[SharpDX] Understanding DX11 blend states

Started by
8 comments, last by AlexandreMutel 11 years ago

In dx9, the blend state was fairly simple. In dx11, it's a lot more complicated and I'm having trouble understanding how I need to have it set. I have a small app that is supposed to draw several instances of tessellated bezier triangles, and even though I have the pixel shader set to just paint one color, I'm not seeing that color on my screen at all. I've looked at my app with PIX (I use VS 2012 Express so it's my only debugging option for now.) and my vertex buffers seem to be doing what they are supposed to.

Right now I'm wondering about the blend state because I don't fully understand it. Here is how I have it set in my render method:


            RenderTargetBlendDescription rendBlendDesc = new RenderTargetBlendDescription();
            rendBlendDesc.SourceAlphaBlend = BlendOption.One;
            rendBlendDesc.DestinationAlphaBlend = BlendOption.Zero;
            rendBlendDesc.BlendOperation = BlendOperation.Add;
            rendBlendDesc.SourceBlend = BlendOption.One;
            rendBlendDesc.DestinationBlend = BlendOption.Zero;

            BlendStateDescription blendDesc = new BlendStateDescription();
            blendDesc.AlphaToCoverageEnable = false;
            blendDesc.IndependentBlendEnable = false;
            blendDesc.RenderTarget[0] = rendBlendDesc;

            BlendState blendState = new BlendState(Game.GraphicsDevice, blendDesc);
            Game.GraphicsDevice.ImmediateContext.OutputMerger.SetBlendState(blendState);

Do you see anything here that would prevent drawing from being visible?

Advertisement

Your blend state will result in the pixel shader value being written to the render target(s), and completely overwriting any existing contents of the render target. This is pretty standard for rendering without any blending. If you're not seeing your primitives, then the problem is probably somewhere else.

I would recommend enabling device debug messages if you haven't already, and checking for any warning or messages. Pass the "Debug" flag when creating your device to specify that you want messages, and then enable native debugging for your project. You should then get messages in your debugger output window. If you're using an express version of VS or you don't want to turn on native debugging, you can use a program like DebugView to view the native debugger output stream.

I used to use DebugView for my dx9 stuff and it was very useful. This time though I'm not seeing any warnings in the DebugView window even though I have created my device with the debug option. Does dx11 have a messaging level like dx9 had? I haven't used DebugView for a couple of years, and I can't remember all the steps necessary to capture messages from my app.

Do you see the triangles without this blending turned on?
If not, then 2 quick tips: forgot to transpose the viewprojection matrix, or forgot to set some constant buffer to the proper shaders. At least those are my main 2 sources of pain nowadays. rolleyes.gif

You can turn on dx debug in sdk->utilities->Directx control panel, if you haven't already. I got some usefull info about not setting the proper patch type for my hull shader, which made the driver reset, so it can be usefull,but not a magic bullet.

I used to use DebugView for my dx9 stuff and it was very useful. This time though I'm not seeing any warnings in the DebugView window even though I have created my device with the debug option. Does dx11 have a messaging level like dx9 had? I haven't used DebugView for a couple of years, and I can't remember all the steps necessary to capture messages from my app.


There's not really a "message level" anymore. There's functionality to filter out certain warnings/errors using the ID3D11InfoQueue interface, but by default you get all possible warnings and errors.

If you're not getting any messages, then it's possible you're not causing any errors or warnings. To find out for sure, you could try to deliberately cause an error by passing an incorrect parameter to a function, or something like that.

You will be able to see D3D11 messages directly from the output window if you check "Enable native code debugging" in the Project Properties/Debug tab (you need to use the debugger to see the messages) otherwise DebugView is still an option.

Thanks everyone, of course things are made worse by the fact that I have to stick with express version of VS for now. Very hard to learn dx11 with express.

You will be able to see D3D11 messages directly from the output window if you check "Enable native code debugging" in the Project Properties/Debug tab (you need to use the debugger to see the messages) otherwise DebugView is still an option.

Oh my gosh! This is working with express! Somebody told me it wouldn't. Now I have about 100 pages of warnings to examine. Thanks!

You may find it useful to have the debugger break on those warnings, in which case take a look at http://blogs.msdn.com/b/chuckw/archive/2012/11/30/direct3d-sdk-debug-layer-tricks.aspx

I'm not sure how easy it would be to interface with that API from C# though, as the SharpDX implementation looks incomplete.

I'm not sure how easy it would be to interface with that API from C# though, as the SharpDX implementation looks incomplete.

It is not incomplete, the class is marked as "partial" so the other part of the code is generated at built time by the DirectX C++ to C# code generator used in SharpDX.

Edit: Though there are here some NotImplementedException for GetStorageFilter/GetRetrievalFilter, will have to double check :D

This topic is closed to new replies.

Advertisement