Commit Graph

9660 Commits

Author SHA1 Message Date
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
Eqkoss / T1NT1N
bb9d5cdaad Lights: Add normalize property
When enabled, this normalize the strength by the light area, to keep
the total output the same regardless of shape or size. This is the
existing behavior.

This is supported in Cycles, EEVEE, Hydra, USD, COLLADA.

For add-ons, an API function to compute the area is added for conversion,
in case there is no native support for normalization.

area = light.area(matrix_world=ob.matrix_world)

Co-authored-by: Brecht Van Lommel <brecht@blender.org>

Pull Request: https://projects.blender.org/blender/blender/pulls/136958
2025-05-22 16:32:44 +02:00
Eqkoss / T1NT1N
a12bce039f Lights: Add temperature property
Similar to other renderers, this adds a temperature property to set the
light color using blackbody emission. This can be more convenient than
using nodes, and can improve interop with other software.

This is supported in Cycles, EEVEE, Hydra, USD, COLLADA and FBX.

Pull Request: https://projects.blender.org/blender/blender/pulls/134303
2025-05-22 16:32:44 +02:00
Eqkoss / T1NT1N
7e0dad0580 Lights: Add exposure property
Similar to other renderers, this adds an exposure property to multiply
the light power by 2^exposure. This can be more convenient to control
a wide range of values.

This is supported in Cycles, EEVEE, Hydra, USD, COLLADA and FBX.

Pull Request: https://projects.blender.org/blender/blender/pulls/134528
2025-05-22 16:32:44 +02:00
Clément Foucault
d955ebce30 EEVEE: Default Startup Speedup
Low hanging fruit optimizations for improving default
startup time.

Went from 7.2sec to 4sec on my system.

Pull Request: https://projects.blender.org/blender/blender/pulls/139278
2025-05-22 15:57:41 +02:00
Clément Foucault
78170cbf90 Fix #139189: Vulkan: UV Display Issues When Selecting Specific Mesh Regions
The format was not 4 byte aligned and not compatible with the new
format enums.

Pull Request: https://projects.blender.org/blender/blender/pulls/139202
2025-05-22 09:18:08 +02:00
Campbell Barton
e5deeafe92 Cleanup: spelling in comments (make check_spelling_*) 2025-05-22 11:11:48 +10:00
Clément Foucault
9a9fec7f03 EEVEE: Only request raytracing shader specialization if needed
This improves opengl startup time with default settings
or when rendering with raytracing turned off.

Fix #139188

Pull Request: https://projects.blender.org/blender/blender/pulls/139201
2025-05-21 15:57:00 +02:00
Clément Foucault
decf99106a GPU: Add shader and pass name inside debug groups
This allows to know which shader specialization and
compilation are affecting performance.
2025-05-20 14:44:23 +02:00
Clément Foucault
1c17063155 EEVEE: Avoid stall caused by film specialization in preview render
This is because the warm_shader_specialization was
not called for the actually used specialization since
the samples_len would be updated right before accumulation.

Fixed by calling update_sample_table before the warm shader
call. Also avoid default filter request 4 sample specialization.
This avoid all stall altogether.
2025-05-20 14:38:36 +02:00
Christoph Lendenfeld
b690e9d4db Anim: Use bone_is_visible_... functions
This is mostly a non-functional change except for

* `overlay_armature.cc` was drawing relationship lines to bone
hidden by collection logic (except that doesn't seem to work anyway,
relationship lines are drawn regardless)
* `transform_snap_armature.cc` it was possible to snap to pose bones
hidden by collection logic.

I assumed those to be oversights so I changed them in this PR.

This does *not* remove all usages of `BONE_HIDDEN_P`
and `BONE_HIDDEN_A`. Some direct access is required in
the UI and for cases where we explicitly don't want to check
collection visibility.

Part of #138482

Pull Request: https://projects.blender.org/blender/blender/pulls/139151
2025-05-20 12:58:53 +02:00
Clément Foucault
8bc70f24a1 EEVEE: Film: Reduce amount of compilation stutters at startup
Removes the stutters comming from the film shader.
The number of samples used by the film shader is set
throught a specialization constant. Since the number of
effective sample can depend on jitter position, this
number was fluctuating and trigger compilation on
new specialization until all specialization were
encountered.

