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 enable_pipeline_runtime_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 enable_pipeline_runtime_layer,
49 bool show_version_info,
50 std::unique_ptr<amber::EngineConfig>* config) {
51 switch (engine) {
52 case amber::kEngineTypeVulkan:
53 #if AMBER_ENGINE_VULKAN
54 impl_ = amber::MakeUnique<ConfigHelperVulkan>();
55 break;
56 #else
57 return amber::Result("Unable to create engine config for Vulkan");
58 #endif // AMBER_ENGINE_VULKAN
59 case amber::kEngineTypeDawn:
60 #if AMBER_ENGINE_DAWN
61 impl_ = amber::MakeUnique<ConfigHelperDawn>();
62 break;
63 #else
64 return amber::Result("Unable to create engine config for Dawn");
65 #endif // AMBER_ENGINE_DAWN
66 }
67
68 if (!impl_)
69 return amber::Result("Unable to create config helper");
70
71 return impl_->CreateConfig(
72 engine_major, engine_minor, selected_device, required_features,
73 required_instance_extensions, required_device_extensions,
74 disable_validation_layer, enable_pipeline_runtime_layer,
75 show_version_info, config);
76 }
77
78 } // namespace sample
79