[PATCH 3/6] wined3d: Factor out shader_get_stream_output_register_info().

Józef Kucia jkucia at codeweavers.com
Mon Feb 11 09:32:14 CST 2019


Signed-off-by: Józef Kucia <jkucia at codeweavers.com>
---
 dlls/wined3d/glsl_shader.c     | 52 +++++++++-------------------------
 dlls/wined3d/shader.c          | 37 +++++++++++++++++-------
 dlls/wined3d/wined3d_private.h |  5 ++--
 3 files changed, 43 insertions(+), 51 deletions(-)

diff --git a/dlls/wined3d/glsl_shader.c b/dlls/wined3d/glsl_shader.c
index 4de0f82115df..970fa4b2b6d6 100644
--- a/dlls/wined3d/glsl_shader.c
+++ b/dlls/wined3d/glsl_shader.c
@@ -822,9 +822,9 @@ static BOOL shader_glsl_generate_transform_feedback_varyings(struct wined3d_stri
         const char **varyings, unsigned int *varying_count, char *strings, unsigned int *strings_length,
         GLenum buffer_mode, struct wined3d_shader *shader)
 {
-    unsigned int i, component_idx, buffer_idx, count, length, highest_output_slot, stride;
     const struct wined3d_stream_output_desc *so_desc = &shader->u.gs.so_desc;
-    const struct wined3d_shader_signature_element *output;
+    unsigned int buffer_idx, count, length, highest_output_slot, stride;
+    unsigned int i, register_idx, component_idx;
     BOOL have_varyings_to_record = FALSE;
 
     count = length = 0;
@@ -856,17 +856,9 @@ static BOOL shader_glsl_generate_transform_feedback_varyings(struct wined3d_stri
                 continue;
             }
 
-            if (!(output = shader_find_signature_element(&shader->output_signature,
-                    e->stream_idx, e->semantic_name, e->semantic_idx)))
+            if (!shader_get_stream_output_register_info(shader, e, &register_idx, &component_idx))
                 continue;
 
-            for (component_idx = 0; component_idx < 4; ++component_idx)
-            {
-                if ((1u << component_idx) & output->mask)
-                    break;
-            }
-            component_idx += e->component_idx;
-
             if (component_idx || e->component_count != 4)
             {
                 if (so_desc->rasterizer_stream_idx != WINED3D_NO_RASTERIZER_STREAM)
@@ -878,12 +870,12 @@ static BOOL shader_glsl_generate_transform_feedback_varyings(struct wined3d_stri
                 }
 
                 string_buffer_sprintf(buffer, "shader_in_out.reg%u_%u_%u",
-                        output->register_idx, component_idx, component_idx + e->component_count - 1);
+                        register_idx, component_idx, component_idx + e->component_count - 1);
                 append_transform_feedback_varying(varyings, &count, &strings, &length, buffer);
             }
             else
             {
-                string_buffer_sprintf(buffer, "shader_in_out.reg%u", output->register_idx);
+                string_buffer_sprintf(buffer, "shader_in_out.reg%u", register_idx);
                 append_transform_feedback_varying(varyings, &count, &strings, &length, buffer);
             }
 
@@ -7437,8 +7429,7 @@ static void shader_glsl_generate_stream_output_setup(struct wined3d_string_buffe
         const struct wined3d_shader *shader)
 {
     const struct wined3d_stream_output_desc *so_desc = &shader->u.gs.so_desc;
-    const struct wined3d_shader_signature_element *output;
-    unsigned int i, component_idx;
+    unsigned int i, register_idx, component_idx;
 
     shader_addline(buffer, "out shader_in_out\n{\n");
     for (i = 0; i < so_desc->element_count; ++i)
@@ -7452,17 +7443,9 @@ static void shader_glsl_generate_stream_output_setup(struct wined3d_string_buffe
         }
         if (!e->semantic_name)
             continue;
-        if (!(output = shader_find_signature_element(&shader->output_signature,
-                e->stream_idx, e->semantic_name, e->semantic_idx)))
+        if (!shader_get_stream_output_register_info(shader, e, &register_idx, &component_idx))
             continue;
 
-        for (component_idx = 0; component_idx < 4; ++component_idx)
-        {
-            if ((1u << component_idx) & output->mask)
-                break;
-        }
-        component_idx += e->component_idx;
-
         if (component_idx || e->component_count != 4)
         {
             if (e->component_count == 1)
@@ -7471,11 +7454,11 @@ static void shader_glsl_generate_stream_output_setup(struct wined3d_string_buffe
                 shader_addline(buffer, "vec%u", e->component_count);
 
             shader_addline(buffer, " reg%u_%u_%u;\n",
-                    output->register_idx, component_idx, component_idx + e->component_count - 1);
+                    register_idx, component_idx, component_idx + e->component_count - 1);
         }
         else
         {
-            shader_addline(buffer, "vec4 reg%u;\n", output->register_idx);
+            shader_addline(buffer, "vec4 reg%u;\n", register_idx);
         }
     }
     shader_addline(buffer, "} shader_out;\n");
@@ -7493,17 +7476,9 @@ static void shader_glsl_generate_stream_output_setup(struct wined3d_string_buffe
         }
         if (!e->semantic_name)
             continue;
-        if (!(output = shader_find_signature_element(&shader->output_signature,
-                e->stream_idx, e->semantic_name, e->semantic_idx)))
+        if (!shader_get_stream_output_register_info(shader, e, &register_idx, &component_idx))
             continue;
 
