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);
            }
        }
Exemple #2
0
 // _device.ThrowIfFailed calls this to flush messages, so we can't call it
 static void ThrowIfFailed(int hr)
 {
     LogHelper.LogError(
         "if this next bit of text says E_INVALIDARG then this code is messing up. {0}. " +
         "Else you have really messed up and have managed to break the debug message queue", DebugExtensions.TranslateHr(hr));
 }