Refactor: Remove layer index from draw attribute request struct
The goal is to separate the draw attribute request from the CustomData implementation. For the layer index this was already started a while ago; it's only used in a couple places and lookups are mostly name based anyway. Conceptually the attribute request is just a request that the extraction system create a buffer for a certain attribute name. Information about where the attribute is stored doesn't fit. Pull Request: https://projects.blender.org/blender/blender/pulls/138570
This commit is contained in:
@@ -17,7 +17,7 @@ static bool drw_attributes_has_request(const DRW_Attributes *requests,
|
||||
{
|
||||
for (int i = 0; i < requests->num_requests; i++) {
|
||||
const DRW_AttributeRequest &src_req = requests->requests[i];
|
||||
if (src_req.domain == req.domain && src_req.layer_index == req.layer_index &&
|
||||
if (STREQ(src_req.attribute_name, req.attribute_name) && src_req.domain == req.domain &&
|
||||
src_req.cd_type == req.cd_type)
|
||||
{
|
||||
return true;
|
||||
@@ -71,20 +71,17 @@ bool drw_attributes_overlap(const DRW_Attributes *a, const DRW_Attributes *b)
|
||||
void drw_attributes_add_request(DRW_Attributes *attrs,
|
||||
const char *name,
|
||||
const eCustomDataType type,
|
||||
const int layer_index,
|
||||
const blender::bke::AttrDomain domain)
|
||||
{
|
||||
if (attrs->num_requests >= GPU_MAX_ATTR ||
|
||||
drw_attributes_has_request(attrs, {type, layer_index, domain}))
|
||||
{
|
||||
DRW_AttributeRequest req{};
|
||||
req.cd_type = type;
|
||||
STRNCPY(req.attribute_name, name);
|
||||
req.domain = domain;
|
||||
if (attrs->num_requests >= GPU_MAX_ATTR || drw_attributes_has_request(attrs, req)) {
|
||||
return;
|
||||
}
|
||||
|
||||
DRW_AttributeRequest *req = &attrs->requests[attrs->num_requests];
|
||||
req->cd_type = type;
|
||||
STRNCPY(req->attribute_name, name);
|
||||
req->layer_index = layer_index;
|
||||
req->domain = domain;
|
||||
attrs->requests[attrs->num_requests] = req;
|
||||
attrs->num_requests += 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@ namespace blender::draw {
|
||||
|
||||
struct DRW_AttributeRequest {
|
||||
eCustomDataType cd_type;
|
||||
int layer_index;
|
||||
blender::bke::AttrDomain domain;
|
||||
char attribute_name[64];
|
||||
};
|
||||
@@ -62,7 +61,6 @@ bool drw_attributes_overlap(const DRW_Attributes *a, const DRW_Attributes *b);
|
||||
void drw_attributes_add_request(DRW_Attributes *attrs,
|
||||
const char *name,
|
||||
eCustomDataType data_type,
|
||||
int layer_index,
|
||||
blender::bke::AttrDomain domain);
|
||||
|
||||
bool drw_custom_data_match_attribute(const CustomData &custom_data,
|
||||
|
||||
@@ -819,7 +819,7 @@ static bool ensure_attributes(const Curves &curves,
|
||||
}
|
||||
|
||||
if (layer != -1 && domain.has_value()) {
|
||||
drw_attributes_add_request(&attrs_needed, name, CD_PROP_FLOAT2, layer, *domain);
|
||||
drw_attributes_add_request(&attrs_needed, name, CD_PROP_FLOAT2, *domain);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -840,7 +840,7 @@ static bool ensure_attributes(const Curves &curves,
|
||||
case CD_PROP_FLOAT:
|
||||
case CD_PROP_FLOAT2: {
|
||||
if (layer != -1 && domain.has_value()) {
|
||||
drw_attributes_add_request(&attrs_needed, name, type, layer, *domain);
|
||||
drw_attributes_add_request(&attrs_needed, name, type, *domain);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -894,11 +894,8 @@ static void request_attribute(Curves &curves, const char *name)
|
||||
}
|
||||
const bke::AttrDomain domain = meta_data->domain;
|
||||
const eCustomDataType type = meta_data->data_type;
|
||||
const CustomData &custom_data = domain == bke::AttrDomain::Point ? curves.geometry.point_data :
|
||||
curves.geometry.curve_data;
|
||||
|
||||
drw_attributes_add_request(
|
||||
&attributes, name, type, CustomData_get_named_layer(&custom_data, type, name), domain);
|
||||
drw_attributes_add_request(&attributes, name, type, domain);
|
||||
|
||||
drw_attributes_merge(&final_cache.attr_used, &attributes, cache.render_mutex);
|
||||
}
|
||||
|
||||
@@ -305,7 +305,7 @@ static DRW_MeshCDMask mesh_cd_calc_used_gpu_layers(const Object &object,
|
||||
case CD_PROP_FLOAT:
|
||||
case CD_PROP_FLOAT2: {
|
||||
if (layer != -1 && domain.has_value()) {
|
||||
drw_attributes_add_request(attributes, name, type, layer, *domain);
|
||||
drw_attributes_add_request(attributes, name, type, *domain);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -700,10 +700,10 @@ static void request_active_and_default_color_attributes(const Object &object,
|
||||
int layer_index;
|
||||
eCustomDataType type;
|
||||
if (drw_custom_data_match_attribute(cd_vdata, name, &layer_index, &type)) {
|
||||
drw_attributes_add_request(&attributes, name, type, layer_index, bke::AttrDomain::Point);
|
||||
drw_attributes_add_request(&attributes, name, type, bke::AttrDomain::Point);
|
||||
}
|
||||
else if (drw_custom_data_match_attribute(cd_ldata, name, &layer_index, &type)) {
|
||||
drw_attributes_add_request(&attributes, name, type, layer_index, bke::AttrDomain::Corner);
|
||||
drw_attributes_add_request(&attributes, name, type, bke::AttrDomain::Corner);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -347,6 +347,7 @@ gpu::Batch **pointcloud_surface_shaded_get(PointCloud *pointcloud,
|
||||
GPUMaterial **gpu_materials,
|
||||
int mat_len)
|
||||
{
|
||||
const bke::AttributeAccessor attributes = pointcloud->attributes();
|
||||
PointCloudBatchCache *cache = pointcloud_batch_cache_get(*pointcloud);
|
||||
DRW_Attributes attrs_needed;
|
||||
drw_attributes_clear(&attrs_needed);
|
||||
@@ -355,15 +356,12 @@ gpu::Batch **pointcloud_surface_shaded_get(PointCloud *pointcloud,
|
||||
ListBase gpu_attrs = GPU_material_attributes(gpu_material);
|
||||
LISTBASE_FOREACH (GPUMaterialAttribute *, gpu_attr, &gpu_attrs) {
|
||||
const char *name = gpu_attr->name;
|
||||
|
||||
int layer_index;
|
||||
eCustomDataType type;
|
||||
bke::AttrDomain domain = bke::AttrDomain::Point;
|
||||
if (!drw_custom_data_match_attribute(pointcloud->pdata, name, &layer_index, &type)) {
|
||||
const std::optional<bke::AttributeMetaData> meta_data = attributes.lookup_meta_data(name);
|
||||
if (!meta_data) {
|
||||
continue;
|
||||
}
|
||||
|
||||
drw_attributes_add_request(&attrs_needed, name, type, layer_index, domain);
|
||||
drw_attributes_add_request(&attrs_needed, name, meta_data->data_type, meta_data->domain);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -407,15 +405,17 @@ gpu::VertBuf *DRW_pointcloud_position_and_radius_buffer_get(Object *ob)
|
||||
|
||||
gpu::VertBuf **DRW_pointcloud_evaluated_attribute(PointCloud *pointcloud, const char *name)
|
||||
{
|
||||
const bke::AttributeAccessor attributes = pointcloud->attributes();
|
||||
PointCloudBatchCache &cache = *pointcloud_batch_cache_get(*pointcloud);
|
||||
|
||||
int layer_index;
|
||||
eCustomDataType type;
|
||||
bke::AttrDomain domain = bke::AttrDomain::Point;
|
||||
if (drw_custom_data_match_attribute(pointcloud->pdata, name, &layer_index, &type)) {
|
||||
DRW_Attributes attributes{};
|
||||
drw_attributes_add_request(&attributes, name, type, layer_index, domain);
|
||||
drw_attributes_merge(&cache.eval_cache.attr_used, &attributes, cache.render_mutex);
|
||||
const std::optional<bke::AttributeMetaData> meta_data = attributes.lookup_meta_data(name);
|
||||
if (!meta_data) {
|
||||
return nullptr;
|
||||
}
|
||||
{
|
||||
DRW_Attributes requests{};
|
||||
drw_attributes_add_request(&requests, name, meta_data->data_type, meta_data->domain);
|
||||
drw_attributes_merge(&cache.eval_cache.attr_used, &requests, cache.render_mutex);
|
||||
}
|
||||
|
||||
int request_i = -1;
|
||||
|
||||
@@ -324,15 +324,15 @@ gpu::Batch *curves_sub_pass_setup_implementation(PassT &sub_ps,
|
||||
sub_ps.bind_texture("l", curves_cache->proc_length_buf);
|
||||
}
|
||||
|
||||
int curve_data_render_uv = 0;
|
||||
int point_data_render_uv = 0;
|
||||
StringRef curve_data_render_uv;
|
||||
StringRef point_data_render_uv;
|
||||
if (CustomData_has_layer(&curves_id.geometry.curve_data, CD_PROP_FLOAT2)) {
|
||||
curve_data_render_uv = CustomData_get_render_layer(&curves_id.geometry.curve_data,
|
||||
CD_PROP_FLOAT2);
|
||||
curve_data_render_uv = CustomData_get_render_layer_name(&curves_id.geometry.curve_data,
|
||||
CD_PROP_FLOAT2);
|
||||
}
|
||||
if (CustomData_has_layer(&curves_id.geometry.point_data, CD_PROP_FLOAT2)) {
|
||||
point_data_render_uv = CustomData_get_render_layer(&curves_id.geometry.point_data,
|
||||
CD_PROP_FLOAT2);
|
||||
point_data_render_uv = CustomData_get_render_layer_name(&curves_id.geometry.point_data,
|
||||
CD_PROP_FLOAT2);
|
||||
}
|
||||
|
||||
const DRW_Attributes &attrs = curves_cache->final.attr_used;
|
||||
@@ -346,7 +346,7 @@ gpu::Batch *curves_sub_pass_setup_implementation(PassT &sub_ps,
|
||||
continue;
|
||||
}
|
||||
sub_ps.bind_texture(sampler_name, curves_cache->proc_attributes_buf[i]);
|
||||
if (request.cd_type == CD_PROP_FLOAT2 && request.layer_index == curve_data_render_uv) {
|
||||
if (request.cd_type == CD_PROP_FLOAT2 && request.attribute_name == curve_data_render_uv) {
|
||||
sub_ps.bind_texture("a", curves_cache->proc_attributes_buf[i]);
|
||||
}
|
||||
}
|
||||
@@ -355,7 +355,7 @@ gpu::Batch *curves_sub_pass_setup_implementation(PassT &sub_ps,
|
||||
continue;
|
||||
}
|
||||
sub_ps.bind_texture(sampler_name, curves_cache->final.attributes_buf[i]);
|
||||
if (request.cd_type == CD_PROP_FLOAT2 && request.layer_index == point_data_render_uv) {
|
||||
if (request.cd_type == CD_PROP_FLOAT2 && request.attribute_name == point_data_render_uv) {
|
||||
sub_ps.bind_texture("a", curves_cache->final.attributes_buf[i]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user