Vulkan: Check Resource Bind Type when Binding
GPU module assumes that image and textures uses different bind namespaces. In Vulkan this isn't the case, leading that some shaders generate incorrect bind types, when the state has bindings that are not used by the shader, but would conflict due to namespace differences. This PR will only return the binding when after validating it is from the expected namespace. This removes several validation warnings. This was done in order to debug EEVEE using modern toolsets. These toolsets don't support OpenGL and we use Vulkan as a workaround if possible. Pull Request: https://projects.blender.org/blender/blender/pulls/116465
This commit is contained in:
@@ -156,11 +156,13 @@ void VKShaderInterface::init(const shader::ShaderCreateInfo &info)
|
||||
const uint32_t resources_len = input_tot_len;
|
||||
descriptor_set_locations_ = Array<VKDescriptorSet::Location>(resources_len);
|
||||
descriptor_set_locations_.fill(-1);
|
||||
descriptor_set_bind_types_ = Array<shader::ShaderCreateInfo::Resource::BindType>(resources_len);
|
||||
descriptor_set_bind_types_.fill(shader::ShaderCreateInfo::Resource::BindType::UNIFORM_BUFFER);
|
||||
uint32_t descriptor_set_location = 0;
|
||||
for (ShaderCreateInfo::Resource &res : all_resources) {
|
||||
const ShaderInput *input = shader_input_get(res);
|
||||
BLI_assert(input);
|
||||
descriptor_set_location_update(input, descriptor_set_location++);
|
||||
descriptor_set_location_update(input, descriptor_set_location++, res.bind_type);
|
||||
}
|
||||
|
||||
/* Post initializing push constants. */
|
||||
@@ -169,7 +171,9 @@ void VKShaderInterface::init(const shader::ShaderCreateInfo &info)
|
||||
if (push_constants_storage_type == VKPushConstants::StorageType::UNIFORM_BUFFER) {
|
||||
push_constant_descriptor_set_location = descriptor_set_location++;
|
||||
const ShaderInput *push_constant_input = ubo_get(PUSH_CONSTANTS_FALLBACK_NAME);
|
||||
descriptor_set_location_update(push_constant_input, push_constants_fallback_location);
|
||||
descriptor_set_location_update(push_constant_input,
|
||||
push_constants_fallback_location,
|
||||
shader::ShaderCreateInfo::Resource::UNIFORM_BUFFER);
|
||||
}
|
||||
push_constants_layout_.init(
|
||||
info, *this, push_constants_storage_type, push_constant_descriptor_set_location);
|
||||
@@ -182,12 +186,15 @@ static int32_t shader_input_index(const ShaderInput *shader_inputs,
|
||||
return index;
|
||||
}
|
||||
|
||||
void VKShaderInterface::descriptor_set_location_update(const ShaderInput *shader_input,
|
||||
const VKDescriptorSet::Location location)
|
||||
void VKShaderInterface::descriptor_set_location_update(
|
||||
const ShaderInput *shader_input,
|
||||
const VKDescriptorSet::Location location,
|
||||
const shader::ShaderCreateInfo::Resource::BindType bind_type)
|
||||
{
|
||||
int32_t index = shader_input_index(inputs_, shader_input);
|
||||
BLI_assert(descriptor_set_locations_[index].binding == -1);
|
||||
descriptor_set_locations_[index] = location;
|
||||
descriptor_set_bind_types_[index] = bind_type;
|
||||
}
|
||||
|
||||
const VKDescriptorSet::Location VKShaderInterface::descriptor_set_location(
|
||||
@@ -197,6 +204,13 @@ const VKDescriptorSet::Location VKShaderInterface::descriptor_set_location(
|
||||
return descriptor_set_locations_[index];
|
||||
}
|
||||
|
||||
const shader::ShaderCreateInfo::Resource::BindType VKShaderInterface::descriptor_set_bind_type(
|
||||
const ShaderInput *shader_input) const
|
||||
{
|
||||
int32_t index = shader_input_index(inputs_, shader_input);
|
||||
return descriptor_set_bind_types_[index];
|
||||
}
|
||||
|
||||
const VKDescriptorSet::Location VKShaderInterface::descriptor_set_location(
|
||||
const shader::ShaderCreateInfo::Resource &resource) const
|
||||
{
|
||||
@@ -212,6 +226,9 @@ const std::optional<VKDescriptorSet::Location> VKShaderInterface::descriptor_set
|
||||
if (shader_input == nullptr) {
|
||||
return std::nullopt;
|
||||
}
|
||||
if (descriptor_set_bind_type(shader_input) != bind_type) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return descriptor_set_location(shader_input);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ class VKShaderInterface : public ShaderInterface {
|
||||
*/
|
||||
uint32_t image_offset_ = 0;
|
||||
Array<VKDescriptorSet::Location> descriptor_set_locations_;
|
||||
Array<shader::ShaderCreateInfo::Resource::BindType> descriptor_set_bind_types_;
|
||||
|
||||
VKPushConstants::Layout push_constants_layout_;
|
||||
|
||||
@@ -71,8 +72,12 @@ class VKShaderInterface : public ShaderInterface {
|
||||
const ShaderInput *shader_input_get(
|
||||
const shader::ShaderCreateInfo::Resource::BindType &bind_type, int binding) const;
|
||||
const VKDescriptorSet::Location descriptor_set_location(const ShaderInput *shader_input) const;
|
||||
void descriptor_set_location_update(const ShaderInput *shader_input,
|
||||
const VKDescriptorSet::Location location);
|
||||
const shader::ShaderCreateInfo::Resource::BindType descriptor_set_bind_type(
|
||||
const ShaderInput *shader_input) const;
|
||||
void descriptor_set_location_update(
|
||||
const ShaderInput *shader_input,
|
||||
const VKDescriptorSet::Location location,
|
||||
const shader::ShaderCreateInfo::Resource::BindType bind_type);
|
||||
};
|
||||
|
||||
} // namespace blender::gpu
|
||||
|
||||
Reference in New Issue
Block a user