From 7bfcdca4195593a6384674e2c5576ae291138086 Mon Sep 17 00:00:00 2001 From: Yunchao He Date: Thu, 2 Jun 2022 19:07:41 +0000 Subject: [PATCH] Rename GetMipLevelSize Functions GetMipLevel*Size() are somehow unclear and misleading on whether the array layers are counted into the z-axis of the returned Extent3D (Extent3D.depthOrArrayLayers). This change renames them to GetMipLevelSingleSubresource*Size(), making it clear that array layers are not included in its z-axis. Because different array layers are different subreources, they are not in a single subresource. However, depth slices in 3D textures can be in a single subresource and can be counted. Bug: dawn:1288 Change-Id: Ifa1776befa863d0f5a11999cab4099e2e7e5996a Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/92124 Reviewed-by: Corentin Wallez Kokoro: Kokoro Commit-Queue: Yunchao He Reviewed-by: Austin Eng --- src/dawn/native/CommandBuffer.cpp | 2 +- src/dawn/native/CommandEncoder.cpp | 9 +++++--- src/dawn/native/CommandValidation.cpp | 5 +++-- src/dawn/native/SwapChain.cpp | 4 ++-- src/dawn/native/Texture.cpp | 8 ++++---- src/dawn/native/Texture.h | 4 ++-- src/dawn/native/d3d12/TextureD3D12.cpp | 4 ++-- src/dawn/native/metal/TextureMTL.mm | 24 ++++++++++++---------- src/dawn/native/metal/UtilsMetal.mm | 2 +- src/dawn/native/opengl/CommandBufferGL.cpp | 5 +++-- src/dawn/native/opengl/TextureGL.cpp | 9 ++++---- src/dawn/native/vulkan/TextureVk.cpp | 4 ++-- src/dawn/native/vulkan/UtilsVulkan.cpp | 3 ++- 13 files changed, 46 insertions(+), 37 deletions(-) diff --git a/src/dawn/native/CommandBuffer.cpp b/src/dawn/native/CommandBuffer.cpp index b5ae04a07e..ab22dea037 100644 --- a/src/dawn/native/CommandBuffer.cpp +++ b/src/dawn/native/CommandBuffer.cpp @@ -73,7 +73,7 @@ CommandIterator* CommandBufferBase::GetCommandIteratorForTesting() { bool IsCompleteSubresourceCopiedTo(const TextureBase* texture, const Extent3D copySize, const uint32_t mipLevel) { - Extent3D extent = texture->GetMipLevelPhysicalSize(mipLevel); + Extent3D extent = texture->GetMipLevelSingleSubresourcePhysicalSize(mipLevel); switch (texture->GetDimension()) { case wgpu::TextureDimension::e1D: diff --git a/src/dawn/native/CommandEncoder.cpp b/src/dawn/native/CommandEncoder.cpp index 004916381f..9f2a5d120c 100644 --- a/src/dawn/native/CommandEncoder.cpp +++ b/src/dawn/native/CommandEncoder.cpp @@ -126,7 +126,8 @@ MaybeError ValidateOrSetAttachmentSize(const TextureViewBase* attachment, uint32_t* width, uint32_t* height) { const Extent3D& attachmentSize = - attachment->GetTexture()->GetMipLevelVirtualSize(attachment->GetBaseMipLevel()); + attachment->GetTexture()->GetMipLevelSingleSubresourceVirtualSize( + attachment->GetBaseMipLevel()); if (*width == 0) { DAWN_ASSERT(*height == 0); @@ -190,9 +191,11 @@ MaybeError ValidateResolveTarget(const DeviceBase* device, resolveTarget->GetLevelCount()); const Extent3D& colorTextureSize = - attachment->GetTexture()->GetMipLevelVirtualSize(attachment->GetBaseMipLevel()); + attachment->GetTexture()->GetMipLevelSingleSubresourceVirtualSize( + attachment->GetBaseMipLevel()); const Extent3D& resolveTextureSize = - resolveTarget->GetTexture()->GetMipLevelVirtualSize(resolveTarget->GetBaseMipLevel()); + resolveTarget->GetTexture()->GetMipLevelSingleSubresourceVirtualSize( + resolveTarget->GetBaseMipLevel()); DAWN_INVALID_IF(colorTextureSize.width != resolveTextureSize.width || colorTextureSize.height != resolveTextureSize.height, "The Resolve target %s size (width: %u, height: %u) does not match the color " diff --git a/src/dawn/native/CommandValidation.cpp b/src/dawn/native/CommandValidation.cpp index 3df90f1047..723f658d1f 100644 --- a/src/dawn/native/CommandValidation.cpp +++ b/src/dawn/native/CommandValidation.cpp @@ -275,7 +275,8 @@ MaybeError ValidateImageCopyTexture(DeviceBase const* device, texture->GetFormat().format, textureCopy.aspect); if (texture->GetSampleCount() > 1 || texture->GetFormat().HasDepthOrStencil()) { - Extent3D subresourceSize = texture->GetMipLevelPhysicalSize(textureCopy.mipLevel); + Extent3D subresourceSize = + texture->GetMipLevelSingleSubresourcePhysicalSize(textureCopy.mipLevel); ASSERT(texture->GetDimension() == wgpu::TextureDimension::e2D); DAWN_INVALID_IF( textureCopy.origin.x != 0 || textureCopy.origin.y != 0 || @@ -297,7 +298,7 @@ MaybeError ValidateTextureCopyRange(DeviceBase const* device, const TextureBase* texture = textureCopy.texture; // Validation for the copy being in-bounds: - Extent3D mipSize = texture->GetMipLevelPhysicalSize(textureCopy.mipLevel); + Extent3D mipSize = texture->GetMipLevelSingleSubresourcePhysicalSize(textureCopy.mipLevel); // For 1D/2D textures, include the array layer as depth so it can be checked with other // dimensions. if (texture->GetDimension() != wgpu::TextureDimension::e3D) { diff --git a/src/dawn/native/SwapChain.cpp b/src/dawn/native/SwapChain.cpp index 1cc505626a..daa5f3235f 100644 --- a/src/dawn/native/SwapChain.cpp +++ b/src/dawn/native/SwapChain.cpp @@ -330,10 +330,10 @@ ResultOrError> NewSwapChainBase::GetCurrentTextureView() { ASSERT(mCurrentTextureView->GetLayerCount() == 1); ASSERT(mCurrentTextureView->GetDimension() == wgpu::TextureViewDimension::e2D); ASSERT(mCurrentTextureView->GetTexture() - ->GetMipLevelVirtualSize(mCurrentTextureView->GetBaseMipLevel()) + ->GetMipLevelSingleSubresourceVirtualSize(mCurrentTextureView->GetBaseMipLevel()) .width == mWidth); ASSERT(mCurrentTextureView->GetTexture() - ->GetMipLevelVirtualSize(mCurrentTextureView->GetBaseMipLevel()) + ->GetMipLevelSingleSubresourceVirtualSize(mCurrentTextureView->GetBaseMipLevel()) .height == mHeight); return mCurrentTextureView; diff --git a/src/dawn/native/Texture.cpp b/src/dawn/native/Texture.cpp index bb0859106a..75f8866d93 100644 --- a/src/dawn/native/Texture.cpp +++ b/src/dawn/native/Texture.cpp @@ -695,7 +695,7 @@ bool TextureBase::IsMultisampledTexture() const { return mSampleCount > 1; } -Extent3D TextureBase::GetMipLevelVirtualSize(uint32_t level) const { +Extent3D TextureBase::GetMipLevelSingleSubresourceVirtualSize(uint32_t level) const { Extent3D extent = {std::max(mSize.width >> level, 1u), 1u, 1u}; if (mDimension == wgpu::TextureDimension::e1D) { return extent; @@ -710,8 +710,8 @@ Extent3D TextureBase::GetMipLevelVirtualSize(uint32_t level) const { return extent; } -Extent3D TextureBase::GetMipLevelPhysicalSize(uint32_t level) const { - Extent3D extent = GetMipLevelVirtualSize(level); +Extent3D TextureBase::GetMipLevelSingleSubresourcePhysicalSize(uint32_t level) const { + Extent3D extent = GetMipLevelSingleSubresourceVirtualSize(level); // Compressed Textures will have paddings if their width or height is not a multiple of // 4 at non-zero mipmap levels. @@ -731,7 +731,7 @@ Extent3D TextureBase::GetMipLevelPhysicalSize(uint32_t level) const { Extent3D TextureBase::ClampToMipLevelVirtualSize(uint32_t level, const Origin3D& origin, const Extent3D& extent) const { - const Extent3D virtualSizeAtLevel = GetMipLevelVirtualSize(level); + const Extent3D virtualSizeAtLevel = GetMipLevelSingleSubresourceVirtualSize(level); ASSERT(origin.x <= virtualSizeAtLevel.width); ASSERT(origin.y <= virtualSizeAtLevel.height); uint32_t clampedCopyExtentWidth = (extent.width > virtualSizeAtLevel.width - origin.x) diff --git a/src/dawn/native/Texture.h b/src/dawn/native/Texture.h index 1712d7e34e..89bca4fb32 100644 --- a/src/dawn/native/Texture.h +++ b/src/dawn/native/Texture.h @@ -87,8 +87,8 @@ class TextureBase : public ApiObjectBase { // size is the one with paddings if necessary, which is always a multiple of the block size // and used in texture copying. The virtual size is the one without paddings, which is not // required to be a multiple of the block size and used in texture sampling. - Extent3D GetMipLevelPhysicalSize(uint32_t level) const; - Extent3D GetMipLevelVirtualSize(uint32_t level) const; + Extent3D GetMipLevelSingleSubresourcePhysicalSize(uint32_t level) const; + Extent3D GetMipLevelSingleSubresourceVirtualSize(uint32_t level) const; Extent3D ClampToMipLevelVirtualSize(uint32_t level, const Origin3D& origin, const Extent3D& extent) const; diff --git a/src/dawn/native/d3d12/TextureD3D12.cpp b/src/dawn/native/d3d12/TextureD3D12.cpp index c7258a5b18..651f2d0e5f 100644 --- a/src/dawn/native/d3d12/TextureD3D12.cpp +++ b/src/dawn/native/d3d12/TextureD3D12.cpp @@ -1086,7 +1086,7 @@ MaybeError Texture::ClearTexture(CommandRecordingContext* commandContext, for (Aspect aspect : IterateEnumMask(range.aspects)) { const TexelBlockInfo& blockInfo = GetFormat().GetAspectInfo(aspect).block; - Extent3D largestMipSize = GetMipLevelPhysicalSize(range.baseMipLevel); + Extent3D largestMipSize = GetMipLevelSingleSubresourcePhysicalSize(range.baseMipLevel); uint32_t bytesPerRow = Align((largestMipSize.width / blockInfo.width) * blockInfo.byteSize, @@ -1103,7 +1103,7 @@ MaybeError Texture::ClearTexture(CommandRecordingContext* commandContext, for (uint32_t level = range.baseMipLevel; level < range.baseMipLevel + range.levelCount; ++level) { // compute d3d12 texture copy locations for texture and buffer - Extent3D copySize = GetMipLevelPhysicalSize(level); + Extent3D copySize = GetMipLevelSingleSubresourcePhysicalSize(level); for (uint32_t layer = range.baseArrayLayer; layer < range.baseArrayLayer + range.layerCount; ++layer) { diff --git a/src/dawn/native/metal/TextureMTL.mm b/src/dawn/native/metal/TextureMTL.mm index 3a413a9c6f..a629d9dd47 100644 --- a/src/dawn/native/metal/TextureMTL.mm +++ b/src/dawn/native/metal/TextureMTL.mm @@ -869,8 +869,9 @@ MaybeError Texture::ClearTexture(CommandRecordingContext* commandContext, } } - DAWN_TRY(EncodeEmptyMetalRenderPass(device, commandContext, descriptor, - GetMipLevelVirtualSize(level))); + DAWN_TRY( + EncodeEmptyMetalRenderPass(device, commandContext, descriptor, + GetMipLevelSingleSubresourceVirtualSize(level))); } } } else { @@ -883,7 +884,7 @@ MaybeError Texture::ClearTexture(CommandRecordingContext* commandContext, NSRef descriptor; uint32_t attachment = 0; - uint32_t numZSlices = GetMipLevelVirtualSize(level).depthOrArrayLayers; + uint32_t depth = GetMipLevelSingleSubresourceVirtualSize(level).depthOrArrayLayers; for (uint32_t arrayLayer = range.baseArrayLayer; arrayLayer < range.baseArrayLayer + range.layerCount; arrayLayer++) { @@ -894,7 +895,7 @@ MaybeError Texture::ClearTexture(CommandRecordingContext* commandContext, continue; } - for (uint32_t z = 0; z < numZSlices; ++z) { + for (uint32_t z = 0; z < depth; ++z) { if (descriptor == nullptr) { // Note that this creates a descriptor that's autoreleased so we // don't use AcquireNSRef @@ -915,17 +916,18 @@ MaybeError Texture::ClearTexture(CommandRecordingContext* commandContext, if (attachment == kMaxColorAttachments) { attachment = 0; - DAWN_TRY(EncodeEmptyMetalRenderPass(device, commandContext, - descriptor.Get(), - GetMipLevelVirtualSize(level))); + DAWN_TRY(EncodeEmptyMetalRenderPass( + device, commandContext, descriptor.Get(), + GetMipLevelSingleSubresourceVirtualSize(level))); descriptor = nullptr; } } } if (descriptor != nullptr) { - DAWN_TRY(EncodeEmptyMetalRenderPass(device, commandContext, descriptor.Get(), - GetMipLevelVirtualSize(level))); + DAWN_TRY( + EncodeEmptyMetalRenderPass(device, commandContext, descriptor.Get(), + GetMipLevelSingleSubresourceVirtualSize(level))); } } } @@ -937,7 +939,7 @@ MaybeError Texture::ClearTexture(CommandRecordingContext* commandContext, // Computations for the bytes per row / image height are done using the physical size // so that enough data is reserved for compressed textures. - Extent3D largestMipSize = GetMipLevelPhysicalSize(range.baseMipLevel); + Extent3D largestMipSize = GetMipLevelSingleSubresourcePhysicalSize(range.baseMipLevel); uint32_t largestMipBytesPerRow = (largestMipSize.width / blockInfo.width) * blockInfo.byteSize; uint64_t largestMipBytesPerImage = static_cast(largestMipBytesPerRow) * @@ -959,7 +961,7 @@ MaybeError Texture::ClearTexture(CommandRecordingContext* commandContext, for (uint32_t level = range.baseMipLevel; level < range.baseMipLevel + range.levelCount; ++level) { - Extent3D virtualSize = GetMipLevelVirtualSize(level); + Extent3D virtualSize = GetMipLevelSingleSubresourceVirtualSize(level); for (uint32_t arrayLayer = range.baseArrayLayer; arrayLayer < range.baseArrayLayer + range.layerCount; ++arrayLayer) { diff --git a/src/dawn/native/metal/UtilsMetal.mm b/src/dawn/native/metal/UtilsMetal.mm index 339b8872db..22d3681ab5 100644 --- a/src/dawn/native/metal/UtilsMetal.mm +++ b/src/dawn/native/metal/UtilsMetal.mm @@ -262,7 +262,7 @@ TextureBufferCopySplit ComputeTextureBufferCopySplit(const Texture* texture, origin.z + copyExtent.depthOrArrayLayers - 1}; ASSERT(copyExtent.height - blockInfo.height < - texture->GetMipLevelVirtualSize(mipLevel).height); + texture->GetMipLevelSingleSubresourceVirtualSize(mipLevel).height); copy.copies[copy.count].copyExtent = {clampedCopyExtent.width, copyExtent.height - blockInfo.height, 1}; diff --git a/src/dawn/native/opengl/CommandBufferGL.cpp b/src/dawn/native/opengl/CommandBufferGL.cpp index 9931163741..851413dffe 100644 --- a/src/dawn/native/opengl/CommandBufferGL.cpp +++ b/src/dawn/native/opengl/CommandBufferGL.cpp @@ -422,7 +422,8 @@ void ResolveMultisampledRenderTargets(const OpenGLFunctions& gl, Extent3D ComputeTextureCopyExtent(const TextureCopy& textureCopy, const Extent3D& copySize) { Extent3D validTextureCopyExtent = copySize; const TextureBase* texture = textureCopy.texture.Get(); - Extent3D virtualSizeAtLevel = texture->GetMipLevelVirtualSize(textureCopy.mipLevel); + Extent3D virtualSizeAtLevel = + texture->GetMipLevelSingleSubresourceVirtualSize(textureCopy.mipLevel); ASSERT(textureCopy.origin.x <= virtualSizeAtLevel.width); ASSERT(textureCopy.origin.y <= virtualSizeAtLevel.height); if (copySize.width > virtualSizeAtLevel.width - textureCopy.origin.x) { @@ -1240,7 +1241,7 @@ void DoTexSubImage(const OpenGLFunctions& gl, uint32_t z = destination.origin.z; if (texture->GetFormat().isCompressed) { size_t rowSize = copySize.width / blockInfo.width * blockInfo.byteSize; - Extent3D virtSize = texture->GetMipLevelVirtualSize(destination.mipLevel); + Extent3D virtSize = texture->GetMipLevelSingleSubresourceVirtualSize(destination.mipLevel); uint32_t width = std::min(copySize.width, virtSize.width - x); // In GLES glPixelStorei() doesn't affect CompressedTexSubImage*D() and diff --git a/src/dawn/native/opengl/TextureGL.cpp b/src/dawn/native/opengl/TextureGL.cpp index 5b2b999e9a..88130bd8c6 100644 --- a/src/dawn/native/opengl/TextureGL.cpp +++ b/src/dawn/native/opengl/TextureGL.cpp @@ -378,7 +378,7 @@ MaybeError Texture::ClearTexture(const SubresourceRange& range, const GLFormat& glFormat = GetGLFormat(); for (uint32_t level = range.baseMipLevel; level < range.baseMipLevel + range.levelCount; ++level) { - Extent3D mipSize = GetMipLevelPhysicalSize(level); + Extent3D mipSize = GetMipLevelSingleSubresourcePhysicalSize(level); for (uint32_t layer = range.baseArrayLayer; layer < range.baseArrayLayer + range.layerCount; ++layer) { if (clearValue == TextureBase::ClearValue::Zero && @@ -448,7 +448,8 @@ MaybeError Texture::ClearTexture(const SubresourceRange& range, DoClear(); break; case wgpu::TextureDimension::e3D: - uint32_t depth = GetMipLevelVirtualSize(level).depthOrArrayLayers; + uint32_t depth = GetMipLevelSingleSubresourceVirtualSize(level) + .depthOrArrayLayers; for (GLint z = 0; z < static_cast(depth); ++z) { gl.FramebufferTextureLayer(GL_DRAW_FRAMEBUFFER, attachment, GetHandle(), level, z); @@ -477,7 +478,7 @@ MaybeError Texture::ClearTexture(const SubresourceRange& range, const TexelBlockInfo& blockInfo = GetFormat().GetAspectInfo(Aspect::Color).block; ASSERT(kTextureBytesPerRowAlignment % blockInfo.byteSize == 0); - Extent3D largestMipSize = GetMipLevelPhysicalSize(range.baseMipLevel); + Extent3D largestMipSize = GetMipLevelSingleSubresourcePhysicalSize(range.baseMipLevel); uint32_t bytesPerRow = Align((largestMipSize.width / blockInfo.width) * blockInfo.byteSize, 4); @@ -521,7 +522,7 @@ MaybeError Texture::ClearTexture(const SubresourceRange& range, dataLayout.bytesPerRow = bytesPerRow; dataLayout.rowsPerImage = largestMipSize.height; - Extent3D mipSize = GetMipLevelPhysicalSize(level); + Extent3D mipSize = GetMipLevelSingleSubresourcePhysicalSize(level); for (uint32_t layer = range.baseArrayLayer; layer < range.baseArrayLayer + range.layerCount; ++layer) { diff --git a/src/dawn/native/vulkan/TextureVk.cpp b/src/dawn/native/vulkan/TextureVk.cpp index 050050a7c4..404815dca5 100644 --- a/src/dawn/native/vulkan/TextureVk.cpp +++ b/src/dawn/native/vulkan/TextureVk.cpp @@ -1195,7 +1195,7 @@ MaybeError Texture::ClearTexture(CommandRecordingContext* recordingContext, ASSERT(range.aspects == Aspect::Color); const TexelBlockInfo& blockInfo = GetFormat().GetAspectInfo(range.aspects).block; - Extent3D largestMipSize = GetMipLevelPhysicalSize(range.baseMipLevel); + Extent3D largestMipSize = GetMipLevelSingleSubresourcePhysicalSize(range.baseMipLevel); uint32_t bytesPerRow = Align((largestMipSize.width / blockInfo.width) * blockInfo.byteSize, device->GetOptimalBytesPerRowAlignment()); @@ -1211,7 +1211,7 @@ MaybeError Texture::ClearTexture(CommandRecordingContext* recordingContext, std::vector regions; for (uint32_t level = range.baseMipLevel; level < range.baseMipLevel + range.levelCount; ++level) { - Extent3D copySize = GetMipLevelPhysicalSize(level); + Extent3D copySize = GetMipLevelSingleSubresourcePhysicalSize(level); imageRange.baseMipLevel = level; for (uint32_t layer = range.baseArrayLayer; layer < range.baseArrayLayer + range.layerCount; ++layer) { diff --git a/src/dawn/native/vulkan/UtilsVulkan.cpp b/src/dawn/native/vulkan/UtilsVulkan.cpp index fe034244fd..2595112faa 100644 --- a/src/dawn/native/vulkan/UtilsVulkan.cpp +++ b/src/dawn/native/vulkan/UtilsVulkan.cpp @@ -114,7 +114,8 @@ VkImageAspectFlags VulkanAspectMask(const Aspect& aspects) { Extent3D ComputeTextureCopyExtent(const TextureCopy& textureCopy, const Extent3D& copySize) { Extent3D validTextureCopyExtent = copySize; const TextureBase* texture = textureCopy.texture.Get(); - Extent3D virtualSizeAtLevel = texture->GetMipLevelVirtualSize(textureCopy.mipLevel); + Extent3D virtualSizeAtLevel = + texture->GetMipLevelSingleSubresourceVirtualSize(textureCopy.mipLevel); ASSERT(textureCopy.origin.x <= virtualSizeAtLevel.width); ASSERT(textureCopy.origin.y <= virtualSizeAtLevel.height); if (copySize.width > virtualSizeAtLevel.width - textureCopy.origin.x) {