MSL fixes from review of PR 134.

Remove unnecessary use of std:: prefix in spirv_msl.cpp.
Use typedef instead of #define.
spirv-cross deprecate --metal CLI option and replace with --msl option.
This commit is contained in:
Bill Hollings 2017-03-19 21:06:21 -04:00
parent 52a5597161
commit 5ad73f33f5
5 changed files with 24 additions and 24 deletions

View File

@ -288,7 +288,7 @@ See `./test_shaders.py --help` for more.
### Metal backend
To test the roundtrip path GLSL -> SPIR-V -> MSL, `--metal` can be added, e.g. `./test_shaders.py --metal shaders-msl`.
To test the roundtrip path GLSL -> SPIR-V -> MSL, `--msl` can be added, e.g. `./test_shaders.py --msl shaders-msl`.
### HLSL backend

View File

@ -432,7 +432,7 @@ struct CLIArguments
uint32_t iterations = 1;
bool cpp = false;
bool metal = false;
bool msl = false;
bool msl_pack_ubos = true;
bool hlsl = false;
bool vulkan_semantics = false;
@ -443,10 +443,11 @@ struct CLIArguments
static void print_help()
{
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] [--hlsl] [--shader-model] [--vulkan-semantics] [--flatten-ubo] [--fixup-clipspace] "
"[--iterations iter] "
"[--version <GLSL version>] [--dump-resources] [--help] [--force-temporary] "
"[--vulkan-semantics] [--flatten-ubo] [--fixup-clipspace] [--iterations iter] "
"[--cpp] [--cpp-interface-name <name>] "
"[--msl] [--msl-no-pack-ubos] "
"[--hlsl] [--shader-model] "
"[--pls-in format input-name] [--pls-out format output-name] [--remap source_name target_name "
"components] [--extension ext] [--entry name] [--remove-unused-variables] "
"[--remap-variable-type <variable_name> <new_variable_type>]\n");
@ -566,7 +567,8 @@ int main(int argc, char *argv[])
cbs.add("--iterations", [&args](CLIParser &parser) { args.iterations = parser.next_uint(); });
cbs.add("--cpp", [&args](CLIParser &) { args.cpp = true; });
cbs.add("--cpp-interface-name", [&args](CLIParser &parser) { args.cpp_interface_name = parser.next_string(); });
cbs.add("--metal", [&args](CLIParser &) { args.metal = true; });
cbs.add("--metal", [&args](CLIParser &) { args.msl = true; }); // Legacy compatibility
cbs.add("--msl", [&args](CLIParser &) { args.msl = true; });
cbs.add("--msl-no-pack-ubos", [&args](CLIParser &) { args.msl_pack_ubos = false; });
cbs.add("--hlsl", [&args](CLIParser &) { args.hlsl = true; });
cbs.add("--vulkan-semantics", [&args](CLIParser &) { args.vulkan_semantics = true; });
@ -632,7 +634,7 @@ int main(int argc, char *argv[])
if (args.cpp_interface_name)
static_cast<CompilerCPP *>(compiler.get())->set_interface_name(args.cpp_interface_name);
}
else if (args.metal)
else if (args.msl)
{
compiler = unique_ptr<CompilerMSL>(new CompilerMSL(read_spirv_file(args.input)));

View File

@ -28,7 +28,7 @@ using namespace std;
static const uint32_t k_unknown_location = ~0;
CompilerMSL::CompilerMSL(vector<uint32_t> spirv_, vector<MSLVertexAttr> *p_vtx_attrs,
std::vector<MSLResourceBinding> *p_res_bindings)
vector<MSLResourceBinding> *p_res_bindings)
: CompilerGLSL(move(spirv_))
{
populate_func_name_overrides();
@ -119,7 +119,7 @@ string CompilerMSL::compile()
return buffer->str();
}
string CompilerMSL::compile(vector<MSLVertexAttr> *p_vtx_attrs, std::vector<MSLResourceBinding> *p_res_bindings)
string CompilerMSL::compile(vector<MSLVertexAttr> *p_vtx_attrs, vector<MSLResourceBinding> *p_res_bindings)
{
if (p_vtx_attrs)
{
@ -139,7 +139,7 @@ string CompilerMSL::compile(vector<MSLVertexAttr> *p_vtx_attrs, std::vector<MSLR
}
string CompilerMSL::compile(MSLConfiguration &msl_cfg, vector<MSLVertexAttr> *p_vtx_attrs,
std::vector<MSLResourceBinding> *p_res_bindings)
vector<MSLResourceBinding> *p_res_bindings)
{
options = msl_cfg;
return compile(p_vtx_attrs, p_res_bindings);
@ -183,7 +183,7 @@ void CompilerMSL::extract_global_variables_from_functions()
{
// Uniforms
std::unordered_set<uint32_t> global_var_ids;
unordered_set<uint32_t> global_var_ids;
for (auto &id : ids)
{
if (id.get_type() == TypeVariable)
@ -203,7 +203,7 @@ void CompilerMSL::extract_global_variables_from_functions()
global_var_ids.insert(var);
std::set<uint32_t> added_arg_ids;
std::unordered_set<uint32_t> processed_func_ids;
unordered_set<uint32_t> processed_func_ids;
extract_global_variables_from_function(entry_point, added_arg_ids, global_var_ids, processed_func_ids);
}
@ -211,8 +211,8 @@ void CompilerMSL::extract_global_variables_from_functions()
// For any global variable accessed directly by the specified function, extract that variable,
// add it as an argument to that function, and the arg to the added_arg_ids collection.
void CompilerMSL::extract_global_variables_from_function(uint32_t func_id, std::set<uint32_t> &added_arg_ids,
std::unordered_set<uint32_t> &global_var_ids,
std::unordered_set<uint32_t> &processed_func_ids)
unordered_set<uint32_t> &global_var_ids,
unordered_set<uint32_t> &processed_func_ids)
{
// Avoid processing a function more than once
if (processed_func_ids.find(func_id) != processed_func_ids.end())
@ -1814,7 +1814,7 @@ string CompilerMSL::to_qualified_member_name(const SPIRType &type, uint32_t inde
// Strip any underscore prefix from member name
string mbr_name = to_member_name(type, index);
size_t startPos = mbr_name.find_first_not_of("_");
mbr_name = (startPos != std::string::npos) ? mbr_name.substr(startPos) : "";
mbr_name = (startPos != string::npos) ? mbr_name.substr(startPos) : "";
return join(to_name(type.self), "_", mbr_name);
}

View File

@ -27,9 +27,6 @@
namespace spirv_cross
{
// Deprecated legacy syntax
#define MSLConfiguration CompilerMSL::Options
// Defines MSL characteristics of a vertex attribute at a particular location.
// The used_by_shader flag is set to true during compilation of SPIR-V to MSL
// if the shader makes use of this vertex attribute.
@ -119,6 +116,7 @@ public:
std::string compile(std::vector<MSLVertexAttr> *p_vtx_attrs, std::vector<MSLResourceBinding> *p_res_bindings);
// This legacy method is deprecated.
typedef Options MSLConfiguration;
std::string compile(MSLConfiguration &msl_cfg, std::vector<MSLVertexAttr> *p_vtx_attrs = nullptr,
std::vector<MSLResourceBinding> *p_res_bindings = nullptr);

View File

@ -91,7 +91,7 @@ def cross_compile_msl(shader):
os.close(msl_f)
subprocess.check_call(['glslangValidator', '-V', '-o', spirv_path, shader])
spirv_cross_path = './spirv-cross'
subprocess.check_call([spirv_cross_path, '--entry', 'main', '--output', msl_path, spirv_path, '--metal'])
subprocess.check_call([spirv_cross_path, '--entry', 'main', '--output', msl_path, spirv_path, '--msl'])
subprocess.check_call(['spirv-val', spirv_path])
return (spirv_path, msl_path)
@ -294,7 +294,7 @@ def test_shaders_helper(stats, shader_dir, update, malisc, keep, backend):
for i in files:
path = os.path.join(root, i)
relpath = os.path.relpath(path, shader_dir)
if backend == 'metal':
if backend == 'msl':
test_shader_msl(stats, (shader_dir, relpath), update, keep)
elif backend == 'hlsl':
test_shader_hlsl(stats, (shader_dir, relpath), update, keep)
@ -322,7 +322,7 @@ def main():
parser.add_argument('--malisc',
action = 'store_true',
help = 'Use malisc offline compiler to determine static cycle counts before and after spirv-cross.')
parser.add_argument('--metal',
parser.add_argument('--msl',
action = 'store_true',
help = 'Test Metal backend.')
parser.add_argument('--hlsl',
@ -337,13 +337,13 @@ def main():
sys.stderr.write('Need shader folder.\n')
sys.exit(1)
if args.metal:
if args.msl:
print_msl_compiler_version()
global force_no_external_validation
force_no_external_validation = args.force_no_external_validation
test_shaders(args.folder, args.update, args.malisc, args.keep, 'metal' if args.metal else ('hlsl' if args.hlsl else 'glsl'))
test_shaders(args.folder, args.update, args.malisc, args.keep, 'msl' if args.msl else ('hlsl' if args.hlsl else 'glsl'))
if args.malisc:
print('Stats in stats.csv!')
print('Tests completed!')