Vulkan: track discarded resource in swap chain #124863
Labels
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
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#124863
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?
Resources
Lifetime
GPU Resource allocation are triggered from the CPU. Commands can be scheduled to the GPU that uses these resources. The actual moment these commands are executed or finished cannot be detected. GPU resources can only be destroyed after the commands using these resources have finished.
States of a command
What happens on the GPU is asynchronously done from the CPU. When the GPU is executing the previous frame the CPU can already scheduling the next frame. When the execution of the frame is done the result can be presented on the display.
This gives quite a challenge when destroying resources. A typically solution is to keep track of the resources in a discard pile. There would be a discard pile per swap chain image. When a swap chain image is reused again we know for sure that the previous added resources to the discard pile can be destroyed.
Resource pool
Resource pools keep track of the resources for a swap chain image.
In Blender this is a bit more complicated due to the way GPUContext work. A single thread can have multiple contexts. Some of them have a swap chain (GHOST Window) other don't (draw manager). The resource pool should be shared between the contexts running on the same thread.
When opening multiple windows there are also multiple swap chains.
Discard pile
Resource handles that are deleted and stored in the discard pile. When we are sure that these resources are not used on the gpu anymore these are destroyed.
Staging buffers
Staging buffers are used to update GPU resources when they need to be updated. For example when a buffer is used in frame 1 and 2, but have different content. The new content is stored in a staging buffer. The new content will be copied just before the buffer is first used in frame 2.
Keeping a pool of staging buffers per swap chain image allow reusing previous allocated resources.
Reusable resources
There are other resources as well like:
Resource deletion
From Blender perspective there are several deletion patterns.
Active Context
Most common is that there is an active context. In this case we add the resource to the active discard pile.
Dependency graph update
Dependency graph updates occur in Blenders main loop or when rendering. When the dependency graph is updated cached gpu data can be deleted. The data include material shaders and textures and geometry buffers.
The deletion happens from any thread and there is no active context. There is also no information if the deletion happens for rendering (triggered from background thread) or main loop (triggered from main thread).
During rendering the deps graph update happens after the rendering is finished and is safe to destroy immediately. But as we don't know if a resource is destroyed from the main loop or render we assume we cannot destroy it immediately. The deleted resources will be added to the device level discard pile.
Next time a swap chain context advanced to the next swap chain image the device level discard pile is added to the swap chain image discard pile. When Blender runs in the background it is added to the context first discard pile.
Solution
Thread discarded resources are destroyed when the context becomes active with a new swap chain index.
Device discarded resources are moved to the thread discarded resources when:
Resources that are discarded outside a context are placed inside the
orphaned_data
. When a context switches its swap chain the content oforphaned_data
is moved to the new swap chain image discard pool.Jeroen Bakker referenced this issue2024-08-15 08:24:10 +02:00