Blender V5.3
draw_curves_topology.bsl.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
11
12#pragma once
13
15#include "gpu_shader_offset_indices_lib.glsl"
16
17namespace curves {
18
19struct Topology {
20 /* Offsets giving the start and end of the curve. */
21 [[storage(0, read)]] int (&evaluated_offsets_buf)[];
22 [[storage(1, read)]] uint (&curves_cyclic_buf)[]; /* Actually bool (1 byte). */
23 [[storage(2, write)]] int (&indirection_buf)[];
28};
29
31 [[resource_table]] Topology &srt, [[global_invocation_id]] const uint3 global_id)
32{
33 if (global_id.x >= uint(srt.curves_count)) {
34 return;
35 }
36 uint curve_id = global_id.x + uint(srt.curves_start);
37
38 bool is_curve_cyclic = false;
39 if (srt.use_cyclic) {
40 /* Note: Quirk of the force_inline implementation. */
41 bool value = gpu_attr_load_bool(srt.curves_cyclic_buf, curve_id);
42 is_curve_cyclic = value;
43 }
44
45 IndexRange points = offset_indices::load_range_from_buffer(srt.evaluated_offsets_buf,
46 int(curve_id));
47 int index_start = points.start();
48 int num_segment = points.size();
49
50 if (srt.use_cyclic) {
51 index_start += int(curve_id);
52 num_segment += 1;
53 }
54
55 constexpr int cyclic_endpoint_pivot = INT_MAX / 2;
56 constexpr int end_of_curve = INT_MAX;
57
58 int indirection_index_count = num_segment + (srt.is_ribbon_topology ? 1 : -1);
59 index_start += int(srt.is_ribbon_topology ? curve_id : -curve_id);
60
61 for (int i = 0; i < indirection_index_count; i++) {
62 int value = (i == 0) ? int(curve_id) : -i;
63
64 bool is_restart = false;
65 bool is_cyclic_last_segment = false;
66
67 if (srt.use_cyclic) {
68 if (srt.is_ribbon_topology) {
69 is_cyclic_last_segment = i == indirection_index_count - 2;
70 if (is_curve_cyclic) {
71 is_restart = i == indirection_index_count - 1;
72 }
73 else {
74 is_restart = i >= indirection_index_count - 2;
75 }
76 }
77 else {
78 is_cyclic_last_segment = i == indirection_index_count - 1;
79 if (is_curve_cyclic) {
80 is_restart = false;
81 }
82 else {
83 is_restart = i == indirection_index_count - 1;
84 }
85 }
86 }
87 else {
88 if (srt.is_ribbon_topology) {
89 is_restart = i == indirection_index_count - 1;
90 }
91 else {
92 is_restart = false;
93 }
94 }
95
96 srt.indirection_buf[index_start + i] = is_restart ? end_of_curve :
97 (is_cyclic_last_segment ?
98 value - cyclic_endpoint_pivot :
99 value);
100 }
101}
102
103} // namespace curves
104
#define CURVES_PER_THREADGROUP
PipelineCompute draw_curves_topology(curves::eval_topology)
bool gpu_attr_load_bool(const uint(&data)[], uint i)
#define INT_MAX
#define storage(slot, qualifiers)
#define push_constant
#define resource_table
#define global_invocation_id
#define compute
#define local_size(...)
void eval_topology(Topology &srt, const uint3 global_id)