From e7b269b08209d2be56222037d7478876d01148cd Mon Sep 17 00:00:00 2001 From: Justin Marshall Date: Fri, 22 May 2026 19:26:48 -0700 Subject: [PATCH] Fixed editor issues caused by DLSS and framegen integration. --- neo/engine/opengl/gl_d3d12shim.cpp | 102 ++++++++++++++++++++++------- 1 file changed, 79 insertions(+), 23 deletions(-) diff --git a/neo/engine/opengl/gl_d3d12shim.cpp b/neo/engine/opengl/gl_d3d12shim.cpp index 9337330c..ec8e761c 100644 --- a/neo/engine/opengl/gl_d3d12shim.cpp +++ b/neo/engine/opengl/gl_d3d12shim.cpp @@ -6881,6 +6881,50 @@ static bool QD3D12_IsEmbeddedEditorWindow(const QD3D12Window& w) return w.hwnd && GetParent(w.hwnd) != nullptr; } +static bool QD3D12_GetWindowClassName(const QD3D12Window& w, char* className, int classNameBytes) +{ + if (!w.hwnd || !className || classNameBytes <= 0) + return false; + + className[0] = '\0'; + return GetClassNameA(w.hwnd, className, classNameBytes) > 0; +} + +static bool QD3D12_IsRadiantCameraWindow(const QD3D12Window& w) +{ + char className[64] = {}; + if (!QD3D12_GetWindowClassName(w, className, sizeof(className))) + return false; + return strcmp(className, "QCamera") == 0 || + strcmp(className, "Q3DFXCamera") == 0; +} + +static bool QD3D12_IsGameWindow(const QD3D12Window& w) +{ + char className[64] = {}; + if (!QD3D12_GetWindowClassName(w, className, sizeof(className))) + return false; + return strcmp(className, "DOOM3") == 0; +} + +static bool QD3D12_IsFullRenderEmbeddedWindow(const QD3D12Window& w) +{ + return QD3D12_IsRadiantCameraWindow(w) || + QD3D12_IsGameWindow(w); +} + +static bool QD3D12_AllowsGamePresentationFeatures(const QD3D12Window& w) +{ + return !QD3D12_IsEmbeddedEditorWindow(w) || + QD3D12_IsGameWindow(w); +} + +static bool QD3D12_IsNativeEditorPreviewWindow(const QD3D12Window& w) +{ + return QD3D12_IsEmbeddedEditorWindow(w) && + !QD3D12_IsFullRenderEmbeddedWindow(w); +} + #if defined(QD3D12_ENABLE_STREAMLINE) struct QD3D12StreamlineState { @@ -7208,7 +7252,7 @@ static bool QD3D12_WantsDLSSRayReconstruction() static bool QD3D12_CanUseDLSSRayReconstructionForLighting(const QD3D12Window& w) { return !w.isPbuffer && - !QD3D12_IsEmbeddedEditorWindow(w) && + QD3D12_AllowsGamePresentationFeatures(w) && g_gl.cameraState.valid && QD3D12_WantsDLSSRayReconstruction(); } @@ -7295,7 +7339,7 @@ static bool QD3D12_WantsDLSSFrameGeneration(const QD3D12Window& w) { return !w.isPbuffer && - !QD3D12_IsEmbeddedEditorWindow(w) && + QD3D12_AllowsGamePresentationFeatures(w) && g_gl.cameraState.valid && g_qd3d12Sl.deviceBound && g_qd3d12Sl.dlssGSupported && @@ -7312,7 +7356,7 @@ static uint32_t QD3D12_GetDLSSFrameGenerationEligibilityMask(const QD3D12Window& uint32_t mask = 0; if (w.isPbuffer) mask |= 1u << 0; - if (QD3D12_IsEmbeddedEditorWindow(w)) + if (!QD3D12_AllowsGamePresentationFeatures(w)) mask |= 1u << 8; if (!g_gl.cameraState.valid) mask |= 1u << 1; @@ -8401,8 +8445,9 @@ static void QD3D12_RunUpscalerOrBlit(QD3D12Window& w) QD3D12_UpdateCameraInfoFromCurrentMatrices(); - const bool haveTemporalCameraInputs = (!w.isPbuffer) && g_gl.cameraState.valid; - const bool useLightingUpscaleInput = (!w.isPbuffer) && QD3D12_UseLightingTextureAsUpscaleInput(w); + const bool allowGamePresentationFeatures = QD3D12_AllowsGamePresentationFeatures(w); + const bool haveTemporalCameraInputs = (!w.isPbuffer) && allowGamePresentationFeatures && g_gl.cameraState.valid; + const bool useLightingUpscaleInput = (!w.isPbuffer) && allowGamePresentationFeatures && QD3D12_UseLightingTextureAsUpscaleInput(w); ID3D12Resource* upscaleInputResource = w.sceneColorBuffers[w.frameIndex].Get(); D3D12_GPU_DESCRIPTOR_HANDLE upscaleInputSrv = w.sceneColorSrvGpu[w.frameIndex]; @@ -10425,7 +10470,8 @@ void QD3D12_BeginFrame() QD3D12_WaitForFrame(w.frameIndex); QD3D12_ResetUploadRing(); - g_gl.framePhase = QD3D12_FRAME_LOW_RES; + const bool nativeEditorPreviewWindow = QD3D12_IsNativeEditorPreviewWindow(w); + g_gl.framePhase = nativeEditorPreviewWindow ? QD3D12_FRAME_NATIVE_POST_UPSCALE : QD3D12_FRAME_LOW_RES; g_gl.sceneResolvedThisFrame = false; g_gl.gbufferResolvedThisFrame = false; g_gl.raytracedLightingReadyThisFrame = false; @@ -10438,16 +10484,19 @@ void QD3D12_BeginFrame() QD3D12_BindTargetsForCurrentPhase(w); - const float normalClear[4] = { 0.0f, 0.0f, 1.0f, 0.5f }; - const float positionClear[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; - const float velocityClear[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; - const float emissiveClear[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; - const float specularClear[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; - g_gl.cmdList->ClearRenderTargetView(CurrentNormalRTV(), normalClear, 0, nullptr); - g_gl.cmdList->ClearRenderTargetView(CurrentPositionRTV(), positionClear, 0, nullptr); - g_gl.cmdList->ClearRenderTargetView(CurrentVelocityRTV(), velocityClear, 0, nullptr); - g_gl.cmdList->ClearRenderTargetView(CurrentEmissiveRTV(), emissiveClear, 0, nullptr); - g_gl.cmdList->ClearRenderTargetView(CurrentSpecularRTV(), specularClear, 0, nullptr); + if (!nativeEditorPreviewWindow) + { + const float normalClear[4] = { 0.0f, 0.0f, 1.0f, 0.5f }; + const float positionClear[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + const float velocityClear[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + const float emissiveClear[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + const float specularClear[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + g_gl.cmdList->ClearRenderTargetView(CurrentNormalRTV(), normalClear, 0, nullptr); + g_gl.cmdList->ClearRenderTargetView(CurrentPositionRTV(), positionClear, 0, nullptr); + g_gl.cmdList->ClearRenderTargetView(CurrentVelocityRTV(), velocityClear, 0, nullptr); + g_gl.cmdList->ClearRenderTargetView(CurrentEmissiveRTV(), emissiveClear, 0, nullptr); + g_gl.cmdList->ClearRenderTargetView(CurrentSpecularRTV(), specularClear, 0, nullptr); + } g_gl.frameOpen = true; g_gl.frameOwner = &w; @@ -10472,7 +10521,9 @@ void QD3D12_EndFrame() QD3D12_FlushQueuedBatches(); - if (!g_gl.sceneResolvedThisFrame) + const bool nativeEditorPreviewWindow = QD3D12_IsNativeEditorPreviewWindow(w); + const bool allowGamePresentationFeatures = QD3D12_AllowsGamePresentationFeatures(w); + if (!nativeEditorPreviewWindow && !g_gl.sceneResolvedThisFrame) { QD3D12_ResolveGBufferForCurrentFrame(w); if (!g_gl.raytracedLightingReadyThisFrame) @@ -10491,11 +10542,13 @@ void QD3D12_EndFrame() // Do the nonblocking mipchain handoff after the frame's draws/blit are recorded. // This keeps first-use texture uploads to mip 0 and spreads completed mip uploads. - QD3D12_ProcessCompletedTextureMipJobs(2); + if (allowGamePresentationFeatures) + QD3D12_ProcessCompletedTextureMipJobs(1); QD3D12_TransitionResource(g_gl.cmdList.Get(), w.backBuffers[w.frameIndex].Get(), w.backBufferState[w.frameIndex], D3D12_RESOURCE_STATE_PRESENT); #if defined(QD3D12_ENABLE_STREAMLINE) - QD3D12_ConfigureDLSSFrameGeneration(w, nullptr); + if (allowGamePresentationFeatures) + QD3D12_ConfigureDLSSFrameGeneration(w, nullptr); #endif QD3D12_CHECK(g_gl.cmdList->Close()); @@ -10513,7 +10566,7 @@ void QD3D12_EndFrame() g_gl.frameOpen = false; g_gl.frameOwner = nullptr; - if (!w.isPbuffer) + if (!w.isPbuffer && allowGamePresentationFeatures) QD3D12_CommitMotionHistoryForFrame(); g_gl.framePhase = QD3D12_FRAME_LOW_RES; @@ -10532,7 +10585,8 @@ void QD3D12_Present() { QD3D12_CHECK(w.swapChain->Present(0, DXGI_PRESENT_ALLOW_TEARING)); #if defined(QD3D12_ENABLE_STREAMLINE) - QD3D12_LogDLSSFrameGenerationPresentResult(); + if (QD3D12_AllowsGamePresentationFeatures(w)) + QD3D12_LogDLSSFrameGenerationPresentResult(); #endif } @@ -11486,7 +11540,7 @@ static void QD3D12_ProcessCompletedTextureMipJobs(UINT maxUploads) } UINT uploads = 0; - const UINT64 uploadBudgetBytes = 8ull * 1024ull * 1024ull; + const UINT64 uploadBudgetBytes = 2ull * 1024ull * 1024ull; UINT64 uploadedBytes = 0; for (auto& kv : g_gl.textures) @@ -12948,7 +13002,7 @@ void APIENTRY glFinish(void) if (!g_gl.frameOpen && g_gl.queuedBatches.empty()) { - if (!QD3D12_IsEmbeddedEditorWindow(*owner)) + if (QD3D12_AllowsGamePresentationFeatures(*owner)) QD3D12_WaitForGPU(); return; } @@ -17246,6 +17300,8 @@ void glLightScene(glRaytracingSceneHandle_t sceneHandle) auto* window = g_currentWindow; if (!window) return; + if (QD3D12_IsNativeEditorPreviewWindow(*window)) + return; const int width = (int)window->renderWidth; const int height = (int)window->renderHeight;