Validate Metal shaders on OSX with Metal compiler
If we run on a system with Xcode installed to a default path, run Xcode
Metal shader compiler to validate the generated MSL shader.
This uncovers an issue in the existing MSL test - MSL backend currently
does not auto-assign attribute locations, which means that translating
GLSL shader without location layout produces an invalid MSL which
generates "error: 'attribute' index '0' is used more than once".
diff --git a/test_shaders.py b/test_shaders.py
index 97d09bd..a3004f4 100755
--- a/test_shaders.py
+++ b/test_shaders.py
@@ -2,6 +2,7 @@
import sys
import os
+import os.path
import subprocess
import tempfile
import re
@@ -60,11 +61,10 @@
returned = stdout.decode('utf-8')
return parse_stats(returned)
-def validate_shader(shader, vulkan):
- if vulkan:
- subprocess.check_call(['glslangValidator', '-V', shader])
- else:
- subprocess.check_call(['glslangValidator', shader])
+def validate_shader_msl(shader):
+ path = "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/usr/bin/metal"
+ if os.path.exists(path):
+ subprocess.check_call([path, '-x', 'metal', '-std=ios-metal1.0', '-Werror', shader])
def cross_compile_msl(shader):
spirv_f, spirv_path = tempfile.mkstemp()
@@ -76,9 +76,16 @@
subprocess.check_call([spirv_cross_path, '--entry', 'main', '--output', msl_path, spirv_path, '--metal'])
subprocess.check_call(['spirv-val', spirv_path])
- # TODO: Add optional validation of the MSL output.
+ validate_shader_msl(msl_path)
+
return (spirv_path, msl_path)
+def validate_shader(shader, vulkan):
+ if vulkan:
+ subprocess.check_call(['glslangValidator', '-V', shader])
+ else:
+ subprocess.check_call(['glslangValidator', shader])
+
def cross_compile(shader, vulkan, spirv, invalid_spirv, eliminate, is_legacy, flatten_ubo):
spirv_f, spirv_path = tempfile.mkstemp()
glsl_f, glsl_path = tempfile.mkstemp(suffix = os.path.basename(shader))