Optimize DrawBatch for faster sorting

This commit is contained in:
Wojtek Figat
2024-04-12 13:46:20 +02:00
parent e47e91c223
commit 1e77f3aa5a
2 changed files with 5 additions and 3 deletions

View File

@@ -570,6 +570,7 @@ void RenderList::SortDrawCalls(const RenderContext& renderContext, bool reverseD
const auto* drawCallsData = drawCalls.Get();
const auto* listData = list.Indices.Get();
const int32 listSize = list.Indices.Count();
ZoneValue(listSize);
// Peek shared memory
#define PREPARE_CACHE(list) (list).Clear(); (list).Resize(listSize)
@@ -626,6 +627,7 @@ void RenderList::SortDrawCalls(const RenderContext& renderContext, bool reverseD
}
DrawBatch batch;
static_assert(sizeof(DrawBatch) == sizeof(uint64) * 2, "Fix the size of draw batch to optimize memory access.");
batch.SortKey = sortedKeys[i];
batch.StartIndex = i;
batch.BatchSize = batchSize;

View File

@@ -212,17 +212,17 @@ struct DrawBatch
/// <summary>
/// The first draw call index.
/// </summary>
int32 StartIndex;
uint16 StartIndex;
/// <summary>
/// A number of draw calls to be submitted at once.
/// </summary>
int32 BatchSize;
uint16 BatchSize;
/// <summary>
/// The total amount of instances (sum from all draw calls in this batch).
/// </summary>
int32 InstanceCount;
uint32 InstanceCount;
bool operator<(const DrawBatch& other) const
{