Skip to content

Commit

Permalink
gpu: add pl_gpu_limits.max_mapped_vram
Browse files Browse the repository at this point in the history
Since this is very restricted on non-resizable BAR platforms.
haasn committed Mar 5, 2024
1 parent a3d8788 commit 90a88bc
Showing 6 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ project('libplacebo', ['c', 'cpp'],
7,
# API version
{
'347': 'add pl_gpu_limits.max_mapped_vram',
'346': 'add pl_render_params.background/border, deprecate skip_target_clearing and blend_against_tiles',
'345': 'add pl_frame_clear_tiles',
'344': 'add PL_ALPHA_NONE',
6 changes: 5 additions & 1 deletion src/gpu.c
Original file line number Diff line number Diff line change
@@ -590,7 +590,11 @@ pl_buf pl_buf_create(pl_gpu gpu, const struct pl_buf_params *params)
require(!params->uniform || params->size <= gpu->limits.max_ubo_size);
require(!params->storable || params->size <= gpu->limits.max_ssbo_size);
require(!params->drawable || params->size <= gpu->limits.max_vbo_size);
require(!params->host_mapped || params->size <= gpu->limits.max_mapped_size);
if (params->host_mapped) {
require(params->size <= gpu->limits.max_mapped_size);
require(params->memory_type != PL_BUF_MEM_DEVICE ||
params->size <= gpu->limits.max_mapped_vram);
}

if (params->format) {
pl_fmt fmt = params->format;
1 change: 1 addition & 0 deletions src/gpu/utils.c
Original file line number Diff line number Diff line change
@@ -147,6 +147,7 @@ pl_gpu pl_gpu_finalize(struct pl_gpu_t *gpu)
pl_assert(gpu->limits.max_ssbo_size <= gpu->limits.max_buf_size);
pl_assert(gpu->limits.max_vbo_size <= gpu->limits.max_buf_size);
pl_assert(gpu->limits.max_mapped_size <= gpu->limits.max_buf_size);
pl_assert(gpu->limits.max_mapped_vram <= gpu->limits.max_mapped_size);

for (int n = 0; n < gpu->num_formats; n++) {
pl_fmt fmt = gpu->formats[n];
3 changes: 3 additions & 0 deletions src/include/libplacebo/gpu.h
Original file line number Diff line number Diff line change
@@ -105,6 +105,9 @@ struct pl_gpu_limits {
size_t max_mapped_size; // maximum size of a `host_mapped` buffer
uint64_t max_buffer_texels; // maximum number of texels in a texel buffer
bool host_cached; // if true, PL_BUF_MEM_HOST buffers are cached
size_t max_mapped_vram; // maximum (known) size of a `host_mapped`
// PL_BUF_MEM_DEVICE buffer, or 0 if this
// combination is not supported

// Required alignment for PL_HANDLE_HOST_PTR imports. This is provided
// merely as a hint to the user. If the host pointer being imported is
1 change: 1 addition & 0 deletions src/opengl/gpu.c
Original file line number Diff line number Diff line change
@@ -184,6 +184,7 @@ pl_gpu pl_gpu_create_gl(pl_log log, pl_opengl pl_gl, const struct pl_opengl_para
if (gl_test_ext(gpu, "GL_ARB_buffer_storage", 44, 0)) {
const char *vendor = (char *) gl->GetString(GL_VENDOR);
limits->max_mapped_size = limits->max_buf_size;
limits->max_mapped_vram = limits->max_buf_size;
limits->host_cached = strcmp(vendor, "AMD") == 0 ||
strcmp(vendor, "NVIDIA Corporation") == 0;
}
2 changes: 2 additions & 0 deletions src/vulkan/gpu.c
Original file line number Diff line number Diff line change
@@ -517,6 +517,8 @@ pl_gpu pl_gpu_create_vk(struct vk_ctx *vk)
.max_ssbo_size = PL_MIN(limits.maxStorageBufferRange, max_size),
.max_vbo_size = vk_malloc_avail(vk->ma, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT),
.max_mapped_size = vk_malloc_avail(vk->ma, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT),
.max_mapped_vram = vk_malloc_avail(vk->ma, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT),
.max_buffer_texels = PL_MIN(limits.maxTexelBufferElements, max_size),
.align_host_ptr = host_props.minImportedHostPointerAlignment,
.host_cached = vk_malloc_avail(vk->ma, VK_MEMORY_PROPERTY_HOST_CACHED_BIT),

0 comments on commit 90a88bc

Please sign in to comment.