aboutsummaryrefslogtreecommitdiffstats
path: root/src/gallium
diff options
context:
space:
mode:
authorGert Wollny <[email protected]>2020-02-27 08:10:36 +0100
committerGert Wollny <[email protected]>2020-03-02 20:00:14 +0100
commit7780b50b7e7c29fef4065c1b3ba7f63edeed3028 (patch)
tree7ad61a5fbecd0d082538c11d9d0764b218a946b3 /src/gallium
parent3503cb4c28e01b34f3a25546c058150709c22348 (diff)
r600/sfn: Avoid using dynamic_cast to identify type
v2: Fix typo (maurossi) Related: #2566 Signed-off-by: Gert Wollny <[email protected]> Tested-by: Mauro Rossi <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3974>
Diffstat (limited to 'src/gallium')
-rw-r--r--src/gallium/drivers/r600/sfn/sfn_shaderio.cpp47
-rw-r--r--src/gallium/drivers/r600/sfn/sfn_shaderio.h4
2 files changed, 34 insertions, 17 deletions
diff --git a/src/gallium/drivers/r600/sfn/sfn_shaderio.cpp b/src/gallium/drivers/r600/sfn/sfn_shaderio.cpp
index 46aaf15e655..5526ab447c5 100644
--- a/src/gallium/drivers/r600/sfn/sfn_shaderio.cpp
+++ b/src/gallium/drivers/r600/sfn/sfn_shaderio.cpp
@@ -72,6 +72,11 @@ int ShaderInput::lds_pos() const
return 0;
}
+bool ShaderInput::is_varying() const
+{
+ return false;
+}
+
void ShaderInput::set_uses_interpolate_at_centroid()
{
m_uses_interpolate_at_centroid = true;
@@ -170,6 +175,11 @@ ShaderInputVarying::ShaderInputVarying(tgsi_semantic _name, int sid, nir_variabl
<< "\n";
}
+bool ShaderInputVarying::is_varying() const
+{
+ return true;
+}
+
void ShaderInputVarying::update_mask(int additional_comps)
{
m_mask |= additional_comps;
@@ -273,9 +283,9 @@ PShaderInput ShaderIO::find_varying(tgsi_semantic name, int sid, int frac)
{
for (auto& a : m_inputs) {
if (a->name() == name) {
- ShaderInputVarying *v = dynamic_cast<ShaderInputVarying *>(a.get());
- assert(v);
- if (v->sid() == sid && (v->location_frac() == frac))
+ assert(a->is_varying());
+ auto& v = static_cast<ShaderInputVarying&>(*a);
+ if (v.sid() == sid && (v.location_frac() == frac))
return a;
}
}
@@ -298,8 +308,7 @@ void ShaderIO::sort_varying_inputs()
vector<int> idx;
for (auto i = 0u; i < m_inputs.size(); ++i) {
- ShaderInputVarying *vi = dynamic_cast<ShaderInputVarying *>(m_inputs[i].get());
- if (vi) {
+ if (m_inputs[i]->is_varying()) {
q.push(m_inputs[i]);
idx.push_back(i);
}
@@ -318,25 +327,26 @@ void ShaderIO::update_lds_pos()
m_lds_pos = -1;
m_ldspos.resize(m_inputs.size());
for (auto& i : m_inputs) {
- ShaderInputVarying *v = dynamic_cast<ShaderInputVarying *>(i.get());
- if (!v)
+ if (!i->is_varying())
continue;
+
+ auto& v = static_cast<ShaderInputVarying&>(*i);
/* There are shaders that miss an input ...*/
- if (m_ldspos.size() <= static_cast<unsigned>(v->location()))
- m_ldspos.resize(v->location() + 1);
+ if (m_ldspos.size() <= static_cast<unsigned>(v.location()))
+ m_ldspos.resize(v.location() + 1);
}
std::fill(m_ldspos.begin(), m_ldspos.end(), -1);
for (auto& i : m_inputs) {
- ShaderInputVarying *v = dynamic_cast<ShaderInputVarying *>(i.get());
- if (!v)
+ if (!i->is_varying())
continue;
- if (m_ldspos[v->location()] < 0) {
+ auto& v = static_cast<ShaderInputVarying&>(*i);
+ if (m_ldspos[v.location()] < 0) {
++m_lds_pos;
- m_ldspos[v->location()] = m_lds_pos;
+ m_ldspos[v.location()] = m_lds_pos;
}
- v->set_lds_pos(m_lds_pos);
+ v.set_lds_pos(m_lds_pos);
}
++m_lds_pos;
}
@@ -355,9 +365,12 @@ ShaderInput& ShaderIO::input(size_t k)
ShaderInput& ShaderIO::input(size_t driver_loc, int frac)
{
for (auto& i: m_inputs) {
- auto v = dynamic_cast<ShaderInputVarying*>(i.get());
- if (v && v->location() == driver_loc && v->location_frac() == frac)
- return *v;
+ if (!i->is_varying())
+ continue;
+
+ auto& v = static_cast<ShaderInputVarying&>(*i);
+ if (v.location() == driver_loc && v.location_frac() == frac)
+ return v;
}
return input(driver_loc);
}
diff --git a/src/gallium/drivers/r600/sfn/sfn_shaderio.h b/src/gallium/drivers/r600/sfn/sfn_shaderio.h
index 41cadfce5a5..3c63d56b706 100644
--- a/src/gallium/drivers/r600/sfn/sfn_shaderio.h
+++ b/src/gallium/drivers/r600/sfn/sfn_shaderio.h
@@ -55,6 +55,8 @@ public:
virtual int lds_pos() const;
void set_uses_interpolate_at_centroid();
+ virtual bool is_varying() const;
+
private:
virtual void set_specific_ioinfo(r600_shader_io& io) const;
@@ -93,6 +95,8 @@ public:
size_t location() const {return m_driver_location;}
int location_frac() const {return m_location_frac;}
+ bool is_varying() const override;
+
private:
void evaluate_spi_sid();