Skip to content

Commit 8d03d06

Browse files
committed
Implement debugger engine testing
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.
1 parent f472700 commit 8d03d06

File tree

8 files changed

+1034
-0
lines changed

8 files changed

+1034
-0
lines changed

Android.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ LOCAL_SRC_FILES:= \
5959
src/vulkan/descriptor.cc \
6060
src/vulkan/device.cc \
6161
src/vulkan/engine_vulkan.cc \
62+
src/vulkan/engine_vulkan_debugger.cc \
6263
src/vulkan/frame_buffer.cc \
6364
src/vulkan/graphics_pipeline.cc \
6465
src/vulkan/image_descriptor.cc \

src/dawn/engine_dawn.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <cstdint>
1919
#include <string>
2020
#include <unordered_map>
21+
#include <utility>
2122
#include <vector>
2223

2324
#include "dawn/dawncpp.h"
@@ -61,6 +62,10 @@ class EngineDawn : public Engine {
6162
const PatchParameterVerticesCommand* cmd) override;
6263
Result DoBuffer(const BufferCommand* cmd) override;
6364

65+
std::pair<Debugger*, Result> GetDebugger() override {
66+
return {nullptr, Result("Dawn does not currently support a debugger")};
67+
}
68+
6469
private:
6570
// Returns the Dawn-specific render pipeline for the given command,
6671
// if it exists. Returns nullptr otherwise.

src/engine.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include <memory>
1919
#include <string>
20+
#include <utility>
2021
#include <vector>
2122

2223
#include "amber/amber.h"
@@ -53,6 +54,14 @@ struct EngineData {
5354
/// 5. Engine destructor is called.
5455
class Engine {
5556
public:
57+
/// Debugger is the interface to the engine's shader debugger.
58+
class Debugger : public debug::Events {
59+
public:
60+
/// Flush waits for all the debugger commands issued to complete, and
61+
/// returns a Result that includes any debugger test failure.
62+
virtual Result Flush() = 0;
63+
};
64+
5665
/// Creates a new engine of the requested |type|.
5766
static std::unique_ptr<Engine> Create(EngineType type);
5867

@@ -106,6 +115,11 @@ class Engine {
106115
/// This covers both Vulkan buffers and images.
107116
virtual Result DoBuffer(const BufferCommand* cmd) = 0;
108117

118+
/// GetDebugger returns the shader debugger from the engine.
119+
/// If the engine does not support a shader debugger then the Result will be a
120+
/// failure.
121+
virtual std::pair<Debugger*, Result> GetDebugger() = 0;
122+
109123
/// Sets the engine data to use.
110124
void SetEngineData(const EngineData& data) { engine_data_ = data; }
111125

src/executor.cc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,40 @@ Result Executor::Execute(Engine* engine,
8383
if (options->execution_type == ExecutionType::kPipelineCreateOnly)
8484
return {};
8585

86+
Engine::Debugger* debugger = nullptr;
87+
8688
// Process Commands
8789
for (const auto& cmd : script->GetCommands()) {
8890
if (options->delegate && options->delegate->LogExecuteCalls()) {
8991
options->delegate->Log(std::to_string(cmd->GetLine()) + ": " +
9092
cmd->ToString());
9193
}
9294

95+
auto dbg_script = cmd->GetDebugScript();
96+
if (dbg_script != nullptr) {
97+
if (debugger == nullptr) {
98+
// Lazilly obtain the debugger from the engine.
99+
Result res;
100+
std::tie(debugger, res) = engine->GetDebugger();
101+
if (!res.IsSuccess()) {
102+
return res;
103+
}
104+
}
105+
// Run the debugger script on the debugger for this command.
106+
// This will run concurrently with the command.
107+
dbg_script->Run(debugger);
108+
}
109+
93110
Result r = ExecuteCommand(engine, cmd.get());
94111
if (!r.IsSuccess())
95112
return r;
113+
114+
if (debugger != nullptr) {
115+
// Collect the debugger test results.
116+
r = debugger->Flush();
117+
if (!r.IsSuccess())
118+
return r;
119+
}
96120
}
97121
return {};
98122
}

src/executor_test.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ class EngineStub : public Engine {
159159
return {};
160160
}
161161

162+
std::pair<Debugger*, Result> GetDebugger() override {
163+
return {nullptr,
164+
Result("EngineStub does not currently support a debugger")};
165+
}
166+
162167
private:
163168
bool fail_clear_command_ = false;
164169
bool fail_clear_color_command_ = false;

src/vulkan/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ set(VULKAN_ENGINE_SOURCES
2121
device.cc
2222
descriptor.cc
2323
engine_vulkan.cc
24+
engine_vulkan_debugger.cc
2425
frame_buffer.cc
2526
graphics_pipeline.cc
2627
image_descriptor.cc

src/vulkan/engine_vulkan.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <memory>
2020
#include <string>
2121
#include <unordered_map>
22+
#include <utility>
2223
#include <vector>
2324

2425
#include "amber/vulkan_header.h"
@@ -37,6 +38,8 @@ namespace vulkan {
3738
/// Engine implementation based on Vulkan.
3839
class EngineVulkan : public Engine {
3940
public:
41+
class VkDebugger;
42+
4043
EngineVulkan();
4144
~EngineVulkan() override;
4245

@@ -60,6 +63,8 @@ class EngineVulkan : public Engine {
6063
const PatchParameterVerticesCommand* cmd) override;
6164
Result DoBuffer(const BufferCommand* cmd) override;
6265

66+
std::pair<Debugger*, Result> GetDebugger() override;
67+
6368
private:
6469
struct PipelineInfo {
6570
std::unique_ptr<Pipeline> vk_pipeline;
@@ -87,6 +92,8 @@ class EngineVulkan : public Engine {
8792
std::unique_ptr<CommandPool> pool_;
8893

8994
std::map<amber::Pipeline*, PipelineInfo> pipeline_map_;
95+
96+
std::unique_ptr<Debugger> debugger_;
9097
};
9198

9299
} // namespace vulkan

0 commit comments

Comments
 (0)