summaryrefslogtreecommitdiff
path: root/source/slang/slang-emit-spirv.cpp
diff options
context:
space:
mode:
authorArielG-NV <159081215+ArielG-NV@users.noreply.github.com>2024-04-03 14:19:15 -0400
committerGitHub <noreply@github.com>2024-04-03 11:19:15 -0700
commite0de98e9aabbe118f0eeca7821518c8fb4e1f6c4 (patch)
treea310629cd025372c6d554705ba7f42251f400ac5 /source/slang/slang-emit-spirv.cpp
parenta697b2c6707ee699cb734a03fa529dd214ac66cc (diff)
Refactor memory qualifier decorators to be a bit-flag set, resolves #3841 (#3881)
* Refactor memory qualifier decorators to be a bit-flag set. replace GloballyCoherent, ReadOnly, WriteOnly, Volatile, and Restrict memory modifiers and decorations with a bit flag set to more efficiently manage memory qualifiers. added `restrict` modifier to test to ensure the code works when dropping a `restrict` memory qualifier * Refine tests & add SSBO memory qualifer support add CHECK's to tests to ensure memory qualifiers emit as intended added tests and changed code to ensure memory qualifiers work on SSBO objects (SPIR-V & GLSL) * add memory qualifiers & fixes. Add to StructuredBuffer & ByteAddressBuffer `ReadOnly`/NonWritable qualifier. * Memory qualifiers must be decorated on a variable inst. Due to this the qualifier is added after `lowerStructuredBufferType` Fixed an error where ReadOnly->NonReadable & WriteOnly->NonWritable * Adjusted tests accordingly Added back the removed `globallycoherent` memory qualifier emit'ing code in hlsl-emit (was incorrectly removed). undo hlsl.meta changes cleanup
Diffstat (limited to 'source/slang/slang-emit-spirv.cpp')
-rw-r--r--source/slang/slang-emit-spirv.cpp129
1 files changed, 92 insertions, 37 deletions
diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp
index 91078e1fa..8bc3b9a44 100644
--- a/source/slang/slang-emit-spirv.cpp
+++ b/source/slang/slang-emit-spirv.cpp
@@ -3344,36 +3344,47 @@ struct SPIRVEmitContext
requireSPIRVCapability(SpvCapabilityRayQueryKHR);
isRayTracingObject = true;
break;
- case kIROp_GloballyCoherentDecoration:
- emitOpDecorate(getSection(SpvLogicalSectionID::Annotations),
- decoration,
- dstID,
- SpvDecorationCoherent);
- break;
- case kIROp_GLSLVolatileDecoration:
- emitOpDecorate(getSection(SpvLogicalSectionID::Annotations),
- decoration,
- dstID,
- SpvDecorationVolatile);
- break;
- case kIROp_GLSLRestrictDecoration:
- emitOpDecorate(getSection(SpvLogicalSectionID::Annotations),
- decoration,
- dstID,
- SpvDecorationRestrict);
- break;
- case kIROp_GLSLReadOnlyDecoration:
- emitOpDecorate(getSection(SpvLogicalSectionID::Annotations),
- decoration,
- dstID,
- SpvDecorationNonWritable);
- break;
- case kIROp_GLSLWriteOnlyDecoration:
- emitOpDecorate(getSection(SpvLogicalSectionID::Annotations),
- decoration,
- dstID,
- SpvDecorationNonReadable);
+ case kIROp_MemoryQualifierSetDecoration:
+ {
+ auto collection = as<IRMemoryQualifierSetDecoration>(decoration);
+ IRIntegerValue flags = collection->getMemoryQualifierBit();
+ if (flags & MemoryQualifierSetModifier::Flags::kCoherent)
+ {
+ emitOpDecorate(getSection(SpvLogicalSectionID::Annotations),
+ nullptr,
+ dstID,
+ SpvDecorationCoherent);
+ }
+ if (flags & MemoryQualifierSetModifier::Flags::kVolatile)
+ {
+ emitOpDecorate(getSection(SpvLogicalSectionID::Annotations),
+ nullptr,
+ dstID,
+ SpvDecorationVolatile);
+ }
+ if (flags & MemoryQualifierSetModifier::Flags::kRestrict)
+ {
+ emitOpDecorate(getSection(SpvLogicalSectionID::Annotations),
+ nullptr,
+ dstID,
+ SpvDecorationRestrict);
+ }
+ if (flags & MemoryQualifierSetModifier::Flags::kReadOnly)
+ {
+ emitOpDecorate(getSection(SpvLogicalSectionID::Annotations),
+ nullptr,
+ dstID,
+ SpvDecorationNonWritable);
+ }
+ if (flags & MemoryQualifierSetModifier::Flags::kWriteOnly)
+ {
+ emitOpDecorate(getSection(SpvLogicalSectionID::Annotations),
+ nullptr,
+ dstID,
+ SpvDecorationNonReadable);
+ }
break;
+ }
// ...
}
@@ -3466,15 +3477,59 @@ struct SPIRVEmitContext
id,
fieldNameDecor->getName());
}
- else if (as<IRGloballyCoherentDecoration>(decor))
+ else if (auto collection = as<IRMemoryQualifierSetDecoration>(decor))
{
- emitOpMemberDecorate(
- getSection(SpvLogicalSectionID::Annotations),
- decor,
- spvStructID,
- SpvLiteralInteger::from32(id),
- SpvDecorationCoherent
- );
+ IRIntegerValue flags = collection->getMemoryQualifierBit();
+ if (flags & MemoryQualifierSetModifier::Flags::kCoherent)
+ {
+ emitOpMemberDecorate(
+ getSection(SpvLogicalSectionID::Annotations),
+ nullptr,
+ spvStructID,
+ SpvLiteralInteger::from32(id),
+ SpvDecorationCoherent
+ );
+ }
+ if (flags & MemoryQualifierSetModifier::Flags::kVolatile)
+ {
+ emitOpMemberDecorate(
+ getSection(SpvLogicalSectionID::Annotations),
+ nullptr,
+ spvStructID,
+ SpvLiteralInteger::from32(id),
+ SpvDecorationVolatile
+ );
+ }
+ if (flags & MemoryQualifierSetModifier::Flags::kRestrict)
+ {
+ emitOpMemberDecorate(
+ getSection(SpvLogicalSectionID::Annotations),
+ nullptr,
+ spvStructID,
+ SpvLiteralInteger::from32(id),
+ SpvDecorationRestrict
+ );
+ }
+ if (flags & MemoryQualifierSetModifier::Flags::kReadOnly)
+ {
+ emitOpMemberDecorate(
+ getSection(SpvLogicalSectionID::Annotations),
+ nullptr,
+ spvStructID,
+ SpvLiteralInteger::from32(id),
+ SpvDecorationNonWritable
+ );
+ }
+ if (flags & MemoryQualifierSetModifier::Flags::kWriteOnly)
+ {
+ emitOpMemberDecorate(
+ getSection(SpvLogicalSectionID::Annotations),
+ nullptr,
+ spvStructID,
+ SpvLiteralInteger::from32(id),
+ SpvDecorationNonReadable
+ );
+ }
}
else if (auto semanticDecor = field->getKey()->findDecoration<IRSemanticDecoration>())
{