From 7c8527d20e433c3a10736136d31e4cd882a3baaa Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Fri, 4 Oct 2019 09:46:03 -0400 Subject: 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. --- source/slang/slang-lower-to-ir.cpp | 73 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) (limited to 'source/slang/slang-lower-to-ir.cpp') 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 { IRGenContext* context; + DiagnosticSink* getSink() { return context->getSink(); } + IRBuilder* getBuilder() { return context->irBuilder; @@ -5573,6 +5575,27 @@ struct DeclLoweringVisitor : DeclVisitor } } + IRIntLit* _getIntLitFromAttribute(IRBuilder* builder, Attribute* attrib) + { + attrib->args.getCount(); + SLANG_ASSERT(attrib->args.getCount() ==1); + Expr* expr = attrib->args[0]; + auto intLitExpr = as(expr); + SLANG_ASSERT(intLitExpr); + return as(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(expr); + SLANG_ASSERT(stringLitExpr); + return as(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 getBuilder()->addRequireGLSLVersionDecoration(irFunc, Int(getIntegerLiteralValue(versionMod->versionNumberToken))); } + if (auto attr = decl->FindModifier()) + { + IRIntLit* intLit = _getIntLitFromAttribute(getBuilder(), attr); + getBuilder()->addDecoration(irFunc, kIROp_InstanceDecoration, intLit); + } + + if(auto attr = decl->FindModifier()) + { + IRIntLit* intLit = _getIntLitFromAttribute(getBuilder(), attr); + getBuilder()->addDecoration(irFunc, kIROp_MaxVertexCountDecoration, intLit); + } + + if(auto attr = decl->FindModifier()) + { + 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()) { getBuilder()->addSimpleDecoration(irFunc); @@ -5922,6 +5971,30 @@ struct DeclLoweringVisitor : DeclVisitor getBuilder()->addSimpleDecoration(irFunc); } + if (auto attr = decl->FindModifier()) + { + IRStringLit* stringLit = _getStringLitFromAttribute(getBuilder(), attr); + getBuilder()->addDecoration(irFunc, kIROp_DomainDecoration, stringLit); + } + + if (auto attr = decl->FindModifier()) + { + IRStringLit* stringLit = _getStringLitFromAttribute(getBuilder(), attr); + getBuilder()->addDecoration(irFunc, kIROp_PartitioningDecoration, stringLit); + } + + if (auto attr = decl->FindModifier()) + { + IRStringLit* stringLit = _getStringLitFromAttribute(getBuilder(), attr); + getBuilder()->addDecoration(irFunc, kIROp_OutputTopologyDecoration, stringLit); + } + + if (auto attr = decl->FindModifier()) + { + 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 -- cgit v1.2.3