Advertisement Jump to content

Shader Resource Binding

This topic is 488 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

Hello, I am trying to set some shader values in a cbuffer. Im not getting any response or values.

My code is:

cbuffer MatrixBuffer : register(b0) 
{ float4 test; 
#pragma pack(push,1) 
D3DXVECTOR4 test; 
#pragma pack(pop) 
ZeroMemory( &cbDesc, sizeof(cbDesc) );
cbDesc.Usage = D3D11_USAGE_DYNAMIC; 
cbDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; 
cbDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; 
cbDesc.ByteWidth = sizeof( CB_GBUFFER_UNPACK ); 
device->CreateBuffer( &cbDesc, NULL, &m_pGBufferUnpackCB ); 
ic->Map( m_pGBufferUnpackCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &MappedResource ); 
CB_GBUFFER_UNPACK* pGBufferUnpackCB = ( CB_GBUFFER_UNPACK* )MappedResource.pData; 
pGBufferUnpackCB->test.x = 10.0f; pGBufferUnpackCB->test.y = 10.0f; pGBufferUnpackCB->test.z = 10.0f; pGBufferUnpackCB->test.w = 0.0f; 
ic->Unmap( m_pGBufferUnpackCB, 0 ); 
ic->PSSetConstantBuffers( 0, 1, &m_pGBufferUnpackCB );

What is wrong?

Edited by terrysworkstations

Share this post

Link to post
Share on other sites

This should be in the shader

On 9/7/2017 at 9:44 AM, terrysworkstations said:

cbuffer MatrixBuffer : register(b0) { float4 test; };

What is


It should be a ID3D11Buffer*

Also, why are you initializing pGBufferUnpackCB to (CB_GBUFFER_UNPACK*)MappedResource.pData, then filling it in manually the next line?

those lines should be something like:


// Fill in the data for pGBufferUnpackCB

// I don't like filling in a struct's data while Map() is called, so I moved this down two lines
ic->Map(m_pGBufferUnpackCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &MappedResource);

// memcpy(destination, source, sizeof(source));
memcpy(MappedResource.pData, pGBufferUnpackCB, sizeof(pGBufferUnpackCB));


Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!