Change SubresourceRange to be hierarchical.

Initializing SubresourceRange with {x, y, z} type of constructor
was error prone because it was going from the smallest concept
to the larger one instead of being hierarchical.

This CL changes the order of the structure and more importantly
adds a constructor that's in hierarchical order and groups related
members together. For example:

  SubresourceRange range(Aspect::Color, {layerStart, layerCount}, {0, mipCount});

It also adds a rename of SingleMipAndLayer in hierarchical order as
SubresourceRange::Single and a helper that gives a full range as
SubresourceRange::Full (it will be used in follow-up CLs).

Bug: dawn:441

Change-Id: I8e71bae1129a96222f7779014575b24b31f5ef7a
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/35000
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Corentin Wallez 2020-12-08 12:39:03 +00:00 committed by Commit Bot service account
parent 8a73e1876d
commit 61355d416d
5 changed files with 63 additions and 17 deletions

View File

@ -77,10 +77,9 @@ namespace dawn_native {
const Extent3D& copySize) { const Extent3D& copySize) {
switch (copy.texture->GetDimension()) { switch (copy.texture->GetDimension()) {
case wgpu::TextureDimension::e2D: case wgpu::TextureDimension::e2D:
return {copy.mipLevel, 1, copy.origin.z, copySize.depth, copy.aspect}; return {copy.aspect, {copy.origin.z, copySize.depth}, {copy.mipLevel, 1}};
default: default:
UNREACHABLE(); UNREACHABLE();
return {};
} }
} }

View File

@ -180,18 +180,18 @@ namespace dawn_native {
return deviceBase->GetDeprecationWarningCountForTesting(); return deviceBase->GetDeprecationWarningCountForTesting();
} }
bool IsTextureSubresourceInitialized(WGPUTexture texture, bool IsTextureSubresourceInitialized(WGPUTexture cTexture,
uint32_t baseMipLevel, uint32_t baseMipLevel,
uint32_t levelCount, uint32_t levelCount,
uint32_t baseArrayLayer, uint32_t baseArrayLayer,
uint32_t layerCount, uint32_t layerCount,
WGPUTextureAspect aspect) { WGPUTextureAspect cAspect) {
dawn_native::TextureBase* textureBase = dawn_native::TextureBase* texture = reinterpret_cast<dawn_native::TextureBase*>(cTexture);
reinterpret_cast<dawn_native::TextureBase*>(texture);
SubresourceRange range = { Aspect aspect =
baseMipLevel, levelCount, baseArrayLayer, layerCount, ConvertAspect(texture->GetFormat(), static_cast<wgpu::TextureAspect>(cAspect));
ConvertAspect(textureBase->GetFormat(), static_cast<wgpu::TextureAspect>(aspect))}; SubresourceRange range(aspect, {baseArrayLayer, layerCount}, {baseMipLevel, levelCount});
return textureBase->IsSubresourceContentInitialized(range); return texture->IsSubresourceContentInitialized(range);
} }
std::vector<const char*> GetProcMapNamesForTestingInternal(); std::vector<const char*> GetProcMapNamesForTestingInternal();

View File

@ -68,11 +68,40 @@ namespace dawn_native {
} }
} }
SubresourceRange::SubresourceRange(Aspect aspects,
FirstAndCountRange<uint32_t> arrayLayerParam,
FirstAndCountRange<uint32_t> mipLevelParams)
: aspects(aspects),
baseArrayLayer(arrayLayerParam.first),
layerCount(arrayLayerParam.count),
baseMipLevel(mipLevelParams.first),
levelCount(mipLevelParams.count) {
}
SubresourceRange::SubresourceRange()
: aspects(Aspect::None), baseArrayLayer(0), layerCount(0), baseMipLevel(0), levelCount(0) {
}
// static // static
SubresourceRange SubresourceRange::SingleMipAndLayer(uint32_t baseMipLevel, SubresourceRange SubresourceRange::SingleMipAndLayer(uint32_t baseMipLevel,
uint32_t baseArrayLayer, uint32_t baseArrayLayer,
Aspect aspects) { Aspect aspects) {
return {baseMipLevel, 1, baseArrayLayer, 1, aspects}; return {aspects, {baseArrayLayer, 1}, {baseMipLevel, 1}};
}
// static
SubresourceRange SubresourceRange::MakeSingle(Aspect aspect,
uint32_t baseArrayLayer,
uint32_t baseMipLevel) {
ASSERT(HasOneBit(aspect));
return {aspect, {baseArrayLayer, 1}, {baseMipLevel, 1}};
}
// static
SubresourceRange SubresourceRange::MakeFull(Aspect aspects,
uint32_t layerCount,
uint32_t levelCount) {
return {aspects, {0, layerCount}, {0, levelCount}};
} }
} // namespace dawn_native } // namespace dawn_native

