57#define TRIS_PER_MAT_INDEX BUFFER_LEN
68 for (
const VBOType vbo : vbos) {
69 if (
const auto *buffer = mbc->buff.vbos.lookup_ptr(vbo)) {
70 buffer_ptrs.
add(buffer->get());
75 for (
const IBOType ibo : ibos) {
76 if (
const auto *buffer = mbc->buff.ibos.lookup_ptr(ibo)) {
77 buffer_ptrs.
add(buffer->get());
82 const auto batch_contains_data = [&](gpu::Batch &batch) {
83 if (buffer_ptrs.
contains(batch.elem)) {
86 if (std::any_of(batch.verts,
88 [&](
gpu::VertBuf *vbo) { return vbo && buffer_ptrs.contains(vbo); }))
96 gpu::Batch *batch = (
reinterpret_cast<gpu::Batch **
>(&cache.
batch))[i];
97 if (batch && batch_contains_data(*batch)) {
113 for (
const VBOType vbo : vbos) {
118 for (
const IBOType ibo : ibos) {
145 const StringRef active_uv_map = me_final.active_or_default_uv_map_name();
158 name =
mesh.active_uv_map_name();
170 return mesh.attributes().contains(name);
184 return mesh.attributes().lookup_meta_data(name);
197 if (gpumat ==
nullptr) {
203 if (gpu_attr.is_default_color) {
211 if (gpu_attr.type ==
CD_ORCO) {
212 r_cd_used->
orco =
true;
220 const StringRef default_name = me_final.default_uv_map_name();
230 r_cd_used->
orco =
true;
237 const StringRef default_name = me_final.default_uv_map_name();
240 r_cd_used->
uv.
add(default_name);
250 if (meta_data == UV_METADATA) {
251 r_cd_used->
uv.
add(name);
272 memset(wstate, 0,
sizeof(*wstate));
285 memcpy(wstate_dst, wstate_src,
sizeof(*wstate_dst));
301 return ((!array1 && !array2) ||
302 (array1 && array2 && memcmp(array1, array2, size *
sizeof(
bool)) == 0));
321 memset(wstate, 0,
sizeof(*wstate));
394 if (cache ==
nullptr) {
417 if (!
mesh.runtime->batch_cache) {
418 mesh.runtime->batch_cache = MEM_new<MeshBatchCache>(__func__);
421 *
mesh.runtime->batch_cache = {};
448 if (
mesh.runtime->batch_cache) {
457 return mesh.runtime->batch_cache;
484 for (
int i = 0; i < cache.
mat_len; i++) {
490 for (
const int i : used_material_indices) {
551 if (!
mesh->runtime->batch_cache) {
612 for (
int i = 0; i <
sizeof(cache.
batch) /
sizeof(
void *); i++) {
613 gpu::Batch **batch =
reinterpret_cast<gpu::Batch **
>(&cache.
batch);
640 MEM_delete(batch_cache);
654 "No uv layer available in texpaint, but batches requested anyway!");
665 auto request_color_attribute = [&](
const StringRef name) {
666 if (!name.is_empty()) {
960 if (tot_area !=
nullptr) {
963 if (tot_uv_area !=
nullptr) {
1058 if (cache ==
nullptr) {
1070 if (ctime - cache->
lastmatch >
U.vbotimeout) {
1084 gpu::VertBuf *vbo = GPU_vertbuf_create_with_format(format);
1096 const bool is_paint_mode,
1097 const bool use_hide)
1102 bool cd_uv_update =
false;
1131 if (batch_requested &
1154 if (!uvs_overlap || !tan_overlap || !attr_overlap ||
1162 cd_uv_update =
true;
1173 if (!attr_overlap) {
1174 for (
int i = 0; i < GPU_MAX_ATTR; i++) {
1181 for (
int i = 0; i < cache.
mat_len; i++) {
1198 if ((batch_requested &
MBC_EDITUV) || cd_uv_update) {
1201 if (cd_uv_update || (cache.
is_uvsyncsel != is_uvsyncsel)) {
1246 bool do_cage =
false;
1247 const Mesh *edit_data_mesh =
nullptr;
1250 if (eval_cage && eval_cage != &
mesh) {
1255 edit_data_mesh = eval_cage;
1258 edit_data_mesh = &
mesh;
1262 bool do_uvcage =
false;
1266 do_uvcage = !(
mesh.runtime->is_original_bmesh &&
1270 const DRWBatchFlag batches_to_create = batch_requested & ~cache.batch_ready;
1274 enum class BufferList :
int8_t { Final, Cage, UVCage };
1276 struct BatchCreateData {
1280 std::optional<IBOType> ibo;
1286 const BufferList
list = BufferList::Final;
1299 batch_info.
append(std::move(batch));
1307 batch_info.
append(std::move(batch));
1374 BatchCreateData batch{
1379 batch_info.
append(std::move(batch));
1382 BatchCreateData batch{
1387 batch_info.
append(std::move(batch));
1390 BatchCreateData batch{
1395 batch_info.
append(std::move(batch));
1401 const bool is_face_selectable =
1410 batch_info.
append(std::move(batch));
1426 *edit_data_mesh, orig_edit_mesh);
1429 const BufferList
list = do_cage ? BufferList::Cage : BufferList::Final;
1431 if (edit_mapping_valid) {
1443 if (edit_mapping_valid) {
1449 if (!do_subdivision || do_cage) {
1452 batch_info.
append(std::move(batch));
1459 if (edit_mapping_valid) {
1465 batch_info.
append(std::move(batch));
1472 if (edit_mapping_valid) {
1484 if (edit_mapping_valid) {
1496 if (edit_mapping_valid) {
1508 if (edit_mapping_valid) {
1520 if (is_editmode && !edit_mapping_valid) {
1532 if (is_editmode && !edit_mapping_valid) {
1544 if (is_editmode && !edit_mapping_valid) {
1556 if (is_editmode && !edit_mapping_valid) {
1575 const BufferList
list = do_uvcage ? BufferList::UVCage : BufferList::Final;
1578 if (edit_mapping_valid) {
1590 if (edit_mapping_valid) {
1602 if (edit_mapping_valid) {
1614 if (edit_mapping_valid) {
1626 if (edit_mapping_valid) {
1638 if (edit_mapping_valid) {
1651 std::array<VectorSet<IBOType>, 3> ibo_requests;
1652 std::array<VectorSet<VBOType>, 3> vbo_requests;
1653 for (
const BatchCreateData &batch : batch_info) {
1655 ibo_requests[int(batch.list)].add(*batch.ibo);
1657 vbo_requests[int(batch.list)].add_multiple(batch.vbos);
1668 vbo_requests[int(BufferList::Final)].add(
VBOType::UVs);
1683 ibo_requests[
int(BufferList::UVCage)],
1684 vbo_requests[
int(BufferList::UVCage)],
1699 ibo_requests[
int(BufferList::Cage)],
1700 vbo_requests[
int(BufferList::Cage)],
1710 if (do_subdivision) {
1715 ibo_requests[
int(BufferList::Final)],
1716 vbo_requests[
int(BufferList::Final)],
1735 ibo_requests[
int(BufferList::Final)],
1736 vbo_requests[
int(BufferList::Final)],
1745 std::array<MeshBufferCache *, 3> caches{&cache.
final, &cache.
cage, &cache.
uv_cage};
1746 for (
const BatchCreateData &batch : batch_info) {
1748 gpu::IndexBuf *ibo = batch.ibo ? caches[int(batch.list)]->buff.ibos.lookup(*batch.ibo).get() :
1751 for (
const VBOType vbo_request : batch.vbos) {
1753 &batch.batch, cache_for_batch.
buff.
vbos.lookup(vbo_request).get(),
false);
CustomData interface, see also DNA_customdata_types.h.
General operations, lookup, etc. for materials.
General operations, lookup, etc. for blender objects.
A BVH for high poly meshes.
#define ME_USING_MIRROR_X_VERTEX_GROUPS(_me)
Object is a sort of wrapper for general info.
#define GPU_BATCH_CLEAR_SAFE(batch)
#define GPU_batch_init(batch, primitive_type, vertex_buf, index_buf)
#define GPU_BATCH_DISCARD_SAFE(batch)
void GPU_ray_tracing_blas_discard(blender::gpu::BottomLevelAS *blas)
Read Blender memory allocation and freeing.
IndexRange index_range() const
void reinitialize(const int64_t new_size)
constexpr IndexRange()=default
void reserve(const int64_t n)
bool contains(const Key &key) const
constexpr int64_t size() const
bool add_as(ForwardKey &&key)
IndexRange index_range() const
void append(const T &value)
constexpr bool is_empty() const
virtual void add_geometry(IndexBuf &index_buffer, VertBuf &vertex_buffer)=0
pbvh::Tree * pbvh_get(Object &object)
void update_normals_from_eval(Object &object_eval, Tree &pbvh)
static bool attribute_exists(const Mesh &mesh, const StringRef name)
void DRW_mesh_batch_cache_validate(Mesh &mesh)
gpu::Batch * DRW_mesh_batch_cache_get_edituv_faces_stretch_angle(Object &object, Mesh &mesh)
void drw_attributes_add_request(VectorSet< std::string > *attrs, const StringRef name)
static void drw_mesh_weight_state_extract(Object &ob, Mesh &mesh, const ToolSettings &ts, bool paint_mode, DRW_MeshWeightState *wstate)
static void init_empty_dummy_batch(gpu::Batch &batch)
gpu::Batch * DRW_mesh_batch_cache_get_loose_edges(Mesh &mesh)
gpu::Batch * DRW_mesh_batch_cache_get_edituv_edges(Object &object, Mesh &mesh)
gpu::Batch * DRW_mesh_batch_cache_get_surface_texpaint_single(Object &object, Mesh &mesh)
gpu::Batch * DRW_mesh_batch_cache_get_edit_edges(Mesh &mesh)
static void mesh_batch_cache_discard_shaded_tri(MeshBatchCache &cache)
gpu::Batch * DRW_mesh_batch_cache_get_edituv_facedots(Object &object, Mesh &mesh)
static bool drw_mesh_flags_equal(const bool *array1, const bool *array2, int size)
gpu::Batch * DRW_mesh_batch_cache_get_facedots_with_select_id(Mesh &mesh)
static void mesh_cd_calc_active_uv_layer(const Object &object, const Mesh &mesh, DRW_MeshCDMask &cd_used)
gpu::Batch * DRW_mesh_batch_cache_get_edituv_wireframe(Object &object, Mesh &mesh)
void DRW_mesh_batch_cache_free(draw::MeshBatchCache *batch_cache)
gpu::Batch * DRW_mesh_batch_cache_get_edit_facedots(Mesh &mesh)
void draw_subdiv_cache_free(DRWSubdivCache &cache)
gpu::Batch * DRW_mesh_batch_cache_get_edituv_verts(Object &object, Mesh &mesh)
gpu::Batch * DRW_mesh_batch_cache_get_edit_mesh_analysis(Mesh &mesh)
gpu::Batch * DRW_mesh_batch_cache_get_surface(Mesh &mesh)
static void texpaint_request_active_uv(MeshBatchCache &cache, Object &object, Mesh &mesh)
static void mesh_cd_calc_edit_uv_layer(const Mesh &, DRW_MeshCDMask *cd_used)
static void mesh_batch_cache_discard_uvedit_select(MeshBatchCache &cache)
gpu::Batch * DRW_mesh_batch_cache_get_surface_weights(Mesh &mesh)
Span< gpu::Batch * > DRW_mesh_batch_cache_get_surface_shaded(Object &object, Mesh &mesh, Span< const GPUMaterial * > materials)
gpu::Batch * DRW_mesh_batch_cache_get_edituv_faces(Object &object, Mesh &mesh)
@ MBC_EDIT_SELECTION_FACES
@ MBC_PAINT_OVERLAY_VERTS
@ MBC_PAINT_OVERLAY_WIRE_LOOPS
@ MBC_EDITUV_FACES_STRETCH_ANGLE
@ MBC_EDIT_SELECTION_FACEDOTS
@ MBC_PAINT_OVERLAY_SURFACE
@ MBC_EDIT_SELECTION_VERTS
@ MBC_EDITUV_FACES_STRETCH_AREA
@ MBC_VIEWER_ATTRIBUTE_OVERLAY
@ MBC_EDIT_SELECTION_EDGES
gpu::Batch * DRW_mesh_batch_cache_get_surface_vertpaint(Object &object, Mesh &mesh)
gpu::Batch * DRW_mesh_batch_cache_get_wireframes_face(Mesh &mesh)
gpu::Batch * DRW_mesh_batch_cache_get_surface_sculpt(Object &object, Mesh &mesh)
gpu::Batch * DRW_mesh_batch_cache_get_all_edges(Mesh &mesh)
gpu::Batch * DRW_mesh_batch_cache_get_paint_overlay_verts(Mesh &mesh)
gpu::Batch * DRW_mesh_batch_cache_get_edit_loop_normals(Mesh &mesh)
static bool drw_mesh_weight_state_compare(const DRW_MeshWeightState *a, const DRW_MeshWeightState *b)
gpu::Batch * DRW_mesh_batch_cache_get_edge_detection(Mesh &mesh, bool *r_is_manifold)
void DRW_mesh_batch_cache_free_old(Mesh *mesh, int ctime)
static std::optional< bke::AttributeMetaData > lookup_meta_data(const Mesh &mesh, const StringRef name)
gpu::Batch * DRW_mesh_batch_cache_get_edit_triangles(Mesh &mesh)
Span< gpu::Batch * > DRW_mesh_batch_cache_get_surface_texpaint(Object &object, Mesh &mesh)
gpu::Batch * DRW_mesh_batch_cache_get_edit_vertices(Mesh &mesh)
static void mesh_cd_calc_used_gpu_layers(const Object &object, const Mesh &mesh, const Span< const GPUMaterial * > materials, VectorSet< std::string > *r_attributes, DRW_MeshCDMask *r_cd_used)
static void mesh_batch_cache_init(Mesh &mesh)
gpu::Batch * DRW_mesh_batch_cache_get_all_uv_wireframe(Object &object, Mesh &mesh)
static void mesh_batch_cache_clear(MeshBatchCache &cache)
gpu::Batch * DRW_mesh_batch_cache_get_triangles_with_select_id(Mesh &mesh)
static void mesh_buffer_cache_clear(MeshBufferCache *mbc)
static void mesh_batch_cache_discard_uvedit(MeshBatchCache &cache)
static void mesh_batch_cache_check_vertex_group(MeshBatchCache &cache, const DRW_MeshWeightState *wstate)
static void drw_mesh_weight_state_copy(DRW_MeshWeightState *wstate_dst, const DRW_MeshWeightState *wstate_src)
const Mesh & editmesh_final_or_this(const Object &object, const Mesh &mesh)
static void mesh_cd_calc_active_mask_uv_layer(const Object &object, const Mesh &mesh, DRW_MeshCDMask &cd_used)
bool drw_attributes_overlap(const VectorSet< std::string > *a, const VectorSet< std::string > *b)
static void mesh_batch_cache_request_surface_batches(Mesh &mesh, MeshBatchCache &cache)
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 void mesh_batch_cache_request_surface_blas(MeshBatchCache &cache)
static void request_active_and_default_color_attributes(const Object &object, const Mesh &mesh, VectorSet< std::string > &attributes)
gpu::Batch * DRW_mesh_batch_cache_get_verts_with_select_id(Mesh &mesh)
gpu::Batch * DRW_mesh_batch_cache_get_sculpt_overlays(Mesh &mesh)
static void discard_buffers(MeshBatchCache &cache, const Span< VBOType > vbos, const Span< IBOType > ibos)
gpu::Batch * DRW_mesh_batch_cache_get_paint_overlay_surface(Mesh &mesh)
void DRW_mesh_batch_cache_dirty_tag(Mesh *mesh, eMeshBatchDirtyMode mode)
gpu::Batch * DRW_mesh_batch_cache_get_surface_viewer_attribute(Mesh &mesh)
void DRW_mesh_batch_cache_create_requested(TaskGraph &task_graph, Object &ob, Mesh &mesh, const Scene &scene, bool is_paint_mode, bool use_hide)
BLI_INLINE void mesh_cd_layers_type_merge(DRW_MeshCDMask *a, const DRW_MeshCDMask &b)
void DRW_mesh_get_attributes(const Object &object, const Mesh &mesh, const Span< const GPUMaterial * > materials, VectorSet< std::string > *r_attrs, DRW_MeshCDMask *r_cd_needed)
static void mesh_batch_cache_free_subdiv_cache(MeshBatchCache &cache)
void mesh_buffer_cache_create_requested(TaskGraph &task_graph, const Scene &scene, MeshBatchCache &cache, MeshBufferCache &mbc, Span< IBOType > ibo_requests, Span< VBOType > vbo_requests, Object &object, Mesh &mesh, bool is_editmode, bool is_paint_mode, bool do_final, bool do_uvedit, bool use_hide)
gpu::Batch * DRW_mesh_batch_cache_get_edit_vert_normals(Mesh &mesh)
static MeshBatchCache * mesh_batch_cache_get(Mesh &mesh)
static void drw_mesh_weight_state_clear(DRW_MeshWeightState *wstate)
void drw_attributes_merge(VectorSet< std::string > *dst, const VectorSet< std::string > *src)
gpu::Batch * DRW_mesh_batch_cache_get_uv_faces(Object &object, Mesh &mesh)
gpu::Batch * DRW_mesh_batch_cache_get_edges_with_select_id(Mesh &mesh)
gpu::Batch * DRW_mesh_batch_cache_get_edituv_faces_stretch_area(Object &object, Mesh &mesh, float **tot_area, float **tot_uv_area)
gpu::Batch * DRW_mesh_batch_cache_get_paint_overlay_edges(Mesh &mesh)
static void edituv_request_active_uv(MeshBatchCache &cache, Object &object, Mesh &mesh)
static bool mesh_batch_cache_valid(Mesh &mesh)
gpu::Batch * DRW_mesh_batch_cache_get_all_verts(Mesh &mesh)
@ DRW_MESH_WEIGHT_STATE_MULTIPAINT
@ DRW_MESH_WEIGHT_STATE_LOCK_RELATIVE
@ DRW_MESH_WEIGHT_STATE_AUTO_NORMALIZE
gpu::Batch * DRW_mesh_batch_cache_get_uv_wireframe(Object &object, Mesh &mesh)
gpu::Batch * DRW_mesh_batch_cache_get_edit_skin_roots(Mesh &mesh)
gpu::BottomLevelAS * DRW_mesh_batch_cache_get_surface_blas(Mesh &mesh)
void create_material_subranges(const SortedFaceData &face_sorted, gpu::IndexBuf &tris_ibo, MutableSpan< gpu::IndexBufPtr > ibos)
const Mesh * BKE_object_get_pre_modified_mesh(const Object *object)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
unsigned __int64 uint64_t
bool BKE_subsurf_modifier_has_gpu_subdiv(const Mesh *mesh)
void BKE_object_defgroup_mirror_selection(struct Object *ob, int defbase_tot, const bool *selection, bool *dg_flags_sel, int *r_dg_flags_sel_tot)
bool * BKE_object_defgroup_validmap_get(struct Object *ob, int defbase_tot)
const Mesh * BKE_object_get_editmesh_eval_final(const Object *object)
void DRW_blas_request(gpu::BottomLevelAS **blas)
void BKE_object_defgroup_split_locked_validmap(int defbase_tot, const bool *locked, const bool *deform, bool *r_locked, bool *r_unlocked)
int BKE_id_material_used_with_fallback_eval(const ID &id)
bool * BKE_object_defgroup_selected_get(struct Object *ob, int defbase_tot, int *r_dg_flags_sel_tot)
ListBaseT< GPUMaterialAttribute > GPU_material_attributes(const GPUMaterial *material)
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
BMDataLayerLookup BM_data_layer_lookup(const BMesh &bm, const StringRef name)
const void * CustomData_get_layer(const CustomData *data, eCustomDataType type)
bool BKE_editmesh_eval_orig_map_available(const Mesh &mesh_eval, const Mesh *mesh_orig)
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
gpu::Batch * DRW_batch_request(gpu::Batch **batch)
bool * BKE_object_defgroup_lock_flags_get(struct Object *ob, int defbase_tot)
bool BKE_object_defgroup_check_lock_relative_multi(int defbase_tot, const bool *lock_flags, const bool *selected, int sel_tot)
void GPU_vertbuf_data_alloc(gpu::VertBuf &verts, uint v_len)
const Mesh * DRW_object_get_editmesh_cage_for_drawing(const Object &object)
const BMesh * BKE_editmesh_bmesh_get(const Object *ob)
bool BKE_object_defgroup_check_lock_relative(const bool *lock_flags, const bool *validmap, int index)
@ BKE_MESH_BATCH_DIRTY_UVEDIT_ALL
@ BKE_MESH_BATCH_DIRTY_UVEDIT_SELECT
@ BKE_MESH_BATCH_DIRTY_ALL
@ BKE_MESH_BATCH_DIRTY_SHADING
@ BKE_MESH_BATCH_DIRTY_SELECT
@ BKE_MESH_BATCH_DIRTY_SELECT_PAINT
void GPU_vertbuf_data_len_set(gpu::VertBuf &verts, uint v_len)
int GPU_batch_vertbuf_add(gpu::Batch *batch, gpu::VertBuf *vertex_buf, bool own_vbo)
char * stencil_uv_map_attribute
char * active_color_attribute
char * default_color_attribute
struct ToolSettings * toolsettings
VectorSet< std::string > tan
VectorSet< std::string > uv
VectorSet< std::string > attr_used_over_time
gpu::BottomLevelAS * surface_blas
DRW_MeshWeightState weight_state
Array< gpu::IndexBufPtr > tris_per_mat
DRWBatchFlag batch_requested
VectorSet< std::string > attr_used
DRWSubdivCache * subdiv_cache
Array< gpu::Batch * > surface_per_mat
bool surface_blas_requested
DRW_MeshCDMask cd_used_over_time
VectorSet< std::string > attr_needed
gpu::Batch * wire_loops_edituvs
gpu::Batch * edit_selection_faces
gpu::Batch * edit_skin_roots
gpu::Batch * wire_loops_uvs
gpu::Batch * paint_overlay_surface
gpu::Batch * surface_weights
gpu::Batch * edituv_fdots
gpu::Batch * sculpt_overlays
gpu::Batch * paint_overlay_verts
gpu::Batch * edit_selection_edges
gpu::Batch * edituv_faces
gpu::Batch * surface_viewer_attribute
gpu::Batch * edituv_faces_stretch_angle
gpu::Batch * wire_loops_all_uvs
gpu::Batch * edit_mesh_analysis
gpu::Batch * edit_vertices
gpu::Batch * edituv_verts
gpu::Batch * edge_detection
gpu::Batch * edit_selection_verts
gpu::Batch * edit_triangles
gpu::Batch * paint_overlay_wire_loops
gpu::Batch * edituv_edges
gpu::Batch * edituv_faces_stretch_area
gpu::Batch * edit_selection_fdots
gpu::VertBufPtr face_offsets
MeshExtractLooseGeom loose_geom
SortedFaceData face_sorted
gpu::VertBufPtr corner_edges
gpu::VertBufPtr corner_verts
Map< IBOType, std::unique_ptr< gpu::IndexBuf, gpu::IndexBufDeleter > > ibos
Map< VBOType, std::unique_ptr< gpu::VertBuf, gpu::VertBufDeleter > > vbos