mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-01-28 13:05:02 -08:00
vkd3d-shader: Add constant folding for 'rsq'.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
This commit is contained in:
parent
a58c659b10
commit
f3389789b2
Notes:
Alexandre Julliard
2023-10-05 22:37:31 +02:00
Approved-by: Giovanni Mascellani (@giomasce) Approved-by: Zebediah Figura (@zfigura) Approved-by: Henri Verbeet (@hverbeet) Approved-by: Alexandre Julliard (@julliard) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/368
@ -429,6 +429,46 @@ static bool fold_rcp(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, cons
|
|||||||
return true;
|
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,
|
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)
|
const struct hlsl_ir_constant *src)
|
||||||
{
|
{
|
||||||
@ -1213,6 +1253,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);
|
success = fold_rcp(ctx, &res, instr->data_type, arg1, &instr->loc);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case HLSL_OP1_RSQ:
|
||||||
|
success = fold_rsq(ctx, &res, instr->data_type, arg1, &instr->loc);
|
||||||
|
break;
|
||||||
|
|
||||||
case HLSL_OP1_SAT:
|
case HLSL_OP1_SAT:
|
||||||
success = fold_sat(ctx, &res, instr->data_type, arg1);
|
success = fold_sat(ctx, &res, instr->data_type, arg1);
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user