8
\$\begingroup\$

I am really frustrated because my cbufer isn't updating. This is my VS:

cbuffer MatrixBuffer: register(b0)
{
float4x4 worldViewProj;

};

struct VertexIn
{
float4 Pos : POSITION;
float4 Color: COLOR;
};

struct PixelIn
{
float4 PosH : SV_POSITION;
float4 Color: COLOR;
};

PixelIn VS (VertexIn vin)
{
PixelIn vout;

vin.Pos.w = 1.0f;

vout.PosH = mul(vin.Pos, worldViewProj);

vout.Color = vin.Color;

return vout;
}

PixelIn VS1(VertexIn vin)
{
PixelIn vout;

vin.Pos.w = 1.0f;
vout.PosH = vin.Pos;

vout.Color = vin.Color;

return vout;
}

When using VS1 it draws correctly, but when using VS it doesn't draw anything?

Here is my CBUFFER update code

bool Game::UpdateShaders()
{
    HRESULT result;
    D3D11_MAPPED_SUBRESOURCE mappedResource;
    MatrixBufferType* dataPtr;

    worldViewProjM = worldM * viewM * projM;
    worldViewProjM = XMMatrixTranspose(worldViewProjM);
    result = md3dDeviceContext->Map(mMatrixBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
    if (FAILED(result))
    {
        MessageBoxW(mMainWnd, L"FAOE:", 0, 0);
        return false;
    }

    dataPtr = (MatrixBufferType*)mappedResource.pData;

    dataPtr->worldViewProj = worldViewProjM;

    md3dDeviceContext->Unmap(mMatrixBuffer, 0);

    int NBuffers = 0;

    md3dDeviceContext->VSSetConstantBuffers(0, 1, &mMatrixBuffer);
    //md3dDeviceContext->PSSetConstantBuffers(0, 1, &mMatrixBuffer);

    return true;
}

Here is my MATRIXBUFFERTYPE struct:

struct MatrixBufferType
{
        XMMATRIX worldViewProj;
};

This is called after I clear my depth stencil view and render target view. Does somebody know why my CBUFFER isn't updating?

Thanks in advance.

\$\endgroup\$
7
  • 1
    \$\begingroup\$ Are you sure the problem is no the matrix itself? The code generally looks correct for updating the CB. \$\endgroup\$ Aug 22, 2015 at 17:30
  • \$\begingroup\$ @ChuckWalbourn The matrix consists of a world matrix, which i specified as an identity matrix., a projection matrix which is just XMMatrixPerspectiveFovLH(0.25 * 3.1415, mClientWidth / mClientHeight, 1.0f, 100.0f); XMStoreFloat4x4(&projM, proj); and a View matrix which is just XMMATRIX V = XMMatrixLookAtLH(pos, target, up); \$\endgroup\$
    – Daniel Hop
    Aug 23, 2015 at 15:23
  • \$\begingroup\$ I see how you are computing it, but in the debugger you should inspect the values to make sure they are reasonable. \$\endgroup\$ Aug 23, 2015 at 20:50
  • \$\begingroup\$ @ChuckWalbourn How can I do that? \$\endgroup\$
    – Daniel Hop
    Aug 23, 2015 at 23:04
  • \$\begingroup\$ Viewing Data in the Debugger; Overview of Visual Studio Graphics Diagnostics \$\endgroup\$ Aug 24, 2015 at 0:18

2 Answers 2

0
\$\begingroup\$

you have to update your subresource (if i'm not mistaken):

md3dDeviceContext->UpdateSubresource(mMatrixBuffer, 0, NULL, &worldViewProjM, 0, 0);
\$\endgroup\$
2
  • \$\begingroup\$ I think you cant have a constant buffer who can map/unmap and UpdateSubresource. Because UpdateSubresource needs a Default usage buffer, and a Map.unmap needs a Dynamic buffer. I also tried just uodateSubresource, but that didn`t work either:( \$\endgroup\$
    – Daniel Hop
    Aug 23, 2015 at 15:08
  • \$\begingroup\$ You can either use UpdateSubresource or Map/Discard to update constants. See Windows to Reality: Getting the Most out of Direct3D 10 Graphics in Your Games \$\endgroup\$ Aug 23, 2015 at 20:50
-1
\$\begingroup\$

Setting the cbuffer variable to matrix fixed it for me. Thanks all for youre help!

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .