1
votes

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
Does sizeof(GsConstDataTri) give you the right size? Off the top of my head, I'm not sure it will give you the full size of the array, it might only give you the size of the pointer. - cehnehdeh
It does give the right size (16384) but when I check the buffer which gets used it says size 65536. I don't think that's correct? (same for the other buffer ofc) - Achille Depla
I think you need to not pass the address of the pointers when you set pSysMem, so remove the &. That pointer is a pointer to the memory. This makes it a void*, which means all type security is thrown out the window. - cehnehdeh
I was following this example of MS msdn.microsoft.com/en-us/library/windows/desktop/…. When I remove the & I get an error message because pSysMem require a void pointer. - Achille Depla
Never mind, you're right, I thought it was dynamically allocated. Due to really weird byte-alignment stuff, there might be an offset. Try giving the address of the actual array, so GsConstDataTri.triTable - cehnehdeh

1 Answers

0
votes

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.