gr2: share vertex streams across tri-groups on the GPU skinning path

Each tri-group draw now references one shared geometry with a
first_index/index_count sub-range instead of copying the vertex
streams per group.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-10-12 16:27:00 +09:00
co-authored by Claude Opus 5.5
parent e354b92e08
commit 9ec7fa10c0
2 changed files with 64 additions and 2 deletions
+60 -2
View File
@@ -489,6 +489,35 @@ std::vector<Gr2MeshDraw> Gr2ModelInstance::BuildDrawCommandsWithPalette(const st
draw.alpha_ref = 70;
}
draws.push_back(std::move(draw));
} else if (hardwareSkinning) {
// Resident GPU geometry: one vertex set per mesh instead of a full copy per tri-group.
Gr2MeshDraw streams;
streams.positions = std::move(skinned_positions);
streams.normals = std::move(skinned_normals);
streams.uv0 = std::move(uvs);
streams.bone_indices = std::move(bone_indices);
streams.bone_weights = std::move(bone_weights);
streams.indices = mesh.indices;
auto geometry = std::make_shared<const Gr2MeshDraw>(std::move(streams));
for (const auto& group : mesh.tri_groups) {
Gr2MeshDraw draw;
std::copy(effective_world, effective_world + 16, draw.world);
draw.geometry = geometry;
std::size_t start_idx = static_cast<std::size_t>(group.tri_first * 3);
std::size_t count_idx = static_cast<std::size_t>(group.tri_count * 3);
draw.first_index = static_cast<uint32_t>(start_idx);
draw.index_count = start_idx + count_idx <= mesh.indices.size() ? static_cast<uint32_t>(count_idx) : 0;
if (group.material_index >= 0 && group.material_index < static_cast<int>(mesh.material_textures.size())) {
draw.texture0 = mesh.material_textures[group.material_index];
}
if (draw.texture0.find("hair") != std::string::npos || mesh.name.find("hair") != std::string::npos ||
draw.texture0.find("leaf") != std::string::npos || draw.texture0.find("tree") != std::string::npos) {
draw.alpha_test = true;
draw.alpha_ref = 70;
}
draws.push_back(std::move(draw));
}
} else {
for (const auto& group : mesh.tri_groups) {
Gr2MeshDraw draw;
@@ -519,7 +548,7 @@ std::vector<Gr2MeshDraw> Gr2ModelInstance::BuildDrawCommandsWithPalette(const st
}
}
if(hardwareSkinning) {
for(auto& draw:draws){draw.gpu_skinning=!part_skin_matrices.empty();draw=ShareGpuMesh(std::move(draw));}
for(auto& draw:draws){draw.gpu_skinning=!part_skin_matrices.empty();if(!draw.geometry)draw=ShareGpuMesh(std::move(draw));}
m_gpuParts=draws;UpdateGpuDraws(draws,cachedWorld,part_skin_matrices);
}
}
@@ -645,6 +674,35 @@ std::vector<Gr2MeshDraw> Gr2ModelInstance::BuildDrawCommands(float animation_tim
draw.alpha_ref = 70;
}
draws.push_back(std::move(draw));
} else if (hardwareSkinning) {
// Resident GPU geometry: one vertex set per mesh instead of a full copy per tri-group.
Gr2MeshDraw streams;
streams.positions = std::move(skinned_positions);
streams.normals = std::move(skinned_normals);
streams.uv0 = std::move(uvs);
streams.bone_indices = std::move(bone_indices);
streams.bone_weights = std::move(bone_weights);
streams.indices = mesh.indices;
auto geometry = std::make_shared<const Gr2MeshDraw>(std::move(streams));
for (const auto& group : mesh.tri_groups) {
Gr2MeshDraw draw;
std::copy(effective_world, effective_world + 16, draw.world);
draw.geometry = geometry;
std::size_t start_idx = static_cast<std::size_t>(group.tri_first * 3);
std::size_t count_idx = static_cast<std::size_t>(group.tri_count * 3);
draw.first_index = static_cast<uint32_t>(start_idx);
draw.index_count = start_idx + count_idx <= mesh.indices.size() ? static_cast<uint32_t>(count_idx) : 0;
if (group.material_index >= 0 && group.material_index < static_cast<int>(mesh.material_textures.size())) {
draw.texture0 = mesh.material_textures[group.material_index];
}
if (draw.texture0.find("hair") != std::string::npos || mesh.name.find("hair") != std::string::npos ||
draw.texture0.find("leaf") != std::string::npos || draw.texture0.find("tree") != std::string::npos) {
draw.alpha_test = true;
draw.alpha_ref = 70;
}
draws.push_back(std::move(draw));
}
} else {
for (const auto& group : mesh.tri_groups) {
Gr2MeshDraw draw;
@@ -676,7 +734,7 @@ std::vector<Gr2MeshDraw> Gr2ModelInstance::BuildDrawCommands(float animation_tim
}
if(hardwareSkinning) {
for(auto& draw:draws){draw.gpu_skinning=!skin_matrices.empty();draw=ShareGpuMesh(std::move(draw));}
for(auto& draw:draws){draw.gpu_skinning=!skin_matrices.empty();if(!draw.geometry)draw=ShareGpuMesh(std::move(draw));}
m_gpuMain=draws;UpdateGpuDraws(draws,cachedWorld,skin_matrices);
}
}