diff --git a/crates/metal2vulkan-runtime/examples/host_ab/gpu.rs b/crates/metal2vulkan-runtime/examples/host_ab/gpu.rs index 4f0c467ea..c3b78fccb 100644 --- a/crates/metal2vulkan-runtime/examples/host_ab/gpu.rs +++ b/crates/metal2vulkan-runtime/examples/host_ab/gpu.rs @@ -524,8 +524,9 @@ pub trait Gpu { /// outlives the call. unsafe fn driver_floor(&self, _windows: usize, _pages: *mut u8) {} - /// The side's own counts of the work its calls made, by name, as they stand: the runtime's - /// `WorkCounts` the compositing and burst workloads report; none natively. + /// The side's own counts of the work its calls made, by name, as they stand: every scalar + /// count of the runtime's `WorkCounts`, which the compositing and burst workloads report a + /// few of and the per-call table reports every one a call moved; none natively. fn work_counts(&self) -> Vec<(&'static str, f64)> { Vec::new() } diff --git a/crates/metal2vulkan-runtime/examples/host_ab/percall.rs b/crates/metal2vulkan-runtime/examples/host_ab/percall.rs index 285e402b0..bc298d777 100644 --- a/crates/metal2vulkan-runtime/examples/host_ab/percall.rs +++ b/crates/metal2vulkan-runtime/examples/host_ab/percall.rs @@ -19,10 +19,18 @@ //! - `_drain_others`: our other threads' CPU time in that drain; //! - `_allocs`: the heap allocations a call made on the calling thread; //! - `_rt_`: the runtime's own counts of what the calls made, where they moved -//! ([`COUNTERS`]); none natively, so these rows have no ratio. +//! ([`counted`]); none natively, so these rows have no ratio. Every count the runtime keeps is +//! reported where a call moved it, and `_at_call` and `_at_commit` say whether the call paid +//! for it or left it for the commit — including the driver's own makings, which the runtime +//! counts where it calls them (`churn_counts.rs`), so a creation call's driver share is a count +//! and not an inference from the driver floor below the table. //! //! The wall times are a median over the windows, and the rest the group's totals over its //! calls, because the thread and process CPU clocks answer in microseconds. +//! +//! The counts are also the table's **gate**: [`HELD`] holds named calls to what they were +//! measured making, and the run fails where one makes more. A count is deterministic, so it holds +//! in CI under any load, where none of the times above can. use crate::gpu::{Format, Gpu}; use crate::workloads::{emit, host_pages, process_cpu, thread_cpu, Scene, Sizes, TARGET_SIDE}; @@ -31,26 +39,13 @@ use std::time::{Duration, Instant}; /// The windows a group runs before the measured ones. const WARM: usize = 3; -/// The runtime's counts a group reports per call where they moved: what its calls made the -/// driver, and our own threads, do ([`Gpu::work_counts`]; none natively). -const COUNTERS: [&str; 16] = [ - "queue_submissions", - "pipeline_barriers", - "draws", - "dispatches", - "render_passes_begun", - "requirement_images_made", - "images_own_memory", - "arena_pools_made", - "command_pools_made", - "wakes_handler_threads", - "scheduler_passes", - "variant_pipelines_made", - "host_pointer_imports_made", - "completed_waits", - "device_memory_bytes", - "cleared_bytes", -]; +/// Whether a count of the side's own ([`Gpu::work_counts`]) belongs in the table: every count +/// of work does, and the accumulators of nanoseconds do not, since a time is not a fact a gate +/// can hold. Every other count the side keeps is reported where a group's calls moved it, so no +/// family of work is left out of a call's row by an allowlist nobody revisits. +fn counted(name: &str) -> bool { + !name.ends_with("_nanos") +} /// What each group's call is on the runtime's public API, one entry a group: the group's name, /// then the methods it calls, `Type::method`. [`group`] fails for a group that is not named here @@ -188,11 +183,11 @@ pub const TIMED: [(&str, &str); 60] = [ ("replace_region_256", "Texture::replace_region"), ]; -/// The counts of [`COUNTERS`] that moved between two readings of the side's own counts, and by +/// The counts [`counted`] keeps that moved between two readings of the side's own counts, and by /// how much: none at all on a side that keeps none. fn moved(from: &[(&'static str, f64)], to: &[(&'static str, f64)]) -> Vec<(&'static str, f64)> { from.iter() - .filter(|(counted, _)| COUNTERS.contains(counted)) + .filter(|(name, _)| counted(name)) .filter_map(|(counted, before)| { let now = to .iter() @@ -337,51 +332,173 @@ pub fn group( let drained = g.work_counts(); (made, moved(&opened, &called), moved(&called, &drained)) }); - emit( - "percall", - &metric("allocs"), - "allocs/call", - &mut [made as f64 / inner as f64], - ); - for (counted, count) in at_call { + // The counts this group measured, under the names the table prints, so [`HELD`]'s rows for it + // are checked against the same numbers the report shows. + let mut measured: Vec<(String, f64)> = vec![]; + let mut keep = |what: String, value: f64| { emit( "percall", - &metric(&format!("rt_{counted}_at_call")), - "count/call", - &mut [count / inner as f64], + &metric(&what), + if what == "allocs" { + "allocs/call" + } else { + "count/call" + }, + &mut [value], ); + measured.push((what, value)); + }; + keep("allocs".to_owned(), made as f64 / inner as f64); + for (counted, count) in at_call { + keep(format!("rt_{counted}_at_call"), count / inner as f64); } for (counted, count) in at_drain { - emit( - "percall", - &metric(&format!("rt_{counted}_at_commit")), - "count/call", - &mut [count / inner as f64], - ); + keep(format!("rt_{counted}_at_commit"), count / inner as f64); } // What the measured windows' calls made the runtime do, per call. - for (counted, from) in &before { - if !COUNTERS.contains(counted) { + for (which, from) in &before { + if !counted(which) { continue; } let now = after .iter() - .find(|(name, _)| name == counted) + .find(|(counted, _)| counted == which) .map_or(0.0, |(_, count)| *count); assert!( - *counted != "variant_pipelines_made" || now <= *from, + *which != "variant_pipelines_made" || now <= *from, "{name}: {} pipeline states were made inside its timed windows", now - from ); if now > *from { - emit( - "percall", - &metric(&format!("rt_{counted}")), - "count/call", - &mut [(now - from) / calls], - ); + keep(format!("rt_{which}"), (now - from) / calls); } } + // The side that keeps no counts of its own is Metal's, which has no counterpart for any of + // these, so only ours is held to them. + if !before.is_empty() { + hold(name, &measured); + } +} + +/// What a call must have made, per call: the group, the count under the name the table prints +/// (`allocs`, or `rt__at_call` and `rt__at_commit` for the runtime's own counts), +/// and the most a call of it may make. A count a group never moved is not printed, and reads as +/// zero here, so a row of `0.0` holds a call to making none of that work at all. +/// +/// These are the gate on the cost half. A count is the same under any load and on any host, so a +/// regression reads "this call now makes two allocations where it made none" and fails the run, +/// where a 12% change in a time would not. Each row is a fact measured on this M3 Max that the +/// runtime should not quietly lose: an upper bound, so a call that does *less* work passes and the +/// row is then tightened. +const HELD: [(&str, &str, f64); 43] = [ + // A draw records exactly one draw command and makes no driver object: the cost it pays at the + // call is planning, which is settled work and nothing a driver charges for. + ("draw_strip", "rt_draws_at_commit", 1.0), + ("draw_strip", "rt_draws_at_call", 0.0), + ("draw_strip", "rt_vk_images_made_at_call", 0.0), + ("draw_strip", "rt_vk_buffers_made_at_call", 0.0), + ("draw_strip", "rt_vk_memory_allocations_at_call", 0.0), + ("draw_triangles", "rt_draws_at_commit", 1.0), + ( + "draw_indexed", + "rt_replayed_cmd_draw_indexed_at_commit", + 1.0, + ), + // And it allocates about once in twenty draws (0.049 measured), nothing a draw of its own. + ("draw_strip", "allocs", 0.2), + ("draw_triangles", "allocs", 0.2), + ("draw_indexed", "allocs", 0.2), + // The draw's settling is three lookups that each find what an earlier draw made: a draw that + // starts recording shapes or sets again would show here before it showed in a time. + ("draw_strip", "rt_draw_shapes_made_at_call", 0.0), + ("draw_strip", "rt_sampler_sets_made_at_call", 0.0), + ("draw_strip", "rt_live_tables_uploaded_at_call", 0.0), + // The render pass is begun at the commit, never at the call, and ending the encoding makes no + // driver object. Its 25 allocations are the largest counted quantity on the path. + ("end_render", "rt_render_passes_begun_at_call", 0.0), + ("end_render", "rt_vk_images_made_at_call", 0.0), + ("end_render", "allocs", 25.0), + ("end_compute", "allocs", 7.0), + ("end_blit", "allocs", 7.0), + ("dispatch", "rt_dispatches_at_commit", 1.0), + ("dispatch", "allocs", 19.0), + // A heap texture's image takes its storage from the heap: one image and one binding, and no + // allocation of memory of its own. + ("heap_texture_256", "rt_vk_images_made_at_call", 1.0), + ("heap_texture_256", "rt_vk_image_bindings_at_call", 1.0), + ("heap_texture_256", "rt_vk_memory_allocations_at_call", 0.0), + ("heap_texture_256", "allocs", 19.0), + // A Shared texture likewise, and it starts its image on the host once. + ("texture_256_shared", "rt_vk_images_made_at_call", 1.0), + ("texture_256_shared", "rt_vk_image_bindings_at_call", 1.0), + ( + "texture_256_shared", + "rt_vk_memory_allocations_at_call", + 0.0, + ), + ( + "texture_256_shared", + "rt_images_started_on_the_host_at_call", + 1.0, + ), + ("texture_256_shared", "allocs", 32.0), + // A render target of a shape the runtime has seen takes a parked image: it makes no image at + // all, which is why it costs what Metal's does. Losing the recycler here would cost 20 us a + // call and this row is what would say so. + ("texture_1024_target", "rt_vk_images_made_at_call", 0.0), + ( + "texture_1024_target", + "rt_vk_memory_allocations_at_call", + 0.0, + ), + // A texture over a buffer's bytes takes a parked image too, and makes one view of it. + ("buffer_texture_256", "rt_vk_images_made_at_call", 0.0), + ("buffer_texture_256", "rt_vk_image_views_made_at_call", 1.0), + // A buffer comes out of the runtime's memory pool: no `vkCreateBuffer`, no `vkAllocateMemory`. + ("buffer_4k", "rt_vk_buffers_made_at_call", 0.0), + ("buffer_4k", "rt_vk_memory_allocations_at_call", 0.0), + ("buffer_1m", "rt_vk_buffers_made_at_call", 0.0), + ("buffer_1m", "rt_vk_memory_allocations_at_call", 0.0), + // A no-copy buffer imports its pages once: one buffer, one import, one binding. A walk of the + // memory types that tried several would read as more than one allocation here. + ("buffer_no_copy_1m", "rt_vk_buffers_made_at_call", 1.0), + ("buffer_no_copy_1m", "rt_vk_memory_allocations_at_call", 1.0), + ("buffer_no_copy_1m", "rt_vk_buffer_bindings_at_call", 1.0), + // Residency is our own bookkeeping: no driver call, and the allocation a resource the standing + // cost of 256 of them. + ("use_resources_read_256", "rt_vk_buffers_made_at_call", 0.0), + ("use_resources_read_256", "allocs", 277.0), + // One Metal command buffer carrying one dispatch is submitted as two of Vulkan's. + ( + "commit_one_dispatch", + "rt_vk_command_buffers_submitted", + 2.0, + ), +]; + +/// Fail where a group's call made more work than [`HELD`] allows it, naming the call, the count, +/// what it made and what it is held to. +/// +/// A count a group never moved is not printed, so a row that names one reads zero and would pass +/// whatever the call did: a row holding a call to *some* work must therefore name a count the +/// group moved, or it is a misspelling that holds nothing, and that fails too. +fn hold(name: &str, measured: &[(String, f64)]) { + for (group, what, most) in HELD { + if group != name { + continue; + } + let made = measured.iter().find(|(counted, _)| counted == what); + assert!( + most <= 0.0 || made.is_some(), + "{name}: {what} is held to at most {most}, but the group moved no such count, so the \ + row holds nothing" + ); + let made = made.map_or(0.0, |(_, value)| *value); + assert!( + made <= most, + "{name}: {what} is {made} a call, where it is held to at most {most}" + ); + } } /// How many bytes of host pages the no-copy buffers of one window lie over, and how many such diff --git a/crates/metal2vulkan-runtime/examples/host_ab/runtime.rs b/crates/metal2vulkan-runtime/examples/host_ab/runtime.rs index 636d634bc..a83c190df 100644 --- a/crates/metal2vulkan-runtime/examples/host_ab/runtime.rs +++ b/crates/metal2vulkan-runtime/examples/host_ab/runtime.rs @@ -1294,6 +1294,816 @@ impl Gpu for Runtime { ("completed_waits", c.completed_waits), ("device_memory_bytes", c.device_memory_allocated), ("cleared_bytes", c.new_buffer_bytes_cleared), + ( + "replayed_begin_command_buffer", + replayed.begin_command_buffer, + ), + ("replayed_end_command_buffer", replayed.end_command_buffer), + ("replayed_cmd_bind_pipeline", replayed.cmd_bind_pipeline), + ("replayed_cmd_set_viewport", replayed.cmd_set_viewport), + ("replayed_cmd_set_scissor", replayed.cmd_set_scissor), + ("replayed_cmd_set_depth_bias", replayed.cmd_set_depth_bias), + ( + "replayed_cmd_set_blend_constants", + replayed.cmd_set_blend_constants, + ), + ( + "replayed_cmd_set_stencil_compare_mask", + replayed.cmd_set_stencil_compare_mask, + ), + ( + "replayed_cmd_set_stencil_write_mask", + replayed.cmd_set_stencil_write_mask, + ), + ( + "replayed_cmd_set_stencil_reference", + replayed.cmd_set_stencil_reference, + ), + ( + "replayed_cmd_bind_descriptor_sets", + replayed.cmd_bind_descriptor_sets, + ), + ( + "replayed_cmd_bind_index_buffer", + replayed.cmd_bind_index_buffer, + ), + ( + "replayed_cmd_bind_vertex_buffers", + replayed.cmd_bind_vertex_buffers, + ), + ("replayed_cmd_draw_indexed", replayed.cmd_draw_indexed), + ("replayed_cmd_draw_indirect", replayed.cmd_draw_indirect), + ( + "replayed_cmd_draw_indexed_indirect", + replayed.cmd_draw_indexed_indirect, + ), + ("replayed_cmd_copy_buffer", replayed.cmd_copy_buffer), + ("replayed_cmd_copy_image", replayed.cmd_copy_image), + ("replayed_cmd_blit_image", replayed.cmd_blit_image), + ( + "replayed_cmd_copy_buffer_to_image", + replayed.cmd_copy_buffer_to_image, + ), + ( + "replayed_cmd_copy_image_to_buffer", + replayed.cmd_copy_image_to_buffer, + ), + ("replayed_cmd_update_buffer", replayed.cmd_update_buffer), + ("replayed_cmd_fill_buffer", replayed.cmd_fill_buffer), + ( + "replayed_cmd_clear_color_image", + replayed.cmd_clear_color_image, + ), + ( + "replayed_cmd_clear_depth_stencil_image", + replayed.cmd_clear_depth_stencil_image, + ), + ( + "replayed_cmd_clear_attachments", + replayed.cmd_clear_attachments, + ), + ("replayed_cmd_begin_query", replayed.cmd_begin_query), + ("replayed_cmd_end_query", replayed.cmd_end_query), + ( + "replayed_cmd_reset_query_pool", + replayed.cmd_reset_query_pool, + ), + ("replayed_cmd_write_timestamp", replayed.cmd_write_timestamp), + ( + "replayed_cmd_copy_query_pool_results", + replayed.cmd_copy_query_pool_results, + ), + ("replayed_cmd_push_constants", replayed.cmd_push_constants), + ("replayed_cmd_end_render_pass", replayed.cmd_end_render_pass), + ( + "replayed_cmd_execute_commands", + replayed.cmd_execute_commands, + ), + ("replayed_cmd_set_cull_mode", replayed.cmd_set_cull_mode), + ("replayed_cmd_set_front_face", replayed.cmd_set_front_face), + ( + "replayed_cmd_set_primitive_topology", + replayed.cmd_set_primitive_topology, + ), + ( + "replayed_cmd_bind_vertex_buffers2", + replayed.cmd_bind_vertex_buffers2, + ), + ( + "replayed_cmd_set_depth_test_enable", + replayed.cmd_set_depth_test_enable, + ), + ( + "replayed_cmd_set_depth_write_enable", + replayed.cmd_set_depth_write_enable, + ), + ( + "replayed_cmd_set_depth_compare_op", + replayed.cmd_set_depth_compare_op, + ), + ( + "replayed_cmd_set_stencil_test_enable", + replayed.cmd_set_stencil_test_enable, + ), + ("replayed_cmd_set_stencil_op", replayed.cmd_set_stencil_op), + ( + "replayed_cmd_push_descriptor_set", + replayed.cmd_push_descriptor_set, + ), + ( + "replayed_cmd_set_color_write_mask", + replayed.cmd_set_color_write_mask, + ), + ("replayed_cmd_set_depth_bias2", replayed.cmd_set_depth_bias2), + ( + "replayed_cmd_bind_index_buffer2", + replayed.cmd_bind_index_buffer2, + ), + ("replayed_cmd_draw_mesh_tasks", replayed.cmd_draw_mesh_tasks), + ( + "replayed_cmd_draw_mesh_tasks_indirect", + replayed.cmd_draw_mesh_tasks_indirect, + ), + ("command_buffers_deferred", c.command_buffers_deferred), + ("command_buffers_replayed", c.command_buffers_replayed), + ( + "command_buffers_replayed_inline", + c.command_buffers_replayed_inline, + ), + ("copy_regions_split", c.copy_regions_split), + ("spare_command_pools_taken", c.spare_command_pools_taken), + ("spare_command_pools_reset", c.spare_command_pools_reset), + ("live_tables_uploaded", c.live_tables_uploaded), + ("timeline_waits", c.timeline_waits), + ("missed_completion_wakes", c.missed_completion_wakes), + ("completed_where_seen", c.completed_where_seen), + ("timestamp_slots_taken", c.timestamp_slots_taken), + ( + "timestamp_slots_reset_on_host", + c.timestamp_slots_reset_on_host, + ), + ("calibrations", c.calibrations), + ("calibration_readings", c.calibration_readings), + ("calibration_deviation_most", c.calibration_deviation_most), + ("calibration_disagreements", c.calibration_disagreements), + ("storage_forms_taken", c.storage_forms_taken), + ("addressable_buffers_made", c.addressable_buffers_made), + ("mipmap_first_levels_fetched", c.mipmap_first_levels_fetched), + ("compressed_rows_rewritten", c.compressed_rows_rewritten), + ("pipelines_pooled", c.pipelines_pooled), + ("residual_form_draws", c.residual_form_draws), + ("residual_form_makings", c.residual_form_makings), + ("pipeline_pool_busy", c.pipeline_pool_busy), + ("shader_modules_made", c.shader_modules_made), + ("shader_modules_shared", c.shader_modules_shared), + ("pipeline_layouts_made", c.pipeline_layouts_made), + ("pipeline_layouts_shared", c.pipeline_layouts_shared), + ("flights_followed", c.flights_followed), + ("predicated_loop_runs_again", c.predicated_loop_runs_again), + ("variants_taken_back", c.variants_taken_back), + ( + "unlisted_argument_sampler_buffers", + c.unlisted_argument_sampler_buffers, + ), + ("host_step_sampler_sets_made", c.host_step_sampler_sets_made), + ("creation_pipelines_made", c.creation_pipelines_made), + ("creation_pipelines_drawn", c.creation_pipelines_drawn), + ("sampler_sets_made", c.sampler_sets_made), + ("sampler_sets_shared", c.sampler_sets_shared), + ("sampler_sets_destroyed", c.sampler_sets_destroyed), + ("ahead_render_passes_made", c.ahead_render_passes_made), + ("render_passes_made", c.render_passes_made), + ("ahead_framebuffers_made", c.ahead_framebuffers_made), + ("kept_backings_made", c.kept_backings_made), + ("pooled_backings_made", c.pooled_backings_made), + ("storage_placeholders_made", c.storage_placeholders_made), + ( + "storage_placeholder_attachments", + c.storage_placeholder_attachments, + ), + ("color_resolve_passes_made", c.color_resolve_passes_made), + ("color_resolve_passes_kept", c.color_resolve_passes_kept), + ("ahead_nanos", c.ahead_nanos), + ("unused_bits_load_passes", c.unused_bits_load_passes), + ("unused_bits_load_texels", c.unused_bits_load_texels), + ("capture_reach_passes", c.capture_reach_passes), + ("capture_reach_primitives", c.capture_reach_primitives), + ("capture_reach_tiles_found", c.capture_reach_tiles_found), + ("capture_reach_tiles_bound", c.capture_reach_tiles_bound), + ("capture_reach_bound_passes", c.capture_reach_bound_passes), + ( + "capture_reach_narrower_passes", + c.capture_reach_narrower_passes, + ), + ("driver_diagnostics_withheld", c.driver_diagnostics_withheld), + ("memory_blocks_live", c.memory_blocks_live), + ("empty_memory_blocks_live", c.empty_memory_blocks_live), + ("pooled_memory_blocks_made", c.pooled_memory_blocks_made), + ("pooled_memory_blocks_freed", c.pooled_memory_blocks_freed), + ( + "dedicated_memory_blocks_live", + c.dedicated_memory_blocks_live, + ), + ("host_imports_live", c.host_imports_live), + ("freed_memory_parked", c.freed_memory_parked), + ("freed_memory_waiting", c.freed_memory_waiting), + ("stand_ins_made", c.stand_ins_made), + ("stand_in_bytes", c.stand_in_bytes), + ("stale_detached_reaches", c.stale_detached_reaches), + ("detached_storage_reaches", c.detached_storage_reaches), + ("heap_slots_rewritten", c.heap_slots_rewritten), + ("heap_slot_writes_deferred", c.heap_slot_writes_deferred), + ("host_range_lookups", c.host_range_lookups), + ("heap_textures_tiled", c.heap_textures_tiled), + ( + "heap_sample_move_images_made", + c.heap_sample_move_images_made, + ), + ( + "heap_sample_move_images_lent", + c.heap_sample_move_images_lent, + ), + ("requirement_limits_asked", c.requirement_limits_asked), + ( + "heap_texture_lossless_layouts", + c.heap_texture_lossless_layouts, + ), + ( + "heap_texture_block_compressed_layouts", + c.heap_texture_block_compressed_layouts, + ), + ( + "heap_texture_untiled_layouts", + c.heap_texture_untiled_layouts, + ), + ("fills_recorded", c.fills_recorded), + ("fills_by_transfers", c.fills_by_transfers), + ("ycbcr_refreshes", c.ycbcr_refreshes), + ("ycbcr_whole_conversions", c.ycbcr_whole_conversions), + ("attachment_clears_recorded", c.attachment_clears_recorded), + ("image_blits_recorded", c.image_blits_recorded), + ( + "query_result_copies_recorded", + c.query_result_copies_recorded, + ), + ("visibility_queries_begun", c.visibility_queries_begun), + ("indirect_draws_recorded", c.indirect_draws_recorded), + ("gpu_pool_blocks_made", c.gpu_pool_blocks_made), + ("gpu_pool_blocks_released", c.gpu_pool_blocks_released), + ("gpu_pool_leases_peak", c.gpu_pool_leases_peak), + ("internal_submissions", c.internal_submissions), + ("batch_submit_nanos", c.batch_submit_nanos), + ("command_buffers_begun", c.command_buffers_begun), + ( + "encoder_command_buffers_begun", + c.encoder_command_buffers_begun, + ), + ( + "command_buffers_begun_encoders", + c.command_buffers_begun_encoders, + ), + ( + "command_buffers_begun_segments", + c.command_buffers_begun_segments, + ), + ( + "command_buffers_begun_continuations", + c.command_buffers_begun_continuations, + ), + ( + "command_buffers_begun_secondaries", + c.command_buffers_begun_secondaries, + ), + ( + "command_buffers_begun_kept_barriers", + c.command_buffers_begun_kept_barriers, + ), + ( + "command_buffers_begun_internal", + c.command_buffers_begun_internal, + ), + ( + "encoder_primaries_begun_ahead", + c.encoder_primaries_begun_ahead, + ), + ("primaries_begun_ahead", c.primaries_begun_ahead), + ("barrier_buffers_kept", c.barrier_buffers_kept), + ("stamped_buffers_kept", c.stamped_buffers_kept), + ("stamped_buffers_reused", c.stamped_buffers_reused), + ("finales_folded", c.finales_folded), + ("grouped_submissions", c.grouped_submissions), + ("batches_grouped", c.batches_grouped), + ("group_ends_full", c.group_ends_full), + ("group_ends_wait", c.group_ends_wait), + ("group_ends_apart", c.group_ends_apart), + ("group_ends_first_work", c.group_ends_first_work), + ("group_ends_drained", c.group_ends_drained), + ("group_ends_checks", c.group_ends_checks), + ("group_ends_held", c.group_ends_held), + ("batches_with_none_pending", c.batches_with_none_pending), + ("batches_with_one_pending", c.batches_with_one_pending), + ( + "batches_with_two_or_three_pending", + c.batches_with_two_or_three_pending, + ), + ( + "batches_with_four_or_more_pending", + c.batches_with_four_or_more_pending, + ), + ("groups_kept_pending", c.groups_kept_pending), + ("groups_sent_for_waits", c.groups_sent_for_waits), + ("registrations_waited", c.registrations_waited), + ("scheduler_wakes_completion", c.scheduler_wakes_completion), + ("scheduler_sleep_slices", c.scheduler_sleep_slices), + ("scheduler_gpu_waits", c.scheduler_gpu_waits), + ("wakes_completion_waiters", c.wakes_completion_waiters), + ( + "wakes_command_buffer_waiters", + c.wakes_command_buffer_waiters, + ), + ("wakes_event_waiters", c.wakes_event_waiters), + ("wakes_spared", c.wakes_spared), + ("slot_returns", c.slot_returns), + ("slot_return_nanos", c.slot_return_nanos), + ("slot_waits", c.slot_waits), + ("slot_wait_nanos", c.slot_wait_nanos), + ("event_waits_met", c.event_waits_met), + ("bare_starts", c.bare_starts), + ("prefixed_starts", c.prefixed_starts), + ("command_barriers", c.command_barriers), + ("unrun_instances_ended", c.unrun_instances_ended), + ("untouched_passes_skipped", c.untouched_passes_skipped), + ("inline_passes", c.inline_passes), + ("inline_passes_split", c.inline_passes_split), + ("inline_split_instances", c.inline_split_instances), + ( + "inline_memoryless_write_splits", + c.inline_memoryless_write_splits, + ), + ( + "render_log_batches_by_thread", + c.render_log_batches_by_thread, + ), + ( + "render_log_batches_by_program", + c.render_log_batches_by_program, + ), + ("render_log_waits", c.render_log_waits), + ("render_log_ends_by_thread", c.render_log_ends_by_thread), + ("render_log_ends_by_program", c.render_log_ends_by_program), + ( + "render_log_commits_by_thread", + c.render_log_commits_by_thread, + ), + ( + "render_log_commits_by_program", + c.render_log_commits_by_program, + ), + ("passes_not_inline_encoders", c.passes_not_inline_encoders), + ("passes_not_inline_layouts", c.passes_not_inline_layouts), + ( + "passes_not_inline_memoryless", + c.passes_not_inline_memoryless, + ), + ("passes_not_inline_actions", c.passes_not_inline_actions), + ( + "passes_not_inline_actions_dont_care_load", + c.passes_not_inline_actions_dont_care_load, + ), + ( + "passes_not_inline_actions_unequal_reach", + c.passes_not_inline_actions_unequal_reach, + ), + ( + "passes_not_inline_actions_nan_clear", + c.passes_not_inline_actions_nan_clear, + ), + ( + "passes_not_inline_actions_resolve", + c.passes_not_inline_actions_resolve, + ), + ( + "passes_not_inline_actions_store", + c.passes_not_inline_actions_store, + ), + ( + "passes_not_inline_buffer_textures", + c.passes_not_inline_buffer_textures, + ), + ( + "passes_not_inline_attachments", + c.passes_not_inline_attachments, + ), + ("passes_not_inline_storage", c.passes_not_inline_storage), + ("passes_not_inline_stand_ins", c.passes_not_inline_stand_ins), + ( + "passes_not_inline_memoryless_writes", + c.passes_not_inline_memoryless_writes, + ), + ("passes_not_inline_draws", c.passes_not_inline_draws), + ("commits_handed_off", c.commits_handed_off), + ("images_started_on_the_host", c.images_started_on_the_host), + ("host_texel_copies", c.host_texel_copies), + ("staging_submissions", c.staging_submissions), + ("uncached_host_images", c.uncached_host_images), + ("cpu_block_decodes", c.cpu_block_decodes), + ("block_decode_passes", c.block_decode_passes), + ("second_twins", c.second_twins), + ("second_twin_checks", c.second_twin_checks), + ("second_twin_decodes", c.second_twin_decodes), + ("queue_drains", c.queue_drains), + ("stand_in_copies_made", c.stand_in_copies_made), + ( + "stand_in_copies_made_at_draws", + c.stand_in_copies_made_at_draws, + ), + ("draw_shapes_made", c.draw_shapes_made), + ("draw_shapes_found", c.draw_shapes_found), + ("argument_samplers_taken", c.argument_samplers_taken), + ("bind_views_worked_out", c.bind_views_worked_out), + ("stage_tables_read", c.stage_tables_read), + ("stage_tables_read_in_part", c.stage_tables_read_in_part), + ("no_copy_lies_read", c.no_copy_lies_read), + ("commands_noted_as_before", c.commands_noted_as_before), + ("draws_settled", c.draws_settled), + ("depth16_sided_draws", c.depth16_sided_draws), + ("two_plane_draws", c.two_plane_draws), + ("bound_notices_made", c.bound_notices_made), + ("argument_tables_retained", c.argument_tables_retained), + ("argument_objects_retained", c.argument_objects_retained), + ( + "graphics_pipelines_looked_up", + c.graphics_pipelines_looked_up, + ), + ("linear_passes_in_place", c.linear_passes_in_place), + ( + "linear_passes_through_copies", + c.linear_passes_through_copies, + ), + ("kept_bytes_passes", c.kept_bytes_passes), + ("signed_depth_switch_ons", c.signed_depth_switch_ons), + ("magnitude_stand_in_passes", c.magnitude_stand_in_passes), + ("magnitude_write_backs", c.magnitude_write_backs), + ("sign_strips", c.sign_strips), + ("color_group_passes", c.color_group_passes), + ("color_group_twins", c.color_group_twins), + ("color_group_draws_skipped", c.color_group_draws_skipped), + ("draw_states_recorded", c.draw_states_recorded), + ("draws_pushing_set_zero", c.draws_pushing_set_zero), + ("set_zero_writes_pushed", c.set_zero_writes_pushed), + ( + "set_zero_equal_shape_switches", + c.set_zero_equal_shape_switches, + ), + ( + "set_zero_writes_on_equal_shape_switches", + c.set_zero_writes_on_equal_shape_switches, + ), + ( + "set_zero_writes_if_shapes_shared", + c.set_zero_writes_if_shapes_shared, + ), + ("dispatches_pushing_set_zero", c.dispatches_pushing_set_zero), + ("set_zero_sets_reused", c.set_zero_sets_reused), + ("set_zero_sets_found", c.set_zero_sets_found), + ("draw_shapes_reused", c.draw_shapes_reused), + ( + "baked_sampler_dispatches_apart", + c.baked_sampler_dispatches_apart, + ), + ("host_deallocators_delayed", c.host_deallocators_delayed), + ("host_import_releases_posted", c.host_import_releases_posted), + ( + "host_import_releases_pending", + c.host_import_releases_pending, + ), + ("host_keep_alives_kept", c.host_keep_alives_kept), + ("host_keep_alives_covered", c.host_keep_alives_covered), + ("host_mappings_queried", c.host_mappings_queried), + ("dma_buf_imports", c.dma_buf_imports), + ("dma_buf_memories_live", c.dma_buf_memories_live), + ("dma_buf_image_memories_live", c.dma_buf_image_memories_live), + ("host_imports_released", c.host_imports_released), + ("host_imports_reimported", c.host_imports_reimported), + ("host_imports_resident", c.host_imports_resident), + ("host_imports_lost", c.host_imports_lost), + ("host_import_fds_kept", c.host_import_fds_kept), + ("host_imports_kept_for_fds", c.host_imports_kept_for_fds), + ("host_imports_used", c.host_imports_used), + ("host_imports_read_apart", c.host_imports_read_apart), + ( + "host_imports_read_apart_address", + c.host_imports_read_apart_address, + ), + ( + "host_imports_read_apart_vk_buffer", + c.host_imports_read_apart_vk_buffer, + ), + ( + "host_imports_read_apart_binding", + c.host_imports_read_apart_binding, + ), + ( + "host_imports_read_apart_texture", + c.host_imports_read_apart_texture, + ), + ( + "host_imports_read_apart_second_buffer", + c.host_imports_read_apart_second_buffer, + ), + ( + "host_imports_read_apart_unreleased", + c.host_imports_read_apart_unreleased, + ), + ("host_remaps_reported", c.host_remaps_reported), + ("host_remaps_over_imports", c.host_remaps_over_imports), + ("host_imports_remapped", c.host_imports_remapped), + ( + "host_pointer_import_bytes_made", + c.host_pointer_import_bytes_made, + ), + ("host_imports_kept_of_heap", c.host_imports_kept_of_heap), + ("host_imports_kept_rebound", c.host_imports_kept_rebound), + ( + "host_imports_rebound_unlisted", + c.host_imports_rebound_unlisted, + ), + ("host_rebind_imports_made", c.host_rebind_imports_made), + ("host_rebind_imports_covered", c.host_rebind_imports_covered), + ("host_imports_kept_pointer", c.host_imports_kept_pointer), + ( + "host_imports_kept_no_stand_in", + c.host_imports_kept_no_stand_in, + ), + ("dma_buf_sparse_buffers", c.dma_buf_sparse_buffers), + ("dma_buf_images", c.dma_buf_images), + ("dma_buf_image_fallbacks", c.dma_buf_image_fallbacks), + ("modifier_feature_queries", c.modifier_feature_queries), + ("shadowed_textures", c.shadowed_textures), + ("shadows_zeroed", c.shadows_zeroed), + ("shadows_over_fresh_pages", c.shadows_over_fresh_pages), + ("fresh_page_buffers_made", c.fresh_page_buffers_made), + ("fresh_page_bytes", c.fresh_page_bytes), + ("shadow_copies", c.shadow_copies), + ("shadow_texels_copied_in", c.shadow_texels_copied_in), + ( + "shadow_texels_copied_in_images", + c.shadow_texels_copied_in_images, + ), + ( + "shadow_texels_first_copied_in", + c.shadow_texels_first_copied_in, + ), + ( + "shadow_texels_first_copied_in_images", + c.shadow_texels_first_copied_in_images, + ), + ( + "shadow_texels_first_copied_in_private_buffers", + c.shadow_texels_first_copied_in_private_buffers, + ), + ( + "shadow_texels_first_copied_in_mapped_buffers", + c.shadow_texels_first_copied_in_mapped_buffers, + ), + ( + "shadow_texels_first_copied_in_host_pages", + c.shadow_texels_first_copied_in_host_pages, + ), + ( + "shadow_texels_first_copied_in_aliased_host_pages", + c.shadow_texels_first_copied_in_aliased_host_pages, + ), + ( + "shadow_texels_first_copied_in_surfaces", + c.shadow_texels_first_copied_in_surfaces, + ), + ( + "shadow_texels_first_copied_in_large_surfaces", + c.shadow_texels_first_copied_in_large_surfaces, + ), + ( + "shadow_texels_first_copied_in_again", + c.shadow_texels_first_copied_in_again, + ), + ( + "shadow_texels_recopied_beyond_held", + c.shadow_texels_recopied_beyond_held, + ), + ( + "shadow_texels_recopied_after_changes", + c.shadow_texels_recopied_after_changes, + ), + ( + "shadow_texels_recopied_after_other_shadows", + c.shadow_texels_recopied_after_other_shadows, + ), + ( + "shadow_texels_recopied_after_two_ways_merges", + c.shadow_texels_recopied_after_two_ways_merges, + ), + ( + "shadow_texels_recopied_after_writes", + c.shadow_texels_recopied_after_writes, + ), + ( + "shadow_texels_recopied_after_writes_within", + c.shadow_texels_recopied_after_writes_within, + ), + ( + "shadow_texels_recopied_after_dropped_writes", + c.shadow_texels_recopied_after_dropped_writes, + ), + ( + "shadow_texels_bounded_copied_in", + c.shadow_texels_bounded_copied_in, + ), + ( + "shadow_texels_recopied_in_images", + c.shadow_texels_recopied_in_images, + ), + ( + "shadow_texels_recopied_in_private_buffers", + c.shadow_texels_recopied_in_private_buffers, + ), + ( + "shadow_texels_recopied_in_mapped_buffers", + c.shadow_texels_recopied_in_mapped_buffers, + ), + ( + "shadow_texels_recopied_in_host_pages", + c.shadow_texels_recopied_in_host_pages, + ), + ( + "shadow_texels_recopied_in_aliased_host_pages", + c.shadow_texels_recopied_in_aliased_host_pages, + ), + ( + "shadow_texels_recopied_in_surfaces", + c.shadow_texels_recopied_in_surfaces, + ), + ( + "shadow_texels_recopied_in_large_surfaces", + c.shadow_texels_recopied_in_large_surfaces, + ), + ("shadow_texels_copied_back", c.shadow_texels_copied_back), + ( + "shadow_copies_back_dispatched", + c.shadow_copies_back_dispatched, + ), + ("shadow_copies_in_dispatched", c.shadow_copies_in_dispatched), + ( + "shadow_merge_copies_dispatched", + c.shadow_merge_copies_dispatched, + ), + ( + "shadow_merge_scratches_reused", + c.shadow_merge_scratches_reused, + ), + ( + "shadow_merge_scratches_zeroed", + c.shadow_merge_scratches_zeroed, + ), + ("row_copies", c.row_copies), + ("row_copy_regions", c.row_copy_regions), + ("row_copy_regions_most", c.row_copy_regions_most), + ("row_copies_dispatched", c.row_copies_dispatched), + ("shadow_merges_fetched", c.shadow_merges_fetched), + ( + "shadow_merges_kept_in_images", + c.shadow_merges_kept_in_images, + ), + ( + "shadow_merge_kept_images_made", + c.shadow_merge_kept_images_made, + ), + ( + "shadow_merge_kept_images_followed", + c.shadow_merge_kept_images_followed, + ), + ( + "shadow_merge_kept_images_live", + c.shadow_merge_kept_images_live, + ), + ("shadow_attachment_passes", c.shadow_attachment_passes), + ("shadow_attachment_textures", c.shadow_attachment_textures), + ( + "shadow_attachment_loads_within", + c.shadow_attachment_loads_within, + ), + ( + "shadow_attachment_loads_whole", + c.shadow_attachment_loads_whole, + ), + ("shadow_attachment_clears", c.shadow_attachment_clears), + ( + "shadow_attachment_clears_in_part", + c.shadow_attachment_clears_in_part, + ), + ( + "shadow_attachment_loads_untouched", + c.shadow_attachment_loads_untouched, + ), + ( + "shadow_attachment_tiles_covered", + c.shadow_attachment_tiles_covered, + ), + ( + "shadow_attachment_tiles_bounded", + c.shadow_attachment_tiles_bounded, + ), + ("shadows_sharing_truth", c.shadows_sharing_truth), + ("owned_descriptor_pools", c.owned_descriptor_pools), + ("shadow_texels_kept", c.shadow_texels_kept), + ("bounded_shadow_copies", c.bounded_shadow_copies), + ("views_through_swizzle", c.views_through_swizzle), + ("view_shadows", c.view_shadows), + ( + "attachment_reads_through_copies", + c.attachment_reads_through_copies, + ), + ("attachment_read_splits", c.attachment_read_splits), + ("reading_draws_snapshotted", c.reading_draws_snapshotted), + ("snapshot_inline_splits", c.snapshot_inline_splits), + ("feedback_loop_alias_images", c.feedback_loop_alias_images), + ("depth_attachments_moved", c.depth_attachments_moved), + ("depth_instances_held", c.depth_instances_held), + ("held_depths_released", c.held_depths_released), + ("own_pixel_reads", c.own_pixel_reads), + ("replay_logs_kept", c.replay_logs_kept), + ("replay_log_bytes", c.replay_log_bytes), + ("encoders_reencoded", c.encoders_reencoded), + ("segments_recorded_again", c.segments_recorded_again), + ("replay_tables_pointed", c.replay_tables_pointed), + ("reencodes_refused", c.reencodes_refused), + ("fences_made", c.fences_made), + ("pipeline_libraries_made", c.pipeline_libraries_made), + ( + "fragment_shader_libraries_made", + c.fragment_shader_libraries_made, + ), + ("pipelines_linked", c.pipelines_linked), + ("dispatch_pipelines_pooled", c.dispatch_pipelines_pooled), + ("tile_pipelines_pooled", c.tile_pipelines_pooled), + ( + "upload_chunks_in_device_memory", + c.upload_chunks_in_device_memory, + ), + ("tile_dispatches_recorded", c.tile_dispatches_recorded), + ( + "churn_vk_buffers_destroyed", + c.object_churn.vk_buffers_destroyed, + ), + ( + "churn_vk_buffer_views_destroyed", + c.object_churn.vk_buffer_views_destroyed, + ), + ("churn_vk_memory_freed", c.object_churn.vk_memory_freed), + ("vk_images_made", c.object_churn.vk_images_made), + ("vk_buffers_made", c.object_churn.vk_buffers_made), + ("vk_image_views_made", c.object_churn.vk_image_views_made), + ( + "vk_memory_allocations", + c.object_churn.vk_memory_allocations, + ), + ("vk_image_bindings", c.object_churn.vk_image_bindings), + ("vk_buffer_bindings", c.object_churn.vk_buffer_bindings), + ("churn_images_in_buffers", c.object_churn.images_in_buffers), + ("churn_images_in_heaps", c.object_churn.images_in_heaps), + ("churn_images_other", c.object_churn.images_other), + ("churn_textures_image", c.object_churn.textures_image), + ("churn_textures_in_heaps", c.object_churn.textures_in_heaps), + ("churn_textures_shadow", c.object_churn.textures_shadow), + ("churn_textures_alias", c.object_churn.textures_alias), + ("churn_textures_texels", c.object_churn.textures_texels), + ("churn_buffers_recycled", c.object_churn.buffers_recycled), + ("churn_buffers_parked", c.object_churn.buffers_parked), + ("churn_buffers_evicted", c.object_churn.buffers_evicted), + ( + "churn_imports_inside_live", + c.object_churn.imports_inside_live, + ), + ("keeps_render_cut", c.shadow_keeps.render_cut), + ("keeps_render_cut_texels", c.shadow_keeps.render_cut_texels), + ("keeps_render_whole", c.shadow_keeps.render_whole), + ( + "keeps_render_whole_texels", + c.shadow_keeps.render_whole_texels, + ), + ("keeps_compute_cut", c.shadow_keeps.compute_cut), + ( + "keeps_compute_cut_texels", + c.shadow_keeps.compute_cut_texels, + ), + ("keeps_compute_whole", c.shadow_keeps.compute_whole), + ( + "keeps_compute_whole_texels", + c.shadow_keeps.compute_whole_texels, + ), + ("keeps_blit_cut", c.shadow_keeps.blit_cut), + ("keeps_blit_cut_texels", c.shadow_keeps.blit_cut_texels), + ("keeps_blit_whole", c.shadow_keeps.blit_whole), + ("keeps_blit_whole_texels", c.shadow_keeps.blit_whole_texels), ] .into_iter() .map(|(name, count)| (name, count as f64)) diff --git a/crates/metal2vulkan-runtime/src/buffer.rs b/crates/metal2vulkan-runtime/src/buffer.rs index e1102ff5d..a1e7b04ce 100644 --- a/crates/metal2vulkan-runtime/src/buffer.rs +++ b/crates/metal2vulkan-runtime/src/buffer.rs @@ -2094,7 +2094,7 @@ impl Device { } (None, None) => (|| { // SAFETY: the device is live and `info` valid. - let raw = unsafe { raw_device.create_buffer(&info, None) }.map_err(vulkan)?; + let raw = unsafe { crate::creation::buffer(raw_device, &info) }.map_err(vulkan)?; shared.counts.buffer_made(info.usage); let placed = if of_heap { self.place_heap_buffer(raw, length, class, placement) @@ -2175,7 +2175,7 @@ impl Device { .usage(vk::BufferUsageFlags::TRANSFER_SRC | vk::BufferUsageFlags::TRANSFER_DST), ); // SAFETY: the device is live and `info` valid. - let raw = unsafe { raw_device.create_buffer(&info, None) }.map_err(vulkan)?; + let raw = unsafe { crate::creation::buffer(raw_device, &info) }.map_err(vulkan)?; // SAFETY: `raw` is a live buffer of this device. let requirements = unsafe { raw_device.get_buffer_memory_requirements(raw) }; let allocated = crate::memory::allocate( @@ -2186,8 +2186,9 @@ impl Device { ); let placed = allocated.and_then(|placement| { // SAFETY: the placement meets the buffer's requirements and is not bound elsewhere. - match unsafe { raw_device.bind_buffer_memory(raw, placement.memory, placement.offset) } - { + match unsafe { + crate::creation::bind_buffer(raw_device, raw, placement.memory, placement.offset) + } { Ok(()) => Ok(placement), Err(error) => { lock(&shared.memory).free(raw_device, &placement); @@ -2239,7 +2240,7 @@ impl Device { .push_next(&mut usage), ); // SAFETY: the device is live and `info` and its chain valid. - let raw = unsafe { raw_device.create_buffer(&info, None) }.map_err(vulkan)?; + let raw = unsafe { crate::creation::buffer(raw_device, &info) }.map_err(vulkan)?; shared .counts .buffer_made(vk::BufferUsageFlags::SHADER_DEVICE_ADDRESS); @@ -2556,8 +2557,9 @@ impl Device { crate::memory::allocate(&shared.memory, raw_device, &requirements, class)? }; // SAFETY: the placement meets the buffer's requirements and is not bound elsewhere. - let bound = - unsafe { raw_device.bind_buffer_memory(raw, placement.memory, placement.offset) }; + let bound = unsafe { + crate::creation::bind_buffer(raw_device, raw, placement.memory, placement.offset) + }; let address = match bound { Ok(()) => lock(&shared.addresses).place(at, length), Err(error) => { diff --git a/crates/metal2vulkan-runtime/src/buffer_descriptor.rs b/crates/metal2vulkan-runtime/src/buffer_descriptor.rs index 1ad8883a9..063bb1212 100644 --- a/crates/metal2vulkan-runtime/src/buffer_descriptor.rs +++ b/crates/metal2vulkan-runtime/src/buffer_descriptor.rs @@ -823,7 +823,7 @@ impl Device { .push_next(&mut external), ); // SAFETY: the device is live and `info` and its chain valid. - let raw = unsafe { raw_device.create_buffer(&info, None) }.map_err(vulkan)?; + let raw = unsafe { crate::creation::buffer(raw_device, &info) }.map_err(vulkan)?; shared.counts.buffer_made(info.usage); // SAFETY: `raw` is a live buffer of this device. let requirements = unsafe { raw_device.get_buffer_memory_requirements(raw) }; @@ -1153,8 +1153,9 @@ impl Device { })?; // SAFETY: the placement is the pages' memory, the buffer's size and requirements of it // available from `at` (the caller's), and the buffer is unbound. - let bound = - unsafe { raw_device.bind_buffer_memory(raw, placement.memory, placement.offset + at) }; + let bound = unsafe { + crate::creation::bind_buffer(raw_device, raw, placement.memory, placement.offset + at) + }; match bound { Ok(()) => { shared.counts.host_pointer_import_made(size); diff --git a/crates/metal2vulkan-runtime/src/churn_counts.rs b/crates/metal2vulkan-runtime/src/churn_counts.rs index 79fc7c0ce..e36f7998b 100644 --- a/crates/metal2vulkan-runtime/src/churn_counts.rs +++ b/crates/metal2vulkan-runtime/src/churn_counts.rs @@ -10,6 +10,12 @@ //! on MoltenVK, a commit at the release and one at the making before it. The releases of the //! whole process, by entry point (`release.rs`), and of a device's images and textures, by //! what owned them. +//! - **Object makings.** The other side of the same ledger: the `vkCreateImage`, +//! `vkCreateBuffer`, `vkCreateImageView`, `vkAllocateMemory`, `vkBindImageMemory` and +//! `vkBindBufferMemory` calls of the whole process, by entry point and by the place in the +//! runtime that asked for one (`creation.rs`, their one door). What a texture or buffer +//! creation made the driver do is then a count of that call's own work, not an inference from a +//! driver floor timed apart, and a count holds under any load where a time does not. //! - **Shadow keeps.** The keeps of merged-back shadows (`shadow_merge.rs`) by the encoder that //! planned them (a render pass's attachments, a compute dispatch's bindings, a blit), cut to a //! rectangle or of every texel, and the texels they copy. @@ -25,6 +31,12 @@ static VK_RELEASES: [AtomicU64; 4] = [const { AtomicU64::new(0) }; 4]; /// The places in the runtime that released those, the first [`COPY_SITES`] met. static RELEASE_SITES: LazyLock = LazyLock::new(CopySites::default); +/// The Vulkan makings of the process a driver charges for, by entry point ([`VkMaking`]). +static VK_MAKINGS: [AtomicU64; 6] = [const { AtomicU64::new(0) }; 6]; + +/// The places in the runtime that made those, the first [`COPY_SITES`] met. +static MAKING_SITES: LazyLock = LazyLock::new(CopySites::default); + /// An entry point [`VK_RELEASES`] counts. #[derive(Clone, Copy)] pub(crate) enum VkRelease { @@ -34,6 +46,18 @@ pub(crate) enum VkRelease { Memory = 3, } +/// An entry point [`VK_MAKINGS`] counts: the makings a driver charges for, whose cost one call of +/// the API carries (`creation.rs`). +#[derive(Clone, Copy)] +pub(crate) enum VkMaking { + Image = 0, + Buffer = 1, + ImageView = 2, + Memory = 3, + ImageBinding = 4, + BufferBinding = 5, +} + /// A release of `what` (`release::object`), called `at`. pub(crate) fn vk_released(what: VkRelease, at: &Location<'static>) { VK_RELEASES[what as usize].fetch_add(1, Ordering::Relaxed); @@ -46,6 +70,26 @@ pub(crate) fn vk_released(what: VkRelease, at: &Location<'static>) { RELEASE_SITES.count(command, at, 0); } +/// A making of `what` (`creation.rs`), called `at`. +pub(crate) fn vk_made(what: VkMaking, at: &Location<'static>) { + VK_MAKINGS[what as usize].fetch_add(1, Ordering::Relaxed); + MAKING_SITES.count(what.command(), at, 0); +} + +impl VkMaking { + /// Its Vulkan entry point. + fn command(self) -> &'static str { + match self { + VkMaking::Image => "vkCreateImage", + VkMaking::Buffer => "vkCreateBuffer", + VkMaking::ImageView => "vkCreateImageView", + VkMaking::Memory => "vkAllocateMemory", + VkMaking::ImageBinding => "vkBindImageMemory", + VkMaking::BufferBinding => "vkBindBufferMemory", + } + } +} + /// What owned an image or a texture as it went. #[derive(Clone, Copy)] pub(crate) enum Owned { @@ -135,6 +179,7 @@ impl ChurnCounters { pub(crate) fn snapshot(&self) -> (ObjectChurn, ShadowKeeps) { let owned = |o: Owned| self.owned[o as usize].load(Ordering::Relaxed); let vk = |r: VkRelease| VK_RELEASES[r as usize].load(Ordering::Relaxed); + let made = |m: VkMaking| VK_MAKINGS[m as usize].load(Ordering::Relaxed); let keep = |by: KeepBy, at: usize| self.keeps[by as usize][at].load(Ordering::Relaxed); let recycled = |what: Recycled, at: usize| self.recycled[what as usize][at].load(Ordering::Relaxed); @@ -144,6 +189,13 @@ impl ChurnCounters { vk_buffers_destroyed: vk(VkRelease::Buffer), vk_buffer_views_destroyed: vk(VkRelease::BufferView), vk_memory_freed: vk(VkRelease::Memory), + vk_images_made: made(VkMaking::Image), + vk_buffers_made: made(VkMaking::Buffer), + vk_image_views_made: made(VkMaking::ImageView), + vk_memory_allocations: made(VkMaking::Memory), + vk_image_bindings: made(VkMaking::ImageBinding), + vk_buffer_bindings: made(VkMaking::BufferBinding), + making_sites: MAKING_SITES.read(), images_own_memory: owned(Owned::ImageOwnMemory), images_in_buffers: owned(Owned::ImageInBuffer), images_in_heaps: owned(Owned::ImageInHeap), @@ -193,6 +245,19 @@ pub struct ObjectChurn { pub vk_buffer_views_destroyed: u64, /// `vkFreeMemory` calls of the process. pub vk_memory_freed: u64, + /// `vkCreateImage` calls of the process (`creation.rs`). + pub vk_images_made: u64, + /// `vkCreateBuffer` calls of the process. + pub vk_buffers_made: u64, + /// `vkCreateImageView` calls of the process. + pub vk_image_views_made: u64, + /// `vkAllocateMemory` calls of the process, the tries a caller that walks the memory types + /// made included. + pub vk_memory_allocations: u64, + /// `vkBindImageMemory` calls of the process. + pub vk_image_bindings: u64, + /// `vkBindBufferMemory` calls of the process. + pub vk_buffer_bindings: u64, /// The device's images that went, of memory of their own. pub images_own_memory: u64, /// Linear images in buffers' memory. @@ -229,6 +294,10 @@ pub struct ObjectChurn { /// The places that released the images, buffers, buffer views and memory counted above, each /// with its calls (`regions` unused): the first 32 the process met. pub release_sites: [CopySite; COPY_SITES], + /// The places that made the images, buffers, views, memory and bindings counted above, each + /// with its calls (`regions` unused): the first 32 the process met. What a creation call of + /// the API made the driver do, and the line of the runtime that asked for it. + pub making_sites: [CopySite; COPY_SITES], } /// The keeps of merged-back shadows by who planned them, cut to a rectangle or of every texel diff --git a/crates/metal2vulkan-runtime/src/creation.rs b/crates/metal2vulkan-runtime/src/creation.rs index 87550437a..1d760a063 100644 --- a/crates/metal2vulkan-runtime/src/creation.rs +++ b/crates/metal2vulkan-runtime/src/creation.rs @@ -1,5 +1,7 @@ //! The runtime's one door to `vkCreateImage`, `vkCreateRenderPass`, `vkCreateRenderPass2` and -//! `vkCreateFramebuffer`, so their entry points stay in the exit guard's tables. +//! `vkCreateFramebuffer`, so their entry points stay in the exit guard's tables; and to the other +//! makings a driver charges for — `vkCreateBuffer`, `vkCreateImageView`, `vkAllocateMemory`, +//! `vkBindImageMemory` and `vkBindBufferMemory` — so each counts itself where it is called. //! //! Each is made where it is first needed: on the program's thread, in a section of the device's //! lowering thread, which lowers render encoders' calls (`render/lowering_worker.rs`), or in a host @@ -10,19 +12,31 @@ //! host step makes (`exit_guard::HOST_STEP`). The device's priming (`device/prime.rs`) makes its //! own, on the thread that makes the device. No other file calls these entry points: a source test //! fails when one does (`tests/exit_guard.rs`). +//! +//! **Each making is counted at its caller's place** (`churn_counts.rs`, as the releases are), so +//! what one call of the API made the driver do is a count of that call's own work rather than an +//! inference from a separately timed driver floor: a 256x256 texture's `vkCreateImage` and its +//! binding, a buffer's `vkCreateBuffer` and whether its memory came from a pool or a fresh +//! `vkAllocateMemory`. A count is deterministic, so a test can hold a call to it where a time +//! cannot. +use crate::churn_counts::{vk_made, VkMaking}; use crate::error::{vulkan, Error}; +use ash::prelude::VkResult; use ash::vk; +use std::panic::Location; /// A `VkImage` of `info`, made by `device`. /// /// # Safety /// /// As `vkCreateImage`'s: `device` is live, and `info` and its chain are valid for it. +#[track_caller] pub(crate) unsafe fn image( device: &ash::Device, info: &vk::ImageCreateInfo<'_>, ) -> Result { + vk_made(VkMaking::Image, Location::caller()); // SAFETY: the caller's. unsafe { device.create_image(info, None) }.map_err(vulkan) } @@ -35,10 +49,12 @@ pub(crate) unsafe fn image( /// # Safety /// /// As `vkCreateImage`'s: `device` is live, and `info` and its chain are valid for it. +#[track_caller] pub(crate) unsafe fn image_or_refusal( device: &ash::Device, info: &vk::ImageCreateInfo<'_>, ) -> Result, Error> { + vk_made(VkMaking::Image, Location::caller()); // SAFETY: the caller's. match unsafe { device.create_image(info, None) } { Ok(raw) => Ok(Ok(raw)), @@ -47,6 +63,92 @@ pub(crate) unsafe fn image_or_refusal( } } +/// A `VkBuffer` of `info`, made by `device`, with the driver's result as it gave it: the callers +/// read a refusal differently (a staging buffer's caller takes another way, a program's buffer +/// turns it into `Error`). +/// +/// # Safety +/// +/// As `vkCreateBuffer`'s: `device` is live, and `info` and its chain are valid for it. +#[track_caller] +pub(crate) unsafe fn buffer( + device: &ash::Device, + info: &vk::BufferCreateInfo<'_>, +) -> VkResult { + vk_made(VkMaking::Buffer, Location::caller()); + // SAFETY: the caller's. + unsafe { device.create_buffer(info, None) } +} + +/// A `VkImageView` of `info`, made by `device`. +/// +/// # Safety +/// +/// As `vkCreateImageView`'s: `device` is live, and `info` and its chain are valid for it. +#[track_caller] +pub(crate) unsafe fn image_view( + device: &ash::Device, + info: &vk::ImageViewCreateInfo<'_>, +) -> VkResult { + vk_made(VkMaking::ImageView, Location::caller()); + // SAFETY: the caller's. + unsafe { device.create_image_view(info, None) } +} + +/// `VkDeviceMemory` of `info`, allocated by `device`: one call of `vkAllocateMemory`, counted +/// whether or not the driver gave it, because a caller that tries memory types in turn pays for +/// each try. +/// +/// # Safety +/// +/// As `vkAllocateMemory`'s: `device` is live, and `info` and its chain are valid for it and live +/// for the call. +#[track_caller] +pub(crate) unsafe fn allocate_memory( + device: &ash::Device, + info: &vk::MemoryAllocateInfo<'_>, +) -> VkResult { + vk_made(VkMaking::Memory, Location::caller()); + // SAFETY: the caller's. + unsafe { device.allocate_memory(info, None) } +} + +/// `image` bound to `memory` at `offset`. +/// +/// # Safety +/// +/// As `vkBindImageMemory`'s: `device` is live, `image` is its unbound image, and `memory` is its +/// memory of a type the image takes, long enough for it from `offset`. +#[track_caller] +pub(crate) unsafe fn bind_image( + device: &ash::Device, + image: vk::Image, + memory: vk::DeviceMemory, + offset: vk::DeviceSize, +) -> VkResult<()> { + vk_made(VkMaking::ImageBinding, Location::caller()); + // SAFETY: the caller's. + unsafe { device.bind_image_memory(image, memory, offset) } +} + +/// `buffer` bound to `memory` at `offset`. +/// +/// # Safety +/// +/// As `vkBindBufferMemory`'s: `device` is live, `buffer` is its unbound buffer, and `memory` is +/// its memory of a type the buffer takes, long enough for it from `offset`. +#[track_caller] +pub(crate) unsafe fn bind_buffer( + device: &ash::Device, + buffer: vk::Buffer, + memory: vk::DeviceMemory, + offset: vk::DeviceSize, +) -> VkResult<()> { + vk_made(VkMaking::BufferBinding, Location::caller()); + // SAFETY: the caller's. + unsafe { device.bind_buffer_memory(buffer, memory, offset) } +} + /// A `VkRenderPass` of `info`, made by `device`. /// /// # Safety diff --git a/crates/metal2vulkan-runtime/src/dma_buf.rs b/crates/metal2vulkan-runtime/src/dma_buf.rs index 902e7694e..5370cc5ed 100644 --- a/crates/metal2vulkan-runtime/src/dma_buf.rs +++ b/crates/metal2vulkan-runtime/src/dma_buf.rs @@ -576,7 +576,7 @@ impl Device { ); // SAFETY: the device is live and `info` and its chain valid; a sparse one has // `sparseBinding` (`Device::sparse_granule`). - let raw = unsafe { raw_device.create_buffer(&info, None) }.map_err(vulkan)?; + let raw = unsafe { crate::creation::buffer(raw_device, &info) }.map_err(vulkan)?; shared.counts.buffer_made(info.usage); // SAFETY: `raw` is a live buffer of this device. let requirements = unsafe { raw_device.get_buffer_memory_requirements(raw) }; @@ -597,7 +597,8 @@ impl Device { if !sparse { // SAFETY: the buffer is unbound, made for dma-bufs; the memory is of a type it // takes and holds its requirements from 0. - unsafe { raw_device.bind_buffer_memory(raw, memories[0].0, 0) }.map_err(vulkan)?; + unsafe { crate::creation::bind_buffer(raw_device, raw, memories[0].0, 0) } + .map_err(vulkan)?; return Ok(memories[0]); } let mut offset = 0; @@ -689,7 +690,7 @@ impl Device { .push_next(&mut external), ); // SAFETY: the device is live, has `sparseBinding`, and `info` and its chain are valid. - let raw = unsafe { raw_device.create_buffer(&info, None) }.ok()?; + let raw = unsafe { crate::creation::buffer(raw_device, &info) }.ok()?; shared.counts.buffer_made(info.usage); // SAFETY: `raw` is a live buffer of this device. let alignment = unsafe { raw_device.get_buffer_memory_requirements(raw) }.alignment; @@ -998,7 +999,7 @@ impl Device { } }; // SAFETY: the image is unbound; the memory is its dedicated allocation, of its size. - if let Err(error) = unsafe { raw_device.bind_image_memory(raw, memory, 0) } { + if let Err(error) = unsafe { crate::creation::bind_image(raw_device, raw, memory, 0) } { // SAFETY: nothing is bound to the memory, and no command uses it. unsafe { release::object(raw_device, memory) }; return refuse(format!("the driver refuses to bind the import ({error:?})")); diff --git a/crates/metal2vulkan-runtime/src/fresh_pages.rs b/crates/metal2vulkan-runtime/src/fresh_pages.rs index d97c37c21..2dc55b3e3 100644 --- a/crates/metal2vulkan-runtime/src/fresh_pages.rs +++ b/crates/metal2vulkan-runtime/src/fresh_pages.rs @@ -153,7 +153,7 @@ impl Device { .push_next(&mut external), ); // SAFETY: the device is live and `info` and its chain valid. - let raw = unsafe { raw_device.create_buffer(&info, None) }.map_err(vulkan)?; + let raw = unsafe { crate::creation::buffer(raw_device, &info) }.map_err(vulkan)?; shared.counts.buffer_made(info.usage); // SAFETY: `raw` is a live buffer of this device. let requirements = unsafe { raw_device.get_buffer_memory_requirements(raw) }; @@ -184,9 +184,9 @@ impl Device { }; // SAFETY: the placement is the pages' memory, at least the buffer's size and of a type it // takes, at offset 0, which every alignment divides; the buffer is unbound. - if let Err(error) = - unsafe { raw_device.bind_buffer_memory(raw, placement.memory, placement.offset) } - { + if let Err(error) = unsafe { + crate::creation::bind_buffer(raw_device, raw, placement.memory, placement.offset) + } { // SAFETY: the buffer is unused. unsafe { release::object(raw_device, raw) }; lock(&shared.memory).free(raw_device, &placement); diff --git a/crates/metal2vulkan-runtime/src/heap_sets.rs b/crates/metal2vulkan-runtime/src/heap_sets.rs index b8e26af8e..6363b0377 100644 --- a/crates/metal2vulkan-runtime/src/heap_sets.rs +++ b/crates/metal2vulkan-runtime/src/heap_sets.rs @@ -361,7 +361,7 @@ impl Table { .usage(vk::BufferUsageFlags::STORAGE_BUFFER), ); // SAFETY: the device is live and `info` valid. - let buffer = unsafe { raw.create_buffer(&info, None) }.map_err(vulkan)?; + let buffer = unsafe { crate::creation::buffer(raw, &info) }.map_err(vulkan)?; // SAFETY: `buffer` is a live buffer of this device. let requirements = unsafe { raw.get_buffer_memory_requirements(buffer) }; let placement = match crate::memory::allocate( @@ -380,7 +380,12 @@ impl Table { let table = Table { buffer, placement }; // SAFETY: the placement meets the buffer's requirements and is not bound elsewhere. let bound = unsafe { - raw.bind_buffer_memory(buffer, table.placement.memory, table.placement.offset) + crate::creation::bind_buffer( + raw, + buffer, + table.placement.memory, + table.placement.offset, + ) }; if let Err(error) = bound.map_err(vulkan).and_then(|()| table.start()) { table.destroy(raw, &mut lock(&shared.memory)); diff --git a/crates/metal2vulkan-runtime/src/memory.rs b/crates/metal2vulkan-runtime/src/memory.rs index 98486d1d3..7eec41f58 100644 --- a/crates/metal2vulkan-runtime/src/memory.rs +++ b/crates/metal2vulkan-runtime/src/memory.rs @@ -632,7 +632,7 @@ fn address_buffer( .usage(usage(true)), ); // SAFETY: the device is live and `info` valid. - let raw = unsafe { device.create_buffer(&info, None) }.map_err(vulkan)?; + let raw = unsafe { crate::creation::buffer(device, &info) }.map_err(vulkan)?; // SAFETY: `raw` is a live buffer of this device. let required = unsafe { device.get_buffer_memory_requirements(raw) }.size; Ok((raw, required)) @@ -651,7 +651,7 @@ unsafe fn bind_addresses( memory: vk::DeviceMemory, ) -> Result { // SAFETY: the caller's contract. - if let Err(error) = unsafe { device.bind_buffer_memory(raw, memory, 0) } { + if let Err(error) = unsafe { crate::creation::bind_buffer(device, raw, memory, 0) } { // SAFETY: the buffer is unused. unsafe { release::object(device, raw) }; return Err(vulkan(error)); @@ -1412,7 +1412,7 @@ impl Memory { // SAFETY: `info` and its chain live for the call; the type index is the device's and // allows the dma-buf (and the image, unbound and made for dma-bufs, whose size this // is). A failed import leaves the descriptor open, the caller's. - match unsafe { device.allocate_memory(&info, None) } { + match unsafe { crate::creation::allocate_memory(device, &info) } { Ok(memory) => { // A successful import owns the descriptor: Vulkan closes it with the memory. let _ = fd.into_raw_fd(); @@ -1537,7 +1537,7 @@ impl BlockMaker { info = info.push_next(&mut flags); } // SAFETY: `info` and its chain live for the call; the type index is the device's. - let memory = match unsafe { device.allocate_memory(&info, None) } { + let memory = match unsafe { crate::creation::allocate_memory(device, &info) } { Ok(memory) => memory, Err(error) => { release_addresses(); @@ -1601,7 +1601,7 @@ fn buffer_types( ) -> Result { let info = sharing.buffer(vk::BufferCreateInfo::default().size(16).usage(usage)); // SAFETY: the device is live and `info` valid. - let raw = unsafe { device.create_buffer(&info, None) }.map_err(vulkan)?; + let raw = unsafe { crate::creation::buffer(device, &info) }.map_err(vulkan)?; // SAFETY: `raw` is a live buffer of this device, destroyed right after the query with no // memory bound. Ok(unsafe { @@ -1706,7 +1706,7 @@ unsafe fn import_pointer( } // SAFETY: `info` and its chain live for the call; the type index is the device's and // allows the pointer; the caller's contract keeps the memory mapped. - match unsafe { device.allocate_memory(&info, None) } { + match unsafe { crate::creation::allocate_memory(device, &info) } { Ok(memory) => return Ok((memory, type_index)), Err(error) => failure = ImportFailure::Vulkan(error), } diff --git a/crates/metal2vulkan-runtime/src/mipmap_scratch.rs b/crates/metal2vulkan-runtime/src/mipmap_scratch.rs index 7ae834145..1d60a1359 100644 --- a/crates/metal2vulkan-runtime/src/mipmap_scratch.rs +++ b/crates/metal2vulkan-runtime/src/mipmap_scratch.rs @@ -219,7 +219,7 @@ impl Device { .sharing() .buffer(vk::BufferCreateInfo::default().size(size).usage(usage)); // SAFETY: the device is live and `info` valid. - let raw = unsafe { raw_device.create_buffer(&info, None) }.map_err(vulkan)?; + let raw = unsafe { crate::creation::buffer(raw_device, &info) }.map_err(vulkan)?; // SAFETY: `raw` is a live buffer of this device. let requirements = unsafe { raw_device.get_buffer_memory_requirements(raw) }; let allocated = if addressed { @@ -241,8 +241,9 @@ impl Device { let placed = allocated.and_then(|placement| { // SAFETY: the placement meets the buffer's requirements and is bound nowhere // else. - match unsafe { raw_device.bind_buffer_memory(raw, placement.memory, placement.offset) } - { + match unsafe { + crate::creation::bind_buffer(raw_device, raw, placement.memory, placement.offset) + } { Ok(()) => Ok(placement), Err(error) => { lock(&shared.memory).free(raw_device, &placement); diff --git a/crates/metal2vulkan-runtime/src/neutral.rs b/crates/metal2vulkan-runtime/src/neutral.rs index 2cd1913de..b91e09963 100644 --- a/crates/metal2vulkan-runtime/src/neutral.rs +++ b/crates/metal2vulkan-runtime/src/neutral.rs @@ -200,7 +200,7 @@ impl Device { .usage(usage | vk::BufferUsageFlags::TRANSFER_DST), ); // SAFETY: the device is live and `info` valid. - let buffer = unsafe { raw_device.create_buffer(&info, None) }.map_err(vulkan)?; + let buffer = unsafe { crate::creation::buffer(raw_device, &info) }.map_err(vulkan)?; // SAFETY: `buffer` is a live buffer of this device. let requirements = unsafe { raw_device.get_buffer_memory_requirements(buffer) }; let placement = match crate::memory::allocate( @@ -222,9 +222,9 @@ impl Device { unsafe { release::object(raw_device, buffer) }; }; // SAFETY: the placement meets the buffer's requirements and is not bound elsewhere. - if let Err(error) = - unsafe { raw_device.bind_buffer_memory(buffer, placement.memory, placement.offset) } - { + if let Err(error) = unsafe { + crate::creation::bind_buffer(raw_device, buffer, placement.memory, placement.offset) + } { release(&placement); return Err(vulkan(error)); } @@ -364,9 +364,9 @@ impl Device { unsafe { release::object(raw_device, image) }; }; // SAFETY: the placement meets the image's requirements and is not bound elsewhere. - if let Err(error) = - unsafe { raw_device.bind_image_memory(image, placement.memory, placement.offset) } - { + if let Err(error) = unsafe { + crate::creation::bind_image(raw_device, image, placement.memory, placement.offset) + } { release(&placement); return Err(vulkan(error)); } @@ -383,7 +383,7 @@ impl Device { .format(format) .subresource_range(range); // SAFETY: the image is live and bound; the view type takes its layers. - let view = match unsafe { raw_device.create_image_view(&view_info, None) } { + let view = match unsafe { crate::creation::image_view(raw_device, &view_info) } { Ok(view) => view, Err(error) => { release(&placement); diff --git a/crates/metal2vulkan-runtime/src/storage_placeholder.rs b/crates/metal2vulkan-runtime/src/storage_placeholder.rs index 1ddbb1d8b..f551e08ba 100644 --- a/crates/metal2vulkan-runtime/src/storage_placeholder.rs +++ b/crates/metal2vulkan-runtime/src/storage_placeholder.rs @@ -135,7 +135,7 @@ impl Placeholder { layer_count: key.1, }); // SAFETY: the image is live and bound; the layers are among its own (`covers`). - let view = unsafe { device.create_image_view(&info, None) }.map_err(vulkan)?; + let view = unsafe { crate::creation::image_view(device, &info) }.map_err(vulkan)?; views.push((key, view)); Ok(view) } @@ -258,9 +258,9 @@ impl Device { } }; // SAFETY: the placement meets the image's requirements and is not bound elsewhere. - if let Err(error) = - unsafe { raw_device.bind_image_memory(image, placement.memory, placement.offset) } - { + if let Err(error) = unsafe { + crate::creation::bind_image(raw_device, image, placement.memory, placement.offset) + } { lock(&shared.memory).free(raw_device, &placement); // SAFETY: the image is unused. unsafe { release::object(raw_device, image) }; diff --git a/crates/metal2vulkan-runtime/src/tests/exit_guard.rs b/crates/metal2vulkan-runtime/src/tests/exit_guard.rs index 654130594..8d1fb0a18 100644 --- a/crates/metal2vulkan-runtime/src/tests/exit_guard.rs +++ b/crates/metal2vulkan-runtime/src/tests/exit_guard.rs @@ -1505,6 +1505,28 @@ fn every_image_render_pass_and_framebuffer_goes_through_the_creation_door() { ); } +/// Every buffer, image view, memory allocation and binding the runtime makes goes through +/// `creation.rs` too, where each counts itself at its caller's place (`churn_counts.rs`): a +/// making outside the door would be driver work no call of the API could be held to. The device's +/// priming makes its own, on the thread that makes the device. +#[test] +fn every_buffer_view_allocation_and_binding_goes_through_the_creation_door() { + let found: Vec = [ + ".create_buffer(", + ".create_image_view(", + ".allocate_memory(", + ".bind_image_memory(", + ".bind_buffer_memory(", + ] + .iter() + .flat_map(|needle| uses(&["creation.rs", "device/prime.rs"], needle, &[])) + .collect(); + assert!( + found.is_empty(), + "buffers, views, allocations or bindings made outside creation.rs: {found:#?}" + ); +} + /// Every instance the runtime creates goes through `device/create.rs`'s door (`new_instance`), /// which registers the exit hook again after it: a layer registers an exit handler at each /// `vkCreateInstance`. The runtime's sources call `vkCreateInstance` once, in that door, and the diff --git a/crates/metal2vulkan-runtime/src/texture.rs b/crates/metal2vulkan-runtime/src/texture.rs index 44e28dcf1..8ff8eb85d 100644 --- a/crates/metal2vulkan-runtime/src/texture.rs +++ b/crates/metal2vulkan-runtime/src/texture.rs @@ -1013,7 +1013,7 @@ impl Image { let mut usage = vk::ImageViewUsageCreateInfo::default(); let info = view.create_info(image, &mut usage); // SAFETY: the caller's. - unsafe { self.device.shared().vk().create_image_view(&info, None) }.map_err(vulkan) + unsafe { crate::creation::image_view(self.device.shared().vk(), &info) }.map_err(vulkan) } /// Exchange the image's `VkImage` and views with `objects`'s: the image is `objects`'s new @@ -1931,9 +1931,9 @@ impl Device { } }; // SAFETY: the placement meets the image's requirements and is not bound elsewhere. - if let Err(error) = - unsafe { raw_device.bind_image_memory(raw, placement.memory, placement.offset) } - { + if let Err(error) = unsafe { + crate::creation::bind_image(raw_device, raw, placement.memory, placement.offset) + } { lock(&shared.memory).free(raw_device, &placement); // SAFETY: the image is unused. unsafe { release::object(raw_device, raw) }; @@ -2591,7 +2591,9 @@ impl Device { // SAFETY: the image is live and unbound; the memory is the buffer's, which outlives the // texture holding it, in a type the image takes, at an offset `aliases` checked against // the image's alignment and size. - if let Err(error) = unsafe { raw_device.bind_image_memory(raw, memory, memory_offset) } { + if let Err(error) = + unsafe { crate::creation::bind_image(raw_device, raw, memory, memory_offset) } + { // SAFETY: the image is live and unbound, and no command uses it. unsafe { release::object(raw_device, raw) }; return Err(vulkan(error)); @@ -2856,9 +2858,9 @@ impl Device { } }; // SAFETY: the placement meets the image's requirements and is not bound elsewhere. - if let Err(error) = - unsafe { raw_device.bind_image_memory(raw, placement.memory, placement.offset) } - { + if let Err(error) = unsafe { + crate::creation::bind_image(raw_device, raw, placement.memory, placement.offset) + } { lock(&shared.memory).free(raw_device, &placement); // SAFETY: the image is unused. unsafe { release::object(raw_device, raw) }; @@ -3791,7 +3793,7 @@ impl Staging<'_> { .usage(vk::BufferUsageFlags::TRANSFER_SRC | vk::BufferUsageFlags::TRANSFER_DST), ); // SAFETY: the device is live and `info` valid. - let raw = unsafe { raw_device.create_buffer(&info, None) }.map_err(vulkan)?; + let raw = unsafe { crate::creation::buffer(raw_device, &info) }.map_err(vulkan)?; // SAFETY: `raw` is a live buffer of this device. let requirements = unsafe { raw_device.get_buffer_memory_requirements(raw) }; let placement = match crate::memory::allocate( @@ -3818,7 +3820,12 @@ impl Staging<'_> { } // SAFETY: the placement meets the buffer's requirements and is not bound elsewhere. unsafe { - raw_device.bind_buffer_memory(raw, staging.placement.memory, staging.placement.offset) + crate::creation::bind_buffer( + raw_device, + raw, + staging.placement.memory, + staging.placement.offset, + ) } .map_err(vulkan)?; Ok(staging) diff --git a/crates/metal2vulkan-runtime/src/texture/first_move.rs b/crates/metal2vulkan-runtime/src/texture/first_move.rs index 7bcb880ef..db7d604ed 100644 --- a/crates/metal2vulkan-runtime/src/texture/first_move.rs +++ b/crates/metal2vulkan-runtime/src/texture/first_move.rs @@ -1213,8 +1213,9 @@ impl Scratch { } }; // SAFETY: the placement meets the image's requirements and is bound nowhere else. - let bound = - unsafe { raw_device.bind_image_memory(image, placement.memory, placement.offset) }; + let bound = unsafe { + crate::creation::bind_image(raw_device, image, placement.memory, placement.offset) + }; if let Err(error) = bound { // SAFETY: the image is unused. unsafe { release::object(raw_device, image) }; @@ -1237,7 +1238,7 @@ impl Zeros { .usage(vk::BufferUsageFlags::TRANSFER_SRC), ); // SAFETY: the device is live and `info` valid. - let raw = unsafe { raw_device.create_buffer(&info, None) }.map_err(vulkan)?; + let raw = unsafe { crate::creation::buffer(raw_device, &info) }.map_err(vulkan)?; // SAFETY: `raw` is a live buffer of this device. let requirements = unsafe { raw_device.get_buffer_memory_requirements(raw) }; let placement = match crate::memory::allocate( @@ -1258,7 +1259,12 @@ impl Zeros { None => Err(Error::OutOfMemory(MemoryKind::Host)), // SAFETY: the placement meets the buffer's requirements and is bound nowhere else. Some(mapped) => unsafe { - raw_device.bind_buffer_memory(raw, made.placement.memory, made.placement.offset) + crate::creation::bind_buffer( + raw_device, + raw, + made.placement.memory, + made.placement.offset, + ) } .map_err(vulkan) .map(|()| mapped), @@ -1296,7 +1302,7 @@ impl Zeros { let info = (shared.sharing()).buffer(vk::BufferCreateInfo::default().size(length).usage(usage)); // SAFETY: the device is live and `info` valid. - let raw = unsafe { raw_device.create_buffer(&info, None) }.map_err(vulkan)?; + let raw = unsafe { crate::creation::buffer(raw_device, &info) }.map_err(vulkan)?; // SAFETY: `raw` is a live buffer of this device. let requirements = unsafe { raw_device.get_buffer_memory_requirements(raw) }; let placement = match crate::memory::allocate( @@ -1315,7 +1321,12 @@ impl Zeros { let made = Zeros { raw, placement }; // SAFETY: the placement meets the buffer's requirements and is bound nowhere else. let bound = unsafe { - raw_device.bind_buffer_memory(raw, made.placement.memory, made.placement.offset) + crate::creation::bind_buffer( + raw_device, + raw, + made.placement.memory, + made.placement.offset, + ) }; if let Err(error) = bound { made.destroy(raw_device, &mut lock(&shared.memory)); diff --git a/crates/metal2vulkan-runtime/src/texture/heap.rs b/crates/metal2vulkan-runtime/src/texture/heap.rs index 0c516f94c..3c644ab3a 100644 --- a/crates/metal2vulkan-runtime/src/texture/heap.rs +++ b/crates/metal2vulkan-runtime/src/texture/heap.rs @@ -2698,7 +2698,7 @@ impl Device { // SAFETY: the image is live and unbound; the memory is the heap's, which the texture // holds, of a type the image takes (`new_heap_texture`, `host_heap_plan`), at an offset // that meets the image's alignment and with its size inside the heap. - if let Err(error) = unsafe { raw_device.bind_image_memory(raw, memory, at) } { + if let Err(error) = unsafe { crate::creation::bind_image(raw_device, raw, memory, at) } { // SAFETY: the image is live and unbound, and no command uses it. unsafe { release::object(raw_device, raw) }; return Err(vulkan(error)); @@ -3544,7 +3544,7 @@ impl Device { .usage(buffer_usage(shared.device_address)), ); // SAFETY: the device is live and `info` valid. - let raw = unsafe { raw_device.create_buffer(&info, None) }.map_err(vulkan)?; + let raw = unsafe { crate::creation::buffer(raw_device, &info) }.map_err(vulkan)?; // SAFETY: `raw` is a live buffer of this device, which nothing else uses: it is // destroyed right after the query, with no memory bound. let requirements = unsafe { diff --git a/crates/metal2vulkan-runtime/src/texture/stand_in.rs b/crates/metal2vulkan-runtime/src/texture/stand_in.rs index c6691dc35..7a1f2e334 100644 --- a/crates/metal2vulkan-runtime/src/texture/stand_in.rs +++ b/crates/metal2vulkan-runtime/src/texture/stand_in.rs @@ -204,7 +204,12 @@ impl Device { let image = StandInImage { raw, placement }; // SAFETY: the placement meets the image's requirements and is bound nowhere else. if let Err(error) = unsafe { - raw_device.bind_image_memory(raw, image.placement.memory, image.placement.offset) + crate::creation::bind_image( + raw_device, + raw, + image.placement.memory, + image.placement.offset, + ) } { self.drop_stand_in_image(&image); return Err(vulkan(error)); diff --git a/crates/metal2vulkan-validation/runtime-sources.sha256 b/crates/metal2vulkan-validation/runtime-sources.sha256 index d87d63f96..38ea14e01 100644 --- a/crates/metal2vulkan-validation/runtime-sources.sha256 +++ b/crates/metal2vulkan-validation/runtime-sources.sha256 @@ -1 +1 @@ -a665c4b979e8e1a941791a3e47071af80db3bd438d103189bb393472b0904d2d +70c2e8b719e64c75b7f6233d46aa1f0c8537ebb25fc96e3041451d5c17bd3fab