Extracted from shader_spirv_resource_bindings_init().
Signed-off-by: Jan Sikorski jsikorski@codeweavers.com --- dlls/wined3d/shader_spirv.c | 125 ++++++++++++++++++++---------------- 1 file changed, 68 insertions(+), 57 deletions(-)
diff --git a/dlls/wined3d/shader_spirv.c b/dlls/wined3d/shader_spirv.c index 7617ee9d6ef..fb9f9dc4ff1 100644 --- a/dlls/wined3d/shader_spirv.c +++ b/dlls/wined3d/shader_spirv.c @@ -657,86 +657,97 @@ static enum wined3d_data_type wined3d_data_type_from_vkd3d(enum vkd3d_shader_res } }
-static bool shader_spirv_resource_bindings_init(struct shader_spirv_resource_bindings *bindings, - struct wined3d_shader_resource_bindings *wined3d_bindings, - const struct wined3d_state *state, uint32_t shader_mask) +static bool shader_spirv_resource_bindings_add_shader(struct shader_spirv_resource_bindings *bindings, + struct wined3d_shader_resource_bindings *wined3d_bindings, struct wined3d_shader *shader, + enum wined3d_shader_type shader_type) { struct vkd3d_shader_scan_descriptor_info *descriptor_info; enum wined3d_shader_descriptor_type wined3d_type; enum vkd3d_shader_visibility shader_visibility; - enum wined3d_shader_type shader_type; VkDescriptorType vk_descriptor_type; VkShaderStageFlagBits vk_stage; - struct wined3d_shader *shader; size_t binding_idx; unsigned int i;
- bindings->binding_count = 0; - bindings->uav_counter_count = 0; - bindings->vk_binding_count = 0; - bindings->so_stage = WINED3D_SHADER_TYPE_GEOMETRY; - wined3d_bindings->count = 0; - - for (shader_type = 0; shader_type < WINED3D_SHADER_TYPE_COUNT; ++shader_type) + if (shader_type == WINED3D_SHADER_TYPE_COMPUTE) { - bindings->binding_base[shader_type] = bindings->vk_binding_count; + descriptor_info = &((struct shader_spirv_compute_program_vk *)shader->backend_data)->descriptor_info; + } + else + { + descriptor_info = &((struct shader_spirv_graphics_program_vk *)shader->backend_data)->descriptor_info; + if (shader_type == WINED3D_SHADER_TYPE_GEOMETRY && !shader->function) + bindings->so_stage = WINED3D_SHADER_TYPE_VERTEX; + }
- if (!(shader_mask & (1u << shader_type)) || !(shader = state->shader[shader_type])) - continue; + vk_stage = vk_shader_stage_from_wined3d(shader_type); + shader_visibility = vkd3d_shader_visibility_from_wined3d(shader_type);
- if (shader_type == WINED3D_SHADER_TYPE_COMPUTE) + for (i = 0; i < descriptor_info->descriptor_count; ++i) + { + struct vkd3d_shader_descriptor_info *d = &descriptor_info->descriptors[i]; + uint32_t flags; + + if (d->register_space) { - descriptor_info = &((struct shader_spirv_compute_program_vk *)shader->backend_data)->descriptor_info; + WARN("Unsupported register space %u.\n", d->register_space); + return false; } + + if (d->resource_type == VKD3D_SHADER_RESOURCE_BUFFER) + flags = VKD3D_SHADER_BINDING_FLAG_BUFFER; else - { - descriptor_info = &((struct shader_spirv_graphics_program_vk *)shader->backend_data)->descriptor_info; - if (shader_type == WINED3D_SHADER_TYPE_GEOMETRY && !shader->function) - bindings->so_stage = WINED3D_SHADER_TYPE_VERTEX; - } + flags = VKD3D_SHADER_BINDING_FLAG_IMAGE;
- vk_stage = vk_shader_stage_from_wined3d(shader_type); - shader_visibility = vkd3d_shader_visibility_from_wined3d(shader_type); + vk_descriptor_type = vk_descriptor_type_from_vkd3d(d->type, d->resource_type); + if (!shader_spirv_resource_bindings_add_binding(bindings, d->type, vk_descriptor_type, + d->register_index, shader_visibility, vk_stage, flags, &binding_idx)) + return false;
- for (i = 0; i < descriptor_info->descriptor_count; ++i) - { - struct vkd3d_shader_descriptor_info *d = &descriptor_info->descriptors[i]; - uint32_t flags; + wined3d_type = wined3d_descriptor_type_from_vkd3d(d->type); + if (!wined3d_shader_resource_bindings_add_binding(wined3d_bindings, shader_type, + wined3d_type, d->register_index, wined3d_shader_resource_type_from_vkd3d(d->resource_type), + wined3d_data_type_from_vkd3d(d->resource_data_type), binding_idx)) + return false;
- if (d->register_space) - { - WARN("Unsupported register space %u.\n", d->register_space); + if (d->type == VKD3D_SHADER_DESCRIPTOR_TYPE_UAV + && (d->flags & VKD3D_SHADER_DESCRIPTOR_INFO_FLAG_UAV_COUNTER)) + { + if (!shader_spirv_resource_bindings_add_uav_counter_binding(bindings, + d->register_index, shader_visibility, vk_stage, &binding_idx)) return false; - } + if (!wined3d_shader_resource_bindings_add_binding(wined3d_bindings, + shader_type, WINED3D_SHADER_DESCRIPTOR_TYPE_UAV_COUNTER, d->register_index, + WINED3D_SHADER_RESOURCE_BUFFER, WINED3D_DATA_UINT, binding_idx)) + return false; + } + }
- if (d->resource_type == VKD3D_SHADER_RESOURCE_BUFFER) - flags = VKD3D_SHADER_BINDING_FLAG_BUFFER; - else - flags = VKD3D_SHADER_BINDING_FLAG_IMAGE; + return true; +}
- vk_descriptor_type = vk_descriptor_type_from_vkd3d(d->type, d->resource_type); - if (!shader_spirv_resource_bindings_add_binding(bindings, d->type, vk_descriptor_type, - d->register_index, shader_visibility, vk_stage, flags, &binding_idx)) - return false; +static bool shader_spirv_resource_bindings_init(struct shader_spirv_resource_bindings *bindings, + struct wined3d_shader_resource_bindings *wined3d_bindings, + const struct wined3d_state *state, uint32_t shader_mask) +{ + enum wined3d_shader_type shader_type; + struct wined3d_shader *shader;
- wined3d_type = wined3d_descriptor_type_from_vkd3d(d->type); - if (!wined3d_shader_resource_bindings_add_binding(wined3d_bindings, shader_type, - wined3d_type, d->register_index, wined3d_shader_resource_type_from_vkd3d(d->resource_type), - wined3d_data_type_from_vkd3d(d->resource_data_type), binding_idx)) - return false; + bindings->binding_count = 0; + bindings->uav_counter_count = 0; + bindings->vk_binding_count = 0; + bindings->so_stage = WINED3D_SHADER_TYPE_GEOMETRY; + wined3d_bindings->count = 0;
- if (d->type == VKD3D_SHADER_DESCRIPTOR_TYPE_UAV - && (d->flags & VKD3D_SHADER_DESCRIPTOR_INFO_FLAG_UAV_COUNTER)) - { - if (!shader_spirv_resource_bindings_add_uav_counter_binding(bindings, - d->register_index, shader_visibility, vk_stage, &binding_idx)) - return false; - if (!wined3d_shader_resource_bindings_add_binding(wined3d_bindings, - shader_type, WINED3D_SHADER_DESCRIPTOR_TYPE_UAV_COUNTER, d->register_index, - WINED3D_SHADER_RESOURCE_BUFFER, WINED3D_DATA_UINT, binding_idx)) - return false; - } - } + for (shader_type = 0; shader_type < WINED3D_SHADER_TYPE_COUNT; ++shader_type) + { + bindings->binding_base[shader_type] = bindings->vk_binding_count; + + if (!(shader_mask & (1u << shader_type)) || !(shader = state->shader[shader_type])) + continue; + + if (!shader_spirv_resource_bindings_add_shader(bindings, wined3d_bindings, shader, shader_type)) + return false; }
return true;