• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Narf the Mouse

Looking into how to parallelize my game engine

20 posts in this topic

Making my game engine parallel is next on the list, since (this version) is in an early state and it seems a good idea to do that before I go any further. Anyway, I know of the following methods (C#), using examples:

1) Build command queues for drawing objects in parallel; execute the command queues singlethreaded (as (IMU) drawing to the GPU multi-threaded doesn't work too well). Downsides: Command object overhead; by my test, not actually faster for untextured, unlit cubes (not conclusive, but worrisome).
2) One thread per "process"; that is, a DrawThread, a PhysicsThread, an AIThread, yada. Downsides: Not sure if possible to always have as many processes as threads; synchronization between threads

Looking for:
Information on those methods.
Information on other methods.
Tutorials.

Thanks.
0

Share this post


Link to post
Share on other sites
Some of that I knew already, but the way you put it is interesting.

I'm trying to support from DirectX9 (SlimDX) up; I have a factory pattern that should be able to do that, with minimal overhead. DirectX9, at least, doesn't seem very parallel in its draw calls - IMU, it glitches if you make a draw call from a different thread than the one the device was created on. That seems to be one of the main problems I'll have to overcome if I want to make my engine parallel.
0

Share this post


Link to post
Share on other sites
That's two votes for executing tasks in parallel - That's also the way I'd prefer to do it, too.

Interesting stuff. Keep it coming. :)
0

Share this post


Link to post
Share on other sites
[url="http://www.gameenginegems.net/geg1.php"]http://www.gameenginegems.net/geg1.php[/url]

Chapter 21 talks about multi threaded object models

[url="http://www.gameenginegems.net/geg2.php"]http://www.gameenginegems.net/geg2.php[/url]

Chapter 29 talks about thread communication techniques

Also, the books are just awesome in general and are worth picking up if you are working on your own custom engine. Just thought I'd point them out :D
2

Share this post


Link to post
Share on other sites
Downside: Completely wrong on the DirectX 9 Device not being able to receive commands from multiple threads.
Upside: Completely wrong on the DirectX 9 Device not being able to receive commands from multiple threads.
Downside: In my testbed, no matter how lightly or heavily the CPU is loaded, single-threading draws faster.

Thanks; unfinances are one reason I haven't picked up the Game Engine Gems books.
0

Share this post


Link to post
Share on other sites
How would you suggest setting up the command-queuing system?

Edit: To clarify:

1) How would you implement getting commands for the queue? For example, should every function which interacts with the device return a Command object?
2) How would you processs the commands? For example, drop them off in a central point? Edited by Narf the Mouse
0

Share this post


Link to post
Share on other sites
[quote name='Narf the Mouse' timestamp='1340233759' post='4951153']
How would you suggest setting up the command-queuing system?

Edit: To clarify:

1) How would you implement getting commands for the queue? For example, should every function which interacts with the device return a Command object?
2) How would you processs the commands? For example, drop them off in a central point?
[/quote]
Assuming you're talking about drawing commands; http://realtimecollisiondetection.net/blog/?p=86
0

Share this post


Link to post
Share on other sites
[quote name='Wyrframe' timestamp='1340291207' post='4951366']
[quote name='Narf the Mouse' timestamp='1340233759' post='4951153']
How would you suggest setting up the command-queuing system?

Edit: To clarify:

1) How would you implement getting commands for the queue? For example, should every function which interacts with the device return a Command object?
2) How would you processs the commands? For example, drop them off in a central point?
[/quote]
Assuming you're talking about drawing commands; [url="http://realtimecollisiondetection.net/blog/?p=86"]http://realtimecolli....net/blog/?p=86[/url]
[/quote]
Thanks; that does tell me about sorting commands. But that's not quite what I asked.

Although, my question will probably be answered when I get to that section of Design Patterns. :)
0

Share this post


Link to post
Share on other sites
I would take a look at this sample from Intel for some help, along with the supporting articles: [url="http://software.intel.com/en-us/articles/vcsource-samples-tasking-update/"]http://software.intel.com/en-us/articles/vcsource-samples-tasking-update/[/url]

Full disclosure: although I'm a games industry veteran I also worked for Intel for a few years helping developers make their code more parallel amongst other things, so I'm likely a bit biased towards their solutions. Having said that, these techniques are in several shipping games. The tasking (also often called Jobs) methodology is pretty much universally used in games these days.

The linked article has a list of useful references. Although the code uses a directx11 interface, the overall architecture is suitable for OpenGL and DirectX9 / 10 if you batch rendering up for execution in the main thread. See [url="http://beautifulpixels.blogspot.ch/2008/07/parallel-rendering-with-directx-command.html"]http://beautifulpixels.blogspot.ch/2008/07/parallel-rendering-with-directx-command.html[/url] for some insight (and code!) about one way to do that.
0

Share this post


