2 * Copyright (C) 2008-2009 Advanced Micro Devices, Inc.
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 shall be included
12 * in all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 * Richard Li <RichardZ.Li@amd.com>, <richardradeon@gmail.com>
25 * CooperYuan <cooper.yuan@amd.com>, <cooperyuan@gmail.com>
34 #include "main/imports.h"
35 #include "program/prog_parameter.h"
36 #include "program/prog_statevars.h"
37 #include "program/program.h"
39 #include "r600_context.h"
40 #include "r600_cmdbuf.h"
41 #include "r600_emit.h"
43 #include "r700_fragprog.h"
45 #include "r700_debug.h"
47 void insert_wpos_code(GLcontext
*ctx
, struct gl_fragment_program
*fprog
)
49 static const gl_state_index winstate
[STATE_LENGTH
]
50 = { STATE_INTERNAL
, STATE_FB_SIZE
, 0, 0, 0};
51 struct prog_instruction
*newInst
, *inst
;
52 GLint win_size
; /* state reference */
53 GLuint wpos_temp
; /* temp register */
56 /* PARAM win_size = STATE_FB_SIZE */
57 win_size
= _mesa_add_state_reference(fprog
->Base
.Parameters
, winstate
);
59 wpos_temp
= fprog
->Base
.NumTemporaries
++;
61 /* scan program where WPOS is used and replace with wpos_temp */
62 inst
= fprog
->Base
.Instructions
;
63 for (i
= 0; i
< fprog
->Base
.NumInstructions
; i
++) {
64 for (j
=0; j
< 3; j
++) {
65 if(inst
->SrcReg
[j
].File
== PROGRAM_INPUT
&&
66 inst
->SrcReg
[j
].Index
== FRAG_ATTRIB_WPOS
) {
67 inst
->SrcReg
[j
].File
= PROGRAM_TEMPORARY
;
68 inst
->SrcReg
[j
].Index
= wpos_temp
;
74 _mesa_insert_instructions(&(fprog
->Base
), 0, 1);
76 newInst
= fprog
->Base
.Instructions
;
78 * wpos_temp.xyzw = wpos.x-yzw + winsize.0y00 */
79 newInst
[0].Opcode
= OPCODE_ADD
;
80 newInst
[0].DstReg
.File
= PROGRAM_TEMPORARY
;
81 newInst
[0].DstReg
.Index
= wpos_temp
;
82 newInst
[0].DstReg
.WriteMask
= WRITEMASK_XYZW
;
84 newInst
[0].SrcReg
[0].File
= PROGRAM_INPUT
;
85 newInst
[0].SrcReg
[0].Index
= FRAG_ATTRIB_WPOS
;
86 newInst
[0].SrcReg
[0].Swizzle
= SWIZZLE_XYZW
;
87 newInst
[0].SrcReg
[0].Negate
= NEGATE_Y
;
89 newInst
[0].SrcReg
[1].File
= PROGRAM_STATE_VAR
;
90 newInst
[0].SrcReg
[1].Index
= win_size
;
91 newInst
[0].SrcReg
[1].Swizzle
= MAKE_SWIZZLE4(SWIZZLE_ZERO
, SWIZZLE_Y
, SWIZZLE_ZERO
, SWIZZLE_ZERO
);
95 //TODO : Validate FP input with VP output.
96 void Map_Fragment_Program(r700_AssemblerBase
*pAsm
,
97 struct gl_fragment_program
*mesa_fp
,
104 /* match fp inputs with vp exports. */
105 struct r700_vertex_program_cont
*vpc
=
106 (struct r700_vertex_program_cont
*)ctx
->VertexProgram
._Current
;
107 GLbitfield OutputsWritten
= vpc
->mesa_program
.Base
.OutputsWritten
;
109 pAsm
->number_used_registers
= 0;
111 //Input mapping : mesa_fp->Base.InputsRead set the flag, set in
112 //The flags parsed in parse_attrib_binding. FRAG_ATTRIB_COLx, FRAG_ATTRIB_TEXx, ...
113 //MUST match order in Map_Vertex_Output
114 unBit
= 1 << FRAG_ATTRIB_WPOS
;
115 if(mesa_fp
->Base
.InputsRead
& unBit
)
117 pAsm
->uiFP_AttributeMap
[FRAG_ATTRIB_WPOS
] = pAsm
->number_used_registers
++;
120 unBit
= 1 << VERT_RESULT_COL0
;
121 if(OutputsWritten
& unBit
)
123 pAsm
->uiFP_AttributeMap
[FRAG_ATTRIB_COL0
] = pAsm
->number_used_registers
++;
126 unBit
= 1 << VERT_RESULT_COL1
;
127 if(OutputsWritten
& unBit
)
129 pAsm
->uiFP_AttributeMap
[FRAG_ATTRIB_COL1
] = pAsm
->number_used_registers
++;
132 unBit
= 1 << VERT_RESULT_FOGC
;
133 if(OutputsWritten
& unBit
)
135 pAsm
->uiFP_AttributeMap
[FRAG_ATTRIB_FOGC
] = pAsm
->number_used_registers
++;
140 unBit
= 1 << (VERT_RESULT_TEX0
+ i
);
141 if(OutputsWritten
& unBit
)
143 pAsm
->uiFP_AttributeMap
[FRAG_ATTRIB_TEX0
+ i
] = pAsm
->number_used_registers
++;
147 /* order has been taken care of */
149 for(i
=VERT_RESULT_VAR0
; i
<VERT_RESULT_MAX
; i
++)
152 if(OutputsWritten
& unBit
)
154 pAsm
->uiFP_AttributeMap
[i
-VERT_RESULT_VAR0
+FRAG_ATTRIB_VAR0
] = pAsm
->number_used_registers
++;
158 if( (mesa_fp
->Base
.InputsRead
>> FRAG_ATTRIB_VAR0
) > 0 )
160 struct r700_vertex_program_cont
*vpc
=
161 (struct r700_vertex_program_cont
*)ctx
->VertexProgram
._Current
;
162 struct gl_program_parameter_list
* VsVarying
= vpc
->mesa_program
.Base
.Varying
;
163 struct gl_program_parameter_list
* PsVarying
= mesa_fp
->Base
.Varying
;
164 struct gl_program_parameter
* pVsParam
;
165 struct gl_program_parameter
* pPsParam
;
167 GLuint unMaxVarying
= 0;
169 for(i
=0; i
<VsVarying
->NumParameters
; i
++)
171 pAsm
->uiFP_AttributeMap
[i
+ FRAG_ATTRIB_VAR0
] = 0;
174 for(i
=FRAG_ATTRIB_VAR0
; i
<FRAG_ATTRIB_MAX
; i
++)
177 if(mesa_fp
->Base
.InputsRead
& unBit
)
179 j
= i
- FRAG_ATTRIB_VAR0
;
180 pPsParam
= PsVarying
->Parameters
+ j
;
182 for(k
=0; k
<VsVarying
->NumParameters
; k
++)
184 pVsParam
= VsVarying
->Parameters
+ k
;
186 if( strcmp(pPsParam
->Name
, pVsParam
->Name
) == 0)
188 pAsm
->uiFP_AttributeMap
[i
] = pAsm
->number_used_registers
+ k
;
199 pAsm
->number_used_registers
+= unMaxVarying
+ 1;
202 unBit
= 1 << FRAG_ATTRIB_FACE
;
203 if(mesa_fp
->Base
.InputsRead
& unBit
)
205 pAsm
->uiFP_AttributeMap
[FRAG_ATTRIB_FACE
] = pAsm
->number_used_registers
++;
208 unBit
= 1 << FRAG_ATTRIB_PNTC
;
209 if(mesa_fp
->Base
.InputsRead
& unBit
)
211 pAsm
->uiFP_AttributeMap
[FRAG_ATTRIB_PNTC
] = pAsm
->number_used_registers
++;
214 /* Map temporary registers (GPRs) */
215 pAsm
->starting_temp_register_number
= pAsm
->number_used_registers
;
217 if(mesa_fp
->Base
.NumNativeTemporaries
>= mesa_fp
->Base
.NumTemporaries
)
219 pAsm
->number_used_registers
+= mesa_fp
->Base
.NumNativeTemporaries
;
223 pAsm
->number_used_registers
+= mesa_fp
->Base
.NumTemporaries
;
227 pAsm
->number_of_exports
= 0;
228 pAsm
->number_of_colorandz_exports
= 0; /* don't include stencil and mask out. */
229 pAsm
->starting_export_register_number
= pAsm
->number_used_registers
;
231 for (i
= 0; i
< FRAG_RESULT_MAX
; ++i
)
234 if (mesa_fp
->Base
.OutputsWritten
& unBit
)
236 if (i
== FRAG_RESULT_DEPTH
)
238 pAsm
->depth_export_register_number
= pAsm
->number_used_registers
;
239 pAsm
->pR700Shader
->depthIsExported
= 1;
242 pAsm
->uiFP_OutputMap
[i
] = pAsm
->number_used_registers
++;
243 ++pAsm
->number_of_exports
;
244 ++pAsm
->number_of_colorandz_exports
;
248 pAsm
->pucOutMask
= (unsigned char*) MALLOC(pAsm
->number_of_exports
);
249 for(ui
=0; ui
<pAsm
->number_of_exports
; ui
++)
251 pAsm
->pucOutMask
[ui
] = 0x0;
254 pAsm
->flag_reg_index
= pAsm
->number_used_registers
++;
256 pAsm
->uFirstHelpReg
= pAsm
->number_used_registers
;
259 GLboolean
Find_Instruction_Dependencies_fp(struct r700_fragment_program
*fp
,
260 struct gl_fragment_program
*mesa_fp
)
263 GLint
* puiTEMPwrites
;
264 GLint
* puiTEMPreads
;
265 struct prog_instruction
* pILInst
;
267 struct prog_instruction
* texcoord_DepInst
;
270 puiTEMPwrites
= (GLint
*) MALLOC(sizeof(GLuint
)*mesa_fp
->Base
.NumTemporaries
);
271 puiTEMPreads
= (GLint
*) MALLOC(sizeof(GLuint
)*mesa_fp
->Base
.NumTemporaries
);
273 for(i
=0; i
<mesa_fp
->Base
.NumTemporaries
; i
++)
275 puiTEMPwrites
[i
] = -1;
276 puiTEMPreads
[i
] = -1;
279 pInstDeps
= (InstDeps
*)MALLOC(sizeof(InstDeps
)*mesa_fp
->Base
.NumInstructions
);
281 for(i
=0; i
<mesa_fp
->Base
.NumInstructions
; i
++)
283 pInstDeps
[i
].nDstDep
= -1;
284 pILInst
= &(mesa_fp
->Base
.Instructions
[i
]);
287 if(pILInst
->DstReg
.File
== PROGRAM_TEMPORARY
)
289 //Set lastwrite for the temp
290 puiTEMPwrites
[pILInst
->DstReg
.Index
] = i
;
296 if(pILInst
->SrcReg
[j
].File
== PROGRAM_TEMPORARY
)
299 pInstDeps
[i
].nSrcDeps
[j
] = puiTEMPwrites
[pILInst
->SrcReg
[j
].Index
];
301 if(puiTEMPreads
[pILInst
->SrcReg
[j
].Index
] < 0 )
303 puiTEMPreads
[pILInst
->SrcReg
[j
].Index
] = i
;
308 pInstDeps
[i
].nSrcDeps
[j
] = -1;
313 fp
->r700AsmCode
.pInstDeps
= pInstDeps
;
315 //Find dep for tex inst
316 for(i
=0; i
<mesa_fp
->Base
.NumInstructions
; i
++)
318 pILInst
= &(mesa_fp
->Base
.Instructions
[i
]);
320 if(GL_TRUE
== IsTex(pILInst
->Opcode
))
321 { //src0 is the tex coord register, src1 is texunit, src2 is textype
322 nDepInstID
= pInstDeps
[i
].nSrcDeps
[0];
325 texcoord_DepInst
= &(mesa_fp
->Base
.Instructions
[nDepInstID
]);
326 if(GL_TRUE
== IsAlu(texcoord_DepInst
->Opcode
) )
328 pInstDeps
[nDepInstID
].nDstDep
= i
;
329 pInstDeps
[i
].nDstDep
= i
;
331 else if(GL_TRUE
== IsTex(texcoord_DepInst
->Opcode
) )
333 pInstDeps
[i
].nDstDep
= i
;
339 // make sure that we dont overwrite src used earlier
340 nDepInstID
= puiTEMPreads
[pILInst
->DstReg
.Index
];
343 pInstDeps
[i
].nDstDep
= puiTEMPreads
[pILInst
->DstReg
.Index
];
344 texcoord_DepInst
= &(mesa_fp
->Base
.Instructions
[nDepInstID
]);
345 if(GL_TRUE
== IsAlu(texcoord_DepInst
->Opcode
) )
347 pInstDeps
[nDepInstID
].nDstDep
= i
;
361 GLboolean
r700TranslateFragmentShader(struct r700_fragment_program
*fp
,
362 struct gl_fragment_program
*mesa_fp
,
365 GLuint number_of_colors_exported
;
366 GLboolean z_enabled
= GL_FALSE
;
367 GLuint unBit
, shadow_unit
;
369 struct prog_instruction
*inst
;
370 gl_state_index shadow_ambient
[STATE_LENGTH
]
371 = { STATE_INTERNAL
, STATE_SHADOW_AMBIENT
, 0, 0, 0};
374 Init_r700_AssemblerBase( SPT_FP
, &(fp
->r700AsmCode
), &(fp
->r700Shader
) );
376 if(mesa_fp
->Base
.InputsRead
& FRAG_BIT_WPOS
)
378 insert_wpos_code(ctx
, mesa_fp
);
381 /* add/map consts for ARB_shadow_ambient */
382 if(mesa_fp
->Base
.ShadowSamplers
)
384 inst
= mesa_fp
->Base
.Instructions
;
385 for (i
= 0; i
< mesa_fp
->Base
.NumInstructions
; i
++)
387 if(inst
->TexShadow
== 1)
389 shadow_unit
= inst
->TexSrcUnit
;
390 shadow_ambient
[2] = shadow_unit
;
391 fp
->r700AsmCode
.shadow_regs
[shadow_unit
] =
392 _mesa_add_state_reference(mesa_fp
->Base
.Parameters
, shadow_ambient
);
398 Map_Fragment_Program(&(fp
->r700AsmCode
), mesa_fp
, ctx
);
400 if( GL_FALSE
== Find_Instruction_Dependencies_fp(fp
, mesa_fp
) )
405 InitShaderProgram(&(fp
->r700AsmCode
));
407 for(i
=0; i
< MAX_SAMPLERS
; i
++)
409 fp
->r700AsmCode
.SamplerUnits
[i
] = fp
->mesa_program
.Base
.SamplerUnits
[i
];
412 fp
->r700AsmCode
.unCurNumILInsts
= mesa_fp
->Base
.NumInstructions
;
414 if( GL_FALSE
== AssembleInstr(0,
416 mesa_fp
->Base
.NumInstructions
,
417 &(mesa_fp
->Base
.Instructions
[0]),
418 &(fp
->r700AsmCode
)) )
423 if(GL_FALSE
== Process_Fragment_Exports(&(fp
->r700AsmCode
), mesa_fp
->Base
.OutputsWritten
) )
428 if( GL_FALSE
== RelocProgram(&(fp
->r700AsmCode
), &(mesa_fp
->Base
)) )
433 fp
->r700Shader
.nRegs
= (fp
->r700AsmCode
.number_used_registers
== 0) ? 0
434 : (fp
->r700AsmCode
.number_used_registers
- 1);
436 fp
->r700Shader
.nParamExports
= fp
->r700AsmCode
.number_of_exports
;
438 number_of_colors_exported
= fp
->r700AsmCode
.number_of_colorandz_exports
;
440 unBit
= 1 << FRAG_RESULT_DEPTH
;
441 if(mesa_fp
->Base
.OutputsWritten
& unBit
)
444 number_of_colors_exported
--;
447 /* illegal to set this to 0 */
448 if(number_of_colors_exported
|| z_enabled
)
450 fp
->r700Shader
.exportMode
= number_of_colors_exported
<< 1 | z_enabled
;
454 fp
->r700Shader
.exportMode
= (1 << 1);
457 fp
->translated
= GL_TRUE
;
462 void r700SelectFragmentShader(GLcontext
*ctx
)
464 context_t
*context
= R700_CONTEXT(ctx
);
465 struct r700_fragment_program
*fp
= (struct r700_fragment_program
*)
466 (ctx
->FragmentProgram
._Current
);
467 if (context
->radeon
.radeonScreen
->chip_family
< CHIP_FAMILY_RV770
)
469 fp
->r700AsmCode
.bR6xx
= 1;
472 if (GL_FALSE
== fp
->translated
)
473 r700TranslateFragmentShader(fp
, &(fp
->mesa_program
), ctx
);
476 void * r700GetActiveFpShaderBo(GLcontext
* ctx
)
478 struct r700_fragment_program
*fp
= (struct r700_fragment_program
*)
479 (ctx
->FragmentProgram
._Current
);
484 GLboolean
r700SetupFragmentProgram(GLcontext
* ctx
)
486 context_t
*context
= R700_CONTEXT(ctx
);
487 R700_CHIP_CONTEXT
*r700
= (R700_CHIP_CONTEXT
*)(&context
->hw
);
488 struct r700_fragment_program
*fp
= (struct r700_fragment_program
*)
489 (ctx
->FragmentProgram
._Current
);
490 r700_AssemblerBase
*pAsm
= &(fp
->r700AsmCode
);
491 struct gl_fragment_program
*mesa_fp
= &(fp
->mesa_program
);
492 struct gl_program_parameter_list
*paramList
;
493 unsigned int unNumParamData
;
495 unsigned int unNumOfReg
;
498 GLboolean point_sprite
= GL_FALSE
;
500 if(GL_FALSE
== fp
->loaded
)
502 if(fp
->r700Shader
.bNeedsAssembly
== GL_TRUE
)
504 Assemble( &(fp
->r700Shader
) );
510 (GLvoid
*)(fp
->r700Shader
.pProgram
),
511 fp
->r700Shader
.uShaderBinaryDWORDSize
,
514 fp
->loaded
= GL_TRUE
;
517 DumpHwBinary(DUMP_PIXEL_SHADER
, (GLvoid
*)(fp
->r700Shader
.pProgram
),
518 fp
->r700Shader
.uShaderBinaryDWORDSize
);
520 /* TODO : enable this after MemUse fixed *=
521 (context->chipobj.MemUse)(context, fp->shadercode.buf->id);
524 R600_STATECHANGE(context
, ps
);
526 r700
->ps
.SQ_PGM_RESOURCES_PS
.u32All
= 0;
527 SETbit(r700
->ps
.SQ_PGM_RESOURCES_PS
.u32All
, PGM_RESOURCES__PRIME_CACHE_ON_DRAW_bit
);
529 r700
->ps
.SQ_PGM_START_PS
.u32All
= 0; /* set from buffer obj */
531 R600_STATECHANGE(context
, spi
);
533 unNumOfReg
= fp
->r700Shader
.nRegs
+ 1;
535 ui
= (r700
->SPI_PS_IN_CONTROL_0
.u32All
& NUM_INTERP_mask
) / (1 << NUM_INTERP_shift
);
537 /* PS uses fragment.position */
538 if (mesa_fp
->Base
.InputsRead
& (1 << FRAG_ATTRIB_WPOS
))
541 SETfield(r700
->SPI_PS_IN_CONTROL_0
.u32All
, ui
, NUM_INTERP_shift
, NUM_INTERP_mask
);
542 SETfield(r700
->SPI_PS_IN_CONTROL_0
.u32All
, CENTERS_ONLY
, BARYC_SAMPLE_CNTL_shift
, BARYC_SAMPLE_CNTL_mask
);
543 SETbit(r700
->SPI_PS_IN_CONTROL_0
.u32All
, POSITION_ENA_bit
);
544 SETbit(r700
->SPI_INPUT_Z
.u32All
, PROVIDE_Z_TO_SPI_bit
);
548 CLEARbit(r700
->SPI_PS_IN_CONTROL_0
.u32All
, POSITION_ENA_bit
);
549 CLEARbit(r700
->SPI_INPUT_Z
.u32All
, PROVIDE_Z_TO_SPI_bit
);
552 if (mesa_fp
->Base
.InputsRead
& (1 << FRAG_ATTRIB_FACE
))
555 SETfield(r700
->SPI_PS_IN_CONTROL_0
.u32All
, ui
, NUM_INTERP_shift
, NUM_INTERP_mask
);
556 SETbit(r700
->SPI_PS_IN_CONTROL_1
.u32All
, FRONT_FACE_ENA_bit
);
557 SETbit(r700
->SPI_PS_IN_CONTROL_1
.u32All
, FRONT_FACE_ALL_BITS_bit
);
558 SETfield(r700
->SPI_PS_IN_CONTROL_1
.u32All
, pAsm
->uiFP_AttributeMap
[FRAG_ATTRIB_FACE
], FRONT_FACE_ADDR_shift
, FRONT_FACE_ADDR_mask
);
562 CLEARbit(r700
->SPI_PS_IN_CONTROL_1
.u32All
, FRONT_FACE_ENA_bit
);
565 /* see if we need any point_sprite replacements, also increase num_interp
566 * as there's no vp output for them */
567 if (ctx
->Point
.PointSprite
)
569 for (i
= FRAG_ATTRIB_TEX0
; i
<= FRAG_ATTRIB_TEX7
; i
++)
571 if (ctx
->Point
.CoordReplace
[i
- FRAG_ATTRIB_TEX0
] == GL_TRUE
)
574 point_sprite
= GL_TRUE
;
579 if( mesa_fp
->Base
.InputsRead
& (1 << FRAG_ATTRIB_PNTC
))
582 if ((mesa_fp
->Base
.InputsRead
& (1 << FRAG_ATTRIB_PNTC
)) || point_sprite
)
584 SETfield(r700
->SPI_PS_IN_CONTROL_0
.u32All
, ui
, NUM_INTERP_shift
, NUM_INTERP_mask
);
585 SETbit(r700
->SPI_INTERP_CONTROL_0
.u32All
, PNT_SPRITE_ENA_bit
);
586 SETfield(r700
->SPI_INTERP_CONTROL_0
.u32All
, SPI_PNT_SPRITE_SEL_S
, PNT_SPRITE_OVRD_X_shift
, PNT_SPRITE_OVRD_X_mask
);
587 SETfield(r700
->SPI_INTERP_CONTROL_0
.u32All
, SPI_PNT_SPRITE_SEL_T
, PNT_SPRITE_OVRD_Y_shift
, PNT_SPRITE_OVRD_Y_mask
);
588 SETfield(r700
->SPI_INTERP_CONTROL_0
.u32All
, SPI_PNT_SPRITE_SEL_0
, PNT_SPRITE_OVRD_Z_shift
, PNT_SPRITE_OVRD_Z_mask
);
589 SETfield(r700
->SPI_INTERP_CONTROL_0
.u32All
, SPI_PNT_SPRITE_SEL_1
, PNT_SPRITE_OVRD_W_shift
, PNT_SPRITE_OVRD_W_mask
);
590 /* Like e.g. viewport and winding, point sprite coordinates are
591 * inverted when rendering to FBO. */
592 if ((ctx
->Point
.SpriteOrigin
== GL_LOWER_LEFT
) == !ctx
->DrawBuffer
->Name
)
593 SETbit(r700
->SPI_INTERP_CONTROL_0
.u32All
, PNT_SPRITE_TOP_1_bit
);
595 CLEARbit(r700
->SPI_INTERP_CONTROL_0
.u32All
, PNT_SPRITE_TOP_1_bit
);
599 CLEARbit(r700
->SPI_INTERP_CONTROL_0
.u32All
, PNT_SPRITE_ENA_bit
);
603 ui
= (unNumOfReg
< ui
) ? ui
: unNumOfReg
;
605 SETfield(r700
->ps
.SQ_PGM_RESOURCES_PS
.u32All
, ui
, NUM_GPRS_shift
, NUM_GPRS_mask
);
607 CLEARbit(r700
->ps
.SQ_PGM_RESOURCES_PS
.u32All
, UNCACHED_FIRST_INST_bit
);
609 if(fp
->r700Shader
.uStackSize
) /* we don't use branch for now, it should be zero. */
611 SETfield(r700
->ps
.SQ_PGM_RESOURCES_PS
.u32All
, fp
->r700Shader
.uStackSize
,
612 STACK_SIZE_shift
, STACK_SIZE_mask
);
615 SETfield(r700
->ps
.SQ_PGM_EXPORTS_PS
.u32All
, fp
->r700Shader
.exportMode
,
616 EXPORT_MODE_shift
, EXPORT_MODE_mask
);
619 struct r700_vertex_program_cont
*vpc
=
620 (struct r700_vertex_program_cont
*)ctx
->VertexProgram
._Current
;
621 GLbitfield OutputsWritten
= vpc
->mesa_program
.Base
.OutputsWritten
;
623 for(ui
= 0; ui
< R700_MAX_SHADER_EXPORTS
; ui
++)
624 r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
= 0;
626 unBit
= 1 << FRAG_ATTRIB_WPOS
;
627 if(mesa_fp
->Base
.InputsRead
& unBit
)
629 ui
= pAsm
->uiFP_AttributeMap
[FRAG_ATTRIB_WPOS
];
630 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, SEL_CENTROID_bit
);
631 SETfield(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, ui
,
632 SEMANTIC_shift
, SEMANTIC_mask
);
633 if (r700
->SPI_INTERP_CONTROL_0
.u32All
& FLAT_SHADE_ENA_bit
)
634 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, FLAT_SHADE_bit
);
636 CLEARbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, FLAT_SHADE_bit
);
639 unBit
= 1 << VERT_RESULT_COL0
;
640 if(OutputsWritten
& unBit
)
642 ui
= pAsm
->uiFP_AttributeMap
[FRAG_ATTRIB_COL0
];
643 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, SEL_CENTROID_bit
);
644 SETfield(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, ui
,
645 SEMANTIC_shift
, SEMANTIC_mask
);
646 if (r700
->SPI_INTERP_CONTROL_0
.u32All
& FLAT_SHADE_ENA_bit
)
647 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, FLAT_SHADE_bit
);
649 CLEARbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, FLAT_SHADE_bit
);
652 unBit
= 1 << VERT_RESULT_COL1
;
653 if(OutputsWritten
& unBit
)
655 ui
= pAsm
->uiFP_AttributeMap
[FRAG_ATTRIB_COL1
];
656 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, SEL_CENTROID_bit
);
657 SETfield(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, ui
,
658 SEMANTIC_shift
, SEMANTIC_mask
);
659 if (r700
->SPI_INTERP_CONTROL_0
.u32All
& FLAT_SHADE_ENA_bit
)
660 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, FLAT_SHADE_bit
);
662 CLEARbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, FLAT_SHADE_bit
);
665 unBit
= 1 << VERT_RESULT_FOGC
;
666 if(OutputsWritten
& unBit
)
668 ui
= pAsm
->uiFP_AttributeMap
[FRAG_ATTRIB_FOGC
];
669 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, SEL_CENTROID_bit
);
670 SETfield(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, ui
,
671 SEMANTIC_shift
, SEMANTIC_mask
);
672 if (r700
->SPI_INTERP_CONTROL_0
.u32All
& FLAT_SHADE_ENA_bit
)
673 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, FLAT_SHADE_bit
);
675 CLEARbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, FLAT_SHADE_bit
);
680 GLboolean coord_replace
= ctx
->Point
.PointSprite
&& ctx
->Point
.CoordReplace
[i
];
681 unBit
= 1 << (VERT_RESULT_TEX0
+ i
);
682 if ((OutputsWritten
& unBit
) || coord_replace
)
684 ui
= pAsm
->uiFP_AttributeMap
[FRAG_ATTRIB_TEX0
+ i
];
685 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, SEL_CENTROID_bit
);
686 SETfield(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, ui
,
687 SEMANTIC_shift
, SEMANTIC_mask
);
688 CLEARbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, FLAT_SHADE_bit
);
689 /* ARB_point_sprite */
692 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, PT_SPRITE_TEX_bit
);
697 unBit
= 1 << FRAG_ATTRIB_FACE
;
698 if(mesa_fp
->Base
.InputsRead
& unBit
)
700 ui
= pAsm
->uiFP_AttributeMap
[FRAG_ATTRIB_FACE
];
701 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, SEL_CENTROID_bit
);
702 SETfield(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, ui
,
703 SEMANTIC_shift
, SEMANTIC_mask
);
704 if (r700
->SPI_INTERP_CONTROL_0
.u32All
& FLAT_SHADE_ENA_bit
)
705 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, FLAT_SHADE_bit
);
707 CLEARbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, FLAT_SHADE_bit
);
709 unBit
= 1 << FRAG_ATTRIB_PNTC
;
710 if(mesa_fp
->Base
.InputsRead
& unBit
)
712 ui
= pAsm
->uiFP_AttributeMap
[FRAG_ATTRIB_PNTC
];
713 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, SEL_CENTROID_bit
);
714 SETfield(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, ui
,
715 SEMANTIC_shift
, SEMANTIC_mask
);
716 if (r700
->SPI_INTERP_CONTROL_0
.u32All
& FLAT_SHADE_ENA_bit
)
717 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, FLAT_SHADE_bit
);
719 CLEARbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, FLAT_SHADE_bit
);
720 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, PT_SPRITE_TEX_bit
);
726 for(i
=VERT_RESULT_VAR0
; i
<VERT_RESULT_MAX
; i
++)
729 if(OutputsWritten
& unBit
)
731 ui
= pAsm
->uiFP_AttributeMap
[i
-VERT_RESULT_VAR0
+FRAG_ATTRIB_VAR0
];
732 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, SEL_CENTROID_bit
);
733 SETfield(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, ui
,
734 SEMANTIC_shift
, SEMANTIC_mask
);
735 if (r700
->SPI_INTERP_CONTROL_0
.u32All
& FLAT_SHADE_ENA_bit
)
736 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, FLAT_SHADE_bit
);
738 CLEARbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, FLAT_SHADE_bit
);
742 exportCount
= (r700
->ps
.SQ_PGM_EXPORTS_PS
.u32All
& EXPORT_MODE_mask
) / (1 << EXPORT_MODE_shift
);
743 if (r700
->CB_SHADER_CONTROL
.u32All
!= ((1 << exportCount
) - 1))
745 R600_STATECHANGE(context
, cb
);
746 r700
->CB_SHADER_CONTROL
.u32All
= (1 << exportCount
) - 1;
749 /* sent out shader constants. */
750 paramList
= fp
->mesa_program
.Base
.Parameters
;
752 if(NULL
!= paramList
)
754 _mesa_load_state_parameters(ctx
, paramList
);
756 if (paramList
->NumParameters
> R700_MAX_DX9_CONSTS
)
759 R600_STATECHANGE(context
, ps_consts
);
761 r700
->ps
.num_consts
= paramList
->NumParameters
;
763 unNumParamData
= paramList
->NumParameters
;
765 for(ui
=0; ui
<unNumParamData
; ui
++) {
766 r700
->ps
.consts
[ui
][0].f32All
= paramList
->ParameterValues
[ui
][0];
767 r700
->ps
.consts
[ui
][1].f32All
= paramList
->ParameterValues
[ui
][1];
768 r700
->ps
.consts
[ui
][2].f32All
= paramList
->ParameterValues
[ui
][2];
769 r700
->ps
.consts
[ui
][3].f32All
= paramList
->ParameterValues
[ui
][3];
772 r700
->ps
.num_consts
= 0;
774 COMPILED_SUB
* pCompiledSub
;
776 GLuint unConstOffset
= r700
->ps
.num_consts
;
777 for(ui
=0; ui
<pAsm
->unNumPresub
; ui
++)
779 pCompiledSub
= pAsm
->presubs
[ui
].pCompiledSub
;
781 r700
->ps
.num_consts
+= pCompiledSub
->NumParameters
;
783 for(uj
=0; uj
<pCompiledSub
->NumParameters
; uj
++)
785 r700
->ps
.consts
[uj
+ unConstOffset
][0].f32All
= pCompiledSub
->ParameterValues
[uj
][0];
786 r700
->ps
.consts
[uj
+ unConstOffset
][1].f32All
= pCompiledSub
->ParameterValues
[uj
][1];
787 r700
->ps
.consts
[uj
+ unConstOffset
][2].f32All
= pCompiledSub
->ParameterValues
[uj
][2];
788 r700
->ps
.consts
[uj
+ unConstOffset
][3].f32All
= pCompiledSub
->ParameterValues
[uj
][3];
790 unConstOffset
+= pCompiledSub
->NumParameters
;