• 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.
  • entries
    316
  • comments
    485
  • views
    321129

Multithreaded Rendering

Sign in to follow this  
Followers 0
Jason Z

1061 views


Multithreaded Rendering with D3D11


Lately I have been splitting my time between writing some new material for a forth coming project and trying to understand the design differences needed to allow multithreaded rendering in D3D11. Since the latter is the more complicated one, I thought I would flesh out a few ideas here and talk a little bit about it.

In Hieroglyph, the renderer has always been a singleton-like class. It was not a stricly enforced singleton, but I did always create a static accessor method that would let anyone that had the renderer's header included get a reference to it. This always made rapid development easier, but over the years I found myself using the static method less and less - it just didn't seem like such a good idea anymore.

Now I know why - when you want to make changes to your designs, it is good to have the flexibility to try out different things - and singletons are kind of like a lock-in to a particular way of doing things. They aren't necesarily bad, but they certainly aren't good either... Especially when you want to do something crazy like let your engine think it has more than one renderer [grin].

Multithreading

My desire to add multithreading to the engine is to take advantage of the deferred rendering context (not to be mistaken for deferred rendering in general!). This basically allows a bunch of rendering calls to be made on a 'deferred' context, which basically creates a command list to be replayed later on the immediate context. This, in theory, should minimize the CPU interfering with the GPU if your command lists are long enough without any stalls.

Hieroglyph also utilizes a design concept of RenderViews to encapsulate a complete scene rendering pass. Want to generate a shadow map? Use a render view. Want to generate an ambient occlusion buffer? Use a render view. As it turns out, this paradigm provides a convenient 'batch' of work to supply to a deferred context.

The tricky part is to be able to make the renderer (which by now is certainly a non-trivial class) be able to be mostly cloned, and have its context replaced by a deferred one. This renderer instance can then be passed into the 'render' function of a render view, and he is none the wiser about if it is rendering immediately or generating a command buffer. Sounds pretty good so far...

Of course, the 'real' renderer would be in charge of managing these doppelganger renderers (I like the word doppelganger, so I'll use it for these mini-me renderers [grin]). In fact, I'm considering making a renderer interface and allowing the renderer to replace parts of itself in a new implementation. The tough part is that all of the resource and state references that are stored in the renderer must be accessible to all of the doppelgangers, but the complete parameter system which is used to connect all those resources and states to textual names in the shaders must be unique to each doppelganger due to the fact that the parameter system stores state that can't be shared between multiple render views simultaneously. Plus, using a locking system on the parameter system is a non-starter since it is one of the most widely used parts of the renderer...

The solution? I'm going to create inner classes to hold all the parameter systems and their methods, and allow it to be dynamically recreated and/or cloned. This should provide enough flexibility to use the interface technique I mentioned above, and create a subclass of the renderer with only the functionality that I want to be used for deferred contexts... I still have a ways to go until I am ready for some trials, but I think this overall modification should be worth while.

Soon I will have a myriad of renderers running around in my engine [cool]!

0
Sign in to follow this  
Followers 0


5 Comments


Don't be surprised if multithreaded rendering doesn't result in as much a gain as you're expecting or even worse lowers the performance altogether, especially considering that on a multi-core machine, command lists are already dispatched for execution on multiple threads in the driver. Based on what I've seen, unless there's a significant amount of parallelism in your rendering pipeline, the cost outweighs any benefits substantially. The MultithreadedRendering11 sample that comes with the SDK for instance, which is supposed to make a good use of the API, runs twice / thrice slower on my quad core machine when choosing the MT renderpath as opposed to ST.

Anyway, keep us informed. I'd love to see how your implementation is going to end up.
0

Share this comment


Link to comment
Thanks for the heads up - although this is more of an experiment than an expected performance booster. I'm fairly certain that it will take somewhat of a contrived scene to make any difference at... (I.e. a bazillion objects in my scene graph...).

Also, I wouldn't make the assumption that if the sample isn't able to do it... you know what I mean... Let's see if I can do better. ;)
0

Share this comment


Link to comment
Performance of deferred contexts have always had me slightly confused, mainly due to the SDK sample and the fact that I haven't actually worked with them yet. That said I've read some developers saying that they are great, they didn't elaborate though. Anyway Jason I'm looking forward to reading about your findings, and it would be very interesting to maybe see some benchmarks. I'm guessing there is some criteria you have to meet before you start to see a speed up (high amount of draw calls? something else?)
0

Share this comment


Link to comment
That's my basic assumption, that you need to have something that would normally eat up a bunch of CPU time to make all of the draw calls. Still with D3D11 it is hard to know which calls will really take lots of time and which are trivial. Also, with multiple cores running and accessing the scene at the same time I would have to think that the CPU side would have a terrible cache coherency access pattern... That might help explain the issues mentioned above about the quad core not performing very well.

Even so, I want to build the tools and then try to find out where it can be useful.
0

Share this comment


Link to comment
Good point, I guess the only way to really find out is to actually do it. The idea I have been toying with for a bit was breaking scene rendering up into jobs (I already have a job system for other tasks, just haven't touched my renderer yet) and kicking off jobs to threads and letting them use a pool of deferred contexts to do things like, render out gbuffer, update shadow map a, update shadow map b... etc, do post process filters, etc.

Curious to see how it performs. Probably no benefit at all for things like post processing, but it does help at least with breaking the code up nicely.
0

Share this comment


Link to comment

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