Skip to content

Commit

Permalink
Printing out the GPU DRI path
Browse files Browse the repository at this point in the history
  • Loading branch information
ViktorWalter committed Feb 27, 2024
1 parent 002aa0e commit 6672027
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions include/compute_lib/compute_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,39 +31,41 @@ static void compute_lib_gl_callback(GLenum source, GLenum type, GLuint id, GLenu

int compute_lib_init(compute_lib_instance_t* inst)
{
fprintf(stderr, "[ComputeLib]: Checking if initialized... " );
fprintf(stderr, "[ComputeLib]: Checking if initialized... \n" );
if (inst->initialised == true) {
return COMPUTE_LIB_ERROR_ALREADY_INITIALISED;
}

fprintf(stderr, "[ComputeLib]: Opening GPU DRI PATH... " );
fprintf(stderr, "[ComputeLib]: Opening GPU DRI PATH at [%s]... \n", COMPUTE_LIB_GPU_DRI_PATH );
inst->fd = open(COMPUTE_LIB_GPU_DRI_PATH, O_RDWR);
if (inst->fd <= 0) {
fprintf(stderr, "[ComputeLib]: Opening GPU DRI PATH at [%s] failed!, will deinit... \n", COMPUTE_LIB_GPU_DRI_PATH );
compute_lib_deinit(inst);
fprintf(stderr, "[ComputeLib]: Deinitialized. \n", COMPUTE_LIB_GPU_DRI_PATH );
return COMPUTE_LIB_ERROR_GPU_DRI_PATH;
}

fprintf(stderr, "[ComputeLib]: Creating BGM device... " );
fprintf(stderr, "[ComputeLib]: Creating BGM device... \n" );
inst->gbm = gbm_create_device(inst->fd);
if (inst->gbm == NULL) {
compute_lib_deinit(inst);
return COMPUTE_LIB_ERROR_CREATE_GBM_CTX;
}

fprintf(stderr, "[ComputeLib]: Getting EGL platform display... " );
fprintf(stderr, "[ComputeLib]: Getting EGL platform display... \n" );
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;
}

fprintf(stderr, "[ComputeLib]: Initializing EGL... " );
fprintf(stderr, "[ComputeLib]: Initializing EGL... \n" );
if (!eglInitialize(inst->dpy, NULL, NULL)) {
compute_lib_deinit(inst);
return COMPUTE_LIB_ERROR_EGL_INIT;
}

fprintf(stderr, "[ComputeLib]: Getting EGL extensions... " );
fprintf(stderr, "[ComputeLib]: Getting EGL extensions... \n" );
const char* egl_extension_st = eglQueryString(inst->dpy, EGL_EXTENSIONS);
if (strstr(egl_extension_st, "EGL_KHR_create_context") == NULL) {
compute_lib_deinit(inst);
Expand All @@ -76,25 +78,25 @@ int compute_lib_init(compute_lib_instance_t* inst)

EGLConfig egl_cfg;
EGLint egl_count;
fprintf(stderr, "[ComputeLib]: Choosing EGL config... " );
fprintf(stderr, "[ComputeLib]: Choosing EGL config... \n" );
if (!eglChooseConfig(inst->dpy, egl_config_attribs, &egl_cfg, 1, &egl_count)) {
compute_lib_deinit(inst);
return COMPUTE_LIB_ERROR_EGL_CONFIG;
}
fprintf(stderr, "[ComputeLib]: Binding EGL API... " );
fprintf(stderr, "[ComputeLib]: Binding EGL API... \n" );
if (!eglBindAPI(EGL_OPENGL_ES_API)) {
compute_lib_deinit(inst);
return COMPUTE_LIB_ERROR_EGL_BIND_API;
}

fprintf(stderr, "[ComputeLib]: Crating EGL context... " );
fprintf(stderr, "[ComputeLib]: Crating EGL context... \n" );
inst->ctx = eglCreateContext(inst->dpy, egl_cfg, EGL_NO_CONTEXT, egl_ctx_attribs);
if (inst->ctx == EGL_NO_CONTEXT) {
compute_lib_deinit(inst);
return COMPUTE_LIB_ERROR_EGL_CREATE_CTX;
}

fprintf(stderr, "[ComputeLib]: Making EGL current... " );
fprintf(stderr, "[ComputeLib]: Making EGL current... \n" );
if (!eglMakeCurrent(inst->dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, inst->ctx)) {
compute_lib_deinit(inst);
return COMPUTE_LIB_ERROR_EGL_MAKE_CURRENT;
Expand All @@ -104,12 +106,12 @@ int compute_lib_init(compute_lib_instance_t* inst)
inst->error_total_cnt = 0;
inst->error_queue = queue_create(64);

fprintf(stderr, "[ComputeLib]: Enabling GL output... " );
fprintf(stderr, "[ComputeLib]: Enabling GL output... \n" );
glEnable(GL_DEBUG_OUTPUT);
fprintf(stderr, "[ComputeLib]: Setting message callback... " );
fprintf(stderr, "[ComputeLib]: Setting message callback... \n" );
glDebugMessageCallback(compute_lib_gl_callback, (const void*) inst);

fprintf(stderr, "[ComputeLib]: Initialized... " );
fprintf(stderr, "[ComputeLib]: Initialized... \n" );
inst->initialised = true;

return 0;
Expand Down

0 comments on commit 6672027

Please sign in to comment.