diff --git a/crates/metal2vulkan-runtime/src/color_resolve.rs b/crates/metal2vulkan-runtime/src/color_resolve.rs index f5ee15c89..83ed3516a 100644 --- a/crates/metal2vulkan-runtime/src/color_resolve.rs +++ b/crates/metal2vulkan-runtime/src/color_resolve.rs @@ -540,7 +540,6 @@ fn resolve_pipeline( making: Making, ) -> Result { let shared = device.shared(); - let raw = shared.vk(); let stages = [ vk::PipelineShaderStageCreateInfo::default() .stage(vk::ShaderStageFlags::VERTEX) @@ -582,17 +581,7 @@ fn resolve_pipeline( .layout(made.layout) .render_pass(made.render_pass) .subpass(0); - let created = shared - .make_pipelines(making, |cache| { - // SAFETY: every pointer in `info` outlives the call; the pipeline cache is the - // making's own (`shader_cache/driver.rs`). - unsafe { raw.create_graphics_pipelines(cache, &[info], None) } - }) - .map_err(|(_, error)| vulkan(error))?; - created - .first() - .copied() - .ok_or_else(|| internal("the driver made no pipeline")) + shared.make_graphics_pipeline(making, info) } /// The objects one pass's resolves hold until its command buffer completes, and, kept diff --git a/crates/metal2vulkan-runtime/src/depth_copy.rs b/crates/metal2vulkan-runtime/src/depth_copy.rs index b749a8971..17ae82cb2 100644 --- a/crates/metal2vulkan-runtime/src/depth_copy.rs +++ b/crates/metal2vulkan-runtime/src/depth_copy.rs @@ -62,7 +62,7 @@ use super::binding_view::VkView; use super::degradation::Degradation; use super::device::{device_error, lock}; -use super::error::{internal, vulkan, Error}; +use super::error::{internal, Error}; use super::release; use super::render_pass::Target; use super::sample_planes::{pipeline_layout, set_layout, shader_module}; @@ -500,17 +500,8 @@ impl Device { let info = vk::ComputePipelineCreateInfo::default() .stage(stage) .layout(kernel.layout); - let created = shared - .make_pipelines(Making::new("depth split").words(&module.spirv), |cache| { - // SAFETY: every pointer in `info` outlives the call; the pipeline cache is the - // making's own (`shader_cache/driver.rs`). - unsafe { raw.create_compute_pipelines(cache, &[info], None) } - }) - .map_err(|(_, error)| vulkan(error))?; - kernel.pipeline = created - .first() - .copied() - .ok_or_else(|| internal("the driver made no pipeline"))?; + kernel.pipeline = shared + .make_compute_pipeline(Making::new("depth split").words(&module.spirv), info)?; Ok(()) })(); match made { @@ -691,7 +682,6 @@ fn depth_pipeline( (colour, making): (bool, Making), ) -> Result { let shared = device.shared(); - let raw = shared.vk(); let stages = [ vk::PipelineShaderStageCreateInfo::default() .stage(vk::ShaderStageFlags::VERTEX) @@ -749,17 +739,7 @@ fn depth_pipeline( true => info, false => info.depth_stencil_state(&depth_stencil), }; - let created = shared - .make_pipelines(making, |cache| { - // SAFETY: every pointer in `info` outlives the call; the pipeline cache is the - // making's own (`shader_cache/driver.rs`). - unsafe { raw.create_graphics_pipelines(cache, &[info], None) } - }) - .map_err(|(_, error)| vulkan(error))?; - created - .first() - .copied() - .ok_or_else(|| internal("the driver made no pipeline")) + shared.make_graphics_pipeline(making, info) } /// Make, where they are not yet made, the draw's objects for a destination of `format` at diff --git a/crates/metal2vulkan-runtime/src/depth_stencil_resolve.rs b/crates/metal2vulkan-runtime/src/depth_stencil_resolve.rs index 6fc8d9238..d8e7ab057 100644 --- a/crates/metal2vulkan-runtime/src/depth_stencil_resolve.rs +++ b/crates/metal2vulkan-runtime/src/depth_stencil_resolve.rs @@ -41,7 +41,7 @@ use super::device::{device_error, lock}; use super::encoder::EncoderCore; -use super::error::{internal, vulkan, Error, RuntimeGap}; +use super::error::{internal, Error, RuntimeGap}; use super::release; use super::render_pass::{PassLayout, Target}; use super::resource::ResourceKey; @@ -341,7 +341,6 @@ fn draw_pipeline( (write, making): (ResolveWrite, Making), ) -> Result { let shared = device.shared(); - let raw = shared.vk(); let stages = [ vk::PipelineShaderStageCreateInfo::default() .stage(vk::ShaderStageFlags::VERTEX) @@ -405,17 +404,7 @@ fn draw_pipeline( .layout(shaders.layout) .render_pass(render_pass) .subpass(0); - let created = shared - .make_pipelines(making, |cache| { - // SAFETY: every pointer in `info` outlives the call; the pipeline cache is the - // making's own (`shader_cache/driver.rs`). - unsafe { raw.create_graphics_pipelines(cache, &[info], None) } - }) - .map_err(|(_, error)| vulkan(error))?; - created - .first() - .copied() - .ok_or_else(|| internal("the driver made no pipeline")) + shared.make_graphics_pipeline(making, info) } /// Whether the draws can resolve `aspects` of `source` by `pick` into `into`, and their objects diff --git a/crates/metal2vulkan-runtime/src/device/mod.rs b/crates/metal2vulkan-runtime/src/device/mod.rs index 0b9e518e1..2d80a6cd1 100644 --- a/crates/metal2vulkan-runtime/src/device/mod.rs +++ b/crates/metal2vulkan-runtime/src/device/mod.rs @@ -55,7 +55,7 @@ use super::depth_copy::DepthCopyObjects; use super::depth_stencil_resolve::DepthStencilResolveObjects; use super::draw_source::{sized_index_bind, SizedIndexBind}; use super::dynamic_state::{ColorWriteMasks, ExtendedDynamicState}; -use super::error::{vulkan, Error}; +use super::error::{internal, vulkan, Error}; use super::exit_guard::{self, Call}; use super::freed_memory::Parking; use super::function_table::TableShared; @@ -79,7 +79,8 @@ use super::resource_ids::{PassingHolds, ResourceIds, SamplerIdReads}; use super::sample_planes::PlanesObjects; use super::sampler::{LiveSamplers, SamplerCount}; use super::scheduler::Scheduler; -use super::shader_cache::{CacheSetup, ShaderCache}; +use super::shader_cache::driver::Making; +use super::shader_cache::{found_in_cache, CacheSetup, ShaderCache, REPORTED_STAGES}; use super::sharing::Sharing; use super::spares::Spares; use super::sparse::device::SparseDevice; @@ -690,25 +691,16 @@ impl DeviceShared { } /// What `create` makes with the `VkPipelineCache` it is handed, its `vkCreate*Pipelines` call: - /// a cache of the making's own, seeded from the record `making` names - /// (`ShaderCache::make_pipelines`, `shader_cache/driver.rs`). On a pool's thread the exit waits - /// for it longer (`exit_guard::driver_making`). - pub(crate) fn make_pipelines( - &self, - making: crate::shader_cache::driver::Making, - create: impl FnOnce(vk::PipelineCache) -> Result, - ) -> Result { - self.make_pipelines_reported(making, |cache| (create(cache), None)) - } - - /// [`make_pipelines`](Self::make_pipelines), with what the driver reported of the making: - /// `create` returns, with what it made, whether the driver found its pipeline in the cache it - /// was handed (`shader_cache::found_in_cache`, `None` where it reports nothing). A making - /// from its record that the driver reports found reads no data back and writes nothing - /// (`shader_cache/driver.rs`). + /// the device's cache of the record `making` names, seeded from that record + /// (`ShaderCache::make_pipelines`, `shader_cache/driver.rs`). `create` returns, with what it + /// made, whether the driver found its pipeline in the cache it was handed + /// (`shader_cache::found_in_cache`, `None` where it reports nothing). A making from its record + /// that the driver reports found reads no data back and writes nothing + /// (`shader_cache/driver.rs`). On a pool's thread the exit waits for it longer + /// (`exit_guard::driver_making`). pub(crate) fn make_pipelines_reported( &self, - making: crate::shader_cache::driver::Making, + making: Making, create: impl FnOnce(vk::PipelineCache) -> (Result, Option), ) -> Result { // What every making is measured to report, withheld inside it (`driver_facts.rs`); a @@ -721,6 +713,92 @@ impl DeviceShared { }) } + /// The compute pipeline of `info`, made as + /// [`make_pipelines_reported`](Self::make_pipelines_reported) makes one under the record + /// `making` names, with what its driver reports of it where the device's makings report + /// (`VK_EXT_pipeline_creation_feedback`, counted in `driver_pipeline_hits` and `misses`): one + /// found in a cache loaded from its record reads no data back and writes nothing, whatever + /// bytes the driver's data holds after it. A program's compute pipelines and the runtime's + /// own kernels. + pub(crate) fn make_compute_pipeline( + &self, + making: Making, + info: vk::ComputePipelineCreateInfo<'_>, + ) -> Result { + let reports = self.shader_cache.driver_reports(); + let mut whole = vk::PipelineCreationFeedback::default(); + let mut stage = [vk::PipelineCreationFeedback::default()]; + let made = self.make_pipelines_reported(making, |cache| { + let mut feedback = vk::PipelineCreationFeedbackCreateInfo::default() + .pipeline_creation_feedback(&mut whole) + .pipeline_stage_creation_feedbacks(&mut stage); + let mut info = info; + if reports { + info = info.push_next(&mut feedback); + } + // SAFETY: what `info` points to outlives it, and so the call; the cache is the + // device's of the record, or none. + let made = unsafe { self.vk().create_compute_pipelines(cache, &[info], None) }; + let found = reports.then(|| found_in_cache(&whole, &stage)).flatten(); + (made, found) + }); + self.made_one(made, reports.then_some((&whole, &stage[..]))) + } + + /// The graphics pipeline, or graphics pipeline library, of `info`, made and reported as + /// [`make_compute_pipeline`](Self::make_compute_pipeline) makes a compute pipeline: a library + /// of shaders of a render pipeline linked from libraries (`pipeline/graphics.rs`), and the + /// runtime's own draws (its copies, resolves and planes steps). + pub(crate) fn make_graphics_pipeline( + &self, + making: Making, + info: vk::GraphicsPipelineCreateInfo<'_>, + ) -> Result { + let reports = self.shader_cache.driver_reports(); + // Its stages' feedback where it has at most `REPORTED_STAGES`, none where more (a count of + // 0 is valid, one equal to `stageCount` else: + // VUID-VkGraphicsPipelineCreateInfo-pipelineStageCreationFeedbackCount-06594). + let mut whole = vk::PipelineCreationFeedback::default(); + let mut stages = [vk::PipelineCreationFeedback::default(); REPORTED_STAGES]; + let count = info.stage_count as usize; + let reported = if count <= REPORTED_STAGES { count } else { 0 }; + let made = self.make_pipelines_reported(making, |cache| { + let mut feedback = vk::PipelineCreationFeedbackCreateInfo::default() + .pipeline_creation_feedback(&mut whole) + .pipeline_stage_creation_feedbacks(&mut stages[..reported]); + let mut info = info; + if reports { + info = info.push_next(&mut feedback); + } + // SAFETY: as `make_compute_pipeline`'s. + let made = unsafe { self.vk().create_graphics_pipelines(cache, &[info], None) }; + let found = reports + .then(|| found_in_cache(&whole, &stages[..reported])) + .flatten(); + (made, found) + }); + self.made_one(made, reports.then_some((&whole, &stages[..reported]))) + } + + /// The one pipeline a making `made`, with what its driver reported of it, `reported`, counted + /// where the making chained the reports and made it. + fn made_one( + &self, + made: Result, (Vec, vk::Result)>, + reported: Option<( + &vk::PipelineCreationFeedback, + &[vk::PipelineCreationFeedback], + )>, + ) -> Result { + let made = made.map_err(|(_, error)| vulkan(error))?; + if let Some((whole, stages)) = reported { + self.shader_cache.driver_reported(whole, stages); + } + made.first() + .copied() + .ok_or_else(|| internal("the driver made no pipeline")) + } + /// The device's functions. The runtime's own threads reach them only inside a section of /// the exit guard, or while they run the program's code, and a section reaches only the exit /// guard's table of entry points; builds with debug assertions end the process otherwise diff --git a/crates/metal2vulkan-runtime/src/owned_kernel.rs b/crates/metal2vulkan-runtime/src/owned_kernel.rs index f659b049c..dccf17107 100644 --- a/crates/metal2vulkan-runtime/src/owned_kernel.rs +++ b/crates/metal2vulkan-runtime/src/owned_kernel.rs @@ -965,26 +965,16 @@ fn make( let info = vk::ComputePipelineCreateInfo::default() .stage(stage) .layout(kernel.layout); - let created = shared - .make_pipelines( - Making::new("owned kernel").words(spirv).text(&( - images, - storage_images, - buffers, - push_bytes, - pushed, - )), - |cache| { - // SAFETY: every pointer in `info` outlives the call; the pipeline cache is the - // making's own (`shader_cache/driver.rs`). - unsafe { raw.create_compute_pipelines(cache, &[info], None) } - }, - ) - .map_err(|(_, error)| vulkan(error))?; - kernel.pipeline = created - .first() - .copied() - .ok_or_else(|| internal("the driver made no pipeline"))?; + kernel.pipeline = shared.make_compute_pipeline( + Making::new("owned kernel").words(spirv).text(&( + images, + storage_images, + buffers, + push_bytes, + pushed, + )), + info, + )?; Ok(()) })(); match made { diff --git a/crates/metal2vulkan-runtime/src/pipeline/graphics.rs b/crates/metal2vulkan-runtime/src/pipeline/graphics.rs index 8fedacd7f..387ea809f 100644 --- a/crates/metal2vulkan-runtime/src/pipeline/graphics.rs +++ b/crates/metal2vulkan-runtime/src/pipeline/graphics.rs @@ -1348,32 +1348,34 @@ impl VariantObjects { vk::GraphicsPipelineLibraryCreateInfoEXT::default().flags(part.flag()); let info = infos.part(part, &mut flag); // A part with shaders is made through the device's shader cache, under a record - // of its own; one without holds nothing a record would keep. + // of its own, with what its driver reports of it; one without holds nothing a + // record would keep. let made = match part.holds_shaders() { true => { let _ = creation_log::take_record(); - let made = - self.library_of_shaders(Making::new(part.kind()).digest(name), info); + let made = shared + .make_graphics_pipeline(Making::new(part.kind()).digest(name), info); made_here = Some(creation_log::take_record()); - made + made? } false => { made_here = Some(None); // SAFETY: every pointer in `info` outlives the call. - unsafe { + let made = unsafe { shared.vk().create_graphics_pipelines( vk::PipelineCache::null(), &[info], None, ) - } + }; + made.map_err(|(_, error)| vulkan(error))? + .first() + .copied() + .ok_or_else(|| internal("the driver made no pipeline library"))? } }; - let made = made.map_err(|(_, error)| vulkan(error))?; shared.counts.pipeline_library_made(part); - made.first() - .copied() - .ok_or_else(|| internal("the driver made no pipeline library")) + Ok(made) })?; if let Some(at) = asked { let how = match made_here { @@ -1407,50 +1409,6 @@ impl VariantObjects { .copied() .ok_or_else(|| internal("the driver linked no pipeline")) } - - /// The library of `info`, a part that holds shaders, made through the device's shader cache - /// under the record `making` names, with what its driver reports of it as a whole pipeline's - /// making has (`shader_cache::found_in_cache`, counted in `driver_pipeline_hits` and - /// `misses`): one found in a cache loaded from its record reads no data back and writes - /// nothing (`shader_cache/driver.rs`), whatever bytes the driver's data holds after it. - fn library_of_shaders( - &self, - making: Making, - info: vk::GraphicsPipelineCreateInfo<'_>, - ) -> Result, (Vec, vk::Result)> { - let shared = self.device.shared(); - let driver_reports = shared.shader_cache.driver_reports(); - // Its stages' feedback where it has at most `REPORTED_STAGES`, none where more (a count - // of 0 is valid, one equal to `stageCount` else: - // VUID-VkGraphicsPipelineCreateInfo-pipelineStageCreationFeedbackCount-06594). - let mut whole = vk::PipelineCreationFeedback::default(); - let mut stages = [vk::PipelineCreationFeedback::default(); REPORTED_STAGES]; - let count = info.stage_count as usize; - let reported_stages = if count <= REPORTED_STAGES { count } else { 0 }; - let made = shared.make_pipelines_reported(making, |cache| { - let reported = &mut stages[..reported_stages]; - let mut feedback = vk::PipelineCreationFeedbackCreateInfo::default() - .pipeline_creation_feedback(&mut whole) - .pipeline_stage_creation_feedbacks(reported); - let mut info = info; - if driver_reports { - info = info.push_next(&mut feedback); - } - // SAFETY: every pointer in `info` outlives the call; the pipeline cache is the - // device's for the record, or none. - let made = unsafe { shared.vk().create_graphics_pipelines(cache, &[info], None) }; - let found = driver_reports - .then(|| found_in_cache(&whole, &stages[..reported_stages])) - .flatten(); - (made, found) - }); - if driver_reports && made.is_ok() { - shared - .shader_cache - .driver_reported(&whole, &stages[..reported_stages]); - } - made - } } #[cfg(test)] diff --git a/crates/metal2vulkan-runtime/src/pipeline/objects.rs b/crates/metal2vulkan-runtime/src/pipeline/objects.rs index 846e90607..d2290cccf 100644 --- a/crates/metal2vulkan-runtime/src/pipeline/objects.rs +++ b/crates/metal2vulkan-runtime/src/pipeline/objects.rs @@ -1052,13 +1052,7 @@ impl VariantObjects { if bindable { info = info.push_next(&mut flags); } - // Whether the making's cache held it and its one stage, where the making reports them - // (`shader_cache::found_in_cache`; one stage's feedback, as - // VUID-VkComputePipelineCreateInfo-pipelineStageCreationFeedbackCount-06566 allows). - let mut whole = vk::PipelineCreationFeedback::default(); - let mut stage = [vk::PipelineCreationFeedback::default()]; let shared = self.device.shared(); - let driver_reports = shared.shader_cache.driver_reports(); // Its record is named by the variant's content and what this making adds to it. let making = self.making("compute").text(&( c.object.stage.as_raw(), @@ -1084,34 +1078,10 @@ impl VariantObjects { let started = std::time::Instant::now(); // With what the driver reports of the making: a pipeline found in its record's cache // reads no data back (`shader_cache/driver.rs`). - let created = shared - .make_pipelines_reported(making, |cache| { - let mut feedback = vk::PipelineCreationFeedbackCreateInfo::default() - .pipeline_creation_feedback(&mut whole) - .pipeline_stage_creation_feedbacks(&mut stage); - let mut info = info; - if driver_reports { - info = info.push_next(&mut feedback); - } - // SAFETY: every pointer in `info` outlives the call; the pipeline cache is the - // making's own, destroyed once the call returned. - let made = unsafe { shared.vk().create_compute_pipelines(cache, &[info], None) }; - let found = driver_reports - .then(|| crate::shader_cache::found_in_cache(&whole, &stage)) - .flatten(); - (made, found) - }) - .map_err(|(_, error)| vulkan(error))?; + let raw = shared.make_compute_pipeline(making, info)?; let created_in = started.elapsed(); drop(leader); drop(turn); - if driver_reports { - shared.shader_cache.driver_reported(&whole, &stage); - } - let raw = created - .first() - .copied() - .ok_or_else(|| internal("the driver made no pipeline"))?; self.device.shared().counts.variant_pipeline_made(); let pipeline = RawPipeline { device: self.device.clone(), diff --git a/crates/metal2vulkan-runtime/src/sample_interleave.rs b/crates/metal2vulkan-runtime/src/sample_interleave.rs index e499b169c..ddeb62228 100644 --- a/crates/metal2vulkan-runtime/src/sample_interleave.rs +++ b/crates/metal2vulkan-runtime/src/sample_interleave.rs @@ -255,20 +255,10 @@ impl Device { let info = vk::ComputePipelineCreateInfo::default() .stage(stage) .layout(kernel.layout); - let created = shared - .make_pipelines( - Making::new("interleave split").words(&module.spirv), - |cache| { - // SAFETY: every pointer in `info` outlives the call; the pipeline cache is the - // making's own (`shader_cache/driver.rs`). - unsafe { raw.create_compute_pipelines(cache, &[info], None) } - }, - ) - .map_err(|(_, error)| vulkan(error))?; - kernel.pipeline = created - .first() - .copied() - .ok_or_else(|| internal("the driver made no pipeline"))?; + kernel.pipeline = shared.make_compute_pipeline( + Making::new("interleave split").words(&module.spirv), + info, + )?; Ok(()) })(); if let Err(error) = made { @@ -431,7 +421,6 @@ fn merge_pipeline( making: Making, ) -> Result { let shared = device.shared(); - let raw = shared.vk(); let stages = [ vk::PipelineShaderStageCreateInfo::default() .stage(vk::ShaderStageFlags::VERTEX) @@ -477,17 +466,7 @@ fn merge_pipeline( .layout(shaders.layout) .render_pass(render_pass) .subpass(0); - let created = shared - .make_pipelines(making, |cache| { - // SAFETY: every pointer in `info` outlives the call; the pipeline cache is the - // making's own (`shader_cache/driver.rs`). - unsafe { raw.create_graphics_pipelines(cache, &[info], None) } - }) - .map_err(|(_, error)| vulkan(error))?; - created - .first() - .copied() - .ok_or_else(|| internal("the driver made no pipeline")) + shared.make_graphics_pipeline(making, info) } /// A band's descriptor pool and framebuffer, held until the command buffer completes. diff --git a/crates/metal2vulkan-runtime/src/sample_planes.rs b/crates/metal2vulkan-runtime/src/sample_planes.rs index 3b2f61e0b..a66ef2cbf 100644 --- a/crates/metal2vulkan-runtime/src/sample_planes.rs +++ b/crates/metal2vulkan-runtime/src/sample_planes.rs @@ -467,17 +467,8 @@ impl Device { let info = vk::ComputePipelineCreateInfo::default() .stage(stage) .layout(kernel.layout); - let created = shared - .make_pipelines(Making::new("planes split").words(&module.spirv), |cache| { - // SAFETY: every pointer in `info` outlives the call; the pipeline cache is the - // making's own (`shader_cache/driver.rs`). - unsafe { raw.create_compute_pipelines(cache, &[info], None) } - }) - .map_err(|(_, error)| vulkan(error))?; - kernel.pipeline = created - .first() - .copied() - .ok_or_else(|| internal("the driver made no pipeline"))?; + kernel.pipeline = shared + .make_compute_pipeline(Making::new("planes split").words(&module.spirv), info)?; Ok(()) })(); match made { @@ -651,7 +642,6 @@ fn merge_pipeline( making: Making, ) -> Result { let shared = device.shared(); - let raw = shared.vk(); let stages = [ vk::PipelineShaderStageCreateInfo::default() .stage(vk::ShaderStageFlags::VERTEX) @@ -697,17 +687,7 @@ fn merge_pipeline( .layout(shaders.layout) .render_pass(render_pass) .subpass(0); - let created = shared - .make_pipelines(making, |cache| { - // SAFETY: every pointer in `info` outlives the call; the pipeline cache is the - // making's own (`shader_cache/driver.rs`). - unsafe { raw.create_graphics_pipelines(cache, &[info], None) } - }) - .map_err(|(_, error)| vulkan(error))?; - created - .first() - .copied() - .ok_or_else(|| internal("the driver made no pipeline")) + shared.make_graphics_pipeline(making, info) } /// The objects one pass's planes steps hold until its command buffer completes: their diff --git a/crates/metal2vulkan-runtime/src/shader_cache/driver.rs b/crates/metal2vulkan-runtime/src/shader_cache/driver.rs index 8a379dee3..602e9a0ee 100644 --- a/crates/metal2vulkan-runtime/src/shader_cache/driver.rs +++ b/crates/metal2vulkan-runtime/src/shader_cache/driver.rs @@ -30,14 +30,16 @@ //! library map iterates its modules' keys opposite to their insertion), so the byte comparison //! alone wrote every record of two modules again at each warm making. The data's format is //! MoltenVK's own, undocumented beyond Vulkan's header, so no comparison here reads its -//! entries. A library of shaders, where the device links its render pipelines from graphics -//! pipeline libraries, is made with its driver's report as a whole pipeline is: RADV's data -//! after a library's making from its record is now and then not the record's byte for byte, -//! one byte of over a thousand differing at the same length (Mesa 26.2.6 on a Radeon 780M: -//! both libraries of a state, in 2 runs of 20), which the byte comparison alone took for data -//! the making added, and wrote the record again. A making whose driver reports nothing, or -//! reports a compile, or whose cache was made empty, reads the data and compares its SHA-256 -//! with what the cache was loaded with or last wrote. +//! entries. Every making asks for the driver's report where the device's makings report +//! (`DeviceShared::make_compute_pipeline`, `make_graphics_pipeline`): a program's pipelines, +//! the libraries of shaders a render pipeline is linked from, and the runtime's own pipelines +//! (its copies, resolves, planes steps and kernels). RADV's data after a making from its record +//! is now and then not the record's byte for byte, one byte of over a thousand differing at the +//! same length (Mesa 26.2.6 on a Radeon 780M: both libraries of a state, in 2 runs of 20), +//! which the byte comparison alone took for data the making added, and wrote the record again. +//! A making whose driver reports nothing, or reports a compile, or whose cache was made empty, +//! reads the data and compares its SHA-256 with what the cache was loaded with or last +//! wrote. //! - **Named by what a stage's conversion reads** ([`Making`]). A record is named by the SHA-256 //! of [`VERSION`], the making's description, the driver's identity (vendor, device, driver //! version, `pipelineCacheUUID`) and the digest of the layer settings the instance was created diff --git a/crates/metal2vulkan-runtime/src/shader_cache/mod.rs b/crates/metal2vulkan-runtime/src/shader_cache/mod.rs index ea3bfd1ff..507a38b00 100644 --- a/crates/metal2vulkan-runtime/src/shader_cache/mod.rs +++ b/crates/metal2vulkan-runtime/src/shader_cache/mod.rs @@ -250,7 +250,8 @@ pub struct ShaderCacheStatistics { /// `APPLICATION_PIPELINE_CACHE_HIT`, or every stage's feedback is valid and says it. Drivers /// differ in where they say it: most for the whole pipeline; MoltenVK 1.4.1 for each stage /// alone, whose Metal function it found converted in the cache (its whole pipeline's - /// feedback is only ever valid). Where the device links render pipelines from graphics + /// feedback is only ever valid). The runtime's own pipelines (its copies, resolves and + /// kernels) count as the program's do; where the device links render pipelines from graphics /// pipeline libraries, each library of shaders is such a making (its pre-rasterization or /// fragment shader part), and the link itself is none. pub driver_pipeline_hits: u64, diff --git a/crates/metal2vulkan-runtime/src/stencil_copy.rs b/crates/metal2vulkan-runtime/src/stencil_copy.rs index f457b27f4..e15557eee 100644 --- a/crates/metal2vulkan-runtime/src/stencil_copy.rs +++ b/crates/metal2vulkan-runtime/src/stencil_copy.rs @@ -172,17 +172,8 @@ impl Device { let info = vk::ComputePipelineCreateInfo::default() .stage(stage) .layout(kernel.layout); - let created = shared - .make_pipelines(Making::new("stencil split").words(&module.spirv), |cache| { - // SAFETY: every pointer in `info` outlives the call; the pipeline cache is the - // making's own (`shader_cache/driver.rs`). - unsafe { raw.create_compute_pipelines(cache, &[info], None) } - }) - .map_err(|(_, error)| vulkan(error))?; - kernel.pipeline = created - .first() - .copied() - .ok_or_else(|| internal("the driver made no pipeline"))?; + kernel.pipeline = shared + .make_compute_pipeline(Making::new("stencil split").words(&module.spirv), info)?; Ok(()) })(); match made { @@ -377,7 +368,6 @@ fn plane_pipeline( (samples, bit, making): (u32, StencilBit, Making), ) -> Result { let shared = device.shared(); - let raw = shared.vk(); let stages = [ vk::PipelineShaderStageCreateInfo::default() .stage(vk::ShaderStageFlags::VERTEX) @@ -435,17 +425,7 @@ fn plane_pipeline( .layout(shaders.layout) .render_pass(render_pass) .subpass(0); - let created = shared - .make_pipelines(making, |cache| { - // SAFETY: every pointer in `info` outlives the call; the pipeline cache is the - // making's own (`shader_cache/driver.rs`). - unsafe { raw.create_graphics_pipelines(cache, &[info], None) } - }) - .map_err(|(_, error)| vulkan(error))?; - created - .first() - .copied() - .ok_or_else(|| internal("the driver made no pipeline")) + shared.make_graphics_pipeline(making, info) } /// The objects one copy holds until its command buffer completes: its descriptor set's pool and, diff --git a/crates/metal2vulkan-runtime/src/tests/driver_pipeline_compile.rs b/crates/metal2vulkan-runtime/src/tests/driver_pipeline_compile.rs index c210a0861..076a1482f 100644 --- a/crates/metal2vulkan-runtime/src/tests/driver_pipeline_compile.rs +++ b/crates/metal2vulkan-runtime/src/tests/driver_pipeline_compile.rs @@ -55,7 +55,9 @@ //! **A library of shaders reports what its driver found**, as a whole pipeline's making does: a //! later device over the directory an earlier one wrote counts one report per library of shaders //! it makes, and reads no data back for one found in its record -//! (`a_library_of_shaders_reports_what_its_driver_found`). +//! (`a_library_of_shaders_reports_what_its_driver_found`). So do the runtime's own kernels, and +//! one found in its record writes no record again +//! (`the_runtime_s_own_kernels_found_in_their_records_write_nothing`). //! //! The device takes a shader cache directory of its own, empty, so no run reads a record an //! earlier run stored. @@ -66,6 +68,7 @@ use super::blit_holds::{device, Scratch}; use super::descriptor_key_once::descriptor; +use crate::owned_kernel::OwnedModule; use crate::PipelineOptions; use metal2vulkan::metal::{BlendFactor, BlendOperation}; @@ -247,3 +250,63 @@ fn a_library_of_shaders_reports_what_its_driver_found() { assert_eq!(saves, 0, "libraries found in their records write nothing"); } } + +/// The runtime's own kernels made again on a later device report what their driver found, and +/// those it reports found in the records an earlier device over the same directory wrote write no +/// record again (`driver_saves`), whatever bytes the driver's data holds after them: RADV's +/// differs from the record's now and then (`shader_cache/driver.rs`), which a byte comparison +/// took for new data and wrote the record again at the device's every making of them. +#[test] +fn the_runtime_s_own_kernels_found_in_their_records_write_nothing() { + let scratch = Scratch::new("driver-own-kernels"); + let kernels = [OwnedModule::RowsCopy, OwnedModule::VisibilityCombine]; + { + let device = device(&scratch.0); + let reports = device.shared().shader_cache.driver_reports(); + if !reports { + println!("DRIVER-OWN-KERNELS: not covered (the device's makings report nothing)"); + return; + } + for which in kernels { + device.owned_kernel(which).unwrap(); + } + } + // The first device is gone, so its cache thread wrote what its makings handed it. + let device = device(&scratch.0); + let before = device.shader_cache_statistics(); + let counts_before = device.work_counts(); + for which in kernels { + device.owned_kernel(which).unwrap(); + } + let after = device.shader_cache_statistics(); + let made = device.work_counts().owned_kernels_made - counts_before.owned_kernels_made; + let since = |of: fn(&crate::ShaderCacheStatistics) -> u64| of(&after) - of(&before); + let (hits, misses) = ( + since(|s| s.driver_pipeline_hits), + since(|s| s.driver_pipeline_misses), + ); + let (found, saves) = (since(|s| s.driver_data_found), since(|s| s.driver_saves)); + println!( + "DRIVER-OWN-KERNELS: {made} kernels made, {hits} hits and {misses} misses reported, \ + {found} found and read nothing back, {saves} records' data written, {} loaded", + since(|s| s.driver_loads) + ); + assert_eq!( + made, + kernels.len() as u64, + "the later device made each kernel" + ); + assert_eq!( + hits + misses, + made, + "each of the runtime's kernels reports what its driver found: {hits} hits and {misses} \ + misses" + ); + assert_eq!( + found, hits, + "each kernel its driver reports found in the cache its record loaded reads no data back" + ); + if hits == made { + assert_eq!(saves, 0, "kernels found in their records write nothing"); + } +}