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"
36 #include "r600_context.h"
37 #include "r700_debug.h"
39 #include "r700_assembler.h"
41 BITS
addrmode_PVSDST(PVSDST
* pPVSDST
)
43 return pPVSDST
->addrmode0
| ((BITS
)pPVSDST
->addrmode1
<< 1);
46 void setaddrmode_PVSDST(PVSDST
* pPVSDST
, BITS addrmode
)
48 pPVSDST
->addrmode0
= addrmode
& 1;
49 pPVSDST
->addrmode1
= (addrmode
>> 1) & 1;
52 void nomask_PVSDST(PVSDST
* pPVSDST
)
54 pPVSDST
->writex
= pPVSDST
->writey
= pPVSDST
->writez
= pPVSDST
->writew
= 1;
57 BITS
addrmode_PVSSRC(PVSSRC
* pPVSSRC
)
59 return pPVSSRC
->addrmode0
| ((BITS
)pPVSSRC
->addrmode1
<< 1);
62 void setaddrmode_PVSSRC(PVSSRC
* pPVSSRC
, BITS addrmode
)
64 pPVSSRC
->addrmode0
= addrmode
& 1;
65 pPVSSRC
->addrmode1
= (addrmode
>> 1) & 1;
69 void setswizzle_PVSSRC(PVSSRC
* pPVSSRC
, BITS swz
)
74 pPVSSRC
->swizzlew
= swz
;
77 void noswizzle_PVSSRC(PVSSRC
* pPVSSRC
)
79 pPVSSRC
->swizzlex
= SQ_SEL_X
;
80 pPVSSRC
->swizzley
= SQ_SEL_Y
;
81 pPVSSRC
->swizzlez
= SQ_SEL_Z
;
82 pPVSSRC
->swizzlew
= SQ_SEL_W
;
86 swizzleagain_PVSSRC(PVSSRC
* pPVSSRC
, BITS x
, BITS y
, BITS z
, BITS w
)
90 case SQ_SEL_X
: x
= pPVSSRC
->swizzlex
;
92 case SQ_SEL_Y
: x
= pPVSSRC
->swizzley
;
94 case SQ_SEL_Z
: x
= pPVSSRC
->swizzlez
;
96 case SQ_SEL_W
: x
= pPVSSRC
->swizzlew
;
103 case SQ_SEL_X
: y
= pPVSSRC
->swizzlex
;
105 case SQ_SEL_Y
: y
= pPVSSRC
->swizzley
;
107 case SQ_SEL_Z
: y
= pPVSSRC
->swizzlez
;
109 case SQ_SEL_W
: y
= pPVSSRC
->swizzlew
;
116 case SQ_SEL_X
: z
= pPVSSRC
->swizzlex
;
118 case SQ_SEL_Y
: z
= pPVSSRC
->swizzley
;
120 case SQ_SEL_Z
: z
= pPVSSRC
->swizzlez
;
122 case SQ_SEL_W
: z
= pPVSSRC
->swizzlew
;
129 case SQ_SEL_X
: w
= pPVSSRC
->swizzlex
;
131 case SQ_SEL_Y
: w
= pPVSSRC
->swizzley
;
133 case SQ_SEL_Z
: w
= pPVSSRC
->swizzlez
;
135 case SQ_SEL_W
: w
= pPVSSRC
->swizzlew
;
140 pPVSSRC
->swizzlex
= x
;
141 pPVSSRC
->swizzley
= y
;
142 pPVSSRC
->swizzlez
= z
;
143 pPVSSRC
->swizzlew
= w
;
146 void neg_PVSSRC(PVSSRC
* pPVSSRC
)
154 void noneg_PVSSRC(PVSSRC
* pPVSSRC
)
162 // negate argument (for SUB instead of ADD and alike)
163 void flipneg_PVSSRC(PVSSRC
* pPVSSRC
)
165 pPVSSRC
->negx
= !pPVSSRC
->negx
;
166 pPVSSRC
->negy
= !pPVSSRC
->negy
;
167 pPVSSRC
->negz
= !pPVSSRC
->negz
;
168 pPVSSRC
->negw
= !pPVSSRC
->negw
;
171 void zerocomp_PVSSRC(PVSSRC
* pPVSSRC
, int c
)
175 case 0: pPVSSRC
->swizzlex
= SQ_SEL_0
; pPVSSRC
->negx
= 0; break;
176 case 1: pPVSSRC
->swizzley
= SQ_SEL_0
; pPVSSRC
->negy
= 0; break;
177 case 2: pPVSSRC
->swizzlez
= SQ_SEL_0
; pPVSSRC
->negz
= 0; break;
178 case 3: pPVSSRC
->swizzlew
= SQ_SEL_0
; pPVSSRC
->negw
= 0; break;
183 void onecomp_PVSSRC(PVSSRC
* pPVSSRC
, int c
)
187 case 0: pPVSSRC
->swizzlex
= SQ_SEL_1
; pPVSSRC
->negx
= 0; break;
188 case 1: pPVSSRC
->swizzley
= SQ_SEL_1
; pPVSSRC
->negy
= 0; break;
189 case 2: pPVSSRC
->swizzlez
= SQ_SEL_1
; pPVSSRC
->negz
= 0; break;
190 case 3: pPVSSRC
->swizzlew
= SQ_SEL_1
; pPVSSRC
->negw
= 0; break;
195 BITS
is_misc_component_exported(VAP_OUT_VTX_FMT_0
* pOutVTXFmt0
)
197 return (pOutVTXFmt0
->point_size
|
198 pOutVTXFmt0
->edge_flag
|
199 pOutVTXFmt0
->rta_index
|
200 pOutVTXFmt0
->kill_flag
|
201 pOutVTXFmt0
->viewport_index
);
204 BITS
is_depth_component_exported(OUT_FRAGMENT_FMT_0
* pFPOutFmt
)
206 return (pFPOutFmt
->depth
|
207 pFPOutFmt
->stencil_ref
|
209 pFPOutFmt
->coverage_to_mask
);
212 GLboolean
is_reduction_opcode(PVSDWORD
* dest
)
214 if (dest
->dst
.op3
== 0)
216 if ( (dest
->dst
.opcode
== SQ_OP2_INST_DOT4
|| dest
->dst
.opcode
== SQ_OP2_INST_DOT4_IEEE
) )
224 GLuint
GetSurfaceFormat(GLenum eType
, GLuint nChannels
, GLuint
* pClient_size
)
226 GLuint format
= FMT_INVALID
;
227 GLuint uiElemSize
= 0;
232 case GL_UNSIGNED_BYTE
:
237 format
= FMT_8
; break;
239 format
= FMT_8_8
; break;
241 format
= FMT_8_8_8
; break;
243 format
= FMT_8_8_8_8
; break;
249 case GL_UNSIGNED_SHORT
:
255 format
= FMT_16
; break;
257 format
= FMT_16_16
; break;
259 format
= FMT_16_16_16
; break;
261 format
= FMT_16_16_16_16
; break;
267 case GL_UNSIGNED_INT
:
273 format
= FMT_32
; break;
275 format
= FMT_32_32
; break;
277 format
= FMT_32_32_32
; break;
279 format
= FMT_32_32_32_32
; break;
290 format
= FMT_32_FLOAT
; break;
292 format
= FMT_32_32_FLOAT
; break;
294 format
= FMT_32_32_32_FLOAT
; break;
296 format
= FMT_32_32_32_32_FLOAT
; break;
306 format
= FMT_32_FLOAT
; break;
308 format
= FMT_32_32_FLOAT
; break;
310 format
= FMT_32_32_32_FLOAT
; break;
312 format
= FMT_32_32_32_32_FLOAT
; break;
319 //GL_ASSERT_NO_CASE();
322 if(NULL
!= pClient_size
)
324 *pClient_size
= uiElemSize
* nChannels
;
330 unsigned int r700GetNumOperands(r700_AssemblerBase
* pAsm
)
337 switch (pAsm
->D
.dst
.opcode
)
339 case SQ_OP2_INST_ADD
:
340 case SQ_OP2_INST_MUL
:
341 case SQ_OP2_INST_MAX
:
342 case SQ_OP2_INST_MIN
:
343 //case SQ_OP2_INST_MAX_DX10:
344 //case SQ_OP2_INST_MIN_DX10:
345 case SQ_OP2_INST_SETGT
:
346 case SQ_OP2_INST_SETGE
:
347 case SQ_OP2_INST_PRED_SETE
:
348 case SQ_OP2_INST_PRED_SETGT
:
349 case SQ_OP2_INST_PRED_SETGE
:
350 case SQ_OP2_INST_PRED_SETNE
:
351 case SQ_OP2_INST_DOT4
:
352 case SQ_OP2_INST_DOT4_IEEE
:
355 case SQ_OP2_INST_MOV
:
356 case SQ_OP2_INST_FRACT
:
357 case SQ_OP2_INST_FLOOR
:
358 case SQ_OP2_INST_KILLGT
:
359 case SQ_OP2_INST_EXP_IEEE
:
360 case SQ_OP2_INST_LOG_CLAMPED
:
361 case SQ_OP2_INST_LOG_IEEE
:
362 case SQ_OP2_INST_RECIP_IEEE
:
363 case SQ_OP2_INST_RECIPSQRT_IEEE
:
364 case SQ_OP2_INST_FLT_TO_INT
:
365 case SQ_OP2_INST_SIN
:
366 case SQ_OP2_INST_COS
:
369 default: r700_error(TODO_ASM_NEEDIMPINST
,
370 "Need instruction operand number. \n");;
376 int Init_r700_AssemblerBase(SHADER_PIPE_TYPE spt
, r700_AssemblerBase
* pAsm
, R700_Shader
* pShader
)
380 Init_R700_Shader(pShader
);
381 pAsm
->pR700Shader
= pShader
;
382 pAsm
->currentShaderType
= spt
;
384 pAsm
->cf_last_export_ptr
= NULL
;
386 pAsm
->cf_current_export_clause_ptr
= NULL
;
387 pAsm
->cf_current_alu_clause_ptr
= NULL
;
388 pAsm
->cf_current_tex_clause_ptr
= NULL
;
389 pAsm
->cf_current_vtx_clause_ptr
= NULL
;
390 pAsm
->cf_current_cf_clause_ptr
= NULL
;
392 // No clause has been created yet
393 pAsm
->cf_current_clause_type
= CF_EMPTY_CLAUSE
;
395 pAsm
->number_of_colorandz_exports
= 0;
396 pAsm
->number_of_exports
= 0;
397 pAsm
->number_of_export_opcodes
= 0;
405 pAsm
->uLastPosUpdate
= 0;
407 *(BITS
*) &pAsm
->fp_stOutFmt0
= 0;
411 pAsm
->number_used_registers
= 0;
412 pAsm
->uUsedConsts
= 256;
416 pAsm
->uBoolConsts
= 0;
417 pAsm
->uIntConsts
= 0;
422 pAsm
->fc_stack
[0].type
= FC_NONE
;
424 pAsm
->branch_depth
= 0;
425 pAsm
->max_branch_depth
= 0;
430 pAsm
->aArgSubst
[3] = (-1);
434 for (i
=0; i
<NUMBER_OF_OUTPUT_COLORS
; i
++)
436 pAsm
->color_export_register_number
[i
] = (-1);
440 pAsm
->depth_export_register_number
= (-1);
441 pAsm
->stencil_export_register_number
= (-1);
442 pAsm
->coverage_to_mask_export_register_number
= (-1);
443 pAsm
->mask_export_register_number
= (-1);
445 pAsm
->starting_export_register_number
= 0;
446 pAsm
->starting_vfetch_register_number
= 0;
447 pAsm
->starting_temp_register_number
= 0;
448 pAsm
->uFirstHelpReg
= 0;
451 pAsm
->input_position_is_used
= GL_FALSE
;
452 pAsm
->input_normal_is_used
= GL_FALSE
;
455 for (i
=0; i
<NUMBER_OF_INPUT_COLORS
; i
++)
457 pAsm
->input_color_is_used
[ i
] = GL_FALSE
;
460 for (i
=0; i
<NUMBER_OF_TEXTURE_UNITS
; i
++)
462 pAsm
->input_texture_unit_is_used
[ i
] = GL_FALSE
;
465 for (i
=0; i
<VERT_ATTRIB_MAX
; i
++)
467 pAsm
->vfetch_instruction_ptr_array
[ i
] = NULL
;
470 pAsm
->number_of_inputs
= 0;
475 GLboolean
IsTex(gl_inst_opcode Opcode
)
477 if( (OPCODE_TEX
==Opcode
) || (OPCODE_TXP
==Opcode
) || (OPCODE_TXB
==Opcode
) )
484 GLboolean
IsAlu(gl_inst_opcode Opcode
)
486 //TODO : more for fc and ex for higher spec.
494 int check_current_clause(r700_AssemblerBase
* pAsm
,
495 CF_CLAUSE_TYPE new_clause_type
)
497 if (pAsm
->cf_current_clause_type
!= new_clause_type
)
498 { //Close last open clause
499 switch (pAsm
->cf_current_clause_type
)
502 if ( pAsm
->cf_current_alu_clause_ptr
!= NULL
)
504 pAsm
->cf_current_alu_clause_ptr
= NULL
;
508 if ( pAsm
->cf_current_vtx_clause_ptr
!= NULL
)
510 pAsm
->cf_current_vtx_clause_ptr
= NULL
;
514 if ( pAsm
->cf_current_tex_clause_ptr
!= NULL
)
516 pAsm
->cf_current_tex_clause_ptr
= NULL
;
519 case CF_EXPORT_CLAUSE
:
520 if ( pAsm
->cf_current_export_clause_ptr
!= NULL
)
522 pAsm
->cf_current_export_clause_ptr
= NULL
;
525 case CF_OTHER_CLAUSE
:
526 if ( pAsm
->cf_current_cf_clause_ptr
!= NULL
)
528 pAsm
->cf_current_cf_clause_ptr
= NULL
;
531 case CF_EMPTY_CLAUSE
:
534 r700_error(ERROR_ASM_VTX_CLAUSE
,
535 "Unknown CF_CLAUSE_TYPE (%d) in check_current_clause. \n", (int) new_clause_type
);
539 pAsm
->cf_current_clause_type
= CF_EMPTY_CLAUSE
;
542 switch (new_clause_type
)
545 pAsm
->cf_current_clause_type
= CF_ALU_CLAUSE
;
548 pAsm
->cf_current_clause_type
= CF_VTX_CLAUSE
;
551 pAsm
->cf_current_clause_type
= CF_TEX_CLAUSE
;
553 case CF_EXPORT_CLAUSE
:
555 R700ControlFlowSXClause
* pR700ControlFlowSXClause
556 = (R700ControlFlowSXClause
*) CALLOC_STRUCT(R700ControlFlowSXClause
);
558 // Add new export instruction to control flow program
559 if (pR700ControlFlowSXClause
!= 0)
561 pAsm
->cf_current_export_clause_ptr
= pR700ControlFlowSXClause
;
562 Init_R700ControlFlowSXClause(pR700ControlFlowSXClause
);
563 AddCFInstruction( pAsm
->pR700Shader
,
564 (R700ControlFlowInstruction
*)pR700ControlFlowSXClause
);
568 r700_error(ERROR_ASM_ALLOCEXPORTCF
,
569 "Error allocating new EXPORT CF instruction in check_current_clause. \n");
572 pAsm
->cf_current_clause_type
= CF_EXPORT_CLAUSE
;
575 case CF_EMPTY_CLAUSE
:
577 case CF_OTHER_CLAUSE
:
578 pAsm
->cf_current_clause_type
= CF_OTHER_CLAUSE
;
581 r700_error(ERROR_ASM_UNKOWNCLAUSE
,
582 "Unknown CF_CLAUSE_TYPE (%d) in check_current_clause. \n", (int) new_clause_type
);
590 GLboolean
add_vfetch_instruction(r700_AssemblerBase
* pAsm
,
591 R700VertexInstruction
* vertex_instruction_ptr
)
593 if( GL_FALSE
== check_current_clause(pAsm
, CF_VTX_CLAUSE
) )
598 if( pAsm
->cf_current_vtx_clause_ptr
== NULL
||
599 ( (pAsm
->cf_current_vtx_clause_ptr
!= NULL
) &&
600 (pAsm
->cf_current_vtx_clause_ptr
->m_Word1
.f
.count
>= GetCFMaxInstructions(pAsm
->cf_current_vtx_clause_ptr
->m_ShaderInstType
)-1)
603 // Create new Vfetch control flow instruction for this new clause
604 pAsm
->cf_current_vtx_clause_ptr
= (R700ControlFlowGenericClause
*) CALLOC_STRUCT(R700ControlFlowGenericClause
);
606 if (pAsm
->cf_current_vtx_clause_ptr
!= NULL
)
608 Init_R700ControlFlowGenericClause(pAsm
->cf_current_vtx_clause_ptr
);
609 AddCFInstruction( pAsm
->pR700Shader
,
610 (R700ControlFlowInstruction
*)pAsm
->cf_current_vtx_clause_ptr
);
614 r700_error(ERROR_ASM_ALLOCVTXCF
, "Could not allocate a new VFetch CF instruction.");
618 pAsm
->cf_current_vtx_clause_ptr
->m_Word1
.f
.pop_count
= 0x0;
619 pAsm
->cf_current_vtx_clause_ptr
->m_Word1
.f
.cf_const
= 0x0;
620 pAsm
->cf_current_vtx_clause_ptr
->m_Word1
.f
.cond
= SQ_CF_COND_ACTIVE
;
621 pAsm
->cf_current_vtx_clause_ptr
->m_Word1
.f
.count
= 0x0;
622 pAsm
->cf_current_vtx_clause_ptr
->m_Word1
.f
.end_of_program
= 0x0;
623 pAsm
->cf_current_vtx_clause_ptr
->m_Word1
.f
.valid_pixel_mode
= 0x0;
624 pAsm
->cf_current_vtx_clause_ptr
->m_Word1
.f
.cf_inst
= SQ_CF_INST_VTX
;
625 pAsm
->cf_current_vtx_clause_ptr
->m_Word1
.f
.whole_quad_mode
= 0x0;
626 pAsm
->cf_current_vtx_clause_ptr
->m_Word1
.f
.barrier
= 0x1;
628 LinkVertexInstruction(pAsm
->cf_current_vtx_clause_ptr
, vertex_instruction_ptr
);
632 pAsm
->cf_current_vtx_clause_ptr
->m_Word1
.f
.count
++;
635 AddVTXInstruction(pAsm
->pR700Shader
, vertex_instruction_ptr
);
640 GLboolean
add_tex_instruction(r700_AssemblerBase
* pAsm
,
641 R700TextureInstruction
* tex_instruction_ptr
)
643 if ( GL_FALSE
== check_current_clause(pAsm
, CF_TEX_CLAUSE
) )
648 if ( pAsm
->cf_current_tex_clause_ptr
== NULL
||
649 ( (pAsm
->cf_current_tex_clause_ptr
!= NULL
) &&
650 (pAsm
->cf_current_tex_clause_ptr
->m_Word1
.f
.count
>= GetCFMaxInstructions(pAsm
->cf_current_tex_clause_ptr
->m_ShaderInstType
)-1)
653 // new tex cf instruction for this new clause
654 pAsm
->cf_current_tex_clause_ptr
= (R700ControlFlowGenericClause
*) CALLOC_STRUCT(R700ControlFlowGenericClause
);
656 if (pAsm
->cf_current_tex_clause_ptr
!= NULL
)
658 Init_R700ControlFlowGenericClause(pAsm
->cf_current_tex_clause_ptr
);
659 AddCFInstruction( pAsm
->pR700Shader
,
660 (R700ControlFlowInstruction
*)pAsm
->cf_current_tex_clause_ptr
);
664 r700_error(ERROR_ASM_ALLOCTEXCF
, "Could not allocate a new TEX CF instruction.");
668 pAsm
->cf_current_tex_clause_ptr
->m_Word1
.f
.pop_count
= 0x0;
669 pAsm
->cf_current_tex_clause_ptr
->m_Word1
.f
.cf_const
= 0x0;
670 pAsm
->cf_current_tex_clause_ptr
->m_Word1
.f
.cond
= SQ_CF_COND_ACTIVE
;
672 pAsm
->cf_current_tex_clause_ptr
->m_Word1
.f
.end_of_program
= 0x0;
673 pAsm
->cf_current_tex_clause_ptr
->m_Word1
.f
.valid_pixel_mode
= 0x0;
674 pAsm
->cf_current_tex_clause_ptr
->m_Word1
.f
.cf_inst
= SQ_CF_INST_TEX
;
675 pAsm
->cf_current_tex_clause_ptr
->m_Word1
.f
.whole_quad_mode
= 0x0;
676 pAsm
->cf_current_tex_clause_ptr
->m_Word1
.f
.barrier
= 0x0; //0x1;
680 pAsm
->cf_current_tex_clause_ptr
->m_Word1
.f
.count
++;
683 // If this clause constains any TEX instruction that is dependent on a previous instruction,
684 // set the barrier bit
685 if( pAsm
->pInstDeps
[pAsm
->uiCurInst
].nDstDep
> (-1) )
687 pAsm
->cf_current_tex_clause_ptr
->m_Word1
.f
.barrier
= 0x1;
690 if(NULL
== pAsm
->cf_current_tex_clause_ptr
->m_pLinkedTEXInstruction
)
692 pAsm
->cf_current_tex_clause_ptr
->m_pLinkedTEXInstruction
= tex_instruction_ptr
;
693 tex_instruction_ptr
->m_pLinkedGenericClause
= pAsm
->cf_current_tex_clause_ptr
;
696 AddTEXInstruction(pAsm
->pR700Shader
, tex_instruction_ptr
);
701 GLboolean
assemble_vfetch_instruction(r700_AssemblerBase
* pAsm
,
703 GLuint destination_register
,
704 GLuint number_of_elements
,
705 GLenum dataElementType
,
706 VTX_FETCH_METHOD
* pFetchMethod
)
708 GLuint client_size_inbyte
;
710 GLuint mega_fetch_count
;
711 GLuint is_mega_fetch_flag
;
713 R700VertexGenericFetch
* vfetch_instruction_ptr
;
714 R700VertexGenericFetch
* assembled_vfetch_instruction_ptr
= pAsm
->vfetch_instruction_ptr_array
[ gl_client_id
];
716 if (assembled_vfetch_instruction_ptr
== NULL
)
718 vfetch_instruction_ptr
= (R700VertexGenericFetch
*) CALLOC_STRUCT(R700VertexGenericFetch
);
719 if (vfetch_instruction_ptr
== NULL
)
723 Init_R700VertexGenericFetch(vfetch_instruction_ptr
);
727 vfetch_instruction_ptr
= assembled_vfetch_instruction_ptr
;
730 data_format
= GetSurfaceFormat(dataElementType
, number_of_elements
, &client_size_inbyte
);
732 if(GL_TRUE
== pFetchMethod
->bEnableMini
) //More conditions here
738 mega_fetch_count
= MEGA_FETCH_BYTES
- 1;
739 is_mega_fetch_flag
= 0x1;
740 pFetchMethod
->mega_fetch_remainder
= MEGA_FETCH_BYTES
- client_size_inbyte
;
743 vfetch_instruction_ptr
->m_Word0
.f
.vtx_inst
= SQ_VTX_INST_FETCH
;
744 vfetch_instruction_ptr
->m_Word0
.f
.fetch_type
= SQ_VTX_FETCH_VERTEX_DATA
;
745 vfetch_instruction_ptr
->m_Word0
.f
.fetch_whole_quad
= 0x0;
747 vfetch_instruction_ptr
->m_Word0
.f
.buffer_id
= gl_client_id
;
748 vfetch_instruction_ptr
->m_Word0
.f
.src_gpr
= 0x0;
749 vfetch_instruction_ptr
->m_Word0
.f
.src_rel
= SQ_ABSOLUTE
;
750 vfetch_instruction_ptr
->m_Word0
.f
.src_sel_x
= SQ_SEL_X
;
751 vfetch_instruction_ptr
->m_Word0
.f
.mega_fetch_count
= mega_fetch_count
;
753 vfetch_instruction_ptr
->m_Word1
.f
.dst_sel_x
= (number_of_elements
< 1) ? SQ_SEL_0
: SQ_SEL_X
;
754 vfetch_instruction_ptr
->m_Word1
.f
.dst_sel_y
= (number_of_elements
< 2) ? SQ_SEL_0
: SQ_SEL_Y
;
755 vfetch_instruction_ptr
->m_Word1
.f
.dst_sel_z
= (number_of_elements
< 3) ? SQ_SEL_0
: SQ_SEL_Z
;
756 vfetch_instruction_ptr
->m_Word1
.f
.dst_sel_w
= (number_of_elements
< 4) ? SQ_SEL_1
: SQ_SEL_W
;
758 vfetch_instruction_ptr
->m_Word1
.f
.use_const_fields
= 1;
760 // Destination register
761 vfetch_instruction_ptr
->m_Word1_GPR
.f
.dst_gpr
= destination_register
;
762 vfetch_instruction_ptr
->m_Word1_GPR
.f
.dst_rel
= SQ_ABSOLUTE
;
764 vfetch_instruction_ptr
->m_Word2
.f
.offset
= 0;
765 vfetch_instruction_ptr
->m_Word2
.f
.const_buf_no_stride
= 0x0;
767 vfetch_instruction_ptr
->m_Word2
.f
.mega_fetch
= is_mega_fetch_flag
;
769 if (assembled_vfetch_instruction_ptr
== NULL
)
771 if ( GL_FALSE
== add_vfetch_instruction(pAsm
, (R700VertexInstruction
*)vfetch_instruction_ptr
) )
776 if (pAsm
->vfetch_instruction_ptr_array
[ gl_client_id
] != NULL
)
782 pAsm
->vfetch_instruction_ptr_array
[ gl_client_id
] = vfetch_instruction_ptr
;
789 GLuint
gethelpr(r700_AssemblerBase
* pAsm
)
791 GLuint r
= pAsm
->uHelpReg
;
793 if (pAsm
->uHelpReg
> pAsm
->number_used_registers
)
795 pAsm
->number_used_registers
= pAsm
->uHelpReg
;
799 void resethelpr(r700_AssemblerBase
* pAsm
)
801 pAsm
->uHelpReg
= pAsm
->uFirstHelpReg
;
804 void checkop_init(r700_AssemblerBase
* pAsm
)
810 pAsm
->aArgSubst
[3] = -1;
813 GLboolean
mov_temp(r700_AssemblerBase
* pAsm
, int src
)
815 GLuint tmp
= gethelpr(pAsm
);
817 //mov src to temp helper gpr.
818 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_MOV
;
820 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
822 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
823 pAsm
->D
.dst
.reg
= tmp
;
825 nomask_PVSDST(&(pAsm
->D
.dst
));
827 if( GL_FALSE
== assemble_src(pAsm
, src
, 0) )
832 noswizzle_PVSSRC(&(pAsm
->S
[0].src
));
833 noneg_PVSSRC(&(pAsm
->S
[0].src
));
835 if( GL_FALSE
== next_ins(pAsm
) )
840 pAsm
->aArgSubst
[1 + src
] = tmp
;
845 GLboolean
checkop1(r700_AssemblerBase
* pAsm
)
851 GLboolean
checkop2(r700_AssemblerBase
* pAsm
)
853 GLboolean bSrcConst
[2];
854 struct prog_instruction
*pILInst
= &(pAsm
->pILInst
[pAsm
->uiCurInst
]);
858 if( (pILInst
->SrcReg
[0].File
== PROGRAM_CONSTANT
) ||
859 (pILInst
->SrcReg
[0].File
== PROGRAM_LOCAL_PARAM
) ||
860 (pILInst
->SrcReg
[0].File
== PROGRAM_ENV_PARAM
) ||
861 (pILInst
->SrcReg
[0].File
== PROGRAM_STATE_VAR
) )
863 bSrcConst
[0] = GL_TRUE
;
867 bSrcConst
[0] = GL_FALSE
;
869 if( (pILInst
->SrcReg
[1].File
== PROGRAM_CONSTANT
) ||
870 (pILInst
->SrcReg
[1].File
== PROGRAM_LOCAL_PARAM
) ||
871 (pILInst
->SrcReg
[1].File
== PROGRAM_ENV_PARAM
) ||
872 (pILInst
->SrcReg
[1].File
== PROGRAM_STATE_VAR
) )
874 bSrcConst
[1] = GL_TRUE
;
878 bSrcConst
[1] = GL_FALSE
;
881 if( (bSrcConst
[0] == GL_TRUE
) && (bSrcConst
[1] == GL_TRUE
) )
883 if(pILInst
->SrcReg
[0].Index
!= pILInst
->SrcReg
[1].Index
)
885 if( GL_FALSE
== mov_temp(pAsm
, 1) )
895 GLboolean
checkop3(r700_AssemblerBase
* pAsm
)
897 GLboolean bSrcConst
[3];
898 struct prog_instruction
*pILInst
= &(pAsm
->pILInst
[pAsm
->uiCurInst
]);
902 if( (pILInst
->SrcReg
[0].File
== PROGRAM_CONSTANT
) ||
903 (pILInst
->SrcReg
[0].File
== PROGRAM_LOCAL_PARAM
) ||
904 (pILInst
->SrcReg
[0].File
== PROGRAM_ENV_PARAM
) ||
905 (pILInst
->SrcReg
[0].File
== PROGRAM_STATE_VAR
) )
907 bSrcConst
[0] = GL_TRUE
;
911 bSrcConst
[0] = GL_FALSE
;
913 if( (pILInst
->SrcReg
[1].File
== PROGRAM_CONSTANT
) ||
914 (pILInst
->SrcReg
[1].File
== PROGRAM_LOCAL_PARAM
) ||
915 (pILInst
->SrcReg
[1].File
== PROGRAM_ENV_PARAM
) ||
916 (pILInst
->SrcReg
[1].File
== PROGRAM_STATE_VAR
) )
918 bSrcConst
[1] = GL_TRUE
;
922 bSrcConst
[1] = GL_FALSE
;
924 if( (pILInst
->SrcReg
[2].File
== PROGRAM_CONSTANT
) ||
925 (pILInst
->SrcReg
[2].File
== PROGRAM_LOCAL_PARAM
) ||
926 (pILInst
->SrcReg
[2].File
== PROGRAM_ENV_PARAM
) ||
927 (pILInst
->SrcReg
[2].File
== PROGRAM_STATE_VAR
) )
929 bSrcConst
[2] = GL_TRUE
;
933 bSrcConst
[2] = GL_FALSE
;
936 if( (GL_TRUE
== bSrcConst
[0]) &&
937 (GL_TRUE
== bSrcConst
[1]) &&
938 (GL_TRUE
== bSrcConst
[2]) )
940 if( GL_FALSE
== mov_temp(pAsm
, 1) )
944 if( GL_FALSE
== mov_temp(pAsm
, 2) )
951 else if( (GL_TRUE
== bSrcConst
[0]) &&
952 (GL_TRUE
== bSrcConst
[1]) )
954 if(pILInst
->SrcReg
[0].Index
!= pILInst
->SrcReg
[1].Index
)
956 if( GL_FALSE
== mov_temp(pAsm
, 1) )
964 else if ( (GL_TRUE
== bSrcConst
[0]) &&
965 (GL_TRUE
== bSrcConst
[2]) )
967 if(pILInst
->SrcReg
[0].Index
!= pILInst
->SrcReg
[2].Index
)
969 if( GL_FALSE
== mov_temp(pAsm
, 2) )
977 else if( (GL_TRUE
== bSrcConst
[1]) &&
978 (GL_TRUE
== bSrcConst
[2]) )
980 if(pILInst
->SrcReg
[1].Index
!= pILInst
->SrcReg
[2].Index
)
982 if( GL_FALSE
== mov_temp(pAsm
, 2) )
994 GLboolean
assemble_src(r700_AssemblerBase
*pAsm
,
998 struct prog_instruction
*pILInst
= &(pAsm
->pILInst
[pAsm
->uiCurInst
]);
1005 if(pAsm
->aArgSubst
[1+src
] >= 0)
1007 setaddrmode_PVSSRC(&(pAsm
->S
[fld
].src
), ADDR_ABSOLUTE
);
1008 pAsm
->S
[fld
].src
.rtype
= SRC_REG_TEMPORARY
;
1009 pAsm
->S
[fld
].src
.reg
= pAsm
->aArgSubst
[1+src
];
1013 switch (pILInst
->SrcReg
[src
].File
)
1015 case PROGRAM_TEMPORARY
:
1016 setaddrmode_PVSSRC(&(pAsm
->S
[fld
].src
), ADDR_ABSOLUTE
);
1017 pAsm
->S
[fld
].src
.rtype
= SRC_REG_TEMPORARY
;
1018 pAsm
->S
[fld
].src
.reg
= pILInst
->SrcReg
[src
].Index
+ pAsm
->starting_temp_register_number
;
1020 case PROGRAM_CONSTANT
:
1021 case PROGRAM_LOCAL_PARAM
:
1022 case PROGRAM_ENV_PARAM
:
1023 case PROGRAM_STATE_VAR
:
1024 if (1 == pILInst
->SrcReg
[src
].RelAddr
)
1026 setaddrmode_PVSSRC(&(pAsm
->S
[fld
].src
), ADDR_RELATIVE_A0
);
1030 setaddrmode_PVSSRC(&(pAsm
->S
[fld
].src
), ADDR_ABSOLUTE
);
1033 pAsm
->S
[fld
].src
.rtype
= SRC_REG_CONSTANT
;
1034 pAsm
->S
[fld
].src
.reg
= pILInst
->SrcReg
[src
].Index
;
1037 setaddrmode_PVSSRC(&(pAsm
->S
[fld
].src
), ADDR_ABSOLUTE
);
1038 pAsm
->S
[fld
].src
.rtype
= SRC_REG_INPUT
;
1039 switch (pAsm
->currentShaderType
)
1042 pAsm
->S
[fld
].src
.reg
= pAsm
->uiFP_AttributeMap
[pILInst
->SrcReg
[src
].Index
];
1045 pAsm
->S
[fld
].src
.reg
= pAsm
->ucVP_AttributeMap
[pILInst
->SrcReg
[src
].Index
];
1050 r700_error(ERROR_ASM_SRCARGUMENT
, "Invalid source argument type");
1055 pAsm
->S
[fld
].src
.swizzlex
= pILInst
->SrcReg
[src
].Swizzle
& 0x7;
1056 pAsm
->S
[fld
].src
.swizzley
= (pILInst
->SrcReg
[src
].Swizzle
>> 3) & 0x7;
1057 pAsm
->S
[fld
].src
.swizzlez
= (pILInst
->SrcReg
[src
].Swizzle
>> 6) & 0x7;
1058 pAsm
->S
[fld
].src
.swizzlew
= (pILInst
->SrcReg
[src
].Swizzle
>> 9) & 0x7;
1060 pAsm
->S
[fld
].src
.negx
= pILInst
->SrcReg
[src
].Negate
& 0x1;
1061 pAsm
->S
[fld
].src
.negy
= (pILInst
->SrcReg
[src
].Negate
>> 1) & 0x1;
1062 pAsm
->S
[fld
].src
.negz
= (pILInst
->SrcReg
[src
].Negate
>> 2) & 0x1;
1063 pAsm
->S
[fld
].src
.negw
= (pILInst
->SrcReg
[src
].Negate
>> 3) & 0x1;
1068 GLboolean
assemble_dst(r700_AssemblerBase
*pAsm
)
1070 struct prog_instruction
*pILInst
= &(pAsm
->pILInst
[pAsm
->uiCurInst
]);
1071 switch (pILInst
->DstReg
.File
)
1073 case PROGRAM_TEMPORARY
:
1074 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
1075 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
1076 pAsm
->D
.dst
.reg
= pILInst
->DstReg
.Index
+ pAsm
->starting_temp_register_number
;
1078 case PROGRAM_ADDRESS
:
1079 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
1080 pAsm
->D
.dst
.rtype
= DST_REG_A0
;
1081 pAsm
->D
.dst
.reg
= 0;
1083 case PROGRAM_OUTPUT
:
1084 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
1085 pAsm
->D
.dst
.rtype
= DST_REG_OUT
;
1086 switch (pAsm
->currentShaderType
)
1089 pAsm
->D
.dst
.reg
= pAsm
->uiFP_OutputMap
[pILInst
->DstReg
.Index
];
1092 pAsm
->D
.dst
.reg
= pAsm
->ucVP_OutputMap
[pILInst
->DstReg
.Index
];
1097 r700_error(ERROR_ASM_DSTARGUMENT
, "Invalid destination output argument type");
1101 pAsm
->D
.dst
.writex
= pILInst
->DstReg
.WriteMask
& 0x1;
1102 pAsm
->D
.dst
.writey
= (pILInst
->DstReg
.WriteMask
>> 1) & 0x1;
1103 pAsm
->D
.dst
.writez
= (pILInst
->DstReg
.WriteMask
>> 2) & 0x1;
1104 pAsm
->D
.dst
.writew
= (pILInst
->DstReg
.WriteMask
>> 3) & 0x1;
1109 GLboolean
tex_dst(r700_AssemblerBase
*pAsm
)
1111 struct prog_instruction
*pILInst
= &(pAsm
->pILInst
[pAsm
->uiCurInst
]);
1113 if(PROGRAM_TEMPORARY
== pILInst
->DstReg
.File
)
1115 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
1116 pAsm
->D
.dst
.reg
= pAsm
->pILInst
[pAsm
->uiCurInst
].DstReg
.Index
+ pAsm
->starting_temp_register_number
;
1118 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
1120 else if(PROGRAM_OUTPUT
== pILInst
->DstReg
.File
)
1122 pAsm
->D
.dst
.rtype
= DST_REG_OUT
;
1123 switch (pAsm
->currentShaderType
)
1126 pAsm
->D
.dst
.reg
= pAsm
->uiFP_OutputMap
[pILInst
->DstReg
.Index
];
1129 pAsm
->D
.dst
.reg
= pAsm
->ucVP_OutputMap
[pILInst
->DstReg
.Index
];
1133 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
1137 r700_error(ERROR_ASM_DSTARGUMENT
, "Invalid destination output argument type");
1141 pAsm
->D
.dst
.writex
= pILInst
->DstReg
.WriteMask
& 0x1;
1142 pAsm
->D
.dst
.writey
= (pILInst
->DstReg
.WriteMask
>> 1) & 0x1;
1143 pAsm
->D
.dst
.writez
= (pILInst
->DstReg
.WriteMask
>> 2) & 0x1;
1144 pAsm
->D
.dst
.writew
= (pILInst
->DstReg
.WriteMask
>> 3) & 0x1;
1149 GLboolean
tex_src(r700_AssemblerBase
*pAsm
)
1151 struct prog_instruction
*pILInst
= &(pAsm
->pILInst
[pAsm
->uiCurInst
]);
1153 GLboolean bValidTexCoord
= GL_FALSE
;
1155 switch (pILInst
->SrcReg
[0].File
)
1157 case PROGRAM_TEMPORARY
:
1158 bValidTexCoord
= GL_TRUE
;
1160 pAsm
->S
[0].src
.reg
= pILInst
->SrcReg
[0].Index
+ pAsm
->starting_temp_register_number
;
1161 pAsm
->S
[0].src
.rtype
= SRC_REG_TEMPORARY
;
1165 switch (pILInst
->SrcReg
[0].Index
)
1167 case FRAG_ATTRIB_COL0
:
1168 case FRAG_ATTRIB_COL1
:
1169 case FRAG_ATTRIB_TEX0
:
1170 case FRAG_ATTRIB_TEX1
:
1171 case FRAG_ATTRIB_TEX2
:
1172 case FRAG_ATTRIB_TEX3
:
1173 case FRAG_ATTRIB_TEX4
:
1174 case FRAG_ATTRIB_TEX5
:
1175 case FRAG_ATTRIB_TEX6
:
1176 case FRAG_ATTRIB_TEX7
:
1177 bValidTexCoord
= GL_TRUE
;
1179 pAsm
->S
[0].src
.reg
= pAsm
->uiFP_AttributeMap
[pILInst
->SrcReg
[0].Index
];
1180 pAsm
->S
[0].src
.rtype
= SRC_REG_INPUT
;
1185 if(GL_TRUE
== bValidTexCoord
)
1187 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
1191 r700_error(ERROR_ASM_BADTEXSRC
, "Invalid source texcoord for TEX instruction");
1195 pAsm
->S
[0].src
.swizzlex
= pILInst
->SrcReg
[0].Swizzle
& 0x7;
1196 pAsm
->S
[0].src
.swizzley
= (pILInst
->SrcReg
[0].Swizzle
>> 3) & 0x7;
1197 pAsm
->S
[0].src
.swizzlez
= (pILInst
->SrcReg
[0].Swizzle
>> 6) & 0x7;
1198 pAsm
->S
[0].src
.swizzlew
= (pILInst
->SrcReg
[0].Swizzle
>> 9) & 0x7;
1200 pAsm
->S
[0].src
.negx
= pILInst
->SrcReg
[0].Negate
& 0x1;
1201 pAsm
->S
[0].src
.negy
= (pILInst
->SrcReg
[0].Negate
>> 1) & 0x1;
1202 pAsm
->S
[0].src
.negz
= (pILInst
->SrcReg
[0].Negate
>> 2) & 0x1;
1203 pAsm
->S
[0].src
.negw
= (pILInst
->SrcReg
[0].Negate
>> 3) & 0x1;
1208 GLboolean
assemble_tex_instruction(r700_AssemblerBase
*pAsm
)
1210 PVSSRC
* texture_coordinate_source
;
1211 PVSSRC
* texture_unit_source
;
1213 R700TextureInstruction
* tex_instruction_ptr
= (R700TextureInstruction
*) CALLOC_STRUCT(R700TextureInstruction
);
1214 if (tex_instruction_ptr
== NULL
)
1218 Init_R700TextureInstruction(tex_instruction_ptr
);
1220 texture_coordinate_source
= &(pAsm
->S
[0].src
);
1221 texture_unit_source
= &(pAsm
->S
[1].src
);
1223 tex_instruction_ptr
->m_Word0
.f
.tex_inst
= pAsm
->D
.dst
.opcode
;
1224 tex_instruction_ptr
->m_Word0
.f
.bc_frac_mode
= 0x0;
1225 tex_instruction_ptr
->m_Word0
.f
.fetch_whole_quad
= 0x0;
1227 tex_instruction_ptr
->m_Word0
.f
.resource_id
= texture_unit_source
->reg
;
1229 tex_instruction_ptr
->m_Word1
.f
.lod_bias
= 0x0;
1230 tex_instruction_ptr
->m_Word1
.f
.coord_type_x
= SQ_TEX_NORMALIZED
;
1231 tex_instruction_ptr
->m_Word1
.f
.coord_type_y
= SQ_TEX_NORMALIZED
;
1232 tex_instruction_ptr
->m_Word1
.f
.coord_type_z
= SQ_TEX_NORMALIZED
;
1233 tex_instruction_ptr
->m_Word1
.f
.coord_type_w
= SQ_TEX_NORMALIZED
;
1235 tex_instruction_ptr
->m_Word2
.f
.offset_x
= 0x0;
1236 tex_instruction_ptr
->m_Word2
.f
.offset_y
= 0x0;
1237 tex_instruction_ptr
->m_Word2
.f
.offset_z
= 0x0;
1239 tex_instruction_ptr
->m_Word2
.f
.sampler_id
= texture_unit_source
->reg
;
1242 if ( (pAsm
->D
.dst
.rtype
== DST_REG_TEMPORARY
) ||
1243 (pAsm
->D
.dst
.rtype
== DST_REG_OUT
) )
1245 tex_instruction_ptr
->m_Word0
.f
.src_gpr
= texture_coordinate_source
->reg
;
1246 tex_instruction_ptr
->m_Word0
.f
.src_rel
= SQ_ABSOLUTE
;
1248 tex_instruction_ptr
->m_Word1
.f
.dst_gpr
= pAsm
->D
.dst
.reg
;
1249 tex_instruction_ptr
->m_Word1
.f
.dst_rel
= SQ_ABSOLUTE
;
1251 tex_instruction_ptr
->m_Word1
.f
.dst_sel_x
= (pAsm
->D
.dst
.writex
? texture_unit_source
->swizzlex
: SQ_SEL_MASK
);
1252 tex_instruction_ptr
->m_Word1
.f
.dst_sel_y
= (pAsm
->D
.dst
.writey
? texture_unit_source
->swizzley
: SQ_SEL_MASK
);
1253 tex_instruction_ptr
->m_Word1
.f
.dst_sel_z
= (pAsm
->D
.dst
.writez
? texture_unit_source
->swizzlez
: SQ_SEL_MASK
);
1254 tex_instruction_ptr
->m_Word1
.f
.dst_sel_w
= (pAsm
->D
.dst
.writew
? texture_unit_source
->swizzlew
: SQ_SEL_MASK
);
1257 tex_instruction_ptr
->m_Word2
.f
.src_sel_x
= texture_coordinate_source
->swizzlex
;
1258 tex_instruction_ptr
->m_Word2
.f
.src_sel_y
= texture_coordinate_source
->swizzley
;
1259 tex_instruction_ptr
->m_Word2
.f
.src_sel_z
= texture_coordinate_source
->swizzlez
;
1260 tex_instruction_ptr
->m_Word2
.f
.src_sel_w
= texture_coordinate_source
->swizzlew
;
1264 r700_error(ERROR_ASM_TEXDSTBADTYPE
, "Only temp destination registers supported for TEX dest regs.");
1268 if( GL_FALSE
== add_tex_instruction(pAsm
, tex_instruction_ptr
) )
1276 void initialize(r700_AssemblerBase
*pAsm
)
1278 GLuint cycle
, component
;
1280 for (cycle
=0; cycle
<NUMBER_OF_CYCLES
; cycle
++)
1282 for (component
=0; component
<NUMBER_OF_COMPONENTS
; component
++)
1284 pAsm
->hw_gpr
[cycle
][component
] = (-1);
1287 for (component
=0; component
<NUMBER_OF_COMPONENTS
; component
++)
1289 pAsm
->hw_cfile_addr
[component
] = (-1);
1290 pAsm
->hw_cfile_chan
[component
] = (-1);
1294 GLboolean
assemble_alu_src(R700ALUInstruction
* alu_instruction_ptr
,
1297 BITS scalar_channel_index
)
1304 //--------------------------------------------------------------------------
1305 // Source for operands src0, src1.
1306 // Values [0,127] correspond to GPR[0..127].
1307 // Values [256,511] correspond to cfile constants c[0..255].
1309 //--------------------------------------------------------------------------
1310 // Other special values are shown in the list below.
1312 // 248 SQ_ALU_SRC_0: special constant 0.0.
1313 // 249 SQ_ALU_SRC_1: special constant 1.0 float.
1315 // 250 SQ_ALU_SRC_1_INT: special constant 1 integer.
1316 // 251 SQ_ALU_SRC_M_1_INT: special constant -1 integer.
1318 // 252 SQ_ALU_SRC_0_5: special constant 0.5 float.
1319 // 253 SQ_ALU_SRC_LITERAL: literal constant.
1321 // 254 SQ_ALU_SRC_PV: previous vector result.
1322 // 255 SQ_ALU_SRC_PS: previous scalar result.
1323 //--------------------------------------------------------------------------
1325 BITS channel_swizzle
;
1326 switch (scalar_channel_index
)
1328 case 0: channel_swizzle
= pSource
->swizzlex
; break;
1329 case 1: channel_swizzle
= pSource
->swizzley
; break;
1330 case 2: channel_swizzle
= pSource
->swizzlez
; break;
1331 case 3: channel_swizzle
= pSource
->swizzlew
; break;
1332 default: channel_swizzle
= SQ_SEL_MASK
; break;
1335 if(channel_swizzle
== SQ_SEL_0
)
1337 src_sel
= SQ_ALU_SRC_0
;
1339 else if (channel_swizzle
== SQ_SEL_1
)
1341 src_sel
= SQ_ALU_SRC_1
;
1345 if ( (pSource
->rtype
== SRC_REG_TEMPORARY
) ||
1346 (pSource
->rtype
== SRC_REG_INPUT
)
1349 src_sel
= pSource
->reg
;
1351 else if (pSource
->rtype
== SRC_REG_CONSTANT
)
1353 src_sel
= pSource
->reg
+ CFILE_REGISTER_OFFSET
;
1357 r700_error(ERROR_ASM_ALUSRCBADTYPE
, "Source (%d) register type (%d) not one of TEMP, INPUT, or CONSTANT.",
1358 source_index
, pSource
->rtype
);
1363 if( ADDR_ABSOLUTE
== addrmode_PVSSRC(pSource
) )
1365 src_rel
= SQ_ABSOLUTE
;
1369 src_rel
= SQ_RELATIVE
;
1372 switch (channel_swizzle
)
1375 src_chan
= SQ_CHAN_X
;
1378 src_chan
= SQ_CHAN_Y
;
1381 src_chan
= SQ_CHAN_Z
;
1384 src_chan
= SQ_CHAN_W
;
1388 // Does not matter since src_sel controls
1389 src_chan
= SQ_CHAN_X
;
1392 r700_error(ERROR_ASM_ALUSRCSELECT
, "Unknown source select value (%d) in assemble_alu_src().");
1397 switch (scalar_channel_index
)
1399 case 0: src_neg
= pSource
->negx
; break;
1400 case 1: src_neg
= pSource
->negy
; break;
1401 case 2: src_neg
= pSource
->negz
; break;
1402 case 3: src_neg
= pSource
->negw
; break;
1403 default: src_neg
= 0; break;
1406 switch (source_index
)
1409 alu_instruction_ptr
->m_Word0
.f
.src0_sel
= src_sel
;
1410 alu_instruction_ptr
->m_Word0
.f
.src0_rel
= src_rel
;
1411 alu_instruction_ptr
->m_Word0
.f
.src0_chan
= src_chan
;
1412 alu_instruction_ptr
->m_Word0
.f
.src0_neg
= src_neg
;
1415 alu_instruction_ptr
->m_Word0
.f
.src1_sel
= src_sel
;
1416 alu_instruction_ptr
->m_Word0
.f
.src1_rel
= src_rel
;
1417 alu_instruction_ptr
->m_Word0
.f
.src1_chan
= src_chan
;
1418 alu_instruction_ptr
->m_Word0
.f
.src1_neg
= src_neg
;
1421 alu_instruction_ptr
->m_Word1_OP3
.f
.src2_sel
= src_sel
;
1422 alu_instruction_ptr
->m_Word1_OP3
.f
.src2_rel
= src_rel
;
1423 alu_instruction_ptr
->m_Word1_OP3
.f
.src2_chan
= src_chan
;
1424 alu_instruction_ptr
->m_Word1_OP3
.f
.src2_neg
= src_neg
;
1427 r700_error(ERROR_ASM_ALUSRCNUMBER
, "Only three sources allowed in ALU opcodes.");
1435 GLboolean
add_alu_instruction(r700_AssemblerBase
* pAsm
,
1436 R700ALUInstruction
* alu_instruction_ptr
,
1437 GLuint contiguous_slots_needed
)
1439 if( GL_FALSE
== check_current_clause(pAsm
, CF_ALU_CLAUSE
) )
1444 if ( pAsm
->cf_current_alu_clause_ptr
== NULL
||
1445 ( (pAsm
->cf_current_alu_clause_ptr
!= NULL
) &&
1446 (pAsm
->cf_current_alu_clause_ptr
->m_Word1
.f
.count
>= (GetCFMaxInstructions(pAsm
->cf_current_alu_clause_ptr
->m_ShaderInstType
)-contiguous_slots_needed
-1) )
1450 //new cf inst for this clause
1451 pAsm
->cf_current_alu_clause_ptr
= (R700ControlFlowALUClause
*) CALLOC_STRUCT(R700ControlFlowALUClause
);
1453 // link the new cf to cf segment
1454 if(NULL
!= pAsm
->cf_current_alu_clause_ptr
)
1456 Init_R700ControlFlowALUClause(pAsm
->cf_current_alu_clause_ptr
);
1457 AddCFInstruction( pAsm
->pR700Shader
,
1458 (R700ControlFlowInstruction
*)pAsm
->cf_current_alu_clause_ptr
);
1462 r700_error(ERROR_ASM_ALLOCALUCF
, "Could not allocate a new ALU CF instruction.");
1466 pAsm
->cf_current_alu_clause_ptr
->m_Word0
.f
.kcache_bank0
= 0x0;
1467 pAsm
->cf_current_alu_clause_ptr
->m_Word0
.f
.kcache_bank1
= 0x0;
1468 pAsm
->cf_current_alu_clause_ptr
->m_Word0
.f
.kcache_mode0
= SQ_CF_KCACHE_NOP
;
1470 pAsm
->cf_current_alu_clause_ptr
->m_Word1
.f
.kcache_mode1
= SQ_CF_KCACHE_NOP
;
1471 pAsm
->cf_current_alu_clause_ptr
->m_Word1
.f
.kcache_addr0
= 0x0;
1472 pAsm
->cf_current_alu_clause_ptr
->m_Word1
.f
.kcache_addr1
= 0x0;
1474 //cf_current_alu_clause_ptr->m_Word1.f.count = number_of_scalar_operations - 1;
1475 pAsm
->cf_current_alu_clause_ptr
->m_Word1
.f
.count
= 0x0;
1476 pAsm
->cf_current_alu_clause_ptr
->m_Word1
.f
.cf_inst
= SQ_CF_INST_ALU
;
1478 pAsm
->cf_current_alu_clause_ptr
->m_Word1
.f
.whole_quad_mode
= 0x0;
1480 pAsm
->cf_current_alu_clause_ptr
->m_Word1
.f
.barrier
= 0x1;
1484 pAsm
->cf_current_alu_clause_ptr
->m_Word1
.f
.count
++;
1487 // If this clause constains any instruction that is forward dependent on a TEX instruction,
1488 // set the whole_quad_mode for this clause
1489 if ( pAsm
->pInstDeps
[pAsm
->uiCurInst
].nDstDep
> (-1) )
1491 pAsm
->cf_current_alu_clause_ptr
->m_Word1
.f
.whole_quad_mode
= 0x1;
1494 if (pAsm
->cf_current_alu_clause_ptr
->m_Word1
.f
.count
>= (GetCFMaxInstructions(pAsm
->cf_current_alu_clause_ptr
->m_ShaderInstType
)-1) )
1496 alu_instruction_ptr
->m_Word0
.f
.last
= 1;
1499 if(NULL
== pAsm
->cf_current_alu_clause_ptr
->m_pLinkedALUInstruction
)
1501 pAsm
->cf_current_alu_clause_ptr
->m_pLinkedALUInstruction
= alu_instruction_ptr
;
1502 alu_instruction_ptr
->m_pLinkedALUClause
= pAsm
->cf_current_alu_clause_ptr
;
1505 AddALUInstruction(pAsm
->pR700Shader
, alu_instruction_ptr
);
1510 void get_src_properties(R700ALUInstruction
* alu_instruction_ptr
,
1517 switch (source_index
)
1520 *psrc_sel
= alu_instruction_ptr
->m_Word0
.f
.src0_sel
;
1521 *psrc_rel
= alu_instruction_ptr
->m_Word0
.f
.src0_rel
;
1522 *psrc_chan
= alu_instruction_ptr
->m_Word0
.f
.src0_chan
;
1523 *psrc_neg
= alu_instruction_ptr
->m_Word0
.f
.src0_neg
;
1527 *psrc_sel
= alu_instruction_ptr
->m_Word0
.f
.src1_sel
;
1528 *psrc_rel
= alu_instruction_ptr
->m_Word0
.f
.src1_rel
;
1529 *psrc_chan
= alu_instruction_ptr
->m_Word0
.f
.src1_chan
;
1530 *psrc_neg
= alu_instruction_ptr
->m_Word0
.f
.src1_neg
;
1534 *psrc_sel
= alu_instruction_ptr
->m_Word1_OP3
.f
.src2_sel
;
1535 *psrc_rel
= alu_instruction_ptr
->m_Word1_OP3
.f
.src2_rel
;
1536 *psrc_chan
= alu_instruction_ptr
->m_Word1_OP3
.f
.src2_chan
;
1537 *psrc_neg
= alu_instruction_ptr
->m_Word1_OP3
.f
.src2_neg
;
1542 int is_cfile(BITS sel
)
1544 if (sel
> 255 && sel
< 512)
1551 int is_const(BITS sel
)
1557 else if(sel
>= SQ_ALU_SRC_0
&& sel
<= SQ_ALU_SRC_LITERAL
)
1564 int is_gpr(BITS sel
)
1566 if (sel
>= 0 && sel
< 128)
1573 const GLuint BANK_SWIZZLE_VEC
[8] = {SQ_ALU_VEC_210
, //000
1574 SQ_ALU_VEC_120
, //001
1575 SQ_ALU_VEC_102
, //010
1577 SQ_ALU_VEC_201
, //011
1578 SQ_ALU_VEC_012
, //100
1579 SQ_ALU_VEC_021
, //101
1581 SQ_ALU_VEC_012
, //110
1582 SQ_ALU_VEC_012
}; //111
1584 const GLuint BANK_SWIZZLE_SCL
[8] = {SQ_ALU_SCL_210
, //000
1585 SQ_ALU_SCL_122
, //001
1586 SQ_ALU_SCL_122
, //010
1588 SQ_ALU_SCL_221
, //011
1589 SQ_ALU_SCL_212
, //100
1590 SQ_ALU_SCL_122
, //101
1592 SQ_ALU_SCL_122
, //110
1593 SQ_ALU_SCL_122
}; //111
1595 GLboolean
reserve_cfile(r700_AssemblerBase
* pAsm
,
1599 int res_match
= (-1);
1600 int res_empty
= (-1);
1604 for (res
=3; res
>=0; res
--)
1606 if(pAsm
->hw_cfile_addr
[ res
] < 0)
1610 else if( (pAsm
->hw_cfile_addr
[res
] == (int)sel
)
1612 (pAsm
->hw_cfile_chan
[ res
] == (int) chan
) )
1620 // Read for this scalar component already reserved, nothing to do here.
1623 else if(res_empty
>= 0)
1625 pAsm
->hw_cfile_addr
[ res_empty
] = sel
;
1626 pAsm
->hw_cfile_chan
[ res_empty
] = chan
;
1630 r700_error(ERROR_ASM_CONSTCHANNEL
, "All cfile read ports are used, cannot reference C$sel, channel $chan.");
1636 GLboolean
reserve_gpr(r700_AssemblerBase
* pAsm
, GLuint sel
, GLuint chan
, GLuint cycle
)
1638 if(pAsm
->hw_gpr
[cycle
][chan
] < 0)
1640 pAsm
->hw_gpr
[cycle
][chan
] = sel
;
1642 else if(pAsm
->hw_gpr
[cycle
][chan
] != (int)sel
)
1644 r700_error(ERROR_ASM_BADGPRRESERVE
, "Another scalar operation has already used GPR read port for given channel");
1651 GLboolean
cycle_for_scalar_bank_swizzle(const int swiz
, const int sel
, GLuint
* pCycle
)
1655 case SQ_ALU_SCL_210
:
1657 int table
[3] = {2, 1, 0};
1658 *pCycle
= table
[sel
];
1662 case SQ_ALU_SCL_122
:
1664 int table
[3] = {1, 2, 2};
1665 *pCycle
= table
[sel
];
1669 case SQ_ALU_SCL_212
:
1671 int table
[3] = {2, 1, 2};
1672 *pCycle
= table
[sel
];
1676 case SQ_ALU_SCL_221
:
1678 int table
[3] = {2, 2, 1};
1679 *pCycle
= table
[sel
];
1684 r700_error(ERROR_ASM_BADSCALARBZ
, "Bad Scalar bank swizzle value");
1691 GLboolean
cycle_for_vector_bank_swizzle(const int swiz
, const int sel
, GLuint
* pCycle
)
1695 case SQ_ALU_VEC_012
:
1697 int table
[3] = {0, 1, 2};
1698 *pCycle
= table
[sel
];
1701 case SQ_ALU_VEC_021
:
1703 int table
[3] = {0, 2, 1};
1704 *pCycle
= table
[sel
];
1707 case SQ_ALU_VEC_120
:
1709 int table
[3] = {1, 2, 0};
1710 *pCycle
= table
[sel
];
1713 case SQ_ALU_VEC_102
:
1715 int table
[3] = {1, 0, 2};
1716 *pCycle
= table
[sel
];
1719 case SQ_ALU_VEC_201
:
1721 int table
[3] = {2, 0, 1};
1722 *pCycle
= table
[sel
];
1725 case SQ_ALU_VEC_210
:
1727 int table
[3] = {2, 1, 0};
1728 *pCycle
= table
[sel
];
1732 r700_error(ERROR_ASM_BADVECTORBZ
, "Bad Vec bank swizzle value");
1740 GLboolean
check_scalar(r700_AssemblerBase
* pAsm
,
1741 R700ALUInstruction
* alu_instruction_ptr
)
1744 GLuint bank_swizzle
;
1745 GLuint const_count
= 0;
1754 BITS src_sel
[3] = {0,0,0};
1755 BITS src_chan
[3] = {0,0,0};
1756 BITS src_rel
[3] = {0,0,0};
1757 BITS src_neg
[3] = {0,0,0};
1761 GLuint number_of_operands
= r700GetNumOperands(pAsm
);
1763 for (src
=0; src
<number_of_operands
; src
++)
1765 get_src_properties(alu_instruction_ptr
,
1774 swizzle_key
= ( (is_const( src_sel
[0] ) ? 4 : 0) +
1775 (is_const( src_sel
[1] ) ? 2 : 0) +
1776 (is_const( src_sel
[2] ) ? 1 : 0) );
1778 alu_instruction_ptr
->m_Word1
.f
.bank_swizzle
= BANK_SWIZZLE_SCL
[ swizzle_key
];
1780 for (src
=0; src
<number_of_operands
; src
++)
1782 sel
= src_sel
[src
];
1783 chan
= src_chan
[src
];
1784 rel
= src_rel
[src
];
1785 neg
= src_neg
[src
];
1787 if (is_const( sel
))
1789 // Any constant, including literal and inline constants
1792 if (is_cfile( sel
))
1794 reserve_cfile(pAsm
, sel
, chan
);
1800 for (src
=0; src
<number_of_operands
; src
++)
1802 sel
= src_sel
[src
];
1803 chan
= src_chan
[src
];
1804 rel
= src_rel
[src
];
1805 neg
= src_neg
[src
];
1809 bank_swizzle
= alu_instruction_ptr
->m_Word1
.f
.bank_swizzle
;
1811 if( GL_FALSE
== cycle_for_scalar_bank_swizzle(bank_swizzle
, src
, &cycle
) )
1816 if(cycle
< const_count
)
1818 if( GL_FALSE
== reserve_gpr(pAsm
, sel
, chan
, cycle
) )
1829 GLboolean
check_vector(r700_AssemblerBase
* pAsm
,
1830 R700ALUInstruction
* alu_instruction_ptr
)
1833 GLuint bank_swizzle
;
1834 GLuint const_count
= 0;
1843 BITS src_sel
[3] = {0,0,0};
1844 BITS src_chan
[3] = {0,0,0};
1845 BITS src_rel
[3] = {0,0,0};
1846 BITS src_neg
[3] = {0,0,0};
1850 GLuint number_of_operands
= r700GetNumOperands(pAsm
);
1852 for (src
=0; src
<number_of_operands
; src
++)
1854 get_src_properties(alu_instruction_ptr
,
1863 swizzle_key
= ( (is_const( src_sel
[0] ) ? 4 : 0) +
1864 (is_const( src_sel
[1] ) ? 2 : 0) +
1865 (is_const( src_sel
[2] ) ? 1 : 0)
1868 alu_instruction_ptr
->m_Word1
.f
.bank_swizzle
= BANK_SWIZZLE_VEC
[swizzle_key
];
1870 for (src
=0; src
<number_of_operands
; src
++)
1872 sel
= src_sel
[src
];
1873 chan
= src_chan
[src
];
1874 rel
= src_rel
[src
];
1875 neg
= src_neg
[src
];
1878 bank_swizzle
= alu_instruction_ptr
->m_Word1
.f
.bank_swizzle
;
1882 if( GL_FALSE
== cycle_for_vector_bank_swizzle(bank_swizzle
, src
, &cycle
) )
1888 (sel
== src_sel
[0]) &&
1889 (chan
== src_chan
[0]) )
1894 if( GL_FALSE
== reserve_gpr(pAsm
, sel
, chan
, cycle
) )
1900 else if( is_const(sel
) )
1906 if( GL_FALSE
== reserve_cfile(pAsm
, sel
, chan
) )
1917 GLboolean
assemble_alu_instruction(r700_AssemblerBase
*pAsm
)
1919 GLuint number_of_scalar_operations
;
1920 GLboolean is_single_scalar_operation
;
1921 GLuint scalar_channel_index
;
1923 PVSSRC
* pcurrent_source
;
1924 int current_source_index
;
1925 GLuint contiguous_slots_needed
;
1927 GLuint uNumSrc
= r700GetNumOperands(pAsm
);
1928 GLuint channel_swizzle
, j
;
1929 GLuint chan_counter
[4] = {0, 0, 0, 0};
1930 PVSSRC
* pSource
[3];
1931 GLboolean bSplitInst
= GL_FALSE
;
1933 if (1 == pAsm
->D
.dst
.math
)
1935 is_single_scalar_operation
= GL_TRUE
;
1936 number_of_scalar_operations
= 1;
1940 is_single_scalar_operation
= GL_FALSE
;
1941 number_of_scalar_operations
= 4;
1943 /* check read port, only very preliminary algorithm, not count in
1944 src0/1 same comp case and prev slot repeat case; also not count relative
1945 addressing. TODO: improve performance. */
1946 for(j
=0; j
<uNumSrc
; j
++)
1948 pSource
[j
] = &(pAsm
->S
[j
].src
);
1950 for(scalar_channel_index
=0; scalar_channel_index
<4; scalar_channel_index
++)
1952 for(j
=0; j
<uNumSrc
; j
++)
1954 switch (scalar_channel_index
)
1956 case 0: channel_swizzle
= pSource
[j
]->swizzlex
; break;
1957 case 1: channel_swizzle
= pSource
[j
]->swizzley
; break;
1958 case 2: channel_swizzle
= pSource
[j
]->swizzlez
; break;
1959 case 3: channel_swizzle
= pSource
[j
]->swizzlew
; break;
1960 default: channel_swizzle
= SQ_SEL_MASK
; break;
1962 if ( ((pSource
[j
]->rtype
== SRC_REG_TEMPORARY
) ||
1963 (pSource
[j
]->rtype
== SRC_REG_INPUT
))
1964 && (channel_swizzle
<= SQ_SEL_W
) )
1966 chan_counter
[channel_swizzle
]++;
1970 if( (chan_counter
[SQ_SEL_X
] > 3)
1971 || (chan_counter
[SQ_SEL_Y
] > 3)
1972 || (chan_counter
[SQ_SEL_Z
] > 3)
1973 || (chan_counter
[SQ_SEL_W
] > 3) ) /* each chan bank has only 3 ports. */
1975 bSplitInst
= GL_TRUE
;
1979 contiguous_slots_needed
= 0;
1981 if(GL_TRUE
== is_reduction_opcode(&(pAsm
->D
)) )
1983 contiguous_slots_needed
= 4;
1988 for (scalar_channel_index
=0;
1989 scalar_channel_index
< number_of_scalar_operations
;
1990 scalar_channel_index
++)
1992 R700ALUInstruction
* alu_instruction_ptr
= (R700ALUInstruction
*) CALLOC_STRUCT(R700ALUInstruction
);
1993 if (alu_instruction_ptr
== NULL
)
1997 Init_R700ALUInstruction(alu_instruction_ptr
);
2000 current_source_index
= 0;
2001 pcurrent_source
= &(pAsm
->S
[0].src
);
2003 if (GL_FALSE
== assemble_alu_src(alu_instruction_ptr
,
2004 current_source_index
,
2006 scalar_channel_index
) )
2011 if (pAsm
->D
.dst
.math
== 0)
2014 current_source_index
= 1;
2015 pcurrent_source
= &(pAsm
->S
[current_source_index
].src
);
2017 if (GL_FALSE
== assemble_alu_src(alu_instruction_ptr
,
2018 current_source_index
,
2020 scalar_channel_index
) )
2027 alu_instruction_ptr
->m_Word0
.f
.index_mode
= SQ_INDEX_LOOP
;
2029 if( (is_single_scalar_operation
== GL_TRUE
)
2030 || (GL_TRUE
== bSplitInst
) )
2032 alu_instruction_ptr
->m_Word0
.f
.last
= 1;
2036 alu_instruction_ptr
->m_Word0
.f
.last
= (scalar_channel_index
== 3) ? 1 : 0;
2039 alu_instruction_ptr
->m_Word0
.f
.pred_sel
= 0x0;
2040 alu_instruction_ptr
->m_Word1_OP2
.f
.update_pred
= 0x0;
2041 alu_instruction_ptr
->m_Word1_OP2
.f
.update_execute_mask
= 0x0;
2044 if( (pAsm
->D
.dst
.rtype
== DST_REG_TEMPORARY
) ||
2045 (pAsm
->D
.dst
.rtype
== DST_REG_OUT
) )
2047 alu_instruction_ptr
->m_Word1
.f
.dst_gpr
= pAsm
->D
.dst
.reg
;
2051 r700_error(ERROR_ASM_ALUDSTBADTYPE
, "Only temp destination registers supported for ALU dest regs.");
2055 alu_instruction_ptr
->m_Word1
.f
.dst_rel
= SQ_ABSOLUTE
; //D.rtype
2057 if ( is_single_scalar_operation
== GL_TRUE
)
2059 // Override scalar_channel_index since only one scalar value will be written
2060 if(pAsm
->D
.dst
.writex
)
2062 scalar_channel_index
= 0;
2064 else if(pAsm
->D
.dst
.writey
)
2066 scalar_channel_index
= 1;
2068 else if(pAsm
->D
.dst
.writez
)
2070 scalar_channel_index
= 2;
2072 else if(pAsm
->D
.dst
.writew
)
2074 scalar_channel_index
= 3;
2078 alu_instruction_ptr
->m_Word1
.f
.dst_chan
= scalar_channel_index
;
2080 alu_instruction_ptr
->m_Word1
.f
.clamp
= pAsm
->pILInst
[pAsm
->uiCurInst
].SaturateMode
;
2082 if (pAsm
->D
.dst
.op3
)
2086 alu_instruction_ptr
->m_Word1_OP3
.f
.alu_inst
= pAsm
->D
.dst
.opcode
;
2088 //There's 3rd src for op3
2089 current_source_index
= 2;
2090 pcurrent_source
= &(pAsm
->S
[current_source_index
].src
);
2092 if ( GL_FALSE
== assemble_alu_src(alu_instruction_ptr
,
2093 current_source_index
,
2095 scalar_channel_index
) )
2105 alu_instruction_ptr
->m_Word1_OP2
.f6
.alu_inst
= pAsm
->D
.dst
.opcode
;
2107 alu_instruction_ptr
->m_Word1_OP2
.f6
.src0_abs
= 0x0;
2108 alu_instruction_ptr
->m_Word1_OP2
.f6
.src1_abs
= 0x0;
2110 //alu_instruction_ptr->m_Word1_OP2.f6.update_execute_mask = 0x0;
2111 //alu_instruction_ptr->m_Word1_OP2.f6.update_pred = 0x0;
2112 switch (scalar_channel_index
)
2115 alu_instruction_ptr
->m_Word1_OP2
.f6
.write_mask
= pAsm
->D
.dst
.writex
;
2118 alu_instruction_ptr
->m_Word1_OP2
.f6
.write_mask
= pAsm
->D
.dst
.writey
;
2121 alu_instruction_ptr
->m_Word1_OP2
.f6
.write_mask
= pAsm
->D
.dst
.writez
;
2124 alu_instruction_ptr
->m_Word1_OP2
.f6
.write_mask
= pAsm
->D
.dst
.writew
;
2127 alu_instruction_ptr
->m_Word1_OP2
.f6
.write_mask
= SQ_SEL_MASK
;
2130 alu_instruction_ptr
->m_Word1_OP2
.f6
.omod
= SQ_ALU_OMOD_OFF
;
2134 alu_instruction_ptr
->m_Word1_OP2
.f
.alu_inst
= pAsm
->D
.dst
.opcode
;
2136 alu_instruction_ptr
->m_Word1_OP2
.f
.src0_abs
= 0x0;
2137 alu_instruction_ptr
->m_Word1_OP2
.f
.src1_abs
= 0x0;
2139 //alu_instruction_ptr->m_Word1_OP2.f.update_execute_mask = 0x0;
2140 //alu_instruction_ptr->m_Word1_OP2.f.update_pred = 0x0;
2141 switch (scalar_channel_index
)
2144 alu_instruction_ptr
->m_Word1_OP2
.f
.write_mask
= pAsm
->D
.dst
.writex
;
2147 alu_instruction_ptr
->m_Word1_OP2
.f
.write_mask
= pAsm
->D
.dst
.writey
;
2150 alu_instruction_ptr
->m_Word1_OP2
.f
.write_mask
= pAsm
->D
.dst
.writez
;
2153 alu_instruction_ptr
->m_Word1_OP2
.f
.write_mask
= pAsm
->D
.dst
.writew
;
2156 alu_instruction_ptr
->m_Word1_OP2
.f
.write_mask
= SQ_SEL_MASK
;
2159 alu_instruction_ptr
->m_Word1_OP2
.f
.omod
= SQ_ALU_OMOD_OFF
;
2163 if(GL_FALSE
== add_alu_instruction(pAsm
, alu_instruction_ptr
, contiguous_slots_needed
) )
2169 * Judge the type of current instruction, is it vector or scalar
2172 if (is_single_scalar_operation
)
2174 if(GL_FALSE
== check_scalar(pAsm
, alu_instruction_ptr
) )
2181 if(GL_FALSE
== check_vector(pAsm
, alu_instruction_ptr
) )
2187 contiguous_slots_needed
= 0;
2193 GLboolean
next_ins(r700_AssemblerBase
*pAsm
)
2195 struct prog_instruction
*pILInst
= &(pAsm
->pILInst
[pAsm
->uiCurInst
]);
2197 if( GL_TRUE
== IsTex(pILInst
->Opcode
) )
2199 if( GL_FALSE
== assemble_tex_instruction(pAsm
) )
2201 r700_error(ERROR_ASM_TEXINSTRUCTION
, "Error assembling TEX instruction");
2207 if( GL_FALSE
== assemble_alu_instruction(pAsm
) )
2209 r700_error(ERROR_ASM_TEXINSTRUCTION
, "Error assembling ALU instruction");
2214 if(pAsm
->D
.dst
.rtype
== DST_REG_OUT
)
2218 // There is no mask for OP3 instructions, so all channels are written
2219 pAsm
->pucOutMask
[pAsm
->D
.dst
.reg
- pAsm
->starting_export_register_number
] = 0xF;
2223 pAsm
->pucOutMask
[pAsm
->D
.dst
.reg
- pAsm
->starting_export_register_number
]
2224 |= (unsigned char)pAsm
->pILInst
[pAsm
->uiCurInst
].DstReg
.WriteMask
;
2228 //reset for next inst.
2230 pAsm
->S
[0].bits
= 0;
2231 pAsm
->S
[1].bits
= 0;
2232 pAsm
->S
[2].bits
= 0;
2237 GLboolean
assemble_math_function(r700_AssemblerBase
* pAsm
, BITS opcode
)
2243 tmp
= gethelpr(pAsm
);
2245 // opcode tmp.x, a.x
2248 pAsm
->D
.dst
.opcode
= opcode
;
2249 pAsm
->D
.dst
.math
= 1;
2251 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
2252 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
2253 pAsm
->D
.dst
.reg
= tmp
;
2254 pAsm
->D
.dst
.writex
= 1;
2256 if( GL_FALSE
== assemble_src(pAsm
, 0, -1) )
2261 if ( GL_FALSE
== next_ins(pAsm
) )
2266 // Now replicate result to all necessary channels in destination
2267 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_MOV
;
2269 if( GL_FALSE
== assemble_dst(pAsm
) )
2274 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
2275 pAsm
->S
[0].src
.rtype
= DST_REG_TEMPORARY
;
2276 pAsm
->S
[0].src
.reg
= tmp
;
2278 setswizzle_PVSSRC(&(pAsm
->S
[0].src
), SQ_SEL_X
);
2279 noneg_PVSSRC(&(pAsm
->S
[0].src
));
2281 if( GL_FALSE
== next_ins(pAsm
) )
2289 GLboolean
assemble_ABS(r700_AssemblerBase
*pAsm
)
2293 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_MAX
;
2295 if( GL_FALSE
== assemble_dst(pAsm
) )
2299 if( GL_FALSE
== assemble_src(pAsm
, 0, -1) )
2304 pAsm
->S
[1].bits
= pAsm
->S
[0].bits
;
2305 flipneg_PVSSRC(&(pAsm
->S
[1].src
));
2307 if ( GL_FALSE
== next_ins(pAsm
) )
2315 GLboolean
assemble_ADD(r700_AssemblerBase
*pAsm
)
2317 if( GL_FALSE
== checkop2(pAsm
) )
2322 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_ADD
;
2324 if( GL_FALSE
== assemble_dst(pAsm
) )
2329 if( GL_FALSE
== assemble_src(pAsm
, 0, -1) )
2334 if( GL_FALSE
== assemble_src(pAsm
, 1, -1) )
2339 if(pAsm
->pILInst
[pAsm
->uiCurInst
].Opcode
== OPCODE_SUB
)
2341 flipneg_PVSSRC(&(pAsm
->S
[1].src
));
2344 if( GL_FALSE
== next_ins(pAsm
) )
2352 GLboolean
assemble_BAD(char *opcode_str
)
2354 r700_error(TODO_ASM_NEEDIMPINST
, "Not yet implemented instruction (%s)", opcode_str
);
2358 GLboolean
assemble_CMP(r700_AssemblerBase
*pAsm
)
2362 if( GL_FALSE
== checkop3(pAsm
) )
2367 pAsm
->D
.dst
.opcode
= SQ_OP3_INST_CNDGE
;
2368 pAsm
->D
.dst
.op3
= 1;
2372 if(0xF != pAsm
->pILInst
[pAsm
->uiCurInst
].DstReg
.WriteMask
)
2374 //OP3 has no support for write mask
2375 tmp
= gethelpr(pAsm
);
2377 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
2378 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
2379 pAsm
->D
.dst
.reg
= tmp
;
2381 nomask_PVSDST(&(pAsm
->D
.dst
));
2385 if( GL_FALSE
== assemble_dst(pAsm
) )
2391 if( GL_FALSE
== assemble_src(pAsm
, 0, -1) )
2396 if( GL_FALSE
== assemble_src(pAsm
, 2, 1) )
2401 if( GL_FALSE
== assemble_src(pAsm
, 1, 2) )
2406 if ( GL_FALSE
== next_ins(pAsm
) )
2411 if (0xF != pAsm
->pILInst
[pAsm
->uiCurInst
].DstReg
.WriteMask
)
2413 if( GL_FALSE
== assemble_dst(pAsm
) )
2418 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_MOV
;
2421 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
2422 pAsm
->S
[0].src
.rtype
= SRC_REG_TEMPORARY
;
2423 pAsm
->S
[0].src
.reg
= tmp
;
2425 noneg_PVSSRC(&(pAsm
->S
[0].src
));
2426 noswizzle_PVSSRC(&(pAsm
->S
[0].src
));
2428 if( GL_FALSE
== next_ins(pAsm
) )
2437 GLboolean
assemble_COS(r700_AssemblerBase
*pAsm
)
2439 return assemble_math_function(pAsm
, SQ_OP2_INST_COS
);
2442 GLboolean
assemble_DOT(r700_AssemblerBase
*pAsm
)
2444 if( GL_FALSE
== checkop2(pAsm
) )
2449 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_DOT4
;
2451 if( GL_FALSE
== assemble_dst(pAsm
) )
2456 if( GL_FALSE
== assemble_src(pAsm
, 0, -1) )
2461 if( GL_FALSE
== assemble_src(pAsm
, 1, -1) )
2466 if(OPCODE_DP3
== pAsm
->pILInst
[pAsm
->uiCurInst
].Opcode
)
2468 zerocomp_PVSSRC(&(pAsm
->S
[0].src
), 3);
2469 zerocomp_PVSSRC(&(pAsm
->S
[1].src
), 3);
2471 else if(pAsm
->pILInst
[pAsm
->uiCurInst
].Opcode
== OPCODE_DPH
)
2473 onecomp_PVSSRC(&(pAsm
->S
[1].src
), 3);
2476 if ( GL_FALSE
== next_ins(pAsm
) )
2484 GLboolean
assemble_DST(r700_AssemblerBase
*pAsm
)
2486 if( GL_FALSE
== checkop2(pAsm
) )
2491 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_MUL
;
2493 if( GL_FALSE
== assemble_dst(pAsm
) )
2498 if( GL_FALSE
== assemble_src(pAsm
, 0, -1) )
2503 if( GL_FALSE
== assemble_src(pAsm
, 1, -1) )
2508 onecomp_PVSSRC(&(pAsm
->S
[0].src
), 0);
2509 onecomp_PVSSRC(&(pAsm
->S
[0].src
), 3);
2511 onecomp_PVSSRC(&(pAsm
->S
[1].src
), 0);
2512 onecomp_PVSSRC(&(pAsm
->S
[1].src
), 2);
2514 if ( GL_FALSE
== next_ins(pAsm
) )
2522 GLboolean
assemble_EX2(r700_AssemblerBase
*pAsm
)
2524 return assemble_math_function(pAsm
, SQ_OP2_INST_EXP_IEEE
);
2527 GLboolean
assemble_FLR(r700_AssemblerBase
*pAsm
)
2531 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_FLOOR
;
2533 if ( GL_FALSE
== assemble_dst(pAsm
) )
2538 if ( GL_FALSE
== assemble_src(pAsm
, 0, -1) )
2543 if ( GL_FALSE
== next_ins(pAsm
) )
2551 GLboolean
assemble_FLR_INT(r700_AssemblerBase
*pAsm
)
2553 return assemble_math_function(pAsm
, SQ_OP2_INST_FLT_TO_INT
);
2556 GLboolean
assemble_FRC(r700_AssemblerBase
*pAsm
)
2560 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_FRACT
;
2562 if ( GL_FALSE
== assemble_dst(pAsm
) )
2567 if ( GL_FALSE
== assemble_src(pAsm
, 0, -1) )
2572 if ( GL_FALSE
== next_ins(pAsm
) )
2580 GLboolean
assemble_KIL(r700_AssemblerBase
*pAsm
)
2584 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_KILLGT
;
2586 if ( GL_FALSE
== assemble_dst(pAsm
) )
2591 pAsm
->D
.dst
.writex
= 0;
2592 pAsm
->D
.dst
.writey
= 0;
2593 pAsm
->D
.dst
.writez
= 0;
2594 pAsm
->D
.dst
.writew
= 0;
2596 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
2597 pAsm
->S
[0].src
.rtype
= SRC_REG_TEMPORARY
;
2598 pAsm
->S
[0].src
.reg
= 0;
2600 setswizzle_PVSSRC(&(pAsm
->S
[0].src
), SQ_SEL_0
);
2601 noneg_PVSSRC(&(pAsm
->S
[0].src
));
2603 pAsm
->S
[1].src
.rtype
= SRC_REG_TEMPORARY
;
2605 if(PROGRAM_TEMPORARY
== pAsm
->pILInst
[pAsm
->uiCurInst
].DstReg
.File
)
2607 pAsm
->S
[1].src
.reg
= pAsm
->pILInst
[pAsm
->uiCurInst
].DstReg
.Index
+ pAsm
->starting_temp_register_number
;
2611 pAsm
->S
[1].src
.reg
= pAsm
->uiFP_OutputMap
[pAsm
->pILInst
[pAsm
->uiCurInst
].DstReg
.Index
];
2614 setaddrmode_PVSSRC(&(pAsm
->S
[1].src
), ADDR_ABSOLUTE
);
2615 noswizzle_PVSSRC(&(pAsm
->S
[1].src
));
2617 if ( GL_FALSE
== next_ins(pAsm
) )
2622 pAsm
->pR700Shader
->killIsUsed
= GL_TRUE
;
2627 GLboolean
assemble_LG2(r700_AssemblerBase
*pAsm
)
2629 return assemble_math_function(pAsm
, SQ_OP2_INST_LOG_IEEE
);
2632 GLboolean
assemble_LRP(r700_AssemblerBase
*pAsm
)
2636 if( GL_FALSE
== checkop3(pAsm
) )
2641 tmp
= gethelpr(pAsm
);
2643 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_ADD
;
2645 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
2646 pAsm
->D
.dst
.reg
= tmp
;
2647 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
2648 nomask_PVSDST(&(pAsm
->D
.dst
));
2651 if( GL_FALSE
== assemble_src(pAsm
, 1, 0) )
2656 if ( GL_FALSE
== assemble_src(pAsm
, 2, 1) )
2661 neg_PVSSRC(&(pAsm
->S
[1].src
));
2663 if( GL_FALSE
== next_ins(pAsm
) )
2668 pAsm
->D
.dst
.opcode
= SQ_OP3_INST_MULADD
;
2669 pAsm
->D
.dst
.op3
= 1;
2671 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
2672 pAsm
->D
.dst
.reg
= tmp
;
2673 nomask_PVSDST(&(pAsm
->D
.dst
));
2674 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
2676 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
2677 pAsm
->S
[0].src
.rtype
= SRC_REG_TEMPORARY
;
2678 pAsm
->S
[0].src
.reg
= tmp
;
2679 noswizzle_PVSSRC(&(pAsm
->S
[0].src
));
2682 if( GL_FALSE
== assemble_src(pAsm
, 0, 1) )
2686 if( GL_FALSE
== assemble_src(pAsm
, 2, -1) )
2691 if( GL_FALSE
== next_ins(pAsm
) )
2696 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_MOV
;
2698 if( GL_FALSE
== assemble_dst(pAsm
) )
2703 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
2704 pAsm
->S
[0].src
.rtype
= SRC_REG_TEMPORARY
;
2705 pAsm
->S
[0].src
.reg
= tmp
;
2706 noswizzle_PVSSRC(&(pAsm
->S
[0].src
));
2708 if( GL_FALSE
== next_ins(pAsm
) )
2716 GLboolean
assemble_MAD(struct r700_AssemblerBase
*pAsm
)
2719 GLboolean bReplaceDst
= GL_FALSE
;
2720 struct prog_instruction
*pILInst
= &(pAsm
->pILInst
[pAsm
->uiCurInst
]);
2722 if( GL_FALSE
== checkop3(pAsm
) )
2727 pAsm
->D
.dst
.opcode
= SQ_OP3_INST_MULADD
;
2728 pAsm
->D
.dst
.op3
= 1;
2732 if(PROGRAM_TEMPORARY
== pILInst
->DstReg
.File
)
2733 { /* TODO : more investigation on MAD src and dst using same register */
2734 for(ii
=0; ii
<3; ii
++)
2736 if( (PROGRAM_TEMPORARY
== pILInst
->SrcReg
[ii
].File
)
2737 && (pILInst
->DstReg
.Index
== pILInst
->SrcReg
[ii
].Index
) )
2739 bReplaceDst
= GL_TRUE
;
2744 if(0xF != pILInst
->DstReg
.WriteMask
)
2745 { /* OP3 has no support for write mask */
2746 bReplaceDst
= GL_TRUE
;
2749 if(GL_TRUE
== bReplaceDst
)
2751 tmp
= gethelpr(pAsm
);
2753 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
2754 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
2755 pAsm
->D
.dst
.reg
= tmp
;
2757 nomask_PVSDST(&(pAsm
->D
.dst
));
2761 if( GL_FALSE
== assemble_dst(pAsm
) )
2767 if( GL_FALSE
== assemble_src(pAsm
, 0, -1) )
2772 if( GL_FALSE
== assemble_src(pAsm
, 1, -1) )
2777 if( GL_FALSE
== assemble_src(pAsm
, 2, -1) )
2782 if ( GL_FALSE
== next_ins(pAsm
) )
2787 if (GL_TRUE
== bReplaceDst
)
2789 if( GL_FALSE
== assemble_dst(pAsm
) )
2794 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_MOV
;
2797 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
2798 pAsm
->S
[0].src
.rtype
= SRC_REG_TEMPORARY
;
2799 pAsm
->S
[0].src
.reg
= tmp
;
2801 noneg_PVSSRC(&(pAsm
->S
[0].src
));
2802 noswizzle_PVSSRC(&(pAsm
->S
[0].src
));
2804 if( GL_FALSE
== next_ins(pAsm
) )
2814 GLboolean
assemble_LIT(r700_AssemblerBase
*pAsm
)
2816 unsigned int dstReg
;
2817 unsigned int dstType
;
2818 unsigned int srcReg
;
2819 unsigned int srcType
;
2821 int tmp
= gethelpr(pAsm
);
2823 if( GL_FALSE
== assemble_dst(pAsm
) )
2827 if( GL_FALSE
== assemble_src(pAsm
, 0, -1) )
2831 dstReg
= pAsm
->D
.dst
.reg
;
2832 dstType
= pAsm
->D
.dst
.rtype
;
2833 srcReg
= pAsm
->S
[0].src
.reg
;
2834 srcType
= pAsm
->S
[0].src
.rtype
;
2836 /* dst.xw, <- 1.0 */
2837 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_MOV
;
2838 pAsm
->D
.dst
.rtype
= dstType
;
2839 pAsm
->D
.dst
.reg
= dstReg
;
2840 pAsm
->D
.dst
.writex
= 1;
2841 pAsm
->D
.dst
.writey
= 0;
2842 pAsm
->D
.dst
.writez
= 0;
2843 pAsm
->D
.dst
.writew
= 1;
2844 pAsm
->S
[0].src
.rtype
= SRC_REG_TEMPORARY
;
2845 pAsm
->S
[0].src
.reg
= tmp
;
2846 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
2847 noneg_PVSSRC(&(pAsm
->S
[0].src
));
2848 pAsm
->S
[0].src
.swizzlex
= SQ_SEL_1
;
2849 pAsm
->S
[0].src
.swizzley
= SQ_SEL_1
;
2850 pAsm
->S
[0].src
.swizzlez
= SQ_SEL_1
;
2851 pAsm
->S
[0].src
.swizzlew
= SQ_SEL_1
;
2852 if( GL_FALSE
== next_ins(pAsm
) )
2857 /* dst.y = max(src.x, 0.0) */
2858 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_MAX
;
2859 pAsm
->D
.dst
.rtype
= dstType
;
2860 pAsm
->D
.dst
.reg
= dstReg
;
2861 pAsm
->D
.dst
.writex
= 0;
2862 pAsm
->D
.dst
.writey
= 1;
2863 pAsm
->D
.dst
.writez
= 0;
2864 pAsm
->D
.dst
.writew
= 0;
2865 pAsm
->S
[0].src
.rtype
= srcType
;
2866 pAsm
->S
[0].src
.reg
= srcReg
;
2867 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
2868 noneg_PVSSRC(&(pAsm
->S
[0].src
));
2869 pAsm
->S
[0].src
.swizzlex
= SQ_SEL_X
;
2870 pAsm
->S
[0].src
.swizzley
= SQ_SEL_X
;
2871 pAsm
->S
[0].src
.swizzlez
= SQ_SEL_X
;
2872 pAsm
->S
[0].src
.swizzlew
= SQ_SEL_X
;
2873 pAsm
->S
[1].src
.rtype
= SRC_REG_TEMPORARY
;
2874 pAsm
->S
[1].src
.reg
= tmp
;
2875 setaddrmode_PVSSRC(&(pAsm
->S
[1].src
), ADDR_ABSOLUTE
);
2876 noneg_PVSSRC(&(pAsm
->S
[1].src
));
2877 pAsm
->S
[1].src
.swizzlex
= SQ_SEL_0
;
2878 pAsm
->S
[1].src
.swizzley
= SQ_SEL_0
;
2879 pAsm
->S
[1].src
.swizzlez
= SQ_SEL_0
;
2880 pAsm
->S
[1].src
.swizzlew
= SQ_SEL_0
;
2881 if( GL_FALSE
== next_ins(pAsm
) )
2886 /* before: dst.w = log(src.y)
2887 * after : dst.x = log(src.y)
2888 * why change dest register is that dst.w has been initialized as 1 before
2890 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_LOG_CLAMPED
;
2891 pAsm
->D
.dst
.math
= 1;
2892 pAsm
->D
.dst
.rtype
= dstType
;
2893 pAsm
->D
.dst
.reg
= dstReg
;
2894 pAsm
->D
.dst
.writex
= 1;
2895 pAsm
->D
.dst
.writey
= 0;
2896 pAsm
->D
.dst
.writez
= 0;
2897 pAsm
->D
.dst
.writew
= 0;
2898 pAsm
->S
[0].src
.rtype
= srcType
;
2899 pAsm
->S
[0].src
.reg
= srcReg
;
2900 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
2901 noneg_PVSSRC(&(pAsm
->S
[0].src
));
2902 pAsm
->S
[0].src
.swizzlex
= SQ_SEL_Y
;
2903 pAsm
->S
[0].src
.swizzley
= SQ_SEL_Y
;
2904 pAsm
->S
[0].src
.swizzlez
= SQ_SEL_Y
;
2905 pAsm
->S
[0].src
.swizzlew
= SQ_SEL_Y
;
2906 if( GL_FALSE
== next_ins(pAsm
) )
2911 /* before: tmp.x = amd MUL_LIT(src.w, dst.w, src.x ) */
2912 /* after : tmp.x = amd MUL_LIT(src.w, dst.x, src.x ) */
2913 pAsm
->D
.dst
.opcode
= SQ_OP3_INST_MUL_LIT
;
2914 pAsm
->D
.dst
.op3
= 1;
2915 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
2916 pAsm
->D
.dst
.reg
= tmp
;
2917 pAsm
->D
.dst
.writex
= 1;
2918 pAsm
->D
.dst
.writey
= 0;
2919 pAsm
->D
.dst
.writez
= 0;
2920 pAsm
->D
.dst
.writew
= 0;
2922 pAsm
->S
[0].src
.rtype
= srcType
;
2923 pAsm
->S
[0].src
.reg
= srcReg
;
2924 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
2925 noneg_PVSSRC(&(pAsm
->S
[0].src
));
2926 pAsm
->S
[0].src
.swizzlex
= SQ_SEL_W
;
2927 pAsm
->S
[0].src
.swizzley
= SQ_SEL_W
;
2928 pAsm
->S
[0].src
.swizzlez
= SQ_SEL_W
;
2929 pAsm
->S
[0].src
.swizzlew
= SQ_SEL_W
;
2931 pAsm
->S
[1].src
.rtype
= SRC_REG_TEMPORARY
;
2932 pAsm
->S
[1].src
.reg
= dstReg
;
2933 setaddrmode_PVSSRC(&(pAsm
->S
[1].src
), ADDR_ABSOLUTE
);
2934 noneg_PVSSRC(&(pAsm
->S
[1].src
));
2935 pAsm
->S
[1].src
.swizzlex
= SQ_SEL_X
;
2936 pAsm
->S
[1].src
.swizzley
= SQ_SEL_X
;
2937 pAsm
->S
[1].src
.swizzlez
= SQ_SEL_X
;
2938 pAsm
->S
[1].src
.swizzlew
= SQ_SEL_X
;
2940 pAsm
->S
[2].src
.rtype
= srcType
;
2941 pAsm
->S
[2].src
.reg
= srcReg
;
2942 setaddrmode_PVSSRC(&(pAsm
->S
[2].src
), ADDR_ABSOLUTE
);
2943 noneg_PVSSRC(&(pAsm
->S
[2].src
));
2944 pAsm
->S
[2].src
.swizzlex
= SQ_SEL_X
;
2945 pAsm
->S
[2].src
.swizzley
= SQ_SEL_X
;
2946 pAsm
->S
[2].src
.swizzlez
= SQ_SEL_X
;
2947 pAsm
->S
[2].src
.swizzlew
= SQ_SEL_X
;
2949 if( GL_FALSE
== next_ins(pAsm
) )
2954 /* dst.z = exp(tmp.x) */
2955 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_EXP_IEEE
;
2956 pAsm
->D
.dst
.math
= 1;
2957 pAsm
->D
.dst
.rtype
= dstType
;
2958 pAsm
->D
.dst
.reg
= dstReg
;
2959 pAsm
->D
.dst
.writex
= 0;
2960 pAsm
->D
.dst
.writey
= 0;
2961 pAsm
->D
.dst
.writez
= 1;
2962 pAsm
->D
.dst
.writew
= 0;
2964 pAsm
->S
[0].src
.rtype
= SRC_REG_TEMPORARY
;
2965 pAsm
->S
[0].src
.reg
= tmp
;
2966 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
2967 noneg_PVSSRC(&(pAsm
->S
[0].src
));
2968 pAsm
->S
[0].src
.swizzlex
= SQ_SEL_X
;
2969 pAsm
->S
[0].src
.swizzley
= SQ_SEL_X
;
2970 pAsm
->S
[0].src
.swizzlez
= SQ_SEL_X
;
2971 pAsm
->S
[0].src
.swizzlew
= SQ_SEL_X
;
2973 if( GL_FALSE
== next_ins(pAsm
) )
2981 GLboolean
assemble_MAX(r700_AssemblerBase
*pAsm
)
2983 if( GL_FALSE
== checkop2(pAsm
) )
2988 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_MAX
;
2990 if( GL_FALSE
== assemble_dst(pAsm
) )
2995 if( GL_FALSE
== assemble_src(pAsm
, 0, -1) )
3000 if( GL_FALSE
== assemble_src(pAsm
, 1, -1) )
3005 if( GL_FALSE
== next_ins(pAsm
) )
3013 GLboolean
assemble_MIN(r700_AssemblerBase
*pAsm
)
3015 if( GL_FALSE
== checkop2(pAsm
) )
3020 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_MIN
;
3022 if( GL_FALSE
== assemble_dst(pAsm
) )
3027 if( GL_FALSE
== assemble_src(pAsm
, 0, -1) )
3032 if( GL_FALSE
== assemble_src(pAsm
, 1, -1) )
3037 if( GL_FALSE
== next_ins(pAsm
) )
3045 GLboolean
assemble_MOV(r700_AssemblerBase
*pAsm
)
3049 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_MOV
;
3051 if (GL_FALSE
== assemble_dst(pAsm
))
3056 if (GL_FALSE
== assemble_src(pAsm
, 0, -1))
3061 if ( GL_FALSE
== next_ins(pAsm
) )
3069 GLboolean
assemble_MUL(r700_AssemblerBase
*pAsm
)
3071 if( GL_FALSE
== checkop2(pAsm
) )
3076 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_MUL
;
3078 if( GL_FALSE
== assemble_dst(pAsm
) )
3083 if( GL_FALSE
== assemble_src(pAsm
, 0, -1) )
3088 if( GL_FALSE
== assemble_src(pAsm
, 1, -1) )
3093 if( GL_FALSE
== next_ins(pAsm
) )
3101 GLboolean
assemble_POW(r700_AssemblerBase
*pAsm
)
3107 tmp
= gethelpr(pAsm
);
3109 // LG2 tmp.x, a.swizzle
3110 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_LOG_IEEE
;
3111 pAsm
->D
.dst
.math
= 1;
3113 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
3114 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
3115 pAsm
->D
.dst
.reg
= tmp
;
3116 nomask_PVSDST(&(pAsm
->D
.dst
));
3118 if( GL_FALSE
== assemble_src(pAsm
, 0, -1) )
3123 if( GL_FALSE
== next_ins(pAsm
) )
3128 // MUL tmp.x, tmp.x, b.swizzle
3129 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_MUL
;
3131 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
3132 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
3133 pAsm
->D
.dst
.reg
= tmp
;
3134 nomask_PVSDST(&(pAsm
->D
.dst
));
3136 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
3137 pAsm
->S
[0].src
.rtype
= SRC_REG_TEMPORARY
;
3138 pAsm
->S
[0].src
.reg
= tmp
;
3139 setswizzle_PVSSRC(&(pAsm
->S
[0].src
), SQ_SEL_X
);
3140 noneg_PVSSRC(&(pAsm
->S
[0].src
));
3142 if( GL_FALSE
== assemble_src(pAsm
, 1, -1) )
3147 if( GL_FALSE
== next_ins(pAsm
) )
3152 // EX2 dst.mask, tmp.x
3154 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_EXP_IEEE
;
3155 pAsm
->D
.dst
.math
= 1;
3157 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
3158 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
3159 pAsm
->D
.dst
.reg
= tmp
;
3160 nomask_PVSDST(&(pAsm
->D
.dst
));
3162 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
3163 pAsm
->S
[0].src
.rtype
= SRC_REG_TEMPORARY
;
3164 pAsm
->S
[0].src
.reg
= tmp
;
3165 setswizzle_PVSSRC(&(pAsm
->S
[0].src
), SQ_SEL_X
);
3166 noneg_PVSSRC(&(pAsm
->S
[0].src
));
3168 if( GL_FALSE
== next_ins(pAsm
) )
3173 // Now replicate result to all necessary channels in destination
3174 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_MOV
;
3176 if( GL_FALSE
== assemble_dst(pAsm
) )
3181 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
3182 pAsm
->S
[0].src
.rtype
= DST_REG_TEMPORARY
;
3183 pAsm
->S
[0].src
.reg
= tmp
;
3185 setswizzle_PVSSRC(&(pAsm
->S
[0].src
), SQ_SEL_X
);
3186 noneg_PVSSRC(&(pAsm
->S
[0].src
));
3188 if( GL_FALSE
== next_ins(pAsm
) )
3196 GLboolean
assemble_RCP(r700_AssemblerBase
*pAsm
)
3198 return assemble_math_function(pAsm
, SQ_OP2_INST_RECIP_IEEE
);
3201 GLboolean
assemble_RSQ(r700_AssemblerBase
*pAsm
)
3203 return assemble_math_function(pAsm
, SQ_OP2_INST_RECIPSQRT_IEEE
);
3206 GLboolean
assemble_SIN(r700_AssemblerBase
*pAsm
)
3208 return assemble_math_function(pAsm
, SQ_OP2_INST_SIN
);
3211 GLboolean
assemble_SCS(r700_AssemblerBase
*pAsm
)
3217 tmp
= gethelpr(pAsm
);
3220 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_COS
;
3221 pAsm
->D
.dst
.math
= 1;
3223 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
3224 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
3225 pAsm
->D
.dst
.reg
= tmp
;
3226 pAsm
->D
.dst
.writex
= 1;
3228 if( GL_FALSE
== assemble_src(pAsm
, 0, -1) )
3233 if ( GL_FALSE
== next_ins(pAsm
) )
3239 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_SIN
;
3240 pAsm
->D
.dst
.math
= 1;
3242 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
3243 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
3244 pAsm
->D
.dst
.reg
= tmp
;
3245 pAsm
->D
.dst
.writey
= 1;
3247 if( GL_FALSE
== assemble_src(pAsm
, 0, -1) )
3252 if( GL_FALSE
== next_ins(pAsm
) )
3257 // MOV dst.mask, tmp
3258 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_MOV
;
3260 if( GL_FALSE
== assemble_dst(pAsm
) )
3265 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
3266 pAsm
->S
[0].src
.rtype
= DST_REG_TEMPORARY
;
3267 pAsm
->S
[0].src
.reg
= tmp
;
3269 noswizzle_PVSSRC(&(pAsm
->S
[0].src
));
3270 pAsm
->S
[0].src
.swizzlez
= SQ_SEL_0
;
3271 pAsm
->S
[0].src
.swizzlew
= SQ_SEL_0
;
3273 if ( GL_FALSE
== next_ins(pAsm
) )
3281 GLboolean
assemble_SGE(r700_AssemblerBase
*pAsm
)
3283 if( GL_FALSE
== checkop2(pAsm
) )
3288 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_SETGE
;
3290 if( GL_FALSE
== assemble_dst(pAsm
) )
3295 if( GL_FALSE
== assemble_src(pAsm
, 0, -1) )
3300 if( GL_FALSE
== assemble_src(pAsm
, 1, -1) )
3305 if( GL_FALSE
== next_ins(pAsm
) )
3313 GLboolean
assemble_SLT(r700_AssemblerBase
*pAsm
)
3315 if( GL_FALSE
== checkop2(pAsm
) )
3320 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_SETGT
;
3322 if( GL_FALSE
== assemble_dst(pAsm
) )
3327 if( GL_FALSE
== assemble_src(pAsm
, 0, 1) )
3332 if( GL_FALSE
== assemble_src(pAsm
, 1, 0) )
3337 if( GL_FALSE
== next_ins(pAsm
) )
3345 GLboolean
assemble_STP(r700_AssemblerBase
*pAsm
)
3350 GLboolean
assemble_TEX(r700_AssemblerBase
*pAsm
)
3352 GLboolean src_const
;
3354 switch (pAsm
->pILInst
[pAsm
->uiCurInst
].SrcReg
[0].File
)
3356 case PROGRAM_CONSTANT
:
3357 case PROGRAM_LOCAL_PARAM
:
3358 case PROGRAM_ENV_PARAM
:
3359 case PROGRAM_STATE_VAR
:
3360 src_const
= GL_TRUE
;
3361 case PROGRAM_TEMPORARY
:
3363 src_const
= GL_FALSE
;
3366 if (GL_TRUE
== src_const
)
3368 r700_error(TODO_ASM_CONSTTEXADDR
, "TODO: Texture coordinates from a constant register not supported.");
3372 switch (pAsm
->pILInst
[pAsm
->uiCurInst
].Opcode
)
3375 pAsm
->D
.dst
.opcode
= SQ_TEX_INST_SAMPLE
;
3378 r700_error(TODO_ASM_TXB
, "do not support TXB yet");
3382 /* TODO : tex proj version : divid first 3 components by 4th */
3383 pAsm
->D
.dst
.opcode
= SQ_TEX_INST_SAMPLE
;
3386 r700_error(ERROR_ASM_BADTEXINST
, "Internal error: bad texture op (not TEX)");
3391 // Set src1 to tex unit id
3392 pAsm
->S
[1].src
.reg
= pAsm
->pILInst
[pAsm
->uiCurInst
].TexSrcUnit
;
3393 pAsm
->S
[1].src
.rtype
= SRC_REG_TEMPORARY
;
3395 //No sw info from mesa compiler, so hard code here.
3396 pAsm
->S
[1].src
.swizzlex
= SQ_SEL_X
;
3397 pAsm
->S
[1].src
.swizzley
= SQ_SEL_Y
;
3398 pAsm
->S
[1].src
.swizzlez
= SQ_SEL_Z
;
3399 pAsm
->S
[1].src
.swizzlew
= SQ_SEL_W
;
3401 if( GL_FALSE
== tex_dst(pAsm
) )
3406 if( GL_FALSE
== tex_src(pAsm
) )
3411 if ( GL_FALSE
== next_ins(pAsm
) )
3419 GLboolean
assemble_XPD(r700_AssemblerBase
*pAsm
)
3423 if( GL_FALSE
== checkop2(pAsm
) )
3428 tmp
= gethelpr(pAsm
);
3430 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_MUL
;
3432 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
3433 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
3434 pAsm
->D
.dst
.reg
= tmp
;
3435 nomask_PVSDST(&(pAsm
->D
.dst
));
3437 if( GL_FALSE
== assemble_src(pAsm
, 0, -1) )
3442 if( GL_FALSE
== assemble_src(pAsm
, 1, -1) )
3447 swizzleagain_PVSSRC(&(pAsm
->S
[0].src
), SQ_SEL_Z
, SQ_SEL_X
, SQ_SEL_Y
, SQ_SEL_0
);
3448 swizzleagain_PVSSRC(&(pAsm
->S
[1].src
), SQ_SEL_Y
, SQ_SEL_Z
, SQ_SEL_X
, SQ_SEL_0
);
3450 if( GL_FALSE
== next_ins(pAsm
) )
3455 pAsm
->D
.dst
.opcode
= SQ_OP3_INST_MULADD
;
3456 pAsm
->D
.dst
.op3
= 1;
3458 if(0xF != pAsm
->pILInst
[pAsm
->uiCurInst
].DstReg
.WriteMask
)
3460 tmp
= gethelpr(pAsm
);
3462 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
3463 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
3464 pAsm
->D
.dst
.reg
= tmp
;
3466 nomask_PVSDST(&(pAsm
->D
.dst
));
3470 if( GL_FALSE
== assemble_dst(pAsm
) )
3476 if( GL_FALSE
== assemble_src(pAsm
, 0, -1) )
3481 if( GL_FALSE
== assemble_src(pAsm
, 1, -1) )
3486 swizzleagain_PVSSRC(&(pAsm
->S
[0].src
), SQ_SEL_Y
, SQ_SEL_Z
, SQ_SEL_X
, SQ_SEL_0
);
3487 swizzleagain_PVSSRC(&(pAsm
->S
[1].src
), SQ_SEL_Z
, SQ_SEL_X
, SQ_SEL_Y
, SQ_SEL_0
);
3489 // result1 + (neg) result0
3490 setaddrmode_PVSSRC(&(pAsm
->S
[2].src
),ADDR_ABSOLUTE
);
3491 pAsm
->S
[2].src
.rtype
= SRC_REG_TEMPORARY
;
3492 pAsm
->S
[2].src
.reg
= tmp
;
3494 neg_PVSSRC(&(pAsm
->S
[2].src
));
3495 noswizzle_PVSSRC(&(pAsm
->S
[2].src
));
3497 if( GL_FALSE
== next_ins(pAsm
) )
3503 if(0xF != pAsm
->pILInst
[pAsm
->uiCurInst
].DstReg
.WriteMask
)
3505 if( GL_FALSE
== assemble_dst(pAsm
) )
3510 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_MOV
;
3512 // Use tmp as source
3513 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
3514 pAsm
->S
[0].src
.rtype
= SRC_REG_TEMPORARY
;
3515 pAsm
->S
[0].src
.reg
= tmp
;
3517 noneg_PVSSRC(&(pAsm
->S
[0].src
));
3518 noswizzle_PVSSRC(&(pAsm
->S
[0].src
));
3520 if( GL_FALSE
== next_ins(pAsm
) )
3529 GLboolean
assemble_EXPORT(r700_AssemblerBase
*pAsm
)
3534 GLboolean
assemble_IF(r700_AssemblerBase
*pAsm
)
3539 GLboolean
assemble_ENDIF(r700_AssemblerBase
*pAsm
)
3544 GLboolean
AssembleInstr(GLuint uiNumberInsts
,
3545 struct prog_instruction
*pILInst
,
3546 r700_AssemblerBase
*pR700AsmCode
)
3550 pR700AsmCode
->pILInst
= pILInst
;
3551 for(i
=0; i
<uiNumberInsts
; i
++)
3553 pR700AsmCode
->uiCurInst
= i
;
3555 switch (pILInst
[i
].Opcode
)
3558 if ( GL_FALSE
== assemble_ABS(pR700AsmCode
) )
3563 if ( GL_FALSE
== assemble_ADD(pR700AsmCode
) )
3568 r700_error(TODO_ASM_NEEDIMPINST
, "Not yet implemented instruction OPCODE_ARL ");
3569 //if ( GL_FALSE == assemble_BAD("ARL") )
3573 r700_error(TODO_ASM_NEEDIMPINST
, "Not yet implemented instruction OPCODE_ARR ");
3574 //if ( GL_FALSE == assemble_BAD("ARR") )
3579 if ( GL_FALSE
== assemble_CMP(pR700AsmCode
) )
3583 if ( GL_FALSE
== assemble_COS(pR700AsmCode
) )
3590 if ( GL_FALSE
== assemble_DOT(pR700AsmCode
) )
3595 if ( GL_FALSE
== assemble_DST(pR700AsmCode
) )
3600 if ( GL_FALSE
== assemble_EX2(pR700AsmCode
) )
3604 r700_error(TODO_ASM_NEEDIMPINST
, "Not yet implemented instruction OPCODE_EXP ");
3605 //if ( GL_FALSE == assemble_BAD("EXP") )
3607 break; // approx of EX2
3610 if ( GL_FALSE
== assemble_FLR(pR700AsmCode
) )
3614 // if ( GL_FALSE == assemble_FLR_INT() )
3619 if ( GL_FALSE
== assemble_FRC(pR700AsmCode
) )
3624 if ( GL_FALSE
== assemble_KIL(pR700AsmCode
) )
3628 if ( GL_FALSE
== assemble_LG2(pR700AsmCode
) )
3632 if ( GL_FALSE
== assemble_LIT(pR700AsmCode
) )
3636 if ( GL_FALSE
== assemble_LRP(pR700AsmCode
) )
3640 r700_error(TODO_ASM_NEEDIMPINST
, "Not yet implemented instruction OPCODE_LOG ");
3641 //if ( GL_FALSE == assemble_BAD("LOG") )
3643 break; // approx of LG2
3646 if ( GL_FALSE
== assemble_MAD(pR700AsmCode
) )
3650 if ( GL_FALSE
== assemble_MAX(pR700AsmCode
) )
3654 if ( GL_FALSE
== assemble_MIN(pR700AsmCode
) )
3659 if ( GL_FALSE
== assemble_MOV(pR700AsmCode
) )
3663 if ( GL_FALSE
== assemble_MUL(pR700AsmCode
) )
3668 if ( GL_FALSE
== assemble_POW(pR700AsmCode
) )
3672 if ( GL_FALSE
== assemble_RCP(pR700AsmCode
) )
3676 if ( GL_FALSE
== assemble_RSQ(pR700AsmCode
) )
3680 if ( GL_FALSE
== assemble_SIN(pR700AsmCode
) )
3684 if ( GL_FALSE
== assemble_SCS(pR700AsmCode
) )
3689 if ( GL_FALSE
== assemble_SGE(pR700AsmCode
) )
3693 if ( GL_FALSE
== assemble_SLT(pR700AsmCode
) )
3698 // if ( GL_FALSE == assemble_STP(pR700AsmCode) )
3703 if ( GL_FALSE
== assemble_MOV(pR700AsmCode
) )
3709 if( (i
+1)<uiNumberInsts
)
3711 if(OPCODE_END
!= pILInst
[i
+1].Opcode
)
3713 if( GL_TRUE
== IsTex(pILInst
[i
+1].Opcode
) )
3715 pR700AsmCode
->pInstDeps
[i
+1].nDstDep
= i
+1; //=1?
3725 if ( GL_FALSE
== assemble_TEX(pR700AsmCode
) )
3730 if ( GL_FALSE
== assemble_XPD(pR700AsmCode
) )
3735 if ( GL_FALSE
== assemble_IF(pR700AsmCode
) )
3739 r700_error(TODO_ASM_NEEDIMPINST
, "Not yet implemented instruction OPCODE_ELSE ");
3740 //if ( GL_FALSE == assemble_BAD("ELSE") )
3744 if ( GL_FALSE
== assemble_ENDIF(pR700AsmCode
) )
3748 //case OPCODE_EXPORT:
3749 // if ( GL_FALSE == assemble_EXPORT() )
3754 //pR700AsmCode->uiCurInst = i;
3755 //This is to remaind that if in later exoort there is depth/stencil
3756 //export, we need a mov to re-arrange DST channel, where using a
3757 //psuedo inst, we will use this end inst to do it.
3761 r700_error(ERROR_ASM_UNKNOWNILINST
, "internal: unknown instruction");
3769 GLboolean
Process_Export(r700_AssemblerBase
* pAsm
,
3771 GLuint export_starting_index
,
3772 GLuint export_count
,
3773 GLuint starting_register_number
,
3774 GLboolean is_depth_export
)
3776 unsigned char ucWriteMask
;
3778 check_current_clause(pAsm
, CF_EMPTY_CLAUSE
);
3779 check_current_clause(pAsm
, CF_EXPORT_CLAUSE
); //alloc the cf_current_export_clause_ptr
3781 pAsm
->cf_current_export_clause_ptr
->m_Word0
.f
.type
= type
;
3785 case SQ_EXPORT_PIXEL
:
3786 if(GL_TRUE
== is_depth_export
)
3788 pAsm
->cf_current_export_clause_ptr
->m_Word0
.f
.array_base
= SQ_CF_PIXEL_Z
;
3792 pAsm
->cf_current_export_clause_ptr
->m_Word0
.f
.array_base
= SQ_CF_PIXEL_MRT0
+ export_starting_index
;
3797 pAsm
->cf_current_export_clause_ptr
->m_Word0
.f
.array_base
= SQ_CF_POS_0
+ export_starting_index
;
3800 case SQ_EXPORT_PARAM
:
3801 pAsm
->cf_current_export_clause_ptr
->m_Word0
.f
.array_base
= 0x0 + export_starting_index
;
3805 r700_error(ERROR_ASM_BADEXPORTTYPE
, "Unknown export type: %d", type
);
3810 pAsm
->cf_current_export_clause_ptr
->m_Word0
.f
.rw_gpr
= starting_register_number
;
3812 pAsm
->cf_current_export_clause_ptr
->m_Word0
.f
.rw_rel
= SQ_ABSOLUTE
;
3813 pAsm
->cf_current_export_clause_ptr
->m_Word0
.f
.index_gpr
= 0x0;
3814 pAsm
->cf_current_export_clause_ptr
->m_Word0
.f
.elem_size
= 0x3;
3816 pAsm
->cf_current_export_clause_ptr
->m_Word1
.f
.burst_count
= (export_count
- 1);
3817 pAsm
->cf_current_export_clause_ptr
->m_Word1
.f
.end_of_program
= 0x0;
3818 pAsm
->cf_current_export_clause_ptr
->m_Word1
.f
.valid_pixel_mode
= 0x0;
3819 pAsm
->cf_current_export_clause_ptr
->m_Word1
.f
.cf_inst
= SQ_CF_INST_EXPORT
; // _DONE
3820 pAsm
->cf_current_export_clause_ptr
->m_Word1
.f
.whole_quad_mode
= 0x0;
3821 pAsm
->cf_current_export_clause_ptr
->m_Word1
.f
.barrier
= 0x1;
3823 if (export_count
== 1)
3825 ucWriteMask
= pAsm
->pucOutMask
[starting_register_number
- pAsm
->starting_export_register_number
];
3827 if( (ucWriteMask
& 0x1) != 0)
3829 pAsm
->cf_current_export_clause_ptr
->m_Word1_SWIZ
.f
.sel_x
= SQ_SEL_X
;
3833 pAsm
->cf_current_export_clause_ptr
->m_Word1_SWIZ
.f
.sel_x
= SQ_SEL_MASK
;
3835 if( ((ucWriteMask
>>1) & 0x1) != 0)
3837 pAsm
->cf_current_export_clause_ptr
->m_Word1_SWIZ
.f
.sel_y
= SQ_SEL_Y
;
3841 pAsm
->cf_current_export_clause_ptr
->m_Word1_SWIZ
.f
.sel_y
= SQ_SEL_MASK
;
3843 if( ((ucWriteMask
>>2) & 0x1) != 0)
3845 pAsm
->cf_current_export_clause_ptr
->m_Word1_SWIZ
.f
.sel_z
= SQ_SEL_Z
;
3849 pAsm
->cf_current_export_clause_ptr
->m_Word1_SWIZ
.f
.sel_z
= SQ_SEL_MASK
;
3851 if( ((ucWriteMask
>>3) & 0x1) != 0)
3853 pAsm
->cf_current_export_clause_ptr
->m_Word1_SWIZ
.f
.sel_w
= SQ_SEL_W
;
3857 pAsm
->cf_current_export_clause_ptr
->m_Word1_SWIZ
.f
.sel_w
= SQ_SEL_MASK
;
3862 // This should only be used if all components for all registers have been written
3863 pAsm
->cf_current_export_clause_ptr
->m_Word1_SWIZ
.f
.sel_x
= SQ_SEL_X
;
3864 pAsm
->cf_current_export_clause_ptr
->m_Word1_SWIZ
.f
.sel_y
= SQ_SEL_Y
;
3865 pAsm
->cf_current_export_clause_ptr
->m_Word1_SWIZ
.f
.sel_z
= SQ_SEL_Z
;
3866 pAsm
->cf_current_export_clause_ptr
->m_Word1_SWIZ
.f
.sel_w
= SQ_SEL_W
;
3869 pAsm
->cf_last_export_ptr
= pAsm
->cf_current_export_clause_ptr
;
3874 GLboolean
Move_Depth_Exports_To_Correct_Channels(r700_AssemblerBase
*pAsm
, BITS depth_channel_select
)
3876 gl_inst_opcode Opcode_save
= pAsm
->pILInst
[pAsm
->uiCurInst
].Opcode
; //Should be OPCODE_END
3877 pAsm
->pILInst
[pAsm
->uiCurInst
].Opcode
= OPCODE_MOV
;
3879 // MOV depth_export_register.hw_depth_channel, depth_export_register.depth_channel_select
3881 pAsm
->D
.dst
.opcode
= SQ_OP2_INST_MOV
;
3883 setaddrmode_PVSDST(&(pAsm
->D
.dst
), ADDR_ABSOLUTE
);
3884 pAsm
->D
.dst
.rtype
= DST_REG_TEMPORARY
;
3885 pAsm
->D
.dst
.reg
= pAsm
->depth_export_register_number
;
3887 pAsm
->D
.dst
.writex
= 1; // depth goes in R channel for HW
3889 setaddrmode_PVSSRC(&(pAsm
->S
[0].src
), ADDR_ABSOLUTE
);
3890 pAsm
->S
[0].src
.rtype
= DST_REG_TEMPORARY
;
3891 pAsm
->S
[0].src
.reg
= pAsm
->depth_export_register_number
;
3893 setswizzle_PVSSRC(&(pAsm
->S
[0].src
), depth_channel_select
);
3895 noneg_PVSSRC(&(pAsm
->S
[0].src
));
3897 if( GL_FALSE
== next_ins(pAsm
) )
3902 pAsm
->pILInst
[pAsm
->uiCurInst
].Opcode
= Opcode_save
;
3907 GLboolean
Process_Fragment_Exports(r700_AssemblerBase
*pR700AsmCode
,
3908 GLbitfield OutputsWritten
)
3912 if(pR700AsmCode
->depth_export_register_number
>= 0)
3914 if( GL_FALSE
== Move_Depth_Exports_To_Correct_Channels(pR700AsmCode
, SQ_SEL_Z
) ) // depth
3920 unBit
= 1 << FRAG_RESULT_COLOR
;
3921 if(OutputsWritten
& unBit
)
3923 if( GL_FALSE
== Process_Export(pR700AsmCode
,
3927 pR700AsmCode
->uiFP_OutputMap
[FRAG_RESULT_COLOR
],
3933 unBit
= 1 << FRAG_RESULT_DEPTH
;
3934 if(OutputsWritten
& unBit
)
3936 if( GL_FALSE
== Process_Export(pR700AsmCode
,
3940 pR700AsmCode
->uiFP_OutputMap
[FRAG_RESULT_DEPTH
],
3947 if(pR700AsmCode
->cf_last_export_ptr
!= NULL
)
3949 pR700AsmCode
->cf_last_export_ptr
->m_Word1
.f
.cf_inst
= SQ_CF_INST_EXPORT_DONE
;
3950 pR700AsmCode
->cf_last_export_ptr
->m_Word1
.f
.end_of_program
= 0x1;
3956 GLboolean
Process_Vertex_Exports(r700_AssemblerBase
*pR700AsmCode
,
3957 GLbitfield OutputsWritten
)
3962 GLuint export_starting_index
= 0;
3963 GLuint export_count
= pR700AsmCode
->number_of_exports
;
3965 unBit
= 1 << VERT_RESULT_HPOS
;
3966 if(OutputsWritten
& unBit
)
3968 if( GL_FALSE
== Process_Export(pR700AsmCode
,
3970 export_starting_index
,
3972 pR700AsmCode
->ucVP_OutputMap
[VERT_RESULT_HPOS
],
3980 pR700AsmCode
->cf_last_export_ptr
->m_Word1
.f
.cf_inst
= SQ_CF_INST_EXPORT_DONE
;
3983 pR700AsmCode
->number_of_exports
= export_count
;
3985 unBit
= 1 << VERT_RESULT_COL0
;
3986 if(OutputsWritten
& unBit
)
3988 if( GL_FALSE
== Process_Export(pR700AsmCode
,
3990 export_starting_index
,
3992 pR700AsmCode
->ucVP_OutputMap
[VERT_RESULT_COL0
],
3998 export_starting_index
++;
4001 unBit
= 1 << VERT_RESULT_COL1
;
4002 if(OutputsWritten
& unBit
)
4004 if( GL_FALSE
== Process_Export(pR700AsmCode
,
4006 export_starting_index
,
4008 pR700AsmCode
->ucVP_OutputMap
[VERT_RESULT_COL1
],
4014 export_starting_index
++;
4017 unBit
= 1 << VERT_RESULT_FOGC
;
4018 if(OutputsWritten
& unBit
)
4020 if( GL_FALSE
== Process_Export(pR700AsmCode
,
4022 export_starting_index
,
4024 pR700AsmCode
->ucVP_OutputMap
[VERT_RESULT_FOGC
],
4030 export_starting_index
++;
4035 unBit
= 1 << (VERT_RESULT_TEX0
+ i
);
4036 if(OutputsWritten
& unBit
)
4038 if( GL_FALSE
== Process_Export(pR700AsmCode
,
4040 export_starting_index
,
4042 pR700AsmCode
->ucVP_OutputMap
[VERT_RESULT_TEX0
+ i
],
4048 export_starting_index
++;
4052 // At least one param should be exported
4055 pR700AsmCode
->cf_last_export_ptr
->m_Word1
.f
.cf_inst
= SQ_CF_INST_EXPORT_DONE
;
4059 if( GL_FALSE
== Process_Export(pR700AsmCode
,
4063 pR700AsmCode
->starting_export_register_number
,
4069 pR700AsmCode
->cf_last_export_ptr
->m_Word1_SWIZ
.f
.sel_x
= SQ_SEL_0
;
4070 pR700AsmCode
->cf_last_export_ptr
->m_Word1_SWIZ
.f
.sel_y
= SQ_SEL_0
;
4071 pR700AsmCode
->cf_last_export_ptr
->m_Word1_SWIZ
.f
.sel_z
= SQ_SEL_0
;
4072 pR700AsmCode
->cf_last_export_ptr
->m_Word1_SWIZ
.f
.sel_w
= SQ_SEL_1
;
4073 pR700AsmCode
->cf_last_export_ptr
->m_Word1
.f
.cf_inst
= SQ_CF_INST_EXPORT_DONE
;
4076 pR700AsmCode
->cf_last_export_ptr
->m_Word1
.f
.end_of_program
= 0x1;
4081 GLboolean
Clean_Up_Assembler(r700_AssemblerBase
*pR700AsmCode
)
4083 FREE(pR700AsmCode
->pucOutMask
);
4084 FREE(pR700AsmCode
->pInstDeps
);