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-parser.cpp | 45 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) (limited to 'source/slang/slang-parser.cpp') diff --git a/source/slang/slang-parser.cpp b/source/slang/slang-parser.cpp index 1a7845a25..1fd8bffcc 100644 --- a/source/slang/slang-parser.cpp +++ b/source/slang/slang-parser.cpp @@ -190,7 +190,7 @@ namespace Slang void parseSourceFile(ContainerDecl* parentDecl); Decl* ParseStruct(); ClassDecl* ParseClass(); - GLSLInterfaceBlockDecl* ParseGLSLInterfaceBlock(); + Decl* ParseGLSLInterfaceBlock(); Stmt* ParseStatement(Stmt* parentStmt = nullptr); Stmt* parseBlockStatement(); Stmt* parseLabelStatement(); @@ -2379,6 +2379,15 @@ namespace Slang } } + static String _wrappingModifierType(const WrappingTypeModifier* mod) + { + if(as(mod)) + { + return "GLSLShaderStorageBuffer"; + } + SLANG_UNREACHABLE("unhandled wrapping type modifier"); + } + /// Apply any type modifier in `ioBaseModifiers` to the given `typeExpr`. /// /// If any type modifiers were present, `ioBaseModifiers` will be updated @@ -2424,6 +2433,30 @@ namespace Slang // baseModifierLink = &baseModifier->next; } + else if(const auto wrappingTypeModifier = as(typeModifier)) + { + // This is where we match things which are modifiers in the + // syntax, but we match conceptually as wrappers around a type + // expression + + // Firstly, disptach the modifier, we don't need it again + baseModifierLink = &baseModifier->next; + + // Conjure up the generic wrapper type + // Make sure to use the outer scope, to avoid user name shadowing + auto bufferWrapperTypeExpr = parser->astBuilder->create(); + bufferWrapperTypeExpr->loc = wrappingTypeModifier->loc; + bufferWrapperTypeExpr->name = getName(parser, _wrappingModifierType(wrappingTypeModifier)); + bufferWrapperTypeExpr->scope = parser->outerScope; + + // Apply the wrapper + auto bufferPointerTypeExpr = parser->astBuilder->create(); + bufferPointerTypeExpr->loc = wrappingTypeModifier->loc; + bufferPointerTypeExpr->functionExpr = bufferWrapperTypeExpr; + bufferPointerTypeExpr->arguments.add(typeExpr); + + typeExpr = bufferPointerTypeExpr; + } else { // If we have a type modifier, we need to graft it onto @@ -2533,9 +2566,10 @@ namespace Slang && parser->LookAheadToken(TokenType::Identifier) && parser->LookAheadToken(TokenType::LBrace,1) ) { - auto decl = parser->ParseGLSLInterfaceBlock(); - typeSpec.decl = decl; - typeSpec.expr = createDeclRefType(parser, decl); + // Parse the struct-like part + auto innerStructDecl = parser->ParseGLSLInterfaceBlock(); + typeSpec.decl = innerStructDecl; + typeSpec.expr = createDeclRefType(parser, typeSpec.decl); return typeSpec; } else if(parser->LookAheadToken("enum")) @@ -4589,11 +4623,12 @@ namespace Slang return rs; } - GLSLInterfaceBlockDecl* Parser::ParseGLSLInterfaceBlock() + Decl* Parser::ParseGLSLInterfaceBlock() { // // MyBlockName { float myData[]; } myBufferName; // + // This returns a struct decl representing the fields auto* rs = astBuilder->create(); FillPosition(rs); -- cgit v1.2.3