vkd3d-shader/hlsl: Parse SampleCmp() method.

This commit is contained in:
Nikolay Sivov 2023-05-16 20:54:22 +02:00 committed by Alexandre Julliard
parent 7c94705c54
commit 2fd3550ba6
Notes: Alexandre Julliard 2023-05-29 22:32:35 +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/206
5 changed files with 88 additions and 2 deletions

View File

@ -1356,6 +1356,7 @@ struct hlsl_ir_node *hlsl_new_resource_load(struct hlsl_ctx *ctx,
hlsl_src_from_node(&load->lod, params->lod);
hlsl_src_from_node(&load->ddx, params->ddx);
hlsl_src_from_node(&load->ddy, params->ddy);
hlsl_src_from_node(&load->cmp, params->cmp);
load->sampling_dim = params->sampling_dim;
if (load->sampling_dim == HLSL_SAMPLER_DIM_GENERIC)
load->sampling_dim = hlsl_deref_get_type(ctx, &load->resource)->sampler_dim;
@ -1649,6 +1650,7 @@ static struct hlsl_ir_node *clone_resource_load(struct hlsl_ctx *ctx,
clone_src(map, &dst->ddx, &src->ddx);
clone_src(map, &dst->ddy, &src->ddy);
clone_src(map, &dst->sample_index, &src->sample_index);
clone_src(map, &dst->cmp, &src->cmp);
clone_src(map, &dst->texel_offset, &src->texel_offset);
dst->sampling_dim = src->sampling_dim;
return &dst->node;
@ -2442,6 +2444,7 @@ static void dump_ir_resource_load(struct vkd3d_string_buffer *buffer, const stru
{
[HLSL_RESOURCE_LOAD] = "load_resource",
[HLSL_RESOURCE_SAMPLE] = "sample",
[HLSL_RESOURCE_SAMPLE_CMP] = "sample_cmp",
[HLSL_RESOURCE_SAMPLE_LOD] = "sample_lod",
[HLSL_RESOURCE_SAMPLE_LOD_BIAS] = "sample_biased",
[HLSL_RESOURCE_SAMPLE_GRAD] = "sample_grad",
@ -2483,6 +2486,11 @@ static void dump_ir_resource_load(struct vkd3d_string_buffer *buffer, const stru
vkd3d_string_buffer_printf(buffer, ", ddy = ");
dump_src(buffer, &load->ddy);
}
if (load->cmp.node)
{
vkd3d_string_buffer_printf(buffer, ", cmp = ");
dump_src(buffer, &load->cmp);
}
vkd3d_string_buffer_printf(buffer, ")");
}
@ -2720,6 +2728,7 @@ static void free_ir_resource_load(struct hlsl_ir_resource_load *load)
hlsl_src_remove(&load->lod);
hlsl_src_remove(&load->ddx);
hlsl_src_remove(&load->ddy);
hlsl_src_remove(&load->cmp);
hlsl_src_remove(&load->texel_offset);
hlsl_src_remove(&load->sample_index);
vkd3d_free(load);

View File

@ -615,6 +615,7 @@ enum hlsl_resource_load_type
{
HLSL_RESOURCE_LOAD,
HLSL_RESOURCE_SAMPLE,
HLSL_RESOURCE_SAMPLE_CMP,
HLSL_RESOURCE_SAMPLE_LOD,
HLSL_RESOURCE_SAMPLE_LOD_BIAS,
HLSL_RESOURCE_SAMPLE_GRAD,
@ -629,7 +630,7 @@ struct hlsl_ir_resource_load
struct hlsl_ir_node node;
enum hlsl_resource_load_type load_type;
struct hlsl_deref resource, sampler;
struct hlsl_src coords, lod, ddx, ddy, sample_index, texel_offset;
struct hlsl_src coords, lod, ddx, ddy, cmp, sample_index, texel_offset;
enum hlsl_sampler_dim sampling_dim;
};
@ -831,7 +832,7 @@ struct hlsl_resource_load_params
struct hlsl_type *format;
enum hlsl_resource_load_type type;
struct hlsl_ir_node *resource, *sampler;
struct hlsl_ir_node *coords, *lod, *ddx, *ddy, *sample_index, *texel_offset;
struct hlsl_ir_node *coords, *lod, *ddx, *ddy, *cmp, *sample_index, *texel_offset;
enum hlsl_sampler_dim sampling_dim;
};

View File

@ -3856,6 +3856,75 @@ static bool add_sample_method_call(struct hlsl_ctx *ctx, struct list *instrs, st
return true;
}
static bool add_sample_cmp_method_call(struct hlsl_ctx *ctx, struct list *instrs, struct hlsl_ir_node *object,
const char *name, const struct parse_initializer *params, const struct vkd3d_shader_location *loc)
{
const struct hlsl_type *object_type = object->data_type;
const unsigned int sampler_dim = hlsl_sampler_dim_count(object_type->sampler_dim);
const unsigned int offset_dim = hlsl_offset_dim_count(object_type->sampler_dim);
struct hlsl_resource_load_params load_params = {.type = HLSL_RESOURCE_SAMPLE_CMP};
const struct hlsl_type *sampler_type;
struct hlsl_ir_node *load;
if (object_type->sampler_dim == HLSL_SAMPLER_DIM_2DMS
|| object_type->sampler_dim == HLSL_SAMPLER_DIM_2DMSARRAY)
{
return raise_invalid_method_object_type(ctx, object_type, name, loc);
}
if (params->args_count < 3 || params->args_count > 5 + !!offset_dim)
{
hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_WRONG_PARAMETER_COUNT,
"Wrong number of arguments to method '%s': expected from 3 to %u, but got %u.",
name, 5 + !!offset_dim, params->args_count);
return false;
}
sampler_type = params->args[0]->data_type;
if (sampler_type->class != HLSL_CLASS_OBJECT || sampler_type->base_type != HLSL_TYPE_SAMPLER
|| sampler_type->sampler_dim != HLSL_SAMPLER_DIM_COMPARISON)
{
struct vkd3d_string_buffer *string;
if ((string = hlsl_type_to_string(ctx, sampler_type)))
hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
"Wrong type for argument 0 of %s(): expected 'SamplerComparisonState', but got '%s'.",
name, string->buffer);
hlsl_release_string_buffer(ctx, string);
return false;
}
if (!(load_params.coords = add_implicit_conversion(ctx, instrs, params->args[1],
hlsl_get_vector_type(ctx, HLSL_TYPE_FLOAT, sampler_dim), loc)))
return false;
if (!(load_params.cmp = add_implicit_conversion(ctx, instrs, params->args[2],
hlsl_get_scalar_type(ctx, HLSL_TYPE_FLOAT), loc)))
load_params.cmp = params->args[2];
if (offset_dim && params->args_count > 3)
{
if (!(load_params.texel_offset = add_implicit_conversion(ctx, instrs, params->args[2],
hlsl_get_vector_type(ctx, HLSL_TYPE_INT, offset_dim), loc)))
return false;
}
if (params->args_count > 3 + !!offset_dim)
hlsl_fixme(ctx, loc, "%s() clamp parameter.", name);
if (params->args_count > 4 + !!offset_dim)
hlsl_fixme(ctx, loc, "Tiled resource status argument.");
load_params.format = object_type->e.resource_format;
load_params.resource = object;
load_params.sampler = params->args[0];
if (!(load = hlsl_new_resource_load(ctx, &load_params, loc)))
return false;
list_add_tail(instrs, &load->entry);
return true;
}
static bool add_gather_method_call(struct hlsl_ctx *ctx, struct list *instrs, struct hlsl_ir_node *object,
const char *name, const struct parse_initializer *params, const struct vkd3d_shader_location *loc)
{
@ -4121,6 +4190,7 @@ object_methods[] =
{ "Sample", add_sample_method_call },
{ "SampleBias", add_sample_lod_method_call },
{ "SampleCmp", add_sample_cmp_method_call },
{ "SampleGrad", add_sample_grad_method_call },
{ "SampleLevel", add_sample_lod_method_call },
};

View File

@ -2680,6 +2680,8 @@ static void compute_liveness_recurse(struct hlsl_block *block, unsigned int loop
load->ddy.node->last_read = last_read;
if (load->sample_index.node)
load->sample_index.node->last_read = last_read;
if (load->cmp.node)
load->cmp.node->last_read = last_read;
break;
}
case HLSL_IR_RESOURCE_STORE:

View File

@ -4982,6 +4982,10 @@ static void write_sm4_resource_load(struct hlsl_ctx *ctx,
write_sm4_gather(ctx, buffer, resource_type, &load->node, &load->resource,
&load->sampler, coords, HLSL_SWIZZLE(W, W, W, W), texel_offset);
break;
case HLSL_RESOURCE_SAMPLE_CMP:
hlsl_fixme(ctx, &load->node.loc, "SM4 sample-comparison expression.");
break;
}
}