Commit Graph

606 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
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
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
Miguel Pozo
8d392d41c2 Fix: GPU: GPU_indexbuf_bind_as_ssbo
Make the behavior consistent across all backends.
Clean up the GL function.

Follow-up from #132712.

Pull Request: https://projects.blender.org/blender/blender/pulls/133383
2025-01-23 15:40:45 +01:00
Miguel Pozo
3f5fa8b65e Fix #132211: Overlay-Next: Drag&Drop material assets doesn't work
`GLIndexBuf::bind_as_ssbo` didn't bind subrange index buffers.

Pull Request: https://projects.blender.org/blender/blender/pulls/132712
2025-01-07 13:19:03 +01:00
Brecht Van Lommel
24e5226ff0 Fix #128186: Invalid GPU framebuffer free from context
Framebuffers are getting freed in the GPUContext base class destructor. But
the framebuffer destructors use the MTL/VK/GLContext derived class, whose
destructor has already completed at this point. So these contexts are no
longer valid to use.

Now free the framebuffers earlier.

This caused ASAN warnings, it's not known to cause actual bugs.

Pull Request: https://projects.blender.org/blender/blender/pulls/132504
2025-01-06 11:32:02 +01:00
Campbell Barton
d2d754be3f Cleanup: spelling in comments (make check_spelling*)
- Back-tick quote math expressions so differentiate them
  from English.
- Use doxygen code blocks for TEX expressions.
2025-01-04 16:26:39 +11:00
Miguel Pozo
7655784981 Fix #128388: GPU: Always forward viewport/layer from geometry shader
Ensure `gl_ViewportIndex` and `gl_Layer` are properly forwarded from the
geometry shader, and don't write to them from the vertex shader if
there's a geometry shader stage.

Fixes the Displacement "dicing" render tests on Nvidia OpenGL.

Pull Request: https://projects.blender.org/blender/blender/pulls/131875
2024-12-19 20:22:06 +01:00
Jason Fielder
81f9df606a Fix #130700: Release Metal resources after each frame when rendering Python animations.
Rendering animations from Python scripts via `bpy.ops.render.opengl()`
did not trigger any of the notifications in the Metal back-end to
indicate a frame had been rendered and that the associated resources
could be released. This adds a call to GPU_render_step() after each
render. For the original asset in the bug report this reduces the high
memory watermark from 30gb to 13gb for 500 frames. 13gb is likely
still too high and therefore it is likely there are additional leaks
that need to be addressed so this should only be considered a partial
fix.

Authored by Apple: James McCarthy

Co-authored-by: James McCarthy <jamesmccarthy@apple.com>
Co-authored-by: Clément Foucault <foucault.clem@gmail.com>
Pull Request: https://projects.blender.org/blender/blender/pulls/131085
2024-12-12 20:30:18 +01:00
Miguel Pozo
e24eadbb42 GPU: Add assert_framebuffer_shader_compatibility
Ensure all the framebuffer color attachments are written to.

