mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-09-12 18:50:22 -07:00
vkd3d-shader/hlsl: Implement constant folding of 'cos' expressions.
As encountered in tests/hlsl/trigonometry.shader_test.
This commit is contained in:
Notes:
Henri Verbeet
2025-09-09 15:10:32 +02:00
Approved-by: Henri Verbeet (@hverbeet) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1716
@@ -250,6 +250,36 @@ static bool fold_ceil(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst,
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool fold_cos(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst,
|
||||
const struct hlsl_type *dst_type, const struct hlsl_ir_constant *src)
|
||||
{
|
||||
enum hlsl_base_type type = dst_type->e.numeric.type;
|
||||
unsigned int k;
|
||||
|
||||
VKD3D_ASSERT(type == src->node.data_type->e.numeric.type);
|
||||
|
||||
for (k = 0; k < dst_type->e.numeric.dimx; ++k)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case HLSL_TYPE_FLOAT:
|
||||
case HLSL_TYPE_HALF:
|
||||
dst->u[k].f = cosf(src->value.u[k].f);
|
||||
break;
|
||||
|
||||
case HLSL_TYPE_DOUBLE:
|
||||
dst->u[k].d = cos(src->value.u[k].d);
|
||||
break;
|
||||
|
||||
default:
|
||||
FIXME("Fold 'cos' for type %s.\n", debug_hlsl_type(ctx, dst_type));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool fold_exp2(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst,
|
||||
const struct hlsl_type *dst_type, const struct hlsl_ir_constant *src)
|
||||
{
|
||||
@@ -1331,6 +1361,10 @@ bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr,
|
||||
success = fold_ceil(ctx, &res, instr->data_type, arg1);
|
||||
break;
|
||||
|
||||
case HLSL_OP1_COS:
|
||||
success = fold_cos(ctx, &res, instr->data_type, arg1);
|
||||
break;
|
||||
|
||||
case HLSL_OP1_EXP2:
|
||||
success = fold_exp2(ctx, &res, instr->data_type, arg1);
|
||||
break;
|
||||
|
@@ -171,5 +171,5 @@ float4 main() : sv_target
|
||||
}
|
||||
|
||||
[test]
|
||||
todo(msl & sm<6) draw quad
|
||||
probe (0, 0) rgba (0, 0, 0, 0);
|
||||
draw quad
|
||||
probe (0, 0) f32(0, 0, 0, 0);
|
||||
|
Reference in New Issue
Block a user