1e5c31af7Sopenharmony_ci// Copyright 2019 The Amber Authors. 2e5c31af7Sopenharmony_ci// 3e5c31af7Sopenharmony_ci// Licensed under the Apache License, Version 2.0 (the "License"); 4e5c31af7Sopenharmony_ci// you may not use this file except in compliance with the License. 5e5c31af7Sopenharmony_ci// You may obtain a copy of the License at 6e5c31af7Sopenharmony_ci// 7e5c31af7Sopenharmony_ci// http://www.apache.org/licenses/LICENSE-2.0 8e5c31af7Sopenharmony_ci// 9e5c31af7Sopenharmony_ci// Unless required by applicable law or agreed to in writing, software 10e5c31af7Sopenharmony_ci// distributed under the License is distributed on an "AS IS" BASIS, 11e5c31af7Sopenharmony_ci// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12e5c31af7Sopenharmony_ci// See the License for the specific language governing permissions and 13e5c31af7Sopenharmony_ci// limitations under the License. 14e5c31af7Sopenharmony_ci 15e5c31af7Sopenharmony_ci#include "samples/config_helper.h" 16e5c31af7Sopenharmony_ci 17e5c31af7Sopenharmony_ci#include <algorithm> 18e5c31af7Sopenharmony_ci#include <set> 19e5c31af7Sopenharmony_ci#include <string> 20e5c31af7Sopenharmony_ci#include <vector> 21e5c31af7Sopenharmony_ci 22e5c31af7Sopenharmony_ci#include "src/make_unique.h" 23e5c31af7Sopenharmony_ci 24e5c31af7Sopenharmony_ci#if AMBER_ENGINE_DAWN 25e5c31af7Sopenharmony_ci#include "samples/config_helper_dawn.h" 26e5c31af7Sopenharmony_ci#endif // AMBER_ENGINE_DAWN 27e5c31af7Sopenharmony_ci#if AMBER_ENGINE_VULKAN 28e5c31af7Sopenharmony_ci#include "samples/config_helper_vulkan.h" 29e5c31af7Sopenharmony_ci#endif // AMBER_ENGINE_VULKAN 30e5c31af7Sopenharmony_ci 31e5c31af7Sopenharmony_cinamespace sample { 32e5c31af7Sopenharmony_ci 33e5c31af7Sopenharmony_ciConfigHelperImpl::~ConfigHelperImpl() = default; 34e5c31af7Sopenharmony_ci 35e5c31af7Sopenharmony_ciConfigHelper::ConfigHelper() = default; 36e5c31af7Sopenharmony_ci 37e5c31af7Sopenharmony_ciConfigHelper::~ConfigHelper() = default; 38e5c31af7Sopenharmony_ci 39e5c31af7Sopenharmony_ciamber::Result ConfigHelper::CreateConfig( 40e5c31af7Sopenharmony_ci amber::EngineType engine, 41e5c31af7Sopenharmony_ci uint32_t engine_major, 42e5c31af7Sopenharmony_ci uint32_t engine_minor, 43e5c31af7Sopenharmony_ci int32_t selected_device, 44e5c31af7Sopenharmony_ci const std::vector<std::string>& required_features, 45e5c31af7Sopenharmony_ci const std::vector<std::string>& required_instance_extensions, 46e5c31af7Sopenharmony_ci const std::vector<std::string>& required_device_extensions, 47e5c31af7Sopenharmony_ci bool disable_validation_layer, 48e5c31af7Sopenharmony_ci bool show_version_info, 49e5c31af7Sopenharmony_ci std::unique_ptr<amber::EngineConfig>* config) { 50e5c31af7Sopenharmony_ci switch (engine) { 51e5c31af7Sopenharmony_ci case amber::kEngineTypeVulkan: 52e5c31af7Sopenharmony_ci#if AMBER_ENGINE_VULKAN 53e5c31af7Sopenharmony_ci impl_ = amber::MakeUnique<ConfigHelperVulkan>(); 54e5c31af7Sopenharmony_ci break; 55e5c31af7Sopenharmony_ci#else 56e5c31af7Sopenharmony_ci return amber::Result("Unable to create engine config for Vulkan"); 57e5c31af7Sopenharmony_ci#endif // AMBER_ENGINE_VULKAN 58e5c31af7Sopenharmony_ci case amber::kEngineTypeDawn: 59e5c31af7Sopenharmony_ci#if AMBER_ENGINE_DAWN 60e5c31af7Sopenharmony_ci impl_ = amber::MakeUnique<ConfigHelperDawn>(); 61e5c31af7Sopenharmony_ci break; 62e5c31af7Sopenharmony_ci#else 63e5c31af7Sopenharmony_ci return amber::Result("Unable to create engine config for Dawn"); 64e5c31af7Sopenharmony_ci#endif // AMBER_ENGINE_DAWN 65e5c31af7Sopenharmony_ci } 66e5c31af7Sopenharmony_ci 67e5c31af7Sopenharmony_ci if (!impl_) 68e5c31af7Sopenharmony_ci return amber::Result("Unable to create config helper"); 69e5c31af7Sopenharmony_ci 70e5c31af7Sopenharmony_ci return impl_->CreateConfig( 71e5c31af7Sopenharmony_ci engine_major, engine_minor, selected_device, required_features, 72e5c31af7Sopenharmony_ci required_instance_extensions, required_device_extensions, 73e5c31af7Sopenharmony_ci disable_validation_layer, show_version_info, config); 74e5c31af7Sopenharmony_ci} 75e5c31af7Sopenharmony_ci 76e5c31af7Sopenharmony_ci} // namespace sample 77