[Mesa-dev] [PATCH 1/4] r600g/sb: fix allocation of indirectly addressed input arrays

Vadim Girlin vadimgirlin at gmail.com
Thu May 2 08:46:55 PDT 2013


Some inputs may be preloaded into predefined GPRs,
so we can't reallocate arrays with such inputs.

Fixes issues with webgl demo: http://oos.moxiecode.com/js_webgl/snake/

Signed-off-by: Vadim Girlin <vadimgirlin at gmail.com>
---
 src/gallium/drivers/r600/sb/sb_ra_coalesce.cpp | 14 +++++++++-----
 src/gallium/drivers/r600/sb/sb_ra_init.cpp     |  6 ++++++
 src/gallium/drivers/r600/sb/sb_shader.cpp      | 13 +++++++++----
 src/gallium/drivers/r600/sb/sb_shader.h        |  2 +-
 4 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/src/gallium/drivers/r600/sb/sb_ra_coalesce.cpp b/src/gallium/drivers/r600/sb/sb_ra_coalesce.cpp
index cec4bbc..25c46f7 100644
--- a/src/gallium/drivers/r600/sb/sb_ra_coalesce.cpp
+++ b/src/gallium/drivers/r600/sb/sb_ra_coalesce.cpp
@@ -345,13 +345,17 @@ void coalescer::init_reg_bitset(sb_bitset &bs, val_set &vs) {
 	for (val_set::iterator I = vs.begin(sh), E = vs.end(sh); I != E; ++I) {
 		value *v = *I;
 
-		if (!v->is_sgpr())
+		if (!v->is_any_gpr())
 			continue;
 
-		if (v->gpr) {
-			if (v->gpr >= bs.size())
-				bs.resize(v->gpr + 64);
-			bs.set(v->gpr, 1);
+		unsigned gpr = v->get_final_gpr();
+		if (!gpr)
+			continue;
+
+		if (gpr) {
+			if (gpr >= bs.size())
+				bs.resize(gpr + 64);
+			bs.set(gpr, 1);
 		}
 	}
 }
diff --git a/src/gallium/drivers/r600/sb/sb_ra_init.cpp b/src/gallium/drivers/r600/sb/sb_ra_init.cpp
index 0447f29..99ff6ff 100644
--- a/src/gallium/drivers/r600/sb/sb_ra_init.cpp
+++ b/src/gallium/drivers/r600/sb/sb_ra_init.cpp
@@ -244,6 +244,12 @@ void ra_init::alloc_arrays() {
 			cerr << "\n";
 		);
 
+		// skip preallocated arrays (e.g. with preloaded inputs)
+		if (a->gpr) {
+			RA_DUMP( cerr << "   FIXED at " << a->gpr << "\n"; );
+			continue;
+		}
+
 		bool dead = a->is_dead();
 
 		if (dead) {
diff --git a/src/gallium/drivers/r600/sb/sb_shader.cpp b/src/gallium/drivers/r600/sb/sb_shader.cpp
index 6dd3678..3fd6ea4 100644
--- a/src/gallium/drivers/r600/sb/sb_shader.cpp
+++ b/src/gallium/drivers/r600/sb/sb_shader.cpp
@@ -61,7 +61,7 @@ bool shader::assign_slot(alu_node* n, alu_node *slots[5]) {
 	return true;
 }
 
-void shader::add_gpr_values(vvec& vec, unsigned gpr, unsigned comp_mask,
+void shader::add_pinned_gpr_values(vvec& vec, unsigned gpr, unsigned comp_mask,
                             bool src) {
 	unsigned chan = 0;
 	while (comp_mask) {
@@ -72,6 +72,11 @@ void shader::add_gpr_values(vvec& vec, unsigned gpr, unsigned comp_mask,
 				v->gpr = v->pin_gpr = v->select;
 				v->fix();
 			}
+			if (v->array && !v->array->gpr) {
+				// if pinned value can be accessed with indirect addressing
+				// pin the entire array to its original location
+				v->array->gpr = v->array->base_gpr;
+			}
 			vec.push_back(v);
 		}
 		comp_mask >>= 1;
@@ -199,7 +204,7 @@ void shader::add_input(unsigned gpr, bool preloaded, unsigned comp_mask) {
 	i.comp_mask = comp_mask;
 
 	if (preloaded) {
-		add_gpr_values(root->dst, gpr, comp_mask, true);
+		add_pinned_gpr_values(root->dst, gpr, comp_mask, true);
 	}
 
 }
@@ -217,9 +222,9 @@ void shader::init_call_fs(cf_node* cf) {
 	for(inputs_vec::const_iterator I = inputs.begin(),
 			E = inputs.end(); I != E; ++I, ++gpr) {
 		if (!I->preloaded)
-			add_gpr_values(cf->dst, gpr, I->comp_mask, false);
+			add_pinned_gpr_values(cf->dst, gpr, I->comp_mask, false);
 		else
-			add_gpr_values(cf->src, gpr, I->comp_mask, true);
+			add_pinned_gpr_values(cf->src, gpr, I->comp_mask, true);
 	}
 }
 
diff --git a/src/gallium/drivers/r600/sb/sb_shader.h b/src/gallium/drivers/r600/sb/sb_shader.h
index aa71d54..b2e3837 100644
--- a/src/gallium/drivers/r600/sb/sb_shader.h
+++ b/src/gallium/drivers/r600/sb/sb_shader.h
@@ -315,7 +315,7 @@ public:
 	value* get_value_version(value* v, unsigned ver);
 
 	void init();
-	void add_gpr_values(vvec& vec, unsigned gpr, unsigned comp_mask, bool src);
+	void add_pinned_gpr_values(vvec& vec, unsigned gpr, unsigned comp_mask, bool src);
 
 	void dump_ir();
 
-- 
1.8.2.1



More information about the mesa-dev mailing list