e07148d6783736418f6988492906bda19edadcfe
[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 semName == TGSI_SEMANTIC_CULLDIST) {
341 switch (fulldecl->Interp.Interpolate) {
342 case TGSI_INTERPOLATE_COLOR:
343 case TGSI_INTERPOLATE_PERSPECTIVE:
344 switch (fulldecl->Interp.Location) {
345 case TGSI_INTERPOLATE_LOC_CENTER:
346 info->uses_persp_center = TRUE;
347 break;
348 case TGSI_INTERPOLATE_LOC_CENTROID:
349 info->uses_persp_centroid = TRUE;
350 break;
351 case TGSI_INTERPOLATE_LOC_SAMPLE:
352 info->uses_persp_sample = TRUE;
353 break;
354 }
355 break;
356 case TGSI_INTERPOLATE_LINEAR:
357 switch (fulldecl->Interp.Location) {
358 case TGSI_INTERPOLATE_LOC_CENTER:
359 info->uses_linear_center = TRUE;
360 break;
361 case TGSI_INTERPOLATE_LOC_CENTROID:
362 info->uses_linear_centroid = TRUE;
363 break;
364 case TGSI_INTERPOLATE_LOC_SAMPLE:
365 info->uses_linear_sample = TRUE;
366 break;
367 }
368 break;
369 /* TGSI_INTERPOLATE_CONSTANT doesn't do any interpolation. */
370 }
371 }
372
373 if (semName == TGSI_SEMANTIC_PRIMID)
374 info->uses_primid = TRUE;
375 else if (procType == PIPE_SHADER_FRAGMENT) {
376 if (semName == TGSI_SEMANTIC_POSITION)
377 info->reads_position = TRUE;
378 else if (semName == TGSI_SEMANTIC_FACE)
379 info->uses_frontface = TRUE;
380 }
381 }
382 else if (file == TGSI_FILE_SYSTEM_VALUE) {
383 unsigned index = fulldecl->Range.First;
384
385 info->system_value_semantic_name[index] = semName;
386 info->num_system_values = MAX2(info->num_system_values, index + 1);
387
388 switch (semName) {
389 case TGSI_SEMANTIC_INSTANCEID:
390 info->uses_instanceid = TRUE;
391 break;
392 case TGSI_SEMANTIC_VERTEXID:
393 info->uses_vertexid = TRUE;
394 break;
395 case TGSI_SEMANTIC_VERTEXID_NOBASE:
396 info->uses_vertexid_nobase = TRUE;
397 break;
398 case TGSI_SEMANTIC_BASEVERTEX:
399 info->uses_basevertex = TRUE;
400 break;
401 case TGSI_SEMANTIC_PRIMID:
402 info->uses_primid = TRUE;
403 break;
404 case TGSI_SEMANTIC_INVOCATIONID:
405 info->uses_invocationid = TRUE;
406 break;
407 case TGSI_SEMANTIC_POSITION:
408 info->reads_position = TRUE;
409 break;
410 case TGSI_SEMANTIC_FACE:
411 info->uses_frontface = TRUE;
412 break;
413 case TGSI_SEMANTIC_SAMPLEMASK:
414 info->reads_samplemask = TRUE;
415 break;
416 }
417 }
418 else if (file == TGSI_FILE_OUTPUT) {
419 info->output_semantic_name[reg] = (ubyte) semName;
420 info->output_semantic_index[reg] = (ubyte) semIndex;
421 info->num_outputs++;
422 assert(reg < info->num_outputs);
423
424 if (semName == TGSI_SEMANTIC_COLOR)
425 info->colors_written |= 1 << semIndex;
426
427 if (procType == PIPE_SHADER_VERTEX ||
428 procType == PIPE_SHADER_GEOMETRY ||
429 procType == PIPE_SHADER_TESS_CTRL ||
430 procType == PIPE_SHADER_TESS_EVAL) {
431 switch (semName) {
432 case TGSI_SEMANTIC_VIEWPORT_INDEX:
433 info->writes_viewport_index = TRUE;
434 break;
435 case TGSI_SEMANTIC_LAYER:
436 info->writes_layer = TRUE;
437 break;
438 case TGSI_SEMANTIC_PSIZE:
439 info->writes_psize = TRUE;
440 break;
441 case TGSI_SEMANTIC_CLIPVERTEX:
442 info->writes_clipvertex = TRUE;
443 break;
444 }
445 }
446
447 if (procType == PIPE_SHADER_FRAGMENT) {
448 switch (semName) {
449 case TGSI_SEMANTIC_POSITION:
450 info->writes_z = TRUE;
451 break;
452 case TGSI_SEMANTIC_STENCIL:
453 info->writes_stencil = TRUE;
454 break;
455 case TGSI_SEMANTIC_SAMPLEMASK:
456 info->writes_samplemask = TRUE;
457 break;
458 }
459 }
460
461 if (procType == PIPE_SHADER_VERTEX) {
462 if (semName == TGSI_SEMANTIC_EDGEFLAG) {
463 info->writes_edgeflag = TRUE;
464 }
465 }
466 } else if (file == TGSI_FILE_SAMPLER) {
467 STATIC_ASSERT(sizeof(info->samplers_declared) * 8 >= PIPE_MAX_SAMPLERS);
468 info->samplers_declared |= 1u << reg;
469 } else if (file == TGSI_FILE_SAMPLER_VIEW) {
470 unsigned target = fulldecl->SamplerView.Resource;
471 assert(target < TGSI_TEXTURE_UNKNOWN);
472 if (info->sampler_targets[reg] == TGSI_TEXTURE_UNKNOWN) {
473 /* Save sampler target for this sampler index */
474 info->sampler_targets[reg] = target;
475 } else {
476 /* if previously declared, make sure targets agree */
477 assert(info->sampler_targets[reg] == target);
478 }
479 } else if (file == TGSI_FILE_IMAGE) {
480 if (fulldecl->Image.Resource == TGSI_TEXTURE_BUFFER)
481 info->images_buffers |= 1 << reg;
482 }
483 }
484 }
485
486
487 static void
488 scan_immediate(struct tgsi_shader_info *info)
489 {
490 uint reg = info->immediate_count++;
491 uint file = TGSI_FILE_IMMEDIATE;
492
493 info->file_mask[file] |= (1 << reg);
494 info->file_count[file]++;
495 info->file_max[file] = MAX2(info->file_max[file], (int)reg);
496 }
497
498
499 static void
500 scan_property(struct tgsi_shader_info *info,
501 const struct tgsi_full_property *fullprop)
502 {
503 unsigned name = fullprop->Property.PropertyName;
504 unsigned value = fullprop->u[0].Data;
505
506 assert(name < ARRAY_SIZE(info->properties));
507 info->properties[name] = value;
508
509 switch (name) {
510 case TGSI_PROPERTY_NUM_CLIPDIST_ENABLED:
511 info->num_written_clipdistance = value;
512 info->clipdist_writemask |= (1 << value) - 1;
513 break;
514 case TGSI_PROPERTY_NUM_CULLDIST_ENABLED:
515 info->num_written_culldistance = value;
516 info->culldist_writemask |= (1 << value) - 1;
517 break;
518 }
519 }
520
521
522 /**
523 * Scan the given TGSI shader to collect information such as number of
524 * registers used, special instructions used, etc.
525 * \return info the result of the scan
526 */
527 void
528 tgsi_scan_shader(const struct tgsi_token *tokens,
529 struct tgsi_shader_info *info)
530 {
531 uint procType, i;
532 struct tgsi_parse_context parse;
533 unsigned current_depth = 0;
534
535 memset(info, 0, sizeof(*info));
536 for (i = 0; i < TGSI_FILE_COUNT; i++)
537 info->file_max[i] = -1;
538 for (i = 0; i < ARRAY_SIZE(info->const_file_max); i++)
539 info->const_file_max[i] = -1;
540 info->properties[TGSI_PROPERTY_GS_INVOCATIONS] = 1;
541 for (i = 0; i < ARRAY_SIZE(info->sampler_targets); i++)
542 info->sampler_targets[i] = TGSI_TEXTURE_UNKNOWN;
543
544 /**
545 ** Setup to begin parsing input shader
546 **/
547 if (tgsi_parse_init( &parse, tokens ) != TGSI_PARSE_OK) {
548 debug_printf("tgsi_parse_init() failed in tgsi_scan_shader()!\n");
549 return;
550 }
551 procType = parse.FullHeader.Processor.Processor;
552 assert(procType == PIPE_SHADER_FRAGMENT ||
553 procType == PIPE_SHADER_VERTEX ||
554 procType == PIPE_SHADER_GEOMETRY ||
555 procType == PIPE_SHADER_TESS_CTRL ||
556 procType == PIPE_SHADER_TESS_EVAL ||
557 procType == PIPE_SHADER_COMPUTE);
558 info->processor = procType;
559
560 /**
561 ** Loop over incoming program tokens/instructions
562 */
563 while (!tgsi_parse_end_of_tokens(&parse)) {
564 info->num_tokens++;
565
566 tgsi_parse_token( &parse );
567
568 switch( parse.FullToken.Token.Type ) {
569 case TGSI_TOKEN_TYPE_INSTRUCTION:
570 scan_instruction(info, &parse.FullToken.FullInstruction,
571 &current_depth);
572 break;
573 case TGSI_TOKEN_TYPE_DECLARATION:
574 scan_declaration(info, &parse.FullToken.FullDeclaration);
575 break;
576 case TGSI_TOKEN_TYPE_IMMEDIATE:
577 scan_immediate(info);
578 break;
579 case TGSI_TOKEN_TYPE_PROPERTY:
580 scan_property(info, &parse.FullToken.FullProperty);
581 break;
582 default:
583 assert(!"Unexpected TGSI token type");
584 }
585 }
586
587 info->uses_kill = (info->opcode_count[TGSI_OPCODE_KILL_IF] ||
588 info->opcode_count[TGSI_OPCODE_KILL]);
589
590 /* The dimensions of the IN decleration in geometry shader have
591 * to be deduced from the type of the input primitive.
592 */
593 if (procType == PIPE_SHADER_GEOMETRY) {
594 unsigned input_primitive =
595 info->properties[TGSI_PROPERTY_GS_INPUT_PRIM];
596 int num_verts = u_vertices_per_prim(input_primitive);
597 int j;
598 info->file_count[TGSI_FILE_INPUT] = num_verts;
599 info->file_max[TGSI_FILE_INPUT] =
600 MAX2(info->file_max[TGSI_FILE_INPUT], num_verts - 1);
601 for (j = 0; j < num_verts; ++j) {
602 info->file_mask[TGSI_FILE_INPUT] |= (1 << j);
603 }
604 }
605
606 tgsi_parse_free(&parse);
607 }
608
609
610
611 /**
612 * Check if the given shader is a "passthrough" shader consisting of only
613 * MOV instructions of the form: MOV OUT[n], IN[n]
614 *
615 */
616 boolean
617 tgsi_is_passthrough_shader(const struct tgsi_token *tokens)
618 {
619 struct tgsi_parse_context parse;
620
621 /**
622 ** Setup to begin parsing input shader
623 **/
624 if (tgsi_parse_init(&parse, tokens) != TGSI_PARSE_OK) {
625 debug_printf("tgsi_parse_init() failed in tgsi_is_passthrough_shader()!\n");
626 return FALSE;
627 }
628
629 /**
630 ** Loop over incoming program tokens/instructions
631 */
632 while (!tgsi_parse_end_of_tokens(&parse)) {
633
634 tgsi_parse_token(&parse);
635
636 switch (parse.FullToken.Token.Type) {
637 case TGSI_TOKEN_TYPE_INSTRUCTION:
638 {
639 struct tgsi_full_instruction *fullinst =
640 &parse.FullToken.FullInstruction;
641 const struct tgsi_full_src_register *src =
642 &fullinst->Src[0];
643 const struct tgsi_full_dst_register *dst =
644 &fullinst->Dst[0];
645
646 /* Do a whole bunch of checks for a simple move */
647 if (fullinst->Instruction.Opcode != TGSI_OPCODE_MOV ||
648 (src->Register.File != TGSI_FILE_INPUT &&
649 src->Register.File != TGSI_FILE_SYSTEM_VALUE) ||
650 dst->Register.File != TGSI_FILE_OUTPUT ||
651 src->Register.Index != dst->Register.Index ||
652
653 src->Register.Negate ||
654 src->Register.Absolute ||
655
656 src->Register.SwizzleX != TGSI_SWIZZLE_X ||
657 src->Register.SwizzleY != TGSI_SWIZZLE_Y ||
658 src->Register.SwizzleZ != TGSI_SWIZZLE_Z ||
659 src->Register.SwizzleW != TGSI_SWIZZLE_W ||
660
661 dst->Register.WriteMask != TGSI_WRITEMASK_XYZW)
662 {
663 tgsi_parse_free(&parse);
664 return FALSE;
665 }
666 }
667 break;
668
669 case TGSI_TOKEN_TYPE_DECLARATION:
670 /* fall-through */
671 case TGSI_TOKEN_TYPE_IMMEDIATE:
672 /* fall-through */
673 case TGSI_TOKEN_TYPE_PROPERTY:
674 /* fall-through */
675 default:
676 ; /* no-op */
677 }
678 }
679
680 tgsi_parse_free(&parse);
681
682 /* if we get here, it's a pass-through shader */
683 return TRUE;
684 }