1 // Copyright 2020 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_WRITER_SPIRV_GENERATOR_H_ 16 #define SRC_WRITER_SPIRV_GENERATOR_H_ 17 18 #include <memory> 19 #include <string> 20 #include <vector> 21 22 #include "src/writer/writer.h" 23 24 namespace tint { 25 26 // Forward declarations 27 class Program; 28 29 namespace writer { 30 namespace spirv { 31 32 /// Forward declarations 33 class Builder; 34 class BinaryWriter; 35 36 /// Configuration options used for generating SPIR-V. 37 struct Options { 38 /// Set to `true` to generate a PointSize builtin and have it set to 1.0 39 /// from all vertex shaders in the module. 40 bool emit_vertex_point_size = true; 41 42 /// Set to `true` to disable workgroup memory zero initialization 43 bool disable_workgroup_init = false; 44 }; 45 46 /// The result produced when generating SPIR-V. 47 struct Result { 48 /// Constructor 49 Result(); 50 51 /// Destructor 52 ~Result(); 53 54 /// Copy constructor 55 Result(const Result&); 56 57 /// True if generation was successful. 58 bool success = false; 59 60 /// The errors generated during code generation, if any. 61 std::string error; 62 63 /// The generated SPIR-V. 64 std::vector<uint32_t> spirv; 65 }; 66 67 /// Generate SPIR-V for a program, according to a set of configuration options. 68 /// The result will contain the SPIR-V, as well as success status and diagnostic 69 /// information. 70 /// @param program the program to translate to SPIR-V 71 /// @param options the configuration options to use when generating SPIR-V 72 /// @returns the resulting SPIR-V and supplementary information 73 Result Generate(const Program* program, const Options& options); 74 75 } // namespace spirv 76 } // namespace writer 77 } // namespace tint 78 79 #endif // SRC_WRITER_SPIRV_GENERATOR_H_ 80