2
0
Эх сурвалжийг харах

Enable recompile of shaders with includes in dxc (#2996)

* Enable recompile of shaders with includes in dxc

When recompiling, the dxc executable stores all file blobs under names
that use backslashes. However, when recompiling, the filenames of the
includes in a shader are joined with the directory using a forward
slash. In addition, many authors use forward slashes to separate
subdirectories in these includes. Because of this, no includes could
ever match.

By converting all / in the path to \ just before trying to retrieve the
associated pseudo-file, the file is found. Recompilation is only
supported on Windows presently, so other OS path dividers needn't be
considered. The same native() call that generates the keys originally is
used to generate the keys to retrieve them.

Modify smoke.hlsl to verify that recompilation works
Greg Roth 5 жил өмнө
parent
commit
dd27189bab

+ 1 - 1
external/SPIRV-Tools

@@ -1 +1 @@
-Subproject commit 7a1af5878594cec2992a1bb00565b4c712490239
+Subproject commit 33cf7c425af29c1612c30845a0c426585b8d98c8

+ 7 - 1
tools/clang/tools/dxclib/dxc.cpp

@@ -59,6 +59,7 @@
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/Path.h"
 #ifdef _WIN32
 #include <dia2.h>
 #include <comdef.h>
@@ -555,7 +556,12 @@ public:
     _COM_Outptr_result_maybenull_ IDxcBlob **ppIncludeSource
   ) override {
     try {
-      *ppIncludeSource = includeFiles.at(std::wstring(pFilename));
+      // Convert pFilename into native form for indexing as is done when the MD is created
+      std::string FilenameStr8 = Unicode::UTF16ToUTF8StringOrThrow(pFilename);
+      llvm::SmallString<128> NormalizedPath;
+      llvm::sys::path::native(FilenameStr8, NormalizedPath);
+      std::wstring FilenameStr16 = Unicode::UTF8ToUTF16StringOrThrow(NormalizedPath.c_str());
+      *ppIncludeSource = includeFiles.at(FilenameStr16);
       (*ppIncludeSource)->AddRef();
     }
     CATCH_CPP_RETURN_HRESULT()

+ 4 - 0
utils/hct/cmdtestfiles/inc2.hlsli

@@ -0,0 +1,4 @@
+int f2(int g)
+{
+  return g*42;
+}

+ 7 - 0
utils/hct/cmdtestfiles/include/inc1.hlsli

@@ -0,0 +1,7 @@
+// Verify that we can find an include header in the original directory
+#include "inc2.hlsli"
+
+int f1(int g)
+{
+  return f2(g);
+}

+ 4 - 1
utils/hct/cmdtestfiles/smoke.hlsl

@@ -1,3 +1,6 @@
+// Verify that we can successfully process an include
+#include "include/inc1.hlsli"
+
 int g;
 static int g_unused;
 
@@ -15,5 +18,5 @@ float4 main() : semantic
   int x = 3;
   x;
   #endif
-  return g;
+  return f1(g);
 }