Skip to content

Commit 8a1e66e

Browse files
committed
Enable dGPU for decoder and encoder
1\ Enable ONEVPL_EXPERIMENTAL for init dGPU session and get deviceId 2\ According to device id to judge if it is dGPU or iGPU 3\ dGPU deviceid range: 0x5600 < deviceId < 0x56B3 4\ After initializing dGPU, reset RateControl for dGPU. 5\ Set buffer Tile4 for dGPU and Y-Tile for iGPU Tracked-On: OAM-112744 Signed-off-by: Shaofeng Tang <[email protected]>
1 parent 6459655 commit 8a1e66e

File tree

10 files changed

+196
-8
lines changed

10 files changed

+196
-8
lines changed

c2_components/Android.bp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ cc_library_shared {
7676
],
7777

7878
cflags: [
79-
79+
"-DONEVPL_EXPERIMENTAL", // For enable dGPU
8080
],
8181

8282
vendor: true,
83-
}
83+
}

c2_components/include/mfx_c2_component.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ class MfxC2Component : public C2ComponentInterface,
8484

8585
public:
8686
virtual ~MfxC2Component();
87+
#ifdef ONEVPL_EXPERIMENTAL
88+
bool isdGPU() { return dedicated;}
89+
#endif
8790

8891
private: // Non-virtual interface methods optionally overridden in descendants
8992
virtual c2_status_t Init() = 0;
@@ -174,6 +177,16 @@ class MfxC2Component : public C2ComponentInterface,
174177

175178
std::unique_lock<std::mutex> AcquireRunningStateLock(bool may_block) const;
176179

180+
#ifdef ONEVPL_EXPERIMENTAL
181+
void detectdGPU(mfxU16 deviceId) {
182+
// DG2 paiid from kernel/include/drm/i915_pciids.h#696
183+
if (deviceId >= 0x5690 && deviceId <= 0x56B3)
184+
dedicated = true;
185+
else
186+
dedicated = false;
187+
}
188+
#endif
189+
177190
private:
178191
c2_status_t CheckStateTransitionConflict(
179192
const std::unique_lock<std::mutex>& state_lock,
@@ -200,6 +213,10 @@ class MfxC2Component : public C2ComponentInterface,
200213
std::list<std::shared_ptr<Listener>> m_listeners;
201214

202215
std::mutex m_listenersMutex;
216+
217+
#ifdef ONEVPL_EXPERIMENTAL
218+
bool dedicated = false;
219+
#endif
203220
};
204221

205222
typedef MfxC2Component* (CreateMfxC2ComponentFunc)(const char* name,

c2_components/src/mfx_c2_decoder_component.cpp

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -874,8 +874,8 @@ mfxStatus MfxC2DecoderComponent::InitSession()
874874
MFX_DEBUG_TRACE_FUNC;
875875

876876
mfxStatus mfx_res = MFX_ERR_NONE;
877-
mfxConfig cfg[2];
878-
mfxVariant cfgVal[2];
877+
mfxConfig cfg[3];
878+
mfxVariant cfgVal[3];
879879

880880
if (nullptr == m_mfxLoader)
881881
m_mfxLoader = MFXLoad();
@@ -918,6 +918,22 @@ mfxStatus MfxC2DecoderComponent::InitSession()
918918
return MFX_ERR_UNKNOWN;
919919
}
920920

