From: Francisco Casas fcasas@codeweavers.com
Some functions work with dereferences and need to know if they are lowered yet.
This can be known checking if deref->offset.node is NULL or deref->data_type is NULL. I am using the latter since it keeps working even after the following patches that split deref->offset into constant and variable parts. --- libs/vkd3d-shader/hlsl.c | 20 +++++++------------- libs/vkd3d-shader/hlsl.h | 8 +++++++- libs/vkd3d-shader/hlsl_codegen.c | 4 +--- 3 files changed, 15 insertions(+), 17 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 0bfba35f4..ae5a388cd 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -249,14 +249,7 @@ static enum hlsl_regset type_get_regset(const struct hlsl_type *type)
enum hlsl_regset hlsl_deref_get_regset(struct hlsl_ctx *ctx, const struct hlsl_deref *deref) { - struct hlsl_type *type; - - if (deref->data_type) - type = deref->data_type; - else - type = hlsl_deref_get_type(ctx, deref); - - return type_get_regset(type); + return type_get_regset(hlsl_deref_get_type(ctx, deref)); }
unsigned int hlsl_type_get_sm4_offset(const struct hlsl_type *type, unsigned int offset) @@ -520,6 +513,7 @@ static bool init_deref(struct hlsl_ctx *ctx, struct hlsl_deref *deref, struct hl deref->var = var; deref->path_len = path_len; deref->offset.node = NULL; + deref->data_type = NULL;
if (path_len == 0) { @@ -609,7 +603,7 @@ struct hlsl_type *hlsl_deref_get_type(struct hlsl_ctx *ctx, const struct hlsl_de
assert(deref);
- if (deref->offset.node) + if (hlsl_deref_is_lowered(deref)) return deref->data_type;
type = deref->var->data_type; @@ -1120,7 +1114,7 @@ bool hlsl_copy_deref(struct hlsl_ctx *ctx, struct hlsl_deref *deref, const struc if (!other) return true;
- assert(!other->offset.node); + assert(!hlsl_deref_is_lowered(other));
if (!init_deref(ctx, deref, other->var, other->path_len)) return false; @@ -1177,7 +1171,7 @@ struct hlsl_ir_node *hlsl_new_store_index(struct hlsl_ctx *ctx, const struct hls unsigned int i;
assert(lhs); - assert(!lhs->offset.node); + assert(!hlsl_deref_is_lowered(lhs));
if (!(store = hlsl_alloc(ctx, sizeof(*store)))) return NULL; @@ -1350,7 +1344,7 @@ struct hlsl_ir_load *hlsl_new_load_index(struct hlsl_ctx *ctx, const struct hlsl struct hlsl_type *type; unsigned int i;
- assert(!deref->offset.node); + assert(!hlsl_deref_is_lowered(deref));
type = hlsl_deref_get_type(ctx, deref); if (idx) @@ -1623,7 +1617,7 @@ static bool clone_deref(struct hlsl_ctx *ctx, struct clone_instr_map *map, { unsigned int i;
- assert(!src->offset.node); + assert(!hlsl_deref_is_lowered(src));
if (!init_deref(ctx, dst, src->var, src->path_len)) return false; diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index e45256bce..9c3e16750 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -621,11 +621,17 @@ struct hlsl_deref * The path is lowered to this single offset -- whose value may vary between SM1 and SM4 -- * before writing the bytecode. * Since the type information cannot longer be retrieved from the offset alone, the type is - * stored in the data_type field. */ + * stored in the data_type field, which remains NULL if the deref hasn't been lowered yet. */ struct hlsl_src offset; struct hlsl_type *data_type; };
+/* Whether the path has been lowered to an offset or not. */ +static inline bool hlsl_deref_is_lowered(const struct hlsl_deref *deref) +{ + return !!deref->data_type; +} + struct hlsl_ir_load { struct hlsl_ir_node node; diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index 3c80e8fc7..4787833a9 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -135,9 +135,7 @@ static bool replace_deref_path_with_offset(struct hlsl_ctx *ctx, struct hlsl_der struct hlsl_block block;
assert(deref->var); - - /* register offsets shouldn't be used before this point is reached. */ - assert(!deref->offset.node); + assert(!hlsl_deref_is_lowered(deref));
type = hlsl_deref_get_type(ctx, deref);