Direct3D 12 可以渲染到 Xaml.Media.Imaging.SurfaceImageSource 吗?

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

这里是我正在使用的教程。

查克已经说过两次这是可能的 https://stackoverflow.com/a/39683147/11998382

但是,

ISurfaceImageSourceNative::SetDevice
接受
IDXGIDevice
,这是 Direct3D 11 遗留的东西,Direct3D 12 不再支持。https://stackoverflow.com/a/40427079/11998382

ISurfaceImageSourceNative::SetDevice

docs
清楚地表明它是 Direct3D 11 拥有的资源。

设置使用 D3D11_CREATE_DEVICE_BGRA_SUPPORT 创建的 DXGI 设备,该设备将绘制表面。该方法必须从 UI 线程调用。

查克的回答是什么意思?这是否需要 11 和 12 之间的互操作? 我什至不认为 12 可以渲染到 11 拥有的纹理。 ChatGPT 认为使用共享句柄是可能的。

明天我要尝试与

ID3D11On12Device
一起。

xaml interop direct3d directx-12 dxgi
1个回答
0
投票

ID3D11On12Device
配合使用效果很好。

auto width_height = std::array{ 300U, 300U };
auto surfaceImageSource = winrt::Microsoft::UI::Xaml::Media::Imaging::SurfaceImageSource(width_height[0], width_height[1]);
auto m_sisNative = surfaceImageSource.as<ISurfaceImageSourceNative>();

winrt::check_hresult(m_sisNative->SetDevice(resources.dxgiDevice.get()));

winrt::com_ptr<IDXGISurface> surface;

POINT offset{};
RECT updateRect{0, 0, width_height[0], width_height[1]};
winrt::check_hresult(m_sisNative->BeginDraw(updateRect, surface.put(), &offset));

auto d3d11 = surface.as<ID3D11Resource>();
auto pResource = d3d11.get();
resources.m_d3d11On12Device->AcquireWrappedResources(&pResource, 1);

Chuck 链接到同一教程,其中有一个关于与

SurfaceImageSource
SwapChainPanel
互操作的部分。 他显然是指 DX12 可以使用
SwapChainPanel
进行互操作。然而,DX12 无法与
SurfaceImageSource
互操作。

© www.soinside.com 2019 - 2024. All rights reserved.