Sign in to follow this  
Chris_F

OpenGL OpenGL and unified address space

Recommended Posts

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
[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
[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
[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
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
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  

  • Forum Statistics

    • Total Topics
      627716
    • Total Posts
      2978783
  • Similar Content

    • By DelicateTreeFrog
      Hello! As an exercise for delving into modern OpenGL, I'm creating a simple .obj renderer. I want to support things like varying degrees of specularity, geometry opacity, things like that, on a per-material basis. Different materials can also have different textures. Basic .obj necessities. I've done this in old school OpenGL, but modern OpenGL has its own thing going on, and I'd like to conform as closely to the standards as possible so as to keep the program running correctly, and I'm hoping to avoid picking up bad habits this early on.
      Reading around on the OpenGL Wiki, one tip in particular really stands out to me on this page:
      For something like a renderer for .obj files, this sort of thing seems almost ideal, but according to the wiki, it's a bad idea. Interesting to note!
      So, here's what the plan is so far as far as loading goes:
      Set up a type for materials so that materials can be created and destroyed. They will contain things like diffuse color, diffuse texture, geometry opacity, and so on, for each material in the .mtl file. Since .obj files are conveniently split up by material, I can load different groups of vertices/normals/UVs and triangles into different blocks of data for different models. When it comes to the rendering, I get a bit lost. I can either:
      Between drawing triangle groups, call glUseProgram to use a different shader for that particular geometry (so a unique shader just for the material that is shared by this triangle group). or
      Between drawing triangle groups, call glUniform a few times to adjust different parameters within the "master shader", such as specularity, diffuse color, and geometry opacity. In both cases, I still have to call glBindTexture between drawing triangle groups in order to bind the diffuse texture used by the material, so there doesn't seem to be a way around having the CPU do *something* during the rendering process instead of letting the GPU do everything all at once.
      The second option here seems less cluttered, however. There are less shaders to keep up with while one "master shader" handles it all. I don't have to duplicate any code or compile multiple shaders. Arguably, I could always have the shader program for each material be embedded in the material itself, and be auto-generated upon loading the material from the .mtl file. But this still leads to constantly calling glUseProgram, much more than is probably necessary in order to properly render the .obj. There seem to be a number of differing opinions on if it's okay to use hundreds of shaders or if it's best to just use tens of shaders.
      So, ultimately, what is the "right" way to do this? Does using a "master shader" (or a few variants of one) bog down the system compared to using hundreds of shader programs each dedicated to their own corresponding materials? Keeping in mind that the "master shaders" would have to track these additional uniforms and potentially have numerous branches of ifs, it may be possible that the ifs will lead to additional and unnecessary processing. But would that more expensive than constantly calling glUseProgram to switch shaders, or storing the shaders to begin with?
      With all these angles to consider, it's difficult to come to a conclusion. Both possible methods work, and both seem rather convenient for their own reasons, but which is the most performant? Please help this beginner/dummy understand. Thank you!
    • By JJCDeveloper
      I want to make professional java 3d game with server program and database,packet handling for multiplayer and client-server communicating,maps rendering,models,and stuffs Which aspect of java can I learn and where can I learn java Lwjgl OpenGL rendering Like minecraft and world of tanks
    • By AyeRonTarpas
      A friend of mine and I are making a 2D game engine as a learning experience and to hopefully build upon the experience in the long run.

      -What I'm using:
          C++;. Since im learning this language while in college and its one of the popular language to make games with why not.     Visual Studios; Im using a windows so yea.     SDL or GLFW; was thinking about SDL since i do some research on it where it is catching my interest but i hear SDL is a huge package compared to GLFW, so i may do GLFW to start with as learning since i may get overwhelmed with SDL.  
      -Questions
      Knowing what we want in the engine what should our main focus be in terms of learning. File managements, with headers, functions ect. How can i properly manage files with out confusing myself and my friend when sharing code. Alternative to Visual studios: My friend has a mac and cant properly use Vis studios, is there another alternative to it?  
    • By ferreiradaselva
      Both functions are available since 3.0, and I'm currently using `glMapBuffer()`, which works fine.
      But, I was wondering if anyone has experienced advantage in using `glMapBufferRange()`, which allows to specify the range of the mapped buffer. Could this be only a safety measure or does it improve performance?
      Note: I'm not asking about glBufferSubData()/glBufferData. Those two are irrelevant in this case.
    • By xhcao
      Before using void glBindImageTexture(    GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format), does need to make sure that texture is completeness. 
  • Popular Now