Blender V5.3
subdiv_common.bsl.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2021-2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
12
13float2 decode_uv(uint encoded_uv)
14{
15 float u = float((encoded_uv >> 16) & 0xFFFFu) / 65535.0f;
16 float v = float(encoded_uv & 0xFFFFu) / 65535.0f;
17 return float2(u, v);
18}
19
20bool is_set(uint i)
21{
22 /* QuadNode.Child.isSet is the first bit of the bit-field. */
23 return (i & 0x1u) != 0;
24}
25
26bool is_leaf(uint i)
27{
28 /* QuadNode.Child.isLeaf is the second bit of the bit-field. */
29 return (i & 0x2u) != 0;
30}
31
32uint get_index(uint i)
33{
34 /* QuadNode.Child.index is made of the remaining bits. */
35 return (i >> 2) & 0x3FFFFFFFu;
36}
37
38#define ORIGINDEX_NONE -1
39
42
43 uint get_global_invocation_index(const uint3 global_id, const uint3 num_work_groups) const
44 {
45 uint invocations_per_row = SUBDIV_GROUP_SIZE * num_work_groups.x;
46 return global_id.x + global_id.y * invocations_per_row;
47 }
48};
49
52
53 /* Given the index of the subdivision quad, return the index of the corresponding coarse polygon.
54 * This uses subdiv_face_offset and since it is a growing list of offsets, we can use binary
55 * search to locate the right index. */
56 uint coarse_face_index_from_subdiv_quad_index(uint subdiv_quad_index,
57 uint coarse_face_count) const
58 {
59 uint first = 0;
60 uint last = coarse_face_count;
61
62 while (first != last) {
63 uint middle = (first + last) / 2;
64
65 if (subdiv_face_offset[middle] < subdiv_quad_index) {
66 first = middle + 1;
67 }
68 else {
69 last = middle;
70 }
71 }
72
73 if (first < coarse_face_count && subdiv_face_offset[first] == subdiv_quad_index) {
74 return first;
75 }
76
77 return first - 1;
78 }
79};
#define SHADER_DATA_BUF_SLOT
#define SUBDIV_GROUP_SIZE
#define SUBDIV_FACE_OFFSET_BUF_SLOT
#define uniform(slot)
#define storage(slot, qualifiers)
#define num_work_groups
VecBase< uint32_t, 3 > uint3
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
uint coarse_face_index_from_subdiv_quad_index(uint subdiv_quad_index, uint coarse_face_count) const
const DRWSubdivUboStorage shader_data
uint get_global_invocation_index(const uint3 global_id, const uint3 num_work_groups) const
float2 decode_uv(uint encoded_uv)
bool is_set(uint i)
uint get_index(uint i)
bool is_leaf(uint i)