/// <summary> /// Constructor is private, because this is a singleton class: /// client controls should use the public AddRef method instead. /// </summary> SharpDXGraphicsDeviceService10() { // We need a a D3D9 device. sharpDXGraphicsDeviceService9 = SharpDXGraphicsDeviceService9.RefToNew(0, 0); factoryDXGI = new Factory(); factory2D = new SharpDX.Direct2D1.Factory(); // Try to create a hardware device first and fall back to a // software (WARP doesn't let us share resources) var device1 = TryCreateDevice1(SharpDX.Direct3D10.DriverType.Hardware); if (device1 == null) { device1 = TryCreateDevice1(SharpDX.Direct3D10.DriverType.Software); if (device1 == null) { throw new Exception("Unable to create a DirectX 10 device."); } } // Ratserizer not needed for Direct2D (retain for if mixing D2D and D3D). //RasterizerStateDescription rastDesc = new RasterizerStateDescription(); //rastDesc.CullMode = CullMode.Back; //rastDesc.FillMode = FillMode.Solid; //rastDesc.IsMultisampleEnabled = false; //rastDesc.IsAntialiasedLineEnabled = false; //device1.Rasterizer.State = new RasterizerState(device1, rastDesc); this.device = device1; }
internal static void InitializeDirect2D() { lock (s_initLock) { if (s_initialized) { return; } #if DEBUG try { s_d2D1Factory = new SharpDX.Direct2D1.Factory1(SharpDX.Direct2D1.FactoryType.MultiThreaded, SharpDX.Direct2D1.DebugLevel.Error); } catch { // } #endif s_dwfactory = new SharpDX.DirectWrite.Factory(); s_imagingFactory = new SharpDX.WIC.ImagingFactory(); if (s_d2D1Factory == null) { s_d2D1Factory = new SharpDX.Direct2D1.Factory1(SharpDX.Direct2D1.FactoryType.MultiThreaded, SharpDX.Direct2D1.DebugLevel.None); } var featureLevels = new[] { SharpDX.Direct3D.FeatureLevel.Level_11_1, SharpDX.Direct3D.FeatureLevel.Level_11_0, SharpDX.Direct3D.FeatureLevel.Level_10_1, SharpDX.Direct3D.FeatureLevel.Level_10_0, SharpDX.Direct3D.FeatureLevel.Level_9_3, SharpDX.Direct3D.FeatureLevel.Level_9_2, SharpDX.Direct3D.FeatureLevel.Level_9_1, }; using (var d3dDevice = new SharpDX.Direct3D11.Device( SharpDX.Direct3D.DriverType.Hardware, SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport | SharpDX.Direct3D11.DeviceCreationFlags.VideoSupport, featureLevels)) { s_dxgiDevice = d3dDevice.QueryInterface <SharpDX.DXGI.Device>(); } using (var factory1 = s_d2D1Factory.QueryInterface <SharpDX.Direct2D1.Factory1>()) { s_d2D1Device = new SharpDX.Direct2D1.Device(factory1, s_dxgiDevice); } s_initialized = true; } }
public override void Dispose() { base.Dispose(); this.direct2D1factory?.Dispose(); this.direct2D1factory = null; this.windowRenderTarget?.Dispose(); this.windowRenderTarget = null; GC.Collect(); }
public void SetHWND(IntPtr hWnd, int w, int h) { if (_hWnd == hWnd) { return; } Dispose(); _hWnd = hWnd; // SwapChain description var desc = new SwapChainDescription() { BufferCount = 1, ModeDescription = new ModeDescription(w, h, new Rational(60, 1), Format.R8G8B8A8_UNorm), IsWindowed = true, OutputHandle = hWnd, SampleDescription = new SampleDescription(1, 0), SwapEffect = SwapEffect.Discard, Usage = Usage.RenderTargetOutput }; // Create Device and SwapChain SharpDX.Direct3D11.Device device; SwapChain swapChain; SharpDX.Direct3D11.Device.CreateWithSwapChain( SharpDX.Direct3D.DriverType.Hardware, SharpDX.Direct3D11.DeviceCreationFlags.Debug | SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport, desc, out device, out swapChain); // Ignore all windows events using (var factory = swapChain.GetParent <Factory>()) { factory.MakeWindowAssociation(hWnd, WindowAssociationFlags.IgnoreAll); } Device = device; Context = Device.ImmediateContext; SwapChain = new DXGISwapChain(swapChain); // D2D using (var dxgi = Device.QueryInterface <Device2>()) { D2DDevice = new SharpDX.Direct2D1.Device(dxgi); D2DDeviceContext = new SharpDX.Direct2D1.DeviceContext(D2DDevice, SharpDX.Direct2D1.DeviceContextOptions.None); } using (var factroy = new SharpDX.Direct2D1.Factory(SharpDX.Direct2D1.FactoryType.SingleThreaded)) { Dpi = factroy.DesktopDpi; } }
private void InitializeDirectXResources() { var clientSize = ClientSize; var backBufferDesc = new SharpDX.DXGI.ModeDescription(clientSize.Width, clientSize.Height, new SharpDX.DXGI.Rational(60, 1), SharpDX.DXGI.Format.R8G8B8A8_UNorm); var swapChainDesc = new SharpDX.DXGI.SwapChainDescription() { ModeDescription = backBufferDesc, SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0), Usage = SharpDX.DXGI.Usage.RenderTargetOutput, BufferCount = 1, OutputHandle = Handle, SwapEffect = SharpDX.DXGI.SwapEffect.Discard, IsWindowed = false }; SharpDX.Direct3D11.Device.CreateWithSwapChain(SharpDX.Direct3D.DriverType.Hardware, SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport, new[] { SharpDX.Direct3D.FeatureLevel.Level_10_0 }, swapChainDesc, out _d3DDevice, out var swapChain); _d3DDeviceContext = _d3DDevice.ImmediateContext; _swapChain = new SharpDX.DXGI.SwapChain1(swapChain.NativePointer); _d2DFactory = new SharpDX.Direct2D1.Factory(); using (var backBuffer = _swapChain.GetBackBuffer <SharpDX.Direct3D11.Texture2D>(0)) { _renderTargetView = new SharpDX.Direct3D11.RenderTargetView(_d3DDevice, backBuffer); _renderTarget = new SharpDX.Direct2D1.RenderTarget(_d2DFactory, backBuffer.QueryInterface <SharpDX.DXGI.Surface>(), new SharpDX.Direct2D1.RenderTargetProperties(new SharpDX.Direct2D1.PixelFormat(SharpDX.DXGI.Format.Unknown, SharpDX.Direct2D1.AlphaMode.Premultiplied))) { TextAntialiasMode = SharpDX.Direct2D1.TextAntialiasMode.Cleartype }; } _solidColorBrush = new SharpDX.Direct2D1.SolidColorBrush(_renderTarget, Color.White); _dwFactory = new SharpDX.DirectWrite.Factory(SharpDX.DirectWrite.FactoryType.Shared); _textFormat = new SharpDX.DirectWrite.TextFormat(_dwFactory, "Arial", SharpDX.DirectWrite.FontWeight.Bold, SharpDX.DirectWrite.FontStyle.Normal, SharpDX.DirectWrite.FontStretch.Normal, 84 * (float)GraphicsUtils.Scale) { TextAlignment = SharpDX.DirectWrite.TextAlignment.Center, ParagraphAlignment = SharpDX.DirectWrite.ParagraphAlignment.Center }; // var rectangleGeometry = new D2D1.RoundedRectangleGeometry(_d2DFactory, // new D2D1.RoundedRectangle() { RadiusX = 32, RadiusY = 32, Rect = new RectangleF(128, 128, Width - 128 * 2, Height - 128 * 2) }); }
D3D11Device(SharpDX.Direct3D11.Device device) { Device = device; Context = Device.ImmediateContext; // D2D DXGIDevice = Device.QueryInterface <Device2>(); D2DDevice = new SharpDX.Direct2D1.Device(DXGIDevice); D2DDeviceContext = new SharpDX.Direct2D1.DeviceContext(D2DDevice, SharpDX.Direct2D1.DeviceContextOptions.None); using (var factroy = new SharpDX.Direct2D1.Factory(SharpDX.Direct2D1.FactoryType.SingleThreaded)) { Dpi = factroy.DesktopDpi; } }
public DUIWindowRenderTarget(IntPtr handle) { Size size = System.Windows.Forms.Control.FromHandle(handle).Size; this.direct2D1factory = new SharpDX.Direct2D1.Factory(SharpDX.Direct2D1.FactoryType.SingleThreaded); SharpDX.Direct2D1.HwndRenderTargetProperties hwndRenderTargetProperties = new SharpDX.Direct2D1.HwndRenderTargetProperties() { Hwnd = handle, PixelSize = new SharpDX.Size2(size.Width, size.Height), PresentOptions = SharpDX.Direct2D1.PresentOptions.None }; SharpDX.Direct2D1.PixelFormat pixelFormat = new SharpDX.Direct2D1.PixelFormat(SharpDX.DXGI.Format.Unknown, SharpDX.Direct2D1.AlphaMode.Premultiplied); //强制设置DPI为96,96(默认值),无意间发现有的人居然会去修改系统的dpi SharpDX.Direct2D1.RenderTargetProperties renderTargetProperties = new SharpDX.Direct2D1.RenderTargetProperties(SharpDX.Direct2D1.RenderTargetType.Default, pixelFormat, 96, 96, SharpDX.Direct2D1.RenderTargetUsage.None, SharpDX.Direct2D1.FeatureLevel.Level_DEFAULT); //初始化,在_d2dFactory创建渲染缓冲区并与Target绑定 //SharpDX.Direct2D1.PixelFormat pf = new SharpDX.Direct2D1.PixelFormat(SharpDX.DXGI.Format.Unknown, SharpDX.Direct2D1.AlphaMode.Premultiplied); this.windowRenderTarget = new SharpDX.Direct2D1.WindowRenderTarget(direct2D1factory, renderTargetProperties, hwndRenderTargetProperties); this.windowRenderTarget.AntialiasMode = SharpDX.Direct2D1.AntialiasMode.Aliased; this.windowRenderTarget.TextAntialiasMode = SharpDX.Direct2D1.TextAntialiasMode.Aliased; }
public static void Init() { factory = new Factory(); fontFactory = new FontFactory(); fonts = new Hashtable(); }
public GraphicsManager(Form win) { if (GraphicsManager._instance == null) { GraphicsManager._instance = this; } _win = win; // Check for available settings Factory1 fac = new Factory1(); Adapter adapter = fac.GetAdapter(0); Output mon = adapter.GetOutput(0); ModeDescription[] modeList = mon.GetDisplayModeList(Format.B8G8R8A8_UNorm, DisplayModeEnumerationFlags.Interlaced); Rational rational = new Rational(0, 1); foreach (ModeDescription mode in modeList) { if (mode.Width == win.ClientSize.Width) { rational = new Rational(mode.RefreshRate.Numerator, mode.RefreshRate.Numerator); } } /* * SwapChainDescription1 scd1 = new SwapChainDescription1 * { * BufferCount = 2, * Flags = SwapChainFlags.None, * SampleDescription = new SampleDescription(1, 0), * SwapEffect = SwapEffect.Discard * }; */ // Create swap chain descirpiom object SwapChainDescription scd = new SwapChainDescription { BufferCount = 2, Flags = SwapChainFlags.None, IsWindowed = true, ModeDescription = new ModeDescription(win.ClientSize.Width, win.ClientSize.Height, rational, Format.R8G8B8A8_UNorm), OutputHandle = win.Handle, SampleDescription = new SampleDescription(1, 0), SwapEffect = SwapEffect.FlipSequential, Usage = Usage.RenderTargetOutput }; /* Reference * https://stackoverflow.com/questions/26220964/sharpdxhow-to-place-sharpdx-window-in-winforms-window * https://github.com/sharpdx/SharpDX-Samples/blob/master/Desktop/Direct2D1/MiniRect/Program.cs * https://github.com/r2d2rigo/MyFirstDirect2D-SharpDX/blob/master/MyFirstDirect2D/MyViewProvider.cs */ try { // Create our DirectX 11 device object and swap chain SharpDX.Direct3D11.Device.CreateWithSwapChain( SharpDX.Direct3D.DriverType.Hardware, DeviceCreationFlags.Debug | DeviceCreationFlags.BgraSupport, scd, out d3dDevice, out swapChain); }catch (Exception e) { MessageBox.Show(e.ToString()); return; } // Get access to the DirectX 11 context d3dContext = d3dDevice.ImmediateContext; // Create the Direct2D factory object, used in building a render target d2dFactory = new SharpDX.Direct2D1.Factory(); dwFactory = new SharpDX.DirectWrite.Factory(); // Create a texture target target = Texture2D.FromSwapChain <Texture2D>(swapChain, 0); targetView = new RenderTargetView(d3dDevice, target); // Create a surface from target surface = target.QueryInterface <Surface>(); // Finally create the important Direct2D render target d2dRenderTarget = new SharpDX.Direct2D1.RenderTarget(d2dFactory, surface, new SharpDX.Direct2D1.RenderTargetProperties( new SharpDX.Direct2D1.PixelFormat(scd.ModeDescription.Format, SharpDX.Direct2D1.AlphaMode.Premultiplied) )); // Initiallize the Graphic Manager internal parameters _inRender = false; _lock = new Object(); // Set initial tranformation of graphics system d2dRenderTarget.Transform = Identity; }
private void LoadPipeline(RenderForm form) { int width = form.ClientSize.Width; int height = form.ClientSize.Height; viewport.Width = width; viewport.Height = height; viewport.MaxDepth = 1.0f; scissorRect.Right = width; scissorRect.Bottom = height; #if DEBUG // Enable the D3D12 debug layer. { DebugInterface.Get().EnableDebugLayer(); } #endif device = new Device(null, SharpDX.Direct3D.FeatureLevel.Level_12_0); using (var factory = new Factory4()) { // Describe and create the command queue. CommandQueueDescription queueDesc = new CommandQueueDescription(CommandListType.Direct); commandQueue = device.CreateCommandQueue(queueDesc); // Describe and create the swap chain. SwapChainDescription swapChainDesc = new SwapChainDescription() { BufferCount = FrameCount, ModeDescription = new ModeDescription(width, height, new Rational(60, 1), Format.R8G8B8A8_UNorm), Usage = Usage.RenderTargetOutput, SwapEffect = SwapEffect.FlipDiscard, OutputHandle = form.Handle, //Flags = SwapChainFlags.None, SampleDescription = new SampleDescription(1, 0), IsWindowed = true }; SwapChain tempSwapChain = new SwapChain(factory, commandQueue, swapChainDesc); swapChain = tempSwapChain.QueryInterface <SwapChain3>(); tempSwapChain.Dispose(); frameIndex = swapChain.CurrentBackBufferIndex; } // Create descriptor heaps. // Describe and create a render target view (RTV) descriptor heap. DescriptorHeapDescription rtvHeapDesc = new DescriptorHeapDescription() { DescriptorCount = FrameCount, Flags = DescriptorHeapFlags.None, Type = DescriptorHeapType.RenderTargetView }; renderTargetViewHeap = device.CreateDescriptorHeap(rtvHeapDesc); rtvDescriptorSize = device.GetDescriptorHandleIncrementSize(DescriptorHeapType.RenderTargetView); //Init Direct3D11 device from Direct3D12 device device11 = SharpDX.Direct3D11.Device.CreateFromDirect3D12(device, SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport, null, null, commandQueue); deviceContext11 = device11.ImmediateContext; device11on12 = device11.QueryInterface <SharpDX.Direct3D11.ID3D11On12Device>(); var d2dFactory = new SharpDX.Direct2D1.Factory(SharpDX.Direct2D1.FactoryType.MultiThreaded); // Create frame resources. CpuDescriptorHandle rtvHandle = renderTargetViewHeap.CPUDescriptorHandleForHeapStart; for (int n = 0; n < FrameCount; n++) { renderTargets[n] = swapChain.GetBackBuffer <Resource>(n); device.CreateRenderTargetView(renderTargets[n], null, rtvHandle); rtvHandle += rtvDescriptorSize; //init Direct2D surfaces SharpDX.Direct3D11.D3D11ResourceFlags format = new SharpDX.Direct3D11.D3D11ResourceFlags() { BindFlags = (int)SharpDX.Direct3D11.BindFlags.RenderTarget, CPUAccessFlags = (int)SharpDX.Direct3D11.CpuAccessFlags.None }; device11on12.CreateWrappedResource( renderTargets[n], format, (int)ResourceStates.Present, (int)ResourceStates.RenderTarget, typeof(SharpDX.Direct3D11.Resource).GUID, out wrappedBackBuffers[n]); //Init direct2D surface var d2dSurface = wrappedBackBuffers[n].QueryInterface <Surface>(); direct2DRenderTarget[n] = new SharpDX.Direct2D1.RenderTarget(d2dFactory, d2dSurface, new SharpDX.Direct2D1.RenderTargetProperties(new SharpDX.Direct2D1.PixelFormat(Format.Unknown, SharpDX.Direct2D1.AlphaMode.Premultiplied))); d2dSurface.Dispose(); } commandAllocator = device.CreateCommandAllocator(CommandListType.Direct); d2dFactory.Dispose(); //Init font var directWriteFactory = new SharpDX.DirectWrite.Factory(); textFormat = new SharpDX.DirectWrite.TextFormat(directWriteFactory, "Arial", SharpDX.DirectWrite.FontWeight.Bold, SharpDX.DirectWrite.FontStyle.Normal, 48) { TextAlignment = SharpDX.DirectWrite.TextAlignment.Leading, ParagraphAlignment = SharpDX.DirectWrite.ParagraphAlignment.Near }; textBrush = new SharpDX.Direct2D1.SolidColorBrush(direct2DRenderTarget[0], Color.White); directWriteFactory.Dispose(); }
public SharpDXStates(Settings settings) { this.settings = settings; d2DFactory = new D2dFactory(); }
public static SharpDX.Direct2D1.RectangleGeometry ToRectangleGeometry(SharpDX.Direct2D1.Factory factory, RectangleF rect) { return(new SharpDX.Direct2D1.RectangleGeometry(factory, ToRectF(rect))); }
private void LoadPipeline(RenderForm form) { int width = form.ClientSize.Width; int height = form.ClientSize.Height; viewport.Width = width; viewport.Height = height; viewport.MaxDepth = 1.0f; scissorRect.Right = width; scissorRect.Bottom = height; #if DEBUG // Enable the D3D12 debug layer. { DebugInterface.Get().EnableDebugLayer(); } #endif device = new Device(null, SharpDX.Direct3D.FeatureLevel.Level_12_0); using (var factory = new Factory4()) { // Describe and create the command queue. CommandQueueDescription queueDesc = new CommandQueueDescription(CommandListType.Direct); commandQueue = device.CreateCommandQueue(queueDesc); // Describe and create the swap chain. SwapChainDescription swapChainDesc = new SwapChainDescription() { BufferCount = FrameCount, ModeDescription = new ModeDescription(width, height, new Rational(60, 1), Format.R8G8B8A8_UNorm), Usage = Usage.RenderTargetOutput, SwapEffect = SwapEffect.FlipDiscard, OutputHandle = form.Handle, //Flags = SwapChainFlags.None, SampleDescription = new SampleDescription(1, 0), IsWindowed = true }; SwapChain tempSwapChain = new SwapChain(factory, commandQueue, swapChainDesc); swapChain = tempSwapChain.QueryInterface<SwapChain3>(); tempSwapChain.Dispose(); frameIndex = swapChain.CurrentBackBufferIndex; } // Create descriptor heaps. // Describe and create a render target view (RTV) descriptor heap. DescriptorHeapDescription rtvHeapDesc = new DescriptorHeapDescription() { DescriptorCount = FrameCount, Flags = DescriptorHeapFlags.None, Type = DescriptorHeapType.RenderTargetView }; renderTargetViewHeap = device.CreateDescriptorHeap(rtvHeapDesc); rtvDescriptorSize = device.GetDescriptorHandleIncrementSize(DescriptorHeapType.RenderTargetView); //Init Direct3D11 device from Direct3D12 device device11 = SharpDX.Direct3D11.Device.CreateFromDirect3D12(device, SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport, null, null, commandQueue); deviceContext11 = device11.ImmediateContext; device11on12 = device11.QueryInterface<SharpDX.Direct3D11.ID3D11On12Device>(); var d2dFactory = new SharpDX.Direct2D1.Factory(SharpDX.Direct2D1.FactoryType.MultiThreaded); // Create frame resources. CpuDescriptorHandle rtvHandle = renderTargetViewHeap.CPUDescriptorHandleForHeapStart; for (int n = 0; n < FrameCount; n++) { renderTargets[n] = swapChain.GetBackBuffer<Resource>(n); device.CreateRenderTargetView(renderTargets[n], null, rtvHandle); rtvHandle += rtvDescriptorSize; //init Direct2D surfaces SharpDX.Direct3D11.D3D11ResourceFlags format = new SharpDX.Direct3D11.D3D11ResourceFlags() { BindFlags = (int)SharpDX.Direct3D11.BindFlags.RenderTarget, CPUAccessFlags = (int)SharpDX.Direct3D11.CpuAccessFlags.None }; device11on12.CreateWrappedResource( renderTargets[n], format, (int)ResourceStates.Present, (int)ResourceStates.RenderTarget, typeof(SharpDX.Direct3D11.Resource).GUID, out wrappedBackBuffers[n]); //Init direct2D surface var d2dSurface = wrappedBackBuffers[n].QueryInterface<Surface>(); direct2DRenderTarget[n] = new SharpDX.Direct2D1.RenderTarget(d2dFactory, d2dSurface, new SharpDX.Direct2D1.RenderTargetProperties(new SharpDX.Direct2D1.PixelFormat(Format.Unknown, SharpDX.Direct2D1.AlphaMode.Premultiplied))); d2dSurface.Dispose(); } commandAllocator = device.CreateCommandAllocator(CommandListType.Direct); d2dFactory.Dispose(); //Init font var directWriteFactory = new SharpDX.DirectWrite.Factory(); textFormat = new SharpDX.DirectWrite.TextFormat(directWriteFactory, "Arial", SharpDX.DirectWrite.FontWeight.Bold, SharpDX.DirectWrite.FontStyle.Normal, 48) { TextAlignment = SharpDX.DirectWrite.TextAlignment.Leading, ParagraphAlignment = SharpDX.DirectWrite.ParagraphAlignment.Near }; textBrush = new SharpDX.Direct2D1.SolidColorBrush(direct2DRenderTarget[0], Color.White); directWriteFactory.Dispose(); }
public CompositionEngine() { _wicFactory = new ImagingFactory(); _d2DFactory = new SharpDX.Direct2D1.Factory(); this._dWriteFactory = new SharpDX.DirectWrite.Factory(); }
public Pipeline(int frameCount, System.Drawing.Size size, System.IntPtr windowHandle) { // Fields FrameCount = frameCount; Size = size; // Pipeline var d3d12Device = new SharpDX.Direct3D12.Device(null, SharpDX.Direct3D.FeatureLevel.Level_12_1); var queueDescription = new SharpDX.Direct3D12.CommandQueueDescription(SharpDX.Direct3D12.CommandListType.Direct); var commandQueue = d3d12Device.CreateCommandQueue(queueDescription); var swapChainDescription = new SharpDX.DXGI.SwapChainDescription() { BufferCount = frameCount, ModeDescription = new SharpDX.DXGI.ModeDescription(Size.Width, Size.Height, new SharpDX.DXGI.Rational(60, 1), SharpDX.DXGI.Format.R8G8B8A8_UNorm), Usage = SharpDX.DXGI.Usage.RenderTargetOutput, SwapEffect = SharpDX.DXGI.SwapEffect.FlipDiscard, OutputHandle = windowHandle, Flags = SharpDX.DXGI.SwapChainFlags.None, SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0), IsWindowed = true }; var rtvHeapDescription = new SharpDX.Direct3D12.DescriptorHeapDescription() { DescriptorCount = frameCount, Flags = SharpDX.Direct3D12.DescriptorHeapFlags.None, Type = SharpDX.Direct3D12.DescriptorHeapType.RenderTargetView }; var renderTargetViewHeap = d3d12Device.CreateDescriptorHeap(rtvHeapDescription); var rtvHandle = renderTargetViewHeap.CPUDescriptorHandleForHeapStart; var dxgiFactory = new SharpDX.DXGI.Factory4(); var swapChain = new SharpDX.DXGI.SwapChain(dxgiFactory, commandQueue, swapChainDescription); var swapChain3 = swapChain.QueryInterface <SharpDX.DXGI.SwapChain3>(); var frameIndex = swapChain3.CurrentBackBufferIndex; var renderTargets = new SharpDX.Direct3D12.Resource[frameCount]; var commandAllocators = new SharpDX.Direct3D12.CommandAllocator[frameCount]; var rtvDescriptorSize = d3d12Device.GetDescriptorHandleIncrementSize(SharpDX.Direct3D12.DescriptorHeapType.RenderTargetView); var d2d1Factory = new SharpDX.Direct2D1.Factory(); var d3d11Device = SharpDX.Direct3D11.Device.CreateFromDirect3D12(d3d12Device, SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport, null, null, commandQueue); var d3d11On12Device = d3d11Device.QueryInterface <SharpDX.Direct3D11.Device11On12>(); var wrappedBackBuffers = new SharpDX.Direct3D11.Resource[frameCount]; var d2dRenderTargets = new SharpDX.Direct2D1.RenderTarget[frameCount]; for (int i = 0; i < frameCount; i++) { renderTargets[i] = swapChain3.GetBackBuffer <SharpDX.Direct3D12.Resource>(i); commandAllocators[i] = d3d12Device.CreateCommandAllocator(SharpDX.Direct3D12.CommandListType.Direct); d3d12Device.CreateRenderTargetView(renderTargets[i], null, rtvHandle); rtvHandle += rtvDescriptorSize; var format = new SharpDX.Direct3D11.D3D11ResourceFlags() { BindFlags = (int)SharpDX.Direct3D11.BindFlags.RenderTarget, CPUAccessFlags = (int)SharpDX.Direct3D11.CpuAccessFlags.None }; d3d11On12Device.CreateWrappedResource(renderTargets[i], format, (int)SharpDX.Direct3D12.ResourceStates.Present, (int)SharpDX.Direct3D12.ResourceStates.RenderTarget, typeof(SharpDX.Direct3D11.Resource).GUID, out wrappedBackBuffers[i]); var surface = wrappedBackBuffers[i].QueryInterface <SharpDX.DXGI.Surface>(); d2dRenderTargets[i] = new SharpDX.Direct2D1.RenderTarget(d2d1Factory, surface, new SharpDX.Direct2D1.RenderTargetProperties(new SharpDX.Direct2D1.PixelFormat(SharpDX.DXGI.Format.Unknown, SharpDX.Direct2D1.AlphaMode.Premultiplied))); } // Assets var fenceEvent = new System.Threading.AutoResetEvent(false); var fence = d3d12Device.CreateFence(0, SharpDX.Direct3D12.FenceFlags.None); var fenceValues = new int[frameCount]; for (int i = 0; i < frameCount; i++) { fenceValues[i] = 1; } var commandList = d3d12Device.CreateCommandList(SharpDX.Direct3D12.CommandListType.Direct, commandAllocators[frameIndex], pipelineState); commandList.Close(); D3D12Device = d3d12Device; CommandAllocators = commandAllocators; RenderTargetViewHeap = renderTargetViewHeap; RenderTargets = renderTargets; CommandQueue = commandQueue; SwapChain3 = swapChain3; Fence = fence; FenceEvent = fenceEvent; D3D11Device = d3d11Device; D3D11On12Device = d3d11On12Device; WrappedBackBuffers = wrappedBackBuffers; D2DRenderTargets = d2dRenderTargets; CommandList = commandList; FenceValues = fenceValues; RtvDescriptorSize = rtvDescriptorSize; FrameIndex = frameIndex; }