public static void NameD3D12Object(ID3D12CommandQueue *pObject, string name) { fixed(char *pName = name) { pObject->SetName(pName); } }
public static void PIXBeginEvent(ID3D12CommandQueue *pCommandQueue, ulong metadata, string format) { var size = (uint)((format.Length + 1) * sizeof(char)); fixed(char *pFormat = format) { pCommandQueue->BeginEvent(Detail.PIX_EVENT_UNICODE_VERSION, pFormat, size); } }
public static ID3D12CommandQueue *GetLatestD3D12CommandQueue(ID3D12CommandQueue *d3d12CommandQueue, out uint d3d12CommandQueueVersion) { ID3D12CommandQueue *result; d3d12CommandQueueVersion = 0; result = d3d12CommandQueue; return(result); }
public static void PIXBeginEvent(ID3D12CommandQueue *pCommandQueue, ulong metadata, string format, params object[] args) { string buf = string.Format(format, args); var count = (uint)((buf.Length + 1) * sizeof(char)); fixed(char *pBuf = buf) { pCommandQueue->BeginEvent(Detail.PIX_EVENT_UNICODE_VERSION, pBuf, count); } }
public static void SetMarker( ID3D12CommandQueue *context, ulong *args, uint argsLength, PIXEventsThreadInfo *threadInfo, ulong time ) { SerializeForCpuCapture(args, argsLength, threadInfo, time); SetGPUMarkerOnContext(context, args, argsLength * sizeof(ulong)); }
public static void EndEvent( ID3D12CommandQueue *context, ulong *args, uint argsLength, PIXEventsThreadInfo *threadInfo, ulong time ) { SerializeForCpuCapture(args, argsLength, threadInfo, time); EndGPUEventOnContext(context); }
public void Run() { while (!_windowClosed) { if (_windowVisible) { CoreWindow.GetForCurrentThread().Dispatcher.ProcessEvents(CoreProcessEventsOption.ProcessAllIfPresent); ID3D12CommandQueue *commandQueue = GetDeviceResources().CommandQueue; _main.Update(); if (_main.Render()) { GetDeviceResources().Present(); } } else { CoreWindow.GetForCurrentThread().Dispatcher.ProcessEvents(CoreProcessEventsOption.ProcessOneAndAllPending); } } }
public int AcquireDirect3D12BufferResource(ID3D12Resource *pResourceToAcquire, ID3D12CommandQueue *pCommandQueue) { return(((delegate * unmanaged <IHolographicCameraInterop *, ID3D12Resource *, ID3D12CommandQueue *, int>)(lpVtbl[8]))((IHolographicCameraInterop *)Unsafe.AsPointer(ref this), pResourceToAcquire, pCommandQueue)); }
public void SetThreadDeviceCreationParams([NativeTypeName("ID3D12Device *")] ID3D12Device *pDevice, [NativeTypeName("ID3D12CommandQueue *")] ID3D12CommandQueue *pGraphicsQueue) { ((delegate * unmanaged <ID3D11On12On7 *, ID3D12Device *, ID3D12CommandQueue *, void>)(lpVtbl[3]))((ID3D11On12On7 *)Unsafe.AsPointer(ref this), pDevice, pGraphicsQueue); }
public HRESULT CreateFromD3D12CommandQueue(ID3D12CommandQueue *value, IUnknown **result) { return(((delegate * unmanaged <ILearningModelDeviceFactoryNative *, ID3D12CommandQueue *, IUnknown **, int>)(lpVtbl[3]))((ILearningModelDeviceFactoryNative *)Unsafe.AsPointer(ref this), value, result)); }
public int AcquireDirect3D12BufferResource([NativeTypeName("ID3D12Resource *")] ID3D12Resource *pResourceToAcquire, [NativeTypeName("ID3D12CommandQueue *")] ID3D12CommandQueue *pCommandQueue) { return(((delegate * unmanaged <IHolographicQuadLayerInterop *, ID3D12Resource *, ID3D12CommandQueue *, int>)(lpVtbl[8]))((IHolographicQuadLayerInterop *)Unsafe.AsPointer(ref this), pResourceToAcquire, pCommandQueue)); }
public AutoBreadcrumbNode ( byte *pCommandListDebugNameA = null, char *pCommandListDebugNameW = null, byte *pCommandQueueDebugNameA = null, char *pCommandQueueDebugNameW = null, ID3D12GraphicsCommandList *pCommandList = null, ID3D12CommandQueue *pCommandQueue = null, uint?breadcrumbCount = null, uint *pLastBreadcrumbValue = null, AutoBreadcrumbOp *pCommandHistory = null, AutoBreadcrumbNode *pNext = null ) : this() { if (pCommandListDebugNameA is not null) { PCommandListDebugNameA = pCommandListDebugNameA; } if (pCommandListDebugNameW is not null) { PCommandListDebugNameW = pCommandListDebugNameW; } if (pCommandQueueDebugNameA is not null) { PCommandQueueDebugNameA = pCommandQueueDebugNameA; } if (pCommandQueueDebugNameW is not null) { PCommandQueueDebugNameW = pCommandQueueDebugNameW; } if (pCommandList is not null) { PCommandList = pCommandList; } if (pCommandQueue is not null) { PCommandQueue = pCommandQueue; } if (breadcrumbCount is not null) { BreadcrumbCount = breadcrumbCount.Value; } if (pLastBreadcrumbValue is not null) { PLastBreadcrumbValue = pLastBreadcrumbValue; } if (pCommandHistory is not null) { PCommandHistory = pCommandHistory; } if (pNext is not null) { PNext = pNext; } }
protected override void CreateDeviceDependentResources() { _dxgiFactory = CreateDxgiFactory(); _dxgiAdapter = GetDxgiAdapter(); _d3dDevice = CreateD3DDevice(); _commandQueue = CreateCommandQueue(); CreateDescriptorHeaps(); for (int i = 0; i < FrameCount; i++) { _commandAllocators[i] = CreateCommandAllocator(); } _fence = CreateFence(); _fenceValues = CreateFenceValues(); _fenceEvent = CreateFenceEvent(); _rootSignature = CreateRootSignature(); _pipelineState = CreatePipelineState(); _graphicsCommandLists = CreateGraphicsCommandLists(); ThrowIfFailed(nameof(ID3D12CommandAllocator.Reset), CommandAllocator->Reset()); ThrowIfFailed(nameof(ID3D12GraphicsCommandList.Reset), GraphicsCommandList->Reset(CommandAllocator, PipelineState)); CreateAssets(); ID3D12CommandAllocator *CreateCommandAllocator() { ID3D12CommandAllocator *commandAllocator; var iid = IID_ID3D12CommandAllocator; ThrowIfFailed(nameof(ID3D12Device.CreateCommandAllocator), D3DDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, &iid, (void **)&commandAllocator)); return(commandAllocator); } ID3D12CommandQueue *CreateCommandQueue() { var queueDesc = new D3D12_COMMAND_QUEUE_DESC(); ID3D12CommandQueue *commandQueue; var iid = IID_ID3D12CommandQueue; ThrowIfFailed(nameof(ID3D12Device.CreateCommandQueue), D3DDevice->CreateCommandQueue(&queueDesc, &iid, (void **)&commandQueue)); return(commandQueue); } ID3D12Device *CreateD3DDevice() { ID3D12Device *d3dDevice; var iid = IID_ID3D12Device; ThrowIfFailed(nameof(D3D12CreateDevice), D3D12CreateDevice((IUnknown *)_dxgiAdapter, D3D_FEATURE_LEVEL_11_0, &iid, (void **)&d3dDevice)); return(d3dDevice); } IDXGIFactory4 *CreateDxgiFactory() { var dxgiFactoryFlags = TryEnableDebugLayer() ? DXGI_CREATE_FACTORY_DEBUG : 0u; IDXGIFactory4 *dxgiFactory; var iid = IID_IDXGIFactory4; ThrowIfFailed(nameof(CreateDXGIFactory2), CreateDXGIFactory2(dxgiFactoryFlags, &iid, (void **)&dxgiFactory)); return(dxgiFactory); } ID3D12Fence *CreateFence() { ID3D12Fence *fence; var iid = IID_ID3D12Fence; ThrowIfFailed(nameof(ID3D12Device.CreateFence), D3DDevice->CreateFence(InitialValue: 0, D3D12_FENCE_FLAG_NONE, &iid, (void **)&fence)); return(fence); } IntPtr CreateFenceEvent() { var fenceEvent = CreateEventW(lpEventAttributes: null, bManualReset: FALSE, bInitialState: FALSE, lpName: null); if (fenceEvent == IntPtr.Zero) { var hr = Marshal.GetHRForLastWin32Error(); Marshal.ThrowExceptionForHR(hr); } return(fenceEvent); } ulong[] CreateFenceValues() { var fenceValues = new ulong[FrameCount]; fenceValues[0] = 1; return(fenceValues); } ID3D12GraphicsCommandList *[] CreateGraphicsCommandLists() { var graphicsCommandLists = new ID3D12GraphicsCommandList *[FrameCount]; for (uint i = 0u; i < FrameCount; i++) { ID3D12GraphicsCommandList *graphicsCommandList; var iid = IID_ID3D12GraphicsCommandList; ThrowIfFailed(nameof(ID3D12Device.CreateCommandList), D3DDevice->CreateCommandList(nodeMask: 0, D3D12_COMMAND_LIST_TYPE_DIRECT, _commandAllocators[i], PipelineState, &iid, (void **)&graphicsCommandList)); ThrowIfFailed(nameof(ID3D12GraphicsCommandList.Close), graphicsCommandList->Close()); graphicsCommandLists[i] = graphicsCommandList; } return(graphicsCommandLists); } IDXGIAdapter1 *GetDxgiAdapter() { if (UseWarpDevice) { IDXGIAdapter1 *adapter; var iid = IID_IDXGIAdapter; ThrowIfFailed(nameof(IDXGIFactory4.EnumWarpAdapter), _dxgiFactory->EnumWarpAdapter(&iid, (void **)&adapter)); return(adapter); } else { return(GetHardwareAdapter((IDXGIFactory1 *)_dxgiFactory)); } } bool TryEnableDebugLayer() { #if DEBUG // Enable the debug layer (requires the Graphics Tools "optional feature"). // NOTE: Enabling the debug layer after device creation will invalidate the active device. using ComPtr <ID3D12Debug> debugController = null; var iid = IID_ID3D12Debug; if (SUCCEEDED(D3D12GetDebugInterface(&iid, (void **)&debugController))) { debugController.Get()->EnableDebugLayer(); return(true); } #endif return(false); } }
private ScopedEvent(ID3D12CommandQueue *context) { _context = context; _type = ContextType.Queue; }
public int AcquireDirect3D12BufferResourceWithTimeout(ID3D12Resource *pResourceToAcquire, ID3D12CommandQueue *pCommandQueue, [NativeTypeName("UINT64")] ulong duration) { return(((delegate * unmanaged <IHolographicCameraInterop *, ID3D12Resource *, ID3D12CommandQueue *, ulong, int>)(lpVtbl[9]))((IHolographicCameraInterop *)Unsafe.AsPointer(ref this), pResourceToAcquire, pCommandQueue, duration)); }
public int UnwrapUnderlyingResource(ID3D11Resource *pResource11, ID3D12CommandQueue *pCommandQueue, [NativeTypeName("const IID &")] Guid *riid, void **ppvResource12) { return(((delegate * unmanaged <ID3D11On12Device2 *, ID3D11Resource *, ID3D12CommandQueue *, Guid *, void **, int>)(lpVtbl[7]))((ID3D11On12Device2 *)Unsafe.AsPointer(ref this), pResource11, pCommandQueue, riid, ppvResource12)); }
public static void PIXEndEvent(ID3D12CommandQueue *pCommandQueue) { pCommandQueue->EndEvent(); }
protected override void DestroyDeviceDependentResources() { DestroyAssets(); DestroyGraphicsCommandLists(); DestroyPipelineState(); DestroyRootSignature(); DestroyFenceEvent(); DestroyFence(); DestroyCommandAllocators(); DestroyDescriptorHeaps(); DestroyCommandQueue(); DestroyD3DDevice(); DestroyDxgiAdapter(); DestroyDxgiFactory(); void DestroyCommandAllocators() { for (var i = 0; i < _commandAllocators.Length; i++) { var commandAllocator = _commandAllocators[i]; if (commandAllocator != null) { _commandAllocators[i] = null; _ = commandAllocator->Release(); } } } void DestroyCommandQueue() { var commandQueue = _commandQueue; if (commandQueue != null) { _commandQueue = null; _ = commandQueue->Release(); } } void DestroyD3DDevice() { var d3dDevice = _d3dDevice; if (d3dDevice != null) { _d3dDevice = null; _ = d3dDevice->Release(); } } void DestroyDxgiAdapter() { var dxgiAdapter = _dxgiAdapter; if (dxgiAdapter != null) { _dxgiAdapter = null; _ = dxgiAdapter->Release(); } } void DestroyDxgiFactory() { var dxgiFactory = _dxgiFactory; if (dxgiFactory != null) { _dxgiFactory = null; _ = dxgiFactory->Release(); } } void DestroyFence() { var fence = _fence; if (fence != null) { _fence = null; _ = fence->Release(); } } void DestroyFenceEvent() { var fenceEvent = _fenceEvent; if (fenceEvent != IntPtr.Zero) { _fenceEvent = IntPtr.Zero; _ = CloseHandle(_fenceEvent); } } void DestroyGraphicsCommandLists() { for (var i = 0; i < _graphicsCommandLists.Length; i++) { var graphicsCommandList = _graphicsCommandLists[i]; if (graphicsCommandList != null) { _graphicsCommandLists[i] = null; _ = graphicsCommandList->Release(); } } } void DestroyPipelineState() { var pipelineState = _pipelineState; if (pipelineState != null) { _pipelineState = null; _ = pipelineState->Release(); } } void DestroyRootSignature() { var rootSignature = _rootSignature; if (rootSignature != null) { _rootSignature = null; _ = rootSignature->Release(); } } }
internal PixScopedEvent(ID3D12CommandQueue *context) { _context = context; _type = ContextType.Queue; }
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 CreateDeviceDependentResources() { _dxgiFactory = CreateDxgiFactory(); _dxgiAdapter = GetDxgiAdapter(); _d3dDevice = CreateD3DDevice(); StartInfoPump(); _commandQueue = CreateCommandQueue(); CreateDescriptorHeaps(); for (int i = 0; i < FrameCount; i++) { _commandAllocators[i] = CreateCommandAllocator(); } _fence = CreateFence(); _fenceValues = CreateFenceValues(); _fenceEvent = CreateFenceEvent(); _rootSignature = CreateRootSignature(); _pipelineState = CreatePipelineState(); _graphicsCommandLists = CreateGraphicsCommandLists(); SilkMarshal.ThrowHResult(CommandAllocator->Reset()); SilkMarshal.ThrowHResult(GraphicsCommandList->Reset(CommandAllocator, PipelineState)); CreateAssets(); ID3D12CommandAllocator *CreateCommandAllocator() { ID3D12CommandAllocator *commandAllocator; var iid = ID3D12CommandAllocator.Guid; SilkMarshal.ThrowHResult ( D3DDevice->CreateCommandAllocator (CommandListType.CommandListTypeDirect, &iid, (void **)&commandAllocator) ); return(commandAllocator); } ID3D12CommandQueue *CreateCommandQueue() { var queueDesc = new CommandQueueDesc(); ID3D12CommandQueue *commandQueue; var iid = ID3D12CommandQueue.Guid; SilkMarshal.ThrowHResult(D3DDevice->CreateCommandQueue(&queueDesc, &iid, (void **)&commandQueue)); return(commandQueue); } ID3D12Device *CreateD3DDevice() { ID3D12Device *d3dDevice; var iid = ID3D12Device.Guid; SilkMarshal.ThrowHResult ( D3D12.CreateDevice ((IUnknown *)_dxgiAdapter, D3DFeatureLevel.D3DFeatureLevel110, &iid, (void **)&d3dDevice) ); return(d3dDevice); } IDXGIFactory4 *CreateDxgiFactory() { var dxgiFactoryFlags = TryEnableDebugLayer() ? 0x01 : 0u; IDXGIFactory4 *dxgiFactory; var iid = IDXGIFactory4.Guid; SilkMarshal.ThrowHResult(Dxgi.CreateDXGIFactory2(dxgiFactoryFlags, &iid, (void **)&dxgiFactory)); return(dxgiFactory); } ID3D12Fence *CreateFence() { ID3D12Fence *fence; var iid = ID3D12Fence.Guid; SilkMarshal.ThrowHResult (D3DDevice->CreateFence(InitialValue: 0, FenceFlags.FenceFlagNone, &iid, (void **)&fence)); return(fence); } IntPtr CreateFenceEvent() { var fenceEvent = SilkMarshal.CreateWindowsEvent(null, false, false, null); if (fenceEvent == IntPtr.Zero) { var hr = Marshal.GetHRForLastWin32Error(); Marshal.ThrowExceptionForHR(hr); } return(fenceEvent); } ulong[] CreateFenceValues() { var fenceValues = new ulong[FrameCount]; fenceValues[0] = 1; return(fenceValues); } ID3D12GraphicsCommandList *[] CreateGraphicsCommandLists() { var graphicsCommandLists = new ID3D12GraphicsCommandList *[FrameCount]; for (uint i = 0u; i < FrameCount; i++) { ID3D12GraphicsCommandList *graphicsCommandList; var iid = ID3D12GraphicsCommandList.Guid; SilkMarshal.ThrowHResult ( D3DDevice->CreateCommandList ( nodeMask: 0, CommandListType.CommandListTypeDirect, _commandAllocators[i], PipelineState, &iid, (void **)&graphicsCommandList ) ); SilkMarshal.ThrowHResult(graphicsCommandList->Close()); graphicsCommandLists[i] = graphicsCommandList; } return(graphicsCommandLists); } IDXGIAdapter1 *GetDxgiAdapter() { if (UseWarpDevice) { IDXGIAdapter1 *adapter; var iid = IDXGIAdapter.Guid; SilkMarshal.ThrowHResult(_dxgiFactory->EnumWarpAdapter(&iid, (void **)&adapter)); return(adapter); } else { return(GetHardwareAdapter((IDXGIFactory1 *)_dxgiFactory)); } } bool TryEnableDebugLayer() { #if DEBUG // Enable the debug layer (requires the Graphics Tools "optional feature"). // NOTE: Enabling the debug layer after device creation will invalidate the active device. using ComPtr <ID3D12Debug> debugController = null; var iid = ID3D12Debug.Guid; var hr = D3D12.GetDebugInterface(&iid, (void **)&debugController); if (HResult.IndicatesSuccess(hr)) { debugController.Get().EnableDebugLayer(); Log.LogInformation("Debug layer enabled"); return(_debug = true); } else { Log.LogWarning ( Marshal.GetExceptionForHR(hr), $"Failed to enable debug layer, failed with result {hr} (0x{hr:x8})" ); } #endif return(false); } void StartInfoPump() { #if DEBUG if (!_debug) { Log.LogInformation("Skipped creation of info pump due to the debug layer not being enabled."); return; } var iid = ID3D12InfoQueue.Guid; fixed(ID3D12InfoQueue ** @out = &_infoQueue) { SilkMarshal.ThrowHResult(D3DDevice->QueryInterface(&iid, (void **)@out)); } _infoPumpCancellationToken = new(); _infoPump = Task.Run ( () => { Log.LogInformation("Info queue pump started"); while (!_infoPumpCancellationToken.Token.IsCancellationRequested) { var numMessages = _infoQueue->GetNumStoredMessages(); if (numMessages == 0) { continue; } for (var i = 0ul; i < numMessages; i++) { nuint msgByteLength; SilkMarshal.ThrowHResult(_infoQueue->GetMessageA(i, null, &msgByteLength)); using var memory = GlobalMemory.Allocate((int)msgByteLength); SilkMarshal.ThrowHResult ( _infoQueue->GetMessageA(i, memory.AsPtr <Message>(), &msgByteLength) ); ref var msg = ref memory.AsRef <Message>(); var descBytes = new Span <byte>(msg.PDescription, (int)msg.DescriptionByteLength); var desc = Encoding.UTF8.GetString(descBytes[..^ 1]); var eid = new EventId((int)msg.ID, msg.ID.ToString()["MessageID".Length..]);