Commit Graph

162 Commits

Author SHA1 Message Date
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
954b800c3f GPU: Add test for byte pattern clearing of storage buffers 2025-02-07 12:23:50 +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
Jeroen Bakker
16a739dc8a GPU: Add unpack row length tests
This PR adds 2 test cases to test uploading sub texture with and
without unpack row length.

Ref #130977

Pull Request: https://projects.blender.org/blender/blender/pulls/131791
2024-12-12 12:58:16 +01:00
Jeroen Bakker
567595e850 Fix: GPU: OpenGL texture tests
Some texture roundtrip tests are not supported on OpenGL. This PR will
skip these tests.

Pull Request: https://projects.blender.org/blender/blender/pulls/131792
2024-12-12 12:57:41 +01:00
Campbell Barton
b9f055459a Cleanup: ensure trailing space around comment blocks 2024-11-27 19:01:00 +11:00
Jeroen Bakker
e440828221 Fix #130588: Vulkan: Depth stencil readback
Functionality like snapping cursor requires readback of depth stencil
textures. This was not supported yet. This PR will add readback of depth
stencil textures to float.

Fixes: #128624, #130588

Pull Request: https://projects.blender.org/blender/blender/pulls/130717
2024-11-22 09:45:38 +01:00
Clément Foucault
e9252f206b GPU: Comment out test not compatible with metal backend
These test are either not compatible because of the
spec or are just broken in the current state of the backend.

These should be dealt with soon.
2024-11-10 15:16:34 +01:00
Clément Foucault
8260e3aa81 GPU: Simplify framebuffer tests 2024-11-10 15:16:34 +01:00
Clément Foucault
9b91a42240 GPU: Improve fetch mode tests to cover GPU_FETCH_INT_TO_FLOAT_UNIT 2024-11-09 21:50:37 +01:00
Clément Foucault
2738e33a58 GPU: Silence invalid fetch mode tests on Metal
These vertex buffer setup are invalid on metal.
For now simply disable them on Apple hardware.
2024-11-09 21:50:37 +01:00
Clément Foucault
ef8ea88f5f Fix: GPU: Tests not passing on Metal with ASAN on
Fixes a few stack overflow error, reduce framebuffer size
to avoid errors flooding the output.
2024-11-09 21:50:37 +01:00
Jeroen Bakker
a4529f0e17 Merge branch 'blender-v4.3-release' 2024-11-07 14:01:32 +01:00
Jacques Lucke
3688a2919b Merge branch 'blender-v4.3-release' 2024-11-07 14:00:52 +01:00
Jeroen Bakker
da767bcbdc Fix: Vulkan: Enable interleaved tests
Interleaved tests where disabled for Vulkan, but interleaving has been
implemented. This PR enabled these tests.

Pull Request: https://projects.blender.org/blender/blender/pulls/129957
2024-11-07 14:00:51 +01:00
Jeroen Bakker
e0f699abdb Fix: Vulkan: Read & write outside of bounds
When running test cases
`test_texture_roundtrip__GPU_DATA_10_11_11_REV__GPU_R11F_G11F_B10F`
would read and write outside of allocated memory. This is an error in
the test case itself the GPU API doesn't have a public function to get
the desired byte and component size.

Pull Request: https://projects.blender.org/blender/blender/pulls/129958
2024-11-07 13:59:53 +01: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
Clément Foucault
7e5bc58649 GPU: Change GLSL include directive
This changes the include directive to use the standard C preprocessor
`#include` directive.

The regex to applied to all glsl sources is:
`pragma BLENDER_REQUIRE\((\w+\.glsl)\)`
`include "$1"`

This allow C++ linter to parse the code and allow easier codebase
traversal.

However there is a small catch. While it does work like a standard
include directive when the code is treated as C++, it doesn't when
compiled by our shader backends. In this case, we still use our
dependency concatenation approach instead of file injection.

This means that included files will always be prepended when compiled
to GLSL and a file cannot be appended more than once.

This is why all GLSL lib file should have the `#pragma once` directive
and always be included at the start of the file.

These requirements are actually already enforced by our code-style
in practice.

On the implementation, the source needed to be mutated to comment
the `#pragma once` and `#include`. This is needed to avoid GLSL
compiler error out as this is an extension that not all vendor
supports.

Rel #127983
Pull Request: https://projects.blender.org/blender/blender/pulls/128076
2024-10-04 15:48:22 +02:00
Jason Fielder
eb3fe75392 Metal: Add support for parallel compilation and precompilation specialisation
This speeds up EEVEE startup and material compilation time.

Authored by Apple: James McCarthy
Pull Request: https://projects.blender.org/blender/blender/pulls/125657
2024-09-30 11:21:28 +02:00
Jeroen Bakker
2c6b1eb2e5 GPU: Fix static shader tests for NVIDIA
Skipping tests when workarounds are enabled due to GLSL restrictions in
the NVIDIA driver.
2024-08-20 14:52:35 +02:00
Jeroen Bakker
df910f2417 GPU: Fix draw test on NVIDIA/OpenGL
Some workarounds cannot work on NVIDIA but are tested leading to
segfaults. Fixed by skipping in these cases.
2024-08-20 13:37:00 +02:00
Campbell Barton
dffc47e6cf Merge branch 'blender-v4.2-release' 2024-07-02 17:06:35 +10:00
Jeroen Bakker
4d0c14bed3 OpenGL: Fix read from uninitialized memory
When performing framebuffer transition on legacy opengl platforms, some
state was uninitialized. Resulting in incorrect behavior and crashes.

Note that this doens't fix the black cube on legacy platforms. With this PR we
might be able to reproduce the issue on modern HW.

Pull Request: https://projects.blender.org/blender/blender/pulls/123989
2024-07-02 08:37:50 +02:00
Jeroen Bakker
f13e51543c Cleanup: Fix spelling mistake
Attachement -> Attachment

Pull Request: https://projects.blender.org/blender/blender/pulls/122988
2024-06-10 09:57:15 +02:00
Clément Foucault
3f247d6a3c Fix: GPU: Make tests compile 2024-06-08 00:25:40 +02:00
Hans Goudey
84c4ddbbb9 Cleanup: GPU: Use references for some vertex buffer functions
Pull Request: https://projects.blender.org/blender/blender/pulls/122784
2024-06-05 18:47:22 +02:00
Jeroen Bakker
94e2880dfb GPU: Fix use after free in draw tests
Pull Request: https://projects.blender.org/blender/blender/pulls/122201
2024-05-24 12:36:30 +02:00
Jeroen Bakker
c50a0f6478 Cleanup: Framebuffer tests expect parameter order
Framebuffer tests use incorrect order of parameters, which lead to messages
misinforming the developer.

Pull Request: https://projects.blender.org/blender/blender/pulls/121481
2024-05-06 16:19:52 +02:00
Jeroen Bakker
6106bb3d3b GPU: Remove Compute test from test cases
Test cases that uses compute shaders were exited when run on platforms
not supporting compute shaders. Since 4.0 Blender requires a platform
that supports compute shaders.

We should eventually phase out `GPU_compute_shader_support` as it
would always return true. Note that in OpenGL a platform is mentioned
that doesn't support compute shaders, but that is from an old driver
and should be save to remove as well.

Pull Request: https://projects.blender.org/blender/blender/pulls/120907
2024-04-22 06:55:09 +02:00
Jeroen Bakker
d9d4f90142 GPU: Add test case for GPU_storagebuf_copy_sub_from_vertbuf
This API function wasn't covered in any test.

Pull Request: https://projects.blender.org/blender/blender/pulls/120817
2024-04-19 11:12:16 +02:00
Jeroen Bakker
4ae9948f3a GPU: Improve push constants tests
- Expected results should come before actual result.
- Add test case for 8192 bytes as apple has a push constants size of 4096.
- Add more variation to the first order test data.

Improvements detected when working on vulkan backend and validated they
work on metal and opengl as well.

Pull Request: https://projects.blender.org/blender/blender/pulls/120557
2024-04-12 12:26:26 +02: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
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
5698fb2049 RenderDoc: Set Capture Title
Adds an option to set the capture title when using renderdoc
`GPU_debug_capture_begin` has an optional `title` parameter to set
the title of the renderdoc capture.

