Example #1
0
        //释放资源
        public void Dispose()
        {
            //等待GPU处理完所有的资源
            WaitForPreviousFrame();

            //释放所有资源
            foreach (var target in renderTargets)
            {
                target.Dispose();
            }
            commandAllocator.Dispose();
            bundleAllocator.Dispose();
            commandQueue.Dispose();
            rootSignature.Dispose();
            pipelineState.Dispose();
            vertexBuffer.Dispose();
            texture.Dispose();
            indexBuffer.Dispose();
            renderTargetViewHeap.Dispose();
            commandList.Dispose();
            bundle.Dispose();
            fence.Dispose();
            swapChain.Dispose();
            device.Dispose();
        }
        private void PlatformEnd()
        {
            _commandList.Close();

            var d3d12CommandQueue = _graphicsDevice.CommandQueue.DeviceCommandQueue;

            d3d12CommandQueue.ExecuteCommandList(_commandList);

            using (var fence = _device.CreateFence(0, FenceFlags.None))
                using (var gpuCompletedEvent = new ManualResetEvent(false))
                {
                    d3d12CommandQueue.Signal(fence, 1);
                    fence.SetEventOnCompletion(1, gpuCompletedEvent.GetSafeWaitHandle().DangerousGetHandle());

                    gpuCompletedEvent.WaitOne();
                }

            foreach (var resource in _trackedResources)
            {
                resource.Dispose();
            }
            _trackedResources.Clear();

            _commandList.Dispose();
            _commandList = null;

            _commandAllocator.Dispose();
            _commandAllocator = null;
        }
        public void Dispose()
        {
            WaitForPreviousFrame();

            foreach (var target in renderTargets)
            {
                target.Dispose();
            }
            commandAllocator.Dispose();
            commandQueue.Dispose();
            rootSignature.Dispose();
            renderTargetViewHeap.Dispose();
            pipelineState.Dispose();
            commandList.Dispose();
            vertexBuffer.Dispose();
            fence.Dispose();
            swapChain.Dispose();
            device.Dispose();
        }
Example #4
0
        public void Dispose()
        {
            // Wait for the GPU to be done with all resources.
            WaitForPreviousFrame();

            foreach (var target in _renderTargets)
            {
                target.Dispose();
            }
            _commandAllocator.Dispose();
            _graphicsQueue.Dispose();
            _rootSignature.Dispose();
            _renderTargetViewHeap.Dispose();
            _pipelineState.Dispose();
            _commandList.Dispose();
            _fence.Dispose();
            _swapChain.Dispose();
            _device.Dispose();
        }
Example #5
0
        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;
        }