Link to post
Share on other sites
[quote name='dougbinks' timestamp='1340307079' post='4951466']
I would take a look at this sample from Intel for some help, along with the supporting articles: [url="http://software.intel.com/en-us/articles/vcsource-samples-tasking-update/"]http://software.inte...tasking-update/[/url]

Full disclosure: although I'm a games industry veteran I also worked for Intel for a few years helping developers make their code more parallel amongst other things, so I'm likely a bit biased towards their solutions. Having said that, these techniques are in several shipping games. The tasking (also often called Jobs) methodology is pretty much universally used in games these days.

The linked article has a list of useful references. Although the code uses a directx11 interface, the overall architecture is suitable for OpenGL and DirectX9 / 10 if you batch rendering up for execution in the main thread. See [url="http://beautifulpixels.blogspot.ch/2008/07/parallel-rendering-with-directx-command.html"]http://beautifulpixe...tx-command.html[/url] for some insight (and code!) about one way to do that.
[/quote]
"ContactDialog.rc(10): fatal error RC1015: cannot open include file 'afxres.h'."

"Don't have permission to modify solution file." - Permissions clearly show full control.
0

Share this post


Link to post
Share on other sites
It works for me when I compile the solution:

TaskingUpdate_source\TaskingUpdate\DX11MultiThreadedAnimation\TaskingGameEngine\DX11MultiThreadedAnimation\DX11MultiThreadedAnimation_2010.sln

Which solution did you try, and what version of the compiler (VS full, or express) are you using?
0

Share this post


Link to post
Share on other sites
I would start by looking into OpenCL.
At a minimum get an idea of how they designed things.

If you survey the field most of the effort in parallelization is centered around "big problems" where they can tolerate significant overhead because the gains from parallel processing are massive. When you start trying to parallel ~1ms tasks the overhead probably cannot be ignored.

The first thing I did was separate the windows-pump thread from the game-engine.
The primary thread runs the message-pump and the game runs on a second thread. If I am in window'd mode I use a 'monitor' synchronization mechanism to lock the game-thread while the window is resized. (I use OpenGL and switching the OpenGL context between threads, just unlocking & locking it, is expensive so you can't do it every frame.)
This has several nice effects, such as it allows me to continue rendering while the window is being dragged.
There are things you can do to lock this down and get decent behavior without a second thread for the game but for tools (which need a GUI) this was a nice touch.

Anytime you are chasing down a tree, two+ tail recursion, it can be parallelized. Scene culling, phsyics/collisions, & boid affects.

The physics part is where I think you get the most gain from parallelization. The collision detection and resultant forces/movement pass can be parallelized. You need a sync-point after each pass then you can submit a new batch of tasks for the next pass. I submit a job for the root of the tree and let it recurse and spawn more jobs. This is wasteful at the top of the tree but pays gains at the bottom. Figuring out the optimal place to spawn new jobs is... difficult.

Each time the scene culler determines it needs to chase down two (or more) branches each branch can be submitted as a culling job to the thread-pool.


The thread-pool is owned by my "core", the core also owns each sub-system so you can submit a scene-culling task and a collision task and they will process in parallel but I don't do this. I want the scene-culling to finish and I want to start submitting geometry to OpenGL to get the GPUs working, then start calculating physics. Kick-off scene-culling, sync-point waiting for culling to finish, reduce the thread-pool size by 1 (OGL needs to run on the core thread, this might be less awkward with D3D), kick-off physics, run opaque OGL shaders on culled geometry and once that is complete bump the thread-pool size back up and then sync that physics pass (physics passes repeat for a while).

Now I can run the opaque shader of the dynamic objects, then all mirrors, then all translucents.
I have my graphics engine setup to accept 'shader fragments'. It hash sorts them by shader priority (and then by shader) and the priority determines what order things are shaded in (order submitted for rendering). The priorities are set to minimize state-changes in the OGL pipeline.

If I did it again I think I would try adding an affinity mask to Jobs so I could force a job to execute on a particular thread. Then OGL & D3D rendering would work the same way through the thread-pool and I wouldn't have 'special steps' in the core process. Edited by Shannon Barber
1

Share this post


Link to post
Share on other sites
[quote name='dougbinks' timestamp='1340356481' post='4951663']
It works for me when I compile the solution:

TaskingUpdate_source\TaskingUpdate\DX11MultiThreadedAnimation\TaskingGameEngine\DX11MultiThreadedAnimation\DX11MultiThreadedAnimation_2010.sln

Which solution did you try, and what version of the compiler (VS full, or express) are you using?
[/quote]
I used Visual C++ Express 2010 and Visual C++ Express 10 (from the options) - Probably the same thing.

@Shannon Barber: Thanks; that gives me some more ideas for my engine.


This thread details a specific problem I'm having with parallel code:

[url="http://www.gamedev.net/topic/626804-slow-parallel-code/"]http://www.gamedev.n...-parallel-code/[/url] Edited by Narf the Mouse
0

