Skip to content

Fix edge coverage, add nvdiffrast compatibility, cube maps and examples - #3

Merged
sennecools merged 4 commits into
mainfrom
compat-fixes-and-examples
Nov 17, 2026
Merged

sennecools merged 4 commits into
mainfrom
compat-fixes-and-examples

Conversation

@sennecools

Copy link
Copy Markdown
Owner

Summary

An audit of the library, plus a survey of how 24 open-source projects call nvdiffrast, turned up a set of correctness bugs and missing API surface. This PR fixes and adds those, adds seven examples, and refreshes the README with new images and benchmark numbers.

Rasterization

  • A pixel centre exactly on a shared edge now belongs to one triangle only (top-left rule). The Triton visibility kernels run with enable_fp_fusion=False: fused multiply-adds broke the exact antisymmetry of the edge functions and left holes on quad diagonals and pixel-aligned grids. On the same device both backends now pick the same triangle for every pixel.
  • Zero-area triangles and triangles with NaN/inf vertices are not drawn (the latter were binned into every tile).
  • Range mode (2D pos + ranges), the glctx parameter name, output_db on contexts, a batch of zero, the 2**24 triangle limit, and very wide images.
  • DepthPeeler keeps its own copy of the geometry and raises after its with block.

Texture

  • Cube maps (boundary_mode="cube", seamless across faces; PyTorch on both backends), custom mip lists, texture_construct_mip.
  • Area-weighted mip levels for odd sizes; defined behaviour for out-of-range and NaN input; a zero-size texture no longer aborts the process on Triton.

Antialias

  • No NaN position gradients on axis-aligned edges in the reference backend.
  • A pixel centred on a silhouette is half covered whatever side the fill rule gave it to.
  • Edge adjacency is cached per tri tensor; antialias_construct_topology_hash and a shared 2D pos are supported.

Compatibility

  • import diffrast.torch as dr, RasterizeGLContext, install_as_nvdiffrast(), get/set_log_level.
  • tri indices are validated; interpolate returns an empty out_da instead of None.
  • Triton backward passes raise on second-order gradients instead of silently dropping terms.

Performance

  • The Triton interpolate backward skips attribute gradients that are not needed. At 10k triangles, 8 x 2048² the full forward+backward render goes from 299 ms to 139 ms on an RX 9070 XT. No measured case got slower.

Examples, benchmarks, docs

  • New: shape_fitting.py, pose_fitting.py, env_lighting.py, depth_peeling.py, gbuffer.py, antialias_gradients.py; texture_fitting.py rewritten. All run as CPU smoke tests in tests/test_examples.py.
  • benchmarks/bench_pipeline.py and plot_pipeline.py for the full render.
  • README rewritten (hero image, G-buffer figure, porting guide, examples gallery, benchmark chart), plus CHANGELOG, docs/design.md and CONTRIBUTING. docs/images (about 12 MB) is excluded from the sdist.

Worth knowing for review

  • Pixels exactly on an edge change owner compared with main, by design. Reference images can differ by up to half a pixel along edges that pass exactly through pixel centres.
  • The fill rule is exact per device: CPU and GPU can round pixel centres differently, so the owner of a tie pixel may differ between them. Coverage stays exactly once on each.
  • Calls that relied on out_da is None need updating.

Checklist

  • pytest passes (1175 passed on GPU; 702 passed, 471 skipped with the GPU hidden)
  • ruff check . && ruff format --check . passes
  • GPU tested on: RX 9070 XT / ROCm, torch 2.13.0+rocm10.0.0, triton-windows 3.9.0.post30 (Windows)
  • Written without reference to nvdiffrast source code (see CONTRIBUTING.md)

Rasterization: a pixel centre on a shared edge now belongs to one
triangle only (top-left rule), and the Triton visibility kernels run
without FP fusion, which left holes on such edges. Zero-area and
non-finite triangles are not drawn. Adds range mode, the glctx
parameter name and output_db on contexts.

Texture: cube maps, custom mip lists, texture_construct_mip, and
area-weighted mip levels for odd sizes. Out-of-range input behaves
the same on both backends.

Antialias: no NaN gradients on axis-aligned edges, pixels on a
silhouette are half covered whatever the fill rule, edge adjacency is
cached per tri tensor, and pos may be shared across the batch.

Compatibility: diffrast.torch, RasterizeGLContext,
install_as_nvdiffrast, the log-level functions, validated indices,
and an empty out_da instead of None. Triton backward passes raise on
second-order gradients, and interpolate skips attribute gradients
that are not needed.
The examples share meshes, cameras and image helpers in examples/common.py, and each runs as a smoke test on the CPU. texture_fitting.py now fits a texture on a torus knot.
@coderabbitai

coderabbitai Bot commented Nov 16, 2026

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 25bfb00d-b65d-4c1e-a683-fe0e1b5ba1f7
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-16T21:18:08.968076Z 526c29c PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@sennecools
sennecools merged commit 0072b8e into main Nov 17, 2026
6 checks passed
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

Successfully merging this pull request may close these issues.

1 participant