Commit 3aec8a3b by Chris Forbes

Tidy around sampler handling

Bug: b/134584057 Change-Id: I1574c9017a5d48f69d14732874a8c8b814056aec Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/34248Tested-by: 's avatarChris Forbes <chrisforbes@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent 060fcf77
...@@ -52,26 +52,6 @@ namespace sw ...@@ -52,26 +52,6 @@ namespace sw
float4 depth; float4 depth;
}; };
enum SamplerType
{
SAMPLER_PIXEL,
SAMPLER_VERTEX
};
enum TextureType ENUM_UNDERLYING_TYPE_UNSIGNED_INT
{
TEXTURE_NULL, // TODO(b/129523279): Eliminate
TEXTURE_1D,
TEXTURE_2D,
TEXTURE_3D,
TEXTURE_CUBE,
TEXTURE_1D_ARRAY, // Treated as 2D texture with second coordinate 0. TODO(b/134669567)
TEXTURE_2D_ARRAY,
TEXTURE_CUBE_ARRAY,
TEXTURE_LAST = TEXTURE_CUBE_ARRAY
};
enum FilterType ENUM_UNDERLYING_TYPE_UNSIGNED_INT enum FilterType ENUM_UNDERLYING_TYPE_UNSIGNED_INT
{ {
FILTER_POINT, FILTER_POINT,
...@@ -109,36 +89,9 @@ namespace sw ...@@ -109,36 +89,9 @@ namespace sw
ADDRESSING_LAST = ADDRESSING_TEXELFETCH ADDRESSING_LAST = ADDRESSING_TEXELFETCH
}; };
enum CompareFunc ENUM_UNDERLYING_TYPE_UNSIGNED_INT
{
COMPARE_BYPASS,
COMPARE_LESSEQUAL,
COMPARE_GREATEREQUAL,
COMPARE_LESS,
COMPARE_GREATER,
COMPARE_EQUAL,
COMPARE_NOTEQUAL,
COMPARE_ALWAYS,
COMPARE_NEVER,
COMPARE_LAST = COMPARE_NEVER
};
enum SwizzleType ENUM_UNDERLYING_TYPE_UNSIGNED_INT
{
SWIZZLE_RED,
SWIZZLE_GREEN,
SWIZZLE_BLUE,
SWIZZLE_ALPHA,
SWIZZLE_ZERO,
SWIZZLE_ONE,
SWIZZLE_LAST = SWIZZLE_ONE
};
struct Sampler struct Sampler
{ {
TextureType textureType; VkImageViewType textureType;
vk::Format textureFormat; vk::Format textureFormat;
FilterType textureFilter; FilterType textureFilter;
AddressingMode addressingModeU; AddressingMode addressingModeU;
......
...@@ -68,7 +68,7 @@ namespace sw ...@@ -68,7 +68,7 @@ namespace sw
Float4 vDelta; Float4 vDelta;
Float4 M; // Major axis Float4 M; // Major axis
if(state.textureType == TEXTURE_CUBE) if(state.textureType == VK_IMAGE_VIEW_TYPE_CUBE)
{ {
Int4 face = cubeFace(uuuu, vvvv, u, v, w, M); Int4 face = cubeFace(uuuu, vvvv, u, v, w, M);
wwww = As<Float4>(face); wwww = As<Float4>(face);
...@@ -76,9 +76,9 @@ namespace sw ...@@ -76,9 +76,9 @@ namespace sw
if(function == Implicit || function == Bias || function == Grad || function == Query) if(function == Implicit || function == Bias || function == Grad || function == Query)
{ {
if(state.textureType != TEXTURE_3D) if(state.textureType != VK_IMAGE_VIEW_TYPE_3D)
{ {
if(state.textureType != TEXTURE_CUBE) if(state.textureType != VK_IMAGE_VIEW_TYPE_CUBE)
{ {
computeLod(texture, sampler, lod, anisotropy, uDelta, vDelta, uuuu, vvvv, dsx, dsy, function); computeLod(texture, sampler, lod, anisotropy, uDelta, vDelta, uuuu, vvvv, dsx, dsy, function);
} }
...@@ -446,7 +446,7 @@ namespace sw ...@@ -446,7 +446,7 @@ namespace sw
Vector4s SamplerCore::sampleQuad(Pointer<Byte> &texture, Float4 &u, Float4 &v, Float4 &w, Vector4f &offset, Float &lod, bool secondLOD, SamplerFunction function) Vector4s SamplerCore::sampleQuad(Pointer<Byte> &texture, Float4 &u, Float4 &v, Float4 &w, Vector4f &offset, Float &lod, bool secondLOD, SamplerFunction function)
{ {
if(state.textureType != TEXTURE_3D) if(state.textureType != VK_IMAGE_VIEW_TYPE_3D)
{ {
return sampleQuad2D(texture, u, v, w, offset, lod, secondLOD, function); return sampleQuad2D(texture, u, v, w, offset, lod, secondLOD, function);
} }
...@@ -867,7 +867,7 @@ namespace sw ...@@ -867,7 +867,7 @@ namespace sw
Vector4f SamplerCore::sampleFloat(Pointer<Byte> &texture, Float4 &u, Float4 &v, Float4 &w, Float4 &q, Vector4f &offset, Float &lod, bool secondLOD, SamplerFunction function) Vector4f SamplerCore::sampleFloat(Pointer<Byte> &texture, Float4 &u, Float4 &v, Float4 &w, Float4 &q, Vector4f &offset, Float &lod, bool secondLOD, SamplerFunction function)
{ {
if(state.textureType != TEXTURE_3D) if(state.textureType != VK_IMAGE_VIEW_TYPE_3D)
{ {
return sampleFloat2D(texture, u, v, w, q, offset, lod, secondLOD, function); return sampleFloat2D(texture, u, v, w, q, offset, lod, secondLOD, function);
} }
...@@ -1288,7 +1288,7 @@ namespace sw ...@@ -1288,7 +1288,7 @@ namespace sw
if(hasThirdCoordinate()) if(hasThirdCoordinate())
{ {
if(state.textureType == TEXTURE_3D) if(state.textureType == VK_IMAGE_VIEW_TYPE_3D)
{ {
if(!texelFetch) if(!texelFetch)
{ {
...@@ -2361,9 +2361,9 @@ namespace sw ...@@ -2361,9 +2361,9 @@ namespace sw
bool SamplerCore::hasThirdCoordinate() const bool SamplerCore::hasThirdCoordinate() const
{ {
return (state.textureType == TEXTURE_3D) || return (state.textureType == VK_IMAGE_VIEW_TYPE_3D) ||
(state.textureType == TEXTURE_2D_ARRAY) || (state.textureType == VK_IMAGE_VIEW_TYPE_2D_ARRAY) ||
(state.textureType == TEXTURE_1D_ARRAY); // Treated as 2D texture with second coordinate 0. TODO(b/134669567) (state.textureType == VK_IMAGE_VIEW_TYPE_1D_ARRAY); // Treated as 2D texture with second coordinate 0. TODO(b/134669567)
} }
bool SamplerCore::has16bitTextureFormat() const bool SamplerCore::has16bitTextureFormat() const
......
...@@ -1235,7 +1235,6 @@ namespace sw ...@@ -1235,7 +1235,6 @@ namespace sw
static std::shared_ptr<rr::Routine> emitSamplerRoutine(ImageInstruction instruction, const Sampler &samplerState); static std::shared_ptr<rr::Routine> emitSamplerRoutine(ImageInstruction instruction, const Sampler &samplerState);
// TODO(b/129523279): Eliminate conversion and use vk::Sampler members directly. // TODO(b/129523279): Eliminate conversion and use vk::Sampler members directly.
static sw::TextureType convertTextureType(VkImageViewType imageViewType);
static sw::FilterType convertFilterMode(const vk::Sampler *sampler); static sw::FilterType convertFilterMode(const vk::Sampler *sampler);
static sw::MipmapType convertMipmapMode(const vk::Sampler *sampler); static sw::MipmapType convertMipmapMode(const vk::Sampler *sampler);
static sw::AddressingMode convertAddressingMode(int coordinateIndex, VkSamplerAddressMode addressMode, VkImageViewType imageViewType); static sw::AddressingMode convertAddressingMode(int coordinateIndex, VkSamplerAddressMode addressMode, VkImageViewType imageViewType);
......
...@@ -57,7 +57,7 @@ SpirvShader::ImageSampler *SpirvShader::getImageSampler(uint32_t inst, vk::Sampl ...@@ -57,7 +57,7 @@ SpirvShader::ImageSampler *SpirvShader::getImageSampler(uint32_t inst, vk::Sampl
auto type = imageDescriptor->type; auto type = imageDescriptor->type;
Sampler samplerState = {}; Sampler samplerState = {};
samplerState.textureType = convertTextureType(type); samplerState.textureType = type;
samplerState.textureFormat = imageDescriptor->format; samplerState.textureFormat = imageDescriptor->format;
samplerState.textureFilter = (instruction.samplerMethod == Gather) ? FILTER_GATHER : convertFilterMode(sampler); samplerState.textureFilter = (instruction.samplerMethod == Gather) ? FILTER_GATHER : convertFilterMode(sampler);
samplerState.border = sampler->borderColor; samplerState.border = sampler->borderColor;
...@@ -128,11 +128,11 @@ std::shared_ptr<rr::Routine> SpirvShader::emitSamplerRoutine(ImageInstruction in ...@@ -128,11 +128,11 @@ std::shared_ptr<rr::Routine> SpirvShader::emitSamplerRoutine(ImageInstruction in
// TODO(b/134669567): Currently 1D textures are treated as 2D by setting the second coordinate to 0. // TODO(b/134669567): Currently 1D textures are treated as 2D by setting the second coordinate to 0.
// Implement optimized 1D sampling. // Implement optimized 1D sampling.
if(samplerState.textureType == TEXTURE_1D) if(samplerState.textureType == VK_IMAGE_VIEW_TYPE_1D)
{ {
uvw[1] = SIMD::Float(0); uvw[1] = SIMD::Float(0);
} }
else if(samplerState.textureType == TEXTURE_1D_ARRAY) else if(samplerState.textureType == VK_IMAGE_VIEW_TYPE_1D_ARRAY)
{ {
uvw[1] = SIMD::Float(0); uvw[1] = SIMD::Float(0);
uvw[2] = in[1]; // Move 1D layer coordinate to 2D layer coordinate index. uvw[2] = in[1]; // Move 1D layer coordinate to 2D layer coordinate index.
...@@ -185,7 +185,7 @@ std::shared_ptr<rr::Routine> SpirvShader::emitSamplerRoutine(ImageInstruction in ...@@ -185,7 +185,7 @@ std::shared_ptr<rr::Routine> SpirvShader::emitSamplerRoutine(ImageInstruction in
dPdy.z = Pointer<Float>(&dsy.z)[i]; dPdy.z = Pointer<Float>(&dsy.z)[i];
// 1D textures are treated as 2D texture with second coordinate 0, so we also need to zero out the second grad component. TODO(b/134669567) // 1D textures are treated as 2D texture with second coordinate 0, so we also need to zero out the second grad component. TODO(b/134669567)
if(samplerState.textureType == TEXTURE_1D || samplerState.textureType == TEXTURE_1D_ARRAY) if(samplerState.textureType == VK_IMAGE_VIEW_TYPE_1D || samplerState.textureType == VK_IMAGE_VIEW_TYPE_1D_ARRAY)
{ {
dPdx.y = Float(0.0f); dPdx.y = Float(0.0f);
dPdy.y = Float(0.0f); dPdy.y = Float(0.0f);
...@@ -215,23 +215,6 @@ std::shared_ptr<rr::Routine> SpirvShader::emitSamplerRoutine(ImageInstruction in ...@@ -215,23 +215,6 @@ std::shared_ptr<rr::Routine> SpirvShader::emitSamplerRoutine(ImageInstruction in
return function("sampler"); return function("sampler");
} }
sw::TextureType SpirvShader::convertTextureType(VkImageViewType imageViewType)
{
switch(imageViewType)
{
case VK_IMAGE_VIEW_TYPE_1D: return TEXTURE_1D;
case VK_IMAGE_VIEW_TYPE_2D: return TEXTURE_2D;
case VK_IMAGE_VIEW_TYPE_3D: return TEXTURE_3D;
case VK_IMAGE_VIEW_TYPE_CUBE: return TEXTURE_CUBE;
case VK_IMAGE_VIEW_TYPE_1D_ARRAY: return TEXTURE_1D_ARRAY;
case VK_IMAGE_VIEW_TYPE_2D_ARRAY: return TEXTURE_2D_ARRAY;
// case VK_IMAGE_VIEW_TYPE_CUBE_ARRAY: return TEXTURE_CUBE_ARRAY;
default:
UNIMPLEMENTED("imageViewType %d", imageViewType);
return TEXTURE_2D;
}
}
sw::FilterType SpirvShader::convertFilterMode(const vk::Sampler *sampler) sw::FilterType SpirvShader::convertFilterMode(const vk::Sampler *sampler)
{ {
switch(sampler->magFilter) switch(sampler->magFilter)
......
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