Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bo tile to linear switch by BLT engine on UMD #14

Open
wants to merge 1 commit into
base: intel-media-kbl
Choose a base branch
from
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
38 changes: 32 additions & 6 deletions media_driver/linux/common/ddi/media_libva.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5770,13 +5770,9 @@ VAStatus DdiMedia_ExportSurfaceHandle(
DDI_CHK_NULL(mediaSurface->bo, "nullptr mediaSurface->bo", VA_STATUS_ERROR_INVALID_SURFACE);
DDI_CHK_NULL(mediaSurface->pGmmResourceInfo, "nullptr mediaSurface->pGmmResourceInfo", VA_STATUS_ERROR_INVALID_SURFACE);

int32_t ret = mos_bo_gem_export_to_prime(mediaSurface->bo, (int32_t*)&mediaSurface->name);
if (ret)
{
//LOGE("Failed drm_intel_gem_export_to_prime operation!!!\n");
return VA_STATUS_ERROR_OPERATION_FAILED;
}
uint32_t tiling, swizzle;
int32_t ret;

if(mos_bo_get_tiling(mediaSurface->bo,&tiling, &swizzle))
{
tiling = I915_TILING_NONE;
Expand All @@ -5787,6 +5783,36 @@ VAStatus DdiMedia_ExportSurfaceHandle(
{
return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
}

if (mediaSurface->pBoShadow && (desc->fourcc == VA_FOURCC_NV12))
{
drm_intel_bo_switch(mediaSurface->bo, mediaSurface->pBoShadow, mediaSurface->pGmmResourceInfo->GetBaseHeight() * 3 / 2, mediaSurface->pGmmResourceInfo->GetRenderPitch());
mos_bo_map(mediaSurface->pBoShadow, (MOS_LOCKFLAG_READONLY | MOS_LOCKFLAG_WRITEONLY));
mediaSurface->bBoShadowMapped = true;

#if 0
FILE *fp = fopen("umd_dump_boshadow.yuv", "ab+");
fwrite(mediaSurface->pBoShadow->virt, mediaSurface->pGmmResourceInfo->GetBaseHeight() * mediaSurface->pGmmResourceInfo->GetRenderPitch() * 3 / 2, 1, fp);
fclose(fp);
#endif
ret = mos_bo_gem_export_to_prime(mediaSurface->pBoShadow, (int32_t*)&mediaSurface->name);
if (ret)
{
DDI_ASSERTMESSAGE("Failed drm_intel_gem_export_to_prime bo shadow operation!!!");
return VA_STATUS_ERROR_OPERATION_FAILED;
}
}
else
{

ret = mos_bo_gem_export_to_prime(mediaSurface->bo, (int32_t*)&mediaSurface->name);
if (ret)
{
DDI_ASSERTMESSAGE("Failed drm_intel_gem_export_to_prime bo operation!!!")
return VA_STATUS_ERROR_OPERATION_FAILED;
}
}

desc->width = mediaSurface->iWidth;
desc->height = mediaSurface->iHeight;

Expand Down
2 changes: 2 additions & 0 deletions media_driver/linux/common/ddi/media_libva_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,9 @@ typedef struct _DDI_MEDIA_SURFACE
uint32_t isTiled;
uint32_t TileType;
uint32_t bMapped;
uint32_t bBoShadowMapped;
MOS_LINUX_BO *bo;
MOS_LINUX_BO *pBoShadow;
uint32_t name;
uint32_t surfaceUsageHint;
PDDI_MEDIA_SURFACE_DESCRIPTOR pSurfDesc; // nullptr means surface was allocated by media driver
Expand Down
13 changes: 13 additions & 0 deletions media_driver/linux/common/ddi/media_libva_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ VAStatus DdiMediaUtil_AllocateSurface(
{
int32_t pitch = 0;
MOS_LINUX_BO *bo = nullptr;
MOS_LINUX_BO *boShadow = nullptr;
GMM_RESCREATE_PARAMS gmmParams;
GMM_RESOURCE_INFO *gmmResourceInfo;
bool grallocAllocation;
Expand Down Expand Up @@ -556,6 +557,8 @@ VAStatus DdiMediaUtil_AllocateSurface(
{
bo = mos_bo_alloc_tiled(mediaDrvCtx->pDrmBufMgr, "MEDIA", gmmPitch, gmmSize/gmmPitch, 1, &tileformat, (unsigned long *)&ulPitch, 0);
pitch = (int32_t)ulPitch;

boShadow = mos_bo_alloc(mediaDrvCtx->pDrmBufMgr, "MEDIA", gmmSize, 4096);
}
}
}
Expand Down Expand Up @@ -592,6 +595,8 @@ VAStatus DdiMediaUtil_AllocateSurface(
}

mediaSurface->bMapped = false;
mediaSurface->bBoShadowMapped = false;

if (bo)
{
mediaSurface->format = format;
Expand All @@ -601,6 +606,7 @@ VAStatus DdiMediaUtil_AllocateSurface(
mediaSurface->iPitch = pitch;
mediaSurface->iRefCount = 0;
mediaSurface->bo = bo;
mediaSurface->pBoShadow = boShadow;
mediaSurface->TileType = tileformat;
mediaSurface->isTiled = (tileformat != I915_TILING_NONE) ? 1 : 0;
mediaSurface->pData = (uint8_t*) bo->virt;
Expand Down Expand Up @@ -1090,7 +1096,14 @@ void DdiMediaUtil_FreeSurface(DDI_MEDIA_SURFACE *surface)
DdiMediaUtil_UnlockSurface(surface);
DDI_VERBOSEMESSAGE("DDI: try to free a locked surface.");
}
if (surface->bBoShadowMapped)
{
mos_bo_unmap(surface->pBoShadow);
surface->pBoShadow->virt = nullptr;
}
mos_bo_unreference(surface->pBoShadow);
mos_bo_unreference(surface->bo);
surface->pBoShadow = nullptr;
surface->bo = nullptr;
}

Expand Down
10 changes: 10 additions & 0 deletions media_driver/linux/common/os/libdrm/include/i915_drm.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ struct drm_i915_cmd_parser_append {
#define DRM_I915_GEM_CONTEXT_GETPARAM 0x34
#define DRM_I915_GEM_CONTEXT_SETPARAM 0x35
#define DRM_I915_PERFMON 0x3e
#define DRM_I915_GEM_BO_SWITCH 0x40

#ifndef ANDROID
#define DRM_I915_LOAD_BALANCING_HINT 0x3f
Expand Down Expand Up @@ -329,6 +330,7 @@ struct drm_i915_cmd_parser_append {
#define DRM_IOCTL_I915_GEM_USERPTR DRM_IOWR (DRM_COMMAND_BASE + DRM_I915_GEM_USERPTR, struct drm_i915_gem_userptr)
#define DRM_IOCTL_I915_GEM_CONTEXT_GETPARAM DRM_IOWR (DRM_COMMAND_BASE + DRM_I915_GEM_CONTEXT_GETPARAM, struct drm_i915_gem_context_param)
#define DRM_IOCTL_I915_GEM_CONTEXT_SETPARAM DRM_IOWR (DRM_COMMAND_BASE + DRM_I915_GEM_CONTEXT_SETPARAM, struct drm_i915_gem_context_param)
#define DRM_IOCTL_I915_GEM_BO_SWITCH DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GEM_BO_SWITCH, struct drm_i915_bo_switch)

#ifndef ANDROID
#define DRM_IOCTL_I915_LOAD_BALANCING_HINT DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_LOAD_BALANCING_HINT, struct drm_i915_ring_load_query)
Expand Down Expand Up @@ -1375,4 +1377,12 @@ typedef struct drm_i915_ring_load_query
drm_i915_ring_load_info *load_info;
} drm_i915_ring_load_query;

struct drm_i915_bo_switch {
__u32 handle_tiled;
__u32 handle_linear;
__u32 flags;
__u32 height;
__u32 width;
};

#endif /* _I915_DRM_H_ */
2 changes: 1 addition & 1 deletion media_driver/linux/common/os/libdrm/include/mos_bufmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ int mos_gem_bo_context_fence_exec(struct mos_linux_bo *bo, struct mos_linux_cont
int mos_bo_gem_export_to_prime(struct mos_linux_bo *bo, int *prime_fd);
struct mos_linux_bo *mos_bo_gem_create_from_prime(struct mos_bufmgr *bufmgr,
int prime_fd, int size);

int drm_intel_bo_switch(struct mos_linux_bo *bo_tiled, struct mos_linux_bo *bo_linear, uint32_t height, uint32_t width);
/* drm_intel_bufmgr_fake.c */
struct mos_bufmgr *mos_bufmgr_fake_init(int fd,
unsigned long low_offset,
Expand Down
20 changes: 20 additions & 0 deletions media_driver/linux/common/os/libdrm/mos_bufmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -4111,6 +4111,26 @@ mos_bo_gem_export_to_prime(struct mos_linux_bo *bo, int *prime_fd)
return 0;
}

int drm_intel_bo_switch(struct mos_linux_bo *bo_tiled, struct mos_linux_bo *bo_linear, uint32_t height, uint32_t width)
{
struct mos_bufmgr_gem *bufmgr_gem_tiled = (struct mos_bufmgr_gem *) bo_tiled->bufmgr;
struct mos_bo_gem *bo_gem_tiled = (struct mos_bo_gem *) bo_tiled;
struct mos_bo_gem *bo_gem_linear = (struct mos_bo_gem *) bo_linear;
struct drm_i915_bo_switch args;
int ret;

args.handle_tiled = bo_gem_tiled->gem_handle;
args.handle_linear = bo_gem_linear->gem_handle;
args.flags = 0; //will use in later
args.height = height;
args.width = width;
ret = drmIoctl(bufmgr_gem_tiled->fd, DRM_IOCTL_I915_GEM_BO_SWITCH, &args);
if (ret)
return ret;

return 0;
}

static int
mos_gem_bo_flink(struct mos_linux_bo *bo, uint32_t * name)
{
Expand Down