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