Cleanup: Pass PBVH draw attribute requests as span

Also remove an unused argument to batch retrieval functions
This commit is contained in:
Hans Goudey
2023-11-30 20:30:37 -05:00
parent 2864f3ad3f
commit 2a94328346
4 changed files with 34 additions and 65 deletions

View File

@@ -79,16 +79,12 @@ void node_gpu_flush(PBVHBatches *batches);
PBVHBatches *node_create(const PBVH_GPU_Args &args);
void node_free(PBVHBatches *batches);
GPUBatch *tris_get(PBVHBatches *batches,
const PBVHAttrReq *attrs,
int attrs_num,
Span<PBVHAttrReq> attrs,
const PBVH_GPU_Args &args,
int *r_prim_count,
bool do_coarse_grids);
GPUBatch *lines_get(PBVHBatches *batches,
const PBVHAttrReq *attrs,
int attrs_num,
Span<PBVHAttrReq> attrs,
const PBVH_GPU_Args &args,
int *r_prim_count,
bool do_coarse_grids);
} // namespace blender::draw::pbvh

View File

@@ -1213,8 +1213,7 @@ struct DRWSculptCallbackData {
bool fast_mode; /* Set by draw manager. Do not init. */
int debug_node_nr;
PBVHAttrReq *attrs;
int attrs_num;
blender::Span<PBVHAttrReq> attrs;
};
#define SCULPT_DEBUG_COLOR(id) (sculpt_debug_colors[id % 9])
@@ -1239,16 +1238,13 @@ static void sculpt_draw_cb(DRWSculptCallbackData *scd,
return;
}
int primcount;
GPUBatch *geom;
if (!scd->use_wire) {
geom = pbvh::tris_get(
batches, scd->attrs, scd->attrs_num, pbvh_draw_args, &primcount, scd->fast_mode);
geom = pbvh::tris_get(batches, scd->attrs, pbvh_draw_args, scd->fast_mode);
}
else {
geom = pbvh::lines_get(
batches, scd->attrs, scd->attrs_num, pbvh_draw_args, &primcount, scd->fast_mode);
geom = pbvh::lines_get(batches, scd->attrs, pbvh_draw_args, scd->fast_mode);
}
short index = 0;
@@ -1458,8 +1454,7 @@ void DRW_shgroup_call_sculpt(DRWShadingGroup *shgroup,
}
}
scd.attrs = attrs;
scd.attrs_num = attrs_num;
scd.attrs = {attrs, attrs_num};
drw_sculpt_generate_calls(&scd);
}
@@ -1529,8 +1524,7 @@ void DRW_shgroup_call_sculpt_with_materials(DRWShadingGroup **shgroups,
scd.use_wire = false;
scd.use_mats = true;
scd.use_mask = false;
scd.attrs = attrs.data();
scd.attrs_num = attrs_num;
scd.attrs = attrs;
drw_sculpt_generate_calls(&scd);
}

View File

