@@ -4669,7 +4669,7 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
46694669 Actions.push_back (C.MakeAction <BinaryAnalyzeJobAction>(
46704670 LastAction, types::TY_DX_CONTAINER));
46714671 }
4672- if (Args. getLastArg (options::OPT_metal )) {
4672+ if (TC. requiresBinaryTranslation (Args )) {
46734673 Action *LastAction = Actions.back ();
46744674 // Metal shader converter runs on DXIL containers, which can either be
46754675 // validated (in which case they are TY_DX_CONTAINER), or unvalidated
@@ -5219,8 +5219,14 @@ void Driver::BuildJobs(Compilation &C) const {
52195219 unsigned NumOutputs = 0 ;
52205220 unsigned NumIfsOutputs = 0 ;
52215221 for (const Action *A : C.getActions ()) {
5222+ // The actions below do not increase the number of outputs, when operating
5223+ // on DX containers.
5224+ if (A->getType () == types::TY_DX_CONTAINER &&
5225+ (A->getKind () == clang::driver::Action::BinaryAnalyzeJobClass ||
5226+ A->getKind () == clang::driver::Action::BinaryTranslatorJobClass))
5227+ continue ;
5228+
52225229 if (A->getType () != types::TY_Nothing &&
5223- A->getType () != types::TY_DX_CONTAINER &&
52245230 !(A->getKind () == Action::IfsMergeJobClass ||
52255231 (A->getType () == clang::driver::types::TY_IFS_CPP &&
52265232 A->getKind () == clang::driver::Action::CompileJobClass &&
@@ -6221,11 +6227,27 @@ const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA,
62216227 return C.addResultFile (C.getArgs ().MakeArgString (FcValue.str ()), &JA);
62226228 }
62236229
6224- if (JA.getType () == types::TY_Object &&
6225- C.getArgs ().hasArg (options::OPT_dxc_Fo)) {
6230+ if ((JA.getType () == types::TY_Object &&
6231+ C.getArgs ().hasArg (options::OPT_dxc_Fo)) ||
6232+ JA.getType () == types::TY_DX_CONTAINER) {
62266233 StringRef FoValue = C.getArgs ().getLastArgValue (options::OPT_dxc_Fo);
6227- // TODO: Should we use `MakeCLOutputFilename` here? If so, we can probably
6228- // handle this as part of the SLASH_Fo handling below.
6234+ // If we are targeting DXIL and not validating or translating, we should set
6235+ // the final result file. Otherwise we should emit to a temporary.
6236+ if (C.getDefaultToolChain ().getTriple ().isDXIL ()) {
6237+ const auto &TC = static_cast <const toolchains::HLSLToolChain &>(
6238+ C.getDefaultToolChain ());
6239+ // Fo can be empty here if the validator is running for a compiler flow
6240+ // that is using Fc or just printing disassembly.
6241+ if (TC.isLastJob (C.getArgs (), JA.getKind ()) && !FoValue.empty ())
6242+ return C.addResultFile (C.getArgs ().MakeArgString (FoValue.str ()), &JA);
6243+ StringRef Name = llvm::sys::path::filename (BaseInput);
6244+ std::pair<StringRef, StringRef> Split = Name.split (' .' );
6245+ const char *Suffix = types::getTypeTempSuffix (JA.getType (), true );
6246+ return CreateTempFile (C, Split.first , Suffix, false );
6247+ }
6248+ // We don't have SPIRV-val integrated (yet), so for now we can assume this
6249+ // is the final output.
6250+ assert (C.getDefaultToolChain ().getTriple ().isSPIRV ());
62296251 return C.addResultFile (C.getArgs ().MakeArgString (FoValue.str ()), &JA);
62306252 }
62316253
0 commit comments