diff options
author | Chris Robinson <[email protected]> | 2023-04-30 17:46:18 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2023-04-30 17:46:18 -0700 |
commit | 22077687cf4b9fdfd29d78debc2daf044deee81d (patch) | |
tree | fc9aab402ea9e33f7cec2e1ef1dfa98203665578 /alc | |
parent | f2a0df87916de7b9fa8b65a52814c9a09fc6bee9 (diff) |
Implement debug log storage
Diffstat (limited to 'alc')
-rw-r--r-- | alc/alc.cpp | 5 | ||||
-rw-r--r-- | alc/context.cpp | 29 | ||||
-rw-r--r-- | alc/context.h | 19 | ||||
-rw-r--r-- | alc/inprogext.h | 6 |
4 files changed, 58 insertions, 1 deletions
diff --git a/alc/alc.cpp b/alc/alc.cpp index b6dc111d..504737ec 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -463,6 +463,7 @@ const struct { DECL(alDebugMessageCallbackSOFT), DECL(alDebugMessageInsertSOFT), DECL(alDebugMessageControlSOFT), + DECL(alGetDebugMessageLogSOFT), #ifdef ALSOFT_EAX }, eaxFunctions[] = { DECL(EAXGet), @@ -939,6 +940,10 @@ constexpr struct { DECL(AL_DEBUG_SEVERITY_MEDIUM_SOFT), DECL(AL_DEBUG_SEVERITY_LOW_SOFT), DECL(AL_DEBUG_SEVERITY_NOTIFICATION_SOFT), + DECL(AL_DEBUG_LOGGED_MESSAGES_SOFT), + DECL(AL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_SOFT), + DECL(AL_MAX_DEBUG_MESSAGE_LENGTH_SOFT), + DECL(AL_MAX_DEBUG_LOGGED_MESSAGES_SOFT), DECL(AL_STOP_SOURCES_ON_DISCONNECT_SOFT), diff --git a/alc/context.cpp b/alc/context.cpp index 4e5a3ab6..a07e5412 100644 --- a/alc/context.cpp +++ b/alc/context.cpp @@ -15,6 +15,7 @@ #include "AL/efx.h" #include "al/auxeffectslot.h" +#include "al/debug.h" #include "al/source.h" #include "al/effect.h" #include "al/event.h" @@ -342,6 +343,22 @@ void ALCcontext::sendDebugMessage(DebugSource source, DebugType type, ALuint id, throw std::runtime_error{"Unexpected debug severity value "+std::to_string(al::to_underlying(severity))}; }; + if(length < 0) + { + size_t newlen{std::strlen(message)}; + if(newlen > MaxDebugMessageLength) UNLIKELY + { + ERR("Debug message too long (%zu > %d)\n", newlen, MaxDebugMessageLength); + return; + } + length = static_cast<ALsizei>(newlen); + } + else if(length > MaxDebugMessageLength) UNLIKELY + { + ERR("Debug message too long (%d > %d)\n", length, MaxDebugMessageLength); + return; + } + std::unique_lock<std::mutex> debuglock{mDebugCbLock}; if(!mDebugEnabled.load()) UNLIKELY return; @@ -364,7 +381,17 @@ void ALCcontext::sendDebugMessage(DebugSource source, DebugType type, ALuint id, } else { - /* TODO: Store in a log. */ + if(mDebugLog.size() < MaxDebugLoggedMessages) + mDebugLog.emplace_back(source, type, id, severity, message); + else UNLIKELY + ERR("Debug message log overflow. Lost message:\n" + " Source: 0x%04x\n" + " Type: 0x%04x\n" + " ID: %u\n" + " Severity: 0x%04x\n" + " Message: \"%s\"\n", + get_source_enum(source), get_type_enum(type), id, get_severity_enum(severity), + message); } } diff --git a/alc/context.h b/alc/context.h index b5ee440b..031e061e 100644 --- a/alc/context.h +++ b/alc/context.h @@ -2,6 +2,7 @@ #define ALC_CONTEXT_H #include <atomic> +#include <deque> #include <memory> #include <mutex> #include <stdint.h> @@ -66,6 +67,23 @@ enum class DebugSeverity : uint8_t { }; constexpr uint DebugSeverityCount{4}; +struct LogEntry { + const DebugSource mSource; + const DebugType mType; + const DebugSeverity mSeverity; + const uint mId; + + std::string mMessage; + + template<typename T> + LogEntry(DebugSource source, DebugType type, uint id, DebugSeverity severity, T&& message) + : mSource{source}, mType{type}, mSeverity{severity}, mId{id} + , mMessage{std::forward<T>(message)} + { } + LogEntry(const LogEntry&) = default; + LogEntry(LogEntry&&) = default; +}; + struct SourceSubList { uint64_t FreeMask{~0_u64}; @@ -127,6 +145,7 @@ struct ALCcontext : public al::intrusive_ref<ALCcontext>, ContextBase { ALDEBUGPROCSOFT mDebugCb{}; void *mDebugParam{nullptr}; std::vector<uint> mDebugFilters; + std::deque<LogEntry> mDebugLog; ALlistener mListener{}; diff --git a/alc/inprogext.h b/alc/inprogext.h index a4e2c353..f73963cb 100644 --- a/alc/inprogext.h +++ b/alc/inprogext.h @@ -76,15 +76,21 @@ AL_API void AL_APIENTRY alAuxiliaryEffectSlotStopvSOFT(ALsizei n, const ALuint * #define AL_DEBUG_SEVERITY_MEDIUM_SOFT 0x19C2 #define AL_DEBUG_SEVERITY_LOW_SOFT 0x19C3 #define AL_DEBUG_SEVERITY_NOTIFICATION_SOFT 0x19C4 +#define AL_DEBUG_LOGGED_MESSAGES_SOFT 0x19C5 +#define AL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_SOFT 0x19C6 +#define AL_MAX_DEBUG_MESSAGE_LENGTH_SOFT 0x19C7 +#define AL_MAX_DEBUG_LOGGED_MESSAGES_SOFT 0x19C8 typedef void (AL_APIENTRY*ALDEBUGPROCSOFT)(ALenum source, ALenum type, ALuint id, ALenum severity, ALsizei length, const ALchar *message, void *userParam); typedef void (AL_APIENTRY*LPALDEBUGMESSAGECALLBACKSOFT)(ALDEBUGPROCSOFT callback, void *userParam); typedef void (AL_APIENTRY*LPALDEBUGMESSAGEINSERTSOFT)(ALenum source, ALenum type, ALuint id, ALenum severity, ALsizei length, const ALchar *message); typedef void (AL_APIENTRY*LPALDEBUGMESSAGECONTROLSOFT)(ALenum source, ALenum type, ALenum severity, ALsizei count, const ALuint *ids, ALboolean enable); +typedef ALuint (AL_APIENTRY*LPALGETDEBUGMESSAGELOGSOFT)(ALuint count, ALsizei logBufSize, ALenum *sources, ALenum *types, ALuint *ids, ALenum *severities, ALsizei *lengths, ALchar *logBuf); #ifdef AL_ALEXT_PROTOTYPES void AL_APIENTRY alDebugMessageCallbackSOFT(ALDEBUGPROCSOFT callback, void *userParam) noexcept; void AL_APIENTRY alDebugMessageInsertSOFT(ALenum source, ALenum type, ALuint id, ALenum severity, ALsizei length, const ALchar *message) noexcept; void AL_APIENTRY alDebugMessageControlSOFT(ALenum source, ALenum type, ALenum severity, ALsizei count, const ALuint *ids, ALboolean enable) noexcept; +ALuint AL_APIENTRY alGetDebugMessageLogSOFT(ALuint count, ALsizei logBufSize, ALenum *sources, ALenum *types, ALuint *ids, ALenum *severities, ALsizei *lengths, ALchar *logBuf) noexcept; #endif #endif |