The first time a shader is compiled Godot performs the following:
```cpp
for (uint32_t i = 0; i < SHADER_STAGE_MAX; i++) {
if
(spirv_data.push_constant_stages_mask.has_flag((ShaderStage)(1 << i))) {
binary_data.push_constant_vk_stages_mask |=
shader_stage_masks[i];
}
}
```
However binary_data.push_constant_vk_stages_mask is never initialized to
0 and thus contains garbage data or'ed with the good data.
This value is used by push constants (and many other things) thus it can
be a big deal.
Fortunately because the relevant flags are always guaranteed to be set
(but not guaranteed to be unset), the damage is restricted to:
1. Performance (unnecessary flushing & over-excessive barriers)
2. Overwriting push descriptors already set (this would be serious,
doesn't seem to be an issue)
3. Driver implementations going crazy when they see bits set they don't
expect (unknown if this is an issue)
This uninitialized value is later saved into the binary cache.
Valgrind is able to detect this bug on the first run, but not on the
subsequent ones because they data comes from a file.
cache_file_version has been bumped to force rebuild of all cached
shaders. Because the ones generated so far are compromised.
As more users use compute in Godot 4, the way they do is most likely incompatible when running
on separate threads and will start erroring soon as we improve the thread safety of the render thread.
To properly run code on the render thread, this function was added. Use like this:
```GDScript
func initialize_compute_code():
....
func update_compute_code(custom_data):
...
func _ready():
RenderingServer.call_on_render_thread( initialize_compute_code )
func _process():
RenderingServer.call_on_render_thread( update_compute_code.bind(with_data) )
```
discard was being included in all shaders set to depth pass opaque, which is the majority of shaders
Instead it should only be used with alpha prepass materials
This allows us to specify a subset of variants to compile at load time and conditionally other variants later.
This works seamlessly with shader caching.
Needed to ensure that users only pay the cost for variants they use
Commit 2c000cb72f changed the interpolation limits from (0.04, 1.0) to (0.04, 0.37). This is incorrect, as we want to have an F0 of 0.04 for dielectrics (materials with metalness of 0.0) and an F0 of 1.0 for metals.
The Schlick approximation uses an F0 of 0.04 for all dielectrics and it's good enough.
Having it lower than 1.0 leads to an incorrect application of the Fresnel effect for metals and leads to bugs like #79549
Explicitly clear the separate specular buffer when the background mode is canvas and screen space effects (and thus a separate specular buffer) are used.