diff --git a/main.cpp b/main.cpp index c1b9f632..ebb10f60 100644 --- a/main.cpp +++ b/main.cpp @@ -401,11 +401,13 @@ struct CLIArguments bool metal = false; bool vulkan_semantics = false; bool remove_unused = false; + bool cfg_analysis = true; }; static void print_help() { - fprintf(stderr, "Usage: spirv-cross [--output ] [SPIR-V file] [--es] [--no-es] [--version ] [SPIR-V file] [--es] [--no-es] [--no-cfg-analysis] " + "[--version ] [--dump-resources] [--help] [--force-temporary] [--cpp] [--cpp-interface-name ] " "[--metal] [--vulkan-semantics] [--flatten-ubo] [--fixup-clipspace] [--iterations iter] [--pls-in " "format input-name] [--pls-out format output-name] [--remap source_name target_name components] " @@ -519,6 +521,7 @@ int main(int argc, char *argv[]) args.version = parser.next_uint(); args.set_version = true; }); + cbs.add("--no-cfg-analysis", [&args](CLIParser &) { args.cfg_analysis = false; }); cbs.add("--dump-resources", [&args](CLIParser &) { args.dump_resources = true; }); cbs.add("--force-temporary", [&args](CLIParser &) { args.force_temporary = true; }); cbs.add("--flatten-ubo", [&args](CLIParser &) { args.flatten_ubo = true; }); @@ -623,6 +626,7 @@ int main(int argc, char *argv[]) opts.force_temporary = args.force_temporary; opts.vulkan_semantics = args.vulkan_semantics; opts.vertex.fixup_clipspace = args.fixup; + opts.cfg_analysis = args.cfg_analysis; compiler->set_options(opts); ShaderResources res; diff --git a/spirv_common.hpp b/spirv_common.hpp index 1bb464ca..d9e2ccd6 100644 --- a/spirv_common.hpp +++ b/spirv_common.hpp @@ -513,6 +513,7 @@ struct SPIRFunction : IVariant bool active = false; bool flush_undeclared = true; bool do_combined_parameters = true; + bool analyzed_variable_scope = false; }; struct SPIRVariable : IVariant diff --git a/spirv_cross.hpp b/spirv_cross.hpp index a271b57c..36c5bc5e 100644 --- a/spirv_cross.hpp +++ b/spirv_cross.hpp @@ -578,10 +578,6 @@ private: ShaderResources get_shader_resources(const std::unordered_set *active_variables) const; VariableTypeRemapCallback variable_remap_callback; - - SPIRBlock &find_common_dominator( - const SPIRBlock &entry, uint32_t variable, - const std::unordered_map> &block_to_variable_map); }; } diff --git a/spirv_glsl.cpp b/spirv_glsl.cpp index e78976f2..042a98c2 100644 --- a/spirv_glsl.cpp +++ b/spirv_glsl.cpp @@ -5232,9 +5232,17 @@ void CompilerGLSL::emit_function(SPIRFunction &func, uint64_t return_flags) } } - analyze_variable_scope(func); - auto &entry_block = get(func.entry_block); + + if (!func.analyzed_variable_scope) + { + if (options.cfg_analysis) + analyze_variable_scope(func); + else + entry_block.dominated_variables = func.local_variables; + func.analyzed_variable_scope = true; + } + entry_block.loop_dominator = SPIRBlock::NoDominator; emit_block_chain(entry_block); diff --git a/spirv_glsl.hpp b/spirv_glsl.hpp index 04a03bff..41372a34 100644 --- a/spirv_glsl.hpp +++ b/spirv_glsl.hpp @@ -60,6 +60,9 @@ public: bool es = false; bool force_temporary = false; + // If true, variables will be moved to their appropriate scope through CFG analysis. + bool cfg_analysis = true; + // If true, Vulkan GLSL features are used instead of GL-compatible features. // Mostly useful for debugging SPIR-V files. bool vulkan_semantics = false;