1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
|
/*
* Copyright (C) 2006 Ben Skeggs.
*
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
/*
* Authors:
* Ben Skeggs <darktama@iinet.net.au>
*/
#include "glheader.h"
#include "macros.h"
#include "enums.h"
#include "extensions.h"
#include "program.h"
#include "tnl/tnl.h"
#include "nouveau_context.h"
#include "nouveau_shader.h"
/*****************************************************************************
* Mesa entry points
*/
static void
nouveauBindProgram(GLcontext *ctx, GLenum target, struct gl_program *prog)
{
}
static struct gl_program *
nouveauNewProgram(GLcontext *ctx, GLenum target, GLuint id)
{
nouveauShader *nvs;
nvs = CALLOC_STRUCT(_nouveauShader);
switch (target) {
case GL_VERTEX_PROGRAM_ARB:
return _mesa_init_vertex_program(ctx, &nvs->mesa.vp, target, id);
case GL_FRAGMENT_PROGRAM_ARB:
return _mesa_init_fragment_program(ctx, &nvs->mesa.fp, target, id);
default:
_mesa_problem(ctx, "Unsupported shader target");
break;
}
FREE(nvs);
return NULL;
}
static void
nouveauDeleteProgram(GLcontext *ctx, struct gl_program *prog)
{
nouveauShader *nvs = (nouveauShader *)prog;
if (nvs->translated)
FREE(nvs->program);
_mesa_delete_program(ctx, prog);
}
static void
nouveauProgramStringNotify(GLcontext *ctx, GLenum target,
struct gl_program *prog)
{
nouveauShader *nvs = (nouveauShader *)prog;
if (nvs->translated)
FREE(nvs->program);
nvs->translated = 0;
_tnl_program_string(ctx, target, prog);
}
static GLboolean
nouveauIsProgramNative(GLcontext * ctx, GLenum target, struct gl_program *prog)
{
nouveauShader *nvs = (nouveauShader *)prog;
return nvs->translated;
}
GLboolean
nvsUpdateShader(GLcontext *ctx, nouveauShader *nvs)
{
nouveauContextPtr nmesa = NOUVEAU_CONTEXT(ctx);
struct gl_program_parameter_list *plist;
int i;
/* Translate to HW format now if necessary */
if (!nvs->translated) {
/* Mesa ASM shader -> nouveauShader */
if (!nouveau_shader_pass0_arb(ctx, nvs))
return GL_FALSE;
/* Basic dead code elimination + register usage info */
if (!nouveau_shader_pass1(nvs))
return GL_FALSE;
/* nouveauShader -> HW bytecode, HW register alloc */
if (!nouveau_shader_pass2(nvs))
return GL_FALSE;
assert(nvs->translated);
assert(nvs->program);
}
/* Update state parameters */
plist = nvs->mesa.vp.Base.Parameters;
_mesa_load_state_parameters(ctx, plist);
for (i=0; i<plist->NumParameters; i++) {
if (!nvs->on_hardware) {
/* if we've been kicked off the hardware there's no guarantee our
* consts are still there.. reupload them all
*/
nvs->func->UpdateConst(ctx, nvs, i);
} else if (plist->Parameters[i].Type == PROGRAM_STATE_VAR) {
/* update any changed state parameters */
if (!TEST_EQ_4V(nvs->params[i].val, nvs->params[i].source_val))
nvs->func->UpdateConst(ctx, nvs, i);
}
}
/* Upload program to hardware, this must come after state param update
* as >=NV30 fragprogs inline consts into the bytecode.
*/
if (!nvs->on_hardware) {
nouveauShader **current;
if (nvs->mesa.vp.Base.Target == GL_VERTEX_PROGRAM_ARB)
current = &nmesa->current_vertprog;
else
current = &nmesa->current_fragprog;
if (*current) (*current)->on_hardware = 0;
nvs->func->UploadToHW(ctx, nvs);
nvs->on_hardware = 1;
*current = nvs;
}
return GL_TRUE;
}
void
nouveauShaderInitFuncs(GLcontext * ctx)
{
nouveauContextPtr nmesa = NOUVEAU_CONTEXT(ctx);
switch (nmesa->screen->card->type) {
case NV_20:
NV20VPInitShaderFuncs(&nmesa->VPfunc);
break;
case NV_30:
NV30VPInitShaderFuncs(&nmesa->VPfunc);
NV30FPInitShaderFuncs(&nmesa->FPfunc);
break;
case NV_40:
case G_70:
NV40VPInitShaderFuncs(&nmesa->VPfunc);
NV40FPInitShaderFuncs(&nmesa->FPfunc);
break;
default:
return;
}
_mesa_enable_extension(ctx, "GL_ARB_vertex_program");
ctx->Const.VertexProgram.MaxNativeInstructions = nmesa->VPfunc.MaxInst;
ctx->Const.VertexProgram.MaxNativeAluInstructions = nmesa->VPfunc.MaxInst;
ctx->Const.VertexProgram.MaxNativeTexInstructions = nmesa->VPfunc.MaxInst;
ctx->Const.VertexProgram.MaxNativeTexIndirections =
ctx->Const.VertexProgram.MaxNativeTexInstructions;
ctx->Const.VertexProgram.MaxNativeAttribs = nmesa->VPfunc.MaxAttrib;
ctx->Const.VertexProgram.MaxNativeTemps = nmesa->VPfunc.MaxTemp;
ctx->Const.VertexProgram.MaxNativeAddressRegs = nmesa->VPfunc.MaxAddress;
ctx->Const.VertexProgram.MaxNativeParameters = nmesa->VPfunc.MaxConst;
if (nmesa->screen->card->type >= NV_30) {
_mesa_enable_extension(ctx, "GL_ARB_fragment_program");
ctx->Const.FragmentProgram.MaxNativeInstructions = nmesa->FPfunc.MaxInst;
ctx->Const.FragmentProgram.MaxNativeAluInstructions = nmesa->FPfunc.MaxInst;
ctx->Const.FragmentProgram.MaxNativeTexInstructions = nmesa->FPfunc.MaxInst;
ctx->Const.FragmentProgram.MaxNativeTexIndirections =
ctx->Const.FragmentProgram.MaxNativeTexInstructions;
ctx->Const.FragmentProgram.MaxNativeAttribs = nmesa->FPfunc.MaxAttrib;
ctx->Const.FragmentProgram.MaxNativeTemps = nmesa->FPfunc.MaxTemp;
ctx->Const.FragmentProgram.MaxNativeAddressRegs = nmesa->FPfunc.MaxAddress;
ctx->Const.FragmentProgram.MaxNativeParameters = nmesa->FPfunc.MaxConst;
}
ctx->Driver.NewProgram = nouveauNewProgram;
ctx->Driver.BindProgram = nouveauBindProgram;
ctx->Driver.DeleteProgram = nouveauDeleteProgram;
ctx->Driver.ProgramStringNotify = nouveauProgramStringNotify;
ctx->Driver.IsProgramNative = nouveauIsProgramNative;
}
/*****************************************************************************
* Disassembly support structs
*/
#define CHECK_RANGE(idx, arr) ((idx)<sizeof(_##arr)/sizeof(const char *)) \
? _##arr[(idx)] : #arr"_OOB"
#define NODS (1<<0)
#define BRANCH_TR (1<<1)
#define BRANCH_EL (1<<2)
#define BRANCH_EN (1<<3)
#define BRANCH_RE (1<<4)
#define BRANCH_ALL (BRANCH_TR|BRANCH_EL|BRANCH_EN)
#define COUNT_INC (1<<4)
#define COUNT_IND (1<<5)
#define COUNT_NUM (1<<6)
#define COUNT_ALL (COUNT_INC|COUNT_IND|COUNT_NUM)
#define TI_UNIT (1<<7)
struct _opcode_info
{
const char *name;
int numsrc;
int flags;
};
static struct _opcode_info ops[] = {
[NVS_OP_ABS] = {"ABS", 1, 0},
[NVS_OP_ADD] = {"ADD", 2, 0},
[NVS_OP_ARA] = {"ARA", 1, 0},
[NVS_OP_ARL] = {"ARL", 1, 0},
[NVS_OP_ARR] = {"ARR", 1, 0},
[NVS_OP_BRA] = {"BRA", 0, NODS | BRANCH_TR},
[NVS_OP_BRK] = {"BRK", 0, NODS},
[NVS_OP_CAL] = {"CAL", 0, NODS | BRANCH_TR},
[NVS_OP_CMP] = {"CMP", 2, 0},
[NVS_OP_COS] = {"COS", 1, 0},
[NVS_OP_DIV] = {"DIV", 2, 0},
[NVS_OP_DDX] = {"DDX", 1, 0},
[NVS_OP_DDY] = {"DDY", 1, 0},
[NVS_OP_DP2] = {"DP2", 2, 0},
[NVS_OP_DP2A] = {"DP2A", 3, 0},
[NVS_OP_DP3] = {"DP3", 2, 0},
[NVS_OP_DP4] = {"DP4", 2, 0},
[NVS_OP_DPH] = {"DPH", 2, 0},
[NVS_OP_DST] = {"DST", 2, 0},
[NVS_OP_EX2] = {"EX2", 1, 0},
[NVS_OP_EXP] = {"EXP", 1, 0},
[NVS_OP_FLR] = {"FLR", 1, 0},
[NVS_OP_FRC] = {"FRC", 1, 0},
[NVS_OP_IF] = {"IF", 0, NODS | BRANCH_EL | BRANCH_EN},
[NVS_OP_KIL] = {"KIL", 1, 0},
[NVS_OP_LG2] = {"LG2", 1, 0},
[NVS_OP_LIT] = {"LIT", 1, 0},
[NVS_OP_LOG] = {"LOG", 1, 0},
[NVS_OP_LOOP] = {"LOOP", 0, NODS | COUNT_ALL | BRANCH_EN},
[NVS_OP_LRP] = {"LRP", 3, 0},
[NVS_OP_MAD] = {"MAD", 3, 0},
[NVS_OP_MAX] = {"MAX", 2, 0},
[NVS_OP_MIN] = {"MIN", 2, 0},
[NVS_OP_MOV] = {"MOV", 1, 0},
[NVS_OP_MUL] = {"MUL", 2, 0},
[NVS_OP_NRM] = {"NRM", 1, 0},
[NVS_OP_PK2H] = {"PK2H", 1, 0},
[NVS_OP_PK2US] = {"PK2US", 1, 0},
[NVS_OP_PK4B] = {"PK4B", 1, 0},
[NVS_OP_PK4UB] = {"PK4UB", 1, 0},
[NVS_OP_POW] = {"POW", 2, 0},
[NVS_OP_POPA] = {"POPA", 0, 0},
[NVS_OP_PUSHA] = {"PUSHA", 1, NODS},
[NVS_OP_RCC] = {"RCC", 1, 0},
[NVS_OP_RCP] = {"RCP", 1, 0},
[NVS_OP_REP] = {"REP", 0, NODS | BRANCH_EN | COUNT_NUM},
[NVS_OP_RET] = {"RET", 0, NODS},
[NVS_OP_RFL] = {"RFL", 1, 0},
[NVS_OP_RSQ] = {"RSQ", 1, 0},
[NVS_OP_SCS] = {"SCS", 1, 0},
[NVS_OP_SEQ] = {"SEQ", 2, 0},
[NVS_OP_SFL] = {"SFL", 2, 0},
[NVS_OP_SGE] = {"SGE", 2, 0},
[NVS_OP_SGT] = {"SGT", 2, 0},
[NVS_OP_SIN] = {"SIN", 1, 0},
[NVS_OP_SLE] = {"SLE", 2, 0},
[NVS_OP_SLT] = {"SLT", 2, 0},
[NVS_OP_SNE] = {"SNE", 2, 0},
[NVS_OP_SSG] = {"SSG", 1, 0},
[NVS_OP_STR] = {"STR", 2, 0},
[NVS_OP_SUB] = {"SUB", 2, 0},
[NVS_OP_TEX] = {"TEX", 1, TI_UNIT},
[NVS_OP_TXB] = {"TXB", 1, TI_UNIT},
[NVS_OP_TXD] = {"TXD", 3, TI_UNIT},
[NVS_OP_TXL] = {"TXL", 1, TI_UNIT},
[NVS_OP_TXP] = {"TXP", 1, TI_UNIT},
[NVS_OP_UP2H] = {"UP2H", 1, 0},
[NVS_OP_UP2US] = {"UP2US", 1, 0},
[NVS_OP_UP4B] = {"UP4B", 1, 0},
[NVS_OP_UP4UB] = {"UP4UB", 1, 0},
[NVS_OP_X2D] = {"X2D", 3, 0},
[NVS_OP_XPD] = {"XPD", 2, 0},
[NVS_OP_NOP] = {"NOP", 0, NODS},
};
static struct _opcode_info *
_get_op_info(int op)
{
if (op >= (sizeof(ops) / sizeof(struct _opcode_info)))
return NULL;
if (ops[op].name == NULL)
return NULL;
return &ops[op];
}
static const char *_SFR_STRING[] = {
[NVS_FR_POSITION] = "position",
[NVS_FR_WEIGHT] = "weight",
[NVS_FR_NORMAL] = "normal",
[NVS_FR_COL0] = "color",
[NVS_FR_COL1] = "color.secondary",
[NVS_FR_BFC0] = "bfc",
[NVS_FR_BFC1] = "bfc.secondary",
[NVS_FR_FOGCOORD] = "fogcoord",
[NVS_FR_POINTSZ] = "pointsize",
[NVS_FR_TEXCOORD0] = "texcoord[0]",
[NVS_FR_TEXCOORD1] = "texcoord[1]",
[NVS_FR_TEXCOORD2] = "texcoord[2]",
[NVS_FR_TEXCOORD3] = "texcoord[3]",
[NVS_FR_TEXCOORD4] = "texcoord[4]",
[NVS_FR_TEXCOORD5] = "texcoord[5]",
[NVS_FR_TEXCOORD6] = "texcoord[6]",
[NVS_FR_TEXCOORD7] = "texcoord[7]",
[NVS_FR_FRAGDATA0] = "data[0]",
[NVS_FR_FRAGDATA1] = "data[1]",
[NVS_FR_FRAGDATA2] = "data[2]",
[NVS_FR_FRAGDATA3] = "data[3]",
[NVS_FR_CLIP0] = "clip_plane[0]",
[NVS_FR_CLIP1] = "clip_plane[1]",
[NVS_FR_CLIP2] = "clip_plane[2]",
[NVS_FR_CLIP3] = "clip_plane[3]",
[NVS_FR_CLIP4] = "clip_plane[4]",
[NVS_FR_CLIP5] = "clip_plane[5]",
[NVS_FR_CLIP6] = "clip_plane[6]",
[NVS_FR_FACING] = "facing",
};
#define SFR_STRING(idx) CHECK_RANGE((idx), SFR_STRING)
static const char *_SWZ_STRING[] = {
[NVS_SWZ_X] = "x",
[NVS_SWZ_Y] = "y",
[NVS_SWZ_Z] = "z",
[NVS_SWZ_W] = "w"
};
#define SWZ_STRING(idx) CHECK_RANGE((idx), SWZ_STRING)
static const char *_NVS_PREC_STRING[] = {
[NVS_PREC_FLOAT32] = "R",
[NVS_PREC_FLOAT16] = "H",
[NVS_PREC_FIXED12] = "X",
[NVS_PREC_UNKNOWN] = "?"
};
#define NVS_PREC_STRING(idx) CHECK_RANGE((idx), NVS_PREC_STRING)
static const char *_NVS_COND_STRING[] = {
[NVS_COND_FL] = "FL",
[NVS_COND_LT] = "LT",
[NVS_COND_EQ] = "EQ",
[NVS_COND_LE] = "LE",
[NVS_COND_GT] = "GT",
[NVS_COND_NE] = "NE",
[NVS_COND_GE] = "GE",
[NVS_COND_TR] = "TR",
[NVS_COND_UNKNOWN] = "??"
};
#define NVS_COND_STRING(idx) CHECK_RANGE((idx), NVS_COND_STRING)
/*****************************************************************************
* ShaderFragment dumping
*/
static void
nvsDumpIndent(int lvl)
{
while (lvl--)
printf(" ");
}
static void
nvsDumpSwizzle(nvsSwzComp *swz)
{
printf(".%s%s%s%s",
SWZ_STRING(swz[0]),
SWZ_STRING(swz[1]), SWZ_STRING(swz[2]), SWZ_STRING(swz[3])
);
}
static void
nvsDumpReg(nvsInstruction * inst, nvsRegister * reg)
{
if (reg->negate)
printf("-");
if (reg->abs)
printf("abs(");
switch (reg->file) {
case NVS_FILE_TEMP:
printf("R%d", reg->index);
nvsDumpSwizzle(reg->swizzle);
break;
case NVS_FILE_ATTRIB:
printf("attrib.%s", SFR_STRING(reg->index));
nvsDumpSwizzle(reg->swizzle);
break;
case NVS_FILE_ADDRESS:
printf("A%d", reg->index);
break;
case NVS_FILE_CONST:
if (reg->indexed)
printf("const[A%d.%s + %d]",
reg->addr_reg, SWZ_STRING(reg->addr_comp), reg->index);
else
printf("const[%d]", reg->index);
nvsDumpSwizzle(reg->swizzle);
break;
default:
printf("UNKNOWN_FILE");
break;
}
if (reg->abs)
printf(")");
}
void
nvsDumpInstruction(nvsInstruction * inst, int slot, int lvl)
{
struct _opcode_info *opr = &ops[inst->op];
int i;
nvsDumpIndent(lvl);
printf("%s ", opr->name);
if (!opr->flags & NODS) {
switch (inst->dest.file) {
case NVS_FILE_RESULT:
printf("result.%s", SFR_STRING(inst->dest.index));
break;
case NVS_FILE_TEMP:
printf("R%d", inst->dest.index);
break;
case NVS_FILE_ADDRESS:
printf("A%d", inst->dest.index);
break;
default:
printf("UNKNOWN_DST_FILE");
break;
}
if (inst->mask != SMASK_ALL) {
printf(".");
if (inst->mask & SMASK_X)
printf("x");
if (inst->mask & SMASK_Y)
printf("y");
if (inst->mask & SMASK_Z)
printf("z");
if (inst->mask & SMASK_W)
printf("w");
}
if (opr->numsrc)
printf(", ");
}
for (i = 0; i < opr->numsrc; i++) {
nvsDumpReg(inst, &inst->src[i]);
if (i != opr->numsrc - 1)
printf(", ");
}
if (opr->flags & TI_UNIT)
printf(", texture[%d]", inst->tex_unit);
printf("\n");
}
void
nvsDumpFragmentList(nvsFragmentList *f, int lvl)
{
while (f) {
switch (f->fragment->type) {
case NVS_INSTRUCTION:
nvsDumpInstruction((nvsInstruction*)f->fragment, 0, lvl);
break;
default:
fprintf(stderr, "%s: Only NVS_INSTRUCTION fragments can be in"
"nvsFragmentList!\n", __func__);
return;
}
f = f->next;
}
}
/*****************************************************************************
* HW shader disassembly
*/
static void
nvsDisasmHWShaderOp(nvsFunc * shader, int merged)
{
struct _opcode_info *opi;
nvsOpcode op;
nvsRegFile file;
nvsSwzComp swz[4];
int i;
op = shader->GetOpcode(shader, merged);
opi = _get_op_info(op);
if (!opi) {
printf("NO OPINFO!");
return;
}
printf("%s", opi->name);
if (shader->GetPrecision &&
(!(opi->flags & BRANCH_ALL)) && (!(opi->flags * NODS)) &&
(op != NVS_OP_NOP))
printf("%s", NVS_PREC_STRING(shader->GetPrecision(shader)));
if (shader->SupportsConditional && shader->SupportsConditional(shader)) {
if (shader->GetConditionUpdate(shader)) {
printf("C%d", shader->GetCondRegID(shader));
}
}
if (shader->GetSaturate && shader->GetSaturate(shader))
printf("_SAT");
if (!(opi->flags & NODS)) {
int mask = shader->GetDestMask(shader, merged);
switch (shader->GetDestFile(shader, merged)) {
case NVS_FILE_ADDRESS:
printf(" A%d", shader->GetDestID(shader, merged));
break;
case NVS_FILE_TEMP:
printf(" R%d", shader->GetDestID(shader, merged));
break;
case NVS_FILE_RESULT:
printf(" result.%s", (SFR_STRING(shader->GetDestID(shader, merged))));
break;
default:
printf(" BAD_RESULT_FILE");
break;
}
if (mask != SMASK_ALL) {
printf(".");
if (mask & SMASK_X) printf("x");
if (mask & SMASK_Y) printf("y");
if (mask & SMASK_Z) printf("z");
if (mask & SMASK_W) printf("w");
}
}
if (shader->SupportsConditional && shader->SupportsConditional(shader) &&
shader->GetConditionTest(shader)) {
shader->GetCondRegSwizzle(shader, swz);
printf(" (%s%d.%s%s%s%s)",
NVS_COND_STRING(shader->GetCondition(shader)),
shader->GetCondRegID(shader),
SWZ_STRING(swz[NVS_SWZ_X]),
SWZ_STRING(swz[NVS_SWZ_Y]),
SWZ_STRING(swz[NVS_SWZ_Z]),
SWZ_STRING(swz[NVS_SWZ_W])
);
}
/* looping */
if (opi->flags & COUNT_ALL) {
printf(" { ");
if (opi->flags & COUNT_NUM) {
printf("%d", shader->GetLoopCount(shader));
}
if (opi->flags & COUNT_IND) {
printf(", %d", shader->GetLoopInitial(shader));
}
if (opi->flags & COUNT_INC) {
printf(", %d", shader->GetLoopIncrement(shader));
}
printf(" }");
}
/* branching */
if (opi->flags & BRANCH_TR)
printf(" %d", shader->GetBranch(shader));
if (opi->flags & BRANCH_EL)
printf(" ELSE %d", shader->GetBranchElse(shader));
if (opi->flags & BRANCH_EN)
printf(" END %d", shader->GetBranchEnd(shader));
if (!(opi->flags & NODS) && opi->numsrc)
printf(",");
printf(" ");
for (i = 0; i < opi->numsrc; i++) {
if (shader->GetSourceAbs(shader, merged, i))
printf("abs(");
if (shader->GetSourceNegate(shader, merged, i))
printf("-");
file = shader->GetSourceFile(shader, merged, i);
switch (file) {
case NVS_FILE_TEMP:
printf("R%d", shader->GetSourceID(shader, merged, i));
break;
case NVS_FILE_CONST:
if (shader->GetSourceIndexed(shader, merged, i)) {
printf("c[A%d.%s + 0x%x]",
shader->GetRelAddressRegID(shader),
SWZ_STRING(shader->GetRelAddressSwizzle(shader)),
shader->GetSourceID(shader, merged, i)
);
} else {
float val[4];
if (shader->GetSourceConstVal) {
shader->GetSourceConstVal(shader, merged, i, val);
printf("{ %.02f, %.02f, %.02f, %.02f }",
val[0], val[1], val[2], val[3]);
} else {
printf("c[0x%x]", shader->GetSourceID(shader, merged, i));
}
}
break;
case NVS_FILE_ATTRIB:
if (shader->GetSourceIndexed(shader, merged, i)) {
printf("attrib[A%d.%s + %d]",
shader->GetRelAddressRegID(shader),
SWZ_STRING(shader->GetRelAddressSwizzle(shader)),
shader->GetSourceID(shader, merged, i)
);
}
else {
printf("attrib.%s",
SFR_STRING(shader->GetSourceID(shader, merged, i))
);
}
break;
case NVS_FILE_ADDRESS:
printf("A%d", shader->GetRelAddressRegID(shader));
break;
default:
printf("UNKNOWN_SRC_FILE");
break;
}
shader->GetSourceSwizzle(shader, merged, i, swz);
if (file != NVS_FILE_ADDRESS &&
(swz[NVS_SWZ_X] != NVS_SWZ_X || swz[NVS_SWZ_Y] != NVS_SWZ_Y ||
swz[NVS_SWZ_Z] != NVS_SWZ_Z || swz[NVS_SWZ_W] != NVS_SWZ_W)) {
printf(".%s%s%s%s", SWZ_STRING(swz[NVS_SWZ_X]),
SWZ_STRING(swz[NVS_SWZ_Y]),
SWZ_STRING(swz[NVS_SWZ_Z]),
SWZ_STRING(swz[NVS_SWZ_W]));
}
if (shader->GetSourceAbs(shader, merged, i))
printf(")");
if (shader->GetSourceScale) {
int scale = shader->GetSourceScale(shader, merged, i);
if (scale > 1)
printf("{scaled %dx}", scale);
}
if (i < (opi->numsrc - 1))
printf(", ");
}
if (shader->IsLastInst(shader))
printf(" + END");
}
void
nvsDisasmHWShader(nvsPtr nvs)
{
nvsFunc *shader = nvs->func;
unsigned int iaddr = 0;
if (!nvs->program) {
fprintf(stderr, "No HW program present");
return;
}
shader->inst = nvs->program;
while (1) {
if (shader->inst >= (nvs->program + nvs->program_size)) {
fprintf(stderr, "Reached end of program, but HW inst has no END");
break;
}
printf("\t0x%08x:\n", shader->inst[0]);
printf("\t0x%08x:\n", shader->inst[1]);
printf("\t0x%08x:\n", shader->inst[2]);
printf("\t0x%08x:", shader->inst[3]);
printf("\n\t\tINST %d.0: ", iaddr);
nvsDisasmHWShaderOp(shader, 0);
if (shader->HasMergedInst(shader)) {
printf("\n\t\tINST %d.1: ", iaddr);
nvsDisasmHWShaderOp(shader, 1);
}
printf("\n");
if (shader->IsLastInst(shader))
break;
shader->inst += shader->GetOffsetNext(shader);
iaddr++;
}
printf("\n");
}
|