diff options
author | Germano Cavalcante <mano-wii> | 2021-06-14 14:00:42 +0300 |
---|---|---|
committer | Germano Cavalcante <germano.costa@ig.com.br> | 2021-06-15 23:03:19 +0300 |
commit | 6bb980b0f43721a5f87185cbac11d1bd0919a490 (patch) | |
tree | f882e5ba728a29d02f275e4c8fe26b257d56e7c0 /source/blender/draw | |
parent | 8e84938dd0428c0aa9705077b017bad85d490cc9 (diff) |
DRW: sanitize 'DRW_mesh_batch_cache_dirty_tag'
Create maps that specify which batches have vbo or ibo as a reference
and use these maps to discard batches along with buffers.
Differential Revision: https://developer.blender.org/D11588
Diffstat (limited to 'source/blender/draw')
-rw-r--r-- | source/blender/draw/intern/draw_cache_extract.h | 80 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_cache_extract_mesh_private.h | 66 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_cache_impl_mesh.c | 266 |
3 files changed, 315 insertions, 97 deletions
diff --git a/source/blender/draw/intern/draw_cache_extract.h b/source/blender/draw/intern/draw_cache_extract.h index 2c4e4dfe76b..a9c1a506460 100644 --- a/source/blender/draw/intern/draw_cache_extract.h +++ b/source/blender/draw/intern/draw_cache_extract.h @@ -175,41 +175,6 @@ typedef struct MeshBufferExtractionCache { } MeshBufferExtractionCache; -typedef enum DRWBatchFlag { - MBC_SURFACE = (1 << 0), - MBC_SURFACE_WEIGHTS = (1 << 1), - MBC_EDIT_TRIANGLES = (1 << 2), - MBC_EDIT_VERTICES = (1 << 3), - MBC_EDIT_EDGES = (1 << 4), - MBC_EDIT_VNOR = (1 << 5), - MBC_EDIT_LNOR = (1 << 6), - MBC_EDIT_FACEDOTS = (1 << 7), - MBC_EDIT_MESH_ANALYSIS = (1 << 8), - MBC_EDITUV_FACES_STRETCH_AREA = (1 << 9), - MBC_EDITUV_FACES_STRETCH_ANGLE = (1 << 10), - MBC_EDITUV_FACES = (1 << 11), - MBC_EDITUV_EDGES = (1 << 12), - MBC_EDITUV_VERTS = (1 << 13), - MBC_EDITUV_FACEDOTS = (1 << 14), - MBC_EDIT_SELECTION_VERTS = (1 << 15), - MBC_EDIT_SELECTION_EDGES = (1 << 16), - MBC_EDIT_SELECTION_FACES = (1 << 17), - MBC_EDIT_SELECTION_FACEDOTS = (1 << 18), - MBC_ALL_VERTS = (1 << 19), - MBC_ALL_EDGES = (1 << 20), - MBC_LOOSE_EDGES = (1 << 21), - MBC_EDGE_DETECTION = (1 << 22), - MBC_WIRE_EDGES = (1 << 23), - MBC_WIRE_LOOPS = (1 << 24), - MBC_WIRE_LOOPS_UVS = (1 << 25), - MBC_SKIN_ROOTS = (1 << 26), - MBC_SCULPT_OVERLAYS = (1 << 27), -} DRWBatchFlag; - -#define MBC_EDITUV \ - (MBC_EDITUV_FACES_STRETCH_AREA | MBC_EDITUV_FACES_STRETCH_ANGLE | MBC_EDITUV_FACES | \ - MBC_EDITUV_EDGES | MBC_EDITUV_VERTS | MBC_EDITUV_FACEDOTS | MBC_WIRE_LOOPS_UVS) - #define FOREACH_MESH_BUFFER_CACHE(batch_cache, mbc) \ for (MeshBufferCache *mbc = &batch_cache->final; \ mbc == &batch_cache->final || mbc == &batch_cache->cage || mbc == &batch_cache->uv_cage; \ @@ -262,8 +227,8 @@ typedef struct MeshBatchCache { GPUBatch **surface_per_mat; - DRWBatchFlag batch_requested; - DRWBatchFlag batch_ready; + uint32_t batch_requested; /* DRWBatchFlag */ + uint32_t batch_ready; /* DRWBatchFlag */ /* settings to determine if cache is invalid */ int edge_len; @@ -297,6 +262,47 @@ typedef struct MeshBatchCache { #define MBC_VBO_LEN (sizeof(((MeshBufferCache){0}).vbo) / sizeof(void *)) #define MBC_IBO_LEN (sizeof(((MeshBufferCache){0}).ibo) / sizeof(void *)) +#define MBC_BATCH_INDEX(batch_name) \ + ((offsetof(MeshBatchCache, batch_name) - offsetof(MeshBatchCache, batch.surface)) / \ + sizeof(void *)) + +typedef enum DRWBatchFlag { + MBC_SURFACE = (1u << MBC_BATCH_INDEX(batch.surface)), + MBC_SURFACE_WEIGHTS = (1u << MBC_BATCH_INDEX(batch.surface_weights)), + MBC_EDIT_TRIANGLES = (1u << MBC_BATCH_INDEX(batch.edit_triangles)), + MBC_EDIT_VERTICES = (1u << MBC_BATCH_INDEX(batch.edit_vertices)), + MBC_EDIT_EDGES = (1u << MBC_BATCH_INDEX(batch.edit_edges)), + MBC_EDIT_VNOR = (1u << MBC_BATCH_INDEX(batch.edit_vnor)), + MBC_EDIT_LNOR = (1u << MBC_BATCH_INDEX(batch.edit_lnor)), + MBC_EDIT_FACEDOTS = (1u << MBC_BATCH_INDEX(batch.edit_fdots)), + MBC_EDIT_MESH_ANALYSIS = (1u << MBC_BATCH_INDEX(batch.edit_mesh_analysis)), + MBC_SKIN_ROOTS = (1u << MBC_BATCH_INDEX(batch.edit_skin_roots)), + MBC_EDITUV_FACES_STRETCH_AREA = (1u << MBC_BATCH_INDEX(batch.edituv_faces_stretch_area)), + MBC_EDITUV_FACES_STRETCH_ANGLE = (1u << MBC_BATCH_INDEX(batch.edituv_faces_stretch_angle)), + MBC_EDITUV_FACES = (1u << MBC_BATCH_INDEX(batch.edituv_faces)), + MBC_EDITUV_EDGES = (1u << MBC_BATCH_INDEX(batch.edituv_edges)), + MBC_EDITUV_VERTS = (1u << MBC_BATCH_INDEX(batch.edituv_verts)), + MBC_EDITUV_FACEDOTS = (1u << MBC_BATCH_INDEX(batch.edituv_fdots)), + MBC_EDIT_SELECTION_VERTS = (1u << MBC_BATCH_INDEX(batch.edit_selection_verts)), + MBC_EDIT_SELECTION_EDGES = (1u << MBC_BATCH_INDEX(batch.edit_selection_edges)), + MBC_EDIT_SELECTION_FACES = (1u << MBC_BATCH_INDEX(batch.edit_selection_faces)), + MBC_EDIT_SELECTION_FACEDOTS = (1u << MBC_BATCH_INDEX(batch.edit_selection_fdots)), + MBC_ALL_VERTS = (1u << MBC_BATCH_INDEX(batch.all_verts)), + MBC_ALL_EDGES = (1u << MBC_BATCH_INDEX(batch.all_edges)), + MBC_LOOSE_EDGES = (1u << MBC_BATCH_INDEX(batch.loose_edges)), + MBC_EDGE_DETECTION = (1u << MBC_BATCH_INDEX(batch.edge_detection)), + MBC_WIRE_EDGES = (1u << MBC_BATCH_INDEX(batch.wire_edges)), + MBC_WIRE_LOOPS = (1u << MBC_BATCH_INDEX(batch.wire_loops)), + MBC_WIRE_LOOPS_UVS = (1u << MBC_BATCH_INDEX(batch.wire_loops_uvs)), + MBC_SCULPT_OVERLAYS = (1u << MBC_BATCH_INDEX(batch.sculpt_overlays)), +} DRWBatchFlag; + +BLI_STATIC_ASSERT(MBC_BATCH_INDEX(surface_per_mat) < 32, "Number of batches exceeded the limit of bit fields"); + +#define MBC_EDITUV \ + (MBC_EDITUV_FACES_STRETCH_AREA | MBC_EDITUV_FACES_STRETCH_ANGLE | MBC_EDITUV_FACES | \ + MBC_EDITUV_EDGES | MBC_EDITUV_VERTS | MBC_EDITUV_FACEDOTS | MBC_WIRE_LOOPS_UVS) + void mesh_buffer_cache_create_requested(struct TaskGraph *task_graph, MeshBatchCache *cache, MeshBufferCache *mbc, diff --git a/source/blender/draw/intern/draw_cache_extract_mesh_private.h b/source/blender/draw/intern/draw_cache_extract_mesh_private.h index 8c7011dd13c..6e92db3cfb9 100644 --- a/source/blender/draw/intern/draw_cache_extract_mesh_private.h +++ b/source/blender/draw/intern/draw_cache_extract_mesh_private.h @@ -38,6 +38,70 @@ extern "C" { #endif +/* ---------------------------------------------------------------------- */ +/** \name Dependencies between buffer and batch + * \{ */ +#ifndef NDEBUG +# define _MDEF_type(name) static DRWBatchFlag MDEP_assert_##name = 0, MDEP_##name +#else +# define _MDEF_type(name) static const DRWBatchFlag MDEP_##name +#endif + +/* clang-format off */ + +#define _MDEPS_CREATE1(b) (1u << MBC_BATCH_INDEX(b)) +#define _MDEPS_CREATE2(b1, b2) _MDEPS_CREATE1(b1) | _MDEPS_CREATE1(b2) +#define _MDEPS_CREATE3(b1, b2, b3) _MDEPS_CREATE2(b1, b2) | _MDEPS_CREATE1(b3) +#define _MDEPS_CREATE4(b1, b2, b3, b4) _MDEPS_CREATE3(b1, b2, b3) | _MDEPS_CREATE1(b4) +#define _MDEPS_CREATE5(b1, b2, b3, b4, b5) _MDEPS_CREATE4(b1, b2, b3, b4) | _MDEPS_CREATE1(b5) +#define _MDEPS_CREATE6(b1, b2, b3, b4, b5, b6) _MDEPS_CREATE5(b1, b2, b3, b4, b5) | _MDEPS_CREATE1(b6) +#define _MDEPS_CREATE7(b1, b2, b3, b4, b5, b6, b7) _MDEPS_CREATE6(b1, b2, b3, b4, b5, b6) | _MDEPS_CREATE1(b7) +#define _MDEPS_CREATE8(b1, b2, b3, b4, b5, b6, b7, b8) _MDEPS_CREATE7(b1, b2, b3, b4, b5, b6, b7) | _MDEPS_CREATE1(b8) +#define _MDEPS_CREATE9(b1, b2, b3, b4, b5, b6, b7, b8, b9) _MDEPS_CREATE8(b1, b2, b3, b4, b5, b6, b7, b8) | _MDEPS_CREATE1(b9) +#define _MDEPS_CREATE10(b1, b2, b3, b4, b5, b6, b7, b8, b9, b10) _MDEPS_CREATE9(b1, b2, b3, b4, b5, b6, b7, b8, b9) | _MDEPS_CREATE1(b10) +#define _MDEPS_CREATE19(b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19) _MDEPS_CREATE10(b1, b2, b3, b4, b5, b6, b7, b8, b9, b10) | _MDEPS_CREATE9(b11, b12, b13, b14, b15, b16, b17, b18, b19) + +#define MDEPS_CREATE(name, ...) _MDEF_type(name) = VA_NARGS_CALL_OVERLOAD(_MDEPS_CREATE, __VA_ARGS__) + +#define _MDEPS_CREATE_MAP1(a) MDEP_##a +#define _MDEPS_CREATE_MAP2(a, b) MDEP_##a | MDEP_##b +#define _MDEPS_CREATE_MAP3(a, b, c) _MDEPS_CREATE_MAP2(a, b) | MDEP_##c +#define _MDEPS_CREATE_MAP4(a, b, c, d) _MDEPS_CREATE_MAP3(a, b, c) | MDEP_##d +#define _MDEPS_CREATE_MAP5(a, b, c, d, e) _MDEPS_CREATE_MAP4(a, b, c, d) | MDEP_##e +#define _MDEPS_CREATE_MAP6(a, b, c, d, e, f) _MDEPS_CREATE_MAP5(a, b, c, d, e) | MDEP_##f +#define _MDEPS_CREATE_MAP7(a, b, c, d, e, f, g) _MDEPS_CREATE_MAP6(a, b, c, d, e, f) | MDEP_##g +#define _MDEPS_CREATE_MAP8(a, b, c, d, e, f, g, h) _MDEPS_CREATE_MAP7(a, b, c, d, e, f, g) | MDEP_##h +#define _MDEPS_CREATE_MAP9(a, b, c, d, e, f, g, h, i) _MDEPS_CREATE_MAP8(a, b, c, d, e, f, g, h) | MDEP_##i +#define _MDEPS_CREATE_MAP10(a, b, c, d, e, f, g, h, i, j) _MDEPS_CREATE_MAP9(a, b, c, d, e, f, g, h, i) | MDEP_##j + +#define MDEPS_CREATE_MAP(...) VA_NARGS_CALL_OVERLOAD(_MDEPS_CREATE_MAP, __VA_ARGS__) + +#ifndef NDEBUG +# define _MDEPS_ASSERT2(b, name) \ + MDEP_assert_##name |= _MDEPS_CREATE1(b); \ + BLI_assert(MDEP_##name & _MDEPS_CREATE1(b)) +# define _MDEPS_ASSERT3(b, n1, n2) _MDEPS_ASSERT2(b, n1); _MDEPS_ASSERT2(b, n2) +# define _MDEPS_ASSERT4(b, n1, n2, n3) _MDEPS_ASSERT3(b, n1, n2); _MDEPS_ASSERT2(b, n3) +# define _MDEPS_ASSERT5(b, n1, n2, n3, n4) _MDEPS_ASSERT4(b, n1, n2, n3); _MDEPS_ASSERT2(b, n4) +# define _MDEPS_ASSERT6(b, n1, n2, n3, n4, n5) _MDEPS_ASSERT5(b, n1, n2, n3, n4); _MDEPS_ASSERT2(b, n5) +# define _MDEPS_ASSERT7(b, n1, n2, n3, n4, n5, n6) _MDEPS_ASSERT6(b, n1, n2, n3, n4, n5); _MDEPS_ASSERT2(b, n6) +# define _MDEPS_ASSERT8(b, n1, n2, n3, n4, n5, n6, n7) _MDEPS_ASSERT7(b, n1, n2, n3, n4, n5, n6); _MDEPS_ASSERT2(b, n7) + +# define MDEPS_ASSERT(...) VA_NARGS_CALL_OVERLOAD(_MDEPS_ASSERT, __VA_ARGS__) +# define MDEPS_ASSERT_MAP(name) BLI_assert(MDEP_assert_##name == MDEP_##name) +#else +# define MDEPS_ASSERT(...) +# define MDEPS_ASSERT_MAP(name) +#endif + +/* clang-format on */ + +/** \} */ + +/* ---------------------------------------------------------------------- */ +/** \name Mesh Render Data + * \{ */ + typedef enum eMRExtractType { MR_EXTRACT_BMESH, MR_EXTRACT_MAPPED, @@ -154,6 +218,8 @@ BLI_INLINE const float *bm_face_no_get(const MeshRenderData *mr, const BMFace *e return efa->no; } +/** \} */ + /* ---------------------------------------------------------------------- */ /** \name Mesh Elements Extract Struct * \{ */ diff --git a/source/blender/draw/intern/draw_cache_impl_mesh.c b/source/blender/draw/intern/draw_cache_impl_mesh.c index e4c682e1765..20ec22a2f78 100644 --- a/source/blender/draw/intern/draw_cache_impl_mesh.c +++ b/source/blender/draw/intern/draw_cache_impl_mesh.c @@ -67,12 +67,109 @@ #include "ED_uvedit.h" #include "draw_cache_extract.h" +#include "draw_cache_extract_mesh_private.h" #include "draw_cache_inline.h" #include "draw_cache_impl.h" /* own include */ +MDEPS_CREATE(vbo_lnor, batch.surface, batch.wire_loops, batch.edit_lnor, surface_per_mat); +MDEPS_CREATE(vbo_pos_nor, + batch.surface, + batch.surface_weights, + batch.all_verts, + batch.all_edges, + batch.loose_edges, + batch.edge_detection, + batch.wire_loops, + batch.wire_edges, + batch.edit_vnor, + batch.edit_lnor, + batch.edit_vertices, + batch.edit_edges, + batch.edit_triangles, + batch.edit_selection_verts, + batch.edit_selection_edges, + batch.edit_selection_faces, + batch.edit_mesh_analysis, + batch.sculpt_overlays, + surface_per_mat); +MDEPS_CREATE(vbo_uv, + batch.surface, + batch.wire_loops_uvs, + batch.edituv_faces, + batch.edituv_faces_stretch_area, + batch.edituv_faces_stretch_angle, + batch.edituv_edges, + batch.edituv_verts, + surface_per_mat); +MDEPS_CREATE(vbo_vcol, batch.surface, surface_per_mat); +MDEPS_CREATE(vbo_sculpt_data, batch.sculpt_overlays); +MDEPS_CREATE(vbo_weights, batch.surface_weights); +MDEPS_CREATE(vbo_edge_fac, batch.wire_edges); +MDEPS_CREATE(vbo_mesh_analysis, batch.edit_mesh_analysis); +MDEPS_CREATE(vbo_tan, surface_per_mat); +MDEPS_CREATE(vbo_orco, surface_per_mat); +MDEPS_CREATE(vbo_edit_data, batch.edit_triangles, batch.edit_edges, batch.edit_vertices); +MDEPS_CREATE(vbo_fdots_pos, batch.edit_fdots, batch.edit_selection_fdots); +MDEPS_CREATE(vbo_fdots_nor, batch.edit_fdots); +MDEPS_CREATE(vbo_skin_roots, batch.edit_skin_roots); +MDEPS_CREATE(vbo_vert_idx, batch.edit_selection_verts); +MDEPS_CREATE(vbo_edge_idx, batch.edit_selection_edges); +MDEPS_CREATE(vbo_poly_idx, batch.edit_selection_faces); +MDEPS_CREATE(vbo_fdot_idx, batch.edit_selection_fdots); +MDEPS_CREATE(vbo_edituv_data, + batch.edituv_faces, + batch.edituv_faces_stretch_area, + batch.edituv_faces_stretch_angle, + batch.edituv_edges, + batch.edituv_verts); +MDEPS_CREATE(vbo_edituv_stretch_area, batch.edituv_faces_stretch_area); +MDEPS_CREATE(vbo_edituv_stretch_angle, batch.edituv_faces_stretch_angle); +MDEPS_CREATE(vbo_fdots_uv, batch.edituv_fdots); +MDEPS_CREATE(vbo_fdots_edituv_data, batch.edituv_fdots); + +MDEPS_CREATE(ibo_tris, + batch.surface, + batch.sculpt_overlays, + batch.surface_weights, + batch.edit_mesh_analysis, + batch.edit_triangles, + batch.edit_lnor, + batch.edit_selection_faces); +MDEPS_CREATE( + ibo_lines, batch.all_edges, batch.wire_edges, batch.edit_edges, batch.edit_selection_edges); +MDEPS_CREATE(ibo_lines_loose, batch.loose_edges); +MDEPS_CREATE(ibo_lines_adjacency, batch.edge_detection); +MDEPS_CREATE(ibo_lines_paint_mask, batch.wire_loops); +MDEPS_CREATE(ibo_tris_per_mat, surface_per_mat); +MDEPS_CREATE(ibo_points, batch.edit_vnor, batch.edit_selection_verts, batch.edit_vertices); +MDEPS_CREATE(ibo_fdots, batch.edit_fdots, batch.edit_selection_fdots); +MDEPS_CREATE(ibo_edituv_tris, + batch.edituv_faces, + batch.edituv_faces_stretch_area, + batch.edituv_faces_stretch_angle); +MDEPS_CREATE(ibo_edituv_lines, batch.edituv_edges, batch.wire_loops_uvs); +MDEPS_CREATE(ibo_edituv_points, batch.edituv_verts); +MDEPS_CREATE(ibo_edituv_fdots, batch.edituv_fdots); + +static void mesh_batch_cache_discard_surface_batches(MeshBatchCache *cache); static void mesh_batch_cache_clear(Mesh *me); +static void mesh_batch_cache_discard_batch(MeshBatchCache *cache, const DRWBatchFlag batch_map) +{ + for (int i = 0; i < MBC_BATCH_LEN; i++) { + DRWBatchFlag batch_requested = (1u << i); + if (batch_map & batch_requested) { + GPU_BATCH_DISCARD_SAFE(((GPUBatch **)&cache->batch)[i]); + cache->batch_ready &= ~batch_requested; + } + } + + if (batch_map & (1u << MBC_BATCH_INDEX(surface_per_mat))) { + mesh_batch_cache_discard_surface_batches(cache); + } +} + /* Return true is all layers in _b_ are inside _a_. */ BLI_INLINE bool mesh_cd_layers_type_overlap(DRW_MeshCDMask a, DRW_MeshCDMask b) { @@ -562,14 +659,8 @@ static void mesh_batch_cache_discard_shaded_tri(MeshBatchCache *cache) GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.vcol); GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.orco); } - /* Discard batches using vbo.uv. */ - GPU_BATCH_DISCARD_SAFE(cache->batch.edituv_faces); - GPU_BATCH_DISCARD_SAFE(cache->batch.edituv_faces_stretch_area); - GPU_BATCH_DISCARD_SAFE(cache->batch.edituv_faces_stretch_angle); - GPU_BATCH_DISCARD_SAFE(cache->batch.edituv_edges); - GPU_BATCH_DISCARD_SAFE(cache->batch.edituv_verts); - - mesh_batch_cache_discard_surface_batches(cache); + DRWBatchFlag batch_map = MDEPS_CREATE_MAP(vbo_uv, vbo_tan, vbo_vcol, vbo_orco); + mesh_batch_cache_discard_batch(cache, batch_map); mesh_cd_layers_type_clear(&cache->cd_used); } @@ -587,13 +678,17 @@ static void mesh_batch_cache_discard_uvedit(MeshBatchCache *cache) GPU_INDEXBUF_DISCARD_SAFE(mbufcache->ibo.edituv_points); GPU_INDEXBUF_DISCARD_SAFE(mbufcache->ibo.edituv_fdots); } - GPU_BATCH_DISCARD_SAFE(cache->batch.edituv_faces_stretch_area); - GPU_BATCH_DISCARD_SAFE(cache->batch.edituv_faces_stretch_angle); - GPU_BATCH_DISCARD_SAFE(cache->batch.edituv_faces); - GPU_BATCH_DISCARD_SAFE(cache->batch.edituv_edges); - GPU_BATCH_DISCARD_SAFE(cache->batch.edituv_verts); - GPU_BATCH_DISCARD_SAFE(cache->batch.edituv_fdots); - GPU_BATCH_DISCARD_SAFE(cache->batch.wire_loops_uvs); + DRWBatchFlag batch_map = MDEPS_CREATE_MAP(vbo_edituv_stretch_angle, + vbo_edituv_stretch_area, + vbo_uv, + vbo_edituv_data, + vbo_fdots_uv, + vbo_fdots_edituv_data, + ibo_edituv_tris, + ibo_edituv_lines, + ibo_edituv_points, + ibo_edituv_fdots); + mesh_batch_cache_discard_batch(cache, batch_map); cache->tot_area = 0.0f; cache->tot_uv_area = 0.0f; @@ -603,9 +698,6 @@ static void mesh_batch_cache_discard_uvedit(MeshBatchCache *cache) /* We discarded the vbo.uv so we need to reset the cd_used flag. */ cache->cd_used.uv = 0; cache->cd_used.edit_uv = 0; - - /* Discard other batches that uses vbo.uv */ - mesh_batch_cache_discard_surface_batches(cache); } static void mesh_batch_cache_discard_uvedit_select(MeshBatchCache *cache) @@ -618,14 +710,13 @@ static void mesh_batch_cache_discard_uvedit_select(MeshBatchCache *cache) GPU_INDEXBUF_DISCARD_SAFE(mbufcache->ibo.edituv_points); GPU_INDEXBUF_DISCARD_SAFE(mbufcache->ibo.edituv_fdots); } - GPU_BATCH_DISCARD_SAFE(cache->batch.edituv_faces_stretch_area); - GPU_BATCH_DISCARD_SAFE(cache->batch.edituv_faces_stretch_angle); - GPU_BATCH_DISCARD_SAFE(cache->batch.edituv_faces); - GPU_BATCH_DISCARD_SAFE(cache->batch.edituv_edges); - GPU_BATCH_DISCARD_SAFE(cache->batch.edituv_verts); - GPU_BATCH_DISCARD_SAFE(cache->batch.edituv_fdots); - GPU_BATCH_DISCARD_SAFE(cache->batch.wire_loops_uvs); - cache->batch_ready &= ~MBC_EDITUV; + DRWBatchFlag batch_map = MDEPS_CREATE_MAP(vbo_edituv_data, + vbo_fdots_edituv_data, + ibo_edituv_tris, + ibo_edituv_lines, + ibo_edituv_points, + ibo_edituv_fdots); + mesh_batch_cache_discard_batch(cache, batch_map); } void DRW_mesh_batch_cache_dirty_tag(Mesh *me, eMeshBatchDirtyMode mode) @@ -634,25 +725,16 @@ void DRW_mesh_batch_cache_dirty_tag(Mesh *me, eMeshBatchDirtyMode mode) if (cache == NULL) { return; } + DRWBatchFlag batch_map; switch (mode) { case BKE_MESH_BATCH_DIRTY_SELECT: FOREACH_MESH_BUFFER_CACHE (cache, mbufcache) { GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.edit_data); GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.fdots_nor); } - GPU_BATCH_DISCARD_SAFE(cache->batch.edit_triangles); - GPU_BATCH_DISCARD_SAFE(cache->batch.edit_vertices); - GPU_BATCH_DISCARD_SAFE(cache->batch.edit_edges); - GPU_BATCH_DISCARD_SAFE(cache->batch.edit_fdots); - GPU_BATCH_DISCARD_SAFE(cache->batch.edit_selection_verts); - GPU_BATCH_DISCARD_SAFE(cache->batch.edit_selection_edges); - GPU_BATCH_DISCARD_SAFE(cache->batch.edit_selection_faces); - GPU_BATCH_DISCARD_SAFE(cache->batch.edit_selection_fdots); - GPU_BATCH_DISCARD_SAFE(cache->batch.edit_mesh_analysis); - cache->batch_ready &= ~(MBC_EDIT_TRIANGLES | MBC_EDIT_VERTICES | MBC_EDIT_EDGES | - MBC_EDIT_FACEDOTS | MBC_EDIT_SELECTION_FACEDOTS | - MBC_EDIT_SELECTION_FACES | MBC_EDIT_SELECTION_EDGES | - MBC_EDIT_SELECTION_VERTS | MBC_EDIT_MESH_ANALYSIS); + batch_map = MDEPS_CREATE_MAP(vbo_edit_data, vbo_fdots_nor); + mesh_batch_cache_discard_batch(cache, batch_map); + /* Because visible UVs depends on edit mode selection, discard topology. */ mesh_batch_cache_discard_uvedit_select(cache); break; @@ -664,20 +746,8 @@ void DRW_mesh_batch_cache_dirty_tag(Mesh *me, eMeshBatchDirtyMode mode) GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.pos_nor); GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.lnor); } - GPU_BATCH_DISCARD_SAFE(cache->batch.surface); - /* Discard batches using vbo.pos_nor. */ - GPU_BATCH_DISCARD_SAFE(cache->batch.wire_loops); - GPU_BATCH_DISCARD_SAFE(cache->batch.wire_edges); - GPU_BATCH_DISCARD_SAFE(cache->batch.all_verts); - GPU_BATCH_DISCARD_SAFE(cache->batch.all_edges); - GPU_BATCH_DISCARD_SAFE(cache->batch.loose_edges); - GPU_BATCH_DISCARD_SAFE(cache->batch.edge_detection); - GPU_BATCH_DISCARD_SAFE(cache->batch.surface_weights); - GPU_BATCH_DISCARD_SAFE(cache->batch.edit_mesh_analysis); - /* Discard batches using vbo.lnor. */ - GPU_BATCH_DISCARD_SAFE(cache->batch.edit_lnor); - mesh_batch_cache_discard_surface_batches(cache); - cache->batch_ready &= ~(MBC_SURFACE | MBC_WIRE_EDGES | MBC_WIRE_LOOPS); + batch_map = MDEPS_CREATE_MAP(ibo_lines_paint_mask, vbo_pos_nor, vbo_lnor); + mesh_batch_cache_discard_batch(cache, batch_map); break; case BKE_MESH_BATCH_DIRTY_ALL: cache->is_dirty = true; @@ -694,13 +764,8 @@ void DRW_mesh_batch_cache_dirty_tag(Mesh *me, eMeshBatchDirtyMode mode) GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.edituv_data); GPU_VERTBUF_DISCARD_SAFE(mbufcache->vbo.fdots_edituv_data); } - GPU_BATCH_DISCARD_SAFE(cache->batch.edituv_faces_stretch_area); - GPU_BATCH_DISCARD_SAFE(cache->batch.edituv_faces_stretch_angle); - GPU_BATCH_DISCARD_SAFE(cache->batch.edituv_faces); - GPU_BATCH_DISCARD_SAFE(cache->batch.edituv_edges); - GPU_BATCH_DISCARD_SAFE(cache->batch.edituv_verts); - GPU_BATCH_DISCARD_SAFE(cache->batch.edituv_fdots); - cache->batch_ready &= ~MBC_EDITUV; + batch_map = MDEPS_CREATE_MAP(vbo_edituv_data, vbo_fdots_edituv_data); + mesh_batch_cache_discard_batch(cache, batch_map); break; default: BLI_assert(0); @@ -1372,6 +1437,7 @@ void DRW_mesh_batch_cache_create_requested(struct TaskGraph *task_graph, MeshBufferCache *mbufcache = &cache->final; /* Initialize batches and request VBO's & IBO's. */ + MDEPS_ASSERT(batch.surface, ibo_tris, vbo_lnor, vbo_pos_nor, vbo_uv, vbo_vcol); if (DRW_batch_requested(cache->batch.surface, GPU_PRIM_TRIS)) { DRW_ibo_request(cache->batch.surface, &mbufcache->ibo.tris); /* Order matters. First ones override latest VBO's attributes. */ @@ -1384,43 +1450,52 @@ void DRW_mesh_batch_cache_create_requested(struct TaskGraph *task_graph, DRW_vbo_request(cache->batch.surface, &mbufcache->vbo.vcol); } } + MDEPS_ASSERT(batch.all_verts, vbo_pos_nor); if (DRW_batch_requested(cache->batch.all_verts, GPU_PRIM_POINTS)) { DRW_vbo_request(cache->batch.all_verts, &mbufcache->vbo.pos_nor); } + MDEPS_ASSERT(batch.sculpt_overlays, ibo_tris, vbo_pos_nor, vbo_sculpt_data); if (DRW_batch_requested(cache->batch.sculpt_overlays, GPU_PRIM_TRIS)) { DRW_ibo_request(cache->batch.sculpt_overlays, &mbufcache->ibo.tris); DRW_vbo_request(cache->batch.sculpt_overlays, &mbufcache->vbo.pos_nor); DRW_vbo_request(cache->batch.sculpt_overlays, &mbufcache->vbo.sculpt_data); } + MDEPS_ASSERT(batch.all_edges, ibo_lines, vbo_pos_nor); if (DRW_batch_requested(cache->batch.all_edges, GPU_PRIM_LINES)) { DRW_ibo_request(cache->batch.all_edges, &mbufcache->ibo.lines); DRW_vbo_request(cache->batch.all_edges, &mbufcache->vbo.pos_nor); } + MDEPS_ASSERT(batch.loose_edges, ibo_lines_loose, vbo_pos_nor); if (DRW_batch_requested(cache->batch.loose_edges, GPU_PRIM_LINES)) { DRW_ibo_request(NULL, &mbufcache->ibo.lines); DRW_ibo_request(cache->batch.loose_edges, &mbufcache->ibo.lines_loose); DRW_vbo_request(cache->batch.loose_edges, &mbufcache->vbo.pos_nor); } + MDEPS_ASSERT(batch.edge_detection, ibo_lines_adjacency, vbo_pos_nor); if (DRW_batch_requested(cache->batch.edge_detection, GPU_PRIM_LINES_ADJ)) { DRW_ibo_request(cache->batch.edge_detection, &mbufcache->ibo.lines_adjacency); DRW_vbo_request(cache->batch.edge_detection, &mbufcache->vbo.pos_nor); } + MDEPS_ASSERT(batch.surface_weights, ibo_tris, vbo_pos_nor, vbo_weights); if (DRW_batch_requested(cache->batch.surface_weights, GPU_PRIM_TRIS)) { DRW_ibo_request(cache->batch.surface_weights, &mbufcache->ibo.tris); DRW_vbo_request(cache->batch.surface_weights, &mbufcache->vbo.pos_nor); DRW_vbo_request(cache->batch.surface_weights, &mbufcache->vbo.weights); } + MDEPS_ASSERT(batch.wire_loops, ibo_lines_paint_mask, vbo_lnor, vbo_pos_nor); if (DRW_batch_requested(cache->batch.wire_loops, GPU_PRIM_LINES)) { DRW_ibo_request(cache->batch.wire_loops, &mbufcache->ibo.lines_paint_mask); /* Order matters. First ones override latest VBO's attributes. */ DRW_vbo_request(cache->batch.wire_loops, &mbufcache->vbo.lnor); DRW_vbo_request(cache->batch.wire_loops, &mbufcache->vbo.pos_nor); } + MDEPS_ASSERT(batch.wire_edges, ibo_lines, vbo_pos_nor, vbo_edge_fac); if (DRW_batch_requested(cache->batch.wire_edges, GPU_PRIM_LINES)) { DRW_ibo_request(cache->batch.wire_edges, &mbufcache->ibo.lines); DRW_vbo_request(cache->batch.wire_edges, &mbufcache->vbo.pos_nor); DRW_vbo_request(cache->batch.wire_edges, &mbufcache->vbo.edge_fac); } + MDEPS_ASSERT(batch.wire_loops_uvs, ibo_edituv_lines, vbo_uv); if (DRW_batch_requested(cache->batch.wire_loops_uvs, GPU_PRIM_LINES)) { DRW_ibo_request(cache->batch.wire_loops_uvs, &mbufcache->ibo.edituv_lines); /* For paint overlay. Active layer should have been queried. */ @@ -1428,6 +1503,7 @@ void DRW_mesh_batch_cache_create_requested(struct TaskGraph *task_graph, DRW_vbo_request(cache->batch.wire_loops_uvs, &mbufcache->vbo.uv); } } + MDEPS_ASSERT(batch.edit_mesh_analysis, ibo_tris, vbo_pos_nor, vbo_mesh_analysis); if (DRW_batch_requested(cache->batch.edit_mesh_analysis, GPU_PRIM_TRIS)) { DRW_ibo_request(cache->batch.edit_mesh_analysis, &mbufcache->ibo.tris); DRW_vbo_request(cache->batch.edit_mesh_analysis, &mbufcache->vbo.pos_nor); @@ -1435,6 +1511,14 @@ void DRW_mesh_batch_cache_create_requested(struct TaskGraph *task_graph, } /* Per Material */ + MDEPS_ASSERT(surface_per_mat, + ibo_tris_per_mat, + vbo_lnor, + vbo_pos_nor, + vbo_uv, + vbo_tan, + vbo_vcol, + vbo_orco); for (int i = 0; i < cache->mat_len; i++) { if (DRW_batch_requested(cache->surface_per_mat[i], GPU_PRIM_TRIS)) { DRW_ibo_request(cache->surface_per_mat[i], &mbufcache->tris_per_mat[i]); @@ -1459,55 +1543,66 @@ void DRW_mesh_batch_cache_create_requested(struct TaskGraph *task_graph, mbufcache = (do_cage) ? &cache->cage : &cache->final; /* Edit Mesh */ + MDEPS_ASSERT(batch.edit_triangles, ibo_tris, vbo_pos_nor, vbo_edit_data); if (DRW_batch_requested(cache->batch.edit_triangles, GPU_PRIM_TRIS)) { DRW_ibo_request(cache->batch.edit_triangles, &mbufcache->ibo.tris); DRW_vbo_request(cache->batch.edit_triangles, &mbufcache->vbo.pos_nor); DRW_vbo_request(cache->batch.edit_triangles, &mbufcache->vbo.edit_data); } + MDEPS_ASSERT(batch.edit_vertices, ibo_points, vbo_pos_nor, vbo_edit_data); if (DRW_batch_requested(cache->batch.edit_vertices, GPU_PRIM_POINTS)) { DRW_ibo_request(cache->batch.edit_vertices, &mbufcache->ibo.points); DRW_vbo_request(cache->batch.edit_vertices, &mbufcache->vbo.pos_nor); DRW_vbo_request(cache->batch.edit_vertices, &mbufcache->vbo.edit_data); } + MDEPS_ASSERT(batch.edit_edges, ibo_lines, vbo_pos_nor, vbo_edit_data); if (DRW_batch_requested(cache->batch.edit_edges, GPU_PRIM_LINES)) { DRW_ibo_request(cache->batch.edit_edges, &mbufcache->ibo.lines); DRW_vbo_request(cache->batch.edit_edges, &mbufcache->vbo.pos_nor); DRW_vbo_request(cache->batch.edit_edges, &mbufcache->vbo.edit_data); } + MDEPS_ASSERT(batch.edit_vnor, ibo_points, vbo_pos_nor); if (DRW_batch_requested(cache->batch.edit_vnor, GPU_PRIM_POINTS)) { DRW_ibo_request(cache->batch.edit_vnor, &mbufcache->ibo.points); DRW_vbo_request(cache->batch.edit_vnor, &mbufcache->vbo.pos_nor); } + MDEPS_ASSERT(batch.edit_lnor, ibo_tris, vbo_pos_nor, vbo_lnor); if (DRW_batch_requested(cache->batch.edit_lnor, GPU_PRIM_POINTS)) { DRW_ibo_request(cache->batch.edit_lnor, &mbufcache->ibo.tris); DRW_vbo_request(cache->batch.edit_lnor, &mbufcache->vbo.pos_nor); DRW_vbo_request(cache->batch.edit_lnor, &mbufcache->vbo.lnor); } + MDEPS_ASSERT(batch.edit_fdots, ibo_fdots, vbo_fdots_pos, vbo_fdots_nor); if (DRW_batch_requested(cache->batch.edit_fdots, GPU_PRIM_POINTS)) { DRW_ibo_request(cache->batch.edit_fdots, &mbufcache->ibo.fdots); DRW_vbo_request(cache->batch.edit_fdots, &mbufcache->vbo.fdots_pos); DRW_vbo_request(cache->batch.edit_fdots, &mbufcache->vbo.fdots_nor); } + MDEPS_ASSERT(batch.edit_skin_roots, vbo_skin_roots); if (DRW_batch_requested(cache->batch.edit_skin_roots, GPU_PRIM_POINTS)) { DRW_vbo_request(cache->batch.edit_skin_roots, &mbufcache->vbo.skin_roots); } /* Selection */ + MDEPS_ASSERT(batch.edit_selection_verts, ibo_points, vbo_pos_nor, vbo_vert_idx); if (DRW_batch_requested(cache->batch.edit_selection_verts, GPU_PRIM_POINTS)) { DRW_ibo_request(cache->batch.edit_selection_verts, &mbufcache->ibo.points); DRW_vbo_request(cache->batch.edit_selection_verts, &mbufcache->vbo.pos_nor); DRW_vbo_request(cache->batch.edit_selection_verts, &mbufcache->vbo.vert_idx); } + MDEPS_ASSERT(batch.edit_selection_edges, ibo_lines, vbo_pos_nor, vbo_edge_idx); if (DRW_batch_requested(cache->batch.edit_selection_edges, GPU_PRIM_LINES)) { DRW_ibo_request(cache->batch.edit_selection_edges, &mbufcache->ibo.lines); DRW_vbo_request(cache->batch.edit_selection_edges, &mbufcache->vbo.pos_nor); DRW_vbo_request(cache->batch.edit_selection_edges, &mbufcache->vbo.edge_idx); } + MDEPS_ASSERT(batch.edit_selection_faces, ibo_tris, vbo_pos_nor, vbo_poly_idx); if (DRW_batch_requested(cache->batch.edit_selection_faces, GPU_PRIM_TRIS)) { DRW_ibo_request(cache->batch.edit_selection_faces, &mbufcache->ibo.tris); DRW_vbo_request(cache->batch.edit_selection_faces, &mbufcache->vbo.pos_nor); DRW_vbo_request(cache->batch.edit_selection_faces, &mbufcache->vbo.poly_idx); } + MDEPS_ASSERT(batch.edit_selection_fdots, ibo_fdots, vbo_fdots_pos, vbo_fdot_idx); if (DRW_batch_requested(cache->batch.edit_selection_fdots, GPU_PRIM_POINTS)) { DRW_ibo_request(cache->batch.edit_selection_fdots, &mbufcache->ibo.fdots); DRW_vbo_request(cache->batch.edit_selection_fdots, &mbufcache->vbo.fdots_pos); @@ -1522,39 +1617,90 @@ void DRW_mesh_batch_cache_create_requested(struct TaskGraph *task_graph, mbufcache = (do_uvcage) ? &cache->uv_cage : &cache->final; /* Edit UV */ + MDEPS_ASSERT(batch.edituv_faces, ibo_edituv_tris, vbo_uv, vbo_edituv_data); if (DRW_batch_requested(cache->batch.edituv_faces, GPU_PRIM_TRIS)) { DRW_ibo_request(cache->batch.edituv_faces, &mbufcache->ibo.edituv_tris); DRW_vbo_request(cache->batch.edituv_faces, &mbufcache->vbo.uv); DRW_vbo_request(cache->batch.edituv_faces, &mbufcache->vbo.edituv_data); } + MDEPS_ASSERT(batch.edituv_faces_stretch_area, + ibo_edituv_tris, + vbo_uv, + vbo_edituv_data, + vbo_edituv_stretch_area); if (DRW_batch_requested(cache->batch.edituv_faces_stretch_area, GPU_PRIM_TRIS)) { DRW_ibo_request(cache->batch.edituv_faces_stretch_area, &mbufcache->ibo.edituv_tris); DRW_vbo_request(cache->batch.edituv_faces_stretch_area, &mbufcache->vbo.uv); DRW_vbo_request(cache->batch.edituv_faces_stretch_area, &mbufcache->vbo.edituv_data); DRW_vbo_request(cache->batch.edituv_faces_stretch_area, &mbufcache->vbo.edituv_stretch_area); } + MDEPS_ASSERT(batch.edituv_faces_stretch_angle, + ibo_edituv_tris, + vbo_uv, + vbo_edituv_data, + vbo_edituv_stretch_angle); if (DRW_batch_requested(cache->batch.edituv_faces_stretch_angle, GPU_PRIM_TRIS)) { DRW_ibo_request(cache->batch.edituv_faces_stretch_angle, &mbufcache->ibo.edituv_tris); DRW_vbo_request(cache->batch.edituv_faces_stretch_angle, &mbufcache->vbo.uv); DRW_vbo_request(cache->batch.edituv_faces_stretch_angle, &mbufcache->vbo.edituv_data); DRW_vbo_request(cache->batch.edituv_faces_stretch_angle, &mbufcache->vbo.edituv_stretch_angle); } + MDEPS_ASSERT(batch.edituv_edges, ibo_edituv_lines, vbo_uv, vbo_edituv_data); if (DRW_batch_requested(cache->batch.edituv_edges, GPU_PRIM_LINES)) { DRW_ibo_request(cache->batch.edituv_edges, &mbufcache->ibo.edituv_lines); DRW_vbo_request(cache->batch.edituv_edges, &mbufcache->vbo.uv); DRW_vbo_request(cache->batch.edituv_edges, &mbufcache->vbo.edituv_data); } + MDEPS_ASSERT(batch.edituv_verts, ibo_edituv_points, vbo_uv, vbo_edituv_data); if (DRW_batch_requested(cache->batch.edituv_verts, GPU_PRIM_POINTS)) { DRW_ibo_request(cache->batch.edituv_verts, &mbufcache->ibo.edituv_points); DRW_vbo_request(cache->batch.edituv_verts, &mbufcache->vbo.uv); DRW_vbo_request(cache->batch.edituv_verts, &mbufcache->vbo.edituv_data); } + MDEPS_ASSERT(batch.edituv_fdots, ibo_edituv_fdots, vbo_fdots_uv, vbo_fdots_edituv_data); if (DRW_batch_requested(cache->batch.edituv_fdots, GPU_PRIM_POINTS)) { DRW_ibo_request(cache->batch.edituv_fdots, &mbufcache->ibo.edituv_fdots); DRW_vbo_request(cache->batch.edituv_fdots, &mbufcache->vbo.fdots_uv); DRW_vbo_request(cache->batch.edituv_fdots, &mbufcache->vbo.fdots_edituv_data); } + MDEPS_ASSERT_MAP(vbo_lnor); + MDEPS_ASSERT_MAP(vbo_pos_nor); + MDEPS_ASSERT_MAP(vbo_uv); + MDEPS_ASSERT_MAP(vbo_vcol); + MDEPS_ASSERT_MAP(vbo_sculpt_data); + MDEPS_ASSERT_MAP(vbo_weights); + MDEPS_ASSERT_MAP(vbo_edge_fac); + MDEPS_ASSERT_MAP(vbo_mesh_analysis); + MDEPS_ASSERT_MAP(vbo_tan); + MDEPS_ASSERT_MAP(vbo_orco); + MDEPS_ASSERT_MAP(vbo_edit_data); + MDEPS_ASSERT_MAP(vbo_fdots_pos); + MDEPS_ASSERT_MAP(vbo_fdots_nor); + MDEPS_ASSERT_MAP(vbo_skin_roots); + MDEPS_ASSERT_MAP(vbo_vert_idx); + MDEPS_ASSERT_MAP(vbo_edge_idx); + MDEPS_ASSERT_MAP(vbo_poly_idx); + MDEPS_ASSERT_MAP(vbo_fdot_idx); + MDEPS_ASSERT_MAP(vbo_edituv_data); + MDEPS_ASSERT_MAP(vbo_edituv_stretch_area); + MDEPS_ASSERT_MAP(vbo_edituv_stretch_angle); + MDEPS_ASSERT_MAP(vbo_fdots_uv); + MDEPS_ASSERT_MAP(vbo_fdots_edituv_data); + + MDEPS_ASSERT_MAP(ibo_tris); + MDEPS_ASSERT_MAP(ibo_lines); + MDEPS_ASSERT_MAP(ibo_lines_loose); + MDEPS_ASSERT_MAP(ibo_lines_adjacency); + MDEPS_ASSERT_MAP(ibo_lines_paint_mask); + MDEPS_ASSERT_MAP(ibo_tris_per_mat); + MDEPS_ASSERT_MAP(ibo_points); + MDEPS_ASSERT_MAP(ibo_fdots); + MDEPS_ASSERT_MAP(ibo_edituv_tris); + MDEPS_ASSERT_MAP(ibo_edituv_lines); + MDEPS_ASSERT_MAP(ibo_edituv_points); + MDEPS_ASSERT_MAP(ibo_edituv_fdots); + /* Meh loose Scene const correctness here. */ const bool use_subsurf_fdots = scene ? BKE_modifiers_uses_subsurf_facedots(scene, ob) : false; |