diff --git a/tools/dxvk/proton/keyed-mutex-without-fence.patch b/tools/dxvk/proton/keyed-mutex-without-fence.patch new file mode 100644 index 0000000000..4475e7e2cb --- /dev/null +++ b/tools/dxvk/proton/keyed-mutex-without-fence.patch @@ -0,0 +1,101 @@ +diff --git a/src/dxvk/dxvk_image.cpp b/src/dxvk/dxvk_image.cpp +index 5bcb22a..e98547d 100644 +--- a/src/dxvk/dxvk_image.cpp ++++ b/src/dxvk/dxvk_image.cpp +@@ -54,75 +54,81 @@ namespace dxvk { + + HRESULT DxvkKeyedMutex::AcquireSync(UINT64 key, DWORD milliseconds) { + if (m_owned.load(std::memory_order_acquire)) + return DXGI_ERROR_INVALID_CALL; + + LARGE_INTEGER timeout = { }; + timeout.QuadPart = int64_t(milliseconds) * -10000; + + D3DKMT_ACQUIREKEYEDMUTEX acquire = { }; + acquire.hKeyedMutex = m_kmtLocal; + acquire.Key = key; + acquire.pTimeout = milliseconds == INFINITE ? nullptr : &timeout; + + NTSTATUS status = D3DKMTAcquireKeyedMutex(&acquire); + + if (status == STATUS_TIMEOUT) + return WAIT_TIMEOUT; + if (status) + return DXGI_ERROR_INVALID_CALL; + +- VkSemaphore semaphore = m_fence->handle(); ++ if (m_fence) { ++ VkSemaphore semaphore = m_fence->handle(); + +- VkSemaphoreWaitInfo info = { VK_STRUCTURE_TYPE_SEMAPHORE_WAIT_INFO }; +- info.semaphoreCount = 1; +- info.pSemaphores = &semaphore; +- info.pValues = &acquire.FenceValue; ++ VkSemaphoreWaitInfo info = { VK_STRUCTURE_TYPE_SEMAPHORE_WAIT_INFO }; ++ info.semaphoreCount = 1; ++ info.pSemaphores = &semaphore; ++ info.pValues = &acquire.FenceValue; + +- if (m_vkd->vkWaitSemaphores(m_vkd->device(), &info, -1)) { +- Logger::warn("DxvkKeyedMutex::AcquireSync: Failed to wait semaphore"); +- return DXGI_ERROR_INVALID_CALL; ++ if (m_vkd->vkWaitSemaphores(m_vkd->device(), &info, -1)) { ++ Logger::warn("DxvkKeyedMutex::AcquireSync: Failed to wait semaphore"); ++ return DXGI_ERROR_INVALID_CALL; ++ } + } + + m_fenceValue = acquire.FenceValue; + m_owned.store(true, std::memory_order_release); + return S_OK; + } + + + HRESULT DxvkKeyedMutex::ReleaseSync(UINT64 key) { + if (!m_owned.load(std::memory_order_acquire)) + return DXGI_ERROR_INVALID_CALL; + +- VkSemaphoreSignalInfo info = { VK_STRUCTURE_TYPE_SEMAPHORE_SIGNAL_INFO }; +- info.semaphore = m_fence->handle(); +- info.value = m_fenceValue + 1; ++ uint64_t fenceValue = m_fenceValue; + +- if (m_vkd->vkSignalSemaphore(m_vkd->device(), &info)) { +- Logger::warn("D3D11DXGIKeyedMutex::ReleaseSync: Failed to signal semaphore"); +- return DXGI_ERROR_INVALID_CALL; ++ if (m_fence) { ++ VkSemaphoreSignalInfo info = { VK_STRUCTURE_TYPE_SEMAPHORE_SIGNAL_INFO }; ++ info.semaphore = m_fence->handle(); ++ info.value = ++fenceValue; ++ ++ if (m_vkd->vkSignalSemaphore(m_vkd->device(), &info)) { ++ Logger::warn("D3D11DXGIKeyedMutex::ReleaseSync: Failed to signal semaphore"); ++ return DXGI_ERROR_INVALID_CALL; ++ } + } + + D3DKMT_RELEASEKEYEDMUTEX release = { }; + release.hKeyedMutex = m_kmtLocal; + release.Key = key; +- release.FenceValue = m_fenceValue + 1; ++ release.FenceValue = fenceValue; + + if (D3DKMTReleaseKeyedMutex(&release)) { + Logger::warn("D3D11DXGIKeyedMutex::ReleaseSync: Failed to release mutex."); + return DXGI_ERROR_INVALID_CALL; + } + + m_owned.store(false, std::memory_order_release); + return S_OK; + } + + + DxvkImage::DxvkImage( + DxvkDevice* device, + const DxvkImageCreateInfo& createInfo, + DxvkMemoryAllocator& allocator, + VkMemoryPropertyFlags memFlags) + : DxvkPagedResource(allocator), + m_vkd (device->vkd()), + m_properties (memFlags), + m_shaderStages (util::shaderStages(createInfo.stages)), diff --git a/tools/tests/test_dxvk_keyed_mutex.py b/tools/tests/test_dxvk_keyed_mutex.py index e6b03f5fd2..5b3374a6ef 100644 --- a/tools/tests/test_dxvk_keyed_mutex.py +++ b/tools/tests/test_dxvk_keyed_mutex.py @@ -6,15 +6,18 @@ import tempfile import unittest ROOT = Path(__file__).resolve().parents[2] -PATCH = ROOT / 'tools/dxvk/patches/0005-keyed-mutex-without-fence.patch' +PATCHES = { + 'pinned component': ROOT / 'tools/dxvk/patches/0005-keyed-mutex-without-fence.patch', + 'DroidDeck-Proton': ROOT / 'tools/dxvk/proton/keyed-mutex-without-fence.patch', +} CHECK = ROOT / 'tools/dxvk/check_keyed_mutex_fence.py' TARGET = 'src/dxvk/dxvk_image.cpp' -def pre_image(): +def pre_image(patch): lines = [] inside = False - for line in PATCH.read_text().splitlines(): + for line in patch.read_text().splitlines(): if line.startswith('@@'): inside = True lines.append('') @@ -29,27 +32,34 @@ class KeyedMutexFenceTest(unittest.TestCase): temporary = tempfile.TemporaryDirectory() self.addCleanup(temporary.cleanup) self.tree = Path(temporary.name) - (self.tree / 'src/dxvk').mkdir(parents=True) def run_check(self, path): return subprocess.run(['python3', '-I', str(CHECK), str(path)], capture_output=True, text=True, timeout=120) def test_patched_source_passes(self): - target = self.tree / TARGET - target.write_text(pre_image()) - subprocess.run(['git', 'apply', '--unsafe-paths', '--directory', str(self.tree), str(PATCH)], - check=True, cwd=self.tree) - result = self.run_check(target) - self.assertEqual(result.returncode, 0, result.stdout + result.stderr) - self.assertIn('PASS', result.stdout) + for name, patch in PATCHES.items(): + with self.subTest(name): + tree = self.tree / patch.stem + (tree / 'src/dxvk').mkdir(parents=True) + target = tree / TARGET + target.write_text(pre_image(patch)) + subprocess.run(['git', 'apply', '--unsafe-paths', '--directory', str(tree), str(patch)], + check=True, cwd=tree) + result = self.run_check(target) + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + self.assertIn('PASS', result.stdout) def test_unpatched_source_is_rejected(self): - target = self.tree / TARGET - target.write_text(pre_image()) - result = self.run_check(target) - self.assertNotEqual(result.returncode, 0) - self.assertIn('FAIL', result.stderr) + for name, patch in PATCHES.items(): + with self.subTest(name): + tree = self.tree / patch.stem + (tree / 'src/dxvk').mkdir(parents=True) + target = tree / TARGET + target.write_text(pre_image(patch)) + result = self.run_check(target) + self.assertNotEqual(result.returncode, 0) + self.assertIn('FAIL', result.stderr) if __name__ == '__main__':