diff options
author | Sarah <9856269+sarahM0@users.noreply.github.com> | 2019-04-08 17:06:01 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-08 17:06:01 -0400 |
commit | 77b90e8d22a2a6191f058adcfba51076b115f112 (patch) | |
tree | ee59d1051ccf7cbad6fd0cc305c3cf0d92e18dd5 /samples/config_helper_dawn.cc | |
parent | 6a392679a1bb1feb7ae8d93ab2e70cf4fc8c6bb0 (diff) | |
download | amber-77b90e8d22a2a6191f058adcfba51076b115f112.tar.gz |
Update Dawn config file (#440)
* support Vulkan for the Dawn backend
* DoClear
* make same config file to work for metal
* fix clang-format
Diffstat (limited to 'samples/config_helper_dawn.cc')
-rw-r--r-- | samples/config_helper_dawn.cc | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/samples/config_helper_dawn.cc b/samples/config_helper_dawn.cc index eeb66f3..32c4869 100644 --- a/samples/config_helper_dawn.cc +++ b/samples/config_helper_dawn.cc @@ -13,18 +13,12 @@ // limitations under the License. #include "samples/config_helper_dawn.h" - #include <iostream> #include "samples/dawn_device_metal.h" - namespace sample { - ConfigHelperDawn::ConfigHelperDawn() = default; - ConfigHelperDawn::~ConfigHelperDawn() = default; - -namespace { -// Callback which prints a message from a Dawn device operation. +namespace { // Callback which prints a message from a Dawn device operation. void PrintDeviceError(const char* message, ::dawn::CallbackUserdata) { std::cout << "Device error: " << message << std::endl; } @@ -39,22 +33,32 @@ amber::Result ConfigHelperDawn::CreateConfig( bool, bool, std::unique_ptr<amber::EngineConfig>* config) { -#if AMBER_DAWN_METAL - auto r = dawn::CreateMetalDevice(&dawn_instance_, &dawn_device_); - if (!r.IsSuccess()) - return r; -#else - return amber::Result("Can't make Dawn engine config"); -#endif // Set procedure table and error callback. - dawnProcTable backendProcs = dawn_native::GetProcs(); + DawnProcTable backendProcs = dawn_native::GetProcs(); dawnSetProcs(&backendProcs); - backendProcs.deviceSetErrorCallback(dawn_device_.Get(), PrintDeviceError, 0); + dawn_instance_.DiscoverDefaultAdapters(); + for (dawn_native::Adapter& adapter : dawn_instance_.GetAdapters()) { +#if AMBER_DAWN_METAL + ::dawn_native::BackendType backendType = ::dawn_native::BackendType::Metal; +#else // assuming VULKAN + ::dawn_native::BackendType backendType = ::dawn_native::BackendType::Vulkan; +#endif + + if (adapter.GetBackendType() == backendType) { + dawn_device_ = ::dawn::Device::Acquire(adapter.CreateDevice()); + } + } + + if (!dawn_device_) + return amber::Result("could not find Vulkan or Metal backend for Dawn"); + + backendProcs.deviceSetErrorCallback(dawn_device_.Get(), PrintDeviceError, 0); auto* dawn_config = new amber::DawnEngineConfig; dawn_config->device = &dawn_device_; config->reset(dawn_config); + return {}; } |