1 // Copyright 2021 The Tint 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 #ifndef SRC_VAL_VAL_H_ 16 #define SRC_VAL_VAL_H_ 17 18 #include <string> 19 #include <utility> 20 #include <vector> 21 22 #include "src/ast/pipeline_stage.h" 23 24 // Forward declarations 25 namespace tint { 26 class Program; 27 } // namespace tint 28 29 namespace tint { 30 namespace val { 31 32 using EntryPointList = std::vector<std::pair<std::string, ast::PipelineStage>>; 33 34 /// The return structure of Validate() 35 struct Result { 36 /// True if validation passed 37 bool failed = false; 38 /// Output of DXC. 39 std::string output; 40 }; 41 42 /// Hlsl attempts to compile the shader with DXC, verifying that the shader 43 /// compiles successfully. 44 /// @param dxc_path path to DXC 45 /// @param source the generated HLSL source 46 /// @param entry_points the list of entry points to validate 47 /// @return the result of the compile 48 Result HlslUsingDXC(const std::string& dxc_path, 49 const std::string& source, 50 const EntryPointList& entry_points); 51 52 #ifdef _WIN32 53 /// Hlsl attempts to compile the shader with FXC, verifying that the shader 54 /// compiles successfully. 55 /// @param source the generated HLSL source 56 /// @param entry_points the list of entry points to validate 57 /// @return the result of the compile 58 Result HlslUsingFXC(const std::string& source, 59 const EntryPointList& entry_points); 60 #endif // _WIN32 61 62 /// Msl attempts to compile the shader with the Metal Shader Compiler, 63 /// verifying that the shader compiles successfully. 64 /// @param xcrun_path path to xcrun 65 /// @param source the generated MSL source 66 /// @return the result of the compile 67 Result Msl(const std::string& xcrun_path, const std::string& source); 68 69 #ifdef TINT_ENABLE_MSL_VALIDATION_USING_METAL_API 70 /// Msl attempts to compile the shader with the runtime Metal Shader Compiler 71 /// API, verifying that the shader compiles successfully. 72 /// @param source the generated MSL source 73 /// @return the result of the compile 74 Result MslUsingMetalAPI(const std::string& source); 75 #endif // TINT_ENABLE_MSL_VALIDATION_USING_METAL_API 76 77 } // namespace val 78 } // namespace tint 79 80 #endif // SRC_VAL_VAL_H_ 81