diff options
author | Lei Zhang <antiagainst@google.com> | 2016-09-30 13:07:25 -0400 |
---|---|---|
committer | Lei Zhang <antiagainst@google.com> | 2016-09-30 16:58:10 -0400 |
commit | 501a864298b6c66074366deb0a8b3256dd3f0b18 (patch) | |
tree | 26ebcd5cf6c53611180c2f627e98baa1cff3bd97 | |
parent | 987b74e63a685872853b9244766120ecce1a0b6d (diff) | |
download | shaderc-501a864298b6c66074366deb0a8b3256dd3f0b18.tar.gz |
Chanage the C interface for assembling to accept options.
Also together with the C interface change, new overloads for assembling
are added into the C++ interface.
-rw-r--r-- | libshaderc/include/shaderc/shaderc.h | 5 | ||||
-rw-r--r-- | libshaderc/include/shaderc/shaderc.hpp | 27 | ||||
-rw-r--r-- | libshaderc/src/shaderc.cc | 3 | ||||
-rw-r--r-- | libshaderc/src/shaderc_test.cc | 5 |
4 files changed, 34 insertions, 6 deletions
diff --git a/libshaderc/include/shaderc/shaderc.h b/libshaderc/include/shaderc/shaderc.h index e798229..46d98b4 100644 --- a/libshaderc/include/shaderc/shaderc.h +++ b/libshaderc/include/shaderc/shaderc.h @@ -295,12 +295,15 @@ shaderc_compilation_result_t shaderc_compile_into_preprocessed_text( // (https://github.com/KhronosGroup/SPIRV-Tools/blob/master/syntax.md), // assembles it into SPIR-V binary and a shaderc_compilation_result will be // returned to hold the results. +// The assembling will pick options suitable for assembling specified in the +// additional_options parameter. // May be safely called from multiple threads without explicit synchronization. // If there was failure in allocating the compiler object, null will be // returned. shaderc_compilation_result_t shaderc_assemble_into_spv( const shaderc_compiler_t compiler, const char* source_assembly, - size_t source_assembly_size); + size_t source_assembly_size, + const shaderc_compile_options_t additional_options); // The following functions, operating on shaderc_compilation_result_t objects, // offer only the basic thread-safety guarantee. diff --git a/libshaderc/include/shaderc/shaderc.hpp b/libshaderc/include/shaderc/shaderc.hpp index 1666397..4e5dfd7 100644 --- a/libshaderc/include/shaderc/shaderc.hpp +++ b/libshaderc/include/shaderc/shaderc.hpp @@ -334,19 +334,42 @@ class Compiler { // (https://github.com/KhronosGroup/SPIRV-Tools/blob/master/syntax.md). // It is valid for the returned CompilationResult object to outlive this // compiler object. + // The assembling will pick options suitable for assembling specified in the + // CompileOptions parameter. + SpvCompilationResult AssembleToSpv(const char* source_assembly, + size_t source_assembly_size, + const CompileOptions& options) const { + return SpvCompilationResult(shaderc_assemble_into_spv( + compiler_, source_assembly, source_assembly_size, options.options_)); + } + + // Assembles the given SPIR-V assembly and returns a SPIR-V binary module + // compilation result. + // Like the first AssembleToSpv method but uses the default compiler options. SpvCompilationResult AssembleToSpv(const char* source_assembly, size_t source_assembly_size) const { return SpvCompilationResult(shaderc_assemble_into_spv( - compiler_, source_assembly, source_assembly_size)); + compiler_, source_assembly, source_assembly_size, nullptr)); } // Assembles the given SPIR-V assembly and returns a SPIR-V binary module // compilation result. // Like the first AssembleToSpv method but the source is provided as a // std::string. + SpvCompilationResult AssembleToSpv(const std::string& source_assembly, + const CompileOptions& options) const { + return SpvCompilationResult( + shaderc_assemble_into_spv(compiler_, source_assembly.data(), + source_assembly.size(), options.options_)); + } + + // Assembles the given SPIR-V assembly and returns a SPIR-V binary module + // compilation result. + // Like the first AssembleToSpv method but the source is provided as a + // std::string and also uses default compiler options. SpvCompilationResult AssembleToSpv(const std::string& source_assembly) const { return SpvCompilationResult(shaderc_assemble_into_spv( - compiler_, source_assembly.data(), source_assembly.size())); + compiler_, source_assembly.data(), source_assembly.size(), nullptr)); } // Compiles the given source GLSL and returns the SPIR-V assembly text diff --git a/libshaderc/src/shaderc.cc b/libshaderc/src/shaderc.cc index 55f9b4b..f301158 100644 --- a/libshaderc/src/shaderc.cc +++ b/libshaderc/src/shaderc.cc @@ -458,7 +458,8 @@ shaderc_compilation_result_t shaderc_compile_into_preprocessed_text( shaderc_compilation_result_t shaderc_assemble_into_spv( const shaderc_compiler_t compiler, const char* source_assembly, - size_t source_assembly_size) { + size_t source_assembly_size, + const shaderc_compile_options_t /* additional_options */) { auto* result = new (std::nothrow) shaderc_compilation_result_spv_binary; if (!result) return nullptr; result->compilation_status = shaderc_compilation_status_invalid_assembly; diff --git a/libshaderc/src/shaderc_test.cc b/libshaderc/src/shaderc_test.cc index 878f3d5..6de7053 100644 --- a/libshaderc/src/shaderc_test.cc +++ b/libshaderc/src/shaderc_test.cc @@ -122,9 +122,10 @@ class Compilation { class Assembling { public: // Assembles shader and keeps the result. - Assembling(const shaderc_compiler_t compiler, const std::string& assembly) + Assembling(const shaderc_compiler_t compiler, const std::string& assembly, + const shaderc_compile_options_t options = nullptr) : compiled_result_(shaderc_assemble_into_spv(compiler, assembly.data(), - assembly.size())) {} + assembly.size(), options)) {} ~Assembling() { shaderc_result_release(compiled_result_); } |