Sign in to follow this  
Chris_F

OpenGL OpenGL and unified address space

Recommended Posts

Chris_F    3030
Supposedly new and upcoming hardware supports a feature refereed to as "unified address space" whereby the GPU and CPU can share the same address space, which should allow you to transfer data back and forth with nothing but a memory pointer.

I haven't managed to find much practical information on this. How exactly can this be used? Are there OpenGL extensions for this?

Share this post


Link to post
Share on other sites
swiftcoder    18426
[quote name='Chris_F' timestamp='1348602202' post='4983697']
Supposedly new and upcoming hardware supports a feature refereed to as "unified address space" whereby the GPU and CPU can share the same address space, which should allow you to transfer data back and forth with nothing but a memory pointer.[/quote]
As an aside, integrated GPUs have done this for years.

It's especially easy in the integrated case, because the GPU is actually using a portion of main memory as its video memory. This has the odd effect of sometimes making CPU->GPU data transfer much cheaper for integrated GPUs than for faster, dedicated GPUs.

[quote name='Chris_F' timestamp='1348602202' post='4983697']
I haven't managed to find much practical information on this. How exactly can this be used? Are there OpenGL extensions for this?[/quote]
No, and I doubt that there will be, in the near future. Unified address space is much more the domain of OpenCL and CUDA computations - I would expect to see support for unified addressing in both of those. Edited by swiftcoder

Share this post


Link to post
Share on other sites
_the_phantom_    11250
[quote name='swiftcoder' timestamp='1348607470' post='4983747']
As an aside, integrated GPUs have done this for years.
[/quote]

In fact they haven't; CPUs and GPUs, even integrated ones, use their own address spaces to access the physical memory. What 0x00F4567380 refers to as far as the CPU is concerned is different to what the GPU sees.

AMD's Trinity APUs are, afaik, the first CPU+GPU combo where both parts can access the same memory without requiring a driver to do address translation in any form but it won't be until 2013 that they will be using the same memory controller.

As for the second part of the question; AMD do have some extensions which allow you to 'pin' memory so that it can't be swapped out (GPUs currently can't handle paging in/out of memory so any pages shared must be resident) and thus freely accessed by both CPU and GPU parts - however this is really only useful in the context of an APU otherwise the GPU would be accessing via the PCIe bus which would be a tad on the slow side.

Now, once both the CPU and GPU share the MMU and can respond to page faults accordingly such pinning won't be required, but that's not due until the 2013 time frame from AMD.

Share this post


Link to post
Share on other sites
swiftcoder    18426
[quote name='phantom' timestamp='1348610824' post='4983767']
In fact they haven't; CPUs and GPUs, even integrated ones, use their own address spaces to access the physical memory. What 0x00F4567380 refers to as far as the CPU is concerned is different to what the GPU sees.[/quote]
That isn't what I meant. Yes, the address space is different, but don't they still have the ability to transfer control of hardware pages back-and-forth?

Share this post


Link to post
Share on other sites
_the_phantom_    11250
Until recently I'm 99.999999% sure that isn't the case; on system start up a chunk of memory was reserved for the integrated GPUs and that was all they could see.

If you wanted to copy something to GPU controlled memory then it was copied across from 'system' ram to 'graphics' ram.

That's why AMD's pinning extensions is a pretty big deal as it allows for that zero-copy stuff to work but the GPU doesn't 'own' it, the memory is just locked so it can't be paged out from the physical address; the GPU itself is still just seeing a physical address, all be it one outside of its normal address range.

Share this post


Link to post
Share on other sites
Hodgman    51223
Most games consoles use a unified address space from system RAM / GPU RAM ([i]regardless of whether these are physically the same, or separate chips[/i]), which sounds pretty cool, but isn't that much of a game changer.
Some random observations:

* Loading of assets is more straightforward. Typically to load a texture, I read it from disk into some malloc'ed memory, then create a GPU texture resource, then copy my malloc'ed memory into the texture resource ([i]map/unmap/update/etc[/i]), then free my temporary memory.
On consoles, I can "malloc" some "GPU RAM" directly, and then stream the texture from disk straight into it.

* CPU read-back is still not a good idea, unless CPU/GPU RAM are physically unified as well. Dereferencing a pointer to GPU RAM may be very slow. In my experiences on systems where GPU/CPU RAM are physically seperate, despite being unified in address space, the CPU can [i]write[/i] to GPU RAM very quickly, but [i]reads[/i] from it ~10 times slower.

* Even if you do want to have to CPU/GPU communicate via shared memory, it's not straightforward. The GPU buffers commands, and is often an entire frame behind the CPU ([i]on PC, it can be even worse, with some drivers buffering up to half a dozen frames of commands at high frame-rates![/i]).
So, say for example that the GPU is producing some data for us, and the CPU wants to consume that data once it's complete -- then as well as having a (unified address space) pointer to the data to read, you also need to use GPU fence/[url="http://msdn.microsoft.com/en-us/library/windows/desktop/ff476191(v=vs.85).aspx#D3D11_QUERY_EVENT"]event[/url] system, so you can be notified once the GPU has completed that workload.
Or the converse of the above, where the CPU is producing data for the GPU to consume -- if that's some mutable resource, like changing a single pixel in a texture, then you need to insert GPU fences/events so you can tell when the GPU has finished using the previous version of that texture, then perform your modifications after the GPU has passed that fence/completed that event.

To expand on that last one -- on consoles you can work at a level where you've got a lot of synchronisation between the two processors to get the most out of your extremely limited resources ([i]keep in mind the PS3 has a [/i][i]256MiB [/i][i]GeForce7 and the 360 isn't much better!![/i]).
e.g. we've got 3 objects with procedural textures, but only enough ram for 2 at a time:
You can send off a whole stream of GPU commands in one go, which tells it to draw the 3 objects, but with some important notify/wait points
[font=courier new,courier,monospace]DrawA using Tex0, Notify DrawA complete, DrawB using Tex1, Infinite Loop C, DrawC using Tex0[/font]

You can then prime the CPU so that upon receiving "[i]Notify DrawA complete[/i]", it will immediately execute the function that writes out the appropriate texture data for DrawC into [font=courier new,courier,monospace]Tex0[/font] ([i]which is safe because DrawA is no longer using [font=courier new,courier,monospace]Tex0[/font][/i]).
Meanwhile the GPU continues on with DrawB, and if it completes it before the CPU has done this job, then it goes into an infinite loop ([i]lots of careful hand scheduling work will be done to try and ensure this doesn't happen for efficiency's sake[/i]).
When the CPU finishes writing out the new data to [font=courier new,courier,monospace]Tex0[/font], it overwrites "[font=courier new,courier,monospace]Infinite Loop C[/font]" with "[font=courier new,courier,monospace]goto next[/font]" -- if the GPU hasn't yet reached this command, then when it gets up to it, it will do nothing and move on to the next command ([i]to Draw C using the new [font=courier new,courier,monospace]Tex0[/font][/i]), or, if the GPU has reached the infinite loop, then this will break it out of it so that it can continue to Draw C.

I wouldn't dare try to implement something with such fine-grained CPU/GPU synchronisation via D3D/GL!!

