BMesh: Respect data alignment for attributes #109237

Open
Joseph Eagar wants to merge 8 commits from JosephEagar/blender:temp-customdata-aligned-offsets into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
1 changed files with 13 additions and 11 deletions
Showing only changes of commit 1e3de4c7c7 - Show all commits

View File

@ -62,6 +62,8 @@
/* only for customdata_data_transfer_interp_normal_normals */
#include "data_transfer_intern.h"
#include <array>
JosephEagar marked this conversation as resolved Outdated

Unnecessary change

Unnecessary change
using blender::Array;
using blender::float2;
using blender::ImplicitSharingInfo;
@ -2544,6 +2546,8 @@ void CustomData_free_typemask(CustomData *data, const int totelem, eCustomDataMa
static int customData_get_alignment(eCustomDataType type)
JosephEagar marked this conversation as resolved
Review

This comment isn't quite right, since CD_PROP_BYTE_COLOR is also an array type. Maybe "Handle float array types"?

This comment isn't quite right, since `CD_PROP_BYTE_COLOR` is also an array type. Maybe "Handle float array types"?
Review

I has an if statement for that. I admit the comment isn't clear, it applies to the three if statements (for 4,2,1 alignments).

I has an if statement for that. I admit the comment isn't clear, it applies to the three if statements (for 4,2,1 alignments).
Review

Ah I see. I don't think the comment is necessary honestly

Ah I see. I don't think the comment is necessary honestly
{
/* Handle array types. */
/* Float and integer arrays. */
if (ELEM(type,
CD_PROP_FLOAT2,
CD_PROP_FLOAT3,
@ -2558,10 +2562,12 @@ static int customData_get_alignment(eCustomDataType type)
return 4;
}
/* Short arrays. */
if (ELEM(type, CD_TESSLOOPNORMAL)) {
return 2;
}
/* Byte arrays. */
if (type == CD_PROP_BYTE_COLOR) {
return 1;
}
@ -2585,26 +2591,21 @@ static int customData_get_alignment(eCustomDataType type)
/* Update BMesh block offsets, respects alignment. */
static void customData_update_offsets(CustomData *data)
{
const LayerTypeInfo *typeInfo;
if (data->totlayer == 0) {
data->totsize = 0;
return;
}
JosephEagar marked this conversation as resolved Outdated

std::array should work here, a bit nicer IMO

`std::array` should work here, a bit nicer IMO
const std::array<int, 4> aligns = {8, 4, 2, 1};
int max_alignment = 1;
int aligns[] = {8, 4, 2, 1};
int offset = 0;
JosephEagar marked this conversation as resolved Outdated

Declare variables const

Declare variables const
for (int align : aligns) {
for (int i = 0; i < data->totlayer; i++) {
CustomDataLayer *layer = data->layers + i;
for (int i = 0; i < ARRAY_SIZE(aligns) + 1; i++) {
for (int j = 0; j < data->totlayer; j++) {
CustomDataLayer *layer = data->layers + j;
int align = customData_get_alignment(eCustomDataType(layer->type));
max_alignment = max_ii(max_alignment, align);
if (align != aligns[i]) {
int layer_align = customData_get_alignment(eCustomDataType(layer->type));
if (layer_align != align) {
continue;
}
@ -2616,6 +2617,7 @@ static void customData_update_offsets(CustomData *data)
}
offset += size;
max_alignment = max_ii(max_alignment, align);
}
}