Module: vkd3d Branch: master Commit: 4778d051df2d8a92a729751c15cfff6355459958 URL: https://gitlab.winehq.org/wine/vkd3d/-/commit/4778d051df2d8a92a729751c15cfff...
Author: Nikolay Sivov nsivov@codeweavers.com Date: Wed Oct 18 00:08:02 2023 +0200
vkd3d-shader: Add constant folding for 'floor'.
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com
---
libs/vkd3d-shader/hlsl_constant_ops.c | 30 ++++++++++++++++++++++++++++++ tests/hlsl/floor.shader_test | 10 ++++++++++ 2 files changed, 40 insertions(+)
diff --git a/libs/vkd3d-shader/hlsl_constant_ops.c b/libs/vkd3d-shader/hlsl_constant_ops.c index c869dc02..b76b1fce 100644 --- a/libs/vkd3d-shader/hlsl_constant_ops.c +++ b/libs/vkd3d-shader/hlsl_constant_ops.c @@ -280,6 +280,32 @@ static bool fold_exp2(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, return true; }
+static bool fold_floor(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->base_type; + unsigned int k; + + assert(type == src->node.data_type->base_type); + + for (k = 0; k < dst_type->dimx; ++k) + { + switch (type) + { + case HLSL_TYPE_FLOAT: + case HLSL_TYPE_HALF: + dst->u[k].f = floorf(src->value.u[k].f); + break; + + default: + FIXME("Fold 'floor' for type %s.\n", debug_hlsl_type(ctx, dst_type)); + return false; + } + } + + return true; +} + static bool fold_fract(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, const struct hlsl_type *dst_type, const struct hlsl_ir_constant *src) { @@ -1263,6 +1289,10 @@ bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, success = fold_exp2(ctx, &res, instr->data_type, arg1); break;
+ case HLSL_OP1_FLOOR: + success = fold_floor(ctx, &res, instr->data_type, arg1); + break; + case HLSL_OP1_FRACT: success = fold_fract(ctx, &res, instr->data_type, arg1); break; diff --git a/tests/hlsl/floor.shader_test b/tests/hlsl/floor.shader_test index deb9acf9..e6562c4a 100644 --- a/tests/hlsl/floor.shader_test +++ b/tests/hlsl/floor.shader_test @@ -1,3 +1,13 @@ +[pixel shader] +float4 main() : sv_target +{ + return floor(float4(-0.5, 6.5, 7.5, 3.4)); +} + +[test] +draw quad +probe all rgba (-1.0, 6.0, 7.0, 3.0) 4 + [pixel shader] uniform float4 u;