mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-01-06 17:30:20 +01:00
freedreno/drm: Add fd_bo_upload()
There are some buffers that we mmap just to write to them a single time. Add the possibility of the drm backend to provide an alternate upload path to avoid these mmap's. Signed-off-by: Rob Clark <robdclark@chromium.org> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14900>
This commit is contained in:
parent
115518ec35
commit
9bcc983256
4 changed files with 34 additions and 7 deletions
|
|
@ -454,16 +454,13 @@ fd_bo_is_cached(struct fd_bo *bo)
|
|||
return !!(bo->alloc_flags & FD_BO_CACHED_COHERENT);
|
||||
}
|
||||
|
||||
void *
|
||||
fd_bo_map(struct fd_bo *bo)
|
||||
static void *
|
||||
bo_map(struct fd_bo *bo)
|
||||
{
|
||||
if (!bo->map) {
|
||||
uint64_t offset;
|
||||
int ret;
|
||||
|
||||
if (bo->alloc_flags & FD_BO_NOMAP)
|
||||
return NULL;
|
||||
|
||||
ret = bo->funcs->offset(bo, &offset);
|
||||
if (ret) {
|
||||
return NULL;
|
||||
|
|
@ -479,6 +476,29 @@ fd_bo_map(struct fd_bo *bo)
|
|||
return bo->map;
|
||||
}
|
||||
|
||||
void *
|
||||
fd_bo_map(struct fd_bo *bo)
|
||||
{
|
||||
/* don't allow mmap'ing something allocated with FD_BO_NOMAP
|
||||
* for sanity
|
||||
*/
|
||||
if (bo->alloc_flags & FD_BO_NOMAP)
|
||||
return NULL;
|
||||
|
||||
return bo_map(bo);
|
||||
}
|
||||
|
||||
void
|
||||
fd_bo_upload(struct fd_bo *bo, void *src, unsigned len)
|
||||
{
|
||||
if (bo->funcs->upload) {
|
||||
bo->funcs->upload(bo, src, len);
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(bo_map(bo), src, len);
|
||||
}
|
||||
|
||||
/* a bit odd to take the pipe as an arg, but it's a, umm, quirk of kgsl.. */
|
||||
int
|
||||
fd_bo_cpu_prep(struct fd_bo *bo, struct fd_pipe *pipe, uint32_t op)
|
||||
|
|
|
|||
|
|
@ -215,6 +215,7 @@ uint32_t fd_bo_handle(struct fd_bo *bo);
|
|||
int fd_bo_dmabuf(struct fd_bo *bo);
|
||||
uint32_t fd_bo_size(struct fd_bo *bo);
|
||||
void *fd_bo_map(struct fd_bo *bo);
|
||||
void fd_bo_upload(struct fd_bo *bo, void *src, unsigned len);
|
||||
int fd_bo_cpu_prep(struct fd_bo *bo, struct fd_pipe *pipe, uint32_t op);
|
||||
void fd_bo_cpu_fini(struct fd_bo *bo);
|
||||
bool fd_bo_is_cached(struct fd_bo *bo);
|
||||
|
|
|
|||
|
|
@ -294,6 +294,12 @@ struct fd_bo_funcs {
|
|||
uint64_t (*iova)(struct fd_bo *bo);
|
||||
void (*set_name)(struct fd_bo *bo, const char *fmt, va_list ap);
|
||||
void (*destroy)(struct fd_bo *bo);
|
||||
|
||||
/**
|
||||
* Optional, copy data into bo, falls back to mmap+memcpy. If not
|
||||
* implemented, it must be possible to mmap all buffers
|
||||
*/
|
||||
void (*upload)(struct fd_bo *bo, void *src, unsigned len);
|
||||
};
|
||||
|
||||
struct fd_bo_fence {
|
||||
|
|
|
|||
|
|
@ -108,13 +108,13 @@ upload_shader_variant(struct ir3_shader_variant *v)
|
|||
assert(!v->bo);
|
||||
|
||||
v->bo =
|
||||
fd_bo_new(compiler->dev, v->info.size, 0,
|
||||
fd_bo_new(compiler->dev, v->info.size, FD_BO_NOMAP,
|
||||
"%s:%s", ir3_shader_stage(v), info->name);
|
||||
|
||||
/* Always include shaders in kernel crash dumps. */
|
||||
fd_bo_mark_for_dump(v->bo);
|
||||
|
||||
memcpy(fd_bo_map(v->bo), v->bin, v->info.size);
|
||||
fd_bo_upload(v->bo, v->bin, v->info.size);
|
||||
}
|
||||
|
||||
struct ir3_shader_variant *
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue