aboutsummaryrefslogtreecommitdiff
path: root/samples
diff options
context:
space:
mode:
authorHugues Evrard <hevrard@users.noreply.github.com>2019-03-08 16:28:07 +0100
committerdan sinclair <dj2@everburning.com>2019-03-08 10:28:07 -0500
commit5bd86e6705c3d91247fbca5c447dc7a6ef054aed (patch)
tree224ab7504d3472f4b019bdc2584c87055e6a38c5 /samples
parentd9e823e5ab380fcf417452581721ad9c3bdcf60b (diff)
downloadamber-5bd86e6705c3d91247fbca5c447dc7a6ef054aed.tar.gz
Add Delegate and --log-graphics-calls flag (#334)
This adds a Delegate which enables users of the amber library to define some hook functions as they like. The first usage here is a Delegate::Log() function to log graphics API calls. In practice, a pointer to the delegate object is passed at engine creation and the Vulkan engine eventually pass it to LoadVulkanPointers() which calls the functions produced by update_vk_wrappers.py. This enable to choose, when loading the Vulkan functions, whether to load a straighforward wrapper to the API command, or to load a lambda that surround the API command with calls to the delegate methods. The --log-graphics-calls flag in the samples sets the delegate to produce a log of API calls.
Diffstat (limited to 'samples')
-rw-r--r--samples/CMakeLists.txt1
-rw-r--r--samples/amber.cc29
2 files changed, 30 insertions, 0 deletions
diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt
index 33e3517..213d4c3 100644
--- a/samples/CMakeLists.txt
+++ b/samples/CMakeLists.txt
@@ -47,6 +47,7 @@ add_executable(amber ${AMBER_SOURCES})
target_include_directories(amber PRIVATE "${CMAKE_BINARY_DIR}")
set_target_properties(amber PROPERTIES OUTPUT_NAME "amber")
target_link_libraries(amber libamber ${AMBER_EXTRA_LIBS})
+amber_default_compile_options(amber)
add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/src/build-versions.h.fake
diff --git a/samples/amber.cc b/samples/amber.cc
index 160c60b..79d0cee 100644
--- a/samples/amber.cc
+++ b/samples/amber.cc
@@ -45,6 +45,7 @@ struct Options {
bool quiet = false;
bool show_help = false;
bool show_version_info = false;
+ bool log_graphics_calls = false;
amber::EngineType engine = amber::kEngineTypeVulkan;
std::string spv_env;
};
@@ -64,6 +65,7 @@ const char kUsage[] = R"(Usage: amber [options] SCRIPT [SCRIPTS...]
-e <engine> -- Specify graphics engine: vulkan, dawn. Default is vulkan.
-v <engine version> -- Engine version (eg, 1.1 for Vulkan). Default 1.0.
-V, --version -- Output version information for Amber and libraries.
+ --log-graphics-calls -- Log graphics API calls (only for Vulkan so far).
-h -- This help text.
)";
@@ -157,6 +159,8 @@ bool ParseArgs(const std::vector<std::string>& args, Options* opts) {
opts->quiet = false;
} else if (arg == "-q") {
opts->quiet = true;
+ } else if (arg == "--log-graphics-calls") {
+ opts->log_graphics_calls = true;
} else if (arg.size() > 0 && arg[0] == '-') {
std::cerr << "Unrecognized option " << arg << std::endl;
return false;
@@ -203,6 +207,25 @@ std::string ReadFile(const std::string& input_file) {
return std::string(data.begin(), data.end());
}
+class SampleDelegate : public amber::Delegate {
+ public:
+ SampleDelegate() : log_graphics_calls_(false) {}
+ ~SampleDelegate() override = default;
+
+ void Log(const std::string& message) override {
+ std::cout << message << std::endl;
+ }
+
+ bool LogGraphicsCalls() const override { return log_graphics_calls_; }
+
+ void SetLogGraphicsCalls(bool log_graphics_calls) {
+ log_graphics_calls_ = log_graphics_calls;
+ }
+
+ private:
+ bool log_graphics_calls_;
+};
+
} // namespace
int main(int argc, const char** argv) {
@@ -264,10 +287,16 @@ int main(int argc, const char** argv) {
if (options.parse_only)
return 0;
+ SampleDelegate delegate;
+ if (options.log_graphics_calls) {
+ delegate.SetLogGraphicsCalls(true);
+ }
+
amber::Options amber_options;
amber_options.engine = options.engine;
amber_options.spv_env = options.spv_env;
amber_options.pipeline_create_only = options.pipeline_create_only;
+ amber_options.delegate = &delegate;
std::set<std::string> required_features;
std::set<std::string> required_device_extensions;