コード例 #1
0
            public ListCreationParams(
                ExecutionContext context,
                ID3D12CommandAllocator *allocator,
                ID3D12PipelineState *pso
                )
            {
                Debug.Assert(allocator != null);

                Type      = (D3D12_COMMAND_LIST_TYPE)context;
                Allocator = allocator;
                Pso       = pso;
            }
コード例 #2
0
        private ID3D12CommandAllocator *[] CreateCommandAllocators()
        {
            var commandAllocators = new ID3D12CommandAllocator *[_graphicsSurface.BufferCount];
            var iid = IID_ID3D12CommandAllocator;

            for (var i = 0; i < commandAllocators.Length; i++)
            {
                ID3D12CommandAllocator *commandAllocator;
                ThrowExternalExceptionIfFailed(nameof(ID3D12Device.CreateCommandAllocator), Device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, &iid, (void **)&commandAllocator));
                commandAllocators[i] = commandAllocator;
            }

            return(commandAllocators);
        }
コード例 #3
0
        protected override void CreateAssets()
        {
            base.CreateAssets();

            _bundleAllocator = CreateBundleAllocator();
            _bundle          = CreateBundle();

            ID3D12GraphicsCommandList *CreateBundle()
            {
                ID3D12GraphicsCommandList *bundle;

                var iid = IID_ID3D12GraphicsCommandList;

                ThrowIfFailed(nameof(ID3D12Device.CreateCommandList), D3DDevice->CreateCommandList(nodeMask: 0, D3D12_COMMAND_LIST_TYPE_BUNDLE, _bundleAllocator, PipelineState, &iid, (void **)&bundle));

                bundle->SetGraphicsRootSignature(RootSignature);
                bundle->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

                fixed(D3D12_VERTEX_BUFFER_VIEW *pVertexBufferView = &VertexBufferView)
                {
                    bundle->IASetVertexBuffers(StartSlot: 0, 1, pVertexBufferView);
                }

                bundle->DrawInstanced(3, 1, 0, 0);
                ThrowIfFailed(nameof(ID3D12GraphicsCommandList.Close), bundle->Close());

                return(bundle);
            }

            ID3D12CommandAllocator *CreateBundleAllocator()
            {
                ID3D12CommandAllocator *bundleAllocator;

                var iid = IID_ID3D12CommandAllocator;

                ThrowIfFailed(nameof(ID3D12Device.CreateCommandAllocator), D3DDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_BUNDLE, &iid, (void **)&bundleAllocator));

                return(bundleAllocator);
            }
        }
コード例 #4
0
 public HRESULT Reset(ID3D12CommandAllocator *pAllocator)
 {
     return(((delegate * unmanaged <ID3D12VideoDecodeCommandList2 *, ID3D12CommandAllocator *, int>)(lpVtbl[10]))((ID3D12VideoDecodeCommandList2 *)Unsafe.AsPointer(ref this), pAllocator));
 }
コード例 #5
0
 public int CreateCommandList([NativeTypeName("UINT")] uint nodeMask, D3D12_COMMAND_LIST_TYPE type, [NativeTypeName("ID3D12CommandAllocator *")] ID3D12CommandAllocator *pCommandAllocator, [NativeTypeName("ID3D12PipelineState *")] ID3D12PipelineState *pInitialState, [NativeTypeName("const IID &")] Guid *riid, [NativeTypeName("void **")] void **ppCommandList)
 {
     return(((delegate * unmanaged <ID3D12Device *, uint, D3D12_COMMAND_LIST_TYPE, ID3D12CommandAllocator *, ID3D12PipelineState *, Guid *, void **, int>)(lpVtbl[12]))((ID3D12Device *)Unsafe.AsPointer(ref this), nodeMask, type, pCommandAllocator, pInitialState, riid, ppCommandList));
 }
コード例 #6
0
 public int Reset(ID3D12CommandAllocator *pAllocator, ID3D12PipelineState *pInitialState)
 {
     return(((delegate * unmanaged <ID3D12GraphicsCommandList2 *, ID3D12CommandAllocator *, ID3D12PipelineState *, int>)(lpVtbl[10]))((ID3D12GraphicsCommandList2 *)Unsafe.AsPointer(ref this), pAllocator, pInitialState));
 }
コード例 #7
0
 public int Reset([NativeTypeName("ID3D12CommandAllocator *")] ID3D12CommandAllocator *pAllocator)
 {
     return(((delegate * stdcall <ID3D12VideoProcessCommandList *, ID3D12CommandAllocator *, int>)(lpVtbl[10]))((ID3D12VideoProcessCommandList *)Unsafe.AsPointer(ref this), pAllocator));
 }
コード例 #8
0
 public int Reset([NativeTypeName("ID3D12CommandAllocator *")] ID3D12CommandAllocator *pAllocator, [NativeTypeName("ID3D12PipelineState *")] ID3D12PipelineState *pInitialState)
 {
     return(((delegate * stdcall <ID3D12GraphicsCommandList4 *, ID3D12CommandAllocator *, ID3D12PipelineState *, int>)(lpVtbl[10]))((ID3D12GraphicsCommandList4 *)Unsafe.AsPointer(ref this), pAllocator, pInitialState));
 }
