feat(gpu): afegir suport SPIRV (Vulkan) per Linux/Windows

- Nou: shaders/sprite.vert|frag, postfx.vert|frag, ball.vert (GLSL)
- Nou: cmake/spv_to_header.cmake — converteix .spv → uint8_t C header
- CMakeLists.txt: bloc non-Apple troba glslc, compila GLSL → SPIRV en
  build-time i genera headers embeguts a build/generated_shaders/
- gpu_context.cpp: MSL|METALLIB en Apple, SPIRV en la resta
- gpu_pipeline.cpp: createShaderSPIRV() + branques #ifdef __APPLE__
  per sprite/ball/postfx pipelines
- Corregeix crash a engine.cpp:821 (Windows/Linux) causat per pipelines
  null quan init() fallava en no trobar suport MSL

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-20 09:47:36 +01:00
parent 5c0d0479ad
commit 6ffe7594ab
9 changed files with 201 additions and 5 deletions

View File

@@ -6,10 +6,12 @@
bool GpuContext::init(SDL_Window* window) {
window_ = window;
// Create GPU device — prefer Metal on macOS, Vulkan elsewhere
SDL_GPUShaderFormat preferred = SDL_GPU_SHADERFORMAT_MSL
| SDL_GPU_SHADERFORMAT_METALLIB
| SDL_GPU_SHADERFORMAT_SPIRV;
// Create GPU device: Metal on Apple, Vulkan elsewhere
#ifdef __APPLE__
SDL_GPUShaderFormat preferred = SDL_GPU_SHADERFORMAT_MSL | SDL_GPU_SHADERFORMAT_METALLIB;
#else
SDL_GPUShaderFormat preferred = SDL_GPU_SHADERFORMAT_SPIRV;
#endif
device_ = SDL_CreateGPUDevice(preferred, false, nullptr);
if (!device_) {
std::cerr << "GpuContext: SDL_CreateGPUDevice failed: " << SDL_GetError() << std::endl;