2021-12-03 03:41:41 +11:00
|
|
|
#pragma clang diagnostic ignored "-Wmissing-prototypes"
|
|
|
|
|
|
|
|
#include <metal_stdlib>
|
|
|
|
#include <simd/simd.h>
|
|
|
|
|
|
|
|
using namespace metal;
|
|
|
|
|
|
|
|
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 Alloc
|
|
|
|
{
|
|
|
|
uint offset;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Config
|
|
|
|
{
|
|
|
|
uint n_elements;
|
|
|
|
uint n_pathseg;
|
|
|
|
uint width_in_tiles;
|
|
|
|
uint height_in_tiles;
|
|
|
|
Alloc tile_alloc;
|
|
|
|
Alloc bin_alloc;
|
|
|
|
Alloc ptcl_alloc;
|
|
|
|
Alloc pathseg_alloc;
|
|
|
|
Alloc anno_alloc;
|
|
|
|
Alloc trans_alloc;
|
2022-03-03 09:44:03 +11:00
|
|
|
Alloc path_bbox_alloc;
|
2021-12-03 03:41:41 +11:00
|
|
|
Alloc drawmonoid_alloc;
|
2022-02-18 11:25:41 +11:00
|
|
|
Alloc clip_alloc;
|
|
|
|
Alloc clip_bic_alloc;
|
|
|
|
Alloc clip_stack_alloc;
|
|
|
|
Alloc clip_bbox_alloc;
|
2022-03-03 09:44:03 +11:00
|
|
|
Alloc draw_bbox_alloc;
|
|
|
|
Alloc drawinfo_alloc;
|
2021-12-03 03:41:41 +11:00
|
|
|
uint n_trans;
|
2021-12-03 10:07:33 +11:00
|
|
|
uint n_path;
|
2022-02-18 11:25:41 +11:00
|
|
|
uint n_clip;
|
2021-12-03 03:41:41 +11:00
|
|
|
uint trans_offset;
|
|
|
|
uint linewidth_offset;
|
2021-12-03 10:07:33 +11:00
|
|
|
uint pathtag_offset;
|
2021-12-03 03:41:41 +11:00
|
|
|
uint pathseg_offset;
|
2022-03-03 09:44:03 +11:00
|
|
|
uint drawtag_offset;
|
|
|
|
uint drawdata_offset;
|
2021-12-03 03:41:41 +11:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ConfigBuf
|
|
|
|
{
|
|
|
|
Config conf;
|
|
|
|
};
|
|
|
|
|
2022-03-03 09:44:03 +11:00
|
|
|
struct SceneBuf
|
2021-12-03 03:41:41 +11:00
|
|
|
{
|
2022-03-03 09:44:03 +11:00
|
|
|
uint scene[1];
|
|
|
|
};
|
2021-12-03 03:41:41 +11:00
|
|
|
|
2022-03-03 09:44:03 +11:00
|
|
|
struct DrawMonoid_1
|
2021-12-03 03:41:41 +11:00
|
|
|
{
|
2022-03-03 09:44:03 +11:00
|
|
|
uint path_ix;
|
|
|
|
uint clip_ix;
|
|
|
|
uint scene_offset;
|
|
|
|
uint info_offset;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct OutBuf
|
|
|
|
{
|
|
|
|
DrawMonoid_1 outbuf[1];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Memory
|
|
|
|
{
|
|
|
|
uint mem_offset;
|
|
|
|
uint mem_error;
|
|
|
|
uint memory[1];
|
|
|
|
};
|
|
|
|
|
|
|
|
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 map_tag(thread const uint& tag_word)
|
2021-12-03 03:41:41 +11:00
|
|
|
{
|
2022-03-03 09:44:03 +11:00
|
|
|
uint has_path = uint(tag_word != 0u);
|
|
|
|
return DrawMonoid{ has_path, tag_word & 1u, tag_word & 28u, (tag_word >> uint(4)) & 28u };
|
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;
|
|
|
|
}
|
|
|
|
|
2022-03-03 09:44:03 +11:00
|
|
|
kernel void main0(const device ConfigBuf& _86 [[buffer(1)]], const device SceneBuf& _96 [[buffer(2)]], device OutBuf& _187 [[buffer(3)]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]], uint3 gl_LocalInvocationID [[thread_position_in_threadgroup]], uint3 gl_WorkGroupID [[threadgroup_position_in_grid]])
|
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;
|
2022-03-03 09:44:03 +11:00
|
|
|
uint drawtag_base = _86.conf.drawtag_offset >> uint(2);
|
|
|
|
uint tag_word = _96.scene[drawtag_base + ix];
|
|
|
|
uint param = tag_word;
|
|
|
|
DrawMonoid agg = map_tag(param);
|
2021-12-03 03:41:41 +11:00
|
|
|
for (uint i = 1u; i < 8u; i++)
|
|
|
|
{
|
2022-03-03 09:44:03 +11:00
|
|
|
uint tag_word_1 = _96.scene[(drawtag_base + ix) + i];
|
|
|
|
uint param_1 = tag_word_1;
|
|
|
|
DrawMonoid param_2 = agg;
|
|
|
|
DrawMonoid param_3 = map_tag(param_1);
|
|
|
|
agg = combine_draw_monoid(param_2, param_3);
|
2021-12-03 03:41:41 +11:00
|
|
|
}
|
|
|
|
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);
|
2021-12-09 05:42:35 +11:00
|
|
|
if ((gl_LocalInvocationID.x + (1u << i_1)) < 256u)
|
2021-12-03 03:41:41 +11:00
|
|
|
{
|
|
|
|
DrawMonoid other = sh_scratch[gl_LocalInvocationID.x + (1u << i_1)];
|
2022-03-03 09:44:03 +11:00
|
|
|
DrawMonoid param_4 = agg;
|
|
|
|
DrawMonoid param_5 = other;
|
|
|
|
agg = combine_draw_monoid(param_4, param_5);
|
2021-12-03 03:41:41 +11:00
|
|
|
}
|
|
|
|
threadgroup_barrier(mem_flags::mem_threadgroup);
|
|
|
|
sh_scratch[gl_LocalInvocationID.x] = agg;
|
|
|
|
}
|
|
|
|
if (gl_LocalInvocationID.x == 0u)
|
|
|
|
{
|
2022-03-03 09:44:03 +11:00
|
|
|
_187.outbuf[gl_WorkGroupID.x].path_ix = agg.path_ix;
|
|
|
|
_187.outbuf[gl_WorkGroupID.x].clip_ix = agg.clip_ix;
|
|
|
|
_187.outbuf[gl_WorkGroupID.x].scene_offset = agg.scene_offset;
|
|
|
|
_187.outbuf[gl_WorkGroupID.x].info_offset = agg.info_offset;
|
2021-12-03 03:41:41 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|