mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2024-11-21 16:46:41 -08:00
vkd3d-shader/hlsl: Add constant folding for 'log2'.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
This commit is contained in:
parent
58bc61e48d
commit
932c5e36dc
Notes:
Alexandre Julliard
2023-08-14 21:00:52 +02:00
Approved-by: Giovanni Mascellani (@giomasce) Approved-by: Zebediah Figura (@zfigura) Approved-by: Francisco Casas (@fcasas) Approved-by: Henri Verbeet (@hverbeet) Approved-by: Alexandre Julliard (@julliard) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/265
@ -152,6 +152,51 @@ static bool fold_cast(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst,
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool fold_log2(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 && src->value.u[k].f < 0.0f)
|
||||
{
|
||||
hlsl_warning(ctx, loc, VKD3D_SHADER_WARNING_HLSL_NON_FINITE_RESULT,
|
||||
"Indefinite logarithm result.");
|
||||
}
|
||||
dst->u[k].f = log2f(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;
|
||||
|
||||
case HLSL_TYPE_DOUBLE:
|
||||
if (src->value.u[k].d < 0.0)
|
||||
{
|
||||
hlsl_warning(ctx, loc, VKD3D_SHADER_WARNING_HLSL_NON_FINITE_RESULT,
|
||||
"Indefinite logarithm result.");
|
||||
}
|
||||
dst->u[k].d = log2(src->value.u[k].d);
|
||||
break;
|
||||
|
||||
default:
|
||||
FIXME("Fold 'log2' for type %s.\n", debug_hlsl_type(ctx, dst_type));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool fold_neg(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst,
|
||||
const struct hlsl_type *dst_type, const struct hlsl_ir_constant *src)
|
||||
{
|
||||
@ -867,6 +912,10 @@ bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr,
|
||||
success = fold_cast(ctx, &res, instr->data_type, arg1);
|
||||
break;
|
||||
|
||||
case HLSL_OP1_LOG2:
|
||||
success = fold_log2(ctx, &res, instr->data_type, arg1, &instr->loc);
|
||||
break;
|
||||
|
||||
case HLSL_OP1_NEG:
|
||||
success = fold_neg(ctx, &res, instr->data_type, arg1);
|
||||
break;
|
||||
|
@ -139,6 +139,7 @@ enum vkd3d_shader_error
|
||||
VKD3D_SHADER_WARNING_HLSL_DIVISION_BY_ZERO = 5301,
|
||||
VKD3D_SHADER_WARNING_HLSL_UNKNOWN_ATTRIBUTE = 5302,
|
||||
VKD3D_SHADER_WARNING_HLSL_IMAGINARY_NUMERIC_RESULT = 5303,
|
||||
VKD3D_SHADER_WARNING_HLSL_NON_FINITE_RESULT = 5304,
|
||||
|
||||
VKD3D_SHADER_ERROR_GLSL_INTERNAL = 6000,
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user