From 102789d4487a8dbbb13a131dde3d21a612e86adb Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 28 Apr 2023 22:28:32 -0700 Subject: Unset sLocalContext when releasing it --- alc/context.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'alc/context.cpp') diff --git a/alc/context.cpp b/alc/context.cpp index e02c549b..008c2bf4 100644 --- a/alc/context.cpp +++ b/alc/context.cpp @@ -93,7 +93,7 @@ std::atomic ALCcontext::sGlobalContext{nullptr}; thread_local ALCcontext *ALCcontext::sLocalContext{nullptr}; ALCcontext::ThreadCtx::~ThreadCtx() { - if(ALCcontext *ctx{ALCcontext::sLocalContext}) + if(ALCcontext *ctx{std::exchange(ALCcontext::sLocalContext, nullptr)}) { const bool result{ctx->releaseIfNoDelete()}; ERR("Context %p current for thread being destroyed%s!\n", voidp{ctx}, -- cgit v1.2.3 From a35211e2c1dc53e47c4a300366d22a27fb046a8c Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 29 Apr 2023 19:18:06 -0700 Subject: Start a debug API extension --- al/error.cpp | 11 ++++++-- al/state.cpp | 38 +++++++++++++++++++++++++--- alc/alc.cpp | 4 +++ alc/context.cpp | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- alc/context.h | 41 ++++++++++++++++++++++++++++++ alc/inprogext.h | 31 +++++++++++++++++++++++ 6 files changed, 196 insertions(+), 7 deletions(-) (limited to 'alc/context.cpp') diff --git a/al/error.cpp b/al/error.cpp index afa7019a..70081a2e 100644 --- a/al/error.cpp +++ b/al/error.cpp @@ -61,8 +61,13 @@ void ALCcontext::setError(ALenum errorCode, const char *msg, ...) va_end(args2); va_end(args); - if(msglen >= 0) msg = message.data(); - else msg = ""; + if(msglen >= 0) + msg = message.data(); + else + { + msg = ""; + msglen = static_cast(strlen(msg)); + } WARN("Error generated on context %p, code 0x%04x, \"%s\"\n", decltype(std::declval()){this}, errorCode, msg); @@ -79,6 +84,8 @@ void ALCcontext::setError(ALenum errorCode, const char *msg, ...) ALenum curerr{AL_NO_ERROR}; mLastError.compare_exchange_strong(curerr, errorCode); + + debugMessage(DebugSource::API, DebugType::Error, 0, DebugSeverity::High, msglen, msg); } AL_API ALenum AL_APIENTRY alGetError(void) diff --git a/al/state.cpp b/al/state.cpp index 86d81b13..fc9acb25 100644 --- a/al/state.cpp +++ b/al/state.cpp @@ -170,6 +170,10 @@ START_API_FUNC } break; + case AL_DEBUG_OUTPUT_SOFT: + context->mDebugEnabled = true; + break; + case AL_STOP_SOURCES_ON_DISCONNECT_SOFT: context->setError(AL_INVALID_OPERATION, "Re-enabling AL_STOP_SOURCES_ON_DISCONNECT_SOFT not yet supported"); break; @@ -196,6 +200,10 @@ START_API_FUNC } break; + case AL_DEBUG_OUTPUT_SOFT: + context->mDebugEnabled = false; + break; + case AL_STOP_SOURCES_ON_DISCONNECT_SOFT: context->mStopVoicesOnDisconnect = false; break; @@ -220,6 +228,10 @@ START_API_FUNC value = context->mSourceDistanceModel ? AL_TRUE : AL_FALSE; break; + case AL_DEBUG_OUTPUT_SOFT: + value = context->mDebugEnabled ? AL_TRUE : AL_FALSE; + break; + case AL_STOP_SOURCES_ON_DISCONNECT_SOFT: value = context->mStopVoicesOnDisconnect ? AL_TRUE : AL_FALSE; break; @@ -546,6 +558,14 @@ START_API_FUNC value = context->mEventParam; break; + case AL_DEBUG_CALLBACK_FUNCTION_SOFT: + value = reinterpret_cast(context->mDebugCb); + break; + + case AL_DEBUG_CALLBACK_USER_PARAM_SOFT: + value = context->mDebugParam; + break; + default: context->setError(AL_INVALID_VALUE, "Invalid pointer property 0x%04x", pname); } @@ -726,10 +746,12 @@ START_API_FUNC { switch(pname) { - case AL_EVENT_CALLBACK_FUNCTION_SOFT: - case AL_EVENT_CALLBACK_USER_PARAM_SOFT: - values[0] = alGetPointerSOFT(pname); - return; + case AL_EVENT_CALLBACK_FUNCTION_SOFT: + case AL_EVENT_CALLBACK_USER_PARAM_SOFT: + case AL_DEBUG_CALLBACK_FUNCTION_SOFT: + case AL_DEBUG_CALLBACK_USER_PARAM_SOFT: + values[0] = alGetPointerSOFT(pname); + return; } } @@ -825,6 +847,14 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(!context) UNLIKELY return; + if(context->mDebugEnabled.load(std::memory_order_relaxed)) + { + static constexpr char deprecatedMessage[] = "alDopplerVelocity is deprecated in AL 1.1"; + context->sendDebugMessage(DebugSource::API, DebugType::DeprecatedBehavior, 0, + DebugSeverity::Medium, static_cast(std::strlen(deprecatedMessage)), + deprecatedMessage); + } + if(!(value >= 0.0f && std::isfinite(value))) context->setError(AL_INVALID_VALUE, "Doppler velocity %f out of range", value); else diff --git a/alc/alc.cpp b/alc/alc.cpp index af8ff55d..0ed0ae58 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -459,6 +459,8 @@ const struct { DECL(alBufferSubDataSOFT), DECL(alBufferDataStatic), + + DECL(alDebugMessageCallbackSOFT), #ifdef ALSOFT_EAX }, eaxFunctions[] = { DECL(EAXGet), @@ -915,6 +917,8 @@ constexpr struct { DECL(AL_FORMAT_UHJ4CHN_MULAW_SOFT), DECL(AL_FORMAT_UHJ4CHN_ALAW_SOFT), + DECL(AL_DEBUG_OUTPUT_SOFT), + DECL(AL_STOP_SOURCES_ON_DISCONNECT_SOFT), #ifdef ALSOFT_EAX diff --git a/alc/context.cpp b/alc/context.cpp index 008c2bf4..e2a2e2d2 100644 --- a/alc/context.cpp +++ b/alc/context.cpp @@ -113,7 +113,7 @@ void ALCcontext::setThreadContext(ALCcontext *context) noexcept #endif ALCcontext::ALCcontext(al::intrusive_ptr device) - : ContextBase{device.get()}, mALDevice{std::move(device)} + : ContextBase{device.get()}, mALDevice{std::move(device)} { } @@ -295,6 +295,82 @@ void ALCcontext::applyAllUpdates() mHoldUpdates.store(false, std::memory_order_release); } +void ALCcontext::sendDebugMessage(DebugSource source, DebugType type, ALuint id, + DebugSeverity severity, ALsizei length, const char *message) +{ + std::lock_guard _{mDebugCbLock}; + if(!mDebugEnabled.load()) + return; + + if(mDebugCb) + mDebugCb(al::to_underlying(source), al::to_underlying(type), id, + al::to_underlying(severity), length, message, mDebugParam); + else + { + /* TODO: Store in a log. */ + } +} + +FORCE_ALIGN void AL_APIENTRY alDebugMessageCallbackSOFT(ALDEBUGPROCSOFT callback, void *userParam) noexcept +{ + ContextRef context{GetContextRef()}; + if(!context) UNLIKELY return; + + std::lock_guard _{context->mDebugCbLock}; + context->mDebugCb = callback; + context->mDebugParam = userParam; +} + +FORCE_ALIGN void AL_APIENTRY alDebugMessageInsertSOFT(ALenum source, ALenum type, ALuint id, + ALenum severity, ALsizei length, const ALchar *message) noexcept +{ + ContextRef context{GetContextRef()}; + if(!context) UNLIKELY return; + + if(!message) + return context->setError(AL_INVALID_VALUE, "Null message pointer"); + + DebugSource dsource{}; + switch(source) + { + case AL_DEBUG_SOURCE_THIRD_PARTY_SOFT: dsource = DebugSource::ThirdParty; break; + case AL_DEBUG_SOURCE_APPLICATION_SOFT: dsource = DebugSource::Application; break; + case AL_DEBUG_SOURCE_API_SOFT: + case AL_DEBUG_SOURCE_AUDIO_SYSTEM_SOFT: + case AL_DEBUG_SOURCE_OTHER_SOFT: + return context->setError(AL_INVALID_ENUM, "Debug source enum 0x%04x not allowed", source); + default: + return context->setError(AL_INVALID_ENUM, "Invalid debug source enum 0x%04x", source); + } + + DebugType dtype{}; + switch(type) + { + case AL_DEBUG_TYPE_ERROR_SOFT: dtype = DebugType::Error; break; + case AL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_SOFT: dtype = DebugType::DeprecatedBehavior; break; + case AL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_SOFT: dtype = DebugType::UndefinedBehavior; break; + case AL_DEBUG_TYPE_PORTABILITY_SOFT: dtype = DebugType::Portability; break; + case AL_DEBUG_TYPE_PERFORMANCE_SOFT: dtype = DebugType::Performance; break; + case AL_DEBUG_TYPE_MARKER_SOFT: dtype = DebugType::Marker; break; + case AL_DEBUG_TYPE_OTHER_SOFT: dtype = DebugType::Other; break; + default: + return context->setError(AL_INVALID_ENUM, "Invalid debug type 0x%04x", type); + } + + DebugSeverity dseverity{}; + switch(severity) + { + case AL_DEBUG_SEVERITY_HIGH_SOFT: dseverity = DebugSeverity::High; break; + case AL_DEBUG_SEVERITY_MEDIUM_SOFT: dseverity = DebugSeverity::Medium; break; + case AL_DEBUG_SEVERITY_LOW_SOFT: dseverity = DebugSeverity::Low; break; + case AL_DEBUG_SEVERITY_NOTIFICATION_SOFT: dseverity = DebugSeverity::Notification; break; + default: + return context->setError(AL_INVALID_ENUM, "Invalid debug severity 0x%04x", severity); + } + + context->debugMessage(dsource, dtype, id, dseverity, length, message); +} + #ifdef ALSOFT_EAX namespace { diff --git a/alc/context.h b/alc/context.h index e8efdbf1..697ecfe9 100644 --- a/alc/context.h +++ b/alc/context.h @@ -34,6 +34,30 @@ struct ALsource; using uint = unsigned int; +enum class DebugSource : ALenum { + API = AL_DEBUG_SOURCE_API_SOFT, + System = AL_DEBUG_SOURCE_AUDIO_SYSTEM_SOFT, + ThirdParty = AL_DEBUG_SOURCE_THIRD_PARTY_SOFT, + Application = AL_DEBUG_SOURCE_APPLICATION_SOFT, + Other = AL_DEBUG_SOURCE_OTHER_SOFT, +}; +enum class DebugType : ALenum { + Error = AL_DEBUG_TYPE_ERROR_SOFT, + DeprecatedBehavior = AL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_SOFT, + UndefinedBehavior = AL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_SOFT, + Portability = AL_DEBUG_TYPE_PORTABILITY_SOFT, + Performance = AL_DEBUG_TYPE_PERFORMANCE_SOFT, + Marker = AL_DEBUG_TYPE_MARKER_SOFT, + Other = AL_DEBUG_TYPE_OTHER_SOFT, +}; +enum class DebugSeverity : ALenum { + High = AL_DEBUG_SEVERITY_HIGH_SOFT, + Medium = AL_DEBUG_SEVERITY_MEDIUM_SOFT, + Low = AL_DEBUG_SEVERITY_LOW_SOFT, + Notification = AL_DEBUG_SEVERITY_NOTIFICATION_SOFT, +}; + + struct SourceSubList { uint64_t FreeMask{~0_u64}; ALsource *Sources{nullptr}; /* 64 */ @@ -76,6 +100,8 @@ struct ALCcontext : public al::intrusive_ref, ContextBase { std::atomic mLastError{AL_NO_ERROR}; + std::atomic mDebugEnabled{false}; + DistanceModel mDistanceModel{DistanceModel::Default}; bool mSourceDistanceModel{false}; @@ -88,6 +114,10 @@ struct ALCcontext : public al::intrusive_ref, ContextBase { ALEVENTPROCSOFT mEventCb{}; void *mEventParam{nullptr}; + std::mutex mDebugCbLock; + ALDEBUGPROCSOFT mDebugCb{}; + void *mDebugParam{nullptr}; + ALlistener mListener{}; al::vector mSourceList; @@ -149,6 +179,17 @@ struct ALCcontext : public al::intrusive_ref, ContextBase { #endif void setError(ALenum errorCode, const char *msg, ...); + void sendDebugMessage(DebugSource source, DebugType type, ALuint id, DebugSeverity severity, + ALsizei length, const char *message); + + void debugMessage(DebugSource source, DebugType type, ALuint id, DebugSeverity severity, + ALsizei length, const char *message) + { + if(!mDebugEnabled.load(std::memory_order_relaxed)) LIKELY + return; + sendDebugMessage(source, type, id, severity, length, message); + } + /* Process-wide current context */ static std::atomic sGlobalContextLock; static std::atomic sGlobalContext; diff --git a/alc/inprogext.h b/alc/inprogext.h index ccb9a4be..53dc9f0c 100644 --- a/alc/inprogext.h +++ b/alc/inprogext.h @@ -54,6 +54,37 @@ AL_API void AL_APIENTRY alAuxiliaryEffectSlotStopvSOFT(ALsizei n, const ALuint * #define AL_STOP_SOURCES_ON_DISCONNECT_SOFT 0x19AB #endif +#ifndef AL_SOFT_debug +#define AL_SOFT_debug +#define AL_DEBUG_OUTPUT_SOFT 0x19B2 +#define AL_DEBUG_CALLBACK_FUNCTION_SOFT 0x19B3 +#define AL_DEBUG_CALLBACK_USER_PARAM_SOFT 0x19B4 +#define AL_DEBUG_SOURCE_API_SOFT 0x19B5 +#define AL_DEBUG_SOURCE_AUDIO_SYSTEM_SOFT 0x19B6 +#define AL_DEBUG_SOURCE_THIRD_PARTY_SOFT 0x19B7 +#define AL_DEBUG_SOURCE_APPLICATION_SOFT 0x19B8 +#define AL_DEBUG_SOURCE_OTHER_SOFT 0x19B9 +#define AL_DEBUG_TYPE_ERROR_SOFT 0x19BA +#define AL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_SOFT 0x19BB +#define AL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_SOFT 0x19BC +#define AL_DEBUG_TYPE_PORTABILITY_SOFT 0x19BD +#define AL_DEBUG_TYPE_PERFORMANCE_SOFT 0x19BE +#define AL_DEBUG_TYPE_MARKER_SOFT 0x19BF +#define AL_DEBUG_TYPE_OTHER_SOFT 0x19C0 +#define AL_DEBUG_SEVERITY_HIGH_SOFT 0x19C1 +#define AL_DEBUG_SEVERITY_MEDIUM_SOFT 0x19C2 +#define AL_DEBUG_SEVERITY_LOW_SOFT 0x19C3 +#define AL_DEBUG_SEVERITY_NOTIFICATION_SOFT 0x19C4 + +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); +#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; +#endif +#endif + /* Non-standard export. Not part of any extension. */ AL_API const ALchar* AL_APIENTRY alsoft_get_version(void); -- cgit v1.2.3 From d7e22a8ada669910882ae34e0b57da6712629e72 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 30 Apr 2023 03:13:37 -0700 Subject: Implement non-ID based debug message filtering --- alc/alc.cpp | 21 ++++++++ alc/context.cpp | 147 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- alc/context.h | 9 ++++ alc/inprogext.h | 3 ++ 4 files changed, 179 insertions(+), 1 deletion(-) (limited to 'alc/context.cpp') diff --git a/alc/alc.cpp b/alc/alc.cpp index 33531afb..b6dc111d 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -461,6 +461,8 @@ const struct { DECL(alBufferDataStatic), DECL(alDebugMessageCallbackSOFT), + DECL(alDebugMessageInsertSOFT), + DECL(alDebugMessageControlSOFT), #ifdef ALSOFT_EAX }, eaxFunctions[] = { DECL(EAXGet), @@ -917,7 +919,26 @@ constexpr struct { DECL(AL_FORMAT_UHJ4CHN_MULAW_SOFT), DECL(AL_FORMAT_UHJ4CHN_ALAW_SOFT), + DECL(AL_DONT_CARE_SOFT), DECL(AL_DEBUG_OUTPUT_SOFT), + DECL(AL_DEBUG_CALLBACK_FUNCTION_SOFT), + DECL(AL_DEBUG_CALLBACK_USER_PARAM_SOFT), + DECL(AL_DEBUG_SOURCE_API_SOFT), + DECL(AL_DEBUG_SOURCE_AUDIO_SYSTEM_SOFT), + DECL(AL_DEBUG_SOURCE_THIRD_PARTY_SOFT), + DECL(AL_DEBUG_SOURCE_APPLICATION_SOFT), + DECL(AL_DEBUG_SOURCE_OTHER_SOFT), + DECL(AL_DEBUG_TYPE_ERROR_SOFT), + DECL(AL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_SOFT), + DECL(AL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_SOFT), + DECL(AL_DEBUG_TYPE_PORTABILITY_SOFT), + DECL(AL_DEBUG_TYPE_PERFORMANCE_SOFT), + DECL(AL_DEBUG_TYPE_MARKER_SOFT), + DECL(AL_DEBUG_TYPE_OTHER_SOFT), + DECL(AL_DEBUG_SEVERITY_HIGH_SOFT), + DECL(AL_DEBUG_SEVERITY_MEDIUM_SOFT), + DECL(AL_DEBUG_SEVERITY_LOW_SOFT), + DECL(AL_DEBUG_SEVERITY_NOTIFICATION_SOFT), DECL(AL_STOP_SOURCES_ON_DISCONNECT_SOFT), diff --git a/alc/context.cpp b/alc/context.cpp index e2a2e2d2..3f7b456d 100644 --- a/alc/context.cpp +++ b/alc/context.cpp @@ -4,11 +4,13 @@ #include "context.h" #include +#include #include #include #include #include #include +#include #include "AL/efx.h" @@ -19,6 +21,7 @@ #include "al/listener.h" #include "albit.h" #include "alc/alu.h" +#include "alspan.h" #include "core/async_event.h" #include "core/device.h" #include "core/effectslot.h" @@ -27,6 +30,7 @@ #include "core/voice_change.h" #include "device.h" #include "ringbuffer.h" +#include "threads.h" #include "vecmat.h" #ifdef ALSOFT_EAX @@ -295,11 +299,45 @@ void ALCcontext::applyAllUpdates() mHoldUpdates.store(false, std::memory_order_release); } + void ALCcontext::sendDebugMessage(DebugSource source, DebugType type, ALuint id, DebugSeverity severity, ALsizei length, const char *message) { + static_assert(DebugSeverityBase+DebugSeverityCount <= 32, "Too many debug bits"); + std::lock_guard _{mDebugCbLock}; - if(!mDebugEnabled.load()) + if(!mDebugEnabled.load()) UNLIKELY + return; + + uint filter{0}; + switch(source) + { + case DebugSource::API: filter |= 1<<(DebugSourceBase+0); break; + case DebugSource::System: filter |= 1<<(DebugSourceBase+1); break; + case DebugSource::ThirdParty: filter |= 1<<(DebugSourceBase+2); break; + case DebugSource::Application: filter |= 1<<(DebugSourceBase+3); break; + case DebugSource::Other: filter |= 1<<(DebugSourceBase+4); break; + } + switch(type) + { + case DebugType::Error: filter |= 1<<(DebugTypeBase+0); break; + case DebugType::DeprecatedBehavior: filter |= 1<<(DebugTypeBase+1); break; + case DebugType::UndefinedBehavior: filter |= 1<<(DebugTypeBase+2); break; + case DebugType::Portability: filter |= 1<<(DebugTypeBase+3); break; + case DebugType::Performance: filter |= 1<<(DebugTypeBase+4); break; + case DebugType::Marker: filter |= 1<<(DebugTypeBase+5); break; + case DebugType::Other: filter |= 1<<(DebugTypeBase+6); break; + } + switch(severity) + { + case DebugSeverity::High: filter |= 1<<(DebugSeverityBase+0); break; + case DebugSeverity::Medium: filter |= 1<<(DebugSeverityBase+1); break; + case DebugSeverity::Low: filter |= 1<<(DebugSeverityBase+2); break; + case DebugSeverity::Notification: filter |= 1<<(DebugSeverityBase+3); break; + } + + auto iter = std::lower_bound(mDebugFilters.cbegin(), mDebugFilters.cend(), filter); + if(iter != mDebugFilters.cend() && *iter == filter) return; if(mDebugCb) @@ -371,6 +409,113 @@ FORCE_ALIGN void AL_APIENTRY alDebugMessageInsertSOFT(ALenum source, ALenum type context->debugMessage(dsource, dtype, id, dseverity, length, message); } + +namespace { + +template +constexpr auto make_array(std::integer_sequence) +{ return std::array{Vals...}; } + +template> +constexpr auto make_array() +{ return make_array(Indices{}); } + +} // namespace + +FORCE_ALIGN void AL_APIENTRY alDebugMessageControlSOFT(ALenum source, ALenum type, ALenum severity, + ALsizei count, const ALuint *ids, ALboolean enable) noexcept +{ + ContextRef context{GetContextRef()}; + if(!context) UNLIKELY return; + + if(count > 0) + { + if(!ids) + return context->setError(AL_INVALID_VALUE, "IDs is null with non-0 count"); + if(source == AL_DONT_CARE_SOFT) + return context->setError(AL_INVALID_VALUE, + "Debug source cannot be AL_DONT_CARE_SOFT with IDs"); + if(type == AL_DONT_CARE_SOFT) + return context->setError(AL_INVALID_VALUE, + "Debug type cannot be AL_DONT_CARE_SOFT with IDs"); + if(severity != AL_DONT_CARE_SOFT) + return context->setError(AL_INVALID_VALUE, + "Debug severity must be AL_DONT_CARE_SOFT with IDs"); + + return context->setError(AL_INVALID_VALUE, "Debug ID filtering not supported"); + return; + } + + if(enable != AL_TRUE && enable != AL_FALSE) + return context->setError(AL_INVALID_VALUE, "Invalid debug enable %d", enable); + + static constexpr size_t ElemCount{DebugSourceCount + DebugTypeCount + DebugSeverityCount}; + static constexpr auto Values = make_array(); + + al::span srcIndices{al::as_span(Values).subspan()}; + switch(source) + { + case AL_DEBUG_SOURCE_API_SOFT: srcIndices = srcIndices.subspan(0, 1); break; + case AL_DEBUG_SOURCE_AUDIO_SYSTEM_SOFT: srcIndices = srcIndices.subspan(1, 1); break; + case AL_DEBUG_SOURCE_THIRD_PARTY_SOFT: srcIndices = srcIndices.subspan(2, 1); break; + case AL_DEBUG_SOURCE_APPLICATION_SOFT: srcIndices = srcIndices.subspan(3, 1); break; + case AL_DEBUG_SOURCE_OTHER_SOFT: srcIndices = srcIndices.subspan(4, 1); break; + case AL_DONT_CARE_SOFT: break; + default: + return context->setError(AL_INVALID_VALUE, "Invalid debug source 0x%04x", source); + } + + al::span typeIndices{al::as_span(Values).subspan()}; + switch(type) + { + case AL_DEBUG_TYPE_ERROR_SOFT: typeIndices = typeIndices.subspan(0, 1); break; + case AL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_SOFT: typeIndices = typeIndices.subspan(1, 1); break; + case AL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_SOFT: typeIndices = typeIndices.subspan(2, 1); break; + case AL_DEBUG_TYPE_PORTABILITY_SOFT: typeIndices = typeIndices.subspan(3, 1); break; + case AL_DEBUG_TYPE_PERFORMANCE_SOFT: typeIndices = typeIndices.subspan(4, 1); break; + case AL_DEBUG_TYPE_MARKER_SOFT: typeIndices = typeIndices.subspan(5, 1); break; + case AL_DEBUG_TYPE_OTHER_SOFT: typeIndices = typeIndices.subspan(6, 1); break; + case AL_DONT_CARE_SOFT: break; + default: + return context->setError(AL_INVALID_VALUE, "Invalid debug type 0x%04x", type); + } + + al::span svrIndices{al::as_span(Values).subspan()}; + switch(severity) + { + case AL_DEBUG_SEVERITY_HIGH_SOFT: svrIndices = svrIndices.subspan(0, 1); break; + case AL_DEBUG_SEVERITY_MEDIUM_SOFT: svrIndices = svrIndices.subspan(1, 1); break; + case AL_DEBUG_SEVERITY_LOW_SOFT: svrIndices = svrIndices.subspan(2, 1); break; + case AL_DEBUG_SEVERITY_NOTIFICATION_SOFT: svrIndices = svrIndices.subspan(3, 1); break; + case AL_DONT_CARE_SOFT: break; + default: + return context->setError(AL_INVALID_VALUE, "Invalid debug severity 0x%04x", severity); + } + + std::lock_guard _{context->mDebugCbLock}; + auto apply_filter = [enable,&context](const uint filter) + { + auto iter = std::lower_bound(context->mDebugFilters.cbegin(), + context->mDebugFilters.cend(), filter); + if(enable && (iter == context->mDebugFilters.cend() || *iter != filter)) + context->mDebugFilters.insert(iter, filter); + else if(!enable && iter != context->mDebugFilters.cend() && *iter == filter) + context->mDebugFilters.erase(iter); + }; + auto apply_severity = [apply_filter,svrIndices](const uint filter) + { + std::for_each(svrIndices.cbegin(), svrIndices.cend(), + [apply_filter,filter](const uint idx){ apply_filter(filter | (1<, ContextBase { std::mutex mDebugCbLock; ALDEBUGPROCSOFT mDebugCb{}; void *mDebugParam{nullptr}; + std::vector mDebugFilters; ALlistener mListener{}; diff --git a/alc/inprogext.h b/alc/inprogext.h index 53dc9f0c..a4e2c353 100644 --- a/alc/inprogext.h +++ b/alc/inprogext.h @@ -56,6 +56,7 @@ AL_API void AL_APIENTRY alAuxiliaryEffectSlotStopvSOFT(ALsizei n, const ALuint * #ifndef AL_SOFT_debug #define AL_SOFT_debug +#define AL_DONT_CARE_SOFT 0x0002 #define AL_DEBUG_OUTPUT_SOFT 0x19B2 #define AL_DEBUG_CALLBACK_FUNCTION_SOFT 0x19B3 #define AL_DEBUG_CALLBACK_USER_PARAM_SOFT 0x19B4 @@ -79,9 +80,11 @@ AL_API void AL_APIENTRY alAuxiliaryEffectSlotStopvSOFT(ALsizei n, const ALuint * 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); #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; #endif #endif -- cgit v1.2.3 From 755429798a1dbe658d2a4d342927c9b9272629ee Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 30 Apr 2023 03:24:20 -0700 Subject: Move debug functions to their own source --- CMakeLists.txt | 2 + al/debug.cpp | 186 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ al/debug.h | 4 ++ alc/context.cpp | 166 -------------------------------------------------- 4 files changed, 192 insertions(+), 166 deletions(-) create mode 100644 al/debug.cpp create mode 100644 al/debug.h (limited to 'alc/context.cpp') diff --git a/CMakeLists.txt b/CMakeLists.txt index 55644b04..eec2d58f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -742,6 +742,8 @@ set(OPENAL_OBJS al/auxeffectslot.h al/buffer.cpp al/buffer.h + al/debug.cpp + al/debug.h al/effect.cpp al/effect.h al/effects/autowah.cpp diff --git a/al/debug.cpp b/al/debug.cpp new file mode 100644 index 00000000..975443c7 --- /dev/null +++ b/al/debug.cpp @@ -0,0 +1,186 @@ +#include "config.h" + +#include "debug.h" + +#include +#include +#include +#include +#include + +#include "AL/al.h" + +#include "alc/context.h" +#include "alc/inprogext.h" +#include "alspan.h" +#include "opthelpers.h" +#include "threads.h" + + +namespace { + +template +constexpr auto make_array(std::integer_sequence) +{ return std::array{Vals...}; } + +template> +constexpr auto make_array() +{ return make_array(Indices{}); } + +} // namespace + + +FORCE_ALIGN void AL_APIENTRY alDebugMessageCallbackSOFT(ALDEBUGPROCSOFT callback, void *userParam) noexcept +{ + ContextRef context{GetContextRef()}; + if(!context) UNLIKELY return; + + std::lock_guard _{context->mDebugCbLock}; + context->mDebugCb = callback; + context->mDebugParam = userParam; +} + +FORCE_ALIGN void AL_APIENTRY alDebugMessageInsertSOFT(ALenum source, ALenum type, ALuint id, + ALenum severity, ALsizei length, const ALchar *message) noexcept +{ + ContextRef context{GetContextRef()}; + if(!context) UNLIKELY return; + + if(!message) + return context->setError(AL_INVALID_VALUE, "Null message pointer"); + + DebugSource dsource{}; + switch(source) + { + case AL_DEBUG_SOURCE_THIRD_PARTY_SOFT: dsource = DebugSource::ThirdParty; break; + case AL_DEBUG_SOURCE_APPLICATION_SOFT: dsource = DebugSource::Application; break; + case AL_DEBUG_SOURCE_API_SOFT: + case AL_DEBUG_SOURCE_AUDIO_SYSTEM_SOFT: + case AL_DEBUG_SOURCE_OTHER_SOFT: + return context->setError(AL_INVALID_ENUM, "Debug source enum 0x%04x not allowed", source); + default: + return context->setError(AL_INVALID_ENUM, "Invalid debug source enum 0x%04x", source); + } + + DebugType dtype{}; + switch(type) + { + case AL_DEBUG_TYPE_ERROR_SOFT: dtype = DebugType::Error; break; + case AL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_SOFT: dtype = DebugType::DeprecatedBehavior; break; + case AL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_SOFT: dtype = DebugType::UndefinedBehavior; break; + case AL_DEBUG_TYPE_PORTABILITY_SOFT: dtype = DebugType::Portability; break; + case AL_DEBUG_TYPE_PERFORMANCE_SOFT: dtype = DebugType::Performance; break; + case AL_DEBUG_TYPE_MARKER_SOFT: dtype = DebugType::Marker; break; + case AL_DEBUG_TYPE_OTHER_SOFT: dtype = DebugType::Other; break; + default: + return context->setError(AL_INVALID_ENUM, "Invalid debug type 0x%04x", type); + } + + DebugSeverity dseverity{}; + switch(severity) + { + case AL_DEBUG_SEVERITY_HIGH_SOFT: dseverity = DebugSeverity::High; break; + case AL_DEBUG_SEVERITY_MEDIUM_SOFT: dseverity = DebugSeverity::Medium; break; + case AL_DEBUG_SEVERITY_LOW_SOFT: dseverity = DebugSeverity::Low; break; + case AL_DEBUG_SEVERITY_NOTIFICATION_SOFT: dseverity = DebugSeverity::Notification; break; + default: + return context->setError(AL_INVALID_ENUM, "Invalid debug severity 0x%04x", severity); + } + + context->debugMessage(dsource, dtype, id, dseverity, length, message); +} + + +FORCE_ALIGN void AL_APIENTRY alDebugMessageControlSOFT(ALenum source, ALenum type, ALenum severity, + ALsizei count, const ALuint *ids, ALboolean enable) noexcept +{ + ContextRef context{GetContextRef()}; + if(!context) UNLIKELY return; + + if(count > 0) + { + if(!ids) + return context->setError(AL_INVALID_VALUE, "IDs is null with non-0 count"); + if(source == AL_DONT_CARE_SOFT) + return context->setError(AL_INVALID_VALUE, + "Debug source cannot be AL_DONT_CARE_SOFT with IDs"); + if(type == AL_DONT_CARE_SOFT) + return context->setError(AL_INVALID_VALUE, + "Debug type cannot be AL_DONT_CARE_SOFT with IDs"); + if(severity != AL_DONT_CARE_SOFT) + return context->setError(AL_INVALID_VALUE, + "Debug severity must be AL_DONT_CARE_SOFT with IDs"); + + return context->setError(AL_INVALID_VALUE, "Debug ID filtering not supported"); + return; + } + + if(enable != AL_TRUE && enable != AL_FALSE) + return context->setError(AL_INVALID_VALUE, "Invalid debug enable %d", enable); + + static constexpr size_t ElemCount{DebugSourceCount + DebugTypeCount + DebugSeverityCount}; + static constexpr auto Values = make_array(); + + al::span srcIndices{al::as_span(Values).subspan()}; + switch(source) + { + case AL_DEBUG_SOURCE_API_SOFT: srcIndices = srcIndices.subspan(0, 1); break; + case AL_DEBUG_SOURCE_AUDIO_SYSTEM_SOFT: srcIndices = srcIndices.subspan(1, 1); break; + case AL_DEBUG_SOURCE_THIRD_PARTY_SOFT: srcIndices = srcIndices.subspan(2, 1); break; + case AL_DEBUG_SOURCE_APPLICATION_SOFT: srcIndices = srcIndices.subspan(3, 1); break; + case AL_DEBUG_SOURCE_OTHER_SOFT: srcIndices = srcIndices.subspan(4, 1); break; + case AL_DONT_CARE_SOFT: break; + default: + return context->setError(AL_INVALID_VALUE, "Invalid debug source 0x%04x", source); + } + + al::span typeIndices{al::as_span(Values).subspan()}; + switch(type) + { + case AL_DEBUG_TYPE_ERROR_SOFT: typeIndices = typeIndices.subspan(0, 1); break; + case AL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_SOFT: typeIndices = typeIndices.subspan(1, 1); break; + case AL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_SOFT: typeIndices = typeIndices.subspan(2, 1); break; + case AL_DEBUG_TYPE_PORTABILITY_SOFT: typeIndices = typeIndices.subspan(3, 1); break; + case AL_DEBUG_TYPE_PERFORMANCE_SOFT: typeIndices = typeIndices.subspan(4, 1); break; + case AL_DEBUG_TYPE_MARKER_SOFT: typeIndices = typeIndices.subspan(5, 1); break; + case AL_DEBUG_TYPE_OTHER_SOFT: typeIndices = typeIndices.subspan(6, 1); break; + case AL_DONT_CARE_SOFT: break; + default: + return context->setError(AL_INVALID_VALUE, "Invalid debug type 0x%04x", type); + } + + al::span svrIndices{al::as_span(Values).subspan()}; + switch(severity) + { + case AL_DEBUG_SEVERITY_HIGH_SOFT: svrIndices = svrIndices.subspan(0, 1); break; + case AL_DEBUG_SEVERITY_MEDIUM_SOFT: svrIndices = svrIndices.subspan(1, 1); break; + case AL_DEBUG_SEVERITY_LOW_SOFT: svrIndices = svrIndices.subspan(2, 1); break; + case AL_DEBUG_SEVERITY_NOTIFICATION_SOFT: svrIndices = svrIndices.subspan(3, 1); break; + case AL_DONT_CARE_SOFT: break; + default: + return context->setError(AL_INVALID_VALUE, "Invalid debug severity 0x%04x", severity); + } + + std::lock_guard _{context->mDebugCbLock}; + auto apply_filter = [enable,&context](const uint filter) + { + auto iter = std::lower_bound(context->mDebugFilters.cbegin(), + context->mDebugFilters.cend(), filter); + if(enable && (iter == context->mDebugFilters.cend() || *iter != filter)) + context->mDebugFilters.insert(iter, filter); + else if(!enable && iter != context->mDebugFilters.cend() && *iter == filter) + context->mDebugFilters.erase(iter); + }; + auto apply_severity = [apply_filter,svrIndices](const uint filter) + { + std::for_each(svrIndices.cbegin(), svrIndices.cend(), + [apply_filter,filter](const uint idx){ apply_filter(filter | (1< _{context->mDebugCbLock}; - context->mDebugCb = callback; - context->mDebugParam = userParam; -} - -FORCE_ALIGN void AL_APIENTRY alDebugMessageInsertSOFT(ALenum source, ALenum type, ALuint id, - ALenum severity, ALsizei length, const ALchar *message) noexcept -{ - ContextRef context{GetContextRef()}; - if(!context) UNLIKELY return; - - if(!message) - return context->setError(AL_INVALID_VALUE, "Null message pointer"); - - DebugSource dsource{}; - switch(source) - { - case AL_DEBUG_SOURCE_THIRD_PARTY_SOFT: dsource = DebugSource::ThirdParty; break; - case AL_DEBUG_SOURCE_APPLICATION_SOFT: dsource = DebugSource::Application; break; - case AL_DEBUG_SOURCE_API_SOFT: - case AL_DEBUG_SOURCE_AUDIO_SYSTEM_SOFT: - case AL_DEBUG_SOURCE_OTHER_SOFT: - return context->setError(AL_INVALID_ENUM, "Debug source enum 0x%04x not allowed", source); - default: - return context->setError(AL_INVALID_ENUM, "Invalid debug source enum 0x%04x", source); - } - - DebugType dtype{}; - switch(type) - { - case AL_DEBUG_TYPE_ERROR_SOFT: dtype = DebugType::Error; break; - case AL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_SOFT: dtype = DebugType::DeprecatedBehavior; break; - case AL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_SOFT: dtype = DebugType::UndefinedBehavior; break; - case AL_DEBUG_TYPE_PORTABILITY_SOFT: dtype = DebugType::Portability; break; - case AL_DEBUG_TYPE_PERFORMANCE_SOFT: dtype = DebugType::Performance; break; - case AL_DEBUG_TYPE_MARKER_SOFT: dtype = DebugType::Marker; break; - case AL_DEBUG_TYPE_OTHER_SOFT: dtype = DebugType::Other; break; - default: - return context->setError(AL_INVALID_ENUM, "Invalid debug type 0x%04x", type); - } - - DebugSeverity dseverity{}; - switch(severity) - { - case AL_DEBUG_SEVERITY_HIGH_SOFT: dseverity = DebugSeverity::High; break; - case AL_DEBUG_SEVERITY_MEDIUM_SOFT: dseverity = DebugSeverity::Medium; break; - case AL_DEBUG_SEVERITY_LOW_SOFT: dseverity = DebugSeverity::Low; break; - case AL_DEBUG_SEVERITY_NOTIFICATION_SOFT: dseverity = DebugSeverity::Notification; break; - default: - return context->setError(AL_INVALID_ENUM, "Invalid debug severity 0x%04x", severity); - } - - context->debugMessage(dsource, dtype, id, dseverity, length, message); -} - - -namespace { - -template -constexpr auto make_array(std::integer_sequence) -{ return std::array{Vals...}; } - -template> -constexpr auto make_array() -{ return make_array(Indices{}); } - -} // namespace - -FORCE_ALIGN void AL_APIENTRY alDebugMessageControlSOFT(ALenum source, ALenum type, ALenum severity, - ALsizei count, const ALuint *ids, ALboolean enable) noexcept -{ - ContextRef context{GetContextRef()}; - if(!context) UNLIKELY return; - - if(count > 0) - { - if(!ids) - return context->setError(AL_INVALID_VALUE, "IDs is null with non-0 count"); - if(source == AL_DONT_CARE_SOFT) - return context->setError(AL_INVALID_VALUE, - "Debug source cannot be AL_DONT_CARE_SOFT with IDs"); - if(type == AL_DONT_CARE_SOFT) - return context->setError(AL_INVALID_VALUE, - "Debug type cannot be AL_DONT_CARE_SOFT with IDs"); - if(severity != AL_DONT_CARE_SOFT) - return context->setError(AL_INVALID_VALUE, - "Debug severity must be AL_DONT_CARE_SOFT with IDs"); - - return context->setError(AL_INVALID_VALUE, "Debug ID filtering not supported"); - return; - } - - if(enable != AL_TRUE && enable != AL_FALSE) - return context->setError(AL_INVALID_VALUE, "Invalid debug enable %d", enable); - - static constexpr size_t ElemCount{DebugSourceCount + DebugTypeCount + DebugSeverityCount}; - static constexpr auto Values = make_array(); - - al::span srcIndices{al::as_span(Values).subspan()}; - switch(source) - { - case AL_DEBUG_SOURCE_API_SOFT: srcIndices = srcIndices.subspan(0, 1); break; - case AL_DEBUG_SOURCE_AUDIO_SYSTEM_SOFT: srcIndices = srcIndices.subspan(1, 1); break; - case AL_DEBUG_SOURCE_THIRD_PARTY_SOFT: srcIndices = srcIndices.subspan(2, 1); break; - case AL_DEBUG_SOURCE_APPLICATION_SOFT: srcIndices = srcIndices.subspan(3, 1); break; - case AL_DEBUG_SOURCE_OTHER_SOFT: srcIndices = srcIndices.subspan(4, 1); break; - case AL_DONT_CARE_SOFT: break; - default: - return context->setError(AL_INVALID_VALUE, "Invalid debug source 0x%04x", source); - } - - al::span typeIndices{al::as_span(Values).subspan()}; - switch(type) - { - case AL_DEBUG_TYPE_ERROR_SOFT: typeIndices = typeIndices.subspan(0, 1); break; - case AL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_SOFT: typeIndices = typeIndices.subspan(1, 1); break; - case AL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_SOFT: typeIndices = typeIndices.subspan(2, 1); break; - case AL_DEBUG_TYPE_PORTABILITY_SOFT: typeIndices = typeIndices.subspan(3, 1); break; - case AL_DEBUG_TYPE_PERFORMANCE_SOFT: typeIndices = typeIndices.subspan(4, 1); break; - case AL_DEBUG_TYPE_MARKER_SOFT: typeIndices = typeIndices.subspan(5, 1); break; - case AL_DEBUG_TYPE_OTHER_SOFT: typeIndices = typeIndices.subspan(6, 1); break; - case AL_DONT_CARE_SOFT: break; - default: - return context->setError(AL_INVALID_VALUE, "Invalid debug type 0x%04x", type); - } - - al::span svrIndices{al::as_span(Values).subspan()}; - switch(severity) - { - case AL_DEBUG_SEVERITY_HIGH_SOFT: svrIndices = svrIndices.subspan(0, 1); break; - case AL_DEBUG_SEVERITY_MEDIUM_SOFT: svrIndices = svrIndices.subspan(1, 1); break; - case AL_DEBUG_SEVERITY_LOW_SOFT: svrIndices = svrIndices.subspan(2, 1); break; - case AL_DEBUG_SEVERITY_NOTIFICATION_SOFT: svrIndices = svrIndices.subspan(3, 1); break; - case AL_DONT_CARE_SOFT: break; - default: - return context->setError(AL_INVALID_VALUE, "Invalid debug severity 0x%04x", severity); - } - - std::lock_guard _{context->mDebugCbLock}; - auto apply_filter = [enable,&context](const uint filter) - { - auto iter = std::lower_bound(context->mDebugFilters.cbegin(), - context->mDebugFilters.cend(), filter); - if(enable && (iter == context->mDebugFilters.cend() || *iter != filter)) - context->mDebugFilters.insert(iter, filter); - else if(!enable && iter != context->mDebugFilters.cend() && *iter == filter) - context->mDebugFilters.erase(iter); - }; - auto apply_severity = [apply_filter,svrIndices](const uint filter) - { - std::for_each(svrIndices.cbegin(), svrIndices.cend(), - [apply_filter,filter](const uint idx){ apply_filter(filter | (1< Date: Sun, 30 Apr 2023 03:53:16 -0700 Subject: Separate the internal debug enums from the API values --- al/debug.cpp | 129 +++++++++++++++++++++++++++++--------------------------- alc/context.cpp | 67 +++++++++++++++++------------ alc/context.h | 54 ++++++++++++------------ 3 files changed, 133 insertions(+), 117 deletions(-) (limited to 'alc/context.cpp') diff --git a/al/debug.cpp b/al/debug.cpp index 975443c7..5d01fda9 100644 --- a/al/debug.cpp +++ b/al/debug.cpp @@ -12,6 +12,7 @@ #include "alc/context.h" #include "alc/inprogext.h" +#include "aloptional.h" #include "alspan.h" #include "opthelpers.h" #include "threads.h" @@ -27,6 +28,47 @@ template GetDebugSource(ALenum source) noexcept +{ + switch(source) + { + case AL_DEBUG_SOURCE_API_SOFT: return DebugSource::API; + case AL_DEBUG_SOURCE_AUDIO_SYSTEM_SOFT: return DebugSource::System; + case AL_DEBUG_SOURCE_THIRD_PARTY_SOFT: return DebugSource::ThirdParty; + case AL_DEBUG_SOURCE_APPLICATION_SOFT: return DebugSource::Application; + case AL_DEBUG_SOURCE_OTHER_SOFT: return DebugSource::Other; + } + return al::nullopt; +} + +constexpr al::optional GetDebugType(ALenum type) noexcept +{ + switch(type) + { + case AL_DEBUG_TYPE_ERROR_SOFT: return DebugType::Error; + case AL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_SOFT: return DebugType::DeprecatedBehavior; + case AL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_SOFT: return DebugType::UndefinedBehavior; + case AL_DEBUG_TYPE_PORTABILITY_SOFT: return DebugType::Portability; + case AL_DEBUG_TYPE_PERFORMANCE_SOFT: return DebugType::Performance; + case AL_DEBUG_TYPE_MARKER_SOFT: return DebugType::Marker; + case AL_DEBUG_TYPE_OTHER_SOFT: return DebugType::Other; + } + return al::nullopt; +} + +constexpr al::optional GetDebugSeverity(ALenum severity) noexcept +{ + switch(severity) + { + case AL_DEBUG_SEVERITY_HIGH_SOFT: return DebugSeverity::High; + case AL_DEBUG_SEVERITY_MEDIUM_SOFT: return DebugSeverity::Medium; + case AL_DEBUG_SEVERITY_LOW_SOFT: return DebugSeverity::Low; + case AL_DEBUG_SEVERITY_NOTIFICATION_SOFT: return DebugSeverity::Notification; + } + return al::nullopt; +} + } // namespace @@ -49,45 +91,21 @@ FORCE_ALIGN void AL_APIENTRY alDebugMessageInsertSOFT(ALenum source, ALenum type if(!message) return context->setError(AL_INVALID_VALUE, "Null message pointer"); - DebugSource dsource{}; - switch(source) - { - case AL_DEBUG_SOURCE_THIRD_PARTY_SOFT: dsource = DebugSource::ThirdParty; break; - case AL_DEBUG_SOURCE_APPLICATION_SOFT: dsource = DebugSource::Application; break; - case AL_DEBUG_SOURCE_API_SOFT: - case AL_DEBUG_SOURCE_AUDIO_SYSTEM_SOFT: - case AL_DEBUG_SOURCE_OTHER_SOFT: - return context->setError(AL_INVALID_ENUM, "Debug source enum 0x%04x not allowed", source); - default: - return context->setError(AL_INVALID_ENUM, "Invalid debug source enum 0x%04x", source); - } + auto dsource = GetDebugSource(source); + if(!dsource) + return context->setError(AL_INVALID_ENUM, "Invalid debug source 0x%04x", source); + if(*dsource != DebugSource::ThirdParty && *dsource != DebugSource::Application) + return context->setError(AL_INVALID_ENUM, "Debug source 0x%04x not allowed", source); - DebugType dtype{}; - switch(type) - { - case AL_DEBUG_TYPE_ERROR_SOFT: dtype = DebugType::Error; break; - case AL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_SOFT: dtype = DebugType::DeprecatedBehavior; break; - case AL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_SOFT: dtype = DebugType::UndefinedBehavior; break; - case AL_DEBUG_TYPE_PORTABILITY_SOFT: dtype = DebugType::Portability; break; - case AL_DEBUG_TYPE_PERFORMANCE_SOFT: dtype = DebugType::Performance; break; - case AL_DEBUG_TYPE_MARKER_SOFT: dtype = DebugType::Marker; break; - case AL_DEBUG_TYPE_OTHER_SOFT: dtype = DebugType::Other; break; - default: + auto dtype = GetDebugType(type); + if(!dtype) return context->setError(AL_INVALID_ENUM, "Invalid debug type 0x%04x", type); - } - DebugSeverity dseverity{}; - switch(severity) - { - case AL_DEBUG_SEVERITY_HIGH_SOFT: dseverity = DebugSeverity::High; break; - case AL_DEBUG_SEVERITY_MEDIUM_SOFT: dseverity = DebugSeverity::Medium; break; - case AL_DEBUG_SEVERITY_LOW_SOFT: dseverity = DebugSeverity::Low; break; - case AL_DEBUG_SEVERITY_NOTIFICATION_SOFT: dseverity = DebugSeverity::Notification; break; - default: + auto dseverity = GetDebugSeverity(severity); + if(!dseverity) return context->setError(AL_INVALID_ENUM, "Invalid debug severity 0x%04x", severity); - } - context->debugMessage(dsource, dtype, id, dseverity, length, message); + context->debugMessage(*dsource, *dtype, id, *dseverity, length, message); } @@ -122,43 +140,30 @@ FORCE_ALIGN void AL_APIENTRY alDebugMessageControlSOFT(ALenum source, ALenum typ static constexpr auto Values = make_array(); al::span srcIndices{al::as_span(Values).subspan()}; - switch(source) + if(source != AL_DONT_CARE_SOFT) { - case AL_DEBUG_SOURCE_API_SOFT: srcIndices = srcIndices.subspan(0, 1); break; - case AL_DEBUG_SOURCE_AUDIO_SYSTEM_SOFT: srcIndices = srcIndices.subspan(1, 1); break; - case AL_DEBUG_SOURCE_THIRD_PARTY_SOFT: srcIndices = srcIndices.subspan(2, 1); break; - case AL_DEBUG_SOURCE_APPLICATION_SOFT: srcIndices = srcIndices.subspan(3, 1); break; - case AL_DEBUG_SOURCE_OTHER_SOFT: srcIndices = srcIndices.subspan(4, 1); break; - case AL_DONT_CARE_SOFT: break; - default: - return context->setError(AL_INVALID_VALUE, "Invalid debug source 0x%04x", source); + auto dsource = GetDebugSource(source); + if(!dsource) + return context->setError(AL_INVALID_ENUM, "Invalid debug source 0x%04x", source); + srcIndices = srcIndices.subspan(al::to_underlying(*dsource), 1); } al::span typeIndices{al::as_span(Values).subspan()}; - switch(type) + if(type != AL_DONT_CARE_SOFT) { - case AL_DEBUG_TYPE_ERROR_SOFT: typeIndices = typeIndices.subspan(0, 1); break; - case AL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_SOFT: typeIndices = typeIndices.subspan(1, 1); break; - case AL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_SOFT: typeIndices = typeIndices.subspan(2, 1); break; - case AL_DEBUG_TYPE_PORTABILITY_SOFT: typeIndices = typeIndices.subspan(3, 1); break; - case AL_DEBUG_TYPE_PERFORMANCE_SOFT: typeIndices = typeIndices.subspan(4, 1); break; - case AL_DEBUG_TYPE_MARKER_SOFT: typeIndices = typeIndices.subspan(5, 1); break; - case AL_DEBUG_TYPE_OTHER_SOFT: typeIndices = typeIndices.subspan(6, 1); break; - case AL_DONT_CARE_SOFT: break; - default: - return context->setError(AL_INVALID_VALUE, "Invalid debug type 0x%04x", type); + auto dtype = GetDebugType(type); + if(!dtype) + return context->setError(AL_INVALID_ENUM, "Invalid debug type 0x%04x", type); + typeIndices = typeIndices.subspan(al::to_underlying(*dtype), 1); } al::span svrIndices{al::as_span(Values).subspan()}; - switch(severity) + if(severity != AL_DONT_CARE_SOFT) { - case AL_DEBUG_SEVERITY_HIGH_SOFT: svrIndices = svrIndices.subspan(0, 1); break; - case AL_DEBUG_SEVERITY_MEDIUM_SOFT: svrIndices = svrIndices.subspan(1, 1); break; - case AL_DEBUG_SEVERITY_LOW_SOFT: svrIndices = svrIndices.subspan(2, 1); break; - case AL_DEBUG_SEVERITY_NOTIFICATION_SOFT: svrIndices = svrIndices.subspan(3, 1); break; - case AL_DONT_CARE_SOFT: break; - default: - return context->setError(AL_INVALID_VALUE, "Invalid debug severity 0x%04x", severity); + auto dseverity = GetDebugSeverity(severity); + if(!dseverity) + return context->setError(AL_INVALID_ENUM, "Invalid debug severity 0x%04x", severity); + svrIndices = svrIndices.subspan(al::to_underlying(*dseverity), 1); } std::lock_guard _{context->mDebugCbLock}; diff --git a/alc/context.cpp b/alc/context.cpp index 5b476009..7fcb6539 100644 --- a/alc/context.cpp +++ b/alc/context.cpp @@ -304,45 +304,56 @@ void ALCcontext::sendDebugMessage(DebugSource source, DebugType type, ALuint id, DebugSeverity severity, ALsizei length, const char *message) { static_assert(DebugSeverityBase+DebugSeverityCount <= 32, "Too many debug bits"); + static auto get_source_enum = [](DebugSource source) noexcept + { + switch(source) + { + case DebugSource::API: return AL_DEBUG_SOURCE_API_SOFT; + case DebugSource::System: return AL_DEBUG_SOURCE_AUDIO_SYSTEM_SOFT; + case DebugSource::ThirdParty: return AL_DEBUG_SOURCE_THIRD_PARTY_SOFT; + case DebugSource::Application: return AL_DEBUG_SOURCE_APPLICATION_SOFT; + case DebugSource::Other: return AL_DEBUG_SOURCE_OTHER_SOFT; + } + }; + static auto get_type_enum = [](DebugType type) noexcept + { + switch(type) + { + case DebugType::Error: return AL_DEBUG_TYPE_ERROR_SOFT; + case DebugType::DeprecatedBehavior: return AL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_SOFT; + case DebugType::UndefinedBehavior: return AL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_SOFT; + case DebugType::Portability: return AL_DEBUG_TYPE_PORTABILITY_SOFT; + case DebugType::Performance: return AL_DEBUG_TYPE_PERFORMANCE_SOFT; + case DebugType::Marker: return AL_DEBUG_TYPE_MARKER_SOFT; + case DebugType::Other: return AL_DEBUG_TYPE_OTHER_SOFT; + } + }; + static auto get_severity_enum = [](DebugSeverity severity) noexcept + { + switch(severity) + { + case DebugSeverity::High: return AL_DEBUG_SEVERITY_HIGH_SOFT; + case DebugSeverity::Medium: return AL_DEBUG_SEVERITY_MEDIUM_SOFT; + case DebugSeverity::Low: return AL_DEBUG_SEVERITY_LOW_SOFT; + case DebugSeverity::Notification: return AL_DEBUG_SEVERITY_NOTIFICATION_SOFT; + } + }; std::lock_guard _{mDebugCbLock}; if(!mDebugEnabled.load()) UNLIKELY return; - uint filter{0}; - switch(source) - { - case DebugSource::API: filter |= 1<<(DebugSourceBase+0); break; - case DebugSource::System: filter |= 1<<(DebugSourceBase+1); break; - case DebugSource::ThirdParty: filter |= 1<<(DebugSourceBase+2); break; - case DebugSource::Application: filter |= 1<<(DebugSourceBase+3); break; - case DebugSource::Other: filter |= 1<<(DebugSourceBase+4); break; - } - switch(type) - { - case DebugType::Error: filter |= 1<<(DebugTypeBase+0); break; - case DebugType::DeprecatedBehavior: filter |= 1<<(DebugTypeBase+1); break; - case DebugType::UndefinedBehavior: filter |= 1<<(DebugTypeBase+2); break; - case DebugType::Portability: filter |= 1<<(DebugTypeBase+3); break; - case DebugType::Performance: filter |= 1<<(DebugTypeBase+4); break; - case DebugType::Marker: filter |= 1<<(DebugTypeBase+5); break; - case DebugType::Other: filter |= 1<<(DebugTypeBase+6); break; - } - switch(severity) - { - case DebugSeverity::High: filter |= 1<<(DebugSeverityBase+0); break; - case DebugSeverity::Medium: filter |= 1<<(DebugSeverityBase+1); break; - case DebugSeverity::Low: filter |= 1<<(DebugSeverityBase+2); break; - case DebugSeverity::Notification: filter |= 1<<(DebugSeverityBase+3); break; - } + const uint filter{(1u<<(DebugSourceBase+al::to_underlying(source))) + | (1u<<(DebugTypeBase+al::to_underlying(type))) + | (1u<<(DebugSeverityBase+al::to_underlying(severity)))}; auto iter = std::lower_bound(mDebugFilters.cbegin(), mDebugFilters.cend(), filter); if(iter != mDebugFilters.cend() && *iter == filter) return; if(mDebugCb) - mDebugCb(al::to_underlying(source), al::to_underlying(type), id, - al::to_underlying(severity), length, message, mDebugParam); + mDebugCb(get_source_enum(source), get_type_enum(type), id, get_severity_enum(severity), + length, message, mDebugParam); else { /* TODO: Store in a log. */ diff --git a/alc/context.h b/alc/context.h index 8613c2a3..b5ee440b 100644 --- a/alc/context.h +++ b/alc/context.h @@ -35,36 +35,36 @@ struct ALsource; using uint = unsigned int; -constexpr size_t DebugSourceBase{0}; -enum class DebugSource : ALenum { - API = AL_DEBUG_SOURCE_API_SOFT, - System = AL_DEBUG_SOURCE_AUDIO_SYSTEM_SOFT, - ThirdParty = AL_DEBUG_SOURCE_THIRD_PARTY_SOFT, - Application = AL_DEBUG_SOURCE_APPLICATION_SOFT, - Other = AL_DEBUG_SOURCE_OTHER_SOFT, +constexpr uint DebugSourceBase{0}; +enum class DebugSource : uint8_t { + API = 0, + System, + ThirdParty, + Application, + Other, }; -constexpr size_t DebugSourceCount{5}; - -constexpr size_t DebugTypeBase{DebugSourceBase + DebugSourceCount}; -enum class DebugType : ALenum { - Error = AL_DEBUG_TYPE_ERROR_SOFT, - DeprecatedBehavior = AL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_SOFT, - UndefinedBehavior = AL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_SOFT, - Portability = AL_DEBUG_TYPE_PORTABILITY_SOFT, - Performance = AL_DEBUG_TYPE_PERFORMANCE_SOFT, - Marker = AL_DEBUG_TYPE_MARKER_SOFT, - Other = AL_DEBUG_TYPE_OTHER_SOFT, +constexpr uint DebugSourceCount{5}; + +constexpr uint DebugTypeBase{DebugSourceBase + DebugSourceCount}; +enum class DebugType : uint8_t { + Error = 0, + DeprecatedBehavior, + UndefinedBehavior, + Portability, + Performance, + Marker, + Other, }; -constexpr size_t DebugTypeCount{7}; - -constexpr size_t DebugSeverityBase{DebugTypeBase + DebugTypeCount}; -enum class DebugSeverity : ALenum { - High = AL_DEBUG_SEVERITY_HIGH_SOFT, - Medium = AL_DEBUG_SEVERITY_MEDIUM_SOFT, - Low = AL_DEBUG_SEVERITY_LOW_SOFT, - Notification = AL_DEBUG_SEVERITY_NOTIFICATION_SOFT, +constexpr uint DebugTypeCount{7}; + +constexpr uint DebugSeverityBase{DebugTypeBase + DebugTypeCount}; +enum class DebugSeverity : uint8_t { + High = 0, + Medium, + Low, + Notification, }; -constexpr size_t DebugSeverityCount{4}; +constexpr uint DebugSeverityCount{4}; struct SourceSubList { -- cgit v1.2.3 From b64b500c6b75aebb3b5d1c41206317f81636a21c Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 30 Apr 2023 04:22:13 -0700 Subject: Improve some debug error handling --- al/debug.cpp | 8 ++++---- alc/context.cpp | 9 ++++++--- 2 files changed, 10 insertions(+), 7 deletions(-) (limited to 'alc/context.cpp') diff --git a/al/debug.cpp b/al/debug.cpp index 5d01fda9..98c5a0b5 100644 --- a/al/debug.cpp +++ b/al/debug.cpp @@ -120,13 +120,13 @@ FORCE_ALIGN void AL_APIENTRY alDebugMessageControlSOFT(ALenum source, ALenum typ if(!ids) return context->setError(AL_INVALID_VALUE, "IDs is null with non-0 count"); if(source == AL_DONT_CARE_SOFT) - return context->setError(AL_INVALID_VALUE, + return context->setError(AL_INVALID_OPERATION, "Debug source cannot be AL_DONT_CARE_SOFT with IDs"); if(type == AL_DONT_CARE_SOFT) - return context->setError(AL_INVALID_VALUE, + return context->setError(AL_INVALID_OPERATION, "Debug type cannot be AL_DONT_CARE_SOFT with IDs"); if(severity != AL_DONT_CARE_SOFT) - return context->setError(AL_INVALID_VALUE, + return context->setError(AL_INVALID_OPERATION, "Debug severity must be AL_DONT_CARE_SOFT with IDs"); return context->setError(AL_INVALID_VALUE, "Debug ID filtering not supported"); @@ -134,7 +134,7 @@ FORCE_ALIGN void AL_APIENTRY alDebugMessageControlSOFT(ALenum source, ALenum typ } if(enable != AL_TRUE && enable != AL_FALSE) - return context->setError(AL_INVALID_VALUE, "Invalid debug enable %d", enable); + return context->setError(AL_INVALID_ENUM, "Invalid debug enable %d", enable); static constexpr size_t ElemCount{DebugSourceCount + DebugTypeCount + DebugSeverityCount}; static constexpr auto Values = make_array(); diff --git a/alc/context.cpp b/alc/context.cpp index 7fcb6539..6553f322 100644 --- a/alc/context.cpp +++ b/alc/context.cpp @@ -304,7 +304,7 @@ void ALCcontext::sendDebugMessage(DebugSource source, DebugType type, ALuint id, DebugSeverity severity, ALsizei length, const char *message) { static_assert(DebugSeverityBase+DebugSeverityCount <= 32, "Too many debug bits"); - static auto get_source_enum = [](DebugSource source) noexcept + static auto get_source_enum = [](DebugSource source) { switch(source) { @@ -314,8 +314,9 @@ void ALCcontext::sendDebugMessage(DebugSource source, DebugType type, ALuint id, case DebugSource::Application: return AL_DEBUG_SOURCE_APPLICATION_SOFT; case DebugSource::Other: return AL_DEBUG_SOURCE_OTHER_SOFT; } + throw std::runtime_error{"Unexpected debug source value "+std::to_string(al::to_underlying(source))}; }; - static auto get_type_enum = [](DebugType type) noexcept + static auto get_type_enum = [](DebugType type) { switch(type) { @@ -327,8 +328,9 @@ void ALCcontext::sendDebugMessage(DebugSource source, DebugType type, ALuint id, case DebugType::Marker: return AL_DEBUG_TYPE_MARKER_SOFT; case DebugType::Other: return AL_DEBUG_TYPE_OTHER_SOFT; } + throw std::runtime_error{"Unexpected debug type value "+std::to_string(al::to_underlying(type))}; }; - static auto get_severity_enum = [](DebugSeverity severity) noexcept + static auto get_severity_enum = [](DebugSeverity severity) { switch(severity) { @@ -337,6 +339,7 @@ void ALCcontext::sendDebugMessage(DebugSource source, DebugType type, ALuint id, case DebugSeverity::Low: return AL_DEBUG_SEVERITY_LOW_SOFT; case DebugSeverity::Notification: return AL_DEBUG_SEVERITY_NOTIFICATION_SOFT; } + throw std::runtime_error{"Unexpected debug severity value "+std::to_string(al::to_underlying(severity))}; }; std::lock_guard _{mDebugCbLock}; -- cgit v1.2.3 From f2a0df87916de7b9fa8b65a52814c9a09fc6bee9 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 30 Apr 2023 14:36:56 -0700 Subject: Unlock the debug lock when calling the callback There's no full guarantee about calling AL functions in a debug callback, due to a risk of deadlocks from an AL call that tries to take a lock that's already held at the time the callback is invoked, but this helps more work. --- alc/context.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'alc/context.cpp') diff --git a/alc/context.cpp b/alc/context.cpp index 6553f322..4e5a3ab6 100644 --- a/alc/context.cpp +++ b/alc/context.cpp @@ -342,7 +342,7 @@ void ALCcontext::sendDebugMessage(DebugSource source, DebugType type, ALuint id, throw std::runtime_error{"Unexpected debug severity value "+std::to_string(al::to_underlying(severity))}; }; - std::lock_guard _{mDebugCbLock}; + std::unique_lock debuglock{mDebugCbLock}; if(!mDebugEnabled.load()) UNLIKELY return; @@ -355,8 +355,13 @@ void ALCcontext::sendDebugMessage(DebugSource source, DebugType type, ALuint id, return; if(mDebugCb) - mDebugCb(get_source_enum(source), get_type_enum(type), id, get_severity_enum(severity), - length, message, mDebugParam); + { + auto callback = mDebugCb; + auto param = mDebugParam; + debuglock.unlock(); + callback(get_source_enum(source), get_type_enum(type), id, get_severity_enum(severity), + length, message, param); + } else { /* TODO: Store in a log. */ -- cgit v1.2.3 From 22077687cf4b9fdfd29d78debc2daf044deee81d Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 30 Apr 2023 17:46:18 -0700 Subject: Implement debug log storage --- al/debug.cpp | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ al/debug.h | 9 ++++++ al/state.cpp | 61 ++++++++++++++++++++++++++++++++++++- alc/alc.cpp | 5 ++++ alc/context.cpp | 29 +++++++++++++++++- alc/context.h | 19 ++++++++++++ alc/inprogext.h | 6 ++++ 7 files changed, 220 insertions(+), 2 deletions(-) (limited to 'alc/context.cpp') diff --git a/al/debug.cpp b/al/debug.cpp index 2694d7b4..ab81f5a8 100644 --- a/al/debug.cpp +++ b/al/debug.cpp @@ -71,6 +71,46 @@ constexpr al::optional GetDebugSeverity(ALenum severity) noexcept } // namespace +ALenum GetDebugSourceEnum(DebugSource source) +{ + switch(source) + { + case DebugSource::API: return AL_DEBUG_SOURCE_API_SOFT; + case DebugSource::System: return AL_DEBUG_SOURCE_AUDIO_SYSTEM_SOFT; + case DebugSource::ThirdParty: return AL_DEBUG_SOURCE_THIRD_PARTY_SOFT; + case DebugSource::Application: return AL_DEBUG_SOURCE_APPLICATION_SOFT; + case DebugSource::Other: return AL_DEBUG_SOURCE_OTHER_SOFT; + } + throw std::runtime_error{"Unexpected debug source value "+std::to_string(al::to_underlying(source))}; +} + +ALenum GetDebugTypeEnum(DebugType type) +{ + switch(type) + { + case DebugType::Error: return AL_DEBUG_TYPE_ERROR_SOFT; + case DebugType::DeprecatedBehavior: return AL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_SOFT; + case DebugType::UndefinedBehavior: return AL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_SOFT; + case DebugType::Portability: return AL_DEBUG_TYPE_PORTABILITY_SOFT; + case DebugType::Performance: return AL_DEBUG_TYPE_PERFORMANCE_SOFT; + case DebugType::Marker: return AL_DEBUG_TYPE_MARKER_SOFT; + case DebugType::Other: return AL_DEBUG_TYPE_OTHER_SOFT; + } + throw std::runtime_error{"Unexpected debug type value "+std::to_string(al::to_underlying(type))}; +} + +ALenum GetDebugSeverityEnum(DebugSeverity severity) +{ + switch(severity) + { + case DebugSeverity::High: return AL_DEBUG_SEVERITY_HIGH_SOFT; + case DebugSeverity::Medium: return AL_DEBUG_SEVERITY_MEDIUM_SOFT; + case DebugSeverity::Low: return AL_DEBUG_SEVERITY_LOW_SOFT; + case DebugSeverity::Notification: return AL_DEBUG_SEVERITY_NOTIFICATION_SOFT; + } + throw std::runtime_error{"Unexpected debug severity value "+std::to_string(al::to_underlying(severity))}; +} + FORCE_ALIGN void AL_APIENTRY alDebugMessageCallbackSOFT(ALDEBUGPROCSOFT callback, void *userParam) noexcept { @@ -91,6 +131,18 @@ FORCE_ALIGN void AL_APIENTRY alDebugMessageInsertSOFT(ALenum source, ALenum type if(!message) return context->setError(AL_INVALID_VALUE, "Null message pointer"); + if(length < 0) + { + size_t newlen{std::strlen(message)}; + if(newlen > MaxDebugMessageLength) UNLIKELY + return context->setError(AL_INVALID_VALUE, "Debug message too long (%zu > %d)", newlen, + MaxDebugMessageLength); + length = static_cast(newlen); + } + else if(length > MaxDebugMessageLength) UNLIKELY + return context->setError(AL_INVALID_VALUE, "Debug message too long (%d > %d)", length, + MaxDebugMessageLength); + auto dsource = GetDebugSource(source); if(!dsource) return context->setError(AL_INVALID_ENUM, "Invalid debug source 0x%04x", source); @@ -189,3 +241,44 @@ FORCE_ALIGN void AL_APIENTRY alDebugMessageControlSOFT(ALenum source, ALenum typ std::for_each(srcIndices.cbegin(), srcIndices.cend(), [apply_type](const uint idx){ apply_type(1<setError(AL_INVALID_VALUE, "Negative debug log buffer size"); + return 0; + } + + std::lock_guard _{context->mDebugCbLock}; + ALsizei logBufWritten{0}; + for(ALuint i{0};i < count;++i) + { + if(context->mDebugLog.empty()) + return i; + + auto &entry = context->mDebugLog.front(); + const size_t tocopy{entry.mMessage.size() + 1}; + const size_t avail{static_cast(logBufSize - logBufWritten)}; + if(avail < tocopy) + return i; + + if(sources) sources[i] = GetDebugSourceEnum(entry.mSource); + if(types) types[i] = GetDebugTypeEnum(entry.mType); + if(ids) ids[i] = entry.mId; + if(severities) severities[i] = GetDebugSeverityEnum(entry.mSeverity); + if(lengths) lengths[i] = static_cast(tocopy); + if(logBuf) std::copy_n(entry.mMessage.data(), tocopy, logBuf+logBufWritten); + + logBufWritten += static_cast(tocopy); + context->mDebugLog.pop_front(); + } + + return count; +} diff --git a/al/debug.h b/al/debug.h index a268f690..23b0ca1b 100644 --- a/al/debug.h +++ b/al/debug.h @@ -1,4 +1,13 @@ #ifndef AL_DEBUG_H #define AL_DEBUG_H +#include + + +/* Somewhat arbitrary. Avoid letting it get out of control if the app enables + * logging but never reads it. + */ +constexpr uint8_t MaxDebugLoggedMessages{64}; +constexpr uint16_t MaxDebugMessageLength{1024}; + #endif /* AL_DEBUG_H */ diff --git a/al/state.cpp b/al/state.cpp index 7b7377f7..1e1a0085 100644 --- a/al/state.cpp +++ b/al/state.cpp @@ -33,6 +33,7 @@ #include "AL/alc.h" #include "AL/alext.h" +#include "al/debug.h" #include "alc/alu.h" #include "alc/context.h" #include "alc/inprogext.h" @@ -259,6 +260,10 @@ START_API_FUNC case AL_DISTANCE_MODEL: case AL_NUM_RESAMPLERS_SOFT: case AL_DEFAULT_RESAMPLER_SOFT: + case AL_DEBUG_LOGGED_MESSAGES_SOFT: + case AL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_SOFT: + case AL_MAX_DEBUG_MESSAGE_LENGTH_SOFT: + case AL_MAX_DEBUG_LOGGED_MESSAGES_SOFT: return alGetInteger(pname) != 0; } @@ -299,6 +304,10 @@ START_API_FUNC case AL_DISTANCE_MODEL: case AL_NUM_RESAMPLERS_SOFT: case AL_DEFAULT_RESAMPLER_SOFT: + case AL_DEBUG_LOGGED_MESSAGES_SOFT: + case AL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_SOFT: + case AL_MAX_DEBUG_MESSAGE_LENGTH_SOFT: + case AL_MAX_DEBUG_LOGGED_MESSAGES_SOFT: return alGetInteger(pname); } @@ -325,8 +334,11 @@ START_API_FUNC case AL_DISTANCE_MODEL: case AL_NUM_RESAMPLERS_SOFT: case AL_DEFAULT_RESAMPLER_SOFT: + case AL_DEBUG_LOGGED_MESSAGES_SOFT: + case AL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_SOFT: + case AL_MAX_DEBUG_MESSAGE_LENGTH_SOFT: + case AL_MAX_DEBUG_LOGGED_MESSAGES_SOFT: return static_cast(alGetInteger(pname)); - break; case AL_DEFERRED_UPDATES_SOFT: return alGetBoolean(pname) ? 1.0f : 0.0f; @@ -401,6 +413,29 @@ START_API_FUNC value = al::to_underlying(ResamplerDefault); break; + case AL_DEBUG_LOGGED_MESSAGES_SOFT: + { + std::lock_guard __{context->mDebugCbLock}; + value = static_cast(context->mDebugLog.size()); + break; + } + + case AL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_SOFT: + { + std::lock_guard __{context->mDebugCbLock}; + value = context->mDebugLog.empty() ? 0 + : static_cast(context->mDebugLog.front().mMessage.size()+1); + break; + } + + case AL_MAX_DEBUG_MESSAGE_LENGTH_SOFT: + value = MaxDebugMessageLength; + break; + + case AL_MAX_DEBUG_LOGGED_MESSAGES_SOFT: + value = MaxDebugLoggedMessages; + break; + #ifdef ALSOFT_EAX #define EAX_ERROR "[alGetInteger] EAX not enabled." @@ -452,6 +487,10 @@ START_API_FUNC case AL_DISTANCE_MODEL: case AL_NUM_RESAMPLERS_SOFT: case AL_DEFAULT_RESAMPLER_SOFT: + case AL_DEBUG_LOGGED_MESSAGES_SOFT: + case AL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_SOFT: + case AL_MAX_DEBUG_MESSAGE_LENGTH_SOFT: + case AL_MAX_DEBUG_LOGGED_MESSAGES_SOFT: return alGetInteger(pname); } @@ -519,6 +558,10 @@ START_API_FUNC case AL_GAIN_LIMIT_SOFT: case AL_NUM_RESAMPLERS_SOFT: case AL_DEFAULT_RESAMPLER_SOFT: + case AL_DEBUG_LOGGED_MESSAGES_SOFT: + case AL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_SOFT: + case AL_MAX_DEBUG_MESSAGE_LENGTH_SOFT: + case AL_MAX_DEBUG_LOGGED_MESSAGES_SOFT: values[0] = alGetBoolean(pname); return; } @@ -552,6 +595,10 @@ START_API_FUNC case AL_GAIN_LIMIT_SOFT: case AL_NUM_RESAMPLERS_SOFT: case AL_DEFAULT_RESAMPLER_SOFT: + case AL_DEBUG_LOGGED_MESSAGES_SOFT: + case AL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_SOFT: + case AL_MAX_DEBUG_MESSAGE_LENGTH_SOFT: + case AL_MAX_DEBUG_LOGGED_MESSAGES_SOFT: values[0] = alGetDouble(pname); return; } @@ -585,6 +632,10 @@ START_API_FUNC case AL_GAIN_LIMIT_SOFT: case AL_NUM_RESAMPLERS_SOFT: case AL_DEFAULT_RESAMPLER_SOFT: + case AL_DEBUG_LOGGED_MESSAGES_SOFT: + case AL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_SOFT: + case AL_MAX_DEBUG_MESSAGE_LENGTH_SOFT: + case AL_MAX_DEBUG_LOGGED_MESSAGES_SOFT: values[0] = alGetFloat(pname); return; } @@ -618,6 +669,10 @@ START_API_FUNC case AL_GAIN_LIMIT_SOFT: case AL_NUM_RESAMPLERS_SOFT: case AL_DEFAULT_RESAMPLER_SOFT: + case AL_DEBUG_LOGGED_MESSAGES_SOFT: + case AL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_SOFT: + case AL_MAX_DEBUG_MESSAGE_LENGTH_SOFT: + case AL_MAX_DEBUG_LOGGED_MESSAGES_SOFT: values[0] = alGetInteger(pname); return; } @@ -651,6 +706,10 @@ START_API_FUNC case AL_GAIN_LIMIT_SOFT: case AL_NUM_RESAMPLERS_SOFT: case AL_DEFAULT_RESAMPLER_SOFT: + case AL_DEBUG_LOGGED_MESSAGES_SOFT: + case AL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_SOFT: + case AL_MAX_DEBUG_MESSAGE_LENGTH_SOFT: + case AL_MAX_DEBUG_LOGGED_MESSAGES_SOFT: values[0] = alGetInteger64SOFT(pname); return; } 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(newlen); + } + else if(length > MaxDebugMessageLength) UNLIKELY + { + ERR("Debug message too long (%d > %d)\n", length, MaxDebugMessageLength); + return; + } + std::unique_lock 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 +#include #include #include #include @@ -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 + LogEntry(DebugSource source, DebugType type, uint id, DebugSeverity severity, T&& message) + : mSource{source}, mType{type}, mSeverity{severity}, mId{id} + , mMessage{std::forward(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, ContextBase { ALDEBUGPROCSOFT mDebugCb{}; void *mDebugParam{nullptr}; std::vector mDebugFilters; + std::deque 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 -- cgit v1.2.3 From 9215e8c9d5f4fdc7b2e552203f5836264542c4a3 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 30 Apr 2023 18:17:24 -0700 Subject: Add an extension string for the in-progress debug extension --- alc/context.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'alc/context.cpp') diff --git a/alc/context.cpp b/alc/context.cpp index a07e5412..4b477184 100644 --- a/alc/context.cpp +++ b/alc/context.cpp @@ -71,6 +71,7 @@ constexpr ALchar alExtList[] = "AL_SOFT_buffer_length_query " "AL_SOFT_callback_buffer " "AL_SOFTX_convolution_reverb " + "AL_SOFTX_debug " "AL_SOFT_deferred_updates " "AL_SOFT_direct_channels " "AL_SOFT_direct_channels_remix " -- cgit v1.2.3 From 3953cb5dbef7add70e72f41bbf36d5fdf1b02917 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 30 Apr 2023 19:22:38 -0700 Subject: Fix shadowing warnings and add another missing include --- alc/context.cpp | 55 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 27 deletions(-) (limited to 'alc/context.cpp') diff --git a/alc/context.cpp b/alc/context.cpp index 4b477184..66de19d6 100644 --- a/alc/context.cpp +++ b/alc/context.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -306,7 +307,28 @@ void ALCcontext::sendDebugMessage(DebugSource source, DebugType type, ALuint id, DebugSeverity severity, ALsizei length, const char *message) { static_assert(DebugSeverityBase+DebugSeverityCount <= 32, "Too many debug bits"); - static auto get_source_enum = [](DebugSource source) + + 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(newlen); + } + else if(length > MaxDebugMessageLength) UNLIKELY + { + ERR("Debug message too long (%d > %d)\n", length, MaxDebugMessageLength); + return; + } + + std::unique_lock debuglock{mDebugCbLock}; + if(!mDebugEnabled.load()) UNLIKELY + return; + + auto get_source_enum = [source]() { switch(source) { @@ -318,7 +340,7 @@ void ALCcontext::sendDebugMessage(DebugSource source, DebugType type, ALuint id, } throw std::runtime_error{"Unexpected debug source value "+std::to_string(al::to_underlying(source))}; }; - static auto get_type_enum = [](DebugType type) + auto get_type_enum = [type]() { switch(type) { @@ -332,7 +354,7 @@ void ALCcontext::sendDebugMessage(DebugSource source, DebugType type, ALuint id, } throw std::runtime_error{"Unexpected debug type value "+std::to_string(al::to_underlying(type))}; }; - static auto get_severity_enum = [](DebugSeverity severity) + auto get_severity_enum = [severity]() { switch(severity) { @@ -344,26 +366,6 @@ 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(newlen); - } - else if(length > MaxDebugMessageLength) UNLIKELY - { - ERR("Debug message too long (%d > %d)\n", length, MaxDebugMessageLength); - return; - } - - std::unique_lock debuglock{mDebugCbLock}; - if(!mDebugEnabled.load()) UNLIKELY - return; - const uint filter{(1u<<(DebugSourceBase+al::to_underlying(source))) | (1u<<(DebugTypeBase+al::to_underlying(type))) | (1u<<(DebugSeverityBase+al::to_underlying(severity)))}; @@ -377,8 +379,8 @@ void ALCcontext::sendDebugMessage(DebugSource source, DebugType type, ALuint id, auto callback = mDebugCb; auto param = mDebugParam; debuglock.unlock(); - callback(get_source_enum(source), get_type_enum(type), id, get_severity_enum(severity), - length, message, param); + callback(get_source_enum(), get_type_enum(), id, get_severity_enum(), length, message, + param); } else { @@ -391,8 +393,7 @@ void ALCcontext::sendDebugMessage(DebugSource source, DebugType type, ALuint id, " ID: %u\n" " Severity: 0x%04x\n" " Message: \"%s\"\n", - get_source_enum(source), get_type_enum(type), id, get_severity_enum(severity), - message); + get_source_enum(), get_type_enum(), id, get_severity_enum(), message); } } -- cgit v1.2.3 From 931e261fe0944c1876a95a373996351f3424f399 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 1 May 2023 01:22:29 -0700 Subject: Implement debug message filtering for IDs --- al/debug.cpp | 71 +++++++++++++++++++++++++++++++++++++++------------------ alc/context.cpp | 11 +++++++++ alc/context.h | 2 ++ 3 files changed, 62 insertions(+), 22 deletions(-) (limited to 'alc/context.cpp') diff --git a/al/debug.cpp b/al/debug.cpp index 702f165a..26a69aff 100644 --- a/al/debug.cpp +++ b/al/debug.cpp @@ -183,9 +183,6 @@ FORCE_ALIGN void AL_APIENTRY alDebugMessageControlSOFT(ALenum source, ALenum typ if(severity != AL_DONT_CARE_SOFT) return context->setError(AL_INVALID_OPERATION, "Debug severity must be AL_DONT_CARE_SOFT with IDs"); - - return context->setError(AL_INVALID_VALUE, "Debug ID filtering not supported"); - return; } if(enable != AL_TRUE && enable != AL_FALSE) @@ -222,27 +219,57 @@ FORCE_ALIGN void AL_APIENTRY alDebugMessageControlSOFT(ALenum source, ALenum typ } std::lock_guard _{context->mDebugCbLock}; - auto apply_filter = [enable,&context](const uint filter) - { - auto iter = std::lower_bound(context->mDebugFilters.cbegin(), - context->mDebugFilters.cend(), filter); - if(!enable && (iter == context->mDebugFilters.cend() || *iter != filter)) - context->mDebugFilters.insert(iter, filter); - else if(enable && iter != context->mDebugFilters.cend() && *iter == filter) - context->mDebugFilters.erase(iter); - }; - auto apply_severity = [apply_filter,svrIndices](const uint filter) + if(count > 0) { - std::for_each(svrIndices.cbegin(), svrIndices.cend(), - [apply_filter,filter](const uint idx){ apply_filter(filter | (1<(count))) + { + if(!enable) + { + auto &idfilters = context->mDebugIdFilters[id]; + auto iter = std::lower_bound(idfilters.cbegin(), idfilters.cend(), filter); + if(iter == idfilters.cend() || *iter != filter) + idfilters.insert(iter, filter); + continue; + } + + auto iditer = context->mDebugIdFilters.find(id); + if(iditer == context->mDebugIdFilters.end()) + continue; + auto iter = std::lower_bound(iditer->second.cbegin(), iditer->second.cend(), filter); + if(iter != iditer->second.cend() && *iter == filter) + { + iditer->second.erase(iter); + if(iditer->second.empty()) + context->mDebugIdFilters.erase(iditer); + } + } + } + else { - std::for_each(typeIndices.cbegin(), typeIndices.cend(), - [apply_severity,filter](const uint idx){ apply_severity(filter | (1<mDebugFilters.cbegin(), + context->mDebugFilters.cend(), filter); + if(!enable && (iter == context->mDebugFilters.cend() || *iter != filter)) + context->mDebugFilters.insert(iter, filter); + else if(enable && iter != context->mDebugFilters.cend() && *iter == filter) + context->mDebugFilters.erase(iter); + }; + auto apply_severity = [apply_filter,svrIndices](const uint filter) + { + std::for_each(svrIndices.cbegin(), svrIndices.cend(), + [apply_filter,filter](const uint idx){ apply_filter(filter | (1<second.cbegin(), iditer->second.cend(), filter); + if(iter != iditer->second.cend() && *iter == filter) + return; + } + const uint filter{(1u<<(DebugSourceBase+al::to_underlying(source))) | (1u<<(DebugTypeBase+al::to_underlying(type))) | (1u<<(DebugSeverityBase+al::to_underlying(severity)))}; diff --git a/alc/context.h b/alc/context.h index 031e061e..c626160b 100644 --- a/alc/context.h +++ b/alc/context.h @@ -6,6 +6,7 @@ #include #include #include +#include #include #include "AL/al.h" @@ -145,6 +146,7 @@ struct ALCcontext : public al::intrusive_ref, ContextBase { ALDEBUGPROCSOFT mDebugCb{}; void *mDebugParam{nullptr}; std::vector mDebugFilters; + std::unordered_map> mDebugIdFilters; std::deque mDebugLog; ALlistener mListener{}; -- cgit v1.2.3 From bd8c13d7883cb0a570f724885c7a55ad687dada6 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 1 May 2023 03:43:25 -0700 Subject: Fix some debug message length limit checks --- al/debug.cpp | 11 +++++++---- alc/context.cpp | 11 +++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) (limited to 'alc/context.cpp') diff --git a/al/debug.cpp b/al/debug.cpp index 26a69aff..66cbc622 100644 --- a/al/debug.cpp +++ b/al/debug.cpp @@ -134,15 +134,18 @@ FORCE_ALIGN void AL_APIENTRY alDebugMessageInsertSOFT(ALenum source, ALenum type if(!message) return context->setError(AL_INVALID_VALUE, "Null message pointer"); + /* MaxDebugMessageLength is the size including the null terminator, + * does not include the null terminator. + */ if(length < 0) { size_t newlen{std::strlen(message)}; - if(newlen > MaxDebugMessageLength) UNLIKELY - return context->setError(AL_INVALID_VALUE, "Debug message too long (%zu > %d)", newlen, - MaxDebugMessageLength); + if(newlen >= MaxDebugMessageLength) UNLIKELY + return context->setError(AL_INVALID_VALUE, "Debug message too long (%zu >= %d)", + newlen, MaxDebugMessageLength); length = static_cast(newlen); } - else if(length > MaxDebugMessageLength) UNLIKELY + else if(length >= MaxDebugMessageLength) UNLIKELY return context->setError(AL_INVALID_VALUE, "Debug message too long (%d > %d)", length, MaxDebugMessageLength); diff --git a/alc/context.cpp b/alc/context.cpp index d4019bc9..bb4930ee 100644 --- a/alc/context.cpp +++ b/alc/context.cpp @@ -308,19 +308,22 @@ void ALCcontext::sendDebugMessage(DebugSource source, DebugType type, ALuint id, { static_assert(DebugSeverityBase+DebugSeverityCount <= 32, "Too many debug bits"); + /* MaxDebugMessageLength is the size including the null terminator, + * does not include the null terminator. + */ if(length < 0) { size_t newlen{std::strlen(message)}; - if(newlen > MaxDebugMessageLength) UNLIKELY + if(newlen >= MaxDebugMessageLength) UNLIKELY { - ERR("Debug message too long (%zu > %d)\n", newlen, MaxDebugMessageLength); + ERR("Debug message too long (%zu >= %d)\n", newlen, MaxDebugMessageLength); return; } length = static_cast(newlen); } - else if(length > MaxDebugMessageLength) UNLIKELY + else if(length >= MaxDebugMessageLength) UNLIKELY { - ERR("Debug message too long (%d > %d)\n", length, MaxDebugMessageLength); + ERR("Debug message too long (%d >= %d)\n", length, MaxDebugMessageLength); return; } -- cgit v1.2.3 From 89f67ad6f9878ecfb48b49ce0dd69b9ecb065d0b Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 1 May 2023 14:46:26 -0700 Subject: Use a 64-bit value for tracking ID filters --- al/debug.cpp | 29 +++++++++-------------------- alc/context.cpp | 23 +++++++++-------------- alc/context.h | 2 +- 3 files changed, 19 insertions(+), 35 deletions(-) (limited to 'alc/context.cpp') diff --git a/al/debug.cpp b/al/debug.cpp index 66cbc622..70c7c4db 100644 --- a/al/debug.cpp +++ b/al/debug.cpp @@ -224,29 +224,18 @@ FORCE_ALIGN void AL_APIENTRY alDebugMessageControlSOFT(ALenum source, ALenum typ std::lock_guard _{context->mDebugCbLock}; if(count > 0) { - const uint filter{(1u<(count))) { - if(!enable) - { - auto &idfilters = context->mDebugIdFilters[id]; - auto iter = std::lower_bound(idfilters.cbegin(), idfilters.cend(), filter); - if(iter == idfilters.cend() || *iter != filter) - idfilters.insert(iter, filter); - continue; - } - - auto iditer = context->mDebugIdFilters.find(id); - if(iditer == context->mDebugIdFilters.end()) - continue; - auto iter = std::lower_bound(iditer->second.cbegin(), iditer->second.cend(), filter); - if(iter != iditer->second.cend() && *iter == filter) - { - iditer->second.erase(iter); - if(iditer->second.empty()) - context->mDebugIdFilters.erase(iditer); - } + const uint64_t filter{filterbase | (uint64_t{id} << 32)}; + + auto iter = std::lower_bound(context->mDebugIdFilters.cbegin(), + context->mDebugIdFilters.cend(), filter); + if(!enable && (iter == context->mDebugIdFilters.cend() || *iter != filter)) + context->mDebugIdFilters.insert(iter, filter); + else if(enable && iter != context->mDebugIdFilters.cend() && *iter == filter) + context->mDebugIdFilters.erase(iter); } } else diff --git a/alc/context.cpp b/alc/context.cpp index bb4930ee..7d10a91d 100644 --- a/alc/context.cpp +++ b/alc/context.cpp @@ -369,21 +369,16 @@ void ALCcontext::sendDebugMessage(DebugSource source, DebugType type, ALuint id, throw std::runtime_error{"Unexpected debug severity value "+std::to_string(al::to_underlying(severity))}; }; - auto iditer = mDebugIdFilters.find(id); - if(iditer != mDebugIdFilters.end()) - { - const uint filter{(1u<<(DebugSourceBase+al::to_underlying(source))) - | (1u<<(DebugTypeBase+al::to_underlying(type)))}; - - auto iter = std::lower_bound(iditer->second.cbegin(), iditer->second.cend(), filter); - if(iter != iditer->second.cend() && *iter == filter) - return; - } - - const uint filter{(1u<<(DebugSourceBase+al::to_underlying(source))) - | (1u<<(DebugTypeBase+al::to_underlying(type))) - | (1u<<(DebugSeverityBase+al::to_underlying(severity)))}; + const uint64_t idfilter{(1_u64 << (DebugSourceBase+al::to_underlying(source))) + | (1_u64 << (DebugTypeBase+al::to_underlying(type))) + | (uint64_t{id} << 32)}; + auto iditer = std::lower_bound(mDebugIdFilters.cbegin(), mDebugIdFilters.cend(), idfilter); + if(iditer != mDebugIdFilters.cend() && *iditer == idfilter) + return; + const uint filter{(1u << (DebugSourceBase+al::to_underlying(source))) + | (1u << (DebugTypeBase+al::to_underlying(type))) + | (1u << (DebugSeverityBase+al::to_underlying(severity)))}; auto iter = std::lower_bound(mDebugFilters.cbegin(), mDebugFilters.cend(), filter); if(iter != mDebugFilters.cend() && *iter == filter) return; diff --git a/alc/context.h b/alc/context.h index c626160b..b3f548c8 100644 --- a/alc/context.h +++ b/alc/context.h @@ -146,7 +146,7 @@ struct ALCcontext : public al::intrusive_ref, ContextBase { ALDEBUGPROCSOFT mDebugCb{}; void *mDebugParam{nullptr}; std::vector mDebugFilters; - std::unordered_map> mDebugIdFilters; + std::vector mDebugIdFilters; std::deque mDebugLog; ALlistener mListener{}; -- cgit v1.2.3 From bb08a416f1b0e31292b896f2f8845e365daee6b1 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 1 May 2023 17:11:49 -0700 Subject: Put the debug filters into a group --- al/debug.cpp | 26 +++++++++++----------- al/debug.h | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ al/error.cpp | 1 + alc/alc.cpp | 1 + alc/context.cpp | 10 +++++---- alc/context.h | 60 +++++++------------------------------------------ 6 files changed, 98 insertions(+), 69 deletions(-) (limited to 'alc/context.cpp') diff --git a/al/debug.cpp b/al/debug.cpp index 70c7c4db..fc893490 100644 --- a/al/debug.cpp +++ b/al/debug.cpp @@ -222,6 +222,7 @@ FORCE_ALIGN void AL_APIENTRY alDebugMessageControlSOFT(ALenum source, ALenum typ } std::lock_guard _{context->mDebugCbLock}; + DebugGroup &debug = context->mDebugGroups.back(); if(count > 0) { const uint filterbase{(1u<mDebugIdFilters.cbegin(), - context->mDebugIdFilters.cend(), filter); - if(!enable && (iter == context->mDebugIdFilters.cend() || *iter != filter)) - context->mDebugIdFilters.insert(iter, filter); - else if(enable && iter != context->mDebugIdFilters.cend() && *iter == filter) - context->mDebugIdFilters.erase(iter); + auto iter = std::lower_bound(debug.mIdFilters.cbegin(), debug.mIdFilters.cend(), + filter); + if(!enable && (iter == debug.mIdFilters.cend() || *iter != filter)) + debug.mIdFilters.insert(iter, filter); + else if(enable && iter != debug.mIdFilters.cend() && *iter == filter) + debug.mIdFilters.erase(iter); } } else { - auto apply_filter = [enable,&context](const uint filter) + auto apply_filter = [enable,&debug](const uint filter) { - auto iter = std::lower_bound(context->mDebugFilters.cbegin(), - context->mDebugFilters.cend(), filter); - if(!enable && (iter == context->mDebugFilters.cend() || *iter != filter)) - context->mDebugFilters.insert(iter, filter); - else if(enable && iter != context->mDebugFilters.cend() && *iter == filter) - context->mDebugFilters.erase(iter); + auto iter = std::lower_bound(debug.mFilters.cbegin(), debug.mFilters.cend(), filter); + if(!enable && (iter == debug.mFilters.cend() || *iter != filter)) + debug.mFilters.insert(iter, filter); + else if(enable && iter != debug.mFilters.cend() && *iter == filter) + debug.mFilters.erase(iter); }; auto apply_severity = [apply_filter,svrIndices](const uint filter) { diff --git a/al/debug.h b/al/debug.h index 23b0ca1b..c2147cf4 100644 --- a/al/debug.h +++ b/al/debug.h @@ -2,6 +2,10 @@ #define AL_DEBUG_H #include +#include +#include + +using uint = unsigned int; /* Somewhat arbitrary. Avoid letting it get out of control if the app enables @@ -10,4 +14,69 @@ constexpr uint8_t MaxDebugLoggedMessages{64}; constexpr uint16_t MaxDebugMessageLength{1024}; + +constexpr uint DebugSourceBase{0}; +enum class DebugSource : uint8_t { + API = 0, + System, + ThirdParty, + Application, + Other, +}; +constexpr uint DebugSourceCount{5}; + +constexpr uint DebugTypeBase{DebugSourceBase + DebugSourceCount}; +enum class DebugType : uint8_t { + Error = 0, + DeprecatedBehavior, + UndefinedBehavior, + Portability, + Performance, + Marker, + Other, +}; +constexpr uint DebugTypeCount{7}; + +constexpr uint DebugSeverityBase{DebugTypeBase + DebugTypeCount}; +enum class DebugSeverity : uint8_t { + High = 0, + Medium, + Low, + Notification, +}; +constexpr uint DebugSeverityCount{4}; + +struct DebugGroup { + const uint mId; + const DebugSource mSource; + std::string mMessage; + std::vector mFilters; + std::vector mIdFilters; + + template + DebugGroup(DebugSource source, uint id, T&& message) + : mId{id}, mSource{source}, mMessage{std::forward(message)} + { } + DebugGroup(const DebugGroup&) = default; + DebugGroup(DebugGroup&&) = default; +}; + + +struct DebugLogEntry { + const DebugSource mSource; + const DebugType mType; + const DebugSeverity mSeverity; + const uint mId; + + std::string mMessage; + + template + DebugLogEntry(DebugSource source, DebugType type, uint id, DebugSeverity severity, T&& message) + : mSource{source}, mType{type}, mSeverity{severity}, mId{id} + , mMessage{std::forward(message)} + { } + DebugLogEntry(const DebugLogEntry&) = default; + DebugLogEntry(DebugLogEntry&&) = default; +}; + #endif /* AL_DEBUG_H */ diff --git a/al/error.cpp b/al/error.cpp index 70081a2e..39fd9f0a 100644 --- a/al/error.cpp +++ b/al/error.cpp @@ -35,6 +35,7 @@ #include "AL/al.h" #include "AL/alc.h" +#include "al/debug.h" #include "alc/context.h" #include "almalloc.h" #include "core/except.h" diff --git a/alc/alc.cpp b/alc/alc.cpp index 63654b1a..aa65222c 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -61,6 +61,7 @@ #include "al/auxeffectslot.h" #include "al/buffer.h" +#include "al/debug.h" #include "al/effect.h" #include "al/filter.h" #include "al/listener.h" diff --git a/alc/context.cpp b/alc/context.cpp index 7d10a91d..755a1e41 100644 --- a/alc/context.cpp +++ b/alc/context.cpp @@ -122,6 +122,7 @@ void ALCcontext::setThreadContext(ALCcontext *context) noexcept ALCcontext::ALCcontext(al::intrusive_ptr device) : ContextBase{device.get()}, mALDevice{std::move(device)} { + mDebugGroups.emplace_back(DebugSource::Other, 0, std::string{}); } ALCcontext::~ALCcontext() @@ -328,6 +329,7 @@ void ALCcontext::sendDebugMessage(DebugSource source, DebugType type, ALuint id, } std::unique_lock debuglock{mDebugCbLock}; + DebugGroup &debug = mDebugGroups.back(); if(!mDebugEnabled.load()) UNLIKELY return; @@ -372,15 +374,15 @@ void ALCcontext::sendDebugMessage(DebugSource source, DebugType type, ALuint id, const uint64_t idfilter{(1_u64 << (DebugSourceBase+al::to_underlying(source))) | (1_u64 << (DebugTypeBase+al::to_underlying(type))) | (uint64_t{id} << 32)}; - auto iditer = std::lower_bound(mDebugIdFilters.cbegin(), mDebugIdFilters.cend(), idfilter); - if(iditer != mDebugIdFilters.cend() && *iditer == idfilter) + auto iditer = std::lower_bound(debug.mIdFilters.cbegin(), debug.mIdFilters.cend(), idfilter); + if(iditer != debug.mIdFilters.cend() && *iditer == idfilter) return; const uint filter{(1u << (DebugSourceBase+al::to_underlying(source))) | (1u << (DebugTypeBase+al::to_underlying(type))) | (1u << (DebugSeverityBase+al::to_underlying(severity)))}; - auto iter = std::lower_bound(mDebugFilters.cbegin(), mDebugFilters.cend(), filter); - if(iter != mDebugFilters.cend() && *iter == filter) + auto iter = std::lower_bound(debug.mFilters.cbegin(), debug.mFilters.cend(), filter); + if(iter != debug.mFilters.cend() && *iter == filter) return; if(mDebugCb) diff --git a/alc/context.h b/alc/context.h index b3f548c8..3e31c9b8 100644 --- a/alc/context.h +++ b/alc/context.h @@ -33,57 +33,14 @@ struct ALeffect; struct ALeffectslot; struct ALsource; +struct DebugGroup; +struct DebugLogEntry; -using uint = unsigned int; - +enum class DebugSource : uint8_t; +enum class DebugType : uint8_t; +enum class DebugSeverity : uint8_t; -constexpr uint DebugSourceBase{0}; -enum class DebugSource : uint8_t { - API = 0, - System, - ThirdParty, - Application, - Other, -}; -constexpr uint DebugSourceCount{5}; - -constexpr uint DebugTypeBase{DebugSourceBase + DebugSourceCount}; -enum class DebugType : uint8_t { - Error = 0, - DeprecatedBehavior, - UndefinedBehavior, - Portability, - Performance, - Marker, - Other, -}; -constexpr uint DebugTypeCount{7}; - -constexpr uint DebugSeverityBase{DebugTypeBase + DebugTypeCount}; -enum class DebugSeverity : uint8_t { - High = 0, - Medium, - Low, - Notification, -}; -constexpr uint DebugSeverityCount{4}; - -struct LogEntry { - const DebugSource mSource; - const DebugType mType; - const DebugSeverity mSeverity; - const uint mId; - - std::string mMessage; - - template - LogEntry(DebugSource source, DebugType type, uint id, DebugSeverity severity, T&& message) - : mSource{source}, mType{type}, mSeverity{severity}, mId{id} - , mMessage{std::forward(message)} - { } - LogEntry(const LogEntry&) = default; - LogEntry(LogEntry&&) = default; -}; +using uint = unsigned int; struct SourceSubList { @@ -145,9 +102,8 @@ struct ALCcontext : public al::intrusive_ref, ContextBase { std::mutex mDebugCbLock; ALDEBUGPROCSOFT mDebugCb{}; void *mDebugParam{nullptr}; - std::vector mDebugFilters; - std::vector mDebugIdFilters; - std::deque mDebugLog; + std::vector mDebugGroups; + std::deque mDebugLog; ALlistener mListener{}; -- cgit v1.2.3 From e1b573284b649c6fef42ab5b6ca51978c4a1329a Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 1 May 2023 19:11:26 -0700 Subject: Implement pushing/popping debug groups --- al/debug.cpp | 145 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- al/debug.h | 5 +- al/state.cpp | 23 +++++++++ alc/alc.cpp | 7 +++ alc/context.cpp | 105 ---------------------------------------- alc/context.h | 7 +-- alc/inprogext.h | 27 +++++++---- 7 files changed, 197 insertions(+), 122 deletions(-) (limited to 'alc/context.cpp') diff --git a/al/debug.cpp b/al/debug.cpp index fc893490..2dd0e7c7 100644 --- a/al/debug.cpp +++ b/al/debug.cpp @@ -17,12 +17,15 @@ #include "alc/inprogext.h" #include "aloptional.h" #include "alspan.h" +#include "core/logging.h" #include "opthelpers.h" #include "threads.h" namespace { +static_assert(DebugSeverityBase+DebugSeverityCount <= 32, "Too many debug bits"); + template constexpr auto make_array(std::integer_sequence) { return std::array{Vals...}; } @@ -55,6 +58,8 @@ constexpr al::optional GetDebugType(ALenum type) noexcept case AL_DEBUG_TYPE_PORTABILITY_SOFT: return DebugType::Portability; case AL_DEBUG_TYPE_PERFORMANCE_SOFT: return DebugType::Performance; case AL_DEBUG_TYPE_MARKER_SOFT: return DebugType::Marker; + case AL_DEBUG_TYPE_PUSH_GROUP_SOFT: return DebugType::PushGroup; + case AL_DEBUG_TYPE_POP_GROUP_SOFT: return DebugType::PopGroup; case AL_DEBUG_TYPE_OTHER_SOFT: return DebugType::Other; } return al::nullopt; @@ -72,7 +77,6 @@ constexpr al::optional GetDebugSeverity(ALenum severity) noexcept return al::nullopt; } -} // namespace ALenum GetDebugSourceEnum(DebugSource source) { @@ -97,6 +101,8 @@ ALenum GetDebugTypeEnum(DebugType type) case DebugType::Portability: return AL_DEBUG_TYPE_PORTABILITY_SOFT; case DebugType::Performance: return AL_DEBUG_TYPE_PERFORMANCE_SOFT; case DebugType::Marker: return AL_DEBUG_TYPE_MARKER_SOFT; + case DebugType::PushGroup: return AL_DEBUG_TYPE_PUSH_GROUP_SOFT; + case DebugType::PopGroup: return AL_DEBUG_TYPE_POP_GROUP_SOFT; case DebugType::Other: return AL_DEBUG_TYPE_OTHER_SOFT; } throw std::runtime_error{"Unexpected debug type value "+std::to_string(al::to_underlying(type))}; @@ -114,6 +120,74 @@ ALenum GetDebugSeverityEnum(DebugSeverity severity) throw std::runtime_error{"Unexpected debug severity value "+std::to_string(al::to_underlying(severity))}; } +} // namespace + + +void ALCcontext::sendDebugMessage(std::unique_lock &debuglock, DebugSource source, + DebugType type, ALuint id, DebugSeverity severity, ALsizei length, const char *message) +{ + if(!mDebugEnabled.load()) UNLIKELY + return; + + /* MaxDebugMessageLength is the size including the null terminator, + * does not include the null terminator. + */ + 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(newlen); + } + else if(length >= MaxDebugMessageLength) UNLIKELY + { + ERR("Debug message too long (%d >= %d)\n", length, MaxDebugMessageLength); + return; + } + + DebugGroup &debug = mDebugGroups.back(); + + const uint64_t idfilter{(1_u64 << (DebugSourceBase+al::to_underlying(source))) + | (1_u64 << (DebugTypeBase+al::to_underlying(type))) + | (uint64_t{id} << 32)}; + auto iditer = std::lower_bound(debug.mIdFilters.cbegin(), debug.mIdFilters.cend(), idfilter); + if(iditer != debug.mIdFilters.cend() && *iditer == idfilter) + return; + + const uint filter{(1u << (DebugSourceBase+al::to_underlying(source))) + | (1u << (DebugTypeBase+al::to_underlying(type))) + | (1u << (DebugSeverityBase+al::to_underlying(severity)))}; + auto iter = std::lower_bound(debug.mFilters.cbegin(), debug.mFilters.cend(), filter); + if(iter != debug.mFilters.cend() && *iter == filter) + return; + + if(mDebugCb) + { + auto callback = mDebugCb; + auto param = mDebugParam; + debuglock.unlock(); + callback(GetDebugSourceEnum(source), GetDebugTypeEnum(type), id, + GetDebugSeverityEnum(severity), length, message, param); + } + else + { + 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", + GetDebugSourceEnum(source), GetDebugTypeEnum(type), id, + GetDebugSeverityEnum(severity), message); + } +} + FORCE_ALIGN void AL_APIENTRY alDebugMessageCallbackSOFT(ALDEBUGPROCSOFT callback, void *userParam) noexcept { @@ -134,9 +208,6 @@ FORCE_ALIGN void AL_APIENTRY alDebugMessageInsertSOFT(ALenum source, ALenum type if(!message) return context->setError(AL_INVALID_VALUE, "Null message pointer"); - /* MaxDebugMessageLength is the size including the null terminator, - * does not include the null terminator. - */ if(length < 0) { size_t newlen{std::strlen(message)}; @@ -265,6 +336,72 @@ FORCE_ALIGN void AL_APIENTRY alDebugMessageControlSOFT(ALenum source, ALenum typ } +FORCE_ALIGN void AL_APIENTRY alPushDebugGroupSOFT(ALenum source, ALuint id, ALsizei length, const ALchar *message) noexcept +{ + ContextRef context{GetContextRef()}; + if(!context) UNLIKELY return; + + if(length < 0) + { + size_t newlen{std::strlen(message)}; + if(newlen >= MaxDebugMessageLength) UNLIKELY + return context->setError(AL_INVALID_VALUE, "Debug message too long (%zu >= %d)", + newlen, MaxDebugMessageLength); + length = static_cast(newlen); + } + else if(length >= MaxDebugMessageLength) UNLIKELY + return context->setError(AL_INVALID_VALUE, "Debug message too long (%d > %d)", length, + MaxDebugMessageLength); + + auto dsource = GetDebugSource(source); + if(!dsource) + return context->setError(AL_INVALID_ENUM, "Invalid debug source 0x%04x", source); + if(*dsource != DebugSource::ThirdParty && *dsource != DebugSource::Application) + return context->setError(AL_INVALID_ENUM, "Debug source 0x%04x not allowed", source); + + std::unique_lock debuglock{context->mDebugCbLock}; + if(context->mDebugGroups.size() >= MaxDebugGroupDepth) + { + debuglock.unlock(); + return context->setError(AL_STACK_OVERFLOW_SOFT, "Pushing too many debug groups"); + } + + context->mDebugGroups.emplace_back(*dsource, id, message); + auto &oldback = *(context->mDebugGroups.end()-2); + auto &newback = context->mDebugGroups.back(); + + newback.mFilters = oldback.mFilters; + newback.mIdFilters = oldback.mIdFilters; + + context->sendDebugMessage(debuglock, newback.mSource, DebugType::PushGroup, newback.mId, + DebugSeverity::Notification, static_cast(newback.mMessage.size()), + newback.mMessage.data()); +} + +FORCE_ALIGN void AL_APIENTRY alPopDebugGroupSOFT(void) noexcept +{ + ContextRef context{GetContextRef()}; + if(!context) UNLIKELY return; + + std::unique_lock debuglock{context->mDebugCbLock}; + if(context->mDebugGroups.size() <= 1) + { + debuglock.unlock(); + return context->setError(AL_STACK_UNDERFLOW_SOFT, + "Attempting to pop the default debug group"); + } + + DebugGroup &debug = context->mDebugGroups.back(); + const auto source = debug.mSource; + const auto id = debug.mId; + std::string message{std::move(debug.mMessage)}; + + context->mDebugGroups.pop_back(); + context->sendDebugMessage(debuglock, source, DebugType::PopGroup, id, + DebugSeverity::Notification, static_cast(message.size()), message.data()); +} + + FORCE_ALIGN ALuint AL_APIENTRY alGetDebugMessageLogSOFT(ALuint count, ALsizei logBufSize, ALenum *sources, ALenum *types, ALuint *ids, ALenum *severities, ALsizei *lengths, ALchar *logBuf) noexcept diff --git a/al/debug.h b/al/debug.h index c2147cf4..8f83fd5e 100644 --- a/al/debug.h +++ b/al/debug.h @@ -13,6 +13,7 @@ using uint = unsigned int; */ constexpr uint8_t MaxDebugLoggedMessages{64}; constexpr uint16_t MaxDebugMessageLength{1024}; +constexpr uint8_t MaxDebugGroupDepth{64}; constexpr uint DebugSourceBase{0}; @@ -33,9 +34,11 @@ enum class DebugType : uint8_t { Portability, Performance, Marker, + PushGroup, + PopGroup, Other, }; -constexpr uint DebugTypeCount{7}; +constexpr uint DebugTypeCount{9}; constexpr uint DebugSeverityBase{DebugTypeBase + DebugTypeCount}; enum class DebugSeverity : uint8_t { diff --git a/al/state.cpp b/al/state.cpp index 1e1a0085..2a350646 100644 --- a/al/state.cpp +++ b/al/state.cpp @@ -69,6 +69,8 @@ constexpr ALchar alErrInvalidEnum[] = "Invalid Enum"; constexpr ALchar alErrInvalidValue[] = "Invalid Value"; constexpr ALchar alErrInvalidOp[] = "Invalid Operation"; constexpr ALchar alErrOutOfMemory[] = "Out of Memory"; +constexpr ALchar alStackOverflow[] = "Stack Overflow"; +constexpr ALchar alStackUnderflow[] = "Stack Underflow"; /* Resampler strings */ template struct ResamplerName { }; @@ -264,6 +266,7 @@ START_API_FUNC case AL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_SOFT: case AL_MAX_DEBUG_MESSAGE_LENGTH_SOFT: case AL_MAX_DEBUG_LOGGED_MESSAGES_SOFT: + case AL_MAX_DEBUG_GROUP_STACK_DEPTH_SOFT: return alGetInteger(pname) != 0; } @@ -308,6 +311,7 @@ START_API_FUNC case AL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_SOFT: case AL_MAX_DEBUG_MESSAGE_LENGTH_SOFT: case AL_MAX_DEBUG_LOGGED_MESSAGES_SOFT: + case AL_MAX_DEBUG_GROUP_STACK_DEPTH_SOFT: return alGetInteger(pname); } @@ -338,6 +342,7 @@ START_API_FUNC case AL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_SOFT: case AL_MAX_DEBUG_MESSAGE_LENGTH_SOFT: case AL_MAX_DEBUG_LOGGED_MESSAGES_SOFT: + case AL_MAX_DEBUG_GROUP_STACK_DEPTH_SOFT: return static_cast(alGetInteger(pname)); case AL_DEFERRED_UPDATES_SOFT: @@ -436,6 +441,10 @@ START_API_FUNC value = MaxDebugLoggedMessages; break; + case AL_MAX_DEBUG_GROUP_STACK_DEPTH_SOFT: + value = MaxDebugGroupDepth; + break; + #ifdef ALSOFT_EAX #define EAX_ERROR "[alGetInteger] EAX not enabled." @@ -491,6 +500,7 @@ START_API_FUNC case AL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_SOFT: case AL_MAX_DEBUG_MESSAGE_LENGTH_SOFT: case AL_MAX_DEBUG_LOGGED_MESSAGES_SOFT: + case AL_MAX_DEBUG_GROUP_STACK_DEPTH_SOFT: return alGetInteger(pname); } @@ -562,6 +572,7 @@ START_API_FUNC case AL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_SOFT: case AL_MAX_DEBUG_MESSAGE_LENGTH_SOFT: case AL_MAX_DEBUG_LOGGED_MESSAGES_SOFT: + case AL_MAX_DEBUG_GROUP_STACK_DEPTH_SOFT: values[0] = alGetBoolean(pname); return; } @@ -599,6 +610,7 @@ START_API_FUNC case AL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_SOFT: case AL_MAX_DEBUG_MESSAGE_LENGTH_SOFT: case AL_MAX_DEBUG_LOGGED_MESSAGES_SOFT: + case AL_MAX_DEBUG_GROUP_STACK_DEPTH_SOFT: values[0] = alGetDouble(pname); return; } @@ -636,6 +648,7 @@ START_API_FUNC case AL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_SOFT: case AL_MAX_DEBUG_MESSAGE_LENGTH_SOFT: case AL_MAX_DEBUG_LOGGED_MESSAGES_SOFT: + case AL_MAX_DEBUG_GROUP_STACK_DEPTH_SOFT: values[0] = alGetFloat(pname); return; } @@ -673,6 +686,7 @@ START_API_FUNC case AL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_SOFT: case AL_MAX_DEBUG_MESSAGE_LENGTH_SOFT: case AL_MAX_DEBUG_LOGGED_MESSAGES_SOFT: + case AL_MAX_DEBUG_GROUP_STACK_DEPTH_SOFT: values[0] = alGetInteger(pname); return; } @@ -710,6 +724,7 @@ START_API_FUNC case AL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_SOFT: case AL_MAX_DEBUG_MESSAGE_LENGTH_SOFT: case AL_MAX_DEBUG_LOGGED_MESSAGES_SOFT: + case AL_MAX_DEBUG_GROUP_STACK_DEPTH_SOFT: values[0] = alGetInteger64SOFT(pname); return; } @@ -806,6 +821,14 @@ START_API_FUNC value = alErrOutOfMemory; break; + case AL_STACK_OVERFLOW_SOFT: + value = alStackOverflow; + break; + + case AL_STACK_UNDERFLOW_SOFT: + value = alStackUnderflow; + break; + default: context->setError(AL_INVALID_VALUE, "Invalid string property 0x%04x", pname); } diff --git a/alc/alc.cpp b/alc/alc.cpp index aa65222c..50982ed2 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -464,6 +464,8 @@ const struct { DECL(alDebugMessageCallbackSOFT), DECL(alDebugMessageInsertSOFT), DECL(alDebugMessageControlSOFT), + DECL(alPushDebugGroupSOFT), + DECL(alPopDebugGroupSOFT), DECL(alGetDebugMessageLogSOFT), #ifdef ALSOFT_EAX }, eaxFunctions[] = { @@ -936,6 +938,8 @@ constexpr struct { DECL(AL_DEBUG_TYPE_PORTABILITY_SOFT), DECL(AL_DEBUG_TYPE_PERFORMANCE_SOFT), DECL(AL_DEBUG_TYPE_MARKER_SOFT), + DECL(AL_DEBUG_TYPE_PUSH_GROUP_SOFT), + DECL(AL_DEBUG_TYPE_POP_GROUP_SOFT), DECL(AL_DEBUG_TYPE_OTHER_SOFT), DECL(AL_DEBUG_SEVERITY_HIGH_SOFT), DECL(AL_DEBUG_SEVERITY_MEDIUM_SOFT), @@ -945,6 +949,9 @@ constexpr struct { DECL(AL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_SOFT), DECL(AL_MAX_DEBUG_MESSAGE_LENGTH_SOFT), DECL(AL_MAX_DEBUG_LOGGED_MESSAGES_SOFT), + DECL(AL_MAX_DEBUG_GROUP_STACK_DEPTH_SOFT), + DECL(AL_STACK_OVERFLOW_SOFT), + DECL(AL_STACK_UNDERFLOW_SOFT), DECL(AL_STOP_SOURCES_ON_DISCONNECT_SOFT), diff --git a/alc/context.cpp b/alc/context.cpp index 755a1e41..0c8253fb 100644 --- a/alc/context.cpp +++ b/alc/context.cpp @@ -304,111 +304,6 @@ void ALCcontext::applyAllUpdates() } -void ALCcontext::sendDebugMessage(DebugSource source, DebugType type, ALuint id, - DebugSeverity severity, ALsizei length, const char *message) -{ - static_assert(DebugSeverityBase+DebugSeverityCount <= 32, "Too many debug bits"); - - /* MaxDebugMessageLength is the size including the null terminator, - * does not include the null terminator. - */ - 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(newlen); - } - else if(length >= MaxDebugMessageLength) UNLIKELY - { - ERR("Debug message too long (%d >= %d)\n", length, MaxDebugMessageLength); - return; - } - - std::unique_lock debuglock{mDebugCbLock}; - DebugGroup &debug = mDebugGroups.back(); - if(!mDebugEnabled.load()) UNLIKELY - return; - - auto get_source_enum = [source]() - { - switch(source) - { - case DebugSource::API: return AL_DEBUG_SOURCE_API_SOFT; - case DebugSource::System: return AL_DEBUG_SOURCE_AUDIO_SYSTEM_SOFT; - case DebugSource::ThirdParty: return AL_DEBUG_SOURCE_THIRD_PARTY_SOFT; - case DebugSource::Application: return AL_DEBUG_SOURCE_APPLICATION_SOFT; - case DebugSource::Other: return AL_DEBUG_SOURCE_OTHER_SOFT; - } - throw std::runtime_error{"Unexpected debug source value "+std::to_string(al::to_underlying(source))}; - }; - auto get_type_enum = [type]() - { - switch(type) - { - case DebugType::Error: return AL_DEBUG_TYPE_ERROR_SOFT; - case DebugType::DeprecatedBehavior: return AL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_SOFT; - case DebugType::UndefinedBehavior: return AL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_SOFT; - case DebugType::Portability: return AL_DEBUG_TYPE_PORTABILITY_SOFT; - case DebugType::Performance: return AL_DEBUG_TYPE_PERFORMANCE_SOFT; - case DebugType::Marker: return AL_DEBUG_TYPE_MARKER_SOFT; - case DebugType::Other: return AL_DEBUG_TYPE_OTHER_SOFT; - } - throw std::runtime_error{"Unexpected debug type value "+std::to_string(al::to_underlying(type))}; - }; - auto get_severity_enum = [severity]() - { - switch(severity) - { - case DebugSeverity::High: return AL_DEBUG_SEVERITY_HIGH_SOFT; - case DebugSeverity::Medium: return AL_DEBUG_SEVERITY_MEDIUM_SOFT; - case DebugSeverity::Low: return AL_DEBUG_SEVERITY_LOW_SOFT; - case DebugSeverity::Notification: return AL_DEBUG_SEVERITY_NOTIFICATION_SOFT; - } - throw std::runtime_error{"Unexpected debug severity value "+std::to_string(al::to_underlying(severity))}; - }; - - const uint64_t idfilter{(1_u64 << (DebugSourceBase+al::to_underlying(source))) - | (1_u64 << (DebugTypeBase+al::to_underlying(type))) - | (uint64_t{id} << 32)}; - auto iditer = std::lower_bound(debug.mIdFilters.cbegin(), debug.mIdFilters.cend(), idfilter); - if(iditer != debug.mIdFilters.cend() && *iditer == idfilter) - return; - - const uint filter{(1u << (DebugSourceBase+al::to_underlying(source))) - | (1u << (DebugTypeBase+al::to_underlying(type))) - | (1u << (DebugSeverityBase+al::to_underlying(severity)))}; - auto iter = std::lower_bound(debug.mFilters.cbegin(), debug.mFilters.cend(), filter); - if(iter != debug.mFilters.cend() && *iter == filter) - return; - - if(mDebugCb) - { - auto callback = mDebugCb; - auto param = mDebugParam; - debuglock.unlock(); - callback(get_source_enum(), get_type_enum(), id, get_severity_enum(), length, message, - param); - } - else - { - 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(), get_type_enum(), id, get_severity_enum(), message); - } -} - - #ifdef ALSOFT_EAX namespace { diff --git a/alc/context.h b/alc/context.h index 3e31c9b8..8757b041 100644 --- a/alc/context.h +++ b/alc/context.h @@ -166,15 +166,16 @@ struct ALCcontext : public al::intrusive_ref, ContextBase { #endif void setError(ALenum errorCode, const char *msg, ...); - void sendDebugMessage(DebugSource source, DebugType type, ALuint id, DebugSeverity severity, - ALsizei length, const char *message); + void sendDebugMessage(std::unique_lock &debuglock, DebugSource source, + DebugType type, ALuint id, DebugSeverity severity, ALsizei length, const char *message); void debugMessage(DebugSource source, DebugType type, ALuint id, DebugSeverity severity, ALsizei length, const char *message) { if(!mDebugEnabled.load(std::memory_order_relaxed)) LIKELY return; - sendDebugMessage(source, type, id, severity, length, message); + std::unique_lock debuglock{mDebugCbLock}; + sendDebugMessage(debuglock, source, type, id, severity, length, message); } /* Process-wide current context */ diff --git a/alc/inprogext.h b/alc/inprogext.h index f73963cb..7f9d7766 100644 --- a/alc/inprogext.h +++ b/alc/inprogext.h @@ -71,25 +71,34 @@ AL_API void AL_APIENTRY alAuxiliaryEffectSlotStopvSOFT(ALsizei n, const ALuint * #define AL_DEBUG_TYPE_PORTABILITY_SOFT 0x19BD #define AL_DEBUG_TYPE_PERFORMANCE_SOFT 0x19BE #define AL_DEBUG_TYPE_MARKER_SOFT 0x19BF -#define AL_DEBUG_TYPE_OTHER_SOFT 0x19C0 -#define AL_DEBUG_SEVERITY_HIGH_SOFT 0x19C1 -#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 +#define AL_DEBUG_TYPE_PUSH_GROUP_SOFT 0x19C0 +#define AL_DEBUG_TYPE_POP_GROUP_SOFT 0x19C1 +#define AL_DEBUG_TYPE_OTHER_SOFT 0x19C2 +#define AL_DEBUG_SEVERITY_HIGH_SOFT 0x19C3 +#define AL_DEBUG_SEVERITY_MEDIUM_SOFT 0x19C4 +#define AL_DEBUG_SEVERITY_LOW_SOFT 0x19C5 +#define AL_DEBUG_SEVERITY_NOTIFICATION_SOFT 0x19C6 +#define AL_DEBUG_LOGGED_MESSAGES_SOFT 0x19C7 +#define AL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_SOFT 0x19C8 +#define AL_MAX_DEBUG_MESSAGE_LENGTH_SOFT 0x19C9 +#define AL_MAX_DEBUG_LOGGED_MESSAGES_SOFT 0x19CA +#define AL_MAX_DEBUG_GROUP_STACK_DEPTH_SOFT 0x19CB +#define AL_STACK_OVERFLOW_SOFT 0x19CC +#define AL_STACK_UNDERFLOW_SOFT 0x19CD 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 void (AL_APIENTRY*LPALPUSHDEBUGGROUPSOFT)(ALenum source, ALuint id, ALsizei length, const ALchar *message); +typedef void (AL_APIENTRY*LPALPOPDEBUGGROUPSOFT)(void); 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; +void AL_APIENTRY alPushDebugGroupSOFT(ALenum source, ALuint id, ALsizei length, const ALchar *message) noexcept; +void AL_APIENTRY alPopDebugGroupSOFT(void) noexcept; ALuint AL_APIENTRY alGetDebugMessageLogSOFT(ALuint count, ALsizei logBufSize, ALenum *sources, ALenum *types, ALuint *ids, ALenum *severities, ALsizei *lengths, ALchar *logBuf) noexcept; #endif #endif -- cgit v1.2.3 From 4739b77b8a20800b24b6187dca9aedca5fac367b Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Wed, 3 May 2023 07:03:07 -0700 Subject: Rename AL_SOFT_debug to AL_EXT_DEBUG --- al/debug.cpp | 159 +++++++++++++++++++++++++++++++++++--------------------- al/state.cpp | 34 ++++++------ alc/alc.cpp | 70 ++++++++++++------------- alc/context.cpp | 2 +- alc/context.h | 2 +- alc/inprogext.h | 88 +++++++++++++++---------------- 6 files changed, 199 insertions(+), 156 deletions(-) (limited to 'alc/context.cpp') diff --git a/al/debug.cpp b/al/debug.cpp index 2dd0e7c7..f584da99 100644 --- a/al/debug.cpp +++ b/al/debug.cpp @@ -39,11 +39,11 @@ constexpr al::optional GetDebugSource(ALenum source) noexcept { switch(source) { - case AL_DEBUG_SOURCE_API_SOFT: return DebugSource::API; - case AL_DEBUG_SOURCE_AUDIO_SYSTEM_SOFT: return DebugSource::System; - case AL_DEBUG_SOURCE_THIRD_PARTY_SOFT: return DebugSource::ThirdParty; - case AL_DEBUG_SOURCE_APPLICATION_SOFT: return DebugSource::Application; - case AL_DEBUG_SOURCE_OTHER_SOFT: return DebugSource::Other; + case AL_DEBUG_SOURCE_API_EXT: return DebugSource::API; + case AL_DEBUG_SOURCE_AUDIO_SYSTEM_EXT: return DebugSource::System; + case AL_DEBUG_SOURCE_THIRD_PARTY_EXT: return DebugSource::ThirdParty; + case AL_DEBUG_SOURCE_APPLICATION_EXT: return DebugSource::Application; + case AL_DEBUG_SOURCE_OTHER_EXT: return DebugSource::Other; } return al::nullopt; } @@ -52,15 +52,15 @@ constexpr al::optional GetDebugType(ALenum type) noexcept { switch(type) { - case AL_DEBUG_TYPE_ERROR_SOFT: return DebugType::Error; - case AL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_SOFT: return DebugType::DeprecatedBehavior; - case AL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_SOFT: return DebugType::UndefinedBehavior; - case AL_DEBUG_TYPE_PORTABILITY_SOFT: return DebugType::Portability; - case AL_DEBUG_TYPE_PERFORMANCE_SOFT: return DebugType::Performance; - case AL_DEBUG_TYPE_MARKER_SOFT: return DebugType::Marker; - case AL_DEBUG_TYPE_PUSH_GROUP_SOFT: return DebugType::PushGroup; - case AL_DEBUG_TYPE_POP_GROUP_SOFT: return DebugType::PopGroup; - case AL_DEBUG_TYPE_OTHER_SOFT: return DebugType::Other; + case AL_DEBUG_TYPE_ERROR_EXT: return DebugType::Error; + case AL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_EXT: return DebugType::DeprecatedBehavior; + case AL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_EXT: return DebugType::UndefinedBehavior; + case AL_DEBUG_TYPE_PORTABILITY_EXT: return DebugType::Portability; + case AL_DEBUG_TYPE_PERFORMANCE_EXT: return DebugType::Performance; + case AL_DEBUG_TYPE_MARKER_EXT: return DebugType::Marker; + case AL_DEBUG_TYPE_PUSH_GROUP_EXT: return DebugType::PushGroup; + case AL_DEBUG_TYPE_POP_GROUP_EXT: return DebugType::PopGroup; + case AL_DEBUG_TYPE_OTHER_EXT: return DebugType::Other; } return al::nullopt; } @@ -69,10 +69,10 @@ constexpr al::optional GetDebugSeverity(ALenum severity) noexcept { switch(severity) { - case AL_DEBUG_SEVERITY_HIGH_SOFT: return DebugSeverity::High; - case AL_DEBUG_SEVERITY_MEDIUM_SOFT: return DebugSeverity::Medium; - case AL_DEBUG_SEVERITY_LOW_SOFT: return DebugSeverity::Low; - case AL_DEBUG_SEVERITY_NOTIFICATION_SOFT: return DebugSeverity::Notification; + case AL_DEBUG_SEVERITY_HIGH_EXT: return DebugSeverity::High; + case AL_DEBUG_SEVERITY_MEDIUM_EXT: return DebugSeverity::Medium; + case AL_DEBUG_SEVERITY_LOW_EXT: return DebugSeverity::Low; + case AL_DEBUG_SEVERITY_NOTIFICATION_EXT: return DebugSeverity::Notification; } return al::nullopt; } @@ -82,11 +82,11 @@ ALenum GetDebugSourceEnum(DebugSource source) { switch(source) { - case DebugSource::API: return AL_DEBUG_SOURCE_API_SOFT; - case DebugSource::System: return AL_DEBUG_SOURCE_AUDIO_SYSTEM_SOFT; - case DebugSource::ThirdParty: return AL_DEBUG_SOURCE_THIRD_PARTY_SOFT; - case DebugSource::Application: return AL_DEBUG_SOURCE_APPLICATION_SOFT; - case DebugSource::Other: return AL_DEBUG_SOURCE_OTHER_SOFT; + case DebugSource::API: return AL_DEBUG_SOURCE_API_EXT; + case DebugSource::System: return AL_DEBUG_SOURCE_AUDIO_SYSTEM_EXT; + case DebugSource::ThirdParty: return AL_DEBUG_SOURCE_THIRD_PARTY_EXT; + case DebugSource::Application: return AL_DEBUG_SOURCE_APPLICATION_EXT; + case DebugSource::Other: return AL_DEBUG_SOURCE_OTHER_EXT; } throw std::runtime_error{"Unexpected debug source value "+std::to_string(al::to_underlying(source))}; } @@ -95,15 +95,15 @@ ALenum GetDebugTypeEnum(DebugType type) { switch(type) { - case DebugType::Error: return AL_DEBUG_TYPE_ERROR_SOFT; - case DebugType::DeprecatedBehavior: return AL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_SOFT; - case DebugType::UndefinedBehavior: return AL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_SOFT; - case DebugType::Portability: return AL_DEBUG_TYPE_PORTABILITY_SOFT; - case DebugType::Performance: return AL_DEBUG_TYPE_PERFORMANCE_SOFT; - case DebugType::Marker: return AL_DEBUG_TYPE_MARKER_SOFT; - case DebugType::PushGroup: return AL_DEBUG_TYPE_PUSH_GROUP_SOFT; - case DebugType::PopGroup: return AL_DEBUG_TYPE_POP_GROUP_SOFT; - case DebugType::Other: return AL_DEBUG_TYPE_OTHER_SOFT; + case DebugType::Error: return AL_DEBUG_TYPE_ERROR_EXT; + case DebugType::DeprecatedBehavior: return AL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_EXT; + case DebugType::UndefinedBehavior: return AL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_EXT; + case DebugType::Portability: return AL_DEBUG_TYPE_PORTABILITY_EXT; + case DebugType::Performance: return AL_DEBUG_TYPE_PERFORMANCE_EXT; + case DebugType::Marker: return AL_DEBUG_TYPE_MARKER_EXT; + case DebugType::PushGroup: return AL_DEBUG_TYPE_PUSH_GROUP_EXT; + case DebugType::PopGroup: return AL_DEBUG_TYPE_POP_GROUP_EXT; + case DebugType::Other: return AL_DEBUG_TYPE_OTHER_EXT; } throw std::runtime_error{"Unexpected debug type value "+std::to_string(al::to_underlying(type))}; } @@ -112,14 +112,57 @@ ALenum GetDebugSeverityEnum(DebugSeverity severity) { switch(severity) { - case DebugSeverity::High: return AL_DEBUG_SEVERITY_HIGH_SOFT; - case DebugSeverity::Medium: return AL_DEBUG_SEVERITY_MEDIUM_SOFT; - case DebugSeverity::Low: return AL_DEBUG_SEVERITY_LOW_SOFT; - case DebugSeverity::Notification: return AL_DEBUG_SEVERITY_NOTIFICATION_SOFT; + case DebugSeverity::High: return AL_DEBUG_SEVERITY_HIGH_EXT; + case DebugSeverity::Medium: return AL_DEBUG_SEVERITY_MEDIUM_EXT; + case DebugSeverity::Low: return AL_DEBUG_SEVERITY_LOW_EXT; + case DebugSeverity::Notification: return AL_DEBUG_SEVERITY_NOTIFICATION_EXT; } throw std::runtime_error{"Unexpected debug severity value "+std::to_string(al::to_underlying(severity))}; } + +const char *GetDebugSourceName(DebugSource source) +{ + switch(source) + { + case DebugSource::API: return "API"; + case DebugSource::System: return "Audio System"; + case DebugSource::ThirdParty: return "Third Party"; + case DebugSource::Application: return "Application"; + case DebugSource::Other: return "Other"; + } + return ""; +} + +const char *GetDebugTypeName(DebugType type) +{ + switch(type) + { + case DebugType::Error: return "Error"; + case DebugType::DeprecatedBehavior: return "Deprecated Behavior"; + case DebugType::UndefinedBehavior: return "Undefined Behavior"; + case DebugType::Portability: return "Portability"; + case DebugType::Performance: return "Performance"; + case DebugType::Marker: return "Marker"; + case DebugType::PushGroup: return "Push Group"; + case DebugType::PopGroup: return "Pop Group"; + case DebugType::Other: return "Other"; + } + return ""; +} + +const char *GetDebugSeverityName(DebugSeverity severity) +{ + switch(severity) + { + case DebugSeverity::High: return "High"; + case DebugSeverity::Medium: return "Medium"; + case DebugSeverity::Low: return "Low"; + case DebugSeverity::Notification: return "Notification"; + } + return ""; +} + } // namespace @@ -178,18 +221,18 @@ void ALCcontext::sendDebugMessage(std::unique_lock &debuglock, Debug 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" + " Source: %s\n" + " Type: %s\n" " ID: %u\n" - " Severity: 0x%04x\n" + " Severity: %s\n" " Message: \"%s\"\n", - GetDebugSourceEnum(source), GetDebugTypeEnum(type), id, - GetDebugSeverityEnum(severity), message); + GetDebugSourceName(source), GetDebugTypeName(type), id, + GetDebugSeverityName(severity), message); } } -FORCE_ALIGN void AL_APIENTRY alDebugMessageCallbackSOFT(ALDEBUGPROCSOFT callback, void *userParam) noexcept +FORCE_ALIGN void AL_APIENTRY alDebugMessageCallbackEXT(ALDEBUGPROCEXT callback, void *userParam) noexcept { ContextRef context{GetContextRef()}; if(!context) UNLIKELY return; @@ -199,7 +242,7 @@ FORCE_ALIGN void AL_APIENTRY alDebugMessageCallbackSOFT(ALDEBUGPROCSOFT callback context->mDebugParam = userParam; } -FORCE_ALIGN void AL_APIENTRY alDebugMessageInsertSOFT(ALenum source, ALenum type, ALuint id, +FORCE_ALIGN void AL_APIENTRY alDebugMessageInsertEXT(ALenum source, ALenum type, ALuint id, ALenum severity, ALsizei length, const ALchar *message) noexcept { ContextRef context{GetContextRef()}; @@ -238,7 +281,7 @@ FORCE_ALIGN void AL_APIENTRY alDebugMessageInsertSOFT(ALenum source, ALenum type } -FORCE_ALIGN void AL_APIENTRY alDebugMessageControlSOFT(ALenum source, ALenum type, ALenum severity, +FORCE_ALIGN void AL_APIENTRY alDebugMessageControlEXT(ALenum source, ALenum type, ALenum severity, ALsizei count, const ALuint *ids, ALboolean enable) noexcept { ContextRef context{GetContextRef()}; @@ -248,15 +291,15 @@ FORCE_ALIGN void AL_APIENTRY alDebugMessageControlSOFT(ALenum source, ALenum typ { if(!ids) return context->setError(AL_INVALID_VALUE, "IDs is null with non-0 count"); - if(source == AL_DONT_CARE_SOFT) + if(source == AL_DONT_CARE_EXT) return context->setError(AL_INVALID_OPERATION, - "Debug source cannot be AL_DONT_CARE_SOFT with IDs"); - if(type == AL_DONT_CARE_SOFT) + "Debug source cannot be AL_DONT_CARE_EXT with IDs"); + if(type == AL_DONT_CARE_EXT) return context->setError(AL_INVALID_OPERATION, - "Debug type cannot be AL_DONT_CARE_SOFT with IDs"); - if(severity != AL_DONT_CARE_SOFT) + "Debug type cannot be AL_DONT_CARE_EXT with IDs"); + if(severity != AL_DONT_CARE_EXT) return context->setError(AL_INVALID_OPERATION, - "Debug severity must be AL_DONT_CARE_SOFT with IDs"); + "Debug severity must be AL_DONT_CARE_EXT with IDs"); } if(enable != AL_TRUE && enable != AL_FALSE) @@ -266,7 +309,7 @@ FORCE_ALIGN void AL_APIENTRY alDebugMessageControlSOFT(ALenum source, ALenum typ static constexpr auto Values = make_array(); al::span srcIndices{al::as_span(Values).subspan()}; - if(source != AL_DONT_CARE_SOFT) + if(source != AL_DONT_CARE_EXT) { auto dsource = GetDebugSource(source); if(!dsource) @@ -275,7 +318,7 @@ FORCE_ALIGN void AL_APIENTRY alDebugMessageControlSOFT(ALenum source, ALenum typ } al::span typeIndices{al::as_span(Values).subspan()}; - if(type != AL_DONT_CARE_SOFT) + if(type != AL_DONT_CARE_EXT) { auto dtype = GetDebugType(type); if(!dtype) @@ -284,7 +327,7 @@ FORCE_ALIGN void AL_APIENTRY alDebugMessageControlSOFT(ALenum source, ALenum typ } al::span svrIndices{al::as_span(Values).subspan()}; - if(severity != AL_DONT_CARE_SOFT) + if(severity != AL_DONT_CARE_EXT) { auto dseverity = GetDebugSeverity(severity); if(!dseverity) @@ -336,7 +379,7 @@ FORCE_ALIGN void AL_APIENTRY alDebugMessageControlSOFT(ALenum source, ALenum typ } -FORCE_ALIGN void AL_APIENTRY alPushDebugGroupSOFT(ALenum source, ALuint id, ALsizei length, const ALchar *message) noexcept +FORCE_ALIGN void AL_APIENTRY alPushDebugGroupEXT(ALenum source, ALuint id, ALsizei length, const ALchar *message) noexcept { ContextRef context{GetContextRef()}; if(!context) UNLIKELY return; @@ -363,7 +406,7 @@ FORCE_ALIGN void AL_APIENTRY alPushDebugGroupSOFT(ALenum source, ALuint id, ALsi if(context->mDebugGroups.size() >= MaxDebugGroupDepth) { debuglock.unlock(); - return context->setError(AL_STACK_OVERFLOW_SOFT, "Pushing too many debug groups"); + return context->setError(AL_STACK_OVERFLOW_EXT, "Pushing too many debug groups"); } context->mDebugGroups.emplace_back(*dsource, id, message); @@ -378,7 +421,7 @@ FORCE_ALIGN void AL_APIENTRY alPushDebugGroupSOFT(ALenum source, ALuint id, ALsi newback.mMessage.data()); } -FORCE_ALIGN void AL_APIENTRY alPopDebugGroupSOFT(void) noexcept +FORCE_ALIGN void AL_APIENTRY alPopDebugGroupEXT(void) noexcept { ContextRef context{GetContextRef()}; if(!context) UNLIKELY return; @@ -387,7 +430,7 @@ FORCE_ALIGN void AL_APIENTRY alPopDebugGroupSOFT(void) noexcept if(context->mDebugGroups.size() <= 1) { debuglock.unlock(); - return context->setError(AL_STACK_UNDERFLOW_SOFT, + return context->setError(AL_STACK_UNDERFLOW_EXT, "Attempting to pop the default debug group"); } @@ -402,7 +445,7 @@ FORCE_ALIGN void AL_APIENTRY alPopDebugGroupSOFT(void) noexcept } -FORCE_ALIGN ALuint AL_APIENTRY alGetDebugMessageLogSOFT(ALuint count, ALsizei logBufSize, +FORCE_ALIGN ALuint AL_APIENTRY alGetDebugMessageLogEXT(ALuint count, ALsizei logBufSize, ALenum *sources, ALenum *types, ALuint *ids, ALenum *severities, ALsizei *lengths, ALchar *logBuf) noexcept { diff --git a/al/state.cpp b/al/state.cpp index 7f75268f..71c9b703 100644 --- a/al/state.cpp +++ b/al/state.cpp @@ -145,11 +145,11 @@ enum PropertyValue : ALenum { GainLimit = AL_GAIN_LIMIT_SOFT, NumResamplers = AL_NUM_RESAMPLERS_SOFT, DefaultResampler = AL_DEFAULT_RESAMPLER_SOFT, - DebugLoggedMessages = AL_DEBUG_LOGGED_MESSAGES_SOFT, - DebugNextLoggedMessageLength = AL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_SOFT, - MaxDebugMessageLength = AL_MAX_DEBUG_MESSAGE_LENGTH_SOFT, - MaxDebugLoggedMessages = AL_MAX_DEBUG_LOGGED_MESSAGES_SOFT, - MaxDebugGroupDepth = AL_MAX_DEBUG_GROUP_STACK_DEPTH_SOFT, + DebugLoggedMessages = AL_DEBUG_LOGGED_MESSAGES_EXT, + DebugNextLoggedMessageLength = AL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_EXT, + MaxDebugMessageLength = AL_MAX_DEBUG_MESSAGE_LENGTH_EXT, + MaxDebugLoggedMessages = AL_MAX_DEBUG_LOGGED_MESSAGES_EXT, + MaxDebugGroupDepth = AL_MAX_DEBUG_GROUP_STACK_DEPTH_EXT, #ifdef ALSOFT_EAX EaxRamSize = AL_EAX_RAM_SIZE, EaxRamFree = AL_EAX_RAM_FREE, @@ -214,14 +214,14 @@ void GetValue(ALCcontext *context, ALenum pname, T *values) *values = cast_value(al::to_underlying(ResamplerDefault)); return; - case AL_DEBUG_LOGGED_MESSAGES_SOFT: + case AL_DEBUG_LOGGED_MESSAGES_EXT: { std::lock_guard _{context->mDebugCbLock}; *values = cast_value(context->mDebugLog.size()); return; } - case AL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_SOFT: + case AL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_EXT: { std::lock_guard _{context->mDebugCbLock}; *values = cast_value(context->mDebugLog.empty() ? size_t{0} @@ -229,15 +229,15 @@ void GetValue(ALCcontext *context, ALenum pname, T *values) return; } - case AL_MAX_DEBUG_MESSAGE_LENGTH_SOFT: + case AL_MAX_DEBUG_MESSAGE_LENGTH_EXT: *values = cast_value(MaxDebugMessageLength); return; - case AL_MAX_DEBUG_LOGGED_MESSAGES_SOFT: + case AL_MAX_DEBUG_LOGGED_MESSAGES_EXT: *values = cast_value(MaxDebugLoggedMessages); return; - case AL_MAX_DEBUG_GROUP_STACK_DEPTH_SOFT: + case AL_MAX_DEBUG_GROUP_STACK_DEPTH_EXT: *values = cast_value(MaxDebugGroupDepth); return; @@ -310,7 +310,7 @@ START_API_FUNC } break; - case AL_DEBUG_OUTPUT_SOFT: + case AL_DEBUG_OUTPUT_EXT: context->mDebugEnabled = true; break; @@ -340,7 +340,7 @@ START_API_FUNC } break; - case AL_DEBUG_OUTPUT_SOFT: + case AL_DEBUG_OUTPUT_EXT: context->mDebugEnabled = false; break; @@ -368,7 +368,7 @@ START_API_FUNC value = context->mSourceDistanceModel ? AL_TRUE : AL_FALSE; break; - case AL_DEBUG_OUTPUT_SOFT: + case AL_DEBUG_OUTPUT_EXT: value = context->mDebugEnabled ? AL_TRUE : AL_FALSE; break; @@ -517,11 +517,11 @@ START_API_FUNC *values = context->mEventParam; break; - case AL_DEBUG_CALLBACK_FUNCTION_SOFT: + case AL_DEBUG_CALLBACK_FUNCTION_EXT: *values = reinterpret_cast(context->mDebugCb); break; - case AL_DEBUG_CALLBACK_USER_PARAM_SOFT: + case AL_DEBUG_CALLBACK_USER_PARAM_EXT: *values = context->mDebugParam; break; @@ -580,11 +580,11 @@ START_API_FUNC value = alErrOutOfMemory; break; - case AL_STACK_OVERFLOW_SOFT: + case AL_STACK_OVERFLOW_EXT: value = alStackOverflow; break; - case AL_STACK_UNDERFLOW_SOFT: + case AL_STACK_UNDERFLOW_EXT: value = alStackUnderflow; break; diff --git a/alc/alc.cpp b/alc/alc.cpp index 50982ed2..de5bc232 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -461,12 +461,12 @@ const struct { DECL(alBufferDataStatic), - DECL(alDebugMessageCallbackSOFT), - DECL(alDebugMessageInsertSOFT), - DECL(alDebugMessageControlSOFT), - DECL(alPushDebugGroupSOFT), - DECL(alPopDebugGroupSOFT), - DECL(alGetDebugMessageLogSOFT), + DECL(alDebugMessageCallbackEXT), + DECL(alDebugMessageInsertEXT), + DECL(alDebugMessageControlEXT), + DECL(alPushDebugGroupEXT), + DECL(alPopDebugGroupEXT), + DECL(alGetDebugMessageLogEXT), #ifdef ALSOFT_EAX }, eaxFunctions[] = { DECL(EAXGet), @@ -923,35 +923,35 @@ constexpr struct { DECL(AL_FORMAT_UHJ4CHN_MULAW_SOFT), DECL(AL_FORMAT_UHJ4CHN_ALAW_SOFT), - DECL(AL_DONT_CARE_SOFT), - DECL(AL_DEBUG_OUTPUT_SOFT), - DECL(AL_DEBUG_CALLBACK_FUNCTION_SOFT), - DECL(AL_DEBUG_CALLBACK_USER_PARAM_SOFT), - DECL(AL_DEBUG_SOURCE_API_SOFT), - DECL(AL_DEBUG_SOURCE_AUDIO_SYSTEM_SOFT), - DECL(AL_DEBUG_SOURCE_THIRD_PARTY_SOFT), - DECL(AL_DEBUG_SOURCE_APPLICATION_SOFT), - DECL(AL_DEBUG_SOURCE_OTHER_SOFT), - DECL(AL_DEBUG_TYPE_ERROR_SOFT), - DECL(AL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_SOFT), - DECL(AL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_SOFT), - DECL(AL_DEBUG_TYPE_PORTABILITY_SOFT), - DECL(AL_DEBUG_TYPE_PERFORMANCE_SOFT), - DECL(AL_DEBUG_TYPE_MARKER_SOFT), - DECL(AL_DEBUG_TYPE_PUSH_GROUP_SOFT), - DECL(AL_DEBUG_TYPE_POP_GROUP_SOFT), - DECL(AL_DEBUG_TYPE_OTHER_SOFT), - DECL(AL_DEBUG_SEVERITY_HIGH_SOFT), - 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_MAX_DEBUG_GROUP_STACK_DEPTH_SOFT), - DECL(AL_STACK_OVERFLOW_SOFT), - DECL(AL_STACK_UNDERFLOW_SOFT), + DECL(AL_DONT_CARE_EXT), + DECL(AL_DEBUG_OUTPUT_EXT), + DECL(AL_DEBUG_CALLBACK_FUNCTION_EXT), + DECL(AL_DEBUG_CALLBACK_USER_PARAM_EXT), + DECL(AL_DEBUG_SOURCE_API_EXT), + DECL(AL_DEBUG_SOURCE_AUDIO_SYSTEM_EXT), + DECL(AL_DEBUG_SOURCE_THIRD_PARTY_EXT), + DECL(AL_DEBUG_SOURCE_APPLICATION_EXT), + DECL(AL_DEBUG_SOURCE_OTHER_EXT), + DECL(AL_DEBUG_TYPE_ERROR_EXT), + DECL(AL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_EXT), + DECL(AL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_EXT), + DECL(AL_DEBUG_TYPE_PORTABILITY_EXT), + DECL(AL_DEBUG_TYPE_PERFORMANCE_EXT), + DECL(AL_DEBUG_TYPE_MARKER_EXT), + DECL(AL_DEBUG_TYPE_PUSH_GROUP_EXT), + DECL(AL_DEBUG_TYPE_POP_GROUP_EXT), + DECL(AL_DEBUG_TYPE_OTHER_EXT), + DECL(AL_DEBUG_SEVERITY_HIGH_EXT), + DECL(AL_DEBUG_SEVERITY_MEDIUM_EXT), + DECL(AL_DEBUG_SEVERITY_LOW_EXT), + DECL(AL_DEBUG_SEVERITY_NOTIFICATION_EXT), + DECL(AL_DEBUG_LOGGED_MESSAGES_EXT), + DECL(AL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_EXT), + DECL(AL_MAX_DEBUG_MESSAGE_LENGTH_EXT), + DECL(AL_MAX_DEBUG_LOGGED_MESSAGES_EXT), + DECL(AL_MAX_DEBUG_GROUP_STACK_DEPTH_EXT), + DECL(AL_STACK_OVERFLOW_EXT), + DECL(AL_STACK_UNDERFLOW_EXT), DECL(AL_STOP_SOURCES_ON_DISCONNECT_SOFT), diff --git a/alc/context.cpp b/alc/context.cpp index 0c8253fb..6a2f57ca 100644 --- a/alc/context.cpp +++ b/alc/context.cpp @@ -51,6 +51,7 @@ using voidp = void*; constexpr ALchar alExtList[] = "AL_EXT_ALAW " "AL_EXT_BFORMAT " + "AL_EXTX_DEBUG " "AL_EXT_DOUBLE " "AL_EXT_EXPONENT_DISTANCE " "AL_EXT_FLOAT32 " @@ -72,7 +73,6 @@ constexpr ALchar alExtList[] = "AL_SOFT_buffer_length_query " "AL_SOFT_callback_buffer " "AL_SOFTX_convolution_reverb " - "AL_SOFTX_debug " "AL_SOFT_deferred_updates " "AL_SOFT_direct_channels " "AL_SOFT_direct_channels_remix " diff --git a/alc/context.h b/alc/context.h index d74bc8d1..9381db04 100644 --- a/alc/context.h +++ b/alc/context.h @@ -118,7 +118,7 @@ struct ALCcontext : public al::intrusive_ref, ContextBase { void *mEventParam{nullptr}; std::mutex mDebugCbLock; - ALDEBUGPROCSOFT mDebugCb{}; + ALDEBUGPROCEXT mDebugCb{}; void *mDebugParam{nullptr}; std::vector mDebugGroups; std::deque mDebugLog; diff --git a/alc/inprogext.h b/alc/inprogext.h index 7f9d7766..9db3b65b 100644 --- a/alc/inprogext.h +++ b/alc/inprogext.h @@ -54,52 +54,52 @@ AL_API void AL_APIENTRY alAuxiliaryEffectSlotStopvSOFT(ALsizei n, const ALuint * #define AL_STOP_SOURCES_ON_DISCONNECT_SOFT 0x19AB #endif -#ifndef AL_SOFT_debug -#define AL_SOFT_debug -#define AL_DONT_CARE_SOFT 0x0002 -#define AL_DEBUG_OUTPUT_SOFT 0x19B2 -#define AL_DEBUG_CALLBACK_FUNCTION_SOFT 0x19B3 -#define AL_DEBUG_CALLBACK_USER_PARAM_SOFT 0x19B4 -#define AL_DEBUG_SOURCE_API_SOFT 0x19B5 -#define AL_DEBUG_SOURCE_AUDIO_SYSTEM_SOFT 0x19B6 -#define AL_DEBUG_SOURCE_THIRD_PARTY_SOFT 0x19B7 -#define AL_DEBUG_SOURCE_APPLICATION_SOFT 0x19B8 -#define AL_DEBUG_SOURCE_OTHER_SOFT 0x19B9 -#define AL_DEBUG_TYPE_ERROR_SOFT 0x19BA -#define AL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_SOFT 0x19BB -#define AL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_SOFT 0x19BC -#define AL_DEBUG_TYPE_PORTABILITY_SOFT 0x19BD -#define AL_DEBUG_TYPE_PERFORMANCE_SOFT 0x19BE -#define AL_DEBUG_TYPE_MARKER_SOFT 0x19BF -#define AL_DEBUG_TYPE_PUSH_GROUP_SOFT 0x19C0 -#define AL_DEBUG_TYPE_POP_GROUP_SOFT 0x19C1 -#define AL_DEBUG_TYPE_OTHER_SOFT 0x19C2 -#define AL_DEBUG_SEVERITY_HIGH_SOFT 0x19C3 -#define AL_DEBUG_SEVERITY_MEDIUM_SOFT 0x19C4 -#define AL_DEBUG_SEVERITY_LOW_SOFT 0x19C5 -#define AL_DEBUG_SEVERITY_NOTIFICATION_SOFT 0x19C6 -#define AL_DEBUG_LOGGED_MESSAGES_SOFT 0x19C7 -#define AL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_SOFT 0x19C8 -#define AL_MAX_DEBUG_MESSAGE_LENGTH_SOFT 0x19C9 -#define AL_MAX_DEBUG_LOGGED_MESSAGES_SOFT 0x19CA -#define AL_MAX_DEBUG_GROUP_STACK_DEPTH_SOFT 0x19CB -#define AL_STACK_OVERFLOW_SOFT 0x19CC -#define AL_STACK_UNDERFLOW_SOFT 0x19CD +#ifndef AL_EXT_DEBUG +#define AL_EXT_DEBUG +#define AL_DONT_CARE_EXT 0x0002 +#define AL_DEBUG_OUTPUT_EXT 0x19B2 +#define AL_DEBUG_CALLBACK_FUNCTION_EXT 0x19B3 +#define AL_DEBUG_CALLBACK_USER_PARAM_EXT 0x19B4 +#define AL_DEBUG_SOURCE_API_EXT 0x19B5 +#define AL_DEBUG_SOURCE_AUDIO_SYSTEM_EXT 0x19B6 +#define AL_DEBUG_SOURCE_THIRD_PARTY_EXT 0x19B7 +#define AL_DEBUG_SOURCE_APPLICATION_EXT 0x19B8 +#define AL_DEBUG_SOURCE_OTHER_EXT 0x19B9 +#define AL_DEBUG_TYPE_ERROR_EXT 0x19BA +#define AL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_EXT 0x19BB +#define AL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_EXT 0x19BC +#define AL_DEBUG_TYPE_PORTABILITY_EXT 0x19BD +#define AL_DEBUG_TYPE_PERFORMANCE_EXT 0x19BE +#define AL_DEBUG_TYPE_MARKER_EXT 0x19BF +#define AL_DEBUG_TYPE_PUSH_GROUP_EXT 0x19C0 +#define AL_DEBUG_TYPE_POP_GROUP_EXT 0x19C1 +#define AL_DEBUG_TYPE_OTHER_EXT 0x19C2 +#define AL_DEBUG_SEVERITY_HIGH_EXT 0x19C3 +#define AL_DEBUG_SEVERITY_MEDIUM_EXT 0x19C4 +#define AL_DEBUG_SEVERITY_LOW_EXT 0x19C5 +#define AL_DEBUG_SEVERITY_NOTIFICATION_EXT 0x19C6 +#define AL_DEBUG_LOGGED_MESSAGES_EXT 0x19C7 +#define AL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_EXT 0x19C8 +#define AL_MAX_DEBUG_MESSAGE_LENGTH_EXT 0x19C9 +#define AL_MAX_DEBUG_LOGGED_MESSAGES_EXT 0x19CA +#define AL_MAX_DEBUG_GROUP_STACK_DEPTH_EXT 0x19CB +#define AL_STACK_OVERFLOW_EXT 0x19CC +#define AL_STACK_UNDERFLOW_EXT 0x19CD -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 void (AL_APIENTRY*LPALPUSHDEBUGGROUPSOFT)(ALenum source, ALuint id, ALsizei length, const ALchar *message); -typedef void (AL_APIENTRY*LPALPOPDEBUGGROUPSOFT)(void); -typedef ALuint (AL_APIENTRY*LPALGETDEBUGMESSAGELOGSOFT)(ALuint count, ALsizei logBufSize, ALenum *sources, ALenum *types, ALuint *ids, ALenum *severities, ALsizei *lengths, ALchar *logBuf); +typedef void (AL_APIENTRY*ALDEBUGPROCEXT)(ALenum source, ALenum type, ALuint id, ALenum severity, ALsizei length, const ALchar *message, void *userParam); +typedef void (AL_APIENTRY*LPALDEBUGMESSAGECALLBACKEXT)(ALDEBUGPROCEXT callback, void *userParam); +typedef void (AL_APIENTRY*LPALDEBUGMESSAGEINSERTEXT)(ALenum source, ALenum type, ALuint id, ALenum severity, ALsizei length, const ALchar *message); +typedef void (AL_APIENTRY*LPALDEBUGMESSAGECONTROLEXT)(ALenum source, ALenum type, ALenum severity, ALsizei count, const ALuint *ids, ALboolean enable); +typedef void (AL_APIENTRY*LPALPUSHDEBUGGROUPEXT)(ALenum source, ALuint id, ALsizei length, const ALchar *message); +typedef void (AL_APIENTRY*LPALPOPDEBUGGROUPEXT)(void); +typedef ALuint (AL_APIENTRY*LPALGETDEBUGMESSAGELOGEXT)(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; -void AL_APIENTRY alPushDebugGroupSOFT(ALenum source, ALuint id, ALsizei length, const ALchar *message) noexcept; -void AL_APIENTRY alPopDebugGroupSOFT(void) noexcept; -ALuint AL_APIENTRY alGetDebugMessageLogSOFT(ALuint count, ALsizei logBufSize, ALenum *sources, ALenum *types, ALuint *ids, ALenum *severities, ALsizei *lengths, ALchar *logBuf) noexcept; +void AL_APIENTRY alDebugMessageCallbackEXT(ALDEBUGPROCEXT callback, void *userParam) noexcept; +void AL_APIENTRY alDebugMessageInsertEXT(ALenum source, ALenum type, ALuint id, ALenum severity, ALsizei length, const ALchar *message) noexcept; +void AL_APIENTRY alDebugMessageControlEXT(ALenum source, ALenum type, ALenum severity, ALsizei count, const ALuint *ids, ALboolean enable) noexcept; +void AL_APIENTRY alPushDebugGroupEXT(ALenum source, ALuint id, ALsizei length, const ALchar *message) noexcept; +void AL_APIENTRY alPopDebugGroupEXT(void) noexcept; +ALuint AL_APIENTRY alGetDebugMessageLogEXT(ALuint count, ALsizei logBufSize, ALenum *sources, ALenum *types, ALuint *ids, ALenum *severities, ALsizei *lengths, ALchar *logBuf) noexcept; #endif #endif -- cgit v1.2.3 From ce588ea5a3c3ee6c7fce64ec501a03ebaca373d4 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Wed, 3 May 2023 10:42:32 -0700 Subject: Implement a context debug flag Setting the debug flag at context creation enables more debug messages for the created context, and enables debug messages by default. --- al/debug.cpp | 15 ++++++++++----- al/state.cpp | 23 +++++++++++++++-------- alc/alc.cpp | 41 ++++++++++++++++++++++++++++++----------- alc/context.cpp | 7 ++++--- alc/context.h | 9 ++++++++- alc/inprogext.h | 11 +++++++++-- 6 files changed, 76 insertions(+), 30 deletions(-) (limited to 'alc/context.cpp') diff --git a/al/debug.cpp b/al/debug.cpp index fa16ff73..786fcd1f 100644 --- a/al/debug.cpp +++ b/al/debug.cpp @@ -248,6 +248,9 @@ FORCE_ALIGN void AL_APIENTRY alDebugMessageInsertEXT(ALenum source, ALenum type, ContextRef context{GetContextRef()}; if(!context) UNLIKELY return; + if(!context->mContextFlags.test(ContextFlags::DebugBit)) + return; + if(!message) return context->setError(AL_INVALID_VALUE, "Null message pointer"); @@ -416,9 +419,10 @@ FORCE_ALIGN void AL_APIENTRY alPushDebugGroupEXT(ALenum source, ALuint id, ALsiz newback.mFilters = oldback.mFilters; newback.mIdFilters = oldback.mIdFilters; - context->sendDebugMessage(debuglock, newback.mSource, DebugType::PushGroup, newback.mId, - DebugSeverity::Notification, static_cast(newback.mMessage.size()), - newback.mMessage.data()); + if(context->mContextFlags.test(ContextFlags::DebugBit)) + context->sendDebugMessage(debuglock, newback.mSource, DebugType::PushGroup, newback.mId, + DebugSeverity::Notification, static_cast(newback.mMessage.size()), + newback.mMessage.data()); } FORCE_ALIGN void AL_APIENTRY alPopDebugGroupEXT(void) noexcept @@ -440,8 +444,9 @@ FORCE_ALIGN void AL_APIENTRY alPopDebugGroupEXT(void) noexcept std::string message{std::move(debug.mMessage)}; context->mDebugGroups.pop_back(); - context->sendDebugMessage(debuglock, source, DebugType::PopGroup, id, - DebugSeverity::Notification, static_cast(message.size()), message.data()); + if(context->mContextFlags.test(ContextFlags::DebugBit)) + context->sendDebugMessage(debuglock, source, DebugType::PopGroup, id, + DebugSeverity::Notification, static_cast(message.size()), message.data()); } diff --git a/al/state.cpp b/al/state.cpp index 71c9b703..efc6398d 100644 --- a/al/state.cpp +++ b/al/state.cpp @@ -150,6 +150,7 @@ enum PropertyValue : ALenum { MaxDebugMessageLength = AL_MAX_DEBUG_MESSAGE_LENGTH_EXT, MaxDebugLoggedMessages = AL_MAX_DEBUG_LOGGED_MESSAGES_EXT, MaxDebugGroupDepth = AL_MAX_DEBUG_GROUP_STACK_DEPTH_EXT, + ContextFlags = AL_CONTEXT_FLAGS_EXT, #ifdef ALSOFT_EAX EaxRamSize = AL_EAX_RAM_SIZE, EaxRamFree = AL_EAX_RAM_FREE, @@ -183,10 +184,11 @@ void GetValue(ALCcontext *context, ALenum pname, T *values) return; case AL_DOPPLER_VELOCITY: - context->debugMessage(DebugSource::API, DebugType::DeprecatedBehavior, 0, - DebugSeverity::Medium, -1, - "AL_DOPPLER_VELOCITY is deprecated in AL 1.1, use AL_SPEED_OF_SOUND; " - "AL_DOPPLER_VELOCITY -> AL_SPEED_OF_SOUND / 343.3f"); + if(context->mContextFlags.test(ContextFlags::DebugBit)) UNLIKELY + context->debugMessage(DebugSource::API, DebugType::DeprecatedBehavior, 0, + DebugSeverity::Medium, -1, + "AL_DOPPLER_VELOCITY is deprecated in AL 1.1, use AL_SPEED_OF_SOUND; " + "AL_DOPPLER_VELOCITY -> AL_SPEED_OF_SOUND / 343.3f"); *values = cast_value(context->mDopplerVelocity); return; @@ -241,6 +243,10 @@ void GetValue(ALCcontext *context, ALenum pname, T *values) *values = cast_value(MaxDebugGroupDepth); return; + case AL_CONTEXT_FLAGS_EXT: + *values = cast_value(context->mContextFlags.to_ulong()); + return; + #ifdef ALSOFT_EAX #define EAX_ERROR "[alGetInteger] EAX not enabled." @@ -618,10 +624,11 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(!context) UNLIKELY return; - context->debugMessage(DebugSource::API, DebugType::DeprecatedBehavior, 0, - DebugSeverity::Medium, -1, - "alDopplerVelocity is deprecated in AL 1.1, use alSpeedOfSound; " - "alDopplerVelocity(x) -> alSpeedOfSound(343.3f * x)"); + if(context->mContextFlags.test(ContextFlags::DebugBit)) UNLIKELY + context->debugMessage(DebugSource::API, DebugType::DeprecatedBehavior, 0, + DebugSeverity::Medium, -1, + "alDopplerVelocity is deprecated in AL 1.1, use alSpeedOfSound; " + "alDopplerVelocity(x) -> alSpeedOfSound(343.3f * x)"); if(!(value >= 0.0f && std::isfinite(value))) context->setError(AL_INVALID_VALUE, "Doppler velocity %f out of range", value); diff --git a/alc/alc.cpp b/alc/alc.cpp index de5bc232..8932a084 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -573,6 +573,9 @@ constexpr struct { DECL(ALC_INVALID_VALUE), DECL(ALC_OUT_OF_MEMORY), + DECL(ALC_CONTEXT_FLAGS_EXT), + DECL(ALC_CONTEXT_DEBUG_BIT_EXT), + DECL(AL_INVALID), DECL(AL_NONE), @@ -1021,6 +1024,7 @@ constexpr ALCchar alcExtensionList[] = "ALC_ENUMERATE_ALL_EXT " "ALC_ENUMERATION_EXT " "ALC_EXT_CAPTURE " + "ALC_EXTX_debug " "ALC_EXT_DEDICATED " "ALC_EXT_disconnect " "ALC_EXT_EFX " @@ -2619,11 +2623,12 @@ START_API_FUNC return; } - ctx->debugMessage(DebugSource::API, DebugType::Portability, 0, DebugSeverity::Medium, -1, - "alcSuspendContext behavior is not portable -- some implementations suspend all " - "rendering, some only defer property changes, and some are completely no-op; consider " - "using alcDevicePauseSOFT to suspend all rendering, or alDeferUpdatesSOFT to only defer " - "property changes"); + if(context->mContextFlags.test(ContextFlags::DebugBit)) UNLIKELY + ctx->debugMessage(DebugSource::API, DebugType::Portability, 0, DebugSeverity::Medium, -1, + "alcSuspendContext behavior is not portable -- some implementations suspend all " + "rendering, some only defer property changes, and some are completely no-op; consider " + "using alcDevicePauseSOFT to suspend all rendering, or alDeferUpdatesSOFT to only " + "defer property changes"); if(SuspendDefers) { @@ -2643,11 +2648,12 @@ START_API_FUNC return; } - ctx->debugMessage(DebugSource::API, DebugType::Portability, 0, DebugSeverity::Medium, -1, - "alcProcessContext behavior is not portable -- some implementations resume rendering, " - "some apply deferred property changes, and some are completely no-op; consider using " - "alcDeviceResumeSOFT to resume rendering, or alProcessUpdatesSOFT to apply deferred " - "property changes"); + if(context->mContextFlags.test(ContextFlags::DebugBit)) UNLIKELY + ctx->debugMessage(DebugSource::API, DebugType::Portability, 0, DebugSeverity::Medium, -1, + "alcProcessContext behavior is not portable -- some implementations resume rendering, " + "some apply deferred property changes, and some are completely no-op; consider using " + "alcDeviceResumeSOFT to resume rendering, or alProcessUpdatesSOFT to apply deferred " + "property changes"); if(SuspendDefers) { @@ -3366,7 +3372,20 @@ START_API_FUNC return nullptr; } - ContextRef context{new ALCcontext{dev}}; + ContextFlagBitset ctxflags{0}; + if(attrList) + { + for(size_t i{0};attrList[i];i+=2) + { + if(attrList[i] == ALC_CONTEXT_FLAGS_EXT) + { + ctxflags = static_cast(attrList[i+1]); + break; + } + } + } + + ContextRef context{new ALCcontext{dev, ctxflags}}; context->init(); if(auto volopt = dev->configValue(nullptr, "volume-adjust")) diff --git a/alc/context.cpp b/alc/context.cpp index 6a2f57ca..2fbf67af 100644 --- a/alc/context.cpp +++ b/alc/context.cpp @@ -51,7 +51,7 @@ using voidp = void*; constexpr ALchar alExtList[] = "AL_EXT_ALAW " "AL_EXT_BFORMAT " - "AL_EXTX_DEBUG " + "AL_EXTX_debug " "AL_EXT_DOUBLE " "AL_EXT_EXPONENT_DISTANCE " "AL_EXT_FLOAT32 " @@ -119,10 +119,11 @@ void ALCcontext::setThreadContext(ALCcontext *context) noexcept { sThreadContext.set(context); } #endif -ALCcontext::ALCcontext(al::intrusive_ptr device) - : ContextBase{device.get()}, mALDevice{std::move(device)} +ALCcontext::ALCcontext(al::intrusive_ptr device, ContextFlagBitset flags) + : ContextBase{device.get()}, mALDevice{std::move(device)}, mContextFlags{flags} { mDebugGroups.emplace_back(DebugSource::Other, 0, std::string{}); + mDebugEnabled.store(mContextFlags.test(ContextFlags::DebugBit), std::memory_order_relaxed); } ALCcontext::~ALCcontext() diff --git a/alc/context.h b/alc/context.h index 9381db04..402794eb 100644 --- a/alc/context.h +++ b/alc/context.h @@ -43,6 +43,12 @@ enum class DebugSeverity : uint8_t; using uint = unsigned int; +enum ContextFlags { + DebugBit = 0, /* ALC_CONTEXT_DEBUG_BIT_EXT */ +}; +using ContextFlagBitset = std::bitset; + + struct DebugLogEntry { const DebugSource mSource; const DebugType mType; @@ -103,6 +109,7 @@ struct ALCcontext : public al::intrusive_ref, ContextBase { std::atomic mLastError{AL_NO_ERROR}; + const ContextFlagBitset mContextFlags; std::atomic mDebugEnabled{false}; DistanceModel mDistanceModel{DistanceModel::Default}; @@ -141,7 +148,7 @@ struct ALCcontext : public al::intrusive_ref, ContextBase { std::string mExtensionListOverride{}; - ALCcontext(al::intrusive_ptr device); + ALCcontext(al::intrusive_ptr device, ContextFlagBitset flags); ALCcontext(const ALCcontext&) = delete; ALCcontext& operator=(const ALCcontext&) = delete; ~ALCcontext(); diff --git a/alc/inprogext.h b/alc/inprogext.h index 9db3b65b..b39eaa58 100644 --- a/alc/inprogext.h +++ b/alc/inprogext.h @@ -54,8 +54,14 @@ AL_API void AL_APIENTRY alAuxiliaryEffectSlotStopvSOFT(ALsizei n, const ALuint * #define AL_STOP_SOURCES_ON_DISCONNECT_SOFT 0x19AB #endif -#ifndef AL_EXT_DEBUG -#define AL_EXT_DEBUG +#ifndef ALC_EXT_debug +#define ALC_EXT_debug +#define ALC_CONTEXT_FLAGS_EXT 0x19CE +#define ALC_CONTEXT_DEBUG_BIT_EXT 0x0001 +#endif + +#ifndef AL_EXT_debug +#define AL_EXT_debug #define AL_DONT_CARE_EXT 0x0002 #define AL_DEBUG_OUTPUT_EXT 0x19B2 #define AL_DEBUG_CALLBACK_FUNCTION_EXT 0x19B3 @@ -85,6 +91,7 @@ AL_API void AL_APIENTRY alAuxiliaryEffectSlotStopvSOFT(ALsizei n, const ALuint * #define AL_MAX_DEBUG_GROUP_STACK_DEPTH_EXT 0x19CB #define AL_STACK_OVERFLOW_EXT 0x19CC #define AL_STACK_UNDERFLOW_EXT 0x19CD +#define AL_CONTEXT_FLAGS_EXT 0x19CE typedef void (AL_APIENTRY*ALDEBUGPROCEXT)(ALenum source, ALenum type, ALuint id, ALenum severity, ALsizei length, const ALchar *message, void *userParam); typedef void (AL_APIENTRY*LPALDEBUGMESSAGECALLBACKEXT)(ALDEBUGPROCEXT callback, void *userParam); -- cgit v1.2.3 From e42681c4472b8a149a8f1e68614e4f5ee5d04fb0 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 8 May 2023 14:47:19 -0700 Subject: Store extension strings individually And dynamically build the full AL_EXTENSIONS string --- al/extension.cpp | 12 +--- al/state.cpp | 2 +- alc/context.cpp | 166 ++++++++++++++++++++++++++----------------------------- alc/context.h | 7 +-- 4 files changed, 85 insertions(+), 102 deletions(-) (limited to 'alc/context.cpp') diff --git a/al/extension.cpp b/al/extension.cpp index 3ead0af8..dbaf4d5f 100644 --- a/al/extension.cpp +++ b/al/extension.cpp @@ -46,18 +46,10 @@ START_API_FUNC } size_t len{strlen(extName)}; - const char *ptr{context->mExtensionList}; - while(ptr && *ptr) + for(std::string_view ext : context->mExtensions) { - if(al::strncasecmp(ptr, extName, len) == 0 && (ptr[len] == '\0' || isspace(ptr[len]))) + if(len == ext.length() && al::strncasecmp(ext.data(), extName, len) == 0) return AL_TRUE; - - if((ptr=strchr(ptr, ' ')) != nullptr) - { - do { - ++ptr; - } while(isspace(*ptr)); - } } return AL_FALSE; diff --git a/al/state.cpp b/al/state.cpp index fb3186c7..cb2afd6c 100644 --- a/al/state.cpp +++ b/al/state.cpp @@ -560,7 +560,7 @@ START_API_FUNC break; case AL_EXTENSIONS: - value = context->mExtensionList; + value = context->mExtensionsString.c_str(); break; case AL_NO_ERROR: diff --git a/alc/context.cpp b/alc/context.cpp index 2fbf67af..d920d4b6 100644 --- a/alc/context.cpp +++ b/alc/context.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include "AL/efx.h" @@ -48,48 +49,52 @@ using namespace std::placeholders; using voidp = void*; /* Default context extensions */ -constexpr ALchar alExtList[] = - "AL_EXT_ALAW " - "AL_EXT_BFORMAT " - "AL_EXTX_debug " - "AL_EXT_DOUBLE " - "AL_EXT_EXPONENT_DISTANCE " - "AL_EXT_FLOAT32 " - "AL_EXT_IMA4 " - "AL_EXT_LINEAR_DISTANCE " - "AL_EXT_MCFORMATS " - "AL_EXT_MULAW " - "AL_EXT_MULAW_BFORMAT " - "AL_EXT_MULAW_MCFORMATS " - "AL_EXT_OFFSET " - "AL_EXT_source_distance_model " - "AL_EXT_SOURCE_RADIUS " - "AL_EXT_STATIC_BUFFER " - "AL_EXT_STEREO_ANGLES " - "AL_LOKI_quadriphonic " - "AL_SOFT_bformat_ex " - "AL_SOFTX_bformat_hoa " - "AL_SOFT_block_alignment " - "AL_SOFT_buffer_length_query " - "AL_SOFT_callback_buffer " - "AL_SOFTX_convolution_reverb " - "AL_SOFT_deferred_updates " - "AL_SOFT_direct_channels " - "AL_SOFT_direct_channels_remix " - "AL_SOFT_effect_target " - "AL_SOFT_events " - "AL_SOFT_gain_clamp_ex " - "AL_SOFTX_hold_on_disconnect " - "AL_SOFT_loop_points " - "AL_SOFTX_map_buffer " - "AL_SOFT_MSADPCM " - "AL_SOFT_source_latency " - "AL_SOFT_source_length " - "AL_SOFT_source_resampler " - "AL_SOFT_source_spatialize " - "AL_SOFT_source_start_delay " - "AL_SOFT_UHJ " - "AL_SOFT_UHJ_ex"; +std::vector getContextExtensions() noexcept +{ + return std::vector{ + "AL_EXT_ALAW", + "AL_EXT_BFORMAT", + "AL_EXTX_debug", + "AL_EXT_DOUBLE", + "AL_EXT_EXPONENT_DISTANCE", + "AL_EXT_FLOAT32", + "AL_EXT_IMA4", + "AL_EXT_LINEAR_DISTANCE", + "AL_EXT_MCFORMATS", + "AL_EXT_MULAW", + "AL_EXT_MULAW_BFORMAT", + "AL_EXT_MULAW_MCFORMATS", + "AL_EXT_OFFSET", + "AL_EXT_source_distance_model", + "AL_EXT_SOURCE_RADIUS", + "AL_EXT_STATIC_BUFFER", + "AL_EXT_STEREO_ANGLES", + "AL_LOKI_quadriphonic", + "AL_SOFT_bformat_ex", + "AL_SOFTX_bformat_hoa", + "AL_SOFT_block_alignment", + "AL_SOFT_buffer_length_query", + "AL_SOFT_callback_buffer", + "AL_SOFTX_convolution_reverb", + "AL_SOFT_deferred_updates", + "AL_SOFT_direct_channels", + "AL_SOFT_direct_channels_remix", + "AL_SOFT_effect_target", + "AL_SOFT_events", + "AL_SOFT_gain_clamp_ex", + "AL_SOFTX_hold_on_disconnect", + "AL_SOFT_loop_points", + "AL_SOFTX_map_buffer", + "AL_SOFT_MSADPCM", + "AL_SOFT_source_latency", + "AL_SOFT_source_length", + "AL_SOFT_source_resampler", + "AL_SOFT_source_spatialize", + "AL_SOFT_source_start_delay", + "AL_SOFT_UHJ", + "AL_SOFT_UHJ_ex", + }; +} } // namespace @@ -179,26 +184,41 @@ void ALCcontext::init() mCurrentVoiceChange.store(cur, std::memory_order_relaxed); } - mExtensionList = alExtList; + mExtensions = getContextExtensions(); if(sBufferSubDataCompat) { - std::string extlist{mExtensionList}; - - const auto pos = extlist.find("AL_EXT_SOURCE_RADIUS "); - if(pos != std::string::npos) - extlist.replace(pos, 20, "AL_SOFT_buffer_sub_data"); - else - extlist += " AL_SOFT_buffer_sub_data"; - - mExtensionListOverride = std::move(extlist); - mExtensionList = mExtensionListOverride.c_str(); + auto iter = std::find(mExtensions.begin(), mExtensions.end(), "AL_EXT_SOURCE_RADIUS"); + if(iter != mExtensions.end()) mExtensions.erase(iter); + /* TODO: Would be nice to sort this alphabetically. Needs case- + * insensitive searching. + */ + mExtensions.emplace_back("AL_SOFT_buffer_sub_data"); } #ifdef ALSOFT_EAX eax_initialize_extensions(); #endif // ALSOFT_EAX + if(!mExtensions.empty()) + { + const size_t len{std::accumulate(mExtensions.cbegin()+1, mExtensions.cend(), + mExtensions.front().length(), + [](size_t current, std::string_view ext) noexcept + { return current + ext.length() + 1; })}; + + std::string extensions; + extensions.reserve(len); + extensions += mExtensions.front(); + for(std::string_view ext : al::span{mExtensions}.subspan<1>()) + { + extensions += ' '; + extensions += ext; + } + + mExtensionsString = std::move(extensions); + } + mParams.Position = alu::Vector{0.0f, 0.0f, 0.0f, 1.0f}; mParams.Matrix = alu::Matrix::Identity(); mParams.Velocity = alu::Vector{}; @@ -457,43 +477,15 @@ void ALCcontext::eax_initialize_extensions() if(!eax_g_is_enabled) return; - const auto string_max_capacity = - std::strlen(mExtensionList) + 1 + - std::strlen(eax1_ext_name) + 1 + - std::strlen(eax2_ext_name) + 1 + - std::strlen(eax3_ext_name) + 1 + - std::strlen(eax4_ext_name) + 1 + - std::strlen(eax5_ext_name) + 1 + - std::strlen(eax_x_ram_ext_name) + 1; - - std::string extlist; - extlist.reserve(string_max_capacity); - + mExtensions.emplace(mExtensions.begin(), eax_x_ram_ext_name); if(eaxIsCapable()) { - extlist += eax1_ext_name; - extlist += ' '; - - extlist += eax2_ext_name; - extlist += ' '; - - extlist += eax3_ext_name; - extlist += ' '; - - extlist += eax4_ext_name; - extlist += ' '; - - extlist += eax5_ext_name; - extlist += ' '; + mExtensions.emplace(mExtensions.begin(), eax5_ext_name); + mExtensions.emplace(mExtensions.begin(), eax4_ext_name); + mExtensions.emplace(mExtensions.begin(), eax3_ext_name); + mExtensions.emplace(mExtensions.begin(), eax2_ext_name); + mExtensions.emplace(mExtensions.begin(), eax1_ext_name); } - - extlist += eax_x_ram_ext_name; - extlist += ' '; - - extlist += mExtensionList; - - mExtensionListOverride = std::move(extlist); - mExtensionList = mExtensionListOverride.c_str(); } void ALCcontext::eax_initialize() diff --git a/alc/context.h b/alc/context.h index 402794eb..acbb3788 100644 --- a/alc/context.h +++ b/alc/context.h @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include "AL/al.h" @@ -143,9 +143,8 @@ struct ALCcontext : public al::intrusive_ref, ContextBase { /* Default effect slot */ std::unique_ptr mDefaultSlot; - const char *mExtensionList{nullptr}; - - std::string mExtensionListOverride{}; + std::vector mExtensions; + std::string mExtensionsString{}; ALCcontext(al::intrusive_ptr device, ContextFlagBitset flags); -- cgit v1.2.3 From 1b2e5ba854c5c7fa35deb8cfb17f413341596a77 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 14 May 2023 01:27:42 -0700 Subject: Implement direct functions for extension queries and EAX --- al/buffer.cpp | 8 ++++++-- al/extension.cpp | 26 +++++++++++++++++--------- alc/alc.cpp | 10 ++++++++++ alc/context.cpp | 25 +++++++++++-------------- 4 files changed, 44 insertions(+), 25 deletions(-) (limited to 'alc/context.cpp') diff --git a/al/buffer.cpp b/al/buffer.cpp index bfc10906..216c82eb 100644 --- a/al/buffer.cpp +++ b/al/buffer.cpp @@ -1547,10 +1547,12 @@ BufferSubList::~BufferSubList() #ifdef ALSOFT_EAX FORCE_ALIGN ALboolean AL_APIENTRY EAXSetBufferMode(ALsizei n, const ALuint *buffers, ALint value) noexcept +{ return EAXSetBufferModeDirect(GetContextRef().get(), n, buffers, value); } +FORCE_ALIGN ALboolean AL_APIENTRY EAXSetBufferModeDirect(ALCcontext *context, ALsizei n, + const ALuint *buffers, ALint value) noexcept { #define EAX_PREFIX "[EAXSetBufferMode] " - const auto context = ContextRef{GetContextRef()}; if(!context) { ERR(EAX_PREFIX "%s\n", "No current context."); @@ -1688,10 +1690,12 @@ FORCE_ALIGN ALboolean AL_APIENTRY EAXSetBufferMode(ALsizei n, const ALuint *buff } FORCE_ALIGN ALenum AL_APIENTRY EAXGetBufferMode(ALuint buffer, ALint *pReserved) noexcept +{ return EAXGetBufferModeDirect(GetContextRef().get(), buffer, pReserved); } +FORCE_ALIGN ALenum AL_APIENTRY EAXGetBufferModeDirect(ALCcontext *context, ALuint buffer, + ALint *pReserved) noexcept { #define EAX_PREFIX "[EAXGetBufferMode] " - const auto context = ContextRef{GetContextRef()}; if(!context) { ERR(EAX_PREFIX "%s\n", "No current context."); diff --git a/al/extension.cpp b/al/extension.cpp index dbaf4d5f..077e3324 100644 --- a/al/extension.cpp +++ b/al/extension.cpp @@ -30,14 +30,15 @@ #include "alc/context.h" #include "alstring.h" #include "core/except.h" +#include "direct_defs.h" #include "opthelpers.h" -AL_API ALboolean AL_APIENTRY alIsExtensionPresent(const ALchar *extName) -START_API_FUNC +AL_API DECL_FUNC1(ALboolean, alIsExtensionPresent, const ALchar*) +FORCE_ALIGN ALboolean AL_APIENTRY alIsExtensionPresentDirect(ALCcontext *context, const ALchar *extName) noexcept { - ContextRef context{GetContextRef()}; - if(!context) UNLIKELY return AL_FALSE; + if(!context) UNLIKELY + return AL_FALSE; if(!extName) UNLIKELY { @@ -54,21 +55,28 @@ START_API_FUNC return AL_FALSE; } -END_API_FUNC AL_API ALvoid* AL_APIENTRY alGetProcAddress(const ALchar *funcName) -START_API_FUNC { if(!funcName) return nullptr; return alcGetProcAddress(nullptr, funcName); } -END_API_FUNC + +FORCE_ALIGN ALvoid* AL_APIENTRY alGetProcAddressDirect(ALCcontext*, const ALchar *funcName) noexcept +{ + if(!funcName) return nullptr; + return alcGetProcAddress(nullptr, funcName); +} AL_API ALenum AL_APIENTRY alGetEnumValue(const ALchar *enumName) -START_API_FUNC { if(!enumName) return static_cast(0); return alcGetEnumValue(nullptr, enumName); } -END_API_FUNC + +FORCE_ALIGN ALenum AL_APIENTRY alGetEnumValueDirect(ALCcontext*, const ALchar *enumName) noexcept +{ + if(!enumName) return static_cast(0); + return alcGetEnumValue(nullptr, enumName); +} diff --git a/alc/alc.cpp b/alc/alc.cpp index c9a56d90..23ed101d 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -485,6 +485,11 @@ const struct { DECL(alGetFloatDirect), DECL(alGetDoubleDirect), + DECL(alGetErrorDirect), + DECL(alIsExtensionPresentDirect), + DECL(alGetProcAddress), + DECL(alGetEnumValueDirect), + DECL(alDeferUpdatesDirectSOFT), DECL(alProcessUpdatesDirectSOFT), DECL(alGetStringiDirectSOFT), @@ -495,6 +500,11 @@ const struct { DECL(EAXSet), DECL(EAXGetBufferMode), DECL(EAXSetBufferMode), + + DECL(EAXGetDirect), + DECL(EAXSetDirect), + DECL(EAXGetBufferModeDirect), + DECL(EAXSetBufferModeDirect), #endif }; #undef DECL diff --git a/alc/context.cpp b/alc/context.cpp index d920d4b6..81529adf 100644 --- a/alc/context.cpp +++ b/alc/context.cpp @@ -1049,16 +1049,14 @@ public: } // namespace -FORCE_ALIGN ALenum AL_APIENTRY EAXSet( - const GUID* property_set_id, - ALuint property_id, - ALuint property_source_id, - ALvoid* property_value, +FORCE_ALIGN ALenum AL_APIENTRY EAXSet(const GUID *property_set_id, ALuint property_id, + ALuint property_source_id, ALvoid *property_value, ALuint property_value_size) noexcept +{ return EAXSetDirect(GetContextRef().get(), property_set_id, property_id, property_source_id, property_value, property_value_size); } +FORCE_ALIGN ALenum AL_APIENTRY EAXSetDirect(ALCcontext *context, const GUID *property_set_id, + ALuint property_id, ALuint property_source_id, ALvoid *property_value, ALuint property_value_size) noexcept try { - auto context = GetContextRef(); - if(!context) eax_fail_set("No current context."); @@ -1077,16 +1075,15 @@ catch (...) return AL_INVALID_OPERATION; } -FORCE_ALIGN ALenum AL_APIENTRY EAXGet( - const GUID* property_set_id, - ALuint property_id, - ALuint property_source_id, - ALvoid* property_value, + +FORCE_ALIGN ALenum AL_APIENTRY EAXGet(const GUID *property_set_id, ALuint property_id, + ALuint property_source_id, ALvoid *property_value, ALuint property_value_size) noexcept +{ return EAXGetDirect(GetContextRef().get(), property_set_id, property_id, property_source_id, property_value, property_value_size); } +FORCE_ALIGN ALenum AL_APIENTRY EAXGetDirect(ALCcontext *context, const GUID *property_set_id, + ALuint property_id, ALuint property_source_id, ALvoid *property_value, ALuint property_value_size) noexcept try { - auto context = GetContextRef(); - if(!context) eax_fail_get("No current context."); -- cgit v1.2.3 From b80502e41d4d0fa0978bfa11b73803e5dfa45148 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 14 May 2023 19:44:06 -0700 Subject: Add extension strings for the in-progress direct API --- alc/alc.cpp | 2 ++ alc/context.cpp | 1 + 2 files changed, 3 insertions(+) (limited to 'alc/context.cpp') diff --git a/alc/alc.cpp b/alc/alc.cpp index bddc3384..8b108b51 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -1169,6 +1169,7 @@ constexpr ALCchar alcNoDeviceExtList[] = "ALC_ENUMERATE_ALL_EXT " "ALC_ENUMERATION_EXT " "ALC_EXT_CAPTURE " + "ALC_EXTX_direct_context " "ALC_EXT_EFX " "ALC_EXT_thread_local_context " "ALC_SOFT_loopback " @@ -1180,6 +1181,7 @@ constexpr ALCchar alcExtensionList[] = "ALC_EXT_CAPTURE " "ALC_EXTX_debug " "ALC_EXT_DEDICATED " + "ALC_EXTX_direct_context " "ALC_EXT_disconnect " "ALC_EXT_EFX " "ALC_EXT_thread_local_context " diff --git a/alc/context.cpp b/alc/context.cpp index 81529adf..bcd72f92 100644 --- a/alc/context.cpp +++ b/alc/context.cpp @@ -55,6 +55,7 @@ std::vector getContextExtensions() noexcept "AL_EXT_ALAW", "AL_EXT_BFORMAT", "AL_EXTX_debug", + "AL_EXTX_direct_context", "AL_EXT_DOUBLE", "AL_EXT_EXPONENT_DISTANCE", "AL_EXT_FLOAT32", -- cgit v1.2.3 From 2b7ab0b75086f3d73a7ffe9bc05a80e5d9c625f5 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Thu, 1 Jun 2023 18:16:17 -0700 Subject: Rename threads.cpp/h to alsem.cpp/h --- CMakeLists.txt | 4 +- al/debug.cpp | 1 - al/event.cpp | 1 - al/source.cpp | 1 - alc/alc.cpp | 1 - alc/alu.cpp | 1 - alc/backends/jack.cpp | 2 +- alc/backends/opensl.cpp | 2 +- alc/backends/winmm.cpp | 2 +- alc/context.cpp | 1 - alc/events.cpp | 1 - common/alsem.cpp | 126 ++++++++++++++++++++++++++++++++++++++++++++++++ common/alsem.h | 43 +++++++++++++++++ common/threads.cpp | 125 ----------------------------------------------- common/threads.h | 43 ----------------- core/context.h | 2 +- 16 files changed, 175 insertions(+), 181 deletions(-) create mode 100644 common/alsem.cpp create mode 100644 common/alsem.h delete mode 100644 common/threads.cpp delete mode 100644 common/threads.h (limited to 'alc/context.cpp') diff --git a/CMakeLists.txt b/CMakeLists.txt index 63a213c9..c73dee55 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -618,6 +618,8 @@ set(COMMON_OBJS common/almalloc.h common/alnumbers.h common/alnumeric.h + common/alsem.cpp + common/alsem.h common/alspan.h common/alstring.cpp common/alstring.h @@ -638,8 +640,6 @@ set(COMMON_OBJS common/ringbuffer.h common/strutils.cpp common/strutils.h - common/threads.cpp - common/threads.h common/vecmat.h common/vector.h) diff --git a/al/debug.cpp b/al/debug.cpp index 56705c65..af67859a 100644 --- a/al/debug.cpp +++ b/al/debug.cpp @@ -20,7 +20,6 @@ #include "core/logging.h" #include "direct_defs.h" #include "opthelpers.h" -#include "threads.h" namespace { diff --git a/al/event.cpp b/al/event.cpp index a5b5fdc5..ef58f86d 100644 --- a/al/event.cpp +++ b/al/event.cpp @@ -30,7 +30,6 @@ #include "direct_defs.h" #include "opthelpers.h" #include "ringbuffer.h" -#include "threads.h" namespace { diff --git a/al/source.cpp b/al/source.cpp index 8dbbbcd8..8f4d4d48 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -73,7 +73,6 @@ #include "filter.h" #include "opthelpers.h" #include "ringbuffer.h" -#include "threads.h" #ifdef ALSOFT_EAX #include diff --git a/alc/alc.cpp b/alc/alc.cpp index 128b3d7e..48fa19ec 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -103,7 +103,6 @@ #include "intrusive_ptr.h" #include "opthelpers.h" #include "strutils.h" -#include "threads.h" #include "backends/base.h" #include "backends/null.h" diff --git a/alc/alu.cpp b/alc/alu.cpp index c43da639..0130f280 100644 --- a/alc/alu.cpp +++ b/alc/alu.cpp @@ -77,7 +77,6 @@ #include "opthelpers.h" #include "ringbuffer.h" #include "strutils.h" -#include "threads.h" #include "vecmat.h" #include "vector.h" diff --git a/alc/backends/jack.cpp b/alc/backends/jack.cpp index b8325b05..66fc0877 100644 --- a/alc/backends/jack.cpp +++ b/alc/backends/jack.cpp @@ -35,13 +35,13 @@ #include "albit.h" #include "alc/alconfig.h" #include "alnumeric.h" +#include "alsem.h" #include "althrd_setname.h" #include "core/device.h" #include "core/helpers.h" #include "core/logging.h" #include "dynload.h" #include "ringbuffer.h" -#include "threads.h" #include #include diff --git a/alc/backends/opensl.cpp b/alc/backends/opensl.cpp index a3b70791..2a161056 100644 --- a/alc/backends/opensl.cpp +++ b/alc/backends/opensl.cpp @@ -35,13 +35,13 @@ #include "albit.h" #include "alnumeric.h" +#include "alsem.h" #include "althrd_setname.h" #include "core/device.h" #include "core/helpers.h" #include "core/logging.h" #include "opthelpers.h" #include "ringbuffer.h" -#include "threads.h" #include #include diff --git a/alc/backends/winmm.cpp b/alc/backends/winmm.cpp index fa5bf22a..661585cd 100644 --- a/alc/backends/winmm.cpp +++ b/alc/backends/winmm.cpp @@ -39,13 +39,13 @@ #include #include "alnumeric.h" +#include "alsem.h" #include "althrd_setname.h" #include "core/device.h" #include "core/helpers.h" #include "core/logging.h" #include "ringbuffer.h" #include "strutils.h" -#include "threads.h" #ifndef WAVE_FORMAT_IEEE_FLOAT #define WAVE_FORMAT_IEEE_FLOAT 0x0003 diff --git a/alc/context.cpp b/alc/context.cpp index bcd72f92..142ad50c 100644 --- a/alc/context.cpp +++ b/alc/context.cpp @@ -33,7 +33,6 @@ #include "core/voice_change.h" #include "device.h" #include "ringbuffer.h" -#include "threads.h" #include "vecmat.h" #ifdef ALSOFT_EAX diff --git a/alc/events.cpp b/alc/events.cpp index b5b65cb1..b14b1a8d 100644 --- a/alc/events.cpp +++ b/alc/events.cpp @@ -6,7 +6,6 @@ #include #include "alspan.h" -#include "common/threads.h" #include "core/logging.h" #include "device.h" diff --git a/common/alsem.cpp b/common/alsem.cpp new file mode 100644 index 00000000..6a92b35c --- /dev/null +++ b/common/alsem.cpp @@ -0,0 +1,126 @@ +/** + * OpenAL cross platform audio library + * Copyright (C) 1999-2007 by authors. + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * Or go to http://www.gnu.org/copyleft/lgpl.html + */ + +#include "config.h" + +#include "alsem.h" + +#include + +#include "opthelpers.h" + + +#ifdef _WIN32 +#define WIN32_LEAN_AND_MEAN +#include + +#include + +namespace al { + +semaphore::semaphore(unsigned int initial) +{ + if(initial > static_cast(std::numeric_limits::max())) + throw std::system_error(std::make_error_code(std::errc::value_too_large)); + mSem = CreateSemaphore(nullptr, initial, std::numeric_limits::max(), nullptr); + if(mSem == nullptr) + throw std::system_error(std::make_error_code(std::errc::resource_unavailable_try_again)); +} + +semaphore::~semaphore() +{ CloseHandle(mSem); } + +void semaphore::post() +{ + if(!ReleaseSemaphore(static_cast(mSem), 1, nullptr)) + throw std::system_error(std::make_error_code(std::errc::value_too_large)); +} + +void semaphore::wait() noexcept +{ WaitForSingleObject(static_cast(mSem), INFINITE); } + +bool semaphore::try_wait() noexcept +{ return WaitForSingleObject(static_cast(mSem), 0) == WAIT_OBJECT_0; } + +} // namespace al + +#else + +/* Do not try using libdispatch on systems where it is absent. */ +#if defined(AL_APPLE_HAVE_DISPATCH) + +namespace al { + +semaphore::semaphore(unsigned int initial) +{ + mSem = dispatch_semaphore_create(initial); + if(!mSem) + throw std::system_error(std::make_error_code(std::errc::resource_unavailable_try_again)); +} + +semaphore::~semaphore() +{ dispatch_release(mSem); } + +void semaphore::post() +{ dispatch_semaphore_signal(mSem); } + +void semaphore::wait() noexcept +{ dispatch_semaphore_wait(mSem, DISPATCH_TIME_FOREVER); } + +bool semaphore::try_wait() noexcept +{ return dispatch_semaphore_wait(mSem, DISPATCH_TIME_NOW) == 0; } + +} // namespace al + +#else /* !__APPLE__ */ + +#include + +namespace al { + +semaphore::semaphore(unsigned int initial) +{ + if(sem_init(&mSem, 0, initial) != 0) + throw std::system_error(std::make_error_code(std::errc::resource_unavailable_try_again)); +} + +semaphore::~semaphore() +{ sem_destroy(&mSem); } + +void semaphore::post() +{ + if(sem_post(&mSem) != 0) + throw std::system_error(std::make_error_code(std::errc::value_too_large)); +} + +void semaphore::wait() noexcept +{ + while(sem_wait(&mSem) == -1 && errno == EINTR) { + } +} + +bool semaphore::try_wait() noexcept +{ return sem_trywait(&mSem) == 0; } + +} // namespace al + +#endif /* __APPLE__ */ + +#endif /* _WIN32 */ diff --git a/common/alsem.h b/common/alsem.h new file mode 100644 index 00000000..9f72d1c6 --- /dev/null +++ b/common/alsem.h @@ -0,0 +1,43 @@ +#ifndef COMMON_ALSEM_H +#define COMMON_ALSEM_H + +#if defined(__APPLE__) +#include +#include +#if (((MAC_OS_X_VERSION_MIN_REQUIRED > 1050) && !defined(__ppc__)) || TARGET_OS_IOS || TARGET_OS_TV) +#include +#define AL_APPLE_HAVE_DISPATCH 1 +#else +#include /* Fallback option for Apple without a working libdispatch */ +#endif +#elif !defined(_WIN32) +#include +#endif + +namespace al { + +class semaphore { +#ifdef _WIN32 + using native_type = void*; +#elif defined(AL_APPLE_HAVE_DISPATCH) + using native_type = dispatch_semaphore_t; +#else + using native_type = sem_t; +#endif + native_type mSem; + +public: + semaphore(unsigned int initial=0); + semaphore(const semaphore&) = delete; + ~semaphore(); + + semaphore& operator=(const semaphore&) = delete; + + void post(); + void wait() noexcept; + bool try_wait() noexcept; +}; + +} // namespace al + +#endif /* COMMON_ALSEM_H */ diff --git a/common/threads.cpp b/common/threads.cpp deleted file mode 100644 index c176f5af..00000000 --- a/common/threads.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/** - * OpenAL cross platform audio library - * Copyright (C) 1999-2007 by authors. - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * Or go to http://www.gnu.org/copyleft/lgpl.html - */ - -#include "config.h" - -#include "opthelpers.h" -#include "threads.h" - -#include - - -#ifdef _WIN32 -#define WIN32_LEAN_AND_MEAN -#include - -#include - -namespace al { - -semaphore::semaphore(unsigned int initial) -{ - if(initial > static_cast(std::numeric_limits::max())) - throw std::system_error(std::make_error_code(std::errc::value_too_large)); - mSem = CreateSemaphore(nullptr, initial, std::numeric_limits::max(), nullptr); - if(mSem == nullptr) - throw std::system_error(std::make_error_code(std::errc::resource_unavailable_try_again)); -} - -semaphore::~semaphore() -{ CloseHandle(mSem); } - -void semaphore::post() -{ - if(!ReleaseSemaphore(static_cast(mSem), 1, nullptr)) - throw std::system_error(std::make_error_code(std::errc::value_too_large)); -} - -void semaphore::wait() noexcept -{ WaitForSingleObject(static_cast(mSem), INFINITE); } - -bool semaphore::try_wait() noexcept -{ return WaitForSingleObject(static_cast(mSem), 0) == WAIT_OBJECT_0; } - -} // namespace al - -#else - -/* Do not try using libdispatch on systems where it is absent. */ -#if defined(AL_APPLE_HAVE_DISPATCH) - -namespace al { - -semaphore::semaphore(unsigned int initial) -{ - mSem = dispatch_semaphore_create(initial); - if(!mSem) - throw std::system_error(std::make_error_code(std::errc::resource_unavailable_try_again)); -} - -semaphore::~semaphore() -{ dispatch_release(mSem); } - -void semaphore::post() -{ dispatch_semaphore_signal(mSem); } - -void semaphore::wait() noexcept -{ dispatch_semaphore_wait(mSem, DISPATCH_TIME_FOREVER); } - -bool semaphore::try_wait() noexcept -{ return dispatch_semaphore_wait(mSem, DISPATCH_TIME_NOW) == 0; } - -} // namespace al - -#else /* !__APPLE__ */ - -#include - -namespace al { - -semaphore::semaphore(unsigned int initial) -{ - if(sem_init(&mSem, 0, initial) != 0) - throw std::system_error(std::make_error_code(std::errc::resource_unavailable_try_again)); -} - -semaphore::~semaphore() -{ sem_destroy(&mSem); } - -void semaphore::post() -{ - if(sem_post(&mSem) != 0) - throw std::system_error(std::make_error_code(std::errc::value_too_large)); -} - -void semaphore::wait() noexcept -{ - while(sem_wait(&mSem) == -1 && errno == EINTR) { - } -} - -bool semaphore::try_wait() noexcept -{ return sem_trywait(&mSem) == 0; } - -} // namespace al - -#endif /* __APPLE__ */ - -#endif /* _WIN32 */ diff --git a/common/threads.h b/common/threads.h deleted file mode 100644 index 703d50d4..00000000 --- a/common/threads.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef AL_THREADS_H -#define AL_THREADS_H - -#if defined(__APPLE__) -#include -#include -#if (((MAC_OS_X_VERSION_MIN_REQUIRED > 1050) && !defined(__ppc__)) || TARGET_OS_IOS || TARGET_OS_TV) -#include -#define AL_APPLE_HAVE_DISPATCH 1 -#else -#include /* Fallback option for Apple without a working libdispatch */ -#endif -#elif !defined(_WIN32) -#include -#endif - -namespace al { - -class semaphore { -#ifdef _WIN32 - using native_type = void*; -#elif defined(AL_APPLE_HAVE_DISPATCH) - using native_type = dispatch_semaphore_t; -#else - using native_type = sem_t; -#endif - native_type mSem; - -public: - semaphore(unsigned int initial=0); - semaphore(const semaphore&) = delete; - ~semaphore(); - - semaphore& operator=(const semaphore&) = delete; - - void post(); - void wait() noexcept; - bool try_wait() noexcept; -}; - -} // namespace al - -#endif /* AL_THREADS_H */ diff --git a/core/context.h b/core/context.h index 629e67a5..ccb7dd3b 100644 --- a/core/context.h +++ b/core/context.h @@ -10,11 +10,11 @@ #include #include "almalloc.h" +#include "alsem.h" #include "alspan.h" #include "async_event.h" #include "atomic.h" #include "opthelpers.h" -#include "threads.h" #include "vecmat.h" struct DeviceBase; -- cgit v1.2.3 From 3b7e3a164fa0ea734308f1db69c8537ac4bab4d2 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 11 Aug 2023 13:11:42 -0700 Subject: Make AL(C)_EXT_debug public --- alc/alc.cpp | 2 +- alc/context.cpp | 2 +- alc/inprogext.h | 66 ------------------------------------------------------ include/AL/alext.h | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 68 deletions(-) (limited to 'alc/context.cpp') diff --git a/alc/alc.cpp b/alc/alc.cpp index 45a55793..b2a5355a 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -312,7 +312,7 @@ constexpr ALCchar alcExtensionList[] = "ALC_ENUMERATE_ALL_EXT " "ALC_ENUMERATION_EXT " "ALC_EXT_CAPTURE " - "ALC_EXTX_debug " + "ALC_EXT_debug " "ALC_EXT_DEDICATED " "ALC_EXTX_direct_context " "ALC_EXT_disconnect " diff --git a/alc/context.cpp b/alc/context.cpp index 142ad50c..9c5a62c4 100644 --- a/alc/context.cpp +++ b/alc/context.cpp @@ -53,7 +53,7 @@ std::vector getContextExtensions() noexcept return std::vector{ "AL_EXT_ALAW", "AL_EXT_BFORMAT", - "AL_EXTX_debug", + "AL_EXT_debug", "AL_EXTX_direct_context", "AL_EXT_DOUBLE", "AL_EXT_EXPONENT_DISTANCE", diff --git a/alc/inprogext.h b/alc/inprogext.h index dc1744ee..739af517 100644 --- a/alc/inprogext.h +++ b/alc/inprogext.h @@ -62,72 +62,6 @@ AL_API void AL_APIENTRY alAuxiliaryEffectSlotStopvSOFT(ALsizei n, const ALuint * #define AL_STOP_SOURCES_ON_DISCONNECT_SOFT 0x19AB #endif -#ifndef ALC_EXT_debug -#define ALC_EXT_debug -#define ALC_CONTEXT_FLAGS_EXT 0x19CE -#define ALC_CONTEXT_DEBUG_BIT_EXT 0x0001 -#endif - -#ifndef AL_EXT_debug -#define AL_EXT_debug -#define AL_DONT_CARE_EXT 0x0002 -#define AL_DEBUG_OUTPUT_EXT 0x19B2 -#define AL_DEBUG_CALLBACK_FUNCTION_EXT 0x19B3 -#define AL_DEBUG_CALLBACK_USER_PARAM_EXT 0x19B4 -#define AL_DEBUG_SOURCE_API_EXT 0x19B5 -#define AL_DEBUG_SOURCE_AUDIO_SYSTEM_EXT 0x19B6 -#define AL_DEBUG_SOURCE_THIRD_PARTY_EXT 0x19B7 -#define AL_DEBUG_SOURCE_APPLICATION_EXT 0x19B8 -#define AL_DEBUG_SOURCE_OTHER_EXT 0x19B9 -#define AL_DEBUG_TYPE_ERROR_EXT 0x19BA -#define AL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_EXT 0x19BB -#define AL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_EXT 0x19BC -#define AL_DEBUG_TYPE_PORTABILITY_EXT 0x19BD -#define AL_DEBUG_TYPE_PERFORMANCE_EXT 0x19BE -#define AL_DEBUG_TYPE_MARKER_EXT 0x19BF -#define AL_DEBUG_TYPE_PUSH_GROUP_EXT 0x19C0 -#define AL_DEBUG_TYPE_POP_GROUP_EXT 0x19C1 -#define AL_DEBUG_TYPE_OTHER_EXT 0x19C2 -#define AL_DEBUG_SEVERITY_HIGH_EXT 0x19C3 -#define AL_DEBUG_SEVERITY_MEDIUM_EXT 0x19C4 -#define AL_DEBUG_SEVERITY_LOW_EXT 0x19C5 -#define AL_DEBUG_SEVERITY_NOTIFICATION_EXT 0x19C6 -#define AL_DEBUG_LOGGED_MESSAGES_EXT 0x19C7 -#define AL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_EXT 0x19C8 -#define AL_MAX_DEBUG_MESSAGE_LENGTH_EXT 0x19C9 -#define AL_MAX_DEBUG_LOGGED_MESSAGES_EXT 0x19CA -#define AL_MAX_DEBUG_GROUP_STACK_DEPTH_EXT 0x19CB -#define AL_MAX_LABEL_LENGTH_EXT 0x19CC -#define AL_STACK_OVERFLOW_EXT 0x19CD -#define AL_STACK_UNDERFLOW_EXT 0x19CE -#define AL_CONTEXT_FLAGS_EXT 0x19CF -#define AL_BUFFER_EXT 0x1009 /* Same as AL_BUFFER */ -#define AL_SOURCE_EXT 0x19D0 -#define AL_FILTER_EXT 0x19D1 -#define AL_EFFECT_EXT 0x19D2 -#define AL_AUXILIARY_EFFECT_SLOT_EXT 0x19D3 - -typedef void (AL_APIENTRY*ALDEBUGPROCEXT)(ALenum source, ALenum type, ALuint id, ALenum severity, ALsizei length, const ALchar *message, void *userParam) AL_API_NOEXCEPT17; -typedef void (AL_APIENTRY*LPALDEBUGMESSAGECALLBACKEXT)(ALDEBUGPROCEXT callback, void *userParam) AL_API_NOEXCEPT17; -typedef void (AL_APIENTRY*LPALDEBUGMESSAGEINSERTEXT)(ALenum source, ALenum type, ALuint id, ALenum severity, ALsizei length, const ALchar *message) AL_API_NOEXCEPT17; -typedef void (AL_APIENTRY*LPALDEBUGMESSAGECONTROLEXT)(ALenum source, ALenum type, ALenum severity, ALsizei count, const ALuint *ids, ALboolean enable) AL_API_NOEXCEPT17; -typedef void (AL_APIENTRY*LPALPUSHDEBUGGROUPEXT)(ALenum source, ALuint id, ALsizei length, const ALchar *message) AL_API_NOEXCEPT17; -typedef void (AL_APIENTRY*LPALPOPDEBUGGROUPEXT)(void) AL_API_NOEXCEPT17; -typedef ALuint (AL_APIENTRY*LPALGETDEBUGMESSAGELOGEXT)(ALuint count, ALsizei logBufSize, ALenum *sources, ALenum *types, ALuint *ids, ALenum *severities, ALsizei *lengths, ALchar *logBuf) AL_API_NOEXCEPT17; -typedef void (AL_APIENTRY*LPALOBJECTLABELEXT)(ALenum identifier, ALuint name, ALsizei length, const ALchar *label) AL_API_NOEXCEPT17; -typedef void (AL_APIENTRY*LPALGETOBJECTLABELEXT)(ALenum identifier, ALuint name, ALsizei bufSize, ALsizei *length, ALchar *label) AL_API_NOEXCEPT17; -#ifdef AL_ALEXT_PROTOTYPES -void AL_APIENTRY alDebugMessageCallbackEXT(ALDEBUGPROCEXT callback, void *userParam) AL_API_NOEXCEPT; -void AL_APIENTRY alDebugMessageInsertEXT(ALenum source, ALenum type, ALuint id, ALenum severity, ALsizei length, const ALchar *message) AL_API_NOEXCEPT; -void AL_APIENTRY alDebugMessageControlEXT(ALenum source, ALenum type, ALenum severity, ALsizei count, const ALuint *ids, ALboolean enable) AL_API_NOEXCEPT; -void AL_APIENTRY alPushDebugGroupEXT(ALenum source, ALuint id, ALsizei length, const ALchar *message) AL_API_NOEXCEPT; -void AL_APIENTRY alPopDebugGroupEXT(void) AL_API_NOEXCEPT; -ALuint AL_APIENTRY alGetDebugMessageLogEXT(ALuint count, ALsizei logBufSize, ALenum *sources, ALenum *types, ALuint *ids, ALenum *severities, ALsizei *lengths, ALchar *logBuf) AL_API_NOEXCEPT; -void AL_APIENTRY alObjectLabelEXT(ALenum identifier, ALuint name, ALsizei length, const ALchar *label) AL_API_NOEXCEPT; -void AL_APIENTRY alGetObjectLabelEXT(ALenum identifier, ALuint name, ALsizei bufSize, ALsizei *length, ALchar *label) AL_API_NOEXCEPT; -#endif -#endif - #ifndef AL_EXT_direct_context #define AL_EXT_direct_context diff --git a/include/AL/alext.h b/include/AL/alext.h index c4f4d4b2..7ac09010 100644 --- a/include/AL/alext.h +++ b/include/AL/alext.h @@ -647,6 +647,72 @@ void AL_APIENTRY alSourcePlayAtTimevSOFT(ALsizei n, const ALuint *sources, ALint #endif #endif +#ifndef ALC_EXT_debug +#define ALC_EXT_debug +#define ALC_CONTEXT_FLAGS_EXT 0x19CE +#define ALC_CONTEXT_DEBUG_BIT_EXT 0x0001 +#endif + +#ifndef AL_EXT_debug +#define AL_EXT_debug +#define AL_DONT_CARE_EXT 0x0002 +#define AL_DEBUG_OUTPUT_EXT 0x19B2 +#define AL_DEBUG_CALLBACK_FUNCTION_EXT 0x19B3 +#define AL_DEBUG_CALLBACK_USER_PARAM_EXT 0x19B4 +#define AL_DEBUG_SOURCE_API_EXT 0x19B5 +#define AL_DEBUG_SOURCE_AUDIO_SYSTEM_EXT 0x19B6 +#define AL_DEBUG_SOURCE_THIRD_PARTY_EXT 0x19B7 +#define AL_DEBUG_SOURCE_APPLICATION_EXT 0x19B8 +#define AL_DEBUG_SOURCE_OTHER_EXT 0x19B9 +#define AL_DEBUG_TYPE_ERROR_EXT 0x19BA +#define AL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_EXT 0x19BB +#define AL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_EXT 0x19BC +#define AL_DEBUG_TYPE_PORTABILITY_EXT 0x19BD +#define AL_DEBUG_TYPE_PERFORMANCE_EXT 0x19BE +#define AL_DEBUG_TYPE_MARKER_EXT 0x19BF +#define AL_DEBUG_TYPE_PUSH_GROUP_EXT 0x19C0 +#define AL_DEBUG_TYPE_POP_GROUP_EXT 0x19C1 +#define AL_DEBUG_TYPE_OTHER_EXT 0x19C2 +#define AL_DEBUG_SEVERITY_HIGH_EXT 0x19C3 +#define AL_DEBUG_SEVERITY_MEDIUM_EXT 0x19C4 +#define AL_DEBUG_SEVERITY_LOW_EXT 0x19C5 +#define AL_DEBUG_SEVERITY_NOTIFICATION_EXT 0x19C6 +#define AL_DEBUG_LOGGED_MESSAGES_EXT 0x19C7 +#define AL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_EXT 0x19C8 +#define AL_MAX_DEBUG_MESSAGE_LENGTH_EXT 0x19C9 +#define AL_MAX_DEBUG_LOGGED_MESSAGES_EXT 0x19CA +#define AL_MAX_DEBUG_GROUP_STACK_DEPTH_EXT 0x19CB +#define AL_MAX_LABEL_LENGTH_EXT 0x19CC +#define AL_STACK_OVERFLOW_EXT 0x19CD +#define AL_STACK_UNDERFLOW_EXT 0x19CE +#define AL_CONTEXT_FLAGS_EXT 0x19CF +#define AL_BUFFER_EXT 0x1009 /* Same as AL_BUFFER */ +#define AL_SOURCE_EXT 0x19D0 +#define AL_FILTER_EXT 0x19D1 +#define AL_EFFECT_EXT 0x19D2 +#define AL_AUXILIARY_EFFECT_SLOT_EXT 0x19D3 + +typedef void (AL_APIENTRY*ALDEBUGPROCEXT)(ALenum source, ALenum type, ALuint id, ALenum severity, ALsizei length, const ALchar *message, void *userParam) AL_API_NOEXCEPT17; +typedef void (AL_APIENTRY*LPALDEBUGMESSAGECALLBACKEXT)(ALDEBUGPROCEXT callback, void *userParam) AL_API_NOEXCEPT17; +typedef void (AL_APIENTRY*LPALDEBUGMESSAGEINSERTEXT)(ALenum source, ALenum type, ALuint id, ALenum severity, ALsizei length, const ALchar *message) AL_API_NOEXCEPT17; +typedef void (AL_APIENTRY*LPALDEBUGMESSAGECONTROLEXT)(ALenum source, ALenum type, ALenum severity, ALsizei count, const ALuint *ids, ALboolean enable) AL_API_NOEXCEPT17; +typedef void (AL_APIENTRY*LPALPUSHDEBUGGROUPEXT)(ALenum source, ALuint id, ALsizei length, const ALchar *message) AL_API_NOEXCEPT17; +typedef void (AL_APIENTRY*LPALPOPDEBUGGROUPEXT)(void) AL_API_NOEXCEPT17; +typedef ALuint (AL_APIENTRY*LPALGETDEBUGMESSAGELOGEXT)(ALuint count, ALsizei logBufSize, ALenum *sources, ALenum *types, ALuint *ids, ALenum *severities, ALsizei *lengths, ALchar *logBuf) AL_API_NOEXCEPT17; +typedef void (AL_APIENTRY*LPALOBJECTLABELEXT)(ALenum identifier, ALuint name, ALsizei length, const ALchar *label) AL_API_NOEXCEPT17; +typedef void (AL_APIENTRY*LPALGETOBJECTLABELEXT)(ALenum identifier, ALuint name, ALsizei bufSize, ALsizei *length, ALchar *label) AL_API_NOEXCEPT17; +#ifdef AL_ALEXT_PROTOTYPES +void AL_APIENTRY alDebugMessageCallbackEXT(ALDEBUGPROCEXT callback, void *userParam) AL_API_NOEXCEPT; +void AL_APIENTRY alDebugMessageInsertEXT(ALenum source, ALenum type, ALuint id, ALenum severity, ALsizei length, const ALchar *message) AL_API_NOEXCEPT; +void AL_APIENTRY alDebugMessageControlEXT(ALenum source, ALenum type, ALenum severity, ALsizei count, const ALuint *ids, ALboolean enable) AL_API_NOEXCEPT; +void AL_APIENTRY alPushDebugGroupEXT(ALenum source, ALuint id, ALsizei length, const ALchar *message) AL_API_NOEXCEPT; +void AL_APIENTRY alPopDebugGroupEXT(void) AL_API_NOEXCEPT; +ALuint AL_APIENTRY alGetDebugMessageLogEXT(ALuint count, ALsizei logBufSize, ALenum *sources, ALenum *types, ALuint *ids, ALenum *severities, ALsizei *lengths, ALchar *logBuf) AL_API_NOEXCEPT; +void AL_APIENTRY alObjectLabelEXT(ALenum identifier, ALuint name, ALsizei length, const ALchar *label) AL_API_NOEXCEPT; +void AL_APIENTRY alGetObjectLabelEXT(ALenum identifier, ALuint name, ALsizei bufSize, ALsizei *length, ALchar *label) AL_API_NOEXCEPT; +#endif +#endif + #ifdef __cplusplus } #endif -- cgit v1.2.3 From 2b05b61a4a941280391e7b97e1b6b423e4dae6e2 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 13 Aug 2023 09:23:55 -0700 Subject: Don't null check the context in the direct EAX functions --- al/buffer.cpp | 18 ++---------------- alc/context.cpp | 54 +++++++++++++----------------------------------------- 2 files changed, 15 insertions(+), 57 deletions(-) (limited to 'alc/context.cpp') diff --git a/al/buffer.cpp b/al/buffer.cpp index e56aa13e..28afc7c0 100644 --- a/al/buffer.cpp +++ b/al/buffer.cpp @@ -1474,19 +1474,12 @@ BufferSubList::~BufferSubList() #ifdef ALSOFT_EAX -FORCE_ALIGN ALboolean AL_APIENTRY EAXSetBufferMode(ALsizei n, const ALuint *buffers, ALint value) noexcept -{ return EAXSetBufferModeDirect(GetContextRef().get(), n, buffers, value); } +FORCE_ALIGN DECL_FUNC3(ALboolean, EAXSetBufferMode, ALsizei, const ALuint*, ALint) FORCE_ALIGN ALboolean AL_APIENTRY EAXSetBufferModeDirect(ALCcontext *context, ALsizei n, const ALuint *buffers, ALint value) noexcept { #define EAX_PREFIX "[EAXSetBufferMode] " - if(!context) - { - ERR(EAX_PREFIX "%s\n", "No current context."); - return AL_FALSE; - } - if(!eax_g_is_enabled) { context->setError(AL_INVALID_OPERATION, EAX_PREFIX "%s", "EAX not enabled."); @@ -1617,19 +1610,12 @@ FORCE_ALIGN ALboolean AL_APIENTRY EAXSetBufferModeDirect(ALCcontext *context, AL #undef EAX_PREFIX } -FORCE_ALIGN ALenum AL_APIENTRY EAXGetBufferMode(ALuint buffer, ALint *pReserved) noexcept -{ return EAXGetBufferModeDirect(GetContextRef().get(), buffer, pReserved); } +FORCE_ALIGN DECL_FUNC2(ALenum, EAXGetBufferMode, ALuint, ALint*) FORCE_ALIGN ALenum AL_APIENTRY EAXGetBufferModeDirect(ALCcontext *context, ALuint buffer, ALint *pReserved) noexcept { #define EAX_PREFIX "[EAXGetBufferMode] " - if(!context) - { - ERR(EAX_PREFIX "%s\n", "No current context."); - return AL_NONE; - } - if(!eax_g_is_enabled) { context->setError(AL_INVALID_OPERATION, EAX_PREFIX "%s", "EAX not enabled."); diff --git a/alc/context.cpp b/alc/context.cpp index 9c5a62c4..bba74a59 100644 --- a/alc/context.cpp +++ b/alc/context.cpp @@ -1020,48 +1020,20 @@ void ALCcontext::eaxCommit() eax_update_sources(); } -namespace { - -class EaxSetException : public EaxException { -public: - explicit EaxSetException(const char* message) - : EaxException{"EAX_SET", message} - {} -}; - -[[noreturn]] void eax_fail_set(const char* message) -{ - throw EaxSetException{message}; -} - -class EaxGetException : public EaxException { -public: - explicit EaxGetException(const char* message) - : EaxException{"EAX_GET", message} - {} -}; -[[noreturn]] void eax_fail_get(const char* message) +FORCE_ALIGN ALenum AL_APIENTRY EAXSet(const GUID *a, ALuint b, ALuint c, ALvoid *d, ALuint e) noexcept { - throw EaxGetException{message}; + auto context = GetContextRef(); + if(!context) UNLIKELY return AL_INVALID_OPERATION; + return EAXSetDirect(context.get(), a, b, c, d, e); } -} // namespace - - -FORCE_ALIGN ALenum AL_APIENTRY EAXSet(const GUID *property_set_id, ALuint property_id, - ALuint property_source_id, ALvoid *property_value, ALuint property_value_size) noexcept -{ return EAXSetDirect(GetContextRef().get(), property_set_id, property_id, property_source_id, property_value, property_value_size); } FORCE_ALIGN ALenum AL_APIENTRY EAXSetDirect(ALCcontext *context, const GUID *property_set_id, ALuint property_id, ALuint property_source_id, ALvoid *property_value, ALuint property_value_size) noexcept try { - if(!context) - eax_fail_set("No current context."); - std::lock_guard prop_lock{context->mPropLock}; - return context->eax_eax_set( property_set_id, property_id, @@ -1069,26 +1041,26 @@ try property_value, property_value_size); } -catch (...) +catch(...) { eax_log_exception(__func__); return AL_INVALID_OPERATION; } -FORCE_ALIGN ALenum AL_APIENTRY EAXGet(const GUID *property_set_id, ALuint property_id, - ALuint property_source_id, ALvoid *property_value, ALuint property_value_size) noexcept -{ return EAXGetDirect(GetContextRef().get(), property_set_id, property_id, property_source_id, property_value, property_value_size); } +FORCE_ALIGN ALenum AL_APIENTRY EAXGet(const GUID *a, ALuint b, ALuint c, ALvoid *d, ALuint e) noexcept +{ + auto context = GetContextRef(); + if(!context) UNLIKELY return AL_INVALID_OPERATION; + return EAXGetDirect(context.get(), a, b, c, d, e); +} + FORCE_ALIGN ALenum AL_APIENTRY EAXGetDirect(ALCcontext *context, const GUID *property_set_id, ALuint property_id, ALuint property_source_id, ALvoid *property_value, ALuint property_value_size) noexcept try { - if(!context) - eax_fail_get("No current context."); - std::lock_guard prop_lock{context->mPropLock}; - return context->eax_eax_get( property_set_id, property_id, @@ -1096,7 +1068,7 @@ try property_value, property_value_size); } -catch (...) +catch(...) { eax_log_exception(__func__); return AL_INVALID_OPERATION; -- cgit v1.2.3 From 6722ad196145ef7334d7478bdd375308801e7096 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 11 Sep 2023 19:34:55 -0700 Subject: Make some global and static member variables inline This also seems to work around the problematic MinGW code generation, so the indirection to access it can be removed. --- alc/context.cpp | 8 -------- alc/context.h | 11 +---------- router/al.cpp | 2 -- router/router.cpp | 9 --------- router/router.h | 18 +++++------------- 5 files changed, 6 insertions(+), 42 deletions(-) (limited to 'alc/context.cpp') diff --git a/alc/context.cpp b/alc/context.cpp index bba74a59..3b1de7b9 100644 --- a/alc/context.cpp +++ b/alc/context.cpp @@ -102,7 +102,6 @@ std::vector getContextExtensions() noexcept std::atomic ALCcontext::sGlobalContextLock{false}; std::atomic ALCcontext::sGlobalContext{nullptr}; -thread_local ALCcontext *ALCcontext::sLocalContext{nullptr}; ALCcontext::ThreadCtx::~ThreadCtx() { if(ALCcontext *ctx{std::exchange(ALCcontext::sLocalContext, nullptr)}) @@ -117,13 +116,6 @@ thread_local ALCcontext::ThreadCtx ALCcontext::sThreadContext; ALeffect ALCcontext::sDefaultEffect; -#ifdef __MINGW32__ -ALCcontext *ALCcontext::getThreadContext() noexcept -{ return sLocalContext; } -void ALCcontext::setThreadContext(ALCcontext *context) noexcept -{ sThreadContext.set(context); } -#endif - ALCcontext::ALCcontext(al::intrusive_ptr device, ContextFlagBitset flags) : ContextBase{device.get()}, mALDevice{std::move(device)}, mContextFlags{flags} { diff --git a/alc/context.h b/alc/context.h index f936bbe8..201c8873 100644 --- a/alc/context.h +++ b/alc/context.h @@ -211,7 +211,7 @@ struct ALCcontext : public al::intrusive_ref, ContextBase { private: /* Thread-local current context. */ - static thread_local ALCcontext *sLocalContext; + static inline thread_local ALCcontext *sLocalContext{}; /* Thread-local context handling. This handles attempting to release the * context which may have been left current when the thread is destroyed. @@ -224,17 +224,8 @@ private: static thread_local ThreadCtx sThreadContext; public: - /* HACK: MinGW generates bad code when accessing an extern thread_local - * object. Add a wrapper function for it that only accesses it where it's - * defined. - */ -#ifdef __MINGW32__ - static ALCcontext *getThreadContext() noexcept; - static void setThreadContext(ALCcontext *context) noexcept; -#else static ALCcontext *getThreadContext() noexcept { return sLocalContext; } static void setThreadContext(ALCcontext *context) noexcept { sThreadContext.set(context); } -#endif /* Default effect that applies to sources that don't have an effect on send 0. */ static ALeffect sDefaultEffect; diff --git a/router/al.cpp b/router/al.cpp index c7e01d51..6ed8a626 100644 --- a/router/al.cpp +++ b/router/al.cpp @@ -7,8 +7,6 @@ #include "router.h" -std::atomic CurrentCtxDriver{nullptr}; - #define DECL_THUNK1(R,n,T1) AL_API R AL_APIENTRY n(T1 a) noexcept \ { \ DriverIface *iface = GetThreadDriver(); \ diff --git a/router/router.cpp b/router/router.cpp index b2274c0b..e2ba91d1 100644 --- a/router/router.cpp +++ b/router/router.cpp @@ -17,18 +17,9 @@ #include "version.h" -std::vector DriverList; - -thread_local DriverIface *ThreadCtxDriver; - enum LogLevel LogLevel = LogLevel_Error; FILE *LogFile; -#ifdef __MINGW32__ -DriverIface *GetThreadDriver() noexcept { return ThreadCtxDriver; } -void SetThreadDriver(DriverIface *driver) noexcept { ThreadCtxDriver = driver; } -#endif - static void LoadDriverList(void); diff --git a/router/router.h b/router/router.h index 2a126d42..f5c7f455 100644 --- a/router/router.h +++ b/router/router.h @@ -173,21 +173,13 @@ struct DriverIface { }; using DriverIfacePtr = std::unique_ptr; -extern std::vector DriverList; - -extern thread_local DriverIface *ThreadCtxDriver; -extern std::atomic CurrentCtxDriver; - -/* HACK: MinGW generates bad code when accessing an extern thread_local object. - * Add a wrapper function for it that only accesses it where it's defined. - */ -#ifdef __MINGW32__ -DriverIface *GetThreadDriver() noexcept; -void SetThreadDriver(DriverIface *driver) noexcept; -#else +inline std::vector DriverList; + +inline thread_local DriverIface *ThreadCtxDriver{}; +inline std::atomic CurrentCtxDriver{}; + inline DriverIface *GetThreadDriver() noexcept { return ThreadCtxDriver; } inline void SetThreadDriver(DriverIface *driver) noexcept { ThreadCtxDriver = driver; } -#endif class PtrIntMap { -- cgit v1.2.3 From c53ed17c59345526ba41b62bd886c2cbaaca423b Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 22 Sep 2023 13:13:09 -0700 Subject: Avoid casting an integer literal --- al/auxeffectslot.cpp | 2 +- al/buffer.cpp | 2 +- al/eax/call.h | 2 +- al/effect.cpp | 2 +- al/filter.cpp | 2 +- al/source.cpp | 29 +++++++++++++++++------------ al/state.cpp | 2 +- alc/alu.cpp | 2 +- alc/backends/wave.cpp | 4 ++-- alc/context.cpp | 4 ++-- alc/device.cpp | 6 +++--- core/hrtf.cpp | 2 +- core/mixer/mixer_neon.cpp | 4 ++-- core/mixer/mixer_sse.cpp | 4 ++-- core/voice.cpp | 4 ++-- 15 files changed, 38 insertions(+), 33 deletions(-) (limited to 'alc/context.cpp') diff --git a/al/auxeffectslot.cpp b/al/auxeffectslot.cpp index 66a65b5c..33252410 100644 --- a/al/auxeffectslot.cpp +++ b/al/auxeffectslot.cpp @@ -239,7 +239,7 @@ EffectSlotType EffectSlotTypeFromEnum(ALenum type) bool EnsureEffectSlots(ALCcontext *context, size_t needed) { size_t count{std::accumulate(context->mEffectSlotList.cbegin(), - context->mEffectSlotList.cend(), size_t{0}, + context->mEffectSlotList.cend(), 0_uz, [](size_t cur, const EffectSlotSubList &sublist) noexcept -> size_t { return cur + static_cast(al::popcount(sublist.FreeMask)); })}; diff --git a/al/buffer.cpp b/al/buffer.cpp index 28afc7c0..8ba874e4 100644 --- a/al/buffer.cpp +++ b/al/buffer.cpp @@ -174,7 +174,7 @@ constexpr ALbitfieldSOFT INVALID_MAP_FLAGS{~unsigned(AL_MAP_READ_BIT_SOFT | AL_M bool EnsureBuffers(ALCdevice *device, size_t needed) { - size_t count{std::accumulate(device->BufferList.cbegin(), device->BufferList.cend(), size_t{0}, + size_t count{std::accumulate(device->BufferList.cbegin(), device->BufferList.cend(), 0_uz, [](size_t cur, const BufferSubList &sublist) noexcept -> size_t { return cur + static_cast(al::popcount(sublist.FreeMask)); })}; diff --git a/al/eax/call.h b/al/eax/call.h index f2ad529e..45ff328c 100644 --- a/al/eax/call.h +++ b/al/eax/call.h @@ -61,7 +61,7 @@ public: template al::span get_values() const { - return get_values(~size_t{}); + return get_values(~0_uz); } template diff --git a/al/effect.cpp b/al/effect.cpp index 5c7f9627..c4b06407 100644 --- a/al/effect.cpp +++ b/al/effect.cpp @@ -162,7 +162,7 @@ void InitEffectParams(ALeffect *effect, ALenum type) bool EnsureEffects(ALCdevice *device, size_t needed) { - size_t count{std::accumulate(device->EffectList.cbegin(), device->EffectList.cend(), size_t{0}, + size_t count{std::accumulate(device->EffectList.cbegin(), device->EffectList.cend(), 0_uz, [](size_t cur, const EffectSubList &sublist) noexcept -> size_t { return cur + static_cast(al::popcount(sublist.FreeMask)); })}; diff --git a/al/filter.cpp b/al/filter.cpp index e6520e6a..f0a078b7 100644 --- a/al/filter.cpp +++ b/al/filter.cpp @@ -117,7 +117,7 @@ void InitFilterParams(ALfilter *filter, ALenum type) bool EnsureFilters(ALCdevice *device, size_t needed) { - size_t count{std::accumulate(device->FilterList.cbegin(), device->FilterList.cend(), size_t{0}, + size_t count{std::accumulate(device->FilterList.cbegin(), device->FilterList.cend(), 0_uz, [](size_t cur, const FilterSubList &sublist) noexcept -> size_t { return cur + static_cast(al::popcount(sublist.FreeMask)); })}; diff --git a/al/source.cpp b/al/source.cpp index 01a981d3..2fbd1703 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -719,8 +719,7 @@ inline ALenum GetSourceState(ALsource *source, Voice *voice) bool EnsureSources(ALCcontext *context, size_t needed) { - size_t count{std::accumulate(context->mSourceList.cbegin(), context->mSourceList.cend(), - size_t{0}, + size_t count{std::accumulate(context->mSourceList.cbegin(), context->mSourceList.cend(), 0_uz, [](size_t cur, const SourceSubList &sublist) noexcept -> size_t { return cur + static_cast(al::popcount(sublist.FreeMask)); })}; @@ -3697,7 +3696,8 @@ ALsource* ALsource::EaxLookupSource(ALCcontext& al_context, ALuint source_id) no void ALsource::eax_set_sends_defaults(EaxSends& sends, const EaxFxSlotIds& ids) noexcept { - for (auto i = size_t{}; i < EAX_MAX_FXSLOTS; ++i) { + for(size_t i{0};i < EAX_MAX_FXSLOTS;++i) + { auto& send = sends[i]; send.guidReceivingFXSlotID = *(ids[i]); send.lSend = EAXSOURCE_DEFAULTSEND; @@ -3809,7 +3809,8 @@ void ALsource::eax5_set_active_fx_slots_defaults(EAX50ACTIVEFXSLOTS& slots) noex void ALsource::eax5_set_speaker_levels_defaults(EaxSpeakerLevels& speaker_levels) noexcept { - for (auto i = size_t{}; i < eax_max_speakers; ++i) { + for(size_t i{0};i < eax_max_speakers;++i) + { auto& speaker_level = speaker_levels[i]; speaker_level.lSpeakerID = static_cast(EAXSPEAKER_FRONT_LEFT + i); speaker_level.lLevel = EAXSOURCE_DEFAULTSPEAKERLEVEL; @@ -3912,7 +3913,7 @@ void ALsource::eax4_translate(const Eax4Props& src, Eax5Props& dst) noexcept // dst.sends = src.sends; - for (auto i = size_t{}; i < EAX_MAX_FXSLOTS; ++i) + for(size_t i{0};i < EAX_MAX_FXSLOTS;++i) dst.sends[i].guidReceivingFXSlotID = *(eax5_fx_slot_ids[i]); // Active FX slots. @@ -3974,19 +3975,21 @@ EaxAlLowPassParam ALsource::eax_create_direct_filter_param() const noexcept static_cast(mEax.source.lDirectHF) + static_cast(mEax.source.lObstruction); - for (auto i = std::size_t{}; i < EAX_MAX_FXSLOTS; ++i) + for(size_t i{0};i < EAX_MAX_FXSLOTS;++i) { if(!mEaxActiveFxSlots[i]) continue; - if(has_source_occlusion) { + if(has_source_occlusion) + { const auto& fx_slot = mEaxAlContext->eaxGetFxSlot(i); const auto& fx_slot_eax = fx_slot.eax_get_eax_fx_slot(); const auto is_environmental_fx = ((fx_slot_eax.ulFlags & EAXFXSLOTFLAGS_ENVIRONMENT) != 0); const auto is_primary = (mEaxPrimaryFxSlotId.value_or(-1) == fx_slot.eax_get_index()); const auto is_listener_environment = (is_environmental_fx && is_primary); - if(is_listener_environment) { + if(is_listener_environment) + { gain_mb += eax_calculate_dst_occlusion_mb( mEax.source.lOcclusion, mEax.source.flOcclusionDirectRatio, @@ -3998,7 +4001,8 @@ EaxAlLowPassParam ALsource::eax_create_direct_filter_param() const noexcept const auto& send = mEax.sends[i]; - if(send.lOcclusion != 0) { + if(send.lOcclusion != 0) + { gain_mb += eax_calculate_dst_occlusion_mb( send.lOcclusion, send.flOcclusionDirectRatio, @@ -4073,8 +4077,9 @@ void ALsource::eax_update_direct_filter() void ALsource::eax_update_room_filters() { - for (auto i = size_t{}; i < EAX_MAX_FXSLOTS; ++i) { - if (!mEaxActiveFxSlots[i]) + for(size_t i{0};i < EAX_MAX_FXSLOTS;++i) + { + if(!mEaxActiveFxSlots[i]) continue; auto& fx_slot = mEaxAlContext->eaxGetFxSlot(i); @@ -4880,7 +4885,7 @@ void ALsource::eax_commit_active_fx_slots() // Deactivate EFX auxiliary effect slots for inactive slots. Active slots // will be updated with the room filters. - for(auto i = size_t{}; i < EAX_MAX_FXSLOTS; ++i) + for(size_t i{0};i < EAX_MAX_FXSLOTS;++i) { if(!mEaxActiveFxSlots[i]) eax_set_al_source_send(nullptr, i, EaxAlLowPassParam{1.0f, 1.0f}); diff --git a/al/state.cpp b/al/state.cpp index 1c41d63c..5131edd9 100644 --- a/al/state.cpp +++ b/al/state.cpp @@ -229,7 +229,7 @@ void GetValue(ALCcontext *context, ALenum pname, T *values) case AL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_EXT: { std::lock_guard _{context->mDebugCbLock}; - *values = cast_value(context->mDebugLog.empty() ? size_t{0} + *values = cast_value(context->mDebugLog.empty() ? 0_uz : (context->mDebugLog.front().mMessage.size()+1)); return; } diff --git a/alc/alu.cpp b/alc/alu.cpp index 1fa9d1d4..6eb4691e 100644 --- a/alc/alu.cpp +++ b/alc/alu.cpp @@ -733,7 +733,7 @@ void AmbiRotator(AmbiRotateMatrix &matrix, const int order) } } last_band = band_idx; - band_idx += static_cast(l)*size_t{2} + 1; + band_idx += static_cast(l)*2_uz + 1; } } /* End ambisonic rotation helpers. */ diff --git a/alc/backends/wave.cpp b/alc/backends/wave.cpp index 1078c654..794d5cb8 100644 --- a/alc/backends/wave.cpp +++ b/alc/backends/wave.cpp @@ -154,13 +154,13 @@ int WaveBackend::mixerProc() if(bytesize == 2) { - const size_t len{mBuffer.size() & ~size_t{1}}; + const size_t len{mBuffer.size() & ~1_uz}; for(size_t i{0};i < len;i+=2) std::swap(mBuffer[i], mBuffer[i+1]); } else if(bytesize == 4) { - const size_t len{mBuffer.size() & ~size_t{3}}; + const size_t len{mBuffer.size() & ~3_uz}; for(size_t i{0};i < len;i+=4) { std::swap(mBuffer[i ], mBuffer[i+3]); diff --git a/alc/context.cpp b/alc/context.cpp index 3b1de7b9..8c930056 100644 --- a/alc/context.cpp +++ b/alc/context.cpp @@ -127,7 +127,7 @@ ALCcontext::~ALCcontext() { TRACE("Freeing context %p\n", voidp{this}); - size_t count{std::accumulate(mSourceList.cbegin(), mSourceList.cend(), size_t{0u}, + size_t count{std::accumulate(mSourceList.cbegin(), mSourceList.cend(), 0_uz, [](size_t cur, const SourceSubList &sublist) noexcept -> size_t { return cur + static_cast(al::popcount(~sublist.FreeMask)); })}; if(count > 0) @@ -140,7 +140,7 @@ ALCcontext::~ALCcontext() #endif // ALSOFT_EAX mDefaultSlot = nullptr; - count = std::accumulate(mEffectSlotList.cbegin(), mEffectSlotList.cend(), size_t{0u}, + count = std::accumulate(mEffectSlotList.cbegin(), mEffectSlotList.cend(), 0_uz, [](size_t cur, const EffectSlotSubList &sublist) noexcept -> size_t { return cur + static_cast(al::popcount(~sublist.FreeMask)); }); if(count > 0) diff --git a/alc/device.cpp b/alc/device.cpp index 66b13c5e..27aa6f36 100644 --- a/alc/device.cpp +++ b/alc/device.cpp @@ -34,19 +34,19 @@ ALCdevice::~ALCdevice() Backend = nullptr; - size_t count{std::accumulate(BufferList.cbegin(), BufferList.cend(), size_t{0u}, + size_t count{std::accumulate(BufferList.cbegin(), BufferList.cend(), 0_uz, [](size_t cur, const BufferSubList &sublist) noexcept -> size_t { return cur + static_cast(al::popcount(~sublist.FreeMask)); })}; if(count > 0) WARN("%zu Buffer%s not deleted\n", count, (count==1)?"":"s"); - count = std::accumulate(EffectList.cbegin(), EffectList.cend(), size_t{0u}, + count = std::accumulate(EffectList.cbegin(), EffectList.cend(), 0_uz, [](size_t cur, const EffectSubList &sublist) noexcept -> size_t { return cur + static_cast(al::popcount(~sublist.FreeMask)); }); if(count > 0) WARN("%zu Effect%s not deleted\n", count, (count==1)?"":"s"); - count = std::accumulate(FilterList.cbegin(), FilterList.cend(), size_t{0u}, + count = std::accumulate(FilterList.cbegin(), FilterList.cend(), 0_uz, [](size_t cur, const FilterSubList &sublist) noexcept -> size_t { return cur + static_cast(al::popcount(~sublist.FreeMask)); }); if(count > 0) diff --git a/core/hrtf.cpp b/core/hrtf.cpp index f131e72d..9a13a004 100644 --- a/core/hrtf.cpp +++ b/core/hrtf.cpp @@ -1368,7 +1368,7 @@ HrtfStorePtr GetLoadedHrtf(const std::string &name, const uint devrate) TRACE("Resampling HRTF %s (%uhz -> %uhz)\n", name.c_str(), hrtf->mSampleRate, devrate); /* Calculate the last elevation's index and get the total IR count. */ - const size_t lastEv{std::accumulate(hrtf->mFields.begin(), hrtf->mFields.end(), size_t{0}, + const size_t lastEv{std::accumulate(hrtf->mFields.begin(), hrtf->mFields.end(), 0_uz, [](const size_t curval, const HrtfStore::Field &field) noexcept -> size_t { return curval + field.evCount; } ) - 1}; diff --git a/core/mixer/mixer_neon.cpp b/core/mixer/mixer_neon.cpp index ef2936b3..ead775af 100644 --- a/core/mixer/mixer_neon.cpp +++ b/core/mixer/mixer_neon.cpp @@ -342,7 +342,7 @@ void Mix_(const al::span InSamples, const al::span 0) ? 1.0f / static_cast(Counter) : 0.0f}; const auto min_len = minz(Counter, InSamples.size()); - const auto aligned_len = minz((min_len+3) & ~size_t{3}, InSamples.size()) - min_len; + const auto aligned_len = minz((min_len+3) & ~3_uz, InSamples.size()) - min_len; for(FloatBufferLine &output : OutBuffer) MixLine(InSamples, al::assume_aligned<16>(output.data()+OutPos), *CurrentGains++, @@ -355,7 +355,7 @@ void Mix_(const al::span InSamples, float *OutBuffer, floa { const float delta{(Counter > 0) ? 1.0f / static_cast(Counter) : 0.0f}; const auto min_len = minz(Counter, InSamples.size()); - const auto aligned_len = minz((min_len+3) & ~size_t{3}, InSamples.size()) - min_len; + const auto aligned_len = minz((min_len+3) & ~3_uz, InSamples.size()) - min_len; MixLine(InSamples, al::assume_aligned<16>(OutBuffer), CurrentGain, TargetGain, delta, min_len, aligned_len, Counter); diff --git a/core/mixer/mixer_sse.cpp b/core/mixer/mixer_sse.cpp index 0aa5d5fb..70f77c14 100644 --- a/core/mixer/mixer_sse.cpp +++ b/core/mixer/mixer_sse.cpp @@ -307,7 +307,7 @@ void Mix_(const al::span InSamples, const al::span 0) ? 1.0f / static_cast(Counter) : 0.0f}; const auto min_len = minz(Counter, InSamples.size()); - const auto aligned_len = minz((min_len+3) & ~size_t{3}, InSamples.size()) - min_len; + const auto aligned_len = minz((min_len+3) & ~3_uz, InSamples.size()) - min_len; for(FloatBufferLine &output : OutBuffer) MixLine(InSamples, al::assume_aligned<16>(output.data()+OutPos), *CurrentGains++, @@ -320,7 +320,7 @@ void Mix_(const al::span InSamples, float *OutBuffer, float { const float delta{(Counter > 0) ? 1.0f / static_cast(Counter) : 0.0f}; const auto min_len = minz(Counter, InSamples.size()); - const auto aligned_len = minz((min_len+3) & ~size_t{3}, InSamples.size()) - min_len; + const auto aligned_len = minz((min_len+3) & ~3_uz, InSamples.size()) - min_len; MixLine(InSamples, al::assume_aligned<16>(OutBuffer), CurrentGain, TargetGain, delta, min_len, aligned_len, Counter); diff --git a/core/voice.cpp b/core/voice.cpp index 92da3e76..b8acc7a6 100644 --- a/core/voice.cpp +++ b/core/voice.cpp @@ -330,7 +330,7 @@ inline void LoadSamples(float *RESTRICT dstSamples, const std::byte *sr for(;skip;--skip) { const size_t byteShift{(nibbleOffset&1) * 4}; - const size_t wordOffset{(nibbleOffset>>1) & ~size_t{3}}; + const size_t wordOffset{(nibbleOffset>>1) & ~3_uz}; const size_t byteOffset{wordOffset*srcStep + ((nibbleOffset>>1)&3u)}; ++nibbleOffset; @@ -344,7 +344,7 @@ inline void LoadSamples(float *RESTRICT dstSamples, const std::byte *sr for(size_t i{0};i < todo;++i) { const size_t byteShift{(nibbleOffset&1) * 4}; - const size_t wordOffset{(nibbleOffset>>1) & ~size_t{3}}; + const size_t wordOffset{(nibbleOffset>>1) & ~3_uz}; const size_t byteOffset{wordOffset*srcStep + ((nibbleOffset>>1)&3u)}; ++nibbleOffset; -- cgit v1.2.3 From 5b86b80591ce85869716885ca393e080f6f72685 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Thu, 12 Oct 2023 06:42:32 -0700 Subject: Rename the convolution reverb effect to just convolution While the common use case, convolution can do more than just reverb, and it nicely shortens the name. --- al/auxeffectslot.cpp | 2 +- al/effect.cpp | 4 ++-- al/effects/convolution.cpp | 4 ++-- alc/context.cpp | 2 +- alc/export_list.h | 2 +- alc/inprogext.h | 8 ++++---- examples/alconvolve.c | 32 ++++++++++++++++---------------- 7 files changed, 27 insertions(+), 27 deletions(-) (limited to 'alc/context.cpp') diff --git a/al/auxeffectslot.cpp b/al/auxeffectslot.cpp index 33252410..fb646389 100644 --- a/al/auxeffectslot.cpp +++ b/al/auxeffectslot.cpp @@ -230,7 +230,7 @@ EffectSlotType EffectSlotTypeFromEnum(ALenum type) case AL_EFFECT_EAXREVERB: return EffectSlotType::EAXReverb; case AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT: return EffectSlotType::DedicatedLFE; case AL_EFFECT_DEDICATED_DIALOGUE: return EffectSlotType::DedicatedDialog; - case AL_EFFECT_CONVOLUTION_REVERB_SOFT: return EffectSlotType::Convolution; + case AL_EFFECT_CONVOLUTION_SOFT: return EffectSlotType::Convolution; } ERR("Unhandled effect enum: 0x%04x\n", type); return EffectSlotType::None; diff --git a/al/effect.cpp b/al/effect.cpp index c4b06407..3e48e91b 100644 --- a/al/effect.cpp +++ b/al/effect.cpp @@ -74,7 +74,7 @@ const EffectList gEffectList[16]{ { "vmorpher", VMORPHER_EFFECT, AL_EFFECT_VOCAL_MORPHER }, { "dedicated", DEDICATED_EFFECT, AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT }, { "dedicated", DEDICATED_EFFECT, AL_EFFECT_DEDICATED_DIALOGUE }, - { "convolution", CONVOLUTION_EFFECT, AL_EFFECT_CONVOLUTION_REVERB_SOFT }, + { "convolution", CONVOLUTION_EFFECT, AL_EFFECT_CONVOLUTION_SOFT }, }; bool DisabledEffects[MAX_EFFECTS]; @@ -113,7 +113,7 @@ constexpr EffectPropsItem EffectPropsList[] = { { AL_EFFECT_VOCAL_MORPHER, VmorpherEffectProps, VmorpherEffectVtable }, { AL_EFFECT_DEDICATED_DIALOGUE, DedicatedEffectProps, DedicatedEffectVtable }, { AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT, DedicatedEffectProps, DedicatedEffectVtable }, - { AL_EFFECT_CONVOLUTION_REVERB_SOFT, ConvolutionEffectProps, ConvolutionEffectVtable }, + { AL_EFFECT_CONVOLUTION_SOFT, ConvolutionEffectProps, ConvolutionEffectVtable }, }; diff --git a/al/effects/convolution.cpp b/al/effects/convolution.cpp index 494950b7..3e7885f8 100644 --- a/al/effects/convolution.cpp +++ b/al/effects/convolution.cpp @@ -40,7 +40,7 @@ void Convolution_setParamfv(EffectProps *props, ALenum param, const float *value { switch(param) { - case AL_CONVOLUTION_REVERB_ORIENTATION_SOFT: + case AL_CONVOLUTION_ORIENTATION_SOFT: if(!(std::isfinite(values[0]) && std::isfinite(values[1]) && std::isfinite(values[2]) && std::isfinite(values[3]) && std::isfinite(values[4]) && std::isfinite(values[5]))) throw effect_exception{AL_INVALID_VALUE, "Property 0x%04x value out of range", param}; @@ -88,7 +88,7 @@ void Convolution_getParamfv(const EffectProps *props, ALenum param, float *value { switch(param) { - case AL_CONVOLUTION_REVERB_ORIENTATION_SOFT: + case AL_CONVOLUTION_ORIENTATION_SOFT: values[0] = props->Convolution.OrientAt[0]; values[1] = props->Convolution.OrientAt[1]; values[2] = props->Convolution.OrientAt[2]; diff --git a/alc/context.cpp b/alc/context.cpp index 8c930056..ffc2743e 100644 --- a/alc/context.cpp +++ b/alc/context.cpp @@ -75,7 +75,7 @@ std::vector getContextExtensions() noexcept "AL_SOFT_block_alignment", "AL_SOFT_buffer_length_query", "AL_SOFT_callback_buffer", - "AL_SOFTX_convolution_reverb", + "AL_SOFTX_convolution_effect", "AL_SOFT_deferred_updates", "AL_SOFT_direct_channels", "AL_SOFT_direct_channels_remix", diff --git a/alc/export_list.h b/alc/export_list.h index cefe7a09..2ef0d777 100644 --- a/alc/export_list.h +++ b/alc/export_list.h @@ -820,7 +820,7 @@ inline const EnumExport alcEnumerations[]{ DECL(AL_UNPACK_AMBISONIC_ORDER_SOFT), - DECL(AL_EFFECT_CONVOLUTION_REVERB_SOFT), + DECL(AL_EFFECT_CONVOLUTION_SOFT), DECL(AL_EFFECTSLOT_STATE_SOFT), DECL(AL_FORMAT_UHJ2CHN8_SOFT), diff --git a/alc/inprogext.h b/alc/inprogext.h index a595721d..a145b8e4 100644 --- a/alc/inprogext.h +++ b/alc/inprogext.h @@ -41,10 +41,10 @@ void AL_APIENTRY alFlushMappedBufferDirectSOFT(ALCcontext *context, ALuint buffe #define AL_UNPACK_AMBISONIC_ORDER_SOFT 0x199D #endif -#ifndef AL_SOFT_convolution_reverb -#define AL_SOFT_convolution_reverb -#define AL_EFFECT_CONVOLUTION_REVERB_SOFT 0xA000 -#define AL_CONVOLUTION_REVERB_ORIENTATION_SOFT 0x100F /* same as AL_ORIENTATION */ +#ifndef AL_SOFT_convolution_effect +#define AL_SOFT_convolution_effect +#define AL_EFFECT_CONVOLUTION_SOFT 0xA000 +#define AL_CONVOLUTION_ORIENTATION_SOFT 0x100F /* same as AL_ORIENTATION */ #define AL_EFFECTSLOT_STATE_SOFT 0x199E typedef void (AL_APIENTRY*LPALAUXILIARYEFFECTSLOTPLAYSOFT)(ALuint slotid) AL_API_NOEXCEPT17; typedef void (AL_APIENTRY*LPALAUXILIARYEFFECTSLOTPLAYVSOFT)(ALsizei n, const ALuint *slotids) AL_API_NOEXCEPT17; diff --git a/examples/alconvolve.c b/examples/alconvolve.c index 94b978b5..8580d443 100644 --- a/examples/alconvolve.c +++ b/examples/alconvolve.c @@ -22,7 +22,7 @@ * THE SOFTWARE. */ -/* This file contains an example for applying convolution reverb to a source. */ +/* This file contains an example for applying convolution to a source. */ #include #include @@ -39,9 +39,9 @@ #include "common/alhelpers.h" -#ifndef AL_SOFT_convolution_reverb -#define AL_SOFT_convolution_reverb -#define AL_EFFECT_CONVOLUTION_REVERB_SOFT 0xA000 +#ifndef AL_SOFT_convolution_effect +#define AL_SOFT_convolution_effect +#define AL_EFFECT_CONVOLUTION_SOFT 0xA000 #endif @@ -278,19 +278,19 @@ static int UpdatePlayer(StreamPlayer *player) } -/* CreateEffect creates a new OpenAL effect object with a convolution reverb - * type, and returns the new effect ID. +/* CreateEffect creates a new OpenAL effect object with a convolution type, and + * returns the new effect ID. */ static ALuint CreateEffect(void) { ALuint effect = 0; ALenum err; - printf("Using Convolution Reverb\n"); + printf("Using Convolution\n"); - /* Create the effect object and set the convolution reverb effect type. */ + /* Create the effect object and set the convolution effect type. */ alGenEffects(1, &effect); - alEffecti(effect, AL_EFFECT_TYPE, AL_EFFECT_CONVOLUTION_REVERB_SOFT); + alEffecti(effect, AL_EFFECT_TYPE, AL_EFFECT_CONVOLUTION_SOFT); /* Check if an error occurred, and clean up if so. */ err = alGetError(); @@ -423,10 +423,10 @@ int main(int argc, char **argv) if(InitAL(&argv, &argc) != 0) return 1; - if(!alIsExtensionPresent("AL_SOFTX_convolution_reverb")) + if(!alIsExtensionPresent("AL_SOFTX_convolution_effect")) { CloseAL(); - fprintf(stderr, "Error: Convolution revern not supported\n"); + fprintf(stderr, "Error: Convolution effect not supported\n"); return 1; } @@ -500,11 +500,11 @@ int main(int argc, char **argv) alGenAuxiliaryEffectSlots(1, &slot); /* Set the impulse response sound buffer on the effect slot. This allows - * effects to access it as needed. In this case, convolution reverb uses it - * as the filter source. NOTE: Unlike the effect object, the buffer *is* - * kept referenced and may not be changed or deleted as long as it's set, - * just like with a source. When another buffer is set, or the effect slot - * is deleted, the buffer reference is released. + * effects to access it as needed. In this case, convolution uses it as the + * filter source. NOTE: Unlike the effect object, the buffer *is* kept + * referenced and may not be changed or deleted as long as it's set, just + * like with a source. When another buffer is set, or the effect slot is + * deleted, the buffer reference is released. * * The effect slot's gain is reduced because the impulse responses I've * tested with result in excessively loud reverb. Is that normal? Even with -- cgit v1.2.3