Currently UV maps and tangents are referenced by custom data layer index by the mesh extraction system that decides what attributes are needed on the GPU for rendering. This system is closely tied to CustomData, and adds a limit on 8 total UV maps on the mesh (crucially different than a limit on the supported UV map count for rendering). The process of detecting which attributes to upload is also directly tied to CustomData. In particular, `mesh_cd_calc_used_gpu_layers` is quite complicated. This commit reimplements that function, and references used UV maps and UV tangents by name rather than by index. The process is now mostly separated from `CustomData`, which is important as Mesh moves to `AttributeStorage` instead. Overall I noticed this introduces some overhead (a few percent cost to playback in some extreme cases). `DRW_MeshCDMask` is bigger than before (it was just an integer), and the attribute API currently has some overhead that can be removed when it's backed by `AttributeStorage`. The change still feels worth it to me, given other opportunities for optimization in this area. Ref #122398 Pull Request: https://projects.blender.org/blender/blender/pulls/141467
36 lines
736 B
C++
36 lines
736 B
C++
/* SPDX-FileCopyrightText: 2022 Blender Authors
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
#include "GPU_shader.hh"
|
|
|
|
#include "draw_attributes.hh"
|
|
|
|
namespace blender::draw {
|
|
|
|
void drw_attributes_merge(VectorSet<std::string> *dst, const VectorSet<std::string> *src)
|
|
{
|
|
dst->add_multiple(src->as_span());
|
|
}
|
|
|
|
bool drw_attributes_overlap(const VectorSet<std::string> *a, const VectorSet<std::string> *b)
|
|
{
|
|
for (const std::string &req : b->as_span()) {
|
|
if (!a->contains(req)) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
void drw_attributes_add_request(VectorSet<std::string> *attrs, const StringRef name)
|
|
{
|
|
if (attrs->size() >= GPU_MAX_ATTR) {
|
|
return;
|
|
}
|
|
attrs->add_as(name);
|
|
}
|
|
|
|
} // namespace blender::draw
|