From 9bad477f16000587c5320698509739e304f78069 Mon Sep 17 00:00:00 2001 From: Hans-Kristian Arntzen Date: Sat, 1 Apr 2017 16:08:19 +0200 Subject: [PATCH] Add vector-less IR construction to subclasses as well. --- spirv_cpp.hpp | 6 ++++++ spirv_glsl.hpp | 22 +++++++++++++++++----- spirv_hlsl.hpp | 5 +++++ spirv_msl.cpp | 18 +++++++++++++++--- spirv_msl.hpp | 6 ++++++ 5 files changed, 49 insertions(+), 8 deletions(-) diff --git a/spirv_cpp.hpp b/spirv_cpp.hpp index c6f2880a..89850076 100644 --- a/spirv_cpp.hpp +++ b/spirv_cpp.hpp @@ -30,6 +30,12 @@ public: : CompilerGLSL(move(spirv_)) { } + + CompilerCPP(const uint32_t *ir, size_t word_count) + : CompilerGLSL(ir, word_count) + { + } + std::string compile() override; // Sets a custom symbol name that can override diff --git a/spirv_glsl.hpp b/spirv_glsl.hpp index a32eb1df..81be16fc 100644 --- a/spirv_glsl.hpp +++ b/spirv_glsl.hpp @@ -100,11 +100,13 @@ public: CompilerGLSL(std::vector spirv_) : Compiler(move(spirv_)) { - if (source.known) - { - options.es = source.es; - options.version = source.version; - } + init(); + } + + CompilerGLSL(const uint32_t *ir, size_t word_count) + : Compiler(ir, word_count) + { + init(); } const Options &get_options() const @@ -446,6 +448,16 @@ protected: void fixup_image_load_store_access(); bool type_is_empty(const SPIRType &type); + +private: + void init() + { + if (source.known) + { + options.es = source.es; + options.version = source.version; + } + } }; } diff --git a/spirv_hlsl.hpp b/spirv_hlsl.hpp index 1b535504..c59222e8 100644 --- a/spirv_hlsl.hpp +++ b/spirv_hlsl.hpp @@ -38,6 +38,11 @@ public: { } + CompilerHLSL(const uint32_t *ir, size_t size) + : CompilerGLSL(ir, size) + { + } + const Options &get_options() const { return options; diff --git a/spirv_msl.cpp b/spirv_msl.cpp index 77495405..36b6e5a5 100644 --- a/spirv_msl.cpp +++ b/spirv_msl.cpp @@ -27,9 +27,7 @@ using namespace std; static const uint32_t k_unknown_location = ~0; -CompilerMSL::CompilerMSL(vector spirv_, vector *p_vtx_attrs, - vector *p_res_bindings) - : CompilerGLSL(move(spirv_)) +void CompilerMSL::init(vector *p_vtx_attrs, vector *p_res_bindings) { populate_func_name_overrides(); populate_var_name_overrides(); @@ -43,6 +41,20 @@ CompilerMSL::CompilerMSL(vector spirv_, vector *p_vtx_a resource_bindings.push_back(&rb); } +CompilerMSL::CompilerMSL(vector spirv_, vector *p_vtx_attrs, + vector *p_res_bindings) + : CompilerGLSL(move(spirv_)) +{ + init(p_vtx_attrs, p_res_bindings); +} + +CompilerMSL::CompilerMSL(const uint32_t *ir, size_t word_count, vector *p_vtx_attrs, + vector *p_res_bindings) + : CompilerGLSL(ir, word_count) +{ + init(p_vtx_attrs, p_res_bindings); +} + // Populate the collection of function names that need to be overridden void CompilerMSL::populate_func_name_overrides() { diff --git a/spirv_msl.hpp b/spirv_msl.hpp index 319c87b7..e93011a3 100644 --- a/spirv_msl.hpp +++ b/spirv_msl.hpp @@ -106,6 +106,9 @@ public: CompilerMSL(std::vector spirv, std::vector *p_vtx_attrs = nullptr, std::vector *p_res_bindings = nullptr); + CompilerMSL(const uint32_t *ir, size_t word_count, std::vector *p_vtx_attrs = nullptr, + std::vector *p_res_bindings = nullptr); + // Compiles the SPIR-V code into Metal Shading Language. std::string compile() override; @@ -249,6 +252,9 @@ protected: Meta &meta; SortAspect sort_aspect; }; + +private: + void init(std::vector *p_vtx_attrs, std::vector *p_res_bindings); }; }