2

One of my calls to SetGraphicsRootDescriptorTable returns the following error:

D3D12 ERROR: CGraphicsCommandList::SetGraphicsRootDescriptorTable: The descriptor heap (0x052184B0:'m_lightBufHeap') containing handle 0x0546DDE0 is different from currently set descriptor heap (null). [ EXECUTION ERROR #708: SET_DESCRIPTOR_TABLE_INVALID]

I can't figure out what it wants to tell me. What exactly is different, and why it is a problem?

Changing the contents of the descriptor heap I'm trying to set does not seem to resolve anything.

I reduced the size of the descriptor heap to hold only 1 element.

This is how I create the descriptor heap:

    D3D12_DESCRIPTOR_HEAP_DESC heapDsc = {};
    heapDsc.NumDescriptors = 1;
    heapDsc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
    heapDsc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
    ThrowIfFailed(pDevice->CreateDescriptorHeap(&heapDsc, IID_PPV_ARGS(&m_lightBufHeap)));
    NAME_D3D12_OBJECT(m_lightBufHeap);

This is how I create the root signature parameters (param 4 is my buffer):

   CD3DX12_DESCRIPTOR_RANGE1 ranges[5];
    ranges[0].Init(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 2, 1, 0, D3D12_DESCRIPTOR_RANGE_FLAG_DATA_STATIC);
    ranges[1].Init(D3D12_DESCRIPTOR_RANGE_TYPE_CBV, 1, 0, 0, D3D12_DESCRIPTOR_RANGE_FLAG_DATA_STATIC);
    ranges[2].Init(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 0);
    ranges[3].Init(D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER, 2, 0);
    ranges[4].Init(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 3, 0, D3D12_DESCRIPTOR_RANGE_FLAG_DATA_STATIC);  // parameter 4, t3

    CD3DX12_ROOT_PARAMETER1 rootParameters[5];
    rootParameters[0].InitAsDescriptorTable(1, &ranges[0], D3D12_SHADER_VISIBILITY_PIXEL);
    rootParameters[1].InitAsDescriptorTable(1, &ranges[1], D3D12_SHADER_VISIBILITY_ALL);
    rootParameters[2].InitAsDescriptorTable(1, &ranges[2], D3D12_SHADER_VISIBILITY_PIXEL);
    rootParameters[3].InitAsDescriptorTable(1, &ranges[3], D3D12_SHADER_VISIBILITY_PIXEL);
    rootParameters[4].InitAsDescriptorTable(1, &ranges[4], D3D12_SHADER_VISIBILITY_ALL);

    CD3DX12_VERSIONED_ROOT_SIGNATURE_DESC rootSignatureDesc;
    rootSignatureDesc.Init_1_1(_countof(rootParameters), rootParameters, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT);

This is how I create the Shader Resource View:

        CD3DX12_CPU_DESCRIPTOR_HANDLE lightHeapHandle(m_lightBufHeap->GetCPUDescriptorHandleForHeapStart());

        D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
        srvDesc.ViewDimension = D3D12_SRV_DIMENSION_BUFFER;
        srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
        srvDesc.Buffer.FirstElement = 0;
        srvDesc.Buffer.NumElements = lights.size();
        srvDesc.Buffer.StructureByteStride = sizeof(LightStruct);

        pDevice->CreateShaderResourceView(m_lightsBuffer.Get(), &srvDesc, lightHeapHandle); 

The buffer m_lightsBuffer seems allright, I tried filling the descriptor heap with a valid Texture2D as well, same result. So it's not from the buffer.

This is how my shader declares the buffer:

StructuredBuffer<LightBlob> lightBlobs : register(t3);

In my command list I call:

//Parameter 4 in root signature     
pSceneCommandList->SetGraphicsRootDescriptorTable(4, m_lightBufHeap->GetGPUDescriptorHandleForHeapStart());
jsg
  • 23
  • 3

1 Answers1

3

currently set descriptor heap (null)

This seems to be the clue. Have you called SetDescriptorHeaps before submitting your command-list?

Typical draw code for DirectX 12 is:

commandList->SetGraphicsRootSignature(m_rootSignature.Get());

commandList->SetPipelineState(m_pipelineState.Get());

auto heap = m_srvHeap.Get();
commandList->SetDescriptorHeaps(1, &heap);

commandList->SetGraphicsRootDescriptorTable(0,
    m_srvHeap->GetGPUDescriptorHandleForHeapStart());

// Set necessary state.
commandList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
commandList->IASetVertexBuffers(0, 1, &m_vertexBufferView);
commandList->IASetIndexBuffer(&m_indexBufferView);

// Draw quad.
commandList->DrawIndexedInstanced(6, 1, 0, 0, 0);

DirectX 12 is an expert graphics API that assumes you already know DirectX 11. If you don't, you should really take a look at these tutorials. If you are, you might find the DirectX Tool Kit for DX12 useful. There are also a series of Introductory Graphics samples on Xbox-ATG-Graphics which cover both DirectX 11 and DirectX 12.

DirectX 12 puts the application in charge of a lot, so debugging is very challenging. As such, you should really have mastered DirectX 11 debugging or you'll have problems being productive.

Chuck Walbourn
  • 38,259
  • 2
  • 58
  • 81