Jump to content
  • Advertisement
terrysworkstations

Shader Resource Binding

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) 
struct CB_GBUFFER_UNPACK 
{ 
D3DXVECTOR4 test; 
}; 
#pragma pack(pop) 
-------------------------------------------------
D3D11_BUFFER_DESC cbDesc;
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 ); 
D3D11_MAPPED_SUBRESOURCE MappedResource; 
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
Advertisement

This should be in the shader

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

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

What is

m_pGBufferUnpackCB

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:

CB_GBUFFER_UNPACK* pGBufferUnpackCB = new CB_GBUFFER_UNPACK;

// 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 GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!