Sign in to follow this  
BlackBrain

Problem With Creation of TypedBuffer

Recommended Posts

BlackBrain    517

Hello.

 

I want to create a typedBuffer in SharpDX but when I tr to create a ShaderResourceView for it, gives me this error : 

Additional information: HRESULT: [0x80070057], Module: [General], ApiCode: [E_INVALIDARG/Invalid Arguments], Message: The parameter is incorrect.

 

The Code : 

 public RWIntBuffer(int MaximumCount, int[] initialData, bool IsDynamic = false)
        {
            this.IsDynamic = IsDynamic;
            int stride = Marshal.SizeOf(typeof(int));
            DataStream stream = new DataStream(MaximumCount*stride,false, true);
            if (initialData != null)
                stream.WriteRange<int>(initialData);

            ResourceUsage usage = ResourceUsage.Default;
            if(IsDynamic)
                usage = ResourceUsage.Dynamic;

            buffer = new Buffer(GraphicsRenderer.device, stream, stride * MaximumCount, usage, BindFlags.ShaderResource | BindFlags.UnorderedAccess, IsDynamic ? CpuAccessFlags.Write : CpuAccessFlags.None, ResourceOptionFlags.BufferAllowRawViews, stride);

            ShaderResourceViewDescription desc = new ShaderResourceViewDescription();
            desc.Dimension = ShaderResourceViewDimension.Buffer;
           desc.Format = SharpDX.DXGI.Format.R32_UInt;




           ShaderView = new ShaderResourceView(GraphicsRenderer.device, buffer,desc);

            UnorderedAccessViewDescription desc2 = new UnorderedAccessViewDescription();
            desc2.Format = SharpDX.DXGI.Format.R32_SInt;
            desc2.Dimension = UnorderedAccessViewDimension.Buffer;

            UnorderedView = new UnorderedAccessView(GraphicsRenderer.device, buffer,desc2);
        }

Help Me pls , Thanks in advance. 

Edited by BlackBrain

Share this post


Link to post
Share on other sites
BlackBrain    517

Excuse me , I thought u meant The message of the pop up window. In the output I got this :

 

D3D11 ERROR: ID3D11Device::CreateShaderResourceView: The Dimensions of the View are invalid due to at least one of the following conditions. Assuming this Format (0x2a, R32_UINT), ElementOffset (value = 0) must be between 0 and the maximum offset of the Buffer, 121599, inclusively. With the current ElementOffset, ElementWidth (value = 0) must be between 1 and 121600, inclusively, in order that the View fit on the Buffer. [ STATE_CREATION ERROR #128: CREATESHADERRESOURCEVIEW_INVALIDDIMENSIONS]
 
First-chance exception at 0x7620C41F in SharpdxTest2.exe: Microsoft C++ exception: _com_error at memory location 0x0045E6DC.
D3D11 ERROR: ID3D11Device::CreateShaderResourceView: Returning E_INVALIDARG, meaning invalid parameters were passed. [ STATE_CREATION ERROR #131: CREATESHADERRESOURCEVIEW_INVALIDARG_RETURN]
 
A first chance exception of type 'SharpDX.SharpDXException' occurred in SharpDX.dll
An unhandled exception of type 'SharpDX.SharpDXException' occurred in SharpDX.dll
Additional information: HRESULT: [0x80070057], Module: [General], ApiCode: [E_INVALIDARG/Invalid Arguments], Message: The parameter is incorrect.

Share this post


Link to post
Share on other sites
AlexandreMutel    1105

 

Excuse me , I thought u meant The message of the pop up window. In the output I got this :

 

This was explicitly explained in the link above, item 3) "And check the output log of Visual Studio in the Output Log tab"

 

 

D3D11 ERROR: ID3D11Device::CreateShaderResourceView: The Dimensions of the View are invalid due to at least one of the following conditions. Assuming this Format (0x2a, R32_UINT), ElementOffset (value = 0) must be between 0 and the maximum offset of the Buffer, 121599, inclusively. With the current ElementOffset, ElementWidth (value = 0) must be between 1 and 121600, inclusively, in order that the View fit on the Buffer. [ STATE_CREATION ERROR #128: CREATESHADERRESOURCEVIEW_INVALIDDIMENSIONS]

 

You should be able to see your problem with this message.

 

When you create a buffer view, you need to tell the range of data that is going into the view. In your sample, you don't define this. Check the documentation D3D11_SHADER_RESOURCE_VIEW_DESC , D3D11_BUFFER_SRV doc,  For this Shader Resource View you need to define ElementOffset and ElementWidth but the error message (and documentation) is a bit misleading because they should suggest the number of elements, not the size of a single element, so prefer using ElementCount and FirstElement, like this:

var desc = new ShaderResourceViewDescription();
desc.Dimension = ShaderResourceViewDimension.Buffer;
desc.Format = SharpDX.DXGI.Format.R32_UInt;
desc.Buffer.FirstElement = 0;    // same as ElementOffset in error message but more appropriate
desc.Buffer.ElementCount = MaximumCount; // same as ElementWidth in error message but more appropriate

You will get probably similar error for the declaration of UAV view.

Edited by xoofx

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