From 3c3e2bc4d90f170a6384f52021b90492d1d57958 Mon Sep 17 00:00:00 2001 From: Corentin Wallez Date: Mon, 8 Jul 2019 09:41:51 +0000 Subject: [PATCH] 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 Reviewed-by: Austin Eng --- dawn.json | 4 +- src/dawn_native/CommandEncoder.cpp | 30 +++++++------- src/dawn_native/Commands.h | 4 +- src/dawn_native/d3d12/CommandBufferD3D12.cpp | 43 +++++++++++--------- src/dawn_native/metal/CommandBufferMTL.mm | 40 +++++++++--------- src/dawn_native/opengl/CommandBufferGL.cpp | 39 ++++++++++-------- src/dawn_native/vulkan/CommandBufferVk.cpp | 14 +++---- src/utils/DawnHelpers.cpp | 8 ++-- 8 files changed, 95 insertions(+), 87 deletions(-) diff --git a/dawn.json b/dawn.json index c5403489ea..e1639a0c78 100644 --- a/dawn.json +++ b/dawn.json @@ -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"} ] }, diff --git a/src/dawn_native/CommandEncoder.cpp b/src/dawn_native/CommandEncoder.cpp index 6a2656f830..b8bc34ca68 100644 --- a/src/dawn_native/CommandEncoder.cpp +++ b/src/dawn_native/CommandEncoder.cpp @@ -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(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(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; } diff --git a/src/dawn_native/Commands.h b/src/dawn_native/Commands.h index c514e9ca34..24e4e11543 100644 --- a/src/dawn_native/Commands.h +++ b/src/dawn_native/Commands.h @@ -100,8 +100,8 @@ namespace dawn_native { struct TextureCopy { Ref texture; - uint32_t level; - uint32_t slice; + uint32_t mipLevel; + uint32_t arrayLayer; Origin3D origin; // Texels }; diff --git a/src/dawn_native/d3d12/CommandBufferD3D12.cpp b/src/dawn_native/d3d12/CommandBufferD3D12.cpp index 0a6261077d..75f927d24d 100644 --- a/src/dawn_native/d3d12/CommandBufferD3D12.cpp +++ b/src/dawn_native/d3d12/CommandBufferD3D12.cpp @@ -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; diff --git a/src/dawn_native/metal/CommandBufferMTL.mm b/src/dawn_native/metal/CommandBufferMTL.mm index ac4bafe053..b0372853d5 100644 --- a/src/dawn_native/metal/CommandBufferMTL.mm +++ b/src/dawn_native/metal/CommandBufferMTL.mm @@ -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; diff --git a/src/dawn_native/opengl/CommandBufferGL.cpp b/src/dawn_native/opengl/CommandBufferGL.cpp index 2e4a062aba..c1a3d452d7 100644 --- a/src/dawn_native/opengl/CommandBufferGL.cpp +++ b/src/dawn_native/opengl/CommandBufferGL.cpp @@ -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(static_cast(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(static_cast(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; diff --git a/src/dawn_native/vulkan/CommandBufferVk.cpp b/src/dawn_native/vulkan/CommandBufferVk.cpp index 706efeeb1d..1ad5280835 100644 --- a/src/dawn_native/vulkan/CommandBufferVk.cpp +++ b/src/dawn_native/vulkan/CommandBufferVk.cpp @@ -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; diff --git a/src/utils/DawnHelpers.cpp b/src/utils/DawnHelpers.cpp index 9bb3cc6627..f955057e08 100644 --- a/src/utils/DawnHelpers.cpp +++ b/src/utils/DawnHelpers.cpp @@ -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;