@@ -391,19 +391,18 @@ struct PBVHBatches {
GPU_INDEXBUF_DISCARD_SAFE(lines_index_coarse);
}
std::string build_key(const PBVHAttrReq *attrs, int attrs_num, bool do_coarse_grids)
std::string build_key(const Span<PBVHAttrReq> attrs, bool do_coarse_grids)
{
PBVHBatch batch;
Vector<PBVHVbo> vbos;
for (int i : IndexRange(attrs_num)) {
const PBVHAttrReq *attr = attrs + i;
if (!pbvh_attr_supported(attr->type, attr->domain)) {
for (const int i : attrs.index_range()) {
const PBVHAttrReq &attr = attrs[i];
if (!pbvh_attr_supported(attr.type, attr.domain)) {
continue;
}
PBVHVbo vbo(attr->domain, attr->type, std::string(attr->name));
PBVHVbo vbo(attr.domain, attr.type, std::string(attr.name));
vbo.build_key();
vbos.append(vbo);
@@ -447,21 +446,20 @@ struct PBVHBatches {
return nullptr;
}
bool has_batch(const PBVHAttrReq *attrs, int attrs_num, bool do_coarse_grids)
bool has_batch(const Span<PBVHAttrReq> attrs, bool do_coarse_grids)
{
return batches.contains(build_key(attrs, attrs_num, do_coarse_grids));
return batches.contains(build_key(attrs, do_coarse_grids));
}
PBVHBatch &ensure_batch(const PBVHAttrReq *attrs,
int attrs_num,
PBVHBatch &ensure_batch(const Span<PBVHAttrReq> attrs,
const PBVH_GPU_Args &args,
bool do_coarse_grids)
{
if (!has_batch(attrs, attrs_num, do_coarse_grids)) {
create_batch(attrs, attrs_num, args, do_coarse_grids);
if (!has_batch(attrs, do_coarse_grids)) {
create_batch(attrs, args, do_coarse_grids);
}
return batches.lookup(build_key(attrs, attrs_num, do_coarse_grids));
return batches.lookup(build_key(attrs, do_coarse_grids));
}
void fill_vbo_normal_faces(const PBVH_GPU_Args &args, GPUVertBuf &vert_buf)
@@ -1332,10 +1330,7 @@ struct PBVHBatches {
}
}
void create_batch(const PBVHAttrReq *attrs,
int attrs_num,
const PBVH_GPU_Args &args,
bool do_coarse_grids)
void create_batch(const Span<PBVHAttrReq> attrs, const PBVH_GPU_Args &args, bool do_coarse_grids)
{
check_index_buffers(args);
@@ -1354,18 +1349,16 @@ struct PBVHBatches {
batch.lines_count = do_coarse_grids ? lines_count_coarse : lines_count;
}
for (int i : IndexRange(attrs_num)) {
const PBVHAttrReq *attr = attrs + i;
if (!pbvh_attr_supported(attr->type, attr->domain)) {
for (const PBVHAttrReq &attr : attrs) {
if (!pbvh_attr_supported(attr.type, attr.domain)) {
continue;
}
if (!has_vbo(attr->domain, int(attr->type), attr->name)) {
create_vbo(attr->domain, uint32_t(attr->type), attr->name, args);
if (!has_vbo(attr.domain, int(attr.type), attr.name)) {
create_vbo(attr.domain, uint32_t(attr.type), attr.name, args);
}
PBVHVbo *vbo = get_vbo(attr->domain, uint32_t(attr->type), attr->name);
PBVHVbo *vbo = get_vbo(attr.domain, uint32_t(attr.type), attr.name);
int vbo_i = get_vbo_index(vbo);
batch.vbos.append(vbo_i);
@@ -1402,33 +1395,25 @@ void node_free(PBVHBatches *batches)
}
GPUBatch *tris_get(PBVHBatches *batches,
const PBVHAttrReq *attrs,
int attrs_num,
const Span<PBVHAttrReq> attrs,
const PBVH_GPU_Args &args,
int *r_prim_count,
bool do_coarse_grids)
{
do_coarse_grids &= args.pbvh_type == PBVH_GRIDS;
PBVHBatch &batch = batches->ensure_batch(attrs, attrs_num, args, do_coarse_grids);
*r_prim_count = batch.tris_count;
PBVHBatch &batch = batches->ensure_batch(attrs, args, do_coarse_grids);
return batch.tris;
}
GPUBatch *lines_get(PBVHBatches *batches,
const PBVHAttrReq *attrs,
int attrs_num,
const Span<PBVHAttrReq> attrs,
const PBVH_GPU_Args &args,
int *r_prim_count,
bool do_coarse_grids)
{
do_coarse_grids &= args.pbvh_type == PBVH_GRIDS;
PBVHBatch &batch = batches->ensure_batch(attrs, attrs_num, args, do_coarse_grids);
*r_prim_count = batch.lines_count;
PBVHBatch &batch = batches->ensure_batch(attrs, args, do_coarse_grids);
return batch.lines;
}

View File

@@ -40,8 +40,7 @@ struct SculptCallbackData {
bool use_wire;
bool fast_mode;
const PBVHAttrReq *attrs;
int attrs_len;
Span<PBVHAttrReq> attrs;
Vector<SculptBatch> batches;
};
@@ -56,14 +55,11 @@ static void sculpt_draw_cb(SculptCallbackData *data,
SculptBatch batch = {};
int primcount;
if (data->use_wire) {
batch.batch = pbvh::lines_get(
batches, data->attrs, data->attrs_len, pbvh_draw_args, &primcount, data->fast_mode);
batch.batch = pbvh::lines_get(batches, data->attrs, pbvh_draw_args, data->fast_mode);
}
else {
batch.batch = pbvh::tris_get(
batches, data->attrs, data->attrs_len, pbvh_draw_args, &primcount, data->fast_mode);
batch.batch = pbvh::tris_get(batches, data->attrs, pbvh_draw_args, data->fast_mode);
}
batch.material_slot = pbvh::material_index_get(batches);
@@ -74,8 +70,7 @@ static void sculpt_draw_cb(SculptCallbackData *data,
static Vector<SculptBatch> sculpt_batches_get_ex(const Object *ob,
bool use_wire,
const PBVHAttrReq *attrs,
int attrs_len)
const Span<PBVHAttrReq> attrs)
{
/* PBVH should always exist for non-empty meshes, created by depsgraph eval. */
PBVH *pbvh = ob->sculpt ? ob->sculpt->pbvh : nullptr;
@@ -139,7 +134,6 @@ static Vector<SculptBatch> sculpt_batches_get_ex(const Object *ob,
data.use_wire = use_wire;
data.fast_mode = fast_mode;
data.attrs = attrs;
data.attrs_len = attrs_len;
BKE_pbvh_draw_cb(
*mesh,
@@ -194,7 +188,7 @@ Vector<SculptBatch> sculpt_batches_get(const Object *ob, SculptBatchFeature feat
}
}
return sculpt_batches_get_ex(ob, features & SCULPT_BATCH_WIREFRAME, attrs, attrs_len);
return sculpt_batches_get_ex(ob, features & SCULPT_BATCH_WIREFRAME, {attrs, attrs_len});
}
Vector<SculptBatch> sculpt_batches_per_material_get(const Object *ob,
@@ -237,7 +231,7 @@ Vector<SculptBatch> sculpt_batches_per_material_get(const Object *ob,
}
}
return sculpt_batches_get_ex(ob, false, attrs, attrs_len);
return sculpt_batches_get_ex(ob, false, {attrs, attrs_len});
}
} // namespace blender::draw