Skip to content
This repository was archived by the owner on Jun 1, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions media_driver/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,7 @@ LOCAL_SRC_FILES := \
../media_softlet/linux/common/os/i915/xf86drmRandom.c \
../media_softlet/linux/common/os/i915_production/mos_bufmgr.c \
../media_softlet/linux/common/os/i915_production/mos_bufmgr_prelim.cpp \
../media_softlet/linux/common/os/xe/mos_synchronization_xe.c \
../media_softlet/linux/common/os/mos_auxtable_mgr.cpp \
../media_softlet/linux/common/os/mos_commandbuffer_specific_next.cpp \
../media_softlet/linux/common/os/mos_context_specific_next.cpp \
Expand Down Expand Up @@ -1949,6 +1950,7 @@ LOCAL_C_INCLUDES = \
$(LOCAL_PATH)/../media_softlet/linux/common/os/i915/include \
$(LOCAL_PATH)/../media_softlet/linux/common/os/i915_production/include \
$(LOCAL_PATH)/../media_softlet/linux/common/os/i915_production \
$(LOCAL_PATH)/../media_softlet/linux/common/os/xe/include \
$(LOCAL_PATH)/../media_softlet/linux/common/os \
$(LOCAL_PATH)/../media_softlet/linux/common/cp/ddi \
$(LOCAL_PATH)/../media_softlet/linux/common/cp \
Expand Down
3 changes: 3 additions & 0 deletions media_driver/linux/common/ddi/ddi_media_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ struct DDI_MEDIA_CONTEXT
MEDIA_MUTEX_T ProtMutex = {};
MEDIA_MUTEX_T CmMutex = {};
MEDIA_MUTEX_T MfeMutex = {};
//todo: #if VA_CHECK_VERSION(1, 9, 0)
MEDIA_MUTEX_T SyncFenceMutex = {};
//#endif

