Skip to content

Commit 33b492b

Browse files
committed
Add more config-ext interface
1 parent 4facf40 commit 33b492b

File tree

6 files changed

+22
-7
lines changed

6 files changed

+22
-7
lines changed

include/luisa/backends/ext/dx_config_ext.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ struct DirectXDeviceConfigExt : public DeviceConfigExt {
7676
virtual bool SignalFence(
7777
ID3D12CommandQueue *queue,
7878
ID3D12Fence *fence, uint64_t fenceIndex) noexcept { return false; }
79-
79+
virtual bool WaitFence(
80+
ID3D12CommandQueue *queue,
81+
ID3D12Fence *fence, uint64_t fenceIndex) noexcept { return false; }
82+
virtual bool SyncFence(ID3D12Fence *fence, uint64_t fenceIndex) { return false; }
8083
virtual ~DirectXDeviceConfigExt() noexcept override = default;
8184
};
8285

include/luisa/backends/ext/vk_config_ext.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ class VulkanDeviceConfigExt : public DeviceConfigExt {
2828
virtual VkCommandBuffer borrow_command_buffer(
2929
StreamTag stream_tag) noexcept { return nullptr; }
3030
virtual bool execute_command_buffer(VkCommandBuffer cmd_buffer) noexcept { return false; }
31+
virtual bool signal_semaphore(VkQueue queue, VkSemaphore _semaphore, uint64_t index) { return false; }
32+
virtual bool wait_semaphore(VkQueue queue, VkSemaphore _semaphore, uint64_t index) { return false; }
33+
virtual bool sync_semaphore(VkSemaphore _semaphore, uint64_t index) { return false; }
3134
virtual void readback_vulkan_device(
3235
VkInstance instance,
3336
VkPhysicalDevice physical_device,

src/backends/dx/DXApi/LCEvent.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ void LCEvent::Sync(uint64_t fenceIdx) const {
1919
}
2020
void LCEvent::Signal(CommandQueue *queue, uint64 fenceIdx) const {
2121
std::lock_guard lck(eventMtx);
22-
queue->Queue()->Signal(fence.Get(), fenceIdx);
22+
if (!device->deviceSettings || !device->deviceSettings->SignalFence(queue->Queue(), fence.Get(), fenceIdx))
23+
queue->Queue()->Signal(fence.Get(), fenceIdx);
2324
lastFence = std::max(lastFence, fenceIdx);
2425
queue->AddEvent(this, fenceIdx);
2526
}
@@ -31,7 +32,8 @@ void LCEvent::Signal(DStorageCommandQueue *queue, uint64 fenceIdx) const {
3132
}
3233
void LCEvent::Wait(CommandQueue *queue, uint64 fenceIdx) const {
3334
std::lock_guard lck(eventMtx);
34-
queue->Queue()->Wait(fence.Get(), fenceIdx);
35+
if (!device->deviceSettings || !device->deviceSettings->WaitFence(queue->Queue(), fence.Get(), fenceIdx))
36+
queue->Queue()->Wait(fence.Get(), fenceIdx);
3537
}
3638
bool LCEvent::IsComplete(uint64 fenceIdx) const {
3739
std::lock_guard lck(eventMtx);

src/backends/dx/DXRuntime/Device.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Device::~Device() {
5050

5151
void Device::WaitFence(ID3D12Fence *fence, uint64 fenceIndex) {
5252
if (fenceIndex <= 0) return;
53+
if (deviceSettings && deviceSettings->SyncFence(fence, fenceIndex)) return;
5354
HANDLE eventHandle = CreateEventEx(nullptr, nullptr, false, EVENT_ALL_ACCESS);
5455
auto d = vstd::scope_exit([&] {
5556
CloseHandle(eventHandle);

src/backends/vk/event.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ void Event::signal(Stream &stream, uint64_t value, VkCommandBuffer *cmdbuffer) {
5151
std::lock_guard lck(eventMtx);
5252
lastFence = std::max(lastFence, value);
5353
}
54+
if (device()->config_ext() && device()->config_ext()->signal_semaphore(stream.queue(), _semaphore, value))
55+
return;
5456
auto timelineInfo1 = get_timeline_submit(&value);
5557
VkSubmitInfo info1{};
5658
info1.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
@@ -65,7 +67,9 @@ void Event::signal(Stream &stream, uint64_t value, VkCommandBuffer *cmdbuffer) {
6567

6668
VK_CHECK_RESULT(vkQueueSubmit(stream.queue(), 1, &info1, VK_NULL_HANDLE));
6769
}
68-
void Event::wait(Stream &stream, uint64_t value, VkCommandBuffer *cmdbuffer) {
70+
void Event::wait(Stream &stream, uint64_t value) {
71+
if (device()->config_ext() && device()->config_ext()->wait_semaphore(stream.queue(), _semaphore, value))
72+
return;
6973
VkTimelineSemaphoreSubmitInfo timelineInfo1{};
7074
timelineInfo1.sType = VK_STRUCTURE_TYPE_TIMELINE_SEMAPHORE_SUBMIT_INFO;
7175
timelineInfo1.pNext = nullptr;
@@ -84,11 +88,13 @@ void Event::wait(Stream &stream, uint64_t value, VkCommandBuffer *cmdbuffer) {
8488
info1.signalSemaphoreCount = 0;
8589
info1.pSignalSemaphores = nullptr;
8690
// ... Enqueue initial device work here.
87-
info1.commandBufferCount = cmdbuffer ? 1 : 0;
88-
info1.pCommandBuffers = cmdbuffer;
91+
info1.commandBufferCount = 0;
92+
info1.pCommandBuffers = nullptr;
8993
VK_CHECK_RESULT(vkQueueSubmit(stream.queue(), 1, &info1, VK_NULL_HANDLE));
9094
}
9195
void Event::host_wait(uint64_t value) {
96+
if (device()->config_ext() && device()->config_ext()->sync_semaphore(_semaphore, value))
97+
return;
9298
VkSemaphoreWaitInfo info{
9399
.sType = VK_STRUCTURE_TYPE_SEMAPHORE_WAIT_INFO,
94100
.semaphoreCount = 1,

src/backends/vk/event.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Event : public Resource {
1111
void update_fence(uint64_t value);
1212
void signal(Stream &stream, uint64_t value, VkCommandBuffer *cmdbuffer = nullptr);
1313
void signal_sparse(Stream &stream, uint64_t const* value_ptr, VkBindSparseInfo *sparse_info, VkTimelineSemaphoreSubmitInfo* timeline_ptr);
14-
void wait(Stream &stream, uint64_t value, VkCommandBuffer *cmdbuffer = nullptr);
14+
void wait(Stream &stream, uint64_t value);
1515
void host_wait(uint64_t value);
1616
void notify(uint64_t value);
1717
public:

0 commit comments

Comments
 (0)