View File

@ -48,16 +48,33 @@ namespace dawn_native {
// Aspect::None. // Aspect::None.
Aspect TryConvertAspect(const Format& format, wgpu::TextureAspect aspect); Aspect TryConvertAspect(const Format& format, wgpu::TextureAspect aspect);
// Helper struct to make it clear that what the parameters of a range mean.
template <typename T>
struct FirstAndCountRange {
T first;
T count;
};
struct SubresourceRange { struct SubresourceRange {
uint32_t baseMipLevel; SubresourceRange(Aspect aspects,
uint32_t levelCount; FirstAndCountRange<uint32_t> arrayLayerParam,
FirstAndCountRange<uint32_t> mipLevelParams);
SubresourceRange();
Aspect aspects;
uint32_t baseArrayLayer; uint32_t baseArrayLayer;
uint32_t layerCount; uint32_t layerCount;
Aspect aspects; uint32_t baseMipLevel;
uint32_t levelCount;
static SubresourceRange SingleMipAndLayer(uint32_t baseMipLevel, static SubresourceRange SingleMipAndLayer(uint32_t baseMipLevel,
uint32_t baseArrayLayer, uint32_t baseArrayLayer,
Aspect aspects); Aspect aspects);
static SubresourceRange MakeSingle(Aspect aspect,
uint32_t baseArrayLayer,
uint32_t baseMipLevel);
static SubresourceRange MakeFull(Aspect aspects, uint32_t layerCount, uint32_t levelCount);
}; };
// Helper function to use aspects as linear indices in arrays. // Helper function to use aspects as linear indices in arrays.

View File

@ -421,7 +421,7 @@ namespace dawn_native {
} }
SubresourceRange TextureBase::GetAllSubresources() const { SubresourceRange TextureBase::GetAllSubresources() const {
ASSERT(!IsError()); ASSERT(!IsError());
return {0, mMipLevelCount, 0, GetArrayLayers(), mFormat.aspects}; return {mFormat.aspects, {0, GetArrayLayers()}, {0, mMipLevelCount}};
} }
uint32_t TextureBase::GetSampleCount() const { uint32_t TextureBase::GetSampleCount() const {
ASSERT(!IsError()); ASSERT(!IsError());
@ -577,8 +577,9 @@ namespace dawn_native {
mTexture(texture), mTexture(texture),
mFormat(GetDevice()->GetValidInternalFormat(descriptor->format)), mFormat(GetDevice()->GetValidInternalFormat(descriptor->format)),
mDimension(descriptor->dimension), mDimension(descriptor->dimension),
mRange({descriptor->baseMipLevel, descriptor->mipLevelCount, descriptor->baseArrayLayer, mRange({ConvertAspect(mFormat, descriptor->aspect),
descriptor->arrayLayerCount, ConvertAspect(mFormat, descriptor->aspect)}) { {descriptor->baseArrayLayer, descriptor->arrayLayerCount},
{descriptor->baseMipLevel, descriptor->mipLevelCount}}) {
} }
TextureViewBase::TextureViewBase(DeviceBase* device, ObjectBase::ErrorTag tag) TextureViewBase::TextureViewBase(DeviceBase* device, ObjectBase::ErrorTag tag)