97 Commits

Author SHA1 Message Date
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
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
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
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
cae6c6d81a GPU: Remove Shader Draw Parameter workaround
With 5.0 we start requiring this extension for GL and VK.
All of our target hardware supports it with up to date
drivers.

Some old drivers were disabling this extension because of
buggy behavior. We simply drop support for them in 5.0.

This allows us to remove a lot of code and the last
shader create info override done at startup. This will
unlock more refactoring of the shader create info into
static classes to reduce binary size and other benefits.

## TODO:
- [x] Remove checks for ARB_shader_draw_parameters
- [x] Remove checks for ARB_clip_control
- [x] Check for the extension on startup for OpenGL
- [x] Check for the extension on startup for Vulkan
- [x] ~~Add user facing popup message about minimum
      requirements not being met.~~ Done using the same
      popup as old hardware.

Pull Request: https://projects.blender.org/blender/blender/pulls/142334
2025-08-12 14:04:41 +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
Miguel Pozo
e6638d6e5e Refactor: GPU: GPUMaterial & GPUPass compilation
Cleanup and simplification of GPUMaterial and GPUPass compilation.
See #133674 for details/goals.

- Remove the `draw_manage_shader` thread.
  Deferred compilation is now handled by the gpu::ShaderCompiler
  through the batch compilation API.
  Batch management is handled by the `GPUPassCache`.
- Simplify `GPUMaterial` status tracking so it just queries the
  `GPUPass` status.
- Split the `GPUPass` and the `GPUCodegen` code.
- Replaced the (broken) `GPU_material_recalc_flag_get` with the new
  `GPU_pass_compilation_timestamp`.
- Add the `GPU_pass_cache_wait_for_all` and
  `GPU_shader_batch_wait_for_all`, and remove the busy waits from
   EEVEE.
- Remove many unused functions, properties, includes...

Pull Request: https://projects.blender.org/blender/blender/pulls/135637
2025-05-22 17:53:22 +02:00
Clément Foucault
59df50c326 GPU: Refactor Qualifier and ImageType
This allow to use types closer to GLSL in resource
declaration.

These are aliased for clarity in the GPU
module (i.e. `isampler2D` is shortened to `Int2D`).

Rel #137446

Pull Request: https://projects.blender.org/blender/blender/pulls/137954
2025-04-24 14:38:13 +02:00
Brecht Van Lommel
637c6497e9 Refactor: Use more typed MEM_calloc<>, avoid unnecessary size_t cast
Handle some cases that were missed in previous refactor. And eliminate
unnecessary size_t casts as these could hide issues.

Pull Request: https://projects.blender.org/blender/blender/pulls/137404
2025-04-21 17:59:41 +02:00
Bastien Montagne
bbebf72a33 Cleanup: Add explicit defaults to MEM_new-allocated structs with no constructors.
While not strictly needed (currently!), relying on C++ 'default
initialization' is fragile and unreliable.
2025-02-14 17:07:23 +01:00
Bastien Montagne
194e233d86 Fix (unreported) more invalid C-style allocation of non-trivial C++ data. 2025-02-14 12:23:38 +01:00
Brecht Van Lommel
c7502b092d Cleanup: Various clang-tidy warnings in gpu
Pull Request: https://projects.blender.org/blender/blender/pulls/133734
2025-01-31 17:03:18 +01:00
Brecht Van Lommel
7a0a173d39 Fix: Missed case of OCIO luminance coefficients in EEVEE
Following up on #133368. Thanks Omar for spotting this.

Pull Request: https://projects.blender.org/blender/blender/pulls/133400
2025-01-22 11:19:02 +01:00
Falk David
d413b0064f Cleanup: Move BKE_material.h to C++
The `BKE_material.h` is only renamed to `.hh` to preserve
the history of the file. Changes to the file are done in
the following commit.
2025-01-09 18:11:46 +01:00
Clément Foucault
dd01858959 GPU: Avoid assert caused by overlapping attribute in material shaders
This was caused by `drw_ResourceID` taking one vertex input
(at slot 15) which was then also used by material shaders.

