Skip to content

Commit a289315

Browse files
authored
Merge branch 'master' into cheneym2/samplerbindingdoc
2 parents 07279aa + c356d3a commit a289315

File tree

3 files changed

+64
-4
lines changed

3 files changed

+64
-4
lines changed

source/slang/slang-emit-c-like.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -3722,10 +3722,6 @@ void CLikeSourceEmitter::emitSimpleFuncImpl(IRFunc* func)
37223722
emitEntryPointAttributes(func, entryPointDecor);
37233723
}
37243724

3725-
// Deal with required features/capabilities of the function
3726-
//
3727-
handleRequiredCapabilitiesImpl(func);
3728-
37293725
emitFunctionPreambleImpl(func);
37303726

37313727
emitFuncDecorations(func);
@@ -4885,6 +4881,10 @@ void CLikeSourceEmitter::emitGlobalInstImpl(IRInst* inst)
48854881
{
48864882
m_writer->advanceToSourceLocation(inst->sourceLoc);
48874883

4884+
// Deal with required features/capabilities of the global inst
4885+
//
4886+
handleRequiredCapabilitiesImpl(inst);
4887+
48884888
switch (inst->getOp())
48894889
{
48904890
case kIROp_GlobalHashedStringLiterals:

source/slang/slang-lower-to-ir.cpp

+33
Original file line numberDiff line numberDiff line change
@@ -9101,6 +9101,7 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo>
91019101
subBuilder->addAutoDiffBuiltinDecoration(irAggType);
91029102
}
91039103

9104+
addTargetRequirementDecorations(irAggType, decl);
91049105

91059106
return LoweredValInfo::simple(finalFinishedVal);
91069107
}
@@ -9774,6 +9775,36 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo>
97749775
}
97759776
}
97769777

9778+
void addTargetRequirementDecorations(IRInst* inst, Decl* decl)
9779+
{
9780+
// If this declaration requires certain GLSL extension (or a particular GLSL version)
9781+
// for it to be usable, then declare that here. Similarly for SPIR-V or CUDA
9782+
//
9783+
// TODO: We should wrap this an `SpecializedForTargetModifier` together into a single
9784+
// case for enumerating the "capabilities" that a declaration requires.
9785+
//
9786+
for (auto extensionMod : decl->getModifiersOfType<RequiredGLSLExtensionModifier>())
9787+
{
9788+
getBuilder()->addRequireGLSLExtensionDecoration(
9789+
inst,
9790+
extensionMod->extensionNameToken.getContent());
9791+
}
9792+
for (auto versionMod : decl->getModifiersOfType<RequiredGLSLVersionModifier>())
9793+
{
9794+
getBuilder()->addRequireGLSLVersionDecoration(
9795+
inst,
9796+
Int(getIntegerLiteralValue(versionMod->versionNumberToken)));
9797+
}
9798+
for (auto versionMod : decl->getModifiersOfType<RequiredSPIRVVersionModifier>())
9799+
{
9800+
getBuilder()->addRequireSPIRVVersionDecoration(inst, versionMod->version);
9801+
}
9802+
for (auto versionMod : decl->getModifiersOfType<RequiredCUDASMVersionModifier>())
9803+
{
9804+
getBuilder()->addRequireCUDASMVersionDecoration(inst, versionMod->version);
9805+
}
9806+
}
9807+
97779808
void addBitFieldAccessorDecorations(IRInst* irFunc, Decl* decl)
97789809
{
97799810
// If this is an accessor and the parent is describing some bitfield,
@@ -10340,6 +10371,8 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo>
1034010371

1034110372
addCatchAllIntrinsicDecorationIfNeeded(irFunc, decl);
1034210373

10374+
addTargetRequirementDecorations(irFunc, decl);
10375+
1034310376
bool isInline = false;
1034410377

1034510378
addBitFieldAccessorDecorations(irFunc, decl);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//TEST:SIMPLE(filecheck=CHECK): -target glsl -entry main -stage compute
2+
3+
RWStructuredBuffer<float> outputBuffer;
4+
5+
// Check that extensions on types work
6+
__glsl_extension(GL_BAR_bar)
7+
// CHECK-DAG: #extension GL_BAR_bar : require
8+
struct S
9+
{
10+
float a;
11+
}
12+
13+
// Check that extensions on functions work
14+
__glsl_extension(GL_FOO_foo)
15+
// CHECK-DAG: #extension GL_FOO_foo : require
16+
float foo(S s)
17+
{
18+
return s.a;
19+
}
20+
21+
[numthreads(4, 1, 1)]
22+
void main(uint3 dispatchThreadID : SV_DispatchThreadID)
23+
{
24+
S s;
25+
s.a = 0;
26+
outputBuffer[dispatchThreadID.x] = foo(s);
27+
}

0 commit comments

Comments
 (0)