Commit Graph

125 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
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
06ddc55846 Cleanup: GPU: Fix french spelling of Dictionary
...baguette?
2025-08-26 15:38:33 +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
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
1388a70914 GPU: Remove wrapper type for gpu::Shader
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/144229
2025-08-11 09:34:28 +02:00
Clément Foucault
d6f9414c27 Fix #140367: EEVEE: Materials with special characters fail to compile
These `CREATE_INFO_` guards are not yet used.
Still have special case for materials.
2025-06-16 11:28:04 +02:00
Clément Foucault
368a64f386 GPU: Shader: Add support for shader entry points
This works by wrapping the entry point call inside a
`main` function.

Since resources are still defined in global space,
function accessing these are marked with a custom
attribute. This custom attribute expands in a
`#ifdef` guard for the matching stage.
This is a temporary solution and will eventually
be lifted once we support SRD.

### TODO
- [ ] Implement `[[gpu::vertex/fragment_function]]`.

Pull Request: https://projects.blender.org/blender/blender/pulls/139233
2025-06-10 12:37:20 +02:00
Clément Foucault
1c47e31367 GPU: Enable GL multithreaded compilation by default
This allows to reduce the waiting time caused by
shader compilation on some GPU-driver combo.

A new settings in the User Preferences make it
possible to override the default amount of worker
threads and optionally use subprocesses.

We still use only one worker thread in cases where
there is no benefit with adding more workers
(like AMD pro driver and Intel windows).

It doesn't scale as much as subprocesses for material
shader compilation but that is for other reasons
explained in #139818.

Add some heuristic to avoid too much memory usage
and / or too many stalls.

Also add some heuristic to the default number of subprocess for
the platform that shows scalling.

Historically, multithreaded compilation was prevented by the
need of context per thread inside `DRWShader` module.
Also there was no good scaling at that time. But
nowadays numbers shows different results with
good scaling with reasonable amount of threads on many
platforms.

Even if we are going for vulkan in the next release
most of the legacy hardware will still use OpenGL for
a few other releases. So it is relevant to make this
easy improvement.

See pull request for measurements.

Pull Request: https://projects.blender.org/blender/blender/pulls/139821
2025-06-09 12:36:06 +02:00
Clément Foucault
e69762b8dd GPU: Add compilation constants
Compilation constants are constants defined in the create info.
They cannot be changed after the shader is created.
It is a replacement to macros with added type safety.

Reuse most of the logic from Specialization constants.

Pull Request: https://projects.blender.org/blender/blender/pulls/139703
2025-06-03 17:34:04 +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
Clément Foucault
9990273d04 GPU: Change Type enum to use lower case values
This is to help for future resource declaration
using macros.

Rel #137261

Pull Request: https://projects.blender.org/blender/blender/pulls/137367
2025-04-11 22:39:01 +02:00
Clément Foucault
3a7d086200 Cleanup: DRW: Remove legacy create info and rename new ones
This is just mass renaming
2025-02-25 23:05:12 +01:00
Clément Foucault
86b70143d5 Cleanup: GPU: Remove unused Transform Feedback implementation
Most of the cleanup is inside the metal backend.

Pull Request: https://projects.blender.org/blender/blender/pulls/134349
2025-02-10 17:30:42 +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
920e709069 Refactor: Make header files more clangd and clang-tidy friendly
When using clangd or running clang-tidy on headers there are
currently many errors. These are noisy in IDEs, make auto fixes
impossible, and break features like code completion, refactoring
and navigation.

This makes source/blender headers work by themselves, which is
generally the goal anyway. But #includes and forward declarations
were often incomplete.

* Add #includes and forward declarations
* Add IWYU pragma: export in a few places
* Remove some unused #includes (but there are many more)
* Tweak ShaderCreateInfo macros to work better with clangd

Some types of headers still have errors, these could be fixed or
worked around with more investigation. Mostly preprocessor
template headers like NOD_static_types.h.

Note that that disabling WITH_UNITY_BUILD is required for clangd to
work properly, otherwise compile_commands.json does not contain
the information for the relevant source files.

For more details see the developer docs:
https://developer.blender.org/docs/handbook/tooling/clangd/

