begin et end frame dans context

This commit is contained in:
Jérôme Bousquié
2026-07-04 14:57:29 +02:00
parent 4fd39d32c6
commit 4b7a1b05e5
3 changed files with 98 additions and 1 deletions
+42
View File
@@ -0,0 +1,42 @@
# Technical Architecture Summary
## Three-Layer Structure
### Manager Layer (`Context`)
- **Responsibility:** Owner of hardware resource lifecycles (`Device`, `Queue`, `Surface`, `SurfaceConfiguration`).
- **Role:** Encapsulates windowing system and swapchain complexity. Exposes high-level methods such as `begin_frame()` and `end_frame()` to orchestrate GPU transactions.
### Specialist Layer (`Renderer`)
- **Responsibility:** Owner of rendering logic (`RenderPipeline`, `Shaders`, `Buffers`).
- **Role:** Executes actual drawing. Does not own hardware resources — uses references (`&Device`, `&TextureView`) provided at call time.
### Orchestrator Layer (`main.rs`)
- **Responsibility:** Business logic and execution loop.
- **Role:** Calls `Context` methods to obtain the target texture, passes that target to the `Renderer`, then triggers presentation.
---
## Benefits Analysis
### 1. Independence & Modularity
- **Runtime Agnosticism:** By avoiding any async calls or dependencies on runtimes like Tokio within the library, we ensure the code is portable and can be integrated into any kind of project (game, visualization tool, UI).
- **Decoupling:** The `Renderer` does not know about the existence of the windowing system (Winit). It could just as well draw onto an off-screen texture for headless rendering.
### 2. Performance & Efficiency
- **CPU/GPU Parallelism:** Using the `begin_frame` / `end_frame` pattern with a per-frame `CommandEncoder`, we maximize GPU utilization: the CPU prepares commands for one frame while the GPU executes those from the previous frame.
- **Persistent Resource Management:** The `Renderer` retains heavy objects (`RenderPipeline`) compiled only once. Conversely, ephemeral objects (`CommandEncoder`, `TextureView`) are created and freed quickly, minimizing long-term memory footprint.
### 3. Robustness (Safety & Errors)
- **Explicit Error Handling:** Use of `Result` types and safe methods such as `.first()` (instead of manual indexing) prevents panics during initialization or resizing, protecting the application against graphics driver instabilities.
---
## Summary
This structure transforms what is often called "spaghetti" graphics code — a mix of window management and shader computation — into a clean, predictable pipeline. The `Context` prepares the ground, the `Renderer` performs the drawing, and the orchestrator maintains the rhythm.