Commit 7f46917f by Nicolas Capens Committed by Nicolas Capens

Specialize sampling routine for immutable sampler data

Treat floating-point sampler values as state that is baked into the sampling routine, instead of reading it from memory. This offers more opportunities for optimizing the generated code. Bug: b/151957215 Change-Id: If41455dece60307a54d97463e9ad26ed052f2588 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/42588Tested-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarAntonio Maiorano <amaiorano@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
parent 4b8b0782
...@@ -112,6 +112,11 @@ struct Sampler ...@@ -112,6 +112,11 @@ struct Sampler
VkSamplerYcbcrModelConversion ycbcrModel; VkSamplerYcbcrModelConversion ycbcrModel;
bool studioSwing; // Narrow range bool studioSwing; // Narrow range
bool swappedChroma; // Cb/Cr components in reverse order bool swappedChroma; // Cb/Cr components in reverse order
float mipLodBias = 0.0f;
float maxAnisotropy = 0.0f;
float minLod = 0.0f;
float maxLod = 0.0f;
}; };
} // namespace sw } // namespace sw
......
...@@ -96,7 +96,7 @@ Vector4f SamplerCore::sampleTexture(Pointer<Byte> &texture, Pointer<Byte> &sampl ...@@ -96,7 +96,7 @@ Vector4f SamplerCore::sampleTexture(Pointer<Byte> &texture, Pointer<Byte> &sampl
computeLod3D(texture, sampler, lod, uuuu, vvvv, wwww, dsx, dsy, function); computeLod3D(texture, sampler, lod, uuuu, vvvv, wwww, dsx, dsy, function);
} }
Float bias = *Pointer<Float>(sampler + OFFSET(vk::Sampler, mipLodBias)); Float bias = state.mipLodBias;
if(function == Bias) if(function == Bias)
{ {
...@@ -110,7 +110,7 @@ Vector4f SamplerCore::sampleTexture(Pointer<Byte> &texture, Pointer<Byte> &sampl ...@@ -110,7 +110,7 @@ Vector4f SamplerCore::sampleTexture(Pointer<Byte> &texture, Pointer<Byte> &sampl
{ {
// Vulkan 1.1: "The absolute value of mipLodBias must be less than or equal to VkPhysicalDeviceLimits::maxSamplerLodBias" // Vulkan 1.1: "The absolute value of mipLodBias must be less than or equal to VkPhysicalDeviceLimits::maxSamplerLodBias"
// Hence no explicit clamping to maxSamplerLodBias is required in this case. // Hence no explicit clamping to maxSamplerLodBias is required in this case.
lod = lodOrBias + *Pointer<Float>(sampler + OFFSET(vk::Sampler, mipLodBias)); lod = lodOrBias + state.mipLodBias;
} }
else if(function == Fetch) else if(function == Fetch)
{ {
...@@ -131,8 +131,8 @@ Vector4f SamplerCore::sampleTexture(Pointer<Byte> &texture, Pointer<Byte> &sampl ...@@ -131,8 +131,8 @@ Vector4f SamplerCore::sampleTexture(Pointer<Byte> &texture, Pointer<Byte> &sampl
c.y = Float4(lod); // Unclamped LOD. c.y = Float4(lod); // Unclamped LOD.
} }
lod = Max(lod, *Pointer<Float>(sampler + OFFSET(vk::Sampler, minLod))); lod = Max(lod, state.minLod);
lod = Min(lod, *Pointer<Float>(sampler + OFFSET(vk::Sampler, maxLod))); lod = Min(lod, state.maxLod);
if(function == Query) if(function == Query)
{ {
...@@ -1198,7 +1198,7 @@ void SamplerCore::computeLod(Pointer<Byte> &texture, Pointer<Byte> &sampler, Flo ...@@ -1198,7 +1198,7 @@ void SamplerCore::computeLod(Pointer<Byte> &texture, Pointer<Byte> &sampler, Flo
vDelta = As<Float4>((As<Int4>(dvdx) & mask) | ((As<Int4>(dvdy) & ~mask))); vDelta = As<Float4>((As<Int4>(dvdx) & mask) | ((As<Int4>(dvdy) & ~mask)));
anisotropy = lod * Rcp_pp(det); anisotropy = lod * Rcp_pp(det);
anisotropy = Min(anisotropy, *Pointer<Float>(sampler + OFFSET(vk::Sampler, maxAnisotropy))); anisotropy = Min(anisotropy, state.maxAnisotropy);
lod *= Rcp_pp(anisotropy * anisotropy); lod *= Rcp_pp(anisotropy * anisotropy);
} }
......
...@@ -90,6 +90,11 @@ SpirvShader::ImageSampler *SpirvShader::getImageSampler(uint32_t inst, vk::Sampl ...@@ -90,6 +90,11 @@ SpirvShader::ImageSampler *SpirvShader::getImageSampler(uint32_t inst, vk::Sampl
samplerState.studioSwing = (sampler->ycbcrConversion->ycbcrRange == VK_SAMPLER_YCBCR_RANGE_ITU_NARROW); samplerState.studioSwing = (sampler->ycbcrConversion->ycbcrRange == VK_SAMPLER_YCBCR_RANGE_ITU_NARROW);
samplerState.swappedChroma = (sampler->ycbcrConversion->components.r != VK_COMPONENT_SWIZZLE_R); samplerState.swappedChroma = (sampler->ycbcrConversion->components.r != VK_COMPONENT_SWIZZLE_R);
} }
samplerState.mipLodBias = sampler->mipLodBias;
samplerState.maxAnisotropy = sampler->maxAnisotropy;
samplerState.minLod = sampler->minLod;
samplerState.maxLod = sampler->maxLod;
} }
routine = emitSamplerRoutine(instruction, samplerState); routine = emitSamplerRoutine(instruction, samplerState);
......
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