agc: agc_driver_front_face_all_bits writes a float fragment output to an R32_UINT color attachment (undefined in Vulkan; MoltenVK rejects the pipeline) #7703

Open
opened 2026-10-19 01:29:06 +00:00 by jotitadev · 2 comments
jotitadev commented 2026-10-19 01:29:06 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-19T01:29:06Z.


What happens

core/libs/prx/libSceAgcDriver/tests/execution/FrontFaceAllBits.cpp (added in 8dbf06798) binds a VK_FORMAT_R32_UINT color target:

pixel.targetOutputMode[0] = 1;   // SPI_SHADER_32_R
...
state.color = {..., VK_FORMAT_R32_UINT, sizeof(Pixels), 0xe4u};   // uintExport left false

The recompiler declares out_mrt_0 as uint4 only for export mode 7 (SpirvEmitterHelpers.cpp, uintOutput); for mode 1 it is float4. ShaderValidation.cpp accepts that because the target's uintExport is false. The pipeline therefore writes a float output to an unsigned-integer attachment.

The Khronos validation layer flags it on any driver:

Validation Warning: [ Undefined-Value-ShaderFragmentOutputMismatch ]
vkCreateGraphicsPipelines(): pCreateInfos[0] Inside [VK_SHADER_STAGE_FRAGMENT_BIT], it writes to [Output variable, Location 0, "out_mrt_0"] with a numeric type of FLOAT but VkSubpassDescription::pColorAttachments[0] pointing at VkRenderPassCreateInfo::pAttachments[0] is created with VK_FORMAT_R32_UINT (numeric type of UINT) which does not match and the resulting values written will be undefined.

On desktop drivers the raw bits usually land in the attachment, so the test passes there. On MoltenVK the Metal compiler rejects the pipeline:

output of type float4 is not compatible with a MTLPixelFormatR32Uint color attachment..
AGC graphics: vkCreateGraphicsPipelines: Vulkan result -3

Repro

Any host with the Vulkan SDK validation layer:

VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ./build/tests/agc_driver_front_face_all_bits_tests 2>&1 | grep -A2 ShaderFragmentOutputMismatch

Possible fix

Make the test's state self-consistent, for example by exporting through mode 7 with uintExport set (the path the packed and unsigned-integer targets already use), or by using an R32_SFLOAT target and comparing bits. I did not check whether a real title can reach export mode 1 with an unsigned-integer target through State.cpp (which maps a 32-bit UINT color buffer to R32_UINT); if it can, the same mismatch would apply to the driver, not only to the test.

Environment

Apple M2 Max, macOS 27.2, x86-64 build under Rosetta 2, MoltenVK 1.4.2 (Vulkan SDK 1.4.363.0) and MoltenVK main with SPIRV-Cross #2704: same result with both. Tree: main a373e85e5 + mugurc ci/macos-series-2 (91e4eccaf) + #6667 #6668 #6969 #7524 (needed to build on macOS; none touch this test or the recompiler output types).

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5916258101 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/7703). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-19T01:29:06Z. --- ### What happens `core/libs/prx/libSceAgcDriver/tests/execution/FrontFaceAllBits.cpp` (added in 8dbf06798) binds a `VK_FORMAT_R32_UINT` color target: ```cpp pixel.targetOutputMode[0] = 1; // SPI_SHADER_32_R ... state.color = {..., VK_FORMAT_R32_UINT, sizeof(Pixels), 0xe4u}; // uintExport left false ``` The recompiler declares `out_mrt_0` as `uint4` only for export mode 7 (`SpirvEmitterHelpers.cpp`, `uintOutput`); for mode 1 it is `float4`. `ShaderValidation.cpp` accepts that because the target's `uintExport` is false. The pipeline therefore writes a float output to an unsigned-integer attachment. The Khronos validation layer flags it on any driver: ``` Validation Warning: [ Undefined-Value-ShaderFragmentOutputMismatch ] vkCreateGraphicsPipelines(): pCreateInfos[0] Inside [VK_SHADER_STAGE_FRAGMENT_BIT], it writes to [Output variable, Location 0, "out_mrt_0"] with a numeric type of FLOAT but VkSubpassDescription::pColorAttachments[0] pointing at VkRenderPassCreateInfo::pAttachments[0] is created with VK_FORMAT_R32_UINT (numeric type of UINT) which does not match and the resulting values written will be undefined. ``` On desktop drivers the raw bits usually land in the attachment, so the test passes there. On MoltenVK the Metal compiler rejects the pipeline: ``` output of type float4 is not compatible with a MTLPixelFormatR32Uint color attachment.. AGC graphics: vkCreateGraphicsPipelines: Vulkan result -3 ``` ### Repro Any host with the Vulkan SDK validation layer: ```sh VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ./build/tests/agc_driver_front_face_all_bits_tests 2>&1 | grep -A2 ShaderFragmentOutputMismatch ``` ### Possible fix Make the test's state self-consistent, for example by exporting through mode 7 with `uintExport` set (the path the packed and unsigned-integer targets already use), or by using an `R32_SFLOAT` target and comparing bits. I did not check whether a real title can reach export mode 1 with an unsigned-integer target through `State.cpp` (which maps a 32-bit UINT color buffer to `R32_UINT`); if it can, the same mismatch would apply to the driver, not only to the test. ### Environment Apple M2 Max, macOS 27.2, x86-64 build under Rosetta 2, MoltenVK 1.4.2 (Vulkan SDK 1.4.363.0) and MoltenVK main with SPIRV-Cross #2704: same result with both. Tree: main a373e85e5 + mugurc `ci/macos-series-2` (91e4eccaf) + #6667 #6668 #6969 #7524 (needed to build on macOS; none touch this test or the recompiler output types). Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
jotitadev commented 2026-10-19 01:52:56 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-19T01:52:56Z.