Pull Request: https://projects.blender.org/blender/blender/pulls/132608
2025-01-07 12:39:13 +01:00
Miguel Pozo
b295df7345 Refactor: Overlay: Port "next" shaders declarations to static CreateInfos
Use static CreateInfos for Overlay-Next shaders using a similar approach to Workbench shader variations.

Remove unused infos and shader sources.
Remove the `gpu_shader_create_info_get_unfinalized_copy` workaround.

Pull Request: https://projects.blender.org/blender/blender/pulls/131514
2024-12-12 23:05:00 +01:00
Clément Foucault
18f3a11955 GPU: Remove remaining metal geometry shader workarounds
_No response_

Pull Request: https://projects.blender.org/blender/blender/pulls/131267
2024-12-03 10:18:50 +01:00
Clément Foucault
00a8d006fe GPU: Move Polyline shader to primitive expansion
This port is not so straightforward.

This shader is used in different configurations and is
available to python bindings. So we need to keep
compatibility with different attributes configurations.

This is why attributes are loaded per component and a
uniform sets the length of the component.

Since this shader can be used from both the imm and batch
API, we need to inject some workarounds to bind the buffers
correctly.

The end result is still less versatile than the previous
metal workaround (i.e.: more attribute fetch mode supported),
but it is also way less code.

### Limitations:
The new shader has some limitation:
- Both `color` and `pos` attributes need to be `F32`.
- Each attribute needs to be 4byte aligned.
- Fetch type needs to be `GPU_FETCH_FLOAT`.
- Primitive type needs to be `GPU_PRIM_LINES`, `GPU_PRIM_LINE_STRIP` or `GPU_PRIM_LINE_LOOP`.
- If drawing using an index buffer, it must contain no primitive restart.

Rel #127493

Co-authored-by: Jeroen Bakker <jeroen@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/129315
2024-11-27 17:37:04 +01:00
Campbell Barton
0de8ae8046 Cleanup: spelling in comments 2024-11-25 13:24:46 +11:00
Clément Foucault
654cc9ed36 GPU: Fix printf force injection logic and limit it to material shader
This fixes backend error caused by missing resource.
2024-11-08 20:20:07 +01:00
Clément Foucault
8c0bd61342 Merge branch 'blender-v4.3-release' 2024-11-05 17:40:49 +01:00
Clément Foucault
43b5e2d0ed Fix: EEVEE: Add buffer workaround for stencil classification
Adding a dummy storage buffer to the classification shader
seems to fix the issue on Qualcomm drivers (WoA).

The workaround is added to the force workaround option to
allow other platforms to test the fix.

Rel #122837

Pull Request: https://projects.blender.org/blender/blender/pulls/129857
2024-11-05 17:12:28 +01:00
Clément Foucault
118ca96c8a GPU: Enable shader interface check for geometry shader fallback 2024-11-05 15:07:56 +01:00
Clément Foucault
9ee81411bf GPU: Multithread compilation of shaders during tests 2024-11-01 18:57:22 +01:00
Clément Foucault
e9298dced4 GPU: Avoid ShaderCreateInfo object directly inside Map
This avoid uneeded big internal allocation for the map.
2024-10-26 13:51:45 +02:00
Clément Foucault
3035fd1c36 GPencil: Port geometry shader to primitive expansion API
This removes the need for the geometry shader and the
workaround path for Metal.

Note that creating 2 batches for each stroke might become
a bottleneck in bigger scenes. But currently the bottleneck
is always be the fill algorithm. It can be optimized further
if needed.

Rel #127493

Pull Request: https://projects.blender.org/blender/blender/pulls/129274
2024-10-21 16:25:24 +02:00
Clément Foucault
46c452dfc3 GPU: Remove shader builder
There is no need for this complexity anymore
as we now have the shader unit tests.

Pull Request: https://projects.blender.org/blender/blender/pulls/129014
2024-10-21 14:00:12 +02:00
Clément Foucault
62826931b0 GPU: Move more linting and processing of GLSL to compile time
The goal is to reduce the startup time cost of
all of these parsing and string replacement.

All comments are now stripped at compile time.
This comment check added noticeable slowdown at
startup in debug builds and during preprocessing.

Put all metadatas between start and end token.
Use very simple parsing using `StringRef` and
hash all identifiers.

Move all the complexity to the preprocessor that
massagess the metadata into a well expected input
to the runtime parser.

