From fafe2a1dbadefd5a8a88e89ca3e5d5f49bcb057b Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Wed, 6 Dec 2023 18:20:25 +0100 Subject: [PATCH] vkd3d-shader/hlsl: Store swizzles as a uint32_t. --- libs/vkd3d-shader/hlsl.c | 16 +++++++++------- libs/vkd3d-shader/hlsl.h | 12 ++++++------ libs/vkd3d-shader/hlsl.y | 5 +++-- libs/vkd3d-shader/hlsl_codegen.c | 10 +++++----- 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index da3bbda1..d40a8e67 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -1505,7 +1505,7 @@ struct hlsl_ir_node *hlsl_new_resource_store(struct hlsl_ctx *ctx, const struct return &store->node; } -struct hlsl_ir_node *hlsl_new_swizzle(struct hlsl_ctx *ctx, DWORD s, unsigned int components, +struct hlsl_ir_node *hlsl_new_swizzle(struct hlsl_ctx *ctx, uint32_t s, unsigned int components, struct hlsl_ir_node *val, const struct vkd3d_shader_location *loc) { struct hlsl_ir_swizzle *swizzle; @@ -2432,7 +2432,7 @@ const char *debug_hlsl_writemask(unsigned int writemask) return vkd3d_dbg_sprintf(".%s", string); } -const char *debug_hlsl_swizzle(unsigned int swizzle, unsigned int size) +const char *debug_hlsl_swizzle(uint32_t swizzle, unsigned int size) { static const char components[] = {'x', 'y', 'z', 'w'}; char string[5]; @@ -3147,9 +3147,10 @@ void hlsl_add_function(struct hlsl_ctx *ctx, char *name, struct hlsl_ir_function rb_put(&ctx->functions, func->name, &func->entry); } -unsigned int hlsl_map_swizzle(unsigned int swizzle, unsigned int writemask) +uint32_t hlsl_map_swizzle(uint32_t swizzle, unsigned int writemask) { - unsigned int i, ret = 0; + uint32_t ret = 0; + unsigned int i; /* Leave replicate swizzles alone; some instructions need them. */ if (swizzle == HLSL_SWIZZLE(X, X, X, X) @@ -3169,7 +3170,7 @@ unsigned int hlsl_map_swizzle(unsigned int swizzle, unsigned int writemask) return ret; } -unsigned int hlsl_swizzle_from_writemask(unsigned int writemask) +uint32_t hlsl_swizzle_from_writemask(unsigned int writemask) { static const unsigned int swizzles[16] = { @@ -3210,9 +3211,10 @@ unsigned int hlsl_combine_writemasks(unsigned int first, unsigned int second) return ret; } -unsigned int hlsl_combine_swizzles(unsigned int first, unsigned int second, unsigned int dim) +uint32_t hlsl_combine_swizzles(uint32_t first, uint32_t second, unsigned int dim) { - unsigned int ret = 0, i; + uint32_t ret = 0; + unsigned int i; for (i = 0; i < dim; ++i) { unsigned int s = hlsl_swizzle_get_component(second, i); diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 21b2fe38..8c64f0c9 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -65,7 +65,7 @@ #define HLSL_SWIZZLE_MASK (0x3u) #define HLSL_SWIZZLE_SHIFT(idx) (2u * (idx)) -static inline unsigned int hlsl_swizzle_get_component(unsigned int swizzle, unsigned int idx) +static inline unsigned int hlsl_swizzle_get_component(uint32_t swizzle, unsigned int idx) { return (swizzle >> HLSL_SWIZZLE_SHIFT(idx)) & HLSL_SWIZZLE_MASK; } @@ -622,7 +622,7 @@ struct hlsl_ir_swizzle { struct hlsl_ir_node node; struct hlsl_src val; - DWORD swizzle; + uint32_t swizzle; }; struct hlsl_ir_index @@ -1250,7 +1250,7 @@ struct hlsl_ir_node *hlsl_new_resource_store(struct hlsl_ctx *ctx, const struct struct hlsl_ir_node *coords, struct hlsl_ir_node *value, const struct vkd3d_shader_location *loc); struct hlsl_type *hlsl_new_struct_type(struct hlsl_ctx *ctx, const char *name, struct hlsl_struct_field *fields, size_t field_count); -struct hlsl_ir_node *hlsl_new_swizzle(struct hlsl_ctx *ctx, DWORD s, unsigned int components, +struct hlsl_ir_node *hlsl_new_swizzle(struct hlsl_ctx *ctx, uint32_t s, unsigned int components, struct hlsl_ir_node *val, const struct vkd3d_shader_location *loc); struct hlsl_ir_var *hlsl_new_synthetic_var(struct hlsl_ctx *ctx, const char *template, struct hlsl_type *type, const struct vkd3d_shader_location *loc); @@ -1304,10 +1304,10 @@ bool hlsl_types_are_equal(const struct hlsl_type *t1, const struct hlsl_type *t2 const struct hlsl_type *hlsl_get_multiarray_element_type(const struct hlsl_type *type); unsigned int hlsl_get_multiarray_size(const struct hlsl_type *type); -unsigned int hlsl_combine_swizzles(unsigned int first, unsigned int second, unsigned int dim); +uint32_t hlsl_combine_swizzles(uint32_t first, uint32_t second, unsigned int dim); unsigned int hlsl_combine_writemasks(unsigned int first, unsigned int second); -unsigned int hlsl_map_swizzle(unsigned int swizzle, unsigned int writemask); -unsigned int hlsl_swizzle_from_writemask(unsigned int writemask); +uint32_t hlsl_map_swizzle(uint32_t swizzle, unsigned int writemask); +uint32_t hlsl_swizzle_from_writemask(unsigned int writemask); struct hlsl_type *hlsl_deref_get_type(struct hlsl_ctx *ctx, const struct hlsl_deref *deref); enum hlsl_regset hlsl_deref_get_regset(struct hlsl_ctx *ctx, const struct hlsl_deref *deref); diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index ed053f16..a9959c63 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -1717,7 +1717,7 @@ static enum hlsl_ir_expr_op op_from_assignment(enum parse_assign_op op) return ops[op]; } -static bool invert_swizzle(unsigned int *swizzle, unsigned int *writemask, unsigned int *ret_width) +static bool invert_swizzle(uint32_t *swizzle, unsigned int *writemask, unsigned int *ret_width) { unsigned int i, j, bit = 0, inverted = 0, width, new_writemask = 0, new_swizzle = 0; @@ -1791,8 +1791,9 @@ static struct hlsl_ir_node *add_assignment(struct hlsl_ctx *ctx, struct hlsl_blo else if (lhs->type == HLSL_IR_SWIZZLE) { struct hlsl_ir_swizzle *swizzle = hlsl_ir_swizzle(lhs); - unsigned int width, s = swizzle->swizzle; struct hlsl_ir_node *new_swizzle; + uint32_t s = swizzle->swizzle; + unsigned int width; if (lhs->data_type->class == HLSL_CLASS_MATRIX) hlsl_fixme(ctx, &lhs->loc, "Matrix assignment with a writemask."); diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index 88cbef61..f161f248 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -1519,7 +1519,7 @@ static void copy_propagation_set_value(struct hlsl_ctx *ctx, struct copy_propaga static bool copy_propagation_replace_with_single_instr(struct hlsl_ctx *ctx, const struct copy_propagation_state *state, const struct hlsl_ir_load *load, - unsigned int swizzle, struct hlsl_ir_node *instr) + uint32_t swizzle, struct hlsl_ir_node *instr) { const unsigned int instr_component_count = hlsl_type_component_count(instr->data_type); const struct hlsl_deref *deref = &load->src; @@ -1527,7 +1527,7 @@ static bool copy_propagation_replace_with_single_instr(struct hlsl_ctx *ctx, struct hlsl_ir_node *new_instr = NULL; unsigned int time = load->node.index; unsigned int start, count, i; - unsigned int ret_swizzle = 0; + uint32_t ret_swizzle = 0; if (!hlsl_component_index_range_from_deref(ctx, deref, &start, &count)) return false; @@ -1573,7 +1573,7 @@ static bool copy_propagation_replace_with_single_instr(struct hlsl_ctx *ctx, static bool copy_propagation_replace_with_constant_vector(struct hlsl_ctx *ctx, const struct copy_propagation_state *state, const struct hlsl_ir_load *load, - unsigned int swizzle, struct hlsl_ir_node *instr) + uint32_t swizzle, struct hlsl_ir_node *instr) { const unsigned int instr_component_count = hlsl_type_component_count(instr->data_type); const struct hlsl_deref *deref = &load->src; @@ -2239,7 +2239,7 @@ static bool fold_swizzle_chains(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr if (next_instr->type == HLSL_IR_SWIZZLE) { struct hlsl_ir_node *new_swizzle; - unsigned int combined_swizzle; + uint32_t combined_swizzle; combined_swizzle = hlsl_combine_swizzles(hlsl_ir_swizzle(next_instr)->swizzle, swizzle->swizzle, instr->data_type->dimx); @@ -3145,7 +3145,7 @@ static bool lower_int_dot(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, stru for (i = 0; i < dimx; ++i) { - unsigned int s = hlsl_swizzle_from_writemask(1 << i); + uint32_t s = hlsl_swizzle_from_writemask(1 << i); if (!(comps[i] = hlsl_new_swizzle(ctx, s, 1, mult, &instr->loc))) return false;