}
-/**
- * Create/emit a constant with values {0, 0.5, -1, 1}.
- * We can swizzle this to produce other useful constants such as
- * {0, 0, 0, 0}, {1, 1, 1, 1}, etc.
- */
-static boolean
-create_zero_immediate( struct svga_shader_emitter *emit )
-{
- unsigned idx = emit->nr_hw_float_const++;
-
- /* Emit the constant (0, 0.5, -1, 1) and use swizzling to generate
- * other useful vectors.
- */
- if (!emit_def_const( emit, SVGA3D_CONST_TYPE_FLOAT,
- idx, 0, 0.5, -1, 1 ))
- return FALSE;
-
- emit->zero_immediate_idx = idx;
- emit->created_zero_immediate = TRUE;
-
- return TRUE;
-}
-
-
static boolean
create_loop_const( struct svga_shader_emitter *emit )
{
/**
- * returns {0, 0, 0, 1} immediate
+ * Create/emit a "common" constant with values {0, 0.5, -1, 1}.
+ * We can swizzle this to produce other useful constants such as
+ * {0, 0, 0, 0}, {1, 1, 1, 1}, etc.
+ */
+static boolean
+create_common_immediate( struct svga_shader_emitter *emit )
+{
+ unsigned idx = emit->nr_hw_float_const++;
+
+ /* Emit the constant (0, 0.5, -1, 1) and use swizzling to generate
+ * other useful vectors.
+ */
+ if (!emit_def_const( emit, SVGA3D_CONST_TYPE_FLOAT,
+ idx, 0.0f, 0.5f, -1.0f, 1.0f ))
+ return FALSE;
+
+ emit->common_immediate_idx = idx;
+ emit->created_common_immediate = TRUE;
+
+ return TRUE;
+}
+
+
+/**
+ * Return swizzle/position for the given value in the "common" immediate.
+ */
+static inline unsigned
+common_immediate_swizzle(float value)
+{
+ if (value == 0.0f)
+ return TGSI_SWIZZLE_X;
+ else if (value == 0.5f)
+ return TGSI_SWIZZLE_Y;
+ else if (value == -1.0f)
+ return TGSI_SWIZZLE_Z;
+ else if (value == 1.0f)
+ return TGSI_SWIZZLE_W;
+ else {
+ assert(!"illegal value in common_immediate_swizzle");
+ return TGSI_SWIZZLE_X;
+ }
+}
+
+
+/**
+ * Returns an immediate reg where all the terms are either 0, 1, -1 or 0.5
+ */
+static struct src_register
+get_immediate(struct svga_shader_emitter *emit,
+ float x, float y, float z, float w)
+{
+ unsigned sx = common_immediate_swizzle(x);
+ unsigned sy = common_immediate_swizzle(y);
+ unsigned sz = common_immediate_swizzle(z);
+ unsigned sw = common_immediate_swizzle(w);
+ assert(emit->created_common_immediate);
+ assert(emit->common_immediate_idx >= 0);
+ return swizzle(src_register(SVGA3DREG_CONST, emit->common_immediate_idx),
+ sx, sy, sz, sw);
+}
+
+
+/**
+ * returns {0, 0, 0, 0} immediate
*/
static struct src_register
get_zero_immediate( struct svga_shader_emitter *emit )
{
- assert(emit->created_zero_immediate);
- assert(emit->zero_immediate_idx >= 0);
+ assert(emit->created_common_immediate);
+ assert(emit->common_immediate_idx >= 0);
return swizzle(src_register( SVGA3DREG_CONST,
- emit->zero_immediate_idx),
- 0, 0, 0, 3);
+ emit->common_immediate_idx),
+ 0, 0, 0, 0);
}
/**
- * returns {1, 1, 1, -1} immediate
+ * returns {1, 1, 1, 1} immediate
*/
static struct src_register
-get_pos_neg_one_immediate( struct svga_shader_emitter *emit )
+get_one_immediate( struct svga_shader_emitter *emit )
{
- assert(emit->created_zero_immediate);
- assert(emit->zero_immediate_idx >= 0);
+ assert(emit->created_common_immediate);
+ assert(emit->common_immediate_idx >= 0);
return swizzle(src_register( SVGA3DREG_CONST,
- emit->zero_immediate_idx),
- 3, 3, 3, 2);
+ emit->common_immediate_idx),
+ 3, 3, 3, 3);
}
static struct src_register
get_half_immediate( struct svga_shader_emitter *emit )
{
- assert(emit->created_zero_immediate);
- assert(emit->zero_immediate_idx >= 0);
- return swizzle(src_register(SVGA3DREG_CONST, emit->zero_immediate_idx),
+ assert(emit->created_common_immediate);
+ assert(emit->common_immediate_idx >= 0);
+ return swizzle(src_register(SVGA3DREG_CONST, emit->common_immediate_idx),
1, 1, 1, 1);
}
{
struct src_register src0 =
translate_src_register(emit, &insn->Src[0]);
- struct src_register zero = get_zero_immediate( emit );
+ struct src_register zero = get_zero_immediate(emit);
SVGA3dShaderInstToken if_token = inst_token( SVGA3DOP_IFC );
if_token.control = SVGA3DOPCOMPC_NE;
- zero = scalar(zero, TGSI_SWIZZLE_X);
if (SVGA3dShaderGetRegType(src0.base.value) == SVGA3DREG_CONST) {
/*
src( temp0 ), src( temp1 ) );
}
- zero = get_zero_immediate( emit );
- one = scalar( zero, TGSI_SWIZZLE_W );
- zero = scalar( zero, TGSI_SWIZZLE_X );
+ one = get_one_immediate(emit);
+ zero = get_zero_immediate(emit);
/* CMP TMP0, SRC0, one, zero */
if (!submit_op3( emit, inst_token( SVGA3DOP_CMP ),
const struct tgsi_full_instruction *insn)
{
SVGA3dShaderDestToken temp;
- struct src_register one = scalar( get_zero_immediate( emit ),
- TGSI_SWIZZLE_W );
+ struct src_register one = get_one_immediate(emit);
SVGA3dShaderInstToken inst = inst_token( SVGA3DOP_TEXKILL );
/* texkill doesn't allow negation on the operand so lets move
{
struct src_register one, zero;
/* zero immediate is 0,0,0,1 */
- zero = get_zero_immediate( emit );
- one = scalar( zero, TGSI_SWIZZLE_W );
- zero = scalar( zero, TGSI_SWIZZLE_X );
+ zero = get_zero_immediate(emit);
+ one = get_one_immediate(emit);
return emit_conditional(emit, compare_func, dst, src0, src1, one, zero);
}
translate_src_register(emit, &insn->Src[2] );
if (emit->unit == PIPE_SHADER_VERTEX) {
- struct src_register zero =
- scalar(get_zero_immediate(emit), TGSI_SWIZZLE_X);
+ struct src_register zero = get_zero_immediate(emit);
/* We used to simulate CMP with SLT+LRP. But that didn't work when
* src1 or src2 was Inf/NaN. In particular, GLSL sqrt(0) failed
* because it involves a CMP to handle the 0 case.
if (emit->dynamic_branching_level > 0 &&
inst.op == SVGA3DOP_TEX &&
SVGA3dShaderGetRegType(texcoord.base.value) == SVGA3DREG_TEMP) {
- struct src_register zero = get_zero_immediate( emit );
+ struct src_register zero = get_zero_immediate(emit);
/* MOV tmp, texcoord */
if (!submit_op1( emit,
if (!submit_op1( emit,
inst_token( SVGA3DOP_MOV ),
writemask( tmp, TGSI_WRITEMASK_W ),
- scalar( zero, TGSI_SWIZZLE_X )))
+ zero ))
return FALSE;
texcoord = src( tmp );
if (!submit_op1(emit,
inst_token(SVGA3DOP_MOV),
writemask(dst, zeroWritemask),
- scalar(get_zero_immediate(emit), TGSI_SWIZZLE_X)))
+ get_zero_immediate(emit)))
return FALSE;
}
if (!submit_op1(emit,
inst_token(SVGA3DOP_MOV),
writemask(dst, oneWritemask),
- scalar(get_zero_immediate(emit), TGSI_SWIZZLE_W)))
+ get_one_immediate(emit)))
return FALSE;
}
}
if (dst.mask & TGSI_WRITEMASK_W) {
- struct src_register one =
- scalar( get_zero_immediate( emit ), TGSI_SWIZZLE_W );
+ struct src_register one = get_one_immediate(emit);
if (!submit_op1( emit, inst_token( SVGA3DOP_MOV ),
writemask( dst2, TGSI_WRITEMASK_W ),
if (emit->dynamic_branching_level > 0 &&
insn->Src[0].Register.File == TGSI_FILE_TEMPORARY)
{
- struct src_register zero = get_zero_immediate( emit );
SVGA3dShaderDestToken dst =
translate_dst_register( emit, insn, 0 );
if (!submit_op1(emit,
inst_token( SVGA3DOP_MOV ),
dst,
- scalar(zero, TGSI_SWIZZLE_X)))
+ get_zero_immediate(emit)))
return FALSE;
return TRUE;
/* Need to emit 1.0 to dst.w?
*/
if (dst.mask & TGSI_WRITEMASK_W) {
- struct src_register zero = get_zero_immediate( emit );
+ struct src_register one = get_one_immediate( emit );
if (!submit_op1(emit,
inst_token( SVGA3DOP_MOV ),
writemask(dst, TGSI_WRITEMASK_W),
- zero))
+ one))
return FALSE;
}
emit, &insn->Src[0] );
const struct src_register src1 = translate_src_register(
emit, &insn->Src[1] );
- struct src_register zero = get_zero_immediate( emit );
boolean need_tmp = FALSE;
if (SVGA3dShaderGetRegType(dst.value) != SVGA3DREG_TEMP ||
if (tmp.mask & TGSI_WRITEMASK_XW) {
if (!submit_op1( emit, inst_token( SVGA3DOP_MOV ),
writemask(tmp, TGSI_WRITEMASK_XW ),
- scalar( zero, 3 )))
+ get_one_immediate(emit)))
return FALSE;
}
SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 );
struct src_register src0 =
translate_src_register( emit, &insn->Src[0] );
- struct src_register zero = get_zero_immediate( emit );
SVGA3dShaderDestToken fraction;
if (dst.mask & TGSI_WRITEMASK_Y)
if (dst.mask & TGSI_WRITEMASK_W) {
if (!submit_op1( emit, inst_token( SVGA3DOP_MOV ),
writemask(dst, TGSI_WRITEMASK_W),
- scalar( zero, TGSI_SWIZZLE_W ) ))
+ get_one_immediate(emit)))
return FALSE;
}
SVGA3dShaderDestToken tmp = get_temp( emit );
const struct src_register src0 = translate_src_register(
emit, &insn->Src[0] );
- struct src_register zero = get_zero_immediate( emit );
/* tmp = pow(src.y, src.w)
*/
/* SETP src0.xxyy, GT, {0}.x */
if (!submit_op2( emit, setp_token, pred_reg,
predsrc,
- swizzle(zero, 0, 0, 0, 0) ))
+ get_zero_immediate(emit)))
return FALSE;
/* MOV dst, fail */
if (!submit_op1( emit, inst_token( SVGA3DOP_MOV ), dst,
- swizzle(zero, 3, 0, 0, 3 )))
+ get_immediate(emit, 1.0f, 0.0f, 0.0f, 1.0f)))
return FALSE;
/* MOV dst.yz, tmp (predicated)
SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 );
struct src_register src0 =
translate_src_register( emit, &insn->Src[0] );
- struct src_register zero = get_zero_immediate( emit );
SVGA3dShaderDestToken abs_tmp;
struct src_register abs_src0;
SVGA3dShaderDestToken log2_abs;
if (dst.mask & TGSI_WRITEMASK_W) {
if (!submit_op1( emit, inst_token( SVGA3DOP_MOV ),
writemask(dst, TGSI_WRITEMASK_W),
- scalar( zero, TGSI_SWIZZLE_W ) ))
+ get_one_immediate(emit)))
return FALSE;
}
*/
if (emit->unit == PIPE_SHADER_FRAGMENT &&
emit->key.fkey.white_fragments) {
- struct src_register one = scalar( get_zero_immediate( emit ),
- TGSI_SWIZZLE_W );
+ struct src_register one = get_one_immediate(emit);
if (!submit_op1( emit,
inst_token(SVGA3DOP_MOV),
return TRUE;
vface = get_vface( emit );
- zero = get_zero_immediate( emit );
+ zero = get_zero_immediate(emit);
/* Can't use get_temp() to allocate the color reg as such
* temporaries will be reclaimed after each instruction by the call
else
if_token.control = SVGA3DOPCOMP_GT;
- zero = scalar(zero, TGSI_SWIZZLE_X);
-
if (!(emit_instruction( emit, if_token ) &&
emit_src( emit, vface ) &&
emit_src( emit, zero ) ))
static boolean
emit_frontface(struct svga_shader_emitter *emit)
{
- struct src_register vface, zero;
+ struct src_register vface;
SVGA3dShaderDestToken temp;
struct src_register pass, fail;
vface = get_vface( emit );
- zero = get_zero_immediate( emit );
/* Can't use get_temp() to allocate the fake frontface reg as such
* temporaries will be reclaimed after each instruction by the call
emit->nr_hw_temp++ );
if (emit->key.fkey.front_ccw) {
- pass = scalar( zero, TGSI_SWIZZLE_X );
- fail = scalar( zero, TGSI_SWIZZLE_W );
+ pass = get_zero_immediate(emit);
+ fail = get_one_immediate(emit);
} else {
- pass = scalar( zero, TGSI_SWIZZLE_W );
- fail = scalar( zero, TGSI_SWIZZLE_X );
+ pass = get_one_immediate(emit);
+ fail = get_zero_immediate(emit);
}
if (!emit_conditional(emit, PIPE_FUNC_GREATER,
- temp, vface, scalar( zero, TGSI_SWIZZLE_X ),
+ temp, vface, get_zero_immediate(emit),
pass, fail))
return FALSE;
static boolean
emit_inverted_texcoords(struct svga_shader_emitter *emit)
{
- struct src_register zero = get_zero_immediate(emit);
- struct src_register pos_neg_one = get_pos_neg_one_immediate( emit );
unsigned inverted_texcoords = emit->inverted_texcoords;
while (inverted_texcoords) {
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) */
- swizzle(zero, 0, 3, 0, 0))) /* (0, 1, 0, 0) */
+ get_immediate(emit, 1.0f, -1.0f, 1.0f, 1.0f),
+ get_immediate(emit, 0.0f, 1.0f, 0.0f, 0.0f)))
return FALSE;
/* Reassign the input_map entry to the new texcoord register */
/**
- * Determine if we need to emit an immediate value with zeros.
+ * Determine if we need to create the "common" immediate value which is
+ * used for generating useful vector constants such as {0,0,0,0} and
+ * {1,1,1,1}.
* We could just do this all the time except that we want to conserve
* registers whenever possible.
*/
static boolean
-needs_to_create_zero(const struct svga_shader_emitter *emit)
+needs_to_create_common_immediate(const struct svga_shader_emitter *emit)
{
unsigned i;
static boolean
svga_shader_emit_helpers(struct svga_shader_emitter *emit)
{
- if (needs_to_create_zero( emit )) {
- create_zero_immediate( emit );
+ if (needs_to_create_common_immediate( emit )) {
+ create_common_immediate( emit );
}
if (needs_to_create_loop_const( emit )) {
create_loop_const( emit );