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 'sin' 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
@@ -544,6 +544,36 @@ static bool fold_sat(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, cons
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool fold_sin(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 = sinf(src->value.u[k].f);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HLSL_TYPE_DOUBLE:
|
||||||
|
dst->u[k].d = sin(src->value.u[k].d);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
FIXME("Fold 'sin' for type %s.\n", debug_hlsl_type(ctx, dst_type));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static bool fold_sqrt(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, const struct hlsl_type *dst_type,
|
static bool fold_sqrt(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, const struct hlsl_type *dst_type,
|
||||||
const struct hlsl_ir_constant *src, const struct vkd3d_shader_location *loc)
|
const struct hlsl_ir_constant *src, const struct vkd3d_shader_location *loc)
|
||||||
{
|
{
|
||||||
@@ -1337,6 +1367,10 @@ bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr,
|
|||||||
success = fold_sat(ctx, &res, instr->data_type, arg1);
|
success = fold_sat(ctx, &res, instr->data_type, arg1);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case HLSL_OP1_SIN:
|
||||||
|
success = fold_sin(ctx, &res, instr->data_type, arg1);
|
||||||
|
break;
|
||||||
|
|
||||||
case HLSL_OP1_SQRT:
|
case HLSL_OP1_SQRT:
|
||||||
success = fold_sqrt(ctx, &res, instr->data_type, arg1, &instr->loc);
|
success = fold_sqrt(ctx, &res, instr->data_type, arg1, &instr->loc);
|
||||||
break;
|
break;
|
||||||
|
Reference in New Issue
Block a user