diff --git a/ash/src/extensions/amd/shader_info.rs b/ash/src/extensions/amd/shader_info.rs index 800f40f8b..52cc801cc 100644 --- a/ash/src/extensions/amd/shader_info.rs +++ b/ash/src/extensions/amd/shader_info.rs @@ -6,55 +6,63 @@ use alloc::vec::Vec; use core::mem; impl crate::amd::shader_info::Device { - /// + /// with [`vk::ShaderInfoTypeAMD::STATISTICS`] #[inline] - pub unsafe fn get_shader_info( + pub unsafe fn get_shader_info_statistics( &self, pipeline: vk::Pipeline, shader_stage: vk::ShaderStageFlags, - info_type: vk::ShaderInfoTypeAMD, - ) -> VkResult { - let load_data = |count: &mut usize, data: *mut u8| { + ) -> VkResult { + let mut info = mem::MaybeUninit::::uninit(); + let mut size = mem::size_of_val(&info); + (self.fp.get_shader_info_amd)( + self.handle, + pipeline, + shader_stage, + vk::ShaderInfoTypeAMD::STATISTICS, + &mut size, + info.as_mut_ptr().cast(), + ) + .result()?; + assert_eq!(size, mem::size_of_val(&info)); + Ok(info.assume_init()) + } + + /// with [`vk::ShaderInfoTypeAMD::BINARY`] + #[inline] + pub unsafe fn get_shader_info_binary( + &self, + pipeline: vk::Pipeline, + shader_stage: vk::ShaderStageFlags, + ) -> VkResult> { + read_into_uninitialized_vector(|count, data: *mut u8| { (self.fp.get_shader_info_amd)( self.handle, pipeline, shader_stage, - info_type, + vk::ShaderInfoTypeAMD::BINARY, count, data.cast(), ) - }; - - match info_type { - vk::ShaderInfoTypeAMD::STATISTICS => { - let mut statistics_info = mem::MaybeUninit::::uninit(); - load_data( - &mut mem::size_of_val(&statistics_info), - statistics_info.as_mut_ptr().cast(), - ) - .result()?; - Ok(ShaderInfoResult::StatisticsInfo( - statistics_info.assume_init(), - )) - } - vk::ShaderInfoTypeAMD::BINARY => { - read_into_uninitialized_vector(load_data).map(ShaderInfoResult::Binary) - } - vk::ShaderInfoTypeAMD::DISASSEMBLY => { - read_into_uninitialized_vector(load_data).map(ShaderInfoResult::Disassembly) - } - #[cfg(feature = "debug")] - x => unimplemented!("ShaderInfoTypeAMD {:?}", x), - #[cfg(not(feature = "debug"))] - x => unimplemented!("ShaderInfoTypeAMD {}", x.0), - } + }) } -} -#[derive(Clone)] -#[cfg_attr(feature = "debug", derive(Debug))] -pub enum ShaderInfoResult { - StatisticsInfo(vk::ShaderStatisticsInfoAMD), - Binary(Vec), - Disassembly(Vec), + /// with [`vk::ShaderInfoTypeAMD::DISASSEMBLY`] + #[inline] + pub unsafe fn get_shader_info_disassembly( + &self, + pipeline: vk::Pipeline, + shader_stage: vk::ShaderStageFlags, + ) -> VkResult> { + read_into_uninitialized_vector(|count, data: *mut u8| { + (self.fp.get_shader_info_amd)( + self.handle, + pipeline, + shader_stage, + vk::ShaderInfoTypeAMD::DISASSEMBLY, + count, + data.cast(), + ) + }) + } }