Commit Graph

3603 Commits

Author SHA1 Message Date
Jeroen Bakker
e2dc63c5de Fix #147618: PyGPU incorrect colors when drawing images
644fb2b679 fixed a long standing issue
that offscreen example showed the wrong colors. However the fix assumes
that input texture color space is always sRGB.

This adds a shader variation that draws textures that are stored in scene referred
linear color space (like all of our Image data-block).

Co-authored-by: Clément Foucault <foucault.clem@gmail.com>
Pull Request: https://projects.blender.org/blender/blender/pulls/147788
2025-10-16 19:12:16 +02:00
Miguel Pozo
8c425ccd4d Cleanup: Remove unused variables 2025-10-08 16:59:20 +02:00
Miguel Pozo
71f4277467 GPU: Codegen: Native support for repeat zones
Support loops at the GLSL level instead of relying on
NOD_shader_nodes_inline.
This improves compilation and runtime performance, avoids causing
recompilations on iteration count changes, and allows supporting
dynamic iteration counts.

(EEVEE-only)

Pull Request: https://projects.blender.org/blender/blender/pulls/145269
2025-10-08 16:38:14 +02:00
Jeroen Bakker
c279d894db Fix #141013: VSE: Show pure emissive colors in preview
VSE doesn support pure emissive colors when rendering, but weren't
showed inside the preview. This was a limitation when the background
checkerbord is draw. It renders the alpha of the overlay to 1.0 making
the background be drawn on top of the image, hiding the pure emissive
colors.

This PR fixes this by clearing the alpha. This will render the
checkerboard below the image.

Another solution would be to set the alpha to zero in the theme, but that
adds confusion as theme colors will still be able to alter the support of
pure emissive colors.

Pull Request: https://projects.blender.org/blender/blender/pulls/146562
2025-10-03 10:19:19 +02:00
Hans Goudey
a68d39e9d9 Cleanup: Formatting
Run `make format` after the library update in the previous commit.
2025-10-02 12:55:42 -04:00
hogan.mastanduno
dde9d21b91 OpenXR: VR Advanced Locomotion Phase 1
Includes the following changes to the existing Locomotion system for VR Scene Inspection:
 * new VR Navigation Preferences and VR Session Settings
 * changes to XR raycast logic and its visualization
 * new XR vignette that appears when moving
 * snap turning

Pull Request: https://projects.blender.org/blender/blender/pulls/144241
2025-10-01 22:16:12 +02:00
Aras Pranckevicius
ed9fc54e0e Fix #147006: VSE preview crashes with too high output resolution
Check whether creating GPU textures succeeds before using them.
However, currently when that happens there is no indication to the user
that "hey the resolution is maybe too big". Not sure what is the best
way to do that however; e.g. Workbench rendering also does not
indicate that in a similar scenario.

While at it, add GPU_is_safe_texture_size instead of duplicating
the same logic in two places.

Pull Request: https://projects.blender.org/blender/blender/pulls/147043
2025-10-01 10:08:18 +02:00
Clément Foucault
7ad9a2a72b GPU: Move gl_FragStencilRefARB to be scanned and added to created info 2025-09-30 21:33:33 +02:00
Clément Foucault
ef8319aaee GPU: ShaderCreateInfo: Add convenience ResourceString
This will improve readability of shader resource generation
code.
2025-09-30 20:54:46 +02:00
Clément Foucault
596062329d GPU: Improve shader dependency logger
Add shader name to graph.
Strip CLOG prefix for mermaid lines.
2025-09-29 16:31:47 +02:00
Jeroen Bakker
a0370d2fe3 Fix: Vulkan: Performance regression text drawing
7becc38a3c introduced new text rendering.
In the refactoring the vertex buffer was replaced by a more shallow
storage buffer. However the refactoring removed one optimization that
the vulkan backend uses, namely the actual amount of bytes that is being
used by the draw call. This resulted in overly large data transfers.

For example in the text editor the texts are rendered one glyph at a
time. But the storage buffer would always upload the data for 1024
glyphs.

This PR allows the usage size of a storage buffer to be set to ensure
that the data transfers are limited.

The implementation wasn't added to OpenGL as it draws incorrectly.

Issue detected during the research of !146956 That PR will implement
better data streaming inside the Vulkan backend and also requires
to know the actual usage size of the buffer to detect what data can
be grouped together.

Pull Request: https://projects.blender.org/blender/blender/pulls/146958
2025-09-29 15:55:31 +02:00
Clément Foucault
23134124dc LOG: Change shader dependency printing to its own prefix
This avoid flooding the console when using --debug-gpu.
2025-09-29 14:06:33 +02:00
Clément Foucault
fe213f80a4 GPU: Shader: Make info files generated
This is the first step of moving the create infos
back inside shader sources.

All info files are now treated as source files.
However, they are not considered in the include tree
yet. This will come in another following PR.

Each shader source file now generate a `.info` file
containing only the create info declarations.

This renames all info files so that they do not
conflict with their previous versions that were
copied (non-generated).

Pull Request: https://projects.blender.org/blender/blender/pulls/146676
2025-09-25 10:57:02 +02:00
Clément Foucault
e098441b5a GPU: Material: Improve limit of UBO size
This moves the UBO size limit to be a capability.
This allows to check if size fits the requirements before
creating it and avoids hitting an assert.

Rel #146705

Pull Request: https://projects.blender.org/blender/blender/pulls/146728
2025-09-25 09:44:12 +02:00
Clément Foucault
acb2f02910 EEVEE: Reduce necessary includes
This saves a few milisecond of compile time per shader.

This removes the need for occlusion lib when not using occlusion
node.

To improve detection of uneeded includes, we add a new logging
system which output can be fed to mermaid to inspect dependencies.

The new dependencies can be inspected using `--log "gpu.shader_dependencies"`

Example pasted here:
```mermaid
flowchart LR
draw_curves_lib.glsl_7298 --> gpu_shader_math_constants_lib.glsl_600
style gpu_shader_math_constants_lib.glsl_600 fill:#0f0
gpu_shader_math_matrix_conversion_lib.glsl_1032 --> gpu_shader_math_base_lib.glsl_1406
style gpu_shader_math_base_lib.glsl_1406 fill:#1e0
gpu_shader_math_matrix_conversion_lib.glsl_1032 --> gpu_shader_math_euler_lib.glsl_461
style gpu_shader_math_euler_lib.glsl_461 fill:#0f0
gpu_shader_math_matrix_compare_lib.glsl_2964 --> gpu_shader_math_vector_compare_lib.glsl_2489
style gpu_shader_math_vector_compare_lib.glsl_2489 fill:#2d0
gpu_shader_math_matrix_conversion_lib.glsl_1032 --> gpu_shader_math_matrix_compare_lib.glsl_2964
style gpu_shader_math_matrix_compare_lib.glsl_2964 fill:#2d0
gpu_shader_math_matrix_conversion_lib.glsl_1032 --> gpu_shader_math_quaternion_lib.glsl_395
style gpu_shader_math_quaternion_lib.glsl_395 fill:#0f0
gpu_shader_math_matrix_conversion_lib.glsl_1032 --> gpu_shader_utildefines_lib.glsl_3112
style gpu_shader_utildefines_lib.glsl_3112 fill:#3c0
draw_curves_lib.glsl_7298 --> gpu_shader_math_matrix_conversion_lib.glsl_1032
style gpu_shader_math_matrix_conversion_lib.glsl_1032 fill:#1e0
draw_curves_lib.glsl_7298 --> gpu_shader_math_matrix_transform_lib.glsl_706
style gpu_shader_math_matrix_transform_lib.glsl_706 fill:#0f0
eevee_surf_deferred_frag.glsl_4531 --> draw_curves_lib.glsl_7298
style draw_curves_lib.glsl_7298 fill:#780
eevee_surf_deferred_frag.glsl_4531 --> draw_view_lib.glsl_3551
style draw_view_lib.glsl_3551 fill:#3c0
eevee_gbuffer_lib.glsl_14598 --> gpu_shader_math_vector_reduce_lib.glsl_1383
style gpu_shader_math_vector_reduce_lib.glsl_1383 fill:#1e0
eevee_gbuffer_lib.glsl_14598 --> gpu_shader_codegen_lib.glsl_6143
style gpu_shader_codegen_lib.glsl_6143 fill:#690
eevee_gbuffer_lib.glsl_14598 --> gpu_shader_math_vector_lib.glsl_5038
style gpu_shader_math_vector_lib.glsl_5038 fill:#5a0
eevee_gbuffer_lib.glsl_14598 --> gpu_shader_utildefines_lib.glsl_3112
style gpu_shader_utildefines_lib.glsl_3112 fill:#3c0
eevee_gbuffer_write_lib.glsl_7324 --> eevee_gbuffer_lib.glsl_14598
style eevee_gbuffer_lib.glsl_14598 fill:#e10
eevee_surf_deferred_frag.glsl_4531 --> eevee_gbuffer_write_lib.glsl_7324
style eevee_gbuffer_write_lib.glsl_7324 fill:#780
eevee_ambient_occlusion_lib.glsl_10738 --> draw_view_lib.glsl_3551
style draw_view_lib.glsl_3551 fill:#3c0
draw_math_geom_lib.glsl_5172 --> gpu_shader_math_vector_lib.glsl_5038
style gpu_shader_math_vector_lib.glsl_5038 fill:#5a0
draw_math_geom_lib.glsl_5172 --> gpu_shader_math_vector_reduce_lib.glsl_1383
style gpu_shader_math_vector_reduce_lib.glsl_1383 fill:#1e0
eevee_ray_types_lib.glsl_2390 --> draw_math_geom_lib.glsl_5172
style draw_math_geom_lib.glsl_5172 fill:#5a0
eevee_ray_types_lib.glsl_2390 --> draw_view_lib.glsl_3551
style draw_view_lib.glsl_3551 fill:#3c0
eevee_ray_types_lib.glsl_2390 --> gpu_shader_math_matrix_transform_lib.glsl_706
style gpu_shader_math_matrix_transform_lib.glsl_706 fill:#0f0
gpu_shader_math_safe_lib.glsl_1235 --> gpu_shader_math_constants_lib.glsl_600
style gpu_shader_math_constants_lib.glsl_600 fill:#0f0
eevee_ray_types_lib.glsl_2390 --> gpu_shader_math_safe_lib.glsl_1235
style gpu_shader_math_safe_lib.glsl_1235 fill:#1e0
eevee_ray_types_lib.glsl_2390 --> gpu_shader_ray_lib.glsl_137
style gpu_shader_ray_lib.glsl_137 fill:#0f0
eevee_ambient_occlusion_lib.glsl_10738 --> eevee_ray_types_lib.glsl_2390
style eevee_ray_types_lib.glsl_2390 fill:#2d0
eevee_sampling_lib.glsl_4291 --> gpu_shader_math_base_lib.glsl_1406
style gpu_shader_math_base_lib.glsl_1406 fill:#1e0
eevee_sampling_lib.glsl_4291 --> gpu_shader_math_constants_lib.glsl_600
style gpu_shader_math_constants_lib.glsl_600 fill:#0f0
eevee_sampling_lib.glsl_4291 --> gpu_shader_math_safe_lib.glsl_1235
style gpu_shader_math_safe_lib.glsl_1235 fill:#1e0
eevee_ambient_occlusion_lib.glsl_10738 --> eevee_sampling_lib.glsl_4291
style eevee_sampling_lib.glsl_4291 fill:#4b0
eevee_ambient_occlusion_lib.glsl_10738 --> eevee_utility_tx_lib.glsl_1225
style eevee_utility_tx_lib.glsl_1225 fill:#1e0
eevee_ambient_occlusion_lib.glsl_10738 --> gpu_shader_math_base_lib.glsl_1406
style gpu_shader_math_base_lib.glsl_1406 fill:#1e0
gpu_shader_math_fast_lib.glsl_921 --> gpu_shader_math_constants_lib.glsl_600
style gpu_shader_math_constants_lib.glsl_600 fill:#0f0
eevee_ambient_occlusion_lib.glsl_10738 --> gpu_shader_math_fast_lib.glsl_921
style gpu_shader_math_fast_lib.glsl_921 fill:#0f0
gpu_shader_math_vector_safe_lib.glsl_5847 --> gpu_shader_math_safe_lib.glsl_1235
style gpu_shader_math_safe_lib.glsl_1235 fill:#1e0
eevee_ambient_occlusion_lib.glsl_10738 --> gpu_shader_math_vector_safe_lib.glsl_5847
style gpu_shader_math_vector_safe_lib.glsl_5847 fill:#5a0
eevee_ambient_occlusion_lib.glsl_10738 --> gpu_shader_utildefines_lib.glsl_3112
style gpu_shader_utildefines_lib.glsl_3112 fill:#3c0
eevee_nodetree_frag_lib.glsl_395 --> eevee_ambient_occlusion_lib.glsl_10738
style eevee_ambient_occlusion_lib.glsl_10738 fill:#a50
eevee_nodetree_frag_lib.glsl_395 --> eevee_geom_types_lib.glsl_682
style eevee_geom_types_lib.glsl_682 fill:#0f0
draw_model_lib.glsl_2563 --> draw_view_lib.glsl_3551
style draw_view_lib.glsl_3551 fill:#3c0
eevee_nodetree_lib.glsl_16051 --> draw_model_lib.glsl_2563
style draw_model_lib.glsl_2563 fill:#2d0
draw_object_infos_lib.glsl_1114 --> draw_model_lib.glsl_2563
style draw_model_lib.glsl_2563 fill:#2d0
eevee_nodetree_lib.glsl_16051 --> draw_object_infos_lib.glsl_1114
style draw_object_infos_lib.glsl_1114 fill:#1e0
eevee_nodetree_lib.glsl_16051 --> draw_view_lib.glsl_3551
style draw_view_lib.glsl_3551 fill:#3c0
eevee_nodetree_lib.glsl_16051 --> eevee_renderpass_lib.glsl_1793
style eevee_renderpass_lib.glsl_1793 fill:#1e0
eevee_nodetree_lib.glsl_16051 --> eevee_utility_tx_lib.glsl_1225
style eevee_utility_tx_lib.glsl_1225 fill:#1e0
eevee_nodetree_lib.glsl_16051 --> gpu_shader_codegen_lib.glsl_6143
style gpu_shader_codegen_lib.glsl_6143 fill:#690
eevee_nodetree_lib.glsl_16051 --> gpu_shader_math_base_lib.glsl_1406
style gpu_shader_math_base_lib.glsl_1406 fill:#1e0
eevee_nodetree_lib.glsl_16051 --> gpu_shader_math_safe_lib.glsl_1235
style gpu_shader_math_safe_lib.glsl_1235 fill:#1e0
eevee_nodetree_lib.glsl_16051 --> gpu_shader_math_vector_reduce_lib.glsl_1383
style gpu_shader_math_vector_reduce_lib.glsl_1383 fill:#1e0
eevee_nodetree_lib.glsl_16051 --> gpu_shader_utildefines_lib.glsl_3112
style gpu_shader_utildefines_lib.glsl_3112 fill:#3c0
eevee_nodetree_frag_lib.glsl_395 --> eevee_nodetree_lib.glsl_16051
style eevee_nodetree_lib.glsl_16051 fill:#f00
gpu_shader_material_ambient_occlusion.glsl_558 --> gpu_shader_math_vector_safe_lib.glsl_5847
style gpu_shader_math_vector_safe_lib.glsl_5847 fill:#5a0
eevee_nodetree_frag_lib.glsl_395 --> gpu_shader_material_ambient_occlusion.glsl_558
style gpu_shader_material_ambient_occlusion.glsl_558 fill:#0f0
eevee_nodetree_frag_lib.glsl_395 --> gpu_shader_material_emission.glsl_380
style gpu_shader_material_emission.glsl_380 fill:#0f0
gpu_shader_material_output_material.glsl_850 --> gpu_shader_material_transform_utils.glsl_2136
style gpu_shader_material_transform_utils.glsl_2136 fill:#2d0
eevee_nodetree_frag_lib.glsl_395 --> gpu_shader_material_output_material.glsl_850
style gpu_shader_material_output_material.glsl_850 fill:#0f0
eevee_nodetree_frag_lib.glsl_395 --> gpu_shader_material_world_normals.glsl_128
style gpu_shader_material_world_normals.glsl_128 fill:#0f0
eevee_surf_deferred_frag.glsl_4531 --> eevee_nodetree_frag_lib.glsl_395
style eevee_nodetree_frag_lib.glsl_395 fill:#0f0
eevee_surf_deferred_frag.glsl_4531 --> eevee_sampling_lib.glsl_4291
style eevee_sampling_lib.glsl_4291 fill:#4b0
eevee_surf_lib.glsl_3650 --> draw_view_lib.glsl_3551
style draw_view_lib.glsl_3551 fill:#3c0
eevee_surf_lib.glsl_3650 --> gpu_shader_codegen_lib.glsl_6143
style gpu_shader_codegen_lib.glsl_6143 fill:#690
eevee_surf_lib.glsl_3650 --> gpu_shader_math_base_lib.glsl_1406
style gpu_shader_math_base_lib.glsl_1406 fill:#1e0
eevee_surf_lib.glsl_3650 --> gpu_shader_math_vector_safe_lib.glsl_5847
style gpu_shader_math_vector_safe_lib.glsl_5847 fill:#5a0
eevee_surf_deferred_frag.glsl_4531 --> eevee_surf_lib.glsl_3650
style eevee_surf_lib.glsl_3650 fill:#3c0
```

Pull Request: https://projects.blender.org/blender/blender/pulls/146580
2025-09-23 17:21:56 +02:00
Clément Foucault
759e85c3ff Cleanup: GPU: Remove unused gl_bindcode_get function
_No response_

Pull Request: https://projects.blender.org/blender/blender/pulls/146471
2025-09-22 11:56:40 +02:00
Clément Foucault
fb3904ce45 GPU: Shader Codegen: Split different graph includes
This allows to reduce the number of includes for each
tree graph (surface, volume, displacement) and
reduce the code size significantly for most vertex
shaders, speeding up compile time.

Rel #145347

Pull Request: https://projects.blender.org/blender/blender/pulls/146419
2025-09-22 10:24:10 +02:00
Clément Foucault
36151962d6 Cleanup: GL: Remove unused AMD workaround
_No response_

Pull Request: https://projects.blender.org/blender/blender/pulls/146404
2025-09-17 14:23:32 +02:00
Clément Foucault
9d0fe5573b GPU: FrameBuffer: Remove GPUFrameBuffer wrapper opaque type
This is the first step into merging DRW_gpu_wrapper.hh into
the GPU module.

This is very similar to #119825.

Pull Request: https://projects.blender.org/blender/blender/pulls/146372
2025-09-16 17:50:48 +02:00
Clément Foucault
680fec144c Cleanup: GPU: Remove prefix 'e' from enum types
_No response_

