AGC: a raw 32-bit float export into a UINT color target fails pipeline creation on MoltenVK (Doom 3 BFG, ccleste) #9783
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 rooklz on 2026-10-22T14:46:07Z.
What stops
Two homebrew catalog titles stop at their first draw on macOS with MoltenVK, because a pixel shader that exports raw 32-bit values into a color target whose number type is UINT reaches Vulkan as a
float4output on an integer attachment, which Metal refuses to compile:ps5-v1.0.0catalog build)VK_FORMAT_R32G32B32A32_UINT(COLOR_32_32_32_32, number UINT)output of type float4 is not compatible with a MTLPixelFormatRGBA32Uint color attachmentVK_FORMAT_R8_UINT(COLOR_8, number UINT)output of type float4 is not compatible with a MTLPixelFormatR8Uint color attachmentBoth end as
(the second line of the Metal message is only printed with
MVK_CONFIG_LOG_LEVEL=3). Doom 3 BFG's draw is a 3-index rect-list draw with one color target, vertex0x200320000and fragment0x200320400, asAPS5_TRACE_DRAW_PROGRAMSprints it; it also has blending enabled on that target, which MoltenVK warns about separately (Blending is enabled for attachment with format VK_FORMAT_R32G32B32A32_UINT, which does not support it) but which is not what fails the compile: I tried forcingblendEnableoff for integer formats inState.cppand the compile error stays.On a Linux NVIDIA or AMD driver the same pipeline is accepted (the float output is written as its bits), so this only shows on Metal.
Where
Graphics/src/State.cppchooses the attachment format from the target's number type:COLOR_32_32_32_32with UINT becomesR32G32B32A32_UINT(case 14),COLOR_8with UINT becomesR8_UINT.Graphics/src/ShaderValidation.cpp(line 711 onmain8b3e39832a) expects the fragment output signaturevertex:u32x4only whencolor.uintExportis set, andState.cppline 1386 sets that only for export format 7 (UINT16_ABGR). A raw 32-bit export (formats 1, 2, 3 and 9) into a UINT target keeps the float signature, so the SPIR-V output isfloat4while the attachment is integer.Vulkan leaves the result undefined when the output's numeric type differs from the attachment's; Metal rejects it at compile time. The Vulkan spec also says
Blending is only defined for floating-point, UNORM, SNORM, and sRGB formats(framebuffer chapter), so the enabled blend on the UINT target is a second undefined case in the same draw.What I think the fix is
Type the fragment output by the target, not only by the export format: for a UINT (or SINT) target reached through a raw 32-bit export, emit the export as
u32x4(a bitcast of the same bits) and expect that signature inShaderValidation.cpp. For 32-bit channels that is the same stored bits the console's CB stores, since it does no conversion for 32-bit components; for 8- and 16-bit channels the console converts the raw export per the number type, which the integer attachment then does too. Blending on a UINT target should be dropped at the same time, since neither the console's CB nor Vulkan blends integer formats.I have not measured this on a console; the CB conversion rules above are from the RDNA CB documentation as the driver already uses them. I can test a change on this M5 and on NVIDIA tomorrow, and I'm happy to do the PR if nobody is on it; I'm not touching the recompiler without saying so here first.
Environment
macOS 26.2, Apple M5, Apple clang 21, x86-64 under Rosetta 2, the
ci/macos-series-2integration tree at53db0badbwith #7524, the code of #7937 and the libSceSsl change of #7332, MoltenVK from MBridge (itsVK_EXT_provoking_vertex,VK_KHR_fragment_shader_barycentricand mesh-shader features report false). Titles converted withmain's relinker,--macos --to-rosetta.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-22T14:48:26Z.
Starting on this now, so it's said here first: the change I'm trying is a fourth
ColorExportPackingkind for UINT targets, which goes through the existing fragment-output specialization (the same retype-and-bitcast it already does for the 11_11_10 packings, no new SPIR-V shapes), the driver picking it for UINT number types reached by raw 32-bit exports and dropping the blend on those targets, plus a DecodeState check and an execution test. If someone is already on it, say so and I'll stop.Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-22T15:05:30Z.
Pull request: #9789. On the M5 with MoltenVK it takes Doom 3 BFG past the pipeline compile to its own data check and ccleste to the barycentric gap; bring-up threads #9787 and #9788.