From: Zebediah Figura zfigura@codeweavers.com
--- libs/vkd3d-shader/hlsl.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 00b54b76..3ff8566a 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -1051,8 +1051,17 @@ struct hlsl_ir_resource_load *hlsl_new_resource_load(struct hlsl_ctx *ctx, struc return NULL; init_node(&load->node, HLSL_IR_RESOURCE_LOAD, data_type, *loc); load->load_type = type; - hlsl_copy_deref(ctx, &load->resource, resource); - hlsl_copy_deref(ctx, &load->sampler, sampler); + if (!hlsl_copy_deref(ctx, &load->resource, resource)) + { + vkd3d_free(load); + return NULL; + } + if (!hlsl_copy_deref(ctx, &load->sampler, 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;
From: Zebediah Figura zfigura@codeweavers.com
Synthesize the internal name from the template inside of this function. --- libs/vkd3d-shader/hlsl.c | 19 +++++++++++--- libs/vkd3d-shader/hlsl.h | 4 +-- libs/vkd3d-shader/hlsl.y | 57 +++++++--------------------------------- 3 files changed, 27 insertions(+), 53 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 3ff8566a..da6d81b8 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -770,11 +770,24 @@ struct hlsl_ir_var *hlsl_new_var(struct hlsl_ctx *ctx, const char *name, struct return var; }
-struct hlsl_ir_var *hlsl_new_synthetic_var(struct hlsl_ctx *ctx, const char *name, struct hlsl_type *type, - const struct vkd3d_shader_location loc) +struct hlsl_ir_var *hlsl_new_synthetic_var(struct hlsl_ctx *ctx, const char *template, + struct hlsl_type *type, const struct vkd3d_shader_location *loc) { - struct hlsl_ir_var *var = hlsl_new_var(ctx, hlsl_strdup(ctx, name), type, loc, NULL, 0, NULL); + struct vkd3d_string_buffer *string; + struct hlsl_ir_var *var; + static LONG counter; + const char *name;
+ if (!(string = hlsl_get_string_buffer(ctx))) + return NULL; + vkd3d_string_buffer_printf(string, "<%s-%u>", template, InterlockedIncrement(&counter)); + if (!(name = hlsl_strdup(ctx, string->buffer))) + { + hlsl_release_string_buffer(ctx, string); + return NULL; + } + var = hlsl_new_var(ctx, name, type, *loc, NULL, 0, NULL); + hlsl_release_string_buffer(ctx, string); if (var) list_add_tail(&ctx->globals->vars, &var->scope_entry); return var; diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 794749aa..141b26ca 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -785,8 +785,8 @@ 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, struct hlsl_ir_node *val, const struct vkd3d_shader_location *loc); -struct hlsl_ir_var *hlsl_new_synthetic_var(struct hlsl_ctx *ctx, const char *name, struct hlsl_type *type, - const struct vkd3d_shader_location loc); +struct hlsl_ir_var *hlsl_new_synthetic_var(struct hlsl_ctx *ctx, const char *template, + struct hlsl_type *type, const struct vkd3d_shader_location *loc); struct hlsl_type *hlsl_new_texture_type(struct hlsl_ctx *ctx, enum hlsl_sampler_dim dim, struct hlsl_type *format); struct hlsl_ir_constant *hlsl_new_uint_constant(struct hlsl_ctx *ctx, unsigned int n, const struct vkd3d_shader_location *loc); diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 624481d8..d6cd57a3 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -287,8 +287,6 @@ static struct hlsl_ir_node *add_cast(struct hlsl_ctx *ctx, struct list *instrs, if ((src_type->type == HLSL_CLASS_MATRIX || dst_type->type == HLSL_CLASS_MATRIX) && src_type->type <= HLSL_CLASS_LAST_NUMERIC && dst_type->type <= HLSL_CLASS_LAST_NUMERIC) { - struct vkd3d_string_buffer *name; - static unsigned int counter = 0; struct hlsl_deref var_deref; struct hlsl_ir_load *load; struct hlsl_ir_var *var; @@ -303,11 +301,7 @@ static struct hlsl_ir_node *add_cast(struct hlsl_ctx *ctx, struct list *instrs, assert(dst_type->dimy <= src_type->dimy); }
- name = vkd3d_string_buffer_get(&ctx->string_buffers); - vkd3d_string_buffer_printf(name, "<cast-%u>", counter++); - var = hlsl_new_synthetic_var(ctx, name->buffer, dst_type, *loc); - vkd3d_string_buffer_release(&ctx->string_buffers, name); - if (!var) + if (!(var = hlsl_new_synthetic_var(ctx, "cast", dst_type, loc))) return NULL; hlsl_init_simple_deref_from_var(&var_deref, var);
@@ -635,16 +629,10 @@ static struct hlsl_ir_load *add_load_index(struct hlsl_ctx *ctx, struct list *in } else { - struct vkd3d_string_buffer *name; struct hlsl_ir_store *store; struct hlsl_ir_var *var;
- if (!(name = hlsl_get_string_buffer(ctx))) - return NULL; - vkd3d_string_buffer_printf(name, "<deref-%p>", var_instr); - var = hlsl_new_synthetic_var(ctx, name->buffer, var_instr->data_type, var_instr->loc); - hlsl_release_string_buffer(ctx, name); - if (!var) + if (!(var = hlsl_new_synthetic_var(ctx, "deref", var_instr->data_type, &var_instr->loc))) return NULL;
if (!(store = hlsl_new_simple_store(ctx, var, var_instr))) @@ -674,16 +662,10 @@ static struct hlsl_ir_load *add_load_component(struct hlsl_ctx *ctx, struct list } else { - struct vkd3d_string_buffer *name; struct hlsl_ir_store *store; struct hlsl_ir_var *var;
- if (!(name = hlsl_get_string_buffer(ctx))) - return NULL; - vkd3d_string_buffer_printf(name, "<deref-%p>", var_instr); - var = hlsl_new_synthetic_var(ctx, name->buffer, var_instr->data_type, var_instr->loc); - hlsl_release_string_buffer(ctx, name); - if (!var) + if (!(var = hlsl_new_synthetic_var(ctx, "deref", var_instr->data_type, &var_instr->loc))) return NULL;
if (!(store = hlsl_new_simple_store(ctx, var, var_instr))) @@ -722,8 +704,6 @@ static bool add_matrix_index(struct hlsl_ctx *ctx, struct list *instrs, struct hlsl_ir_node *matrix, struct hlsl_ir_node *index, const struct vkd3d_shader_location *loc) { struct hlsl_type *mat_type = matrix->data_type, *ret_type; - struct vkd3d_string_buffer *name; - static unsigned int counter = 0; struct hlsl_deref var_deref; struct hlsl_ir_load *load; struct hlsl_ir_var *var; @@ -734,11 +714,7 @@ static bool add_matrix_index(struct hlsl_ctx *ctx, struct list *instrs,
ret_type = hlsl_get_vector_type(ctx, mat_type->base_type, mat_type->dimx);
- name = vkd3d_string_buffer_get(&ctx->string_buffers); - vkd3d_string_buffer_printf(name, "<index-%u>", counter++); - var = hlsl_new_synthetic_var(ctx, name->buffer, ret_type, *loc); - vkd3d_string_buffer_release(&ctx->string_buffers, name); - if (!var) + if (!(var = hlsl_new_synthetic_var(ctx, "index", ret_type, loc))) return false; hlsl_init_simple_deref_from_var(&var_deref, var);
@@ -1247,8 +1223,6 @@ static struct hlsl_ir_node *add_expr(struct hlsl_ctx *ctx, struct list *instrs,
if (type->type == HLSL_CLASS_MATRIX) { - struct vkd3d_string_buffer *name; - static unsigned int counter = 0; struct hlsl_type *vector_type; struct hlsl_deref var_deref; struct hlsl_ir_load *load; @@ -1256,11 +1230,7 @@ static struct hlsl_ir_node *add_expr(struct hlsl_ctx *ctx, struct list *instrs,
vector_type = hlsl_get_vector_type(ctx, type->base_type, hlsl_type_minor_size(type));
- name = vkd3d_string_buffer_get(&ctx->string_buffers); - vkd3d_string_buffer_printf(name, "<split_op-%u>", counter++); - var = hlsl_new_synthetic_var(ctx, name->buffer, type, *loc); - vkd3d_string_buffer_release(&ctx->string_buffers, name); - if (!var) + if (!(var = hlsl_new_synthetic_var(ctx, "split_op", type, loc))) return NULL; hlsl_init_simple_deref_from_var(&var_deref, var);
@@ -2218,8 +2188,6 @@ static bool intrinsic_mul(struct hlsl_ctx *ctx, enum hlsl_base_type base = expr_common_base_type(arg1->data_type->base_type, arg2->data_type->base_type); struct hlsl_type *cast_type1 = arg1->data_type, *cast_type2 = arg2->data_type, *matrix_type, *ret_type; unsigned int i, j, k, vect_count = 0; - struct vkd3d_string_buffer *name; - static unsigned int counter = 0; struct hlsl_deref var_deref; struct hlsl_ir_load *load; struct hlsl_ir_var *var; @@ -2261,11 +2229,7 @@ static bool intrinsic_mul(struct hlsl_ctx *ctx, if (!(cast2 = add_implicit_conversion(ctx, params->instrs, arg2, cast_type2, loc))) return false;
- name = vkd3d_string_buffer_get(&ctx->string_buffers); - vkd3d_string_buffer_printf(name, "<mul-%u>", counter++); - var = hlsl_new_synthetic_var(ctx, name->buffer, matrix_type, *loc); - vkd3d_string_buffer_release(&ctx->string_buffers, name); - if (!var) + if (!(var = hlsl_new_synthetic_var(ctx, "mul", matrix_type, loc))) return false; hlsl_init_simple_deref_from_var(&var_deref, var);
@@ -2455,14 +2419,11 @@ static struct list *add_call(struct hlsl_ctx *ctx, const char *name, static struct list *add_constructor(struct hlsl_ctx *ctx, struct hlsl_type *type, struct parse_initializer *params, struct vkd3d_shader_location loc) { - static unsigned int counter; struct hlsl_ir_load *load; struct hlsl_ir_var *var; unsigned int i, idx = 0; - char name[23];
- sprintf(name, "<constructor-%x>", counter++); - if (!(var = hlsl_new_synthetic_var(ctx, name, type, loc))) + if (!(var = hlsl_new_synthetic_var(ctx, "constructor", type, &loc))) return NULL;
for (i = 0; i < params->args_count; ++i) @@ -4079,8 +4040,8 @@ primary_expr: struct hlsl_ir_load *load; struct hlsl_ir_var *var;
- if (!(var = hlsl_new_synthetic_var(ctx, "<state-block-expr>", - hlsl_get_scalar_type(ctx, HLSL_TYPE_INT), @1))) + if (!(var = hlsl_new_synthetic_var(ctx, "state_block_expr", + hlsl_get_scalar_type(ctx, HLSL_TYPE_INT), &@1))) YYABORT; if (!(load = hlsl_new_var_load(ctx, var, @1))) YYABORT;
From: Zebediah Figura zfigura@codeweavers.com
--- libs/vkd3d-shader/hlsl.c | 2 +- libs/vkd3d-shader/hlsl.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index da6d81b8..44211854 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -798,7 +798,7 @@ static bool type_is_single_reg(const struct hlsl_type *type) return type->type == HLSL_CLASS_SCALAR || type->type == HLSL_CLASS_VECTOR; }
-bool hlsl_copy_deref(struct hlsl_ctx *ctx, struct hlsl_deref *deref, struct hlsl_deref *other) +bool hlsl_copy_deref(struct hlsl_ctx *ctx, struct hlsl_deref *deref, const struct hlsl_deref *other) { unsigned int i;
diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 141b26ca..e39b2230 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -723,7 +723,7 @@ void hlsl_dump_function(struct hlsl_ctx *ctx, const struct hlsl_ir_function_decl int hlsl_emit_bytecode(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry_func, enum vkd3d_shader_target_type target_type, struct vkd3d_shader_code *out);
-bool hlsl_copy_deref(struct hlsl_ctx *ctx, struct hlsl_deref *deref, struct hlsl_deref *other); +bool hlsl_copy_deref(struct hlsl_ctx *ctx, struct hlsl_deref *deref, const struct hlsl_deref *other); void hlsl_cleanup_deref(struct hlsl_deref *deref);
void hlsl_replace_node(struct hlsl_ir_node *old, struct hlsl_ir_node *new);
From: Zebediah Figura zfigura@codeweavers.com
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. --- libs/vkd3d-shader/hlsl.c | 30 +++++------------ libs/vkd3d-shader/hlsl.h | 17 ++++++---- libs/vkd3d-shader/hlsl.y | 73 +++++++++++++++++++++------------------- 3 files changed, 57 insertions(+), 63 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 44211854..b222fb1d 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -1054,41 +1054,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; }
diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index e39b2230..3a51bc13 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -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); @@ -773,14 +781,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, diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index d6cd57a3..0a365865 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -2503,9 +2503,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 @@ -2526,7 +2525,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; } @@ -2536,12 +2535,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; @@ -2552,11 +2553,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) { @@ -2582,13 +2582,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; } @@ -2598,8 +2598,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);
@@ -2614,33 +2617,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; }
@@ -2671,7 +2671,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; } @@ -2696,17 +2696,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; @@ -2715,13 +2716,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) { @@ -2747,17 +2747,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; } @@ -2765,8 +2765,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;
This merge request was approved by Henri Verbeet.