2019-12-10 11:00:49 +00:00
|
|
|
/*
|
2022-02-17 11:38:42 +00:00
|
|
|
* Copyright © 2019 Raspberry Pi Ltd
|
2019-12-10 11:00:49 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
* Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
|
|
* IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef V3DV_BO_H
|
|
|
|
#define V3DV_BO_H
|
|
|
|
|
|
|
|
struct v3dv_device;
|
|
|
|
|
|
|
|
struct v3dv_bo {
|
2020-05-22 08:03:32 +01:00
|
|
|
struct list_head list_link;
|
|
|
|
|
2019-12-10 11:00:49 +00:00
|
|
|
uint32_t handle;
|
2021-04-14 08:08:36 +01:00
|
|
|
uint64_t handle_bit;
|
2019-12-10 11:00:49 +00:00
|
|
|
uint32_t size;
|
|
|
|
uint32_t offset;
|
|
|
|
|
|
|
|
uint32_t map_size;
|
|
|
|
void *map;
|
2020-01-30 11:24:55 +00:00
|
|
|
|
|
|
|
const char *name;
|
v3dv/bo: adding a BO cache
Heavily based on the already existing for the v3d OpenGL driver, but
without references, and with some extra OOM checks (Vulkan CTS has
several OOM tests).
With this commit v3dv_bo_alloc and v3dv_bo_free became frontends to
the bo_cache. The former tries to get a BO from the cache if possible,
and the latter stores the BO on the cache if possible. The former also
adds a new parameter to point if the BO to allocate is private.
As v3d we are only caching private BOs, those created by the driver
for internal use (like CLs, tile_alloc, etc). They are the ones with
the highest change of being reused (for example, CL BOs are always
4KB, so they can always be reused). User-created BOs can have any
size, including some very large ones for buffers and images, which
makes them far less likely to be reused and would add a lot of memory
pressure if we decided to cache them.
In any case, in practice, we found that we could get a performance
improvement by caching also user-created BOs, but that would need more
care and an analysis to decide which ones makes sense. Would also
require to change how the cached BOs are stored by size. Right now
there are an array of list_head, that doesn't work well with big
BOs. If done, that would be handled on a separate commit.
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-06-05 11:21:54 +01:00
|
|
|
|
|
|
|
/** Entry in the linked list of buffers freed, by age. */
|
|
|
|
struct list_head time_list;
|
|
|
|
/** Entry in the per-page-count linked list of buffers freed (by age). */
|
|
|
|
struct list_head size_list;
|
|
|
|
/** Approximate second when the bo was freed. */
|
|
|
|
time_t free_time;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether only our process has a reference to the BO (meaning that
|
|
|
|
* it's safe to reuse it in the BO cache).
|
|
|
|
*/
|
|
|
|
bool private;
|
2020-09-11 11:20:20 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* If this BO was allocated for a swapchain on the display device, the
|
|
|
|
* handle of the dumb BO on that device.
|
|
|
|
*/
|
|
|
|
int32_t dumb_handle;
|
2022-01-04 11:56:42 +00:00
|
|
|
|
|
|
|
int32_t refcnt;
|
2019-12-10 11:00:49 +00:00
|
|
|
};
|
|
|
|
|
2020-11-04 09:39:12 +00:00
|
|
|
void v3dv_bo_init(struct v3dv_bo *bo, uint32_t handle, uint32_t size, uint32_t offset, const char *name, bool private);
|
|
|
|
|
v3dv/bo: adding a BO cache
Heavily based on the already existing for the v3d OpenGL driver, but
without references, and with some extra OOM checks (Vulkan CTS has
several OOM tests).
With this commit v3dv_bo_alloc and v3dv_bo_free became frontends to
the bo_cache. The former tries to get a BO from the cache if possible,
and the latter stores the BO on the cache if possible. The former also
adds a new parameter to point if the BO to allocate is private.
As v3d we are only caching private BOs, those created by the driver
for internal use (like CLs, tile_alloc, etc). They are the ones with
the highest change of being reused (for example, CL BOs are always
4KB, so they can always be reused). User-created BOs can have any
size, including some very large ones for buffers and images, which
makes them far less likely to be reused and would add a lot of memory
pressure if we decided to cache them.
In any case, in practice, we found that we could get a performance
improvement by caching also user-created BOs, but that would need more
care and an analysis to decide which ones makes sense. Would also
require to change how the cached BOs are stored by size. Right now
there are an array of list_head, that doesn't work well with big
BOs. If done, that would be handled on a separate commit.
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-06-05 11:21:54 +01:00
|
|
|
struct v3dv_bo *v3dv_bo_alloc(struct v3dv_device *device, uint32_t size, const char *name, bool private);
|
2019-12-10 11:00:49 +00:00
|
|
|
|
|
|
|
bool v3dv_bo_free(struct v3dv_device *device, struct v3dv_bo *bo);
|
|
|
|
|
|
|
|
bool v3dv_bo_wait(struct v3dv_device *device, struct v3dv_bo *bo, uint64_t timeout_ns);
|
|
|
|
|
|
|
|
bool v3dv_bo_map_unsynchronized(struct v3dv_device *device, struct v3dv_bo *bo, uint32_t size);
|
|
|
|
|
|
|
|
bool v3dv_bo_map(struct v3dv_device *device, struct v3dv_bo *bo, uint32_t size);
|
|
|
|
|
|
|
|
void v3dv_bo_unmap(struct v3dv_device *device, struct v3dv_bo *bo);
|
|
|
|
|
v3dv/bo: adding a BO cache
Heavily based on the already existing for the v3d OpenGL driver, but
without references, and with some extra OOM checks (Vulkan CTS has
several OOM tests).
With this commit v3dv_bo_alloc and v3dv_bo_free became frontends to
the bo_cache. The former tries to get a BO from the cache if possible,
and the latter stores the BO on the cache if possible. The former also
adds a new parameter to point if the BO to allocate is private.
As v3d we are only caching private BOs, those created by the driver
for internal use (like CLs, tile_alloc, etc). They are the ones with
the highest change of being reused (for example, CL BOs are always
4KB, so they can always be reused). User-created BOs can have any
size, including some very large ones for buffers and images, which
makes them far less likely to be reused and would add a lot of memory
pressure if we decided to cache them.
In any case, in practice, we found that we could get a performance
improvement by caching also user-created BOs, but that would need more
care and an analysis to decide which ones makes sense. Would also
require to change how the cached BOs are stored by size. Right now
there are an array of list_head, that doesn't work well with big
BOs. If done, that would be handled on a separate commit.
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-06-05 11:21:54 +01:00
|
|
|
void v3dv_bo_cache_init(struct v3dv_device *device);
|
|
|
|
void v3dv_bo_cache_destroy(struct v3dv_device *device);
|
|
|
|
|
2019-12-10 11:00:49 +00:00
|
|
|
#endif /* V3DV_BO_H */
|