1 | #include "taichi/program/field_info.h" |
2 | |
3 | namespace taichi { |
4 | |
5 | namespace ui { |
6 | |
7 | using namespace taichi::lang; |
8 | |
9 | DevicePtr get_device_ptr(taichi::lang::Program *program, SNode *snode) { |
10 | /* |
11 | GGUI makes the assumption that the input fields are created directly from |
12 | ti.field() or ti.Vector field with `shape` specified. In other words, we |
13 | assume that the fields are created via ti.root.dense.place() That is, the |
14 | parent of the snode is a dense, and the parent of that node is a root. Note |
15 | that, GGUI's python-side code creates a staging buffer to construct the VBO, |
16 | which obeys this assumption. Thus, the only situation where this assumption |
17 | may be violated is for set_image(), because the image isn't part of the VBO. |
18 | Using this assumption, we will compute the offset of this field relative to |
19 | the begin of the root buffer. |
20 | */ |
21 | |
22 | SNode *dense_parent = snode->parent; |
23 | SNode *root = dense_parent->parent; |
24 | |
25 | int tree_id = root->get_snode_tree_id(); |
26 | DevicePtr root_ptr = program->get_snode_tree_device_ptr(tree_id); |
27 | |
28 | return root_ptr.get_ptr(program->get_field_in_tree_offset(tree_id, snode)); |
29 | } |
30 | |
31 | } // namespace ui |
32 | |
33 | } // namespace taichi |
34 | |