| 930 | } |
| 931 | |
| 932 | static void on_begin_render_effects(effect_runtime *runtime, command_list *cmd_list, resource_view, resource_view) |
| 933 | { |
| 934 | device *const device = runtime->get_device(); |
| 935 | generic_depth_device_data *const device_data = device->get_private_data<generic_depth_device_data>(); |
| 936 | |
| 937 | if (device_data == nullptr) |
| 938 | return; |
| 939 | |
| 940 | auto &data = *runtime->get_private_data<generic_depth_data>(); |
| 941 | |
| 942 | resource selected_depth_stencil = { 0 }; |
| 943 | const depth_stencil_resource *selected_depth_stencil_info = nullptr; |
| 944 | |
| 945 | uint32_t frame_width, frame_height; |
| 946 | runtime->get_screenshot_width_and_height(&frame_width, &frame_height); |
| 947 | |
| 948 | std::shared_lock<std::shared_mutex> lock(s_mutex); |
| 949 | const std::unordered_map<resource, depth_stencil_resource, resource_hash> current_depth_stencil_resources = device_data->depth_stencil_resources; |
| 950 | // Unlock before calling into device below, since device may hold a lock itself and that then can deadlock another thread that calls into 'on_destroy_resource' from the device holding that lock |
| 951 | lock.unlock(); |
| 952 | |
| 953 | for (auto &[depth_stencil, info] : current_depth_stencil_resources) |
| 954 | { |
| 955 | if (info.last_frame_stats.total.drawcalls == 0 || (info.last_frame_stats.total.vertices <= 3 && info.last_frame_stats.total.drawcalls_indirect == 0)) |
| 956 | continue; // Skip unused |
| 957 | |
| 958 | if (info.last_used_in_frame < device_data->frame_index || device_data->frame_index <= (info.first_used_in_frame + 1)) |
| 959 | continue; // Skip resources not used this frame or those that only just appeared for the first time |
| 960 | |
| 961 | if (info.desc.texture.samples > 1 && !device->check_capability(device_caps::resolve_depth_stencil)) |
| 962 | continue; // Ignore multisampled textures, since they would need to be resolved first |
| 963 | |
| 964 | if (s_format_filtering != 0 && !check_depth_format(info.desc.texture.format)) |
| 965 | continue; |
| 966 | if (s_aspect_ratio_heuristic != aspect_ratio_heuristic::none && !check_aspect_ratio(static_cast<float>(info.desc.texture.width), static_cast<float>(info.desc.texture.height), static_cast<float>(frame_width), static_cast<float>(frame_height))) |
| 967 | continue; // Not a good fit |
| 968 | |
| 969 | if (selected_depth_stencil.handle == 0 || |
| 970 | info.last_frame_stats.total > selected_depth_stencil_info->last_frame_stats.total) |
| 971 | { |
| 972 | selected_depth_stencil = depth_stencil; |
| 973 | selected_depth_stencil_info = &info; |
| 974 | } |
| 975 | } |
| 976 | |
| 977 | if (data.override_depth_stencil != 0) |
| 978 | { |
| 979 | const auto it = current_depth_stencil_resources.find(data.override_depth_stencil); |
| 980 | if (it != current_depth_stencil_resources.end()) |
| 981 | { |
| 982 | selected_depth_stencil = it->first; |
| 983 | selected_depth_stencil_info = &it->second; |
| 984 | } |
| 985 | } |
| 986 | |
| 987 | const resource_view prev_shader_resource = data.selected_shader_resource; |
| 988 | |
| 989 | if (selected_depth_stencil != 0) do |
nothing calls this directly
no test coverage detected