Commit 8c56e8d3 by Ben Clayton

SpirvShader: Don't abort for unused, unbound UniformConstants

Bug: b/126330097 Tests: dEQP-VK.glsl.discard.* Change-Id: I17632f68705aa8f0c8c607b5ec469272a58047db Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/29908Reviewed-by: 's avatarChris Forbes <chrisforbes@google.com> Tested-by: 's avatarBen Clayton <bclayton@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
parent 92797c27
...@@ -1345,6 +1345,7 @@ namespace sw ...@@ -1345,6 +1345,7 @@ namespace sw
auto set = routine->getPointer(id); auto set = routine->getPointer(id);
auto setLayout = routine->pipelineLayout->getDescriptorSetLayout(d.DescriptorSet); auto setLayout = routine->pipelineLayout->getDescriptorSetLayout(d.DescriptorSet);
ASSERT_MSG(setLayout->hasBinding(d.Binding), "Descriptor set %d does not contain binding %d", int(d.DescriptorSet), int(d.Binding));
int bindingOffset = static_cast<int>(setLayout->getBindingOffset(d.Binding, arrayIndex)); int bindingOffset = static_cast<int>(setLayout->getBindingOffset(d.Binding, arrayIndex));
Pointer<Byte> descriptor = set.base + bindingOffset; // BufferDescriptor* Pointer<Byte> descriptor = set.base + bindingOffset; // BufferDescriptor*
...@@ -2501,11 +2502,20 @@ namespace sw ...@@ -2501,11 +2502,20 @@ namespace sw
uint32_t arrayIndex = 0; // TODO(b/129523279) uint32_t arrayIndex = 0; // TODO(b/129523279)
auto setLayout = routine->pipelineLayout->getDescriptorSetLayout(d.DescriptorSet); auto setLayout = routine->pipelineLayout->getDescriptorSetLayout(d.DescriptorSet);
size_t bindingOffset = setLayout->getBindingOffset(d.Binding, arrayIndex); if (setLayout->hasBinding(d.Binding))
Pointer<Byte> set = routine->descriptorSets[d.DescriptorSet]; // DescriptorSet* {
Pointer<Byte> binding = Pointer<Byte>(set + bindingOffset); // vk::SampledImageDescriptor* size_t bindingOffset = setLayout->getBindingOffset(d.Binding, arrayIndex);
auto size = 0; // Not required as this pointer is not directly used by SIMD::Read or SIMD::Write. Pointer<Byte> set = routine->descriptorSets[d.DescriptorSet]; // DescriptorSet*
routine->createPointer(resultId, SIMD::Pointer(binding, size)); Pointer<Byte> binding = Pointer<Byte>(set + bindingOffset); // vk::SampledImageDescriptor*
auto size = 0; // Not required as this pointer is not directly used by SIMD::Read or SIMD::Write.
routine->createPointer(resultId, SIMD::Pointer(binding, size));
}
else
{
// TODO: Error if the variable with the non-existant binding is
// used? Or perhaps strip these unused variable declarations as
// a preprocess on the SPIR-V?
}
break; break;
} }
case spv::StorageClassUniform: case spv::StorageClassUniform:
......
...@@ -175,6 +175,18 @@ size_t DescriptorSetLayout::getBindingCount() const ...@@ -175,6 +175,18 @@ size_t DescriptorSetLayout::getBindingCount() const
return bindingCount; return bindingCount;
} }
bool DescriptorSetLayout::hasBinding(uint32_t binding) const
{
for(uint32_t i = 0; i < bindingCount; i++)
{
if(binding == bindings[i].binding)
{
return true;
}
}
return false;
}
size_t DescriptorSetLayout::getBindingStride(uint32_t binding) const size_t DescriptorSetLayout::getBindingStride(uint32_t binding) const
{ {
uint32_t index = getBindingIndex(binding); uint32_t index = getBindingIndex(binding);
......
...@@ -78,6 +78,9 @@ public: ...@@ -78,6 +78,9 @@ public:
// Returns the number of bindings in the descriptor set. // Returns the number of bindings in the descriptor set.
size_t getBindingCount() const; size_t getBindingCount() const;
// Returns true iff the given binding exists.
bool hasBinding(uint32_t binding) const;
// Returns the byte offset from the base address of the descriptor set for // Returns the byte offset from the base address of the descriptor set for
// the given binding and array element within that binding. // the given binding and array element within that binding.
size_t getBindingOffset(uint32_t binding, size_t arrayElement) const; size_t getBindingOffset(uint32_t binding, size_t arrayElement) const;
......
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