D3D11On12CreateDevice function (d3d11on12.h) - Win32 apps (2024)

  • Article

Creates a device that uses Direct3D 11 functionality in Direct3D 12, specifying a pre-existing Direct3D 12 device to use for Direct3D 11 interop.

Syntax

HRESULT D3D11On12CreateDevice( [in] IUnknown *pDevice, UINT Flags, [in, optional] const D3D_FEATURE_LEVEL *pFeatureLevels, UINT FeatureLevels, [in, optional] IUnknown * const *ppCommandQueues, UINT NumQueues, UINT NodeMask, [out, optional] ID3D11Device **ppDevice, [out, optional] ID3D11DeviceContext **ppImmediateContext, [out, optional] D3D_FEATURE_LEVEL *pChosenFeatureLevel);

Parameters

[in] pDevice

Type: IUnknown*

Specifies a pre-existing Direct3D 12 device to use for Direct3D 11 interop. May not be NULL.

Flags

Type: UINT

One or more bitwise OR'd flags from D3D11_CREATE_DEVICE_FLAG. These are the same flags as those used by D3D11CreateDeviceAndSwapChain. Specifies which runtime layers to enable. Flags must be compatible with device flags, and its NodeMask must be a subset of the NodeMask provided to the present API.

[in, optional] pFeatureLevels

Type: const D3D_FEATURE_LEVEL*

An array of any of the following:

  • D3D_FEATURE_LEVEL_12_1
  • D3D_FEATURE_LEVEL_12_0
  • D3D_FEATURE_LEVEL_11_1
  • D3D_FEATURE_LEVEL_11_0
  • D3D_FEATURE_LEVEL_10_1
  • D3D_FEATURE_LEVEL_10_0
  • D3D_FEATURE_LEVEL_9_3
  • D3D_FEATURE_LEVEL_9_2
  • D3D_FEATURE_LEVEL_9_1

The first feature level that is less than or equal to the Direct3D 12 device's feature level will be used to perform Direct3D 11 validation. Creation will fail if no acceptable feature levels are provided. Providing NULL will default to the Direct3D 12 device's feature level.

FeatureLevels

Type: UINT

The size of (that is, the number of elements in) the pFeatureLevels array.

[in, optional] ppCommandQueues

Type: IUnknown* const *

An array of unique queues for D3D11On12 to use. The queues must be of the 3D command queue type.

NumQueues

Type: UINT

The size of (that is, the number of elements in) the ppCommandQueues array.

NodeMask

Type: UINT

Which node of the Direct3D 12 device to use. Only 1 bit may be set.

[out, optional] ppDevice

Type: ID3D11Device**

Pointer to the returned ID3D11Device. May be NULL.

[out, optional] ppImmediateContext

Type: ID3D11DeviceContext**

A pointer to the returned ID3D11DeviceContext. May be NULL.

[out, optional] pChosenFeatureLevel

Type: D3D_FEATURE_LEVEL*

A pointer to the returned feature level. May be NULL.

Return value

Type: HRESULT

This method returns one of the Direct3D 12 Return Codes that are documented for D3D11CreateDevice.

This method returns DXGI_ERROR_SDK_COMPONENT_MISSING if you specify D3D11_CREATE_DEVICE_DEBUG in Flags and the incorrect version of the debug layer is installed on your computer. Install the latest Windows SDK to get the correct version.

Remarks

The function signature PFN_D3D11ON12_CREATE_DEVICE is provided as a typedef, so that you can use dynamic linking techniques (GetProcAddress) instead of statically linking.

Examples

To render text over Direct3D 12 using Direct2D via the 11On12 device, load the rendering pipeline dependencies.

