Skip to content

Fix inconsistency in CUDA rasterizer option causing startup failures in WSL #456

Closed
@xhiroga

Description

@xhiroga

Problem Description

When running in WSL environment, ComfyUI-3D-Pack fails to load with the following error:

RuntimeError: Cuda error: 304[cudaGraphicsGLRegisterBuffer(&s.cudaPosBuffer, s.glPosBuffer, cudaGraphicsRegisterFlagsWriteDiscard);]

Root Cause

The issue stems from an inconsistency in how the rasterizer is selected:

  1. The multiview_color_projection_texture() function offers a force_cuda_rast parameter that allows choosing between OpenGL and CUDA rasterizers
  2. However, the Pix2FacesRenderer class in project_mesh.py always initializes with RasterizeGLContext during module loading
  3. This initial OpenGL-based renderer creation fails in WSL2 due to OpenGL-CUDA interoperability limitations (like Unable to load under WSL 2 in Win10 due to: RuntimeError: Cuda error: 304[cudaGraphicsGLRegisterBuffer(&s.cudaPosBuffer, s.glPosBuffer, cudaGraphicsRegisterFlagsWriteDiscard);] #425)

Proposed Fix

The solution is to make the CUDA rasterizer option consistent throughout the codebase:

class Pix2FacesRenderer:
    def __init__(self, device="cuda"):
      try:
        self._glctx = dr.RasterizeGLContext(output_db=False, device=device)
      except Exception:
        self._glctx = dr.RasterizeCudaContext()

      self.device = device
      _warmup(self._glctx, device)

I've verified that this approach works by manually modifying the code. However, I would appreciate any feedback on this fix before submitting a PR.
I would also be happy to submit a PR with this fix if it looks good.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions