Skip to content

Commit 4d14e29

Browse files
committed
Fix FFX crash on DestroyContext by using real context ptr
1 parent ddd7dad commit 4d14e29

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

OptiScaler/proxies/FfxApi_Proxy.h

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class FfxApiProxy
8080

8181
inline static FfxModule main_vk;
8282

83-
inline static ankerl::unordered_dense::map<ffxContext*, FFXStructType> contextToType;
83+
inline static ankerl::unordered_dense::map<ffxContext, FFXStructType> contextToType;
8484

8585
inline static bool _skipDestroyCalls = false;
8686

@@ -855,27 +855,39 @@ class FfxApiProxy
855855
auto type = GetType(desc->type);
856856
auto isFg = type == FFXStructType::FG || type == FFXStructType::SwapchainDX12;
857857

858-
contextToType[context] = type;
858+
ffxReturnCode_t result = FFX_API_RETURN_ERROR;
859859

860860
if (isFg && fg_dx12.dll != nullptr)
861861
{
862862
LOG_DEBUG("Creating with fg_dx12");
863-
return fg_dx12.CreateContext(context, desc, memCb);
863+
result = fg_dx12.CreateContext(context, desc, memCb);
864+
contextToType[*context] = type;
865+
LOG_DEBUG("Created with fg_dx12: {:X}", (size_t) *context);
866+
return result;
864867
}
865868
else if (type == FFXStructType::Upscaling && upscaling_dx12.dll != nullptr)
866869
{
867870
LOG_DEBUG("Creating with upscaling_dx12");
868-
return upscaling_dx12.CreateContext(context, desc, memCb);
871+
result = upscaling_dx12.CreateContext(context, desc, memCb);
872+
contextToType[*context] = type;
873+
LOG_DEBUG("Created with upscaling_dx12: {:X}", (size_t) *context);
874+
return result;
869875
}
870876
else if (type == FFXStructType::Denoiser && denoiser_dx12.dll != nullptr)
871877
{
872878
LOG_DEBUG("Creating with denoiser_dx12");
873-
return denoiser_dx12.CreateContext(context, desc, memCb);
879+
result = denoiser_dx12.CreateContext(context, desc, memCb);
880+
contextToType[*context] = type;
881+
LOG_DEBUG("Created with denoiser_dx12: {:X}", (size_t) *context);
882+
return result;
874883
}
875884
else if (type == FFXStructType::RadianceCache && radiance_dx12.dll != nullptr)
876885
{
877886
LOG_DEBUG("Creating with radiance_dx12");
878-
return radiance_dx12.CreateContext(context, desc, memCb);
887+
result = radiance_dx12.CreateContext(context, desc, memCb);
888+
contextToType[*context] = type;
889+
LOG_DEBUG("Created with radiance_dx12: {:X}", (size_t) *context);
890+
return result;
879891
}
880892

881893
const auto skipFG = isFg && fg_dx12.skipQueryCalls;
@@ -890,7 +902,7 @@ class FfxApiProxy
890902
else if (type == FFXStructType::Upscaling)
891903
upscaling_dx12.skipCreateCalls = true;
892904

893-
auto result = main_dx12.CreateContext(context, desc, memCb);
905+
result = main_dx12.CreateContext(context, desc, memCb);
894906

895907
if (isFg)
896908
fg_dx12.skipCreateCalls = false;
@@ -908,11 +920,11 @@ class FfxApiProxy
908920
ffxReturnCode_t result = FFX_API_RETURN_ERROR;
909921
auto type = FFXStructType::Unknown;
910922

911-
if (contextToType.contains(context))
923+
if (contextToType.contains(*context))
912924
{
913-
type = contextToType[context];
925+
type = contextToType[*context];
914926
LOG_DEBUG("Found context type mapping: {}", magic_enum::enum_name(type));
915-
contextToType.erase(context);
927+
contextToType.erase(*context);
916928
}
917929
else
918930
{

0 commit comments

Comments
 (0)