1 // Copyright 2015 The Shaderc Authors. All rights reserved. 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 LIBSHADERC_SRC_SHADERC_PRIVATE_H_ 16 #define LIBSHADERC_SRC_SHADERC_PRIVATE_H_ 17 18 #include <cstdint> 19 #include <string> 20 #include <vector> 21 22 #include "shaderc/shaderc.h" 23 24 #include "spirv-tools/libspirv.h" 25 26 // Described in shaderc.h. 27 struct shaderc_compilation_result { 28 virtual ~shaderc_compilation_result() {} 29 30 // Returns the data from this compilation as a sequence of bytes. 31 virtual const char* GetBytes() const = 0; 32 33 // The size of the output data in term of bytes. 34 size_t output_data_size = 0; 35 // Compilation messages. 36 std::string messages; 37 // Number of errors. 38 size_t num_errors = 0; 39 // Number of warnings. 40 size_t num_warnings = 0; 41 // Compilation status. 42 shaderc_compilation_status compilation_status = 43 shaderc_compilation_status_null_result_object; 44 }; 45 46 // Compilation result class using a vector for holding the compilation 47 // output data. 48 class shaderc_compilation_result_vector : public shaderc_compilation_result { 49 public: 50 ~shaderc_compilation_result_vector() = default; 51 52 void SetOutputData(std::vector<uint32_t>&& data) { 53 output_data_ = std::move(data); 54 } 55 56 const char* GetBytes() const override { 57 return reinterpret_cast<const char*>(output_data_.data()); 58 } 59 60 private: 61 // Compilation output data. In normal compilation mode, it contains the 62 // compiled SPIR-V binary code. In disassembly and preprocessing-only mode, it 63 // contains a null-terminated string which is the text output. For text 64 // output, extra bytes with value 0x00 might be appended to complete the last 65 // uint32_t element. 66 std::vector<uint32_t> output_data_; 67 }; 68 69 // Compilation result class using a spv_binary for holding the compilation 70 // output data. 71 class shaderc_compilation_result_spv_binary 72 : public shaderc_compilation_result { 73 public: 74 ~shaderc_compilation_result_spv_binary() { spvBinaryDestroy(output_data_); } 75 76 void SetOutputData(spv_binary data) { output_data_ = data; } 77 78 const char* GetBytes() const override { 79 return reinterpret_cast<const char*>(output_data_->code); 80 } 81 82 private: 83 spv_binary output_data_ = nullptr; 84 }; 85 86 namespace shaderc_util { 87 class GlslInitializer; 88 } 89 90 struct shaderc_compiler { 91 shaderc_util::GlslInitializer* initializer; 92 }; 93 94 #endif // LIBSHADERC_SRC_SHADERC_PRIVATE_H_ 95