Starting material shaders at 14 in this case avoid the overlap.

Note that this reduces the amount of supported attribute when
using the workarounds by one.
2024-11-06 13:03:32 +01:00
Miguel Pozo
3a39121a07 Fix: Finalize CreateInfos at startup
Prevents race conditions on ShaderCreateInfo::finalize.
Previoulsy fixed by #128281, but it doesn't work for the render thread.
2024-10-04 19:16:02 +02:00
Miguel Pozo
ba4c026215 Fix #128164: Race condition in ShaderCreateInfo::finalize()
We can have deferred and non-deferred shaders (so, different threads)
with the same `additonal_info` dependencies trying to finalize the same
`ShaderCreateInfo`.

This ensures `finalize` always runs from the main thread to avoid race
conditions.

Pull Request: https://projects.blender.org/blender/blender/pulls/128281
2024-10-01 15:35:57 +02:00
Miguel Pozo
a602e5530a Fix #127437: Crash with parallel shader compilation
Avoid race conditions and handle pending async compilations
when compiling synchronously.
2024-09-11 16:34:57 +02:00
Miguel Pozo
6f81cb7c63 Fix #126194: Parallel shader compilation crash 2024-09-03 18:13:19 +02:00
Jeroen Bakker
925753c83b Fix #125618: EEVEE: Cryptomatte Material Layer Incorrect
Missing oversight in previous fix where incorrect name size where
used to generate the cryptomatte hash.

Pull Request: https://projects.blender.org/blender/blender/pulls/126352
2024-08-15 08:41:12 +02:00
Jeroen Bakker
c4e90eddcb Fix #125618: EEVEE: Cryptomatte Material Layer Incorrect
The encoded material names used by cryptomatte were incorrect. Reason
was that it used the name including the object type.

NOTE: reference images needs to be updated

Pull Request: https://projects.blender.org/blender/blender/pulls/126267
2024-08-13 11:28:45 +02:00
Omar Emara
149825bc2a Fix #125946: Crash when adding compositor node
Blender crashes when adding any Color compositor node when both the
viewport and the interactive compositors are active at the same time.
This is caused by a threading issue where both threads try to compile
the same GPU material at the same time.

To fix this, we protects GPU material pass compilation using a mutex.

Pull Request: https://projects.blender.org/blender/blender/pulls/126084
2024-08-08 13:54:22 +02:00
Campbell Barton
4afb3aff35 Cleanup: pass const arguments, use r_ prefixed return arg 2024-07-29 13:01:12 +10:00
Miguel Pozo
4919221456 GPU: Batch Compilation: Show compiled GPUMaterials as soon as possible
Request one separate compilation batch for each GPUPass so users can
get a better sense of the compilation progress, and to better distribute
texture loading over time.

Pull Request: https://projects.blender.org/blender/blender/pulls/125012
2024-07-25 19:18:07 +02:00
Lukas Stockner
26eb5d9899 EEVEE: Adapt Principled BSDF to closure sampling
With the new closure approach, the code can be simplified and cleaned up quite
a bit.

This also removes four parameters, which is helpful for future additions (!123616)
since the parameter limit appears to be reached.

Pull Request: https://projects.blender.org/blender/blender/pulls/123643
2024-06-24 00:20:30 +02:00
Clément Foucault
b5a9a67dcf Fix: EEVEE: Object holdout not working
This implement the holdout flag by switching to
the holdout case in the shader. This has a few benefits:
- Doesn't recompile the shaders.
- Makes the object infos mandatory (already the case in
  practice)
- Handle transparent materials properly, keeping the
  transparency working.

Fix #123284

Pull Request: https://projects.blender.org/blender/blender/pulls/123315
2024-06-17 19:08:37 +02:00
Miguel Pozo
fb98edf322 GPU: Add GPU_material_batch_compile
Add `GPU_material_batch` API.
It uses the new `GPU_shader_batch` from #122232 internally and it
works in the same way.

