diff --git a/dawn.json b/dawn.json index 7e03a5ff1f..8d4851f202 100644 --- a/dawn.json +++ b/dawn.json @@ -857,7 +857,7 @@ "members": [ {"name": "color formats count", "type": "uint32_t"}, {"name": "color formats", "type": "texture format", "annotation": "const*", "length": "color formats count"}, - {"name": "depth stencil format", "type": "texture format", "annotation": "const*", "optional": true}, + {"name": "depth stencil format", "type": "texture format", "default": "none"}, {"name": "sample count", "type": "uint32_t", "default": "1"} ] }, diff --git a/src/dawn_native/AttachmentState.cpp b/src/dawn_native/AttachmentState.cpp index 00bd10ba13..f02aa73827 100644 --- a/src/dawn_native/AttachmentState.cpp +++ b/src/dawn_native/AttachmentState.cpp @@ -23,32 +23,27 @@ namespace dawn_native { AttachmentStateBlueprint::AttachmentStateBlueprint( const RenderBundleEncoderDescriptor* descriptor) - : mHasDepthStencilAttachment(descriptor->depthStencilFormat != nullptr), - mSampleCount(descriptor->sampleCount) { + : mSampleCount(descriptor->sampleCount) { for (uint32_t i = 0; i < descriptor->colorFormatsCount; ++i) { mColorAttachmentsSet.set(i); mColorFormats[i] = descriptor->colorFormats[i]; } - if (mHasDepthStencilAttachment) { - mDepthStencilFormat = *descriptor->depthStencilFormat; - } + mDepthStencilFormat = descriptor->depthStencilFormat; } AttachmentStateBlueprint::AttachmentStateBlueprint(const RenderPipelineDescriptor* descriptor) - : mHasDepthStencilAttachment(descriptor->depthStencilState != nullptr), - mSampleCount(descriptor->sampleCount) { + : mSampleCount(descriptor->sampleCount) { for (uint32_t i = 0; i < descriptor->colorStateCount; ++i) { ASSERT(descriptor->colorStates[i] != nullptr); mColorAttachmentsSet.set(i); mColorFormats[i] = descriptor->colorStates[i]->format; } - if (mHasDepthStencilAttachment) { + if (descriptor->depthStencilState != nullptr) { mDepthStencilFormat = descriptor->depthStencilState->format; } } - AttachmentStateBlueprint::AttachmentStateBlueprint(const RenderPassDescriptor* descriptor) - : mHasDepthStencilAttachment(descriptor->depthStencilAttachment != nullptr) { + AttachmentStateBlueprint::AttachmentStateBlueprint(const RenderPassDescriptor* descriptor) { for (uint32_t i = 0; i < descriptor->colorAttachmentCount; ++i) { TextureViewBase* attachment = descriptor->colorAttachments[i]->attachment; mColorAttachmentsSet.set(i); @@ -59,7 +54,7 @@ namespace dawn_native { ASSERT(mSampleCount == attachment->GetTexture()->GetSampleCount()); } } - if (mHasDepthStencilAttachment) { + if (descriptor->depthStencilAttachment != nullptr) { TextureViewBase* attachment = descriptor->depthStencilAttachment->attachment; mDepthStencilFormat = attachment->GetFormat().format; if (mSampleCount == 0) { @@ -84,10 +79,8 @@ namespace dawn_native { HashCombine(&hash, attachmentState->mColorFormats[i]); } - // Hash depth stencil attachments - if (attachmentState->mHasDepthStencilAttachment) { - HashCombine(&hash, attachmentState->mDepthStencilFormat); - } + // Hash depth stencil attachment + HashCombine(&hash, attachmentState->mDepthStencilFormat); // Hash sample count HashCombine(&hash, attachmentState->mSampleCount); @@ -99,8 +92,7 @@ namespace dawn_native { const AttachmentStateBlueprint* a, const AttachmentStateBlueprint* b) const { // Check set attachments - if (a->mColorAttachmentsSet != b->mColorAttachmentsSet || - a->mHasDepthStencilAttachment != b->mHasDepthStencilAttachment) { + if (a->mColorAttachmentsSet != b->mColorAttachmentsSet) { return false; } @@ -112,10 +104,8 @@ namespace dawn_native { } // Check depth stencil format - if (a->mHasDepthStencilAttachment) { - if (a->mDepthStencilFormat != b->mDepthStencilFormat) { - return false; - } + if (a->mDepthStencilFormat != b->mDepthStencilFormat) { + return false; } // Check sample count @@ -144,11 +134,11 @@ namespace dawn_native { } bool AttachmentState::HasDepthStencilAttachment() const { - return mHasDepthStencilAttachment; + return mDepthStencilFormat != dawn::TextureFormat::None; } dawn::TextureFormat AttachmentState::GetDepthStencilFormat() const { - ASSERT(mHasDepthStencilAttachment); + ASSERT(HasDepthStencilAttachment()); return mDepthStencilFormat; } diff --git a/src/dawn_native/AttachmentState.h b/src/dawn_native/AttachmentState.h index a7202fd682..1da074c2ac 100644 --- a/src/dawn_native/AttachmentState.h +++ b/src/dawn_native/AttachmentState.h @@ -51,8 +51,8 @@ namespace dawn_native { protected: std::bitset mColorAttachmentsSet; std::array mColorFormats; - bool mHasDepthStencilAttachment = false; - dawn::TextureFormat mDepthStencilFormat; + // Default (texture format None) indicates there is no depth stencil attachment. + dawn::TextureFormat mDepthStencilFormat = dawn::TextureFormat::None; uint32_t mSampleCount = 0; }; diff --git a/src/dawn_native/RenderBundleEncoder.cpp b/src/dawn_native/RenderBundleEncoder.cpp index 03bf7cc82b..9979ec429f 100644 --- a/src/dawn_native/RenderBundleEncoder.cpp +++ b/src/dawn_native/RenderBundleEncoder.cpp @@ -59,7 +59,8 @@ namespace dawn_native { return DAWN_VALIDATION_ERROR("Color formats count exceeds maximum"); } - if (descriptor->colorFormatsCount == 0 && !descriptor->depthStencilFormat) { + if (descriptor->colorFormatsCount == 0 && + descriptor->depthStencilFormat == dawn::TextureFormat::None) { return DAWN_VALIDATION_ERROR("Should have at least one attachment format"); } @@ -67,8 +68,8 @@ namespace dawn_native { DAWN_TRY(ValidateColorAttachmentFormat(device, descriptor->colorFormats[i])); } - if (descriptor->depthStencilFormat != nullptr) { - DAWN_TRY(ValidateDepthStencilAttachmentFormat(device, *descriptor->depthStencilFormat)); + if (descriptor->depthStencilFormat != dawn::TextureFormat::None) { + DAWN_TRY(ValidateDepthStencilAttachmentFormat(device, descriptor->depthStencilFormat)); } return {}; diff --git a/src/tests/unittests/validation/RenderBundleValidationTests.cpp b/src/tests/unittests/validation/RenderBundleValidationTests.cpp index 2baf2f1daf..54b3643a12 100644 --- a/src/tests/unittests/validation/RenderBundleValidationTests.cpp +++ b/src/tests/unittests/validation/RenderBundleValidationTests.cpp @@ -580,8 +580,7 @@ TEST_F(RenderBundleValidationTest, RequiresAtLeastOneTextureFormat) { // Test success with a depth stencil format. { utils::ComboRenderBundleEncoderDescriptor desc = {}; - desc.cDepthStencilFormat = dawn::TextureFormat::Depth24PlusStencil8; - desc.depthStencilFormat = &desc.cDepthStencilFormat; + desc.depthStencilFormat = dawn::TextureFormat::Depth24PlusStencil8; device.CreateRenderBundleEncoder(&desc); } } @@ -595,8 +594,7 @@ TEST_F(RenderBundleValidationTest, ColorFormatNone) { TEST_F(RenderBundleValidationTest, DepthStencilFormatNone) { utils::ComboRenderBundleEncoderDescriptor desc = {}; - const dawn::TextureFormat kFormatNone = dawn::TextureFormat::None; - desc.depthStencilFormat = &kFormatNone; + desc.depthStencilFormat = dawn::TextureFormat::None; ASSERT_DEVICE_ERROR(device.CreateRenderBundleEncoder(&desc)); } @@ -750,8 +748,7 @@ TEST_F(RenderBundleValidationTest, PipelineDepthStencilFormatMismatch) { utils::ComboRenderBundleEncoderDescriptor renderBundleDesc = {}; renderBundleDesc.colorFormatsCount = 1; renderBundleDesc.cColorFormats[0] = dawn::TextureFormat::RGBA8Unorm; - renderBundleDesc.cDepthStencilFormat = dawn::TextureFormat::Depth24PlusStencil8; - renderBundleDesc.depthStencilFormat = &renderBundleDesc.cDepthStencilFormat; + renderBundleDesc.depthStencilFormat = dawn::TextureFormat::Depth24PlusStencil8; utils::ComboRenderPipelineDescriptor renderPipelineDesc(device); InitializeRenderPipelineDescriptor(&renderPipelineDesc); @@ -905,8 +902,7 @@ TEST_F(RenderBundleValidationTest, RenderPassDepthStencilFormatMismatch) { utils::ComboRenderBundleEncoderDescriptor renderBundleDesc = {}; renderBundleDesc.colorFormatsCount = 1; renderBundleDesc.cColorFormats[0] = dawn::TextureFormat::RGBA8Unorm; - renderBundleDesc.cDepthStencilFormat = dawn::TextureFormat::Depth24Plus; - renderBundleDesc.depthStencilFormat = &renderBundleDesc.cDepthStencilFormat; + renderBundleDesc.depthStencilFormat = dawn::TextureFormat::Depth24Plus; dawn::RenderBundleEncoder renderBundleEncoder = device.CreateRenderBundleEncoder(&renderBundleDesc); @@ -1024,8 +1020,7 @@ TEST_F(RenderBundleValidationTest, TextureFormats) { // Test that depth/stencil formats are validated as depth/stencil. { utils::ComboRenderBundleEncoderDescriptor desc = {}; - desc.cDepthStencilFormat = dawn::TextureFormat::RGBA8Unorm; - desc.depthStencilFormat = &desc.cDepthStencilFormat; + desc.depthStencilFormat = dawn::TextureFormat::RGBA8Unorm; ASSERT_DEVICE_ERROR(device.CreateRenderBundleEncoder(&desc)); } diff --git a/src/utils/ComboRenderBundleEncoderDescriptor.cpp b/src/utils/ComboRenderBundleEncoderDescriptor.cpp index 86e1f26014..82427379ed 100644 --- a/src/utils/ComboRenderBundleEncoderDescriptor.cpp +++ b/src/utils/ComboRenderBundleEncoderDescriptor.cpp @@ -21,8 +21,6 @@ namespace utils { ComboRenderBundleEncoderDescriptor::ComboRenderBundleEncoderDescriptor() { dawn::RenderBundleEncoderDescriptor* descriptor = this; - descriptor->sampleCount = 1; - descriptor->depthStencilFormat = nullptr; descriptor->colorFormatsCount = 0; descriptor->colorFormats = &cColorFormats[0]; } diff --git a/src/utils/ComboRenderBundleEncoderDescriptor.h b/src/utils/ComboRenderBundleEncoderDescriptor.h index e8296936b6..dbf833583d 100644 --- a/src/utils/ComboRenderBundleEncoderDescriptor.h +++ b/src/utils/ComboRenderBundleEncoderDescriptor.h @@ -28,7 +28,6 @@ namespace utils { ComboRenderBundleEncoderDescriptor(); std::array cColorFormats; - dawn::TextureFormat cDepthStencilFormat; }; } // namespace utils