Skip to content

Commit 2f4f6f6

Browse files
committed
Rewriter: improvements plus extract uniforms to global scope (#2730)
- Added rewriter functions for extracting uniforms into global scope - Will not work if name collides (namespaces have bugs) - Values under cbuffer _Params, resources outside (more bugs) - Added rewriter HLSLOptions and support all through RewriteWithOptions - Refactored dxr.exe to use HLSLOptions and RewriteWithOptions - Exposed Write*VersionInfo functions from dxclib - Fixed issue with External[Lib/Fn] for version printing.
1 parent a98faf6 commit 2f4f6f6

16 files changed

Lines changed: 514 additions & 321 deletions

File tree

include/dxc/Support/HLSLOptions.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ enum HlslFlags {
4141
NoArgumentUnused = (1 << 14),
4242
CoreOption = (1 << 15),
4343
ISenseOption = (1 << 16),
44+
RewriteOption = (1 << 17),
4445
};
4546

4647
enum ID {
@@ -64,7 +65,7 @@ static const unsigned CompilerFlags = HlslFlags::CoreOption;
6465
/// Flags for dxc.exe command-line tool.
6566
static const unsigned DxcFlags = HlslFlags::CoreOption | HlslFlags::DriverOption;
6667
/// Flags for dxr.exe command-line tool.
67-
static const unsigned DxrFlags = HlslFlags::CoreOption | HlslFlags::DriverOption;
68+
static const unsigned DxrFlags = HlslFlags::RewriteOption | HlslFlags::DriverOption;
6869
/// Flags for IDxcIntelliSense APIs.
6970
static const unsigned ISenseFlags = HlslFlags::CoreOption | HlslFlags::ISenseOption;
7071

@@ -85,6 +86,16 @@ class DxcDefines {
8586
unsigned size() const { return DefineVector.size(); }
8687
};
8788

89+
struct RewriterOpts {
90+
bool Unchanged = false; // OPT_rw_unchanged
91+
bool SkipFunctionBody = false; // OPT_rw_skip_function_body
92+
bool SkipStatic = false; // OPT_rw_skip_static
93+
bool GlobalExternByDefault = false; // OPT_rw_global_extern_by_default
94+
bool KeepUserMacro = false; // OPT_rw_keep_user_macro
95+
bool ExtractEntryUniforms = false; // OPT_rw_extract_entry_uniforms
96+
bool RemoveUnusedGlobals = false; // OPT_rw_remove_unused_globals
97+
};
98+
8899
/// Use this class to capture all options.
89100
class DxcOpts {
90101
public:
@@ -174,6 +185,9 @@ class DxcOpts {
174185
unsigned long ValVerMajor = UINT_MAX, ValVerMinor = UINT_MAX; // OPT_validator_version
175186
unsigned ScanLimit = 0; // OPT_memdep_block_scan_limit
176187

188+
// Rewriter Options
189+
RewriterOpts RWOpt;
190+
177191
std::vector<std::string> Warnings;
178192

179193
bool IsRootSignatureProfile();

include/dxc/Support/HLSLOptions.td

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ def CoreOption : OptionFlag;
2626
// ISenseOption - This option is only supported for IntelliSense.
2727
def ISenseOption : OptionFlag;
2828

29+
// RewriteOption - This is considered a "rewriter" HLSL option.
30+
def RewriteOption : OptionFlag;
31+
2932
//////////////////////////////////////////////////////////////////////////////
3033
// Groups
3134

@@ -66,6 +69,7 @@ def hlslcomp_Group : OptionGroup<"HLSL Compilation">, HelpText<"Compilation Opti
6669
def hlsloptz_Group : OptionGroup<"HLSL Optimization">, HelpText<"Optimization Options">;
6770
def hlslutil_Group : OptionGroup<"HLSL Utility">, HelpText<"Utility Options">;
6871
def hlslcore_Group : OptionGroup<"HLSL Core">, HelpText<"Common Options">;
72+
def hlslrewrite_Group : OptionGroup<"HLSL Rewriter">, HelpText<"Rewriter Options">;
6973

7074
def spirv_Group : OptionGroup<"SPIR-V CodeGen">, HelpText<"SPIR-V CodeGen Options">; // SPIRV Change
7175

@@ -82,11 +86,11 @@ def spirv_Group : OptionGroup<"SPIR-V CodeGen">, HelpText<"SPIR-V CodeGen Option
8286
// The general approach is to include only things that are in use, in the
8387
// same order as in Options.td.
8488

85-
def D : JoinedOrSeparate<["-", "/"], "D">, Group<hlslcomp_Group>, Flags<[CoreOption]>,
89+
def D : JoinedOrSeparate<["-", "/"], "D">, Group<hlslcomp_Group>, Flags<[CoreOption, RewriteOption]>,
8690
HelpText<"Define macro">;
8791
def H : Flag<["-"], "H">, Flags<[CoreOption]>, Group<hlslcomp_Group>,
8892
HelpText<"Show header includes and nesting depth">;
89-
def I : JoinedOrSeparate<["-", "/"], "I">, Group<hlslcomp_Group>, Flags<[CoreOption]>,
93+
def I : JoinedOrSeparate<["-", "/"], "I">, Group<hlslcomp_Group>, Flags<[CoreOption, RewriteOption]>,
9094
HelpText<"Add directory to include search path">;
9195
def O0 : Flag<["-", "/"], "O0">, Group<hlsloptz_Group>, Flags<[CoreOption]>,
9296
HelpText<"Optimization Level 0">;
@@ -212,13 +216,13 @@ def _help_question : Flag<["-", "/"], "?">, Flags<[DriverOption]>, Alias<help>;
212216

213217
def ast_dump : Flag<["-", "/"], "ast-dump">, Flags<[CoreOption, DriverOption, HelpHidden]>,
214218
HelpText<"Dumps the parsed Abstract Syntax Tree.">; // should not be core, but handy workaround until explicit API written
215-
def external_lib : Separate<["-", "/"], "external">, Group<hlslcore_Group>, Flags<[DriverOption, HelpHidden]>,
219+
def external_lib : Separate<["-", "/"], "external">, Group<hlslcore_Group>, Flags<[DriverOption, RewriteOption, HelpHidden]>,
216220
HelpText<"External DLL name to load for compiler support">;
217-
def external_fn : Separate<["-", "/"], "external-fn">, Group<hlslcore_Group>, Flags<[DriverOption, HelpHidden]>,
221+
def external_fn : Separate<["-", "/"], "external-fn">, Group<hlslcore_Group>, Flags<[DriverOption, RewriteOption, HelpHidden]>,
218222
HelpText<"External function name to load for compiler support">;
219223
def fcgl : Flag<["-", "/"], "fcgl">, Group<hlslcore_Group>, Flags<[CoreOption, HelpHidden]>,
220224
HelpText<"Generate high-level code only">;
221-
def flegacy_macro_expansion : Flag<["-", "/"], "flegacy-macro-expansion">, Group<hlslcomp_Group>, Flags<[CoreOption, DriverOption]>,
225+
def flegacy_macro_expansion : Flag<["-", "/"], "flegacy-macro-expansion">, Group<hlslcomp_Group>, Flags<[CoreOption, RewriteOption, DriverOption]>,
222226
HelpText<"Expand the operands before performing token-pasting operation (fxc behavior)">;
223227
def flegacy_resource_reservation : Flag<["-", "/"], "flegacy-resource-reservation">, Group<hlslcomp_Group>, Flags<[CoreOption, DriverOption]>,
224228
HelpText<"Reserve unused explicit register assignments for compatibility with shader model 5.0 and below">;
@@ -234,13 +238,13 @@ def pack_optimized : Flag<["-", "/"], "pack-optimized">, Group<hlslcomp_Group>,
234238
HelpText<"Optimize signature packing assuming identical signature provided for each connecting stage">;
235239
def pack_optimized_ : Flag<["-", "/"], "pack_optimized">, Group<hlslcomp_Group>, Flags<[CoreOption, HelpHidden]>,
236240
HelpText<"Optimize signature packing assuming identical signature provided for each connecting stage">;
237-
def hlsl_version : Separate<["-", "/"], "HV">, Group<hlslcomp_Group>, Flags<[CoreOption]>,
241+
def hlsl_version : Separate<["-", "/"], "HV">, Group<hlslcomp_Group>, Flags<[CoreOption, RewriteOption]>,
238242
HelpText<"HLSL version (2016, 2017, 2018). Default is 2018">;
239-
def no_warnings : Flag<["-", "/"], "no-warnings">, Group<hlslcomp_Group>, Flags<[CoreOption]>,
243+
def no_warnings : Flag<["-", "/"], "no-warnings">, Group<hlslcomp_Group>, Flags<[CoreOption, RewriteOption]>,
240244
HelpText<"Suppress warnings">;
241245
def rootsig_define : Separate<["-", "/"], "rootsig-define">, Group<hlslcomp_Group>, Flags<[CoreOption]>,
242246
HelpText<"Read root signature from a #define">;
243-
def enable_16bit_types: Flag<["-", "/"], "enable-16bit-types">, Flags<[CoreOption, DriverOption]>, Group<hlslcomp_Group>,
247+
def enable_16bit_types: Flag<["-", "/"], "enable-16bit-types">, Flags<[CoreOption, RewriteOption, DriverOption]>, Group<hlslcomp_Group>,
244248
HelpText<"Enable 16bit types and disable min precision types. Available in HLSL 2018 and shader model 6.2">;
245249
def ignore_line_directives : Flag<["-", "/"], "ignore-line-directives">, HelpText<"Ignore line directives">, Flags<[CoreOption]>, Group<hlslcomp_Group>;
246250
def auto_binding_space : Separate<["-", "/"], "auto-binding-space">, Group<hlslcomp_Group>, Flags<[CoreOption]>,
@@ -251,7 +255,7 @@ def export_shaders_only : Flag<["-", "/"], "export-shaders-only">, Group<hlslcom
251255
HelpText<"Only export shaders when compiling a library">;
252256
def default_linkage : Separate<["-", "/"], "default-linkage">, Group<hlslcomp_Group>, Flags<[CoreOption]>,
253257
HelpText<"Set default linkage for non-shader functions when compiling or linking to a library target (internal, external)">;
254-
def encoding : Separate<["-", "/"], "encoding">, Group<hlslcomp_Group>, Flags<[CoreOption, DriverOption]>,
258+
def encoding : Separate<["-", "/"], "encoding">, Group<hlslcomp_Group>, Flags<[CoreOption, RewriteOption, DriverOption]>,
255259
HelpText<"Set default encoding for text outputs (utf8|utf16) default=utf8">;
256260
def validator_version : Separate<["-", "/"], "validator-version">, Group<hlslcomp_Group>, Flags<[CoreOption, HelpHidden]>,
257261
HelpText<"Override validator version for module. Format: <major.minor> ; Default: DXIL.dll version or current internal version.">;
@@ -314,7 +318,7 @@ def target_profile : JoinedOrSeparate<["-", "/"], "T">, Flags<[CoreOption]>, Gro
314318
// VALRULE-TEXT:BEGIN
315319
HelpText<"Set target profile. \n\t<profile>: ps_6_0, ps_6_1, ps_6_2, ps_6_3, ps_6_4, ps_6_5, \n\t\t vs_6_0, vs_6_1, vs_6_2, vs_6_3, vs_6_4, vs_6_5, \n\t\t gs_6_0, gs_6_1, gs_6_2, gs_6_3, gs_6_4, gs_6_5, \n\t\t hs_6_0, hs_6_1, hs_6_2, hs_6_3, hs_6_4, hs_6_5, \n\t\t ds_6_0, ds_6_1, ds_6_2, ds_6_3, ds_6_4, ds_6_5, \n\t\t cs_6_0, cs_6_1, cs_6_2, cs_6_3, cs_6_4, cs_6_5, \n\t\t lib_6_1, lib_6_2, lib_6_3, lib_6_4, lib_6_5, \n\t\t ms_6_5, \n\t\t as_6_5, \n\t\t ">;
316320
// VALRULE-TEXT:END
317-
def entrypoint : JoinedOrSeparate<["-", "/"], "E">, Flags<[CoreOption]>, Group<hlslcomp_Group>,
321+
def entrypoint : JoinedOrSeparate<["-", "/"], "E">, Flags<[CoreOption, RewriteOption]>, Group<hlslcomp_Group>,
318322
HelpText<"Entry point name">;
319323
// /I <include> - already defined above
320324
def _vi : Flag<["-", "/"], "Vi">, Alias<H>, Flags<[CoreOption]>, Group<hlslcomp_Group>,
@@ -348,7 +352,7 @@ def Gis : Flag<["-", "/"], "Gis">, HelpText<"Force IEEE strictness">, Flags<[Cor
348352

349353
def denorm : JoinedOrSeparate<["-", "/"], "denorm">, HelpText<"select denormal value options (any, preserve, ftz). any is the default.">, Flags<[CoreOption]>, Group<hlslcomp_Group>;
350354

351-
def Fo : JoinedOrSeparate<["-", "/"], "Fo">, MetaVarName<"<file>">, HelpText<"Output object file">, Flags<[CoreOption, DriverOption]>, Group<hlslcomp_Group>;
355+
def Fo : JoinedOrSeparate<["-", "/"], "Fo">, MetaVarName<"<file>">, HelpText<"Output object file">, Flags<[CoreOption, RewriteOption, DriverOption]>, Group<hlslcomp_Group>;
352356
// def Fl : JoinedOrSeparate<["-", "/"], "Fl">, MetaVarName<"<file>">, HelpText<"Output a library">;
353357
def Fc : JoinedOrSeparate<["-", "/"], "Fc">, MetaVarName<"<file>">, HelpText<"Output assembly code listing file">, Flags<[DriverOption]>, Group<hlslcomp_Group>;
354358
//def Fx : JoinedOrSeparate<["-", "/"], "Fx">, MetaVarName<"<file>">, HelpText<"Output assembly code and hex listing file">;
@@ -426,5 +430,23 @@ def getprivate : JoinedOrSeparate<["-", "/"], "getprivate">, Flags<[DriverOption
426430
def nologo : Flag<["-", "/"], "nologo">, Group<hlslcore_Group>, Flags<[DriverOption]>,
427431
HelpText<"Suppress copyright message">;
428432

433+
//////////////////////////////////////////////////////////////////////////////
434+
// Rewriter Options
435+
436+
def rw_unchanged : Flag<["-", "/"], "unchanged">, Group<hlslrewrite_Group>, Flags<[RewriteOption]>,
437+
HelpText<"Rewrite HLSL, without changes.">;
438+
def rw_skip_function_body : Flag<["-", "/"], "skip-fn-body">, Group<hlslrewrite_Group>, Flags<[RewriteOption]>,
439+
HelpText<"Translate function definitions to declarations">;
440+
def rw_skip_static : Flag<["-", "/"], "skip-static">, Group<hlslrewrite_Group>, Flags<[RewriteOption]>,
441+
HelpText<"Remove static functions and globals when used with -skip-fn-body">;
442+
def rw_global_extern_by_default : Flag<["-", "/"], "global-extern-by-default">, Group<hlslrewrite_Group>, Flags<[RewriteOption]>,
443+
HelpText<"Set extern on non-static globals">;
444+
def rw_keep_user_macro : Flag<["-", "/"], "keep-user-macro">, Group<hlslrewrite_Group>, Flags<[RewriteOption]>,
445+
HelpText<"Write out user defines after rewritten HLSL">;
446+
def rw_extract_entry_uniforms : Flag<["-", "/"], "extract-entry-uniforms">, Group<hlslrewrite_Group>, Flags<[RewriteOption]>,
447+
HelpText<"Move uniform parameters from entry point to global scope">;
448+
def rw_remove_unused_globals : Flag<["-", "/"], "remove-unused-globals">, Group<hlslrewrite_Group>, Flags<[RewriteOption]>,
449+
HelpText<"Remove unused static globals and functions">;
450+
429451
// Also removed: compress, decompress, /Gch (child effect), /Gpp (partial precision)
430452
// /Op - no support for preshaders.

include/llvm/Option/OptTable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class OptTable {
4242
unsigned ID;
4343
unsigned char Kind;
4444
unsigned char Param;
45-
unsigned short Flags;
45+
unsigned long Flags;
4646
unsigned short GroupID;
4747
unsigned short AliasID;
4848
const char *AliasArgs;

lib/DxcSupport/HLSLOptions.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,9 @@ int ReadDxcOpts(const OptTable *optionTable, unsigned flagsToInclude,
680680

681681
// XXX TODO: Sort this out, since it's required for new API, but a separate argument for old APIs.
682682
if ((flagsToInclude & hlsl::options::DriverOption) &&
683-
opts.TargetProfile.empty() && !opts.DumpBin && opts.Preprocess.empty() && !opts.RecompileFromBinary) {
683+
!(flagsToInclude & hlsl::options::RewriteOption) &&
684+
opts.TargetProfile.empty() && !opts.DumpBin && opts.Preprocess.empty() && !opts.RecompileFromBinary
685+
) {
684686
// Target profile is required in arguments only for drivers when compiling;
685687
// APIs take this through an argument.
686688
errors << "Target profile argument is missing";
@@ -880,6 +882,23 @@ int ReadDxcOpts(const OptTable *optionTable, unsigned flagsToInclude,
880882
return 1;
881883
}
882884

885+
// Rewriter Options
886+
if (flagsToInclude & hlsl::options::RewriteOption) {
887+
opts.RWOpt.Unchanged = Args.hasFlag(OPT_rw_unchanged, OPT_INVALID, false);
888+
opts.RWOpt.SkipFunctionBody = Args.hasFlag(OPT_rw_skip_function_body, OPT_INVALID, false);
889+
opts.RWOpt.SkipStatic = Args.hasFlag(OPT_rw_skip_static, OPT_INVALID, false);
890+
opts.RWOpt.GlobalExternByDefault = Args.hasFlag(OPT_rw_global_extern_by_default, OPT_INVALID, false);
891+
opts.RWOpt.KeepUserMacro = Args.hasFlag(OPT_rw_keep_user_macro, OPT_INVALID, false);
892+
opts.RWOpt.ExtractEntryUniforms = Args.hasFlag(OPT_rw_extract_entry_uniforms, OPT_INVALID, false);
893+
opts.RWOpt.RemoveUnusedGlobals = Args.hasFlag(OPT_rw_remove_unused_globals, OPT_INVALID, false);
894+
895+
if (opts.EntryPoint.empty() &&
896+
(opts.RWOpt.RemoveUnusedGlobals || opts.RWOpt.ExtractEntryUniforms)) {
897+
errors << "-rw-remove-unused-globals and -rw-extract-entry-uniforms requires entry point (-E) to be specified.";
898+
return 1;
899+
}
900+
}
901+
883902
opts.Args = std::move(Args);
884903
return 0;
885904
}

tools/clang/include/clang/AST/PrettyPrinter.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ struct PrintingPolicy {
4343
Bool(LO.Bool), TerseOutput(false), PolishForDeclaration(false),
4444
Half(LO.HLSL || LO.Half), // HLSL Change - always print 'half' for HLSL
4545
MSWChar(LO.MicrosoftExt && !LO.WChar),
46-
IncludeNewlines(true) { }
46+
IncludeNewlines(true),
47+
HLSLSuppressUniformParameters(false) { }
4748

4849
/// \brief What language we're printing.
4950
LangOptions LangOpts;
@@ -164,6 +165,11 @@ struct PrintingPolicy {
164165

165166
/// \brief When true, include newlines after statements like "break", etc.
166167
unsigned IncludeNewlines : 1;
168+
169+
// HLSL Change Begin
170+
/// \brief When true, exclude uniform function parameters
171+
unsigned HLSLSuppressUniformParameters : 1;
172+
// HLSL Change Ends
167173
};
168174

169175
} // end namespace clang

tools/clang/lib/AST/DeclPrinter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,10 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) {
510510
llvm::raw_string_ostream POut(Proto);
511511
DeclPrinter ParamPrinter(POut, SubPolicy, Indentation);
512512
for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
513+
if (Policy.HLSLSuppressUniformParameters &&
514+
Policy.LangOpts.HLSL &&
515+
D->getParamDecl(i)->hasAttr<HLSLUniformAttr>()) // HLSL Change
516+
continue;
513517
if (i) POut << ", ";
514518
ParamPrinter.VisitParmVarDecl(D->getParamDecl(i));
515519
}

tools/clang/lib/Sema/SemaHLSL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12405,7 +12405,7 @@ void hlsl::CustomPrintHLSLAttr(const clang::Attr *A, llvm::raw_ostream &Out, con
1240512405
Attr * noconst = const_cast<Attr*>(A);
1240612406
HLSLRootSignatureAttr *ACast = static_cast<HLSLRootSignatureAttr*>(noconst);
1240712407
Indent(Indentation, Out);
12408-
Out << "[RootSignature(" << ACast->getSignatureName() << ")]\n";
12408+
Out << "[RootSignature(\"" << ACast->getSignatureName() << "\")]\n";
1240912409
break;
1241012410
}
1241112411

tools/clang/test/HLSL/rewriter/correct_rewrites/array-length-rw_gold.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Rewrite unchanged result:
22
const float4 planes[8];
3-
[RootSignature(CBV(b0, space=0, visibility=SHADER_VISIBILITY_ALL))]
3+
[RootSignature("CBV(b0, space=0, visibility=SHADER_VISIBILITY_ALL)")]
44
float main() {
55
float4 x = float4(1., 1., 1., 1.);
66
for (uint i = 0; i < planes.Length; ++i) {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#define RS "RootFlags(0),DescriptorTable(UAV(u0, numDescriptors = 1), CBV(b0, numDescriptors = 1))"
2+
3+
[RootSignature(RS)]
4+
[numthreads(4,8,16)]
5+
void FloatFunc(uint3 id : SV_DispatchThreadID, uniform RWStructuredBuffer<float> buf, uniform uint ui)
6+
{
7+
buf[id.x+id.y+id.z] = id.x;
8+
}
9+
10+
[RootSignature(RS)]
11+
[numthreads(4,8,16)]
12+
void IntFunc(uint3 id : SV_DispatchThreadID, uniform RWStructuredBuffer<int> buf, uniform uint ui)
13+
{
14+
buf[id.x+id.y+id.z] = id.x + ui;
15+
}

tools/clang/tools/dxclib/dxc.cpp

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,9 +1070,14 @@ bool GetDLLProductVersionInfo(const char *dllPath, std::string &productVersion)
10701070
return false;
10711071
}
10721072

1073-
// Collects compiler/validator version info
1074-
void DxcContext::GetCompilerVersionInfo(llvm::raw_string_ostream &OS) {
1075-
if (m_dxcSupport.IsEnabled()) {
1073+
namespace dxc {
1074+
1075+
// Writes compiler version info to stream
1076+
void WriteDxCompilerVersionInfo(llvm::raw_ostream &OS,
1077+
const char *ExternalLib,
1078+
const char *ExternalFn,
1079+
DxcDllSupport &DxcSupport) {
1080+
if (DxcSupport.IsEnabled()) {
10761081
UINT32 compilerMajor = 1;
10771082
UINT32 compilerMinor = 0;
10781083
CComPtr<IDxcVersionInfo> VerInfo;
@@ -1083,10 +1088,12 @@ void DxcContext::GetCompilerVersionInfo(llvm::raw_string_ostream &OS) {
10831088
CComPtr<IDxcVersionInfo2> VerInfo2;
10841089
#endif // SUPPORT_QUERY_GIT_COMMIT_INFO
10851090

1086-
const char *compilerName =
1087-
m_Opts.ExternalFn.empty() ? "dxcompiler.dll" : m_Opts.ExternalFn.data();
1091+
const char *dllName = !ExternalLib ? "dxcompiler.dll" : ExternalLib;
1092+
std::string compilerName(dllName);
1093+
if (ExternalFn)
1094+
compilerName = compilerName + "!" + ExternalFn;
10881095

1089-
if (SUCCEEDED(CreateInstance(CLSID_DxcCompiler, &VerInfo))) {
1096+
if (SUCCEEDED(DxcSupport.CreateInstance(CLSID_DxcCompiler, &VerInfo))) {
10901097
VerInfo->GetVersion(&compilerMajor, &compilerMinor);
10911098
#ifdef SUPPORT_QUERY_GIT_COMMIT_INFO
10921099
if (SUCCEEDED(VerInfo->QueryInterface(&VerInfo2)))
@@ -1095,13 +1102,16 @@ void DxcContext::GetCompilerVersionInfo(llvm::raw_string_ostream &OS) {
10951102
OS << compilerName << ": " << compilerMajor << "." << compilerMinor;
10961103
}
10971104
// compiler.dll 1.0 did not support IdxcVersionInfo
1098-
else if (m_Opts.ExternalFn.empty()) {
1105+
else if (!ExternalLib) {
10991106
OS << compilerName << ": " << 1 << "." << 0;
1107+
} else {
1108+
// ExternalLib/ExternalFn, no version info:
1109+
OS << compilerName;
11001110
}
11011111

11021112
#ifdef _WIN32
11031113
unsigned int version[4];
1104-
if (GetDLLFileVersionInfo(compilerName, version)) {
1114+
if (GetDLLFileVersionInfo(dllName, version)) {
11051115
// back-compat - old dev buidls had version 3.7.0.0
11061116
if (version[0] == 3 && version[1] == 7 && version[2] == 0 && version[3] == 0) {
11071117
#endif
@@ -1115,17 +1125,18 @@ void DxcContext::GetCompilerVersionInfo(llvm::raw_string_ostream &OS) {
11151125
}
11161126
else {
11171127
std::string productVersion;
1118-
if (GetDLLProductVersionInfo(compilerName, productVersion)) {
1128+
if (GetDLLProductVersionInfo(dllName, productVersion)) {
11191129
OS << " - " << productVersion;
11201130
}
11211131
}
11221132
}
11231133
#endif
11241134
}
1135+
}
11251136

1126-
// Print validator if exists
1127-
DxcDllSupport DxilSupport;
1128-
DxilSupport.InitializeForDll(L"dxil.dll", "DxcCreateInstance");
1137+
// Writes compiler version info to stream
1138+
void WriteDXILVersionInfo(llvm::raw_ostream &OS,
1139+
DxcDllSupport &DxilSupport) {
11291140
if (DxilSupport.IsEnabled()) {
11301141
CComPtr<IDxcVersionInfo> VerInfo;
11311142
if (SUCCEEDED(DxilSupport.CreateInstance(CLSID_DxcValidator, &VerInfo))) {
@@ -1149,6 +1160,21 @@ void DxcContext::GetCompilerVersionInfo(llvm::raw_string_ostream &OS) {
11491160
}
11501161
}
11511162

1163+
} // namespace dxc
1164+
1165+
// Collects compiler/validator version info
1166+
void DxcContext::GetCompilerVersionInfo(llvm::raw_string_ostream &OS) {
1167+
WriteDxCompilerVersionInfo(OS,
1168+
m_Opts.ExternalLib.empty() ? nullptr : m_Opts.ExternalLib.data(),
1169+
m_Opts.ExternalFn.empty() ? nullptr : m_Opts.ExternalFn.data(),
1170+
m_dxcSupport);
1171+
1172+
// Print validator if exists
1173+
DxcDllSupport DxilSupport;
1174+
DxilSupport.InitializeForDll(L"dxil.dll", "DxcCreateInstance");
1175+
WriteDXILVersionInfo(OS, DxilSupport);
1176+
}
1177+
11521178
#ifndef VERSION_STRING_SUFFIX
11531179
#define VERSION_STRING_SUFFIX ""
11541180
#endif

0 commit comments

Comments
 (0)