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 "shader/prog_parameter.h"
36 #include "shader/prog_statevars.h"
37 #include "shader/program.h"
39 #include "r600_context.h"
40 #include "r600_cmdbuf.h"
42 #include "r700_fragprog.h"
44 #include "r700_debug.h"
46 void insert_wpos_code(GLcontext
*ctx
, struct gl_fragment_program
*fprog
)
48 static const gl_state_index winstate
[STATE_LENGTH
]
49 = { STATE_INTERNAL
, STATE_FB_SIZE
, 0, 0, 0};
50 struct prog_instruction
*newInst
, *inst
;
51 GLint win_size
; /* state reference */
52 GLuint wpos_temp
; /* temp register */
55 /* PARAM win_size = STATE_FB_SIZE */
56 win_size
= _mesa_add_state_reference(fprog
->Base
.Parameters
, winstate
);
58 wpos_temp
= fprog
->Base
.NumTemporaries
++;
60 /* scan program where WPOS is used and replace with wpos_temp */
61 inst
= fprog
->Base
.Instructions
;
62 for (i
= 0; i
< fprog
->Base
.NumInstructions
; i
++) {
63 for (j
=0; j
< 3; j
++) {
64 if(inst
->SrcReg
[j
].File
== PROGRAM_INPUT
&&
65 inst
->SrcReg
[j
].Index
== FRAG_ATTRIB_WPOS
) {
66 inst
->SrcReg
[j
].File
= PROGRAM_TEMPORARY
;
67 inst
->SrcReg
[j
].Index
= wpos_temp
;
73 _mesa_insert_instructions(&(fprog
->Base
), 0, 1);
75 newInst
= fprog
->Base
.Instructions
;
77 * wpos_temp.xyzw = wpos.x-yzw + winsize.0y00 */
78 newInst
[0].Opcode
= OPCODE_ADD
;
79 newInst
[0].DstReg
.File
= PROGRAM_TEMPORARY
;
80 newInst
[0].DstReg
.Index
= wpos_temp
;
81 newInst
[0].DstReg
.WriteMask
= WRITEMASK_XYZW
;
83 newInst
[0].SrcReg
[0].File
= PROGRAM_INPUT
;
84 newInst
[0].SrcReg
[0].Index
= FRAG_ATTRIB_WPOS
;
85 newInst
[0].SrcReg
[0].Swizzle
= SWIZZLE_XYZW
;
86 newInst
[0].SrcReg
[0].Negate
= NEGATE_Y
;
88 newInst
[0].SrcReg
[1].File
= PROGRAM_STATE_VAR
;
89 newInst
[0].SrcReg
[1].Index
= win_size
;
90 newInst
[0].SrcReg
[1].Swizzle
= MAKE_SWIZZLE4(SWIZZLE_ZERO
, SWIZZLE_Y
, SWIZZLE_ZERO
, SWIZZLE_ZERO
);
94 //TODO : Validate FP input with VP output.
95 void Map_Fragment_Program(r700_AssemblerBase
*pAsm
,
96 struct gl_fragment_program
*mesa_fp
,
103 /* match fp inputs with vp exports. */
104 struct r700_vertex_program_cont
*vpc
=
105 (struct r700_vertex_program_cont
*)ctx
->VertexProgram
._Current
;
106 GLbitfield OutputsWritten
= vpc
->mesa_program
.Base
.OutputsWritten
;
108 pAsm
->number_used_registers
= 0;
110 //Input mapping : mesa_fp->Base.InputsRead set the flag, set in
111 //The flags parsed in parse_attrib_binding. FRAG_ATTRIB_COLx, FRAG_ATTRIB_TEXx, ...
112 //MUST match order in Map_Vertex_Output
113 unBit
= 1 << FRAG_ATTRIB_WPOS
;
114 if(mesa_fp
->Base
.InputsRead
& unBit
)
116 pAsm
->uiFP_AttributeMap
[FRAG_ATTRIB_WPOS
] = pAsm
->number_used_registers
++;
119 unBit
= 1 << VERT_RESULT_COL0
;
120 if(OutputsWritten
& unBit
)
122 pAsm
->uiFP_AttributeMap
[FRAG_ATTRIB_COL0
] = pAsm
->number_used_registers
++;
125 unBit
= 1 << VERT_RESULT_COL1
;
126 if(OutputsWritten
& unBit
)
128 pAsm
->uiFP_AttributeMap
[FRAG_ATTRIB_COL1
] = pAsm
->number_used_registers
++;
131 unBit
= 1 << VERT_RESULT_FOGC
;
132 if(OutputsWritten
& unBit
)
134 pAsm
->uiFP_AttributeMap
[FRAG_ATTRIB_FOGC
] = pAsm
->number_used_registers
++;
139 unBit
= 1 << (VERT_RESULT_TEX0
+ i
);
140 if(OutputsWritten
& unBit
)
142 pAsm
->uiFP_AttributeMap
[FRAG_ATTRIB_TEX0
+ i
] = pAsm
->number_used_registers
++;
146 /* order has been taken care of */
148 for(i
=VERT_RESULT_VAR0
; i
<VERT_RESULT_MAX
; i
++)
151 if(OutputsWritten
& unBit
)
153 pAsm
->uiFP_AttributeMap
[i
-VERT_RESULT_VAR0
+FRAG_ATTRIB_VAR0
] = pAsm
->number_used_registers
++;
157 if( (mesa_fp
->Base
.InputsRead
>> FRAG_ATTRIB_VAR0
) > 0 )
159 struct r700_vertex_program_cont
*vpc
=
160 (struct r700_vertex_program_cont
*)ctx
->VertexProgram
._Current
;
161 struct gl_program_parameter_list
* VsVarying
= vpc
->mesa_program
.Base
.Varying
;
162 struct gl_program_parameter_list
* PsVarying
= mesa_fp
->Base
.Varying
;
163 struct gl_program_parameter
* pVsParam
;
164 struct gl_program_parameter
* pPsParam
;
166 GLuint unMaxVarying
= 0;
168 for(i
=0; i
<VsVarying
->NumParameters
; i
++)
170 pAsm
->uiFP_AttributeMap
[i
+ FRAG_ATTRIB_VAR0
] = 0;
173 for(i
=FRAG_ATTRIB_VAR0
; i
<FRAG_ATTRIB_MAX
; i
++)
176 if(mesa_fp
->Base
.InputsRead
& unBit
)
178 j
= i
- FRAG_ATTRIB_VAR0
;
179 pPsParam
= PsVarying
->Parameters
+ j
;
181 for(k
=0; k
<VsVarying
->NumParameters
; k
++)
183 pVsParam
= VsVarying
->Parameters
+ k
;
185 if( strcmp(pPsParam
->Name
, pVsParam
->Name
) == 0)
187 pAsm
->uiFP_AttributeMap
[i
] = pAsm
->number_used_registers
+ k
;
198 pAsm
->number_used_registers
+= unMaxVarying
+ 1;
201 unBit
= 1 << FRAG_ATTRIB_FACE
;
202 if(mesa_fp
->Base
.InputsRead
& unBit
)
204 pAsm
->uiFP_AttributeMap
[FRAG_ATTRIB_FACE
] = pAsm
->number_used_registers
++;
207 unBit
= 1 << FRAG_ATTRIB_PNTC
;
208 if(mesa_fp
->Base
.InputsRead
& unBit
)
210 pAsm
->uiFP_AttributeMap
[FRAG_ATTRIB_PNTC
] = pAsm
->number_used_registers
++;
213 /* Map temporary registers (GPRs) */
214 pAsm
->starting_temp_register_number
= pAsm
->number_used_registers
;
216 if(mesa_fp
->Base
.NumNativeTemporaries
>= mesa_fp
->Base
.NumTemporaries
)
218 pAsm
->number_used_registers
+= mesa_fp
->Base
.NumNativeTemporaries
;
222 pAsm
->number_used_registers
+= mesa_fp
->Base
.NumTemporaries
;
226 pAsm
->number_of_exports
= 0;
227 pAsm
->number_of_colorandz_exports
= 0; /* don't include stencil and mask out. */
228 pAsm
->starting_export_register_number
= pAsm
->number_used_registers
;
230 for (i
= 0; i
< FRAG_RESULT_MAX
; ++i
)
233 if (mesa_fp
->Base
.OutputsWritten
& unBit
)
235 if (i
== FRAG_RESULT_DEPTH
)
237 pAsm
->depth_export_register_number
= pAsm
->number_used_registers
;
238 pAsm
->pR700Shader
->depthIsExported
= 1;
241 pAsm
->uiFP_OutputMap
[i
] = pAsm
->number_used_registers
++;
242 ++pAsm
->number_of_exports
;
243 ++pAsm
->number_of_colorandz_exports
;
247 pAsm
->pucOutMask
= (unsigned char*) MALLOC(pAsm
->number_of_exports
);
248 for(ui
=0; ui
<pAsm
->number_of_exports
; ui
++)
250 pAsm
->pucOutMask
[ui
] = 0x0;
253 pAsm
->flag_reg_index
= pAsm
->number_used_registers
++;
255 pAsm
->uFirstHelpReg
= pAsm
->number_used_registers
;
258 GLboolean
Find_Instruction_Dependencies_fp(struct r700_fragment_program
*fp
,
259 struct gl_fragment_program
*mesa_fp
)
262 GLint
* puiTEMPwrites
;
263 GLint
* puiTEMPreads
;
264 struct prog_instruction
* pILInst
;
266 struct prog_instruction
* texcoord_DepInst
;
269 puiTEMPwrites
= (GLint
*) MALLOC(sizeof(GLuint
)*mesa_fp
->Base
.NumTemporaries
);
270 puiTEMPreads
= (GLint
*) MALLOC(sizeof(GLuint
)*mesa_fp
->Base
.NumTemporaries
);
272 for(i
=0; i
<mesa_fp
->Base
.NumTemporaries
; i
++)
274 puiTEMPwrites
[i
] = -1;
275 puiTEMPreads
[i
] = -1;
278 pInstDeps
= (InstDeps
*)MALLOC(sizeof(InstDeps
)*mesa_fp
->Base
.NumInstructions
);
280 for(i
=0; i
<mesa_fp
->Base
.NumInstructions
; i
++)
282 pInstDeps
[i
].nDstDep
= -1;
283 pILInst
= &(mesa_fp
->Base
.Instructions
[i
]);
286 if(pILInst
->DstReg
.File
== PROGRAM_TEMPORARY
)
288 //Set lastwrite for the temp
289 puiTEMPwrites
[pILInst
->DstReg
.Index
] = i
;
295 if(pILInst
->SrcReg
[j
].File
== PROGRAM_TEMPORARY
)
298 pInstDeps
[i
].nSrcDeps
[j
] = puiTEMPwrites
[pILInst
->SrcReg
[j
].Index
];
300 if(puiTEMPreads
[pILInst
->SrcReg
[j
].Index
] < 0 )
302 puiTEMPreads
[pILInst
->SrcReg
[j
].Index
] = i
;
307 pInstDeps
[i
].nSrcDeps
[j
] = -1;
312 fp
->r700AsmCode
.pInstDeps
= pInstDeps
;
314 //Find dep for tex inst
315 for(i
=0; i
<mesa_fp
->Base
.NumInstructions
; i
++)
317 pILInst
= &(mesa_fp
->Base
.Instructions
[i
]);
319 if(GL_TRUE
== IsTex(pILInst
->Opcode
))
320 { //src0 is the tex coord register, src1 is texunit, src2 is textype
321 nDepInstID
= pInstDeps
[i
].nSrcDeps
[0];
324 texcoord_DepInst
= &(mesa_fp
->Base
.Instructions
[nDepInstID
]);
325 if(GL_TRUE
== IsAlu(texcoord_DepInst
->Opcode
) )
327 pInstDeps
[nDepInstID
].nDstDep
= i
;
328 pInstDeps
[i
].nDstDep
= i
;
330 else if(GL_TRUE
== IsTex(texcoord_DepInst
->Opcode
) )
332 pInstDeps
[i
].nDstDep
= i
;
338 // make sure that we dont overwrite src used earlier
339 nDepInstID
= puiTEMPreads
[pILInst
->DstReg
.Index
];
342 pInstDeps
[i
].nDstDep
= puiTEMPreads
[pILInst
->DstReg
.Index
];
343 texcoord_DepInst
= &(mesa_fp
->Base
.Instructions
[nDepInstID
]);
344 if(GL_TRUE
== IsAlu(texcoord_DepInst
->Opcode
) )
346 pInstDeps
[nDepInstID
].nDstDep
= i
;
360 GLboolean
r700TranslateFragmentShader(struct r700_fragment_program
*fp
,
361 struct gl_fragment_program
*mesa_fp
,
364 GLuint number_of_colors_exported
;
365 GLboolean z_enabled
= GL_FALSE
;
366 GLuint unBit
, shadow_unit
;
368 struct prog_instruction
*inst
;
369 gl_state_index shadow_ambient
[STATE_LENGTH
]
370 = { STATE_INTERNAL
, STATE_SHADOW_AMBIENT
, 0, 0, 0};
373 Init_r700_AssemblerBase( SPT_FP
, &(fp
->r700AsmCode
), &(fp
->r700Shader
) );
375 if(mesa_fp
->Base
.InputsRead
& FRAG_BIT_WPOS
)
377 insert_wpos_code(ctx
, mesa_fp
);
380 /* add/map consts for ARB_shadow_ambient */
381 if(mesa_fp
->Base
.ShadowSamplers
)
383 inst
= mesa_fp
->Base
.Instructions
;
384 for (i
= 0; i
< mesa_fp
->Base
.NumInstructions
; i
++)
386 if(inst
->TexShadow
== 1)
388 shadow_unit
= inst
->TexSrcUnit
;
389 shadow_ambient
[2] = shadow_unit
;
390 fp
->r700AsmCode
.shadow_regs
[shadow_unit
] =
391 _mesa_add_state_reference(mesa_fp
->Base
.Parameters
, shadow_ambient
);
397 Map_Fragment_Program(&(fp
->r700AsmCode
), mesa_fp
, ctx
);
399 if( GL_FALSE
== Find_Instruction_Dependencies_fp(fp
, mesa_fp
) )
404 InitShaderProgram(&(fp
->r700AsmCode
));
406 for(i
=0; i
< MAX_SAMPLERS
; i
++)
408 fp
->r700AsmCode
.SamplerUnits
[i
] = fp
->mesa_program
.Base
.SamplerUnits
[i
];
411 fp
->r700AsmCode
.unCurNumILInsts
= mesa_fp
->Base
.NumInstructions
;
413 if( GL_FALSE
== AssembleInstr(0,
415 mesa_fp
->Base
.NumInstructions
,
416 &(mesa_fp
->Base
.Instructions
[0]),
417 &(fp
->r700AsmCode
)) )
422 if(GL_FALSE
== Process_Fragment_Exports(&(fp
->r700AsmCode
), mesa_fp
->Base
.OutputsWritten
) )
427 if( GL_FALSE
== RelocProgram(&(fp
->r700AsmCode
), &(mesa_fp
->Base
)) )
432 fp
->r700Shader
.nRegs
= (fp
->r700AsmCode
.number_used_registers
== 0) ? 0
433 : (fp
->r700AsmCode
.number_used_registers
- 1);
435 fp
->r700Shader
.nParamExports
= fp
->r700AsmCode
.number_of_exports
;
437 number_of_colors_exported
= fp
->r700AsmCode
.number_of_colorandz_exports
;
439 unBit
= 1 << FRAG_RESULT_DEPTH
;
440 if(mesa_fp
->Base
.OutputsWritten
& unBit
)
443 number_of_colors_exported
--;
446 /* illegal to set this to 0 */
447 if(number_of_colors_exported
|| z_enabled
)
449 fp
->r700Shader
.exportMode
= number_of_colors_exported
<< 1 | z_enabled
;
453 fp
->r700Shader
.exportMode
= (1 << 1);
456 fp
->translated
= GL_TRUE
;
461 void r700SelectFragmentShader(GLcontext
*ctx
)
463 context_t
*context
= R700_CONTEXT(ctx
);
464 struct r700_fragment_program
*fp
= (struct r700_fragment_program
*)
465 (ctx
->FragmentProgram
._Current
);
466 if (context
->radeon
.radeonScreen
->chip_family
< CHIP_FAMILY_RV770
)
468 fp
->r700AsmCode
.bR6xx
= 1;
471 if (GL_FALSE
== fp
->translated
)
472 r700TranslateFragmentShader(fp
, &(fp
->mesa_program
), ctx
);
475 void * r700GetActiveFpShaderBo(GLcontext
* ctx
)
477 struct r700_fragment_program
*fp
= (struct r700_fragment_program
*)
478 (ctx
->FragmentProgram
._Current
);
483 GLboolean
r700SetupFragmentProgram(GLcontext
* ctx
)
485 context_t
*context
= R700_CONTEXT(ctx
);
486 R700_CHIP_CONTEXT
*r700
= (R700_CHIP_CONTEXT
*)(&context
->hw
);
487 struct r700_fragment_program
*fp
= (struct r700_fragment_program
*)
488 (ctx
->FragmentProgram
._Current
);
489 r700_AssemblerBase
*pAsm
= &(fp
->r700AsmCode
);
490 struct gl_fragment_program
*mesa_fp
= &(fp
->mesa_program
);
491 struct gl_program_parameter_list
*paramList
;
492 unsigned int unNumParamData
;
494 unsigned int unNumOfReg
;
497 GLboolean point_sprite
= GL_FALSE
;
499 if(GL_FALSE
== fp
->loaded
)
501 if(fp
->r700Shader
.bNeedsAssembly
== GL_TRUE
)
503 Assemble( &(fp
->r700Shader
) );
509 (GLvoid
*)(fp
->r700Shader
.pProgram
),
510 fp
->r700Shader
.uShaderBinaryDWORDSize
,
513 fp
->loaded
= GL_TRUE
;
516 DumpHwBinary(DUMP_PIXEL_SHADER
, (GLvoid
*)(fp
->r700Shader
.pProgram
),
517 fp
->r700Shader
.uShaderBinaryDWORDSize
);
519 /* TODO : enable this after MemUse fixed *=
520 (context->chipobj.MemUse)(context, fp->shadercode.buf->id);
523 R600_STATECHANGE(context
, ps
);
525 r700
->ps
.SQ_PGM_RESOURCES_PS
.u32All
= 0;
526 SETbit(r700
->ps
.SQ_PGM_RESOURCES_PS
.u32All
, PGM_RESOURCES__PRIME_CACHE_ON_DRAW_bit
);
528 r700
->ps
.SQ_PGM_START_PS
.u32All
= 0; /* set from buffer obj */
530 R600_STATECHANGE(context
, spi
);
532 unNumOfReg
= fp
->r700Shader
.nRegs
+ 1;
534 ui
= (r700
->SPI_PS_IN_CONTROL_0
.u32All
& NUM_INTERP_mask
) / (1 << NUM_INTERP_shift
);
536 /* PS uses fragment.position */
537 if (mesa_fp
->Base
.InputsRead
& (1 << FRAG_ATTRIB_WPOS
))
540 SETfield(r700
->SPI_PS_IN_CONTROL_0
.u32All
, ui
, NUM_INTERP_shift
, NUM_INTERP_mask
);
541 SETfield(r700
->SPI_PS_IN_CONTROL_0
.u32All
, CENTERS_ONLY
, BARYC_SAMPLE_CNTL_shift
, BARYC_SAMPLE_CNTL_mask
);
542 SETbit(r700
->SPI_PS_IN_CONTROL_0
.u32All
, POSITION_ENA_bit
);
543 SETbit(r700
->SPI_INPUT_Z
.u32All
, PROVIDE_Z_TO_SPI_bit
);
547 CLEARbit(r700
->SPI_PS_IN_CONTROL_0
.u32All
, POSITION_ENA_bit
);
548 CLEARbit(r700
->SPI_INPUT_Z
.u32All
, PROVIDE_Z_TO_SPI_bit
);
551 if (mesa_fp
->Base
.InputsRead
& (1 << FRAG_ATTRIB_FACE
))
554 SETfield(r700
->SPI_PS_IN_CONTROL_0
.u32All
, ui
, NUM_INTERP_shift
, NUM_INTERP_mask
);
555 SETbit(r700
->SPI_PS_IN_CONTROL_1
.u32All
, FRONT_FACE_ENA_bit
);
556 SETbit(r700
->SPI_PS_IN_CONTROL_1
.u32All
, FRONT_FACE_ALL_BITS_bit
);
557 SETfield(r700
->SPI_PS_IN_CONTROL_1
.u32All
, pAsm
->uiFP_AttributeMap
[FRAG_ATTRIB_FACE
], FRONT_FACE_ADDR_shift
, FRONT_FACE_ADDR_mask
);
561 CLEARbit(r700
->SPI_PS_IN_CONTROL_1
.u32All
, FRONT_FACE_ENA_bit
);
564 /* see if we need any point_sprite replacements, also increase num_interp
565 * as there's no vp output for them */
566 for (i
= FRAG_ATTRIB_TEX0
; i
<= FRAG_ATTRIB_TEX7
; i
++)
568 if(ctx
->Point
.CoordReplace
[i
- FRAG_ATTRIB_TEX0
] == GL_TRUE
) {
570 point_sprite
= GL_TRUE
;
574 if( mesa_fp
->Base
.InputsRead
& (1 << FRAG_ATTRIB_PNTC
))
577 if ((mesa_fp
->Base
.InputsRead
& (1 << FRAG_ATTRIB_PNTC
)) || point_sprite
)
579 SETfield(r700
->SPI_PS_IN_CONTROL_0
.u32All
, ui
, NUM_INTERP_shift
, NUM_INTERP_mask
);
580 SETbit(r700
->SPI_INTERP_CONTROL_0
.u32All
, PNT_SPRITE_ENA_bit
);
581 SETfield(r700
->SPI_INTERP_CONTROL_0
.u32All
, SPI_PNT_SPRITE_SEL_S
, PNT_SPRITE_OVRD_X_shift
, PNT_SPRITE_OVRD_X_mask
);
582 SETfield(r700
->SPI_INTERP_CONTROL_0
.u32All
, SPI_PNT_SPRITE_SEL_T
, PNT_SPRITE_OVRD_Y_shift
, PNT_SPRITE_OVRD_Y_mask
);
583 SETfield(r700
->SPI_INTERP_CONTROL_0
.u32All
, SPI_PNT_SPRITE_SEL_0
, PNT_SPRITE_OVRD_Z_shift
, PNT_SPRITE_OVRD_Z_mask
);
584 SETfield(r700
->SPI_INTERP_CONTROL_0
.u32All
, SPI_PNT_SPRITE_SEL_1
, PNT_SPRITE_OVRD_W_shift
, PNT_SPRITE_OVRD_W_mask
);
585 if(ctx
->Point
.SpriteOrigin
== GL_LOWER_LEFT
)
586 SETbit(r700
->SPI_INTERP_CONTROL_0
.u32All
, PNT_SPRITE_TOP_1_bit
);
588 CLEARbit(r700
->SPI_INTERP_CONTROL_0
.u32All
, PNT_SPRITE_TOP_1_bit
);
592 CLEARbit(r700
->SPI_INTERP_CONTROL_0
.u32All
, PNT_SPRITE_ENA_bit
);
596 ui
= (unNumOfReg
< ui
) ? ui
: unNumOfReg
;
598 SETfield(r700
->ps
.SQ_PGM_RESOURCES_PS
.u32All
, ui
, NUM_GPRS_shift
, NUM_GPRS_mask
);
600 CLEARbit(r700
->ps
.SQ_PGM_RESOURCES_PS
.u32All
, UNCACHED_FIRST_INST_bit
);
602 if(fp
->r700Shader
.uStackSize
) /* we don't use branch for now, it should be zero. */
604 SETfield(r700
->ps
.SQ_PGM_RESOURCES_PS
.u32All
, fp
->r700Shader
.uStackSize
,
605 STACK_SIZE_shift
, STACK_SIZE_mask
);
608 SETfield(r700
->ps
.SQ_PGM_EXPORTS_PS
.u32All
, fp
->r700Shader
.exportMode
,
609 EXPORT_MODE_shift
, EXPORT_MODE_mask
);
612 struct r700_vertex_program_cont
*vpc
=
613 (struct r700_vertex_program_cont
*)ctx
->VertexProgram
._Current
;
614 GLbitfield OutputsWritten
= vpc
->mesa_program
.Base
.OutputsWritten
;
616 for(ui
= 0; ui
< R700_MAX_SHADER_EXPORTS
; ui
++)
617 r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
= 0;
619 unBit
= 1 << FRAG_ATTRIB_WPOS
;
620 if(mesa_fp
->Base
.InputsRead
& unBit
)
622 ui
= pAsm
->uiFP_AttributeMap
[FRAG_ATTRIB_WPOS
];
623 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, SEL_CENTROID_bit
);
624 SETfield(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, ui
,
625 SEMANTIC_shift
, SEMANTIC_mask
);
626 if (r700
->SPI_INTERP_CONTROL_0
.u32All
& FLAT_SHADE_ENA_bit
)
627 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, FLAT_SHADE_bit
);
629 CLEARbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, FLAT_SHADE_bit
);
632 unBit
= 1 << VERT_RESULT_COL0
;
633 if(OutputsWritten
& unBit
)
635 ui
= pAsm
->uiFP_AttributeMap
[FRAG_ATTRIB_COL0
];
636 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, SEL_CENTROID_bit
);
637 SETfield(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, ui
,
638 SEMANTIC_shift
, SEMANTIC_mask
);
639 if (r700
->SPI_INTERP_CONTROL_0
.u32All
& FLAT_SHADE_ENA_bit
)
640 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, FLAT_SHADE_bit
);
642 CLEARbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, FLAT_SHADE_bit
);
645 unBit
= 1 << VERT_RESULT_COL1
;
646 if(OutputsWritten
& unBit
)
648 ui
= pAsm
->uiFP_AttributeMap
[FRAG_ATTRIB_COL1
];
649 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, SEL_CENTROID_bit
);
650 SETfield(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, ui
,
651 SEMANTIC_shift
, SEMANTIC_mask
);
652 if (r700
->SPI_INTERP_CONTROL_0
.u32All
& FLAT_SHADE_ENA_bit
)
653 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, FLAT_SHADE_bit
);
655 CLEARbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, FLAT_SHADE_bit
);
658 unBit
= 1 << VERT_RESULT_FOGC
;
659 if(OutputsWritten
& unBit
)
661 ui
= pAsm
->uiFP_AttributeMap
[FRAG_ATTRIB_FOGC
];
662 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, SEL_CENTROID_bit
);
663 SETfield(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, ui
,
664 SEMANTIC_shift
, SEMANTIC_mask
);
665 if (r700
->SPI_INTERP_CONTROL_0
.u32All
& FLAT_SHADE_ENA_bit
)
666 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, FLAT_SHADE_bit
);
668 CLEARbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, FLAT_SHADE_bit
);
673 unBit
= 1 << (VERT_RESULT_TEX0
+ i
);
674 if((OutputsWritten
& unBit
) || (ctx
->Point
.CoordReplace
[i
] == GL_TRUE
))
676 ui
= pAsm
->uiFP_AttributeMap
[FRAG_ATTRIB_TEX0
+ i
];
677 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, SEL_CENTROID_bit
);
678 SETfield(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, ui
,
679 SEMANTIC_shift
, SEMANTIC_mask
);
680 CLEARbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, FLAT_SHADE_bit
);
681 /* ARB_point_sprite */
682 if(ctx
->Point
.CoordReplace
[i
] == GL_TRUE
)
684 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, PT_SPRITE_TEX_bit
);
689 unBit
= 1 << FRAG_ATTRIB_FACE
;
690 if(mesa_fp
->Base
.InputsRead
& unBit
)
692 ui
= pAsm
->uiFP_AttributeMap
[FRAG_ATTRIB_FACE
];
693 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, SEL_CENTROID_bit
);
694 SETfield(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, ui
,
695 SEMANTIC_shift
, SEMANTIC_mask
);
696 if (r700
->SPI_INTERP_CONTROL_0
.u32All
& FLAT_SHADE_ENA_bit
)
697 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, FLAT_SHADE_bit
);
699 CLEARbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, FLAT_SHADE_bit
);
701 unBit
= 1 << FRAG_ATTRIB_PNTC
;
702 if(mesa_fp
->Base
.InputsRead
& unBit
)
704 ui
= pAsm
->uiFP_AttributeMap
[FRAG_ATTRIB_PNTC
];
705 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, SEL_CENTROID_bit
);
706 SETfield(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, ui
,
707 SEMANTIC_shift
, SEMANTIC_mask
);
708 if (r700
->SPI_INTERP_CONTROL_0
.u32All
& FLAT_SHADE_ENA_bit
)
709 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, FLAT_SHADE_bit
);
711 CLEARbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, FLAT_SHADE_bit
);
712 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, PT_SPRITE_TEX_bit
);
718 for(i
=VERT_RESULT_VAR0
; i
<VERT_RESULT_MAX
; i
++)
721 if(OutputsWritten
& unBit
)
723 ui
= pAsm
->uiFP_AttributeMap
[i
-VERT_RESULT_VAR0
+FRAG_ATTRIB_VAR0
];
724 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, SEL_CENTROID_bit
);
725 SETfield(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, ui
,
726 SEMANTIC_shift
, SEMANTIC_mask
);
727 if (r700
->SPI_INTERP_CONTROL_0
.u32All
& FLAT_SHADE_ENA_bit
)
728 SETbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, FLAT_SHADE_bit
);
730 CLEARbit(r700
->SPI_PS_INPUT_CNTL
[ui
].u32All
, FLAT_SHADE_bit
);
734 exportCount
= (r700
->ps
.SQ_PGM_EXPORTS_PS
.u32All
& EXPORT_MODE_mask
) / (1 << EXPORT_MODE_shift
);
735 if (r700
->CB_SHADER_CONTROL
.u32All
!= ((1 << exportCount
) - 1))
737 R600_STATECHANGE(context
, cb
);
738 r700
->CB_SHADER_CONTROL
.u32All
= (1 << exportCount
) - 1;
741 /* sent out shader constants. */
742 paramList
= fp
->mesa_program
.Base
.Parameters
;
744 if(NULL
!= paramList
)
746 _mesa_load_state_parameters(ctx
, paramList
);
748 if (paramList
->NumParameters
> R700_MAX_DX9_CONSTS
)
751 R600_STATECHANGE(context
, ps_consts
);
753 r700
->ps
.num_consts
= paramList
->NumParameters
;
755 unNumParamData
= paramList
->NumParameters
;
757 for(ui
=0; ui
<unNumParamData
; ui
++) {
758 r700
->ps
.consts
[ui
][0].f32All
= paramList
->ParameterValues
[ui
][0];
759 r700
->ps
.consts
[ui
][1].f32All
= paramList
->ParameterValues
[ui
][1];
760 r700
->ps
.consts
[ui
][2].f32All
= paramList
->ParameterValues
[ui
][2];
761 r700
->ps
.consts
[ui
][3].f32All
= paramList
->ParameterValues
[ui
][3];
764 r700
->ps
.num_consts
= 0;
766 COMPILED_SUB
* pCompiledSub
;
768 GLuint unConstOffset
= r700
->ps
.num_consts
;
769 for(ui
=0; ui
<pAsm
->unNumPresub
; ui
++)
771 pCompiledSub
= pAsm
->presubs
[ui
].pCompiledSub
;
773 r700
->ps
.num_consts
+= pCompiledSub
->NumParameters
;
775 for(uj
=0; uj
<pCompiledSub
->NumParameters
; uj
++)
777 r700
->ps
.consts
[uj
+ unConstOffset
][0].f32All
= pCompiledSub
->ParameterValues
[uj
][0];
778 r700
->ps
.consts
[uj
+ unConstOffset
][1].f32All
= pCompiledSub
->ParameterValues
[uj
][1];
779 r700
->ps
.consts
[uj
+ unConstOffset
][2].f32All
= pCompiledSub
->ParameterValues
[uj
][2];
780 r700
->ps
.consts
[uj
+ unConstOffset
][3].f32All
= pCompiledSub
->ParameterValues
[uj
][3];
782 unConstOffset
+= pCompiledSub
->NumParameters
;