Commit Graph

3257 Commits

Author SHA1 Message Date
Campbell Barton
7632c528de Docs: remove references to "above" in code comments & corrections
Reference identifiers instead of "above" in code comments as these
tends to become outdated. Even when declarations are removed it's at
least clear that the reference no longer exists instead of referring to
whatever is currently above the declaration.
It's also straightforward to search history for a removed identifier.

Corrected 4 cases of references to things that were no longer above
the doc-strings. Noticed other references which look to be incorrect
but need further investigation.
2024-06-23 12:14:19 +10:00
Miguel Pozo
33005ad716 GPU: Non-blocking specialization constants compilation
Update the batch specializations compilation to allow using it in an
async way.

The implementation has 2 main limitations:
- Only one batch at a time can be processed, extra batches will be
  added to a queue.
- Binding a specialization variant that is still being compiled will fail.

Pull Request: https://projects.blender.org/blender/blender/pulls/123015
2024-06-20 18:02:44 +02:00
Miguel Pozo
feed10a4c2 Fix: GPU: Workaround for validation errors on replaced passes 2024-06-18 18:36:09 +02:00
Clément Foucault
979e142965 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-18 15:35:04 +02:00
Miguel Pozo
a22a4810c7 GPU: Use size_t for GPU buffer sizes
Update all GPU buffer size-related functions to use `size_t` for
consistency.

Pull Request: https://projects.blender.org/blender/blender/pulls/123240
2024-06-14 19:27:33 +02:00
Miguel Pozo
22652b305e GPU: Add GPU_shaders_precompile_specializations
Allow precompiling specialization constants variations in parallel.
Only supported in OpenGL as the rest of the batch compilation API,
on the other backends the function is a no-op.
This also moves the `SpecializationConstant` from
`gpu_shader_create_info` (private API) into`GPU_common_types`
(public API).

Pull Request: https://projects.blender.org/blender/blender/pulls/122796
2024-06-07 18:45:31 +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
a249e93ad1 GPU: Add missing virtual destructor to ShaderCompiler 2024-06-06 15:50:09 +02:00
Miguel Pozo
74224b25a5 GPU: Add GPU_shader_batch_create_from_infos
This is the first commit of the several required to support
subprocess-based parallel compilation on OpenGL.
This provides the base API and implementation, and exposes the max
subprocesses setting on the UI, but it's not used by any code yet.

More information and the rest of the code can be found in #121925.

This one includes:
- A new `GPU_shader_batch` API that allows requesting the compilation
  of multiple shaders at once, allowing GPU backed to compile them in
  parallel and asynchronously without blocking the Blender UI.
- A virtual `ShaderCompiler` class that backends can use to add their
  own implementation.
- A `ShaderCompilerGeneric` class that implements synchronous/blocking
  compilation of batches for backends that don't have their own
  implementation yet.
- A `GLShaderCompiler` that supports parallel compilation using
  subprocesses.
- A new `BLI_subprocess` API, including IPC (required for the
  `GLShaderCompiler` implementation).
- The implementation of the subprocess program in
  `GPU_compilation_subprocess`.
- A new `Max Shader Compilation Subprocesses` option in
  `Preferences > System > Memory & Limits` to enable parallel shader
  compilation and the max number of subprocesses to allocate (each
  subprocess has a relatively high memory footprint).

Implementation Overview:
There's a single `GLShaderCompiler` shared by all OpenGL contexts.
This class stores a pool of up to `GCaps.max_parallel_compilations`
subprocesses that can be used for compilation.
Each subprocess has a shared memory pool used for sending the shader
source code from the main Blender process and for receiving the already
compiled shader binary from the subprocess. This is synchronized using
a series of shared semaphores.
The subprocesses maintain a shader cache on disk inside a
`BLENDER_SHADER_CACHE` folder at the OS temporary folder.
Shaders that fail to compile are tried to be compiled again locally for
proper error reports.
Hanged subprocesses are currently detected using a timeout of 30s.

Pull Request: https://projects.blender.org/blender/blender/pulls/122232
2024-06-05 18:45:57 +02:00
Aras Pranckevicius
7fdfa47f23 VSE: Rounded corners for timeline strips
VSE timeline strips now have rounded corners. Strip corner rounding radius is
4, 6 or 8px depending on strip height (if strip is too narrow to fit
rounding, then rounding is turned off).