-        for (component_idx = 0; component_idx < 4; ++component_idx)
-        {
-            if ((1u << component_idx) & output->mask)
-                break;
-        }
-        component_idx += e->component_idx;
-
         if (component_idx || e->component_count != 4)
         {
             DWORD write_mask;
@@ -7512,13 +7487,12 @@ static void shader_glsl_generate_stream_output_setup(struct wined3d_string_buffe
             write_mask = ((1u << e->component_count) - 1) << component_idx;
             shader_glsl_write_mask_to_str(write_mask, str_mask);
             shader_addline(buffer, "shader_out.reg%u_%u_%u = outputs[%u]%s;\n",
-                    output->register_idx, component_idx, component_idx + e->component_count - 1,
-                    output->register_idx, str_mask);
+                    register_idx, component_idx, component_idx + e->component_count - 1,
+                    register_idx, str_mask);
         }
         else
         {
-            shader_addline(buffer, "shader_out.reg%u = outputs[%u];\n",
-                    output->register_idx, output->register_idx);
+            shader_addline(buffer, "shader_out.reg%u = outputs[%u];\n", register_idx, register_idx);
         }
     }
     shader_addline(buffer, "}\n");
diff --git a/dlls/wined3d/shader.c b/dlls/wined3d/shader.c
index a7d0e6911901..b75ff6f99ce7 100644
--- a/dlls/wined3d/shader.c
+++ b/dlls/wined3d/shader.c
@@ -3728,7 +3728,7 @@ static HRESULT vertex_shader_init(struct wined3d_shader *shader, struct wined3d_
     return WINED3D_OK;
 }
 
-struct wined3d_shader_signature_element *shader_find_signature_element(const struct wined3d_shader_signature *s,
+static struct wined3d_shader_signature_element *shader_find_signature_element(const struct wined3d_shader_signature *s,
         unsigned int stream_idx, const char *semantic_name, unsigned int semantic_idx)
 {
     struct wined3d_shader_signature_element *e = s->elements;
@@ -3745,14 +3745,36 @@ struct wined3d_shader_signature_element *shader_find_signature_element(const str
     return NULL;
 }
 
+BOOL shader_get_stream_output_register_info(const struct wined3d_shader *shader,
+        const struct wined3d_stream_output_element *so_element, unsigned int *register_idx, unsigned int *component_idx)
+{
+    const struct wined3d_shader_signature_element *output;
+    unsigned int idx;
+
+    if (!(output = shader_find_signature_element(&shader->output_signature,
+            so_element->stream_idx, so_element->semantic_name, so_element->semantic_idx)))
+        return FALSE;
+
+    for (idx = 0; idx < 4; ++idx)
+    {
+        if (output->mask & (1u << idx))
+            break;
+    }
+    idx += so_element->component_idx;
+
+    *register_idx = output->register_idx;
+    *component_idx = idx;
+    return TRUE;
+}
+
 static HRESULT geometry_shader_init_stream_output(struct wined3d_shader *shader,
         const struct wined3d_stream_output_desc *so_desc)
 {
     const struct wined3d_shader_frontend *fe = shader->frontend;
     const struct wined3d_shader_signature_element *output;
+    unsigned int i, component_idx, register_idx, mask;
     struct wined3d_stream_output_element *elements;
     struct wined3d_shader_version shader_version;
-    unsigned int i, component_idx, mask;
     const DWORD *ptr;
     void *fe_data;
     HRESULT hr;
@@ -3805,7 +3827,8 @@ static HRESULT geometry_shader_init_stream_output(struct wined3d_shader *shader,
         if (!e->semantic_name)
             continue;
         if (!(output = shader_find_signature_element(&shader->output_signature,
-                e->stream_idx, e->semantic_name, e->semantic_idx)))
+                e->stream_idx, e->semantic_name, e->semantic_idx))
+                || !shader_get_stream_output_register_info(shader, e, &register_idx, &component_idx))
         {
             WARN("Failed to find output signature element for stream output entry.\n");
             return E_INVALIDARG;
@@ -3813,17 +3836,11 @@ static HRESULT geometry_shader_init_stream_output(struct wined3d_shader *shader,
 
         e->semantic_name = output->semantic_name;
 
-        for (component_idx = 0; component_idx < 4; ++component_idx)
-        {
-            if ((1u << component_idx) & output->mask)
-                break;
-        }
-        component_idx += e->component_idx;
         mask = ((1u << e->component_count) - 1) << component_idx;
         if ((output->mask & 0xff & mask) != mask)
         {
             WARN("Invalid component range %u-%u (mask %#x), output mask %#x.\n",
-                    e->component_idx, e->component_count, mask, output->mask & 0xff);
+                    component_idx, e->component_count, mask, output->mask & 0xff);
             return E_INVALIDARG;
         }
     }
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 187c9e18c523..6aadc316f68e 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -1267,8 +1267,9 @@ extern const struct wined3d_shader_frontend sm4_shader_frontend DECLSPEC_HIDDEN;
 
 HRESULT shader_extract_from_dxbc(struct wined3d_shader *shader,
         unsigned int max_shader_version, enum wined3d_shader_byte_code_format *format) DECLSPEC_HIDDEN;
-struct wined3d_shader_signature_element *shader_find_signature_element(const struct wined3d_shader_signature *s,
-        unsigned int stream_idx, const char *semantic_name, unsigned int semantic_idx) DECLSPEC_HIDDEN;
+BOOL shader_get_stream_output_register_info(const struct wined3d_shader *shader,
+        const struct wined3d_stream_output_element *so_element, unsigned int *register_idx,
+        unsigned int *component_idx) DECLSPEC_HIDDEN;
 
 typedef void (*SHADER_HANDLER)(const struct wined3d_shader_instruction *);
 
-- 
2.19.2




More information about the wine-devel mailing list