diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2019-10-04 09:46:03 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-10-04 09:46:03 -0400 |
| commit | 7c8527d20e433c3a10736136d31e4cd882a3baaa (patch) | |
| tree | 44032051a4d76c8773b8a503dae14d9c8c9e786d /source/slang/slang-lower-to-ir.cpp | |
| parent | 0bc7d9b0aeb77c40befeb3618240a065374216a1 (diff) | |
IR types for subset of Attributes (#1067)
* IROutputControlPointsDecoration
* IROutputTopologyDecoration
* IRPartitioningDecoration
* IRDomainDecoration
* Use IRPatchConstantDecoration alone for hlsl output.
* IRMaxVertexCountDecoration
* IRInstanceDecoration
* Removed _emitHLSLAttributeSingleString and _emitHLSLAttributeSingleInt
Removed GLSLBindingAttribute and just use NumThreadsAttribute
* Added IRNumThreadsDecoration.
* Added IRNumThreadsDecoration
* Fix build problem on x86.
Improve diagnostic text based on review.
Diffstat (limited to 'source/slang/slang-lower-to-ir.cpp')
| -rw-r--r-- | source/slang/slang-lower-to-ir.cpp | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp index 1edd7d331..a622c9802 100644 --- a/source/slang/slang-lower-to-ir.cpp +++ b/source/slang/slang-lower-to-ir.cpp @@ -4075,6 +4075,8 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo> { IRGenContext* context; + DiagnosticSink* getSink() { return context->getSink(); } + IRBuilder* getBuilder() { return context->irBuilder; @@ -5573,6 +5575,27 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo> } } + IRIntLit* _getIntLitFromAttribute(IRBuilder* builder, Attribute* attrib) + { + attrib->args.getCount(); + SLANG_ASSERT(attrib->args.getCount() ==1); + Expr* expr = attrib->args[0]; + auto intLitExpr = as<IntegerLiteralExpr>(expr); + SLANG_ASSERT(intLitExpr); + return as<IRIntLit>(builder->getIntValue(builder->getIntType(), intLitExpr->value)); + } + + IRStringLit* _getStringLitFromAttribute(IRBuilder* builder, Attribute* attrib) + { + attrib->args.getCount(); + SLANG_ASSERT(attrib->args.getCount() == 1); + Expr* expr = attrib->args[0]; + + auto stringLitExpr = as<StringLiteralExpr>(expr); + SLANG_ASSERT(stringLitExpr); + return as<IRStringLit>(builder->getStringValue(stringLitExpr->value.getUnownedSlice())); + } + LoweredValInfo lowerFuncDecl(FunctionDeclBase* decl) { // We are going to use a nested builder, because we will @@ -5912,6 +5935,32 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo> getBuilder()->addRequireGLSLVersionDecoration(irFunc, Int(getIntegerLiteralValue(versionMod->versionNumberToken))); } + if (auto attr = decl->FindModifier<InstanceAttribute>()) + { + IRIntLit* intLit = _getIntLitFromAttribute(getBuilder(), attr); + getBuilder()->addDecoration(irFunc, kIROp_InstanceDecoration, intLit); + } + + if(auto attr = decl->FindModifier<MaxVertexCountAttribute>()) + { + IRIntLit* intLit = _getIntLitFromAttribute(getBuilder(), attr); + getBuilder()->addDecoration(irFunc, kIROp_MaxVertexCountDecoration, intLit); + } + + if(auto attr = decl->FindModifier<NumThreadsAttribute>()) + { + auto builder = getBuilder(); + IRType* intType = builder->getIntType(); + + IRInst* operands[3] = { + builder->getIntValue(intType, attr->x), + builder->getIntValue(intType, attr->y), + builder->getIntValue(intType, attr->z) + }; + + builder->addDecoration(irFunc, kIROp_NumThreadsDecoration, operands, 3); + } + if(decl->FindModifier<ReadNoneAttribute>()) { getBuilder()->addSimpleDecoration<IRReadNoneDecoration>(irFunc); @@ -5922,6 +5971,30 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo> getBuilder()->addSimpleDecoration<IREarlyDepthStencilDecoration>(irFunc); } + if (auto attr = decl->FindModifier<DomainAttribute>()) + { + IRStringLit* stringLit = _getStringLitFromAttribute(getBuilder(), attr); + getBuilder()->addDecoration(irFunc, kIROp_DomainDecoration, stringLit); + } + + if (auto attr = decl->FindModifier<PartitioningAttribute>()) + { + IRStringLit* stringLit = _getStringLitFromAttribute(getBuilder(), attr); + getBuilder()->addDecoration(irFunc, kIROp_PartitioningDecoration, stringLit); + } + + if (auto attr = decl->FindModifier<OutputTopologyAttribute>()) + { + IRStringLit* stringLit = _getStringLitFromAttribute(getBuilder(), attr); + getBuilder()->addDecoration(irFunc, kIROp_OutputTopologyDecoration, stringLit); + } + + if (auto attr = decl->FindModifier<OutputControlPointsAttribute>()) + { + IRIntLit* intLit = _getIntLitFromAttribute(getBuilder(), attr); + getBuilder()->addDecoration(irFunc, kIROp_OutputControlPointsDecoration, intLit); + } + // For convenience, ensure that any additional global // values that were emitted while outputting the function // body appear before the function itself in the list |
