1 // Copyright 2018 The Amber Authors.
2 // Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15
16 #include "src/script.h"
17
18 #include "src/make_unique.h"
19 #include "src/type_parser.h"
20
21 namespace amber {
22
Script()23 Script::Script() : virtual_files_(MakeUnique<VirtualFileStore>()) {}
24
25 Script::~Script() = default;
26
GetShaderInfo() const27 std::vector<ShaderInfo> Script::GetShaderInfo() const {
28 std::vector<ShaderInfo> ret;
29 for (const auto& shader : shaders_) {
30 bool in_pipeline = false;
31 // A given shader could be in multiple pipelines with different
32 // optimizations so make sure we check and report all pipelines.
33 for (const auto& pipeline : pipelines_) {
34 auto shader_info = pipeline->GetShader(shader.get());
35 if (shader_info) {
36 ret.emplace_back(
37 ShaderInfo{shader->GetFormat(), shader->GetType(),
38 pipeline->GetName() + "-" + shader->GetName(),
39 shader->GetData(), shader_info->GetShaderOptimizations(),
40 shader->GetTargetEnv(), shader_info->GetData()});
41
42 in_pipeline = true;
43 }
44 }
45
46 if (!in_pipeline) {
47 ret.emplace_back(ShaderInfo{shader->GetFormat(),
48 shader->GetType(),
49 shader->GetName(),
50 shader->GetData(),
51 {},
52 shader->GetTargetEnv(),
53 {}});
54 }
55 }
56 return ret;
57 }
58
AddRequiredExtension(const std::string & ext)59 void Script::AddRequiredExtension(const std::string& ext) {
60 // Make this smarter when we have more instance extensions to match.
61 if (ext == "VK_KHR_get_physical_device_properties2")
62 AddRequiredInstanceExtension(ext);
63 else
64 AddRequiredDeviceExtension(ext);
65 }
66
IsKnownFeature(const std::string & name) const67 bool Script::IsKnownFeature(const std::string& name) const {
68 return name == "robustBufferAccess" || name == "fullDrawIndexUint32" ||
69 name == "imageCubeArray" || name == "independentBlend" ||
70 name == "geometryShader" || name == "tessellationShader" ||
71 name == "sampleRateShading" || name == "dualSrcBlend" ||
72 name == "logicOp" || name == "multiDrawIndirect" ||
73 name == "drawIndirectFirstInstance" || name == "depthClamp" ||
74 name == "depthBiasClamp" || name == "fillModeNonSolid" ||
75 name == "depthBounds" || name == "wideLines" ||
76 name == "largePoints" || name == "alphaToOne" ||
77 name == "multiViewport" || name == "samplerAnisotropy" ||
78 name == "textureCompressionETC2" ||
79 name == "textureCompressionASTC_LDR" ||
80 name == "textureCompressionBC" || name == "occlusionQueryPrecise" ||
81 name == "pipelineStatisticsQuery" ||
82 name == "vertexPipelineStoresAndAtomics" ||
83 name == "fragmentStoresAndAtomics" ||
84 name == "shaderTessellationAndGeometryPointSize" ||
85 name == "shaderImageGatherExtended" ||
86 name == "shaderStorageImageExtendedFormats" ||
87 name == "shaderStorageImageMultisample" ||
88 name == "shaderStorageImageReadWithoutFormat" ||
89 name == "shaderStorageImageWriteWithoutFormat" ||
90 name == "shaderUniformBufferArrayDynamicIndexing" ||
91 name == "shaderSampledImageArrayDynamicIndexing" ||
92 name == "shaderStorageBufferArrayDynamicIndexing" ||
93 name == "shaderStorageImageArrayDynamicIndexing" ||
94 name == "shaderClipDistance" || name == "shaderCullDistance" ||
95 name == "shaderFloat64" || name == "shaderInt64" ||
96 name == "shaderInt16" || name == "shaderResourceResidency" ||
97 name == "shaderResourceMinLod" || name == "sparseBinding" ||
98 name == "sparseResidencyBuffer" || name == "sparseResidencyImage2D" ||
99 name == "sparseResidencyImage3D" ||
100 name == "sparseResidency2Samples" ||
101 name == "sparseResidency4Samples" ||
102 name == "sparseResidency8Samples" ||
103 name == "sparseResidency16Samples" ||
104 name == "sparseResidencyAliased" ||
105 name == "variableMultisampleRate" || name == "inheritedQueries" ||
106 name == "VariablePointerFeatures.variablePointers" ||
107 name == "VariablePointerFeatures.variablePointersStorageBuffer" ||
108 name == "Float16Int8Features.shaderFloat16" ||
109 name == "Float16Int8Features.shaderInt8" ||
110 name == "Storage8BitFeatures.storageBuffer8BitAccess" ||
111 name == "Storage8BitFeatures.uniformAndStorageBuffer8BitAccess" ||
112 name == "Storage8BitFeatures.storagePushConstant8" ||
113 name == "Storage16BitFeatures.storageBuffer16BitAccess" ||
114 name == "Storage16BitFeatures.uniformAndStorageBuffer16BitAccess" ||
115 name == "Storage16BitFeatures.storagePushConstant16" ||
116 name == "Storage16BitFeatures.storageInputOutput16" ||
117 name == "SubgroupSizeControl.subgroupSizeControl" ||
118 name == "SubgroupSizeControl.computeFullSubgroups" ||
119 name == "SubgroupSupportedOperations.basic" ||
120 name == "SubgroupSupportedOperations.vote" ||
121 name == "SubgroupSupportedOperations.arithmetic" ||
122 name == "SubgroupSupportedOperations.ballot" ||
123 name == "SubgroupSupportedOperations.shuffle" ||
124 name == "SubgroupSupportedOperations.shuffleRelative" ||
125 name == "SubgroupSupportedOperations.clustered" ||
126 name == "SubgroupSupportedOperations.quad" ||
127 name == "SubgroupSupportedStages.vertex" ||
128 name == "SubgroupSupportedStages.tessellationControl" ||
129 name == "SubgroupSupportedStages.tessellationEvaluation" ||
130 name == "SubgroupSupportedStages.geometry" ||
131 name == "SubgroupSupportedStages.fragment" ||
132 name == "SubgroupSupportedStages.compute" ||
133 name == "IndexTypeUint8Features.indexTypeUint8" ||
134 name ==
135 "ShaderSubgroupExtendedTypesFeatures"
136 ".shaderSubgroupExtendedTypes" ||
137 name == "RayTracingPipelineFeaturesKHR.rayTracingPipeline" ||
138 name == "AccelerationStructureFeaturesKHR.accelerationStructure" ||
139 name == "BufferDeviceAddressFeatures.bufferDeviceAddress";
140 }
141
IsKnownProperty(const std::string & name) const142 bool Script::IsKnownProperty(const std::string& name) const {
143 return name ==
144 "FloatControlsProperties.shaderSignedZeroInfNanPreserveFloat16" ||
145 name ==
146 "FloatControlsProperties.shaderSignedZeroInfNanPreserveFloat32" ||
147 name ==
148 "FloatControlsProperties.shaderSignedZeroInfNanPreserveFloat64" ||
149 name == "FloatControlsProperties.shaderDenormPreserveFloat16" ||
150 name == "FloatControlsProperties.shaderDenormPreserveFloat32" ||
151 name == "FloatControlsProperties.shaderDenormPreserveFloat64" ||
152 name == "FloatControlsProperties.shaderDenormFlushToZeroFloat16" ||
153 name == "FloatControlsProperties.shaderDenormFlushToZeroFloat32" ||
154 name == "FloatControlsProperties.shaderDenormFlushToZeroFloat64" ||
155 name == "FloatControlsProperties.shaderRoundingModeRTEFloat16" ||
156 name == "FloatControlsProperties.shaderRoundingModeRTEFloat32" ||
157 name == "FloatControlsProperties.shaderRoundingModeRTEFloat64" ||
158 name == "FloatControlsProperties.shaderRoundingModeRTZFloat16" ||
159 name == "FloatControlsProperties.shaderRoundingModeRTZFloat32" ||
160 name == "FloatControlsProperties.shaderRoundingModeRTZFloat64";
161 }
162
ParseType(const std::string & str)163 type::Type* Script::ParseType(const std::string& str) {
164 auto type = GetType(str);
165 if (type)
166 return type;
167
168 TypeParser parser;
169 auto new_type = parser.Parse(str);
170 if (new_type != nullptr) {
171 type = new_type.get();
172 RegisterType(std::move(new_type));
173 }
174 return type;
175 }
176
177 } // namespace amber
178