Commit 47747616 by Ben Clayton

SpirvShader: Make value names more consistent

Rename Object::Kind::Value to Object::Kind::Intermediate. Rename SpirvRoutine::Value to SpirvRoutine::Variable. Change-Id: I1dba30687cbf979d80b0deeca7a96e64a88c94db Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/28393 Presubmit-Ready: Ben Clayton <bclayton@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Tested-by: 's avatarBen Clayton <bclayton@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent d67ee5f5
...@@ -167,8 +167,7 @@ namespace sw ...@@ -167,8 +167,7 @@ namespace sw
if (it != shader->inputBuiltins.end()) if (it != shader->inputBuiltins.end())
{ {
const auto& builtin = it->second; const auto& builtin = it->second;
auto &value = routine.getValue(builtin.Id); cb(builtin, routine.getVariable(builtin.Id));
cb(builtin, value);
} }
} }
......
...@@ -444,7 +444,7 @@ namespace sw ...@@ -444,7 +444,7 @@ namespace sw
Object::ID resultId = insn.word(2); Object::ID resultId = insn.word(2);
auto &object = defs[resultId]; auto &object = defs[resultId];
object.type = typeId; object.type = typeId;
object.kind = Object::Kind::Value; object.kind = Object::Kind::Intermediate;
object.definition = insn; object.definition = insn;
if (insn.opcode() == spv::OpAccessChain || insn.opcode() == spv::OpInBoundsAccessChain) if (insn.opcode() == spv::OpAccessChain || insn.opcode() == spv::OpInBoundsAccessChain)
...@@ -829,7 +829,7 @@ namespace sw ...@@ -829,7 +829,7 @@ namespace sw
// The <base> operand is an intermediate value itself, ie produced by a previous OpAccessChain. // The <base> operand is an intermediate value itself, ie produced by a previous OpAccessChain.
// Start with its offset and build from there. // Start with its offset and build from there.
if (baseObject.kind == Object::Kind::Value) if (baseObject.kind == Object::Kind::Intermediate)
{ {
dynamicOffset += routine->getIntermediate(id).Int(0); dynamicOffset += routine->getIntermediate(id).Int(0);
} }
...@@ -905,7 +905,7 @@ namespace sw ...@@ -905,7 +905,7 @@ namespace sw
// The <base> operand is an intermediate value itself, ie produced by a previous OpAccessChain. // The <base> operand is an intermediate value itself, ie produced by a previous OpAccessChain.
// Start with its offset and build from there. // Start with its offset and build from there.
if (baseObject.kind == Object::Kind::Value) if (baseObject.kind == Object::Kind::Intermediate)
{ {
dynamicOffset += routine->getIntermediate(id).Int(0); dynamicOffset += routine->getIntermediate(id).Int(0);
} }
...@@ -1155,7 +1155,7 @@ namespace sw ...@@ -1155,7 +1155,7 @@ namespace sw
if(pointeeType.sizeInComponents > 0) // TODO: what to do about zero-slot objects? if(pointeeType.sizeInComponents > 0) // TODO: what to do about zero-slot objects?
{ {
Object::ID resultId = insn.word(2); Object::ID resultId = insn.word(2);
routine->createLvalue(resultId, pointeeType.sizeInComponents); routine->createVariable(resultId, pointeeType.sizeInComponents);
} }
break; break;
} }
...@@ -1705,7 +1705,7 @@ namespace sw ...@@ -1705,7 +1705,7 @@ namespace sw
{ {
if (object.kind == Object::Kind::InterfaceVariable) if (object.kind == Object::Kind::InterfaceVariable)
{ {
auto &dst = routine->getValue(resultId); auto &dst = routine->getVariable(resultId);
int offset = 0; int offset = 0;
VisitInterface(resultId, VisitInterface(resultId,
[&](Decorations const &d, AttribType type) { [&](Decorations const &d, AttribType type) {
...@@ -1792,7 +1792,7 @@ namespace sw ...@@ -1792,7 +1792,7 @@ namespace sw
} }
else else
{ {
ptrBase = &routine->getValue(pointer.pointerBase)[0]; ptrBase = &routine->getVariable(pointer.pointerBase)[0];
} }
bool interleavedByLane = IsStorageInterleavedByLane(pointerBaseTy.storageClass); bool interleavedByLane = IsStorageInterleavedByLane(pointerBaseTy.storageClass);
...@@ -1800,10 +1800,10 @@ namespace sw ...@@ -1800,10 +1800,10 @@ namespace sw
auto load = std::unique_ptr<SIMD::Float[]>(new SIMD::Float[resultTy.sizeInComponents]); auto load = std::unique_ptr<SIMD::Float[]>(new SIMD::Float[resultTy.sizeInComponents]);
If(pointer.kind == Object::Kind::Value || anyInactiveLanes) If(pointer.kind == Object::Kind::Intermediate || anyInactiveLanes)
{ {
// Divergent offsets or masked lanes. // Divergent offsets or masked lanes.
auto offsets = pointer.kind == Object::Kind::Value ? auto offsets = pointer.kind == Object::Kind::Intermediate ?
As<SIMD::Int>(routine->getIntermediate(pointerId).Int(0)) : As<SIMD::Int>(routine->getIntermediate(pointerId).Int(0)) :
RValue<SIMD::Int>(SIMD::Int(0)); RValue<SIMD::Int>(SIMD::Int(0));
for (auto i = 0u; i < resultTy.sizeInComponents; i++) for (auto i = 0u; i < resultTy.sizeInComponents; i++)
...@@ -1886,7 +1886,7 @@ namespace sw ...@@ -1886,7 +1886,7 @@ namespace sw
} }
else else
{ {
ptrBase = &routine->getValue(pointer.pointerBase)[0]; ptrBase = &routine->getVariable(pointer.pointerBase)[0];
} }
bool interleavedByLane = IsStorageInterleavedByLane(pointerBaseTy.storageClass); bool interleavedByLane = IsStorageInterleavedByLane(pointerBaseTy.storageClass);
...@@ -1896,10 +1896,10 @@ namespace sw ...@@ -1896,10 +1896,10 @@ namespace sw
{ {
// Constant source data. // Constant source data.
auto src = reinterpret_cast<float *>(object.constantValue.get()); auto src = reinterpret_cast<float *>(object.constantValue.get());
If(pointer.kind == Object::Kind::Value || anyInactiveLanes) If(pointer.kind == Object::Kind::Intermediate || anyInactiveLanes)
{ {
// Divergent offsets or masked lanes. // Divergent offsets or masked lanes.
auto offsets = pointer.kind == Object::Kind::Value ? auto offsets = pointer.kind == Object::Kind::Intermediate ?
As<SIMD::Int>(routine->getIntermediate(pointerId).Int(0)) : As<SIMD::Int>(routine->getIntermediate(pointerId).Int(0)) :
RValue<SIMD::Int>(SIMD::Int(0)); RValue<SIMD::Int>(SIMD::Int(0));
for (auto i = 0u; i < elementTy.sizeInComponents; i++) for (auto i = 0u; i < elementTy.sizeInComponents; i++)
...@@ -1930,10 +1930,10 @@ namespace sw ...@@ -1930,10 +1930,10 @@ namespace sw
{ {
// Intermediate source data. // Intermediate source data.
auto &src = routine->getIntermediate(objectId); auto &src = routine->getIntermediate(objectId);
If(pointer.kind == Object::Kind::Value || anyInactiveLanes) If(pointer.kind == Object::Kind::Intermediate || anyInactiveLanes)
{ {
// Divergent offsets or masked lanes. // Divergent offsets or masked lanes.
auto offsets = pointer.kind == Object::Kind::Value ? auto offsets = pointer.kind == Object::Kind::Intermediate ?
As<SIMD::Int>(routine->getIntermediate(pointerId).Int(0)) : As<SIMD::Int>(routine->getIntermediate(pointerId).Int(0)) :
RValue<SIMD::Int>(SIMD::Int(0)); RValue<SIMD::Int>(SIMD::Int(0));
for (auto i = 0u; i < elementTy.sizeInComponents; i++) for (auto i = 0u; i < elementTy.sizeInComponents; i++)
...@@ -3103,7 +3103,7 @@ namespace sw ...@@ -3103,7 +3103,7 @@ namespace sw
auto &objectTy = getType(object.type); auto &objectTy = getType(object.type);
if (object.kind == Object::Kind::InterfaceVariable && objectTy.storageClass == spv::StorageClassOutput) if (object.kind == Object::Kind::InterfaceVariable && objectTy.storageClass == spv::StorageClassOutput)
{ {
auto &dst = routine->getValue(resultId); auto &dst = routine->getVariable(resultId);
int offset = 0; int offset = 0;
VisitInterface(resultId, VisitInterface(resultId,
[&](Decorations const &d, AttribType type) { [&](Decorations const &d, AttribType type) {
......
...@@ -242,7 +242,7 @@ namespace sw ...@@ -242,7 +242,7 @@ namespace sw
Variable, // TODO: Document Variable, // TODO: Document
InterfaceVariable, // TODO: Document InterfaceVariable, // TODO: Document
Constant, // Values held by Object::constantValue Constant, // Values held by Object::constantValue
Value, // Values held by SpirvRoutine::intermediates Intermediate, // Values held by SpirvRoutine::intermediates
PhysicalPointer, // Pointer held by SpirvRoutine::physicalPointers PhysicalPointer, // Pointer held by SpirvRoutine::physicalPointers
} kind = Kind::Unknown; } kind = Kind::Unknown;
}; };
...@@ -647,28 +647,28 @@ namespace sw ...@@ -647,28 +647,28 @@ namespace sw
public: public:
SpirvRoutine(vk::PipelineLayout const *pipelineLayout); SpirvRoutine(vk::PipelineLayout const *pipelineLayout);
using Value = Array<SIMD::Float>; using Variable = Array<SIMD::Float>;
vk::PipelineLayout const * const pipelineLayout; vk::PipelineLayout const * const pipelineLayout;
std::unordered_map<SpirvShader::Object::ID, Value> lvalues; std::unordered_map<SpirvShader::Object::ID, Variable> variables;
std::unordered_map<SpirvShader::Object::ID, Intermediate> intermediates; std::unordered_map<SpirvShader::Object::ID, Intermediate> intermediates;
std::unordered_map<SpirvShader::Object::ID, Pointer<Byte> > physicalPointers; std::unordered_map<SpirvShader::Object::ID, Pointer<Byte> > physicalPointers;
Value inputs = Value{MAX_INTERFACE_COMPONENTS}; Variable inputs = Variable{MAX_INTERFACE_COMPONENTS};
Value outputs = Value{MAX_INTERFACE_COMPONENTS}; Variable outputs = Variable{MAX_INTERFACE_COMPONENTS};
Pointer<Pointer<Byte>> descriptorSets; Pointer<Pointer<Byte>> descriptorSets;
Pointer<Int> descriptorDynamicOffsets; Pointer<Int> descriptorDynamicOffsets;
Pointer<Byte> pushConstants; Pointer<Byte> pushConstants;
Int killMask = Int{0}; Int killMask = Int{0};
void createLvalue(SpirvShader::Object::ID id, uint32_t size) void createVariable(SpirvShader::Object::ID id, uint32_t size)
{ {
bool added = lvalues.emplace(id, Value(size)).second; bool added = variables.emplace(id, Variable(size)).second;
ASSERT_MSG(added, "Value %d created twice", id.value()); ASSERT_MSG(added, "Variable %d created twice", id.value());
} }
Intermediate& createIntermediate(SpirvShader::Object::ID id, uint32_t size) Intermediate& createIntermediate(SpirvShader::Object::ID id, uint32_t size)
...@@ -680,10 +680,10 @@ namespace sw ...@@ -680,10 +680,10 @@ namespace sw
return it.first->second; return it.first->second;
} }
Value& getValue(SpirvShader::Object::ID id) Variable& getVariable(SpirvShader::Object::ID id)
{ {
auto it = lvalues.find(id); auto it = variables.find(id);
ASSERT_MSG(it != lvalues.end(), "Unknown value %d", id.value()); ASSERT_MSG(it != variables.end(), "Unknown variables %d", id.value());
return it->second; return it->second;
} }
...@@ -715,7 +715,7 @@ namespace sw ...@@ -715,7 +715,7 @@ namespace sw
public: public:
GenericValue(SpirvShader const *shader, SpirvRoutine const *routine, SpirvShader::Object::ID objId) : GenericValue(SpirvShader const *shader, SpirvRoutine const *routine, SpirvShader::Object::ID objId) :
obj(shader->getObject(objId)), obj(shader->getObject(objId)),
intermediate(obj.kind == SpirvShader::Object::Kind::Value ? &routine->getIntermediate(objId) : nullptr) {} intermediate(obj.kind == SpirvShader::Object::Kind::Intermediate ? &routine->getIntermediate(objId) : nullptr) {}
RValue<SIMD::Float> Float(uint32_t i) const RValue<SIMD::Float> Float(uint32_t i) const
{ {
......
...@@ -42,7 +42,7 @@ namespace sw ...@@ -42,7 +42,7 @@ namespace sw
{ {
// TODO: we could do better here; we know InstanceIndex is uniform across all lanes // TODO: we could do better here; we know InstanceIndex is uniform across all lanes
assert(it->second.SizeInComponents == 1); assert(it->second.SizeInComponents == 1);
routine.getValue(it->second.Id)[it->second.FirstComponent] = routine.getVariable(it->second.Id)[it->second.FirstComponent] =
As<Float4>(Int4((*Pointer<Int>(data + OFFSET(DrawData, instanceID))))); As<Float4>(Int4((*Pointer<Int>(data + OFFSET(DrawData, instanceID)))));
} }
...@@ -65,7 +65,7 @@ namespace sw ...@@ -65,7 +65,7 @@ namespace sw
if (it != spirvShader->inputBuiltins.end()) if (it != spirvShader->inputBuiltins.end())
{ {
assert(it->second.SizeInComponents == 1); assert(it->second.SizeInComponents == 1);
routine.getValue(it->second.Id)[it->second.FirstComponent] = routine.getVariable(it->second.Id)[it->second.FirstComponent] =
As<Float4>(Int4(index) + Int4(0, 1, 2, 3)); As<Float4>(Int4(index) + Int4(0, 1, 2, 3));
} }
......
...@@ -109,7 +109,7 @@ namespace sw ...@@ -109,7 +109,7 @@ namespace sw
auto it = spirvShader->outputBuiltins.find(spv::BuiltInPosition); auto it = spirvShader->outputBuiltins.find(spv::BuiltInPosition);
assert(it != spirvShader->outputBuiltins.end()); assert(it != spirvShader->outputBuiltins.end());
assert(it->second.SizeInComponents == 4); assert(it->second.SizeInComponents == 4);
auto &pos = routine.getValue(it->second.Id); auto &pos = routine.getVariable(it->second.Id);
auto posX = pos[it->second.FirstComponent]; auto posX = pos[it->second.FirstComponent];
auto posY = pos[it->second.FirstComponent + 1]; auto posY = pos[it->second.FirstComponent + 1];
auto posZ = pos[it->second.FirstComponent + 2]; auto posZ = pos[it->second.FirstComponent + 2];
...@@ -525,7 +525,7 @@ namespace sw ...@@ -525,7 +525,7 @@ namespace sw
auto it = spirvShader->outputBuiltins.find(spv::BuiltInPosition); auto it = spirvShader->outputBuiltins.find(spv::BuiltInPosition);
assert(it != spirvShader->outputBuiltins.end()); assert(it != spirvShader->outputBuiltins.end());
assert(it->second.SizeInComponents == 4); assert(it->second.SizeInComponents == 4);
auto &pos = routine.getValue(it->second.Id); auto &pos = routine.getVariable(it->second.Id);
auto posX = pos[it->second.FirstComponent]; auto posX = pos[it->second.FirstComponent];
auto posY = pos[it->second.FirstComponent + 1]; auto posY = pos[it->second.FirstComponent + 1];
auto posZ = pos[it->second.FirstComponent + 2]; auto posZ = pos[it->second.FirstComponent + 2];
...@@ -564,7 +564,7 @@ namespace sw ...@@ -564,7 +564,7 @@ namespace sw
if (it != spirvShader->outputBuiltins.end()) if (it != spirvShader->outputBuiltins.end())
{ {
assert(it->second.SizeInComponents == 1); assert(it->second.SizeInComponents == 1);
auto psize = routine.getValue(it->second.Id)[it->second.FirstComponent]; auto psize = routine.getVariable(it->second.Id)[it->second.FirstComponent];
*Pointer<Float>(cacheLine + OFFSET(Vertex,builtins.pointSize) + sizeof(Vertex) * 0) = Extract(psize, 0); *Pointer<Float>(cacheLine + OFFSET(Vertex,builtins.pointSize) + sizeof(Vertex) * 0) = Extract(psize, 0);
*Pointer<Float>(cacheLine + OFFSET(Vertex,builtins.pointSize) + sizeof(Vertex) * 1) = Extract(psize, 1); *Pointer<Float>(cacheLine + OFFSET(Vertex,builtins.pointSize) + sizeof(Vertex) * 1) = Extract(psize, 1);
*Pointer<Float>(cacheLine + OFFSET(Vertex,builtins.pointSize) + sizeof(Vertex) * 2) = Extract(psize, 2); *Pointer<Float>(cacheLine + OFFSET(Vertex,builtins.pointSize) + sizeof(Vertex) * 2) = Extract(psize, 2);
......
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