Follow-up: this is reachable from the driver, not only from the test. On main (324e0e48e), State.cpp only checks export mode 7 against the target type and sets uintExport = slotExport == 7, so a title can export mode 1 to a 32-bit uint color buffer, which becomes R32_UINT. SpirvEmitterHelpers.cpp declares an integer output only for mode 7, and ShaderValidation.cpp accepts the float output because uintExport is false.

#6235 (firesand) fixes exactly this: raw32 exports (modes 1/2/3/9) to UINT/SINT attachments get an integer output of the attachment's type, and it updates FrontFaceAllBits.cpp accordingly. It currently conflicts with main; once rebased I can run it on MoltenVK, where Metal rejects the pipeline today.

Written with AI assistance (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6257968076 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/7703#issuecomment-6257968076). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-19T01:52:56Z. --- Follow-up: this is reachable from the driver, not only from the test. On `main` (324e0e48e), `State.cpp` only checks export mode 7 against the target type and sets `uintExport = slotExport == 7`, so a title can export mode 1 to a 32-bit uint color buffer, which becomes `R32_UINT`. `SpirvEmitterHelpers.cpp` declares an integer output only for mode 7, and `ShaderValidation.cpp` accepts the float output because `uintExport` is false. #6235 (firesand) fixes exactly this: raw32 exports (modes 1/2/3/9) to UINT/SINT attachments get an integer output of the attachment's type, and it updates `FrontFaceAllBits.cpp` accordingly. It currently conflicts with `main`; once rebased I can run it on MoltenVK, where Metal rejects the pipeline today. Written with AI assistance (Claude Code).
MarcZX10 commented 2026-10-20 07:49:29 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T07:49:29Z.


The test-side mismatch described here is already corrected on current main by ca76e540db (test(agc): export the front-face bits through a uint target as uint): FrontFaceAllBits.cpp now uses export mode 7 and sets uintExport = true for its R32_UINT target.

The broader production case—raw32 fragment exports targeting UINT/SINT attachments—is covered by the open PR #6235. I found no distinct remaining change to submit for this report, so I have not opened a duplicate PR. Leaving the issue open pending the production fix.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6286108041 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/7703#issuecomment-6286108041). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-20T07:49:29Z. --- The test-side mismatch described here is already corrected on current `main` by `ca76e540db` (`test(agc): export the front-face bits through a uint target as uint`): `FrontFaceAllBits.cpp` now uses export mode 7 and sets `uintExport = true` for its `R32_UINT` target. The broader production case—raw32 fragment exports targeting UINT/SINT attachments—is covered by the open PR #6235. I found no distinct remaining change to submit for this report, so I have not opened a duplicate PR. Leaving the issue open pending the production fix.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5#7703
No description provided.