yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
f65d756bf
master
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{ 15if (m_waitEvent ) 16CloseHandle (m_waitEvent ); 17} 18 19HANDLE FenceImpl ::getWaitEvent () 20{ 21if (m_waitEvent ) 22return m_waitEvent ; 23m_waitEvent = CreateEventEx (nullptr ,nullptr ,0 ,EVENT_ALL_ACCESS ); 24return m_waitEvent ; 25} 26 27Result FenceImpl ::init (DeviceImpl * device ,const IFence ::Desc & desc ) 28{ 29SLANG_RETURN_ON_FAIL (device -> m_device -> CreateFence ( 30desc .initialValue , 31desc .isShared ?D3D12_FENCE_FLAG_SHARED :D3D12_FENCE_FLAG_NONE , 32IID_PPV_ARGS (m_fence .writeRef ()))); 33return SLANG_OK ; 34} 35 36Result FenceImpl ::getCurrentValue (uint64_t * outValue ) 37{ 38* outValue = m_fence -> GetCompletedValue (); 39return SLANG_OK ; 40} 41 42Result FenceImpl ::setCurrentValue (uint64_t value ) 43{ 44SLANG_RETURN_ON_FAIL (m_fence -> Signal (value )); 45return SLANG_OK ; 46} 47 48Result FenceImpl ::getSharedHandle (InteropHandle * outHandle ) 49{ 50#if !SLANG_WINDOWS_FAMILY 51return SLANG_E_NOT_IMPLEMENTED ; 52#else 53// Check if a shared handle already exists. 54if (sharedHandle .handleValue != 0 ) 55 { 56* outHandle = sharedHandle ; 57return SLANG_OK ; 58 } 59 60ComPtr < ID3D12Device > devicePtr ; 61m_fence -> GetDevice (IID_PPV_ARGS (devicePtr .writeRef ())); 62SLANG_RETURN_ON_FAIL (devicePtr -> CreateSharedHandle ( 63m_fence , 64NULL , 65GENERIC_ALL , 66nullptr , 67 (HANDLE * )& outHandle -> handleValue )); 68outHandle -> api = InteropHandleAPI ::D3D12 ; 69sharedHandle = * outHandle ; 70return SLANG_OK ; 71#endif 72} 73 74Result FenceImpl ::getNativeHandle (InteropHandle * outNativeHandle ) 75{ 76outNativeHandle -> api = gfx::InteropHandleAPI ::D3D12 ; 77outNativeHandle -> handleValue = (uint64_t )m_fence .get (); 78return SLANG_OK ; 79} 80 81}// namespace d3d12 82}// namespace gfx