GetCPUDescriptorHandleForHeapStart stack corruption

前端 未结 1 558
有刺的猬
有刺的猬 2021-02-14 00:36

I\'ve stumbled upon a rather unusual problem while programming with DirectX 12.0. No research so far has been insightful.

I am programming using C (not C++). It would ap

相关标签:
1条回答
  • 2021-02-14 01:08

    SOLUTION

    Debug symbols for D3D12.DLL reveal just enough. Naming conventions (e.g. ID3D12DescriptionHeap::GetCPUDescriptorHandleForHeapStart) are a strong indication that the DLL is written in C++. A (hidden) second parameter is indeed passed to the method - a pointer to the output structure D3D12_CPU_DESCRIPTOR_HANDLE (comprising nothing more than just an integer, aliased as a structure. I don't know why they do this). I forgot that C++ differs from C in that C++ can return structures as return values, and that structures cannot be passed as a return via the accumulator (%EAX) register, so it must be passed as a pointer on the stack to the callee.

    The problem is bad C bindings (a Microsoft header bug). The following fix is proposed:

    Old code:

    D3D12_CPU_DESCRIPTOR_HANDLE (
        STDMETHODCALLTYPE *GetCPUDescriptorHandleForHeapStart )( 
        ID3D12DescriptorHeap * This);
    

    Replace with:

    void ( STDMETHODCALLTYPE *GetCPUDescriptorHandleForHeapStart )(
        ID3D12DescriptorHeap *This, D3D12_CPU_DESCRIPTOR_HANDLE *pOut);
    

    Thank you.

    0 讨论(0)
提交回复
热议问题