nir/tex_instr: Rename sampler to texture
[mesa.git] / src / compiler / nir / nir_clone.c
1 /*
2 * Copyright © 2015 Red Hat
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #include "nir.h"
25 #include "nir_control_flow_private.h"
26
27 /* Secret Decoder Ring:
28 * clone_foo():
29 * Allocate and clone a foo.
30 * __clone_foo():
31 * Clone body of foo (ie. parent class, embedded struct, etc)
32 */
33
34 typedef struct {
35 /* maps orig ptr -> cloned ptr: */
36 struct hash_table *ptr_table;
37
38 /* List of phi sources. */
39 struct list_head phi_srcs;
40
41 /* new shader object, used as memctx for just about everything else: */
42 nir_shader *ns;
43 } clone_state;
44
45 static void
46 init_clone_state(clone_state *state)
47 {
48 state->ptr_table = _mesa_hash_table_create(NULL, _mesa_hash_pointer,
49 _mesa_key_pointer_equal);
50 list_inithead(&state->phi_srcs);
51 }
52
53 static void
54 free_clone_state(clone_state *state)
55 {
56 _mesa_hash_table_destroy(state->ptr_table, NULL);
57 }
58
59 static void *
60 lookup_ptr(clone_state *state, const void *ptr)
61 {
62 struct hash_entry *entry;
63
64 if (!ptr)
65 return NULL;
66
67 entry = _mesa_hash_table_search(state->ptr_table, ptr);
68 assert(entry && "Failed to find pointer!");
69 if (!entry)
70 return NULL;
71
72 return entry->data;
73 }
74
75 static void
76 store_ptr(clone_state *state, void *nptr, const void *ptr)
77 {
78 _mesa_hash_table_insert(state->ptr_table, ptr, nptr);
79 }
80
81 static nir_constant *
82 clone_constant(clone_state *state, const nir_constant *c, nir_variable *nvar)
83 {
84 nir_constant *nc = ralloc(nvar, nir_constant);
85
86 nc->value = c->value;
87 nc->num_elements = c->num_elements;
88 nc->elements = ralloc_array(nvar, nir_constant *, c->num_elements);
89 for (unsigned i = 0; i < c->num_elements; i++) {
90 nc->elements[i] = clone_constant(state, c->elements[i], nvar);
91 }
92
93 return nc;
94 }
95
96 /* NOTE: for cloning nir_variable's, bypass nir_variable_create to avoid
97 * having to deal with locals and globals separately:
98 */
99 static nir_variable *
100 clone_variable(clone_state *state, const nir_variable *var)
101 {
102 nir_variable *nvar = rzalloc(state->ns, nir_variable);
103 store_ptr(state, nvar, var);
104
105 nvar->type = var->type;
106 nvar->name = ralloc_strdup(nvar, var->name);
107 nvar->data = var->data;
108 nvar->num_state_slots = var->num_state_slots;
109 nvar->state_slots = ralloc_array(nvar, nir_state_slot, var->num_state_slots);
110 memcpy(nvar->state_slots, var->state_slots,
111 var->num_state_slots * sizeof(nir_state_slot));
112 if (var->constant_initializer) {
113 nvar->constant_initializer =
114 clone_constant(state, var->constant_initializer, nvar);
115 }
116 nvar->interface_type = var->interface_type;
117
118 return nvar;
119 }
120
121 /* clone list of nir_variable: */
122 static void
123 clone_var_list(clone_state *state, struct exec_list *dst,
124 const struct exec_list *list)
125 {
126 exec_list_make_empty(dst);
127 foreach_list_typed(nir_variable, var, node, list) {
128 nir_variable *nvar = clone_variable(state, var);
129 exec_list_push_tail(dst, &nvar->node);
130 }
131 }
132
133 /* NOTE: for cloning nir_register's, bypass nir_global/local_reg_create()
134 * to avoid having to deal with locals and globals separately:
135 */
136 static nir_register *
137 clone_register(clone_state *state, const nir_register *reg)
138 {
139 nir_register *nreg = rzalloc(state->ns, nir_register);
140 store_ptr(state, nreg, reg);
141
142 nreg->num_components = reg->num_components;
143 nreg->num_array_elems = reg->num_array_elems;
144 nreg->index = reg->index;
145 nreg->name = ralloc_strdup(nreg, reg->name);
146 nreg->is_global = reg->is_global;
147 nreg->is_packed = reg->is_packed;
148
149 /* reconstructing uses/defs/if_uses handled by nir_instr_insert() */
150 list_inithead(&nreg->uses);
151 list_inithead(&nreg->defs);
152 list_inithead(&nreg->if_uses);
153
154 return nreg;
155 }
156
157 /* clone list of nir_register: */
158 static void
159 clone_reg_list(clone_state *state, struct exec_list *dst,
160 const struct exec_list *list)
161 {
162 exec_list_make_empty(dst);
163 foreach_list_typed(nir_register, reg, node, list) {
164 nir_register *nreg = clone_register(state, reg);
165 exec_list_push_tail(dst, &nreg->node);
166 }
167 }
168
169 static void
170 __clone_src(clone_state *state, void *ninstr_or_if,
171 nir_src *nsrc, const nir_src *src)
172 {
173 nsrc->is_ssa = src->is_ssa;
174 if (src->is_ssa) {
175 nsrc->ssa = lookup_ptr(state, src->ssa);
176 } else {
177 nsrc->reg.reg = lookup_ptr(state, src->reg.reg);
178 if (src->reg.indirect) {
179 nsrc->reg.indirect = ralloc(ninstr_or_if, nir_src);
180 __clone_src(state, ninstr_or_if, nsrc->reg.indirect, src->reg.indirect);
181 }
182 nsrc->reg.base_offset = src->reg.base_offset;
183 }
184 }
185
186 static void
187 __clone_dst(clone_state *state, nir_instr *ninstr,
188 nir_dest *ndst, const nir_dest *dst)
189 {
190 ndst->is_ssa = dst->is_ssa;
191 if (dst->is_ssa) {
192 nir_ssa_dest_init(ninstr, ndst, dst->ssa.num_components, dst->ssa.name);
193 store_ptr(state, &ndst->ssa, &dst->ssa);
194 } else {
195 ndst->reg.reg = lookup_ptr(state, dst->reg.reg);
196 if (dst->reg.indirect) {
197 ndst->reg.indirect = ralloc(ninstr, nir_src);
198 __clone_src(state, ninstr, ndst->reg.indirect, dst->reg.indirect);
199 }
200 ndst->reg.base_offset = dst->reg.base_offset;
201 }
202 }
203
204 static nir_deref *clone_deref(clone_state *state, const nir_deref *deref,
205 nir_instr *ninstr, nir_deref *parent);
206
207 static nir_deref_var *
208 clone_deref_var(clone_state *state, const nir_deref_var *dvar,
209 nir_instr *ninstr)
210 {
211 nir_variable *nvar = lookup_ptr(state, dvar->var);
212 nir_deref_var *ndvar = nir_deref_var_create(ninstr, nvar);
213
214 if (dvar->deref.child)
215 ndvar->deref.child = clone_deref(state, dvar->deref.child,
216 ninstr, &ndvar->deref);
217
218 return ndvar;
219 }
220
221 static nir_deref_array *
222 clone_deref_array(clone_state *state, const nir_deref_array *darr,
223 nir_instr *ninstr, nir_deref *parent)
224 {
225 nir_deref_array *ndarr = nir_deref_array_create(parent);
226
227 ndarr->deref.type = darr->deref.type;
228 if (darr->deref.child)
229 ndarr->deref.child = clone_deref(state, darr->deref.child,
230 ninstr, &ndarr->deref);
231
232 ndarr->deref_array_type = darr->deref_array_type;
233 ndarr->base_offset = darr->base_offset;
234 if (ndarr->deref_array_type == nir_deref_array_type_indirect)
235 __clone_src(state, ninstr, &ndarr->indirect, &darr->indirect);
236
237 return ndarr;
238 }
239
240 static nir_deref_struct *
241 clone_deref_struct(clone_state *state, const nir_deref_struct *dstr,
242 nir_instr *ninstr, nir_deref *parent)
243 {
244 nir_deref_struct *ndstr = nir_deref_struct_create(parent, dstr->index);
245
246 ndstr->deref.type = dstr->deref.type;
247 if (dstr->deref.child)
248 ndstr->deref.child = clone_deref(state, dstr->deref.child,
249 ninstr, &ndstr->deref);
250
251 return ndstr;
252 }
253
254 static nir_deref *
255 clone_deref(clone_state *state, const nir_deref *dref,
256 nir_instr *ninstr, nir_deref *parent)
257 {
258 switch (dref->deref_type) {
259 case nir_deref_type_array:
260 return &clone_deref_array(state, nir_deref_as_array(dref),
261 ninstr, parent)->deref;
262 case nir_deref_type_struct:
263 return &clone_deref_struct(state, nir_deref_as_struct(dref),
264 ninstr, parent)->deref;
265 default:
266 unreachable("bad deref type");
267 return NULL;
268 }
269 }
270
271 static nir_alu_instr *
272 clone_alu(clone_state *state, const nir_alu_instr *alu)
273 {
274 nir_alu_instr *nalu = nir_alu_instr_create(state->ns, alu->op);
275
276 __clone_dst(state, &nalu->instr, &nalu->dest.dest, &alu->dest.dest);
277 nalu->dest.saturate = alu->dest.saturate;
278 nalu->dest.write_mask = alu->dest.write_mask;
279
280 for (unsigned i = 0; i < nir_op_infos[alu->op].num_inputs; i++) {
281 __clone_src(state, &nalu->instr, &nalu->src[i].src, &alu->src[i].src);
282 nalu->src[i].negate = alu->src[i].negate;
283 nalu->src[i].abs = alu->src[i].abs;
284 memcpy(nalu->src[i].swizzle, alu->src[i].swizzle,
285 sizeof(nalu->src[i].swizzle));
286 }
287
288 return nalu;
289 }
290
291 static nir_intrinsic_instr *
292 clone_intrinsic(clone_state *state, const nir_intrinsic_instr *itr)
293 {
294 nir_intrinsic_instr *nitr =
295 nir_intrinsic_instr_create(state->ns, itr->intrinsic);
296
297 unsigned num_variables = nir_intrinsic_infos[itr->intrinsic].num_variables;
298 unsigned num_srcs = nir_intrinsic_infos[itr->intrinsic].num_srcs;
299
300 if (nir_intrinsic_infos[itr->intrinsic].has_dest)
301 __clone_dst(state, &nitr->instr, &nitr->dest, &itr->dest);
302
303 nitr->num_components = itr->num_components;
304 memcpy(nitr->const_index, itr->const_index, sizeof(nitr->const_index));
305
306 for (unsigned i = 0; i < num_variables; i++) {
307 nitr->variables[i] = clone_deref_var(state, itr->variables[i],
308 &nitr->instr);
309 }
310
311 for (unsigned i = 0; i < num_srcs; i++)
312 __clone_src(state, &nitr->instr, &nitr->src[i], &itr->src[i]);
313
314 return nitr;
315 }
316
317 static nir_load_const_instr *
318 clone_load_const(clone_state *state, const nir_load_const_instr *lc)
319 {
320 nir_load_const_instr *nlc =
321 nir_load_const_instr_create(state->ns, lc->def.num_components);
322
323 memcpy(&nlc->value, &lc->value, sizeof(nlc->value));
324
325 store_ptr(state, &nlc->def, &lc->def);
326
327 return nlc;
328 }
329
330 static nir_ssa_undef_instr *
331 clone_ssa_undef(clone_state *state, const nir_ssa_undef_instr *sa)
332 {
333 nir_ssa_undef_instr *nsa =
334 nir_ssa_undef_instr_create(state->ns, sa->def.num_components);
335
336 store_ptr(state, &nsa->def, &sa->def);
337
338 return nsa;
339 }
340
341 static nir_tex_instr *
342 clone_tex(clone_state *state, const nir_tex_instr *tex)
343 {
344 nir_tex_instr *ntex = nir_tex_instr_create(state->ns, tex->num_srcs);
345
346 ntex->sampler_dim = tex->sampler_dim;
347 ntex->dest_type = tex->dest_type;
348 ntex->op = tex->op;
349 __clone_dst(state, &ntex->instr, &ntex->dest, &tex->dest);
350 for (unsigned i = 0; i < ntex->num_srcs; i++) {
351 ntex->src[i].src_type = tex->src[i].src_type;
352 __clone_src(state, &ntex->instr, &ntex->src[i].src, &tex->src[i].src);
353 }
354 ntex->coord_components = tex->coord_components;
355 ntex->is_array = tex->is_array;
356 ntex->is_shadow = tex->is_shadow;
357 ntex->is_new_style_shadow = tex->is_new_style_shadow;
358 memcpy(ntex->const_offset, tex->const_offset, sizeof(ntex->const_offset));
359 ntex->component = tex->component;
360 ntex->texture_index = tex->texture_index;
361 ntex->texture_array_size = tex->texture_array_size;
362 if (tex->texture)
363 ntex->texture = clone_deref_var(state, tex->texture, &ntex->instr);
364
365 return ntex;
366 }
367
368 static nir_phi_instr *
369 clone_phi(clone_state *state, const nir_phi_instr *phi, nir_block *nblk)
370 {
371 nir_phi_instr *nphi = nir_phi_instr_create(state->ns);
372
373 __clone_dst(state, &nphi->instr, &nphi->dest, &phi->dest);
374
375 /* Cloning a phi node is a bit different from other instructions. The
376 * sources of phi instructions are the only time where we can use an SSA
377 * def before it is defined. In order to handle this, we just copy over
378 * the sources from the old phi instruction directly and then fix them up
379 * in a second pass once all the instrutions in the function have been
380 * properly cloned.
381 *
382 * In order to ensure that the copied sources (which are the same as the
383 * old phi instruction's sources for now) don't get inserted into the old
384 * shader's use-def lists, we have to add the phi instruction *before* we
385 * set up its sources.
386 */
387 nir_instr_insert_after_block(nblk, &nphi->instr);
388
389 foreach_list_typed(nir_phi_src, src, node, &phi->srcs) {
390 nir_phi_src *nsrc = ralloc(nphi, nir_phi_src);
391
392 /* Just copy the old source for now. */
393 memcpy(nsrc, src, sizeof(*src));
394
395 /* Since we're not letting nir_insert_instr handle use/def stuff for us,
396 * we have to set the parent_instr manually. It doesn't really matter
397 * when we do it, so we might as well do it here.
398 */
399 nsrc->src.parent_instr = &nphi->instr;
400
401 /* Stash it in the list of phi sources. We'll walk this list and fix up
402 * sources at the very end of clone_function_impl.
403 */
404 list_add(&nsrc->src.use_link, &state->phi_srcs);
405
406 exec_list_push_tail(&nphi->srcs, &nsrc->node);
407 }
408
409 return nphi;
410 }
411
412 static nir_jump_instr *
413 clone_jump(clone_state *state, const nir_jump_instr *jmp)
414 {
415 nir_jump_instr *njmp = nir_jump_instr_create(state->ns, jmp->type);
416
417 return njmp;
418 }
419
420 static nir_call_instr *
421 clone_call(clone_state *state, const nir_call_instr *call)
422 {
423 nir_function *ncallee = lookup_ptr(state, call->callee);
424 nir_call_instr *ncall = nir_call_instr_create(state->ns, ncallee);
425
426 for (unsigned i = 0; i < ncall->num_params; i++)
427 ncall->params[i] = clone_deref_var(state, call->params[i], &ncall->instr);
428
429 ncall->return_deref = clone_deref_var(state, call->return_deref,
430 &ncall->instr);
431
432 return ncall;
433 }
434
435 static nir_instr *
436 clone_instr(clone_state *state, const nir_instr *instr)
437 {
438 switch (instr->type) {
439 case nir_instr_type_alu:
440 return &clone_alu(state, nir_instr_as_alu(instr))->instr;
441 case nir_instr_type_intrinsic:
442 return &clone_intrinsic(state, nir_instr_as_intrinsic(instr))->instr;
443 case nir_instr_type_load_const:
444 return &clone_load_const(state, nir_instr_as_load_const(instr))->instr;
445 case nir_instr_type_ssa_undef:
446 return &clone_ssa_undef(state, nir_instr_as_ssa_undef(instr))->instr;
447 case nir_instr_type_tex:
448 return &clone_tex(state, nir_instr_as_tex(instr))->instr;
449 case nir_instr_type_phi:
450 unreachable("Cannot clone phis with clone_instr");
451 case nir_instr_type_jump:
452 return &clone_jump(state, nir_instr_as_jump(instr))->instr;
453 case nir_instr_type_call:
454 return &clone_call(state, nir_instr_as_call(instr))->instr;
455 case nir_instr_type_parallel_copy:
456 unreachable("Cannot clone parallel copies");
457 default:
458 unreachable("bad instr type");
459 return NULL;
460 }
461 }
462
463 static nir_block *
464 clone_block(clone_state *state, struct exec_list *cf_list, const nir_block *blk)
465 {
466 /* Don't actually create a new block. Just use the one from the tail of
467 * the list. NIR guarantees that the tail of the list is a block and that
468 * no two blocks are side-by-side in the IR; It should be empty.
469 */
470 nir_block *nblk =
471 exec_node_data(nir_block, exec_list_get_tail(cf_list), cf_node.node);
472 assert(nblk->cf_node.type == nir_cf_node_block);
473 assert(exec_list_is_empty(&nblk->instr_list));
474
475 /* We need this for phi sources */
476 store_ptr(state, nblk, blk);
477
478 nir_foreach_instr(blk, instr) {
479 if (instr->type == nir_instr_type_phi) {
480 /* Phi instructions are a bit of a special case when cloning because
481 * we don't want inserting the instruction to automatically handle
482 * use/defs for us. Instead, we need to wait until all the
483 * blocks/instructions are in so that we can set their sources up.
484 */
485 clone_phi(state, nir_instr_as_phi(instr), nblk);
486 } else {
487 nir_instr *ninstr = clone_instr(state, instr);
488 nir_instr_insert_after_block(nblk, ninstr);
489 }
490 }
491
492 return nblk;
493 }
494
495 static void
496 clone_cf_list(clone_state *state, struct exec_list *dst,
497 const struct exec_list *list);
498
499 static nir_if *
500 clone_if(clone_state *state, struct exec_list *cf_list, const nir_if *i)
501 {
502 nir_if *ni = nir_if_create(state->ns);
503
504 __clone_src(state, ni, &ni->condition, &i->condition);
505
506 nir_cf_node_insert_end(cf_list, &ni->cf_node);
507
508 clone_cf_list(state, &ni->then_list, &i->then_list);
509 clone_cf_list(state, &ni->else_list, &i->else_list);
510
511 return ni;
512 }
513
514 static nir_loop *
515 clone_loop(clone_state *state, struct exec_list *cf_list, const nir_loop *loop)
516 {
517 nir_loop *nloop = nir_loop_create(state->ns);
518
519 nir_cf_node_insert_end(cf_list, &nloop->cf_node);
520
521 clone_cf_list(state, &nloop->body, &loop->body);
522
523 return nloop;
524 }
525
526 /* clone list of nir_cf_node: */
527 static void
528 clone_cf_list(clone_state *state, struct exec_list *dst,
529 const struct exec_list *list)
530 {
531 foreach_list_typed(nir_cf_node, cf, node, list) {
532 switch (cf->type) {
533 case nir_cf_node_block:
534 clone_block(state, dst, nir_cf_node_as_block(cf));
535 break;
536 case nir_cf_node_if:
537 clone_if(state, dst, nir_cf_node_as_if(cf));
538 break;
539 case nir_cf_node_loop:
540 clone_loop(state, dst, nir_cf_node_as_loop(cf));
541 break;
542 default:
543 unreachable("bad cf type");
544 }
545 }
546 }
547
548 static nir_function_impl *
549 clone_function_impl(clone_state *state, const nir_function_impl *fi,
550 nir_function *nfxn)
551 {
552 nir_function_impl *nfi = nir_function_impl_create(nfxn);
553
554 clone_var_list(state, &nfi->locals, &fi->locals);
555 clone_reg_list(state, &nfi->registers, &fi->registers);
556 nfi->reg_alloc = fi->reg_alloc;
557
558 nfi->num_params = fi->num_params;
559 nfi->params = ralloc_array(state->ns, nir_variable *, fi->num_params);
560 for (unsigned i = 0; i < fi->num_params; i++) {
561 nfi->params[i] = lookup_ptr(state, fi->params[i]);
562 }
563 nfi->return_var = lookup_ptr(state, fi->return_var);
564
565 assert(list_empty(&state->phi_srcs));
566
567 clone_cf_list(state, &nfi->body, &fi->body);
568
569 /* After we've cloned almost everything, we have to walk the list of phi
570 * sources and fix them up. Thanks to loops, the block and SSA value for a
571 * phi source may not be defined when we first encounter it. Instead, we
572 * add it to the phi_srcs list and we fix it up here.
573 */
574 list_for_each_entry_safe(nir_phi_src, src, &state->phi_srcs, src.use_link) {
575 src->pred = lookup_ptr(state, src->pred);
576 assert(src->src.is_ssa);
577 src->src.ssa = lookup_ptr(state, src->src.ssa);
578
579 /* Remove from this list and place in the uses of the SSA def */
580 list_del(&src->src.use_link);
581 list_addtail(&src->src.use_link, &src->src.ssa->uses);
582 }
583 assert(list_empty(&state->phi_srcs));
584
585 /* All metadata is invalidated in the cloning process */
586 nfi->valid_metadata = 0;
587
588 return nfi;
589 }
590
591 static nir_function *
592 clone_function(clone_state *state, const nir_function *fxn, nir_shader *ns)
593 {
594 assert(ns == state->ns);
595 nir_function *nfxn = nir_function_create(ns, fxn->name);
596
597 /* Needed for call instructions */
598 store_ptr(state, nfxn, fxn);
599
600 nfxn->num_params = fxn->num_params;
601 nfxn->params = ralloc_array(state->ns, nir_parameter, fxn->num_params);
602 memcpy(nfxn->params, fxn->params, sizeof(nir_parameter) * fxn->num_params);
603
604 nfxn->return_type = fxn->return_type;
605
606 /* At first glance, it looks like we should clone the function_impl here.
607 * However, call instructions need to be able to reference at least the
608 * function and those will get processed as we clone the function_impl's.
609 * We stop here and do function_impls as a second pass.
610 */
611
612 return nfxn;
613 }
614
615 nir_shader *
616 nir_shader_clone(void *mem_ctx, const nir_shader *s)
617 {
618 clone_state state;
619 init_clone_state(&state);
620
621 nir_shader *ns = nir_shader_create(mem_ctx, s->stage, s->options);
622 state.ns = ns;
623
624 clone_var_list(&state, &ns->uniforms, &s->uniforms);
625 clone_var_list(&state, &ns->inputs, &s->inputs);
626 clone_var_list(&state, &ns->outputs, &s->outputs);
627 clone_var_list(&state, &ns->globals, &s->globals);
628 clone_var_list(&state, &ns->system_values, &s->system_values);
629
630 /* Go through and clone functions */
631 foreach_list_typed(nir_function, fxn, node, &s->functions)
632 clone_function(&state, fxn, ns);
633
634 /* Only after all functions are cloned can we clone the actual function
635 * implementations. This is because nir_call_instr's need to reference the
636 * functions of other functions and we don't know what order the functions
637 * will have in the list.
638 */
639 nir_foreach_function(s, fxn) {
640 nir_function *nfxn = lookup_ptr(&state, fxn);
641 clone_function_impl(&state, fxn->impl, nfxn);
642 }
643
644 clone_reg_list(&state, &ns->registers, &s->registers);
645 ns->reg_alloc = s->reg_alloc;
646
647 ns->info = s->info;
648 ns->info.name = ralloc_strdup(ns, ns->info.name);
649 if (ns->info.label)
650 ns->info.label = ralloc_strdup(ns, ns->info.label);
651
652 ns->num_inputs = s->num_inputs;
653 ns->num_uniforms = s->num_uniforms;
654 ns->num_outputs = s->num_outputs;
655
656 free_clone_state(&state);
657
658 return ns;
659 }