Skip to content

Commit

Permalink
vulkan/gpu_buf: check host-mapped VRAM size limits
Browse files Browse the repository at this point in the history
Instead of promoting *all* texture upload buffers to host-mapped VRAM,
only do it when there is sufficient space available (e.g. BAR devices).

Fixes: mpv-player/mpv#13303
Fixes: mpv-player/mpv#12517
  • Loading branch information
haasn committed Mar 5, 2024
1 parent 90a88bc commit 12285cd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/vulkan/gpu_buf.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,13 @@ pl_buf vk_buf_create(pl_gpu gpu, const struct pl_buf_params *params)
case PL_BUF_MEM_AUTO:
// We generally prefer VRAM since it's faster than RAM, but any number
// of other requirements could potentially exclude it, so just mark it
// as optimal by default.
if (!(mparams.optimal & VK_MEMORY_PROPERTY_HOST_CACHED_BIT))
// as optimal by default. Additionally, don't do this if the available
// VRAM size is very small.
if (!(mparams.optimal & VK_MEMORY_PROPERTY_HOST_CACHED_BIT) &&
params->size * MAPPED_VRAM_THRESHOLD <= gpu->limits.max_mapped_vram)
{
mparams.optimal |= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
}
break;
case PL_BUF_MEM_DEVICE:
// Force device local memory.
Expand Down
7 changes: 7 additions & 0 deletions src/vulkan/malloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@

#include "common.h"

// The threshold for which allocations to serve from host-mapped VRAM, as
// opposed to host memory. Will not allocate more than this fraction of VRAM in
// one go. (For a 256 MB non-resizable BAR, this is equivalent to 4 MB)
//
// Note: Not actually used by malloc.c, but by gpu_buf.c
#define MAPPED_VRAM_THRESHOLD 64

// All memory allocated from a vk_malloc MUST be explicitly released by
// the caller before vk_malloc_destroy is called.
struct vk_malloc *vk_malloc_create(struct vk_ctx *vk);
Expand Down

0 comments on commit 12285cd

Please sign in to comment.