vkd3d-shader/hlsl: Support coarse derivates.

This commit is contained in:
Francisco Casas 2023-06-19 15:29:58 -04:00 committed by Alexandre Julliard
parent dc84afe73a
commit ff31284f8d
Notes: Alexandre Julliard 2023-07-04 23:24:52 +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/224
5 changed files with 40 additions and 2 deletions

View File

@ -2339,7 +2339,9 @@ const char *debug_hlsl_expr_op(enum hlsl_ir_expr_op op)
[HLSL_OP1_COS] = "cos",
[HLSL_OP1_COS_REDUCED] = "cos_reduced",
[HLSL_OP1_DSX] = "dsx",
[HLSL_OP1_DSX_COARSE] = "dsx_coarse",
[HLSL_OP1_DSY] = "dsy",
[HLSL_OP1_DSY_COARSE] = "dsy_coarse",
[HLSL_OP1_EXP2] = "exp2",
[HLSL_OP1_FRACT] = "fract",
[HLSL_OP1_LOG2] = "log2",

View File

@ -502,7 +502,9 @@ enum hlsl_ir_expr_op
HLSL_OP1_COS,
HLSL_OP1_COS_REDUCED, /* Reduced range [-pi, pi] */
HLSL_OP1_DSX,
HLSL_OP1_DSX_COARSE,
HLSL_OP1_DSY,
HLSL_OP1_DSY_COARSE,
HLSL_OP1_EXP2,
HLSL_OP1_FLOOR,
HLSL_OP1_FRACT,

View File

@ -2670,6 +2670,17 @@ static bool intrinsic_ddx(struct hlsl_ctx *ctx,
return !!add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_DSX, arg, loc);
}
static bool intrinsic_ddx_coarse(struct hlsl_ctx *ctx,
const struct parse_initializer *params, const struct vkd3d_shader_location *loc)
{
struct hlsl_ir_node *arg;
if (!(arg = intrinsic_float_convert_arg(ctx, params, params->args[0], loc)))
return false;
return !!add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_DSX_COARSE, arg, loc);
}
static bool intrinsic_ddy(struct hlsl_ctx *ctx,
const struct parse_initializer *params, const struct vkd3d_shader_location *loc)
{
@ -2681,6 +2692,17 @@ static bool intrinsic_ddy(struct hlsl_ctx *ctx,
return !!add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_DSY, arg, loc);
}
static bool intrinsic_ddy_coarse(struct hlsl_ctx *ctx,
const struct parse_initializer *params, const struct vkd3d_shader_location *loc)
{
struct hlsl_ir_node *arg;
if (!(arg = intrinsic_float_convert_arg(ctx, params, params->args[0], loc)))
return false;
return !!add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_DSY_COARSE, arg, loc);
}
static bool intrinsic_distance(struct hlsl_ctx *ctx,
const struct parse_initializer *params, const struct vkd3d_shader_location *loc)
{
@ -3541,7 +3563,9 @@ intrinsic_functions[] =
{"cos", 1, true, intrinsic_cos},
{"cross", 2, true, intrinsic_cross},
{"ddx", 1, true, intrinsic_ddx},
{"ddx_coarse", 1, true, intrinsic_ddx_coarse},
{"ddy", 1, true, intrinsic_ddy},
{"ddy_coarse", 1, true, intrinsic_ddy_coarse},
{"distance", 2, true, intrinsic_distance},
{"dot", 2, true, intrinsic_dot},
{"exp", 1, true, intrinsic_exp},

View File

@ -4370,11 +4370,21 @@ static void write_sm4_expr(struct hlsl_ctx *ctx,
write_sm4_unary_op(buffer, VKD3D_SM4_OP_DERIV_RTX, &expr->node, arg1, 0);
break;
case HLSL_OP1_DSX_COARSE:
assert(type_is_float(dst_type));
write_sm4_unary_op(buffer, VKD3D_SM5_OP_DERIV_RTX_COARSE, &expr->node, arg1, 0);
break;
case HLSL_OP1_DSY:
assert(type_is_float(dst_type));
write_sm4_unary_op(buffer, VKD3D_SM4_OP_DERIV_RTY, &expr->node, arg1, 0);
break;
case HLSL_OP1_DSY_COARSE:
assert(type_is_float(dst_type));
write_sm4_unary_op(buffer, VKD3D_SM5_OP_DERIV_RTY_COARSE, &expr->node, arg1, 0);
break;
case HLSL_OP1_EXP2:
assert(type_is_float(dst_type));
write_sm4_unary_op(buffer, VKD3D_SM4_OP_EXP, &expr->node, arg1, 0);

View File

@ -43,7 +43,7 @@ probe (150, 150) rgba (-226.0, -47.0, 45.0, 0.0)
shader model >= 5.0
[pixel shader todo]
[pixel shader]
float4 main(float4 pos : sv_position) : sv_target
{
pos /= 10.0;
@ -55,7 +55,7 @@ float4 main(float4 pos : sv_position) : sv_target
}
[test]
todo draw quad
draw quad
probe (10, 10) rgba (-16.0, -5.0, 3.0, 0.0)
probe (11, 10) rgba (-21.0, -5.0, 3.0, 0.0)
probe (10, 11) rgba (-13.0, -5.0, 3.0, 0.0)