protected virtual void Dispose(bool disposing) { // Implements the basic dispose pattern. // Ref: https://msdn.microsoft.com/en-us/library/b1yfkh5e(v=vs.110).aspx if (disposing) { FlushCommandQueue(); RtvHeap?.Dispose(); DsvHeap?.Dispose(); SwapChain?.Dispose(); foreach (Resource buffer in _swapChainBuffers) { buffer?.Dispose(); } DepthStencilBuffer?.Dispose(); CommandList?.Dispose(); DirectCmdListAlloc?.Dispose(); CommandQueue?.Dispose(); Fence?.Dispose(); Device?.Dispose(); } }
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; }