gallium: add TGSI property NEXT_SHADER
[mesa.git] / src / gallium / auxiliary / tgsi / tgsi_ureg.c
1 /**************************************************************************
2 *
3 * Copyright 2009-2010 VMware, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE, INC AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28
29 #include "pipe/p_screen.h"
30 #include "pipe/p_context.h"
31 #include "pipe/p_state.h"
32 #include "tgsi/tgsi_ureg.h"
33 #include "tgsi/tgsi_build.h"
34 #include "tgsi/tgsi_info.h"
35 #include "tgsi/tgsi_dump.h"
36 #include "tgsi/tgsi_sanity.h"
37 #include "util/u_debug.h"
38 #include "util/u_inlines.h"
39 #include "util/u_memory.h"
40 #include "util/u_math.h"
41 #include "util/u_bitmask.h"
42
43 union tgsi_any_token {
44 struct tgsi_header header;
45 struct tgsi_processor processor;
46 struct tgsi_token token;
47 struct tgsi_property prop;
48 struct tgsi_property_data prop_data;
49 struct tgsi_declaration decl;
50 struct tgsi_declaration_range decl_range;
51 struct tgsi_declaration_dimension decl_dim;
52 struct tgsi_declaration_interp decl_interp;
53 struct tgsi_declaration_image decl_image;
54 struct tgsi_declaration_semantic decl_semantic;
55 struct tgsi_declaration_sampler_view decl_sampler_view;
56 struct tgsi_declaration_array array;
57 struct tgsi_immediate imm;
58 union tgsi_immediate_data imm_data;
59 struct tgsi_instruction insn;
60 struct tgsi_instruction_predicate insn_predicate;
61 struct tgsi_instruction_label insn_label;
62 struct tgsi_instruction_texture insn_texture;
63 struct tgsi_instruction_memory insn_memory;
64 struct tgsi_texture_offset insn_texture_offset;
65 struct tgsi_src_register src;
66 struct tgsi_ind_register ind;
67 struct tgsi_dimension dim;
68 struct tgsi_dst_register dst;
69 unsigned value;
70 };
71
72
73 struct ureg_tokens {
74 union tgsi_any_token *tokens;
75 unsigned size;
76 unsigned order;
77 unsigned count;
78 };
79
80 #define UREG_MAX_INPUT PIPE_MAX_SHADER_INPUTS
81 #define UREG_MAX_SYSTEM_VALUE PIPE_MAX_ATTRIBS
82 #define UREG_MAX_OUTPUT PIPE_MAX_SHADER_OUTPUTS
83 #define UREG_MAX_CONSTANT_RANGE 32
84 #define UREG_MAX_IMMEDIATE 4096
85 #define UREG_MAX_ADDR 3
86 #define UREG_MAX_PRED 1
87 #define UREG_MAX_ARRAY_TEMPS 256
88
89 struct const_decl {
90 struct {
91 unsigned first;
92 unsigned last;
93 } constant_range[UREG_MAX_CONSTANT_RANGE];
94 unsigned nr_constant_ranges;
95 };
96
97 #define DOMAIN_DECL 0
98 #define DOMAIN_INSN 1
99
100 struct ureg_program
101 {
102 unsigned processor;
103 bool supports_any_inout_decl_range;
104 int next_shader_processor;
105
106 struct {
107 unsigned semantic_name;
108 unsigned semantic_index;
109 unsigned interp;
110 unsigned char cylindrical_wrap;
111 unsigned interp_location;
112 unsigned first;
113 unsigned last;
114 unsigned array_id;
115 } input[UREG_MAX_INPUT];
116 unsigned nr_inputs, nr_input_regs;
117
118 unsigned vs_inputs[PIPE_MAX_ATTRIBS/32];
119
120 struct {
121 unsigned semantic_name;
122 unsigned semantic_index;
123 } system_value[UREG_MAX_SYSTEM_VALUE];
124 unsigned nr_system_values;
125
126 struct {
127 unsigned semantic_name;
128 unsigned semantic_index;
129 unsigned usage_mask; /* = TGSI_WRITEMASK_* */
130 unsigned first;
131 unsigned last;
132 unsigned array_id;
133 } output[UREG_MAX_OUTPUT];
134 unsigned nr_outputs, nr_output_regs;
135
136 struct {
137 union {
138 float f[4];
139 unsigned u[4];
140 int i[4];
141 } value;
142 unsigned nr;
143 unsigned type;
144 } immediate[UREG_MAX_IMMEDIATE];
145 unsigned nr_immediates;
146
147 struct ureg_src sampler[PIPE_MAX_SAMPLERS];
148 unsigned nr_samplers;
149
150 struct {
151 unsigned index;
152 unsigned target;
153 unsigned return_type_x;
154 unsigned return_type_y;
155 unsigned return_type_z;
156 unsigned return_type_w;
157 } sampler_view[PIPE_MAX_SHADER_SAMPLER_VIEWS];
158 unsigned nr_sampler_views;
159
160 struct {
161 unsigned index;
162 unsigned target;
163 unsigned format;
164 boolean wr;
165 boolean raw;
166 } image[PIPE_MAX_SHADER_IMAGES];
167 unsigned nr_images;
168
169 struct {
170 unsigned index;
171 bool atomic;
172 } buffer[PIPE_MAX_SHADER_BUFFERS];
173 unsigned nr_buffers;
174
175 struct util_bitmask *free_temps;
176 struct util_bitmask *local_temps;
177 struct util_bitmask *decl_temps;
178 unsigned nr_temps;
179
180 unsigned array_temps[UREG_MAX_ARRAY_TEMPS];
181 unsigned nr_array_temps;
182
183 struct const_decl const_decls;
184 struct const_decl const_decls2D[PIPE_MAX_CONSTANT_BUFFERS];
185
186 unsigned properties[TGSI_PROPERTY_COUNT];
187
188 unsigned nr_addrs;
189 unsigned nr_preds;
190 unsigned nr_instructions;
191
192 struct ureg_tokens domain[2];
193
194 bool use_shared_memory;
195 };
196
197 static union tgsi_any_token error_tokens[32];
198
199 static void tokens_error( struct ureg_tokens *tokens )
200 {
201 if (tokens->tokens && tokens->tokens != error_tokens)
202 FREE(tokens->tokens);
203
204 tokens->tokens = error_tokens;
205 tokens->size = Elements(error_tokens);
206 tokens->count = 0;
207 }
208
209
210 static void tokens_expand( struct ureg_tokens *tokens,
211 unsigned count )
212 {
213 unsigned old_size = tokens->size * sizeof(unsigned);
214
215 if (tokens->tokens == error_tokens) {
216 return;
217 }
218
219 while (tokens->count + count > tokens->size) {
220 tokens->size = (1 << ++tokens->order);
221 }
222
223 tokens->tokens = REALLOC(tokens->tokens,
224 old_size,
225 tokens->size * sizeof(unsigned));
226 if (tokens->tokens == NULL) {
227 tokens_error(tokens);
228 }
229 }
230
231 static void set_bad( struct ureg_program *ureg )
232 {
233 tokens_error(&ureg->domain[0]);
234 }
235
236
237
238 static union tgsi_any_token *get_tokens( struct ureg_program *ureg,
239 unsigned domain,
240 unsigned count )
241 {
242 struct ureg_tokens *tokens = &ureg->domain[domain];
243 union tgsi_any_token *result;
244
245 if (tokens->count + count > tokens->size)
246 tokens_expand(tokens, count);
247
248 result = &tokens->tokens[tokens->count];
249 tokens->count += count;
250 return result;
251 }
252
253
254 static union tgsi_any_token *retrieve_token( struct ureg_program *ureg,
255 unsigned domain,
256 unsigned nr )
257 {
258 if (ureg->domain[domain].tokens == error_tokens)
259 return &error_tokens[0];
260
261 return &ureg->domain[domain].tokens[nr];
262 }
263
264 void
265 ureg_property(struct ureg_program *ureg, unsigned name, unsigned value)
266 {
267 assert(name < Elements(ureg->properties));
268 ureg->properties[name] = value;
269 }
270
271 struct ureg_src
272 ureg_DECL_fs_input_cyl_centroid(struct ureg_program *ureg,
273 unsigned semantic_name,
274 unsigned semantic_index,
275 unsigned interp_mode,
276 unsigned cylindrical_wrap,
277 unsigned interp_location,
278 unsigned array_id,
279 unsigned array_size)
280 {
281 unsigned i;
282
283 for (i = 0; i < ureg->nr_inputs; i++) {
284 if (ureg->input[i].semantic_name == semantic_name &&
285 ureg->input[i].semantic_index == semantic_index) {
286 assert(ureg->input[i].interp == interp_mode);
287 assert(ureg->input[i].cylindrical_wrap == cylindrical_wrap);
288 assert(ureg->input[i].interp_location == interp_location);
289 assert(ureg->input[i].array_id == array_id);
290 goto out;
291 }
292 }
293
294 if (ureg->nr_inputs < UREG_MAX_INPUT) {
295 assert(array_size >= 1);
296 ureg->input[i].semantic_name = semantic_name;
297 ureg->input[i].semantic_index = semantic_index;
298 ureg->input[i].interp = interp_mode;
299 ureg->input[i].cylindrical_wrap = cylindrical_wrap;
300 ureg->input[i].interp_location = interp_location;
301 ureg->input[i].first = ureg->nr_input_regs;
302 ureg->input[i].last = ureg->nr_input_regs + array_size - 1;
303 ureg->input[i].array_id = array_id;
304 ureg->nr_input_regs += array_size;
305 ureg->nr_inputs++;
306 } else {
307 set_bad(ureg);
308 }
309
310 out:
311 return ureg_src_array_register(TGSI_FILE_INPUT, ureg->input[i].first,
312 array_id);
313 }
314
315
316 struct ureg_src
317 ureg_DECL_vs_input( struct ureg_program *ureg,
318 unsigned index )
319 {
320 assert(ureg->processor == TGSI_PROCESSOR_VERTEX);
321 assert(index / 32 < ARRAY_SIZE(ureg->vs_inputs));
322
323 ureg->vs_inputs[index/32] |= 1 << (index % 32);
324 return ureg_src_register( TGSI_FILE_INPUT, index );
325 }
326
327
328 struct ureg_src
329 ureg_DECL_input(struct ureg_program *ureg,
330 unsigned semantic_name,
331 unsigned semantic_index,
332 unsigned array_id,
333 unsigned array_size)
334 {
335 return ureg_DECL_fs_input_cyl_centroid(ureg, semantic_name, semantic_index,
336 0, 0, 0, array_id, array_size);
337 }
338
339
340 struct ureg_src
341 ureg_DECL_system_value(struct ureg_program *ureg,
342 unsigned semantic_name,
343 unsigned semantic_index)
344 {
345 unsigned i;
346
347 for (i = 0; i < ureg->nr_system_values; i++) {
348 if (ureg->system_value[i].semantic_name == semantic_name &&
349 ureg->system_value[i].semantic_index == semantic_index) {
350 goto out;
351 }
352 }
353
354 if (ureg->nr_system_values < UREG_MAX_SYSTEM_VALUE) {
355 ureg->system_value[ureg->nr_system_values].semantic_name = semantic_name;
356 ureg->system_value[ureg->nr_system_values].semantic_index = semantic_index;
357 i = ureg->nr_system_values;
358 ureg->nr_system_values++;
359 } else {
360 set_bad(ureg);
361 }
362
363 out:
364 return ureg_src_register(TGSI_FILE_SYSTEM_VALUE, i);
365 }
366
367
368 struct ureg_dst
369 ureg_DECL_output_masked(struct ureg_program *ureg,
370 unsigned name,
371 unsigned index,
372 unsigned usage_mask,
373 unsigned array_id,
374 unsigned array_size)
375 {
376 unsigned i;
377
378 assert(usage_mask != 0);
379
380 for (i = 0; i < ureg->nr_outputs; i++) {
381 if (ureg->output[i].semantic_name == name &&
382 ureg->output[i].semantic_index == index) {
383 assert(ureg->output[i].array_id == array_id);
384 ureg->output[i].usage_mask |= usage_mask;
385 goto out;
386 }
387 }
388
389 if (ureg->nr_outputs < UREG_MAX_OUTPUT) {
390 ureg->output[i].semantic_name = name;
391 ureg->output[i].semantic_index = index;
392 ureg->output[i].usage_mask = usage_mask;
393 ureg->output[i].first = ureg->nr_output_regs;
394 ureg->output[i].last = ureg->nr_output_regs + array_size - 1;
395 ureg->output[i].array_id = array_id;
396 ureg->nr_output_regs += array_size;
397 ureg->nr_outputs++;
398 }
399 else {
400 set_bad( ureg );
401 }
402
403 out:
404 return ureg_dst_array_register(TGSI_FILE_OUTPUT, ureg->output[i].first,
405 array_id);
406 }
407
408
409 struct ureg_dst
410 ureg_DECL_output(struct ureg_program *ureg,
411 unsigned name,
412 unsigned index)
413 {
414 return ureg_DECL_output_masked(ureg, name, index, TGSI_WRITEMASK_XYZW,
415 0, 1);
416 }
417
418 struct ureg_dst
419 ureg_DECL_output_array(struct ureg_program *ureg,
420 unsigned semantic_name,
421 unsigned semantic_index,
422 unsigned array_id,
423 unsigned array_size)
424 {
425 return ureg_DECL_output_masked(ureg, semantic_name, semantic_index,
426 TGSI_WRITEMASK_XYZW,
427 array_id, array_size);
428 }
429
430
431 /* Returns a new constant register. Keep track of which have been
432 * referred to so that we can emit decls later.
433 *
434 * Constant operands declared with this function must be addressed
435 * with a two-dimensional index.
436 *
437 * There is nothing in this code to bind this constant to any tracked
438 * value or manage any constant_buffer contents -- that's the
439 * resposibility of the calling code.
440 */
441 void
442 ureg_DECL_constant2D(struct ureg_program *ureg,
443 unsigned first,
444 unsigned last,
445 unsigned index2D)
446 {
447 struct const_decl *decl = &ureg->const_decls2D[index2D];
448
449 assert(index2D < PIPE_MAX_CONSTANT_BUFFERS);
450
451 if (decl->nr_constant_ranges < UREG_MAX_CONSTANT_RANGE) {
452 uint i = decl->nr_constant_ranges++;
453
454 decl->constant_range[i].first = first;
455 decl->constant_range[i].last = last;
456 }
457 }
458
459
460 /* A one-dimensional, depricated version of ureg_DECL_constant2D().
461 *
462 * Constant operands declared with this function must be addressed
463 * with a one-dimensional index.
464 */
465 struct ureg_src
466 ureg_DECL_constant(struct ureg_program *ureg,
467 unsigned index)
468 {
469 struct const_decl *decl = &ureg->const_decls;
470 unsigned minconst = index, maxconst = index;
471 unsigned i;
472
473 /* Inside existing range?
474 */
475 for (i = 0; i < decl->nr_constant_ranges; i++) {
476 if (decl->constant_range[i].first <= index &&
477 decl->constant_range[i].last >= index) {
478 goto out;
479 }
480 }
481
482 /* Extend existing range?
483 */
484 for (i = 0; i < decl->nr_constant_ranges; i++) {
485 if (decl->constant_range[i].last == index - 1) {
486 decl->constant_range[i].last = index;
487 goto out;
488 }
489
490 if (decl->constant_range[i].first == index + 1) {
491 decl->constant_range[i].first = index;
492 goto out;
493 }
494
495 minconst = MIN2(minconst, decl->constant_range[i].first);
496 maxconst = MAX2(maxconst, decl->constant_range[i].last);
497 }
498
499 /* Create new range?
500 */
501 if (decl->nr_constant_ranges < UREG_MAX_CONSTANT_RANGE) {
502 i = decl->nr_constant_ranges++;
503 decl->constant_range[i].first = index;
504 decl->constant_range[i].last = index;
505 goto out;
506 }
507
508 /* Collapse all ranges down to one:
509 */
510 i = 0;
511 decl->constant_range[0].first = minconst;
512 decl->constant_range[0].last = maxconst;
513 decl->nr_constant_ranges = 1;
514
515 out:
516 assert(i < decl->nr_constant_ranges);
517 assert(decl->constant_range[i].first <= index);
518 assert(decl->constant_range[i].last >= index);
519 return ureg_src_register(TGSI_FILE_CONSTANT, index);
520 }
521
522 static struct ureg_dst alloc_temporary( struct ureg_program *ureg,
523 boolean local )
524 {
525 unsigned i;
526
527 /* Look for a released temporary.
528 */
529 for (i = util_bitmask_get_first_index(ureg->free_temps);
530 i != UTIL_BITMASK_INVALID_INDEX;
531 i = util_bitmask_get_next_index(ureg->free_temps, i + 1)) {
532 if (util_bitmask_get(ureg->local_temps, i) == local)
533 break;
534 }
535
536 /* Or allocate a new one.
537 */
538 if (i == UTIL_BITMASK_INVALID_INDEX) {
539 i = ureg->nr_temps++;
540
541 if (local)
542 util_bitmask_set(ureg->local_temps, i);
543
544 /* Start a new declaration when the local flag changes */
545 if (!i || util_bitmask_get(ureg->local_temps, i - 1) != local)
546 util_bitmask_set(ureg->decl_temps, i);
547 }
548
549 util_bitmask_clear(ureg->free_temps, i);
550
551 return ureg_dst_register( TGSI_FILE_TEMPORARY, i );
552 }
553
554 struct ureg_dst ureg_DECL_temporary( struct ureg_program *ureg )
555 {
556 return alloc_temporary(ureg, FALSE);
557 }
558
559 struct ureg_dst ureg_DECL_local_temporary( struct ureg_program *ureg )
560 {
561 return alloc_temporary(ureg, TRUE);
562 }
563
564 struct ureg_dst ureg_DECL_array_temporary( struct ureg_program *ureg,
565 unsigned size,
566 boolean local )
567 {
568 unsigned i = ureg->nr_temps;
569 struct ureg_dst dst = ureg_dst_register( TGSI_FILE_TEMPORARY, i );
570
571 if (local)
572 util_bitmask_set(ureg->local_temps, i);
573
574 /* Always start a new declaration at the start */
575 util_bitmask_set(ureg->decl_temps, i);
576
577 ureg->nr_temps += size;
578
579 /* and also at the end of the array */
580 util_bitmask_set(ureg->decl_temps, ureg->nr_temps);
581
582 if (ureg->nr_array_temps < UREG_MAX_ARRAY_TEMPS) {
583 ureg->array_temps[ureg->nr_array_temps++] = i;
584 dst.ArrayID = ureg->nr_array_temps;
585 }
586
587 return dst;
588 }
589
590 void ureg_release_temporary( struct ureg_program *ureg,
591 struct ureg_dst tmp )
592 {
593 if(tmp.File == TGSI_FILE_TEMPORARY)
594 util_bitmask_set(ureg->free_temps, tmp.Index);
595 }
596
597
598 /* Allocate a new address register.
599 */
600 struct ureg_dst ureg_DECL_address( struct ureg_program *ureg )
601 {
602 if (ureg->nr_addrs < UREG_MAX_ADDR)
603 return ureg_dst_register( TGSI_FILE_ADDRESS, ureg->nr_addrs++ );
604
605 assert( 0 );
606 return ureg_dst_register( TGSI_FILE_ADDRESS, 0 );
607 }
608
609 /* Allocate a new predicate register.
610 */
611 struct ureg_dst
612 ureg_DECL_predicate(struct ureg_program *ureg)
613 {
614 if (ureg->nr_preds < UREG_MAX_PRED) {
615 return ureg_dst_register(TGSI_FILE_PREDICATE, ureg->nr_preds++);
616 }
617
618 assert(0);
619 return ureg_dst_register(TGSI_FILE_PREDICATE, 0);
620 }
621
622 /* Allocate a new sampler.
623 */
624 struct ureg_src ureg_DECL_sampler( struct ureg_program *ureg,
625 unsigned nr )
626 {
627 unsigned i;
628
629 for (i = 0; i < ureg->nr_samplers; i++)
630 if (ureg->sampler[i].Index == nr)
631 return ureg->sampler[i];
632
633 if (i < PIPE_MAX_SAMPLERS) {
634 ureg->sampler[i] = ureg_src_register( TGSI_FILE_SAMPLER, nr );
635 ureg->nr_samplers++;
636 return ureg->sampler[i];
637 }
638
639 assert( 0 );
640 return ureg->sampler[0];
641 }
642
643 /*
644 * Allocate a new shader sampler view.
645 */
646 struct ureg_src
647 ureg_DECL_sampler_view(struct ureg_program *ureg,
648 unsigned index,
649 unsigned target,
650 unsigned return_type_x,
651 unsigned return_type_y,
652 unsigned return_type_z,
653 unsigned return_type_w)
654 {
655 struct ureg_src reg = ureg_src_register(TGSI_FILE_SAMPLER_VIEW, index);
656 uint i;
657
658 for (i = 0; i < ureg->nr_sampler_views; i++) {
659 if (ureg->sampler_view[i].index == index) {
660 return reg;
661 }
662 }
663
664 if (i < PIPE_MAX_SHADER_SAMPLER_VIEWS) {
665 ureg->sampler_view[i].index = index;
666 ureg->sampler_view[i].target = target;
667 ureg->sampler_view[i].return_type_x = return_type_x;
668 ureg->sampler_view[i].return_type_y = return_type_y;
669 ureg->sampler_view[i].return_type_z = return_type_z;
670 ureg->sampler_view[i].return_type_w = return_type_w;
671 ureg->nr_sampler_views++;
672 return reg;
673 }
674
675 assert(0);
676 return reg;
677 }
678
679 /* Allocate a new image.
680 */
681 struct ureg_src
682 ureg_DECL_image(struct ureg_program *ureg,
683 unsigned index,
684 unsigned target,
685 unsigned format,
686 boolean wr,
687 boolean raw)
688 {
689 struct ureg_src reg = ureg_src_register(TGSI_FILE_IMAGE, index);
690 unsigned i;
691
692 for (i = 0; i < ureg->nr_images; i++)
693 if (ureg->image[i].index == index)
694 return reg;
695
696 if (i < PIPE_MAX_SHADER_IMAGES) {
697 ureg->image[i].index = index;
698 ureg->image[i].target = target;
699 ureg->image[i].wr = wr;
700 ureg->image[i].raw = raw;
701 ureg->image[i].format = format;
702 ureg->nr_images++;
703 return reg;
704 }
705
706 assert(0);
707 return reg;
708 }
709
710 /* Allocate a new buffer.
711 */
712 struct ureg_src ureg_DECL_buffer(struct ureg_program *ureg, unsigned nr,
713 bool atomic)
714 {
715 struct ureg_src reg = ureg_src_register(TGSI_FILE_BUFFER, nr);
716 unsigned i;
717
718 for (i = 0; i < ureg->nr_buffers; i++)
719 if (ureg->buffer[i].index == nr)
720 return reg;
721
722 if (i < PIPE_MAX_SHADER_BUFFERS) {
723 ureg->buffer[i].index = nr;
724 ureg->buffer[i].atomic = atomic;
725 ureg->nr_buffers++;
726 return reg;
727 }
728
729 assert(0);
730 return reg;
731 }
732
733 /* Allocate a shared memory area.
734 */
735 struct ureg_src ureg_DECL_shared_memory(struct ureg_program *ureg)
736 {
737 struct ureg_src reg = ureg_src_register(TGSI_FILE_MEMORY, 0);
738
739 ureg->use_shared_memory = true;
740 return reg;
741 }
742
743 static int
744 match_or_expand_immediate64( const unsigned *v,
745 int type,
746 unsigned nr,
747 unsigned *v2,
748 unsigned *pnr2,
749 unsigned *swizzle )
750 {
751 unsigned nr2 = *pnr2;
752 unsigned i, j;
753 *swizzle = 0;
754
755 for (i = 0; i < nr; i += 2) {
756 boolean found = FALSE;
757
758 for (j = 0; j < nr2 && !found; j += 2) {
759 if (v[i] == v2[j] && v[i + 1] == v2[j + 1]) {
760 *swizzle |= (j << (i * 2)) | ((j + 1) << ((i + 1) * 2));
761 found = TRUE;
762 }
763 }
764 if (!found) {
765 if ((nr2) >= 4) {
766 return FALSE;
767 }
768
769 v2[nr2] = v[i];
770 v2[nr2 + 1] = v[i + 1];
771
772 *swizzle |= (nr2 << (i * 2)) | ((nr2 + 1) << ((i + 1) * 2));
773 nr2 += 2;
774 }
775 }
776
777 /* Actually expand immediate only when fully succeeded.
778 */
779 *pnr2 = nr2;
780 return TRUE;
781 }
782
783 static int
784 match_or_expand_immediate( const unsigned *v,
785 int type,
786 unsigned nr,
787 unsigned *v2,
788 unsigned *pnr2,
789 unsigned *swizzle )
790 {
791 unsigned nr2 = *pnr2;
792 unsigned i, j;
793
794 if (type == TGSI_IMM_FLOAT64)
795 return match_or_expand_immediate64(v, type, nr, v2, pnr2, swizzle);
796
797 *swizzle = 0;
798
799 for (i = 0; i < nr; i++) {
800 boolean found = FALSE;
801
802 for (j = 0; j < nr2 && !found; j++) {
803 if (v[i] == v2[j]) {
804 *swizzle |= j << (i * 2);
805 found = TRUE;
806 }
807 }
808
809 if (!found) {
810 if (nr2 >= 4) {
811 return FALSE;
812 }
813
814 v2[nr2] = v[i];
815 *swizzle |= nr2 << (i * 2);
816 nr2++;
817 }
818 }
819
820 /* Actually expand immediate only when fully succeeded.
821 */
822 *pnr2 = nr2;
823 return TRUE;
824 }
825
826
827 static struct ureg_src
828 decl_immediate( struct ureg_program *ureg,
829 const unsigned *v,
830 unsigned nr,
831 unsigned type )
832 {
833 unsigned i, j;
834 unsigned swizzle = 0;
835
836 /* Could do a first pass where we examine all existing immediates
837 * without expanding.
838 */
839
840 for (i = 0; i < ureg->nr_immediates; i++) {
841 if (ureg->immediate[i].type != type) {
842 continue;
843 }
844 if (match_or_expand_immediate(v,
845 type,
846 nr,
847 ureg->immediate[i].value.u,
848 &ureg->immediate[i].nr,
849 &swizzle)) {
850 goto out;
851 }
852 }
853
854 if (ureg->nr_immediates < UREG_MAX_IMMEDIATE) {
855 i = ureg->nr_immediates++;
856 ureg->immediate[i].type = type;
857 if (match_or_expand_immediate(v,
858 type,
859 nr,
860 ureg->immediate[i].value.u,
861 &ureg->immediate[i].nr,
862 &swizzle)) {
863 goto out;
864 }
865 }
866
867 set_bad(ureg);
868
869 out:
870 /* Make sure that all referenced elements are from this immediate.
871 * Has the effect of making size-one immediates into scalars.
872 */
873 if (type == TGSI_IMM_FLOAT64) {
874 for (j = nr; j < 4; j+=2) {
875 swizzle |= (swizzle & 0xf) << (j * 2);
876 }
877 } else {
878 for (j = nr; j < 4; j++) {
879 swizzle |= (swizzle & 0x3) << (j * 2);
880 }
881 }
882 return ureg_swizzle(ureg_src_register(TGSI_FILE_IMMEDIATE, i),
883 (swizzle >> 0) & 0x3,
884 (swizzle >> 2) & 0x3,
885 (swizzle >> 4) & 0x3,
886 (swizzle >> 6) & 0x3);
887 }
888
889
890 struct ureg_src
891 ureg_DECL_immediate( struct ureg_program *ureg,
892 const float *v,
893 unsigned nr )
894 {
895 union {
896 float f[4];
897 unsigned u[4];
898 } fu;
899 unsigned int i;
900
901 for (i = 0; i < nr; i++) {
902 fu.f[i] = v[i];
903 }
904
905 return decl_immediate(ureg, fu.u, nr, TGSI_IMM_FLOAT32);
906 }
907
908 struct ureg_src
909 ureg_DECL_immediate_f64( struct ureg_program *ureg,
910 const double *v,
911 unsigned nr )
912 {
913 union {
914 unsigned u[4];
915 double d[2];
916 } fu;
917 unsigned int i;
918
919 assert((nr / 2) < 3);
920 for (i = 0; i < nr / 2; i++) {
921 fu.d[i] = v[i];
922 }
923
924 return decl_immediate(ureg, fu.u, nr, TGSI_IMM_FLOAT64);
925 }
926
927 struct ureg_src
928 ureg_DECL_immediate_uint( struct ureg_program *ureg,
929 const unsigned *v,
930 unsigned nr )
931 {
932 return decl_immediate(ureg, v, nr, TGSI_IMM_UINT32);
933 }
934
935
936 struct ureg_src
937 ureg_DECL_immediate_block_uint( struct ureg_program *ureg,
938 const unsigned *v,
939 unsigned nr )
940 {
941 uint index;
942 uint i;
943
944 if (ureg->nr_immediates + (nr + 3) / 4 > UREG_MAX_IMMEDIATE) {
945 set_bad(ureg);
946 return ureg_src_register(TGSI_FILE_IMMEDIATE, 0);
947 }
948
949 index = ureg->nr_immediates;
950 ureg->nr_immediates += (nr + 3) / 4;
951
952 for (i = index; i < ureg->nr_immediates; i++) {
953 ureg->immediate[i].type = TGSI_IMM_UINT32;
954 ureg->immediate[i].nr = nr > 4 ? 4 : nr;
955 memcpy(ureg->immediate[i].value.u,
956 &v[(i - index) * 4],
957 ureg->immediate[i].nr * sizeof(uint));
958 nr -= 4;
959 }
960
961 return ureg_src_register(TGSI_FILE_IMMEDIATE, index);
962 }
963
964
965 struct ureg_src
966 ureg_DECL_immediate_int( struct ureg_program *ureg,
967 const int *v,
968 unsigned nr )
969 {
970 return decl_immediate(ureg, (const unsigned *)v, nr, TGSI_IMM_INT32);
971 }
972
973
974 void
975 ureg_emit_src( struct ureg_program *ureg,
976 struct ureg_src src )
977 {
978 unsigned size = 1 + (src.Indirect ? 1 : 0) +
979 (src.Dimension ? (src.DimIndirect ? 2 : 1) : 0);
980
981 union tgsi_any_token *out = get_tokens( ureg, DOMAIN_INSN, size );
982 unsigned n = 0;
983
984 assert(src.File != TGSI_FILE_NULL);
985 assert(src.File < TGSI_FILE_COUNT);
986
987 out[n].value = 0;
988 out[n].src.File = src.File;
989 out[n].src.SwizzleX = src.SwizzleX;
990 out[n].src.SwizzleY = src.SwizzleY;
991 out[n].src.SwizzleZ = src.SwizzleZ;
992 out[n].src.SwizzleW = src.SwizzleW;
993 out[n].src.Index = src.Index;
994 out[n].src.Negate = src.Negate;
995 out[0].src.Absolute = src.Absolute;
996 n++;
997
998 if (src.Indirect) {
999 out[0].src.Indirect = 1;
1000 out[n].value = 0;
1001 out[n].ind.File = src.IndirectFile;
1002 out[n].ind.Swizzle = src.IndirectSwizzle;
1003 out[n].ind.Index = src.IndirectIndex;
1004 if (!ureg->supports_any_inout_decl_range &&
1005 (src.File == TGSI_FILE_INPUT || src.File == TGSI_FILE_OUTPUT))
1006 out[n].ind.ArrayID = 0;
1007 else
1008 out[n].ind.ArrayID = src.ArrayID;
1009 n++;
1010 }
1011
1012 if (src.Dimension) {
1013 out[0].src.Dimension = 1;
1014 out[n].dim.Dimension = 0;
1015 out[n].dim.Padding = 0;
1016 if (src.DimIndirect) {
1017 out[n].dim.Indirect = 1;
1018 out[n].dim.Index = src.DimensionIndex;
1019 n++;
1020 out[n].value = 0;
1021 out[n].ind.File = src.DimIndFile;
1022 out[n].ind.Swizzle = src.DimIndSwizzle;
1023 out[n].ind.Index = src.DimIndIndex;
1024 if (!ureg->supports_any_inout_decl_range &&
1025 (src.File == TGSI_FILE_INPUT || src.File == TGSI_FILE_OUTPUT))
1026 out[n].ind.ArrayID = 0;
1027 else
1028 out[n].ind.ArrayID = src.ArrayID;
1029 } else {
1030 out[n].dim.Indirect = 0;
1031 out[n].dim.Index = src.DimensionIndex;
1032 }
1033 n++;
1034 }
1035
1036 assert(n == size);
1037 }
1038
1039
1040 void
1041 ureg_emit_dst( struct ureg_program *ureg,
1042 struct ureg_dst dst )
1043 {
1044 unsigned size = 1 + (dst.Indirect ? 1 : 0) +
1045 (dst.Dimension ? (dst.DimIndirect ? 2 : 1) : 0);
1046
1047 union tgsi_any_token *out = get_tokens( ureg, DOMAIN_INSN, size );
1048 unsigned n = 0;
1049
1050 assert(dst.File != TGSI_FILE_NULL);
1051 assert(dst.File != TGSI_FILE_CONSTANT);
1052 assert(dst.File != TGSI_FILE_INPUT);
1053 assert(dst.File != TGSI_FILE_SAMPLER);
1054 assert(dst.File != TGSI_FILE_SAMPLER_VIEW);
1055 assert(dst.File != TGSI_FILE_IMMEDIATE);
1056 assert(dst.File < TGSI_FILE_COUNT);
1057
1058 out[n].value = 0;
1059 out[n].dst.File = dst.File;
1060 out[n].dst.WriteMask = dst.WriteMask;
1061 out[n].dst.Indirect = dst.Indirect;
1062 out[n].dst.Index = dst.Index;
1063 n++;
1064
1065 if (dst.Indirect) {
1066 out[n].value = 0;
1067 out[n].ind.File = dst.IndirectFile;
1068 out[n].ind.Swizzle = dst.IndirectSwizzle;
1069 out[n].ind.Index = dst.IndirectIndex;
1070 if (!ureg->supports_any_inout_decl_range &&
1071 (dst.File == TGSI_FILE_INPUT || dst.File == TGSI_FILE_OUTPUT))
1072 out[n].ind.ArrayID = 0;
1073 else
1074 out[n].ind.ArrayID = dst.ArrayID;
1075 n++;
1076 }
1077
1078 if (dst.Dimension) {
1079 out[0].dst.Dimension = 1;
1080 out[n].dim.Dimension = 0;
1081 out[n].dim.Padding = 0;
1082 if (dst.DimIndirect) {
1083 out[n].dim.Indirect = 1;
1084 out[n].dim.Index = dst.DimensionIndex;
1085 n++;
1086 out[n].value = 0;
1087 out[n].ind.File = dst.DimIndFile;
1088 out[n].ind.Swizzle = dst.DimIndSwizzle;
1089 out[n].ind.Index = dst.DimIndIndex;
1090 if (!ureg->supports_any_inout_decl_range &&
1091 (dst.File == TGSI_FILE_INPUT || dst.File == TGSI_FILE_OUTPUT))
1092 out[n].ind.ArrayID = 0;
1093 else
1094 out[n].ind.ArrayID = dst.ArrayID;
1095 } else {
1096 out[n].dim.Indirect = 0;
1097 out[n].dim.Index = dst.DimensionIndex;
1098 }
1099 n++;
1100 }
1101
1102 assert(n == size);
1103 }
1104
1105
1106 static void validate( unsigned opcode,
1107 unsigned nr_dst,
1108 unsigned nr_src )
1109 {
1110 #ifdef DEBUG
1111 const struct tgsi_opcode_info *info = tgsi_get_opcode_info( opcode );
1112 assert(info);
1113 if (info) {
1114 assert(nr_dst == info->num_dst);
1115 assert(nr_src == info->num_src);
1116 }
1117 #endif
1118 }
1119
1120 struct ureg_emit_insn_result
1121 ureg_emit_insn(struct ureg_program *ureg,
1122 unsigned opcode,
1123 boolean saturate,
1124 boolean predicate,
1125 boolean pred_negate,
1126 unsigned pred_swizzle_x,
1127 unsigned pred_swizzle_y,
1128 unsigned pred_swizzle_z,
1129 unsigned pred_swizzle_w,
1130 unsigned num_dst,
1131 unsigned num_src )
1132 {
1133 union tgsi_any_token *out;
1134 uint count = predicate ? 2 : 1;
1135 struct ureg_emit_insn_result result;
1136
1137 validate( opcode, num_dst, num_src );
1138
1139 out = get_tokens( ureg, DOMAIN_INSN, count );
1140 out[0].insn = tgsi_default_instruction();
1141 out[0].insn.Opcode = opcode;
1142 out[0].insn.Saturate = saturate;
1143 out[0].insn.NumDstRegs = num_dst;
1144 out[0].insn.NumSrcRegs = num_src;
1145
1146 result.insn_token = ureg->domain[DOMAIN_INSN].count - count;
1147 result.extended_token = result.insn_token;
1148
1149 if (predicate) {
1150 out[0].insn.Predicate = 1;
1151 out[1].insn_predicate = tgsi_default_instruction_predicate();
1152 out[1].insn_predicate.Negate = pred_negate;
1153 out[1].insn_predicate.SwizzleX = pred_swizzle_x;
1154 out[1].insn_predicate.SwizzleY = pred_swizzle_y;
1155 out[1].insn_predicate.SwizzleZ = pred_swizzle_z;
1156 out[1].insn_predicate.SwizzleW = pred_swizzle_w;
1157 }
1158
1159 ureg->nr_instructions++;
1160
1161 return result;
1162 }
1163
1164
1165 /**
1166 * Emit a label token.
1167 * \param label_token returns a token number indicating where the label
1168 * needs to be patched later. Later, this value should be passed to the
1169 * ureg_fixup_label() function.
1170 */
1171 void
1172 ureg_emit_label(struct ureg_program *ureg,
1173 unsigned extended_token,
1174 unsigned *label_token )
1175 {
1176 union tgsi_any_token *out, *insn;
1177
1178 if (!label_token)
1179 return;
1180
1181 out = get_tokens( ureg, DOMAIN_INSN, 1 );
1182 out[0].value = 0;
1183
1184 insn = retrieve_token( ureg, DOMAIN_INSN, extended_token );
1185 insn->insn.Label = 1;
1186
1187 *label_token = ureg->domain[DOMAIN_INSN].count - 1;
1188 }
1189
1190 /* Will return a number which can be used in a label to point to the
1191 * next instruction to be emitted.
1192 */
1193 unsigned
1194 ureg_get_instruction_number( struct ureg_program *ureg )
1195 {
1196 return ureg->nr_instructions;
1197 }
1198
1199 /* Patch a given label (expressed as a token number) to point to a
1200 * given instruction (expressed as an instruction number).
1201 */
1202 void
1203 ureg_fixup_label(struct ureg_program *ureg,
1204 unsigned label_token,
1205 unsigned instruction_number )
1206 {
1207 union tgsi_any_token *out = retrieve_token( ureg, DOMAIN_INSN, label_token );
1208
1209 out->insn_label.Label = instruction_number;
1210 }
1211
1212
1213 void
1214 ureg_emit_texture(struct ureg_program *ureg,
1215 unsigned extended_token,
1216 unsigned target, unsigned num_offsets)
1217 {
1218 union tgsi_any_token *out, *insn;
1219
1220 out = get_tokens( ureg, DOMAIN_INSN, 1 );
1221 insn = retrieve_token( ureg, DOMAIN_INSN, extended_token );
1222
1223 insn->insn.Texture = 1;
1224
1225 out[0].value = 0;
1226 out[0].insn_texture.Texture = target;
1227 out[0].insn_texture.NumOffsets = num_offsets;
1228 }
1229
1230 void
1231 ureg_emit_texture_offset(struct ureg_program *ureg,
1232 const struct tgsi_texture_offset *offset)
1233 {
1234 union tgsi_any_token *out;
1235
1236 out = get_tokens( ureg, DOMAIN_INSN, 1);
1237
1238 out[0].value = 0;
1239 out[0].insn_texture_offset = *offset;
1240
1241 }
1242
1243 void
1244 ureg_emit_memory(struct ureg_program *ureg,
1245 unsigned extended_token,
1246 unsigned qualifier,
1247 unsigned texture,
1248 unsigned format)
1249 {
1250 union tgsi_any_token *out, *insn;
1251
1252 out = get_tokens( ureg, DOMAIN_INSN, 1 );
1253 insn = retrieve_token( ureg, DOMAIN_INSN, extended_token );
1254
1255 insn->insn.Memory = 1;
1256
1257 out[0].value = 0;
1258 out[0].insn_memory.Qualifier = qualifier;
1259 out[0].insn_memory.Texture = texture;
1260 out[0].insn_memory.Format = format;
1261 }
1262
1263 void
1264 ureg_fixup_insn_size(struct ureg_program *ureg,
1265 unsigned insn )
1266 {
1267 union tgsi_any_token *out = retrieve_token( ureg, DOMAIN_INSN, insn );
1268
1269 assert(out->insn.Type == TGSI_TOKEN_TYPE_INSTRUCTION);
1270 out->insn.NrTokens = ureg->domain[DOMAIN_INSN].count - insn - 1;
1271 }
1272
1273
1274 void
1275 ureg_insn(struct ureg_program *ureg,
1276 unsigned opcode,
1277 const struct ureg_dst *dst,
1278 unsigned nr_dst,
1279 const struct ureg_src *src,
1280 unsigned nr_src )
1281 {
1282 struct ureg_emit_insn_result insn;
1283 unsigned i;
1284 boolean saturate;
1285 boolean predicate;
1286 boolean negate = FALSE;
1287 unsigned swizzle[4] = { 0 };
1288
1289 if (nr_dst && ureg_dst_is_empty(dst[0])) {
1290 return;
1291 }
1292
1293 saturate = nr_dst ? dst[0].Saturate : FALSE;
1294 predicate = nr_dst ? dst[0].Predicate : FALSE;
1295 if (predicate) {
1296 negate = dst[0].PredNegate;
1297 swizzle[0] = dst[0].PredSwizzleX;
1298 swizzle[1] = dst[0].PredSwizzleY;
1299 swizzle[2] = dst[0].PredSwizzleZ;
1300 swizzle[3] = dst[0].PredSwizzleW;
1301 }
1302
1303 insn = ureg_emit_insn(ureg,
1304 opcode,
1305 saturate,
1306 predicate,
1307 negate,
1308 swizzle[0],
1309 swizzle[1],
1310 swizzle[2],
1311 swizzle[3],
1312 nr_dst,
1313 nr_src);
1314
1315 for (i = 0; i < nr_dst; i++)
1316 ureg_emit_dst( ureg, dst[i] );
1317
1318 for (i = 0; i < nr_src; i++)
1319 ureg_emit_src( ureg, src[i] );
1320
1321 ureg_fixup_insn_size( ureg, insn.insn_token );
1322 }
1323
1324 void
1325 ureg_tex_insn(struct ureg_program *ureg,
1326 unsigned opcode,
1327 const struct ureg_dst *dst,
1328 unsigned nr_dst,
1329 unsigned target,
1330 const struct tgsi_texture_offset *texoffsets,
1331 unsigned nr_offset,
1332 const struct ureg_src *src,
1333 unsigned nr_src )
1334 {
1335 struct ureg_emit_insn_result insn;
1336 unsigned i;
1337 boolean saturate;
1338 boolean predicate;
1339 boolean negate = FALSE;
1340 unsigned swizzle[4] = { 0 };
1341
1342 if (nr_dst && ureg_dst_is_empty(dst[0])) {
1343 return;
1344 }
1345
1346 saturate = nr_dst ? dst[0].Saturate : FALSE;
1347 predicate = nr_dst ? dst[0].Predicate : FALSE;
1348 if (predicate) {
1349 negate = dst[0].PredNegate;
1350 swizzle[0] = dst[0].PredSwizzleX;
1351 swizzle[1] = dst[0].PredSwizzleY;
1352 swizzle[2] = dst[0].PredSwizzleZ;
1353 swizzle[3] = dst[0].PredSwizzleW;
1354 }
1355
1356 insn = ureg_emit_insn(ureg,
1357 opcode,
1358 saturate,
1359 predicate,
1360 negate,
1361 swizzle[0],
1362 swizzle[1],
1363 swizzle[2],
1364 swizzle[3],
1365 nr_dst,
1366 nr_src);
1367
1368 ureg_emit_texture( ureg, insn.extended_token, target, nr_offset );
1369
1370 for (i = 0; i < nr_offset; i++)
1371 ureg_emit_texture_offset( ureg, &texoffsets[i]);
1372
1373 for (i = 0; i < nr_dst; i++)
1374 ureg_emit_dst( ureg, dst[i] );
1375
1376 for (i = 0; i < nr_src; i++)
1377 ureg_emit_src( ureg, src[i] );
1378
1379 ureg_fixup_insn_size( ureg, insn.insn_token );
1380 }
1381
1382
1383 void
1384 ureg_label_insn(struct ureg_program *ureg,
1385 unsigned opcode,
1386 const struct ureg_src *src,
1387 unsigned nr_src,
1388 unsigned *label_token )
1389 {
1390 struct ureg_emit_insn_result insn;
1391 unsigned i;
1392
1393 insn = ureg_emit_insn(ureg,
1394 opcode,
1395 FALSE,
1396 FALSE,
1397 FALSE,
1398 TGSI_SWIZZLE_X,
1399 TGSI_SWIZZLE_Y,
1400 TGSI_SWIZZLE_Z,
1401 TGSI_SWIZZLE_W,
1402 0,
1403 nr_src);
1404
1405 ureg_emit_label( ureg, insn.extended_token, label_token );
1406
1407 for (i = 0; i < nr_src; i++)
1408 ureg_emit_src( ureg, src[i] );
1409
1410 ureg_fixup_insn_size( ureg, insn.insn_token );
1411 }
1412
1413
1414 void
1415 ureg_memory_insn(struct ureg_program *ureg,
1416 unsigned opcode,
1417 const struct ureg_dst *dst,
1418 unsigned nr_dst,
1419 const struct ureg_src *src,
1420 unsigned nr_src,
1421 unsigned qualifier,
1422 unsigned texture,
1423 unsigned format)
1424 {
1425 struct ureg_emit_insn_result insn;
1426 unsigned i;
1427
1428 insn = ureg_emit_insn(ureg,
1429 opcode,
1430 FALSE,
1431 FALSE,
1432 FALSE,
1433 TGSI_SWIZZLE_X,
1434 TGSI_SWIZZLE_Y,
1435 TGSI_SWIZZLE_Z,
1436 TGSI_SWIZZLE_W,
1437 nr_dst,
1438 nr_src);
1439
1440 ureg_emit_memory(ureg, insn.extended_token, qualifier, texture, format);
1441
1442 for (i = 0; i < nr_dst; i++)
1443 ureg_emit_dst(ureg, dst[i]);
1444
1445 for (i = 0; i < nr_src; i++)
1446 ureg_emit_src(ureg, src[i]);
1447
1448 ureg_fixup_insn_size(ureg, insn.insn_token);
1449 }
1450
1451
1452 static void
1453 emit_decl_semantic(struct ureg_program *ureg,
1454 unsigned file,
1455 unsigned first,
1456 unsigned last,
1457 unsigned semantic_name,
1458 unsigned semantic_index,
1459 unsigned usage_mask,
1460 unsigned array_id)
1461 {
1462 union tgsi_any_token *out = get_tokens(ureg, DOMAIN_DECL, array_id ? 4 : 3);
1463
1464 out[0].value = 0;
1465 out[0].decl.Type = TGSI_TOKEN_TYPE_DECLARATION;
1466 out[0].decl.NrTokens = 3;
1467 out[0].decl.File = file;
1468 out[0].decl.UsageMask = usage_mask;
1469 out[0].decl.Semantic = 1;
1470 out[0].decl.Array = array_id != 0;
1471
1472 out[1].value = 0;
1473 out[1].decl_range.First = first;
1474 out[1].decl_range.Last = last;
1475
1476 out[2].value = 0;
1477 out[2].decl_semantic.Name = semantic_name;
1478 out[2].decl_semantic.Index = semantic_index;
1479
1480 if (array_id) {
1481 out[3].value = 0;
1482 out[3].array.ArrayID = array_id;
1483 }
1484 }
1485
1486
1487 static void
1488 emit_decl_fs(struct ureg_program *ureg,
1489 unsigned file,
1490 unsigned first,
1491 unsigned last,
1492 unsigned semantic_name,
1493 unsigned semantic_index,
1494 unsigned interpolate,
1495 unsigned cylindrical_wrap,
1496 unsigned interpolate_location,
1497 unsigned array_id)
1498 {
1499 union tgsi_any_token *out = get_tokens(ureg, DOMAIN_DECL,
1500 array_id ? 5 : 4);
1501
1502 out[0].value = 0;
1503 out[0].decl.Type = TGSI_TOKEN_TYPE_DECLARATION;
1504 out[0].decl.NrTokens = 4;
1505 out[0].decl.File = file;
1506 out[0].decl.UsageMask = TGSI_WRITEMASK_XYZW; /* FIXME! */
1507 out[0].decl.Interpolate = 1;
1508 out[0].decl.Semantic = 1;
1509 out[0].decl.Array = array_id != 0;
1510
1511 out[1].value = 0;
1512 out[1].decl_range.First = first;
1513 out[1].decl_range.Last = last;
1514
1515 out[2].value = 0;
1516 out[2].decl_interp.Interpolate = interpolate;
1517 out[2].decl_interp.CylindricalWrap = cylindrical_wrap;
1518 out[2].decl_interp.Location = interpolate_location;
1519
1520 out[3].value = 0;
1521 out[3].decl_semantic.Name = semantic_name;
1522 out[3].decl_semantic.Index = semantic_index;
1523
1524 if (array_id) {
1525 out[4].value = 0;
1526 out[4].array.ArrayID = array_id;
1527 }
1528 }
1529
1530 static void
1531 emit_decl_temps( struct ureg_program *ureg,
1532 unsigned first, unsigned last,
1533 boolean local,
1534 unsigned arrayid )
1535 {
1536 union tgsi_any_token *out = get_tokens( ureg, DOMAIN_DECL,
1537 arrayid ? 3 : 2 );
1538
1539 out[0].value = 0;
1540 out[0].decl.Type = TGSI_TOKEN_TYPE_DECLARATION;
1541 out[0].decl.NrTokens = 2;
1542 out[0].decl.File = TGSI_FILE_TEMPORARY;
1543 out[0].decl.UsageMask = TGSI_WRITEMASK_XYZW;
1544 out[0].decl.Local = local;
1545
1546 out[1].value = 0;
1547 out[1].decl_range.First = first;
1548 out[1].decl_range.Last = last;
1549
1550 if (arrayid) {
1551 out[0].decl.Array = 1;
1552 out[2].value = 0;
1553 out[2].array.ArrayID = arrayid;
1554 }
1555 }
1556
1557 static void emit_decl_range( struct ureg_program *ureg,
1558 unsigned file,
1559 unsigned first,
1560 unsigned count )
1561 {
1562 union tgsi_any_token *out = get_tokens( ureg, DOMAIN_DECL, 2 );
1563
1564 out[0].value = 0;
1565 out[0].decl.Type = TGSI_TOKEN_TYPE_DECLARATION;
1566 out[0].decl.NrTokens = 2;
1567 out[0].decl.File = file;
1568 out[0].decl.UsageMask = TGSI_WRITEMASK_XYZW;
1569 out[0].decl.Semantic = 0;
1570
1571 out[1].value = 0;
1572 out[1].decl_range.First = first;
1573 out[1].decl_range.Last = first + count - 1;
1574 }
1575
1576 static void
1577 emit_decl_range2D(struct ureg_program *ureg,
1578 unsigned file,
1579 unsigned first,
1580 unsigned last,
1581 unsigned index2D)
1582 {
1583 union tgsi_any_token *out = get_tokens(ureg, DOMAIN_DECL, 3);
1584
1585 out[0].value = 0;
1586 out[0].decl.Type = TGSI_TOKEN_TYPE_DECLARATION;
1587 out[0].decl.NrTokens = 3;
1588 out[0].decl.File = file;
1589 out[0].decl.UsageMask = TGSI_WRITEMASK_XYZW;
1590 out[0].decl.Dimension = 1;
1591
1592 out[1].value = 0;
1593 out[1].decl_range.First = first;
1594 out[1].decl_range.Last = last;
1595
1596 out[2].value = 0;
1597 out[2].decl_dim.Index2D = index2D;
1598 }
1599
1600 static void
1601 emit_decl_sampler_view(struct ureg_program *ureg,
1602 unsigned index,
1603 unsigned target,
1604 unsigned return_type_x,
1605 unsigned return_type_y,
1606 unsigned return_type_z,
1607 unsigned return_type_w )
1608 {
1609 union tgsi_any_token *out = get_tokens(ureg, DOMAIN_DECL, 3);
1610
1611 out[0].value = 0;
1612 out[0].decl.Type = TGSI_TOKEN_TYPE_DECLARATION;
1613 out[0].decl.NrTokens = 3;
1614 out[0].decl.File = TGSI_FILE_SAMPLER_VIEW;
1615 out[0].decl.UsageMask = TGSI_WRITEMASK_XYZW;
1616
1617 out[1].value = 0;
1618 out[1].decl_range.First = index;
1619 out[1].decl_range.Last = index;
1620
1621 out[2].value = 0;
1622 out[2].decl_sampler_view.Resource = target;
1623 out[2].decl_sampler_view.ReturnTypeX = return_type_x;
1624 out[2].decl_sampler_view.ReturnTypeY = return_type_y;
1625 out[2].decl_sampler_view.ReturnTypeZ = return_type_z;
1626 out[2].decl_sampler_view.ReturnTypeW = return_type_w;
1627 }
1628
1629 static void
1630 emit_decl_image(struct ureg_program *ureg,
1631 unsigned index,
1632 unsigned target,
1633 unsigned format,
1634 boolean wr,
1635 boolean raw)
1636 {
1637 union tgsi_any_token *out = get_tokens(ureg, DOMAIN_DECL, 3);
1638
1639 out[0].value = 0;
1640 out[0].decl.Type = TGSI_TOKEN_TYPE_DECLARATION;
1641 out[0].decl.NrTokens = 3;
1642 out[0].decl.File = TGSI_FILE_IMAGE;
1643 out[0].decl.UsageMask = TGSI_WRITEMASK_XYZW;
1644
1645 out[1].value = 0;
1646 out[1].decl_range.First = index;
1647 out[1].decl_range.Last = index;
1648
1649 out[2].value = 0;
1650 out[2].decl_image.Resource = target;
1651 out[2].decl_image.Writable = wr;
1652 out[2].decl_image.Raw = raw;
1653 out[2].decl_image.Format = format;
1654 }
1655
1656 static void
1657 emit_decl_buffer(struct ureg_program *ureg,
1658 unsigned index,
1659 bool atomic)
1660 {
1661 union tgsi_any_token *out = get_tokens(ureg, DOMAIN_DECL, 2);
1662
1663 out[0].value = 0;
1664 out[0].decl.Type = TGSI_TOKEN_TYPE_DECLARATION;
1665 out[0].decl.NrTokens = 2;
1666 out[0].decl.File = TGSI_FILE_BUFFER;
1667 out[0].decl.UsageMask = TGSI_WRITEMASK_XYZW;
1668 out[0].decl.Atomic = atomic;
1669
1670 out[1].value = 0;
1671 out[1].decl_range.First = index;
1672 out[1].decl_range.Last = index;
1673 }
1674
1675 static void
1676 emit_decl_shared_memory(struct ureg_program *ureg)
1677 {
1678 union tgsi_any_token *out = get_tokens(ureg, DOMAIN_DECL, 2);
1679
1680 out[0].value = 0;
1681 out[0].decl.Type = TGSI_TOKEN_TYPE_DECLARATION;
1682 out[0].decl.NrTokens = 2;
1683 out[0].decl.File = TGSI_FILE_MEMORY;
1684 out[0].decl.UsageMask = TGSI_WRITEMASK_XYZW;
1685 out[0].decl.Shared = true;
1686
1687 out[1].value = 0;
1688 out[1].decl_range.First = 0;
1689 out[1].decl_range.Last = 0;
1690 }
1691
1692 static void
1693 emit_immediate( struct ureg_program *ureg,
1694 const unsigned *v,
1695 unsigned type )
1696 {
1697 union tgsi_any_token *out = get_tokens( ureg, DOMAIN_DECL, 5 );
1698
1699 out[0].value = 0;
1700 out[0].imm.Type = TGSI_TOKEN_TYPE_IMMEDIATE;
1701 out[0].imm.NrTokens = 5;
1702 out[0].imm.DataType = type;
1703 out[0].imm.Padding = 0;
1704
1705 out[1].imm_data.Uint = v[0];
1706 out[2].imm_data.Uint = v[1];
1707 out[3].imm_data.Uint = v[2];
1708 out[4].imm_data.Uint = v[3];
1709 }
1710
1711 static void
1712 emit_property(struct ureg_program *ureg,
1713 unsigned name,
1714 unsigned data)
1715 {
1716 union tgsi_any_token *out = get_tokens(ureg, DOMAIN_DECL, 2);
1717
1718 out[0].value = 0;
1719 out[0].prop.Type = TGSI_TOKEN_TYPE_PROPERTY;
1720 out[0].prop.NrTokens = 2;
1721 out[0].prop.PropertyName = name;
1722
1723 out[1].prop_data.Data = data;
1724 }
1725
1726
1727 static void emit_decls( struct ureg_program *ureg )
1728 {
1729 unsigned i,j;
1730
1731 for (i = 0; i < Elements(ureg->properties); i++)
1732 if (ureg->properties[i] != ~0)
1733 emit_property(ureg, i, ureg->properties[i]);
1734
1735 if (ureg->processor == TGSI_PROCESSOR_VERTEX) {
1736 for (i = 0; i < PIPE_MAX_ATTRIBS; i++) {
1737 if (ureg->vs_inputs[i/32] & (1 << (i%32))) {
1738 emit_decl_range( ureg, TGSI_FILE_INPUT, i, 1 );
1739 }
1740 }
1741 } else if (ureg->processor == TGSI_PROCESSOR_FRAGMENT) {
1742 if (ureg->supports_any_inout_decl_range) {
1743 for (i = 0; i < ureg->nr_inputs; i++) {
1744 emit_decl_fs(ureg,
1745 TGSI_FILE_INPUT,
1746 ureg->input[i].first,
1747 ureg->input[i].last,
1748 ureg->input[i].semantic_name,
1749 ureg->input[i].semantic_index,
1750 ureg->input[i].interp,
1751 ureg->input[i].cylindrical_wrap,
1752 ureg->input[i].interp_location,
1753 ureg->input[i].array_id);
1754 }
1755 }
1756 else {
1757 for (i = 0; i < ureg->nr_inputs; i++) {
1758 for (j = ureg->input[i].first; j <= ureg->input[i].last; j++) {
1759 emit_decl_fs(ureg,
1760 TGSI_FILE_INPUT,
1761 j, j,
1762 ureg->input[i].semantic_name,
1763 ureg->input[i].semantic_index +
1764 (j - ureg->input[i].first),
1765 ureg->input[i].interp,
1766 ureg->input[i].cylindrical_wrap,
1767 ureg->input[i].interp_location, 0);
1768 }
1769 }
1770 }
1771 } else {
1772 if (ureg->supports_any_inout_decl_range) {
1773 for (i = 0; i < ureg->nr_inputs; i++) {
1774 emit_decl_semantic(ureg,
1775 TGSI_FILE_INPUT,
1776 ureg->input[i].first,
1777 ureg->input[i].last,
1778 ureg->input[i].semantic_name,
1779 ureg->input[i].semantic_index,
1780 TGSI_WRITEMASK_XYZW,
1781 ureg->input[i].array_id);
1782 }
1783 }
1784 else {
1785 for (i = 0; i < ureg->nr_inputs; i++) {
1786 for (j = ureg->input[i].first; j <= ureg->input[i].last; j++) {
1787 emit_decl_semantic(ureg,
1788 TGSI_FILE_INPUT,
1789 j, j,
1790 ureg->input[i].semantic_name,
1791 ureg->input[i].semantic_index +
1792 (j - ureg->input[i].first),
1793 TGSI_WRITEMASK_XYZW, 0);
1794 }
1795 }
1796 }
1797 }
1798
1799 for (i = 0; i < ureg->nr_system_values; i++) {
1800 emit_decl_semantic(ureg,
1801 TGSI_FILE_SYSTEM_VALUE,
1802 i,
1803 i,
1804 ureg->system_value[i].semantic_name,
1805 ureg->system_value[i].semantic_index,
1806 TGSI_WRITEMASK_XYZW, 0);
1807 }
1808
1809 if (ureg->supports_any_inout_decl_range) {
1810 for (i = 0; i < ureg->nr_outputs; i++) {
1811 emit_decl_semantic(ureg,
1812 TGSI_FILE_OUTPUT,
1813 ureg->output[i].first,
1814 ureg->output[i].last,
1815 ureg->output[i].semantic_name,
1816 ureg->output[i].semantic_index,
1817 ureg->output[i].usage_mask,
1818 ureg->output[i].array_id);
1819 }
1820 }
1821 else {
1822 for (i = 0; i < ureg->nr_outputs; i++) {
1823 for (j = ureg->output[i].first; j <= ureg->output[i].last; j++) {
1824 emit_decl_semantic(ureg,
1825 TGSI_FILE_OUTPUT,
1826 j, j,
1827 ureg->output[i].semantic_name,
1828 ureg->output[i].semantic_index +
1829 (j - ureg->output[i].first),
1830 ureg->output[i].usage_mask, 0);
1831 }
1832 }
1833 }
1834
1835 for (i = 0; i < ureg->nr_samplers; i++) {
1836 emit_decl_range( ureg,
1837 TGSI_FILE_SAMPLER,
1838 ureg->sampler[i].Index, 1 );
1839 }
1840
1841 for (i = 0; i < ureg->nr_sampler_views; i++) {
1842 emit_decl_sampler_view(ureg,
1843 ureg->sampler_view[i].index,
1844 ureg->sampler_view[i].target,
1845 ureg->sampler_view[i].return_type_x,
1846 ureg->sampler_view[i].return_type_y,
1847 ureg->sampler_view[i].return_type_z,
1848 ureg->sampler_view[i].return_type_w);
1849 }
1850
1851 for (i = 0; i < ureg->nr_images; i++) {
1852 emit_decl_image(ureg,
1853 ureg->image[i].index,
1854 ureg->image[i].target,
1855 ureg->image[i].format,
1856 ureg->image[i].wr,
1857 ureg->image[i].raw);
1858 }
1859
1860 for (i = 0; i < ureg->nr_buffers; i++) {
1861 emit_decl_buffer(ureg, ureg->buffer[i].index, ureg->buffer[i].atomic);
1862 }
1863
1864 if (ureg->use_shared_memory)
1865 emit_decl_shared_memory(ureg);
1866
1867 if (ureg->const_decls.nr_constant_ranges) {
1868 for (i = 0; i < ureg->const_decls.nr_constant_ranges; i++) {
1869 emit_decl_range(ureg,
1870 TGSI_FILE_CONSTANT,
1871 ureg->const_decls.constant_range[i].first,
1872 ureg->const_decls.constant_range[i].last - ureg->const_decls.constant_range[i].first + 1);
1873 }
1874 }
1875
1876 for (i = 0; i < PIPE_MAX_CONSTANT_BUFFERS; i++) {
1877 struct const_decl *decl = &ureg->const_decls2D[i];
1878
1879 if (decl->nr_constant_ranges) {
1880 uint j;
1881
1882 for (j = 0; j < decl->nr_constant_ranges; j++) {
1883 emit_decl_range2D(ureg,
1884 TGSI_FILE_CONSTANT,
1885 decl->constant_range[j].first,
1886 decl->constant_range[j].last,
1887 i);
1888 }
1889 }
1890 }
1891
1892 if (ureg->nr_temps) {
1893 unsigned array = 0;
1894 for (i = 0; i < ureg->nr_temps;) {
1895 boolean local = util_bitmask_get(ureg->local_temps, i);
1896 unsigned first = i;
1897 i = util_bitmask_get_next_index(ureg->decl_temps, i + 1);
1898 if (i == UTIL_BITMASK_INVALID_INDEX)
1899 i = ureg->nr_temps;
1900
1901 if (array < ureg->nr_array_temps && ureg->array_temps[array] == first)
1902 emit_decl_temps( ureg, first, i - 1, local, ++array );
1903 else
1904 emit_decl_temps( ureg, first, i - 1, local, 0 );
1905 }
1906 }
1907
1908 if (ureg->nr_addrs) {
1909 emit_decl_range( ureg,
1910 TGSI_FILE_ADDRESS,
1911 0, ureg->nr_addrs );
1912 }
1913
1914 if (ureg->nr_preds) {
1915 emit_decl_range(ureg,
1916 TGSI_FILE_PREDICATE,
1917 0,
1918 ureg->nr_preds);
1919 }
1920
1921 for (i = 0; i < ureg->nr_immediates; i++) {
1922 emit_immediate( ureg,
1923 ureg->immediate[i].value.u,
1924 ureg->immediate[i].type );
1925 }
1926 }
1927
1928 /* Append the instruction tokens onto the declarations to build a
1929 * contiguous stream suitable to send to the driver.
1930 */
1931 static void copy_instructions( struct ureg_program *ureg )
1932 {
1933 unsigned nr_tokens = ureg->domain[DOMAIN_INSN].count;
1934 union tgsi_any_token *out = get_tokens( ureg,
1935 DOMAIN_DECL,
1936 nr_tokens );
1937
1938 memcpy(out,
1939 ureg->domain[DOMAIN_INSN].tokens,
1940 nr_tokens * sizeof out[0] );
1941 }
1942
1943
1944 static void
1945 fixup_header_size(struct ureg_program *ureg)
1946 {
1947 union tgsi_any_token *out = retrieve_token( ureg, DOMAIN_DECL, 0 );
1948
1949 out->header.BodySize = ureg->domain[DOMAIN_DECL].count - 2;
1950 }
1951
1952
1953 static void
1954 emit_header( struct ureg_program *ureg )
1955 {
1956 union tgsi_any_token *out = get_tokens( ureg, DOMAIN_DECL, 2 );
1957
1958 out[0].header.HeaderSize = 2;
1959 out[0].header.BodySize = 0;
1960
1961 out[1].processor.Processor = ureg->processor;
1962 out[1].processor.Padding = 0;
1963 }
1964
1965
1966 const struct tgsi_token *ureg_finalize( struct ureg_program *ureg )
1967 {
1968 const struct tgsi_token *tokens;
1969
1970 switch (ureg->processor) {
1971 case TGSI_PROCESSOR_VERTEX:
1972 case TGSI_PROCESSOR_TESS_EVAL:
1973 ureg_property(ureg, TGSI_PROPERTY_NEXT_SHADER,
1974 ureg->next_shader_processor == -1 ?
1975 TGSI_PROCESSOR_FRAGMENT :
1976 ureg->next_shader_processor);
1977 break;
1978 }
1979
1980 emit_header( ureg );
1981 emit_decls( ureg );
1982 copy_instructions( ureg );
1983 fixup_header_size( ureg );
1984
1985 if (ureg->domain[0].tokens == error_tokens ||
1986 ureg->domain[1].tokens == error_tokens) {
1987 debug_printf("%s: error in generated shader\n", __FUNCTION__);
1988 assert(0);
1989 return NULL;
1990 }
1991
1992 tokens = &ureg->domain[DOMAIN_DECL].tokens[0].token;
1993
1994 if (0) {
1995 debug_printf("%s: emitted shader %d tokens:\n", __FUNCTION__,
1996 ureg->domain[DOMAIN_DECL].count);
1997 tgsi_dump( tokens, 0 );
1998 }
1999
2000 #if DEBUG
2001 if (tokens && !tgsi_sanity_check(tokens)) {
2002 debug_printf("tgsi_ureg.c, sanity check failed on generated tokens:\n");
2003 tgsi_dump(tokens, 0);
2004 assert(0);
2005 }
2006 #endif
2007
2008
2009 return tokens;
2010 }
2011
2012
2013 void *ureg_create_shader( struct ureg_program *ureg,
2014 struct pipe_context *pipe,
2015 const struct pipe_stream_output_info *so )
2016 {
2017 struct pipe_shader_state state;
2018
2019 state.tokens = ureg_finalize(ureg);
2020 if(!state.tokens)
2021 return NULL;
2022
2023 if (so)
2024 state.stream_output = *so;
2025 else
2026 memset(&state.stream_output, 0, sizeof(state.stream_output));
2027
2028 switch (ureg->processor) {
2029 case TGSI_PROCESSOR_VERTEX:
2030 return pipe->create_vs_state(pipe, &state);
2031 case TGSI_PROCESSOR_TESS_CTRL:
2032 return pipe->create_tcs_state(pipe, &state);
2033 case TGSI_PROCESSOR_TESS_EVAL:
2034 return pipe->create_tes_state(pipe, &state);
2035 case TGSI_PROCESSOR_GEOMETRY:
2036 return pipe->create_gs_state(pipe, &state);
2037 case TGSI_PROCESSOR_FRAGMENT:
2038 return pipe->create_fs_state(pipe, &state);
2039 default:
2040 return NULL;
2041 }
2042 }
2043
2044
2045 const struct tgsi_token *ureg_get_tokens( struct ureg_program *ureg,
2046 unsigned *nr_tokens )
2047 {
2048 const struct tgsi_token *tokens;
2049
2050 ureg_finalize(ureg);
2051
2052 tokens = &ureg->domain[DOMAIN_DECL].tokens[0].token;
2053
2054 if (nr_tokens)
2055 *nr_tokens = ureg->domain[DOMAIN_DECL].size;
2056
2057 ureg->domain[DOMAIN_DECL].tokens = 0;
2058 ureg->domain[DOMAIN_DECL].size = 0;
2059 ureg->domain[DOMAIN_DECL].order = 0;
2060 ureg->domain[DOMAIN_DECL].count = 0;
2061
2062 return tokens;
2063 }
2064
2065
2066 void ureg_free_tokens( const struct tgsi_token *tokens )
2067 {
2068 FREE((struct tgsi_token *)tokens);
2069 }
2070
2071
2072 struct ureg_program *
2073 ureg_create(unsigned processor)
2074 {
2075 return ureg_create_with_screen(processor, NULL);
2076 }
2077
2078
2079 struct ureg_program *
2080 ureg_create_with_screen(unsigned processor, struct pipe_screen *screen)
2081 {
2082 int i;
2083 struct ureg_program *ureg = CALLOC_STRUCT( ureg_program );
2084 if (!ureg)
2085 goto no_ureg;
2086
2087 ureg->processor = processor;
2088 ureg->supports_any_inout_decl_range =
2089 screen &&
2090 screen->get_shader_param(screen,
2091 util_pipe_shader_from_tgsi_processor(processor),
2092 PIPE_SHADER_CAP_TGSI_ANY_INOUT_DECL_RANGE) != 0;
2093 ureg->next_shader_processor = -1;
2094
2095 for (i = 0; i < Elements(ureg->properties); i++)
2096 ureg->properties[i] = ~0;
2097
2098 ureg->free_temps = util_bitmask_create();
2099 if (ureg->free_temps == NULL)
2100 goto no_free_temps;
2101
2102 ureg->local_temps = util_bitmask_create();
2103 if (ureg->local_temps == NULL)
2104 goto no_local_temps;
2105
2106 ureg->decl_temps = util_bitmask_create();
2107 if (ureg->decl_temps == NULL)
2108 goto no_decl_temps;
2109
2110 return ureg;
2111
2112 no_decl_temps:
2113 util_bitmask_destroy(ureg->local_temps);
2114 no_local_temps:
2115 util_bitmask_destroy(ureg->free_temps);
2116 no_free_temps:
2117 FREE(ureg);
2118 no_ureg:
2119 return NULL;
2120 }
2121
2122
2123 void
2124 ureg_set_next_shader_processor(struct ureg_program *ureg, unsigned processor)
2125 {
2126 ureg->next_shader_processor = processor;
2127 }
2128
2129
2130 unsigned
2131 ureg_get_nr_outputs( const struct ureg_program *ureg )
2132 {
2133 if (!ureg)
2134 return 0;
2135 return ureg->nr_outputs;
2136 }
2137
2138
2139 void ureg_destroy( struct ureg_program *ureg )
2140 {
2141 unsigned i;
2142
2143 for (i = 0; i < Elements(ureg->domain); i++) {
2144 if (ureg->domain[i].tokens &&
2145 ureg->domain[i].tokens != error_tokens)
2146 FREE(ureg->domain[i].tokens);
2147 }
2148
2149 util_bitmask_destroy(ureg->free_temps);
2150 util_bitmask_destroy(ureg->local_temps);
2151 util_bitmask_destroy(ureg->decl_temps);
2152
2153 FREE(ureg);
2154 }