Signed-off-by: Nikolay Sivov nsivov@codeweavers.com
-- v2: vkd3d-shader: Add constant folding for 'rsq'.
From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- libs/vkd3d-shader/hlsl_constant_ops.c | 44 +++++++++++++++++++++++++++ 1 file changed, 44 insertions(+)
diff --git a/libs/vkd3d-shader/hlsl_constant_ops.c b/libs/vkd3d-shader/hlsl_constant_ops.c index cff0ba31e..77ce721f6 100644 --- a/libs/vkd3d-shader/hlsl_constant_ops.c +++ b/libs/vkd3d-shader/hlsl_constant_ops.c @@ -379,6 +379,46 @@ static bool fold_rcp(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, cons 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) +{ + 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: + if (ctx->profile->major_version >= 4) + { + if (src->value.u[k].f < 0.0f) + hlsl_warning(ctx, loc, VKD3D_SHADER_WARNING_HLSL_IMAGINARY_NUMERIC_RESULT, + "Imaginary square root result."); + else if (src->value.u[k].f == 0.0f) + hlsl_warning(ctx, loc, VKD3D_SHADER_WARNING_HLSL_IMAGINARY_NUMERIC_RESULT, + "Floating point division by zero."); + } + dst->u[k].f = 1.0f / sqrtf(src->value.u[k].f); + if (ctx->profile->major_version < 4 && !isfinite(dst->u[k].f)) + { + hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_NON_FINITE_RESULT, + "Infinities and NaNs are not allowed by the shader model."); + } + break; + + default: + FIXME("Fold 'rsq' for type %s.\n", debug_hlsl_type(ctx, dst_type)); + return false; + } + } + + return true; +} + static bool fold_sat(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, const struct hlsl_type *dst_type, const struct hlsl_ir_constant *src) { @@ -1095,6 +1135,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_RSQ: + success = fold_rsq(ctx, &res, instr->data_type, arg1, &instr->loc); + break; + case HLSL_OP1_SAT: success = fold_sat(ctx, &res, instr->data_type, arg1); break;
On Wed Sep 27 10:58:53 2023 +0000, Nikolay Sivov wrote:
changed this line in [version 2 of the diff](/wine/vkd3d/-/merge_requests/368/diffs?diff_id=72251&start_sha=b23a242a325f1d3279050a8216e515ca61e1eb96#42d7bc823e29607ffee11286a3147a03c3ae6ce6_396_396)
Yes, it was meant to be removed.
This merge request was approved by Giovanni Mascellani.
This merge request was approved by Zebediah Figura.
This merge request was approved by Henri Verbeet.