Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/Deferred.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "Deferred.h"

#include <DDSTextureLoader.h>

#include "ShaderCache.h"
#include "State.h"
#include "TruePBR.h"
Expand Down Expand Up @@ -175,6 +177,13 @@ void Deferred::SetupResources()
prevDiffuseAmbientTexture->CreateSRV(srvDesc);
prevDiffuseAmbientTexture->CreateUAV(uavDesc);
}

// Testing code for imagespace shaders
{
auto device = globals::d3d::device;
auto context = globals::d3d::context;
DirectX::CreateDDSTextureFromFile(device, context, L"Data\\Shaders\\LUT.dds", nullptr, lutTexture.put());
}
Comment on lines +180 to +186
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add error handling for LUT file loading.

The hardcoded path and lack of error handling could cause issues if the LUT file doesn't exist or fails to load.

Consider adding proper error handling:

 // Testing code for imagespace shaders
 {
     auto device = globals::d3d::device;
     auto context = globals::d3d::context;
-    DirectX::CreateDDSTextureFromFile(device, context, L"Data\\Shaders\\LUT.dds", nullptr, lutTexture.put());
+    auto hr = DirectX::CreateDDSTextureFromFile(device, context, L"Data\\Shaders\\LUT.dds", nullptr, lutTexture.put());
+    if (FAILED(hr)) {
+        logger::warn("Failed to load LUT texture: Data\\Shaders\\LUT.dds (HRESULT: 0x{:08X})", static_cast<uint32_t>(hr));
+        lutTexture = nullptr;
+    }
 }
🤖 Prompt for AI Agents
In src/Deferred.cpp around lines 180 to 186, the code loads a LUT texture from a
hardcoded path without checking for errors, which can cause issues if the file
is missing or fails to load. Modify the code to capture the HRESULT returned by
CreateDDSTextureFromFile and check if the operation succeeded. If it fails, log
an appropriate error message or handle the failure gracefully to prevent silent
errors.

}

void Deferred::CopyShadowData()
Expand Down Expand Up @@ -716,6 +725,14 @@ ID3D11ComputeShader* Deferred::GetComputeMainCompositeInterior()
return mainCompositeInteriorCS;
}

// Testing code for imagespace shaders
void Deferred::BindLUT()
{
auto view = lutTexture.get();
if (view)
globals::d3d::context->PSSetShaderResources(100, 1, &view);
}

void Deferred::Hooks::Main_RenderShadowMaps::thunk()
{
func();
Expand Down
26 changes: 26 additions & 0 deletions src/Deferred.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ class Deferred
Buffer* perShadow = nullptr;
ID3D11ShaderResourceView* shadowView = nullptr;

winrt::com_ptr<ID3D11ShaderResourceView> lutTexture = nullptr;
void BindLUT();

struct Hooks
{
struct Main_RenderShadowMaps
Expand Down Expand Up @@ -127,6 +130,26 @@ class Deferred
static inline REL::Relocation<decltype(thunk)> func;
};

struct BSImagespaceShaderHDRTonemapBlendCinematic_SetupTechnique
{
static void thunk(RE::BSShader* a_shader, RE::BSShaderMaterial* a_material)
{
GetSingleton()->BindLUT();
func(a_shader, a_material);
}
static inline REL::Relocation<decltype(thunk)> func;
};

struct BSImagespaceShaderHDRTonemapBlendCinematicFade_SetupTechnique
{
static void thunk(RE::BSShader* a_shader, RE::BSShaderMaterial* a_material)
{
GetSingleton()->BindLUT();
func(a_shader, a_material);
}
static inline REL::Relocation<decltype(thunk)> func;
};

static void Install()
{
stl::write_vfunc<0x35, BSCubeMapCamera_RenderCubemap>(RE::VTABLE_BSCubeMapCamera[0]);
Expand All @@ -142,6 +165,9 @@ class Deferred
stl::write_thunk_call<BSShaderAccumulator_FirstPerson_BlendedDecals>(REL::RelocationID(99943, 106588).address() + REL::Relocate(0xFE, 0xF4));
stl::write_thunk_call<BSShaderAccumulator_ShadowMapOrMask_BlendedDecals>(REL::RelocationID(99947, 106592).address() + 0x107);

stl::write_vfunc<0x2, BSImagespaceShaderHDRTonemapBlendCinematic_SetupTechnique>(RE::VTABLE_BSImagespaceShaderHDRTonemapBlendCinematic[0]);
stl::write_vfunc<0x2, BSImagespaceShaderHDRTonemapBlendCinematicFade_SetupTechnique>(RE::VTABLE_BSImagespaceShaderHDRTonemapBlendCinematicFade[0]);

logger::info("[Deferred] Installed hooks");
}
};
Expand Down
Loading