Skip to content

Commit

Permalink
Added check for 16-bit surface driver support
Browse files Browse the repository at this point in the history
  • Loading branch information
elFarto committed Jan 30, 2022
1 parent e7e6ca9 commit 15d5a10
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
22 changes: 21 additions & 1 deletion src/export-buf.c
Expand Up @@ -152,7 +152,6 @@ static int findCudaDisplay(EGLDisplay *eglDisplay) {
//this ioctl should fail if modeset=0
struct drm_get_cap caps = { .capability = DRM_CAP_DUMB_BUFFER };
int ret = ioctl(fd, DRM_IOCTL_GET_CAP, &caps);
LOG("Got DRM_IOCTL_GET_CAP ioctl response: %d %d", ret, caps.value);
close(fd);
if (ret != 0) {
//the modeset parameter is set to 0
Expand Down Expand Up @@ -188,6 +187,7 @@ bool initExporter(NVDriver *drv) {
eglStreamImageConsumerConnectNV = (PFNEGLSTREAMIMAGECONSUMERCONNECTNVPROC) eglGetProcAddress("eglStreamImageConsumerConnectNV");
eglQueryDeviceStringEXT = (PFNEGLQUERYDEVICESTRINGEXTPROC) eglGetProcAddress("eglQueryDeviceStringEXT");

PFNEGLQUERYDMABUFFORMATSEXTPROC eglQueryDmaBufFormatsEXT = (PFNEGLQUERYDMABUFFORMATSEXTPROC) eglGetProcAddress("eglQueryDmaBufFormatsEXT");
PFNEGLDEBUGMESSAGECONTROLKHRPROC eglDebugMessageControlKHR = (PFNEGLDEBUGMESSAGECONTROLKHRPROC) eglGetProcAddress("eglDebugMessageControlKHR");

int ret = findCudaDisplay(&drv->eglDisplay);
Expand All @@ -206,6 +206,26 @@ bool initExporter(NVDriver *drv) {
//setup debug logging
eglDebugMessageControlKHR(debug, debugAttribs);

//see if the driver supports 16-bit exports
EGLint formats[64];
EGLint formatCount;
if (eglQueryDmaBufFormatsEXT(drv->eglDisplay, 64, formats, &formatCount)) {
bool r16 = false, rg1616 = false;
for (int i = 0; i < formatCount; i++) {
if (formats[i] == DRM_FORMAT_R16) {
r16 = true;
} else if (formats[i] == DRM_FORMAT_RG1616) {
rg1616 = true;
}
}
drv->supports16BitSurface = r16 & rg1616;
if (drv->supports16BitSurface) {
LOG("Driver supports 16-bit surfaces");
} else {
LOG("Driver doesn't support 16-bit surfaces");
}
}

reconnect(drv);

return true;
Expand Down
11 changes: 6 additions & 5 deletions src/vabackend.c
Expand Up @@ -398,6 +398,7 @@ static VAStatus nvGetConfigAttributes(
int num_attribs
)
{
NVDriver *drv = (NVDriver*) ctx->pDriverData;
if (vaToCuCodec(profile) == cudaVideoCodec_NONE) {
return VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
}
Expand All @@ -408,7 +409,7 @@ static VAStatus nvGetConfigAttributes(
{
attrib_list[i].value = VA_RT_FORMAT_YUV420;

if (profile == VAProfileHEVCMain10) {
if (drv->supports16BitSurface && profile == VAProfileHEVCMain10) {
attrib_list[i].value |= VA_RT_FORMAT_YUV420_10;
}
}
Expand Down Expand Up @@ -466,7 +467,7 @@ static VAStatus nvCreateConfig(
cfg->cudaCodec = cudaCodec;

//these should be set from the attributes, or a default if the user doesn't care
if (profile == VAProfileHEVCMain10) {
if (drv->supports16BitSurface && profile == VAProfileHEVCMain10) {
cfg->surfaceFormat = cudaVideoSurfaceFormat_P016;
cfg->chromaFormat = cudaVideoChromaFormat_420;
cfg->bitDepth = 10;
Expand Down Expand Up @@ -511,7 +512,7 @@ static VAStatus nvQueryConfigAttributes(
int i = 0;
attrib_list[i].type = VAConfigAttribRTFormat;
attrib_list[i].value = VA_RT_FORMAT_YUV420;
if (cfg->profile == VAProfileHEVCMain10) {
if (drv->supports16BitSurface && cfg->profile == VAProfileHEVCMain10) {
attrib_list[i].value |= VA_RT_FORMAT_YUV420_10;
}
i++;
Expand Down Expand Up @@ -1352,9 +1353,9 @@ static VAStatus nvQuerySurfaceAttributes(
attrib_list[0].value.type = VAGenericValueTypeInteger;

if (cfg->chromaFormat == cudaVideoChromaFormat_420) {
if (cfg->bitDepth == 10 && (videoDecodeCaps.nOutputFormatMask & 2)) {
if (drv->supports16BitSurface && cfg->bitDepth == 10 && (videoDecodeCaps.nOutputFormatMask & 2)) {
attrib_list[0].value.value.i = VA_FOURCC_P010;
} else if (cfg->bitDepth == 12 && (videoDecodeCaps.nOutputFormatMask & 2)) {
} else if (drv->supports16BitSurface && cfg->bitDepth == 12 && (videoDecodeCaps.nOutputFormatMask & 2)) {
attrib_list[0].value.value.i = VA_FOURCC_P012;
} else if (videoDecodeCaps.nOutputFormatMask & 1) {
attrib_list[0].value.value.i = VA_FOURCC_NV12;
Expand Down
1 change: 1 addition & 0 deletions src/vabackend.h
Expand Up @@ -85,6 +85,7 @@ typedef struct
CUeglStreamConnection cuStreamConnection;
int numFramesPresented;
bool useCorrectNV12Format;
bool supports16BitSurface;
NVEGLImage *allocatedEGLImages;
int surfaceCount;
} NVDriver;
Expand Down

0 comments on commit 15d5a10

Please sign in to comment.