Commit 04dae5ec by Alexis Hetu Committed by Alexis Hétu

Use the ImageView's format in clear operations

Added support for using the ImageView's format to perform clear operations. Bug b/119620767 Tests: dEQP-VK.image.mutable.*_draw_copy Change-Id: I3ea6d3264435bbd8390c7a8907e0c7a54c4c6783 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/28508Tested-by: 's avatarAlexis Hétu <sugoi@google.com> Presubmit-Ready: Alexis Hétu <sugoi@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Reviewed-by: 's avatarChris Forbes <chrisforbes@google.com>
parent 32a9ea1c
......@@ -34,20 +34,21 @@ namespace sw
delete blitCache;
}
void Blitter::clear(void *pixel, vk::Format format, vk::Image *dest, const VkImageSubresourceRange& subresourceRange, const VkRect2D* renderArea)
void Blitter::clear(void *pixel, vk::Format format, vk::Image *dest, const vk::Format& viewFormat, const VkImageSubresourceRange& subresourceRange, const VkRect2D* renderArea)
{
VkImageAspectFlagBits aspect = static_cast<VkImageAspectFlagBits>(subresourceRange.aspectMask);
if(dest->getFormat(aspect) == VK_FORMAT_UNDEFINED)
vk::Format dstFormat = vk::Image::GetFormat(viewFormat, aspect);
if(dstFormat == VK_FORMAT_UNDEFINED)
{
return;
}
if(fastClear(pixel, format, dest, subresourceRange, renderArea))
if(fastClear(pixel, format, dest, dstFormat, subresourceRange, renderArea))
{
return;
}
State state(format, dest->getFormat(aspect), 1, dest->getSampleCountFlagBits(), { 0xF });
State state(format, dstFormat, 1, dest->getSampleCountFlagBits(), { 0xF });
Routine *blitRoutine = getRoutine(state);
if(!blitRoutine)
{
......@@ -112,7 +113,7 @@ namespace sw
}
}
bool Blitter::fastClear(void *pixel, vk::Format format, vk::Image *dest, const VkImageSubresourceRange& subresourceRange, const VkRect2D* renderArea)
bool Blitter::fastClear(void *pixel, vk::Format format, vk::Image *dest, const vk::Format& viewFormat, const VkImageSubresourceRange& subresourceRange, const VkRect2D* renderArea)
{
if(format != VK_FORMAT_R32G32B32A32_SFLOAT)
{
......@@ -128,7 +129,7 @@ namespace sw
uint32_t packed;
VkImageAspectFlagBits aspect = static_cast<VkImageAspectFlagBits>(subresourceRange.aspectMask);
switch(dest->getFormat(aspect))
switch(viewFormat)
{
case VK_FORMAT_R5G6B5_UNORM_PACK16:
packed = ((uint16_t)(31 * b + 0.5f) << 0) |
......@@ -203,7 +204,7 @@ namespace sw
{
uint8_t *d = slice;
switch(dest->getFormat(aspect).bytes())
switch(viewFormat.bytes())
{
case 2:
for(uint32_t i = 0; i < area.extent.height; i++)
......
......@@ -104,12 +104,12 @@ namespace sw
Blitter();
virtual ~Blitter();
void clear(void *pixel, vk::Format format, vk::Image *dest, const VkImageSubresourceRange& subresourceRange, const VkRect2D* renderArea = nullptr);
void clear(void *pixel, vk::Format format, vk::Image *dest, const vk::Format& viewFormat, const VkImageSubresourceRange& subresourceRange, const VkRect2D* renderArea = nullptr);
void blit(vk::Image *src, vk::Image *dst, VkImageBlit region, VkFilter filter);
private:
bool fastClear(void *pixel, vk::Format format, vk::Image *dest, const VkImageSubresourceRange& subresourceRange, const VkRect2D* renderArea);
bool fastClear(void *pixel, vk::Format format, vk::Image *dest, const vk::Format& viewFormat, const VkImageSubresourceRange& subresourceRange, const VkRect2D* renderArea);
bool read(Float4 &color, Pointer<Byte> element, const State &state);
bool write(Float4 &color, Pointer<Byte> element, const State &state);
......
......@@ -45,6 +45,7 @@ public:
bool isSRGBwritable() const;
bool isFloatFormat() const;
bool isCompatible(const Format& other) const;
bool isCompressed() const;
int blockWidth() const;
int blockHeight() const;
......@@ -68,6 +69,8 @@ public:
bool isRGBComponent(int component) const;
private:
VkFormat compatibleFormat() const;
VkFormat format = VK_FORMAT_UNDEFINED;
};
......
......@@ -502,6 +502,11 @@ int Image::bytesPerTexel(VkImageAspectFlagBits aspect) const
Format Image::getFormat(VkImageAspectFlagBits aspect) const
{
return GetFormat(format, aspect);
}
Format Image::GetFormat(const vk::Format& format, VkImageAspectFlagBits aspect)
{
switch(aspect)
{
case VK_IMAGE_ASPECT_DEPTH_BIT:
......@@ -644,7 +649,7 @@ uint32_t Image::getLastMipLevel(const VkImageSubresourceRange& subresourceRange)
mipLevels : (subresourceRange.baseMipLevel + subresourceRange.levelCount)) - 1;
}
void Image::clear(void* pixelData, VkFormat format, const VkImageSubresourceRange& subresourceRange, const VkRect2D& renderArea)
void Image::clear(void* pixelData, VkFormat pixelFormat, const vk::Format& viewFormat, const VkImageSubresourceRange& subresourceRange, const VkRect2D& renderArea)
{
if((subresourceRange.baseMipLevel != 0) ||
(subresourceRange.levelCount != 1))
......@@ -652,7 +657,7 @@ void Image::clear(void* pixelData, VkFormat format, const VkImageSubresourceRang
UNIMPLEMENTED("subresourceRange");
}
device->getBlitter()->clear(pixelData, format, this, subresourceRange, &renderArea);
device->getBlitter()->clear(pixelData, pixelFormat, this, viewFormat, subresourceRange, &renderArea);
}
void Image::clear(const VkClearColorValue& color, const VkImageSubresourceRange& subresourceRange)
......@@ -662,7 +667,7 @@ void Image::clear(const VkClearColorValue& color, const VkImageSubresourceRange&
UNIMPLEMENTED("aspectMask");
}
device->getBlitter()->clear((void*)color.float32, getClearFormat(), this, subresourceRange);
device->getBlitter()->clear((void*)color.float32, getClearFormat(), this, format, subresourceRange);
}
void Image::clear(const VkClearDepthStencilValue& color, const VkImageSubresourceRange& subresourceRange)
......@@ -677,18 +682,18 @@ void Image::clear(const VkClearDepthStencilValue& color, const VkImageSubresourc
{
VkImageSubresourceRange depthSubresourceRange = subresourceRange;
depthSubresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
device->getBlitter()->clear((void*)(&color.depth), VK_FORMAT_D32_SFLOAT, this, depthSubresourceRange);
device->getBlitter()->clear((void*)(&color.depth), VK_FORMAT_D32_SFLOAT, this, format, depthSubresourceRange);
}
if(subresourceRange.aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT)
{
VkImageSubresourceRange stencilSubresourceRange = subresourceRange;
stencilSubresourceRange.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
device->getBlitter()->clear((void*)(&color.stencil), VK_FORMAT_S8_UINT, this, stencilSubresourceRange);
device->getBlitter()->clear((void*)(&color.stencil), VK_FORMAT_S8_UINT, this, format, stencilSubresourceRange);
}
}
void Image::clear(const VkClearValue& clearValue, const VkRect2D& renderArea, const VkImageSubresourceRange& subresourceRange)
void Image::clear(const VkClearValue& clearValue, const vk::Format& viewFormat, const VkRect2D& renderArea, const VkImageSubresourceRange& subresourceRange)
{
if(!((subresourceRange.aspectMask == VK_IMAGE_ASPECT_COLOR_BIT) ||
(subresourceRange.aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT |
......@@ -701,7 +706,7 @@ void Image::clear(const VkClearValue& clearValue, const VkRect2D& renderArea, co
if(subresourceRange.aspectMask == VK_IMAGE_ASPECT_COLOR_BIT)
{
clear((void*)(clearValue.color.float32), getClearFormat(), subresourceRange, renderArea);
clear((void*)(clearValue.color.float32), getClearFormat(), viewFormat, subresourceRange, renderArea);
}
else
{
......@@ -709,14 +714,14 @@ void Image::clear(const VkClearValue& clearValue, const VkRect2D& renderArea, co
{
VkImageSubresourceRange depthSubresourceRange = subresourceRange;
depthSubresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
clear((void*)(&clearValue.depthStencil.depth), VK_FORMAT_D32_SFLOAT, depthSubresourceRange, renderArea);
clear((void*)(&clearValue.depthStencil.depth), VK_FORMAT_D32_SFLOAT, viewFormat, depthSubresourceRange, renderArea);
}
if(subresourceRange.aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT)
{
VkImageSubresourceRange stencilSubresourceRange = subresourceRange;
stencilSubresourceRange.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
clear((void*)(&clearValue.depthStencil.stencil), VK_FORMAT_S8_UINT, stencilSubresourceRange, renderArea);
clear((void*)(&clearValue.depthStencil.stencil), VK_FORMAT_S8_UINT, viewFormat, stencilSubresourceRange, renderArea);
}
}
}
......
......@@ -47,7 +47,7 @@ public:
void copyFrom(VkBuffer srcBuffer, const VkBufferImageCopy& region);
void blit(VkImage dstImage, const VkImageBlit& region, VkFilter filter);
void clear(const VkClearValue& clearValue, const VkRect2D& renderArea, const VkImageSubresourceRange& subresourceRange);
void clear(const VkClearValue& clearValue, const vk::Format& viewFormat, const VkRect2D& renderArea, const VkImageSubresourceRange& subresourceRange);
void clear(const VkClearColorValue& color, const VkImageSubresourceRange& subresourceRange);
void clear(const VkClearDepthStencilValue& color, const VkImageSubresourceRange& subresourceRange);
......@@ -67,6 +67,8 @@ public:
bool isCube() const;
uint8_t* end() const;
static Format GetFormat(const vk::Format& format, VkImageAspectFlagBits aspect);
private:
void copy(VkBuffer buffer, const VkBufferImageCopy& region, bool bufferIsSource);
VkDeviceSize getStorageSize(VkImageAspectFlags flags) const;
......@@ -82,7 +84,7 @@ private:
VkExtent2D bufferExtentInBlocks(const VkExtent2D& extent, const VkBufferImageCopy& region) const;
int bytesPerTexel(VkImageAspectFlagBits flags) const;
VkFormat getClearFormat() const;
void clear(void* pixelData, VkFormat format, const VkImageSubresourceRange& subresourceRange, const VkRect2D& renderArea);
void clear(void* pixelData, VkFormat pixelFormat, const vk::Format& viewFormat, const VkImageSubresourceRange& subresourceRange, const VkRect2D& renderArea);
int borderSize(VkImageAspectFlagBits aspect) const;
const Device *const device = nullptr;
......
......@@ -87,14 +87,14 @@ void ImageView::clear(const VkClearValue& clearValue, const VkImageAspectFlags a
UNIMPLEMENTED("imageTypesMatch");
}
if(image->getFormat() != format)
if(!format.isCompatible(image->getFormat()))
{
UNIMPLEMENTED("format");
UNIMPLEMENTED("incompatible formats");
}
VkImageSubresourceRange sr = subresourceRange;
sr.aspectMask = aspectMask;
image->clear(clearValue, renderArea, sr);
image->clear(clearValue, format, renderArea, sr);
}
void ImageView::clear(const VkClearValue& clearValue, const VkImageAspectFlags aspectMask, const VkClearRect& renderArea)
......@@ -106,10 +106,10 @@ void ImageView::clear(const VkClearValue& clearValue, const VkImageAspectFlags a
UNIMPLEMENTED("imageTypesMatch");
}
if(image->getFormat() != format)
if(!format.isCompatible(image->getFormat()))
{
UNIMPLEMENTED("format");
}
UNIMPLEMENTED("incompatible formats");
}
VkImageSubresourceRange sr;
sr.aspectMask = aspectMask;
......@@ -118,7 +118,7 @@ void ImageView::clear(const VkClearValue& clearValue, const VkImageAspectFlags a
sr.baseArrayLayer = renderArea.baseArrayLayer + subresourceRange.baseArrayLayer;
sr.layerCount = renderArea.layerCount;
image->clear(clearValue, renderArea.rect, sr);
image->clear(clearValue, format, renderArea.rect, sr);
}
void ImageView::resolve(ImageView* resolveAttachment)
......
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