render: resolve GPU textures once per draw and sort by handle

RenderSceneGPU resolves each draw's texture while classifying it and
sorts opaque draws by the texture handle instead of comparing paths;
invalid draws are dropped before sorting. Bumps sdk (skin cache).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-10-12 16:30:32 +09:00
co-authored by Claude Opus 5.5
parent f03f63e700
commit 545cbb1e5d
4 changed files with 28 additions and 10 deletions
+1 -1
Submodule sdk updated: 9ec7fa10c0...16d16de90d
+11 -9
View File
@@ -829,7 +829,15 @@ void Gr2SceneRenderer::RenderSceneGPU(SDL_Renderer* renderer, const std::vector<
DrawOrder ord;
ord.draw = &d;
const auto& sortedMesh = d.Mesh();
if (!sortedMesh.positions.empty()) {
if (d.Indices().size < 3 || sortedMesh.positions.size() < 9) continue;
if (d.texture0.empty() && sortedMesh.diffuse.empty()) continue;
if (m_hardware && !d.texture0.empty()) {
ord.texture=m_hardware->FindTexture(d.texture0);
if(!ord.texture){const auto* data=GetTexture(d.texture0);if(!data)continue;
ord.texture=m_hardware->Texture(d.texture0,data->width,data->height,data->rgba.data());}
if(!ord.texture)continue;
}
{
float cx = sortedMesh.positions[0], cy = sortedMesh.positions[1], cz = sortedMesh.positions[2];
float wx = cx * d.world[0] + cy * d.world[4] + cz * d.world[8] + d.world[12];
float wy = cx * d.world[1] + cy * d.world[5] + cz * d.world[9] + d.world[13];
@@ -859,7 +867,7 @@ void Gr2SceneRenderer::RenderSceneGPU(SDL_Renderer* renderer, const std::vector<
if(m_hardware && a.priority==1) {
if(a.draw->alpha_blend!=b.draw->alpha_blend)return !a.draw->alpha_blend;
if(!a.draw->alpha_blend) {
if(a.draw->texture0!=b.draw->texture0)return a.draw->texture0<b.draw->texture0;
if(a.texture!=b.texture)return std::less<SDL_GPUTexture*>{}(a.texture,b.texture);
if(a.draw->geometry.get()!=b.draw->geometry.get())return std::less<const Render3DDraw*>{}(a.draw->geometry.get(),b.draw->geometry.get());
return a.depth<b.depth;
}
@@ -898,13 +906,7 @@ void Gr2SceneRenderer::RenderSceneGPU(SDL_Renderer* renderer, const std::vector<
size_t num_verts = mesh.positions.size() / 3;
if (m_hardware) {
SDL_GPUTexture* texture=nullptr;
if (!draw.texture0.empty()) {
texture=m_hardware->FindTexture(draw.texture0);
if(!texture){const auto* data=GetTexture(draw.texture0);if(!data)continue;
texture=m_hardware->Texture(draw.texture0,data->width,data->height,data->rgba.data());}
if(!texture)continue;
}
SDL_GPUTexture* texture=ord.texture;
HardwareBatch batch{};batch.texture=texture;batch.cull=draw.cull_mode;
batch.depth=draw.z_enable;batch.depthWrite=draw.z_enable&&draw.z_write;
batch.blend=draw.alpha_blend;batch.additive=draw.blend_mode==1;
+1
View File
@@ -148,6 +148,7 @@ private:
int priority = 1;
float depth = 0.0f;
const Render3DDraw* draw = nullptr;
SDL_GPUTexture* texture = nullptr; // resolved once per draw; also the opaque sort key
};
float m_eye[3] = {0.0f, 0.0f, 0.0f};
+15
View File
@@ -117,6 +117,21 @@ int main(int argc, char** argv) {
std::cout << "Draw " << i << " texture0: '" << draws[i].texture0 << "'" << std::endl;
}
assert(!draws.empty() && "Must produce at least one 3D draw command");
{
// GPU draw caches keep skinned texture names; skin changes after the cache is built must apply.
auto skinned = ava2::Gr2ModelInstance::Load(model_path);assert(skinned);
const auto base = skinned->BuildDrawCommands(-1.0f, nullptr, true);assert(!base.empty());
assert(skinned->BuildDrawCommands(-1.0f, nullptr, true)[0].texture0 == base[0].texture0);
std::string upper = base[0].texture0;for (auto& c : upper) c = static_cast<char>(std::toupper(static_cast<unsigned char>(c)));
skinned->SetSkin(upper, "skin-test.dds");
assert(skinned->BuildDrawCommands(-1.0f, nullptr, true)[0].texture0 == "skin-test.dds");
assert(skinned->BuildDrawCommands(-1.0f, nullptr, true)[0].texture0 == "skin-test.dds");
skinned->ClearSkins();
assert(skinned->BuildDrawCommands(-1.0f, nullptr, true)[0].texture0 == base[0].texture0);
auto fresh = ava2::Gr2ModelInstance::Load(model_path);assert(fresh);fresh->SetSkin(base[0].texture0, "skin-test.dds");
assert(fresh->BuildDrawCommands(-1.0f, nullptr, true)[0].texture0 == "skin-test.dds");
assert(fresh->BuildDrawCommands(-1.0f, nullptr, true)[0].texture0 == "skin-test.dds");
}
// Setup 3D Scene Renderer
const int width = 1024;