From 778f998cd26fa203bcd0d7fceaaa1723ca317975 Mon Sep 17 00:00:00 2001 From: Hans-Kristian Arntzen Date: Mon, 3 Sep 2018 10:21:59 +0200 Subject: [PATCH 1/4] MSL: Throw error on multisampled array textures. --- .../desktop-only/frag/sampler-ms-query.desktop.frag | 4 ++-- .../desktop-only/frag/sampler-ms-query.desktop.frag | 4 ++-- shaders-msl/desktop-only/frag/sampler-ms-query.desktop.frag | 4 +--- spirv_msl.cpp | 4 ++++ 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/reference/opt/shaders-msl/desktop-only/frag/sampler-ms-query.desktop.frag b/reference/opt/shaders-msl/desktop-only/frag/sampler-ms-query.desktop.frag index 937e2746..a6f06064 100644 --- a/reference/opt/shaders-msl/desktop-only/frag/sampler-ms-query.desktop.frag +++ b/reference/opt/shaders-msl/desktop-only/frag/sampler-ms-query.desktop.frag @@ -8,10 +8,10 @@ struct main0_out float4 FragColor [[color(0)]]; }; -fragment main0_out main0(texture2d_ms uSampler [[texture(0)]], texture2d_ms uSamplerArray [[texture(1)]], texture2d_ms uImage [[texture(2)]], texture2d_ms uImageArray [[texture(3)]], sampler uSamplerSmplr [[sampler(0)]], sampler uSamplerArraySmplr [[sampler(1)]]) +fragment main0_out main0(texture2d_ms uSampler [[texture(0)]], texture2d_ms uImage [[texture(2)]], sampler uSamplerSmplr [[sampler(0)]]) { main0_out out = {}; - out.FragColor = float4(float(((int(uSampler.get_num_samples()) + int(uSamplerArray.get_num_samples())) + int(uImage.get_num_samples())) + int(uImageArray.get_num_samples()))); + out.FragColor = float4(float(int(uSampler.get_num_samples()) + int(uImage.get_num_samples()))); return out; } diff --git a/reference/shaders-msl/desktop-only/frag/sampler-ms-query.desktop.frag b/reference/shaders-msl/desktop-only/frag/sampler-ms-query.desktop.frag index 937e2746..a6f06064 100644 --- a/reference/shaders-msl/desktop-only/frag/sampler-ms-query.desktop.frag +++ b/reference/shaders-msl/desktop-only/frag/sampler-ms-query.desktop.frag @@ -8,10 +8,10 @@ struct main0_out float4 FragColor [[color(0)]]; }; -fragment main0_out main0(texture2d_ms uSampler [[texture(0)]], texture2d_ms uSamplerArray [[texture(1)]], texture2d_ms uImage [[texture(2)]], texture2d_ms uImageArray [[texture(3)]], sampler uSamplerSmplr [[sampler(0)]], sampler uSamplerArraySmplr [[sampler(1)]]) +fragment main0_out main0(texture2d_ms uSampler [[texture(0)]], texture2d_ms uImage [[texture(2)]], sampler uSamplerSmplr [[sampler(0)]]) { main0_out out = {}; - out.FragColor = float4(float(((int(uSampler.get_num_samples()) + int(uSamplerArray.get_num_samples())) + int(uImage.get_num_samples())) + int(uImageArray.get_num_samples()))); + out.FragColor = float4(float(int(uSampler.get_num_samples()) + int(uImage.get_num_samples()))); return out; } diff --git a/shaders-msl/desktop-only/frag/sampler-ms-query.desktop.frag b/shaders-msl/desktop-only/frag/sampler-ms-query.desktop.frag index 4c30ed15..4c8dcf97 100644 --- a/shaders-msl/desktop-only/frag/sampler-ms-query.desktop.frag +++ b/shaders-msl/desktop-only/frag/sampler-ms-query.desktop.frag @@ -1,14 +1,12 @@ #version 450 layout(binding = 0) uniform sampler2DMS uSampler; -layout(binding = 1) uniform sampler2DMSArray uSamplerArray; layout(binding = 2, rgba8) uniform readonly writeonly image2DMS uImage; -layout(binding = 3, rgba8) uniform readonly writeonly image2DMSArray uImageArray; layout(location = 0) out vec4 FragColor; void main() { - FragColor = vec4(float(((textureSamples(uSampler) + textureSamples(uSamplerArray)) + imageSamples(uImage)) + imageSamples(uImageArray))); + FragColor = vec4(float(textureSamples(uSampler) + imageSamples(uImage))); } diff --git a/spirv_msl.cpp b/spirv_msl.cpp index 05bfb378..7d73132b 100644 --- a/spirv_msl.cpp +++ b/spirv_msl.cpp @@ -3760,6 +3760,8 @@ string CompilerMSL::image_type_glsl(const SPIRType &type, uint32_t id) img_type_name += "depth1d_unsupported_by_metal"; break; case Dim2D: + if (img_type.ms && img_type.arrayed) + SPIRV_CROSS_THROW("Multisampled array textures are not yet supported in MSL."); img_type_name += (img_type.ms ? "depth2d_ms" : (img_type.arrayed ? "depth2d_array" : "depth2d")); break; case Dim3D: @@ -3783,6 +3785,8 @@ string CompilerMSL::image_type_glsl(const SPIRType &type, uint32_t id) case DimBuffer: case Dim2D: case DimSubpassData: + if (img_type.ms && img_type.arrayed) + SPIRV_CROSS_THROW("Multisampled array textures are not yet supported in MSL."); img_type_name += (img_type.ms ? "texture2d_ms" : (img_type.arrayed ? "texture2d_array" : "texture2d")); break; case Dim3D: From 0c1d4d8b6a1a0c7979434bd3dd1fc0dac19a6a2c Mon Sep 17 00:00:00 2001 From: Hans-Kristian Arntzen Date: Mon, 3 Sep 2018 11:02:31 +0200 Subject: [PATCH 2/4] MSL: Support texture2d_ms_array. --- .travis.yml | 2 +- .../frag/texture-multisample-array.msl21.frag | 23 ++++++++++++++++ .../frag/texture-multisample-array.msl21.frag | 23 ++++++++++++++++ .../frag/texture-multisample-array.msl21.frag | 10 +++++++ spirv_msl.cpp | 26 ++++++++++++++++--- test_shaders.py | 7 ++++- 6 files changed, 85 insertions(+), 6 deletions(-) create mode 100644 reference/opt/shaders-msl/frag/texture-multisample-array.msl21.frag create mode 100644 reference/shaders-msl/frag/texture-multisample-array.msl21.frag create mode 100644 shaders-msl/frag/texture-multisample-array.msl21.frag diff --git a/.travis.yml b/.travis.yml index 8e09d619..b5119929 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ language: cpp os: - linux - osx -osx_image: xcode9.3beta +osx_image: xcode10 # Use Ubuntu 14.04 LTS (Trusty) as the Linux testing environment. sudo: required diff --git a/reference/opt/shaders-msl/frag/texture-multisample-array.msl21.frag b/reference/opt/shaders-msl/frag/texture-multisample-array.msl21.frag new file mode 100644 index 00000000..ed1e81f3 --- /dev/null +++ b/reference/opt/shaders-msl/frag/texture-multisample-array.msl21.frag @@ -0,0 +1,23 @@ +#include +#include + +using namespace metal; + +struct main0_out +{ + float4 FragColor [[color(0)]]; +}; + +struct main0_in +{ + int3 vCoord [[user(locn0)]]; + int vSample [[user(locn1)]]; +}; + +fragment main0_out main0(main0_in in [[stage_in]], texture2d_ms_array uTexture [[texture(0)]], sampler uTextureSmplr [[sampler(0)]]) +{ + main0_out out = {}; + out.FragColor = uTexture.read(uint2(in.vCoord.xy), uint(in.vCoord.z), in.vSample); + return out; +} + diff --git a/reference/shaders-msl/frag/texture-multisample-array.msl21.frag b/reference/shaders-msl/frag/texture-multisample-array.msl21.frag new file mode 100644 index 00000000..ed1e81f3 --- /dev/null +++ b/reference/shaders-msl/frag/texture-multisample-array.msl21.frag @@ -0,0 +1,23 @@ +#include +#include + +using namespace metal; + +struct main0_out +{ + float4 FragColor [[color(0)]]; +}; + +struct main0_in +{ + int3 vCoord [[user(locn0)]]; + int vSample [[user(locn1)]]; +}; + +fragment main0_out main0(main0_in in [[stage_in]], texture2d_ms_array uTexture [[texture(0)]], sampler uTextureSmplr [[sampler(0)]]) +{ + main0_out out = {}; + out.FragColor = uTexture.read(uint2(in.vCoord.xy), uint(in.vCoord.z), in.vSample); + return out; +} + diff --git a/shaders-msl/frag/texture-multisample-array.msl21.frag b/shaders-msl/frag/texture-multisample-array.msl21.frag new file mode 100644 index 00000000..ede809bd --- /dev/null +++ b/shaders-msl/frag/texture-multisample-array.msl21.frag @@ -0,0 +1,10 @@ +#version 450 +layout(location = 0) out vec4 FragColor; +layout(binding = 0) uniform sampler2DMSArray uTexture; +layout(location = 0) flat in ivec3 vCoord; +layout(location = 1) flat in int vSample; + +void main() +{ + FragColor = texelFetch(uTexture, vCoord, vSample); +} diff --git a/spirv_msl.cpp b/spirv_msl.cpp index 7d73132b..3ec43e86 100644 --- a/spirv_msl.cpp +++ b/spirv_msl.cpp @@ -3761,8 +3761,17 @@ string CompilerMSL::image_type_glsl(const SPIRType &type, uint32_t id) break; case Dim2D: if (img_type.ms && img_type.arrayed) - SPIRV_CROSS_THROW("Multisampled array textures are not yet supported in MSL."); - img_type_name += (img_type.ms ? "depth2d_ms" : (img_type.arrayed ? "depth2d_array" : "depth2d")); + { + if (!msl_options.supports_msl_version(2, 1)) + SPIRV_CROSS_THROW("Multisampled array textures are supported from 2.1."); + img_type_name += "depth2d_ms_array"; + } + else if (img_type.ms) + img_type_name += "depth2d_ms"; + else if (img_type.arrayed) + img_type_name += "depth2d_array"; + else + img_type_name += "depth2d"; break; case Dim3D: img_type_name += "depth3d_unsupported_by_metal"; @@ -3786,8 +3795,17 @@ string CompilerMSL::image_type_glsl(const SPIRType &type, uint32_t id) case Dim2D: case DimSubpassData: if (img_type.ms && img_type.arrayed) - SPIRV_CROSS_THROW("Multisampled array textures are not yet supported in MSL."); - img_type_name += (img_type.ms ? "texture2d_ms" : (img_type.arrayed ? "texture2d_array" : "texture2d")); + { + if (!msl_options.supports_msl_version(2, 1)) + SPIRV_CROSS_THROW("Multisampled array textures are supported from 2.1."); + img_type_name += "texture2d_ms_array"; + } + else if (img_type.ms) + img_type_name += "texture2d_ms"; + else if (img_type.arrayed) + img_type_name += "texture2d_array"; + else + img_type_name += "texture2d"; break; case Dim3D: img_type_name += "texture3d"; diff --git a/test_shaders.py b/test_shaders.py index 40e1c2e2..40ae1500 100755 --- a/test_shaders.py +++ b/test_shaders.py @@ -89,10 +89,11 @@ def print_msl_compiler_version(): def validate_shader_msl(shader, opt): msl_path = reference_path(shader[0], shader[1], opt) msl2 = '.msl2.' in msl_path + msl21 = '.msl21.' in msl_path try: msl_os = 'macosx' # msl_os = 'iphoneos' - subprocess.check_call(['xcrun', '--sdk', msl_os, 'metal', '-x', 'metal', '-std=osx-metal{}'.format('2.0' if msl2 else '1.2'), '-Werror', '-Wno-unused-variable', msl_path]) + subprocess.check_call(['xcrun', '--sdk', msl_os, 'metal', '-x', 'metal', '-std=osx-metal{}'.format('2.1' if msl21 else ('2.0' if msl2 else '1.2')), '-Werror', '-Wno-unused-variable', msl_path]) print('Compiled Metal shader: ' + msl_path) # display after so xcrun FNF is silent except OSError as oe: if (oe.errno != errno.ENOENT): # Ignore xcrun not found error @@ -103,6 +104,7 @@ def validate_shader_msl(shader, opt): def cross_compile_msl(shader, spirv, opt): msl2 = '.msl2.' in shader + msl21 = '.msl21.' in shader spirv_path = create_temporary() msl_path = create_temporary(os.path.basename(shader)) @@ -120,6 +122,9 @@ def cross_compile_msl(shader, spirv, opt): if msl2: msl_args.append('--msl-version') msl_args.append('20000') + elif msl21: + msl_args.append('--msl-version') + msl_args.append('20100') subprocess.check_call(msl_args) From ea65ec4ac6900c5b0530397e919e42d77e58d451 Mon Sep 17 00:00:00 2001 From: Hans-Kristian Arntzen Date: Mon, 3 Sep 2018 11:15:03 +0200 Subject: [PATCH 3/4] brew update python3 fails on xcode10 image. --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b5119929..becc7cb5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,6 @@ sudo: required dist: trusty before_script: - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew upgrade python3; fi - ./checkout_glslang_spirv_tools.sh script: From 452a65324e095c6aa77b1f8406fe9490cfefc531 Mon Sep 17 00:00:00 2001 From: Hans-Kristian Arntzen Date: Mon, 3 Sep 2018 12:03:14 +0200 Subject: [PATCH 4/4] Use new macos -std= flag in Metal compiler. --- test_shaders.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_shaders.py b/test_shaders.py index 40ae1500..be54eaa8 100755 --- a/test_shaders.py +++ b/test_shaders.py @@ -93,7 +93,7 @@ def validate_shader_msl(shader, opt): try: msl_os = 'macosx' # msl_os = 'iphoneos' - subprocess.check_call(['xcrun', '--sdk', msl_os, 'metal', '-x', 'metal', '-std=osx-metal{}'.format('2.1' if msl21 else ('2.0' if msl2 else '1.2')), '-Werror', '-Wno-unused-variable', msl_path]) + subprocess.check_call(['xcrun', '--sdk', msl_os, 'metal', '-x', 'metal', '-std=macos-metal{}'.format('2.1' if msl21 else ('2.0' if msl2 else '1.2')), '-Werror', '-Wno-unused-variable', msl_path]) print('Compiled Metal shader: ' + msl_path) # display after so xcrun FNF is silent except OSError as oe: if (oe.errno != errno.ENOENT): # Ignore xcrun not found error