All identifiers are compile time hashed so that no string
comparison is made at runtime.

Speed up the source loading:
- from 10ms to 1.6ms (6.25x speedup) in release
- from 194ms to 6ms (32.3x speedup) in debug

Follow up #129009

Pull Request: https://projects.blender.org/blender/blender/pulls/128927
2024-10-15 19:47:30 +02:00
Clément Foucault
86f442df95 GPU: Make create info list not runtime generated
This avoid cmake shenanigans to try to make proper
dependency tracking.

The previous code was not tracking changes inside
the create info files.

There is no real benefit for having these headers listed in
the cmakefile itself.

Pull Request: https://projects.blender.org/blender/blender/pulls/129027
2024-10-15 16:31:37 +02:00
Miguel Pozo
3272b56190 Merge branch 'blender-v4.3-release' 2024-10-05 01:23:36 +02:00
Miguel Pozo
40d20f023a Fix: gpu_shader_create_info_get_unfinalized_copy 2024-10-05 01:22:51 +02:00
Miguel Pozo
6e6e3da454 Workaround: Allow patching CreateInfos at runtime
Temporary workaround for Overlay Next.

Pull Request: https://projects.blender.org/blender/blender/pulls/128452
2024-10-04 19:16:30 +02: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
ba2faf4285 Workaround: Allow patching CreateInfos at runtime
Temporary workaround for Overlay Next.

Pull Request: https://projects.blender.org/blender/blender/pulls/128452
2024-10-04 19:06:37 +02:00
Miguel Pozo
aed1871bd3 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:06:32 +02:00
Clément Foucault
e4c802e53e GPU: Use macros for create infos
Mass rename create info function to use the new macros.
This allows to define resources in C++ inside IDEs'
precompilation system for linting purpose.

This applies the following script and format afterwards:
https://projects.blender.org/blender/blender/pulls/128602#issuecomment-1310597

Rel #127983

Pull Request: https://projects.blender.org/blender/blender/pulls/128602
2024-10-04 19:04:40 +02:00
Clément Foucault
7a36906ecd GPU: CreateInfo: Add macros for C++ stubs
These macros allow to define resources in
C++ inside IDEs' precompilation system for
linting purpose.

The following script can be used to port
existing create info files to the new macros:
https://projects.blender.org/blender/blender/pulls/128602#issuecomment-1310597

Rel #127983

Pull Request: https://projects.blender.org/blender/blender/pulls/128599
2024-10-04 17:45:00 +02:00
Miguel Pozo
54ad693486 Fix: Partially revert #128281
Avoid the asserts until we figure out a better design.
2024-10-01 19:55:36 +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
Laurynas Duburas
84dedfaf4b Curves: smooth handles
Adds antialiasing to curve's handles and thickness to active ones.
Also handles now react to
 `Preferences > Interface > Display > Resolution Scale` and
`Preferences > Themes > 3D Viewport > Edge Width` as they do in
legacy curves.

Pull Request: https://projects.blender.org/blender/blender/pulls/122910
2024-09-25 15:21:31 +02:00
Clément FOUCAULT
d712f91881 DRW: Primitive Expansion
This PR introduces the concept of primitive expansion draws.
This allows to create a drawcall that will generate N amount of new
primitive for an original primitive in a `gpu::Batch`. The intent is to
phase out the use of geometry shader for this purpose.

This adds a new `Frequency::GEOMETRY` only available for SSBOs.
The resources using this will be fed the current `gpu::Batch` VBOs
using name matching.

A dedicated slot is reserved for the index buffer, which has its own
internal  lib to decode the index buffer content.

A new attribute lib is added to ease the loading of unaligned attribute.
This should be revisited and made obsolete once more refactor
lands.

It is similar to the Metal backend SSBO vertex fetch path but it is
defined on a different level. The main difference is that this PR is
backend independant and modify the draw module instead of the GPU
module. However, it doesn't cover all possible attribute conversion
cases. This will only be added if needed.

This system is less automatic than the Metal backend one and needs
more care to make sure the data matches what the shader expects.
The Metal system will be removed once all its usage have been
converted.

This PR only shows example usage for workbench shadows. Cleanup PRs
will follow this one.

Rel #105221

