Francisco Casas : vkd3d-shader/hlsl: Unify type minor/major size functions.

Alexandre Julliard julliard at winehq.org
Wed Aug 10 14:45:26 CDT 2022


Module: vkd3d
Branch: master
Commit: 2dcfc888fb514fd908681178efed98fe7ff4863c
URL:    https://gitlab.winehq.org/wine/vkd3d/-/commit/2dcfc888fb514fd908681178efed98fe7ff4863c

Author: Francisco Casas <fcasas at codeweavers.com>
Date:   Thu Jun 30 16:25:12 2022 -0400

vkd3d-shader/hlsl: Unify type minor/major size functions.

Signed-off-by: Francisco Casas <fcasas at codeweavers.com>
Signed-off-by: Giovanni Mascellani <gmascellani at codeweavers.com>

---

 libs/vkd3d-shader/hlsl.c         | 16 ++++++++++++++++
 libs/vkd3d-shader/hlsl.h         |  2 ++
 libs/vkd3d-shader/hlsl.y         | 20 ++------------------
 libs/vkd3d-shader/hlsl_codegen.c | 28 ++++++----------------------
 4 files changed, 26 insertions(+), 40 deletions(-)

diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c
index 0f0634d8..3fa87ca3 100644
--- a/libs/vkd3d-shader/hlsl.c
+++ b/libs/vkd3d-shader/hlsl.c
@@ -124,6 +124,22 @@ bool hlsl_type_is_row_major(const struct hlsl_type *type)
     return !!(type->modifiers & HLSL_MODIFIER_ROW_MAJOR);
 }
 
+unsigned int hlsl_type_minor_size(const struct hlsl_type *type)
+{
+    if (type->type != HLSL_CLASS_MATRIX || hlsl_type_is_row_major(type))
+        return type->dimx;
+    else
+        return type->dimy;
+}
+
+unsigned int hlsl_type_major_size(const struct hlsl_type *type)
+{
+    if (type->type != HLSL_CLASS_MATRIX || hlsl_type_is_row_major(type))
+        return type->dimy;
+    else
+        return type->dimx;
+}
+
 static unsigned int get_array_size(const struct hlsl_type *type)
 {
     if (type->type == HLSL_CLASS_ARRAY)
diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h
index d5cbb560..b82689b0 100644
--- a/libs/vkd3d-shader/hlsl.h
+++ b/libs/vkd3d-shader/hlsl.h
@@ -799,6 +799,8 @@ unsigned int hlsl_type_get_array_element_reg_size(const struct hlsl_type *type);
 unsigned int hlsl_compute_component_offset(struct hlsl_ctx *ctx, struct hlsl_type *type,
         unsigned int idx, struct hlsl_type **comp_type);
 bool hlsl_type_is_row_major(const struct hlsl_type *type);
+unsigned int hlsl_type_minor_size(const struct hlsl_type *type);
+unsigned int hlsl_type_major_size(const struct hlsl_type *type);
 unsigned int hlsl_type_get_sm4_offset(const struct hlsl_type *type, unsigned int offset);
 bool hlsl_types_are_equal(const struct hlsl_type *t1, const struct hlsl_type *t2);
 
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y
index 91b9f9ff..0c5e6aca 100644
--- a/libs/vkd3d-shader/hlsl.y
+++ b/libs/vkd3d-shader/hlsl.y
@@ -1218,22 +1218,6 @@ static bool expr_common_shape(struct hlsl_ctx *ctx, struct hlsl_type *t1, struct
     return true;
 }
 
-static unsigned int minor_size(const struct hlsl_type *type)
-{
-    if (type->modifiers & HLSL_MODIFIER_ROW_MAJOR)
-        return type->dimx;
-    else
-        return type->dimy;
-}
-
-static unsigned int major_size(const struct hlsl_type *type)
-{
-    if (type->modifiers & HLSL_MODIFIER_ROW_MAJOR)
-        return type->dimy;
-    else
-        return type->dimx;
-}
-
 static struct hlsl_ir_node *add_expr(struct hlsl_ctx *ctx, struct list *instrs,
         enum hlsl_ir_expr_op op, struct hlsl_ir_node *operands[HLSL_MAX_OPERANDS],
         struct hlsl_type *type, const struct vkd3d_shader_location *loc)
@@ -1249,7 +1233,7 @@ static struct hlsl_ir_node *add_expr(struct hlsl_ctx *ctx, struct list *instrs,
         struct hlsl_ir_load *load;
         struct hlsl_ir_var *var;
 
-        vector_type = hlsl_get_vector_type(ctx, type->base_type, minor_size(type));
+        vector_type = hlsl_get_vector_type(ctx, type->base_type, hlsl_type_minor_size(type));
 
         name = vkd3d_string_buffer_get(&ctx->string_buffers);
         vkd3d_string_buffer_printf(name, "<split_op-%u>", counter++);
@@ -1258,7 +1242,7 @@ static struct hlsl_ir_node *add_expr(struct hlsl_ctx *ctx, struct list *instrs,
         if (!var)
             return NULL;
 
-        for (i = 0; i < major_size(type); i++)
+        for (i = 0; i < hlsl_type_major_size(type); ++i)
         {
             struct hlsl_ir_node *value, *vector_operands[HLSL_MAX_OPERANDS] = { NULL };
             struct hlsl_ir_store *store;
diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c
index 484b415d..373439af 100644
--- a/libs/vkd3d-shader/hlsl_codegen.c
+++ b/libs/vkd3d-shader/hlsl_codegen.c
@@ -21,22 +21,6 @@
 #include "hlsl.h"
 #include <stdio.h>
 
-static unsigned int minor_size(const struct hlsl_type *type)
-{
-    if (type->modifiers & HLSL_MODIFIER_ROW_MAJOR)
-        return type->dimx;
-    else
-        return type->dimy;
-}
-
-static unsigned int major_size(const struct hlsl_type *type)
-{
-    if (type->modifiers & HLSL_MODIFIER_ROW_MAJOR)
-        return type->dimy;
-    else
-        return type->dimx;
-}
-
 /* Split uniforms into two variables representing the constant and temp
  * registers, and copy the former to the latter, so that writes to uniforms
  * work. */
@@ -86,11 +70,11 @@ static void prepend_input_copy(struct hlsl_ctx *ctx, struct list *instrs, struct
 
     if (type->type == HLSL_CLASS_MATRIX)
     {
-        struct hlsl_type *vector_type = hlsl_get_vector_type(ctx, type->base_type, minor_size(type));
+        struct hlsl_type *vector_type = hlsl_get_vector_type(ctx, type->base_type, hlsl_type_minor_size(type));
         struct hlsl_semantic vector_semantic = *semantic;
         unsigned int i;
 
-        for (i = 0; i < major_size(type); ++i)
+        for (i = 0; i < hlsl_type_major_size(type); ++i)
         {
             prepend_input_copy(ctx, instrs, var, vector_type, 4 * i, modifiers, &vector_semantic);
             ++vector_semantic.index;
@@ -176,11 +160,11 @@ static void append_output_copy(struct hlsl_ctx *ctx, struct list *instrs, struct
 
     if (type->type == HLSL_CLASS_MATRIX)
     {
-        struct hlsl_type *vector_type = hlsl_get_vector_type(ctx, type->base_type, minor_size(type));
+        struct hlsl_type *vector_type = hlsl_get_vector_type(ctx, type->base_type, hlsl_type_minor_size(type));
         struct hlsl_semantic vector_semantic = *semantic;
         unsigned int i;
 
-        for (i = 0; i < major_size(type); ++i)
+        for (i = 0; i < hlsl_type_major_size(type); ++i)
         {
             append_output_copy(ctx, instrs, var, vector_type, 4 * i, modifiers, &vector_semantic);
             ++vector_semantic.index;
@@ -915,7 +899,7 @@ static bool split_matrix_copies(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr
     type = rhs->data_type;
     if (type->type != HLSL_CLASS_MATRIX)
         return false;
-    element_type = hlsl_get_vector_type(ctx, type->base_type, minor_size(type));
+    element_type = hlsl_get_vector_type(ctx, type->base_type, hlsl_type_minor_size(type));
 
     if (rhs->type != HLSL_IR_LOAD)
     {
@@ -923,7 +907,7 @@ static bool split_matrix_copies(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr
         return false;
     }
 
-    for (i = 0; i < major_size(type); ++i)
+    for (i = 0; i < hlsl_type_major_size(type); ++i)
     {
         if (!split_copy(ctx, store, hlsl_ir_load(rhs), 4 * i, element_type))
             return false;




More information about the wine-cvs mailing list