Skip to content

Commit 64eb5e6

Browse files
committed
Added option for disabling HLSL intrinsics
1 parent 062a96b commit 64eb5e6

File tree

12 files changed

+137
-15
lines changed

12 files changed

+137
-15
lines changed

include/dxc/Support/HLSLOptions.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,3 +601,6 @@ def rw_decl_global_cb : Flag<["-", "/"], "decl-global-cb">, Group<hlslrewrite_Gr
601601
HelpText<"Collect all global constants outside cbuffer declarations into cbuffer GlobalCB { ... }. Still experimental, not all dependency scenarios handled.">;
602602
// Also removed: compress, decompress, /Gch (child effect), /Gpp (partial precision)
603603
// /Op - no support for preshaders.
604+
605+
def fvk_disable_hlsl_intrinsics : Flag<["-"], "fvk-disable-hlsl-intrinsics">, Group<spirv_Group>, Flags<[CoreOption, DriverOption]>,
606+
HelpText<"Disable HLSL intrinsics">;

include/dxc/Support/SPIRVOptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ enum class SpirvLayoutRule {
3838
};
3939

4040
struct SpirvCodeGenOptions {
41+
bool disableHLSLIntrinsics;
4142
/// Disable legalization and optimization and emit raw SPIR-V
4243
bool codeGenHighLevel;
4344
bool debugInfoFile;

lib/DxcSupport/HLSLOptions.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,8 @@ int ReadDxcOpts(const OptTable *optionTable, unsigned flagsToInclude,
10741074

10751075
// SPIRV Change Starts
10761076
#ifdef ENABLE_SPIRV_CODEGEN
1077+
opts.SpirvOptions.disableHLSLIntrinsics =
1078+
Args.hasFlag(OPT_fvk_disable_hlsl_intrinsics, OPT_INVALID, false);
10771079
opts.GenSPIRV = Args.hasFlag(OPT_spirv, OPT_INVALID, false);
10781080
opts.SpirvOptions.invertY =
10791081
Args.hasFlag(OPT_fvk_invert_y, OPT_INVALID, false);

tools/clang/include/clang/AST/ASTContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2408,7 +2408,7 @@ class ASTContext : public RefCountedBase<ASTContext> {
24082408
/// It is normally invoked after ASTContext construction.
24092409
///
24102410
/// \param Target The target
2411-
void InitBuiltinTypes(const TargetInfo &Target);
2411+
void InitBuiltinTypes(const TargetInfo &Target, bool ignoreHLSLIntrinsics);
24122412

24132413
private:
24142414
void InitBuiltinType(CanQualType &R, BuiltinType::Kind K);

tools/clang/include/clang/AST/HlslTypes.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ namespace hlsl {
5151

5252
/// <summary>Initializes the specified context to support HLSL
5353
/// compilation.</summary>
54-
void InitializeASTContextForHLSL(clang::ASTContext &context);
54+
void InitializeASTContextForHLSL(clang::ASTContext &context,
55+
bool ignoreHLSLIntrinsics);
5556

5657
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
5758
// Type system enumerations.

tools/clang/include/clang/Frontend/CompilerInstance.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ class CompilerInstance : public ModuleLoader {
669669
std::string getSpecificModuleCachePath();
670670

671671
/// Create the AST context.
672-
void createASTContext();
672+
void createASTContext(bool ignoreHLSLIntrinsics = false);
673673

674674
/// Create an external AST source to read a PCH file and attach it to the AST
675675
/// context.

tools/clang/include/clang/Frontend/FrontendAction.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ class FrontendAction {
208208
///
209209
/// \return True on success; on failure the compilation of this file should
210210
/// be aborted and neither Execute() nor EndSourceFile() should be called.
211-
bool BeginSourceFile(CompilerInstance &CI, const FrontendInputFile &Input);
211+
bool BeginSourceFile(CompilerInstance &CI, const FrontendInputFile &Input,
212+
bool ignoreHLSLIntrinsics = false);
212213

213214
/// \brief Set the source manager's main input file, and run the action.
214215
bool Execute();

tools/clang/lib/AST/ASTContext.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,7 @@ void ASTContext::InitBuiltinType(CanQualType &R, BuiltinType::Kind K) {
958958
Types.push_back(Ty);
959959
}
960960

961-
void ASTContext::InitBuiltinTypes(const TargetInfo &Target) {
961+
void ASTContext::InitBuiltinTypes(const TargetInfo &Target, bool ignoreHLSLIntrinsics) {
962962
assert((!this->Target || this->Target == &Target) &&
963963
"Incorrect target reinitialization");
964964
assert(VoidTy.isNull() && "Context reinitialized?");
@@ -1108,7 +1108,7 @@ void ASTContext::InitBuiltinTypes(const TargetInfo &Target) {
11081108

11091109
HLSLStringTy = this->getPointerType(CharTy);
11101110

1111-
hlsl::InitializeASTContextForHLSL(*this); // Previously in constructor, guarded by !DelayInitialization
1111+
hlsl::InitializeASTContextForHLSL(*this, ignoreHLSLIntrinsics); // Previously in constructor, guarded by !DelayInitialization
11121112
}
11131113
// HLSL Change Ends
11141114
}

tools/clang/lib/Frontend/CompilerInstance.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,12 +409,12 @@ std::string CompilerInstance::getSpecificModuleCachePath() {
409409

410410
// ASTContext
411411

412-
void CompilerInstance::createASTContext() {
412+
void CompilerInstance::createASTContext(bool ignoreHLSLIntrinsics) {
413413
Preprocessor &PP = getPreprocessor();
414414
Context = new ASTContext(getLangOpts(), PP.getSourceManager(),
415415
PP.getIdentifierTable(), PP.getSelectorTable(),
416416
PP.getBuiltinInfo());
417-
Context->InitBuiltinTypes(getTarget());
417+
Context->InitBuiltinTypes(getTarget(), ignoreHLSLIntrinsics);
418418
}
419419

420420
// ExternalASTSource

tools/clang/lib/Frontend/FrontendAction.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ FrontendAction::CreateWrappedASTConsumer(CompilerInstance &CI,
173173
}
174174

175175
bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
176-
const FrontendInputFile &Input) {
176+
const FrontendInputFile &Input,
177+
bool ignoreHLSLIntrinsics) {
177178
assert(!Instance && "Already processing a source file!");
178179
assert(!Input.isEmpty() && "Unexpected empty filename!");
179180
setCurrentInput(Input);
@@ -323,7 +324,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
323324
if (!usesPreprocessorOnly()) {
324325
// Parsing a model file should reuse the existing ASTContext.
325326
if (!isModelParsingAction())
326-
CI.createASTContext();
327+
CI.createASTContext(ignoreHLSLIntrinsics);
327328

328329
std::unique_ptr<ASTConsumer> Consumer =
329330
CreateWrappedASTConsumer(CI, InputFile);

0 commit comments

Comments
 (0)