private static SwapChain3 CreateSwapChain( IntPtr windowHandle, D3D12.CommandQueue commandQueue, PixelFormat backBufferFormat, int backBufferCount, int width, int height) { var swapChainDescription = new SwapChainDescription1 { Width = width, Height = height, Format = backBufferFormat.ToDxgiFormat(), Stereo = false, SampleDescription = new SampleDescription(1, 0), Usage = Usage.RenderTargetOutput, Scaling = Scaling.Stretch, BufferCount = backBufferCount, SwapEffect = SwapEffect.FlipSequential, Flags = SwapChainFlags.None }; #if DEBUG const bool debug = true; #else const bool debug = false; #endif using (var dxgiFactory = new Factory2(debug)) using (var tempSwapChain = new SwapChain1(dxgiFactory, commandQueue, windowHandle, ref swapChainDescription)) { return(tempSwapChain.QueryInterface <SwapChain3>()); } }
private void CreateCommandQueue() { SharpDX.Direct3D12.CommandQueueDescription desc = new CommandQueueDescription { Type = CommandListType.Direct, Priority = (int)CommandQueuePriority.Normal, Flags = CommandQueueFlags.None, NodeMask = 0 }; _queue = _dev.CreateCommandQueue(desc); }
/// <exception cref="SharpDX.SharpDXException"></exception> protected override void CreateImpl() { var descd3d12 = new CommandQueueDescription { Priority = (int) CommandQueuePriority.Normal, Flags = CommandQueueFlags.None, // Disabling GPU timeout is not yet exposed. NodeMask = 0, Type = InternalUtils.GetDXCommandListType(Desc.Type) }; CommandQueueD3D12 = ((Device) Device).DeviceD3D12.CreateCommandQueue(descd3d12); CommandQueueD3D12.Name = Label; }
/// <exception cref="SharpDX.SharpDXException"></exception> protected override void CreateImpl() { var descd3d12 = new CommandQueueDescription { Priority = (int)CommandQueuePriority.Normal, Flags = CommandQueueFlags.None, // Disabling GPU timeout is not yet exposed. NodeMask = 0, Type = InternalUtils.GetDXCommandListType(Desc.Type) }; CommandQueueD3D12 = ((Device)Device).DeviceD3D12.CreateCommandQueue(descd3d12); CommandQueueD3D12.Name = Label; }
private void PlatformConstruct(GraphicsDevice graphicsDevice) { const CommandListType commandListType = CommandListType.Direct; var device = graphicsDevice.Device; DeviceCommandQueue = AddDisposable(device.CreateCommandQueue(new CommandQueueDescription(commandListType))); _fence = AddDisposable(device.CreateFence(0, FenceFlags.None)); _fenceEvent = AddDisposable(new AutoResetEvent(false)); _allocatorPool = AddDisposable(new CommandAllocatorPool(graphicsDevice, commandListType)); _nextFenceValue = 1; _commandBuffer = AddDisposable(new CommandBuffer(graphicsDevice, this)); }
public static SwapChain3 CreateSwapchain(RenderForm form, CommandQueue queue,Config config) { using (var Factory = new Factory4()) { var swapChainDesc = new SwapChainDescription() { BufferCount = config.FrameCount, ModeDescription = new ModeDescription(config.Width, config.Height, new Rational(config.RefreshRate, 1), config.Format), Usage = Usage.RenderTargetOutput, SwapEffect = SwapEffect.FlipDiscard, OutputHandle = form.Handle, SampleDescription = new SampleDescription(config.SampleCount, config.SampleQuality), IsWindowed = true }; var tempSwapChain = new SwapChain(Factory, queue, swapChainDesc); var SwapChain = tempSwapChain.QueryInterface<SwapChain3>(); tempSwapChain.Dispose(); return SwapChain; } }
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_11_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); DescriptorHeapDescription srvHeapDesc = new DescriptorHeapDescription() { DescriptorCount = 1, Flags = DescriptorHeapFlags.ShaderVisible, Type = DescriptorHeapType.ConstantBufferViewShaderResourceViewUnorderedAccessView }; shaderRenderViewHeap = device.CreateDescriptorHeap(srvHeapDesc); rtvDescriptorSize = device.GetDescriptorHandleIncrementSize(DescriptorHeapType.RenderTargetView); // 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; } commandAllocator = device.CreateCommandAllocator(CommandListType.Direct); }
private static Device CreateDeviceWithSwapChain(DriverType driverType, FeatureLevel level, SwapChainDescription swapChainDescription, out SwapChain swapChain, out CommandQueue queue) { #if DEBUG // Enable the D3D12 debug layer. // DebugInterface.Get().EnableDebugLayer(); #endif using (var factory = new Factory4()) { var adapter = driverType == DriverType.Hardware ? null : factory.GetWarpAdapter(); var device = new Device(adapter, level); queue = device.CreateCommandQueue(new CommandQueueDescription(CommandListType.Direct)); swapChain = new SwapChain(factory, queue, swapChainDescription); return device; } }
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; device = new Device(null, SharpDX.Direct3D.FeatureLevel.Level_11_0); using (var factory = new Factory4()) { var queueDesc = new CommandQueueDescription(CommandListType.Direct); commandQueue = device.CreateCommandQueue(queueDesc); var 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, SampleDescription = new SampleDescription(1, 0), IsWindowed = true }; var tempSwapChain = new SwapChain(factory, commandQueue, swapChainDesc); swapChain = tempSwapChain.QueryInterface<SwapChain3>(); frameIndex = swapChain.CurrentBackBufferIndex; } var rtvHeapDesc = new DescriptorHeapDescription() { DescriptorCount = FrameCount, Flags = DescriptorHeapFlags.None, Type = DescriptorHeapType.RenderTargetView }; renderTargetViewHeap = device.CreateDescriptorHeap(rtvHeapDesc); rtvDescriptorSize = device.GetDescriptorHandleIncrementSize(DescriptorHeapType.RenderTargetView); var srvHeapDesc = new DescriptorHeapDescription() { DescriptorCount = 200, Flags = DescriptorHeapFlags.ShaderVisible, Type = DescriptorHeapType.ConstantBufferViewShaderResourceViewUnorderedAccessView }; shaderRenderViewHeap = device.CreateDescriptorHeap(srvHeapDesc); var terrainHeapDesc = new DescriptorHeapDescription() { DescriptorCount = 2, Flags = DescriptorHeapFlags.ShaderVisible, Type = DescriptorHeapType.ConstantBufferViewShaderResourceViewUnorderedAccessView }; terrainHeap = device.CreateDescriptorHeap(terrainHeapDesc); var meshCtrCbvDesc = new DescriptorHeapDescription() { DescriptorCount = 1, Flags = DescriptorHeapFlags.ShaderVisible, Type = DescriptorHeapType.ConstantBufferViewShaderResourceViewUnorderedAccessView }; meshCtrBufferViewHeap = device.CreateDescriptorHeap(meshCtrCbvDesc); var rtcHandle = renderTargetViewHeap.CPUDescriptorHandleForHeapStart; for (int n = 0; n < FrameCount; n++) { renderTargets[n] = swapChain.GetBackBuffer<Resource>(n); device.CreateRenderTargetView(renderTargets[n], null, rtcHandle); rtcHandle += rtvDescriptorSize; } var svHeapDesc = new DescriptorHeapDescription() { Type = DescriptorHeapType.Sampler, DescriptorCount = 1, Flags = DescriptorHeapFlags.ShaderVisible, NodeMask = 0 }; samplerViewHeap = device.CreateDescriptorHeap(svHeapDesc); commandAllocator = device.CreateCommandAllocator(CommandListType.Direct); }
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_11_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); // 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; } //create depth buffer; DescriptorHeapDescription dsvHeapDesc = new DescriptorHeapDescription() { DescriptorCount = FrameCount, Flags = DescriptorHeapFlags.None, Type = DescriptorHeapType.DepthStencilView }; depthStencilViewHeap = device.CreateDescriptorHeap(dsvHeapDesc); CpuDescriptorHandle dsvHandle = depthStencilViewHeap.CPUDescriptorHandleForHeapStart; ClearValue depthOptimizedClearValue = new ClearValue() { Format = Format.D32_Float, DepthStencil = new DepthStencilValue() { Depth = 1.0F, Stencil = 0 }, }; depthTarget = device.CreateCommittedResource( new HeapProperties(HeapType.Default), HeapFlags.None, new ResourceDescription(ResourceDimension.Texture2D, 0, width, height, 1, 0, Format.D32_Float, 1, 0, TextureLayout.Unknown, ResourceFlags.AllowDepthStencil), ResourceStates.DepthWrite, depthOptimizedClearValue); var depthView = new DepthStencilViewDescription() { Format = Format.D32_Float, Dimension = DepthStencilViewDimension.Texture2D, Flags = DepthStencilViewFlags.None, }; //bind depth buffer device.CreateDepthStencilView(depthTarget, null, dsvHandle); commandAllocator = device.CreateCommandAllocator(CommandListType.Direct); bundleAllocator = device.CreateCommandAllocator(CommandListType.Bundle); }
public D3D12CommandQueue(D3D12GraphicsDevice device, CommandListType type) : base(device) { NativeQueue = device.Device.CreateCommandQueue(new CommandQueueDescription(type, CommandQueueFlags.None)); }
private void LoadPipeline(RenderForm form) { int width = form.ClientSize.Width; int height = form.ClientSize.Height; #if DEBUG // Enable the D3D12 debug layer. { DebugInterface.Get().EnableDebugLayer(); } #endif device = new Device(null, SharpDX.Direct3D.FeatureLevel.Level_11_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. renderTargetViewHeap = device.CreateDescriptorHeap(new DescriptorHeapDescription() { DescriptorCount = FrameCount, Flags = DescriptorHeapFlags.None, Type = DescriptorHeapType.RenderTargetView }); rtvDescriptorSize = device.GetDescriptorHandleIncrementSize(DescriptorHeapType.RenderTargetView); //create depth buffer; depthStencilViewHeap = device.CreateDescriptorHeap(new DescriptorHeapDescription() { DescriptorCount = FrameCount, Flags = DescriptorHeapFlags.None, Type = DescriptorHeapType.DepthStencilView }); //constant buffer view heap constantBufferViewHeap = device.CreateDescriptorHeap(new DescriptorHeapDescription() { DescriptorCount = 100, Type = DescriptorHeapType.ConstantBufferViewShaderResourceViewUnorderedAccessView, Flags = DescriptorHeapFlags.ShaderVisible }); //Create targets CreateTargets(width, height); //sampler buffer view heap samplerViewHeap = device.CreateDescriptorHeap(new DescriptorHeapDescription() { DescriptorCount = 10, Type = DescriptorHeapType.Sampler, Flags = DescriptorHeapFlags.ShaderVisible }); //bind sampler device.CreateSampler(new SamplerStateDescription() { Filter = Filter.ComparisonMinMagMipLinear, AddressU = TextureAddressMode.Wrap, AddressV = TextureAddressMode.Wrap, AddressW = TextureAddressMode.Wrap, MinimumLod = float.MinValue, MaximumLod = float.MaxValue, MipLodBias = 0, MaximumAnisotropy = 0, ComparisonFunction = Comparison.Never }, samplerViewHeap.CPUDescriptorHandleForHeapStart); commandAllocator = device.CreateCommandAllocator(CommandListType.Direct); bundleAllocator = device.CreateCommandAllocator(CommandListType.Bundle); form.UserResized += (sender, e) => { isResizing = true; }; }
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(); }