Commit 59cd59b9 by Ben Clayton

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/+/33350Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Tested-by: 's avatarBen Clayton <bclayton@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
parent 1d4f5775
...@@ -6458,6 +6458,11 @@ namespace sw ...@@ -6458,6 +6458,11 @@ namespace sw
} }
} }
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) : SpirvRoutine::SpirvRoutine(vk::PipelineLayout const *pipelineLayout) :
pipelineLayout(pipelineLayout) pipelineLayout(pipelineLayout)
{ {
......
...@@ -54,7 +54,6 @@ namespace sw ...@@ -54,7 +54,6 @@ namespace sw
{ {
// Forward declarations. // Forward declarations.
class SpirvRoutine; class SpirvRoutine;
class GenericValue;
// SIMD contains types that represent multiple scalars packed into a single // SIMD contains types that represent multiple scalars packed into a single
// vector data type. Types in the SIMD namespace provide a semantic hint // vector data type. Types in the SIMD namespace provide a semantic hint
...@@ -989,6 +988,41 @@ namespace sw ...@@ -989,6 +988,41 @@ namespace sw
Terminator, // Reached a termination instruction. 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 // existsPath returns true if there's a direct or indirect flow from
// the 'from' block to the 'to' block that does not pass through // the 'from' block to the 'to' block that does not pass through
// notPassingThrough. // notPassingThrough.
...@@ -1153,10 +1187,9 @@ namespace sw ...@@ -1153,10 +1187,9 @@ namespace sw
private: private:
// The fields and accessors below are only accessible to SpirvShader // 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(). // SpirvShader::emitProlog() and SpirvShader::emitEpilog().
friend class SpirvShader; friend class SpirvShader;
friend class GenericValue;
std::unordered_map<SpirvShader::Object::ID, Intermediate> intermediates; std::unordered_map<SpirvShader::Object::ID, Intermediate> intermediates;
std::unordered_map<SpirvShader::Object::ID, SIMD::Pointer> pointers; std::unordered_map<SpirvShader::Object::ID, SIMD::Pointer> pointers;
...@@ -1192,45 +1225,6 @@ namespace sw ...@@ -1192,45 +1225,6 @@ namespace sw
} }
}; };
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 #endif // sw_SpirvShader_hpp
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment