Fix #114414: Alternative fix for greyscale textures retaining perf #114611

Merged
Jeroen Bakker merged 1 commits from Jason-Fielder/blender:Fix_114414_Alternative into blender-v4.0-release 2023-11-09 11:02:30 +01:00
Member

Alternative solution to #114414 which reduces the scope of
textures for which single-channel greyscale optimization
is removed from.

Some byte buffers are converted to float buffers during
color management. These cases should retain support in
the optimal path.

Authored by Apple: Michael Parkin-White

Alternative solution to #114414 which reduces the scope of textures for which single-channel greyscale optimization is removed from. Some byte buffers are converted to float buffers during color management. These cases should retain support in the optimal path. Authored by Apple: Michael Parkin-White
Jason Fielder added 1 commit 2023-11-08 01:54:15 +01:00
Alternative solution to #114414 which reduces the scope of
textures for which single-channel greyscale optimization
is removed from.

Some byte buffers are converted to float buffers during
color management. These cases should retain support in
the optimal path.

Authored by Apple: Michael Parkin-White
Jason Fielder requested review from Jeroen Bakker 2023-11-08 01:54:22 +01:00
First-time contributor

For a few technical notes, in the process of implementing a more comprehensive solution which allowed single channel textures to be updated from multi-component source buffers, I noticed that in quite a few of the common cases, the colormanagement still allocates a float buffer for a given ImBuf during data preparation.

In this case, these paths could still take the optimal packed channel path, so long as the source eGPUDataType was overriden to float if the source buffer was converted during imb_gpu_get_data(..).

Loosening the check as follows to byte buffers with given colorspaces enables the optimized single channel GPUTexture to be used in most cases, while also resolving: #114414

Note that I have only been able to test this in the Metal backend. I have also not been able to test every source format, but the Wanderer appears to work, and the logic should limit this to the cases where the float buffer is later allocated and used.

For a few technical notes, in the process of implementing a more comprehensive solution which allowed single channel textures to be updated from multi-component source buffers, I noticed that in quite a few of the common cases, the colormanagement still allocates a float buffer for a given ImBuf during data preparation. In this case, these paths could still take the optimal packed channel path, so long as the source eGPUDataType was overriden to float if the source buffer was converted during `imb_gpu_get_data(..)`. Loosening the check as follows to byte buffers with given colorspaces enables the optimized single channel GPUTexture to be used in most cases, while also resolving: https://projects.blender.org/blender/blender/issues/114414 Note that I have only been able to test this in the Metal backend. I have also not been able to test every source format, but the Wanderer appears to work, and the logic should limit this to the cases where the float buffer is later allocated and used.
Jeroen Bakker requested changes 2023-11-09 09:15:09 +01:00
Jeroen Bakker left a comment
Member

I agree with the solution, just need to cleanup a parameter as it is always overwritten.

I agree with the solution, just need to cleanup a parameter as it is always overwritten.
@ -121,2 +131,3 @@
const bool store_premultiplied,
bool *r_freedata)
bool *r_freedata,
eGPUDataFormat *out_data_format)
Member

This makes two ways to determine the data_format.
one by imb_gpu_get_format which could be overwritten by imb_gpu_get_data.

Or the correct data_format should be returned by imb_gpu_get_format, or the r_data_format parameter should be removed from that function.

I would prefer the removal of the r_data_format

This makes two ways to determine the data_format. one by `imb_gpu_get_format` which could be overwritten by `imb_gpu_get_data`. Or the correct data_format should be returned by imb_gpu_get_format, or the r_data_format parameter should be removed from that function. I would prefer the removal of the `r_data_format`
First-time contributor

Yeah, this is a little non-ideal as it stands.
However, part of what makes this solution work to retain the 4ch->1ch compression is that in imb_gpu_get_data, even if the source data is a byte_buffer, some of the colour conversions appear to generate floating point data, in which case, one of the original reasons for the bug was that the wrong data type was being generated.

It may still be valid to have the data type return in the original imb_gpu_get_format, as I believe this is used in certain cases without the data upload. Although the override in imb_gpu_get_data allows for the case where the data is flipped to being floating point, to ensure the correct flag is passed to GPU_texture_update(..).

Although it will likely make sense to refactor both paths to use the same thing, or defer data format determination to a point where the source data type is known.

But yes, it'll likely make the most sense to remove r_data_format from imb_gpu_get_format, and leave that to only being the source GPU tex format, to allow for the destination texture format and source data format to allow different types.

Yeah, this is a little non-ideal as it stands. However, part of what makes this solution work to retain the 4ch->1ch compression is that in `imb_gpu_get_data`, even if the source data is a byte_buffer, some of the colour conversions appear to generate floating point data, in which case, one of the original reasons for the bug was that the wrong data type was being generated. It may still be valid to have the data type return in the original `imb_gpu_get_format`, as I believe this is used in certain cases without the data upload. Although the override in `imb_gpu_get_data` allows for the case where the data is flipped to being floating point, to ensure the correct flag is passed to `GPU_texture_update(..)`. Although it will likely make sense to refactor both paths to use the same thing, or defer data format determination to a point where the source data type is known. But yes, it'll likely make the most sense to remove r_data_format from `imb_gpu_get_format`, and leave that to only being the source GPU tex format, to allow for the destination texture format and source data format to allow different types.
Jeroen Bakker approved these changes 2023-11-09 11:02:02 +01:00
Jeroen Bakker left a comment
Member

I approve for now so users can test and report back.
Will perform the removal of the unused parameter on main

I approve for now so users can test and report back. Will perform the removal of the unused parameter on main
Jeroen Bakker merged commit ed540b4d3a into blender-v4.0-release 2023-11-09 11:02:30 +01:00
First-time contributor

Thanks for the feedback, will look into addressing this.

Thanks for the feedback, will look into addressing this.
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
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
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
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
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
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
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
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 project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#114611
No description provided.