Commit Graph

43 Commits

Author SHA1 Message Date
Jeroen Bakker
e2dc63c5de Fix #147618: PyGPU incorrect colors when drawing images
644fb2b679 fixed a long standing issue
that offscreen example showed the wrong colors. However the fix assumes
that input texture color space is always sRGB.

This adds a shader variation that draws textures that are stored in scene referred
linear color space (like all of our Image data-block).

Co-authored-by: Clément Foucault <foucault.clem@gmail.com>
Pull Request: https://projects.blender.org/blender/blender/pulls/147788
2025-10-16 19:12:16 +02:00
Christoph Neuhauser
ad4adccdeb GPU: Added image format validation for shader image bindings
The OpenGL specs require that the storage image qualifier in shaders
(e.g., "rgba32f") needs to be compatible with the format of a bound image
(see https://registry.khronos.org/OpenGL/specs/gl/glspec46.core.pdf#page=318).

We know that Blender currently does not handle this correctly in
multiple places. AMD and NVIDIA seem to silently ignore a mismatch and
just seem to use the format of the bound image. However, for the
Intel Windows drivers, this seems to lead to visual corruptions
(#141436, #141173). While a more graceful handling of a mismatch may
be nice, this is in line with the OpenGL specs.

This PR adds code for validating image formats for bindings.

Pull Request: https://projects.blender.org/blender/blender/pulls/143791
2025-08-27 15:43:09 +02:00
YimingWu
37df7ea850 Fix #137429: GPU: Allow missing attribute in pygpu_shader_attrs_info_get
In `pygpu_shader_attrs_info_get`, it tries to check information for all
vertex attributes that are added via `VERTEX_IN`, however some drivers
will optimize compiled shaders so some vertex attributes that are not
used will be removed. This fix makes sure that the input length that
is used in `GPU_shader_get_attribute_len` does not exceed actual max
binding number.

Pull Request: https://projects.blender.org/blender/blender/pulls/137584
2025-07-17 15:54:12 +02:00
Clément Foucault
bb2d123fbd Cleanup: DRW: Remove ObjectInfos legacy GLSL macros
_No response_

Pull Request: https://projects.blender.org/blender/blender/pulls/135542
2025-03-06 11:06:26 +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
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
324517fd78 Cleanup: GPU: Fix clang tidy warnings
Removes some other things like:
- `TRUST_NO_ONE` which was the same as `#ifndef NDEBUG`.
- Replace `reinterpret_cast` by `unwrap`

Pull Request: https://projects.blender.org/blender/blender/pulls/129631
2024-10-31 15:18:29 +01:00
Clément FOUCAULT
d712f91881 DRW: Primitive Expansion
This PR introduces the concept of primitive expansion draws.
This allows to create a drawcall that will generate N amount of new
primitive for an original primitive in a `gpu::Batch`. The intent is to
phase out the use of geometry shader for this purpose.

This adds a new `Frequency::GEOMETRY` only available for SSBOs.
The resources using this will be fed the current `gpu::Batch` VBOs
using name matching.

A dedicated slot is reserved for the index buffer, which has its own
internal  lib to decode the index buffer content.

A new attribute lib is added to ease the loading of unaligned attribute.
This should be revisited and made obsolete once more refactor
lands.

It is similar to the Metal backend SSBO vertex fetch path but it is
defined on a different level. The main difference is that this PR is
backend independant and modify the draw module instead of the GPU
module. However, it doesn't cover all possible attribute conversion
cases. This will only be added if needed.

This system is less automatic than the Metal backend one and needs
more care to make sure the data matches what the shader expects.
The Metal system will be removed once all its usage have been
converted.

This PR only shows example usage for workbench shadows. Cleanup PRs
will follow this one.

Rel #105221

Pull Request: https://projects.blender.org/blender/blender/pulls/125782
2024-08-03 11:06:17 +02: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
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
Campbell Barton
345d1a4b44 Cleanup: simplify struct declarations in C++
Replace `typedef struct X {} X;` with `struct X {};`

In some cases the first and last name didn't match although this
is rarely useful, even a typo in some cases, e.g. TrachPathPoint.
2023-07-02 19:54:26 +10:00
Sergey Sharybin
c1bc70b711 Cleanup: Add a copyright notice to files and use SPDX format
A lot of files were missing copyright field in the header and
the Blender Foundation contributed to them in a sense of bug
fixing and general maintenance.

This change makes it explicit that those files are at least
partially copyrighted by the Blender Foundation.

Note that this does not make it so the Blender Foundation is
the only holder of the copyright in those files, and developers
who do not have a signed contract with the foundation still
hold the copyright as well.

Another aspect of this change is using SPDX format for the
header. We already used it for the license specification,
and now we state it for the copyright as well, following the
FAQ:

    https://reuse.software/faq/
2023-05-31 16:19:06 +02:00
Jeroen Bakker
c0e61afc05 GPU: Make ShaderInterface.debug_print const
Method didn't modified the ShaderInterface but wasn't usable when trying
to debug a const reference to the ShaderInterface. This PR just adds the
const to the method.

Pull Request: https://projects.blender.org/blender/blender/pulls/108190
2023-05-23 15:55:47 +02:00
Jeroen Bakker
7fb1f060ff Vulkan: Initial Compute Shaders support
This patch adds initial support for compute shaders to
the vulkan backend. As the development is oriented to the test-
cases we have the implementation is limited to what is used there.

It has been validated that with this patch that the following test
cases are running as expected
- `GPUVulkanTest.gpu_shader_compute_vbo`
- `GPUVulkanTest.gpu_shader_compute_ibo`
- `GPUVulkanTest.gpu_shader_compute_ssbo`
- `GPUVulkanTest.gpu_storage_buffer_create_update_read`
- `GPUVulkanTest.gpu_shader_compute_2d`

This patch includes:
- Allocating VkBuffer on device.
- Uploading data from CPU to VkBuffer.
- Binding VkBuffer as SSBO to a compute shader.
- Execute compute shader and altering VkBuffer.
- Download the VkBuffer to CPU ram.
- Validate that it worked.
- Use device only vertex buffer as SSBO
- Use device only index buffer as SSBO
- Use device only image buffers

GHOST API has been changed as the original design was created before
we even had support for compute shaders in blender. The function
`GHOST_getVulkanBackbuffer` has been separated to retrieve the command
buffer without a backbuffer (`GHOST_getVulkanCommandBuffer`). In order
to do correct command buffer processing we needed access to the queue
owned by GHOST. This is returned as part of the `GHOST_getVulkanHandles`
function.

Open topics (not considered part of this patch)
- Memory barriers & command buffer encoding
- Indirect compute dispatching
- Rest of the test cases
- Data conversions when requested data format is different than on device.
- GPUVulkanTest.gpu_shader_compute_1d is supported on AMD devices.
  NVIDIA doesn't seem to support 1d textures.

Pull-request: #104518
2023-02-21 15:04:52 +01:00
Clément Foucault
173a8f4ac9 GPU: Removes GPU_shader_get_builtin_ssbo
Simplify the API. Use hardcoded ssbo location instead.
2023-02-13 11:22:38 +01:00
Jeroen Bakker
6c66f3e2b3 GPU: Remove prototype without implementation.
`GPUShaderInterface(const ShaderCreateInfo&)` is defined but its
implementation has been removed.
2023-02-02 11:46:29 +01:00
Clément Foucault
bfb6ea898b DRW: View: Add base for multi-view support
This implements the base needed for supporting multiple view concurently
inside the same drawcall.

The view used by common macros and view related functions is indexed using
a global variable `drw_view_id` which can be set arbitrarly or read
from the `drw_ResourceID`.

This is needed for EEVEE-Next shadow but can be used for other purpose
in the future.

Note that a shader specialization is needed for it to work. `DRW_VIEW_LEN`
needs to be defined to the amount of view the shader will access.

The number of views contained in a `draw::View` is set at construction
time.

Note that the maximum number of object correctly drawn by the shaders
using multiple views will be lower than thoses who don't.
2022-11-14 11:17:38 +01:00
Clément Foucault
a945cf4d0f DRW: Move clipping planes to their own UBO
This is part of the effor to simplify the View struct in order to implement
multiview rendering.
2022-10-07 12:43:10 +02:00
Germano Cavalcante
6269d66da2 PyGPU: GPUShader: implementation of 'attrs_info_get' method
With the new `attrs_info_get` method, we can get information about
the attributes used in a `GPUShader` and thus have more freedom in the
automatic creation of `GPUVertFormat`s

Reviewed By: fclem, campbellbarton

Differential Revision: https://developer.blender.org/D15764
2022-09-01 08:25:55 -03:00
Clément Foucault
f6639cc4fc DRW: DebugDraw: Port module to C++ and add GPU capabilities
This is a complete rewrite of the draw debug drawing module in C++.
It uses `GPUStorageBuf` to store the data to be drawn and use indirect
drawing. This makes it easier to do a mirror API for GPU shaders.

The C++ API class is exposed through `draw_debug.hh` and should be used
when possible in new code.

However, the debug drawing will not work for platform not yet supporting
`GPUStorageBuf`. Also keep in mind that this module must only be used
in debug build for performance and compatibility reasons.
2022-08-09 15:45:46 +02:00
Clément Foucault
862170c0b1 Cleanup: GPU: Replace NULL by nullptr from C++ files 2022-07-15 11:16:14 +02:00
Campbell Barton
c434782e3a File headers: SPDX License migration
Use a shorter/simpler license convention, stops the header taking so
much space.

Follow the SPDX license specification: https://spdx.org/licenses

- C/C++/objc/objc++
- Python
- Shell Scripts
- CMake, GNUmakefile

While most of the source tree has been included

- `./extern/` was left out.
- `./intern/cycles` & `./intern/atomic` are also excluded because they
  use different header conventions.

doc/license/SPDX-license-identifiers.txt has been added to list SPDX all
used identifiers.

See P2788 for the script that automated these edits.

Reviewed By: brecht, mont29, sergey

Ref D14069
2022-02-11 09:14:36 +11:00
Clément Foucault
e5af6a0d0f GLShaderInterface: Fix SSBO using the ubo mask
This might head lead to a crash when a shader uses both ubo and ssbo.
2022-02-05 13:28:41 +01:00
Clément Foucault
0379ddac7d GPUShaderCreateInfo: Add optionnal check for optimized out resources
This opt-in functionnality enabled developper keep track of unused
resources present in the `GPUShaderCreateInfo` descriptors of their
shaders.

The output is pretty noisy at the moment so we do not enforce its usage.
2022-01-27 10:30:06 +01:00
Clément Foucault
57dfec79f4 DRW: Fix builtin uniform name mismatch
This lead to severe unreported regression, like volume rendering broken
in workbench.
2022-01-26 19:09:05 +01:00
Clément Foucault
5b299e5999 D13910: Workbench: Port shaders to use GPUShaderCreateInfo
Also adds a few things to GPUShader for easily create shaders.
Heavy usage of macros to compose the createInfo and avoid
duplications and copy paste bugs.
This makes the link between the shader request functions
(in workbench_shader.cc) and the actual createInfo a bit
obscure since the names are composed and not searchable.

Reviewed By: jbakker
Differential Revision: https://developer.blender.org/D13910
2022-01-26 12:46:37 +01:00
Jeroen Bakker
9d3f35a0bf Revert "Revert "GPUShaderCreateInfo for interface abstraction""
This reverts commit edee5a947b.

Fixes compilation error (Missing file BLI_float2.hh)
2022-01-17 14:46:32 +01:00
Jeroen Bakker
edee5a947b Revert "GPUShaderCreateInfo for interface abstraction"
This reverts commit 8fb2ff458b.
Missing some files.
2022-01-17 14:34:28 +01:00
Jeroen Bakker
8fb2ff458b GPUShaderCreateInfo for interface abstraction
This is a first part of the Shader Create Info system could be.

A shader create info provides a way to define shader structure, resources
and interfaces. This makes for a quick way to provide backend agnostic
binding informations while also making shader variations easy to declare.

- Clear source input (only one file). Cleans up the GPU api since we can create a
  shader from one descriptor
- Resources and interfaces are generated by the backend (much simpler than parsing).
- Bindings are explicit from position in the array.
- GPUShaderInterface becomes a trivial translation of enums and string copy.
- No external dependency to third party lib.
- Cleaner code, less fragmentation of resources in several libs.
- Easy to modify / extend at runtime.
- no parser involve, very easy to code.
- Does not hold any data, can be static and kept on disc.
- Could hold precompiled bytecode for static shaders.

This also includes a new global dependency system.
GLSL shaders can include other sources by using #pragma BLENDER_REQUIRE(...).

This patch already migrated several builtin shaders. Other shaders should be migrated
one at a time, and could be done inside master.

There is a new compile directive `WITH_GPU_SHADER_BUILDER` this is an optional
directive for linting shaders to increase turn around time.

What is remaining:
- pyGPU API {T94975}
- Migration of other shaders. This could be a community effort.

Reviewed By: jbakker

Maniphest Tasks: T94975

Differential Revision: https://developer.blender.org/D13360
2022-01-17 14:32:28 +01:00
Campbell Barton
3d3bc74884 Cleanup: remove redundant const qualifiers for POD types
MSVC used to warn about const mismatch for arguments passed by value.
Remove these as newer versions of MSVC no longer show this warning.
2022-01-07 14:16:26 +11:00
Aaron Carlisle
4067367b6c Cleanup: Clang-tidy: modernize-redundant-void-arg 2022-01-05 21:44:22 -05:00
Campbell Barton
7c76bdca1b Cleanup: move public doc-strings into headers for 'gpu'
Ref T92709
2021-12-09 20:01:47 +11:00
Jeroen Bakker
87055dc71b GPU: Compute Pipeline.
With the compute pipeline calculation can be offloaded to the GPU.
This patch only adds the framework for compute. So no changes for users at
this moment.

NOTE: As this is an OpenGL4.3 feature it must always have a fallback.

Use `GPU_compute_shader_support` to check if compute pipeline can be used.
Check `gpu_shader_compute*` test cases for usage.

This patch also adds support for shader storage buffer objects and device only
vertex/index buffers.

An alternative that had been discussed was adding this to the `GPUBatch`, this
was eventually not chosen as it would lead to more code when used as part of a
shading group. The idea is that we add an `eDRWCommandType` in the near
future.

Reviewed By: fclem

Differential Revision: https://developer.blender.org/D10913
2021-05-26 16:49:30 +02:00
Campbell Barton
20a6255d49 Cleanup: spelling 2021-02-17 15:04:29 +11:00
Campbell Barton
17e1e2bfd8 Cleanup: correct spelling in comments 2021-02-05 16:23:34 +11:00
Campbell Barton
54f89e8704 Cleanup: docy comments beginning with '/**' don't end with '**/' 2021-01-04 17:38:11 +11:00
Campbell Barton
17a2820da8 Cleanup: consistent TODO/FIXME formatting for names
Following the most widely used convention for including todo's in
the code, that is: `TODO(name):`, `FIXME(name)` ... etc.
2020-09-19 14:34:32 +10:00
Clément Foucault
136bdb561b GPU: Add Image Load Store extension support
This wraps the functionality used to speedup EEVEE volumetrics.

This touches the rendering code of EEVEE as it should fix a mis-usage of
the GL barrier. The barrier changed type and location, removing an
unused barrier.
2020-09-12 15:29:54 +02:00
Clément Foucault
7d4adbdfab GLTexture: Add validation for empty slots before drawing
This is to have better error detection in debug builds.
This is not a replacement for a full check like in renderdoc but it
might catch some issues early on.
2020-09-05 17:49:14 +02:00
Clément Foucault
53a806f6df GPU: Move UBO binding validation to GL backend
This also make the validation quicker by tracking the currently
bound slots.
2020-09-01 12:03:52 +02:00
Campbell Barton
661ba642f2 Cleanup: spelling 2020-08-22 00:10:52 +10:00
Clément Foucault
3a6e981bcd Cleanup: GPU: Update classes comments
This should avoid confusion about what is a class and what is an opaque
pointer.
2020-08-21 14:16:42 +02:00
Clément Foucault
19d72175ba GPUShaderInterface: GL backend isolation 2020-08-20 16:11:14 +02:00