diff --git a/src/dawn_native/CommandBuffer.cpp b/src/dawn_native/CommandBuffer.cpp index b9c47058f9..bde0c63252 100644 --- a/src/dawn_native/CommandBuffer.cpp +++ b/src/dawn_native/CommandBuffer.cpp @@ -77,10 +77,9 @@ namespace dawn_native { const Extent3D& copySize) { switch (copy.texture->GetDimension()) { 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: UNREACHABLE(); - return {}; } } diff --git a/src/dawn_native/DawnNative.cpp b/src/dawn_native/DawnNative.cpp index 21343e68bb..35ed9becdf 100644 --- a/src/dawn_native/DawnNative.cpp +++ b/src/dawn_native/DawnNative.cpp @@ -180,18 +180,18 @@ namespace dawn_native { return deviceBase->GetDeprecationWarningCountForTesting(); } - bool IsTextureSubresourceInitialized(WGPUTexture texture, + bool IsTextureSubresourceInitialized(WGPUTexture cTexture, uint32_t baseMipLevel, uint32_t levelCount, uint32_t baseArrayLayer, uint32_t layerCount, - WGPUTextureAspect aspect) { - dawn_native::TextureBase* textureBase = - reinterpret_cast(texture); - SubresourceRange range = { - baseMipLevel, levelCount, baseArrayLayer, layerCount, - ConvertAspect(textureBase->GetFormat(), static_cast(aspect))}; - return textureBase->IsSubresourceContentInitialized(range); + WGPUTextureAspect cAspect) { + dawn_native::TextureBase* texture = reinterpret_cast(cTexture); + + Aspect aspect = + ConvertAspect(texture->GetFormat(), static_cast(cAspect)); + SubresourceRange range(aspect, {baseArrayLayer, layerCount}, {baseMipLevel, levelCount}); + return texture->IsSubresourceContentInitialized(range); } std::vector GetProcMapNamesForTestingInternal(); diff --git a/src/dawn_native/Subresource.cpp b/src/dawn_native/Subresource.cpp index f3581e9b41..766cb1d7ce 100644 --- a/src/dawn_native/Subresource.cpp +++ b/src/dawn_native/Subresource.cpp @@ -68,11 +68,40 @@ namespace dawn_native { } } + SubresourceRange::SubresourceRange(Aspect aspects, + FirstAndCountRange arrayLayerParam, + FirstAndCountRange 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 SubresourceRange SubresourceRange::SingleMipAndLayer(uint32_t baseMipLevel, uint32_t baseArrayLayer, 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 diff --git a/src/dawn_native/Subresource.h b/src/dawn_native/Subresource.h index b2f7d40b8e..927f66569b 100644 --- a/src/dawn_native/Subresource.h +++ b/src/dawn_native/Subresource.h @@ -48,16 +48,33 @@ namespace dawn_native { // Aspect::None. Aspect TryConvertAspect(const Format& format, wgpu::TextureAspect aspect); + // Helper struct to make it clear that what the parameters of a range mean. + template + struct FirstAndCountRange { + T first; + T count; + }; + struct SubresourceRange { - uint32_t baseMipLevel; - uint32_t levelCount; + SubresourceRange(Aspect aspects, + FirstAndCountRange arrayLayerParam, + FirstAndCountRange mipLevelParams); + SubresourceRange(); + + Aspect aspects; uint32_t baseArrayLayer; uint32_t layerCount; - Aspect aspects; + uint32_t baseMipLevel; + uint32_t levelCount; static SubresourceRange SingleMipAndLayer(uint32_t baseMipLevel, uint32_t baseArrayLayer, 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. diff --git a/src/dawn_native/Texture.cpp b/src/dawn_native/Texture.cpp index 7e62d73322..cc345e3047 100644 --- a/src/dawn_native/Texture.cpp +++ b/src/dawn_native/Texture.cpp @@ -421,7 +421,7 @@ namespace dawn_native { } SubresourceRange TextureBase::GetAllSubresources() const { ASSERT(!IsError()); - return {0, mMipLevelCount, 0, GetArrayLayers(), mFormat.aspects}; + return {mFormat.aspects, {0, GetArrayLayers()}, {0, mMipLevelCount}}; } uint32_t TextureBase::GetSampleCount() const { ASSERT(!IsError()); @@ -577,8 +577,9 @@ namespace dawn_native { mTexture(texture), mFormat(GetDevice()->GetValidInternalFormat(descriptor->format)), mDimension(descriptor->dimension), - mRange({descriptor->baseMipLevel, descriptor->mipLevelCount, descriptor->baseArrayLayer, - descriptor->arrayLayerCount, ConvertAspect(mFormat, descriptor->aspect)}) { + mRange({ConvertAspect(mFormat, descriptor->aspect), + {descriptor->baseArrayLayer, descriptor->arrayLayerCount}, + {descriptor->baseMipLevel, descriptor->mipLevelCount}}) { } TextureViewBase::TextureViewBase(DeviceBase* device, ObjectBase::ErrorTag tag)