From 30fa0d8d2ced43e44baa522dd4bd4684b14a3099 Mon Sep 17 00:00:00 2001 From: Loko Kung Date: Thu, 18 Aug 2022 02:34:40 +0000 Subject: [PATCH] Makes sure to zero-init D3D12 descriptors for cache keys. Fixed: dawn:1471 Change-Id: I2692d3caa9b0d4dabe473b7a7d5249473da80c5b Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/99600 Auto-Submit: Loko Kung Commit-Queue: Austin Eng Reviewed-by: Austin Eng Kokoro: Kokoro --- src/dawn/native/d3d12/RenderPipelineD3D12.cpp | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/dawn/native/d3d12/RenderPipelineD3D12.cpp b/src/dawn/native/d3d12/RenderPipelineD3D12.cpp index e33d19f937..b1da726691 100644 --- a/src/dawn/native/d3d12/RenderPipelineD3D12.cpp +++ b/src/dawn/native/d3d12/RenderPipelineD3D12.cpp @@ -235,7 +235,7 @@ uint8_t D3D12RenderTargetWriteMask(wgpu::ColorWriteMask writeMask) { } D3D12_RENDER_TARGET_BLEND_DESC ComputeColorDesc(const ColorTargetState* state) { - D3D12_RENDER_TARGET_BLEND_DESC blendDesc; + D3D12_RENDER_TARGET_BLEND_DESC blendDesc = {}; blendDesc.BlendEnable = state->blend != nullptr; if (blendDesc.BlendEnable) { blendDesc.SrcBlend = D3D12Blend(state->blend->color.srcFactor); @@ -273,7 +273,7 @@ D3D12_STENCIL_OP StencilOp(wgpu::StencilOperation op) { } D3D12_DEPTH_STENCILOP_DESC StencilOpDesc(const StencilFaceState& descriptor) { - D3D12_DEPTH_STENCILOP_DESC desc; + D3D12_DEPTH_STENCILOP_DESC desc = {}; desc.StencilFailOp = StencilOp(descriptor.failOp); desc.StencilDepthFailOp = StencilOp(descriptor.depthFailOp); @@ -284,23 +284,23 @@ D3D12_DEPTH_STENCILOP_DESC StencilOpDesc(const StencilFaceState& descriptor) { } D3D12_DEPTH_STENCIL_DESC ComputeDepthStencilDesc(const DepthStencilState* descriptor) { - D3D12_DEPTH_STENCIL_DESC mDepthStencilDescriptor; - mDepthStencilDescriptor.DepthEnable = + D3D12_DEPTH_STENCIL_DESC depthStencilDescriptor = {}; + depthStencilDescriptor.DepthEnable = (descriptor->depthCompare == wgpu::CompareFunction::Always && !descriptor->depthWriteEnabled) ? FALSE : TRUE; - mDepthStencilDescriptor.DepthWriteMask = + depthStencilDescriptor.DepthWriteMask = descriptor->depthWriteEnabled ? D3D12_DEPTH_WRITE_MASK_ALL : D3D12_DEPTH_WRITE_MASK_ZERO; - mDepthStencilDescriptor.DepthFunc = ToD3D12ComparisonFunc(descriptor->depthCompare); + depthStencilDescriptor.DepthFunc = ToD3D12ComparisonFunc(descriptor->depthCompare); - mDepthStencilDescriptor.StencilEnable = StencilTestEnabled(descriptor) ? TRUE : FALSE; - mDepthStencilDescriptor.StencilReadMask = static_cast(descriptor->stencilReadMask); - mDepthStencilDescriptor.StencilWriteMask = static_cast(descriptor->stencilWriteMask); + depthStencilDescriptor.StencilEnable = StencilTestEnabled(descriptor) ? TRUE : FALSE; + depthStencilDescriptor.StencilReadMask = static_cast(descriptor->stencilReadMask); + depthStencilDescriptor.StencilWriteMask = static_cast(descriptor->stencilWriteMask); - mDepthStencilDescriptor.FrontFace = StencilOpDesc(descriptor->stencilFront); - mDepthStencilDescriptor.BackFace = StencilOpDesc(descriptor->stencilBack); - return mDepthStencilDescriptor; + depthStencilDescriptor.FrontFace = StencilOpDesc(descriptor->stencilFront); + depthStencilDescriptor.BackFace = StencilOpDesc(descriptor->stencilBack); + return depthStencilDescriptor; } D3D12_INDEX_BUFFER_STRIP_CUT_VALUE ComputeIndexBufferStripCutValue( @@ -402,9 +402,6 @@ MaybeError RenderPipeline::Initialize() { static_assert(kMaxColorAttachments == 8); for (uint8_t i = 0; i < kMaxColorAttachments; i++) { descriptorD3D12.RTVFormats[i] = DXGI_FORMAT_UNKNOWN; - descriptorD3D12.BlendState.RenderTarget[i].BlendEnable = false; - descriptorD3D12.BlendState.RenderTarget[i].RenderTargetWriteMask = 0; - descriptorD3D12.BlendState.RenderTarget[i].LogicOpEnable = false; descriptorD3D12.BlendState.RenderTarget[i].LogicOp = D3D12_LOGIC_OP_NOOP; } ColorAttachmentIndex highestColorAttachmentIndexPlusOne =