Split vk::Sampler state off into a structure
This enables deriving the state structure from Memset<> so we can ensure
it is fully zero-initialized and becomes comparable, while vk::Sampler
holds the identifier for the state.
Bug: b/151235334
Change-Id: I23a09eda9b50409c761bdd6ed10911ec159dc3ba
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/42768
Presubmit-Ready: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
Tested-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/Vulkan/VkSampler.cpp b/src/Vulkan/VkSampler.cpp
index df62cc2..e5adb19 100644
--- a/src/Vulkan/VkSampler.cpp
+++ b/src/Vulkan/VkSampler.cpp
@@ -18,4 +18,35 @@
std::atomic<uint32_t> Sampler::nextID(1);
+SamplerState::SamplerState(const VkSamplerCreateInfo *pCreateInfo, const vk::SamplerYcbcrConversion *ycbcrConversion)
+ : Memset(this, 0)
+ , magFilter(pCreateInfo->magFilter)
+ , minFilter(pCreateInfo->minFilter)
+ , mipmapMode(pCreateInfo->mipmapMode)
+ , addressModeU(pCreateInfo->addressModeU)
+ , addressModeV(pCreateInfo->addressModeV)
+ , addressModeW(pCreateInfo->addressModeW)
+ , mipLodBias(pCreateInfo->mipLodBias)
+ , anisotropyEnable(pCreateInfo->anisotropyEnable)
+ , maxAnisotropy(pCreateInfo->maxAnisotropy)
+ , compareEnable(pCreateInfo->compareEnable)
+ , compareOp(pCreateInfo->compareOp)
+ , minLod(ClampLod(pCreateInfo->minLod))
+ , maxLod(ClampLod(pCreateInfo->maxLod))
+ , borderColor(pCreateInfo->borderColor)
+ , unnormalizedCoordinates(pCreateInfo->unnormalizedCoordinates)
+{
+ if(ycbcrConversion)
+ {
+ ycbcrModel = ycbcrConversion->ycbcrModel;
+ studioSwing = (ycbcrConversion->ycbcrRange == VK_SAMPLER_YCBCR_RANGE_ITU_NARROW);
+ swappedChroma = (ycbcrConversion->components.r != VK_COMPONENT_SWIZZLE_R);
+ }
+}
+
+Sampler::Sampler(const VkSamplerCreateInfo *pCreateInfo, void *mem, const vk::SamplerYcbcrConversion *ycbcrConversion)
+ : SamplerState(pCreateInfo, ycbcrConversion)
+{
+}
+
} // namespace vk