vkd3d-shader/hlsl: Parse the max() intrinsic.

Signed-off-by: Zebediah Figura <zfigura@codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Giovanni Mascellani <gmascellani@codeweavers.com>
Signed-off-by: Matteo Bruni <mbruni@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zebediah Figura 2021-09-01 17:20:54 -05:00 committed by Alexandre Julliard
parent f86e4d6b92
commit 99674ab60f
4 changed files with 94 additions and 0 deletions

View File

@ -72,6 +72,7 @@ vkd3d_shader_tests = \
tests/hlsl-vector-indexing.shader_test \ tests/hlsl-vector-indexing.shader_test \
tests/hlsl-vector-indexing-uniform.shader_test \ tests/hlsl-vector-indexing-uniform.shader_test \
tests/math.shader_test \ tests/math.shader_test \
tests/max.shader_test \
tests/preproc-if.shader_test \ tests/preproc-if.shader_test \
tests/preproc-ifdef.shader_test \ tests/preproc-ifdef.shader_test \
tests/preproc-if-expr.shader_test \ tests/preproc-if-expr.shader_test \
@ -278,6 +279,7 @@ XFAIL_TESTS = \
tests/hlsl-vector-indexing.shader_test \ tests/hlsl-vector-indexing.shader_test \
tests/hlsl-vector-indexing-uniform.shader_test \ tests/hlsl-vector-indexing-uniform.shader_test \
tests/math.shader_test \ tests/math.shader_test \
tests/max.shader_test \
tests/trigonometry.shader_test \ tests/trigonometry.shader_test \
tests/writemask-assignop-1.shader_test tests/writemask-assignop-1.shader_test
endif endif

View File

@ -1555,10 +1555,38 @@ static const struct hlsl_ir_function_decl *find_function_call(struct hlsl_ctx *c
return args.decl; return args.decl;
} }
static bool intrinsic_max(struct hlsl_ctx *ctx,
const struct parse_initializer *params, struct vkd3d_shader_location loc)
{
struct hlsl_ir_node *args[3] = {params->args[0], params->args[1]};
return !!add_expr(ctx, params->instrs, HLSL_OP2_MAX, args, &loc);
}
static const struct intrinsic_function
{
const char *name;
int param_count;
bool check_numeric;
bool (*handler)(struct hlsl_ctx *ctx, const struct parse_initializer *params, struct vkd3d_shader_location loc);
}
intrinsic_functions[] =
{
{"max", 2, true, intrinsic_max},
};
static int intrinsic_function_name_compare(const void *a, const void *b)
{
const struct intrinsic_function *func = b;
return strcmp(a, func->name);
}
static struct list *add_call(struct hlsl_ctx *ctx, const char *name, static struct list *add_call(struct hlsl_ctx *ctx, const char *name,
struct parse_initializer *params, struct vkd3d_shader_location loc) struct parse_initializer *params, struct vkd3d_shader_location loc)
{ {
const struct hlsl_ir_function_decl *decl; const struct hlsl_ir_function_decl *decl;
struct intrinsic_function *intrinsic;
if ((decl = find_function_call(ctx, name, params))) if ((decl = find_function_call(ctx, name, params)))
{ {
@ -1566,6 +1594,45 @@ static struct list *add_call(struct hlsl_ctx *ctx, const char *name,
free_parse_initializer(params); free_parse_initializer(params);
return NULL; return NULL;
} }
else if ((intrinsic = bsearch(name, intrinsic_functions, ARRAY_SIZE(intrinsic_functions),
sizeof(*intrinsic_functions), intrinsic_function_name_compare)))
{
if (intrinsic->param_count >= 0 && params->args_count != intrinsic->param_count)
{
hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_WRONG_PARAMETER_COUNT,
"Wrong number of arguments to function '%s': expected %u, but got %u.\n",
name, intrinsic->param_count, params->args_count);
free_parse_initializer(params);
return NULL;
}
if (intrinsic->check_numeric)
{
unsigned int i;
for (i = 0; i < params->args_count; ++i)
{
if (params->args[i]->data_type->type > HLSL_CLASS_LAST_NUMERIC)
{
struct vkd3d_string_buffer *string;
if ((string = hlsl_type_to_string(ctx, params->args[i]->data_type)))
hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
"Wrong type for argument %u of '%s': expected a numeric type, but got '%s'.\n",
i + 1, name, string->buffer);
hlsl_release_string_buffer(ctx, string);
free_parse_initializer(params);
return NULL;
}
}
}
if (!intrinsic->handler(ctx, params, loc))
{
free_parse_initializer(params);
return NULL;
}
}
else else
{ {
hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_NOT_DEFINED, "Function \"%s\" is not defined.", name); hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_NOT_DEFINED, "Function \"%s\" is not defined.", name);

23
tests/max.shader_test Normal file
View File

@ -0,0 +1,23 @@
[pixel shader]
float4 main(uniform float u, uniform float v) : sv_target
{
return float4(max(u, v), max(2, 2.1), max(true, 2), max(-1, -1));
}
[test]
uniform 0 float4 0.7 -0.1 0.0 0.0
draw quad
probe all rgba (0.7, 2.1, 2.0, -1.0)
[pixel shader]
float4 main(uniform float2 u, uniform float2 v) : sv_target
{
float3 a = float3(-0.1, 0.2, 0.3);
return float4(max(u, v), max(a, u));
}
[test]
uniform 0 float4 0.7 -0.1 0.4 0.8
draw quad
probe all rgba (0.7, 0.8, 0.7, 0.2)

View File

@ -136,6 +136,8 @@ static void parse_test_directive(struct shader_context *context, const char *lin
static const float clear_color[4]; static const float clear_color[4];
ID3D12PipelineState *pso; ID3D12PipelineState *pso;
if (context->c.root_signature)
ID3D12RootSignature_Release(context->c.root_signature);
context->c.root_signature = create_32bit_constants_root_signature(context->c.device, context->c.root_signature = create_32bit_constants_root_signature(context->c.device,
0, context->uniform_count, D3D12_SHADER_VISIBILITY_ALL); 0, context->uniform_count, D3D12_SHADER_VISIBILITY_ALL);