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
@@ -18,6 +18,7 @@
|
||||
#include <iostream>
|
||||
#include <filesystem>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <fstream>
|
||||
#include <chrono>
|
||||
#include "test_rundir.h"
|
||||
@@ -716,8 +717,13 @@ int main(int argc, char** argv) {
|
||||
assert(cpu.size()==gpu.size());
|
||||
auto again=instance.GetImpl()->BuildDrawCommands(time+.1f,nullptr,true);
|
||||
assert(again.size()==gpu.size());
|
||||
// One palette per instance per frame: draws of a mesh/part share it instead of copying.
|
||||
std::set<const void*> palettes;size_t skinned=0;
|
||||
for(const auto& g:gpu)if(g.gpu_skinning){palettes.insert(g.palette.get());++skinned;}
|
||||
assert(skinned<2 || palettes.size()<skinned);
|
||||
for(size_t d=0;d<cpu.size();++d) {
|
||||
const auto& g=gpu[d];assert(g.geometry && again[d].geometry==g.geometry);
|
||||
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);
|
||||
@@ -725,8 +731,8 @@ int main(int argc, char** argv) {
|
||||
float p[3]{},n[3]{},total=0;
|
||||
if(g.gpu_skinning)for(int b=0;b<4;++b) {
|
||||
const auto bone=mesh.bone_indices[v*4+b];const float w=mesh.bone_weights[v*4+b];
|
||||
if(w<=0 || size_t(bone)*16+15>=g.bone_matrices.size())continue;
|
||||
const auto* m=g.bone_matrices.data()+bone*16;
|
||||
if(w<=0 || size_t(bone)*16+15>=g.palette->size())continue;
|
||||
const auto* m=g.palette->data()+bone*16;
|
||||
for(int k=0;k<3;++k){p[k]+=(mesh.positions[v*3]*m[k]+mesh.positions[v*3+1]*m[k+4]+mesh.positions[v*3+2]*m[k+8]+m[k+12])*w;
|
||||
n[k]+=(mesh.normals[v*3]*m[k]+mesh.normals[v*3+1]*m[k+4]+mesh.normals[v*3+2]*m[k+8])*w;}
|
||||
total+=w;
|
||||
|
||||
Reference in New Issue
Block a user