Share GPU skinning palette per instance; push it once per change

Render3DDraw/HardwareBatch hold the SDK's shared palette instead of
copying 16 floats per bone per draw, and HardwareScene re-pushes the
uniform only when the palette pointer changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-10-12 16:12:14 +09:00
co-authored by Claude Opus 5.5
parent 1eccdc87d7
commit 837ccc2f31
7 changed files with 19 additions and 13 deletions
+4 -4
View File
@@ -139,20 +139,20 @@ int main() {
assert(resident.GetLastDrawCallCount()==2 && redAt(16)>245 && redAt(48)>120 && redAt(48)<135);
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={1,0,0,0,0,1,0,0,0,0,1,0,.5f,0,0,1};
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;
pixels=frame({left});assert(redAt(32)>245 && redAt(16)<5);SDL_DestroySurface(pixels);
// Two weighted, rotated bones: compare every rendered pixel to CPU-transformed vertices.
left.transform.skin[0]=2;
left.palette={1,0,0,0,0,1,0,0,0,0,1,0,.2f,0,0,1,
0,1,0,0,-1,0,0,0,0,0,1,0,.7f,0,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,.2f,0,0,1,
0,1,0,0,-1,0,0,0,0,0,1,0,.7f,0,0,1});
skinned=std::make_shared<ava2::Render3DDraw>(*mesh);
skinned->bone_indices={0,1,0,0,0,1,0,0,0,1,0,0};
skinned->bone_weights={.4f,.6f,0,0,.4f,.6f,0,0,.4f,.6f,0,0};
left.geometry=skinned;pixels=frame({left});
std::vector<ava2::HardwareVertex> reference;
for(size_t v=0;v<3;++v){auto vertex=ava2::MakeHardwareVertex(*skinned,v);float pos[4]{};
for(size_t b=0;b<2;++b){const auto* matrix=left.palette.data()+b*16;float w=vertex.weights[b];
for(size_t b=0;b<2;++b){const auto* matrix=left.palette->data()+b*16;float w=vertex.weights[b];
for(int k=0;k<4;++k)pos[k]+=(vertex.position[0]*matrix[k]+vertex.position[1]*matrix[k+4]+vertex.position[2]*matrix[k+8]+matrix[k+12])*w;}
std::copy_n(pos,4,vertex.position);vertex.position[0]-=.5f;reference.push_back(vertex);}
ava2::HardwareBatch cpu{};cpu.indexCount=3;cpu.cull=1;cpu.depth=true;cpu.depthWrite=true;cpu.alphaRef=-1;