diff options
author | Hugues Evrard <hevrard@users.noreply.github.com> | 2019-03-08 16:28:07 +0100 |
---|---|---|
committer | dan sinclair <dj2@everburning.com> | 2019-03-08 10:28:07 -0500 |
commit | 5bd86e6705c3d91247fbca5c447dc7a6ef054aed (patch) | |
tree | 224ab7504d3472f4b019bdc2584c87055e6a38c5 /src | |
parent | d9e823e5ab380fcf417452581721ad9c3bdcf60b (diff) | |
download | amber-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 'src')
-rw-r--r-- | src/amber.cc | 5 | ||||
-rw-r--r-- | src/dawn/engine_dawn.cc | 1 | ||||
-rw-r--r-- | src/dawn/engine_dawn.h | 1 | ||||
-rw-r--r-- | src/engine.h | 1 | ||||
-rw-r--r-- | src/executor_test.cc | 3 | ||||
-rw-r--r-- | src/vulkan/device.cc | 15 | ||||
-rw-r--r-- | src/vulkan/device.h | 4 | ||||
-rw-r--r-- | src/vulkan/engine_vulkan.cc | 3 | ||||
-rw-r--r-- | src/vulkan/engine_vulkan.h | 1 |
9 files changed, 27 insertions, 7 deletions
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; |