Use mipLevel/arrayLayer for TextureCopyView

These are the names for the level/slice concept in WebGPU and this one
occurence was forgotten in the previous rename.

BUG=dawn:22

Change-Id: I0aef05e21b2291cf02712034c6ddc3ab62ecbc33
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/8681
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
Corentin Wallez 2019-07-08 09:41:51 +00:00 committed by Commit Bot service account
parent a0491c9141
commit 3c3e2bc4d9
8 changed files with 95 additions and 87 deletions

View File

@ -1018,8 +1018,8 @@
"extensible": true,
"members": [
{"name": "texture", "type": "texture"},
{"name": "level", "type": "uint32_t"},
{"name": "slice", "type": "uint32_t"},
{"name": "mip level", "type": "uint32_t"},
{"name": "array layer", "type": "uint32_t"},
{"name": "origin", "type": "origin 3D"}
]
},

View File

@ -35,20 +35,18 @@ namespace dawn_native {
MaybeError ValidateCopySizeFitsInTexture(const TextureCopy& textureCopy,
const Extent3D& copySize) {
const TextureBase* texture = textureCopy.texture.Get();
if (textureCopy.level >= texture->GetNumMipLevels()) {
return DAWN_VALIDATION_ERROR("Copy mip-level out of range");
if (textureCopy.mipLevel >= texture->GetNumMipLevels()) {
return DAWN_VALIDATION_ERROR("Copy mipLevel out of range");
}
if (textureCopy.slice >= texture->GetArrayLayers()) {
return DAWN_VALIDATION_ERROR("Copy array-layer out of range");
if (textureCopy.arrayLayer >= texture->GetArrayLayers()) {
return DAWN_VALIDATION_ERROR("Copy arrayLayer out of range");
}
Extent3D extent = texture->GetMipLevelPhysicalSize(textureCopy.mipLevel);
// All texture dimensions are in uint32_t so by doing checks in uint64_t we avoid
// overflows.
uint64_t level = textureCopy.level;
Extent3D extent = texture->GetMipLevelPhysicalSize(level);
if (uint64_t(textureCopy.origin.x) + uint64_t(copySize.width) >
static_cast<uint64_t>(extent.width) ||
uint64_t(textureCopy.origin.y) + uint64_t(copySize.height) >
@ -766,8 +764,8 @@ namespace dawn_native {
copy->destination.texture = destination->texture;
copy->destination.origin = destination->origin;
copy->copySize = *copySize;
copy->destination.level = destination->level;
copy->destination.slice = destination->slice;
copy->destination.mipLevel = destination->mipLevel;
copy->destination.arrayLayer = destination->arrayLayer;
if (source->rowPitch == 0) {
copy->source.rowPitch =
ComputeDefaultRowPitch(destination->texture->GetFormat(), copySize->width);
@ -801,8 +799,8 @@ namespace dawn_native {
copy->source.texture = source->texture;
copy->source.origin = source->origin;
copy->copySize = *copySize;
copy->source.level = source->level;
copy->source.slice = source->slice;
copy->source.mipLevel = source->mipLevel;
copy->source.arrayLayer = source->arrayLayer;
copy->destination.buffer = destination->buffer;
copy->destination.offset = destination->offset;
if (destination->rowPitch == 0) {
@ -837,12 +835,12 @@ namespace dawn_native {
mAllocator.Allocate<CopyTextureToTextureCmd>(Command::CopyTextureToTexture);
copy->source.texture = source->texture;
copy->source.origin = source->origin;
copy->source.level = source->level;
copy->source.slice = source->slice;
copy->source.mipLevel = source->mipLevel;
copy->source.arrayLayer = source->arrayLayer;
copy->destination.texture = destination->texture;
copy->destination.origin = destination->origin;
copy->destination.level = destination->level;
copy->destination.slice = destination->slice;
copy->destination.mipLevel = destination->mipLevel;
copy->destination.arrayLayer = destination->arrayLayer;
copy->copySize = *copySize;
}

View File

@ -100,8 +100,8 @@ namespace dawn_native {
struct TextureCopy {
Ref<TextureBase> texture;
uint32_t level;
uint32_t slice;
uint32_t mipLevel;
uint32_t arrayLayer;
Origin3D origin; // Texels
};

View File

@ -509,12 +509,13 @@ namespace dawn_native { namespace d3d12 {
Texture* texture = ToBackend(copy->destination.texture.Get());
if (IsCompleteSubresourceCopiedTo(texture, copy->copySize,
copy->destination.level)) {
texture->SetIsSubresourceContentInitialized(copy->destination.level, 1,
copy->destination.slice, 1);
copy->destination.mipLevel)) {
texture->SetIsSubresourceContentInitialized(
copy->destination.mipLevel, 1, copy->destination.arrayLayer, 1);
} else {
texture->EnsureSubresourceContentInitialized(
commandList, copy->destination.level, 1, copy->destination.slice, 1);
commandList, copy->destination.mipLevel, 1,
copy->destination.arrayLayer, 1);
}
buffer->TransitionUsageNow(commandList, dawn::BufferUsageBit::TransferSrc);
@ -525,8 +526,8 @@ namespace dawn_native { namespace d3d12 {
copy->source.offset, copy->source.rowPitch, copy->source.imageHeight);
D3D12_TEXTURE_COPY_LOCATION textureLocation =
CreateTextureCopyLocationForTexture(*texture, copy->destination.level,
copy->destination.slice);
CreateTextureCopyLocationForTexture(*texture, copy->destination.mipLevel,
copy->destination.arrayLayer);
for (uint32_t i = 0; i < copySplit.count; ++i) {
auto& info = copySplit.copies[i];
@ -560,8 +561,8 @@ namespace dawn_native { namespace d3d12 {
Texture* texture = ToBackend(copy->source.texture.Get());
Buffer* buffer = ToBackend(copy->destination.buffer.Get());
texture->EnsureSubresourceContentInitialized(commandList, copy->source.level, 1,
copy->source.slice, 1);
texture->EnsureSubresourceContentInitialized(commandList, copy->source.mipLevel,
1, copy->source.arrayLayer, 1);
texture->TransitionUsageNow(commandList, dawn::TextureUsageBit::TransferSrc);
buffer->TransitionUsageNow(commandList, dawn::BufferUsageBit::TransferDst);
@ -572,8 +573,8 @@ namespace dawn_native { namespace d3d12 {
copy->destination.imageHeight);
D3D12_TEXTURE_COPY_LOCATION textureLocation =
CreateTextureCopyLocationForTexture(*texture, copy->source.level,
copy->source.slice);
CreateTextureCopyLocationForTexture(*texture, copy->source.mipLevel,
copy->source.arrayLayer);
for (uint32_t i = 0; i < copySplit.count; ++i) {
auto& info = copySplit.copies[i];
@ -610,15 +611,16 @@ namespace dawn_native { namespace d3d12 {
Texture* source = ToBackend(copy->source.texture.Get());
Texture* destination = ToBackend(copy->destination.texture.Get());
source->EnsureSubresourceContentInitialized(commandList, copy->source.level, 1,
copy->source.slice, 1);
source->EnsureSubresourceContentInitialized(commandList, copy->source.mipLevel,
1, copy->source.arrayLayer, 1);
if (IsCompleteSubresourceCopiedTo(destination, copy->copySize,
copy->destination.level)) {
destination->SetIsSubresourceContentInitialized(copy->destination.level, 1,
copy->destination.slice, 1);
copy->destination.mipLevel)) {
destination->SetIsSubresourceContentInitialized(
copy->destination.mipLevel, 1, copy->destination.arrayLayer, 1);
} else {
destination->EnsureSubresourceContentInitialized(
commandList, copy->destination.level, 1, copy->destination.slice, 1);
commandList, copy->destination.mipLevel, 1,
copy->destination.arrayLayer, 1);
}
source->TransitionUsageNow(commandList, dawn::TextureUsageBit::TransferSrc);
destination->TransitionUsageNow(commandList,
@ -630,12 +632,13 @@ namespace dawn_native { namespace d3d12 {
source->GetD3D12Resource());
} else {
D3D12_TEXTURE_COPY_LOCATION srcLocation =
CreateTextureCopyLocationForTexture(*source, copy->source.level,
copy->source.slice);
CreateTextureCopyLocationForTexture(*source, copy->source.mipLevel,
copy->source.arrayLayer);
D3D12_TEXTURE_COPY_LOCATION dstLocation =
CreateTextureCopyLocationForTexture(
*destination, copy->destination.level, copy->destination.slice);
CreateTextureCopyLocationForTexture(*destination,
copy->destination.mipLevel,
copy->destination.arrayLayer);
D3D12_BOX sourceRegion;
sourceRegion.left = copy->source.origin.x;

View File

@ -409,8 +409,8 @@ namespace dawn_native { namespace metal {
sourceBytesPerImage:(src.rowPitch * src.imageHeight)
sourceSize:size
toTexture:texture->GetMTLTexture()
destinationSlice:dst.slice
destinationLevel:dst.level
destinationSlice:dst.arrayLayer
destinationLevel:dst.mipLevel
destinationOrigin:origin];
break;
}
@ -426,8 +426,8 @@ namespace dawn_native { namespace metal {
sourceBytesPerImage:(src.rowPitch * src.imageHeight)
sourceSize:MTLSizeMake(size.width, size.height, size.depth - 1)
toTexture:texture->GetMTLTexture()
destinationSlice:dst.slice
destinationLevel:dst.level
destinationSlice:dst.arrayLayer
destinationLevel:dst.mipLevel
destinationOrigin:origin];
// Update offset to copy to the last image.
@ -442,8 +442,8 @@ namespace dawn_native { namespace metal {
sourceBytesPerImage:(src.rowPitch * (src.imageHeight - 1))
sourceSize:MTLSizeMake(size.width, size.height - 1, 1)
toTexture:texture->GetMTLTexture()
destinationSlice:dst.slice
destinationLevel:dst.level
destinationSlice:dst.arrayLayer
destinationLevel:dst.mipLevel
destinationOrigin:MTLOriginMake(origin.x, origin.y,
origin.z + size.depth - 1)];
@ -462,8 +462,8 @@ namespace dawn_native { namespace metal {
sourceBytesPerImage:lastRowDataSize
sourceSize:MTLSizeMake(size.width, 1, 1)
toTexture:texture->GetMTLTexture()
destinationSlice:dst.slice
destinationLevel:dst.level
destinationSlice:dst.arrayLayer
destinationLevel:dst.mipLevel
destinationOrigin:MTLOriginMake(origin.x, origin.y + size.height - 1,
origin.z + size.depth - 1)];
} break;
@ -515,8 +515,8 @@ namespace dawn_native { namespace metal {
if (!needWorkaround) {
[encoders.blit copyFromTexture:texture->GetMTLTexture()
sourceSlice:src.slice
sourceLevel:src.level
sourceSlice:src.arrayLayer
sourceLevel:src.mipLevel
sourceOrigin:origin
sourceSize:size
toBuffer:buffer->GetMTLBuffer()
@ -533,8 +533,8 @@ namespace dawn_native { namespace metal {
size.depth = copySize.depth - 1;
[encoders.blit copyFromTexture:texture->GetMTLTexture()
sourceSlice:src.slice
sourceLevel:src.level
sourceSlice:src.arrayLayer
sourceLevel:src.mipLevel
sourceOrigin:origin
sourceSize:MTLSizeMake(size.width, size.height,
size.depth - 1)
@ -550,8 +550,8 @@ namespace dawn_native { namespace metal {
// Doing all the copy in last image except the last row.
if (size.height > 1) {
[encoders.blit copyFromTexture:texture->GetMTLTexture()
sourceSlice:src.slice
sourceLevel:src.level
sourceSlice:src.arrayLayer
sourceLevel:src.mipLevel
sourceOrigin:MTLOriginMake(origin.x, origin.y,
origin.z + size.depth - 1)
sourceSize:MTLSizeMake(size.width, size.height - 1, 1)
@ -570,8 +570,8 @@ namespace dawn_native { namespace metal {
[encoders.blit
copyFromTexture:texture->GetMTLTexture()
sourceSlice:src.slice
sourceLevel:src.level
sourceSlice:src.arrayLayer
sourceLevel:src.mipLevel
sourceOrigin:MTLOriginMake(origin.x, origin.y + size.height - 1,
origin.z + size.depth - 1)
sourceSize:MTLSizeMake(size.width, 1, 1)
@ -605,13 +605,13 @@ namespace dawn_native { namespace metal {
encoders.EnsureBlit(commandBuffer);
[encoders.blit copyFromTexture:srcTexture->GetMTLTexture()
sourceSlice:copy->source.slice
sourceLevel:copy->source.level
sourceSlice:copy->source.arrayLayer
sourceLevel:copy->source.mipLevel
sourceOrigin:srcOrigin
sourceSize:size
toTexture:dstTexture->GetMTLTexture()
destinationSlice:copy->destination.slice
destinationLevel:copy->destination.level
destinationSlice:copy->destination.arrayLayer
destinationLevel:copy->destination.mipLevel
destinationOrigin:dstOrigin];
} break;

View File

@ -393,10 +393,12 @@ namespace dawn_native { namespace opengl {
Texture* texture = ToBackend(dst.texture.Get());
GLenum target = texture->GetGLTarget();
auto format = texture->GetGLFormat();
if (IsCompleteSubresourceCopiedTo(texture, copySize, dst.level)) {
texture->SetIsSubresourceContentInitialized(dst.level, 1, dst.slice, 1);
if (IsCompleteSubresourceCopiedTo(texture, copySize, dst.mipLevel)) {
texture->SetIsSubresourceContentInitialized(dst.mipLevel, 1, dst.arrayLayer,
1);
} else {
texture->EnsureSubresourceContentInitialized(dst.level, 1, dst.slice, 1);
texture->EnsureSubresourceContentInitialized(dst.mipLevel, 1,
dst.arrayLayer, 1);
}
gl.BindBuffer(GL_PIXEL_UNPACK_BUFFER, buffer->GetHandle());
@ -410,13 +412,14 @@ namespace dawn_native { namespace opengl {
case dawn::TextureDimension::e2D:
if (texture->GetArrayLayers() > 1) {
gl.TexSubImage3D(
target, dst.level, dst.origin.x, dst.origin.y, dst.slice,
copySize.width, copySize.height, 1, format.format, format.type,
target, dst.mipLevel, dst.origin.x, dst.origin.y,
dst.arrayLayer, copySize.width, copySize.height, 1,
format.format, format.type,
reinterpret_cast<void*>(static_cast<uintptr_t>(src.offset)));
} else {
gl.TexSubImage2D(
target, dst.level, dst.origin.x, dst.origin.y, copySize.width,
copySize.height, format.format, format.type,
target, dst.mipLevel, dst.origin.x, dst.origin.y,
copySize.width, copySize.height, format.format, format.type,
reinterpret_cast<void*>(static_cast<uintptr_t>(src.offset)));
}
break;
@ -440,7 +443,8 @@ namespace dawn_native { namespace opengl {
auto format = texture->GetGLFormat();
GLenum target = texture->GetGLTarget();
texture->EnsureSubresourceContentInitialized(src.level, 1, src.slice, 1);
texture->EnsureSubresourceContentInitialized(src.mipLevel, 1, src.arrayLayer,
1);
// The only way to move data from a texture to a buffer in GL is via
// glReadPixels with a pack buffer. Create a temporary FBO for the copy.
gl.BindTexture(target, texture->GetHandle());
@ -453,11 +457,11 @@ namespace dawn_native { namespace opengl {
if (texture->GetArrayLayers() > 1) {
gl.FramebufferTextureLayer(
GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture->GetHandle(),
src.level, src.slice);
src.mipLevel, src.arrayLayer);
} else {
gl.FramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D, texture->GetHandle(),
src.level);
src.mipLevel);
}
break;
@ -488,16 +492,19 @@ namespace dawn_native { namespace opengl {
auto& copySize = copy->copySize;
Texture* srcTexture = ToBackend(src.texture.Get());
Texture* dstTexture = ToBackend(dst.texture.Get());
srcTexture->EnsureSubresourceContentInitialized(src.level, 1, src.slice, 1);
if (IsCompleteSubresourceCopiedTo(dstTexture, copySize, dst.level)) {
dstTexture->SetIsSubresourceContentInitialized(dst.level, 1, dst.slice, 1);
srcTexture->EnsureSubresourceContentInitialized(src.mipLevel, 1, src.arrayLayer,
1);
if (IsCompleteSubresourceCopiedTo(dstTexture, copySize, dst.mipLevel)) {
dstTexture->SetIsSubresourceContentInitialized(dst.mipLevel, 1,
dst.arrayLayer, 1);
} else {
dstTexture->EnsureSubresourceContentInitialized(dst.level, 1, dst.slice, 1);
dstTexture->EnsureSubresourceContentInitialized(dst.mipLevel, 1,
dst.arrayLayer, 1);
}
gl.CopyImageSubData(srcTexture->GetHandle(), srcTexture->GetGLTarget(),
src.level, src.origin.x, src.origin.y, src.slice,
src.mipLevel, src.origin.x, src.origin.y, src.arrayLayer,
dstTexture->GetHandle(), dstTexture->GetGLTarget(),
dst.level, dst.origin.x, dst.origin.y, dst.slice,
dst.mipLevel, dst.origin.x, dst.origin.y, dst.arrayLayer,
copySize.width, copySize.height, 1);
} break;

View File

@ -50,7 +50,7 @@ namespace dawn_native { namespace vulkan {
const Extent3D& copySize) {
Extent3D validTextureCopyExtent = copySize;
const TextureBase* texture = textureCopy.texture.Get();
Extent3D virtualSizeAtLevel = texture->GetMipLevelVirtualSize(textureCopy.level);
Extent3D virtualSizeAtLevel = texture->GetMipLevelVirtualSize(textureCopy.mipLevel);
if (textureCopy.origin.x + copySize.width > virtualSizeAtLevel.width) {
ASSERT(texture->GetFormat().isCompressed);
validTextureCopyExtent.width = virtualSizeAtLevel.width - textureCopy.origin.x;
@ -78,8 +78,8 @@ namespace dawn_native { namespace vulkan {
region.bufferImageHeight = bufferCopy.imageHeight;
region.imageSubresource.aspectMask = texture->GetVkAspectMask();
region.imageSubresource.mipLevel = textureCopy.level;
region.imageSubresource.baseArrayLayer = textureCopy.slice;
region.imageSubresource.mipLevel = textureCopy.mipLevel;
region.imageSubresource.baseArrayLayer = textureCopy.arrayLayer;
region.imageSubresource.layerCount = 1;
region.imageOffset.x = textureCopy.origin.x;
@ -103,8 +103,8 @@ namespace dawn_native { namespace vulkan {
VkImageCopy region;
region.srcSubresource.aspectMask = srcTexture->GetVkAspectMask();
region.srcSubresource.mipLevel = srcCopy.level;
region.srcSubresource.baseArrayLayer = srcCopy.slice;
region.srcSubresource.mipLevel = srcCopy.mipLevel;
region.srcSubresource.baseArrayLayer = srcCopy.arrayLayer;
region.srcSubresource.layerCount = 1;
region.srcOffset.x = srcCopy.origin.x;
@ -112,8 +112,8 @@ namespace dawn_native { namespace vulkan {
region.srcOffset.z = srcCopy.origin.z;
region.dstSubresource.aspectMask = dstTexture->GetVkAspectMask();
region.dstSubresource.mipLevel = dstCopy.level;
region.dstSubresource.baseArrayLayer = dstCopy.slice;
region.dstSubresource.mipLevel = dstCopy.mipLevel;
region.dstSubresource.baseArrayLayer = dstCopy.arrayLayer;
region.dstSubresource.layerCount = 1;
region.dstOffset.x = dstCopy.origin.x;

View File

@ -245,13 +245,13 @@ namespace utils {
}
dawn::TextureCopyView CreateTextureCopyView(dawn::Texture texture,
uint32_t level,
uint32_t slice,
uint32_t mipLevel,
uint32_t arrayLayer,
dawn::Origin3D origin) {
dawn::TextureCopyView textureCopyView;
textureCopyView.texture = texture;
textureCopyView.level = level;
textureCopyView.slice = slice;
textureCopyView.mipLevel = mipLevel;
textureCopyView.arrayLayer = arrayLayer;
textureCopyView.origin = origin;
return textureCopyView;