Skip to content

Commit

Permalink
va:add synchornization fence for HW execution
Browse files Browse the repository at this point in the history
add fence in and fence out for vaEndPicture which is using to submit command buffer
fence out will be signaled after HW execution, fence in is the dependencies

Signed-off-by: Carl Zhang <[email protected]>
  • Loading branch information
XinfengZhang committed May 30, 2024
1 parent 1b7d71f commit 7c7a66d
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 2 deletions.
28 changes: 27 additions & 1 deletion va/va.c
Original file line number Diff line number Diff line change
Expand Up @@ -1643,7 +1643,7 @@ VAStatus vaEndPicture(
ctx = CTX(dpy);

VA_TRACE_V(dpy, END_PICTURE, TRACE_BEGIN, context);
VA_TRACE_ALL(va_TraceEndPicture, dpy, context, 0);
VA_TRACE_ALL(va_TraceEndPicture, dpy, context, NULL, 0, 0);
va_status = ctx->vtable->vaEndPicture(ctx, context);
VA_TRACE_RET(dpy, va_status);
/* dump surface content */
Expand All @@ -1653,6 +1653,32 @@ VAStatus vaEndPicture(
return va_status;
}

VAStatus vaEndPicture2(
VADisplay dpy,
VAContextID context,
int32_t *sync_fds,
int32_t sync_num

)
{
VAStatus va_status = VA_STATUS_SUCCESS;
VADriverContextP ctx;

CHECK_DISPLAY(dpy);
ctx = CTX(dpy);

VA_TRACE_V(dpy, END_PICTURE, TRACE_BEGIN, context);
VA_TRACE_ALL(va_TraceEndPicture, dpy, context, sync_fds, sync_num, 0);
va_status = ctx->vtable->vaEndPicture2(ctx, context, sync_fds, sync_num);
VA_TRACE_RET(dpy, va_status);
/* dump surface content */
VA_TRACE_ALL(va_TraceEndPictureExt, dpy, context, 1);
VA_TRACE_V(dpy, END_PICTURE, TRACE_END, va_status);

return va_status;
}


VAStatus vaSyncSurface(
VADisplay dpy,
VASurfaceID render_target
Expand Down
18 changes: 18 additions & 0 deletions va/va.h
Original file line number Diff line number Diff line change
Expand Up @@ -4174,6 +4174,24 @@ VAStatus vaEndPicture(
VAContextID context
);

/**
* Same behavior as vaEndPicture except a sync fd list for synchronizations.
* if sync_num = 0 or sync_fds == NULL, the behavior should be same as vaEndPicture.
* if sync_num >= 1, the sync_fds[0] should be the fence out, this fd(or the fence
* behind this fd) will be overridden by this call, and will be signaled to indicate
* current frame finishing. sync_num = 1 means only fence out is needed.
* sync_fds[1] to sync_fds[1 ~ sync_num-1] is fence in, current HW execution
* will be blocked until all these fences are signaled.
* these fence fds is file descriptor of dma_fence.
*/

VAStatus vaEndPicture2(
VADisplay dpy,
VAContextID context,
int32_t *sync_fds,
int32_t sync_num
);

/**
* Make the end of rendering for a pictures in contexts passed with submission.
* The server should start processing all pending operations for contexts.
Expand Down
10 changes: 9 additions & 1 deletion va/va_backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -511,8 +511,16 @@ struct VADriverVTable {
void **pbuf, /* out */
uint32_t flags /* in */
);

VAStatus(*vaEndPicture2)(
VADriverContextP ctx, /* in */
VAContextID context, /* in */
int32_t *sync_fds,
int32_t sync_num
);

/** \brief Reserved bytes for future use, must be zero */
unsigned long reserved[53];
unsigned long reserved[52];

};

Expand Down
8 changes: 8 additions & 0 deletions va/va_trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -5943,6 +5943,8 @@ void va_TraceRenderPicture(
void va_TraceEndPicture(
VADisplay dpy,
VAContextID context,
int32_t *sync_fds,
int32_t sync_num,
int endpic_done
)
{
Expand All @@ -5952,6 +5954,12 @@ void va_TraceEndPicture(

va_TraceMsg(trace_ctx, "\tcontext = 0x%08x\n", context);
va_TraceMsg(trace_ctx, "\trender_targets = 0x%08x\n", trace_ctx->trace_rendertarget);
if (sync_num && sync_fds) {
va_TraceMsg(trace_ctx, "\t fence out = %d \n", sync_fds[0]);
for (int i = 1; i < sync_num && sync_num > 1; i ++) {
va_TraceMsg(trace_ctx, "\t fence_in index %d = %d \n", i - 1, sync_fds[i]);
}
}
va_TraceMsg(trace_ctx, NULL);
}

Expand Down
2 changes: 2 additions & 0 deletions va/va_trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,8 @@ DLL_HIDDEN
void va_TraceEndPicture(
VADisplay dpy,
VAContextID context,
int32_t *sync_fds,
int32_t sync_num,
int endpic_done
);

Expand Down

0 comments on commit 7c7a66d

Please sign in to comment.