• Home
  • Raw
  • Download

Lines Matching +full:test +full:- +full:shared +full:- +full:dbg

7 //    http://www.apache.org/licenses/LICENSE-2.0
38 # include "spirv-tools/libspirv.h"
130 // makeDbgValue() returns a vk::dbg::Value that contains a copy of val.
132 std::shared_ptr<vk::dbg::Value> makeDbgValue(const T &val) in makeDbgValue()
134 return vk::dbg::make_constant(val); in makeDbgValue()
137 // makeDbgValue() returns a vk::dbg::Value that contains a copy of vec.
139 std::shared_ptr<vk::dbg::Value> makeDbgValue(const sw::vec<T, N> &vec) in makeDbgValue()
141 return vk::dbg::Struct::create("vec" + std::to_string(N), [&](auto &vc) { in makeDbgValue()
144 vc->put(vecElementName(i, N), makeDbgValue<T>(vec[i])); in makeDbgValue()
149 // NullptrValue is an implementation of vk::dbg::Value that simply displays
151 class NullptrValue : public vk::dbg::Value
158 std::string get(const vk::dbg::FormatFlags &) { return "<null>"; } in get()
178 // clang-format off
184 // clang-format on
227 return it->second; in getOrCreate()
234 // HoversFromLocals is an implementation of vk::dbg::Variables that is used to
235 // provide a scope's 'hover' variables - those that appear when you place the
237 // Unlike the top-level SIMD lane grouping of variables in Frame::locals,
241 class HoversFromLocals : public vk::dbg::Variables
244 HoversFromLocals(const std::shared_ptr<vk::dbg::Variables> &locals) in HoversFromLocals()
250 // No op - hovers are only searched, never iterated. in foreach()
253 std::shared_ptr<vk::dbg::Value> get(const std::string &name) override in get()
255 // Is the hover variable a SIMD-common variable? If so, just return in get()
257 if(auto val = locals->get(name)) in get()
265 auto str = vk::dbg::Struct::create("", [&](auto &vc) { in get()
269 if(auto laneV = locals->get(laneN)) in get()
271 if(auto children = laneV->children()) in get()
273 if(auto val = children->get(name)) in get()
275 vc->put(laneN, val); in get()
299 std::shared_ptr<vk::dbg::Variables> locals;
300 std::shared_ptr<vk::dbg::Struct> lastFind;
307 // Function implemented in third_party/SPIRV-Tools/source/disassemble.cpp
380 // cstr() returns the c-string name of the given Object::Kind.
435 return (TO::kindof(obj->kind)) ? static_cast<TO *>(obj) : nullptr; in cast()
444 return (TO::kindof(obj->kind)) ? static_cast<const TO *>(obj) : nullptr; in cast()
501 // value() returns a shared pointer to a vk::dbg::Value that views the data
503 virtual std::shared_ptr<vk::dbg::Value> value(void *ptr, bool interleaved) const = 0;
511 // undefined() returns a shared pointer to a vk::dbg::Value that represents
513 std::shared_ptr<vk::dbg::Value> undefined() const in undefined()
515 struct Undef : public vk::dbg::Value in undefined()
522 std::string get(const vk::dbg::FormatFlags &) override { return "<undefined>"; } in undefined()
530 // https://www.khronos.org/registry/spir-v/specs/unified1/OpenCL.DebugInfo.100.html#DebugCompilatio…
536 // https://www.khronos.org/registry/spir-v/specs/unified1/OpenCL.DebugInfo.100.html#DebugSource
544 std::shared_ptr<vk::dbg::File> dbgFile;
548 // https://www.khronos.org/registry/spir-v/specs/unified1/OpenCL.DebugInfo.100.html#DebugBasicType
560 std::shared_ptr<vk::dbg::Value> value(void *ptr, bool interleaved) const override in value()
567 // return vk::dbg::make_reference(*static_cast<void **>(ptr)); in value()
571 return vk::dbg::make_reference(*static_cast<bool *>(ptr)); in value()
573 return vk::dbg::make_reference(*static_cast<float *>(ptr)); in value()
575 return vk::dbg::make_reference(*static_cast<int32_t *>(ptr)); in value()
577 return vk::dbg::make_reference(*static_cast<int8_t *>(ptr)); in value()
579 return vk::dbg::make_reference(*static_cast<uint32_t *>(ptr)); in value()
581 return vk::dbg::make_reference(*static_cast<uint8_t *>(ptr)); in value()
590 // https://www.khronos.org/registry/spir-v/specs/unified1/OpenCL.DebugInfo.100.html#DebugTypeArray
593 // single-dimensional. Multi-dimensional arrays are transformed into multiple
606 std::string name() const override { return base->name() + "[]"; } in name()
607 uint32_t sizeInBytes() const override { return base->sizeInBytes() * size; } in sizeInBytes()
611 std::shared_ptr<vk::dbg::Value> value(void *ptr, bool interleaved) const override in value()
615 auto members = std::make_shared<vk::dbg::VariableContainer>(); in value()
625 members->put(member.name, base->value(addr, interleaved)); in value()
627 addr += base->sizeInBytes() * (interleaved ? sw::SIMD::Width : 1); in value()
629 return std::make_shared<vk::dbg::Struct>(name(), members); in value()
634 // https://www.khronos.org/registry/spir-v/specs/unified1/OpenCL.DebugInfo.100.html#DebugTypeVector
640 …std::string name() const override { return "vec" + std::to_string(components) + "<" + base->name()… in name()
641 uint32_t sizeInBytes() const override { return base->sizeInBytes() * components; } in sizeInBytes()
645 std::shared_ptr<vk::dbg::Value> value(void *ptr, bool interleaved) const override in value()
649 const auto elSize = base->sizeInBytes(); in value()
650 auto members = std::make_shared<vk::dbg::VariableContainer>(); in value()
658 members->put(getMember(i).name, base->value(elPtr, interleaved)); in value()
660 return std::make_shared<vk::dbg::Struct>(name(), members); in value()
666 // https://www.khronos.org/registry/spir-v/specs/unified1/OpenCL.DebugInfo.100.html#DebugTypeFuncti…
677 …std::shared_ptr<vk::dbg::Value> value(void *ptr, bool interleaved) const override { return nullptr… in value()
681 // Despite the instruction name, this is not a type - rather a member of a type.
682 // https://www.khronos.org/registry/spir-v/specs/unified1/OpenCL.DebugInfo.100.html#DebugTypeMember
698 // https://www.khronos.org/registry/spir-v/specs/unified1/OpenCL.DebugInfo.100.html#DebugTypeCompos…
715 Member getMember(size_t i) const override { return { members_[i]->type, members_[i]->name }; } in getMember()
717 std::shared_ptr<vk::dbg::Value> value(void *ptr, bool interleaved) const override in value()
719 auto fields = std::make_shared<vk::dbg::VariableContainer>(); in value()
722 auto offset = (member->offset / 8) * (interleaved ? sw::SIMD::Width : 1); in value()
724 auto elKey = member->name; in value()
728 fields->put(elKey, member->type->value(elPtr, interleaved)); in value()
730 return std::make_shared<vk::dbg::Struct>(name_, fields); in value()
736 // https://www.khronos.org/registry/spir-v/specs/unified1/OpenCL.DebugInfo.100.html#DebugTypeTempla…
749 // https://www.khronos.org/registry/spir-v/specs/unified1/OpenCL.DebugInfo.100.html#DebugTypeTempla…
756 uint32_t sizeInBytes() const override { return target->sizeInBytes(); } in sizeInBytes()
759 std::shared_ptr<vk::dbg::Value> value(void *ptr, bool interleaved) const override in value()
761 return target->value(ptr, interleaved); in value()
766 // https://www.khronos.org/registry/spir-v/specs/unified1/OpenCL.DebugInfo.100.html#DebugLexicalBlo…
786 // https://www.khronos.org/registry/spir-v/specs/unified1/OpenCL.DebugInfo.100.html#DebugFunction
799 // https://www.khronos.org/registry/spir-v/specs/unified1/OpenCL.DebugInfo.100.html#DebugInlinedAt
808 // https://www.khronos.org/registry/spir-v/specs/unified1/OpenCL.DebugInfo.100.html#DebugScope
816 // https://www.khronos.org/registry/spir-v/specs/unified1/OpenCL.DebugInfo.100.html#DebugGlobalVari…
836 // https://www.khronos.org/registry/spir-v/specs/unified1/OpenCL.DebugInfo.100.html#DebugLocalVaria…
873 // https://www.khronos.org/registry/spir-v/specs/unified1/OpenCL.DebugInfo.100.html#DebugOperation
881 // https://www.khronos.org/registry/spir-v/specs/unified1/OpenCL.DebugInfo.100.html#DebugExpression
888 // https://www.khronos.org/registry/spir-v/specs/unified1/OpenCL.DebugInfo.100.html#DebugDeclare
897 // https://www.khronos.org/registry/spir-v/specs/unified1/OpenCL.DebugInfo.100.html#DebugValue
913 return scope->parent ? find<T>(scope->parent) : nullptr; in find()
944 // SpirvShader-private struct holding compile-time-mutable and
945 // execution-time-immutable debugger information.
949 struct SpirvShader::Impl::Debugger : public vk::dbg::ClientEventListener
954 Debugger(const SpirvShader *shader, const std::shared_ptr<vk::dbg::Context> &ctx);
959 Define, // Pre-pass (called from SpirvShader constructor)
985 void setLocation(EmitState *state, const std::shared_ptr<vk::dbg::File> &, int line);
991 std::shared_ptr<vk::dbg::Context> const ctx; // The debugger context
992 …bool shaderHasDebugInfo; // True if the shader has high-level…
993 …std::shared_ptr<vk::dbg::File> spirvFile; // Virtual file containing SPIR-V di…
1000 vk::dbg::Location location;
1016 // Traps holds information about debugger traps - points in the shader
1020 // triggering a trap when the byte is non-zero. Traps can also be enabled
1024 // Source location + scope -> line trap index
1027 // Function name -> entry trap index
1030 // Trap index -> source location + scope
1033 // Trap memory - shared for all running instances of the shader.
1039 // (State::shadow) that contains an up-to-date copy of each
1041 // Shadow memory either contains SIMD-interleaved values for all components
1042 // in the object, or a SIMD-pointer (Shadow::Pointer).
1088 // vk::dbg::ClientEventListener
1089 void onSetBreakpoint(const vk::dbg::Location &location, bool &handled) override;
1121 // zero-initialized object into the Debugger::objects map using the
1124 // previously-built object.
1133 std::unordered_map<std::string, std::shared_ptr<vk::dbg::File>> files;
1137 vk::dbg::Location lastSetLocation;
1143 // Implementation of vk::dbg::Value that displays a debug::LocalVariable that
1153 // like llvm.dbg.value.
1155 // https://llvm.org/docs/SourceLevelDebugging.html#object-lifetime-in-optimized-code
1156 // describes the expected behavior of llvm.dbg.value, which instead of runtime
1160 // If DebugValue is to behave the same way as llvm.dbg.value, then this
1162 // instructions in the SPIR-V. This can only be done once the SPIR-V generating
1163 // compiler and SPIR-V optimization passes generate and preserve the DebugValue
1166 class sw::SpirvShader::Impl::Debugger::LocalVariableValue : public vk::dbg::Value
1169 // Data shared across all nodes in the LocalVariableValue.
1170 struct Shared struct in sw::sw::SpirvShader::Impl::Debugger::LocalVariableValue
1172 Shared(const debug::LocalVariable *const variable, const State *const state, int const lane) in Shared() argument
1177 ASSERT(variable->definition == debug::LocalVariable::Definition::Values); in Shared()
1188 const std::shared_ptr<const Shared> &shared,
1193 // vk::dbg::Value
1195 std::string get(const vk::dbg::FormatFlags &) override;
1196 std::shared_ptr<vk::dbg::Variables> children() override;
1199 std::shared_ptr<const Shared> const shared; member in sw::sw::SpirvShader::Impl::Debugger::LocalVariableValue
1203 std::shared_ptr<vk::dbg::Value> value;
1214 // * Shadow memory for keeping track of register-held values.
1269 // Called at the start of the debugger-enabled shader program.
1273 // Called at the end of the debugger-enabled shader program.
1276 // trap() is called by the debugger-enabled shader program to suspend
1279 // trap() will be called if the Debugger::Traps::memory[index] is non-zero,
1280 // or if alwaysTrap is non-zero.
1290 // alwaysTrap (if non-zero) forces a call trap() even if
1308 // Data holds the debugger-interface state (vk::dbg::*).
1329 using PerLaneVariables = std::array<std::shared_ptr<vk::dbg::VariableContainer>, sw::SIMD::Width>;
1341 std::shared_ptr<vk::dbg::VariableContainer> common;
1347 void updateFrameLocals(State *state, vk::dbg::Frame &frame, debug::LexicalBlock *block);
1349 // getOrCreateLocals() creates and returns the per-lane local variables
1365 // buildSpirvVariables() builds a Struct holding all the SPIR-V named
1367 std::shared_ptr<vk::dbg::Struct> buildSpirvVariables(State *state, int lane) const;
1369 // buildSpirvValue() returns a debugger value for the SPIR-V shadow
1371 …std::shared_ptr<vk::dbg::Value> buildSpirvValue(State *state, Shadow::Memory memory, const SpirvSh…
1374 std::shared_ptr<vk::dbg::Thread> thread;
1387 SpirvShader::Impl::Debugger::Debugger(const SpirvShader *shader, const std::shared_ptr<vk::dbg::Con… in Debugger()
1395 ctx->removeListener(this); in ~Debugger()
1403 ctx->addListener(this); in finalize()
1419 void SpirvShader::Impl::Debugger::setLocation(EmitState *state, const std::shared_ptr<vk::dbg::File… in setLocation()
1421 vk::dbg::Location location{ file, line }; in setLocation()
1436 return traps.byIndex.size() - 1; in setLocation()
1443 if(auto func = debug::find<debug::Function>(lastSetScope->scope)) in setLocation()
1445 getOrCreate(traps.byFunctionName, func->name, [&] { return index; }); in setLocation()
1449 // Emit the shader logic to test the trap value (either through via in setLocation()
1452 auto dbgState = state->routine->dbgState; in setLocation()
1458 rr::Call(&State::trap, state->routine->dbgState, index); in setLocation()
1466 auto lock = ctx->lock(); in setLocation()
1475 void SpirvShader::Impl::Debugger::onSetBreakpoint(const vk::dbg::Location &location, bool &handled) in onSetBreakpoint()
1493 // Notify the debugger if the function-entry breakpoint is handled. in onSetBreakpoint()
1503 if(isEntryBreakpointForShaderType(shader->executionModel, func)) in onSetBreakpoint()
1513 // a shared mutex (RWMutex) for the traps, read-locking for execution, and in onBreakpointsChanged()
1516 // never-completing shader). in onBreakpointsChanged()
1527 for(auto line : file->getBreakpoints()) in onBreakpointsChanged()
1531 if(it.first.location == vk::dbg::Location{ file, line }) in onBreakpointsChanged()
1540 auto lock = ctx->lock(); in onBreakpointsChanged()
1552 if(isEntryBreakpointForShaderType(shader->executionModel, bp)) in onBreakpointsChanged()
1587 cu->source = get(debug::Source::ID(insn.word(7))); in process()
1592 type->name_ = shader->getString(insn.word(5)); in process()
1593 type->size = shader->GetConstScalarInt(insn.word(6)); in process()
1594 type->encoding = static_cast<OpenCLDebugInfo100DebugBaseTypeAttributeEncoding>(insn.word(7)); in process()
1599 type->base = get(debug::Type::ID(insn.word(5))); in process()
1600 type->size = shader->GetConstScalarInt(insn.word(6)); in process()
1603 // Decompose multi-dimentional into nested single in process()
1606 inner->base = type->base; in process()
1607 type->size = shader->GetConstScalarInt(insn.word(i)); in process()
1608 type->base = inner; in process()
1609 type->ownsBase = true; in process()
1616 type->base = get(debug::Type::ID(insn.word(5))); in process()
1617 type->components = insn.word(6); in process()
1622 type->flags = insn.word(5); in process()
1623 type->returnTy = getOrNull(debug::Type::ID(insn.word(6))); in process()
1626 …// https://www.khronos.org/registry/spir-v/specs/unified1/OpenCL.DebugInfo.100.html#DebugTypeFunct… in process()
1627 …ASSERT_MSG(type->returnTy != nullptr || shader->getType(insn.word(6)).opcode() == spv::Op::OpTypeV… in process()
1631 type->paramTys.push_back(get(debug::Type::ID(insn.word(i)))); in process()
1637 type->name_ = shader->getString(insn.word(5)); in process()
1638 type->tag = static_cast<OpenCLDebugInfo100DebugCompositeType>(insn.word(6)); in process()
1639 type->source = get(debug::Source::ID(insn.word(7))); in process()
1640 type->line = insn.word(8); in process()
1641 type->column = insn.word(9); in process()
1642 type->parent = get(debug::Object::ID(insn.word(10))); in process()
1643 type->linkage = shader->getString(insn.word(11)); in process()
1644 type->size = isNone(insn.word(12)) ? 0 : shader->GetConstScalarInt(insn.word(12)); in process()
1645 type->flags = insn.word(13); in process()
1651 type->members_.push_back(member); in process()
1658 member->name = shader->getString(insn.word(5)); in process()
1659 member->type = get(debug::Type::ID(insn.word(6))); in process()
1660 member->source = get(debug::Source::ID(insn.word(7))); in process()
1661 member->line = insn.word(8); in process()
1662 member->column = insn.word(9); in process()
1663 member->parent = get(debug::CompositeType::ID(insn.word(10))); in process()
1664 member->offset = shader->GetConstScalarInt(insn.word(11)); in process()
1665 member->size = shader->GetConstScalarInt(insn.word(12)); in process()
1666 member->flags = insn.word(13); in process()
1671 tpl->target = get(debug::Type::ID(insn.word(5))); in process()
1674 tpl->parameters.emplace_back(get(debug::TemplateParameter::ID(insn.word(i)))); in process()
1680 param->name = shader->getString(insn.word(5)); in process()
1681 param->type = get(debug::Type::ID(insn.word(6))); in process()
1682 param->value = 0; // TODO: Get value from OpConstant if "a template value parameter". in process()
1683 param->source = get(debug::Source::ID(insn.word(8))); in process()
1684 param->line = insn.word(9); in process()
1685 param->column = insn.word(10); in process()
1690 var->name = shader->getString(insn.word(5)); in process()
1691 var->type = get(debug::Type::ID(insn.word(6))); in process()
1692 var->source = get(debug::Source::ID(insn.word(7))); in process()
1693 var->line = insn.word(8); in process()
1694 var->column = insn.word(9); in process()
1695 var->parent = get(debug::Scope::ID(insn.word(10))); in process()
1696 var->linkage = shader->getString(insn.word(11)); in process()
1697 var->variable = isNone(insn.word(12)) ? 0 : insn.word(12); in process()
1698 var->flags = insn.word(13); in process()
1704 func->name = shader->getString(insn.word(5)); in process()
1705 func->type = get(debug::FunctionType::ID(insn.word(6))); in process()
1706 func->source = get(debug::Source::ID(insn.word(7))); in process()
1707 func->declLine = insn.word(8); in process()
1708 func->declColumn = insn.word(9); in process()
1709 func->parent = get(debug::Scope::ID(insn.word(10))); in process()
1710 func->linkage = shader->getString(insn.word(11)); in process()
1711 func->flags = insn.word(12); in process()
1712 func->line = insn.word(13); in process()
1713 func->function = Function::ID(insn.word(14)); in process()
1719 scope->source = get(debug::Source::ID(insn.word(5))); in process()
1720 scope->line = insn.word(6); in process()
1721 scope->column = insn.word(7); in process()
1722 scope->parent = get(debug::Scope::ID(insn.word(8))); in process()
1725 scope->name = shader->getString(insn.word(9)); in process()
1731 ss->scope = get(debug::Scope::ID(insn.word(5))); in process()
1734 ss->inlinedAt = get(debug::InlinedAt::ID(insn.word(6))); in process()
1743 ia->line = insn.word(5); in process()
1744 ia->scope = get(debug::Scope::ID(insn.word(6))); in process()
1747 ia->inlined = get(debug::InlinedAt::ID(insn.word(7))); in process()
1753 var->name = shader->getString(insn.word(5)); in process()
1754 var->type = get(debug::Type::ID(insn.word(6))); in process()
1755 var->source = get(debug::Source::ID(insn.word(7))); in process()
1756 var->line = insn.word(8); in process()
1757 var->column = insn.word(9); in process()
1758 var->parent = get(debug::Scope::ID(insn.word(10))); in process()
1761 var->arg = insn.word(11); in process()
1763 if(auto block = debug::find<debug::LexicalBlock>(var->parent)) in process()
1765 block->variables.emplace_back(var); in process()
1771 decl->local = get(debug::LocalVariable::ID(insn.word(5))); in process()
1772 decl->variable = Object::ID(insn.word(6)); in process()
1773 decl->expression = get(debug::Expression::ID(insn.word(7))); in process()
1775 decl->local->declaration = decl; in process()
1777 ASSERT_MSG(decl->local->definition == debug::LocalVariable::Definition::Undefined, in process()
1779 decl->local->name.c_str(), in process()
1780 decl->local->source ? decl->local->source->file.c_str() : "<unknown>", in process()
1781 (int)decl->local->line, in process()
1782 tostring(decl->local->definition), in process()
1784 decl->local->definition = debug::LocalVariable::Definition::Declaration; in process()
1789 value->local = get(debug::LocalVariable::ID(insn.word(5))); in process()
1790 value->value = insn.word(6); in process()
1791 value->expression = get(debug::Expression::ID(insn.word(7))); in process()
1793 if(value->local->definition == debug::LocalVariable::Definition::Undefined) in process()
1795 value->local->definition = debug::LocalVariable::Definition::Values; in process()
1799 ASSERT_MSG(value->local->definition == debug::LocalVariable::Definition::Values, in process()
1801 value->local->name.c_str(), in process()
1802 value->local->source ? value->local->source->file.c_str() : "<unknown>", in process()
1803 (int)value->local->line, in process()
1804 tostring(value->local->definition), in process()
1808 auto node = &value->local->values; in process()
1811 auto idx = shader->GetConstScalarInt(insn.word(i)); in process()
1812 value->indexes.push_back(idx); in process()
1814 auto it = node->children.find(idx); in process()
1815 if(it != node->children.end()) in process()
1817 node = it->second.get(); in process()
1824 parent->children.emplace(idx, std::move(child)); in process()
1828 if(node->debugValueIndex == debug::LocalVariable::ValueNode::NoDebugValueIndex) in process()
1830 node->debugValueIndex = numDebugValueSlots++; in process()
1834 state->routine->dbgState + OFFSET(Impl::Debugger::State, lastReachedDebugValues)); in process()
1835 rr::Pointer<rr::Pointer<Byte>> lastReached = &lastReachedArray[node->debugValueIndex]; in process()
1843 expr->operations.push_back(get(debug::Operation::ID(insn.word(i)))); in process()
1849 source->file = shader->getString(insn.word(5)); in process()
1852 source->source = shader->getString(insn.word(6)); in process()
1853 auto file = ctx->lock().createVirtualFile(source->file.c_str(), source->source.c_str()); in process()
1854 source->dbgFile = file; in process()
1855 files.emplace(source->file.c_str(), file); in process()
1859 auto file = ctx->lock().createPhysicalFile(source->file.c_str()); in process()
1860 source->dbgFile = file; in process()
1861 files.emplace(source->file.c_str(), file); in process()
1867 operation->opcode = insn.word(5); in process()
1870 operation->operands.push_back(insn.word(i)); in process()
1914 return it->second.get() == nullptr; in isNone()
1922 auto ptr = debug::cast<T>(it->second.get()); in get()
1924 id.value(), cstr(it->second->kind), cstr(T::KIND)); in get()
1933 auto ptr = debug::cast<T>(it->second.get()); in getOrNull()
1935 id.value(), cstr(it->second->kind), cstr(T::KIND)); in getOrNull()
1950 …rr::Pointer<Byte> base = *rr::Pointer<rr::Pointer<Byte>>(state->routine->dbgState + OFFSET(Impl::D… in create()
1953 auto &obj = shader->getObject(objId); in create()
1954 auto &objTy = shader->getType(obj.typeId()); in create()
1955 auto mask = state->activeLaneMask(); in create()
1976 auto ptr = state->getPointer(objId); in create()
1994 OpcodeName(state->debugger->shader->getObject(objId).opcode())); in get()
1995 auto &entry = entryIt->second; in get()
1996 auto data = &state->shadow[entry.offset]; in get()
2019 …: LocalVariableValue(std::make_shared<Shared>(variable, state, lane), variable->type, &variable->v… in LocalVariableValue()
2023 const std::shared_ptr<const Shared> &shared, in LocalVariableValue() argument
2026 : shared(shared) in LocalVariableValue()
2035 return value->type(); in type()
2038 std::string sw::SpirvShader::Impl::Debugger::LocalVariableValue::get(const vk::dbg::FormatFlags &fm… in get()
2041 return value->get(fmt); in get()
2044 std::shared_ptr<vk::dbg::Variables> sw::SpirvShader::Impl::Debugger::LocalVariableValue::children() in children()
2047 return value->children(); in children()
2053 auto newActiveValue = (node->debugValueIndex != debug::LocalVariable::ValueNode::NoDebugValueIndex) in updateValue()
2054 ? shared->state->lastReachedDebugValues[node->debugValueIndex] in updateValue()
2062 …ASSERT(activeValue->local == shared->variable); // If this isn't true, then something is very won… in updateValue()
2065 auto ptr = shared->state->debugger->shadow.get(shared->state, activeValue->value); in updateValue()
2066 for(auto op : activeValue->expression->operations) in updateValue()
2068 switch(op->opcode) in updateValue()
2071 ptr = ptr.dref(shared->lane); in updateValue()
2074 UNIMPLEMENTED("b/148401179 OpenCLDebugInfo100DebugOperation %d", (int)op->opcode); in updateValue()
2078 value = ty->value(ptr, true); in updateValue()
2083 if(node->children.empty()) in updateValue()
2085 value = ty->undefined(); in updateValue()
2089 // Display <undefined> for those that don't have sub-nodes, and in updateValue()
2091 value = vk::dbg::Struct::create(ty->name(), [&](auto &vc) { in updateValue()
2092 auto numMembers = ty->numMembers(); in updateValue()
2095 auto member = ty->getMember(i); in updateValue()
2097 auto it = node->children.find(i); in updateValue()
2098 if(it != node->children.end()) in updateValue()
2100 auto child = std::make_shared<LocalVariableValue>(shared, member.type, it->second.get()); in updateValue()
2101 vc->put(member.name, child); in updateValue()
2105 vc->put(member.name, member.type->undefined()); in updateValue()
2128 , traps(debugger->traps.memory.get()) in State()
2129 , shadow(new uint8_t[debugger->shadow.size]) in State()
2130 , lastReachedDebugValues(new debug::Value *[debugger->numDebugValueSlots]) in State()
2132 memset(shadow.get(), 0, debugger->shadow.size); in State()
2133 …memset(lastReachedDebugValues.get(), 0, sizeof(lastReachedDebugValues[0]) * debugger->numDebugValu… in State()
2138 if(data) { data->terminate(this); } in ~State()
2158 data->trap(index, this); in trap()
2165 thread = state->debugger->ctx->lock().currentThread(); in Data()
2167 if(!state->debugger->shaderHasDebugInfo) in Data()
2169 // Enter the stack frame entry for the SPIR-V. in Data()
2170 thread->enter(state->debugger->spirvFile, "SPIR-V", [&](vk::dbg::Frame &frame) { in Data()
2173 auto laneLocals = std::make_shared<vk::dbg::Struct>("Lane", globals.lanes[lane]); in Data()
2174 frame.locals->variables->put(laneName(lane), laneLocals); in Data()
2175 frame.hovers->variables->extend(std::make_shared<HoversFromLocals>(frame.locals->variables)); in Data()
2183 if(state->debugger->shaderHasDebugInfo) in terminate()
2187 thread->exit(); in terminate()
2192 thread->exit(); in terminate()
2198 auto debugger = state->debugger; in trap()
2201 const auto &locationAndScope = debugger->traps.byIndex[index]; in trap()
2207 if(auto block = debug::find<debug::LexicalBlock>(locationAndScope.scope->scope)) in trap()
2209 newStack.emplace_back(StackEntry{ block, block->line }); in trap()
2211 …for(auto inlined = locationAndScope.scope->inlinedAt; inlined != nullptr; inlined = inlined->inlin… in trap()
2213 if(auto block = debug::find<debug::LexicalBlock>(inlined->scope)) in trap()
2215 newStack.emplace_back(StackEntry{ block, inlined->line }); in trap()
2224 thread->exit(true); in trap()
2240 bool wasTopMostFrame = i == (stack.size() - 1); in trap()
2247 // Don't exit() and enter() for the same function - it'll in trap()
2252 thread->update(true, [&](vk::dbg::Frame &frame) { in trap()
2263 frame.location = vk::dbg::Location{ function->source->dbgFile, (int)stack[i].line }; in trap()
2279 // (1) thread->enter() is called to construct the new stack frame with in trap()
2282 // (2) thread->update() is called to adjust the frame's location to in trap()
2285 // this is a no-op. in trap()
2287 // This two-stage approach allows the debugger to step through chains of in trap()
2296 thread->enter(entry.block->source->dbgFile, function->name, [&](vk::dbg::Frame &frame) { in trap()
2297 frame.location = vk::dbg::Location{ function->source->dbgFile, (int)function->line }; in trap()
2298 frame.hovers->variables->extend(std::make_shared<HoversFromLocals>(frame.locals->variables)); in trap()
2301 thread->update(true, [&](vk::dbg::Frame &frame) { in trap()
2309 if(thread->state() == vk::dbg::Thread::State::Running) in trap()
2314 thread->pause(); in trap()
2315 debugger->ctx->serverEventBroadcast()->onLineBreakpointHit(thread->id); in trap()
2320 thread->update(true, [&](vk::dbg::Frame &frame) { in trap()
2327 state->alwaysTrap = thread->state() != vk::dbg::Thread::State::Running; in trap()
2330 void SpirvShader::Impl::Debugger::State::Data::updateFrameLocals(State *state, vk::dbg::Frame &fram… in updateFrameLocals()
2335 auto laneLocals = std::make_shared<vk::dbg::Struct>("Lane", locals[lane]); in updateFrameLocals()
2336 frame.locals->variables->put(laneName(lane), laneLocals); in updateFrameLocals()
2347 auto vc = std::make_shared<vk::dbg::VariableContainer>(); in getOrCreateLocals()
2349 for(auto var : block->variables) in getOrCreateLocals()
2351 auto name = var->name; in getOrCreateLocals()
2353 switch(var->definition) in getOrCreateLocals()
2357 vc->put(name, var->type->undefined()); in getOrCreateLocals()
2362 auto data = state->debugger->shadow.get(state, var->declaration->variable); in getOrCreateLocals()
2363 vc->put(name, var->type->value(data.dref(lane), true)); in getOrCreateLocals()
2368 vc->put(name, std::make_shared<LocalVariableValue>(var, state, lane)); in getOrCreateLocals()
2376 if(auto parent = debug::find<debug::LexicalBlock>(block->parent)) in getOrCreateLocals()
2381 locals[lane]->extend(extend[lane]); in getOrCreateLocals()
2388 locals[lane]->extend(globals.lanes[lane]); in getOrCreateLocals()
2398 globals.common->put(name, makeDbgValue(val)); in buildGlobal()
2406 globals.lanes[lane]->put(name, makeDbgValue(simd[lane])); in buildGlobal()
2412 globals.common = std::make_shared<vk::dbg::VariableContainer>(); in buildGlobals()
2413 globals.common->put("subgroupSize", vk::dbg::make_reference(state->globals.subgroupSize)); in buildGlobals()
2417 auto vc = std::make_shared<vk::dbg::VariableContainer>(); in buildGlobals()
2419 …vc->put("enabled", vk::dbg::make_reference(reinterpret_cast<const bool &>(state->globals.activeLan… in buildGlobals()
2421 for(auto &it : state->debugger->objects) in buildGlobals()
2425 if(var->variable != 0) in buildGlobals()
2427 auto data = state->debugger->shadow.get(state, var->variable); in buildGlobals()
2428 vc->put(var->name, var->type->value(data.dref(lane), true)); in buildGlobals()
2434 if(state->debugger->shaderHasDebugInfo) in buildGlobals()
2436 vc->put("SPIR-V", spirv); in buildGlobals()
2440 vc->extend(spirv->children()); in buildGlobals()
2443 vc->extend(globals.common); in buildGlobals()
2447 switch(state->debugger->shader->executionModel) in buildGlobals()
2451 buildGlobal("numWorkgroups", state->globals.compute.numWorkgroups); in buildGlobals()
2452 buildGlobal("workgroupID", state->globals.compute.workgroupID); in buildGlobals()
2453 buildGlobal("workgroupSize", state->globals.compute.workgroupSize); in buildGlobals()
2454 buildGlobal("numSubgroups", state->globals.compute.numSubgroups); in buildGlobals()
2455 buildGlobal("subgroupIndex", state->globals.compute.subgroupIndex); in buildGlobals()
2456 buildGlobal("globalInvocationId", state->globals.compute.globalInvocationId); in buildGlobals()
2457 buildGlobal("localInvocationIndex", state->globals.compute.localInvocationIndex); in buildGlobals()
2462 buildGlobal("viewIndex", state->globals.fragment.viewIndex); in buildGlobals()
2463 buildGlobal("fragCoord", state->globals.fragment.fragCoord); in buildGlobals()
2464 buildGlobal("pointCoord", state->globals.fragment.pointCoord); in buildGlobals()
2465 buildGlobal("windowSpacePosition", state->globals.fragment.windowSpacePosition); in buildGlobals()
2466 buildGlobal("helperInvocation", state->globals.fragment.helperInvocation); in buildGlobals()
2471 buildGlobal("viewIndex", state->globals.vertex.viewIndex); in buildGlobals()
2472 buildGlobal("instanceIndex", state->globals.vertex.instanceIndex); in buildGlobals()
2473 buildGlobal("vertexIndex", state->globals.vertex.vertexIndex); in buildGlobals()
2481 std::shared_ptr<vk::dbg::Struct>
2484 return vk::dbg::Struct::create("SPIR-V", [&](auto &vc) { in buildSpirvVariables()
2485 auto debugger = state->debugger; in buildSpirvVariables()
2486 auto &entries = debugger->shadow.entries; in buildSpirvVariables()
2496 auto &obj = debugger->shader->getObject(id); in buildSpirvVariables()
2497 auto &objTy = debugger->shader->getType(obj.typeId()); in buildSpirvVariables()
2499 auto memory = debugger->shadow.get(state, id); in buildSpirvVariables()
2506 vc->put(name, val); in buildSpirvVariables()
2516 std::shared_ptr<vk::dbg::Value>
2519 auto debugger = state->debugger; in buildSpirvValue()
2520 auto shader = debugger->shader; in buildSpirvValue()
2525 return vk::dbg::make_reference(reinterpret_cast<uint32_t *>(memory.addr)[lane]); in buildSpirvValue()
2527 return vk::dbg::make_reference(reinterpret_cast<float *>(memory.addr)[lane]); in buildSpirvValue()
2530 auto elTy = shader->getType(type.element); in buildSpirvValue()
2531 return vk::dbg::Struct::create("vector", [&](auto &fields) { in buildSpirvValue()
2536 fields->put(vecElementName(i, type.componentCount), val); in buildSpirvValue()
2550 void SpirvShader::dbgInit(const std::shared_ptr<vk::dbg::Context> &ctx) in dbgInit()
2565 auto dbg = impl.debugger; in dbgCreateFile() local
2566 if(!dbg) { return; } in dbgCreateFile()
2580 dbg->spirvLineMappings[insn.data()] = currentLine; in dbgCreateFile()
2590 default: name = "SPIR-V Shader"; break; in dbgCreateFile()
2594 dbg->spirvFile = dbg->ctx->lock().createVirtualFile(name.c_str(), source.c_str()); in dbgCreateFile()
2599 auto dbg = impl.debugger; in dbgBeginEmit() local
2600 if(!dbg) { return; } in dbgBeginEmit()
2602 dbg->shaderHasDebugInfo = extensionsImported.count(Extension::OpenCLDebugInfo100) > 0; in dbgBeginEmit()
2604 auto routine = state->routine; in dbgBeginEmit()
2606 auto dbgState = rr::Call(&Impl::Debugger::State::create, dbg); in dbgBeginEmit()
2608 routine->dbgState = dbgState; in dbgBeginEmit()
2610 SetActiveLaneMask(state->activeLaneMask(), state); in dbgBeginEmit()
2617 store(globals + OFFSET(Globals, subgroupSize), routine->invocationsPerSubgroup); in dbgBeginEmit()
2624 store(compute + OFFSET(Globals::Compute, numWorkgroups), routine->numWorkgroups); in dbgBeginEmit()
2625 store(compute + OFFSET(Globals::Compute, workgroupID), routine->workgroupID); in dbgBeginEmit()
2626 store(compute + OFFSET(Globals::Compute, workgroupSize), routine->workgroupSize); in dbgBeginEmit()
2627 store(compute + OFFSET(Globals::Compute, numSubgroups), routine->subgroupsPerWorkgroup); in dbgBeginEmit()
2628 store(compute + OFFSET(Globals::Compute, subgroupIndex), routine->subgroupIndex); in dbgBeginEmit()
2629 store(compute + OFFSET(Globals::Compute, globalInvocationId), routine->globalInvocationID); in dbgBeginEmit()
2630 store(compute + OFFSET(Globals::Compute, localInvocationIndex), routine->localInvocationIndex); in dbgBeginEmit()
2636 store(fragment + OFFSET(Globals::Fragment, viewIndex), routine->layer); in dbgBeginEmit()
2637 store(fragment + OFFSET(Globals::Fragment, fragCoord), routine->fragCoord); in dbgBeginEmit()
2638 store(fragment + OFFSET(Globals::Fragment, pointCoord), routine->pointCoord); in dbgBeginEmit()
2639 store(fragment + OFFSET(Globals::Fragment, windowSpacePosition), routine->windowSpacePosition); in dbgBeginEmit()
2640 store(fragment + OFFSET(Globals::Fragment, helperInvocation), routine->helperInvocation); in dbgBeginEmit()
2646 store(vertex + OFFSET(Globals::Vertex, viewIndex), routine->layer); in dbgBeginEmit()
2647 store(vertex + OFFSET(Globals::Vertex, instanceIndex), routine->instanceID); in dbgBeginEmit()
2648 store(vertex + OFFSET(Globals::Vertex, vertexIndex), routine->vertexIndex); in dbgBeginEmit()
2659 auto dbg = impl.debugger; in dbgEndEmit() local
2660 if(!dbg) { return; } in dbgEndEmit()
2662 dbg->finalize(); in dbgEndEmit()
2664 rr::Call(&Impl::Debugger::State::destroy, state->routine->dbgState); in dbgEndEmit()
2697 if(auto dbg = impl.debugger) in dbgBeginEmitInstruction() local
2706 dbg->setNextSetLocationIsSteppable(); in dbgBeginEmitInstruction()
2709 if(!dbg->shaderHasDebugInfo) in dbgBeginEmitInstruction()
2711 // We're emitting debugger logic for SPIR-V. in dbgBeginEmitInstruction()
2714 auto line = dbg->spirvLineMappings.at(insn.data()); in dbgBeginEmitInstruction()
2715 dbg->setLocation(state, dbg->spirvFile, line); in dbgBeginEmitInstruction()
2723 auto dbg = impl.debugger; in dbgEndEmitInstruction() local
2724 if(!dbg) { return; } in dbgEndEmitInstruction()
2734 dbg->shadow.create(this, state, insn.resultId()); in dbgEndEmitInstruction()
2738 auto resIt = dbg->results.find(insn.data()); in dbgEndEmitInstruction()
2739 if(resIt != dbg->results.end()) in dbgEndEmitInstruction()
2741 dbg->shadow.create(this, state, resIt->second); in dbgEndEmitInstruction()
2749 auto dbg = impl.debugger; in dbgUpdateActiveLaneMask() local
2750 if(!dbg) { return; } in dbgUpdateActiveLaneMask()
2752 auto dbgState = state->routine->dbgState; in dbgUpdateActiveLaneMask()
2759 auto dbg = impl.debugger; in dbgDeclareResult() local
2760 if(!dbg) { return; } in dbgDeclareResult()
2762 dbg->results.emplace(insn.data(), resultId); in dbgDeclareResult()
2767 if(auto dbg = impl.debugger) in EmitLine() local
2771 dbg->setLocation(state, path.c_str(), line); in EmitLine()
2791 auto dbg = impl.debugger; in DefineOpenCLDebugInfo100() local
2792 if(!dbg) { return; } in DefineOpenCLDebugInfo100()
2794 dbg->process(insn, nullptr, Impl::Debugger::Pass::Define); in DefineOpenCLDebugInfo100()
2799 if(auto dbg = impl.debugger) in EmitOpenCLDebugInfo100() local
2801 dbg->process(insn, state, Impl::Debugger::Pass::Emit); in EmitOpenCLDebugInfo100()