Francisco Casas : vkd3d-shader/hlsl: Move register offset functions to hlsl_codegen.c.
Alexandre Julliard
julliard at winehq.org
Wed Aug 10 14:45:26 CDT 2022
Module: vkd3d
Branch: master
Commit: c572adbf2a46d904e2b8ecaba9c497f5eb50a7c7
URL: https://gitlab.winehq.org/wine/vkd3d/-/commit/c572adbf2a46d904e2b8ecaba9c497f5eb50a7c7
Author: Francisco Casas <fcasas at codeweavers.com>
Date: Fri Jul 1 12:36:25 2022 -0400
vkd3d-shader/hlsl: Move register offset functions to hlsl_codegen.c.
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>
Signed-off-by: Giovanni Mascellani <gmascellani 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 bf74131a..4a469d40 100644
--- a/libs/vkd3d-shader/hlsl.c
+++ b/libs/vkd3d-shader/hlsl.c
@@ -456,109 +456,6 @@ struct hlsl_type *hlsl_get_inner_type_from_path_index(struct hlsl_ctx *ctx, cons
}
}
-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_idx = hlsl_ir_constant(idx)->value[0].u;
- struct hlsl_struct_field *field = &type->e.record.fields[field_idx];
-
- 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_instr_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_inner_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 2af22c03..0c684ae9 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_inner_type_from_path_index(struct hlsl_ctx *ctx, const struct hlsl_type *type,
struct hlsl_ir_node *idx);
-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_instr_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 45012333..fdccd2c7 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_instr_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_idx = hlsl_ir_constant(idx)->value[0].u;
+ struct hlsl_struct_field *field = &type->e.record.fields[field_idx];
+
+ 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_instr_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_inner_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_instr_from_deref(ctx, &block, deref, &instr->loc)))
+ if (!(offset = new_offset_instr_from_deref(ctx, &block, deref, &instr->loc)))
return;
list_move_before(&instr->entry, &block.instrs);
More information about the wine-cvs
mailing list