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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
|
#include "slang-compiler-options.h"
#include "slang-compiler.h"
namespace Slang
{
void CompilerOptionSet::load(uint32_t count, slang::CompilerOptionEntry* entries)
{
for (uint32_t i = 0; i < count; i++)
{
CompilerOptionValue value;
value.kind = entries[i].value.kind;
value.intValue = entries[i].value.intValue0;
value.intValue2 = entries[i].value.intValue1;
if (value.kind == CompilerOptionValueKind::String)
{
value.stringValue = entries[i].value.stringValue0;
value.stringValue2 = entries[i].value.stringValue1;
}
add(entries[i].name, value);
}
}
void CompilerOptionSet::buildHash(DigestBuilder<SHA1>& builder)
{
for (auto& kv : options)
{
builder.append(kv.key);
builder.append(kv.value.getCount());
for (auto& v : kv.value)
{
if (v.kind == CompilerOptionValueKind::Int)
{
builder.append(v.intValue);
}
else
{
builder.append(v.stringValue);
builder.append(v.stringValue2);
}
}
}
}
bool CompilerOptionSet::allowDuplicate(CompilerOptionName name)
{
switch (name)
{
case CompilerOptionName::Include:
case CompilerOptionName::MacroDefine:
case CompilerOptionName::WarningsAsErrors:
case CompilerOptionName::DisableWarning:
case CompilerOptionName::DisableWarnings:
case CompilerOptionName::EnableWarning:
case CompilerOptionName::Capability:
case CompilerOptionName::DownstreamArgs:
case CompilerOptionName::VulkanBindShift:
case CompilerOptionName::VulkanBindShiftAll:
return true;
}
return false;
}
CompilerOptionValue Slang::CompilerOptionSet::getDefault(CompilerOptionName name)
{
switch (name)
{
case CompilerOptionName::Optimization:
return CompilerOptionValue::fromEnum(OptimizationLevel::Default);
default:
return CompilerOptionValue();
}
}
SlangTargetFlags CompilerOptionSet::getTargetFlags()
{
SlangTargetFlags result = 0;
if (getBoolOption(CompilerOptionName::DumpIr))
result |= SLANG_TARGET_FLAG_DUMP_IR;
if (getBoolOption(CompilerOptionName::GenerateWholeProgram))
result |= SLANG_TARGET_FLAG_GENERATE_WHOLE_PROGRAM;
if (getBoolOption(CompilerOptionName::EmitSpirvDirectly))
result |= SLANG_TARGET_FLAG_GENERATE_SPIRV_DIRECTLY;
if (getBoolOption(CompilerOptionName::ParameterBlocksUseRegisterSpaces))
result |= SLANG_TARGET_FLAG_PARAMETER_BLOCKS_USE_REGISTER_SPACES;
return result;
}
void CompilerOptionSet::setTargetFlags(SlangTargetFlags flags)
{
set(CompilerOptionName::DumpIr, (flags & SLANG_TARGET_FLAG_DUMP_IR) != 0);
set(CompilerOptionName::GenerateWholeProgram, (flags & SLANG_TARGET_FLAG_GENERATE_WHOLE_PROGRAM) != 0);
set(CompilerOptionName::EmitSpirvDirectly, (flags & SLANG_TARGET_FLAG_GENERATE_SPIRV_DIRECTLY) != 0);
set(CompilerOptionName::ParameterBlocksUseRegisterSpaces, (flags & SLANG_TARGET_FLAG_PARAMETER_BLOCKS_USE_REGISTER_SPACES) != 0);
}
void CompilerOptionSet::addTargetFlags(SlangTargetFlags flags)
{
if ((flags & SLANG_TARGET_FLAG_DUMP_IR))
set(CompilerOptionName::DumpIr, true);
if ((flags & SLANG_TARGET_FLAG_GENERATE_WHOLE_PROGRAM) != 0)
set(CompilerOptionName::GenerateWholeProgram, true);
if ((flags & SLANG_TARGET_FLAG_GENERATE_SPIRV_DIRECTLY) != 0)
set(CompilerOptionName::EmitSpirvDirectly, true);
if ((flags & SLANG_TARGET_FLAG_PARAMETER_BLOCKS_USE_REGISTER_SPACES) != 0)
set(CompilerOptionName::ParameterBlocksUseRegisterSpaces, true);
}
MatrixLayoutMode CompilerOptionSet::getMatrixLayoutMode()
{
if (getBoolOption(CompilerOptionName::MatrixLayoutRow))
return kMatrixLayoutMode_RowMajor;
if (getBoolOption(CompilerOptionName::MatrixLayoutColumn))
return kMatrixLayoutMode_ColumnMajor;
return (MatrixLayoutMode)kMatrixLayoutMode_RowMajor;
}
void CompilerOptionSet::setMatrixLayoutMode(MatrixLayoutMode mode)
{
options.remove(CompilerOptionName::MatrixLayoutColumn);
options.remove(CompilerOptionName::MatrixLayoutRow);
if (mode == kMatrixLayoutMode_ColumnMajor)
set(CompilerOptionName::MatrixLayoutColumn, true);
if (mode == kMatrixLayoutMode_RowMajor)
set(CompilerOptionName::MatrixLayoutRow, true);
}
Profile CompilerOptionSet::getProfile()
{
if (auto profileRaw = getEnumOption<Profile::RawEnum>(CompilerOptionName::Profile))
return Profile(profileRaw);
return Profile();
}
void CompilerOptionSet::setProfile(Profile profile)
{
set(CompilerOptionName::Profile, (int)profile.raw);
}
ProfileVersion CompilerOptionSet::getProfileVersion()
{
if (auto profileRaw = getEnumOption<Profile::RawEnum>(CompilerOptionName::Profile))
return Profile(profileRaw).getVersion();
return ProfileVersion::Unknown;
}
void CompilerOptionSet::setProfileVersion(ProfileVersion version)
{
Profile profile;
if (auto profileRaw = getEnumOption<Profile::RawEnum>(CompilerOptionName::Profile))
profile = Profile(profileRaw);
profile.setVersion(version);
set(CompilerOptionName::Profile, (int)profile.raw);
}
void CompilerOptionSet::addCapabilityAtom(CapabilityName cap)
{
add(CompilerOptionName::Capability, cap);
}
List<String> CompilerOptionSet::getDownstreamArgs(String downstreamToolName)
{
List<String> result;
auto downstreamArgsArray = getArray(CompilerOptionName::DownstreamArgs);
for (auto& argSet : downstreamArgsArray)
{
if (argSet.stringValue == downstreamToolName)
{
CommandLineArgs args;
args.deserialize(argSet.stringValue2);
for (auto arg : args.m_args)
result.add(arg.value);
break;
}
}
return result;
}
void CompilerOptionSet::serialize(SerializedOptionsData* outData)
{
for (auto& option : options)
{
for (auto val : option.value)
{
slang::CompilerOptionEntry entry = {};
entry.name = option.key;
entry.value.kind = val.kind;
entry.value.intValue0 = val.intValue;
entry.value.intValue1 = val.intValue2;
outData->stringPool.add(val.stringValue);
entry.value.stringValue0 = val.stringValue.getBuffer();
outData->stringPool.add(val.stringValue2);
entry.value.stringValue1 = val.stringValue.getBuffer();
outData->entries.add(entry);
}
}
}
void applySettingsToDiagnosticSink(DiagnosticSink* targetSink, DiagnosticSink* outputSink, CompilerOptionSet& options)
{
auto disableArray = options.getArray(CompilerOptionName::DisableWarning);
for (auto& element : disableArray)
{
overrideDiagnostic(targetSink, outputSink, element.stringValue.getUnownedSlice(), Severity::Warning, Severity::Disable);
}
disableArray = options.getArray(CompilerOptionName::DisableWarnings);
for (auto& element : disableArray)
{
overrideDiagnostics(targetSink, outputSink, element.stringValue.getUnownedSlice(), Severity::Warning, Severity::Disable);
}
auto enableArray = options.getArray(CompilerOptionName::EnableWarning);
for (auto& element : enableArray)
{
overrideDiagnostics(targetSink, outputSink, element.stringValue.getUnownedSlice(), Severity::Warning, Severity::Warning);
}
auto warningsAsErrorsArray = options.getArray(CompilerOptionName::WarningsAsErrors);
for (auto& element : warningsAsErrorsArray)
{
if (element.stringValue == "all")
targetSink->setFlag(DiagnosticSink::Flag::TreatWarningsAsErrors);
else
overrideDiagnostics(targetSink, outputSink, element.stringValue.getUnownedSlice(), Severity::Warning, Severity::Error);
}
}
}
|