921+
cfg[2] = MFXCreateConfig(m_mfxLoader);
922+
if (!cfg[2]) {
923+
ALOGE("Failed to create a MFX configuration");
924+
MFXUnload(m_mfxLoader);
925+
return MFX_ERR_UNKNOWN;
926+
}
927+
928+
cfgVal[2].Type = MFX_VARIANT_TYPE_U32;
929+
cfgVal[2].Data.U32 = DRM_RENDER_NODE_NUM;
930+
mfx_res = MFXSetConfigFilterProperty(cfg[2], (const mfxU8 *) "mfxExtendedDeviceId.DRMRenderNodeNum", cfgVal[2]);
931+
if (MFX_ERR_NONE != mfx_res) {
932+
ALOGE("Failed to add an additional MFX configuration (%d)", mfx_res);
933+
MFXUnload(m_mfxLoader);
934+
return MFX_ERR_UNKNOWN;
935+
}
936+
921937
while (1) {
922938
/* Enumerate all implementations */
923939
uint32_t idx = 0;
@@ -940,7 +956,56 @@ mfxStatus MfxC2DecoderComponent::InitSession()
940956

941957
mfx_res = MFXCreateSession(m_mfxLoader, idx, &m_mfxSession);
942958

959+
MFX_LOG_INFO("ApiVersion: %hu.%hu ",
960+
idesc->ApiVersion.Major,
961+
idesc->ApiVersion.Minor);
962+
MFX_LOG_INFO(" Implementation type: %s\n",
963+
(idesc->Impl == MFX_IMPL_TYPE_SOFTWARE) ? "SW" : "HW");
964+
MFX_LOG_INFO("%2sApiVersion.Major: 0x%04X\n", "", idesc->ApiVersion.Major);
965+
MFX_LOG_INFO("%2sApiVersion.Minor: 0x%04X\n", "", idesc->ApiVersion.Minor);
966+
MFX_LOG_INFO("%2sImplementation Name: %s\n", "", idesc->ImplName);
967+
MFX_LOG_INFO("%2sLicense: %s\n", "", idesc->License);
968+
MFX_LOG_INFO("%2sKeywords: %s\n", "", idesc->Keywords);
969+
MFX_LOG_INFO("%2sVendorID: 0x%04X\n", "", idesc->VendorID);
970+
MFX_LOG_INFO("%2sVendorImplID: 0x%04X\n", "", idesc->VendorImplID);
971+
943972
MFXDispReleaseImplDescription(m_mfxLoader, idesc);
973+
#ifdef ONEVPL_EXPERIMENTAL
974+
mfxExtendedDeviceId* idescDevice;
975+
976+
mfx_res = MFXEnumImplementations(m_mfxLoader,
977+
0,
978+
MFX_IMPLCAPS_DEVICE_ID_EXTENDED,
979+
reinterpret_cast<mfxHDL*>(&idescDevice));
980+
if (MFX_ERR_NONE != mfx_res) {
981+
ALOGE("MFXEnumImplementations MFX_IMPLCAPS_DEVICE_ID_EXTENDED error=%d\n", mfx_res);
982+
}
983+
else {
984+
MFX_LOG_INFO("%6sDeviceName: %s\n", "", idescDevice->DeviceName);
985+
MFX_LOG_INFO("%6sExtended DeviceID's:\n", "");
986+
MFX_LOG_INFO("%6sVendorID: 0x%04X\n", "", idescDevice->VendorID);
987+
MFX_LOG_INFO("%6sDeviceID: 0x%04X\n", "", idescDevice->DeviceID);
988+
MFX_LOG_INFO("%6sPCIDomain: 0x%08X\n", "", idescDevice->PCIDomain);
989+
MFX_LOG_INFO("%6sPCIBus: 0x%08X\n", "", idescDevice->PCIBus);
990+
MFX_LOG_INFO("%6sPCIdevice: 0x%08X\n", "", idescDevice->PCIDevice);
991+
MFX_LOG_INFO("%6sPCIFunction: 0x%08X\n", "", idescDevice->PCIFunction);
992+
MFX_LOG_INFO("%6sDRMRenderNodeNum: %d\n", "", idescDevice->DRMRenderNodeNum);
993+
MFX_LOG_INFO("%6sDRMPrimaryNodeNum: 0x%04X\n", "", idescDevice->DRMPrimaryNodeNum);
994+
MFX_LOG_INFO("%6sLUIDValid: 0x%04X\n", "", idescDevice->LUIDValid);
995+
996+
detectdGPU(idescDevice->DeviceID);
997+
998+
if (idescDevice->LUIDValid) {
999+
MFX_LOG_INFO("%6sDeviceLUID: ", "");
1000+
for (mfxU32 idx = 0; idx < 8; idx++) {
1001+
MFX_LOG_INFO("%02x", idescDevice->DeviceLUID[7 - idx]);
1002+
}
1003+
MFX_LOG_INFO("%6sLUIDDeviceNodeMask: 0x%04X\n", "", idescDevice->LUIDDeviceNodeMask);
1004+
}
1005+
}
1006+
1007+
MFXDispReleaseImplDescription(m_mfxLoader, idescDevice);
1008+
#endif
9441009

9451010
if (MFX_ERR_NONE == mfx_res)
9461011
break;
@@ -957,6 +1022,9 @@ mfxStatus MfxC2DecoderComponent::InitSession()
9571022
return mfx_res;
9581023
}
9591024

