Quellcode durchsuchen

Restrict no min precision option to shader model 6.2 (#615)

Young Kim vor 8 Jahren
Ursprung
Commit
fb33d62978

+ 12 - 2
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)) {

+ 1 - 1
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

+ 1 - 1
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

+ 1 - 1
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.
 

+ 3 - 3
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));

+ 2 - 0
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");
 }
 

+ 2 - 1
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<LPCWSTR> 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}"},

+ 14 - 0
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