Files
kaizen/external/parallel-rdp/parallel-rdp-standalone/vulkan/semaphore.cpp
T
iris 00cc9309cb Squashed 'external/ircolib/' changes from ce3cd726c..de6e324bd
de6e324bd separate emu thread
10d3daf86 Roms List improvements
95d202f37 Let's make the rom list process on a separate thread so the emulator doesnt take ages to load.
fc306967f Wow the ROM Header was just completely busted. Game list view works now
bad1691ee fuck this shit
2b59e5f46 game list in progress
d26417b83 remappable inputs in progress
ac4af8106 input
e72abc240 update readme
430139dc9 Qt6 frontend
3080d4d45 Fix this small bug too
08cd13b85 Cop0 unused functions do not actually pose a threat (as per manual). They don't do anything, so shall we.
61bb4fb44 make idle loop detection a little more specific with where the load goes
b037de4c3 SAZDFsdff
12e81e73e need to figure out why n64-systemtest loops indefinitely at some address that appears to be valid (i think it's me not invalidating the cache properly)
204f0e13b idle skipping seems to work!
cb8bb634a sdkfjlasdf
58e5c89c1 Fix compilation issue on my machine (no idea)
24fb2898e attempting more serious idle skipping
214719577 Place rsp.Step inside cached interpreter. Gains about 3 more fps
bb97dcc23 mmmmm
920b77d38 wjkhasdfjhkasdf
430ccdab4 it's a start...
4f42a673a Cached interpreter plays Mario 64. Start looking into RSP as well
c9a030787 idle skipping works!
5fbda03ce new idea
366637aba Idle skipping... maybe?
609fa2fb0 Cache instructions implemented but broken lmao. Commented out for now
e140a6d12 - Stop using inheritance for CPU, instead use composition. - Introduce KAIZEN_JIT_ENABLED optional define instead of relying on __aarch64__ and the like. - More cache work
68e613057 prep cache impl
811b4d809 fix clang format
fda755f7d idk
d5024ebbf small MI refactor in preparation of (eventually) implementing the RDRAM interface properly
694b45341 Merge commit '206dcdedf195fb320913584180edb12c7731e396' as 'external/SDL'
206dcdedf Squashed 'external/SDL/' content from commit 4d17b99d0a
4d16e1cb4 need to update sdl
848b19920 Fix compilation error
db61b5299 Merge commit 'e94a94559f28e49678fbcf72199a5258137b0fe9' as 'external/imgui'
e94a94559 Squashed 'external/imgui/' content from commit 02e9b8cac
52edb3757 need to update imgui
c1a705e86 Emulate weird JALR behaviour
4b4c32f4b Fix exception for "unusable COP1" in 4 instructions i missed accidentally (again)
df5828142 Bug putting 0s in the log everywhere
f8b580048 Make isviewer a sink to file
8241e9735 Fix exception for "unusable COP1" in 4 instructions i missed accidentally
b29715f20 small changes
d9a620bc1 make use of my new small utility library
0d1aa938e Add 'external/ircolib/' from commit 'ce3cd726c8df8388d554abf8bb55d55020eb4450'
e64eb40b3 Fuck git

git-subtree-dir: external/ircolib
git-subtree-split: de6e324bde
2026-06-15 11:56:38 +02:00

245 lines
6.9 KiB
C++

/* Copyright (c) 2017-2023 Hans-Kristian Arntzen
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "semaphore.hpp"
#include "device.hpp"
#ifndef _WIN32
#include <unistd.h>
#else
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif
namespace Vulkan
{
SemaphoreHolder::~SemaphoreHolder()
{
recycle_semaphore();
}
void SemaphoreHolder::recycle_semaphore()
{
if (!owned)
return;
VK_ASSERT(semaphore);
if (internal_sync)
{
if (semaphore_type == VK_SEMAPHORE_TYPE_TIMELINE || external_compatible_features)
{
device->destroy_semaphore_nolock(semaphore);
}
else if (is_signalled())
{
// We can't just destroy a semaphore if we don't know who signals it (e.g. WSI).
// Have to consume it by waiting then recycle.
if (signal_is_foreign_queue)
device->consume_semaphore_nolock(semaphore);
else
device->destroy_semaphore_nolock(semaphore);
}
else
device->recycle_semaphore_nolock(semaphore);
}
else
{
if (semaphore_type == VK_SEMAPHORE_TYPE_TIMELINE || external_compatible_features)
{
device->destroy_semaphore(semaphore);
}
else if (is_signalled())
{
// We can't just destroy a semaphore if we don't know who signals it (e.g. WSI).
// Have to consume it by waiting then recycle.
if (signal_is_foreign_queue)
device->consume_semaphore(semaphore);
else
device->destroy_semaphore(semaphore);
}
else
device->recycle_semaphore(semaphore);
}
}
bool SemaphoreHolder::wait_timeline_timeout(uint64_t value, uint64_t timeout)
{
VK_ASSERT(semaphore_type == VK_SEMAPHORE_TYPE_TIMELINE);
VK_ASSERT(is_proxy_timeline());
VkSemaphoreWaitInfo wait_info = { VK_STRUCTURE_TYPE_SEMAPHORE_WAIT_INFO };
wait_info.pSemaphores = &semaphore;
wait_info.semaphoreCount = 1;
wait_info.pValues = &value;
return device->get_device_table().vkWaitSemaphores(device->get_device(), &wait_info, timeout) == VK_SUCCESS;
}
void SemaphoreHolder::wait_timeline(uint64_t value)
{
wait_timeline_timeout(value, UINT64_MAX);
}
SemaphoreHolder &SemaphoreHolder::operator=(SemaphoreHolder &&other) noexcept
{
if (this == &other)
return *this;
assert(device == other.device);
recycle_semaphore();
semaphore = other.semaphore;
timeline = other.timeline;
signalled = other.signalled;
pending_wait = other.pending_wait;
semaphore_type = other.semaphore_type;
owned = other.owned;
other.semaphore = VK_NULL_HANDLE;
other.timeline = 0;
other.signalled = false;
other.pending_wait = false;
other.owned = false;
return *this;
}
ExternalHandle SemaphoreHolder::export_to_handle()
{
ExternalHandle h;
if ((external_compatible_features & VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT) == 0)
{
LOGE("Semaphore is not export compatible.\n");
return h;
}
if (!semaphore)
{
LOGE("Semaphore has already been consumed.\n");
return h;
}
// Technically we can export early with reference transference, but it's a bit dubious.
// We want to remain compatible with copy transference for later, e.g. SYNC_FD.
if (!signalled && semaphore_type == VK_SEMAPHORE_TYPE_BINARY)
{
LOGE("Cannot export payload from a semaphore that is not queued up for signal.\n");
return h;
}
#ifdef _WIN32
VkSemaphoreGetWin32HandleInfoKHR handle_info = { VK_STRUCTURE_TYPE_SEMAPHORE_GET_WIN32_HANDLE_INFO_KHR };
handle_info.semaphore = semaphore;
handle_info.handleType = external_compatible_handle_type;
if (device->get_device_table().vkGetSemaphoreWin32HandleKHR(device->get_device(), &handle_info, &h.handle) != VK_SUCCESS)
{
LOGE("Failed to export to opaque handle.\n");
h.handle = nullptr;
}
#else
VkSemaphoreGetFdInfoKHR fd_info = { VK_STRUCTURE_TYPE_SEMAPHORE_GET_FD_INFO_KHR };
fd_info.semaphore = semaphore;
fd_info.handleType = external_compatible_handle_type;
if (device->get_device_table().vkGetSemaphoreFdKHR(device->get_device(), &fd_info, &h.handle) != VK_SUCCESS)
{
LOGE("Failed to export to opaque FD.\n");
h.handle = -1;
}
#endif
h.semaphore_handle_type = external_compatible_handle_type;
return h;
}
bool SemaphoreHolder::import_from_handle(ExternalHandle handle)
{
if ((external_compatible_features & VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT) == 0)
{
LOGE("Semaphore is not import compatible.\n");
return false;
}
if (!semaphore)
{
LOGE("Semaphore has already been consumed.\n");
return false;
}
if (signalled)
{
LOGE("Cannot import payload to semaphore that is already signalled.\n");
return false;
}
if (handle.semaphore_handle_type != external_compatible_handle_type)
{
LOGE("Mismatch in semaphore handle type.\n");
return false;
}
#ifdef _WIN32
VkImportSemaphoreWin32HandleInfoKHR import = { VK_STRUCTURE_TYPE_IMPORT_SEMAPHORE_WIN32_HANDLE_INFO_KHR };
import.handle = handle.handle;
import.semaphore = semaphore;
import.handleType = handle.semaphore_handle_type;
import.flags = semaphore_type == VK_SEMAPHORE_TYPE_BINARY_KHR ? VK_SEMAPHORE_IMPORT_TEMPORARY_BIT : 0;
if (device->get_device_table().vkImportSemaphoreWin32HandleKHR(device->get_device(), &import) != VK_SUCCESS)
{
LOGE("Failed to import semaphore handle %p!\n", handle.handle);
return false;
}
#else
VkImportSemaphoreFdInfoKHR import = { VK_STRUCTURE_TYPE_IMPORT_SEMAPHORE_FD_INFO_KHR };
import.fd = handle.handle;
import.semaphore = semaphore;
import.handleType = handle.semaphore_handle_type;
import.flags = semaphore_type == VK_SEMAPHORE_TYPE_BINARY_KHR ? VK_SEMAPHORE_IMPORT_TEMPORARY_BIT : 0;
if (device->get_device_table().vkImportSemaphoreFdKHR(device->get_device(), &import) != VK_SUCCESS)
{
LOGE("Failed to import semaphore FD %d!\n", handle.handle);
return false;
}
#endif
if (ExternalHandle::semaphore_handle_type_imports_by_reference(import.handleType))
{
#ifdef _WIN32
// Consume the handle, since the VkSemaphore holds a reference on Win32.
::CloseHandle(handle.handle);
#else
::close(handle.handle);
#endif
}
signal_external();
return true;
}
void SemaphoreHolderDeleter::operator()(Vulkan::SemaphoreHolder *semaphore)
{
semaphore->device->handle_pool.semaphores.free(semaphore);
}
}