Commit 5f7e9117 by Ben Clayton

SpirvRoutine: Use SIMD::Pointers for pointers map.

The split of intermediate + base pointer in two maps was ugly. This is also required for tracking bounds on pointers, required for robustness tests. Change-Id: I782aeee8caab43ce58ba948dcca97afa2e07482c Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/29273 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 7dd3889f
...@@ -68,11 +68,13 @@ namespace sw ...@@ -68,11 +68,13 @@ namespace sw
Pointer(rr::Pointer<Byte> base) : base(base), offset(0), uniform(true) {} Pointer(rr::Pointer<Byte> base) : base(base), offset(0), uniform(true) {}
Pointer(rr::Pointer<Byte> base, SIMD::Int offset) : base(base), offset(offset), uniform(false) {} Pointer(rr::Pointer<Byte> base, SIMD::Int offset) : base(base), offset(offset), uniform(false) {}
inline void addOffset(Int delta) { offset += delta; uniform = false; }
// Base address for the pointer, common across all lanes. // Base address for the pointer, common across all lanes.
rr::Pointer<rr::Float> base; rr::Pointer<rr::Float> base;
// Per lane offsets from base. // Per lane offsets from base.
// If uniform is false, all offsets are considered zero. // If uniform is true, all offsets are considered zero.
Int offset; Int offset;
// True if all offsets are zero. // True if all offsets are zero.
...@@ -274,8 +276,7 @@ namespace sw ...@@ -274,8 +276,7 @@ namespace sw
Intermediate, Intermediate,
// DivergentPointer formed from a base pointer and per-lane offset. // DivergentPointer formed from a base pointer and per-lane offset.
// Base pointer held by SpirvRoutine::pointers // Pointer held by SpirvRoutine::pointers
// Per-lane offset held by SpirvRoutine::intermediates.
DivergentPointer, DivergentPointer,
// Pointer with uniform address across all lanes. // Pointer with uniform address across all lanes.
...@@ -287,6 +288,7 @@ namespace sw ...@@ -287,6 +288,7 @@ namespace sw
DescriptorSet, DescriptorSet,
// Pointer to an image/sampler descriptor. // Pointer to an image/sampler descriptor.
// Pointer held by SpirvRoutine::pointers.
SampledImage, SampledImage,
}; };
...@@ -621,7 +623,7 @@ namespace sw ...@@ -621,7 +623,7 @@ namespace sw
SIMD::Pointer GetPointerToData(Object::ID id, int arrayIndex, SpirvRoutine *routine) const; SIMD::Pointer GetPointerToData(Object::ID id, int arrayIndex, SpirvRoutine *routine) const;
SIMD::Pointer WalkExplicitLayoutAccessChain(Object::ID id, uint32_t numIndexes, uint32_t const *indexIds, SpirvRoutine *routine) const; SIMD::Pointer WalkExplicitLayoutAccessChain(Object::ID id, uint32_t numIndexes, uint32_t const *indexIds, SpirvRoutine *routine) const;
SIMD::Int WalkAccessChain(Object::ID id, uint32_t numIndexes, uint32_t const *indexIds, SpirvRoutine *routine) const; SIMD::Pointer WalkAccessChain(Object::ID id, uint32_t numIndexes, uint32_t const *indexIds, SpirvRoutine *routine) const;
uint32_t WalkLiteralAccessChain(Type::ID id, uint32_t numIndexes, uint32_t const *indexes) const; uint32_t WalkLiteralAccessChain(Type::ID id, uint32_t numIndexes, uint32_t const *indexes) const;
// EmitState holds control-flow state for the emit() pass. // EmitState holds control-flow state for the emit() pass.
...@@ -772,7 +774,7 @@ namespace sw ...@@ -772,7 +774,7 @@ namespace sw
std::unordered_map<SpirvShader::Object::ID, Intermediate> intermediates; std::unordered_map<SpirvShader::Object::ID, Intermediate> intermediates;
std::unordered_map<SpirvShader::Object::ID, Pointer<Byte> > pointers; std::unordered_map<SpirvShader::Object::ID, SIMD::Pointer> pointers;
Variable inputs = Variable{MAX_INTERFACE_COMPONENTS}; Variable inputs = Variable{MAX_INTERFACE_COMPONENTS};
Variable outputs = Variable{MAX_INTERFACE_COMPONENTS}; Variable outputs = Variable{MAX_INTERFACE_COMPONENTS};
...@@ -788,25 +790,12 @@ namespace sw ...@@ -788,25 +790,12 @@ namespace sw
ASSERT_MSG(added, "Variable %d created twice", id.value()); ASSERT_MSG(added, "Variable %d created twice", id.value());
} }
template <typename T> void createPointer(SpirvShader::Object::ID id, SIMD::Pointer ptr)
void createPointer(SpirvShader::Object::ID id, Pointer<T> ptrBase)
{ {
bool added = pointers.emplace(id, ptrBase).second; bool added = pointers.emplace(id, ptr).second;
ASSERT_MSG(added, "Pointer %d created twice", id.value()); ASSERT_MSG(added, "Pointer %d created twice", id.value());
} }
template <typename T>
void createPointer(SpirvShader::Object::ID id, RValue<Pointer<T>> ptrBase)
{
createPointer(id, Pointer<T>(ptrBase));
}
template <typename T>
void createPointer(SpirvShader::Object::ID id, Reference<Pointer<T>> ptrBase)
{
createPointer(id, Pointer<T>(ptrBase));
}
Intermediate& createIntermediate(SpirvShader::Object::ID id, uint32_t size) Intermediate& createIntermediate(SpirvShader::Object::ID id, uint32_t size)
{ {
auto it = intermediates.emplace(std::piecewise_construct, auto it = intermediates.emplace(std::piecewise_construct,
...@@ -830,7 +819,7 @@ namespace sw ...@@ -830,7 +819,7 @@ namespace sw
return it->second; return it->second;
} }
Pointer<Byte>& getPointer(SpirvShader::Object::ID id) SIMD::Pointer const& getPointer(SpirvShader::Object::ID id) const
{ {
auto it = pointers.find(id); auto it = pointers.find(id);
ASSERT_MSG(it != pointers.end(), "Unknown pointer %d", id.value()); ASSERT_MSG(it != pointers.end(), "Unknown pointer %d", id.value());
......
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