Exemple #1
0
    private protected GraphicsContext(GraphicsCommandQueue commandQueue, GraphicsContextKind kind) : base(commandQueue)
    {
        // No need for a CommandQueue.AddContext(this) as it will be done by the underlying pool

        var d3d12CommandListType = kind.AsD3D12CommandListType();

        var d3d12CommandAllocator = CreateD3D12CommandAllocator(d3d12CommandListType, out _d3d12CommandAllocatorVersion);

        _d3d12CommandAllocator.Attach(d3d12CommandAllocator);

        var d3d12GraphicsCommandList = CreateD3D12GraphicsCommandList(d3d12CommandListType, out _d3d12GraphicsCommandListVersion);

        _d3d12GraphicsCommandList.Attach(d3d12GraphicsCommandList);

        _kind  = kind;
        _fence = Device.CreateFence(isSignalled: true);

        SetNameUnsafe(Name);

        ID3D12CommandAllocator *CreateD3D12CommandAllocator(D3D12_COMMAND_LIST_TYPE d3d12CommandListType, out uint d3d12CommandAllocatorVersion)
        {
            ID3D12CommandAllocator *d3d12CommandAllocator;

            ThrowExternalExceptionIfFailed(Device.D3D12Device->CreateCommandAllocator(d3d12CommandListType, __uuidof <ID3D12CommandAllocator>(), (void **)&d3d12CommandAllocator));
            return(GetLatestD3D12CommandAllocator(d3d12CommandAllocator, out d3d12CommandAllocatorVersion));
        }

        ID3D12GraphicsCommandList *CreateD3D12GraphicsCommandList(D3D12_COMMAND_LIST_TYPE d3d12CommandListType, out uint d3d12GraphicsCommandListVersion)
        {
            ID3D12GraphicsCommandList *d3d12GraphicsCommandList;

            if (Device.D3D12DeviceVersion >= 4)
            {
                var d3d12Device4 = (ID3D12Device4 *)Device.D3D12Device;
                ThrowExternalExceptionIfFailed(d3d12Device4->CreateCommandList1(nodeMask: 0, d3d12CommandListType, D3D12_COMMAND_LIST_FLAG_NONE, __uuidof <ID3D12GraphicsCommandList>(), (void **)&d3d12GraphicsCommandList));
            }
            else
            {
                var d3d12Device = Device.D3D12Device;
                ThrowExternalExceptionIfFailed(d3d12Device->CreateCommandList(nodeMask: 0, d3d12CommandListType, _d3d12CommandAllocator, pInitialState: null, __uuidof <ID3D12GraphicsCommandList>(), (void **)&d3d12GraphicsCommandList));

                // Command lists are created in the recording state, but there is nothing
                // to record yet. The main loop expects it to be closed, so close it now.
                ThrowExternalExceptionIfFailed(d3d12GraphicsCommandList->Close());
            }

            return(GetLatestD3D12GraphicsCommandList(d3d12GraphicsCommandList, out d3d12GraphicsCommandListVersion));
        }
    }
Exemple #2
0
 /// <summary>Initializes a new instance of the <see cref="GraphicsCommandQueueObject" /> class.</summary>
 /// <param name="commandQueue">The command queue for which the object is being created.</param>
 /// <param name="name">The name of the object or <c>null</c> to use <see cref="MemberInfo.Name" />.</param>
 /// <exception cref="ArgumentNullException"><paramref name="commandQueue" /> is <c>null</c>.</exception>
 protected GraphicsCommandQueueObject(GraphicsCommandQueue commandQueue, string? name = null) : base(commandQueue.Device, name)
 {
     _commandQueue = commandQueue;
 }