yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Jay KwakHandle debug-layer messages in a separate channel (#7988)aefd1e3e0

master
2.1 KiB89 linesraw
1#ifndef SLANG_CORE_STD_WRITERS_H
2#define SLANG_CORE_STD_WRITERS_H
3
4#include "slang-com-ptr.h"
5#include "slang-writer.h"
6
7namespace Slang
8{
9
10enum class DebugMessageType
11{
12    Info,
13    Warning,
14    Error
15};
16
17enum class DebugMessageSource
18{
19    Layer,
20    Driver,
21    Slang
22};
23
24class IDebugCallback
25{
26public:
27    virtual SLANG_NO_THROW void SLANG_MCALL
28    handleMessage(DebugMessageType type, DebugMessageSource source, const char* message) = 0;
29};
30
31/* Holds standard writers for the channels */
32class StdWriters : public RefObject
33{
34public:
35    ISlangWriter* getWriter(SlangWriterChannel chan) const { return m_writers[chan]; }
36    void setWriter(SlangWriterChannel chan, ISlangWriter* writer) { m_writers[chan] = writer; }
37
38    IDebugCallback* getDebugCallback() const { return m_debugCallback; }
39    void setDebugCallback(IDebugCallback* callback) { m_debugCallback = callback; }
40
41    /// Flush all the set writers
42    void flushWriters();
43
44    /// Ctor
45    StdWriters() {}
46
47    /// Initialize a default context
48    static RefPtr<StdWriters> createDefault();
49    static RefPtr<StdWriters> initDefaultSingleton();
50
51    static StdWriters* getSingleton() { return s_singleton; }
52    static void setSingleton(StdWriters* context) { s_singleton = context; }
53
54    static WriterHelper getError()
55    {
56        return getSingleton()->getWriter(SLANG_WRITER_CHANNEL_STD_ERROR);
57    }
58    static WriterHelper getOut()
59    {
60        return getSingleton()->getWriter(SLANG_WRITER_CHANNEL_STD_OUTPUT);
61    }
62    static WriterHelper getDiagnostic()
63    {
64        return getSingleton()->getWriter(SLANG_WRITER_CHANNEL_DIAGNOSTIC);
65    }
66
67protected:
68    ComPtr<ISlangWriter> m_writers[SLANG_WRITER_CHANNEL_COUNT_OF];
69    IDebugCallback* m_debugCallback = nullptr;
70
71    static StdWriters* s_singleton;
72};
73
74// --------------------------------------------------------------------------
75inline void StdWriters::flushWriters()
76{
77    for (Index i = 0; i < Count(SLANG_WRITER_CHANNEL_COUNT_OF); ++i)
78    {
79        auto writer = m_writers[i];
80        if (writer)
81        {
82            writer->flush();
83        }
84    }
85}
86
87} // namespace Slang
88
89#endif