mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-01-28 13:05:02 -08:00
vkd3d-shader/hlsl: Pass the arguments to hlsl_new_resource_load() as an indirect structure.
The function has far too many arguments, including multiple different arguments with the same type. Use a structure for clarity and to avoid errors. Merge hlsl_new_sample_lod() into hlsl_new_resource_load() accordingly.
This commit is contained in:
parent
fb724d60e3
commit
15a0b44ada
Notes:
Alexandre Julliard
2022-10-18 00:13:00 +02:00
Approved-by: Henri Verbeet (@hverbeet) Approved-by: Alexandre Julliard (@julliard) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/17
@ -1050,41 +1050,29 @@ struct hlsl_ir_load *hlsl_new_load_component(struct hlsl_ctx *ctx, struct hlsl_b
|
||||
return load;
|
||||
}
|
||||
|
||||
struct hlsl_ir_resource_load *hlsl_new_resource_load(struct hlsl_ctx *ctx, struct hlsl_type *data_type,
|
||||
enum hlsl_resource_load_type type, struct hlsl_deref *resource, struct hlsl_deref *sampler,
|
||||
struct hlsl_ir_node *coords, struct hlsl_ir_node *texel_offset, const struct vkd3d_shader_location *loc)
|
||||
struct hlsl_ir_resource_load *hlsl_new_resource_load(struct hlsl_ctx *ctx,
|
||||
const struct hlsl_resource_load_params *params, const struct vkd3d_shader_location *loc)
|
||||
{
|
||||
struct hlsl_ir_resource_load *load;
|
||||
|
||||
if (!(load = hlsl_alloc(ctx, sizeof(*load))))
|
||||
return NULL;
|
||||
init_node(&load->node, HLSL_IR_RESOURCE_LOAD, data_type, *loc);
|
||||
load->load_type = type;
|
||||
if (!hlsl_copy_deref(ctx, &load->resource, resource))
|
||||
init_node(&load->node, HLSL_IR_RESOURCE_LOAD, params->format, *loc);
|
||||
load->load_type = params->type;
|
||||
if (!hlsl_copy_deref(ctx, &load->resource, ¶ms->resource))
|
||||
{
|
||||
vkd3d_free(load);
|
||||
return NULL;
|
||||
}
|
||||
if (!hlsl_copy_deref(ctx, &load->sampler, sampler))
|
||||
if (!hlsl_copy_deref(ctx, &load->sampler, ¶ms->sampler))
|
||||
{
|
||||
hlsl_cleanup_deref(&load->resource);
|
||||
vkd3d_free(load);
|
||||
return NULL;
|
||||
}
|
||||
hlsl_src_from_node(&load->coords, coords);
|
||||
hlsl_src_from_node(&load->texel_offset, texel_offset);
|
||||
return load;
|
||||
}
|
||||
|
||||
struct hlsl_ir_resource_load *hlsl_new_sample_lod(struct hlsl_ctx *ctx, struct hlsl_type *data_type,
|
||||
struct hlsl_deref *resource, struct hlsl_deref *sampler, struct hlsl_ir_node *coords,
|
||||
struct hlsl_ir_node *texel_offset, struct hlsl_ir_node *lod, const struct vkd3d_shader_location *loc)
|
||||
{
|
||||
struct hlsl_ir_resource_load *load;
|
||||
|
||||
if ((load = hlsl_new_resource_load(ctx, data_type, HLSL_RESOURCE_SAMPLE_LOD,
|
||||
resource, sampler, coords, texel_offset, loc)))
|
||||
hlsl_src_from_node(&load->lod, lod);
|
||||
hlsl_src_from_node(&load->coords, params->coords);
|
||||
hlsl_src_from_node(&load->texel_offset, params->texel_offset);
|
||||
hlsl_src_from_node(&load->lod, params->lod);
|
||||
return load;
|
||||
}
|
||||
|
||||
|
@ -526,6 +526,14 @@ enum hlsl_error_level
|
||||
HLSL_LEVEL_NOTE,
|
||||
};
|
||||
|
||||
struct hlsl_resource_load_params
|
||||
{
|
||||
struct hlsl_type *format;
|
||||
enum hlsl_resource_load_type type;
|
||||
struct hlsl_deref resource, sampler;
|
||||
struct hlsl_ir_node *coords, *lod, *texel_offset;
|
||||
};
|
||||
|
||||
static inline struct hlsl_ir_constant *hlsl_ir_constant(const struct hlsl_ir_node *node)
|
||||
{
|
||||
assert(node->type == HLSL_IR_CONSTANT);
|
||||
@ -772,14 +780,9 @@ struct hlsl_ir_store *hlsl_new_store_index(struct hlsl_ctx *ctx, const struct hl
|
||||
struct hlsl_ir_store *hlsl_new_store_component(struct hlsl_ctx *ctx, struct hlsl_block *block,
|
||||
const struct hlsl_deref *lhs, unsigned int comp, struct hlsl_ir_node *rhs);
|
||||
|
||||
struct hlsl_ir_resource_load *hlsl_new_resource_load(struct hlsl_ctx *ctx, struct hlsl_type *data_type,
|
||||
enum hlsl_resource_load_type type, struct hlsl_deref *resource, struct hlsl_deref *sampler,
|
||||
struct hlsl_ir_node *coords, struct hlsl_ir_node *texel_offset, const struct vkd3d_shader_location *loc);
|
||||
struct hlsl_ir_resource_load *hlsl_new_sample_lod(struct hlsl_ctx *ctx, struct hlsl_type *data_type,
|
||||
struct hlsl_deref *resource, struct hlsl_deref *sampler, struct hlsl_ir_node *coords,
|
||||
struct hlsl_ir_node *texel_offset, struct hlsl_ir_node *lod, const struct vkd3d_shader_location *loc);
|
||||
|
||||
struct hlsl_ir_loop *hlsl_new_loop(struct hlsl_ctx *ctx, struct vkd3d_shader_location loc);
|
||||
struct hlsl_ir_resource_load *hlsl_new_resource_load(struct hlsl_ctx *ctx,
|
||||
const struct hlsl_resource_load_params *params, const struct vkd3d_shader_location *loc);
|
||||
struct hlsl_type *hlsl_new_struct_type(struct hlsl_ctx *ctx, const char *name,
|
||||
struct hlsl_struct_field *fields, size_t field_count);
|
||||
struct hlsl_ir_swizzle *hlsl_new_swizzle(struct hlsl_ctx *ctx, DWORD s, unsigned int components,
|
||||
|
@ -2501,9 +2501,8 @@ static bool add_method_call(struct hlsl_ctx *ctx, struct list *instrs, struct hl
|
||||
{
|
||||
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_LOAD};
|
||||
struct hlsl_ir_resource_load *load;
|
||||
struct hlsl_ir_node *offset = NULL;
|
||||
struct hlsl_ir_node *coords;
|
||||
bool multisampled;
|
||||
|
||||
multisampled = object_type->sampler_dim == HLSL_SAMPLER_DIM_2DMS
|
||||
@ -2524,7 +2523,7 @@ static bool add_method_call(struct hlsl_ctx *ctx, struct list *instrs, struct hl
|
||||
assert(offset_dim);
|
||||
if (params->args_count > 1 + multisampled)
|
||||
{
|
||||
if (!(offset = add_implicit_conversion(ctx, instrs, params->args[1 + multisampled],
|
||||
if (!(load_params.texel_offset = add_implicit_conversion(ctx, instrs, params->args[1 + multisampled],
|
||||
hlsl_get_vector_type(ctx, HLSL_TYPE_INT, offset_dim), loc)))
|
||||
return false;
|
||||
}
|
||||
@ -2534,12 +2533,14 @@ static bool add_method_call(struct hlsl_ctx *ctx, struct list *instrs, struct hl
|
||||
}
|
||||
|
||||
/* +1 for the mipmap level */
|
||||
if (!(coords = add_implicit_conversion(ctx, instrs, params->args[0],
|
||||
if (!(load_params.coords = add_implicit_conversion(ctx, instrs, params->args[0],
|
||||
hlsl_get_vector_type(ctx, HLSL_TYPE_INT, sampler_dim + 1), loc)))
|
||||
return false;
|
||||
|
||||
if (!(load = hlsl_new_resource_load(ctx, object_type->e.resource_format, HLSL_RESOURCE_LOAD,
|
||||
&object_load->src, NULL, coords, offset, loc)))
|
||||
load_params.format = object_type->e.resource_format;
|
||||
load_params.resource = object_load->src;
|
||||
|
||||
if (!(load = hlsl_new_resource_load(ctx, &load_params, loc)))
|
||||
return false;
|
||||
list_add_tail(instrs, &load->node.entry);
|
||||
return true;
|
||||
@ -2550,11 +2551,10 @@ static bool add_method_call(struct hlsl_ctx *ctx, struct list *instrs, struct hl
|
||||
{
|
||||
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};
|
||||
const struct hlsl_type *sampler_type;
|
||||
struct hlsl_ir_resource_load *load;
|
||||
struct hlsl_ir_node *offset = NULL;
|
||||
struct hlsl_ir_load *sampler_load;
|
||||
struct hlsl_ir_node *coords;
|
||||
|
||||
if (params->args_count < 2 || params->args_count > 4 + !!offset_dim)
|
||||
{
|
||||
@ -2580,13 +2580,13 @@ static bool add_method_call(struct hlsl_ctx *ctx, struct list *instrs, struct hl
|
||||
/* Only HLSL_IR_LOAD can return an object. */
|
||||
sampler_load = hlsl_ir_load(params->args[0]);
|
||||
|
||||
if (!(coords = add_implicit_conversion(ctx, instrs, params->args[1],
|
||||
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 (offset_dim && params->args_count > 2)
|
||||
{
|
||||
if (!(offset = add_implicit_conversion(ctx, instrs, params->args[2],
|
||||
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;
|
||||
}
|
||||
@ -2596,8 +2596,11 @@ static bool add_method_call(struct hlsl_ctx *ctx, struct list *instrs, struct hl
|
||||
if (params->args_count > 3 + !!offset_dim)
|
||||
hlsl_fixme(ctx, loc, "Tiled resource status argument.");
|
||||
|
||||
if (!(load = hlsl_new_resource_load(ctx, object_type->e.resource_format,
|
||||
HLSL_RESOURCE_SAMPLE, &object_load->src, &sampler_load->src, coords, offset, loc)))
|
||||
load_params.format = object_type->e.resource_format;
|
||||
load_params.resource = object_load->src;
|
||||
load_params.sampler = sampler_load->src;
|
||||
|
||||
if (!(load = hlsl_new_resource_load(ctx, &load_params, loc)))
|
||||
return false;
|
||||
list_add_tail(instrs, &load->node.entry);
|
||||
|
||||
@ -2612,33 +2615,30 @@ static bool add_method_call(struct hlsl_ctx *ctx, struct list *instrs, struct hl
|
||||
{
|
||||
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);
|
||||
enum hlsl_resource_load_type load_type;
|
||||
struct hlsl_resource_load_params load_params = {0};
|
||||
const struct hlsl_type *sampler_type;
|
||||
struct hlsl_ir_resource_load *load;
|
||||
struct hlsl_ir_node *offset = NULL;
|
||||
struct hlsl_ir_load *sampler_load;
|
||||
struct hlsl_type *result_type;
|
||||
struct hlsl_ir_node *coords;
|
||||
unsigned int read_channel;
|
||||
|
||||
if (!strcmp(name, "GatherGreen"))
|
||||
{
|
||||
load_type = HLSL_RESOURCE_GATHER_GREEN;
|
||||
load_params.type = HLSL_RESOURCE_GATHER_GREEN;
|
||||
read_channel = 1;
|
||||
}
|
||||
else if (!strcmp(name, "GatherBlue"))
|
||||
{
|
||||
load_type = HLSL_RESOURCE_GATHER_BLUE;
|
||||
load_params.type = HLSL_RESOURCE_GATHER_BLUE;
|
||||
read_channel = 2;
|
||||
}
|
||||
else if (!strcmp(name, "GatherAlpha"))
|
||||
{
|
||||
load_type = HLSL_RESOURCE_GATHER_ALPHA;
|
||||
load_params.type = HLSL_RESOURCE_GATHER_ALPHA;
|
||||
read_channel = 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
load_type = HLSL_RESOURCE_GATHER_RED;
|
||||
load_params.type = HLSL_RESOURCE_GATHER_RED;
|
||||
read_channel = 0;
|
||||
}
|
||||
|
||||
@ -2669,7 +2669,7 @@ static bool add_method_call(struct hlsl_ctx *ctx, struct list *instrs, struct hl
|
||||
}
|
||||
else if (offset_dim && params->args_count > 2)
|
||||
{
|
||||
if (!(offset = add_implicit_conversion(ctx, instrs, params->args[2],
|
||||
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;
|
||||
}
|
||||
@ -2694,17 +2694,18 @@ static bool add_method_call(struct hlsl_ctx *ctx, struct list *instrs, struct hl
|
||||
return false;
|
||||
}
|
||||
|
||||
result_type = hlsl_get_vector_type(ctx, object_type->e.resource_format->base_type, 4);
|
||||
|
||||
/* Only HLSL_IR_LOAD can return an object. */
|
||||
sampler_load = hlsl_ir_load(params->args[0]);
|
||||
|
||||
if (!(coords = add_implicit_conversion(ctx, instrs, params->args[1],
|
||||
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 = hlsl_new_resource_load(ctx, result_type, load_type, &object_load->src,
|
||||
&sampler_load->src, coords, offset, loc)))
|
||||
load_params.format = hlsl_get_vector_type(ctx, object_type->e.resource_format->base_type, 4);
|
||||
load_params.resource = object_load->src;
|
||||
load_params.sampler = sampler_load->src;
|
||||
|
||||
if (!(load = hlsl_new_resource_load(ctx, &load_params, loc)))
|
||||
return false;
|
||||
list_add_tail(instrs, &load->node.entry);
|
||||
return true;
|
||||
@ -2713,13 +2714,12 @@ static bool add_method_call(struct hlsl_ctx *ctx, struct list *instrs, struct hl
|
||||
&& object_type->sampler_dim != HLSL_SAMPLER_DIM_2DMS
|
||||
&& object_type->sampler_dim != HLSL_SAMPLER_DIM_2DMSARRAY)
|
||||
{
|
||||
struct hlsl_resource_load_params load_params = {.type = HLSL_RESOURCE_SAMPLE_LOD};
|
||||
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);
|
||||
const struct hlsl_type *sampler_type;
|
||||
struct hlsl_ir_resource_load *load;
|
||||
struct hlsl_ir_node *offset = NULL;
|
||||
struct hlsl_ir_load *sampler_load;
|
||||
struct hlsl_ir_node *coords, *lod;
|
||||
|
||||
if (params->args_count < 3 || params->args_count > 4 + !!offset_dim)
|
||||
{
|
||||
@ -2745,17 +2745,17 @@ static bool add_method_call(struct hlsl_ctx *ctx, struct list *instrs, struct hl
|
||||
/* Only HLSL_IR_LOAD can return an object. */
|
||||
sampler_load = hlsl_ir_load(params->args[0]);
|
||||
|
||||
if (!(coords = add_implicit_conversion(ctx, instrs, params->args[1],
|
||||
if (!(load_params.coords = add_implicit_conversion(ctx, instrs, params->args[1],
|
||||
hlsl_get_vector_type(ctx, HLSL_TYPE_FLOAT, sampler_dim), loc)))
|
||||
coords = params->args[1];
|
||||
load_params.coords = params->args[1];
|
||||
|
||||
if (!(lod = add_implicit_conversion(ctx, instrs, params->args[2],
|
||||
if (!(load_params.lod = add_implicit_conversion(ctx, instrs, params->args[2],
|
||||
hlsl_get_scalar_type(ctx, HLSL_TYPE_FLOAT), loc)))
|
||||
lod = params->args[2];
|
||||
load_params.lod = params->args[2];
|
||||
|
||||
if (offset_dim && params->args_count > 3)
|
||||
{
|
||||
if (!(offset = add_implicit_conversion(ctx, instrs, params->args[3],
|
||||
if (!(load_params.texel_offset = add_implicit_conversion(ctx, instrs, params->args[3],
|
||||
hlsl_get_vector_type(ctx, HLSL_TYPE_INT, offset_dim), loc)))
|
||||
return false;
|
||||
}
|
||||
@ -2763,8 +2763,11 @@ static bool add_method_call(struct hlsl_ctx *ctx, struct list *instrs, struct hl
|
||||
if (params->args_count > 3 + !!offset_dim)
|
||||
hlsl_fixme(ctx, loc, "Tiled resource status argument.");
|
||||
|
||||
if (!(load = hlsl_new_sample_lod(ctx, object_type->e.resource_format,
|
||||
&object_load->src, &sampler_load->src, coords, offset, lod, loc)))
|
||||
load_params.format = object_type->e.resource_format;
|
||||
load_params.resource = object_load->src;
|
||||
load_params.sampler = sampler_load->src;
|
||||
|
||||
if (!(load = hlsl_new_resource_load(ctx, &load_params, loc)))
|
||||
return false;
|
||||
list_add_tail(instrs, &load->node.entry);
|
||||
return true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user