mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-04-13 05:43:18 -07:00
vkd3d-shader/hlsl: Pass hlsl_constant_value and hlsl_type pointers to fold_div().
This commit is contained in:
committed by
Alexandre Julliard
parent
133421a38c
commit
c8b7dbebe4
Notes:
Alexandre Julliard
2023-05-26 22:17:06 +02:00
Approved-by: Giovanni Mascellani (@giomasce) Approved-by: Henri Verbeet (@hverbeet) Approved-by: Alexandre Julliard (@julliard) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/210
@@ -293,16 +293,17 @@ static bool fold_nequal(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, c
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool fold_div(struct hlsl_ctx *ctx, struct hlsl_ir_constant *dst,
|
static bool fold_div(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, const struct hlsl_type *dst_type,
|
||||||
struct hlsl_ir_constant *src1, struct hlsl_ir_constant *src2)
|
const struct hlsl_ir_constant *src1, const struct hlsl_ir_constant *src2,
|
||||||
|
const struct vkd3d_shader_location *loc)
|
||||||
{
|
{
|
||||||
enum hlsl_base_type type = dst->node.data_type->base_type;
|
enum hlsl_base_type type = dst_type->base_type;
|
||||||
unsigned int k;
|
unsigned int k;
|
||||||
|
|
||||||
assert(type == src1->node.data_type->base_type);
|
assert(type == src1->node.data_type->base_type);
|
||||||
assert(type == src2->node.data_type->base_type);
|
assert(type == src2->node.data_type->base_type);
|
||||||
|
|
||||||
for (k = 0; k < dst->node.data_type->dimx; ++k)
|
for (k = 0; k < dst_type->dimx; ++k)
|
||||||
{
|
{
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
@@ -310,13 +311,13 @@ static bool fold_div(struct hlsl_ctx *ctx, struct hlsl_ir_constant *dst,
|
|||||||
case HLSL_TYPE_HALF:
|
case HLSL_TYPE_HALF:
|
||||||
if (ctx->profile->major_version >= 4 && src2->value.u[k].f == 0)
|
if (ctx->profile->major_version >= 4 && src2->value.u[k].f == 0)
|
||||||
{
|
{
|
||||||
hlsl_warning(ctx, &dst->node.loc, VKD3D_SHADER_WARNING_HLSL_DIVISION_BY_ZERO,
|
hlsl_warning(ctx, loc, VKD3D_SHADER_WARNING_HLSL_DIVISION_BY_ZERO,
|
||||||
"Floating point division by zero.");
|
"Floating point division by zero.");
|
||||||
}
|
}
|
||||||
dst->value.u[k].f = src1->value.u[k].f / src2->value.u[k].f;
|
dst->u[k].f = src1->value.u[k].f / src2->value.u[k].f;
|
||||||
if (ctx->profile->major_version < 4 && !isfinite(dst->value.u[k].f))
|
if (ctx->profile->major_version < 4 && !isfinite(dst->u[k].f))
|
||||||
{
|
{
|
||||||
hlsl_error(ctx, &dst->node.loc, VKD3D_SHADER_ERROR_HLSL_DIVISION_BY_ZERO,
|
hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_DIVISION_BY_ZERO,
|
||||||
"Infinities and NaNs are not allowed by the shader model.");
|
"Infinities and NaNs are not allowed by the shader model.");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -324,37 +325,37 @@ static bool fold_div(struct hlsl_ctx *ctx, struct hlsl_ir_constant *dst,
|
|||||||
case HLSL_TYPE_DOUBLE:
|
case HLSL_TYPE_DOUBLE:
|
||||||
if (src2->value.u[k].d == 0)
|
if (src2->value.u[k].d == 0)
|
||||||
{
|
{
|
||||||
hlsl_warning(ctx, &dst->node.loc, VKD3D_SHADER_WARNING_HLSL_DIVISION_BY_ZERO,
|
hlsl_warning(ctx, loc, VKD3D_SHADER_WARNING_HLSL_DIVISION_BY_ZERO,
|
||||||
"Floating point division by zero.");
|
"Floating point division by zero.");
|
||||||
}
|
}
|
||||||
dst->value.u[k].d = src1->value.u[k].d / src2->value.u[k].d;
|
dst->u[k].d = src1->value.u[k].d / src2->value.u[k].d;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HLSL_TYPE_INT:
|
case HLSL_TYPE_INT:
|
||||||
if (src2->value.u[k].i == 0)
|
if (src2->value.u[k].i == 0)
|
||||||
{
|
{
|
||||||
hlsl_error(ctx, &dst->node.loc, VKD3D_SHADER_ERROR_HLSL_DIVISION_BY_ZERO,
|
hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_DIVISION_BY_ZERO,
|
||||||
"Division by zero.");
|
"Division by zero.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (src1->value.u[k].i == INT_MIN && src2->value.u[k].i == -1)
|
if (src1->value.u[k].i == INT_MIN && src2->value.u[k].i == -1)
|
||||||
dst->value.u[k].i = INT_MIN;
|
dst->u[k].i = INT_MIN;
|
||||||
else
|
else
|
||||||
dst->value.u[k].i = src1->value.u[k].i / src2->value.u[k].i;
|
dst->u[k].i = src1->value.u[k].i / src2->value.u[k].i;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HLSL_TYPE_UINT:
|
case HLSL_TYPE_UINT:
|
||||||
if (src2->value.u[k].u == 0)
|
if (src2->value.u[k].u == 0)
|
||||||
{
|
{
|
||||||
hlsl_error(ctx, &dst->node.loc, VKD3D_SHADER_ERROR_HLSL_DIVISION_BY_ZERO,
|
hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_DIVISION_BY_ZERO,
|
||||||
"Division by zero.");
|
"Division by zero.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
dst->value.u[k].u = src1->value.u[k].u / src2->value.u[k].u;
|
dst->u[k].u = src1->value.u[k].u / src2->value.u[k].u;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
FIXME("Fold division for type %s.\n", debug_hlsl_type(ctx, dst->node.data_type));
|
FIXME("Fold division for type %s.\n", debug_hlsl_type(ctx, dst_type));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -600,7 +601,7 @@ bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case HLSL_OP2_DIV:
|
case HLSL_OP2_DIV:
|
||||||
success = fold_div(ctx, res, arg1, arg2);
|
success = fold_div(ctx, &res->value, instr->data_type, arg1, arg2, &instr->loc);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HLSL_OP2_MOD:
|
case HLSL_OP2_MOD:
|
||||||
|
Reference in New Issue
Block a user