Commit c55fd97b by Nicolas Capens Committed by Nicolas Capens

Fix image slice / plane name usage

Image planes have a distinct meaning in Vulkan, signifying the disjoint memory regions which store components of a texel format. Typically this includes YCbCr formats that can have 2 or 3 planes for luminance and chroma data. Slices refer to 2D sections of 3D images. Currently we also use slices for storing each sample of a multisample image separately. Note only 2D images can be multisampled, so there are no 3D images with slices for the depth and the number of samples. Bug: b/159210008 Change-Id: I4b70a7b8bb49e79c7494e28aa8280752a5b9727d Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/46288 Presubmit-Ready: Nicolas Capens <nicolascapens@google.com> Kokoro-Result: kokoro <noreply+kokoro@google.com> Tested-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarAntonio Maiorano <amaiorano@google.com>
parent 5bd80722
...@@ -342,8 +342,8 @@ void Image::copyTo(Image *dstImage, const VkImageCopy &region) const ...@@ -342,8 +342,8 @@ void Image::copyTo(Image *dstImage, const VkImageCopy &region) const
return device->getBlitter()->blit(this, dstImage, blitRegion, VK_FILTER_NEAREST); return device->getBlitter()->blit(this, dstImage, blitRegion, VK_FILTER_NEAREST);
} }
int srcBytesPerBlock = srcFormat.bytesPerBlock(); int bytesPerBlock = srcFormat.bytesPerBlock();
ASSERT(srcBytesPerBlock == dstFormat.bytesPerBlock()); ASSERT(bytesPerBlock == dstFormat.bytesPerBlock());
const uint8_t *srcMem = static_cast<const uint8_t *>(getTexelPointer(region.srcOffset, { region.srcSubresource.aspectMask, region.srcSubresource.mipLevel, region.srcSubresource.baseArrayLayer })); const uint8_t *srcMem = static_cast<const uint8_t *>(getTexelPointer(region.srcOffset, { region.srcSubresource.aspectMask, region.srcSubresource.mipLevel, region.srcSubresource.baseArrayLayer }));
uint8_t *dstMem = static_cast<uint8_t *>(dstImage->getTexelPointer(region.dstOffset, { region.dstSubresource.aspectMask, region.dstSubresource.mipLevel, region.dstSubresource.baseArrayLayer })); uint8_t *dstMem = static_cast<uint8_t *>(dstImage->getTexelPointer(region.dstOffset, { region.dstSubresource.aspectMask, region.dstSubresource.mipLevel, region.dstSubresource.baseArrayLayer }));
...@@ -357,8 +357,8 @@ void Image::copyTo(Image *dstImage, const VkImageCopy &region) const ...@@ -357,8 +357,8 @@ void Image::copyTo(Image *dstImage, const VkImageCopy &region) const
VkExtent3D dstExtent = dstImage->getMipLevelExtent(dstAspect, region.dstSubresource.mipLevel); VkExtent3D dstExtent = dstImage->getMipLevelExtent(dstAspect, region.dstSubresource.mipLevel);
VkExtent3D copyExtent = imageExtentInBlocks(region.extent, srcAspect); VkExtent3D copyExtent = imageExtentInBlocks(region.extent, srcAspect);
bool isSinglePlane = (copyExtent.depth == 1); bool isSingleSlice = (copyExtent.depth == 1);
bool isSingleLine = (copyExtent.height == 1) && isSinglePlane; bool isSingleLine = (copyExtent.height == 1) && isSingleSlice;
// In order to copy multiple lines using a single memcpy call, we // In order to copy multiple lines using a single memcpy call, we
// have to make sure that we need to copy the entire line and that // have to make sure that we need to copy the entire line and that
// both source and destination lines have the same length in bytes // both source and destination lines have the same length in bytes
...@@ -373,36 +373,36 @@ void Image::copyTo(Image *dstImage, const VkImageCopy &region) const ...@@ -373,36 +373,36 @@ void Image::copyTo(Image *dstImage, const VkImageCopy &region) const
// srcRowPitchBytes * dstBlockWidth == dstRowPitchBytes * srcBlockWidth // srcRowPitchBytes * dstBlockWidth == dstRowPitchBytes * srcBlockWidth
((srcRowPitchBytes * dstFormat.blockWidth()) == ((srcRowPitchBytes * dstFormat.blockWidth()) ==
(dstRowPitchBytes * srcFormat.blockWidth())); (dstRowPitchBytes * srcFormat.blockWidth()));
// In order to copy multiple planes using a single memcpy call, we // In order to copy multiple slices using a single memcpy call, we
// have to make sure that we need to copy the entire plane and that // have to make sure that we need to copy the entire slice and that
// both source and destination planes have the same length in bytes // both source and destination slices have the same length in bytes
bool isEntirePlane = isEntireLine && bool isEntireSlice = isEntireLine &&
(copyExtent.height == srcExtent.height) && (copyExtent.height == srcExtent.height) &&
(copyExtent.height == dstExtent.height) && (copyExtent.height == dstExtent.height) &&
(srcSlicePitchBytes == dstSlicePitchBytes); (srcSlicePitchBytes == dstSlicePitchBytes);
if(isSingleLine) // Copy one line if(isSingleLine) // Copy one line
{ {
size_t copySize = copyExtent.width * srcBytesPerBlock; size_t copySize = copyExtent.width * bytesPerBlock;
ASSERT((srcMem + copySize) < end()); ASSERT((srcMem + copySize) < end());
ASSERT((dstMem + copySize) < dstImage->end()); ASSERT((dstMem + copySize) < dstImage->end());
memcpy(dstMem, srcMem, copySize); memcpy(dstMem, srcMem, copySize);
} }
else if(isEntireLine && isSinglePlane) // Copy one plane else if(isEntireLine && isSingleSlice) // Copy one slice
{ {
size_t copySize = copyExtent.height * srcRowPitchBytes; size_t copySize = copyExtent.height * srcRowPitchBytes;
ASSERT((srcMem + copySize) < end()); ASSERT((srcMem + copySize) < end());
ASSERT((dstMem + copySize) < dstImage->end()); ASSERT((dstMem + copySize) < dstImage->end());
memcpy(dstMem, srcMem, copySize); memcpy(dstMem, srcMem, copySize);
} }
else if(isEntirePlane) // Copy multiple planes else if(isEntireSlice) // Copy multiple slices
{ {
size_t copySize = copyExtent.depth * srcSlicePitchBytes; size_t copySize = copyExtent.depth * srcSlicePitchBytes;
ASSERT((srcMem + copySize) < end()); ASSERT((srcMem + copySize) < end());
ASSERT((dstMem + copySize) < dstImage->end()); ASSERT((dstMem + copySize) < dstImage->end());
memcpy(dstMem, srcMem, copySize); memcpy(dstMem, srcMem, copySize);
} }
else if(isEntireLine) // Copy plane by plane else if(isEntireLine) // Copy slice by slice
{ {
size_t copySize = copyExtent.height * srcRowPitchBytes; size_t copySize = copyExtent.height * srcRowPitchBytes;
...@@ -415,7 +415,7 @@ void Image::copyTo(Image *dstImage, const VkImageCopy &region) const ...@@ -415,7 +415,7 @@ void Image::copyTo(Image *dstImage, const VkImageCopy &region) const
} }
else // Copy line by line else // Copy line by line
{ {
size_t copySize = copyExtent.width * srcBytesPerBlock; size_t copySize = copyExtent.width * bytesPerBlock;
for(uint32_t z = 0; z < copyExtent.depth; z++, dstMem += dstSlicePitchBytes, srcMem += srcSlicePitchBytes) for(uint32_t z = 0; z < copyExtent.depth; z++, dstMem += dstSlicePitchBytes, srcMem += srcSlicePitchBytes)
{ {
...@@ -472,11 +472,11 @@ void Image::copy(Buffer *buffer, const VkBufferImageCopy &region, bool bufferIsS ...@@ -472,11 +472,11 @@ void Image::copy(Buffer *buffer, const VkBufferImageCopy &region, bool bufferIsS
int dstRowPitchBytes = bufferIsSource ? imageRowPitchBytes : bufferRowPitchBytes; int dstRowPitchBytes = bufferIsSource ? imageRowPitchBytes : bufferRowPitchBytes;
VkExtent3D mipLevelExtent = getMipLevelExtent(aspect, region.imageSubresource.mipLevel); VkExtent3D mipLevelExtent = getMipLevelExtent(aspect, region.imageSubresource.mipLevel);
bool isSinglePlane = (imageExtent.depth == 1); bool isSingleSlice = (imageExtent.depth == 1);
bool isSingleLine = (imageExtent.height == 1) && isSinglePlane; bool isSingleLine = (imageExtent.height == 1) && isSingleSlice;
bool isEntireLine = (imageExtent.width == mipLevelExtent.width) && bool isEntireLine = (imageExtent.width == mipLevelExtent.width) &&
(imageRowPitchBytes == bufferRowPitchBytes); (imageRowPitchBytes == bufferRowPitchBytes);
bool isEntirePlane = isEntireLine && (imageExtent.height == mipLevelExtent.height) && bool isEntireSlice = isEntireLine && (imageExtent.height == mipLevelExtent.height) &&
(imageSlicePitchBytes == bufferSlicePitchBytes); (imageSlicePitchBytes == bufferSlicePitchBytes);
VkDeviceSize copySize = 0; VkDeviceSize copySize = 0;
...@@ -486,17 +486,17 @@ void Image::copy(Buffer *buffer, const VkBufferImageCopy &region, bool bufferIsS ...@@ -486,17 +486,17 @@ void Image::copy(Buffer *buffer, const VkBufferImageCopy &region, bool bufferIsS
copySize = imageExtent.width * bytesPerBlock; copySize = imageExtent.width * bytesPerBlock;
bufferLayerSize = copySize; bufferLayerSize = copySize;
} }
else if(isEntireLine && isSinglePlane) else if(isEntireLine && isSingleSlice)
{ {
copySize = imageExtent.height * imageRowPitchBytes; copySize = imageExtent.height * imageRowPitchBytes;
bufferLayerSize = copySize; bufferLayerSize = copySize;
} }
else if(isEntirePlane) else if(isEntireSlice)
{ {
copySize = imageExtent.depth * imageSlicePitchBytes; // Copy multiple planes copySize = imageExtent.depth * imageSlicePitchBytes; // Copy multiple slices
bufferLayerSize = copySize; bufferLayerSize = copySize;
} }
else if(isEntireLine) // Copy plane by plane else if(isEntireLine) // Copy slice by slice
{ {
copySize = imageExtent.height * imageRowPitchBytes; copySize = imageExtent.height * imageRowPitchBytes;
bufferLayerSize = copySize * imageExtent.depth; bufferLayerSize = copySize * imageExtent.depth;
...@@ -513,23 +513,23 @@ void Image::copy(Buffer *buffer, const VkBufferImageCopy &region, bool bufferIsS ...@@ -513,23 +513,23 @@ void Image::copy(Buffer *buffer, const VkBufferImageCopy &region, bool bufferIsS
for(uint32_t i = 0; i < region.imageSubresource.layerCount; i++) for(uint32_t i = 0; i < region.imageSubresource.layerCount; i++)
{ {
if(isSingleLine || (isEntireLine && isSinglePlane) || isEntirePlane) if(isSingleLine || (isEntireLine && isSingleSlice) || isEntireSlice)
{ {
ASSERT(((bufferIsSource ? dstMemory : srcMemory) + copySize) < end()); ASSERT(((bufferIsSource ? dstMemory : srcMemory) + copySize) < end());
ASSERT(((bufferIsSource ? srcMemory : dstMemory) + copySize) < buffer->end()); ASSERT(((bufferIsSource ? srcMemory : dstMemory) + copySize) < buffer->end());
memcpy(dstMemory, srcMemory, copySize); memcpy(dstMemory, srcMemory, copySize);
} }
else if(isEntireLine) // Copy plane by plane else if(isEntireLine) // Copy slice by slice
{ {
uint8_t *srcPlaneMemory = srcMemory; uint8_t *srcSliceMemory = srcMemory;
uint8_t *dstPlaneMemory = dstMemory; uint8_t *dstSliceMemory = dstMemory;
for(uint32_t z = 0; z < imageExtent.depth; z++) for(uint32_t z = 0; z < imageExtent.depth; z++)
{ {
ASSERT(((bufferIsSource ? dstPlaneMemory : srcPlaneMemory) + copySize) < end()); ASSERT(((bufferIsSource ? dstSliceMemory : srcSliceMemory) + copySize) < end());
ASSERT(((bufferIsSource ? srcPlaneMemory : dstPlaneMemory) + copySize) < buffer->end()); ASSERT(((bufferIsSource ? srcSliceMemory : dstSliceMemory) + copySize) < buffer->end());
memcpy(dstPlaneMemory, srcPlaneMemory, copySize); memcpy(dstSliceMemory, srcSliceMemory, copySize);
srcPlaneMemory += srcSlicePitchBytes; srcSliceMemory += srcSlicePitchBytes;
dstPlaneMemory += dstSlicePitchBytes; dstSliceMemory += dstSlicePitchBytes;
} }
} }
else // Copy line by line else // Copy line by line
...@@ -538,15 +538,15 @@ void Image::copy(Buffer *buffer, const VkBufferImageCopy &region, bool bufferIsS ...@@ -538,15 +538,15 @@ void Image::copy(Buffer *buffer, const VkBufferImageCopy &region, bool bufferIsS
uint8_t *dstLayerMemory = dstMemory; uint8_t *dstLayerMemory = dstMemory;
for(uint32_t z = 0; z < imageExtent.depth; z++) for(uint32_t z = 0; z < imageExtent.depth; z++)
{ {
uint8_t *srcPlaneMemory = srcLayerMemory; uint8_t *srcSliceMemory = srcLayerMemory;
uint8_t *dstPlaneMemory = dstLayerMemory; uint8_t *dstSliceMemory = dstLayerMemory;
for(uint32_t y = 0; y < imageExtent.height; y++) for(uint32_t y = 0; y < imageExtent.height; y++)
{ {
ASSERT(((bufferIsSource ? dstPlaneMemory : srcPlaneMemory) + copySize) < end()); ASSERT(((bufferIsSource ? dstSliceMemory : srcSliceMemory) + copySize) < end());
ASSERT(((bufferIsSource ? srcPlaneMemory : dstPlaneMemory) + copySize) < buffer->end()); ASSERT(((bufferIsSource ? srcSliceMemory : dstSliceMemory) + copySize) < buffer->end());
memcpy(dstPlaneMemory, srcPlaneMemory, copySize); memcpy(dstSliceMemory, srcSliceMemory, copySize);
srcPlaneMemory += srcRowPitchBytes; srcSliceMemory += srcRowPitchBytes;
dstPlaneMemory += dstRowPitchBytes; dstSliceMemory += dstRowPitchBytes;
} }
srcLayerMemory += srcSlicePitchBytes; srcLayerMemory += srcSlicePitchBytes;
dstLayerMemory += dstSlicePitchBytes; dstLayerMemory += dstSlicePitchBytes;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment