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

State blocks in DX10

7 posts in this topic

I've used state blocks (http://msdn.microsoft.com/en-us/library/windows/desktop/bb206121%28v=vs.85%29.aspx) with Direct3D 9 in the past to save off the current render state, make some state changes, render some primitives, and then reset the render state to what it was previously.

How do I do something similar in Direct3D 10/11? I basically want to take the current render state (e.g. shaders, input layout) and save them off, change the state to whatever I need in order to render something else, and then set the state back to what it was before I rendered.
0

Share this post


Link to post
Share on other sites
just set the state before you render your stuff, and set it again before you render things that use a different state. some states include:

blending state:
OMSetBlendState();

bind the vertex buffer to IA:
IASetVertexBuffers();

bind index buffer to IA:
IASetIndexBuffer();

set shaders (pixel and vertex, but you can set other shaders with similar methods);
VSSetShader();
PSSetShader();

set the render target:
OMSetRenderTargets()

set the rasterizer state (eg. backface culling, wireframe):
RSSetState()

set constant buffers (vertex and pixel shader)
VSSetConstantBuffers()
PSSetConstantBuffers()

set shader resources (pixel shader)(eg. textures)
PSSetShaderResources();

set sampler state (pixel shader)
PSSetSamplers()

All these are methods of the device context interface, unlike d3d9 that only has a device interface for everything (device context is used for rendering and stuff, and the regular device is used for the creation of things, if i'm not mistaking)
0

Share this post


Link to post
Share on other sites
Well, so the problem here is that I don't actually set the initial render state myself. I'm essentially doing an overlay over the Direct3D application, which means I'm piggy backing off of the application's existing render state (i.e. whatever the application had already set) and I want to make sure that when I'm done rendering, the state is set back to what it was before I did my thing,
0

Share this post


Link to post
Share on other sites
to set the state back to the default, you can just pass NULL as the parameter. the application should set the state to whatever it needs before it draws it's stuff though. it's possible it set the state during initialization time, so that when you change the state, it never goes back to the state that was set in the initialization of the scene. In that case, you'll have to find where it sets the state and just set it back after you are done drawing your stuff. But, that's bad practice to assume the state does not change throughout the scene. the state should always be explicitly set before you draw things that need that specific state (at least in my opinion). Directx as you probably know is a "state machine", which means once you set a state, it will never change until you explicitly set it to something else

another possibility is that it just uses the default state, and never actually sets the state at all, so once you set your state, it doesn't actually change. So just try setting the state back to NULL to see if that helps
0

Share this post


Link to post
Share on other sites
[quote name='iedoc' timestamp='1330106689' post='4916271']
to set the state back to the default, you can just pass NULL as the parameter. the application should set the state to whatever it needs before it draws it's stuff though. it's possible it set the state during initialization time, so that when you change the state, it never goes back to the state that was set in the initialization of the scene.[/quote]

That's pretty much the core problem. Having done this for quite a bunch of Direct3D 9 games, I know for a fact that some games only set their state initially rather than on a per-frame basis, and thus modifying the state so that I can render my stuff will mess up the game itself. One thing I've learned when interacting with games is that you can never expect game developers to Do The Right Thing (TM) in code and you always have to consider the worst case scenario.

It's therefore really important that I'm able to set back the game's render state after I'm done rendering my things. So, there's no way to do this automatically for DX10 like I can do in DX9 with state blocks?

The only solution, then, would be to hook all the state functions that I change, such that I know what value to set back once I'm done rendering. That's a bunch of work though...
0

Share this post


Link to post
Share on other sites
All D3D10/11 states have a "Get" accessor, so you could - for example, with rasterizer states - use RSGetState to access the current state, then GetDesc on the state object if you need it's description.

I haven't benchmarked the use of such a Get call, but I would expect that all you're doing is getting a handle to the object from the runtime (rather than reading back data from the GPU) so it should be OK.

Don't forget to Release the state object you get back when done as the Get call will AddRef it.

With D3D11 I'd create a deferred context, record my stuff in a command list, then play it back and destroy the context. FinishCommandList can be told to save and restore the previous states for you, so you won't need to worry about any of that.
1

Share this post


Link to post
Share on other sites
[quote name='mhagain' timestamp='1330108471' post='4916280']
I haven't benchmarked the use of such a Get call, but I would expect that all you're doing is getting a handle to the object from the runtime (rather than reading back data from the GPU) so it should be OK.
[/quote]

Right, I haven't benchmarked them either so they might just be really simple wrappers and pretty cheap to call each frame. I just didn't think of going down that road since I know OpenGL's GetXX() functions are really slow and not recommended to call on a per-frame basis (although I know the DIrectX API is fundamentally different :),

[quote name='mhagain' timestamp='1330108471' post='4916280']With D3D11 I'd create a deferred context, record my stuff in a command list, then play it back and destroy the context. FinishCommandList can be told to save and restore the previous states for you, so you won't need to worry about any of that.
[/quote]

That's really cool. That's exactly what I was looking for. I need to read up on deferred contexts, but ideally I'd be able to create the context once and reuse each frame.
0

Share this post


Link to post
Share on other sites
In case others are interested, I stumbled upon an interface called ID3D10StateBlock, which presumably does exactly what I want.
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