protected override void DestroyWindowSizeDependentResources() { DestroyResourceViews(); DestroySwapChain(); void DestroySwapChain() { var swapChain = _swapChain; if (swapChain != null) { _swapChain = null; _ = swapChain->Release(); } } }
private void CoreInitialize( DeviceManager manager, ID3D12Device *device, IDXGISwapChain3 *swapChain, GraphicalConfiguration config, ScreenData screenData ) { _resourceCount = config.BufferCount; _resourceIndex = swapChain->GetCurrentBackBufferIndex(); _allocator = manager.Allocator; CreateRtvAndDsvResources(swapChain, config, screenData); CreateRtvAndDsvDescriptorHeaps(device, config); CreateRtvAndDsvViews(device, config); }
internal static void Initialize( DeviceManager manager, ID3D12Device *device, IDXGISwapChain3 *swapChain, GraphicalConfiguration config, ScreenData screenData ) { // TODO could probably use CAS/System.Threading.LazyInitializer lock (Lock) { Debug.Assert(!_initialized); _initialized = true; Value.CoreInitialize(manager, device, swapChain, config, screenData); } }
protected override void Dispose(bool isDisposing) { var swapChain = _swapChain; if (swapChain != null) { _swapChain = null; _ = swapChain->Release(); } var device = _device; if (device != null) { _device = null; _ = device->Release(); } for (var index = 0; index < FrameCount; index++) { var renderTarget = _renderTargets[index]; if (renderTarget != null) { _renderTargets[index] = null; _ = renderTarget->Release(); } } var commandAllocator = _commandAllocator; if (commandAllocator != null) { _commandAllocator = null; _ = commandAllocator->Release(); } var bundleAllocator = _bundleAllocator; if (bundleAllocator != null) { _bundleAllocator = null; _ = bundleAllocator->Release(); } var commandQueue = _commandQueue; if (commandQueue != null) { _commandQueue = null; _ = commandQueue->Release(); } var rootSignature = _rootSignature; if (rootSignature != null) { _rootSignature = null; _ = rootSignature->Release(); } var rtvHeap = _rtvHeap; if (rtvHeap != null) { _rtvHeap = null; _ = rtvHeap->Release(); } var pipelineState = _pipelineState; if (pipelineState != null) { _pipelineState = null; _ = pipelineState->Release(); } var commandList = _commandList; if (commandList != null) { _commandList = null; _ = commandList->Release(); } var bundle = _bundle; if (bundle != null) { _bundle = null; _ = bundle->Release(); } var vertexBuffer = _vertexBuffer; if (vertexBuffer != null) { _vertexBuffer = null; _ = vertexBuffer->Release(); } var fence = _fence; if (fence != null) { _fence = null; _ = fence->Release(); } base.Dispose(isDisposing); }
protected override void CreateWindowSizeDependentResources() { // Wait until all previous GPU work is complete. WaitForGpu(moveToNextFrame: false); // Clear the previous window size specific content and update the tracked fence values. for (var i = 0u; i < FrameCount; i++) { _renderTargets[i] = null; _fenceValues[i] = _fenceValues[FrameIndex]; } if (_swapChain != null) { ThrowIfFailed(nameof(IDXGISwapChain3.ResizeBuffers), _swapChain->ResizeBuffers(FrameCount, (uint)Size.Width, (uint)Size.Height, BackBufferFormat, 0)); } else { _swapChain = CreateSwapChain(); } CreateResourceViews(); _viewport = new D3D12_VIEWPORT { TopLeftX = 0, TopLeftY = 0, Width = Size.Width, Height = Size.Height, MinDepth = D3D12_MIN_DEPTH, MaxDepth = D3D12_MAX_DEPTH }; _scissorRect = new RECT { left = 0, top = 0, right = Size.Width, bottom = Size.Height }; IDXGISwapChain3 *CreateSwapChain() { using ComPtr <IDXGISwapChain1> swapChain = null; var swapChainDesc = new DXGI_SWAP_CHAIN_DESC1 { BufferCount = FrameCount, Width = (uint)Size.Width, Height = (uint)Size.Height, Format = BackBufferFormat, BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT, SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD, SampleDesc = new DXGI_SAMPLE_DESC(count: 1, quality: 0), }; ThrowIfFailed(nameof(IDXGIFactory4.CreateSwapChainForHwnd), DxgiFactory->CreateSwapChainForHwnd( (IUnknown *)_commandQueue, // Swap chain needs the queue so that it can force a flush on it. Hwnd, &swapChainDesc, pFullscreenDesc: null, pRestrictToOutput: null, swapChain.GetAddressOf() )); IDXGISwapChain3 *swapChain3; var iid = IID_IDXGISwapChain3; ThrowIfFailed(nameof(IDXGISwapChain1.QueryInterface), swapChain.Get()->QueryInterface(&iid, (void **)&swapChain3)); return(swapChain3); } }
private void CreateRtvAndDsvResources( IDXGISwapChain3 *swapChain, GraphicalConfiguration config, in ScreenData screenData