Hi,
Il 20/07/22 15:23, Francisco Casas ha scritto:
-static void prepend_input_copy(struct hlsl_ctx *ctx, struct list *instrs, struct hlsl_ir_var *var,
struct hlsl_type *type, unsigned int field_offset, unsigned int modifiers, const struct hlsl_semantic *semantic)+static void prepend_input_copy(struct hlsl_ctx *ctx, struct list *instrs, struct hlsl_ir_load *lhs,
{struct hlsl_type *type, unsigned int modifiers, const struct hlsl_semantic *semantic)
- struct hlsl_ir_constant *offset;
- struct hlsl_ir_store *store;
- struct hlsl_ir_load *load;
- struct hlsl_ir_var *input;
- struct hlsl_type *vector_type = hlsl_get_vector_type(ctx, type->base_type, hlsl_type_minor_size(type));
- struct hlsl_ir_var *var = lhs->src.var;
- unsigned int i;
- if (type->type == HLSL_CLASS_MATRIX)
- for (i = 0; i < hlsl_type_major_size(type); ++i) {
struct hlsl_type *vector_type = hlsl_get_vector_type(ctx, type->base_type, hlsl_type_minor_size(type));struct hlsl_semantic vector_semantic = *semantic;unsigned int i;
struct hlsl_semantic semantic_copy = *semantic;struct hlsl_ir_store *store;struct hlsl_ir_constant *c;struct hlsl_ir_var *input;struct hlsl_ir_load *load;
for (i = 0; i < hlsl_type_major_size(type); ++i){prepend_input_copy(ctx, instrs, var, vector_type, 4 * i, modifiers, &vector_semantic);++vector_semantic.index;}
semantic_copy.index = semantic->index + i;
return;- }
if (!(input = add_semantic_var(ctx, var, vector_type, modifiers, &semantic_copy, false)))return;
- if (!(input = add_semantic_var(ctx, var, type, modifiers, semantic, false)))
return;
if (!(load = hlsl_new_var_load(ctx, input, var->loc)))return;list_add_after(&lhs->node.entry, &load->node.entry);
- if (!(load = hlsl_new_var_load(ctx, input, var->loc)))
return;- list_add_head(instrs, &load->node.entry);
if (type->type == HLSL_CLASS_MATRIX){if (!(c = hlsl_new_uint_constant(ctx, i, &var->loc)))return;list_add_after(&load->node.entry, &c->node.entry);
- if (!(offset = hlsl_new_uint_constant(ctx, field_offset, &var->loc)))
return;- list_add_after(&load->node.entry, &offset->node.entry);
if (!(store = hlsl_new_store_index(ctx, &lhs->src, &c->node, &load->node, 0, &var->loc)))return;list_add_after(&c->node.entry, &store->node.entry);}else{assert(i == 0);
- if (!(store = hlsl_new_store(ctx, var, &offset->node, &load->node, 0, var->loc)))
return;- list_add_after(&offset->node.entry, &store->node.entry);
if (!(store = hlsl_new_store_index(ctx, &lhs->src, NULL, &load->node, 0, &var->loc)))return;list_add_after(&load->node.entry, &store->node.entry);}- }
Here (and analogously in append_output_copy()) you can easily move the common call to hlsl_new_store_index() out of the conditional branch. I think it makes the code more readable.
Giovanni.