render: draw tri-groups as index sub-ranges of one resident mesh

Render3DDraw/HardwareBatch carry first_index/index_count; resident
meshes are uploaded once per model and groups draw with firstIndex.
Bumps sdk to 9ec7fa1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-10-12 16:27:05 +09:00
co-authored by Claude Opus 5.5
parent d5333745c5
commit f03f63e700
6 changed files with 53 additions and 19 deletions
+4 -1
View File
@@ -726,7 +726,10 @@ int main(int argc, char** argv) {
assert(!g.gpu_skinning || g.palette);
const auto& mesh=*g.geometry;
assert(cpu[d].positions.size()==mesh.positions.size());
assert(cpu[d].indices==mesh.indices);
// Tri-groups share one geometry per mesh; each GPU draw covers its own index range.
assert(g.first_index+size_t(cpu[d].indices.size())<=mesh.indices.size() || g.index_count==0);
assert(std::equal(cpu[d].indices.begin(),cpu[d].indices.end(),mesh.indices.begin()+std::min<size_t>(g.first_index,mesh.indices.size())));
assert(g.index_count==UINT32_MAX ? cpu[d].indices.size()==mesh.indices.size() : cpu[d].indices.size()==g.index_count);
for(size_t v=0;v<mesh.positions.size()/3;++v) {
float p[3]{},n[3]{},total=0;
if(g.gpu_skinning)for(int b=0;b<4;++b) {
+15
View File
@@ -138,6 +138,21 @@ int main() {
pixels=frame({offscreen,left,right});
assert(resident.GetLastDrawCallCount()==2 && redAt(16)>245 && redAt(48)>120 && redAt(48)<135);
SDL_DestroySurface(pixels);
// Tri-group sub-ranges share one resident buffer; firstIndex selects the right-hand triangle only.
{
auto groups=std::make_shared<ava2::Render3DDraw>(*mesh);
groups->positions={-.65f,-.2f,.5f,-.35f,-.2f,.5f,-.5f,.2f,.5f, .35f,-.2f,.5f,.65f,-.2f,.5f,.5f,.2f,.5f};
groups->indices={0,1,2,3,4,5};groups->diffuse=std::vector<uint32_t>(6,0xffff0000);
auto second=left;second.geometry=groups;second.transform.mvp[12]=0;second.firstIndex=3;second.indexCount=3;
const auto uploads=resident.GetResidentUploadCount();
pixels=frame({second});
assert(resident.GetResidentUploadCount()==uploads+1 && resident.GetLastDynamicUploadBytes()==0);
assert(redAt(48)>245 && redAt(16)<5);SDL_DestroySurface(pixels);
auto first=second;first.firstIndex=0;
pixels=frame({first,second});
assert(resident.GetResidentUploadCount()==uploads+1 && resident.GetLastDrawCallCount()==2);
assert(redAt(16)>245 && redAt(48)>245);SDL_DestroySurface(pixels);
}
// Bone translation moves the raw triangle to the center; no CPU-deformed stream is uploaded.
left.transform.skin[0]=1;left.palette=std::make_shared<std::vector<float>>(std::vector<float>{1,0,0,0,0,1,0,0,0,0,1,0,.5f,0,0,1});
auto skinned=std::make_shared<ava2::Render3DDraw>(*mesh);skinned->bone_indices=std::vector<uint8_t>(12,0);skinned->bone_weights={1,0,0,0,1,0,0,0,1,0,0,0};left.geometry=skinned;