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 'round' expressions.
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
@@ -521,6 +521,35 @@ static bool fold_reinterpret(struct hlsl_ctx *ctx, struct hlsl_constant_value *d
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool fold_round(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:
|
||||
/* Somewhat unfortunately, constant folded round() rounds
|
||||
* halfway cases towards positive infinity, as opposed to
|
||||
* nearest even like vsir/TPF round_ne. */
|
||||
dst->u[k].f = floorf(src->value.u[k].f + 0.5f);
|
||||
break;
|
||||
|
||||
default:
|
||||
FIXME("Fold 'round' for type %s.\n", debug_hlsl_type(ctx, dst_type));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool fold_rsq(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)
|
||||
{
|
||||
@@ -1410,6 +1439,10 @@ bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr,
|
||||
success = fold_reinterpret(ctx, &res, instr->data_type, arg1);
|
||||
break;
|
||||
|
||||
case HLSL_OP1_ROUND:
|
||||
success = fold_round(ctx, &res, instr->data_type, arg1);
|
||||
break;
|
||||
|
||||
case HLSL_OP1_RSQ:
|
||||
success = fold_rsq(ctx, &res, instr->data_type, arg1, &instr->loc);
|
||||
break;
|
||||
|
@@ -53,5 +53,5 @@ float4 main() : sv_target
|
||||
|
||||
[test]
|
||||
draw quad
|
||||
if(sm<6) todo(sm>=4) probe (0, 0) f32(-1.0, 0.0, 1.0, 2.0)
|
||||
if(sm<6) probe (0, 0) f32(-1.0, 0.0, 1.0, 2.0)
|
||||
if(sm>=6) probe (0, 0) f32(-2.0, -0.0, 0.0, 2.0)
|
||||
|
Reference in New Issue
Block a user