Constant buffer is empty when passed HLSL C++

836 views Asked by At

So I moved from this problem: Previous problem to this one :).

I made 2 constant buffers in C++ which I'm passing to my HLSL Shader but when I debug and look into the buffers they are just filled with zeros except the last 3 numbers (which are -572662307). I was following this example https://msdn.microsoft.com/en-us/library/windows/desktop/ff476896(v=vs.85).aspx

This is the code I'm using to create the buffer.

    // Define the constant data used to communicate with shaders.
__declspec(align(4)) struct GS_CONSTANT_BUFFER_EDGETABLE
{
    int edgeTable[256];
};
__declspec(align(4)) struct GS_CONSTANT_BUFFER_TRITABLE
{
    int triTable[256][16];
};

// Supply the gs constant data.
GS_CONSTANT_BUFFER_EDGETABLE GsConstDataEdge;
GS_CONSTANT_BUFFER_TRITABLE GsConstDataTri;
for (int i = 0; i < 256; ++i)
{
    GsConstDataEdge.edgeTable[i] = edgeTable[i];
    for (int j = 0; j < 16; ++j)        
        GsConstDataTri.triTable[i][j] = triTable[i][j];     
}

//EDGE
// Fill in a buffer description.
D3D11_BUFFER_DESC cbDesc1;
cbDesc1.ByteWidth = sizeof(GsConstDataEdge);
cbDesc1.Usage = D3D11_USAGE_DYNAMIC;
cbDesc1.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
cbDesc1.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
cbDesc1.MiscFlags = 0;
cbDesc1.StructureByteStride = 0;

// Fill in the subresource data.
D3D11_SUBRESOURCE_DATA InitData1;
InitData1.pSysMem = &GsConstDataEdge;
InitData1.SysMemPitch = 0;
InitData1.SysMemSlicePitch = 0;

// Create the buffer. 
auto hr = gameContext.pDevice->CreateBuffer(&cbDesc1, &InitData1, &g_pConstantBuffer1);

if (FAILED(hr)) 
    std::cout << "Error buffer creation1" << endl;  

// Set the buffer.
gameContext.pDeviceContext->GSSetConstantBuffers(0, 1, &g_pConstantBuffer1);
//

// TRI
// Fill in a buffer description.
D3D11_BUFFER_DESC cbDesc2;
cbDesc2.ByteWidth = sizeof(GsConstDataTri);
cbDesc2.Usage = D3D11_USAGE_DYNAMIC;
cbDesc2.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
cbDesc2.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
cbDesc2.MiscFlags = 0;
cbDesc2.StructureByteStride = 0;

// Fill in the subresource data.
D3D11_SUBRESOURCE_DATA InitData2;
InitData2.pSysMem = &GsConstDataTri;
InitData2.SysMemPitch = 0;
InitData2.SysMemSlicePitch = 0;

// Create the buffer. 
hr = gameContext.pDevice->CreateBuffer(&cbDesc2, &InitData2, &g_pConstantBuffer2);

if (FAILED(hr)) 
    std::cout << "Error buffer creation2" << endl;  

// Set the buffer.
gameContext.pDeviceContext->GSSetConstantBuffers(1, 1, &g_pConstantBuffer2);

This is the struct in my HLSL shader.

cbuffer GS_CONSTANT_BUFFER_EDGETABLE : register(b0)
{
    int edgeTable[256];
}

cbuffer GS_CONSTANT_BUFFER_TRITABLE : register(b1)
{
    int triTable[256][16];
}

EDIT: http://imgur.com/Xv7B1SO Now I do have the 2 buffers I created but they don't seems to get assigned to the cbuffers in the HLSL code.

1

There are 1 answers

0
Achille Depla On BEST ANSWER

Fixed it, I simply added it to the pipeline to soon. I had to assign it just before calling it the draw but after the get technique.