# Conflicts:
#	test_shaders.py
This commit is contained in:
Robert Konrad 2017-01-26 09:49:52 +01:00
commit 9ebc93a820
3 changed files with 22 additions and 9 deletions

View File

@ -10,8 +10,8 @@ struct UBO
struct main0_in
{
float3 aNormal [[attribute(1)]];
float4 aVertex [[attribute(0)]];
float3 aNormal [[attribute(0)]];
};
struct main0_out

View File

@ -4,8 +4,10 @@ layout(std140) uniform UBO
{
uniform mat4 uMVP;
};
in vec4 aVertex;
in vec3 aNormal;
layout(location = 0) in vec4 aVertex;
layout(location = 1) in vec3 aNormal;
out vec3 vNormal;
void main()

View File

@ -2,6 +2,7 @@
import sys
import os
import os.path
import subprocess
import tempfile
import re
@ -10,6 +11,8 @@ import hashlib
import shutil
import argparse
METALC = '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/usr/bin/metal'
def parse_stats(stats):
m = re.search('([0-9]+) work registers', stats)
registers = int(m.group(1)) if m else 0
@ -60,11 +63,8 @@ def get_shader_stats(shader):
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):
subprocess.check_call([METALC, '-x', 'metal', '-std=ios-metal1.0', '-Werror', shader])
def cross_compile_msl(shader):
spirv_f, spirv_path = tempfile.mkstemp()
@ -76,7 +76,9 @@ def cross_compile_msl(shader):
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.
if os.path.exists(METALC):
validate_shader_msl(msl_path)
return (spirv_path, msl_path)
def cross_compile_hlsl(shader):
@ -92,6 +94,12 @@ def cross_compile_hlsl(shader):
# TODO: Add optional validation of the HLSL output.
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))
@ -297,6 +305,9 @@ def main():
sys.stderr.write('Need shader folder.\n')
sys.exit(1)
if os.path.exists(METALC):
subprocess.check_call([METALC, '--version'])
test_shaders(args.folder, args.update, args.malisc, args.keep, 'metal' if args.metal else ('hlsl' if args.hlsl else 'glsl'))
if args.malisc:
print('Stats in stats.csv!')