Skip to content

Commit

Permalink
Enforce linear buffer for decoding in the case of hybrid-GPU
Browse files Browse the repository at this point in the history
In hybrid GPU case, video decoder could be iGPU and the coded images
would be consumed by dGPU. Unfortunately, it's likely that we can hardly
find a tiling format supported by both of them. To achieve best
compatibility and make our life better, simply use linear buffers for
decoded images.

By setting CPU_READ and CPU_WRITE flags, we force OneVPL to allocate
internal buffers and blit decoded content to external buffers. In this
way we can work around hardware limitation that DG2 cannot decode to
linear buffers.

We will detect the GPU group type and decide whether to use linear
buffers or not.

Tracked-On: OAM-126399
Signed-off-by: Weifeng Liu <[email protected]>

(cherry picked from commit bfcd81e)
Tracked-On: OAM-128364
Signed-off-by: Lina Sun <[email protected]>
  • Loading branch information
phreer authored and lsun30 committed Dec 10, 2024
1 parent 449ab47 commit dd00ed4
Show file tree
Hide file tree
Showing 6 changed files with 820 additions and 0 deletions.
2 changes: 2 additions & 0 deletions c2_components/include/mfx_c2_decoder_component.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "mfx_c2_bitstream_in.h"
#include "mfx_frame_pool_allocator.h"
#include "mfx_gralloc_instance.h"
#include "mfx_intel_device.h"
#include "mfx_c2_setters.h"
#include "mfx_c2_utils.h"
#include <cutils/properties.h>
Expand Down Expand Up @@ -264,6 +265,7 @@ class MfxC2DecoderComponent : public MfxC2Component
// dump output multiple times, the first dumped file named xxx_0.yuv,
// second dumped file named xxx_1.yuv ...
uint32_t m_file_num = 0;
bool m_needCpuAccess = false;

/* -----------------------C2Parameters--------------------------- */
std::shared_ptr<C2ComponentNameSetting> m_name;
Expand Down
16 changes: 16 additions & 0 deletions c2_components/src/mfx_c2_decoder_component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "mfx_c2_decoder_component.h"