// GT system Info
MEDIA_SYSTEM_INFO *pGtSystemInfo = nullptr;
Expand Down
60 changes: 60 additions & 0 deletions media_driver/linux/common/ddi/media_libva.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1428,6 +1428,9 @@ static VAStatus DdiMedia_HeapInitialize(
DdiMediaUtil_InitMutex(&mediaCtx->ProtMutex);
DdiMediaUtil_InitMutex(&mediaCtx->CmMutex);
DdiMediaUtil_InitMutex(&mediaCtx->MfeMutex);
//todo: #if VA_CHECK_VERSION(1, 9, 0)
DdiMediaUtil_InitMutex(&mediaCtx->SyncFenceMutex);
//#endif

return VA_STATUS_SUCCESS;
}
Expand Down Expand Up @@ -1482,6 +1485,9 @@ static VAStatus DdiMedia_HeapDestroy(
DdiMediaUtil_DestroyMutex(&mediaCtx->ProtMutex);
DdiMediaUtil_DestroyMutex(&mediaCtx->CmMutex);
DdiMediaUtil_DestroyMutex(&mediaCtx->MfeMutex);
//todo: #if VA_CHECK_VERSION(1, 9, 0)
DdiMediaUtil_DestroyMutex(&mediaCtx->SyncFenceMutex);
//#endif

//resource checking
if (mediaCtx->uiNumSurfaces != 0)
Expand Down Expand Up @@ -1559,6 +1565,9 @@ void DestroyMediaContextMutex(PDDI_MEDIA_CONTEXT mediaCtx)
DdiMediaUtil_DestroyMutex(&mediaCtx->VpMutex);
DdiMediaUtil_DestroyMutex(&mediaCtx->CmMutex);
DdiMediaUtil_DestroyMutex(&mediaCtx->MfeMutex);
//todo: #if VA_CHECK_VERSION(1, 9, 0)
DdiMediaUtil_DestroyMutex(&mediaCtx->SyncFenceMutex);
//#endif
#if !defined(ANDROID) && defined(X11_FOUND)
DdiMediaUtil_DestroyMutex(&mediaCtx->PutSurfaceRenderMutex);
DdiMediaUtil_DestroyMutex(&mediaCtx->PutSurfaceSwapBufferMutex);
Expand Down Expand Up @@ -2169,6 +2178,9 @@ VAStatus DdiMedia_LoadFuncion (VADriverContextP ctx)
pVTable->vaBeginPicture = DdiMedia_BeginPicture;
pVTable->vaRenderPicture = DdiMedia_RenderPicture;
pVTable->vaEndPicture = DdiMedia_EndPicture;
//todo: #if VA_CHECK_VERSION(1, 9, 0)
pVTable->vaEndPicture2 = DdiMedia_EndPicture2;
//#endif
pVTable->vaSyncSurface = DdiMedia_SyncSurface;
#if VA_CHECK_VERSION(1, 9, 0)
pVTable->vaSyncSurface2 = DdiMedia_SyncSurface2;
Expand Down Expand Up @@ -4088,6 +4100,54 @@ VAStatus DdiMedia_EndPicture (
return vaStatus;
}

//#if VA_CHECK_VERSION(1, 9, 0) //todo: check correct version
VAStatus DdiMedia_EndPicture2 (
VADriverContextP ctx,
VAContextID context,
int32_t *fences,
int32_t count
)
{
DDI_FUNCTION_ENTER();

DDI_CHK_NULL(ctx, "nullptr ctx", VA_STATUS_ERROR_INVALID_CONTEXT);
DDI_CHK_NULL(fences, "nullptr fences", VA_STATUS_ERROR_INVALID_PARAMETER);

uint32_t ctxType = DDI_MEDIA_CONTEXT_TYPE_NONE;
void *ctxPtr = DdiMedia_GetContextFromContextID(ctx, context, &ctxType);
PDDI_MEDIA_CONTEXT mediaCtx = DdiMedia_GetMediaContext(ctx);
VAStatus vaStatus = VA_STATUS_SUCCESS;

DdiMediaUtil_LockMutex(&mediaCtx->SyncFenceMutex);
vaStatus = DdiMedia_SetSyncFences(ctx, context, fences, count);
//todo: add fences[1...count] into bufmgr->fences[...]

switch (ctxType)
{
case DDI_MEDIA_CONTEXT_TYPE_DECODER:
vaStatus = DdiDecode_EndPicture(ctx, context);
break;
case DDI_MEDIA_CONTEXT_TYPE_ENCODER:
vaStatus = DdiEncode_EndPicture(ctx, context);
break;
case DDI_MEDIA_CONTEXT_TYPE_VP:
vaStatus = DdiVp_EndPicture(ctx, context);
break;
default:
DDI_ASSERTMESSAGE("DDI: unsupported context in DdiCodec_EndPicture.");
vaStatus = VA_STATUS_ERROR_INVALID_CONTEXT;
}
vaStatus = DdiMedia_GetSyncFenceOut(ctx, context, &fences[0]);
//todo: get fence out from bufmgr->fence[0]
DdiMediaUtil_UnLockMutex(&mediaCtx->SyncFenceMutex);

MOS_TraceEventExt(EVENT_VA_PICTURE, EVENT_TYPE_END, &context, sizeof(context), &vaStatus, sizeof(vaStatus));
PERF_UTILITY_STOP_ONCE("First Frame Time", PERF_MOS, PERF_LEVEL_DDI);

return vaStatus;
}
//#endif

static VAStatus DdiMedia_StatusCheck (
PDDI_MEDIA_CONTEXT mediaCtx,
DDI_MEDIA_SURFACE *surface,
Expand Down
9 changes: 9 additions & 0 deletions media_driver/linux/common/ddi/media_libva.h
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,15 @@ VAStatus DdiMedia_EndPicture (
VAContextID context
);

//#if VA_CHECK_VERSION(1, 9, 0) //todo: check correct version
VAStatus DdiMedia_EndPicture2 (
VADriverContextP ctx,
VAContextID context,
int32_t *fences,
int32_t count
);
//#endif

//!
//! \brief Sync surface
//! \details This function blocks until all pending operations on the render target
Expand Down
30 changes: 30 additions & 0 deletions media_driver/linux/common/ddi/media_libva_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,3 +475,33 @@ void MovePriorityBufferIdToEnd (VABufferID *buffers, int32_t priorityIndexInBuf,
}
}

VAStatus DdiMedia_SetSyncFences(VADriverContextP ctx, VAContextID context, int32_t *fences, int32_t count)
{
VAStatus vaStatus = VA_STATUS_SUCCESS;
PDDI_MEDIA_CONTEXT mediaCtx = DdiMedia_GetMediaContext(ctx);
struct mos_exec_fences exec_fences;
exec_fences.fences = fences;
exec_fences.count = count;
int ret = mos_set_fences(mediaCtx->pDrmBufMgr, &exec_fences);

if (ret)
{
vaStatus = VA_STATUS_ERROR_OPERATION_FAILED;
}

return vaStatus;
}

VAStatus DdiMedia_GetSyncFenceOut(VADriverContextP ctx, VAContextID context, int32_t *fence_out)
{
VAStatus vaStatus = VA_STATUS_SUCCESS;
PDDI_MEDIA_CONTEXT mediaCtx = DdiMedia_GetMediaContext(ctx);
int ret = mos_get_fence(mediaCtx->pDrmBufMgr, fence_out);
if (ret)
{
vaStatus = VA_STATUS_ERROR_OPERATION_FAILED;
*fence_out = 0;
}

return vaStatus;
}
10 changes: 10 additions & 0 deletions media_driver/linux/common/ddi/media_libva_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,4 +273,14 @@ int32_t DdiMedia_GetGpuPriority (VADriverContextP ctx, VABufferID *buffers, int3
//!
void MovePriorityBufferIdToEnd (VABufferID *buffers, int32_t priorityIndexInBuf, int32_t numBuffers);

//!
//! \brief Add fence fds into bufmgr for execution sync
//!
VAStatus DdiMedia_SetSyncFences(VADriverContextP ctx, VAContextID context, int32_t *fences, int32_t count);

//!
//! \brief Get fence out from current execution submission
//!
VAStatus DdiMedia_GetSyncFenceOut(VADriverContextP ctx, VAContextID context, int32_t *fence_out);

#endif
10 changes: 10 additions & 0 deletions media_softlet/linux/common/os/i915/include/mos_bufmgr_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,13 @@ struct mos_drm_uc_version {
uint32_t minor_version;
};

struct mos_exec_fences
{
#define FENCES_MAX 10
int32_t *fences;
int32_t count;
};

struct mos_linux_bo *mos_bo_alloc(struct mos_bufmgr *bufmgr,
struct mos_drm_bo_alloc *alloc);
struct mos_linux_bo *mos_bo_alloc_userptr(struct mos_bufmgr *bufmgr,
Expand Down Expand Up @@ -313,6 +320,9 @@ int mos_bufmgr_get_memory_info(struct mos_bufmgr *bufmgr, char *info, uint32_t l
int mos_bufmgr_get_devid(struct mos_bufmgr *bufmgr);
void mos_bufmgr_realloc_cache(struct mos_bufmgr *bufmgr, uint8_t alloc_mode);

int mos_set_fences(struct mos_bufmgr *bufmgr, struct mos_exec_fences *exec_fences);
int mos_get_fence(struct mos_bufmgr *bufmgr, int32_t *fence_out);

int mos_bo_map_unsynchronized(struct mos_linux_bo *bo);
int mos_bo_map_gtt(struct mos_linux_bo *bo);
int mos_bo_unmap_gtt(struct mos_linux_bo *bo);
Expand Down
3 changes: 3 additions & 0 deletions media_softlet/linux/common/os/i915/include/mos_bufmgr_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,9 @@ struct mos_bufmgr {
uint8_t (*switch_off_n_bits)(struct mos_linux_context *ctx, uint8_t in_mask, int n) = nullptr;
unsigned int (*hweight8)(struct mos_linux_context *ctx, uint8_t w) = nullptr;

int (*set_fences)(struct mos_bufmgr *bufmgr, struct mos_exec_fences *exec_fences) = nullptr;
int (*get_fence)(struct mos_bufmgr *bufmgr, int32_t *fence_out) = nullptr;

/**< Enables verbose debugging printouts */
int debug = 0;
uint32_t *get_reserved = nullptr;
Expand Down
42 changes: 42 additions & 0 deletions media_softlet/linux/common/os/i915/mos_bufmgr_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1223,6 +1223,48 @@ mos_bufmgr_realloc_cache(struct mos_bufmgr *bufmgr, uint8_t alloc_mode)
}
}

int
mos_set_fences(struct mos_bufmgr *bufmgr, struct mos_exec_fences *exec_fences)
{
if(!bufmgr)
{
MOS_OS_CRITICALMESSAGE("Input null ptr\n");
return -EINVAL;
}

if (bufmgr->set_fences)
{
return bufmgr->set_fences(bufmgr, exec_fences);
}
else
{
MOS_OS_CRITICALMESSAGE("Unsupported\n");
return -EPERM;
}

}

int
mos_get_fence(struct mos_bufmgr *bufmgr, int32_t *fence_out)
{
if(!bufmgr)
{
MOS_OS_CRITICALMESSAGE("Input null ptr\n");
return -EINVAL;
}

if (bufmgr->get_fence)
{
return bufmgr->get_fence(bufmgr, fence_out);
}
else
{
MOS_OS_CRITICALMESSAGE("Unsupported\n");
return -EPERM;
}

}

int
mos_query_engines_count(struct mos_bufmgr *bufmgr,
unsigned int *nengine)
Expand Down
Loading