Skip to content

Commit 3a2ac99

Browse files
committed
fix(utils::state): skip null descriptor tables during restore
1 parent aa0680e commit 3a2ac99

1 file changed

Lines changed: 41 additions & 17 deletions

File tree

src/utils/state.hpp

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ struct CommandListState {
4040
// Destroyed RTVs are not removed
4141
std::vector<reshade::api::resource_view> new_rtvs = render_targets;
4242
size_t len = render_targets.size();
43-
auto* device = cmd_list->get_device();
4443
for (size_t i = 0; i < len; ++i) {
4544
const auto& rtv = render_targets[i];
4645
if (!renodx::utils::resource::IsKnownResourceView(rtv)) {
@@ -80,22 +79,47 @@ struct CommandListState {
8079
cmd_list->bind_scissor_rects(0, static_cast<uint32_t>(scissor_rects.size()), scissor_rects.data());
8180
}
8281

83-
if (graphics_pipeline_layout.handle != 0u) {
84-
cmd_list->bind_descriptor_tables(
85-
reshade::api::shader_stage::all_graphics,
86-
graphics_pipeline_layout,
87-
0,
88-
static_cast<uint32_t>(graphics_descriptor_tables.size()),
89-
graphics_descriptor_tables.data());
90-
}
91-
if (compute_pipeline_layout.handle != 0u) {
92-
cmd_list->bind_descriptor_tables(
93-
reshade::api::shader_stage::all_compute,
94-
compute_pipeline_layout,
95-
0,
96-
static_cast<uint32_t>(compute_descriptor_tables.size()),
97-
compute_descriptor_tables.data());
98-
}
82+
const bool is_d3d12 = cmd_list->get_device()->get_api() == reshade::api::device_api::d3d12;
83+
const auto bind_descriptor_tables = [&](reshade::api::shader_stage stages,
84+
reshade::api::pipeline_layout layout,
85+
const std::vector<reshade::api::descriptor_table>& tables) {
86+
if (layout.handle == 0u) return;
87+
88+
if (is_d3d12) {
89+
bool bound_table = false;
90+
for (uint32_t index = 0; index < tables.size(); ++index) {
91+
if (tables[index].handle == 0u) continue;
92+
cmd_list->bind_descriptor_tables(stages, layout, index, 1u, &tables[index]);
93+
bound_table = true;
94+
}
95+
96+
if (!bound_table) {
97+
cmd_list->bind_descriptor_tables(stages, layout, 0u, 0u, nullptr);
98+
}
99+
return;
100+
}
101+
102+
if (tables.empty()) return;
103+
104+
size_t index = 0;
105+
while (index < tables.size()) {
106+
while (index < tables.size() && tables[index].handle == 0u) {
107+
++index;
108+
}
109+
if (index >= tables.size()) break;
110+
111+
const size_t first = index;
112+
while (index < tables.size() && tables[index].handle != 0u) {
113+
++index;
114+
}
115+
const auto count = static_cast<uint32_t>(index - first);
116+
117+
cmd_list->bind_descriptor_tables(stages, layout, static_cast<uint32_t>(first), count, tables.data() + first);
118+
}
119+
};
120+
121+
bind_descriptor_tables(reshade::api::shader_stage::all_graphics, graphics_pipeline_layout, graphics_descriptor_tables);
122+
bind_descriptor_tables(reshade::api::shader_stage::all_compute, compute_pipeline_layout, compute_descriptor_tables);
99123
}
100124

101125
void Clear() {

0 commit comments

Comments
 (0)