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 <cwallez@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Yunchao He <yunchao.he@intel.com>
Reviewed-by: Austin Eng <enga@chromium.org>
diff --git a/src/dawn/native/CommandBuffer.cpp b/src/dawn/native/CommandBuffer.cpp
index b5ae04a..ab22dea 100644
--- a/src/dawn/native/CommandBuffer.cpp
+++ b/src/dawn/native/CommandBuffer.cpp
@@ -73,7 +73,7 @@
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 0049163..9f2a5d1 100644
--- a/src/dawn/native/CommandEncoder.cpp
+++ b/src/dawn/native/CommandEncoder.cpp
@@ -126,7 +126,8 @@
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 @@
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 3df90f1..723f658 100644
--- a/src/dawn/native/CommandValidation.cpp
+++ b/src/dawn/native/CommandValidation.cpp
@@ -275,7 +275,8 @@
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 @@
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 1cc5056..daa5f32 100644
--- a/src/dawn/native/SwapChain.cpp
+++ b/src/dawn/native/SwapChain.cpp
@@ -330,10 +330,10 @@
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 bb08591..75f8866 100644
--- a/src/dawn/native/Texture.cpp
+++ b/src/dawn/native/Texture.cpp
@@ -695,7 +695,7 @@
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 @@
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::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 1712d7e..89bca4f 100644
--- a/src/dawn/native/Texture.h
+++ b/src/dawn/native/Texture.h
@@ -87,8 +87,8 @@
// 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 c7258a5..651f2d0 100644
--- a/src/dawn/native/d3d12/TextureD3D12.cpp
+++ b/src/dawn/native/d3d12/TextureD3D12.cpp
@@ -1086,7 +1086,7 @@
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 @@
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 3a413a9..a629d9d 100644
--- a/src/dawn/native/metal/TextureMTL.mm
+++ b/src/dawn/native/metal/TextureMTL.mm
@@ -869,8 +869,9 @@
}
}
- DAWN_TRY(EncodeEmptyMetalRenderPass(device, commandContext, descriptor,
- GetMipLevelVirtualSize(level)));
+ DAWN_TRY(
+ EncodeEmptyMetalRenderPass(device, commandContext, descriptor,
+ GetMipLevelSingleSubresourceVirtualSize(level)));
}
}
} else {
@@ -883,7 +884,7 @@
NSRef<MTLRenderPassDescriptor> 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 @@
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 @@
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 @@
// 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<uint64_t>(largestMipBytesPerRow) *
@@ -959,7 +961,7 @@
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 339b8872..22d3681 100644
--- a/src/dawn/native/metal/UtilsMetal.mm
+++ b/src/dawn/native/metal/UtilsMetal.mm
@@ -262,7 +262,7 @@
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 9931163..851413d 100644
--- a/src/dawn/native/opengl/CommandBufferGL.cpp
+++ b/src/dawn/native/opengl/CommandBufferGL.cpp
@@ -422,7 +422,8 @@
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 @@
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 5b2b999..88130bd 100644
--- a/src/dawn/native/opengl/TextureGL.cpp
+++ b/src/dawn/native/opengl/TextureGL.cpp
@@ -378,7 +378,7 @@
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 @@
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<GLint>(depth); ++z) {
gl.FramebufferTextureLayer(GL_DRAW_FRAMEBUFFER, attachment,
GetHandle(), level, z);
@@ -477,7 +478,7 @@
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 @@
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 050050a..404815d 100644
--- a/src/dawn/native/vulkan/TextureVk.cpp
+++ b/src/dawn/native/vulkan/TextureVk.cpp
@@ -1195,7 +1195,7 @@
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 @@
std::vector<VkBufferImageCopy> 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 fe03424..2595112 100644
--- a/src/dawn/native/vulkan/UtilsVulkan.cpp
+++ b/src/dawn/native/vulkan/UtilsVulkan.cpp
@@ -114,7 +114,8 @@
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) {