Pass compiler options to preprocessor (#4234)

* Pass compiler options to preprocessor

If we don't pass the compiler options to the preprocessor the
preprocessor doesn't get initialized correctly.

Without this change the preprocessor step identifies the shader model
version as 0.0, pipeline stage as invalid, and language version as the
default.

* Remove arugment duplication
This commit is contained in:
Chris B 2022-02-07 16:08:01 -06:00 коммит произвёл GitHub
Родитель 5dc2ef659e
Коммит c95c076f52
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 59 добавлений и 15 удалений

Просмотреть файл

@ -924,28 +924,26 @@ void DxcContext::Preprocess() {
CComPtr<IDxcCompiler> pCompiler;
CComPtr<IDxcOperationResult> pPreprocessResult;
CComPtr<IDxcBlobEncoding> pSource;
std::vector<std::wstring> argStrings;
CopyArgsToWStrings(m_Opts.Args, CoreOption, argStrings);
std::vector<LPCWSTR> args;
args.reserve(argStrings.size());
for (const std::wstring &a : argStrings)
args.push_back(a.data());
CComPtr<IDxcLibrary> pLibrary;
CComPtr<IDxcIncludeHandler> pIncludeHandler;
IFT(CreateInstance(CLSID_DxcLibrary, &pLibrary));
IFT(pLibrary->CreateIncludeHandler(&pIncludeHandler));
// Carry forward the options that control preprocessor
if (m_Opts.LegacyMacroExpansion)
args.push_back(L"-flegacy-macro-expansion");
std::vector<std::wstring> includePath;
for (const llvm::opt::Arg *A : m_Opts.Args.filtered(hlsl::options::OPT_I))
includePath.emplace_back(Unicode::UTF8ToUTF16StringOrThrow(A->getValue()));
for (const std::wstring &directory : includePath) {
args.emplace_back(L"-I");
args.emplace_back(directory.c_str()); // The strings are kept alive in the includePath vector
}
ReadFileIntoBlob(m_dxcSupport, StringRefUtf16(m_Opts.InputFile), &pSource);
IFT(CreateInstance(CLSID_DxcCompiler, &pCompiler));
IFT(pCompiler->Preprocess(pSource, StringRefUtf16(m_Opts.InputFile), args.data(), args.size(), m_Opts.Defines.data(), m_Opts.Defines.size(), pIncludeHandler, &pPreprocessResult));
IFT(pCompiler->Preprocess(pSource, StringRefUtf16(m_Opts.InputFile),
args.data(), args.size(), m_Opts.Defines.data(),
m_Opts.Defines.size(), pIncludeHandler,
&pPreprocessResult));
WriteOperationErrorsToConsole(pPreprocessResult, m_Opts.OutputWarnings);
HRESULT status;

Просмотреть файл

@ -815,8 +815,6 @@ public:
} else {
compiler.getLangOpts().HLSLEntryFunction =
compiler.getCodeGenOpts().HLSLEntryFunction = pUtf8EntryPoint;
compiler.getLangOpts().HLSLProfile =
compiler.getCodeGenOpts().HLSLProfile = opts.TargetProfile;
// Parse and apply
if (opts.BindingTableDefine.size()) {
@ -1415,6 +1413,8 @@ public:
compiler.getLangOpts().EnablePayloadAccessQualifiers = Opts.EnablePayloadQualifiers;
compiler.getLangOpts().EnableShortCircuit = Opts.EnableShortCircuit;
compiler.getLangOpts().EnableBitfields = Opts.EnableBitfields;
compiler.getLangOpts().HLSLProfile =
compiler.getCodeGenOpts().HLSLProfile = Opts.TargetProfile;
// SPIRV change starts
#ifdef ENABLE_SPIRV_CODEGEN

Просмотреть файл

@ -0,0 +1,21 @@
#if __SHADER_TARGET_STAGE == __SHADER_STAGE_VERTEX
#define __SHADER_STAGE_PREFIX vs
#elif __SHADER_TARGET_STAGE == __SHADER_STAGE_PIXEL
#define __SHADER_STAGE_PREFIX ps
#elif __SHADER_TARGET_STAGE == __SHADER_STAGE_GEOMETRY
#define __SHADER_STAGE_PREFIX gs
#elif __SHADER_TARGET_STAGE == __SHADER_STAGE_HULL
#define __SHADER_STAGE_PREFIX hs
#elif __SHADER_TARGET_STAGE == __SHADER_STAGE_DOMAIN
#define __SHADER_STAGE_PREFIX ds
#elif __SHADER_TARGET_STAGE == __SHADER_STAGE_COMPUTE
#define __SHADER_STAGE_PREFIX cs
#elif __SHADER_TARGET_STAGE == __SHADER_STAGE_AMPLIFICATION
#define __SHADER_STAGE_PREFIX as
#elif __SHADER_TARGET_STAGE == __SHADER_STAGE_MESH
#define __SHADER_STAGE_PREFIX ms
#elif __SHADER_TARGET_STAGE == __SHADER_STAGE_LIBRARY
#define __SHADER_STAGE_PREFIX lib
#endif
__SHADER_STAGE_PREFIX __SHADER_TARGET_MAJOR __SHADER_TARGET_MINOR)

Просмотреть файл

@ -0,0 +1 @@
__HLSL_VERSION

Просмотреть файл

@ -443,6 +443,30 @@ if %Failed% neq 0 goto :failed
call :run dxc.exe -P include-main.hlsl.pp -I inc subfolder\include-main.hlsl
if %Failed% neq 0 goto :failed
set testname=Test Version macro
for %%v in (2016 2017 2018 2021) do (
call :run dxc.exe -HV %%v -P %%v.hlsl.pp %testfiles%\VersionMacro.hlsl
if %Failed% neq 0 goto :failed
call :check_file %%v.hlsl.pp find %%v del
if %Failed% neq 0 goto :failed
)
set testname=Test shader profile macro
for %%p in (vs ps gs hs ds cs lib) do (
for %%v in (5 6) do (
if "%%p" == "lib" ( if %%v leq 2 goto :next )
if "%%p" == "ms" ( if %%v leq 4 goto :next )
if "%%p" == "as" ( if %%v leq 4 goto :next )
call :run dxc.exe -T %%p_6_%%v -P %%p_%%v.hlsl.pp %testfiles%\PipelineStage.hlsl
if %Failed% neq 0 goto :failed
call :check_file %%p_%%v.hlsl.pp find "%%p 6 %%v" del
if %Failed% neq 0 goto :failed
:next
rem Skip to the next iteration
)
)
set testname=Byte Order Markers
call :run dxc.exe /T ps_6_0 "%testfiles%\bom-main-ascii.hlsl"
call :run dxc.exe /T ps_6_0 "%testfiles%\bom-main-utf8.hlsl"