From 23ee29a953c23bc4e6a19555f0376bf526968ab8 Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Wed, 3 Sep 2025 16:25:47 +0200 Subject: [PATCH] vkd3d-shader/hlsl: Implement constant folding of 'reinterpret' expressions. As encountered in tests/hlsl/frexp.shader_test. --- libs/vkd3d-shader/hlsl_constant_ops.c | 17 +++++++++++++++++ tests/hlsl/frexp.shader_test | 14 +++++++------- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/libs/vkd3d-shader/hlsl_constant_ops.c b/libs/vkd3d-shader/hlsl_constant_ops.c index 1262cfe89..492969ec6 100644 --- a/libs/vkd3d-shader/hlsl_constant_ops.c +++ b/libs/vkd3d-shader/hlsl_constant_ops.c @@ -508,6 +508,19 @@ static bool fold_rcp(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, cons return true; } +static bool fold_reinterpret(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, + const struct hlsl_type *dst_type, const struct hlsl_ir_constant *src) +{ + unsigned int k; + + for (k = 0; k < dst_type->e.numeric.dimx; ++k) + { + dst->u[k] = src->value.u[k]; + } + + 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) { @@ -1393,6 +1406,10 @@ bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, success = fold_rcp(ctx, &res, instr->data_type, arg1, &instr->loc); break; + case HLSL_OP1_REINTERPRET: + success = fold_reinterpret(ctx, &res, instr->data_type, arg1); + break; + case HLSL_OP1_RSQ: success = fold_rsq(ctx, &res, instr->data_type, arg1, &instr->loc); break; diff --git a/tests/hlsl/frexp.shader_test b/tests/hlsl/frexp.shader_test index f0fd773a4..bbea71825 100644 --- a/tests/hlsl/frexp.shader_test +++ b/tests/hlsl/frexp.shader_test @@ -55,7 +55,7 @@ uniform 0 uint4 0x0007ffff 0 0 0 todo(sm<4 | msl & sm>=6) draw quad probe (0, 0) f32(0, 0, 0, 0) -[pixel shader todo(sm<4)] +[pixel shader] float4 main() : sv_target { int arg = 7604; @@ -66,10 +66,10 @@ float4 main() : sv_target } [test] -todo(sm<4) draw quad +draw quad probe (0, 0) f32(13.0, 0.0, 0.0, 0.0) -[pixel shader todo(sm<4)] +[pixel shader] float4 main() : sv_target { bool arg = true; @@ -80,11 +80,11 @@ float4 main() : sv_target } [test] -todo(sm<4) draw quad -if(sm<4) probe (0, 0) f32(0.0, 1.0, 0.0, 0.0) +draw quad +if(sm<4) todo probe (0, 0) f32(0.0, 1.0, 0.0, 0.0) if(sm>=4) probe (0, 0) f32(1.0, 1.0, 0.0, 0.0) -[pixel shader todo(sm<4)] +[pixel shader] float4 main() : sv_target { half arg = 3.141; @@ -95,7 +95,7 @@ float4 main() : sv_target } [test] -todo(sm<4) draw quad +draw quad probe (0, 0) f32(2.0, 0.785250008, 0.0, 0.0) [require]