Fix uninitialized memoryOwner on unused DescriptorSet In the Renderer, we call DescriptorSet::PrepareForSampling() on all input descriptors, not only the ones used in the current draw pass. Because of this, DescriptorSet::PrepareForSampling() might be called on uninitialized descriptors. Before this CL: https://swiftshader-review.googlesource.com/c/SwiftShader/+/57889 that memory used to be zeroed out, so that wasn't an issue, but now the memoryOwner pointer may be used without being initialized. This CL adds an initialization for the memoryOwner field on structures which use it (SampledImageDescriptor and StorageImageDescriptor). Bug: chromium:1260606 Change-Id: I41a02a8b652a48b790d8aacf16fd28d26e527336 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/58308 Presubmit-Ready: Alexis Hétu <sugoi@google.com> Tested-by: Alexis Hétu <sugoi@google.com> Kokoro-Result: kokoro <noreply+kokoro@google.com> Reviewed-by: Nicolas Capens <nicolascapens@google.com> Commit-Queue: Alexis Hétu <sugoi@google.com>
diff --git a/src/Vulkan/VkDescriptorSetLayout.cpp b/src/Vulkan/VkDescriptorSetLayout.cpp index 63a8a90..f839d6b 100644 --- a/src/Vulkan/VkDescriptorSetLayout.cpp +++ b/src/Vulkan/VkDescriptorSetLayout.cpp
@@ -176,12 +176,44 @@ { SampledImageDescriptor *imageSamplerDescriptor = reinterpret_cast<SampledImageDescriptor *>(mem); imageSamplerDescriptor->samplerId = bindings[i].immutableSamplers[j]->id; + imageSamplerDescriptor->memoryOwner = nullptr; mem += descriptorSize; } } else { - mem += bindings[i].descriptorCount * descriptorSize; + switch(bindings[i].descriptorType) + { + case VK_DESCRIPTOR_TYPE_SAMPLER: + case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: + case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: + case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: + for(uint32_t j = 0; j < bindings[i].descriptorCount; j++) + { + SampledImageDescriptor *imageSamplerDescriptor = reinterpret_cast<SampledImageDescriptor *>(mem); + imageSamplerDescriptor->memoryOwner = nullptr; + mem += descriptorSize; + } + break; + case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: + case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: + case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: + for(uint32_t j = 0; j < bindings[i].descriptorCount; j++) + { + StorageImageDescriptor *storageImage = reinterpret_cast<StorageImageDescriptor *>(mem); + storageImage->memoryOwner = nullptr; + mem += descriptorSize; + } + break; + case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: + case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: + case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC: + case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: + mem += bindings[i].descriptorCount * descriptorSize; + break; + default: + UNSUPPORTED("Unsupported Descriptor Type: %d", int(bindings[i].descriptorType)); + } } } }