summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Stellard <tstellar@gmail.com>2011-02-19 23:37:05 -0800
committerTom Stellard <tstellar@gmail.com>2011-02-19 23:37:05 -0800
commit26a3a6c58430001b4011b6fe05b391eae7d33d1c (patch)
tree6da020fb2a78b1bc155f80496d826beba06c2fe6
parentdb6f8fbf67a32d42e557ed978d7da0f1ab462d42 (diff)
Temp it works a little bit.regalloc-wip-2
-rw-r--r--src/mesa/drivers/dri/r300/compiler/radeon_compiler_util.c42
-rw-r--r--src/mesa/drivers/dri/r300/compiler/radeon_compiler_util.h1
-rw-r--r--src/mesa/drivers/dri/r300/compiler/radeon_variable.c131
-rw-r--r--src/mesa/drivers/dri/r300/compiler/radeon_variable.h2
4 files changed, 117 insertions, 59 deletions
diff --git a/src/mesa/drivers/dri/r300/compiler/radeon_compiler_util.c b/src/mesa/drivers/dri/r300/compiler/radeon_compiler_util.c
index 559ef1070ff..a8ff7dcc9c5 100644
--- a/src/mesa/drivers/dri/r300/compiler/radeon_compiler_util.c
+++ b/src/mesa/drivers/dri/r300/compiler/radeon_compiler_util.c
@@ -259,35 +259,25 @@ unsigned int rc_normal_rewrite_writemask(
unsigned int rc_rewrite_swizzle(
unsigned int swizzle,
- unsigned int old_mask,
- unsigned int new_mask)
+ unsigned int conversion_swizzle)
{
- unsigned int old_index;
- unsigned int new_index = 0;
+ unsigned int chan;
unsigned int out_swizzle = swizzle;
- /*XXX If writemasks are the same do nothing */
- fprintf(stderr, "Rewriting swizzle 0x%x, oldmask=%u new_mask=%u\n",
- swizzle, old_mask, new_mask);
- for (old_index = 0; old_index < 4; old_index++) {
- unsigned int i;
- if (!GET_BIT(old_mask, old_index)) {
- continue;
- }
- for ( ; new_index < 4; new_index++) {
- if (GET_BIT(new_mask, new_index)) {
- break;
- }
- }
- /*XXX Use rc_replace swizzle here. */
- fprintf(stderr, "Going to replace %u with %u in the swizzle\n", old_index, new_index);
- for (i = 0; i < 4; i++) {
- if (GET_SWZ(swizzle, i) == old_index) {
- fprintf(stderr, "Setting swizzle at chan %u = %u\n", i, new_index);
- SET_SWZ(out_swizzle, i, new_index);
+ fprintf(stderr, "Rewriting swizzle with conversion %x\n", conversion_swizzle);
+ for (chan = 0; chan < 4; chan++) {
+ unsigned int swz = GET_SWZ(swizzle, chan);
+ unsigned int new_swz;
+ if (swz > 3) {
+ SET_SWZ(out_swizzle, chan, swz);
+ } else {
+ new_swz = GET_SWZ(conversion_swizzle, swz);
+ if (new_swz != RC_SWIZZLE_UNUSED) {
+ SET_SWZ(out_swizzle, chan, new_swz);
+ } else {
+ SET_SWZ(out_swizzle, chan, swz);
}
}
- new_index++;
}
return out_swizzle;
}
@@ -502,10 +492,14 @@ static unsigned int can_remove_src(
unsigned int rm_chan, check_chan;
for (rm_chan = 0; rm_chan < 4; rm_chan++) {
unsigned int swz = GET_SWZ(swizzle, rm_chan);
+ fprintf(stderr, "swz=%u\n", swz);
if (swz > 3)
continue;
unsigned int match = 0;
+ fprintf(stderr, "LOoking for a match in %u\n", sub->Arg[i].Swizzle);
for (check_chan = 0; check_chan < 4; check_chan++) {
+ fprintf(stderr, "Checking swz %u\n",
+ GET_SWZ(sub->Arg[i].Swizzle, check_chan));
if (swz == GET_SWZ(sub->Arg[i].Swizzle,
check_chan)) {
match = 1;
diff --git a/src/mesa/drivers/dri/r300/compiler/radeon_compiler_util.h b/src/mesa/drivers/dri/r300/compiler/radeon_compiler_util.h
index a3e04a5c788..4b97b654a14 100644
--- a/src/mesa/drivers/dri/r300/compiler/radeon_compiler_util.h
+++ b/src/mesa/drivers/dri/r300/compiler/radeon_compiler_util.h
@@ -40,7 +40,6 @@ unsigned int rc_normal_rewrite_writemask(
unsigned int rc_rewrite_swizzle(
unsigned int swizzle,
- unsigned int old_mask,
unsigned int new_mask);
struct rc_src_register lmul_swizzle(unsigned int swizzle, struct rc_src_register srcreg);
diff --git a/src/mesa/drivers/dri/r300/compiler/radeon_variable.c b/src/mesa/drivers/dri/r300/compiler/radeon_variable.c
index 831ee224f03..97be9e2c901 100644
--- a/src/mesa/drivers/dri/r300/compiler/radeon_variable.c
+++ b/src/mesa/drivers/dri/r300/compiler/radeon_variable.c
@@ -39,47 +39,71 @@ void rc_variable_change_dst(
unsigned int new_index,
unsigned int new_writemask)
{
- for ( ; var; var = var->Friend) {
- unsigned int old_mask = var->Dst.WriteMask;
+ unsigned int i, j;
+ unsigned int conversion_swizzle = rc_init_swizzle(RC_SWIZZLE_UNUSED, 0);
+ /* XXX Figure out what to do with these two. */
+ unsigned int remaining_writemask = new_writemask;
+ unsigned int rem_mask = new_writemask;
+ unsigned int unused_mask = 0;
+ unsigned int used_mask;
+ struct rc_variable * var_ptr;
+ struct rc_list * readers;
+ for (var_ptr = var; var_ptr; var_ptr = var_ptr->Friend) {
+ unsigned int old_mask = var_ptr->Dst.WriteMask;
unsigned int unused_mask;
- unsigned int new_writemask_friend;
- unsigned int rindex;
- if (var->Inst->Type == RC_INSTRUCTION_NORMAL) {
+ if (var_ptr->Inst->Type == RC_INSTRUCTION_NORMAL) {
unused_mask = rc_normal_rewrite_writemask(
- var->Inst, new_writemask);
- var->Inst->U.I.DstReg.Index = new_index;
+ var_ptr->Inst, rem_mask);
+ used_mask = var_ptr->Inst->U.I.DstReg.WriteMask;
+ var_ptr->Inst->U.I.DstReg.Index = new_index;
} else {
struct rc_pair_sub_instruction * sub;
- if (var->Dst.WriteMask == RC_MASK_W) {
+ if (var_ptr->Dst.WriteMask == RC_MASK_W) {
assert(new_writemask & RC_MASK_W);
- sub = &var->Inst->U.P.Alpha;
+ sub = &var_ptr->Inst->U.P.Alpha;
unused_mask = new_writemask & ~RC_MASK_W;
} else {
- sub = &var->Inst->U.P.RGB;
+ sub = &var_ptr->Inst->U.P.RGB;
unused_mask = rc_pair_rewrite_writemask(sub,
- new_writemask);
+ rem_mask);
}
sub->DestIndex = new_index;
+ used_mask = sub->WriteMask;
+ fprintf(stderr, "Unused mask = %u rem = %u\n", unused_mask, rem_mask);
+ rem_mask &= unused_mask;
}
- new_writemask_friend = new_writemask & ~unused_mask;
- new_writemask = unused_mask;
- fprintf(stderr, "Chaning DST friend=%u global=%u unused=%u new_index=%u\n",
- new_writemask_friend, new_writemask, unused_mask, new_index);
- for (rindex = 0; rindex < var->ReaderCount; rindex++) {
- struct rc_reader reader = var->Readers[rindex];
- fprintf(stderr, "Changing the swizzle for reader %u\n", rindex);
- if (reader.Inst->Type == RC_INSTRUCTION_NORMAL) {
- reader.U.Src->Index = new_index;
- reader.U.Src->Swizzle = rc_rewrite_swizzle(
- reader.U.Src->Swizzle, old_mask,
- new_writemask_friend);
+ fprintf(stderr, "usedmask=%u\n", used_mask);
+ for (i = 0; i < 4; i++) {
+ if (old_mask & (1 << i)) {
+ for (j = 0; j < 4; j++) {
+ fprintf(stderr, "Setting conversion for %u\n", i);
+ if (GET_BIT(remaining_writemask, j)) {
+ fprintf(stderr, "Found %u\n", j);
+ SET_SWZ(conversion_swizzle, i, j);
+ remaining_writemask &= ~(1 << j);
+ break;
+ }
+ }
+ }
+ }
+ }
+ readers = rc_variable_readers_union(var);
+ fprintf(stderr, "Changing DST global=%u unused=%u new_index=%u\n",
+ new_writemask, unused_mask, new_index);
+
+ for ( ; readers; readers = readers->Next) {
+ struct rc_reader * reader = readers->Item;
+ if (reader->Inst->Type == RC_INSTRUCTION_NORMAL) {
+ reader->U.Src->Index = new_index;
+ reader->U.Src->Swizzle = rc_rewrite_swizzle(
+ reader->U.Src->Swizzle, conversion_swizzle);
} else {
unsigned int is_rgb = 0, is_alpha = 0;
unsigned int src_type = rc_source_type_swz(
- reader.U.Arg->Swizzle);
- if (!rc_pair_remove_src(reader.Inst,
- reader.U.Arg->Source, reader.U.Arg->Swizzle)){
+ reader->U.Arg->Swizzle);
+ if (!rc_pair_remove_src(reader->Inst,
+ reader->U.Arg->Source, reader->U.Arg->Swizzle)){
/* XXX: Error here */
fprintf(stderr, "No room for remapped souce.\n");
return;
@@ -87,8 +111,8 @@ void rc_variable_change_dst(
/* XXX: Ugly rewrite please */
if (src_type & RC_SOURCE_RGB) {
struct rc_pair_instruction_source * src =
- &reader.Inst->U.P.RGB.Src
- [reader.U.Arg->Source];
+ &reader->Inst->U.P.RGB.Src
+ [reader->U.Arg->Source];
src->Used = 1;
src->File = RC_FILE_TEMPORARY;
src->Index = new_index;
@@ -97,8 +121,8 @@ void rc_variable_change_dst(
}
if (src_type & RC_SOURCE_ALPHA) {
struct rc_pair_instruction_source * src =
- &reader.Inst->U.P.Alpha.Src
- [reader.U.Arg->Source];
+ &reader->Inst->U.P.Alpha.Src
+ [reader->U.Arg->Source];
src->Used = 1;
src->File = RC_FILE_TEMPORARY;
src->Index = new_index;
@@ -114,13 +138,11 @@ void rc_variable_change_dst(
// fprintf(stderr, "Can't allocate source.\n");
// return;
// }
- reader.U.Arg->Swizzle = rc_rewrite_swizzle(
- reader.U.Arg->Swizzle, old_mask,
- new_writemask_friend);
+ reader->U.Arg->Swizzle = rc_rewrite_swizzle(
+ reader->U.Arg->Swizzle, conversion_swizzle);
// reader.U.Arg->Source = new_src_index;
}
}
- }
}
void rc_variable_compute_live_intervals(struct rc_variable * var)
@@ -320,6 +342,47 @@ unsigned int rc_variable_writemask_sum(struct rc_variable * var)
return writemask;
}
+struct rc_list * rc_variable_readers_union(struct rc_variable * var)
+{
+ struct rc_list * list = NULL;
+ fprintf(stderr, "readers union\n");
+ while (var) {
+ unsigned int i;
+ fprintf(stderr, "count=%u\n", var->ReaderCount);
+ for (i = 0; i < var->ReaderCount; i++) {
+ struct rc_list * temp;
+ struct rc_reader * a = &var->Readers[i];
+ unsigned int match = 0;
+ for (temp = list; temp; temp = temp->Next) {
+ struct rc_reader * b = temp->Item;
+ if (a->Inst->Type != b->Inst->Type) {
+ continue;
+ }
+ if (a->Inst->Type == RC_INSTRUCTION_NORMAL) {
+ if (a->U.Src == b->U.Src) {
+ match = 1;
+ break;
+ }
+ }
+ if (a->Inst->Type == RC_INSTRUCTION_PAIR) {
+ if (a->U.Arg == b->U.Arg) {
+ match = 1;
+ break;
+ }
+ }
+ }
+ if (match) {
+ fprintf(stderr, "Match found\n");
+ continue;
+ }
+ fprintf(stderr, "Adding\n");
+ rc_list_add(&list, rc_list(&var->C->Pool, a));
+ }
+ var = var->Friend;
+ }
+ return list;
+}
+
void rc_variable_print(struct rc_variable * var)
{
unsigned int i;
diff --git a/src/mesa/drivers/dri/r300/compiler/radeon_variable.h b/src/mesa/drivers/dri/r300/compiler/radeon_variable.h
index ca38ec621f8..1944b59b796 100644
--- a/src/mesa/drivers/dri/r300/compiler/radeon_variable.h
+++ b/src/mesa/drivers/dri/r300/compiler/radeon_variable.h
@@ -82,6 +82,8 @@ struct rc_list * rc_get_variables(struct radeon_compiler * c);
unsigned int rc_variable_writemask_sum(struct rc_variable * var);
+struct rc_list * rc_variable_readers_union(struct rc_variable * var);
+
void rc_variable_print(struct rc_variable * var);
#endif /* RADEON_VARIABLE_H */