Commit Graph

28 Commits

Author SHA1 Message Date
Clément Foucault
8b70166214 GPU: Tests: Avoid test not passing on certain platform
These tests were using exact comparison on data that
was going through lossy conversion steps. Adding
casting or epsilon value fixes the issue.
2025-04-29 15:27:58 +02:00
Brecht Van Lommel
fb2ba20b67 Refactor: Use more typed MEM_calloc<> and MEM_malloc<>
Pull Request: https://projects.blender.org/blender/blender/pulls/137822
2025-04-22 11:22:18 +02:00
Brecht Van Lommel
637c6497e9 Refactor: Use more typed MEM_calloc<>, avoid unnecessary size_t cast
Handle some cases that were missed in previous refactor. And eliminate
unnecessary size_t casts as these could hide issues.

Pull Request: https://projects.blender.org/blender/blender/pulls/137404
2025-04-21 17:59:41 +02:00
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
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
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
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
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
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
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
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
Jeroen Bakker
71821d1251 Fix compilation error draw test
Pull Request: https://projects.blender.org/blender/blender/pulls/111964
2023-09-05 11:02:33 +02:00
Jeroen Bakker
ad0e4f08c0 GPU: Add tests for 1d, 2d array texture types
This PR adds several unit tests to construct and upload data for
different texture types (1d_array, 2d_array).

Pull Request: https://projects.blender.org/blender/blender/pulls/111338
2023-09-05 10:51:49 +02:00
Campbell Barton
e955c94ed3 License Headers: Set copyright to "Blender Authors", add AUTHORS
Listing the "Blender Foundation" as copyright holder implied the Blender
Foundation holds copyright to files which may include work from many
developers.

While keeping copyright on headers makes sense for isolated libraries,
Blender's own code may be refactored or moved between files in a way
that makes the per file copyright holders less meaningful.

Copyright references to the "Blender Foundation" have been replaced with
"Blender Authors", with the exception of `./extern/` since these this
contains libraries which are more isolated, any changed to license
headers there can be handled on a case-by-case basis.

Some directories in `./intern/` have also been excluded:

- `./intern/cycles/` it's own `AUTHORS` file is planned.
- `./intern/opensubdiv/`.

An "AUTHORS" file has been added, using the chromium projects authors
file as a template.

Design task: #110784

Ref !110783.
2023-08-16 00:20:26 +10:00
Jeroen Bakker
d84a64900f Vulkan: Device Context Resource Management
The current Vulkan resource management has some issues as context that
are not active can still use resources that are freed via another
context.

When this happens incorrect data can be read on the GPU and even crash
Blender. When trying to bind something that now contains other memory
pointers.

This change introduces that contexts are tracked via the device.
Context will be registered/unregistered with the device instance.
Unbinding of resources must pass the device and the device will check
all registered contexts. Binding of resources will happen via the active
context only.

On user perspective this now allowes:
- Opening/switching files
- Switching workspaces
- Switching render engines

Pull Request: https://projects.blender.org/blender/blender/pulls/108968
2023-06-15 08:14:37 +02:00
Jeroen Bakker
2ee2ae93fb Vulkan: Initial Cube(Array) Support
This PR adds initial cube (array) support. Depending on how the texture
is used a different image view is created. When used as a framebuffer
attachment only a single side of the cubemap is attached. The image
view is attached as a 2d texture array. When used as a shader resource
the image view is a cubemap.

Also adds test cases to test both scenarios.

Pull Request: https://projects.blender.org/blender/blender/pulls/108794
2023-06-09 16:09:54 +02:00
Jeroen Bakker
8f988206de Vulkan: UBYTE to SRGBA8 Texture Format
Adds support to create SRGBA8 textures using UBYTE as input data.
It is assumed that the UBYTE are already converted to SRGB and no
conversion actually needs to happen.

Pull Request: https://projects.blender.org/blender/blender/pulls/108741
2023-06-08 09:44:51 +02:00
Jeroen Bakker
2231b819a5 Vulkan: Workaround for 24bit depth component
Some vulkan platforms don't support 24bit depth components. In this
case we will allocate float depth component. During readback the data
should be converted back to what is expected.

Pull Request: https://projects.blender.org/blender/blender/pulls/108698
2023-06-08 08:53:12 +02:00
Jeroen Bakker
b7963d247c Vulkan: Low Precision Float Conversion
This PR adds conversion template to convert between Low Precision float
formats. These include Binary32 floats and lower. It also adds support
to convert between unsigned and signed float formats and float formats
with different mantissa and exponents.

Additionally overflows (values that don't fit in the target float
format) will be clamped to the maximum value.