1025+
#ifdef ONEVPL_EXPERIMENTAL
1026+
m_device->setDedicated(isdGPU());
1027+
#endif
9601028
mfx_res = m_device->InitMfxSession(m_mfxSession);
9611029

9621030
MFX_DEBUG_TRACE__mfxStatus(mfx_res);

c2_components/src/mfx_c2_encoder_component.cpp

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,15 @@ c2_status_t MfxC2EncoderComponent::Init()
523523

524524
if(mfx_res == MFX_ERR_NONE) mfx_res = InitSession();
525525

526+
// Need to reset the RateControlMethod according to HW Capability
527+
// Here is a WA to set RateControlMethod depend on iGPU or dGPU
528+
if(mfx_res == MFX_ERR_NONE) {
529+
if (isdGPU())
530+
mfx_set_RateControlMethod(MFX_RATECONTROL_CQP, &m_mfxVideoParamsConfig);
531+
else
532+
mfx_set_RateControlMethod(MFX_RATECONTROL_CBR, &m_mfxVideoParamsConfig);
533+
}
534+
526535
return MfxStatusToC2(mfx_res);
527536
}
528537

@@ -678,8 +687,8 @@ mfxStatus MfxC2EncoderComponent::InitSession()
678687
MFX_DEBUG_TRACE_FUNC;
679688

680689
mfxStatus mfx_res = MFX_ERR_NONE;
681-
mfxConfig cfg[2];
682-
mfxVariant cfgVal[2];
690+
mfxConfig cfg[3];
691+
mfxVariant cfgVal[3];
683692

684693
if (nullptr == m_mfxLoader)
685694
m_mfxLoader = MFXLoad();
@@ -722,6 +731,22 @@ mfxStatus MfxC2EncoderComponent::InitSession()
722731
return MFX_ERR_UNKNOWN;
723732
}
724733

