Skip to content

Commit

Permalink
Trying to enable sw rendering if hw is unavailable
Browse files Browse the repository at this point in the history
  • Loading branch information
ViktorWalter committed Feb 28, 2024
1 parent 369f23a commit 84ac7b5
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions include/compute_lib/compute_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ int compute_lib_init(compute_lib_instance_t* inst)
return COMPUTE_LIB_ERROR_ALREADY_INITIALISED;
}

bool use_hw_rendering = true;
if (access(COMPUTE_LIB_GPU_DRI_PATH, F_OK) == 0) {
fprintf(stderr, "[ComputeLib]: Selecting the main renderer path %s\n", COMPUTE_LIB_GPU_DRI_PATH);
inst->fd = open(COMPUTE_LIB_GPU_DRI_PATH, O_RDWR);
Expand All @@ -43,27 +44,42 @@ int compute_lib_init(compute_lib_instance_t* inst)
compute_lib_deinit(inst);
return COMPUTE_LIB_ERROR_GPU_DRI_PATH;
}
} else {
fprintf(stderr, "[ComputeLib]: Opened the renderer.\n");
}
else if (access(COMPUTE_LIB_GPU_DRI_BACKUP_PATH, F_OK) == 0) {
fprintf(stderr, "[ComputeLib]: Selecting the backup renderer path %s\n", COMPUTE_LIB_GPU_DRI_BACKUP_PATH);
inst->fd = open(COMPUTE_LIB_GPU_DRI_BACKUP_PATH, O_RDWR);
if (inst->fd <= 0) {
fprintf(stderr, "[ComputeLib]: Failed to open backup renderer path %s\n", COMPUTE_LIB_GPU_DRI_BACKUP_PATH);
compute_lib_deinit(inst);
return COMPUTE_LIB_ERROR_GPU_DRI_BACKUP_PATH;
}
fprintf(stderr, "[ComputeLib]: Opened the renderer.\n");
}
else {
use_hw_rendering = false;
fprintf(stderr, "[ComputeLib]: Will attempt to use software rendering.\n");
}
fprintf(stderr, "[ComputeLib]: Opened the renderer.\n");

inst->gbm = gbm_create_device(inst->fd);
if (inst->gbm == NULL) {
if (use_hw_rendering){
inst->gbm = gbm_create_device(inst->fd);
if (inst->gbm == NULL) {
compute_lib_deinit(inst);
return COMPUTE_LIB_ERROR_CREATE_GBM_CTX;
}
}

inst->dpy = eglGetPlatformDisplay(EGL_PLATFORM_GBM_MESA, inst->gbm, NULL);
if (inst->dpy == NULL) {
inst->dpy = eglGetPlatformDisplay(EGL_PLATFORM_GBM_MESA, inst->gbm, NULL);
if (inst->dpy == NULL) {
compute_lib_deinit(inst);
return COMPUTE_LIB_ERROR_EGL_PLATFORM_DISPLAY;
}
}
else {
inst->dpy = eglGetPlatformDisplay(EGL_PLATFORM_SURFACELESS_MESA, NULL, NULL);
if (inst->dpy == NULL) {
compute_lib_deinit(inst);
return COMPUTE_LIB_ERROR_EGL_PLATFORM_DISPLAY;
}
}

if (!eglInitialize(inst->dpy, NULL, NULL)) {
Expand Down Expand Up @@ -151,7 +167,7 @@ void compute_lib_deinit(compute_lib_instance_t* inst)
}

inst->initialised = false;
fprintf(stderr, "[ComputeLib]: De-initialized.");
fprintf(stderr, "[ComputeLib]: De-initialized.\n");
}

int compute_lib_error_queue_flush(compute_lib_instance_t* inst, FILE* out)
Expand Down

0 comments on commit 84ac7b5

Please sign in to comment.