Pull Request: https://projects.blender.org/blender/blender/pulls/118649
2024-02-23 10:57:37 +01:00
Bastien Montagne
54618dbae3 Cleanup: Make BKE_global.h a Cpp header. 2024-02-10 18:25:14 +01:00
Jeroen Bakker
24bc2fef1d GPU: Disable Unsupported OpenGL test cases.
Some test cases are not support when used with the OpenGL backend. These
test cases are easier to support when using Vulkan as we do control the
GPU->CPU data conversion logic.

We remove the test cases that aren't working yet for any backend and
skip test cases where OpenGL support is failing.
2024-02-01 16:13:18 +01:00
Jeroen Bakker
efc37b2573 GPU: Fixed Assert when running Specialization Constants test
Specialization constants tests use points render primitives, but the
shader isn't capable of point rendering. For the test results it doesn't
matter as it only validates the vertex output, but it would trigger an
assert when using Vulkan backend. The vulkan backend is more strict and
currently signals these common errors.
2024-02-01 14:28:02 +01:00
Clément Foucault
8c02b6eb24 EEVEE-Next: Add normal layer reuse
This allows to save some space in the gbuffer
and improve write performance.

Pull Request: https://projects.blender.org/blender/blender/pulls/117131
2024-01-31 15:36:42 +01:00
Campbell Barton
2783af45ee Cleanup: trailing newlines 2024-01-08 11:31:43 +11:00
Hans Goudey
5b55c1dc10 Cleanup: Move five draw headers to C++ 2024-01-05 13:26:22 -05:00
Clément Foucault
1e7a2fe483 GPU: Fix wrong error lines in tests
This was caused by the addition of the
license headers. This is not very
important but allow debugging failling
tests.
2024-01-01 00:34:29 +13:00
Jason Fielder
335d3a1b75 GPU: Add Shader specialization constant API
Adds API to allow usage of specialization constants in shaders.
Specialization constants are dynamic runtime constants which can
be compiled into a shader pipeline state object (PSO) to improve
runtime performance by reducing shader complexity through
shader compiler constant-folding.

This API allows specialization constant values to be specified
along with a default value if no constant value has been declared.
Each GPU backend is then responsible for caching PSO permutations
against the current specialization configuration.

This patch adds support for specialization constants in the
Metal backend and provides a generalised high-level solution
which can be adopted by other graphics APIs supporting
this feature.

Authored by Apple: Michael Parkin-White
Authored by Blender: Clément Foucault (files in gpu/test folder)

Pull Request: https://projects.blender.org/blender/blender/pulls/115193
2023-12-28 05:34:38 +01:00
Clément Foucault
f4275cc4df EEVEE-Next: Gbuffer Optimization
This modify the GBuffer layout to store less bits per closures.
This allows packing all closures into 64 bits or 96 bits.
In turn, this reduces the amount of data stored for most
usual materials.

Moreover, this contain some groundwork for the getting rid of the
hard-coded closure type. But evaluation shaders still use
the hard-coded types.

This adds tests for checking packing and unpacking of the gbuffer
doesn't loose any data.

Related to #115966

Pull Request: https://projects.blender.org/blender/blender/pulls/116476
2023-12-23 05:58:52 +01:00
Jeroen Bakker
efc1094d6a Metal: Enable Shader Validation on Buildbot
This PR enables shader validation testing on buildbot for Metal.

OpenGL isn't enabled as OpenGL requires an actual driver and GPU
attached to the build bot infrastructure. Also the OpenGL backend
caches data (glsl_patch) globally and requires a restart in order to
create the correct one.

Vulkan isn't enabled as it requires some changes:
* For windows it requires to install more recent vulkan software versions as
  part of the buildbot windows configuration
* For Linux it requires to start a GHOST System without any X11/Wayland
  This currently fails on the buildbot. We should check if we can use
  `GHOST_SystemHeadless` with `GHOST_ContextVK`

Each shaders are compiled twice. Once based on the
actual features of the installed GPU/backend. And once with all
the work-arounds enabled, simulating a platform close to the
minimum requirements of Blender.

