[PATCH vkd3d v3 14/17] vkd3d-shader/hlsl: Move register offset functions to hlsl_codegen.c.
Giovanni Mascellani
wine at mascellani.eu
Fri Jul 22 07:36:35 CDT 2022
Signed-off-by: Giovanni Mascellani <gmascellani at codeweavers.com>
Il 20/07/22 15:23, Francisco Casas ha scritto:
> This can be done now, to ensure that register offsets are no longer used
> in hlsl.c and hlsl.h.
>
> Signed-off-by: Francisco Casas <fcasas at codeweavers.com>
> ---
>
> v3:
> * No changes.
>
> Signed-off-by: Francisco Casas <fcasas at codeweavers.com>
> ---
> libs/vkd3d-shader/hlsl.c | 103 -------------------------------
> libs/vkd3d-shader/hlsl.h | 6 --
> libs/vkd3d-shader/hlsl_codegen.c | 103 ++++++++++++++++++++++++++++++-
> 3 files changed, 102 insertions(+), 110 deletions(-)
>
> diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c
> index a4d594b7..20dcd9af 100644
> --- a/libs/vkd3d-shader/hlsl.c
> +++ b/libs/vkd3d-shader/hlsl.c
> @@ -452,109 +452,6 @@ struct hlsl_type *hlsl_get_type_from_path_index(struct hlsl_ctx *ctx, const stru
> }
> }
>
> -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_ir_node *hlsl_new_offset_node_from_deref(struct hlsl_ctx *ctx, struct hlsl_block *block,
> - const struct hlsl_deref *deref, const struct vkd3d_shader_location *loc)
> -{
> - struct hlsl_ir_node *offset = NULL;
> - struct hlsl_type *type;
> - unsigned int i;
> -
> - list_init(&block->instrs);
> -
> - if (deref->offset.node)
> - return deref->offset.node;
> -
> - assert(deref->var);
> -
> - type = deref->var->data_type;
> -
> - for (i = 0; i < deref->path_len; ++i)
> - {
> - struct hlsl_block idx_block;
> -
> - if (!(offset = hlsl_new_offset_from_path_index(ctx, &idx_block, type, offset, deref->path[i].node, loc)))
> - return NULL;
> -
> - list_move_tail(&block->instrs, &idx_block.instrs);
> -
> - type = hlsl_get_type_from_path_index(ctx, type, deref->path[i].node);
> - }
> -
> - return 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 f54b7cb7..e1ddd0cf 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,
> @@ -773,9 +770,6 @@ struct hlsl_ir_store *hlsl_new_store_index(struct hlsl_ctx *ctx, const struct hl
> struct hlsl_ir_store *hlsl_new_store_component(struct hlsl_ctx *ctx, struct hlsl_block *block,
> const struct hlsl_deref *lhs, unsigned int comp, struct hlsl_ir_node *rhs);
>
> -struct hlsl_ir_node *hlsl_new_offset_node_from_deref(struct hlsl_ctx *ctx, struct hlsl_block *block,
> - const struct hlsl_deref *deref, const struct vkd3d_shader_location *loc);
> -
> struct hlsl_ir_resource_load *hlsl_new_resource_load(struct hlsl_ctx *ctx, struct hlsl_type *data_type,
> enum hlsl_resource_load_type type, struct hlsl_deref *resource, struct hlsl_deref *sampler,
> struct hlsl_ir_node *coords, struct hlsl_ir_node *texel_offset, const struct vkd3d_shader_location *loc);
> diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c
> index 483ee9e1..e10377cb 100644
> --- a/libs/vkd3d-shader/hlsl_codegen.c
> +++ b/libs/vkd3d-shader/hlsl_codegen.c
> @@ -21,6 +21,107 @@
> #include "hlsl.h"
> #include <stdio.h>
>
> +/* TODO: remove when no longer needed, only used for new_offset_node_from_deref() */
> +static struct hlsl_ir_node *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 replace_deref_path_with_offset() */
> +static struct hlsl_ir_node *new_offset_node_from_deref(struct hlsl_ctx *ctx, struct hlsl_block *block,
> + const struct hlsl_deref *deref, const struct vkd3d_shader_location *loc)
> +{
> + struct hlsl_ir_node *offset = NULL;
> + struct hlsl_type *type;
> + unsigned int i;
> +
> + list_init(&block->instrs);
> +
> + assert(deref->var);
> + type = deref->var->data_type;
> +
> + for (i = 0; i < deref->path_len; ++i)
> + {
> + struct hlsl_block idx_block;
> +
> + if (!(offset = new_offset_from_path_index(ctx, &idx_block, type, offset, deref->path[i].node, loc)))
> + return NULL;
> +
> + list_move_tail(&block->instrs, &idx_block.instrs);
> +
> + type = hlsl_get_type_from_path_index(ctx, type, deref->path[i].node);
> + }
> +
> + return 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)
> @@ -34,7 +135,7 @@ static void replace_deref_path_with_offset(struct hlsl_ctx *ctx, struct hlsl_der
> /* register offsets shouldn't be used before this point is reached. */
> assert(!deref->offset.node);
>
> - if (!(offset = hlsl_new_offset_node_from_deref(ctx, &block, deref, &instr->loc)))
> + if (!(offset = new_offset_node_from_deref(ctx, &block, deref, &instr->loc)))
> return;
> list_move_before(&instr->entry, &block.instrs);
>
More information about the wine-devel
mailing list