feat(agc): single-sample sample masks as a per-quad-pixel discard #448
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/448"
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 MichonGoddijn231849 on 2026-10-03T09:14:09Z.
What
Draws whose
PA_SC_AA_MASKwas not all ones were refused withsample masks are unsupported. At one sample, each pixel of the 2x2 quad keeps a single coverage bit (bit 0 of its 16-bit field). So the mask chooses which pixels of every quad a draw may write. GTA V uses0xffff0000/0x00000000to render a target one quarter of its pixels at a time (pixel (1, 0) of each quad).DecodePixelStageInforeduces the two registers to a 4-bitquadPixelMask(bit(x & 1) | (y & 1) << 1). The state rule and the draw precheck now refuse partial masks only on multisampled draws.ShaderPixelStageInfo::quadPixelMask. A fragment shader whose mask is not full:gl_FragCoordquad position is set (theFragCoordinput is added for it);Tested
Windows 11 Pro, AMD Ryzen 5 7600, NVIDIA GeForce RTX 5080 (driver 32.0.16.1074), 32 GB DDR5-5600, MinGW-w64 GCC 15.2.0.
ctest: all tests pass. New cases:agc_driver_quad_pixel_maskdraws a full-screen triangle on the GPU with masks 0xf, 0x2 and 0x9, and checks every pixel;PA_SC_AA_MASKdecodes to the quad mask;sample masks are unsupported. They now render, and the scene looks as before. Tested on my branch that combines this change with my other open PRs.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🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T05:45:42Z.
The quad mask decode matches PA_SC_AA_MASK at one sample, and the GPU test is nice. One exactness point: the mask is applied with an OpKill at the top of the shader. On the hardware, a pixel that AA_MASK leaves uncovered still runs as a helper lane of its quad, so derivatives in the covered pixels stay defined. After OpKill, Vulkan no longer keeps that invocation as a helper, so implicit-LOD samples and other derivatives in the remaining pixels are undefined, and with one covered pixel per quad that's every quad.
OpDemoteToHelperInvocation(core in Vulkan 1.3,shaderDemoteToHelperInvocation) keeps the lane as a helper and would match the hardware. Without demote support the draw could be refused when the pixel program uses derivatives. Could the test also sample a texture with implicit LOD in the masked draw? Once #375 and #423 land, a rebase would leave just this commit.Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-04T08:32:04Z.
Good catch, thanks. Done in 7316e3ab:
shaderDemoteToHelperInvocation, the mask now emitsOpDemoteToHelperInvocation. The device enables the feature and extension when available, and the validator accepts capability 5379 only then. A masked-off pixel's starting EXEC bit also reads as a helper, as on the hardware.OpKillonly when the pixel program reads no neighbouring lanes: no implicit-LOD samples, LOD queries, DPP, swizzles, bpermute, permlane16 or readlane. Otherwise the draw is refused with a message naming the mask and the missing feature.One honest limit: on my RTX 5080 the test passes even with
OpKillforced, because this driver evidently keeps killed lanes as helpers. So it shows the demote path is correct, not that kill is wrong there. Treating readlane and DPP as derivative-like reads for the refusal is my own choice; the docs don't define it. I'll rebase once #375 and #423 land.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T09:52:21Z.
Thanks, that's what I meant. Demote is only emitted when the device enabled
shaderDemoteToHelperInvocation, the validator only accepts it then, the uncovered pixels start with their EXEC bit clear like helpers do, and the test now samples at LOD 2 with one covered pixel per quad, which only works with the helpers alive.One small thing for the path without demote, not blocking: a program that runs
s_wqm_b64 exec, execand then a ballot orreadfirstlanecan also see the helper lanes, whichOpKillremoves. Most such programs sample with implicit LOD and are refused already, but addingWqmU64toReadsNeighbourLaneswould close it. I'll look again once #375 and #423 land and this is down to its own commits.Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-05T15:40:42Z.
Done in bed8cb06:
WqmU64now counts as a neighbour-lane read, so without demote a quad-masked program that enables whole-quad mode is refused like one that samples with implicit LOD. The refusal message names whole-quad mode too.Also rebased onto current
maintogether with the PRs it carries (#295, #375, #423, all rebased today). The only conflict was the include list inSpirvAnalysis.cpp. Build and ctest are clean apart from the failuresmainhas locally.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-06T05:34:08Z.
Thanks, bed8cb06 does it:
WqmU64counts as a neighbour-lane read, so a quad-masked program that enables whole-quad mode is refused without demote, and the message says so. It's down to the stack now. #752 has landed since, and #375'sShaderValidation.cppline conflicts with it (details on #375).Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-06T15:39:17Z.
Rebased onto current
mainand the rebased #375 and #423 (now eecdf09c). Two conflicts:VulkanDevice.cpp:main's 64-bit buffer atomics feature and this PR's demote feature both chain into the device features at the same place. Both are kept, each with its own block.CacheKey.hpp,ShaderStageInputInfo.hppandShaderInputInfoBuilder.cpp:main'sconservativeZExportand this PR'squadPixelMasksit side by side.The request version also moved: #423 now uses version 8 (
maintook 7), so the quad pixel mask is read from version 9. Builds; the driver tests pass apart fromagc_driver_scalar_sop1, which fails without this PR too.Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-07T08:44:36Z.
Rebased onto current
mainand the rebased #423 (now aafff7dd). The conflict was the request version again:maintook version 8 for the pixel stage's target export mapping, so #423 moved to version 9 and the quad pixel mask here to version 10. The mask is written after the export mapping and read from version 10 on; the serializer test checks the version 10 prefix and refuses 11. Builds; the driver tests andQuadPixelMaskpass apart fromagc_driver_scalar_sop1(fixed by #928).Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-07T17:31:07Z.
Rebased onto current
mainand the rebased #423 (now 31d47639). Conflicts:main's 64-bit image atomics feature and this PR's demote feature chain into the device features at the same place, so both are kept; the demote parameter ofValidateShaders/Inspectnow comes aftermain'simageInt64Atomics. Since #423 now uses request version 10, the quad pixel mask moves to version 11 (the earlier version-10 commit became empty and was dropped). Build and ctest pass.Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-09T08:32:50Z.
Parked as a draft to keep my rebase load sane after #639. I'll rebase it when someone wants to review it.
Imported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-13T19:09:07Z.
I recovered this implementation on current main (
18c438b10), retaining your three original commits and authorship, and prepared a verified branch atfdfawef324:codex/samplemask-no-demote-review(e8c1057abdb07b0590ad28b7dc70d52ff884c322). It also covers uniform and varying multisample PA_SC_AA_MASK fields, with explicit refusals for unsupported ordering and centroid cases. I would like to offer that branch here for review/integration because the single-sample implementation overlaps this PR.Adversarial verification found that the no-demote guard also needs ReadFirstLane, Ballot and PermuteU32: explicit EXEC can enable uncovered helpers, and a constant WQM instruction can fold away before analysis. The added CPU regression fails on the recovered implementation and passes with those three classifications. Unmasked programs, supported demote paths, and the constant-colour kill fallback are checked as controls.
The real DCB test fails at the unsupported-mask runtime path without the implementation. With it, non-skipped GPU readbacks pass for driver mask changes, 1x depth/stencil suppression and fragment stores, 4x uniform/varying coverage, per-sample stores, and implicit-LOD helper preservation. Current-main shader-memory and focused no-demote checks also pass; conventions are clean. GTA gameplay validation is still pending.
GPUs tested: NVIDIA GeForce RTX 3060 12 GB, driver 591.86 (32.0.15.9186), Vulkan 1.4.325, Windows Server 2025 10.0.26100.
AI-assisted: yes.
Co-Authored-By: Codex [email protected]
Imported from boykopovar/AnyPS5. Originally posted by tibzejoker on 2026-10-14T00:00:18Z.
@fdfawef324 the GTA gameplay check for
codex/samplemask-no-demote-review(e8c1057ab), the one you listed as pending. GTA V (PPSA04264), Windows 11, RTX 4090, MinGW-w64 GCC 15.2.0, Release.Base:
main8d98e8851plus the open PRs GTA needs to reach Story: #5003, #4878, #1186, #1189, and a local port of #637 (without it, write watch crashes the title on currentmain). Your five commits went in as they are. The only conflict was one test registration line intests/Graphics.cpp, where I kept both lines.sample masks are unsupported. With them, the prologue runs for 150 s with no sample-mask error, and the scene, HUD and minimap render correctly. That is the same picture as with Michon's three commits on our older stack.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-14T08:36:33Z.
@fdfawef324 thanks for recovering this on current
mainand extending it to the multisample fields, and @tibzejoker for the GTA V check. Your branch is further along than this one. Please open it as its own PR, since you can answer the review on the new parts. Link it here and I'll close this one in its favour. If you'd rather I carry it, say so and I'll push your branch here instead.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T19:20:12Z.
Opened #6015 with @fdfawef324's
codex/samplemask-no-demote-reviewrebased onto currentmain. It includes @MichonGoddijn231849's three commits, and everyone keeps authorship. The request version is now 26/27 becausemain's dither flag took 25. On GTA V, Story Mode now gets to the prologue title card. The next stop there is a CB resolve into a non-resident target. Michon, you can close this one in favour of #6015, as you offered.Pull request closed