Commit e7b8020e by Chris Forbes

Add SpirvRoutine::getValue helper

- Provides a point to complain if something is not yet defined. - Allows avoiding ugly syntax from use of unique_ptr Bug: b/124388146 Change-Id: Ib55023fff5c90b71a41c5f558544be65250bb67d Reviewed-on: https://swiftshader-review.googlesource.com/c/24791Tested-by: 's avatarChris Forbes <chrisforbes@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarBen Clayton <bclayton@google.com>
parent 38f85b35
......@@ -498,7 +498,7 @@ namespace sw
auto typeId = baseObject.definition.word(1);
if (baseObject.kind == Object::Kind::Value)
res += As<Int4>((*routine->lvalues[id])[0]);
res += As<Int4>(routine->getValue(id)[0]);
for (auto i = 0u; i < numIndexes; i++)
{
......@@ -525,7 +525,7 @@ namespace sw
if (obj.kind == Object::Kind::Constant)
res += Int4(stride * GetConstantInt(indexIds[i]));
else
res += Int4(stride) * As<Int4>((*(routine->lvalues)[indexIds[i]])[0]);
res += Int4(stride) * As<Int4>(routine->getValue(indexIds[i])[0]);
break;
}
......@@ -685,12 +685,12 @@ namespace sw
UNIMPLEMENTED("Descriptor-backed load not yet implemented");
}
SpirvRoutine::Value& ptrBase = *(routine->lvalues)[pointer.pointerBase];
auto & dst = *(routine->lvalues)[insn.word(2)];
SpirvRoutine::Value& ptrBase = routine->getValue(pointer.pointerBase);
auto & dst = routine->getValue(insn.word(2));
if (pointer.kind == Object::Kind::Value)
{
auto offsets = As<Int4>(*(routine->lvalues)[insn.word(3)]);
auto offsets = As<Int4>(routine->getValue(insn.word(3)));
for (auto i = 0u; i < object.sizeInComponents; i++)
{
// i wish i had a Float,Float,Float,Float constructor here..
......@@ -732,7 +732,7 @@ namespace sw
UNIMPLEMENTED("Descriptor-backed OpAccessChain not yet implemented");
}
auto & dst = *(routine->lvalues)[insn.word(2)];
auto & dst = routine->getValue(insn.word(2));
dst[0] = As<Float4>(WalkAccessChain(insn.word(3), insn.wordCount() - 4, insn.wordPointer(4), routine));
break;
}
......@@ -754,12 +754,12 @@ namespace sw
UNIMPLEMENTED("Descriptor-backed store not yet implemented");
}
SpirvRoutine::Value& ptrBase = *(routine->lvalues)[pointer.pointerBase];
auto & src = *(routine->lvalues)[insn.word(2)];
SpirvRoutine::Value& ptrBase = routine->getValue(pointer.pointerBase);
auto & src = routine->getValue(insn.word(2));;
if (pointer.kind == Object::Kind::Value)
{
auto offsets = As<Int4>(*(routine->lvalues)[insn.word(1)]);
auto offsets = As<Int4>(routine->getValue(insn.word(1)));
for (auto i = 0u; i < object.sizeInComponents; i++)
{
// Scattered store
......
......@@ -42,6 +42,13 @@ namespace sw
{
lvalues.emplace(id, std::unique_ptr<Value>(new Value(size)));
}
Value& getValue(uint32_t id)
{
auto it = lvalues.find(id);
assert(it != lvalues.end());
return *it->second;
}
};
class SpirvShader
......
......@@ -37,7 +37,7 @@ namespace sw
{
// TODO: we could do better here; we know InstanceIndex is uniform across all lanes
assert(it->second.SizeInComponents == 1);
(*routine.lvalues[it->second.Id])[it->second.FirstComponent] =
routine.getValue(it->second.Id)[it->second.FirstComponent] =
As<Float4>(Int4((*Pointer<Int>(data + OFFSET(DrawData, instanceID)))));
}
}
......@@ -56,7 +56,7 @@ namespace sw
if (it != spirvShader->inputBuiltins.end())
{
assert(it->second.SizeInComponents == 1);
(*routine.lvalues[it->second.Id])[it->second.FirstComponent] =
routine.getValue(it->second.Id)[it->second.FirstComponent] =
As<Float4>(Int4(index) + Int4(0, 1, 2, 3));
}
......
......@@ -107,7 +107,7 @@ namespace sw
auto it = spirvShader->outputBuiltins.find(spv::BuiltInPosition);
assert(it != spirvShader->outputBuiltins.end());
assert(it->second.SizeInComponents == 4);
auto &pos = (*routine.lvalues[it->second.Id]);
auto &pos = routine.getValue(it->second.Id);
auto posX = pos[it->second.FirstComponent];
auto posY = pos[it->second.FirstComponent + 1];
auto posZ = pos[it->second.FirstComponent + 2];
......@@ -640,7 +640,7 @@ namespace sw
auto it = spirvShader->outputBuiltins.find(spv::BuiltInPosition);
assert(it != spirvShader->outputBuiltins.end());
assert(it->second.SizeInComponents == 4);
auto &pos = (*routine.lvalues[it->second.Id]);
auto &pos = routine.getValue(it->second.Id);
auto posX = pos[it->second.FirstComponent];
auto posY = pos[it->second.FirstComponent + 1];
auto posZ = pos[it->second.FirstComponent + 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