Pull Request: https://projects.blender.org/blender/blender/pulls/146034
2025-09-15 15:11:02 +02:00
Clément Foucault
f729e639f4 GPU: Simplify Codegen dependency injection
Dependencies were previously merged manually
inside the generated_sources by EEVEE.
This caused issues with double includes.

Instead, we now only gather the name of the
nodetree dependencies and add them to the
dependencies of the `GeneratedSource`.

This also make the compositor use the `GeneratedSource`
mechanism.

Pull Request: https://projects.blender.org/blender/blender/pulls/146106
2025-09-12 16:07:55 +02:00
Clément Foucault
e19e9e57ee EEVEE: Split eevee_shader_shared.hh into multiple files
The goal of this patch is to reduce final shader code footprint to
hopefully reduce shader compile time (see #145347).

This also contains a pass over most shader file to remove unused
include or use more granular ones to reduce final shader code
length.

Testing with the same setup as #145347:
|          | main (ms) |  PR (ms) |   Delta (ms) |
| -------- | ----------- | ------------ |------------ |
| Nvidia   |         257 |  207 (1.24x) |         50 |
| Mesa AMD |         323 |  295 (1.09x)    |        28 |

In barbershop test scene however the saving are not so noticeable:
|          | main (s) |  PR (s) |   Delta (s) |
| -------- | ----------- | ------------ |------------ |
| Nvidia (OpenGL)  |         40 |  39 (1.02x) |         1 |
| Nvidia (Vulkan)   |         29 |  29 (1.0x) |         0 |

Pull Request: https://projects.blender.org/blender/blender/pulls/145803
2025-09-12 14:09:35 +02:00
Jeroen Bakker
9c9757e52b Cleanup: GPUFence parameter names
Renamed incorrect naming pixbuf->fence

Pull Request: https://projects.blender.org/blender/blender/pulls/146065
2025-09-11 10:36:00 +02:00
Clément Foucault
b3dec6617a Fix: GPU: Avoid accessing GLContext after it is destroyed
This error showed up inside an ASAN build.

Candidate for backporting in 4.5 as this can happen when simply
rendering with EEVEE or Workbench.

Pull Request: https://projects.blender.org/blender/blender/pulls/146017
2025-09-10 12:17:43 +02:00
Jacques Lucke
32c301e3cf Shader Nodes: support repeat zones, closures and bundles
This adds a function that can turn an existing `bNodeTree` into an inlined one.
The new node tree has all node groups, repeat zones, closures and bundles
inlined. So it's just a flat tree that ideally can be consumed easily by render
engines. As part of the process, it also does constant folding.

The goal is to support more advanced features from geometry nodes (repeat zones,
etc.) in shader nodes which the evaluator is more limited because it has to be
able to run on the GPU. Creating an inlined `bNodeTree` is likely the most
direct way to get but may also be limiting in the future. Since this is a fairly
local change, it's likely still worth it to support these features in all render
engines without having to make their evaluators significantly more complex.

Some limitations apply here that do not apply in Geometry Nodes. For example,
the iterations count in a repeat zone has to be a constant after constant
folding.

There is also a `Test Inlining Shader Nodes` operator that creates the inlined
tree and creates a group node for it. This is just for testing purposes.

#145811 will make this functionality available to the Python API as well so that
external renderers can use it too.
2025-09-09 16:15:43 +02:00
Clément Foucault
18d3f0a1a5 Fix #145651: GPU: Memoryleak drawing node links
The link buffer was not free on exit.
Previous implementation was freing it with the
gpu::Batch which is registered as preset.
This commit introduces buffer registration
to free them on exit.

Pull Request: https://projects.blender.org/blender/blender/pulls/145921
2025-09-09 12:49:32 +02:00
luz paz
81c8b22eeb Cleanup: Fix typos in source/blender/gpu
Fix some non-user-facing typos.
Found via codespell

Pull Request: https://projects.blender.org/blender/blender/pulls/145815
2025-09-09 09:07:23 +02:00
Brecht Van Lommel
ffa4f8c7ad Refactor: Split off lighter BLI_color_types.hh from BLI_color.hh
Functions for convert between the color types and ostream support are
now outside the classes.

Many files were changed to fix cases where direct includes for headers
were missing.

Pull Request: https://projects.blender.org/blender/blender/pulls/145756
2025-09-05 11:11:32 +02:00
Jeroen Bakker
8d40ecbf85 Cleanup: GPUFramebuffer variable names
The internal wrap/unwrap functions used vert as variable names. Should
be framebuffer.
2025-08-29 08:59:01 +02:00
Clément Foucault
8c7ba3579f GPU: Batch: Remove unused instance attributes
This has been completely replaced by SSBOs overtime.

This reduces API size and avoid untested/legacy path
in drivers that are known to break (see #134509).

Pull Request: https://projects.blender.org/blender/blender/pulls/145242
2025-08-28 12:07:41 +02:00
Brecht Van Lommel
5d72498154 Color Management: Improve gamma 2.2 vs piecewise sRGB handling for HDR
See the code comments for detailed explanation. But overall we use particular
combinations of sRGB and gamma 2.2 encode/decode to match SDR applications
while still ensuring HDR values are passed on linearly.

This means the user interface and SDR content will display different in
Windows HDR mode off and on, but that is consistent with other applications.

Split use_hdr variable into use_hdr_buffer about the graphics buffer,
and use_hdr_display about the chosen display in Blender.

Ref #145022

Pull Request: https://projects.blender.org/blender/blender/pulls/145025
2025-08-28 11:35:10 +02:00
Miguel Pozo
0cf4d39aa9 GPU: Improve the do_static_compilation_ check coverage (2)
162a24e05d had to be reverted, since it
didn't take into account other types of dynamically generated
`ShaderCreateInfo` (external shaders like OCIO or Python ones).
This just marks `ShaderCreateInfo`s as generated by default and only
sets the ones from gpu_shader_create_info_list as non generated.

Pull Request: https://projects.blender.org/blender/blender/pulls/145128
2025-08-27 20:17:04 +02:00
Clément Foucault
03296e6679 GPU: Remove unused workarounds
The line workaround is no longer necessary since the
shader now uses SSBO and is less likely to have
issues (more tested path).

The source patching is now always done in the GL and VK
backend before compilation.

Pull Request: https://projects.blender.org/blender/blender/pulls/145240
2025-08-27 16:01:07 +02:00
Christoph Neuhauser
ad4adccdeb GPU: Added image format validation for shader image bindings
The OpenGL specs require that the storage image qualifier in shaders
(e.g., "rgba32f") needs to be compatible with the format of a bound image
(see https://registry.khronos.org/OpenGL/specs/gl/glspec46.core.pdf#page=318).

We know that Blender currently does not handle this correctly in
multiple places. AMD and NVIDIA seem to silently ignore a mismatch and
just seem to use the format of the bound image. However, for the
Intel Windows drivers, this seems to lead to visual corruptions
(#141436, #141173). While a more graceful handling of a mismatch may
be nice, this is in line with the OpenGL specs.

This PR adds code for validating image formats for bindings.

Pull Request: https://projects.blender.org/blender/blender/pulls/143791
2025-08-27 15:43:09 +02:00
Clément Foucault
fa3355c505 Refactor: GPU: NodeLink shader to remove need of instance attributes
Use SSBO loads instead.

Contains a cleanup pass to bring this shader to current shader
standards.

This removes the non-instance version of the shader as it is
not necessary anymore.

The motivation for this is to remove the instance buffer from
the batch API.

Pull Request: https://projects.blender.org/blender/blender/pulls/145238
2025-08-27 15:24:22 +02:00
Clément Foucault
ba4589e894 DRW: New Curve Drawing
Implementation of the design task #142969.

This adds the following:
- Exact GPU interpolation of curves of all types.
- Radius attribute support.
- Cyclic curve support.
- Resolution attribute support.
- New Cylinder hair shape type.
![image.png](/attachments/a8e7aea0-b0e5-4694-b660-89fb3df1ddcd)

What changed:
- EEVEE doesn't compute random normals for strand hairs anymore. These are considered legacy now.
- EEVEE now have an internal shadow bias to avoid self shadowing on hair.
- Workbench Curves Strip display option is no longer flat and has better shading.
- Legacy Hair particle system evaluates radius at control points before applying additional subdivision. This now matches Cycles.
- Color Attribute Node without a name do not fetch the active color attribute anymore. This now matches Cycles.

Notes:
- This is not 100% matching the CPU implementation for interpolation (see the epsilons in the tests).
- Legacy Hair Particle points is now stored in local space after interpolation.

The new cylinder shape allows for more correct hair shading in workbench and better intersection in EEVEE.

|      | Strand | Strip | Cylinder |
| ---- | --- | --- | --- |
| Main | ![main_strand.png](/attachments/67d3b792-962c-4272-a92c-1c0c7c6cf8de) | ![main_strip.png](/attachments/f2aa3575-368e-4fbb-b888-74df845918f1) | N/A |
| PR   | ![pr_strand.png](/attachments/cc012483-25f0-491f-a06e-ad3029981d47) | ![pr_strip.png](/attachments/73fa2f5c-5252-4b30-a334-e935ed0fb938) | ![pr_cylinder.png](/attachments/3133b2d4-a6f2-41ee-8e2d-f6fd00db0c8d) |

|      | Strand | Strip | Cylinder |
| ---- | --- | --- | --- |
| Main | ![main_strand_closeup.png](/attachments/730bd79c-6762-446d-819b-3ea47961ff9f) |![main_strip_closeup.png](/attachments/d9ace578-cfeb-4895-9896-3625b6ad7a02) | N/A |
| PR   | ![pr_strand_closeup.png](/attachments/ac8f3b0c-6ef6-4d54-b714-6322f9865036)|![pr_strip_closeup.png](/attachments/8504711a-955b-4ab2-aa3d-c2d114baf9d4)| ![pr_cylinder_closeup.png](/attachments/1e2899a8-0a5c-431f-ac6c-5184d87e9598) |

Cyclic Curve, Mixed curve type, and proper radius support:
![image.png](/attachments/7f0bf05e-62ee-4ae9-aef9-a5599249b8d7)

Test file for attribute lookup: [test_attribute_lookup.blend](/attachments/1d54dd06-379b-4480-a1c5-96adc1953f77)

Follow Up Tasks:
- Correct full tube segments orientation based on tangent and normal attributes
- Correct V resolution property per object
- More attribute type support (currently only color)

TODO:
- [x] Attribute Loading Changes
  - [x] Generic Attributes
  - [x] Length Attribute
  - [x] Intercept Attribute
  - [x] Original Coordinate Attribute
- [x] Cyclic Curves
- [x] Legacy Hair Particle conversion
  - [x] Attribute Loading
  - [x] Additional Subdivision
- [x] Move some function to generic headers (VertBuf, OffsetIndices)
- [x] Fix default UV/Color attribute assignment

Pull Request: https://projects.blender.org/blender/blender/pulls/143180
2025-08-27 09:49:43 +02:00
Clément Foucault
06ddc55846 Cleanup: GPU: Fix french spelling of Dictionary
...baguette?
2025-08-26 15:38:33 +02:00
Jeroen Bakker
f82e89183e Fix #142110: Vulkan: Only last planar probe is visible
When using multiple planar probes only the last one would
be visible. The other probes would use the world probe.

Reason is that the data of planar probes are stored in
layered textures. When updating planar probes framebuffers
are created with the correct layer attached.

Vulkan backend missed some code paths to clear a single layer
when clearing a framebuffer where the previous action had depth
write disabled. This PR adds the missing code path.

Pull Request: https://projects.blender.org/blender/blender/pulls/145170
2025-08-26 14:18:47 +02:00
Clément Foucault
1f2c906e2a GPU: Shader: Always mute line directives for GLSL
This is motivated by the latest changes to the preprocessor
which outputs a lot of line directives when code is
generated or unrolled.

In this case the reported line would be correct but not
correctly displayed.

Moreover the system of outputing hashes inside the
`#line` directive proved to be incompatible with some
compilers and tools (renderdoc).

This commit always comments the line directives before
compilation (solves the compatibility issue).
When error logging, we then scan the commented
directives to output the correct filename and source
line. The log line is kept untouched and will show
the correct final generated code that triggered the
error.

This also fixed the error line parsing for vulkan.

Pull Request: https://projects.blender.org/blender/blender/pulls/145096
2025-08-26 12:46:46 +02:00
Aras Pranckevicius
a52bed7786 VSE: Do Scopes on the GPU, improve their look, HDR for waveform/parade
Faster and better looking VSE scopes & "show overexposed". Waveform &
RGB Parade now can also show HDR color intensities. (Note: this is
only about VSE scopes; Image Space scopes are to be improved separately)

- Waveform, RGB Parade, Vectorscope scopes are done on the GPU now, by
  drawing points for each input pixel, and placing them according to
  scope logic. The point drawing is implemented in a compute shader,
  with a fragment shader resolve pass; this is because drawing lots of
  points in the same location is very slow on some GPUs (e.g. Apple).
  The compute shader rasterizer is several times faster on regular
  desktop GPU as well.
- If a non-default color management is needed (e.g. VSE colorspace is
  not the same as display colorspace, or a custom look transform is used
  etc. etc.), then transform the VSE preview texture into display space
  RGBA 16F texture using OCIO GPU machinery, and calculate scopes
  from that.
- The "show overexposed" (zebra) preview option is also done on the
  GPU now.
- Waveform/Parade scopes unlock zoom X/Y aspect for viewing HDR scope,
  similar to how it was done for HDR histograms recently.
- Added SEQ_preview_cache.hh that holds GPU textures of VSE preview,
  this is so that when you have a preview and several scopes, each of
  them does not have to create/upload their own GPU texture (that would
  both waste memory, and be slow).

Screenshots and performance details in the PR.

Pull Request: https://projects.blender.org/blender/blender/pulls/144867
2025-08-26 12:25:43 +02:00
Clément Foucault
505e4fc3ae GPU: Shader: Add support for templated struct
This does a few things:
- Add support for templated struct.
- Change parsing of template scope.
  Now all template scope `<..>` are parsed properly.
- Rework to support better match syntax.
- Avoid warning from scope guard processing. Now initialize
  the return value to zero.

Pull Request: https://projects.blender.org/blender/blender/pulls/145132
2025-08-26 10:10:43 +02:00
Miguel Pozo
9f59a36181 Revert "GPU: Improve the do_static_compilation_ check coverage"
This reverts commit 162a24e05d.

Needs testing.
There are asserts triggering on startup.
2025-08-25 16:31:43 +02:00
Miguel Pozo
cb9116f58a Fix #145017: EEVEE: Performance regression with Drivers in Shaders
Make the optimization_delay per-pass.
Lower the optimization pass GC collect rate.

Pull Request: https://projects.blender.org/blender/blender/pulls/145114
2025-08-25 15:56:35 +02:00
Miguel Pozo
162a24e05d GPU: Improve the do_static_compilation_ check coverage
Since we use StaticShader now in many places, the check is often
bypassed.

Ensure that any compiled shader is either marked as static or as a
GPUPass.

Pull Request: https://projects.blender.org/blender/blender/pulls/144950
2025-08-25 15:55:26 +02:00
Clément Foucault
87fe13fb7b Fix: EEVEE: Avoid Valgrind issues
Running valgrind on a render test exhibit a lot of warnings
about `Conditional jump or move depends on uninitialised value(s)`.

This patch makes sure to initialize the memory to avoid
platform dependent bugs.

Pull Request: https://projects.blender.org/blender/blender/pulls/144995
2025-08-25 14:05:50 +02:00
Miguel Pozo
e0a82933ab Cleanup: Remove unused code 2025-08-25 12:43:28 +02:00
Jeroen Bakker
0ea1feabd9 Vulkan: HDR support for Windows
This PR adds HDR support for Windows for `VK_COLOR_SPACE_EXTENDED_SRGB_LINEAR_EXT`
on `VK_FORMAT_R16G16B16A16_SFLOAT` swapchains .

For nonlinear surface formats (sRGB and extended sRGB) the back buffer is blit into the swapchain,
When VK_COLOR_SPACE_EXTENDED_SRGB_LINEAR_EXT is used as surface format a compute shader
is used to flip and invert the gamma.

SDR white level is updated from a few window event changes, but actually
none of them immediately respond to SDR white level changes in the system.
That requires using the WinRT API, which we don't do so far.

Current limitations:
- Intel GPU support
- Dual GPU support

In the future we may add controls inside Blender for absolute HDR nits,
across different platforms. But this makes behavior closer to macOS.

See !144565 for details

Co-authored-by: Brecht Van Lommel <brecht@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/144717
2025-08-22 10:11:55 +02:00
Brecht Van Lommel
b0d52c528b Color Management: Remove "High Dynamic Range" setting
This was a temporary solution until we had proper HDR displays.

* Auto detect from the display + view transform if they are HDR, and
  enable it automatically. This is based on encoding hdr-video in the config.
* If a HDR transform is selected and there is no HDR display support, an
  info message will be shown in the color management panel.
* It is now possible to view HDR images in the image editor, without
  needing to use "View as Render".
* There is no versioning to switch to a HDR display, because that also
  affects image saving. So users will have to manually select the
  "Rec.2100 PQ" display to see HDR colors again.

Ref #144911

Pull Request: https://projects.blender.org/blender/blender/pulls/144565
2025-08-21 15:25:06 +02:00
Brecht Van Lommel
62485a760f Color Management: Wide gamut display
* Change meaning of display device to be the device that we are trying
  to emulate, not the monitor configuration.
* The display transform is now:
 * User specified view and display transform
 * Clamp to 0 to limit colors to gamut
 * Inverse untonemapped display transform
 * Convert to extended sRGB
* When using the display space in the color management API, it now needs to
  be specified if it's for drawing (with emulation) or file output or color
  inspection (without).

Like HDR, this only works on macOS and Linux + Wayland + Vulkan currently.
Support for Windows/Vulkan is under development in #144717.

Ref #144911

Pull Request: https://projects.blender.org/blender/blender/pulls/144565
2025-08-21 15:25:01 +02:00
Clément Foucault
2f2ff44e56 GPU: Shader: Remove legacy creation API
This API is no longer used for 5.0.

Pull Request: https://projects.blender.org/blender/blender/pulls/144819
2025-08-20 09:25:32 +02:00