Pull Request: https://projects.blender.org/blender/blender/pulls/125782
2024-08-03 11:06:17 +02:00
Clément Foucault
d2fdb22b93 GPU: Add support for in shader printf
This allows much easier debugging of shader programs.

Usage is as simple as adding `printf` calls inside shaders.
example: `printf("Formating %d\n", my_var);`

Contrary to the `drw_print`, this is not limited
to draw manager shader dispatch/draws. It is compatible
with any shader inside blender.
Most notably, this doesn't need a viewport to display.
So this can be used to debug render pipeline.

Data formating is currently limited to only `%x`, `%d`,
`%u` and `%f`. This could be easily extended if this is
really needed.

There is no type checking, so values are directly reinterpreted
as specified by the printf format.

The current approach for making this work is to bind a
storage buffer inside `GPU_shader_bind`, making it
available to any shader that needs it. The storage buffer
is downloaded back to CPU after a frame or a render
step and the content printed to the console.

This scheduling means that you cannot rely on these printfs
to detect crashes. We could add a mode to force flushing
at shader binding to avoid this limitation.

The values are written from the shaders in binary form and
only formated on the CPU. This avoid issues with manual
printing like with `drw_print`.

Pull Request: https://projects.blender.org/blender/blender/pulls/125071
2024-07-19 15:48:00 +02:00
Clément Foucault
cc0d12dd20 EEVEE: Remove EEVEE-Legacy
This handles the transition to EEVEE-Next (now EEVEE).

This removes some things that make no sense to keep
even for compatibility.
- Scene.eevee.light_cache_data
- Scene Light cache operators
- Scene Light cache RNA properties

The remaining legacy properties will be removed later
on to avoid python API breakage.

We keep the identifier of EEVEE-Next as `BLENDER_EEVEE_NEXT`
to avoid addons being incorrectly silently made compatible
with the EEVEE-Next where the Python API is different.
This renaming should be done in 5.0 release.

Thank you EEVEE-Legacy, you served us well.

Pull Request: https://projects.blender.org/blender/blender/pulls/122433
2024-06-04 14:17:58 +02:00
Christoph Lendenfeld
f9ea64b0ba Anim: Per bone wire width for custom shapes
The setting adds the "Custom Shape Wire Width"
option to the "Viewport Display/Custom Shape" section of a pose bone.
As the setting says, this controls how thick the wire is drawn in the viewport.

This is done by adding a geometry shader that makes two triangles out of a line.

The Anti-Aliasing is controlled by the setting
Viewport->Quality->Smooth Wires->Overlay in the user preferences.

## Artifacts
When increasing the line width, the lines start to separate at their vertices.
This comes from extruding each edge along the normal of its direction.
This could be solved by adding round caps in a later PR.

Pull Request: https://projects.blender.org/blender/blender/pulls/120176
2024-05-30 15:51:30 +02:00
Jason Fielder
996014e537 EEVEE Next: Disable TILE_COPY shadow update method
Disabling tile_copy method for shadow update for
stability in scenes with large geometry counts
which may exceed parameter buffer size.

This pass can be re-used in future if the workload
distribution for shadow updates is changed to
better suit this method.

Authored by Apple: Michael Parkin-White

Pull Request: https://projects.blender.org/blender/blender/pulls/121623
2024-05-09 15:50:53 +02:00
Jeroen Bakker
0c2085a316 GPU: Remove GPU_compute_shader_support
Compute shaders are required since 4.0. There was one occasion where
an older AMD driver failed and support was turned off. This driver
is now marked unsupported.

This PR includes:
- removing the check in viewport compositing
- remove properties from system info
- always construct draw manager.
- remove unused pass logic in draw hair/curves
- add deprecation warning when accessed from python

Pull Request: https://projects.blender.org/blender/blender/pulls/120909
2024-04-22 13:28:10 +02:00
Campbell Barton
4e8b24f1d1 Cleanup: spelling in comments & punctuation 2024-04-19 15:57:06 +10:00
Jeroen Bakker
9c1cba528b OpenGL: Remove Apple specific workarounds
This PR removes apple specific OpenGL workarounds. OpenGL on Apple isn't supported
so they can be removed.

Pull Request: https://projects.blender.org/blender/blender/pulls/120522
2024-04-11 17:25:21 +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