private protected GraphicsCommandQueue(GraphicsDevice device, GraphicsContextKind kind) : base(device) { var d3d12CommandListType = kind.AsD3D12CommandListType(); var d3d12CommandQueue = CreateD3D12CommandQueue(d3d12CommandListType, out _d3d12CommandQueueVersion); _d3d12CommandQueue.Attach(d3d12CommandQueue); _kind = kind; _waitForIdleFence = device.CreateFence(isSignalled: false); SetNameUnsafe(Name); ID3D12CommandQueue *CreateD3D12CommandQueue(D3D12_COMMAND_LIST_TYPE d3d12CommandListType, out uint d3d12CommandQueueVersion) { ID3D12CommandQueue *d3d12CommandQueue; var d3d12CommandQueueDesc = new D3D12_COMMAND_QUEUE_DESC { Type = d3d12CommandListType, Priority = 0, Flags = D3D12_COMMAND_QUEUE_FLAG_NONE, NodeMask = 0, }; ThrowExternalExceptionIfFailed(Device.D3D12Device->CreateCommandQueue(&d3d12CommandQueueDesc, __uuidof <ID3D12CommandQueue>(), (void **)&d3d12CommandQueue)); return(GetLatestD3D12CommandQueue(d3d12CommandQueue, out d3d12CommandQueueVersion)); } }
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)); } }
public static D3D12_COMMAND_LIST_TYPE AsD3D12CommandListType(this GraphicsContextKind kind) => s_d3d12CommandListTypeMap[(uint)kind];