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.
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
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.
CPPcheck found most of them.
no need to assign the variable twice:
- AnimationTrackEditTypeAudio
- SSEffects
variable is assigned in all if-else clauses:
- EditorHelp
- AndroidInputHandler
- MenuBar
- ShaderCompiler
same if clause:
- ItemList
clearing an empty bitfield has no effect:
- Viewport
This also fixes RENDERING_INFO_TOTAL_PRIMITIVES_IN_FRAME for the RD renderers as it was incorrectly reporting vertex/index count at times
This also adds memory tracking to textures and buffers to catch memory leaks.
This also cleans up some memory leaks that the new system caught.
If using normal buffer debugging or if the normal texture was used, we should use PASS_MODE_DEPTH_NORMAL_ROUGHNESS regardless of whether there is a valid Environment or not. Otherwise, shaders reading the normal texture will not work without a valid Environment (and possibly other problems).
The OpenGL implementation has used GL_FUNC_REVERSE_SUBTRACT for a long time, but the new RenderingDevice abstraction used by the Vulkan renderers had been mistakenly set to BLEND_OP_SUBTRACT instead of BLEND_OP_REVERSE_SUBTRACT.
Fixes#77448