Rounding the samples up to the most common sample
count fixes the issue.

Pull Request: https://projects.blender.org/blender/blender/pulls/139154
2025-05-20 12:45:45 +02:00
Clément Foucault
d3053fead0 GPU: Assert that a shader is not bound when deleting it
This caused UB in the tests now that tests are all ran
inside the same context.

A shader could be free but its pointer would be dangling
inside the `Context`. A new shader could have the same
address and generate UB after binding.

This is not the best way to solve this issue but at least
we prevent the use of the UB.

Pull Request: https://projects.blender.org/blender/blender/pulls/139109
2025-05-20 12:43:58 +02:00
Clément Foucault
de8f13d1d6 Fix: GPU: Assert caused by specialization constant with primitive expansion
This path was not passing the the specialization constant state
to `GPU_shader_bind`.

Fix #139132
2025-05-20 11:23:42 +02:00
Campbell Barton
277dc3aef4 Cleanup: use doxygen style comments for doc-strings 2025-05-20 04:33:42 +00:00
Clément Foucault
caac241c84 GPU: Make Shader Specialization Constant API Thread Safe
This allows multiple threads to request different specializations without
locking usage of all specialized shaders program when a new specialization
is being compiled.

The specialization constants are bundled in a structure that is being
passed to the `Shader::bind()` method. The structure is owned by the
calling thread and only used by the `Shader::bind()`.
Only querying for the specialized shader (Map lookup) is locking the shader
usage.

The variant compilation is now also locking and ensured that
multiple thread trying to compile the same variant will never result
in race condition.

Note that this removes the `is_dirty` optimization. This can be added
back if this becomes a bottleneck in the future. Otherwise, the
performance impact is not noticeable.

Pull Request: https://projects.blender.org/blender/blender/pulls/136991
2025-05-19 17:42:55 +02:00
Clément Foucault
ca88983af2 EEVEE: Reverse-Z implementation
This feature greatly increase depth buffer precision.
This is very noticeable in large view distance scenes.

This is enabled by default on GPUs that supports it (most of the hardware we
support already supports this). This makes rendering different on the GPUs
that do not support that feature (`glClipControl`).

While this give much better depth precision as before, we also have a lot of
imprecision caused by our vertex transformations. This can be improved in
another task.

Pull Request: https://projects.blender.org/blender/blender/pulls/138898
2025-05-19 16:29:26 +02:00
Miguel Pozo
239eb386ff Fix #139064: EEVEE: Resizing render region can cause a crash
Clamp the render rect to the viewport area.
2025-05-19 12:49:29 +02:00
Brecht Van Lommel
40642343b6 Fix #138978: Modifier cage option not working when GPU subdivision is off
Need an equivalent of DRW_object_get_data_for_drawing for the cage mesh,
to ensure proper comparison between meshes.

Pull Request: https://projects.blender.org/blender/blender/pulls/138987
2025-05-19 11:50:00 +02:00
Clément Foucault
c7c3ed9fbf GPU: Shader Preprocess: Assert pragma once in lib
This avoid forgetting to add `pragma once` inside
shader library files and have different include
behavior between C++ and shader code.
2025-05-19 09:20:31 +02:00
EmomaxD
5a4a642472 Fix: Typo in default_world_get
This commit fixes a typo in `eevee_world.cc`,
"EEVEEE" to "EEVEE".

Pull Request: https://projects.blender.org/blender/blender/pulls/138989
2025-05-19 05:29:07 +02:00
Aras Pranckevicius
01698188e9 Cleanup: remove stale comment 2025-05-17 09:40:11 +03:00
Aras Pranckevicius
e2b43a4dba Cleanup: armature bone display type naming
- User visible rename: "Use Armature Setting" -> "Armature Defined"
  (just added in 8bf73386f2)
- Internal code only: rename eArmature_Drawtype enum items to have
  ARM_DRAW_TYPE_ prefix, instead of just ARM_ (just ARM_ is used in
  several unrelated enums, leading to confusion)

This is re-apply of PR !138982 was backed out in cef7cb4534 due to
Win x64 buildbot failure. The error was:
```
view3d_navigate_view_all.cc(321): error C2672: 'blender::bounds::transform_bounds': no matching overloaded function found
view3d_navigate_view_all.cc(322): error C2784: 'blender::Bounds<blender::VecBase<T,3>> blender::bounds::transform_bounds(const blender::MatBase<T,Size,Size,NumCol*NumRow%4==0?4:1*sizeof(T)> &,const blender::Bounds<blender::VecBase<T,3>> &)': could not deduce template argument for 'const blender::MatBase<T,Size,Size,NumCol*NumRow%4==0?4:1*sizeof(T)> &' from 'const blender::float4x4'
```
which has nothing whatsoever to do with the PR. But something
in the PR (i.e. rename of a completely unrelated enum entries)
presumably makes this specific VS2019 compiler version not be
able to resolve template argument type. Again, in completely
unrelated file with completely unrelated types.

So "the fix" is to help VS2019 compiler in that place by explicitly
specifying the template types. What exactly in the original
change triggers the issue, remains a mystery. "It is known" that
VS2019 is quite funky in template argument deduction, maybe this
is one of these cases.

Pull Request: https://projects.blender.org/blender/blender/pulls/138995
2025-05-17 08:36:33 +02:00
Campbell Barton
b3dfde88f3 Cleanup: spelling in comments (check_spelling_* target)
Also uppercase acronyms: API, UTF & ASCII.
2025-05-17 10:17:37 +10:00
Thomas Dinges
cef7cb4534 Revert "Cleanup: armature bone display type naming"
This reverts commit 2149f462d4 (broke Windows x64 compilation on CI).

Pull Request: https://projects.blender.org/blender/blender/pulls/138994
2025-05-16 21:01:41 +02:00
Hans Goudey
7a125d5ebc Cleanup: Draw: Simplify trivial attribute requests clearing 2025-05-16 12:30:48 -04:00
Aras Pranckevicius
2149f462d4 Cleanup: armature bone display type naming
- User visible rename: "Use Armature Setting" -> "Armature Defined"
  (just added in 8bf73386f2)
- Internal code only: rename eArmature_Drawtype enum items to have
  ARM_DRAW_TYPE_ prefix, instead of just ARM_ (just ARM_ is used in
  several unrelated enums, leading to confusion)

Pull Request: https://projects.blender.org/blender/blender/pulls/138982
2025-05-16 15:35:56 +02:00
Aras Pranckevicius
8bf73386f2 Anim: support per-bone "Display As" overrides
Armature bone display mode (Octahedral, Stick, Envelope, B-Bone,
Wire) could only be set on the whole armature. This adds ability to
override the display mode per-bone (by default bones use the
same display mode as the armature).

Images in the PR.

Pull Request: https://projects.blender.org/blender/blender/pulls/138445
2025-05-16 15:06:36 +02:00
Christoph Lendenfeld
9c35656766 Refactor: Move bone functions to separate file and into namespace
No functional changes intended.

This moves the functions
* ANIM_bone_is_visible
* ANIM_bone_is_visible_ebone
* ANIM_bone_is_visible_pchan

into new files `ANIM_armature.hh`/`armature.cc`.
They were previously in `ANIM_bone_collections.hh` but don't
directly have anything to do with bone collections.

It also puts the functions into the `blender::animrig::` namespace
and removes the `ANIM_` prefix as is the standard for C++ files.

Part of #138482

Pull Request: https://projects.blender.org/blender/blender/pulls/138833
2025-05-16 14:45:46 +02:00
Clément Foucault
8ac5940e33 GPU: Add GL_ARB_clip_control support to the GL backend
This adds support for the extension and always
set the clip state value to 0..1 to align with vulkan
and metal. Moreover this is needed for the Reverse Z
implementation.

Note that this is a OpenGL 4.5 feature and is not
required to start Blender. So there must still be
a fallback path for now.

Rel #138898

Pull Request: https://projects.blender.org/blender/blender/pulls/138941
2025-05-16 13:53:36 +02:00
Christoph Lendenfeld
45240026a2 Refactor: Remove unused bone flag
No functional changes intended.

