Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
xhiroga opened this issue Feb 24, 2025 · 3 comments
Open

Comments

@xhiroga
Copy link

xhiroga commented Feb 24, 2025

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.

@rob-ack
Copy link

rob-ack commented Feb 25, 2025

I want to ref that this is also able to fix #425 (which is closed as not supported). I would like to see support for WSL so good job so far 👍

@HDANILO
Copy link

HDANILO commented Mar 6, 2025

I support the fix, it's rather annoying error to be manually fixing everytime

@Ainaemaet
Copy link

Has this fix been committed? I haven't tried the nodes yet out of fear of issues, but would like to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants