Blender  V3.3
Classes | Macros | Enumerations | Functions | Variables
draw_cache_impl_subdivision.cc File Reference
#include "draw_subdivision.h"
#include "DNA_mesh_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "BKE_editmesh.h"
#include "BKE_mesh.h"
#include "BKE_modifier.h"
#include "BKE_object.h"
#include "BKE_scene.h"
#include "BKE_subdiv.h"
#include "BKE_subdiv_eval.h"
#include "BKE_subdiv_foreach.h"
#include "BKE_subdiv_mesh.h"
#include "BKE_subdiv_modifier.h"
#include "BLI_linklist.h"
#include "BLI_string.h"
#include "PIL_time.h"
#include "DRW_engine.h"
#include "DRW_render.h"
#include "GPU_capabilities.h"
#include "GPU_compute.h"
#include "GPU_index_buffer.h"
#include "GPU_state.h"
#include "GPU_vertex_buffer.h"
#include "opensubdiv_capi.h"
#include "opensubdiv_capi_type.h"
#include "opensubdiv_converter_capi.h"
#include "opensubdiv_evaluator_capi.h"
#include "opensubdiv_topology_refiner_capi.h"
#include "draw_cache_extract.hh"
#include "draw_cache_impl.h"
#include "draw_cache_inline.h"
#include "mesh_extractors/extract_mesh.hh"

Go to the source code of this file.

Classes

struct  CompressedPatchCoord
 
struct  DRWCacheBuildingContext
 
struct  DRWSubdivUboStorage
 

Macros

#define SUBDIV_LOCAL_WORK_GROUP_SIZE   64
 

Enumerations

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

Functions

static const char * get_shader_code (int shader_type)
 
static const char * get_shader_name (int shader_type)
 
static GPUShaderget_patch_evaluation_shader (int shader_type)
 
static GPUShaderget_subdiv_shader (int shader_type, const char *defines)
 
static uint tris_count_from_number_of_loops (const uint number_of_loops)
 
static uint get_dispatch_size (uint elements)
 
static void 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)
 
void draw_subdiv_extract_pos_nor (const DRWSubdivCache *cache, GPUVertBuf *pos_nor, GPUVertBuf *orco)
 
void draw_subdiv_extract_uvs (const DRWSubdivCache *cache, GPUVertBuf *uvs, const int face_varying_channel, const int dst_offset)
 
void draw_subdiv_interp_custom_data (const DRWSubdivCache *cache, GPUVertBuf *src_data, GPUVertBuf *dst_data, int dimensions, int dst_offset, bool compress_to_u16)
 
void draw_subdiv_build_sculpt_data_buffer (const DRWSubdivCache *cache, GPUVertBuf *mask_vbo, GPUVertBuf *face_set_vbo, GPUVertBuf *sculpt_data)
 
void draw_subdiv_accumulate_normals (const DRWSubdivCache *cache, GPUVertBuf *pos_nor, GPUVertBuf *face_adjacency_offsets, GPUVertBuf *face_adjacency_lists, GPUVertBuf *vertex_loop_map, GPUVertBuf *vertex_normals)
 
void draw_subdiv_finalize_normals (const DRWSubdivCache *cache, GPUVertBuf *vertex_normals, GPUVertBuf *subdiv_loop_subdiv_vert_index, GPUVertBuf *pos_nor)
 
void draw_subdiv_finalize_custom_normals (const DRWSubdivCache *cache, GPUVertBuf *src_custom_normals, GPUVertBuf *pos_nor)
 
void draw_subdiv_build_tris_buffer (const DRWSubdivCache *cache, GPUIndexBuf *subdiv_tris, const int material_count)
 
void draw_subdiv_build_fdots_buffers (const DRWSubdivCache *cache, GPUVertBuf *fdots_pos, GPUVertBuf *fdots_nor, GPUIndexBuf *fdots_indices)
 
void draw_subdiv_build_lines_buffer (const DRWSubdivCache *cache, GPUIndexBuf *lines_indices)
 
void draw_subdiv_build_lines_loose_buffer (const DRWSubdivCache *cache, GPUIndexBuf *lines_indices, GPUVertBuf *lines_flags, uint num_loose_edges)
 
void draw_subdiv_build_edge_fac_buffer (const DRWSubdivCache *cache, GPUVertBuf *pos_nor, GPUVertBuf *edge_idx, GPUVertBuf *edge_fac)
 
void draw_subdiv_build_lnor_buffer (const DRWSubdivCache *cache, GPUVertBuf *pos_nor, GPUVertBuf *lnor)
 
void draw_subdiv_build_edituv_stretch_area_buffer (const DRWSubdivCache *cache, GPUVertBuf *coarse_data, GPUVertBuf *subdiv_data)
 
void draw_subdiv_build_edituv_stretch_angle_buffer (const DRWSubdivCache *cache, GPUVertBuf *pos_nor, GPUVertBuf *uvs, int uvs_offset, GPUVertBuf *stretch_angles)
 
static void draw_subdiv_cache_ensure_mat_offsets (DRWSubdivCache *cache, Mesh *mesh_eval, uint mat_len)
 
static bool 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 is_mode_active, const float obmat[4][4], const bool do_final, const bool do_uvedit, const bool do_cage, const ToolSettings *ts, const bool use_hide, OpenSubdiv_EvaluatorCache *evaluator_cache)
 
void DRW_subdivide_loose_geom (DRWSubdivCache *subdiv_cache, MeshBufferCache *cache)
 
blender::Span< DRWSubdivLooseEdgedraw_subdiv_cache_get_loose_edges (const DRWSubdivCache *cache)
 
blender::Span< DRWSubdivLooseVertexdraw_subdiv_cache_get_loose_verts (const DRWSubdivCache *cache)
 
void DRW_create_subdivision (Object *ob, Mesh *mesh, MeshBatchCache *batch_cache, MeshBufferCache *mbc, const bool is_editmode, const bool is_paint_mode, const bool is_mode_active, const float obmat[4][4], const bool do_final, const bool do_uvedit, const bool do_cage, const ToolSettings *ts, const bool use_hide)
 
void DRW_subdiv_free ()
 
void DRW_subdiv_cache_free (Subdiv *subdiv)
 
void DRW_cache_free_old_subdiv ()
 
static GPUVertFormatget_uvs_format ()
 
static GPUVertFormatget_patch_array_format ()
 
static GPUVertFormatget_patch_handle_format ()
 
static GPUVertFormatget_quadtree_format ()
 
static GPUVertFormatget_patch_param_format ()
 
static GPUVertFormatget_patch_index_format ()
 
static GPUVertFormatget_subdiv_vertex_format ()
 
MINLINE CompressedPatchCoord make_patch_coord (int ptex_face_index, float u, float v)
 
static GPUVertFormatget_blender_patch_coords_format ()
 
static GPUVertFormatget_origindex_format ()
 
GPUVertFormatdraw_subdiv_get_pos_nor_format ()
 
Utilities to initialize a OpenSubdiv_Buffer for a GPUVertBuf.
static void vertbuf_bind_gpu (const OpenSubdiv_Buffer *buffer)
 
static voidvertbuf_alloc (const OpenSubdiv_Buffer *interface, const uint len)
 
static void vertbuf_device_alloc (const OpenSubdiv_Buffer *interface, const uint len)
 
static void vertbuf_wrap_device_handle (const OpenSubdiv_Buffer *interface, uint64_t handle)
 
static void vertbuf_update_data (const OpenSubdiv_Buffer *interface, uint start, uint len, const void *data)
 
static void opensubdiv_gpu_buffer_init (OpenSubdiv_Buffer *buffer_interface, GPUVertBuf *vertbuf)
 
static GPUVertBufcreate_buffer_and_interface (OpenSubdiv_Buffer *interface, GPUVertFormat *format)
 
Utilities to build a GPUVertBuf from an origindex buffer.
void draw_subdiv_init_origindex_buffer (GPUVertBuf *buffer, int32_t *vert_origindex, uint num_loops, uint loose_len)
 
GPUVertBufdraw_subdiv_build_origindex_buffer (int *vert_origindex, uint num_loops)
 
Utilities for DRWPatchMap.
static void draw_patch_map_build (DRWPatchMap *gpu_patch_map, Subdiv *subdiv)
 
static void 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 draw_subdiv_topology_info_cb (const SubdivForeachContext *foreach_context, const int num_vertices, const int num_edges, const int num_loops, const int num_polygons, const int *subdiv_polygon_offset)
 
static void draw_subdiv_vertex_corner_cb (const SubdivForeachContext *foreach_context, void *UNUSED(tls), const int UNUSED(ptex_face_index), const float UNUSED(u), const float UNUSED(v), const int coarse_vertex_index, const int UNUSED(coarse_poly_index), const int UNUSED(coarse_corner), const int subdiv_vertex_index)
 
static void draw_subdiv_vertex_edge_cb (const SubdivForeachContext *UNUSED(foreach_context), void *UNUSED(tls_v), const int UNUSED(ptex_face_index), const float UNUSED(u), const float UNUSED(v), const int UNUSED(coarse_edge_index), const int UNUSED(coarse_poly_index), const int UNUSED(coarse_corner), const int UNUSED(subdiv_vertex_index))
 
static void draw_subdiv_edge_cb (const SubdivForeachContext *foreach_context, void *UNUSED(tls), const int coarse_edge_index, const int subdiv_edge_index, const bool UNUSED(is_loose), const int UNUSED(subdiv_v1), const int UNUSED(subdiv_v2))
 
static void draw_subdiv_loop_cb (const SubdivForeachContext *foreach_context, void *UNUSED(tls_v), const int ptex_face_index, const float u, const float v, const int UNUSED(coarse_loop_index), const int coarse_poly_index, const int UNUSED(coarse_corner), const int subdiv_loop_index, const int subdiv_vertex_index, const int subdiv_edge_index)
 
static void draw_subdiv_foreach_callbacks (SubdivForeachContext *foreach_context)
 
static void do_subdiv_traversal (DRWCacheBuildingContext *cache_building_context, Subdiv *subdiv)
 
static GPUVertBufgpu_vertbuf_create_from_format (GPUVertFormat *format, uint len)
 
static void build_vertex_face_adjacency_maps (DRWSubdivCache *cache)
 
static bool draw_subdiv_build_cache (DRWSubdivCache *cache, Subdiv *subdiv, Mesh *mesh_eval, const SubsurfRuntimeData *runtime_data)
 
DRWSubdivUboStorage.

Common uniforms for the various shaders.

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)
 
static void 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)
 

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 GPUShaderg_subdiv_shaders [NUM_SHADERS]
 
static OpenSubdiv_EvaluatorCacheg_evaluator_cache = nullptr
 
static LinkNodegpu_subdiv_free_queue = nullptr
 
static ThreadMutex gpu_subdiv_queue_mutex = BLI_MUTEX_INITIALIZER
 

DRWSubdivCache

#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 draw_subdiv_cache_need_polygon_data (const DRWSubdivCache *cache)
 
static void draw_subdiv_cache_free_material_data (DRWSubdivCache *cache)
 
static void draw_subdiv_free_edit_mode_cache (DRWSubdivCache *cache)
 
void draw_subdiv_cache_free (DRWSubdivCache *cache)
 
static uint32_t compute_coarse_face_flag (BMFace *f, BMFace *efa_act)
 
static void draw_subdiv_cache_extra_coarse_face_data_bm (BMesh *bm, BMFace *efa_act, uint32_t *flags_data)
 
static void draw_subdiv_cache_extra_coarse_face_data_mesh (Mesh *mesh, uint32_t *flags_data)
 
static void draw_subdiv_cache_extra_coarse_face_data_mapped (Mesh *mesh, BMesh *bm, MeshRenderData *mr, uint32_t *flags_data)
 
static void draw_subdiv_cache_update_extra_coarse_face_data (DRWSubdivCache *cache, Mesh *mesh, MeshRenderData *mr)
 
static DRWSubdivCachemesh_batch_cache_ensure_subdiv_cache (MeshBatchCache *mbc)
 
static void draw_subdiv_invalidate_evaluator_for_orco (Subdiv *subdiv, Mesh *mesh)
 

Macro Definition Documentation

◆ SUBDIV_COARSE_FACE_FLAG_ACTIVE

#define SUBDIV_COARSE_FACE_FLAG_ACTIVE   4u

Definition at line 615 of file draw_cache_impl_subdivision.cc.

◆ SUBDIV_COARSE_FACE_FLAG_ACTIVE_MASK

#define SUBDIV_COARSE_FACE_FLAG_ACTIVE_MASK    (SUBDIV_COARSE_FACE_FLAG_ACTIVE << SUBDIV_COARSE_FACE_FLAG_OFFSET)

Definition at line 624 of file draw_cache_impl_subdivision.cc.

◆ SUBDIV_COARSE_FACE_FLAG_HIDDEN

#define SUBDIV_COARSE_FACE_FLAG_HIDDEN   8u

Definition at line 616 of file draw_cache_impl_subdivision.cc.

◆ SUBDIV_COARSE_FACE_FLAG_HIDDEN_MASK

#define SUBDIV_COARSE_FACE_FLAG_HIDDEN_MASK    (SUBDIV_COARSE_FACE_FLAG_HIDDEN << SUBDIV_COARSE_FACE_FLAG_OFFSET)

Definition at line 626 of file draw_cache_impl_subdivision.cc.

◆ SUBDIV_COARSE_FACE_FLAG_OFFSET

#define SUBDIV_COARSE_FACE_FLAG_OFFSET   28u

Definition at line 618 of file draw_cache_impl_subdivision.cc.

◆ SUBDIV_COARSE_FACE_FLAG_SELECT

#define SUBDIV_COARSE_FACE_FLAG_SELECT   2u

Definition at line 614 of file draw_cache_impl_subdivision.cc.

◆ SUBDIV_COARSE_FACE_FLAG_SELECT_MASK

#define SUBDIV_COARSE_FACE_FLAG_SELECT_MASK    (SUBDIV_COARSE_FACE_FLAG_SELECT << SUBDIV_COARSE_FACE_FLAG_OFFSET)

Definition at line 622 of file draw_cache_impl_subdivision.cc.

◆ SUBDIV_COARSE_FACE_FLAG_SMOOTH

#define SUBDIV_COARSE_FACE_FLAG_SMOOTH   1u

Definition at line 613 of file draw_cache_impl_subdivision.cc.

◆ SUBDIV_COARSE_FACE_FLAG_SMOOTH_MASK

#define SUBDIV_COARSE_FACE_FLAG_SMOOTH_MASK    (SUBDIV_COARSE_FACE_FLAG_SMOOTH << SUBDIV_COARSE_FACE_FLAG_OFFSET)

Definition at line 620 of file draw_cache_impl_subdivision.cc.

◆ SUBDIV_COARSE_FACE_LOOP_START_MASK

#define SUBDIV_COARSE_FACE_LOOP_START_MASK
Value:
SUBDIV_COARSE_FACE_FLAG_ACTIVE | SUBDIV_COARSE_FACE_FLAG_HIDDEN) \
#define SUBDIV_COARSE_FACE_FLAG_HIDDEN
#define SUBDIV_COARSE_FACE_FLAG_OFFSET
#define SUBDIV_COARSE_FACE_FLAG_SMOOTH
#define SUBDIV_COARSE_FACE_FLAG_SELECT

Definition at line 629 of file draw_cache_impl_subdivision.cc.

◆ SUBDIV_LOCAL_WORK_GROUP_SIZE

#define SUBDIV_LOCAL_WORK_GROUP_SIZE   64

Definition at line 1269 of file draw_cache_impl_subdivision.cc.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
SHADER_BUFFER_LINES 
SHADER_BUFFER_LINES_LOOSE 
SHADER_BUFFER_EDGE_FAC 
SHADER_BUFFER_LNOR 
SHADER_BUFFER_TRIS 
SHADER_BUFFER_TRIS_MULTIPLE_MATERIALS 
SHADER_BUFFER_NORMALS_ACCUMULATE 
SHADER_BUFFER_NORMALS_FINALIZE 
SHADER_PATCH_EVALUATION 
SHADER_PATCH_EVALUATION_FVAR 
SHADER_PATCH_EVALUATION_FACE_DOTS 
SHADER_PATCH_EVALUATION_FACE_DOTS_WITH_NORMALS 
SHADER_PATCH_EVALUATION_ORCO 
SHADER_COMP_CUSTOM_DATA_INTERP_1D 
SHADER_COMP_CUSTOM_DATA_INTERP_2D 
SHADER_COMP_CUSTOM_DATA_INTERP_3D 
SHADER_COMP_CUSTOM_DATA_INTERP_4D 
SHADER_BUFFER_SCULPT_DATA 
SHADER_BUFFER_UV_STRETCH_ANGLE 
SHADER_BUFFER_UV_STRETCH_AREA 
NUM_SHADERS 

Definition at line 60 of file draw_cache_impl_subdivision.cc.

Function Documentation

◆ build_vertex_face_adjacency_maps()

static void build_vertex_face_adjacency_maps ( DRWSubdivCache cache)
static

◆ compute_coarse_face_flag()

static uint32_t compute_coarse_face_flag ( BMFace f,
BMFace efa_act 
)
static

◆ create_buffer_and_interface()

static GPUVertBuf* create_buffer_and_interface ( OpenSubdiv_Buffer interface,
GPUVertFormat format 
)
static

◆ do_subdiv_traversal()

static void do_subdiv_traversal ( DRWCacheBuildingContext cache_building_context,
Subdiv subdiv 
)
static

◆ draw_patch_map_build()

static void draw_patch_map_build ( DRWPatchMap gpu_patch_map,
Subdiv subdiv 
)
static

◆ draw_patch_map_free()

static void draw_patch_map_free ( DRWPatchMap gpu_patch_map)
static

◆ draw_subdiv_accumulate_normals()

void draw_subdiv_accumulate_normals ( const DRWSubdivCache cache,
GPUVertBuf pos_nor,
GPUVertBuf face_adjacency_offsets,
GPUVertBuf face_adjacency_lists,
GPUVertBuf vertex_loop_map,
GPUVertBuf vertex_normals 
)

◆ draw_subdiv_build_cache()

static bool draw_subdiv_build_cache ( DRWSubdivCache cache,
Subdiv subdiv,
Mesh mesh_eval,
const SubsurfRuntimeData runtime_data 
)
static

◆ draw_subdiv_build_edge_fac_buffer()

void draw_subdiv_build_edge_fac_buffer ( const DRWSubdivCache cache,
GPUVertBuf pos_nor,
GPUVertBuf edge_idx,
GPUVertBuf edge_fac 
)

◆ draw_subdiv_build_edituv_stretch_angle_buffer()

void draw_subdiv_build_edituv_stretch_angle_buffer ( const DRWSubdivCache cache,
GPUVertBuf pos_nor,
GPUVertBuf uvs,
int  uvs_offset,
GPUVertBuf stretch_angles 
)

◆ draw_subdiv_build_edituv_stretch_area_buffer()

void draw_subdiv_build_edituv_stretch_area_buffer ( const DRWSubdivCache cache,
GPUVertBuf coarse_data,
GPUVertBuf subdiv_data 
)

◆ draw_subdiv_build_fdots_buffers()

void draw_subdiv_build_fdots_buffers ( const DRWSubdivCache cache,
GPUVertBuf fdots_pos,
GPUVertBuf fdots_nor,
GPUIndexBuf fdots_indices 
)

◆ draw_subdiv_build_lines_buffer()

void draw_subdiv_build_lines_buffer ( const DRWSubdivCache cache,
GPUIndexBuf lines_indices 
)

◆ draw_subdiv_build_lines_loose_buffer()

void draw_subdiv_build_lines_loose_buffer ( const DRWSubdivCache cache,
GPUIndexBuf lines_indices,
GPUVertBuf lines_flags,
uint  num_loose_edges 
)

◆ draw_subdiv_build_lnor_buffer()

void draw_subdiv_build_lnor_buffer ( const DRWSubdivCache cache,
GPUVertBuf pos_nor,
GPUVertBuf lnor 
)

◆ draw_subdiv_build_origindex_buffer()

GPUVertBuf* draw_subdiv_build_origindex_buffer ( int *  vert_origindex,
uint  num_loops 
)

◆ draw_subdiv_build_sculpt_data_buffer()

void draw_subdiv_build_sculpt_data_buffer ( const DRWSubdivCache cache,
GPUVertBuf mask_vbo,
GPUVertBuf face_set_vbo,
GPUVertBuf sculpt_data 
)

◆ draw_subdiv_build_tris_buffer()

void draw_subdiv_build_tris_buffer ( const DRWSubdivCache cache,
GPUIndexBuf subdiv_tris,
const int  material_count 
)

◆ draw_subdiv_cache_ensure_mat_offsets()

static void draw_subdiv_cache_ensure_mat_offsets ( DRWSubdivCache cache,
Mesh mesh_eval,
uint  mat_len 
)
static

For material assignments we want indices for triangles that share a common material to be laid out contiguously in memory. To achieve this, we sort the indices based on which material the coarse polygon was assigned. The sort is performed by offsetting the loops indices so that they are directly assigned to the right sorted indices.

Here is a visual representation, considering four quads:
+---------+---------+---------+---------+
| 3 2 | 7 6 | 11 10 | 15 14 |
| | | | |
| 0 1 | 4 5 | 8 9 | 12 13 |
+---------+---------+---------+---------+
If the first and third quads have the same material, we should have:
+---------+---------+---------+---------+
| 3 2 | 11 10 | 7 6 | 15 14 |
| | | | |
| 0 1 | 8 9 | 4 5 | 12 13 |
+---------+---------+---------+---------+
So the offsets would be:
+---------+---------+---------+---------+
| 0 0 | 4 4 | -4 -4 | 0 0 |
| | | | |
| 0 0 | 4 4 | -4 -4 | 0 0 |
+---------+---------+---------+---------+

The offsets are computed not based on the loops indices, but on the number of subdivided polygons for each coarse polygon. We then only store a single offset for each coarse polygon, since all sub-faces are contiguous, they all share the same offset.

Definition at line 1947 of file draw_cache_impl_subdivision.cc.

References draw_subdiv_build_origindex_buffer(), draw_subdiv_cache_free_material_data(), DRWSubdivCache::mat_end, MPoly::mat_nr, DRWSubdivCache::mat_start, MEM_callocN, MEM_dupallocN, MEM_freeN, MEM_mallocN, Mesh::mpoly, DRWSubdivCache::num_subdiv_loops, DRWSubdivCache::polygon_mat_offset, DRWSubdivCache::subdiv_polygon_offset, and Mesh::totpoly.

Referenced by draw_subdiv_create_requested_buffers().

◆ draw_subdiv_cache_extra_coarse_face_data_bm()

static void draw_subdiv_cache_extra_coarse_face_data_bm ( BMesh bm,
BMFace efa_act,
uint32_t flags_data 
)
static

◆ draw_subdiv_cache_extra_coarse_face_data_mapped()

static void draw_subdiv_cache_extra_coarse_face_data_mapped ( Mesh mesh,
BMesh bm,
MeshRenderData mr,
uint32_t flags_data 
)
static

◆ draw_subdiv_cache_extra_coarse_face_data_mesh()

static void draw_subdiv_cache_extra_coarse_face_data_mesh ( Mesh mesh,
uint32_t flags_data 
)
static

◆ draw_subdiv_cache_free()

void draw_subdiv_cache_free ( DRWSubdivCache cache)

◆ draw_subdiv_cache_free_material_data()

static void draw_subdiv_cache_free_material_data ( DRWSubdivCache cache)
static

◆ draw_subdiv_cache_get_loose_edges()

blender::Span<DRWSubdivLooseEdge> draw_subdiv_cache_get_loose_edges ( const DRWSubdivCache cache)

◆ draw_subdiv_cache_get_loose_verts()

blender::Span<DRWSubdivLooseVertex> draw_subdiv_cache_get_loose_verts ( const DRWSubdivCache cache)

◆ draw_subdiv_cache_need_polygon_data()

static bool draw_subdiv_cache_need_polygon_data ( const DRWSubdivCache cache)
static

◆ draw_subdiv_cache_update_extra_coarse_face_data()

static void draw_subdiv_cache_update_extra_coarse_face_data ( DRWSubdivCache cache,
Mesh mesh,
MeshRenderData mr 
)
static

◆ draw_subdiv_create_requested_buffers()

static bool 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  is_mode_active,
const float  obmat[4][4],
const bool  do_final,
const bool  do_uvedit,
const bool  do_cage,
const ToolSettings ts,
const bool  use_hide,
OpenSubdiv_EvaluatorCache evaluator_cache 
)
static

Definition at line 2012 of file draw_cache_impl_subdivision.cc.

References BKE_object_get_editmesh_eval_final(), BKE_subdiv_eval_begin_from_mesh(), BKE_subsurf_modifier_subdiv_descriptor_ensure(), BLI_assert, BMEditMesh::bm, bm, DRWSubdivCache::bm, MeshBufferCache::buff, CD_CUSTOMLOOPNORMAL, CustomData_has_layer(), draw_subdiv_build_cache(), draw_subdiv_cache_ensure_mat_offsets(), draw_subdiv_cache_update_extra_coarse_face_data(), draw_subdiv_invalidate_evaluator_for_orco(), DRW_ibo_requested(), MeshRenderData::edit_bmesh, Mesh::edit_mesh, Mesh::flag, SubsurfRuntimeData::has_gpu_subdiv, MeshBufferList::ibo, DRWSubdivCache::is_edit_mode, Mesh::ldata, SubdivSettings::level, MeshBatchCache::mat_len, ME_AUTOSMOOTH, mesh, DRWSubdivCache::mesh, mesh_batch_cache_ensure_subdiv_cache(), blender::draw::mesh_buffer_cache_create_requested_subdiv(), mesh_render_data_create(), mesh_render_data_free(), DRWSubdivCache::num_subdiv_edges, DRWSubdivCache::num_subdiv_loops, DRWSubdivCache::num_subdiv_quads, DRWSubdivCache::num_subdiv_triangles, DRWSubdivCache::num_subdiv_verts, DRWSubdivCache::optimal_display, Mesh::runtime, SubsurfRuntimeData::settings, SubsurfRuntimeData::stats_totedge, SubsurfRuntimeData::stats_totloop, SubsurfRuntimeData::stats_totpoly, SubsurfRuntimeData::stats_totvert, DRWSubdivCache::subdiv, SUBDIV_EVALUATOR_TYPE_GPU, Mesh_Runtime::subsurf_runtime_data, Mesh::totpoly, MeshBufferList::tris, tris_count_from_number_of_loops(), DRWSubdivCache::use_custom_loop_normals, DRWSubdivCache::use_hide, MeshRenderData::use_hide, SubsurfRuntimeData::use_loop_normals, and SubsurfRuntimeData::use_optimal_display.

Referenced by DRW_create_subdivision().

◆ draw_subdiv_edge_cb()

static void draw_subdiv_edge_cb ( const SubdivForeachContext foreach_context,
void UNUSEDtls,
const int  coarse_edge_index,
const int  subdiv_edge_index,
const bool   UNUSEDis_loose,
const int   UNUSEDsubdiv_v1,
const int   UNUSEDsubdiv_v2 
)
static

◆ draw_subdiv_extract_pos_nor()

void draw_subdiv_extract_pos_nor ( const DRWSubdivCache cache,
GPUVertBuf pos_nor,
GPUVertBuf orco 
)

◆ draw_subdiv_extract_uvs()

void draw_subdiv_extract_uvs ( const DRWSubdivCache cache,
GPUVertBuf uvs,
const int  face_varying_channel,
const int  dst_offset 
)

◆ draw_subdiv_finalize_custom_normals()

void draw_subdiv_finalize_custom_normals ( const DRWSubdivCache cache,
GPUVertBuf src_custom_normals,
GPUVertBuf pos_nor 
)

◆ draw_subdiv_finalize_normals()

void draw_subdiv_finalize_normals ( const DRWSubdivCache cache,
GPUVertBuf vertex_normals,
GPUVertBuf subdiv_loop_subdiv_vert_index,
GPUVertBuf pos_nor 
)

◆ draw_subdiv_foreach_callbacks()

static void draw_subdiv_foreach_callbacks ( SubdivForeachContext foreach_context)
static

◆ draw_subdiv_free_edit_mode_cache()

static void draw_subdiv_free_edit_mode_cache ( DRWSubdivCache cache)
static

◆ draw_subdiv_get_pos_nor_format()

GPUVertFormat* draw_subdiv_get_pos_nor_format ( void  )

◆ draw_subdiv_init_origindex_buffer()

void draw_subdiv_init_origindex_buffer ( GPUVertBuf buffer,
int32_t vert_origindex,
uint  num_loops,
uint  loose_len 
)

◆ draw_subdiv_init_ubo_storage()

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 
)
static

◆ draw_subdiv_interp_custom_data()

void draw_subdiv_interp_custom_data ( const DRWSubdivCache cache,
GPUVertBuf src_data,
GPUVertBuf dst_data,
int  dimensions,
int  dst_offset,
bool  compress_to_u16 
)

◆ draw_subdiv_invalidate_evaluator_for_orco()

static void draw_subdiv_invalidate_evaluator_for_orco ( Subdiv subdiv,
Mesh mesh 
)
static

◆ draw_subdiv_loop_cb()

static void draw_subdiv_loop_cb ( const SubdivForeachContext foreach_context,
void UNUSEDtls_v,
const int  ptex_face_index,
const float  u,
const float  v,
const int   UNUSEDcoarse_loop_index,
const int  coarse_poly_index,
const int   UNUSEDcoarse_corner,
const int  subdiv_loop_index,
const int  subdiv_vertex_index,
const int  subdiv_edge_index 
)
static

◆ draw_subdiv_topology_info_cb()

static bool draw_subdiv_topology_info_cb ( const SubdivForeachContext foreach_context,
const int  num_vertices,
const int  num_edges,
const int  num_loops,
const int  num_polygons,
const int *  subdiv_polygon_offset 
)
static

◆ draw_subdiv_ubo_update_and_bind()

static void 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 
)
static

◆ draw_subdiv_vertex_corner_cb()

static void draw_subdiv_vertex_corner_cb ( const SubdivForeachContext foreach_context,
void UNUSEDtls,
const int   UNUSEDptex_face_index,
const float   UNUSEDu,
const float   UNUSEDv,
const int  coarse_vertex_index,
const int   UNUSEDcoarse_poly_index,
const int   UNUSEDcoarse_corner,
const int  subdiv_vertex_index 
)
static

◆ draw_subdiv_vertex_edge_cb()

static void draw_subdiv_vertex_edge_cb ( const SubdivForeachContext UNUSEDforeach_context,
void UNUSEDtls_v,
const int   UNUSEDptex_face_index,
const float   UNUSEDu,
const float   UNUSEDv,
const int   UNUSEDcoarse_edge_index,
const int   UNUSEDcoarse_poly_index,
const int   UNUSEDcoarse_corner,
const int   UNUSEDsubdiv_vertex_index 
)
static

Definition at line 910 of file draw_cache_impl_subdivision.cc.

Referenced by draw_subdiv_foreach_callbacks().

◆ DRW_cache_free_old_subdiv()

void DRW_cache_free_old_subdiv ( void  )

◆ DRW_create_subdivision()

void DRW_create_subdivision ( Object ob,
Mesh mesh,
MeshBatchCache batch_cache,
MeshBufferCache mbc,
const bool  is_editmode,
const bool  is_paint_mode,
const bool  is_mode_active,
const float  obmat[4][4],
const bool  do_final,
const bool  do_uvedit,
const bool  do_cage,
const ToolSettings ts,
const bool  use_hide 
)

◆ DRW_subdiv_cache_free()

void DRW_subdiv_cache_free ( Subdiv subdiv)

◆ drw_subdiv_compute_dispatch()

static void 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 
)
static

◆ DRW_subdiv_free()

void DRW_subdiv_free ( void  )

◆ DRW_subdivide_loose_geom()

void DRW_subdivide_loose_geom ( DRWSubdivCache subdiv_cache,
MeshBufferCache cache 
)

◆ get_blender_patch_coords_format()

static GPUVertFormat* get_blender_patch_coords_format ( )
static

◆ get_dispatch_size()

static uint get_dispatch_size ( uint  elements)
static

◆ get_origindex_format()

static GPUVertFormat* get_origindex_format ( )
static

◆ get_patch_array_format()

static GPUVertFormat* get_patch_array_format ( )
static

◆ get_patch_evaluation_shader()

static GPUShader* get_patch_evaluation_shader ( int  shader_type)
static

◆ get_patch_handle_format()

static GPUVertFormat* get_patch_handle_format ( )
static

◆ get_patch_index_format()

static GPUVertFormat* get_patch_index_format ( )
static

◆ get_patch_param_format()

static GPUVertFormat* get_patch_param_format ( )
static

◆ get_quadtree_format()

static GPUVertFormat* get_quadtree_format ( )
static

◆ get_shader_code()

static const char* get_shader_code ( int  shader_type)
static

◆ get_shader_name()

static const char* get_shader_name ( int  shader_type)
static

◆ get_subdiv_shader()

static GPUShader* get_subdiv_shader ( int  shader_type,
const char *  defines 
)
static

◆ get_subdiv_vertex_format()

static GPUVertFormat* get_subdiv_vertex_format ( )
static

◆ get_uvs_format()

static GPUVertFormat* get_uvs_format ( )
static

Vertex formats used for data transfer from OpenSubdiv, and for data processing on our side.

Definition at line 278 of file draw_cache_impl_subdivision.cc.

References GPU_COMP_F32, GPU_FETCH_FLOAT, and GPU_vertformat_attr_add().

Referenced by draw_subdiv_extract_uvs().

◆ gpu_vertbuf_create_from_format()

static GPUVertBuf* gpu_vertbuf_create_from_format ( GPUVertFormat format,
uint  len 
)
static

◆ make_patch_coord()

MINLINE CompressedPatchCoord make_patch_coord ( int  ptex_face_index,
float  u,
float  v 
)

Definition at line 363 of file draw_cache_impl_subdivision.cc.

References v.

Referenced by draw_subdiv_build_cache(), and draw_subdiv_loop_cb().

◆ mesh_batch_cache_ensure_subdiv_cache()

static DRWSubdivCache* mesh_batch_cache_ensure_subdiv_cache ( MeshBatchCache mbc)
static

◆ opensubdiv_gpu_buffer_init()

static void opensubdiv_gpu_buffer_init ( OpenSubdiv_Buffer buffer_interface,
GPUVertBuf vertbuf 
)
static

◆ tris_count_from_number_of_loops()

static uint tris_count_from_number_of_loops ( const uint  number_of_loops)
static

◆ vertbuf_alloc()

static void* vertbuf_alloc ( const OpenSubdiv_Buffer interface,
const uint  len 
)
static

◆ vertbuf_bind_gpu()

static void vertbuf_bind_gpu ( const OpenSubdiv_Buffer buffer)
static

Definition at line 410 of file draw_cache_impl_subdivision.cc.

References buffer, GPU_vertbuf_use(), and verts.

Referenced by opensubdiv_gpu_buffer_init().

◆ vertbuf_device_alloc()

static void vertbuf_device_alloc ( const OpenSubdiv_Buffer interface,
const uint  len 
)
static

◆ vertbuf_update_data()

static void vertbuf_update_data ( const OpenSubdiv_Buffer interface,
uint  start,
uint  len,
const void data 
)
static

◆ vertbuf_wrap_device_handle()

static void vertbuf_wrap_device_handle ( const OpenSubdiv_Buffer interface,
uint64_t  handle 
)
static

Variable Documentation

◆ datatoc_common_subdiv_custom_data_interp_comp_glsl

char datatoc_common_subdiv_custom_data_interp_comp_glsl[]

Definition at line 47 of file draw_cache_impl_subdivision.cc.

Referenced by get_shader_code().

◆ datatoc_common_subdiv_ibo_lines_comp_glsl

char datatoc_common_subdiv_ibo_lines_comp_glsl[]

Definition at line 48 of file draw_cache_impl_subdivision.cc.

Referenced by get_shader_code().

◆ datatoc_common_subdiv_ibo_tris_comp_glsl

char datatoc_common_subdiv_ibo_tris_comp_glsl[]

Definition at line 49 of file draw_cache_impl_subdivision.cc.

Referenced by get_shader_code().

◆ datatoc_common_subdiv_lib_glsl

char datatoc_common_subdiv_lib_glsl[]

◆ datatoc_common_subdiv_normals_accumulate_comp_glsl

char datatoc_common_subdiv_normals_accumulate_comp_glsl[]

Definition at line 51 of file draw_cache_impl_subdivision.cc.

Referenced by get_shader_code().

◆ datatoc_common_subdiv_normals_finalize_comp_glsl

char datatoc_common_subdiv_normals_finalize_comp_glsl[]

Definition at line 52 of file draw_cache_impl_subdivision.cc.

Referenced by get_shader_code().

◆ datatoc_common_subdiv_patch_evaluation_comp_glsl

char datatoc_common_subdiv_patch_evaluation_comp_glsl[]

Definition at line 53 of file draw_cache_impl_subdivision.cc.

Referenced by get_shader_code().

◆ datatoc_common_subdiv_vbo_edge_fac_comp_glsl

char datatoc_common_subdiv_vbo_edge_fac_comp_glsl[]

Definition at line 54 of file draw_cache_impl_subdivision.cc.

Referenced by 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 57 of file draw_cache_impl_subdivision.cc.

Referenced by 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 58 of file draw_cache_impl_subdivision.cc.

Referenced by get_shader_code().

◆ datatoc_common_subdiv_vbo_lnor_comp_glsl

char datatoc_common_subdiv_vbo_lnor_comp_glsl[]

Definition at line 55 of file draw_cache_impl_subdivision.cc.

Referenced by get_shader_code().

◆ datatoc_common_subdiv_vbo_sculpt_data_comp_glsl

char datatoc_common_subdiv_vbo_sculpt_data_comp_glsl[]

Definition at line 56 of file draw_cache_impl_subdivision.cc.

Referenced by get_shader_code().

◆ g_evaluator_cache

OpenSubdiv_EvaluatorCache* g_evaluator_cache = nullptr
static

Definition at line 2207 of file draw_cache_impl_subdivision.cc.

Referenced by DRW_create_subdivision(), and DRW_subdiv_free().

◆ g_subdiv_shaders

GPUShader* g_subdiv_shaders[NUM_SHADERS]
static

◆ gpu_subdiv_free_queue

LinkNode* gpu_subdiv_free_queue = nullptr
static

◆ gpu_subdiv_queue_mutex

ThreadMutex gpu_subdiv_queue_mutex = BLI_MUTEX_INITIALIZER
static