mirror of
https://github.com/KhronosGroup/SPIRV-Cross.git
synced 2024-11-09 22:00:05 +00:00
MSL: Add test for texture/sampler variable count.
This commit is contained in:
parent
e10bf53324
commit
a8b1e07fde
@ -0,0 +1,55 @@
|
||||
#pragma clang diagnostic ignored "-Wmissing-prototypes"
|
||||
|
||||
#include <metal_stdlib>
|
||||
#include <simd/simd.h>
|
||||
|
||||
using namespace metal;
|
||||
|
||||
template<typename T>
|
||||
struct spvDescriptor
|
||||
{
|
||||
T value;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct spvDescriptorArray
|
||||
{
|
||||
spvDescriptorArray(const device spvDescriptor<T>* ptr) : ptr(ptr)
|
||||
{
|
||||
}
|
||||
const device T& operator [] (size_t i) const
|
||||
{
|
||||
return ptr[i].value;
|
||||
}
|
||||
const device spvDescriptor<T>* ptr;
|
||||
};
|
||||
|
||||
struct SSBO
|
||||
{
|
||||
float4 v[1];
|
||||
};
|
||||
|
||||
constant uint3 gl_WorkGroupSize [[maybe_unused]] = uint3(64u, 1u, 1u);
|
||||
|
||||
struct spvDescriptorSetBuffer0
|
||||
{
|
||||
device SSBO* m_13 [[id(0)]];
|
||||
texture2d<float> T [[id(1)]];
|
||||
spvDescriptor<texture2d<float>> Ts [[id(2)]][1] /* unsized array hack */;
|
||||
};
|
||||
|
||||
struct spvDescriptorSetBuffer1
|
||||
{
|
||||
sampler S [[id(0)]];
|
||||
spvDescriptor<sampler> Ss [[id(1)]][1] /* unsized array hack */;
|
||||
};
|
||||
|
||||
kernel void main0(const device spvDescriptorSetBuffer0& spvDescriptorSet0 [[buffer(0)]], const device spvDescriptorSetBuffer1& spvDescriptorSet1 [[buffer(1)]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]], uint3 gl_WorkGroupID [[threadgroup_position_in_grid]])
|
||||
{
|
||||
spvDescriptorArray<texture2d<float>> Ts {spvDescriptorSet0.Ts};
|
||||
spvDescriptorArray<sampler> Ss {spvDescriptorSet1.Ss};
|
||||
|
||||
(*spvDescriptorSet0.m_13).v[gl_GlobalInvocationID.x] = spvDescriptorSet0.T.sample(spvDescriptorSet1.S, float2(0.5), level(0.0));
|
||||
(*spvDescriptorSet0.m_13).v[gl_GlobalInvocationID.x] = Ts[gl_WorkGroupID.x].sample(Ss[gl_WorkGroupID.x], float2(0.5), level(0.0));
|
||||
}
|
||||
|
@ -0,0 +1,61 @@
|
||||
#pragma clang diagnostic ignored "-Wmissing-prototypes"
|
||||
|
||||
#include <metal_stdlib>
|
||||
#include <simd/simd.h>
|
||||
|
||||
using namespace metal;
|
||||
|
||||
template<typename T>
|
||||
struct spvDescriptor
|
||||
{
|
||||
T value;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct spvDescriptorArray
|
||||
{
|
||||
spvDescriptorArray(const device spvDescriptor<T>* ptr) : ptr(ptr)
|
||||
{
|
||||
}
|
||||
const device T& operator [] (size_t i) const
|
||||
{
|
||||
return ptr[i].value;
|
||||
}
|
||||
const device spvDescriptor<T>* ptr;
|
||||
};
|
||||
|
||||
struct SSBO
|
||||
{
|
||||
float4 v[1];
|
||||
};
|
||||
|
||||
constant uint3 gl_WorkGroupSize [[maybe_unused]] = uint3(64u, 1u, 1u);
|
||||
|
||||
struct spvDescriptorSetBuffer0
|
||||
{
|
||||
device SSBO* m_13 [[id(0)]];
|
||||
texture2d<float> T [[id(1)]];
|
||||
spvDescriptor<texture2d<float>> Ts [[id(2)]][1] /* unsized array hack */;
|
||||
};
|
||||
|
||||
struct spvDescriptorSetBuffer1
|
||||
{
|
||||
sampler S [[id(0)]];
|
||||
spvDescriptor<sampler> Ss [[id(1)]][1] /* unsized array hack */;
|
||||
};
|
||||
|
||||
static inline __attribute__((always_inline))
|
||||
void in_func(device SSBO& _13, thread uint3& gl_GlobalInvocationID, texture2d<float> T, sampler S, const spvDescriptorArray<texture2d<float>> Ts, thread uint3& gl_WorkGroupID, const spvDescriptorArray<sampler> Ss)
|
||||
{
|
||||
_13.v[gl_GlobalInvocationID.x] = T.sample(S, float2(0.5), level(0.0));
|
||||
_13.v[gl_GlobalInvocationID.x] = Ts[gl_WorkGroupID.x].sample(Ss[gl_WorkGroupID.x], float2(0.5), level(0.0));
|
||||
}
|
||||
|
||||
kernel void main0(const device spvDescriptorSetBuffer0& spvDescriptorSet0 [[buffer(0)]], const device spvDescriptorSetBuffer1& spvDescriptorSet1 [[buffer(1)]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]], uint3 gl_WorkGroupID [[threadgroup_position_in_grid]])
|
||||
{
|
||||
spvDescriptorArray<texture2d<float>> Ts {spvDescriptorSet0.Ts};
|
||||
spvDescriptorArray<sampler> Ss {spvDescriptorSet1.Ss};
|
||||
|
||||
in_func((*spvDescriptorSet0.m_13), gl_GlobalInvocationID, spvDescriptorSet0.T, spvDescriptorSet1.S, Ts, gl_WorkGroupID, Ss);
|
||||
}
|
||||
|
@ -0,0 +1,25 @@
|
||||
#version 450
|
||||
#extension GL_EXT_nonuniform_qualifier : require
|
||||
layout(local_size_x = 64) in;
|
||||
|
||||
layout(set = 0, binding = 0) buffer SSBO
|
||||
{
|
||||
vec4 v[];
|
||||
};
|
||||
|
||||
layout(set = 0, binding = 1) uniform texture2D T;
|
||||
layout(set = 0, binding = 2) uniform texture2D Ts[];
|
||||
|
||||
layout(set = 1, binding = 0) uniform sampler S;
|
||||
layout(set = 1, binding = 1) uniform sampler Ss[];
|
||||
|
||||
void in_func()
|
||||
{
|
||||
v[gl_GlobalInvocationID.x] = textureLod(sampler2D(T, S), vec2(0.5), 0.0);
|
||||
v[gl_GlobalInvocationID.x] = textureLod(sampler2D(Ts[gl_WorkGroupID.x], Ss[gl_WorkGroupID.x]), vec2(0.5), 0.0);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
in_func();
|
||||
}
|
Loading…
Reference in New Issue
Block a user