From d8fd3d75a40d0845e67654eb1da0779c30c7d7c3 Mon Sep 17 00:00:00 2001 From: doodlum <15017472+doodlum@users.noreply.github.com> Date: Fri, 19 Sep 2025 16:31:46 +0100 Subject: [PATCH 1/3] fix(upscaling): more upscaling fixes --- package/Shaders/DistantTree.hlsl | 4 +-- src/Features/Upscaling.cpp | 52 ++++++++++++-------------------- src/Features/Upscaling.h | 4 +-- src/Hooks.cpp | 17 ++++++----- src/Hooks.h | 1 + 5 files changed, 35 insertions(+), 43 deletions(-) diff --git a/package/Shaders/DistantTree.hlsl b/package/Shaders/DistantTree.hlsl index 21640deac2..afa7354306 100644 --- a/package/Shaders/DistantTree.hlsl +++ b/package/Shaders/DistantTree.hlsl @@ -200,7 +200,7 @@ PS_OUTPUT main(PS_INPUT input) discard; } - float alpha = TexDiffuse.Sample(SampDiffuse, input.TexCoord.xy).w; + float alpha = TexDiffuse.SampleBias(SampDiffuse, input.TexCoord.xy, SharedData::MipBias).w; if ((alpha - AlphaTestRefRS) < 0) { discard; @@ -209,7 +209,7 @@ PS_OUTPUT main(PS_INPUT input) psout.Diffuse.xyz = input.Depth.xxx / input.Depth.yyy; psout.Diffuse.w = 0; # else - float4 baseColor = TexDiffuse.Sample(SampDiffuse, input.TexCoord.xy); + float4 baseColor = TexDiffuse.SampleBias(SampDiffuse, input.TexCoord.xy, SharedData::MipBias); if ((baseColor.w - AlphaTestRefRS) < 0) { discard; diff --git a/src/Features/Upscaling.cpp b/src/Features/Upscaling.cpp index 97fffc4f71..c148175b00 100644 --- a/src/Features/Upscaling.cpp +++ b/src/Features/Upscaling.cpp @@ -646,19 +646,10 @@ void GetJitterOffset(float* outX, float* outY, int32_t index, int32_t phaseCount *outY = y; } -void Upscaling::ConfigureUpscaling(RE::BSGraphics::State* a_viewport) +void Upscaling::ConfigureTAA() { auto upscaleMethod = GetUpscaleMethod(); - // Delete or create resources as necessary - CheckResources(upscaleMethod); - - // The game defaults this to a non-zero value - if (!globals::game::isVR) { - auto fDRClampOffset = RE::GetINISetting("fDRClampOffset:Display"); - fDRClampOffset->data.f = 0.0f; - } - auto imageSpaceManager = RE::ImageSpaceManager::GetSingleton(); GET_INSTANCE_MEMBER(BSImagespaceShaderISTemporalAA, imageSpaceManager); @@ -668,6 +659,20 @@ void Upscaling::ConfigureUpscaling(RE::BSGraphics::State* a_viewport) // Force enable TAA if needed BSImagespaceShaderISTemporalAA->taaEnabled = upscaleMethod != UpscaleMethod::kNONE; +} + +void Upscaling::ConfigureUpscaling(RE::BSGraphics::State* a_viewport) +{ + auto upscaleMethod = GetUpscaleMethod(); + + // Delete or create resources as necessary + CheckResources(upscaleMethod); + + // The game defaults this to a non-zero value + if (!globals::game::isVR) { + auto fDRClampOffset = RE::GetINISetting("fDRClampOffset:Display"); + fDRClampOffset->data.f = 0.0f; + } // Cache original TAA values for UI projectionPosScaleX = a_viewport->projectionPosScaleX; @@ -1037,18 +1042,7 @@ void Upscaling::CopySharedD3D12Resources() // Not required by XeSS if (upscaleMethod == UpscaleMethod::kFSR || (d3d12SwapChainActive && settings.frameGenerationMode && upscaleMethod != UpscaleMethod::kXESS)) { auto& motionVector = renderer->GetRuntimeData().renderTargets[RE::RENDER_TARGETS::kMOTION_VECTOR]; - - // Copy only the dynamic resolution area - auto renderSize = Util::ConvertToDynamic(globals::state->screenSize); - D3D11_BOX srcBox = {}; - srcBox.left = 0; - srcBox.top = 0; - srcBox.front = 0; - srcBox.right = (UINT)renderSize.x; - srcBox.bottom = (UINT)renderSize.y; - srcBox.back = 1; - - context->CopySubresourceRegion(motionVectorBufferShared12->resource11, 0, 0, 0, 0, motionVector.texture, 0, &srcBox); + context->CopyResource(motionVectorBufferShared12->resource11, motionVector.texture); } if (upscaleMethod == UpscaleMethod::kFSR || upscaleMethod == UpscaleMethod::kXESS || d3d12SwapChainActive && settings.frameGenerationMode) { @@ -1428,17 +1422,10 @@ void Upscaling::Upscale() if (upscaleMethod == UpscaleMethod::kDLSS) streamline.Upscale(main.texture, reactiveMaskTexture->resource.get(), transparencyCompositionMaskTexture->resource.get(), motionVectorCopyTexture->resource.get(), sl::DLSSPreset::ePresetK); else { - // Copy input color texture to shared D3D12 resource (only dynamic resolution area) auto renderSize = Util::ConvertToDynamic(globals::state->screenSize); - D3D11_BOX srcBox = {}; - srcBox.left = 0; - srcBox.top = 0; - srcBox.front = 0; - srcBox.right = (UINT)renderSize.x; - srcBox.bottom = (UINT)renderSize.y; - srcBox.back = 1; - - context->CopySubresourceRegion(inputColorBufferShared12->resource11, 0, 0, 0, 0, main.texture, 0, &srcBox); + + // Copy input color texture to shared D3D12 resource + context->CopyResource(inputColorBufferShared12->resource11, main.texture); // Wait for D3D11 to finish winrt::com_ptr d3d11Context4; @@ -1622,6 +1609,7 @@ void Upscaling::UpscaleDepth() void Upscaling::Main_UpdateJitter::thunk(RE::BSGraphics::State* a_state) { + globals::features::upscaling.ConfigureTAA(); func(a_state); globals::features::upscaling.ConfigureUpscaling(a_state); } diff --git a/src/Features/Upscaling.h b/src/Features/Upscaling.h index 22fb4914e1..c32464683b 100644 --- a/src/Features/Upscaling.h +++ b/src/Features/Upscaling.h @@ -127,10 +127,10 @@ struct Upscaling : Feature winrt::com_ptr upscaleDepthStencilState; winrt::com_ptr upscaleBlendState; winrt::com_ptr upscaleRasterizerState; - + + void ConfigureTAA(); void ConfigureUpscaling(RE::BSGraphics::State* a_state); void Upscale(); - void ApplyNISSharpening(); // D3D11 textures Texture2D* reactiveMaskTexture = nullptr; diff --git a/src/Hooks.cpp b/src/Hooks.cpp index c881728e97..fa10cc7597 100644 --- a/src/Hooks.cpp +++ b/src/Hooks.cpp @@ -868,13 +868,6 @@ namespace Hooks */ void Install() { - if (!globals::features::upscaling.loaded) { - logger::info("Hooking D3D11CreateDeviceAndSwapChain"); - *(uintptr_t*)&ptrD3D11CreateDeviceAndSwapChain = SKSE::PatchIAT(hk_D3D11CreateDeviceAndSwapChain, "d3d11.dll", "D3D11CreateDeviceAndSwapChain"); - } - - *(uintptr_t*)&ptrCreateDXGIFactory = SKSE::PatchIAT(hk_CreateDXGIFactory, "dxgi.dll", !REL::Module::IsVR() ? "CreateDXGIFactory" : "CreateDXGIFactory1"); - if (!REL::Module::IsVR()) { logger::info("Hooking BSImageSpace::Init::IBLF"); stl::detour_thunk(REL::RelocationID(100480, 107198)); @@ -978,4 +971,14 @@ namespace Hooks stl::write_thunk_call(REL::RelocationID(100565, 107300).address() + REL::Relocate(0x523, 0xB0E, 0x5FE)); } + + void InstallEarlyHooks() + { + if (!globals::features::upscaling.loaded) { + logger::info("Hooking D3D11CreateDeviceAndSwapChain"); + *(uintptr_t*)&ptrD3D11CreateDeviceAndSwapChain = SKSE::PatchIAT(hk_D3D11CreateDeviceAndSwapChain, "d3d11.dll", "D3D11CreateDeviceAndSwapChain"); + } + + *(uintptr_t*)&ptrCreateDXGIFactory = SKSE::PatchIAT(hk_CreateDXGIFactory, "dxgi.dll", !REL::Module::IsVR() ? "CreateDXGIFactory" : "CreateDXGIFactory1"); + } } \ No newline at end of file diff --git a/src/Hooks.h b/src/Hooks.h index f22fd880b6..335a7df7d8 100644 --- a/src/Hooks.h +++ b/src/Hooks.h @@ -20,4 +20,5 @@ namespace Hooks }; void Install(); + void InstallEarlyHooks(); } From 32a98b68541d9daecfd1b3804c9d1e918b4df015 Mon Sep 17 00:00:00 2001 From: doodlum <15017472+doodlum@users.noreply.github.com> Date: Fri, 19 Sep 2025 16:37:01 +0100 Subject: [PATCH 2/3] chore: work --- src/Hooks.cpp | 1 + src/XSEPlugin.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/src/Hooks.cpp b/src/Hooks.cpp index fa10cc7597..72bd0858ea 100644 --- a/src/Hooks.cpp +++ b/src/Hooks.cpp @@ -979,6 +979,7 @@ namespace Hooks *(uintptr_t*)&ptrD3D11CreateDeviceAndSwapChain = SKSE::PatchIAT(hk_D3D11CreateDeviceAndSwapChain, "d3d11.dll", "D3D11CreateDeviceAndSwapChain"); } + logger::info("Hooking CreateDXGIFactory"); *(uintptr_t*)&ptrCreateDXGIFactory = SKSE::PatchIAT(hk_CreateDXGIFactory, "dxgi.dll", !REL::Module::IsVR() ? "CreateDXGIFactory" : "CreateDXGIFactory1"); } } \ No newline at end of file diff --git a/src/XSEPlugin.cpp b/src/XSEPlugin.cpp index 6ade711af4..522c58a167 100644 --- a/src/XSEPlugin.cpp +++ b/src/XSEPlugin.cpp @@ -196,6 +196,7 @@ bool Load() } if (errors.empty()) { + Hooks::InstallEarlyHooks(); logger::info("Calling feature Load methods"); for (auto* feature : Feature::GetFeatureList()) { if (feature->loaded) { From 4c87030d9ff0700464539d7d44abc0c38fd7c27a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 19 Sep 2025 15:39:55 +0000 Subject: [PATCH 3/3] =?UTF-8?q?style:=20=F0=9F=8E=A8=20apply=20pre-commit.?= =?UTF-8?q?ci=20formatting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Automated formatting by clang-format, prettier, and other hooks. See https://pre-commit.ci for details. --- src/Features/Upscaling.cpp | 4 ++-- src/Features/Upscaling.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Features/Upscaling.cpp b/src/Features/Upscaling.cpp index c148175b00..7cceffec8d 100644 --- a/src/Features/Upscaling.cpp +++ b/src/Features/Upscaling.cpp @@ -1423,8 +1423,8 @@ void Upscaling::Upscale() streamline.Upscale(main.texture, reactiveMaskTexture->resource.get(), transparencyCompositionMaskTexture->resource.get(), motionVectorCopyTexture->resource.get(), sl::DLSSPreset::ePresetK); else { auto renderSize = Util::ConvertToDynamic(globals::state->screenSize); - - // Copy input color texture to shared D3D12 resource + + // Copy input color texture to shared D3D12 resource context->CopyResource(inputColorBufferShared12->resource11, main.texture); // Wait for D3D11 to finish diff --git a/src/Features/Upscaling.h b/src/Features/Upscaling.h index c32464683b..975f91df3f 100644 --- a/src/Features/Upscaling.h +++ b/src/Features/Upscaling.h @@ -127,7 +127,7 @@ struct Upscaling : Feature winrt::com_ptr upscaleDepthStencilState; winrt::com_ptr upscaleBlendState; winrt::com_ptr upscaleRasterizerState; - + void ConfigureTAA(); void ConfigureUpscaling(RE::BSGraphics::State* a_state); void Upscale();