Skip to content

Commit

Permalink
Fixed an issue where opening renderD129 will cause a crash
Browse files Browse the repository at this point in the history
Temporarily change to only open renderD128.

Tracked-On: OAM-121112
Signed-off-by: Zhang, YichiX <yichix.zhang@intel.com>
  • Loading branch information
zhangyichix committed Jun 28, 2024
1 parent 68bbe35 commit 753444c
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 57 deletions.
2 changes: 1 addition & 1 deletion _studio/mfx_lib/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ LOCAL_LDFLAGS := $(MFX_LOCAL_LDFLAGS_HW)
LOCAL_CPPFLAGS += -std=c++14

LOCAL_WHOLE_STATIC_LIBRARIES := $(MFX_LOCAL_STATIC_LIBRARIES_HW)
LOCAL_SHARED_LIBRARIES := libva liblog libcutils libdrm
LOCAL_SHARED_LIBRARIES := libva liblog libcutils libdrm libva-android

LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := libmfx-gen
Expand Down
113 changes: 57 additions & 56 deletions _studio/mfx_lib/shared/src/libmfxsw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
#include <fcntl.h>
#include <xf86drm.h>
#include "va/drm/va_drm.h"
#include <va/va_android.h>
#include "va/va_backend.h"
#include "va_drmcommon.h"

#include "mediasdk_version.h"
#include "libmfx_core_factory.h"
Expand Down Expand Up @@ -610,82 +613,80 @@ GetAdapterInfo(mfxU64 adapterId)
return result;
}

#define MFX_VA_ANDROID_DISPLAY_ID 0x18c34078

static bool QueryImplCaps(std::function < bool (VideoCORE&, mfxU32, mfxU32 , mfxU64, const std::vector<bool>& ) > QueryImpls)
{
for (int i = 0; i < 64; ++i)
{
std::string path;

{
mfxU32 vendorId = 0;
std::string path;

path = std::string("/sys/class/drm/renderD") + std::to_string(128 + i) + "/device/vendor";
FILE* file = fopen(path.c_str(), "r");
{
mfxU32 vendorId = 0;

if (!file)
break;
path = std::string("/sys/class/drm/renderD128/device/vendor");
FILE* file = fopen(path.c_str(), "r");

int nread = fscanf(file, "%x", &vendorId);
fclose(file);
if (!file)
return false;

if (nread != 1 || vendorId != 0x8086)
continue;
}
int nread = fscanf(file, "%x", &vendorId);
fclose(file);

mfxU32 deviceId = 0;
{
path = std::string("/sys/class/drm/renderD") + std::to_string(128 + i) + "/device/device";

FILE* file = fopen(path.c_str(), "r");
if (!file)
break;
if (nread != 1 || vendorId != 0x8086)
return false;
}

int nread = fscanf(file, "%x", &deviceId);
fclose(file);
mfxU32 deviceId = 0;
{
path = std::string("/sys/class/drm/renderD128/device/device");

if (nread != 1)
break;
}
FILE* file = fopen(path.c_str(), "r");
if (!file)
return false;

path = std::string("/dev/dri/renderD") + std::to_string(128 + i);
int nread = fscanf(file, "%x", &deviceId);
fclose(file);

int fd = open(path.c_str(), O_RDWR);
if (fd < 0)
continue;
if (nread != 1)
return false;
}

std::shared_ptr<int> closeFile(&fd, [fd](int*) { close(fd); });
{
unsigned int displayId = MFX_VA_ANDROID_DISPLAY_ID;
VADisplay vaDisplay = vaGetDisplay(&displayId);
if (vaDisplay == nullptr)
return false;

{
auto displ = vaGetDisplayDRM(fd);
VADisplayContextP ctx = (VADisplayContextP)vaDisplay;
drm_state* drm = (drm_state*)ctx->pDriverContext->drm_state;
int fd = drm->fd;

int vamajor = 0, vaminor = 0;
if (VA_STATUS_SUCCESS != vaInitialize(displ, &vamajor, &vaminor))
continue;
int vamajor = 0, vaminor = 0;
if (VA_STATUS_SUCCESS != vaInitialize(vaDisplay, &vamajor, &vaminor))
return false;

std::shared_ptr<VADisplay> closeVA(&displ, [displ](VADisplay*) { vaTerminate(displ); });
std::shared_ptr<VADisplay> closeVA(&vaDisplay, [vaDisplay](VADisplay*) { vaTerminate(vaDisplay); });

VADisplayAttribute attr = {};
attr.type = VADisplayAttribSubDevice;
auto sts = vaGetDisplayAttributes(displ, &attr, 1);
std::ignore = MFX_STS_TRACE(sts);
VADisplayAttribute attr = {};
attr.type = VADisplayAttribSubDevice;
auto sts = vaGetDisplayAttributes(vaDisplay, &attr, 1);
std::ignore = MFX_STS_TRACE(sts);

VADisplayAttribValSubDevice out = {};
out.value = attr.value;
VADisplayAttribValSubDevice out = {};
out.value = attr.value;

std::vector<bool> subDevMask(VA_STATUS_SUCCESS == sts ? out.bits.sub_device_count : 0);
for (std::size_t id = 0; id < subDevMask.size(); ++id)
{
subDevMask[id] = !!((1 << id) & out.bits.sub_device_mask);
}
{
std::unique_ptr<VideoCORE> pCore(FactoryCORE::CreateCORE(MFX_HW_VAAPI, 0, {}, 0));
std::vector<bool> subDevMask(VA_STATUS_SUCCESS == sts ? out.bits.sub_device_count : 0);
for (std::size_t id = 0; id < subDevMask.size(); ++id)
{
subDevMask[id] = !!((1 << id) & out.bits.sub_device_mask);
}
{
std::unique_ptr<VideoCORE> pCore(FactoryCORE::CreateCORE(MFX_HW_VAAPI, 0, {}, 0));

if (pCore->SetHandle(MFX_HANDLE_VA_DISPLAY, (mfxHDL)displ))
continue;
if (pCore->SetHandle(MFX_HANDLE_VA_DISPLAY, (mfxHDL)vaDisplay))
return false;

if (!QueryImpls(*pCore, deviceId, i, fd, subDevMask))
return false;
}
if (!QueryImpls(*pCore, deviceId, 0, fd, subDevMask))
return false;
}
}
return true;
Expand Down

0 comments on commit 753444c

Please sign in to comment.