static boolean emit_ps_postamble( struct svga_shader_emitter *emit );
-
-
static unsigned
translate_opcode(
uint opcode )
}
-
-
-
-
-static SVGA3dShaderDestToken
+static SVGA3dShaderDestToken
translate_dst_register( struct svga_shader_emitter *emit,
const struct tgsi_full_instruction *insn,
unsigned idx )
assert(index < SVGA3D_TEMPREG_MAX);
index = MIN2(index, SVGA3D_TEMPREG_MAX - 1);
dest = dst_register(translate_file(reg->Register.File), index);
- }
+ }
break;
}
dest.mask = reg->Register.WriteMask;
assert(dest.mask);
- if (insn->Instruction.Saturate)
+ if (insn->Instruction.Saturate)
dest.dstMod = SVGA3DDSTMOD_SATURATE;
return dest;
}
-static struct src_register
+static struct src_register
swizzle( struct src_register src,
int x,
int y,
return 0;
}
-static struct src_register
+static struct src_register
translate_src_register( const struct svga_shader_emitter *emit,
const struct tgsi_full_src_register *reg )
{
*/
src = emit->input_map[reg->Register.Index];
break;
-
+
case TGSI_FILE_IMMEDIATE:
/* Immediates are appended after TGSI constants in the D3D
* constant buffer.
*/
src = src_register( translate_file( reg->Register.File ),
- reg->Register.Index +
- emit->imm_start );
+ reg->Register.Index + emit->imm_start );
break;
default:
* Note: if we exceed the temporary register limit we just use
* register SVGA3D_TEMPREG_MAX - 1.
*/
-static INLINE SVGA3dShaderDestToken
+static INLINE SVGA3dShaderDestToken
get_temp( struct svga_shader_emitter *emit )
{
int i = emit->nr_hw_temp + emit->internal_temp_count++;
* allocated temp, otherwise release will be delayed until the next
* call to reset_temp_regs().
*/
-static INLINE void
+static INLINE void
release_temp( struct svga_shader_emitter *emit,
SVGA3dShaderDestToken temp )
{
{
emit->internal_temp_count = 0;
}
-
+
/* Replace the src with the temporary specified in the dst, but copying
* only the necessary channels, and preserving the original swizzle (which is
SVGA3dShaderInstToken inst,
SVGA3dShaderDestToken dest )
{
- return (emit_instruction( emit, inst ) &&
+ return (emit_instruction( emit, inst ) &&
emit_dst( emit, dest ));
}
if (need_temp0) {
temp0 = get_temp( emit );
-
+
if (!emit_repl( emit, temp0, &src0 ))
return FALSE;
}
if (need_temp0) {
temp0 = get_temp( emit );
-
+
if (!emit_repl( emit, temp0, &src0 ))
return FALSE;
}
get_vface( struct svga_shader_emitter *emit )
{
assert(emit->emitted_vface);
- return src_register(SVGA3DREG_MISCTYPE,
- SVGA3DMISCREG_FACE);
+ return src_register(SVGA3DREG_MISCTYPE, SVGA3DMISCREG_FACE);
}
/* returns {0, 0, 0, 1} immediate */
/*
* Max different constant registers readable per IFC instruction is 1.
*/
-
SVGA3dShaderDestToken tmp = get_temp( emit );
if (!submit_op1(emit, inst_token( SVGA3DOP_MOV ), tmp, src0))
{
emit->dynamic_branching_level--;
- return (emit_instruction( emit,
- inst_token( SVGA3DOP_ENDIF )));
+ return emit_instruction(emit, inst_token(SVGA3DOP_ENDIF));
}
static boolean emit_else(struct svga_shader_emitter *emit,
const struct tgsi_full_instruction *insn)
{
- return (emit_instruction( emit,
- inst_token( SVGA3DOP_ELSE )));
+ return emit_instruction(emit, inst_token(SVGA3DOP_ELSE));
}
/* Translate the following TGSI FLR instruction.
unsigned channel = 1 << i;
if (dst.mask & channel) {
/* RCP TMP.?, SRC1.???? */
- if (!submit_op1( emit, inst_token( SVGA3DOP_RCP ),
- writemask(temp, channel),
+ if (!submit_op1( emit, inst_token( SVGA3DOP_RCP ),
+ writemask(temp, channel),
scalar(src1, i) ))
return FALSE;
}
}
- /* Then multiply them out with a single mul:
- *
+ /* Vector mul:
* MUL DST, SRC0, TMP
*/
if (!submit_op2( emit, inst_token( SVGA3DOP_MUL ), dst, src0,
struct src_register src0)
{
src0 = scalar(src0, TGSI_SWIZZLE_X);
-
- return submit_op1( emit, inst_token( SVGA3DOP_SINCOS ),
- dst, src0 );
+ return submit_op1(emit, inst_token(SVGA3DOP_SINCOS), dst, src0);
}
static boolean emit_sincos(struct svga_shader_emitter *emit,
*
* SETP src0, cmp, src1 -- do this first to avoid aliasing problems.
* MOV dst, fail
- * MOV dst, pass, p0
+ * MOV dst, pass, p0
*/
static boolean
emit_conditional(struct svga_shader_emitter *emit,
emit, &insn->Src[0] );
struct src_register src1 = translate_src_register(
emit, &insn->Src[1] );
-
+
return emit_select( emit, compare, dst, src0, src1 );
}
return submit_op3( emit, inst_token( SVGA3DOP_CMP ), dst,
src0, src2, src1);
}
-
}
struct src_register texcoord;
struct src_register sampler;
SVGA3dShaderDestToken tmp;
-
+
inst.value = 0;
switch (insn->Instruction.Opcode) {
return FALSE;
/* MOV tmp.w, zero */
- if (!submit_op1( emit,
+ if (!submit_op1( emit,
inst_token( SVGA3DOP_MOV ),
- writemask( tmp, TGSI_WRITEMASK_W ),
+ writemask( tmp, TGSI_WRITEMASK_W ),
scalar( zero, TGSI_SWIZZLE_X )))
return FALSE;
-
+
texcoord = src( tmp );
inst.op = SVGA3DOP_TEXLDL;
}
inst.value = 0;
switch (insn->Instruction.Opcode) {
- case TGSI_OPCODE_TXD:
+ case TGSI_OPCODE_TXD:
inst.op = SVGA3DOP_TEXLDD; /* 4 args! */
break;
default:
/* write x/y/z/w comps */
if (dst.mask & srcWritemask) {
- if (!submit_op1(emit,
- inst_token(SVGA3DOP_MOV),
- writemask(dst, srcWritemask),
+ if (!submit_op1(emit,
+ inst_token(SVGA3DOP_MOV),
+ writemask(dst, srcWritemask),
swizzle(src,
srcSwizzle[0],
srcSwizzle[1],
/* write 0 comps */
if (dst.mask & zeroWritemask) {
- if (!submit_op1(emit,
- inst_token(SVGA3DOP_MOV),
- writemask(dst, zeroWritemask),
+ if (!submit_op1(emit,
+ inst_token(SVGA3DOP_MOV),
+ writemask(dst, zeroWritemask),
scalar(get_zero_immediate(emit), TGSI_SWIZZLE_X)))
return FALSE;
}
/* write 1 comps */
if (dst.mask & oneWritemask) {
- if (!submit_op1(emit,
- inst_token(SVGA3DOP_MOV),
- writemask(dst, oneWritemask),
+ if (!submit_op1(emit,
+ inst_token(SVGA3DOP_MOV),
+ writemask(dst, oneWritemask),
scalar(get_zero_immediate(emit), TGSI_SWIZZLE_W)))
return FALSE;
}
static boolean emit_tex(struct svga_shader_emitter *emit,
const struct tgsi_full_instruction *insn )
{
- SVGA3dShaderDestToken dst =
+ SVGA3dShaderDestToken dst =
translate_dst_register( emit, insn, 0 );
struct src_register src0 =
translate_src_register( emit, &insn->Src[0] );
assert(0);
}
-
if (compare) {
SVGA3dShaderDestToken dst2;
const struct tgsi_full_instruction *insn )
{
if (emit->dynamic_branching_level > 0 &&
- insn->Src[0].Register.File == TGSI_FILE_TEMPORARY)
+ insn->Src[0].Register.File == TGSI_FILE_TEMPORARY)
{
struct src_register zero = get_zero_immediate( emit );
- SVGA3dShaderDestToken dst =
+ SVGA3dShaderDestToken dst =
translate_dst_register( emit, insn, 0 );
/* Deriv opcodes not valid inside dynamic branching, workaround
* by zeroing out the destination.
*/
- if (!submit_op1(emit,
- inst_token( SVGA3DOP_MOV ),
+ if (!submit_op1(emit,
+ inst_token( SVGA3DOP_MOV ),
dst,
scalar(zero, TGSI_SWIZZLE_X)))
return FALSE;
-
+
return TRUE;
}
else {
struct src_register src1 = translate_src_register(
emit, &insn->Src[1] );
boolean need_tmp = FALSE;
-
+
/* POW can only output to a temporary */
if (insn->Dst[0].Register.File != TGSI_FILE_TEMPORARY)
need_tmp = TRUE;
-
+
/* POW src1 must not be the same register as dst */
if (alias_src_dst( src1, dst ))
need_tmp = TRUE;
return FALSE;
return submit_op1(emit, inst_token( SVGA3DOP_MOV ), dst, scalar(src(tmp), 0) );
- }
+ }
else {
return submit_op2(emit, inst_token( SVGA3DOP_POW ), dst, src0, src1);
}
boolean need_dst_tmp = FALSE;
/* XPD can only output to a temporary */
- if (SVGA3dShaderGetRegType(dst.value) != SVGA3DREG_TEMP)
+ if (SVGA3dShaderGetRegType(dst.value) != SVGA3DREG_TEMP)
need_dst_tmp = TRUE;
/* The dst reg must not be the same as src0 or src1*/
if (!submit_op1(emit, inst_token( SVGA3DOP_MOV ), dst, src( tmp )))
return FALSE;
- }
+ }
else {
if (!submit_op2(emit, inst_token( SVGA3DOP_CRS ), dst, src0, src1))
return FALSE;
if (dst.mask & TGSI_WRITEMASK_W) {
struct src_register zero = get_zero_immediate( emit );
- if (!submit_op1(emit,
- inst_token( SVGA3DOP_MOV ),
+ if (!submit_op1(emit,
+ inst_token( SVGA3DOP_MOV ),
writemask(dst, TGSI_WRITEMASK_W),
zero))
return FALSE;
/* tmp.xw = 1.0
*/
if (tmp.mask & TGSI_WRITEMASK_XW) {
- if (!submit_op1( emit, inst_token( SVGA3DOP_MOV ),
+ if (!submit_op1( emit, inst_token( SVGA3DOP_MOV ),
writemask(tmp, TGSI_WRITEMASK_XW ),
scalar( zero, 3 )))
return FALSE;
}
-
+
/* tmp.yz = src0
*/
if (tmp.mask & TGSI_WRITEMASK_YZ) {
- if (!submit_op1( emit, inst_token( SVGA3DOP_MOV ),
+ if (!submit_op1( emit, inst_token( SVGA3DOP_MOV ),
writemask(tmp, TGSI_WRITEMASK_YZ ),
src0))
return FALSE;
/* tmp.yw = tmp * src1
*/
if (tmp.mask & TGSI_WRITEMASK_YW) {
- if (!submit_op2( emit, inst_token( SVGA3DOP_MUL ),
+ if (!submit_op2( emit, inst_token( SVGA3DOP_MUL ),
writemask(tmp, TGSI_WRITEMASK_YW ),
src(tmp),
src1))
/* dst = tmp
*/
if (need_tmp) {
- if (!submit_op1( emit, inst_token( SVGA3DOP_MOV ),
+ if (!submit_op1( emit, inst_token( SVGA3DOP_MOV ),
dst,
src(tmp)))
return FALSE;
- }
+ }
}
-
+
return TRUE;
}
return emit_simple_instruction(emit, SVGA3DOP_LIT, insn);
}
else {
-
/* D3D vs. GL semantics can be fairly easily accomodated by
* variations on this sequence.
*
*
* Will implement the GL version for now.
*/
-
SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 );
SVGA3dShaderDestToken tmp = get_temp( emit );
const struct src_register src0 = translate_src_register(
/* tmp = pow(src.y, src.w)
*/
if (dst.mask & TGSI_WRITEMASK_Z) {
- if (!submit_op2(emit, inst_token( SVGA3DOP_POW ),
- tmp,
- scalar(src0, 1),
+ if (!submit_op2(emit, inst_token( SVGA3DOP_POW ),
+ tmp,
+ scalar(src0, 1),
scalar(src0, 3)))
return FALSE;
}
/* tmp.y = src.x
*/
if (dst.mask & TGSI_WRITEMASK_Y) {
- if (!submit_op1( emit, inst_token( SVGA3DOP_MOV ),
+ if (!submit_op1( emit, inst_token( SVGA3DOP_MOV ),
writemask(tmp, TGSI_WRITEMASK_Y ),
scalar(src0, 0)))
return FALSE;
}
-
+
/* Can't quite do this with emit conditional due to the extra
* writemask on the predicated mov:
*/
/* SETP src0.xxyy, GT, {0}.x */
if (!submit_op2( emit, setp_token, pred_reg,
- predsrc,
+ predsrc,
swizzle(zero, 0, 0, 0, 0) ))
return FALSE;
-
+
/* MOV dst, fail */
if (!submit_op1( emit, inst_token( SVGA3DOP_MOV ), dst,
swizzle(zero, 3, 0, 0, 3 )))
}
-
-
static boolean emit_ex2( struct svga_shader_emitter *emit,
const struct tgsi_full_instruction *insn )
{
* shader.
*/
emit->in_main_func = FALSE;
-
+
for (i = 0; i < emit->nr_labels; i++) {
if (emit->label[i] == position) {
return (emit_instruction( emit, inst_token( SVGA3DOP_RET ) ) &&
{
unsigned position = insn->Label.Label;
unsigned i;
-
+
for (i = 0; i < emit->nr_labels; i++) {
- if (emit->label[i] == position)
+ if (emit->label[i] == position)
break;
}
* touch PSIZ with a hand-crafted MOV below.
*/
if (SVGA3dShaderGetRegType(emit->true_psiz.value) != 0) {
-
if (!submit_op1( emit,
inst_token(SVGA3DOP_MOV),
emit->true_psiz,
SVGA3dShaderDestToken depth = emit->depth_pos;
SVGA3dShaderDestToken pos = emit->true_pos;
unsigned offset = emit->info.file_max[TGSI_FILE_CONSTANT] + 1;
- struct src_register prescale_scale = src_register( SVGA3DREG_CONST,
- offset + 0 );
- struct src_register prescale_trans = src_register( SVGA3DREG_CONST,
- offset + 1 );
+ struct src_register prescale_scale = src_register( SVGA3DREG_CONST,
+ offset + 0 );
+ struct src_register prescale_trans = src_register( SVGA3DREG_CONST,
+ offset + 1 );
if (!submit_op1( emit,
inst_token(SVGA3DOP_MOV),
* MAD result.position, temp_pos.wwww, prescale.trans, temp_pos
* --> Note that prescale.trans.w == 0
*/
- if (!submit_op2( emit,
- inst_token(SVGA3DOP_MUL),
- writemask(temp_pos, TGSI_WRITEMASK_XYZ),
+ if (!submit_op2( emit,
+ inst_token(SVGA3DOP_MUL),
+ writemask(temp_pos, TGSI_WRITEMASK_XYZ),
src(temp_pos),
prescale_scale ))
return FALSE;
- if (!submit_op3( emit,
- inst_token(SVGA3DOP_MAD),
- pos,
+ if (!submit_op3( emit,
+ inst_token(SVGA3DOP_MAD),
+ pos,
swizzle(src(temp_pos), 3, 3, 3, 3),
prescale_trans,
src(temp_pos)))
/* Adjust GL clipping coordinate space to hardware (D3D-style):
*
* DP4 temp_pos.z, {0,0,.5,.5}, temp_pos
- * MOV result.position, temp_pos
+ * MOV result.position, temp_pos
*/
- if (!submit_op2( emit,
- inst_token(SVGA3DOP_DP4),
- writemask(temp_pos, TGSI_WRITEMASK_Z),
- imm_0055,
+ if (!submit_op2( emit,
+ inst_token(SVGA3DOP_DP4),
+ writemask(temp_pos, TGSI_WRITEMASK_Z),
+ imm_0055,
src(temp_pos) ))
return FALSE;
* to reset_temp_regs().
*/
for (i = 0; i < count; i++) {
- color[i] = dst_register( SVGA3DREG_TEMP,
- emit->nr_hw_temp++ );
-
+ color[i] = dst_register( SVGA3DREG_TEMP, emit->nr_hw_temp++ );
front[i] = emit->input_map[emit->internal_color_idx[i]];
/* Back is always the next input:
*/
emit->input_map[emit->internal_color_idx[i]] = src(color[i]);
}
-
+
if_token = inst_token( SVGA3DOP_IFC );
if (emit->key.fkey.front_ccw)
if (!(emit_instruction( emit, inst_token( SVGA3DOP_ELSE))))
return FALSE;
-
+
for (i = 0; i < count; i++) {
if (!submit_op1( emit, inst_token( SVGA3DOP_MOV ), color[i], back[i] ))
return FALSE;
< Elements(emit->input_map));
/* inverted = coord * (1, -1, 1, 1) + (0, 1, 0, 0) */
- if (!submit_op3(emit,
- inst_token(SVGA3DOP_MAD),
+ if (!submit_op3(emit,
+ inst_token(SVGA3DOP_MAD),
dst(emit->ps_inverted_texcoord[unit]),
emit->ps_true_texcoord[unit],
swizzle(pos_neg_one, 0, 3, 0, 0), /* (1, -1, 1, 1) */
emit->input_map[emit->ps_inverted_texcoord_input[unit]] =
emit->ps_inverted_texcoord[unit];
- inverted_texcoords &= ~(1 << unit);
+ inverted_texcoords &= ~(1 << unit);
}
return TRUE;
if (!ret)
goto done;
break;
-
+
case TGSI_TOKEN_TYPE_INSTRUCTION:
if (!helpers_emitted) {
if (!svga_shader_emit_helpers( emit ))
goto done;
helpers_emitted = TRUE;
}
- ret = svga_emit_instruction( emit,
+ ret = svga_emit_instruction( emit,
line_nr++,
&parse.FullToken.FullInstruction );
if (!ret)
default:
break;
}
-
+
reset_temp_regs( emit );
}
tgsi_parse_free( &parse );
return ret;
}
-