aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShahbaz Youssefi <syoussefi@google.com>2024-01-22 09:49:16 -0500
committerswiftshader-scoped@luci-project-accounts.iam.gserviceaccount.com <swiftshader-scoped@luci-project-accounts.iam.gserviceaccount.com>2024-01-22 16:26:19 +0000
commit3bc9ccd923dafcaf43c63da60dd56e4d3050db39 (patch)
tree53aa1a1a4517c5e5c9a80066b9a679697bd225fc
parent5ab5177fc72dbb67f7353f1cfeb5ef64d67cfc67 (diff)
downloadswiftshader-3bc9ccd923dafcaf43c63da60dd56e4d3050db39.tar.gz
Clamp min LOD during image Fetch for robustness
The previous change clamped max LOD only, but min LOD also needs clamping because texelFetch takes an `int` as LOD instead of `uint`. Bug: chromium:1504556 Change-Id: Ibae8250a877b3e04b71fac45a40b77c78756d6c8 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/72968 Kokoro-Result: kokoro <noreply+kokoro@google.com> Reviewed-by: Ben Clayton <bclayton@google.com> Tested-by: Shahbaz Youssefi <syoussefi@google.com> Commit-Queue: Shahbaz Youssefi <syoussefi@google.com> Presubmit-Ready: Shahbaz Youssefi <syoussefi@google.com>
-rw-r--r--src/Pipeline/SamplerCore.cpp1
-rw-r--r--src/Pipeline/SpirvShaderSampling.cpp1
-rw-r--r--src/Vulkan/VkImageView.cpp8
-rw-r--r--src/Vulkan/VkImageView.hpp2
4 files changed, 10 insertions, 2 deletions
diff --git a/src/Pipeline/SamplerCore.cpp b/src/Pipeline/SamplerCore.cpp
index d62936273..ab55c036a 100644
--- a/src/Pipeline/SamplerCore.cpp
+++ b/src/Pipeline/SamplerCore.cpp
@@ -133,6 +133,7 @@ Vector4f SamplerCore::sampleTexture128(Pointer<Byte> &texture, Float4 uvwa[4], c
{
// TODO: Eliminate int-float-int conversion.
lod = Float(As<Int>(lodOrBias));
+ lod = Max(lod, state.minLod);
lod = Min(lod, state.maxLod);
}
else if(function == Base || function == Gather)
diff --git a/src/Pipeline/SpirvShaderSampling.cpp b/src/Pipeline/SpirvShaderSampling.cpp
index cb2d1d8d1..4c674050e 100644
--- a/src/Pipeline/SpirvShaderSampling.cpp
+++ b/src/Pipeline/SpirvShaderSampling.cpp
@@ -111,6 +111,7 @@ SpirvEmitter::ImageSampler *SpirvEmitter::getImageSampler(const vk::Device *devi
// Otherwise make sure LOD is clamped for robustness
else
{
+ samplerState.minLod = imageViewState.minLod;
samplerState.maxLod = imageViewState.maxLod;
}
}
diff --git a/src/Vulkan/VkImageView.cpp b/src/Vulkan/VkImageView.cpp
index 26b69aef7..1b25544a5 100644
--- a/src/Vulkan/VkImageView.cpp
+++ b/src/Vulkan/VkImageView.cpp
@@ -89,13 +89,15 @@ Identifier::Identifier(const VkImageViewCreateInfo *pCreateInfo)
const Image *sampledImage = image->getSampledImage(viewFormat);
vk::Format samplingFormat = (image == sampledImage) ? viewFormat : sampledImage->getFormat().getAspectFormat(subresource.aspectMask);
- pack({ pCreateInfo->viewType, samplingFormat, ResolveComponentMapping(pCreateInfo->components, viewFormat), static_cast<uint8_t>(subresource.baseMipLevel + subresource.levelCount), subresource.levelCount <= 1u });
+ pack({ pCreateInfo->viewType, samplingFormat, ResolveComponentMapping(pCreateInfo->components, viewFormat),
+ static_cast<uint8_t>(subresource.baseMipLevel),
+ static_cast<uint8_t>(subresource.baseMipLevel + subresource.levelCount), subresource.levelCount <= 1u });
}
Identifier::Identifier(VkFormat bufferFormat)
{
constexpr VkComponentMapping identityMapping = { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A };
- pack({ VK_IMAGE_VIEW_TYPE_1D, bufferFormat, ResolveComponentMapping(identityMapping, bufferFormat), 1, true });
+ pack({ VK_IMAGE_VIEW_TYPE_1D, bufferFormat, ResolveComponentMapping(identityMapping, bufferFormat), 0, 1, true });
}
void Identifier::pack(const State &state)
@@ -106,6 +108,7 @@ void Identifier::pack(const State &state)
g = static_cast<uint32_t>(state.mapping.g);
b = static_cast<uint32_t>(state.mapping.b);
a = static_cast<uint32_t>(state.mapping.a);
+ minLod = state.minLod;
maxLod = state.maxLod;
singleMipLevel = state.singleMipLevel;
}
@@ -118,6 +121,7 @@ Identifier::State Identifier::getState() const
static_cast<VkComponentSwizzle>(g),
static_cast<VkComponentSwizzle>(b),
static_cast<VkComponentSwizzle>(a) },
+ static_cast<uint8_t>(minLod),
static_cast<uint8_t>(maxLod),
static_cast<bool>(singleMipLevel) };
}
diff --git a/src/Vulkan/VkImageView.hpp b/src/Vulkan/VkImageView.hpp
index 5acb89639..25feebc9e 100644
--- a/src/Vulkan/VkImageView.hpp
+++ b/src/Vulkan/VkImageView.hpp
@@ -53,6 +53,7 @@ union Identifier
VkImageViewType imageViewType;
VkFormat format;
VkComponentMapping mapping;
+ uint8_t minLod;
uint8_t maxLod;
bool singleMipLevel;
};
@@ -71,6 +72,7 @@ private:
uint32_t g : 3;
uint32_t b : 3;
uint32_t a : 3;
+ uint32_t minLod : 4;
uint32_t maxLod : 4;
uint32_t singleMipLevel : 1;
};