# Here we reinterpret it as a UInt32 CuArray.ĭeviceptr = reinterpret(CuPtr() # Here we get a CUDA pointer to the graphics resource.ĬUDA.cuGraphicsResourceGetMappedPointer_v2(deviceptrref, numbytesref, resource) # This allows us to write to the Pixel Buffer Object from CUDA.ĬUDA.cuGraphicsMapResources(1,, stream()) # - cuGraphicsResourceGetMappedPointer_v2 # See the NVIDIA CUDA documentation for more info about what the methods # The pixel values will then end up in the texture buffer, as far as I understand. # This graphics resource can be sent into the CUDA kernel above, as a UInt32 array # Here we map a Pixel Buffer Object (PBO) in OpenGL to a CUDA "graphics resource". Vec4 texel = texture(basic_texture, texture_coordinates) Gl_Position = vec4(vertex_position, 1.0) Layout (location = 1) in vec2 vt // per-vertex texture co-ords Layout (location = 0) in vec3 vertex_position # to the triangles we display on the screen. # The vertex and fragment shaders are OpenGL shaders that map the texture # and the array is of course 1-indexed, so add 1. # The pixel array is 1D, so figure out the index of this pixel Isoddblock = (blockIdx().x + blockIdx().y) % 2 = 0 # so R is the least significant byte, and A is the most significant, Row = threadIdx().y - 1 + blockDim().x * (blockIdx().y - 1) # Even thread blocks are red and odd blocks are black.Ĭolumn = threadIdx().x - 1 + blockDim().x * (blockIdx().x - 1) # A GitHub repository for the source code for the book CUDA For Engineers: # All of this was pieced together from different sources: # This should only require the Julia packages # The CUDA kernel then writes pixels to that texture. # two triangles, and maps a texture onto this rectangle. # Essentially, this OpenGL code creates a rectangle out of # I have no idea about how effective a method it is. # This is the first successful attempt I made at this, so # A CUDA kernel writes pixel color values to a texture, Here is the actual code: # A self-contained example of CUDA/OpenGL interoperability. GitHub - JuliaGL/GLFW.jl: Julia interface to GLFW, a multi-platform library for creating windows with OpenGL contexts and managing input and events. Videre/OpenGL 4 Tutorials/09_texture_mapping at master Programming Guide :: CUDA Toolkit DocumentationĪ GitHub repository for the source code for the book CUDA For Engineers: I pieced it together from a number of different sources: I believe it only requires these packages: ] add CUDA ModernGL GLFW I get the feeling that trying to do CUDA/OpenGL interop the way I want is abuse of OpenGL, so maybe there’s no good way of doing it. My naive thought is that one ought to be able to write directly to whatever buffer GLFWĬreated for us, but I don’t know if that would actually be possible. I have no idea if this is the correct way, or even remotely efficient way, but it was the first thing I got working. ![]()
0 Comments
Leave a Reply. |