Commit Graph

5084 Commits

Author SHA1 Message Date
Campbell Barton
6e3eaae299 Cleanup: spelling in comments 2024-04-14 12:13:55 +10:00
Campbell Barton
43179864f4 Cleanup: remove strcpy usage 2024-04-14 11:58:14 +10:00
Clément Foucault
fdf5a05bde Fix: EEVEE-Next: Broken shader compilation because of displacement
Oversight inside f371624b2e
2024-04-13 12:57:50 +02:00
Clément Foucault
f371624b2e Fix: EEVEE-Next: Displacement: Wrong output space
The space of the displacement socket on the ouput node
is local space. We now scale it back to world space
as expected by the consumer code.
2024-04-13 12:37:29 +02:00
Clément Foucault
b07d392b5a MTL: Remove warning in debug build 2024-04-13 09:12:22 +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
Jason Fielder
5f86faf3a5 Metal: Fix write-only qualifier on shader generation
A small logic issue caused all write-only image resources
to be tagged as read-write in all cases. This caused
correctness issues on Intel and AMD GPUs which
are resolved through this change.

Change also yields a small performance uplift
due to enabling improved non-dependent workload
scheduling.

Authored by Apple: Michael Parkin-White

Co-authored-by: Michael Parkin-White <mparkinwhite@apple.com>
Pull Request: https://projects.blender.org/blender/blender/pulls/120528
2024-04-11 18:17:40 +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
Jeroen Bakker
c15e5116ab Vulkan: MoltenVK Support for Developers
MoltenVK original intent was to let developers work on a mac system developing
for the vulkan eco-system. MoltenVK doesn't support all the features that we
require and would require additional workarounds to be actually supported.

It is not expected that we will release Blender with MoltenVK for this reason.
But it still has value for shader developers to validate shaders on metal and
vulkan on a single platform.

![image](/attachments/9a4a9904-a5f6-4922-896d-744dfb78244c)

Pull Request: https://projects.blender.org/blender/blender/pulls/117940
2024-04-11 11:04:43 +02:00
Jason Fielder
5753a27624 Metal: Disable usage attachment for atomic buffer textures
Removes the implicit USAGE_ATTACHMENT flag from
atomic fallback textures which are buffer-backed.
This usage flag results in a validation failure, and is
not required by these textures as they are cleared
via the backing buffer.

Authored by Apple: Michael Parkin-White

Pull Request: https://projects.blender.org/blender/blender/pulls/119785
2024-04-11 10:46:20 +02:00
Campbell Barton
09ee8d97e6 Cleanup: use C-style comments for descriptive text 2024-04-11 17:44:27 +10: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
ea7657511c Cleanup: promote to size_t before calculating sizes
Avoids integer truncation although it's mostly theoretical in this case.
2024-04-09 14:06:37 +10: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
7e9f7320e4 Cleanup: spelling in comments & comment blocks 2024-04-04 11:26:28 +11:00
Campbell Barton
b03332a055 Cleanup: use BLI_assert_msg instead of checking string literals 2024-04-03 14:27:54 +11:00
Campbell Barton
d5d1025e94 Cleanup: use const pointer arguments 2024-04-03 10:22:05 +11:00
Omar Emara
0b1dc351e4 Fix: eGPUBarrier enum negate operator is broken
The ENUM_OPERATORS macro for the eGPUBarrier enum uses
GPU_BARRIER_UNIFORM as its maximum value, while it should be
GPU_BARRIER_BUFFER_UPDATE instead.
2024-04-01 16:14:23 +02:00
Hoshinova
c78c6b0bdf Fix #119797: Noise Texture Precision Issues
The Perlin noise algorithms suffer from precision issues when a coordinate
is greater than about 250000.

To fix this the Perlin noise texture is repeated every 100000 on each axis.
This causes discontinuities every 100000, however at such scales this
usually shouldn't be noticeable.

Pull Request: https://projects.blender.org/blender/blender/pulls/119884
2024-03-29 16:12:23 +01: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
362d381a5a Cleanup: pass GPUStateMutable as a const reference 2024-03-28 18:10:49 +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
Campbell Barton
3416fe6e1e License headers: add SPDX headers 2024-03-27 10:31:24 +11:00
Campbell Barton
40ab214c0a Cleanup: spelling in comments 2024-03-27 10:25:31 +11:00
Hans Goudey
48e4576162 Cleanup: Remove unnecessary keywords from C++ headers 2024-03-26 15:58:39 -04: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
Aras Pranckevicius
3663c8147c Vulkan: implement support for compressed textures
Textures that are GPU-compressed already (in practice: from DDS files
that are DXT1/DXT3/DXT5 compressed) now can stay GPU compressed
in Vulkan, similar to how that works on OpenGL.

Additionally, fixed lack of mipmaps in Vulkan textures. The textures
were created with mipmaps (good), the sampler too (good), but
the vulkan image view was always saying "yo, this is mip 0 only"
because mip range variables were never set to anything than zero.

Pull Request: https://projects.blender.org/blender/blender/pulls/119866
2024-03-26 14:49:53 +01:00
Jeroen Bakker
e811785f37 Vulkan: to_string for used vulkan types
Every vulkan installation has a vk.xml file containing the vulkan specification
in a machine readable fasion.

This PR uses the vk.xml to generate to_string functions for data types blender uses.
When updating to a new specification or when changing features/extensions we
should re-generate the to_string functions.

The generator is implemented in `vk_to_string.py`.

Pull Request: https://projects.blender.org/blender/blender/pulls/119880
2024-03-26 11:35:16 +01:00
Campbell Barton
155dae94d7 Cleanup: code-comments, use doxygen formatting & spelling corrections
Also move some function doc-strings from the implementation
to their declarations.
2024-03-26 17:55:20 +11:00
Hans Goudey
fc0d8ba012 Cleanup: Remove C++ ifdef checks in C++ headers
Pull Request: https://projects.blender.org/blender/blender/pulls/119900
2024-03-26 04:56:03 +01: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
Aras Pranckevicius
26337b9fb4 Metal: implement support for compressed textures
Noticed lack of it via #119793. Now DDS images using BC1/BC2/BC3
(aka DXT1/DXT3/DXT5) formats can keep on being GPU compressed
on Metal too, just like e.g. on OpenGL.

Pull Request: https://projects.blender.org/blender/blender/pulls/119835
2024-03-25 11:40:20 +01:00
Hans Goudey
b54d9875ba Fix: Another Metal build error after recent refactor
Sorry for the noise, I misread the output from the PR build.
2024-03-24 13:24:03 -04:00
Hans Goudey
aa87b747c5 Fix: Additional macOS metal build error 2024-03-24 12:37:36 -04: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
Miguel Pozo
def5f86cae Fix: EEVEE-Next: Material compilation
Move pcg functions to eevee_sampling_lib.
Including gpu_shader_common libs in engine code results in double  includes.
2024-03-22 18:58:12 +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
Campbell Barton
57dd9c21d3 Cleanup: spelling in comments 2024-03-21 10:02:53 +11:00
Miguel Pozo
3888bdf8b2 EEVEE-Next: Fix transparent shadows convergence
Replace the hashed alpha function in shadows for a fully random one.
Add pcg functions to `gpu_shader_common_hash.glsl`
(Split from #119480)

Pull Request: https://projects.blender.org/blender/blender/pulls/119526
2024-03-20 16:05:07 +01:00
Brecht Van Lommel
dc34e96dc4 Merge branch 'blender-v4.1-release' 2024-03-20 15:49:15 +01:00
Jason Fielder
c584597165 Fix #109363: Resolve GPencil fill in Metal
Resolves an issue with stroke rendering in
Metal using the geometry shader fallback
path. Stroke rendering now matches OpenGL
which should enable the GPencil fill tool to
function correctly at all zoom levels.

Authored by Apple: Michael Parkin-White

Pull Request: https://projects.blender.org/blender/blender/pulls/119660
2024-03-20 15:38:44 +01:00
Clément Foucault
23dce15f67 EEVEE-Next: Horizon Scan: Use Spherical harmonics
This uses Spherical Harmonics to store the indirect lighting and
distant lighting visibility.

We can then reuse this information for each closure which divide
the cost of it by 2 or 3 in many cases, doing the scanning once.

The storage cost is higher than previous method, so we split the
resolution scaling to be independant of raytracing.

The spatial filtering has been split to its own pass for performance
reason. Upsampling now only uses 4 bilinearly interpolated samples
(instead of 9) using bilateral weights to avoid bleeding.

This also add a missing dot product (which soften the lighting
around corners) and fixes the blocky artifacts seen at lower
resolution.

Pull Request: https://projects.blender.org/blender/blender/pulls/118924
2024-03-19 19:16:21 +01:00
Aras Pranckevicius
a05adbef28 BLF: optimizations and fixes to font shader
Simplifies/optimizes the "font" shader. It runs faster now too, but primarily
this is so that it loads/initializes faster.

* Instead of doing blur via individual bilinear samples (where each sample is 4
  texel fetches), do raw texel fetches of the kernel footprint and compute final
  result by shifting the kernel weights according to bilinear fraction weight.
  For 5x5 blur, this reduces number of texel fetches from 64 down to 36.
* Instead of checking "is the texel inside the glyph box? if so, then fetch it",
  first fetch it, and then set result to zero if it was outside. Simplifies the
  branching code flow in the compiled GPU shader.
* Avoid costly integer modulo/division for "unwrapping" the font texture. The
  texture width is always power of two size, so division/modulo can be replaced
  by masking and a shift. Setup uniforms to contain the needed data.

### Fixes

* The 3x3 blur was not doing a 3x3 blur, due to a copy-pasta typo (one of the
  sample offsets was repeated twice, and thus another sample offset was
  missing).
* Blur towards left/top edges of the glyphs had artifacts, because float->int
  casting in GLSL rounds towards zero, but the code actually wanted to round
  towards floor.

Image of how the blur has changed in the PR.

### First time initialization

* Windows 10, NVIDIA RTX 3080Ti, OpenGL: 274.4ms -> 51.3ms
* macOS, Apple M1 Max, Metal: 456ms -> 289ms (this is including PSO creation
  time).

### Shader performance/complexity

Performance I only measured on macOS (M1 Max), by making a BLF text that is
scaled up to cover most of screen via Python. Using Xcode Metal profiler,
drawing that text with 5x5 shadow blur: 1.5ms -> 0.3ms.

More performance analysis details in PR.

Pull Request: https://projects.blender.org/blender/blender/pulls/119653
2024-03-19 16:29:21 +01:00
Brecht Van Lommel
7a395e2e7f Revert changes from main commits that were merged into blender-v4.1-release
The last good commit was f57e4c5b98.

After this one more fix was committed, this one is preserved as well:
67bd678887.
2024-03-18 15:04:12 +01:00
Jason Fielder
661d12aef7 Fix #119195: Ensure Metal uses correct attribute conversion mode
Resolves custom attribute types for ints and booleans by ensuring
conversion mode is correct. Previously, the attribute declarations
were assumed to be linear. However, patch ensures the correct
attribute index is now fetched, ensuring the conversion mode
is correctly specified for non-linear attribute ID's.

Authored by Apple: Michael Parkin-White

Pull Request: https://projects.blender.org/blender/blender/pulls/119569
2024-03-18 13:38:09 +01:00