From 21d17abb0e511806b7c93effc58f37169d837766 Mon Sep 17 00:00:00 2001 From: Ellie Hermaszewska Date: Fri, 15 Dec 2023 23:41:27 +0800 Subject: GLSL SSBO Support (#3400) * Squash warnings and fix build with SLANG_EMBED_STDLIB * Add GLSLShaderStorageBuffer magic wrapper * Make GLSLSSBO not a uniform type * Buffers are global variables * Allow creating ssbo aggregate types * Allow reading from RWSB using builder * Nicer debug printing for ssbos * Lower SSBO to RWSB * Parse interface blocks into wrapped structs * Lower Interface Block Decls to structs * remove comment * Two simple ssbo tests * Move ssbo pass earlier * Correct mutable buffer detection * Do not replace ssbo usages outside of blocks * Treat GLSLSSBO as a mutable buffer for type layouts * regenerate vs projects * Correctly detect ssbo types * Diagnose illegal ssbo * remove unreachable code * neaten * ci wobble * Make GLSLSSBO ast handling more uniform * Add modifier cases for glsl * Use empty val info for unhandled interface blocks necessary for ./tests/glsl/out-binding-redeclaration.slang * more sophisticated modifier check * Correct ssbo wrapper name --- source/slang/slang-ir.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'source/slang/slang-ir.cpp') diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp index 833ce5bb5..f9a1276fe 100644 --- a/source/slang/slang-ir.cpp +++ b/source/slang/slang-ir.cpp @@ -4418,6 +4418,16 @@ namespace Slang return classType; } + IRGLSLShaderStorageBufferType* IRBuilder::createGLSLShaderStorableBufferType() + { + IRGLSLShaderStorageBufferType* ssboType = createInst( + this, + kIROp_GLSLShaderStorageBufferType, + getTypeKind()); + addGlobalValue(this, ssboType); + return ssboType; + } + IRInterfaceType* IRBuilder::createInterfaceType(UInt operandCount, IRInst* const* operands) { IRInterfaceType* interfaceType = createInst( @@ -5932,6 +5942,22 @@ namespace Slang return emitIntrinsicInst(nullptr, kIROp_GenericAsm, 1, &arg); } + IRInst* IRBuilder::emitRWStructuredBufferGetElementPtr(IRInst* structuredBuffer, IRInst* index) + { + const auto sbt = cast(structuredBuffer->getDataType()); + const auto t = getPtrType(sbt->getElementType()); + IRInst* const operands[2] = {structuredBuffer, index}; + const auto i = createInst( + this, + kIROp_RWStructuredBufferGetElementPtr, + t, + 2, + operands + ); + addInst(i); + return i; + } + // // Decorations // @@ -6416,6 +6442,8 @@ namespace Slang switch( inst->getOp() ) { case kIROp_StructType: + case kIROp_ClassType: + case kIROp_GLSLShaderStorageBufferType: case kIROp_InterfaceType: return false; @@ -6812,6 +6840,8 @@ namespace Slang case kIROp_WitnessTable: case kIROp_StructType: + case kIROp_ClassType: + case kIROp_GLSLShaderStorageBufferType: case kIROp_SPIRVAsm: dumpIRParentInst(context, inst); return; @@ -7012,6 +7042,7 @@ namespace Slang { case kIROp_StructType: case kIROp_ClassType: + case kIROp_GLSLShaderStorageBufferType: case kIROp_InterfaceType: case kIROp_Generic: case kIROp_Param: @@ -7737,6 +7768,7 @@ namespace Slang // All of the cases for "global values" are side-effect-free. case kIROp_StructType: case kIROp_StructField: + case kIROp_GLSLShaderStorageBufferType: case kIROp_RTTIPointerType: case kIROp_RTTIObject: case kIROp_RTTIType: -- cgit v1.2.3