[Bf-blender-cvs] [3505dcf3b27] temp-T101739-fix-seam-bleeding-non-manifold: Use struct of arrays per tile.
Jeroen Bakker
noreply at git.blender.org
Fri Jan 13 09:11:59 CET 2023
Commit: 3505dcf3b27f63eac60f6e4c5291c5831e3fde9b
Author: Jeroen Bakker
Date: Fri Jan 13 09:10:01 2023 +0100
Branches: temp-T101739-fix-seam-bleeding-non-manifold
https://developer.blender.org/rB3505dcf3b27f63eac60f6e4c5291c5831e3fde9b
Use struct of arrays per tile.
===================================================================
M source/blender/blenkernel/BKE_pbvh_pixels.hh
M source/blender/blenkernel/intern/pbvh_pixels_copy.cc
===================================================================
diff --git a/source/blender/blenkernel/BKE_pbvh_pixels.hh b/source/blender/blenkernel/BKE_pbvh_pixels.hh
index 0ccb28a6a51..67278c62bc2 100644
--- a/source/blender/blenkernel/BKE_pbvh_pixels.hh
+++ b/source/blender/blenkernel/BKE_pbvh_pixels.hh
@@ -282,9 +282,11 @@ struct DeltaCopyPixelCommand {
};
struct CopyPixelGroup {
- int2 destination;
- int2 source;
- Vector<DeltaCopyPixelCommand> deltas;
+ int2 start_destination;
+ int2 start_source_1;
+ int64_t start_delta_index;
+ // TODO: extract from next group.
+ int num_deltas;
};
/** Pixel copy command to mix 2 source pixels and write to a destination pixel. */
@@ -300,9 +302,9 @@ struct CopyPixelCommand {
CopyPixelCommand() = default;
CopyPixelCommand(const CopyPixelGroup &group)
- : destination(group.destination),
- source_1(group.source),
- source_2(group.source),
+ : destination(group.start_destination),
+ source_1(group.start_source_1),
+ source_2(),
mix_factor(0.0f)
{
}
@@ -335,6 +337,7 @@ struct CopyPixelCommand {
struct CopyPixelTile {
image::TileNumber tile_number;
Vector<CopyPixelGroup> groups;
+ Vector<DeltaCopyPixelCommand> command_deltas;
CopyPixelTile(image::TileNumber tile_number) : tile_number(tile_number)
{
@@ -357,7 +360,8 @@ struct CopyPixelTile {
{
for (const CopyPixelGroup &group : groups) {
CopyPixelCommand copy_command(group);
- for (const DeltaCopyPixelCommand &item : group.deltas) {
+ for (const DeltaCopyPixelCommand &item : Span<const DeltaCopyPixelCommand>(
+ &command_deltas[group.start_delta_index], group.num_deltas)) {
copy_command.apply(item);
/*
printf("| %d,%d | %d,%d | %d,%d | %f |\n",
diff --git a/source/blender/blenkernel/intern/pbvh_pixels_copy.cc b/source/blender/blenkernel/intern/pbvh_pixels_copy.cc
index 2c3c9aca2cd..61a23724870 100644
--- a/source/blender/blenkernel/intern/pbvh_pixels_copy.cc
+++ b/source/blender/blenkernel/intern/pbvh_pixels_copy.cc
@@ -397,9 +397,14 @@ struct Rows {
}
}
- static bool can_be_extended_with(const CopyPixelGroup &group, const CopyPixelCommand &command)
+ static bool can_extend_last_group(const CopyPixelTile &tile_pixels,
+ const CopyPixelCommand &command)
{
- CopyPixelCommand last_command = last_copy_command(group);
+ if (tile_pixels.groups.is_empty()) {
+ return false;
+ }
+ const CopyPixelGroup &group = tile_pixels.groups.last();
+ CopyPixelCommand last_command = last_copy_command(tile_pixels, group);
/* Can only extend when pushing the next pixel. */
if (last_command.destination.x != command.destination.x - 1 ||
last_command.destination.y != command.destination.y) {
@@ -413,32 +418,39 @@ struct Rows {
return true;
}
- static void extend_with(CopyPixelGroup &group, const CopyPixelCommand &command)
+ static void extend_last_group(CopyPixelTile &tile_pixels, const CopyPixelCommand &command)
{
- CopyPixelCommand last_command = last_copy_command(group);
+ CopyPixelGroup &group = tile_pixels.groups.last();
+ CopyPixelCommand last_command = last_copy_command(tile_pixels, group);
DeltaCopyPixelCommand delta_command = last_command.encode_delta(command);
- group.deltas.append(delta_command);
+ tile_pixels.command_deltas.append(delta_command);
+ group.num_deltas += 1;
}
- static CopyPixelCommand last_copy_command(const CopyPixelGroup &group)
+ // TODO: move to group. */
+ static CopyPixelCommand last_copy_command(const CopyPixelTile &tile_pixels,
+ const CopyPixelGroup &group)
{
CopyPixelCommand last_command(group);
- for (const DeltaCopyPixelCommand &item : group.deltas) {
+ for (const DeltaCopyPixelCommand &item : Span<const DeltaCopyPixelCommand>(
+ &tile_pixels.command_deltas[group.start_delta_index], group.num_deltas)) {
last_command.apply(item);
}
return last_command;
}
- void pack_into(Vector<CopyPixelGroup> &groups) const
+ void pack_into(CopyPixelTile ©_tile) const
{
for (const Pixel &elem : pixels) {
if (elem.type == PixelType::CopyFromClosestEdge) {
- if (groups.is_empty() || !can_be_extended_with(groups.last(), elem.copy_command)) {
- CopyPixelGroup new_group = {
- elem.copy_command.destination - int2(1, 0), elem.copy_command.source_1, {}};
- groups.append(new_group);
+ if (!can_extend_last_group(copy_tile, elem.copy_command)) {
+ CopyPixelGroup new_group = {elem.copy_command.destination - int2(1, 0),
+ elem.copy_command.source_1,
+ copy_tile.command_deltas.size(),
+ 0};
+ copy_tile.groups.append(new_group);
}
- extend_with(groups.last(), elem.copy_command);
+ extend_last_group(copy_tile, elem.copy_command);
}
}
}
@@ -481,10 +493,10 @@ struct Rows {
}
}
- void pack_into(Vector<CopyPixelGroup> &groups) const
+ void pack_into(CopyPixelTile ©_tile) const
{
for (const Row &row : rows) {
- row.pack_into(groups);
+ row.pack_into(copy_tile);
}
}
@@ -538,7 +550,7 @@ void BKE_pbvh_pixels_copy_update(PBVH &pbvh,
Rows rows(tile_resolution, image.seam_margin, nodes_tile_pixels);
rows.mark_for_evaluation(tile_edges);
rows.find_copy_source();
- rows.pack_into(copy_tile.groups);
+ rows.pack_into(copy_tile);
pbvh_data.tiles_copy_pixels.tiles.append(copy_tile);
}
TIMEIT_END(pbvh_pixels_copy_update);
More information about the Bf-blender-cvs
mailing list