-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[HLSL][DirectX] Add the Qdx-rootsignature-strip driver option #154454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
0f11eb0
acfd4d5
f3f3a07
f8ff016
154c2b0
a0ff7f7
2b6f936
ba36461
7dd6205
514063b
2945de4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4647,6 +4647,16 @@ void Driver::BuildDefaultActions(Compilation &C, DerivedArgList &Args, | |
// Only add action when needValidation. | ||
|
||
const auto &TC = | ||
static_cast<const toolchains::HLSLToolChain &>(C.getDefaultToolChain()); | ||
if (TC.requiresObjcopy(Args)) { | ||
Action *LastAction = Actions.back(); | ||
// llvm-objcopy expects a DXIL container, which can either be | ||
// validated (in which case they are TY_DX_CONTAINER), or unvalidated | ||
// (TY_OBJECT). | ||
inbelic marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
if (LastAction->getType() == types::TY_DX_CONTAINER || | ||
|
||
LastAction->getType() == types::TY_Object) | ||
Actions.push_back( | ||
C.MakeAction<ObjcopyJobAction>(LastAction, types::TY_DX_CONTAINER)); | ||
} | ||
if (TC.requiresValidation(Args)) { | ||
Action *LastAction = Actions.back(); | ||
Actions.push_back(C.MakeAction<BinaryAnalyzeJobAction>( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -295,6 +295,32 @@ void tools::hlsl::MetalConverter::ConstructJob( | |
Exec, CmdArgs, Inputs, Input)); | ||
} | ||
|
||
void tools::LLVMObjcopy::ConstructJob(Compilation &C, const JobAction &JA, | ||
const InputInfo &Output, | ||
const InputInfoList &Inputs, | ||
const ArgList &Args, | ||
const char *LinkingOutput) const { | ||
|
||
std::string ObjcopyPath = getToolChain().GetProgramPath("llvm-objcopy"); | ||
inbelic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const char *Exec = Args.MakeArgString(ObjcopyPath); | ||
|
||
ArgStringList CmdArgs; | ||
assert(Inputs.size() == 1 && "Unable to handle multiple inputs."); | ||
const InputInfo &Input = Inputs[0]; | ||
CmdArgs.push_back(Input.getFilename()); | ||
CmdArgs.push_back(Output.getFilename()); | ||
|
||
if (Args.hasArg(options::OPT_dxc_strip_rootsignature)) { | ||
const char *Frs = Args.MakeArgString("--remove-section=RTS0"); | ||
CmdArgs.push_back(Frs); | ||
} | ||
|
||
inbelic marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
assert(CmdArgs.size() > 2 && "Unnecessary invocation of objcopy."); | ||
|
||
C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(), | ||
Exec, CmdArgs, Inputs, Input)); | ||
} | ||
|
||
/// DirectX Toolchain | ||
HLSLToolChain::HLSLToolChain(const Driver &D, const llvm::Triple &Triple, | ||
const ArgList &Args) | ||
|
@@ -315,6 +341,10 @@ Tool *clang::driver::toolchains::HLSLToolChain::getTool( | |
if (!MetalConverter) | ||
MetalConverter.reset(new tools::hlsl::MetalConverter(*this)); | ||
return MetalConverter.get(); | ||
case Action::ObjcopyJobClass: | ||
if (!LLVMObjcopy) | ||
LLVMObjcopy.reset(new tools::LLVMObjcopy(*this)); | ||
return LLVMObjcopy.get(); | ||
default: | ||
return ToolChain::getTool(AC); | ||
} | ||
|
@@ -452,16 +482,25 @@ bool HLSLToolChain::requiresBinaryTranslation(DerivedArgList &Args) const { | |
return Args.hasArg(options::OPT_metal) && Args.hasArg(options::OPT_dxc_Fo); | ||
} | ||
|
||
bool HLSLToolChain::requiresObjcopy(DerivedArgList &Args) const { | ||
return Args.hasArg(options::OPT_dxc_Fo) && | ||
Args.hasArg(options::OPT_dxc_strip_rootsignature); | ||
} | ||
|
||
bool HLSLToolChain::isLastJob(DerivedArgList &Args, | ||
Action::ActionClass AC) const { | ||
bool HasTranslation = requiresBinaryTranslation(Args); | ||
bool HasValidation = requiresValidation(Args); | ||
bool HasObjcopy = requiresObjcopy(Args); | ||
// If translation and validation are not required, we should only have one | ||
// action. | ||
if (!HasTranslation && !HasValidation) | ||
if (!HasTranslation && !HasValidation && !HasObjcopy) | ||
return true; | ||
if ((HasTranslation && AC == Action::BinaryTranslatorJobClass) || | ||
(!HasTranslation && HasValidation && AC == Action::BinaryAnalyzeJobClass)) | ||
(!HasTranslation && HasValidation && | ||
AC == Action::BinaryAnalyzeJobClass) || | ||
(!HasTranslation && !HasValidation && HasObjcopy && | ||
AC == Action::ObjcopyJobClass)) | ||
return true; | ||
return false; | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,21 @@ class LLVM_LIBRARY_VISIBILITY MetalConverter : public Tool { | |
const llvm::opt::ArgList &TCArgs, | ||
const char *LinkingOutput) const override; | ||
}; | ||
|
||
} // namespace hlsl | ||
|
||
class LLVM_LIBRARY_VISIBILITY LLVMObjcopy : public Tool { | ||
public: | ||
LLVMObjcopy(const ToolChain &TC) : Tool("LLVMObjcopy", "llvm-objcopy", TC) {} | ||
|
||
bool hasIntegratedCPP() const override { return false; } | ||
|
||
void ConstructJob(Compilation &C, const JobAction &JA, | ||
const InputInfo &Output, const InputInfoList &Inputs, | ||
const llvm::opt::ArgList &TCArgs, | ||
const char *LinkingOutput) const override; | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While it is generic, the logic of It is convention for the other toolchains to each redefine their own version of the struct with their namespace prefixed. See So I have added back the |
||
|
||
} // namespace tools | ||
|
||
namespace toolchains { | ||
|
@@ -65,6 +79,7 @@ class LLVM_LIBRARY_VISIBILITY HLSLToolChain : public ToolChain { | |
static std::optional<std::string> parseTargetProfile(StringRef TargetProfile); | ||
bool requiresValidation(llvm::opt::DerivedArgList &Args) const; | ||
bool requiresBinaryTranslation(llvm::opt::DerivedArgList &Args) const; | ||
bool requiresObjcopy(llvm::opt::DerivedArgList &Args) const; | ||
bool isLastJob(llvm::opt::DerivedArgList &Args, Action::ActionClass AC) const; | ||
|
||
// Set default DWARF version to 4 for DXIL uses version 4. | ||
|
@@ -73,6 +88,7 @@ class LLVM_LIBRARY_VISIBILITY HLSLToolChain : public ToolChain { | |
private: | ||
mutable std::unique_ptr<tools::hlsl::Validator> Validator; | ||
mutable std::unique_ptr<tools::hlsl::MetalConverter> MetalConverter; | ||
mutable std::unique_ptr<tools::LLVMObjcopy> LLVMObjcopy; | ||
}; | ||
|
||
} // end namespace toolchains | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// RUN: %clang_dxc -Qstrip-rootsignature -T cs_6_0 /Fo %t -### %s 2>&1 | FileCheck %s | ||
|
||
// Test to demonstrate that we specify to the root signature with the | ||
// -Qstrip-rootsignature option | ||
|
||
// CHECK: "{{.*}}llvm-objcopy{{.*}}" "{{.*}}" "{{.*}}" "--remove-section=RTS0" | ||
|
||
[shader("compute"), RootSignature("")] | ||
[numthreads(1,1,1)] | ||
void EmptyEntry() {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this anymore? I don't see it being used, and I would think that making this a separate tool's job would make this unnecessary.