Shaders: fix packed SV_ClipDistance/SV_CullDistance widths and channel offsets #3339
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3339"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-29T09:26:53Z.
What changed
gpu::recomp::output_channel_spanhelper incrates/xcl/src/gpu/recomp/mod.rsthat computes(start_channel, component_count)forSV_ClipDistance/SV_CullDistanceoutputs from the active bit span of their OSG1mask(start = (mask & 0xF).trailing_zeros(),count = hi - start + 1, with(0, 1)fallback for empty masks) while leaving user semantics as full 4-vectors from.x.crates/xcl/src/gpu/dxil/lower_gfx.rs), the HLSL vertex-shader recompiler (crates/xcl/src/gpu/recomp/emit.rs::export_graphicsandout_comps), and the mesh/geometry pass-through (crates/xcl/src/gpu/recomp/emit.rs::mesh_passthrough_for) to declare each packed clip/cull element with its true component count and read from register channelsstart..start + count(.y,.zw,.w, etc.) instead of always starting at.x.crates/xcl/src/gpu/dxil/graphics.rs::sig_partto sortISG1/OSG1rows by(stream, register, semantic_name_rank, mask.trailing_zeros()), matching DXC's program-signature writer so elements sharing a register and semantic name stay adjacent even when another semantic packs between their columns (e.g.SV_ClipDistance0at.x,SV_CullDistance0at.y,SV_ClipDistance1at.z).crates/xcl/src/gpu/recomp/mod.rs,crates/xcl/src/gpu/recomp/tests.rs, andcrates/xcl/src/gpu/dxil/core_tests.rs.Why
Both
lower_gfx.rs::out_compsandemit.rs::out_compspreviously computed clip/cull component count as8 - e.mask.leading_zeros(), ignoringmask.trailing_zeros(), and always read channels0..countfrom.x. When DXC packs multiple clip/cull outputs into one register (for exampleSV_ClipDistance0in.xyz+SV_ClipDistance1in.wat one register andSV_CullDistance0in.xyat the next, orSV_ClipDistance0in.x+SV_CullDistance0in.yin one register):.welement (mask = 0x8) inflated tofloat4(pushing valid 6-component signatures to 9 > D3D12's 8-distance limit so DXC anddxil.dllrejected the shader)..xclip/cull outputs copied earlier channels (such as another clip plane or unused register channels) into the wrong clip/cull planes instead of reading from their own channel offset.graphics.rs::sig_partpreviously sorted signature rows by(register, mask.trailing_zeros()), causingdxil.dllcontainer validation to reject interleaved packed signatures (SV_ClipDistance0,SV_CullDistance0,SV_ClipDistance1) withContainer part 'Program Output Signature' does not match expected for module.Tested
rustc 1.99.0, DXC1.9.2609.5(dxil.dll 1.9.2609.5).cargo check --workspace --all-targets: passed with 0 errors and 0 new warnings.31 passed; 0 failed; 0 ignored):gpu::recomp::attribute_tests::output_channel_span_preserves_packed_clip_and_cull_offsetsgpu::recomp::tests::packed_clip_and_cull_outputs_keep_width_and_channel_offset_in_hlsl_mesh_and_rect_gs(compiledvs_6_6, bothms_6_6pass-through variants, andgs_6_6with DXC 1.9)gpu::dxil::core_tests::packed_clip_and_cull_distances_validate_and_draw_on_gpu(validated 6-distance and interleaved single-register direct DXIL shaders withdxil.dlland executed both direct DXIL and HLSL draws on RTX 5070 Ti, verifying exact top-right quadrant survival with negative poison on unused.zand full-triangle culling via.y)gpu::dxil::graphics::tests::*tests, plusrect_list_gs_outputs,mesh_split_accounts_vertex_chunks, andmesh_layout_independent_of_group_count.cargo test --workspace -- --test-threads=4,XCL_DXC_DIRset): passed (exit 0, 136.1 s).62d532671d43a5b60fe1abfac9fe262e10a3ca71, rebased ontoorigin/main3b6a91ed,XCL_HEAP_WINDOWS=1,XCL_DIRECT_DXIL=all,XCL_DRED=1), 0 minidumps, 0 display events:Baseline (
mainancestorf0e8fdd5c3942ddd399d5ee11384c8595c5aacff):This PR (
62d532671d43a5b60fe1abfac9fe262e10a3ca71):Not tested
exp pos1–pos3clip/cull exports without anexp param(intentionally left untouched to avoid overlapping open PR#1350).AI use
Written, verified, and tested with an AI coding assistant; all compiler, DXC/DXIL validator, GPU draw, full workspace test suite, and 150 s real-title smoke runs were executed directly on this machine.
Imported from ivall/xcl. Originally posted by Aniseto on 2026-11-29T12:57:05Z.
Ran the packed clip/cull output tests at
c5a9a056on an NVIDIA Blackwell desktop part.System
Results
XCL_ADAPTER=NVIDIA cargo test -p xcl --lib output_channel_span_preserves_packed_clip_and_cull_offsets -- --test-threads=1: 1 passed, 0 failed, 0 ignored.XCL_ADAPTER=NVIDIA cargo test -p xcl --lib packed_clip_and_cull_distances_validate_and_draw_on_gpu -- --test-threads=1: 1 passed, 0 failed, 0 ignored. The GPU draw ran here, with no SKIPPED line.What this adds
Both tests pass: packed
SV_ClipDistance/SV_CullDistanceelements keep their true component width and channel offset, and the generated DXIL validates and draws on the card. The thread already has an RTX 5070 Ti report from the author; this adds an independent run on driver 32.0.16.2140. Synthetic draw only, no title.Not tested
A retail title, a paired smoke run, the full workspace suite, AMD and Intel GPUs, native wave64 hosts, Wine, release profile, game data.
AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - ran the commands above on this machine and wrote this report; no game data was used.
Imported from ivall/xcl. Originally posted by Aniseto on 2026-11-29T14:20:52Z.
Re-ran the packed clip/cull tests at
62d53267after the head moved fromc5a9a056; this is a new response in the same thread, not an edit of my earlier report: https://github.com/xcl-dev/xcl/pull/3339#issuecomment-7256179938System
Results
XCL_ADAPTER=NVIDIA cargo test -p xcl --lib output_channel_span_preserves_packed_clip_and_cull_offsets -- --test-threads=1: 1 passed, 0 failed, 0 ignored.XCL_ADAPTER=NVIDIA cargo test -p xcl --lib packed_clip_and_cull_distances_validate_and_draw_on_gpu -- --test-threads=1: 1 passed, 0 failed, 0 ignored. The GPU draw ran here, with no SKIPPED line.What this adds
Both tests still pass at the new head, including the DXIL validation and D3D12 draw. This adds the new head and driver 32.0.16.2140 as dimensions; no title run was made.
Not tested
A retail title, a paired smoke run, the full workspace suite, AMD and Intel GPUs, native wave64 hosts, Wine, release profile, game data.
AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - ran the commands above on this machine and wrote this report; no game data was used.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:41:54Z.
merge-check
base:
d0832e614fhead:
62d532671dmerge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2893 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: read the whole diff (gpu/dxil graphics.rs, lower_gfx.rs, core_tests.rs; gpu/recomp emit.rs, mod.rs, tests.rs). It changes the default path: every title with clip/cull distances that don't start at
.xchanges on both the HLSL and the direct DXIL path, and the newsig_partorder applies to every direct DXIL signature. No correctness bug found. Mesh records store whole registers, so reading.w/.zwin the pass-through is right. Pixel shaders never declare clip/cull inputs and clip/cull pack after the user rows, so VS -> PS linkage can't shift. The VS, the rect-list GS (out_struct) and the pass-through use the same widths, and the new sort (stream, register, name-table order, column) matches the row order DXC writes. The tests fail on main (.wcomes out 4 components wide, 9 > 8, and the draw reads the -10 poison channel). Findings: (1) the PR's CI run is red on 16 tests in files it doesn't touch (title_textures, pipeline_library, warm_library, geometry_tests, lower_mem stage guards), the same failures an unrelated run that day had; they all pass in the run above on current main, so that CI failure came from the old base. (2) Some DXC compiles in the new tests are skipped silently without printing SKIPPED (part 1 of the core_tests.rs test, the end of the recomp test). The name de-duplication andstreamkey insig_part(~610-622) change nothing. (3) AI use names no tool or model; Tested has no suite counts; the PR's smoke runs used non-defaultXCL_DIRECT_DXIL=all XCL_HEAP_WINDOWS=1 XCL_DRED=1and end at 0 presents.performance: 60 s smoke of a retail title, main
d0832e61vs this merge (a2d47467): 1516 -> 1681 frames shown (110 %; last presents per 2 s: 60 61 60), peak commit 18133 -> 17239 MB, 0 device removals, 0 crashes.verdict: safe to merge (after a rebase and green CI rerun; the description should name the AI model and give the suite counts)
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5
AI-written and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T00:18:11Z.
Code review location:
crates/xcl/src/gpu/recomp/mod.rs; line 582Not certain about this one:
output_channel_spanreturns (0, 1) for an empty mask, so a clip/cull element with mask 0 becomes a real 1-component distance that reads channel .x of its register. If OSG1 has SV_CullDistance0 at r2.x (mask 0x1) and an SV_ClipDistance at r2 with mask 0, both the direct DXIL path (lower_gfx.rs ~331) and the HLSL path (emit.rs ~2372) copy r2.x into the clip distance, so a negative cull value also clips pixels. It also uses one of the 8 clip/cull slots, which can push a full 8-distance signature to 9, the rejection this PR fixes. Skipping mask-0 elements, asSigElement::from_d3ddoes by returning None, would avoid both.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T00:18:11Z.
Review: COMMENTED
Review of
62d53267: 1 finding(s). 1 are inline.These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.