From b915ae662b2e4bcaaeb6da62eb964356d0a978b4 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Thu, 5 May 2022 15:53:29 -0400 Subject: Support for HLSL `export` (#2223) * #include an absolute path didn't work - because paths were taken to always be relative. * Add support for HLSL `export`. * Test for using `export` keyword. --- source/slang/slang-emit-hlsl.cpp | 46 +++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 17 deletions(-) (limited to 'source/slang/slang-emit-hlsl.cpp') diff --git a/source/slang/slang-emit-hlsl.cpp b/source/slang/slang-emit-hlsl.cpp index 650012b9f..945f00499 100644 --- a/source/slang/slang-emit-hlsl.cpp +++ b/source/slang/slang-emit-hlsl.cpp @@ -727,28 +727,40 @@ void HLSLSourceEmitter::emitLoopControlDecorationImpl(IRLoopControlDecoration* d } } -void HLSLSourceEmitter::emitFuncDecorationImpl(IRDecoration* decoration) +static bool _canEmitExport(const Profile& profile) { - switch( decoration->getOp() ) - { - case kIROp_PublicDecoration: + const auto family = profile.getFamily(); + const auto version = profile.getVersion(); + // Is ita late enough version of shader model to output with 'export' + return (family == ProfileFamily::DX && version >= ProfileVersion::DX_6_1); +} + +/* virtual */void HLSLSourceEmitter::emitFuncDecorationsImpl(IRFunc* func) +{ + // Specially handle export, as we don't want to emit it multiple times + if (getTargetReq()->isWholeProgramRequest() && + _canEmitExport(m_effectiveProfile)) { - auto profile = m_effectiveProfile; - - const auto family = profile.getFamily(); - const auto version = profile.getVersion(); - - // If it's whole program and it's for a late enough version of shader model - // output with 'export' - if (getTargetReq()->isWholeProgramRequest() && - family == ProfileFamily::DX && - version >= ProfileVersion::DX_6_1) + for (auto decoration : func->getDecorations()) { - m_writer->emit("export\n"); + const auto op = decoration->getOp(); + if (op == kIROp_PublicDecoration || + op == kIROp_HLSLExportDecoration) + { + m_writer->emit("export\n"); + break; + } } - break; } - + + // Use the default for others + Super::emitFuncDecorationsImpl(func); +} + +void HLSLSourceEmitter::emitFuncDecorationImpl(IRDecoration* decoration) +{ + switch( decoration->getOp() ) + { case kIROp_NoInlineDecoration: m_writer->emit("[noinline]\n"); break; -- cgit v1.2.3