llvmpipe: add compute debug option
[mesa.git] / src / gallium / drivers / r300 / compiler / radeon_compiler_util.c
index 2742721f80015ea25031e8d8f9c355505c6cedad..b609d9fae3c9b1a7de569796878476b7713ad335 100644 (file)
@@ -211,8 +211,8 @@ static void normal_rewrite_writemask_cb(
        struct rc_instruction * inst,
        struct rc_src_register * src)
 {
-       unsigned int * new_mask = (unsigned int *)userdata;
-       src->Swizzle = rc_adjust_channels(src->Swizzle, *new_mask);
+       unsigned int * conversion_swizzle = (unsigned int *)userdata;
+       src->Swizzle = rc_adjust_channels(src->Swizzle, *conversion_swizzle);
 }
 
 /**
@@ -223,7 +223,6 @@ void rc_normal_rewrite_writemask(
        struct rc_instruction * inst,
        unsigned int conversion_swizzle)
 {
-       unsigned int new_mask;
        struct rc_sub_instruction * sub = &inst->U.I;
        const struct rc_opcode_info * info = rc_get_opcode_info(sub->Opcode);
        sub->DstReg.WriteMask =
@@ -244,8 +243,8 @@ void rc_normal_rewrite_writemask(
                return;
        }
 
-       new_mask = sub->DstReg.WriteMask;
-       rc_for_all_reads_src(inst, normal_rewrite_writemask_cb, &new_mask);
+       rc_for_all_reads_src(inst, normal_rewrite_writemask_cb,
+                                                       &conversion_swizzle);
 }
 
 /**
@@ -699,3 +698,56 @@ unsigned int rc_make_conversion_swizzle(
        }
        return conversion_swizzle;
 }
+
+/**
+ * @return 1 if the register contains an immediate value, 0 otherwise.
+ */
+unsigned int rc_src_reg_is_immediate(
+       struct radeon_compiler * c,
+       unsigned int file,
+       unsigned int index)
+{
+       return file == RC_FILE_CONSTANT &&
+       c->Program.Constants.Constants[index].Type == RC_CONSTANT_IMMEDIATE;
+}
+
+/**
+ * @return The immediate value in the specified register.
+ */
+float rc_get_constant_value(
+       struct radeon_compiler * c,
+       unsigned int index,
+       unsigned int swizzle,
+       unsigned int negate,
+       unsigned int chan)
+{
+       float base = 1.0f;
+       int swz = GET_SWZ(swizzle, chan);
+       if(swz >= 4 || index >= c->Program.Constants.Count ){
+               rc_error(c, "get_constant_value: Can't find a value.\n");
+               return 0.0f;
+       }
+       if(GET_BIT(negate, chan)){
+               base = -1.0f;
+       }
+       return base *
+               c->Program.Constants.Constants[index].u.Immediate[swz];
+}
+
+/**
+ * This function returns the component value (RC_SWIZZLE_*) of the first used
+ * channel in the swizzle.  This is only useful for scalar instructions that are
+ * known to use only one channel of the swizzle.
+ */
+unsigned int rc_get_scalar_src_swz(unsigned int swizzle)
+{
+       unsigned int swz, chan;
+       for (chan = 0; chan < 4; chan++) {
+               swz = GET_SWZ(swizzle, chan);
+               if (swz != RC_SWIZZLE_UNUSED) {
+                       break;
+               }
+       }
+       assert(swz != RC_SWIZZLE_UNUSED);
+       return swz;
+}