diff --git a/src/devkit/addon.cpp b/src/devkit/addon.cpp index 831bc4bf..856fa8c2 100644 --- a/src/devkit/addon.cpp +++ b/src/devkit/addon.cpp @@ -114,8 +114,8 @@ struct PipelineBindDetails { }; struct DrawDetails { - std::unordered_map srv_binds; - std::unordered_map uav_binds; + std::map srv_binds; + std::map uav_binds; std::vector pipeline_binds; enum class DrawMethods { PRESENT, @@ -124,7 +124,7 @@ struct DrawDetails { DRAW_INDEXED_OR_INDIRECT, DISPATCH } draw_method; - std::vector render_targets; + std::map render_targets; [[nodiscard]] std::string DrawMethodString() const { switch (draw_method) { @@ -421,7 +421,7 @@ void OnPushDescriptors( auto log_resource_view = [&](uint32_t index, reshade::api::resource_view view, - std::unordered_map& destination) { + std::map& destination) { if (view.handle == 0) return; auto pair = device_data.pipeline_layout_params.find(layout.handle); @@ -585,10 +585,13 @@ bool OnDraw(reshade::api::command_list* cmd_list, DrawDetails::DrawMethods draw_ auto& draw_details = command_list_data.GetCurrentDrawDetails(); draw_details.draw_method = draw_method; draw_details.render_targets.clear(); + + uint32_t rtv_index = 0u; for (auto render_target : renodx::utils::swapchain::GetRenderTargets(cmd_list)) { - if (render_target.handle == 0u) continue; - draw_details.render_targets.push_back( - device_data.GetResourceViewDetails(render_target, device)); + if (render_target.handle != 0u) { + draw_details.render_targets[rtv_index] = device_data.GetResourceViewDetails(render_target, device); + } + ++rtv_index; } device_data.command_list_data.push_back(command_list_data); @@ -1045,15 +1048,14 @@ void RenderCapturePane(reshade::api::device* device, DeviceData& data) { } } - int render_target_index = 0; - for (auto& render_target : draw_details.render_targets) { + for (auto& [rtv_index, render_target] : draw_details.render_targets) { ++row_index; bool rtv_node_open = false; if (draw_node_open) { ImGui::TableNextRow(); ImGui::TableNextColumn(); ImGui::PushID(row_index); - rtv_node_open = ImGui::TreeNodeEx("", tree_node_flags | ImGuiTreeNodeFlags_DefaultOpen, "RTV%d", render_target_index++); + rtv_node_open = ImGui::TreeNodeEx("", tree_node_flags | ImGuiTreeNodeFlags_DefaultOpen, "RTV%d", rtv_index); ImGui::PopID(); ImGui::TableNextColumn(); diff --git a/src/mods/swapchain.hpp b/src/mods/swapchain.hpp index 82a6a62f..273401f5 100644 --- a/src/mods/swapchain.hpp +++ b/src/mods/swapchain.hpp @@ -1828,18 +1828,14 @@ static void RewriteRenderTargets( auto* device = cmd_list->get_device(); - size_t last_non_null = -1; + reshade::api::resource_view* new_rtvs = nullptr; - const size_t size = count * sizeof(reshade::api::resource_view); - auto* new_rtvs = static_cast(malloc(size)); - memcpy(new_rtvs, rtvs, count); bool changed = false; auto& data = device->get_private_data(); const std::unique_lock lock(data.mutex); - for (uint32_t i = 0; i < count; i++) { + for (uint32_t i = 0; i < count; ++i) { const reshade::api::resource_view resource_view = rtvs[i]; if (resource_view.handle == 0u) continue; - last_non_null = i; auto new_resource_view = GetResourceViewClone(device, &data, resource_view); @@ -1854,11 +1850,18 @@ static void RewriteRenderTargets( s << ") [" << i << "]"; reshade::log::message(reshade::log::level::debug, s.str().c_str()); #endif - changed = true; + if (!changed) { + const size_t size = count * sizeof(reshade::api::resource_view); + new_rtvs = static_cast(malloc(size)); + memcpy(new_rtvs, rtvs, size); + changed = true; + } new_rtvs[i] = new_resource_view; } if (!changed) return; - cmd_list->bind_render_targets_and_depth_stencil(last_non_null + 1, new_rtvs, dsv); + + cmd_list->bind_render_targets_and_depth_stencil(count, new_rtvs, dsv); + free(new_rtvs); } static void DiscardDescriptors(reshade::api::command_list* cmd_list) { diff --git a/src/utils/swapchain.hpp b/src/utils/swapchain.hpp index 3ebf681f..ffe11fa1 100644 --- a/src/utils/swapchain.hpp +++ b/src/utils/swapchain.hpp @@ -161,14 +161,6 @@ static void OnBindRenderTargetsAndDepthStencil( const bool found_swapchain_rtv = false; cmd_list_data.current_render_targets.assign(rtvs, rtvs + count); cmd_list_data.current_depth_stencil = dsv; - uint32_t counted = 0; - for (uint32_t i = 0; i < count; i++) { - const reshade::api::resource_view rtv = rtvs[i]; - if (rtv.handle != 0u) { - counted++; - } - } - cmd_list_data.current_render_targets.resize(counted); cmd_list_data.has_swapchain_render_target_dirty = true; }