[Mesa-dev] [PATCH 3/3] radeonsi: implement sync_file import/export
Nicolai Hähnle
nhaehnle at gmail.com
Wed Sep 13 16:30:52 UTC 2017
On 13.09.2017 18:21, Marek Olšák wrote:
> On Wed, Sep 13, 2017 at 5:39 PM, Nicolai Hähnle <nhaehnle at gmail.com> wrote:
>> On 12.09.2017 22:50, Marek Olšák wrote:
>>>
>>> From: Marek Olšák <marek.olsak at amd.com>
>>>
>>> ---
>>> src/gallium/drivers/radeon/r600_pipe_common.c | 77
>>> ++++++++++++++++++++++++++-
>>> src/gallium/drivers/radeonsi/si_pipe.c | 4 +-
>>> 2 files changed, 79 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/src/gallium/drivers/radeon/r600_pipe_common.c
>>> b/src/gallium/drivers/radeon/r600_pipe_common.c
>>> index 48fda7b..b66acf7 100644
>>> --- a/src/gallium/drivers/radeon/r600_pipe_common.c
>>> +++ b/src/gallium/drivers/radeon/r600_pipe_common.c
>>> @@ -31,20 +31,21 @@
>>> #include "util/u_draw_quad.h"
>>> #include "util/u_memory.h"
>>> #include "util/u_format_s3tc.h"
>>> #include "util/u_upload_mgr.h"
>>> #include "os/os_time.h"
>>> #include "vl/vl_decoder.h"
>>> #include "vl/vl_video_buffer.h"
>>> #include "radeon/radeon_video.h"
>>> #include <inttypes.h>
>>> #include <sys/utsname.h>
>>> +#include <libsync.h>
>>> #ifndef HAVE_LLVM
>>> #define HAVE_LLVM 0
>>> #endif
>>> #if HAVE_LLVM
>>> #include <llvm-c/TargetMachine.h>
>>> #endif
>>> #ifndef MESA_LLVM_VERSION_PATCH
>>> @@ -448,20 +449,89 @@ static void r600_fence_server_sync(struct
>>> pipe_context *ctx,
>>> * this fence dependency is signalled.
>>> *
>>> * Should we flush the context to allow more GPU parallelism?
>>> */
>>> if (rfence->sdma)
>>> r600_add_fence_dependency(rctx, rfence->sdma);
>>> if (rfence->gfx)
>>> r600_add_fence_dependency(rctx, rfence->gfx);
>>> }
>>> +static void r600_create_fence_fd(struct pipe_context *ctx,
>>> + struct pipe_fence_handle **pfence, int
>>> fd)
>>> +{
>>> + struct r600_common_screen *rscreen = (struct
>>> r600_common_screen*)ctx->screen;
>>> + struct radeon_winsys *ws = rscreen->ws;
>>> + struct r600_multi_fence *rfence;
>>> +
>>> + *pfence = NULL;
>>> +
>>> + if (!rscreen->info.has_sync_file)
>>> + return;
>>> +
>>> + rfence = CALLOC_STRUCT(r600_multi_fence);
>>> + if (!rfence)
>>> + return;
>>> +
>>> + pipe_reference_init(&rfence->reference, 1);
>>> + rfence->gfx = ws->fence_import_sync_file(ws, fd);
>>> + if (!rfence->gfx) {
>>> + FREE(rfence);
>>> + return;
>>> + }
>>> +
>>> + *pfence = (struct pipe_fence_handle*)rfence;
>>> +}
>>> +
>>> +static int r600_fence_get_fd(struct pipe_screen *screen,
>>> + struct pipe_fence_handle *fence)
>>> +{
>>> + struct r600_common_screen *rscreen = (struct
>>> r600_common_screen*)screen;
>>> + struct radeon_winsys *ws = rscreen->ws;
>>> + struct r600_multi_fence *rfence = (struct r600_multi_fence
>>> *)fence;
>>> + int gfx_fd = -1, sdma_fd = -1;
>>> +
>>> + if (!rscreen->info.has_sync_file)
>>> + return -1;
>>> +
>>> + /* Deferred fences aren't supported. */
>>> + assert(!rfence->gfx_unflushed.ctx);
>>> + if (rfence->gfx_unflushed.ctx)
>>> + return -1;
>>> +
>>> + if (rfence->sdma) {
>>> + sdma_fd = ws->fence_export_sync_file(ws, rfence->sdma);
>>> + if (sdma_fd == -1)
>>> + return -1;
>>> + }
>>> + if (rfence->gfx) {
>>> + gfx_fd = ws->fence_export_sync_file(ws, rfence->gfx);
>>> + if (gfx_fd == -1) {
>>> + if (sdma_fd != -1)
>>> + close(sdma_fd);
>>> + return -1;
>>> + }
>>> + }
>>> +
>>> + /* If we don't have FDs at this point, it means we don't have
>>> fences
>>> + * either. */
>>> + if (sdma_fd == -1)
>>> + return gfx_fd;
>>> + if (gfx_fd == -1)
>>> + return sdma_fd;
>>> +
>>> + /* Get a fence that will be a combination of both fences. */
>>> + sync_accumulate("radeonsi", &gfx_fd, sdma_fd);
>>
>>
>> What happens if this fails?
>
> gfx_fd will be returned.
... and sync_accumulate hopefully promises that it's all-or-nothing.
Seems reasonable enough, thanks.
>
> Marek
>
--
Lerne, wie die Welt wirklich ist,
Aber vergiss niemals, wie sie sein sollte.
More information about the mesa-dev
mailing list