From cad643187985adce2d62ce2e34be66cf094d5b91 Mon Sep 17 00:00:00 2001 From: BramTeurlings Date: Wed, 21 Feb 2024 12:50:40 +0100 Subject: [PATCH 1/5] Code convention cleaning Removed find_closest method Removed unused overlay draw methods Added README.md --- gamebridge_reshade/README.md | 22 +++- gamebridge_reshade/src/directx10weaver.cpp | 74 ++++-------- gamebridge_reshade/src/directx10weaver.h | 56 +++++---- gamebridge_reshade/src/directx11weaver.cpp | 75 ++++-------- gamebridge_reshade/src/directx11weaver.h | 61 ++++++---- gamebridge_reshade/src/directx12weaver.cpp | 130 ++++++--------------- gamebridge_reshade/src/directx12weaver.h | 67 ++++++----- gamebridge_reshade/src/directx9weaver.cpp | 75 ++++-------- gamebridge_reshade/src/directx9weaver.h | 56 +++++---- gamebridge_reshade/src/dllmain.cpp | 36 ++---- gamebridge_reshade/src/hotkey.cpp | 43 +++---- gamebridge_reshade/src/hotkey.h | 11 +- gamebridge_reshade/src/hotkeyManager.h | 5 +- gamebridge_reshade/src/hotkeymanager.cpp | 43 ++++--- gamebridge_reshade/src/igraphicsapi.h | 59 +++++++--- gamebridge_reshade/src/pch.h | 5 +- 16 files changed, 366 insertions(+), 452 deletions(-) diff --git a/gamebridge_reshade/README.md b/gamebridge_reshade/README.md index 056d0d8..020ea44 100644 --- a/gamebridge_reshade/README.md +++ b/gamebridge_reshade/README.md @@ -1 +1,21 @@ -# SimulatedRealityInjector \ No newline at end of file +# SimulatedRealityInjector + +## Summary +Implements the SR SDK into ReShade to allow for conversion of SBS content to be turned into 3D on "Simulated Realty" displays from any brand or OEM. + +## Installation +Download the latest binary release from the tags section on GitHub and follow the installation instructions hosted here:
+https://docs.google.com/document/d/1ZlB1LhWfolDzp-nI4ojzc0AbdSv05lwYqka7FpztK8Y/edit?usp=sharing + +## Building +1. Install the Simulated Reality SDK: www.srappstore.com/develop
(Alternatively you can download a supported SDK version directly from the Google Docs installation instructions above) +2. Clone the repository +3. Build the project with Cmake, no additional Cmake arguments are required + +## Code conventions +A link to the repository's code conventions can be found here:
+https://docs.google.com/document/d/1mYjsWdWhKdVjgc639hNoqFpKtnVTbTRmOcpre0uQEb8/edit?usp=sharing + +## Contact & Contributions +If you have a question or want to make a contribution, please make a pull request or let us know through Discord.
+https://discord.gg/K46jgbzwDa diff --git a/gamebridge_reshade/src/directx10weaver.cpp b/gamebridge_reshade/src/directx10weaver.cpp index 1e4a922..08b3f5d 100644 --- a/gamebridge_reshade/src/directx10weaver.cpp +++ b/gamebridge_reshade/src/directx10weaver.cpp @@ -8,13 +8,12 @@ #include "directx10weaver.h" DirectX10Weaver::DirectX10Weaver(SR::SRContext* context) { - //Set context here. + // Set context here. sr_context = context; weaving_enabled = true; } -bool DirectX10Weaver::create_effect_copy_buffer(const reshade::api::resource_desc& effect_resource_desc) -{ +bool DirectX10Weaver::create_effect_copy_buffer(const reshade::api::resource_desc& effect_resource_desc) { reshade::api::resource_desc desc = effect_resource_desc; desc.type = reshade::api::resource_type::texture_2d; desc.heap = reshade::api::memory_heap::gpu_only; @@ -68,17 +67,16 @@ bool DirectX10Weaver::init_weaver(reshade::api::effect_runtime* runtime, reshade try { weaver = new SR::PredictingDX10Weaver(*sr_context, dev, desc.texture.width, desc.texture.height, (HWND)runtime->get_hwnd()); - weaver->setInputFrameBuffer((ID3D10ShaderResourceView*)rtv.handle); //resourceview of the buffer + weaver->setInputFrameBuffer((ID3D10ShaderResourceView*)rtv.handle); // Resourceview of the buffer sr_context->initialize(); reshade::log_message(reshade::log_level::info, "Initialized weaver"); // Set mode to latency in frames by default. - set_latency_mode(LatencyModes::framerateAdaptive); - set_latency_framerate_adaptive(DEFAULT_WEAVER_LATENCY); - std::string latencyLog = "Current latency mode set to: STATIC " + std::to_string(DEFAULT_WEAVER_LATENCY) + " Microseconds"; - reshade::log_message(reshade::log_level::info, latencyLog.c_str()); + set_latency_frametime_adaptive(g_default_weaver_latency); + std::string latency_log = "Current latency mode set to: STATIC " + std::to_string(g_default_weaver_latency) + " Microseconds"; + reshade::log_message(reshade::log_level::info, latency_log.c_str()); } - catch (std::exception e) { + catch (std::exception &e) { reshade::log_message(reshade::log_level::info, e.what()); return false; } @@ -97,8 +95,8 @@ void DirectX10Weaver::draw_status_overlay(reshade::api::effect_runtime *runtime) // Log the latency mode std::string latencyModeDisplay = "Latency mode: "; - if(current_latency_mode == LatencyModes::framerateAdaptive) { - latencyModeDisplay += "IN " + std::to_string(lastLatencyFrameTimeSet) + " MICROSECONDS"; + if (current_latency_mode == LatencyModes::FRAMERATE_ADAPTIVE) { + latencyModeDisplay += "IN " + std::to_string(last_latency_frame_time_set) + " MICROSECONDS"; } else { latencyModeDisplay += "IN " + std::to_string(runtime->get_back_buffer_count()) + " FRAMES"; @@ -110,32 +108,6 @@ void DirectX10Weaver::draw_status_overlay(reshade::api::effect_runtime *runtime) ImGui::TextUnformatted(s.c_str()); } -void DirectX10Weaver::draw_debug_overlay(reshade::api::effect_runtime* runtime) -{ - ImGui::TextUnformatted("Some text"); - - if (ImGui::Button("Press me to open an additional popup window")) - g_popup_window_visible = true; - - if (g_popup_window_visible) - { - ImGui::Begin("Popup", &g_popup_window_visible); - ImGui::TextUnformatted("Some other text"); - ImGui::End(); - } -} - -void DirectX10Weaver::draw_sr_settings_overlay(reshade::api::effect_runtime* runtime) -{ - ImGui::Checkbox("Turn on SR", &g_popup_window_visible); - ImGui::SliderFloat("View Separation", &view_separation, -50.f, 50.f); - ImGui::SliderFloat("Vertical Shift", &vertical_shift, -50.f, 50.f); -} - -void DirectX10Weaver::draw_settings_overlay(reshade::api::effect_runtime* runtime) -{ -} - void DirectX10Weaver::on_reshade_finish_effects(reshade::api::effect_runtime* runtime, reshade::api::command_list* cmd_list, reshade::api::resource_view rtv, reshade::api::resource_view rtv_srgb) { reshade::api::resource_view chosen_rtv; @@ -150,11 +122,11 @@ void DirectX10Weaver::on_reshade_finish_effects(reshade::api::effect_runtime* ru if (weaver_initialized) { // Check if we need to set the latency in frames. - if(get_latency_mode() == LatencyModes::latencyInFramesAutomatic) { + if (get_latency_mode() == LatencyModes::LATENCY_IN_FRAMES_AUTOMATIC) { weaver->setLatencyInFrames(runtime->get_back_buffer_count()); // Set the latency with which the weaver should do prediction. } - //Check texture size + // Check texture size if (desc.texture.width != effect_frame_copy_x || desc.texture.height != effect_frame_copy_y) { // Update current buffer format current_buffer_format = desc.texture.format; @@ -168,7 +140,7 @@ void DirectX10Weaver::on_reshade_finish_effects(reshade::api::effect_runtime* ru use_srgb_rtv = false; } - //TODO Might have to get the buffer from the create_effect_copy_buffer function and only swap them when creation suceeds + // Todo: Might have to get the buffer from the create_effect_copy_buffer function and only swap them when creation suceeds d3d10_device->destroy_resource(effect_frame_copy); d3d10_device->destroy_resource_view(effect_frame_copy_srv); if (!create_effect_copy_buffer(desc) && !resize_buffer_failed) { @@ -214,30 +186,30 @@ void DirectX10Weaver::on_init_effect_runtime(reshade::api::effect_runtime* runti d3d10_device = runtime->get_device(); } -void DirectX10Weaver::do_weave(bool doWeave) +void DirectX10Weaver::do_weave(bool do_weave) { - weaving_enabled = doWeave; + weaving_enabled = do_weave; } -bool DirectX10Weaver::set_latency_in_frames(int32_t numberOfFrames) { +bool DirectX10Weaver::set_latency_in_frames(int32_t number_of_frames) { if (weaver_initialized) { - if (numberOfFrames < 0) { - set_latency_mode(LatencyModes::latencyInFramesAutomatic); + if (number_of_frames < 0) { + set_latency_mode(LatencyModes::LATENCY_IN_FRAMES_AUTOMATIC); } else { - set_latency_mode(LatencyModes::latencyInFrames); - weaver->setLatencyInFrames(numberOfFrames); + set_latency_mode(LatencyModes::LATENCY_IN_FRAMES); + weaver->setLatencyInFrames(number_of_frames); } return true; } return false; } -bool DirectX10Weaver::set_latency_framerate_adaptive(uint32_t frametimeInMicroseconds) { +bool DirectX10Weaver::set_latency_frametime_adaptive(uint32_t frametime_in_microseconds) { if (weaver_initialized) { - set_latency_mode(LatencyModes::framerateAdaptive); - weaver->setLatency(frametimeInMicroseconds); - lastLatencyFrameTimeSet = frametimeInMicroseconds; + set_latency_mode(LatencyModes::FRAMERATE_ADAPTIVE); + weaver->setLatency(frametime_in_microseconds); + last_latency_frame_time_set = frametime_in_microseconds; return true; } return false; diff --git a/gamebridge_reshade/src/directx10weaver.h b/gamebridge_reshade/src/directx10weaver.h index 8c7306d..6d713ef 100644 --- a/gamebridge_reshade/src/directx10weaver.h +++ b/gamebridge_reshade/src/directx10weaver.h @@ -6,58 +6,68 @@ */ #pragma once -#include "pch.h" - -// Directx -#include -#include -#include // Weaver #include "sr/weaver/dx10weaver.h" - // srReshade #include "igraphicsapi.h" +#include "pch.h" + +// Directx +#include class DirectX10Weaver: public IGraphicsApi { - uint32_t lastLatencyFrameTimeSet = DEFAULT_WEAVER_LATENCY; + uint32_t last_latency_frame_time_set = g_default_weaver_latency; + uint32_t effect_frame_copy_x = 0, effect_frame_copy_y = 0; bool weaver_initialized = false; bool weaving_enabled = false; - SR::SRContext* sr_context; - SR::PredictingDX10Weaver* weaver = nullptr; - reshade::api::device* d3d10_device = nullptr; - + bool popup_window_visible = false; + bool resize_buffer_failed = false; bool use_srgb_rtv = true; - bool g_popup_window_visible = false; + float view_separation = 0.f; float vertical_shift = 0.f; + SR::SRContext* sr_context; + SR::PredictingDX10Weaver* weaver = nullptr; + + reshade::api::device* d3d10_device = nullptr; reshade::api::format current_buffer_format = reshade::api::format::unknown; reshade::api::command_list* command_list{}; reshade::api::resource effect_frame_copy{}; reshade::api::resource_view effect_frame_copy_srv{}; - uint32_t effect_frame_copy_x = 0, effect_frame_copy_y = 0; - bool resize_buffer_failed = false; - LatencyModes current_latency_mode = LatencyModes::framerateAdaptive; + LatencyModes current_latency_mode = LatencyModes::FRAMERATE_ADAPTIVE; + + /// \brief Private function to set the internal latency mode of the weaver + /// \param mode The latency mode to persist void set_latency_mode(LatencyModes mode); public: + /// \brief Explicit constructor + /// \param context Pointer to an already initialized SRContext explicit DirectX10Weaver(SR::SRContext* context); + + /// \brief Initialized the SR weaver appropriate for the graphics API + /// \param runtime Represents the reshade effect runtime + /// \param rtv Represents the current render target view + /// \param cmd_list Represents the current command list from ReShade + /// \return A bool representing if the weaver was initialized successfully bool init_weaver(reshade::api::effect_runtime* runtime, reshade::api::resource rtv, reshade::api::command_list* cmd_list); + + /// \brief Method that creates a copy of the RTV so we can weave on it + /// \param effect_resource_desc ReShade resource representing the currently selected RTV + /// \return A bool respresenting if the effect frame copy was successful bool create_effect_copy_buffer(const reshade::api::resource_desc& effect_resource_desc); // Inherited via IGraphicsApi - void draw_debug_overlay(reshade::api::effect_runtime* runtime) override; - void draw_sr_settings_overlay(reshade::api::effect_runtime* runtime) override; - void draw_settings_overlay(reshade::api::effect_runtime* runtime) override; + void draw_status_overlay(reshade::api::effect_runtime *runtime) override; void on_reshade_finish_effects(reshade::api::effect_runtime* runtime, reshade::api::command_list* cmd_list, reshade::api::resource_view rtv, reshade::api::resource_view rtv_srgb) override; void on_init_effect_runtime(reshade::api::effect_runtime* runtime) override; - void do_weave(bool doWeave) override; - bool set_latency_in_frames(int32_t numberOfFrames) override; - bool set_latency_framerate_adaptive(uint32_t frametimeInMicroseconds) override; - void draw_status_overlay(reshade::api::effect_runtime *runtime) override; + void do_weave(bool do_weave) override; + bool set_latency_in_frames(int32_t number_of_frames) override; + bool set_latency_frametime_adaptive(uint32_t frametime_in_microseconds) override; LatencyModes get_latency_mode() override; }; diff --git a/gamebridge_reshade/src/directx11weaver.cpp b/gamebridge_reshade/src/directx11weaver.cpp index 689d157..8acadba 100644 --- a/gamebridge_reshade/src/directx11weaver.cpp +++ b/gamebridge_reshade/src/directx11weaver.cpp @@ -6,16 +6,16 @@ */ #include "directx11weaver.h" + #include DirectX11Weaver::DirectX11Weaver(SR::SRContext* context) { - //Set context here. + // Set context here. sr_context = context; weaving_enabled = true; } -bool DirectX11Weaver::create_effect_copy_buffer(const reshade::api::resource_desc& effect_resource_desc) -{ +bool DirectX11Weaver::create_effect_copy_buffer(const reshade::api::resource_desc& effect_resource_desc) { reshade::api::resource_desc desc = effect_resource_desc; desc.type = reshade::api::resource_type::texture_2d; desc.heap = reshade::api::memory_heap::gpu_only; @@ -76,17 +76,16 @@ bool DirectX11Weaver::init_weaver(reshade::api::effect_runtime* runtime, reshade try { weaver = new SR::PredictingDX11Weaver(*sr_context, dev, context, desc.texture.width, desc.texture.height, (HWND)runtime->get_hwnd()); weaver->setContext((ID3D11DeviceContext*)cmd_list->get_native()); - weaver->setInputFrameBuffer((ID3D11ShaderResourceView*)rtv.handle); //resourceview of the buffer + weaver->setInputFrameBuffer((ID3D11ShaderResourceView*)rtv.handle); // Resourceview of the buffer sr_context->initialize(); reshade::log_message(reshade::log_level::info, "Initialized weaver"); // Set mode to latency in frames by default. - set_latency_mode(LatencyModes::framerateAdaptive); - set_latency_framerate_adaptive(DEFAULT_WEAVER_LATENCY); - std::string latencyLog = "Current latency mode set to: STATIC " + std::to_string(DEFAULT_WEAVER_LATENCY) + " Microseconds"; - reshade::log_message(reshade::log_level::info, latencyLog.c_str()); + set_latency_frametime_adaptive(g_default_weaver_latency); + std::string latency_log = "Current latency mode set to: STATIC " + std::to_string(g_default_weaver_latency) + " Microseconds"; + reshade::log_message(reshade::log_level::info, latency_log.c_str()); } - catch (std::exception e) { + catch (std::exception &e) { reshade::log_message(reshade::log_level::info, e.what()); return false; } @@ -99,29 +98,14 @@ bool DirectX11Weaver::init_weaver(reshade::api::effect_runtime* runtime, reshade return weaver_initialized; } -void DirectX11Weaver::draw_debug_overlay(reshade::api::effect_runtime* runtime) -{ - ImGui::TextUnformatted("Some text"); - - if (ImGui::Button("Press me to open an additional popup window")) - g_popup_window_visible = true; - - if (g_popup_window_visible) - { - ImGui::Begin("Popup", &g_popup_window_visible); - ImGui::TextUnformatted("Some other text"); - ImGui::End(); - } -} - void DirectX11Weaver::draw_status_overlay(reshade::api::effect_runtime *runtime) { // Log activity status ImGui::TextUnformatted("Status: ACTIVE"); // Log the latency mode std::string latencyModeDisplay = "Latency mode: "; - if(current_latency_mode == LatencyModes::framerateAdaptive) { - latencyModeDisplay += "IN " + std::to_string(lastLatencyFrameTimeSet) + " MICROSECONDS"; + if (current_latency_mode == LatencyModes::FRAMERATE_ADAPTIVE) { + latencyModeDisplay += "IN " + std::to_string(last_latency_frame_time_set) + " MICROSECONDS"; } else { latencyModeDisplay += "IN " + std::to_string(runtime->get_back_buffer_count()) + " FRAMES"; @@ -133,17 +117,6 @@ void DirectX11Weaver::draw_status_overlay(reshade::api::effect_runtime *runtime) ImGui::TextUnformatted(s.c_str()); } -void DirectX11Weaver::draw_sr_settings_overlay(reshade::api::effect_runtime* runtime) -{ - ImGui::Checkbox("Turn on SR", &g_popup_window_visible); - ImGui::SliderFloat("View Separation", &view_separation, -50.f, 50.f); - ImGui::SliderFloat("Vertical Shift", &vertical_shift, -50.f, 50.f); -} - -void DirectX11Weaver::draw_settings_overlay(reshade::api::effect_runtime* runtime) -{ -} - void DirectX11Weaver::on_reshade_finish_effects(reshade::api::effect_runtime* runtime, reshade::api::command_list* cmd_list, reshade::api::resource_view rtv, reshade::api::resource_view rtv_srgb) { reshade::api::resource_view chosen_rtv; @@ -159,11 +132,11 @@ void DirectX11Weaver::on_reshade_finish_effects(reshade::api::effect_runtime* ru if (weaver_initialized) { // Check if we need to set the latency in frames. - if(get_latency_mode() == LatencyModes::latencyInFramesAutomatic) { + if (get_latency_mode() == LatencyModes::LATENCY_IN_FRAMES_AUTOMATIC) { weaver->setLatencyInFrames(runtime->get_back_buffer_count()); // Set the latency with which the weaver should do prediction. } - //Check texture size + // Check texture size if (desc.texture.width != effect_frame_copy_x || desc.texture.height != effect_frame_copy_y) { // Update current buffer format current_buffer_format = desc.texture.format; @@ -177,7 +150,7 @@ void DirectX11Weaver::on_reshade_finish_effects(reshade::api::effect_runtime* ru use_srgb_rtv = false; } - //TODO Might have to get the buffer from the create_effect_copy_buffer function and only swap them when creation suceeds + // Todo: Might have to get the buffer from the create_effect_copy_buffer function and only swap them when creation suceeds d3d11_device->destroy_resource(effect_frame_copy); d3d11_device->destroy_resource_view(effect_frame_copy_srv); if (!create_effect_copy_buffer(desc) && !resize_buffer_failed) { @@ -224,30 +197,30 @@ void DirectX11Weaver::on_init_effect_runtime(reshade::api::effect_runtime* runti d3d11_device = runtime->get_device(); } -void DirectX11Weaver::do_weave(bool doWeave) +void DirectX11Weaver::do_weave(bool do_weave) { - weaving_enabled = doWeave; + weaving_enabled = do_weave; } -bool DirectX11Weaver::set_latency_in_frames(int32_t numberOfFrames) { +bool DirectX11Weaver::set_latency_in_frames(int32_t number_of_frames) { if (weaver_initialized) { - if (numberOfFrames < 0) { - set_latency_mode(LatencyModes::latencyInFramesAutomatic); + if (number_of_frames < 0) { + set_latency_mode(LatencyModes::LATENCY_IN_FRAMES_AUTOMATIC); } else { - set_latency_mode(LatencyModes::latencyInFrames); - weaver->setLatencyInFrames(numberOfFrames); + set_latency_mode(LatencyModes::LATENCY_IN_FRAMES); + weaver->setLatencyInFrames(number_of_frames); } return true; } return false; } -bool DirectX11Weaver::set_latency_framerate_adaptive(uint32_t frametimeInMicroseconds) { +bool DirectX11Weaver::set_latency_frametime_adaptive(uint32_t frametime_in_microseconds) { if (weaver_initialized) { - set_latency_mode(LatencyModes::framerateAdaptive); - weaver->setLatency(frametimeInMicroseconds); - lastLatencyFrameTimeSet = frametimeInMicroseconds; + set_latency_mode(LatencyModes::FRAMERATE_ADAPTIVE); + weaver->setLatency(frametime_in_microseconds); + last_latency_frame_time_set = frametime_in_microseconds; return true; } return false; diff --git a/gamebridge_reshade/src/directx11weaver.h b/gamebridge_reshade/src/directx11weaver.h index 7faf378..dd47472 100644 --- a/gamebridge_reshade/src/directx11weaver.h +++ b/gamebridge_reshade/src/directx11weaver.h @@ -6,57 +6,68 @@ */ #pragma once -#include "pch.h" - -// Directx -#include -#include // Weaver #include "sr/weaver/dx11weaver.h" - // srReshade #include "igraphicsapi.h" +#include "pch.h" + +// Directx +#include class DirectX11Weaver: public IGraphicsApi { - uint32_t lastLatencyFrameTimeSet = DEFAULT_WEAVER_LATENCY; + uint32_t last_latency_frame_time_set = g_default_weaver_latency; + uint32_t effect_frame_copy_x = 0, effect_frame_copy_y = 0; bool weaver_initialized = false; bool weaving_enabled = false; - SR::SRContext* sr_context; - SR::PredictingDX11Weaver* weaver = nullptr; - reshade::api::device* d3d11_device = nullptr; - + bool popup_window_visible = false; + bool resize_buffer_failed = false; bool use_srgb_rtv = true; - bool g_popup_window_visible = false; + float view_separation = 0.f; float vertical_shift = 0.f; + SR::SRContext* sr_context; + SR::PredictingDX11Weaver* weaver = nullptr; + + reshade::api::device* d3d11_device = nullptr; + reshade::api::command_list* command_list{}; + reshade::api::resource effect_frame_copy{}; + reshade::api::resource_view effect_frame_copy_srv{}; reshade::api::format current_buffer_format = reshade::api::format::unknown; - reshade::api::command_list* command_list; - reshade::api::resource effect_frame_copy; - reshade::api::resource_view effect_frame_copy_srv; - uint32_t effect_frame_copy_x = 0, effect_frame_copy_y = 0; - bool resize_buffer_failed = false; - LatencyModes current_latency_mode = LatencyModes::framerateAdaptive; + LatencyModes current_latency_mode = LatencyModes::FRAMERATE_ADAPTIVE; + + /// \brief Private function to set the internal latency mode of the weaver + /// \param mode The latency mode to persist void set_latency_mode(LatencyModes mode); public: + /// \brief Explicit constructor + /// \param context Pointer to an already initialized SRContext explicit DirectX11Weaver(SR::SRContext* context); + + /// \brief Initialized the SR weaver appropriate for the graphics API + /// \param runtime Represents the reshade effect runtime + /// \param rtv Represents the current render target view + /// \param cmd_list Represents the current command list from ReShade + /// \return A bool representing if the weaver was initialized successfully bool init_weaver(reshade::api::effect_runtime* runtime, reshade::api::resource rtv, reshade::api::command_list* cmd_list); + + /// \brief Method that creates a copy of the RTV so we can weave on it + /// \param effect_resource_desc ReShade resource representing the currently selected RTV + /// \return A bool respresenting if the effect frame copy was successful bool create_effect_copy_buffer(const reshade::api::resource_desc& effect_resource_desc); // Inherited via IGraphicsApi - void draw_debug_overlay(reshade::api::effect_runtime* runtime) override; - void draw_sr_settings_overlay(reshade::api::effect_runtime* runtime) override; - void draw_settings_overlay(reshade::api::effect_runtime* runtime) override; + void draw_status_overlay(reshade::api::effect_runtime *runtime) override; void on_reshade_finish_effects(reshade::api::effect_runtime* runtime, reshade::api::command_list* cmd_list, reshade::api::resource_view rtv, reshade::api::resource_view rtv_srgb) override; void on_init_effect_runtime(reshade::api::effect_runtime* runtime) override; - void do_weave(bool doWeave) override; - bool set_latency_in_frames(int32_t numberOfFrames) override; - bool set_latency_framerate_adaptive(uint32_t frametimeInMicroseconds) override; - void draw_status_overlay(reshade::api::effect_runtime *runtime) override; + void do_weave(bool do_weave) override; + bool set_latency_in_frames(int32_t number_of_frames) override; + bool set_latency_frametime_adaptive(uint32_t frametime_in_microseconds) override; LatencyModes get_latency_mode() override; }; diff --git a/gamebridge_reshade/src/directx12weaver.cpp b/gamebridge_reshade/src/directx12weaver.cpp index d77cca8..7abdfc7 100644 --- a/gamebridge_reshade/src/directx12weaver.cpp +++ b/gamebridge_reshade/src/directx12weaver.cpp @@ -7,9 +7,8 @@ #include "directx12weaver.h" -DirectX12Weaver::DirectX12Weaver(SR::SRContext* context) -{ - //Set context here. +DirectX12Weaver::DirectX12Weaver(SR::SRContext* context) { + // Set context here. sr_context = context; weaving_enabled = true; } @@ -26,21 +25,21 @@ bool DirectX12Weaver::init_weaver(reshade::api::effect_runtime* runtime, reshade return false; } - ID3D12CommandAllocator* CommandAllocator; - dev->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&CommandAllocator)); - if (CommandAllocator == nullptr) { + ID3D12CommandAllocator* command_allocator; + dev->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&command_allocator)); + if (command_allocator == nullptr) { reshade::log_message(reshade::log_level::info, "Couldn't ceate command allocator"); return false; } // Describe and create the command queue. - ID3D12CommandQueue* CommandQueue; - D3D12_COMMAND_QUEUE_DESC QueueDesc = {}; - QueueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE; - QueueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT; + ID3D12CommandQueue* command_queue; + D3D12_COMMAND_QUEUE_DESC queue_desc = {}; + queue_desc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE; + queue_desc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT; - dev->CreateCommandQueue(&QueueDesc, IID_PPV_ARGS(&CommandQueue)); - if (CommandQueue == nullptr) + dev->CreateCommandQueue(&queue_desc, IID_PPV_ARGS(&command_queue)); + if (command_queue == nullptr) { reshade::log_message(reshade::log_level::info, "Couldn't create command queue"); return false; @@ -49,15 +48,14 @@ bool DirectX12Weaver::init_weaver(reshade::api::effect_runtime* runtime, reshade ID3D12Resource* native_frame_buffer = (ID3D12Resource*)rtv.handle; ID3D12Resource* native_back_buffer = (ID3D12Resource*)back_buffer.handle; try { - weaver = new SR::PredictingDX12Weaver(*sr_context, dev, CommandAllocator, CommandQueue, native_frame_buffer, native_back_buffer, (HWND)runtime->get_hwnd()); + weaver = new SR::PredictingDX12Weaver(*sr_context, dev, command_allocator, command_queue, native_frame_buffer, native_back_buffer, (HWND)runtime->get_hwnd()); sr_context->initialize(); reshade::log_message(reshade::log_level::info, "Initialized weaver"); // Set mode to latency in frames by default. - set_latency_mode(LatencyModes::framerateAdaptive); - set_latency_framerate_adaptive(DEFAULT_WEAVER_LATENCY); - std::string latencyLog = "Current latency mode set to: STATIC " + std::to_string(DEFAULT_WEAVER_LATENCY) + " Microseconds"; - reshade::log_message(reshade::log_level::info, latencyLog.c_str()); + set_latency_frametime_adaptive(g_default_weaver_latency); + std::string latency_log = "Current latency mode set to: STATIC " + std::to_string(g_default_weaver_latency) + " Microseconds"; + reshade::log_message(reshade::log_level::info, latency_log.c_str()); } catch (std::exception& e) { reshade::log_message(reshade::log_level::info, e.what()); @@ -77,46 +75,20 @@ void DirectX12Weaver::draw_status_overlay(reshade::api::effect_runtime *runtime) ImGui::TextUnformatted("Status: ACTIVE"); // Log the latency mode - std::string latencyModeDisplay = "Latency mode: "; - if(current_latency_mode == LatencyModes::framerateAdaptive) { - latencyModeDisplay += "IN " + std::to_string(lastLatencyFrameTimeSet) + " MICROSECONDS"; + std::string latency_mode_display = "Latency mode: "; + if (current_latency_mode == LatencyModes::FRAMERATE_ADAPTIVE) { + latency_mode_display += "IN " + std::to_string(last_latency_frame_time_set) + " MICROSECONDS"; } else { - latencyModeDisplay += "IN " + std::to_string(runtime->get_back_buffer_count()) + " FRAMES"; + latency_mode_display += "IN " + std::to_string(runtime->get_back_buffer_count()) + " FRAMES"; } - ImGui::TextUnformatted(latencyModeDisplay.c_str()); + ImGui::TextUnformatted(latency_mode_display.c_str()); // Log the buffer type, this can be removed once we've tested a larger amount of games. std::string s = "Buffer type: " + std::to_string(static_cast(current_buffer_format)); ImGui::TextUnformatted(s.c_str()); } -void DirectX12Weaver::draw_debug_overlay(reshade::api::effect_runtime* runtime) -{ - ImGui::TextUnformatted("Some text"); - - if (ImGui::Button("Press me to open an additional popup window")) - g_popup_window_visible = true; - - if (g_popup_window_visible) - { - ImGui::Begin("Popup", &g_popup_window_visible); - ImGui::TextUnformatted("Some other text"); - ImGui::End(); - } -} - -void DirectX12Weaver::draw_sr_settings_overlay(reshade::api::effect_runtime* runtime) -{ - ImGui::Checkbox("Turn on SR", &g_popup_window_visible); - ImGui::SliderFloat("View Separation", &view_separation, -50.f, 50.f); - ImGui::SliderFloat("Vertical Shift", &vertical_shift, -50.f, 50.f); -} - -void DirectX12Weaver::draw_settings_overlay(reshade::api::effect_runtime* runtime) -{ -} - bool DirectX12Weaver::create_effect_copy_buffer(const reshade::api::resource_desc& effect_resource_desc) { reshade::api::resource_desc desc = effect_resource_desc; desc.type = reshade::api::resource_type::texture_2d; @@ -154,7 +126,7 @@ void DirectX12Weaver::on_reshade_finish_effects(reshade::api::effect_runtime* ru if (weaver_initialized) { // Check if we need to set the latency in frames. - if(get_latency_mode() == LatencyModes::latencyInFramesAutomatic) { + if (get_latency_mode() == LatencyModes::LATENCY_IN_FRAMES_AUTOMATIC) { weaver->setLatencyInFrames(runtime->get_back_buffer_count()); // Set the latency with which the weaver should do prediction. } @@ -172,8 +144,7 @@ void DirectX12Weaver::on_reshade_finish_effects(reshade::api::effect_runtime* ru use_srgb_rtv = false; } - - // TODO Might have to get the buffer from the create_effect_copy_buffer function and only swap them when creation succeeds + // Todo: Might have to get the buffer from the create_effect_copy_buffer function and only swap them when creation succeeds // Destroy the resource only when the GPU is finished drawing. runtime->get_command_queue()->wait_idle(); d3d12_device->destroy_resource(effect_frame_copy); @@ -230,64 +201,29 @@ void DirectX12Weaver::on_init_effect_runtime(reshade::api::effect_runtime* runti d3d12_device = runtime->get_device(); } -void DirectX12Weaver::do_weave(bool doWeave) -{ - weaving_enabled = doWeave; -} - -/** - * Find the closest element to a given value in a sorted array. - * - * @param sorted_array A sorted vector of integers. - * @param target_value The value to find the closest element to. - * @return The closest element in the array to the target value. - * @throws std::invalid_argument if the array is empty. - */ -int32_t find_closest(const std::vector& sorted_array, int target_value) { - // Check if the array is empty - if (sorted_array.empty()) { - throw std::invalid_argument("Unable to find closest, array is empty."); - } - - // Use binary search to find the lower bound of the target value - const auto lower_bound = std::lower_bound(sorted_array.begin(), sorted_array.end(), target_value); - - // Initialize the answer with the closest value found so far - int32_t closest_value = (lower_bound != sorted_array.end()) ? *lower_bound : sorted_array.back(); - - // Check if there is a predecessor to the lower bound - if (lower_bound != sorted_array.begin()) { - auto predecessor = lower_bound - 1; - - // Update the answer if the predecessor is closer to the target value - if (std::abs(closest_value - target_value) > std::abs(*predecessor - target_value)) { - closest_value = *predecessor; - } - } - - // Return the closest value found - return closest_value; +void DirectX12Weaver::do_weave(bool do_weave) { + weaving_enabled = do_weave; } -bool DirectX12Weaver::set_latency_in_frames(int32_t numberOfFrames) { +bool DirectX12Weaver::set_latency_in_frames(int32_t number_of_frames) { if (weaver_initialized) { - if (numberOfFrames < 0) { - set_latency_mode(LatencyModes::latencyInFramesAutomatic); + if (number_of_frames < 0) { + set_latency_mode(LatencyModes::LATENCY_IN_FRAMES_AUTOMATIC); } else { - set_latency_mode(LatencyModes::latencyInFrames); - weaver->setLatencyInFrames(numberOfFrames); + set_latency_mode(LatencyModes::LATENCY_IN_FRAMES); + weaver->setLatencyInFrames(number_of_frames); } return true; } return false; } -bool DirectX12Weaver::set_latency_framerate_adaptive(uint32_t frametimeInMicroseconds) { +bool DirectX12Weaver::set_latency_frametime_adaptive(uint32_t frametime_in_microseconds) { if (weaver_initialized) { - set_latency_mode(LatencyModes::framerateAdaptive); - weaver->setLatency(frametimeInMicroseconds); - lastLatencyFrameTimeSet = frametimeInMicroseconds; + set_latency_mode(LatencyModes::FRAMERATE_ADAPTIVE); + weaver->setLatency(frametime_in_microseconds); + last_latency_frame_time_set = frametime_in_microseconds; return true; } return false; diff --git a/gamebridge_reshade/src/directx12weaver.h b/gamebridge_reshade/src/directx12weaver.h index f2ae756..7ab0506 100644 --- a/gamebridge_reshade/src/directx12weaver.h +++ b/gamebridge_reshade/src/directx12weaver.h @@ -6,62 +6,67 @@ */ #pragma once -#include "pch.h" - -// Directx -#include -#include -#include -#include // Weaver #include "sr/weaver/dx12weaver.h" - // srReshade #include "igraphicsapi.h" +#include "pch.h" + +// Directx +#include class DirectX12Weaver: public IGraphicsApi { - uint32_t lastLatencyFrameTimeSet = DEFAULT_WEAVER_LATENCY; + uint32_t last_latency_frame_time_set = g_default_weaver_latency; + uint32_t effect_frame_copy_x = 0, effect_frame_copy_y = 0; bool weaver_initialized = false; bool weaving_enabled = false; - SR::SRContext* sr_context; - SR::PredictingDX12Weaver* weaver = nullptr; - reshade::api::device* d3d12_device = nullptr; - + bool popup_window_visible = false; + bool resize_buffer_failed = false; bool use_srgb_rtv = false; - bool g_popup_window_visible = false; + float view_separation = 0.f; float vertical_shift = 0.f; - reshade::api::format current_buffer_format = reshade::api::format::unknown; - reshade::api::command_list* command_list; - reshade::api::resource_view game_frame_buffer; + SR::SRContext* sr_context; + SR::PredictingDX12Weaver* weaver = nullptr; - std::vector effect_copy_resource_res; - reshade::api::resource effect_frame_copy; - uint32_t effect_frame_copy_x = 0, effect_frame_copy_y = 0; + reshade::api::device* d3d12_device = nullptr; + reshade::api::command_list* command_list{}; + reshade::api::resource effect_frame_copy{}; + reshade::api::resource_view game_frame_buffer{}; + reshade::api::format current_buffer_format = reshade::api::format::unknown; - std::vector to_destroy; + LatencyModes current_latency_mode = LatencyModes::FRAMERATE_ADAPTIVE; - LatencyModes current_latency_mode = LatencyModes::framerateAdaptive; + /// \brief Private function to set the internal latency mode of the weaver + /// \param mode The latency mode to persist void set_latency_mode(LatencyModes mode); public: - bool resize_buffer_failed = false; + /// \brief Explicit constructor + /// \param context Pointer to an already initialized SRContext explicit DirectX12Weaver(SR::SRContext* context); + + /// \brief Initialized the SR weaver appropriate for the graphics API + /// \param runtime Represents the reshade effect runtime + /// \param rtv Represents the current render target view + /// \param back_buffer Represents the current back buffer from ReShade + /// \return A bool representing if the weaver was initialized successfully bool init_weaver(reshade::api::effect_runtime* runtime, reshade::api::resource rtv, reshade::api::resource back_buffer); + + /// \brief Method that creates a copy of the RTV so we can weave on it + /// \param effect_resource_desc ReShade resource representing the currently selected RTV + /// \return A bool respresenting if the effect frame copy was successful bool create_effect_copy_buffer(const reshade::api::resource_desc& effect_resource_desc); // Inherited via IGraphicsApi - void draw_debug_overlay(reshade::api::effect_runtime* runtime) override; - void draw_sr_settings_overlay(reshade::api::effect_runtime* runtime) override; - void draw_settings_overlay(reshade::api::effect_runtime* runtime) override; - void on_reshade_finish_effects(reshade::api::effect_runtime* runtime, reshade::api::command_list* cmd_list, reshade::api::resource_view rtv, reshade::api::resource_view rtv_srgb) override; - void on_init_effect_runtime(reshade::api::effect_runtime* runtime) override; - void do_weave(bool doWeave) override; - bool set_latency_in_frames(int32_t numberOfFrames) override; - bool set_latency_framerate_adaptive(uint32_t frametimeInMicroseconds) override; void draw_status_overlay(reshade::api::effect_runtime *runtime) override; + void on_reshade_finish_effects(reshade::api::effect_runtime* runtime, reshade::api::command_list* cmd_list, reshade::api::resource_view rtv, reshade::api::resource_view) override; + void on_init_effect_runtime(reshade::api::effect_runtime* runtime) override; + void do_weave(bool do_weave) override; + bool set_latency_in_frames(int32_t number_of_frames) override; + bool set_latency_frametime_adaptive(uint32_t frametime_in_microseconds) override; LatencyModes get_latency_mode() override; }; diff --git a/gamebridge_reshade/src/directx9weaver.cpp b/gamebridge_reshade/src/directx9weaver.cpp index a006ea2..09a3e2d 100644 --- a/gamebridge_reshade/src/directx9weaver.cpp +++ b/gamebridge_reshade/src/directx9weaver.cpp @@ -8,13 +8,12 @@ #include "directx9weaver.h" DirectX9Weaver::DirectX9Weaver(SR::SRContext* context) { - //Set context here. + // Set context here. sr_context = context; weaving_enabled = true; } -bool DirectX9Weaver::create_effect_copy_buffer(const reshade::api::resource_desc& effect_resource_desc) -{ +bool DirectX9Weaver::create_effect_copy_buffer(const reshade::api::resource_desc& effect_resource_desc) { reshade::api::resource_desc desc = effect_resource_desc; desc.type = reshade::api::resource_type::texture_2d; desc.heap = reshade::api::memory_heap::gpu_only; @@ -56,17 +55,16 @@ bool DirectX9Weaver::init_weaver(reshade::api::effect_runtime* runtime, reshade: try { weaver = new SR::PredictingDX9Weaver(*sr_context, dev, desc.texture.width, desc.texture.height, (HWND)runtime->get_hwnd()); - weaver->setInputFrameBuffer((IDirect3DTexture9*)rtv.handle); //resourceview of the buffer + weaver->setInputFrameBuffer((IDirect3DTexture9*)rtv.handle); // Resourceview of the buffer sr_context->initialize(); reshade::log_message(reshade::log_level::info, "Initialized weaver"); // Set mode to latency in frames by default. - set_latency_mode(LatencyModes::framerateAdaptive); - set_latency_framerate_adaptive(DEFAULT_WEAVER_LATENCY); - std::string latencyLog = "Current latency mode set to: STATIC " + std::to_string(DEFAULT_WEAVER_LATENCY) + " Microseconds"; - reshade::log_message(reshade::log_level::info, latencyLog.c_str()); + set_latency_frametime_adaptive(g_default_weaver_latency); + std::string latency_log = "Current latency mode set to: STATIC " + std::to_string(g_default_weaver_latency) + " Microseconds"; + reshade::log_message(reshade::log_level::info, latency_log.c_str()); } - catch (std::exception e) { + catch (std::exception &e) { reshade::log_message(reshade::log_level::info, e.what()); return false; } @@ -85,8 +83,8 @@ void DirectX9Weaver::draw_status_overlay(reshade::api::effect_runtime *runtime) // Log the latency mode std::string latencyModeDisplay = "Latency mode: "; - if(current_latency_mode == LatencyModes::framerateAdaptive) { - latencyModeDisplay += "IN " + std::to_string(lastLatencyFrameTimeSet) + " MICROSECONDS"; + if (current_latency_mode == LatencyModes::FRAMERATE_ADAPTIVE) { + latencyModeDisplay += "IN " + std::to_string(last_latency_frame_time_set) + " MICROSECONDS"; } else { latencyModeDisplay += "IN " + std::to_string(runtime->get_back_buffer_count()) + " FRAMES"; @@ -98,32 +96,6 @@ void DirectX9Weaver::draw_status_overlay(reshade::api::effect_runtime *runtime) ImGui::TextUnformatted(s.c_str()); } -void DirectX9Weaver::draw_debug_overlay(reshade::api::effect_runtime* runtime) -{ - ImGui::TextUnformatted("Some text"); - - if (ImGui::Button("Press me to open an additional popup window")) - g_popup_window_visible = true; - - if (g_popup_window_visible) - { - ImGui::Begin("Popup", &g_popup_window_visible); - ImGui::TextUnformatted("Some other text"); - ImGui::End(); - } -} - -void DirectX9Weaver::draw_sr_settings_overlay(reshade::api::effect_runtime* runtime) -{ - ImGui::Checkbox("Turn on SR", &g_popup_window_visible); - ImGui::SliderFloat("View Separation", &view_separation, -50.f, 50.f); - ImGui::SliderFloat("Vertical Shift", &vertical_shift, -50.f, 50.f); -} - -void DirectX9Weaver::draw_settings_overlay(reshade::api::effect_runtime* runtime) -{ -} - void DirectX9Weaver::on_reshade_finish_effects(reshade::api::effect_runtime* runtime, reshade::api::command_list* cmd_list, reshade::api::resource_view rtv, reshade::api::resource_view rtv_srgb) { reshade::api::resource_view chosen_rtv; @@ -139,11 +111,11 @@ void DirectX9Weaver::on_reshade_finish_effects(reshade::api::effect_runtime* run if (weaver_initialized) { // Check if we need to set the latency in frames. - if(get_latency_mode() == LatencyModes::latencyInFramesAutomatic) { + if (get_latency_mode() == LatencyModes::LATENCY_IN_FRAMES_AUTOMATIC) { weaver->setLatencyInFrames(runtime->get_back_buffer_count()); // Set the latency with which the weaver should do prediction. } - //Check texture size + // Check texture size if (desc.texture.width != effect_frame_copy_x || desc.texture.height != effect_frame_copy_y) { // Update current buffer format current_buffer_format = desc.texture.format; @@ -151,7 +123,8 @@ void DirectX9Weaver::on_reshade_finish_effects(reshade::api::effect_runtime* run // Invalidate weaver device objects before resizing the resource. weaver->invalidateDeviceObjects(); - // Check buffer format and see if it's in the list of known problematic ones. Change to SRGB rtv if so. + // Todo: Might have to get the buffer from the create_effect_copy_buffer function and only swap them when creation suceeds + // Check buffer format and see if it's in the list of known SRGB ones. Change to SRGB rtv if so. if ((std::find(srgb_color_formats.begin(), srgb_color_formats.end(), desc.texture.format) != srgb_color_formats.end())) { // SRGB format detected, switch to SRGB buffer. use_srgb_rtv = true; @@ -208,30 +181,30 @@ void DirectX9Weaver::on_init_effect_runtime(reshade::api::effect_runtime* runtim d3d9_device = runtime->get_device(); } -void DirectX9Weaver::do_weave(bool doWeave) +void DirectX9Weaver::do_weave(bool do_weave) { - weaving_enabled = doWeave; + weaving_enabled = do_weave; } -bool DirectX9Weaver::set_latency_in_frames(int32_t numberOfFrames) { +bool DirectX9Weaver::set_latency_in_frames(int32_t number_of_frames) { if (weaver_initialized) { - if (numberOfFrames < 0) { - set_latency_mode(LatencyModes::latencyInFramesAutomatic); + if (number_of_frames < 0) { + set_latency_mode(LatencyModes::LATENCY_IN_FRAMES_AUTOMATIC); } else { - set_latency_mode(LatencyModes::latencyInFrames); - weaver->setLatencyInFrames(numberOfFrames); + set_latency_mode(LatencyModes::LATENCY_IN_FRAMES); + weaver->setLatencyInFrames(number_of_frames); } return true; } return false; } -bool DirectX9Weaver::set_latency_framerate_adaptive(uint32_t frametimeInMicroseconds) { +bool DirectX9Weaver::set_latency_frametime_adaptive(uint32_t frametime_in_microseconds) { if (weaver_initialized) { - set_latency_mode(LatencyModes::framerateAdaptive); - weaver->setLatency(frametimeInMicroseconds); - lastLatencyFrameTimeSet = frametimeInMicroseconds; + set_latency_mode(LatencyModes::FRAMERATE_ADAPTIVE); + weaver->setLatency(frametime_in_microseconds); + last_latency_frame_time_set = frametime_in_microseconds; return true; } return false; diff --git a/gamebridge_reshade/src/directx9weaver.h b/gamebridge_reshade/src/directx9weaver.h index 2747f29..042a01d 100644 --- a/gamebridge_reshade/src/directx9weaver.h +++ b/gamebridge_reshade/src/directx9weaver.h @@ -6,55 +6,67 @@ */ #pragma once -#include "pch.h" - -// Directx -#include -#include // Weaver #include "sr/weaver/dx9weaver.h" - // srReshade #include "igraphicsapi.h" +#include "pch.h" + +// Directx +#include class DirectX9Weaver: public IGraphicsApi { - uint32_t lastLatencyFrameTimeSet = DEFAULT_WEAVER_LATENCY; + uint32_t last_latency_frame_time_set = g_default_weaver_latency; + uint32_t effect_frame_copy_x = 0, effect_frame_copy_y = 0; bool weaver_initialized = false; bool weaving_enabled = false; - SR::SRContext* sr_context; - SR::PredictingDX9Weaver* weaver = nullptr; - reshade::api::device* d3d9_device = nullptr; + bool popup_window_visible = false; + bool resize_buffer_failed = false; + bool use_srgb_rtv = true; - bool g_popup_window_visible = false; float view_separation = 0.f; float vertical_shift = 0.f; + SR::SRContext* sr_context; + SR::PredictingDX9Weaver* weaver = nullptr; + + reshade::api::device* d3d9_device = nullptr; + reshade::api::format current_buffer_format = reshade::api::format::unknown; reshade::api::command_list* command_list{}; reshade::api::resource effect_frame_copy{}; - uint32_t effect_frame_copy_x = 0, effect_frame_copy_y = 0; - bool use_srgb_rtv = true; - bool resize_buffer_failed = false; - LatencyModes current_latency_mode = LatencyModes::framerateAdaptive; + LatencyModes current_latency_mode = LatencyModes::FRAMERATE_ADAPTIVE; + + /// \brief Private function to set the internal latency mode of the weaver + /// \param mode The latency mode to persist void set_latency_mode(LatencyModes mode); public: + /// \brief Explicit constructor + /// \param context Pointer to an already initialized SRContext explicit DirectX9Weaver(SR::SRContext* context); + + /// \brief Initialized the SR weaver appropriate for the graphics API + /// \param runtime Represents the reshade effect runtime + /// \param rtv Represents the current render target view + /// \param cmd_list Represents the current command list from ReShade + /// \return A bool representing if the weaver was initialized successfully bool init_weaver(reshade::api::effect_runtime* runtime, reshade::api::resource rtv, reshade::api::command_list* cmd_list); + + /// \brief Method that creates a copy of the RTV so we can weave on it + /// \param effect_resource_desc ReShade resource representing the currently selected RTV + /// \return A bool respresenting if the effect frame copy was successful bool create_effect_copy_buffer(const reshade::api::resource_desc& effect_resource_desc); // Inherited via IGraphicsApi - void draw_debug_overlay(reshade::api::effect_runtime* runtime) override; - void draw_sr_settings_overlay(reshade::api::effect_runtime* runtime) override; - void draw_settings_overlay(reshade::api::effect_runtime* runtime) override; + void draw_status_overlay(reshade::api::effect_runtime *runtime) override; void on_reshade_finish_effects(reshade::api::effect_runtime* runtime, reshade::api::command_list* cmd_list, reshade::api::resource_view rtv, reshade::api::resource_view rtv_srgb) override; void on_init_effect_runtime(reshade::api::effect_runtime* runtime) override; - void do_weave(bool doWeave) override; - bool set_latency_in_frames(int32_t numberOfFrames) override; - bool set_latency_framerate_adaptive(uint32_t frametimeInMicroseconds) override; - void draw_status_overlay(reshade::api::effect_runtime *runtime) override; + void do_weave(bool do_weave) override; + bool set_latency_in_frames(int32_t number_of_frames) override; + bool set_latency_frametime_adaptive(uint32_t frametime_in_microseconds) override; LatencyModes get_latency_mode() override; }; diff --git a/gamebridge_reshade/src/dllmain.cpp b/gamebridge_reshade/src/dllmain.cpp index 28c44fb..c4a2a4e 100644 --- a/gamebridge_reshade/src/dllmain.cpp +++ b/gamebridge_reshade/src/dllmain.cpp @@ -110,10 +110,10 @@ static void execute_hot_key_function_by_type(std::map hot_ke for (i = hot_key_list.begin(); i != hot_key_list.end(); i++) { switch (i->first) { - case shortcutType::toggle_SR: + case shortcutType::TOGGLE_SR: //Here we want to completely disable all SR related functions including the eye tracker, weaver, context etc. break; - case shortcutType::toggle_lens: + case shortcutType::TOGGLE_LENS: //Here we want to toggle to the lens and toggle weaving if (i->second) { lens_hint->enable(); @@ -126,7 +126,7 @@ static void execute_hot_key_function_by_type(std::map hot_ke weaver_implementation->do_weave(false); } break; - case shortcutType::toggle_3D: + case shortcutType::TOGGLE_3D: //Here we want to toggle Depth3D or any other 3D effect we use to create our second eye image. enumerate_techniques(runtime, [&togglable_3D_effects](reshade::api::effect_runtime *runtime, reshade::api::effect_technique technique, @@ -145,17 +145,17 @@ static void execute_hot_key_function_by_type(std::map hot_ke } } break; - case shortcutType::toggle_lens_and_3D: + case shortcutType::TOGGLE_LENS_AND_3D: //Todo: This should look at the current state of the lens toggle and 3D toggle, then, flip those.This toggle having its own state isn't great. if (i->second) { - toggle_map = {{shortcutType::toggle_lens, true}, {shortcutType::toggle_3D, true} }; + toggle_map = {{shortcutType::TOGGLE_LENS, true}, {shortcutType::TOGGLE_3D, true} }; } else { - toggle_map = {{shortcutType::toggle_lens, false}, {shortcutType::toggle_3D, false} }; + toggle_map = {{shortcutType::TOGGLE_LENS, false}, {shortcutType::TOGGLE_3D, false} }; } execute_hot_key_function_by_type(toggle_map, runtime); break; - case shortcutType::toggle_latency_mode: + case shortcutType::TOGGLE_LATENCY_MODE: //Here we want to toggle the eye tracker latency mode between framerate-adaptive and latency-in-frames. if (i->second) { // Set the latency in frames to -1 to use ReShade's swap_chain buffer count. @@ -166,7 +166,7 @@ static void execute_hot_key_function_by_type(std::map hot_ke } else { // Set the latency to the SR default of 40000 microseconds (Tuned for 60Hz) - weaver_implementation->set_latency_framerate_adaptive(DEFAULT_WEAVER_LATENCY); + weaver_implementation->set_latency_frametime_adaptive(g_default_weaver_latency); //Log the current mode: reshade::log_message(reshade::log_level::info, "Current latency mode set to: STATIC 40000 Microseconds"); @@ -200,18 +200,6 @@ static void draw_status_overlay(reshade::api::effect_runtime* runtime) { } } -static void draw_debug_overlay(reshade::api::effect_runtime* runtime) { - //weaver_implementation->draw_debug_overlay(runtime); -} - -static void draw_sr_settings_overlay(reshade::api::effect_runtime* runtime) { - //weaver_implementation->draw_sr_settings_overlay(runtime); -} - -static void draw_settings_overlay(reshade::api::effect_runtime* runtime) { - //weaver_implementation->draw_settings_overlay(runtime); -} - static void on_reshade_reload_effects(reshade::api::effect_runtime* runtime) { vector sr_technique = {}; @@ -235,7 +223,7 @@ static void on_reshade_begin_effects(reshade::api::effect_runtime* runtime, resh } static void on_reshade_finish_effects(reshade::api::effect_runtime* runtime, reshade::api::command_list* cmd_list, reshade::api::resource_view rtv, reshade::api::resource_view rtv_srgb) { - if(!sr_initialized) { + if (!sr_initialized) { return; } @@ -345,15 +333,9 @@ BOOL APIENTRY DllMain( HMODULE hModule, reshade::register_overlay(nullptr, &draw_status_overlay); - //reshade::register_overlay("Test", &draw_debug_overlay); - //reshade::register_overlay(nullptr, &draw_sr_settings_overlay); - //reshade::log_message(3, "registered: draw_sr_settings_overlay"); - break; case DLL_PROCESS_DETACH: reshade::unregister_addon(hModule); - //reshade::unregister_event(on_reshade_finish_effects); - //reshade::unregister_event(on_init_effect_runtime); break; } return TRUE; diff --git a/gamebridge_reshade/src/hotkey.cpp b/gamebridge_reshade/src/hotkey.cpp index 8420e96..37ebab1 100644 --- a/gamebridge_reshade/src/hotkey.cpp +++ b/gamebridge_reshade/src/hotkey.cpp @@ -11,56 +11,49 @@ HotKey::HotKey() { } -void HotKey::set_toggle_key(uint8_t newKeyValue, shortcutType type, bool shiftRequired, bool altRequired, bool ctrlRequired) { - this->shortcut_key = newKeyValue; +void HotKey::set_toggle_key(uint8_t new_key_value, shortcutType type, bool shift_required, bool alt_required, bool ctrl_required) { + this->shortcut_key = new_key_value; this->type = type; - this->shift_required = shiftRequired; - this->alt_required = altRequired; - this->ctrl_required = ctrlRequired; + this->shift_required = shift_required; + this->alt_required = alt_required; + this->ctrl_required = ctrl_required; } -HotKey::HotKey(bool isEnabled, shortcutType type, uint8_t key, bool shiftRequired, bool altRequired, bool ctrlRequired) { +HotKey::HotKey(bool isEnabled, shortcutType type, uint8_t key, bool shift_required, bool alt_required, bool ctrl_required) { this->is_enabled = isEnabled; this->type = type; this->shortcut_key = key; - this->shift_required = shiftRequired; - this->alt_required = altRequired; - this->ctrl_required = ctrlRequired; + this->shift_required = shift_required; + this->alt_required = alt_required; + this->ctrl_required = ctrl_required; } -bool HotKey::get_enabled() -{ +bool HotKey::get_enabled() { return is_enabled; } -bool HotKey::get_shift_required() -{ +bool HotKey::get_shift_required() { return shift_required; } -bool HotKey::get_alt_required() -{ +bool HotKey::get_alt_required() { return alt_required; } -bool HotKey::get_ctrl_required() -{ +bool HotKey::get_ctrl_required() { return ctrl_required; } -shortcutType HotKey::get_type() -{ +shortcutType HotKey::get_type() { return type; } -uint8_t HotKey::get_key() -{ +uint8_t HotKey::get_key() { return shortcut_key; } -uint8_t HotKey::get_id() -{ - //Returns a "unique" integer. - //Todo: A check should be performed when a new shortcut is added to ensure every id is indeed unique. +uint8_t HotKey::get_id() { + // Returns a "unique" integer. + // Todo: A check should be performed when a new shortcut is added to ensure every id is indeed unique. return type + shortcut_key; } diff --git a/gamebridge_reshade/src/hotkey.h b/gamebridge_reshade/src/hotkey.h index 919977e..ee51c67 100644 --- a/gamebridge_reshade/src/hotkey.h +++ b/gamebridge_reshade/src/hotkey.h @@ -5,18 +5,19 @@ * Copyright and license notices must be preserved. Contributors provide an express grant of patent rights. Modifications to the source code must be disclosed publicly. */ +#pragma once + #include "pch.h" #include -#include class HotKey { public: HotKey(); - HotKey(bool isEnabled, shortcutType type, uint8_t key, bool shiftRequired, bool altRequired, bool ctrlRequired); + HotKey(bool isEnabled, shortcutType type, uint8_t key, bool shift_required, bool alt_required, bool ctrl_required); void toggle_hot_key() { is_enabled = !is_enabled; } - //Unused for now, can make the key editable with this later. - void set_toggle_key(uint8_t newKeyValue, shortcutType type, bool shiftRequired, bool altRequired, bool ctrlRequired); + // Unused for now, can make the key editable with this later. + void set_toggle_key(uint8_t new_key_value, shortcutType type, bool shift_required, bool alt_required, bool ctrl_required); bool get_enabled(); bool get_shift_required(); @@ -31,6 +32,6 @@ class HotKey { bool shift_required = false; bool alt_required = false; bool ctrl_required = true; - shortcutType type = shortcutType::toggle_SR; + shortcutType type = shortcutType::TOGGLE_SR; uint8_t shortcut_key = 0x00; }; diff --git a/gamebridge_reshade/src/hotkeyManager.h b/gamebridge_reshade/src/hotkeyManager.h index 3f26d06..7f27404 100644 --- a/gamebridge_reshade/src/hotkeyManager.h +++ b/gamebridge_reshade/src/hotkeyManager.h @@ -5,18 +5,19 @@ * Copyright and license notices must be preserved. Contributors provide an express grant of patent rights. Modifications to the source code must be disclosed publicly. */ +#pragma once + #include "hotkey.h" #include "pch.h" #include -#include class HotKeyManager { public: HotKeyManager(); std::map check_hot_keys(reshade::api::effect_runtime* runtime, SR::SRContext* context); //Todo: Implement a way to edit and create now hotkeys? - void edit_hot_key(uint8_t hotKeyId); + void edit_hot_key(uint8_t hot_key_id); private: //Todo: We should define these in a .ini file eventually. diff --git a/gamebridge_reshade/src/hotkeymanager.cpp b/gamebridge_reshade/src/hotkeymanager.cpp index 2a1742c..55d0f2c 100644 --- a/gamebridge_reshade/src/hotkeymanager.cpp +++ b/gamebridge_reshade/src/hotkeymanager.cpp @@ -7,23 +7,22 @@ #include "hotkeyManager.h" -HotKeyManager::HotKeyManager() -{ - //Todo: Could be prettier - //Create some default hotkeys. - HotKey toggleSRKey = HotKey(true, shortcutType::toggle_SR, 0x31, false, false, true); - HotKey toggleLensKey = HotKey(true, shortcutType::toggle_lens, 0x32, false, false, true); - HotKey toggle3D = HotKey(false, shortcutType::toggle_3D, 0x33, false, false, true); - HotKey toggleLensAnd3D = HotKey(false, shortcutType::toggle_lens_and_3D, 0x34, false, false, true); - HotKey toggleLatencyMode = HotKey(false, shortcutType::toggle_latency_mode, 0x35, false, false, true); - registered_hot_keys.push_back(toggleSRKey); - registered_hot_keys.push_back(toggleLensKey); - registered_hot_keys.push_back(toggle3D); - registered_hot_keys.push_back(toggleLensAnd3D); - registered_hot_keys.push_back(toggleLatencyMode); +HotKeyManager::HotKeyManager() { + // Todo: Could be prettier + // Create some default hotkeys. + HotKey toggle_sr_key = HotKey(true, shortcutType::TOGGLE_SR, 0x31, false, false, true); + HotKey toggle_lens_key = HotKey(true, shortcutType::TOGGLE_LENS, 0x32, false, false, true); + HotKey toggle_3d = HotKey(false, shortcutType::TOGGLE_3D, 0x33, false, false, true); + HotKey toggle_lens_and_3d = HotKey(false, shortcutType::TOGGLE_LENS_AND_3D, 0x34, false, false, true); + HotKey toggle_latency_mode = HotKey(false, shortcutType::TOGGLE_LATENCY_MODE, 0x35, false, false, true); + registered_hot_keys.push_back(toggle_sr_key); + registered_hot_keys.push_back(toggle_lens_key); + registered_hot_keys.push_back(toggle_3d); + registered_hot_keys.push_back(toggle_lens_and_3d); + registered_hot_keys.push_back(toggle_latency_mode); } -bool checkModifierKeys(HotKey hotKey, reshade::api::effect_runtime* runtime) { +bool check_modifier_keys(HotKey hotKey, reshade::api::effect_runtime* runtime) { if (hotKey.get_alt_required()) { if (!runtime->is_key_down(VK_MENU)) { return false; @@ -45,25 +44,25 @@ bool checkModifierKeys(HotKey hotKey, reshade::api::effect_runtime* runtime) { return true; } -//Returns a list of toggled hotkeys. +// Returns a list of toggled hotkeys. std::map HotKeyManager::check_hot_keys(reshade::api::effect_runtime* runtime, SR::SRContext* context) { - std::map toggledHotKeys; + std::map toggled_hot_keys; - //This might be pretty slow but for now it will do since we only ever have 3 hotkeys. + // This might be pretty slow but for now it will do since we only ever have 3 hotkeys. for (int i = 0; i < registered_hot_keys.size(); i++) { if (runtime->is_key_pressed(registered_hot_keys[i].get_key())) { //Hotkey is being pressed, now check for the modifier keys. - if (checkModifierKeys(registered_hot_keys[i], runtime)) { + if (check_modifier_keys(registered_hot_keys[i], runtime)) { //All conditions are met, execute hotkey logic. registered_hot_keys[i].toggle_hot_key(); - toggledHotKeys[registered_hot_keys[i].get_type()] = registered_hot_keys[i].get_enabled(); + toggled_hot_keys[registered_hot_keys[i].get_type()] = registered_hot_keys[i].get_enabled(); } } } - return toggledHotKeys; + return toggled_hot_keys; } -void HotKeyManager::edit_hot_key(uint8_t hotKeyId) { +void HotKeyManager::edit_hot_key(uint8_t hot_key_id) { } diff --git a/gamebridge_reshade/src/igraphicsapi.h b/gamebridge_reshade/src/igraphicsapi.h index 5920585..43f378a 100644 --- a/gamebridge_reshade/src/igraphicsapi.h +++ b/gamebridge_reshade/src/igraphicsapi.h @@ -6,6 +6,7 @@ */ #pragma once + #include "pch.h" // List of color formats that require color linearization in order restore the correct gamma. @@ -13,11 +14,11 @@ const std::list srgb_color_formats { reshade::api::format::r8g8b8a8_unorm_srgb, }; -const uint32_t DEFAULT_WEAVER_LATENCY = 40000; +const uint32_t g_default_weaver_latency = 40000; // framerateAdaptive = provide an amount of time in microseconds in between weave() calls. // latencyInFrames = provide an amount of buffers or "frames" between the application and presenting to the screen. // latencyInFramesAutomatic = gets the amount of buffers or "frames" from the backbuffer using the ReShade api every frame. -enum LatencyModes { framerateAdaptive, latencyInFrames, latencyInFramesAutomatic }; +enum LatencyModes { FRAMERATE_ADAPTIVE, LATENCY_IN_FRAMES, LATENCY_IN_FRAMES_AUTOMATIC }; struct Int32XY { @@ -33,31 +34,57 @@ struct Destroy_Resource_Data class IGraphicsApi { public: + /// \brief ReShade version numbers read from the appropriate DLL. useful for when certain options only work in certain ReShade versions + /// These values are set on DLL_ATTACH int32_t reshade_version_nr_major = 0; int32_t reshade_version_nr_minor = 0; int32_t reshade_version_nr_patch = 0; + /// \brief Concatenates the reshade_version_nr_major/minor/patch into one number + /// \return A concatenated ReShade version code without periods. Example: 580 (instead of 5.8.0) int32_t get_concatinated_reshade_version(); - virtual void draw_debug_overlay(reshade::api::effect_runtime* runtime) = 0; - virtual void draw_sr_settings_overlay(reshade::api::effect_runtime* runtime) = 0; - virtual void draw_settings_overlay(reshade::api::effect_runtime* runtime) = 0; + /// \brief Responsible for drawing debug information in the ImGUI UI + /// \param runtime Represents the reshade effect runtime virtual void draw_status_overlay(reshade::api::effect_runtime* runtime) = 0; - virtual void on_reshade_finish_effects(reshade::api::effect_runtime* runtime, reshade::api::command_list* cmd_list, reshade::api::resource_view rtv, reshade::api::resource_view) = 0; + + /// \brief The main call responsible for weaving the image once ReShade is done drawing effects + /// \param runtime Represents the reshade effect runtime + /// \param cmd_list Represents the current command list from ReShade + /// \param rtv Represents the current render target view + /// \param rtv_srgb Represents the current render target view with the srgb color format + virtual void on_reshade_finish_effects(reshade::api::effect_runtime* runtime, reshade::api::command_list* cmd_list, reshade::api::resource_view rtv, reshade::api::resource_view rtv_srgb) = 0; + + /// \brief Method responsible for initializing SR related variables required for weaving + /// \param runtime Represents the reshade effect runtime virtual void on_init_effect_runtime(reshade::api::effect_runtime* runtime) = 0; - virtual void do_weave(bool doWeave) = 0; - virtual ~IGraphicsApi() = default; + /// \brief Sets the boolean that decides whether we are ready to weave or not. + /// \param do_weave Sets the interal value for do_weave to true or false. + virtual void do_weave(bool do_weave) = 0; + + /// \brief Allows user to get the current weaver latency mode + /// \return An enum representing the current latency mode of the weaver, see LatencyModes enum for more info virtual LatencyModes get_latency_mode() = 0; - // The two methods below return true if the latency was succesfully set, they return false if their current latency mode does not permit them to set the latency. + /// \brief Default destructor + virtual ~IGraphicsApi() = default; - // This method should only be called once, after which it will use the maximum framerate of the monitor in use to determine the latency of the eye tracker. - // This does NOT look at the current framerate, use this when you are able to consistently reach your monitor's maximum refresh rate. - // The numberOfFrames setting is overwritten when the latency mode is changed to latencyInFramesAutomatic. - // Sets the latency mode to latencyInFramesAutomatic if numberOfFrames is negative. - virtual bool set_latency_in_frames(int32_t numberOfFrames) = 0; + /// \brief Sets the weaver latency mode to latency in frames. + /// + /// This does NOT look at the current framerate or frametime, it is best used when you are able to consistently reach your monitor's VSYNC + /// Sets the latency mode to latencyInFramesAutomatic if number_of_frames is negative. + /// + /// \param number_of_frames The amount of frames or "buffers" between the application and the moment they are presented on-screen. If set to -1, this will use the back buffer count taken from the ReShade API automatically + /// \return Returns true if the latency was succesfully set, returns false if its current latency mode does not permit it to set the latency. + virtual bool set_latency_in_frames(int32_t number_of_frames) = 0; - // This method must be called every frame with the current frametime. - virtual bool set_latency_framerate_adaptive(uint32_t frametimeInMicroseconds) = 0; + /// \brief Sets the weaver latency to a static number of microseconds + /// + /// This method can be called every frame with the current frametime + /// The default is 40000 microseconds which is optimized for 60FPS VSYNCED gameplay + /// + /// \param frametime_in_microseconds The amount of microseconds it takes for a frame to be rendered and shown on screen. This is used for eye tracking prediction so accuracy is key. + /// \return Returns true if the latency was succesfully set, returns false if its current latency mode does not permit it to set the latency. + virtual bool set_latency_frametime_adaptive(uint32_t frametime_in_microseconds) = 0; }; diff --git a/gamebridge_reshade/src/pch.h b/gamebridge_reshade/src/pch.h index bf582ca..3fbf893 100644 --- a/gamebridge_reshade/src/pch.h +++ b/gamebridge_reshade/src/pch.h @@ -17,7 +17,7 @@ #define IMGUI_DISABLE_INCLUDE_IMCONFIG_H #define ImTextureID unsigned long long // Change ImGui texture ID type to that of a 'reshade::api::resource_view' handle -// add headers that you want to pre-compile here +// Add headers that you want to pre-compile here #include "framework.h" // Reshade @@ -27,13 +27,12 @@ // SR #include "sr/sense/eyetracker/eyetracker.h" #include "sr/sense/core/inputstream.h" -//#include "sr/sense/system/systemsense.h" //#include "sr/sense/system/systemevent.h" //Systemsense causes many warnings #include "sr/sense/display/switchablehint.h" #include "sr/utility/exception.h" #include "sr/types.h" // Global shortcut definition -enum shortcutType { toggle_SR, toggle_lens, toggle_3D, toggle_lens_and_3D, toggle_latency_mode }; +enum shortcutType { TOGGLE_SR, TOGGLE_LENS, TOGGLE_3D, TOGGLE_LENS_AND_3D, TOGGLE_LATENCY_MODE }; #endif //PCH_H From ddc1b43ad29a00208734200d52ebd426e1f37d88 Mon Sep 17 00:00:00 2001 From: BramTeurlings Date: Wed, 21 Feb 2024 14:50:17 +0100 Subject: [PATCH 2/5] Attempted to fix some color format issues Color formats are still messing up, check out the main branch version in Cities Skylines --- gamebridge_reshade/src/directx10weaver.cpp | 27 ++++++++++++++------ gamebridge_reshade/src/directx10weaver.h | 6 ++++- gamebridge_reshade/src/directx11weaver.cpp | 27 ++++++++++++++------ gamebridge_reshade/src/directx11weaver.h | 6 ++++- gamebridge_reshade/src/directx12weaver.cpp | 20 +++++++++++++++ gamebridge_reshade/src/directx12weaver.h | 4 +++ gamebridge_reshade/src/directx9weaver.cpp | 29 +++++++++++++++------- gamebridge_reshade/src/directx9weaver.h | 6 ++++- 8 files changed, 97 insertions(+), 28 deletions(-) diff --git a/gamebridge_reshade/src/directx10weaver.cpp b/gamebridge_reshade/src/directx10weaver.cpp index 08b3f5d..a7e3695 100644 --- a/gamebridge_reshade/src/directx10weaver.cpp +++ b/gamebridge_reshade/src/directx10weaver.cpp @@ -131,14 +131,8 @@ void DirectX10Weaver::on_reshade_finish_effects(reshade::api::effect_runtime* ru // Update current buffer format current_buffer_format = desc.texture.format; - // Check buffer format and see if it's in the list of known problematic ones. Change to SRGB rtv if so. - if ((std::find(srgb_color_formats.begin(), srgb_color_formats.end(), desc.texture.format) != srgb_color_formats.end())) { - // SRGB format detected, switch to SRGB buffer. - use_srgb_rtv = true; - } - else { - use_srgb_rtv = false; - } + // Update color format settings + check_color_format(desc); // Todo: Might have to get the buffer from the create_effect_copy_buffer function and only swap them when creation suceeds d3d10_device->destroy_resource(effect_frame_copy); @@ -168,6 +162,12 @@ void DirectX10Weaver::on_reshade_finish_effects(reshade::api::effect_runtime* ru } } else { + // Set current buffer format + current_buffer_format = desc.texture.format; + + // Set color format settings + check_color_format(desc); + create_effect_copy_buffer(desc); if (init_weaver(runtime, effect_frame_copy, cmd_list)) { // Set context and input frame buffer again to make sure they are correct @@ -219,6 +219,17 @@ void DirectX10Weaver::set_latency_mode(LatencyModes mode) { current_latency_mode = mode; } +void DirectX10Weaver::check_color_format(reshade::api::resource_desc desc) { + // Check buffer format and see if it's in the list of known SRGB ones. Change to SRGB rtv if so. + if ((std::find(srgb_color_formats.begin(), srgb_color_formats.end(), desc.texture.format) != srgb_color_formats.end())) { + // SRGB format detected, switch to SRGB buffer. + use_srgb_rtv = true; + } + else { + use_srgb_rtv = false; + } +} + LatencyModes DirectX10Weaver::get_latency_mode() { return current_latency_mode; } diff --git a/gamebridge_reshade/src/directx10weaver.h b/gamebridge_reshade/src/directx10weaver.h index 6d713ef..33f297c 100644 --- a/gamebridge_reshade/src/directx10weaver.h +++ b/gamebridge_reshade/src/directx10weaver.h @@ -24,7 +24,7 @@ class DirectX10Weaver: public IGraphicsApi { bool weaving_enabled = false; bool popup_window_visible = false; bool resize_buffer_failed = false; - bool use_srgb_rtv = true; + bool use_srgb_rtv = false; float view_separation = 0.f; float vertical_shift = 0.f; @@ -44,6 +44,10 @@ class DirectX10Weaver: public IGraphicsApi { /// \param mode The latency mode to persist void set_latency_mode(LatencyModes mode); + /// \brief Checks the current rtv buffer color format and chooses the correct rtv for weaving based on that. + /// \param desc Represents the current ReShade resource view + void DirectX10Weaver::check_color_format(reshade::api::resource_desc desc); + public: /// \brief Explicit constructor /// \param context Pointer to an already initialized SRContext diff --git a/gamebridge_reshade/src/directx11weaver.cpp b/gamebridge_reshade/src/directx11weaver.cpp index 8acadba..9db48c0 100644 --- a/gamebridge_reshade/src/directx11weaver.cpp +++ b/gamebridge_reshade/src/directx11weaver.cpp @@ -141,14 +141,8 @@ void DirectX11Weaver::on_reshade_finish_effects(reshade::api::effect_runtime* ru // Update current buffer format current_buffer_format = desc.texture.format; - // Check buffer format and see if it's in the list of known problematic ones. Change to SRGB rtv if so. - if ((std::find(srgb_color_formats.begin(), srgb_color_formats.end(), desc.texture.format) != srgb_color_formats.end())) { - // SRGB format detected, switch to SRGB buffer. - use_srgb_rtv = true; - } - else { - use_srgb_rtv = false; - } + // Update color format settings + check_color_format(desc); // Todo: Might have to get the buffer from the create_effect_copy_buffer function and only swap them when creation suceeds d3d11_device->destroy_resource(effect_frame_copy); @@ -178,6 +172,12 @@ void DirectX11Weaver::on_reshade_finish_effects(reshade::api::effect_runtime* ru } } else { + // Set current buffer format + current_buffer_format = desc.texture.format; + + // Set color format settings + check_color_format(desc); + create_effect_copy_buffer(desc); if (init_weaver(runtime, effect_frame_copy, cmd_list)) { // Set context and input frame buffer again to make sure they are correct @@ -230,6 +230,17 @@ void DirectX11Weaver::set_latency_mode(LatencyModes mode) { current_latency_mode = mode; } +void DirectX11Weaver::check_color_format(reshade::api::resource_desc desc) { + // Check buffer format and see if it's in the list of known SRGB ones. Change to SRGB rtv if so. + if ((std::find(srgb_color_formats.begin(), srgb_color_formats.end(), desc.texture.format) != srgb_color_formats.end())) { + // SRGB format detected, switch to SRGB buffer. + use_srgb_rtv = true; + } + else { + use_srgb_rtv = false; + } +} + LatencyModes DirectX11Weaver::get_latency_mode() { return current_latency_mode; } diff --git a/gamebridge_reshade/src/directx11weaver.h b/gamebridge_reshade/src/directx11weaver.h index dd47472..e38dab0 100644 --- a/gamebridge_reshade/src/directx11weaver.h +++ b/gamebridge_reshade/src/directx11weaver.h @@ -24,7 +24,7 @@ class DirectX11Weaver: public IGraphicsApi { bool weaving_enabled = false; bool popup_window_visible = false; bool resize_buffer_failed = false; - bool use_srgb_rtv = true; + bool use_srgb_rtv = false; float view_separation = 0.f; float vertical_shift = 0.f; @@ -44,6 +44,10 @@ class DirectX11Weaver: public IGraphicsApi { /// \param mode The latency mode to persist void set_latency_mode(LatencyModes mode); + /// \brief Checks the current rtv buffer color format and chooses the correct rtv for weaving based on that. + /// \param desc Represents the current ReShade resource view + void DirectX11Weaver::check_color_format(reshade::api::resource_desc desc); + public: /// \brief Explicit constructor /// \param context Pointer to an already initialized SRContext diff --git a/gamebridge_reshade/src/directx12weaver.cpp b/gamebridge_reshade/src/directx12weaver.cpp index 7abdfc7..7751c85 100644 --- a/gamebridge_reshade/src/directx12weaver.cpp +++ b/gamebridge_reshade/src/directx12weaver.cpp @@ -135,6 +135,9 @@ void DirectX12Weaver::on_reshade_finish_effects(reshade::api::effect_runtime* ru // Update current buffer format current_buffer_format = desc.texture.format; + // Update color format settings + check_color_format(desc); + // Check buffer format and see if it's in the list of known problematic ones. Change to SRGB rtv if so. if ((std::find(srgb_color_formats.begin(), srgb_color_formats.end(), desc.texture.format) != srgb_color_formats.end())) { // SRGB format detected, switch to SRGB buffer. @@ -181,6 +184,12 @@ void DirectX12Weaver::on_reshade_finish_effects(reshade::api::effect_runtime* ru } } else { + // Set current buffer format + current_buffer_format = desc.texture.format; + + // Set color format settings + check_color_format(desc); + create_effect_copy_buffer(desc); if (init_weaver(runtime, effect_frame_copy, d3d12_device->get_resource_from_view(chosen_rtv))) { //Set command list and input frame buffer again to make sure they are correct @@ -233,6 +242,17 @@ void DirectX12Weaver::set_latency_mode(LatencyModes mode) { current_latency_mode = mode; } +void DirectX12Weaver::check_color_format(reshade::api::resource_desc desc) { + // Check buffer format and see if it's in the list of known SRGB ones. Change to SRGB rtv if so. + if ((std::find(srgb_color_formats.begin(), srgb_color_formats.end(), desc.texture.format) != srgb_color_formats.end())) { + // SRGB format detected, switch to SRGB buffer. + use_srgb_rtv = true; + } + else { + use_srgb_rtv = false; + } +} + LatencyModes DirectX12Weaver::get_latency_mode() { return current_latency_mode; } diff --git a/gamebridge_reshade/src/directx12weaver.h b/gamebridge_reshade/src/directx12weaver.h index 7ab0506..f14b322 100644 --- a/gamebridge_reshade/src/directx12weaver.h +++ b/gamebridge_reshade/src/directx12weaver.h @@ -44,6 +44,10 @@ class DirectX12Weaver: public IGraphicsApi { /// \param mode The latency mode to persist void set_latency_mode(LatencyModes mode); + /// \brief Checks the current rtv buffer color format and chooses the correct rtv for weaving based on that. + /// \param desc Represents the current ReShade resource view + void DirectX12Weaver::check_color_format(reshade::api::resource_desc desc); + public: /// \brief Explicit constructor /// \param context Pointer to an already initialized SRContext diff --git a/gamebridge_reshade/src/directx9weaver.cpp b/gamebridge_reshade/src/directx9weaver.cpp index 09a3e2d..11804ee 100644 --- a/gamebridge_reshade/src/directx9weaver.cpp +++ b/gamebridge_reshade/src/directx9weaver.cpp @@ -123,15 +123,8 @@ void DirectX9Weaver::on_reshade_finish_effects(reshade::api::effect_runtime* run // Invalidate weaver device objects before resizing the resource. weaver->invalidateDeviceObjects(); - // Todo: Might have to get the buffer from the create_effect_copy_buffer function and only swap them when creation suceeds - // Check buffer format and see if it's in the list of known SRGB ones. Change to SRGB rtv if so. - if ((std::find(srgb_color_formats.begin(), srgb_color_formats.end(), desc.texture.format) != srgb_color_formats.end())) { - // SRGB format detected, switch to SRGB buffer. - use_srgb_rtv = true; - } - else { - use_srgb_rtv = false; - } + // Update color format settings. + check_color_format(desc); //TODO Might have to get the buffer from the create_effect_copy_buffer function and only swap them when creation suceeds d3d9_device->destroy_resource(effect_frame_copy); @@ -163,6 +156,12 @@ void DirectX9Weaver::on_reshade_finish_effects(reshade::api::effect_runtime* run } } else { + // Set current buffer format + current_buffer_format = desc.texture.format; + + // Set color format settings + check_color_format(desc); + create_effect_copy_buffer(desc); if (init_weaver(runtime, effect_frame_copy, cmd_list)) { // Set context and input frame buffer again to make sure they are correct @@ -214,6 +213,18 @@ void DirectX9Weaver::set_latency_mode(LatencyModes mode) { current_latency_mode = mode; } +void DirectX9Weaver::check_color_format(reshade::api::resource_desc desc) { + // Check buffer format and see if it's in the list of known SRGB ones. Change to SRGB rtv if so. + if ((std::find(srgb_color_formats.begin(), srgb_color_formats.end(), desc.texture.format) != srgb_color_formats.end())) { + // SRGB format detected, switch to SRGB buffer. + use_srgb_rtv = true; + } + else { + use_srgb_rtv = false; + } +} + LatencyModes DirectX9Weaver::get_latency_mode() { return current_latency_mode; } + diff --git a/gamebridge_reshade/src/directx9weaver.h b/gamebridge_reshade/src/directx9weaver.h index 042a01d..fd8f7f9 100644 --- a/gamebridge_reshade/src/directx9weaver.h +++ b/gamebridge_reshade/src/directx9weaver.h @@ -24,7 +24,7 @@ class DirectX9Weaver: public IGraphicsApi { bool weaving_enabled = false; bool popup_window_visible = false; bool resize_buffer_failed = false; - bool use_srgb_rtv = true; + bool use_srgb_rtv = false; float view_separation = 0.f; float vertical_shift = 0.f; @@ -44,6 +44,10 @@ class DirectX9Weaver: public IGraphicsApi { /// \param mode The latency mode to persist void set_latency_mode(LatencyModes mode); + /// \brief Checks the current rtv buffer color format and chooses the correct rtv for weaving based on that. + /// \param desc Represents the current ReShade resource view + void DirectX9Weaver::check_color_format(reshade::api::resource_desc desc); + public: /// \brief Explicit constructor /// \param context Pointer to an already initialized SRContext From 8370dc499cdb25124f8b017b0785d05888240ac8 Mon Sep 17 00:00:00 2001 From: Bram Teurlings Date: Wed, 6 Mar 2024 16:46:52 +0100 Subject: [PATCH 3/5] First round of reviews --- gamebridge_reshade/src/directx12weaver.cpp | 2 +- gamebridge_reshade/src/directx12weaver.h | 6 ++-- gamebridge_reshade/src/directx9weaver.cpp | 2 +- gamebridge_reshade/src/dllmain.cpp | 34 +++++++++++----------- gamebridge_reshade/src/hotkeyManager.h | 4 +-- gamebridge_reshade/src/hotkeymanager.cpp | 4 +-- 6 files changed, 26 insertions(+), 26 deletions(-) diff --git a/gamebridge_reshade/src/directx12weaver.cpp b/gamebridge_reshade/src/directx12weaver.cpp index 7751c85..537fdb7 100644 --- a/gamebridge_reshade/src/directx12weaver.cpp +++ b/gamebridge_reshade/src/directx12weaver.cpp @@ -192,7 +192,7 @@ void DirectX12Weaver::on_reshade_finish_effects(reshade::api::effect_runtime* ru create_effect_copy_buffer(desc); if (init_weaver(runtime, effect_frame_copy, d3d12_device->get_resource_from_view(chosen_rtv))) { - //Set command list and input frame buffer again to make sure they are correct + // Set command list and input frame buffer again to make sure they are correct weaver->setCommandList((ID3D12GraphicsCommandList*)cmd_list->get_native()); weaver->setInputFrameBuffer((ID3D12Resource*)effect_frame_copy.handle); } diff --git a/gamebridge_reshade/src/directx12weaver.h b/gamebridge_reshade/src/directx12weaver.h index f14b322..3d4a0e8 100644 --- a/gamebridge_reshade/src/directx12weaver.h +++ b/gamebridge_reshade/src/directx12weaver.h @@ -44,7 +44,7 @@ class DirectX12Weaver: public IGraphicsApi { /// \param mode The latency mode to persist void set_latency_mode(LatencyModes mode); - /// \brief Checks the current rtv buffer color format and chooses the correct rtv for weaving based on that. + /// \brief Checks the current color format of the RTV's back buffer and chooses the correct buffer from ReShade for weaving based on that. /// \param desc Represents the current ReShade resource view void DirectX12Weaver::check_color_format(reshade::api::resource_desc desc); @@ -55,8 +55,8 @@ class DirectX12Weaver: public IGraphicsApi { /// \brief Initialized the SR weaver appropriate for the graphics API /// \param runtime Represents the reshade effect runtime - /// \param rtv Represents the current render target view - /// \param back_buffer Represents the current back buffer from ReShade + /// \param rtv Represents the buffer that the weaver uses as a source to weave with + /// \param back_buffer Represents the current back buffer from ReShade, this is used by the weaver as output location /// \return A bool representing if the weaver was initialized successfully bool init_weaver(reshade::api::effect_runtime* runtime, reshade::api::resource rtv, reshade::api::resource back_buffer); diff --git a/gamebridge_reshade/src/directx9weaver.cpp b/gamebridge_reshade/src/directx9weaver.cpp index 11804ee..6d60b03 100644 --- a/gamebridge_reshade/src/directx9weaver.cpp +++ b/gamebridge_reshade/src/directx9weaver.cpp @@ -126,7 +126,7 @@ void DirectX9Weaver::on_reshade_finish_effects(reshade::api::effect_runtime* run // Update color format settings. check_color_format(desc); - //TODO Might have to get the buffer from the create_effect_copy_buffer function and only swap them when creation suceeds + // TODO Might have to get the buffer from the create_effect_copy_buffer function and only swap them when creation suceeds d3d9_device->destroy_resource(effect_frame_copy); if (!create_effect_copy_buffer(desc) && !resize_buffer_failed) { reshade::log_message(reshade::log_level::warning, "Couldn't create effect copy buffer, trying again next frame"); diff --git a/gamebridge_reshade/src/dllmain.cpp b/gamebridge_reshade/src/dllmain.cpp index c4a2a4e..57ddbde 100644 --- a/gamebridge_reshade/src/dllmain.cpp +++ b/gamebridge_reshade/src/dllmain.cpp @@ -33,7 +33,7 @@ SR::SRContext* sr_context = nullptr; SR::SwitchableLensHint* lens_hint = nullptr; HotKeyManager* hotKey_manager = nullptr; -//Currently we use this string to determine if we should toggle this shader on press of the shortcut. We can expand this to a list later. +// Currently we use this string to determine if we should toggle this shader on press of the shortcut. We can expand this to a list later. static const std::string depth_3D_shader_name = "SuperDepth3D"; static const std::string sr_shader_name = "SR"; static char g_charBuffer[CHAR_BUFFER_SIZE]; @@ -101,8 +101,8 @@ static void enumerate_techniques(reshade::api::effect_runtime* runtime, std::fun }); } -//Todo: Move this function outside of the dllmain. -//It was placed here because it needed access to the SRContext but it should be moved to another class for cleanliness sake. +// Todo: Move this function outside of the dllmain. +// It was placed here because it needed access to the SRContext but it should be moved to another class for cleanliness sake. static void execute_hot_key_function_by_type(std::map hot_key_list, reshade::api::effect_runtime* runtime) { std::map::iterator i; vector togglable_3D_effects = {}; @@ -111,23 +111,23 @@ static void execute_hot_key_function_by_type(std::map hot_ke for (i = hot_key_list.begin(); i != hot_key_list.end(); i++) { switch (i->first) { case shortcutType::TOGGLE_SR: - //Here we want to completely disable all SR related functions including the eye tracker, weaver, context etc. + // Here we want to completely disable all SR related functions including the eye tracker, weaver, context etc. break; case shortcutType::TOGGLE_LENS: - //Here we want to toggle to the lens and toggle weaving + // Here we want to toggle to the lens and toggle weaving if (i->second) { lens_hint->enable(); - //Bypass weave() call + // Bypass weave() call weaver_implementation->do_weave(true); } else { lens_hint->disable(); - //Bypass weave() call + // Bypass weave() call weaver_implementation->do_weave(false); } break; case shortcutType::TOGGLE_3D: - //Here we want to toggle Depth3D or any other 3D effect we use to create our second eye image. + // Here we want to toggle Depth3D or any other 3D effect we use to create our second eye image. enumerate_techniques(runtime, [&togglable_3D_effects](reshade::api::effect_runtime *runtime, reshade::api::effect_technique technique, string &name) { @@ -146,7 +146,7 @@ static void execute_hot_key_function_by_type(std::map hot_ke } break; case shortcutType::TOGGLE_LENS_AND_3D: - //Todo: This should look at the current state of the lens toggle and 3D toggle, then, flip those.This toggle having its own state isn't great. + // Todo: This should look at the current state of the lens toggle and 3D toggle, then, flip those.This toggle having its own state isn't great. if (i->second) { toggle_map = {{shortcutType::TOGGLE_LENS, true}, {shortcutType::TOGGLE_3D, true} }; } @@ -156,7 +156,7 @@ static void execute_hot_key_function_by_type(std::map hot_ke execute_hot_key_function_by_type(toggle_map, runtime); break; case shortcutType::TOGGLE_LATENCY_MODE: - //Here we want to toggle the eye tracker latency mode between framerate-adaptive and latency-in-frames. + // Here we want to toggle the eye tracker latency mode between framerate-adaptive and latency-in-frames. if (i->second) { // Set the latency in frames to -1 to use ReShade's swap_chain buffer count. weaver_implementation->set_latency_in_frames(-1); @@ -168,7 +168,7 @@ static void execute_hot_key_function_by_type(std::map hot_ke // Set the latency to the SR default of 40000 microseconds (Tuned for 60Hz) weaver_implementation->set_latency_frametime_adaptive(g_default_weaver_latency); - //Log the current mode: + // Log the current mode: reshade::log_message(reshade::log_level::info, "Current latency mode set to: STATIC 40000 Microseconds"); } @@ -229,9 +229,9 @@ static void on_reshade_finish_effects(reshade::api::effect_runtime* runtime, res std::map hot_key_list; - //Check if certain hotkeys are being pressed + // Check if certain hotkeys are being pressed if (hotKey_manager != nullptr) { - //Find out which hotkeys have changed their toggled state, then execute their respective code. + // Find out which hotkeys have changed their toggled state, then execute their respective code. hot_key_list = hotKey_manager->check_hot_keys(runtime, sr_context); execute_hot_key_function_by_type(hot_key_list, runtime); } @@ -243,7 +243,7 @@ static void on_reshade_finish_effects(reshade::api::effect_runtime* runtime, res } static bool init_sr() { - //Construct SR Context and senses + // Construct SR Context and senses if (sr_context == nullptr) { try { sr_context = new SR::SRContext; @@ -268,13 +268,13 @@ static void on_init_effect_runtime(reshade::api::effect_runtime* runtime) { return; } - //Todo: Move these hard-coded hotkeys to user-definable hotkeys in the .ini file - //Register some standard hotkeys + // Todo: Move these hard-coded hotkeys to user-definable hotkeys in the .ini file + // Register some standard hotkeys if (hotKey_manager == nullptr) { hotKey_manager = new HotKeyManager(); } - //Then, check the active graphics API and pass it a new context. + // Then, check the active graphics API and pass it a new context. if (weaver_implementation == nullptr) { switch (runtime->get_device()->get_api()) { case reshade::api::device_api::d3d9: diff --git a/gamebridge_reshade/src/hotkeyManager.h b/gamebridge_reshade/src/hotkeyManager.h index 7f27404..20f3e30 100644 --- a/gamebridge_reshade/src/hotkeyManager.h +++ b/gamebridge_reshade/src/hotkeyManager.h @@ -16,10 +16,10 @@ class HotKeyManager { public: HotKeyManager(); std::map check_hot_keys(reshade::api::effect_runtime* runtime, SR::SRContext* context); - //Todo: Implement a way to edit and create now hotkeys? + // Todo: Implement a way to edit and create now hotkeys? void edit_hot_key(uint8_t hot_key_id); private: - //Todo: We should define these in a .ini file eventually. + // Todo: We should define these in a .ini file eventually. std::vector registered_hot_keys; }; diff --git a/gamebridge_reshade/src/hotkeymanager.cpp b/gamebridge_reshade/src/hotkeymanager.cpp index 55d0f2c..d3f77a4 100644 --- a/gamebridge_reshade/src/hotkeymanager.cpp +++ b/gamebridge_reshade/src/hotkeymanager.cpp @@ -51,9 +51,9 @@ std::map HotKeyManager::check_hot_keys(reshade::api::effect_ // This might be pretty slow but for now it will do since we only ever have 3 hotkeys. for (int i = 0; i < registered_hot_keys.size(); i++) { if (runtime->is_key_pressed(registered_hot_keys[i].get_key())) { - //Hotkey is being pressed, now check for the modifier keys. + // Hotkey is being pressed, now check for the modifier keys. if (check_modifier_keys(registered_hot_keys[i], runtime)) { - //All conditions are met, execute hotkey logic. + // All conditions are met, execute hotkey logic. registered_hot_keys[i].toggle_hot_key(); toggled_hot_keys[registered_hot_keys[i].get_type()] = registered_hot_keys[i].get_enabled(); } From 3b142d2f90eecfc902b3cec06d589251cd52f377 Mon Sep 17 00:00:00 2001 From: BramTeurlings Date: Mon, 18 Mar 2024 14:20:36 +0100 Subject: [PATCH 4/5] Changed some includes, corrected some documentation --- gamebridge_reshade/src/directx10weaver.cpp | 3 +++ gamebridge_reshade/src/directx10weaver.h | 7 ++----- gamebridge_reshade/src/directx11weaver.cpp | 3 ++- gamebridge_reshade/src/directx11weaver.h | 7 ++----- gamebridge_reshade/src/directx12weaver.cpp | 3 +++ gamebridge_reshade/src/directx12weaver.h | 9 +++------ gamebridge_reshade/src/directx9weaver.cpp | 3 +++ gamebridge_reshade/src/directx9weaver.h | 7 ++----- gamebridge_reshade/src/igraphicsapi.h | 10 ---------- 9 files changed, 20 insertions(+), 32 deletions(-) diff --git a/gamebridge_reshade/src/directx10weaver.cpp b/gamebridge_reshade/src/directx10weaver.cpp index a7e3695..0e017eb 100644 --- a/gamebridge_reshade/src/directx10weaver.cpp +++ b/gamebridge_reshade/src/directx10weaver.cpp @@ -7,6 +7,9 @@ #include "directx10weaver.h" +// Directx +#include + DirectX10Weaver::DirectX10Weaver(SR::SRContext* context) { // Set context here. sr_context = context; diff --git a/gamebridge_reshade/src/directx10weaver.h b/gamebridge_reshade/src/directx10weaver.h index 33f297c..12250af 100644 --- a/gamebridge_reshade/src/directx10weaver.h +++ b/gamebridge_reshade/src/directx10weaver.h @@ -13,9 +13,6 @@ #include "igraphicsapi.h" #include "pch.h" -// Directx -#include - class DirectX10Weaver: public IGraphicsApi { uint32_t last_latency_frame_time_set = g_default_weaver_latency; uint32_t effect_frame_copy_x = 0, effect_frame_copy_y = 0; @@ -60,8 +57,8 @@ class DirectX10Weaver: public IGraphicsApi { /// \return A bool representing if the weaver was initialized successfully bool init_weaver(reshade::api::effect_runtime* runtime, reshade::api::resource rtv, reshade::api::command_list* cmd_list); - /// \brief Method that creates a copy of the RTV so we can weave on it - /// \param effect_resource_desc ReShade resource representing the currently selected RTV + /// \brief Creates and reset the effect copy resource so it is similar to the back buffer resource, then use it as weaver input. + /// \param effect_resource_desc ReShade resource representing the currently selected back buffer description /// \return A bool respresenting if the effect frame copy was successful bool create_effect_copy_buffer(const reshade::api::resource_desc& effect_resource_desc); diff --git a/gamebridge_reshade/src/directx11weaver.cpp b/gamebridge_reshade/src/directx11weaver.cpp index 9db48c0..9db88cf 100644 --- a/gamebridge_reshade/src/directx11weaver.cpp +++ b/gamebridge_reshade/src/directx11weaver.cpp @@ -7,7 +7,8 @@ #include "directx11weaver.h" -#include +// Directx +#include DirectX11Weaver::DirectX11Weaver(SR::SRContext* context) { // Set context here. diff --git a/gamebridge_reshade/src/directx11weaver.h b/gamebridge_reshade/src/directx11weaver.h index e38dab0..27f948b 100644 --- a/gamebridge_reshade/src/directx11weaver.h +++ b/gamebridge_reshade/src/directx11weaver.h @@ -13,9 +13,6 @@ #include "igraphicsapi.h" #include "pch.h" -// Directx -#include - class DirectX11Weaver: public IGraphicsApi { uint32_t last_latency_frame_time_set = g_default_weaver_latency; uint32_t effect_frame_copy_x = 0, effect_frame_copy_y = 0; @@ -60,8 +57,8 @@ class DirectX11Weaver: public IGraphicsApi { /// \return A bool representing if the weaver was initialized successfully bool init_weaver(reshade::api::effect_runtime* runtime, reshade::api::resource rtv, reshade::api::command_list* cmd_list); - /// \brief Method that creates a copy of the RTV so we can weave on it - /// \param effect_resource_desc ReShade resource representing the currently selected RTV + /// \brief Creates and reset the effect copy resource so it is similar to the back buffer resource, then use it as weaver input. + /// \param effect_resource_desc ReShade resource representing the currently selected back buffer description /// \return A bool respresenting if the effect frame copy was successful bool create_effect_copy_buffer(const reshade::api::resource_desc& effect_resource_desc); diff --git a/gamebridge_reshade/src/directx12weaver.cpp b/gamebridge_reshade/src/directx12weaver.cpp index 537fdb7..501b657 100644 --- a/gamebridge_reshade/src/directx12weaver.cpp +++ b/gamebridge_reshade/src/directx12weaver.cpp @@ -7,6 +7,9 @@ #include "directx12weaver.h" +// Directx +#include + DirectX12Weaver::DirectX12Weaver(SR::SRContext* context) { // Set context here. sr_context = context; diff --git a/gamebridge_reshade/src/directx12weaver.h b/gamebridge_reshade/src/directx12weaver.h index 3d4a0e8..6de0787 100644 --- a/gamebridge_reshade/src/directx12weaver.h +++ b/gamebridge_reshade/src/directx12weaver.h @@ -13,9 +13,6 @@ #include "igraphicsapi.h" #include "pch.h" -// Directx -#include - class DirectX12Weaver: public IGraphicsApi { uint32_t last_latency_frame_time_set = g_default_weaver_latency; uint32_t effect_frame_copy_x = 0, effect_frame_copy_y = 0; @@ -56,12 +53,12 @@ class DirectX12Weaver: public IGraphicsApi { /// \brief Initialized the SR weaver appropriate for the graphics API /// \param runtime Represents the reshade effect runtime /// \param rtv Represents the buffer that the weaver uses as a source to weave with - /// \param back_buffer Represents the current back buffer from ReShade, this is used by the weaver as output location + /// \param back_buffer Represents the current back buffer from ReShade /// \return A bool representing if the weaver was initialized successfully bool init_weaver(reshade::api::effect_runtime* runtime, reshade::api::resource rtv, reshade::api::resource back_buffer); - /// \brief Method that creates a copy of the RTV so we can weave on it - /// \param effect_resource_desc ReShade resource representing the currently selected RTV + /// \brief Creates and reset the effect copy resource so it is similar to the back buffer resource, then use it as weaver input. + /// \param effect_resource_desc ReShade resource representing the currently selected back buffer description /// \return A bool respresenting if the effect frame copy was successful bool create_effect_copy_buffer(const reshade::api::resource_desc& effect_resource_desc); diff --git a/gamebridge_reshade/src/directx9weaver.cpp b/gamebridge_reshade/src/directx9weaver.cpp index 6d60b03..0652c16 100644 --- a/gamebridge_reshade/src/directx9weaver.cpp +++ b/gamebridge_reshade/src/directx9weaver.cpp @@ -7,6 +7,9 @@ #include "directx9weaver.h" +// Directx +#include + DirectX9Weaver::DirectX9Weaver(SR::SRContext* context) { // Set context here. sr_context = context; diff --git a/gamebridge_reshade/src/directx9weaver.h b/gamebridge_reshade/src/directx9weaver.h index fd8f7f9..2f2ecf5 100644 --- a/gamebridge_reshade/src/directx9weaver.h +++ b/gamebridge_reshade/src/directx9weaver.h @@ -13,9 +13,6 @@ #include "igraphicsapi.h" #include "pch.h" -// Directx -#include - class DirectX9Weaver: public IGraphicsApi { uint32_t last_latency_frame_time_set = g_default_weaver_latency; uint32_t effect_frame_copy_x = 0, effect_frame_copy_y = 0; @@ -60,8 +57,8 @@ class DirectX9Weaver: public IGraphicsApi { /// \return A bool representing if the weaver was initialized successfully bool init_weaver(reshade::api::effect_runtime* runtime, reshade::api::resource rtv, reshade::api::command_list* cmd_list); - /// \brief Method that creates a copy of the RTV so we can weave on it - /// \param effect_resource_desc ReShade resource representing the currently selected RTV + /// \brief Creates and reset the effect copy resource so it is similar to the back buffer resource, then use it as weaver input. + /// \param effect_resource_desc ReShade resource representing the currently selected back buffer description /// \return A bool respresenting if the effect frame copy was successful bool create_effect_copy_buffer(const reshade::api::resource_desc& effect_resource_desc); diff --git a/gamebridge_reshade/src/igraphicsapi.h b/gamebridge_reshade/src/igraphicsapi.h index 43f378a..991c330 100644 --- a/gamebridge_reshade/src/igraphicsapi.h +++ b/gamebridge_reshade/src/igraphicsapi.h @@ -20,12 +20,6 @@ const uint32_t g_default_weaver_latency = 40000; // latencyInFramesAutomatic = gets the amount of buffers or "frames" from the backbuffer using the ReShade api every frame. enum LatencyModes { FRAMERATE_ADAPTIVE, LATENCY_IN_FRAMES, LATENCY_IN_FRAMES_AUTOMATIC }; -struct Int32XY -{ - uint32_t x = 0; - uint32_t y = 0; -}; - struct Destroy_Resource_Data { reshade::api::resource resource; @@ -71,19 +65,15 @@ class IGraphicsApi { virtual ~IGraphicsApi() = default; /// \brief Sets the weaver latency mode to latency in frames. - /// /// This does NOT look at the current framerate or frametime, it is best used when you are able to consistently reach your monitor's VSYNC /// Sets the latency mode to latencyInFramesAutomatic if number_of_frames is negative. - /// /// \param number_of_frames The amount of frames or "buffers" between the application and the moment they are presented on-screen. If set to -1, this will use the back buffer count taken from the ReShade API automatically /// \return Returns true if the latency was succesfully set, returns false if its current latency mode does not permit it to set the latency. virtual bool set_latency_in_frames(int32_t number_of_frames) = 0; /// \brief Sets the weaver latency to a static number of microseconds - /// /// This method can be called every frame with the current frametime /// The default is 40000 microseconds which is optimized for 60FPS VSYNCED gameplay - /// /// \param frametime_in_microseconds The amount of microseconds it takes for a frame to be rendered and shown on screen. This is used for eye tracking prediction so accuracy is key. /// \return Returns true if the latency was succesfully set, returns false if its current latency mode does not permit it to set the latency. virtual bool set_latency_frametime_adaptive(uint32_t frametime_in_microseconds) = 0; From c7db2deb5f57c54e8ef975fd5065ca13bd2bd4fb Mon Sep 17 00:00:00 2001 From: Bram Teurlings Date: Tue, 19 Mar 2024 10:07:32 +0100 Subject: [PATCH 5/5] Renamed globals to non global convention --- gamebridge_reshade/src/directx10weaver.cpp | 4 ++-- gamebridge_reshade/src/directx10weaver.h | 2 +- gamebridge_reshade/src/directx11weaver.cpp | 4 ++-- gamebridge_reshade/src/directx11weaver.h | 2 +- gamebridge_reshade/src/directx12weaver.cpp | 4 ++-- gamebridge_reshade/src/directx12weaver.h | 2 +- gamebridge_reshade/src/directx9weaver.cpp | 4 ++-- gamebridge_reshade/src/directx9weaver.h | 2 +- gamebridge_reshade/src/dllmain.cpp | 12 ++++++------ gamebridge_reshade/src/igraphicsapi.h | 2 +- 10 files changed, 19 insertions(+), 19 deletions(-) diff --git a/gamebridge_reshade/src/directx10weaver.cpp b/gamebridge_reshade/src/directx10weaver.cpp index 0e017eb..472a8a4 100644 --- a/gamebridge_reshade/src/directx10weaver.cpp +++ b/gamebridge_reshade/src/directx10weaver.cpp @@ -75,8 +75,8 @@ bool DirectX10Weaver::init_weaver(reshade::api::effect_runtime* runtime, reshade reshade::log_message(reshade::log_level::info, "Initialized weaver"); // Set mode to latency in frames by default. - set_latency_frametime_adaptive(g_default_weaver_latency); - std::string latency_log = "Current latency mode set to: STATIC " + std::to_string(g_default_weaver_latency) + " Microseconds"; + set_latency_frametime_adaptive(default_weaver_latency); + std::string latency_log = "Current latency mode set to: STATIC " + std::to_string(default_weaver_latency) + " Microseconds"; reshade::log_message(reshade::log_level::info, latency_log.c_str()); } catch (std::exception &e) { diff --git a/gamebridge_reshade/src/directx10weaver.h b/gamebridge_reshade/src/directx10weaver.h index 12250af..70e3dab 100644 --- a/gamebridge_reshade/src/directx10weaver.h +++ b/gamebridge_reshade/src/directx10weaver.h @@ -14,7 +14,7 @@ #include "pch.h" class DirectX10Weaver: public IGraphicsApi { - uint32_t last_latency_frame_time_set = g_default_weaver_latency; + uint32_t last_latency_frame_time_set = default_weaver_latency; uint32_t effect_frame_copy_x = 0, effect_frame_copy_y = 0; bool weaver_initialized = false; diff --git a/gamebridge_reshade/src/directx11weaver.cpp b/gamebridge_reshade/src/directx11weaver.cpp index 9db88cf..b183e8f 100644 --- a/gamebridge_reshade/src/directx11weaver.cpp +++ b/gamebridge_reshade/src/directx11weaver.cpp @@ -82,8 +82,8 @@ bool DirectX11Weaver::init_weaver(reshade::api::effect_runtime* runtime, reshade reshade::log_message(reshade::log_level::info, "Initialized weaver"); // Set mode to latency in frames by default. - set_latency_frametime_adaptive(g_default_weaver_latency); - std::string latency_log = "Current latency mode set to: STATIC " + std::to_string(g_default_weaver_latency) + " Microseconds"; + set_latency_frametime_adaptive(default_weaver_latency); + std::string latency_log = "Current latency mode set to: STATIC " + std::to_string(default_weaver_latency) + " Microseconds"; reshade::log_message(reshade::log_level::info, latency_log.c_str()); } catch (std::exception &e) { diff --git a/gamebridge_reshade/src/directx11weaver.h b/gamebridge_reshade/src/directx11weaver.h index 27f948b..637e9f9 100644 --- a/gamebridge_reshade/src/directx11weaver.h +++ b/gamebridge_reshade/src/directx11weaver.h @@ -14,7 +14,7 @@ #include "pch.h" class DirectX11Weaver: public IGraphicsApi { - uint32_t last_latency_frame_time_set = g_default_weaver_latency; + uint32_t last_latency_frame_time_set = default_weaver_latency; uint32_t effect_frame_copy_x = 0, effect_frame_copy_y = 0; bool weaver_initialized = false; diff --git a/gamebridge_reshade/src/directx12weaver.cpp b/gamebridge_reshade/src/directx12weaver.cpp index 501b657..1fb2f86 100644 --- a/gamebridge_reshade/src/directx12weaver.cpp +++ b/gamebridge_reshade/src/directx12weaver.cpp @@ -56,8 +56,8 @@ bool DirectX12Weaver::init_weaver(reshade::api::effect_runtime* runtime, reshade reshade::log_message(reshade::log_level::info, "Initialized weaver"); // Set mode to latency in frames by default. - set_latency_frametime_adaptive(g_default_weaver_latency); - std::string latency_log = "Current latency mode set to: STATIC " + std::to_string(g_default_weaver_latency) + " Microseconds"; + set_latency_frametime_adaptive(default_weaver_latency); + std::string latency_log = "Current latency mode set to: STATIC " + std::to_string(default_weaver_latency) + " Microseconds"; reshade::log_message(reshade::log_level::info, latency_log.c_str()); } catch (std::exception& e) { diff --git a/gamebridge_reshade/src/directx12weaver.h b/gamebridge_reshade/src/directx12weaver.h index 6de0787..f8d5f07 100644 --- a/gamebridge_reshade/src/directx12weaver.h +++ b/gamebridge_reshade/src/directx12weaver.h @@ -14,7 +14,7 @@ #include "pch.h" class DirectX12Weaver: public IGraphicsApi { - uint32_t last_latency_frame_time_set = g_default_weaver_latency; + uint32_t last_latency_frame_time_set = default_weaver_latency; uint32_t effect_frame_copy_x = 0, effect_frame_copy_y = 0; bool weaver_initialized = false; diff --git a/gamebridge_reshade/src/directx9weaver.cpp b/gamebridge_reshade/src/directx9weaver.cpp index 0652c16..3afa897 100644 --- a/gamebridge_reshade/src/directx9weaver.cpp +++ b/gamebridge_reshade/src/directx9weaver.cpp @@ -63,8 +63,8 @@ bool DirectX9Weaver::init_weaver(reshade::api::effect_runtime* runtime, reshade: reshade::log_message(reshade::log_level::info, "Initialized weaver"); // Set mode to latency in frames by default. - set_latency_frametime_adaptive(g_default_weaver_latency); - std::string latency_log = "Current latency mode set to: STATIC " + std::to_string(g_default_weaver_latency) + " Microseconds"; + set_latency_frametime_adaptive(default_weaver_latency); + std::string latency_log = "Current latency mode set to: STATIC " + std::to_string(default_weaver_latency) + " Microseconds"; reshade::log_message(reshade::log_level::info, latency_log.c_str()); } catch (std::exception &e) { diff --git a/gamebridge_reshade/src/directx9weaver.h b/gamebridge_reshade/src/directx9weaver.h index 2f2ecf5..532e10c 100644 --- a/gamebridge_reshade/src/directx9weaver.h +++ b/gamebridge_reshade/src/directx9weaver.h @@ -14,7 +14,7 @@ #include "pch.h" class DirectX9Weaver: public IGraphicsApi { - uint32_t last_latency_frame_time_set = g_default_weaver_latency; + uint32_t last_latency_frame_time_set = default_weaver_latency; uint32_t effect_frame_copy_x = 0, effect_frame_copy_y = 0; bool weaver_initialized = false; diff --git a/gamebridge_reshade/src/dllmain.cpp b/gamebridge_reshade/src/dllmain.cpp index 57ddbde..946550c 100644 --- a/gamebridge_reshade/src/dllmain.cpp +++ b/gamebridge_reshade/src/dllmain.cpp @@ -36,8 +36,8 @@ HotKeyManager* hotKey_manager = nullptr; // Currently we use this string to determine if we should toggle this shader on press of the shortcut. We can expand this to a list later. static const std::string depth_3D_shader_name = "SuperDepth3D"; static const std::string sr_shader_name = "SR"; -static char g_charBuffer[CHAR_BUFFER_SIZE]; -static size_t g_charBufferSize = CHAR_BUFFER_SIZE; +static char char_buffer[CHAR_BUFFER_SIZE]; +static size_t char_buffer_size = CHAR_BUFFER_SIZE; static bool effects_are_active = false; static bool sr_initialized = false; @@ -94,9 +94,9 @@ vector get_module_version_info(LPCWSTR moduleName) { static void enumerate_techniques(reshade::api::effect_runtime* runtime, std::function func) { runtime->enumerate_techniques(nullptr, [func](reshade::api::effect_runtime* rt, reshade::api::effect_technique technique) { - g_charBufferSize = CHAR_BUFFER_SIZE; - rt->get_technique_name(technique, g_charBuffer, &g_charBufferSize); - string name(g_charBuffer); + char_buffer_size = CHAR_BUFFER_SIZE; + rt->get_technique_name(technique, char_buffer, &char_buffer_size); + string name(char_buffer); func(rt, technique, name); }); } @@ -166,7 +166,7 @@ static void execute_hot_key_function_by_type(std::map hot_ke } else { // Set the latency to the SR default of 40000 microseconds (Tuned for 60Hz) - weaver_implementation->set_latency_frametime_adaptive(g_default_weaver_latency); + weaver_implementation->set_latency_frametime_adaptive(default_weaver_latency); // Log the current mode: reshade::log_message(reshade::log_level::info, "Current latency mode set to: STATIC 40000 Microseconds"); diff --git a/gamebridge_reshade/src/igraphicsapi.h b/gamebridge_reshade/src/igraphicsapi.h index 991c330..4ef7e16 100644 --- a/gamebridge_reshade/src/igraphicsapi.h +++ b/gamebridge_reshade/src/igraphicsapi.h @@ -14,7 +14,7 @@ const std::list srgb_color_formats { reshade::api::format::r8g8b8a8_unorm_srgb, }; -const uint32_t g_default_weaver_latency = 40000; +const uint32_t default_weaver_latency = 40000; // framerateAdaptive = provide an amount of time in microseconds in between weave() calls. // latencyInFrames = provide an amount of buffers or "frames" between the application and presenting to the screen. // latencyInFramesAutomatic = gets the amount of buffers or "frames" from the backbuffer using the ReShade api every frame.