Commit Graph

117 Commits

Author SHA1 Message Date
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
daadf38780 Fix: DRW: Tests: Asserts in test_draw_submit_only
The setup was not setuping a correct rendering
environment (missing resource + framebuffer).
2025-04-29 18:16:10 +02:00
Clément Foucault
f2cfa822da Fix: DRW: Broken or non-deterministic tests
The test_draw_submit_only was broken because of the
empty pass optimization #135875. Making the passes
non-empty fixes the test.

`eevee_surfel_list` has non-deterministic result. This
should be investigated in the future.
2025-04-16 21:48:47 +02:00
Clément Foucault
0b2a178efc Fix: DRW: Uninitialized mutex in tests
Tests were calling the submission mutex without
init. Adding functions to expose only setting
up the submission mutex instead of the full
DRW context (which is uneeded here).
2025-04-16 21:38:19 +02:00
Clément Foucault
894c7fa4e2 EEVEE: Remove EEVEE Next mention inside the code
This only changes file and function names.
The EEVEE identifier is still `BLENDER_EEVEE_NEXT`.

No functional changes.
2025-03-17 15:37:04 +01:00
Clément Foucault
94c7c84bcd Refactor: DRW: Simplify the DRWContext classes and methods
This refactor part of `draw_manager_c.cc` to make it more understandable
and less bug prone.

- Splits the context handing to `draw_gpu_context.cc`
- Rename `draw_manager_c.cc` to `draw_context.cc`
- Merge `DRWContextState` into `DRWContext`
- Merge lots of static functions into `DRWContext` to avoid global access
- Deduplicate code between entry point functions
- Move context init logic to `DRWContext` constructor
- Move resource init logic to `DRWContext::acquire_data`
- Move extraction `TaskGraph` out of `DRWContext`
- Reduce / centralize complexity of enabling draw engines
- Reduce the amount of `drw_get` calls
- Remove unused code

Pull Request: https://projects.blender.org/blender/blender/pulls/135821
2025-03-13 13:47:02 +01:00
Clément Foucault
7a3ef6a8ab Cleanup: DRW: Remove draw_manager_c from DRW_gpu_wrapper.hh dependencies
This makes dependency on the draw manager clearer and improve
build time.
2025-02-18 12:50:30 +01:00
Clément Foucault
5b6f4d4759 Cleanup: DRW: Remove unused API functions
Pull Request: https://projects.blender.org/blender/blender/pulls/134461
2025-02-17 12:37:53 +01:00
Brecht Van Lommel
569e0f5e7f Fix: Build error in eevee tests after recent cleanups 2025-01-31 18:46:01 +01:00
Brecht Van Lommel
61eedabae9 Cleanup: Various clang-tidy warnings in draw
Pull Request: https://projects.blender.org/blender/blender/pulls/133734
2025-01-31 17:03:18 +01:00
Brecht Van Lommel
d5d686d540 Fix: Build error with draw test after recent cleanup 2025-01-23 13:17:20 +01:00
Jeroen Bakker
6cb8cdaa45 Fix: Draw: Tests
Visibility test is not setup correctly and only tests positives. This
test should be adapted with better testing. For now we skip the test.

Resource id test was wrong as it didn't add the null resource for
drawcalls with no handle. Ref `DrawCommandBuf::generate_commands`.

Pull Request: https://projects.blender.org/blender/blender/pulls/133040
2025-01-14 12:11:32 +01:00
Clément Foucault
eeeac09241 DRW: Update reference for pass_all_commands and manager_sync tests
These were not updated after functional changes.
2024-11-18 21:33:17 +01:00
Clément Foucault
63a91c8d82 Fix: DRW: Tests: GPU backend error because of missing resources 2024-11-10 23:47:21 +01:00
Clément Foucault
20d09435ab DRW: Add split visibility and command generation function
This adds the possibility to the user code to
group visibility and command generation compute
dispatch together to reduce the overhead of
PSO and pipeline switch.

This PR also make passes that have been submitted
(i.e.: that generated commands) as read-only.

This allows to automatically remove redundant
command generation when submitting the same
pass with the same view multiple times, or,
remove redundant visibility calculation for the
same view in multiple passes. This automation
is done for the common usage of the API (using `submit`).

Custom usage (using `submit_only`) needs to abide by
the rule of the API and update visibility and commands
when required.

Pull Request: https://projects.blender.org/blender/blender/pulls/129170
2024-10-21 13:32:54 +02:00
Clément Foucault
65efde82c3 EEVEE: Update shadow finalize test 2024-08-23 16:11:28 +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
e0b3dee35a EEVEE-Next: Jittered Soft Shadows
Jittered Soft Shadows support.
Improves soft shadow quality at the cost of re-rendering shadow maps every sample.
Disabled by default in the viewport unless enabled in the Scene settings.

| Tracing-only | Jitter-only | Jitter+Over-blur |
| --- | --- | --- |
| ![imagen](/attachments/e5ca6120-0666-4e86-b6e0-3d7512587b86) | ![imagen](/attachments/a72631aa-14f8-4e10-a748-848fc4bd4ab2) | ![imagen](/attachments/07c5de65-61d2-48e7-b78c-9c3cbdcaf844) |

Tracing-only is the method used by default in EEVEE-Next.
Jitter-only is the method used by EEVEE-Legacy Soft Shadows.
Jitter+Over-blur combines both.

