Blender V5.3
draw_cache_impl_subdivision.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2021 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
10#include "draw_subdivision.hh"
11
12#include "DNA_mesh_types.h"
13#include "DNA_object_types.h"
14#include "DNA_scene_types.h"
15
16#include "BKE_attribute.hh"
17#include "BKE_editmesh.hh"
18#include "BKE_mesh.hh"
19#include "BKE_mesh_mapping.hh"
20#include "BKE_object.hh"
21#include "BKE_subdiv.hh"
22#include "BKE_subdiv_eval.hh"
23#include "BKE_subdiv_foreach.hh"
24#include "BKE_subdiv_mesh.hh"
26
27#include "BLI_linklist.hh"
28#include "BLI_mutex.hh"
29#include "BLI_virtual_array.hh"
30
31#include "DRW_engine.hh"
32#include "DRW_render.hh"
33
34#include "GPU_capabilities.hh"
35#include "GPU_compute.hh"
36#include "GPU_index_buffer.hh"
37#include "GPU_state.hh"
38#include "GPU_uniform_buffer.hh"
39#include "GPU_vertex_buffer.hh"
40
43#ifdef WITH_OPENSUBDIV
46#endif
47
48#include "draw_cache_extract.hh"
49#include "draw_cache_impl.hh"
50#include "draw_cache_inline.hh"
51#include "draw_common_c.hh"
52#include "draw_shader.hh"
55
56namespace blender::draw {
57
58/* -------------------------------------------------------------------- */
63
64#ifdef WITH_OPENSUBDIV
65/* Vertex format used for the `PatchTable::PatchHandle`. */
66static const GPUVertFormat &get_patch_handle_format()
67{
68 static const GPUVertFormat format = [&]() {
69 GPUVertFormat format{};
70 GPU_vertformat_attr_add(&format, "vert_index", gpu::VertAttrType::SINT_32);
71 GPU_vertformat_attr_add(&format, "array_index", gpu::VertAttrType::SINT_32);
72 GPU_vertformat_attr_add(&format, "patch_index", gpu::VertAttrType::SINT_32);
73 return format;
74 }();
75 return format;
76}
77
78/* Vertex format used for the quad-tree nodes of the PatchMap. */
79static const GPUVertFormat &get_quadtree_format()
80{
81 static const GPUVertFormat format = [&]() {
82 GPUVertFormat format{};
83 GPU_vertformat_attr_add(&format, "child", gpu::VertAttrType::UINT_32_32_32_32);
84 return format;
85 }();
86 return format;
87}
88
89struct CompressedPatchCoord {
90 int ptex_face_index;
91 /* UV coordinate encoded as u << 16 | v, where u and v are quantized on 16-bits. */
92 uint encoded_uv;
93};
94
95MINLINE CompressedPatchCoord make_patch_coord(int ptex_face_index, float u, float v)
96{
97 CompressedPatchCoord patch_coord = {
98 ptex_face_index,
99 (uint(u * 65535.0f) << 16) | uint(v * 65535.0f),
100 };
101 return patch_coord;
102}
103
104/* Vertex format used for the #CompressedPatchCoord. */
105static const GPUVertFormat &get_blender_patch_coords_format()
106{
107 static const GPUVertFormat format = [&]() {
108 GPUVertFormat format{};
109 /* WARNING! Adjust #CompressedPatchCoord accordingly. */
110 GPU_vertformat_attr_add(&format, "ptex_face_index", gpu::VertAttrType::UINT_32);
111 GPU_vertformat_attr_add(&format, "uv", gpu::VertAttrType::UINT_32);
112 return format;
113 }();
114 return format;
115}
116
117#endif
118
120{
121 static const GPUVertFormat format = [&]() {
122 GPUVertFormat format{};
123 GPU_vertformat_attr_add(&format, "index", gpu::VertAttrType::SINT_32);
124 return format;
125 }();
126 return format;
127}
128
130
131// --------------------------------------------------------
132
133static uint tris_count_from_number_of_loops(const uint number_of_loops)
134{
135 const uint32_t number_of_quads = number_of_loops / 4;
136 return number_of_quads * 2;
137}
138
139/* -------------------------------------------------------------------- */
142
144 uint num_loops,
145 uint loose_len)
146{
149 GPU_vertbuf_data_alloc(*buffer, num_loops + loose_len);
150
151 buffer->data<int32_t>().take_front(num_loops).copy_from({vert_origindex, num_loops});
152 return buffer;
153}
154
156{
157 return draw_subdiv_init_origindex_buffer(vert_origindex, num_loops, 0).release();
158}
159
161{
164 GPU_vertbuf_data_alloc(*buffer, vert_origindex.size() + loose_len);
165
166 buffer->data<int32_t>().take_front(vert_origindex.size()).copy_from(vert_origindex);
167 return buffer;
168}
169
171{
172 return draw_subdiv_init_origindex_buffer(vert_origindex, 0).release();
173}
174
176
177/* -------------------------------------------------------------------- */
180
181#ifdef WITH_OPENSUBDIV
182
183static void draw_patch_map_build(DRWPatchMap *gpu_patch_map, bke::subdiv::Subdiv *subdiv)
184{
185 gpu::VertBuf *patch_map_handles = GPU_vertbuf_calloc();
186 GPU_vertbuf_init_with_format_ex(*patch_map_handles, get_patch_handle_format(), GPU_USAGE_STATIC);
187
188 gpu::VertBuf *patch_map_quadtree = GPU_vertbuf_calloc();
189 GPU_vertbuf_init_with_format_ex(*patch_map_quadtree, get_quadtree_format(), GPU_USAGE_STATIC);
190
191 int min_patch_face = 0;
192 int max_patch_face = 0;
193 int max_depth = 0;
194 int patches_are_triangular = 0;
195
196 OpenSubdiv_Evaluator *evaluator = subdiv->evaluator;
197 evaluator->eval_output->getPatchMap(patch_map_handles,
198 patch_map_quadtree,
199 &min_patch_face,
200 &max_patch_face,
201 &max_depth,
202 &patches_are_triangular);
203
204 gpu_patch_map->patch_map_handles = patch_map_handles;
205 gpu_patch_map->patch_map_quadtree = patch_map_quadtree;
206 gpu_patch_map->min_patch_face = min_patch_face;
207 gpu_patch_map->max_patch_face = max_patch_face;
208 gpu_patch_map->max_depth = max_depth;
209 gpu_patch_map->patches_are_triangular = patches_are_triangular;
210}
211
212#endif
213
214static void draw_patch_map_free(DRWPatchMap *gpu_patch_map)
215{
218 gpu_patch_map->min_patch_face = 0;
219 gpu_patch_map->max_patch_face = 0;
220 gpu_patch_map->max_depth = 0;
221 gpu_patch_map->patches_are_triangular = false;
222}
223
225
226/* -------------------------------------------------------------------- */
229
231{
232 return cache.subdiv && cache.subdiv->evaluator && cache.num_subdiv_loops != 0;
233}
234
236{
238 MEM_SAFE_DELETE(cache.mat_start);
239 MEM_SAFE_DELETE(cache.mat_end);
240}
241
249
280
281/* Flags used in #DRWSubdivCache.extra_coarse_face_data. The flags are packed in the upper bits of
282 * each uint (one per coarse face), #SUBDIV_COARSE_FACE_FLAG_OFFSET tells where they are in the
283 * packed bits. */
284#define SUBDIV_COARSE_FACE_FLAG_SMOOTH 1u
285#define SUBDIV_COARSE_FACE_FLAG_SELECT 2u
286#define SUBDIV_COARSE_FACE_FLAG_ACTIVE 4u
287#define SUBDIV_COARSE_FACE_FLAG_HIDDEN 8u
288
289#define SUBDIV_COARSE_FACE_FLAG_OFFSET 28u
290
291#define SUBDIV_COARSE_FACE_FLAG_SMOOTH_MASK \
292 (SUBDIV_COARSE_FACE_FLAG_SMOOTH << SUBDIV_COARSE_FACE_FLAG_OFFSET)
293#define SUBDIV_COARSE_FACE_FLAG_SELECT_MASK \
294 (SUBDIV_COARSE_FACE_FLAG_SELECT << SUBDIV_COARSE_FACE_FLAG_OFFSET)
295#define SUBDIV_COARSE_FACE_FLAG_ACTIVE_MASK \
296 (SUBDIV_COARSE_FACE_FLAG_ACTIVE << SUBDIV_COARSE_FACE_FLAG_OFFSET)
297#define SUBDIV_COARSE_FACE_FLAG_HIDDEN_MASK \
298 (SUBDIV_COARSE_FACE_FLAG_HIDDEN << SUBDIV_COARSE_FACE_FLAG_OFFSET)
299
300#define SUBDIV_COARSE_FACE_LOOP_START_MASK \
301 ~((SUBDIV_COARSE_FACE_FLAG_SMOOTH | SUBDIV_COARSE_FACE_FLAG_SELECT | \
302 SUBDIV_COARSE_FACE_FLAG_ACTIVE | SUBDIV_COARSE_FACE_FLAG_HIDDEN) \
303 << SUBDIV_COARSE_FACE_FLAG_OFFSET)
304
306{
307 uint32_t flag = 0;
310 }
313 }
314 if (f == efa_act) {
316 }
317 return flag;
318}
319
321 BMFace *efa_act,
322 MutableSpan<uint32_t> flags_data)
323{
324 BMFace *f;
325 BMIter iter;
326
327 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
328 const int index = BM_elem_index_get(f);
329 uint32_t flag = compute_coarse_face_flag_bm(f, efa_act);
332 }
333 const int loopstart = BM_elem_index_get(f->l_first);
334 flags_data[index] = uint(loopstart) | (flag << SUBDIV_COARSE_FACE_FLAG_OFFSET);
335 }
336}
337
339 const Mesh *mesh,
340 MutableSpan<uint32_t> flags_data)
341{
342 const OffsetIndices faces = mesh->faces();
343 for (const int i : faces.index_range()) {
344 uint32_t flag = 0;
346 (!mr.sharp_faces.is_empty() && mr.sharp_faces[i])))
347 {
349 }
350 if (!mr.select_poly.is_empty() && mr.select_poly[i]) {
352 }
353 if (!mr.hide_poly.is_empty() && mr.hide_poly[i]) {
355 }
356 flags_data[i] = uint(faces[i].start()) | (flag << SUBDIV_COARSE_FACE_FLAG_OFFSET);
357 }
358}
359
361 BMesh *bm,
362 MeshRenderData &mr,
363 MutableSpan<uint32_t> flags_data)
364{
365 if (bm == nullptr) {
367 return;
368 }
369
370 const OffsetIndices faces = mesh->faces();
371 for (const int i : faces.index_range()) {
372 BMFace *f = bm_original_face_get(mr, i);
373 /* Selection and hiding from bmesh. */
374 uint32_t flag = (f) ? compute_coarse_face_flag_bm(f, mr.efa_act) : 0;
375 /* Smooth from mesh. */
377 (!mr.sharp_faces.is_empty() && mr.sharp_faces[i])))
378 {
380 }
381 flags_data[i] = uint(faces[i].start()) | (flag << SUBDIV_COARSE_FACE_FLAG_OFFSET);
382 }
383}
384
386 const Mesh *mesh,
387 MeshRenderData &mr)
388{
389 if (cache.extra_coarse_face_data == nullptr) {
391 static const GPUVertFormat format = []() {
392 GPUVertFormat format{};
393 GPU_vertformat_attr_add(&format, "data", gpu::VertAttrType::UINT_32);
394 return format;
395 }();
399 mesh->faces_num);
400 }
401
403
406 }
407 else if (mr.orig_index_face != nullptr) {
409 }
410 else {
412 }
413
414 /* Make sure updated data is re-uploaded. */
416}
417
419{
420 DRWSubdivCache *subdiv_cache = mbc.subdiv_cache;
421 if (subdiv_cache == nullptr) {
422 subdiv_cache = MEM_new<DRWSubdivCache>(__func__);
423 }
424 mbc.subdiv_cache = subdiv_cache;
425 return *subdiv_cache;
426}
427
428#ifdef WITH_OPENSUBDIV
429
430static void draw_subdiv_invalidate_evaluator_for_orco(bke::subdiv::Subdiv *subdiv,
431 const Mesh *mesh)
432{
433 if (!(subdiv && subdiv->evaluator)) {
434 return;
435 }
436
437 const bool has_orco = CustomData_has_layer(&mesh->vert_data, CD_ORCO);
438 if (has_orco && !subdiv->evaluator->eval_output->hasVertexData()) {
439 /* If we suddenly have/need original coordinates, recreate the evaluator if the extra
440 * source was not created yet. The refiner also has to be recreated as refinement for source
441 * and vertex data is done only once. */
442 delete subdiv->evaluator;
443 subdiv->evaluator = nullptr;
444
445 delete subdiv->topology_refiner;
446 subdiv->topology_refiner = nullptr;
447 }
448}
449
451
452/* -------------------------------------------------------------------- */
462
463struct DRWCacheBuildingContext {
464 const Mesh *coarse_mesh;
465 const bke::subdiv::Subdiv *subdiv;
466 const bke::subdiv::ToMeshSettings *settings;
467
468 DRWSubdivCache *cache;
469
470 /* Pointers into #DRWSubdivCache buffers for easier access during traversal. */
471 CompressedPatchCoord *patch_coords;
472 int *subdiv_loop_vert_index;
473 int *subdiv_loop_subdiv_vert_index;
474 int *subdiv_loop_edge_index;
475 int *subdiv_loop_edge_draw_flag;
476 int *subdiv_loop_subdiv_edge_index;
477 int *subdiv_loop_face_index;
478
479 /* Temporary buffers used during traversal. */
480 int *vert_origindex_map;
481 int *edge_draw_flag_map;
482 int *edge_origindex_map;
483
484 /* #CD_ORIGINDEX layers from the mesh to directly look up during traversal the original-index
485 * from the base mesh for edit data so that we do not have to handle yet another GPU buffer and
486 * do this in the shaders. */
487 const int *orig_index_vert;
488 const int *orig_index_edge;
489};
490
491static bool draw_subdiv_topology_info_cb(const bke::subdiv::ForeachContext *foreach_context,
492 const int num_verts,
493 const int num_edges,
494 const int num_loops,
495 const int num_faces,
496 const Span<int> subdiv_face_offset)
497{
498 /* num_loops does not take into account meshes with only loose geometry, which might be meshes
499 * used as custom bone shapes, so let's check the num_verts also. */
500 if (num_verts == 0 && num_loops == 0) {
501 return false;
502 }
503
504 DRWCacheBuildingContext *ctx = (DRWCacheBuildingContext *)(foreach_context->user_data);
505 DRWSubdivCache *cache = ctx->cache;
506
507 /* Set topology information only if we have loops. */
508 if (num_loops != 0) {
509 cache->num_subdiv_edges = uint(num_edges);
510 cache->num_subdiv_loops = uint(num_loops);
511 cache->num_subdiv_verts = uint(num_verts);
512 cache->num_subdiv_quads = uint(num_faces);
513 cache->subdiv_face_offset = subdiv_face_offset;
514 }
515
516 cache->may_have_loose_geom = num_verts != 0 || num_edges != 0;
517
518 /* Initialize cache buffers, prefer dynamic usage so we can reuse memory on the host even after
519 * it was sent to the device, since we may use the data while building other buffers on the CPU
520 * side.
521 *
522 * These VBOs are created even when there are no faces and only loose geometry. This avoids the
523 * need for many null checks. Binding them must be avoided if they are empty though. */
524 cache->patch_coords = GPU_vertbuf_calloc();
526 *cache->patch_coords, get_blender_patch_coords_format(), GPU_USAGE_DYNAMIC);
527 GPU_vertbuf_data_alloc(*cache->patch_coords, cache->num_subdiv_loops);
528
529 cache->corner_patch_coords = GPU_vertbuf_calloc();
531 *cache->corner_patch_coords, get_blender_patch_coords_format(), GPU_USAGE_DYNAMIC);
532 GPU_vertbuf_data_alloc(*cache->corner_patch_coords, cache->num_subdiv_loops);
533
534 cache->verts_orig_index = GPU_vertbuf_calloc();
536 *cache->verts_orig_index, get_origindex_format(), GPU_USAGE_DYNAMIC);
537 GPU_vertbuf_data_alloc(*cache->verts_orig_index, cache->num_subdiv_loops);
538
539 cache->edges_orig_index = GPU_vertbuf_calloc();
541 *cache->edges_orig_index, get_origindex_format(), GPU_USAGE_DYNAMIC);
542 GPU_vertbuf_data_alloc(*cache->edges_orig_index, cache->num_subdiv_loops);
543
544 cache->edges_draw_flag = GPU_vertbuf_calloc();
546 *cache->edges_draw_flag, get_origindex_format(), GPU_USAGE_DYNAMIC);
547 GPU_vertbuf_data_alloc(*cache->edges_draw_flag, cache->num_subdiv_loops);
548
549 cache->subdiv_loop_subdiv_vert_index = MEM_new_array_uninitialized<int>(
550 cache->num_subdiv_loops, "subdiv_loop_subdiv_vert_index");
551
552 cache->subdiv_loop_subdiv_edge_index = MEM_new_array_uninitialized<int>(
553 cache->num_subdiv_loops, "subdiv_loop_subdiv_edge_index");
554
555 cache->subdiv_loop_face_index = MEM_new_array_uninitialized<int>(cache->num_subdiv_loops,
556 "subdiv_loop_face_index");
557
558 /* Initialize context pointers and temporary buffers. */
559 ctx->patch_coords = cache->patch_coords->data<CompressedPatchCoord>().data();
560 ctx->subdiv_loop_vert_index = cache->verts_orig_index->data<int>().data();
561 ctx->subdiv_loop_edge_index = cache->edges_orig_index->data<int>().data();
562 ctx->subdiv_loop_edge_draw_flag = cache->edges_draw_flag->data<int>().data();
563 ctx->subdiv_loop_subdiv_vert_index = cache->subdiv_loop_subdiv_vert_index;
564 ctx->subdiv_loop_subdiv_edge_index = cache->subdiv_loop_subdiv_edge_index;
565 ctx->subdiv_loop_face_index = cache->subdiv_loop_face_index;
566
567 ctx->orig_index_vert = static_cast<const int *>(
568 CustomData_get_layer(&ctx->coarse_mesh->vert_data, CD_ORIGINDEX));
569
570 ctx->orig_index_edge = static_cast<const int *>(
571 CustomData_get_layer(&ctx->coarse_mesh->edge_data, CD_ORIGINDEX));
572
573 if (cache->num_subdiv_verts) {
574 ctx->vert_origindex_map = MEM_new_array_uninitialized<int>(cache->num_subdiv_verts,
575 "subdiv_vert_origindex_map");
576 for (int i = 0; i < num_verts; i++) {
577 ctx->vert_origindex_map[i] = -1;
578 }
579 }
580
581 if (cache->num_subdiv_edges) {
582 ctx->edge_origindex_map = MEM_new_array_uninitialized<int>(cache->num_subdiv_edges,
583 "subdiv_edge_origindex_map");
584 for (int i = 0; i < num_edges; i++) {
585 ctx->edge_origindex_map[i] = -1;
586 }
587 ctx->edge_draw_flag_map = MEM_new_array_zeroed<int>(cache->num_subdiv_edges,
588 "subdiv_edge_draw_flag_map");
589 }
590
591 return true;
592}
593
594static void draw_subdiv_vert_corner_cb(const bke::subdiv::ForeachContext *foreach_context,
595 void * /*tls*/,
596 const int /*ptex_face_index*/,
597 const float /*u*/,
598 const float /*v*/,
599 const int coarse_vert_index,
600 const int /*coarse_face_index*/,
601 const int /*coarse_corner*/,
602 const int subdiv_vert_index)
603{
604 BLI_assert(coarse_vert_index != ORIGINDEX_NONE);
605 DRWCacheBuildingContext *ctx = (DRWCacheBuildingContext *)(foreach_context->user_data);
606 ctx->vert_origindex_map[subdiv_vert_index] = coarse_vert_index;
607}
608
609static void draw_subdiv_vert_edge_cb(const bke::subdiv::ForeachContext * /*foreach_context*/,
610 void * /*tls_v*/,
611 const int /*ptex_face_index*/,
612 const float /*u*/,
613 const float /*v*/,
614 const int /*coarse_edge_index*/,
615 const int /*coarse_face_index*/,
616 const int /*coarse_corner*/,
617 const int /*subdiv_vert_index*/)
618{
619 /* Required if bke::subdiv::ForeachContext.vert_corner is also set. */
620}
621
622static void draw_subdiv_edge_cb(const bke::subdiv::ForeachContext *foreach_context,
623 void * /*tls*/,
624 const int coarse_edge_index,
625 const int subdiv_edge_index,
626 const bool /*is_loose*/,
627 const int /*subdiv_v1*/,
628 const int /*subdiv_v2*/)
629{
630 DRWCacheBuildingContext *ctx = (DRWCacheBuildingContext *)(foreach_context->user_data);
631
632 if (!ctx->edge_origindex_map) {
633 return;
634 }
635
636 if (coarse_edge_index == ORIGINDEX_NONE) {
637 /* Not mapped to edge in the subdivision base mesh. */
638 ctx->edge_origindex_map[subdiv_edge_index] = ORIGINDEX_NONE;
639 if (!ctx->cache->optimal_display) {
640 ctx->edge_draw_flag_map[subdiv_edge_index] = 1;
641 }
642 }
643 else {
644 if (ctx->orig_index_edge) {
645 const int origindex = ctx->orig_index_edge[coarse_edge_index];
646 ctx->edge_origindex_map[subdiv_edge_index] = origindex;
647 if (!(origindex == ORIGINDEX_NONE && ctx->cache->hide_unmapped_edges)) {
648 /* Not mapped to edge in original mesh (generated by a preceding modifier). */
649 ctx->edge_draw_flag_map[subdiv_edge_index] = 1;
650 }
651 }
652 else {
653 ctx->edge_origindex_map[subdiv_edge_index] = coarse_edge_index;
654 ctx->edge_draw_flag_map[subdiv_edge_index] = 1;
655 }
656 }
657}
658
659static void draw_subdiv_loop_cb(const bke::subdiv::ForeachContext *foreach_context,
660 void * /*tls_v*/,
661 const int ptex_face_index,
662 const float u,
663 const float v,
664 const int /*coarse_loop_index*/,
665 const int coarse_face_index,
666 const int /*coarse_corner*/,
667 const int subdiv_loop_index,
668 const int subdiv_vert_index,
669 const int subdiv_edge_index)
670{
671 DRWCacheBuildingContext *ctx = (DRWCacheBuildingContext *)(foreach_context->user_data);
672 ctx->patch_coords[subdiv_loop_index] = make_patch_coord(ptex_face_index, u, v);
673
674 int coarse_vert_index = ctx->vert_origindex_map[subdiv_vert_index];
675
676 ctx->subdiv_loop_subdiv_vert_index[subdiv_loop_index] = subdiv_vert_index;
677 ctx->subdiv_loop_subdiv_edge_index[subdiv_loop_index] = subdiv_edge_index;
678 ctx->subdiv_loop_face_index[subdiv_loop_index] = coarse_face_index;
679 ctx->subdiv_loop_vert_index[subdiv_loop_index] = coarse_vert_index;
680}
681
682static void draw_subdiv_foreach_callbacks(bke::subdiv::ForeachContext *foreach_context)
683{
684 *foreach_context = {};
685 foreach_context->topology_info = draw_subdiv_topology_info_cb;
686 foreach_context->loop = draw_subdiv_loop_cb;
687 foreach_context->edge = draw_subdiv_edge_cb;
688 foreach_context->vert_corner = draw_subdiv_vert_corner_cb;
689 foreach_context->vert_edge = draw_subdiv_vert_edge_cb;
690}
691
692static void do_subdiv_traversal(DRWCacheBuildingContext *cache_building_context,
693 bke::subdiv::Subdiv *subdiv)
694{
695 bke::subdiv::ForeachContext foreach_context;
696 draw_subdiv_foreach_callbacks(&foreach_context);
697 foreach_context.user_data = cache_building_context;
698
700 &foreach_context,
701 cache_building_context->settings,
702 cache_building_context->coarse_mesh);
703
704 /* Now that traversal is done, we can set up the right original indices for the
705 * subdiv-loop-to-coarse-edge map.
706 */
707 for (int i = 0; i < cache_building_context->cache->num_subdiv_loops; i++) {
708 const int edge_index = cache_building_context->subdiv_loop_subdiv_edge_index[i];
709 cache_building_context->subdiv_loop_edge_index[i] =
710 cache_building_context->edge_origindex_map[edge_index];
711 cache_building_context->subdiv_loop_edge_draw_flag[i] =
712 cache_building_context->edge_draw_flag_map[edge_index];
713 }
714}
715
716static gpu::VertBuf *gpu_vertbuf_create_from_format(const GPUVertFormat &format, uint len)
717{
718 gpu::VertBuf *verts = GPU_vertbuf_calloc();
719 GPU_vertbuf_init_with_format(*verts, format);
721 return verts;
722}
723
724/* Build maps to hold enough information to tell which face is adjacent to which vertex; those will
725 * be used for computing normals if limit surfaces are unavailable. */
726static void build_vert_face_adjacency_maps(DRWSubdivCache &cache)
727{
728 /* +1 so that we do not require a special case for the last vertex, this extra offset will
729 * contain the total number of adjacent faces. */
730 cache.subdiv_vert_face_adjacency_offsets = gpu_vertbuf_create_from_format(
731 get_origindex_format(), cache.num_subdiv_verts + 1);
732
733 MutableSpan<int> vert_offsets = cache.subdiv_vert_face_adjacency_offsets->data<int>();
734 vert_offsets.fill(0);
735
737 {cache.subdiv_loop_subdiv_vert_index, cache.num_subdiv_loops}, vert_offsets);
738
739 cache.subdiv_vert_face_adjacency = gpu_vertbuf_create_from_format(get_origindex_format(),
740 cache.num_subdiv_loops);
741 MutableSpan<int> adjacent_faces = cache.subdiv_vert_face_adjacency->data<int>();
742 int *tmp_set_faces = MEM_new_array_zeroed<int>(cache.num_subdiv_verts,
743 "tmp subdiv vertex offset");
744
745 for (int i = 0; i < cache.num_subdiv_loops / 4; i++) {
746 for (int j = 0; j < 4; j++) {
747 const int subdiv_vert = cache.subdiv_loop_subdiv_vert_index[i * 4 + j];
748 int first_face_offset = vert_offsets[subdiv_vert] + tmp_set_faces[subdiv_vert];
749 adjacent_faces[first_face_offset] = i;
750 tmp_set_faces[subdiv_vert] += 1;
751 }
752 }
753
754 MEM_delete(tmp_set_faces);
755}
756
757static bool draw_subdiv_build_cache(DRWSubdivCache &cache,
758 bke::subdiv::Subdiv *subdiv,
759 const Mesh *mesh_eval,
760 const SubsurfRuntimeData *runtime_data)
761{
762 bke::subdiv::ToMeshSettings to_mesh_settings;
763 to_mesh_settings.resolution = runtime_data->resolution;
764 to_mesh_settings.use_optimal_display = false;
765
766 if (cache.resolution != to_mesh_settings.resolution) {
767 /* Resolution changed, we need to rebuild, free any existing cached data. */
769 }
770
771 /* If the resolution between the cache and the settings match for some reason, check if the patch
772 * coordinates were not already generated. Those coordinates are specific to the resolution, so
773 * they should be null either after initialization, or after freeing if the resolution (or some
774 * other subdivision setting) changed.
775 */
776 if (cache.patch_coords != nullptr) {
777 return true;
778 }
779
780 DRWCacheBuildingContext cache_building_context;
781 memset(&cache_building_context, 0, sizeof(DRWCacheBuildingContext));
782 cache_building_context.coarse_mesh = mesh_eval;
783 cache_building_context.settings = &to_mesh_settings;
784 cache_building_context.cache = &cache;
785
786 do_subdiv_traversal(&cache_building_context, subdiv);
787 if (cache.num_subdiv_loops == 0 && cache.num_subdiv_verts == 0 && !cache.may_have_loose_geom) {
788 /* Either the traversal failed, or we have an empty mesh, either way we cannot go any further.
789 * The subdiv_face_offset cannot then be reliably stored in the cache, so free it directly.
790 */
791 cache.subdiv_face_offset = {};
792 return false;
793 }
794
795 /* Only build face related data if we have polygons. */
796 const OffsetIndices faces = mesh_eval->faces();
797 if (cache.num_subdiv_loops != 0) {
798 /* Build buffers for the PatchMap. */
799 draw_patch_map_build(&cache.gpu_patch_map, subdiv);
800
801 cache.face_ptex_offset = bke::subdiv::face_ptex_offset_get(subdiv);
802
803 /* Build patch coordinates for all the face dots. */
804 cache.fdots_patch_coords = gpu_vertbuf_create_from_format(get_blender_patch_coords_format(),
805 mesh_eval->faces_num);
806 CompressedPatchCoord *blender_fdots_patch_coords =
807 cache.fdots_patch_coords->data<CompressedPatchCoord>().data();
808 for (int i = 0; i < mesh_eval->faces_num; i++) {
809 const int ptex_face_index = cache.face_ptex_offset[i];
810 if (faces[i].size() == 4) {
811 /* For quads, the center coordinate of the coarse face has `u = v = 0.5`. */
812 blender_fdots_patch_coords[i] = make_patch_coord(ptex_face_index, 0.5f, 0.5f);
813 }
814 else {
815 /* For N-gons, since they are split into quads from the center, and since the center is
816 * chosen to be the top right corner of each quad, the center coordinate of the coarse face
817 * is any one of those top right corners with `u = v = 1.0`. */
818 blender_fdots_patch_coords[i] = make_patch_coord(ptex_face_index, 1.0f, 1.0f);
819 }
820 }
821
822 cache.subdiv_face_offset_buffer = draw_subdiv_build_origindex_buffer(
823 cache.subdiv_face_offset.data(), faces.size());
824
825 cache.face_ptex_offset_buffer = draw_subdiv_build_origindex_buffer(cache.face_ptex_offset);
826
827 build_vert_face_adjacency_maps(cache);
828 }
829
830 cache.resolution = to_mesh_settings.resolution;
831 cache.num_coarse_faces = faces.size();
832
833 /* To avoid floating point precision issues when evaluating patches at patch boundaries,
834 * ensure that all loops sharing a vertex use the same patch coordinate. This could cause
835 * the mesh to not be watertight, leading to shadowing artifacts (see #97877). */
836 Vector<int> first_loop_index(cache.num_subdiv_verts, -1);
837
838 /* Save coordinates for corners, as attributes may vary for each loop connected to the same
839 * vertex. */
840 if (cache.num_subdiv_loops > 0) {
841 memcpy(cache.corner_patch_coords->data<CompressedPatchCoord>().data(),
842 cache_building_context.patch_coords,
843 sizeof(CompressedPatchCoord) * cache.num_subdiv_loops);
844
845 for (int i = 0; i < cache.num_subdiv_loops; i++) {
846 const int vert = cache_building_context.subdiv_loop_subdiv_vert_index[i];
847 if (first_loop_index[vert] != -1) {
848 continue;
849 }
850 first_loop_index[vert] = i;
851 }
852
853 for (int i = 0; i < cache.num_subdiv_loops; i++) {
854 const int vert = cache_building_context.subdiv_loop_subdiv_vert_index[i];
855 cache_building_context.patch_coords[i] =
856 cache_building_context.patch_coords[first_loop_index[vert]];
857 }
858 }
859
860 /* Cleanup. */
861 MEM_SAFE_DELETE(cache_building_context.vert_origindex_map);
862 MEM_SAFE_DELETE(cache_building_context.edge_origindex_map);
863 MEM_SAFE_DELETE(cache_building_context.edge_draw_flag_map);
864
865 return true;
866}
867
868#endif
869
871
872/* -------------------------------------------------------------------- */
877
880 const int src_offset,
881 const int dst_offset,
882 const uint total_dispatch_size,
883 const bool has_sculpt_mask,
884 const uint edge_loose_offset)
885{
886 ubo->src_offset = src_offset;
887 ubo->dst_offset = dst_offset;
890 ubo->max_depth = cache.gpu_patch_map.max_depth;
894 ubo->edge_loose_offset = edge_loose_offset;
895 ubo->has_sculpt_mask = has_sculpt_mask;
901 ubo->total_dispatch_size = total_dispatch_size;
902 ubo->is_edit_mode = cache.is_edit_mode;
903 ubo->use_hide = cache.use_hide;
904}
905
907 const int src_offset,
908 const int dst_offset,
909 const uint total_dispatch_size,
910 const bool has_sculpt_mask = false,
911 const uint edge_loose_offset = 0)
912{
915 &storage,
916 src_offset,
917 dst_offset,
918 total_dispatch_size,
919 has_sculpt_mask,
920 edge_loose_offset);
921
922 if (!cache.ubo) {
923 const_cast<DRWSubdivCache *>(&cache)->ubo = GPU_uniformbuf_create_ex(
924 sizeof(DRWSubdivUboStorage), &storage, "DRWSubdivUboStorage");
925 }
926
929}
930
932
933// --------------------------------------------------------
934
935#define SUBDIV_LOCAL_WORK_GROUP_SIZE 64
937{
939}
940
948 const int src_offset,
949 const int dst_offset,
950 uint total_dispatch_size,
951 const bool has_sculpt_mask = false,
952 const uint edge_loose_offset = 0)
953{
954 const uint max_res_x = uint(GPU_max_work_group_count(0));
955
956 const uint dispatch_size = get_dispatch_size(total_dispatch_size);
957 uint dispatch_rx = dispatch_size;
958 uint dispatch_ry = 1u;
959 if (dispatch_rx > max_res_x) {
960 /* Since there are some limitations with regards to the maximum work group size (could be as
961 * low as 64k elements per call), we split the number elements into a "2d" number, with the
962 * final index being computed as `res_x + res_y * max_work_group_size`. Even with a maximum
963 * work group size of 64k, that still leaves us with roughly `64k * 64k = 4` billion elements
964 * total, which should be enough. If not, we could also use the 3rd dimension. */
965 /* TODO(fclem): We could dispatch fewer groups if we compute the prime factorization and
966 * get the smallest rect fitting the requirements. */
967 dispatch_rx = dispatch_ry = ceilf(sqrtf(dispatch_size));
968 /* Avoid a completely empty dispatch line caused by rounding. */
969 if ((dispatch_rx * (dispatch_ry - 1)) >= dispatch_size) {
970 dispatch_ry -= 1;
971 }
972 }
973
974 /* X and Y dimensions may have different limits so the above computation may not be right, but
975 * even with the standard 64k minimum on all dimensions we still have a lot of room. Therefore,
976 * we presume it all fits. */
977 BLI_assert(dispatch_ry < uint(GPU_max_work_group_count(1)));
978
980 cache, src_offset, dst_offset, total_dispatch_size, has_sculpt_mask, edge_loose_offset);
981
982 GPU_compute_dispatch(shader, dispatch_rx, dispatch_ry, 1);
983}
984
986{
987#ifdef WITH_OPENSUBDIV
989 /* Happens on meshes with only loose geometry. */
990 return;
991 }
992
994 OpenSubdiv_Evaluator *evaluator = subdiv->evaluator;
995
996 gpu::VertBuf *src_buffer = evaluator->eval_output->get_source_buf();
997 gpu::VertBuf *src_extra_buffer = nullptr;
998 if (orco) {
999 src_extra_buffer = evaluator->eval_output->get_source_data_buf();
1000 }
1001
1002 gpu::StorageBuf *patch_arrays_buffer = evaluator->eval_output->create_patch_arrays_buf();
1003 gpu::StorageBuf *patch_index_buffer = evaluator->eval_output->get_patch_index_buf();
1004 gpu::StorageBuf *patch_param_buffer = evaluator->eval_output->get_patch_param_buf();
1005
1009
1020 if (orco) {
1021 GPU_vertbuf_bind_as_ssbo(src_extra_buffer,
1024 }
1025
1027
1028 /* This generates a vertex buffer, so we need to put a barrier on the vertex attribute array.
1029 * We also need it for subsequent compute shaders, so a barrier on the shader storage is also
1030 * needed. */
1032
1033 /* Cleanup. */
1035
1036 GPU_storagebuf_free(patch_arrays_buffer);
1037#else
1038 UNUSED_VARS(cache, pos, orco);
1039#endif
1040}
1041
1043 gpu::VertBuf *uvs,
1044 const int face_varying_channel,
1045 const int dst_offset)
1046{
1047#ifdef WITH_OPENSUBDIV
1049 /* Happens on meshes with only loose geometry. */
1050 return;
1051 }
1052
1054 OpenSubdiv_Evaluator *evaluator = subdiv->evaluator;
1055
1056 gpu::VertBuf *src_buffer = evaluator->eval_output->get_face_varying_source_buf(
1057 face_varying_channel);
1058 int src_buffer_offset = evaluator->eval_output->get_face_varying_source_offset(
1059 face_varying_channel);
1060
1061 gpu::StorageBuf *patch_arrays_buffer =
1062 evaluator->eval_output->create_face_varying_patch_array_buf(face_varying_channel);
1063 gpu::StorageBuf *patch_index_buffer = evaluator->eval_output->get_face_varying_patch_index_buf(
1064 face_varying_channel);
1065 gpu::StorageBuf *patch_param_buffer = evaluator->eval_output->get_face_varying_patch_param_buf(
1066 face_varying_channel);
1067
1070
1081
1082 /* The buffer offset has the stride baked in (which is 2 as we have UVs) so remove the stride by
1083 * dividing by 2 */
1085 cache, shader, src_buffer_offset / 2, dst_offset, cache.num_subdiv_quads);
1086
1087 /* This generates a vertex buffer, so we need to put a barrier on the vertex attribute array.
1088 * Since it may also be used for computing UV stretches, we also need a barrier on the shader
1089 * storage. */
1091
1092 /* Cleanup. */
1094
1095 GPU_storagebuf_free(patch_arrays_buffer);
1096#else
1097 UNUSED_VARS(cache, uvs, face_varying_channel, dst_offset);
1098#endif
1099}
1100
1102 gpu::VertBuf &src_data,
1103 gpu::VertBuf &dst_data,
1104 GPUVertCompType comp_type,
1105 int dimensions,
1106 int dst_offset)
1107{
1109 /* Happens on meshes with only loose geometry. */
1110 return;
1111 }
1112
1113 gpu::Shader *shader = DRW_shader_subdiv_custom_data_get(comp_type, dimensions);
1115
1116 /* subdiv_face_offset is always at binding point 0 for each shader using it. */
1124
1125 drw_subdiv_compute_dispatch(cache, shader, 0, dst_offset, cache.num_subdiv_quads);
1126
1127 /* This generates a vertex buffer, so we need to put a barrier on the vertex attribute array. Put
1128 * a barrier on the shader storage as we may use the result in another compute shader. */
1130
1131 /* Cleanup. */
1133}
1134
1136 gpu::VertBuf &src_data,
1137 gpu::VertBuf &dst_data)
1138{
1140 /* Happens on meshes with only loose geometry. */
1141 return;
1142 }
1143
1146
1147 /* subdiv_face_offset is always at binding point 0 for each shader using it. */
1155
1157
1158 /* This generates a vertex buffer, so we need to put a barrier on the vertex attribute array. Put
1159 * a barrier on the shader storage as we may use the result in another compute shader. */
1161
1162 /* Cleanup. */
1164}
1165
1167 gpu::VertBuf *mask_vbo,
1168 gpu::VertBuf *face_set_vbo,
1169 gpu::VertBuf *sculpt_data)
1170{
1173
1174 /* Mask VBO is always at binding point 0. */
1175 if (mask_vbo) {
1177 }
1180
1181 drw_subdiv_compute_dispatch(cache, shader, 0, 0, cache.num_subdiv_quads, mask_vbo != nullptr);
1182
1183 /* This generates a vertex buffer, so we need to put a barrier on the vertex attribute array. */
1185
1186 /* Cleanup. */
1188}
1189
1191 gpu::VertBuf *pos,
1192 gpu::VertBuf *face_adjacency_offsets,
1193 gpu::VertBuf *face_adjacency_lists,
1194 gpu::VertBuf *vert_loop_map,
1195 gpu::VertBuf *vert_normals)
1196{
1199
1201 GPU_vertbuf_bind_as_ssbo(face_adjacency_offsets,
1206
1208
1209 /* This generates a vertex buffer, so we need to put a barrier on the vertex attribute array.
1210 * We also need it for subsequent compute shaders, so a barrier on the shader storage is also
1211 * needed. */
1213
1214 /* Cleanup. */
1216}
1217
1219 gpu::IndexBuf *subdiv_tris,
1220 const int material_count)
1221{
1223 /* Happens on meshes with only loose geometry. */
1224 return;
1225 }
1226
1227 const bool do_single_material = material_count <= 1;
1228
1230 do_single_material ? SubdivShaderType::BUFFER_TRIS :
1233
1234 /* subdiv_face_offset is always at binding point 0 for each shader using it. */
1237 if (!do_single_material) {
1239 }
1240
1241 /* Outputs */
1243
1245
1246 /* This generates an index buffer, so we need to put a barrier on the element array. */
1248
1249 /* Cleanup. */
1251}
1252
1254 gpu::VertBuf *fdots_pos,
1255 gpu::VertBuf *fdots_nor,
1256 gpu::IndexBuf *fdots_indices)
1257{
1258#ifdef WITH_OPENSUBDIV
1260 /* Happens on meshes with only loose geometry. */
1261 return;
1262 }
1263
1265 OpenSubdiv_Evaluator *evaluator = subdiv->evaluator;
1266
1267 gpu::VertBuf *src_buffer = evaluator->eval_output->get_source_buf();
1268 gpu::StorageBuf *patch_arrays_buffer = evaluator->eval_output->create_patch_arrays_buf();
1269 gpu::StorageBuf *patch_index_buffer = evaluator->eval_output->get_patch_index_buf();
1270 gpu::StorageBuf *patch_param_buffer = evaluator->eval_output->get_patch_param_buf();
1271
1276
1289 /* F-dots normals may not be requested, still reserve the binding point. */
1290 if (fdots_nor) {
1292 }
1296
1298
1299 /* This generates two vertex buffers and an index buffer, so we need to put a barrier on the
1300 * vertex attributes and element arrays. */
1302
1303 /* Cleanup. */
1305
1306 GPU_storagebuf_free(patch_arrays_buffer);
1307#else
1308 UNUSED_VARS(cache, fdots_pos, fdots_nor, fdots_indices);
1309#endif
1310}
1311
1330
1332 gpu::IndexBuf *lines_indices,
1333 gpu::VertBuf *lines_flags,
1334 uint edge_loose_offset,
1335 uint num_loose_edges)
1336{
1339
1342
1343 drw_subdiv_compute_dispatch(cache, shader, 0, 0, num_loose_edges, false, edge_loose_offset);
1344
1345 /* This generates an index buffer, so we need to put a barrier on the element array. */
1347
1348 /* Cleanup. */
1350}
1351
1353 gpu::VertBuf *pos,
1354 gpu::VertBuf *edge_draw_flag,
1355 gpu::VertBuf *poly_other_map,
1356 gpu::VertBuf *edge_fac)
1357{
1360
1365
1367
1368 /* This generates a vertex buffer, so we need to put a barrier on the vertex attribute array. */
1370
1371 /* Cleanup. */
1373}
1374
1376 gpu::VertBuf *pos,
1377 gpu::VertBuf *vert_normals,
1378 gpu::VertBuf *subdiv_corner_verts,
1379 gpu::VertBuf *lnor)
1380{
1382 /* Happens on meshes with only loose geometry. */
1383 return;
1384 }
1385
1388
1389 /* Inputs */
1396
1397 /* Outputs */
1399
1401
1402 /* This generates a vertex buffer, so we need to put a barrier on the vertex attribute array. */
1404
1405 /* Cleanup. */
1407}
1408
1410{
1412 /* Happens on meshes with only loose geometry. */
1413 return;
1414 }
1415
1418
1419 /* Inputs */
1424
1425 /* Outputs */
1427
1429
1430 /* This generates a vertex buffer, so we need to put a barrier on the vertex attribute array. */
1432
1433 /* Cleanup. */
1435}
1436
1438 gpu::VertBuf *coarse_data,
1439 gpu::VertBuf *subdiv_data)
1440{
1443
1444 /* Inputs */
1445 /* subdiv_face_offset is always at binding point 0 for each shader using it. */
1448 /* Outputs */
1450
1452
1453 /* This generates a vertex buffer, so we need to put a barrier on the vertex attribute array. */
1455
1456 /* Cleanup. */
1458}
1459
1461 gpu::VertBuf *pos,
1462 gpu::VertBuf *uvs,
1463 int uvs_offset,
1464 gpu::VertBuf *stretch_angles)
1465{
1468
1469 /* Inputs */
1472 /* Outputs */
1474
1475 drw_subdiv_compute_dispatch(cache, shader, uvs_offset, 0, cache.num_subdiv_quads);
1476
1477 /* This generates a vertex buffer, so we need to put a barrier on the vertex attribute array. */
1479
1480 /* Cleanup. */
1482}
1483
1484/* -------------------------------------------------------------------- */
1485
1520 const Mesh *mesh_eval,
1521 uint mat_len)
1522{
1524
1525 const int number_of_quads = cache.num_subdiv_loops / 4;
1526
1527 if (mat_len == 1) {
1528 cache.mat_start = MEM_new_zeroed<int>("subdiv mat_end");
1529 cache.mat_end = MEM_new_zeroed<int>("subdiv mat_end");
1530 cache.mat_start[0] = 0;
1531 cache.mat_end[0] = number_of_quads;
1532 return;
1533 }
1534
1535 const bke::AttributeAccessor attributes = mesh_eval->attributes();
1536 const VArraySpan<int> material_indices = *attributes.lookup_or_default<int>(
1537 "material_index", bke::AttrDomain::Face, 0);
1538
1539 /* Count number of subdivided polygons for each material. */
1540 int *mat_start = MEM_new_array_zeroed<int>(mat_len, "subdiv mat_start");
1541 int *subdiv_face_offset = cache.subdiv_face_offset.data();
1542
1543 /* TODO: parallel_reduce? */
1544 for (int i = 0; i < mesh_eval->faces_num; i++) {
1545 const int next_offset = (i == mesh_eval->faces_num - 1) ? number_of_quads :
1546 subdiv_face_offset[i + 1];
1547 const int quad_count = next_offset - subdiv_face_offset[i];
1548 const uint mat_index = uint(material_indices[i]) < mat_len ? uint(material_indices[i]) : 0;
1549 mat_start[mat_index] += quad_count;
1550 }
1551
1552 /* Accumulate offsets. */
1553 int ofs = mat_start[0];
1554 mat_start[0] = 0;
1555 for (uint i = 1; i < mat_len; i++) {
1556 int tmp = mat_start[i];
1557 mat_start[i] = ofs;
1558 ofs += tmp;
1559 }
1560
1561 /* Compute per face offsets. */
1562 int *mat_end = MEM_dupalloc(mat_start);
1563 int *per_face_mat_offset = MEM_new_array_uninitialized<int>(mesh_eval->faces_num,
1564 "per_face_mat_offset");
1565
1566 for (int i = 0; i < mesh_eval->faces_num; i++) {
1567 const uint mat_index = uint(material_indices[i]) < mat_len ? uint(material_indices[i]) : 0;
1568 const int single_material_index = subdiv_face_offset[i];
1569 const int material_offset = mat_end[mat_index];
1570 const int next_offset = (i == mesh_eval->faces_num - 1) ? number_of_quads :
1571 subdiv_face_offset[i + 1];
1572 const int quad_count = next_offset - subdiv_face_offset[i];
1573 mat_end[mat_index] += quad_count;
1574
1575 per_face_mat_offset[i] = material_offset - single_material_index;
1576 }
1577
1578 cache.face_mat_offset = draw_subdiv_build_origindex_buffer(per_face_mat_offset,
1579 mesh_eval->faces_num);
1580 cache.mat_start = mat_start;
1581 cache.mat_end = mat_end;
1582
1583 MEM_delete(per_face_mat_offset);
1584}
1585
1593/* The evaluator cache is global, so we cannot allow concurrent usage and need synchronization. */
1595
1597 Mesh &mesh,
1598 MeshBatchCache &batch_cache,
1599 MeshBufferCache &mbc,
1600 const Span<IBOType> ibo_requests,
1601 const Span<VBOType> vbo_requests,
1602 const bool is_editmode,
1603 const bool is_paint_mode,
1604 const bool do_final,
1605 const bool do_uvedit,
1606 const bool do_cage,
1607 const ToolSettings *ts,
1608 const bool use_hide)
1609{
1610 SubsurfRuntimeData *runtime_data = mesh.runtime->subsurf_runtime_data;
1611 BLI_assert(runtime_data && runtime_data->has_gpu_subdiv);
1612
1613 if (runtime_data->settings.level == 0) {
1614 return false;
1615 }
1616
1617 const Mesh *mesh_eval = &mesh;
1618 BMesh *bm = nullptr;
1619 if (mesh.runtime->edit_mesh) {
1620 mesh_eval = BKE_object_get_editmesh_eval_final(&ob);
1622 }
1623
1624#ifdef WITH_OPENSUBDIV
1625 draw_subdiv_invalidate_evaluator_for_orco(runtime_data->subdiv_gpu, mesh_eval);
1626#endif
1627
1629 runtime_data, mesh_eval, true);
1630 if (!subdiv) {
1631 return false;
1632 }
1633
1634 /* Lock the entire evaluation to avoid concurrent usage of shader objects in evaluator cache. */
1635 std::scoped_lock lock(g_subdiv_eval_mutex);
1636
1637 if (g_subdiv_evaluator_cache == nullptr) {
1639 }
1640
1641 /* Increment evaluator cache reference if an evaluator has been assigned to it. */
1642 bool evaluator_might_be_assigned = subdiv->evaluator == nullptr;
1643 auto maybe_increment_cache_ref = [evaluator_might_be_assigned](bke::subdiv::Subdiv *subdiv) {
1644 if (evaluator_might_be_assigned && subdiv->evaluator != nullptr) {
1645 /* An evaluator was assigned. */
1647 }
1648 };
1649
1652 {
1653 /* This could happen in two situations:
1654 * - OpenSubdiv is disabled.
1655 * - Something totally bad happened, and OpenSubdiv rejected our topology.
1656 * In either way, we can't safely continue. However, we still have to handle potential loose
1657 * geometry, which is done separately. */
1658 if (mesh_eval->faces_num) {
1659 maybe_increment_cache_ref(subdiv);
1660 return false;
1661 }
1662 }
1663
1664 DRWSubdivCache &draw_cache = mesh_batch_cache_ensure_subdiv_cache(batch_cache);
1665
1666 draw_cache.optimal_display = runtime_data->use_optimal_display;
1667 /* If there is no distinct cage, hide unmapped edges that can't be selected. */
1668 draw_cache.hide_unmapped_edges = is_editmode && !do_cage;
1669 draw_cache.bm = bm;
1670 draw_cache.mesh = mesh_eval;
1671 draw_cache.subdiv = subdiv;
1672
1673#ifdef WITH_OPENSUBDIV
1674 if (!draw_subdiv_build_cache(draw_cache, subdiv, mesh_eval, runtime_data)) {
1675 maybe_increment_cache_ref(subdiv);
1676 return false;
1677 }
1678#endif
1679
1681
1682 /* Copy topology information for stats display. */
1683 runtime_data->stats_totvert = draw_cache.num_subdiv_verts;
1684 runtime_data->stats_totedge = draw_cache.num_subdiv_edges;
1685 runtime_data->stats_faces_num = draw_cache.num_subdiv_quads;
1686 runtime_data->stats_totloop = draw_cache.num_subdiv_loops;
1687
1688 draw_cache.use_custom_loop_normals = (runtime_data->use_loop_normals) &&
1689 mesh_eval->attributes().contains("custom_normal");
1690
1691 if (ibo_requests.contains(IBOType::Tris)) {
1692 draw_subdiv_cache_ensure_mat_offsets(draw_cache, mesh_eval, batch_cache.mat_len);
1693 }
1694
1696 ob, mesh, is_editmode, is_paint_mode, do_final, do_uvedit, use_hide, ts);
1697 draw_cache.use_hide = use_hide;
1698
1699 /* Used for setting loop normals flags. Mapped extraction is only used during edit mode.
1700 * See comments in #extract_lnor_iter_face_mesh.
1701 */
1702 draw_cache.is_edit_mode = mr.edit_bmesh != nullptr;
1703
1704 draw_subdiv_cache_update_extra_coarse_face_data(draw_cache, mesh_eval, mr);
1705
1707 batch_cache, mbc, ibo_requests, vbo_requests, draw_cache, mr);
1708
1709 maybe_increment_cache_ref(subdiv);
1710 return true;
1711}
1712
1714{
1715 const IndexMask &loose_edges = cache.loose_geom.edges;
1716 if (loose_edges.is_empty()) {
1717 return;
1718 }
1719
1720 if (!subdiv_cache.loose_edge_positions.is_empty()) {
1721 /* Already processed. */
1722 return;
1723 }
1724
1725 const Mesh *coarse_mesh = subdiv_cache.mesh;
1726 const bool is_simple = subdiv_cache.subdiv->settings.is_simple;
1727 const int resolution = subdiv_cache.resolution;
1728 const int resolution_1 = resolution - 1;
1729 const float inv_resolution_1 = 1.0f / float(resolution_1);
1730
1731 const Span<float3> coarse_positions = coarse_mesh->vert_positions();
1732 const Span<int2> coarse_edges = coarse_mesh->edges();
1733
1734 Array<int> vert_to_edge_offsets;
1735 Array<int> vert_to_edge_indices;
1736 const GroupedSpan<int> vert_to_edge_map = bke::mesh::build_vert_to_edge_map(
1737 coarse_edges, coarse_mesh->verts_num, vert_to_edge_offsets, vert_to_edge_indices);
1738
1739 /* Also store the last vertex to simplify copying the positions to the VBO. */
1740 subdiv_cache.loose_edge_positions.reinitialize(loose_edges.size() * resolution);
1741 MutableSpan<float3> edge_positions = subdiv_cache.loose_edge_positions;
1742
1743 loose_edges.foreach_index([&](const int coarse_edge, const int i) {
1744 MutableSpan positions = edge_positions.slice(i * resolution, resolution);
1745 for (const int j : positions.index_range()) {
1746 positions[j] = bke::subdiv::mesh_interpolate_position_on_edge(coarse_positions,
1747 coarse_edges,
1748 vert_to_edge_map,
1749 coarse_edge,
1750 is_simple,
1751 j * inv_resolution_1);
1752 }
1753 });
1754}
1755
1765
1767 Mesh &mesh,
1768 MeshBatchCache &batch_cache,
1769 MeshBufferCache &mbc,
1770 const Span<IBOType> ibo_requests,
1771 const Span<VBOType> vbo_requests,
1772 const bool is_editmode,
1773 const bool is_paint_mode,
1774 const bool do_final,
1775 const bool do_uvedit,
1776 const bool do_cage,
1777 const ToolSettings *ts,
1778 const bool use_hide)
1779{
1780
1781#undef TIME_SUBDIV
1782
1783#ifdef TIME_SUBDIV
1784 const double begin_time = BLI_time_now_seconds();
1785#endif
1786
1788 mesh,
1789 batch_cache,
1790 mbc,
1791 ibo_requests,
1792 vbo_requests,
1793 is_editmode,
1794 is_paint_mode,
1795 do_final,
1796 do_uvedit,
1797 do_cage,
1798 ts,
1799 use_hide))
1800 {
1801 /* Did not run. */
1802 return;
1803 }
1804
1805#ifdef TIME_SUBDIV
1806 const double end_time = BLI_time_now_seconds();
1807 fprintf(stderr, "Time to update subdivision: %f\n", end_time - begin_time);
1808 fprintf(stderr, "Maximum FPS: %f\n", 1.0 / (end_time - begin_time));
1809#endif
1810}
1811
1817
1819{
1820 {
1821 std::scoped_lock lock(gpu_subdiv_queue_mutex);
1822
1823 while (gpu_subdiv_free_queue != nullptr) {
1826
1827 {
1828 std::scoped_lock lock(g_subdiv_eval_mutex);
1829 if (subdiv->evaluator != nullptr) {
1831 }
1832 }
1833#ifdef WITH_OPENSUBDIV
1834 /* Set the type to CPU so that we do actually free the cache. */
1835 subdiv->evaluator->type = OPENSUBDIV_EVALUATOR_CPU;
1836#endif
1838 }
1839 }
1840
1841 {
1842 std::scoped_lock lock(g_subdiv_eval_mutex);
1843 /* Free evaluator cache if there is no more reference to it.. */
1844 if (g_subdiv_evaluator_users == 0) {
1846 g_subdiv_evaluator_cache = nullptr;
1847 }
1848 }
1849}
1850
1851} // namespace blender::draw
#define ORIGINDEX_NONE
General operations, lookup, etc. for blender objects.
#define MINLINE
Object is a sort of wrapper for general info.
#define GPU_vertbuf_init_with_format(verts, format)
#define GPU_VERTBUF_DISCARD_SAFE(verts)
volatile int lock
#define UNUSED_VARS(...)
#define BLI_assert(a)
#define BM_elem_index_get(ele)
#define BM_elem_flag_test(ele, hflag)
#define BM_ITER_MESH(ele, iter, bm, itype)
const T * data() const
Definition BLI_array.hh:323
void reinitialize(const int64_t new_size)
Definition BLI_array.hh:430
bool is_empty() const
Definition BLI_array.hh:275
constexpr MutableSpan slice(const int64_t start, const int64_t size) const
Definition BLI_span.hh:579
constexpr IndexRange index_range() const
Definition BLI_span.hh:676
constexpr int64_t size() const
Definition BLI_span.hh:256
constexpr bool contains(const T &value) const
Definition BLI_span.hh:281
GAttributeReader lookup_or_default(StringRef name, AttrDomain domain, AttrType data_type, const void *default_value=nullptr) const
constexpr bool is_empty() const
MutableSpan< T > data()
void foreach_index(Fn &&fn, Mode mode=exec_mode::serial) const
gpu::VertBuf * get_face_varying_source_buf(const int face_varying_channel)
gpu::StorageBuf * get_face_varying_patch_index_buf(const int face_varying_channel)
gpu::StorageBuf * create_patch_arrays_buf()
gpu::StorageBuf * create_face_varying_patch_array_buf(const int face_varying_channel)
int get_face_varying_source_offset(const int face_varying_channel) const
gpu::StorageBuf * get_face_varying_patch_param_buf(const int face_varying_channel)
void getPatchMap(blender::gpu::VertBuf *patch_map_handles, blender::gpu::VertBuf *patch_map_quadtree, int *min_patch_face, int *max_patch_face, int *max_depth, int *patches_are_triangular)
#define SUBDIV_COARSE_FACE_FLAG_HIDDEN
#define SUBDIV_COARSE_FACE_FLAG_HIDDEN_MASK
#define SUBDIV_COARSE_FACE_FLAG_ACTIVE_MASK
#define SUBDIV_COARSE_FACE_FLAG_OFFSET
#define SUBDIV_COARSE_FACE_FLAG_SMOOTH_MASK
#define SUBDIV_COARSE_FACE_FLAG_SMOOTH
#define SUBDIV_COARSE_FACE_FLAG_ACTIVE
#define SUBDIV_COARSE_FACE_FLAG_SELECT_MASK
#define SUBDIV_LOCAL_WORK_GROUP_SIZE
#define SUBDIV_COARSE_FACE_FLAG_SELECT
#define SUBDIV_COARSE_FACE_LOOP_START_MASK
#define LOOP_NORMALS_POS_SLOT
#define LOOP_NORMALS_VERT_NORMALS_BUF_SLOT
#define EDGE_FAC_EDGE_FAC_BUF_SLOT
#define LINES_EXTRA_COARSE_FACE_DATA_BUF_SLOT
#define TRIS_OUTPUT_TRIS_BUF_SLOT
#define PATCH_EVALUATION_OUTPUT_NORMALS_BUF_SLOT
#define NORMALS_ACCUMULATE_POS_BUF_SLOT
#define PATCH_EVALUATION_OUTPUT_POS_BUF_SLOT
#define PAINT_OVERLAY_EXTRA_INPUT_VERT_ORIG_INDEX_SLOT
#define PATCH_EVALUATION_PATCH_ARRAY_BUFFER_BUF_SLOT
#define CUSTOM_DATA_SOURCE_DATA_BUF_SLOT
#define CUSTOM_DATA_FACE_PTEX_OFFSET_BUF_SLOT
#define LOOP_NORMALS_OUTPUT_LNOR_BUF_SLOT
#define LINES_OUTPUT_LINES_BUF_SLOT
#define PATCH_EVALUATION_INPUT_VERTEX_ORIG_INDEX_BUF_SLOT
#define SCULPT_DATA_SCULPT_DATA_BUF_SLOT
#define SHADER_DATA_BUF_SLOT
#define PATCH_EVALUATION_QUAD_NODES_BUF_SLOT
#define PATCH_EVALUATION_INPUT_PATCH_HANDLES_BUF_SLOT
#define PATCH_EVALUATION_SOURCE_EXTRA_VERTEX_BUFFER_BUF_SLOT
#define STRETCH_ANGLE_UV_STRETCHES_BUF_SLOT
#define NORMALS_ACCUMULATE_FACE_ADJACENCY_LISTS_BUF_SLOT
#define PATCH_EVALUATION_PATCH_PARAM_BUFFER_BUF_SLOT
#define PATCH_EVALUATION_OUTPUT_FDOTS_VERTEX_BUFFER_BUF_SLOT
#define LINES_LINES_LOOSE_FLAGS
#define EDGE_FAC_POS_BUF_SLOT
#define EDGE_FAC_POLY_OTHER_MAP_BUF_SLOT
#define LINES_INPUT_EDGE_DRAW_FLAG_BUF_SLOT
#define TRIS_EXTRA_COARSE_FACE_DATA_BUF_SLOT
#define PATCH_EVALUATION_PATCH_COORDS_BUF_SLOT
#define PATCH_EVALUATION_PATCH_INDEX_BUFFER_BUF_SLOT
#define PATCH_EVALUATION_OUTPUT_INDICES_BUF_SLOT
#define NORMALS_ACCUMULATE_NORMALS_BUF_SLOT
#define PATCH_EVALUATION_OUTPUT_ORCOS_BUF_SLOT
#define SCULPT_DATA_SCULPT_FACE_SET_COLOR_BUF_SLOT
#define LOOP_NORMALS_EXTRA_COARSE_FACE_DATA_BUF_SLOT
#define SCULPT_DATA_SCULPT_MASK_BUF_SLOT
#define PAINT_OVERLAY_EXTRA_COARSE_FACE_DATA_BUF_SLOT
#define EDGE_FAC_EDGE_DRAW_FLAG_BUF_SLOT
#define STRETCH_ANGLE_POS_BUF_SLOT
#define PATCH_EVALUATION_SOURCE_VERTEX_BUFFER_BUF_SLOT
#define TRIS_FACE_MAT_OFFSET
#define STRETCH_AREA_COARSE_STRETCH_AREA_BUF_SLOT
#define CUSTOM_DATA_DESTINATION_DATA_BUF_SLOT
#define PATCH_EVALUATION_OUTPUT_FVAR_BUF_SLOT
#define SUBDIV_FACE_OFFSET_BUF_SLOT
#define CUSTOM_DATA_EXTRA_COARSE_FACE_DATA_BUF_SLOT
#define NORMALS_ACCUMULATE_VERTEX_LOOP_MAP_BUF_SLOT
#define STRETCH_AREA_SUBDIV_STRETCH_AREA_BUF_SLOT
#define PATCH_EVALUATION_EXTRA_COARSE_FACE_DATA_BUF_SLOT
#define NORMALS_ACCUMULATE_FACE_ADJACENCY_OFFSETS_BUF_SLOT
#define LOOP_NORMALS_VERTEX_LOOP_MAP_BUF_SLOT
#define PAINT_OVERLAY_OUTPUT_FLAG_SLOT
#define STRETCH_ANGLE_UVS_BUF_SLOT
#define CUSTOM_DATA_PATCH_COORDS_BUF_SLOT
void openSubdiv_deleteEvaluatorCache(OpenSubdiv_EvaluatorCache *evaluator_cache)
OpenSubdiv_EvaluatorCache * openSubdiv_createEvaluatorCache(eOpenSubdivEvaluator evaluator_type)
Extraction of Mesh data into VBO to feed to GPU.
#define storage(slot, qualifiers)
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
Definition math_dual.h:263
GroupedSpan< int > build_vert_to_edge_map(Span< int2 > edges, int verts_num, Array< int > &r_offsets, Array< int > &r_indices)
void free(Subdiv *subdiv)
Definition subdiv.cc:192
bool eval_begin_from_mesh(Subdiv *subdiv, const Mesh *mesh, eSubdivEvaluatorType evaluator_type, Span< float3 > coarse_vert_positions={}, OpenSubdiv_EvaluatorCache *evaluator_cache=nullptr)
float3 mesh_interpolate_position_on_edge(Span< float3 > coarse_positions, Span< int2 > coarse_edges, GroupedSpan< int > vert_to_edge_map, int coarse_edge_index, bool is_simple, float u)
bool foreach_subdiv_geometry(Subdiv *subdiv, const ForeachContext *context, const ToMeshSettings *mesh_settings, const Mesh *coarse_mesh)
Span< int > face_ptex_offset_get(Subdiv *subdiv)
Definition subdiv.cc:216
BLI_INLINE BMFace * bm_original_face_get(const MeshRenderData &mr, int idx)
static void draw_subdiv_init_ubo_storage(const DRWSubdivCache &cache, DRWSubdivUboStorage *ubo, const int src_offset, const int dst_offset, const uint total_dispatch_size, const bool has_sculpt_mask, const uint edge_loose_offset)
static void draw_subdiv_cache_free_material_data(DRWSubdivCache &cache)
void draw_subdiv_build_edge_fac_buffer(const DRWSubdivCache &cache, gpu::VertBuf *pos, gpu::VertBuf *edge_draw_flag, gpu::VertBuf *poly_other_map, gpu::VertBuf *edge_fac)
static void draw_subdiv_free_edit_mode_cache(DRWSubdivCache &cache)
static bool draw_subdiv_cache_need_face_data(const DRWSubdivCache &cache)
void draw_subdiv_extract_uvs(const DRWSubdivCache &cache, gpu::VertBuf *uvs, const int face_varying_channel, const int dst_offset)
gpu::VertBufPtr draw_subdiv_init_origindex_buffer(int32_t *vert_origindex, uint num_loops, uint loose_len)
void draw_subdiv_build_edituv_stretch_area_buffer(const DRWSubdivCache &cache, gpu::VertBuf *coarse_data, gpu::VertBuf *subdiv_data)
static void draw_patch_map_free(DRWPatchMap *gpu_patch_map)
void draw_subdiv_build_lnor_buffer(const DRWSubdivCache &cache, gpu::VertBuf *pos, gpu::VertBuf *vert_normals, gpu::VertBuf *subdiv_corner_verts, gpu::VertBuf *lnor)
static void draw_subdiv_cache_ensure_mat_offsets(DRWSubdivCache &cache, const Mesh *mesh_eval, uint mat_len)
void draw_subdiv_build_fdots_buffers(const DRWSubdivCache &cache, gpu::VertBuf *fdots_pos, gpu::VertBuf *fdots_nor, gpu::IndexBuf *fdots_indices)
void draw_subdiv_interp_corner_normals(const DRWSubdivCache &cache, gpu::VertBuf &src_data, gpu::VertBuf &dst_data)
void DRW_subdivide_loose_geom(DRWSubdivCache &subdiv_cache, const MeshBufferCache &cache)
void draw_subdiv_interp_custom_data(const DRWSubdivCache &cache, gpu::VertBuf &src_data, gpu::VertBuf &dst_data, GPUVertCompType comp_type, int dimensions, int dst_offset)
void draw_subdiv_cache_free(DRWSubdivCache &cache)
void draw_subdiv_build_paint_overlay_flag_buffer(const DRWSubdivCache &cache, gpu::VertBuf &flags)
void draw_subdiv_build_tris_buffer(const DRWSubdivCache &cache, gpu::IndexBuf *subdiv_tris, const int material_count)
static LinkNode * gpu_subdiv_free_queue
void DRW_subdiv_cache_free(bke::subdiv::Subdiv *subdiv)
void draw_subdiv_build_lines_buffer(const DRWSubdivCache &cache, gpu::IndexBuf *lines_indices)
static void drw_subdiv_compute_dispatch(const DRWSubdivCache &cache, gpu::Shader *shader, const int src_offset, const int dst_offset, uint total_dispatch_size, const bool has_sculpt_mask=false, const uint edge_loose_offset=0)
static uint get_dispatch_size(uint elements)
void draw_subdiv_extract_pos(const DRWSubdivCache &cache, gpu::VertBuf *pos, gpu::VertBuf *orco)
static bool draw_subdiv_create_requested_buffers(Object &ob, Mesh &mesh, MeshBatchCache &batch_cache, MeshBufferCache &mbc, const Span< IBOType > ibo_requests, const Span< VBOType > vbo_requests, const bool is_editmode, const bool is_paint_mode, const bool do_final, const bool do_uvedit, const bool do_cage, const ToolSettings *ts, const bool use_hide)
void mesh_buffer_cache_create_requested_subdiv(MeshBatchCache &cache, MeshBufferCache &mbc, Span< IBOType > ibo_requests, Span< VBOType > vbo_requests, DRWSubdivCache &subdiv_cache, MeshRenderData &mr)
static DRWSubdivCache & mesh_batch_cache_ensure_subdiv_cache(MeshBatchCache &mbc)
void draw_subdiv_build_lines_loose_buffer(const DRWSubdivCache &cache, gpu::IndexBuf *lines_indices, gpu::VertBuf *lines_flags, uint edge_loose_offset, uint num_loose_edges)
void draw_subdiv_build_edituv_stretch_angle_buffer(const DRWSubdivCache &cache, gpu::VertBuf *pos, gpu::VertBuf *uvs, int uvs_offset, gpu::VertBuf *stretch_angles)
static uint32_t compute_coarse_face_flag_bm(BMFace *f, BMFace *efa_act)
static void draw_subdiv_cache_extra_coarse_face_data_mesh(const MeshRenderData &mr, const Mesh *mesh, MutableSpan< uint32_t > flags_data)
static void draw_subdiv_ubo_update_and_bind(const DRWSubdivCache &cache, const int src_offset, const int dst_offset, const uint total_dispatch_size, const bool has_sculpt_mask=false, const uint edge_loose_offset=0)
static uint tris_count_from_number_of_loops(const uint number_of_loops)
void draw_subdiv_build_sculpt_data_buffer(const DRWSubdivCache &cache, gpu::VertBuf *mask_vbo, gpu::VertBuf *face_set_vbo, gpu::VertBuf *sculpt_data)
void DRW_create_subdivision(Object &ob, Mesh &mesh, MeshBatchCache &batch_cache, MeshBufferCache &mbc, const Span< IBOType > ibo_requests, const Span< VBOType > vbo_requests, const bool is_editmode, const bool is_paint_mode, const bool do_final, const bool do_uvedit, const bool do_cage, const ToolSettings *ts, const bool use_hide)
gpu::VertBuf * draw_subdiv_build_origindex_buffer(int *vert_origindex, uint num_loops)
static void draw_subdiv_cache_extra_coarse_face_data_mapped(const Mesh *mesh, BMesh *bm, MeshRenderData &mr, MutableSpan< uint32_t > flags_data)
static void draw_subdiv_cache_update_extra_coarse_face_data(DRWSubdivCache &cache, const Mesh *mesh, MeshRenderData &mr)
MeshRenderData mesh_render_data_create(Object &object, Mesh &mesh, const bool is_editmode, const bool is_paint_mode, const bool do_final, const bool do_uvedit, const bool use_hide, const ToolSettings *ts)
static const GPUVertFormat & get_origindex_format()
void draw_subdiv_accumulate_normals(const DRWSubdivCache &cache, gpu::VertBuf *pos, gpu::VertBuf *face_adjacency_offsets, gpu::VertBuf *face_adjacency_lists, gpu::VertBuf *vert_loop_map, gpu::VertBuf *vert_normals)
static OpenSubdiv_EvaluatorCache * g_subdiv_evaluator_cache
static uint64_t g_subdiv_evaluator_users
static void draw_subdiv_cache_extra_coarse_face_data_bm(BMesh *bm, BMFace *efa_act, MutableSpan< uint32_t > flags_data)
int size(const AssetLibraryReference *library_reference)
std::unique_ptr< gpu::VertBuf, gpu::VertBufDeleter > VertBufPtr
OffsetIndices< int > build_reverse_offsets(Span< int > indices, MutableSpan< int > offsets)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void GPU_vertbuf_tag_dirty(gpu::VertBuf *verts)
unsigned __int64 uint64_t
Definition BKE_text.h:91
BMesh * BKE_editmesh_bmesh_get_for_write(Mesh *mesh)
Definition editmesh.cc:79
void GPU_vertbuf_init_with_format_ex(gpu::VertBuf &verts, const GPUVertFormat &format, GPUUsageType)
unsigned int uint
Definition BKE_text.h:55
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void GPU_uniformbuf_free(gpu::UniformBuf *ubo)
void void void * BLI_linklist_pop(LinkNode **listp) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
bool CustomData_has_layer(const CustomData *data, eCustomDataType type)
const Mesh * BKE_object_get_editmesh_eval_final(const Object *object)
Definition object.cc:4477
ATTR_WARN_UNUSED_RESULT const BMVert * v
void GPU_compute_dispatch(gpu::Shader *shader, uint groups_x_len, uint groups_y_len, uint groups_z_len, const gpu::shader::SpecializationConstants *constants_state=nullptr)
void GPU_vertbuf_bind_as_ssbo(gpu::VertBuf *verts, int binding)
void void BLI_linklist_prepend(LinkNode **listp, void *ptr) ATTR_NONNULL(1)
void GPU_indexbuf_bind_as_ssbo(gpu::IndexBuf *elem, int binding)
int GPU_max_work_group_count(int index)
unsigned int uint32_t
Definition BKE_text.h:81
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
void GPU_memory_barrier(GPUBarrier barrier)
Definition gpu_state.cc:305
BMesh const char void * data
void GPU_shader_unbind()
gpu::VertBuf * GPU_vertbuf_calloc()
gpu::Shader * DRW_shader_subdiv_interp_corner_normals_get()
void GPU_shader_bind(gpu::Shader *shader, const gpu::shader::SpecializationConstants *constants_state=nullptr)
@ GPU_BARRIER_VERTEX_ATTRIB_ARRAY
Definition GPU_state.hh:53
@ GPU_BARRIER_SHADER_STORAGE
Definition GPU_state.hh:51
@ GPU_BARRIER_ELEMENT_ARRAY
Definition GPU_state.hh:55
const void * CustomData_get_layer(const CustomData *data, eCustomDataType type)
void GPU_storagebuf_bind(gpu::StorageBuf *ssbo, int slot)
gpu::VertBuf * GPU_vertbuf_create_with_format_ex(const GPUVertFormat &format, GPUUsageType usage)
gpu::Shader * DRW_shader_subdiv_custom_data_get(GPUVertCompType comp_type, int dimensions)
void GPU_uniformbuf_bind(gpu::UniformBuf *ubo, int slot)
gpu::UniformBuf * GPU_uniformbuf_create_ex(size_t size, const void *data, const char *name)
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
void GPU_uniformbuf_update(gpu::UniformBuf *ubo, const void *data)
bke::subdiv::Subdiv * BKE_subsurf_modifier_subdiv_descriptor_ensure(SubsurfRuntimeData *runtime_data, const Mesh *mesh, bool for_draw_code)
std::mutex Mutex
Definition BLI_mutex.hh:51
void GPU_vertbuf_data_alloc(gpu::VertBuf &verts, uint v_len)
MINLINE uint divide_ceil_u(uint a, uint b)
signed int int32_t
Definition BKE_text.h:78
double BLI_time_now_seconds()
Definition time.cc:30
void GPU_storagebuf_free(gpu::StorageBuf *ssbo)
gpu::Shader * DRW_shader_subdiv_get(SubdivShaderType shader_type)
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
std::string format(const std::string &fmt, Args &&...args)
Definition diagnostic.hh:43
void vert(const int vert_id, float4 &position)
@ OPENSUBDIV_EVALUATOR_GPU
@ OPENSUBDIV_EVALUATOR_CPU
#define sqrtf
#define ceilf
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
blender::opensubdiv::EvalOutputAPI * eval_output
CustomData vert_data
bke::subdiv::Subdiv * subdiv_gpu
OpenSubdiv_Evaluator * evaluator
gpu::VertBuf * subdiv_vert_face_adjacency_offsets
VArraySpan< bool > sharp_faces
VArraySpan< bool > select_poly
bke::MeshNormalDomain normals_domain