66static const GPUVertFormat &get_patch_handle_format()
68 static const GPUVertFormat
format = [&]() {
79static const GPUVertFormat &get_quadtree_format()
81 static const GPUVertFormat
format = [&]() {
89struct CompressedPatchCoord {
95MINLINE CompressedPatchCoord make_patch_coord(
int ptex_face_index,
float u,
float v)
97 CompressedPatchCoord patch_coord = {
99 (
uint(u * 65535.0f) << 16) |
uint(
v * 65535.0f),
105static const GPUVertFormat &get_blender_patch_coords_format()
107 static const GPUVertFormat
format = [&]() {
135 const uint32_t number_of_quads = number_of_loops / 4;
136 return number_of_quads * 2;
151 buffer->data<
int32_t>().take_front(num_loops).copy_from({vert_origindex, num_loops});
166 buffer->data<
int32_t>().take_front(vert_origindex.
size()).copy_from(vert_origindex);
181#ifdef WITH_OPENSUBDIV
191 int min_patch_face = 0;
192 int max_patch_face = 0;
194 int patches_are_triangular = 0;
202 &patches_are_triangular);
239 MEM_SAFE_DELETE(cache.
mat_end);
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
289#define SUBDIV_COARSE_FACE_FLAG_OFFSET 28u
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)
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)
421 if (subdiv_cache ==
nullptr) {
422 subdiv_cache = MEM_new<DRWSubdivCache>(__func__);
425 return *subdiv_cache;
428#ifdef WITH_OPENSUBDIV
438 if (has_orco && !
subdiv->evaluator->eval_output->hasVertexData()) {
443 subdiv->evaluator =
nullptr;
445 delete subdiv->topology_refiner;
446 subdiv->topology_refiner =
nullptr;
463struct DRWCacheBuildingContext {
464 const Mesh *coarse_mesh;
465 const bke::subdiv::Subdiv *subdiv;
466 const bke::subdiv::ToMeshSettings *settings;
468 DRWSubdivCache *cache;
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;
480 int *vert_origindex_map;
481 int *edge_draw_flag_map;
482 int *edge_origindex_map;
487 const int *orig_index_vert;
488 const int *orig_index_edge;
491static bool draw_subdiv_topology_info_cb(
const bke::subdiv::ForeachContext *foreach_context,
496 const Span<int> subdiv_face_offset)
500 if (num_verts == 0 && num_loops == 0) {
504 DRWCacheBuildingContext *ctx = (DRWCacheBuildingContext *)(foreach_context->user_data);
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;
516 cache->may_have_loose_geom = num_verts != 0 || num_edges != 0;
531 *cache->corner_patch_coords, get_blender_patch_coords_format(),
GPU_USAGE_DYNAMIC);
550 cache->num_subdiv_loops,
"subdiv_loop_subdiv_vert_index");
553 cache->num_subdiv_loops,
"subdiv_loop_subdiv_edge_index");
556 "subdiv_loop_face_index");
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;
567 ctx->orig_index_vert =
static_cast<const int *
>(
570 ctx->orig_index_edge =
static_cast<const int *
>(
573 if (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;
581 if (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;
588 "subdiv_edge_draw_flag_map");
594static void draw_subdiv_vert_corner_cb(
const bke::subdiv::ForeachContext *foreach_context,
599 const int coarse_vert_index,
602 const int subdiv_vert_index)
605 DRWCacheBuildingContext *ctx = (DRWCacheBuildingContext *)(foreach_context->user_data);
606 ctx->vert_origindex_map[subdiv_vert_index] = coarse_vert_index;
609static void draw_subdiv_vert_edge_cb(
const bke::subdiv::ForeachContext * ,
622static void draw_subdiv_edge_cb(
const bke::subdiv::ForeachContext *foreach_context,
624 const int coarse_edge_index,
625 const int subdiv_edge_index,
630 DRWCacheBuildingContext *ctx = (DRWCacheBuildingContext *)(foreach_context->user_data);
632 if (!ctx->edge_origindex_map) {
639 if (!ctx->cache->optimal_display) {
640 ctx->edge_draw_flag_map[subdiv_edge_index] = 1;
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)) {
649 ctx->edge_draw_flag_map[subdiv_edge_index] = 1;
653 ctx->edge_origindex_map[subdiv_edge_index] = coarse_edge_index;
654 ctx->edge_draw_flag_map[subdiv_edge_index] = 1;
659static void draw_subdiv_loop_cb(
const bke::subdiv::ForeachContext *foreach_context,
661 const int ptex_face_index,
665 const int coarse_face_index,
667 const int subdiv_loop_index,
668 const int subdiv_vert_index,
669 const int subdiv_edge_index)
671 DRWCacheBuildingContext *ctx = (DRWCacheBuildingContext *)(foreach_context->user_data);
672 ctx->patch_coords[subdiv_loop_index] = make_patch_coord(ptex_face_index, u,
v);
674 int coarse_vert_index = ctx->vert_origindex_map[subdiv_vert_index];
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;
682static void draw_subdiv_foreach_callbacks(bke::subdiv::ForeachContext *foreach_context)
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;
692static void do_subdiv_traversal(DRWCacheBuildingContext *cache_building_context,
693 bke::subdiv::Subdiv *subdiv)
695 bke::subdiv::ForeachContext foreach_context;
696 draw_subdiv_foreach_callbacks(&foreach_context);
697 foreach_context.user_data = cache_building_context;
701 cache_building_context->settings,
702 cache_building_context->coarse_mesh);
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];
716static gpu::VertBuf *gpu_vertbuf_create_from_format(
const GPUVertFormat &format,
uint len)
730 cache.subdiv_vert_face_adjacency_offsets = gpu_vertbuf_create_from_format(
733 MutableSpan<int> vert_offsets = cache.subdiv_vert_face_adjacency_offsets->data<
int>();
734 vert_offsets.fill(0);
737 {cache.subdiv_loop_subdiv_vert_index, cache.num_subdiv_loops}, vert_offsets);
740 cache.num_subdiv_loops);
741 MutableSpan<int> adjacent_faces = cache.subdiv_vert_face_adjacency->data<
int>();
743 "tmp subdiv vertex offset");
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;
754 MEM_delete(tmp_set_faces);
758 bke::subdiv::Subdiv *subdiv,
759 const Mesh *mesh_eval,
760 const SubsurfRuntimeData *runtime_data)
762 bke::subdiv::ToMeshSettings to_mesh_settings;
763 to_mesh_settings.resolution = runtime_data->resolution;
764 to_mesh_settings.use_optimal_display =
false;
766 if (cache.resolution != to_mesh_settings.resolution) {
776 if (cache.patch_coords !=
nullptr) {
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;
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) {
791 cache.subdiv_face_offset = {};
796 const OffsetIndices faces = mesh_eval->faces();
797 if (cache.num_subdiv_loops != 0) {
799 draw_patch_map_build(&cache.gpu_patch_map, subdiv);
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) {
812 blender_fdots_patch_coords[i] = make_patch_coord(ptex_face_index, 0.5f, 0.5f);
818 blender_fdots_patch_coords[i] = make_patch_coord(ptex_face_index, 1.0f, 1.0f);
823 cache.subdiv_face_offset.data(), faces.size());
827 build_vert_face_adjacency_maps(cache);
830 cache.resolution = to_mesh_settings.resolution;
831 cache.num_coarse_faces = faces.size();
836 Vector<int> first_loop_index(cache.num_subdiv_verts, -1);
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);
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) {
850 first_loop_index[
vert] = i;
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]];
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);
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)
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)
935#define SUBDIV_LOCAL_WORK_GROUP_SIZE 64
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)
957 uint dispatch_rx = dispatch_size;
958 uint dispatch_ry = 1u;
959 if (dispatch_rx > max_res_x) {
967 dispatch_rx = dispatch_ry =
ceilf(
sqrtf(dispatch_size));
969 if ((dispatch_rx * (dispatch_ry - 1)) >= dispatch_size) {
980 cache, src_offset, dst_offset, total_dispatch_size, has_sculpt_mask, edge_loose_offset);
987#ifdef WITH_OPENSUBDIV
1044 const int face_varying_channel,
1045 const int dst_offset)
1047#ifdef WITH_OPENSUBDIV
1057 face_varying_channel);
1059 face_varying_channel);
1064 face_varying_channel);
1066 face_varying_channel);
1097 UNUSED_VARS(cache, uvs, face_varying_channel, dst_offset);
1220 const int material_count)
1227 const bool do_single_material = material_count <= 1;
1237 if (!do_single_material) {
1258#ifdef WITH_OPENSUBDIV
1308 UNUSED_VARS(cache, fdots_pos, fdots_nor, fdots_indices);
1334 uint edge_loose_offset,
1335 uint num_loose_edges)
1520 const Mesh *mesh_eval,
1531 cache.
mat_end[0] = number_of_quads;
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;
1553 int ofs = mat_start[0];
1555 for (
uint i = 1; i < mat_len; i++) {
1556 int tmp = mat_start[i];
1562 int *mat_end = MEM_dupalloc(mat_start);
1564 "per_face_mat_offset");
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;
1575 per_face_mat_offset[i] = material_offset - single_material_index;
1583 MEM_delete(per_face_mat_offset);
1602 const bool is_editmode,
1603 const bool is_paint_mode,
1604 const bool do_final,
1605 const bool do_uvedit,
1608 const bool use_hide)
1619 if (
mesh.runtime->edit_mesh) {
1624#ifdef WITH_OPENSUBDIV
1625 draw_subdiv_invalidate_evaluator_for_orco(runtime_data->
subdiv_gpu, mesh_eval);
1629 runtime_data, mesh_eval,
true);
1642 bool evaluator_might_be_assigned =
subdiv->evaluator ==
nullptr;
1644 if (evaluator_might_be_assigned &&
subdiv->evaluator !=
nullptr) {
1659 maybe_increment_cache_ref(
subdiv);
1670 draw_cache.
mesh = mesh_eval;
1673#ifdef WITH_OPENSUBDIV
1674 if (!draw_subdiv_build_cache(draw_cache,
subdiv, mesh_eval, runtime_data)) {
1675 maybe_increment_cache_ref(
subdiv);
1689 mesh_eval->attributes().contains(
"custom_normal");
1696 ob,
mesh, is_editmode, is_paint_mode, do_final, do_uvedit, use_hide, ts);
1707 batch_cache, mbc, ibo_requests, vbo_requests, draw_cache, mr);
1709 maybe_increment_cache_ref(
subdiv);
1725 const Mesh *coarse_mesh = subdiv_cache.
mesh;
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);
1731 const Span<float3> coarse_positions = coarse_mesh->vert_positions();
1732 const Span<int2> coarse_edges = coarse_mesh->edges();
1737 coarse_edges, coarse_mesh->
verts_num, vert_to_edge_offsets, vert_to_edge_indices);
1743 loose_edges.
foreach_index([&](
const int coarse_edge,
const int i) {
1751 j * inv_resolution_1);
1772 const bool is_editmode,
1773 const bool is_paint_mode,
1774 const bool do_final,
1775 const bool do_uvedit,
1778 const bool use_hide)
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));
1829 if (
subdiv->evaluator !=
nullptr) {
1833#ifdef WITH_OPENSUBDIV
General operations, lookup, etc. for blender objects.
Object is a sort of wrapper for general info.
#define GPU_vertbuf_init_with_format(verts, format)
#define GPU_VERTBUF_DISCARD_SAFE(verts)
#define BM_elem_index_get(ele)
#define BM_elem_flag_test(ele, hflag)
#define BM_ITER_MESH(ele, iter, bm, itype)
void reinitialize(const int64_t new_size)
constexpr MutableSpan slice(const int64_t start, const int64_t size) const
constexpr IndexRange index_range() const
constexpr int64_t size() const
constexpr bool contains(const T &value) const
GAttributeReader lookup_or_default(StringRef name, AttrDomain domain, AttrType data_type, const void *default_value=nullptr) const
constexpr bool is_empty() const
void foreach_index(Fn &&fn, Mode mode=exec_mode::serial) const
IndexRange index_range() 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 * get_patch_param_buf()
gpu::StorageBuf * create_face_varying_patch_array_buf(const int face_varying_channel)
gpu::StorageBuf * get_patch_index_buf()
int get_face_varying_source_offset(const int face_varying_channel) const
gpu::VertBuf * get_source_data_buf()
gpu::VertBuf * get_source_buf()
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)
#define storage(slot, qualifiers)
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
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)
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)
@ SUBDIV_EVALUATOR_TYPE_GPU
Span< int > face_ptex_offset_get(Subdiv *subdiv)
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)
static Mutex gpu_subdiv_queue_mutex
void DRW_cache_free_old_subdiv()
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 Mutex g_subdiv_eval_mutex
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
BMesh * BKE_editmesh_bmesh_get_for_write(Mesh *mesh)
void GPU_vertbuf_init_with_format_ex(gpu::VertBuf &verts, const GPUVertFormat &format, GPUUsageType)
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)
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)
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)
BMesh const char void * data
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
@ GPU_BARRIER_SHADER_STORAGE
@ GPU_BARRIER_ELEMENT_ARRAY
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)
@ PATCH_EVALUATION_FACE_DOTS
@ BUFFER_PAINT_OVERLAY_FLAG
@ BUFFER_UV_STRETCH_ANGLE
@ BUFFER_NORMALS_ACCUMULATE
@ PATCH_EVALUATION_FACE_DOTS_WITH_NORMALS
@ BUFFER_TRIS_MULTIPLE_MATERIALS
bke::subdiv::Subdiv * BKE_subsurf_modifier_subdiv_descriptor_ensure(SubsurfRuntimeData *runtime_data, const Mesh *mesh, bool for_draw_code)
void GPU_vertbuf_data_alloc(gpu::VertBuf &verts, uint v_len)
MINLINE uint divide_ceil_u(uint a, uint b)
double BLI_time_now_seconds()
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)
void vert(const int vert_id, float4 &position)
@ OPENSUBDIV_EVALUATOR_GPU
@ OPENSUBDIV_EVALUATOR_CPU
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
uint coarse_face_active_mask
uint coarse_face_loopstart_mask
bool32_t patches_are_triangular
uint coarse_face_select_mask
uint coarse_face_smooth_mask
uint coarse_face_hidden_mask
blender::opensubdiv::EvalOutputAPI * eval_output
bke::subdiv::Subdiv * subdiv_gpu
bke::subdiv::Settings settings
OpenSubdiv_Evaluator * evaluator
gpu::VertBuf * patch_map_quadtree
bool patches_are_triangular
gpu::VertBuf * patch_map_handles
gpu::VertBuf * face_mat_offset
DRWPatchMap gpu_patch_map
gpu::VertBuf * subdiv_vert_face_adjacency
int * subdiv_loop_subdiv_vert_index
gpu::VertBuf * verts_orig_index
gpu::VertBuf * edges_orig_index
bool use_custom_loop_normals
gpu::VertBuf * fdots_patch_coords
gpu::VertBuf * extra_coarse_face_data
gpu::VertBuf * face_ptex_offset_buffer
int * subdiv_loop_face_index
gpu::VertBuf * subdiv_face_offset_buffer
int * subdiv_loop_subdiv_edge_index
gpu::VertBuf * edges_draw_flag
gpu::VertBuf * subdiv_vert_face_adjacency_offsets
Array< float3 > loose_edge_positions
Array< int > subdiv_face_offset
uint num_subdiv_triangles
gpu::VertBuf * corner_patch_coords
bke::subdiv::Subdiv * subdiv
gpu::VertBuf * patch_coords
DRWSubdivCache * subdiv_cache
MeshExtractLooseGeom loose_geom
MeshExtractType extract_type
const int * orig_index_face
VArraySpan< bool > sharp_faces
VArraySpan< bool > select_poly
VArraySpan< bool > hide_poly
bke::MeshNormalDomain normals_domain