While working on a project using D3D12 I was getting an exception being thrown while trying to get a D3D12_CPU_DESCRIPTOR_HANDLE. The project is using plain C so it uses the COBJMACROS. The following application replicates the problem happening in the project.
#define COBJMACROS
#pragma warning(push, 3)
#include <Windows.h>
#include <d3d12.h>
#include <dxgi1_4.h>
#pragma warning(pop)
IDXGIFactory4 *factory;
ID3D12Device *device;
ID3D12DescriptorHeap *rtv_heap;
int WINAPI
wWinMain(HINSTANCE hinst, HINSTANCE pinst, PWSTR cline, int cshow) {
(hinst), (pinst), (cline), (cshow);
HRESULT hr = CreateDXGIFactory1(&IID_IDXGIFactory4, (void **)&factory);
hr = D3D12CreateDevice(0, D3D_FEATURE_LEVEL_11_0, &IID_ID3D12Device, &device);
D3D12_DESCRIPTOR_HEAP_DESC desc;
desc.NumDescriptors = 1;
desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
desc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
desc.NodeMask = 0;
hr = ID3D12Device_CreateDescriptorHeap(device, &desc, &IID_ID3D12DescriptorHeap, (void **)&rtv_heap);
D3D12_CPU_DESCRIPTOR_HANDLE rtv = ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(rtv_heap);
(rtv);
}
The call to ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart throws an exception. Stepping into the disassembly for ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart show that the error occurs on the instruction
mov qword ptr [rdx],rax
which seems odd since rdx doesn't appear to be used. Any help would be greatly appreciated. Thank you.