Repository navigation
fix(agc): emulate comparison sampling of color textures in the shader - #668
Conversation
AMD hardware compares a sample_c reference against a color texture's red channel; Vulkan defines comparison sampling only for depth formats, so the driver refused any compare-sampled texture that is not R32 float or R16 unorm. PPSA21567 compares the same LESSEQUAL, clamp-to-border (opaque white) sampler against a shadow map and against a 1x1 RGBA8 texture. For a compare-sampled image whose format is not natively comparable, the specialization records the paired sampler's compare function, filter, addressing and border, and the view's reference clamp kind; the image then binds as an ordinary color texture. The backend fetches the red channel, applies wrap, clamp-to-edge or clamp-to-border addressing with the sampler's texel-centre convention (border taps take the border's red), compares, and blends four comparisons for bilinear filtering. Real depth formats keep the native path. Only sample_c / sample_c_lz on 2D and 2D array views, float/unorm/snorm formats, wrap, clamp-to-edge or clamp-to-border, point or bilinear at one level are implemented; half-border, the border color table and everything else on this path throw. The reference clamp for unorm/snorm color formats is not documented by AMD and is recorded in the technical debt. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
CI note: the |
|
Thanks for porting this to main. It replaces the stopgap I have on my integration branch, which leaves the colour image under the compare sampler and takes whatever the driver returns, so I'm glad to see a defined result. I went through the decoding and it matches the GFX10 layouts as far as I can tell: CLAMP_X/Y, DEPTH_COMPARE_FUNC, FORCE_UNNORMALIZED, LOD_BIAS, the XY filters, BORDER_COLOR_TYPE, and BASE/LAST_LEVEL for the single level check. Comparing A few questions, none of them blocking on its own:
One thing to be aware of: the maintainer's #639 removes PPSA21564 does reach this path (a 1x1 RGBA8 surface under a LESSEQUAL sampler), so I'll run it through my visual regression check before it lands. Locally (Linux, GCC, NVIDIA): |
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
|
|
Thanks for the detailed review. Pushed
Tested on Linux (CachyOS, GCC 16.2.1, NVIDIA): |
|
A note on timing: this was merged at 00:27 UTC, before I pushed the follow-up commits that answer the review, so |
|
Sorry about that, it went in on the gate result before your answers arrived; that's on my side. Thanks for moving them onto main. Please link the follow-up here, and I'll review and gate it straight away. |
|
The follow-up is open: #907. It carries the two commits that answer the four review points (unordered NOT_EQUAL and refusing |
The emulated comparison picked the array layer as floor(z + 0.5). Measured on RDNA2 (adriadam10, in the boykopovar#907 review), the hardware takes clamp(roundEven(z), 0, layers - 1): z = 0.5 selects layer 0 and 2.5 layer 2, and 0.49999997, which floor(z + 0.5) rounds up to 1 in f32, selects 0. GLSL.std.450 RoundEven matches that and is the rule Vulkan uses for its own array layer. The floor(z + 0.5) came in with boykopovar#668. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
What
AMD hardware compares a
sample_creference against the red channel of a colour texture. Vulkan defines comparison sampling only for depth formats, so the driver refused any compare-sampled texture that isn't R32 float or R16 unorm. PPSA21567 (Astro Bot) uses the sameLESSEQUAL, clamp-to-border (opaque white) sampler on a shadow map and on a 1x1 RGBA8 texture.For a compare-sampled image whose format isn't natively comparable:
Real depth formats keep the native path.
Scope: only
sample_c/sample_c_lzon 2D and 2D-array views, float/unorm/snorm formats, wrap / clamp-to-edge / clamp-to-border, and point or bilinear filtering at one level. Half-border, the border colour table (#665) and everything else on this path throw. AMD doesn't document the reference clamp for unorm/snorm colour formats; that's recorded in the technical debt.Tested
BUILD_TESTING=ON,ctestpasses 285/285.agc_driver_emulated_color_compareexecution test. It runs aLESSEQUALcompare on the GPU against a CPU reference: point and bilinear with clamp-to-edge, bilinear with wrap, and point and bilinear with white and black clamp-to-border. It also checks that R32 float keeps the native depth compare and that an RGBA8 texture doesn't, and that the out-of-scope cases throw (uint format, mirror, half-border, border colour table, anisotropic).mainthe title stopped at this refusal. The same change on oneandonlydean'sastrobotbranch ran 2 of 2 runs (35 min each, Linux, virtual display) to the Crash Site tutorial, with no new throws. This exactmainversion has not been run against the title, sincemaindoesn't reach that point on it.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code