0
\$\begingroup\$

I posted previously before about my two dynamic buffers not being dynamically updating the constant shader. The tessellation buffer isn't working because I have to manually update the tessellation factor inside the hull shader. I believe the camera position isn't updating either because when I perform distance adaptation the far edges are more tessellated then the what's truly in front of the camera. I have all the buffers set to dynamic. Inside the render loop I have them set as:

Here is the updating map and unmap functions.

 D3D11_MAPPED_SUBRESOURCE map;
                 CBUFFER_PER_OBJECT *cBufferTessPerObject;
                 ZeroMemory(&map, sizeof(D3D11_MAPPED_SUBRESOURCE));
                 devcon->Map(mesh.m_constantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map);

                // mesh.worldMatrix = XMMatrixIdentity();
                 mesh.worldMatrix = mesh.translationMatrix;
                 XMMATRIX world = XMMatrixTranspose(mesh.worldMatrix);
                 cBufferTessPerObject = (CBUFFER_PER_OBJECT*)map.pData;

                 cBufferTessPerObject->WorldMatrix = mesh.worldMatrix * CameraView * CameraProjection;
                 cBufferTessPerObject->viewMatrix = CameraView;
                 cBufferTessPerObject->projectionMatrix = CameraProjection;
                 cBufferTessPerObject->modelWorldMatrix = mesh.worldMatrix;
                 cBufferTessPerObject->isSelected = mesh.isSelected;

                 // Finally set the matrix constant buffer in the domain shader with the/ updated values.


                 devcon->Unmap(mesh.m_constantBuffer, 0);

                 cameraConstantBuffer *dataPtr1;
                 ZeroMemory(&map, sizeof(D3D11_MAPPED_SUBRESOURCE));
                 devcon->Map(camCbuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map);
                 dataPtr1 = (cameraConstantBuffer*)map.pData;

                 float cx = XMVectorGetX(CameraPosition);
                 float cy = XMVectorGetY(CameraPosition);
                 float cz = XMVectorGetZ(CameraPosition);

                 dataPtr1->cameraPosition = XMFLOAT3(cx, cy, cz);
                 dataPtr1->padding = 0.0f;
                 devcon->Unmap(camCbuffer, 0);


                 TessellationBufferType *dataPtr2;
                 ZeroMemory(&map, sizeof(D3D11_MAPPED_SUBRESOURCE));
                 devcon->Map(mesh.tessellationBuffer, 0 ,D3D11_MAP_WRITE_DISCARD, 0, &map);
                 dataPtr2 = (TessellationBufferType*)map.pData;

                 mesh.tessellationFactor = tessAmount;
                 dataPtr2->tessellationAmount = mesh.tessellationFactor;
                 dataPtr2->padding = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
                 devcon->Unmap(mesh.tessellationBuffer, 0);

                 mesh.multiBuffers[0] = mesh.m_constantBuffer;
                 mesh.multiBuffers[1] = camCbuffer;
                 mesh.multiBuffers[2] = mesh.tessellationBuffer;

                 devcon->VSSetShader(mesh.m_vertexShader, NULL, 0);
                 devcon->HSSetShader(mesh.m_hullShader, NULL, 0);
                 devcon->DSSetShader(mesh.m_domainShader, NULL, 0);
                 devcon->PSSetShader(mesh.m_pixelShader, NULL, 0);


                 devcon->VSSetConstantBuffers(0, 3, mesh.multiBuffers);
                 devcon->HSSetConstantBuffers(0, 3, mesh.multiBuffers);
                 devcon->DSSetConstantBuffers(0, 3, mesh.multiBuffers);
                 devcon->PSSetConstantBuffers(0, 3, mesh.multiBuffers);

I only got that from a directX Sample. Inside the shader file I have the three cbuffer structs.

cbuffer ConstantBuffer 
{
    float4x4 WorldMatrix;
    float4x4 viewMatrix;
    float4x4 projectionMatrix;
    float4x4 modelWorldMatrix;    // the rotation matrix
    float3 lightvec;      // the light's vector
    float4 lightcol;      // the light's color
    float4 ambientcol;    // the ambient light's color
    bool isSelected;
}

cbuffer cameraBuffer
{
float3 cameraDirection;
float padding;
}

cbuffer TessellationBuffer 
{
float tessellationAmount;
float3 padding2;

}

Am I missing something or would anyone know why wouldn't my buffers update to the shader file?

\$\endgroup\$
  • 1
    \$\begingroup\$ Can you also post the code where you are actually updating the constant buffers on the CPU - i.e. using Map/Unmap, or UpdateSubresource? Also, are you using the D3D11 debug layer and checking for any errors/warnings from it? \$\endgroup\$ – Nathan Reed Nov 1 '13 at 4:30
  • \$\begingroup\$ I'll be also working on my organization code skills because I realized that I have a hard time spotting issues in code. I can narrow it down but sometimes, it leaves me completely lost. A bit more error handling system would be in development too. \$\endgroup\$ – SICGames2013 Nov 2 '13 at 6:04
4
\$\begingroup\$

When you are calling the VSSetConstantBuffer(), it will locate the diffrent buffers on registers. It might do fine without register semantics in some cases, but this is really bad practice.
To start solving your problem you should start biding your constat buffers with register semantics.
In otherwords, like this:

cbuffer DataBuffer : register(b0) {};
cbuffer VertexHelperBuffer : register(b1) {};

I would refer you to this article, Microsoft clearly explains whats happening.
Buffer description

Next step is to make sure your Map/Updatesubresource function actualy works. In other words, know if itś returning S_OK or not.

After that, you can take a pix capture to see if the correct values went down the pipe.
this is a good video on how to use pix if you have visual studio 2012 <. video

\$\endgroup\$
  • \$\begingroup\$ Today, I gave it a try to bind with register the sematics which I believe is working, so I'm going to see whether or not the device map and unmap are returning a S_OK hresult. Because most of the functions are being intergrated to C# for the editor side pix always crashes. \$\endgroup\$ – SICGames2013 Nov 2 '13 at 5:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.