Vulkan - Constantly increasing shared memory/RAM usage as frames are rendered - Recent NVIDIA drivers #127225

Open
opened 2024-09-06 10:22:08 +02:00 by Alaska · 13 comments
Member

System Information
Operating system: Windows-10-10.0.22631-SP0 64 Bits
Graphics card: NVIDIA GeForce RTX 4090 NVIDIA Corporation 560.94.0.0

Blender Version
Broken: version: 4.3.0 Alpha, branch: main, commit date: 2024-09-06 06:32, hash: 792c29e52f3d
Worked: Never as Vulkan was only recently enabled.

Short description of error
As frames are rendered in EEVEE, GPU shared memory/RAM increases until Blender crashes. See attached video for demonstration.

Exact steps for others to reproduce the error

  1. Open Blender.
  2. Open preferences Edit -> Preferences from the top of Blender.
  3. In the System tab change the backend to Vulkan.
  4. Save preferences then close Blender.
  5. Open Blender.
  6. Enter EEVEE rendered viewport mode.
  7. Continually move the camera around and notice increasing shared memory/RAM usage in a external tool like task manager until Blender crashes.
**System Information** Operating system: Windows-10-10.0.22631-SP0 64 Bits Graphics card: NVIDIA GeForce RTX 4090 NVIDIA Corporation 560.94.0.0 **Blender Version** Broken: version: 4.3.0 Alpha, branch: main, commit date: 2024-09-06 06:32, hash: `792c29e52f3d` Worked: Never as Vulkan was only recently enabled. **Short description of error** As frames are rendered in EEVEE, GPU shared memory/RAM increases until Blender crashes. See attached video for demonstration. **Exact steps for others to reproduce the error** 1. Open Blender. 2. Open preferences `Edit -> Preferences` from the top of Blender. 3. In the `System` tab change the backend to Vulkan. 4. Save preferences then close Blender. 5. Open Blender. 6. Enter EEVEE rendered viewport mode. 7. Continually move the camera around and notice increasing shared memory/RAM usage in a external tool like task manager until Blender crashes.
Alaska added the
Type
Bug
Status
Needs Triage
Severity
Normal
labels 2024-09-06 10:22:09 +02:00

Hmm, I am not able to reproduce this one (or 127267 which is similar). The only difference here is that I'm using driver version 551.61.0.0

Hmm, I am not able to reproduce this one (or 127267 which is similar). The only difference here is that I'm using driver version 551.61.0.0
Author
Member

I can confirm the downgrading to NVIDIA GPU driver 551.61.0.0 resolves the issue

I can confirm the downgrading to NVIDIA GPU driver 551.61.0.0 resolves the issue
Alaska changed title from Vulkan - EEVEE sees increasing shared memory/RAM usage as frames are rendered. to Vulkan - EEVEE sees increasing shared memory/RAM usage as frames are rendered - Recent NVIDIA drivers 2024-09-07 05:41:35 +02:00
Member

So updated to latest game ready driver 560.94 but unable to confirm the memory usage or a leak.
@Alaska hi, is it resolved already in today's main?

**System Information**
Operating system: Windows-10-10.0.22631-SP0 64 Bits
Graphics card: NVIDIA GeForce RTX 3050 Laptop GPU NVIDIA Corporation 560.94.0.0
So updated to latest game ready driver 560.94 but unable to confirm the memory usage or a leak. @Alaska hi, is it resolved already in today's main? ``` **System Information** Operating system: Windows-10-10.0.22631-SP0 64 Bits Graphics card: NVIDIA GeForce RTX 3050 Laptop GPU NVIDIA Corporation 560.94.0.0 ```
Author
Member

I can still reproduce the issue in latest main, both in a local build and the latest from the build bot

System Information
Operating system: Windows-10-10.0.22631-SP0 64 Bits
Graphics card: NVIDIA GeForce RTX 4090 NVIDIA Corporation 560.94.0.0
Local version: 4.3.0 Alpha, branch: main, commit date: 2024-09-10 12:55, hash: 3fdc9e9637b5
Build bot version: 4.3.0 Alpha, branch: main, commit date: 2024-09-09 22:55, hash: 72a0be0944f9

I can still reproduce the issue in latest main, both in a local build and the latest from the build bot **System Information** Operating system: Windows-10-10.0.22631-SP0 64 Bits Graphics card: NVIDIA GeForce RTX 4090 NVIDIA Corporation 560.94.0.0 Local version: 4.3.0 Alpha, branch: main, commit date: 2024-09-10 12:55, hash: `3fdc9e9637b5` Build bot version: 4.3.0 Alpha, branch: main, commit date: 2024-09-09 22:55, hash: `72a0be0944f9`
Contributor
  1. Enter EEVEE rendered viewport mode.

JFYI, I can reproduce the same issue in Wireframe / Solid viewport modes as well.

main @ 615cb464128
Windows-10-10.0.19045-SP0
NVIDIA GeForce RTX 3060 Ti 556.12.0.0
> 6. Enter EEVEE rendered viewport mode. JFYI, I can reproduce the same issue in Wireframe / Solid viewport modes as well. ``` main @ 615cb464128 Windows-10-10.0.19045-SP0 NVIDIA GeForce RTX 3060 Ti 556.12.0.0 ```
Member

With Vulkan backend?

With Vulkan backend?
Contributor

With Vulkan backend?

Yes

> With Vulkan backend? Yes
Alaska added
Module
Viewport & EEVEE
Status
Confirmed
Interest
Vulkan
and removed
Status
Needs Triage
labels 2024-09-20 15:18:47 +02:00
Alaska changed title from Vulkan - EEVEE sees increasing shared memory/RAM usage as frames are rendered - Recent NVIDIA drivers to Vulkan - Constantly increasing shared memory/RAM usage as frames are rendered - Recent NVIDIA drivers 2024-09-30 01:40:14 +02:00
Author
Member

CC @Jeroen-Bakker so you know about this issue.

CC @Jeroen-Bakker so you know about this issue.
Contributor

The issue is that discarded resources (VKResourcePool::discard_pool) are not being destroyed:
(I'm printing the total elements in the discarded pool)

This reduces a little, but not the right fix:


diff --git a/source/blender/gpu/vulkan/vk_context.cc b/source/blender/gpu/vulkan/vk_context.cc
index a45ff5a1f94..e549f4f5efa 100644
--- a/source/blender/gpu/vulkan/vk_context.cc
+++ b/source/blender/gpu/vulkan/vk_context.cc
@@ -134,7 +134,14 @@ void VKContext::begin_frame() {}

 void VKContext::end_frame() {}

-void VKContext::flush() {}
+void VKContext::flush()
+{
+  VKDevice &device = VKBackend::get().device;
+  VKThreadData &thread_data = thread_data_.value().get();
+  VKResourcePool &resource_pool = thread_data.resource_pool_get();
+  resource_pool.discard_pool.destroy_discarded_resources(device);
+  resource_pool.reset();
+}

 void VKContext::flush_render_graph()
 {
@@ -146,6 +153,11 @@ void VKContext::flush_render_graph()
   }
   descriptor_set_get().upload_descriptor_sets();
   render_graph.submit();
+  VKDevice &device = VKBackend::get().device;
+  VKThreadData &thread_data = thread_data_.value().get();
+  VKResourcePool &resource_pool = thread_data.resource_pool_get();
+  resource_pool.discard_pool.destroy_discarded_resources(device);
+  resource_pool.reset();
 }

However still some resources are not being released with the fix diff, leaving a animation playing slowly increases memory usage

