Shader: a compute sample takes its derivatives from the quad, not level 0 #591
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/591"
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 readmet3xt-lab/foxhound. Originally posted by oxybes on 2026-12-04T08:48:45Z.
lower.rsdocuments a shortcut: asamplewith an implicit level outside a pixel shader reads mip level 0. In this title that is about 730 compute programs - the sky, the screen-space reflections and the occlusion resolves - and it shows as shimmering gradients at the horizon and dirty reflections on water.A compute program's lanes are threads in the group's linear order, quads are lanes 0-3, 4-7 and so on, and the console's quad hardware computes exactly these derivatives (host waves hold 32 or 64 lanes and every base this emitter relabels is 4-aligned, so a quad never straddles a wave - including the wave64 split into two 32-lane waves).
The emitter now reads each coordinate in the neighbouring lane across x and y (
dx.op.quadOp.f32, kinds 0 and 1), takes the difference against its own lane, and samples withdx.op.sampleGrad.f32(three gradient slots per axis,undefin the unused one, as the DXIL signature requires). Mip offsets and the clamp are preserved.Level 0 stays where the lanes cannot be read:
quadOpon lanes 4 and 5 of a 6-thread group reads lanes 6 and 7, which belong to the next group);lane_blocks), where the neighbouring lanes execute different code.Behind
VICTORY_SAMPLE_GRAD, on unless the value is exactly0. The switch is part of the translator cache key, so both states keep their own translations.Measured
RTX 5070, Windows 11, Series S profile, DLSS Quality, frame generation on, one route, both states fully warmed, window in front; medians per
draws/frameslice:VICTORY_SAMPLE_GRAD0(level 0)sampleGrad)The GPU time on those slices nearly halves: level 0 was fetching unfiltered texels, so the gain is bandwidth, not a trade against quality. The sky at the horizon and the water's reflections were checked by eye in both states - no regular grid pattern (which would mean the quad pairing is wrong), no over-blur (a level too high), no popping.
Both sessions: zero warnings or errors, the same drop categories.
Testing
Four emitter tests:
a_compute_sample_reads_its_gradients_from_the_lanes_across: a 64-thread compute program declaresdx.op.sampleGrad.f32anddx.op.quadOp.f32, notsampleLevel; the module is validated withdxil.dlland a compute PSO is created on hardware.a_wave64_group_of_64_takes_the_grad_form_from_its_quads: with the wave64 relabelling to 32-lane host waves, the quad reads pair lanes 0/1 and 2/3 (quad_reads == [0, 0, 1, 1]), never across a wave.the_switch_keeps_the_level_zero_sample,a_group_without_a_quad_keeps_the_level_zero_sample([1,1,1]and[6,1,1]),four_threads_are_one_quad_and_take_the_grad_form,a_two_by_two_group_takes_the_grad_form.a_sample_in_a_per_lane_branch_keeps_the_level_zero_sampleanda_pixel_shaders_sample_is_unchanged.cargo test -p victory-shader: 338 passed.Notes for review
Module::function_namesandLowered::functionsare#[cfg(test)].NaN/infcoordinate now poisons the gradient where level 0 was immune.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.