Skip to content

Commit c5d0f3a

Browse files
authored
Merge branch 'master' into hlsl/hlsl-set-supported-versio-to-2021
2 parents d5b06a6 + 5d6578b commit c5d0f3a

22 files changed

+412
-60
lines changed

CMakeLists.txt

+31-15
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,19 @@ advanced_option(
199199
)
200200
advanced_option(
201201
SLANG_OVERRIDE_GLSLANG_PATH
202-
"Build using user defined path for glslang, this also requires "
202+
"Build using user defined path for glslang"
203+
OFF
204+
)
205+
206+
advanced_option(
207+
SLANG_EXCLUDE_DAWN
208+
"Optionally exclude webgpu_dawn from the build"
209+
OFF
210+
)
211+
212+
advanced_option(
213+
SLANG_EXCLUDE_TINT
214+
"Optionally exclude slang-tint from the build"
203215
OFF
204216
)
205217

@@ -292,24 +304,28 @@ if(SLANG_SLANG_LLVM_FLAVOR MATCHES FETCH_BINARY)
292304
)
293305
endif()
294306

295-
set(webgpu_dawn_release_tag "webgpu_dawn-0")
296-
if(
297-
CMAKE_SYSTEM_NAME MATCHES "Windows"
298-
AND CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|AMD64"
299-
)
300-
set(SLANG_WEBGPU_DAWN_BINARY_URL
301-
"https://github.com/shader-slang/dawn/releases/download/${webgpu_dawn_release_tag}/webgpu_dawn-windows-x64.zip"
307+
if(NOT SLANG_EXCLUDE_DAWN)
308+
set(webgpu_dawn_release_tag "webgpu_dawn-0")
309+
if(
310+
CMAKE_SYSTEM_NAME MATCHES "Windows"
311+
AND CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|AMD64"
302312
)
313+
set(SLANG_WEBGPU_DAWN_BINARY_URL
314+
"https://github.com/shader-slang/dawn/releases/download/${webgpu_dawn_release_tag}/webgpu_dawn-windows-x64.zip"
315+
)
316+
endif()
303317
endif()
304318

305-
set(slang_tint_release_tag "slang-tint-0")
306-
if(
307-
CMAKE_SYSTEM_NAME MATCHES "Windows"
308-
AND CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|AMD64"
309-
)
310-
set(SLANG_SLANG_TINT_BINARY_URL
311-
"https://github.com/shader-slang/dawn/releases/download/${slang_tint_release_tag}/slang-tint-windows-x64.zip"
319+
if(NOT SLANG_EXCLUDE_TINT)
320+
set(slang_tint_release_tag "slang-tint-0")
321+
if(
322+
CMAKE_SYSTEM_NAME MATCHES "Windows"
323+
AND CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|AMD64"
312324
)
325+
set(SLANG_SLANG_TINT_BINARY_URL
326+
"https://github.com/shader-slang/dawn/releases/download/${slang_tint_release_tag}/slang-tint-windows-x64.zip"
327+
)
328+
endif()
313329
endif()
314330

315331
#

source/compiler-core/slang-downstream-compiler.h

+14
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,9 @@ class IDownstreamCompiler : public ICastable
340340
/// Disassemble and print to stdout
341341
virtual SLANG_NO_THROW SlangResult SLANG_MCALL
342342
disassemble(const uint32_t* contents, int contentsSize) = 0;
343+
/// Disassemble and return the result as a string
344+
virtual SLANG_NO_THROW SlangResult SLANG_MCALL
345+
disassembleWithResult(const uint32_t* contents, int contentsSize, String& outString) = 0;
343346

344347
/// True if underlying compiler uses file system to communicate source
345348
virtual SLANG_NO_THROW bool SLANG_MCALL isFileBased() = 0;
@@ -398,6 +401,17 @@ class DownstreamCompilerBase : public ComBaseObject, public IDownstreamCompiler
398401
return SLANG_FAIL;
399402
}
400403

404+
virtual SLANG_NO_THROW SlangResult SLANG_MCALL disassembleWithResult(
405+
const uint32_t* contents,
406+
int contentsSize,
407+
String& outString) SLANG_OVERRIDE
408+
{
409+
SLANG_UNUSED(contents);
410+
SLANG_UNUSED(contentsSize);
411+
SLANG_UNUSED(outString);
412+
return SLANG_FAIL;
413+
}
414+
401415
DownstreamCompilerBase(const Desc& desc)
402416
: m_desc(desc)
403417
{

source/compiler-core/slang-glslang-compiler.cpp

+29
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ class GlslangDownstreamCompiler : public DownstreamCompilerBase
4949
validate(const uint32_t* contents, int contentsSize) SLANG_OVERRIDE;
5050
virtual SLANG_NO_THROW SlangResult SLANG_MCALL
5151
disassemble(const uint32_t* contents, int contentsSize) SLANG_OVERRIDE;
52+
virtual SLANG_NO_THROW SlangResult SLANG_MCALL disassembleWithResult(
53+
const uint32_t* contents,
54+
int contentsSize,
55+
String& outString) SLANG_OVERRIDE;
5256
int link(
5357
const uint32_t** modules,
5458
const uint32_t* moduleSizes,
@@ -71,6 +75,7 @@ class GlslangDownstreamCompiler : public DownstreamCompilerBase
7175
glslang_CompileFunc_1_2 m_compile_1_2 = nullptr;
7276
glslang_ValidateSPIRVFunc m_validate = nullptr;
7377
glslang_DisassembleSPIRVFunc m_disassemble = nullptr;
78+
glslang_DisassembleSPIRVWithResultFunc m_disassembleWithResult = nullptr;
7479
glslang_LinkSPIRVFunc m_link = nullptr;
7580

7681
ComPtr<ISlangSharedLibrary> m_sharedLibrary;
@@ -86,6 +91,8 @@ SlangResult GlslangDownstreamCompiler::init(ISlangSharedLibrary* library)
8691
m_validate = (glslang_ValidateSPIRVFunc)library->findFuncByName("glslang_validateSPIRV");
8792
m_disassemble =
8893
(glslang_DisassembleSPIRVFunc)library->findFuncByName("glslang_disassembleSPIRV");
94+
m_disassembleWithResult = (glslang_DisassembleSPIRVWithResultFunc)library->findFuncByName(
95+
"glslang_disassembleSPIRVWithResult");
8996
m_link = (glslang_LinkSPIRVFunc)library->findFuncByName("glslang_linkSPIRV");
9097

9198
if (m_compile_1_0 == nullptr && m_compile_1_1 == nullptr && m_compile_1_2 == nullptr)
@@ -316,6 +323,28 @@ SlangResult GlslangDownstreamCompiler::validate(const uint32_t* contents, int co
316323
return SLANG_FAIL;
317324
}
318325

326+
SlangResult GlslangDownstreamCompiler::disassembleWithResult(
327+
const uint32_t* contents,
328+
int contentsSize,
329+
String& outString)
330+
{
331+
if (m_disassembleWithResult == nullptr)
332+
{
333+
return SLANG_FAIL;
334+
}
335+
336+
char* resultString = nullptr;
337+
if (m_disassembleWithResult(contents, contentsSize, &resultString))
338+
{
339+
if (resultString)
340+
{
341+
outString = String(resultString);
342+
return SLANG_OK;
343+
}
344+
}
345+
return SLANG_FAIL;
346+
}
347+
319348
SlangResult GlslangDownstreamCompiler::disassemble(const uint32_t* contents, int contentsSize)
320349
{
321350
if (m_disassemble == nullptr)

source/slang-glslang/slang-glslang.cpp

+37-7
Original file line numberDiff line numberDiff line change
@@ -184,36 +184,64 @@ extern "C"
184184
return tools.Validate(contents, contentsSize, options);
185185
}
186186

187-
// Disassemble the given SPIRV-ASM instructions.
187+
// Disassemble the given SPIRV-ASM instructions and return the result as a string.
188188
extern "C"
189189
#ifdef _MSC_VER
190190
_declspec(dllexport)
191191
#else
192-
__attribute__((__visibility__("default")))
192+
__attribute__((__visibility__("default")))
193193
#endif
194-
bool glslang_disassembleSPIRV(const uint32_t* contents, int contentsSize)
194+
bool glslang_disassembleSPIRVWithResult(
195+
const uint32_t* contents,
196+
int contentsSize,
197+
char** outString)
195198
{
196199
static const auto kDefaultEnvironment = SPV_ENV_UNIVERSAL_1_5;
200+
spv_text text;
197201

198202
uint32_t options = SPV_BINARY_TO_TEXT_OPTION_NONE;
199203
options |= SPV_BINARY_TO_TEXT_OPTION_COMMENT;
200-
options |= SPV_BINARY_TO_TEXT_OPTION_PRINT;
201-
options |= SPV_BINARY_TO_TEXT_OPTION_COLOR;
202204
options |= SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES;
205+
options |= SPV_BINARY_TO_TEXT_OPTION_INDENT;
203206

204207
spv_diagnostic diagnostic = nullptr;
205208
spv_context context = spvContextCreate(kDefaultEnvironment);
206209
spv_result_t error =
207-
spvBinaryToText(context, contents, contentsSize, options, nullptr, &diagnostic);
210+
spvBinaryToText(context, contents, contentsSize, options, &text, &diagnostic);
208211
spvContextDestroy(context);
209212
if (error)
210213
{
211214
spvDiagnosticPrint(diagnostic);
212215
spvDiagnosticDestroy(diagnostic);
213216
return false;
214217
}
218+
else
219+
{
220+
if (outString)
221+
{
222+
// Allocate memory for the output string and copy the result
223+
size_t len = text->length + 1; // +1 for null terminator
224+
*outString = new char[len];
225+
memcpy(*outString, text->str, text->length);
226+
(*outString)[text->length] = '\0'; // Ensure null termination
227+
}
215228

216-
return true;
229+
spvTextDestroy(text);
230+
return true;
231+
}
232+
}
233+
234+
235+
// Disassemble the given SPIRV-ASM instructions.
236+
extern "C"
237+
#ifdef _MSC_VER
238+
_declspec(dllexport)
239+
#else
240+
__attribute__((__visibility__("default")))
241+
#endif
242+
bool glslang_disassembleSPIRV(const uint32_t* contents, int contentsSize)
243+
{
244+
return glslang_disassembleSPIRVWithResult(contents, contentsSize, nullptr);
217245
}
218246

219247
// Apply the SPIRV-Tools optimizer to generated SPIR-V based on the desired optimization level
@@ -997,6 +1025,8 @@ extern "C"
9971025
spvtools::Context context(SPV_ENV_UNIVERSAL_1_5);
9981026
spvtools::LinkerOptions options = {};
9991027

1028+
options.SetUseHighestVersion(true);
1029+
10001030
spvtools::MessageConsumer consumer = [](spv_message_level_t level,
10011031
const char* source,
10021032
const spv_position_t& position,

source/slang-glslang/slang-glslang.h

+4
Original file line numberDiff line numberDiff line change
@@ -166,5 +166,9 @@ typedef int (*glslang_CompileFunc_1_1)(glslang_CompileRequest_1_1* request);
166166
typedef int (*glslang_CompileFunc_1_2)(glslang_CompileRequest_1_2* request);
167167
typedef bool (*glslang_ValidateSPIRVFunc)(const uint32_t* contents, int contentsSize);
168168
typedef bool (*glslang_DisassembleSPIRVFunc)(const uint32_t* contents, int contentsSize);
169+
typedef bool (*glslang_DisassembleSPIRVWithResultFunc)(
170+
const uint32_t* contents,
171+
int contentsSize,
172+
char** outString);
169173
typedef bool (*glslang_LinkSPIRVFunc)(glslang_LinkRequest* request);
170174
#endif

source/slang-llvm/slang-llvm.cpp

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
#include "clang/Basic/Stack.h"
32
#include "clang/Basic/TargetOptions.h"
43
#include "clang/Basic/Version.h"
@@ -147,6 +146,16 @@ class LLVMDownstreamCompiler : public ComBaseObject, public IDownstreamCompiler
147146
SLANG_UNUSED(contentsSize);
148147
return SLANG_FAIL;
149148
}
149+
virtual SLANG_NO_THROW SlangResult SLANG_MCALL disassembleWithResult(
150+
const uint32_t* contents,
151+
int contentsSize,
152+
String& outString) SLANG_OVERRIDE
153+
{
154+
SLANG_UNUSED(contents);
155+
SLANG_UNUSED(contentsSize);
156+
SLANG_UNUSED(outString);
157+
return SLANG_FAIL;
158+
}
150159

151160
LLVMDownstreamCompiler()
152161
: m_desc(

source/slang/slang-check-conversion.cpp

+25-4
Original file line numberDiff line numberDiff line change
@@ -396,14 +396,35 @@ bool SemanticsVisitor::createInvokeExprForSynthesizedCtor(
396396
{
397397
StructDecl* structDecl = isDeclRefTypeOf<StructDecl>(toType).getDecl();
398398

399-
if (!structDecl || !_getSynthesizedConstructor(
400-
structDecl,
401-
ConstructorDecl::ConstructorFlavor::SynthesizedDefault))
399+
if (!structDecl)
402400
return false;
403401

404402
HashSet<Type*> isVisit;
405-
bool isCStyle = isCStyleType(toType, isVisit);
403+
bool isCStyle = false;
404+
if (!_getSynthesizedConstructor(
405+
structDecl,
406+
ConstructorDecl::ConstructorFlavor::SynthesizedDefault))
407+
{
408+
// When a struct has no constructor and it's not a C-style type, the initializer list is
409+
// invalid.
410+
isCStyle = isCStyleType(toType, isVisit);
411+
412+
// WAR: We currently still has to allow legacy initializer list for array type until we have
413+
// more proper solution for array initialization, so if the right hand side is an array
414+
// type, we will not report error and fall-back to legacy initializer list logic.
415+
bool isArrayType = as<ArrayExpressionType>(toType) != nullptr;
416+
if (!isCStyle && !isArrayType)
417+
{
418+
getSink()->diagnose(
419+
fromInitializerListExpr->loc,
420+
Diagnostics::cannotUseInitializerListForType,
421+
toType);
422+
}
423+
424+
return false;
425+
}
406426

427+
isCStyle = isCStyleType(toType, isVisit);
407428
// TODO: This is just a special case for a backwards-compatibility feature
408429
// for HLSL, this flag will imply that the initializer list is synthesized
409430
// for a type cast from a literal zero to a 'struct'. In this case, we will fall

source/slang/slang-check-decl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -12412,7 +12412,7 @@ bool SemanticsDeclAttributesVisitor::_synthesizeCtorSignature(StructDecl* struct
1241212412
// any constructors. see:
1241312413
// https://github.com/shader-slang/slang/blob/master/docs/proposals/004-initialization.md#inheritance-initialization
1241412414
if (_hasExplicitConstructor(structDecl, true))
12415-
return false;
12415+
return true;
1241612416

1241712417
// synthesize the signature first.
1241812418
// The constructor's visibility level is the same as the struct itself.

source/slang/slang-check-shader.cpp

+11-3
Original file line numberDiff line numberDiff line change
@@ -537,9 +537,17 @@ void validateEntryPoint(EntryPoint* entryPoint, DiagnosticSink* sink)
537537
}
538538
else
539539
{
540-
// Only attempt to error if a user adds to slangc either `-profile` or `-capability`
541-
if ((target->getOptionSet().hasOption(CompilerOptionName::Capability) ||
542-
target->getOptionSet().hasOption(CompilerOptionName::Profile)) &&
540+
auto& targetOptionSet = target->getOptionSet();
541+
bool specificProfileRequested =
542+
targetOptionSet.hasOption(CompilerOptionName::Profile) &&
543+
(targetOptionSet.getIntOption(CompilerOptionName::Profile) !=
544+
SLANG_PROFILE_UNKNOWN);
545+
bool specificCapabilityRequested =
546+
targetOptionSet.hasOption(CompilerOptionName::Capability) &&
547+
(targetOptionSet.getIntOption(CompilerOptionName::Capability) !=
548+
SLANG_CAPABILITY_UNKNOWN);
549+
// Only attempt to error if a specific profile or capability is requested
550+
if ((specificCapabilityRequested || specificProfileRequested) &&
543551
targetCaps.atLeastOneSetImpliedInOther(
544552
entryPointFuncDecl->inferredCapabilityRequirements) ==
545553
CapabilitySet::ImpliesReturnFlags::NotImplied)

source/slang/slang-compiler-tu.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,18 @@ Module::precompileForTarget(SlangCompileTarget target, slang::IBlob** outDiagnos
9595
{
9696
CodeGenTarget targetEnum = CodeGenTarget(target);
9797

98+
// Don't precompile twice for the same target
99+
for (auto globalInst : getIRModule()->getModuleInst()->getChildren())
100+
{
101+
if (auto inst = as<IREmbeddedDownstreamIR>(globalInst))
102+
{
103+
if (inst->getTarget() == targetEnum)
104+
{
105+
return SLANG_OK;
106+
}
107+
}
108+
}
109+
98110
auto module = getIRModule();
99111
auto linkage = getLinkage();
100112
auto builder = IRBuilder(module);

source/slang/slang-emit-spirv.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ enum class SpvLogicalSectionID
9191
};
9292

9393
// The registered id for the Slang compiler.
94-
static const uint32_t kSPIRVSlangCompilerId = 40;
94+
static const uint32_t kSPIRVSlangCompilerId = 40 << 16;
9595

9696
// While the SPIR-V module is nominally (according to the spec) just
9797
// a flat sequence of instructions, in practice some of the instructions

0 commit comments

Comments
 (0)