Skip to content
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
18 changes: 9 additions & 9 deletions cros_gralloc/cros_gralloc_driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -395,15 +395,15 @@ bool cros_gralloc_driver::get_resolved_format_and_use_flags(
resolved_use_flags &= ~BO_USE_SCANOUT;
combo = drv_get_combination(drv, resolved_format, descriptor->use_flags);
}
// if (!combo && (descriptor->droid_usage & GRALLOC_USAGE_HW_VIDEO_ENCODER) &&
// descriptor->droid_format != HAL_PIXEL_FORMAT_YCbCr_420_888) {
// // Unmask BO_USE_HW_VIDEO_ENCODER for other formats. They are mostly
// // intermediate formats not passed directly to the encoder (e.g.
// // camera). YV12 is passed to the encoder component, but it is converted
// // to YCbCr_420_888 before being passed to the hw encoder.
// resolved_use_flags &= ~BO_USE_HW_VIDEO_ENCODER;
// combo = drv_get_combination(drv, resolved_format, resolved_use_flags);
// }
if (!combo && (descriptor->droid_usage & GRALLOC_USAGE_HW_VIDEO_ENCODER) &&
descriptor->droid_format != HAL_PIXEL_FORMAT_YCbCr_420_888) {
// Unmask BO_USE_HW_VIDEO_ENCODER for other formats. They are mostly
// intermediate formats not passed directly to the encoder (e.g.
// camera). YV12 is passed to the encoder component, but it is converted
// to YCbCr_420_888 before being passed to the hw encoder.
resolved_use_flags &= ~BO_USE_HW_VIDEO_ENCODER;
combo = drv_get_combination(drv, resolved_format, resolved_use_flags);
}
if (!combo && (descriptor->droid_usage & BUFFER_USAGE_FRONT_RENDERING_MASK)) {
resolved_use_flags &= ~BO_USE_FRONT_RENDERING;
resolved_use_flags |= BO_USE_LINEAR;
Expand Down
4 changes: 2 additions & 2 deletions cros_gralloc/cros_gralloc_helpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ uint64_t cros_gralloc_convert_usage(uint64_t usage)
handle_usage(&usage, GRALLOC_USAGE_HW_RENDER, &use_flags, BO_USE_RENDERING);
handle_usage(&usage, GRALLOC_USAGE_HW_2D, &use_flags, BO_USE_RENDERING);
/* HWC wants to use display hardware, but can defer to OpenGL. */
handle_usage(&usage, GRALLOC_USAGE_HW_COMPOSER, &use_flags, BO_USE_TEXTURE | BO_USE_SCANOUT);
handle_usage(&usage, GRALLOC_USAGE_HW_COMPOSER, &use_flags, BO_USE_TEXTURE);
handle_usage(&usage, GRALLOC_USAGE_PRIVATE_1, &use_flags, BO_USE_SCANOUT);
handle_usage(&usage, GRALLOC_USAGE_HW_FB, &use_flags, BO_USE_NONE);
/*
Expand All @@ -167,7 +167,7 @@ uint64_t cros_gralloc_convert_usage(uint64_t usage)
handle_usage(&usage, GRALLOC_USAGE_CURSOR, &use_flags, BO_USE_NONE);
/* HACK: See b/30054495 for BO_USE_SW_READ_OFTEN. */
handle_usage(&usage, GRALLOC_USAGE_HW_VIDEO_ENCODER, &use_flags,
BO_USE_HW_VIDEO_ENCODER /* | BO_USE_SW_READ_OFTEN*/);
BO_USE_HW_VIDEO_ENCODER | BO_USE_SW_READ_OFTEN);
handle_usage(&usage, GRALLOC_USAGE_HW_CAMERA_WRITE, &use_flags, BO_USE_CAMERA_WRITE);
handle_usage(&usage, GRALLOC_USAGE_HW_CAMERA_READ, &use_flags, BO_USE_CAMERA_READ);
handle_usage(&usage, GRALLOC_USAGE_RENDERSCRIPT, &use_flags, BO_USE_RENDERSCRIPT);
Expand Down
60 changes: 24 additions & 36 deletions xe.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ static int xe_add_combinations(struct driver *drv)
BO_USE_CAMERA_READ | BO_USE_CAMERA_WRITE | BO_USE_HW_VIDEO_DECODER |
BO_USE_HW_VIDEO_ENCODER | BO_USE_GPU_DATA_BUFFER |
BO_USE_SENSOR_DIRECT_DATA);
drv_modify_combination(drv, DRM_FORMAT_ABGR8888, &metadata_linear, BO_USE_CURSOR | BO_USE_SCANOUT | BO_USE_HW_VIDEO_ENCODER);
drv_modify_combination(drv, DRM_FORMAT_ABGR8888, &metadata_linear, BO_USE_CURSOR | BO_USE_SCANOUT);
drv_modify_combination(drv, DRM_FORMAT_NV12, &metadata_linear,
BO_USE_RENDERING | BO_USE_TEXTURE | BO_USE_CAMERA_MASK);
drv_modify_combination(drv, DRM_FORMAT_YUYV, &metadata_linear,
Expand Down Expand Up @@ -240,9 +240,9 @@ static int xe_add_combinations(struct driver *drv)
&metadata_4_tiled, render_not_linear);
drv_add_combinations(drv, scanout_render_formats,
ARRAY_SIZE(scanout_render_formats), &metadata_4_tiled,
scanout_and_render_not_linear);
drv_add_combinations(drv, source_formats, ARRAY_SIZE(source_formats), &metadata_4_tiled,
texture_flags | BO_USE_NON_GPU_HW);
render_not_linear);
drv_add_combinations(drv, source_formats, ARRAY_SIZE(source_formats), &metadata_4_tiled,
texture_flags | BO_USE_NON_GPU_HW);

} else {
struct format_metadata metadata_y_tiled = { .tiling = XE_TILING_Y,
Expand All @@ -268,7 +268,7 @@ static int xe_add_combinations(struct driver *drv)
*/
drv_add_combinations(drv, scanout_render_formats,
ARRAY_SIZE(scanout_render_formats), &metadata_y_tiled,
scanout_and_render_not_linear);
render_not_linear);
drv_add_combinations(drv, source_formats, ARRAY_SIZE(source_formats), &metadata_y_tiled,
texture_flags | BO_USE_NON_GPU_HW);

Expand Down Expand Up @@ -347,11 +347,7 @@ static void xe_clflush(void *start, size_t size)

__builtin_ia32_mfence();
while (p < end) {
#if defined(__CLFLUSHOPT__)
__builtin_ia32_clflushopt(p);
#else
__builtin_ia32_clflush(p);
#endif
__builtin_ia32_clflush(p);
p = (void *)((uintptr_t)p + XE_CACHELINE_SIZE);
}
}
Expand Down Expand Up @@ -657,6 +653,7 @@ static int xe_bo_create_from_metadata(struct bo *bo)
int ret;
size_t plane;
uint32_t gem_handle;
uint32_t vm;

