diff options
author | Joseph Eagar <joeedh@gmail.com> | 2022-09-29 00:51:23 +0300 |
---|---|---|
committer | Joseph Eagar <joeedh@gmail.com> | 2022-09-29 00:51:23 +0300 |
commit | 65900d88a8317c207885ae4a3993272112114f36 (patch) | |
tree | f5ec12e068ab8f2ee36af384060e59de72ecc08f /source/blender/draw/engines | |
parent | a790873d2a811e0c244266b090d92470cf378ef2 (diff) |
Sculpt: Rewrite PBVH draw
Rewrite PBVH draw to allocate attributes into individual VBOs.
The old system tried to create a single VBO that could feed
every open viewport. This required uploading every color and
UV attribute to the viewport whether needed or not, often exceeding
the VBO limit.
This new system creates one VBO per attribute. Each attribute layout is
given its own GPU batch which is cached inside the owning PBVH node.
Notes:
* This is a full C++ rewrite. The old code is still there; ripping it out
can happen later.
* PBVH nodes now have a collection of batches, PBVHBatches, that keeps
track of all the batches inside the node.
* Batches are built exclusively from a list of attributes.
* Each attribute has its own VBO.
* Overlays, workbench and EEVEE can all have different attribute
layouts, each of which will get its own batch.
Reviewed by: Clement Foucault
Differential Revision: https://developer.blender.org/D15428
Ref D15428
Diffstat (limited to 'source/blender/draw/engines')
8 files changed, 18 insertions, 11 deletions
diff --git a/source/blender/draw/engines/basic/basic_engine.c b/source/blender/draw/engines/basic/basic_engine.c index 975d9e299bf..86c565371c1 100644 --- a/source/blender/draw/engines/basic/basic_engine.c +++ b/source/blender/draw/engines/basic/basic_engine.c @@ -199,7 +199,7 @@ static void basic_cache_populate(void *vedata, Object *ob) } if (use_sculpt_pbvh) { - DRW_shgroup_call_sculpt(shgrp, ob, false, false); + DRW_shgroup_call_sculpt(shgrp, ob, false, false, false, false, false); } else { if (stl->g_data->use_material_slot_selection && BKE_object_supports_material_slots(ob)) { diff --git a/source/blender/draw/engines/eevee/eevee_materials.c b/source/blender/draw/engines/eevee/eevee_materials.c index 94f29d64628..1cb630e6d59 100644 --- a/source/blender/draw/engines/eevee/eevee_materials.c +++ b/source/blender/draw/engines/eevee/eevee_materials.c @@ -824,14 +824,17 @@ void EEVEE_materials_cache_populate(EEVEE_Data *vedata, if (use_sculpt_pbvh) { struct DRWShadingGroup **shgrps_array = BLI_array_alloca(shgrps_array, materials_len); + struct GPUMaterial **gpumat_array = BLI_array_alloca(gpumat_array, materials_len); + MATCACHE_AS_ARRAY(matcache, shading_gpumat, materials_len, gpumat_array); + MATCACHE_AS_ARRAY(matcache, shading_grp, materials_len, shgrps_array); - DRW_shgroup_call_sculpt_with_materials(shgrps_array, materials_len, ob); + DRW_shgroup_call_sculpt_with_materials(shgrps_array, gpumat_array, materials_len, ob); MATCACHE_AS_ARRAY(matcache, depth_grp, materials_len, shgrps_array); - DRW_shgroup_call_sculpt_with_materials(shgrps_array, materials_len, ob); + DRW_shgroup_call_sculpt_with_materials(shgrps_array, gpumat_array, materials_len, ob); MATCACHE_AS_ARRAY(matcache, shadow_grp, materials_len, shgrps_array); - DRW_shgroup_call_sculpt_with_materials(shgrps_array, materials_len, ob); + DRW_shgroup_call_sculpt_with_materials(shgrps_array, gpumat_array, materials_len, ob); } else { struct GPUMaterial **gpumat_array = BLI_array_alloca(gpumat_array, materials_len); diff --git a/source/blender/draw/engines/overlay/overlay_facing.cc b/source/blender/draw/engines/overlay/overlay_facing.cc index 9a501c8f1bb..e40c32b30fc 100644 --- a/source/blender/draw/engines/overlay/overlay_facing.cc +++ b/source/blender/draw/engines/overlay/overlay_facing.cc @@ -48,7 +48,7 @@ void OVERLAY_facing_cache_populate(OVERLAY_Data *vedata, Object *ob) const bool is_xray = (ob->dtx & OB_DRAW_IN_FRONT) != 0; if (use_sculpt_pbvh) { - DRW_shgroup_call_sculpt(pd->facing_grp[is_xray], ob, false, false); + DRW_shgroup_call_sculpt(pd->facing_grp[is_xray], ob, false, false, false, false, false); } else { struct GPUBatch *geom = DRW_cache_object_surface_get(ob); diff --git a/source/blender/draw/engines/overlay/overlay_fade.cc b/source/blender/draw/engines/overlay/overlay_fade.cc index ee5540d91eb..f99e77b75f2 100644 --- a/source/blender/draw/engines/overlay/overlay_fade.cc +++ b/source/blender/draw/engines/overlay/overlay_fade.cc @@ -58,7 +58,7 @@ void OVERLAY_fade_cache_populate(OVERLAY_Data *vedata, Object *ob) const bool is_xray = (ob->dtx & OB_DRAW_IN_FRONT) != 0; if (use_sculpt_pbvh) { - DRW_shgroup_call_sculpt(pd->fade_grp[is_xray], ob, false, false); + DRW_shgroup_call_sculpt(pd->fade_grp[is_xray], ob, false, false, false, false, false); } else { struct GPUBatch *geom = DRW_cache_object_surface_get(ob); diff --git a/source/blender/draw/engines/overlay/overlay_mode_transfer.cc b/source/blender/draw/engines/overlay/overlay_mode_transfer.cc index b312a12a07b..5222abfc743 100644 --- a/source/blender/draw/engines/overlay/overlay_mode_transfer.cc +++ b/source/blender/draw/engines/overlay/overlay_mode_transfer.cc @@ -110,7 +110,7 @@ void OVERLAY_mode_transfer_cache_populate(OVERLAY_Data *vedata, Object *ob) pd->mode_transfer.any_animated = true; if (use_sculpt_pbvh) { - DRW_shgroup_call_sculpt(mode_transfer_grp[is_xray], ob, false, false); + DRW_shgroup_call_sculpt(mode_transfer_grp[is_xray], ob, false, false, false, false, false); } else { struct GPUBatch *geom = DRW_cache_object_surface_get(ob); diff --git a/source/blender/draw/engines/overlay/overlay_sculpt.cc b/source/blender/draw/engines/overlay/overlay_sculpt.cc index ddad1f06537..8f142d68350 100644 --- a/source/blender/draw/engines/overlay/overlay_sculpt.cc +++ b/source/blender/draw/engines/overlay/overlay_sculpt.cc @@ -53,7 +53,7 @@ void OVERLAY_sculpt_cache_populate(OVERLAY_Data *vedata, Object *ob) } if (use_pbvh) { - DRW_shgroup_call_sculpt(pd->sculpt_mask_grp, ob, false, true); + DRW_shgroup_call_sculpt(pd->sculpt_mask_grp, ob, false, true, true, false, false); } else { sculpt_overlays = DRW_mesh_batch_cache_get_sculpt_overlays(static_cast<Mesh *>(ob->data)); diff --git a/source/blender/draw/engines/overlay/overlay_wireframe.cc b/source/blender/draw/engines/overlay/overlay_wireframe.cc index edaa96651b2..bff1bf46923 100644 --- a/source/blender/draw/engines/overlay/overlay_wireframe.cc +++ b/source/blender/draw/engines/overlay/overlay_wireframe.cc @@ -302,7 +302,7 @@ void OVERLAY_wireframe_cache_populate(OVERLAY_Data *vedata, DRW_shgroup_call_no_cull(shgrp, geom, ob); } else if (use_sculpt_pbvh) { - DRW_shgroup_call_sculpt(shgrp, ob, true, false); + DRW_shgroup_call_sculpt(shgrp, ob, true, false, false, false, false); } else { DRW_shgroup_call(shgrp, geom, ob); diff --git a/source/blender/draw/engines/workbench/workbench_engine.c b/source/blender/draw/engines/workbench/workbench_engine.c index ee9521289d9..36a980bd506 100644 --- a/source/blender/draw/engines/workbench/workbench_engine.c +++ b/source/blender/draw/engines/workbench/workbench_engine.c @@ -102,7 +102,11 @@ static void workbench_cache_sculpt_populate(WORKBENCH_PrivateData *wpd, const bool use_single_drawcall = !ELEM(color_type, V3D_SHADING_MATERIAL_COLOR); if (use_single_drawcall) { DRWShadingGroup *grp = workbench_material_setup(wpd, ob, ob->actcol, color_type, NULL); - DRW_shgroup_call_sculpt(grp, ob, false, false); + + bool use_color = color_type == V3D_SHADING_VERTEX_COLOR; + bool use_uv = color_type == V3D_SHADING_TEXTURE_COLOR; + + DRW_shgroup_call_sculpt(grp, ob, false, false, false, use_color, use_uv); } else { const int materials_len = DRW_cache_object_material_count_get(ob); @@ -110,7 +114,7 @@ static void workbench_cache_sculpt_populate(WORKBENCH_PrivateData *wpd, for (int i = 0; i < materials_len; i++) { shgrps[i] = workbench_material_setup(wpd, ob, i + 1, color_type, NULL); } - DRW_shgroup_call_sculpt_with_materials(shgrps, materials_len, ob); + DRW_shgroup_call_sculpt_with_materials(shgrps, NULL, materials_len, ob); } } |