Fix passing arrays of arrays to functions in MSL.
This commit is contained in:
Родитель
ab3907e4b5
Коммит
38b8f733d1
|
@ -0,0 +1,20 @@
|
|||
#include <metal_stdlib>
|
||||
#include <simd/simd.h>
|
||||
|
||||
using namespace metal;
|
||||
|
||||
constant uint3 gl_WorkGroupSize = uint3(4u, 4u, 1u);
|
||||
|
||||
struct SSBO
|
||||
{
|
||||
float out_data[1];
|
||||
};
|
||||
|
||||
kernel void main0(uint3 gl_LocalInvocationID [[thread_position_in_threadgroup]], uint gl_LocalInvocationIndex [[thread_index_in_threadgroup]], device SSBO& _67 [[buffer(0)]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]])
|
||||
{
|
||||
threadgroup float foo[4][4];
|
||||
foo[gl_LocalInvocationID.x][gl_LocalInvocationID.y] = float(gl_LocalInvocationIndex);
|
||||
threadgroup_barrier(mem_flags::mem_threadgroup);
|
||||
_67.out_data[gl_GlobalInvocationID.x] = (((0.0 + foo[gl_LocalInvocationID.x][0]) + foo[gl_LocalInvocationID.x][1]) + foo[gl_LocalInvocationID.x][2]) + foo[gl_LocalInvocationID.x][3];
|
||||
}
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
using namespace metal;
|
||||
|
||||
void myfunc(threadgroup int* foo)
|
||||
void myfunc(threadgroup int (&foo)[1337])
|
||||
{
|
||||
foo[0] = 13;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
#pragma clang diagnostic ignored "-Wmissing-prototypes"
|
||||
|
||||
#include <metal_stdlib>
|
||||
#include <simd/simd.h>
|
||||
|
||||
using namespace metal;
|
||||
|
||||
constant uint3 gl_WorkGroupSize = uint3(4u, 4u, 1u);
|
||||
|
||||
struct SSBO
|
||||
{
|
||||
float out_data[1];
|
||||
};
|
||||
|
||||
void work(threadgroup float (&foo)[4][4], thread uint3& gl_LocalInvocationID, thread uint& gl_LocalInvocationIndex, device SSBO& v_67, thread uint3& gl_GlobalInvocationID)
|
||||
{
|
||||
foo[gl_LocalInvocationID.x][gl_LocalInvocationID.y] = float(gl_LocalInvocationIndex);
|
||||
threadgroup_barrier(mem_flags::mem_threadgroup);
|
||||
float x = 0.0;
|
||||
x += foo[gl_LocalInvocationID.x][0];
|
||||
x += foo[gl_LocalInvocationID.x][1];
|
||||
x += foo[gl_LocalInvocationID.x][2];
|
||||
x += foo[gl_LocalInvocationID.x][3];
|
||||
v_67.out_data[gl_GlobalInvocationID.x] = x;
|
||||
}
|
||||
|
||||
kernel void main0(uint3 gl_LocalInvocationID [[thread_position_in_threadgroup]], uint gl_LocalInvocationIndex [[thread_index_in_threadgroup]], device SSBO& v_67 [[buffer(0)]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]])
|
||||
{
|
||||
threadgroup float foo[4][4];
|
||||
work(foo, gl_LocalInvocationID, gl_LocalInvocationIndex, v_67, gl_GlobalInvocationID);
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
#version 310 es
|
||||
layout(local_size_x = 4, local_size_y = 4) in;
|
||||
|
||||
shared float foo[4][4];
|
||||
|
||||
layout(binding = 0, std430) buffer SSBO
|
||||
{
|
||||
float out_data[];
|
||||
};
|
||||
|
||||
void work()
|
||||
{
|
||||
foo[gl_LocalInvocationID.x][gl_LocalInvocationID.y] = float(gl_LocalInvocationIndex);
|
||||
memoryBarrierShared();
|
||||
barrier();
|
||||
|
||||
float x = 0.0;
|
||||
x += foo[gl_LocalInvocationID.x][0];
|
||||
x += foo[gl_LocalInvocationID.x][1];
|
||||
x += foo[gl_LocalInvocationID.x][2];
|
||||
x += foo[gl_LocalInvocationID.x][3];
|
||||
out_data[gl_GlobalInvocationID.x] = x;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
work();
|
||||
}
|
||||
|
|
@ -2837,17 +2837,28 @@ string CompilerMSL::argument_decl(const SPIRFunction::Parameter &arg)
|
|||
decl += "const ";
|
||||
|
||||
if (is_builtin_variable(var))
|
||||
decl += builtin_type_decl((BuiltIn)get_decoration(arg.id, DecorationBuiltIn));
|
||||
decl += builtin_type_decl(static_cast<BuiltIn>(get_decoration(arg.id, DecorationBuiltIn)));
|
||||
else
|
||||
decl += type_to_glsl(type, arg.id);
|
||||
|
||||
if (is_array(type))
|
||||
decl += "*";
|
||||
{
|
||||
decl += " (&";
|
||||
decl += to_name(var.self);
|
||||
decl += ")";
|
||||
decl += type_to_array_glsl(type);
|
||||
}
|
||||
else if (!pointer)
|
||||
{
|
||||
decl += "&";
|
||||
|
||||
decl += " ";
|
||||
decl += to_name(var.self);
|
||||
decl += " ";
|
||||
decl += to_name(var.self);
|
||||
}
|
||||
else
|
||||
{
|
||||
decl += " ";
|
||||
decl += to_name(var.self);
|
||||
}
|
||||
|
||||
return decl;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче