draw: stop using CULLDIST semantic.
[mesa.git] / src / gallium / auxiliary / tgsi / tgsi_scan.c
1 /**************************************************************************
2 *
3 * Copyright 2008 VMware, Inc.
4 * All Rights Reserved.
5 * Copyright 2008 VMware, Inc. All rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
17 * of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 *
27 **************************************************************************/
28
29 /**
30 * TGSI program scan utility.
31 * Used to determine which registers and instructions are used by a shader.
32 *
33 * Authors: Brian Paul
34 */
35
36
37 #include "util/u_debug.h"
38 #include "util/u_math.h"
39 #include "util/u_memory.h"
40 #include "util/u_prim.h"
41 #include "tgsi/tgsi_info.h"
42 #include "tgsi/tgsi_parse.h"
43 #include "tgsi/tgsi_util.h"
44 #include "tgsi/tgsi_scan.h"
45
46
47 static bool
48 is_memory_file(unsigned file)
49 {
50 return file == TGSI_FILE_SAMPLER ||
51 file == TGSI_FILE_SAMPLER_VIEW ||
52 file == TGSI_FILE_IMAGE ||
53 file == TGSI_FILE_BUFFER;
54 }
55
56
57 /**
58 * Is the opcode a "true" texture instruction which samples from a
59 * texture map?
60 */
61 static bool
62 is_texture_inst(unsigned opcode)
63 {
64 return (opcode != TGSI_OPCODE_TXQ &&
65 opcode != TGSI_OPCODE_TXQS &&
66 opcode != TGSI_OPCODE_TXQ_LZ &&
67 opcode != TGSI_OPCODE_LODQ &&
68 tgsi_get_opcode_info(opcode)->is_tex);
69 }
70
71 static void
72 scan_instruction(struct tgsi_shader_info *info,
73 const struct tgsi_full_instruction *fullinst,
74 unsigned *current_depth)
75 {
76 unsigned i;
77 bool is_mem_inst = false;
78
79 assert(fullinst->Instruction.Opcode < TGSI_OPCODE_LAST);
80 info->opcode_count[fullinst->Instruction.Opcode]++;
81
82 switch (fullinst->Instruction.Opcode) {
83 case TGSI_OPCODE_IF:
84 case TGSI_OPCODE_UIF:
85 case TGSI_OPCODE_BGNLOOP:
86 (*current_depth)++;
87 info->max_depth = MAX2(info->max_depth, *current_depth);
88 break;
89 case TGSI_OPCODE_ENDIF:
90 case TGSI_OPCODE_ENDLOOP:
91 (*current_depth)--;
92 break;
93 default:
94 break;
95 }
96
97 if (fullinst->Instruction.Opcode == TGSI_OPCODE_INTERP_CENTROID ||
98 fullinst->Instruction.Opcode == TGSI_OPCODE_INTERP_OFFSET ||
99 fullinst->Instruction.Opcode == TGSI_OPCODE_INTERP_SAMPLE) {
100 const struct tgsi_full_src_register *src0 = &fullinst->Src[0];
101 unsigned input;
102
103 if (src0->Register.Indirect && src0->Indirect.ArrayID)
104 input = info->input_array_first[src0->Indirect.ArrayID];
105 else
106 input = src0->Register.Index;
107
108 /* For the INTERP opcodes, the interpolation is always
109 * PERSPECTIVE unless LINEAR is specified.
110 */
111 switch (info->input_interpolate[input]) {
112 case TGSI_INTERPOLATE_COLOR:
113 case TGSI_INTERPOLATE_CONSTANT:
114 case TGSI_INTERPOLATE_PERSPECTIVE:
115 switch (fullinst->Instruction.Opcode) {
116 case TGSI_OPCODE_INTERP_CENTROID:
117 info->uses_persp_opcode_interp_centroid = TRUE;
118 break;
119 case TGSI_OPCODE_INTERP_OFFSET:
120 info->uses_persp_opcode_interp_offset = TRUE;
121 break;
122 case TGSI_OPCODE_INTERP_SAMPLE:
123 info->uses_persp_opcode_interp_sample = TRUE;
124 break;
125 }
126 break;
127
128 case TGSI_INTERPOLATE_LINEAR:
129 switch (fullinst->Instruction.Opcode) {
130 case TGSI_OPCODE_INTERP_CENTROID:
131 info->uses_linear_opcode_interp_centroid = TRUE;
132 break;
133 case TGSI_OPCODE_INTERP_OFFSET:
134 info->uses_linear_opcode_interp_offset = TRUE;
135 break;
136 case TGSI_OPCODE_INTERP_SAMPLE:
137 info->uses_linear_opcode_interp_sample = TRUE;
138 break;
139 }
140 break;
141 }
142 }
143
144 if (fullinst->Instruction.Opcode >= TGSI_OPCODE_F2D &&
145 fullinst->Instruction.Opcode <= TGSI_OPCODE_DSSG)
146 info->uses_doubles = TRUE;
147
148 for (i = 0; i < fullinst->Instruction.NumSrcRegs; i++) {
149 const struct tgsi_full_src_register *src = &fullinst->Src[i];
150 int ind = src->Register.Index;
151
152 /* Mark which inputs are effectively used */
153 if (src->Register.File == TGSI_FILE_INPUT) {
154 unsigned usage_mask;
155 usage_mask = tgsi_util_get_inst_usage_mask(fullinst, i);
156 if (src->Register.Indirect) {
157 for (ind = 0; ind < info->num_inputs; ++ind) {
158 info->input_usage_mask[ind] |= usage_mask;
159 }
160 } else {
161 assert(ind >= 0);
162 assert(ind < PIPE_MAX_SHADER_INPUTS);
163 info->input_usage_mask[ind] |= usage_mask;
164 }
165
166 if (info->processor == PIPE_SHADER_FRAGMENT &&
167 !src->Register.Indirect) {
168 unsigned name =
169 info->input_semantic_name[src->Register.Index];
170 unsigned index =
171 info->input_semantic_index[src->Register.Index];
172
173 if (name == TGSI_SEMANTIC_POSITION &&
174 (src->Register.SwizzleX == TGSI_SWIZZLE_Z ||
175 src->Register.SwizzleY == TGSI_SWIZZLE_Z ||
176 src->Register.SwizzleZ == TGSI_SWIZZLE_Z ||
177 src->Register.SwizzleW == TGSI_SWIZZLE_Z))
178 info->reads_z = TRUE;
179
180 if (name == TGSI_SEMANTIC_COLOR) {
181 unsigned mask =
182 (1 << src->Register.SwizzleX) |
183 (1 << src->Register.SwizzleY) |
184 (1 << src->Register.SwizzleZ) |
185 (1 << src->Register.SwizzleW);
186
187 info->colors_read |= mask << (index * 4);
188 }
189 }
190 }
191
192 /* check for indirect register reads */
193 if (src->Register.Indirect) {
194 info->indirect_files |= (1 << src->Register.File);
195 info->indirect_files_read |= (1 << src->Register.File);
196 }
197
198 /* Texture samplers */
199 if (src->Register.File == TGSI_FILE_SAMPLER) {
200 const unsigned index = src->Register.Index;
201
202 assert(fullinst->Instruction.Texture);
203 assert(index < ARRAY_SIZE(info->is_msaa_sampler));
204 assert(index < PIPE_MAX_SAMPLERS);
205
206 if (is_texture_inst(fullinst->Instruction.Opcode)) {
207 const unsigned target = fullinst->Texture.Texture;
208 assert(target < TGSI_TEXTURE_UNKNOWN);
209 /* for texture instructions, check that the texture instruction
210 * target matches the previous sampler view declaration (if there
211 * was one.)
212 */
213 if (info->sampler_targets[index] == TGSI_TEXTURE_UNKNOWN) {
214 /* probably no sampler view declaration */
215 info->sampler_targets[index] = target;
216 } else {
217 /* Make sure the texture instruction's sampler/target info
218 * agrees with the sampler view declaration.
219 */
220 assert(info->sampler_targets[index] == target);
221 }
222 /* MSAA samplers */
223 if (target == TGSI_TEXTURE_2D_MSAA ||
224 target == TGSI_TEXTURE_2D_ARRAY_MSAA) {
225 info->is_msaa_sampler[src->Register.Index] = TRUE;
226 }
227 }
228 }
229
230 if (is_memory_file(src->Register.File)) {
231 is_mem_inst = true;
232
233 if (tgsi_get_opcode_info(fullinst->Instruction.Opcode)->is_store) {
234 info->writes_memory = TRUE;
235
236 if (src->Register.File == TGSI_FILE_IMAGE &&
237 !src->Register.Indirect)
238 info->images_writemask |= 1 << src->Register.Index;
239 }
240 }
241 }
242
243 /* check for indirect register writes */
244 for (i = 0; i < fullinst->Instruction.NumDstRegs; i++) {
245 const struct tgsi_full_dst_register *dst = &fullinst->Dst[i];
246 if (dst->Register.Indirect) {
247 info->indirect_files |= (1 << dst->Register.File);
248 info->indirect_files_written |= (1 << dst->Register.File);
249 }
250
251 if (is_memory_file(dst->Register.File)) {
252 assert(fullinst->Instruction.Opcode == TGSI_OPCODE_STORE);
253
254 is_mem_inst = true;
255 info->writes_memory = TRUE;
256
257 if (dst->Register.File == TGSI_FILE_IMAGE &&
258 !dst->Register.Indirect)
259 info->images_writemask |= 1 << dst->Register.Index;
260 }
261 }
262
263 if (is_mem_inst)
264 info->num_memory_instructions++;
265
266 info->num_instructions++;
267 }
268
269
270 static void
271 scan_declaration(struct tgsi_shader_info *info,
272 const struct tgsi_full_declaration *fulldecl)
273 {
274 const uint file = fulldecl->Declaration.File;
275 const unsigned procType = info->processor;
276 uint reg;
277
278 if (fulldecl->Declaration.Array) {
279 unsigned array_id = fulldecl->Array.ArrayID;
280
281 switch (file) {
282 case TGSI_FILE_INPUT:
283 assert(array_id < ARRAY_SIZE(info->input_array_first));
284 info->input_array_first[array_id] = fulldecl->Range.First;
285 info->input_array_last[array_id] = fulldecl->Range.Last;
286 break;
287 case TGSI_FILE_OUTPUT:
288 assert(array_id < ARRAY_SIZE(info->output_array_first));
289 info->output_array_first[array_id] = fulldecl->Range.First;
290 info->output_array_last[array_id] = fulldecl->Range.Last;
291 break;
292 }
293 info->array_max[file] = MAX2(info->array_max[file], array_id);
294 }
295
296 for (reg = fulldecl->Range.First; reg <= fulldecl->Range.Last; reg++) {
297 unsigned semName = fulldecl->Semantic.Name;
298 unsigned semIndex = fulldecl->Semantic.Index +
299 (reg - fulldecl->Range.First);
300
301 /* only first 32 regs will appear in this bitfield */
302 info->file_mask[file] |= (1 << reg);
303 info->file_count[file]++;
304 info->file_max[file] = MAX2(info->file_max[file], (int)reg);
305
306 if (file == TGSI_FILE_CONSTANT) {
307 int buffer = 0;
308
309 if (fulldecl->Declaration.Dimension)
310 buffer = fulldecl->Dim.Index2D;
311
312 info->const_file_max[buffer] =
313 MAX2(info->const_file_max[buffer], (int)reg);
314 }
315 else if (file == TGSI_FILE_INPUT) {
316 info->input_semantic_name[reg] = (ubyte) semName;
317 info->input_semantic_index[reg] = (ubyte) semIndex;
318 info->input_interpolate[reg] = (ubyte)fulldecl->Interp.Interpolate;
319 info->input_interpolate_loc[reg] = (ubyte)fulldecl->Interp.Location;
320 info->input_cylindrical_wrap[reg] = (ubyte)fulldecl->Interp.CylindricalWrap;
321
322 /* Vertex shaders can have inputs with holes between them. */
323 if (info->processor == PIPE_SHADER_VERTEX)
324 info->num_inputs = MAX2(info->num_inputs, reg + 1);
325 else {
326 info->num_inputs++;
327 assert(reg < info->num_inputs);
328 }
329
330 /* Only interpolated varyings. Don't include POSITION.
331 * Don't include integer varyings, because they are not
332 * interpolated.
333 */
334 if (semName == TGSI_SEMANTIC_GENERIC ||
335 semName == TGSI_SEMANTIC_TEXCOORD ||
336 semName == TGSI_SEMANTIC_COLOR ||
337 semName == TGSI_SEMANTIC_BCOLOR ||
338 semName == TGSI_SEMANTIC_FOG ||
339 semName == TGSI_SEMANTIC_CLIPDIST) {
340 switch (fulldecl->Interp.Interpolate) {
341 case TGSI_INTERPOLATE_COLOR:
342 case TGSI_INTERPOLATE_PERSPECTIVE:
343 switch (fulldecl->Interp.Location) {
344 case TGSI_INTERPOLATE_LOC_CENTER:
345 info->uses_persp_center = TRUE;
346 break;
347 case TGSI_INTERPOLATE_LOC_CENTROID:
348 info->uses_persp_centroid = TRUE;
349 break;
350 case TGSI_INTERPOLATE_LOC_SAMPLE:
351 info->uses_persp_sample = TRUE;
352 break;
353 }
354 break;
355 case TGSI_INTERPOLATE_LINEAR:
356 switch (fulldecl->Interp.Location) {
357 case TGSI_INTERPOLATE_LOC_CENTER:
358 info->uses_linear_center = TRUE;
359 break;
360 case TGSI_INTERPOLATE_LOC_CENTROID:
361 info->uses_linear_centroid = TRUE;
362 break;
363 case TGSI_INTERPOLATE_LOC_SAMPLE:
364 info->uses_linear_sample = TRUE;
365 break;
366 }
367 break;
368 /* TGSI_INTERPOLATE_CONSTANT doesn't do any interpolation. */
369 }
370 }
371
372 if (semName == TGSI_SEMANTIC_PRIMID)
373 info->uses_primid = TRUE;
374 else if (procType == PIPE_SHADER_FRAGMENT) {
375 if (semName == TGSI_SEMANTIC_POSITION)
376 info->reads_position = TRUE;
377 else if (semName == TGSI_SEMANTIC_FACE)
378 info->uses_frontface = TRUE;
379 }
380 }
381 else if (file == TGSI_FILE_SYSTEM_VALUE) {
382 unsigned index = fulldecl->Range.First;
383
384 info->system_value_semantic_name[index] = semName;
385 info->num_system_values = MAX2(info->num_system_values, index + 1);
386
387 switch (semName) {
388 case TGSI_SEMANTIC_INSTANCEID:
389 info->uses_instanceid = TRUE;
390 break;
391 case TGSI_SEMANTIC_VERTEXID:
392 info->uses_vertexid = TRUE;
393 break;
394 case TGSI_SEMANTIC_VERTEXID_NOBASE:
395 info->uses_vertexid_nobase = TRUE;
396 break;
397 case TGSI_SEMANTIC_BASEVERTEX:
398 info->uses_basevertex = TRUE;
399 break;
400 case TGSI_SEMANTIC_PRIMID:
401 info->uses_primid = TRUE;
402 break;
403 case TGSI_SEMANTIC_INVOCATIONID:
404 info->uses_invocationid = TRUE;
405 break;
406 case TGSI_SEMANTIC_POSITION:
407 info->reads_position = TRUE;
408 break;
409 case TGSI_SEMANTIC_FACE:
410 info->uses_frontface = TRUE;
411 break;
412 case TGSI_SEMANTIC_SAMPLEMASK:
413 info->reads_samplemask = TRUE;
414 break;
415 }
416 }
417 else if (file == TGSI_FILE_OUTPUT) {
418 info->output_semantic_name[reg] = (ubyte) semName;
419 info->output_semantic_index[reg] = (ubyte) semIndex;
420 info->num_outputs++;
421 assert(reg < info->num_outputs);
422
423 if (semName == TGSI_SEMANTIC_COLOR)
424 info->colors_written |= 1 << semIndex;
425
426 if (procType == PIPE_SHADER_VERTEX ||
427 procType == PIPE_SHADER_GEOMETRY ||
428 procType == PIPE_SHADER_TESS_CTRL ||
429 procType == PIPE_SHADER_TESS_EVAL) {
430 switch (semName) {
431 case TGSI_SEMANTIC_VIEWPORT_INDEX:
432 info->writes_viewport_index = TRUE;
433 break;
434 case TGSI_SEMANTIC_LAYER:
435 info->writes_layer = TRUE;
436 break;
437 case TGSI_SEMANTIC_PSIZE:
438 info->writes_psize = TRUE;
439 break;
440 case TGSI_SEMANTIC_CLIPVERTEX:
441 info->writes_clipvertex = TRUE;
442 break;
443 }
444 }
445
446 if (procType == PIPE_SHADER_FRAGMENT) {
447 switch (semName) {
448 case TGSI_SEMANTIC_POSITION:
449 info->writes_z = TRUE;
450 break;
451 case TGSI_SEMANTIC_STENCIL:
452 info->writes_stencil = TRUE;
453 break;
454 case TGSI_SEMANTIC_SAMPLEMASK:
455 info->writes_samplemask = TRUE;
456 break;
457 }
458 }
459
460 if (procType == PIPE_SHADER_VERTEX) {
461 if (semName == TGSI_SEMANTIC_EDGEFLAG) {
462 info->writes_edgeflag = TRUE;
463 }
464 }
465 } else if (file == TGSI_FILE_SAMPLER) {
466 STATIC_ASSERT(sizeof(info->samplers_declared) * 8 >= PIPE_MAX_SAMPLERS);
467 info->samplers_declared |= 1u << reg;
468 } else if (file == TGSI_FILE_SAMPLER_VIEW) {
469 unsigned target = fulldecl->SamplerView.Resource;
470 assert(target < TGSI_TEXTURE_UNKNOWN);
471 if (info->sampler_targets[reg] == TGSI_TEXTURE_UNKNOWN) {
472 /* Save sampler target for this sampler index */
473 info->sampler_targets[reg] = target;
474 } else {
475 /* if previously declared, make sure targets agree */
476 assert(info->sampler_targets[reg] == target);
477 }
478 } else if (file == TGSI_FILE_IMAGE) {
479 if (fulldecl->Image.Resource == TGSI_TEXTURE_BUFFER)
480 info->images_buffers |= 1 << reg;
481 }
482 }
483 }
484
485
486 static void
487 scan_immediate(struct tgsi_shader_info *info)
488 {
489 uint reg = info->immediate_count++;
490 uint file = TGSI_FILE_IMMEDIATE;
491
492 info->file_mask[file] |= (1 << reg);
493 info->file_count[file]++;
494 info->file_max[file] = MAX2(info->file_max[file], (int)reg);
495 }
496
497
498 static void
499 scan_property(struct tgsi_shader_info *info,
500 const struct tgsi_full_property *fullprop)
501 {
502 unsigned name = fullprop->Property.PropertyName;
503 unsigned value = fullprop->u[0].Data;
504
505 assert(name < ARRAY_SIZE(info->properties));
506 info->properties[name] = value;
507
508 switch (name) {
509 case TGSI_PROPERTY_NUM_CLIPDIST_ENABLED:
510 info->num_written_clipdistance = value;
511 info->clipdist_writemask |= (1 << value) - 1;
512 break;
513 case TGSI_PROPERTY_NUM_CULLDIST_ENABLED:
514 info->num_written_culldistance = value;
515 info->culldist_writemask |= (1 << value) - 1;
516 break;
517 }
518 }
519
520
521 /**
522 * Scan the given TGSI shader to collect information such as number of
523 * registers used, special instructions used, etc.
524 * \return info the result of the scan
525 */
526 void
527 tgsi_scan_shader(const struct tgsi_token *tokens,
528 struct tgsi_shader_info *info)
529 {
530 uint procType, i;
531 struct tgsi_parse_context parse;
532 unsigned current_depth = 0;
533
534 memset(info, 0, sizeof(*info));
535 for (i = 0; i < TGSI_FILE_COUNT; i++)
536 info->file_max[i] = -1;
537 for (i = 0; i < ARRAY_SIZE(info->const_file_max); i++)
538 info->const_file_max[i] = -1;
539 info->properties[TGSI_PROPERTY_GS_INVOCATIONS] = 1;
540 for (i = 0; i < ARRAY_SIZE(info->sampler_targets); i++)
541 info->sampler_targets[i] = TGSI_TEXTURE_UNKNOWN;
542
543 /**
544 ** Setup to begin parsing input shader
545 **/
546 if (tgsi_parse_init( &parse, tokens ) != TGSI_PARSE_OK) {
547 debug_printf("tgsi_parse_init() failed in tgsi_scan_shader()!\n");
548 return;
549 }
550 procType = parse.FullHeader.Processor.Processor;
551 assert(procType == PIPE_SHADER_FRAGMENT ||
552 procType == PIPE_SHADER_VERTEX ||
553 procType == PIPE_SHADER_GEOMETRY ||
554 procType == PIPE_SHADER_TESS_CTRL ||
555 procType == PIPE_SHADER_TESS_EVAL ||
556 procType == PIPE_SHADER_COMPUTE);
557 info->processor = procType;
558
559 /**
560 ** Loop over incoming program tokens/instructions
561 */
562 while (!tgsi_parse_end_of_tokens(&parse)) {
563 info->num_tokens++;
564
565 tgsi_parse_token( &parse );
566
567 switch( parse.FullToken.Token.Type ) {
568 case TGSI_TOKEN_TYPE_INSTRUCTION:
569 scan_instruction(info, &parse.FullToken.FullInstruction,
570 &current_depth);
571 break;
572 case TGSI_TOKEN_TYPE_DECLARATION:
573 scan_declaration(info, &parse.FullToken.FullDeclaration);
574 break;
575 case TGSI_TOKEN_TYPE_IMMEDIATE:
576 scan_immediate(info);
577 break;
578 case TGSI_TOKEN_TYPE_PROPERTY:
579 scan_property(info, &parse.FullToken.FullProperty);
580 break;
581 default:
582 assert(!"Unexpected TGSI token type");
583 }
584 }
585
586 info->uses_kill = (info->opcode_count[TGSI_OPCODE_KILL_IF] ||
587 info->opcode_count[TGSI_OPCODE_KILL]);
588
589 /* The dimensions of the IN decleration in geometry shader have
590 * to be deduced from the type of the input primitive.
591 */
592 if (procType == PIPE_SHADER_GEOMETRY) {
593 unsigned input_primitive =
594 info->properties[TGSI_PROPERTY_GS_INPUT_PRIM];
595 int num_verts = u_vertices_per_prim(input_primitive);
596 int j;
597 info->file_count[TGSI_FILE_INPUT] = num_verts;
598 info->file_max[TGSI_FILE_INPUT] =
599 MAX2(info->file_max[TGSI_FILE_INPUT], num_verts - 1);
600 for (j = 0; j < num_verts; ++j) {
601 info->file_mask[TGSI_FILE_INPUT] |= (1 << j);
602 }
603 }
604
605 tgsi_parse_free(&parse);
606 }
607
608
609
610 /**
611 * Check if the given shader is a "passthrough" shader consisting of only
612 * MOV instructions of the form: MOV OUT[n], IN[n]
613 *
614 */
615 boolean
616 tgsi_is_passthrough_shader(const struct tgsi_token *tokens)
617 {
618 struct tgsi_parse_context parse;
619
620 /**
621 ** Setup to begin parsing input shader
622 **/
623 if (tgsi_parse_init(&parse, tokens) != TGSI_PARSE_OK) {
624 debug_printf("tgsi_parse_init() failed in tgsi_is_passthrough_shader()!\n");
625 return FALSE;
626 }
627
628 /**
629 ** Loop over incoming program tokens/instructions
630 */
631 while (!tgsi_parse_end_of_tokens(&parse)) {
632
633 tgsi_parse_token(&parse);
634
635 switch (parse.FullToken.Token.Type) {
636 case TGSI_TOKEN_TYPE_INSTRUCTION:
637 {
638 struct tgsi_full_instruction *fullinst =
639 &parse.FullToken.FullInstruction;
640 const struct tgsi_full_src_register *src =
641 &fullinst->Src[0];
642 const struct tgsi_full_dst_register *dst =
643 &fullinst->Dst[0];
644
645 /* Do a whole bunch of checks for a simple move */
646 if (fullinst->Instruction.Opcode != TGSI_OPCODE_MOV ||
647 (src->Register.File != TGSI_FILE_INPUT &&
648 src->Register.File != TGSI_FILE_SYSTEM_VALUE) ||
649 dst->Register.File != TGSI_FILE_OUTPUT ||
650 src->Register.Index != dst->Register.Index ||
651
652 src->Register.Negate ||
653 src->Register.Absolute ||
654
655 src->Register.SwizzleX != TGSI_SWIZZLE_X ||
656 src->Register.SwizzleY != TGSI_SWIZZLE_Y ||
657 src->Register.SwizzleZ != TGSI_SWIZZLE_Z ||
658 src->Register.SwizzleW != TGSI_SWIZZLE_W ||
659
660 dst->Register.WriteMask != TGSI_WRITEMASK_XYZW)
661 {
662 tgsi_parse_free(&parse);
663 return FALSE;
664 }
665 }
666 break;
667
668 case TGSI_TOKEN_TYPE_DECLARATION:
669 /* fall-through */
670 case TGSI_TOKEN_TYPE_IMMEDIATE:
671 /* fall-through */
672 case TGSI_TOKEN_TYPE_PROPERTY:
673 /* fall-through */
674 default:
675 ; /* no-op */
676 }
677 }
678
679 tgsi_parse_free(&parse);
680
681 /* if we get here, it's a pass-through shader */
682 return TRUE;
683 }