diff --git a/runtime/shims/d3d12_vulkan_device.cpp b/runtime/shims/d3d12_vulkan_device.cpp index d2681ad6c4..ace8927641 100644 --- a/runtime/shims/d3d12_vulkan_device.cpp +++ b/runtime/shims/d3d12_vulkan_device.cpp @@ -7299,6 +7299,38 @@ bool vertex_format(DXGI_FORMAT format, VkFormat& out, UINT& bytes) { return false; } +// The render-target formats that hold integers. The console leaves its blender enabled on them (the native state +// keeps CB_BLENDn regardless of the format; D3D12Xbox bypasses the blender there), and Vulkan requires +// blendEnable = VK_FALSE for them (VUID-VkPipelineColorBlendAttachmentState-blendEnable-04727), so the layer clears +// the enable for such a target and keeps the target's write mask. Adapted from DexNom/VIctory ddb7332 +// (GPL-3.0-or-later), "Restore 40 shader variants and repair integer-target blending". +bool integer_color_format(DXGI_FORMAT format) { + switch (format) { + case DXGI_FORMAT_R32G32B32A32_UINT: + case DXGI_FORMAT_R32G32B32A32_SINT: + case DXGI_FORMAT_R32G32B32_UINT: + case DXGI_FORMAT_R32G32B32_SINT: + case DXGI_FORMAT_R16G16B16A16_UINT: + case DXGI_FORMAT_R16G16B16A16_SINT: + case DXGI_FORMAT_R32G32_UINT: + case DXGI_FORMAT_R32G32_SINT: + case DXGI_FORMAT_R10G10B10A2_UINT: + case DXGI_FORMAT_R8G8B8A8_UINT: + case DXGI_FORMAT_R8G8B8A8_SINT: + case DXGI_FORMAT_R16G16_UINT: + case DXGI_FORMAT_R16G16_SINT: + case DXGI_FORMAT_R32_UINT: + case DXGI_FORMAT_R32_SINT: + case DXGI_FORMAT_R8G8_UINT: + case DXGI_FORMAT_R8G8_SINT: + case DXGI_FORMAT_R16_UINT: + case DXGI_FORMAT_R16_SINT: + case DXGI_FORMAT_R8_UINT: + case DXGI_FORMAT_R8_SINT: return true; + default: return false; + } +} + VkBlendFactor blend_factor(D3D12_BLEND blend) { switch (blend) { case D3D12_BLEND_ZERO: return VK_BLEND_FACTOR_ZERO; @@ -8343,7 +8375,7 @@ class PipelineState final return f == D3D12_BLEND_SRC1_COLOR || f == D3D12_BLEND_INV_SRC1_COLOR || f == D3D12_BLEND_SRC1_ALPHA || f == D3D12_BLEND_INV_SRC1_ALPHA; }; - if (b.BlendEnable && + if (b.BlendEnable && !integer_color_format(desc.RTVFormats[i]) && (src1(b.SrcBlend) || src1(b.DestBlend) || src1(b.SrcBlendAlpha) || src1(b.DestBlendAlpha))) dual_source = true; } @@ -8724,7 +8756,7 @@ class PipelineState final for (UINT i = 0; i < desc.NumRenderTargets; ++i) { const D3D12_RENDER_TARGET_BLEND_DESC& b = desc.BlendState.RenderTarget[desc.BlendState.IndependentBlendEnable ? i : 0]; - blends[i].blendEnable = b.BlendEnable; + blends[i].blendEnable = b.BlendEnable && !integer_color_format(desc.RTVFormats[i]); blends[i].srcColorBlendFactor = blend_factor(b.SrcBlend); blends[i].dstColorBlendFactor = blend_factor(b.DestBlend); blends[i].colorBlendOp = blend_op(b.BlendOp); diff --git a/runtime/test/d3d12_pso_validation_test.cpp b/runtime/test/d3d12_pso_validation_test.cpp index 89bee7bd26..5679d49217 100644 --- a/runtime/test/d3d12_pso_validation_test.cpp +++ b/runtime/test/d3d12_pso_validation_test.cpp @@ -388,6 +388,30 @@ int main() { })); } + // 3b. An integer target bypasses its blender. The console's native state keeps blending enabled for every + // target (CB_BLENDn is format-agnostic) and D3D12Xbox ignores it on integer surfaces; PC D3D12 rejects such a + // state at creation, and Vulkan requires blendEnable = VK_FALSE, so this is layer-only rather than parity. The + // target's write mask must survive. Adapted from DexNom/VIctory ddb7332 (GPL-3.0-or-later). + { + auto desc = make_gfx(layer_root.p, layer_vs_fs, layer_ps_uint); + desc.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UINT; + desc.BlendState.RenderTarget[0].BlendEnable = TRUE; + desc.BlendState.RenderTarget[0].SrcBlend = D3D12_BLEND_SRC_ALPHA; + desc.BlendState.RenderTarget[0].DestBlend = D3D12_BLEND_INV_SRC_ALPHA; + desc.BlendState.RenderTarget[0].BlendOp = D3D12_BLEND_OP_ADD; + desc.BlendState.RenderTarget[0].SrcBlendAlpha = D3D12_BLEND_ONE; + desc.BlendState.RenderTarget[0].DestBlendAlpha = D3D12_BLEND_ZERO; + desc.BlendState.RenderTarget[0].BlendOpAlpha = D3D12_BLEND_OP_ADD; + desc.BlendState.RenderTarget[0].RenderTargetWriteMask = D3D12_COLOR_WRITE_ENABLE_RED; + const HRESULT hr = create_graphics(layer_dev.p, desc); + if (hr != S_OK) { + std::fprintf(stderr, "FAIL [gfx: integer target bypasses blending]: layer returned 0x%08lx\n", + static_cast(hr)); + return 1; + } + ++checked; + } + // 4. RTVFormats validation. EXPECT(check_gfx_parity("gfx: RTVFormats[1]!=UNKNOWN with N=1", E_INVALIDARG, false, false, [](auto& d) { d.RTVFormats[1] = DXGI_FORMAT_R8G8B8A8_UNORM; }));