Use TextureFormat::None for RenderBundleEncoder and AttachmentState
Bug: dawn:214
Change-Id: Ia9432582b0a5627c00d46ebcfa63ebf1ba246651
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/10520
Commit-Queue: Kai Ninomiya <kainino@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
diff --git a/dawn.json b/dawn.json
index 7e03a5f..8d4851f 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 00bd10b..f02aa73 100644
--- a/src/dawn_native/AttachmentState.cpp
+++ b/src/dawn_native/AttachmentState.cpp
@@ -23,32 +23,27 @@
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 @@
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 @@
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 @@
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 @@
}
// 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 @@
}
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 a7202fd..1da074c 100644
--- a/src/dawn_native/AttachmentState.h
+++ b/src/dawn_native/AttachmentState.h
@@ -51,8 +51,8 @@
protected:
std::bitset<kMaxColorAttachments> mColorAttachmentsSet;
std::array<dawn::TextureFormat, kMaxColorAttachments> 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 03bf7cc..9979ec4 100644
--- a/src/dawn_native/RenderBundleEncoder.cpp
+++ b/src/dawn_native/RenderBundleEncoder.cpp
@@ -59,7 +59,8 @@
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 @@
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 2baf2f1..54b3643 100644
--- a/src/tests/unittests/validation/RenderBundleValidationTests.cpp
+++ b/src/tests/unittests/validation/RenderBundleValidationTests.cpp
@@ -580,8 +580,7 @@
// 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, 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 @@
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 @@
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 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 86e1f26..8242737 100644
--- a/src/utils/ComboRenderBundleEncoderDescriptor.cpp
+++ b/src/utils/ComboRenderBundleEncoderDescriptor.cpp
@@ -21,8 +21,6 @@
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 e829693..dbf8335 100644
--- a/src/utils/ComboRenderBundleEncoderDescriptor.h
+++ b/src/utils/ComboRenderBundleEncoderDescriptor.h
@@ -28,7 +28,6 @@
ComboRenderBundleEncoderDescriptor();
std::array<dawn::TextureFormat, kMaxColorAttachments> cColorFormats;
- dawn::TextureFormat cDepthStencilFormat;
};
} // namespace utils