Pull Request: https://projects.blender.org/blender/blender/pulls/130995
2024-12-10 17:13:06 +01:00
Aras Pranckevicius
074df4ceeb GPU: ensure viewport does not use uninitialized images (#119685 and others)
GPUViewport is creating a bunch of framebuffer textures for itself, but
some space types never initialize/use them. E.g. Sequencer, Nodes etc.
only ever use the "overlay" texture. Eventually when viewport is
"drawn", it combines this uninitialized texture data and then only by
luck it happens that most of the time it is black. But not always!

The textures were only cleared (right now) on Metal backend, under
GPU_clear_viewport_workaround as if it was some driver workaround. Stop
doing that, and just clear them always.

However, there was seemingly a performance issue on OpenGL, when this
clear was being done. At least on my machine (Win10, Geforce RTX
3080Ti), the overhead of doing the clears is measurable, and is caused
by usage of GL4.4 glClearTexImage instead of a framebuffer clear. As if
glClearTexImage makes "pixel data to exist" on the CPU side and then
later on binding this framebuffer sends off that data to the GPU, or
somesuch.

More details in the PR.

Pull Request: https://projects.blender.org/blender/blender/pulls/131518
2024-12-09 13:23:18 +01:00
Campbell Barton
083b690fb5 Cleanup: spelling in comments 2024-12-09 09:14:44 +11:00
Clément Foucault
52463a5f0b GPU: Remove unused GPUDrawList API
This was only used by the legacy draw manager.
This one has already been removed.
2024-12-05 23:26:29 +01:00
Clément Foucault
3e9a2fbf23 Cleanup: Formating 2024-12-05 23:17:44 +01:00
Clément Foucault
994c43413a Metal: Remove SSBO Vertex Fetch
This API was used as a workaround to the lack of
geometry shader. It has been rendered redundant
since the introduction of #125782.
2024-12-05 22:58:52 +01:00
Jeroen Bakker
52d3cf8568 Fix #131227: OpenGL: Sequence editor crash on legacy Intel platforms
There seems to be an issue inside Intel OpenGL driver of legacy
platforms that fails to link `gpu_shader_sequencer_strips`.
Uniform locations are used to fix an specialization constants issue.

This PR only adds the uniform location when the shader can be
specialized. It is unclear what is actually failing inside the driver
but there are other issues with the driver.

Pull Request: https://projects.blender.org/blender/blender/pulls/131293
2024-12-03 15:31:10 +01:00
Miguel Pozo
8504c12fa9 Fix #130776: OpenGL: Use explicit uniform locations
Ensure uniform locations are the same across specialization constants
shader variations.

Pull Request: https://projects.blender.org/blender/blender/pulls/131116
2024-11-29 15:47:51 +01:00
Clément Foucault
7a73741157 Fix #131133: GPU: Navigation Gizmo sometimes doesn't display the axis lines
Alignment was incorrect if vertex format stride was bigger than
SSBO required alignment.
2024-11-29 12:50:52 +01:00
Clément Foucault
ec84fe5fdb Fix #131091: GL: Weird Lines appearing in Gizmo Overlays
This happened because NVidia GPUs require higher alignment
for SSBO binds than for vertex inputs.

This is related to	#131103 which fixed it for vulkan.

Add a common capability option for that.
2024-11-28 17:22:12 +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
Jeroen Bakker
4018e52d30 GPU: OpenGL&Vulkan incorrect workarounds GLSL
OpenGL & Vulkan has workarounds when gl_Layer/gl_ViewportIndex isn't
supported. In this case a geometry shader will is generated. This
geometry shader doesn't follow the GLSL standard and doesn't work on
some platforms. This has not been an issue as the platforms that
don't support gl_Layer/gl_ViewportIndex don't show the issue.

According to the specs gl_Layer and gl_ViewportIndex should be set for
each call to EmitVertex. A shader should not rely on that EmitVertex
reuses the same memory.

Ref https://www.khronos.org/opengl/wiki/Geometry_Shader#Layered_rendering
```
Warning: gl_Layer and gl_ViewportIndex are GS output variables. As such, every time
you call EmitVertex, their values will become undefined. Therefore, you must set
these variables every time you loop over outputs.
```

Issue detected during development of !129062

Pull Request: https://projects.blender.org/blender/blender/pulls/130506
2024-11-19 13:35:09 +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
Campbell Barton
15c207a294 Merge branch 'blender-v4.3-release' 2024-11-02 17:34:00 +11:00
Campbell Barton
4df285ccd5 Cleanup: move function comments into headers or implementation notes
For C/C++ doc-strings should be located in headers,
move function comments into the headers, in some cases merging
with existing doc-strings, in other cases, moving implementation
notes into the function body.
2024-11-02 17:27:09 +11:00
Hans Goudey
9b97ba1462 Cleanup: GPU: Avoid raw pointers for shader API strings
Avoid measuring the length of strings repeatedly by passing their
length along with their data with `StringRefNull`. Null termination
seems to be necessary still for passing the shader sources to OpenGL.
Though I doubt this is a bottleneck, it's still nice to avoid overhead from
string operations and this helps move in that direction.

Pull Request: https://projects.blender.org/blender/blender/pulls/127702
2024-11-01 20:00:31 +01:00
Clément Foucault
6cc4e51e0a Fix: GPU: Shader error line broken for NVidia drivers
Previously the source was not set and would always return 0.
Now it correctly returns the filename hash.
2024-10-22 23:31:52 +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
9c0321ae9b Metal: Simplify MSL translation
Move most of the string preprocessing used for MSL
compatibility to `glsl_preprocess`.

Enforce some changes like matrix constructor and
array constructor to the GLSL codebase. This is
for C++ compatibility.

Additionally reduce the amount of code duplication
inside the compatibility code.

Pull Request: https://projects.blender.org/blender/blender/pulls/128634
2024-10-07 12:54:10 +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
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
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
Campbell Barton
c6fd26a3f5 Cleanup: spelling in comments 2024-10-01 09:59:33 +10:00
Clément Foucault
d401b36509 GPU: Metal: Fix background render crash
GHOST_CreateSystemBackground was not being
followed by the now mandatory GPU_backend_ghost_system_set
2024-09-30 14:20:12 +02:00
Jeroen Bakker
b6aa4a3142 OpenGL: Add Intel HD 405 to limited support.
This rare GPU has z-fighting issues in editor mode. Might be fixable by
changing the bias, but would decrease precision on other platforms as
well. Better to move this GPU to limited support. It is working, just
has some drawing artifacts.

See #128179

Pull Request: https://projects.blender.org/blender/blender/pulls/128351
2024-09-30 08:44:12 +02:00
Campbell Barton
381898b6dc Refactor: move BLI_path_util header to C++, rename to BLI_path_utils
Move to a C++ header to allow C++ features to be used there,
use the "utils" suffix as it's preferred for new files.

Ref !128147
2024-09-26 21:13:39 +10:00
Campbell Barton
f4c8845b60 Cleanup: remove duplicate check for AMD W6800 GPU
This read like a typo (which missed W6700) however the GPU
wasn't released. Remove the duplicate check and add a note.

Ref !127993
2024-09-23 19:09:14 +10:00
Clément Foucault
e90a84469f EEVEE: Simplify barycentric_distances_get
This uses the path that metal was using.

This doesn't seems to create any difference in render
tests. This simplify the backend code and avoid
specific path for metal.

Idea suggested by Kevin Chuang

Pull Request: https://projects.blender.org/blender/blender/pulls/127687
2024-09-16 14:19:53 +02:00
Jeroen Bakker
a407186dbf GPU: Make shader cache clearing backend independent
Parallel shader compilation introduced `GPU_shader_cache_dir_clear_old`.
The implementation was specific to OpenGL and could not be overwritten
by other backends. This PR improves the implementation so the backend
can have its own implementation.

This is needed for upcoming changes to the Vulkan backend where we
want to use similar mechanisms to speed up shader compilation and caching.

Pull Request: https://projects.blender.org/blender/blender/pulls/127680
2024-09-16 14:03:14 +02:00
Anthony Roberts
5f34338296 Windows: Disable shader draw parameter support on certain Qualcomm GPUs
This works around an issue where eevee was rendering a pure black cube in certain shader configurations in the default scene (#122837). This only affects X Elite devices (8cx Gen3 is unaffected).

Pull Request: https://projects.blender.org/blender/blender/pulls/127148
2024-09-04 18:19:54 +02:00
Clément FOUCAULT
b13593e0be GPU: Silence warnings when not building with renderdoc support 2024-09-01 13:15:56 +02:00
Clément FOUCAULT
8ae0264459 GPU: Add debug scope capture support for Renderdoc
This adds a new launch argument when building with
renderdoc support. It allows to trigger the capture
of a specific capture scope. This allows selective
capture of some commonly captured parts.

Pull Request: https://projects.blender.org/blender/blender/pulls/126791
2024-08-30 15:14:58 +02:00
Jeroen Bakker
78af1722cf Fix #123787: EEVEE: RDNA2 shadow of tiny geom
Workaround for RDNA2 shadow rendering when the geometry it needs
to render is to tiny. In this case the rasterizer can skip triangles
leading to incorrect shadow.

This issue has been forwarded to AMD, but this is a temp workaround
for the current drivers. Note that this workaround adds a performance
penalty of around 50% in selected scenes.

Pull Request: https://projects.blender.org/blender/blender/pulls/126693
2024-08-26 12:45:18 +02:00
Campbell Barton
40f96afa61 Cleanup: various non-functional changes
- Use const arguments.
- Remove redundant cast.
- Use ELEM macro.
- Use boolean & nullptr literals.
2024-08-26 11:50:12 +10:00
Jeroen Bakker
994e14b000 OpenGL: Enable HQ normals workaround for more AMD drivers
Allows EEVEE to be used on Legacy platforms. Fixes rendering black geometry in some cases.

Pull Request: https://projects.blender.org/blender/blender/pulls/126540
2024-08-20 08:46:55 +02:00
Jeroen Bakker
975dcea23f OpenGL: Enable High Quality Normals for Legacy AMD Drivers
On Legacy AMD devices EEVEE doesn't render any geometry. During testing
we found that it was based on reading normal attribute. Further testing
it was detected that enabling the high quality normals would solve the
rendering.

This is a known issue on legacy AMD drivers. This PR updates the check
to enable the high quality normals workaround for the latest known AMD
legacy drivers (22.6.1/21.Q1.2). Both drivers still have this issue.

Pull Request: https://projects.blender.org/blender/blender/pulls/126483
2024-08-19 09:42:52 +02:00
Jeroen Bakker
7fc55c0ad8 OpenGL: Remove conservative depth extension check
No need to enable the GL_ARB_conservative_depth extension as it is
core in GLSL 4.20. Some drivers still complain that the
extension was explicitly enabled.

Detected on AMD 21.Q2.1 (27.20.21026.2006) legacy driver.

Pull Request: https://projects.blender.org/blender/blender/pulls/126223
2024-08-13 12:10:00 +02:00