This removes the `BONE_HIDDEN_PG` flag for Bones.
It was never set, only read so it had no effect.

Part of #138482

Pull Request: https://projects.blender.org/blender/blender/pulls/138802
2025-05-16 13:43:56 +02:00
Jeroen Bakker
729f6290b8 Fix: Draw: Asserts due to recent changes
cbcf421db7 could raise asserts as it
didn't use the `!is_empty()` function to test if the name is set.

Pull Request: https://projects.blender.org/blender/blender/pulls/138970
2025-05-16 11:20:53 +02:00
Hans Goudey
cbcf421db7 Cleanup: Draw: Use StringRef for attribute names
Avoid the need to measure string length potentially many times.
2025-05-15 14:53:51 -04:00
Hans Goudey
760cf70d63 Draw: Use VectorSet for generic attribute requests
Replace `DRW_Attributes` with a VectorSet of std::string. The max number of
attributes is still the same. The inline buffer size is 4, and std::string's inline
buffer is smaller than the previous char array size of 64, but it seems
reasonable to save those optimizations for shorter attribute names and
fewer attributes. In return we significantly decrease the size of the batch
caches, simplify the code, and remove the attribute name length limit.

I observed roughly an 8% increase in the 30k cube objects file, a change from
12 to 13 FPS. I'm guessing this is mostly because `VectorSet<std::string>` is
smaller than `DRW_Attributes`.

Pull Request: https://projects.blender.org/blender/blender/pulls/138946
2025-05-15 20:43:31 +02:00
Clément Foucault
97a1e1501b DRW: Add a new GPU context for rendering preview jobs
This avoid stalling the viewport when a preview job is running.
This is because both were fighting for the same GPU context.

This doesn't remove the blocking but allows to remove it using #136991.

Pull Request: https://projects.blender.org/blender/blender/pulls/138882
2025-05-15 20:09:37 +02:00
Hans Goudey
011b3f5cb3 Cleanup: Remove unused field from mesh draw batch cache 2025-05-15 13:14:47 -04:00
Hans Goudey
b13bdcfaeb Fix #138910: Crash with sculpt mode and "Texture" shading type
Using the wrong `std::string` constructor through an alias, oops..
2025-05-15 10:13:34 -04:00
Hans Goudey
91627b3d47 GPU: Remove int float fetch mode combination
This commit finishes removing the uses of the integer to float
vertex buffer fetch mode. Previous commits noted below already started
that process. The last usage was geometry attributes. Now integers are
converted to floats as part of the existing upload process.

The change makes the Vulkan vertex buffer type conversion unused, so
it's removed. That's nice because Vulkan vertex buffers go from 1040 to
568 bytes in size and have significantly less overhead on creation.

Related:
- 153abc372e
- 1e1ac2bb9b
- 617858e453

Pull Request: https://projects.blender.org/blender/blender/pulls/138873
2025-05-15 15:29:12 +02:00
Sean Kim
745582ee01 Fix #138851: Assert on entering Sculpting workspace
Introduced with 617858e453

Pull Request: https://projects.blender.org/blender/blender/pulls/138852
2025-05-14 20:47:31 +02:00
Hans Goudey
153abc372e GPU: Replace U32/I32 combination with GPU_FETCH_INT_TO_FLOAT in UI code
The conversion from int to float is not supported natively
so it ends up happening beforehand on the CPU or as a
step before the vertex buffer can be used. It's better to just
upload floats in the first place.

Related to:
- 1e1ac2bb9b
- 617858e453

Pull Request: https://projects.blender.org/blender/blender/pulls/138855
2025-05-14 15:15:21 +02:00
Hans Goudey
1e1ac2bb9b Fix: Various asserts when creating GPU vertex formats
Caused by 617858e453.

These formats should use types aligned to 4 bytes. That's generally
required by modern GPUs. Uploading with these types also avoids
automatic conversion by the Vulkan backend which is something
we're hoping to remove fully.

In the end this PR removes a bunch of code related to supporting
the older single-byte formats.

