[dawn][headers] Make RenderPassDepthStencilAttachment extensible.

Bug: 378514256
Change-Id: I335f08b7fe424d25454796c1dde0d9009156aad0
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/223734
Auto-Submit: Loko Kung <lokokung@google.com>
Commit-Queue: Loko Kung <lokokung@google.com>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Kai Ninomiya <kainino@chromium.org>
diff --git a/src/dawn/dawn.json b/src/dawn/dawn.json
index 7ff451e..6a0e92c 100644
--- a/src/dawn/dawn.json
+++ b/src/dawn/dawn.json
@@ -2918,6 +2918,7 @@
     },
     "render pass depth stencil attachment": {
         "category": "structure",
+        "extensible": "in",
         "members": [
             {"name": "view", "type": "texture view"},
             {"name": "depth load op", "type": "load op", "default": "undefined"},
diff --git a/src/dawn/native/CommandEncoder.cpp b/src/dawn/native/CommandEncoder.cpp
index 4f80264..f2b3a5c 100644
--- a/src/dawn/native/CommandEncoder.cpp
+++ b/src/dawn/native/CommandEncoder.cpp
@@ -610,8 +610,10 @@
     UsageValidationMode usageValidationMode,
     RenderPassValidationState* validationState) {
     DAWN_ASSERT(depthStencilAttachment != nullptr);
+    UnpackedPtr<RenderPassDepthStencilAttachment> unpacked;
+    DAWN_TRY_ASSIGN(unpacked, ValidateAndUnpack(depthStencilAttachment));
 
-    TextureViewBase* attachment = depthStencilAttachment->view;
+    TextureViewBase* attachment = unpacked->view;
     DAWN_TRY(device->ValidateObject(attachment));
     DAWN_TRY(
         ValidateCanUseAs(attachment, wgpu::TextureUsage::RenderAttachment, usageValidationMode));
@@ -635,64 +637,59 @@
                     format.format);
 
     // Read only, or depth doesn't exist.
-    if (depthStencilAttachment->depthReadOnly ||
-        !IsSubset(Aspect::Depth, attachment->GetAspects())) {
-        DAWN_INVALID_IF(depthStencilAttachment->depthLoadOp != wgpu::LoadOp::Undefined ||
-                            depthStencilAttachment->depthStoreOp != wgpu::StoreOp::Undefined,
+    if (unpacked->depthReadOnly || !IsSubset(Aspect::Depth, attachment->GetAspects())) {
+        DAWN_INVALID_IF(unpacked->depthLoadOp != wgpu::LoadOp::Undefined ||
+                            unpacked->depthStoreOp != wgpu::StoreOp::Undefined,
                         "Both depthLoadOp (%s) and depthStoreOp (%s) must not be set if the "
                         "attachment (%s) has no depth aspect or depthReadOnly (%u) is true.",
-                        depthStencilAttachment->depthLoadOp, depthStencilAttachment->depthStoreOp,
-                        attachment, depthStencilAttachment->depthReadOnly);
+                        unpacked->depthLoadOp, unpacked->depthStoreOp, attachment,
+                        unpacked->depthReadOnly);
     } else {
-        DAWN_TRY(ValidateLoadOp(depthStencilAttachment->depthLoadOp));
-        DAWN_TRY(ValidateStoreOp(depthStencilAttachment->depthStoreOp));
-        DAWN_INVALID_IF(depthStencilAttachment->depthLoadOp == wgpu::LoadOp::Undefined ||
-                            depthStencilAttachment->depthStoreOp == wgpu::StoreOp::Undefined,
+        DAWN_TRY(ValidateLoadOp(unpacked->depthLoadOp));
+        DAWN_TRY(ValidateStoreOp(unpacked->depthStoreOp));
+        DAWN_INVALID_IF(unpacked->depthLoadOp == wgpu::LoadOp::Undefined ||
+                            unpacked->depthStoreOp == wgpu::StoreOp::Undefined,
                         "Both depthLoadOp (%s) and depthStoreOp (%s) must be set if the attachment "
                         "(%s) has a depth aspect or depthReadOnly (%u) is false.",
-                        depthStencilAttachment->depthLoadOp, depthStencilAttachment->depthStoreOp,
-                        attachment, depthStencilAttachment->depthReadOnly);
+                        unpacked->depthLoadOp, unpacked->depthStoreOp, attachment,
+                        unpacked->depthReadOnly);
     }
 
-    DAWN_INVALID_IF(depthStencilAttachment->depthLoadOp == wgpu::LoadOp::ExpandResolveTexture ||
-                        depthStencilAttachment->stencilLoadOp == wgpu::LoadOp::ExpandResolveTexture,
+    DAWN_INVALID_IF(unpacked->depthLoadOp == wgpu::LoadOp::ExpandResolveTexture ||
+                        unpacked->stencilLoadOp == wgpu::LoadOp::ExpandResolveTexture,
                     "%s is not supported on depth/stencil attachment",
                     wgpu::LoadOp::ExpandResolveTexture);
 
     // Read only, or stencil doesn't exist.
-    if (depthStencilAttachment->stencilReadOnly ||
-        !IsSubset(Aspect::Stencil, attachment->GetAspects())) {
-        DAWN_INVALID_IF(depthStencilAttachment->stencilLoadOp != wgpu::LoadOp::Undefined ||
-                            depthStencilAttachment->stencilStoreOp != wgpu::StoreOp::Undefined,
+    if (unpacked->stencilReadOnly || !IsSubset(Aspect::Stencil, attachment->GetAspects())) {
+        DAWN_INVALID_IF(unpacked->stencilLoadOp != wgpu::LoadOp::Undefined ||
+                            unpacked->stencilStoreOp != wgpu::StoreOp::Undefined,
                         "Both stencilLoadOp (%s) and stencilStoreOp (%s) must not be set if the "
                         "attachment (%s) has no stencil aspect or stencilReadOnly (%u) is true.",
-                        depthStencilAttachment->stencilLoadOp,
-                        depthStencilAttachment->stencilStoreOp, attachment,
-                        depthStencilAttachment->stencilReadOnly);
+                        unpacked->stencilLoadOp, unpacked->stencilStoreOp, attachment,
+                        unpacked->stencilReadOnly);
     } else {
-        DAWN_TRY(ValidateLoadOp(depthStencilAttachment->stencilLoadOp));
-        DAWN_TRY(ValidateStoreOp(depthStencilAttachment->stencilStoreOp));
-        DAWN_INVALID_IF(depthStencilAttachment->stencilLoadOp == wgpu::LoadOp::Undefined ||
-                            depthStencilAttachment->stencilStoreOp == wgpu::StoreOp::Undefined,
+        DAWN_TRY(ValidateLoadOp(unpacked->stencilLoadOp));
+        DAWN_TRY(ValidateStoreOp(unpacked->stencilStoreOp));
+        DAWN_INVALID_IF(unpacked->stencilLoadOp == wgpu::LoadOp::Undefined ||
+                            unpacked->stencilStoreOp == wgpu::StoreOp::Undefined,
                         "Both stencilLoadOp (%s) and stencilStoreOp (%s) must be set if the "
                         "attachment (%s) has a stencil aspect or stencilReadOnly (%u) is false.",
-                        depthStencilAttachment->stencilLoadOp,
-                        depthStencilAttachment->stencilStoreOp, attachment,
-                        depthStencilAttachment->stencilReadOnly);
+                        unpacked->stencilLoadOp, unpacked->stencilStoreOp, attachment,
+                        unpacked->stencilReadOnly);
     }
 
-    if (depthStencilAttachment->depthLoadOp == wgpu::LoadOp::Clear &&
+    if (unpacked->depthLoadOp == wgpu::LoadOp::Clear &&
         IsSubset(Aspect::Depth, attachment->GetAspects())) {
         DAWN_INVALID_IF(
-            std::isnan(depthStencilAttachment->depthClearValue),
+            std::isnan(unpacked->depthClearValue),
             "depthClearValue (%f) must be set and must not be a NaN value if the attachment "
             "(%s) has a depth aspect and depthLoadOp is clear.",
-            depthStencilAttachment->depthClearValue, attachment);
-        DAWN_INVALID_IF(depthStencilAttachment->depthClearValue < 0.0f ||
-                            depthStencilAttachment->depthClearValue > 1.0f,
+            unpacked->depthClearValue, attachment);
+        DAWN_INVALID_IF(unpacked->depthClearValue < 0.0f || unpacked->depthClearValue > 1.0f,
                         "depthClearValue (%f) must be between 0.0 and 1.0 if the attachment (%s) "
                         "has a depth aspect and depthLoadOp is clear.",
-                        depthStencilAttachment->depthClearValue, attachment);
+                        unpacked->depthClearValue, attachment);
     }
 
     DAWN_TRY(ValidateAttachmentArrayLayersAndLevelCount(attachment));
diff --git a/src/dawn/tests/unittests/validation/RenderPassDescriptorValidationTests.cpp b/src/dawn/tests/unittests/validation/RenderPassDescriptorValidationTests.cpp
index cc259fe..b81613c 100644
--- a/src/dawn/tests/unittests/validation/RenderPassDescriptorValidationTests.cpp
+++ b/src/dawn/tests/unittests/validation/RenderPassDescriptorValidationTests.cpp
@@ -578,6 +578,20 @@
     }
 }
 
+// Check that the render pass depth attachment should not have any chained structs on it.
+TEST_F(RenderPassDescriptorValidationTest, DepthAttachmentChained) {
+    wgpu::TextureView renderView =
+        Create2DAttachment(device, 1, 1, wgpu::TextureFormat::Depth32Float);
+    utils::ComboRenderPassDescriptor renderPass({}, renderView);
+    renderPass.cDepthStencilAttachmentInfo.stencilLoadOp = wgpu::LoadOp::Undefined;
+    renderPass.cDepthStencilAttachmentInfo.stencilStoreOp = wgpu::StoreOp::Undefined;
+
+    wgpu::ChainedStruct chain = {};
+    renderPass.cDepthStencilAttachmentInfo.nextInChain = &chain;
+
+    AssertBeginRenderPassError(&renderPass);
+}
+
 // Check that the render pass depth attachment must have the RenderAttachment usage.
 TEST_F(RenderPassDescriptorValidationTest, DepthAttachmentInvalidUsage) {
     // Control case: using a texture with RenderAttachment is valid.