The issue is that discarded resources (`VKResourcePool::discard_pool`) are not being destroyed: (I'm printing the total elements in the discarded pool) <video src="/attachments/5815d038-788e-4b63-88aa-68edeb7b86aa" title="2024-11-01 15-55-13.mp4" controls></video> This reduces a little, but not the right fix: ```diff diff --git a/source/blender/gpu/vulkan/vk_context.cc b/source/blender/gpu/vulkan/vk_context.cc index a45ff5a1f94..e549f4f5efa 100644 --- a/source/blender/gpu/vulkan/vk_context.cc +++ b/source/blender/gpu/vulkan/vk_context.cc @@ -134,7 +134,14 @@ void VKContext::begin_frame() {} void VKContext::end_frame() {} -void VKContext::flush() {} +void VKContext::flush() +{ + VKDevice &device = VKBackend::get().device; + VKThreadData &thread_data = thread_data_.value().get(); + VKResourcePool &resource_pool = thread_data.resource_pool_get(); + resource_pool.discard_pool.destroy_discarded_resources(device); + resource_pool.reset(); +} void VKContext::flush_render_graph() { @@ -146,6 +153,11 @@ void VKContext::flush_render_graph() } descriptor_set_get().upload_descriptor_sets(); render_graph.submit(); + VKDevice &device = VKBackend::get().device; + VKThreadData &thread_data = thread_data_.value().get(); + VKResourcePool &resource_pool = thread_data.resource_pool_get(); + resource_pool.discard_pool.destroy_discarded_resources(device); + resource_pool.reset(); } ``` However still some resources are not being released with the fix diff, leaving a animation playing slowly increases memory usage
Member

The idea of the discard pool is similar to what we have for OpenGL. Background rendering cannot free resources as they may still be in use by other threads. When Blender is started with UI these resources should be picked up and put in the swap chain resource list. After a swap chain image is used again we know for sure these resources can be removed.

device.debug_print() in swap_buffers_pre_handler can help to track this design. I will review the code to find missing parts.

The idea of the discard pool is similar to what we have for OpenGL. Background rendering cannot free resources as they may still be in use by other threads. When Blender is started with UI these resources should be picked up and put in the swap chain resource list. After a swap chain image is used again we know for sure these resources can be removed. `device.debug_print()` in `swap_buffers_pre_handler` can help to track this design. I will review the code to find missing parts.
Contributor

I see whats happening:
Nividia drivers tries to use Vulkan/OpenGL present method = Prefer layered on DXGI Swapchain and seems to fails to cycle between swap-chain images, vkAcquireNextImageKHR always set returns ImageIndex=0 (at high fps seem that sometimes it does cycles correctly), so swap_buffers_pre_handler would never free resources with this check assign_if_different(thread_data.resource_pool_index, swap_chain_data.swap_chain_index) since always will be 0. (Maybe is vkQueuePresentKHR what is failing, they some open reports about)

With Vulkan/OpenGL present method = Prefer Native swap-chain images cycle correctly and memory usage still increases but not as fast (50MB/s vs 400-500 MB/s with Prefer layered on DXGI Swapchain).

@Alaska Could you try this setting?
image

I see whats happening: Nividia drivers tries to use `Vulkan/OpenGL present method = Prefer layered on DXGI Swapchain` and seems to fails to cycle between swap-chain images, `vkAcquireNextImageKHR` always set returns `ImageIndex=0` (at high fps seem that sometimes it does cycles correctly), so `swap_buffers_pre_handler` would never free resources with this check `assign_if_different(thread_data.resource_pool_index, swap_chain_data.swap_chain_index)` since always will be 0. (Maybe is `vkQueuePresentKHR` what is failing, they some open reports about) With `Vulkan/OpenGL present method = Prefer Native` swap-chain images cycle correctly and memory usage still increases but not as fast (50MB/s vs 400-500 MB/s with ` Prefer layered on DXGI Swapchain`). @Alaska Could you try this setting? ![image](/attachments/2b150210-027a-4a0d-86a8-b8830af561a0)
Author
Member

@guishe Swapping to Prefer Native does seem to slow down the memory leak

@guishe Swapping to `Prefer Native` does seem to slow down the memory leak
Member

According to some Vulkan experts we have made an incorrect assumption on the swap chain index.
image

So there are multiple things in play here:

  • We assume swap chain index is always different. But Blender is CPU limited and drivers could return the same index over and over again.
    • Enabling swapchain async submission might change the behavior, but even then we need to keep track if we want to change release swapchain memory.
  • Command buffers are not freed. Resetting the pool might not free the memory. There is a PR for this, which needs to be reviewed.
According to some Vulkan experts we have made an incorrect assumption on the swap chain index. <img width="641" alt="image" src="attachments/8df8cbb5-47b3-4617-a165-a60be2f8e5ed"> So there are multiple things in play here: - We assume swap chain index is always different. But Blender is CPU limited and drivers could return the same index over and over again. - Enabling swapchain async submission might change the behavior, but even then we need to keep track if we want to change release swapchain memory. - Command buffers are not freed. Resetting the pool might not free the memory. There is a PR for this, which needs to be reviewed.
387 KiB
Sign in to join this conversation.
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
6 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#127225
No description provided.