Note: This doesn't implement parallel material optimizations.

Pull Request: https://projects.blender.org/blender/blender/pulls/122793
2024-06-07 16:11:50 +02:00
Miguel Pozo
aa37e46152 Draw: Use GPUPass for default material fallback detection
Update #121137 to store the reused GPUPass on its own GPUMaterial,
instead of replacing the GPUMaterial itself.

Pull Request: https://projects.blender.org/blender/blender/pulls/121790
2024-05-15 16:01:05 +02:00
Hans Goudey
8b514bccd1 Cleanup: Move remaining GPU headers to C++
Pull Request: https://projects.blender.org/blender/blender/pulls/119807
2024-03-23 01:24:18 +01:00
Hans Goudey
1e1d7034ec Cleanup: Move GPU_uniform_buffer.h to C++ 2024-03-06 21:54:28 -05:00
Campbell Barton
5c87dfd269 Cleanup: use BLI_time_ prefix for time functions
Also use the term "now" instead of "check" for clarity.
2024-02-15 13:15:56 +11:00
Hans Goudey
d691ed2f3b GPU: Use std::string instead of C strings for code gen output
The benefits are removing unnecessary reallocations of the string data
and unnecessary recalculations of the size, better type safety, and more
automatic memory management.

Pull Request: https://projects.blender.org/blender/blender/pulls/118045
2024-02-12 19:33:44 +01:00
Jacques Lucke
319b911784 Cleanup: move hash and ghash utils to C++
Also see #103343.

Pull Request: https://projects.blender.org/blender/blender/pulls/117761
2024-02-02 19:55:06 +01:00
Hans Goudey
dccf0e8699 Cleanup: Move GPU_material.h to C++ 2024-02-01 10:40:30 -05:00
Jacques Lucke
4b47b46f9c Cleanup: rename PIL to BLI
The term `PIL` stands for "platform independent library." It exists since the `Initial Revision`
commit from 2002. Nowadays, we generally just use the `BLI` (blenlib) prefix for such code
and the `PIL` prefix feels more confusing then useful. Therefore, this patch renames the
`PIL` to `BLI`.

Pull Request: https://projects.blender.org/blender/blender/pulls/117325
2024-01-19 14:32:28 +01:00
Brecht Van Lommel
d377ef2543 Clang Format: bump to version 17
Along with the 4.1 libraries upgrade, we are bumping the clang-format
version from 8-12 to 17. This affects quite a few files.

If not already the case, you may consider pointing your IDE to the
clang-format binary bundled with the Blender precompiled libraries.
2024-01-03 13:38:14 +01:00
Miguel Pozo
bcab9de531 Fix: GPU: Avoid GPUMaterial/Pass collisions between engines
Prevent draw engines from using GPUMaterials that were compiled for
other engines by storing the engine they where compiled for along the
shader_uuid.

Fix #115356
Fix #115371

Pull Request: https://projects.blender.org/blender/blender/pulls/115819
2023-12-07 16:48:09 +01:00
Lukas Stockner
158dbc1b10 Cycles: Rework Principled BSDF Clearcoat
- Adds tint control, which simulates volumetric absorption inside the coating.
  This results in angle-dependent saturation and affects all underlying layers
  (diffuse, subsurface, metallic, transmission). It provides a physically-based
  alternative to ad-hoc effects such as tinted specular highlights.
- Renames the component from "Clearcoat" to "Coat", since it's no longer
  necessarily clear now. This matches naming in e.g. other renderers or OpenPBR.
- Adds an explicit Coat IOR input, in preparation for future smarter IOR logic
  around the interaction between Coat and main IOR. This used to be hardcoded
  to 1.5.
- Removes hardcoded 0.25 weight multiplier, and adds versioning code to update
  existing files accordingly. OBJ import/export still applies the factor.
- Replaces the GTR1 microfacet component with regular GGX. This removes a corner
  case in the Microfacet code, solves #53038, and makes us more consistent with
  other standard surface shaders. The original Disney BSDF used GTR1, but it
  doesn't appear that it caught on in the industry.

Co-authored-by: Weizhen Huang <weizhen@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/110993
2023-09-13 00:03:11 +02:00
Hans Goudey
fa34992def Cleanup: Remove unnecessary includes from C++ data structure headers
The hash tables and vector blenlib headers were pulling many more
headers than they actually need, including the C base math header,
our C string API header, and the StringRef header. All of this
potentially slows down compilation and polutes autocomplete
with unrelated information.

Also remove the `ListBase` constructor for `Vector`. It wasn't used
much, and making it easy to use `ListBase` isn't worth it for the
same reasons mentioned above.

It turns out a lot of files depended on indirect includes of
`BLI_string.h` and `BLI_listbase.h`, so those are fixed here.

Pull Request: https://projects.blender.org/blender/blender/pulls/111801
2023-09-01 21:37:11 +02:00
Campbell Barton
e955c94ed3 License Headers: Set copyright to "Blender Authors", add AUTHORS
Listing the "Blender Foundation" as copyright holder implied the Blender
Foundation holds copyright to files which may include work from many
developers.

While keeping copyright on headers makes sense for isolated libraries,
Blender's own code may be refactored or moved between files in a way
that makes the per file copyright holders less meaningful.

Copyright references to the "Blender Foundation" have been replaced with
"Blender Authors", with the exception of `./extern/` since these this
contains libraries which are more isolated, any changed to license
headers there can be handled on a case-by-case basis.

Some directories in `./intern/` have also been excluded:

- `./intern/cycles/` it's own `AUTHORS` file is planned.
- `./intern/opensubdiv/`.

An "AUTHORS" file has been added, using the chromium projects authors
file as a template.

Design task: #110784

Ref !110783.
2023-08-16 00:20:26 +10:00
Campbell Barton
724755879e Cleanup: spelling in comments, use doxygen doc-strings 2023-07-31 10:18:09 +10:00
Campbell Barton
246292f486 Cleanup: various non-functional changes (mainly for C++)
- Remove redundant void, struct.
- Remove redundant parenthesis.
- Use STR_ELEM(..)
- Use function style casts.
2023-07-20 11:55:34 +10:00
Clément Foucault
9305778fb5 Fix: EEVEE-Next: bindpoint collision from Object 2023-07-17 16:46:16 +02:00
Brecht Van Lommel
f2705dd913 Fix #109683: Cycles and Eevee missing AOVs when no closure connected
No reason to skip these, and this will be useful for faster shader node
preview rendering based on AOVs.

Pull Request: https://projects.blender.org/blender/blender/pulls/109709
2023-07-10 12:41:44 +02:00
Campbell Barton
69aee8ba6b Cleanup: remove redundant (void) for functions with no args in C++ 2023-07-02 19:54:27 +10:00
Clément Foucault
ff62f402da EEVEE-Next: Fix overlap with nodetree UBO
Reserve the slot 0 for nodetree and bind
directly to it in Next engines.
2023-06-29 21:10:08 +02:00
Hans Goudey
a1cc621e1e Cleanup: Remove unused custom data type
`CD_HAIRLENGTH` is not really a custom data type, it was just used to
specify the hair particle "length" attribute to pass it to EEVEE and
material preview. Because of the "typemap" array in `CustomData`,
it's better not to have this unnecessary type. Instead, use the same
mechanism used to request the active color attribute.

Pull Request: https://projects.blender.org/blender/blender/pulls/109449
2023-06-28 17:17:31 +02:00
Campbell Barton
65f99397ec License headers: use SPDX-FileCopyrightText in all sources 2023-06-15 13:35:34 +10:00
Campbell Barton
74dd0ed09e Cleanup: remove redundant struct qualifiers 2023-06-03 08:54:37 +10:00