Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register OpenGL buffer for interoperability? #90

Open
TomClabault opened this issue Apr 20, 2024 · 1 comment
Open

Register OpenGL buffer for interoperability? #90

TomClabault opened this issue Apr 20, 2024 · 1 comment

Comments

@TomClabault
Copy link

How can I register an OpenGL buffer for use in my CUDA/HIP kernel?

oroGraphicsMapResources(int count, oroGraphicsResource_t * resources, oroStream_t stream) expects a registered resource as its second parameter but there is no oroGraphicsRegisterX functions (although oroGraphicsUnregisterResource exists). I would expect the oroGraphicsGLRegisterBuffer and oroGraphicsGLRegisterImage functions to be present in Orochi API but there are no such functions.

The DX12 example of this repo doesn't really help as it uses a sharedHandle created specifically with the DX12 API:

oroExternalMemoryHandleDesc externalMemoryHandleDesc;
externalMemoryHandleDesc.type = oroExternalMemoryHandleTypeD3D12Resource;
externalMemoryHandleDesc.handle.win32.handle = sharedHandle;
externalMemoryHandleDesc.size = actualSize;
externalMemoryHandleDesc.flags = ORO_EXTERNAL_MEMORY_DEDICATED;

oroImportExternalMemory(&gOroExtMem, &externalMemoryHandleDesc);

Is it somehow possible to adapt this example for OpenGL buffers or is there something simpler I missed in Orochi's API?

@TomClabault
Copy link
Author

TomClabault commented Apr 21, 2024

I tried doing it with HIP (not Orochi), but I still cannot get past hipGraphicsGLRegisterBuffer:

#include "GL/glew.h"
#include "GLFW/glfw3.h"
#include "Orochi/Orochi.h"

#include <iostream>

int main()
{
	glfwInit();
	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
	GLFWwindow* window = glfwCreateWindow(1280, 720, "Test OpenGL Interop", NULL, NULL);
	glfwMakeContextCurrent(window);

	glewInit();

	oroInitialize(oroApi::ORO_API_HIP, 0);
	oroInit(0);

	GLuint buffer;
	glGenBuffers(1, &buffer);
	glBindBuffer(GL_ARRAY_BUFFER, buffer);
	glBufferData(GL_ARRAY_BUFFER, 1024, nullptr, GL_DYNAMIC_DRAW);

	hipGraphicsResource* buffer_resource;
	if (hipGraphicsGLRegisterBuffer(&buffer_resource, buffer, hipGraphicsRegisterFlagsNone) != hipSuccess)
	{
		std::cerr << hipGetErrorString(hipGetLastError()) << std::endl;
		return 3;
	}

	return 0;
}

The above piece of code prints "invalid argument" as hipGraphicsGLRegisterBuffer returns an hipErrorInvalidValue error.

I also tried textures with hipGraphicsGLRegisterImage but I got the exact same issue.

EDIT:

Calling hipGLGetDevices before hipGraphicsGLRegisterImage has the RegisterImage call working for this simple example main(). What is happening?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant