[PATCH vkd3d 09/12] vkd3d-shader/hlsl: Move hlsl_new_offset_from_path_index() to hlsl_codegen.c.
Francisco Casas
fcasas at codeweavers.com
Fri Jul 1 16:24:32 CDT 2022
This can be done now, to help removing register offsets from hlsl.c and
hlsl.h.
Signed-off-by: Francisco Casas <fcasas at codeweavers.com>
---
libs/vkd3d-shader/hlsl.c | 76 -------------------------------
libs/vkd3d-shader/hlsl.h | 3 --
libs/vkd3d-shader/hlsl_codegen.c | 77 ++++++++++++++++++++++++++++++++
3 files changed, 77 insertions(+), 79 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c
index 924121f0..3454e5ee 100644
--- a/libs/vkd3d-shader/hlsl.c
+++ b/libs/vkd3d-shader/hlsl.c
@@ -392,82 +392,6 @@ struct hlsl_type *hlsl_get_type_from_path_index(struct hlsl_ctx *ctx, const stru
return NULL;
}
-struct hlsl_ir_node *hlsl_new_offset_from_path_index(struct hlsl_ctx *ctx, struct hlsl_block *block,
- struct hlsl_type *type, struct hlsl_ir_node *offset, struct hlsl_ir_node *idx,
- const struct vkd3d_shader_location *loc)
-{
- struct hlsl_ir_node *idx_offset = NULL;
- struct hlsl_ir_constant *c;
-
- list_init(&block->instrs);
-
- switch (type->type)
- {
- case HLSL_CLASS_VECTOR:
- {
- idx_offset = idx;
- break;
- }
-
- case HLSL_CLASS_MATRIX:
- {
- if (!(c = hlsl_new_uint_constant(ctx, 4, loc)))
- return NULL;
- list_add_tail(&block->instrs, &c->node.entry);
-
- if (!(idx_offset = hlsl_new_binary_expr(ctx, HLSL_OP2_MUL, &c->node, idx)))
- return NULL;
- list_add_tail(&block->instrs, &idx_offset->entry);
-
- break;
- }
-
- case HLSL_CLASS_ARRAY:
- {
- unsigned int size = hlsl_type_get_array_element_reg_size(type->e.array.type);
-
- if (!(c = hlsl_new_uint_constant(ctx, size, loc)))
- return NULL;
- list_add_tail(&block->instrs, &c->node.entry);
-
- if (!(idx_offset = hlsl_new_binary_expr(ctx, HLSL_OP2_MUL, &c->node, idx)))
- return NULL;
- list_add_tail(&block->instrs, &idx_offset->entry);
-
- break;
- }
-
- case HLSL_CLASS_STRUCT:
- {
- unsigned int field_i = hlsl_ir_constant(idx)->value[0].u;
- struct hlsl_struct_field *field = &type->e.record.fields[field_i];
-
- if (!(c = hlsl_new_uint_constant(ctx, field->reg_offset, loc)))
- return NULL;
- list_add_tail(&block->instrs, &c->node.entry);
-
- idx_offset = &c->node;
-
- break;
- }
-
- default:
- {
- assert(0);
- return NULL;
- }
- }
-
- if (offset)
- {
- if (!(idx_offset = hlsl_new_binary_expr(ctx, HLSL_OP2_ADD, offset, idx_offset)))
- return NULL;
- list_add_tail(&block->instrs, &idx_offset->entry);
- }
-
- return idx_offset;
-}
-
struct hlsl_type *hlsl_new_array_type(struct hlsl_ctx *ctx, struct hlsl_type *basic_type, unsigned int array_size)
{
struct hlsl_type *type;
diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h
index d3885540..dd5ea1d7 100644
--- a/libs/vkd3d-shader/hlsl.h
+++ b/libs/vkd3d-shader/hlsl.h
@@ -737,9 +737,6 @@ struct hlsl_ir_var *hlsl_get_var(struct hlsl_scope *scope, const char *name);
struct hlsl_type *hlsl_get_type_from_path_index(struct hlsl_ctx *ctx, const struct hlsl_type *type,
struct hlsl_ir_node *node);
-struct hlsl_ir_node *hlsl_new_offset_from_path_index(struct hlsl_ctx *ctx, struct hlsl_block *block,
- struct hlsl_type *type, struct hlsl_ir_node *offset, struct hlsl_ir_node *idx,
- const struct vkd3d_shader_location *loc);
struct hlsl_type *hlsl_new_array_type(struct hlsl_ctx *ctx, struct hlsl_type *basic_type, unsigned int array_size);
struct hlsl_ir_node *hlsl_new_binary_expr(struct hlsl_ctx *ctx, enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg1,
diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c
index 513e599e..67229195 100644
--- a/libs/vkd3d-shader/hlsl_codegen.c
+++ b/libs/vkd3d-shader/hlsl_codegen.c
@@ -21,6 +21,83 @@
#include "hlsl.h"
#include <stdio.h>
+/* TODO: remove when no longer needed, only used for replace_deref_path_with_offset() */
+static struct hlsl_ir_node *hlsl_new_offset_from_path_index(struct hlsl_ctx *ctx, struct hlsl_block *block,
+ struct hlsl_type *type, struct hlsl_ir_node *offset, struct hlsl_ir_node *idx,
+ const struct vkd3d_shader_location *loc)
+{
+ struct hlsl_ir_node *idx_offset = NULL;
+ struct hlsl_ir_constant *c;
+
+ list_init(&block->instrs);
+
+ switch (type->type)
+ {
+ case HLSL_CLASS_VECTOR:
+ {
+ idx_offset = idx;
+ break;
+ }
+
+ case HLSL_CLASS_MATRIX:
+ {
+ if (!(c = hlsl_new_uint_constant(ctx, 4, loc)))
+ return NULL;
+ list_add_tail(&block->instrs, &c->node.entry);
+
+ if (!(idx_offset = hlsl_new_binary_expr(ctx, HLSL_OP2_MUL, &c->node, idx)))
+ return NULL;
+ list_add_tail(&block->instrs, &idx_offset->entry);
+
+ break;
+ }
+
+ case HLSL_CLASS_ARRAY:
+ {
+ unsigned int size = hlsl_type_get_array_element_reg_size(type->e.array.type);
+
+ if (!(c = hlsl_new_uint_constant(ctx, size, loc)))
+ return NULL;
+ list_add_tail(&block->instrs, &c->node.entry);
+
+ if (!(idx_offset = hlsl_new_binary_expr(ctx, HLSL_OP2_MUL, &c->node, idx)))
+ return NULL;
+ list_add_tail(&block->instrs, &idx_offset->entry);
+
+ break;
+ }
+
+ case HLSL_CLASS_STRUCT:
+ {
+ unsigned int field_i = hlsl_ir_constant(idx)->value[0].u;
+ struct hlsl_struct_field *field = &type->e.record.fields[field_i];
+
+ if (!(c = hlsl_new_uint_constant(ctx, field->reg_offset, loc)))
+ return NULL;
+ list_add_tail(&block->instrs, &c->node.entry);
+
+ idx_offset = &c->node;
+
+ break;
+ }
+
+ default:
+ {
+ assert(0);
+ return NULL;
+ }
+ }
+
+ if (offset)
+ {
+ if (!(idx_offset = hlsl_new_binary_expr(ctx, HLSL_OP2_ADD, offset, idx_offset)))
+ return NULL;
+ list_add_tail(&block->instrs, &idx_offset->entry);
+ }
+
+ return idx_offset;
+}
+
/* TODO: remove when no longer needed, only used for transform_deref_paths_into_offsets() */
static void replace_deref_path_with_offset(struct hlsl_ctx *ctx, struct hlsl_deref *deref,
struct hlsl_ir_node *instr)
--
2.34.1
More information about the wine-devel
mailing list