Commit 6a12e092 by Nicolas Capens Committed by Nicolas Capens

Refactor image array layer addressing

Make it straightforward to support other dimensionalities. Bug: b/129523279 Change-Id: I29f7a55da26d98141ebea74678776c7d4f16c7c6 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/30152 Presubmit-Ready: Nicolas Capens <nicolascapens@google.com> Tested-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarChris Forbes <chrisforbes@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
parent 420d9da0
...@@ -908,7 +908,7 @@ namespace sw ...@@ -908,7 +908,7 @@ namespace sw
static sw::TextureType convertTextureType(VkImageViewType imageViewType); 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(VkSamplerAddressMode addressMode, VkImageViewType imageViewType); static sw::AddressingMode convertAddressingMode(int coordinateIndex, VkSamplerAddressMode addressMode, VkImageViewType imageViewType);
}; };
class SpirvRoutine class SpirvRoutine
......
...@@ -75,12 +75,9 @@ void SpirvShader::emitSamplerFunction( ...@@ -75,12 +75,9 @@ void SpirvShader::emitSamplerFunction(
samplerState.textureFilter = convertFilterMode(sampler); samplerState.textureFilter = convertFilterMode(sampler);
samplerState.border = sampler->borderColor; samplerState.border = sampler->borderColor;
samplerState.addressingModeU = convertAddressingMode(sampler->addressModeU, imageView->getType()); samplerState.addressingModeU = convertAddressingMode(0, sampler->addressModeU, imageView->getType());
samplerState.addressingModeV = convertAddressingMode(sampler->addressModeV, imageView->getType()); samplerState.addressingModeV = convertAddressingMode(1, sampler->addressModeV, imageView->getType());
samplerState.addressingModeW = convertAddressingMode(sampler->addressModeW, imageView->getType()); samplerState.addressingModeW = convertAddressingMode(2, sampler->addressModeW, imageView->getType());
if (imageView->getType() == VK_IMAGE_VIEW_TYPE_2D_ARRAY)
samplerState.addressingModeW = ADDRESSING_LAYER;
samplerState.mipmapFilter = convertMipmapMode(sampler); samplerState.mipmapFilter = convertMipmapMode(sampler);
samplerState.sRGB = imageView->getFormat().isSRGBformat(); samplerState.sRGB = imageView->getFormat().isSRGBformat();
...@@ -100,7 +97,7 @@ void SpirvShader::emitSamplerFunction( ...@@ -100,7 +97,7 @@ void SpirvShader::emitSamplerFunction(
Pointer<Byte> texture = image + OFFSET(vk::SampledImageDescriptor, texture); // sw::Texture* Pointer<Byte> texture = image + OFFSET(vk::SampledImageDescriptor, texture); // sw::Texture*
SIMD::Float uvw[3]; SIMD::Float uvw[3];
SIMD::Float q(0); // TODO(b/129523279) SIMD::Float q(0); // TODO(b/129523279)
SIMD::Float bias(0); SIMD::Float bias(0); // Bias added to the implicit level-of-detail, or explicit level-of-detail (depending on samplerMethod).
Vector4f dsx; // TODO(b/129523279) Vector4f dsx; // TODO(b/129523279)
Vector4f dsy; // TODO(b/129523279) Vector4f dsy; // TODO(b/129523279)
Vector4f offset; // TODO(b/129523279) Vector4f offset; // TODO(b/129523279)
...@@ -205,8 +202,36 @@ sw::MipmapType SpirvShader::convertMipmapMode(const vk::Sampler *sampler) ...@@ -205,8 +202,36 @@ sw::MipmapType SpirvShader::convertMipmapMode(const vk::Sampler *sampler)
} }
} }
sw::AddressingMode SpirvShader::convertAddressingMode(VkSamplerAddressMode addressMode, VkImageViewType imageViewType) sw::AddressingMode SpirvShader::convertAddressingMode(int coordinateIndex, VkSamplerAddressMode addressMode, VkImageViewType imageViewType)
{ {
switch(imageViewType)
{
case VK_IMAGE_VIEW_TYPE_CUBE:
break;
case VK_IMAGE_VIEW_TYPE_CUBE_ARRAY:
UNSUPPORTED("ImageCubeArray");
if(coordinateIndex == 3)
{
return ADDRESSING_LAYER;
}
break;
case VK_IMAGE_VIEW_TYPE_1D:
case VK_IMAGE_VIEW_TYPE_2D:
// case VK_IMAGE_VIEW_TYPE_3D:
break;
// case VK_IMAGE_VIEW_TYPE_1D_ARRAY:
break;
case VK_IMAGE_VIEW_TYPE_2D_ARRAY:
if(coordinateIndex == 2)
{
return ADDRESSING_LAYER;
}
break;
default:
UNIMPLEMENTED("imageViewType %d", imageViewType);
return ADDRESSING_WRAP;
}
// Vulkan 1.1 spec: // 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 // "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 // 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
...@@ -215,7 +240,9 @@ sw::AddressingMode SpirvShader::convertAddressingMode(VkSamplerAddressMode addre ...@@ -215,7 +240,9 @@ sw::AddressingMode SpirvShader::convertAddressingMode(VkSamplerAddressMode addre
switch(imageViewType) switch(imageViewType)
{ {
case VK_IMAGE_VIEW_TYPE_CUBE: case VK_IMAGE_VIEW_TYPE_CUBE:
case VK_IMAGE_VIEW_TYPE_CUBE_ARRAY: return ADDRESSING_SEAMLESS;
// case VK_IMAGE_VIEW_TYPE_CUBE_ARRAY:
UNSUPPORTED("ImageCubeArray");
return ADDRESSING_SEAMLESS; return ADDRESSING_SEAMLESS;
case VK_IMAGE_VIEW_TYPE_1D: case VK_IMAGE_VIEW_TYPE_1D:
case VK_IMAGE_VIEW_TYPE_2D: case VK_IMAGE_VIEW_TYPE_2D:
......
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