aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/amber/amber.h13
-rw-r--r--samples/CMakeLists.txt1
-rw-r--r--samples/amber.cc29
-rw-r--r--src/amber.cc5
-rw-r--r--src/dawn/engine_dawn.cc1
-rw-r--r--src/dawn/engine_dawn.h1
-rw-r--r--src/engine.h1
-rw-r--r--src/executor_test.cc3
-rw-r--r--src/vulkan/device.cc15
-rw-r--r--src/vulkan/device.h4
-rw-r--r--src/vulkan/engine_vulkan.cc3
-rw-r--r--src/vulkan/engine_vulkan.h1
-rwxr-xr-xtools/update_vk_wrappers.py36
13 files changed, 100 insertions, 13 deletions
diff --git a/include/amber/amber.h b/include/amber/amber.h
index b332129..5a89b88 100644
--- a/include/amber/amber.h
+++ b/include/amber/amber.h
@@ -52,6 +52,17 @@ struct BufferInfo {
std::vector<Value> values;
};
+/// Delegate class for various hook functions
+class Delegate {
+ public:
+ virtual ~Delegate();
+
+ /// Log the given message
+ virtual void Log(const std::string& message) = 0;
+ /// Tells whether to log the graphics API calls
+ virtual bool LogGraphicsCalls() const = 0;
+};
+
struct Options {
/// Sets the engine to be created. Default Vulkan.
EngineType engine;
@@ -63,6 +74,8 @@ struct Options {
std::vector<BufferInfo> extractions;
/// Terminate after creating the pipelines.
bool pipeline_create_only;
+ /// Delegate implementation
+ Delegate* delegate;
};
/// Main interface to the Amber environment.
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;
diff --git a/src/amber.cc b/src/amber.cc
index 4b4da3f..ea2b584 100644
--- a/src/amber.cc
+++ b/src/amber.cc
@@ -29,6 +29,8 @@
namespace amber {
+Delegate::~Delegate() = default;
+
Amber::Amber() = default;
Amber::~Amber() = default;
@@ -77,7 +79,8 @@ Result CreateEngineAndCheckRequirements(const Recipe* recipe,
// Engine initialization checks requirements. Current backends don't do
// much else. Refactor this if they end up doing to much here.
- Result r = engine->Initialize(opts->config, script->GetRequiredFeatures(),
+ Result r = engine->Initialize(opts->config, opts->delegate,
+ script->GetRequiredFeatures(),
script->GetRequiredInstanceExtensions(),
script->GetRequiredDeviceExtensions());
if (!r.IsSuccess())
diff --git a/src/dawn/engine_dawn.cc b/src/dawn/engine_dawn.cc
index b6f3773..e5d3fa2 100644
--- a/src/dawn/engine_dawn.cc
+++ b/src/dawn/engine_dawn.cc
@@ -182,6 +182,7 @@ EngineDawn::EngineDawn() : Engine() {}
EngineDawn::~EngineDawn() = default;
Result EngineDawn::Initialize(EngineConfig* config,
+ Delegate*,
const std::vector<std::string>&,
const std::vector<std::string>&,
const std::vector<std::string>&) {
diff --git a/src/dawn/engine_dawn.h b/src/dawn/engine_dawn.h
index 93e27af..ddbca26 100644
--- a/src/dawn/engine_dawn.h
+++ b/src/dawn/engine_dawn.h
@@ -37,6 +37,7 @@ class EngineDawn : public Engine {
// Engine
// Initialize with given configuration data.
Result Initialize(EngineConfig* config,
+ Delegate*,
const std::vector<std::string>& features,
const std::vector<std::string>& instance_extensions,
const std::vector<std::string>& device_extensions) override;
diff --git a/src/engine.h b/src/engine.h
index 5eea840..0b63f88 100644
--- a/src/engine.h
+++ b/src/engine.h
@@ -85,6 +85,7 @@ class Engine {
/// otherwise.
virtual Result Initialize(
EngineConfig* config,
+ Delegate* delegate,
const std::vector<std::string>& features,
const std::vector<std::string>& instance_extensions,
const std::vector<std::string>& device_extensions) = 0;
diff --git a/src/executor_test.cc b/src/executor_test.cc
index e198bb5..bccccdb 100644
--- a/src/executor_test.cc
+++ b/src/executor_test.cc
@@ -34,6 +34,7 @@ class EngineStub : public Engine {
// Engine
Result Initialize(EngineConfig*,
+ Delegate*,
const std::vector<std::string>& features,
const std::vector<std::string>& instance_exts,
const std::vector<std::string>& device_exts) override {
@@ -214,7 +215,7 @@ class VkScriptExecutorTest : public testing::Test {
const std::vector<std::string>& instance_extensions,
const std::vector<std::string>& device_extensions) {
auto engine = MakeUnique<EngineStub>();
- engine->Initialize(nullptr, features, instance_extensions,
+ engine->Initialize(nullptr, nullptr, features, instance_extensions,
device_extensions);
return std::move(engine);
}
diff --git a/src/vulkan/device.cc b/src/vulkan/device.cc
index 5af9ae6..d2a7145 100644
--- a/src/vulkan/device.cc
+++ b/src/vulkan/device.cc
@@ -15,6 +15,7 @@
#include "src/vulkan/device.h"
#include <cstring>
+#include <iostream>
#include <memory>
#include <set>
#include <string>
@@ -354,20 +355,28 @@ Device::Device(VkInstance instance,
Device::~Device() = default;
-Result Device::LoadVulkanPointers(
- PFN_vkGetInstanceProcAddr getInstanceProcAddr) {
+Result Device::LoadVulkanPointers(PFN_vkGetInstanceProcAddr getInstanceProcAddr,
+ Delegate* delegate) {
+ // Note: logging Vulkan calls is done via the delegate rather than a Vulkan
+ // layer because we want such logging even when Amber is built as a native
+ // executable on Android, where Vulkan layers are usable only with APKs.
+ if (delegate && delegate->LogGraphicsCalls())
+ delegate->Log("Loading Vulkan Pointers");
+
#include "src/vk-wrappers.inc"
+
return {};
}
Result Device::Initialize(
PFN_vkGetInstanceProcAddr getInstanceProcAddr,
+ Delegate* delegate,
const std::vector<std::string>& required_features,
const std::vector<std::string>& required_extensions,
const VkPhysicalDeviceFeatures& available_features,
const VkPhysicalDeviceFeatures2KHR& available_features2,
const std::vector<std::string>& available_extensions) {
- Result r = LoadVulkanPointers(getInstanceProcAddr);
+ Result r = LoadVulkanPointers(getInstanceProcAddr, delegate);
if (!r.IsSuccess())
return r;
diff --git a/src/vulkan/device.h b/src/vulkan/device.h
index 36df393..6706514 100644
--- a/src/vulkan/device.h
+++ b/src/vulkan/device.h
@@ -20,6 +20,7 @@
#include <string>
#include <vector>
+#include "amber/amber.h"
#include "amber/result.h"
#include "amber/vulkan_header.h"
@@ -40,6 +41,7 @@ class Device {
~Device();
Result Initialize(PFN_vkGetInstanceProcAddr getInstanceProcAddr,
+ Delegate* delegate,
const std::vector<std::string>& required_features,
const std::vector<std::string>& required_extensions,
const VkPhysicalDeviceFeatures& available_features,
@@ -62,7 +64,7 @@ class Device {
const VulkanPtrs* GetPtrs() const { return &ptrs_; }
private:
- Result LoadVulkanPointers(PFN_vkGetInstanceProcAddr);
+ Result LoadVulkanPointers(PFN_vkGetInstanceProcAddr, Delegate* delegate);
VkInstance instance_ = VK_NULL_HANDLE;
VkPhysicalDevice physical_device_ = VK_NULL_HANDLE;
diff --git a/src/vulkan/engine_vulkan.cc b/src/vulkan/engine_vulkan.cc
index 85d569e..89eb314 100644
--- a/src/vulkan/engine_vulkan.cc
+++ b/src/vulkan/engine_vulkan.cc
@@ -78,6 +78,7 @@ EngineVulkan::~EngineVulkan() = default;
Result EngineVulkan::Initialize(
EngineConfig* config,
+ Delegate* delegate,
const std::vector<std::string>& features,
const std::vector<std::string>& instance_extensions,
const std::vector<std::string>& device_extensions) {
@@ -105,7 +106,7 @@ Result EngineVulkan::Initialize(
vk_config->queue);
Result r = device_->Initialize(
- vk_config->vkGetInstanceProcAddr, features, device_extensions,
+ vk_config->vkGetInstanceProcAddr, delegate, features, device_extensions,
vk_config->available_features, vk_config->available_features2,
vk_config->available_device_extensions);
if (!r.IsSuccess())
diff --git a/src/vulkan/engine_vulkan.h b/src/vulkan/engine_vulkan.h
index e6bd079..143de06 100644
--- a/src/vulkan/engine_vulkan.h
+++ b/src/vulkan/engine_vulkan.h
@@ -40,6 +40,7 @@ class EngineVulkan : public Engine {
// Engine
Result Initialize(EngineConfig* config,
+ Delegate* delegate,
const std::vector<std::string>& features,
const std::vector<std::string>& instance_extensions,
const std::vector<std::string>& device_extensions) override;
diff --git a/tools/update_vk_wrappers.py b/tools/update_vk_wrappers.py
index 15ffb02..eba68e9 100755
--- a/tools/update_vk_wrappers.py
+++ b/tools/update_vk_wrappers.py
@@ -66,6 +66,7 @@ def read_vk(file):
return methods
+
def gen_wrappers(methods, xml):
content = ""
for method in methods:
@@ -86,20 +87,43 @@ def gen_wrappers(methods, xml):
content += " return Result(\"Vulkan: Unable to "
content += "load {} pointer\");\n".format(method)
content += " }\n"
- content += " ptrs_.{} = [ptr](".format(method)
+
+ # if delegate is not null ...
+ content += " if (delegate && delegate->LogGraphicsCalls()) {\n"
+
+ # ... lambda with delegate calls ...
+ content += " ptrs_.{} = [ptr, delegate](".format(method)
content += ', '.join(str(x) for x in param_vals)
content += ") -> " + data['return_type'] + " {\n"
-
+ content += ' delegate->Log("{}");\n'.format(method)
if data['return_type'] != 'void':
- content += " {} ret = ".format(data['return_type'])
- content += " ptr(" + ", ".join(str(x) for x in param_names) + ");\n"
+ content += " {} ret = ".format(data['return_type'])
+ content += "ptr(" + ", ".join(str(x) for x in param_names) + ");\n"
+ content += " return";
+ if data['return_type'] != 'void':
+ content += " ret"
+ content += ";\n"
+ content += " };\n"
- content += " return";
+ # ... else ...
+ content += " } else {\n"
+
+ # ... simple wrapper lambda ...
+ content += " ptrs_.{} = [ptr](".format(method)
+ content += ', '.join(str(x) for x in param_vals)
+ content += ") -> " + data['return_type'] + " {\n"
+ if data['return_type'] != 'void':
+ content += " {} ret = ".format(data['return_type'])
+ content += "ptr(" + ", ".join(str(x) for x in param_names) + ");\n"
+ content += " return";
if data['return_type'] != 'void':
content += " ret"
content += ";\n"
- content += "};\n"
+ content += " };\n"
+
+ # ... end if
+ content += " }\n"
content += "}\n"
return content