# [DirectX11 & HLSL] Buffer Restrictions?

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

## Recommended Posts

Hi there,

in my program I use five buffers like the following (hlsl declaration):

 Buffer<float4> bufferExample : register( c1 ); 

Everything is working as intended so far. But somehow, when I add a sixth one - no matter what data I fill into it - the content appears to be zero, when I want to read it in the shader.

I don't see any logical explanation for that behaviour and it really drives me mad!

Can anyone enlighten me or is it probably a bug in my code? (as I coded it three times from scratch and the other five buffers are working, I don't think it is a bug)

For the sake of completeness, here the code I use in the application to set the buffer:

 ID3D11ShaderResourceView* g_srvTest; ID3D11Buffer* g_Test; int size = 4000; D3D11_BUFFER_DESC DescTest; DescTest.Usage = D3D11_USAGE_DYNAMIC; DescTest.BindFlags = D3D11_BIND_SHADER_RESOURCE; DescTest.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; DescTest.MiscFlags = 0; DescTest.ByteWidth = sizeof(D3DXVECTOR4) * size; hr = pd3dDevice->CreateBuffer( &DescTest, NULL, &g_Test ); if( FAILED( hr ) ) return; DXUT_SetDebugName( g_Test, "g_Test" ); D3D11_BUFFER_SRV srvBTest; srvBTest.ElementOffset = 0; srvBTest.ElementWidth = size; // create a Resource View and attach the Buffer to it D3D11_SHADER_RESOURCE_VIEW_DESC srvDescTest; srvDescTest.Format = DXGI_FORMAT_R32G32B32A32_FLOAT; srvDescTest.ViewDimension = D3D11_SRV_DIMENSION_BUFFER; srvDescTest.Buffer = srvBTest; hr = pd3dDevice->CreateShaderResourceView( g_Test, &srvDescTest, &g_srvTest ); if( FAILED( hr ) ) return; D3D11_MAPPED_SUBRESOURCE MappedResourceTest; pd3dImmediateContext->Map( g_Test, 0, D3D11_MAP_WRITE_DISCARD, 0, &MappedResourceTest ); D3DXVECTOR4* testData = ( D3DXVECTOR4* )MappedResourceTest.pData; for( int i = 0; i < size; i++) { testData[0] = 20.0f; testData[1] = 20.0f; testData[2] = 20.0f; testData[3] = 20.0f; } pd3dImmediateContext->Unmap( g_Test, 0 ); pd3dImmediateContext->PSSetShaderResources(1, 1, &g_srvTest); 

PS I also experienced the weird behaviour, that the program crashes, when I swap the index of two buffers.

i.e. I change:
 Buffer<float4> bufferExample1 : register( c1 ); Buffer<float4> bufferExample2 : register( c2 ); 
to:
 Buffer<float4> bufferExample2 : register( c1 ); Buffer<float4> bufferExample1 : register( c2 ); 

and at the same time:
 pd3dImmediateContext->PSSetShaderResources(1, 1, &g_srvTest1); pd3dImmediateContext->PSSetShaderResources(2, 1, &g_srvTest2); 
to:
 pd3dImmediateContext->PSSetShaderResources(1, 1, &g_srvTest2); pd3dImmediateContext->PSSetShaderResources(2, 1, &g_srvTest1); 

Does someone know the reason therefore?

##### Share on other sites
Have you tried running with the reference device yet? Perhaps your drivers are not quite up to snuff... Also, is there any debug output in the debug window??? The other easy thing to check is to take a frame grab with PIX and ensure that the references you pass to the API for your buffers are all valid.

In general, there is no limitation of having 5 shader resource views (I'm assuming you are using shader model 5 - is that a valid assumption?), and there certainly shouldn't be any crashes caused by swapping the indices of two buffer resources. One thing that I did notice is that you are using the c0, c1, c2 syntax for your buffers. I normally use the t0, t1, t2 syntax - I don't know if that would cause these types of problems, but it would be an easy thing to check.

##### Share on other sites
Oh well.. the reason of my problem is just as simple as it could be: I was stupid.

It's working now - thanks for your efforts.

1. 1
2. 2
3. 3
4. 4
Rutin
16
5. 5

• 12
• 9
• 12
• 37
• 12
• ### Forum Statistics

• Total Topics
631419
• Total Posts
2999981
×