X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fcompiler%2Fnir%2Fnir_clone.c;h=f57fce599c1c7af127bb5bc24b7920520667b106;hb=d70fff99c5bc3a721e20869e7f0be8024ffe5ecd;hp=a45a581bd05fcc8e352fda5ea5f99d3460c490f8;hpb=6279074de18444152a3ab2f3b870d1779dd9726f;p=mesa.git diff --git a/src/compiler/nir/nir_clone.c b/src/compiler/nir/nir_clone.c index a45a581bd05..f57fce599c1 100644 --- a/src/compiler/nir/nir_clone.c +++ b/src/compiler/nir/nir_clone.c @@ -85,6 +85,11 @@ _lookup_ptr(clone_state *state, const void *ptr, bool global) if (!state->global_clone && global) return (void *)ptr; + if (unlikely(!state->remap_table)) { + assert(state->allow_remap_fallback); + return (void *)ptr; + } + entry = _mesa_hash_table_search(state->remap_table, ptr); if (!entry) { assert(state->allow_remap_fallback); @@ -151,9 +156,11 @@ nir_variable_clone(const nir_variable *var, nir_shader *shader) nvar->name = ralloc_strdup(nvar, var->name); nvar->data = var->data; nvar->num_state_slots = var->num_state_slots; - nvar->state_slots = ralloc_array(nvar, nir_state_slot, var->num_state_slots); - memcpy(nvar->state_slots, var->state_slots, - var->num_state_slots * sizeof(nir_state_slot)); + if (var->num_state_slots) { + nvar->state_slots = ralloc_array(nvar, nir_state_slot, var->num_state_slots); + memcpy(nvar->state_slots, var->state_slots, + var->num_state_slots * sizeof(nir_state_slot)); + } if (var->constant_initializer) { nvar->constant_initializer = nir_constant_clone(var->constant_initializer, nvar); @@ -252,7 +259,8 @@ __clone_dst(clone_state *state, nir_instr *ninstr, if (dst->is_ssa) { nir_ssa_dest_init(ninstr, ndst, dst->ssa.num_components, dst->ssa.bit_size, dst->ssa.name); - add_remap(state, &ndst->ssa, &dst->ssa); + if (likely(state->remap_table)) + add_remap(state, &ndst->ssa, &dst->ssa); } else { ndst->reg.reg = remap_reg(state, dst->reg.reg); if (dst->reg.indirect) { @@ -268,6 +276,8 @@ clone_alu(clone_state *state, const nir_alu_instr *alu) { nir_alu_instr *nalu = nir_alu_instr_create(state->ns, alu->op); nalu->exact = alu->exact; + nalu->no_signed_wrap = alu->no_signed_wrap; + nalu->no_unsigned_wrap = alu->no_unsigned_wrap; __clone_dst(state, &nalu->instr, &nalu->dest.dest, &alu->dest.dest); nalu->dest.saturate = alu->dest.saturate; @@ -284,6 +294,16 @@ clone_alu(clone_state *state, const nir_alu_instr *alu) return nalu; } +nir_alu_instr * +nir_alu_instr_clone(nir_shader *shader, const nir_alu_instr *orig) +{ + clone_state state = { + .allow_remap_fallback = true, + .ns = shader, + }; + return clone_alu(&state, orig); +} + static nir_deref_instr * clone_deref_instr(clone_state *state, const nir_deref_instr *deref) { @@ -355,7 +375,7 @@ clone_load_const(clone_state *state, const nir_load_const_instr *lc) nir_load_const_instr_create(state->ns, lc->def.num_components, lc->def.bit_size); - memcpy(&nlc->value, &lc->value, sizeof(nlc->value)); + memcpy(&nlc->value, &lc->value, sizeof(*nlc->value) * lc->def.num_components); add_remap(state, &nlc->def, &lc->def); @@ -395,9 +415,11 @@ clone_tex(clone_state *state, const nir_tex_instr *tex) memcpy(ntex->tg4_offsets, tex->tg4_offsets, sizeof(tex->tg4_offsets)); ntex->texture_index = tex->texture_index; - ntex->texture_array_size = tex->texture_array_size; ntex->sampler_index = tex->sampler_index; + ntex->texture_non_uniform = tex->texture_non_uniform; + ntex->sampler_non_uniform = tex->sampler_non_uniform; + return ntex; } @@ -605,7 +627,7 @@ fixup_phi_srcs(clone_state *state) list_addtail(&src->src.use_link, &src->src.reg.reg->uses); } } - assert(list_empty(&state->phi_srcs)); + assert(list_is_empty(&state->phi_srcs)); } void @@ -645,7 +667,7 @@ clone_function_impl(clone_state *state, const nir_function_impl *fi) clone_reg_list(state, &nfi->registers, &fi->registers); nfi->reg_alloc = fi->reg_alloc; - assert(list_empty(&state->phi_srcs)); + assert(list_is_empty(&state->phi_srcs)); clone_cf_list(state, &nfi->body, &fi->body); @@ -682,8 +704,10 @@ clone_function(clone_state *state, const nir_function *fxn, nir_shader *ns) add_remap(state, nfxn, fxn); nfxn->num_params = fxn->num_params; - nfxn->params = ralloc_array(state->ns, nir_parameter, fxn->num_params); - memcpy(nfxn->params, fxn->params, sizeof(nir_parameter) * fxn->num_params); + if (fxn->num_params) { + nfxn->params = ralloc_array(state->ns, nir_parameter, fxn->num_params); + memcpy(nfxn->params, fxn->params, sizeof(nir_parameter) * fxn->num_params); + } nfxn->is_entrypoint = fxn->is_entrypoint; /* At first glance, it looks like we should clone the function_impl here. @@ -704,12 +728,7 @@ nir_shader_clone(void *mem_ctx, const nir_shader *s) nir_shader *ns = nir_shader_create(mem_ctx, s->info.stage, s->options, NULL); state.ns = ns; - clone_var_list(&state, &ns->uniforms, &s->uniforms); - clone_var_list(&state, &ns->inputs, &s->inputs); - clone_var_list(&state, &ns->outputs, &s->outputs); - clone_var_list(&state, &ns->shared, &s->shared); - clone_var_list(&state, &ns->globals, &s->globals); - clone_var_list(&state, &ns->system_values, &s->system_values); + clone_var_list(&state, &ns->variables, &s->variables); /* Go through and clone functions */ foreach_list_typed(nir_function, fxn, node, &s->functions) @@ -735,6 +754,7 @@ nir_shader_clone(void *mem_ctx, const nir_shader *s) ns->num_uniforms = s->num_uniforms; ns->num_outputs = s->num_outputs; ns->num_shared = s->num_shared; + ns->scratch_size = s->scratch_size; ns->constant_data_size = s->constant_data_size; if (s->constant_data_size > 0) { @@ -746,3 +766,37 @@ nir_shader_clone(void *mem_ctx, const nir_shader *s) return ns; } + +/** Overwrites dst and replaces its contents with src + * + * Everything ralloc parented to dst and src itself (but not its children) + * will be freed. + * + * This should only be used by test code which needs to swap out shaders with + * a cloned or deserialized version. + */ +void +nir_shader_replace(nir_shader *dst, nir_shader *src) +{ + /* Delete all of dest's ralloc children */ + void *dead_ctx = ralloc_context(NULL); + ralloc_adopt(dead_ctx, dst); + ralloc_free(dead_ctx); + + /* Re-parent all of src's ralloc children to dst */ + ralloc_adopt(dst, src); + + memcpy(dst, src, sizeof(*dst)); + + /* We have to move all the linked lists over separately because we need the + * pointers in the list elements to point to the lists in dst and not src. + */ + exec_list_move_nodes_to(&src->variables, &dst->variables); + + /* Now move the functions over. This takes a tiny bit more work */ + exec_list_move_nodes_to(&src->functions, &dst->functions); + nir_foreach_function(function, dst) + function->shader = dst; + + ralloc_free(src); +}