#include "mfx_debug.h"
#include "mfx_intel_device.h"
#include "mfx_msdk_debug.h"
#include "mfx_c2_debug.h"
#include "mfx_c2_components_registry.h"
Expand Down Expand Up @@ -178,6 +179,12 @@ MfxC2DecoderComponent::MfxC2DecoderComponent(const C2String name, const CreateCo
MFX_DEBUG_TRACE_FUNC;
const unsigned int SINGLE_STREAM_ID = 0u;

// We need to enable CPU access to the buffers of decoded images when
// 1. decode with DG2 and display with RPL-p iGPU;
// 2. decode with RPL-p iGPU and display with DG2.
// The displaying GPU will appear as virtio-GPU.
m_needCpuAccess = enforceLinearBuffer();

addParameter(
DefineParam(m_kind, C2_PARAMKEY_COMPONENT_KIND)
.withConstValue(new C2ComponentKindSetting(C2Component::KIND_DECODER))
Expand Down Expand Up @@ -226,6 +233,11 @@ MfxC2DecoderComponent::MfxC2DecoderComponent(const C2String name, const CreateCo
.build());

m_consumerUsage = C2AndroidMemoryUsage::FromGrallocUsage(kDefaultConsumerUsage).expected;
// We need these flags in the case of hybrid GPU.
if (m_needCpuAccess) {
m_consumerUsage |= C2AndroidMemoryUsage::CPU_READ;
m_consumerUsage |= C2AndroidMemoryUsage::CPU_WRITE;
}
addParameter(
DefineParam(m_outputUsage, C2_PARAMKEY_OUTPUT_STREAM_USAGE)
.withDefault(new C2StreamUsageTuning::output(SINGLE_STREAM_ID, m_consumerUsage))
Expand Down Expand Up @@ -1575,6 +1587,10 @@ void MfxC2DecoderComponent::DoUpdateMfxParam(const std::vector<C2Param*> &params
case kParamIndexUsage: {
if (C2StreamUsageTuning::output::PARAM_TYPE == param->index()) {
m_consumerUsage = m_outputUsage->value;
if (m_needCpuAccess) {
m_consumerUsage |= C2AndroidMemoryUsage::CPU_READ;
m_consumerUsage |= C2AndroidMemoryUsage::CPU_WRITE;
}
// Set memory type according to consumer usage sent from framework
m_mfxVideoParams.IOPattern = (m_consumerUsage & (C2MemoryUsage::CPU_READ | C2MemoryUsage::CPU_WRITE)) ?
MFX_IOPATTERN_OUT_SYSTEM_MEMORY : MFX_IOPATTERN_OUT_VIDEO_MEMORY;
Expand Down
1 change: 1 addition & 0 deletions c2_utils/Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ cc_library_static {
],

shared_libs: [
"libdrm",
"liblog",
"libgralloctypes",
"libstagefright_foundation",
Expand Down
54 changes: 54 additions & 0 deletions c2_utils/include/mfx_intel_device.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright (c) 2024 Intel Corporation
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#pragma once

#include <stdint.h>

enum {
GPU_GRP_TYPE_INTEL_IGPU_IDX = 0,
GPU_GRP_TYPE_INTEL_DGPU_IDX = 1,
GPU_GRP_TYPE_VIRTIO_GPU_BLOB_IDX = 2,
// virtio-GPU with allow-p2p feature, implying its display is backed by dGPU
GPU_GRP_TYPE_VIRTIO_GPU_BLOB_P2P_IDX = 3,
GPU_GRP_TYPE_VIRTIO_GPU_NO_BLOB_IDX = 4,
GPU_GRP_TYPE_VIRTIO_GPU_IVSHMEM_IDX = 5,
GPU_GRP_TYPE_NR,
};

#define GPU_GRP_TYPE_HAS_INTEL_IGPU_BIT (1ull << GPU_GRP_TYPE_INTEL_IGPU_IDX)
#define GPU_GRP_TYPE_HAS_INTEL_DGPU_BIT (1ull << GPU_GRP_TYPE_INTEL_DGPU_IDX)
#define GPU_GRP_TYPE_HAS_VIRTIO_GPU_BLOB_BIT (1ull << GPU_GRP_TYPE_VIRTIO_GPU_BLOB_IDX)
#define GPU_GRP_TYPE_HAS_VIRTIO_GPU_BLOB_P2P_BIT (1ull << GPU_GRP_TYPE_VIRTIO_GPU_BLOB_P2P_IDX)
#define GPU_GRP_TYPE_HAS_VIRTIO_GPU_NO_BLOB_BIT (1ull << GPU_GRP_TYPE_VIRTIO_GPU_NO_BLOB_IDX)
#define GPU_GRP_TYPE_HAS_VIRTIO_GPU_IVSHMEM_BIT (1ull << GPU_GRP_TYPE_VIRTIO_GPU_IVSHMEM_IDX)

#define DRIVER_DEVICE_FEATURE_I915_DGPU (1ull << 1)
#define DRIVER_DEVICE_FEATURE_VIRGL_RESOURCE_BLOB (1ull << 2)
#define DRIVER_DEVICE_FEATURE_VIRGL_QUERY_DEV (1ull << 3)
#define DRIVER_DEVICE_FEATURE_VIRGL_ALLOW_P2P (1ull << 4)

bool isIntelDg2(int fd);
bool isVirtioGpuAllowP2p(int virtgpu_fd);
bool isVirtioGpuPciDevice(int virtgpu_fd);
bool isVirtioGpuWithBlob(int virtgpu_fd);

uint64_t getGpuGroupType();
bool enforceLinearBuffer();
4 changes: 4 additions & 0 deletions c2_utils/src/mfx_c2_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "mfx_c2_utils.h"
#include "mfx_debug.h"
#include "mfx_c2_debug.h"
#include "mfx_intel_device.h"

#include <iomanip>
#include <sys/types.h>
Expand Down Expand Up @@ -573,6 +574,9 @@ int MfxFourCCToGralloc(mfxU32 fourcc, bool using_video_memory)
MFX_DEBUG_TRACE_FUNC;
MFX_DEBUG_TRACE_U32(fourcc);

if (enforceLinearBuffer()) {
using_video_memory = false;
}
switch (fourcc)
{
case MFX_FOURCC_NV12:
Expand Down
Loading

0 comments on commit dd00ed4

Please sign in to comment.