So as you can see, unified address space, plus great event/notification between the two processors, plus explicit knowledge of how CPU->GPU latency and command buffering is implemented, allows you to make the most of both processors... however, this is advanced stuff that's really only done out of desperation on consoles to get by with old hardware. Ideally the above example would be scheduled in such a way that the CPU update job is quicker than the GPU's [font=courier new,courier,monospace]Draw B[/font] job ([i]so that the busy loop isn't executed at all by the GPU[/i]), but if your users can upgrade their GPU, then this busy-wait will occur for some users, and they'll get bottlenecked by their CPUs instead. Edited by Hodgman

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Similar Content

    • By Kjell Andersson
      I'm trying to get some legacy OpenGL code to run with a shader pipeline,
      The legacy code uses glVertexPointer(), glColorPointer(), glNormalPointer() and glTexCoordPointer() to supply the vertex information.
      I know that it should be using setVertexAttribPointer() etc to clearly define the layout but that is not an option right now since the legacy code can't be modified to that extent.
      I've got a version 330 vertex shader to somewhat work:
      #version 330 uniform mat4 osg_ModelViewProjectionMatrix; uniform mat4 osg_ModelViewMatrix; layout(location = 0) in vec4 Vertex; layout(location = 2) in vec4 Normal; // Velocity layout(location = 3) in vec3 TexCoord; // TODO: is this the right layout location? out VertexData { vec4 color; vec3 velocity; float size; } VertexOut; void main(void) { vec4 p0 = Vertex; vec4 p1 = Vertex + vec4(Normal.x, Normal.y, Normal.z, 0.0f); vec3 velocity = (osg_ModelViewProjectionMatrix * p1 - osg_ModelViewProjectionMatrix * p0).xyz; VertexOut.velocity = velocity; VertexOut.size = TexCoord.y; gl_Position = osg_ModelViewMatrix * Vertex; } What works is the Vertex and Normal information that the legacy C++ OpenGL code seem to provide in layout location 0 and 2. This is fine.
      What I'm not getting to work is the TexCoord information that is supplied by a glTexCoordPointer() call in C++.
      Question:
      What layout location is the old standard pipeline using for glTexCoordPointer()? Or is this undefined?
       
      Side note: I'm trying to get an OpenSceneGraph 3.4.0 particle system to use custom vertex, geometry and fragment shaders for rendering the particles.
    • By markshaw001
      Hi i am new to this forum  i wanted to ask for help from all of you i want to generate real time terrain using a 32 bit heightmap i am good at c++ and have started learning Opengl as i am very interested in making landscapes in opengl i have looked around the internet for help about this topic but i am not getting the hang of the concepts and what they are doing can some here suggests me some good resources for making terrain engine please for example like tutorials,books etc so that i can understand the whole concept of terrain generation.
       
    • By KarimIO
      Hey guys. I'm trying to get my application to work on my Nvidia GTX 970 desktop. It currently works on my Intel HD 3000 laptop, but on the desktop, every bind textures specifically from framebuffers, I get half a second of lag. This is done 4 times as I have three RGBA textures and one depth 32F buffer. I tried to use debugging software for the first time - RenderDoc only shows SwapBuffers() and no OGL calls, while Nvidia Nsight crashes upon execution, so neither are helpful. Without binding it runs regularly. This does not happen with non-framebuffer binds.
      GLFramebuffer::GLFramebuffer(FramebufferCreateInfo createInfo) { glGenFramebuffers(1, &fbo); glBindFramebuffer(GL_FRAMEBUFFER, fbo); textures = new GLuint[createInfo.numColorTargets]; glGenTextures(createInfo.numColorTargets, textures); GLenum *DrawBuffers = new GLenum[createInfo.numColorTargets]; for (uint32_t i = 0; i < createInfo.numColorTargets; i++) { glBindTexture(GL_TEXTURE_2D, textures[i]); GLint internalFormat; GLenum format; TranslateFormats(createInfo.colorFormats[i], format, internalFormat); // returns GL_RGBA and GL_RGBA glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, createInfo.width, createInfo.height, 0, format, GL_FLOAT, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); DrawBuffers[i] = GL_COLOR_ATTACHMENT0 + i; glBindTexture(GL_TEXTURE_2D, 0); glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, textures[i], 0); } if (createInfo.depthFormat != FORMAT_DEPTH_NONE) { GLenum depthFormat; switch (createInfo.depthFormat) { case FORMAT_DEPTH_16: depthFormat = GL_DEPTH_COMPONENT16; break; case FORMAT_DEPTH_24: depthFormat = GL_DEPTH_COMPONENT24; break; case FORMAT_DEPTH_32: depthFormat = GL_DEPTH_COMPONENT32; break; case FORMAT_DEPTH_24_STENCIL_8: depthFormat = GL_DEPTH24_STENCIL8; break; case FORMAT_DEPTH_32_STENCIL_8: depthFormat = GL_DEPTH32F_STENCIL8; break; } glGenTextures(1, &depthrenderbuffer); glBindTexture(GL_TEXTURE_2D, depthrenderbuffer); glTexImage2D(GL_TEXTURE_2D, 0, depthFormat, createInfo.width, createInfo.height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glBindTexture(GL_TEXTURE_2D, 0); glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depthrenderbuffer, 0); } if (createInfo.numColorTargets > 0) glDrawBuffers(createInfo.numColorTargets, DrawBuffers); else glDrawBuffer(GL_NONE); if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) std::cout << "Framebuffer Incomplete\n"; glBindFramebuffer(GL_FRAMEBUFFER, 0); width = createInfo.width; height = createInfo.height; } // ... // FBO Creation FramebufferCreateInfo gbufferCI; gbufferCI.colorFormats = gbufferCFs.data(); gbufferCI.depthFormat = FORMAT_DEPTH_32; gbufferCI.numColorTargets = gbufferCFs.size(); gbufferCI.width = engine.settings.resolutionX; gbufferCI.height = engine.settings.resolutionY; gbufferCI.renderPass = nullptr; gbuffer = graphicsWrapper->CreateFramebuffer(gbufferCI); // Bind glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo); // Draw here... // Bind to textures glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, textures[0]); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, textures[1]); glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, textures[2]); glActiveTexture(GL_TEXTURE3); glBindTexture(GL_TEXTURE_2D, depthrenderbuffer); Here is an extract of my code. I can't think of anything else to include. I've really been butting my head into a wall trying to think of a reason but I can think of none and all my research yields nothing. Thanks in advance!
    • By Adrianensis
      Hi everyone, I've shared my 2D Game Engine source code. It's the result of 4 years working on it (and I still continue improving features ) and I want to share with the community. You can see some videos on youtube and some demo gifs on my twitter account.
      This Engine has been developed as End-of-Degree Project and it is coded in Javascript, WebGL and GLSL. The engine is written from scratch.
      This is not a professional engine but it's for learning purposes, so anyone can review the code an learn basis about graphics, physics or game engine architecture. Source code on this GitHub repository.
      I'm available for a good conversation about Game Engine / Graphics Programming
    • By C0dR
      I would like to introduce the first version of my physically based camera rendering library, written in C++, called PhysiCam.
      Physicam is an open source OpenGL C++ library, which provides physically based camera rendering and parameters. It is based on OpenGL and designed to be used as either static library or dynamic library and can be integrated in existing applications.
       
      The following features are implemented:
      Physically based sensor and focal length calculation Autoexposure Manual exposure Lense distortion Bloom (influenced by ISO, Shutter Speed, Sensor type etc.) Bokeh (influenced by Aperture, Sensor type and focal length) Tonemapping  
      You can find the repository at https://github.com/0x2A/physicam
       
      I would be happy about feedback, suggestions or contributions.

  • Popular Now