コード例 #9
0
ファイル: CommandListPool.cs プロジェクト: john-h-k/Voltium
 public UniqueComPtr <ID3D12GraphicsCommandList> Rent(
     ExecutionContext context,
     ID3D12CommandAllocator *allocator,
     ID3D12PipelineState *pso
     )
 => Rent(new ListCreationParams(context, allocator, pso));
 public int Reset(ID3D12CommandAllocator *pAllocator)
 {
     return(((delegate * unmanaged <ID3D12VideoProcessCommandList1 *, ID3D12CommandAllocator *, int>)(lpVtbl[10]))((ID3D12VideoProcessCommandList1 *)Unsafe.AsPointer(ref this), pAllocator));
 }
コード例 #11
0
        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);
        }
コード例 #12
0
 public int Reset([NativeTypeName("ID3D12CommandAllocator *")] ID3D12CommandAllocator *pAllocator)
 {
     return(((delegate * unmanaged <ID3D12VideoDecodeCommandList1 *, ID3D12CommandAllocator *, int>)(lpVtbl[10]))((ID3D12VideoDecodeCommandList1 *)Unsafe.AsPointer(ref this), pAllocator));
 }
コード例 #13
0
    /// <summary>
    /// Rents a <see cref="ID3D12GraphicsCommandList"/> and <see cref="ID3D12CommandAllocator"/> pair.
    /// </summary>
    /// <param name="d3D12Device">The <see cref="ID3D12Device"/> renting the command list.</param>
    /// <param name="d3D12PipelineState">The <see cref="ID3D12PipelineState"/> instance to use for the new command list.</param>
    /// <param name="d3D12CommandList">The resulting <see cref="ID3D12GraphicsCommandList"/> value.</param>
    /// <param name="d3D12CommandAllocator">The resulting <see cref="ID3D12CommandAllocator"/> value.</param>
    public void Rent(ID3D12Device *d3D12Device, ID3D12PipelineState *d3D12PipelineState, out ID3D12GraphicsCommandList *d3D12CommandList, out ID3D12CommandAllocator *d3D12CommandAllocator)
    {
        lock (this.d3D12CommandListBundleQueue)
        {
            if (this.d3D12CommandListBundleQueue.TryDequeue(out D3D12CommandListBundle d3D12CommandListBundle))
            {
                d3D12CommandList      = d3D12CommandListBundle.D3D12CommandList;
                d3D12CommandAllocator = d3D12CommandListBundle.D3D12CommandAllocator;
            }
            else
            {
                d3D12CommandAllocator = null;
                d3D12CommandList      = null;
            }
        }

        // Reset the command allocator and command list outside of the lock, or create a new pair if one to be reused
        // wasn't available. These operations are relatively expensive, so doing so here reduces thread contention
        // when multiple shader executions are being dispatched in parallel on the same device.
        if (d3D12CommandAllocator is not null)
        {
            d3D12CommandAllocator->Reset().Assert();
            d3D12CommandList->Reset(d3D12CommandAllocator, d3D12PipelineState).Assert();
        }
        else
        {
            CreateCommandListAndAllocator(d3D12Device, d3D12PipelineState, out d3D12CommandList, out d3D12CommandAllocator);
        }
    }
コード例 #14
0
 /// <summary>
 /// Creates a new <see cref="D3D12CommandListBundle"/> instance with the given parameters.
 /// </summary>
 /// <param name="d3D12CommandList">The <see cref="ID3D12GraphicsCommandList"/> value to wrap.</param>
 /// <param name="d3D12CommandAllocator">The <see cref="ID3D12CommandAllocator"/> value to wrap.</param>
 public D3D12CommandListBundle(ID3D12GraphicsCommandList *d3D12CommandList, ID3D12CommandAllocator *d3D12CommandAllocator)
 {
     D3D12CommandList      = d3D12CommandList;
     D3D12CommandAllocator = d3D12CommandAllocator;
 }
コード例 #15
0
    private void CreateCommandListAndAllocator(ID3D12Device *d3D12Device, ID3D12PipelineState *d3D12PipelineState, out ID3D12GraphicsCommandList *d3D12CommandList, out ID3D12CommandAllocator *d3D12CommandAllocator)
    {
        using ComPtr <ID3D12CommandAllocator> d3D12CommandAllocatorComPtr = d3D12Device->CreateCommandAllocator(this.d3D12CommandListType);
        using ComPtr <ID3D12GraphicsCommandList> d3D12CommandListComPtr   = d3D12Device->CreateCommandList(this.d3D12CommandListType, d3D12CommandAllocatorComPtr.Get(), d3D12PipelineState);

        fixed(ID3D12GraphicsCommandList **d3D12CommandListPtr = &d3D12CommandList)
        fixed(ID3D12CommandAllocator **d3D12CommandAllocatorPtr = &d3D12CommandAllocator)
        {
            d3D12CommandListComPtr.CopyTo(d3D12CommandListPtr);
            d3D12CommandAllocatorComPtr.CopyTo(d3D12CommandAllocatorPtr);
        }
    }