From e0de98e9aabbe118f0eeca7821518c8fb4e1f6c4 Mon Sep 17 00:00:00 2001 From: ArielG-NV <159081215+ArielG-NV@users.noreply.github.com> Date: Wed, 3 Apr 2024 14:19:15 -0400 Subject: 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 --- source/slang/slang-emit-glsl.cpp | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'source/slang/slang-emit-glsl.cpp') diff --git a/source/slang/slang-emit-glsl.cpp b/source/slang/slang-emit-glsl.cpp index 2347d086b..1ae178aa8 100644 --- a/source/slang/slang-emit-glsl.cpp +++ b/source/slang/slang-emit-glsl.cpp @@ -116,25 +116,26 @@ void GLSLSourceEmitter::_requireGLSLVersion(int version) void GLSLSourceEmitter::_emitMemoryQualifierDecorations(IRInst* varDecl) { - for (auto decoration : varDecl->getDecorations()) + if(auto collection = varDecl->findDecoration()) { - if (as(decoration)) + IRIntegerValue flags = collection->getMemoryQualifierBit(); + if (flags & MemoryQualifierSetModifier::Flags::kCoherent) { m_writer->emit("coherent "); } - else if (as(decoration)) + if (flags & MemoryQualifierSetModifier::Flags::kVolatile) { m_writer->emit("volatile "); } - else if (as(decoration)) + if (flags & MemoryQualifierSetModifier::Flags::kRestrict) { m_writer->emit("restrict "); } - else if (as(decoration)) + if (flags & MemoryQualifierSetModifier::Flags::kReadOnly) { m_writer->emit("readonly "); } - else if (as(decoration)) + if (flags & MemoryQualifierSetModifier::Flags::kWriteOnly) { m_writer->emit("writeonly "); } @@ -2749,11 +2750,6 @@ void GLSLSourceEmitter::emitVarDecorationsImpl(IRInst* varDecl) m_writer->emit(toSlice(")\n")); } } - - if (varDecl->findDecoration()) - { - m_writer->emit("coherent\n"); - } } void GLSLSourceEmitter::emitMatrixLayoutModifiersImpl(IRVarLayout* layout) -- cgit v1.2.3