• Advertisement
  • Popular Tags

  • Popular Now

  • Advertisement
  • Similar Content

    • By Hermetix
      I am trying to setup the custom wizard for making a 3ds MAX 2018 plug-in (to export a character animation data), but I can't locate the wizard file folder to put the .vsz file in. In the 3ds MAX 2018 docs, it only mentions where the folder is in VS 2015 (VC/vcprojects). It's a VC++ project, but I don't see any folder in VC for the wizard files. I'm using VS 2017 update 15.5.6 Enterprise, and the folders in VC are: Auxiliary, Redist and Tools.
    • By elect
      ok, so, we are having problems with our current mirror reflection implementation.
      At the moment we are doing it very simple, so for the i-th frame, we calculate the reflection vectors given the viewPoint and some predefined points on the mirror surface (position and normal).
      Then, using the least squared algorithm, we find the point that has the minimum distance from all these reflections vectors. This is going to be our virtual viewPoint (with the right orientation).
      After that, we render offscreen to a texture by setting the OpenGL camera on the virtual viewPoint.
      And finally we use the rendered texture on the mirror surface.
      So far this has always been fine, but now we are having some more strong constraints on accuracy.
      What are our best options given that:
      - we have a dynamic scene, the mirror and parts of the scene can change continuously from frame to frame
      - we have about 3k points (with normals) per mirror, calculated offline using some cad program (such as Catia)
      - all the mirror are always perfectly spherical (with different radius vertically and horizontally) and they are always convex
      - a scene can have up to 10 mirror
      - it should be fast enough also for vr (Htc Vive) on fastest gpus (only desktops)

      Looking around, some papers talk about calculating some caustic surface derivation offline, but I don't know if this suits my case
      Also, another paper, used some acceleration structures to detect the intersection between the reflection vectors and the scene, and then adjust the corresponding texture coordinate. This looks the most accurate but also very heavy from a computational point of view.

      Other than that, I couldn't find anything updated/exhaustive around, can you help me?
      Thanks in advance
    • By KarimIO
      Hey guys! Three questions about uniform buffers:
      1) Is there a benefit to Vulkan and DirectX's Shader State for the Constant/Uniform Buffer? In these APIs, and NOT in OpenGL, you must set which shader is going to take each buffer. Why is this? For allowing more slots?
      2) I'm building an wrapper over these graphics APIs, and was wondering how to handle passing parameters. In addition, I used my own json format to describe material formats and shader formats. In this, I can describe which shaders get what uniform buffers. I was thinking of moving to support ShaderLab (Unity's shader format) instead, as this would allow people to jump over easily enough and ease up the learning curve. But ShaderLab does not support multiple Uniform Buffers at all, as I can tell, let alone what parameters go where. 
      So to fix this, I was just going to send all Uniform Buffers to all shaders. Is this that big of a problem?
      3) Do you have any references on how to organize material uniform buffers? I may be optimizing too early, but I've seen people say what a toll this can take.
    • By ANIO chan
      Hi, I'm new here and would like to get some help in what i should do first when designing a game? What would you consider to be the best steps to begin designing my game? Give resources with it as well please.
    • By abarnes
      Hello All!
      I am currently pursuing a degree in video game programming, so far I have completed an intro to programming course and object oriented programming course. Both were taught using C++ as the programming langauge which I know is very popular for game development, but in these classes we do not actually do any game development. I would like to start to build my skills with C++ for game development as that is a common required thing for a job and am looking for ways to do this. Any recommendations such as books to read or youtube videos to watch will be greatly appreciated!
  • Advertisement
  • Advertisement

C++ Ping-pong buffer (swap 1-frame allocator) suitable for games?

Recommended Posts

I am considering to allocate most persistent data of my ECS framework on a one-frame allocator.

To extend their life to exist on > 1 frame, I will need to copy it to another buffer.

Initialization  I create Buffer X and Y.  Each has 50-300MB.

  • 1st timestep : every Entity / Components will use buffer X to allocate.
  • 1st-end : copy every Entity/Component that are not marked as deleted to buffer Y, clear X.
  • 2st timestep : every Entity / Components will use buffer Y to allocate.
  • 2st-end : copy every Entity/Component that are not marked as deleted to buffer X, clear Y.  ...


  • almost 0 fragmentation cost, pool is not needed anymore
  • very low cache miss in game-logic


  • high cost of memory swapping (X<-->Y 50-300 MB every timestep)
  • Reason : computer can read or write memory at 10 GB/s = 170 MB/timestep
  • (reference : https://stackoverflow.com/questions/25827416/ )
  • (minor) pointer become invalidated, I must use ID instead

Note: Luckily, every components are POD (plain old data = no pointer as field).

After some draft, it strongly believe it is possible to implement.


  • Does it sound bad?  Is it a good practice / technique?
  • Is "ping-pong buffer" a correct name of this technique?  What are other names?



Edited by hyyou

Share this post

Link to post
Share on other sites

Congratulations, you have reinvented the copying garbage collector. It's going to be ridiculously expensive to run it every frame as you propose - you've already burnt your entire memory bandwidth just of garbage collection, leaving nothing for the actual game.

This might make sense if the number of deleted objects every frame vastly outnumbered the living objects, but I'm hard put to imagine a scenario where that would be true. How many objects in your game *actually* are created/deleted in a single frame?

Many simulations are designed such that zero allocations/deallocations take place on a frame-by-frame basis. i.e. by preallocating pools of objects when the level loads, you can potentially avoid ever performing an allocation during the level.

Share this post

Link to post
Share on other sites

I tried doing something similar to this 10-12 years ago when I was trying my hand at a Liero clone, but with N stages/copies/whatever (ie 5). The idea was basically to store a complete copy of the game state up to N frames back. This way I thought I could back up and re-run the simulation when an old network packet arrived. The reason I wanted to do it that way is that it (Liero that is) is a rather fast paced action game, with thousands if not millions of objects and destructible terrain, where butterfly effects can potentially be a giant problem, while back then we also had much crappier connections than we do now.

Anyway, my conclusion was basically what swiftcoder said, memory bandwidth sucks. Back then we had something like 1-2gb/s, which I thought would give me something like 20MB/frame, but I didn't initially realize that it was 20MB spread across the entire frame, not a quick action at the beginning of the frame. In short, the copying alone ate every last slice of juice my high end P4 system had to offer at the time.

Share this post

Link to post
Share on other sites

Temporary allocation strategies have their place in games, yes. The trick is to use them very selectively, i.e. only for data you know will be short-lived (in this case).

If you need allocation and you know you won't preserve the results for more than a tick, you can definitely use strategies that throw away the memory and restart at the beginning of the next frame. I've done this to great effect in past games.

More generally, if you know the lifetime patterns of a piece of data, you can find a custom allocator that will suit your specific use cases. It is not uncommon for games to have several custom allocation strategies for different sorts of data.

As has been noted already, doing poor-man's copying GC is risky at best and probably prohibitively expensive. But you can still get great mileage out of custom allocators if you're more deliberate in how you deploy them.

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

  • Advertisement