godotengine / godotengine/godot
Shader baker generates baked sources with the host editor's RENDER_DRIVER_ define instead of the target driver's
- Dominant language
- C++
- Stars
- 117k
- Forks
- 26.8k
- PR merge metrics
- PR metrics pending
Description
### Tested versions
4.7.1.stable
### System information
macOS Tahoe - Godot v4.7.1.stable - Metal (Mobile) - Macbook PRO M3 MAX
### Issue description
While investigating why my game's Windows exports rendered incorrectly when exported from a macOS editor with the shader baker enabled (the same project exported on Windows looked correct, and disabling the baker for the Windows preset also fixed it), I audited the shader baker path and found a host/target mismatch in the generated shader sources.
### Steps to reproduce
Some context, transparently: I'm new to the engine's internals. In my (fairly complex) project, Windows builds exported from the macOS editor with the shader baker enabled rendered visibly different from expected, more specifically washed out / too bright and that while the same project exported on Windows, or exported from macOS with the baker disabled, looked correct.
While digging through the shader baker to understand the asymmetry, I found a defect that is verifiable directly in the code:
When the shader baker bakes shaders for another platform, it generates them with the define of the driver the editor is running on, not the driver of the platform being exported to.
Open the editor on macOS (running on Metal).
Enable Shader Baker in a Windows export preset.
To see what gets baked, add a temporary print in _ShaderBakerExportPlugin::_process_work_item_:
`print_line(p_work_item.stage_sources[RD::SHADER_STAGE_FRAGMENT].left(2048));`
Export for Windows.
Expected: the baked shader sources contain #define RENDER_DRIVER_VULKAN / _D3D12 / the drivers the export will run on.
Actual: they contain #define RENDER_DRIVER_METAL which is the the editor's own driver in my case.
### Minimal reproduction project (MRP)
MRP: N/A for now. I couldn't reproduce my project's visual issue in a minimal project.
Contributor guide
Research direction
Start at _ShaderBakerExportPlugin::_process_work_item_ and inspect how stage_sources are generated during cross-platform export. Use the reported macOS-to-Windows export scenario and the temporary shader-source print to trace which driver define is selected. Done means baked sources use the target export driver's RENDER_DRIVER_ define rather than the host editor's define.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- build-system, computer-graphics
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100