mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2024-11-21 16:46:41 -08:00
vkd3d-shader/hlsl: Lower matrix casts.
Signed-off-by: Giovanni Mascellani <gmascellani@codeweavers.com> Signed-off-by: Zebediah Figura <zfigura@codeweavers.com> Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
41df40b4ed
commit
3a755cb0e2
@ -266,6 +266,9 @@ static bool implicit_compatible_data_types(struct hlsl_type *t1, struct hlsl_typ
|
||||
return false;
|
||||
}
|
||||
|
||||
static struct hlsl_ir_load *add_load(struct hlsl_ctx *ctx, struct list *instrs, struct hlsl_ir_node *var_node,
|
||||
struct hlsl_ir_node *offset, struct hlsl_type *data_type, const struct vkd3d_shader_location loc);
|
||||
|
||||
static struct hlsl_ir_node *add_cast(struct hlsl_ctx *ctx, struct list *instrs,
|
||||
struct hlsl_ir_node *node, struct hlsl_type *dst_type, const struct vkd3d_shader_location *loc)
|
||||
{
|
||||
@ -275,10 +278,92 @@ static struct hlsl_ir_node *add_cast(struct hlsl_ctx *ctx, struct list *instrs,
|
||||
if (hlsl_types_are_equal(src_type, dst_type))
|
||||
return node;
|
||||
|
||||
if (!(cast = hlsl_new_cast(ctx, node, dst_type, loc)))
|
||||
return NULL;
|
||||
list_add_tail(instrs, &cast->node.entry);
|
||||
return &cast->node;
|
||||
if ((src_type->type == HLSL_CLASS_MATRIX || dst_type->type == HLSL_CLASS_MATRIX)
|
||||
&& src_type->type <= HLSL_CLASS_LAST_NUMERIC && dst_type->type <= HLSL_CLASS_LAST_NUMERIC)
|
||||
{
|
||||
struct vkd3d_string_buffer *name;
|
||||
static unsigned int counter = 0;
|
||||
struct hlsl_ir_load *load;
|
||||
struct hlsl_ir_var *var;
|
||||
unsigned int dst_idx;
|
||||
bool broadcast;
|
||||
|
||||
broadcast = src_type->dimx == 1 && src_type->dimy == 1;
|
||||
assert(dst_type->dimx * dst_type->dimy <= src_type->dimx * src_type->dimy || broadcast);
|
||||
if (src_type->type == HLSL_CLASS_MATRIX && dst_type->type == HLSL_CLASS_MATRIX && !broadcast)
|
||||
{
|
||||
assert(dst_type->dimx <= src_type->dimx);
|
||||
assert(dst_type->dimy <= src_type->dimy);
|
||||
}
|
||||
|
||||
name = vkd3d_string_buffer_get(&ctx->string_buffers);
|
||||
vkd3d_string_buffer_printf(name, "<cast-%u>", counter++);
|
||||
var = hlsl_new_synthetic_var(ctx, name->buffer, dst_type, *loc);
|
||||
vkd3d_string_buffer_release(&ctx->string_buffers, name);
|
||||
if (!var)
|
||||
return NULL;
|
||||
|
||||
for (dst_idx = 0; dst_idx < dst_type->dimx * dst_type->dimy; ++dst_idx)
|
||||
{
|
||||
struct hlsl_type *src_scalar_type, *dst_scalar_type;
|
||||
unsigned int src_idx, src_offset, dst_offset;
|
||||
struct hlsl_ir_store *store;
|
||||
struct hlsl_ir_constant *c;
|
||||
|
||||
if (broadcast)
|
||||
{
|
||||
src_idx = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (src_type->type == HLSL_CLASS_MATRIX && dst_type->type == HLSL_CLASS_MATRIX)
|
||||
{
|
||||
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_offset = hlsl_compute_component_offset(ctx, dst_type, dst_idx, &dst_scalar_type);
|
||||
src_offset = hlsl_compute_component_offset(ctx, src_type, src_idx, &src_scalar_type);
|
||||
|
||||
if (!(c = hlsl_new_uint_constant(ctx, src_offset, loc)))
|
||||
return NULL;
|
||||
list_add_tail(instrs, &c->node.entry);
|
||||
|
||||
if (!(load = add_load(ctx, instrs, node, &c->node, src_scalar_type, *loc)))
|
||||
return NULL;
|
||||
|
||||
if (!(cast = hlsl_new_cast(ctx, &load->node, dst_scalar_type, loc)))
|
||||
return NULL;
|
||||
list_add_tail(instrs, &cast->node.entry);
|
||||
|
||||
if (!(c = hlsl_new_uint_constant(ctx, dst_offset, loc)))
|
||||
return NULL;
|
||||
list_add_tail(instrs, &c->node.entry);
|
||||
|
||||
if (!(store = hlsl_new_store(ctx, var, &c->node, &cast->node, 0, *loc)))
|
||||
return NULL;
|
||||
list_add_tail(instrs, &store->node.entry);
|
||||
}
|
||||
|
||||
if (!(load = hlsl_new_load(ctx, var, NULL, dst_type, *loc)))
|
||||
return NULL;
|
||||
list_add_tail(instrs, &load->node.entry);
|
||||
|
||||
return &load->node;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!(cast = hlsl_new_cast(ctx, node, dst_type, loc)))
|
||||
return NULL;
|
||||
list_add_tail(instrs, &cast->node.entry);
|
||||
return &cast->node;
|
||||
}
|
||||
}
|
||||
|
||||
static struct hlsl_ir_node *add_implicit_conversion(struct hlsl_ctx *ctx, struct list *instrs,
|
||||
|
@ -7,5 +7,5 @@ float4 main() : sv_target
|
||||
}
|
||||
|
||||
[test]
|
||||
todo draw quad
|
||||
draw quad
|
||||
probe all rgba (0.1, 0.2, 0.3, 0.4)
|
||||
|
@ -55,7 +55,7 @@ float4 main() : SV_TARGET
|
||||
}
|
||||
|
||||
[test]
|
||||
todo draw quad
|
||||
draw quad
|
||||
probe all rgba (21, 22, 31, 32)
|
||||
|
||||
|
||||
|
@ -5,7 +5,7 @@ float4 main() : sv_target
|
||||
}
|
||||
|
||||
[test]
|
||||
todo draw quad
|
||||
draw quad
|
||||
probe all rgba (0.4, 0.3, 0.2, 0.1)
|
||||
|
||||
[pixel shader]
|
||||
@ -15,7 +15,7 @@ float4 main() : sv_target
|
||||
}
|
||||
|
||||
[test]
|
||||
todo draw quad
|
||||
draw quad
|
||||
probe all rgba (0.4, 0.3, 0.2, 0.1)
|
||||
|
||||
[pixel shader]
|
||||
@ -25,7 +25,7 @@ float4 main() : sv_target
|
||||
}
|
||||
|
||||
[test]
|
||||
todo draw quad
|
||||
draw quad
|
||||
probe all rgba (0.4, 0.3, 0.2, 0.1)
|
||||
|
||||
[pixel shader]
|
||||
@ -35,7 +35,7 @@ float4x1 main() : sv_target
|
||||
}
|
||||
|
||||
[test]
|
||||
todo draw quad
|
||||
draw quad
|
||||
probe all rgba (0.4, 0.3, 0.2, 0.1)
|
||||
|
||||
[pixel shader]
|
||||
|
@ -211,7 +211,7 @@ float4 main() : sv_target
|
||||
}
|
||||
|
||||
[test]
|
||||
todo draw quad
|
||||
draw quad
|
||||
probe all rgba (2.0, 4.0, 6.0, 8.0)
|
||||
|
||||
[pixel shader]
|
||||
@ -235,7 +235,7 @@ float4 main() : sv_target
|
||||
}
|
||||
|
||||
[test]
|
||||
todo draw quad
|
||||
draw quad
|
||||
probe all rgba (2.0, 4.0, 6.0, 8.0)
|
||||
|
||||
[pixel shader]
|
||||
@ -260,7 +260,7 @@ float4 main() : sv_target
|
||||
}
|
||||
|
||||
[test]
|
||||
todo draw quad
|
||||
draw quad
|
||||
probe all rgba (2.0, 4.0, 6.0, 8.0)
|
||||
|
||||
[pixel shader]
|
||||
@ -309,7 +309,7 @@ float4 main() : sv_target
|
||||
}
|
||||
|
||||
[test]
|
||||
todo draw quad
|
||||
draw quad
|
||||
probe all rgba (2.0, 4.0, 0.0, 0.0)
|
||||
|
||||
[pixel shader]
|
||||
@ -321,7 +321,7 @@ float4 main() : sv_target
|
||||
}
|
||||
|
||||
[test]
|
||||
todo draw quad
|
||||
draw quad
|
||||
probe all rgba (2.0, 4.0, 0.0, 0.0)
|
||||
|
||||
[pixel shader]
|
||||
|
@ -5,7 +5,7 @@ float4x1 main() : sv_target
|
||||
}
|
||||
|
||||
[test]
|
||||
todo draw quad
|
||||
draw quad
|
||||
probe all rgba (1.0, 2.0, 3.0, 4.0)
|
||||
|
||||
[pixel shader]
|
||||
@ -15,7 +15,7 @@ row_major float1x4 main() : sv_target
|
||||
}
|
||||
|
||||
[test]
|
||||
todo draw quad
|
||||
draw quad
|
||||
probe all rgba (1.0, 2.0, 3.0, 4.0)
|
||||
|
||||
[require]
|
||||
@ -44,7 +44,7 @@ row_major float4x1 main() : sv_target
|
||||
}
|
||||
|
||||
[test]
|
||||
todo draw quad
|
||||
draw quad
|
||||
probe render target 0 all r (1.0)
|
||||
probe render target 1 all r (2.0)
|
||||
probe render target 2 all r (3.0)
|
||||
@ -57,7 +57,7 @@ float1x4 main() : sv_target
|
||||
}
|
||||
|
||||
[test]
|
||||
todo draw quad
|
||||
draw quad
|
||||
probe render target 0 all r (1.0)
|
||||
probe render target 1 all r (2.0)
|
||||
probe render target 2 all r (3.0)
|
||||
@ -78,7 +78,7 @@ void main(out float1x2 x : sv_target0, out float1x2 y : sv_target2)
|
||||
}
|
||||
|
||||
[test]
|
||||
todo draw quad
|
||||
draw quad
|
||||
probe render target 0 all r (1.0)
|
||||
probe render target 1 all r (2.0)
|
||||
probe render target 2 all r (5.0)
|
||||
@ -96,7 +96,7 @@ void main(out row_major float1x4 x : sv_target0, out float1x2 y : sv_target1)
|
||||
}
|
||||
|
||||
[test]
|
||||
todo draw quad
|
||||
draw quad
|
||||
probe render target 0 all rgba (1.0, 2.0, 3.0, 4.0)
|
||||
probe render target 1 all r (5.0)
|
||||
probe render target 2 all r (6.0)
|
||||
|
Loading…
Reference in New Issue
Block a user