perf: BuildFrame 收集段优化——实体级粗剔除 + 数组化 batch 查找 + 合并矩阵写
定位数据(100 背包 + SunTemple,RTX 5060):GPU 全帧仅 ~3ms (Forward 1.91 + Shadow 0.82),CPU BuildFrame 收集段 5.94ms 才是 帧率瓶颈。三段细分测量:pre 0.2 / each+cull 5.0 / flatten 0.4。 优化(collect 5.94 → 4.6ms,-23%): 1. Mesh 全局连续槽位(GetSlot);ViewScratch batch 查找 hash → 数组寻址(slot × kMeshLodCount 槽) 2. Model 级联合包围球(各 mesh bounds 并集):实体在四视图全部 不可见 → 跳过整个 mesh 循环(多 mesh 模型的粗剔除) 3. worlds/prevWorlds 合并为 stride-2 InstanceMatrices 单次写 (每实例每视图 2 次随机堆访问 → 1 次,cache miss 减半) 遥测:Renderer::GetCollectMs 暴露收集段耗时。剩余 4.6ms 的进一步 压缩(并行收集 / GPU-driven culling)单独立项。
This commit is contained in:
@@ -10,16 +10,24 @@
|
||||
#include <Engine/Core/Log.h>
|
||||
|
||||
#include <limits>
|
||||
#include <atomic>
|
||||
|
||||
#include "Engine/Core/Stats.h"
|
||||
|
||||
namespace Engine
|
||||
{
|
||||
namespace {
|
||||
// 全局连续 mesh 槽位:SceneRenderer 的 batch 查找用数组寻址
|
||||
//(每实例每视图一次 hash 的代价在大场景下是 5ms 级)
|
||||
std::atomic<u32> s_nextMeshSlot{0};
|
||||
}
|
||||
|
||||
Mesh::Mesh(Device& device, MemoryAllocator& allocator,
|
||||
const std::vector<Vertex>& vertices,
|
||||
const std::vector<std::vector<u32>>& lods,
|
||||
Material* material)
|
||||
: m_Material(material)
|
||||
, m_Slot(s_nextMeshSlot.fetch_add(1, std::memory_order_relaxed))
|
||||
{
|
||||
if (vertices.empty() || lods.empty() || lods[0].empty())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user