Pull Request: https://projects.blender.org/blender/blender/pulls/138836
2025-05-13 19:07:01 +02:00
Clément Foucault
617858e453 GPU: Unified DataFormat enum
This unifies vertex and texture data formats
into a single base enum class.

`TextureFormat` and `VertexFormat` then mask
the invalid format for their respective usage.

Having a base enum allows casting between
`TextureFormat` and `VertexFormat` possible
(needed for Buffer Textures).

It also makes it easier to write and read data
to buffers/textures as each format will have an
associated host type.

These enum is generated from MACRO expansion.
This allow to centralize all information about
the formats in one place. This avoid duplicating
the list of enums for each backend.

This only creates the new enum. Porting older enums will
be done in other PRs.

Normalized integer CPU format are missing and waiting for #130640

Rel #130632

Pull Request: https://projects.blender.org/blender/blender/pulls/138069
2025-05-13 17:08:32 +02:00
Clément Foucault
90be031d6b EEVEE: Optimize Upfront specialization
Many of the upfront specialized variants
were not needed/ They are only used if
some scene render setting changes, which
we can detect upfront.

This is noticeable on OpenGL which doesn't support
specialization constant and has to do full shader
recompilation for each variants.

Pull Request: https://projects.blender.org/blender/blender/pulls/138589
2025-05-13 16:28:02 +02:00
Clément Foucault
4ab8267b7e Fix: EEVEE: Broken assert
Logic was flawed.
2025-05-13 16:19:31 +02:00
Clément Foucault
a13db5be47 Cleanup: EEVEE: Warnings tautological-constant-out-of-range-compare 2025-05-13 16:19:31 +02:00
Christoph Lendenfeld
9ee5196db7 Refactor: Remove PBONE_VISIBLE and EBONE_VISIBLE macros
No functional changes intended.

This just replaces all calls to `PBONE_VISIBLE` and `EBONE_VISIBLE`
with appropriate functions.
In the case of editbones it is just the function that the macro already contained.
For pose bones, a new function was added that mirrors what the macro had.

Using a function will make it easier to change how selection is queried in the future.

part of #138482

Pull Request: https://projects.blender.org/blender/blender/pulls/138819
2025-05-13 15:51:12 +02:00
Hans Goudey
eaa3dd0cd3 Refactor: Remove data type from draw attribute request struct
Similar to 93be6baa9c.

It doesn't make sense to store the type as part of the request
since we upload any generic attribute, and the vertex buffer
type is just chosen depending on the attribute's type in the
geometry anyway.

The code in `mesh_cd_calc_used_gpu_layers` is unfortunately
still way too complicated to remove the custom data layer lookup,
but this gets us one step closer.

Pull Request: https://projects.blender.org/blender/blender/pulls/138791
2025-05-13 13:35:30 +02:00
Hans Goudey
f2327a956b Cleanup: Remove disabled code
This only makes this function even more difficult to understand.
2025-05-12 16:38:14 -04:00
Hans Goudey
93be6baa9c Refactor: Remove domain from draw attribute request struct
Similar to b21cb20eeb.
This time the domain is removed. The idea is that the domain doesn't
change anything about how the attribute is stored on the vertex buffers
so it doesn't make sense as part of the request. If we continue that
logic to also remove the data type, we can avoid searching through the
geometry when creating the requests, instead handling invalid requests
when creating the buffers.

The complexity of the change comes from the fact that the request's
domain was used to determine whether the Curves drawing code needed to
interpolate the attribute to the evaluated points. This is now stored
separately in the curves cache. The change in the sculpt code is also
non-trivial since we delay more of the logic until after we have
looked up the attribute from the geometry.

Pull Request: https://projects.blender.org/blender/blender/pulls/138619
2025-05-12 21:16:15 +02:00
Miguel Pozo
c16aba915f GPU: Add GPU_shader_batch_cancel
Fix the recently implemented ShaderCompiler::batch_cancel.
Expose it with GPU_shader_batch_cancel and
GPU_shader_specialization_batch_cancel.
Use them in the EEVEE ShaderModule destructor, to prevent blocking on
destruction when there are in-flight compilations.

Pull Request: https://projects.blender.org/blender/blender/pulls/138774
2025-05-12 19:54:03 +02:00