Blender V4.3
draw_cache_impl_subdivision.cc File Reference
#include "draw_subdivision.hh"
#include "DNA_mesh_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "BKE_attribute.hh"
#include "BKE_editmesh.hh"
#include "BKE_mesh.hh"
#include "BKE_mesh_mapping.hh"
#include "BKE_modifier.hh"
#include "BKE_object.hh"
#include "BKE_scene.hh"
#include "BKE_subdiv.hh"
#include "BKE_subdiv_eval.hh"
#include "BKE_subdiv_foreach.hh"
#include "BKE_subdiv_mesh.hh"
#include "BKE_subdiv_modifier.hh"
#include "BLI_linklist.h"
#include "BLI_string.h"
#include "BLI_string_utils.hh"
#include "BLI_time.h"
#include "BLI_virtual_array.hh"
#include "DRW_engine.hh"
#include "DRW_render.hh"
#include "GPU_capabilities.hh"
#include "GPU_compute.hh"
#include "GPU_index_buffer.hh"
#include "GPU_state.hh"
#include "GPU_vertex_buffer.hh"
#include "opensubdiv_capi.hh"
#include "opensubdiv_capi_type.hh"
#include "opensubdiv_converter_capi.hh"
#include "opensubdiv_evaluator_capi.hh"
#include "draw_cache_extract.hh"
#include "draw_cache_impl.hh"
#include "draw_cache_inline.hh"
#include "mesh_extractors/extract_mesh.hh"

Go to the source code of this file.

Classes

struct  blender::draw::CompressedPatchCoord
 
struct  blender::draw::DRWCacheBuildingContext
 
struct  blender::draw::DRWSubdivUboStorage
 

Namespaces

namespace  blender
 
namespace  blender::draw
 

Macros

#define SHADER_CUSTOM_DATA_INTERP_MAX_DIMENSIONS   4
 
#define SUBDIV_LOCAL_WORK_GROUP_SIZE   64
 

Enumerations

enum  {
  blender::draw::SHADER_BUFFER_LINES , blender::draw::SHADER_BUFFER_LINES_LOOSE , blender::draw::SHADER_BUFFER_EDGE_FAC , blender::draw::SHADER_BUFFER_LNOR ,
  blender::draw::SHADER_BUFFER_TRIS , blender::draw::SHADER_BUFFER_TRIS_MULTIPLE_MATERIALS , blender::draw::SHADER_BUFFER_NORMALS_ACCUMULATE , blender::draw::SHADER_BUFFER_NORMALS_FINALIZE ,
  blender::draw::SHADER_BUFFER_CUSTOM_NORMALS_FINALIZE , blender::draw::SHADER_PATCH_EVALUATION , blender::draw::SHADER_PATCH_EVALUATION_FVAR , blender::draw::SHADER_PATCH_EVALUATION_FACE_DOTS ,
  blender::draw::SHADER_PATCH_EVALUATION_FACE_DOTS_WITH_NORMALS , blender::draw::SHADER_PATCH_EVALUATION_ORCO , blender::draw::SHADER_COMP_CUSTOM_DATA_INTERP_1D , blender::draw::SHADER_COMP_CUSTOM_DATA_INTERP_2D ,
  blender::draw::SHADER_COMP_CUSTOM_DATA_INTERP_3D , blender::draw::SHADER_COMP_CUSTOM_DATA_INTERP_4D , blender::draw::SHADER_BUFFER_SCULPT_DATA , blender::draw::SHADER_BUFFER_UV_STRETCH_ANGLE ,
  blender::draw::SHADER_BUFFER_UV_STRETCH_AREA , blender::draw::NUM_SHADERS
}
 

Functions

static const char * blender::draw::get_shader_code (int shader_type)
 
static const char * blender::draw::get_shader_name (int shader_type)
 
static GPUShaderblender::draw::get_patch_evaluation_shader (int shader_type)
 
static GPUShaderblender::draw::get_subdiv_shader (int shader_type)
 
static GPUShaderblender::draw::get_subdiv_custom_data_shader (int comp_type, int dimensions)
 