Co-authored by Miguel Pozo @pragma37 (initial patch #119753)

Pull Request: https://projects.blender.org/blender/blender/pulls/121836
2024-05-18 17:21:47 +02:00
Clément Foucault
c7bc3334ad EEVEE-Next: Shadow: Add Maximum Resolution Option
This adds a light parameter to avoid near camera pixels
allocating too much shadow resolution.

This is more intuitive than the scale shadow setting and
allows reducing the precision without changing the look
of distant shadows.

For sun lights, the property sets the minimum pixel
size the shadow can contains. This allows to
remove a lot tilemap close up.

For local lights, there is another additional property
to set the maximum resolution in shadow space (like
EEVEE-Legacy) instead of in world space (like sun
lights). This allows making older files lighter and
allow a more conservative approach to resolution.

This add versionning code to handle EEVEE-Legacy files
that had fixed resolution per light type.

The resolution setting is always in world space distance
as the maximum shadow resolution distribution might change
in the future or be dependent on other parameters
(like beam angle). This ensure that there is no
dependency on these parameters, but make the
setting use very small units. But this is more of
a UI problem.

Pull Request: https://projects.blender.org/blender/blender/pulls/121701
2024-05-13 14:34:11 +02:00
Clément Foucault
87d164c56b EEVEE-Next: Improve shadow tracing
The goal of this PR is to remove the per face, NDC space
tracing for shadow maps.

This requires custom occluder extrapolation but in return
removes quite a lot of complexity in other areas, namely:
- No more per face transform before the tracing
- No more per face jittering (fix #119565)
- No more frustum padding (increased maximum precision)
- Better use of 32bit precision shadow map
- Fix #121343

This improve softness at relatively low step count (default 6
is better) and reduces light leaking at very low sample
count (sharper). It makes it more intuitive now that
higher sample count is smoother.

Pull Request: https://projects.blender.org/blender/blender/pulls/121317
2024-05-07 14:52:47 +02:00
Campbell Barton
9918488bb1 Cleanup: use uppercase tags, following own style guide 2024-05-03 11:33:21 +10:00
Clément Foucault
bb44bce95c EEVEE-Next: Improve shadow bias
The goal of this PR is to remove any user facing parameter
bias that fixes issues that are caused by inherent nature of
the shadow map (aliasing or discretization).

Compute shadow bias in the normal direction to avoid
both shadow leaking at certain angles or shadow
acnee.

This bias is computed automatically based on the minimum
bias amount required to remove all errors. The render
setting is removed as of no use for now.

#### Normal bias
We do the bias in world space instead of shadow space
for speed and simplicity. This requires us to bias using
the upper bound of biases for the same location in space
(using biggest texel world radius instead of UVZ bias).
This isn't much of an issue since the bias is still less
than 2 texel. The bias is still modulated by facing
ratio to the light so surfaces facing the light have no
biase.

This fixes both self shadowing and flat occluders aliasing
artifacts at the cost of moving the shadow a bit on the
side. This is the blue arrow in the diagram.

We always bias toward the normal direction instead of the
light direction. This is alike Cycles geometric offset for
the shadow terminator fix. This is better since it does'nt
modify the shading at all.

#### Slope bias
To avoid aliasing issue on zero slope receiver, we still
have to use the slope bias with a size of 1 pixel.

#### PCF filtering
We now parametrize the filter around the normal instead of
using the shadow map local space. This requires to use
a disk filter instead of box, which is also more pleasant
for most light shapes (all except rectangle lights).

Setting the filter around normal avoid overshadowing from
zero slope occluders. This cannot be fixed by more slope bias
in light space PCF. We could fix it in light space by projecting
onto the normal plane but that gives an unbounded bias when `N.L`
is near 0 which causes either missing shadows or self shadow if
using an arbitrary max offset value.

To avoid overshadowing from any surface behind the shading
point, we reflect the offset to always face the light.
Doing so instead of using the perpendicular direction
is better for very sharp geometric angles, has less
numerical precision issue, is symetrical and is cheaper.

To avoid any self shadowing artifact on zero slope receivers
with angled neighbors (like a wall and the floor), we have
to increase the slope bias according to the filter size.
This might be overkill in most situation but I don't feel
this should become a setting and should be kept in sync
with the filter. If it has to become an option, it should
simply a factor between unbiased filter and best bias.

#### Shadow terminator

The remaining artifacts are all related to shadow terminator
one way or another. It is always caused by the shading
normal we use for biasing and visibility computation not
being aligned with the geometric normal.

This is still something we need a setting for somewhere.

Pull Request: https://projects.blender.org/blender/blender/pulls/121088
2024-04-27 14:30:52 +02:00
Clément Foucault
e725cc3494 Fix: EEVEE-Next: Shadow: Casters behind area lights cast shadow
This introduces fragment clipping for the shadow pipeline.

The fragments are culled using a sphere distance test
for sphere lights, which is then re-purposed as a simple
distance test for area lights.

However, in the case of area lights, this introduces some
light bleeding. To mitigate this, we bring the shadow origin
back towards the light center so that this artifact only
appears if using larger shadow tracing.

Fixes #119334

Pull Request: https://projects.blender.org/blender/blender/pulls/120992
2024-04-24 17:08:12 +02:00
Clément Foucault
7797231c6d EEVEE-Next: Shadow: Add LOD system to directional clipmap shadows
This act in multiple phases:

- A shader scan the whole clipmap after tilemap finalize to gather
where valid tiles from lower LODs are available and write the page
location and LOD offset at invalid tiles location.

- At sampling time we add the LOD offset before the pixel page
modulo operation. This offset is equal to the amount of pages of
the **sampling** LOD needed to have the same modulo result as the
**sampled** LOD.

The whole thing being very tricky, I added a lot of unit testing.

This has no use for now but the system is needed to implement:
- Shadows from Volumetrics at lower cost & memory footprint.
- Fixing soft shadows artifacts.

These will be implemented in separate PRs.

Pull Request: https://projects.blender.org/blender/blender/pulls/120031
2024-03-29 16:22:55 +01:00
Clément Foucault
2a600b4a83 EEVEE-Next: Shadow: Limit view per shadow map projection
This limits the number of tilemaps per LOD that can be fed to avoid the
easy to hit "Too many shadow updates" (#119757).

This allows for a max 64 tilemaps to be updated at once at their lowest
requested LOD (so ~10.6667 point lights if every faces of the punctual
shadow map is needed, but likely more in practice).

Unfortunately this is still quite low and will surely be hit quite soon
with directional shadow added to it. One idea to workaround this would
be to time slice the update of some lights, but this opens a whole can
of worms that I'm not ready to open for now so I created #119890 for
future reference.

Some notes, most lights seems to request around 3 LODs. It might help
to allow requesting at least 2 LODs if we are rendering since volumes
might want lower LOD available for volumes.

I added a very simplistic heuristic that also lowers the max tilemaps
when transforming, animation playback or navigating the 3D view to
improve the responsiveness of the engine. Note that this doesn't
only lowers the resolution to the minimum requested one. So it should
be good enough in most cases.

Pull Request: https://projects.blender.org/blender/blender/pulls/119889
2024-03-26 20:33:31 +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
a099061feb Cleanup: Move remaining draw headers to C++ 2024-03-23 14:51:59 +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
2f30d220fb Draw: Fix 'draw_resource_id_gen' test
The test uses a none points shader to draw points, which is incorrect
and asserts when using Vulkan. It also didn't test the gpu part of the
pipeline (PassMain).

When using PassMain the order of the resources are expected to be
different as the draw calls are ordered based on the primitive type and
handles.

Pull Request: https://projects.blender.org/blender/blender/pulls/117714
2024-02-01 14:10:51 +01:00
Jeroen Bakker
97852056b2 Cleanup: Incorrect Parameter Order for Expect
The expect and actual parameters were switched in eevee_surfel_list.
2024-02-01 12:05:28 +01:00
Clément Foucault
39397fd73e Cleanup: EEVEE-Next: Fix compilation warnings in shadow tests
Warnings were variable used before initialization.
2024-01-30 17:27:00 +01:00
Jeroen Bakker
062a9f9540 Fix: Compiling EEVEE test cases
Due to recent changes eevee test cases didn't compile anymore.
The issue was that a header file was migrated from C to CPP.

Pull Request: https://projects.blender.org/blender/blender/pulls/117436
2024-01-23 09:14:10 +01:00
Hans Goudey
5b55c1dc10 Cleanup: Move five draw headers to C++ 2024-01-05 13:26:22 -05:00
Jeroen Bakker
5dbc276eed Fix: Compiling EEVEE Test cases
Was introduced when BKE_main got a CPP header file.

Pull Request: https://projects.blender.org/blender/blender/pulls/115743
2023-12-04 09:55:48 +01:00
Hans Goudey
3d57bc4397 Cleanup: Move several blenkernel headers to C++
Mostly focus on areas where we're already using C++ features,
where combining C and C++ APIs is getting in the way.

Pull Request: https://projects.blender.org/blender/blender/pulls/114972
2023-11-16 11:41:55 +01:00
Miguel Pozo
0db6d8a5fc EEVEE-Next: Fix shadow tests
Fix an issue in `find_first_valid` where Nvidia would incorrectly
increment `src` after return.
This should fix the issue where some tiles would stay corrupted
until resetting EEVEE.

Initialize tiles_data in `TestAlloc` so it doesn't fail in debug builds.

Pull Request: https://projects.blender.org/blender/blender/pulls/114550
2023-11-06 20:35:14 +01:00
Hans Goudey
8f27baf388 Merge branch 'blender-v4.0-release' 2023-10-09 23:54:43 +02:00
Hans Goudey
976eaae02f Cleanup: Move BKE_object.hh to C++
Simplifies the fix to #111120, where the object bounds functions
may return a C++ type instead of `BoundBox`.

Pull Request: https://projects.blender.org/blender/blender/pulls/113462
2023-10-09 23:41:53 +02:00
Jason Fielder
57a3ab29cc Metal: EEVEE Next: Optimize Virtual shadow maps for Apple Silicon
Optimization of EEVEE Next's Virtual Shadow Maps for TBDRs.
The core of these optimizations lie in eliminating use of
atomic shadow atlas writes and instead utilise tile memory to
perform depth accumulation as a secondary pass once all
geometry updates for a given shadow view have been updated.

This also allows use of fast on-tile depth testing/sorting, reducing
overdraw and redundant fragment operations, while also allowing
for tile indirection calculations to be offloaded into the vertex
shader to increase fragment storage efficiency and throughput.

Authored by Apple: Michael Parkin-White

Co-authored-by: Michael Parkin-White <mparkinwhite@apple.com>
Co-authored-by: Clément Foucault <foucault.clem@gmail.com>
Pull Request: https://projects.blender.org/blender/blender/pulls/111283
2023-10-05 19:02:39 +02:00
Clément Foucault
eda7926834 DRW: Add SubPassTransition pass command 2023-10-01 18:01:15 +02:00
Clément Foucault
3a4fc2c94e EEVEE-Next: Shadow Map Tracing Initial Implementation
Shadow Map Ray Tracing is a technique that ray cast against the shadow
depth buffer. The technique is described in "Soft Shadows by
Ray Tracing Multilayer Transparent Shadow Maps".
Note that we only implement the single layer approach since storing
multiple depth is prohibitively expensive.

Pull Request: https://projects.blender.org/blender/blender/pulls/111809
2023-09-26 23:42:40 +02:00
Clément Foucault
0a4fa62f51 EEVEE: Add support for metallic F82 tint
This adds a new entry to the split sum LUT to isolate
the effect of the F82 tint.

The application of the tint part is similar to cycles
and uses the same way for precomputing the `b` factor.

Results matches almost perfectly to the extent of the
split sum approximation.

Note that this removes the unused LTC MAG LUT for
EEVEE next to make space for the new table. It can still
be added back if needed.

Pull Request: https://projects.blender.org/blender/blender/pulls/112881
2023-09-26 10:16:39 +02:00
Hans Goudey
867f99c2af Cleanup: Move depsgraph headers to C++
Pull Request: https://projects.blender.org/blender/blender/pulls/110816
2023-09-22 03:18:17 +02:00
Clément Foucault
e2cef1c713 EEVEE-Next: Port SSS profile to Pre-compute shader
This moves the pre-computation offline and store the pre-computed
table in the binary. The pre-computed tables are quite small and are
not a concern with respect to binary size increase.

This rewrites the precomputation to use manually fitted
approximations for both burley and random walk.
The approximations fix a discrepancy between cycles and EEVEE
SSS translucency look. The absolute maximum error is below 2%.
I believe better results could be achieved with automatic fitting
tools.

Note that Cycles Burley translucency profile has some issues as it
does not give a smooth profile. The profile is biased near the end
of the lower radii. For this reason, the fit was done on a white
diffuse with (1,1,1) radii which does not exhibit this artifact.

Note that while this adds the profile for random walk, it isn't
currently used because the profile type is not yet passed down
the deferred path.

The fitting data can be found attached to this PR.

Pull Request: https://projects.blender.org/blender/blender/pulls/112512
2023-09-20 15:17:27 +02:00
Weizhen Huang
e0dacfdda6 EEVEE: use Schlick's approximation instead of real Fresnel for glass
so that we can tint `F0` separately
Ref: #112192 #99447

Mostly affects `IOR < 1`. The overall appearance matches, with some changes in the reflection.

Pull Request: https://projects.blender.org/blender/blender/pulls/112390
2023-09-18 14:26:19 +02:00
Weizhen Huang
5baf652374 Cleanup: EEVEE: rename glass BTDF to BSDF at several places
because it contains reflectance and transmittance, so BSDF would be a
morep proper name.
Also rename BSDF to BRDF at places where only reflectance is returned.
2023-09-14 16:06:26 +02:00
Clément Foucault
938d43c317 Fix: EEVEE-Next: Fix LUT translation unit hanging debug build 2023-09-04 11:43:02 +02:00
Clément Foucault
30de3d7c1a EEVEE-Next: Move LUT to C++ and eevee-next folder 2023-09-03 17:22:31 +02:00
Clément Foucault
760aa0e917 Cleanup: EEVEE-Next: Rename LookUpTable to Precompute 2023-09-03 16:42:53 +02:00
Clément Foucault
2637bbf016 EEVEE-Next: Add LUT test
This avoid the generation code to become desync with
the precomputed tabled.

This is also a good way to test any changes to them.
2023-09-03 16:42:53 +02:00