blob: 51a2c8de12b849cc848acceb4709b371de214feb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
// slang-support.h
#pragma once
#include "core/slang-std-writers.h"
#include "options.h"
#include "shader-input-layout.h"
#include "slang.h"
#include <slang-rhi.h>
namespace renderer_test
{
/// Bridge from core debug callback to RHI debug callback
/// This allows core callbacks to receive messages from RHI systems
/// TODO: We should replace rhi::IDebugCallback with Slang::IDebugCallback.
class CoreToRHIDebugBridge : public rhi::IDebugCallback
{
public:
void setCoreCallback(Slang::IDebugCallback* coreCallback) { m_coreCallback = coreCallback; }
virtual SLANG_NO_THROW void SLANG_MCALL handleMessage(
rhi::DebugMessageType type,
rhi::DebugMessageSource source,
const char* message) override
{
if (m_coreCallback)
{
// Convert RHI types to core types
Slang::DebugMessageType coreType = static_cast<Slang::DebugMessageType>(type);
Slang::DebugMessageSource coreSource = static_cast<Slang::DebugMessageSource>(source);
m_coreCallback->handleMessage(coreType, coreSource, message);
}
}
private:
Slang::IDebugCallback* m_coreCallback = nullptr;
};
/// Core debug callback that captures debug messages in a string buffer
class CoreDebugCallback : public Slang::IDebugCallback
{
public:
virtual SLANG_NO_THROW void SLANG_MCALL handleMessage(
Slang::DebugMessageType type,
Slang::DebugMessageSource source,
const char* message) override
{
SLANG_UNUSED(source);
// Only capture error messages
if (type == Slang::DebugMessageType::Error)
{
m_buf << message;
if (message[strlen(message) - 1] != '\n')
{
m_buf << '\n';
}
}
}
void clear() { m_buf.clear(); }
Slang::String getString() { return m_buf.toString(); }
private:
Slang::StringBuilder m_buf;
};
struct ShaderCompileRequest
{
struct SourceInfo
{
char const* path;
// The data may either be source text (in which
// case it can be assumed to be nul-terminated with
// `dataEnd` pointing at the terminator), or
// raw binary data (in which case `dataEnd` points
// at the end of the buffer).
char const* dataBegin;
char const* dataEnd;
};
struct EntryPoint
{
char const* name = nullptr;
SlangStage slangStage;
};
struct TypeConformance
{
public:
Slang::String derivedTypeName;
Slang::String baseTypeName;
Slang::Int idOverride;
};
SourceInfo source;
Slang::List<EntryPoint> entryPoints;
Slang::List<Slang::String> globalSpecializationArgs;
Slang::List<Slang::String> entryPointSpecializationArgs;
Slang::List<TypeConformance> typeConformances;
};
struct ShaderCompilerUtil
{
struct Input
{
SlangCompileTarget target;
SlangSourceLanguage sourceLanguage;
SlangPassThrough passThrough;
Slang::String profile;
};
struct Output
{
void set(slang::IComponentType* slangProgram);
void reset();
~Output() { reset(); }
ComPtr<slang::IComponentType> slangProgram;
ShaderProgramDesc desc = {};
ComPtr<slang::ISession> m_session = nullptr;
slang::IGlobalSession* globalSession = nullptr;
};
struct OutputAndLayout
{
Output output;
ShaderInputLayout layout;
Slang::String sourcePath;
};
// Wrapper for compileProgram
static SlangResult compileWithLayout(
slang::IGlobalSession* globalSession,
const Options& options,
const ShaderCompilerUtil::Input& input,
OutputAndLayout& output);
};
} // namespace renderer_test
|