Skip to content

Commit

Permalink
[SPIR-V] Handle vk::ext_capability and vk::ext_extension on entry poi…
Browse files Browse the repository at this point in the history
…nt (#6145)

`ext_capability` and `ext_extension` were previously only handled when
translating a CallExpr. Since the entry point is never called, they were
ignored when attached to it.
  • Loading branch information
cassiebeckley authored Jan 17, 2024
1 parent 2f00209 commit 414acd5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
15 changes: 13 additions & 2 deletions tools/clang/lib/SPIRV/SpirvEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12547,6 +12547,13 @@ void SpirvEmitter::processInlineSpirvAttributes(const FunctionDecl *decl) {
modeAttr->getLocation());
}
}

// Handle extension and capability attrs
if (decl->hasAttr<VKExtensionExtAttr>() ||
decl->hasAttr<VKCapabilityExtAttr>()) {
createSpirvIntrInstExt(decl->getAttrs(), QualType(), /* spvArgs */ {},
/* isInst */ false, decl->getLocStart());
}
}

bool SpirvEmitter::processGeometryShaderAttributes(const FunctionDecl *decl,
Expand Down Expand Up @@ -13136,8 +13143,6 @@ bool SpirvEmitter::emitEntryFunctionWrapper(const FunctionDecl *decl,
assert(entryInfo->isEntryFunction);
entryInfo->entryFunction = entryFunction;

processInlineSpirvAttributes(decl);

if (spvContext.isRay()) {
return emitEntryFunctionWrapperForRayTracing(decl, entryFuncInstr,
debugFunction);
Expand Down Expand Up @@ -13215,6 +13220,12 @@ bool SpirvEmitter::emitEntryFunctionWrapper(const FunctionDecl *decl,
auto *entryLabel = spvBuilder.createBasicBlock();
spvBuilder.setInsertPoint(entryLabel);

// Handle vk::execution_mode, vk::ext_extension and vk::ext_capability
// attributes. Uses pseudo-instructions for extensions and capabilities, which
// are added to the beginning of the entry basic block, so must be called
// after the basic block is created and insert point is set.
processInlineSpirvAttributes(decl);

// Add DebugFunctionDefinition if we are emitting
// NonSemantic.Shader.DebugInfo.100 debug info.
// We will emit it in the wrapper rather than the
Expand Down
2 changes: 2 additions & 0 deletions tools/clang/test/CodeGenSPIRV/spv.inline.capability.hlsl
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// RUN: %dxc -T ps_6_0 -E main -fcgl -Vd %s -spirv | FileCheck %s

// CHECK: OpCapability Int8
// CHECK: OpCapability SampleMaskPostDepthCoverage

[[vk::ext_capability(/* SampleMaskPostDepthCoverageCapability */ 4447)]]
int val;

[[vk::ext_capability(/* Int8 */ 39)]]
void main() {
int local = val;
}
2 changes: 2 additions & 0 deletions tools/clang/test/CodeGenSPIRV/spv.inline.extension.hlsl
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// RUN: %dxc -T ps_6_0 -E main -fcgl %s -spirv | FileCheck %s

// CHECK: OpExtension "entry_point_extension"
// CHECK: OpExtension "another_extension"
// CHECK: OpExtension "some_extension"

[[vk::ext_extension("some_extension"), vk::ext_extension("another_extension")]]
int val;

[[vk::ext_extension("entry_point_extension")]]
void main() {
int local = val;
}

0 comments on commit 414acd5

Please sign in to comment.