@@ -230,6 +230,10 @@ NVSDK_NGX_Result Nvngx_FG::D3D12_Init(unsigned long long InApplicationId, const
230230 ID3D12Device* InDevice, const NVSDK_NGX_FeatureCommonInfo* InFeatureInfo,
231231 NVSDK_NGX_Version InSDKVersion)
232232{
233+ auto lease = _calls.TryTransition ();
234+ if (!lease)
235+ return NVSDK_NGX_Result_FAIL_NotInitialized;
236+
233237 const auto lookup = lookupProvider ();
234238 if (lookup.status == ProviderStatus::Pending)
235239 return NVSDK_NGX_Result_FAIL_NotInitialized;
@@ -245,6 +249,10 @@ NVSDK_NGX_Result Nvngx_FG::D3D12_Init_Ext(unsigned long long InApplicationId, co
245249 ID3D12Device* InDevice, NVSDK_NGX_Version InSDKVersion,
246250 const NVSDK_NGX_FeatureCommonInfo* InFeatureInfo)
247251{
252+ auto lease = _calls.TryTransition ();
253+ if (!lease)
254+ return NVSDK_NGX_Result_FAIL_NotInitialized;
255+
248256 const auto lookup = lookupProvider ();
249257 if (lookup.status == ProviderStatus::Pending)
250258 return NVSDK_NGX_Result_FAIL_NotInitialized;
@@ -258,27 +266,21 @@ NVSDK_NGX_Result Nvngx_FG::D3D12_Init_Ext(unsigned long long InApplicationId, co
258266
259267NVSDK_NGX_Result Nvngx_FG::D3D12_Shutdown ()
260268{
261- auto * provider = _provider.Peek ();
262-
263- if (!provider)
264- return NVSDK_NGX_Result_Fail;
265-
266- return provider->D3D12_Shutdown ();
269+ return WithDx12Shutdown ([&](auto closeProvider) { return closeProvider (nullptr ); });
267270}
268271
269272NVSDK_NGX_Result Nvngx_FG::D3D12_Shutdown1 (ID3D12Device* InDevice)
270273{
271- auto * provider = _provider.Peek ();
272-
273- if (!provider)
274- return NVSDK_NGX_Result_Fail;
275-
276- return provider->D3D12_Shutdown1 (InDevice);
274+ return WithDx12Shutdown ([&](auto closeProvider) { return closeProvider (InDevice); });
277275}
278276
279277NVSDK_NGX_Result Nvngx_FG::D3D12_GetScratchBufferSize (NVSDK_NGX_Feature InFeatureId,
280278 const NVSDK_NGX_Parameter* InParameters, size_t * OutSizeInBytes)
281279{
280+ auto lease = _calls.TryOperation ();
281+ if (!lease)
282+ return NVSDK_NGX_Result_FAIL_NotInitialized;
283+
282284 auto * provider = getProvider ();
283285
284286 if (!provider)
@@ -290,6 +292,14 @@ NVSDK_NGX_Result Nvngx_FG::D3D12_GetScratchBufferSize(NVSDK_NGX_Feature InFeatur
290292NVSDK_NGX_Result Nvngx_FG::D3D12_CreateFeature (ID3D12GraphicsCommandList* InCmdList, NVSDK_NGX_Feature InFeatureID,
291293 NVSDK_NGX_Parameter* InParameters, NVSDK_NGX_Handle** OutHandle)
292294{
295+ if (!OutHandle)
296+ return NVSDK_NGX_Result_FAIL_InvalidParameter;
297+ *OutHandle = nullptr ;
298+
299+ auto lease = _calls.TryOperation ();
300+ if (!lease)
301+ return NVSDK_NGX_Result_FAIL_NotInitialized;
302+
293303 return CreateProviderHandle (_handles, OutHandle, Nvngx_FG_Handle { lastIdCreated++ + NVNGX_PROVIDER_ID_OFFSET },
294304 NVSDK_NGX_Result_Success, NVSDK_NGX_Result_FAIL_InvalidParameter, NVSDK_NGX_Result_Fail,
295305 [&](Nvngx_FG_Handle& handle)
@@ -304,6 +314,10 @@ NVSDK_NGX_Result Nvngx_FG::D3D12_CreateFeature(ID3D12GraphicsCommandList* InCmdL
304314
305315NVSDK_NGX_Result Nvngx_FG::D3D12_ReleaseFeature (NVSDK_NGX_Handle* InHandle)
306316{
317+ auto lease = _calls.TryOperation ();
318+ if (!lease)
319+ return NVSDK_NGX_Result_FAIL_NotInitialized;
320+
307321 auto * provider = getProvider ();
308322
309323 if (!provider)
@@ -322,6 +336,10 @@ NVSDK_NGX_Result Nvngx_FG::D3D12_GetFeatureRequirements(IDXGIAdapter* Adapter,
322336 const NVSDK_NGX_FeatureDiscoveryInfo* FeatureDiscoveryInfo,
323337 NVSDK_NGX_FeatureRequirement* OutSupported)
324338{
339+ auto lease = _calls.TryOperation ();
340+ if (!lease)
341+ return NVSDK_NGX_Result_FAIL_NotInitialized;
342+
325343 auto * provider = getProvider ();
326344
327345 if (!provider)
@@ -335,6 +353,10 @@ NVSDK_NGX_Result Nvngx_FG::D3D12_EvaluateFeature(ID3D12GraphicsCommandList* InCm
335353 NVSDK_NGX_Parameter* InParameters,
336354 PFN_NVSDK_NGX_ProgressCallback InCallback)
337355{
356+ auto lease = _calls.TryOperation ();
357+ if (!lease)
358+ return NVSDK_NGX_Result_FAIL_NotInitialized;
359+
338360 auto * provider = getProvider ();
339361
340362 if (!provider)
@@ -404,6 +426,10 @@ NVSDK_NGX_Result Nvngx_FG::D3D12_EvaluateFeature(ID3D12GraphicsCommandList* InCm
404426
405427NVSDK_NGX_Result Nvngx_FG::D3D12_PopulateParameters_Impl (NVSDK_NGX_Parameter* InParameters)
406428{
429+ auto lease = _calls.TryOperation ();
430+ if (!lease)
431+ return NVSDK_NGX_Result_FAIL_NotInitialized;
432+
407433 auto * provider = getProvider ();
408434
409435 if (!provider)
@@ -417,6 +443,10 @@ NVSDK_NGX_Result Nvngx_FG::VULKAN_Init(unsigned long long InApplicationId, const
417443 PFN_vkGetInstanceProcAddr InGIPA, PFN_vkGetDeviceProcAddr InGDPA,
418444 const NVSDK_NGX_FeatureCommonInfo* InFeatureInfo, NVSDK_NGX_Version InSDKVersion)
419445{
446+ auto lease = _calls.TryTransition ();
447+ if (!lease)
448+ return NVSDK_NGX_Result_FAIL_NotInitialized;
449+
420450 const auto lookup = lookupProvider ();
421451 if (lookup.status == ProviderStatus::Pending)
422452 return NVSDK_NGX_Result_FAIL_NotInitialized;
@@ -434,6 +464,10 @@ NVSDK_NGX_Result Nvngx_FG::VULKAN_Init_Ext(unsigned long long InApplicationId, c
434464 NVSDK_NGX_Version InSDKVersion,
435465 const NVSDK_NGX_FeatureCommonInfo* InFeatureInfo)
436466{
467+ auto lease = _calls.TryTransition ();
468+ if (!lease)
469+ return NVSDK_NGX_Result_FAIL_NotInitialized;
470+
437471 const auto lookup = lookupProvider ();
438472 if (lookup.status == ProviderStatus::Pending)
439473 return NVSDK_NGX_Result_FAIL_NotInitialized;
@@ -452,6 +486,10 @@ NVSDK_NGX_Result Nvngx_FG::VULKAN_Init_Ext2(unsigned long long InApplicationId,
452486 NVSDK_NGX_Version InSDKVersion,
453487 const NVSDK_NGX_FeatureCommonInfo* InFeatureInfo)
454488{
489+ auto lease = _calls.TryTransition ();
490+ if (!lease)
491+ return NVSDK_NGX_Result_FAIL_NotInitialized;
492+
455493 const auto lookup = lookupProvider ();
456494 if (lookup.status == ProviderStatus::Pending)
457495 return NVSDK_NGX_Result_FAIL_NotInitialized;
@@ -466,27 +504,21 @@ NVSDK_NGX_Result Nvngx_FG::VULKAN_Init_Ext2(unsigned long long InApplicationId,
466504
467505NVSDK_NGX_Result Nvngx_FG::VULKAN_Shutdown ()
468506{
469- auto * provider = _provider.Peek ();
470-
471- if (!provider)
472- return NVSDK_NGX_Result_Fail;
473-
474- return provider->VULKAN_Shutdown ();
507+ return WithVulkanShutdown ([&](auto closeProvider) { return closeProvider (nullptr ); });
475508}
476509
477510NVSDK_NGX_Result Nvngx_FG::VULKAN_Shutdown1 (VkDevice InDevice)
478511{
479- auto * provider = _provider.Peek ();
480-
481- if (!provider)
482- return NVSDK_NGX_Result_Fail;
483-
484- return provider->VULKAN_Shutdown1 (InDevice);
512+ return WithVulkanShutdown ([&](auto closeProvider) { return closeProvider (InDevice); });
485513}
486514
487515NVSDK_NGX_Result Nvngx_FG::VULKAN_GetScratchBufferSize (NVSDK_NGX_Feature InFeatureId,
488516 const NVSDK_NGX_Parameter* InParameters, size_t * OutSizeInBytes)
489517{
518+ auto lease = _calls.TryOperation ();
519+ if (!lease)
520+ return NVSDK_NGX_Result_FAIL_NotInitialized;
521+
490522 auto * provider = getProvider ();
491523
492524 if (!provider)
@@ -498,6 +530,14 @@ NVSDK_NGX_Result Nvngx_FG::VULKAN_GetScratchBufferSize(NVSDK_NGX_Feature InFeatu
498530NVSDK_NGX_Result Nvngx_FG::VULKAN_CreateFeature (VkCommandBuffer InCmdBuffer, NVSDK_NGX_Feature InFeatureID,
499531 NVSDK_NGX_Parameter* InParameters, NVSDK_NGX_Handle** OutHandle)
500532{
533+ if (!OutHandle)
534+ return NVSDK_NGX_Result_FAIL_InvalidParameter;
535+ *OutHandle = nullptr ;
536+
537+ auto lease = _calls.TryOperation ();
538+ if (!lease)
539+ return NVSDK_NGX_Result_FAIL_NotInitialized;
540+
501541 return CreateProviderHandle (_handles, OutHandle, Nvngx_FG_Handle { lastIdCreated++ + NVNGX_PROVIDER_ID_OFFSET },
502542 NVSDK_NGX_Result_Success, NVSDK_NGX_Result_FAIL_InvalidParameter, NVSDK_NGX_Result_Fail,
503543 [&](Nvngx_FG_Handle& handle)
@@ -514,6 +554,14 @@ NVSDK_NGX_Result Nvngx_FG::VULKAN_CreateFeature1(VkDevice InDevice, VkCommandBuf
514554 NVSDK_NGX_Feature InFeatureID, NVSDK_NGX_Parameter* InParameters,
515555 NVSDK_NGX_Handle** OutHandle)
516556{
557+ if (!OutHandle)
558+ return NVSDK_NGX_Result_FAIL_InvalidParameter;
559+ *OutHandle = nullptr ;
560+
561+ auto lease = _calls.TryOperation ();
562+ if (!lease)
563+ return NVSDK_NGX_Result_FAIL_NotInitialized;
564+
517565 return CreateProviderHandle (_handles, OutHandle, Nvngx_FG_Handle { lastIdCreated++ + NVNGX_PROVIDER_ID_OFFSET },
518566 NVSDK_NGX_Result_Success, NVSDK_NGX_Result_FAIL_InvalidParameter, NVSDK_NGX_Result_Fail,
519567 [&](Nvngx_FG_Handle& handle)
@@ -528,6 +576,10 @@ NVSDK_NGX_Result Nvngx_FG::VULKAN_CreateFeature1(VkDevice InDevice, VkCommandBuf
528576
529577NVSDK_NGX_Result Nvngx_FG::VULKAN_ReleaseFeature (NVSDK_NGX_Handle* InHandle)
530578{
579+ auto lease = _calls.TryOperation ();
580+ if (!lease)
581+ return NVSDK_NGX_Result_FAIL_NotInitialized;
582+
531583 auto * provider = getProvider ();
532584
533585 if (!provider)
@@ -547,6 +599,10 @@ NVSDK_NGX_Result Nvngx_FG::VULKAN_GetFeatureRequirements(const VkInstance Instan
547599 const NVSDK_NGX_FeatureDiscoveryInfo* FeatureDiscoveryInfo,
548600 NVSDK_NGX_FeatureRequirement* OutSupported)
549601{
602+ auto lease = _calls.TryOperation ();
603+ if (!lease)
604+ return NVSDK_NGX_Result_FAIL_NotInitialized;
605+
550606 auto * provider = getProvider ();
551607
552608 if (!provider)
@@ -559,6 +615,10 @@ NVSDK_NGX_Result Nvngx_FG::VULKAN_EvaluateFeature(VkCommandBuffer InCmdList, con
559615 NVSDK_NGX_Parameter* InParameters,
560616 PFN_NVSDK_NGX_ProgressCallback InCallback)
561617{
618+ auto lease = _calls.TryOperation ();
619+ if (!lease)
620+ return NVSDK_NGX_Result_FAIL_NotInitialized;
621+
562622 auto * provider = getProvider ();
563623
564624 if (!provider)
@@ -579,6 +639,10 @@ NVSDK_NGX_Result Nvngx_FG::VULKAN_EvaluateFeature(VkCommandBuffer InCmdList, con
579639
580640NVSDK_NGX_Result Nvngx_FG::VULKAN_PopulateParameters_Impl (NVSDK_NGX_Parameter* InParameters)
581641{
642+ auto lease = _calls.TryOperation ();
643+ if (!lease)
644+ return NVSDK_NGX_Result_FAIL_NotInitialized;
645+
582646 auto * provider = getProvider ();
583647
584648 if (!provider)
0 commit comments