Pull Request: https://projects.blender.org/blender/blender/pulls/116040
2023-12-12 10:14:13 +01:00
Jeroen Bakker
1b99987043 GPU: Shader Builder Filter
This PR introduced some filters to improve the workflow when using
shader_builder. Shader builder is used to validate shader compilation
during buildtime and can be enabled using `WITH_GPU_BUILDTIME_SHADER_BUILDER`.

During backend development shader builder is also handy as you can
pin-point it to the shader/backend you're focusing on. Without filters
you would insert temporary code to break on a specific shader.

* `--gpu-backend` can be used to only check a specific backend.
  possible values are `vulkan`, `metal` or `opengl`. When argument
  isn't passed, all backends will be validated.
* `--gpu-shader-filter` can be used to only check a subset or indivisual
  shader. The filter is a name starts with filter. Use
  `--gpu-shader-filter eevee` to validate all eevee shaders

Pull Request: https://projects.blender.org/blender/blender/pulls/115888
2023-12-11 10:44:09 +01:00
Jeroen Bakker
c0cb39e41b Vulkan: Enable Tests Not Relying on a Context
Some test cases inside the vulkan backend don't rely on an initialized
Vulkan Context and can always be run.

This PR enables those test cases when `WITH_GTEST` and
`WITH_VULKAN_BACKEND` is on. Allowing some tests to run on the
buildbot.

Pull Request: https://projects.blender.org/blender/blender/pulls/114574
2023-11-24 13:27:41 +01:00
Clément Foucault
0684b68eb4 EEVEE-Next: Make Ambient Occlusion Pass use Horizon Scan
This adds a new way of computing occlusion using visibility bitmask. To
make it more algorithm agnostic, we name it horizon scan.
This cleans-up / simplify the code compared to the Horizon based solution.
There is no more trickery for fading influence of distant samples which
makes the result match cycles closer.

This introduces a new thickness option. Maintaining it relatively low
makes it possible to avoid over occlusion because of in front geometry.
Making it too low will cause under occlusion.

Related #112979

Pull Request: https://projects.blender.org/blender/blender/pulls/114150
2023-11-02 19:22:01 +01:00
Clément Foucault
f79b86553a EEVEE-Next: Add mesh volume bounds estimation
This adds correct object bounds estimation.

This works by creating an occupancy texture where one
bit represents one froxel. A geometry pre-pass fill this
occupancy texture and doesn't do any shading. Each bit
set to 0 will not be considered occupied by the object
volume and will discard the material compute shader for
this froxel.

There is 2 method of computing the occupancy map:
- Atomic XOR: For each fragment we compute the amount of
  froxels **center** in-front of it. We then convert that
  into occupancy bitmask that we apply to the occupancy
  texture using `imageAtomicXor`. This is straight forward
  and works well for any manifold geometry.
- Hit List: For each fragment we write the fragment depth
  in a list (contained in one array texture). This list
  is then processed by a fullscreen pass (see
  `eevee_occupancy_convert_frag.glsl`) that sorts and
  converts all the hits to the occupancy bits. This
  emulate Cycles behavior by considering only back-face
  hits as exit events and front-face hits as entry events.
  The result stores it to the occupancy texture using
  bit-wise `OR` operation to compose it with other non-hit
  list objects. This also decouple the hit-list evaluation
  complexity from the material evaluation shader.

## Limitations
### Fast
- Non-manifolds geometry objects are rendered incorrectly.
- Non-manifolds geometry objects will affect other objects
  in front of them.
### Accurate
- Limited to 16 hits per layer for now.
- Non-manifolds geometry objects will affect other objects
  in front of them.

Pull Request: https://projects.blender.org/blender/blender/pulls/113731
2023-10-19 19:22:14 +02:00
Jason Fielder
19765a1f99 GPU: Ensure MTL texture tests are passing and add 1D/3D texture tests
Changes to ensure all supported texture tests are passing with the
Metal backend and add additional tests to cover texture_3d and
texture 1d test cases.

Authored by Apple: Michael Parkin-White

Co-authored-by: Michael Parkin-White <mparkinwhite@apple.com>
Pull Request: https://projects.blender.org/blender/blender/pulls/113889
2023-10-18 18:03:00 +02:00