Commit fa7d1366 by Nicolas Capens Committed by Nicolas Capens

Validate descriptor ID's

Bug: b/129523279 Test: dEQP-VK.glsl.texture_functions.* Test: dEQP-VK.spirv_assembly.instruction.graphics.image_sampler.* Change-Id: I26959eb7665af9f35dba81f83b0e0f13a4798865 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/30408 Presubmit-Ready: Nicolas Capens <nicolascapens@google.com> Tested-by: 's avatarNicolas Capens <nicolascapens@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Reviewed-by: 's avatarChris Forbes <chrisforbes@google.com>
parent 1e7120e4
......@@ -37,8 +37,11 @@
namespace sw {
SpirvShader::ImageSampler *SpirvShader::getImageSampler(uint32_t instruction, const vk::ImageView *imageView, const vk::Sampler *sampler)
SpirvShader::ImageSampler *SpirvShader::getImageSampler(uint32_t inst, const vk::ImageView *imageView, const vk::Sampler *sampler)
{
ImageInstruction instruction(inst);
ASSERT(imageView->id != 0 && (sampler->id != 0 || instruction.samplerMethod == Fetch));
// TODO(b/129523279): Move somewhere sensible.
static std::unordered_map<uint64_t, ImageSampler*> cache;
static std::mutex mutex;
......@@ -72,7 +75,7 @@ SpirvShader::ImageSampler *SpirvShader::getImageSampler(uint32_t instruction, co
ASSERT(sampler->anisotropyEnable == VK_FALSE); // TODO(b/129523279)
ASSERT(sampler->unnormalizedCoordinates == VK_FALSE); // TODO(b/129523279)
auto fptr = emitSamplerFunction({instruction}, samplerState);
auto fptr = emitSamplerFunction(instruction, samplerState);
cache.emplace(key, fptr);
return fptr;
......
......@@ -262,6 +262,12 @@ void SampledImageDescriptor::updateSampler(const vk::Sampler *sampler)
{
memcpy(&this->sampler, sampler, sizeof(this->sampler));
}
else
{
// Descriptor ID's start at 1, allowing to detect descriptor update
// bugs by checking for 0. Also avoid reading random values.
memset(&this->sampler, 0, sizeof(this->sampler));
}
}
void DescriptorSetLayout::WriteDescriptorSet(DescriptorSet *dstSet, VkDescriptorUpdateTemplateEntry const &entry, char const *src)
......
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