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());