static uint blender::draw::tris_count_from_number_of_loops (const uint number_of_loops)
 
static uint blender::draw::get_dispatch_size (uint elements)
 
static void blender::draw::drw_subdiv_compute_dispatch (const DRWSubdivCache &cache, GPUShader *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)
 
void blender::draw::draw_subdiv_extract_pos_nor (const DRWSubdivCache &cache, gpu::VertBuf *flags_buffer, gpu::VertBuf *pos_nor, gpu::VertBuf *orco)
 
void blender::draw::draw_subdiv_extract_uvs (const DRWSubdivCache &cache, gpu::VertBuf *uvs, const int face_varying_channel, const int dst_offset)
 
void blender::draw::draw_subdiv_interp_custom_data (const DRWSubdivCache &cache, gpu::VertBuf &src_data, gpu::VertBuf &dst_data, int comp_type, int dimensions, int dst_offset)
 
void blender::draw::draw_subdiv_build_sculpt_data_buffer (const DRWSubdivCache &cache, gpu::VertBuf *mask_vbo, gpu::VertBuf *face_set_vbo, gpu::VertBuf *sculpt_data)
 
void blender::draw::draw_subdiv_accumulate_normals (const DRWSubdivCache &cache, gpu::VertBuf *pos_nor, gpu::VertBuf *face_adjacency_offsets, gpu::VertBuf *face_adjacency_lists, gpu::VertBuf *vertex_loop_map, gpu::VertBuf *vert_normals)
 
void blender::draw::draw_subdiv_finalize_normals (const DRWSubdivCache &cache, gpu::VertBuf *vert_normals, gpu::VertBuf *subdiv_loop_subdiv_vert_index, gpu::VertBuf *pos_nor)
 
void blender::draw::draw_subdiv_finalize_custom_normals (const DRWSubdivCache &cache, gpu::VertBuf *src_custom_normals, gpu::VertBuf *pos_nor)
 
void blender::draw::draw_subdiv_build_tris_buffer (const DRWSubdivCache &cache, gpu::IndexBuf *subdiv_tris, const int material_count)
 
void blender::draw::draw_subdiv_build_fdots_buffers (const DRWSubdivCache &cache, gpu::VertBuf *fdots_pos, gpu::VertBuf *fdots_nor, gpu::IndexBuf *fdots_indices)
 
void blender::draw::draw_subdiv_build_lines_buffer (const DRWSubdivCache &cache, gpu::IndexBuf *lines_indices)
 
void blender::draw::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 blender::draw::draw_subdiv_build_edge_fac_buffer (const DRWSubdivCache &cache, gpu::VertBuf *pos_nor, gpu::VertBuf *edge_draw_flag, gpu::VertBuf *poly_other_map, gpu::VertBuf *edge_fac)
 
void blender::draw::draw_subdiv_build_lnor_buffer (const DRWSubdivCache &cache, gpu::VertBuf *pos_nor, gpu::VertBuf *lnor)
 
void blender::draw::draw_subdiv_build_edituv_stretch_area_buffer (const DRWSubdivCache &cache, gpu::VertBuf *coarse_data, gpu::VertBuf *subdiv_data)
 
void blender::draw::draw_subdiv_build_edituv_stretch_angle_buffer (const DRWSubdivCache &cache, gpu::VertBuf *pos_nor, gpu::VertBuf *uvs, int uvs_offset, gpu::VertBuf *stretch_angles)
 
static void blender::draw::draw_subdiv_cache_ensure_mat_offsets (DRWSubdivCache &cache, const Mesh *mesh_eval, uint mat_len)
 
static bool blender::draw::draw_subdiv_create_requested_buffers (Object &ob, Mesh &mesh, MeshBatchCache &batch_cache, MeshBufferCache &mbc, const bool is_editmode, const bool is_paint_mode, const bool edit_mode_active, const float4x4 &object_to_world, const bool do_final, const bool do_uvedit, const bool do_cage, const ToolSettings *ts, const bool use_hide, OpenSubdiv_EvaluatorCache *evaluator_cache)
 
void blender::draw::DRW_subdivide_loose_geom (DRWSubdivCache &subdiv_cache, const MeshBufferCache &cache)
 
void blender::draw::DRW_create_subdivision (Object &ob, Mesh &mesh, MeshBatchCache &batch_cache, MeshBufferCache &mbc, const bool is_editmode, const bool is_paint_mode, const bool edit_mode_active, const float4x4 &object_to_world, const bool do_final, const bool do_uvedit, const bool do_cage, const ToolSettings *ts, const bool use_hide)
 
void blender::draw::DRW_subdiv_free ()
 
void blender::draw::DRW_subdiv_cache_free (bke::subdiv::Subdiv *subdiv)
 
void blender::draw::DRW_cache_free_old_subdiv ()
 
Vertex Formats

Used for data transfer from OpenSubdiv, and for data processing on our side.

static const GPUVertFormatblender::draw::get_uvs_format ()
 
static const GPUVertFormatblender::draw::get_patch_array_format ()
 
static const GPUVertFormatblender::draw::get_patch_handle_format ()
 
static const GPUVertFormatblender::draw::get_quadtree_format ()
 
static const GPUVertFormatblender::draw::get_patch_param_format ()
 
static const GPUVertFormatblender::draw::get_patch_index_format ()
 
static const GPUVertFormatblender::draw::get_subdiv_vertex_format ()
 
MINLINE CompressedPatchCoord blender::draw::make_patch_coord (int ptex_face_index, float u, float v)
 
static const GPUVertFormatblender::draw::get_blender_patch_coords_format ()
 
static const GPUVertFormatblender::draw::get_origindex_format ()
 
const GPUVertFormatblender::draw::draw_subdiv_get_pos_nor_format ()
 
Utilities to initialize a OpenSubdiv_Buffer for a gpu::VertBuf.
static void blender::draw::vertbuf_bind_gpu (const OpenSubdiv_Buffer *buffer)
 
static void * blender::draw::vertbuf_alloc (const OpenSubdiv_Buffer *interface, const uint len)
 
static void blender::draw::vertbuf_device_alloc (const OpenSubdiv_Buffer *interface, const uint len)
 
static void blender::draw::vertbuf_wrap_device_handle (const OpenSubdiv_Buffer *interface, uint64_t handle)
 
static void blender::draw::vertbuf_update_data (const OpenSubdiv_Buffer *interface, uint start, uint len, const void *data)
 
static void blender::draw::opensubdiv_gpu_buffer_init (OpenSubdiv_Buffer *buffer_interface, gpu::VertBuf *vertbuf)
 
static gpu::VertBufblender::draw::create_buffer_and_interface (OpenSubdiv_Buffer *interface, const GPUVertFormat &format)
 
Utilities to build a gpu::VertBuf from an origindex buffer.
void blender::draw::draw_subdiv_init_origindex_buffer (gpu::VertBuf &buffer, int32_t *vert_origindex, uint num_loops, uint loose_len)
 
gpu::VertBufblender::draw::draw_subdiv_build_origindex_buffer (int *vert_origindex, uint num_loops)
 
Utilities for DRWPatchMap.
static void blender::draw::draw_patch_map_build (DRWPatchMap *gpu_patch_map, bke::subdiv::Subdiv *subdiv)
 
static void blender::draw::draw_patch_map_free (DRWPatchMap *gpu_patch_map)
 
Subdivision grid traversal.

Traverse the uniform subdivision grid over coarse faces and gather useful information for building the draw buffers on the GPU. We primarily gather the patch coordinates for all subdivision faces, as well as the original coarse indices for each subdivision element (vertex, face, or edge) which directly maps to its coarse counterpart (note that all subdivision faces map to a coarse face). This information will then be cached in #DRWSubdivCache for subsequent reevaluations, as long as the topology does not change.

static bool blender::draw::draw_subdiv_topology_info_cb (const bke::subdiv::ForeachContext *foreach_context, const int num_verts, const int num_edges, const int num_loops, const int num_faces, const int *subdiv_face_offset)
 
static void blender::draw::draw_subdiv_vertex_corner_cb (const bke::subdiv::ForeachContext *foreach_context, void *, const int, const float, const float, const int coarse_vertex_index, const int, const int, const int subdiv_vertex_index)
 
static void blender::draw::draw_subdiv_vertex_edge_cb (const bke::subdiv::ForeachContext *, void *, const int, const float, const float, const int, const int, const int, const int)
 
static void blender::draw::draw_subdiv_edge_cb (const bke::subdiv::ForeachContext *foreach_context, void *, const int coarse_edge_index, const int subdiv_edge_index, const bool, const int, const int)
 
static void blender::draw::draw_subdiv_loop_cb (const bke::subdiv::ForeachContext *foreach_context, void *, const int ptex_face_index, const float u, const float v, const int, const int coarse_face_index, const int, const int subdiv_loop_index, const int subdiv_vertex_index, const int subdiv_edge_index)
 
static void blender::draw::draw_subdiv_foreach_callbacks (bke::subdiv::ForeachContext *foreach_context)
 
static void blender::draw::do_subdiv_traversal (DRWCacheBuildingContext *cache_building_context, bke::subdiv::Subdiv *subdiv)
 
static gpu::VertBufblender::draw::gpu_vertbuf_create_from_format (const GPUVertFormat &format, uint len)
 
static void blender::draw::build_vertex_face_adjacency_maps (DRWSubdivCache &cache)
 
static bool blender::draw::draw_subdiv_build_cache (DRWSubdivCache &cache, bke::subdiv::Subdiv *subdiv, const Mesh *mesh_eval, const SubsurfRuntimeData *runtime_data)
 
DRWSubdivUboStorage.

Common uniforms for the various shaders.

static void blender::draw::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 blender::draw::draw_subdiv_ubo_update_and_bind (const DRWSubdivCache &cache, GPUShader *shader, 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)
 

Variables

char datatoc_common_subdiv_custom_data_interp_comp_glsl []
 
char datatoc_common_subdiv_ibo_lines_comp_glsl []
 
char datatoc_common_subdiv_ibo_tris_comp_glsl []
 
char datatoc_common_subdiv_lib_glsl []
 
char datatoc_common_subdiv_normals_accumulate_comp_glsl []
 
char datatoc_common_subdiv_normals_finalize_comp_glsl []
 
char datatoc_common_subdiv_patch_evaluation_comp_glsl []
 
char datatoc_common_subdiv_vbo_edge_fac_comp_glsl []
 
char datatoc_common_subdiv_vbo_lnor_comp_glsl []
 
char datatoc_common_subdiv_vbo_sculpt_data_comp_glsl []
 
char datatoc_common_subdiv_vbo_edituv_strech_angle_comp_glsl []
 
char datatoc_common_subdiv_vbo_edituv_strech_area_comp_glsl []
 
static GPUShaderblender::draw::g_subdiv_shaders [NUM_SHADERS]
 
static GPUShaderblender::draw::g_subdiv_custom_data_shaders [SHADER_CUSTOM_DATA_INTERP_MAX_DIMENSIONS][GPU_COMP_MAX]
 
static OpenSubdiv_EvaluatorCacheblender::draw::g_evaluator_cache = nullptr
 
static LinkNodeblender::draw::gpu_subdiv_free_queue = nullptr
 
static ThreadMutex blender::draw::gpu_subdiv_queue_mutex = BLI_MUTEX_INITIALIZER
 

DRWSubdivCache

This holds the various buffers used to evaluate and render subdivision through OpenGL.

#define SUBDIV_COARSE_FACE_FLAG_SMOOTH   1u
 
#define SUBDIV_COARSE_FACE_FLAG_SELECT   2u
 
#define SUBDIV_COARSE_FACE_FLAG_ACTIVE   4u
 
#define SUBDIV_COARSE_FACE_FLAG_HIDDEN   8u
 
#define SUBDIV_COARSE_FACE_FLAG_OFFSET   28u
 
#define SUBDIV_COARSE_FACE_FLAG_SMOOTH_MASK    (SUBDIV_COARSE_FACE_FLAG_SMOOTH << SUBDIV_COARSE_FACE_FLAG_OFFSET)
 
#define SUBDIV_COARSE_FACE_FLAG_SELECT_MASK    (SUBDIV_COARSE_FACE_FLAG_SELECT << SUBDIV_COARSE_FACE_FLAG_OFFSET)
 
#define SUBDIV_COARSE_FACE_FLAG_ACTIVE_MASK    (SUBDIV_COARSE_FACE_FLAG_ACTIVE << SUBDIV_COARSE_FACE_FLAG_OFFSET)
 
#define SUBDIV_COARSE_FACE_FLAG_HIDDEN_MASK    (SUBDIV_COARSE_FACE_FLAG_HIDDEN << SUBDIV_COARSE_FACE_FLAG_OFFSET)
 
#define SUBDIV_COARSE_FACE_LOOP_START_MASK
 
static bool blender::draw::draw_subdiv_cache_need_face_data (const DRWSubdivCache &cache)
 
static void blender::draw::draw_subdiv_cache_free_material_data (DRWSubdivCache &cache)
 
static void blender::draw::draw_subdiv_free_edit_mode_cache (DRWSubdivCache &cache)
 
void blender::draw::draw_subdiv_cache_free (DRWSubdivCache &cache)
 
static uint32_t blender::draw::compute_coarse_face_flag_bm (BMFace *f, BMFace *efa_act)
 
static void blender::draw::draw_subdiv_cache_extra_coarse_face_data_bm (BMesh *bm, BMFace *efa_act, MutableSpan< uint32_t > flags_data)
 
static void blender::draw::draw_subdiv_cache_extra_coarse_face_data_mesh (const MeshRenderData &mr, const Mesh *mesh, MutableSpan< uint32_t > flags_data)
 
static void blender::draw::draw_subdiv_cache_extra_coarse_face_data_mapped (const Mesh *mesh, BMesh *bm, MeshRenderData &mr, MutableSpan< uint32_t > flags_data)
 
static void blender::draw::draw_subdiv_cache_update_extra_coarse_face_data (DRWSubdivCache &cache, const Mesh *mesh, MeshRenderData &mr)
 
static DRWSubdivCacheblender::draw::mesh_batch_cache_ensure_subdiv_cache (MeshBatchCache &mbc)
 
static void blender::draw::draw_subdiv_invalidate_evaluator_for_orco (bke::subdiv::Subdiv *subdiv, const Mesh *mesh)
 

Macro Definition Documentation

◆ SHADER_CUSTOM_DATA_INTERP_MAX_DIMENSIONS

#define SHADER_CUSTOM_DATA_INTERP_MAX_DIMENSIONS   4

◆ SUBDIV_COARSE_FACE_FLAG_ACTIVE

#define SUBDIV_COARSE_FACE_FLAG_ACTIVE   4u

◆ SUBDIV_COARSE_FACE_FLAG_ACTIVE_MASK

#define SUBDIV_COARSE_FACE_FLAG_ACTIVE_MASK    (SUBDIV_COARSE_FACE_FLAG_ACTIVE << SUBDIV_COARSE_FACE_FLAG_OFFSET)

◆ SUBDIV_COARSE_FACE_FLAG_HIDDEN

◆ SUBDIV_COARSE_FACE_FLAG_HIDDEN_MASK

#define SUBDIV_COARSE_FACE_FLAG_HIDDEN_MASK    (SUBDIV_COARSE_FACE_FLAG_HIDDEN << SUBDIV_COARSE_FACE_FLAG_OFFSET)

◆ SUBDIV_COARSE_FACE_FLAG_OFFSET

◆ SUBDIV_COARSE_FACE_FLAG_SELECT

◆ SUBDIV_COARSE_FACE_FLAG_SELECT_MASK

#define SUBDIV_COARSE_FACE_FLAG_SELECT_MASK    (SUBDIV_COARSE_FACE_FLAG_SELECT << SUBDIV_COARSE_FACE_FLAG_OFFSET)

◆ SUBDIV_COARSE_FACE_FLAG_SMOOTH

◆ SUBDIV_COARSE_FACE_FLAG_SMOOTH_MASK

#define SUBDIV_COARSE_FACE_FLAG_SMOOTH_MASK    (SUBDIV_COARSE_FACE_FLAG_SMOOTH << SUBDIV_COARSE_FACE_FLAG_OFFSET)

◆ SUBDIV_COARSE_FACE_LOOP_START_MASK

◆ SUBDIV_LOCAL_WORK_GROUP_SIZE

#define SUBDIV_LOCAL_WORK_GROUP_SIZE   64

Definition at line 1389 of file draw_cache_impl_subdivision.cc.

Referenced by blender::draw::get_dispatch_size().

Variable Documentation

◆ datatoc_common_subdiv_custom_data_interp_comp_glsl

char datatoc_common_subdiv_custom_data_interp_comp_glsl[]

Definition at line 52 of file draw_cache_impl_subdivision.cc.

Referenced by blender::draw::get_shader_code().

◆ datatoc_common_subdiv_ibo_lines_comp_glsl

char datatoc_common_subdiv_ibo_lines_comp_glsl[]

Definition at line 53 of file draw_cache_impl_subdivision.cc.

Referenced by blender::draw::get_shader_code().

◆ datatoc_common_subdiv_ibo_tris_comp_glsl

char datatoc_common_subdiv_ibo_tris_comp_glsl[]

Definition at line 54 of file draw_cache_impl_subdivision.cc.

Referenced by blender::draw::get_shader_code().

◆ datatoc_common_subdiv_lib_glsl

◆ datatoc_common_subdiv_normals_accumulate_comp_glsl

char datatoc_common_subdiv_normals_accumulate_comp_glsl[]

Definition at line 56 of file draw_cache_impl_subdivision.cc.

Referenced by blender::draw::get_shader_code().

◆ datatoc_common_subdiv_normals_finalize_comp_glsl

char datatoc_common_subdiv_normals_finalize_comp_glsl[]

Definition at line 57 of file draw_cache_impl_subdivision.cc.

Referenced by blender::draw::get_shader_code().

◆ datatoc_common_subdiv_patch_evaluation_comp_glsl

char datatoc_common_subdiv_patch_evaluation_comp_glsl[]

Definition at line 58 of file draw_cache_impl_subdivision.cc.

Referenced by blender::draw::get_shader_code().

◆ datatoc_common_subdiv_vbo_edge_fac_comp_glsl

char datatoc_common_subdiv_vbo_edge_fac_comp_glsl[]

Definition at line 59 of file draw_cache_impl_subdivision.cc.

Referenced by blender::draw::get_shader_code().

◆ datatoc_common_subdiv_vbo_edituv_strech_angle_comp_glsl

char datatoc_common_subdiv_vbo_edituv_strech_angle_comp_glsl[]

Definition at line 62 of file draw_cache_impl_subdivision.cc.

Referenced by blender::draw::get_shader_code().

◆ datatoc_common_subdiv_vbo_edituv_strech_area_comp_glsl

char datatoc_common_subdiv_vbo_edituv_strech_area_comp_glsl[]

Definition at line 63 of file draw_cache_impl_subdivision.cc.

Referenced by blender::draw::get_shader_code().

◆ datatoc_common_subdiv_vbo_lnor_comp_glsl

char datatoc_common_subdiv_vbo_lnor_comp_glsl[]

Definition at line 60 of file draw_cache_impl_subdivision.cc.

Referenced by blender::draw::get_shader_code().

◆ datatoc_common_subdiv_vbo_sculpt_data_comp_glsl

char datatoc_common_subdiv_vbo_sculpt_data_comp_glsl[]

Definition at line 61 of file draw_cache_impl_subdivision.cc.

Referenced by blender::draw::get_shader_code().