Commit Graph

18 Commits

Author SHA1 Message Date
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
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
3ccdd28458 Cleanup: EEVEE: Avoid duplicate computation in bsdf_lut function
This is likely not an issue but it is preferable to not do it.

Also reorder some lines for readability and and add `const`.

Pull Request: https://projects.blender.org/blender/blender/pulls/146575
2025-09-22 14:26:20 +02:00
Clément Foucault
bb8e987904 GPU: Simplify matrix lib to reduce dead code
This greatly reduce shader compilation time on some systems.

Pull Request: https://projects.blender.org/blender/blender/pulls/146100
2025-09-15 12:07:26 +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
Clément Foucault
36b80971de Cleanup: EEVEE: Typo in interlieved_gradient_noise 2025-09-10 12:47:49 +02:00
Clément Foucault
455d749c52 Fix: GPU: Implicit cast from int to bool in assert()
These are not valid in GLSL.
2025-09-10 12:20:59 +02:00
Clément Foucault
c302b7de7b Refactor: EEVEE: Simplify Gbuffer packing
Implementation of #145417

For more information see pull request.

Pull Request: https://projects.blender.org/blender/blender/pulls/145520
2025-09-10 12:17:21 +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
34e176d255 Fix #138191: EEVEE: Bump is incorrect with pixel size greater than 1x
This was caused by the hardware derivatives output being affected
by render resolution. Scaling them back to the full resolution
value fixes the issue.

This also fixes the Wireframe node that also relies on derivatives.

Pull Request: https://projects.blender.org/blender/blender/pulls/142101
2025-07-24 12:04:15 +02:00
Clément Foucault
a5dc8026ee GPU: Shader: Add runtime dependency resolution
This allows to generate source file that will
be injected in a predefined source dependance tree.

This allow much cleaner shader workflow where
all sources are explicitly referenced from the
main source file.

Pull Request: https://projects.blender.org/blender/blender/pulls/140047
2025-06-10 17:22:58 +02:00
Hans Goudey
77b14f2dcb Cleanup: Grammar: Fallback vs. fall back
The former is a noun or adjective, the latter is a verb.
2025-06-02 17:13:56 -04:00
Clément Foucault
8dee08996e GPU: Shader: Add wrapper to stage agnostic function
This avoid having to guards functions that are
only available in fragment shader stage.

Calling the function inside another stage is still
invalid and will yield a compile error on Metal.

The vulkan and opengl glsl patch need to be modified
per stage to allow the fragment specific function
to be defined.

This is not yet widely used, but a good example is
the change in `film_display_depth_amend`.

Rel #137261

Pull Request: https://projects.blender.org/blender/blender/pulls/138280
2025-05-05 09:59:00 +02:00
Clément Foucault
47d2dffe8c GPU: Shader CodeBase use constexpr instead of const
Do this only when applicable.

This allow better compile time checking in Shader C++ compilation.
Moreover, this allows to have `constexpr` in shared code between
C++ and GLSL.

After investigation the `const` keyword in GLSL has the same
semantic than C/C++.

Rel #137333 and #137446

Pull Request: https://projects.blender.org/blender/blender/pulls/137497
2025-04-15 11:36:53 +02:00
Clément Foucault
3b3a5731df GPU: Shader: Change vector and matrix type to use blender convention
This unify the C++ and GLSL codebase style.

The GLSL types are still in the backend compatibility
layers to support python shaders. However, the C++
shader compilation layer doesn't have them to enforce
correct type usage.

Note that this is going to break pretty much all PRs
in flight that targets shader code.

Rel #137261

Pull Request: https://projects.blender.org/blender/blender/pulls/137369
2025-04-14 13:46:41 +02:00
Clément Foucault
bb52754652 GPU: Use f suffix for float literals
They are actually already some literals with the `f` suffix
that are in our shader codebase and we never had problem in
the past 5 years (or even 8 years).

So I think it is safe to do and improves convergence of codestyles.

Pull Request: https://projects.blender.org/blender/blender/pulls/137352
2025-04-11 18:28:45 +02:00
Brecht Van Lommel
f987ef7b6e Shaders: Add Filter Width input to Bump node
This makes it possible to restore previous Blender 4.3 behavior of bump
mapping, where the large filter width was sometimes (ab)used to get a bevel
like effect on stepwise textures.

For bump from the displacement socket, filter width remains fixed at 0.1.

Ref #133991, #135841

Pull Request: https://projects.blender.org/blender/blender/pulls/136465
2025-03-25 16:29:13 +01:00
Clément Foucault
894c7fa4e2 EEVEE: Remove EEVEE Next mention inside the code
This only changes file and function names.
The EEVEE identifier is still `BLENDER_EEVEE_NEXT`.

No functional changes.
2025-03-17 15:37:04 +01:00