protected override void CreateImpl() { var swapChainDesc = new SwapChainDescription() { BufferCount = (int)Desc.BufferCount, ModeDescription = new ModeDescription((int) Desc.Width, (int)Desc.Height, new Rational(0,0), Memory.Enums.ToDXGIFormat[(int)Desc.Format]), Usage = Usage.RenderTargetOutput, SwapEffect = SwapEffect.FlipDiscard, OutputHandle = Desc.WindowHandle, SampleDescription = new SampleDescription { Count = (int) Desc.SampleCount, Quality = (int) Desc.SampleQuality }, IsWindowed = !Desc.Fullscreen }; using (var factory = new Factory4()) { var tempSwapChain = new SharpDX.DXGI.SwapChain(factory, ((CommandQueue)Desc.AssociatedGraphicsQueue).CommandQueueD3D12, swapChainDesc); SwapChainDXGI = tempSwapChain.QueryInterface<SwapChain3>(); tempSwapChain.Dispose(); CurrentBackBufferIndex = (uint)SwapChainDXGI.CurrentBackBufferIndex; } SwapChainDXGI.DebugName = Label; Log.Info("Created SwapChain"); }
protected override void CreateImpl() { var swapChainDesc = new SwapChainDescription() { BufferCount = (int)Desc.BufferCount, ModeDescription = new ModeDescription((int)Desc.Width, (int)Desc.Height, new Rational(0, 0), Memory.Enums.ToDXGIFormat[(int)Desc.Format]), Usage = Usage.RenderTargetOutput, SwapEffect = SwapEffect.FlipDiscard, OutputHandle = Desc.WindowHandle, SampleDescription = new SampleDescription { Count = (int)Desc.SampleCount, Quality = (int)Desc.SampleQuality }, IsWindowed = !Desc.Fullscreen }; using (var factory = new Factory4()) { var tempSwapChain = new SharpDX.DXGI.SwapChain(factory, ((CommandQueue)Desc.AssociatedGraphicsQueue).CommandQueueD3D12, swapChainDesc); SwapChainDXGI = tempSwapChain.QueryInterface <SwapChain3>(); tempSwapChain.Dispose(); CurrentBackBufferIndex = (uint)SwapChainDXGI.CurrentBackBufferIndex; } SwapChainDXGI.DebugName = Label; Log.Info("Created SwapChain"); }
public void Initialize() { // Lets create a present command queue var queueDesc = new CommandQueueDescription(CommandListType.Direct); NativeCommandQueue = Device.NativeDevice.CreateCommandQueue(queueDesc); // Descirbe and create the swap chain using (var factory = new Factory4()) { var width = Description.Width; var height = Description.Height; var swapChainDescription = new SwapChainDescription { BufferCount = BackBufferCount, ModeDescription = new ModeDescription(width, height, new Rational(60, 1), Format.B8G8R8A8_UNorm), Usage = Usage.RenderTargetOutput, SwapEffect = SwapEffect.FlipDiscard, OutputHandle = Description.WindowHandle, Flags = SwapChainFlags.None, SampleDescription = new SampleDescription(1, 0), IsWindowed = true }; using (var tempSwapChain = new SharpDX.DXGI.SwapChain(factory, NativeCommandQueue, swapChainDescription)) { NativeSwapChain = tempSwapChain.QueryInterface <SwapChain3>(); BackBufferIndex = NativeSwapChain.CurrentBackBufferIndex; } } // We need now to retrieve the back buffers: // 1) We need a heap to store the views BackBuffers = new Texture[BackBufferCount]; for (int i = 0; i < BackBufferCount; i++) { BackBuffers[i] = new Texture(Device); BackBuffers[i].Initialize(NativeSwapChain.GetBackBuffer <Resource>(i)); } BackBuffer = new Texture(Device); BackBuffer.Initialize(NativeSwapChain.GetBackBuffer <Resource>(BackBufferIndex)); CreateDepthStencilBuffer(); Device.PrintLiveObjects(); }
private List<IntPtr> GetProcAddress() { var address = new List<IntPtr>(); _device12 = new SharpDX.Direct3D12.Device(null, SharpDX.Direct3D.FeatureLevel.Level_11_0); using (var renderForm = new Form()) { using (var factory = new SharpDX.DXGI.Factory4()) { _commandQueue = _device12.CreateCommandQueue(new SharpDX.Direct3D12.CommandQueueDescription(SharpDX.Direct3D12.CommandListType.Direct)); _commandAllocator = _device12.CreateCommandAllocator(CommandListType.Direct); _commandList = _device12.CreateCommandList(CommandListType.Direct, _commandAllocator, null); var swapChainDesc = new SharpDX.DXGI.SwapChainDescription() { BufferCount = 2, ModeDescription = new SharpDX.DXGI.ModeDescription(100, 100, new SharpDX.DXGI.Rational(60, 1), SharpDX.DXGI.Format.R8G8B8A8_UNorm), Usage = SharpDX.DXGI.Usage.RenderTargetOutput, SwapEffect = SharpDX.DXGI.SwapEffect.FlipDiscard, OutputHandle = renderForm.Handle, Flags = SwapChainFlags.AllowModeSwitch, SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0), IsWindowed = true }; var tempSwapChain = new SharpDX.DXGI.SwapChain(factory, _commandQueue, swapChainDesc); _swapChain = tempSwapChain.QueryInterface<SharpDX.DXGI.SwapChain3>(); tempSwapChain.Dispose(); } if (_device12 != null && _swapChain != null) { address.AddRange(GetVTblAddresses(_device12.NativePointer, 44)); address.AddRange(GetVTblAddresses(_commandQueue.NativePointer, 19)); address.AddRange(GetVTblAddresses(_commandAllocator.NativePointer, 9)); address.AddRange(GetVTblAddresses(_commandList.NativePointer, 60)); address.AddRange(GetVTblAddresses(_swapChain.NativePointer, 18)); _device12.Dispose(); _device12 = null; _commandQueue.Dispose(); _commandQueue = null; _commandAllocator.Dispose(); _commandAllocator = null; _commandList.Dispose(); _commandList = null; _swapChain.Dispose(); _swapChain = null; } } return address; }