From 77b90e8d22a2a6191f058adcfba51076b115f112 Mon Sep 17 00:00:00 2001 From: Sarah <9856269+sarahM0@users.noreply.github.com> Date: Mon, 8 Apr 2019 17:06:01 -0400 Subject: Update Dawn config file (#440) * support Vulkan for the Dawn backend * DoClear * make same config file to work for metal * fix clang-format --- samples/config_helper_dawn.cc | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) (limited to 'samples/config_helper_dawn.cc') 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 #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* 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 {}; } -- cgit v1.2.3