Cleanup: Use Span for GPU batch array
Pull Request: https://projects.blender.org/blender/blender/pulls/132464
This commit is contained in:
@@ -106,10 +106,9 @@ void SyncModule::sync_mesh(Object *ob, ObjectHandle &ob_handle, const ObjectRef
|
||||
|
||||
MaterialArray &material_array = inst_.materials.material_array_get(ob, has_motion);
|
||||
|
||||
gpu::Batch **mat_geom = DRW_cache_object_surface_material_get(
|
||||
ob, material_array.gpu_materials.data(), material_array.gpu_materials.size());
|
||||
|
||||
if (mat_geom == nullptr) {
|
||||
Span<gpu::Batch *> mat_geom = DRW_cache_object_surface_material_get(
|
||||
ob, material_array.gpu_materials);
|
||||
if (mat_geom.is_empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -204,13 +204,8 @@ class Prepass : Overlay {
|
||||
if (use_material_slot_selection_) {
|
||||
/* TODO(fclem): Improve the API. */
|
||||
const int materials_len = DRW_cache_object_material_count_get(ob_ref.object);
|
||||
Array<GPUMaterial *> materials(materials_len);
|
||||
materials.fill(nullptr);
|
||||
|
||||
gpu::Batch **geom_per_mat = DRW_cache_mesh_surface_shaded_get(
|
||||
ob_ref.object, materials.data(), materials_len);
|
||||
|
||||
geom_list = {geom_per_mat, materials_len};
|
||||
Array<GPUMaterial *> materials(materials_len, nullptr);
|
||||
geom_list = DRW_cache_mesh_surface_shaded_get(ob_ref.object, materials);
|
||||
}
|
||||
else {
|
||||
geom_single = DRW_cache_mesh_surface_get(ob_ref.object);
|
||||
|
||||
@@ -50,12 +50,12 @@ class Instance {
|
||||
Vector<GPUMaterial *> dummy_gpu_materials_ = {1, nullptr, {}};
|
||||
|
||||
public:
|
||||
GPUMaterial **get_dummy_gpu_materials(int material_count)
|
||||
Span<const GPUMaterial *> get_dummy_gpu_materials(int material_count)
|
||||
{
|
||||
if (material_count > dummy_gpu_materials_.size()) {
|
||||
dummy_gpu_materials_.resize(material_count, nullptr);
|
||||
}
|
||||
return dummy_gpu_materials_.begin();
|
||||
return dummy_gpu_materials_;
|
||||
};
|
||||
|
||||
void init(Object *camera_ob = nullptr)
|
||||
@@ -248,16 +248,16 @@ class Instance {
|
||||
if (object_state.use_per_material_batches) {
|
||||
const int material_count = DRW_cache_object_material_count_get(ob_ref.object);
|
||||
|
||||
gpu::Batch **batches;
|
||||
Span<gpu::Batch *> batches;
|
||||
if (object_state.color_type == V3D_SHADING_TEXTURE_COLOR) {
|
||||
batches = DRW_cache_mesh_surface_texpaint_get(ob_ref.object);
|
||||
}
|
||||
else {
|
||||
batches = DRW_cache_object_surface_material_get(
|
||||
ob_ref.object, this->get_dummy_gpu_materials(material_count), material_count);
|
||||
ob_ref.object, this->get_dummy_gpu_materials(material_count));
|
||||
}
|
||||
|
||||
if (batches) {
|
||||
if (!batches.is_empty()) {
|
||||
for (auto i : IndexRange(material_count)) {
|
||||
if (batches[i] == nullptr) {
|
||||
continue;
|
||||
|
||||
@@ -36,6 +36,8 @@
|
||||
#include "draw_cache_impl.hh"
|
||||
#include "draw_manager_c.hh"
|
||||
|
||||
using blender::Span;
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Internal Defines
|
||||
* \{ */
|
||||
@@ -938,15 +940,14 @@ int DRW_cache_object_material_count_get(const Object *ob)
|
||||
return BKE_object_material_count_with_fallback_eval(ob);
|
||||
}
|
||||
|
||||
blender::gpu::Batch **DRW_cache_object_surface_material_get(Object *ob,
|
||||
GPUMaterial **gpumat_array,
|
||||
uint gpumat_array_len)
|
||||
Span<blender::gpu::Batch *> DRW_cache_object_surface_material_get(
|
||||
Object *ob, const Span<const GPUMaterial *> materials)
|
||||
{
|
||||
switch (ob->type) {
|
||||
case OB_MESH:
|
||||
return DRW_cache_mesh_surface_shaded_get(ob, gpumat_array, gpumat_array_len);
|
||||
return DRW_cache_mesh_surface_shaded_get(ob, materials);
|
||||
default:
|
||||
return nullptr;
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2860,17 +2861,15 @@ blender::gpu::Batch *DRW_cache_mesh_surface_edges_get(Object *ob)
|
||||
return DRW_mesh_batch_cache_get_surface_edges(*ob, *static_cast<Mesh *>(ob->data));
|
||||
}
|
||||
|
||||
blender::gpu::Batch **DRW_cache_mesh_surface_shaded_get(Object *ob,
|
||||
GPUMaterial **gpumat_array,
|
||||
uint gpumat_array_len)
|
||||
Span<blender::gpu::Batch *> DRW_cache_mesh_surface_shaded_get(
|
||||
Object *ob, const blender::Span<const GPUMaterial *> materials)
|
||||
{
|
||||
using namespace blender::draw;
|
||||
BLI_assert(ob->type == OB_MESH);
|
||||
return DRW_mesh_batch_cache_get_surface_shaded(
|
||||
*ob, *static_cast<Mesh *>(ob->data), gpumat_array, gpumat_array_len);
|
||||
return DRW_mesh_batch_cache_get_surface_shaded(*ob, *static_cast<Mesh *>(ob->data), materials);
|
||||
}
|
||||
|
||||
blender::gpu::Batch **DRW_cache_mesh_surface_texpaint_get(Object *ob)
|
||||
Span<blender::gpu::Batch *> DRW_cache_mesh_surface_texpaint_get(Object *ob)
|
||||
{
|
||||
using namespace blender::draw;
|
||||
BLI_assert(ob->type == OB_MESH);
|
||||
|
||||
@@ -67,9 +67,8 @@ blender::gpu::Batch *DRW_cache_object_all_edges_get(Object *ob);
|
||||
blender::gpu::Batch *DRW_cache_object_edge_detection_get(Object *ob, bool *r_is_manifold);
|
||||
blender::gpu::Batch *DRW_cache_object_surface_get(Object *ob);
|
||||
blender::gpu::Batch *DRW_cache_object_loose_edges_get(Object *ob);
|
||||
blender::gpu::Batch **DRW_cache_object_surface_material_get(Object *ob,
|
||||
GPUMaterial **gpumat_array,
|
||||
uint gpumat_array_len);
|
||||
blender::Span<blender::gpu::Batch *> DRW_cache_object_surface_material_get(
|
||||
Object *ob, blender::Span<const GPUMaterial *> materials);
|
||||
blender::gpu::Batch *DRW_cache_object_face_wireframe_get(const Scene *scene, Object *ob);
|
||||
int DRW_cache_object_material_count_get(const Object *ob);
|
||||
|
||||
@@ -162,13 +161,12 @@ blender::gpu::Batch *DRW_cache_mesh_surface_edges_get(Object *ob);
|
||||
/**
|
||||
* Return list of batches with length equal to `max(1, totcol)`.
|
||||
*/
|
||||
blender::gpu::Batch **DRW_cache_mesh_surface_shaded_get(Object *ob,
|
||||
GPUMaterial **gpumat_array,
|
||||
uint gpumat_array_len);
|
||||
blender::Span<blender::gpu::Batch *> DRW_cache_mesh_surface_shaded_get(
|
||||
Object *ob, blender::Span<const GPUMaterial *> materials);
|
||||
/**
|
||||
* Return list of batches with length equal to `max(1, totcol)`.
|
||||
*/
|
||||
blender::gpu::Batch **DRW_cache_mesh_surface_texpaint_get(Object *ob);
|
||||
blender::Span<blender::gpu::Batch *> DRW_cache_mesh_surface_texpaint_get(Object *ob);
|
||||
blender::gpu::Batch *DRW_cache_mesh_surface_texpaint_single_get(Object *ob);
|
||||
blender::gpu::Batch *DRW_cache_mesh_surface_vertpaint_get(Object *ob);
|
||||
blender::gpu::Batch *DRW_cache_mesh_surface_sculptcolors_get(Object *ob);
|
||||
|
||||
@@ -183,12 +183,11 @@ blender::gpu::Batch *DRW_mesh_batch_cache_get_loose_edges(Mesh &mesh);
|
||||
blender::gpu::Batch *DRW_mesh_batch_cache_get_edge_detection(Mesh &mesh, bool *r_is_manifold);
|
||||
blender::gpu::Batch *DRW_mesh_batch_cache_get_surface(Mesh &mesh);
|
||||
blender::gpu::Batch *DRW_mesh_batch_cache_get_surface_edges(Object &object, Mesh &mesh);
|
||||
blender::gpu::Batch **DRW_mesh_batch_cache_get_surface_shaded(Object &object,
|
||||
Mesh &mesh,
|
||||
GPUMaterial **gpumat_array,
|
||||
uint gpumat_array_len);
|
||||
Span<gpu::Batch *> DRW_mesh_batch_cache_get_surface_shaded(Object &object,
|
||||
Mesh &mesh,
|
||||
Span<const GPUMaterial *> materials);
|
||||
|
||||
blender::gpu::Batch **DRW_mesh_batch_cache_get_surface_texpaint(Object &object, Mesh &mesh);
|
||||
Span<gpu::Batch *> DRW_mesh_batch_cache_get_surface_texpaint(Object &object, Mesh &mesh);
|
||||
blender::gpu::Batch *DRW_mesh_batch_cache_get_surface_texpaint_single(Object &object, Mesh &mesh);
|
||||
blender::gpu::Batch *DRW_mesh_batch_cache_get_surface_vertpaint(Object &object, Mesh &mesh);
|
||||
blender::gpu::Batch *DRW_mesh_batch_cache_get_surface_sculpt(Object &object, Mesh &mesh);
|
||||
|
||||
@@ -273,8 +273,7 @@ static void mesh_cd_calc_active_mask_uv_layer(const Object &object,
|
||||
|
||||
static DRW_MeshCDMask mesh_cd_calc_used_gpu_layers(const Object &object,
|
||||
const Mesh &mesh,
|
||||
const GPUMaterial *const *gpumat_array,
|
||||
int gpumat_array_len,
|
||||
const Span<const GPUMaterial *> materials,
|
||||
DRW_Attributes *attributes)
|
||||
{
|
||||
const Mesh &me_final = editmesh_final_or_this(object, mesh);
|
||||
@@ -291,8 +290,7 @@ static DRW_MeshCDMask mesh_cd_calc_used_gpu_layers(const Object &object,
|
||||
me_final.default_color_attribute :
|
||||
"";
|
||||
|
||||
for (int i = 0; i < gpumat_array_len; i++) {
|
||||
const GPUMaterial *gpumat = gpumat_array[i];
|
||||
for (const GPUMaterial *gpumat : materials) {
|
||||
if (gpumat == nullptr) {
|
||||
continue;
|
||||
}
|
||||
@@ -951,15 +949,13 @@ gpu::Batch *DRW_mesh_batch_cache_get_edit_mesh_analysis(Mesh &mesh)
|
||||
|
||||
void DRW_mesh_get_attributes(const Object &object,
|
||||
const Mesh &mesh,
|
||||
const GPUMaterial *const *gpumat_array,
|
||||
int gpumat_array_len,
|
||||
const Span<const GPUMaterial *> materials,
|
||||
DRW_Attributes *r_attrs,
|
||||
DRW_MeshCDMask *r_cd_needed)
|
||||
{
|
||||
DRW_Attributes attrs_needed;
|
||||
drw_attributes_clear(&attrs_needed);
|
||||
DRW_MeshCDMask cd_needed = mesh_cd_calc_used_gpu_layers(
|
||||
object, mesh, gpumat_array, gpumat_array_len, &attrs_needed);
|
||||
DRW_MeshCDMask cd_needed = mesh_cd_calc_used_gpu_layers(object, mesh, materials, &attrs_needed);
|
||||
|
||||
if (r_attrs) {
|
||||
*r_attrs = attrs_needed;
|
||||
@@ -970,31 +966,28 @@ void DRW_mesh_get_attributes(const Object &object,
|
||||
}
|
||||
}
|
||||
|
||||
gpu::Batch **DRW_mesh_batch_cache_get_surface_shaded(Object &object,
|
||||
Mesh &mesh,
|
||||
GPUMaterial **gpumat_array,
|
||||
uint gpumat_array_len)
|
||||
Span<gpu::Batch *> DRW_mesh_batch_cache_get_surface_shaded(
|
||||
Object &object, Mesh &mesh, const Span<const GPUMaterial *> materials)
|
||||
{
|
||||
MeshBatchCache &cache = *mesh_batch_cache_get(mesh);
|
||||
DRW_Attributes attrs_needed;
|
||||
drw_attributes_clear(&attrs_needed);
|
||||
DRW_MeshCDMask cd_needed = mesh_cd_calc_used_gpu_layers(
|
||||
object, mesh, gpumat_array, gpumat_array_len, &attrs_needed);
|
||||
DRW_MeshCDMask cd_needed = mesh_cd_calc_used_gpu_layers(object, mesh, materials, &attrs_needed);
|
||||
|
||||
BLI_assert(gpumat_array_len == cache.mat_len);
|
||||
BLI_assert(materials.size() == cache.mat_len);
|
||||
|
||||
mesh_cd_layers_type_merge(&cache.cd_needed, cd_needed);
|
||||
drw_attributes_merge(&cache.attr_needed, &attrs_needed, mesh.runtime->render_mutex);
|
||||
mesh_batch_cache_request_surface_batches(cache);
|
||||
return cache.surface_per_mat.data();
|
||||
return cache.surface_per_mat;
|
||||
}
|
||||
|
||||
gpu::Batch **DRW_mesh_batch_cache_get_surface_texpaint(Object &object, Mesh &mesh)
|
||||
Span<gpu::Batch *> DRW_mesh_batch_cache_get_surface_texpaint(Object &object, Mesh &mesh)
|
||||
{
|
||||
MeshBatchCache &cache = *mesh_batch_cache_get(mesh);
|
||||
texpaint_request_active_uv(cache, object, mesh);
|
||||
mesh_batch_cache_request_surface_batches(cache);
|
||||
return cache.surface_per_mat.data();
|
||||
return cache.surface_per_mat;
|
||||
}
|
||||
|
||||
gpu::Batch *DRW_mesh_batch_cache_get_surface_texpaint_single(Object &object, Mesh &mesh)
|
||||
|
||||
@@ -253,8 +253,7 @@ namespace blender::draw {
|
||||
|
||||
void DRW_mesh_get_attributes(const Object &object,
|
||||
const Mesh &mesh,
|
||||
const GPUMaterial *const *gpumat_array,
|
||||
int gpumat_array_len,
|
||||
Span<const GPUMaterial *> materials,
|
||||
DRW_Attributes *r_attrs,
|
||||
DRW_MeshCDMask *r_cd_needed);
|
||||
|
||||
|
||||
@@ -159,7 +159,7 @@ Vector<SculptBatch> sculpt_batches_per_material_get(const Object *ob,
|
||||
|
||||
DRW_Attributes draw_attrs;
|
||||
DRW_MeshCDMask cd_needed;
|
||||
DRW_mesh_get_attributes(*ob, *mesh, materials.data(), materials.size(), &draw_attrs, &cd_needed);
|
||||
DRW_mesh_get_attributes(*ob, *mesh, materials, &draw_attrs, &cd_needed);
|
||||
|
||||
Vector<pbvh::AttributeRequest, 16> attrs;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user