3d SetGraphicsRootDescriptable给出了不明确的错误

3d SetGraphicsRootDescriptable给出了不明确的错误,3d,directx-12,3d,Directx 12,我对SetGraphicsRootDescriptorTable的一次调用返回以下错误: D3D12错误:CGraphicsCommandList::SetGraphicsRootDescriptorTable:包含句柄0x0546DDE0的描述符堆(0x052184B0:'m_lightBufHeap')与当前设置的描述符堆(null)不同。[执行错误#708:设置_描述符_表_无效] 我不明白它想告诉我什么。到底有什么不同,为什么这是一个问题 更改我试图设置的描述符堆的内容似乎无法解决任何问

我对SetGraphicsRootDescriptorTable的一次调用返回以下错误:

D3D12错误:CGraphicsCommandList::SetGraphicsRootDescriptorTable:包含句柄0x0546DDE0的描述符堆(0x052184B0:'m_lightBufHeap')与当前设置的描述符堆(null)不同。[执行错误#708:设置_描述符_表_无效]

我不明白它想告诉我什么。到底有什么不同,为什么这是一个问题

更改我试图设置的描述符堆的内容似乎无法解决任何问题

我减小了描述符堆的大小,使其只容纳1个元素

以下是创建描述符堆的方法:

    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);
这就是我创建根签名参数的方式(param 4是我的缓冲区):

以下是创建着色器资源视图的方式:

        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); 
缓冲区m_lightsBuffer似乎没有问题,我也尝试用有效的Texture2D填充描述符堆,结果相同。所以它不是来自缓冲区

以下是我的着色器声明缓冲区的方式:

StructuredBuffer<LightBlob> lightBlobs : register(t3);
当前设置的描述符堆(null)

这似乎就是线索。在提交命令列表之前,您是否调用了
SetDescriptorHeaps

DirectX 12的典型绘图代码为:

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是一个专家级图形API,假设您已经了解DirectX 11。如果你没有,你真的应该看看。如果你是的话,你可能会发现它很有用。还有一系列介绍性图形示例,其中包括DirectX 11和DirectX 12

DirectX 12让应用程序负责很多工作,因此调试非常具有挑战性。因此,您应该已经真正掌握了DirectX 11调试,否则您的工作效率会有问题

当前设置的描述符堆(null)

这似乎就是线索。在提交命令列表之前,您是否调用了
SetDescriptorHeaps

DirectX 12的典型绘图代码为:

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是一个专家级图形API,假设您已经了解DirectX 11。如果你没有,你真的应该看看。如果你是的话,你可能会发现它很有用。还有一系列介绍性图形示例,其中包括DirectX 11和DirectX 12

DirectX 12让应用程序负责很多工作,因此调试非常具有挑战性。因此,您应该已经真正掌握了DirectX 11调试,否则您的工作效率会有问题

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