mirror of
https://github.com/optiscaler/OptiScaler.git
synced 2026-08-28 00:56:48 +00:00
Adjust update point + fix rdr2 crashing
This commit is contained in:
@@ -16,42 +16,33 @@ class AntiLag {
|
||||
AMD::AntiLag2DX12::Context context_dx12 = {};
|
||||
AMD::AntiLag2DX11::Context context_dx11 = {};
|
||||
unsigned int max_fps = 0;
|
||||
|
||||
void init_dx12(ID3D12Device *pDevice) {
|
||||
auto res = AMD::AntiLag2DX12::Initialize(&context_dx12, pDevice);
|
||||
}
|
||||
void init_dx11() {
|
||||
auto res = AMD::AntiLag2DX11::Initialize(&context_dx11);
|
||||
}
|
||||
bool al_available = false;
|
||||
|
||||
public:
|
||||
void init(IUnknown *pDevice) {
|
||||
bool calls_input_sample = false;
|
||||
bool calls_sleep = false;
|
||||
|
||||
inline HRESULT init(IUnknown *pDevice) {
|
||||
if (!context_dx12.m_pAntiLagAPI && !context_dx11.m_pAntiLagAPI) {
|
||||
ID3D12Device* device = nullptr;
|
||||
HRESULT hr = pDevice->QueryInterface(__uuidof(ID3D12Device), reinterpret_cast<void**>(&device));
|
||||
HRESULT init_return = S_FALSE;
|
||||
if (hr == S_OK) {
|
||||
init_dx12(device);
|
||||
init_return = AMD::AntiLag2DX12::Initialize(&context_dx12, device);
|
||||
} else {
|
||||
init_dx11();
|
||||
init_return = AMD::AntiLag2DX11::Initialize(&context_dx11);
|
||||
}
|
||||
al_available = init_return == S_OK;
|
||||
}
|
||||
return 0x2137;
|
||||
}
|
||||
|
||||
void update() {
|
||||
inline HRESULT update() {
|
||||
if (!al_available) return S_FALSE;
|
||||
if (context_dx12.m_pAntiLagAPI)
|
||||
AMD::AntiLag2DX12::Update(&context_dx12, true, max_fps);
|
||||
return AMD::AntiLag2DX12::Update(&context_dx12, true, max_fps);
|
||||
else
|
||||
AMD::AntiLag2DX11::Update(&context_dx11, true, max_fps);
|
||||
}
|
||||
|
||||
void mark_end_of_rendering() {
|
||||
if (context_dx12.m_pAntiLagAPI)
|
||||
AMD::AntiLag2DX12::MarkEndOfFrameRendering(&context_dx12);
|
||||
}
|
||||
|
||||
void present_start(bool interpolated_frame) {
|
||||
if (context_dx12.m_pAntiLagAPI)
|
||||
AMD::AntiLag2DX12::SetFrameGenFrameType(&context_dx12, interpolated_frame);
|
||||
return AMD::AntiLag2DX11::Update(&context_dx11, true, max_fps);
|
||||
}
|
||||
|
||||
void set_fps_limit(unsigned int fps) {
|
||||
|
||||
@@ -18,9 +18,10 @@
|
||||
|
||||
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
|
||||
auto logEnv = std::getenv("NVAPI_LOG");
|
||||
bool force_log = false;
|
||||
switch (fdwReason) {
|
||||
case DLL_PROCESS_ATTACH:
|
||||
if (logEnv && *logEnv == '1')
|
||||
if ((logEnv && *logEnv == '1') || force_log)
|
||||
prepareLogging("nvapi-dummy.log");
|
||||
else
|
||||
prepareLogging(std::nullopt);
|
||||
@@ -45,7 +46,8 @@ namespace nvd {
|
||||
extern "C" {
|
||||
NvAPI_Status __cdecl placeholder() {
|
||||
// return Ok();
|
||||
return Error(NVAPI_NO_IMPLEMENTATION);
|
||||
// return Error(NVAPI_NO_IMPLEMENTATION);
|
||||
return NVAPI_NO_IMPLEMENTATION; // no logging
|
||||
}
|
||||
|
||||
static std::unordered_map<NvU32, void*> registry;
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace nvd {
|
||||
if (displayId == 0) {
|
||||
return Ok();
|
||||
}
|
||||
return Error(NVAPI_NVIDIA_DISPLAY_NOT_FOUND);
|
||||
return Error(NVAPI_END_ENUMERATION);
|
||||
}
|
||||
|
||||
NvAPI_Status __cdecl NvAPI_GetLogicalGPUFromPhysicalGPU(NvPhysicalGpuHandle physicalHandle, NvLogicalGpuHandle* logicalHandle) {
|
||||
@@ -313,18 +313,18 @@ namespace nvd {
|
||||
NvAPI_Status __cdecl NvAPI_D3D_SetLatencyMarker(IUnknown* pDev, NV_LATENCY_MARKER_PARAMS* pSetLatencyMarkerParams) {
|
||||
if (!pDev)
|
||||
return Error();
|
||||
log(std::format("markerType: {}", (unsigned int)pSetLatencyMarkerParams->markerType));
|
||||
log(std::format("markerType: {}, frame id: {}", (unsigned int)pSetLatencyMarkerParams->markerType, (unsigned long long)pSetLatencyMarkerParams->frameID));
|
||||
#if _MSC_VER
|
||||
antilag_ctx.init(pDev);
|
||||
switch (pSetLatencyMarkerParams->markerType) {
|
||||
case SIMULATION_START:
|
||||
antilag_ctx.update();
|
||||
if (antilag_ctx.calls_input_sample || antilag_ctx.calls_sleep) break;
|
||||
log(std::format("AntiLag update called on simulation start with result: {}", antilag_ctx.update()));
|
||||
break;
|
||||
case RENDERSUBMIT_END:
|
||||
antilag_ctx.mark_end_of_rendering();
|
||||
break;
|
||||
case PRESENT_START:
|
||||
antilag_ctx.present_start(false);
|
||||
case INPUT_SAMPLE:
|
||||
if (antilag_ctx.calls_sleep) break;
|
||||
antilag_ctx.calls_input_sample = true;
|
||||
log(std::format("AntiLag update called on input sample with result: {}", antilag_ctx.update()));
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
@@ -336,7 +336,8 @@ namespace nvd {
|
||||
return Error();
|
||||
#if _MSC_VER
|
||||
antilag_ctx.init(pDevice);
|
||||
antilag_ctx.update();
|
||||
antilag_ctx.calls_sleep = true;
|
||||
log(std::format("AntiLag update called on sleep with result: {}", antilag_ctx.update()));
|
||||
#endif
|
||||
return Ok();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user