[graphite] Store DepthStencilSettings on ShaderInfo

In the long term, RenderStep will only store its StencilSettings and
it will have flags that control how the depth test/write state are
set in combination with drawpass-level requirements.

Bug: 500416105
Change-Id: I73a57ee3ca4ceab78b6415bdecee87092a56d423
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/1374016
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
Reviewed-by: Thomas Smith <thomsmit@google.com>
diff --git a/src/gpu/graphite/ShaderInfo.cpp b/src/gpu/graphite/ShaderInfo.cpp
index dfe1afa..61c0665 100644
--- a/src/gpu/graphite/ShaderInfo.cpp
+++ b/src/gpu/graphite/ShaderInfo.cpp
@@ -1108,6 +1108,10 @@
 
     result->fStorageBufferStages |= step->storageBufferStages();
 
+    // TODO(michaelludwig): Modify the depth portion of the DepthStencilSettings depending on
+    // whether or not depth is going to be useful (and whether or not the render pass has it).
+    result->fDepthStencilSettings = step->depthStencilSettings();
+
     result->generateVertexSkSL(caps, step, sharedData);
     result->fVSLabel = step->name();
     if (sharedData.fNeedsLocalCoords) {
diff --git a/src/gpu/graphite/ShaderInfo.h b/src/gpu/graphite/ShaderInfo.h
index c008e0f..e2b5852 100644
--- a/src/gpu/graphite/ShaderInfo.h
+++ b/src/gpu/graphite/ShaderInfo.h
@@ -63,6 +63,8 @@
 
     const char* uniformSsboIndex() const { return fUniformSsboIndex; }
 
+    const DepthStencilSettings& depthStencilSettings() const { return fDepthStencilSettings; }
+
     DstReadStrategy dstReadStrategy() const { return fDstReadStrategy; }
     const skgpu::BlendInfo& blendInfo() const { return fBlendInfo; }
 
@@ -115,10 +117,20 @@
                             const RenderStep*,
                             const SharedGeneratorData&);
 
+#if defined(GPU_TEST_UTILS)
+    friend class TextureFallbackTest;
+    static std::string EmitStorageFallbackTexture(const ResourceBindingRequirements&,
+                                                  const RenderStep*);
+#endif
+
     const ShaderCodeDictionary* fShaderCodeDictionary;
     const RuntimeEffectDictionary* fRuntimeEffectDictionary;
     const char* fUniformSsboIndex;
 
+    // The final DepthStencilSettings for the pipeline, combined from the RenderStep's requirements
+    // and the rest of the render pass.
+    DepthStencilSettings fDepthStencilSettings;
+
     // The blendInfo represents the actual GPU blend operations, which may or may not completely
     // implement the paint and coverage blending defined by the root nodes.
     skgpu::BlendInfo fBlendInfo;
@@ -134,12 +146,6 @@
     bool fHasCombinedUniforms = false;
     SkEnumBitMask<PipelineStageFlags> fStorageBufferStages = {};
 
-#if defined(GPU_TEST_UTILS)
-    friend class TextureFallbackTest;
-    static std::string EmitStorageFallbackTexture(const ResourceBindingRequirements&,
-                                                  const RenderStep*);
-#endif
-
     // Append attributes defined by the render step and any attributes within the paint key via
     // a mesh shader snippet.
     skia_private::TArray<Attribute> fAppendAttrs;
diff --git a/src/gpu/graphite/dawn/DawnGraphicsPipeline.cpp b/src/gpu/graphite/dawn/DawnGraphicsPipeline.cpp
index 76c3fd5..f049e21 100644
--- a/src/gpu/graphite/dawn/DawnGraphicsPipeline.cpp
+++ b/src/gpu/graphite/dawn/DawnGraphicsPipeline.cpp
@@ -458,7 +458,7 @@
     descriptor.fragment = &fragment;
 
     // Depth stencil state
-    const auto& depthStencilSettings = step->depthStencilSettings();
+    const auto& depthStencilSettings = shaderInfo->depthStencilSettings();
 
     TextureFormat dsFormat = renderPassDesc.fDepthStencilAttachment.fFormat;
     SkASSERT(dsFormat != TextureFormat::kUnsupported || !depthStencilSettings);
diff --git a/src/gpu/graphite/mtl/MtlGraphicsPipeline.mm b/src/gpu/graphite/mtl/MtlGraphicsPipeline.mm
index d112c22..895f5dd 100644
--- a/src/gpu/graphite/mtl/MtlGraphicsPipeline.mm
+++ b/src/gpu/graphite/mtl/MtlGraphicsPipeline.mm
@@ -291,7 +291,7 @@
             sharedContext, shaderInfo->fsLabel(), fsMSL.fText, errorHandler);
 
     sk_cfp<id<MTLDepthStencilState>> dss =
-            sharedContext->getCompatibleDepthStencilState(step->depthStencilSettings());
+            sharedContext->getCompatibleDepthStencilState(shaderInfo->depthStencilSettings());
 
     PipelineInfo pipelineInfo{ *shaderInfo, pipelineCreationFlags,
                                pipelineKey.hash(), compilationID };
@@ -310,7 +310,7 @@
                shaderInfo->appendAttributes(),
                {fsLibrary.get(), "fragmentMain"},
                std::move(dss),
-               step->depthStencilSettings().fStencilReferenceValue,
+               shaderInfo->depthStencilSettings().fStencilReferenceValue,
                blendInfo,
                renderPassDesc);
 }
diff --git a/src/gpu/graphite/vk/VulkanGraphicsPipeline.cpp b/src/gpu/graphite/vk/VulkanGraphicsPipeline.cpp
index 85c24aa..b074466 100644
--- a/src/gpu/graphite/vk/VulkanGraphicsPipeline.cpp
+++ b/src/gpu/graphite/vk/VulkanGraphicsPipeline.cpp
@@ -273,7 +273,6 @@
         stencilInfo->depthTestEnable = stencilSettings.depthEnabled();
         stencilInfo->depthWriteEnable = stencilSettings.fDepthWriteEnabled;
         stencilInfo->depthCompareOp = compare_op_to_vk_compare_op(stencilSettings.fDepthCompareOp);
-        stencilInfo->depthBoundsTestEnable = VK_FALSE;
         stencilInfo->stencilTestEnable = stencilSettings.stencilEnabled();
         if (stencilInfo->stencilTestEnable) {
             setup_stencil_op_state(&stencilInfo->front,
@@ -287,6 +286,8 @@
                                    stencilSettings.fStencilReadMask,
                                    stencilSettings.fStencilWriteMask);
         }
+
+        stencilInfo->depthBoundsTestEnable = VK_FALSE;
         stencilInfo->minDepthBounds = 0.0f;
         stencilInfo->maxDepthBounds = 1.0f;
     }
@@ -994,7 +995,7 @@
             shaderInfo->appendAttributes(),
             vertexBindingDescriptions,
             vertexAttributeDescriptions,
-            step->depthStencilSettings(),
+            shaderInfo->depthStencilSettings(),
             shaderInfo->blendInfo(),
             renderPassDesc,
             &shadersPipeline);