From 475fa431595cfbaa83ca0ec096814f27ed65e7ca Mon Sep 17 00:00:00 2001 From: Miguel Pozo Date: Mon, 13 Feb 2023 18:23:15 +0100 Subject: [PATCH 1/2] Fix 104370: Draw: Don't request the same attribute more than once Avoid running out of attributes when multiple material slots use the same one. Ideally, we should skip materials with no asigned geometry as well. --- source/blender/draw/intern/draw_attributes.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/source/blender/draw/intern/draw_attributes.cc b/source/blender/draw/intern/draw_attributes.cc index 553832b0bf6..7ea7f5c27e5 100644 --- a/source/blender/draw/intern/draw_attributes.cc +++ b/source/blender/draw/intern/draw_attributes.cc @@ -71,6 +71,14 @@ DRW_AttributeRequest *drw_attributes_add_request(DRW_Attributes *attrs, return nullptr; } + for (int i : blender::IndexRange(attrs->num_requests)) { + /* Check first if it has been requested already. */ + DRW_AttributeRequest *req = &attrs->requests[i]; + if (req->cd_type == type && req->layer_index == layer_index && req->domain == domain) { + return req; + } + } + DRW_AttributeRequest *req = &attrs->requests[attrs->num_requests]; req->cd_type = type; BLI_strncpy(req->attribute_name, name, sizeof(req->attribute_name)); -- 2.30.2 From 71dece7bde7445186e03b7e36a07aa69354f2fd8 Mon Sep 17 00:00:00 2001 From: Miguel Pozo Date: Wed, 15 Feb 2023 19:35:24 +0100 Subject: [PATCH 2/2] Cleanup --- source/blender/draw/intern/draw_attributes.cc | 41 +++++++------------ source/blender/draw/intern/draw_attributes.hh | 10 ++--- 2 files changed, 19 insertions(+), 32 deletions(-) diff --git a/source/blender/draw/intern/draw_attributes.cc b/source/blender/draw/intern/draw_attributes.cc index 7ea7f5c27e5..e1d53844f5a 100644 --- a/source/blender/draw/intern/draw_attributes.cc +++ b/source/blender/draw/intern/draw_attributes.cc @@ -4,20 +4,15 @@ #include "draw_attributes.hh" /* Return true if the given DRW_AttributeRequest is already in the requests. */ -static bool drw_attributes_has_request(const DRW_Attributes *requests, DRW_AttributeRequest req) +static bool drw_attributes_has_request(const DRW_Attributes *requests, + const DRW_AttributeRequest &req) { for (int i = 0; i < requests->num_requests; i++) { - const DRW_AttributeRequest src_req = requests->requests[i]; - if (src_req.domain != req.domain) { - continue; + const DRW_AttributeRequest &src_req = requests->requests[i]; + if (src_req.domain == req.domain && src_req.layer_index == req.layer_index && + src_req.cd_type == req.cd_type) { + return true; } - if (src_req.layer_index != req.layer_index) { - continue; - } - if (src_req.cd_type != req.cd_type) { - continue; - } - return true; } return false; } @@ -61,22 +56,15 @@ bool drw_attributes_overlap(const DRW_Attributes *a, const DRW_Attributes *b) return true; } -DRW_AttributeRequest *drw_attributes_add_request(DRW_Attributes *attrs, - const char *name, - const eCustomDataType type, - const int layer_index, - const eAttrDomain domain) +void drw_attributes_add_request(DRW_Attributes *attrs, + const char *name, + const eCustomDataType type, + const int layer_index, + const eAttrDomain domain) { - if (attrs->num_requests >= GPU_MAX_ATTR) { - return nullptr; - } - - for (int i : blender::IndexRange(attrs->num_requests)) { - /* Check first if it has been requested already. */ - DRW_AttributeRequest *req = &attrs->requests[i]; - if (req->cd_type == type && req->layer_index == layer_index && req->domain == domain) { - return req; - } + if (attrs->num_requests >= GPU_MAX_ATTR || + drw_attributes_has_request(attrs, {type, layer_index, domain})) { + return; } DRW_AttributeRequest *req = &attrs->requests[attrs->num_requests]; @@ -85,7 +73,6 @@ DRW_AttributeRequest *drw_attributes_add_request(DRW_Attributes *attrs, req->layer_index = layer_index; req->domain = domain; attrs->num_requests += 1; - return req; } bool drw_custom_data_match_attribute(const CustomData *custom_data, diff --git a/source/blender/draw/intern/draw_attributes.hh b/source/blender/draw/intern/draw_attributes.hh index 1449f7b3b8a..d5de4e1641b 100644 --- a/source/blender/draw/intern/draw_attributes.hh +++ b/source/blender/draw/intern/draw_attributes.hh @@ -60,11 +60,11 @@ void drw_attributes_merge(DRW_Attributes *dst, /* Return true if all requests in b are in a. */ bool drw_attributes_overlap(const DRW_Attributes *a, const DRW_Attributes *b); -DRW_AttributeRequest *drw_attributes_add_request(DRW_Attributes *attrs, - const char *name, - eCustomDataType data_type, - int layer_index, - eAttrDomain domain); +void drw_attributes_add_request(DRW_Attributes *attrs, + const char *name, + eCustomDataType data_type, + int layer_index, + eAttrDomain domain); bool drw_custom_data_match_attribute(const CustomData *custom_data, const char *name, -- 2.30.2