diff --git a/lib/DxcSupport/HLSLOptions.cpp b/lib/DxcSupport/HLSLOptions.cpp index 63b513cbe..156b0cb29 100644 --- a/lib/DxcSupport/HLSLOptions.cpp +++ b/lib/DxcSupport/HLSLOptions.cpp @@ -237,7 +237,9 @@ int ReadDxcOpts(const OptTable *optionTable, unsigned flagsToInclude, // Entry point is required in arguments only for drivers; APIs take this through an argument. // The value should default to 'main', but we let the caller apply this policy. - opts.TargetProfile = Args.getLastArgValue(OPT_target_profile); + if (opts.TargetProfile.empty()) { + opts.TargetProfile = Args.getLastArgValue(OPT_target_profile); + } if (opts.IsLibraryProfile()) { if (Args.getLastArg(OPT_entrypoint)) { @@ -311,10 +313,18 @@ int ReadDxcOpts(const OptTable *optionTable, unsigned flagsToInclude, << "' for denorm option."; return 1; } - if (opts.TargetProfile.empty() || !opts.TargetProfile.endswith_lower("6_2")) { + } + + // Check options only allowed in shader model >= 6.2 + if (opts.TargetProfile.empty() || !opts.TargetProfile.endswith_lower("6_2")) { + if (!opts.FPDenormalMode.empty()) { errors << "denorm option is only allowed for shader model 6.2 and above."; return 1; } + if (opts.NoMinPrecision) { + errors << "no min precision mode is only allowed for shader model 6.2 and above."; + return 1; + } } if (Arg *A = Args.getLastArg(OPT_O0, OPT_O1, OPT_O2, OPT_O3)) { diff --git a/tools/clang/test/CodeGenHLSL/cbufferHalf.hlsl b/tools/clang/test/CodeGenHLSL/cbufferHalf.hlsl index 5c0d63cf8..f0fac0efa 100644 --- a/tools/clang/test/CodeGenHLSL/cbufferHalf.hlsl +++ b/tools/clang/test/CodeGenHLSL/cbufferHalf.hlsl @@ -1,4 +1,4 @@ -// RUN: %dxc -E main -T ps_6_0 -no-min-precision %s | FileCheck %s +// RUN: %dxc -E main -T ps_6_2 -no-min-precision %s | FileCheck %s // CHECK: Use native low precision // CHECK: cbuffer Foo diff --git a/tools/clang/test/CodeGenHLSL/literals_exact_precision_Mod.hlsl b/tools/clang/test/CodeGenHLSL/literals_exact_precision_Mod.hlsl index 2e11a8e9c..d5b5eb8fb 100644 --- a/tools/clang/test/CodeGenHLSL/literals_exact_precision_Mod.hlsl +++ b/tools/clang/test/CodeGenHLSL/literals_exact_precision_Mod.hlsl @@ -1,4 +1,4 @@ -// RUN: %dxc -no-min-precision -E test -T vs_6_0 %s +// RUN: %dxc -no-min-precision -E test -T vs_6_2 %s // To test with the classic compiler, run // %sdxroot%\tools\x86\fxc.exe /T ps_5_1 literals.hlsl diff --git a/tools/clang/test/CodeGenHLSL/signature_packing_by_width.hlsl b/tools/clang/test/CodeGenHLSL/signature_packing_by_width.hlsl index 35d58c0a2..828ced9fe 100644 --- a/tools/clang/test/CodeGenHLSL/signature_packing_by_width.hlsl +++ b/tools/clang/test/CodeGenHLSL/signature_packing_by_width.hlsl @@ -1,4 +1,4 @@ -// RUN: %dxc -E main -T ps_6_0 -no-min-precision %s | FileCheck %s +// RUN: %dxc -E main -T ps_6_2 -no-min-precision %s | FileCheck %s // TODO: Update this file when we introduce i8/i16. diff --git a/tools/clang/tools/dxcompiler/dxcompilerobj.cpp b/tools/clang/tools/dxcompiler/dxcompilerobj.cpp index ccf59cd91..bc7c1b7da 100644 --- a/tools/clang/tools/dxcompiler/dxcompilerobj.cpp +++ b/tools/clang/tools/dxcompiler/dxcompilerobj.cpp @@ -328,6 +328,9 @@ public: IFT(UIntToInt(argCount, &argCountInt)); hlsl::options::MainArgs mainArgs(argCountInt, pArguments, 0); hlsl::options::DxcOpts opts; + CW2A pUtf8TargetProfile(pTargetProfile, CP_UTF8); + // Set target profile before reading options and validate + opts.TargetProfile = pUtf8TargetProfile.m_psz; bool finished; ReadOptsAndValidate(mainArgs, opts, pOutputStream, ppResult, finished); if (finished) { @@ -339,7 +342,6 @@ public: // Prepare UTF8-encoded versions of API values. CW2A pUtf8EntryPoint(pEntryPoint, CP_UTF8); - CW2A pUtf8TargetProfile(pTargetProfile, CP_UTF8); CW2A utf8SourceName(pSourceName, CP_UTF8); const char *pUtf8SourceName = utf8SourceName.m_psz; if (pUtf8SourceName == nullptr) { @@ -350,8 +352,6 @@ public: pUtf8SourceName = opts.InputFile.data(); } } - // Set target profile. - opts.TargetProfile = pUtf8TargetProfile.m_psz; IFT(msfPtr->RegisterOutputStream(L"output.bc", pOutputStream)); IFT(msfPtr->CreateStdStreams(m_pMalloc)); diff --git a/tools/clang/unittests/HLSL/CompilerTest.cpp b/tools/clang/unittests/HLSL/CompilerTest.cpp index dd670077b..6744a279d 100644 --- a/tools/clang/unittests/HLSL/CompilerTest.cpp +++ b/tools/clang/unittests/HLSL/CompilerTest.cpp @@ -3929,6 +3929,7 @@ TEST_F(CompilerTest, CodeGenSignaturePacking) { } TEST_F(CompilerTest, CodeGenSignaturePackingByWidth) { + if (m_ver.SkipDxilVersion(1, 2)) return; CodeGenTestCheck(L"..\\CodeGenHLSL\\signature_packing_by_width.hlsl"); } @@ -4334,6 +4335,7 @@ TEST_F(CompilerTest, CodeGenLiterals_Mod) { } TEST_F(CompilerTest, CodeGenLiterals_Exact_Precision_Mod) { + if (m_ver.SkipDxilVersion(1, 2)) return; CodeGenTest(L"..\\CodeGenHLSL\\literals_exact_precision_Mod.hlsl"); } diff --git a/tools/clang/unittests/HLSL/ValidationTest.cpp b/tools/clang/unittests/HLSL/ValidationTest.cpp index 3bf13ea20..66e6b8b8b 100644 --- a/tools/clang/unittests/HLSL/ValidationTest.cpp +++ b/tools/clang/unittests/HLSL/ValidationTest.cpp @@ -1101,9 +1101,10 @@ TEST_F(ValidationTest, StreamIDOutOfBound) { } TEST_F(ValidationTest, SignatureDataWidth) { + if (m_ver.SkipDxilVersion(1, 2)) return; std::vector pArguments = { L"-no-min-precision" }; RewriteAssemblyCheckMsg( - L"..\\CodeGenHLSL\\signature_packing_by_width.hlsl", "ps_6_0", + L"..\\CodeGenHLSL\\signature_packing_by_width.hlsl", "ps_6_2", pArguments.data(), 1, nullptr, 0, {"i8 8, i8 0, (![0-9]+), i8 2, i32 1, i8 2, i32 0, i8 0, null}"}, {"i8 9, i8 0, \\1, i8 2, i32 1, i8 2, i32 0, i8 0, null}"}, diff --git a/utils/hct/hcttestcmds.cmd b/utils/hct/hcttestcmds.cmd index cec618370..a7fdde3b6 100644 --- a/utils/hct/hcttestcmds.cmd +++ b/utils/hct/hcttestcmds.cmd @@ -583,6 +583,20 @@ if %errorlevel% equ 0 ( exit /b 1 ) +dxc.exe %script_dir%\smoke.hlsl /Tps_6_2 /no-min-precision 1>nul +if %errorlevel% neq 0 ( + echo Failed to compile %script_dir%\smoke.hlsl with /no-min-precision option + call :cleanup 2>nul + exit /b 1 +) + +dxc.exe %script_dir%\smoke.hlsl /Tps_6_1 /no-min-precision 2>nul +if %errorlevel% equ 0 ( + echo dxc incorrectly compiled %script_dir%\smoke.hlsl shader model 6.1 with /no-min-precision option + call :cleanup 2>nul + exit /b 1 +) + rem SPIR-V Change Starts echo Smoke test for SPIR-V CodeGen ... set spirv_smoke_success=0