bvle-voxels/README.md
Samuel Bouchet cd9814e494 Phase 5.2-5.3: CPU perf optimizations + GPU compute Surface Nets
CPU smooth mesher optimizations (560ms → 17ms):
- VoxelData grid cache eliminates redundant readVoxel calls
- Pre-cached 27 neighbor chunk pointers (readVoxelFast)
- smoothNear dilation (8 lookups/cell instead of 56)
- Early exit via containsSmooth flag on chunks
- Thread-local scratch buffers (SmoothScratch ~600KB)
- wi::jobsystem parallelization across all cores
- Persistent staging vectors for upload

TopingSystem optimizations (58ms → 6ms):
- collectInstancesParallel() with per-chunk local vectors
- Neighbor chunk pointer caching

GPU compute Surface Nets (Phase 5.3):
- Two-pass compute shader: centroid grid + emit with smooth normals
- Pass 1 (voxelSmoothCentroidCS): computes centroids + solid flags
  for cells [-1..32], cross-chunk neighbor voxel reading
- Pass 2 (voxelSmoothCS): reads ONLY from centroid grid, computes
  area-weighted smooth normals from 12 incident edges per vertex
- Batched dispatch: all centroid passes then all emit passes with
  single UAV→SRV barrier (instead of 2 barriers per chunk)
- Smooth chunk filtering: only dispatches chunks with containsSmooth
- Centroid grid buffer dynamically sized per smooth chunk count
- 1-frame readback delay with auto-redispatch on first frame
2026-03-27 22:30:43 +01:00

118 lines
4.6 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# BVLE Voxels
Prototype de moteur voxel hybride basé sur [Wicked Engine](https://github.com/turanszkij/WickedEngine) (MIT, C++17, DX12/Vulkan).
Cible : **60+ fps en 1440p**, monde de 512×512×256 voxels visibles.
## Prérequis
| Outil | Version | Installation |
|-------|---------|-------------|
| **Windows** | 10/11 (x64) | — |
| **CMake** | 3.19+ | `winget install Kitware.CMake` |
| **Visual Studio 2022 Build Tools** | 17.x | `winget install Microsoft.VisualStudio.2022.BuildTools` |
| **Windows SDK** | 10.0.26100+ | `winget install Microsoft.WindowsSDK.10.0.26100` |
| **GPU** | DX12 feature level 12.0+ | AMD RDNA 2+ / Nvidia RTX 3060+ recommandé |
> Le SDK **10.0.26100** est requis car les headers DX12 fournis par Wicked Engine ne sont pas compatibles avec le SDK 22621.
## Installation
```bash
# 1. Cloner le dépôt
git clone <url> bvle-voxels
cd bvle-voxels
# 2. Cloner Wicked Engine dans engine/
git clone --depth 1 https://github.com/turanszkij/WickedEngine.git engine
# 3. Configurer CMake
cmake -B build -G "Visual Studio 17 2022" -A x64 -DCMAKE_SYSTEM_VERSION=10.0.26100.0
# 4. Compiler
cmake --build build --config Release --target BVLEVoxels --parallel
# 5. Lancer
./build/Release/BVLEVoxels.exe
```
## Commandes de lancement
| Commande | Description |
|----------|-------------|
| `BVLEVoxels.exe` | Mode normal (monde procédural, rayon 4 chunks) |
| `BVLEVoxels.exe debug` | Mode debug face-color (+X=Rouge, -X=Rouge sombre, etc.) |
| `BVLEVoxels.exe debugdevice` | Active la couche de debug D3D12 |
| `BVLEVoxels.exe vulkan` | Force le backend Vulkan |
## Contrôles
| Touche | Action |
|--------|--------|
| **WASD** | Déplacement caméra |
| **Espace / Ctrl** | Monter / Descendre |
| **Shift** | Vitesse ×3 |
| **Clic droit** | Capturer/libérer la souris |
| **~** (tilde) | Console Wicked Engine |
## Architecture
```
bvle-voxels/
├── CMakeLists.txt # Build CMake
├── engine/ # Wicked Engine (git clone --depth 1)
├── src/
│ ├── voxel/ # Bibliothèque VoxelEngine (static lib)
│ │ ├── VoxelTypes.h # Types (VoxelData, PackedQuad, ChunkPos)
│ │ ├── VoxelWorld.h/.cpp # Monde voxel (hashmap, génération Perlin)
│ │ ├── VoxelMesher.h/.cpp # Binary Greedy Mesher CPU
│ │ └── VoxelRenderer.h/.cpp# Renderer GPU-driven + VoxelRenderPath
│ └── app/
│ └── main.cpp # Point d'entrée Win32
├── shaders/ # Sources HLSL
│ ├── voxelCommon.hlsli # Root signature, CB, structs partagés
│ ├── voxelVS.hlsl # Vertex shader (vertex pulling)
│ ├── voxelPS.hlsl # Pixel shader (triplanar + lighting)
│ ├── voxelCullCS.hlsl # Compute: frustum + backface culling
│ └── voxelMeshCS.hlsl # Compute: GPU mesher (binary, baseline)
└── voxel_engine_spec.md # Document de spécification complet (Markdown)
```
## Pipeline de rendu (Phase 2 — GPU-driven)
```
CPU: mesh dirty chunks (greedy merge) → pack quads + chunkInfo dans mega-buffers → upload GPU
GPU: frustum cull compute → indirect args → DrawInstancedIndirectCount (1 appel = N draws)
```
**Buffers GPU :**
| Buffer | Type | Slot | Rôle |
|--------|------|------|------|
| `megaQuadBuffer_` | StructuredBuffer\<PackedQuad\> | SRV t0 | 2M quads max (16 MB) |
| `chunkInfoBuffer_` | StructuredBuffer\<GPUChunkInfo\> | SRV t2 | 2048 chunks max |
| `indirectArgsBuffer_` | RWStructuredBuffer | UAV u0 | Indirect draw args |
| `drawCountBuffer_` | RWByteAddressBuffer | UAV u1 | Compteur atomique de draws |
**Caractéristiques Phase 2 :**
- Mega-buffer unique pour tous les quads de tous les chunks
- Vertex pulling via `SV_VertexID` + push constants (`b999`)
- Frustum culling CPU (wi::primitive::Frustum)
- Backface culling par face group (6 directions × chunk)
- GPU frustum cull compute shader (prêt, activation via flag)
- GPU mesher compute shader baseline (binary, sans greedy merge)
- Tri des quads par direction de face dans le mesher CPU
- GPU timestamp queries pour benchmark
## Phases de développement
- [x] **Phase 1** — Setup, meshing CPU, rendu basique
- [x] **Phase 2** — GPU-driven pipeline, mega-buffer, culling, compute shaders
- [x] **Phase 3** — Texture blending (triplanar, height-based)
- [x] **Phase 4** — Toping (rebords, bordures procédurales)
- [x] **Phase 5** — Rendu smooth (Surface Nets / Marching Cubes)
- [ ] **Phase 6** — Ray tracing hybride (RT shadows + AO)
## Licence
Wicked Engine est sous licence MIT. Le code spécifique BVLE est propriétaire.