DirectX 12和C ++ CLI:无法使用IID_PPV_ARGS

问题描述 投票:0回答:1

对于给定的函数如下:

HRESULT D3D12CreateDevice(IUnknown * pAdapter,D3D_FEATURE_LEVEL MinimumFeatureLevel,REFIID riid,void ** ppDevice);

本机C ++使用它的方式是:

ID3D12Device* d3d12Device; 
D3D12CreateDevice(adapter, featureLevel, IID_PPV_ARGS(&d3d12Device));

问题是我无法在/ CLI项目中使用IID_PPV_ARGS,因为托管代码中存在某种不可访问的宏。

所以我尝试按照以前用DirectX 11和C ++ CLI执行的操作,如下所示:

ID3D12Device* d3d12Device; 
D3D12CreateDevice(adapter, featureLevel, __uuidof(ID3D12Device), (void**)&d3d12Device);

它不会产生任何编译器错误,但DX对象创建总是失败..它曾经与DX 11一起使用,但不再适用于DX12。

有人可以告诉我如何在C ++ CLI下初始化DX12对象吗?

非常感谢。

编辑1

D3D12CreateDevice使用以下语法(我做错了):

ID3D12Device* d3d12Device; 
D3D12CreateDevice(adapter, featureLevel, __uuidof(ID3D12Device), (void**)&d3d12Device);

但我无法获得CreateCommandQueue的正确语法。

HRESULT CreateCommandQueue(const D3D12_COMMAND_QUEUE_DESC * pDesc, REFIID riid,void ** ppCommandQueue);

此语法给出了强制转换错误:

_d3d12Device->CreateCommandQueue(&queueDesc, IID_ID3D12CommandQueue, (void**)&_commandQueue)

C2440'cast de type':无法将'cli :: interior_ptr'转换为'void **'

c++ pointers command-line-interface directx
1个回答
0
投票

好的,我发现了怎么做,我会在这里发布样本,如果它可以帮助其他人。

首先,不要像我这样的白痴,不要忘记pin_ptr你的原生对象的指针,否则GC将照顾他们,它越来越难以调试:)

DX 12中的传统资源创建:

pin_ptr<ID3D12CommandQueue*> pCmdQueue = &_commandQueue;
_d3d12Device->CreateCommandQueue(&queueDesc, __uuidof(**(&_commandQueue)), (void**)pCmdQueue);

DX 12中的QueryInterface:

pin_ptr<ID3D12DebugDevice1*> pDeviceDebug = &_d3d12DeviceDebug;
_d3d12Device->QueryInterface<ID3D12DebugDevice1>(pDeviceDebug);
© www.soinside.com 2019 - 2024. All rights reserved.