vkd3d-shader/hlsl: Implement constant folding of 'cos' expressions.

As encountered in tests/hlsl/trigonometry.shader_test.
This commit is contained in:
Henri Verbeet
2025-09-03 14:34:48 +02:00
parent 08e7806b7f
commit e330ad2ac7
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
2 changed files with 36 additions and 2 deletions

View File

@@ -250,6 +250,36 @@ static bool fold_ceil(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst,
return true; 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, 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) 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); success = fold_ceil(ctx, &res, instr->data_type, arg1);
break; break;
case HLSL_OP1_COS:
success = fold_cos(ctx, &res, instr->data_type, arg1);
break;
case HLSL_OP1_EXP2: case HLSL_OP1_EXP2:
success = fold_exp2(ctx, &res, instr->data_type, arg1); success = fold_exp2(ctx, &res, instr->data_type, arg1);
break; break;

View File

@@ -171,5 +171,5 @@ float4 main() : sv_target
} }
[test] [test]
todo(msl & sm<6) draw quad draw quad
probe (0, 0) rgba (0, 0, 0, 0); probe (0, 0) f32(0, 0, 0, 0);