734+
cfg[2] = MFXCreateConfig(m_mfxLoader);
735+
if (!cfg[2]) {
736+
ALOGE("Failed to create a MFX configuration");
737+
MFXUnload(m_mfxLoader);
738+
return MFX_ERR_UNKNOWN;
739+
}
740+
741+
cfgVal[2].Type = MFX_VARIANT_TYPE_U32;
742+
cfgVal[2].Data.U32 = DRM_RENDER_NODE_NUM;
743+
mfx_res = MFXSetConfigFilterProperty(cfg[2], (const mfxU8 *) "mfxExtendedDeviceId.DRMRenderNodeNum", cfgVal[2]);
744+
if (MFX_ERR_NONE != mfx_res) {
745+
ALOGE("Failed to add an additional MFX configuration (%d)", mfx_res);
746+
MFXUnload(m_mfxLoader);
747+
return MFX_ERR_UNKNOWN;
748+
}
749+
725750
while (1) {
726751
/* Enumerate all implementations */
727752
uint32_t idx = 0;
@@ -744,8 +769,58 @@ mfxStatus MfxC2EncoderComponent::InitSession()
744769

745770
mfx_res = MFXCreateSession(m_mfxLoader, idx, &m_mfxSession);
746771

772+
MFX_LOG_INFO("ApiVersion: %hu.%hu ",
773+
idesc->ApiVersion.Major,
774+
idesc->ApiVersion.Minor);
775+
MFX_LOG_INFO(" Implementation type: %s\n",
776+
(idesc->Impl == MFX_IMPL_TYPE_SOFTWARE) ? "SW" : "HW");
777+
MFX_LOG_INFO("%2sApiVersion.Major: 0x%04X\n", "", idesc->ApiVersion.Major);
778+
MFX_LOG_INFO("%2sApiVersion.Minor: 0x%04X\n", "", idesc->ApiVersion.Minor);
779+
MFX_LOG_INFO("%2sImplementation Name: %s\n", "", idesc->ImplName);
780+
MFX_LOG_INFO("%2sLicense: %s\n", "", idesc->License);
781+
MFX_LOG_INFO("%2sKeywords: %s\n", "", idesc->Keywords);
782+
MFX_LOG_INFO("%2sVendorID: 0x%04X\n", "", idesc->VendorID);
783+
MFX_LOG_INFO("%2sVendorImplID: 0x%04X\n", "", idesc->VendorImplID);
784+
747785
MFXDispReleaseImplDescription(m_mfxLoader, idesc);
748786

787+
#ifdef ONEVPL_EXPERIMENTAL
788+
mfxExtendedDeviceId* idescDevice;
789+
790+
mfx_res = MFXEnumImplementations(m_mfxLoader,
791+
0,
792+
MFX_IMPLCAPS_DEVICE_ID_EXTENDED,
793+
reinterpret_cast<mfxHDL*>(&idescDevice));
794+
if (MFX_ERR_NONE != mfx_res) {
795+
ALOGE("MFXEnumImplementations MFX_IMPLCAPS_DEVICE_ID_EXTENDED error=%d\n", mfx_res);
796+
}
797+
else {
798+
MFX_LOG_INFO("%6sDeviceName: %s\n", "", idescDevice->DeviceName);
799+
MFX_LOG_INFO("%6sExtended DeviceID's:\n", "");
800+
MFX_LOG_INFO("%6sVendorID: 0x%04X\n", "", idescDevice->VendorID);
801+
MFX_LOG_INFO("%6sDeviceID: 0x%04X\n", "", idescDevice->DeviceID);
802+
MFX_LOG_INFO("%6sPCIDomain: 0x%08X\n", "", idescDevice->PCIDomain);
803+
MFX_LOG_INFO("%6sPCIBus: 0x%08X\n", "", idescDevice->PCIBus);
804+
MFX_LOG_INFO("%6sPCIdevice: 0x%08X\n", "", idescDevice->PCIDevice);
805+
MFX_LOG_INFO("%6sPCIFunction: 0x%08X\n", "", idescDevice->PCIFunction);
806+
MFX_LOG_INFO("%6sDRMRenderNodeNum: %d\n", "", idescDevice->DRMRenderNodeNum);
807+
MFX_LOG_INFO("%6sDRMPrimaryNodeNum: 0x%04X\n", "", idescDevice->DRMPrimaryNodeNum);
808+
MFX_LOG_INFO("%6sLUIDValid: 0x%04X\n", "", idescDevice->LUIDValid);
809+
810+
detectdGPU(idescDevice->DeviceID);
811+
812+
if (idescDevice->LUIDValid) {
813+
MFX_LOG_INFO("%6sDeviceLUID: ", "");
814+
for (mfxU32 idx = 0; idx < 8; idx++) {
815+
MFX_LOG_INFO("%02x", idescDevice->DeviceLUID[7 - idx]);
816+
}
817+
MFX_LOG_INFO("%6sLUIDDeviceNodeMask: 0x%04X\n", "", idescDevice->LUIDDeviceNodeMask);
818+
}
819+
}
820+
821+
MFXDispReleaseImplDescription(m_mfxLoader, idescDevice);
822+
#endif
823+
749824
if (MFX_ERR_NONE == mfx_res)
750825
break;
751826

@@ -760,6 +835,9 @@ mfxStatus MfxC2EncoderComponent::InitSession()
760835
return mfx_res;
761836
}
762837

838+
#ifdef ONEVPL_EXPERIMENTAL
839+
m_device->setDedicated(isdGPU());
840+
#endif
763841
mfx_res = m_device->InitMfxSession(m_mfxSession);
764842

765843
MFX_DEBUG_TRACE__mfxStatus(mfx_res);

c2_utils/Android.bp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ cc_library_static {
4343
],
4444

4545
cflags: [
46+
"-DONEVPL_EXPERIMENTAL"
4647
//"-DMFX_BUFFER_QUEUE"
4748
],
4849

c2_utils/include/mfx_defs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353

5454
extern mfxVersion g_required_mfx_version;
5555

56+
#define DRM_RENDER_NODE_NUM 128
57+
5658
#ifdef LIBVA_SUPPORT
5759
#include <va/va.h>
5860
#endif // #ifdef LIBVA_SUPPORT

