[Mesa-dev] [PATCH] radeonsi: add missing initialization for userptr buffers
Marek Olšák
maraeo at gmail.com
Thu Apr 13 16:57:47 UTC 2017
Reviewed-by: Marek Olšák <marek.olsak at amd.com>
Marek
On Thu, Apr 13, 2017 at 5:42 PM, Nicolai Hähnle <nhaehnle at gmail.com> wrote:
> From: Nicolai Hähnle <nicolai.haehnle at amd.com>
>
> Fix the accounting for memory usage of userptr buffers, which has been wrong
> forever (or at least for a long time).
>
> Also initialize flags. Without this initialization, the sparse buffer flag
> might end up being set, which leads to staging buffers being used unnecessarily
> (and incorrectly) in transfers to or from userptr buffers.
>
> This works around VM faults that occur with the radeon kernel module when
> running piglit ./bin/amd_pinned_memory decrement-offset map-buffer -auto
> (but it's actually also needed for correctness anyway, since the
> GL_AMD_pinned_memory spec clarifies that staging buffers shouldn't be used).
>
> Fixes: e077c5fe6579 ("gallium/radeon: transfers and invalidation for sparse buffers")
> Reported-by: Michel Dänzer <michel.daenzer at amd.com>
> --
> So, those VM faults shouldn't happen anyway, even when the unnecessary transfers
> occur. We do add the buffer to the buffer list, and amdgpu never showed VM faults,
> so this suggests that there's still a bug in the radeon kernel module.
> ---
> src/gallium/drivers/radeon/r600_buffer_common.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/src/gallium/drivers/radeon/r600_buffer_common.c b/src/gallium/drivers/radeon/r600_buffer_common.c
> index 0e93404..b2289e2 100644
> --- a/src/gallium/drivers/radeon/r600_buffer_common.c
> +++ b/src/gallium/drivers/radeon/r600_buffer_common.c
> @@ -605,27 +605,31 @@ struct pipe_resource *r600_aligned_buffer_create(struct pipe_screen *screen,
> struct pipe_resource *
> r600_buffer_from_user_memory(struct pipe_screen *screen,
> const struct pipe_resource *templ,
> void *user_memory)
> {
> struct r600_common_screen *rscreen = (struct r600_common_screen*)screen;
> struct radeon_winsys *ws = rscreen->ws;
> struct r600_resource *rbuffer = r600_alloc_buffer_struct(screen, templ);
>
> rbuffer->domains = RADEON_DOMAIN_GTT;
> + rbuffer->flags = 0;
> util_range_add(&rbuffer->valid_buffer_range, 0, templ->width0);
>
> /* Convert a user pointer to a buffer. */
> rbuffer->buf = ws->buffer_from_ptr(ws, user_memory, templ->width0);
> if (!rbuffer->buf) {
> FREE(rbuffer);
> return NULL;
> }
>
> if (rscreen->info.has_virtual_memory)
> rbuffer->gpu_address =
> ws->buffer_get_virtual_address(rbuffer->buf);
> else
> rbuffer->gpu_address = 0;
>
> + rbuffer->vram_usage = 0;
> + rbuffer->gart_usage = templ->width0;
> +
> return &rbuffer->b.b;
> }
> --
> 2.9.3
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
More information about the mesa-dev
mailing list