From bd6dbaf7c3ea720b4ed39904fe08878f9dcbd947 Mon Sep 17 00:00:00 2001 From: Yong He Date: Mon, 21 Aug 2023 17:07:34 -0700 Subject: Compile append and consume structured buffers to glsl. (#3142) * Compile append and consume structured buffers to glsl. * Fix. * Update CI config. --------- Co-authored-by: Yong He --- source/slang/slang-emit-glsl.cpp | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 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 0920c236c..e1f74f70d 100644 --- a/source/slang/slang-emit-glsl.cpp +++ b/source/slang/slang-emit-glsl.cpp @@ -201,8 +201,11 @@ void GLSLSourceEmitter::_emitGLSLStructuredBuffer(IRGlobalParam* varDecl, IRHLSL m_writer->emit("buffer "); // Generate a dummy name for the block - m_writer->emit("_S"); - m_writer->emit(m_uniqueIDCounter++); + StringBuilder blockTypeName; + blockTypeName << "StructuredBuffer_"; + getTypeNameHint(blockTypeName, structuredBufferType->getElementType()); + blockTypeName << "_t"; + m_writer->emit(_generateUniqueName(blockTypeName.produceString().getUnownedSlice())); m_writer->emit(" {\n"); m_writer->indent(); @@ -2007,6 +2010,37 @@ bool GLSLSourceEmitter::tryEmitInstExprImpl(IRInst* inst, const EmitOpInfo& inOu return false; } +bool GLSLSourceEmitter::tryEmitInstStmtImpl(IRInst* inst) +{ + switch (inst->getOp()) + { + case kIROp_AtomicCounterIncrement: + { + auto oldValName = getName(inst); + m_writer->emit("int "); + m_writer->emit(oldValName); + m_writer->emit(" = "); + m_writer->emit("atomicAdd("); + emitOperand(inst->getOperand(0), getInfo(EmitOp::General)); + m_writer->emit(", 1);\n"); + return true; + } + case kIROp_AtomicCounterDecrement: + { + auto oldValName = getName(inst); + m_writer->emit("int "); + m_writer->emit(oldValName); + m_writer->emit(" = "); + m_writer->emit("atomicAdd("); + emitOperand(inst->getOperand(0), getInfo(EmitOp::General)); + m_writer->emit(", -1);\n"); + return true; + } + default: + return false; + } +} + void GLSLSourceEmitter::handleRequiredCapabilitiesImpl(IRInst* inst) { // Does this function declare any requirements on GLSL version or -- cgit v1.2.3