diff options
-rw-r--r-- | al/debug.cpp | 129 | ||||
-rw-r--r-- | alc/context.cpp | 67 | ||||
-rw-r--r-- | alc/context.h | 54 |
3 files changed, 133 insertions, 117 deletions
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<typename T, size_t N, typename Indices = std::make_integer_sequence<T,N constexpr auto make_array() { return make_array(Indices{}); } + +constexpr al::optional<DebugSource> 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<DebugType> 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<DebugSeverity> 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<uint,ElemCount>(); al::span<const uint> srcIndices{al::as_span(Values).subspan<DebugSourceBase,DebugSourceCount>()}; - 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<const uint> typeIndices{al::as_span(Values).subspan<DebugTypeBase,DebugTypeCount>()}; - 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<const uint> svrIndices{al::as_span(Values).subspan<DebugSeverityBase,DebugSeverityCount>()}; - 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<std::mutex> _{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<std::mutex> _{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 { |