1 // Copyright 2018 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 "src/script.h"
16
17 #include "src/make_unique.h"
18 #include "src/type_parser.h"
19
20 namespace amber {
21
Script()22 Script::Script() : virtual_files_(MakeUnique<VirtualFileStore>()) {}
23
24 Script::~Script() = default;
25
GetShaderInfo() const26 std::vector<ShaderInfo> Script::GetShaderInfo() const {
27 std::vector<ShaderInfo> ret;
28 for (const auto& shader : shaders_) {
29 bool in_pipeline = false;
30 // A given shader could be in multiple pipelines with different
31 // optimizations so make sure we check and report all pipelines.
32 for (const auto& pipeline : pipelines_) {
33 auto shader_info = pipeline->GetShader(shader.get());
34 if (shader_info) {
35 ret.emplace_back(
36 ShaderInfo{shader->GetFormat(), shader->GetType(),
37 pipeline->GetName() + "-" + shader->GetName(),
38 shader->GetData(), shader_info->GetShaderOptimizations(),
39 shader->GetTargetEnv(), shader_info->GetData()});
40
41 in_pipeline = true;
42 }
43 }
44
45 if (!in_pipeline) {
46 ret.emplace_back(ShaderInfo{shader->GetFormat(),
47 shader->GetType(),
48 shader->GetName(),
49 shader->GetData(),
50 {},
51 shader->GetTargetEnv(),
52 {}});
53 }
54 }
55 return ret;
56 }
57
AddRequiredExtension(const std::string & ext)58 void Script::AddRequiredExtension(const std::string& ext) {
59 // Make this smarter when we have more instance extensions to match.
60 if (ext == "VK_KHR_get_physical_device_properties2")
61 AddRequiredInstanceExtension(ext);
62 else
63 AddRequiredDeviceExtension(ext);
64 }
65
IsKnownFeature(const std::string & name) const66 bool Script::IsKnownFeature(const std::string& name) const {
67 return name == "robustBufferAccess" || name == "fullDrawIndexUint32" ||
68 name == "imageCubeArray" || name == "independentBlend" ||
69 name == "geometryShader" || name == "tessellationShader" ||
70 name == "sampleRateShading" || name == "dualSrcBlend" ||
71 name == "logicOp" || name == "multiDrawIndirect" ||
72 name == "drawIndirectFirstInstance" || name == "depthClamp" ||
73 name == "depthBiasClamp" || name == "fillModeNonSolid" ||
74 name == "depthBounds" || name == "wideLines" ||
75 name == "largePoints" || name == "alphaToOne" ||
76 name == "multiViewport" || name == "samplerAnisotropy" ||
77 name == "textureCompressionETC2" ||
78 name == "textureCompressionASTC_LDR" ||
79 name == "textureCompressionBC" || name == "occlusionQueryPrecise" ||
80 name == "pipelineStatisticsQuery" ||
81 name == "vertexPipelineStoresAndAtomics" ||
82 name == "fragmentStoresAndAtomics" ||
83 name == "shaderTessellationAndGeometryPointSize" ||
84 name == "shaderImageGatherExtended" ||
85 name == "shaderStorageImageExtendedFormats" ||
86 name == "shaderStorageImageMultisample" ||
87 name == "shaderStorageImageReadWithoutFormat" ||
88 name == "shaderStorageImageWriteWithoutFormat" ||
89 name == "shaderUniformBufferArrayDynamicIndexing" ||
90 name == "shaderSampledImageArrayDynamicIndexing" ||
91 name == "shaderStorageBufferArrayDynamicIndexing" ||
92 name == "shaderStorageImageArrayDynamicIndexing" ||
93 name == "shaderClipDistance" || name == "shaderCullDistance" ||
94 name == "shaderFloat64" || name == "shaderInt64" ||
95 name == "shaderInt16" || name == "shaderResourceResidency" ||
96 name == "shaderResourceMinLod" || name == "sparseBinding" ||
97 name == "sparseResidencyBuffer" || name == "sparseResidencyImage2D" ||
98 name == "sparseResidencyImage3D" ||
99 name == "sparseResidency2Samples" ||
100 name == "sparseResidency4Samples" ||
101 name == "sparseResidency8Samples" ||
102 name == "sparseResidency16Samples" ||
103 name == "sparseResidencyAliased" ||
104 name == "variableMultisampleRate" || name == "inheritedQueries" ||
105 name == "VariablePointerFeatures.variablePointers" ||
106 name == "VariablePointerFeatures.variablePointersStorageBuffer" ||
107 name == "Float16Int8Features.shaderFloat16" ||
108 name == "Float16Int8Features.shaderInt8" ||
109 name == "Storage8BitFeatures.storageBuffer8BitAccess" ||
110 name == "Storage8BitFeatures.uniformAndStorageBuffer8BitAccess" ||
111 name == "Storage8BitFeatures.storagePushConstant8" ||
112 name == "Storage16BitFeatures.storageBuffer16BitAccess" ||
113 name == "Storage16BitFeatures.uniformAndStorageBuffer16BitAccess" ||
114 name == "Storage16BitFeatures.storagePushConstant16" ||
115 name == "Storage16BitFeatures.storageInputOutput16" ||
116 name == "SubgroupSizeControl.subgroupSizeControl" ||
117 name == "SubgroupSizeControl.computeFullSubgroups";
118 }
119
ParseType(const std::string & str)120 type::Type* Script::ParseType(const std::string& str) {
121 auto type = GetType(str);
122 if (type)
123 return type;
124
125 TypeParser parser;
126 auto new_type = parser.Parse(str);
127 if (new_type != nullptr) {
128 type = new_type.get();
129 RegisterType(std::move(new_type));
130 }
131 return type;
132 }
133
134 } // namespace amber
135