Signed-off-by: Conor McCarthy cmccarthy@codeweavers.com --- include/vkd3d_shader.h | 38 ++++++++++++++++++++++++++++++++++++++ libs/vkd3d-shader/spirv.c | 12 +++++++++++- 2 files changed, 49 insertions(+), 1 deletion(-)
diff --git a/include/vkd3d_shader.h b/include/vkd3d_shader.h index 37b5936d..77cc3751 100644 --- a/include/vkd3d_shader.h +++ b/include/vkd3d_shader.h @@ -64,6 +64,11 @@ enum vkd3d_shader_structure_type * \since 1.3 */ VKD3D_SHADER_STRUCTURE_TYPE_PREPROCESS_INFO, + /** + * The structure is a vkd3d_shader_descriptor_offset_info structure. + * \since 1.3 + */ + VKD3D_SHADER_STRUCTURE_TYPE_DESCRIPTOR_OFFSET_INFO,
VKD3D_FORCE_32_BIT_ENUM(VKD3D_SHADER_STRUCTURE_TYPE), }; @@ -452,6 +457,39 @@ struct vkd3d_shader_transform_feedback_info unsigned int buffer_stride_count; };
+/* Extends vkd3d_shader_interface_info. */ +struct vkd3d_shader_descriptor_offset_info +{ + /** Must be set to VKD3D_SHADER_STRUCTURE_TYPE_DESCRIPTOR_OFFSET_INFO. */ + enum vkd3d_shader_structure_type type; + /** Optional pointer to a structure containing further parameters. */ + const void *next; + + /** + * Pointer to an array of offsets which define the location of each vkd3d + * shader resource descriptor binding within a Vulkan descriptor binding. + * This array correlates exactly to the 'bindings' array in struct + * vkd3d_shader_interface_info. Multiple vkd3d bindings may be merged into + * a single Vulkan binding, and these offsets will be used to address the + * correct location in a merged binding. This value may be NULL, but if + * merged bindings are not used (i.e. all offsets are zero), struct + * vkd3d_shader_descriptor_offset_info may be omitted. The 'count' field in + * struct vkd3d_shader_descriptor_binding begins at the offset location. + * Use of merged Vulkan bindings requires EXT_descriptor_indexing. Merged + * bindings are not supported for combined samplers. + */ + const unsigned int *descriptor_offsets; + + /** + * Pointer to an array of offsets into UAV counter descriptor bindings. + * These correlate exactly to the 'uav_counters' array in struct + * vkd3d_shader_interface_info, and will be used in the same way as + * \ref descriptor_offsets above. UAV counter arrays are not supported in + * this version of vkd3d-shader, so this value must be NULL. + */ + const unsigned int *uav_counter_offsets; +}; + /** The format of a shader to be compiled or scanned. */ enum vkd3d_shader_source_type { diff --git a/libs/vkd3d-shader/spirv.c b/libs/vkd3d-shader/spirv.c index ebaf1631..d04b1101 100644 --- a/libs/vkd3d-shader/spirv.c +++ b/libs/vkd3d-shader/spirv.c @@ -2231,6 +2231,7 @@ struct vkd3d_dxbc_compiler size_t control_flow_info_size;
struct vkd3d_shader_interface_info shader_interface; + struct vkd3d_shader_descriptor_offset_info offset_info; struct vkd3d_push_constant_buffer_binding *push_constants; const struct vkd3d_shader_spirv_target_info *spirv_target_info;
@@ -2292,6 +2293,7 @@ struct vkd3d_dxbc_compiler *vkd3d_dxbc_compiler_create(const struct vkd3d_shader const struct vkd3d_shader_signature *patch_constant_signature = &shader_desc->patch_constant_signature; const struct vkd3d_shader_signature *output_signature = &shader_desc->output_signature; const struct vkd3d_shader_interface_info *shader_interface; + const struct vkd3d_shader_descriptor_offset_info *offset_info; const struct vkd3d_shader_spirv_target_info *target_info; struct vkd3d_dxbc_compiler *compiler; unsigned int max_element_count; @@ -2385,6 +2387,13 @@ struct vkd3d_dxbc_compiler *vkd3d_dxbc_compiler_create(const struct vkd3d_shader for (i = 0; i < shader_interface->push_constant_buffer_count; ++i) compiler->push_constants[i].pc = shader_interface->push_constant_buffers[i]; } + + if ((offset_info = vkd3d_find_struct(shader_interface->next, DESCRIPTOR_OFFSET_INFO))) + { + compiler->offset_info = *offset_info; + if (offset_info->uav_counter_offsets) + WARN("Ignoring UAV counter offsets %p.\n", offset_info->uav_counter_offsets); + } }
compiler->scan_descriptor_info = scan_descriptor_info; @@ -2546,6 +2555,7 @@ static struct vkd3d_shader_descriptor_binding vkd3d_dxbc_compiler_get_descriptor { const struct vkd3d_shader_interface_info *shader_interface = &compiler->shader_interface; unsigned int register_last = (range->last == ~0u) ? range->first : range->last; + const unsigned int *descriptor_offsets = compiler->offset_info.descriptor_offsets; enum vkd3d_shader_descriptor_type descriptor_type; enum vkd3d_shader_binding_flag resource_type_flag; struct vkd3d_shader_descriptor_binding binding; @@ -2626,7 +2636,7 @@ static struct vkd3d_shader_descriptor_binding vkd3d_dxbc_compiler_get_descriptor || current->binding.count <= register_last - current->register_index) continue;
- *binding_base_idx = current->register_index; + *binding_base_idx = current->register_index - (descriptor_offsets ? descriptor_offsets[i] : 0); return current->binding; } if (shader_interface->binding_count)