Phase 30 (2/n) : geometrie compacte, pool de sous-allocation, early-Z

- Formats GPU : le format de travail Vertex (68 o) n'est plus televerse.
  Objets et vegetation : ObjectVertex 44 o (conversion exacte). Terrain :
  TerrainVertex 16 o (deux altitudes f32 + deux normales snorm16) ; x/z,
  cible de morphing et UV sont recalcules par terrain.vert depuis
  gl_VertexIndex et DrawItem::grid, au bit pres (`precise`).
- Topologie des tuiles televersee UNE fois, en uint16 (96 Ko de moins par
  tuile). Indices des maillages d'objets en uint16.
- GpuBufferPool + RangeAllocator : toute la geometrie dans des blocs de
  4 Mo ; ecriture DIRECTE en memoire unifiee (GPU integre, lavapipe),
  staging conserve sur GPU discret (--force-staging pour l'eprouver),
  barriere ecriture-apres-lecture ajoutee devant les copies (validation
  de synchronisation a zero).
- Rendu : terrain dessine apres la vegetation (early-Z) et culling de ses
  faces arriere.
- Tests : +16 verifications (formats, positions recalculees, allocateur).

Survol 900 m/s (lavapipe) : pic GPU 286 -> 89 Mo, geometrie terrain
188 -> 33 Mo, ~17 000 -> 21 vkAllocateMemory, streaming 4,5 -> 1,6 ms
par image. Foret : 8,3 -> 12,4 images/s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MG5dK27RsN97DDm7CQRhx2
Cette révision appartient à :
Claude a révisé 2026-10-13 23:08:23 +00:00
1 Parent 16775bf1ff
révision 7f2d538768
26 fichiers modifiés
+1845 -463

Aucun fichier ne correspond à votre recherche

+53 -31
Voir le fichier
@@ -1,7 +1,7 @@
#pragma once
#include "renderer/GpuVertex.hpp"
#include "renderer/InstanceData.hpp"
#include "renderer/Vertex.hpp"
#include <vulkan/vulkan.h>
@@ -24,60 +24,82 @@ namespace vercora {
// Consequence concrete : la logique de jeu se compile et se teste sans GPU (voir
// tests/logic_tests.cpp), y compris sur une machine ou le SDK n'est pas installe.
// Un seul binding, sommets entrelaces.
inline VkVertexInputBindingDescription vertexBindingDescription() {
// PHASE 30 : DEUX formats de sommet, un par famille de shaders (voir
// renderer/GpuVertex.hpp) - le format de travail CPU `Vertex` n'est plus
// televerse tel quel. Un seul binding entrelace dans les deux cas.
// --- Objets et vegetation : ObjectVertex, 44 octets -------------------------
inline VkVertexInputBindingDescription objectBindingDescription() {
VkVertexInputBindingDescription binding{};
binding.binding = 0;
binding.stride = sizeof(Vertex);
binding.stride = sizeof(ObjectVertex);
binding.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
return binding;
}
// Mapping des attributs vers les location(...) du vertex shader.
//
// Six attributs depuis la Phase 10 : les deux derniers portent la cible de
// geomorphing du terrain (voir Vertex.hpp) et ne sont decrits qu'aux pipelines
// dont le vertex shader les lit reellement.
// `includeMorph` a false pour un vertex shader qui ne lit pas les locations 4/5
// (cube.vert) : les decrire quand meme declencherait un avertissement de
// validation. Voir ShaderSet::usesMorphAttributes.
inline std::array<VkVertexInputAttributeDescription, 6> vertexAttributeDescriptions() {
std::array<VkVertexInputAttributeDescription, 6> attrs{};
// Locations 0 a 3 : position, couleur, normale, UV - les memes que depuis la
// Phase 3, seul le stride a change (les 24 octets de morphing, qu'aucun de ces
// shaders ne lisait, ne sont plus dans le buffer).
inline std::array<VkVertexInputAttributeDescription, 4> objectAttributeDescriptions() {
std::array<VkVertexInputAttributeDescription, 4> attrs{};
attrs[0].binding = 0;
attrs[0].location = 0;
attrs[0].format = VK_FORMAT_R32G32B32_SFLOAT;
attrs[0].offset = offsetof(Vertex, pos);
attrs[0].offset = offsetof(ObjectVertex, pos);
attrs[1].binding = 0;
attrs[1].location = 1;
attrs[1].format = VK_FORMAT_R32G32B32_SFLOAT;
attrs[1].offset = offsetof(Vertex, color);
attrs[1].offset = offsetof(ObjectVertex, color);
attrs[2].binding = 0;
attrs[2].location = 2;
attrs[2].format = VK_FORMAT_R32G32B32_SFLOAT;
attrs[2].offset = offsetof(Vertex, normal);
attrs[2].offset = offsetof(ObjectVertex, normal);
// Deux composantes seulement -> format R32G32.
attrs[3].binding = 0;
attrs[3].location = 3;
attrs[3].format = VK_FORMAT_R32G32_SFLOAT;
attrs[3].offset = offsetof(Vertex, uv);
attrs[3].offset = offsetof(ObjectVertex, uv);
// Position et normale du meme sommet dans la grille du niveau de detail
// SUPERIEUR (plus grossier). Nulles sur toute geometrie qui n'est pas une
// tuile de quadtree : sans effet, le shader ne morphe que si la bande de
// morphing poussee par le DrawItem est non vide.
attrs[4].binding = 0;
attrs[4].location = 4;
attrs[4].format = VK_FORMAT_R32G32B32_SFLOAT;
attrs[4].offset = offsetof(Vertex, morphPos);
return attrs;
}
attrs[5].binding = 0;
attrs[5].location = 5;
attrs[5].format = VK_FORMAT_R32G32B32_SFLOAT;
attrs[5].offset = offsetof(Vertex, morphNormal);
// --- Terrain : TerrainVertex, 16 octets --------------------------------------
inline VkVertexInputBindingDescription terrainBindingDescription() {
VkVertexInputBindingDescription binding{};
binding.binding = 0;
binding.stride = sizeof(TerrainVertex);
binding.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
return binding;
}
// Deux altitudes en flottant, deux normales en snorm16 (x et z, y reconstruit
// par terrain.vert). Tout le reste se deduit de gl_VertexIndex.
inline std::array<VkVertexInputAttributeDescription, 4> terrainAttributeDescriptions() {
std::array<VkVertexInputAttributeDescription, 4> attrs{};
attrs[0].binding = 0;
attrs[0].location = 0;
attrs[0].format = VK_FORMAT_R32_SFLOAT;
attrs[0].offset = offsetof(TerrainVertex, height);
attrs[1].binding = 0;
attrs[1].location = 1;
attrs[1].format = VK_FORMAT_R32_SFLOAT;
attrs[1].offset = offsetof(TerrainVertex, morphHeight);
attrs[2].binding = 0;
attrs[2].location = 2;
attrs[2].format = VK_FORMAT_R16G16_SNORM;
attrs[2].offset = offsetof(TerrainVertex, normal);
attrs[3].binding = 0;
attrs[3].location = 3;
attrs[3].format = VK_FORMAT_R16G16_SNORM;
attrs[3].offset = offsetof(TerrainVertex, morphNormal);
return attrs;
}
@@ -98,7 +120,7 @@ inline VkVertexInputBindingDescription instanceBindingDescription() {
return binding;
}
// Locations 6 a 8 : les locations 0 a 5 appartiennent au sommet (voir plus haut),
// Locations 6 a 8 : les locations basses appartiennent au sommet (voir plus haut),
// et un pipeline instancie decrit les deux flux dans le meme espace de numeros.
// Les trois flottants scalaires (scale, yaw, variation, fade) sont regroupes en
// deux attributs plutot qu'en quatre : moins d'attributs a decrire, et le shader