GPU: Texture Type Refactor #130671
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Code Documentation
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
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#130671
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
For the same reason as vertex format outlined in #130632 we want to improve the texture API safety.
Currently all texture types are allows to be created and used freely. Some usage require correct usage flags that are bug prone and not enforced on all backend. Type checks are done by the backend at runtime and are not even given to create errors on misusage. Which makes error detection much more complex.
Proposal
This proposal enforce correct usage through different classes with different capabilities. They should all be derived from the same class for easier management in the GPU module.
Conceptually these classes replace the need for
eGPUTextureUsage
and add data type safety.Texture
Can only be read with a sampler
TextureTarget
Can be attached as framebuffer and be read with a sampler
TextureMemoryless
Can only be attached as framebuffer
TextureWrite
Can be used as image and be read with a sampler
TextureAtomic
Can be used as image with atomics operations and be read with a sampler
Implementation
This can be done in a similar fashion as vertex format in #130632:
And for creation:
The GPU and DRW api can be then adjusted to only accept certain class for certain function. For instance, only
TextureTarget
can be attached to framebuffers.Questions
What about if we want to have a texture attached to a framebuffer but then written using image write?
Proposal, add
TextureTargetWrite
. To avoid templates, have explicit conversion functionsas_texture_target()
andas_texture_write()
. This way all types can all convert implicitly to Read only Texture, exceptTextureMemoryLess
, but we can just delete the constructor to prevent casting.Another solution is to forbid such usage. It is very likely to be suboptimal because of layout transition. The issue is that it is already used by EEVEE for gbuffer using texture views.
What about texture views?
Texture views should inherit the parent type.
GPU:to GPU: Texture Type RefactorI like this in theory, but I can see it exploding into too much complexity in practice.
I wouldn't like to end up using templates for each function taking a Texture.
And we are not even taking texture dimensions or data types into account, so we won't have full compile-time safety anyway.
I think having the (most common) types themselves would be nice, as long as they can be optionally constructible from a base Texture (or GPUTexture) doing appropriate runtime checks.
That way we can improve readability and safety, and use static checking where possible, but we don't trap ourselves into having to make the compiler happy at any cost.
We are not aiming to put the everything in the type info. There is no benefit to put things like texture dimensions or the data type inside the texture type (since none of the binding function are shader interface aware). This task is only to move the usage flags into the type info and forbid invalid data types in constructors.
That can be a nice solution for complex usage. But appart from the weird case of EEVEE that uses
TextureWrite
andTextureTarget
on the same texture, I don't see the need for it. And like I said, this should be discouraged.Note that the goal of the task is to make the general usage safe. Custom usage should be very explicit.
Also note that many combination of the usage flags are invalid (can't have
GPU_TEXTURE_USAGE_MEMORYLESS
and notGPU_TEXTURE_USAGE_ATTACHMENT
, can't haveGPU_TEXTURE_USAGE_ATOMIC
withGPU_TEXTURE_USAGE_ATTACHMENT
). So enforcing it at the type level seems to be also a win.Another option to avoid templates, is to have explicit conversion functions
TextureTargetWrite().as_texture_target()
andTextureTargetWrite().as_texture_write()
for these use case. This way all types can all convert to Read Texture (exceptTextureMemoryLess
, but we can just delete the constructor to prevent casting).So we would have:
GPU_TEXTURE_USAGE_HOST_READ
About
GPU_TEXTURE_USAGE_HOST_READ
I a bit on the fence. To me this sounds like it should be a backend detail that we shouldn't have to care about. Proposal for this is to just be an extra argument (or different constructor) forTextureTarget
andTextureWrite
.GPU_TEXTURE_USAGE_FORMAT_VIEW
Given how niche this is, I would rather have some special format tricks to allow this. Like
declaring the texture with a special
UNORM_24_DEPTH_UINT_8_STENCIL_READ
with a view set toUNORM_24_DEPTH_UINT_8
to read the depth bits. Or simply have a runtime switch like forGPU_TEXTURE_USAGE_HOST_READ
.Again, I am not sure statically protecting format view creation is necessary.
@pragma37 I think I misunderstood your comment. I think your concern is also about texture creation functions and their variants.
In this case we also want to be very explicit as there are also requirements:
TextureAtomic
cannot be 1D or 1DArray (Not implemented in Metal)TextureTarget
cannot be 1D or 1DArrayTextureMemoryless
can only be 2D or 2DArray