Skip to content

Commit

Permalink
Merge branch 'clshortfuse:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
marat569 authored Nov 23, 2024
2 parents 980deaa + b41a51d commit 7da1146
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 26 deletions.
22 changes: 12 additions & 10 deletions src/devkit/addon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ struct PipelineBindDetails {
};

struct DrawDetails {
std::unordered_map<uint32_t, ResourceViewDetails> srv_binds;
std::unordered_map<uint32_t, ResourceViewDetails> uav_binds;
std::map<uint32_t, ResourceViewDetails> srv_binds;
std::map<uint32_t, ResourceViewDetails> uav_binds;
std::vector<PipelineBindDetails> pipeline_binds;
enum class DrawMethods {
PRESENT,
Expand All @@ -124,7 +124,7 @@ struct DrawDetails {
DRAW_INDEXED_OR_INDIRECT,
DISPATCH
} draw_method;
std::vector<ResourceViewDetails> render_targets;
std::map<uint32_t, ResourceViewDetails> render_targets;

[[nodiscard]] std::string DrawMethodString() const {
switch (draw_method) {
Expand Down Expand Up @@ -421,7 +421,7 @@ void OnPushDescriptors(

auto log_resource_view = [&](uint32_t index,
reshade::api::resource_view view,
std::unordered_map<uint32_t, ResourceViewDetails>& destination) {
std::map<uint32_t, ResourceViewDetails>& destination) {
if (view.handle == 0) return;

auto pair = device_data.pipeline_layout_params.find(layout.handle);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
19 changes: 11 additions & 8 deletions src/mods/swapchain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<reshade::api::resource_view*>(malloc(size));
memcpy(new_rtvs, rtvs, count);
bool changed = false;
auto& data = device->get_private_data<DeviceData>();
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);

Expand All @@ -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<reshade::api::resource_view*>(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) {
Expand Down
8 changes: 0 additions & 8 deletions src/utils/swapchain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 7da1146

Please sign in to comment.