/* From xe_drm.h: If a VM is specified, this BO must:
* 1. Only ever be bound to that VM.
Expand All @@ -665,28 +662,17 @@ static int xe_bo_create_from_metadata(struct bo *bo)
* Should all buffers be defined as external? See here:
* https://gitlab.freedesktop.org/mesa/mesa/-/blob/main/src/intel/vulkan/xe/anv_kmd_backend.c?ref_type=heads#L60
*/
vm = 0;

struct drm_xe_gem_create gem_create = {
.vm_id = 0,
.vm_id = vm,
.size = ALIGN(bo->meta.total_size, PAGE_SIZE),
.flags = 0,
.flags = DRM_XE_GEM_CREATE_FLAG_SCANOUT,
};

/* FIXME: let's assume iGPU with SYSMEM is only supported */
gem_create.placement |= BITFIELD_BIT(DRM_XE_MEM_REGION_CLASS_SYSMEM);
if ((bo->meta.use_flags & BO_USE_SCANOUT) &&
!(bo->meta.use_flags & (BO_USE_RENDERSCRIPT | BO_USE_CAMERA_READ
| BO_USE_CAMERA_WRITE | BO_USE_SW_READ_OFTEN))) {
gem_create.flags = DRM_XE_GEM_CREATE_FLAG_SCANOUT;
gem_create.cpu_caching = DRM_XE_GEM_CPU_CACHING_WC;
} else if (((bo->meta.use_flags & BO_USE_SW_WRITE_OFTEN) ||
(bo->meta.use_flags & BO_USE_SW_READ_OFTEN)) &&
!(bo->meta.use_flags & BO_USE_HW_VIDEO_ENCODER)) {
gem_create.cpu_caching = DRM_XE_GEM_CPU_CACHING_WB;
} else {
gem_create.flags = DRM_XE_GEM_CREATE_FLAG_SCANOUT;
gem_create.cpu_caching = DRM_XE_GEM_CPU_CACHING_WC;
}

gem_create.cpu_caching = DRM_XE_GEM_CPU_CACHING_WC;

ret = drmIoctl(bo->drv->fd, DRM_IOCTL_XE_GEM_CREATE, &gem_create);
if (ret) {
Expand Down Expand Up @@ -730,17 +716,20 @@ static void *xe_bo_map(struct bo *bo, struct vma *vma, uint32_t map_flags)
struct xe_device *xe = bo->drv->priv;

if ((bo->meta.format_modifier == I915_FORMAT_MOD_Y_TILED_CCS) ||
(bo->meta.format_modifier == I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS))
(bo->meta.format_modifier == I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS) ||
(bo->meta.format_modifier == I915_FORMAT_MOD_4_TILED))
return MAP_FAILED;

struct drm_xe_gem_mmap_offset gem_map = { 0 };
gem_map.handle = bo->handles[0].u32;
if ((bo->meta.tiling == XE_TILING_NONE) || (addr == MAP_FAILED)) {
struct drm_xe_gem_mmap_offset gem_map = { 0 };
gem_map.handle = bo->handles[0].u32;

/* Get the fake offset back */
ret = drmIoctl(bo->drv->fd, DRM_IOCTL_XE_GEM_MMAP_OFFSET, &gem_map);
if (ret == 0)
addr = mmap(0, bo->meta.total_size, drv_get_prot(map_flags),
MAP_SHARED, bo->drv->fd, gem_map.offset);
/* Get the fake offset back */
ret = drmIoctl(bo->drv->fd, DRM_IOCTL_XE_GEM_MMAP_OFFSET, &gem_map);
if (ret == 0)
addr = mmap(0, bo->meta.total_size, drv_get_prot(map_flags),
MAP_SHARED, bo->drv->fd, gem_map.offset);
}

if (addr == MAP_FAILED) {
drv_loge("xe GEM mmap failed\n");
Expand All @@ -760,8 +749,7 @@ static int xe_bo_invalidate(struct bo *bo, struct mapping *mapping)
static int xe_bo_flush(struct bo *bo, struct mapping *mapping)
{
struct xe_device *xe = bo->drv->priv;
if ((bo->meta.tiling == XE_TILING_NONE)
&& (bo->meta.use_flags & BO_USE_SW_WRITE_OFTEN))
if (bo->meta.tiling == XE_TILING_NONE)
xe_clflush(mapping->vma->addr, mapping->vma->length);

return 0;
Expand Down