From 77f5812c5501b6d28432d59a0b07bec40385af83 Mon Sep 17 00:00:00 2001 From: Bill Hollings Date: Fri, 11 Aug 2017 14:54:58 -0400 Subject: [PATCH] Fix issue #239: compilation of shaders-msl/frag/texture-proj-shadow.frag. Remove unsupported sampler1DShadow from shaders-msl/frag/texture-proj-shadow.frag. Improve error message response from unsupported depth texture formats. Fix several integer cast warnings in unrelated code. Run ./format_all.sh on unrelated files. --- main.cpp | 2 +- .../shaders-msl/frag/texture-proj-shadow.frag | 29 +++++++++++++++++++ shaders-msl/frag/texture-proj-shadow.frag | 19 ++++++++++++ spirv_cross.cpp | 6 ++-- spirv_hlsl.cpp | 4 +-- spirv_msl.cpp | 6 ++++ test_shaders.py | 6 ++-- 7 files changed, 63 insertions(+), 9 deletions(-) create mode 100644 reference/shaders-msl/frag/texture-proj-shadow.frag create mode 100644 shaders-msl/frag/texture-proj-shadow.frag diff --git a/main.cpp b/main.cpp index e3f92795..e5f3b7dd 100644 --- a/main.cpp +++ b/main.cpp @@ -15,9 +15,9 @@ */ #include "spirv_cpp.hpp" +#include "spirv_glsl.hpp" #include "spirv_hlsl.hpp" #include "spirv_msl.hpp" -#include "spirv_glsl.hpp" #include #include #include diff --git a/reference/shaders-msl/frag/texture-proj-shadow.frag b/reference/shaders-msl/frag/texture-proj-shadow.frag new file mode 100644 index 00000000..c31e6d96 --- /dev/null +++ b/reference/shaders-msl/frag/texture-proj-shadow.frag @@ -0,0 +1,29 @@ +#include +#include + +using namespace metal; + +struct main0_in +{ + float2 vClip2 [[user(locn2)]]; + float4 vClip4 [[user(locn1)]]; + float3 vClip3 [[user(locn0)]]; +}; + +struct main0_out +{ + float FragColor [[color(0)]]; +}; + +fragment main0_out main0(main0_in in [[stage_in]], depth2d uShadow2D [[texture(0)]], sampler uShadow2DSmplr [[sampler(0)]], texture1d uSampler1D [[texture(1)]], sampler uSampler1DSmplr [[sampler(1)]], texture2d uSampler2D [[texture(2)]], sampler uSampler2DSmplr [[sampler(2)]], texture3d uSampler3D [[texture(3)]], sampler uSampler3DSmplr [[sampler(3)]]) +{ + main0_out out = {}; + float4 _20 = in.vClip4; + _20.z = in.vClip4.w; + out.FragColor = uShadow2D.sample_compare(uShadow2DSmplr, _20.xy / _20.z, in.vClip4.z); + out.FragColor = uSampler1D.sample(uSampler1DSmplr, in.vClip2.x / in.vClip2.y).x; + out.FragColor = uSampler2D.sample(uSampler2DSmplr, in.vClip3.xy / in.vClip3.z).x; + out.FragColor = uSampler3D.sample(uSampler3DSmplr, in.vClip4.xyz / in.vClip4.w).x; + return out; +} + diff --git a/shaders-msl/frag/texture-proj-shadow.frag b/shaders-msl/frag/texture-proj-shadow.frag new file mode 100644 index 00000000..547532e6 --- /dev/null +++ b/shaders-msl/frag/texture-proj-shadow.frag @@ -0,0 +1,19 @@ +#version 450 + +layout(binding = 1) uniform sampler2DShadow uShadow2D; +layout(binding = 2) uniform sampler1D uSampler1D; +layout(binding = 3) uniform sampler2D uSampler2D; +layout(binding = 4) uniform sampler3D uSampler3D; + +layout(location = 0) out float FragColor; +layout(location = 0) in vec3 vClip3; +layout(location = 1) in vec4 vClip4; +layout(location = 2) in vec2 vClip2; + +void main() +{ + FragColor = textureProj(uShadow2D, vClip4); + FragColor = textureProj(uSampler1D, vClip2).x; + FragColor = textureProj(uSampler2D, vClip3).x; + FragColor = textureProj(uSampler3D, vClip4).x; +} diff --git a/spirv_cross.cpp b/spirv_cross.cpp index 2087a44a..8003f5af 100644 --- a/spirv_cross.cpp +++ b/spirv_cross.cpp @@ -3602,18 +3602,18 @@ void Compiler::make_constant_null(uint32_t id, uint32_t type) vector elements(constant_type.array.back()); for (uint32_t i = 0; i < constant_type.array.back(); i++) elements[i] = parent_id; - set(id, type, elements.data(), elements.size()); + set(id, type, elements.data(), uint32_t(elements.size())); } else if (!constant_type.member_types.empty()) { - uint32_t member_ids = increase_bound_by(constant_type.member_types.size()); + uint32_t member_ids = increase_bound_by(uint32_t(constant_type.member_types.size())); vector elements(constant_type.member_types.size()); for (uint32_t i = 0; i < constant_type.member_types.size(); i++) { make_constant_null(member_ids + i, constant_type.member_types[i]); elements[i] = member_ids + i; } - set(id, type, elements.data(), elements.size()); + set(id, type, elements.data(), uint32_t(elements.size())); } else { diff --git a/spirv_hlsl.cpp b/spirv_hlsl.cpp index 3c031bcf..602d947c 100644 --- a/spirv_hlsl.cpp +++ b/spirv_hlsl.cpp @@ -1240,9 +1240,9 @@ void CompilerHLSL::emit_fixup() if (options.shader_model <= 30) { statement("gl_Position.x = gl_Position.x - gl_HalfPixel.x * " - "gl_Position.w;"); + "gl_Position.w;"); statement("gl_Position.y = gl_Position.y + gl_HalfPixel.y * " - "gl_Position.w;"); + "gl_Position.w;"); } if (CompilerGLSL::options.vertex.flip_vert_y) diff --git a/spirv_msl.cpp b/spirv_msl.cpp index a3d9bc72..c6f8cf49 100644 --- a/spirv_msl.cpp +++ b/spirv_msl.cpp @@ -2517,9 +2517,15 @@ string CompilerMSL::image_type_glsl(const SPIRType &type, uint32_t id) { switch (img_type.dim) { + case Dim1D: + img_type_name += "depth1d_unsupported_by_metal"; + break; case Dim2D: img_type_name += (img_type.ms ? "depth2d_ms" : (img_type.arrayed ? "depth2d_array" : "depth2d")); break; + case Dim3D: + img_type_name += "depth3d_unsupported_by_metal"; + break; case DimCube: img_type_name += (img_type.arrayed ? "depthcube_array" : "depthcube"); break; diff --git a/test_shaders.py b/test_shaders.py index 80d7b284..f41c8f1a 100755 --- a/test_shaders.py +++ b/test_shaders.py @@ -206,14 +206,14 @@ def regression_check(shader, glsl, update, keep): if os.path.exists(reference): if md5_for_file(glsl) != md5_for_file(reference): if update: - print('Generated GLSL has changed for {}!'.format(reference)) + print('Generated source code has changed for {}!'.format(reference)) # If we expect changes, update the reference file. if os.path.exists(reference): os.remove(reference) make_reference_dir(reference) shutil.move(glsl, reference) else: - print('Generated GLSL in {} does not match reference {}!'.format(glsl, reference)) + print('Generated source code in {} does not match reference {}!'.format(glsl, reference)) with open(glsl, 'r') as f: print('') print('Generated:') @@ -229,7 +229,7 @@ def regression_check(shader, glsl, update, keep): else: os.remove(glsl) else: - print('Found new shader {}. Placing GLSL in {}'.format(joined_path, reference)) + print('Found new shader {}. Placing generated source code in {}'.format(joined_path, reference)) make_reference_dir(reference) shutil.move(glsl, reference)