aboutsummaryrefslogtreecommitdiffstats
path: root/alc/context.h
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2023-11-28 12:51:46 +0100
committerSven Gothel <[email protected]>2023-11-28 12:51:46 +0100
commit1aaf4f070011490bcece50394b9b32dfa593fd9e (patch)
tree17d68284e401a35eea3d3a574d986d446a60763a /alc/context.h
parent6e7cee4fa9a8af03f28ca26cd89f8357390dfc90 (diff)
parent571b546f35eead77ce109f8d4dd6c3de3199d573 (diff)
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'alc/context.h')
-rw-r--r--alc/context.h81
1 files changed, 64 insertions, 17 deletions
diff --git a/alc/context.h b/alc/context.h
index e8efdbf1..201c8873 100644
--- a/alc/context.h
+++ b/alc/context.h
@@ -2,10 +2,15 @@
#define ALC_CONTEXT_H
#include <atomic>
+#include <deque>
#include <memory>
#include <mutex>
#include <stdint.h>
+#include <string>
+#include <string_view>
+#include <unordered_map>
#include <utility>
+#include <vector>
#include "AL/al.h"
#include "AL/alc.h"
@@ -16,8 +21,8 @@
#include "alnumeric.h"
#include "atomic.h"
#include "core/context.h"
+#include "inprogext.h"
#include "intrusive_ptr.h"
-#include "vector.h"
#ifdef ALSOFT_EAX
#include "al/eax/call.h"
@@ -30,10 +35,39 @@
struct ALeffect;
struct ALeffectslot;
struct ALsource;
+struct DebugGroup;
+
+enum class DebugSource : uint8_t;
+enum class DebugType : uint8_t;
+enum class DebugSeverity : uint8_t;
using uint = unsigned int;
+enum ContextFlags {
+ DebugBit = 0, /* ALC_CONTEXT_DEBUG_BIT_EXT */
+};
+using ContextFlagBitset = std::bitset<sizeof(ALuint)*8>;
+
+
+struct DebugLogEntry {
+ const DebugSource mSource;
+ const DebugType mType;
+ const DebugSeverity mSeverity;
+ const uint mId;
+
+ std::string mMessage;
+
+ template<typename T>
+ DebugLogEntry(DebugSource source, DebugType type, uint id, DebugSeverity severity, T&& message)
+ : mSource{source}, mType{type}, mSeverity{severity}, mId{id}
+ , mMessage{std::forward<T>(message)}
+ { }
+ DebugLogEntry(const DebugLogEntry&) = default;
+ DebugLogEntry(DebugLogEntry&&) = default;
+};
+
+
struct SourceSubList {
uint64_t FreeMask{~0_u64};
ALsource *Sources{nullptr}; /* 64 */
@@ -76,6 +110,9 @@ struct ALCcontext : public al::intrusive_ref<ALCcontext>, ContextBase {
std::atomic<ALenum> mLastError{AL_NO_ERROR};
+ const ContextFlagBitset mContextFlags;
+ std::atomic<bool> mDebugEnabled{false};
+
DistanceModel mDistanceModel{DistanceModel::Default};
bool mSourceDistanceModel{false};
@@ -88,25 +125,32 @@ struct ALCcontext : public al::intrusive_ref<ALCcontext>, ContextBase {
ALEVENTPROCSOFT mEventCb{};
void *mEventParam{nullptr};
+ std::mutex mDebugCbLock;
+ ALDEBUGPROCEXT mDebugCb{};
+ void *mDebugParam{nullptr};
+ std::vector<DebugGroup> mDebugGroups;
+ std::deque<DebugLogEntry> mDebugLog;
+
ALlistener mListener{};
- al::vector<SourceSubList> mSourceList;
+ std::vector<SourceSubList> mSourceList;
ALuint mNumSources{0};
std::mutex mSourceLock;
- al::vector<EffectSlotSubList> mEffectSlotList;
+ std::vector<EffectSlotSubList> mEffectSlotList;
ALuint mNumEffectSlots{0u};
std::mutex mEffectSlotLock;
/* Default effect slot */
std::unique_ptr<ALeffectslot> mDefaultSlot;
- const char *mExtensionList{nullptr};
-
- std::string mExtensionListOverride{};
+ std::vector<std::string_view> mExtensions;
+ std::string mExtensionsString{};
+ std::unordered_map<ALuint,std::string> mSourceNames;
+ std::unordered_map<ALuint,std::string> mEffectSlotNames;
- ALCcontext(al::intrusive_ptr<ALCdevice> device);
+ ALCcontext(al::intrusive_ptr<ALCdevice> device, ContextFlagBitset flags);
ALCcontext(const ALCcontext&) = delete;
ALCcontext& operator=(const ALCcontext&) = delete;
~ALCcontext();
@@ -149,13 +193,25 @@ struct ALCcontext : public al::intrusive_ref<ALCcontext>, ContextBase {
#endif
void setError(ALenum errorCode, const char *msg, ...);
+ void sendDebugMessage(std::unique_lock<std::mutex> &debuglock, DebugSource source,
+ DebugType type, ALuint id, DebugSeverity severity, std::string_view message);
+
+ void debugMessage(DebugSource source, DebugType type, ALuint id, DebugSeverity severity,
+ std::string_view message)
+ {
+ if(!mDebugEnabled.load(std::memory_order_relaxed)) LIKELY
+ return;
+ std::unique_lock<std::mutex> debuglock{mDebugCbLock};
+ sendDebugMessage(debuglock, source, type, id, severity, message);
+ }
+
/* Process-wide current context */
static std::atomic<bool> sGlobalContextLock;
static std::atomic<ALCcontext*> sGlobalContext;
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.
@@ -168,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;