2021-12-03 03:41:41 +11:00
|
|
|
#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 DrawMonoid
|
|
|
|
{
|
|
|
|
uint path_ix;
|
|
|
|
uint clip_ix;
|
2022-03-03 09:44:03 +11:00
|
|
|
uint scene_offset;
|
|
|
|
uint info_offset;
|
2021-12-03 03:41:41 +11:00
|
|
|
};
|
|
|
|
|
|
|
|
struct DrawMonoid_1
|
|
|
|
{
|
|
|
|
uint path_ix;
|
|
|
|
uint clip_ix;
|
2022-03-03 09:44:03 +11:00
|
|
|
uint scene_offset;
|
|
|
|
uint info_offset;
|
2021-12-03 03:41:41 +11:00
|
|
|
};
|
|
|
|
|
|
|
|
struct DataBuf
|
|
|
|
{
|
|
|
|
DrawMonoid_1 data[1];
|
|
|
|
};
|
|
|
|
|
2021-12-09 05:42:35 +11:00
|
|
|
constant uint3 gl_WorkGroupSize [[maybe_unused]] = uint3(256u, 1u, 1u);
|
2021-12-03 03:41:41 +11:00
|
|
|
|
|
|
|
static inline __attribute__((always_inline))
|
2022-03-03 09:44:03 +11:00
|
|
|
DrawMonoid combine_draw_monoid(thread const DrawMonoid& a, thread const DrawMonoid& b)
|
2021-12-03 03:41:41 +11:00
|
|
|
{
|
|
|
|
DrawMonoid c;
|
|
|
|
c.path_ix = a.path_ix + b.path_ix;
|
|
|
|
c.clip_ix = a.clip_ix + b.clip_ix;
|
2022-03-03 09:44:03 +11:00
|
|
|
c.scene_offset = a.scene_offset + b.scene_offset;
|
|
|
|
c.info_offset = a.info_offset + b.info_offset;
|
2021-12-03 03:41:41 +11:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline __attribute__((always_inline))
|
2022-03-03 09:44:03 +11:00
|
|
|
DrawMonoid draw_monoid_identity()
|
2021-12-03 03:41:41 +11:00
|
|
|
{
|
2022-03-03 09:44:03 +11:00
|
|
|
return DrawMonoid{ 0u, 0u, 0u, 0u };
|
2021-12-03 03:41:41 +11:00
|
|
|
}
|
|
|
|
|
2022-03-03 09:44:03 +11:00
|
|
|
kernel void main0(device DataBuf& _71 [[buffer(0)]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]], uint3 gl_LocalInvocationID [[thread_position_in_threadgroup]])
|
2021-12-03 03:41:41 +11:00
|
|
|
{
|
2021-12-09 05:42:35 +11:00
|
|
|
threadgroup DrawMonoid sh_scratch[256];
|
2021-12-03 03:41:41 +11:00
|
|
|
uint ix = gl_GlobalInvocationID.x * 8u;
|
|
|
|
spvUnsafeArray<DrawMonoid, 8> local;
|
2022-03-03 09:44:03 +11:00
|
|
|
local[0].path_ix = _71.data[ix].path_ix;
|
|
|
|
local[0].clip_ix = _71.data[ix].clip_ix;
|
|
|
|
local[0].scene_offset = _71.data[ix].scene_offset;
|
|
|
|
local[0].info_offset = _71.data[ix].info_offset;
|
2021-12-03 03:41:41 +11:00
|
|
|
DrawMonoid param_1;
|
|
|
|
for (uint i = 1u; i < 8u; i++)
|
|
|
|
{
|
2022-03-03 09:44:03 +11:00
|
|
|
uint _100 = ix + i;
|
2021-12-03 03:41:41 +11:00
|
|
|
DrawMonoid param = local[i - 1u];
|
2022-03-03 09:44:03 +11:00
|
|
|
param_1.path_ix = _71.data[_100].path_ix;
|
|
|
|
param_1.clip_ix = _71.data[_100].clip_ix;
|
|
|
|
param_1.scene_offset = _71.data[_100].scene_offset;
|
|
|
|
param_1.info_offset = _71.data[_100].info_offset;
|
|
|
|
local[i] = combine_draw_monoid(param, param_1);
|
2021-12-03 03:41:41 +11:00
|
|
|
}
|
|
|
|
DrawMonoid agg = local[7];
|
|
|
|
sh_scratch[gl_LocalInvocationID.x] = agg;
|
2021-12-09 05:42:35 +11:00
|
|
|
for (uint i_1 = 0u; i_1 < 8u; i_1++)
|
2021-12-03 03:41:41 +11:00
|
|
|
{
|
|
|
|
threadgroup_barrier(mem_flags::mem_threadgroup);
|
|
|
|
if (gl_LocalInvocationID.x >= (1u << i_1))
|
|
|
|
{
|
|
|
|
DrawMonoid other = sh_scratch[gl_LocalInvocationID.x - (1u << i_1)];
|
|
|
|
DrawMonoid param_2 = other;
|
|
|
|
DrawMonoid param_3 = agg;
|
2022-03-03 09:44:03 +11:00
|
|
|
agg = combine_draw_monoid(param_2, param_3);
|
2021-12-03 03:41:41 +11:00
|
|
|
}
|
|
|
|
threadgroup_barrier(mem_flags::mem_threadgroup);
|
|
|
|
sh_scratch[gl_LocalInvocationID.x] = agg;
|
|
|
|
}
|
|
|
|
threadgroup_barrier(mem_flags::mem_threadgroup);
|
2022-03-03 09:44:03 +11:00
|
|
|
DrawMonoid row = draw_monoid_identity();
|
2021-12-03 03:41:41 +11:00
|
|
|
if (gl_LocalInvocationID.x > 0u)
|
|
|
|
{
|
|
|
|
row = sh_scratch[gl_LocalInvocationID.x - 1u];
|
|
|
|
}
|
|
|
|
for (uint i_2 = 0u; i_2 < 8u; i_2++)
|
|
|
|
{
|
|
|
|
DrawMonoid param_4 = row;
|
|
|
|
DrawMonoid param_5 = local[i_2];
|
2022-03-03 09:44:03 +11:00
|
|
|
DrawMonoid m = combine_draw_monoid(param_4, param_5);
|
|
|
|
uint _199 = ix + i_2;
|
|
|
|
_71.data[_199].path_ix = m.path_ix;
|
|
|
|
_71.data[_199].clip_ix = m.clip_ix;
|
|
|
|
_71.data[_199].scene_offset = m.scene_offset;
|
|
|
|
_71.data[_199].info_offset = m.info_offset;
|
2021-12-03 03:41:41 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|