This can be done now, to help removing register offsets from hlsl.c and hlsl.h.
Signed-off-by: Francisco Casas fcasas@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)
On 7/1/22 16:24, Francisco Casas wrote:
This can be done now, to help removing register offsets from hlsl.c and hlsl.h.
Signed-off-by: Francisco Casas fcasas@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(-)
Is this going to be removed eventually? Or used from hlsl_sm1 and hlsl_sm4? In either case there doesn't seem to be a point in moving it.
On 08-07-22 17:28, Zebediah Figura wrote:
On 7/1/22 16:24, Francisco Casas wrote:
This can be done now, to help removing register offsets from hlsl.c and hlsl.h.
Signed-off-by: Francisco Casas fcasas@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(-)
Is this going to be removed eventually? Or used from hlsl_sm1 and hlsl_sm4? In either case there doesn't seem to be a point in moving it.
From this point this function is no longer used (and shall no longer be used) anywhere except for the "transform_deref_paths_into_offsets" pass. This is because it mixes index paths and register offsets, and we shouldn't be doing that anywhere else.
Moving it and making it static seemed like a good way to enforce that this transitional code is not misused somewhere else, and to clean hlsl.c and hlsl.h.
I can remove this patch from the batch if you prefer not to move the function.
Il 08/07/22 23:28, Zebediah Figura ha scritto:
Is this going to be removed eventually? Or used from hlsl_sm1 and hlsl_sm4? In either case there doesn't seem to be a point in moving it.
Isn't the point of the whole patch set to make so that each backend can customize the mapping path index -> register offset without letting the common code know? So what I would expect is that reg_offset will be removed and each backend will have its private version of hlsl_new_offset_from_path_index().
Giovanni.
On 7/14/22 06:24, Giovanni Mascellani wrote:
Il 08/07/22 23:28, Zebediah Figura ha scritto:
Is this going to be removed eventually? Or used from hlsl_sm1 and hlsl_sm4? In either case there doesn't seem to be a point in moving it.
Isn't the point of the whole patch set to make so that each backend can customize the mapping path index -> register offset without letting the common code know? So what I would expect is that reg_offset will be removed and each backend will have its private version of hlsl_new_offset_from_path_index().
That's what I would have expected a priori, yes.
On 14-07-22 14:54, Zebediah Figura wrote:
On 7/14/22 06:24, Giovanni Mascellani wrote:
Il 08/07/22 23:28, Zebediah Figura ha scritto:
Is this going to be removed eventually? Or used from hlsl_sm1 and hlsl_sm4? In either case there doesn't seem to be a point in moving it.
Isn't the point of the whole patch set to make so that each backend can customize the mapping path index -> register offset without letting the common code know? So what I would expect is that reg_offset will be removed and each backend will have its private version of hlsl_new_offset_from_path_index().
That's what I would have expected a priori, yes.
Yep, but first we have to translate all compilation passes to index paths, until transform_deref_paths_into_offsets() is no longer necessary in hlsl_codegen.c.