Merge pull request #674 from KhronosGroup/fix-670

MSL: Implement multisampled array textures.
This commit is contained in:
Hans-Kristian Arntzen 2018-09-03 12:28:09 +02:00 committed by GitHub
commit 1391cb5827
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 92 additions and 12 deletions

View File

@ -2,14 +2,13 @@ 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
dist: trusty
before_script:
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew upgrade python3; fi
- ./checkout_glslang_spirv_tools.sh
script:

View File

@ -8,10 +8,10 @@ struct main0_out
float4 FragColor [[color(0)]];
};
fragment main0_out main0(texture2d_ms<float> uSampler [[texture(0)]], texture2d_ms<float> uSamplerArray [[texture(1)]], texture2d_ms<float> uImage [[texture(2)]], texture2d_ms<float> uImageArray [[texture(3)]], sampler uSamplerSmplr [[sampler(0)]], sampler uSamplerArraySmplr [[sampler(1)]])
fragment main0_out main0(texture2d_ms<float> uSampler [[texture(0)]], texture2d_ms<float> 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;
}

View File

@ -0,0 +1,23 @@
#include <metal_stdlib>
#include <simd/simd.h>
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<float> 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;
}

View File

@ -8,10 +8,10 @@ struct main0_out
float4 FragColor [[color(0)]];
};
fragment main0_out main0(texture2d_ms<float> uSampler [[texture(0)]], texture2d_ms<float> uSamplerArray [[texture(1)]], texture2d_ms<float> uImage [[texture(2)]], texture2d_ms<float> uImageArray [[texture(3)]], sampler uSamplerSmplr [[sampler(0)]], sampler uSamplerArraySmplr [[sampler(1)]])
fragment main0_out main0(texture2d_ms<float> uSampler [[texture(0)]], texture2d_ms<float> 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;
}

View File

@ -0,0 +1,23 @@
#include <metal_stdlib>
#include <simd/simd.h>
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<float> 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;
}

View File

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

View File

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

View File

@ -3760,7 +3760,18 @@ string CompilerMSL::image_type_glsl(const SPIRType &type, uint32_t id)
img_type_name += "depth1d_unsupported_by_metal";
break;
case Dim2D:
img_type_name += (img_type.ms ? "depth2d_ms" : (img_type.arrayed ? "depth2d_array" : "depth2d"));
if (img_type.ms && img_type.arrayed)
{
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";
@ -3783,7 +3794,18 @@ string CompilerMSL::image_type_glsl(const SPIRType &type, uint32_t id)
case DimBuffer:
case Dim2D:
case DimSubpassData:
img_type_name += (img_type.ms ? "texture2d_ms" : (img_type.arrayed ? "texture2d_array" : "texture2d"));
if (img_type.ms && img_type.arrayed)
{
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";

View File

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