Merge pull request #519 from KhronosGroup/fix-507

Fix arrays of images and samplers in MSL
This commit is contained in:
Hans-Kristian Arntzen 2018-04-04 12:47:40 +02:00 коммит произвёл GitHub
Родитель 69ffd918a6 ac81a0ce68
Коммит 7f84537350
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
68 изменённых файлов: 472 добавлений и 93 удалений

Просмотреть файл

@ -2,7 +2,7 @@ language: cpp
os:
- linux
- osx
osx_image: xcode8.3
osx_image: xcode9.3beta
# Use Ubuntu 14.04 LTS (Trusty) as the Linux testing environment.
sudo: required

Просмотреть файл

@ -1,6 +1,7 @@
#!/bin/bash
for file in spirv_*.{cpp,hpp} include/spirv_cross/*.{hpp,h} samples/cpp/*.cpp main.cpp
#for file in spirv_*.{cpp,hpp} include/spirv_cross/*.{hpp,h} samples/cpp/*.cpp main.cpp
for file in spirv_*.{cpp,hpp} main.cpp
do
echo "Formatting file: $file ..."
clang-format -style=file -i $file

Просмотреть файл

@ -0,0 +1,39 @@
Texture2D<float4> uSampler[4] : register(t0);
SamplerState _uSampler_sampler[4] : register(s0);
Texture2D<float4> uTextures[4] : register(t8);
SamplerState uSamplers[4] : register(s4);
static int vIndex;
static float2 vTex;
static float4 FragColor;
struct SPIRV_Cross_Input
{
nointerpolation float2 vTex : TEXCOORD0;
nointerpolation int vIndex : TEXCOORD1;
};
struct SPIRV_Cross_Output
{
float4 FragColor : SV_Target0;
};
void frag_main()
{
FragColor = 0.0f.xxxx;
FragColor += uTextures[2].Sample(uSamplers[1], vTex);
FragColor += uSampler[vIndex].Sample(_uSampler_sampler[vIndex], vTex);
FragColor += uSampler[vIndex].Sample(_uSampler_sampler[vIndex], vTex + 0.100000001490116119384765625f.xx);
FragColor += uSampler[vIndex].Sample(_uSampler_sampler[vIndex], vTex + 0.20000000298023223876953125f.xx);
FragColor += uSampler[3].Sample(_uSampler_sampler[3], vTex + 0.300000011920928955078125f.xx);
}
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
{
vIndex = stage_input.vIndex;
vTex = stage_input.vTex;
frag_main();
SPIRV_Cross_Output stage_output;
stage_output.FragColor = FragColor;
return stage_output;
}

Просмотреть файл

@ -95,7 +95,7 @@ struct main0_out
float4 m_5 [[color(0)]];
};
fragment main0_out main0(constant _6& _7 [[buffer(0)]], constant _10& _11 [[buffer(1)]], constant _18& _19 [[buffer(2)]], texture2d<float> _8 [[texture(0)]], texture2d<float> _12 [[texture(1)]], texture2d<float> _14 [[texture(2)]], sampler _9 [[sampler(0)]], sampler _13 [[sampler(1)]], sampler _15 [[sampler(2)]], float4 gl_FragCoord [[position]])
fragment main0_out main0(constant _6& _7 [[buffer(0)]], constant _18& _19 [[buffer(1)]], constant _10& _11 [[buffer(2)]], texture2d<float> _14 [[texture(4)]], texture2d<float> _12 [[texture(13)]], texture2d<float> _8 [[texture(14)]], sampler _15 [[sampler(3)]], sampler _13 [[sampler(5)]], sampler _9 [[sampler(6)]], float4 gl_FragCoord [[position]])
{
main0_out out = {};
float2 _82 = gl_FragCoord.xy * _19._m23.xy;

Просмотреть файл

@ -12,7 +12,7 @@ struct SSBO
int i32;
};
kernel void main0(device SSBO& ssbo [[buffer(0)]])
kernel void main0(device SSBO& ssbo [[buffer(2)]])
{
uint _16 = atomic_fetch_add_explicit((volatile device atomic_uint*)&(ssbo.u32), 1u, memory_order_relaxed);
uint _18 = atomic_fetch_or_explicit((volatile device atomic_uint*)&(ssbo.u32), 1u, memory_order_relaxed);

Просмотреть файл

@ -8,7 +8,7 @@ struct SSBO
float4 value;
};
kernel void main0(device SSBO& _10 [[buffer(0)]])
kernel void main0(device SSBO& _10 [[buffer(1)]])
{
_10.value = float4(20.0);
}

Просмотреть файл

@ -8,7 +8,7 @@ struct SSBO
int4 value;
};
kernel void main0(device SSBO& _10 [[buffer(0)]], texture2d<int> uImage [[texture(0)]])
kernel void main0(device SSBO& _10 [[buffer(1)]], texture2d<int> uImage [[texture(3)]])
{
_10.value = uImage.read(uint2(int2(10)));
}

Просмотреть файл

@ -8,7 +8,7 @@ struct SSBO2
float3x3 out_data[1];
};
kernel void main0(device SSBO2& _22 [[buffer(0)]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]])
kernel void main0(device SSBO2& _22 [[buffer(1)]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]])
{
_22.out_data[gl_GlobalInvocationID.x] = float3x3(float3(10.0), float3(20.0), float3(40.0));
}

Просмотреть файл

@ -21,7 +21,7 @@ struct Buffer1
float buf1[1];
};
kernel void main0(device Buffer0& _15 [[buffer(0)]], device Buffer1& _34 [[buffer(1)]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]])
kernel void main0(device Buffer0& _15 [[buffer(1)]], device Buffer1& _34 [[buffer(2)]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]])
{
_34.buf1[gl_GlobalInvocationID.x] = _15.buf0[0].b;
}

Просмотреть файл

@ -21,7 +21,7 @@ struct Buffer1
float buf1[1];
};
kernel void main0(device Buffer0& _14 [[buffer(0)]], device Buffer1& _24 [[buffer(1)]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]])
kernel void main0(device Buffer0& _14 [[buffer(1)]], device Buffer1& _24 [[buffer(2)]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]])
{
_24.buf1[gl_GlobalInvocationID.x] = _14.buf0[0].b;
}

Просмотреть файл

@ -21,7 +21,7 @@ struct SSBO1
float4 data3;
};
kernel void main0(device SSBO2& _10 [[buffer(0)]], device SSBO0& _15 [[buffer(1)]], device SSBO1& _21 [[buffer(2)]])
kernel void main0(device SSBO0& _15 [[buffer(0)]], device SSBO1& _21 [[buffer(1)]], device SSBO2& _10 [[buffer(2)]])
{
_10.data4 = _15.data0 + _21.data2;
_10.data5 = _15.data1 + _21.data3;

Просмотреть файл

@ -18,7 +18,7 @@ struct SSBO
Foo in_data[1];
};
kernel void main0(device SSBO2& _23 [[buffer(0)]], device SSBO& _30 [[buffer(1)]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]])
kernel void main0(device SSBO& _30 [[buffer(0)]], device SSBO2& _23 [[buffer(1)]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]])
{
_23.out_data[gl_GlobalInvocationID.x].m = _30.in_data[gl_GlobalInvocationID.x].m * _30.in_data[gl_GlobalInvocationID.x].m;
}

Просмотреть файл

@ -18,7 +18,7 @@ struct dstbuffer
s2 test[1];
};
kernel void main0(device dstbuffer& _19 [[buffer(0)]])
kernel void main0(device dstbuffer& _19 [[buffer(1)]])
{
_19.test[0].b.a = 0;
}

Просмотреть файл

@ -95,7 +95,7 @@ struct SSBO0
float array[1];
};
kernel void main0(device SSBO1& ssbo_430 [[buffer(0)]], device SSBO0& ssbo_140 [[buffer(1)]])
kernel void main0(device SSBO0& ssbo_140 [[buffer(0)]], device SSBO1& ssbo_430 [[buffer(1)]])
{
ssbo_430.content.m0s[0].a[0] = ssbo_140.content.m0s[0].a[0];
ssbo_430.content.m0s[0].b = ssbo_140.content.m0s[0].b;

Просмотреть файл

@ -8,7 +8,7 @@ struct SSBO2
uint outputs[1];
};
kernel void main0(device SSBO2& _10 [[buffer(0)]], device SSBO2& _23 [[buffer(1)]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]])
kernel void main0(device SSBO2& _23 [[buffer(0)]], device SSBO2& _10 [[buffer(1)]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]])
{
_10.outputs[gl_GlobalInvocationID.x] = _23.outputs[gl_GlobalInvocationID.x] / 29u;
}

Просмотреть файл

@ -3,7 +3,7 @@
using namespace metal;
fragment void main0(texture2d_ms<float> uImageMS [[texture(0)]], texture2d_array<float, access::read_write> uImageArray [[texture(1)]], texture2d<float, access::write> uImage [[texture(2)]])
fragment void main0(texture2d<float, access::write> uImage [[texture(0)]], texture2d_array<float, access::read_write> uImageArray [[texture(1)]], texture2d_ms<float> uImageMS [[texture(2)]])
{
uImage.write(uImageMS.read(uint2(int2(1, 2)), 2), uint2(int2(2, 3)));
uImageArray.write(uImageArray.read(uint2(int3(1, 2, 4).xy), uint(int3(1, 2, 4).z)), uint2(int3(2, 3, 7).xy), uint(int3(2, 3, 7).z));

Просмотреть файл

@ -26,7 +26,7 @@ struct main0_out
float4 FragColor [[color(0)]];
};
fragment main0_out main0(constant UBO1& _14 [[buffer(0)]], constant UBO2& _29 [[buffer(1)]], constant UBO0& _41 [[buffer(2)]])
fragment main0_out main0(constant UBO0& _41 [[buffer(0)]], constant UBO1& _14 [[buffer(1)]], constant UBO2& _29 [[buffer(2)]])
{
main0_out out = {};
out.FragColor = ((((float4(_14.c) + float4(_14.d)) + float4(_29.e)) + float4(_29.f)) + _41.a) + _41.b;

Просмотреть файл

@ -8,7 +8,7 @@ struct main0_out
float FragColor [[color(0)]];
};
fragment main0_out main0(depth2d<float> uDepth [[texture(0)]], texture2d<float> uColor [[texture(1)]], sampler uSamplerShadow [[sampler(0)]], sampler uSampler [[sampler(1)]])
fragment main0_out main0(depth2d<float> uDepth [[texture(0)]], texture2d<float> uColor [[texture(1)]], sampler uSampler [[sampler(2)]], sampler uSamplerShadow [[sampler(3)]])
{
main0_out out = {};
out.FragColor = uDepth.sample_compare(uSamplerShadow, float3(0.5).xy, 0.5) + uColor.sample(uSampler, float2(0.5)).x;

Просмотреть файл

@ -0,0 +1,22 @@
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
struct main0_in
{
float vTex [[user(locn0)]];
};
struct main0_out
{
float4 FragColor [[color(0)]];
};
fragment main0_out main0(main0_in in [[stage_in]], texture1d<float> uSampler [[texture(0)]], sampler uSamplerSmplr [[sampler(0)]])
{
main0_out out = {};
out.FragColor += ((uSampler.sample(uSamplerSmplr, in.vTex) + uSampler.sample(uSamplerSmplr, in.vTex)) + uSampler.sample(uSamplerSmplr, in.vTex));
return out;
}

Просмотреть файл

@ -0,0 +1,28 @@
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
struct main0_in
{
int vIndex [[user(locn1)]];
float2 vTex [[user(locn0)]];
};
struct main0_out
{
float4 FragColor [[color(0)]];
};
fragment main0_out main0(main0_in in [[stage_in]], array<texture2d<float>, 4> uSampler [[texture(0)]], array<texture2d<float>, 4> uTextures [[texture(8)]], array<sampler, 4> uSamplerSmplr [[sampler(0)]], array<sampler, 4> uSamplers [[sampler(4)]])
{
main0_out out = {};
out.FragColor = float4(0.0);
out.FragColor += uTextures[2].sample(uSamplers[1], in.vTex);
out.FragColor += uSampler[in.vIndex].sample(uSamplerSmplr[in.vIndex], in.vTex);
out.FragColor += uSampler[in.vIndex].sample(uSamplerSmplr[in.vIndex], (in.vTex + float2(0.100000001490116119384765625)));
out.FragColor += uSampler[in.vIndex].sample(uSamplerSmplr[in.vIndex], (in.vTex + float2(0.20000000298023223876953125)));
out.FragColor += uSampler[3].sample(uSamplerSmplr[3], (in.vTex + float2(0.300000011920928955078125)));
return out;
}

Просмотреть файл

@ -8,7 +8,7 @@ struct main0_out
float4 FragColor [[color(0)]];
};
fragment main0_out main0(texture2d<float> uDepth [[texture(0)]], sampler uSampler [[sampler(0)]])
fragment main0_out main0(texture2d<float> uDepth [[texture(1)]], sampler uSampler [[sampler(0)]])
{
main0_out out = {};
out.FragColor = uDepth.sample(uSampler, float2(0.5));

Просмотреть файл

@ -15,7 +15,7 @@ struct main0_out
float FragColor [[color(0)]];
};
fragment main0_out main0(main0_in in [[stage_in]], depth2d<float> uShadow2D [[texture(0)]], texture1d<float> uSampler1D [[texture(1)]], texture2d<float> uSampler2D [[texture(2)]], texture3d<float> uSampler3D [[texture(3)]], sampler uShadow2DSmplr [[sampler(0)]], sampler uSampler1DSmplr [[sampler(1)]], sampler uSampler2DSmplr [[sampler(2)]], sampler uSampler3DSmplr [[sampler(3)]])
fragment main0_out main0(main0_in in [[stage_in]], depth2d<float> uShadow2D [[texture(1)]], texture1d<float> uSampler1D [[texture(2)]], texture2d<float> uSampler2D [[texture(3)]], texture3d<float> uSampler3D [[texture(4)]], sampler uShadow2DSmplr [[sampler(1)]], sampler uSampler1DSmplr [[sampler(2)]], sampler uSampler2DSmplr [[sampler(3)]], sampler uSampler3DSmplr [[sampler(4)]])
{
main0_out out = {};
float4 _20 = in.vClip4;

Просмотреть файл

@ -37,7 +37,7 @@ struct main0_out
float4 gl_Position [[position]];
};
vertex main0_out main0(main0_in in [[stage_in]], constant _15& _17 [[buffer(0)]], constant _42& _44 [[buffer(1)]])
vertex main0_out main0(main0_in in [[stage_in]], constant _42& _44 [[buffer(12)]], constant _15& _17 [[buffer(13)]])
{
main0_out out = {};
float4 _70 = _44._m0 * float4(_44._m3 + (in.m_25.xyz * (_44._m6 + _44._m7)), 1.0);

Просмотреть файл

@ -8,7 +8,7 @@ struct main0_out
float4 gl_Position [[position]];
};
vertex main0_out main0(texture2d<float> uSamp [[texture(0)]], texture2d<float> uSampo [[texture(1)]])
vertex main0_out main0(texture2d<float> uSamp [[texture(4)]], texture2d<float> uSampo [[texture(5)]])
{
main0_out out = {};
out.gl_Position = uSamp.read(uint2(10, 0)) + uSampo.read(uint2(100, 0));

Просмотреть файл

@ -0,0 +1,54 @@
Texture2D<float4> uSampler[4] : register(t0);
SamplerState _uSampler_sampler[4] : register(s0);
Texture2D<float4> uTextures[4] : register(t8);
SamplerState uSamplers[4] : register(s4);
static int vIndex;
static float2 vTex;
static float4 FragColor;
struct SPIRV_Cross_Input
{
nointerpolation float2 vTex : TEXCOORD0;
nointerpolation int vIndex : TEXCOORD1;
};
struct SPIRV_Cross_Output
{
float4 FragColor : SV_Target0;
};
float4 sample_from_global()
{
return uSampler[vIndex].Sample(_uSampler_sampler[vIndex], vTex + 0.100000001490116119384765625f.xx);
}
float4 sample_from_argument(Texture2D<float4> samplers[4], SamplerState _samplers_sampler[4])
{
return samplers[vIndex].Sample(_samplers_sampler[vIndex], vTex + 0.20000000298023223876953125f.xx);
}
float4 sample_single_from_argument(Texture2D<float4> samp, SamplerState _samp_sampler)
{
return samp.Sample(_samp_sampler, vTex + 0.300000011920928955078125f.xx);
}
void frag_main()
{
FragColor = 0.0f.xxxx;
FragColor += uTextures[2].Sample(uSamplers[1], vTex);
FragColor += uSampler[vIndex].Sample(_uSampler_sampler[vIndex], vTex);
FragColor += sample_from_global();
FragColor += sample_from_argument(uSampler, _uSampler_sampler);
FragColor += sample_single_from_argument(uSampler[3], _uSampler_sampler[3]);
}
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
{
vIndex = stage_input.vIndex;
vTex = stage_input.vTex;
frag_main();
SPIRV_Cross_Output stage_output;
stage_output.FragColor = FragColor;
return stage_output;
}

Просмотреть файл

@ -101,7 +101,7 @@ struct main0_out
float4 _entryPointOutput [[color(0)]];
};
fragment main0_out main0(main0_in in [[stage_in]], constant CB0& _19 [[buffer(0)]], texture3d<float> LightMapTexture [[texture(0)]], texture2d<float> ShadowMapTexture [[texture(1)]], texturecube<float> EnvironmentMapTexture [[texture(2)]], texture2d<float> DiffuseMapTexture [[texture(3)]], texture2d<float> NormalMapTexture [[texture(4)]], texture2d<float> NormalDetailMapTexture [[texture(5)]], texture2d<float> StudsMapTexture [[texture(6)]], texture2d<float> SpecularMapTexture [[texture(7)]], sampler LightMapSampler [[sampler(0)]], sampler ShadowMapSampler [[sampler(1)]], sampler EnvironmentMapSampler [[sampler(2)]], sampler DiffuseMapSampler [[sampler(3)]], sampler NormalMapSampler [[sampler(4)]], sampler NormalDetailMapSampler [[sampler(5)]], sampler StudsMapSampler [[sampler(6)]], sampler SpecularMapSampler [[sampler(7)]], float4 gl_FragCoord [[position]])
fragment main0_out main0(main0_in in [[stage_in]], constant CB0& _19 [[buffer(0)]], texture2d<float> StudsMapTexture [[texture(0)]], texture2d<float> ShadowMapTexture [[texture(1)]], texturecube<float> EnvironmentMapTexture [[texture(2)]], texture2d<float> DiffuseMapTexture [[texture(3)]], texture2d<float> NormalMapTexture [[texture(4)]], texture2d<float> SpecularMapTexture [[texture(5)]], texture3d<float> LightMapTexture [[texture(6)]], texture2d<float> NormalDetailMapTexture [[texture(8)]], sampler StudsMapSampler [[sampler(0)]], sampler ShadowMapSampler [[sampler(1)]], sampler EnvironmentMapSampler [[sampler(2)]], sampler DiffuseMapSampler [[sampler(3)]], sampler NormalMapSampler [[sampler(4)]], sampler SpecularMapSampler [[sampler(5)]], sampler LightMapSampler [[sampler(6)]], sampler NormalDetailMapSampler [[sampler(8)]], float4 gl_FragCoord [[position]])
{
main0_out out = {};
VertexOutput _128 = _121;

Просмотреть файл

@ -8,7 +8,7 @@ struct SSBO2
float4 out_data[1];
};
kernel void main0(device SSBO2& _27 [[buffer(0)]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]])
kernel void main0(device SSBO2& _27 [[buffer(1)]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]])
{
uint ident = gl_GlobalInvocationID.x;
if (ident == 2u)

Просмотреть файл

@ -167,7 +167,7 @@ void vs_adjust(thread float4& dst_reg0, thread float4& dst_reg1, thread float4&
dst_reg0.x = float4(dot(float4(tmp0.xyz, 1.0), v_309.vc[0])).x;
}
vertex main0_out main0(constant VertexBuffer& v_227 [[buffer(0)]], constant VertexConstantsBuffer& v_309 [[buffer(1)]], texture2d<uint> buff_in_2 [[texture(0)]], texture2d<uint> buff_in_1 [[texture(1)]], uint gl_VertexIndex [[vertex_id]])
vertex main0_out main0(constant VertexBuffer& v_227 [[buffer(0)]], constant VertexConstantsBuffer& v_309 [[buffer(1)]], texture2d<uint> buff_in_1 [[texture(3)]], texture2d<uint> buff_in_2 [[texture(4)]], uint gl_VertexIndex [[vertex_id]])
{
main0_out out = {};
float4 dst_reg0 = float4(0.0, 0.0, 0.0, 1.0);

Просмотреть файл

@ -95,7 +95,7 @@ struct main0_out
float4 m_5 [[color(0)]];
};
fragment main0_out main0(constant _6& _7 [[buffer(0)]], constant _10& _11 [[buffer(1)]], constant _18& _19 [[buffer(2)]], texture2d<float> _8 [[texture(0)]], texture2d<float> _12 [[texture(1)]], texture2d<float> _14 [[texture(2)]], sampler _9 [[sampler(0)]], sampler _13 [[sampler(1)]], sampler _15 [[sampler(2)]], float4 gl_FragCoord [[position]])
fragment main0_out main0(constant _6& _7 [[buffer(0)]], constant _18& _19 [[buffer(1)]], constant _10& _11 [[buffer(2)]], texture2d<float> _14 [[texture(4)]], texture2d<float> _12 [[texture(13)]], texture2d<float> _8 [[texture(14)]], sampler _15 [[sampler(3)]], sampler _13 [[sampler(5)]], sampler _9 [[sampler(6)]], float4 gl_FragCoord [[position]])
{
main0_out out = {};
_28 _77 = _74;

Просмотреть файл

@ -12,7 +12,7 @@ struct SSBO
int i32;
};
kernel void main0(device SSBO& ssbo [[buffer(0)]])
kernel void main0(device SSBO& ssbo [[buffer(2)]])
{
uint _16 = atomic_fetch_add_explicit((volatile device atomic_uint*)&(ssbo.u32), 1u, memory_order_relaxed);
uint _18 = atomic_fetch_or_explicit((volatile device atomic_uint*)&(ssbo.u32), 1u, memory_order_relaxed);

Просмотреть файл

@ -8,7 +8,7 @@ struct SSBO
float4 value;
};
kernel void main0(device SSBO& _10 [[buffer(0)]])
kernel void main0(device SSBO& _10 [[buffer(1)]])
{
_10.value = float4(20.0);
}

Просмотреть файл

@ -8,7 +8,7 @@ struct SSBO
int4 value;
};
kernel void main0(device SSBO& _10 [[buffer(0)]], texture2d<int> uImage [[texture(0)]])
kernel void main0(device SSBO& _10 [[buffer(1)]], texture2d<int> uImage [[texture(3)]])
{
_10.value = uImage.read(uint2(int2(10)));
}

Просмотреть файл

@ -8,7 +8,7 @@ struct SSBO2
float3x3 out_data[1];
};
kernel void main0(device SSBO2& _22 [[buffer(0)]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]])
kernel void main0(device SSBO2& _22 [[buffer(1)]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]])
{
uint ident = gl_GlobalInvocationID.x;
_22.out_data[ident] = float3x3(float3(10.0), float3(20.0), float3(40.0));

Просмотреть файл

@ -27,7 +27,7 @@ struct Buffer1
float buf1[1];
};
kernel void main0(device Buffer0& _15 [[buffer(0)]], device Buffer1& _34 [[buffer(1)]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]])
kernel void main0(device Buffer0& _15 [[buffer(1)]], device Buffer1& _34 [[buffer(2)]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]])
{
T1 v;
v.a = _15.buf0[0].a;

Просмотреть файл

@ -21,7 +21,7 @@ struct Buffer1
float buf1[1];
};
kernel void main0(device Buffer0& _14 [[buffer(0)]], device Buffer1& _24 [[buffer(1)]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]])
kernel void main0(device Buffer0& _14 [[buffer(1)]], device Buffer1& _24 [[buffer(2)]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]])
{
float x = _14.buf0[0].b;
_24.buf1[gl_GlobalInvocationID.x] = x;

Просмотреть файл

@ -21,7 +21,7 @@ struct SSBO1
float4 data3;
};
kernel void main0(device SSBO2& _10 [[buffer(0)]], device SSBO0& _15 [[buffer(1)]], device SSBO1& _21 [[buffer(2)]])
kernel void main0(device SSBO0& _15 [[buffer(0)]], device SSBO1& _21 [[buffer(1)]], device SSBO2& _10 [[buffer(2)]])
{
_10.data4 = _15.data0 + _21.data2;
_10.data5 = _15.data1 + _21.data3;

Просмотреть файл

@ -18,7 +18,7 @@ struct SSBO
Foo in_data[1];
};
kernel void main0(device SSBO2& _23 [[buffer(0)]], device SSBO& _30 [[buffer(1)]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]])
kernel void main0(device SSBO& _30 [[buffer(0)]], device SSBO2& _23 [[buffer(1)]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]])
{
uint ident = gl_GlobalInvocationID.x;
_23.out_data[ident].m = _30.in_data[ident].m * _30.in_data[ident].m;

Просмотреть файл

@ -28,7 +28,7 @@ struct dstbuffer
s2_1 test[1];
};
kernel void main0(device dstbuffer& _19 [[buffer(0)]])
kernel void main0(device dstbuffer& _19 [[buffer(1)]])
{
s2 testVal;
testVal.b.a = 0;

Просмотреть файл

@ -118,7 +118,7 @@ struct SSBO0
float array[1];
};
kernel void main0(device SSBO1& ssbo_430 [[buffer(0)]], device SSBO0& ssbo_140 [[buffer(1)]])
kernel void main0(device SSBO0& ssbo_140 [[buffer(0)]], device SSBO1& ssbo_430 [[buffer(1)]])
{
ssbo_430.content.m0s[0].a[0] = ssbo_140.content.m0s[0].a[0];
ssbo_430.content.m0s[0].b = ssbo_140.content.m0s[0].b;

Просмотреть файл

@ -13,7 +13,7 @@ struct SSBO
uint inputs[1];
};
kernel void main0(device SSBO2& _10 [[buffer(0)]], device SSBO& _23 [[buffer(1)]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]])
kernel void main0(device SSBO& _23 [[buffer(0)]], device SSBO2& _10 [[buffer(1)]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]])
{
_10.outputs[gl_GlobalInvocationID.x] = _23.inputs[gl_GlobalInvocationID.x] / 29u;
}

Просмотреть файл

@ -3,7 +3,7 @@
using namespace metal;
fragment void main0(texture2d_ms<float> uImageMS [[texture(0)]], texture2d_array<float, access::read_write> uImageArray [[texture(1)]], texture2d<float, access::write> uImage [[texture(2)]])
fragment void main0(texture2d<float, access::write> uImage [[texture(0)]], texture2d_array<float, access::read_write> uImageArray [[texture(1)]], texture2d_ms<float> uImageMS [[texture(2)]])
{
float4 a = uImageMS.read(uint2(int2(1, 2)), 2);
float4 b = uImageArray.read(uint2(int3(1, 2, 4).xy), uint(int3(1, 2, 4).z));

Просмотреть файл

@ -26,7 +26,7 @@ struct main0_out
float4 FragColor [[color(0)]];
};
fragment main0_out main0(constant UBO1& _14 [[buffer(0)]], constant UBO2& _29 [[buffer(1)]], constant UBO0& _41 [[buffer(2)]])
fragment main0_out main0(constant UBO0& _41 [[buffer(0)]], constant UBO1& _14 [[buffer(1)]], constant UBO2& _29 [[buffer(2)]])
{
main0_out out = {};
out.FragColor = ((((float4(_14.c) + float4(_14.d)) + float4(_29.e)) + float4(_29.f)) + _41.a) + _41.b;

Просмотреть файл

@ -20,7 +20,7 @@ float sample_color_from_function(thread const texture2d<float> uT, thread const
return uT.sample(uS, float2(0.5)).x;
}
fragment main0_out main0(depth2d<float> uDepth [[texture(0)]], texture2d<float> uColor [[texture(1)]], sampler uSamplerShadow [[sampler(0)]], sampler uSampler [[sampler(1)]])
fragment main0_out main0(depth2d<float> uDepth [[texture(0)]], texture2d<float> uColor [[texture(1)]], sampler uSampler [[sampler(2)]], sampler uSamplerShadow [[sampler(3)]])
{
main0_out out = {};
out.FragColor = sample_depth_from_function(uDepth, uSamplerShadow) + sample_color_from_function(uColor, uSampler);

Просмотреть файл

@ -0,0 +1,22 @@
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
struct main0_in
{
float vTex [[user(locn0)]];
};
struct main0_out
{
float4 FragColor [[color(0)]];
};
fragment main0_out main0(main0_in in [[stage_in]], texture1d<float> uSampler [[texture(0)]], sampler uSamplerSmplr [[sampler(0)]])
{
main0_out out = {};
out.FragColor += ((uSampler.sample(uSamplerSmplr, in.vTex) + uSampler.sample(uSamplerSmplr, in.vTex)) + uSampler.sample(uSamplerSmplr, in.vTex));
return out;
}

Просмотреть файл

@ -0,0 +1,45 @@
#pragma clang diagnostic ignored "-Wmissing-prototypes"
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
struct main0_in
{
int vIndex [[user(locn1)]];
float2 vTex [[user(locn0)]];
};
struct main0_out
{
float4 FragColor [[color(0)]];
};
float4 sample_from_global(thread int& vIndex, thread float2& vTex, thread const array<texture2d<float>, 4> uSampler, thread const array<sampler, 4> uSamplerSmplr)
{
return uSampler[vIndex].sample(uSamplerSmplr[vIndex], (vTex + float2(0.100000001490116119384765625)));
}
float4 sample_from_argument(thread const array<texture2d<float>, 4> samplers, thread const array<sampler, 4> samplersSmplr, thread int& vIndex, thread float2& vTex)
{
return samplers[vIndex].sample(samplersSmplr[vIndex], (vTex + float2(0.20000000298023223876953125)));
}
float4 sample_single_from_argument(thread const texture2d<float> samp, thread const sampler sampSmplr, thread float2& vTex)
{
return samp.sample(sampSmplr, (vTex + float2(0.300000011920928955078125)));
}
fragment main0_out main0(main0_in in [[stage_in]], array<texture2d<float>, 4> uSampler [[texture(0)]], array<texture2d<float>, 4> uTextures [[texture(8)]], array<sampler, 4> uSamplerSmplr [[sampler(0)]], array<sampler, 4> uSamplers [[sampler(4)]])
{
main0_out out = {};
out.FragColor = float4(0.0);
out.FragColor += uTextures[2].sample(uSamplers[1], in.vTex);
out.FragColor += uSampler[in.vIndex].sample(uSamplerSmplr[in.vIndex], in.vTex);
out.FragColor += sample_from_global(in.vIndex, in.vTex, uSampler, uSamplerSmplr);
out.FragColor += sample_from_argument(uSampler, uSamplerSmplr, in.vIndex, in.vTex);
out.FragColor += sample_single_from_argument(uSampler[3], uSamplerSmplr[3], in.vTex);
return out;
}

Просмотреть файл

@ -16,7 +16,7 @@ struct main0_out
float4 FragColor [[color(0)]];
};
float4 sample_texture(thread const texture2d<float> tex, thread const sampler& texSmplr, thread const float2& uv)
float4 sample_texture(thread const texture2d<float> tex, thread const sampler texSmplr, thread const float2& uv)
{
return tex.sample(texSmplr, uv);
}

Просмотреть файл

@ -15,7 +15,7 @@ float4 samp(thread const texture2d<float> t, thread const sampler s)
return t.sample(s, float2(0.5));
}
fragment main0_out main0(texture2d<float> uDepth [[texture(0)]], sampler uSampler [[sampler(0)]])
fragment main0_out main0(texture2d<float> uDepth [[texture(1)]], sampler uSampler [[sampler(0)]])
{
main0_out out = {};
out.FragColor = samp(uDepth, uSampler);

Просмотреть файл

@ -15,7 +15,7 @@ struct main0_out
float FragColor [[color(0)]];
};
fragment main0_out main0(main0_in in [[stage_in]], depth2d<float> uShadow2D [[texture(0)]], texture1d<float> uSampler1D [[texture(1)]], texture2d<float> uSampler2D [[texture(2)]], texture3d<float> uSampler3D [[texture(3)]], sampler uShadow2DSmplr [[sampler(0)]], sampler uSampler1DSmplr [[sampler(1)]], sampler uSampler2DSmplr [[sampler(2)]], sampler uSampler3DSmplr [[sampler(3)]])
fragment main0_out main0(main0_in in [[stage_in]], depth2d<float> uShadow2D [[texture(1)]], texture1d<float> uSampler1D [[texture(2)]], texture2d<float> uSampler2D [[texture(3)]], texture3d<float> uSampler3D [[texture(4)]], sampler uShadow2DSmplr [[sampler(1)]], sampler uSampler1DSmplr [[sampler(2)]], sampler uSampler2DSmplr [[sampler(3)]], sampler uSampler3DSmplr [[sampler(4)]])
{
main0_out out = {};
float4 _20 = in.vClip4;

Просмотреть файл

@ -37,7 +37,7 @@ struct main0_out
float4 gl_Position [[position]];
};
vertex main0_out main0(main0_in in [[stage_in]], constant _15& _17 [[buffer(0)]], constant _42& _44 [[buffer(1)]])
vertex main0_out main0(main0_in in [[stage_in]], constant _42& _44 [[buffer(12)]], constant _15& _17 [[buffer(13)]])
{
main0_out out = {};
float3 _13;

Просмотреть файл

@ -8,7 +8,7 @@ struct main0_out
float4 gl_Position [[position]];
};
vertex main0_out main0(texture2d<float> uSamp [[texture(0)]], texture2d<float> uSampo [[texture(1)]])
vertex main0_out main0(texture2d<float> uSamp [[texture(4)]], texture2d<float> uSampo [[texture(5)]])
{
main0_out out = {};
out.gl_Position = uSamp.read(uint2(10, 0)) + uSampo.read(uint2(100, 0));

Просмотреть файл

@ -0,0 +1,33 @@
#version 450
layout(location = 0) out vec4 FragColor;
layout(location = 0) flat in vec2 vTex;
layout(location = 1) flat in int vIndex;
layout(binding = 0) uniform sampler2D uSampler[4];
layout(binding = 4) uniform sampler uSamplers[4];
layout(binding = 8) uniform texture2D uTextures[4];
vec4 sample_from_argument(sampler2D samplers[4])
{
return texture(samplers[vIndex], vTex + 0.2);
}
vec4 sample_single_from_argument(sampler2D samp)
{
return texture(samp, vTex + 0.3);
}
vec4 sample_from_global()
{
return texture(uSampler[vIndex], vTex + 0.1);
}
void main()
{
FragColor = vec4(0.0);
FragColor += texture(sampler2D(uTextures[2], uSamplers[1]), vTex);
FragColor += texture(uSampler[vIndex], vTex);
FragColor += sample_from_global();
FragColor += sample_from_argument(uSampler);
FragColor += sample_single_from_argument(uSampler[3]);
}

Просмотреть файл

@ -15,9 +15,9 @@
OpDecorate %22044 DescriptorSet 0
OpDecorate %22044 Binding 0
OpDecorate %5785 DescriptorSet 0
OpDecorate %5785 Binding 140
OpDecorate %5785 Binding 14
OpDecorate %5688 DescriptorSet 0
OpDecorate %5688 Binding 60
OpDecorate %5688 Binding 6
OpMemberDecorate %_struct_994 0 Offset 0
OpMemberDecorate %_struct_994 1 Offset 16
OpMemberDecorate %_struct_994 2 Offset 28
@ -49,13 +49,13 @@
OpDecorate %12348 DescriptorSet 0
OpDecorate %12348 Binding 2
OpDecorate %3312 DescriptorSet 0
OpDecorate %3312 Binding 142
OpDecorate %3312 Binding 13
OpDecorate %4646 DescriptorSet 0
OpDecorate %4646 Binding 62
OpDecorate %4646 Binding 5
OpDecorate %4862 DescriptorSet 0
OpDecorate %4862 Binding 141
OpDecorate %4862 Binding 4
OpDecorate %3594 DescriptorSet 0
OpDecorate %3594 Binding 61
OpDecorate %3594 Binding 3
OpDecorate %_arr_mat4v4float_uint_2 ArrayStride 64
OpDecorate %_arr_v4float_uint_2 ArrayStride 16
OpMemberDecorate %_struct_408 0 RowMajor

Просмотреть файл

@ -6,7 +6,7 @@ layout(std430, binding = 0) buffer SSBO
uint inputs[];
};
layout(std430, binding = 0) buffer SSBO2
layout(std430, binding = 1) buffer SSBO2
{
uint outputs[];
};

Просмотреть файл

@ -7,13 +7,13 @@ layout(std140, binding = 0) uniform UBO0
vec4 b;
};
layout(std140, binding = 0) uniform UBO1
layout(std140, binding = 1) uniform UBO1
{
ivec4 c;
ivec4 d;
};
layout(std140, binding = 0) uniform UBO2
layout(std140, binding = 2) uniform UBO2
{
uvec4 e;
uvec4 f;

Просмотреть файл

@ -0,0 +1,12 @@
#version 450
layout(location = 0) out vec4 FragColor;
layout(location = 0) flat in float vTex;
layout(binding = 0) uniform sampler1D uSampler;
void main()
{
FragColor += texture(uSampler, vTex, 2.0) +
textureLod(uSampler, vTex, 3.0) +
textureGrad(uSampler, vTex, 5.0, 8.0);
}

Просмотреть файл

@ -0,0 +1,33 @@
#version 450
layout(location = 0) out vec4 FragColor;
layout(location = 0) flat in vec2 vTex;
layout(location = 1) flat in int vIndex;
layout(binding = 0) uniform sampler2D uSampler[4];
layout(binding = 4) uniform sampler uSamplers[4];
layout(binding = 8) uniform texture2D uTextures[4];
vec4 sample_from_argument(sampler2D samplers[4])
{
return texture(samplers[vIndex], vTex + 0.2);
}
vec4 sample_single_from_argument(sampler2D samp)
{
return texture(samp, vTex + 0.3);
}
vec4 sample_from_global()
{
return texture(uSampler[vIndex], vTex + 0.1);
}
void main()
{
FragColor = vec4(0.0);
FragColor += texture(sampler2D(uTextures[2], uSamplers[1]), vTex);
FragColor += texture(uSampler[vIndex], vTex);
FragColor += sample_from_global();
FragColor += sample_from_argument(uSampler);
FragColor += sample_single_from_argument(uSampler[3]);
}

Просмотреть файл

@ -226,4 +226,4 @@ void DominatorBuilder::lift_continue_block_dominator()
if (back_edge_dominator)
dominator = cfg.get_function().entry_block;
}
}
} // namespace spirv_cross

Просмотреть файл

@ -114,6 +114,6 @@ private:
const CFG &cfg;
uint32_t dominator = 0;
};
}
} // namespace spirv_cross
#endif

Просмотреть файл

@ -92,7 +92,7 @@ void join_helper(std::ostringstream &stream, T &&t, Ts &&... ts)
stream << std::forward<T>(t);
join_helper(stream, std::forward<Ts>(ts)...);
}
}
} // namespace inner
class Bitset
{
@ -1257,6 +1257,6 @@ static inline bool type_is_floating_point(const SPIRType &type)
{
return type.basetype == SPIRType::Half || type.basetype == SPIRType::Float || type.basetype == SPIRType::Double;
}
}
} // namespace spirv_cross
#endif

Просмотреть файл

@ -72,6 +72,6 @@ private:
std::string interface_name;
};
}
} // namespace spirv_cross
#endif

Просмотреть файл

@ -847,6 +847,6 @@ private:
void fixup_type_alias();
bool type_is_block_like(const SPIRType &type) const;
};
}
} // namespace spirv_cross
#endif

Просмотреть файл

@ -48,4 +48,4 @@ void rename_interface_variable(spirv_cross::Compiler &compiler, const std::vecto
compiler.set_name(v.id, name);
}
}
}
} // namespace spirv_cross_util

Просмотреть файл

@ -562,6 +562,6 @@ private:
}
}
};
}
} // namespace spirv_cross
#endif

Просмотреть файл

@ -1996,8 +1996,8 @@ void CompilerHLSL::emit_function_prototype(SPIRFunction &func, const Bitset &ret
{
// Manufacture automatic sampler arg for SampledImage texture
decl += ", ";
decl +=
join(arg_type.image.depth ? "SamplerComparisonState " : "SamplerState ", to_sampler_expression(arg.id));
decl += join(arg_type.image.depth ? "SamplerComparisonState " : "SamplerState ",
to_sampler_expression(arg.id), type_to_array_glsl(arg_type));
}
if (&arg != &func.arguments.back())

Просмотреть файл

@ -219,6 +219,6 @@ private:
// when translating push constant ranges.
std::vector<RootConstants> root_constants_layout;
};
}
} // namespace spirv_cross
#endif

Просмотреть файл

@ -2292,7 +2292,7 @@ void CompilerMSL::emit_function_prototype(SPIRFunction &func, const Bitset &)
// Manufacture automatic sampler arg for SampledImage texture
auto &arg_type = get<SPIRType>(arg.type);
if (arg_type.basetype == SPIRType::SampledImage && arg_type.image.dim != DimBuffer)
decl += ", thread const sampler& " + to_sampler_expression(arg.id);
decl += join(", thread const ", sampler_type(arg_type), " ", to_sampler_expression(arg.id));
if (&arg != &func.arguments.back())
decl += ", ";
@ -2443,13 +2443,15 @@ string CompilerMSL::to_function_args(uint32_t img, const SPIRType &imgtype, bool
}
// LOD Options
if (bias)
// Metal does not support LOD for 1D textures.
if (bias && imgtype.image.dim != Dim1D)
{
forward = forward && should_forward(bias);
farg_str += ", bias(" + to_expression(bias) + ")";
}
if (lod)
// Metal does not support LOD for 1D textures.
if (lod && imgtype.image.dim != Dim1D)
{
forward = forward && should_forward(lod);
if (is_fetch)
@ -2462,7 +2464,8 @@ string CompilerMSL::to_function_args(uint32_t img, const SPIRType &imgtype, bool
}
}
if (grad_x || grad_y)
// Metal does not support LOD for 1D textures.
if ((grad_x || grad_y) && imgtype.image.dim != Dim1D)
{
forward = forward && should_forward(grad_x);
forward = forward && should_forward(grad_y);
@ -2502,17 +2505,21 @@ string CompilerMSL::to_function_args(uint32_t img, const SPIRType &imgtype, bool
{
switch (imgtype.image.dim)
{
case Dim1D:
if (coord_type.vecsize > 1)
offset_expr = enclose_expression(offset_expr) + ".x";
farg_str += ", " + offset_expr;
break;
case Dim2D:
if (coord_type.vecsize > 2)
offset_expr += ".xy";
offset_expr = enclose_expression(offset_expr) + ".xy";
farg_str += ", " + offset_expr;
break;
case Dim3D:
if (coord_type.vecsize > 3)
offset_expr += ".xyz";
offset_expr = enclose_expression(offset_expr) + ".xyz";
farg_str += ", " + offset_expr;
break;
@ -2587,14 +2594,9 @@ string CompilerMSL::to_func_call_arg(uint32_t id)
string arg_str = CompilerGLSL::to_func_call_arg(id);
// Manufacture automatic sampler arg if the arg is a SampledImage texture.
Variant &id_v = ids[id];
if (id_v.get_type() == TypeVariable)
{
auto &var = id_v.get<SPIRVariable>();
auto &type = get<SPIRType>(var.basetype);
if (type.basetype == SPIRType::SampledImage && type.image.dim != DimBuffer)
arg_str += ", " + to_sampler_expression(id);
}
auto &type = expression_type(id);
if (type.basetype == SPIRType::SampledImage && type.image.dim != DimBuffer)
arg_str += ", " + to_sampler_expression(id);
return arg_str;
}
@ -2604,8 +2606,18 @@ string CompilerMSL::to_func_call_arg(uint32_t id)
// by appending a suffix to the expression constructed from the ID.
string CompilerMSL::to_sampler_expression(uint32_t id)
{
auto expr = to_expression(id);
auto index = expr.find_first_of('[');
uint32_t samp_id = meta[id].sampler;
return samp_id ? to_expression(samp_id) : to_expression(id) + sampler_name_suffix;
if (index == string::npos)
return samp_id ? to_expression(samp_id) : expr + sampler_name_suffix;
else
{
auto image_expr = expr.substr(0, index);
auto array_expr = expr.substr(index);
return samp_id ? to_expression(samp_id) : (image_expr + sampler_name_suffix + array_expr);
}
}
// Checks whether the ID is a row_major matrix that requires conversion before use
@ -3103,13 +3115,13 @@ string CompilerMSL::entry_point_args(bool append_comma)
case SPIRType::Sampler:
if (!ep_args.empty())
ep_args += ", ";
ep_args += "sampler " + r.name;
ep_args += sampler_type(type) + " " + r.name;
ep_args += " [[sampler(" + convert_to_string(r.index) + ")]]";
break;
case SPIRType::Image:
if (!ep_args.empty())
ep_args += ", ";
ep_args += type_to_glsl(type, var_id) + " " + r.name;
ep_args += image_type_glsl(type, var_id) + " " + r.name;
ep_args += " [[texture(" + convert_to_string(r.index) + ")]]";
break;
default:
@ -3182,18 +3194,36 @@ uint32_t CompilerMSL::get_metal_resource_index(SPIRVariable &var, SPIRType::Base
}
}
// If there is no explicit mapping of bindings to MSL, use the declared binding.
if (has_decoration(var.self, DecorationBinding))
return get_decoration(var.self, DecorationBinding);
uint32_t binding_stride = 1;
auto &type = get<SPIRType>(var.basetype);
for (uint32_t i = 0; i < uint32_t(type.array.size()); i++)
binding_stride *= type.array_size_literal[i] ? type.array[i] : get<SPIRConstant>(type.array[i]).scalar();
// If a binding has not been specified, revert to incrementing resource indices
uint32_t resource_index;
switch (basetype)
{
case SPIRType::Struct:
return next_metal_resource_index.msl_buffer++;
resource_index = next_metal_resource_index.msl_buffer;
next_metal_resource_index.msl_buffer += binding_stride;
break;
case SPIRType::Image:
return next_metal_resource_index.msl_texture++;
resource_index = next_metal_resource_index.msl_texture;
next_metal_resource_index.msl_texture += binding_stride;
break;
case SPIRType::Sampler:
return next_metal_resource_index.msl_sampler++;
resource_index = next_metal_resource_index.msl_sampler;
next_metal_resource_index.msl_sampler += binding_stride;
break;
default:
return 0;
resource_index = 0;
break;
}
return resource_index;
}
// Returns the name of the entry point of this shader
@ -3208,6 +3238,13 @@ string CompilerMSL::argument_decl(const SPIRFunction::Parameter &arg)
auto &type = expression_type(arg.id);
bool constref = !arg.alias_global_variable && (!type.pointer || arg.write_count == 0);
bool type_is_image = type.basetype == SPIRType::Image || type.basetype == SPIRType::SampledImage ||
type.basetype == SPIRType::Sampler;
// Arrays of images/samplers in MSL are always const.
if (!type.array.empty() && type_is_image)
constref = true;
// TODO: Check if this arg is an uniform pointer
bool pointer = type.storage == StorageClassUniformConstant;
@ -3220,7 +3257,8 @@ string CompilerMSL::argument_decl(const SPIRFunction::Parameter &arg)
else
decl += type_to_glsl(type, arg.id);
if (is_array(type))
// Arrays of images and samplers are special cased.
if (is_array(type) && !type_is_image)
{
decl += " (&";
decl += to_expression(var.self);
@ -3376,7 +3414,7 @@ string CompilerMSL::type_to_glsl(const SPIRType &type, uint32_t id)
return image_type_glsl(type, id);
case SPIRType::Sampler:
return "sampler";
return sampler_type(type);
case SPIRType::Void:
return "void";
@ -3428,9 +3466,51 @@ string CompilerMSL::type_to_glsl(const SPIRType &type, uint32_t id)
return type_name;
}
std::string CompilerMSL::sampler_type(const SPIRType &type)
{
if (!type.array.empty())
{
if (!msl_options.supports_msl_version(2))
SPIRV_CROSS_THROW("MSL 2.0 or greater is required for arrays of samplers.");
// Arrays of samplers in MSL must be declared with a special array<T, N> syntax ala C++11 std::array.
auto *parent = &type;
while (parent->pointer)
parent = &get<SPIRType>(parent->parent_type);
parent = &get<SPIRType>(parent->parent_type);
uint32_t array_size =
type.array_size_literal.back() ? type.array.back() : get<SPIRConstant>(type.array.back()).scalar();
if (array_size == 0)
SPIRV_CROSS_THROW("Unsized array of samplers is not supported in MSL.");
return join("array<", sampler_type(*parent), ", ", array_size, ">");
}
else
return "sampler";
}
// Returns an MSL string describing the SPIR-V image type
string CompilerMSL::image_type_glsl(const SPIRType &type, uint32_t id)
{
if (!type.array.empty())
{
if (!msl_options.supports_msl_version(2))
SPIRV_CROSS_THROW("MSL 2.0 or greater is required for arrays of textures.");
// Arrays of images in MSL must be declared with a special array<T, N> syntax ala C++11 std::array.
auto *parent = &type;
while (parent->pointer)
parent = &get<SPIRType>(parent->parent_type);
parent = &get<SPIRType>(parent->parent_type);
uint32_t array_size =
type.array_size_literal.back() ? type.array.back() : get<SPIRConstant>(type.array.back()).scalar();
if (array_size == 0)
SPIRV_CROSS_THROW("Unsized array of images is not supported in MSL.");
return join("array<", image_type_glsl(*parent, id), ", ", array_size, ">");
}
string img_type_name;
// Bypass pointers because we need the real image struct

Просмотреть файл

@ -77,7 +77,8 @@ public:
// Options for compiling to Metal Shading Language
struct Options
{
typedef enum {
typedef enum
{
iOS,
macOS,
} Platform;
@ -202,6 +203,7 @@ protected:
const std::string &qualifier = "", uint32_t base_offset = 0) override;
std::string type_to_glsl(const SPIRType &type, uint32_t id = 0) override;
std::string image_type_glsl(const SPIRType &type, uint32_t id = 0) override;
std::string sampler_type(const SPIRType &type);
std::string builtin_to_glsl(spv::BuiltIn builtin, spv::StorageClass storage) override;
std::string constant_expression(const SPIRConstant &c) override;
size_t get_declared_struct_member_size(const SPIRType &struct_type, uint32_t index) const override;
@ -345,6 +347,6 @@ protected:
SortAspect sort_aspect;
};
};
}
} // namespace spirv_cross
#endif

Просмотреть файл

@ -74,10 +74,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
try:
msl_os = 'macosx'
# msl_os = 'iphoneos'
subprocess.check_call(['xcrun', '--sdk', msl_os, 'metal', '-x', 'metal', '-std=osx-metal1.2', '-Werror', '-Wno-unused-variable', msl_path])
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])
print('Compiled Metal shader: ' + msl_path) # display after so xcrun FNF is silent
except OSError as oe:
if (oe.errno != os.errno.ENOENT): # Ignore xcrun not found error
@ -87,6 +88,7 @@ def validate_shader_msl(shader, opt):
sys.exit(1)
def cross_compile_msl(shader, spirv, opt):
msl2 = '.msl2.' in shader
spirv_f, spirv_path = tempfile.mkstemp()
msl_f, msl_path = tempfile.mkstemp(suffix = os.path.basename(shader))
os.close(spirv_f)
@ -101,7 +103,13 @@ def cross_compile_msl(shader, spirv, opt):
subprocess.check_call(['spirv-opt', '-O', '-o', spirv_path, spirv_path])
spirv_cross_path = './spirv-cross'
subprocess.check_call([spirv_cross_path, '--entry', 'main', '--output', msl_path, spirv_path, '--msl'])
msl_args = [spirv_cross_path, '--entry', 'main', '--output', msl_path, spirv_path, '--msl']
if msl2:
msl_args.append('--msl-version')
msl_args.append('20000')
subprocess.check_call(msl_args)
subprocess.check_call(['spirv-val', spirv_path])
return (spirv_path, msl_path)