yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Ellie Hermaszewskaformatf65d756bf

master
1.8 KiB82 linesraw
1// d3d12-fence.cpp
2#include "d3d12-fence.h"
3
4#include "d3d12-device.h"
5
6namespace gfx
7{
8namespace d3d12
9{
10
11using namespace Slang;
12
13FenceImpl::~FenceImpl()
14{
15    if (m_waitEvent)
16        CloseHandle(m_waitEvent);
17}
18
19HANDLE FenceImpl::getWaitEvent()
20{
21    if (m_waitEvent)
22        return m_waitEvent;
23    m_waitEvent = CreateEventEx(nullptr, nullptr, 0, EVENT_ALL_ACCESS);
24    return m_waitEvent;
25}
26
27Result FenceImpl::init(DeviceImpl* device, const IFence::Desc& desc)
28{
29    SLANG_RETURN_ON_FAIL(device->m_device->CreateFence(
30        desc.initialValue,
31        desc.isShared ? D3D12_FENCE_FLAG_SHARED : D3D12_FENCE_FLAG_NONE,
32        IID_PPV_ARGS(m_fence.writeRef())));
33    return SLANG_OK;
34}
35
36Result FenceImpl::getCurrentValue(uint64_t* outValue)
37{
38    *outValue = m_fence->GetCompletedValue();
39    return SLANG_OK;
40}
41
42Result FenceImpl::setCurrentValue(uint64_t value)
43{
44    SLANG_RETURN_ON_FAIL(m_fence->Signal(value));
45    return SLANG_OK;
46}
47
48Result FenceImpl::getSharedHandle(InteropHandle* outHandle)
49{
50#if !SLANG_WINDOWS_FAMILY
51    return SLANG_E_NOT_IMPLEMENTED;
52#else
53    // Check if a shared handle already exists.
54    if (sharedHandle.handleValue != 0)
55    {
56        *outHandle = sharedHandle;
57        return SLANG_OK;
58    }
59
60    ComPtr<ID3D12Device> devicePtr;
61    m_fence->GetDevice(IID_PPV_ARGS(devicePtr.writeRef()));
62    SLANG_RETURN_ON_FAIL(devicePtr->CreateSharedHandle(
63        m_fence,
64        NULL,
65        GENERIC_ALL,
66        nullptr,
67        (HANDLE*)&outHandle->handleValue));
68    outHandle->api = InteropHandleAPI::D3D12;
69    sharedHandle = *outHandle;
70    return SLANG_OK;
71#endif
72}
73
74Result FenceImpl::getNativeHandle(InteropHandle* outNativeHandle)
75{
76    outNativeHandle->api = gfx::InteropHandleAPI::D3D12;
77    outNativeHandle->handleValue = (uint64_t)m_fence.get();
78    return SLANG_OK;
79}
80
81} // namespace d3d12
82} // namespace gfx