[PATCH vkd3d 08/12] vkd3d-shader/hlsl: Parse matrix constructors.

Francisco Casas fcasas at codeweavers.com
Tue Apr 19 12:05:52 CDT 2022


Signed-off-by: Francisco Casas <fcasas at codeweavers.com>

April 18, 2022 2:34 AM, "Giovanni Mascellani" <gmascellani at codeweavers.com> wrote:

> Signed-off-by: Giovanni Mascellani <gmascellani at codeweavers.com>
> ---
> libs/vkd3d-shader/hlsl.y | 98 ++++++++++++++++---
> tests/hlsl-matrix-indexing.shader_test | 14 +++
> ...lsl-return-implicit-conversion.shader_test | 8 +-
> 3 files changed, 100 insertions(+), 20 deletions(-)
> 
> diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y
> index b6a8e496..1ee1db4c 100644
> --- a/libs/vkd3d-shader/hlsl.y
> +++ b/libs/vkd3d-shader/hlsl.y
> @@ -2081,18 +2081,87 @@ static struct list *add_call(struct hlsl_ctx *ctx, const char *name,
> return params->instrs;
> }
> 
> +static struct hlsl_ir_node *compute_offset_from_index(struct hlsl_ctx *ctx, struct list *instrs,
> + struct hlsl_type *type, unsigned int idx, const struct vkd3d_shader_location *loc)
> +{
> + assert(type->type <= HLSL_CLASS_LAST_NUMERIC);
> + assert(idx < type->dimx * type->dimy);
> +
> + if (type->type == HLSL_CLASS_SCALAR || type->type == HLSL_CLASS_VECTOR)
> + {
> + struct hlsl_ir_constant *c;
> +
> + if (!(c = hlsl_new_uint_constant(ctx, idx, loc)))
> + return NULL;
> + list_add_tail(instrs, &c->node.entry);
> +
> + return &c->node;
> + }
> + else
> + {
> + struct hlsl_ir_constant *x, *y;
> +
> + if (!(x = hlsl_new_uint_constant(ctx, idx % type->dimx, loc)))
> + return NULL;
> + list_add_tail(instrs, &x->node.entry);
> +
> + if (!(y = hlsl_new_uint_constant(ctx, idx / type->dimx, loc)))
> + return NULL;
> + list_add_tail(instrs, &y->node.entry);
> +
> + return compute_matrix_offset(ctx, instrs, type, &x->node, &y->node, loc);
> + }
> +}
> +
> +static struct hlsl_ir_node *load_index(struct hlsl_ctx *ctx, struct list *instrs, struct
> hlsl_ir_node *instr,
> + unsigned int idx, const struct vkd3d_shader_location *loc)
> +{
> + struct hlsl_type *scal_type = hlsl_get_scalar_type(ctx, instr->data_type->base_type);
> + struct hlsl_ir_node *offset;
> + struct hlsl_ir_load *load;
> +
> + if (instr->data_type->type > HLSL_CLASS_LAST_NUMERIC)
> + {
> + hlsl_fixme(ctx, loc, "Loading from non-numeric type.");
> + return NULL;
> + }
> +
> + if (!(offset = compute_offset_from_index(ctx, instrs, instr->data_type, idx, loc)))
> + return NULL;
> +
> + if (!(load = add_load(ctx, instrs, instr, offset, scal_type, *loc)))
> + return NULL;
> +
> + return &load->node;
> +}
> +
> +static struct hlsl_ir_node *store_index(struct hlsl_ctx *ctx, struct list *instrs, struct
> hlsl_ir_var *var,
> + struct hlsl_ir_node *rhs, unsigned int idx, const struct vkd3d_shader_location *loc)
> +{
> + struct hlsl_ir_node *offset;
> + struct hlsl_ir_store *store;
> +
> + if (!(offset = compute_offset_from_index(ctx, instrs, var->data_type, idx, loc)))
> + return NULL;
> +
> + if (!(store = hlsl_new_store(ctx, var, offset, rhs, 0, *loc)))
> + return NULL;
> + list_add_tail(instrs, &store->node.entry);
> +
> + return &store->node;
> +}
> +
> static struct list *add_constructor(struct hlsl_ctx *ctx, struct hlsl_type *type,
> struct parse_initializer *params, struct vkd3d_shader_location loc)
> {
> - unsigned int i, writemask_offset = 0;
> - struct hlsl_ir_store *store;
> static unsigned int counter;
> + struct hlsl_type *scal_type;
> + unsigned int i, j, idx = 0;
> struct hlsl_ir_load *load;
> struct hlsl_ir_var *var;
> char name[23];
> 
> - if (type->type == HLSL_CLASS_MATRIX)
> - hlsl_fixme(ctx, &loc, "Matrix constructor.");
> + scal_type = hlsl_get_scalar_type(ctx, type->base_type);
> 
> sprintf(name, "<constructor-%x>", counter++);
> if (!(var = hlsl_new_synthetic_var(ctx, name, type, loc)))
> @@ -2115,22 +2184,19 @@ static struct list *add_constructor(struct hlsl_ctx *ctx, struct hlsl_type
> *type
> }
> width = hlsl_type_component_count(arg->data_type);
> 
> - if (width > 4)
> + for (j = 0; j < width; ++j, ++idx)
> {
> - FIXME("Constructor argument with %u components.\n", width);
> - continue;
> - }
> + struct hlsl_ir_node *value;
> 
> - if (!(arg = add_implicit_conversion(ctx, params->instrs, arg,
> - hlsl_get_vector_type(ctx, type->base_type, width), &arg->loc)))
> - continue;
> + if (!(value = load_index(ctx, params->instrs, arg, j, &loc)))
> + return NULL;
> 
> - if (!(store = hlsl_new_store(ctx, var, NULL, arg,
> - ((1u << width) - 1) << writemask_offset, arg->loc)))
> - return NULL;
> - list_add_tail(params->instrs, &store->node.entry);
> + if (!(value = add_implicit_conversion(ctx, params->instrs, value, scal_type, &arg->loc)))
> + return NULL;
> 
> - writemask_offset += width;
> + if (!store_index(ctx, params->instrs, var, value, idx, &loc))
> + return NULL;
> + }
> }
> 
> if (!(load = hlsl_new_var_load(ctx, var, loc)))
> diff --git a/tests/hlsl-matrix-indexing.shader_test b/tests/hlsl-matrix-indexing.shader_test
> index 3f4b878f..3cef127a 100644
> --- a/tests/hlsl-matrix-indexing.shader_test
> +++ b/tests/hlsl-matrix-indexing.shader_test
> @@ -62,3 +62,17 @@ uniform 8 float4 9.0 10.0 11.0 12.0
> uniform 12 float4 13.0 14.0 15.0 16.0
> draw quad
> probe all rgba (1.0, 2.0, 10.0, 15.0)
> +
> +[pixel shader]
> +float4 main() : SV_TARGET
> +{
> + float4x4 m = float4x4(1.0, 2.0, 3.0, 4.0,
> + 5.0, 6.0, 7.0, 8.0,
> + 9.0, 10.0, 11.0, 12.0,
> + 13.0, 14.0, 15.0, 16.0);
> + return float4(m[0][0], m[1][0], m[1][2], m[2][3]);
> +}
> +
> +[test]
> +todo draw quad
> +probe all rgba (1.0, 5.0, 7.0, 12.0)
> diff --git a/tests/hlsl-return-implicit-conversion.shader_test
> b/tests/hlsl-return-implicit-conversion.shader_test
> index 38d21633..bf99d9cb 100644
> --- a/tests/hlsl-return-implicit-conversion.shader_test
> +++ b/tests/hlsl-return-implicit-conversion.shader_test
> @@ -98,7 +98,7 @@ float4 main() : sv_target
> todo draw quad
> probe all rgba (0.4, 0.3, 0.2, 0.0)
> 
> -[pixel shader fail todo]
> +[pixel shader fail]
> float3x1 func()
> {
> return float1x3(0.4, 0.3, 0.2);
> @@ -109,7 +109,7 @@ float4 main() : sv_target
> return float4(func(), 0.0);
> }
> 
> -[pixel shader fail todo]
> +[pixel shader fail]
> float1x3 func()
> {
> return float3x1(0.4, 0.3, 0.2);
> @@ -191,7 +191,7 @@ float4 main() : sv_target
> todo draw quad
> probe all rgba (0.4, 0.3, 0.2, 0.0)
> 
> -[pixel shader fail todo]
> +[pixel shader fail]
> float3x1 func()
> {
> return float1x4(0.4, 0.3, 0.2, 0.1);
> @@ -217,7 +217,7 @@ float4 main() : sv_target
> todo draw quad
> probe all rgba (0.4, 0.3, 0.2, 0.0)
> 
> -[pixel shader fail todo]
> +[pixel shader fail]
> float1x3 func()
> {
> return float4x1(0.4, 0.3, 0.2, 0.1);
> -- 
> 2.35.2



More information about the wine-devel mailing list