Commit Graph

5853 Commits

Author SHA1 Message Date
Jacques Lucke
ba4cf3f738 Cleanup: add clarifying comment at assert checking if vbo is empty
I've hit this a couple of times and disabling it always worked fine for me. So
it's good to make it more obvious that there is an actual bug instead of a
missed optimization.

Pull Request: https://projects.blender.org/blender/blender/pulls/135467
2025-03-04 18:03:59 +01:00
Brecht Van Lommel
3dab100860 Fix: ASAN errors after addition of texture pool
Same fix as #132504. Free the texture pool before the derived GPU context
class, as that one is used as part of freeing the texture pool.

Pull Request: https://projects.blender.org/blender/blender/pulls/135444
2025-03-04 16:54:05 +01:00
Clément Foucault
fb6c68aaef Fix: GPU: Shader source log flooding the console on error
This has been commited by mistake in 86b70143d5
2025-03-04 13:05:22 +01:00
Clément Foucault
127a5d6d3a Cleanup: GPU: Shader C++: Avoid #pragma once in main file warning
Pull Request: https://projects.blender.org/blender/blender/pulls/135384
2025-03-03 12:50:47 +01:00
Clément Foucault
783472671e Cleanup: GPU: Add macro for default constructor compatibility on MSL 2025-03-03 12:50:45 +01:00
Clément Foucault
2c20c200bf Cleanup: GPU: Remove warning about is_zero redundant declaration 2025-03-03 12:50:45 +01:00
Jeroen Bakker
e866137cc8 Fix: Compiling shaders without opensubdiv
When blender is compiled with `WITH_OPENSUBDIV=Off` Blender just works
fine. However when compiling all the static shaders the OpenSubDiv
shaders are also compiled and fail as they rely on OpenSubDiv.

This PR fixes this by only adding the shaders when OpenSubDiv is
available.

This issue could be reproduced using the `--debug-gpu-compile-shaders`
option or running GPU test cases.

Pull Request: https://projects.blender.org/blender/blender/pulls/135285
2025-02-28 09:58:08 +01:00
Miguel Pozo
f930d71a1e GPU: Threadsafe shader creation and acquisition
Move the `StaticShader` class from Workbench to `GPU_shader` and make
compilation thread-safe (Shader usage is still not thread-safe).
Use `StaticShader`s for all shader caches.

Subdivision shaders are still not ported.

