[PATCH vkd3d 1/3] vkd3d-shader: Introduce a shader interface extension for binding offset info.

Conor McCarthy cmccarthy at codeweavers.com
Mon Oct 11 09:07:28 CDT 2021


Signed-off-by: Conor McCarthy <cmccarthy at codeweavers.com>
---
 include/vkd3d_shader.h    | 22 ++++++++++++++++++++++
 libs/vkd3d-shader/spirv.c |  8 +++++++-
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/include/vkd3d_shader.h b/include/vkd3d_shader.h
index 37b5936d..8d813d85 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_binding_offset_info structure.
+     * \since 1.3
+     */
+    VKD3D_SHADER_STRUCTURE_TYPE_BINDING_OFFSET_INFO,
 
     VKD3D_FORCE_32_BIT_ENUM(VKD3D_SHADER_STRUCTURE_TYPE),
 };
@@ -452,6 +457,23 @@ struct vkd3d_shader_transform_feedback_info
     unsigned int buffer_stride_count;
 };
 
+/* Extends vkd3d_shader_interface_info. */
+struct vkd3d_shader_binding_offset_info
+{
+    /** Must be set to VKD3D_SHADER_STRUCTURE_TYPE_BINDING_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 into shader resource descriptor bindings.
+     * These correlate 1:1 to the 'bindings' array in struct
+     * vkd3d_shader_interface_info, and will be added to the register index to
+     * address the correct location in a merged binding.
+     */
+    const unsigned int *binding_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..fab92059 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_binding_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_binding_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,9 @@ 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, BINDING_OFFSET_INFO)))
+            compiler->offset_info = *offset_info;
     }
 
     compiler->scan_descriptor_info = scan_descriptor_info;
@@ -2546,6 +2551,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 *binding_offsets = compiler->offset_info.binding_offsets;
     enum vkd3d_shader_descriptor_type descriptor_type;
     enum vkd3d_shader_binding_flag resource_type_flag;
     struct vkd3d_shader_descriptor_binding binding;
@@ -2626,7 +2632,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 - (binding_offsets ? binding_offsets[i] : 0);
             return current->binding;
         }
         if (shader_interface->binding_count)
-- 
2.32.0




More information about the wine-devel mailing list