NVlabs / nvdiffrast

Nvdiffrast - Modular Primitives for High-Performance Differentiable Rendering
Other
1.42k stars 157 forks source link

RuntimeError: width and height must be divisible by 8 #193

Closed ForrestPi closed 3 months ago

ForrestPi commented 4 months ago

setting resx=960 resy=540 got out, out_db = _get_plugin().rasterize_fwd_cuda(raster_ctx.cpp_wrapper, pos, tri, resolution, ranges, peeling_idx) RuntimeError: width and height must be divisible by 8

ForrestPi commented 4 months ago

@s-laine width and height must be divisible by 8.

ForrestPi commented 4 months ago

@nurpax Hi, could you provide some tips?

ForrestPi commented 4 months ago

could anyone help me?

s-laine commented 4 months ago

The Cuda-based rasterizer currently expects a viewport size where both dimensions are divisible by 8, and 540 is not divisible by 8.

The solution is to use a rendering resolution where both dimensions are divisible by 8, e.g., 960×544.

If you want to, you can run the rasterizer in a larger resolution and then crop the output to 960×540 by removing top 2 and bottom 2 rows of the output. The y coordinate of the vertex positions should be adjusted beforehand to account for the crop:

pos_adjusted = pos * torch.tensor((1, 540/544, 1, 1), dtype=pos.dtype, device=pos.device)
out, out_db = dr.rasterize(glctx, pos_adjusted, tri, (544, 960))
out = out[:, 2:-2, :, :] # crop to 960x540
out_db = out_db[:, 2:-2, :, :]

The remainder of the rendering pipeline should use the unadjusted vertex positions as it's operating on the cropped image.

ForrestPi commented 3 months ago

thanks

s-laine commented 1 month ago

For future reference, the Cuda rasterizer in v0.3.2 and above doesn't require the output dimensions to be divisible by 8 anymore.