Commit d30b5ac5 by Chris Forbes

Add GenericValue wrapper for either an Intermediate or a constant

This does automatic widening to per-lane so callers don't have to scatter "is constant?" checks everywhere. This is mostly the right thing to do -- loads and stores will want to continue specializing on whether values and offsets are uniform across lanes, but most other things don't care. Bug: b/126475489 Change-Id: I1b8693a75e93b00a7972ec06777fbaaa599d2a52 Reviewed-on: https://swiftshader-review.googlesource.com/c/25668Tested-by: 's avatarChris Forbes <chrisforbes@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarBen Clayton <bclayton@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
parent 17078c70
...@@ -382,7 +382,7 @@ namespace sw ...@@ -382,7 +382,7 @@ namespace sw
return it->second; return it->second;
} }
Intermediate& getIntermediate(SpirvShader::ObjectID id) Intermediate const& getIntermediate(SpirvShader::ObjectID id) const
{ {
auto it = intermediates.find(id); auto it = intermediates.find(id);
assert(it != intermediates.end()); assert(it != intermediates.end());
...@@ -390,6 +390,31 @@ namespace sw ...@@ -390,6 +390,31 @@ 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::ObjectID objId) :
obj(shader->getObject(objId)),
intermediate(obj.kind == SpirvShader::Object::Kind::Value ? &routine->getIntermediate(objId) : nullptr) {}
RValue<Float4> operator[](uint32_t i) const
{
if (intermediate)
return (*intermediate)[i];
auto constantValue = reinterpret_cast<float *>(obj.constantValue.get());
return RValue<Float4>(constantValue[i]);
}
};
} }
#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