diff --git a/src/dawn_native/CommandEncoder.cpp b/src/dawn_native/CommandEncoder.cpp index d2c1543f66..3aae8c9ce8 100644 --- a/src/dawn_native/CommandEncoder.cpp +++ b/src/dawn_native/CommandEncoder.cpp @@ -325,7 +325,8 @@ namespace dawn_native { const DeviceBase* device, const RenderPassDepthStencilAttachmentDescriptor* depthStencilAttachment, uint32_t* width, - uint32_t* height) { + uint32_t* height, + uint32_t* sampleCount) { DAWN_ASSERT(depthStencilAttachment != nullptr); DAWN_TRY(device->ValidateObject(depthStencilAttachment->attachment)); @@ -337,6 +338,12 @@ namespace dawn_native { "depth stencil format"); } + // *sampleCount == 0 must only happen when there is no color attachment. In that case we + // do not need to validate the sample count of the depth stencil attachment. + if (*sampleCount != 0 && (attachment->GetTexture()->GetSampleCount() != *sampleCount)) { + return DAWN_VALIDATION_ERROR("Depth stencil attachment sample counts mismatch"); + } + DAWN_TRY(ValidateAttachmentArrayLayersAndLevelCount(attachment)); DAWN_TRY(ValidateOrSetAttachmentSize(attachment, width, height)); @@ -359,7 +366,7 @@ namespace dawn_native { if (renderPass->depthStencilAttachment != nullptr) { DAWN_TRY(ValidateRenderPassDepthStencilAttachment( - device, renderPass->depthStencilAttachment, width, height)); + device, renderPass->depthStencilAttachment, width, height, &sampleCount)); } if (renderPass->colorAttachmentCount == 0 && diff --git a/src/tests/unittests/validation/RenderPassDescriptorValidationTests.cpp b/src/tests/unittests/validation/RenderPassDescriptorValidationTests.cpp index b8130d36ed..b532a957ea 100644 --- a/src/tests/unittests/validation/RenderPassDescriptorValidationTests.cpp +++ b/src/tests/unittests/validation/RenderPassDescriptorValidationTests.cpp @@ -583,6 +583,50 @@ TEST_F(MultisampledRenderPassDescriptorValidationTest, ColorAttachmentResolveTar } } +// Tests on the sample count of depth stencil attachment. +TEST_F(MultisampledRenderPassDescriptorValidationTest, DepthStencilAttachmentSampleCount) { + constexpr dawn::TextureFormat kDepthStencilFormat = dawn::TextureFormat::D32FloatS8Uint; + dawn::Texture multisampledDepthStencilTexture = CreateTexture( + device, dawn::TextureDimension::e2D, kDepthStencilFormat, kSize, kSize, kArrayLayers, + kLevelCount, kSampleCount); + dawn::TextureView multisampledDepthStencilTextureView = + multisampledDepthStencilTexture.CreateDefaultTextureView(); + + // It is not allowed to use a depth stencil attachment whose sample count is different from the + // one of the color attachment. + { + dawn::Texture depthStencilTexture = CreateTexture( + device, dawn::TextureDimension::e2D, kDepthStencilFormat, kSize, kSize, kArrayLayers, + kLevelCount); + dawn::TextureView depthStencilTextureView = depthStencilTexture.CreateDefaultTextureView(); + + utils::ComboRenderPassDescriptor renderPass( + {CreateMultisampledColorTextureView()}, depthStencilTextureView); + AssertBeginRenderPassError(&renderPass); + } + + { + utils::ComboRenderPassDescriptor renderPass( + {CreateNonMultisampledColorTextureView()}, multisampledDepthStencilTextureView); + AssertBeginRenderPassError(&renderPass); + } + + // It is allowed to use a multisampled depth stencil attachment whose sample count is equal to + // the one of the color attachment. + { + utils::ComboRenderPassDescriptor renderPass( + {CreateMultisampledColorTextureView()}, multisampledDepthStencilTextureView); + AssertBeginRenderPassSuccess(&renderPass); + } + + // It is allowed to use a multisampled depth stencil attachment while there is no color + // attachment. + { + utils::ComboRenderPassDescriptor renderPass({}, multisampledDepthStencilTextureView); + AssertBeginRenderPassSuccess(&renderPass); + } +} + // TODO(cwallez@chromium.org): Constraints on attachment aliasing? } // anonymous namespace