Commit 3364227f by Alexis Hetu Committed by Alexis Hétu

Allow the Blitter to clear and blit vk::Image objects directly

The sw::Surface object was the intermediate representation of an image used between the vk::Image and the Blitter. This cl removes the need for an intermediate representation by having the Blitter use the vk::Image directly. There should be no regression for the clear and blit tests. Bug b/126883332 Change-Id: Icbc15470e3ad112ed78f4f62d6d82c66e3e37a20 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/25928Tested-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 654540e8
......@@ -21,6 +21,11 @@
#include <string.h>
namespace vk
{
class Image;
}
namespace sw
{
class Blitter
......@@ -57,6 +62,8 @@ namespace sw
{
State() = default;
State(const Options &options) : Options(options) {}
State(VkFormat sourceFormat, VkFormat destFormat, int destSamples, const Options &options) :
Options(options), sourceFormat(sourceFormat), destFormat(destFormat), destSamples(destSamples) {}
bool operator==(const State &state) const
{
......@@ -95,11 +102,15 @@ namespace sw
virtual ~Blitter();
void clear(void *pixel, VkFormat format, Surface *dest, const SliceRect &dRect, unsigned int rgbaMask);
void clear(void *pixel, VkFormat format, vk::Image *dest, const VkImageSubresourceRange& subresourceRange, const VkRect2D* renderArea = nullptr);
void blit(Surface *source, const SliceRectF &sRect, Surface *dest, const SliceRect &dRect, const Options &options);
void blit(vk::Image *src, vk::Image *dst, VkImageBlit region, VkFilter filter);
void blit3D(Surface *source, Surface *dest);
private:
bool fastClear(void *pixel, VkFormat format, Surface *dest, const SliceRect &dRect, unsigned int rgbaMask);
bool fastClear(void *pixel, VkFormat format, vk::Image *dest, 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);
......@@ -111,6 +122,7 @@ namespace sw
static Float4 LinearToSRGB(Float4 &color);
static Float4 sRGBtoLinear(Float4 &color);
bool blitReactor(Surface *source, const SliceRectF &sRect, Surface *dest, const SliceRect &dRect, const Options &options);
Routine *getRoutine(const State &state);
Routine *generate(const State &state);
RoutineCache<State> *blitCache;
......
......@@ -458,50 +458,9 @@ VkDeviceSize Image::getStorageSize(VkImageAspectFlags aspectMask) const
return arrayLayers * getLayerSize(static_cast<VkImageAspectFlagBits>(aspectMask));
}
sw::Surface* Image::asSurface(VkImageAspectFlagBits aspect, uint32_t mipLevel, uint32_t layer) const
{
VkExtent3D mipLevelExtent = getMipLevelExtent(mipLevel);
return sw::Surface::create(mipLevelExtent.width, mipLevelExtent.height, mipLevelExtent.depth, getFormat(aspect),
deviceMemory->getOffsetPointer(getMemoryOffset(aspect, mipLevel, layer)),
rowPitchBytes(aspect, mipLevel), slicePitchBytes(aspect, mipLevel));
}
void Image::blit(VkImage dstImage, const VkImageBlit& region, VkFilter filter)
{
VkImageAspectFlagBits srcAspect = static_cast<VkImageAspectFlagBits>(region.srcSubresource.aspectMask);
VkImageAspectFlagBits dstAspect = static_cast<VkImageAspectFlagBits>(region.dstSubresource.aspectMask);
if((region.srcSubresource.baseArrayLayer != 0) ||
(region.dstSubresource.baseArrayLayer != 0) ||
(region.srcSubresource.layerCount != 1) ||
(region.dstSubresource.layerCount != 1) ||
(srcAspect != dstAspect))
{
UNIMPLEMENTED();
}
int32_t numSlices = (region.srcOffsets[1].z - region.srcOffsets[0].z);
ASSERT(numSlices == (region.dstOffsets[1].z - region.dstOffsets[0].z));
sw::Surface* srcSurface = asSurface(srcAspect, region.srcSubresource.mipLevel, 0);
sw::Surface* dstSurface = Cast(dstImage)->asSurface(dstAspect, region.dstSubresource.mipLevel, 0);
sw::SliceRectF sRect(static_cast<float>(region.srcOffsets[0].x), static_cast<float>(region.srcOffsets[0].y),
static_cast<float>(region.srcOffsets[1].x), static_cast<float>(region.srcOffsets[1].y),
region.srcOffsets[0].z);
sw::SliceRect dRect(region.dstOffsets[0].x, region.dstOffsets[0].y,
region.dstOffsets[1].x, region.dstOffsets[1].y, region.dstOffsets[0].z);
for(int i = 0; i < numSlices; i++)
{
device->getBlitter()->blit(srcSurface, sRect, dstSurface, dRect,
{filter != VK_FILTER_NEAREST, srcAspect == VK_IMAGE_ASPECT_STENCIL_BIT, false});
sRect.slice++;
dRect.slice++;
}
delete srcSurface;
delete dstSurface;
device->getBlitter()->blit(this, Cast(dstImage), region, filter);
}
VkFormat Image::getClearFormat() const
......@@ -532,28 +491,7 @@ uint32_t Image::getLastMipLevel(const VkImageSubresourceRange& subresourceRange)
mipLevels : (subresourceRange.baseMipLevel + subresourceRange.levelCount)) - 1;
}
void Image::clear(void* pixelData, VkFormat format, const VkImageSubresourceRange& subresourceRange, VkImageAspectFlagBits aspect)
{
uint32_t firstLayer = subresourceRange.baseArrayLayer;
uint32_t lastLayer = getLastLayerIndex(subresourceRange);
for(uint32_t layer = firstLayer; layer <= lastLayer; ++layer)
{
uint32_t lastLevel = getLastMipLevel(subresourceRange);
for(uint32_t mipLevel = subresourceRange.baseMipLevel; mipLevel <= lastLevel; ++mipLevel)
{
VkExtent3D mipLevelExtent = getMipLevelExtent(mipLevel);
for(uint32_t s = 0; s < mipLevelExtent.depth; ++s)
{
const sw::SliceRect dRect(0, 0, mipLevelExtent.width, mipLevelExtent.height, s);
sw::Surface* surface = asSurface(aspect, mipLevel, layer);
device->getBlitter()->clear(pixelData, format, surface, dRect, 0xF);
delete surface;
}
}
}
}
void Image::clear(void* pixelData, VkFormat format, const VkRect2D& renderArea, const VkImageSubresourceRange& subresourceRange, VkImageAspectFlagBits aspect)
void Image::clear(void* pixelData, VkFormat format, const VkImageSubresourceRange& subresourceRange, const VkRect2D& renderArea)
{
if((subresourceRange.baseMipLevel != 0) ||
(subresourceRange.levelCount != 1))
......@@ -561,22 +499,7 @@ void Image::clear(void* pixelData, VkFormat format, const VkRect2D& renderArea,
UNIMPLEMENTED();
}
sw::SliceRect dRect(renderArea.offset.x, renderArea.offset.y,
renderArea.offset.x + renderArea.extent.width,
renderArea.offset.y + renderArea.extent.height, 0);
uint32_t firstLayer = subresourceRange.baseArrayLayer;
uint32_t lastLayer = getLastLayerIndex(subresourceRange);
for(uint32_t layer = firstLayer; layer <= lastLayer; ++layer)
{
for(uint32_t s = 0; s < extent.depth; ++s)
{
dRect.slice = s;
sw::Surface* surface = asSurface(aspect, 0, layer);
device->getBlitter()->clear(pixelData, format, surface, dRect, 0xF);
delete surface;
}
}
device->getBlitter()->clear(pixelData, format, this, subresourceRange, &renderArea);
}
void Image::clear(const VkClearColorValue& color, const VkImageSubresourceRange& subresourceRange)
......@@ -586,7 +509,7 @@ void Image::clear(const VkClearColorValue& color, const VkImageSubresourceRange&
UNIMPLEMENTED();
}
clear((void*)color.float32, getClearFormat(), subresourceRange, VK_IMAGE_ASPECT_COLOR_BIT);
device->getBlitter()->clear((void*)color.float32, getClearFormat(), this, subresourceRange);
}
void Image::clear(const VkClearDepthStencilValue& color, const VkImageSubresourceRange& subresourceRange)
......@@ -599,12 +522,16 @@ void Image::clear(const VkClearDepthStencilValue& color, const VkImageSubresourc
if(subresourceRange.aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT)
{
clear((void*)(&color.depth), VK_FORMAT_D32_SFLOAT, subresourceRange, VK_IMAGE_ASPECT_DEPTH_BIT);
VkImageSubresourceRange depthSubresourceRange = subresourceRange;
depthSubresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
device->getBlitter()->clear((void*)(&color.depth), VK_FORMAT_D32_SFLOAT, this, depthSubresourceRange);
}
if(subresourceRange.aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT)
{
clear((void*)(&color.stencil), VK_FORMAT_S8_UINT, subresourceRange, 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);
}
}
......@@ -621,18 +548,22 @@ void Image::clear(const VkClearValue& clearValue, const VkRect2D& renderArea, co
if(subresourceRange.aspectMask == VK_IMAGE_ASPECT_COLOR_BIT)
{
clear((void*)(clearValue.color.float32), getClearFormat(), renderArea, subresourceRange, VK_IMAGE_ASPECT_COLOR_BIT);
clear((void*)(clearValue.color.float32), getClearFormat(), subresourceRange, renderArea);
}
else
{
if(subresourceRange.aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT)
{
clear((void*)(&clearValue.depthStencil.depth), VK_FORMAT_D32_SFLOAT, renderArea, subresourceRange, VK_IMAGE_ASPECT_DEPTH_BIT);
VkImageSubresourceRange depthSubresourceRange = subresourceRange;
depthSubresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
clear((void*)(&clearValue.depthStencil.depth), VK_FORMAT_D32_SFLOAT, depthSubresourceRange, renderArea);
}
if(subresourceRange.aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT)
{
clear((void*)(&clearValue.depthStencil.stencil), VK_FORMAT_S8_UINT, renderArea, subresourceRange, 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);
}
}
}
......
......@@ -17,11 +17,6 @@
#include "VkObject.hpp"
namespace sw
{
class Surface;
};
namespace vk
{
......@@ -57,15 +52,19 @@ public:
VkImageType getImageType() const { return imageType; }
VkFormat getFormat() const { return format; }
VkFormat getFormat(VkImageAspectFlagBits aspect) const;
uint32_t getArrayLayers() const { return arrayLayers; }
uint32_t getMipLevels() const { return mipLevels; }
uint32_t getLastLayerIndex(const VkImageSubresourceRange& subresourceRange) const;
uint32_t getLastMipLevel(const VkImageSubresourceRange& subresourceRange) const;
VkSampleCountFlagBits getSampleCountFlagBits() const { return samples; }
VkExtent3D getMipLevelExtent(uint32_t mipLevel) const;
int rowPitchBytes(VkImageAspectFlagBits aspect, uint32_t mipLevel) const;
int slicePitchBytes(VkImageAspectFlagBits aspect, uint32_t mipLevel) const;
void* getTexelPointer(const VkOffset3D& offset, const VkImageSubresourceLayers& subresource) const;
bool isCube() const;
private:
sw::Surface* asSurface(VkImageAspectFlagBits aspect, uint32_t mipLevel, uint32_t layer) const;
void copy(VkBuffer buffer, const VkBufferImageCopy& region, bool bufferIsSource);
VkDeviceSize getStorageSize(VkImageAspectFlags flags) const;
VkDeviceSize getMipLevelSize(VkImageAspectFlagBits aspect, uint32_t mipLevel) const;
......@@ -75,13 +74,8 @@ private:
VkDeviceSize texelOffsetBytesInStorage(const VkOffset3D& offset, const VkImageSubresourceLayers& subresource) const;
VkDeviceSize getMemoryOffset(VkImageAspectFlagBits aspect) const;
int bytesPerTexel(VkImageAspectFlagBits flags) const;
VkExtent3D getMipLevelExtent(uint32_t mipLevel) const;
VkFormat getFormat(VkImageAspectFlagBits flags) const;
uint32_t getLastLayerIndex(const VkImageSubresourceRange& subresourceRange) const;
uint32_t getLastMipLevel(const VkImageSubresourceRange& subresourceRange) const;
VkFormat getClearFormat() const;
void clear(void* pixelData, VkFormat format, const VkImageSubresourceRange& subresourceRange, VkImageAspectFlagBits aspect);
void clear(void* pixelData, VkFormat format, const VkRect2D& renderArea, const VkImageSubresourceRange& subresourceRange, VkImageAspectFlagBits aspect);
void clear(void* pixelData, VkFormat format, const VkImageSubresourceRange& subresourceRange, const VkRect2D& renderArea);
const Device *const device = nullptr;
DeviceMemory* deviceMemory = nullptr;
......
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