TextureView: only store the Aspect as a bitfield.

In follow-up CLs the aspect of texture views becomes more important as
it is used to query the texture format's base type and supported
componenet types.

Previously asking for the AspectInfo for wgpu::TextureAspect::All could
be ambiguous for depth-stencil formats. By using the internal bitfields
the constraint is much more clear that a single bit must be set.

Bug: dawn:527

Change-Id: Iebff40f28c4a6c38ebe5a7cccf62f8ab3363e4e3
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/30101
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Stephen White <senorblanco@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
Corentin Wallez 2020-10-15 09:15:53 +00:00 committed by Commit Bot service account
parent 6298d2b70c
commit 49c30a70e8
3 changed files with 8 additions and 12 deletions

View File

@ -275,7 +275,8 @@ namespace dawn_native {
DAWN_TRY(device->ValidateObject(colorAttachment.attachment));
const TextureViewBase* attachment = colorAttachment.attachment;
if (!attachment->GetFormat().IsColor() || !attachment->GetFormat().isRenderable) {
if (!(attachment->GetAspects() & Aspect::Color) ||
!attachment->GetFormat().isRenderable) {
return DAWN_VALIDATION_ERROR(
"The format of the texture view used as color attachment is not color "
"renderable");
@ -334,7 +335,7 @@ namespace dawn_native {
DAWN_TRY(device->ValidateObject(depthStencilAttachment->attachment));
const TextureViewBase* attachment = depthStencilAttachment->attachment;
if (!attachment->GetFormat().HasDepthOrStencil() ||
if ((attachment->GetAspects() & (Aspect::Depth | Aspect::Stencil)) == Aspect::None ||
!attachment->GetFormat().isRenderable) {
return DAWN_VALIDATION_ERROR(
"The format of the texture view used as depth stencil attachment is not a "
@ -346,8 +347,7 @@ namespace dawn_native {
DAWN_TRY(ValidateStoreOp(depthStencilAttachment->depthStoreOp));
DAWN_TRY(ValidateStoreOp(depthStencilAttachment->stencilStoreOp));
if (attachment->GetAspect() == wgpu::TextureAspect::All &&
attachment->GetFormat().HasStencil() &&
if (attachment->GetAspects() == (Aspect::Depth | Aspect::Stencil) &&
depthStencilAttachment->depthReadOnly != depthStencilAttachment->stencilReadOnly) {
return DAWN_VALIDATION_ERROR(
"depthReadOnly and stencilReadOnly must be the same when texture aspect is "

View File

@ -613,13 +613,10 @@ namespace dawn_native {
TextureViewBase::TextureViewBase(TextureBase* texture, const TextureViewDescriptor* descriptor)
: ObjectBase(texture->GetDevice()),
mTexture(texture),
mAspect(descriptor->aspect),
mFormat(GetDevice()->GetValidInternalFormat(descriptor->format)),
mDimension(descriptor->dimension),
mRange({descriptor->baseMipLevel, descriptor->mipLevelCount, descriptor->baseArrayLayer,
descriptor->arrayLayerCount, ConvertAspect(mFormat, mAspect)}) {
// TODO(crbug.com/dawn/439): Current validation only allows texture views with aspect "all".
ASSERT(mAspect == wgpu::TextureAspect::All);
descriptor->arrayLayerCount, ConvertAspect(mFormat, descriptor->aspect)}) {
}
TextureViewBase::TextureViewBase(DeviceBase* device, ObjectBase::ErrorTag tag)
@ -641,9 +638,9 @@ namespace dawn_native {
return mTexture.Get();
}
wgpu::TextureAspect TextureViewBase::GetAspect() const {
Aspect TextureViewBase::GetAspects() const {
ASSERT(!IsError());
return mAspect;
return mRange.aspects;
}
const Format& TextureViewBase::GetFormat() const {

View File

@ -163,7 +163,7 @@ namespace dawn_native {
const TextureBase* GetTexture() const;
TextureBase* GetTexture();
wgpu::TextureAspect GetAspect() const;
Aspect GetAspects() const;
const Format& GetFormat() const;
wgpu::TextureViewDimension GetDimension() const;
uint32_t GetBaseMipLevel() const;
@ -177,7 +177,6 @@ namespace dawn_native {
Ref<TextureBase> mTexture;
wgpu::TextureAspect mAspect;
// TODO(cwallez@chromium.org): This should be deduplicated in the Device
const Format& mFormat;
wgpu::TextureViewDimension mDimension;