fix(agc): emulate comparison sampling of color textures in the shader #668
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/668"
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 boykopovar/AnyPS5. Originally posted by ThisIsAkill on 2026-10-05T13:11:55Z.
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
Imported from boykopovar/AnyPS5. Originally posted by ThisIsAkill on 2026-10-05T17:53:43Z.
CI note: the
linuxjob failed with 284 of 285 tests passed. The failing test isagc_driver_flat_cache_bits, a 120 s timeout (https://github.com/boykopovar/AnyPS5/actions/runs/37314963696/job/111779270934);windowspassed. This PR doesn't touch that test or the code it covers (the diff is the comparison-sampling emulation, its execution test and the shader disk cache). On this branch locally (Linux, GCC 16.2.1) the test passes in about 4 s: 15 of 15 runs, and 285/285 in the fullctest. The Linux job is green on the other recent PRs, so it looks like a hang on that runner. Could a maintainer re-run the job?Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T19:45:41Z.
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
ref OP texelper tap and then blending is the right order for bilinear PCF. The CI failure on Linux isagc_driver_flat_cache_bitstiming out, which fails other PRs in the same window too; your new test passed all three repeats.A few questions, none of them blocking on its own:
image_sample_c_lz ... dim:SQ_RSRC_IMG_2D_ARRAY(1,723 shaders, no gathers, no offsets). Could you add a 2D array case, so the layer size query and thefloor(z + 0.5)clamp are covered?OpFOrd*, so NOTEQUAL gives 0 for a NaN texel or reference. I believe the hardware's NOT_EQUAL is unordered (true for NaN), as in D3D. If you agree,OpFUnordNotEqualwould match; otherwise a short line in the TechnicalDebt entry would do.One thing to be aware of: the maintainer's #639 removes
ResourceSpecializationand moves image handling to a fixed set of runtime modes, so this change and #639 conflict inResourceMaterializerandShaderDiskCache. Whichever lands second will need the emulated compare as a runtime mode, with the sampler state read at run time. Nothing to do here now; I'm only mentioning it so it's not a surprise.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):
agc_driver_emulated_color_comparefails on main's code, passes with the change, and passes 20 times in a row. The full ctest passes with it merged together with the other GPU PRs I tested, apart from one unrelated test.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-05T21:31:51Z.
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.
main)core/shader/recompiler/IntermediateRepresentation/include/IntermediateRepresentation/IrMetadata/Resources.hppL34-36, L56-60core/shader/recompiler/Optimization/src/ResourceMaterializer.cppL501-502, L634-644, L963core/shader/recompiler/ShaderDiskCache.cppL73-75, L83, L410-414, L499-503, L814-815core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cppL5-6, L894-895core/shader/recompiler/IntermediateRepresentation/include/IntermediateRepresentation/IrMetadata/Resources.hppL34-36, L56-60core/shader/recompiler/Optimization/src/ResourceMaterializer.cppL501-502, L634-644, L963core/shader/recompiler/ShaderDiskCache.cppL73-75, L83, L410-414, L499-503, L814-815core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cppL5-6, L894-895core/shader/recompiler/IntermediateRepresentation/include/IntermediateRepresentation/IrMetadata/Resources.hppL34-36, L56-60core/shader/recompiler/Optimization/src/ResourceMaterializer.cppL501-502, L634-644, L963core/shader/recompiler/ShaderDiskCache.cppL73-75, L83, L410-414, L499-503, L814-815core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cppL5-6, L894-895Imported from boykopovar/AnyPS5. Originally posted by ThisIsAkill on 2026-10-06T02:05:47Z.
Thanks for the detailed review. Pushed
aaac3189(the code) andf8b209c6(the test):image_sample_c_lz ... dim:SQ_RSRC_IMG_2D_ARRAY, assembled withllvm-mcfor gfx1030) with a different texel table in each layer. The layer coordinates are -0.4, 0, 0.49, 0.5, 0.99, 1, 1.4 and 2.7, so the nearest-slice rounding and the clamp to the layer count are both exercised. Cases: point and bilinear clamp-to-edge, bilinear wrap, bilinear white border, and GREATER with point sampling.OpFUnordNotEqual: it is the IEEE!=(true for a NaN reference or texel), and it is what Vulkan defines forVK_COMPARE_OP_NOT_EQUALon the native depth path. I couldn't find a source for what the hardware does, so the TechnicalDebt entry says the NaN behaviour is unverified. There is no NaN test: an unorm texel can't be NaN, and the reference is clamped first, which SPIR-V leaves undefined for NaN.FILTER_MODE(word 0 bits 29–30) already throws when the sampler is created; the specialization now refuses it explicitly too, so the emulation doesn't depend on that.TRUNC_COORD(bit 27) throws when the sampler is point-filtered (it only affects point sampling; with bilinear it's ignored). Both have a rejection test. What I can't tell is howTRUNC_COORDdiffers from the default at exact texel boundaries: the emulation selectsfloor(u * width), as Vulkan's nearest does.Tested on Linux (CachyOS, GCC 16.2.1, NVIDIA):
agc_driver_emulated_color_comparepasses with the new cases, and the fullctestpasses 285/285. Noted on #639 and the overlap with #757–#759: nothing to do here until one of them lands.Imported from boykopovar/AnyPS5. Originally posted by ThisIsAkill on 2026-10-06T02:38:54Z.
A note on timing: this was merged at 00:27 UTC, before I pushed the follow-up commits that answer the review, so
mainhas the first commit only (52021996). The review fixes are not inmainyet. They are two commits on my branchfix/agc-emulated-color-compare-main(aaac3189: unordered NOT_EQUAL, refuseFILTER_MODEandTRUNC_COORDwith point sampling, TechnicalDebt;f8b209c6: the 2D array, GREATER and rejection tests), tested as described above. I'm moving them onto currentmainas a follow-up change so that the 2D-array coverage and the NaN and sampler-state handling land too.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-06T04:25:57Z.
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.
Imported from boykopovar/AnyPS5. Originally posted by ThisIsAkill on 2026-10-06T15:40:19Z.
The follow-up is open: #907. It carries the two commits that answer the four review points (unordered NOT_EQUAL and refusing
FILTER_MODEreduction andTRUNC_COORD, plus the 2D array and GREATER test cases), rebased on currentmain. No other changes. Fullctestpasses (359 of 359, one test skips itself), andagc_driver_emulated_color_comparepasses 4 of 4 runs. #639 is already conflicting withmainand touchesResourceMaterializer.cpp, which #907 edits by four lines; I noted that in the PR.