ID3D11On12Device::CreateWrappedResource method

This method creates D3D11 resources for use with D3D 11on12.

Syntax


HRESULT CreateWrappedResource(
  [in]                  IUnknown              *pResource12,
  [in]            const D3D11_RESOURCE_FLAGS  *pFlags11,
                        D3D12_RESOURCE_STATES InState,
                        D3D12_RESOURCE_STATES OutState,
                        REFIID                riid,
  [out, optional]       void                  **ppResource11
);

Parameters

pResource12 [in]

Type: IUnknown*

A pointer to an already-created D3D12 resource or heap.

pFlags11 [in]

Type: const D3D11_RESOURCE_FLAGS*

A D3D11_RESOURCE_FLAGS structure that enables an application to override flags that would be inferred by the resource/heap properties. The D3D11_RESOURCE_FLAGS structure contains bind flags, misc flags, and CPU access flags.

InState

Type: D3D12_RESOURCE_STATES

The use of the resource on input, as a bitwise-OR'd combination of D3D12_RESOURCE_STATES enumeration constants.

OutState

Type: D3D12_RESOURCE_STATES

The use of the resource on output, as a bitwise-OR'd combination of D3D12_RESOURCE_STATES enumeration constants.

riid

Type: REFIID

The globally unique identifier (GUID) for the wrapped resource interface. The REFIID, or GUID, of the interface to the wrapped resource can be obtained by using the __uuidof() macro. For example, __uuidof(ID3D12Resource) will get the GUID of the interface to a wrapped resource.

ppResource11 [out, optional]

Type: void**

After the method returns, points to the newly created wrapped D3D11 resource or heap.

Return value

Type: HRESULT

This method returns one of the Direct3D 12 Return Codes.

Examples

Create render target views (RTVs), to render text using D2D on a D3D12 device.


    // Create descriptor heaps.
    {
        // Describe and create a render target view (RTV) descriptor heap.
        D3D12_DESCRIPTOR_HEAP_DESC rtvHeapDesc = {};
        rtvHeapDesc.NumDescriptors = FrameCount;
        rtvHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
        rtvHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
        ThrowIfFailed(m_d3d12Device->CreateDescriptorHeap(&rtvHeapDesc, IID_PPV_ARGS(&m_rtvHeap)));

        m_rtvDescriptorSize = m_d3d12Device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
    }

    // Create frame resources.
    {
        CD3DX12_CPU_DESCRIPTOR_HANDLE rtvHandle(m_rtvHeap->GetCPUDescriptorHandleForHeapStart());

        // Create a RTV, D2D render target, and a command allocator for each frame.
        for (UINT n = 0; n < FrameCount; n++)
        {
            ThrowIfFailed(m_swapChain->GetBuffer(n, IID_PPV_ARGS(&m_renderTargets[n])));
            m_d3d12Device->CreateRenderTargetView(m_renderTargets[n].Get(), nullptr, rtvHandle);

            // Create a wrapped 11On12 resource of this back buffer. Since we are 
            // rendering all D3D12 content first and then all D2D content, we specify 
            // the In resource state as RENDER_TARGET - because D3D12 will have last 
            // used it in this state - and the Out resource state as PRESENT. When 
            // ReleaseWrappedResources() is called on the 11On12 device, the resource 
            // will be transitioned to the PRESENT state.
            D3D11_RESOURCE_FLAGS d3d11Flags = { D3D11_BIND_RENDER_TARGET };
            ThrowIfFailed(m_d3d11On12Device->CreateWrappedResource(
                m_renderTargets[n].Get(),
                &d3d11Flags,
                D3D12_RESOURCE_STATE_RENDER_TARGET,
                D3D12_RESOURCE_STATE_PRESENT,
                IID_PPV_ARGS(&m_wrappedBackBuffers[n])
                ));

            // Create a render target for D2D to draw directly to this back buffer.
            ComPtr<IDXGISurface> surface;
            ThrowIfFailed(m_wrappedBackBuffers[n].As(&surface));
            ThrowIfFailed(m_d2dDeviceContext->CreateBitmapFromDxgiSurface(
                surface.Get(),
                &bitmapProperties,
                &m_d2dRenderTargets[n]
                ));

            rtvHandle.Offset(1, m_rtvDescriptorSize);

            ThrowIfFailed(m_d3d12Device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&m_commandAllocators[n])));
        }
    
    }


Refer to the Example Code in the D3D12 Reference.

Requirements

Header

D3d11on12.h

Library

D3D11.lib

DLL

D3D11.dll

See also

ID3D11On12Device

 

 

Show: