Cleanup, and make cfg analysis optional.

This commit is contained in:
Hans-Kristian Arntzen 2016-11-18 17:06:49 +01:00
parent 5ff11cc689
commit b847c88559
5 changed files with 19 additions and 7 deletions

View File

@ -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 <output path>] [SPIR-V file] [--es] [--no-es] [--version <GLSL "
fprintf(stderr, "Usage: spirv-cross [--output <output path>] [SPIR-V file] [--es] [--no-es] [--no-cfg-analysis] "
"[--version <GLSL "
"version>] [--dump-resources] [--help] [--force-temporary] [--cpp] [--cpp-interface-name <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;

View File

@ -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

View File

@ -578,10 +578,6 @@ private:
ShaderResources get_shader_resources(const std::unordered_set<uint32_t> *active_variables) const;
VariableTypeRemapCallback variable_remap_callback;
SPIRBlock &find_common_dominator(
const SPIRBlock &entry, uint32_t variable,
const std::unordered_map<uint32_t, std::unordered_set<uint32_t>> &block_to_variable_map);
};
}

View File

@ -5232,9 +5232,17 @@ void CompilerGLSL::emit_function(SPIRFunction &func, uint64_t return_flags)
}
}
analyze_variable_scope(func);
auto &entry_block = get<SPIRBlock>(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);

View File

@ -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;