summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2021-12-08 15:20:14 -0800
committerGitHub <noreply@github.com>2021-12-08 15:20:14 -0800
commit6c08cd900c0a02140b6af9de97b05c0a955243a4 (patch)
treeda9ff09d501f1d24d087fdb055763fe469988523
parent9606401e1de1002e3ad070bc5c6384fa5bc4d9ff (diff)
gfx Fence implementation improvements. (#2049)
-rw-r--r--slang-gfx.h9
-rw-r--r--tools/gfx/cuda/render-cuda.cpp4
-rw-r--r--tools/gfx/d3d12/render-d3d12.cpp16
-rw-r--r--tools/gfx/debug-layer.cpp5
-rw-r--r--tools/gfx/debug-layer.h4
-rw-r--r--tools/gfx/immediate-renderer-base.cpp4
-rw-r--r--tools/gfx/vulkan/render-vk.cpp4
7 files changed, 29 insertions, 17 deletions
diff --git a/slang-gfx.h b/slang-gfx.h
index 8ed99f2c1..769a5edf4 100644
--- a/slang-gfx.h
+++ b/slang-gfx.h
@@ -42,6 +42,8 @@ typedef SlangInt Int;
typedef SlangUInt UInt;
typedef uint64_t DeviceAddress;
+const uint64_t kTimeoutInfinite = 0xFFFFFFFFFFFFFFFF;
+
// Declare opaque type
class IInputLayout: public ISlangUnknown
{
@@ -1732,8 +1734,9 @@ public:
virtual SLANG_NO_THROW void SLANG_MCALL waitOnHost() = 0;
- /// Queue a device side wait for the given fences.
- virtual SLANG_NO_THROW Result SLANG_MCALL waitForFences(uint32_t fenceCount, IFence** fences, uint64_t* waitValues) = 0;
+ /// Queues a device side wait for the given fences.
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ waitForFenceValuesOnDevice(uint32_t fenceCount, IFence** fences, uint64_t* waitValues) = 0;
};
#define SLANG_UUID_ICommandQueue \
{ \
@@ -2158,6 +2161,8 @@ public:
virtual SLANG_NO_THROW Result SLANG_MCALL
createFence(const IFence::Desc& desc, IFence** outFence) = 0;
+ /// Wait on the host for the fences to signals.
+ /// `timeout` is in nanoseconds, can be set to `kTimeoutInfinite`.
virtual SLANG_NO_THROW Result SLANG_MCALL waitForFences(
uint32_t fenceCount,
IFence** fences,
diff --git a/tools/gfx/cuda/render-cuda.cpp b/tools/gfx/cuda/render-cuda.cpp
index b97fc819c..4cd460358 100644
--- a/tools/gfx/cuda/render-cuda.cpp
+++ b/tools/gfx/cuda/render-cuda.cpp
@@ -1221,8 +1221,8 @@ public:
SLANG_CUDA_HANDLE_ERROR(resultCode);
}
- virtual SLANG_NO_THROW Result SLANG_MCALL
- waitForFences(uint32_t fenceCount, IFence** fences, uint64_t* waitValues) override
+ virtual SLANG_NO_THROW Result SLANG_MCALL waitForFenceValuesOnDevice(
+ uint32_t fenceCount, IFence** fences, uint64_t* waitValues) override
{
return SLANG_FAIL;
}
diff --git a/tools/gfx/d3d12/render-d3d12.cpp b/tools/gfx/d3d12/render-d3d12.cpp
index ebc894291..d6dc565b0 100644
--- a/tools/gfx/d3d12/render-d3d12.cpp
+++ b/tools/gfx/d3d12/render-d3d12.cpp
@@ -3947,13 +3947,15 @@ public:
WaitForSingleObject(globalWaitHandle, INFINITE);
}
- virtual SLANG_NO_THROW Result SLANG_MCALL
- waitForFences(uint32_t fenceCount, IFence** fences, uint64_t* waitValues) override
+ virtual SLANG_NO_THROW Result SLANG_MCALL waitForFenceValuesOnDevice(
+ uint32_t fenceCount, IFence** fences, uint64_t* waitValues) override
{
for (uint32_t i = 0; i < fenceCount; ++i)
{
auto fenceImpl = static_cast<FenceImpl*>(fences[i]);
- m_d3dQueue->Wait(fenceImpl->m_fence.get(), waitValues[i]);
+ m_d3dQueue->Wait(
+ fenceImpl->m_fence.get(),
+ waitValues[i]);
}
return SLANG_OK;
}
@@ -6307,14 +6309,18 @@ Result D3D12Device::createFence(const IFence::Desc& desc, IFence** outFence)
Result D3D12Device::waitForFences(
uint32_t fenceCount, IFence** fences, uint64_t* fenceValues, bool waitForAll, uint64_t timeout)
{
- List<HANDLE> waitHandles;
+ ShortList<HANDLE> waitHandles;
for (uint32_t i = 0; i < fenceCount; ++i)
{
auto fenceImpl = static_cast<FenceImpl*>(fences[i]);
waitHandles.add(fenceImpl->getWaitEvent());
SLANG_RETURN_ON_FAIL(fenceImpl->m_fence->SetEventOnCompletion(fenceValues[i], fenceImpl->getWaitEvent()));
}
- auto result = WaitForMultipleObjects(fenceCount, waitHandles.getBuffer(), waitForAll ? TRUE : FALSE, (DWORD)timeout);
+ auto result = WaitForMultipleObjects(
+ fenceCount,
+ waitHandles.getArrayView().getBuffer(),
+ waitForAll ? TRUE : FALSE,
+ timeout == kTimeoutInfinite ? INFINITE : (DWORD)(timeout / 1000000));
if (result == WAIT_TIMEOUT)
return SLANG_E_TIME_OUT;
return result == WAIT_FAILED ? SLANG_FAIL : SLANG_OK;
diff --git a/tools/gfx/debug-layer.cpp b/tools/gfx/debug-layer.cpp
index 60e726243..c589662a0 100644
--- a/tools/gfx/debug-layer.cpp
+++ b/tools/gfx/debug-layer.cpp
@@ -1489,7 +1489,8 @@ void DebugCommandQueue::waitOnHost()
baseObject->waitOnHost();
}
-Result DebugCommandQueue::waitForFences(uint32_t fenceCount, IFence** fences, uint64_t* waitValues)
+Result DebugCommandQueue::waitForFenceValuesOnDevice(
+ uint32_t fenceCount, IFence** fences, uint64_t* waitValues)
{
SLANG_GFX_API_FUNC;
List<IFence*> innerFences;
@@ -1497,7 +1498,7 @@ Result DebugCommandQueue::waitForFences(uint32_t fenceCount, IFence** fences, ui
{
innerFences.add(getInnerObj(fences[i]));
}
- return baseObject->waitForFences(fenceCount, innerFences.getBuffer(), waitValues);
+ return baseObject->waitForFenceValuesOnDevice(fenceCount, innerFences.getBuffer(), waitValues);
}
Result DebugCommandQueue::getNativeHandle(NativeHandle* outHandle)
diff --git a/tools/gfx/debug-layer.h b/tools/gfx/debug-layer.h
index 71cf74260..07182d70d 100644
--- a/tools/gfx/debug-layer.h
+++ b/tools/gfx/debug-layer.h
@@ -566,8 +566,8 @@ public:
virtual SLANG_NO_THROW void SLANG_MCALL
executeCommandBuffers(uint32_t count, ICommandBuffer* const* commandBuffers, IFence* fence, uint64_t valueToSignal) override;
virtual SLANG_NO_THROW void SLANG_MCALL waitOnHost() override;
- virtual SLANG_NO_THROW Result SLANG_MCALL
- waitForFences(uint32_t fenceCount, IFence** fences, uint64_t* waitValues) override;
+ virtual SLANG_NO_THROW Result SLANG_MCALL waitForFenceValuesOnDevice(
+ uint32_t fenceCount, IFence** fences, uint64_t* waitValues) override;
virtual SLANG_NO_THROW Result SLANG_MCALL getNativeHandle(NativeHandle* outHandle) override;
};
diff --git a/tools/gfx/immediate-renderer-base.cpp b/tools/gfx/immediate-renderer-base.cpp
index 34cc70b74..df46cc200 100644
--- a/tools/gfx/immediate-renderer-base.cpp
+++ b/tools/gfx/immediate-renderer-base.cpp
@@ -595,8 +595,8 @@ public:
virtual SLANG_NO_THROW void SLANG_MCALL waitOnHost() override { getRenderer()->waitForGpu(); }
- virtual SLANG_NO_THROW Result SLANG_MCALL
- waitForFences(uint32_t fenceCount, IFence** fences, uint64_t* waitValues) override
+ virtual SLANG_NO_THROW Result SLANG_MCALL waitForFenceValuesOnDevice(
+ uint32_t fenceCount, IFence** fences, uint64_t* waitValues) override
{
return SLANG_FAIL;
}
diff --git a/tools/gfx/vulkan/render-vk.cpp b/tools/gfx/vulkan/render-vk.cpp
index b55c78ea0..b05d0fa42 100644
--- a/tools/gfx/vulkan/render-vk.cpp
+++ b/tools/gfx/vulkan/render-vk.cpp
@@ -4981,8 +4981,8 @@ public:
return m_desc;
}
- virtual SLANG_NO_THROW Result SLANG_MCALL
- waitForFences(uint32_t fenceCount, IFence** fences, uint64_t* waitValues) override
+ virtual SLANG_NO_THROW Result SLANG_MCALL waitForFenceValuesOnDevice(
+ uint32_t fenceCount, IFence** fences, uint64_t* waitValues) override
{
for (uint32_t i = 0; i < fenceCount; ++i)
{