diff --git a/include/dxc/HLSL/DxilContainer.h b/include/dxc/HLSL/DxilContainer.h index 7b1dda767..f2f533fe0 100644 --- a/include/dxc/HLSL/DxilContainer.h +++ b/include/dxc/HLSL/DxilContainer.h @@ -395,6 +395,9 @@ DxilContainerWriter *NewDxilContainerWriter(); void SerializeDxilContainerForModule(hlsl::DxilModule *pModule, AbstractMemoryStream *pModuleBitcode, AbstractMemoryStream *pStream); +void SerializeDxilContainerForRootSignature(hlsl::RootSignatureHandle *pRootSigHandle, + AbstractMemoryStream *pStream); + void CreateDxcContainerReflection(IDxcContainerReflection **ppResult); // Converts uint32_t partKind to char array object. diff --git a/include/dxc/Support/HLSLOptions.h b/include/dxc/Support/HLSLOptions.h index 8ac42a026..9569ed368 100644 --- a/include/dxc/Support/HLSLOptions.h +++ b/include/dxc/Support/HLSLOptions.h @@ -145,6 +145,7 @@ public: bool DisassembleInstNumbers; //OPT_Ni bool DisassembleByteOffset; //OPT_No bool DisaseembleHex; //OPT_Lx + bool IsRootSignatureProfile(); }; /// Use this class to capture, convert and handle the lifetime for the diff --git a/lib/DxcSupport/HLSLOptions.cpp b/lib/DxcSupport/HLSLOptions.cpp index 6ed270b9c..c752e4e47 100644 --- a/lib/DxcSupport/HLSLOptions.cpp +++ b/lib/DxcSupport/HLSLOptions.cpp @@ -113,6 +113,11 @@ void DxcDefines::BuildDefines() { } } +bool DxcOpts::IsRootSignatureProfile() { + return TargetProfile == "rootsig_1_0" || + TargetProfile == "rootsig_1_1"; +} + MainArgs::MainArgs(int argc, const wchar_t **argv, int skipArgCount) { if (argc > skipArgCount) { Utf8StringVector.reserve(argc - skipArgCount); diff --git a/lib/HLSL/DxilContainerAssembler.cpp b/lib/HLSL/DxilContainerAssembler.cpp index 7a5c81fd4..720e5f123 100644 --- a/lib/HLSL/DxilContainerAssembler.cpp +++ b/lib/HLSL/DxilContainerAssembler.cpp @@ -703,3 +703,18 @@ void hlsl::SerializeDxilContainerForModule(DxilModule *pModule, writer.write(pFinalStream); } + +void hlsl::SerializeDxilContainerForRootSignature(hlsl::RootSignatureHandle *pRootSigHandle, + AbstractMemoryStream *pFinalStream) { + DXASSERT_NOMSG(pRootSigHandle != nullptr); + DXASSERT_NOMSG(pFinalStream != nullptr); + DxilContainerWriter_impl writer; + // Write the root signature (RTS0) part. + DxilProgramRootSignatureWriter rootSigWriter(*pRootSigHandle); + if (!pRootSigHandle->IsEmpty()) { + writer.AddPart( + DFCC_RootSignature, rootSigWriter.size(), + [&](AbstractMemoryStream *pStream) { rootSigWriter.write(pStream); }); + } + writer.write(pFinalStream); +} diff --git a/tools/clang/include/clang/Frontend/FrontendActions.h b/tools/clang/include/clang/Frontend/FrontendActions.h index d62356777..2e47d0eb5 100644 --- a/tools/clang/include/clang/Frontend/FrontendActions.h +++ b/tools/clang/include/clang/Frontend/FrontendActions.h @@ -13,6 +13,12 @@ #include #include +// HLSL Change Begin. +namespace hlsl { +class RootSignatureHandle; +} +// HLSL Change End. + namespace clang { class Module; @@ -235,6 +241,26 @@ protected: bool hasPCHSupport() const override { return true; } }; + +// HLSL Change Begin. +class HLSLRootSignatureAction : public PreprocessorFrontendAction { +private: + std::string HLSLRootSignatureMacro; + unsigned rootSigMajor; + unsigned rootSigMinor; + std::unique_ptr rootSigHandle; + +protected: + void ExecuteAction() override; + +public: + HLSLRootSignatureAction(StringRef rootSigMacro, unsigned major, + unsigned minor); + /// Take the generated LLVM module, for use after the action has been run. + /// The result may be null on failure. + std::unique_ptr takeRootSigHandle(); +}; +// HLSL Change End. } // end namespace clang diff --git a/tools/clang/include/clang/Parse/ParseHLSL.h b/tools/clang/include/clang/Parse/ParseHLSL.h index d37fe36e8..27d82fd2f 100644 --- a/tools/clang/include/clang/Parse/ParseHLSL.h +++ b/tools/clang/include/clang/Parse/ParseHLSL.h @@ -20,6 +20,7 @@ class raw_ostream; namespace hlsl { enum class DxilRootSignatureVersion; struct DxilVersionedRootSignatureDesc; +class RootSignatureHandle; } namespace clang { @@ -33,6 +34,10 @@ bool ParseHLSLRootSignature(_In_count_(Len) const char *pData, unsigned Len, void ReportHLSLRootSigError(clang::DiagnosticsEngine &Diags, clang::SourceLocation Loc, _In_count_(Len) const char *pData, unsigned Len); +void CompileRootSignature(StringRef rootSigStr, DiagnosticsEngine &Diags, + SourceLocation SLoc, + hlsl::DxilRootSignatureVersion rootSigVer, + hlsl::RootSignatureHandle *pRootSigHandle); } #endif diff --git a/tools/clang/lib/CodeGen/CGHLSLMS.cpp b/tools/clang/lib/CodeGen/CGHLSLMS.cpp index cef42a519..4790732c0 100644 --- a/tools/clang/lib/CodeGen/CGHLSLMS.cpp +++ b/tools/clang/lib/CodeGen/CGHLSLMS.cpp @@ -261,6 +261,30 @@ public: }; } +void clang::CompileRootSignature( + StringRef rootSigStr, DiagnosticsEngine &Diags, SourceLocation SLoc, + hlsl::DxilRootSignatureVersion rootSigVer, + hlsl::RootSignatureHandle *pRootSigHandle) { + std::string OSStr; + llvm::raw_string_ostream OS(OSStr); + hlsl::DxilVersionedRootSignatureDesc *D = nullptr; + + if (ParseHLSLRootSignature(rootSigStr.data(), rootSigStr.size(), rootSigVer, + &D, SLoc, Diags)) { + CComPtr pSignature; + CComPtr pErrors; + hlsl::SerializeRootSignature(D, &pSignature, &pErrors, false); + if (pSignature == nullptr) { + assert(pErrors != nullptr && "else serialize failed with no msg"); + ReportHLSLRootSigError(Diags, SLoc, (char *)pErrors->GetBufferPointer(), + pErrors->GetBufferSize()); + hlsl::DeleteRootSignature(D); + } else { + pRootSigHandle->Assign(D, pSignature); + } + } +} + //------------------------------------------------------------------------------ // // CGMSHLSLRuntime methods. @@ -5206,24 +5230,8 @@ void CGMSHLSLRuntime::EmitHLSLRootSignature(CodeGenFunction &CGF, StringRef StrRef = RSA->getSignatureName(); DiagnosticsEngine &Diags = CGF.getContext().getDiagnostics(); SourceLocation SLoc = RSA->getLocation(); - std::string OSStr; - raw_string_ostream OS(OSStr); - hlsl::DxilVersionedRootSignatureDesc *D = nullptr; - if (ParseHLSLRootSignature(StrRef.data(), StrRef.size(), rootSigVer, &D, SLoc, - Diags)) { - CComPtr pSignature; - CComPtr pErrors; - hlsl::SerializeRootSignature(D, &pSignature, &pErrors, false); - if (pSignature == nullptr) { - DXASSERT(pErrors != nullptr, "else serialize failed with no msg"); - ReportHLSLRootSigError(Diags, SLoc, - (char *)pErrors->GetBufferPointer(), pErrors->GetBufferSize()); - hlsl::DeleteRootSignature(D); - } else { - m_pHLModule->GetRootSignature().Assign(D, pSignature); - } - } + clang::CompileRootSignature(StrRef, Diags, SLoc, rootSigVer, &m_pHLModule->GetRootSignature()); } void CGMSHLSLRuntime::EmitHLSLOutParamConversionInit( diff --git a/tools/clang/lib/Frontend/FrontendActions.cpp b/tools/clang/lib/Frontend/FrontendActions.cpp index 136de2fba..95e806071 100644 --- a/tools/clang/lib/Frontend/FrontendActions.cpp +++ b/tools/clang/lib/Frontend/FrontendActions.cpp @@ -27,7 +27,10 @@ #include "llvm/Support/raw_ostream.h" #include #include - +// HLSL Change Begin. +#include "dxc/HLSL/DxilRootSignature.h" +#include "clang/Parse/ParseHLSL.h" +// HLSL Change End. using namespace clang; //===----------------------------------------------------------------------===// @@ -697,6 +700,94 @@ void PrintPreprocessedAction::ExecuteAction() { CI.getPreprocessorOutputOpts()); } +// HLSL Change Begin. +HLSLRootSignatureAction::HLSLRootSignatureAction(StringRef rootSigMacro, + unsigned major, unsigned minor) + : HLSLRootSignatureMacro(rootSigMacro), rootSigMajor(major), + rootSigMinor(minor) { + rootSigHandle = std::make_unique(); +} + +void HLSLRootSignatureAction::ExecuteAction() { + CompilerInstance &CI = getCompilerInstance(); + Preprocessor &PP = CI.getPreprocessor(); + // Ignore unknown pragmas. + PP.IgnorePragmas(); + + // Scans and ignores all tokens in the files. + PP.EnterMainSourceFile(); + + Token Tok; + do PP.Lex(Tok); + while (Tok.isNot(tok::eof)); + + hlsl::DxilRootSignatureVersion rootSigVer; + if (rootSigMinor == 0) { + rootSigVer = hlsl::DxilRootSignatureVersion::Version_1_0; + } + else { + assert(rootSigMinor == 1 && + "else CGMSHLSLRuntime Constructor needs to be updated"); + rootSigVer = hlsl::DxilRootSignatureVersion::Version_1_1; + } + + assert(rootSigMajor == 1 && + "else CGMSHLSLRuntime Constructor needs to be updated"); + // Try to find HLSLRootSignatureMacro in macros. + MacroInfo *rootSigMI = nullptr; + for (Preprocessor::macro_iterator I = PP.macro_begin(), E = PP.macro_end(); + I != E; ++I) { + auto *MD = I->second.getLatest(); + if (MD && MD->isDefined()) { + if (I->first->getName() == HLSLRootSignatureMacro) { + rootSigMI = MD->getMacroInfo(); + break; + } + } + } + + DiagnosticsEngine &Diags = CI.getDiagnostics(); + if (!rootSigMI) { + std::string cannotFindMacro = + "undeclared identifier " + HLSLRootSignatureMacro; + SourceLocation SLoc = Tok.getLocation(); + ReportHLSLRootSigError(Diags, SLoc, cannotFindMacro.c_str(), + cannotFindMacro.size()); + return; + } + + SourceLocation SLoc = rootSigMI->getDefinitionLoc(); + + std::string rootSigStr; + llvm::raw_string_ostream rootSigOS(rootSigStr); + + SmallString<128> SpellingBuffer; + for (const auto &T : rootSigMI->tokens()) { + if (T.hasLeadingSpace()) + rootSigOS << ' '; + + rootSigOS << PP.getSpelling(T, SpellingBuffer); + } + rootSigOS.flush(); + StringRef StrRef = rootSigStr; + + // Remove the "" on rootsig macro. + if (StrRef.size() >= 2) { + if (rootSigStr.front() == '"') { + if (rootSigStr.back() == '"') { + StrRef = StrRef.substr(1, StrRef.size()-2); + } + } + } + + clang::CompileRootSignature(StrRef, Diags, SLoc, rootSigVer, rootSigHandle.get()); +} + +std::unique_ptr HLSLRootSignatureAction::takeRootSigHandle() { + return std::move(rootSigHandle); +} +// HLSL Change End. + void PrintPreambleAction::ExecuteAction() { switch (getCurrentFileKind()) { case IK_C: diff --git a/tools/clang/test/CodeGenHLSL/rootSigProfile.hlsl b/tools/clang/test/CodeGenHLSL/rootSigProfile.hlsl new file mode 100644 index 000000000..aefb83c7b --- /dev/null +++ b/tools/clang/test/CodeGenHLSL/rootSigProfile.hlsl @@ -0,0 +1,4 @@ +// RUN: %dxc -E main -T rootsig_1_0 %s + +#define main "RootFlags(ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT), DescriptorTable( visibility=SHADER_VISIBILITY_PIXEL, SRV(t0, numDescriptors=16) ), DescriptorTable( visibility=SHADER_VISIBILITY_PIXEL, CBV(b0, numDescriptors=8) ), DescriptorTable( visibility=SHADER_VISIBILITY_PIXEL, Sampler(s0, numDescriptors=16) ), DescriptorTable( visibility=SHADER_VISIBILITY_VERTEX, SRV(t0, numDescriptors=16) ), DescriptorTable( visibility=SHADER_VISIBILITY_VERTEX, CBV(b0, numDescriptors=8) ), DescriptorTable( visibility=SHADER_VISIBILITY_VERTEX, Sampler(s0, numDescriptors=16) ), DescriptorTable( visibility=SHADER_VISIBILITY_GEOMETRY, SRV(t0, numDescriptors=16) ), DescriptorTable( visibility=SHADER_VISIBILITY_GEOMETRY, CBV(b0, numDescriptors=8) ), DescriptorTable( visibility=SHADER_VISIBILITY_GEOMETRY, Sampler(s0, numDescriptors=16) ), DescriptorTable( visibility=SHADER_VISIBILITY_HULL, SRV(t0, numDescriptors=16) ), DescriptorTable( visibility=SHADER_VISIBILITY_HULL, CBV(b0, numDescriptors=8) ), DescriptorTable( visibility=SHADER_VISIBILITY_HULL, Sampler(s0, numDescriptors=16) ), DescriptorTable( visibility=SHADER_VISIBILITY_DOMAIN, SRV(t0, numDescriptors=16) ), DescriptorTable( visibility=SHADER_VISIBILITY_DOMAIN, CBV(b0, numDescriptors=8) ), DescriptorTable( visibility=SHADER_VISIBILITY_DOMAIN, Sampler(s0, numDescriptors=16) ), DescriptorTable( visibility=SHADER_VISIBILITY_ALL, UAV(u0, numDescriptors=8) )" + diff --git a/tools/clang/test/CodeGenHLSL/rootSigProfile2.hlsl b/tools/clang/test/CodeGenHLSL/rootSigProfile2.hlsl new file mode 100644 index 000000000..7768ea877 --- /dev/null +++ b/tools/clang/test/CodeGenHLSL/rootSigProfile2.hlsl @@ -0,0 +1,4 @@ +// RUN: %dxc -E main -T rootsig_1_0 /Dmain="SRV(t0)" %s + +#define MyRS2 RootFlags(ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT), DescriptorTable( visibility=SHADER_VISIBILITY_PIXEL, SRV(t0, numDescriptors=16) ), DescriptorTable( visibility=SHADER_VISIBILITY_PIXEL, CBV(b0, numDescriptors=8) ), DescriptorTable( visibility=SHADER_VISIBILITY_PIXEL, Sampler(s0, numDescriptors=16) ), DescriptorTable( visibility=SHADER_VISIBILITY_VERTEX, SRV(t0, numDescriptors=16) ), DescriptorTable( visibility=SHADER_VISIBILITY_VERTEX, CBV(b0, numDescriptors=8) ), DescriptorTable( visibility=SHADER_VISIBILITY_VERTEX, Sampler(s0, numDescriptors=16) ), DescriptorTable( visibility=SHADER_VISIBILITY_GEOMETRY, SRV(t0, numDescriptors=16) ), DescriptorTable( visibility=SHADER_VISIBILITY_GEOMETRY, CBV(b0, numDescriptors=8) ), DescriptorTable( visibility=SHADER_VISIBILITY_GEOMETRY, Sampler(s0, numDescriptors=16) ), DescriptorTable( visibility=SHADER_VISIBILITY_HULL, SRV(t0, numDescriptors=16) ), DescriptorTable( visibility=SHADER_VISIBILITY_HULL, CBV(b0, numDescriptors=8) ), DescriptorTable( visibility=SHADER_VISIBILITY_HULL, Sampler(s0, numDescriptors=16) ), DescriptorTable( visibility=SHADER_VISIBILITY_DOMAIN, SRV(t0, numDescriptors=16) ), DescriptorTable( visibility=SHADER_VISIBILITY_DOMAIN, CBV(b0, numDescriptors=8) ), DescriptorTable( visibility=SHADER_VISIBILITY_DOMAIN, Sampler(s0, numDescriptors=16) ), DescriptorTable( visibility=SHADER_VISIBILITY_ALL, UAV(u0, numDescriptors=8) ) + diff --git a/tools/clang/test/CodeGenHLSL/rootSigProfile3.hlsl b/tools/clang/test/CodeGenHLSL/rootSigProfile3.hlsl new file mode 100644 index 000000000..d46ca6da6 --- /dev/null +++ b/tools/clang/test/CodeGenHLSL/rootSigProfile3.hlsl @@ -0,0 +1,6 @@ +// RUN: %dxc -E main -T rootsig_1_0 %s | FileCheck %s + +// CHECK: root signature error - undeclared identifier main + +#define MyRS2 RootFlags(ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT), DescriptorTable( visibility=SHADER_VISIBILITY_PIXEL, SRV(t0, numDescriptors=16) ), DescriptorTable( visibility=SHADER_VISIBILITY_PIXEL, CBV(b0, numDescriptors=8) ), DescriptorTable( visibility=SHADER_VISIBILITY_PIXEL, Sampler(s0, numDescriptors=16) ), DescriptorTable( visibility=SHADER_VISIBILITY_VERTEX, SRV(t0, numDescriptors=16) ), DescriptorTable( visibility=SHADER_VISIBILITY_VERTEX, CBV(b0, numDescriptors=8) ), DescriptorTable( visibility=SHADER_VISIBILITY_VERTEX, Sampler(s0, numDescriptors=16) ), DescriptorTable( visibility=SHADER_VISIBILITY_GEOMETRY, SRV(t0, numDescriptors=16) ), DescriptorTable( visibility=SHADER_VISIBILITY_GEOMETRY, CBV(b0, numDescriptors=8) ), DescriptorTable( visibility=SHADER_VISIBILITY_GEOMETRY, Sampler(s0, numDescriptors=16) ), DescriptorTable( visibility=SHADER_VISIBILITY_HULL, SRV(t0, numDescriptors=16) ), DescriptorTable( visibility=SHADER_VISIBILITY_HULL, CBV(b0, numDescriptors=8) ), DescriptorTable( visibility=SHADER_VISIBILITY_HULL, Sampler(s0, numDescriptors=16) ), DescriptorTable( visibility=SHADER_VISIBILITY_DOMAIN, SRV(t0, numDescriptors=16) ), DescriptorTable( visibility=SHADER_VISIBILITY_DOMAIN, CBV(b0, numDescriptors=8) ), DescriptorTable( visibility=SHADER_VISIBILITY_DOMAIN, Sampler(s0, numDescriptors=16) ), DescriptorTable( visibility=SHADER_VISIBILITY_ALL, UAV(u0, numDescriptors=8) ) + diff --git a/tools/clang/test/CodeGenHLSL/rootSigProfile4.hlsl b/tools/clang/test/CodeGenHLSL/rootSigProfile4.hlsl new file mode 100644 index 000000000..4b161ead0 --- /dev/null +++ b/tools/clang/test/CodeGenHLSL/rootSigProfile4.hlsl @@ -0,0 +1,6 @@ +// RUN: %dxc -E main -T rootsig_1_0 /Dmain="SSRV(t0)" %s | FileCheck %s + +// CHECK: root signature error - Unexpected token 'SSRV' when parsing root signature + +#define MyRS2 RootFlags(ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT), DescriptorTable( visibility=SHADER_VISIBILITY_PIXEL, SRV(t0, numDescriptors=16) ), DescriptorTable( visibility=SHADER_VISIBILITY_PIXEL, CBV(b0, numDescriptors=8) ), DescriptorTable( visibility=SHADER_VISIBILITY_PIXEL, Sampler(s0, numDescriptors=16) ), DescriptorTable( visibility=SHADER_VISIBILITY_VERTEX, SRV(t0, numDescriptors=16) ), DescriptorTable( visibility=SHADER_VISIBILITY_VERTEX, CBV(b0, numDescriptors=8) ), DescriptorTable( visibility=SHADER_VISIBILITY_VERTEX, Sampler(s0, numDescriptors=16) ), DescriptorTable( visibility=SHADER_VISIBILITY_GEOMETRY, SRV(t0, numDescriptors=16) ), DescriptorTable( visibility=SHADER_VISIBILITY_GEOMETRY, CBV(b0, numDescriptors=8) ), DescriptorTable( visibility=SHADER_VISIBILITY_GEOMETRY, Sampler(s0, numDescriptors=16) ), DescriptorTable( visibility=SHADER_VISIBILITY_HULL, SRV(t0, numDescriptors=16) ), DescriptorTable( visibility=SHADER_VISIBILITY_HULL, CBV(b0, numDescriptors=8) ), DescriptorTable( visibility=SHADER_VISIBILITY_HULL, Sampler(s0, numDescriptors=16) ), DescriptorTable( visibility=SHADER_VISIBILITY_DOMAIN, SRV(t0, numDescriptors=16) ), DescriptorTable( visibility=SHADER_VISIBILITY_DOMAIN, CBV(b0, numDescriptors=8) ), DescriptorTable( visibility=SHADER_VISIBILITY_DOMAIN, Sampler(s0, numDescriptors=16) ), DescriptorTable( visibility=SHADER_VISIBILITY_ALL, UAV(u0, numDescriptors=8) ) + diff --git a/tools/clang/tools/dxc/dxc.cpp b/tools/clang/tools/dxc/dxc.cpp index c02828358..e8097795b 100644 --- a/tools/clang/tools/dxc/dxc.cpp +++ b/tools/clang/tools/dxc/dxc.cpp @@ -186,8 +186,10 @@ int DxcContext::ActOnBlob(IDxcBlob *pBlob) { m_Opts.ExtractPrivateFile.empty() && m_Opts.VerifyRootSignatureSource.empty() && !m_Opts.ExtractRootSignature); - if (!needDisassembly) - return retVal; + bool isRootSigProfile = m_Opts.IsRootSignatureProfile(); + + if (!needDisassembly || isRootSigProfile) + return retVal; CComPtr pCompiler; IFT(m_dxcSupport.CreateInstance(CLSID_DxcCompiler, &pCompiler)); diff --git a/tools/clang/tools/dxcompiler/dxcompilerobj.cpp b/tools/clang/tools/dxcompiler/dxcompilerobj.cpp index 0a60ac7d4..8f992ff54 100644 --- a/tools/clang/tools/dxcompiler/dxcompilerobj.cpp +++ b/tools/clang/tools/dxcompiler/dxcompilerobj.cpp @@ -38,6 +38,7 @@ #include "dxc/Support/WinIncludes.h" // For DxilPipelineStateValidation.h #include "dxc/HLSL/DxilPipelineStateValidation.h" #include "dxc/HLSL/HLSLExtensionsCodegenHelper.h" +#include "dxc/HLSL/DxilRootSignature.h" #ifdef _DEBUG #if defined(_MSC_VER) @@ -2037,6 +2038,16 @@ public: compiler.getCodeGenOpts().HLSLEntryFunction = pUtf8EntryPoint.m_psz; compiler.getCodeGenOpts().HLSLProfile = pUtf8TargetProfile.m_psz; + unsigned rootSigMajor = 0; + unsigned rootSigMinor = 0; + if (compiler.getCodeGenOpts().HLSLProfile == "rootsig_1_1") { + rootSigMajor = 1; + rootSigMinor = 1; + } else if (compiler.getCodeGenOpts().HLSLProfile == "rootsig_1_0") { + rootSigMajor = 1; + rootSigMinor = 0; + } + // NOTE: this calls the validation component from dxil.dll; the built-in // validator can be used as a fallback. bool needsValidation = !opts.CodeGenHighLevel && !opts.DisableValidation; @@ -2081,6 +2092,29 @@ public: action.EndSourceFile(); outStream.flush(); } + else if (rootSigMajor) { + HLSLRootSignatureAction action( + compiler.getCodeGenOpts().HLSLEntryFunction, rootSigMajor, + rootSigMinor); + FrontendInputFile file(utf8SourceName.m_psz, IK_HLSL); + action.BeginSourceFile(compiler, file); + action.Execute(); + action.EndSourceFile(); + outStream.flush(); + // Don't do work to put in a container if an error has occurred + bool compileOK = !compiler.getDiagnostics().hasErrorOccurred(); + if (compileOK) { + auto rootSigHandle = action.takeRootSigHandle(); + + CComPtr pContainerStream; + IFT(CreateMemoryStream(pMalloc, &pContainerStream)); + SerializeDxilContainerForRootSignature(rootSigHandle.get(), + pContainerStream); + + pOutputBlob.Release(); + IFT(pContainerStream.QueryInterface(&pOutputBlob)); + } + } else { llvm::LLVMContext llvmContext; EmitBCAction action(&llvmContext); diff --git a/tools/clang/unittests/HLSL/CompilerTest.cpp b/tools/clang/unittests/HLSL/CompilerTest.cpp index fbc17a402..59cb24a5d 100644 --- a/tools/clang/unittests/HLSL/CompilerTest.cpp +++ b/tools/clang/unittests/HLSL/CompilerTest.cpp @@ -593,6 +593,10 @@ public: TEST_METHOD(CodeGenResPhi) TEST_METHOD(CodeGenResPhi2) TEST_METHOD(CodeGenRootSigEntry) + TEST_METHOD(CodeGenRootSigProfile) + TEST_METHOD(CodeGenRootSigProfile2) + TEST_METHOD(CodeGenRootSigProfile3) + TEST_METHOD(CodeGenRootSigProfile4) TEST_METHOD(CodeGenCBufferStructArray) TEST_METHOD(PreprocessWhenValidThenOK) TEST_METHOD(WhenSigMismatchPCFunctionThenFail) @@ -1040,9 +1044,9 @@ public: std::wstring profile = Unicode::UTF8ToUTF16StringOrThrow(opts.TargetProfile.str().c_str()); - VERIFY_SUCCEEDED(pCompiler->Compile(pSource, name, entry.c_str(), - profile.c_str(), nullptr, 0, nullptr, 0, - nullptr, &pResult)); + VERIFY_SUCCEEDED(pCompiler->Compile( + pSource, name, entry.c_str(), profile.c_str(), nullptr, 0, + opts.Defines.data(), opts.Defines.size(), nullptr, &pResult)); HRESULT result; VERIFY_SUCCEEDED(pResult->GetStatus(&result)); if (FAILED(result)) { @@ -1057,6 +1061,8 @@ public: CComPtr pProgram; VERIFY_SUCCEEDED(pResult->GetResult(&pProgram)); + if (opts.IsRootSignatureProfile()) + return; CComPtr pDisassembleBlob; VERIFY_SUCCEEDED(pCompiler->Disassemble(pProgram, &pDisassembleBlob)); @@ -3031,6 +3037,23 @@ TEST_F(CompilerTest, CodeGenRootSigEntry) { CodeGenTest(L"..\\CodeGenHLSL\\rootSigEntry.hlsl"); } +TEST_F(CompilerTest, CodeGenRootSigProfile) { + CodeGenTest(L"..\\CodeGenHLSL\\rootSigProfile.hlsl"); +} + +TEST_F(CompilerTest, CodeGenRootSigProfile2) { + // TODO: Verify the result when reflect the structures. + CodeGenTest(L"..\\CodeGenHLSL\\rootSigProfile2.hlsl"); +} + +TEST_F(CompilerTest, CodeGenRootSigProfile3) { + CodeGenTestCheck(L"..\\CodeGenHLSL\\rootSigProfile3.hlsl"); +} + +TEST_F(CompilerTest, CodeGenRootSigProfile4) { + CodeGenTestCheck(L"..\\CodeGenHLSL\\rootSigProfile4.hlsl"); +} + TEST_F(CompilerTest, CodeGenCBufferStructArray) { CodeGenTestCheck(L"..\\CodeGenHLSL\\cbuffer-structarray.hlsl"); }