From 7780b50b7e7c29fef4065c1b3ba7f63edeed3028 Mon Sep 17 00:00:00 2001 From: Gert Wollny Date: Thu, 27 Feb 2020 08:10:36 +0100 Subject: [PATCH] r600/sfn: Avoid using dynamic_cast to identify type v2: Fix typo (maurossi) Related: #2566 Signed-off-by: Gert Wollny Tested-by: Mauro Rossi Part-of: --- src/gallium/drivers/r600/sfn/sfn_shaderio.cpp | 47 ++++++++++++------- src/gallium/drivers/r600/sfn/sfn_shaderio.h | 4 ++ 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(a.get()); - assert(v); - if (v->sid() == sid && (v->location_frac() == frac)) + assert(a->is_varying()); + auto& v = static_cast(*a); + if (v.sid() == sid && (v.location_frac() == frac)) return a; } } @@ -298,8 +308,7 @@ void ShaderIO::sort_varying_inputs() vector idx; for (auto i = 0u; i < m_inputs.size(); ++i) { - ShaderInputVarying *vi = dynamic_cast(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(i.get()); - if (!v) + if (!i->is_varying()) continue; + + auto& v = static_cast(*i); /* There are shaders that miss an input ...*/ - if (m_ldspos.size() <= static_cast(v->location())) - m_ldspos.resize(v->location() + 1); + if (m_ldspos.size() <= static_cast(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(i.get()); - if (!v) + if (!i->is_varying()) continue; - if (m_ldspos[v->location()] < 0) { + auto& v = static_cast(*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(i.get()); - if (v && v->location() == driver_loc && v->location_frac() == frac) - return *v; + if (!i->is_varying()) + continue; + + auto& v = static_cast(*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(); -- 2.30.2