Commit 7a53cb62 by Ben Clayton

SpirvShaderDebugger: Expose builtins in HLSL / GLSL.

Previously, the builtins were only exposed in the SPIR-V scope. This change utilizes the new `VariableContainer::extend()` functionality so that a single `VariableContainer` is created to hold all the builtins, and this is used as a base for the SPIR-V locals VC, as well as the high-level local scope VCs. As part of this change, I've ditched the concept of non-per-lane builtins. While some builtins are uniform across all lanes, having some at the top level of the watch tree, and others in the `Lane N` tree was just messy and complex to test. Finally, a handful of builtins are also exposed for vertex shaders. Bug: b/148401179 Change-Id: I53fedb716ab9337b0aca515768e114a8eef20f28 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/40533 Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Tested-by: 's avatarBen Clayton <bclayton@google.com>
parent 19e9af23
...@@ -464,9 +464,9 @@ public: ...@@ -464,9 +464,9 @@ public:
void createScope(const debug::Scope *); void createScope(const debug::Scope *);
void setScope(debug::SourceScope *newScope); void setScope(debug::SourceScope *newScope);
vk::dbg::VariableContainer *locals(const debug::Scope *);
vk::dbg::VariableContainer *hovers(const debug::Scope *); vk::dbg::VariableContainer *hovers(const debug::Scope *);
vk::dbg::VariableContainer *localsLane(const debug::Scope *, int lane); vk::dbg::VariableContainer *localsLane(const debug::Scope *, int lane);
vk::dbg::VariableContainer *builtinsLane(int lane);
template<typename K> template<typename K>
vk::dbg::VariableContainer *group(vk::dbg::VariableContainer *vc, K key); vk::dbg::VariableContainer *group(vk::dbg::VariableContainer *vc, K key);
...@@ -493,6 +493,7 @@ public: ...@@ -493,6 +493,7 @@ public:
const std::shared_ptr<vk::dbg::Thread> thread; const std::shared_ptr<vk::dbg::Thread> thread;
std::unordered_map<const debug::Scope *, Scopes> scopes; std::unordered_map<const debug::Scope *, Scopes> scopes;
Scopes rootScopes; // Scopes for the root stack frame. Scopes rootScopes; // Scopes for the root stack frame.
std::array<std::shared_ptr<vk::dbg::VariableContainer>, sw::SIMD::Width> builtinsByLane; // Scopes for builtin varibles (shared by all shader frames).
debug::SourceScope *srcScope = nullptr; // Current source scope. debug::SourceScope *srcScope = nullptr; // Current source scope.
}; };
...@@ -512,13 +513,21 @@ SpirvShader::Impl::Debugger::State::State(const Debugger *debugger, const char * ...@@ -512,13 +513,21 @@ SpirvShader::Impl::Debugger::State::State(const Debugger *debugger, const char *
, thread(lock.currentThread()) , thread(lock.currentThread())
{ {
enter(lock, stackBase); enter(lock, stackBase);
for(int i = 0; i < sw::SIMD::Width; i++)
{
builtinsByLane[i] = lock.createVariableContainer();
}
thread->update([&](vk::dbg::Frame &frame) { thread->update([&](vk::dbg::Frame &frame) {
rootScopes.locals = frame.locals; rootScopes.locals = frame.locals;
rootScopes.hovers = frame.hovers; rootScopes.hovers = frame.hovers;
for(int i = 0; i < sw::SIMD::Width; i++) for(int i = 0; i < sw::SIMD::Width; i++)
{ {
rootScopes.localsByLane[i] = lock.createVariableContainer(); auto locals = lock.createVariableContainer();
frame.locals->variables->put(laneNames[i], rootScopes.localsByLane[i]); locals->extend(builtinsByLane[i]);
frame.locals->variables->put(laneNames[i], locals);
rootScopes.localsByLane[i] = locals;
} }
}); });
} }
...@@ -551,11 +560,6 @@ void SpirvShader::Impl::Debugger::State::update(vk::dbg::File::ID fileID, int li ...@@ -551,11 +560,6 @@ void SpirvShader::Impl::Debugger::State::update(vk::dbg::File::ID fileID, int li
}); });
} }
vk::dbg::VariableContainer *SpirvShader::Impl::Debugger::State::locals(const debug::Scope *scope)
{
return getScopes(scope).locals->variables.get();
}
vk::dbg::VariableContainer *SpirvShader::Impl::Debugger::State::hovers(const debug::Scope *scope) vk::dbg::VariableContainer *SpirvShader::Impl::Debugger::State::hovers(const debug::Scope *scope)
{ {
return getScopes(scope).hovers->variables.get(); return getScopes(scope).hovers->variables.get();
...@@ -566,6 +570,11 @@ vk::dbg::VariableContainer *SpirvShader::Impl::Debugger::State::localsLane(const ...@@ -566,6 +570,11 @@ vk::dbg::VariableContainer *SpirvShader::Impl::Debugger::State::localsLane(const
return getScopes(scope).localsByLane[i].get(); return getScopes(scope).localsByLane[i].get();
} }
vk::dbg::VariableContainer *SpirvShader::Impl::Debugger::State::builtinsLane(int i)
{
return builtinsByLane[i].get();
}
template<typename K> template<typename K>
vk::dbg::VariableContainer *SpirvShader::Impl::Debugger::State::group(vk::dbg::VariableContainer *vc, K key) vk::dbg::VariableContainer *SpirvShader::Impl::Debugger::State::group(vk::dbg::VariableContainer *vc, K key)
{ {
...@@ -598,8 +607,10 @@ void SpirvShader::Impl::Debugger::State::createScope(const debug::Scope *spirvSc ...@@ -598,8 +607,10 @@ void SpirvShader::Impl::Debugger::State::createScope(const debug::Scope *spirvSc
s.hovers = lock.createScope(spirvScope->source->dbgFile); s.hovers = lock.createScope(spirvScope->source->dbgFile);
for(int i = 0; i < sw::SIMD::Width; i++) for(int i = 0; i < sw::SIMD::Width; i++)
{ {
s.localsByLane[i] = lock.createVariableContainer(); auto locals = lock.createVariableContainer();
s.locals->variables->put(laneNames[i], s.localsByLane[i]); locals->extend(builtinsByLane[i]);
s.localsByLane[i] = locals;
s.locals->variables->put(laneNames[i], locals);
} }
scopes.emplace(spirvScope, std::move(s)); scopes.emplace(spirvScope, std::move(s));
} }
...@@ -655,6 +666,7 @@ public: ...@@ -655,6 +666,7 @@ public:
static Group hovers(Ptr state, const debug::Scope *scope); static Group hovers(Ptr state, const debug::Scope *scope);
static Group locals(Ptr state, const debug::Scope *scope); static Group locals(Ptr state, const debug::Scope *scope);
static Group localsLane(Ptr state, const debug::Scope *scope, int lane); static Group localsLane(Ptr state, const debug::Scope *scope, int lane);
static Group builtinsLane(Ptr state, int lane);
Group(Ptr state, Ptr group); Group(Ptr state, Ptr group);
...@@ -691,15 +703,15 @@ SpirvShader::Impl::Debugger::Group::hovers(Ptr state, const debug::Scope *scope) ...@@ -691,15 +703,15 @@ SpirvShader::Impl::Debugger::Group::hovers(Ptr state, const debug::Scope *scope)
} }
SpirvShader::Impl::Debugger::Group SpirvShader::Impl::Debugger::Group
SpirvShader::Impl::Debugger::Group::locals(Ptr state, const debug::Scope *scope) SpirvShader::Impl::Debugger::Group::localsLane(Ptr state, const debug::Scope *scope, int lane)
{ {
return Group(state, rr::Call(&State::locals, state, scope)); return Group(state, rr::Call(&State::localsLane, state, scope, lane));
} }
SpirvShader::Impl::Debugger::Group SpirvShader::Impl::Debugger::Group
SpirvShader::Impl::Debugger::Group::localsLane(Ptr state, const debug::Scope *scope, int lane) SpirvShader::Impl::Debugger::Group::builtinsLane(Ptr state, int lane)
{ {
return Group(state, rr::Call(&State::localsLane, state, scope, lane)); return Group(state, rr::Call(&State::builtinsLane, state, lane));
} }
SpirvShader::Impl::Debugger::Group::Group(Ptr state, Ptr group) SpirvShader::Impl::Debugger::Group::Group(Ptr state, Ptr group)
...@@ -1284,56 +1296,58 @@ void SpirvShader::dbgBeginEmit(EmitState *state) const ...@@ -1284,56 +1296,58 @@ void SpirvShader::dbgBeginEmit(EmitState *state) const
SetActiveLaneMask(state->activeLaneMask(), state); SetActiveLaneMask(state->activeLaneMask(), state);
auto locals = Group::locals(dbgState, &debug::Scope::Root); for(int i = 0; i < SIMD::Width; i++)
locals.put<const char *, int>("subgroupSize", routine->invocationsPerSubgroup); {
auto builtins = Group::builtinsLane(dbgState, i);
builtins.put<const char *, int>("subgroupSize", routine->invocationsPerSubgroup);
switch(executionModel) switch(executionModel)
{ {
case spv::ExecutionModelGLCompute: case spv::ExecutionModelGLCompute:
locals.putVec3<const char *, int>("numWorkgroups", routine->numWorkgroups); builtins.putVec3<const char *, int>("numWorkgroups", routine->numWorkgroups);
locals.putVec3<const char *, int>("workgroupID", routine->workgroupID); builtins.putVec3<const char *, int>("workgroupID", routine->workgroupID);
locals.putVec3<const char *, int>("workgroupSize", routine->workgroupSize); builtins.putVec3<const char *, int>("workgroupSize", routine->workgroupSize);
locals.put<const char *, int>("numSubgroups", routine->subgroupsPerWorkgroup); builtins.put<const char *, int>("numSubgroups", routine->subgroupsPerWorkgroup);
locals.put<const char *, int>("subgroupIndex", routine->subgroupIndex); builtins.put<const char *, int>("subgroupIndex", routine->subgroupIndex);
for(int i = 0; i < SIMD::Width; i++) builtins.put<const char *, int>("globalInvocationId",
{
auto lane = Group::localsLane(dbgState, &debug::Scope::Root, i);
lane.put<const char *, int>("globalInvocationId",
rr::Extract(routine->globalInvocationID[0], i), rr::Extract(routine->globalInvocationID[0], i),
rr::Extract(routine->globalInvocationID[1], i), rr::Extract(routine->globalInvocationID[1], i),
rr::Extract(routine->globalInvocationID[2], i)); rr::Extract(routine->globalInvocationID[2], i));
lane.put<const char *, int>("localInvocationId", builtins.put<const char *, int>("localInvocationId",
rr::Extract(routine->localInvocationID[0], i), rr::Extract(routine->localInvocationID[0], i),
rr::Extract(routine->localInvocationID[1], i), rr::Extract(routine->localInvocationID[1], i),
rr::Extract(routine->localInvocationID[2], i)); rr::Extract(routine->localInvocationID[2], i));
lane.put<const char *, int>("localInvocationIndex", rr::Extract(routine->localInvocationIndex, i)); builtins.put<const char *, int>("localInvocationIndex", rr::Extract(routine->localInvocationIndex, i));
}
break; break;
case spv::ExecutionModelFragment: case spv::ExecutionModelFragment:
locals.put<const char *, int>("viewIndex", routine->viewID); builtins.put<const char *, int>("viewIndex", routine->viewID);
for(int i = 0; i < SIMD::Width; i++) builtins.put<const char *, float>("fragCoord",
{
auto lane = Group::localsLane(dbgState, &debug::Scope::Root, i);
lane.put<const char *, float>("fragCoord",
rr::Extract(routine->fragCoord[0], i), rr::Extract(routine->fragCoord[0], i),
rr::Extract(routine->fragCoord[1], i), rr::Extract(routine->fragCoord[1], i),
rr::Extract(routine->fragCoord[2], i), rr::Extract(routine->fragCoord[2], i),
rr::Extract(routine->fragCoord[3], i)); rr::Extract(routine->fragCoord[3], i));
lane.put<const char *, float>("pointCoord", builtins.put<const char *, float>("pointCoord",
rr::Extract(routine->pointCoord[0], i), rr::Extract(routine->pointCoord[0], i),
rr::Extract(routine->pointCoord[1], i)); rr::Extract(routine->pointCoord[1], i));
lane.put<const char *, int>("windowSpacePosition", builtins.put<const char *, int>("windowSpacePosition",
rr::Extract(routine->windowSpacePosition[0], i), rr::Extract(routine->windowSpacePosition[0], i),
rr::Extract(routine->windowSpacePosition[1], i)); rr::Extract(routine->windowSpacePosition[1], i));
lane.put<const char *, int>("helperInvocation", rr::Extract(routine->helperInvocation, i)); builtins.put<const char *, int>("helperInvocation", rr::Extract(routine->helperInvocation, i));
} break;
case spv::ExecutionModelVertex:
builtins.put<const char *, int>("viewIndex", routine->viewID);
builtins.put<const char *, int>("instanceIndex", routine->instanceID);
builtins.put<const char *, int>("vertexIndex",
rr::Extract(routine->vertexIndex, i));
break; break;
default: default:
break; break;
} }
}
} }
void SpirvShader::dbgEndEmit(EmitState *state) const void SpirvShader::dbgEndEmit(EmitState *state) const
......
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