From a1e10e5c90f90ed0a9c767d26c98fabf727f2e45 Mon Sep 17 00:00:00 2001 From: Zebediah Figura Date: Wed, 9 Aug 2023 19:14:54 -0500 Subject: [PATCH] vkd3d-shader/spirv: Split spirv_compiler_has_combined_sampler() into two functions. These functions do not really share any code in common. --- libs/vkd3d-shader/spirv.c | 45 +++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/libs/vkd3d-shader/spirv.c b/libs/vkd3d-shader/spirv.c index d79796bc..982b8a14 100644 --- a/libs/vkd3d-shader/spirv.c +++ b/libs/vkd3d-shader/spirv.c @@ -2594,8 +2594,8 @@ static struct vkd3d_push_constant_buffer_binding *spirv_compiler_find_push_const return NULL; } -static bool spirv_compiler_has_combined_sampler(const struct spirv_compiler *compiler, - const struct vkd3d_shader_resource *resource, const struct vkd3d_shader_sampler *sampler) +static bool spirv_compiler_has_combined_sampler_for_resource(const struct spirv_compiler *compiler, + const struct vkd3d_shader_resource *resource) { const struct vkd3d_shader_interface_info *shader_interface = &compiler->shader_interface; const struct vkd3d_shader_combined_resource_sampler *combined_sampler; @@ -2604,10 +2604,7 @@ static bool spirv_compiler_has_combined_sampler(const struct spirv_compiler *com if (!shader_interface->combined_sampler_count) return false; - if (resource && (resource->reg.reg.type == VKD3DSPR_UAV || resource->range.last != resource->range.first)) - return false; - - if (sampler && sampler->range.first != sampler->range.last) + if (resource->reg.reg.type == VKD3DSPR_UAV || resource->range.last != resource->range.first) return false; for (i = 0; i < shader_interface->combined_sampler_count; ++i) @@ -2617,10 +2614,36 @@ static bool spirv_compiler_has_combined_sampler(const struct spirv_compiler *com if (!spirv_compiler_check_shader_visibility(compiler, combined_sampler->shader_visibility)) continue; - if ((!resource || (combined_sampler->resource_space == resource->range.space + if ((combined_sampler->resource_space == resource->range.space && combined_sampler->resource_index == resource->range.first)) - && (!sampler || (combined_sampler->sampler_space == sampler->range.space - && combined_sampler->sampler_index == sampler->range.first))) + return true; + } + + return false; +} + +static bool spirv_compiler_has_combined_sampler_for_sampler(const struct spirv_compiler *compiler, + const struct vkd3d_shader_sampler *sampler) +{ + const struct vkd3d_shader_interface_info *shader_interface = &compiler->shader_interface; + const struct vkd3d_shader_combined_resource_sampler *combined_sampler; + unsigned int i; + + if (!shader_interface->combined_sampler_count) + return false; + + if (sampler->range.last != sampler->range.first) + return false; + + for (i = 0; i < shader_interface->combined_sampler_count; ++i) + { + combined_sampler = &shader_interface->combined_samplers[i]; + + if (!spirv_compiler_check_shader_visibility(compiler, combined_sampler->shader_visibility)) + continue; + + if (combined_sampler->sampler_space == sampler->range.space + && combined_sampler->sampler_index == sampler->range.first) return true; } @@ -5648,7 +5671,7 @@ static void spirv_compiler_emit_dcl_sampler(struct spirv_compiler *compiler, reg_symbol.info.sampler.range = sampler->range; spirv_compiler_put_symbol(compiler, ®_symbol); - if (spirv_compiler_has_combined_sampler(compiler, NULL, sampler)) + if (spirv_compiler_has_combined_sampler_for_sampler(compiler, sampler)) return; type_id = vkd3d_spirv_get_op_type_sampler(builder); @@ -5860,7 +5883,7 @@ static void spirv_compiler_emit_resource_declaration(struct spirv_compiler *comp sampled_type = vkd3d_component_type_from_data_type(resource_data_type); - if (spirv_compiler_has_combined_sampler(compiler, resource, NULL)) + if (spirv_compiler_has_combined_sampler_for_resource(compiler, resource)) { spirv_compiler_emit_combined_sampler_declarations(compiler, reg, &resource->range, resource_type, sampled_type, structure_stride, raw, resource_type_info);