This is achieved with a dedicated GPU shader for drawing most of VSE
strip widget, that it could do proper rounded corner masking.

More details and images in the PR.

Pull Request: https://projects.blender.org/blender/blender/pulls/122576
2024-06-04 20:05:35 +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
Jeroen Bakker
e5680542aa GPU: Fix GPUStateMutable size
Current size was to big (9X64 bits) when only (3X64 bits) were
needed.

Pull Request: https://projects.blender.org/blender/blender/pulls/122214
2024-05-24 15:19:59 +02:00
Hans Goudey
da1ea4cdd1 Revert "Draw: Avoid temporary copy for mesh triangulation index buffer"
This reverts commit 108ab1df2d.

This causes issues when duplicating objects that I don't have time
to investigate right now.
2024-05-23 23:43:34 -04:00
Hans Goudey
108ab1df2d Draw: Avoid temporary copy for mesh triangulation index buffer
The mesh triangulation data is stored in CPU memory with the same format
as the triangles GPU index buffer. Because of that we can skip creating a
temporary copied owned by the GPU API. One way to do that is to just
upload the data directly and avoid keeping a reference to it. However, we
can only upload GPU data from the main thread with OpenGL, so instead
reference the data and keep track of whether to free it.

When drawing a mesh with a single material and 1.8 million faces, this
change gives a 12-15% improvement in framerate, from about 32 to 37 FPS.

Part of #116901.

Pull Request: https://projects.blender.org/blender/blender/pulls/122175
2024-05-23 19:59:36 +02:00
Hans Goudey
07eac30070 Mesh: Points index buffer improvement
A continuation of #116901. This one doesn't have a performance impact
in my testing. It also adds a bit more code compared to main so it isn't
really obviously "better" like the previous refactors. However it does
get us closer to removing the "extractors" callback iteration loop
(`edit_data` is the only other enabled by default), and I'd argue that
the final code is easier to iterate on in the future since it's more
self-contained.

I made an effort to avoid storing restart indices in the index buffers.
Though this requires a bit more calculation on the CPU (particularly
because the hidden gaps in the IBO need to be compressed out), it
reduces overall CPU->GPU traffic and removes the need to strip the
restart indices on Metal.

Pull Request: https://projects.blender.org/blender/blender/pulls/122084
2024-05-22 16:08:55 +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
Iliya Katueshenock
75d17b1db5 Cleanup: Move BKE_node to namespace
Move all header file into namespace.
Unnecessary namespaces was removed from implementations file.
Part of forward declarations in header was moved in the top part
of file just to do not have a lot of separate namespaces.

Pull Request: https://projects.blender.org/blender/blender/pulls/121637
2024-05-13 16:07:12 +02:00
Miguel Pozo
a7ff3ebad1 Fix: GPU: GPUColorBandBuilder memory leak 2024-05-09 19:38:22 +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
Clément Foucault
b00c6d7d13 GPU: Fix shader builder stubs 2024-05-03 12:24:33 +02:00
Campbell Barton
9918488bb1 Cleanup: use uppercase tags, following own style guide 2024-05-03 11:33:21 +10:00
Bastien Montagne
ec350a6115 BKE ID copy: Pass new owner ID when possible.
Advanced ID copying code can now take a `new_owner_id` ID pointer parameter,
and use it to set the relevant 'loopback' pointer to its owner ID by the
copy code itself.

Besides avoiding the need for all code copying embedded IDs to set the
loopback pointer themselves, this also means that `lib_id` copying code
itself does not need to use `IDWALK_IGNORE_MISSING_OWNER_ID` anymore.

This change is not expected to have any effect in current codebase.
2024-05-02 17:17:04 +02:00
Miguel Pozo
a8f8745dcb Draw: Add default material fallback detection
Detect passes that are functionally equivalent to the default Material
ones to skip their compilation.

Pull Request: https://projects.blender.org/blender/blender/pulls/121137
2024-04-30 19:44:06 +02:00
Jeroen Bakker
9fa6ac6976 GPU: Fix out of bound write when logging system paths
Blender expects that only the filename is provided which is true
for internal shader sources.

Metal shaders can error and return a full path to a system shader.
This doesn't fit inside the reserved memory that Blender reserved
for logging filename and line number.

This out of bound write can be triggered when using `min`
where the parameters aren't of the same kind.
`uint min(uint, int)` for example.

This PR reserves more space to store the filename.

Pull Request: https://projects.blender.org/blender/blender/pulls/120967
2024-04-23 12:50:50 +02:00
Jeroen Bakker
191b4fea5b GPU: Better hash for specialization constants
Due to an error in the hash function the specialization constants hash
wasn't optimal. This PR fixes the hash function implementation by replacing
the addition with an xor.

Pull Request: https://projects.blender.org/blender/blender/pulls/120964
2024-04-23 09:44:08 +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
Jeroen Bakker
463a4c6211 Cleanup: Move specialization constant default hash
The specialization constant default hash was implemented in gl_shader.hh
But the same implementation is needed for vulkan. This PR moves the
default hash to a common place where both backends can use it.

Pull Request: https://projects.blender.org/blender/blender/pulls/120889
2024-04-21 16:56:00 +02:00
Campbell Barton
4e8b24f1d1 Cleanup: spelling in comments & punctuation 2024-04-19 15:57:06 +10:00
Clément Foucault
f2ae04db10 GPU: Implement missing UBO/SSBO bind tracking
This PR adds a context function to consider all
buffer bindings obsolete. This is in order to
track missing binds and invalid lingering states
accross `draw::Pass`es.

The functions `GPU_storagebuf_debug_unbind_all`
and `GPU_uniformbuf_debug_unbind_all` do nothing
more than resetting the internal debug slot bits
to zero. This is what OpenGL backend does as it
doesn't track the bindings themselves.

Other backends might have other way to detect
missing bindings. If not they should be
implemented separately anyway.

I renamed the function to `debug_unbind_all` to
denote that it actually does something related to
debugging.

This also add SSBO binding check for OpenGL as it
was also missing.

#### Future

This error checking logic is pretty much backend
agnostic. While it would be nice to move it at
`gpu::Context` level, we don't have the resources
for that now.

Pull Request: https://projects.blender.org/blender/blender/pulls/120716
2024-04-17 11:06:39 +02: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
Jason Fielder
be32bc5b72 Metal: Add AMD support for subpass transition
Adds support for subpass transition for AMD/Intel IMR
GPUs. This enables correct functioning of EEVEE Next
deferred lighting pass on AMD platforms.

The emulation is consistent with the OpenGL approach
of generating additional texture bindings in the shader
for subpass inputs, and splitting render passes across
sub-pass boundaries.

Authored by Apple: Michael Parkin-White

Pull Request: https://projects.blender.org/blender/blender/pulls/119784
2024-04-11 15:23:53 +02:00
Hans Goudey
0f46e02310 Mesh: Draw triangle index buffer creation improvements
This PR is another step in the refactor described by #116901.
This change applies to the triangle index buffer. The main improvement
is the ability to recognize when the mesh corner triangles index array
can be uploaded directly (when there is a single material and no hidden
faces). In that case the index data should be copied directly to the
GPU rather than to a temporary array owned by the IBO first. Though
that isn't implemented yet since it will be handled by the GPU module
later, the code is now structured to make that change simple from the
data extraction perspective.

Other than that, the main change is to not use the extractor iterator
framework anymore, and to set index data directly instead of using GPU
API functions. Though we're mainly bottlenecked by memory-bandwidth
anyway, it's nice to avoid function call overhead.

We also now avoid creating the array of sorted triangle indices when
there is a single material and no hidden faces. And we don't use
restart indices for the single-material case anymore. For Metal that's
nice because we can avoid `strip_restart_indices`.

I didn't notice significant performance improvements in my test files
beyond a few percent here and there. With a hacked implementation of
the copy-directly-to-the-gpu optimization, I did see more consistent
improvements though.

