Commit Graph

460 Commits

Author SHA1 Message Date
Clément Foucault
f0254c2dcf Refactor: GPU: Remove unnecessary C wrappers for textures
This is the first step into merging `DRW_gpu_wrapper.hh` into
the GPU module.

This is very similar to #119825.

Pull Request: https://projects.blender.org/blender/blender/pulls/142732
2025-07-22 09:48:10 +02:00
Jesse Yurkovich
a27384e389 Fix: Typo in documentation for new POINT_UNIFORM_COLOR gpu shader
Typo introduced with initial commit c56a855b9f
2025-07-18 20:52:10 +02:00
Campbell Barton
6253a33aa3 Cleanup: use nodiscard attribute for functions in the Python API
In most (cases functions returning a PyObject pointer
requires it to be used by the caller, declare functions in the Python
API with the `nodiscard` attribute.
2025-06-28 10:15:27 +10:00
Campbell Barton
83ee7a3122 Merge branch 'blender-v4.5-release' 2025-06-27 18:58:40 +10:00
Andrej730
6dc0c85de6 Fix: PyDocs: GPUShader, use ref for better navigation
Also note removal version.

Ref !140846
2025-06-27 18:52:53 +10:00
Jeroen Bakker
03caffe540 GPU: Deprecate GPU_DATA_UINT_24_8
GPU_DATA_UINT_24_8 isn't used anymore. We cannot phase out the data type
as it can still be used by add-ons. This PR will deprecate
`GPU_DATA_UINT_24_8`. When used in an add-on a deprecation message will
be shown.

Pull Request: https://projects.blender.org/blender/blender/pulls/140715
2025-06-20 12:17:20 +02:00
Campbell Barton
715a8268fa Build: resolve errors & deprecation warnings with Python 3.14 beta
Python 3.14 has moved some functionality into the public API,
use the updated names even with older Python versions.

Also resolve an error caused by variable reuse with delayed annotation
evaluation for TextureProperties_MixIn on startup.

Resolve #140695.
2025-06-20 14:34:25 +10:00
Campbell Barton
6197335658 Build: resolve errors & deprecation warnings with Python 3.14 beta
Python 3.14 has moved some functionality into the public API,
use the updated names even with older Python versions.

Also resolve an error caused by variable reuse with delayed annotation
evaluation for TextureProperties_MixIn on startup.

Resolve #140695.
2025-06-20 04:19:35 +00:00
Jeroen Bakker
09af302457 GPU: Remove depth24 texture format
Metal and AMD/Intel/Vulkan don't support depth24 texture formats
natively. The backends implemented fallback to use depth32f in
stead.

Recently we removed all usages of depth24 to use depth32 and the
next step is to remove the depth24 format and the workarounds in
the backend.

Note: The removal of `GPU_DATA_UINT_24_8` isn't part of this PR.

Pull Request: https://projects.blender.org/blender/blender/pulls/140659
2025-06-19 16:24:06 +02:00
Jeroen Bakker
11ab2de07a Python/GPU: Deprecate DEPTH24 formats
GPU_DEPTH24_STENCIL8 and GPU_DEPTH_COMPONENT24 are deprecated in Blender
5.0. Internally they will be removed. When used via python they are
automatically converted to their DEPTH32F variant and a deprecation
warning will be displayed.

Pull Request: https://projects.blender.org/blender/blender/pulls/140644
2025-06-19 13:31:40 +02:00
Hans Goudey
6f0229b3a0 Cleanup: Remove unused Python OpenGL warning popup
Unused since decd88f67e
2025-06-16 10:27:40 -04:00
Clément Foucault
11063b5b90 pyGPU: Remove creating shaders directly from GLSL source files
The reasoning is that this is not supported by Vulkan.
In order to make shaders cross API compatible, python scripts
needs to use `GPUShaderCreateInfo`.

This removes the constructor all-together. Another option
is to raise an error inside the constructor and always
return none.

Rel #107374

Pull Request: https://projects.blender.org/blender/blender/pulls/140368
2025-06-16 12:51:15 +02:00
Clément Foucault
decd88f67e Python: Remove deprecated BGL API
The API was in a deprecation state for many years now.
This API was not compatible with Metal nor Vulkan.

This also remove `Image.bindcode`.

Pull Request: https://projects.blender.org/blender/blender/pulls/140370
2025-06-16 12:50:50 +02:00
Hans Goudey
913918a16e Merge branch 'blender-v4.5-release' 2025-06-12 12:25:21 -04:00
Clément Foucault
7add4e177b GPU: Add deprecation notice to the docstring of GPUShader constructor 2025-06-12 18:20:40 +02:00
Clément Foucault
e57359726f GPU: VertexFormat: Use new data types
This prevents the use of unaligned data types in
vertex formats. These formats are not supported on many
platform.

This simplify the `GPUVertexFormat` class a lot as
we do not need packing shenanigans anymore and just
compute the vertex stride.

The old enums are kept for progressive porting of the
backends and user code.

This will break compatibility with python addons.

TODO:
- [x] Deprecation warning for PyGPU (4.5)
  - [x] Deprecate matrix attributes
- [x] Error handling for PyGPU (5.0)
- [x] Backends
  - [x] Metal
  - [x] OpenGL
  - [x] Vulkan

Pull Request: https://projects.blender.org/blender/blender/pulls/138846
2025-06-10 17:20:45 +02:00
Jeroen Bakker
c56a855b9f Fix #139565: PyGPU: Add builtin point shaders
This PR adds builtin shaders for drawing points. Using `FLAT_COLOR`,
`SMOOTH_COLOR`, `UNIFORM_COLOR` can lead to undesired behavior
on Metal and Vulkan backends. To ensure future compatibility this PR
adds `POINT_FLAT_COLOR` and `POINT_UNIFORM_COLOR`.

The point size can be set using `gpu.state.point_size_set`.

Pull Request: https://projects.blender.org/blender/blender/pulls/139583
2025-05-29 14:36:32 +02:00
Christoph Neuhauser
282d703f6b Fix #139443: WM: Clear draw region framebuffers to avoid corruption
This PR adds a clear on creation for draw region framebuffers, which
fixes issue https://projects.blender.org/blender/blender/issues/139443.
When using the "Lock Interface" option, redrawing is disabled until the
rendering process has finished. When the GPU driver does not initialize
framebuffer textures with zero, this means that visual corruption can
be perceived when resizing the main window while rendering.
This fix makes sure that framebuffer textures are initialized with zero
on all GPU platforms.

Pull Request: https://projects.blender.org/blender/blender/pulls/139445
2025-05-28 13:17:37 +02:00
Clément Foucault
eb37d19b41 GPU: Python: Raise error when creating shaders without create info
This is adding a hard error for backends do that do not supports it.
Even without this, the backend would return a nullptr. But the error
message in this case was just "see console for more details" without
any additional detail. Which was confusing.
2025-05-26 11:09:49 +02:00
Falk David
4901f38400 Fix: GPU: Crash in pygpu_batch_draw
Introduced by `3d8854b021195fdb253c85133b1db350d3d4c753`.
`py_shader` could still be `nullptr` and needs to be checked.
2025-05-23 12:31:08 +02:00
Clément Foucault
3d8854b021 Fix #138823: GPU: Python: Incorrect color when using widelines
Add a deprecation warning and a helper to draw with
polyline shaders.

Pull Request: https://projects.blender.org/blender/blender/pulls/139216
2025-05-22 12:42:56 +02:00
Clément Foucault
57d9c2c098 GPU: Python: Temporarily add back non-4bytes aligned formats
Add back the deprecated format to avoid asserts.
GPU backends should still have the code to support them.

Also add deprecation warnings as these types will be
removed for 5.0.

Pull Request: https://projects.blender.org/blender/blender/pulls/139213
2025-05-22 12:14:52 +02:00
Clément Foucault
e40a9c6193 GPU: Python: Add workaround to support INT_TO_FLOAT
This promotes any INT_TO_FLOAT attribute to F32 and
to the float promotion inside python `attr_fill`.

We issue a deprecation warning when hitting this path.

Raise an error is the component type is not integer.

Pull Request: https://projects.blender.org/blender/blender/pulls/139206
2025-05-22 11:55:22 +02:00
Hans Goudey
91627b3d47 GPU: Remove int float fetch mode combination
This commit finishes removing the uses of the integer to float
vertex buffer fetch mode. Previous commits noted below already started
that process. The last usage was geometry attributes. Now integers are
converted to floats as part of the existing upload process.

The change makes the Vulkan vertex buffer type conversion unused, so
it's removed. That's nice because Vulkan vertex buffers go from 1040 to
568 bytes in size and have significantly less overhead on creation.

Related:
- 153abc372e
- 1e1ac2bb9b
- 617858e453

Pull Request: https://projects.blender.org/blender/blender/pulls/138873
2025-05-15 15:29:12 +02:00
Jeroen Bakker
41a69b76a6 Partial Fix #129592: Vulkan: Add support for line size
Add-ons can call a batch draw command for lines using a surface shader.
This is not intended and polylines shaders should be used. This PR
lighten this restriction to automatically replace the shader with the
correct polyline shader, similar to immediate mode.

This change is done inside the python wrapper as internally we should
use the correct polyline shader.

For point shaders we don't have a work around in place and that needs
more discussion. Therefore this is only a partial fix.

Pull Request: https://projects.blender.org/blender/blender/pulls/138138
2025-05-01 15:44:40 +02:00
Campbell Barton
43af16a4c1 Cleanup: spelling in comments, correct comment block formatting
Also use doxygen comments more consistently.
2025-05-01 11:44:33 +10:00
Clément Foucault
59df50c326 GPU: Refactor Qualifier and ImageType
This allow to use types closer to GLSL in resource
declaration.

These are aliased for clarity in the GPU
module (i.e. `isampler2D` is shortened to `Int2D`).

Rel #137446

Pull Request: https://projects.blender.org/blender/blender/pulls/137954
2025-04-24 14:38:13 +02:00
Clément Foucault
a6fa1b5969 DRW: Rename common_*_lib.glsl to follow module prefix 2025-04-16 20:19:09 +02:00
Clément Foucault
9990273d04 GPU: Change Type enum to use lower case values
This is to help for future resource declaration
using macros.

Rel #137261

Pull Request: https://projects.blender.org/blender/blender/pulls/137367
2025-04-11 22:39:01 +02:00
Clément Foucault
9d06508837 Fix #137052: GPU: Crash on startup caused by legacy pyGPU API
The removed legacy API was still in used by the pyGPU API.
Add a deprecation warning instead.

This partially reverts commit 3179cb0069.
2025-04-07 12:27:48 +02:00
Clément Foucault
3562433ae7 pyGPU: Deprecate Shader.program getter
This is getting in the way of making the
GPUShader API more threadsafe.

This getter already doesn't work for vulkan
and Metal, and has very limited usage.

Keeping the python function to avoid errors
and display a deprecation warning.

Pull Request: https://projects.blender.org/blender/blender/pulls/136983
2025-04-04 14:23:09 +02:00
nutti
eb3fb565bd PyDoc: correct formatting for GPUShaderCreateInfo.depth_write
Ref !136846
2025-04-04 10:18:34 +11:00
Campbell Barton
7ae020ecd1 Cleanup: use our utility function to create a PyUnicode from a std:str 2025-04-01 12:33:56 +11:00
Campbell Barton
e3d6051181 Cleanup: suppress cast-function-type warnings for CLANG
Extend the existing GCC pragma's and add the warning suppression
for Cycles & Freestyle.
2025-04-01 12:06:03 +11:00
Jeroen Bakker
5a5471b622 Python: Add GPUShaderCreateInfo.depth_write method
Setting depth_write option of ShaderCreateInfo isn't available in
python GPU module. This PR adds support of it.

References #136732

Pull Request: https://projects.blender.org/blender/blender/pulls/136752
2025-03-31 12:37:56 +02:00
Bastien Montagne
bb89c89e7f Cleanup: python: Replace 'void' MEM_[cm]allocN with templated, type-safe MEM_[cm]allocN<T>.
The main issue of 'type-less' standard C allocations is that there is no check on
allocated type possible.

This is a serious source of annoyance (and crashes) when making some
low-level structs non-trivial, as tracking down all usages of these
structs in higher-level other structs and their allocation is... really
painful.

MEM_[cm]allocN<T> templates on the other hand do check that the
given type is trivial, at build time (static assert), which makes such issue...
trivial to catch.

NOTE: New code should strive to use MEM_new (i.e. allocation and
construction) as much as possible, even for trivial PoD types.

Pull Request: https://projects.blender.org/blender/blender/pulls/135852
2025-03-12 11:21:53 +01:00
Brecht Van Lommel
27accea53e Cleanup: Various clang-tidy warnings in python
Pull Request: https://projects.blender.org/blender/blender/pulls/133734
2025-01-31 17:03:18 +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
Brecht Van Lommel
920e709069 Refactor: Make header files more clangd and clang-tidy friendly
When using clangd or running clang-tidy on headers there are
currently many errors. These are noisy in IDEs, make auto fixes
impossible, and break features like code completion, refactoring
and navigation.

This makes source/blender headers work by themselves, which is
generally the goal anyway. But #includes and forward declarations
were often incomplete.

* Add #includes and forward declarations
* Add IWYU pragma: export in a few places
* Remove some unused #includes (but there are many more)
* Tweak ShaderCreateInfo macros to work better with clangd

Some types of headers still have errors, these could be fixed or
worked around with more investigation. Mostly preprocessor
template headers like NOD_static_types.h.

Note that that disabling WITH_UNITY_BUILD is required for clangd to
work properly, otherwise compile_commands.json does not contain
the information for the relevant source files.

For more details see the developer docs:
https://developer.blender.org/docs/handbook/tooling/clangd/

Pull Request: https://projects.blender.org/blender/blender/pulls/132608
2025-01-07 12:39:13 +01:00
Campbell Barton
a404f521a3 Cleanup: remove typedef struct & function(void) in Python declarations 2025-01-07 11:27:20 +11:00
Campbell Barton
6ae599c588 Fix gpu.shader.from_builtin exception without returning null
Returning an object instead of null meant to exception would
not be raised as intended.

Oversight in !132686
2025-01-07 10:18:59 +11:00
Jeroen Bakker
588087f88e Fix #131943: GPU: Vertex formats for polyline shaders
PR #129315 refactored polylines. The shaders now attaches the vertex
attributes as SSBOs. Adding a workaround for polyline shaders to
extract the correct vertex formats when called via Python.

Pull Request: https://projects.blender.org/blender/blender/pulls/132689
2025-01-06 16:05:50 +01:00
Jeroen Bakker
c2b8186b07 Fix #132590: Python/GPU: Builtin clipped shaders messages
Confusing error messages are printed when requesting a clipped builtin
shader via Python that does not exist.

This PR will remove the confusion of the messaging:
- Replaced BLI_assert_unreachable with an assert as it is reachable
  code.
- Adding clipped configuration for POLYLINE_UNIFORM_COLOR

Pull Request: https://projects.blender.org/blender/blender/pulls/132686
2025-01-06 15:42:07 +01:00
Ray Molenkamp
a0d9826b3c Cleanup: CMake: Modernize bf_imbuf dependencies
Pretty straightforward

- Remove any bf_imbuf paths from INC
- Add a dependency though LIB when missing

context: https://devtalk.blender.org/t/cmake-cleanup/30260

Pull Request: https://projects.blender.org/blender/blender/pulls/132336
2024-12-25 23:32:15 +01:00
Ray Molenkamp
b7407aabb5 Cleanup: CMake: Modernize bf_gpu dependencies
Pretty straightforward

- Remove any bf_gpu paths from INC
- Add a dependency though LIB when missing

context: https://devtalk.blender.org/t/cmake-cleanup/30260

Pull Request: https://projects.blender.org/blender/blender/pulls/132286
2024-12-23 21:38:19 +01:00
Ray Molenkamp
a7c39896c6 Cleanup: CMake: Modernize bf_blenkernel dependencies
Pretty straightforward

- Remove any bf_blenkernel paths from INC
- Add a dependency though LIB when missing

context: https://devtalk.blender.org/t/cmake-cleanup/30260

Pull Request: https://projects.blender.org/blender/blender/pulls/132282
2024-12-23 20:08:37 +01:00
Germano Cavalcante
179f2a3cb1 PyGPU: Show error for unsupported POLYLINE shader configurations
In Blender 4.4 (since commit 00a8d006fe), polyline shaders stopped
using geometry shaders and now rely on SSBOs.

In C++, workarounds allow these shaders to function as before, albeit
with some limitations.

To address these known limitations, error messages are now raised when
a polyline shader is used with unsupported configurations.

Pull Request: https://projects.blender.org/blender/blender/pulls/131055
2024-12-11 20:39:25 +01:00
Germano Cavalcante
19fee82b72 Fix #131236: 'batch_for_shader' not working with POLYLINE shaders
In Blender 4.4 (since commit 00a8d006fe), polyline shaders stopped
using geometry shaders and now rely on SSBOs.

In C++, workarounds allow these shaders to function as before, albeit
with some limitations.

However, this change broke the `batch_for_shader` function in Python,
as `GPUShader.attrs_info_get()` only reads attributes and does not
support SSBOs.

To address this, the method now treats polyline shaders differently,
accessing SSBO inputs instead of attributes.

fix
2024-12-11 20:39:24 +01:00
Germano Cavalcante
93e3da136f PyGPU: Rename 'program' to 'shader' in documentation for 'GPUBatch.draw'
Renaming 'program' to 'shader' makes the documentation clearer.
2024-12-11 20:39:24 +01:00
Germano Cavalcante
9b3fb99bc9 Fix #116551: gpu.types.Buffer always returning 'FLOAT' type on MacOS
The issue involves using const on a variable that is later modified.
2024-11-18 23:24:48 -03:00