mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2024-11-21 16:46:41 -08:00
vkd3d-shader/hlsl: Fold swizzle chains.
This commit is contained in:
parent
b7d34e8307
commit
6b82ba9488
Notes:
Alexandre Julliard
2023-01-24 22:27:58 +01: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/51
@ -1419,6 +1419,39 @@ static bool lower_narrowing_casts(struct hlsl_ctx *ctx, struct hlsl_ir_node *ins
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool fold_swizzle_chains(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
|
||||
{
|
||||
struct hlsl_ir_swizzle *swizzle;
|
||||
struct hlsl_ir_node *next_instr;
|
||||
|
||||
if (instr->type != HLSL_IR_SWIZZLE)
|
||||
return false;
|
||||
swizzle = hlsl_ir_swizzle(instr);
|
||||
|
||||
next_instr = swizzle->val.node;
|
||||
|
||||
if (next_instr->type == HLSL_IR_SWIZZLE)
|
||||
{
|
||||
struct hlsl_ir_swizzle *new_swizzle;
|
||||
struct hlsl_ir_node *new_instr;
|
||||
unsigned int combined_swizzle;
|
||||
|
||||
combined_swizzle = hlsl_combine_swizzles(hlsl_ir_swizzle(next_instr)->swizzle,
|
||||
swizzle->swizzle, instr->data_type->dimx);
|
||||
next_instr = hlsl_ir_swizzle(next_instr)->val.node;
|
||||
|
||||
if (!(new_swizzle = hlsl_new_swizzle(ctx, combined_swizzle, instr->data_type->dimx, next_instr, &instr->loc)))
|
||||
return false;
|
||||
|
||||
new_instr = &new_swizzle->node;
|
||||
list_add_before(&instr->entry, &new_instr->entry);
|
||||
hlsl_replace_node(instr, new_instr);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool remove_trivial_swizzles(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
|
||||
{
|
||||
struct hlsl_ir_swizzle *swizzle;
|
||||
@ -2866,6 +2899,7 @@ int hlsl_emit_bytecode(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry
|
||||
progress = transform_ir(ctx, hlsl_fold_constant_exprs, body, NULL);
|
||||
progress |= transform_ir(ctx, hlsl_fold_constant_swizzles, body, NULL);
|
||||
progress |= copy_propagation_execute(ctx, body);
|
||||
progress |= transform_ir(ctx, fold_swizzle_chains, body, NULL);
|
||||
progress |= transform_ir(ctx, remove_trivial_swizzles, body, NULL);
|
||||
}
|
||||
while (progress);
|
||||
|
@ -29,7 +29,7 @@ draw quad
|
||||
probe all rgba (110, 210, 410, 410)
|
||||
|
||||
|
||||
[pixel shader todo]
|
||||
[pixel shader]
|
||||
Texture2D tex;
|
||||
uniform int i;
|
||||
|
||||
@ -43,11 +43,11 @@ float4 main() : sv_target
|
||||
|
||||
[test]
|
||||
uniform 0 int 3
|
||||
todo draw quad
|
||||
todo probe all rgba (105, 5, 305, 305)
|
||||
draw quad
|
||||
probe all rgba (105, 5, 305, 305)
|
||||
|
||||
|
||||
[pixel shader todo]
|
||||
[pixel shader]
|
||||
Texture2D tex;
|
||||
uniform int i;
|
||||
|
||||
@ -59,5 +59,5 @@ float4 main() : sv_target
|
||||
|
||||
[test]
|
||||
uniform 0 int 1
|
||||
todo draw quad
|
||||
todo probe all rgba (14.0, 14.0, 14.0, 14.0)
|
||||
draw quad
|
||||
probe all rgba (14.0, 14.0, 14.0, 14.0)
|
||||
|
Loading…
Reference in New Issue
Block a user