{"id":2624,"date":"2019-11-13T12:16:30","date_gmt":"2019-11-13T20:16:30","guid":{"rendered":"http:\/\/devblogs.microsoft.com\/directx\/?p=2624"},"modified":"2019-11-13T12:24:30","modified_gmt":"2019-11-13T20:24:30","slug":"coming-to-directx-12-d3d9on12-and-d3d11on12-resource-interop-apis","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/directx\/coming-to-directx-12-d3d9on12-and-d3d11on12-resource-interop-apis\/","title":{"rendered":"Coming to DirectX 12: D3D9On12 and D3D11On12 Resource Interop APIs"},"content":{"rendered":"<p>D3D is introducing D3D9on12 with resource interop APIs and adding similar resource interop APIs to D3D11on12.\u00a0 With this new support, callers can now retrieve the underlying D3D12 resource from the D3D11 or D3D9 resource object even when the resource was created with D3D11 or D3D9 API.\u00a0\u00a0\u00a0The new D3D9On12 API can be found in the insider SDK in D3D9on12.h.\u00a0 These features are available in Windows Insider builds now and do not require new drivers to work.<\/p>\n<p>You can explicitly create D3D9 with D3D9On12 using new overrides:<\/p>\n<pre class=\"lang:c++ decode:true\">typedef struct _D3D9ON12_ARGS\r\n{\r\n    BOOL Enable9On12;\r\n    IUnknown *pD3D12Device;\r\n    IUnknown *ppD3D12Queues[MAX_D3D9ON12_QUEUES];\r\n    UINT NumQueues;\r\n    UINT NodeMask;\r\n} D3D9ON12_ARGS;\r\n\r\ntypedef HRESULT (WINAPI *PFN_Direct3DCreate9On12Ex)(UINT SDKVersion, D3D9ON12_ARGS *pOverrideList, UINT NumOverrideEntries, IDirect3D9Ex** ppOutputInterface);\r\nHRESULT WINAPI Direct3DCreate9On12Ex(UINT SDKVersion, D3D9ON12_ARGS *pOverrideList, UINT NumOverrideEntries, IDirect3D9Ex** ppOutputInterface);\r\n\r\ntypedef IDirect3D9* (WINAPI *PFN_Direct3DCreate9On12)(UINT SDKVersion, D3D9ON12_ARGS *pOverrideList, UINT NumOverrideEntries);\r\nIDirect3D9* WINAPI Direct3DCreate9On12(UINT SDKVersion, D3D9ON12_ARGS *pOverrideList, UINT NumOverrideEntries);\r\n<\/pre>\n<p>D3D9 begins by creating an active display adapter enumerator.\u00a0 These new entry points allow you to override each adapter to use D3D9On12 or not by setting Enable9On12 to TRUE and a D3D12 device with an adapter LUID that matches the adapter you want to provide.\u00a0 Optionally use an entry with a nullptr D3D12 device to match any active display adapter and have D3D9On12 create the D3D12 device.<\/p>\n<p>Call QueryInterface on the D3D9 device for IDirect3DDevice9On12 to find out if the device is running on 9On12.\u00a0 QueryInterface will fail with E_NOINTERFACE when not running on D3D9On12.<\/p>\n<p>From this interface, you can retrieve the underlying D3D12 device:<\/p>\n<pre class=\"lang:c++ decode:true \">HRESULT GetD3D12Device(\r\n    REFIID riid, \r\n   _COM_Outptr_ void** ppvDevice);\r\n<\/pre>\n<p>IDirect3DDevice9On12 also has resource interop APIs to access the underlying D3D12 resource.\u00a0 Begin by calling UnwrapUnderlyingResource to retrieve the D3D12 resource pointer.\u00a0 UnwrapUnderlyingResource also takes an ID3D12Queue instance as an input parameter.\u00a0 Any pending work accessing the resource causes fence waits to be scheduled on this queue.\u00a0 Callers can then queue further work on this queue, including a signal on a caller owned fence.<\/p>\n<pre class=\"lang:c++ decode:true\">HRESULT UnwrapUnderlyingResource(\r\n    _In_ IDirect3DResource9* pResource9, \r\n    _In_ ID3D12CommandQueue* pCommandQueue,\r\n    REFIID riid,\r\n    _COM_Outptr_ void** ppvResource12 );\r\n<\/pre>\n<p>Once D3D12 work has been scheduled, call ReturnUnderlyingResource.\u00a0\u00a0 ReturnUnderlyingResource API takes a list of ID3D12Fence instances and a parallel list of signal values.\u00a0 This must include any pending work against the resource submitted by the caller.\u00a0 The translation layer defers the waits for these resources until work is scheduled against the resource.<\/p>\n<pre class=\"lang:c++ decode:true\">HRESULT ReturnUnderlyingResource(\r\n    _In_ IDirect3DResource9* pResource9, \r\n    UINT NumSync,\r\n    _In_reads_(NumSync) UINT64* pSignalValues,\r\n    _In_reads_(NumSync) ID3D12Fence** ppFences );\r\n<\/pre>\n<p>Be aware that unwrapping a resource checks out the resource from the translation layer.\u00a0 No translation layer usage through either the D3D9 API may be scheduled while the resource is checked out.<\/p>\n<p>Similar support is also added to D3D11On12 with the ID3D11On12Device2.<\/p>\n<pre class=\"lang:c++ decode:true\">ID3D11On12Device2 : public ID3D11On12Device1\r\n{\r\npublic:\r\n    virtual HRESULT STDMETHODCALLTYPE UnwrapUnderlyingResource( \r\n        _In_  ID3D11Resource *pResource11,\r\n        _In_  ID3D12CommandQueue *pCommandQueue,\r\n        REFIID riid,\r\n        _COM_Outptr_  void **ppvResource12) = 0;\r\n        \r\n    virtual HRESULT STDMETHODCALLTYPE ReturnUnderlyingResource( \r\n        _In_  ID3D11Resource *pResource11,\r\n        UINT NumSync,\r\n        _In_reads_(NumSync)   UINT64 *pSignalValues,\r\n        _In_reads_(NumSync)   ID3D12Fence **ppFences) = 0;\r\n};\r\n<\/pre>\n<p>The main difference is that UnwrapUnderlyingResource does not flush and may schedule GPU work.\u00a0 You should flush after calling this method if the you externally wait for completion.<\/p>\n<p>This support is available now in the latest preview OS.\u00a0 For further information, the spec is also available <a href=\"https:\/\/nam06.safelinks.protection.outlook.com\/?url=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FDirectX-Specs%2Fblob%2Fmaster%2Fd3d%2FTranslationLayerResourceInterop.md&amp;data=02%7C01%7CRandy.Tidd%40microsoft.com%7C4f46c03a6c3f444201cc08d767d3eaf6%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637092032181373167&amp;sdata=YXZhfRM98WR66fU6lCp3j0XjWLt6Metad5WDU520Si0%3D&amp;reserved=0\">here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>D3D is introducing D3D9on12 with resource interop APIs and adding similar resource interop APIs to D3D11on12.\u00a0 With this new support, callers can now retrieve the underlying D3D12 resource from the D3D11 or D3D9 resource object even when the resource was created with D3D11 or D3D9 API.\u00a0\u00a0\u00a0The new D3D9On12 API can be found in the insider [&hellip;]<\/p>\n","protected":false},"author":5840,"featured_media":12651,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2624","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-directx"],"acf":[],"blog_post_summary":"<p>D3D is introducing D3D9on12 with resource interop APIs and adding similar resource interop APIs to D3D11on12.\u00a0 With this new support, callers can now retrieve the underlying D3D12 resource from the D3D11 or D3D9 resource object even when the resource was created with D3D11 or D3D9 API.\u00a0\u00a0\u00a0The new D3D9On12 API can be found in the insider [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/directx\/wp-json\/wp\/v2\/posts\/2624","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/directx\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/directx\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/directx\/wp-json\/wp\/v2\/users\/5840"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/directx\/wp-json\/wp\/v2\/comments?post=2624"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/directx\/wp-json\/wp\/v2\/posts\/2624\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/directx\/wp-json\/wp\/v2\/media\/12651"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/directx\/wp-json\/wp\/v2\/media?parent=2624"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/directx\/wp-json\/wp\/v2\/categories?post=2624"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/directx\/wp-json\/wp\/v2\/tags?post=2624"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}