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>
33 #include "main/mtypes.h"
34 #include "main/imports.h"
35 #include "shader/prog_parameter.h"
37 #include "radeon_debug.h"
38 #include "r600_context.h"
40 #include "r700_assembler.h"
42 #define USE_CF_FOR_CONTINUE_BREAK 1
43 #define USE_CF_FOR_POP_AFTER 1
45 struct prog_instruction noise1_insts
[12] = {
46 {OPCODE_BGNSUB
, {{13, 0, 1672, 0, 0, 0}, {13, 0, 1672, 0, 0, 0}, {13, 0, 1672, 0, 0, 0}}, {13, 0, 15, 0, 8, 1672, 0}, 0, 0, 0, 1, 0, 0, 0, -1, 0, 0, 0},
47 {OPCODE_MOV
, {{0, 0, 0, 0, 0, 0}, {13, 0, 1672, 0, 0, 0}, {13, 0, 1672, 0, 0, 0}}, {0, 0, 2, 0, 8, 1672, 0}, 0, 0, 0, 1, 0, 0, 0, -1, 0, 0, 0},
48 {OPCODE_MOV
, {{8, 0, 0, 0, 0, 0}, {13, 0, 1672, 0, 0, 0}, {13, 0, 1672, 0, 0, 0}}, {0, 0, 4, 0, 8, 1672, 0}, 0, 0, 0, 1, 0, 0, 0, -1, 0, 0, 0},
49 {OPCODE_MOV
, {{8, 0, 585, 0, 0, 0}, {13, 0, 1672, 0, 0, 0}, {13, 0, 1672, 0, 0, 0}}, {0, 0, 8, 0, 8, 1672, 0}, 0, 0, 0, 1, 0, 0, 0, -1, 0, 0, 0},
50 {OPCODE_SGT
, {{0, 0, 585, 0, 0, 0}, {8, 0, 1170, 0, 0, 0}, {13, 0, 1672, 0, 0, 0}}, {0, 1, 1, 0, 8, 1672, 0}, 1, 0, 0, 1, 0, 0, 0, -1, 0, 0, 0},
51 {OPCODE_IF
, {{13, 0, 1672, 0, 0, 0}, {13, 0, 1672, 0, 0, 0}, {13, 0, 1672, 0, 0, 0}}, {13, 0, 15, 0, 7, 0, 0}, 0, 0, 0, 1, 0, 0, 0, 15, 0, 0, 0},
52 {OPCODE_MOV
, {{0, 0, 1755, 0, 0, 0}, {13, 0, 1672, 0, 0, 0}, {13, 0, 1672, 0, 0, 0}}, {0, 0, 1, 0, 8, 1672, 0}, 0, 0, 0, 1, 0, 0, 0, -1, 0, 0, 0},
53 {OPCODE_RET
, {{13, 0, 1672, 0, 0, 0}, {13, 0, 1672, 0, 0, 0}, {13, 0, 1672, 0, 0, 0}}, {13, 0, 15, 0, 8, 1672, 0}, 0, 0, 0, 1, 0, 0, 0, -1, 0, 0, 0},
54 {OPCODE_ENDIF
, {{13, 0, 1672, 0, 0, 0}, {13, 0, 1672, 0, 0, 0}, {13, 0, 1672, 0, 0, 0}}, {13, 0, 15, 0, 8, 1672, 0}, 0, 0, 0, 1, 0, 0, 0, -1, 0, 0, 0},
55 {OPCODE_MOV
, {{0, 0, 1170, 0, 0, 0}, {13, 0, 1672, 0, 0, 0}, {13, 0, 1672, 0, 0, 0}}, {0, 0, 1, 0, 8, 1672, 0}, 0, 0, 0, 1, 0, 0, 0, -1, 0, 0, 0},
56 {OPCODE_RET
, {{13, 0, 1672, 0, 0, 0}, {13, 0, 1672, 0, 0, 0}, {13, 0, 1672, 0, 0, 0}}, {13, 0, 15, 0, 8, 1672, 0}, 0, 0, 0, 1, 0, 0, 0, -1, 0, 0, 0},
57 {OPCODE_ENDSUB
, {{13, 0, 1672, 0, 0, 0}, {13, 0, 1672, 0, 0, 0}, {13, 0, 1672, 0, 0, 0}}, {13, 0, 15, 0, 8, 1672, 0}, 0, 0, 0, 1, 0, 0, 0, -1, 0, 0, 0}
59 float noise1_const
[2][4] = {
60 {0.300000f
, 0.900000f
, 0.500000f
, 0.300000f
}
63 COMPILED_SUB noise1_presub
= {
78 BITS
addrmode_PVSDST(PVSDST
* pPVSDST
)
80 return pPVSDST
->addrmode0
| ((BITS
)pPVSDST
->addrmode1
<< 1);
83 void setaddrmode_PVSDST(PVSDST
* pPVSDST
, BITS addrmode
)
85 pPVSDST
->addrmode0
= addrmode
& 1;
86 pPVSDST
->addrmode1
= (addrmode
>> 1) & 1;
89 void nomask_PVSDST(PVSDST
* pPVSDST
)
91 pPVSDST
->writex
= pPVSDST
->writey
= pPVSDST
->writez
= pPVSDST
->writew
= 1;
94 BITS
addrmode_PVSSRC(PVSSRC
* pPVSSRC
)
96 return pPVSSRC
->addrmode0
| ((BITS
)pPVSSRC
->addrmode1
<< 1);
99 void setaddrmode_PVSSRC(PVSSRC
* pPVSSRC
, BITS addrmode
)
101 pPVSSRC
->addrmode0
= addrmode
& 1;
102 pPVSSRC
->addrmode1
= (addrmode
>> 1) & 1;
106 void setswizzle_PVSSRC(PVSSRC
* pPVSSRC
, BITS swz
)
111 pPVSSRC
->swizzlew
= swz
;
114 void noswizzle_PVSSRC(PVSSRC
* pPVSSRC
)
116 pPVSSRC
->swizzlex
= SQ_SEL_X
;
117 pPVSSRC
->swizzley
= SQ_SEL_Y
;
118 pPVSSRC
->swizzlez
= SQ_SEL_Z
;
119 pPVSSRC
->swizzlew
= SQ_SEL_W
;
123 swizzleagain_PVSSRC(PVSSRC
* pPVSSRC
, BITS x
, BITS y
, BITS z
, BITS w
)
127 case SQ_SEL_X
: x
= pPVSSRC
->swizzlex
;
129 case SQ_SEL_Y
: x
= pPVSSRC
->swizzley
;
131 case SQ_SEL_Z
: x
= pPVSSRC
->swizzlez
;
133 case SQ_SEL_W
: x
= pPVSSRC
->swizzlew
;
140 case SQ_SEL_X
: y
= pPVSSRC
->swizzlex
;
142 case SQ_SEL_Y
: y
= pPVSSRC
->swizzley
;
144 case SQ_SEL_Z
: y
= pPVSSRC
->swizzlez
;
146 case SQ_SEL_W
: y
= pPVSSRC
->swizzlew
;
153 case SQ_SEL_X
: z
= pPVSSRC
->swizzlex
;
155 case SQ_SEL_Y
: z
= pPVSSRC
->swizzley
;
157 case SQ_SEL_Z
: z
= pPVSSRC
->swizzlez
;
159 case SQ_SEL_W
: z
= pPVSSRC
->swizzlew
;
166 case SQ_SEL_X
: w
= pPVSSRC
->swizzlex
;
168 case SQ_SEL_Y
: w
= pPVSSRC
->swizzley
;
170 case SQ_SEL_Z
: w
= pPVSSRC
->swizzlez
;
172 case SQ_SEL_W
: w
= pPVSSRC
->swizzlew
;
177 pPVSSRC
->swizzlex
= x
;
178 pPVSSRC
->swizzley
= y
;
179 pPVSSRC
->swizzlez
= z
;
180 pPVSSRC
->swizzlew
= w
;
183 void neg_PVSSRC(PVSSRC
* pPVSSRC
)
191 void noneg_PVSSRC(PVSSRC
* pPVSSRC
)
199 // negate argument (for SUB instead of ADD and alike)
200 void flipneg_PVSSRC(PVSSRC
* pPVSSRC
)
202 pPVSSRC
->negx
= !pPVSSRC
->negx
;
203 pPVSSRC
->negy
= !pPVSSRC
->negy
;
204 pPVSSRC
->negz
= !pPVSSRC
->negz
;
205 pPVSSRC
->negw
= !pPVSSRC
->negw
;
208 void zerocomp_PVSSRC(PVSSRC
* pPVSSRC
, int c
)
212 case 0: pPVSSRC
->swizzlex
= SQ_SEL_0
; pPVSSRC
->negx
= 0; break;
213 case 1: pPVSSRC
->swizzley
= SQ_SEL_0
; pPVSSRC
->negy
= 0; break;
214 case 2: pPVSSRC
->swizzlez
= SQ_SEL_0
; pPVSSRC
->negz
= 0; break;
215 case 3: pPVSSRC
->swizzlew
= SQ_SEL_0
; pPVSSRC
->negw
= 0; break;
220 void onecomp_PVSSRC(PVSSRC
* pPVSSRC
, int c
)
224 case 0: pPVSSRC
->swizzlex
= SQ_SEL_1
; pPVSSRC
->negx
= 0; break;
225 case 1: pPVSSRC
->swizzley
= SQ_SEL_1
; pPVSSRC
->negy
= 0; break;
226 case 2: pPVSSRC
->swizzlez
= SQ_SEL_1
; pPVSSRC
->negz
= 0; break;
227 case 3: pPVSSRC
->swizzlew
= SQ_SEL_1
; pPVSSRC
->negw
= 0; break;
232 BITS
is_misc_component_exported(VAP_OUT_VTX_FMT_0
* pOutVTXFmt0
)
234 return (pOutVTXFmt0
->point_size
|
235 pOutVTXFmt0
->edge_flag
|
236 pOutVTXFmt0
->rta_index
|
237 pOutVTXFmt0
->kill_flag
|
238 pOutVTXFmt0
->viewport_index
);
241 BITS
is_depth_component_exported(OUT_FRAGMENT_FMT_0
* pFPOutFmt
)
243 return (pFPOutFmt
->depth
|
244 pFPOutFmt
->stencil_ref
|
246 pFPOutFmt
->coverage_to_mask
);
249 GLboolean
is_reduction_opcode(PVSDWORD
* dest
)
251 if (dest
->dst
.op3
== 0)
253 if ( (dest
->dst
.opcode
== SQ_OP2_INST_DOT4
|| dest
->dst
.opcode
== SQ_OP2_INST_DOT4_IEEE
|| dest
->dst
.opcode
== SQ_OP2_INST_CUBE
) )
261 GLuint
GetSurfaceFormat(GLenum eType
, GLuint nChannels
, GLuint
* pClient_size
)
263 GLuint format
= FMT_INVALID
;
264 GLuint uiElemSize
= 0;
269 case GL_UNSIGNED_BYTE
:
274 format
= FMT_8
; break;
276 format
= FMT_8_8
; break;
278 format
= FMT_8_8_8
; break;
280 format
= FMT_8_8_8_8
; break;
286 case GL_UNSIGNED_SHORT
:
292 format
= FMT_16
; break;
294 format
= FMT_16_16
; break;
296 format
= FMT_16_16_16
; break;
298 format
= FMT_16_16_16_16
; break;
304 case GL_UNSIGNED_INT
:
310 format
= FMT_32
; break;
312 format
= FMT_32_32
; break;
314 format
= FMT_32_32_32
; break;
316 format
= FMT_32_32_32_32
; break;
327 format
= FMT_32_FLOAT
; break;
329 format
= FMT_32_32_FLOAT
; break;
331 format
= FMT_32_32_32_FLOAT
; break;
333 format
= FMT_32_32_32_32_FLOAT
; break;
343 format
= FMT_32_FLOAT
; break;
345 format
= FMT_32_32_FLOAT
; break;
347 format
= FMT_32_32_32_FLOAT
; break;
349 format
= FMT_32_32_32_32_FLOAT
; break;
356 //GL_ASSERT_NO_CASE();
359 if(NULL
!= pClient_size
)
361 *pClient_size
= uiElemSize
* nChannels
;
367 unsigned int r700GetNumOperands(GLuint opcode
, GLuint nIsOp3
)
376 case SQ_OP2_INST_ADD
:
377 case SQ_OP2_INST_KILLE
:
378 case SQ_OP2_INST_KILLGT
:
379 case SQ_OP2_INST_KILLGE
:
380 case SQ_OP2_INST_KILLNE
:
381 case SQ_OP2_INST_MUL
:
382 case SQ_OP2_INST_MAX
:
383 case SQ_OP2_INST_MIN
:
384 //case SQ_OP2_INST_MAX_DX10:
385 //case SQ_OP2_INST_MIN_DX10:
386 case SQ_OP2_INST_SETE
:
387 case SQ_OP2_INST_SETNE
:
388 case SQ_OP2_INST_SETGT
:
389 case SQ_OP2_INST_SETGE
:
390 case SQ_OP2_INST_PRED_SETE
:
391 case SQ_OP2_INST_PRED_SETGT
:
392 case SQ_OP2_INST_PRED_SETGE
:
393 case SQ_OP2_INST_PRED_SETNE
:
394 case SQ_OP2_INST_DOT4
:
395 case SQ_OP2_INST_DOT4_IEEE
:
396 case SQ_OP2_INST_CUBE
:
399 case SQ_OP2_INST_MOV
:
400 case SQ_OP2_INST_MOVA_FLOOR
:
401 case SQ_OP2_INST_FRACT
:
402 case SQ_OP2_INST_FLOOR
:
403 case SQ_OP2_INST_TRUNC
:
404 case SQ_OP2_INST_EXP_IEEE
:
405 case SQ_OP2_INST_LOG_CLAMPED
:
406 case SQ_OP2_INST_LOG_IEEE
:
407 case SQ_OP2_INST_RECIP_IEEE
:
408 case SQ_OP2_INST_RECIPSQRT_IEEE
:
409 case SQ_OP2_INST_FLT_TO_INT
:
410 case SQ_OP2_INST_SIN
:
411 case SQ_OP2_INST_COS
:
414 default: radeon_error(
415 "Need instruction operand number for %x.\n", opcode
);
421 int Init_r700_AssemblerBase(SHADER_PIPE_TYPE spt
, r700_AssemblerBase
* pAsm
, R700_Shader
* pShader
)
425 Init_R700_Shader(pShader
);
426 pAsm
->pR700Shader
= pShader
;
427 pAsm
->currentShaderType
= spt
;
429 pAsm
->cf_last_export_ptr
= NULL
;
431 pAsm
->cf_current_export_clause_ptr
= NULL
;
432 pAsm
->cf_current_alu_clause_ptr
= NULL
;
433 pAsm
->cf_current_tex_clause_ptr
= NULL
;
434 pAsm
->cf_current_vtx_clause_ptr
= NULL
;
435 pAsm
->cf_current_cf_clause_ptr
= NULL
;
437 // No clause has been created yet
438 pAsm
->cf_current_clause_type
= CF_EMPTY_CLAUSE
;
440 pAsm
->number_of_colorandz_exports
= 0;
441 pAsm
->number_of_exports
= 0;
442 pAsm
->number_of_export_opcodes
= 0;
444 pAsm
->alu_x_opcode
= 0;
453 pAsm
->uLastPosUpdate
= 0;
455 *(BITS
*) &pAsm
->fp_stOutFmt0
= 0;
459 pAsm
->number_used_registers
= 0;
460 pAsm
->uUsedConsts
= 256;
464 pAsm
->uBoolConsts
= 0;
465 pAsm
->uIntConsts
= 0;
470 pAsm
->fc_stack
[0].type
= FC_NONE
;
475 pAsm
->aArgSubst
[3] = (-1);
479 for (i
=0; i
<NUMBER_OF_OUTPUT_COLORS
; i
++)
481 pAsm
->color_export_register_number
[i
] = (-1);
485 pAsm
->depth_export_register_number
= (-1);
486 pAsm
->stencil_export_register_number
= (-1);
487 pAsm
->coverage_to_mask_export_register_number
= (-1);
488 pAsm
->mask_export_register_number
= (-1);
490 pAsm
->starting_export_register_number
= 0;
491 pAsm
->starting_vfetch_register_number
= 0;
492 pAsm
->starting_temp_register_number
= 0;
493 pAsm
->uFirstHelpReg
= 0;
495 pAsm
->input_position_is_used
= GL_FALSE
;
496 pAsm
->input_normal_is_used
= GL_FALSE
;
498 for (i
=0; i
<NUMBER_OF_INPUT_COLORS
; i
++)
500 pAsm
->input_color_is_used
[ i
] = GL_FALSE
;
503 for (i
=0; i
<NUMBER_OF_TEXTURE_UNITS
; i
++)
505 pAsm
->input_texture_unit_is_used
[ i
] = GL_FALSE
;
508 for (i
=0; i
<VERT_ATTRIB_MAX
; i
++)
510 pAsm
->vfetch_instruction_ptr_array
[ i
] = NULL
;
513 pAsm
->number_of_inputs
= 0;
515 pAsm
->is_tex
= GL_FALSE
;
516 pAsm
->need_tex_barrier
= GL_FALSE
;
519 pAsm
->unSubArraySize
= 0;
520 pAsm
->unSubArrayPointer
= 0;
521 pAsm
->callers
= NULL
;
522 pAsm
->unCallerArraySize
= 0;
523 pAsm
->unCallerArrayPointer
= 0;
526 pAsm
->CALLSTACK
[0].FCSP_BeforeEntry
= 0;
527 pAsm
->CALLSTACK
[0].plstCFInstructions_local
528 = &(pAsm
->pR700Shader
->lstCFInstructions
);
530 pAsm
->CALLSTACK
[0].max
= 0;
531 pAsm
->CALLSTACK
[0].current
= 0;
533 SetActiveCFlist(pAsm
->pR700Shader
, pAsm
->CALLSTACK
[0].plstCFInstructions_local
);
537 pAsm
->presubs
= NULL
;
538 pAsm
->unPresubArraySize
= 0;
539 pAsm
->unNumPresub
= 0;
540 pAsm
->unCurNumILInsts
= 0;
542 pAsm
->unVetTexBits
= 0;
547 GLboolean
IsTex(gl_inst_opcode Opcode
)
549 if( (OPCODE_TEX
==Opcode
) || (OPCODE_TXP
==Opcode
) || (OPCODE_TXB
==Opcode
) ||
550 (OPCODE_DDX
==Opcode
) || (OPCODE_DDY
==Opcode
) )
557 GLboolean
IsAlu(gl_inst_opcode Opcode
)
559 //TODO : more for fc and ex for higher spec.
567 int check_current_clause(r700_AssemblerBase
* pAsm
,
568 CF_CLAUSE_TYPE new_clause_type
)
570 if (pAsm
->cf_current_clause_type
!= new_clause_type
)
571 { //Close last open clause
572 switch (pAsm
->cf_current_clause_type
)
575 if ( pAsm
->cf_current_alu_clause_ptr
!= NULL
)
577 pAsm
->cf_current_alu_clause_ptr
= NULL
;
581 if ( pAsm
->cf_current_vtx_clause_ptr
!= NULL
)
583 pAsm
->cf_current_vtx_clause_ptr
= NULL
;
587 if ( pAsm
->cf_current_tex_clause_ptr
!= NULL
)
589 pAsm
->cf_current_tex_clause_ptr
= NULL
;
592 case CF_EXPORT_CLAUSE
:
593 if ( pAsm
->cf_current_export_clause_ptr
!= NULL
)
595 pAsm
->cf_current_export_clause_ptr
= NULL
;
598 case CF_OTHER_CLAUSE
:
599 if ( pAsm
->cf_current_cf_clause_ptr
!= NULL
)
601 pAsm
->cf_current_cf_clause_ptr
= NULL
;
604 case CF_EMPTY_CLAUSE
:
608 "Unknown CF_CLAUSE_TYPE (%d) in check_current_clause. \n", (int) new_clause_type
);
612 pAsm
->cf_current_clause_type
= CF_EMPTY_CLAUSE
;
615 switch (new_clause_type
)
618 pAsm
->cf_current_clause_type
= CF_ALU_CLAUSE
;
621 pAsm
->cf_current_clause_type
= CF_VTX_CLAUSE
;
624 pAsm
->cf_current_clause_type
= CF_TEX_CLAUSE
;
626 case CF_EXPORT_CLAUSE
:
628 R700ControlFlowSXClause
* pR700ControlFlowSXClause
629 = (R700ControlFlowSXClause
*) CALLOC_STRUCT(R700ControlFlowSXClause
);
631 // Add new export instruction to control flow program
632 if (pR700ControlFlowSXClause
!= 0)
634 pAsm
->cf_current_export_clause_ptr
= pR700ControlFlowSXClause
;
635 Init_R700ControlFlowSXClause(pR700ControlFlowSXClause
);
636 AddCFInstruction( pAsm
->pR700Shader
,
637 (R700ControlFlowInstruction
*)pR700ControlFlowSXClause
);
642 "Error allocating new EXPORT CF instruction in check_current_clause. \n");
645 pAsm
->cf_current_clause_type
= CF_EXPORT_CLAUSE
;
648 case CF_EMPTY_CLAUSE
:
650 case CF_OTHER_CLAUSE
:
651 pAsm
->cf_current_clause_type
= CF_OTHER_CLAUSE
;
655 "Unknown CF_CLAUSE_TYPE (%d) in check_current_clause. \n", (int) new_clause_type
);
663 GLboolean
add_cf_instruction(r700_AssemblerBase
* pAsm
)
665 if(GL_FALSE
== check_current_clause(pAsm
, CF_OTHER_CLAUSE
))
670 pAsm
->cf_current_cf_clause_ptr
=
671 (R700ControlFlowGenericClause
*) CALLOC_STRUCT(R700ControlFlowGenericClause
);
673 if (pAsm
->cf_current_cf_clause_ptr
!= NULL
)
675 Init_R700ControlFlowGenericClause(pAsm
->cf_current_cf_clause_ptr
);
676 AddCFInstruction( pAsm
->pR700Shader
,
677 (R700ControlFlowInstruction
*)pAsm
->cf_current_cf_clause_ptr
);
681 radeon_error("Could not allocate a new VFetch CF instruction.\n");
688 GLboolean
add_vfetch_instruction(r700_AssemblerBase
* pAsm
,
689 R700VertexInstruction
* vertex_instruction_ptr
)
691 if( GL_FALSE
== check_current_clause(pAsm
, CF_VTX_CLAUSE
) )
696 if( pAsm
->cf_current_vtx_clause_ptr
== NULL
||
697 ( (pAsm
->cf_current_vtx_clause_ptr
!= NULL
) &&
698 (pAsm
->cf_current_vtx_clause_ptr
->m_Word1
.f
.count
>= GetCFMaxInstructions(pAsm
->cf_current_vtx_clause_ptr
->m_ShaderInstType
)-1)
701 // Create new Vfetch control flow instruction for this new clause
702 pAsm
->cf_current_vtx_clause_ptr
= (R700ControlFlowGenericClause
*) CALLOC_STRUCT(R700ControlFlowGenericClause
);
704 if (pAsm
->cf_current_vtx_clause_ptr
!= NULL
)
706 Init_R700ControlFlowGenericClause(pAsm
->cf_current_vtx_clause_ptr
);
707 AddCFInstruction( pAsm
->pR700Shader
,
708 (R700ControlFlowInstruction
*)pAsm
->cf_current_vtx_clause_ptr
);
712 radeon_error("Could not allocate a new VFetch CF instruction.\n");
716 pAsm
->cf_current_vtx_clause_ptr
->m_Word1
.f
.pop_count
= 0x0;
717 pAsm
->cf_current_vtx_clause_ptr
->m_Word1
.f
.cf_const
= 0x0;
718 pAsm
->cf_current_vtx_clause_ptr
->m_Word1
.f
.cond
= SQ_CF_COND_ACTIVE
;
719 pAsm
->cf_current_vtx_clause_ptr
->m_Word1
.f
.count
= 0x0;
720 pAsm
->cf_current_vtx_clause_ptr
->m_Word1
.f
.end_of_program
= 0x0;
721 pAsm
->cf_current_vtx_clause_ptr
->m_Word1
.f
.valid_pixel_mode
= 0x0;
722 pAsm
->cf_current_vtx_clause_ptr
->m_Word1
.f
.cf_inst
= SQ_CF_INST_VTX
;
723 pAsm
->cf_current_vtx_clause_ptr
->m_Word1
.f
.whole_quad_mode
= 0x0;
724 pAsm
->cf_current_vtx_clause_ptr
->m_Word1
.f
.barrier
= 0x1;
726 LinkVertexInstruction(pAsm
->cf_current_vtx_clause_ptr
, vertex_instruction_ptr
);
730 pAsm
->cf_current_vtx_clause_ptr
->m_Word1
.f
.count
++;
733 AddVTXInstruction(pAsm
->pR700Shader
, vertex_instruction_ptr
);
738 GLboolean
add_tex_instruction(r700_AssemblerBase
* pAsm
,
739 R700TextureInstruction
* tex_instruction_ptr
)
741 if ( GL_FALSE
== check_current_clause(pAsm
, CF_TEX_CLAUSE
) )
746 if ( pAsm
->cf_current_tex_clause_ptr
== NULL
||
747 ( (pAsm
->cf_current_tex_clause_ptr
!= NULL
) &&
748 (pAsm
->cf_current_tex_clause_ptr
->m_Word1
.f
.count
>= GetCFMaxInstructions(pAsm
->cf_current_tex_clause_ptr
->m_ShaderInstType
)-1)
751 // new tex cf instruction for this new clause
752 pAsm
->cf_current_tex_clause_ptr
= (R700ControlFlowGenericClause
*) CALLOC_STRUCT(R700ControlFlowGenericClause
);
754 if (pAsm
->cf_current_tex_clause_ptr
!= NULL
)
756 Init_R700ControlFlowGenericClause(pAsm
->cf_current_tex_clause_ptr
);
757 AddCFInstruction( pAsm
->pR700Shader
,
758 (R700ControlFlowInstruction
*)pAsm
->cf_current_tex_clause_ptr
);
762 radeon_error("Could not allocate a new TEX CF instruction.\n");
766 pAsm
->cf_current_tex_clause_ptr
->m_Word1
.f
.pop_count
= 0x0;
767 pAsm
->cf_current_tex_clause_ptr
->m_Word1
.f
.cf_const
= 0x0;
768 pAsm
->cf_current_tex_clause_ptr
->m_Word1
.f
.cond
= SQ_CF_COND_ACTIVE
;
770 pAsm
->cf_current_tex_clause_ptr
->m_Word1
.f
.end_of_program
= 0x0;
771 pAsm
->cf_current_tex_clause_ptr
->m_Word1
.f
.valid_pixel_mode
= 0x0;
772 pAsm
->cf_current_tex_clause_ptr
->m_Word1
.f
.cf_inst
= SQ_CF_INST_TEX
;
773 pAsm
->cf_current_tex_clause_ptr
->m_Word1
.f
.whole_quad_mode
= 0x0;
774 pAsm
->cf_current_tex_clause_ptr
->m_Word1
.f
.barrier
= 0x0; //0x1;
778 pAsm
->cf_current_tex_clause_ptr
->m_Word1
.f
.count
++;
781 // If this clause constains any TEX instruction that is dependent on a previous instruction,
782 // set the barrier bit
783 if( pAsm
->pInstDeps
[pAsm
->uiCurInst
].nDstDep
> (-1) || pAsm
->need_tex_barrier
== GL_TRUE
)
785 pAsm
->cf_current_tex_clause_ptr
->m_Word1
.f
.barrier
= 0x1;
788 if(NULL
== pAsm
->cf_current_tex_clause_ptr
->m_pLinkedTEXInstruction
)
790 pAsm
->cf_current_tex_clause_ptr
->m_pLinkedTEXInstruction
= tex_instruction_ptr
;
791 tex_instruction_ptr
->m_pLinkedGenericClause
= pAsm
->cf_current_tex_clause_ptr
;
794 AddTEXInstruction(pAsm
->pR700Shader
, tex_instruction_ptr
);
799 GLboolean
assemble_vfetch_instruction(r700_AssemblerBase
* pAsm
,
801 GLuint destination_register
,
802 GLuint number_of_elements
,
803 GLenum dataElementType
,
804 VTX_FETCH_METHOD
* pFetchMethod
)
806 GLuint client_size_inbyte
;
808 GLuint mega_fetch_count
;
809 GLuint is_mega_fetch_flag
;
811 R700VertexGenericFetch
* vfetch_instruction_ptr
;
812 R700VertexGenericFetch
* assembled_vfetch_instruction_ptr
= pAsm
->vfetch_instruction_ptr_array
[ gl_client_id
];
814 if (assembled_vfetch_instruction_ptr
== NULL
)
816 vfetch_instruction_ptr
= (R700VertexGenericFetch
*) CALLOC_STRUCT(R700VertexGenericFetch
);
817 if (vfetch_instruction_ptr
== NULL
)
821 Init_R700VertexGenericFetch(vfetch_instruction_ptr
);
825 vfetch_instruction_ptr
= assembled_vfetch_instruction_ptr
;
828 data_format
= GetSurfaceFormat(dataElementType
, number_of_elements
, &client_size_inbyte
);
830 if(GL_TRUE
== pFetchMethod
->bEnableMini
) //More conditions here
836 mega_fetch_count
= MEGA_FETCH_BYTES
- 1;
837 is_mega_fetch_flag
= 0x1;
838 pFetchMethod
->mega_fetch_remainder
= MEGA_FETCH_BYTES
- client_size_inbyte
;
841 vfetch_instruction_ptr
->m_Word0
.f
.vtx_inst
= SQ_VTX_INST_FETCH
;
842 vfetch_instruction_ptr
->m_Word0
.f
.fetch_type
= SQ_VTX_FETCH_VERTEX_DATA
;
843 vfetch_instruction_ptr
->m_Word0
.f
.fetch_whole_quad
= 0x0;
845 vfetch_instruction_ptr
->m_Word0
.f
.buffer_id
= gl_client_id
;
846 vfetch_instruction_ptr
->m_Word0
.f
.src_gpr
= 0x0;
847 vfetch_instruction_ptr
->m_Word0
.f
.src_rel
= SQ_ABSOLUTE
;
848 vfetch_instruction_ptr
->m_Word0
.f
.src_sel_x
= SQ_SEL_X
;
849 vfetch_instruction_ptr
->m_Word0
.f
.mega_fetch_count
= mega_fetch_count
;
851 vfetch_instruction_ptr
->m_Word1
.f
.dst_sel_x
= (number_of_elements
< 1) ? SQ_SEL_0
: SQ_SEL_X
;
852 vfetch_instruction_ptr
->m_Word1
.f
.dst_sel_y
= (number_of_elements
< 2) ? SQ_SEL_0
: SQ_SEL_Y
;
853 vfetch_instruction_ptr
->m_Word1
.f
.dst_sel_z
= (number_of_elements
< 3) ? SQ_SEL_0
: SQ_SEL_Z
;
854 vfetch_instruction_ptr
->m_Word1
.f
.dst_sel_w
= (number_of_elements
< 4) ? SQ_SEL_1
: SQ_SEL_W
;
856 vfetch_instruction_ptr
->m_Word1
.f
.use_const_fields
= 1;
858 // Destination register
859 vfetch_instruction_ptr
->m_Word1_GPR
.f
.dst_gpr
= destination_register
;
860 vfetch_instruction_ptr
->m_Word1_GPR
.f
.dst_rel
= SQ_ABSOLUTE
;
862 vfetch_instruction_ptr
->m_Word2
.f
.offset
= 0;
863 vfetch_instruction_ptr
->m_Word2
.f
.const_buf_no_stride
= 0x0;
865 vfetch_instruction_ptr
->m_Word2
.f
.mega_fetch
= is_mega_fetch_flag
;
867 if (assembled_vfetch_instruction_ptr
== NULL
)
869 if ( GL_FALSE
== add_vfetch_instruction(pAsm
, (R700VertexInstruction
*)vfetch_instruction_ptr
) )
874 if (pAsm
->vfetch_instruction_ptr_array
[ gl_client_id
] != NULL
)
880 pAsm
->vfetch_instruction_ptr_array
[ gl_client_id
] = vfetch_instruction_ptr
;
887 GLboolean
assemble_vfetch_instruction2(r700_AssemblerBase
* pAsm
,
888 GLuint destination_register
,
894 VTX_FETCH_METHOD
* pFetchMethod
)
896 GLuint client_size_inbyte
;
898 GLuint mega_fetch_count
;
899 GLuint is_mega_fetch_flag
;
901 R700VertexGenericFetch
* vfetch_instruction_ptr
;
902 R700VertexGenericFetch
* assembled_vfetch_instruction_ptr
903 = pAsm
->vfetch_instruction_ptr_array
[element
];
905 if (assembled_vfetch_instruction_ptr
== NULL
)
907 vfetch_instruction_ptr
= (R700VertexGenericFetch
*) CALLOC_STRUCT(R700VertexGenericFetch
);
908 if (vfetch_instruction_ptr
== NULL
)
912 Init_R700VertexGenericFetch(vfetch_instruction_ptr
);
916 vfetch_instruction_ptr
= assembled_vfetch_instruction_ptr
;
919 data_format
= GetSurfaceFormat(type
, size
, &client_size_inbyte
);
921 if(GL_TRUE
== pFetchMethod
->bEnableMini
) //More conditions here
927 mega_fetch_count
= MEGA_FETCH_BYTES
- 1;
928 is_mega_fetch_flag
= 0x1;
929 pFetchMethod
->mega_fetch_remainder
= MEGA_FETCH_BYTES
- client_size_inbyte
;
932 vfetch_instruction_ptr
->m_Word0
.f
.vtx_inst
= SQ_VTX_INST_FETCH
;
933 vfetch_instruction_ptr
->m_Word0
.f
.fetch_type
= SQ_VTX_FETCH_VERTEX_DATA
;
934 vfetch_instruction_ptr
->m_Word0
.f
.fetch_whole_quad
= 0x0;
936 vfetch_instruction_ptr
->m_Word0
.f
.buffer_id
= element
;
937 vfetch_instruction_ptr
->m_Word0
.f
.src_gpr
= 0x0;
938 vfetch_instruction_ptr
->m_Word0
.f
.src_rel
= SQ_ABSOLUTE
;
939 vfetch_instruction_ptr
->m_Word0
.f
.src_sel_x
= SQ_SEL_X
;
940 vfetch_instruction_ptr
->m_Word0
.f
.mega_fetch_count
= mega_fetch_count
;
942 vfetch_instruction_ptr
->m_Word1
.f
.dst_sel_x
= (size
< 1) ? SQ_SEL_0
: SQ_SEL_X
;
943 vfetch_instruction_ptr
->m_Word1
.f
.dst_sel_y
= (size
< 2) ? SQ_SEL_0
: SQ_SEL_Y
;
944 vfetch_instruction_ptr
->m_Word1
.f
.dst_sel_z
= (size
< 3) ? SQ_SEL_0
: SQ_SEL_Z
;
945 vfetch_instruction_ptr
->m_Word1
.f
.dst_sel_w
= (size
< 4) ? SQ_SEL_1
: SQ_SEL_W
;
947 vfetch_instruction_ptr
->m_Word1
.f
.use_const_fields
= 1;
948 vfetch_instruction_ptr
->m_Word1
.f
.data_format
= data_format
;
949 vfetch_instruction_ptr
->m_Word2
.f
.endian_swap
= SQ_ENDIAN_NONE
;
953 vfetch_instruction_ptr
->m_Word1
.f
.format_comp_all
= SQ_FORMAT_COMP_SIGNED
;
957 vfetch_instruction_ptr
->m_Word1
.f
.format_comp_all
= SQ_FORMAT_COMP_UNSIGNED
;
960 if(GL_TRUE
== normalize
)
962 vfetch_instruction_ptr
->m_Word1
.f
.num_format_all
= SQ_NUM_FORMAT_NORM
;
966 vfetch_instruction_ptr
->m_Word1
.f
.num_format_all
= SQ_NUM_FORMAT_INT
;
969 // Destination register
970 vfetch_instruction_ptr
->m_Word1_GPR
.f
.dst_gpr
= destination_register
;
971 vfetch_instruction_ptr
->m_Word1_GPR
.f
.dst_rel
= SQ_ABSOLUTE
;
973 vfetch_instruction_ptr
->m_Word2
.f
.offset
= 0;
974 vfetch_instruction_ptr
->m_Word2
.f
.const_buf_no_stride
= 0x0;
976 vfetch_instruction_ptr
->m_Word2
.f
.mega_fetch
= is_mega_fetch_flag
;
978 if (assembled_vfetch_instruction_ptr
== NULL
)
980 if ( GL_FALSE
== add_vfetch_instruction(pAsm
, (R700VertexInstruction
*)vfetch_instruction_ptr
) )
985 if (pAsm
->vfetch_instruction_ptr_array
[element
] != NULL
)
991 pAsm
->vfetch_instruction_ptr_array
[element
] = vfetch_instruction_ptr
;
998 GLboolean
cleanup_vfetch_instructions(r700_AssemblerBase
* pAsm
)
1001 pAsm
->cf_current_clause_type
= CF_EMPTY_CLAUSE
;
1002 pAsm
->cf_current_vtx_clause_ptr
= NULL
;
1004 for (i
=0; i
<VERT_ATTRIB_MAX
; i
++)
1006 pAsm
->vfetch_instruction_ptr_array
[ i
] = NULL
;
1009 cleanup_vfetch_shaderinst(pAsm
->pR700Shader
);
1014 GLuint
gethelpr(r700_AssemblerBase
* pAsm
)
1016 GLuint r
= pAsm
->uHelpReg
;
1018 if (pAsm
->uHelpReg
> pAsm
->number_used_registers
)
1020 pAsm
->number_used_registers
= pAsm
->uHelpReg
;
1024 void resethelpr(r700_AssemblerBase
* pAsm
)
1026 pAsm
->uHelpReg
= pAsm
->uFirstHelpReg
;
1029 void checkop_init(r700_AssemblerBase
* pAsm
)
1032 pAsm
->aArgSubst
[0] =
1033 pAsm
->aArgSubst
[1] =
1034 pAsm
->aArgSubst
[2] =
1035 pAsm
->aArgSubst
[3] = -1;
1038 GLboolean
mov_temp(r700_AssemblerBase
* pAsm
, int src
)
1040 GLuint tmp
= gethelpr(pAsm
);
1042 //mov src to temp helper gpr.
1043 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_MOV
;
1045 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
1047 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
1048 pAsm
->D
.dst
.reg
= tmp
;
1050 nomask_PVSDST(&(pAsm
->D
.dst
));
1052 if( GL_FALSE
== assemble_src(pAsm
, src
, 0) )
1057 noswizzle_PVSSRC(&(pAsm
->S
[0].src
));
1058 noneg_PVSSRC(&(pAsm
->S
[0].src
));
1060 if( GL_FALSE
== next_ins(pAsm
) )
1065 pAsm
->aArgSubst
[1 + src
] = tmp
;
1070 GLboolean
checkop1(r700_AssemblerBase
* pAsm
)
1076 GLboolean
checkop2(r700_AssemblerBase
* pAsm
)
1078 GLboolean bSrcConst
[2];
1079 struct prog_instruction
*pILInst
= &(pAsm
->pILInst
[pAsm
->uiCurInst
]);
1083 if( (pILInst
->SrcReg
[0].File
== PROGRAM_UNIFORM
) ||
1084 (pILInst
->SrcReg
[0].File
== PROGRAM_CONSTANT
) ||
1085 (pILInst
->SrcReg
[0].File
== PROGRAM_LOCAL_PARAM
) ||
1086 (pILInst
->SrcReg
[0].File
== PROGRAM_ENV_PARAM
) ||
1087 (pILInst
->SrcReg
[0].File
== PROGRAM_STATE_VAR
) )
1089 bSrcConst
[0] = GL_TRUE
;
1093 bSrcConst
[0] = GL_FALSE
;
1095 if( (pILInst
->SrcReg
[1].File
== PROGRAM_UNIFORM
) ||
1096 (pILInst
->SrcReg
[1].File
== PROGRAM_CONSTANT
) ||
1097 (pILInst
->SrcReg
[1].File
== PROGRAM_LOCAL_PARAM
) ||
1098 (pILInst
->SrcReg
[1].File
== PROGRAM_ENV_PARAM
) ||
1099 (pILInst
->SrcReg
[1].File
== PROGRAM_STATE_VAR
) )
1101 bSrcConst
[1] = GL_TRUE
;
1105 bSrcConst
[1] = GL_FALSE
;
1108 if( (bSrcConst
[0] == GL_TRUE
) && (bSrcConst
[1] == GL_TRUE
) )
1110 if(pILInst
->SrcReg
[0].Index
!= pILInst
->SrcReg
[1].Index
)
1112 if( GL_FALSE
== mov_temp(pAsm
, 1) )
1122 GLboolean
checkop3(r700_AssemblerBase
* pAsm
)
1124 GLboolean bSrcConst
[3];
1125 struct prog_instruction
*pILInst
= &(pAsm
->pILInst
[pAsm
->uiCurInst
]);
1129 if( (pILInst
->SrcReg
[0].File
== PROGRAM_UNIFORM
) ||
1130 (pILInst
->SrcReg
[0].File
== PROGRAM_CONSTANT
) ||
1131 (pILInst
->SrcReg
[0].File
== PROGRAM_LOCAL_PARAM
) ||
1132 (pILInst
->SrcReg
[0].File
== PROGRAM_ENV_PARAM
) ||
1133 (pILInst
->SrcReg
[0].File
== PROGRAM_STATE_VAR
) )
1135 bSrcConst
[0] = GL_TRUE
;
1139 bSrcConst
[0] = GL_FALSE
;
1141 if( (pILInst
->SrcReg
[1].File
== PROGRAM_UNIFORM
) ||
1142 (pILInst
->SrcReg
[1].File
== PROGRAM_CONSTANT
) ||
1143 (pILInst
->SrcReg
[1].File
== PROGRAM_LOCAL_PARAM
) ||
1144 (pILInst
->SrcReg
[1].File
== PROGRAM_ENV_PARAM
) ||
1145 (pILInst
->SrcReg
[1].File
== PROGRAM_STATE_VAR
) )
1147 bSrcConst
[1] = GL_TRUE
;
1151 bSrcConst
[1] = GL_FALSE
;
1153 if( (pILInst
->SrcReg
[2].File
== PROGRAM_UNIFORM
) ||
1154 (pILInst
->SrcReg
[2].File
== PROGRAM_CONSTANT
) ||
1155 (pILInst
->SrcReg
[2].File
== PROGRAM_LOCAL_PARAM
) ||
1156 (pILInst
->SrcReg
[2].File
== PROGRAM_ENV_PARAM
) ||
1157 (pILInst
->SrcReg
[2].File
== PROGRAM_STATE_VAR
) )
1159 bSrcConst
[2] = GL_TRUE
;
1163 bSrcConst
[2] = GL_FALSE
;
1166 if( (GL_TRUE
== bSrcConst
[0]) &&
1167 (GL_TRUE
== bSrcConst
[1]) &&
1168 (GL_TRUE
== bSrcConst
[2]) )
1170 if( GL_FALSE
== mov_temp(pAsm
, 1) )
1174 if( GL_FALSE
== mov_temp(pAsm
, 2) )
1181 else if( (GL_TRUE
== bSrcConst
[0]) &&
1182 (GL_TRUE
== bSrcConst
[1]) )
1184 if(pILInst
->SrcReg
[0].Index
!= pILInst
->SrcReg
[1].Index
)
1186 if( GL_FALSE
== mov_temp(pAsm
, 1) )
1194 else if ( (GL_TRUE
== bSrcConst
[0]) &&
1195 (GL_TRUE
== bSrcConst
[2]) )
1197 if(pILInst
->SrcReg
[0].Index
!= pILInst
->SrcReg
[2].Index
)
1199 if( GL_FALSE
== mov_temp(pAsm
, 2) )
1207 else if( (GL_TRUE
== bSrcConst
[1]) &&
1208 (GL_TRUE
== bSrcConst
[2]) )
1210 if(pILInst
->SrcReg
[1].Index
!= pILInst
->SrcReg
[2].Index
)
1212 if( GL_FALSE
== mov_temp(pAsm
, 2) )
1224 GLboolean
assemble_src(r700_AssemblerBase
*pAsm
,
1228 struct prog_instruction
*pILInst
= &(pAsm
->pILInst
[pAsm
->uiCurInst
]);
1235 if(pAsm
->aArgSubst
[1+src
] >= 0)
1237 setaddrmode_PVSSRC(&(pAsm
->S
[fld
].src
), ADDR_ABSOLUTE
);
1238 pAsm
->S
[fld
].src
.rtype
= SRC_REG_TEMPORARY
;
1239 pAsm
->S
[fld
].src
.reg
= pAsm
->aArgSubst
[1+src
];
1243 switch (pILInst
->SrcReg
[src
].File
)
1245 case PROGRAM_TEMPORARY
:
1246 setaddrmode_PVSSRC(&(pAsm
->S
[fld
].src
), ADDR_ABSOLUTE
);
1247 pAsm
->S
[fld
].src
.rtype
= SRC_REG_TEMPORARY
;
1248 pAsm
->S
[fld
].src
.reg
= pILInst
->SrcReg
[src
].Index
+ pAsm
->starting_temp_register_number
;
1250 case PROGRAM_CONSTANT
:
1251 case PROGRAM_LOCAL_PARAM
:
1252 case PROGRAM_ENV_PARAM
:
1253 case PROGRAM_STATE_VAR
:
1254 case PROGRAM_UNIFORM
:
1255 if (1 == pILInst
->SrcReg
[src
].RelAddr
)
1257 setaddrmode_PVSSRC(&(pAsm
->S
[fld
].src
), ADDR_RELATIVE_A0
);
1261 setaddrmode_PVSSRC(&(pAsm
->S
[fld
].src
), ADDR_ABSOLUTE
);
1264 pAsm
->S
[fld
].src
.rtype
= SRC_REG_CONSTANT
;
1265 pAsm
->S
[fld
].src
.reg
= pILInst
->SrcReg
[src
].Index
;
1268 setaddrmode_PVSSRC(&(pAsm
->S
[fld
].src
), ADDR_ABSOLUTE
);
1269 pAsm
->S
[fld
].src
.rtype
= SRC_REG_INPUT
;
1270 switch (pAsm
->currentShaderType
)
1273 pAsm
->S
[fld
].src
.reg
= pAsm
->uiFP_AttributeMap
[pILInst
->SrcReg
[src
].Index
];
1276 pAsm
->S
[fld
].src
.reg
= pAsm
->ucVP_AttributeMap
[pILInst
->SrcReg
[src
].Index
];
1281 radeon_error("Invalid source argument type : %d \n", pILInst
->SrcReg
[src
].File
);
1286 pAsm
->S
[fld
].src
.swizzlex
= pILInst
->SrcReg
[src
].Swizzle
& 0x7;
1287 pAsm
->S
[fld
].src
.swizzley
= (pILInst
->SrcReg
[src
].Swizzle
>> 3) & 0x7;
1288 pAsm
->S
[fld
].src
.swizzlez
= (pILInst
->SrcReg
[src
].Swizzle
>> 6) & 0x7;
1289 pAsm
->S
[fld
].src
.swizzlew
= (pILInst
->SrcReg
[src
].Swizzle
>> 9) & 0x7;
1291 pAsm
->S
[fld
].src
.negx
= pILInst
->SrcReg
[src
].Negate
& 0x1;
1292 pAsm
->S
[fld
].src
.negy
= (pILInst
->SrcReg
[src
].Negate
>> 1) & 0x1;
1293 pAsm
->S
[fld
].src
.negz
= (pILInst
->SrcReg
[src
].Negate
>> 2) & 0x1;
1294 pAsm
->S
[fld
].src
.negw
= (pILInst
->SrcReg
[src
].Negate
>> 3) & 0x1;
1299 GLboolean
assemble_dst(r700_AssemblerBase
*pAsm
)
1301 struct prog_instruction
*pILInst
= &(pAsm
->pILInst
[pAsm
->uiCurInst
]);
1302 switch (pILInst
->DstReg
.File
)
1304 case PROGRAM_TEMPORARY
:
1305 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
1306 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
1307 pAsm
->D
.dst
.reg
= pILInst
->DstReg
.Index
+ pAsm
->starting_temp_register_number
;
1309 case PROGRAM_ADDRESS
:
1310 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
1311 pAsm
->D
.dst
.rtype
= DST_REG_A0
;
1312 pAsm
->D
.dst
.reg
= 0;
1314 case PROGRAM_OUTPUT
:
1315 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
1316 pAsm
->D
.dst
.rtype
= DST_REG_OUT
;
1317 switch (pAsm
->currentShaderType
)
1320 pAsm
->D
.dst
.reg
= pAsm
->uiFP_OutputMap
[pILInst
->DstReg
.Index
];
1323 pAsm
->D
.dst
.reg
= pAsm
->ucVP_OutputMap
[pILInst
->DstReg
.Index
];
1328 radeon_error("Invalid destination output argument type\n");
1332 pAsm
->D
.dst
.writex
= pILInst
->DstReg
.WriteMask
& 0x1;
1333 pAsm
->D
.dst
.writey
= (pILInst
->DstReg
.WriteMask
>> 1) & 0x1;
1334 pAsm
->D
.dst
.writez
= (pILInst
->DstReg
.WriteMask
>> 2) & 0x1;
1335 pAsm
->D
.dst
.writew
= (pILInst
->DstReg
.WriteMask
>> 3) & 0x1;
1337 if(pILInst
->SaturateMode
== SATURATE_ZERO_ONE
)
1339 pAsm
->D2
.dst2
.SaturateMode
= 1;
1343 pAsm
->D2
.dst2
.SaturateMode
= 0;
1349 GLboolean
tex_dst(r700_AssemblerBase
*pAsm
)
1351 struct prog_instruction
*pILInst
= &(pAsm
->pILInst
[pAsm
->uiCurInst
]);
1353 if(PROGRAM_TEMPORARY
== pILInst
->DstReg
.File
)
1355 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
1356 pAsm
->D
.dst
.reg
= pAsm
->pILInst
[pAsm
->uiCurInst
].DstReg
.Index
+ pAsm
->starting_temp_register_number
;
1358 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
1360 else if(PROGRAM_OUTPUT
== pILInst
->DstReg
.File
)
1362 pAsm
->D
.dst
.rtype
= DST_REG_OUT
;
1363 switch (pAsm
->currentShaderType
)
1366 pAsm
->D
.dst
.reg
= pAsm
->uiFP_OutputMap
[pILInst
->DstReg
.Index
];
1369 pAsm
->D
.dst
.reg
= pAsm
->ucVP_OutputMap
[pILInst
->DstReg
.Index
];
1373 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
1377 radeon_error("Invalid destination output argument type\n");
1381 pAsm
->D
.dst
.writex
= pILInst
->DstReg
.WriteMask
& 0x1;
1382 pAsm
->D
.dst
.writey
= (pILInst
->DstReg
.WriteMask
>> 1) & 0x1;
1383 pAsm
->D
.dst
.writez
= (pILInst
->DstReg
.WriteMask
>> 2) & 0x1;
1384 pAsm
->D
.dst
.writew
= (pILInst
->DstReg
.WriteMask
>> 3) & 0x1;
1389 GLboolean
tex_src(r700_AssemblerBase
*pAsm
)
1391 struct prog_instruction
*pILInst
= &(pAsm
->pILInst
[pAsm
->uiCurInst
]);
1393 GLboolean bValidTexCoord
= GL_FALSE
;
1395 if(pAsm
->aArgSubst
[1] >= 0)
1397 bValidTexCoord
= GL_TRUE
;
1398 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
1399 pAsm
->S
[0].src
.rtype
= SRC_REG_TEMPORARY
;
1400 pAsm
->S
[0].src
.reg
= pAsm
->aArgSubst
[1];
1404 switch (pILInst
->SrcReg
[0].File
) {
1405 case PROGRAM_UNIFORM
:
1406 case PROGRAM_CONSTANT
:
1407 case PROGRAM_LOCAL_PARAM
:
1408 case PROGRAM_ENV_PARAM
:
1409 case PROGRAM_STATE_VAR
:
1411 case PROGRAM_TEMPORARY
:
1412 bValidTexCoord
= GL_TRUE
;
1413 pAsm
->S
[0].src
.reg
= pILInst
->SrcReg
[0].Index
+
1414 pAsm
->starting_temp_register_number
;
1415 pAsm
->S
[0].src
.rtype
= SRC_REG_TEMPORARY
;
1418 if(SPT_VP
== pAsm
->currentShaderType
)
1420 switch (pILInst
->SrcReg
[0].Index
)
1422 case VERT_ATTRIB_TEX0
:
1423 case VERT_ATTRIB_TEX1
:
1424 case VERT_ATTRIB_TEX2
:
1425 case VERT_ATTRIB_TEX3
:
1426 case VERT_ATTRIB_TEX4
:
1427 case VERT_ATTRIB_TEX5
:
1428 case VERT_ATTRIB_TEX6
:
1429 case VERT_ATTRIB_TEX7
:
1430 bValidTexCoord
= GL_TRUE
;
1431 pAsm
->S
[0].src
.reg
=
1432 pAsm
->ucVP_AttributeMap
[pILInst
->SrcReg
[0].Index
];
1433 pAsm
->S
[0].src
.rtype
= SRC_REG_INPUT
;
1439 switch (pILInst
->SrcReg
[0].Index
)
1441 case FRAG_ATTRIB_WPOS
:
1442 case FRAG_ATTRIB_COL0
:
1443 case FRAG_ATTRIB_COL1
:
1444 case FRAG_ATTRIB_FOGC
:
1445 case FRAG_ATTRIB_TEX0
:
1446 case FRAG_ATTRIB_TEX1
:
1447 case FRAG_ATTRIB_TEX2
:
1448 case FRAG_ATTRIB_TEX3
:
1449 case FRAG_ATTRIB_TEX4
:
1450 case FRAG_ATTRIB_TEX5
:
1451 case FRAG_ATTRIB_TEX6
:
1452 case FRAG_ATTRIB_TEX7
:
1453 bValidTexCoord
= GL_TRUE
;
1454 pAsm
->S
[0].src
.reg
=
1455 pAsm
->uiFP_AttributeMap
[pILInst
->SrcReg
[0].Index
];
1456 pAsm
->S
[0].src
.rtype
= SRC_REG_INPUT
;
1458 case FRAG_ATTRIB_FACE
:
1459 fprintf(stderr
, "FRAG_ATTRIB_FACE unsupported\n");
1461 case FRAG_ATTRIB_PNTC
:
1462 fprintf(stderr
, "FRAG_ATTRIB_PNTC unsupported\n");
1466 if( (pILInst
->SrcReg
[0].Index
>= FRAG_ATTRIB_VAR0
) ||
1467 (pILInst
->SrcReg
[0].Index
< FRAG_ATTRIB_MAX
) )
1469 bValidTexCoord
= GL_TRUE
;
1470 pAsm
->S
[0].src
.reg
=
1471 pAsm
->uiFP_AttributeMap
[pILInst
->SrcReg
[0].Index
];
1472 pAsm
->S
[0].src
.rtype
= SRC_REG_INPUT
;
1480 if(GL_TRUE
== bValidTexCoord
)
1482 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
1486 radeon_error("Invalid source texcoord for TEX instruction\n");
1490 pAsm
->S
[0].src
.swizzlex
= pILInst
->SrcReg
[0].Swizzle
& 0x7;
1491 pAsm
->S
[0].src
.swizzley
= (pILInst
->SrcReg
[0].Swizzle
>> 3) & 0x7;
1492 pAsm
->S
[0].src
.swizzlez
= (pILInst
->SrcReg
[0].Swizzle
>> 6) & 0x7;
1493 pAsm
->S
[0].src
.swizzlew
= (pILInst
->SrcReg
[0].Swizzle
>> 9) & 0x7;
1495 pAsm
->S
[0].src
.negx
= pILInst
->SrcReg
[0].Negate
& 0x1;
1496 pAsm
->S
[0].src
.negy
= (pILInst
->SrcReg
[0].Negate
>> 1) & 0x1;
1497 pAsm
->S
[0].src
.negz
= (pILInst
->SrcReg
[0].Negate
>> 2) & 0x1;
1498 pAsm
->S
[0].src
.negw
= (pILInst
->SrcReg
[0].Negate
>> 3) & 0x1;
1503 GLboolean
assemble_tex_instruction(r700_AssemblerBase
*pAsm
, GLboolean normalized
)
1505 PVSSRC
* texture_coordinate_source
;
1506 PVSSRC
* texture_unit_source
;
1508 R700TextureInstruction
* tex_instruction_ptr
= (R700TextureInstruction
*) CALLOC_STRUCT(R700TextureInstruction
);
1509 if (tex_instruction_ptr
== NULL
)
1513 Init_R700TextureInstruction(tex_instruction_ptr
);
1515 texture_coordinate_source
= &(pAsm
->S
[0].src
);
1516 texture_unit_source
= &(pAsm
->S
[1].src
);
1518 tex_instruction_ptr
->m_Word0
.f
.tex_inst
= pAsm
->D
.dst
.opcode
;
1519 tex_instruction_ptr
->m_Word0
.f
.bc_frac_mode
= 0x0;
1520 tex_instruction_ptr
->m_Word0
.f
.fetch_whole_quad
= 0x0;
1521 tex_instruction_ptr
->m_Word0
.f
.alt_const
= 0;
1523 if(SPT_VP
== pAsm
->currentShaderType
)
1525 tex_instruction_ptr
->m_Word0
.f
.resource_id
= texture_unit_source
->reg
+ VERT_ATTRIB_MAX
;
1526 pAsm
->unVetTexBits
|= 1 << texture_unit_source
->reg
;
1530 tex_instruction_ptr
->m_Word0
.f
.resource_id
= texture_unit_source
->reg
;
1533 tex_instruction_ptr
->m_Word1
.f
.lod_bias
= 0x0;
1535 tex_instruction_ptr
->m_Word1
.f
.coord_type_x
= SQ_TEX_NORMALIZED
;
1536 tex_instruction_ptr
->m_Word1
.f
.coord_type_y
= SQ_TEX_NORMALIZED
;
1537 tex_instruction_ptr
->m_Word1
.f
.coord_type_z
= SQ_TEX_NORMALIZED
;
1538 tex_instruction_ptr
->m_Word1
.f
.coord_type_w
= SQ_TEX_NORMALIZED
;
1540 /* XXX: UNNORMALIZED tex coords have limited wrap modes */
1541 tex_instruction_ptr
->m_Word1
.f
.coord_type_x
= SQ_TEX_UNNORMALIZED
;
1542 tex_instruction_ptr
->m_Word1
.f
.coord_type_y
= SQ_TEX_UNNORMALIZED
;
1543 tex_instruction_ptr
->m_Word1
.f
.coord_type_z
= SQ_TEX_UNNORMALIZED
;
1544 tex_instruction_ptr
->m_Word1
.f
.coord_type_w
= SQ_TEX_UNNORMALIZED
;
1547 tex_instruction_ptr
->m_Word2
.f
.offset_x
= 0x0;
1548 tex_instruction_ptr
->m_Word2
.f
.offset_y
= 0x0;
1549 tex_instruction_ptr
->m_Word2
.f
.offset_z
= 0x0;
1550 tex_instruction_ptr
->m_Word2
.f
.sampler_id
= texture_unit_source
->reg
;
1553 if ( (pAsm
->D
.dst
.rtype
== DST_REG_TEMPORARY
) ||
1554 (pAsm
->D
.dst
.rtype
== DST_REG_OUT
) )
1556 tex_instruction_ptr
->m_Word0
.f
.src_gpr
= texture_coordinate_source
->reg
;
1557 tex_instruction_ptr
->m_Word0
.f
.src_rel
= SQ_ABSOLUTE
;
1559 tex_instruction_ptr
->m_Word1
.f
.dst_gpr
= pAsm
->D
.dst
.reg
;
1560 tex_instruction_ptr
->m_Word1
.f
.dst_rel
= SQ_ABSOLUTE
;
1562 tex_instruction_ptr
->m_Word1
.f
.dst_sel_x
= (pAsm
->D
.dst
.writex
? texture_unit_source
->swizzlex
: SQ_SEL_MASK
);
1563 tex_instruction_ptr
->m_Word1
.f
.dst_sel_y
= (pAsm
->D
.dst
.writey
? texture_unit_source
->swizzley
: SQ_SEL_MASK
);
1564 tex_instruction_ptr
->m_Word1
.f
.dst_sel_z
= (pAsm
->D
.dst
.writez
? texture_unit_source
->swizzlez
: SQ_SEL_MASK
);
1565 tex_instruction_ptr
->m_Word1
.f
.dst_sel_w
= (pAsm
->D
.dst
.writew
? texture_unit_source
->swizzlew
: SQ_SEL_MASK
);
1568 tex_instruction_ptr
->m_Word2
.f
.src_sel_x
= texture_coordinate_source
->swizzlex
;
1569 tex_instruction_ptr
->m_Word2
.f
.src_sel_y
= texture_coordinate_source
->swizzley
;
1570 tex_instruction_ptr
->m_Word2
.f
.src_sel_z
= texture_coordinate_source
->swizzlez
;
1571 tex_instruction_ptr
->m_Word2
.f
.src_sel_w
= texture_coordinate_source
->swizzlew
;
1575 radeon_error("Only temp destination registers supported for TEX dest regs.\n");
1579 if( GL_FALSE
== add_tex_instruction(pAsm
, tex_instruction_ptr
) )
1587 void initialize(r700_AssemblerBase
*pAsm
)
1589 GLuint cycle
, component
;
1591 for (cycle
=0; cycle
<NUMBER_OF_CYCLES
; cycle
++)
1593 for (component
=0; component
<NUMBER_OF_COMPONENTS
; component
++)
1595 pAsm
->hw_gpr
[cycle
][component
] = (-1);
1598 for (component
=0; component
<NUMBER_OF_COMPONENTS
; component
++)
1600 pAsm
->hw_cfile_addr
[component
] = (-1);
1601 pAsm
->hw_cfile_chan
[component
] = (-1);
1605 GLboolean
assemble_alu_src(R700ALUInstruction
* alu_instruction_ptr
,
1608 BITS scalar_channel_index
)
1615 //--------------------------------------------------------------------------
1616 // Source for operands src0, src1.
1617 // Values [0,127] correspond to GPR[0..127].
1618 // Values [256,511] correspond to cfile constants c[0..255].
1620 //--------------------------------------------------------------------------
1621 // Other special values are shown in the list below.
1623 // 248 SQ_ALU_SRC_0: special constant 0.0.
1624 // 249 SQ_ALU_SRC_1: special constant 1.0 float.
1626 // 250 SQ_ALU_SRC_1_INT: special constant 1 integer.
1627 // 251 SQ_ALU_SRC_M_1_INT: special constant -1 integer.
1629 // 252 SQ_ALU_SRC_0_5: special constant 0.5 float.
1630 // 253 SQ_ALU_SRC_LITERAL: literal constant.
1632 // 254 SQ_ALU_SRC_PV: previous vector result.
1633 // 255 SQ_ALU_SRC_PS: previous scalar result.
1634 //--------------------------------------------------------------------------
1636 BITS channel_swizzle
;
1637 switch (scalar_channel_index
)
1639 case 0: channel_swizzle
= pSource
->swizzlex
; break;
1640 case 1: channel_swizzle
= pSource
->swizzley
; break;
1641 case 2: channel_swizzle
= pSource
->swizzlez
; break;
1642 case 3: channel_swizzle
= pSource
->swizzlew
; break;
1643 default: channel_swizzle
= SQ_SEL_MASK
; break;
1646 if(channel_swizzle
== SQ_SEL_0
)
1648 src_sel
= SQ_ALU_SRC_0
;
1650 else if (channel_swizzle
== SQ_SEL_1
)
1652 src_sel
= SQ_ALU_SRC_1
;
1656 if ( (pSource
->rtype
== SRC_REG_TEMPORARY
) ||
1657 (pSource
->rtype
== SRC_REG_INPUT
)
1660 src_sel
= pSource
->reg
;
1662 else if (pSource
->rtype
== SRC_REG_CONSTANT
)
1664 src_sel
= pSource
->reg
+ CFILE_REGISTER_OFFSET
;
1666 else if (pSource
->rtype
== SRC_REC_LITERAL
)
1668 src_sel
= SQ_ALU_SRC_LITERAL
;
1672 radeon_error("Source (%d) register type (%d) not one of TEMP, INPUT, or CONSTANT.\n",
1673 source_index
, pSource
->rtype
);
1678 if( ADDR_ABSOLUTE
== addrmode_PVSSRC(pSource
) )
1680 src_rel
= SQ_ABSOLUTE
;
1684 src_rel
= SQ_RELATIVE
;
1687 switch (channel_swizzle
)
1690 src_chan
= SQ_CHAN_X
;
1693 src_chan
= SQ_CHAN_Y
;
1696 src_chan
= SQ_CHAN_Z
;
1699 src_chan
= SQ_CHAN_W
;
1703 // Does not matter since src_sel controls
1704 src_chan
= SQ_CHAN_X
;
1707 radeon_error("Unknown source select value (%d) in assemble_alu_src().\n", channel_swizzle
);
1712 switch (scalar_channel_index
)
1714 case 0: src_neg
= pSource
->negx
; break;
1715 case 1: src_neg
= pSource
->negy
; break;
1716 case 2: src_neg
= pSource
->negz
; break;
1717 case 3: src_neg
= pSource
->negw
; break;
1718 default: src_neg
= 0; break;
1721 switch (source_index
)
1724 alu_instruction_ptr
->m_Word0
.f
.src0_sel
= src_sel
;
1725 alu_instruction_ptr
->m_Word0
.f
.src0_rel
= src_rel
;
1726 alu_instruction_ptr
->m_Word0
.f
.src0_chan
= src_chan
;
1727 alu_instruction_ptr
->m_Word0
.f
.src0_neg
= src_neg
;
1730 alu_instruction_ptr
->m_Word0
.f
.src1_sel
= src_sel
;
1731 alu_instruction_ptr
->m_Word0
.f
.src1_rel
= src_rel
;
1732 alu_instruction_ptr
->m_Word0
.f
.src1_chan
= src_chan
;
1733 alu_instruction_ptr
->m_Word0
.f
.src1_neg
= src_neg
;
1736 alu_instruction_ptr
->m_Word1_OP3
.f
.src2_sel
= src_sel
;
1737 alu_instruction_ptr
->m_Word1_OP3
.f
.src2_rel
= src_rel
;
1738 alu_instruction_ptr
->m_Word1_OP3
.f
.src2_chan
= src_chan
;
1739 alu_instruction_ptr
->m_Word1_OP3
.f
.src2_neg
= src_neg
;
1742 radeon_error("Only three sources allowed in ALU opcodes.\n");
1750 GLboolean
add_alu_instruction(r700_AssemblerBase
* pAsm
,
1751 R700ALUInstruction
* alu_instruction_ptr
,
1752 GLuint contiguous_slots_needed
)
1754 if( GL_FALSE
== check_current_clause(pAsm
, CF_ALU_CLAUSE
) )
1759 if ( pAsm
->alu_x_opcode
!= 0 ||
1760 pAsm
->cf_current_alu_clause_ptr
== NULL
||
1761 ( (pAsm
->cf_current_alu_clause_ptr
!= NULL
) &&
1762 (pAsm
->cf_current_alu_clause_ptr
->m_Word1
.f
.count
>= (GetCFMaxInstructions(pAsm
->cf_current_alu_clause_ptr
->m_ShaderInstType
)-contiguous_slots_needed
-1) )
1766 //new cf inst for this clause
1767 pAsm
->cf_current_alu_clause_ptr
= (R700ControlFlowALUClause
*) CALLOC_STRUCT(R700ControlFlowALUClause
);
1769 // link the new cf to cf segment
1770 if(NULL
!= pAsm
->cf_current_alu_clause_ptr
)
1772 Init_R700ControlFlowALUClause(pAsm
->cf_current_alu_clause_ptr
);
1773 AddCFInstruction( pAsm
->pR700Shader
,
1774 (R700ControlFlowInstruction
*)pAsm
->cf_current_alu_clause_ptr
);
1778 radeon_error("Could not allocate a new ALU CF instruction.\n");
1782 pAsm
->cf_current_alu_clause_ptr
->m_Word0
.f
.kcache_bank0
= 0x0;
1783 pAsm
->cf_current_alu_clause_ptr
->m_Word0
.f
.kcache_bank1
= 0x0;
1784 pAsm
->cf_current_alu_clause_ptr
->m_Word0
.f
.kcache_mode0
= SQ_CF_KCACHE_NOP
;
1786 pAsm
->cf_current_alu_clause_ptr
->m_Word1
.f
.kcache_mode1
= SQ_CF_KCACHE_NOP
;
1787 pAsm
->cf_current_alu_clause_ptr
->m_Word1
.f
.kcache_addr0
= 0x0;
1788 pAsm
->cf_current_alu_clause_ptr
->m_Word1
.f
.kcache_addr1
= 0x0;
1790 pAsm
->cf_current_alu_clause_ptr
->m_Word1
.f
.count
= 0x0;
1792 if(pAsm
->alu_x_opcode
!= 0)
1794 pAsm
->cf_current_alu_clause_ptr
->m_Word1
.f
.cf_inst
= pAsm
->alu_x_opcode
;
1795 pAsm
->alu_x_opcode
= 0;
1799 pAsm
->cf_current_alu_clause_ptr
->m_Word1
.f
.cf_inst
= SQ_CF_INST_ALU
;
1802 pAsm
->cf_current_alu_clause_ptr
->m_Word1
.f
.whole_quad_mode
= 0x0;
1804 pAsm
->cf_current_alu_clause_ptr
->m_Word1
.f
.barrier
= 0x1;
1808 pAsm
->cf_current_alu_clause_ptr
->m_Word1
.f
.count
+= (GetInstructionSize(alu_instruction_ptr
->m_ShaderInstType
) / 2);
1811 // If this clause constains any instruction that is forward dependent on a TEX instruction,
1812 // set the whole_quad_mode for this clause
1813 if ( pAsm
->pInstDeps
[pAsm
->uiCurInst
].nDstDep
> (-1) )
1815 pAsm
->cf_current_alu_clause_ptr
->m_Word1
.f
.whole_quad_mode
= 0x1;
1818 if (pAsm
->cf_current_alu_clause_ptr
->m_Word1
.f
.count
>= (GetCFMaxInstructions(pAsm
->cf_current_alu_clause_ptr
->m_ShaderInstType
)-1) )
1820 alu_instruction_ptr
->m_Word0
.f
.last
= 1;
1823 if(NULL
== pAsm
->cf_current_alu_clause_ptr
->m_pLinkedALUInstruction
)
1825 pAsm
->cf_current_alu_clause_ptr
->m_pLinkedALUInstruction
= alu_instruction_ptr
;
1826 alu_instruction_ptr
->m_pLinkedALUClause
= pAsm
->cf_current_alu_clause_ptr
;
1829 AddALUInstruction(pAsm
->pR700Shader
, alu_instruction_ptr
);
1834 void get_src_properties(R700ALUInstruction
* alu_instruction_ptr
,
1841 switch (source_index
)
1844 *psrc_sel
= alu_instruction_ptr
->m_Word0
.f
.src0_sel
;
1845 *psrc_rel
= alu_instruction_ptr
->m_Word0
.f
.src0_rel
;
1846 *psrc_chan
= alu_instruction_ptr
->m_Word0
.f
.src0_chan
;
1847 *psrc_neg
= alu_instruction_ptr
->m_Word0
.f
.src0_neg
;
1851 *psrc_sel
= alu_instruction_ptr
->m_Word0
.f
.src1_sel
;
1852 *psrc_rel
= alu_instruction_ptr
->m_Word0
.f
.src1_rel
;
1853 *psrc_chan
= alu_instruction_ptr
->m_Word0
.f
.src1_chan
;
1854 *psrc_neg
= alu_instruction_ptr
->m_Word0
.f
.src1_neg
;
1858 *psrc_sel
= alu_instruction_ptr
->m_Word1_OP3
.f
.src2_sel
;
1859 *psrc_rel
= alu_instruction_ptr
->m_Word1_OP3
.f
.src2_rel
;
1860 *psrc_chan
= alu_instruction_ptr
->m_Word1_OP3
.f
.src2_chan
;
1861 *psrc_neg
= alu_instruction_ptr
->m_Word1_OP3
.f
.src2_neg
;
1866 int is_cfile(BITS sel
)
1868 if (sel
> 255 && sel
< 512)
1875 int is_const(BITS sel
)
1881 else if(sel
>= SQ_ALU_SRC_0
&& sel
<= SQ_ALU_SRC_LITERAL
)
1888 int is_gpr(BITS sel
)
1890 if (sel
>= 0 && sel
< 128)
1897 const GLuint BANK_SWIZZLE_VEC
[8] = {SQ_ALU_VEC_210
, //000
1898 SQ_ALU_VEC_120
, //001
1899 SQ_ALU_VEC_102
, //010
1901 SQ_ALU_VEC_201
, //011
1902 SQ_ALU_VEC_012
, //100
1903 SQ_ALU_VEC_021
, //101
1905 SQ_ALU_VEC_012
, //110
1906 SQ_ALU_VEC_012
}; //111
1908 const GLuint BANK_SWIZZLE_SCL
[8] = {SQ_ALU_SCL_210
, //000
1909 SQ_ALU_SCL_122
, //001
1910 SQ_ALU_SCL_122
, //010
1912 SQ_ALU_SCL_221
, //011
1913 SQ_ALU_SCL_212
, //100
1914 SQ_ALU_SCL_122
, //101
1916 SQ_ALU_SCL_122
, //110
1917 SQ_ALU_SCL_122
}; //111
1919 GLboolean
reserve_cfile(r700_AssemblerBase
* pAsm
,
1923 int res_match
= (-1);
1924 int res_empty
= (-1);
1928 for (res
=3; res
>=0; res
--)
1930 if(pAsm
->hw_cfile_addr
[ res
] < 0)
1934 else if( (pAsm
->hw_cfile_addr
[res
] == (int)sel
)
1936 (pAsm
->hw_cfile_chan
[ res
] == (int) chan
) )
1944 // Read for this scalar component already reserved, nothing to do here.
1947 else if(res_empty
>= 0)
1949 pAsm
->hw_cfile_addr
[ res_empty
] = sel
;
1950 pAsm
->hw_cfile_chan
[ res_empty
] = chan
;
1954 radeon_error("All cfile read ports are used, cannot reference C$sel, channel $chan.\n");
1960 GLboolean
reserve_gpr(r700_AssemblerBase
* pAsm
, GLuint sel
, GLuint chan
, GLuint cycle
)
1962 if(pAsm
->hw_gpr
[cycle
][chan
] < 0)
1964 pAsm
->hw_gpr
[cycle
][chan
] = sel
;
1966 else if(pAsm
->hw_gpr
[cycle
][chan
] != (int)sel
)
1968 radeon_error("Another scalar operation has already used GPR read port for given channel\n");
1975 GLboolean
cycle_for_scalar_bank_swizzle(const int swiz
, const int sel
, GLuint
* pCycle
)
1979 case SQ_ALU_SCL_210
:
1981 int table
[3] = {2, 1, 0};
1982 *pCycle
= table
[sel
];
1986 case SQ_ALU_SCL_122
:
1988 int table
[3] = {1, 2, 2};
1989 *pCycle
= table
[sel
];
1993 case SQ_ALU_SCL_212
:
1995 int table
[3] = {2, 1, 2};
1996 *pCycle
= table
[sel
];
2000 case SQ_ALU_SCL_221
:
2002 int table
[3] = {2, 2, 1};
2003 *pCycle
= table
[sel
];
2008 radeon_error("Bad Scalar bank swizzle value\n");
2015 GLboolean
cycle_for_vector_bank_swizzle(const int swiz
, const int sel
, GLuint
* pCycle
)
2019 case SQ_ALU_VEC_012
:
2021 int table
[3] = {0, 1, 2};
2022 *pCycle
= table
[sel
];
2025 case SQ_ALU_VEC_021
:
2027 int table
[3] = {0, 2, 1};
2028 *pCycle
= table
[sel
];
2031 case SQ_ALU_VEC_120
:
2033 int table
[3] = {1, 2, 0};
2034 *pCycle
= table
[sel
];
2037 case SQ_ALU_VEC_102
:
2039 int table
[3] = {1, 0, 2};
2040 *pCycle
= table
[sel
];
2043 case SQ_ALU_VEC_201
:
2045 int table
[3] = {2, 0, 1};
2046 *pCycle
= table
[sel
];
2049 case SQ_ALU_VEC_210
:
2051 int table
[3] = {2, 1, 0};
2052 *pCycle
= table
[sel
];
2056 radeon_error("Bad Vec bank swizzle value\n");
2064 GLboolean
check_scalar(r700_AssemblerBase
* pAsm
,
2065 R700ALUInstruction
* alu_instruction_ptr
)
2068 GLuint bank_swizzle
;
2069 GLuint const_count
= 0;
2078 BITS src_sel
[3] = {0,0,0};
2079 BITS src_chan
[3] = {0,0,0};
2080 BITS src_rel
[3] = {0,0,0};
2081 BITS src_neg
[3] = {0,0,0};
2085 GLuint number_of_operands
= r700GetNumOperands(pAsm
->D
.dst
.opcode
, pAsm
->D
.dst
.op3
);
2087 for (src
=0; src
<number_of_operands
; src
++)
2089 get_src_properties(alu_instruction_ptr
,
2098 swizzle_key
= ( (is_const( src_sel
[0] ) ? 4 : 0) +
2099 (is_const( src_sel
[1] ) ? 2 : 0) +
2100 (is_const( src_sel
[2] ) ? 1 : 0) );
2102 alu_instruction_ptr
->m_Word1
.f
.bank_swizzle
= BANK_SWIZZLE_SCL
[ swizzle_key
];
2104 for (src
=0; src
<number_of_operands
; src
++)
2106 sel
= src_sel
[src
];
2107 chan
= src_chan
[src
];
2108 rel
= src_rel
[src
];
2109 neg
= src_neg
[src
];
2111 if (is_const( sel
))
2113 // Any constant, including literal and inline constants
2116 if (is_cfile( sel
))
2118 reserve_cfile(pAsm
, sel
, chan
);
2124 for (src
=0; src
<number_of_operands
; src
++)
2126 sel
= src_sel
[src
];
2127 chan
= src_chan
[src
];
2128 rel
= src_rel
[src
];
2129 neg
= src_neg
[src
];
2133 bank_swizzle
= alu_instruction_ptr
->m_Word1
.f
.bank_swizzle
;
2135 if( GL_FALSE
== cycle_for_scalar_bank_swizzle(bank_swizzle
, src
, &cycle
) )
2140 if(cycle
< const_count
)
2142 if( GL_FALSE
== reserve_gpr(pAsm
, sel
, chan
, cycle
) )
2153 GLboolean
check_vector(r700_AssemblerBase
* pAsm
,
2154 R700ALUInstruction
* alu_instruction_ptr
)
2157 GLuint bank_swizzle
;
2158 GLuint const_count
= 0;
2167 BITS src_sel
[3] = {0,0,0};
2168 BITS src_chan
[3] = {0,0,0};
2169 BITS src_rel
[3] = {0,0,0};
2170 BITS src_neg
[3] = {0,0,0};
2174 GLuint number_of_operands
= r700GetNumOperands(pAsm
->D
.dst
.opcode
, pAsm
->D
.dst
.op3
);
2176 for (src
=0; src
<number_of_operands
; src
++)
2178 get_src_properties(alu_instruction_ptr
,
2187 swizzle_key
= ( (is_const( src_sel
[0] ) ? 4 : 0) +
2188 (is_const( src_sel
[1] ) ? 2 : 0) +
2189 (is_const( src_sel
[2] ) ? 1 : 0)
2192 alu_instruction_ptr
->m_Word1
.f
.bank_swizzle
= BANK_SWIZZLE_VEC
[swizzle_key
];
2194 for (src
=0; src
<number_of_operands
; src
++)
2196 sel
= src_sel
[src
];
2197 chan
= src_chan
[src
];
2198 rel
= src_rel
[src
];
2199 neg
= src_neg
[src
];
2202 bank_swizzle
= alu_instruction_ptr
->m_Word1
.f
.bank_swizzle
;
2206 if( GL_FALSE
== cycle_for_vector_bank_swizzle(bank_swizzle
, src
, &cycle
) )
2212 (sel
== src_sel
[0]) &&
2213 (chan
== src_chan
[0]) )
2218 if( GL_FALSE
== reserve_gpr(pAsm
, sel
, chan
, cycle
) )
2224 else if( is_const(sel
) )
2230 if( GL_FALSE
== reserve_cfile(pAsm
, sel
, chan
) )
2241 GLboolean
assemble_alu_instruction(r700_AssemblerBase
*pAsm
)
2243 R700ALUInstruction
* alu_instruction_ptr
;
2244 R700ALUInstructionHalfLiteral
* alu_instruction_ptr_hl
;
2245 R700ALUInstructionFullLiteral
* alu_instruction_ptr_fl
;
2247 GLuint number_of_scalar_operations
;
2248 GLboolean is_single_scalar_operation
;
2249 GLuint scalar_channel_index
;
2251 PVSSRC
* pcurrent_source
;
2252 int current_source_index
;
2253 GLuint contiguous_slots_needed
;
2255 GLuint uNumSrc
= r700GetNumOperands(pAsm
->D
.dst
.opcode
, pAsm
->D
.dst
.op3
);
2256 //GLuint channel_swizzle, j;
2257 //GLuint chan_counter[4] = {0, 0, 0, 0};
2258 //PVSSRC * pSource[3];
2259 GLboolean bSplitInst
= GL_FALSE
;
2261 if (1 == pAsm
->D
.dst
.math
)
2263 is_single_scalar_operation
= GL_TRUE
;
2264 number_of_scalar_operations
= 1;
2268 is_single_scalar_operation
= GL_FALSE
;
2269 number_of_scalar_operations
= 4;
2271 /* current assembler doesn't do more than 1 register per source */
2273 /* check read port, only very preliminary algorithm, not count in
2274 src0/1 same comp case and prev slot repeat case; also not count relative
2275 addressing. TODO: improve performance. */
2276 for(j
=0; j
<uNumSrc
; j
++)
2278 pSource
[j
] = &(pAsm
->S
[j
].src
);
2280 for(scalar_channel_index
=0; scalar_channel_index
<4; scalar_channel_index
++)
2282 for(j
=0; j
<uNumSrc
; j
++)
2284 switch (scalar_channel_index
)
2286 case 0: channel_swizzle
= pSource
[j
]->swizzlex
; break;
2287 case 1: channel_swizzle
= pSource
[j
]->swizzley
; break;
2288 case 2: channel_swizzle
= pSource
[j
]->swizzlez
; break;
2289 case 3: channel_swizzle
= pSource
[j
]->swizzlew
; break;
2290 default: channel_swizzle
= SQ_SEL_MASK
; break;
2292 if ( ((pSource
[j
]->rtype
== SRC_REG_TEMPORARY
) ||
2293 (pSource
[j
]->rtype
== SRC_REG_INPUT
))
2294 && (channel_swizzle
<= SQ_SEL_W
) )
2296 chan_counter
[channel_swizzle
]++;
2300 if( (chan_counter
[SQ_SEL_X
] > 3)
2301 || (chan_counter
[SQ_SEL_Y
] > 3)
2302 || (chan_counter
[SQ_SEL_Z
] > 3)
2303 || (chan_counter
[SQ_SEL_W
] > 3) ) /* each chan bank has only 3 ports. */
2305 bSplitInst
= GL_TRUE
;
2310 contiguous_slots_needed
= 0;
2312 if(!is_single_scalar_operation
)
2314 contiguous_slots_needed
= 4;
2317 contiguous_slots_needed
+= pAsm
->D2
.dst2
.literal_slots
;
2321 for (scalar_channel_index
=0;
2322 scalar_channel_index
< number_of_scalar_operations
;
2323 scalar_channel_index
++)
2325 if(scalar_channel_index
== (number_of_scalar_operations
-1))
2327 switch(pAsm
->D2
.dst2
.literal_slots
)
2330 alu_instruction_ptr
= (R700ALUInstruction
*) CALLOC_STRUCT(R700ALUInstruction
);
2331 Init_R700ALUInstruction(alu_instruction_ptr
);
2334 alu_instruction_ptr_hl
= (R700ALUInstructionHalfLiteral
*) CALLOC_STRUCT(R700ALUInstructionHalfLiteral
);
2335 Init_R700ALUInstructionHalfLiteral(alu_instruction_ptr_hl
, pAsm
->C
[0].f
, pAsm
->C
[1].f
);
2336 alu_instruction_ptr
= (R700ALUInstruction
*)alu_instruction_ptr_hl
;
2339 alu_instruction_ptr_fl
= (R700ALUInstructionFullLiteral
*) CALLOC_STRUCT(R700ALUInstructionFullLiteral
);
2340 Init_R700ALUInstructionFullLiteral(alu_instruction_ptr_fl
,pAsm
->C
[0].f
, pAsm
->C
[1].f
, pAsm
->C
[2].f
, pAsm
->C
[3].f
);
2341 alu_instruction_ptr
= (R700ALUInstruction
*)alu_instruction_ptr_fl
;
2347 alu_instruction_ptr
= (R700ALUInstruction
*) CALLOC_STRUCT(R700ALUInstruction
);
2348 Init_R700ALUInstruction(alu_instruction_ptr
);
2352 current_source_index
= 0;
2353 pcurrent_source
= &(pAsm
->S
[0].src
);
2355 if (GL_FALSE
== assemble_alu_src(alu_instruction_ptr
,
2356 current_source_index
,
2358 scalar_channel_index
) )
2366 current_source_index
= 1;
2367 pcurrent_source
= &(pAsm
->S
[current_source_index
].src
);
2369 if (GL_FALSE
== assemble_alu_src(alu_instruction_ptr
,
2370 current_source_index
,
2372 scalar_channel_index
) )
2379 alu_instruction_ptr
->m_Word0
.f
.index_mode
= pAsm
->D2
.dst2
.index_mode
;
2381 if( (is_single_scalar_operation
== GL_TRUE
)
2382 || (GL_TRUE
== bSplitInst
) )
2384 alu_instruction_ptr
->m_Word0
.f
.last
= 1;
2388 alu_instruction_ptr
->m_Word0
.f
.last
= (scalar_channel_index
== 3) ? 1 : 0;
2391 alu_instruction_ptr
->m_Word0
.f
.pred_sel
= (pAsm
->D
.dst
.pred_inv
> 0) ? 1 : 0;
2392 if(1 == pAsm
->D
.dst
.predicated
)
2394 alu_instruction_ptr
->m_Word1_OP2
.f
.update_pred
= 0x1;
2395 alu_instruction_ptr
->m_Word1_OP2
.f
.update_execute_mask
= 0x1;
2399 alu_instruction_ptr
->m_Word1_OP2
.f
.update_pred
= 0x0;
2400 alu_instruction_ptr
->m_Word1_OP2
.f
.update_execute_mask
= 0x0;
2404 if( (pAsm
->D
.dst
.rtype
== DST_REG_TEMPORARY
) ||
2405 (pAsm
->D
.dst
.rtype
== DST_REG_OUT
) )
2407 alu_instruction_ptr
->m_Word1
.f
.dst_gpr
= pAsm
->D
.dst
.reg
;
2411 radeon_error("Only temp destination registers supported for ALU dest regs.\n");
2415 alu_instruction_ptr
->m_Word1
.f
.dst_rel
= SQ_ABSOLUTE
; //D.rtype
2417 if ( is_single_scalar_operation
== GL_TRUE
)
2419 // Override scalar_channel_index since only one scalar value will be written
2420 if(pAsm
->D
.dst
.writex
)
2422 scalar_channel_index
= 0;
2424 else if(pAsm
->D
.dst
.writey
)
2426 scalar_channel_index
= 1;
2428 else if(pAsm
->D
.dst
.writez
)
2430 scalar_channel_index
= 2;
2432 else if(pAsm
->D
.dst
.writew
)
2434 scalar_channel_index
= 3;
2438 alu_instruction_ptr
->m_Word1
.f
.dst_chan
= scalar_channel_index
;
2440 alu_instruction_ptr
->m_Word1
.f
.clamp
= pAsm
->D2
.dst2
.SaturateMode
;
2442 if (pAsm
->D
.dst
.op3
)
2446 alu_instruction_ptr
->m_Word1_OP3
.f
.alu_inst
= pAsm
->D
.dst
.opcode
;
2448 //There's 3rd src for op3
2449 current_source_index
= 2;
2450 pcurrent_source
= &(pAsm
->S
[current_source_index
].src
);
2452 if ( GL_FALSE
== assemble_alu_src(alu_instruction_ptr
,
2453 current_source_index
,
2455 scalar_channel_index
) )
2465 alu_instruction_ptr
->m_Word1_OP2
.f6
.alu_inst
= pAsm
->D
.dst
.opcode
;
2467 alu_instruction_ptr
->m_Word1_OP2
.f6
.src0_abs
= pAsm
->S
[0].src
.abs
;
2468 alu_instruction_ptr
->m_Word1_OP2
.f6
.src1_abs
= pAsm
->S
[1].src
.abs
;
2470 //alu_instruction_ptr->m_Word1_OP2.f6.update_execute_mask = 0x0;
2471 //alu_instruction_ptr->m_Word1_OP2.f6.update_pred = 0x0;
2472 switch (scalar_channel_index
)
2475 alu_instruction_ptr
->m_Word1_OP2
.f6
.write_mask
= pAsm
->D
.dst
.writex
;
2478 alu_instruction_ptr
->m_Word1_OP2
.f6
.write_mask
= pAsm
->D
.dst
.writey
;
2481 alu_instruction_ptr
->m_Word1_OP2
.f6
.write_mask
= pAsm
->D
.dst
.writez
;
2484 alu_instruction_ptr
->m_Word1_OP2
.f6
.write_mask
= pAsm
->D
.dst
.writew
;
2487 alu_instruction_ptr
->m_Word1_OP2
.f6
.write_mask
= 1; //SQ_SEL_MASK;
2490 alu_instruction_ptr
->m_Word1_OP2
.f6
.omod
= SQ_ALU_OMOD_OFF
;
2494 alu_instruction_ptr
->m_Word1_OP2
.f
.alu_inst
= pAsm
->D
.dst
.opcode
;
2496 alu_instruction_ptr
->m_Word1_OP2
.f
.src0_abs
= pAsm
->S
[0].src
.abs
;
2497 alu_instruction_ptr
->m_Word1_OP2
.f
.src1_abs
= pAsm
->S
[1].src
.abs
;
2499 //alu_instruction_ptr->m_Word1_OP2.f.update_execute_mask = 0x0;
2500 //alu_instruction_ptr->m_Word1_OP2.f.update_pred = 0x0;
2501 switch (scalar_channel_index
)
2504 alu_instruction_ptr
->m_Word1_OP2
.f
.write_mask
= pAsm
->D
.dst
.writex
;
2507 alu_instruction_ptr
->m_Word1_OP2
.f
.write_mask
= pAsm
->D
.dst
.writey
;
2510 alu_instruction_ptr
->m_Word1_OP2
.f
.write_mask
= pAsm
->D
.dst
.writez
;
2513 alu_instruction_ptr
->m_Word1_OP2
.f
.write_mask
= pAsm
->D
.dst
.writew
;
2516 alu_instruction_ptr
->m_Word1_OP2
.f
.write_mask
= 1; //SQ_SEL_MASK;
2519 alu_instruction_ptr
->m_Word1_OP2
.f
.omod
= SQ_ALU_OMOD_OFF
;
2523 if(GL_FALSE
== add_alu_instruction(pAsm
, alu_instruction_ptr
, contiguous_slots_needed
) )
2529 * Judge the type of current instruction, is it vector or scalar
2532 if (is_single_scalar_operation
)
2534 if(GL_FALSE
== check_scalar(pAsm
, alu_instruction_ptr
) )
2541 if(GL_FALSE
== check_vector(pAsm
, alu_instruction_ptr
) )
2547 contiguous_slots_needed
-= 1;
2553 GLboolean
next_ins(r700_AssemblerBase
*pAsm
)
2555 struct prog_instruction
*pILInst
= &(pAsm
->pILInst
[pAsm
->uiCurInst
]);
2557 if( GL_TRUE
== pAsm
->is_tex
)
2559 if (pILInst
->TexSrcTarget
== TEXTURE_RECT_INDEX
) {
2560 if( GL_FALSE
== assemble_tex_instruction(pAsm
, GL_FALSE
) )
2562 radeon_error("Error assembling TEX instruction\n");
2566 if( GL_FALSE
== assemble_tex_instruction(pAsm
, GL_TRUE
) )
2568 radeon_error("Error assembling TEX instruction\n");
2575 if( GL_FALSE
== assemble_alu_instruction(pAsm
) )
2577 radeon_error("Error assembling ALU instruction\n");
2582 if(pAsm
->D
.dst
.rtype
== DST_REG_OUT
)
2586 // There is no mask for OP3 instructions, so all channels are written
2587 pAsm
->pucOutMask
[pAsm
->D
.dst
.reg
- pAsm
->starting_export_register_number
] = 0xF;
2591 pAsm
->pucOutMask
[pAsm
->D
.dst
.reg
- pAsm
->starting_export_register_number
]
2592 |= (unsigned char)pAsm
->pILInst
[pAsm
->uiCurInst
].DstReg
.WriteMask
;
2596 //reset for next inst.
2599 pAsm
->S
[0].bits
= 0;
2600 pAsm
->S
[1].bits
= 0;
2601 pAsm
->S
[2].bits
= 0;
2602 pAsm
->is_tex
= GL_FALSE
;
2603 pAsm
->need_tex_barrier
= GL_FALSE
;
2605 pAsm
->C
[0].bits
= pAsm
->C
[1].bits
= pAsm
->C
[2].bits
= pAsm
->C
[3].bits
= 0;
2609 GLboolean
assemble_math_function(r700_AssemblerBase
* pAsm
, BITS opcode
)
2615 tmp
= gethelpr(pAsm
);
2617 // opcode tmp.x, a.x
2620 pAsm
->D
.dst
.opcode
= opcode
;
2621 pAsm
->D
.dst
.math
= 1;
2623 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
2624 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
2625 pAsm
->D
.dst
.reg
= tmp
;
2626 pAsm
->D
.dst
.writex
= 1;
2628 if( GL_FALSE
== assemble_src(pAsm
, 0, -1) )
2633 if ( GL_FALSE
== next_ins(pAsm
) )
2638 // Now replicate result to all necessary channels in destination
2639 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_MOV
;
2641 if( GL_FALSE
== assemble_dst(pAsm
) )
2646 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
2647 pAsm
->S
[0].src
.rtype
= DST_REG_TEMPORARY
;
2648 pAsm
->S
[0].src
.reg
= tmp
;
2650 setswizzle_PVSSRC(&(pAsm
->S
[0].src
), SQ_SEL_X
);
2651 noneg_PVSSRC(&(pAsm
->S
[0].src
));
2653 if( GL_FALSE
== next_ins(pAsm
) )
2661 GLboolean
assemble_ABS(r700_AssemblerBase
*pAsm
)
2665 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_MAX
;
2667 if( GL_FALSE
== assemble_dst(pAsm
) )
2671 if( GL_FALSE
== assemble_src(pAsm
, 0, -1) )
2676 pAsm
->S
[1].bits
= pAsm
->S
[0].bits
;
2677 flipneg_PVSSRC(&(pAsm
->S
[1].src
));
2679 if ( GL_FALSE
== next_ins(pAsm
) )
2687 GLboolean
assemble_ADD(r700_AssemblerBase
*pAsm
)
2689 if( GL_FALSE
== checkop2(pAsm
) )
2694 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_ADD
;
2696 if( GL_FALSE
== assemble_dst(pAsm
) )
2701 if( GL_FALSE
== assemble_src(pAsm
, 0, -1) )
2706 if( GL_FALSE
== assemble_src(pAsm
, 1, -1) )
2711 if(pAsm
->pILInst
[pAsm
->uiCurInst
].Opcode
== OPCODE_SUB
)
2713 flipneg_PVSSRC(&(pAsm
->S
[1].src
));
2716 if( GL_FALSE
== next_ins(pAsm
) )
2724 GLboolean
assemble_ARL(r700_AssemblerBase
*pAsm
)
2725 { /* TODO: ar values dont' persist between clauses */
2726 if( GL_FALSE
== checkop1(pAsm
) )
2731 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_MOVA_FLOOR
;
2732 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
2733 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
2734 pAsm
->D
.dst
.reg
= 0;
2735 pAsm
->D
.dst
.writex
= 0;
2736 pAsm
->D
.dst
.writey
= 0;
2737 pAsm
->D
.dst
.writez
= 0;
2738 pAsm
->D
.dst
.writew
= 0;
2740 if( GL_FALSE
== assemble_src(pAsm
, 0, -1) )
2745 if( GL_FALSE
== next_ins(pAsm
) )
2753 GLboolean
assemble_BAD(char *opcode_str
)
2755 radeon_error("Not yet implemented instruction (%s)\n", opcode_str
);
2759 GLboolean
assemble_CMP(r700_AssemblerBase
*pAsm
)
2763 if( GL_FALSE
== checkop3(pAsm
) )
2768 pAsm
->D
.dst
.opcode
= SQ_OP3_INST_CNDGE
;
2769 pAsm
->D
.dst
.op3
= 1;
2773 if(0xF != pAsm
->pILInst
[pAsm
->uiCurInst
].DstReg
.WriteMask
)
2775 //OP3 has no support for write mask
2776 tmp
= gethelpr(pAsm
);
2778 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
2779 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
2780 pAsm
->D
.dst
.reg
= tmp
;
2782 nomask_PVSDST(&(pAsm
->D
.dst
));
2786 if( GL_FALSE
== assemble_dst(pAsm
) )
2792 if( GL_FALSE
== assemble_src(pAsm
, 0, -1) )
2797 if( GL_FALSE
== assemble_src(pAsm
, 2, 1) )
2802 if( GL_FALSE
== assemble_src(pAsm
, 1, 2) )
2807 if ( GL_FALSE
== next_ins(pAsm
) )
2812 if (0xF != pAsm
->pILInst
[pAsm
->uiCurInst
].DstReg
.WriteMask
)
2814 if( GL_FALSE
== assemble_dst(pAsm
) )
2819 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_MOV
;
2822 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
2823 pAsm
->S
[0].src
.rtype
= SRC_REG_TEMPORARY
;
2824 pAsm
->S
[0].src
.reg
= tmp
;
2826 noneg_PVSSRC(&(pAsm
->S
[0].src
));
2827 noswizzle_PVSSRC(&(pAsm
->S
[0].src
));
2829 if( GL_FALSE
== next_ins(pAsm
) )
2838 GLboolean
assemble_TRIG(r700_AssemblerBase
*pAsm
, BITS opcode
)
2843 tmp
= gethelpr(pAsm
);
2845 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_MUL
;
2846 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
2847 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
2848 pAsm
->D
.dst
.reg
= tmp
;
2849 pAsm
->D
.dst
.writex
= 1;
2851 assemble_src(pAsm
, 0, -1);
2853 pAsm
->S
[1].src
.rtype
= SRC_REC_LITERAL
;
2854 setswizzle_PVSSRC(&(pAsm
->S
[1].src
), SQ_SEL_X
);
2855 pAsm
->D2
.dst2
.literal_slots
= 1;
2856 pAsm
->C
[0].f
= 1/(3.1415926535 * 2);
2857 pAsm
->C
[1].f
= 0.0F
;
2860 pAsm
->D
.dst
.opcode
= opcode
;
2861 pAsm
->D
.dst
.math
= 1;
2865 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
2866 pAsm
->S
[0].src
.rtype
= SRC_REG_TEMPORARY
;
2867 pAsm
->S
[0].src
.reg
= tmp
;
2868 setswizzle_PVSSRC(&(pAsm
->S
[0].src
), SQ_SEL_X
);
2869 noneg_PVSSRC(&(pAsm
->S
[0].src
));
2873 //TODO - replicate if more channels set in WriteMask
2878 GLboolean
assemble_DOT(r700_AssemblerBase
*pAsm
)
2880 if( GL_FALSE
== checkop2(pAsm
) )
2885 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_DOT4
;
2887 if( GL_FALSE
== assemble_dst(pAsm
) )
2892 if( GL_FALSE
== assemble_src(pAsm
, 0, -1) )
2897 if( GL_FALSE
== assemble_src(pAsm
, 1, -1) )
2902 if(OPCODE_DP3
== pAsm
->pILInst
[pAsm
->uiCurInst
].Opcode
)
2904 zerocomp_PVSSRC(&(pAsm
->S
[0].src
), 3);
2905 zerocomp_PVSSRC(&(pAsm
->S
[1].src
), 3);
2907 else if(pAsm
->pILInst
[pAsm
->uiCurInst
].Opcode
== OPCODE_DPH
)
2909 onecomp_PVSSRC(&(pAsm
->S
[0].src
), 3);
2912 if ( GL_FALSE
== next_ins(pAsm
) )
2920 GLboolean
assemble_DST(r700_AssemblerBase
*pAsm
)
2922 if( GL_FALSE
== checkop2(pAsm
) )
2927 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_MUL
;
2929 if( GL_FALSE
== assemble_dst(pAsm
) )
2934 if( GL_FALSE
== assemble_src(pAsm
, 0, -1) )
2939 if( GL_FALSE
== assemble_src(pAsm
, 1, -1) )
2944 onecomp_PVSSRC(&(pAsm
->S
[0].src
), 0);
2945 onecomp_PVSSRC(&(pAsm
->S
[0].src
), 3);
2947 onecomp_PVSSRC(&(pAsm
->S
[1].src
), 0);
2948 onecomp_PVSSRC(&(pAsm
->S
[1].src
), 2);
2950 if ( GL_FALSE
== next_ins(pAsm
) )
2958 GLboolean
assemble_EX2(r700_AssemblerBase
*pAsm
)
2960 return assemble_math_function(pAsm
, SQ_OP2_INST_EXP_IEEE
);
2963 GLboolean
assemble_EXP(r700_AssemblerBase
*pAsm
)
2969 tmp
= gethelpr(pAsm
);
2974 if (pAsm
->pILInst
->DstReg
.WriteMask
& 0x1) {
2975 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_FLOOR
;
2977 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
2978 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
2979 pAsm
->D
.dst
.reg
= tmp
;
2980 pAsm
->D
.dst
.writex
= 1;
2982 if( GL_FALSE
== assemble_src(pAsm
, 0, -1) )
2987 if( GL_FALSE
== next_ins(pAsm
) )
2992 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_EXP_IEEE
;
2993 pAsm
->D
.dst
.math
= 1;
2995 if( GL_FALSE
== assemble_dst(pAsm
) )
3000 pAsm
->D
.dst
.writey
= pAsm
->D
.dst
.writez
= pAsm
->D
.dst
.writew
= 0;
3002 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
3003 pAsm
->S
[0].src
.rtype
= DST_REG_TEMPORARY
;
3004 pAsm
->S
[0].src
.reg
= tmp
;
3006 setswizzle_PVSSRC(&(pAsm
->S
[0].src
), SQ_SEL_X
);
3007 noneg_PVSSRC(&(pAsm
->S
[0].src
));
3009 if( GL_FALSE
== next_ins(pAsm
) )
3017 if ((pAsm
->pILInst
->DstReg
.WriteMask
>> 1) & 0x1) {
3018 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_FRACT
;
3020 if( GL_FALSE
== assemble_dst(pAsm
) )
3025 if( GL_FALSE
== assemble_src(pAsm
, 0, -1) )
3030 pAsm
->D
.dst
.writex
= pAsm
->D
.dst
.writez
= pAsm
->D
.dst
.writew
= 0;
3032 if( GL_FALSE
== next_ins(pAsm
) )
3040 if ((pAsm
->pILInst
->DstReg
.WriteMask
>> 2) & 0x1) {
3041 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_EXP_IEEE
;
3042 pAsm
->D
.dst
.math
= 1;
3044 if( GL_FALSE
== assemble_dst(pAsm
) )
3049 if( GL_FALSE
== assemble_src(pAsm
, 0, -1) )
3054 pAsm
->D
.dst
.writex
= pAsm
->D
.dst
.writey
= pAsm
->D
.dst
.writew
= 0;
3056 if( GL_FALSE
== next_ins(pAsm
) )
3064 if ((pAsm
->pILInst
->DstReg
.WriteMask
>> 3) & 0x1) {
3065 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_MOV
;
3067 if( GL_FALSE
== assemble_dst(pAsm
) )
3072 pAsm
->D
.dst
.writex
= pAsm
->D
.dst
.writey
= pAsm
->D
.dst
.writez
= 0;
3074 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
3075 pAsm
->S
[0].src
.rtype
= SRC_REG_TEMPORARY
;
3076 pAsm
->S
[0].src
.reg
= tmp
;
3078 setswizzle_PVSSRC(&(pAsm
->S
[0].src
), SQ_SEL_1
);
3079 noneg_PVSSRC(&(pAsm
->S
[0].src
));
3081 if( GL_FALSE
== next_ins(pAsm
) )
3090 GLboolean
assemble_FLR(r700_AssemblerBase
*pAsm
)
3094 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_FLOOR
;
3096 if ( GL_FALSE
== assemble_dst(pAsm
) )
3101 if ( GL_FALSE
== assemble_src(pAsm
, 0, -1) )
3106 if ( GL_FALSE
== next_ins(pAsm
) )
3114 GLboolean
assemble_FLR_INT(r700_AssemblerBase
*pAsm
)
3116 return assemble_math_function(pAsm
, SQ_OP2_INST_FLT_TO_INT
);
3119 GLboolean
assemble_FRC(r700_AssemblerBase
*pAsm
)
3123 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_FRACT
;
3125 if ( GL_FALSE
== assemble_dst(pAsm
) )
3130 if ( GL_FALSE
== assemble_src(pAsm
, 0, -1) )
3135 if ( GL_FALSE
== next_ins(pAsm
) )
3143 GLboolean
assemble_KIL(r700_AssemblerBase
*pAsm
, GLuint opcode
)
3145 struct prog_instruction
*pILInst
= &(pAsm
->pILInst
[pAsm
->uiCurInst
]);
3147 if(pILInst
->Opcode
== OPCODE_KIL
)
3150 pAsm
->D
.dst
.opcode
= opcode
;
3151 //pAsm->D.dst.math = 1;
3153 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
3154 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
3155 pAsm
->D
.dst
.reg
= 0;
3156 pAsm
->D
.dst
.writex
= 0;
3157 pAsm
->D
.dst
.writey
= 0;
3158 pAsm
->D
.dst
.writez
= 0;
3159 pAsm
->D
.dst
.writew
= 0;
3161 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
3162 pAsm
->S
[0].src
.rtype
= SRC_REG_TEMPORARY
;
3163 pAsm
->S
[0].src
.reg
= 0;
3164 setswizzle_PVSSRC(&(pAsm
->S
[0].src
), SQ_SEL_0
);
3165 noneg_PVSSRC(&(pAsm
->S
[0].src
));
3167 if(pILInst
->Opcode
== OPCODE_KIL_NV
)
3169 setaddrmode_PVSSRC(&(pAsm
->S
[1].src
), ADDR_ABSOLUTE
);
3170 pAsm
->S
[1].src
.rtype
= SRC_REG_TEMPORARY
;
3171 pAsm
->S
[1].src
.reg
= 0;
3172 setswizzle_PVSSRC(&(pAsm
->S
[1].src
), SQ_SEL_1
);
3173 neg_PVSSRC(&(pAsm
->S
[1].src
));
3177 if( GL_FALSE
== assemble_src(pAsm
, 0, 1) )
3184 if ( GL_FALSE
== next_ins(pAsm
) )
3189 /* Doc says KILL has to be last(end) ALU clause */
3190 pAsm
->pR700Shader
->killIsUsed
= GL_TRUE
;
3191 pAsm
->alu_x_opcode
= SQ_CF_INST_ALU
;
3196 GLboolean
assemble_LG2(r700_AssemblerBase
*pAsm
)
3198 return assemble_math_function(pAsm
, SQ_OP2_INST_LOG_IEEE
);
3201 GLboolean
assemble_LRP(r700_AssemblerBase
*pAsm
)
3205 if( GL_FALSE
== checkop3(pAsm
) )
3210 tmp
= gethelpr(pAsm
);
3212 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_ADD
;
3214 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
3215 pAsm
->D
.dst
.reg
= tmp
;
3216 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
3217 nomask_PVSDST(&(pAsm
->D
.dst
));
3220 if( GL_FALSE
== assemble_src(pAsm
, 1, 0) )
3225 if ( GL_FALSE
== assemble_src(pAsm
, 2, 1) )
3230 neg_PVSSRC(&(pAsm
->S
[1].src
));
3232 if( GL_FALSE
== next_ins(pAsm
) )
3237 pAsm
->D
.dst
.opcode
= SQ_OP3_INST_MULADD
;
3238 pAsm
->D
.dst
.op3
= 1;
3240 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
3241 pAsm
->D
.dst
.reg
= tmp
;
3242 nomask_PVSDST(&(pAsm
->D
.dst
));
3243 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
3245 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
3246 pAsm
->S
[0].src
.rtype
= SRC_REG_TEMPORARY
;
3247 pAsm
->S
[0].src
.reg
= tmp
;
3248 noswizzle_PVSSRC(&(pAsm
->S
[0].src
));
3251 if( GL_FALSE
== assemble_src(pAsm
, 0, 1) )
3256 if( GL_FALSE
== assemble_src(pAsm
, 2, -1) )
3261 if( GL_FALSE
== next_ins(pAsm
) )
3266 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_MOV
;
3268 if( GL_FALSE
== assemble_dst(pAsm
) )
3273 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
3274 pAsm
->S
[0].src
.rtype
= SRC_REG_TEMPORARY
;
3275 pAsm
->S
[0].src
.reg
= tmp
;
3276 noswizzle_PVSSRC(&(pAsm
->S
[0].src
));
3278 if( GL_FALSE
== next_ins(pAsm
) )
3286 GLboolean
assemble_LOG(r700_AssemblerBase
*pAsm
)
3288 BITS tmp1
, tmp2
, tmp3
;
3292 tmp1
= gethelpr(pAsm
);
3293 tmp2
= gethelpr(pAsm
);
3294 tmp3
= gethelpr(pAsm
);
3296 // FIXME: The hardware can do fabs() directly on input
3297 // elements, but the compiler doesn't have the
3298 // capability to use that.
3300 // MAX tmp1.x, a.x, -a.x (fabs(a.x))
3302 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_MAX
;
3304 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
3305 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
3306 pAsm
->D
.dst
.reg
= tmp1
;
3307 pAsm
->D
.dst
.writex
= 1;
3309 if( GL_FALSE
== assemble_src(pAsm
, 0, -1) )
3314 pAsm
->S
[1].bits
= pAsm
->S
[0].bits
;
3315 flipneg_PVSSRC(&(pAsm
->S
[1].src
));
3317 if ( GL_FALSE
== next_ins(pAsm
) )
3324 // LG2 tmp2.x, tmp1.x
3325 // FLOOR tmp3.x, tmp2.x
3326 // MOV dst.x, tmp3.x
3327 // ADD tmp3.x, tmp2.x, -tmp3.x
3328 // EX2 dst.y, tmp3.x
3329 // MOV dst.z, tmp2.x
3332 // LG2 tmp2.x, tmp1.x
3333 // FLOOR tmp3.x, tmp2.x
3335 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_LOG_IEEE
;
3336 pAsm
->D
.dst
.math
= 1;
3338 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
3339 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
3340 pAsm
->D
.dst
.reg
= tmp2
;
3341 pAsm
->D
.dst
.writex
= 1;
3343 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
3344 pAsm
->S
[0].src
.rtype
= DST_REG_TEMPORARY
;
3345 pAsm
->S
[0].src
.reg
= tmp1
;
3347 setswizzle_PVSSRC(&(pAsm
->S
[0].src
), SQ_SEL_X
);
3348 noneg_PVSSRC(&(pAsm
->S
[0].src
));
3350 if( GL_FALSE
== next_ins(pAsm
) )
3355 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_FLOOR
;
3357 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
3358 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
3359 pAsm
->D
.dst
.reg
= tmp3
;
3360 pAsm
->D
.dst
.writex
= 1;
3362 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
3363 pAsm
->S
[0].src
.rtype
= DST_REG_TEMPORARY
;
3364 pAsm
->S
[0].src
.reg
= tmp2
;
3366 setswizzle_PVSSRC(&(pAsm
->S
[0].src
), SQ_SEL_X
);
3367 noneg_PVSSRC(&(pAsm
->S
[0].src
));
3369 if( GL_FALSE
== next_ins(pAsm
) )
3374 // MOV dst.x, tmp3.x
3376 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_MOV
;
3378 if( GL_FALSE
== assemble_dst(pAsm
) )
3383 pAsm
->D
.dst
.writey
= pAsm
->D
.dst
.writez
= pAsm
->D
.dst
.writew
= 0;
3385 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
3386 pAsm
->S
[0].src
.rtype
= DST_REG_TEMPORARY
;
3387 pAsm
->S
[0].src
.reg
= tmp3
;
3389 setswizzle_PVSSRC(&(pAsm
->S
[0].src
), SQ_SEL_X
);
3390 noneg_PVSSRC(&(pAsm
->S
[0].src
));
3392 if( GL_FALSE
== next_ins(pAsm
) )
3397 // ADD tmp3.x, tmp2.x, -tmp3.x
3398 // EX2 dst.y, tmp3.x
3400 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_ADD
;
3402 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
3403 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
3404 pAsm
->D
.dst
.reg
= tmp3
;
3405 pAsm
->D
.dst
.writex
= 1;
3407 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
3408 pAsm
->S
[0].src
.rtype
= DST_REG_TEMPORARY
;
3409 pAsm
->S
[0].src
.reg
= tmp2
;
3411 setswizzle_PVSSRC(&(pAsm
->S
[0].src
), SQ_SEL_X
);
3412 noneg_PVSSRC(&(pAsm
->S
[0].src
));
3414 setaddrmode_PVSSRC(&(pAsm
->S
[1].src
), ADDR_ABSOLUTE
);
3415 pAsm
->S
[1].src
.rtype
= DST_REG_TEMPORARY
;
3416 pAsm
->S
[1].src
.reg
= tmp3
;
3418 setswizzle_PVSSRC(&(pAsm
->S
[1].src
), SQ_SEL_X
);
3419 neg_PVSSRC(&(pAsm
->S
[1].src
));
3421 if( GL_FALSE
== next_ins(pAsm
) )
3426 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_EXP_IEEE
;
3427 pAsm
->D
.dst
.math
= 1;
3429 if( GL_FALSE
== assemble_dst(pAsm
) )
3434 pAsm
->D
.dst
.writex
= pAsm
->D
.dst
.writez
= pAsm
->D
.dst
.writew
= 0;
3436 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
3437 pAsm
->S
[0].src
.rtype
= DST_REG_TEMPORARY
;
3438 pAsm
->S
[0].src
.reg
= tmp3
;
3440 setswizzle_PVSSRC(&(pAsm
->S
[0].src
), SQ_SEL_X
);
3441 noneg_PVSSRC(&(pAsm
->S
[0].src
));
3443 if( GL_FALSE
== next_ins(pAsm
) )
3448 // MOV dst.z, tmp2.x
3450 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_MOV
;
3452 if( GL_FALSE
== assemble_dst(pAsm
) )
3457 pAsm
->D
.dst
.writex
= pAsm
->D
.dst
.writey
= pAsm
->D
.dst
.writew
= 0;
3459 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
3460 pAsm
->S
[0].src
.rtype
= DST_REG_TEMPORARY
;
3461 pAsm
->S
[0].src
.reg
= tmp2
;
3463 setswizzle_PVSSRC(&(pAsm
->S
[0].src
), SQ_SEL_X
);
3464 noneg_PVSSRC(&(pAsm
->S
[0].src
));
3466 if( GL_FALSE
== next_ins(pAsm
) )
3473 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_MOV
;
3475 if( GL_FALSE
== assemble_dst(pAsm
) )
3480 pAsm
->D
.dst
.writex
= pAsm
->D
.dst
.writey
= pAsm
->D
.dst
.writez
= 0;
3482 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
3483 pAsm
->S
[0].src
.rtype
= SRC_REG_TEMPORARY
;
3484 pAsm
->S
[0].src
.reg
= tmp1
;
3486 setswizzle_PVSSRC(&(pAsm
->S
[0].src
), SQ_SEL_1
);
3487 noneg_PVSSRC(&(pAsm
->S
[0].src
));
3489 if( GL_FALSE
== next_ins(pAsm
) )
3497 GLboolean
assemble_MAD(struct r700_AssemblerBase
*pAsm
)
3500 GLboolean bReplaceDst
= GL_FALSE
;
3501 struct prog_instruction
*pILInst
= &(pAsm
->pILInst
[pAsm
->uiCurInst
]);
3503 if( GL_FALSE
== checkop3(pAsm
) )
3508 pAsm
->D
.dst
.opcode
= SQ_OP3_INST_MULADD
;
3509 pAsm
->D
.dst
.op3
= 1;
3513 if(PROGRAM_TEMPORARY
== pILInst
->DstReg
.File
)
3514 { /* TODO : more investigation on MAD src and dst using same register */
3515 for(ii
=0; ii
<3; ii
++)
3517 if( (PROGRAM_TEMPORARY
== pILInst
->SrcReg
[ii
].File
)
3518 && (pILInst
->DstReg
.Index
== pILInst
->SrcReg
[ii
].Index
) )
3520 bReplaceDst
= GL_TRUE
;
3525 if(0xF != pILInst
->DstReg
.WriteMask
)
3526 { /* OP3 has no support for write mask */
3527 bReplaceDst
= GL_TRUE
;
3530 if(GL_TRUE
== bReplaceDst
)
3532 tmp
= gethelpr(pAsm
);
3534 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
3535 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
3536 pAsm
->D
.dst
.reg
= tmp
;
3538 nomask_PVSDST(&(pAsm
->D
.dst
));
3542 if( GL_FALSE
== assemble_dst(pAsm
) )
3548 if( GL_FALSE
== assemble_src(pAsm
, 0, -1) )
3553 if( GL_FALSE
== assemble_src(pAsm
, 1, -1) )
3558 if( GL_FALSE
== assemble_src(pAsm
, 2, -1) )
3563 if ( GL_FALSE
== next_ins(pAsm
) )
3568 if (GL_TRUE
== bReplaceDst
)
3570 if( GL_FALSE
== assemble_dst(pAsm
) )
3575 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_MOV
;
3578 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
3579 pAsm
->S
[0].src
.rtype
= SRC_REG_TEMPORARY
;
3580 pAsm
->S
[0].src
.reg
= tmp
;
3582 noneg_PVSSRC(&(pAsm
->S
[0].src
));
3583 noswizzle_PVSSRC(&(pAsm
->S
[0].src
));
3585 if( GL_FALSE
== next_ins(pAsm
) )
3595 GLboolean
assemble_LIT(r700_AssemblerBase
*pAsm
)
3597 unsigned int dstReg
;
3598 unsigned int dstType
;
3599 unsigned int srcReg
;
3600 unsigned int srcType
;
3602 int tmp
= gethelpr(pAsm
);
3604 if( GL_FALSE
== assemble_dst(pAsm
) )
3608 if( GL_FALSE
== assemble_src(pAsm
, 0, -1) )
3612 dstReg
= pAsm
->D
.dst
.reg
;
3613 dstType
= pAsm
->D
.dst
.rtype
;
3614 srcReg
= pAsm
->S
[0].src
.reg
;
3615 srcType
= pAsm
->S
[0].src
.rtype
;
3617 /* dst.xw, <- 1.0 */
3618 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_MOV
;
3619 pAsm
->D
.dst
.rtype
= dstType
;
3620 pAsm
->D
.dst
.reg
= dstReg
;
3621 pAsm
->D
.dst
.writex
= 1;
3622 pAsm
->D
.dst
.writey
= 0;
3623 pAsm
->D
.dst
.writez
= 0;
3624 pAsm
->D
.dst
.writew
= 1;
3625 pAsm
->S
[0].src
.rtype
= SRC_REG_TEMPORARY
;
3626 pAsm
->S
[0].src
.reg
= tmp
;
3627 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
3628 noneg_PVSSRC(&(pAsm
->S
[0].src
));
3629 pAsm
->S
[0].src
.swizzlex
= SQ_SEL_1
;
3630 pAsm
->S
[0].src
.swizzley
= SQ_SEL_1
;
3631 pAsm
->S
[0].src
.swizzlez
= SQ_SEL_1
;
3632 pAsm
->S
[0].src
.swizzlew
= SQ_SEL_1
;
3633 if( GL_FALSE
== next_ins(pAsm
) )
3638 if( GL_FALSE
== assemble_src(pAsm
, 0, -1) )
3643 /* dst.y = max(src.x, 0.0) */
3644 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_MAX
;
3645 pAsm
->D
.dst
.rtype
= dstType
;
3646 pAsm
->D
.dst
.reg
= dstReg
;
3647 pAsm
->D
.dst
.writex
= 0;
3648 pAsm
->D
.dst
.writey
= 1;
3649 pAsm
->D
.dst
.writez
= 0;
3650 pAsm
->D
.dst
.writew
= 0;
3651 pAsm
->S
[0].src
.rtype
= srcType
;
3652 pAsm
->S
[0].src
.reg
= srcReg
;
3653 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
3654 swizzleagain_PVSSRC(&(pAsm
->S
[0].src
), SQ_SEL_X
, SQ_SEL_X
, SQ_SEL_X
, SQ_SEL_X
);
3655 pAsm
->S
[1].src
.rtype
= SRC_REG_TEMPORARY
;
3656 pAsm
->S
[1].src
.reg
= tmp
;
3657 setaddrmode_PVSSRC(&(pAsm
->S
[1].src
), ADDR_ABSOLUTE
);
3658 noneg_PVSSRC(&(pAsm
->S
[1].src
));
3659 pAsm
->S
[1].src
.swizzlex
= SQ_SEL_0
;
3660 pAsm
->S
[1].src
.swizzley
= SQ_SEL_0
;
3661 pAsm
->S
[1].src
.swizzlez
= SQ_SEL_0
;
3662 pAsm
->S
[1].src
.swizzlew
= SQ_SEL_0
;
3663 if( GL_FALSE
== next_ins(pAsm
) )
3668 if( GL_FALSE
== assemble_src(pAsm
, 0, -1) )
3673 swizzleagain_PVSSRC(&(pAsm
->S
[0].src
), SQ_SEL_Y
, SQ_SEL_Y
, SQ_SEL_Y
, SQ_SEL_Y
);
3675 /* dst.z = log(src.y) */
3676 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_LOG_CLAMPED
;
3677 pAsm
->D
.dst
.math
= 1;
3678 pAsm
->D
.dst
.rtype
= dstType
;
3679 pAsm
->D
.dst
.reg
= dstReg
;
3680 pAsm
->D
.dst
.writex
= 0;
3681 pAsm
->D
.dst
.writey
= 0;
3682 pAsm
->D
.dst
.writez
= 1;
3683 pAsm
->D
.dst
.writew
= 0;
3684 pAsm
->S
[0].src
.rtype
= srcType
;
3685 pAsm
->S
[0].src
.reg
= srcReg
;
3686 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
3687 if( GL_FALSE
== next_ins(pAsm
) )
3692 if( GL_FALSE
== assemble_src(pAsm
, 0, -1) )
3697 if( GL_FALSE
== assemble_src(pAsm
, 0, 2) )
3702 swizzleagain_PVSSRC(&(pAsm
->S
[0].src
), SQ_SEL_W
, SQ_SEL_W
, SQ_SEL_W
, SQ_SEL_W
);
3704 swizzleagain_PVSSRC(&(pAsm
->S
[2].src
), SQ_SEL_X
, SQ_SEL_X
, SQ_SEL_X
, SQ_SEL_X
);
3706 /* tmp.x = amd MUL_LIT(src.w, dst.z, src.x ) */
3707 pAsm
->D
.dst
.opcode
= SQ_OP3_INST_MUL_LIT
;
3708 pAsm
->D
.dst
.math
= 1;
3709 pAsm
->D
.dst
.op3
= 1;
3710 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
3711 pAsm
->D
.dst
.reg
= tmp
;
3712 pAsm
->D
.dst
.writex
= 1;
3713 pAsm
->D
.dst
.writey
= 0;
3714 pAsm
->D
.dst
.writez
= 0;
3715 pAsm
->D
.dst
.writew
= 0;
3717 pAsm
->S
[0].src
.rtype
= srcType
;
3718 pAsm
->S
[0].src
.reg
= srcReg
;
3719 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
3721 pAsm
->S
[1].src
.rtype
= SRC_REG_TEMPORARY
;
3722 pAsm
->S
[1].src
.reg
= dstReg
;
3723 setaddrmode_PVSSRC(&(pAsm
->S
[1].src
), ADDR_ABSOLUTE
);
3724 noneg_PVSSRC(&(pAsm
->S
[1].src
));
3725 pAsm
->S
[1].src
.swizzlex
= SQ_SEL_Z
;
3726 pAsm
->S
[1].src
.swizzley
= SQ_SEL_Z
;
3727 pAsm
->S
[1].src
.swizzlez
= SQ_SEL_Z
;
3728 pAsm
->S
[1].src
.swizzlew
= SQ_SEL_Z
;
3730 pAsm
->S
[2].src
.rtype
= srcType
;
3731 pAsm
->S
[2].src
.reg
= srcReg
;
3732 setaddrmode_PVSSRC(&(pAsm
->S
[2].src
), ADDR_ABSOLUTE
);
3734 if( GL_FALSE
== next_ins(pAsm
) )
3739 /* dst.z = exp(tmp.x) */
3740 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_EXP_IEEE
;
3741 pAsm
->D
.dst
.math
= 1;
3742 pAsm
->D
.dst
.rtype
= dstType
;
3743 pAsm
->D
.dst
.reg
= dstReg
;
3744 pAsm
->D
.dst
.writex
= 0;
3745 pAsm
->D
.dst
.writey
= 0;
3746 pAsm
->D
.dst
.writez
= 1;
3747 pAsm
->D
.dst
.writew
= 0;
3749 pAsm
->S
[0].src
.rtype
= SRC_REG_TEMPORARY
;
3750 pAsm
->S
[0].src
.reg
= tmp
;
3751 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
3752 noneg_PVSSRC(&(pAsm
->S
[0].src
));
3753 pAsm
->S
[0].src
.swizzlex
= SQ_SEL_X
;
3754 pAsm
->S
[0].src
.swizzley
= SQ_SEL_X
;
3755 pAsm
->S
[0].src
.swizzlez
= SQ_SEL_X
;
3756 pAsm
->S
[0].src
.swizzlew
= SQ_SEL_X
;
3758 if( GL_FALSE
== next_ins(pAsm
) )
3766 GLboolean
assemble_MAX(r700_AssemblerBase
*pAsm
)
3768 if( GL_FALSE
== checkop2(pAsm
) )
3773 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_MAX
;
3775 if( GL_FALSE
== assemble_dst(pAsm
) )
3780 if( GL_FALSE
== assemble_src(pAsm
, 0, -1) )
3785 if( GL_FALSE
== assemble_src(pAsm
, 1, -1) )
3790 if( GL_FALSE
== next_ins(pAsm
) )
3798 GLboolean
assemble_MIN(r700_AssemblerBase
*pAsm
)
3800 if( GL_FALSE
== checkop2(pAsm
) )
3805 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_MIN
;
3807 if( GL_FALSE
== assemble_dst(pAsm
) )
3812 if( GL_FALSE
== assemble_src(pAsm
, 0, -1) )
3817 if( GL_FALSE
== assemble_src(pAsm
, 1, -1) )
3822 if( GL_FALSE
== next_ins(pAsm
) )
3830 GLboolean
assemble_MOV(r700_AssemblerBase
*pAsm
)
3834 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_MOV
;
3836 if (GL_FALSE
== assemble_dst(pAsm
))
3841 if (GL_FALSE
== assemble_src(pAsm
, 0, -1))
3846 if ( GL_FALSE
== next_ins(pAsm
) )
3854 GLboolean
assemble_MUL(r700_AssemblerBase
*pAsm
)
3856 if( GL_FALSE
== checkop2(pAsm
) )
3861 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_MUL
;
3863 if( GL_FALSE
== assemble_dst(pAsm
) )
3868 if( GL_FALSE
== assemble_src(pAsm
, 0, -1) )
3873 if( GL_FALSE
== assemble_src(pAsm
, 1, -1) )
3878 if( GL_FALSE
== next_ins(pAsm
) )
3886 GLboolean
assemble_POW(r700_AssemblerBase
*pAsm
)
3892 tmp
= gethelpr(pAsm
);
3894 // LG2 tmp.x, a.swizzle
3895 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_LOG_IEEE
;
3896 pAsm
->D
.dst
.math
= 1;
3898 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
3899 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
3900 pAsm
->D
.dst
.reg
= tmp
;
3901 nomask_PVSDST(&(pAsm
->D
.dst
));
3903 if( GL_FALSE
== assemble_src(pAsm
, 0, -1) )
3908 if( GL_FALSE
== next_ins(pAsm
) )
3913 // MUL tmp.x, tmp.x, b.swizzle
3914 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_MUL
;
3916 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
3917 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
3918 pAsm
->D
.dst
.reg
= tmp
;
3919 nomask_PVSDST(&(pAsm
->D
.dst
));
3921 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
3922 pAsm
->S
[0].src
.rtype
= SRC_REG_TEMPORARY
;
3923 pAsm
->S
[0].src
.reg
= tmp
;
3924 setswizzle_PVSSRC(&(pAsm
->S
[0].src
), SQ_SEL_X
);
3925 noneg_PVSSRC(&(pAsm
->S
[0].src
));
3927 if( GL_FALSE
== assemble_src(pAsm
, 1, -1) )
3932 if( GL_FALSE
== next_ins(pAsm
) )
3937 // EX2 dst.mask, tmp.x
3939 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_EXP_IEEE
;
3940 pAsm
->D
.dst
.math
= 1;
3942 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
3943 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
3944 pAsm
->D
.dst
.reg
= tmp
;
3945 nomask_PVSDST(&(pAsm
->D
.dst
));
3947 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
3948 pAsm
->S
[0].src
.rtype
= SRC_REG_TEMPORARY
;
3949 pAsm
->S
[0].src
.reg
= tmp
;
3950 setswizzle_PVSSRC(&(pAsm
->S
[0].src
), SQ_SEL_X
);
3951 noneg_PVSSRC(&(pAsm
->S
[0].src
));
3953 if( GL_FALSE
== next_ins(pAsm
) )
3958 // Now replicate result to all necessary channels in destination
3959 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_MOV
;
3961 if( GL_FALSE
== assemble_dst(pAsm
) )
3966 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
3967 pAsm
->S
[0].src
.rtype
= DST_REG_TEMPORARY
;
3968 pAsm
->S
[0].src
.reg
= tmp
;
3970 setswizzle_PVSSRC(&(pAsm
->S
[0].src
), SQ_SEL_X
);
3971 noneg_PVSSRC(&(pAsm
->S
[0].src
));
3973 if( GL_FALSE
== next_ins(pAsm
) )
3981 GLboolean
assemble_RCP(r700_AssemblerBase
*pAsm
)
3983 return assemble_math_function(pAsm
, SQ_OP2_INST_RECIP_IEEE
);
3986 GLboolean
assemble_RSQ(r700_AssemblerBase
*pAsm
)
3988 return assemble_math_function(pAsm
, SQ_OP2_INST_RECIPSQRT_IEEE
);
3991 GLboolean
assemble_SCS(r700_AssemblerBase
*pAsm
)
3997 tmp
= gethelpr(pAsm
);
3998 /* tmp.x = src /2*PI */
3999 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_MUL
;
4000 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
4001 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
4002 pAsm
->D
.dst
.reg
= tmp
;
4003 pAsm
->D
.dst
.writex
= 1;
4005 assemble_src(pAsm
, 0, -1);
4007 pAsm
->S
[1].src
.rtype
= SRC_REC_LITERAL
;
4008 setswizzle_PVSSRC(&(pAsm
->S
[1].src
), SQ_SEL_X
);
4009 pAsm
->D2
.dst2
.literal_slots
= 1;
4010 pAsm
->C
[0].f
= 1/(3.1415926535 * 2);
4011 pAsm
->C
[1].f
= 0.0F
;
4016 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_COS
;
4017 pAsm
->D
.dst
.math
= 1;
4021 pAsm
->D
.dst
.writey
= 0;
4023 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
4024 pAsm
->S
[0].src
.rtype
= SRC_REG_TEMPORARY
;
4025 pAsm
->S
[0].src
.reg
= tmp
;
4026 setswizzle_PVSSRC(&(pAsm
->S
[0].src
), SQ_SEL_X
);
4027 noneg_PVSSRC(&(pAsm
->S
[0].src
));
4029 if ( GL_FALSE
== next_ins(pAsm
) )
4035 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_SIN
;
4036 pAsm
->D
.dst
.math
= 1;
4040 pAsm
->D
.dst
.writex
= 0;
4042 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
4043 pAsm
->S
[0].src
.rtype
= SRC_REG_TEMPORARY
;
4044 pAsm
->S
[0].src
.reg
= tmp
;
4045 setswizzle_PVSSRC(&(pAsm
->S
[0].src
), SQ_SEL_X
);
4046 noneg_PVSSRC(&(pAsm
->S
[0].src
));
4048 if( GL_FALSE
== next_ins(pAsm
) )
4056 GLboolean
assemble_LOGIC(r700_AssemblerBase
*pAsm
, BITS opcode
)
4058 if( GL_FALSE
== checkop2(pAsm
) )
4063 pAsm
->D
.dst
.opcode
= opcode
;
4064 //pAsm->D.dst.math = 1;
4066 if( GL_FALSE
== assemble_dst(pAsm
) )
4071 if( GL_FALSE
== assemble_src(pAsm
, 0, -1) )
4076 if( GL_FALSE
== assemble_src(pAsm
, 1, -1) )
4081 if( GL_FALSE
== next_ins(pAsm
) )
4089 GLboolean
assemble_LOGIC_PRED(r700_AssemblerBase
*pAsm
, BITS opcode
)
4091 struct prog_instruction
*pILInst
= &(pAsm
->pILInst
[pAsm
->uiCurInst
]);
4093 pAsm
->D
.dst
.opcode
= opcode
;
4094 pAsm
->D
.dst
.math
= 1;
4095 pAsm
->D
.dst
.predicated
= 1;
4097 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
4098 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
4099 pAsm
->D
.dst
.reg
= pAsm
->uHelpReg
;
4100 pAsm
->D
.dst
.writex
= 1;
4101 pAsm
->D
.dst
.writey
= pAsm
->D
.dst
.writez
= pAsm
->D
.dst
.writew
= 0;
4103 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
4104 pAsm
->S
[0].src
.rtype
= SRC_REG_TEMPORARY
;
4105 pAsm
->S
[0].src
.reg
= pAsm
->last_cond_register
+ pAsm
->starting_temp_register_number
;
4106 pAsm
->S
[0].src
.swizzlex
= pILInst
->DstReg
.CondSwizzle
& 0x7;
4107 noneg_PVSSRC(&(pAsm
->S
[0].src
));
4109 pAsm
->S
[1].src
.rtype
= SRC_REG_TEMPORARY
;
4110 pAsm
->S
[1].src
.reg
= pAsm
->uHelpReg
;
4111 setaddrmode_PVSSRC(&(pAsm
->S
[1].src
), ADDR_ABSOLUTE
);
4112 noneg_PVSSRC(&(pAsm
->S
[1].src
));
4113 pAsm
->S
[1].src
.swizzlex
= SQ_SEL_0
;
4114 pAsm
->S
[1].src
.swizzley
= SQ_SEL_0
;
4115 pAsm
->S
[1].src
.swizzlez
= SQ_SEL_0
;
4116 pAsm
->S
[1].src
.swizzlew
= SQ_SEL_0
;
4118 if( GL_FALSE
== next_ins(pAsm
) )
4126 GLboolean
assemble_SGE(r700_AssemblerBase
*pAsm
)
4128 if( GL_FALSE
== checkop2(pAsm
) )
4133 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_SETGE
;
4135 if( GL_FALSE
== assemble_dst(pAsm
) )
4140 if( GL_FALSE
== assemble_src(pAsm
, 0, -1) )
4145 if( GL_FALSE
== assemble_src(pAsm
, 1, -1) )
4150 if( GL_FALSE
== next_ins(pAsm
) )
4158 GLboolean
assemble_SLT(r700_AssemblerBase
*pAsm
)
4160 if( GL_FALSE
== checkop2(pAsm
) )
4165 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_SETGT
;
4167 if( GL_FALSE
== assemble_dst(pAsm
) )
4172 if( GL_FALSE
== assemble_src(pAsm
, 0, 1) )
4177 if( GL_FALSE
== assemble_src(pAsm
, 1, 0) )
4182 if( GL_FALSE
== next_ins(pAsm
) )
4190 GLboolean
assemble_STP(r700_AssemblerBase
*pAsm
)
4195 GLboolean
assemble_TEX(r700_AssemblerBase
*pAsm
)
4197 GLboolean src_const
;
4198 GLboolean need_barrier
= GL_FALSE
;
4202 switch (pAsm
->pILInst
[pAsm
->uiCurInst
].SrcReg
[0].File
)
4204 case PROGRAM_UNIFORM
:
4205 case PROGRAM_CONSTANT
:
4206 case PROGRAM_LOCAL_PARAM
:
4207 case PROGRAM_ENV_PARAM
:
4208 case PROGRAM_STATE_VAR
:
4209 src_const
= GL_TRUE
;
4211 case PROGRAM_TEMPORARY
:
4214 src_const
= GL_FALSE
;
4218 if (GL_TRUE
== src_const
)
4220 if ( GL_FALSE
== mov_temp(pAsm
, 0) )
4222 need_barrier
= GL_TRUE
;
4225 if (pAsm
->pILInst
[pAsm
->uiCurInst
].Opcode
== OPCODE_TXP
)
4227 GLuint tmp
= gethelpr(pAsm
);
4228 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_RECIP_IEEE
;
4229 pAsm
->D
.dst
.math
= 1;
4230 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
4231 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
4232 pAsm
->D
.dst
.reg
= tmp
;
4233 pAsm
->D
.dst
.writew
= 1;
4235 if( GL_FALSE
== assemble_src(pAsm
, 0, -1) )
4239 swizzleagain_PVSSRC(&(pAsm
->S
[0].src
), SQ_SEL_W
, SQ_SEL_W
, SQ_SEL_W
, SQ_SEL_W
);
4240 if( GL_FALSE
== next_ins(pAsm
) )
4245 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_MUL
;
4246 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
4247 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
4248 pAsm
->D
.dst
.reg
= tmp
;
4249 pAsm
->D
.dst
.writex
= 1;
4250 pAsm
->D
.dst
.writey
= 1;
4251 pAsm
->D
.dst
.writez
= 1;
4252 pAsm
->D
.dst
.writew
= 0;
4254 if( GL_FALSE
== assemble_src(pAsm
, 0, -1) )
4258 setaddrmode_PVSSRC(&(pAsm
->S
[1].src
), ADDR_ABSOLUTE
);
4259 pAsm
->S
[1].src
.rtype
= SRC_REG_TEMPORARY
;
4260 pAsm
->S
[1].src
.reg
= tmp
;
4261 setswizzle_PVSSRC(&(pAsm
->S
[1].src
), SQ_SEL_W
);
4263 if( GL_FALSE
== next_ins(pAsm
) )
4268 pAsm
->aArgSubst
[1] = tmp
;
4269 need_barrier
= GL_TRUE
;
4272 if (pAsm
->pILInst
[pAsm
->uiCurInst
].TexSrcTarget
== TEXTURE_CUBE_INDEX
)
4274 GLuint tmp1
= gethelpr(pAsm
);
4275 GLuint tmp2
= gethelpr(pAsm
);
4277 /* tmp1.xyzw = CUBE(R0.zzxy, R0.yxzz) */
4278 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_CUBE
;
4279 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
4280 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
4281 pAsm
->D
.dst
.reg
= tmp1
;
4282 nomask_PVSDST(&(pAsm
->D
.dst
));
4284 if( GL_FALSE
== assemble_src(pAsm
, 0, -1) )
4289 if( GL_FALSE
== assemble_src(pAsm
, 0, 1) )
4294 swizzleagain_PVSSRC(&(pAsm
->S
[0].src
), SQ_SEL_Z
, SQ_SEL_Z
, SQ_SEL_X
, SQ_SEL_Y
);
4295 swizzleagain_PVSSRC(&(pAsm
->S
[1].src
), SQ_SEL_Y
, SQ_SEL_X
, SQ_SEL_Z
, SQ_SEL_Z
);
4297 if( GL_FALSE
== next_ins(pAsm
) )
4302 /* tmp1.z = RCP_e(|tmp1.z|) */
4303 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_RECIP_IEEE
;
4304 pAsm
->D
.dst
.math
= 1;
4305 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
4306 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
4307 pAsm
->D
.dst
.reg
= tmp1
;
4308 pAsm
->D
.dst
.writez
= 1;
4310 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
4311 pAsm
->S
[0].src
.rtype
= SRC_REG_TEMPORARY
;
4312 pAsm
->S
[0].src
.reg
= tmp1
;
4313 pAsm
->S
[0].src
.swizzlex
= SQ_SEL_Z
;
4314 pAsm
->S
[0].src
.abs
= 1;
4318 /* MULADD R0.x, R0.x, PS1, (0x3FC00000, 1.5f).x
4319 * MULADD R0.y, R0.y, PS1, (0x3FC00000, 1.5f).x
4320 * muladd has no writemask, have to use another temp
4322 pAsm
->D
.dst
.opcode
= SQ_OP3_INST_MULADD
;
4323 pAsm
->D
.dst
.op3
= 1;
4324 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
4325 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
4326 pAsm
->D
.dst
.reg
= tmp2
;
4328 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
4329 pAsm
->S
[0].src
.rtype
= SRC_REG_TEMPORARY
;
4330 pAsm
->S
[0].src
.reg
= tmp1
;
4331 noswizzle_PVSSRC(&(pAsm
->S
[0].src
));
4332 setaddrmode_PVSSRC(&(pAsm
->S
[1].src
), ADDR_ABSOLUTE
);
4333 pAsm
->S
[1].src
.rtype
= SRC_REG_TEMPORARY
;
4334 pAsm
->S
[1].src
.reg
= tmp1
;
4335 setswizzle_PVSSRC(&(pAsm
->S
[1].src
), SQ_SEL_Z
);
4336 setaddrmode_PVSSRC(&(pAsm
->S
[2].src
), ADDR_ABSOLUTE
);
4337 /* immediate c 1.5 */
4338 pAsm
->D2
.dst2
.literal_slots
= 1;
4339 pAsm
->C
[0].f
= 1.5F
;
4340 pAsm
->S
[2].src
.rtype
= SRC_REC_LITERAL
;
4341 pAsm
->S
[2].src
.reg
= tmp1
;
4342 setswizzle_PVSSRC(&(pAsm
->S
[2].src
), SQ_SEL_X
);
4346 /* tmp1.xy = temp2.xy */
4347 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_MOV
;
4348 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
4349 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
4350 pAsm
->D
.dst
.reg
= tmp1
;
4351 pAsm
->D
.dst
.writex
= 1;
4352 pAsm
->D
.dst
.writey
= 1;
4353 pAsm
->D
.dst
.writez
= 0;
4354 pAsm
->D
.dst
.writew
= 0;
4356 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
4357 pAsm
->S
[0].src
.rtype
= SRC_REG_TEMPORARY
;
4358 pAsm
->S
[0].src
.reg
= tmp2
;
4359 noswizzle_PVSSRC(&(pAsm
->S
[0].src
));
4362 pAsm
->aArgSubst
[1] = tmp1
;
4363 need_barrier
= GL_TRUE
;
4367 switch(pAsm
->pILInst
[pAsm
->uiCurInst
].Opcode
)
4370 /* will these need WQM(1) on CF inst ? */
4371 pAsm
->D
.dst
.opcode
= SQ_TEX_INST_GET_GRADIENTS_H
;
4374 pAsm
->D
.dst
.opcode
= SQ_TEX_INST_GET_GRADIENTS_V
;
4377 pAsm
->D
.dst
.opcode
= SQ_TEX_INST_SAMPLE_L
;
4380 pAsm
->D
.dst
.opcode
= SQ_TEX_INST_SAMPLE
;
4383 pAsm
->is_tex
= GL_TRUE
;
4384 if ( GL_TRUE
== need_barrier
)
4386 pAsm
->is_tex
= GL_TRUE
;
4387 if ( GL_TRUE
== need_barrier
)
4389 pAsm
->need_tex_barrier
= GL_TRUE
;
4391 // Set src1 to tex unit id
4392 pAsm
->S
[1].src
.reg
= pAsm
->SamplerUnits
[pAsm
->pILInst
[pAsm
->uiCurInst
].TexSrcUnit
];
4393 pAsm
->S
[1].src
.rtype
= SRC_REG_TEMPORARY
;
4395 //No sw info from mesa compiler, so hard code here.
4396 pAsm
->S
[1].src
.swizzlex
= SQ_SEL_X
;
4397 pAsm
->S
[1].src
.swizzley
= SQ_SEL_Y
;
4398 pAsm
->S
[1].src
.swizzlez
= SQ_SEL_Z
;
4399 pAsm
->S
[1].src
.swizzlew
= SQ_SEL_W
;
4401 if( GL_FALSE
== tex_dst(pAsm
) )
4406 if( GL_FALSE
== tex_src(pAsm
) )
4411 if(pAsm
->pILInst
[pAsm
->uiCurInst
].Opcode
== OPCODE_TXP
)
4413 /* hopefully did swizzles before */
4414 noswizzle_PVSSRC(&(pAsm
->S
[0].src
));
4417 if(pAsm
->pILInst
[pAsm
->uiCurInst
].TexSrcTarget
== TEXTURE_CUBE_INDEX
)
4419 /* SAMPLE dst, tmp.yxwy, CUBE */
4420 pAsm
->S
[0].src
.swizzlex
= SQ_SEL_Y
;
4421 pAsm
->S
[0].src
.swizzley
= SQ_SEL_X
;
4422 pAsm
->S
[0].src
.swizzlez
= SQ_SEL_W
;
4423 pAsm
->S
[0].src
.swizzlew
= SQ_SEL_Y
;
4426 if ( GL_FALSE
== next_ins(pAsm
) )
4434 GLboolean
assemble_XPD(r700_AssemblerBase
*pAsm
)
4438 if( GL_FALSE
== checkop2(pAsm
) )
4443 tmp
= gethelpr(pAsm
);
4445 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_MUL
;
4447 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
4448 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
4449 pAsm
->D
.dst
.reg
= tmp
;
4450 nomask_PVSDST(&(pAsm
->D
.dst
));
4452 if( GL_FALSE
== assemble_src(pAsm
, 0, -1) )
4457 if( GL_FALSE
== assemble_src(pAsm
, 1, -1) )
4462 swizzleagain_PVSSRC(&(pAsm
->S
[0].src
), SQ_SEL_Z
, SQ_SEL_X
, SQ_SEL_Y
, SQ_SEL_0
);
4463 swizzleagain_PVSSRC(&(pAsm
->S
[1].src
), SQ_SEL_Y
, SQ_SEL_Z
, SQ_SEL_X
, SQ_SEL_0
);
4465 if( GL_FALSE
== next_ins(pAsm
) )
4470 pAsm
->D
.dst
.opcode
= SQ_OP3_INST_MULADD
;
4471 pAsm
->D
.dst
.op3
= 1;
4473 if(0xF != pAsm
->pILInst
[pAsm
->uiCurInst
].DstReg
.WriteMask
)
4475 tmp
= gethelpr(pAsm
);
4477 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
4478 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
4479 pAsm
->D
.dst
.reg
= tmp
;
4481 nomask_PVSDST(&(pAsm
->D
.dst
));
4485 if( GL_FALSE
== assemble_dst(pAsm
) )
4491 if( GL_FALSE
== assemble_src(pAsm
, 0, -1) )
4496 if( GL_FALSE
== assemble_src(pAsm
, 1, -1) )
4501 swizzleagain_PVSSRC(&(pAsm
->S
[0].src
), SQ_SEL_Y
, SQ_SEL_Z
, SQ_SEL_X
, SQ_SEL_0
);
4502 swizzleagain_PVSSRC(&(pAsm
->S
[1].src
), SQ_SEL_Z
, SQ_SEL_X
, SQ_SEL_Y
, SQ_SEL_0
);
4504 // result1 + (neg) result0
4505 setaddrmode_PVSSRC(&(pAsm
->S
[2].src
),ADDR_ABSOLUTE
);
4506 pAsm
->S
[2].src
.rtype
= SRC_REG_TEMPORARY
;
4507 pAsm
->S
[2].src
.reg
= tmp
;
4509 neg_PVSSRC(&(pAsm
->S
[2].src
));
4510 noswizzle_PVSSRC(&(pAsm
->S
[2].src
));
4512 if( GL_FALSE
== next_ins(pAsm
) )
4518 if(0xF != pAsm
->pILInst
[pAsm
->uiCurInst
].DstReg
.WriteMask
)
4520 if( GL_FALSE
== assemble_dst(pAsm
) )
4525 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_MOV
;
4527 // Use tmp as source
4528 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
4529 pAsm
->S
[0].src
.rtype
= SRC_REG_TEMPORARY
;
4530 pAsm
->S
[0].src
.reg
= tmp
;
4532 noneg_PVSSRC(&(pAsm
->S
[0].src
));
4533 noswizzle_PVSSRC(&(pAsm
->S
[0].src
));
4535 if( GL_FALSE
== next_ins(pAsm
) )
4544 GLboolean
assemble_EXPORT(r700_AssemblerBase
*pAsm
)
4549 static inline void decreaseCurrent(r700_AssemblerBase
*pAsm
, GLuint uReason
)
4554 pAsm
->CALLSTACK
[pAsm
->CALLSP
].current
--;
4557 pAsm
->CALLSTACK
[pAsm
->CALLSP
].current
-= 4;
4560 pAsm
->CALLSTACK
[pAsm
->CALLSP
].current
-= 4;
4563 /* TODO : for 16 vp asic, should -= 2; */
4564 pAsm
->CALLSTACK
[pAsm
->CALLSP
].current
-= 1;
4569 static inline void checkStackDepth(r700_AssemblerBase
*pAsm
, GLuint uReason
, GLboolean bCheckMaxOnly
)
4571 if(GL_TRUE
== bCheckMaxOnly
)
4576 if((pAsm
->CALLSTACK
[pAsm
->CALLSP
].current
+ 1)
4577 > pAsm
->CALLSTACK
[pAsm
->CALLSP
].max
)
4579 pAsm
->CALLSTACK
[pAsm
->CALLSP
].max
=
4580 pAsm
->CALLSTACK
[pAsm
->CALLSP
].current
+ 1;
4584 if((pAsm
->CALLSTACK
[pAsm
->CALLSP
].current
+ 4)
4585 > pAsm
->CALLSTACK
[pAsm
->CALLSP
].max
)
4587 pAsm
->CALLSTACK
[pAsm
->CALLSP
].max
=
4588 pAsm
->CALLSTACK
[pAsm
->CALLSP
].current
+ 4;
4598 pAsm
->CALLSTACK
[pAsm
->CALLSP
].current
++;
4601 pAsm
->CALLSTACK
[pAsm
->CALLSP
].current
+= 4;
4604 pAsm
->CALLSTACK
[pAsm
->CALLSP
].current
+= 4;
4607 /* TODO : for 16 vp asic, should += 2; */
4608 pAsm
->CALLSTACK
[pAsm
->CALLSP
].current
+= 1;
4612 if(pAsm
->CALLSTACK
[pAsm
->CALLSP
].current
4613 > pAsm
->CALLSTACK
[pAsm
->CALLSP
].max
)
4615 pAsm
->CALLSTACK
[pAsm
->CALLSP
].max
=
4616 pAsm
->CALLSTACK
[pAsm
->CALLSP
].current
;
4620 GLboolean
jumpToOffest(r700_AssemblerBase
*pAsm
, GLuint pops
, GLint offset
)
4622 if(GL_FALSE
== add_cf_instruction(pAsm
) )
4627 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.pop_count
= pops
;
4628 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.cf_const
= 0x0;
4629 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.cond
= SQ_CF_COND_ACTIVE
;
4631 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.end_of_program
= 0x0;
4632 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.valid_pixel_mode
= 0x0;
4633 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.cf_inst
= SQ_CF_INST_JUMP
;
4634 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.whole_quad_mode
= 0x0;
4636 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.barrier
= 0x1;
4638 pAsm
->cf_current_cf_clause_ptr
->m_Word0
.f
.addr
= pAsm
->cf_current_cf_clause_ptr
->m_uIndex
+ offset
;
4643 GLboolean
pops(r700_AssemblerBase
*pAsm
, GLuint pops
)
4645 if(GL_FALSE
== add_cf_instruction(pAsm
) )
4650 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.pop_count
= pops
;
4651 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.cf_const
= 0x0;
4652 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.cond
= SQ_CF_COND_ACTIVE
;
4654 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.end_of_program
= 0x0;
4655 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.valid_pixel_mode
= 0x0;
4656 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.cf_inst
= SQ_CF_INST_POP
;
4658 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.whole_quad_mode
= 0x0;
4660 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.barrier
= 0x1;
4661 pAsm
->cf_current_cf_clause_ptr
->m_Word0
.f
.addr
= pAsm
->cf_current_cf_clause_ptr
->m_uIndex
+ 1;
4666 GLboolean
assemble_IF(r700_AssemblerBase
*pAsm
, GLboolean bHasElse
)
4668 pAsm
->alu_x_opcode
= SQ_CF_INST_ALU_PUSH_BEFORE
;
4670 assemble_LOGIC_PRED(pAsm
, SQ_OP2_INST_PRED_SETNE
);
4673 if(GL_FALSE
== add_cf_instruction(pAsm
) )
4678 if(GL_TRUE
!= bHasElse
)
4680 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.pop_count
= 1;
4684 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.pop_count
= 0;
4686 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.cf_const
= 0x0;
4687 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.cond
= SQ_CF_COND_ACTIVE
;
4689 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.end_of_program
= 0x0;
4690 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.valid_pixel_mode
= 0x0;
4691 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.cf_inst
= SQ_CF_INST_JUMP
;
4692 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.whole_quad_mode
= 0x0;
4694 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.barrier
= 0x1;
4697 pAsm
->fc_stack
[pAsm
->FCSP
].type
= FC_IF
;
4698 pAsm
->fc_stack
[pAsm
->FCSP
].mid
= NULL
;
4699 pAsm
->fc_stack
[pAsm
->FCSP
].midLen
= 0;
4700 pAsm
->fc_stack
[pAsm
->FCSP
].first
= pAsm
->cf_current_cf_clause_ptr
;
4702 #ifndef USE_CF_FOR_POP_AFTER
4703 if(GL_TRUE
!= bHasElse
)
4705 pAsm
->alu_x_opcode
= SQ_CF_INST_ALU_POP_AFTER
;
4707 #endif /* USE_CF_FOR_POP_AFTER */
4709 checkStackDepth(pAsm
, FC_PUSH_VPM
, GL_FALSE
);
4714 GLboolean
assemble_ELSE(r700_AssemblerBase
*pAsm
)
4716 if(GL_FALSE
== add_cf_instruction(pAsm
) )
4721 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.pop_count
= 1; ///
4722 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.cf_const
= 0x0;
4723 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.cond
= SQ_CF_COND_ACTIVE
;
4725 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.end_of_program
= 0x0;
4726 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.valid_pixel_mode
= 0x0;
4727 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.cf_inst
= SQ_CF_INST_ELSE
;
4728 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.whole_quad_mode
= 0x0;
4730 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.barrier
= 0x1;
4732 pAsm
->fc_stack
[pAsm
->FCSP
].mid
= (R700ControlFlowGenericClause
**)_mesa_realloc( (void *)pAsm
->fc_stack
[pAsm
->FCSP
].mid
,
4734 sizeof(R700ControlFlowGenericClause
*) );
4735 pAsm
->fc_stack
[pAsm
->FCSP
].mid
[0] = pAsm
->cf_current_cf_clause_ptr
;
4736 //pAsm->fc_stack[pAsm->FCSP].unNumMid = 1;
4738 #ifndef USE_CF_FOR_POP_AFTER
4739 pAsm
->alu_x_opcode
= SQ_CF_INST_ALU_POP_AFTER
;
4740 #endif /* USE_CF_FOR_POP_AFTER */
4742 pAsm
->fc_stack
[pAsm
->FCSP
].first
->m_Word0
.f
.addr
= pAsm
->pR700Shader
->plstCFInstructions_active
->uNumOfNode
- 1;
4747 GLboolean
assemble_ENDIF(r700_AssemblerBase
*pAsm
)
4749 #ifdef USE_CF_FOR_POP_AFTER
4751 #endif /* USE_CF_FOR_POP_AFTER */
4753 pAsm
->alu_x_opcode
= SQ_CF_INST_ALU
;
4755 if(NULL
== pAsm
->fc_stack
[pAsm
->FCSP
].mid
)
4757 /* no else in between */
4758 pAsm
->fc_stack
[pAsm
->FCSP
].first
->m_Word0
.f
.addr
= pAsm
->pR700Shader
->plstCFInstructions_active
->uNumOfNode
;
4762 pAsm
->fc_stack
[pAsm
->FCSP
].mid
[0]->m_Word0
.f
.addr
= pAsm
->pR700Shader
->plstCFInstructions_active
->uNumOfNode
;
4765 if(NULL
!= pAsm
->fc_stack
[pAsm
->FCSP
].mid
)
4767 FREE(pAsm
->fc_stack
[pAsm
->FCSP
].mid
);
4770 if(pAsm
->fc_stack
[pAsm
->FCSP
].type
!= FC_IF
)
4772 radeon_error("if/endif in shader code are not paired. \n");
4778 decreaseCurrent(pAsm
, FC_PUSH_VPM
);
4783 GLboolean
assemble_BGNLOOP(r700_AssemblerBase
*pAsm
)
4785 if(GL_FALSE
== add_cf_instruction(pAsm
) )
4791 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.pop_count
= 0;
4792 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.cf_const
= 0x0;
4793 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.cond
= SQ_CF_COND_ACTIVE
;
4795 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.end_of_program
= 0x0;
4796 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.valid_pixel_mode
= 0x0;
4797 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.cf_inst
= SQ_CF_INST_LOOP_START_NO_AL
;
4798 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.whole_quad_mode
= 0x0;
4800 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.barrier
= 0x1;
4803 pAsm
->fc_stack
[pAsm
->FCSP
].type
= FC_LOOP
;
4804 pAsm
->fc_stack
[pAsm
->FCSP
].mid
= NULL
;
4805 pAsm
->fc_stack
[pAsm
->FCSP
].unNumMid
= 0;
4806 pAsm
->fc_stack
[pAsm
->FCSP
].midLen
= 0;
4807 pAsm
->fc_stack
[pAsm
->FCSP
].first
= pAsm
->cf_current_cf_clause_ptr
;
4809 checkStackDepth(pAsm
, FC_LOOP
, GL_FALSE
);
4814 GLboolean
assemble_BRK(r700_AssemblerBase
*pAsm
)
4816 #ifdef USE_CF_FOR_CONTINUE_BREAK
4818 pAsm
->alu_x_opcode
= SQ_CF_INST_ALU_PUSH_BEFORE
;
4820 assemble_LOGIC_PRED(pAsm
, SQ_OP2_INST_PRED_SETNE
);
4822 unsigned int unFCSP
;
4823 for(unFCSP
=pAsm
->FCSP
; unFCSP
>0; unFCSP
--)
4825 if(FC_LOOP
== pAsm
->fc_stack
[unFCSP
].type
)
4832 radeon_error("Break is not inside loop/endloop pair.\n");
4836 if(GL_FALSE
== add_cf_instruction(pAsm
) )
4842 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.pop_count
= 1;
4843 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.cf_const
= 0x0;
4844 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.cond
= SQ_CF_COND_ACTIVE
;
4846 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.end_of_program
= 0x0;
4847 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.valid_pixel_mode
= 0x0;
4848 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.cf_inst
= SQ_CF_INST_LOOP_BREAK
;
4850 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.whole_quad_mode
= 0x0;
4852 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.barrier
= 0x1;
4854 pAsm
->fc_stack
[unFCSP
].mid
= (R700ControlFlowGenericClause
**)_mesa_realloc(
4855 (void *)pAsm
->fc_stack
[unFCSP
].mid
,
4856 sizeof(R700ControlFlowGenericClause
*) * pAsm
->fc_stack
[unFCSP
].unNumMid
,
4857 sizeof(R700ControlFlowGenericClause
*) * (pAsm
->fc_stack
[unFCSP
].unNumMid
+ 1) );
4858 pAsm
->fc_stack
[unFCSP
].mid
[pAsm
->fc_stack
[unFCSP
].unNumMid
] = pAsm
->cf_current_cf_clause_ptr
;
4859 pAsm
->fc_stack
[unFCSP
].unNumMid
++;
4861 if(GL_FALSE
== add_cf_instruction(pAsm
) )
4866 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.pop_count
= 1;
4867 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.cf_const
= 0x0;
4868 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.cond
= SQ_CF_COND_ACTIVE
;
4870 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.end_of_program
= 0x0;
4871 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.valid_pixel_mode
= 0x0;
4872 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.cf_inst
= SQ_CF_INST_POP
;
4874 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.whole_quad_mode
= 0x0;
4876 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.barrier
= 0x1;
4877 pAsm
->cf_current_cf_clause_ptr
->m_Word0
.f
.addr
= pAsm
->cf_current_cf_clause_ptr
->m_uIndex
+ 1;
4879 checkStackDepth(pAsm
, FC_PUSH_VPM
, GL_TRUE
);
4881 #endif //USE_CF_FOR_CONTINUE_BREAK
4885 GLboolean
assemble_CONT(r700_AssemblerBase
*pAsm
)
4887 #ifdef USE_CF_FOR_CONTINUE_BREAK
4888 pAsm
->alu_x_opcode
= SQ_CF_INST_ALU_PUSH_BEFORE
;
4890 assemble_LOGIC_PRED(pAsm
, SQ_OP2_INST_PRED_SETNE
);
4892 unsigned int unFCSP
;
4893 for(unFCSP
=pAsm
->FCSP
; unFCSP
>0; unFCSP
--)
4895 if(FC_LOOP
== pAsm
->fc_stack
[unFCSP
].type
)
4902 radeon_error("Continue is not inside loop/endloop pair.\n");
4906 if(GL_FALSE
== add_cf_instruction(pAsm
) )
4912 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.pop_count
= 1;
4913 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.cf_const
= 0x0;
4914 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.cond
= SQ_CF_COND_ACTIVE
;
4916 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.end_of_program
= 0x0;
4917 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.valid_pixel_mode
= 0x0;
4918 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.cf_inst
= SQ_CF_INST_LOOP_CONTINUE
;
4920 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.whole_quad_mode
= 0x0;
4922 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.barrier
= 0x1;
4924 pAsm
->fc_stack
[unFCSP
].mid
= (R700ControlFlowGenericClause
**)_mesa_realloc(
4925 (void *)pAsm
->fc_stack
[unFCSP
].mid
,
4926 sizeof(R700ControlFlowGenericClause
*) * pAsm
->fc_stack
[unFCSP
].unNumMid
,
4927 sizeof(R700ControlFlowGenericClause
*) * (pAsm
->fc_stack
[unFCSP
].unNumMid
+ 1) );
4928 pAsm
->fc_stack
[unFCSP
].mid
[pAsm
->fc_stack
[unFCSP
].unNumMid
] = pAsm
->cf_current_cf_clause_ptr
;
4929 pAsm
->fc_stack
[unFCSP
].unNumMid
++;
4931 if(GL_FALSE
== add_cf_instruction(pAsm
) )
4936 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.pop_count
= 1;
4937 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.cf_const
= 0x0;
4938 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.cond
= SQ_CF_COND_ACTIVE
;
4940 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.end_of_program
= 0x0;
4941 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.valid_pixel_mode
= 0x0;
4942 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.cf_inst
= SQ_CF_INST_POP
;
4944 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.whole_quad_mode
= 0x0;
4946 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.barrier
= 0x1;
4947 pAsm
->cf_current_cf_clause_ptr
->m_Word0
.f
.addr
= pAsm
->cf_current_cf_clause_ptr
->m_uIndex
+ 1;
4949 checkStackDepth(pAsm
, FC_PUSH_VPM
, GL_TRUE
);
4951 #endif /* USE_CF_FOR_CONTINUE_BREAK */
4956 GLboolean
assemble_ENDLOOP(r700_AssemblerBase
*pAsm
)
4960 if(GL_FALSE
== add_cf_instruction(pAsm
) )
4966 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.pop_count
= 0;
4967 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.cf_const
= 0x0;
4968 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.cond
= SQ_CF_COND_ACTIVE
;
4970 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.end_of_program
= 0x0;
4971 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.valid_pixel_mode
= 0x0;
4972 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.cf_inst
= SQ_CF_INST_LOOP_END
;
4973 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.whole_quad_mode
= 0x0;
4975 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.barrier
= 0x1;
4977 pAsm
->cf_current_cf_clause_ptr
->m_Word0
.f
.addr
= pAsm
->fc_stack
[pAsm
->FCSP
].first
->m_uIndex
+ 1;
4978 pAsm
->fc_stack
[pAsm
->FCSP
].first
->m_Word0
.f
.addr
= pAsm
->cf_current_cf_clause_ptr
->m_uIndex
+ 1;
4980 #ifdef USE_CF_FOR_CONTINUE_BREAK
4981 for(i
=0; i
<pAsm
->fc_stack
[pAsm
->FCSP
].unNumMid
; i
++)
4983 pAsm
->fc_stack
[pAsm
->FCSP
].mid
[i
]->m_Word0
.f
.addr
= pAsm
->cf_current_cf_clause_ptr
->m_uIndex
;
4985 if(NULL
!= pAsm
->fc_stack
[pAsm
->FCSP
].mid
)
4987 FREE(pAsm
->fc_stack
[pAsm
->FCSP
].mid
);
4991 if(pAsm
->fc_stack
[pAsm
->FCSP
].type
!= FC_LOOP
)
4993 radeon_error("loop/endloop in shader code are not paired. \n");
4999 if((pAsm
->unCFflags
& HAS_CURRENT_LOOPRET
) > 0)
5001 for(unFCSP
=(pAsm
->FCSP
-1); unFCSP
>pAsm
->CALLSTACK
[pAsm
->CALLSP
].FCSP_BeforeEntry
; unFCSP
--)
5003 if(FC_LOOP
== pAsm
->fc_stack
[unFCSP
].type
)
5005 breakLoopOnFlag(pAsm
, unFCSP
);
5008 else if(FC_IF
== pAsm
->fc_stack
[unFCSP
].type
)
5013 if(unFCSP
<= pAsm
->CALLSTACK
[pAsm
->CALLSP
].FCSP_BeforeEntry
)
5015 #ifdef USE_CF_FOR_POP_AFTER
5016 returnOnFlag(pAsm
, unIF
);
5018 returnOnFlag(pAsm
, 0);
5019 #endif /* USE_CF_FOR_POP_AFTER */
5020 pAsm
->unCFflags
&= ~HAS_CURRENT_LOOPRET
;
5026 decreaseCurrent(pAsm
, FC_LOOP
);
5031 void add_return_inst(r700_AssemblerBase
*pAsm
)
5033 if(GL_FALSE
== add_cf_instruction(pAsm
) )
5037 //pAsm->cf_current_cf_clause_ptr->m_Word1.f.pop_count = 1;
5038 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.pop_count
= 0;
5039 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.cf_const
= 0x0;
5040 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.cond
= SQ_CF_COND_ACTIVE
;
5042 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.end_of_program
= 0x0;
5043 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.valid_pixel_mode
= 0x0;
5044 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.cf_inst
= SQ_CF_INST_RETURN
;
5045 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.whole_quad_mode
= 0x0;
5047 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.barrier
= 0x1;
5050 GLboolean
assemble_BGNSUB(r700_AssemblerBase
*pAsm
, GLint nILindex
, GLuint uiIL_Shift
)
5053 if( (pAsm
->unSubArrayPointer
+ 1) > pAsm
->unSubArraySize
)
5055 pAsm
->subs
= (SUB_OFFSET
*)_mesa_realloc( (void *)pAsm
->subs
,
5056 sizeof(SUB_OFFSET
) * pAsm
->unSubArraySize
,
5057 sizeof(SUB_OFFSET
) * (pAsm
->unSubArraySize
+ 10) );
5058 if(NULL
== pAsm
->subs
)
5062 pAsm
->unSubArraySize
+= 10;
5065 pAsm
->subs
[pAsm
->unSubArrayPointer
].subIL_Offset
= nILindex
+ uiIL_Shift
;
5066 pAsm
->subs
[pAsm
->unSubArrayPointer
].lstCFInstructions_local
.pHead
=NULL
;
5067 pAsm
->subs
[pAsm
->unSubArrayPointer
].lstCFInstructions_local
.pTail
=NULL
;
5068 pAsm
->subs
[pAsm
->unSubArrayPointer
].lstCFInstructions_local
.uNumOfNode
=0;
5071 pAsm
->CALLSTACK
[pAsm
->CALLSP
].subDescIndex
= pAsm
->unSubArrayPointer
;
5072 pAsm
->CALLSTACK
[pAsm
->CALLSP
].FCSP_BeforeEntry
= pAsm
->FCSP
;
5073 pAsm
->CALLSTACK
[pAsm
->CALLSP
].plstCFInstructions_local
5074 = &(pAsm
->subs
[pAsm
->unSubArrayPointer
].lstCFInstructions_local
);
5075 pAsm
->CALLSTACK
[pAsm
->CALLSP
].max
= 0;
5076 pAsm
->CALLSTACK
[pAsm
->CALLSP
].current
= 0;
5077 SetActiveCFlist(pAsm
->pR700Shader
,
5078 pAsm
->CALLSTACK
[pAsm
->CALLSP
].plstCFInstructions_local
);
5080 pAsm
->unSubArrayPointer
++;
5083 pAsm
->alu_x_opcode
= SQ_CF_INST_ALU
;
5086 pAsm
->fc_stack
[pAsm
->FCSP
].type
= FC_REP
;
5088 checkStackDepth(pAsm
, FC_REP
, GL_FALSE
);
5093 GLboolean
assemble_ENDSUB(r700_AssemblerBase
*pAsm
)
5095 if(pAsm
->fc_stack
[pAsm
->FCSP
].type
!= FC_REP
)
5097 radeon_error("BGNSUB/ENDSUB in shader code are not paired. \n");
5101 /* copy max to sub structure */
5102 pAsm
->subs
[pAsm
->CALLSTACK
[pAsm
->CALLSP
].subDescIndex
].unStackDepthMax
5103 = pAsm
->CALLSTACK
[pAsm
->CALLSP
].max
;
5105 decreaseCurrent(pAsm
, FC_REP
);
5108 SetActiveCFlist(pAsm
->pR700Shader
,
5109 pAsm
->CALLSTACK
[pAsm
->CALLSP
].plstCFInstructions_local
);
5111 pAsm
->alu_x_opcode
= SQ_CF_INST_ALU
;
5118 GLboolean
assemble_RET(r700_AssemblerBase
*pAsm
)
5122 if(pAsm
->CALLSP
> 0)
5125 for(unFCSP
=pAsm
->FCSP
; unFCSP
>pAsm
->CALLSTACK
[pAsm
->CALLSP
].FCSP_BeforeEntry
; unFCSP
--)
5127 if(FC_LOOP
== pAsm
->fc_stack
[unFCSP
].type
)
5129 setRetInLoopFlag(pAsm
, SQ_SEL_1
);
5130 breakLoopOnFlag(pAsm
, unFCSP
);
5131 pAsm
->unCFflags
|= LOOPRET_FLAGS
;
5135 else if(FC_IF
== pAsm
->fc_stack
[unFCSP
].type
)
5142 #ifdef USE_CF_FOR_POP_AFTER
5147 #endif /* USE_CF_FOR_POP_AFTER */
5149 add_return_inst(pAsm
);
5154 GLboolean
assemble_CAL(r700_AssemblerBase
*pAsm
,
5157 GLuint uiNumberInsts
,
5158 struct prog_instruction
*pILInst
,
5159 PRESUB_DESC
* pPresubDesc
)
5163 pAsm
->alu_x_opcode
= SQ_CF_INST_ALU
;
5165 if(GL_FALSE
== add_cf_instruction(pAsm
) )
5170 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.call_count
= 1;
5171 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.pop_count
= 0;
5172 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.cf_const
= 0x0;
5173 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.cond
= SQ_CF_COND_ACTIVE
;
5175 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.end_of_program
= 0x0;
5176 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.valid_pixel_mode
= 0x0;
5177 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.cf_inst
= SQ_CF_INST_CALL
;
5178 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.whole_quad_mode
= 0x0;
5180 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.barrier
= 0x1;
5183 if( (pAsm
->unCallerArrayPointer
+ 1) > pAsm
->unCallerArraySize
)
5185 pAsm
->callers
= (CALLER_POINTER
*)_mesa_realloc( (void *)pAsm
->callers
,
5186 sizeof(CALLER_POINTER
) * pAsm
->unCallerArraySize
,
5187 sizeof(CALLER_POINTER
) * (pAsm
->unCallerArraySize
+ 10) );
5188 if(NULL
== pAsm
->callers
)
5192 pAsm
->unCallerArraySize
+= 10;
5195 uiIL_Offset
= nILindex
+ uiIL_Shift
;
5196 pAsm
->callers
[pAsm
->unCallerArrayPointer
].subIL_Offset
= uiIL_Offset
;
5197 pAsm
->callers
[pAsm
->unCallerArrayPointer
].cf_ptr
= pAsm
->cf_current_cf_clause_ptr
;
5199 pAsm
->callers
[pAsm
->unCallerArrayPointer
].finale_cf_ptr
= NULL
;
5200 pAsm
->callers
[pAsm
->unCallerArrayPointer
].prelude_cf_ptr
= NULL
;
5202 pAsm
->unCallerArrayPointer
++;
5208 for(j
=0; j
<pAsm
->unSubArrayPointer
; j
++)
5210 if(uiIL_Offset
== pAsm
->subs
[j
].subIL_Offset
)
5211 { /* compiled before */
5213 max
= pAsm
->subs
[j
].unStackDepthMax
5214 + pAsm
->CALLSTACK
[pAsm
->CALLSP
].current
;
5215 if(max
> pAsm
->CALLSTACK
[pAsm
->CALLSP
].max
)
5217 pAsm
->CALLSTACK
[pAsm
->CALLSP
].max
= max
;
5220 pAsm
->callers
[pAsm
->unCallerArrayPointer
- 1].subDescIndex
= j
;
5225 pAsm
->callers
[pAsm
->unCallerArrayPointer
- 1].subDescIndex
= pAsm
->unSubArrayPointer
;
5226 unSubID
= pAsm
->unSubArrayPointer
;
5228 bRet
= AssembleInstr(nILindex
, uiIL_Shift
, uiNumberInsts
, pILInst
, pAsm
);
5232 max
= pAsm
->subs
[unSubID
].unStackDepthMax
5233 + pAsm
->CALLSTACK
[pAsm
->CALLSP
].current
;
5234 if(max
> pAsm
->CALLSTACK
[pAsm
->CALLSP
].max
)
5236 pAsm
->CALLSTACK
[pAsm
->CALLSP
].max
= max
;
5239 pAsm
->subs
[unSubID
].pPresubDesc
= pPresubDesc
;
5245 GLboolean
setRetInLoopFlag(r700_AssemblerBase
*pAsm
, GLuint flagValue
)
5247 GLfloat fLiteral
[2] = {0.1, 0.0};
5249 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_MOV
;
5250 pAsm
->D
.dst
.op3
= 0;
5251 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
5252 pAsm
->D
.dst
.reg
= pAsm
->flag_reg_index
;
5253 pAsm
->D
.dst
.writex
= 1;
5254 pAsm
->D
.dst
.writey
= 0;
5255 pAsm
->D
.dst
.writez
= 0;
5256 pAsm
->D
.dst
.writew
= 0;
5257 pAsm
->D2
.dst2
.literal_slots
= 1;
5258 pAsm
->D2
.dst2
.SaturateMode
= SATURATE_OFF
;
5259 pAsm
->D
.dst
.predicated
= 0;
5260 /* in reloc where dislink flag init inst, only one slot alu inst is handled. */
5261 pAsm
->D
.dst
.math
= 1; /* TODO : not math really, but one channel op, more generic alu assembler needed */
5262 pAsm
->D2
.dst2
.index_mode
= SQ_INDEX_LOOP
; /* Check this ! */
5264 pAsm
->S
[0].src
.rtype
= SRC_REC_LITERAL
;
5265 //pAsm->S[0].src.reg = 0;
5266 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
5267 noneg_PVSSRC(&(pAsm
->S
[0].src
));
5268 pAsm
->S
[0].src
.swizzlex
= SQ_SEL_X
;
5269 pAsm
->S
[0].src
.swizzley
= SQ_SEL_Y
;
5270 pAsm
->S
[0].src
.swizzlez
= SQ_SEL_Z
;
5271 pAsm
->S
[0].src
.swizzlew
= SQ_SEL_W
;
5273 if( GL_FALSE
== next_ins_literal(pAsm
, &(fLiteral
[0])) )
5278 pAsm
->S
[0].src
.rtype
= DST_REG_TEMPORARY
;
5279 pAsm
->S
[0].src
.reg
= 0;
5280 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
5281 noneg_PVSSRC(&(pAsm
->S
[0].src
));
5282 pAsm
->S
[0].src
.swizzlex
= flagValue
;
5283 pAsm
->S
[0].src
.swizzley
= flagValue
;
5284 pAsm
->S
[0].src
.swizzlez
= flagValue
;
5285 pAsm
->S
[0].src
.swizzlew
= flagValue
;
5287 if( GL_FALSE
== next_ins(pAsm
) )
5296 GLboolean
testFlag(r700_AssemblerBase
*pAsm
)
5298 GLfloat fLiteral
[2] = {0.1, 0.0};
5301 GLuint tmp
= gethelpr(pAsm
);
5302 pAsm
->alu_x_opcode
= SQ_CF_INST_ALU_PUSH_BEFORE
;
5304 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_PRED_SETE
;
5305 pAsm
->D
.dst
.math
= 1;
5306 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
5307 pAsm
->D
.dst
.reg
= tmp
;
5308 pAsm
->D
.dst
.writex
= 1;
5309 pAsm
->D
.dst
.writey
= 0;
5310 pAsm
->D
.dst
.writez
= 0;
5311 pAsm
->D
.dst
.writew
= 0;
5312 pAsm
->D2
.dst2
.literal_slots
= 1;
5313 pAsm
->D2
.dst2
.SaturateMode
= SATURATE_OFF
;
5314 pAsm
->D
.dst
.predicated
= 1;
5315 pAsm
->D2
.dst2
.index_mode
= SQ_INDEX_LOOP
; /* Check this ! */
5317 pAsm
->S
[0].src
.rtype
= DST_REG_TEMPORARY
;
5318 pAsm
->S
[0].src
.reg
= pAsm
->flag_reg_index
;
5319 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
5320 noneg_PVSSRC(&(pAsm
->S
[0].src
));
5321 pAsm
->S
[0].src
.swizzlex
= SQ_SEL_X
;
5322 pAsm
->S
[0].src
.swizzley
= SQ_SEL_Y
;
5323 pAsm
->S
[0].src
.swizzlez
= SQ_SEL_Z
;
5324 pAsm
->S
[0].src
.swizzlew
= SQ_SEL_W
;
5326 pAsm
->S
[1].src
.rtype
= SRC_REC_LITERAL
;
5327 //pAsm->S[1].src.reg = 0;
5328 setaddrmode_PVSSRC(&(pAsm
->S
[1].src
), ADDR_ABSOLUTE
);
5329 noneg_PVSSRC(&(pAsm
->S
[1].src
));
5330 pAsm
->S
[1].src
.swizzlex
= SQ_SEL_X
;
5331 pAsm
->S
[1].src
.swizzley
= SQ_SEL_Y
;
5332 pAsm
->S
[1].src
.swizzlez
= SQ_SEL_Z
;
5333 pAsm
->S
[1].src
.swizzlew
= SQ_SEL_W
;
5335 if( GL_FALSE
== next_ins_literal(pAsm
, &(fLiteral
[0])) )
5340 pAsm
->S
[1].src
.rtype
= DST_REG_TEMPORARY
;
5341 pAsm
->S
[1].src
.reg
= 0;
5342 setaddrmode_PVSSRC(&(pAsm
->S
[1].src
), ADDR_ABSOLUTE
);
5343 noneg_PVSSRC(&(pAsm
->S
[1].src
));
5344 pAsm
->S
[1].src
.swizzlex
= SQ_SEL_1
;
5345 pAsm
->S
[1].src
.swizzley
= SQ_SEL_1
;
5346 pAsm
->S
[1].src
.swizzlez
= SQ_SEL_1
;
5347 pAsm
->S
[1].src
.swizzlew
= SQ_SEL_1
;
5349 if( GL_FALSE
== next_ins(pAsm
) )
5355 checkStackDepth(pAsm
, FC_PUSH_VPM
, GL_TRUE
);
5360 GLboolean
returnOnFlag(r700_AssemblerBase
*pAsm
, GLuint unIF
)
5363 jumpToOffest(pAsm
, 1, 4);
5364 setRetInLoopFlag(pAsm
, SQ_SEL_0
);
5365 pops(pAsm
, unIF
+ 1);
5366 add_return_inst(pAsm
);
5371 GLboolean
breakLoopOnFlag(r700_AssemblerBase
*pAsm
, GLuint unFCSP
)
5376 if(GL_FALSE
== add_cf_instruction(pAsm
) )
5381 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.pop_count
= 1;
5382 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.cf_const
= 0x0;
5383 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.cond
= SQ_CF_COND_ACTIVE
;
5385 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.end_of_program
= 0x0;
5386 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.valid_pixel_mode
= 0x0;
5387 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.cf_inst
= SQ_CF_INST_LOOP_BREAK
;
5388 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.whole_quad_mode
= 0x0;
5390 pAsm
->cf_current_cf_clause_ptr
->m_Word1
.f
.barrier
= 0x1;
5392 pAsm
->fc_stack
[unFCSP
].mid
= (R700ControlFlowGenericClause
**)_mesa_realloc(
5393 (void *)pAsm
->fc_stack
[unFCSP
].mid
,
5394 sizeof(R700ControlFlowGenericClause
*) * pAsm
->fc_stack
[unFCSP
].unNumMid
,
5395 sizeof(R700ControlFlowGenericClause
*) * (pAsm
->fc_stack
[unFCSP
].unNumMid
+ 1) );
5396 pAsm
->fc_stack
[unFCSP
].mid
[pAsm
->fc_stack
[unFCSP
].unNumMid
] = pAsm
->cf_current_cf_clause_ptr
;
5397 pAsm
->fc_stack
[unFCSP
].unNumMid
++;
5404 GLboolean
AssembleInstr(GLuint uiFirstInst
,
5406 GLuint uiNumberInsts
,
5407 struct prog_instruction
*pILInst
,
5408 r700_AssemblerBase
*pR700AsmCode
)
5412 pR700AsmCode
->pILInst
= pILInst
;
5413 for(i
=uiFirstInst
; i
<uiNumberInsts
; i
++)
5415 pR700AsmCode
->uiCurInst
= i
;
5417 #ifndef USE_CF_FOR_CONTINUE_BREAK
5418 if(OPCODE_BRK
== pILInst
[i
+1].Opcode
)
5420 switch(pILInst
[i
].Opcode
)
5423 pILInst
[i
].Opcode
= OPCODE_SGT
;
5426 pILInst
[i
].Opcode
= OPCODE_SGE
;
5429 pILInst
[i
].Opcode
= OPCODE_SLT
;
5432 pILInst
[i
].Opcode
= OPCODE_SLE
;
5435 pILInst
[i
].Opcode
= OPCODE_SNE
;
5438 pILInst
[i
].Opcode
= OPCODE_SEQ
;
5445 if(pILInst
[i
].CondUpdate
== 1)
5447 /* remember dest register used for cond evaluation */
5448 /* XXX also handle PROGRAM_OUTPUT registers here? */
5449 pR700AsmCode
->last_cond_register
= pILInst
[i
].DstReg
.Index
;
5452 switch (pILInst
[i
].Opcode
)
5455 if ( GL_FALSE
== assemble_ABS(pR700AsmCode
) )
5460 if ( GL_FALSE
== assemble_ADD(pR700AsmCode
) )
5465 if ( GL_FALSE
== assemble_ARL(pR700AsmCode
) )
5469 radeon_error("Not yet implemented instruction OPCODE_ARR \n");
5470 //if ( GL_FALSE == assemble_BAD("ARR") )
5475 if ( GL_FALSE
== assemble_CMP(pR700AsmCode
) )
5479 if ( GL_FALSE
== assemble_TRIG(pR700AsmCode
, SQ_OP2_INST_COS
) )
5486 if ( GL_FALSE
== assemble_DOT(pR700AsmCode
) )
5491 if ( GL_FALSE
== assemble_DST(pR700AsmCode
) )
5496 if ( GL_FALSE
== assemble_EX2(pR700AsmCode
) )
5500 if ( GL_FALSE
== assemble_EXP(pR700AsmCode
) )
5505 if ( GL_FALSE
== assemble_FLR(pR700AsmCode
) )
5508 //case OP_FLR_INT: ;
5510 // if ( GL_FALSE == assemble_FLR_INT() )
5515 if ( GL_FALSE
== assemble_FRC(pR700AsmCode
) )
5521 if ( GL_FALSE
== assemble_KIL(pR700AsmCode
, SQ_OP2_INST_KILLGT
) )
5525 if ( GL_FALSE
== assemble_LG2(pR700AsmCode
) )
5529 if ( GL_FALSE
== assemble_LIT(pR700AsmCode
) )
5533 if ( GL_FALSE
== assemble_LRP(pR700AsmCode
) )
5537 if ( GL_FALSE
== assemble_LOG(pR700AsmCode
) )
5542 if ( GL_FALSE
== assemble_MAD(pR700AsmCode
) )
5546 if ( GL_FALSE
== assemble_MAX(pR700AsmCode
) )
5550 if ( GL_FALSE
== assemble_MIN(pR700AsmCode
) )
5555 if ( GL_FALSE
== assemble_MOV(pR700AsmCode
) )
5559 if ( GL_FALSE
== assemble_MUL(pR700AsmCode
) )
5565 callPreSub(pR700AsmCode
,
5568 pILInst
->DstReg
.Index
+ pR700AsmCode
->starting_temp_register_number
,
5570 radeon_error("noise1: not yet supported shader instruction\n");
5574 radeon_error("noise2: not yet supported shader instruction\n");
5577 radeon_error("noise3: not yet supported shader instruction\n");
5580 radeon_error("noise4: not yet supported shader instruction\n");
5584 if ( GL_FALSE
== assemble_POW(pR700AsmCode
) )
5588 if ( GL_FALSE
== assemble_RCP(pR700AsmCode
) )
5592 if ( GL_FALSE
== assemble_RSQ(pR700AsmCode
) )
5596 if ( GL_FALSE
== assemble_TRIG(pR700AsmCode
, SQ_OP2_INST_SIN
) )
5600 if ( GL_FALSE
== assemble_SCS(pR700AsmCode
) )
5605 if ( GL_FALSE
== assemble_LOGIC(pR700AsmCode
, SQ_OP2_INST_SETE
) )
5612 if ( GL_FALSE
== assemble_LOGIC(pR700AsmCode
, SQ_OP2_INST_SETGT
) )
5619 if ( GL_FALSE
== assemble_SGE(pR700AsmCode
) )
5625 /* NO LT, LE, TODO : use GE => LE, GT => LT : reverse 2 src order would be simpliest. Or use SQ_CF_COND_FALSE for SQ_CF_COND_ACTIVE.*/
5628 struct prog_src_register SrcRegSave
[2];
5629 SrcRegSave
[0] = pILInst
[i
].SrcReg
[0];
5630 SrcRegSave
[1] = pILInst
[i
].SrcReg
[1];
5631 pILInst
[i
].SrcReg
[0] = SrcRegSave
[1];
5632 pILInst
[i
].SrcReg
[1] = SrcRegSave
[0];
5633 if ( GL_FALSE
== assemble_LOGIC(pR700AsmCode
, SQ_OP2_INST_SETGT
) )
5635 pILInst
[i
].SrcReg
[0] = SrcRegSave
[0];
5636 pILInst
[i
].SrcReg
[1] = SrcRegSave
[1];
5639 pILInst
[i
].SrcReg
[0] = SrcRegSave
[0];
5640 pILInst
[i
].SrcReg
[1] = SrcRegSave
[1];
5646 struct prog_src_register SrcRegSave
[2];
5647 SrcRegSave
[0] = pILInst
[i
].SrcReg
[0];
5648 SrcRegSave
[1] = pILInst
[i
].SrcReg
[1];
5649 pILInst
[i
].SrcReg
[0] = SrcRegSave
[1];
5650 pILInst
[i
].SrcReg
[1] = SrcRegSave
[0];
5651 if ( GL_FALSE
== assemble_LOGIC(pR700AsmCode
, SQ_OP2_INST_SETGE
) )
5653 pILInst
[i
].SrcReg
[0] = SrcRegSave
[0];
5654 pILInst
[i
].SrcReg
[1] = SrcRegSave
[1];
5657 pILInst
[i
].SrcReg
[0] = SrcRegSave
[0];
5658 pILInst
[i
].SrcReg
[1] = SrcRegSave
[1];
5663 if ( GL_FALSE
== assemble_LOGIC(pR700AsmCode
, SQ_OP2_INST_SETNE
) )
5670 // if ( GL_FALSE == assemble_STP(pR700AsmCode) )
5675 if ( GL_FALSE
== assemble_MOV(pR700AsmCode
) )
5681 if( (i
+1)<uiNumberInsts
)
5683 if(OPCODE_END
!= pILInst
[i
+1].Opcode
)
5685 if( GL_TRUE
== IsTex(pILInst
[i
+1].Opcode
) )
5687 pR700AsmCode
->pInstDeps
[i
+1].nDstDep
= i
+1; //=1?
5698 if ( GL_FALSE
== assemble_TEX(pR700AsmCode
) )
5703 if ( GL_FALSE
== assemble_math_function(pR700AsmCode
, SQ_OP2_INST_TRUNC
) )
5708 if ( GL_FALSE
== assemble_XPD(pR700AsmCode
) )
5714 GLboolean bHasElse
= GL_FALSE
;
5716 if(pILInst
[pILInst
[i
].BranchTarget
- 1].Opcode
== OPCODE_ELSE
)
5721 if ( GL_FALSE
== assemble_IF(pR700AsmCode
, bHasElse
) )
5729 if ( GL_FALSE
== assemble_ELSE(pR700AsmCode
) )
5734 if ( GL_FALSE
== assemble_ENDIF(pR700AsmCode
) )
5738 case OPCODE_BGNLOOP
:
5739 if( GL_FALSE
== assemble_BGNLOOP(pR700AsmCode
) )
5746 if( GL_FALSE
== assemble_BRK(pR700AsmCode
) )
5753 if( GL_FALSE
== assemble_CONT(pR700AsmCode
) )
5759 case OPCODE_ENDLOOP
:
5760 if( GL_FALSE
== assemble_ENDLOOP(pR700AsmCode
) )
5767 if( GL_FALSE
== assemble_BGNSUB(pR700AsmCode
, i
, uiIL_Shift
) )
5774 if( GL_FALSE
== assemble_RET(pR700AsmCode
) )
5781 if( GL_FALSE
== assemble_CAL(pR700AsmCode
,
5782 pILInst
[i
].BranchTarget
,
5792 //case OPCODE_EXPORT:
5793 // if ( GL_FALSE == assemble_EXPORT() )
5798 return assemble_ENDSUB(pR700AsmCode
);
5801 //pR700AsmCode->uiCurInst = i;
5802 //This is to remaind that if in later exoort there is depth/stencil
5803 //export, we need a mov to re-arrange DST channel, where using a
5804 //psuedo inst, we will use this end inst to do it.
5808 radeon_error("internal: unknown instruction\n");
5816 GLboolean
InitShaderProgram(r700_AssemblerBase
* pAsm
)
5818 setRetInLoopFlag(pAsm
, SQ_SEL_0
);
5819 pAsm
->alu_x_opcode
= SQ_CF_INST_ALU
;
5823 GLboolean
RelocProgram(r700_AssemblerBase
* pAsm
, struct gl_program
* pILProg
)
5827 TypedShaderList
* plstCFmain
;
5828 TypedShaderList
* plstCFsub
;
5830 R700ShaderInstruction
* pInst
;
5831 R700ControlFlowGenericClause
* pCFInst
;
5833 R700ControlFlowALUClause
* pCF_ALU
;
5834 R700ALUInstruction
* pALU
;
5835 GLuint unConstOffset
= 0;
5837 GLuint unMinRegIndex
;
5839 plstCFmain
= pAsm
->CALLSTACK
[0].plstCFInstructions_local
;
5841 /* remove flags init if they are not used */
5842 if((pAsm
->unCFflags
& HAS_LOOPRET
) == 0)
5844 R700ControlFlowALUClause
* pCF_ALU
;
5845 pInst
= plstCFmain
->pHead
;
5848 if(SIT_CF_ALU
== pInst
->m_ShaderInstType
)
5850 pCF_ALU
= (R700ControlFlowALUClause
*)pInst
;
5851 if(0 == pCF_ALU
->m_Word1
.f
.count
)
5853 pCF_ALU
->m_Word1
.f
.cf_inst
= SQ_CF_INST_NOP
;
5857 R700ALUInstruction
* pALU
= pCF_ALU
->m_pLinkedALUInstruction
;
5859 pALU
->m_pLinkedALUClause
= NULL
;
5860 pALU
= (R700ALUInstruction
*)(pALU
->pNextInst
);
5861 pALU
->m_pLinkedALUClause
= pCF_ALU
;
5862 pCF_ALU
->m_pLinkedALUInstruction
= pALU
;
5864 pCF_ALU
->m_Word1
.f
.count
--;
5868 pInst
= pInst
->pNextInst
;
5872 if(pAsm
->CALLSTACK
[0].max
> 0)
5874 pAsm
->pR700Shader
->uStackSize
= ((pAsm
->CALLSTACK
[0].max
+ 3)>>2) + 2;
5877 if(0 == pAsm
->unSubArrayPointer
)
5882 unCFoffset
= plstCFmain
->uNumOfNode
;
5884 if(NULL
!= pILProg
->Parameters
)
5886 unConstOffset
= pILProg
->Parameters
->NumParameters
;
5890 for(i
=0; i
<pAsm
->unSubArrayPointer
; i
++)
5892 pAsm
->subs
[i
].unCFoffset
= unCFoffset
;
5893 plstCFsub
= &(pAsm
->subs
[i
].lstCFInstructions_local
);
5895 pInst
= plstCFsub
->pHead
;
5897 /* reloc instructions */
5900 if(SIT_CF_GENERIC
== pInst
->m_ShaderInstType
)
5902 pCFInst
= (R700ControlFlowGenericClause
*)pInst
;
5904 switch (pCFInst
->m_Word1
.f
.cf_inst
)
5906 case SQ_CF_INST_POP
:
5907 case SQ_CF_INST_JUMP
:
5908 case SQ_CF_INST_ELSE
:
5909 case SQ_CF_INST_LOOP_END
:
5910 case SQ_CF_INST_LOOP_START
:
5911 case SQ_CF_INST_LOOP_START_NO_AL
:
5912 case SQ_CF_INST_LOOP_CONTINUE
:
5913 case SQ_CF_INST_LOOP_BREAK
:
5914 pCFInst
->m_Word0
.f
.addr
+= unCFoffset
;
5921 pInst
->m_uIndex
+= unCFoffset
;
5923 pInst
= pInst
->pNextInst
;
5926 if(NULL
!= pAsm
->subs
[i
].pPresubDesc
)
5930 unMinRegIndex
= pAsm
->subs
[i
].pPresubDesc
->pCompiledSub
->MinRegIndex
;
5931 unRegOffset
= pAsm
->subs
[i
].pPresubDesc
->maxStartReg
;
5932 unConstOffset
+= pAsm
->subs
[i
].pPresubDesc
->unConstantsStart
;
5934 pInst
= plstCFsub
->pHead
;
5937 if(SIT_CF_ALU
== pInst
->m_ShaderInstType
)
5939 pCF_ALU
= (R700ControlFlowALUClause
*)pInst
;
5941 pALU
= pCF_ALU
->m_pLinkedALUInstruction
;
5942 for(int j
=0; j
<=pCF_ALU
->m_Word1
.f
.count
; j
++)
5944 pALU
->m_Word1
.f
.dst_gpr
= pALU
->m_Word1
.f
.dst_gpr
+ unRegOffset
- unMinRegIndex
;
5946 if(pALU
->m_Word0
.f
.src0_sel
< SQ_ALU_SRC_GPR_SIZE
)
5948 pALU
->m_Word0
.f
.src0_sel
= pALU
->m_Word0
.f
.src0_sel
+ unRegOffset
- unMinRegIndex
;
5950 else if(pALU
->m_Word0
.f
.src0_sel
>= SQ_ALU_SRC_CFILE_BASE
)
5952 pALU
->m_Word0
.f
.src0_sel
+= unConstOffset
;
5955 if( ((pALU
->m_Word1
.val
>> SQ_ALU_WORD1_OP3_ALU_INST_SHIFT
) & 0x0000001F)
5956 >= SQ_OP3_INST_MUL_LIT
)
5957 { /* op3 : 3 srcs */
5958 if(pALU
->m_Word1_OP3
.f
.src2_sel
< SQ_ALU_SRC_GPR_SIZE
)
5960 pALU
->m_Word1_OP3
.f
.src2_sel
= pALU
->m_Word1_OP3
.f
.src2_sel
+ unRegOffset
- unMinRegIndex
;
5962 else if(pALU
->m_Word1_OP3
.f
.src2_sel
>= SQ_ALU_SRC_CFILE_BASE
)
5964 pALU
->m_Word1_OP3
.f
.src2_sel
+= unConstOffset
;
5966 if(pALU
->m_Word0
.f
.src1_sel
< SQ_ALU_SRC_GPR_SIZE
)
5968 pALU
->m_Word0
.f
.src1_sel
= pALU
->m_Word0
.f
.src1_sel
+ unRegOffset
- unMinRegIndex
;
5970 else if(pALU
->m_Word0
.f
.src1_sel
>= SQ_ALU_SRC_CFILE_BASE
)
5972 pALU
->m_Word0
.f
.src1_sel
+= unConstOffset
;
5979 uNumSrc
= r700GetNumOperands(pALU
->m_Word1_OP2
.f6
.alu_inst
, 0);
5983 uNumSrc
= r700GetNumOperands(pALU
->m_Word1_OP2
.f
.alu_inst
, 0);
5987 if(pALU
->m_Word0
.f
.src1_sel
< SQ_ALU_SRC_GPR_SIZE
)
5989 pALU
->m_Word0
.f
.src1_sel
= pALU
->m_Word0
.f
.src1_sel
+ unRegOffset
- unMinRegIndex
;
5991 else if(pALU
->m_Word0
.f
.src1_sel
>= SQ_ALU_SRC_CFILE_BASE
)
5993 pALU
->m_Word0
.f
.src1_sel
+= unConstOffset
;
5997 pALU
= (R700ALUInstruction
*)(pALU
->pNextInst
);
6000 pInst
= pInst
->pNextInst
;
6004 /* Put sub into main */
6005 plstCFmain
->pTail
->pNextInst
= plstCFsub
->pHead
;
6006 plstCFmain
->pTail
= plstCFsub
->pTail
;
6007 plstCFmain
->uNumOfNode
+= plstCFsub
->uNumOfNode
;
6009 unCFoffset
+= plstCFsub
->uNumOfNode
;
6013 for(i
=0; i
<pAsm
->unCallerArrayPointer
; i
++)
6015 pAsm
->callers
[i
].cf_ptr
->m_Word0
.f
.addr
6016 = pAsm
->subs
[pAsm
->callers
[i
].subDescIndex
].unCFoffset
;
6018 if(NULL
!= pAsm
->subs
[pAsm
->callers
[i
].subDescIndex
].pPresubDesc
)
6020 unMinRegIndex
= pAsm
->subs
[pAsm
->callers
[i
].subDescIndex
].pPresubDesc
->pCompiledSub
->MinRegIndex
;
6021 unRegOffset
= pAsm
->subs
[pAsm
->callers
[i
].subDescIndex
].pPresubDesc
->maxStartReg
;
6023 if(NULL
!= pAsm
->callers
[i
].prelude_cf_ptr
)
6025 pCF_ALU
= (R700ControlFlowALUClause
* )(pAsm
->callers
[i
].prelude_cf_ptr
);
6026 pALU
= pCF_ALU
->m_pLinkedALUInstruction
;
6027 for(int j
=0; j
<=pCF_ALU
->m_Word1
.f
.count
; j
++)
6029 pALU
->m_Word1
.f
.dst_gpr
= pALU
->m_Word1
.f
.dst_gpr
+ unRegOffset
- unMinRegIndex
;
6030 pALU
= (R700ALUInstruction
*)(pALU
->pNextInst
);
6033 if(NULL
!= pAsm
->callers
[i
].finale_cf_ptr
)
6035 pCF_ALU
= (R700ControlFlowALUClause
* )(pAsm
->callers
[i
].finale_cf_ptr
);
6036 pALU
= pCF_ALU
->m_pLinkedALUInstruction
;
6037 for(int j
=0; j
<=pCF_ALU
->m_Word1
.f
.count
; j
++)
6039 pALU
->m_Word0
.f
.src0_sel
= pALU
->m_Word0
.f
.src0_sel
+ unRegOffset
- unMinRegIndex
;
6040 pALU
= (R700ALUInstruction
*)(pALU
->pNextInst
);
6049 GLboolean
callPreSub(r700_AssemblerBase
* pAsm
,
6050 LOADABLE_SCRIPT_SIGNITURE scriptSigniture
,
6051 COMPILED_SUB
* pCompiledSub
,
6053 GLshort uNumValidSrc
)
6055 /* save assemble context */
6056 GLuint starting_temp_register_number_save
;
6057 GLuint number_used_registers_save
;
6058 GLuint uFirstHelpReg_save
;
6059 GLuint uHelpReg_save
;
6060 GLuint uiCurInst_save
;
6061 struct prog_instruction
*pILInst_save
;
6062 PRESUB_DESC
* pPresubDesc
;
6066 R700ControlFlowGenericClause
* prelude_cf_ptr
= NULL
;
6068 /* copy srcs to presub inputs */
6069 pAsm
->alu_x_opcode
= SQ_CF_INST_ALU
;
6070 for(i
=0; i
<uNumValidSrc
; i
++)
6072 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_MOV
;
6073 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
6074 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
6075 pAsm
->D
.dst
.reg
= pCompiledSub
->srcRegIndex
[i
];
6076 pAsm
->D
.dst
.writex
= 1;
6077 pAsm
->D
.dst
.writey
= 1;
6078 pAsm
->D
.dst
.writez
= 1;
6079 pAsm
->D
.dst
.writew
= 1;
6081 if( GL_FALSE
== assemble_src(pAsm
, i
, 0) )
6088 if(uNumValidSrc
> 0)
6090 prelude_cf_ptr
= pAsm
->cf_current_alu_clause_ptr
;
6091 pAsm
->alu_x_opcode
= SQ_CF_INST_ALU
;
6094 /* browse thro existing presubs. */
6095 for(i
=0; i
<pAsm
->unNumPresub
; i
++)
6097 if(pAsm
->presubs
[i
].sptSigniture
== scriptSigniture
)
6103 if(i
== pAsm
->unNumPresub
)
6104 { /* not loaded yet */
6105 /* save assemble context */
6106 number_used_registers_save
= pAsm
->number_used_registers
;
6107 uFirstHelpReg_save
= pAsm
->uFirstHelpReg
;
6108 uHelpReg_save
= pAsm
->uHelpReg
;
6109 starting_temp_register_number_save
= pAsm
->starting_temp_register_number
;
6110 pILInst_save
= pAsm
->pILInst
;
6111 uiCurInst_save
= pAsm
->uiCurInst
;
6113 /* alloc in presub */
6114 if( (pAsm
->unNumPresub
+ 1) > pAsm
->unPresubArraySize
)
6116 pAsm
->presubs
= (PRESUB_DESC
*)_mesa_realloc( (void *)pAsm
->presubs
,
6117 sizeof(PRESUB_DESC
) * pAsm
->unPresubArraySize
,
6118 sizeof(PRESUB_DESC
) * (pAsm
->unPresubArraySize
+ 4) );
6119 if(NULL
== pAsm
->presubs
)
6121 radeon_error("No memeory to allocate built in shader function description structures. \n");
6124 pAsm
->unPresubArraySize
+= 4;
6127 pPresubDesc
= &(pAsm
->presubs
[i
]);
6128 pPresubDesc
->sptSigniture
= scriptSigniture
;
6130 /* constants offsets need to be final resolved at reloc. */
6131 if(0 == pAsm
->unNumPresub
)
6133 pPresubDesc
->unConstantsStart
= 0;
6137 pPresubDesc
->unConstantsStart
= pAsm
->presubs
[i
-1].unConstantsStart
6138 + pAsm
->presubs
[i
-1].pCompiledSub
->NumParameters
;
6141 pPresubDesc
->pCompiledSub
= pCompiledSub
;
6143 pPresubDesc
->subIL_Shift
= pAsm
->unCurNumILInsts
;
6144 pPresubDesc
->maxStartReg
= uFirstHelpReg_save
;
6145 pAsm
->unCurNumILInsts
+= pCompiledSub
->NumInstructions
;
6147 pAsm
->unNumPresub
++;
6149 /* setup new assemble context */
6150 pAsm
->starting_temp_register_number
= 0;
6151 pAsm
->number_used_registers
= pCompiledSub
->NumTemporaries
;
6152 pAsm
->uFirstHelpReg
= pAsm
->number_used_registers
;
6153 pAsm
->uHelpReg
= pAsm
->uFirstHelpReg
;
6155 bRet
= assemble_CAL(pAsm
,
6157 pPresubDesc
->subIL_Shift
,
6158 pCompiledSub
->NumInstructions
,
6159 pCompiledSub
->Instructions
,
6163 pPresubDesc
->number_used_registers
= pAsm
->number_used_registers
;
6165 /* restore assemble context */
6166 pAsm
->number_used_registers
= number_used_registers_save
;
6167 pAsm
->uFirstHelpReg
= uFirstHelpReg_save
;
6168 pAsm
->uHelpReg
= uHelpReg_save
;
6169 pAsm
->starting_temp_register_number
= starting_temp_register_number_save
;
6170 pAsm
->pILInst
= pILInst_save
;
6171 pAsm
->uiCurInst
= uiCurInst_save
;
6175 pPresubDesc
= &(pAsm
->presubs
[i
]);
6177 bRet
= assemble_CAL(pAsm
,
6179 pPresubDesc
->subIL_Shift
,
6180 pCompiledSub
->NumInstructions
,
6181 pCompiledSub
->Instructions
,
6185 if(GL_FALSE
== bRet
)
6187 radeon_error("Shader presub assemble failed. \n");
6191 /* copy presub output to real dst */
6192 pAsm
->alu_x_opcode
= SQ_CF_INST_ALU
;
6193 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_MOV
;
6195 if( GL_FALSE
== assemble_dst(pAsm
) )
6200 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
6201 pAsm
->S
[0].src
.rtype
= SRC_REG_TEMPORARY
;
6202 pAsm
->S
[0].src
.reg
= pCompiledSub
->dstRegIndex
;
6203 pAsm
->S
[0].src
.swizzlex
= pCompiledSub
->outputSwizzleX
;
6204 pAsm
->S
[0].src
.swizzley
= pCompiledSub
->outputSwizzleY
;
6205 pAsm
->S
[0].src
.swizzlez
= pCompiledSub
->outputSwizzleZ
;
6206 pAsm
->S
[0].src
.swizzlew
= pCompiledSub
->outputSwizzleW
;
6210 pAsm
->callers
[pAsm
->unCallerArrayPointer
- 1].finale_cf_ptr
= pAsm
->cf_current_alu_clause_ptr
;
6211 pAsm
->callers
[pAsm
->unCallerArrayPointer
- 1].prelude_cf_ptr
= prelude_cf_ptr
;
6212 pAsm
->alu_x_opcode
= SQ_CF_INST_ALU
;
6215 if( (pPresubDesc
->number_used_registers
+ pAsm
->uFirstHelpReg
) > pAsm
->number_used_registers
)
6217 pAsm
->number_used_registers
= pPresubDesc
->number_used_registers
+ pAsm
->uFirstHelpReg
;
6219 if(pAsm
->uFirstHelpReg
> pPresubDesc
->maxStartReg
)
6221 pPresubDesc
->maxStartReg
= pAsm
->uFirstHelpReg
;
6227 GLboolean
Process_Export(r700_AssemblerBase
* pAsm
,
6229 GLuint export_starting_index
,
6230 GLuint export_count
,
6231 GLuint starting_register_number
,
6232 GLboolean is_depth_export
)
6234 unsigned char ucWriteMask
;
6236 check_current_clause(pAsm
, CF_EMPTY_CLAUSE
);
6237 check_current_clause(pAsm
, CF_EXPORT_CLAUSE
); //alloc the cf_current_export_clause_ptr
6239 pAsm
->cf_current_export_clause_ptr
->m_Word0
.f
.type
= type
;
6243 case SQ_EXPORT_PIXEL
:
6244 if(GL_TRUE
== is_depth_export
)
6246 pAsm
->cf_current_export_clause_ptr
->m_Word0
.f
.array_base
= SQ_CF_PIXEL_Z
;
6250 pAsm
->cf_current_export_clause_ptr
->m_Word0
.f
.array_base
= SQ_CF_PIXEL_MRT0
+ export_starting_index
;
6255 pAsm
->cf_current_export_clause_ptr
->m_Word0
.f
.array_base
= SQ_CF_POS_0
+ export_starting_index
;
6258 case SQ_EXPORT_PARAM
:
6259 pAsm
->cf_current_export_clause_ptr
->m_Word0
.f
.array_base
= 0x0 + export_starting_index
;
6263 radeon_error("Unknown export type: %d\n", type
);
6268 pAsm
->cf_current_export_clause_ptr
->m_Word0
.f
.rw_gpr
= starting_register_number
;
6270 pAsm
->cf_current_export_clause_ptr
->m_Word0
.f
.rw_rel
= SQ_ABSOLUTE
;
6271 pAsm
->cf_current_export_clause_ptr
->m_Word0
.f
.index_gpr
= 0x0;
6272 pAsm
->cf_current_export_clause_ptr
->m_Word0
.f
.elem_size
= 0x3;
6274 pAsm
->cf_current_export_clause_ptr
->m_Word1
.f
.burst_count
= (export_count
- 1);
6275 pAsm
->cf_current_export_clause_ptr
->m_Word1
.f
.end_of_program
= 0x0;
6276 pAsm
->cf_current_export_clause_ptr
->m_Word1
.f
.valid_pixel_mode
= 0x0;
6277 pAsm
->cf_current_export_clause_ptr
->m_Word1
.f
.cf_inst
= SQ_CF_INST_EXPORT
; // _DONE
6278 pAsm
->cf_current_export_clause_ptr
->m_Word1
.f
.whole_quad_mode
= 0x0;
6279 pAsm
->cf_current_export_clause_ptr
->m_Word1
.f
.barrier
= 0x1;
6281 if (export_count
== 1)
6283 ucWriteMask
= pAsm
->pucOutMask
[starting_register_number
- pAsm
->starting_export_register_number
];
6284 /* exports Z as a float into Red channel */
6285 if (GL_TRUE
== is_depth_export
)
6288 if( (ucWriteMask
& 0x1) != 0)
6290 pAsm
->cf_current_export_clause_ptr
->m_Word1_SWIZ
.f
.sel_x
= SQ_SEL_X
;
6294 pAsm
->cf_current_export_clause_ptr
->m_Word1_SWIZ
.f
.sel_x
= SQ_SEL_MASK
;
6296 if( ((ucWriteMask
>>1) & 0x1) != 0)
6298 pAsm
->cf_current_export_clause_ptr
->m_Word1_SWIZ
.f
.sel_y
= SQ_SEL_Y
;
6302 pAsm
->cf_current_export_clause_ptr
->m_Word1_SWIZ
.f
.sel_y
= SQ_SEL_MASK
;
6304 if( ((ucWriteMask
>>2) & 0x1) != 0)
6306 pAsm
->cf_current_export_clause_ptr
->m_Word1_SWIZ
.f
.sel_z
= SQ_SEL_Z
;
6310 pAsm
->cf_current_export_clause_ptr
->m_Word1_SWIZ
.f
.sel_z
= SQ_SEL_MASK
;
6312 if( ((ucWriteMask
>>3) & 0x1) != 0)
6314 pAsm
->cf_current_export_clause_ptr
->m_Word1_SWIZ
.f
.sel_w
= SQ_SEL_W
;
6318 pAsm
->cf_current_export_clause_ptr
->m_Word1_SWIZ
.f
.sel_w
= SQ_SEL_MASK
;
6323 // This should only be used if all components for all registers have been written
6324 pAsm
->cf_current_export_clause_ptr
->m_Word1_SWIZ
.f
.sel_x
= SQ_SEL_X
;
6325 pAsm
->cf_current_export_clause_ptr
->m_Word1_SWIZ
.f
.sel_y
= SQ_SEL_Y
;
6326 pAsm
->cf_current_export_clause_ptr
->m_Word1_SWIZ
.f
.sel_z
= SQ_SEL_Z
;
6327 pAsm
->cf_current_export_clause_ptr
->m_Word1_SWIZ
.f
.sel_w
= SQ_SEL_W
;
6330 pAsm
->cf_last_export_ptr
= pAsm
->cf_current_export_clause_ptr
;
6335 GLboolean
Move_Depth_Exports_To_Correct_Channels(r700_AssemblerBase
*pAsm
, BITS depth_channel_select
)
6337 gl_inst_opcode Opcode_save
= pAsm
->pILInst
[pAsm
->uiCurInst
].Opcode
; //Should be OPCODE_END
6338 pAsm
->pILInst
[pAsm
->uiCurInst
].Opcode
= OPCODE_MOV
;
6340 // MOV depth_export_register.hw_depth_channel, depth_export_register.depth_channel_select
6342 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_MOV
;
6344 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
6345 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
6346 pAsm
->D
.dst
.reg
= pAsm
->depth_export_register_number
;
6348 pAsm
->D
.dst
.writex
= 1; // depth goes in R channel for HW
6350 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
6351 pAsm
->S
[0].src
.rtype
= DST_REG_TEMPORARY
;
6352 pAsm
->S
[0].src
.reg
= pAsm
->depth_export_register_number
;
6354 setswizzle_PVSSRC(&(pAsm
->S
[0].src
), depth_channel_select
);
6356 noneg_PVSSRC(&(pAsm
->S
[0].src
));
6358 if( GL_FALSE
== next_ins(pAsm
) )
6363 pAsm
->pILInst
[pAsm
->uiCurInst
].Opcode
= Opcode_save
;
6368 GLboolean
Process_Fragment_Exports(r700_AssemblerBase
*pR700AsmCode
,
6369 GLbitfield OutputsWritten
)
6372 GLuint export_count
= 0;
6374 if(pR700AsmCode
->depth_export_register_number
>= 0)
6376 if( GL_FALSE
== Move_Depth_Exports_To_Correct_Channels(pR700AsmCode
, SQ_SEL_Z
) ) // depth
6382 unBit
= 1 << FRAG_RESULT_COLOR
;
6383 if(OutputsWritten
& unBit
)
6385 if( GL_FALSE
== Process_Export(pR700AsmCode
,
6389 pR700AsmCode
->uiFP_OutputMap
[FRAG_RESULT_COLOR
],
6396 unBit
= 1 << FRAG_RESULT_DEPTH
;
6397 if(OutputsWritten
& unBit
)
6399 if( GL_FALSE
== Process_Export(pR700AsmCode
,
6403 pR700AsmCode
->uiFP_OutputMap
[FRAG_RESULT_DEPTH
],
6410 /* Need to export something, otherwise we'll hang
6411 * results are undefined anyway */
6412 if(export_count
== 0)
6414 Process_Export(pR700AsmCode
, SQ_EXPORT_PIXEL
, 0, 1, 0, GL_FALSE
);
6417 if(pR700AsmCode
->cf_last_export_ptr
!= NULL
)
6419 pR700AsmCode
->cf_last_export_ptr
->m_Word1
.f
.cf_inst
= SQ_CF_INST_EXPORT_DONE
;
6420 pR700AsmCode
->cf_last_export_ptr
->m_Word1
.f
.end_of_program
= 0x1;
6426 GLboolean
Process_Vertex_Exports(r700_AssemblerBase
*pR700AsmCode
,
6427 GLbitfield OutputsWritten
)
6432 GLuint export_starting_index
= 0;
6433 GLuint export_count
= pR700AsmCode
->number_of_exports
;
6435 unBit
= 1 << VERT_RESULT_HPOS
;
6436 if(OutputsWritten
& unBit
)
6438 if( GL_FALSE
== Process_Export(pR700AsmCode
,
6440 export_starting_index
,
6442 pR700AsmCode
->ucVP_OutputMap
[VERT_RESULT_HPOS
],
6450 pR700AsmCode
->cf_last_export_ptr
->m_Word1
.f
.cf_inst
= SQ_CF_INST_EXPORT_DONE
;
6453 pR700AsmCode
->number_of_exports
= export_count
;
6455 unBit
= 1 << VERT_RESULT_COL0
;
6456 if(OutputsWritten
& unBit
)
6458 if( GL_FALSE
== Process_Export(pR700AsmCode
,
6460 export_starting_index
,
6462 pR700AsmCode
->ucVP_OutputMap
[VERT_RESULT_COL0
],
6468 export_starting_index
++;
6471 unBit
= 1 << VERT_RESULT_COL1
;
6472 if(OutputsWritten
& unBit
)
6474 if( GL_FALSE
== Process_Export(pR700AsmCode
,
6476 export_starting_index
,
6478 pR700AsmCode
->ucVP_OutputMap
[VERT_RESULT_COL1
],
6484 export_starting_index
++;
6487 unBit
= 1 << VERT_RESULT_FOGC
;
6488 if(OutputsWritten
& unBit
)
6490 if( GL_FALSE
== Process_Export(pR700AsmCode
,
6492 export_starting_index
,
6494 pR700AsmCode
->ucVP_OutputMap
[VERT_RESULT_FOGC
],
6500 export_starting_index
++;
6505 unBit
= 1 << (VERT_RESULT_TEX0
+ i
);
6506 if(OutputsWritten
& unBit
)
6508 if( GL_FALSE
== Process_Export(pR700AsmCode
,
6510 export_starting_index
,
6512 pR700AsmCode
->ucVP_OutputMap
[VERT_RESULT_TEX0
+ i
],
6518 export_starting_index
++;
6522 for(i
=VERT_RESULT_VAR0
; i
<VERT_RESULT_MAX
; i
++)
6525 if(OutputsWritten
& unBit
)
6527 if( GL_FALSE
== Process_Export(pR700AsmCode
,
6529 export_starting_index
,
6531 pR700AsmCode
->ucVP_OutputMap
[i
],
6537 export_starting_index
++;
6541 // At least one param should be exported
6544 pR700AsmCode
->cf_last_export_ptr
->m_Word1
.f
.cf_inst
= SQ_CF_INST_EXPORT_DONE
;
6548 if( GL_FALSE
== Process_Export(pR700AsmCode
,
6552 pR700AsmCode
->starting_export_register_number
,
6558 pR700AsmCode
->cf_last_export_ptr
->m_Word1_SWIZ
.f
.sel_x
= SQ_SEL_0
;
6559 pR700AsmCode
->cf_last_export_ptr
->m_Word1_SWIZ
.f
.sel_y
= SQ_SEL_0
;
6560 pR700AsmCode
->cf_last_export_ptr
->m_Word1_SWIZ
.f
.sel_z
= SQ_SEL_0
;
6561 pR700AsmCode
->cf_last_export_ptr
->m_Word1_SWIZ
.f
.sel_w
= SQ_SEL_1
;
6562 pR700AsmCode
->cf_last_export_ptr
->m_Word1
.f
.cf_inst
= SQ_CF_INST_EXPORT_DONE
;
6565 pR700AsmCode
->cf_last_export_ptr
->m_Word1
.f
.end_of_program
= 0x1;
6570 GLboolean
Clean_Up_Assembler(r700_AssemblerBase
*pR700AsmCode
)
6572 FREE(pR700AsmCode
->pucOutMask
);
6573 FREE(pR700AsmCode
->pInstDeps
);
6575 if(NULL
!= pR700AsmCode
->subs
)
6577 FREE(pR700AsmCode
->subs
);
6579 if(NULL
!= pR700AsmCode
->callers
)
6581 FREE(pR700AsmCode
->callers
);
6584 if(NULL
!= pR700AsmCode
->presubs
)
6586 FREE(pR700AsmCode
->presubs
);