mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2024-11-21 16:46:41 -08:00
vkd3d-shader/hlsl: Handle complex types in add_cast().
This extends the support of this function, whether doing broadcasts or component-wise casts, to struct and array types.
This commit is contained in:
parent
fb751b48c5
commit
d93ce28995
Notes:
Alexandre Julliard
2022-10-25 22:39:01 +02:00
Approved-by: Giovanni Mascellani (@giomasce) Approved-by: Zebediah Figura (@zfigura) Approved-by: Henri Verbeet (@hverbeet) Approved-by: Alexandre Julliard (@julliard) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/35
@ -284,18 +284,21 @@ static struct hlsl_ir_node *add_cast(struct hlsl_ctx *ctx, struct list *instrs,
|
|||||||
if (hlsl_types_are_equal(src_type, dst_type))
|
if (hlsl_types_are_equal(src_type, dst_type))
|
||||||
return node;
|
return node;
|
||||||
|
|
||||||
if ((src_type->type == HLSL_CLASS_MATRIX || dst_type->type == HLSL_CLASS_MATRIX)
|
if (src_type->type > HLSL_CLASS_VECTOR || dst_type->type > HLSL_CLASS_VECTOR)
|
||||||
&& src_type->type <= HLSL_CLASS_LAST_NUMERIC && dst_type->type <= HLSL_CLASS_LAST_NUMERIC)
|
|
||||||
{
|
{
|
||||||
|
unsigned int src_comp_count = hlsl_type_component_count(src_type);
|
||||||
|
unsigned int dst_comp_count = hlsl_type_component_count(dst_type);
|
||||||
struct hlsl_deref var_deref;
|
struct hlsl_deref var_deref;
|
||||||
|
bool broadcast, matrix_cast;
|
||||||
struct hlsl_ir_load *load;
|
struct hlsl_ir_load *load;
|
||||||
struct hlsl_ir_var *var;
|
struct hlsl_ir_var *var;
|
||||||
unsigned int dst_idx;
|
unsigned int dst_idx;
|
||||||
bool broadcast;
|
|
||||||
|
|
||||||
broadcast = src_type->dimx == 1 && src_type->dimy == 1;
|
broadcast = src_type->type <= HLSL_CLASS_LAST_NUMERIC && src_type->dimx == 1 && src_type->dimy == 1;
|
||||||
assert(dst_type->dimx * dst_type->dimy <= src_type->dimx * src_type->dimy || broadcast);
|
matrix_cast = !broadcast && dst_comp_count != src_comp_count
|
||||||
if (src_type->type == HLSL_CLASS_MATRIX && dst_type->type == HLSL_CLASS_MATRIX && !broadcast)
|
&& src_type->type == HLSL_CLASS_MATRIX && dst_type->type == HLSL_CLASS_MATRIX;
|
||||||
|
assert(src_comp_count >= dst_comp_count || broadcast);
|
||||||
|
if (matrix_cast)
|
||||||
{
|
{
|
||||||
assert(dst_type->dimx <= src_type->dimx);
|
assert(dst_type->dimx <= src_type->dimx);
|
||||||
assert(dst_type->dimy <= src_type->dimy);
|
assert(dst_type->dimy <= src_type->dimy);
|
||||||
@ -305,9 +308,9 @@ static struct hlsl_ir_node *add_cast(struct hlsl_ctx *ctx, struct list *instrs,
|
|||||||
return NULL;
|
return NULL;
|
||||||
hlsl_init_simple_deref_from_var(&var_deref, var);
|
hlsl_init_simple_deref_from_var(&var_deref, var);
|
||||||
|
|
||||||
for (dst_idx = 0; dst_idx < dst_type->dimx * dst_type->dimy; ++dst_idx)
|
for (dst_idx = 0; dst_idx < dst_comp_count; ++dst_idx)
|
||||||
{
|
{
|
||||||
struct hlsl_type *dst_scalar_type;
|
struct hlsl_type *dst_comp_type;
|
||||||
struct hlsl_ir_store *store;
|
struct hlsl_ir_store *store;
|
||||||
struct hlsl_block block;
|
struct hlsl_block block;
|
||||||
unsigned int src_idx;
|
unsigned int src_idx;
|
||||||
@ -316,26 +319,23 @@ static struct hlsl_ir_node *add_cast(struct hlsl_ctx *ctx, struct list *instrs,
|
|||||||
{
|
{
|
||||||
src_idx = 0;
|
src_idx = 0;
|
||||||
}
|
}
|
||||||
|
else if (matrix_cast)
|
||||||
|
{
|
||||||
|
unsigned int x = dst_idx % dst_type->dimx, y = dst_idx / dst_type->dimx;
|
||||||
|
|
||||||
|
src_idx = y * src_type->dimx + x;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (src_type->type == HLSL_CLASS_MATRIX && dst_type->type == HLSL_CLASS_MATRIX)
|
src_idx = dst_idx;
|
||||||
{
|
|
||||||
unsigned int x = dst_idx % dst_type->dimx, y = dst_idx / dst_type->dimx;
|
|
||||||
|
|
||||||
src_idx = y * src_type->dimx + x;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
src_idx = dst_idx;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dst_scalar_type = hlsl_type_get_component_type(ctx, dst_type, dst_idx);
|
dst_comp_type = hlsl_type_get_component_type(ctx, dst_type, dst_idx);
|
||||||
|
|
||||||
if (!(load = add_load_component(ctx, instrs, node, src_idx, loc)))
|
if (!(load = add_load_component(ctx, instrs, node, src_idx, loc)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (!(cast = hlsl_new_cast(ctx, &load->node, dst_scalar_type, loc)))
|
if (!(cast = hlsl_new_cast(ctx, &load->node, dst_comp_type, loc)))
|
||||||
return NULL;
|
return NULL;
|
||||||
list_add_tail(instrs, &cast->node.entry);
|
list_add_tail(instrs, &cast->node.entry);
|
||||||
|
|
||||||
|
@ -19,8 +19,8 @@ float4 main() : SV_TARGET
|
|||||||
}
|
}
|
||||||
|
|
||||||
[test]
|
[test]
|
||||||
todo draw quad
|
draw quad
|
||||||
todo probe all rgba (84.0, 84.0, 84.0, 84.0)
|
probe all rgba (84.0, 84.0, 84.0, 84.0)
|
||||||
|
|
||||||
|
|
||||||
[pixel shader fail]
|
[pixel shader fail]
|
||||||
|
@ -16,8 +16,8 @@ float4 main() : sv_target
|
|||||||
|
|
||||||
|
|
||||||
[test]
|
[test]
|
||||||
todo draw quad
|
draw quad
|
||||||
todo probe all rgba (1.0, 2.0, 3.0, 1.0)
|
probe all rgba (1.0, 2.0, 3.0, 1.0)
|
||||||
|
|
||||||
|
|
||||||
[pixel shader]
|
[pixel shader]
|
||||||
@ -39,8 +39,8 @@ float4 main() : sv_target
|
|||||||
|
|
||||||
|
|
||||||
[test]
|
[test]
|
||||||
todo draw quad
|
draw quad
|
||||||
todo probe all rgba (5.0, 6.0, 7.0, 8.0)
|
probe all rgba (5.0, 6.0, 7.0, 8.0)
|
||||||
|
|
||||||
|
|
||||||
[pixel shader]
|
[pixel shader]
|
||||||
@ -55,8 +55,8 @@ float4 main() : sv_target
|
|||||||
|
|
||||||
|
|
||||||
[test]
|
[test]
|
||||||
todo draw quad
|
draw quad
|
||||||
todo probe all rgba (1.0, 2.0, 3.0, 4.0)
|
probe all rgba (1.0, 2.0, 3.0, 4.0)
|
||||||
|
|
||||||
|
|
||||||
[pixel shader]
|
[pixel shader]
|
||||||
@ -86,8 +86,8 @@ float4 main() : sv_target
|
|||||||
}
|
}
|
||||||
|
|
||||||
[test]
|
[test]
|
||||||
todo draw quad
|
draw quad
|
||||||
todo probe all rgba (7.0, 7.0, 7.0, 7.0)
|
probe all rgba (7.0, 7.0, 7.0, 7.0)
|
||||||
|
|
||||||
|
|
||||||
[pixel shader]
|
[pixel shader]
|
||||||
@ -119,8 +119,8 @@ float4 main() : sv_target
|
|||||||
}
|
}
|
||||||
|
|
||||||
[test]
|
[test]
|
||||||
todo draw quad
|
draw quad
|
||||||
todo probe all rgba (3.0, 3.0, 3.0, 3.0)
|
probe all rgba (3.0, 3.0, 3.0, 3.0)
|
||||||
|
|
||||||
|
|
||||||
[pixel shader fail]
|
[pixel shader fail]
|
||||||
|
Loading…
Reference in New Issue
Block a user