public static void Initialize(ComPtr <ID3D12InfoQueue> infoQueue)
        {
            if (!IsEnabled)
            {
                return;
            }

            Debug.Assert(infoQueue.Exists);
            _infoQueue = infoQueue;

            // we deny retrieving anything that isn't an error/warning/corruption
            var deniedSeverities = stackalloc D3D12_MESSAGE_SEVERITY[2]
            {
                D3D12_MESSAGE_SEVERITY.D3D12_MESSAGE_SEVERITY_INFO,
                D3D12_MESSAGE_SEVERITY.D3D12_MESSAGE_SEVERITY_MESSAGE
            };

            var filter = new D3D12_INFO_QUEUE_FILTER
            {
                DenyList = new D3D12_INFO_QUEUE_FILTER_DESC {
                    NumSeverities = 2, pSeverityList = deniedSeverities
                }
            };

            infoQueue.Get()->AddRetrievalFilterEntries(&filter);

            // this causes an SEH exception to be thrown every time a DX error or corruption occurs
#if THROW_ON_D3D12_ERROR
            infoQueue.Get()->SetBreakOnSeverity(D3D12_MESSAGE_SEVERITY.D3D12_MESSAGE_SEVERITY_ERROR, Windows.TRUE);
            infoQueue.Get()->SetBreakOnSeverity(D3D12_MESSAGE_SEVERITY.D3D12_MESSAGE_SEVERITY_CORRUPTION, Windows.TRUE);
#endif
#if THROW_ON_WARNING
            infoQueue.Get()->SetBreakOnSeverity(D3D12_MESSAGE_SEVERITY.D3D12_MESSAGE_SEVERITY_WARNING, Windows.TRUE);
#endif
        }
        public static void WriteAllMessages()
        {
            if (!IsEnabled)
            {
                return;
            }

            byte *buffer = stackalloc byte[StackSentinel.MaxStackallocBytes];

            for (ulong i = 0; i < _infoQueue.Get()->GetNumStoredMessagesAllowedByRetrievalFilter(); i++)
            {
                nuint pLength;
                int   hr = _infoQueue.Get()->GetMessage(i, null, &pLength);

                int length = (int)pLength;

                byte[]? rented = null;
                string transcoded;
                try
                {
                    if (length < StackSentinel.MaxStackallocBytes)
                    {
                        var msgBuffer = (D3D12_MESSAGE *)buffer;
                        _infoQueue.Get()->GetMessage(i, (D3D12_MESSAGE *)buffer, &pLength);
                        transcoded = Encoding.ASCII.GetString(
                            (byte *)msgBuffer->pDescription,
                            (int)msgBuffer->DescriptionByteLength
                            );
                    }
                    else
                    {
                        rented = ArrayPool <byte> .Shared.Rent(length);

                        fixed(byte *pHeapBuffer = &rented[0])
                        {
                            var msgBuffer = (D3D12_MESSAGE *)pHeapBuffer;

                            _infoQueue.Get()->GetMessage(i, msgBuffer, &pLength);
                            transcoded = Encoding.ASCII.GetString(
                                (byte *)msgBuffer->pDescription,
                                (int)msgBuffer->DescriptionByteLength
                                );
                        }
                    }
                }
                finally
                {
                    if (rented is object)
                    {
                        ArrayPool <byte> .Shared.Return(rented);
                    }
                }

                // cant really Guard.ThrowIfFailed here because that calls this method
                if (Windows.FAILED(hr))
                {
                    Console.WriteLine(
                        $"if this next bit of text says E_INVALIDARG then this code is messing up. {DebugExtensions.TranslateHr(hr)}. " +
                        "Else you have really messed up and have managed to break the debug message queue");
                }

                Console.WriteLine(transcoded);
            }
        }
Beispiel #3
0
 public static bool IsDeviceRemoved(this ComPtr <ID3D12Device> device) =>
 device.Get()->GetDeviceRemovedReason() != Windows.S_OK;
Beispiel #4
0
 public static void PossibleDeviceDisconnect(this ComPtr <ID3D12Device> device)
 => PossibleDeviceDisconnect(device.Get());