(Part of #134690)

Pull Request: https://projects.blender.org/blender/blender/pulls/134812
2025-02-27 19:20:33 +01:00
Jeroen Bakker
22aad0fde7 SubDiv: Use shader create info for patch evaluation shader
This PR migrates the subdiv_patch_evaluation_comp.glsl to use
shader create info.

The part of OSD that is used is included as a typedef source (osd_patch_basis.glsl).

Pull Request: https://projects.blender.org/blender/blender/pulls/134917
2025-02-27 15:42:08 +01:00
Jeroen Bakker
667c8a914f Revert "Cleanup: GPU: Reduce compilation warnings"
This reverts commit 3ca5f6f62e.

There were some performance regressions detected.

Fixes: #135215, #134941
2025-02-27 08:23:26 +01:00
Omar Emara
6365110312 Cleanup: GPU: Remove common_math.glsl includes
This patch refactors GPU shaders to remove includes to the utility
gpu_shader_common_math.glsl file. This is done because it has duplicate
functions that exist in other files, and it was really created for use
in GPU material nodes.

The safe_divide and hypot functions were removed since they exist in
gpu_shader_math_base_lib.glsl.

The compatible_[mod|pow] and wrap functions were moved into
gpu_shader_math_base_lib.glsl.

The floor_to_int function was inlined since it was trivial and only used
in one place.

The quick_floor was removed because it was unused.

The euler_to_mat3 function was replaced with the from_rotation function
from gpu_shader_math_matrix_lib.glsl.

Now the file only contains some GPU material node utility functions.

Pull Request: https://projects.blender.org/blender/blender/pulls/135160
2025-02-26 13:37:20 +01:00
Omar Emara
e224e437da Cleanup: Compositor: Remove common_math_utils includes
This patches removes common_math_utils includes from compositor shaders
and replaces them with math lib includes. This involves moving some
functions from that file to to the math lib files.

Pull Request: https://projects.blender.org/blender/blender/pulls/135157
2025-02-26 10:47:39 +01: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
30ccd6b179 GPU: Fix compilation of tests
Caused by missing include.
2025-02-25 18:12:05 +01:00
Hans Goudey
e522a6c826 Cleanup: GPU: Use StringRef for vertex format function arguments
And slightly simplify two string processing functions in this API,
`GPU_vertformat_safe_attr_name` and `copy_attr_name`.
This makes the API easier to interface with from C++ code,
and can avoid unnecessary string length measurements.

Pull Request: https://projects.blender.org/blender/blender/pulls/134882
2025-02-25 14:53:51 +01:00
Clément Foucault
27c20aaae7 Overlay: Add support for CPP shader compilation
Rel #127983

Also removes some unused shaders.

Pull Request: https://projects.blender.org/blender/blender/pulls/135034
2025-02-24 16:17:18 +01:00
Hans Goudey
d0a6189b50 Refactor: DRW: Centralize and clean up packed normals conversion
Move the code dealing with converting float3 to GPU normals
out of the vertex format header into a separate header. Use a
proper C++ namespace and remove duplication by only using
the more recently added C++ templated conversions.

Most of the diff comes from the removal of the indirect includes
from GPU_vertex_format.hh. A lot of files ended up mistakenly
depending on that.

Pull Request: https://projects.blender.org/blender/blender/pulls/134873
2025-02-24 16:08:30 +01:00
Jeroen Bakker
3b5c3e70b1 SubDiv: Use shader create info for stretch overlays
This PR migrates subdiv_vbo_edituv_strech_*_comp.glsl to use
shader create info.

Pull Request: https://projects.blender.org/blender/blender/pulls/135038
2025-02-24 13:32:53 +01:00
Clément Foucault
966a424f00 Fix: GPU: Printf Memory leak
The previous fix 8f00f068ad
doesn't work as the printf buffer gets recreated.

Ensure render boundaries at lower level and do the printf
flush manually.
2025-02-21 14:35:36 +01:00
Clément Foucault
8f00f068ad Fix: GPU: Memory leak from shader printf buffer
The printf buffer were not flushed in some cases
before the context destruction.
2025-02-21 13:47:28 +01:00
Jeroen Bakker
b34bc67f67 Metal: Add support for packed_float3 as storage buffers
Subdivision shaders currently fail to compile using Metal as it doesn't recognize
packed_float3 as an internal data type. This PR includes packed_float3 as an
internal data type.

Without this `blender --debug-gpu-compile-shaders` will fail as it includes a namespace.
```
ERROR (gpu.shader): subdiv_normals_accumulate Compute Shader:
      |
      | source/blender/gpu/metal/mtl_shader_generator.mm:971:9: Error: no type named 'packed_float3' in 'MTLShaderComputeImpl'; did you mean simply 'packed_float3'?
      |
      |         device MTLShaderComputeImpl::packed_float3* normals[[buffer(MTL_storage_buffer_base_index+4)]],
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |         packed_float3
      |
      | /System/Library/PrivateFrameworks/GPUCompiler.framework/Versions/32023/Libraries/lib/clang/32023.196/include/metal/metal_packed_vector:145:58: Note: 'packed_float3' declared here
      |
      | typedef __attribute__((__packed_vector_type__(3))) float packed_float3;
      |                                                          ^
```

Pull Request: https://projects.blender.org/blender/blender/pulls/134925
2025-02-21 13:46:10 +01:00
Bastien Montagne
318ae49f1e Cleanup: Remove void * handling from MEM_freen<T>.
Followup to 48e26c3afe, and discussions in !134771 about keeping
'C-style' and 'C++ template type-safe style' implementations of our
guardedalloc separated. And it makes `MEM_freeN<T>` code simpler.

Also skip type-checking in `MEM_freeN<T>` only with MSVC, as clang-cl on
windows-arm64 does work fine with DNA structs using
`DNA_DEFINE_CXX_METHODS`.

Pull Request: https://projects.blender.org/blender/blender/pulls/134861
2025-02-20 16:42:22 +01:00
Jeroen Bakker
e39669e3c3 SubDiv: Use shader create info for SubdivNormalsFinalize shaders.
This change migrates the first 2 subdiv shaders  to use the ShaderCreateInfo.
Other shaders will follow in separate PRs.

- Should compile when using `WITH_GPU_SHADER_CPP_COMPILATION`
- A `subdiv_` prefix is added only to the functions related to `PosNorLoop`.
    But eventually the prefix should also be added to other lib functions.
- Due to Metal restrictions `subdiv_set_vertex_*` is implemented using a
    functional paradigma. Our Metal backend only supports `inout` qualifier
    on thead local data structures.

Pull Request: https://projects.blender.org/blender/blender/pulls/134218
2025-02-20 12:30:51 +01:00
Jeroen Bakker
3ca5f6f62e Cleanup: GPU: Reduce compilation warnings
When compiling shaders using GCC there are warnings about functions
being declared twice. This PR will remove those warnings as they are
false positives. The warnings exists to identify typing errors.

Pull Request: https://projects.blender.org/blender/blender/pulls/134832
2025-02-20 11:17:49 +01:00
Dalai Felinto
1584cd9aa5 Cleanup: Rename point cloud to pointcloud / POINT_CLOUD to POINTCLOUD
Though "Point Cloud" written as two words is technically correct and should be used in the UI, as one word it's typically easier to write and parse when reading. We had a mix of both before this patch, so better to unify this as well.

This commit also renames the editor/intern/ files to remove pointcloud_ prefix.
point_cloud was only preserved on the user facing strings:

* is_type_point_cloud
* use_new_point_cloud_type

Pull Request: https://projects.blender.org/blender/blender/pulls/134803
2025-02-19 17:11:08 +01:00
Miguel Pozo
6b43873cf9 Cleanup: Remove unused variable 2025-02-18 16:04:27 +01:00
Miguel Pozo
f5d56a3124 GPU: Add --profile-gpu
Add a `--profile-gpu` launch argument.

When set, it generates a profile in the Trace Event Format with CPU and
GPU metrics based on GPU debug scopes.
https://profilerpedia.markhansen.co.nz/formats/trace-event-format/

The profiles are best viewed at https://ui.perfetto.dev/

Notes:
- The profiler captures everything form app start to exit.
- Being JSON based the profiles can become relatively large, but they
  compress very well.
- Only OpenGL profiling is supported for now, but the report formatting
  code can be shared across backends.

Pull Request: https://projects.blender.org/blender/blender/pulls/133557
2025-02-18 15:36:50 +01:00
Clément Foucault
a6364eae75 DRW: Make vertex format threadsafe
Wrapping the vertformat into lambda expression to make
them threadsafe.

Pull Request: https://projects.blender.org/blender/blender/pulls/134685
2025-02-17 18:24:31 +01:00
Clément Foucault
b73c06ada0 Fix: Metal: Avoid overriding GPU matrices after shader bind
This was a bad usage of the Matrix API.
This fixes 2D and 3D cursor being broken on Metal.
2025-02-17 14:47:15 +01:00
Clément Foucault
28ad3736e8 DRW: Move cube batch generation to GPU module
Avoid access on global DRWShapeCache and still
share the code for batch creation.
Each module is then responsible owner of their
own batch.
2025-02-17 12:36:34 +01:00
Clément Foucault
c91d60cda5 DRW: Move procedural batch to GPUContext
This remove relying on a global for storing
the batch and allow for more streamlined usage
of procedural drawing.
2025-02-17 12:36:34 +01:00
Jeroen Bakker
f89a075015 Merge branch 'blender-v4.4-release' 2025-02-17 08:58:44 +01:00
Jeroen Bakker
0faba244a5 Fix: Vulkan: Async readback of storage buffers
The vulkan backend was implemented with async in mind, however the one place
where Blender uses for async was implemented blocking. This PR splits the
readback into flushing the command and waiting for readback.

**Performance**

Improvement of animation playback performance of shader balls.blend is around 10%.
Shader balls.blend frame: 1-100, 10 x animation playback

| Branch               | Total time | Average time |
| -------------------- | ---------- | ------------ |
| blender-v4.4-release | 26851 ms   | 2685 ms      |
| This PR              | 23675 ms   | 2367 ms      |

Pull Request: https://projects.blender.org/blender/blender/pulls/134227
2025-02-17 08:58:06 +01:00
Campbell Barton
5087246f39 Cleanup: strip trailing space, sort file lists 2025-02-16 20:42:16 +11:00
Bastien Montagne
c43a583370 Merge branch 'blender-v4.4-release' 2025-02-14 17:21:17 +01: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
978f2d1caa Merge branch 'blender-v4.4-release' 2025-02-14 12:50:10 +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
c7a33a62a2 Cleanup: Directly include DNA_userdef_types.h and BLI_listbase.h
Instead of relying on them being included indirectly.

Pull Request: https://projects.blender.org/blender/blender/pulls/134406
2025-02-12 23:01:08 +01:00
Alaska
8ed69341d0 Shader: Expose light path "is volume scatter ray" in UI
This commit adds the "is volume scatter" output to the light path node
in the shader editor.

All the funcitonal code for this feature already exists in Cycles SVM
and OSL, but the output wasn't exposed on the node.

EEVEE does not support the feature, so it's output will
always be zero.

Pull Request: https://projects.blender.org/blender/blender/pulls/134343
2025-02-12 15:45:04 +01:00
Clément Foucault
6138ee64a9 GPU: TexturePool: Add texture pool functionality to the GPU module
This patch adds the texture pool functionality that was previously
only available in the DRW module to the GPU module.

This allows to not rely on global `DST` variable for the managment
of these temporary textures.

Moreover, this can be extended using dedicated GPU backend
specific behavior to reduce the amount of memory needed
to render.

The implementation is mostly copy pasted from the draw implementation
but with more documentation. Also it is simplified since the
`DRW_texture_pool_query` functionality is not needed.

Pull Request: https://projects.blender.org/blender/blender/pulls/134403
2025-02-11 18:58:46 +01:00
Clément Foucault
623c81c7ec Fix: GPU: Broken gizmo color
Some unrelated change was brought back inside
86b70143d5

Revert the offending change.
2025-02-11 12:54:20 +01:00
Clément Foucault
ad7b8d5b4c Metal: Ensure that storage buffer reads are synchronized on Intel Macs
There seems to be a pattern where this commonly failed.

This patch adds the async flush (which is effectively not async)
when there were no previous call to `async_flush_to_host`.
This is only done on Intel Macs (or any mac that has non
unified memory arch).

Pull Request: https://projects.blender.org/blender/blender/pulls/134216
2025-02-10 20:44:08 +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
Bastien Montagne
4b996baa76 Merge branch 'blender-v4.4-release' 2025-02-10 14:16:47 +01:00
Clément Foucault
34216a2b7b Fix #134234: GPU: Shader Compile Error on with gpu.types.GPUShader
The removal of the loose uniform made the shader not compile.
This patch adds a new define for these type of shaders and add
back the loose uniform.

Note that these shaders might no longer work on Metal as
the source is not parsed anymore.

Pull Request: https://projects.blender.org/blender/blender/pulls/134341
2025-02-10 14:06:47 +01:00
Campbell Barton
e659e87a67 Cleanup: cmake formatting, sort file lists 2025-02-10 19:40:06 +11:00
Clément Foucault
954b800c3f GPU: Add test for byte pattern clearing of storage buffers 2025-02-07 12:23:50 +01:00
Campbell Barton
9154b5d14a Cleanup: correct misleading variable name
Don't mix up the "patch" version and the "subversion".
2025-02-06 10:12:39 +11:00
Weizhen Huang
d2db9927ed Fix #86648: reduce ray differentials size for bump mapping
Use sub-pixel differentials for bump mapping helps with reducing
artifacts when objects are moving or when textures have high frequency
details.

Currently we scale it by 0.1 because it seems to work good in practice,
we can adjust the value in the future if it turns out to be impractical.

Ref: #122892

Pull Request: https://projects.blender.org/blender/blender/pulls/133991
2025-02-05 13:39:27 +01:00