Fix fuzzer error when ExpandResolveTexture is used on error texture

Bug: 341142177
Change-Id: I9d7d78694629c5bffdbe4c31a8d62939b7c484a9
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/189082
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Quyen Le <lehoangquyen@chromium.org>
diff --git a/src/dawn/native/CommandEncoder.cpp b/src/dawn/native/CommandEncoder.cpp
index 741ca27..6a3492a 100644
--- a/src/dawn/native/CommandEncoder.cpp
+++ b/src/dawn/native/CommandEncoder.cpp
@@ -497,8 +497,10 @@
                     "The color attachment %s's sample count (%u) is not supported by %s.",
                     colorAttachment.view, textureSampleCount, wgpu::LoadOp::ExpandResolveTexture);
 
-    DAWN_INVALID_IF(colorAttachment.resolveTarget == nullptr, "%s is used without resolve target.",
-                    wgpu::LoadOp::ExpandResolveTexture);
+    // These should already be validated before entering this function.
+    DAWN_ASSERT(colorAttachment.resolveTarget != nullptr &&
+                !colorAttachment.resolveTarget->IsError());
+    DAWN_ASSERT(colorAttachment.view->GetFormat().supportsResolveTarget);
 
     DAWN_INVALID_IF((colorAttachment.resolveTarget->GetTexture()->GetUsage() &
                      wgpu::TextureUsage::TextureBinding) == 0,
@@ -507,12 +509,6 @@
                     colorAttachment.resolveTarget, wgpu::TextureUsage::TextureBinding,
                     wgpu::LoadOp::ExpandResolveTexture);
 
-    DAWN_INVALID_IF(!colorAttachment.view->GetFormat().supportsResolveTarget,
-                    "The color attachment %s format (%s) does not support being used with "
-                    "%s. The format does not support resolve.",
-                    colorAttachment.view, colorAttachment.view->GetFormat().format,
-                    wgpu::LoadOp::ExpandResolveTexture);
-
     validationState->SetWillExpandResolveTexture(true);
 
     return {};
@@ -575,7 +571,8 @@
                             std::isnan(clearValue.b) || std::isnan(clearValue.a),
                         "Color clear value (%s) contains a NaN.", &clearValue);
     } else if (colorAttachment.loadOp == wgpu::LoadOp::ExpandResolveTexture) {
-        DAWN_TRY(ValidateExpandResolveTextureLoadOp(device, colorAttachment, validationState));
+        DAWN_INVALID_IF(colorAttachment.resolveTarget == nullptr,
+                        "%s is used without resolve target.", wgpu::LoadOp::ExpandResolveTexture);
     }
 
     DAWN_TRY(ValidateColorAttachmentDepthSlice(attachment, colorAttachment.depthSlice));
@@ -588,6 +585,10 @@
         // This step is skipped if implicitSampleCount > 1, because in that case, there shoudn't be
         // any explicit resolveTarget specified.
         DAWN_TRY(ValidateResolveTarget(device, colorAttachment, usageValidationMode));
+
+        if (colorAttachment.loadOp == wgpu::LoadOp::ExpandResolveTexture) {
+            DAWN_TRY(ValidateExpandResolveTextureLoadOp(device, colorAttachment, validationState));
+        }
         // Add resolve target after adding color attachment to make sure there is already a color
         // attachment for the comparation of with and height.
         DAWN_TRY(validationState->AddAttachment(colorAttachment.resolveTarget,
diff --git a/src/dawn/tests/unittests/validation/RenderPassDescriptorValidationTests.cpp b/src/dawn/tests/unittests/validation/RenderPassDescriptorValidationTests.cpp
index 2e1efd8..a8dfa65 100644
--- a/src/dawn/tests/unittests/validation/RenderPassDescriptorValidationTests.cpp
+++ b/src/dawn/tests/unittests/validation/RenderPassDescriptorValidationTests.cpp
@@ -1968,7 +1968,8 @@
     renderPass.cColorAttachments[0].view = multisampledTexture.CreateView();
     renderPass.cColorAttachments[0].resolveTarget = resolveTexture.CreateView();
     renderPass.cColorAttachments[0].loadOp = wgpu::LoadOp::ExpandResolveTexture;
-    AssertBeginRenderPassError(&renderPass, testing::HasSubstr("does not support resolve"));
+    AssertBeginRenderPassError(&renderPass,
+                               testing::HasSubstr("does not support being used as resolve target"));
 }
 
 // The LoadOp is NOT currently supported on depth/stencil attachment.