**Reasoning**:
Up to now the Vulkan backend only supported float and half float
formats, but to support workbench, 11 and 10 unsigned floats have to be
supported as well. The available libraries that support those float
formats targets scientific applications. Where the final code couldn't
be optimized that well by the compiler.

Data conversion for color pixels have different requirements about
clamping and sign, what could eliminate some clamping code in other
areas in Blender as well. Also could fix some undesired overflow when
using pixels with high intensity that didn't fit in the texture format
leading to known artifects in Eevee and slow-down in the image editor.

**Future**
In the future we might want to move this to the public part of the GPU
module so we can use this as well in other areas (Metal backend), Imbuf clamping
See 3c658d2c2e69e9cf97dfaa7a3c164262aefb9e76 for a commit that uses
this and improves image editor massively as it doesn't need to reiterate over
the image buffer to clamp the values into a known range.

Pull Request: https://projects.blender.org/blender/blender/pulls/108168
2023-06-07 07:50:04 +02: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
3f89ec2866 Vulkan: Copy Between Textures
This PR adds support for copying between two textures.

Pull Request: https://projects.blender.org/blender/blender/pulls/108413
2023-05-30 13:50:35 +02:00
Jeroen Bakker
17201752d9 Vulkan: Add FLOAT to SRGB and Depth24 Conversion
This PR adds support to convert host/device data from floats
to GPU_SRGB8_A8 and GPU_DEPTH_COMPONENT24.

Pull Request: https://projects.blender.org/blender/blender/pulls/107544
2023-05-02 15:57:17 +02:00
Campbell Barton
bb2dc141f2 Cleanup: spelling in comments 2023-03-27 12:08:14 +11:00
Jeroen Bakker
08a6361b3f Vulkan: Texture Data Conversions
This PR adds basic support for texture update, read back and clearing
for Vulkan. In Vulkan we need to convert each data type ourselves as
vulkan buffers are untyped. Therefore this change mostly is about data
conversions.

Considerations:
- Use a compute shader to do the conversions:
  - Leads to performance regression as compute pipeline can stall
    graphics pipeline
  - Lead to additional memory usage as two staging buffers are needed
    one to hold the CPU data, and one to hold the converted data.
- Do inline conversion when sending the data to Vulkan using `eGPUDataFormat`
  - Additional CPU cycles required and not easy to optimize as it the
    implementation requires many branches.
- Do inline conversion when sending the data to Vulkan (optimized for CPU)

For this solution it was chosen to implement the 3rd option as it is fast
and doesn't require additional memory what the other options do.

**Use Imath/half.h**
This patch uses `Imath/half.h` (dependency of OpenEXR) similar to
alembic. But this makes vulkan dependent of the availability of
OpenEXR. For now this isn't checked, but when we are closer to
a working Vulkan backend we have to make a decision how to cope with
this dependency.

**Missing Features**

*Framebuffer textures*
This doesn't include all possible data transformations. Some of those
transformation can only be tested after the VKFramebuffer has been
implemented. Some texture types are only available when created for a
framebuffer. These include the depth and stencil variations.

*Component format*
Is more relevant when implementing VKVertexBuffer.

*SRGB textures*
SRGB encoded textures aren't natively supported on all platforms, in
all usages and might require workarounds. This should be done in a
separate PR in a later stage when we are required to use SRGB textures.

**Test cases**
The added test cases gives an overview of the missing bits and pieces of
the patch. When the implementation/direction is accepted more test cases
can be enabled/implemented.

Some of these test cases will skip depending on the actual support of
platform the tests are running on. For example OpenGL/NVidia will skip
the next test as it doesn't support the texture format on OpenGL, although
it does support it on Vulkan.

```
[ RUN      ] GPUOpenGLTest.texture_roundtrip__GPU_DATA_2_10_10_10_REV__GPU_RGB10_A2UI
[  SKIPPED ] GPUOpenGLTest.texture_roundtrip__GPU_DATA_2_10_10_10_REV__GPU_RGB10_A2UI [ RUN      ] GPUVulkanTest.texture_roundtrip__GPU_DATA_2_10_10_10_REV__GPU_RGB10_A2UI
[       OK ] GPUVulkanTest.texture_roundtrip__GPU_DATA_2_10_10_10_REV__GPU_RGB10_A2UI
```

Pull Request: https://projects.blender.org/blender/blender/pulls/105762
2023-03-24 08:09:19 +01:00
Campbell Barton
80dfb885d7 License headers: add missing license identifiers 2023-03-23 15:12:09 +11:00
Jeroen Bakker
4238080568 Cleanup: Remove gpu prefix in gpu test cases.
The _gpu_ prefix is redundant as they are inside a namespace
and run as part of a test suite that already contain the name
gpu. (GPUOpenGLTest)

This patch also moved the texture test cases to its own
compile module.
2023-03-13 11:14:17 +01:00