Skip to content

Commit

Permalink
fix(mods::swapchain): apply and revert input layout on swapchain proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
clshortfuse committed Jan 5, 2025
1 parent b467db2 commit aedf818
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
8 changes: 8 additions & 0 deletions src/mods/swapchain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "../utils/mutex.hpp"
#include "../utils/pipeline.hpp"
#include "../utils/resource.hpp"
#include "../utils/state.hpp"
#include "../utils/swapchain.hpp"

namespace renodx::mods::swapchain {
Expand Down Expand Up @@ -830,6 +831,8 @@ static void DrawSwapChainProxy(reshade::api::swapchain* swapchain, reshade::api:
auto* device = swapchain->get_device();
auto& data = device->get_private_data<DeviceData>();

auto previous_state = renodx::utils::state::GetCurrentState(cmd_list);

if (std::addressof(data) == nullptr) return;

// std::shared_lock data_lock(data.mutex);
Expand Down Expand Up @@ -1002,6 +1005,10 @@ static void DrawSwapChainProxy(reshade::api::swapchain* swapchain, reshade::api:
}
queue->flush_immediate_command_list();

if (previous_state.has_value()) {
previous_state->Apply(cmd_list);
}

#ifdef DEBUG_LEVEL_2
reshade::log::message(reshade::log::level::debug, s.str().c_str());
#endif
Expand Down Expand Up @@ -2575,6 +2582,7 @@ template <typename T = float*>
static void Use(DWORD fdw_reason, T* new_injections = nullptr) {
renodx::utils::resource::Use(fdw_reason);
renodx::utils::swapchain::Use(fdw_reason);
renodx::utils::state::Use(fdw_reason);
if (use_resource_cloning) {
renodx::utils::descriptor::Use(fdw_reason);
}
Expand Down
15 changes: 9 additions & 6 deletions src/utils/pipeline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,18 @@ static reshade::api::pipeline CreateRenderPipeline(
reshade::api::blend_desc blend_state = {};
reshade::api::rasterizer_desc rasterizer_state = {.cull_mode = reshade::api::cull_mode::none};
reshade::api::depth_stencil_desc depth_stencil_state = {.depth_enable = false};
std::vector<reshade::api::input_element> input_layout;

std::vector<reshade::api::pipeline_subobject> subobjects = {
{.type = reshade::api::pipeline_subobject_type::render_target_formats, .count = 1, .data = &format},
{.type = reshade::api::pipeline_subobject_type::max_vertex_count, .count = 1, .data = &num_vertices},
{.type = reshade::api::pipeline_subobject_type::primitive_topology, .count = 1, .data = &topology},
{.type = reshade::api::pipeline_subobject_type::blend_state, .count = 1, .data = &blend_state},
{.type = reshade::api::pipeline_subobject_type::rasterizer_state, .count = 1, .data = &rasterizer_state},
{.type = reshade::api::pipeline_subobject_type::depth_stencil_state, .count = 1, .data = &depth_stencil_state},
{reshade::api::pipeline_subobject_type::render_target_formats, 1, &format},
{reshade::api::pipeline_subobject_type::max_vertex_count, 1, &num_vertices},
{reshade::api::pipeline_subobject_type::primitive_topology, 1, &topology},
{reshade::api::pipeline_subobject_type::blend_state, 1, &blend_state},
{reshade::api::pipeline_subobject_type::rasterizer_state, 1, &rasterizer_state},
{reshade::api::pipeline_subobject_type::depth_stencil_state, 1, &depth_stencil_state},
{reshade::api::pipeline_subobject_type::input_layout, static_cast<uint32_t>(input_layout.size()), input_layout.data()},
};

subobjects.reserve(6 + shaders.size());

std::vector<reshade::api::shader_desc> shader_descriptions;
Expand Down
6 changes: 5 additions & 1 deletion src/utils/state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#pragma once

#include <include/reshade.hpp>
#include <memory>
#include <optional>
#include <unordered_map>
#include <vector>

Expand Down Expand Up @@ -239,12 +241,14 @@ static void OnBindDescriptorTables(reshade::api::command_list* cmd_list,

static void OnResetCommandList(reshade::api::command_list* cmd_list) {
auto& data = cmd_list->get_private_data<CommandListData>();
if (std::addressof(data) == nullptr) return;
auto& state = data.current_state;
state.Clear();
}

static CommandListState GetCurrentState(reshade::api::command_list* cmd_list) {
static std::optional<CommandListState> GetCurrentState(reshade::api::command_list* cmd_list) {
auto& data = cmd_list->get_private_data<CommandListData>();
if (std::addressof(data) == nullptr) return std::nullopt;
return data.current_state;
}

Expand Down

0 comments on commit aedf818

Please sign in to comment.