• 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
TheAsterite

Multi-threaded Design?

2 posts in this topic

So as of now, I have a somewhat decent grasp about how to break up jobs into smaller parts for parallel processing. I wanted to move to designing an engine framework that revolved around handling different systems such as physics or rendering as different threads when I came across this article by intel: http://software.intel.com/en-us/articles/designing-the-framework-of-a-parallel-game-engine.

 

It seemed really interesting, so I downloaded the source code to their demonstration and was looking at it. 

 

My question is, how relevant is this paper today? Is this scheduling technique used widely in the games industry?

0

Share this post


Link to post
Share on other sites

My view is that the Intel Smoke framework is somewhat over-generic (universal scene, which is extended with system scenes, change management) and some of its concepts are dubious, such as conflict resolution if several systems change the same property such as object transform (IMO that should not happen in the first place.) It doesn't really address the ordering of tasks within a frame, which doesn't hurt in the demo, but in an actual game it could lead to nasty non-determinism if for example AI is sometimes running one frame ahead, sometimes one frame behind in respect to physics. I'd consider it potentially dangerous if used directly as a basis for learning or for own engine.

 

I'd recommend, at least in the beginning, to be very explicit (even hardcoded) of what systems or tasks are actually running simultaneously, and what are the changes they're propagating to each other. For example physics updating object transforms, which the renderer picks up. Then profile constantly to discover the bottlenecks and to able to decide if threading will actually benefit them.

 

Some more resources (in case you're not familiar with them yet)

 

http://www.gamasutra.com/view/feature/1830/multithreaded_game_engine_.php

http://www.gamasutra.com/view/feature/2463/threading_3d_game_engine_basics.php

http://bitsquid.blogspot.fi/2010/03/task-management-practical-example.html

0

Share this post


Link to post
Share on other sites

I tend to agree with AgentC as to Smoke being over generic and also having some really bad bits which should not exist.  Having said that though, let me rephrase it as my preferred question: does the complication outweigh the benefit?  Not everyone is a threading guru, nor in reality should they be.  A person doing gameplay code should not have to worry about threading beyond a very few rules, if they do have to worry about threading a lot, it is an architecture failure in terms of the Knuth saying: "premature optimization is the root of all evil" and threading is most definitely an optimization.  A threading system doesn't have to execute at 99+% of Amdahl's law to be a benefit, 90% is good enough for most things as it scales to 8-10 cores before diminishing returns prevents further benefit.  Better than that, most of the performance loss is pre/post frame organization; the internal per frame work, when done well, but non-intrusively, can average closer to 97-98% which scales beyond 10 cores.

 

I am a fan of staged execution myself.  It is similar in concept to the discussions of threading in the entity frameworks folks are talking about.  You break up the execution into several pieces (components) using a set of simple rules even a junior programmer can follow.  Take for example a flocking system, I won't detail the algo, just the break down and how the rules apply:

 

Vector3f CalculateFlocking()
{
  // Read positions of flock.
  // Calculate center point, avoidance etc.
  // Generate new velocity.
}
 
void Update()
{
  mVelocity = CalculateFlocking();
  mPosition += mVelocity * Time::DeltaTime();
}

 

The above won't work in the way I do threading because it breaks the prime rule of my system:  In a single stage of update you can not read from and write to a variable.  And the other way around also in terms that you can't write a variable and then use it for further calculation.  In the case of flocking, the update function breaks the rule because the calculation reads multiple object positions and then writes to this objects position.  The reason is simple, without inserting a mutex (against another rule) to protect the position member, the assignment is non-atomic and you could get partially updated (potentially invalid) vectors used by other simultaneous executions of this function.  Additionally, there is no consistency in terms of reading a position and getting an old or new version, which can throw off a number of calculations.

 

To fix the update function is simple, break it into two pieces (note: velocity is also read from the flocking calculation, so I fix that also):

void Update1()
{
  mNewVelocity = CalculateFlocking();
}
void Update2()
{
  mVelocity = mNewVelocity;
  mPosition += mNewVelocity * Time::DeltaTime();
}

 

Now, iterating Update1 and Update2 with multiple threads is completely safe without any per object synchronization, you just have to make sure you iterated all Update1's completely before starting on Update2's.  Performance wise, even with the temporaries, this runs exceptionally fast with only a single synchronization point between Update1 and Update2.  I posted an example video at one time which shows flocking implemented in this manner: http://www.youtube.com/watch?v=JVTBRes6gY0 it is not fancy (and takes a second up front to stabilize  but 2000 objects updating multi-threaded in the above manner is not exactly trivial.  The more important number, which I didn't show, is a near complete lack of locking/kernel time taking place except between the various update calls, of which there were 12 stages in that example.

 

Finally, to keep with the basic idea of staying out of peoples way, you can write the first example during initial development and simply mark the "stage" as single threaded.  Once you get things working, you can turn on a debug helper which flags any same stage data accesses and start the process of decomposing the update into different pieces.

 

With only 3 rules and better than 95% Amdahl's efficiency, I've never seen any real reason to worry about this solution much further.  It stays out of the way of getting things done, provides plenty of performance benefit and is very simple to implement.  I'll take the minor losses for the gain of simplicity in this case, not sure how you will feel of course but it is worth keeping in mind.

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