Move GenericValue into SpirvShader GenericValue is only used by SpirvShader so move it as a private inner class of SpirvShader. Part of the foundations of much larger refactoring required for function inlining in SpirvShader. Bug: b/133213304 Change-Id: I75484c3d036b82f3bc6a735034a7c1b04f05f600 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/33350 Reviewed-by: Nicolas Capens <nicolascapens@google.com> Tested-by: Ben Clayton <bclayton@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
diff --git a/src/Pipeline/SpirvShader.cpp b/src/Pipeline/SpirvShader.cpp index 75fe463..266bf40 100644 --- a/src/Pipeline/SpirvShader.cpp +++ b/src/Pipeline/SpirvShader.cpp
@@ -6458,6 +6458,11 @@ } } + SpirvShader::GenericValue::GenericValue(SpirvShader const *shader, SpirvRoutine const *routine, SpirvShader::Object::ID objId) : + obj(shader->getObject(objId)), + intermediate(obj.kind == SpirvShader::Object::Kind::Intermediate ? &routine->getIntermediate(objId) : nullptr), + type(obj.type) {} + SpirvRoutine::SpirvRoutine(vk::PipelineLayout const *pipelineLayout) : pipelineLayout(pipelineLayout) {
diff --git a/src/Pipeline/SpirvShader.hpp b/src/Pipeline/SpirvShader.hpp index 67a3f62..342ad13 100644 --- a/src/Pipeline/SpirvShader.hpp +++ b/src/Pipeline/SpirvShader.hpp
@@ -54,7 +54,6 @@ { // Forward declarations. class SpirvRoutine; - class GenericValue; // SIMD contains types that represent multiple scalars packed into a single // vector data type. Types in the SIMD namespace provide a semantic hint @@ -989,6 +988,41 @@ Terminator, // Reached a termination instruction. }; + // Generic wrapper over either per-lane intermediate value, or a constant. + // Constants are transparently widened to per-lane values in operator[]. + // This is appropriate in most cases -- if we're not going to do something + // significantly different based on whether the value is uniform across lanes. + class GenericValue + { + SpirvShader::Object const &obj; + Intermediate const *intermediate; + + public: + GenericValue(SpirvShader const *shader, SpirvRoutine const *routine, SpirvShader::Object::ID objId); + + RValue<SIMD::Float> Float(uint32_t i) const + { + if (intermediate != nullptr) + { + return intermediate->Float(i); + } + auto constantValue = reinterpret_cast<float *>(obj.constantValue.get()); + return RValue<SIMD::Float>(constantValue[i]); + } + + RValue<SIMD::Int> Int(uint32_t i) const + { + return As<SIMD::Int>(Float(i)); + } + + RValue<SIMD::UInt> UInt(uint32_t i) const + { + return As<SIMD::UInt>(Float(i)); + } + + SpirvShader::Type::ID const type; + }; + // existsPath returns true if there's a direct or indirect flow from // the 'from' block to the 'to' block that does not pass through // notPassingThrough. @@ -1153,10 +1187,9 @@ private: // The fields and accessors below are only accessible to SpirvShader - // and GenericValue as they are only used and exist between calls to + // as they are only used and exist between calls to // SpirvShader::emitProlog() and SpirvShader::emitEpilog(). friend class SpirvShader; - friend class GenericValue; std::unordered_map<SpirvShader::Object::ID, Intermediate> intermediates; std::unordered_map<SpirvShader::Object::ID, SIMD::Pointer> pointers; @@ -1192,45 +1225,6 @@ } }; - class GenericValue - { - // Generic wrapper over either per-lane intermediate value, or a constant. - // Constants are transparently widened to per-lane values in operator[]. - // This is appropriate in most cases -- if we're not going to do something - // significantly different based on whether the value is uniform across lanes. - - SpirvShader::Object const &obj; - Intermediate const *intermediate; - - public: - GenericValue(SpirvShader const *shader, SpirvRoutine const *routine, SpirvShader::Object::ID objId) : - obj(shader->getObject(objId)), - intermediate(obj.kind == SpirvShader::Object::Kind::Intermediate ? &routine->getIntermediate(objId) : nullptr), - type(obj.type) {} - - RValue<SIMD::Float> Float(uint32_t i) const - { - if (intermediate != nullptr) - { - return intermediate->Float(i); - } - auto constantValue = reinterpret_cast<float *>(obj.constantValue.get()); - return RValue<SIMD::Float>(constantValue[i]); - } - - RValue<SIMD::Int> Int(uint32_t i) const - { - return As<SIMD::Int>(Float(i)); - } - - RValue<SIMD::UInt> UInt(uint32_t i) const - { - return As<SIMD::UInt>(Float(i)); - } - - SpirvShader::Type::ID const type; - }; - } #endif // sw_SpirvShader_hpp