jp7677 / dxvk-nvapi

Alternative NVAPI implementation on top of DXVK.
MIT License
353 stars 32 forks source link

nvapi: Guard against null device in Reflex calls #170

Closed Saancreed closed 3 months ago

Saancreed commented 3 months ago

Fixes a crash in Horizon Forbidden West.

esullivan-nvidia commented 3 months ago

Maybe it would be better to have the Reflex NVAPI entry points return NVAPI_INVALID_ARGUMENT if the device is null?

Saancreed commented 3 months ago

Maybe it would be better to have the Reflex NVAPI entry points return NVAPI_INVALID_ARGUMENT if the device is null?

Yeah, good point. I intend to also check how native NVAPI behaves on Windows here first but something like NVAPI_INVALID_ARGUMENT or NVAPI_INVALID_POINTER sounds likely to be the case.

Saancreed commented 3 months ago

Native Windows NVAPI returns -5 / NVAPI_INVALID_ARGUMENT for NvAPI_D3D_* Reflex entry points accepting device as IUnknown* and -14 / NVAPI_INVALID_POINTER for NvAPI_D3D12_* Reflex entry points accepting ID3D12CommandQueue*. I updated each relevant function to behave like this and added tests to verify this behavior.

I've kept the null check in GetLowLatencyDevice for general robustness, even though it shouldn't be needed anymore. We can probably drop that commit though.

jp7677 commented 3 months ago

Reference: https://github.com/ValveSoftware/Proton/issues/7590