Bladeren bron

Move dxclib one level up; string handling in DxilRuntimeReflection (#2308)

Move dxclib one level up / out of dxc directory
Remove unused member in DxilRuntimeData
Change DxilRuntimeReflection handling of strings to be platform independent
Fix opt tool (DxcSetThreadMallocOrDefault no longer exist)
Helena Kotas 6 jaren geleden
bovenliggende
commit
c1f17ac954

+ 0 - 1
include/dxc/DxilContainer/DxilRuntimeReflection.h

@@ -572,7 +572,6 @@ public:
 
 class DxilRuntimeData {
 private:
-  uint32_t m_TableCount;
   StringTableReader m_StringReader;
   IndexTableReader m_IndexTableReader;
   RawBytesReader m_RawBytesReader;

+ 9 - 8
include/dxc/DxilContainer/DxilRuntimeReflection.inl

@@ -13,6 +13,7 @@
 #include <unordered_map>
 #include <vector>
 #include <memory>
+#include <cwchar>
 
 namespace hlsl {
 namespace RDAT {
@@ -92,7 +93,7 @@ public:
 DxilRuntimeData::DxilRuntimeData() : DxilRuntimeData(nullptr, 0) {}
 
 DxilRuntimeData::DxilRuntimeData(const void *ptr, size_t size)
-    : m_TableCount(0), m_StringReader(), m_IndexTableReader(), m_RawBytesReader(),
+    : m_StringReader(), m_IndexTableReader(), m_RawBytesReader(),
       m_ResourceTableReader(), m_FunctionTableReader(),
       m_SubobjectTableReader(), m_Context() {
   m_Context = {&m_StringReader, &m_IndexTableReader, &m_RawBytesReader,
@@ -311,13 +312,13 @@ public:
 
 void DxilRuntimeReflection_impl::AddString(const char *ptr) {
   if (m_StringMap.find(ptr) == m_StringMap.end()) {
-    int size = ::MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, ptr, -1,
-                                     nullptr, 0);
-    if (size != 0) {
-      std::unique_ptr<wchar_t[]> pNew(new wchar_t[size]);
-      ::MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, ptr, -1,
-                            pNew.get(), size);
-      m_StringMap[ptr] = std::move(pNew);
+    auto state = std::mbstate_t();
+    size_t size = std::mbsrtowcs(nullptr, &ptr, 0, &state);
+    if (size != static_cast<size_t>(-1)) {
+      std::unique_ptr<wchar_t[]> pNew(new wchar_t[size + 1]);
+      auto pOldPtr = ptr;
+      std::mbsrtowcs(pNew.get(), &ptr, size + 1, &state);
+      m_StringMap[pOldPtr] = std::move(pNew);
     }
   }
 }

+ 1 - 0
tools/clang/tools/CMakeLists.txt

@@ -24,6 +24,7 @@ add_llvm_external_project(clang-tools-extra extra)
 
 # HLSL Change Starts
 add_subdirectory(dxcompiler)
+add_subdirectory(dxclib)
 add_subdirectory(dxc)
 
 # These targets can currently only be built on Windows.

+ 3 - 2
tools/clang/tools/dxc/CMakeLists.txt

@@ -24,6 +24,7 @@ add_clang_executable(dxc
 target_link_libraries(dxc
   dxclib
   dxcompiler
+  dxclib
   )
 
 if(ENABLE_SPIRV_CODEGEN)
@@ -37,6 +38,8 @@ if (WIN32)
   include_directories(AFTER ${DIASDK_INCLUDE_DIRS})
 endif (WIN32)
 
+include_directories(${LLVM_SOURCE_DIR}/tools/clang/tools)
+
 add_dependencies(dxc dxclib dxcompiler)
 
 if(UNIX)
@@ -51,5 +54,3 @@ endif()
 install(TARGETS dxc
   RUNTIME DESTINATION bin)
 
-add_subdirectory(dxclib)
-

+ 11 - 1
tools/clang/tools/dxc/dxclib/CMakeLists.txt → tools/clang/tools/dxclib/CMakeLists.txt

@@ -6,6 +6,16 @@ if (WIN32)
   find_package(DiaSDK REQUIRED) # Used for constants and declarations.
 endif (WIN32)
 
+set( LLVM_LINK_COMPONENTS
+  ${LLVM_TARGETS_TO_BUILD}
+  dxcsupport
+  DXIL
+  DxilContainer
+  HLSL
+  Option     # option library
+  Support    # just for assert and raw streams
+  )
+
 add_clang_library(dxclib
   dxc.cpp
   )
@@ -18,4 +28,4 @@ if (WIN32)
   include_directories(AFTER ${DIASDK_INCLUDE_DIRS})
 endif (WIN32)
 
-add_dependencies(dxclib TablegenHLSLOptions)
+add_dependencies(dxclib TablegenHLSLOptions dxcompiler)

+ 0 - 0
tools/clang/tools/dxc/dxclib/dxc.cpp → tools/clang/tools/dxclib/dxc.cpp


+ 0 - 0
tools/clang/tools/dxc/dxclib/dxc.h → tools/clang/tools/dxclib/dxc.h


+ 1 - 1
tools/opt/opt.cpp

@@ -305,7 +305,7 @@ int __cdecl main(int argc, char **argv) {
     return 1;
   llvm::sys::fs::AutoCleanupPerThreadFileSystem auto_cleanup_fs;
   if (FAILED(DxcInitThreadMalloc())) return 1;
-  DxcSetThreadMallocOrDefault(nullptr);
+  DxcSetThreadMallocToDefault();
   llvm::sys::fs::MSFileSystem* msfPtr;
   if (FAILED(CreateMSFileSystemForDisk(&msfPtr))) return 1;
   std::unique_ptr<llvm::sys::fs::MSFileSystem> msf(msfPtr);