Vulkan: Texture Data Conversions #105762

Merged
Jeroen Bakker merged 23 commits from Jeroen-Bakker/blender:vulkan-textures into main 2023-03-24 08:09:33 +01:00
Member

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.

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 more memory than the other options.

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
and requires a workaround. This will be 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
your platform. For example on
OpenGL/NVidia I get the next failure, because the texture type isn't
supported. But it is in 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 
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. 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 more memory than the other options. **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 and requires a workaround. This will be 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 your platform. For example on OpenGL/NVidia I get the next failure, because the texture type isn't supported. But it is in 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 ```
Jeroen Bakker added this to the 3.6 LTS milestone 2023-03-14 13:59:35 +01:00
Jeroen Bakker added the
Interest
Vulkan
label 2023-03-14 13:59:35 +01:00
Jeroen Bakker self-assigned this 2023-03-14 13:59:35 +01:00
Jeroen Bakker added 3 commits 2023-03-14 13:59:39 +01:00
Jeroen Bakker added 1 commit 2023-03-14 15:55:57 +01:00
Jeroen Bakker added 1 commit 2023-03-14 15:57:49 +01:00
Jeroen Bakker added 3 commits 2023-03-16 15:59:54 +01:00
Jeroen Bakker added 1 commit 2023-03-16 18:08:31 +01:00
Jeroen Bakker added 3 commits 2023-03-17 10:27:10 +01:00
Jeroen Bakker added 2 commits 2023-03-17 12:36:45 +01:00
Jeroen Bakker added 1 commit 2023-03-17 12:40:34 +01:00
Jeroen Bakker requested review from Clément Foucault 2023-03-17 13:01:12 +01:00
Jeroen Bakker requested review from Bastien Montagne 2023-03-17 13:01:18 +01:00
Jeroen Bakker added this to the EEVEE & Viewport project 2023-03-17 13:01:24 +01:00
Jeroen Bakker changed title from WIP: Vulkan: Texture support. to Vulkan: Texture support. 2023-03-17 13:01:31 +01:00
Jeroen Bakker reviewed 2023-03-17 13:03:33 +01:00
@ -0,0 +51,4 @@
UNSUPPORTED,
};
static ConversionType type_of_conversion_float(eGPUTextureFormat device_format)
Author
Member

Perhaps we can still use texture data format to find out which conversion should be used to remove these large switch statements.

Perhaps we can still use texture data format to find out which conversion should be used to remove these large switch statements.
Jeroen Bakker added 1 commit 2023-03-17 13:30:46 +01:00
Jeroen Bakker reviewed 2023-03-17 13:36:56 +01:00
@ -214,3 +214,3 @@
{
int mip = 0;
int extent[3], offset[3] = {0, 0, 0};
int extent[3] = {1, 1, 1};
Author
Member

This was added as it is easier to have a good default, than afterwards finding out what should be set and what not. Without this change I have to set the 1 based on the actual texture type. what adds a minimum overhead.

I think this is a better solution as it can reduce code complexity in other backends as well.

This was added as it is easier to have a good default, than afterwards finding out what should be set and what not. Without this change I have to set the 1 based on the actual texture type. what adds a minimum overhead. I think this is a better solution as it can reduce code complexity in other backends as well.
fclem marked this conversation as resolved
Jeroen Bakker changed title from Vulkan: Texture support. to Vulkan: Texture Data Conversions. 2023-03-17 14:00:45 +01:00
Jeroen Bakker added 1 commit 2023-03-20 08:09:13 +01:00
Jeroen Bakker added 2 commits 2023-03-20 08:34:01 +01:00
Jeroen Bakker added 1 commit 2023-03-20 08:58:46 +01:00
Clément Foucault approved these changes 2023-03-20 10:02:46 +01:00
Hans Goudey changed title from Vulkan: Texture Data Conversions. to Vulkan: Texture Data Conversions 2023-03-20 16:26:18 +01:00
Jeroen Bakker added 1 commit 2023-03-21 08:56:17 +01:00
Jeroen Bakker added 1 commit 2023-03-23 08:16:54 +01:00
Jeroen Bakker added a new dependency 2023-03-23 08:25:31 +01:00
Jeroen Bakker added a new dependency 2023-03-23 14:45:39 +01:00
Jeroen Bakker added 1 commit 2023-03-24 07:50:58 +01:00
Jeroen Bakker merged commit 08a6361b3f into main 2023-03-24 08:09:33 +01:00
Jeroen Bakker deleted branch vulkan-textures 2023-03-24 08:09:33 +01:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Reference: blender/blender#105762
No description provided.