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 context_t
*context
= R700_CONTEXT(ctx
);
366 R700_CHIP_CONTEXT
*r700
= (R700_CHIP_CONTEXT
*)(&context
->hw
);
368 GLuint number_of_colors_exported
;
369 GLboolean z_enabled
= GL_FALSE
;
370 GLuint unBit
, shadow_unit
;
372 struct prog_instruction
*inst
;
373 gl_state_index shadow_ambient
[STATE_LENGTH
]
374 = { STATE_INTERNAL
, STATE_SHADOW_AMBIENT
, 0, 0, 0};
377 Init_r700_AssemblerBase( SPT_FP
, &(fp
->r700AsmCode
), &(fp
->r700Shader
) );
379 if(GL_TRUE
== r700
->bShaderUseMemConstant
)
381 fp
->r700AsmCode
.bUseMemConstant
= GL_TRUE
;
385 fp
->r700AsmCode
.bUseMemConstant
= GL_FALSE
;
388 fp
->r700AsmCode
.unAsic
= 7;
390 if(mesa_fp
->Base
.InputsRead
& FRAG_BIT_WPOS
)
392 insert_wpos_code(ctx
, mesa_fp
);
395 /* add/map consts for ARB_shadow_ambient */
396 if(mesa_fp
->Base
.ShadowSamplers
)
398 inst
= mesa_fp
->Base
.Instructions
;
399 for (i
= 0; i
< mesa_fp
->Base
.NumInstructions
; i
++)
401 if(inst
->TexShadow
== 1)
403 shadow_unit
= inst
->TexSrcUnit
;
404 shadow_ambient
[2] = shadow_unit
;
405 fp
->r700AsmCode
.shadow_regs
[shadow_unit
] =
406 _mesa_add_state_reference(mesa_fp
->Base
.Parameters
, shadow_ambient
);
412 Map_Fragment_Program(&(fp
->r700AsmCode
), mesa_fp
, ctx
);
414 if( GL_FALSE
== Find_Instruction_Dependencies_fp(fp
, mesa_fp
) )
419 InitShaderProgram(&(fp
->r700AsmCode
));
421 for(i
=0; i
< MAX_SAMPLERS
; i
++)
423 fp
->r700AsmCode
.SamplerUnits
[i
] = fp
->mesa_program
.Base
.SamplerUnits
[i
];
426 fp
->r700AsmCode
.unCurNumILInsts
= mesa_fp
->Base
.NumInstructions
;
428 if( GL_FALSE
== AssembleInstr(0,
430 mesa_fp
->Base
.NumInstructions
,
431 &(mesa_fp
->Base
.Instructions
[0]),
432 &(fp
->r700AsmCode
)) )
437 if(GL_FALSE
== Process_Fragment_Exports(&(fp
->r700AsmCode
), mesa_fp
->Base
.OutputsWritten
) )
442 if( GL_FALSE
== RelocProgram(&(fp
->r700AsmCode
), &(mesa_fp
->Base
)) )
447 fp
->r700Shader
.nRegs
= (fp
->r700AsmCode
.number_used_registers
== 0) ? 0
448 : (fp
->r700AsmCode
.number_used_registers
- 1);
450 fp
->r700Shader
.nParamExports
= fp
->r700AsmCode
.number_of_exports
;
452 number_of_colors_exported
= fp
->r700AsmCode
.number_of_colorandz_exports
;
454 unBit
= 1 << FRAG_RESULT_DEPTH
;
455 if(mesa_fp
->Base
.OutputsWritten
& unBit
)
458 number_of_colors_exported
--;
461 /* illegal to set this to 0 */
462 if(number_of_colors_exported
|| z_enabled
)
464 fp
->r700Shader
.exportMode
= number_of_colors_exported
<< 1 | z_enabled
;
468 fp
->r700Shader
.exportMode
= (1 << 1);
471 fp
->translated
= GL_TRUE
;
476 void r700SelectFragmentShader(GLcontext
*ctx
)
478 context_t
*context
= R700_CONTEXT(ctx
);
479 struct r700_fragment_program
*fp
= (struct r700_fragment_program
*)
480 (ctx
->FragmentProgram
._Current
);
481 if (context
->radeon
.radeonScreen
->chip_family
< CHIP_FAMILY_RV770
)
483 fp
->r700AsmCode
.bR6xx
= 1;
486 if (GL_FALSE
== fp
->translated
)
487 r700TranslateFragmentShader(fp
, &(fp
->mesa_program
), ctx
);
490 void * r700GetActiveFpShaderBo(GLcontext
* ctx
)
492 struct r700_fragment_program
*fp
= (struct r700_fragment_program
*)
493 (ctx
->FragmentProgram
._Current
);
498 void * r700GetActiveFpShaderConstBo(GLcontext
* ctx
)
500 struct r700_fragment_program
*fp
= (struct r700_fragment_program
*)
501 (ctx
->FragmentProgram
._Current
);
506 GLboolean
r700SetupFragmentProgram(GLcontext
* ctx
)
508 context_t
*context
= R700_CONTEXT(ctx
);
509 R700_CHIP_CONTEXT
*r700
= (R700_CHIP_CONTEXT
*)(&context
->hw
);
510 struct r700_fragment_program
*fp
= (struct r700_fragment_program
*)
511 (ctx
->FragmentProgram
._Current
);
512 r700_AssemblerBase
*pAsm
= &(fp
->r700AsmCode
);
513 struct gl_fragment_program
*mesa_fp
= &(fp
->mesa_program
);
514 struct gl_program_parameter_list
*paramList
;
515 unsigned int unNumParamData
;
517 unsigned int unNumOfReg
;
520 GLboolean point_sprite
= GL_FALSE
;
522 if(GL_FALSE
== fp
->loaded
)
524 if(fp
->r700Shader
.bNeedsAssembly
== GL_TRUE
)
526 Assemble( &(fp
->r700Shader
) );
532 (GLvoid
*)(fp
->r700Shader
.pProgram
),
533 fp
->r700Shader
.uShaderBinaryDWORDSize
,
536 fp
->loaded
= GL_TRUE
;
539 DumpHwBinary(DUMP_PIXEL_SHADER
, (GLvoid
*)(fp
->r700Shader
.pProgram
),
540 fp
->r700Shader
.uShaderBinaryDWORDSize
);
542 /* TODO : enable this after MemUse fixed *=
543 (context->chipobj.MemUse)(context, fp->shadercode.buf->id);
546 R600_STATECHANGE(context
, ps
);
548 r700
->ps
.SQ_PGM_RESOURCES_PS
.u32All
= 0;
549 SETbit(r700
->ps
.SQ_PGM_RESOURCES_PS
.u32All
, PGM_RESOURCES__PRIME_CACHE_ON_DRAW_bit
);
551 r700
->ps
.SQ_PGM_START_PS
.u32All
= 0; /* set from buffer obj */
553 R600_STATECHANGE(context
, spi
);
555 unNumOfReg
= fp
->r700Shader
.nRegs
+ 1;
557 ui
= (r700
->SPI_PS_IN_CONTROL_0
.u32All
& NUM_INTERP_mask
) / (1 << NUM_INTERP_shift
);
559 /* PS uses fragment.position */
560 if (mesa_fp
->Base
.InputsRead
& (1 << FRAG_ATTRIB_WPOS
))
563 SETfield(r700
->SPI_PS_IN_CONTROL_0
.u32All
, ui
, NUM_INTERP_shift
, NUM_INTERP_mask
);
564 SETfield(r700
->SPI_PS_IN_CONTROL_0
.u32All
, CENTERS_ONLY
, BARYC_SAMPLE_CNTL_shift
, BARYC_SAMPLE_CNTL_mask
);
565 SETbit(r700
->SPI_PS_IN_CONTROL_0
.u32All
, POSITION_ENA_bit
);
566 SETbit(r700
->SPI_INPUT_Z
.u32All
, PROVIDE_Z_TO_SPI_bit
);
570 CLEARbit(r700
->SPI_PS_IN_CONTROL_0
.u32All
, POSITION_ENA_bit
);
571 CLEARbit(r700
->SPI_INPUT_Z
.u32All
, PROVIDE_Z_TO_SPI_bit
);
574 if (mesa_fp
->Base
.InputsRead
& (1 << FRAG_ATTRIB_FACE
))
577 SETfield(r700
->SPI_PS_IN_CONTROL_0
.u32All
, ui
, NUM_INTERP_shift
, NUM_INTERP_mask
);
578 SETbit(r700
->SPI_PS_IN_CONTROL_1
.u32All
, FRONT_FACE_ENA_bit
);
579 SETbit(r700
->SPI_PS_IN_CONTROL_1
.u32All
, FRONT_FACE_ALL_BITS_bit
);
580 SETfield(r700
->SPI_PS_IN_CONTROL_1
.u32All
, pAsm
->uiFP_AttributeMap
[FRAG_ATTRIB_FACE
], FRONT_FACE_ADDR_shift
, FRONT_FACE_ADDR_mask
);
584 CLEARbit(r700
->SPI_PS_IN_CONTROL_1
.u32All
, FRONT_FACE_ENA_bit
);
587 /* see if we need any point_sprite replacements, also increase num_interp
588 * as there's no vp output for them */
589 if (ctx
->Point
.PointSprite
)
591 for (i
= FRAG_ATTRIB_TEX0
; i
<= FRAG_ATTRIB_TEX7
; i
++)
593 if (ctx
->Point
.CoordReplace
[i
- FRAG_ATTRIB_TEX0
] == GL_TRUE
)
596 point_sprite
= GL_TRUE
;
601 if( mesa_fp
->Base
.InputsRead
& (1 << FRAG_ATTRIB_PNTC
))
604 if ((mesa_fp
->Base
.InputsRead
& (1 << FRAG_ATTRIB_PNTC
)) || point_sprite
)
606 SETfield(r700
->SPI_PS_IN_CONTROL_0
.u32All
, ui
, NUM_INTERP_shift
, NUM_INTERP_mask
);
607 SETbit(r700
->SPI_INTERP_CONTROL_0
.u32All
, PNT_SPRITE_ENA_bit
);
608 SETfield(r700
->SPI_INTERP_CONTROL_0
.u32All
, SPI_PNT_SPRITE_SEL_S
, PNT_SPRITE_OVRD_X_shift
, PNT_SPRITE_OVRD_X_mask
);
609 SETfield(r700
->SPI_INTERP_CONTROL_0
.u32All
, SPI_PNT_SPRITE_SEL_T
, PNT_SPRITE_OVRD_Y_shift
, PNT_SPRITE_OVRD_Y_mask
);
610 SETfield(r700
->SPI_INTERP_CONTROL_0
.u32All
, SPI_PNT_SPRITE_SEL_0
, PNT_SPRITE_OVRD_Z_shift
, PNT_SPRITE_OVRD_Z_mask
);
611 SETfield(r700
->SPI_INTERP_CONTROL_0
.u32All
, SPI_PNT_SPRITE_SEL_1
, PNT_SPRITE_OVRD_W_shift
, PNT_SPRITE_OVRD_W_mask
);
612 /* Like e.g. viewport and winding, point sprite coordinates are
613 * inverted when rendering to FBO. */
614 if ((ctx
->Point
.SpriteOrigin
== GL_LOWER_LEFT
) == !ctx
->DrawBuffer
->Name
)
615 SETbit(r700
->SPI_INTERP_CONTROL_0
.u32All
, PNT_SPRITE_TOP_1_bit
);
617 CLEARbit(r700
->SPI_INTERP_CONTROL_0
.u32All
, PNT_SPRITE_TOP_1_bit
);
621 CLEARbit(r700
->SPI_INTERP_CONTROL_0
.u32All
, PNT_SPRITE_ENA_bit
);
625 ui
= (unNumOfReg
< ui
) ? ui
: unNumOfReg
;
627 SETfield(r700
->ps
.SQ_PGM_RESOURCES_PS
.u32All
, ui
, NUM_GPRS_shift
, NUM_GPRS_mask
);
629 CLEARbit(r700
->ps
.SQ_PGM_RESOURCES_PS
.u32All
, UNCACHED_FIRST_INST_bit
);
631 if(fp
->r700Shader
.uStackSize
) /* we don't use branch for now, it should be zero. */
633 SETfield(r700
->ps
.SQ_PGM_RESOURCES_PS
.u32All
, fp
->r700Shader
.uStackSize
,
634 STACK_SIZE_shift
, STACK_SIZE_mask
);
637 SETfield(r700
->ps
.SQ_PGM_EXPORTS_PS
.u32All
, fp
->r700Shader
.exportMode
,
638 EXPORT_MODE_shift
, EXPORT_MODE_mask
);
641 struct r700_vertex_program_cont
*vpc
=
642 (struct r700_vertex_program_cont
*)ctx
->VertexProgram
._Current
;
643 GLbitfield OutputsWritten
= vpc
->mesa_program
.Base
.OutputsWritten
;
645 for(ui
= 0; ui
< R700_MAX_SHADER_EXPORTS
; ui
++)
646 r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
= 0;
648 unBit
= 1 << FRAG_ATTRIB_WPOS
;
649 if(mesa_fp
->Base
.InputsRead
& unBit
)
651 ui
= pAsm
->uiFP_AttributeMap
[FRAG_ATTRIB_WPOS
];
652 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, SEL_CENTROID_bit
);
653 SETfield(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, ui
,
654 SEMANTIC_shift
, SEMANTIC_mask
);
655 if (r700
->SPI_INTERP_CONTROL_0
.u32All
& FLAT_SHADE_ENA_bit
)
656 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, FLAT_SHADE_bit
);
658 CLEARbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, FLAT_SHADE_bit
);
661 unBit
= 1 << VERT_RESULT_COL0
;
662 if(OutputsWritten
& unBit
)
664 ui
= pAsm
->uiFP_AttributeMap
[FRAG_ATTRIB_COL0
];
665 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, SEL_CENTROID_bit
);
666 SETfield(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, ui
,
667 SEMANTIC_shift
, SEMANTIC_mask
);
668 if (r700
->SPI_INTERP_CONTROL_0
.u32All
& FLAT_SHADE_ENA_bit
)
669 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, FLAT_SHADE_bit
);
671 CLEARbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, FLAT_SHADE_bit
);
674 unBit
= 1 << VERT_RESULT_COL1
;
675 if(OutputsWritten
& unBit
)
677 ui
= pAsm
->uiFP_AttributeMap
[FRAG_ATTRIB_COL1
];
678 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, SEL_CENTROID_bit
);
679 SETfield(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, ui
,
680 SEMANTIC_shift
, SEMANTIC_mask
);
681 if (r700
->SPI_INTERP_CONTROL_0
.u32All
& FLAT_SHADE_ENA_bit
)
682 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, FLAT_SHADE_bit
);
684 CLEARbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, FLAT_SHADE_bit
);
687 unBit
= 1 << VERT_RESULT_FOGC
;
688 if(OutputsWritten
& unBit
)
690 ui
= pAsm
->uiFP_AttributeMap
[FRAG_ATTRIB_FOGC
];
691 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, SEL_CENTROID_bit
);
692 SETfield(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, ui
,
693 SEMANTIC_shift
, SEMANTIC_mask
);
694 if (r700
->SPI_INTERP_CONTROL_0
.u32All
& FLAT_SHADE_ENA_bit
)
695 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, FLAT_SHADE_bit
);
697 CLEARbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, FLAT_SHADE_bit
);
702 GLboolean coord_replace
= ctx
->Point
.PointSprite
&& ctx
->Point
.CoordReplace
[i
];
703 unBit
= 1 << (VERT_RESULT_TEX0
+ i
);
704 if ((OutputsWritten
& unBit
) || coord_replace
)
706 ui
= pAsm
->uiFP_AttributeMap
[FRAG_ATTRIB_TEX0
+ i
];
707 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, SEL_CENTROID_bit
);
708 SETfield(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, ui
,
709 SEMANTIC_shift
, SEMANTIC_mask
);
710 CLEARbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, FLAT_SHADE_bit
);
711 /* ARB_point_sprite */
714 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, PT_SPRITE_TEX_bit
);
719 unBit
= 1 << FRAG_ATTRIB_FACE
;
720 if(mesa_fp
->Base
.InputsRead
& unBit
)
722 ui
= pAsm
->uiFP_AttributeMap
[FRAG_ATTRIB_FACE
];
723 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, SEL_CENTROID_bit
);
724 SETfield(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, ui
,
725 SEMANTIC_shift
, SEMANTIC_mask
);
726 if (r700
->SPI_INTERP_CONTROL_0
.u32All
& FLAT_SHADE_ENA_bit
)
727 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, FLAT_SHADE_bit
);
729 CLEARbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, FLAT_SHADE_bit
);
731 unBit
= 1 << FRAG_ATTRIB_PNTC
;
732 if(mesa_fp
->Base
.InputsRead
& unBit
)
734 ui
= pAsm
->uiFP_AttributeMap
[FRAG_ATTRIB_PNTC
];
735 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, SEL_CENTROID_bit
);
736 SETfield(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, ui
,
737 SEMANTIC_shift
, SEMANTIC_mask
);
738 if (r700
->SPI_INTERP_CONTROL_0
.u32All
& FLAT_SHADE_ENA_bit
)
739 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, FLAT_SHADE_bit
);
741 CLEARbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, FLAT_SHADE_bit
);
742 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, PT_SPRITE_TEX_bit
);
748 for(i
=VERT_RESULT_VAR0
; i
<VERT_RESULT_MAX
; i
++)
751 if(OutputsWritten
& unBit
)
753 ui
= pAsm
->uiFP_AttributeMap
[i
-VERT_RESULT_VAR0
+FRAG_ATTRIB_VAR0
];
754 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, SEL_CENTROID_bit
);
755 SETfield(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, ui
,
756 SEMANTIC_shift
, SEMANTIC_mask
);
757 if (r700
->SPI_INTERP_CONTROL_0
.u32All
& FLAT_SHADE_ENA_bit
)
758 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, FLAT_SHADE_bit
);
760 CLEARbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, FLAT_SHADE_bit
);
764 exportCount
= (r700
->ps
.SQ_PGM_EXPORTS_PS
.u32All
& EXPORT_MODE_mask
) / (1 << EXPORT_MODE_shift
);
765 if (r700
->CB_SHADER_CONTROL
.u32All
!= ((1 << exportCount
) - 1))
767 R600_STATECHANGE(context
, cb
);
768 r700
->CB_SHADER_CONTROL
.u32All
= (1 << exportCount
) - 1;
771 /* sent out shader constants. */
772 paramList
= fp
->mesa_program
.Base
.Parameters
;
774 if(NULL
!= paramList
)
776 _mesa_load_state_parameters(ctx
, paramList
);
778 if (paramList
->NumParameters
> R700_MAX_DX9_CONSTS
)
781 R600_STATECHANGE(context
, ps_consts
);
783 r700
->ps
.num_consts
= paramList
->NumParameters
;
785 unNumParamData
= paramList
->NumParameters
;
787 for(ui
=0; ui
<unNumParamData
; ui
++) {
788 r700
->ps
.consts
[ui
][0].f32All
= paramList
->ParameterValues
[ui
][0];
789 r700
->ps
.consts
[ui
][1].f32All
= paramList
->ParameterValues
[ui
][1];
790 r700
->ps
.consts
[ui
][2].f32All
= paramList
->ParameterValues
[ui
][2];
791 r700
->ps
.consts
[ui
][3].f32All
= paramList
->ParameterValues
[ui
][3];
794 /* Load fp constants to gpu */
795 if( (GL_TRUE
== r700
->bShaderUseMemConstant
) && (unNumParamData
> 0) )
799 (GLvoid
*)&(paramList
->ParameterValues
[0][0]),
805 r700
->ps
.num_consts
= 0;
807 COMPILED_SUB
* pCompiledSub
;
809 GLuint unConstOffset
= r700
->ps
.num_consts
;
810 for(ui
=0; ui
<pAsm
->unNumPresub
; ui
++)
812 pCompiledSub
= pAsm
->presubs
[ui
].pCompiledSub
;
814 r700
->ps
.num_consts
+= pCompiledSub
->NumParameters
;
816 for(uj
=0; uj
<pCompiledSub
->NumParameters
; uj
++)
818 r700
->ps
.consts
[uj
+ unConstOffset
][0].f32All
= pCompiledSub
->ParameterValues
[uj
][0];
819 r700
->ps
.consts
[uj
+ unConstOffset
][1].f32All
= pCompiledSub
->ParameterValues
[uj
][1];
820 r700
->ps
.consts
[uj
+ unConstOffset
][2].f32All
= pCompiledSub
->ParameterValues
[uj
][2];
821 r700
->ps
.consts
[uj
+ unConstOffset
][3].f32All
= pCompiledSub
->ParameterValues
[uj
][3];
823 unConstOffset
+= pCompiledSub
->NumParameters
;