D3D12: Simplify lazy clear of render pass attachments

Bug: dawn:145
Change-Id: If4c83cdf4065acc9f68aa5d9a7e581e9f2e801a9
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/14982
Commit-Queue: Austin Eng <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
diff --git a/src/dawn_native/d3d12/CommandBufferD3D12.cpp b/src/dawn_native/d3d12/CommandBufferD3D12.cpp
index ac3f9cb..a6dcbc5 100644
--- a/src/dawn_native/d3d12/CommandBufferD3D12.cpp
+++ b/src/dawn_native/d3d12/CommandBufferD3D12.cpp
@@ -675,6 +675,8 @@
                     const bool passHasUAV =
                         TransitionForPass(commandContext, passResourceUsages[nextPassNumber]);
                     bindingTracker.SetInComputePass(false);
+
+                    LazyClearRenderPassAttachments(beginRenderPassCmd);
                     RecordRenderPass(commandContext, &bindingTracker, &renderPassTracker,
                                      beginRenderPassCmd, passHasUAV);
 
@@ -930,15 +932,6 @@
         for (uint32_t i : IterateBitSet(renderPass->attachmentState->GetColorAttachmentsMask())) {
             RenderPassColorAttachmentInfo& attachmentInfo = renderPass->colorAttachments[i];
             TextureView* view = ToBackend(attachmentInfo.view.Get());
-            Texture* texture = ToBackend(view->GetTexture());
-
-            // Load operation is changed to clear when the texture is uninitialized.
-            if (!texture->IsSubresourceContentInitialized(view->GetBaseMipLevel(), 1,
-                                                          view->GetBaseArrayLayer(), 1) &&
-                attachmentInfo.loadOp == wgpu::LoadOp::Load) {
-                attachmentInfo.loadOp = wgpu::LoadOp::Clear;
-                attachmentInfo.clearColor = {0.0f, 0.0f, 0.0f, 0.0f};
-            }
 
             // Set color load operation.
             renderPassBuilder->SetRenderTargetBeginningAccess(
@@ -953,46 +946,21 @@
                 resolveDestinationTexture->TransitionUsageNow(commandContext,
                                                               D3D12_RESOURCE_STATE_RESOLVE_DEST);
 
-                // Mark resolve target as initialized to prevent clearing later.
-                resolveDestinationTexture->SetIsSubresourceContentInitialized(
-                    true, resolveDestinationView->GetBaseMipLevel(), 1,
-                    resolveDestinationView->GetBaseArrayLayer(), 1);
-
                 renderPassBuilder->SetRenderTargetEndingAccessResolve(i, attachmentInfo.storeOp,
                                                                       view, resolveDestinationView);
             } else {
                 renderPassBuilder->SetRenderTargetEndingAccess(i, attachmentInfo.storeOp);
             }
-
-            // Set whether or not the texture requires initialization after the pass.
-            bool isInitialized = attachmentInfo.storeOp == wgpu::StoreOp::Store;
-            texture->SetIsSubresourceContentInitialized(isInitialized, view->GetBaseMipLevel(), 1,
-                                                        view->GetBaseArrayLayer(), 1);
         }
 
         if (renderPass->attachmentState->HasDepthStencilAttachment()) {
             RenderPassDepthStencilAttachmentInfo& attachmentInfo =
                 renderPass->depthStencilAttachment;
             TextureView* view = ToBackend(renderPass->depthStencilAttachment.view.Get());
-            Texture* texture = ToBackend(view->GetTexture());
 
             const bool hasDepth = view->GetTexture()->GetFormat().HasDepth();
             const bool hasStencil = view->GetTexture()->GetFormat().HasStencil();
 
-            // Load operations are changed to clear when the texture is uninitialized.
-            if (!view->GetTexture()->IsSubresourceContentInitialized(
-                    view->GetBaseMipLevel(), view->GetLevelCount(), view->GetBaseArrayLayer(),
-                    view->GetLayerCount())) {
-                if (hasDepth && attachmentInfo.depthLoadOp == wgpu::LoadOp::Load) {
-                    attachmentInfo.clearDepth = 0.0f;
-                    attachmentInfo.depthLoadOp = wgpu::LoadOp::Clear;
-                }
-                if (hasStencil && attachmentInfo.stencilLoadOp == wgpu::LoadOp::Load) {
-                    attachmentInfo.clearStencil = 0u;
-                    attachmentInfo.stencilLoadOp = wgpu::LoadOp::Clear;
-                }
-            }
-
             // Set depth/stencil load operations.
             if (hasDepth) {
                 renderPassBuilder->SetDepthAccess(
@@ -1010,12 +978,6 @@
                 renderPassBuilder->SetStencilNoAccess();
             }
 
-            // Set whether or not the texture requires initialization.
-            ASSERT(!hasDepth || !hasStencil ||
-                   attachmentInfo.depthStoreOp == attachmentInfo.stencilStoreOp);
-            bool isInitialized = attachmentInfo.depthStoreOp == wgpu::StoreOp::Store;
-            texture->SetIsSubresourceContentInitialized(isInitialized, view->GetBaseMipLevel(), 1,
-                                                        view->GetBaseArrayLayer(), 1);
         } else {
             renderPassBuilder->SetDepthStencilNoAccess();
         }