=?UTF-8?Q?J=C3=B3zef=20Kucia=20?=: vkd3d-shader: Delay generating functions for shader phases.

Alexandre Julliard julliard at winehq.org
Thu Feb 7 16:08:54 CST 2019


Module: vkd3d
Branch: master
Commit: e88b73797b4d5a2f38d0f92575ace35bcb23844e
URL:    https://source.winehq.org/git/vkd3d.git/?a=commit;h=e88b73797b4d5a2f38d0f92575ace35bcb23844e

Author: Józef Kucia <jkucia at codeweavers.com>
Date:   Thu Feb  7 09:59:14 2019 +0100

vkd3d-shader: Delay generating functions for shader phases.

Mainly in order to wait for dcl_hs_{fork,join}_phase_instance_count.

Signed-off-by: Józef Kucia <jkucia at codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 libs/vkd3d-shader/spirv.c | 86 ++++++++++++++++++++++++++++-------------------
 1 file changed, 51 insertions(+), 35 deletions(-)

diff --git a/libs/vkd3d-shader/spirv.c b/libs/vkd3d-shader/spirv.c
index 8efb385..e1ea236 100644
--- a/libs/vkd3d-shader/spirv.c
+++ b/libs/vkd3d-shader/spirv.c
@@ -1907,6 +1907,8 @@ struct vkd3d_push_constant_buffer_binding
 struct vkd3d_shader_phase
 {
     enum VKD3D_SHADER_INSTRUCTION_HANDLER type;
+    unsigned int idx;
+    unsigned int instance_count;
     uint32_t function_id;
     size_t function_location;
 };
@@ -3829,16 +3831,56 @@ static void vkd3d_dxbc_compiler_emit_initial_declarations(struct vkd3d_dxbc_comp
     vkd3d_dxbc_compiler_emit_shader_signature_outputs(compiler);
 }
 
+static void vkd3d_dxbc_compiler_begin_shader_phase(struct vkd3d_dxbc_compiler *compiler,
+        struct vkd3d_shader_phase *phase)
+{
+    struct vkd3d_spirv_builder *builder = &compiler->spirv_builder;
+    uint32_t void_id, function_type_id;
+    const char *name;
+
+    phase->function_id = vkd3d_spirv_alloc_id(builder);
+
+    void_id = vkd3d_spirv_get_op_type_void(builder);
+    function_type_id = vkd3d_spirv_get_op_type_function(builder, void_id, NULL, 0);
+    vkd3d_spirv_build_op_function(builder, void_id, phase->function_id,
+            SpvFunctionControlMaskNone, function_type_id);
+    vkd3d_spirv_build_op_label(builder, vkd3d_spirv_alloc_id(builder));
+
+    phase->function_location = vkd3d_spirv_stream_current_location(&builder->function_stream);
+
+    switch (phase->type)
+    {
+        case VKD3DSIH_HS_CONTROL_POINT_PHASE:
+            name = "control";
+            break;
+        case VKD3DSIH_HS_FORK_PHASE:
+            name = "fork";
+            break;
+        case VKD3DSIH_HS_JOIN_PHASE:
+            name = "join";
+            break;
+        default:
+            ERR("Invalid phase type %#x.\n", phase->type);
+            return;
+    }
+    vkd3d_spirv_build_op_name(builder, phase->function_id, "%s%u", name, phase->idx);
+}
+
 static const struct vkd3d_shader_phase *vkd3d_dxbc_compiler_get_current_shader_phase(
-        const struct vkd3d_dxbc_compiler *compiler)
+        struct vkd3d_dxbc_compiler *compiler)
 {
+    struct vkd3d_shader_phase *phase;
+
     if (!compiler->shader_phase_count)
         return NULL;
 
-    return &compiler->shader_phases[compiler->shader_phase_count - 1];
+    phase = &compiler->shader_phases[compiler->shader_phase_count - 1];
+    if (!phase->function_id)
+        vkd3d_dxbc_compiler_begin_shader_phase(compiler, phase);
+    return phase;
 }
 
-static size_t vkd3d_dxbc_compiler_get_current_function_location(const struct vkd3d_dxbc_compiler *compiler)
+static size_t vkd3d_dxbc_compiler_get_current_function_location(struct vkd3d_dxbc_compiler *compiler)
 {
     const struct vkd3d_spirv_builder *builder = &compiler->spirv_builder;
     const struct vkd3d_shader_phase *phase;
@@ -4708,14 +4750,10 @@ static void vkd3d_dxbc_compiler_enter_shader_phase(struct vkd3d_dxbc_compiler *c
         const struct vkd3d_shader_instruction *instruction)
 {
     struct vkd3d_spirv_builder *builder = &compiler->spirv_builder;
-    uint32_t void_id, function_type_id;
     struct vkd3d_shader_phase *phase;
-    const char *name;
-    unsigned int id;
-
-    id = compiler->shader_phase_count;
+    unsigned int idx;
 
-    if (id)
+    if ((idx = compiler->shader_phase_count))
         vkd3d_spirv_build_op_function_end(builder);
 
     if (!vkd3d_array_reserve((void **)&compiler->shader_phases, &compiler->shader_phases_size,
@@ -4724,32 +4762,10 @@ static void vkd3d_dxbc_compiler_enter_shader_phase(struct vkd3d_dxbc_compiler *c
     phase = &compiler->shader_phases[compiler->shader_phase_count++];
 
     phase->type = instruction->handler_idx;
-    phase->function_id = vkd3d_spirv_alloc_id(builder);
-
-    void_id = vkd3d_spirv_get_op_type_void(builder);
-    function_type_id = vkd3d_spirv_get_op_type_function(builder, void_id, NULL, 0);
-    vkd3d_spirv_build_op_function(builder, void_id, phase->function_id,
-            SpvFunctionControlMaskNone, function_type_id);
-    vkd3d_spirv_build_op_label(builder, vkd3d_spirv_alloc_id(builder));
-
-    phase->function_location = vkd3d_spirv_stream_current_location(&builder->function_stream);
-
-    switch (instruction->handler_idx)
-    {
-        case VKD3DSIH_HS_CONTROL_POINT_PHASE:
-            name = "control";
-            break;
-        case VKD3DSIH_HS_FORK_PHASE:
-            name = "fork";
-            break;
-        case VKD3DSIH_HS_JOIN_PHASE:
-            name = "join";
-            break;
-        default:
-            ERR("Invalid shader phase %#x.\n", instruction->handler_idx);
-            return;
-    }
-    vkd3d_spirv_build_op_name(builder, phase->function_id, "%s%u", name, id);
+    phase->idx = idx;
+    phase->instance_count = 0;
+    phase->function_id = 0;
+    phase->function_location = 0;
 }
 
 static void vkd3d_dxbc_compiler_emit_hull_shader_main(struct vkd3d_dxbc_compiler *compiler)




More information about the wine-cvs mailing list