<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Graphics state management</title><link>http://blogs.msdn.com/shawnhar/archive/2007/10/25/graphics-state-management.aspx</link><description>Once upon a time there lived a young graphics coder named Johnny. One day Johnny wrote a program that displayed a 3D model. As is frequently the case with people his age, Johnny was somewhat careless and did not bother to set all the renderstates which</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Graphics state management</title><link>http://blogs.msdn.com/shawnhar/archive/2007/10/25/graphics-state-management.aspx#5685593</link><pubDate>Fri, 26 Oct 2007 08:36:20 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5685593</guid><dc:creator>ajmiles</dc:creator><description>&lt;p&gt;What I've never understood is why somewhere in between $3D_Application and the GPU there isn't someone else taking responsibility for ensuring redundant state changes are caught and can also be read back quickly. This could (conceivably) be either the graphics card driver or DirectX itself. Although I've not given this plan much thought, the renderstates that easily map to enums (like FillMode, the Alpha ones etc) could be stored in RAM and just get updated every time the GPU gets updated. Meaning that changing from FillMode.Line to FillMode.Line never gets passed on to the GPU, and querying any of those states doesn't require talking to the GPU.&lt;/p&gt;
&lt;p&gt;I've thought about trying something similar just in my XNA apps, a &amp;quot;RenderStateManager&amp;quot; of sorts, but using things like SpriteBatch mean that I can't run *all* state changes through my manager, and it just ends up being a pain to keep track of.&lt;/p&gt;
</description></item><item><title>re: Graphics state management</title><link>http://blogs.msdn.com/shawnhar/archive/2007/10/25/graphics-state-management.aspx#5691234</link><pubDate>Fri, 26 Oct 2007 16:18:41 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5691234</guid><dc:creator>Ultrahead</dc:creator><description>&lt;p&gt;This can also be combined with a sorting helper so as to minimize switching states. You just define when to call each object's draw method based on, say, material, texture, type of object/entity (good occluder, transparent one), or categories (3D models first then 2D sprites) and so on.&lt;/p&gt;
</description></item><item><title>re: Graphics state management</title><link>http://blogs.msdn.com/shawnhar/archive/2007/10/25/graphics-state-management.aspx#5693289</link><pubDate>Fri, 26 Oct 2007 19:42:18 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5693289</guid><dc:creator>ShawnHargreaves</dc:creator><description>&lt;p&gt;&amp;gt; What I've never understood is why somewhere in between $3D_Application and the GPU there isn't someone else taking responsibility for ensuring redundant state changes are caught and can also be read back quickly.&lt;/p&gt;
&lt;p&gt;There is! At least for setting, and on Windows for reading back as well: reading back is especially slow on Xbox due to the user/supervisor memory split.&lt;/p&gt;
&lt;p&gt;The trouble is not that everybody isn't doing their best to optimize state setting, but that there are simply so many states. A DX9 GPU has kilobytes worth of state data, and it takes hundreds of function calls to set all this state. Even if every one of those function calls could just trivially compare the state it is being asked to set against the current value and return in just a couple of clock cycles, that is still hundreds of calls, comparing hundreds of values, for no good reason.&lt;/p&gt;
&lt;p&gt;Even if T is quick, it is still faster to not call it in the first place, and in this case we are talking about a large number of T's!&lt;/p&gt;
&lt;p&gt;The key thing here is that games are able to use higher level architectural decisions to reduce work, where the driver is only able to apply dumb &amp;quot;this state is the same value I have already&amp;quot; checks. The game knows more, so it can make assumptions like &amp;quot;I don't even need to bother thinking about setting states X, Y, or Z, because I know the previous guy already set them for me&amp;quot;.&lt;/p&gt;
</description></item><item><title>re: Graphics state management</title><link>http://blogs.msdn.com/shawnhar/archive/2007/10/25/graphics-state-management.aspx#5696420</link><pubDate>Sat, 27 Oct 2007 01:39:03 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5696420</guid><dc:creator>Ultrahead</dc:creator><description>&lt;p&gt;There was an interesting reading on ShaderX4 book about this. In the article, it was even considered setting some states back and forth within each shader it-self.&lt;/p&gt;
</description></item><item><title>re: Graphics state management</title><link>http://blogs.msdn.com/shawnhar/archive/2007/10/25/graphics-state-management.aspx#6701702</link><pubDate>Sat, 08 Dec 2007 10:18:09 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6701702</guid><dc:creator>digini</dc:creator><description>&lt;p&gt;Cool post...&lt;/p&gt;
&lt;p&gt;For our material system we've tried a few different approaches EMFH and Consistency.&lt;/p&gt;
&lt;p&gt;Right now we are using kind of a hybrid. &amp;nbsp;When we change materials we set the shader params to the base &amp;quot;known&amp;quot; state and then apply a set of deltas that are specific to the particular material &amp;nbsp;In our testing this seemed to do better than the Consistency approach.&lt;/p&gt;
&lt;p&gt;But I have a question about shader state optimization... &amp;nbsp;Right now we are making heavy use of Effect Parameter Blocks (for static state) since individual calls to set each parameter seems like a really bad idea.&lt;/p&gt;
&lt;p&gt;I'm curious though how fast EPB's are in XNA. &amp;nbsp;What is the underlying mechanism for commiting the parameter block to the GPU. &amp;nbsp;Since I assume the XNA EPB's are simply handles to the underlying native effect blocks in DX9 I guess they are pretty efficient.&lt;/p&gt;
&lt;p&gt;Can it be almost as quick as a native mode block copy? &amp;nbsp;If they are really this quick maybe Approach 1 (EMFH) might actually be the quickest.&lt;/p&gt;
&lt;p&gt;thoughts?&lt;/p&gt;
&lt;p&gt;Christian&lt;/p&gt;
</description></item></channel></rss>