Commit 8da52534 by Nicolas Capens Committed by Nicolas Capens

Don't process unused texture coordinates

Bug: b/129523279 Change-Id: I894b11a58fcde956312ad92f934aaa0c60a0f837 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/30808Tested-by: 's avatarNicolas Capens <nicolascapens@google.com> Presubmit-Ready: Nicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
parent 0559bc47
...@@ -100,6 +100,7 @@ namespace sw ...@@ -100,6 +100,7 @@ namespace sw
enum AddressingMode ENUM_UNDERLYING_TYPE_UNSIGNED_INT enum AddressingMode ENUM_UNDERLYING_TYPE_UNSIGNED_INT
{ {
ADDRESSING_UNUSED,
ADDRESSING_WRAP, ADDRESSING_WRAP,
ADDRESSING_CLAMP, ADDRESSING_CLAMP,
ADDRESSING_MIRROR, ADDRESSING_MIRROR,
......
...@@ -1936,7 +1936,11 @@ namespace sw ...@@ -1936,7 +1936,11 @@ namespace sw
Short4 SamplerCore::address(Float4 &uw, AddressingMode addressingMode, Pointer<Byte> &mipmap) Short4 SamplerCore::address(Float4 &uw, AddressingMode addressingMode, Pointer<Byte> &mipmap)
{ {
if(addressingMode == ADDRESSING_LAYER) if(addressingMode == ADDRESSING_UNUSED)
{
return Short4();
}
else if(addressingMode == ADDRESSING_LAYER)
{ {
return Min(Max(Short4(RoundInt(uw)), Short4(0)), *Pointer<Short4>(mipmap + OFFSET(Mipmap, depth)) - Short4(1)); return Min(Max(Short4(RoundInt(uw)), Short4(0)), *Pointer<Short4>(mipmap + OFFSET(Mipmap, depth)) - Short4(1));
} }
...@@ -1974,6 +1978,11 @@ namespace sw ...@@ -1974,6 +1978,11 @@ namespace sw
void SamplerCore::address(Float4 &uvw, Int4 &xyz0, Int4 &xyz1, Float4 &f, Pointer<Byte> &mipmap, Float4 &texOffset, Int4 &filter, int whd, AddressingMode addressingMode, SamplerFunction function) void SamplerCore::address(Float4 &uvw, Int4 &xyz0, Int4 &xyz1, Float4 &f, Pointer<Byte> &mipmap, Float4 &texOffset, Int4 &filter, int whd, AddressingMode addressingMode, SamplerFunction function)
{ {
if(addressingMode == ADDRESSING_UNUSED)
{
return;
}
Int4 dim = Int4(*Pointer<Short4>(mipmap + whd, 16)); Int4 dim = Int4(*Pointer<Short4>(mipmap + whd, 16));
Int4 maxXYZ = dim - Int4(1); Int4 maxXYZ = dim - Int4(1);
......
...@@ -93,8 +93,8 @@ SpirvShader::ImageSampler *SpirvShader::emitSamplerFunction(ImageInstruction ins ...@@ -93,8 +93,8 @@ SpirvShader::ImageSampler *SpirvShader::emitSamplerFunction(ImageInstruction ins
SamplerCore s(constants, samplerState); SamplerCore s(constants, samplerState);
SIMD::Float uvw[3]; SIMD::Float uvw[3];
SIMD::Float q(0); // TODO(b/129523279) SIMD::Float q;
SIMD::Float lodOrBias(0); // Explicit level-of-detail, or bias added to the implicit level-of-detail (depending on samplerMethod). SIMD::Float lodOrBias; // Explicit level-of-detail, or bias added to the implicit level-of-detail (depending on samplerMethod).
Vector4f dsx; Vector4f dsx;
Vector4f dsy; Vector4f dsy;
Vector4f offset; Vector4f offset;
...@@ -225,64 +225,71 @@ sw::AddressingMode SpirvShader::convertAddressingMode(int coordinateIndex, VkSam ...@@ -225,64 +225,71 @@ sw::AddressingMode SpirvShader::convertAddressingMode(int coordinateIndex, VkSam
{ {
switch(imageViewType) switch(imageViewType)
{ {
case VK_IMAGE_VIEW_TYPE_CUBE:
break;
case VK_IMAGE_VIEW_TYPE_CUBE_ARRAY: case VK_IMAGE_VIEW_TYPE_CUBE_ARRAY:
UNSUPPORTED("SPIR-V ImageCubeArray Capability (imageViewType: %d)", int(imageViewType)); UNSUPPORTED("SPIR-V ImageCubeArray Capability (imageViewType: %d)", int(imageViewType));
if(coordinateIndex == 3) if(coordinateIndex == 3)
{ {
return ADDRESSING_LAYER; return ADDRESSING_LAYER;
} }
break; // Fall through to CUBE case:
case VK_IMAGE_VIEW_TYPE_1D: case VK_IMAGE_VIEW_TYPE_CUBE:
if(coordinateIndex >= 1) if(coordinateIndex >= 2)
{ {
return ADDRESSING_WRAP; // Unused, but must avoid BORDER mode. // Cube faces are addressed as 2D images.
return ADDRESSING_UNUSED;
}
else
{
// Vulkan 1.1 spec:
// "Cube images ignore the wrap modes specified in the sampler. Instead, if VK_FILTER_NEAREST is used within a mip level then
// VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE is used, and if VK_FILTER_LINEAR is used within a mip level then sampling at the edges
// is performed as described earlier in the Cube map edge handling section."
// This corresponds with our 'SEAMLESS' addressing mode.
return ADDRESSING_SEAMLESS;
} }
break; break;
case VK_IMAGE_VIEW_TYPE_2D:
if(coordinateIndex == 2) case VK_IMAGE_VIEW_TYPE_1D: // Treated as 2D texture with second coordinate 0.
if(coordinateIndex == 1)
{
return ADDRESSING_WRAP;
}
else if(coordinateIndex >= 2)
{ {
return ADDRESSING_WRAP; // Unused, but must avoid BORDER mode. return ADDRESSING_UNUSED;
} }
break; break;
case VK_IMAGE_VIEW_TYPE_3D: case VK_IMAGE_VIEW_TYPE_3D:
if(coordinateIndex >= 3)
{
return ADDRESSING_UNUSED;
}
break; break;
case VK_IMAGE_VIEW_TYPE_1D_ARRAY: // Treated as 2D texture with second coordinate 0. case VK_IMAGE_VIEW_TYPE_1D_ARRAY: // Treated as 2D texture with second coordinate 0.
if(coordinateIndex == 1) if(coordinateIndex == 1)
{ {
return ADDRESSING_WRAP; // Unused, but must avoid BORDER mode. return ADDRESSING_WRAP;
} }
// Fall through to 2D array case // Fall through to 2D_ARRAY case:
case VK_IMAGE_VIEW_TYPE_2D_ARRAY: case VK_IMAGE_VIEW_TYPE_2D_ARRAY:
if(coordinateIndex == 2) if(coordinateIndex == 2)
{ {
return ADDRESSING_LAYER; return ADDRESSING_LAYER;
} }
break; else if(coordinateIndex >= 3)
default: {
UNIMPLEMENTED("imageViewType %d", imageViewType); return ADDRESSING_UNUSED;
return ADDRESSING_WRAP; }
} // Fall through to 2D case:
// Vulkan 1.1 spec:
// "Cube images ignore the wrap modes specified in the sampler. Instead, if VK_FILTER_NEAREST is used within a mip level then
// VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE is used, and if VK_FILTER_LINEAR is used within a mip level then sampling at the edges
// is performed as described earlier in the Cube map edge handling section."
// This corresponds with our 'seamless' addressing mode.
switch(imageViewType)
{
case VK_IMAGE_VIEW_TYPE_CUBE:
return ADDRESSING_SEAMLESS;
// case VK_IMAGE_VIEW_TYPE_CUBE_ARRAY:
UNSUPPORTED("SPIR-V ImageCubeArray Capability (imageViewType: %d)", int(imageViewType));
return ADDRESSING_SEAMLESS;
case VK_IMAGE_VIEW_TYPE_1D:
case VK_IMAGE_VIEW_TYPE_2D: case VK_IMAGE_VIEW_TYPE_2D:
case VK_IMAGE_VIEW_TYPE_3D: if(coordinateIndex >= 2)
case VK_IMAGE_VIEW_TYPE_1D_ARRAY: {
case VK_IMAGE_VIEW_TYPE_2D_ARRAY: return ADDRESSING_UNUSED;
}
break; break;
default: default:
UNIMPLEMENTED("imageViewType %d", imageViewType); UNIMPLEMENTED("imageViewType %d", imageViewType);
return ADDRESSING_WRAP; return ADDRESSING_WRAP;
......
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