c2_utils/include/mfx_dev.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,11 @@ class MfxDev
5454
virtual mfxStatus InitMfxSession(MFXVideoSession* session) = 0;
5555
#endif
5656
static mfxStatus Create(Usage usage, std::unique_ptr<MfxDev>* device);
57+
58+
#ifdef ONEVPL_EXPERIMENTAL
59+
bool isDedicated() { return dedicated; }
60+
void setDedicated(bool dGPU) { dedicated = dGPU; }
61+
private:
62+
bool dedicated = false;
63+
#endif
5764
};

c2_utils/include/mfx_va_allocator.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ class MfxVaFrameAllocator : public MfxFrameAllocator, public MfxFrameConverter
4646
MfxVaFrameAllocator(VADisplay dpy);
4747
virtual ~MfxVaFrameAllocator();
4848

49+
#ifdef ONEVPL_EXPERIMENTAL
50+
bool isDedicated() { return dedicated; }
51+
void setDedicated(bool dGPU) { dedicated = dGPU; }
52+
#endif
53+
4954
private: // MfxFrameAllocator
5055
virtual mfxStatus AllocFrames(mfxFrameAllocRequest *request, mfxFrameAllocResponse *response) override;
5156
virtual mfxStatus FreeFrames(mfxFrameAllocResponse *response) override;
@@ -85,6 +90,10 @@ class MfxVaFrameAllocator : public MfxFrameAllocator, public MfxFrameConverter
8590

8691
std::mutex m_mutex;
8792

93+
#ifdef ONEVPL_EXPERIMENTAL
94+
bool dedicated = false;
95+
#endif
96+
8897
std::map<uint64_t, std::unique_ptr<VaMemIdAllocated, VaMemIdDeleter>>
8998
m_mappedVaSurfaces;
9099

c2_utils/src/mfx_dev_va.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,16 @@ mfxStatus MfxDevVa::InitMfxSession(MFXVideoSession* session)
200200
std::shared_ptr<MfxFrameAllocator> MfxDevVa::GetFrameAllocator()
201201
{
202202
MFX_DEBUG_TRACE_FUNC;
203+
if (m_usage == Usage::Encoder && isDedicated())
204+
m_vaAllocator->setDedicated(isDedicated());
203205
return m_usage == Usage::Decoder ? m_vaPoolAllocator : m_vaAllocator;
204206
}
205207

206208
std::shared_ptr<MfxFrameConverter> MfxDevVa::GetFrameConverter()
207209
{
208210
MFX_DEBUG_TRACE_FUNC;
211+
if (m_usage == Usage::Encoder && isDedicated())
212+
m_vaAllocator->setDedicated(isDedicated());
209213
return m_usage == Usage::Decoder ? m_vaPoolAllocator : m_vaAllocator;
210214
}
211215

c2_utils/src/mfx_va_allocator.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,10 +606,12 @@ mfxStatus MfxVaFrameAllocator::CreateSurfaceFromGralloc(const IMfxGrallocModule:
606606
desc.objects[0].fd = info.prime;
607607
desc.objects[0].size = decode_target ? info.pitches[0] * ((height + 31) & ~31) * 1.5 : info.pitches[0] * ((height + 15) & ~15) * 1.5;
608608
if (HAL_PIXEL_FORMAT_NV12_Y_TILED_INTEL == info.format || HAL_PIXEL_FORMAT_P010_INTEL == info.format)
609-
desc.objects[0].drm_format_modifier = I915_FORMAT_MOD_Y_TILED;
609+
if (isDedicated())
610+
desc.objects[0].drm_format_modifier = I915_FORMAT_MOD_4_TILED;
611+
else
612+
desc.objects[0].drm_format_modifier = I915_FORMAT_MOD_Y_TILED;
610613
else
611614
desc.objects[0].drm_format_modifier = DRM_FORMAT_MOD_LINEAR;
612-
//desc.objects[0].drm_format_modifier = I915_FORMAT_MOD_4_TILED;
613615
desc.num_layers = 1;
614616
desc.layers[0].drm_format = ConvertVAFourccToDrmFormat(va_fourcc);
615617
desc.layers[0].num_planes = info.planes_count;

0 commit comments

Comments
 (0)