// Load the rendering pipeline dependencies.void D3D1211on12::LoadPipeline(){ UINT d3d11DeviceFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT; D2D1_FACTORY_OPTIONS d2dFactoryOptions = {};#if defined(_DEBUG) // Enable the D2D debug layer. d2dFactoryOptions.debugLevel = D2D1_DEBUG_LEVEL_INFORMATION; // Enable the Direct3D 11 debug layer. d3d11DeviceFlags |= D3D11_CREATE_DEVICE_DEBUG; // Enable the Direct3D 12 debug layer. { ComPtr<ID3D12Debug> debugController; if (SUCCEEDED(D3D12GetDebugInterface(IID_PPV_ARGS(&debugController)))) { debugController->EnableDebugLayer(); } }#endif ComPtr<IDXGIFactory4> factory; ThrowIfFailed(CreateDXGIFactory1(IID_PPV_ARGS(&factory))); if (m_useWarpDevice) { ComPtr<IDXGIAdapter> warpAdapter; ThrowIfFailed(factory->EnumWarpAdapter(IID_PPV_ARGS(&warpAdapter))); ThrowIfFailed(D3D12CreateDevice( warpAdapter.Get(), D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&m_d3d12Device) )); } else { ComPtr<IDXGIAdapter1> hardwareAdapter; GetHardwareAdapter(factory.Get(), &hardwareAdapter); ThrowIfFailed(D3D12CreateDevice( hardwareAdapter.Get(), D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&m_d3d12Device) )); } // Describe and create the command queue. D3D12_COMMAND_QUEUE_DESC queueDesc = {}; queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE; queueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT; ThrowIfFailed(m_d3d12Device->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(&m_commandQueue))); // Describe the swap chain. DXGI_SWAP_CHAIN_DESC swapChainDesc = {}; swapChainDesc.BufferCount = FrameCount; swapChainDesc.BufferDesc.Width = m_width; swapChainDesc.BufferDesc.Height = m_height; swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD; swapChainDesc.OutputWindow = Win32Application::GetHwnd(); swapChainDesc.SampleDesc.Count = 1; swapChainDesc.Windowed = TRUE; ComPtr<IDXGISwapChain> swapChain; ThrowIfFailed(factory->CreateSwapChain( m_commandQueue.Get(), // Swap chain needs the queue so that it can force a flush on it. &swapChainDesc, &swapChain )); ThrowIfFailed(swapChain.As(&m_swapChain)); // This sample does not support fullscreen transitions. ThrowIfFailed(factory->MakeWindowAssociation(Win32Application::GetHwnd(), DXGI_MWA_NO_ALT_ENTER)); m_frameIndex = m_swapChain->GetCurrentBackBufferIndex(); // Create an 11 device wrapped around the 12 device and share // 12's command queue. ComPtr<ID3D11Device> d3d11Device; ThrowIfFailed(D3D11On12CreateDevice( m_d3d12Device.Get(), d3d11DeviceFlags, nullptr, 0, reinterpret_cast<IUnknown**>(m_commandQueue.GetAddressOf()), 1, 0, &d3d11Device, &m_d3d11DeviceContext, nullptr )); // Query the 11On12 device from the 11 device. ThrowIfFailed(d3d11Device.As(&m_d3d11On12Device)); // Create D2D/DWrite components. { D2D1_DEVICE_CONTEXT_OPTIONS deviceOptions = D2D1_DEVICE_CONTEXT_OPTIONS_NONE; ThrowIfFailed(D2D1CreateFactory( D2D1_FACTORY_TYPE_SINGLE_THREADED, __uuidof(ID2D1Factory3), &d2dFactoryOptions, &m_d2dFactory)); ComPtr<IDXGIDevice> dxgiDevice; ThrowIfFailed(m_d3d11On12Device.As(&dxgiDevice)); ThrowIfFailed(m_d2dFactory->CreateDevice(dxgiDevice.Get(), &m_d2dDevice)); ThrowIfFailed(m_d2dDevice->CreateDeviceContext(deviceOptions, &m_d2dDeviceContext)); ThrowIfFailed(DWriteCreateFactory( DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory), &m_dWriteFactory)); } // Query the desktop's dpi settings, which will be used to create // D2D's render targets. float dpi = GetDpiForWindow(Win32Application::GetHwnd()); D2D1_BITMAP_PROPERTIES1 bitmapProperties = D2D1::BitmapProperties1( D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW, D2D1::PixelFormat(DXGI_FORMAT_UNKNOWN, D2D1_ALPHA_MODE_PREMULTIPLIED), dpi, dpi ); // 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 Direct3D 12 content first and then all D2D content, we specify // the In resource state as RENDER_TARGET - because Direct3D 12 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]))); } }}

See the notes about the Example code in the Direct3D 12 reference content.

Requirements

RequirementValue
Target PlatformWindows
Headerd3d11on12.h
LibraryD3D11.lib
DLLD3D11.dll

See also

11on12 Functions

D3D11On12CreateDevice function (d3d11on12.h) - Win32 apps (2024)

FAQs

Do Win32 apps work on win64? ›

In general, 32-bit applications will run under a 64-bit Windows (This is technically called WOW64 - Windows On Windows). This applies to all 64-bit Windows version to date, including Server. WOW64 processes are marked in task manager with *32, For example: chrome.exe *32.

What is D3D11On12? ›

D3D11On12 is a mapping layer, which maps graphics commands from D3D11 to D3D12. D3D11On12 is not an implementation of the D3D11 API, but is instead an implementation of the D3D11 usermode DDI (device driver interface).

What is the function of Win32? ›

Win32 is a programming interface that allows developers to create applications for the Microsoft Windows operating system. It provides a set of functions and libraries that enable software to interact with the underlying system components, such as memory management, file handling, and user interface controls.

What is the function of WinAPI in Win32? ›

The Windows API, informally WinAPI, is the foundational application programming interface (API) that allows a computer program to access the features of the Microsoft Windows operating system in which the program is running.

What is the difference between Win32 and Win64? ›

A 32-bit PC processes data in smaller pieces, which can limit performance and software compatibility. A 64-bit PC processes larger chunks of data, often leading to better performance. Like having the right-sized shoes, the correct bit version ensures your software runs smoothly on your PC.

Am I running Win32 or Win64? ›

Click Start, type system in the search box, and then click System Information in the Programs list. When System Summary is selected in the navigation pane, the operating system is displayed as follows: For a 64-bit version operating system: X64-based PC appears for the System Type under Item.

How to play DirectX 12 games on DirectX 11? ›

EXPERIMENTAL - Force DirectX 12 games to use DirectX 11 in...
  1. From working Windows 10 PC or Parallels copy C:\Windows\System32\DXCpl.exe and C:\Windows\SysWOW64\DXCpl.exe to equivalent directories in Crossover bottle.
  2. Run Crossover, select game bottle and use "Run Command" to run C:\Windows\SysWOW64\DXCpl.exe.
Feb 24, 2023

How do I get rid of Win32 virus? ›

How to remove Win32 / Virut in 3 simple steps
  1. Download. Download our free removal tool: rmvirut.exe.
  2. Run the tool. To remove infected files, run the tool. ...
  3. Update. After your computer has restarted, make sure your antivirus is up-to-date and then run a full computer scan.

Which function is used to create Windows applications in Win32? ›

Just as every C application and C++ application must have a main function as its starting point, every Windows desktop application must have a WinMain function.

How do I fix Win32? ›

The error not a valid Win32 application may be caused by the corrupt file during downloading. So, in order to fix the error that .exe is not a valid Win32 application, you can try to download the program again and reinstall it. And then run it and check whether the error not a valid Win32 application is solved.

What is the Windows API used for? ›

The Windows API (application programming interface) allows user-written programs to interact with Windows, for example to display things on screen and get input from mouse and keyboard. All Windows programs except console programs must interact with the Windows API regardless of the language.

What is a Win32 app? ›

An application written for 32-bit Windows operating systems.

Is the Win32 API still used? ›

Is Win32 API still used? Yes, Windows API is still used heavily. Though as a . NET or Java or Python or Ruby programmer you may not use it directly but these and other platforms internally calls Windows API functions.

Can you run 32-bit apps on 64? ›

Most programs made for the 32-bit version of Windows will work on the 64-bit version of Windows except for most Antivirus programs. Device drivers that are made for the 32-bit version of Windows will not work correctly on a computer running a 64-bit version of Windows.

Can a 32-bit application use a 64-bit driver? ›

Yes, you can connect a 32-bit application to a 64-bit ODBC driver by using the ODBC-ODBC Bridge. Without the ODBC-ODBC Bridge, a 32-bit application cannot connect to a 64-bit ODBC driver. 32-bit applications must be linked against 32-bit libraries.

Can 32-bit apps use 64-bit DLL? ›

On 64-bit Windows, a 64-bit process cannot load a 32-bit dynamic-link library (DLL). Additionally, a 32-bit process cannot load a 64-bit DLL. However, 64-bit Windows supports remote procedure calls (RPC) between 64-bit and 32-bit processes (both on the same computer and across computers).

Is not a valid Win32 application on 64-bit machine? ›

This error may appear on the screen if the program is an older MS-DOS or early Windows program. The 32-bit version of Windows cannot run the program designed for a 64-bit version of Windows. You will get an error if you try to execute this program.

References

Top Articles
Latest Posts
Article information

Author: Geoffrey Lueilwitz

Last Updated:

Views: 6105

Rating: 5 / 5 (80 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Geoffrey Lueilwitz

Birthday: 1997-03-23

Address: 74183 Thomas Course, Port Micheal, OK 55446-1529

Phone: +13408645881558

Job: Global Representative

Hobby: Sailing, Vehicle restoration, Rowing, Ghost hunting, Scrapbooking, Rugby, Board sports

Introduction: My name is Geoffrey Lueilwitz, I am a zealous, encouraging, sparkling, enchanting, graceful, faithful, nice person who loves writing and wants to share my knowledge and understanding with you.