gallium: use PIPE_SHADER_* everywhere, remove TGSI_PROCESSOR_*
[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_memory[TGSI_MEMORY_TYPE_COUNT];
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 == PIPE_SHADER_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 memory area.
734 */
735 struct ureg_src ureg_DECL_memory(struct ureg_program *ureg,
736 unsigned memory_type)
737 {
738 struct ureg_src reg = ureg_src_register(TGSI_FILE_MEMORY, memory_type);
739
740 ureg->use_memory[memory_type] = true;
741 return reg;
742 }
743
744 static int
745 match_or_expand_immediate64( const unsigned *v,
746 int type,
747 unsigned nr,
748 unsigned *v2,
749 unsigned *pnr2,
750 unsigned *swizzle )
751 {
752 unsigned nr2 = *pnr2;
753 unsigned i, j;
754 *swizzle = 0;
755
756 for (i = 0; i < nr; i += 2) {
757 boolean found = FALSE;
758
759 for (j = 0; j < nr2 && !found; j += 2) {
760 if (v[i] == v2[j] && v[i + 1] == v2[j + 1]) {
761 *swizzle |= (j << (i * 2)) | ((j + 1) << ((i + 1) * 2));
762 found = TRUE;
763 }
764 }
765 if (!found) {
766 if ((nr2) >= 4) {
767 return FALSE;
768 }
769
770 v2[nr2] = v[i];
771 v2[nr2 + 1] = v[i + 1];
772
773 *swizzle |= (nr2 << (i * 2)) | ((nr2 + 1) << ((i + 1) * 2));
774 nr2 += 2;
775 }
776 }
777
778 /* Actually expand immediate only when fully succeeded.
779 */
780 *pnr2 = nr2;
781 return TRUE;
782 }
783
784 static int
785 match_or_expand_immediate( const unsigned *v,
786 int type,
787 unsigned nr,
788 unsigned *v2,
789 unsigned *pnr2,
790 unsigned *swizzle )
791 {
792 unsigned nr2 = *pnr2;
793 unsigned i, j;
794
795 if (type == TGSI_IMM_FLOAT64)
796 return match_or_expand_immediate64(v, type, nr, v2, pnr2, swizzle);
797
798 *swizzle = 0;
799
800 for (i = 0; i < nr; i++) {
801 boolean found = FALSE;
802
803 for (j = 0; j < nr2 && !found; j++) {
804 if (v[i] == v2[j]) {
805 *swizzle |= j << (i * 2);
806 found = TRUE;
807 }
808 }
809
810 if (!found) {
811 if (nr2 >= 4) {
812 return FALSE;
813 }
814
815 v2[nr2] = v[i];
816 *swizzle |= nr2 << (i * 2);
817 nr2++;
818 }
819 }
820
821 /* Actually expand immediate only when fully succeeded.
822 */
823 *pnr2 = nr2;
824 return TRUE;
825 }
826
827
828 static struct ureg_src
829 decl_immediate( struct ureg_program *ureg,
830 const unsigned *v,
831 unsigned nr,
832 unsigned type )
833 {
834 unsigned i, j;
835 unsigned swizzle = 0;
836
837 /* Could do a first pass where we examine all existing immediates
838 * without expanding.
839 */
840
841 for (i = 0; i < ureg->nr_immediates; i++) {
842 if (ureg->immediate[i].type != type) {
843 continue;
844 }
845 if (match_or_expand_immediate(v,
846 type,
847 nr,
848 ureg->immediate[i].value.u,
849 &ureg->immediate[i].nr,
850 &swizzle)) {
851 goto out;
852 }
853 }
854
855 if (ureg->nr_immediates < UREG_MAX_IMMEDIATE) {
856 i = ureg->nr_immediates++;
857 ureg->immediate[i].type = type;
858 if (match_or_expand_immediate(v,
859 type,
860 nr,
861 ureg->immediate[i].value.u,
862 &ureg->immediate[i].nr,
863 &swizzle)) {
864 goto out;
865 }
866 }
867
868 set_bad(ureg);
869
870 out:
871 /* Make sure that all referenced elements are from this immediate.
872 * Has the effect of making size-one immediates into scalars.
873 */
874 if (type == TGSI_IMM_FLOAT64) {
875 for (j = nr; j < 4; j+=2) {
876 swizzle |= (swizzle & 0xf) << (j * 2);
877 }
878 } else {
879 for (j = nr; j < 4; j++) {
880 swizzle |= (swizzle & 0x3) << (j * 2);
881 }
882 }
883 return ureg_swizzle(ureg_src_register(TGSI_FILE_IMMEDIATE, i),
884 (swizzle >> 0) & 0x3,
885 (swizzle >> 2) & 0x3,
886 (swizzle >> 4) & 0x3,
887 (swizzle >> 6) & 0x3);
888 }
889
890
891 struct ureg_src
892 ureg_DECL_immediate( struct ureg_program *ureg,
893 const float *v,
894 unsigned nr )
895 {
896 union {
897 float f[4];
898 unsigned u[4];
899 } fu;
900 unsigned int i;
901
902 for (i = 0; i < nr; i++) {
903 fu.f[i] = v[i];
904 }
905
906 return decl_immediate(ureg, fu.u, nr, TGSI_IMM_FLOAT32);
907 }
908
909 struct ureg_src
910 ureg_DECL_immediate_f64( struct ureg_program *ureg,
911 const double *v,
912 unsigned nr )
913 {
914 union {
915 unsigned u[4];
916 double d[2];
917 } fu;
918 unsigned int i;
919
920 assert((nr / 2) < 3);
921 for (i = 0; i < nr / 2; i++) {
922 fu.d[i] = v[i];
923 }
924
925 return decl_immediate(ureg, fu.u, nr, TGSI_IMM_FLOAT64);
926 }
927
928 struct ureg_src
929 ureg_DECL_immediate_uint( struct ureg_program *ureg,
930 const unsigned *v,
931 unsigned nr )
932 {
933 return decl_immediate(ureg, v, nr, TGSI_IMM_UINT32);
934 }
935
936
937 struct ureg_src
938 ureg_DECL_immediate_block_uint( struct ureg_program *ureg,
939 const unsigned *v,
940 unsigned nr )
941 {
942 uint index;
943 uint i;
944
945 if (ureg->nr_immediates + (nr + 3) / 4 > UREG_MAX_IMMEDIATE) {
946 set_bad(ureg);
947 return ureg_src_register(TGSI_FILE_IMMEDIATE, 0);
948 }
949
950 index = ureg->nr_immediates;
951 ureg->nr_immediates += (nr + 3) / 4;
952
953 for (i = index; i < ureg->nr_immediates; i++) {
954 ureg->immediate[i].type = TGSI_IMM_UINT32;
955 ureg->immediate[i].nr = nr > 4 ? 4 : nr;
956 memcpy(ureg->immediate[i].value.u,
957 &v[(i - index) * 4],
958 ureg->immediate[i].nr * sizeof(uint));
959 nr -= 4;
960 }
961
962 return ureg_src_register(TGSI_FILE_IMMEDIATE, index);
963 }
964
965
966 struct ureg_src
967 ureg_DECL_immediate_int( struct ureg_program *ureg,
968 const int *v,
969 unsigned nr )
970 {
971 return decl_immediate(ureg, (const unsigned *)v, nr, TGSI_IMM_INT32);
972 }
973
974
975 void
976 ureg_emit_src( struct ureg_program *ureg,
977 struct ureg_src src )
978 {
979 unsigned size = 1 + (src.Indirect ? 1 : 0) +
980 (src.Dimension ? (src.DimIndirect ? 2 : 1) : 0);
981
982 union tgsi_any_token *out = get_tokens( ureg, DOMAIN_INSN, size );
983 unsigned n = 0;
984
985 assert(src.File != TGSI_FILE_NULL);
986 assert(src.File < TGSI_FILE_COUNT);
987
988 out[n].value = 0;
989 out[n].src.File = src.File;
990 out[n].src.SwizzleX = src.SwizzleX;
991 out[n].src.SwizzleY = src.SwizzleY;
992 out[n].src.SwizzleZ = src.SwizzleZ;
993 out[n].src.SwizzleW = src.SwizzleW;
994 out[n].src.Index = src.Index;
995 out[n].src.Negate = src.Negate;
996 out[0].src.Absolute = src.Absolute;
997 n++;
998
999 if (src.Indirect) {
1000 out[0].src.Indirect = 1;
1001 out[n].value = 0;
1002 out[n].ind.File = src.IndirectFile;
1003 out[n].ind.Swizzle = src.IndirectSwizzle;
1004 out[n].ind.Index = src.IndirectIndex;
1005 if (!ureg->supports_any_inout_decl_range &&
1006 (src.File == TGSI_FILE_INPUT || src.File == TGSI_FILE_OUTPUT))
1007 out[n].ind.ArrayID = 0;
1008 else
1009 out[n].ind.ArrayID = src.ArrayID;
1010 n++;
1011 }
1012
1013 if (src.Dimension) {
1014 out[0].src.Dimension = 1;
1015 out[n].dim.Dimension = 0;
1016 out[n].dim.Padding = 0;
1017 if (src.DimIndirect) {
1018 out[n].dim.Indirect = 1;
1019 out[n].dim.Index = src.DimensionIndex;
1020 n++;
1021 out[n].value = 0;
1022 out[n].ind.File = src.DimIndFile;
1023 out[n].ind.Swizzle = src.DimIndSwizzle;
1024 out[n].ind.Index = src.DimIndIndex;
1025 if (!ureg->supports_any_inout_decl_range &&
1026 (src.File == TGSI_FILE_INPUT || src.File == TGSI_FILE_OUTPUT))
1027 out[n].ind.ArrayID = 0;
1028 else
1029 out[n].ind.ArrayID = src.ArrayID;
1030 } else {
1031 out[n].dim.Indirect = 0;
1032 out[n].dim.Index = src.DimensionIndex;
1033 }
1034 n++;
1035 }
1036
1037 assert(n == size);
1038 }
1039
1040
1041 void
1042 ureg_emit_dst( struct ureg_program *ureg,
1043 struct ureg_dst dst )
1044 {
1045 unsigned size = 1 + (dst.Indirect ? 1 : 0) +
1046 (dst.Dimension ? (dst.DimIndirect ? 2 : 1) : 0);
1047
1048 union tgsi_any_token *out = get_tokens( ureg, DOMAIN_INSN, size );
1049 unsigned n = 0;
1050
1051 assert(dst.File != TGSI_FILE_NULL);
1052 assert(dst.File != TGSI_FILE_CONSTANT);
1053 assert(dst.File != TGSI_FILE_INPUT);
1054 assert(dst.File != TGSI_FILE_SAMPLER);
1055 assert(dst.File != TGSI_FILE_SAMPLER_VIEW);
1056 assert(dst.File != TGSI_FILE_IMMEDIATE);
1057 assert(dst.File < TGSI_FILE_COUNT);
1058
1059 out[n].value = 0;
1060 out[n].dst.File = dst.File;
1061 out[n].dst.WriteMask = dst.WriteMask;
1062 out[n].dst.Indirect = dst.Indirect;
1063 out[n].dst.Index = dst.Index;
1064 n++;
1065
1066 if (dst.Indirect) {
1067 out[n].value = 0;
1068 out[n].ind.File = dst.IndirectFile;
1069 out[n].ind.Swizzle = dst.IndirectSwizzle;
1070 out[n].ind.Index = dst.IndirectIndex;
1071 if (!ureg->supports_any_inout_decl_range &&
1072 (dst.File == TGSI_FILE_INPUT || dst.File == TGSI_FILE_OUTPUT))
1073 out[n].ind.ArrayID = 0;
1074 else
1075 out[n].ind.ArrayID = dst.ArrayID;
1076 n++;
1077 }
1078
1079 if (dst.Dimension) {
1080 out[0].dst.Dimension = 1;
1081 out[n].dim.Dimension = 0;
1082 out[n].dim.Padding = 0;
1083 if (dst.DimIndirect) {
1084 out[n].dim.Indirect = 1;
1085 out[n].dim.Index = dst.DimensionIndex;
1086 n++;
1087 out[n].value = 0;
1088 out[n].ind.File = dst.DimIndFile;
1089 out[n].ind.Swizzle = dst.DimIndSwizzle;
1090 out[n].ind.Index = dst.DimIndIndex;
1091 if (!ureg->supports_any_inout_decl_range &&
1092 (dst.File == TGSI_FILE_INPUT || dst.File == TGSI_FILE_OUTPUT))
1093 out[n].ind.ArrayID = 0;
1094 else
1095 out[n].ind.ArrayID = dst.ArrayID;
1096 } else {
1097 out[n].dim.Indirect = 0;
1098 out[n].dim.Index = dst.DimensionIndex;
1099 }
1100 n++;
1101 }
1102
1103 assert(n == size);
1104 }
1105
1106
1107 static void validate( unsigned opcode,
1108 unsigned nr_dst,
1109 unsigned nr_src )
1110 {
1111 #ifdef DEBUG
1112 const struct tgsi_opcode_info *info = tgsi_get_opcode_info( opcode );
1113 assert(info);
1114 if (info) {
1115 assert(nr_dst == info->num_dst);
1116 assert(nr_src == info->num_src);
1117 }
1118 #endif
1119 }
1120
1121 struct ureg_emit_insn_result
1122 ureg_emit_insn(struct ureg_program *ureg,
1123 unsigned opcode,
1124 boolean saturate,
1125 boolean predicate,
1126 boolean pred_negate,
1127 unsigned pred_swizzle_x,
1128 unsigned pred_swizzle_y,
1129 unsigned pred_swizzle_z,
1130 unsigned pred_swizzle_w,
1131 unsigned num_dst,
1132 unsigned num_src )
1133 {
1134 union tgsi_any_token *out;
1135 uint count = predicate ? 2 : 1;
1136 struct ureg_emit_insn_result result;
1137
1138 validate( opcode, num_dst, num_src );
1139
1140 out = get_tokens( ureg, DOMAIN_INSN, count );
1141 out[0].insn = tgsi_default_instruction();
1142 out[0].insn.Opcode = opcode;
1143 out[0].insn.Saturate = saturate;
1144 out[0].insn.NumDstRegs = num_dst;
1145 out[0].insn.NumSrcRegs = num_src;
1146
1147 result.insn_token = ureg->domain[DOMAIN_INSN].count - count;
1148 result.extended_token = result.insn_token;
1149
1150 if (predicate) {
1151 out[0].insn.Predicate = 1;
1152 out[1].insn_predicate = tgsi_default_instruction_predicate();
1153 out[1].insn_predicate.Negate = pred_negate;
1154 out[1].insn_predicate.SwizzleX = pred_swizzle_x;
1155 out[1].insn_predicate.SwizzleY = pred_swizzle_y;
1156 out[1].insn_predicate.SwizzleZ = pred_swizzle_z;
1157 out[1].insn_predicate.SwizzleW = pred_swizzle_w;
1158 }
1159
1160 ureg->nr_instructions++;
1161
1162 return result;
1163 }
1164
1165
1166 /**
1167 * Emit a label token.
1168 * \param label_token returns a token number indicating where the label
1169 * needs to be patched later. Later, this value should be passed to the
1170 * ureg_fixup_label() function.
1171 */
1172 void
1173 ureg_emit_label(struct ureg_program *ureg,
1174 unsigned extended_token,
1175 unsigned *label_token )
1176 {
1177 union tgsi_any_token *out, *insn;
1178
1179 if (!label_token)
1180 return;
1181
1182 out = get_tokens( ureg, DOMAIN_INSN, 1 );
1183 out[0].value = 0;
1184
1185 insn = retrieve_token( ureg, DOMAIN_INSN, extended_token );
1186 insn->insn.Label = 1;
1187
1188 *label_token = ureg->domain[DOMAIN_INSN].count - 1;
1189 }
1190
1191 /* Will return a number which can be used in a label to point to the
1192 * next instruction to be emitted.
1193 */
1194 unsigned
1195 ureg_get_instruction_number( struct ureg_program *ureg )
1196 {
1197 return ureg->nr_instructions;
1198 }
1199
1200 /* Patch a given label (expressed as a token number) to point to a
1201 * given instruction (expressed as an instruction number).
1202 */
1203 void
1204 ureg_fixup_label(struct ureg_program *ureg,
1205 unsigned label_token,
1206 unsigned instruction_number )
1207 {
1208 union tgsi_any_token *out = retrieve_token( ureg, DOMAIN_INSN, label_token );
1209
1210 out->insn_label.Label = instruction_number;
1211 }
1212
1213
1214 void
1215 ureg_emit_texture(struct ureg_program *ureg,
1216 unsigned extended_token,
1217 unsigned target, unsigned num_offsets)
1218 {
1219 union tgsi_any_token *out, *insn;
1220
1221 out = get_tokens( ureg, DOMAIN_INSN, 1 );
1222 insn = retrieve_token( ureg, DOMAIN_INSN, extended_token );
1223
1224 insn->insn.Texture = 1;
1225
1226 out[0].value = 0;
1227 out[0].insn_texture.Texture = target;
1228 out[0].insn_texture.NumOffsets = num_offsets;
1229 }
1230
1231 void
1232 ureg_emit_texture_offset(struct ureg_program *ureg,
1233 const struct tgsi_texture_offset *offset)
1234 {
1235 union tgsi_any_token *out;
1236
1237 out = get_tokens( ureg, DOMAIN_INSN, 1);
1238
1239 out[0].value = 0;
1240 out[0].insn_texture_offset = *offset;
1241
1242 }
1243
1244 void
1245 ureg_emit_memory(struct ureg_program *ureg,
1246 unsigned extended_token,
1247 unsigned qualifier,
1248 unsigned texture,
1249 unsigned format)
1250 {
1251 union tgsi_any_token *out, *insn;
1252
1253 out = get_tokens( ureg, DOMAIN_INSN, 1 );
1254 insn = retrieve_token( ureg, DOMAIN_INSN, extended_token );
1255
1256 insn->insn.Memory = 1;
1257
1258 out[0].value = 0;
1259 out[0].insn_memory.Qualifier = qualifier;
1260 out[0].insn_memory.Texture = texture;
1261 out[0].insn_memory.Format = format;
1262 }
1263
1264 void
1265 ureg_fixup_insn_size(struct ureg_program *ureg,
1266 unsigned insn )
1267 {
1268 union tgsi_any_token *out = retrieve_token( ureg, DOMAIN_INSN, insn );
1269
1270 assert(out->insn.Type == TGSI_TOKEN_TYPE_INSTRUCTION);
1271 out->insn.NrTokens = ureg->domain[DOMAIN_INSN].count - insn - 1;
1272 }
1273
1274
1275 void
1276 ureg_insn(struct ureg_program *ureg,
1277 unsigned opcode,
1278 const struct ureg_dst *dst,
1279 unsigned nr_dst,
1280 const struct ureg_src *src,
1281 unsigned nr_src )
1282 {
1283 struct ureg_emit_insn_result insn;
1284 unsigned i;
1285 boolean saturate;
1286 boolean predicate;
1287 boolean negate = FALSE;
1288 unsigned swizzle[4] = { 0 };
1289
1290 if (nr_dst && ureg_dst_is_empty(dst[0])) {
1291 return;
1292 }
1293
1294 saturate = nr_dst ? dst[0].Saturate : FALSE;
1295 predicate = nr_dst ? dst[0].Predicate : FALSE;
1296 if (predicate) {
1297 negate = dst[0].PredNegate;
1298 swizzle[0] = dst[0].PredSwizzleX;
1299 swizzle[1] = dst[0].PredSwizzleY;
1300 swizzle[2] = dst[0].PredSwizzleZ;
1301 swizzle[3] = dst[0].PredSwizzleW;
1302 }
1303
1304 insn = ureg_emit_insn(ureg,
1305 opcode,
1306 saturate,
1307 predicate,
1308 negate,
1309 swizzle[0],
1310 swizzle[1],
1311 swizzle[2],
1312 swizzle[3],
1313 nr_dst,
1314 nr_src);
1315
1316 for (i = 0; i < nr_dst; i++)
1317 ureg_emit_dst( ureg, dst[i] );
1318
1319 for (i = 0; i < nr_src; i++)
1320 ureg_emit_src( ureg, src[i] );
1321
1322 ureg_fixup_insn_size( ureg, insn.insn_token );
1323 }
1324
1325 void
1326 ureg_tex_insn(struct ureg_program *ureg,
1327 unsigned opcode,
1328 const struct ureg_dst *dst,
1329 unsigned nr_dst,
1330 unsigned target,
1331 const struct tgsi_texture_offset *texoffsets,
1332 unsigned nr_offset,
1333 const struct ureg_src *src,
1334 unsigned nr_src )
1335 {
1336 struct ureg_emit_insn_result insn;
1337 unsigned i;
1338 boolean saturate;
1339 boolean predicate;
1340 boolean negate = FALSE;
1341 unsigned swizzle[4] = { 0 };
1342
1343 if (nr_dst && ureg_dst_is_empty(dst[0])) {
1344 return;
1345 }
1346
1347 saturate = nr_dst ? dst[0].Saturate : FALSE;
1348 predicate = nr_dst ? dst[0].Predicate : FALSE;
1349 if (predicate) {
1350 negate = dst[0].PredNegate;
1351 swizzle[0] = dst[0].PredSwizzleX;
1352 swizzle[1] = dst[0].PredSwizzleY;
1353 swizzle[2] = dst[0].PredSwizzleZ;
1354 swizzle[3] = dst[0].PredSwizzleW;
1355 }
1356
1357 insn = ureg_emit_insn(ureg,
1358 opcode,
1359 saturate,
1360 predicate,
1361 negate,
1362 swizzle[0],
1363 swizzle[1],
1364 swizzle[2],
1365 swizzle[3],
1366 nr_dst,
1367 nr_src);
1368
1369 ureg_emit_texture( ureg, insn.extended_token, target, nr_offset );
1370
1371 for (i = 0; i < nr_offset; i++)
1372 ureg_emit_texture_offset( ureg, &texoffsets[i]);
1373
1374 for (i = 0; i < nr_dst; i++)
1375 ureg_emit_dst( ureg, dst[i] );
1376
1377 for (i = 0; i < nr_src; i++)
1378 ureg_emit_src( ureg, src[i] );
1379
1380 ureg_fixup_insn_size( ureg, insn.insn_token );
1381 }
1382
1383
1384 void
1385 ureg_label_insn(struct ureg_program *ureg,
1386 unsigned opcode,
1387 const struct ureg_src *src,
1388 unsigned nr_src,
1389 unsigned *label_token )
1390 {
1391 struct ureg_emit_insn_result insn;
1392 unsigned i;
1393
1394 insn = ureg_emit_insn(ureg,
1395 opcode,
1396 FALSE,
1397 FALSE,
1398 FALSE,
1399 TGSI_SWIZZLE_X,
1400 TGSI_SWIZZLE_Y,
1401 TGSI_SWIZZLE_Z,
1402 TGSI_SWIZZLE_W,
1403 0,
1404 nr_src);
1405
1406 ureg_emit_label( ureg, insn.extended_token, label_token );
1407
1408 for (i = 0; i < nr_src; i++)
1409 ureg_emit_src( ureg, src[i] );
1410
1411 ureg_fixup_insn_size( ureg, insn.insn_token );
1412 }
1413
1414
1415 void
1416 ureg_memory_insn(struct ureg_program *ureg,
1417 unsigned opcode,
1418 const struct ureg_dst *dst,
1419 unsigned nr_dst,
1420 const struct ureg_src *src,
1421 unsigned nr_src,
1422 unsigned qualifier,
1423 unsigned texture,
1424 unsigned format)
1425 {
1426 struct ureg_emit_insn_result insn;
1427 unsigned i;
1428
1429 insn = ureg_emit_insn(ureg,
1430 opcode,
1431 FALSE,
1432 FALSE,
1433 FALSE,
1434 TGSI_SWIZZLE_X,
1435 TGSI_SWIZZLE_Y,
1436 TGSI_SWIZZLE_Z,
1437 TGSI_SWIZZLE_W,
1438 nr_dst,
1439 nr_src);
1440
1441 ureg_emit_memory(ureg, insn.extended_token, qualifier, texture, format);
1442
1443 for (i = 0; i < nr_dst; i++)
1444 ureg_emit_dst(ureg, dst[i]);
1445
1446 for (i = 0; i < nr_src; i++)
1447 ureg_emit_src(ureg, src[i]);
1448
1449 ureg_fixup_insn_size(ureg, insn.insn_token);
1450 }
1451
1452
1453 static void
1454 emit_decl_semantic(struct ureg_program *ureg,
1455 unsigned file,
1456 unsigned first,
1457 unsigned last,
1458 unsigned semantic_name,
1459 unsigned semantic_index,
1460 unsigned usage_mask,
1461 unsigned array_id)
1462 {
1463 union tgsi_any_token *out = get_tokens(ureg, DOMAIN_DECL, array_id ? 4 : 3);
1464
1465 out[0].value = 0;
1466 out[0].decl.Type = TGSI_TOKEN_TYPE_DECLARATION;
1467 out[0].decl.NrTokens = 3;
1468 out[0].decl.File = file;
1469 out[0].decl.UsageMask = usage_mask;
1470 out[0].decl.Semantic = 1;
1471 out[0].decl.Array = array_id != 0;
1472
1473 out[1].value = 0;
1474 out[1].decl_range.First = first;
1475 out[1].decl_range.Last = last;
1476
1477 out[2].value = 0;
1478 out[2].decl_semantic.Name = semantic_name;
1479 out[2].decl_semantic.Index = semantic_index;
1480
1481 if (array_id) {
1482 out[3].value = 0;
1483 out[3].array.ArrayID = array_id;
1484 }
1485 }
1486
1487
1488 static void
1489 emit_decl_fs(struct ureg_program *ureg,
1490 unsigned file,
1491 unsigned first,
1492 unsigned last,
1493 unsigned semantic_name,
1494 unsigned semantic_index,
1495 unsigned interpolate,
1496 unsigned cylindrical_wrap,
1497 unsigned interpolate_location,
1498 unsigned array_id)
1499 {
1500 union tgsi_any_token *out = get_tokens(ureg, DOMAIN_DECL,
1501 array_id ? 5 : 4);
1502
1503 out[0].value = 0;
1504 out[0].decl.Type = TGSI_TOKEN_TYPE_DECLARATION;
1505 out[0].decl.NrTokens = 4;
1506 out[0].decl.File = file;
1507 out[0].decl.UsageMask = TGSI_WRITEMASK_XYZW; /* FIXME! */
1508 out[0].decl.Interpolate = 1;
1509 out[0].decl.Semantic = 1;
1510 out[0].decl.Array = array_id != 0;
1511
1512 out[1].value = 0;
1513 out[1].decl_range.First = first;
1514 out[1].decl_range.Last = last;
1515
1516 out[2].value = 0;
1517 out[2].decl_interp.Interpolate = interpolate;
1518 out[2].decl_interp.CylindricalWrap = cylindrical_wrap;
1519 out[2].decl_interp.Location = interpolate_location;
1520
1521 out[3].value = 0;
1522 out[3].decl_semantic.Name = semantic_name;
1523 out[3].decl_semantic.Index = semantic_index;
1524
1525 if (array_id) {
1526 out[4].value = 0;
1527 out[4].array.ArrayID = array_id;
1528 }
1529 }
1530
1531 static void
1532 emit_decl_temps( struct ureg_program *ureg,
1533 unsigned first, unsigned last,
1534 boolean local,
1535 unsigned arrayid )
1536 {
1537 union tgsi_any_token *out = get_tokens( ureg, DOMAIN_DECL,
1538 arrayid ? 3 : 2 );
1539
1540 out[0].value = 0;
1541 out[0].decl.Type = TGSI_TOKEN_TYPE_DECLARATION;
1542 out[0].decl.NrTokens = 2;
1543 out[0].decl.File = TGSI_FILE_TEMPORARY;
1544 out[0].decl.UsageMask = TGSI_WRITEMASK_XYZW;
1545 out[0].decl.Local = local;
1546
1547 out[1].value = 0;
1548 out[1].decl_range.First = first;
1549 out[1].decl_range.Last = last;
1550
1551 if (arrayid) {
1552 out[0].decl.Array = 1;
1553 out[2].value = 0;
1554 out[2].array.ArrayID = arrayid;
1555 }
1556 }
1557
1558 static void emit_decl_range( struct ureg_program *ureg,
1559 unsigned file,
1560 unsigned first,
1561 unsigned count )
1562 {
1563 union tgsi_any_token *out = get_tokens( ureg, DOMAIN_DECL, 2 );
1564
1565 out[0].value = 0;
1566 out[0].decl.Type = TGSI_TOKEN_TYPE_DECLARATION;
1567 out[0].decl.NrTokens = 2;
1568 out[0].decl.File = file;
1569 out[0].decl.UsageMask = TGSI_WRITEMASK_XYZW;
1570 out[0].decl.Semantic = 0;
1571
1572 out[1].value = 0;
1573 out[1].decl_range.First = first;
1574 out[1].decl_range.Last = first + count - 1;
1575 }
1576
1577 static void
1578 emit_decl_range2D(struct ureg_program *ureg,
1579 unsigned file,
1580 unsigned first,
1581 unsigned last,
1582 unsigned index2D)
1583 {
1584 union tgsi_any_token *out = get_tokens(ureg, DOMAIN_DECL, 3);
1585
1586 out[0].value = 0;
1587 out[0].decl.Type = TGSI_TOKEN_TYPE_DECLARATION;
1588 out[0].decl.NrTokens = 3;
1589 out[0].decl.File = file;
1590 out[0].decl.UsageMask = TGSI_WRITEMASK_XYZW;
1591 out[0].decl.Dimension = 1;
1592
1593 out[1].value = 0;
1594 out[1].decl_range.First = first;
1595 out[1].decl_range.Last = last;
1596
1597 out[2].value = 0;
1598 out[2].decl_dim.Index2D = index2D;
1599 }
1600
1601 static void
1602 emit_decl_sampler_view(struct ureg_program *ureg,
1603 unsigned index,
1604 unsigned target,
1605 unsigned return_type_x,
1606 unsigned return_type_y,
1607 unsigned return_type_z,
1608 unsigned return_type_w )
1609 {
1610 union tgsi_any_token *out = get_tokens(ureg, DOMAIN_DECL, 3);
1611
1612 out[0].value = 0;
1613 out[0].decl.Type = TGSI_TOKEN_TYPE_DECLARATION;
1614 out[0].decl.NrTokens = 3;
1615 out[0].decl.File = TGSI_FILE_SAMPLER_VIEW;
1616 out[0].decl.UsageMask = TGSI_WRITEMASK_XYZW;
1617
1618 out[1].value = 0;
1619 out[1].decl_range.First = index;
1620 out[1].decl_range.Last = index;
1621
1622 out[2].value = 0;
1623 out[2].decl_sampler_view.Resource = target;
1624 out[2].decl_sampler_view.ReturnTypeX = return_type_x;
1625 out[2].decl_sampler_view.ReturnTypeY = return_type_y;
1626 out[2].decl_sampler_view.ReturnTypeZ = return_type_z;
1627 out[2].decl_sampler_view.ReturnTypeW = return_type_w;
1628 }
1629
1630 static void
1631 emit_decl_image(struct ureg_program *ureg,
1632 unsigned index,
1633 unsigned target,
1634 unsigned format,
1635 boolean wr,
1636 boolean raw)
1637 {
1638 union tgsi_any_token *out = get_tokens(ureg, DOMAIN_DECL, 3);
1639
1640 out[0].value = 0;
1641 out[0].decl.Type = TGSI_TOKEN_TYPE_DECLARATION;
1642 out[0].decl.NrTokens = 3;
1643 out[0].decl.File = TGSI_FILE_IMAGE;
1644 out[0].decl.UsageMask = TGSI_WRITEMASK_XYZW;
1645
1646 out[1].value = 0;
1647 out[1].decl_range.First = index;
1648 out[1].decl_range.Last = index;
1649
1650 out[2].value = 0;
1651 out[2].decl_image.Resource = target;
1652 out[2].decl_image.Writable = wr;
1653 out[2].decl_image.Raw = raw;
1654 out[2].decl_image.Format = format;
1655 }
1656
1657 static void
1658 emit_decl_buffer(struct ureg_program *ureg,
1659 unsigned index,
1660 bool atomic)
1661 {
1662 union tgsi_any_token *out = get_tokens(ureg, DOMAIN_DECL, 2);
1663
1664 out[0].value = 0;
1665 out[0].decl.Type = TGSI_TOKEN_TYPE_DECLARATION;
1666 out[0].decl.NrTokens = 2;
1667 out[0].decl.File = TGSI_FILE_BUFFER;
1668 out[0].decl.UsageMask = TGSI_WRITEMASK_XYZW;
1669 out[0].decl.Atomic = atomic;
1670
1671 out[1].value = 0;
1672 out[1].decl_range.First = index;
1673 out[1].decl_range.Last = index;
1674 }
1675
1676 static void
1677 emit_decl_memory(struct ureg_program *ureg, unsigned memory_type)
1678 {
1679 union tgsi_any_token *out = get_tokens(ureg, DOMAIN_DECL, 2);
1680
1681 out[0].value = 0;
1682 out[0].decl.Type = TGSI_TOKEN_TYPE_DECLARATION;
1683 out[0].decl.NrTokens = 2;
1684 out[0].decl.File = TGSI_FILE_MEMORY;
1685 out[0].decl.UsageMask = TGSI_WRITEMASK_XYZW;
1686 out[0].decl.MemType = memory_type;
1687
1688 out[1].value = 0;
1689 out[1].decl_range.First = memory_type;
1690 out[1].decl_range.Last = memory_type;
1691 }
1692
1693 static void
1694 emit_immediate( struct ureg_program *ureg,
1695 const unsigned *v,
1696 unsigned type )
1697 {
1698 union tgsi_any_token *out = get_tokens( ureg, DOMAIN_DECL, 5 );
1699
1700 out[0].value = 0;
1701 out[0].imm.Type = TGSI_TOKEN_TYPE_IMMEDIATE;
1702 out[0].imm.NrTokens = 5;
1703 out[0].imm.DataType = type;
1704 out[0].imm.Padding = 0;
1705
1706 out[1].imm_data.Uint = v[0];
1707 out[2].imm_data.Uint = v[1];
1708 out[3].imm_data.Uint = v[2];
1709 out[4].imm_data.Uint = v[3];
1710 }
1711
1712 static void
1713 emit_property(struct ureg_program *ureg,
1714 unsigned name,
1715 unsigned data)
1716 {
1717 union tgsi_any_token *out = get_tokens(ureg, DOMAIN_DECL, 2);
1718
1719 out[0].value = 0;
1720 out[0].prop.Type = TGSI_TOKEN_TYPE_PROPERTY;
1721 out[0].prop.NrTokens = 2;
1722 out[0].prop.PropertyName = name;
1723
1724 out[1].prop_data.Data = data;
1725 }
1726
1727
1728 static void emit_decls( struct ureg_program *ureg )
1729 {
1730 unsigned i,j;
1731
1732 for (i = 0; i < Elements(ureg->properties); i++)
1733 if (ureg->properties[i] != ~0)
1734 emit_property(ureg, i, ureg->properties[i]);
1735
1736 if (ureg->processor == PIPE_SHADER_VERTEX) {
1737 for (i = 0; i < PIPE_MAX_ATTRIBS; i++) {
1738 if (ureg->vs_inputs[i/32] & (1 << (i%32))) {
1739 emit_decl_range( ureg, TGSI_FILE_INPUT, i, 1 );
1740 }
1741 }
1742 } else if (ureg->processor == PIPE_SHADER_FRAGMENT) {
1743 if (ureg->supports_any_inout_decl_range) {
1744 for (i = 0; i < ureg->nr_inputs; i++) {
1745 emit_decl_fs(ureg,
1746 TGSI_FILE_INPUT,
1747 ureg->input[i].first,
1748 ureg->input[i].last,
1749 ureg->input[i].semantic_name,
1750 ureg->input[i].semantic_index,
1751 ureg->input[i].interp,
1752 ureg->input[i].cylindrical_wrap,
1753 ureg->input[i].interp_location,
1754 ureg->input[i].array_id);
1755 }
1756 }
1757 else {
1758 for (i = 0; i < ureg->nr_inputs; i++) {
1759 for (j = ureg->input[i].first; j <= ureg->input[i].last; j++) {
1760 emit_decl_fs(ureg,
1761 TGSI_FILE_INPUT,
1762 j, j,
1763 ureg->input[i].semantic_name,
1764 ureg->input[i].semantic_index +
1765 (j - ureg->input[i].first),
1766 ureg->input[i].interp,
1767 ureg->input[i].cylindrical_wrap,
1768 ureg->input[i].interp_location, 0);
1769 }
1770 }
1771 }
1772 } else {
1773 if (ureg->supports_any_inout_decl_range) {
1774 for (i = 0; i < ureg->nr_inputs; i++) {
1775 emit_decl_semantic(ureg,
1776 TGSI_FILE_INPUT,
1777 ureg->input[i].first,
1778 ureg->input[i].last,
1779 ureg->input[i].semantic_name,
1780 ureg->input[i].semantic_index,
1781 TGSI_WRITEMASK_XYZW,
1782 ureg->input[i].array_id);
1783 }
1784 }
1785 else {
1786 for (i = 0; i < ureg->nr_inputs; i++) {
1787 for (j = ureg->input[i].first; j <= ureg->input[i].last; j++) {
1788 emit_decl_semantic(ureg,
1789 TGSI_FILE_INPUT,
1790 j, j,
1791 ureg->input[i].semantic_name,
1792 ureg->input[i].semantic_index +
1793 (j - ureg->input[i].first),
1794 TGSI_WRITEMASK_XYZW, 0);
1795 }
1796 }
1797 }
1798 }
1799
1800 for (i = 0; i < ureg->nr_system_values; i++) {
1801 emit_decl_semantic(ureg,
1802 TGSI_FILE_SYSTEM_VALUE,
1803 i,
1804 i,
1805 ureg->system_value[i].semantic_name,
1806 ureg->system_value[i].semantic_index,
1807 TGSI_WRITEMASK_XYZW, 0);
1808 }
1809
1810 if (ureg->supports_any_inout_decl_range) {
1811 for (i = 0; i < ureg->nr_outputs; i++) {
1812 emit_decl_semantic(ureg,
1813 TGSI_FILE_OUTPUT,
1814 ureg->output[i].first,
1815 ureg->output[i].last,
1816 ureg->output[i].semantic_name,
1817 ureg->output[i].semantic_index,
1818 ureg->output[i].usage_mask,
1819 ureg->output[i].array_id);
1820 }
1821 }
1822 else {
1823 for (i = 0; i < ureg->nr_outputs; i++) {
1824 for (j = ureg->output[i].first; j <= ureg->output[i].last; j++) {
1825 emit_decl_semantic(ureg,
1826 TGSI_FILE_OUTPUT,
1827 j, j,
1828 ureg->output[i].semantic_name,
1829 ureg->output[i].semantic_index +
1830 (j - ureg->output[i].first),
1831 ureg->output[i].usage_mask, 0);
1832 }
1833 }
1834 }
1835
1836 for (i = 0; i < ureg->nr_samplers; i++) {
1837 emit_decl_range( ureg,
1838 TGSI_FILE_SAMPLER,
1839 ureg->sampler[i].Index, 1 );
1840 }
1841
1842 for (i = 0; i < ureg->nr_sampler_views; i++) {
1843 emit_decl_sampler_view(ureg,
1844 ureg->sampler_view[i].index,
1845 ureg->sampler_view[i].target,
1846 ureg->sampler_view[i].return_type_x,
1847 ureg->sampler_view[i].return_type_y,
1848 ureg->sampler_view[i].return_type_z,
1849 ureg->sampler_view[i].return_type_w);
1850 }
1851
1852 for (i = 0; i < ureg->nr_images; i++) {
1853 emit_decl_image(ureg,
1854 ureg->image[i].index,
1855 ureg->image[i].target,
1856 ureg->image[i].format,
1857 ureg->image[i].wr,
1858 ureg->image[i].raw);
1859 }
1860
1861 for (i = 0; i < ureg->nr_buffers; i++) {
1862 emit_decl_buffer(ureg, ureg->buffer[i].index, ureg->buffer[i].atomic);
1863 }
1864
1865 for (i = 0; i < TGSI_MEMORY_TYPE_COUNT; i++) {
1866 if (ureg->use_memory[i])
1867 emit_decl_memory(ureg, i);
1868 }
1869
1870 if (ureg->const_decls.nr_constant_ranges) {
1871 for (i = 0; i < ureg->const_decls.nr_constant_ranges; i++) {
1872 emit_decl_range(ureg,
1873 TGSI_FILE_CONSTANT,
1874 ureg->const_decls.constant_range[i].first,
1875 ureg->const_decls.constant_range[i].last - ureg->const_decls.constant_range[i].first + 1);
1876 }
1877 }
1878
1879 for (i = 0; i < PIPE_MAX_CONSTANT_BUFFERS; i++) {
1880 struct const_decl *decl = &ureg->const_decls2D[i];
1881
1882 if (decl->nr_constant_ranges) {
1883 uint j;
1884
1885 for (j = 0; j < decl->nr_constant_ranges; j++) {
1886 emit_decl_range2D(ureg,
1887 TGSI_FILE_CONSTANT,
1888 decl->constant_range[j].first,
1889 decl->constant_range[j].last,
1890 i);
1891 }
1892 }
1893 }
1894
1895 if (ureg->nr_temps) {
1896 unsigned array = 0;
1897 for (i = 0; i < ureg->nr_temps;) {
1898 boolean local = util_bitmask_get(ureg->local_temps, i);
1899 unsigned first = i;
1900 i = util_bitmask_get_next_index(ureg->decl_temps, i + 1);
1901 if (i == UTIL_BITMASK_INVALID_INDEX)
1902 i = ureg->nr_temps;
1903
1904 if (array < ureg->nr_array_temps && ureg->array_temps[array] == first)
1905 emit_decl_temps( ureg, first, i - 1, local, ++array );
1906 else
1907 emit_decl_temps( ureg, first, i - 1, local, 0 );
1908 }
1909 }
1910
1911 if (ureg->nr_addrs) {
1912 emit_decl_range( ureg,
1913 TGSI_FILE_ADDRESS,
1914 0, ureg->nr_addrs );
1915 }
1916
1917 if (ureg->nr_preds) {
1918 emit_decl_range(ureg,
1919 TGSI_FILE_PREDICATE,
1920 0,
1921 ureg->nr_preds);
1922 }
1923
1924 for (i = 0; i < ureg->nr_immediates; i++) {
1925 emit_immediate( ureg,
1926 ureg->immediate[i].value.u,
1927 ureg->immediate[i].type );
1928 }
1929 }
1930
1931 /* Append the instruction tokens onto the declarations to build a
1932 * contiguous stream suitable to send to the driver.
1933 */
1934 static void copy_instructions( struct ureg_program *ureg )
1935 {
1936 unsigned nr_tokens = ureg->domain[DOMAIN_INSN].count;
1937 union tgsi_any_token *out = get_tokens( ureg,
1938 DOMAIN_DECL,
1939 nr_tokens );
1940
1941 memcpy(out,
1942 ureg->domain[DOMAIN_INSN].tokens,
1943 nr_tokens * sizeof out[0] );
1944 }
1945
1946
1947 static void
1948 fixup_header_size(struct ureg_program *ureg)
1949 {
1950 union tgsi_any_token *out = retrieve_token( ureg, DOMAIN_DECL, 0 );
1951
1952 out->header.BodySize = ureg->domain[DOMAIN_DECL].count - 2;
1953 }
1954
1955
1956 static void
1957 emit_header( struct ureg_program *ureg )
1958 {
1959 union tgsi_any_token *out = get_tokens( ureg, DOMAIN_DECL, 2 );
1960
1961 out[0].header.HeaderSize = 2;
1962 out[0].header.BodySize = 0;
1963
1964 out[1].processor.Processor = ureg->processor;
1965 out[1].processor.Padding = 0;
1966 }
1967
1968
1969 const struct tgsi_token *ureg_finalize( struct ureg_program *ureg )
1970 {
1971 const struct tgsi_token *tokens;
1972
1973 switch (ureg->processor) {
1974 case PIPE_SHADER_VERTEX:
1975 case PIPE_SHADER_TESS_EVAL:
1976 ureg_property(ureg, TGSI_PROPERTY_NEXT_SHADER,
1977 ureg->next_shader_processor == -1 ?
1978 PIPE_SHADER_FRAGMENT :
1979 ureg->next_shader_processor);
1980 break;
1981 }
1982
1983 emit_header( ureg );
1984 emit_decls( ureg );
1985 copy_instructions( ureg );
1986 fixup_header_size( ureg );
1987
1988 if (ureg->domain[0].tokens == error_tokens ||
1989 ureg->domain[1].tokens == error_tokens) {
1990 debug_printf("%s: error in generated shader\n", __FUNCTION__);
1991 assert(0);
1992 return NULL;
1993 }
1994
1995 tokens = &ureg->domain[DOMAIN_DECL].tokens[0].token;
1996
1997 if (0) {
1998 debug_printf("%s: emitted shader %d tokens:\n", __FUNCTION__,
1999 ureg->domain[DOMAIN_DECL].count);
2000 tgsi_dump( tokens, 0 );
2001 }
2002
2003 #if DEBUG
2004 if (tokens && !tgsi_sanity_check(tokens)) {
2005 debug_printf("tgsi_ureg.c, sanity check failed on generated tokens:\n");
2006 tgsi_dump(tokens, 0);
2007 assert(0);
2008 }
2009 #endif
2010
2011
2012 return tokens;
2013 }
2014
2015
2016 void *ureg_create_shader( struct ureg_program *ureg,
2017 struct pipe_context *pipe,
2018 const struct pipe_stream_output_info *so )
2019 {
2020 struct pipe_shader_state state;
2021
2022 state.tokens = ureg_finalize(ureg);
2023 if(!state.tokens)
2024 return NULL;
2025
2026 if (so)
2027 state.stream_output = *so;
2028 else
2029 memset(&state.stream_output, 0, sizeof(state.stream_output));
2030
2031 switch (ureg->processor) {
2032 case PIPE_SHADER_VERTEX:
2033 return pipe->create_vs_state(pipe, &state);
2034 case PIPE_SHADER_TESS_CTRL:
2035 return pipe->create_tcs_state(pipe, &state);
2036 case PIPE_SHADER_TESS_EVAL:
2037 return pipe->create_tes_state(pipe, &state);
2038 case PIPE_SHADER_GEOMETRY:
2039 return pipe->create_gs_state(pipe, &state);
2040 case PIPE_SHADER_FRAGMENT:
2041 return pipe->create_fs_state(pipe, &state);
2042 default:
2043 return NULL;
2044 }
2045 }
2046
2047
2048 const struct tgsi_token *ureg_get_tokens( struct ureg_program *ureg,
2049 unsigned *nr_tokens )
2050 {
2051 const struct tgsi_token *tokens;
2052
2053 ureg_finalize(ureg);
2054
2055 tokens = &ureg->domain[DOMAIN_DECL].tokens[0].token;
2056
2057 if (nr_tokens)
2058 *nr_tokens = ureg->domain[DOMAIN_DECL].size;
2059
2060 ureg->domain[DOMAIN_DECL].tokens = 0;
2061 ureg->domain[DOMAIN_DECL].size = 0;
2062 ureg->domain[DOMAIN_DECL].order = 0;
2063 ureg->domain[DOMAIN_DECL].count = 0;
2064
2065 return tokens;
2066 }
2067
2068
2069 void ureg_free_tokens( const struct tgsi_token *tokens )
2070 {
2071 FREE((struct tgsi_token *)tokens);
2072 }
2073
2074
2075 struct ureg_program *
2076 ureg_create(unsigned processor)
2077 {
2078 return ureg_create_with_screen(processor, NULL);
2079 }
2080
2081
2082 struct ureg_program *
2083 ureg_create_with_screen(unsigned processor, struct pipe_screen *screen)
2084 {
2085 int i;
2086 struct ureg_program *ureg = CALLOC_STRUCT( ureg_program );
2087 if (!ureg)
2088 goto no_ureg;
2089
2090 ureg->processor = processor;
2091 ureg->supports_any_inout_decl_range =
2092 screen &&
2093 screen->get_shader_param(screen,
2094 util_pipe_shader_from_tgsi_processor(processor),
2095 PIPE_SHADER_CAP_TGSI_ANY_INOUT_DECL_RANGE) != 0;
2096 ureg->next_shader_processor = -1;
2097
2098 for (i = 0; i < Elements(ureg->properties); i++)
2099 ureg->properties[i] = ~0;
2100
2101 ureg->free_temps = util_bitmask_create();
2102 if (ureg->free_temps == NULL)
2103 goto no_free_temps;
2104
2105 ureg->local_temps = util_bitmask_create();
2106 if (ureg->local_temps == NULL)
2107 goto no_local_temps;
2108
2109 ureg->decl_temps = util_bitmask_create();
2110 if (ureg->decl_temps == NULL)
2111 goto no_decl_temps;
2112
2113 return ureg;
2114
2115 no_decl_temps:
2116 util_bitmask_destroy(ureg->local_temps);
2117 no_local_temps:
2118 util_bitmask_destroy(ureg->free_temps);
2119 no_free_temps:
2120 FREE(ureg);
2121 no_ureg:
2122 return NULL;
2123 }
2124
2125
2126 void
2127 ureg_set_next_shader_processor(struct ureg_program *ureg, unsigned processor)
2128 {
2129 ureg->next_shader_processor = processor;
2130 }
2131
2132
2133 unsigned
2134 ureg_get_nr_outputs( const struct ureg_program *ureg )
2135 {
2136 if (!ureg)
2137 return 0;
2138 return ureg->nr_outputs;
2139 }
2140
2141
2142 void ureg_destroy( struct ureg_program *ureg )
2143 {
2144 unsigned i;
2145
2146 for (i = 0; i < Elements(ureg->domain); i++) {
2147 if (ureg->domain[i].tokens &&
2148 ureg->domain[i].tokens != error_tokens)
2149 FREE(ureg->domain[i].tokens);
2150 }
2151
2152 util_bitmask_destroy(ureg->free_temps);
2153 util_bitmask_destroy(ureg->local_temps);
2154 util_bitmask_destroy(ureg->decl_temps);
2155
2156 FREE(ureg);
2157 }