Graphics interop calls fails

Hey,

I’ve been trying to make an OpenGL application to work with ANGLE-backend and Nvenc encoder without moving the frame from the gpu.

This works great using the bundled libGLESv2 library (which I’m unsure how to check which it is) that comes bundled with Manjaro, however when I try to use the ANGLE one cuGraphicsGLRegisterImage fails
with an CU_INVALID_VALUE error.

The project I’m working on is trying to translate web-graphics to native, so I want to be able to use ANGLE (which is the back-end for most of the web browsers graphics).

Both the cuDeviceGet and cuCtxCreate_v2 work with ANGLE, however the cuGraphicsGLRegisterImage call
fails.

... Set up EGL/openGL context to use OpenGL ES 3 with OpenGL backend

// Set up cuda
cuInit(0);
std::string gpuName = getDeviceName();
CUdevice pCudaDevice;
    
int device_index = strtol(gpuName.c_str(), NULL, 0);
CUresult res = cuDeviceGet(&pCudaDevice, device_index);
if (res != 0) {
   std::cout << "Error getting devices" << std::endl;
}
    
res = cuCtxCreate_v2(&m_cuContext, CU_CTX_SCHED_BLOCKING_SYNC); 
if(res != 0) {
   std::cout << "error creating context" << std::endl;
   return -1;
}
// Generate texture for cuda to copy from
GLuint texture;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, screenWidth, screenHeight, 0, GL_RED, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glBindTexture(GL_TEXTURE_2D, 0);

GLuint fbo;
glGenFramebuffers(1, &fbo);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);

// Register image
CUcontext oldCtx;
res = cuCtxPopCurrent_v2(&oldCtx); // THIS IS ALLOWED TO FAIL
res = cuCtxPushCurrent_v2(m_cuContext);

res = cuGraphicsGLRegisterImage(&cuInpTexRes, texture, GL_TEXTURE_2D, CU_GRAPHICS_REGISTER_FLAGS_READ_ONLY);
if(res != 0) {
   std::cout << "Error registering GL Image, error value: " << res << std::endl;
} else {
   std::cout << "Registering succeeded" <<  std::endl;
}

Anyone have a pointer to what is going wrong?

Nvm found it…

jk, the calls from ANGLE didn’t return the native texture ID’s used by OpenGL. This can be solved using the GL_ANGLE_texture_external_update extension which allows to query the native ID using

GLint native_id;
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_NATIVE_ID_ANGLE, &native_id);