Skip to content

Commit

Permalink
Implement debugger engine testing
Browse files Browse the repository at this point in the history
This is an initial, rough version, but implements enough to perform single line stepping, and verifying location and local values.

See docs/debugger.md for details.
  • Loading branch information
ben-clayton committed Jan 29, 2020
1 parent 8fba74c commit ecefcc6
Show file tree
Hide file tree
Showing 9 changed files with 1,029 additions and 0 deletions.
1 change: 1 addition & 0 deletions Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ LOCAL_SRC_FILES:= \
src/vulkan/descriptor.cc \
src/vulkan/device.cc \
src/vulkan/engine_vulkan.cc \
src/vulkan/engine_vulkan_debugger.cc \
src/vulkan/frame_buffer.cc \
src/vulkan/graphics_pipeline.cc \
src/vulkan/image_descriptor.cc \
Expand Down
4 changes: 4 additions & 0 deletions src/dawn/engine_dawn.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ class EngineDawn : public Engine {
const PatchParameterVerticesCommand* cmd) override;
Result DoBuffer(const BufferCommand* cmd) override;

Result GetDebugger(Debugger**) override {
return Result("Dawn does not currenty support a debugger");
}

private:
// Returns the Dawn-specific render pipeline for the given command,
// if it exists. Returns nullptr otherwise.
Expand Down
13 changes: 13 additions & 0 deletions src/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ struct EngineData {
/// 5. Engine destructor is called.
class Engine {
public:
/// Debugger is the interface to the engine's shader debugger.
class Debugger : public debug::Events {
public:
/// Flush waits for all the debugger commands issued to complete, and
/// returns a Result that includes any debugger test failure.
virtual Result Flush() = 0;
};

/// Creates a new engine of the requested |type|.
static std::unique_ptr<Engine> Create(EngineType type);

Expand Down Expand Up @@ -106,6 +114,11 @@ class Engine {
/// This covers both Vulkan buffers and images.
virtual Result DoBuffer(const BufferCommand* cmd) = 0;

/// GetDebugger retrieves the shader debugger from the engine.
/// If the engine does not support a shader debugger then the Result will be a
/// failure, and |out| will not be written to.
virtual Result GetDebugger(Debugger** out) = 0;

/// Sets the engine data to use.
void SetEngineData(const EngineData& data) { engine_data_ = data; }

Expand Down
23 changes: 23 additions & 0 deletions src/executor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,39 @@ Result Executor::Execute(Engine* engine,
if (options->execution_type == ExecutionType::kPipelineCreateOnly)
return {};

Engine::Debugger* debugger = nullptr;

// Process Commands
for (const auto& cmd : script->GetCommands()) {
if (options->delegate && options->delegate->LogExecuteCalls()) {
options->delegate->Log(std::to_string(cmd->GetLine()) + ": " +
cmd->ToString());
}

auto dbg_script = cmd->GetDebugScript();
if (dbg_script != nullptr) {
if (debugger == nullptr) {
// Lazilly obtain the debugger from the engine.
auto res = engine->GetDebugger(&debugger);
if (!res.IsSuccess()) {
return res;
}
}
// Run the debugger script on the debugger for this command.
// This will run concurrently with the command.
dbg_script->Run(debugger);
}

Result r = ExecuteCommand(engine, cmd.get());
if (!r.IsSuccess())
return r;

if (debugger != nullptr) {
// Collect the debugger test results.
r = debugger->Flush();
if (!r.IsSuccess())
return r;
}
}
return {};
}
Expand Down
4 changes: 4 additions & 0 deletions src/executor_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ class EngineStub : public Engine {
return {};
}

Result GetDebugger(Debugger**) override {
return Result("EngineStub does not currenty support a debugger");
}

private:
bool fail_clear_command_ = false;
bool fail_clear_color_command_ = false;
Expand Down
1 change: 1 addition & 0 deletions src/vulkan/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ set(VULKAN_ENGINE_SOURCES
device.cc
descriptor.cc
engine_vulkan.cc
engine_vulkan_debugger.cc
frame_buffer.cc
graphics_pipeline.cc
image_descriptor.cc
Expand Down
1 change: 1 addition & 0 deletions src/vulkan/engine_vulkan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ EngineVulkan::~EngineVulkan() {
}
}
}
DeleteDebugger();
}

Result EngineVulkan::Initialize(
Expand Down
6 changes: 6 additions & 0 deletions src/vulkan/engine_vulkan.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class EngineVulkan : public Engine {
const PatchParameterVerticesCommand* cmd) override;
Result DoBuffer(const BufferCommand* cmd) override;

Result GetDebugger(Debugger** out) override;

private:
struct PipelineInfo {
std::unique_ptr<Pipeline> vk_pipeline;
Expand Down Expand Up @@ -87,6 +89,10 @@ class EngineVulkan : public Engine {
std::unique_ptr<CommandPool> pool_;

std::map<amber::Pipeline*, PipelineInfo> pipeline_map_;

class VkDebugger;
void DeleteDebugger();
VkDebugger* debugger_ = nullptr;
};

} // namespace vulkan
Expand Down
Loading

0 comments on commit ecefcc6

Please sign in to comment.