Blender V5.3
gpu_shader_index_gen.bsl.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
8
9namespace index_gen {
10
11struct Resources {
14 [[storage(0, write)]] uint (&out_indices)[];
15};
16
17#define INDEX_GEN_GROUP_SIZE 16
18
26 [[resource_table]] const Resources &srt,
27 [[global_invocation_id]] const uint3 global_id,
28 [[num_work_groups]] const uint3 num_groups)
29{
30 int3 gid = int3(global_id);
31 int3 nthreads = int3(num_groups * uint3(INDEX_GEN_GROUP_SIZE, INDEX_GEN_GROUP_SIZE, 1));
32 for (int y = gid.y + gid.z * nthreads.y; y < srt.ncurves; y += nthreads.y * nthreads.z) {
33 for (int x = gid.x; x < srt.elements_per_curve; x += nthreads.x) {
34 int store_index = x + y * srt.elements_per_curve;
35 srt.out_indices[store_index] = (x + 1 < srt.elements_per_curve) ?
36 uint(x + y * (srt.elements_per_curve - 1)) :
37 0xFFFFFFFFu;
38 }
39 }
40}
41
53 [[resource_table]] const Resources &srt,
54 [[global_invocation_id]] const uint3 global_id,
55 [[num_work_groups]] const uint3 num_groups)
56{
57 int3 gid = int3(global_id);
58 int3 nthreads = int3(num_groups * uint3(INDEX_GEN_GROUP_SIZE, INDEX_GEN_GROUP_SIZE, 1));
59 for (int y = gid.y + gid.z * nthreads.y; y < srt.ncurves; y += nthreads.y * nthreads.z) {
60 for (int x = gid.x; x < srt.elements_per_curve; x += nthreads.x) {
61 int store_index = (x + y * srt.elements_per_curve) * 2;
62 uint t = uint(x + y * (srt.elements_per_curve + 1));
63 srt.out_indices[store_index] = t;
64 srt.out_indices[store_index + 1] = t + 1u;
65 }
66 }
67}
68
76 [[resource_table]] const Resources &srt,
77 [[global_invocation_id]] const uint3 global_id,
78 [[num_work_groups]] const uint3 num_groups)
79{
80 int3 gid = int3(global_id);
81 int3 nthreads = int3(num_groups * uint3(INDEX_GEN_GROUP_SIZE, INDEX_GEN_GROUP_SIZE, 1));
82 for (int y = gid.y + gid.z * nthreads.y; y < srt.ncurves; y += nthreads.y * nthreads.z) {
83 for (int x = gid.x; x < srt.elements_per_curve; x += nthreads.x) {
84 int store_index = (x + y * srt.elements_per_curve) * 6;
85 uint t = x * 2 + y * (srt.elements_per_curve * 2 + 2);
86 srt.out_indices[store_index + 0] = t;
87 srt.out_indices[store_index + 1] = t + 1u;
88 srt.out_indices[store_index + 2] = t + 2u;
89 srt.out_indices[store_index + 3] = t + 1u;
90 srt.out_indices[store_index + 4] = t + 3u;
91 srt.out_indices[store_index + 5] = t + 2u;
92 }
93 }
94}
95
96} // namespace index_gen
97
#define storage(slot, qualifiers)
#define push_constant
#define resource_table
#define global_invocation_id
#define compute
#define num_work_groups
#define local_size(...)
PipelineCompute gpu_shader_index_2d_array_lines(index_gen::gen_lines)
PipelineCompute gpu_shader_index_2d_array_tris(index_gen::gen_triangles)
#define INDEX_GEN_GROUP_SIZE
PipelineCompute gpu_shader_index_2d_array_points(index_gen::gen_points)
void gen_lines(const Resources &srt, const uint3 global_id, const uint3 num_groups)
void gen_points(const Resources &srt, const uint3 global_id, const uint3 num_groups)
void gen_triangles(const Resources &srt, const uint3 global_id, const uint3 num_groups)