Skip to content

Fix concurrent dxilconv pass initialization - #8820

Draft
Damyan Pepper (damyanp) wants to merge 1 commit into
microsoft:mainfrom
damyanp:damyanp-fix-dxilconv-pass-registry
Draft

Fix concurrent dxilconv pass initialization#8820
Damyan Pepper (damyanp) wants to merge 1 commit into
microsoft:mainfrom
damyanp:damyanp-fix-dxilconv-pass-registry

Conversation

@damyanp

Copy link
Copy Markdown
Member

Register all passes that dxilconv uses when the DLL starts. This prevents concurrent first conversions from modifying the global pass registry.

Add fresh-process tests that verify pass registration and convert 256 different DXBC shaders at the same time.

Fixes #8819

Register all passes used by the DXBC converter during DLL startup. Add fresh-process tests for the pass closure and concurrent conversion.

Fixes microsoft#8819

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 1147c945-f9cc-4aa3-8f58-e7238e0270ec
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff 9a3e225dab9683212c648d2cc2b7f09bbf57cbe8 9aaaa225d99409f9b572ef8a427cda147b09052b -- projects/dxilconv/include/DxilConvPasses/InitializePasses.h projects/dxilconv/unittests/DxilConvPassRegistryTestHelper.cpp projects/dxilconv/lib/DxilConvPasses/DxilCleanup.cpp projects/dxilconv/lib/DxilConvPasses/InitializePasses.cpp projects/dxilconv/tools/dxilconv/dxilconv.cpp projects/dxilconv/unittests/DxilConvTests.cpp tools/opt/opt.cpp
View the diff from clang-format here.
diff --git a/projects/dxilconv/unittests/DxilConvPassRegistryTestHelper.cpp b/projects/dxilconv/unittests/DxilConvPassRegistryTestHelper.cpp
index 482d3a3f..bddd5c99 100644
--- a/projects/dxilconv/unittests/DxilConvPassRegistryTestHelper.cpp
+++ b/projects/dxilconv/unittests/DxilConvPassRegistryTestHelper.cpp
@@ -29,15 +29,9 @@ static int VerifyPassRegistration() {
 
   llvm::PassRegistry *Registry = llvm::PassRegistry::getPassRegistry();
   const char *RequiredPasses[] = {
-      "dce",
-      "mem2reg",
-      "assumption-cache-tracker",
-      "red",
-      "loops",
-      "domtree",
-      "dxil-cleanup",
-      "normalizedxil",
-      "scopenested",
+      "dce",           "mem2reg",       "assumption-cache-tracker",
+      "red",           "loops",         "domtree",
+      "dxil-cleanup",  "normalizedxil", "scopenested",
       "scopenestinfo",
   };
   for (const char *PassName : RequiredPasses) {
@@ -72,9 +66,9 @@ static bool CompileShaders(std::vector<CComPtr<ID3DBlob>> &Shaders) {
         std::to_string(Index) + ".0f, position.y, 0.0f, 1.0f); }";
     CComPtr<ID3DBlob> Errors;
     HRESULT Result =
-        D3DCompile(Source.data(), Source.size(), "concurrent-init.hlsl", nullptr,
-                   nullptr, "main", "ps_5_0", D3DCOMPILE_OPTIMIZATION_LEVEL3, 0,
-                   &Shaders[Index], &Errors);
+        D3DCompile(Source.data(), Source.size(), "concurrent-init.hlsl",
+                   nullptr, nullptr, "main", "ps_5_0",
+                   D3DCOMPILE_OPTIMIZATION_LEVEL3, 0, &Shaders[Index], &Errors);
     if (FAILED(Result)) {
       if (Errors)
         std::fwrite(Errors->GetBufferPointer(), 1, Errors->GetBufferSize(),
@@ -125,9 +119,9 @@ static int RunConcurrentConversions() {
   for (unsigned Index = 0; Index < WorkerCount; ++Index) {
     Workers.emplace_back([&, Index]() {
       IDxbcConverter *RawConverter = nullptr;
-      HRESULT Result = CreateInstance(
-          CLSID_DxbcConverter, __uuidof(IDxbcConverter),
-          reinterpret_cast<void **>(&RawConverter));
+      HRESULT Result =
+          CreateInstance(CLSID_DxbcConverter, __uuidof(IDxbcConverter),
+                         reinterpret_cast<void **>(&RawConverter));
       CComPtr<IDxbcConverter> Converter;
       Converter.Attach(RawConverter);
 
@@ -141,8 +135,8 @@ static int RunConcurrentConversions() {
         LPWSTR Diagnostics = nullptr;
         Result = Converter->Convert(
             Shaders[Index]->GetBufferPointer(),
-            static_cast<UINT32>(Shaders[Index]->GetBufferSize()), nullptr, &Dxil,
-            &DxilSize, &Diagnostics);
+            static_cast<UINT32>(Shaders[Index]->GetBufferSize()), nullptr,
+            &Dxil, &DxilSize, &Diagnostics);
         CoTaskMemFree(Dxil);
         CoTaskMemFree(Diagnostics);
       }
  • Check this box to apply formatting changes to this branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

dxilconv: Concurrent first calls to IDxbcConverter::Convert cause a race during LLVM pass registration

1 participant