diff options
| author | Ellie Hermaszewska <ellieh@nvidia.com> | 2023-08-15 20:28:42 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-08-15 20:28:42 +0800 |
| commit | 00bd481e001e8c0b8008eaff5a38fa37963e6f99 (patch) | |
| tree | d068f0649167bff80b9cd3aa7d32d790540e9564 /source/slang/slang-lower-to-ir.cpp | |
| parent | 113a257aafe4403c3ab905098d0560635ca94286 (diff) | |
SPIR-V WIP (#3064)
* Add type layout for structured buffer
* Default to generating spirv directly
* vk test for compute simple
* Add spirv-dis as a downstream compiler
* Emit Array types in SPIR-V
* makevector for spirv
* Dump whole spirv module on validation failure
* register array types
todo, use emitTypeInst
* Neater formatting for unhandled inst printing
* break out emitCompositeConstruct
* Correct array type generation
* neaten
* Allow getElement for vector
* Remove unused
* Allow predicating target intrinsics on types
* Consider functions with intrinsics to have definitions
We need to specialize these if they are predicated on types
* Correct array type generation
* makeArray for spir-v
* replace getElement with getElementPtr for spirv
* Correct translation of field access for spirv
* Push layouts to types for spirv
* Spirv intrinsics * operator now makes a pointer
* Add structured buffer of struct test
* Preserve type layout in spirv structured buffer legalization
* neaten
* makeVectorFromScalar for SPIRV
* placeholder for layouts on param groups
* More type safe spirv op construction
* Know that constants and types only go in one section
* Remove emitTypeInst
* Add todo for spirv sampling
* Add links to spirv documentation on emit functions
* OpTypeImage support for SPIR-V
* Add simpler texture test for spirv
* s/spirv_direct/spirv/g
* Allow several string literals in target_intrinsic
* Handle global params without a var layour for SPIR-V
For example groupshared vars
* uint spirv asm type
* Add todo for isDefinition
It is currently too broad
* Some atomic op spirv intrinsics
* Strip ConstantBuffer wrappers for spirv
* Add todo for matrix annotations
* Do not associate decorations insts with spirv counterparts
* Correct entry point parameter generation
* Spelling
* Assert that fieldAddress is returning a pointer
* Add error for existential type layout getting to spir-v emit
* Add IRTupleTypeLayout
Unused so far
* Allow getElementPtr to work with vectors
* Correct target name in test
* Hide default spirv direct behind a premake option --default-spirv-direct=true
* Do not insert space at start of intrinsic def
* Correct asm rendering in tests
* remove redundant option
* Emit directly from direct test
* Add source language options for spirv-dis
* Add comments to spirv dis
* Add dead debug print for before spirv module
* Correct asm rendering in tests
* s/spirv_direct/spirv/g
* Only specialize intrinsic functions with predicates
* regenerate vs projects
* squash warnings
* squash warnings
* remove duplication
* Silence warnings from msvc
* squash warnings
* Overload for zero sized array
* More msvc warnings
* warnings
* Add spirv-tools to path for tests
* Do not be specific about dxc version for diag test
* Normalize line endings from spirv-dis
* Correct filecheck matches
* Temporarily disable two spirv tests
Failing on CI, undebuggable hang :/
* Do not emit storage class more than once for spirv snippet
* Do not pass spir-v to spirv-dis by stdin
* Do not get spirv-dis output via stream, use file
* normalize file endings in spirv-dis output
Diffstat (limited to 'source/slang/slang-lower-to-ir.cpp')
| -rw-r--r-- | source/slang/slang-lower-to-ir.cpp | 40 |
1 files changed, 29 insertions, 11 deletions
diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp index d67d57001..f89f92711 100644 --- a/source/slang/slang-lower-to-ir.cpp +++ b/source/slang/slang-lower-to-ir.cpp @@ -6790,7 +6790,7 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo> builder->addHighLevelDeclDecoration(irParam, decl); } - addTargetIntrinsicDecorations(irParam, decl); + addTargetIntrinsicDecorations(nullptr, irParam, decl); // A global variable's SSA value is a *pointer* to // the underlying storage. @@ -7401,7 +7401,7 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo> irInterface->moveToEnd(); - addTargetIntrinsicDecorations(irInterface, decl); + addTargetIntrinsicDecorations(subContext, irInterface, decl); auto finalVal = finishOuterGenerics(subBuilder, irInterface, outerGeneric); return LoweredValInfo::simple(finalVal); @@ -7602,7 +7602,7 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo> // type declarations later, from the top-level emit logic. irAggType->moveToEnd(); - addTargetIntrinsicDecorations(irAggType, decl); + addTargetIntrinsicDecorations(subContext, irAggType, decl); for (auto modifier : decl->modifiers) { if (as<NonCopyableTypeAttribute>(modifier)) @@ -7747,7 +7747,7 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo> // We allow a field to be marked as a target intrinsic, // so that we can override its mangled name in the // output for the chosen target. - addTargetIntrinsicDecorations(irFieldKey, fieldDecl); + addTargetIntrinsicDecorations(nullptr, irFieldKey, fieldDecl); return LoweredValInfo::simple(irFieldKey); } @@ -8152,6 +8152,7 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo> // Attach target-intrinsic decorations to an instruction, // based on modifiers on an AST declaration. void addTargetIntrinsicDecorations( + IRGenContext* subContext, IRInst* irInst, Decl* decl) { @@ -8160,14 +8161,13 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo> for (auto targetMod : decl->getModifiersOfType<TargetIntrinsicModifier>()) { String definition; - auto definitionToken = targetMod->definitionToken; - if (definitionToken.type == TokenType::StringLiteral) + if(targetMod->isString) { - definition = getStringLiteralTokenValue(definitionToken); + definition = targetMod->definitionString; } - else if(definitionToken.type == TokenType::Identifier) + else if (targetMod->definitionIdent.type == TokenType::Identifier) { - definition = definitionToken.getContent(); + definition = targetMod->definitionIdent.getContent(); } else { @@ -8201,7 +8201,19 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo> targetCaps = CapabilitySet(targetCap); } - builder->addTargetIntrinsicDecoration(irInst, targetCaps, definition.getUnownedSlice()); + IRInst* scrutinee = nullptr; + UnownedStringSlice predicate; + if(targetMod->scrutineeDeclRef) + { + const auto s = subContext->findLoweredDecl(targetMod->scrutineeDeclRef.getDecl()); + if(s && s->flavor == LoweredValInfo::Flavor::Simple) + { + scrutinee = s->val; + predicate = targetMod->predicateToken.getContent(); + } + } + + builder->addTargetIntrinsicDecoration(irInst, targetCaps, definition.getUnownedSlice(), predicate, scrutinee); } if(const auto nvapiMod = decl->findModifier<NVAPIMagicModifier>()) @@ -8685,7 +8697,7 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo> // If this declaration was marked as having a target-specific lowering // for a particular target, then handle that here. - addTargetIntrinsicDecorations(irFunc, decl); + addTargetIntrinsicDecorations(subContext, irFunc, decl); addCatchAllIntrinsicDecorationIfNeeded(irFunc, decl); @@ -10019,6 +10031,12 @@ IRTypeLayout* lowerTypeLayout( return _lowerTypeLayoutCommon(context, &builder, paramGroupTypeLayout); } + else if( auto structuredBufferTypeLayout = as<StructuredBufferTypeLayout>(typeLayout)) + { + auto irElementTypeLayout = lowerTypeLayout(context, structuredBufferTypeLayout->elementTypeLayout); + IRStructuredBufferTypeLayout::Builder builder(context->irBuilder, irElementTypeLayout); + return _lowerTypeLayoutCommon(context, &builder, structuredBufferTypeLayout); + } else if( auto structTypeLayout = as<StructTypeLayout>(typeLayout) ) { IRStructTypeLayout::Builder builder(context->irBuilder); |