Pull Request: https://projects.blender.org/blender/blender/pulls/119130
2024-04-11 04:49:27 +02:00
Campbell Barton
6b14b67a29 Cleanup: spelling in comments 2024-04-08 16:23:25 +10:00
Jason Fielder
93cc55889c EEVEE Next: Horizon scan Metal compiler tuning
Tune Metal compilation parameters for horizon scan
shaders for optimal performance. Selectively unrolling
loops and modifying compilation heuristics results in a
~25% uplift in tracing shader performance, due to
improved latency management.

Authored by Apple: Michael Parkin-White

Pull Request: https://projects.blender.org/blender/blender/pulls/119737
2024-04-04 16:24:20 +02:00
Campbell Barton
b03332a055 Cleanup: use BLI_assert_msg instead of checking string literals 2024-04-03 14:27:54 +11:00
Campbell Barton
686605a6dd Cleanup: declare arrays as const where possible 2024-03-28 22:57:57 +11:00
Campbell Barton
b2e00d1285 Cleanup: use const pointer arguments 2024-03-28 20:57:50 +11:00
Campbell Barton
b0328f67a9 Fix invalid sizes when clearing gpu::Batch
For Batch::verts some values weren't cleared,
for Batch::inst values after the array would be cleared,
although as these were already zeroed this probably didn't cause
problems in practice.
2024-03-28 13:45:22 +11:00
Hans Goudey
48e4576162 Cleanup: Remove unnecessary keywords from C++ headers 2024-03-26 15:58:39 -04:00
Hans Goudey
893130e6fe Refactor: Remove unnecessary C wrapper for GPUBatch class
Similar to fe76d8c946

Pull Request: https://projects.blender.org/blender/blender/pulls/119898
2024-03-26 03:06:25 +01:00
Hans Goudey
e201b5e553 Fix: Debug build error after previous commit 2024-03-24 12:17:44 -04:00
Hans Goudey
fe76d8c946 Refactor: Remove unnecessary C wrappers for vertex and index buffers
Now that all relevant code is C++, the indirection from the C struct
`GPUVertBuf` to the C++ `blender::gpu::VertBuf` class just adds
complexity and necessitates a wrapper API, making more cleanups like
use of RAII or other C++ types more difficult.

This commit replaces the C wrapper structs with direct use of the
vertex and index buffer base classes. In C++ we can choose which parts
of a class are private, so we don't risk exposing too many
implementation details here.

Pull Request: https://projects.blender.org/blender/blender/pulls/119825
2024-03-24 16:38:30 +01: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
Jeroen Bakker
463856e6c6 GPU: Remove print statement when frame capturing
When frame capturing cannot be start an error is printed to the console.
Most of the time the issue is that you're not running from within a frame
capturing environment. For example not from your IDE/GPU debugger.

The print statement is often just not that useful. Especially when
running the `WITH_GPU_DRAW_TESTS` where it floods the console.

Pull Request: https://projects.blender.org/blender/blender/pulls/119783
2024-03-22 16:27:52 +01:00
laurynas
aa3ffca8dc Fix #119247: Curves: Extra point in evaluated spline of Curves geometry
In bf17fc8d79  after extending buffer to multiple of 4 there appeared trailing
space in buffer not covered by shader's `for` loop.

Pull Request: https://projects.blender.org/blender/blender/pulls/119346
2024-03-12 15:01:10 +01:00
Clément Foucault
b8e726a158 GPU: Add support for small types
This implement the design of #118961.

- Add aliases in GLSL since theses types are
  not supported.
- Add detection mechanism that prevents usage
  inside shader shared code.

Check is only done in debug build to avoid slowing down
application startup.

Pull Request: https://projects.blender.org/blender/blender/pulls/119226
2024-03-08 23:28:15 +01:00
Hans Goudey
1e1d7034ec Cleanup: Move GPU_uniform_buffer.h to C++ 2024-03-06 21:54:28 -05:00
Omar Emara
eb91828aab GPU: Add maximum image units to GPU capabilities
This patch adds the maximum number of supported image units to the GPU
capabilities module. Currently, the GPU module assume a maximum of 8
units, so the patch is not currently particularly useful, but we can
consider committing it for the future anyways.

Pull Request: https://projects.blender.org/blender/blender/pulls/119057
2024-03-05 07:25:20 +01:00
Campbell Barton
ed5fb3eaba Cleanup: various non-functional C++ changes 2024-03-05 11:32:42 +11:00