forked from devshgraphicsprogramming/SPIRV-Cross
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MSL: Don't set the layer for multiview if the device doesn't support it.
Some older iOS devices don't support layered rendering. In that case, don't set `[[render_target_array_index]]`, because the compiler will reject the shader in that case. The client will then have to unroll the render pass manually.
- Loading branch information
Showing
13 changed files
with
260 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
reference/opt/shaders-msl/vulkan/frag/basic.multiview.no-layered.nocompat.vk.frag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#pragma clang diagnostic ignored "-Wmissing-prototypes" | ||
#pragma clang diagnostic ignored "-Wmissing-braces" | ||
|
||
#include <metal_stdlib> | ||
#include <simd/simd.h> | ||
|
||
using namespace metal; | ||
|
||
template<typename T, size_t Num> | ||
struct spvUnsafeArray | ||
{ | ||
T elements[Num ? Num : 1]; | ||
|
||
thread T& operator [] (size_t pos) thread | ||
{ | ||
return elements[pos]; | ||
} | ||
constexpr const thread T& operator [] (size_t pos) const thread | ||
{ | ||
return elements[pos]; | ||
} | ||
|
||
device T& operator [] (size_t pos) device | ||
{ | ||
return elements[pos]; | ||
} | ||
constexpr const device T& operator [] (size_t pos) const device | ||
{ | ||
return elements[pos]; | ||
} | ||
|
||
constexpr const constant T& operator [] (size_t pos) const constant | ||
{ | ||
return elements[pos]; | ||
} | ||
|
||
threadgroup T& operator [] (size_t pos) threadgroup | ||
{ | ||
return elements[pos]; | ||
} | ||
constexpr const threadgroup T& operator [] (size_t pos) const threadgroup | ||
{ | ||
return elements[pos]; | ||
} | ||
}; | ||
|
||
struct main0_out | ||
{ | ||
float4 FragColor [[color(0)]]; | ||
}; | ||
|
||
struct main0_in | ||
{ | ||
float4 vColor [[user(locn0)]]; | ||
float2 vTex_0 [[user(locn1)]]; | ||
float2 vTex_1 [[user(locn2)]]; | ||
float2 vTex_2 [[user(locn3)]]; | ||
float2 vTex_3 [[user(locn4)]]; | ||
}; | ||
|
||
fragment main0_out main0(main0_in in [[stage_in]], constant uint* spvViewMask [[buffer(24)]], texture2d<float> uTex [[texture(0)]], sampler uTexSmplr [[sampler(0)]]) | ||
{ | ||
main0_out out = {}; | ||
spvUnsafeArray<float2, 4> vTex = {}; | ||
vTex[0] = in.vTex_0; | ||
vTex[1] = in.vTex_1; | ||
vTex[2] = in.vTex_2; | ||
vTex[3] = in.vTex_3; | ||
const uint gl_ViewIndex = spvViewMask[0]; | ||
out.FragColor = in.vColor * uTex.sample(uTexSmplr, vTex[int(gl_ViewIndex)]); | ||
return out; | ||
} | ||
|
28 changes: 28 additions & 0 deletions
28
reference/opt/shaders-msl/vulkan/vert/multiview.multiview.no-layered.nocompat.vk.vert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include <metal_stdlib> | ||
#include <simd/simd.h> | ||
|
||
using namespace metal; | ||
|
||
struct MVPs | ||
{ | ||
float4x4 MVP[2]; | ||
}; | ||
|
||
struct main0_out | ||
{ | ||
float4 gl_Position [[position]]; | ||
}; | ||
|
||
struct main0_in | ||
{ | ||
float4 Position [[attribute(0)]]; | ||
}; | ||
|
||
vertex main0_out main0(main0_in in [[stage_in]], constant uint* spvViewMask [[buffer(24)]], constant MVPs& _19 [[buffer(0)]]) | ||
{ | ||
main0_out out = {}; | ||
const uint gl_ViewIndex = spvViewMask[0]; | ||
out.gl_Position = _19.MVP[int(gl_ViewIndex)] * in.Position; | ||
return out; | ||
} | ||
|
73 changes: 73 additions & 0 deletions
73
reference/shaders-msl/vulkan/frag/basic.multiview.no-layered.nocompat.vk.frag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#pragma clang diagnostic ignored "-Wmissing-prototypes" | ||
#pragma clang diagnostic ignored "-Wmissing-braces" | ||
|
||
#include <metal_stdlib> | ||
#include <simd/simd.h> | ||
|
||
using namespace metal; | ||
|
||
template<typename T, size_t Num> | ||
struct spvUnsafeArray | ||
{ | ||
T elements[Num ? Num : 1]; | ||
|
||
thread T& operator [] (size_t pos) thread | ||
{ | ||
return elements[pos]; | ||
} | ||
constexpr const thread T& operator [] (size_t pos) const thread | ||
{ | ||
return elements[pos]; | ||
} | ||
|
||
device T& operator [] (size_t pos) device | ||
{ | ||
return elements[pos]; | ||
} | ||
constexpr const device T& operator [] (size_t pos) const device | ||
{ | ||
return elements[pos]; | ||
} | ||
|
||
constexpr const constant T& operator [] (size_t pos) const constant | ||
{ | ||
return elements[pos]; | ||
} | ||
|
||
threadgroup T& operator [] (size_t pos) threadgroup | ||
{ | ||
return elements[pos]; | ||
} | ||
constexpr const threadgroup T& operator [] (size_t pos) const threadgroup | ||
{ | ||
return elements[pos]; | ||
} | ||
}; | ||
|
||
struct main0_out | ||
{ | ||
float4 FragColor [[color(0)]]; | ||
}; | ||
|
||
struct main0_in | ||
{ | ||
float4 vColor [[user(locn0)]]; | ||
float2 vTex_0 [[user(locn1)]]; | ||
float2 vTex_1 [[user(locn2)]]; | ||
float2 vTex_2 [[user(locn3)]]; | ||
float2 vTex_3 [[user(locn4)]]; | ||
}; | ||
|
||
fragment main0_out main0(main0_in in [[stage_in]], constant uint* spvViewMask [[buffer(24)]], texture2d<float> uTex [[texture(0)]], sampler uTexSmplr [[sampler(0)]]) | ||
{ | ||
main0_out out = {}; | ||
spvUnsafeArray<float2, 4> vTex = {}; | ||
vTex[0] = in.vTex_0; | ||
vTex[1] = in.vTex_1; | ||
vTex[2] = in.vTex_2; | ||
vTex[3] = in.vTex_3; | ||
const uint gl_ViewIndex = spvViewMask[0]; | ||
out.FragColor = in.vColor * uTex.sample(uTexSmplr, vTex[int(gl_ViewIndex)]); | ||
return out; | ||
} | ||
|
28 changes: 28 additions & 0 deletions
28
reference/shaders-msl/vulkan/vert/multiview.multiview.no-layered.nocompat.vk.vert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include <metal_stdlib> | ||
#include <simd/simd.h> | ||
|
||
using namespace metal; | ||
|
||
struct MVPs | ||
{ | ||
float4x4 MVP[2]; | ||
}; | ||
|
||
struct main0_out | ||
{ | ||
float4 gl_Position [[position]]; | ||
}; | ||
|
||
struct main0_in | ||
{ | ||
float4 Position [[attribute(0)]]; | ||
}; | ||
|
||
vertex main0_out main0(main0_in in [[stage_in]], constant uint* spvViewMask [[buffer(24)]], constant MVPs& _19 [[buffer(0)]]) | ||
{ | ||
main0_out out = {}; | ||
const uint gl_ViewIndex = spvViewMask[0]; | ||
out.gl_Position = _19.MVP[int(gl_ViewIndex)] * in.Position; | ||
return out; | ||
} | ||
|
14 changes: 14 additions & 0 deletions
14
shaders-msl/vulkan/frag/basic.multiview.no-layered.nocompat.vk.frag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#version 310 es | ||
#extension GL_EXT_multiview : require | ||
precision mediump float; | ||
|
||
layout(location = 0) in vec4 vColor; | ||
layout(location = 1) in vec2 vTex[4]; | ||
layout(binding = 0) uniform sampler2D uTex; | ||
layout(location = 0) out vec4 FragColor; | ||
|
||
void main() | ||
{ | ||
FragColor = vColor * texture(uTex, vTex[gl_ViewIndex]); | ||
} | ||
|
14 changes: 14 additions & 0 deletions
14
shaders-msl/vulkan/vert/multiview.multiview.no-layered.nocompat.vk.vert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#version 310 es | ||
#extension GL_EXT_multiview : require | ||
|
||
layout(std140, binding = 0) uniform MVPs | ||
{ | ||
mat4 MVP[2]; | ||
}; | ||
|
||
layout(location = 0) in vec4 Position; | ||
|
||
void main() | ||
{ | ||
gl_Position = MVP[gl_ViewIndex] * Position; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters