Fix update of immutable samplers
Use a common method for updating mutable and immutable sampler
descriptors.
Bug: b/129523279
Test: dEQP-VK.texture.filtering.2d.formats.r8g8b8a8_unorm.*
Change-Id: I1ef82c8fe2cbb2e92f3dadce794346be525648b8
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/29848
Presubmit-Ready: Nicolas Capens <nicolascapens@google.com>
Tested-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Chris Forbes <chrisforbes@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
diff --git a/src/Vulkan/VkDescriptorSetLayout.cpp b/src/Vulkan/VkDescriptorSetLayout.cpp
index 13a30e9..47f37da 100644
--- a/src/Vulkan/VkDescriptorSetLayout.cpp
+++ b/src/Vulkan/VkDescriptorSetLayout.cpp
@@ -160,7 +160,7 @@
for(uint32_t j = 0; j < bindings[i].descriptorCount; j++)
{
SampledImageDescriptor* imageSamplerDescriptor = reinterpret_cast<SampledImageDescriptor*>(mem);
- imageSamplerDescriptor->sampler = vk::Cast(bindings[i].pImmutableSamplers[j]);
+ imageSamplerDescriptor->updateSampler(vk::Cast(bindings[i].pImmutableSamplers[j]));
mem += typeSize;
}
}
@@ -245,6 +245,14 @@
return &descriptorSet->data[byteOffset];
}
+void SampledImageDescriptor::updateSampler(const vk::Sampler *sampler)
+{
+ this->sampler = sampler;
+
+ texture.minLod = sw::clamp(sampler->minLod, 0.0f, (float)(sw::MAX_TEXTURE_LOD));
+ texture.maxLod = sw::clamp(sampler->maxLod, 0.0f, (float)(sw::MAX_TEXTURE_LOD));
+}
+
void DescriptorSetLayout::WriteDescriptorSet(DescriptorSet *dstSet, VkDescriptorUpdateTemplateEntry const &entry, char const *src)
{
DescriptorSetLayout* dstLayout = dstSet->layout;
@@ -269,16 +277,9 @@
// descriptorCount of zero, must all either use immutable samplers or must all not use immutable samplers."
if(!binding.pImmutableSamplers)
{
- vk::Sampler *sampler = vk::Cast(update->sampler);
-
- imageSampler[i].sampler = sampler;
-
- texture->minLod = sw::clamp(sampler->minLod, 0.0f, (float)(sw::MAX_TEXTURE_LOD));
- texture->maxLod = sw::clamp(sampler->maxLod, 0.0f, (float)(sw::MAX_TEXTURE_LOD));
+ imageSampler[i].updateSampler(vk::Cast(update->sampler));
}
- memset(texture, 0, sizeof(sw::Texture)); // TODO(b/129523279): eliminate
-
imageSampler[i].imageView = imageView;
auto &subresourceRange = imageView->getSubresourceRange();
diff --git a/src/Vulkan/VkDescriptorSetLayout.hpp b/src/Vulkan/VkDescriptorSetLayout.hpp
index 3a3d31a..d7660b9 100644
--- a/src/Vulkan/VkDescriptorSetLayout.hpp
+++ b/src/Vulkan/VkDescriptorSetLayout.hpp
@@ -29,9 +29,11 @@
// TODO(b/129523279): Move to the Device or Pipeline layer.
struct SampledImageDescriptor
{
+ void updateSampler(const vk::Sampler *sampler);
+
// TODO(b/129523279): Minimize to the data actually needed.
- vk::Sampler *sampler;
- vk::ImageView *imageView;
+ const vk::Sampler *sampler;
+ const vk::ImageView *imageView;
sw::Texture texture;
};