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:
co-authored by
Claude Opus 5.5
parent
1eccdc87d7
commit
837ccc2f31
@@ -268,6 +268,7 @@ bool HardwareScene::Render(SDL_Renderer* renderer,int width,int height,const std
|
||||
auto* pass=SDL_BeginGPURenderPass(cmd,&color,1,&depth);if(!pass){SDL_CancelGPUCommandBuffer(cmd);return false;}
|
||||
SDL_BindGPUVertexStorageBuffers(pass,0,&instances_,1);
|
||||
float palette[128*16]{};SDL_PushGPUVertexUniformData(cmd,1,palette,sizeof(palette));
|
||||
const std::vector<float>* pushedPalette=nullptr; // draws of one instance share a palette; push once
|
||||
for(size_t i=0;i<batches.size();) {
|
||||
const auto& batch=batches[i];auto* mesh=meshes[i];
|
||||
size_t count=1;
|
||||
@@ -285,7 +286,7 @@ bool HardwareScene::Render(SDL_Renderer* renderer,int width,int height,const std
|
||||
float params[4]={batch.alphaRef,(!batch.blend&&!batch.additive)?1.f:0.f,0,0};SDL_PushGPUFragmentUniformData(cmd,0,params,sizeof(params));
|
||||
auto transform=batch.transform;if(count>1)transform.modes[0]=2;
|
||||
SDL_PushGPUVertexUniformData(cmd,0,&transform,sizeof(transform));
|
||||
if(transform.skin[0]>0){std::fill(std::begin(palette),std::end(palette),0);std::copy_n(batch.palette.data(),std::min(batch.palette.size(),size_t(128*16)),palette);SDL_PushGPUVertexUniformData(cmd,1,palette,sizeof(palette));}
|
||||
if(transform.skin[0]>0 && batch.palette && batch.palette.get()!=pushedPalette){pushedPalette=batch.palette.get();std::fill(std::begin(palette),std::end(palette),0);std::copy_n(batch.palette->data(),std::min(batch.palette->size(),size_t(128*16)),palette);SDL_PushGPUVertexUniformData(cmd,1,palette,sizeof(palette));}
|
||||
SDL_DrawGPUIndexedPrimitives(pass,batch.indexCount,count,mesh ? 0 : batch.firstIndex,0,count>1 ? i : 0);++lastDrawCalls_;i+=count;
|
||||
}
|
||||
SDL_EndGPURenderPass(pass);const auto beforeSubmit=SDL_GetPerformanceCounter();
|
||||
|
||||
Reference in New Issue
Block a user