Commit 696926d4 by Alexis Hetu Committed by Alexis Hétu

sw::Surface references removed from sampling code

vk::Format was expanded to include more format related checks and the sampler object now uses them. Whether or not the Sampler code ends up actually being used is unsure, but the code has been updated to use vk::Image instead of sw::Surface. This should be the last sw::Surface reference in Vulkan code. Bug b/126883332 Change-Id: Ib1b4c3ce87d0fdad5ac7238b7e86211a499871a5 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/27490Tested-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 avatarNicolas Capens <nicolascapens@google.com>
parent 9041bb7c
......@@ -71,8 +71,8 @@ namespace sw
return memcmp(this, &state, sizeof(State)) == 0;
}
vk::Format sourceFormat = VK_FORMAT_UNDEFINED;
vk::Format destFormat = VK_FORMAT_UNDEFINED;
vk::Format sourceFormat;
vk::Format destFormat;
int destSamples = 0;
};
......
......@@ -15,9 +15,9 @@
#include "Sampler.hpp"
#include "Context.hpp"
#include "Surface.hpp"
#include "Pipeline/PixelRoutine.hpp"
#include "Vulkan/VkDebug.hpp"
#include "Vulkan/VkImage.hpp"
#include <cstring>
......@@ -48,8 +48,7 @@ namespace sw
}
}
externalTextureFormat = VK_FORMAT_UNDEFINED;
internalTextureFormat = VK_FORMAT_UNDEFINED;
textureFormat = VK_FORMAT_UNDEFINED;
textureType = TEXTURE_NULL;
textureFilter = FILTER_LINEAR;
......@@ -89,13 +88,13 @@ namespace sw
if(textureType != TEXTURE_NULL)
{
state.textureType = textureType;
state.textureFormat = internalTextureFormat;
state.textureFormat = textureFormat;
state.textureFilter = getTextureFilter();
state.addressingModeU = getAddressingModeU();
state.addressingModeV = getAddressingModeV();
state.addressingModeW = getAddressingModeW();
state.mipmapFilter = mipmapFilter();
state.sRGB = (sRGB && Surface::isSRGBreadable(externalTextureFormat)) || Surface::isSRGBformat(internalTextureFormat);
state.sRGB = (sRGB && textureFormat.isSRGBreadable()) || textureFormat.isSRGBformat();
state.swizzleR = swizzleR;
state.swizzleG = swizzleG;
state.swizzleB = swizzleB;
......@@ -111,25 +110,33 @@ namespace sw
return state;
}
void Sampler::setTextureLevel(int face, int level, Surface *surface, TextureType type)
void Sampler::setTextureLevel(int face, int level, vk::Image *image, TextureType type)
{
if(surface)
if(image)
{
Mipmap &mipmap = texture.mipmap[level];
border = surface->getBorder();
mipmap.buffer[face] = surface->lockInternal(-border, -border, 0, LOCK_UNLOCKED, PRIVATE);
border = image->isCube() ? 1 : 0;
VkImageSubresourceLayers subresourceLayers =
{
VK_IMAGE_ASPECT_COLOR_BIT,
static_cast<uint32_t>(level),
static_cast<uint32_t>(face),
1
};
mipmap.buffer[face] = image->getTexelPointer({ -border, -border, 0 }, subresourceLayers);
if(face == 0)
{
externalTextureFormat = surface->getExternalFormat();
internalTextureFormat = surface->getInternalFormat();
VkImageAspectFlagBits aspect = VK_IMAGE_ASPECT_COLOR_BIT; // FIXME: get proper aspect
textureFormat = image->getFormat(aspect);
int width = surface->getWidth();
int height = surface->getHeight();
int depth = surface->getDepth();
int pitchP = surface->getInternalPitchP();
int sliceP = surface->getInternalSliceP();
VkExtent3D mipLevelExtent = image->getMipLevelExtent(level);
int width = mipLevelExtent.width;
int height = mipLevelExtent.height;
int depth = mipLevelExtent.depth;
int pitchP = image->rowPitchBytes(aspect, level);
int sliceP = image->slicePitchBytes(aspect, level);
if(level == 0)
{
......@@ -154,7 +161,7 @@ namespace sw
texture.depthLOD[3] = depth * exp2LOD;
}
if(Surface::isFloatFormat(internalTextureFormat))
if(textureFormat.isFloatFormat())
{
mipmap.fWidth[0] = (float)width / 65536.0f;
mipmap.fWidth[1] = (float)width / 65536.0f;
......@@ -221,7 +228,7 @@ namespace sw
mipmap.sliceP[2] = sliceP;
mipmap.sliceP[3] = sliceP;
if(internalTextureFormat == VK_FORMAT_G8_B8R8_2PLANE_420_UNORM)
if(textureFormat.hasYuvFormat())
{
unsigned int YStride = pitchP;
unsigned int YSize = YStride * height;
......@@ -382,10 +389,10 @@ namespace sw
bool Sampler::hasUnsignedTexture() const
{
return Surface::isUnsignedComponent(internalTextureFormat, 0) &&
Surface::isUnsignedComponent(internalTextureFormat, 1) &&
Surface::isUnsignedComponent(internalTextureFormat, 2) &&
Surface::isUnsignedComponent(internalTextureFormat, 3);
return textureFormat.isUnsignedComponent(0) &&
textureFormat.isUnsignedComponent(1) &&
textureFormat.isUnsignedComponent(2) &&
textureFormat.isUnsignedComponent(3);
}
bool Sampler::hasCubeTexture() const
......@@ -438,7 +445,7 @@ namespace sw
FilterType filter = textureFilter;
if(gather && Surface::componentCount(internalTextureFormat) == 1)
if(gather && textureFormat.componentCount() == 1)
{
filter = FILTER_GATHER;
}
......
......@@ -15,9 +15,15 @@
#ifndef sw_Sampler_hpp
#define sw_Sampler_hpp
#include "Device/Color.hpp"
#include "Device/Config.hpp"
#include "Device/Surface.hpp"
#include "System/Types.hpp"
#include "Vulkan/VkFormat.h"
namespace vk
{
class Image;
}
namespace sw
{
......@@ -147,7 +153,7 @@ namespace sw
State();
TextureType textureType;
VkFormat textureFormat;
vk::Format textureFormat;
FilterType textureFilter;
AddressingMode addressingModeU;
AddressingMode addressingModeV;
......@@ -172,7 +178,7 @@ namespace sw
State samplerState() const;
void setTextureLevel(int face, int level, Surface *surface, TextureType type);
void setTextureLevel(int face, int level, vk::Image *image, TextureType type);
void setTextureFilter(FilterType textureFilter);
void setMipmapFilter(MipmapType mipmapFilter);
......@@ -214,8 +220,7 @@ namespace sw
AddressingMode getAddressingModeW() const;
CompareFunc getCompareFunc() const;
VkFormat externalTextureFormat;
VkFormat internalTextureFormat;
vk::Format textureFormat;
TextureType textureType;
FilterType textureFilter;
......
......@@ -2057,7 +2057,7 @@ namespace sw
Vector4s cs = sampleTexel(index, buffer);
bool isInteger = Surface::isNonNormalizedInteger(state.textureFormat);
bool isInteger = state.textureFormat.isNonNormalizedInteger();
int componentCount = textureComponentCount();
for(int n = 0; n < componentCount; n++)
{
......@@ -2426,22 +2426,22 @@ namespace sw
bool SamplerCore::hasFloatTexture() const
{
return Surface::isFloatFormat(state.textureFormat);
return state.textureFormat.isFloatFormat();
}
bool SamplerCore::hasUnnormalizedIntegerTexture() const
{
return Surface::isNonNormalizedInteger(state.textureFormat);
return state.textureFormat.isNonNormalizedInteger();
}
bool SamplerCore::hasUnsignedTextureComponent(int component) const
{
return Surface::isUnsignedComponent(state.textureFormat, component);
return state.textureFormat.isUnsignedComponent(component);
}
int SamplerCore::textureComponentCount() const
{
return Surface::componentCount(state.textureFormat);
return state.textureFormat.componentCount();
}
bool SamplerCore::hasThirdCoordinate() const
......@@ -2451,275 +2451,31 @@ namespace sw
bool SamplerCore::has16bitTextureFormat() const
{
switch(state.textureFormat)
{
case VK_FORMAT_R5G6B5_UNORM_PACK16:
return true;
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_B8G8R8A8_UNORM:
case VK_FORMAT_R8G8B8A8_UNORM:
case VK_FORMAT_R8G8B8A8_SRGB:
case VK_FORMAT_R32_SFLOAT:
case VK_FORMAT_R32G32_SFLOAT:
case VK_FORMAT_R32G32B32A32_SFLOAT:
case VK_FORMAT_R8_UNORM:
case VK_FORMAT_R16G16_UNORM:
case VK_FORMAT_R16G16B16A16_UNORM:
case VK_FORMAT_R16_SINT:
case VK_FORMAT_R16_UINT:
case VK_FORMAT_R16G16_SINT:
case VK_FORMAT_R16G16_UINT:
case VK_FORMAT_R16G16B16A16_SINT:
case VK_FORMAT_R16G16B16A16_UINT:
case VK_FORMAT_G8_B8R8_2PLANE_420_UNORM:
return false;
default:
ASSERT(false);
}
return false;
return state.textureFormat.has16bitTextureFormat();
}
bool SamplerCore::has8bitTextureComponents() const
{
switch(state.textureFormat)
{
case VK_FORMAT_R8G8_UNORM:
case VK_FORMAT_B8G8R8A8_UNORM:
case VK_FORMAT_R8G8B8A8_UNORM:
case VK_FORMAT_R8G8B8A8_SRGB:
case VK_FORMAT_R8_UNORM:
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:
return true;
case VK_FORMAT_R5G6B5_UNORM_PACK16:
case VK_FORMAT_R32_SFLOAT:
case VK_FORMAT_R32G32_SFLOAT:
case VK_FORMAT_R32G32B32A32_SFLOAT:
case VK_FORMAT_R16G16_UNORM:
case VK_FORMAT_R16G16B16A16_UNORM:
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_R16_SINT:
case VK_FORMAT_R16_UINT:
case VK_FORMAT_R16G16_SINT:
case VK_FORMAT_R16G16_UINT:
case VK_FORMAT_R16G16B16A16_SINT:
case VK_FORMAT_R16G16B16A16_UINT:
case VK_FORMAT_G8_B8R8_2PLANE_420_UNORM:
return false;
default:
ASSERT(false);
}
return false;
return state.textureFormat.has8bitTextureComponents();
}
bool SamplerCore::has16bitTextureComponents() const
{
switch(state.textureFormat)
{
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_B8G8R8A8_UNORM:
case VK_FORMAT_R8G8B8A8_UNORM:
case VK_FORMAT_R8G8B8A8_SRGB:
case VK_FORMAT_R32_SFLOAT:
case VK_FORMAT_R32G32_SFLOAT:
case VK_FORMAT_R32G32B32A32_SFLOAT:
case VK_FORMAT_R8_UNORM:
case VK_FORMAT_G8_B8R8_2PLANE_420_UNORM:
return false;
case VK_FORMAT_R16G16_UNORM:
case VK_FORMAT_R16G16B16A16_UNORM:
case VK_FORMAT_R16_SINT:
case VK_FORMAT_R16_UINT:
case VK_FORMAT_R16G16_SINT:
case VK_FORMAT_R16G16_UINT:
case VK_FORMAT_R16G16B16A16_SINT:
case VK_FORMAT_R16G16B16A16_UINT:
return true;
default:
ASSERT(false);
}
return false;
return state.textureFormat.has16bitTextureComponents();
}
bool SamplerCore::has32bitIntegerTextureComponents() const
{
switch(state.textureFormat)
{
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_R8G8_UNORM:
case VK_FORMAT_B8G8R8A8_UNORM:
case VK_FORMAT_R8G8B8A8_UNORM:
case VK_FORMAT_R8G8B8A8_SRGB:
case VK_FORMAT_R16G16_UNORM:
case VK_FORMAT_R16G16B16A16_UNORM:
case VK_FORMAT_R16_SINT:
case VK_FORMAT_R16_UINT:
case VK_FORMAT_R16G16_SINT:
case VK_FORMAT_R16G16_UINT:
case VK_FORMAT_R16G16B16A16_SINT:
case VK_FORMAT_R16G16B16A16_UINT:
case VK_FORMAT_R32_SFLOAT:
case VK_FORMAT_R32G32_SFLOAT:
case VK_FORMAT_R32G32B32A32_SFLOAT:
case VK_FORMAT_R8_UNORM:
case VK_FORMAT_G8_B8R8_2PLANE_420_UNORM:
return false;
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:
return true;
default:
ASSERT(false);
}
return false;
return state.textureFormat.has32bitIntegerTextureComponents();
}
bool SamplerCore::hasYuvFormat() const
{
switch(state.textureFormat)
{
case VK_FORMAT_G8_B8R8_2PLANE_420_UNORM:
return true;
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_B8G8R8A8_UNORM:
case VK_FORMAT_R8G8B8A8_UNORM:
case VK_FORMAT_R8G8B8A8_SRGB:
case VK_FORMAT_R32_SFLOAT:
case VK_FORMAT_R32G32_SFLOAT:
case VK_FORMAT_R32G32B32A32_SFLOAT:
case VK_FORMAT_R8_UNORM:
case VK_FORMAT_R16G16_UNORM:
case VK_FORMAT_R16G16B16A16_UNORM:
case VK_FORMAT_R16_SINT:
case VK_FORMAT_R16_UINT:
case VK_FORMAT_R16G16_SINT:
case VK_FORMAT_R16G16_UINT:
case VK_FORMAT_R16G16B16A16_SINT:
case VK_FORMAT_R16G16B16A16_UINT:
return false;
default:
ASSERT(false);
}
return false;
return state.textureFormat.hasYuvFormat();
}
bool SamplerCore::isRGBComponent(int component) const
{
switch(state.textureFormat)
{
case VK_FORMAT_R5G6B5_UNORM_PACK16: return component < 3;
case VK_FORMAT_R8_SNORM: return component < 1;
case VK_FORMAT_R8G8_SNORM: return component < 2;
case VK_FORMAT_R8G8B8A8_SNORM: return component < 3;
case VK_FORMAT_R8_SINT: return component < 1;
case VK_FORMAT_R8_UINT: return component < 1;
case VK_FORMAT_R8G8_SINT: return component < 2;
case VK_FORMAT_R8G8_UINT: return component < 2;
case VK_FORMAT_R8G8B8A8_SINT: return component < 3;
case VK_FORMAT_R8G8B8A8_UINT: return component < 3;
case VK_FORMAT_R32_SINT: return component < 1;
case VK_FORMAT_R32_UINT: return component < 1;
case VK_FORMAT_R32G32_SINT: return component < 2;
case VK_FORMAT_R32G32_UINT: return component < 2;
case VK_FORMAT_R32G32B32A32_SINT: return component < 3;
case VK_FORMAT_R32G32B32A32_UINT: return component < 3;
case VK_FORMAT_R8G8_UNORM: return component < 2;
case VK_FORMAT_B8G8R8A8_UNORM: return component < 3;
case VK_FORMAT_R8G8B8A8_UNORM: return component < 3;
case VK_FORMAT_R8G8B8A8_SRGB: return component < 3;
case VK_FORMAT_R32_SFLOAT: return component < 1;
case VK_FORMAT_R32G32_SFLOAT: return component < 2;
case VK_FORMAT_R32G32B32A32_SFLOAT: return component < 3;
case VK_FORMAT_R8_UNORM: return component < 1;
case VK_FORMAT_R16G16_UNORM: return component < 2;
case VK_FORMAT_R16G16B16A16_UNORM: return component < 3;
case VK_FORMAT_R16_SINT: return component < 1;
case VK_FORMAT_R16_UINT: return component < 1;
case VK_FORMAT_R16G16_SINT: return component < 2;
case VK_FORMAT_R16G16_UINT: return component < 2;
case VK_FORMAT_R16G16B16A16_SINT: return component < 3;
case VK_FORMAT_R16G16B16A16_UINT: return component < 3;
case VK_FORMAT_G8_B8R8_2PLANE_420_UNORM: return component < 3;
default:
ASSERT(false);
}
return false;
return state.textureFormat.isRGBComponent(component);
}
}
......@@ -28,6 +28,7 @@ namespace vk
class Format
{
public:
Format() {}
Format(VkFormat format) : format(format) {}
inline operator VkFormat() const { return format; }
......@@ -40,8 +41,11 @@ public:
bool hasQuadLayout() const;
bool isSRGBformat() const;
bool isSRGBreadable() const;
bool isSRGBwritable() const;
bool isFloatFormat() const;
int componentCount() const;
bool isUnsignedComponent(int component) const;
int bytes() const;
......@@ -49,8 +53,17 @@ public:
int sliceB(int width, int height, int border, bool target) const;
bool getScale(sw::float4 &scale) const;
// Texture sampling utilities
bool has16bitTextureFormat() const;
bool has8bitTextureComponents() const;
bool has16bitTextureComponents() const;
bool has32bitIntegerTextureComponents() const;
bool hasYuvFormat() const;
bool isRGBComponent(int component) const;
private:
VkFormat format;
VkFormat format = VK_FORMAT_UNDEFINED;
};
} // namespace vk
......
......@@ -84,7 +84,7 @@ private:
VkDeviceSize memoryOffset = 0;
VkImageCreateFlags flags = 0;
VkImageType imageType = VK_IMAGE_TYPE_2D;
Format format = VK_FORMAT_UNDEFINED;
Format format;
VkExtent3D extent = {0, 0, 0};
uint32_t mipLevels = 0;
uint32_t arrayLayers = 0;
......
......@@ -49,7 +49,7 @@ private:
Image* image = nullptr;
VkImageViewType viewType = VK_IMAGE_VIEW_TYPE_2D;
Format format = VK_FORMAT_UNDEFINED;
Format format;
VkComponentMapping components = {};
VkImageSubresourceRange subresourceRange = {};
};
......
......@@ -293,7 +293,7 @@ GraphicsPipeline::GraphicsPipeline(const VkGraphicsPipelineCreateInfo* pCreateIn
sw::Stream& input = context.input[desc.location];
input.count = getNumberOfChannels(desc.format);
input.type = getStreamType(desc.format);
input.normalized = !sw::Surface::isNonNormalizedInteger(desc.format);
input.normalized = !vk::Format(desc.format).isNonNormalizedInteger();
input.offset = desc.offset;
input.binding = desc.binding;
input.stride = bufferStrides[desc.binding];
......
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