Commit cfe11c70 by Nicolas Capens Committed by Nicolas Capens

Refactor obtaining format aspect info

Aspect info is part of the format, so shouldn't be queried from an Image utility function. Bug: b/132437008 Change-Id: I87d632231a810cece3d1ea579e9df63b6b80a714 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/31611 Presubmit-Ready: Nicolas Capens <nicolascapens@google.com> Tested-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
parent 57253153
......@@ -40,7 +40,7 @@ namespace sw
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);
vk::Format dstFormat = vk::Image::GetFormat(viewFormat, aspect);
vk::Format dstFormat = viewFormat.getAspectFormat(aspect);
if(dstFormat == VK_FORMAT_UNDEFINED)
{
return;
......
......@@ -147,7 +147,7 @@ namespace sw
}
}
bool force32BitFiltering = state.highPrecisionFiltering && !hasYuvFormat() && (state.textureFilter != FILTER_POINT);
bool force32BitFiltering = state.highPrecisionFiltering && !isYcbcrFormat() && (state.textureFilter != FILTER_POINT);
bool seamlessCube = (state.addressingModeU == ADDRESSING_SEAMLESS);
bool use32BitFiltering = hasFloatTexture() || hasUnnormalizedIntegerTexture() || force32BitFiltering ||
seamlessCube || state.unnormalizedCoordinates || state.compareEnable || state.largeTexture ||
......@@ -1601,7 +1601,7 @@ namespace sw
UInt index[4];
computeIndices(index, uuuu, vvvv, wwww, offset, mipmap, function);
if(hasYuvFormat())
if(isYcbcrFormat())
{
// Generic YPbPr to RGB transformation
// R = Y + 2 * (1 - Kr) * Pr
......@@ -1844,7 +1844,7 @@ namespace sw
}
else
{
ASSERT(!hasYuvFormat());
ASSERT(!isYcbcrFormat());
Vector4s cs = sampleTexel(index, buffer);
......@@ -1989,7 +1989,7 @@ namespace sw
{
buffer[0] = *Pointer<Pointer<Byte>>(mipmap + OFFSET(Mipmap,buffer[0]));
if(hasYuvFormat())
if(isYcbcrFormat())
{
buffer[1] = *Pointer<Pointer<Byte>>(mipmap + OFFSET(Mipmap,buffer[1]));
buffer[2] = *Pointer<Pointer<Byte>>(mipmap + OFFSET(Mipmap,buffer[2]));
......@@ -2356,9 +2356,9 @@ namespace sw
return state.textureFormat.has32bitIntegerTextureComponents();
}
bool SamplerCore::hasYuvFormat() const
bool SamplerCore::isYcbcrFormat() const
{
return state.textureFormat.hasYuvFormat();
return state.textureFormat.isYcbcrFormat();
}
bool SamplerCore::isRGBComponent(int component) const
......
......@@ -107,7 +107,7 @@ namespace sw
bool has8bitTextureComponents() const;
bool has16bitTextureComponents() const;
bool has32bitIntegerTextureComponents() const;
bool hasYuvFormat() const;
bool isYcbcrFormat() const;
bool isRGBComponent(int component) const;
bool borderModeActive() const;
VkComponentSwizzle gatherSwizzle() const;
......
......@@ -86,6 +86,57 @@ bool Format::isNonNormalizedInteger() const
return isSignedNonNormalizedInteger() || isUnsignedNonNormalizedInteger();
}
VkImageAspectFlags Format::getAspects() const
{
// TODO: probably just flatten this out to a full format list, and alter
// isDepth / isStencil etc to check for their aspect
VkImageAspectFlags aspects = 0;
if (isDepth()) aspects |= VK_IMAGE_ASPECT_DEPTH_BIT;
if (isStencil()) aspects |= VK_IMAGE_ASPECT_STENCIL_BIT;
// TODO: YCbCr planar formats have different aspects
// Anything else is "color".
if (!aspects) aspects |= VK_IMAGE_ASPECT_COLOR_BIT;
return aspects;
}
Format Format::getAspectFormat(VkImageAspectFlags aspect) const
{
switch(aspect)
{
case VK_IMAGE_ASPECT_DEPTH_BIT:
switch(format)
{
case VK_FORMAT_D16_UNORM_S8_UINT:
return VK_FORMAT_D16_UNORM;
case VK_FORMAT_D24_UNORM_S8_UINT:
return VK_FORMAT_X8_D24_UNORM_PACK32; // FIXME: This will allocate an extra byte per pixel
case VK_FORMAT_D32_SFLOAT_S8_UINT:
return VK_FORMAT_D32_SFLOAT;
default:
break;
}
break;
case VK_IMAGE_ASPECT_STENCIL_BIT:
switch(format)
{
case VK_FORMAT_D16_UNORM_S8_UINT:
case VK_FORMAT_D24_UNORM_S8_UINT:
case VK_FORMAT_D32_SFLOAT_S8_UINT:
return VK_FORMAT_S8_UINT;
default:
break;
}
break;
default:
break;
}
return format;
}
bool Format::isStencil() const
{
switch(format)
......@@ -306,6 +357,18 @@ bool Format::isFloatFormat() const
return false;
}
bool Format::isYcbcrFormat() const
{
switch(format)
{
case VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM:
case VK_FORMAT_G8_B8R8_2PLANE_420_UNORM:
return true;
default:
return false;
}
}
bool Format::isCompressed() const
{
switch(format)
......@@ -1983,69 +2046,6 @@ bool Format::has32bitIntegerTextureComponents() const
return false;
}
bool Format::hasYuvFormat() const
{
switch(format)
{
case VK_FORMAT_G8_B8R8_2PLANE_420_UNORM:
return true;
case VK_FORMAT_A1R5G5B5_UNORM_PACK16:
case VK_FORMAT_B4G4R4A4_UNORM_PACK16:
case VK_FORMAT_R5G6B5_UNORM_PACK16:
case VK_FORMAT_R8_SNORM:
case VK_FORMAT_R8G8_SNORM:
case VK_FORMAT_R8G8B8A8_SNORM:
case VK_FORMAT_R8_SINT:
case VK_FORMAT_R8_UINT:
case VK_FORMAT_R8G8_SINT:
case VK_FORMAT_R8G8_UINT:
case VK_FORMAT_R8G8B8A8_SINT:
case VK_FORMAT_R8G8B8A8_UINT:
case VK_FORMAT_R32_SINT:
case VK_FORMAT_R32_UINT:
case VK_FORMAT_R32G32_SINT:
case VK_FORMAT_R32G32_UINT:
case VK_FORMAT_R32G32B32A32_SINT:
case VK_FORMAT_R32G32B32A32_UINT:
case VK_FORMAT_R8G8_UNORM:
case VK_FORMAT_B8G8R8_UNORM:
case VK_FORMAT_B8G8R8A8_UNORM:
case VK_FORMAT_R8G8B8A8_UNORM:
case VK_FORMAT_B8G8R8_SRGB:
case VK_FORMAT_R8G8B8A8_SRGB:
case VK_FORMAT_B8G8R8A8_SRGB:
case VK_FORMAT_R32_SFLOAT:
case VK_FORMAT_R32G32_SFLOAT:
case VK_FORMAT_R32G32B32A32_SFLOAT:
case VK_FORMAT_R8_UNORM:
case VK_FORMAT_R16_UNORM:
case VK_FORMAT_R16_SNORM:
case VK_FORMAT_R16G16_UNORM:
case VK_FORMAT_R16G16_SNORM:
case VK_FORMAT_R16G16B16A16_UNORM:
case VK_FORMAT_R16_SINT:
case VK_FORMAT_R16_UINT:
case VK_FORMAT_R16_SFLOAT:
case VK_FORMAT_R16G16_SINT:
case VK_FORMAT_R16G16_UINT:
case VK_FORMAT_R16G16_SFLOAT:
case VK_FORMAT_R16G16B16A16_SINT:
case VK_FORMAT_R16G16B16A16_UINT:
case VK_FORMAT_R16G16B16A16_SFLOAT:
case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
case VK_FORMAT_A2B10G10R10_UINT_PACK32:
case VK_FORMAT_E5B9G9R9_UFLOAT_PACK32:
case VK_FORMAT_D32_SFLOAT:
case VK_FORMAT_D16_UNORM:
case VK_FORMAT_B10G11R11_UFLOAT_PACK32:
return false;
default:
UNIMPLEMENTED("Format: %d", int(format));
}
return false;
}
bool Format::isRGBComponent(int component) const
{
switch(format)
......
......@@ -36,13 +36,15 @@ public:
bool isUnsignedNonNormalizedInteger() const;
bool isNonNormalizedInteger() const;
VkImageAspectFlags getAspects() const;
Format getAspectFormat(VkImageAspectFlags aspect) const;
bool isStencil() const;
bool isDepth() const;
bool hasQuadLayout() const;
VkFormat getNonQuadLayoutFormat() const;
bool isSRGBformat() const;
bool isFloatFormat() const;
bool isYcbcrFormat() const;
bool isCompatible(const Format& other) const;
bool isCompressed() const;
......@@ -65,7 +67,6 @@ public:
bool has8bitTextureComponents() const;
bool has16bitTextureComponents() const;
bool has32bitIntegerTextureComponents() const;
bool hasYuvFormat() const;
bool isRGBComponent(int component) const;
private:
......
......@@ -22,22 +22,6 @@
namespace
{
VkImageAspectFlags GetAspects(vk::Format format)
{
// TODO: probably just flatten this out to a full format list, and alter
// isDepth / isStencil etc to check for their aspect
VkImageAspectFlags aspects = 0;
if (format.isDepth()) aspects |= VK_IMAGE_ASPECT_DEPTH_BIT;
if (format.isStencil()) aspects |= VK_IMAGE_ASPECT_STENCIL_BIT;
// TODO: YCbCr planar formats have different aspects
// Anything else is "color".
if (!aspects) aspects |= VK_IMAGE_ASPECT_COLOR_BIT;
return aspects;
}
ETC_Decoder::InputType GetInputType(const vk::Format& format)
{
switch(format)
......@@ -108,8 +92,8 @@ const VkMemoryRequirements Image::getMemoryRequirements() const
VkMemoryRequirements memoryRequirements;
memoryRequirements.alignment = vk::REQUIRED_MEMORY_ALIGNMENT;
memoryRequirements.memoryTypeBits = vk::MEMORY_TYPE_GENERIC_BIT;
memoryRequirements.size = getStorageSize(GetAspects(format)) +
(decompressedImage ? decompressedImage->getStorageSize(GetAspects(decompressedImage->format)) : 0);
memoryRequirements.size = getStorageSize(format.getAspects()) +
(decompressedImage ? decompressedImage->getStorageSize(decompressedImage->format.getAspects()) : 0);
return memoryRequirements;
}
......@@ -120,7 +104,7 @@ void Image::bind(VkDeviceMemory pDeviceMemory, VkDeviceSize pMemoryOffset)
if(decompressedImage)
{
decompressedImage->deviceMemory = deviceMemory;
decompressedImage->memoryOffset = memoryOffset + getStorageSize(GetAspects(format));
decompressedImage->memoryOffset = memoryOffset + getStorageSize(format.getAspects());
}
}
......@@ -569,42 +553,7 @@ 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:
switch(format)
{
case VK_FORMAT_D16_UNORM_S8_UINT:
return VK_FORMAT_D16_UNORM;
case VK_FORMAT_D24_UNORM_S8_UINT:
return VK_FORMAT_X8_D24_UNORM_PACK32; // FIXME: This will allocate an extra byte per pixel
case VK_FORMAT_D32_SFLOAT_S8_UINT:
return VK_FORMAT_D32_SFLOAT;
default:
break;
}
break;
case VK_IMAGE_ASPECT_STENCIL_BIT:
switch(format)
{
case VK_FORMAT_D16_UNORM_S8_UINT:
case VK_FORMAT_D24_UNORM_S8_UINT:
case VK_FORMAT_D32_SFLOAT_S8_UINT:
return VK_FORMAT_S8_UINT;
default:
break;
}
break;
default:
break;
}
return format;
return format.getAspectFormat(aspect);
}
bool Image::isCube() const
......
......@@ -72,8 +72,6 @@ public:
void prepareForSampling(const VkImageSubresourceRange& subresourceRange);
const Image* getSampledImage(const vk::Format& imageViewFormat) 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;
......
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