Share this post


Link to post
Share on other sites
Last night this thread piqued my interest in the topic so I went digging in my game engine gems books for some info and found some really relevant stuff. This is a presentation that was cited at the end of the [b]Camera Centric Engine Design for Multithreaded Rendering[/b] chapter. It is a very good intro into the command queuing stuff. Also I didn't know this but Civ 5's engine LORE stands for Low Overhead Rendering Engine, and there is a presentation floating around that details how they implemented this technique for DX 9 and DX 11. When I get on my desktop I can post the link to it for your viewing pleasure.

SIGGRAPH presentation: [url="http://developer.amd.com/gpu_assets/S2008-Scheib-ParallelRenderingSiggraph.pdf"]http://developer.amd...ingSiggraph.pdf[/url] and [url="http://www.scheib.net/work/emergent/DirectXCommandBufferLib-v1.zip"]Source[/url]
Firaxis LORE [url="http://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=3&ved=0CFoQFjAC&url=http%3A%2F%2Fdeveloper.amd.com%2Fgpu_assets%2FFiraxis%2520LORE.pps&ei=Gu7kT7DrFMb-2QW4_OnZCQ&usg=AFQjCNGQHZco2n3cx_7JwtbE2v4ZxwdI0Q&sig2=WRT8NecqFqSzOwjFc9nYHQ"]presentation[/url]
1

Share this post


Link to post
Share on other sites
@Narf the Mouse - tried to reproduce your problem with Visual C++ Express, and couldn't, so I'm not sure how to help.

FYI Civ 5 was multithreaded with the help of the original author of the Multithreaded Animation sample I mentioned, you can see him and Dan Baker chat about their work here: [url="http://www.youtube.com/watch?v=KSqzrHlsiVM"]http://www.youtube.com/watch?v=KSqzrHlsiVM[/url]

There's also an article on this here: [url="http://software.intel.com/en-us/articles/sid-meiers-civilization-v-finds-the-graphics-sweet-spot/"]http://software.intel.com/en-us/articles/sid-meiers-civilization-v-finds-the-graphics-sweet-spot/[/url]
0

Share this post


Link to post
Share on other sites
Thanks, everyone. I've looked through/bookmarked the resources; unfortunately, Intel vTune is a bit out of my price range right now, especially if I'm going to get the ANTS Profiler.

However, your help has already allowed my some significant parallelization.
0

Share this post


Link to post
Share on other sites
You might want to look into Intel GPA and it's CPU profiling capabilities (which require some code mark-up but that's usually fairly straight forwards), it's free of charge. AMD Codeanalyst is also free, and has some great capabilities these days [url="http://developer.amd.com/tools/CodeAnalyst/Pages/default.aspx"]http://developer.amd...es/default.aspx[/url]. Although some of it's abilities only work on AMD systems, I've used the timer profiling on Intel.

If you have Games Programming Gems 3 or Best of Games Programming Gems the Real-Time Hierarchical Profiling article is very decent, though needs some changes to track multiple threads. It can be combined with the markups you need for Intel GPA so you can get offline and real-time viewing of the data.

XPerf is also free and great for a wide range of profiling functions, though somewhat complex. See [url="http://www.altdevblogaday.com/2012/06/20/wpaxperf-trace-analysis-reimagined/"]http://www.altdevblogaday.com/2012/06/20/wpaxperf-trace-analysis-reimagined/[/url] and linked articles. Edited by dougbinks
0

Share this post


Link to post
Share on other sites
[quote name='dougbinks' timestamp='1340737082' post='4953097']
You might want to look into Intel GPA and it's CPU profiling capabilities (which require some code mark-up but that's usually fairly straight forwards), it's free of charge. AMD Codeanalyst is also free, and has some great capabilities these days [url="http://developer.amd.com/tools/CodeAnalyst/Pages/default.aspx"]http://developer.amd...es/default.aspx[/url]. Although some of it's abilities only work on AMD systems, I've used the timer profiling on Intel.

If you have Games Programming Gems 3 or Best of Games Programming Gems the Real-Time Hierarchical Profiling article is very decent, though needs some changes to track multiple threads. It can be combined with the markups you need for Intel GPA so you can get offline and real-time viewing of the data.

XPerf is also free and great for a wide range of profiling functions, though somewhat complex. See [url="http://www.altdevblogaday.com/2012/06/20/wpaxperf-trace-analysis-reimagined/"]http://www.altdevblo...sis-reimagined/[/url] and linked articles.
[/quote]
Thankls. I've downloaded the first and am in the middle of downloading the Windows Software Development Kit for XPerfView - I didn't like command-line interfaces way back on the Amiga 500; I don't like them now. [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

(Although, oddly, the Vice Emulator makes me nostalgic) Edited by Narf the Mouse
0

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  
Followers 0