6 #include "r300_context.h"
7 #include "nvvertprog.h"
9 static void r300BindProgram(GLcontext
*ctx
, GLenum target
, struct program
*prog
)
11 fprintf(stderr
, "r300BindProgram\n");
15 static struct program
*r300NewProgram(GLcontext
*ctx
, GLenum target
, GLuint id
)
17 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
18 struct r300_vertex_program
*vp
;
19 struct fragment_program
*fp
;
20 struct ati_fragment_shader
*afs
;
22 fprintf(stderr
, "r300NewProgram, target=%d, id=%d\n", target
, id
);
25 case GL_VERTEX_PROGRAM_ARB
:
26 fprintf(stderr
, "vertex prog\n");
27 vp
=malloc(sizeof(*vp
));
28 memset(vp
, 0, sizeof(*vp
));
30 /* note that vp points to mesa_program since its first on the struct
32 return _mesa_init_vertex_program(ctx
, &vp
->mesa_program
, target
, id
);
34 case GL_FRAGMENT_PROGRAM_ARB
:
35 fprintf(stderr
, "fragment prog\n");
36 fp
=malloc(sizeof(*fp
));
37 memset(fp
, 0, sizeof(*fp
));
39 return _mesa_init_fragment_program(ctx
, fp
, target
, id
);
40 case GL_FRAGMENT_PROGRAM_NV
:
41 fprintf(stderr
, "nv fragment prog\n");
42 fp
=malloc(sizeof(*fp
));
43 memset(fp
, 0, sizeof(*fp
));
45 return _mesa_init_fragment_program(ctx
, fp
, target
, id
);
47 case GL_FRAGMENT_SHADER_ATI
:
48 fprintf(stderr
, "ati fragment prog\n");
49 afs
=malloc(sizeof(*afs
));
50 memset(afs
, 0, sizeof(*afs
));
52 return _mesa_init_ati_fragment_shader(ctx
, afs
, target
, id
);
61 static void r300DeleteProgram(GLcontext
*ctx
, struct program
*prog
)
63 fprintf(stderr
, "r300DeleteProgram\n");
65 /* check that not active */
66 _mesa_delete_program(ctx
, prog
);
69 static void r300ProgramStringNotify(GLcontext
*ctx
, GLenum target
,
72 struct r300_vertex_program
*vp
=(void *)prog
;
74 fprintf(stderr
, "r300ProgramStringNotify\n");
75 /* XXX: There is still something wrong as mesa doesnt call r300IsProgramNative at all */
76 r300IsProgramNative(ctx
, target
, prog
);
79 case GL_VERTEX_PROGRAM_ARB
:
80 vp
->translated
=GL_FALSE
;
86 #define SCALAR_FLAG (1<<31)
87 #define FLAG_MASK (1<<31)
88 #define OPN(operator, ip, op) {#operator, VP_OPCODE_##operator, ip, op}
92 unsigned long ip
; /* number of input operands and flags */
97 OPN(ARL
, 1, 1|SCALAR_FLAG
),
98 OPN(DP3
, 2, 3|SCALAR_FLAG
),
99 OPN(DP4
, 2, 3|SCALAR_FLAG
),
100 OPN(DPH
, 2, 3|SCALAR_FLAG
),
102 OPN(EX2
, 1|SCALAR_FLAG
, 4|SCALAR_FLAG
),
103 OPN(EXP
, 1|SCALAR_FLAG
, 1),
106 OPN(LG2
, 1|SCALAR_FLAG
, 4|SCALAR_FLAG
),
108 OPN(LOG
, 1|SCALAR_FLAG
, 1),
114 OPN(POW
, 2|SCALAR_FLAG
, 4|SCALAR_FLAG
),
115 OPN(RCP
, 1|SCALAR_FLAG
, 4|SCALAR_FLAG
),
116 OPN(RSQ
, 1|SCALAR_FLAG
, 4|SCALAR_FLAG
),
122 OPN(RCC
, 0, 0), //extra
127 #define OPN(rf) {#rf, PROGRAM_##rf}
132 }register_file_names
[]={
144 char *dst_mask_names
[4]={ "X", "Y", "Z", "W" };
146 /* from vertex program spec:
147 Instruction Inputs Output Description
148 ----------- ------ ------ --------------------------------
149 ABS v v absolute value
151 ARL v a address register load
152 DP3 v,v ssss 3-component dot product
153 DP4 v,v ssss 4-component dot product
154 DPH v,v ssss homogeneous dot product
155 DST v,v v distance vector
156 EX2 s ssss exponential base 2
157 EXP s v exponential base 2 (approximate)
160 LG2 s ssss logarithm base 2
161 LIT v v compute light coefficients
162 LOG s v logarithm base 2 (approximate)
163 MAD v,v,v v multiply and add
168 POW s,s ssss exponentiate
169 RCP s ssss reciprocal
170 RSQ s ssss reciprocal square root
171 SGE v,v v set on greater than or equal
172 SLT v,v v set on less than
174 SWZ v v extended swizzle
175 XPD v,v v cross product
178 void dump_program_params(struct vertex_program
*vp
){
182 fprintf(stderr
, "NumInstructions=%d\n", vp
->Base
.NumInstructions
);
183 fprintf(stderr
, "NumTemporaries=%d\n", vp
->Base
.NumTemporaries
);
184 fprintf(stderr
, "NumParameters=%d\n", vp
->Base
.NumParameters
);
185 fprintf(stderr
, "NumAttributes=%d\n", vp
->Base
.NumAttributes
);
186 fprintf(stderr
, "NumAddressRegs=%d\n", vp
->Base
.NumAddressRegs
);
188 for(pi
=0; pi
< vp
->Base
.NumParameters
; pi
++){
189 fprintf(stderr
, "{ ");
191 fprintf(stderr
, "%f ", vp
->Base
.LocalParams
[pi
][i
]);
192 fprintf(stderr
, "}\n");
195 for(pi
=0; pi
< vp
->Parameters
->NumParameters
; pi
++){
196 fprintf(stderr
, "param %02d:", pi
);
198 switch(vp
->Parameters
->Parameters
[pi
].Type
){
200 case NAMED_PARAMETER
:
201 fprintf(stderr
, "%s", vp
->Parameters
->Parameters
[pi
].Name
);
202 fprintf(stderr
, "(NAMED_PARAMETER)");
206 fprintf(stderr
, "(CONSTANT)");
210 fprintf(stderr
, "(STATE)\n");
211 /* fetch state info */
217 fprintf(stderr
, "{ ");
219 fprintf(stderr
, "%f ", vp
->Parameters
->Parameters
[pi
].Values
[i
]);
220 fprintf(stderr
, "}\n");
225 static GLboolean
r300IsProgramNative(GLcontext
*ctx
, GLenum target
,
226 struct program
*prog
)
228 struct vertex_program
*vp
=(void *)prog
;
229 struct vp_instruction
*vpi
;
230 int i
, operand_index
;
233 fprintf(stderr
, "r300IsProgramNative\n");
236 dump_program_params(vp
);
238 vpi
=vp
->Instructions
;
241 if(vpi
->Opcode
== VP_OPCODE_END
)
244 for(i
=0; i
< sizeof(op_names
) / sizeof(*op_names
); i
++){
245 if(vpi
->Opcode
== op_names
[i
].opcode
){
246 fprintf(stderr
, "%s ", op_names
[i
].name
);
252 for(i
=0; i
< sizeof(register_file_names
) / sizeof(*register_file_names
); i
++){
253 if(vpi
->DstReg
.File
== register_file_names
[i
].id
){
254 fprintf(stderr
, "%s ", register_file_names
[i
].name
);
259 fprintf(stderr
, "%d.", vpi
->DstReg
.Index
);
262 if(vpi
->DstReg
.WriteMask
[i
])
263 fprintf(stderr
, "%s", dst_mask_names
[i
]);
264 fprintf(stderr
, " ");
266 for(operand_index
=0; operand_index
< op_names
[operator_index
].ip
& (~FLAG_MASK
);
269 if(vpi
->SrcReg
[operand_index
].Negate
)
270 fprintf(stderr
, "-");
272 for(i
=0; i
< sizeof(register_file_names
) / sizeof(*register_file_names
); i
++){
273 if(vpi
->SrcReg
[operand_index
].File
== register_file_names
[i
].id
){
274 fprintf(stderr
, "%s ", register_file_names
[i
].name
);
278 fprintf(stderr
, "%d.", vpi
->SrcReg
[operand_index
].Index
);
281 fprintf(stderr
, "%s", dst_mask_names
[vpi
->SrcReg
[operand_index
].Swizzle
[i
]]);
283 if(operand_index
+1 < op_names
[operator_index
].ip
& (~FLAG_MASK
) )
284 fprintf(stderr
, ",");
286 fprintf(stderr
, "\n");
293 /* This is misnamed and shouldnt be here since fragment programs use these functions too */
294 void r300InitVertexProgFuncs(struct dd_function_table
*functions
)
297 functions
->NewProgram
=r300NewProgram
;
298 functions
->BindProgram
=r300BindProgram
;
299 functions
->DeleteProgram
=r300DeleteProgram
;
300 functions
->ProgramStringNotify
=r300ProgramStringNotify
;
301 functions
->IsProgramNative
=r300IsProgramNative
;