Jump to content
  • Advertisement
Sign in to follow this  
.nL

SharpDX: MRT problem

This topic is 1148 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been working on a toy engine for the last couple of weeks, and I've just started tackling the rendering portion of the framework.

 

I'm trying to build a deferred renderer, but every time I try to set the current render targets to my RenderTargetView[], I get the following error:

 
D3D11 CORRUPTION: ID3D11DeviceContext::OMSetRenderTargetsAndUnorderedAccessViews: Second parameter, array index 0 corrupt or unexpectedly NULL. [ MISCELLANEOUS CORRUPTION #14: CORRUPTED_PARAMETER2]
 
I'd expect that to mean that there was an issue with the way I was creating my render targets, but everything seems to be working fine when I point it to any specific index in my array.
 
It's probably worth noting that the array is stored in a 'renderer' class (as a raw array), and is generated using a description loaded from an external file.
 
 
I'm certain I'm probably missing something obvious, but I can't quite put my finger on what it is.
 
 
I'm setting the targets like so:
d3d11Context.OutputMerger.SetRenderTargets(mRenderer.depthStencilView, mRenderer.gBufferTargets);

My depth texture is currently always set to:

depthTextureDescription = new Texture2DDescription
{
   Format = SharpDX.DXGI.Format.D32_Float,
   Width = 1280,
   Height = 720,
   MipLevels = 1,
   ArraySize = 1,
   Usage = ResourceUsage.Default,
   BindFlags = BindFlags.DepthStencil,
   CpuAccessFlags = CpuAccessFlags.None,
   OptionFlags = ResourceOptionFlags.None,
   SampleDescription = new SharpDX.DXGI.SampleDescription { Count = 1}
};

My render target descriptions are in a json file as follows:

    "D3D11" :
        {
            "Shader" : "Default.hlsl",
            "Buffers" : {
                "Diffuse" : {
                    "Format"                : "R8G8B8A8_UNorm_SRgb",
                    "Usage"                 : "Default",
                    "BindFlags"             : ["RenderTarget", "ShaderResource"],
                    "AccessFlags"           : ["None"],
                    "SampleCount"           : 1,
                    "ResolutionMultiplier"  : 1.0,
                    "MipLevels"             : 1,
                    "MipSlice"              : 0
                },
                "Normal" : {
                    "Format"                : "R16G16B16A16_UNorm",
                    "Usage"                 : "Default",
                    "BindFlags"             : ["RenderTarget", "ShaderResource"],
                    "AccessFlags"           : ["None"],
                    "SampleCount"           : 1,
                    "ResolutionMultiplier"  : 1.0,
                    "MipLevels"             : 1
                    "MipSlice"              : 0
                },
                "Velocity" : {
                    "Format"                : "R8G8B8A8_UNorm_SRgb",
                    "Usage"                 : "Default",
                    "BindFlags"             : ["RenderTarget", "ShaderResource"],
                    "AccessFlags"           : ["None"],
                    "SampleCount"           : 1,
                    "ResolutionMultiplier"  : 1.0,
                    "MipLevels"             : 1
                    "MipSlice"              : 0
                },
            }
        }

Any help would be greatly appreciated.

 

Share this post


Link to post
Share on other sites
Advertisement

I think this might be because your render targets have different pixel format sizes. i.e. R8G8B8A8_UNorm_SRgb is a 32 bit-per-pixel format, R16G16B16A16_UNorm is twice that. I think all bound render targets need to be the same width. (edit: width per pixel I mean, in this context.)

 

You should probably also not use the sRGB buffer for your intermediate buffers. You should work in linear space until as late in the pipeline as possible, and certainly until after you've done your lighting.

Edited by BarrySkellern

Share this post


Link to post
Share on other sites

I think this might be because your render targets have different pixel format sizes. i.e. R8G8B8A8_UNorm_SRgb is a 32 bit-per-pixel format, R16G16B16A16_UNorm is twice that. I think all bound render targets need to be the same width. (edit: width per pixel I mean, in this context.)

That was a limitation in Direct3D9. In Direct3D11, according to MSDN, "These render target formats are not required to have identical bit-per-element counts."

 

Share this post


Link to post
Share on other sites

Sorry for the lathargic reply, thing became rather busy for a bit.

 

Here's how I'm creating the render targets:

                depthTextureDescription = new Texture2DDescription
                {
                    Format = SharpDX.DXGI.Format.D32_Float,
                    Width = 1280,
                    Height = 720,
                    MipLevels = 1,
                    ArraySize = 1,
                    Usage = ResourceUsage.Default,
                    BindFlags = BindFlags.DepthStencil,
                    CpuAccessFlags = CpuAccessFlags.None,
                    OptionFlags = ResourceOptionFlags.None,
                    SampleDescription = new SharpDX.DXGI.SampleDescription { Count = 1}
                };


                depthTexture = new Texture2D(device, depthTextureDescription);
                depthStencilView = new DepthStencilView(device, depthTexture);

                string jsonRaw = File.ReadAllText(fileName);
                if (jsonRaw == null) return false;

                Dictionary<string, object> pipeData = (Dictionary<string, object>)JSON.Parse(jsonRaw);
                if (pipeData == null) return false;

                pipeData = (Dictionary<string, object>)pipeData["D3D11"];

                if (!pipeData.ContainsKey("Buffers")) return false;
                Dictionary<string, object> bufferData = (Dictionary<string, object>)pipeData["Buffers"];

                depthStencilView = new DepthStencilView(device, depthTexture);

                depthTexture = new Texture2D(device, depthTextureDescription);
            
                foreach(KeyValuePair<string, object> bufferSpec in bufferData){
                    Dictionary<string, object> curData = (Dictionary<string, object>)bufferSpec.Value;
                    
                    ////////////////////////////////////
                    //Set bindflags, accessflags, etc./

                    BindFlags curBindFlags = BindFlags.None;
                    bool isFirst = true;
                    foreach (string curString in (List<object>)curData["BindFlags"])
                    {
                        if (!isFirst) { curBindFlags |= (BindFlags)Enum.Parse(typeof(BindFlags), curString); }
                        else { curBindFlags = (BindFlags)Enum.Parse(typeof(BindFlags), curString); isFirst = false; }
                    }

                    CpuAccessFlags curAccessFlags = CpuAccessFlags.None;
                    isFirst = true;
                    foreach (string curString in (List<object>)curData["AccessFlags"])
                    {
                        if (!isFirst) { curAccessFlags |= (CpuAccessFlags)Enum.Parse(typeof(CpuAccessFlags), curString); }
                        else { curAccessFlags = (CpuAccessFlags)Enum.Parse(typeof(CpuAccessFlags), curString); isFirst = false; }
                    }

                    ////////////////////////
                    //Current descriptions./
                    Texture2DDescription curTexDesc = new Texture2DDescription { 
                        Width = 1280,
                        Height = 720,
                        Format = (SharpDX.DXGI.Format)Enum.Parse(typeof(SharpDX.DXGI.Format), (string)curData["Format"]),
                        SampleDescription = new SharpDX.DXGI.SampleDescription{Count = Convert.ToInt32((Int64)curData["SampleCount"])},
                        Usage = (ResourceUsage)Enum.Parse(typeof(ResourceUsage), (string)curData["Usage"]),
                        MipLevels = Convert.ToInt32((Int64)curData["MipLevels"]),
                        ArraySize = 1};

                    curTexDesc.BindFlags = curBindFlags;
                    curTexDesc.CpuAccessFlags = curAccessFlags;

                    RenderTargetViewDescription curTargetDesc = new RenderTargetViewDescription { 
                        Format = curTexDesc.Format,
                        Dimension = RenderTargetViewDimension.Texture2D};

                    curTargetDesc.Texture2D.MipSlice = Convert.ToInt32((Int64)curData["MipSlice"]);
                    
                    gBufferTextureDescriptions.Add(curTexDesc);
                    gBufferTargetDescriptions.Add(curTargetDesc);

                    gBufferTextures.Add(new Texture2D(device, curTexDesc));

                    gBufferTargets.Add(new RenderTargetView(device, gBufferTextures[gBufferTextures.Count - 1], gBufferTargetDescriptions[gBufferTargetDescriptions.Count - 1]));

                }

(note, that though I'm using a list to store everything in this instance, the errors don't change if I use a standard linear array)

 

 

The only information SharpDX is spitting out in debug mode is what I had before:

D3D11 CORRUPTION: ID3D11DeviceContext::OMSetRenderTargetsAndUnorderedAccessViews: Second parameter, array index 0 corrupt or unexpectedly NULL. [ MISCELLANEOUS CORRUPTION #14: CORRUPTED_PARAMETER2]

I don't think there's an issue with any of the targets individually, as stetRenderTargets will work if I use the target's index in the array.

Share this post


Link to post
Share on other sites

Could you try the method d3d11Context.OutputMerger.SetTargets instead? as it is using internally the simpler method that doesn't touch UAV bindings... wondering if the UAV version is correctly working...

Share this post


Link to post
Share on other sites

Some googling found me this thread here from msdn:

https://social.msdn.microsoft.com/Forums/windowsapps/en-US/fa819e87-fe9c-4a87-a22f-7a5a06cc87d8/d3d11-corruption-id3d11devicecontextomsetrendertargets-second-parameter-array-index-0-does-not?forum=wingameswithdirectx

 

it basically says that this error occurs when you create an object on one Device but try to render it on a DeviceContext belonging to a different Device

Edited by Lordadmiral Drake

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!