2 * Copyright (c) 2012 Rob Clark <robdclark@gmail.com>
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 #include <sys/types.h>
37 #define ASCII_XOR 0xff
51 uint32_t num_uniforms
;
52 uint32_t num_samplers
;
53 uint32_t num_varyings
;
54 uint32_t num_uniformblocks
;
58 uint32_t unknown1
; /* seems to be # of sections up to and including shader */
59 uint32_t unknown2
; /* seems to be low byte or so of SQ_PROGRAM_CNTL */
66 uint32_t unknown9
; /* seems to be # of sections following shader */
73 // Covers a lot of type_info
74 // varying, attribute, uniform, sampler
76 if ((type_info >> 8) == 0x8b) // vector
83 0x56 = bool // Why is this in vector?
90 0x5a = mat2x2 // Same as mat2
94 0x5b = mat3x3 // Same as mat3
98 0x5c = mat4x4 // same as mat4
101 0x60 = samplerCube // XXX: Doesn't work
102 0x62 = sampler2DShadow
106 else if ((type_info >> 8) == 0x8d) // GLES3 samplers
107 0xC1 = sampler2DArray
108 0xC4 = sampler2DArrayShadow
109 0xC5 = samplerCubeShadow
116 0xD7 = isampler2DArray
117 0xD7 = usampler2DArray // Is the same as isampler2DArray?
118 else // 0x14 = single
125 uint32_t reg
; /* seems to be the register the fetch instruction loads to */
126 uint32_t const_idx
; /* the CONST() indx value for sampler */
139 uint32_t const_base
; /* const base register (for uniforms that take more than one const reg, ie. matrices) */
141 uint32_t const_reg
; /* the const register holding the value */
158 struct uniformblockmember
{
161 uint32_t array_size
; /* elements in the array */
162 uint32_t unknown2
; /* Same as array_size */
163 uint32_t unknown3
; /* Seems to be a offset within UBO in vertex (by components) */
165 uint32_t unknown5
; /* Seems to be a offset within UBO in fragment (by vec4) */
169 uint32_t unknown9
; /* UBO block index? */
183 uint32_t num_members
;
184 uint32_t num_members2
;
195 uint32_t array_size
; /* elements in the array */
196 uint32_t unknown4
; /* same as array_size */
199 uint32_t const_idx
; /* the CONST() indx value for the sampler */
208 uint32_t reg
; /* the register holding the value (on entry to the shader) */
235 struct pgm_header
*hdr
;
236 struct attribute
*attribs
[32]; /* don't really know the upper limit.. */
237 struct uniform
*uniforms
[32];
238 struct sampler
*samplers
[32];
239 struct varying
*varyings
[32];
241 struct uniformblock
*header
;
242 struct uniformblockmember
**members
; /* GL ES 3.0 spec mandates minimum 16K support. a3xx supports 65K */
243 } uniformblocks
[24]; /* Maximum a330 supports */
244 struct output
*outputs
[0]; /* I guess only one?? */
247 static const char *infile
;
248 static int full_dump
= 1;
249 static int dump_shaders
= 0;
252 static char *find_sect_end(char *buf
, int sz
)
254 uint8_t *ptr
= (uint8_t *)buf
;
255 uint8_t *end
= ptr
+ sz
- 3;
265 /* someone at QC likes baseball */
274 static void *next_sect(struct state
*state
, int *sect_size
)
276 char *end
= find_sect_end(state
->buf
, state
->sz
);
282 *sect_size
= end
- state
->buf
;
284 /* copy the section to keep things nicely 32b aligned: */
285 sect
= malloc(ALIGN(*sect_size
, 4));
286 memcpy(sect
, state
->buf
, *sect_size
);
288 state
->sz
-= *sect_size
+ 4;
289 state
->buf
= end
+ 4;
294 static int valid_type(uint32_t type_info
)
296 switch ((type_info
>> 8) & 0xff) {
297 case 0x8b: /* vector */
298 case 0x8d: /* GLES3 samplers */
299 case 0x14: /* float */
307 static int valid_uniformblock(uint32_t type_info
)
309 if (type_info
== 0x128)
315 static void dump_attribute(struct attribute
*attrib
)
317 printf("\tR%d, CONST(%d): %s\n", attrib
->reg
,
318 attrib
->const_idx
, attrib
->name
);
321 static inline int is_uniform_v2(struct uniform
*uniform
)
323 /* TODO maybe this should be based on revision #? */
324 if (uniform
->v2
.unknown10
== 0)
329 static void dump_uniform(struct uniform
*uniform
)
331 char *name
= is_uniform_v2(uniform
) ? uniform
->v2
.name
: uniform
->v1
.name
;
332 if (uniform
->const_reg
== -1) {
333 printf("\tC%d+: %s\n", uniform
->const_base
, name
);
335 printf("\tC%d: %s\n", uniform
->const_reg
, name
);
339 static void dump_sampler(struct sampler
*sampler
)
341 printf("\tCONST(%d): %s\n", sampler
->const_idx
, sampler
->name
);
344 static void dump_varying(struct varying
*varying
)
346 printf("\tR%d: %s\n", varying
->reg
, varying
->name
);
349 static void dump_uniformblock(struct uniformblock
*uniformblock
)
351 printf("\tUniform Block: %s(%d)\n", uniformblock
->name
, uniformblock
->num_members
);
354 static void dump_uniformblockmember(struct uniformblockmember
*member
)
356 printf("Uniform Block member: %s\n", member
->name
);
359 static void dump_output(struct output
*output
)
361 printf("\tR?: %s\n", output
->name
);
364 static void dump_constant(struct constant
*constant
)
366 printf("\tC%d: %f, %f, %f, %f\n", constant
->const_idx
,
367 constant
->val
[0], constant
->val
[1],
368 constant
->val
[2], constant
->val
[3]);
371 /* dump attr/uniform/sampler/varying/const summary: */
372 static void dump_short_summary(struct state
*state
, int nconsts
,
373 struct constant
**constants
)
377 /* dump attr/uniform/sampler/varying/const summary: */
378 for (i
= 0; i
< state
->hdr
->num_varyings
; i
++) {
379 dump_varying(state
->varyings
[i
]);
381 for (i
= 0; i
< state
->hdr
->num_attribs
; i
++) {
382 dump_attribute(state
->attribs
[i
]);
384 for (i
= 0; i
< state
->hdr
->num_uniforms
; i
++) {
385 dump_uniform(state
->uniforms
[i
]);
387 for (i
= 0; i
< state
->hdr
->num_samplers
; i
++) {
388 dump_sampler(state
->samplers
[i
]);
390 for (i
= 0; i
< nconsts
- 1; i
++) {
391 if (constants
[i
]->unknown2
== 0) {
392 dump_constant(constants
[i
]);
398 static void dump_raw_shader(uint32_t *dwords
, uint32_t sizedwords
, int n
, char *ext
)
400 static char filename
[256];
406 sprintf(filename
, "%.*s-%d.%s", (int)strlen(infile
)-3, infile
, n
, ext
);
407 fd
= open(filename
, O_WRONLY
| O_TRUNC
| O_CREAT
, 0644);
408 write(fd
, dwords
, sizedwords
* 4);
411 static void dump_shaders_a2xx(struct state
*state
)
416 /* dump vertex shaders: */
417 for (i
= 0; i
< 3; i
++) {
418 struct vs_header
*vs_hdr
= next_sect(state
, §_size
);
419 struct constant
*constants
[32];
425 printf("#######################################################\n");
426 printf("######## VS%d HEADER: (size %d)\n", i
, sect_size
);
427 dump_hex((void *)vs_hdr
, sect_size
);
430 for (j
= 0; j
< (int)vs_hdr
->unknown1
- 1; j
++) {
431 constants
[j
] = next_sect(state
, §_size
);
433 printf("######## VS%d CONST: (size=%d)\n", i
, sect_size
);
434 dump_constant(constants
[j
]);
435 dump_hex((char *)constants
[j
], sect_size
);
439 ptr
= next_sect(state
, §_size
);
440 printf("######## VS%d SHADER: (size=%d)\n", i
, sect_size
);
442 dump_hex(ptr
, sect_size
);
445 dump_short_summary(state
, vs_hdr
->unknown1
- 1, constants
);
447 disasm_a2xx((uint32_t *)(ptr
+ 32), (sect_size
- 32) / 4, level
+1, MESA_SHADER_VERTEX
);
448 dump_raw_shader((uint32_t *)(ptr
+ 32), (sect_size
- 32) / 4, i
, "vo");
451 for (j
= 0; j
< vs_hdr
->unknown9
; j
++) {
452 ptr
= next_sect(state
, §_size
);
454 printf("######## VS%d CONST?: (size=%d)\n", i
, sect_size
);
455 dump_hex(ptr
, sect_size
);
460 for (j
= 0; j
< vs_hdr
->unknown1
- 1; j
++) {
467 /* dump fragment shaders: */
468 for (i
= 0; i
< 1; i
++) {
469 struct fs_header
*fs_hdr
= next_sect(state
, §_size
);
470 struct constant
*constants
[32];
476 printf("#######################################################\n");
477 printf("######## FS%d HEADER: (size %d)\n", i
, sect_size
);
478 dump_hex((void *)fs_hdr
, sect_size
);
481 for (j
= 0; j
< fs_hdr
->unknown1
- 1; j
++) {
482 constants
[j
] = next_sect(state
, §_size
);
484 printf("######## FS%d CONST: (size=%d)\n", i
, sect_size
);
485 dump_constant(constants
[j
]);
486 dump_hex((char *)constants
[j
], sect_size
);
490 ptr
= next_sect(state
, §_size
);
491 printf("######## FS%d SHADER: (size=%d)\n", i
, sect_size
);
493 dump_hex(ptr
, sect_size
);
496 dump_short_summary(state
, fs_hdr
->unknown1
- 1, constants
);
498 disasm_a2xx((uint32_t *)(ptr
+ 32), (sect_size
- 32) / 4, level
+1, MESA_SHADER_FRAGMENT
);
499 dump_raw_shader((uint32_t *)(ptr
+ 32), (sect_size
- 32) / 4, i
, "fo");
502 for (j
= 0; j
< fs_hdr
->unknown1
- 1; j
++) {
510 static void dump_shaders_a3xx(struct state
*state
)
514 /* dump vertex shaders: */
515 for (i
= 0; i
< 2; i
++) {
516 int instrs_size
, hdr_size
, sect_size
, nconsts
= 0, level
= 0, compact
= 0;
518 struct constant
*constants
[32];
519 uint8_t *instrs
= NULL
;
521 vs_hdr
= next_sect(state
, &hdr_size
);
522 printf("hdr_size=%d\n", hdr_size
);
524 /* seems like there are two cases, either:
525 * 1) 152 byte header,
526 * 2) zero or more 32 byte compiler const sections
527 * 3) followed by shader instructions
528 * or, if there are no compiler consts, this can be
529 * all smashed in one large section
532 if (state
->hdr
->revision
>= 0xb)
534 else if (state
->hdr
->revision
>= 7)
540 instrs_size
= hdr_size
- n
;
545 void *ptr
= next_sect(state
, §_size
);
547 if ((sect_size
!= 32) && (sect_size
!= 44)) {
548 /* end of constants: */
550 instrs_size
= sect_size
;
553 dump_hex_ascii(ptr
, sect_size
, 0);
554 constants
[nconsts
++] = ptr
;
561 printf("#######################################################\n");
562 printf("######## VS%d HEADER: (size %d)\n", i
, hdr_size
);
563 dump_hex((void *)vs_hdr
, hdr_size
);
564 for (j
= 0; j
< nconsts
; j
++) {
565 printf("######## VS%d CONST: (size=%d)\n", i
, (int)sizeof(constants
[i
]));
566 dump_constant(constants
[j
]);
567 dump_hex((char *)constants
[j
], sizeof(constants
[j
]));
571 printf("######## VS%d SHADER: (size=%d)\n", i
, instrs_size
);
573 dump_hex(instrs
, instrs_size
);
576 dump_short_summary(state
, nconsts
, constants
);
580 if (state
->hdr
->revision
>= 7) {
581 instrs
+= ALIGN(instrs_size
, 8) - instrs_size
;
582 instrs_size
= ALIGN(instrs_size
, 8);
588 disasm_a3xx((uint32_t *)instrs
, instrs_size
/ 4, level
+1, stdout
, gpu_id
);
589 dump_raw_shader((uint32_t *)instrs
, instrs_size
/ 4, i
, "vo3");
593 /* dump fragment shaders: */
594 for (i
= 0; i
< 1; i
++) {
595 int instrs_size
, hdr_size
, sect_size
, nconsts
= 0, level
= 0, compact
= 0;
597 struct constant
*constants
[32];
598 uint8_t *instrs
= NULL
;
600 fs_hdr
= next_sect(state
, &hdr_size
);
602 printf("hdr_size=%d\n", hdr_size
);
603 /* two cases, similar to vertex shader, but magic # is 200
604 * (or 208 for newer?)..
607 if (state
->hdr
->revision
>= 0xb)
609 else if (state
->hdr
->revision
>= 8)
611 else if (state
->hdr
->revision
== 7)
618 instrs_size
= hdr_size
- n
;
623 void *ptr
= next_sect(state
, §_size
);
625 if ((sect_size
!= 32) && (sect_size
!= 44)) {
626 /* end of constants: */
628 instrs_size
= sect_size
;
632 dump_hex_ascii(ptr
, sect_size
, 0);
633 constants
[nconsts
++] = ptr
;
640 printf("#######################################################\n");
641 printf("######## FS%d HEADER: (size %d)\n", i
, hdr_size
);
642 dump_hex((void *)fs_hdr
, hdr_size
);
643 for (j
= 0; j
< nconsts
; j
++) {
644 printf("######## FS%d CONST: (size=%d)\n", i
, (int)sizeof(constants
[i
]));
645 dump_constant(constants
[j
]);
646 dump_hex((char *)constants
[j
], sizeof(constants
[j
]));
650 printf("######## FS%d SHADER: (size=%d)\n", i
, instrs_size
);
652 dump_hex(instrs
, instrs_size
);
655 dump_short_summary(state
, nconsts
, constants
);
659 if (state
->hdr
->revision
>= 7) {
667 disasm_a3xx((uint32_t *)instrs
, instrs_size
/ 4, level
+1, stdout
, gpu_id
);
668 dump_raw_shader((uint32_t *)instrs
, instrs_size
/ 4, i
, "fo3");
673 static void dump_program(struct state
*state
)
678 state
->hdr
= next_sect(state
, §_size
);
680 printf("######## HEADER: (size %d)\n", sect_size
);
681 printf("\tsize: %d\n", state
->hdr
->size
);
682 printf("\trevision: %d\n", state
->hdr
->revision
);
683 printf("\tattributes: %d\n", state
->hdr
->num_attribs
);
684 printf("\tuniforms: %d\n", state
->hdr
->num_uniforms
);
685 printf("\tsamplers: %d\n", state
->hdr
->num_samplers
);
686 printf("\tvaryings: %d\n", state
->hdr
->num_varyings
);
687 printf("\tuniform blocks: %d\n", state
->hdr
->num_uniformblocks
);
689 dump_hex((void *)state
->hdr
, sect_size
);
692 /* there seems to be two 0xba5eba11's at the end of the header, possibly
693 * with some other stuff between them:
695 ptr
= next_sect(state
, §_size
);
697 dump_hex_ascii(ptr
, sect_size
, 0);
700 for (i
= 0; (i
< state
->hdr
->num_attribs
) && (state
->sz
> 0); i
++) {
701 state
->attribs
[i
] = next_sect(state
, §_size
);
703 /* hmm, for a3xx (or maybe just newer driver version), we have some
704 * extra sections that don't seem useful, so skip these:
706 while (!valid_type(state
->attribs
[i
]->type_info
)) {
707 dump_hex_ascii(state
->attribs
[i
], sect_size
, 0);
708 state
->attribs
[i
] = next_sect(state
, §_size
);
711 clean_ascii(state
->attribs
[i
]->name
, sect_size
- 28);
713 printf("######## ATTRIBUTE: (size %d)\n", sect_size
);
714 dump_attribute(state
->attribs
[i
]);
715 dump_hex((char *)state
->attribs
[i
], sect_size
);
719 for (i
= 0; (i
< state
->hdr
->num_uniforms
) && (state
->sz
> 0); i
++) {
720 state
->uniforms
[i
] = next_sect(state
, §_size
);
722 /* hmm, for a3xx (or maybe just newer driver version), we have some
723 * extra sections that don't seem useful, so skip these:
725 while (!valid_type(state
->uniforms
[i
]->type_info
)) {
726 dump_hex_ascii(state
->uniforms
[i
], sect_size
, 0);
727 state
->uniforms
[i
] = next_sect(state
, §_size
);
730 if (is_uniform_v2(state
->uniforms
[i
])) {
731 clean_ascii(state
->uniforms
[i
]->v2
.name
, sect_size
- 53);
733 clean_ascii(state
->uniforms
[i
]->v1
.name
, sect_size
- 41);
737 printf("######## UNIFORM: (size %d)\n", sect_size
);
738 dump_uniform(state
->uniforms
[i
]);
739 dump_hex((char *)state
->uniforms
[i
], sect_size
);
743 for (i
= 0; (i
< state
->hdr
->num_samplers
) && (state
->sz
> 0); i
++) {
744 state
->samplers
[i
] = next_sect(state
, §_size
);
746 /* hmm, for a3xx (or maybe just newer driver version), we have some
747 * extra sections that don't seem useful, so skip these:
749 while (!valid_type(state
->samplers
[i
]->type_info
)) {
750 dump_hex_ascii(state
->samplers
[i
], sect_size
, 0);
751 state
->samplers
[i
] = next_sect(state
, §_size
);
754 clean_ascii(state
->samplers
[i
]->name
, sect_size
- 33);
756 printf("######## SAMPLER: (size %d)\n", sect_size
);
757 dump_sampler(state
->samplers
[i
]);
758 dump_hex((char *)state
->samplers
[i
], sect_size
);
763 // These sections show up after all of the other sampler sections
764 // Loops through them all since we don't deal with them
765 if (state
->hdr
->revision
>= 7) {
766 for (i
= 0; (i
< state
->hdr
->num_samplers
) && (state
->sz
> 0); i
++) {
767 ptr
= next_sect(state
, §_size
);
768 dump_hex_ascii(ptr
, sect_size
, 0);
773 for (i
= 0; (i
< state
->hdr
->num_varyings
) && (state
->sz
> 0); i
++) {
774 state
->varyings
[i
] = next_sect(state
, §_size
);
776 /* hmm, for a3xx (or maybe just newer driver version), we have some
777 * extra sections that don't seem useful, so skip these:
779 while (!valid_type(state
->varyings
[i
]->type_info
)) {
780 dump_hex_ascii(state
->varyings
[i
], sect_size
, 0);
781 state
->varyings
[i
] = next_sect(state
, §_size
);
784 clean_ascii(state
->varyings
[i
]->name
, sect_size
- 16);
786 printf("######## VARYING: (size %d)\n", sect_size
);
787 dump_varying(state
->varyings
[i
]);
788 dump_hex((char *)state
->varyings
[i
], sect_size
);
792 /* show up again for revision >= 14?? */
793 if (state
->hdr
->revision
>= 14) {
794 for (i
= 0; (i
< state
->hdr
->num_varyings
) && (state
->sz
> 0); i
++) {
795 ptr
= next_sect(state
, §_size
);
796 dump_hex_ascii(ptr
, sect_size
, 0);
800 /* not sure exactly which revision started this, but seems at least
801 * rev7 and rev8 implicitly include a new section for gl_FragColor:
803 if (state
->hdr
->revision
>= 7) {
804 /* I guess only one? */
805 state
->outputs
[0] = next_sect(state
, §_size
);
807 clean_ascii(state
->outputs
[0]->name
, sect_size
- 32);
809 printf("######## OUTPUT: (size %d)\n", sect_size
);
810 dump_output(state
->outputs
[0]);
811 dump_hex((char *)state
->outputs
[0], sect_size
);
815 for (i
= 0; (i
< state
->hdr
->num_uniformblocks
) && (state
->sz
> 0); i
++) {
816 state
->uniformblocks
[i
].header
= next_sect(state
, §_size
);
818 clean_ascii(state
->uniformblocks
[i
].header
->name
, sect_size
- 40);
820 printf("######## UNIFORM BLOCK: (size %d)\n", sect_size
);
821 dump_uniformblock(state
->uniformblocks
[i
].header
);
822 dump_hex((char *)state
->uniformblocks
[i
].header
, sect_size
);
826 * OpenGL ES 3.0 spec mandates a minimum amount of 16K members supported
827 * a330 supports a minimum of 65K
829 state
->uniformblocks
[i
].members
= malloc(state
->uniformblocks
[i
].header
->num_members
* sizeof(void*));
832 for (member
= 0; (member
< state
->uniformblocks
[i
].header
->num_members
) && (state
->sz
> 0); member
++) {
833 state
->uniformblocks
[i
].members
[member
] = next_sect(state
, §_size
);
835 clean_ascii(state
->uniformblocks
[i
].members
[member
]->name
, sect_size
- 56);
837 printf("######## UNIFORM BLOCK MEMBER: (size %d)\n", sect_size
);
838 dump_uniformblockmember(state
->uniformblocks
[i
].members
[member
]);
839 dump_hex((char *)state
->uniformblocks
[i
].members
[member
], sect_size
);
843 * Qualcomm saves the UBO members twice for each UBO
846 for (member
= 0; (member
< state
->uniformblocks
[i
].header
->num_members
) && (state
->sz
> 0); member
++) {
847 state
->uniformblocks
[i
].members
[member
] = next_sect(state
, §_size
);
849 clean_ascii(state
->uniformblocks
[i
].members
[member
]->name
, sect_size
- 56);
851 printf("######## UNIFORM BLOCK MEMBER2: (size %d)\n", sect_size
);
852 dump_uniformblockmember(state
->uniformblocks
[i
].members
[member
]);
853 dump_hex((char *)state
->uniformblocks
[i
].members
[member
], sect_size
);
859 dump_shaders_a3xx(state
);
861 dump_shaders_a2xx(state
);
867 /* dump ascii version of shader program: */
868 ptr
= next_sect(state
, §_size
);
869 printf("\n#######################################################\n");
870 printf("######## SHADER SRC: (size=%d)\n", sect_size
);
871 dump_ascii(ptr
, sect_size
);
874 /* dump remaining sections (there shouldn't be any): */
875 while (state
->sz
> 0) {
876 ptr
= next_sect(state
, §_size
);
877 printf("######## section (size=%d)\n", sect_size
);
879 dump_hex(ptr
, sect_size
);
880 printf("as float:\n");
881 dump_float(ptr
, sect_size
);
882 printf("as ascii:\n");
883 dump_ascii(ptr
, sect_size
);
886 /* cleanup the uniform buffer members we allocated */
887 if (state
->hdr
->num_uniformblocks
> 0)
888 free (state
->uniformblocks
[i
].members
);
891 int main(int argc
, char **argv
)
893 enum rd_sect_type type
= RD_NONE
;
894 enum debug_t debug
= PRINT_RAW
| PRINT_STATS
;
900 /* lame argument parsing: */
903 if ((argc
> 1) && !strcmp(argv
[1], "--verbose")) {
904 debug
|= PRINT_RAW
| PRINT_VERBOSE
;
909 if ((argc
> 1) && !strcmp(argv
[1], "--expand")) {
910 debug
|= EXPAND_REPEAT
;
915 if ((argc
> 1) && !strcmp(argv
[1], "--short")) {
916 /* only short dump, original shader, symbol table, and disassembly */
922 if ((argc
> 1) && !strcmp(argv
[1], "--dump-shaders")) {
928 if ((argc
> 1) && !strcmp(argv
[1], "--raw")) {
934 if ((argc
> 1) && !strcmp(argv
[1], "--gpu300")) {
944 fprintf(stderr
, "usage: pgmdump [--verbose] [--short] [--dump-shaders] testlog.rd\n");
948 disasm_a2xx_set_debug(debug
);
949 disasm_a3xx_set_debug(debug
);
953 io
= io_open(infile
);
955 fprintf(stderr
, "could not open: %s\n", infile
);
961 io_readn(io
, &sz
, 4);
964 /* note: allow hex dumps to go a bit past the end of the buffer..
965 * might see some garbage, but better than missing the last few bytes..
967 buf
= calloc(1, sz
+ 3);
968 io_readn(io
, buf
+ 4, sz
);
971 struct state state
= {
975 printf("############################################################\n");
976 printf("program:\n");
977 dump_program(&state
);
978 printf("############################################################\n");
982 /* figure out what sort of input we are dealing with: */
983 if (!(check_extension(infile
, ".rd") || check_extension(infile
, ".rd.gz"))) {
984 gl_shader_stage shader
= ~0;
986 if (check_extension(infile
, ".vo")) {
987 shader
= MESA_SHADER_VERTEX
;
988 } else if (check_extension(infile
, ".fo")) {
989 shader
= MESA_SHADER_FRAGMENT
;
990 } else if (check_extension(infile
, ".vo3")) {
991 } else if (check_extension(infile
, ".fo3")) {
992 } else if (check_extension(infile
, ".co3")) {
994 fprintf(stderr
, "invalid input file: %s\n", infile
);
997 buf
= calloc(1, 100 * 1024);
998 ret
= io_readn(io
, buf
, 100 * 1024);
1000 fprintf(stderr
, "error: %m");
1004 return disasm_a2xx(buf
, ret
/4, 0, shader
);
1006 /* disassembly does not depend on shader stage on a3xx+: */
1007 return disasm_a3xx(buf
, ret
/4, 0, stdout
, gpu_id
);
1011 while ((io_readn(io
, &type
, sizeof(type
)) > 0) && (io_readn(io
, &sz
, 4) > 0)) {
1014 /* note: allow hex dumps to go a bit past the end of the buffer..
1015 * might see some garbage, but better than missing the last few bytes..
1017 buf
= calloc(1, sz
+ 3);
1018 io_readn(io
, buf
, sz
);
1023 printf("test: %s\n", (char *)buf
);
1025 case RD_VERT_SHADER
:
1026 printf("vertex shader:\n%s\n", (char *)buf
);
1028 case RD_FRAG_SHADER
:
1029 printf("fragment shader:\n%s\n", (char *)buf
);
1032 struct state state
= {
1036 printf("############################################################\n");
1037 printf("program:\n");
1038 dump_program(&state
);
1039 printf("############################################################\n");
1043 gpu_id
= *((unsigned int *)buf
);
1044 printf("gpu_id: %d\n", gpu_id
);