extensions/amd: Add VK_AMD_shader_info (#773)

This commit is contained in:
Marijn Suijten 2023-07-29 10:51:03 +02:00 committed by GitHub
parent 884ac46e82
commit f558761997
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 89 additions and 0 deletions

View file

@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added `VK_GOOGLE_display_timing` device extension (#765) - Added `VK_GOOGLE_display_timing` device extension (#765)
- Added `VK_ANDROID_external_memory_android_hardware_buffer` device extension (#769) - Added `VK_ANDROID_external_memory_android_hardware_buffer` device extension (#769)
- Added `VK_AMD_buffer_marker` device extension (#772) - Added `VK_AMD_buffer_marker` device extension (#772)
- Added `VK_AMD_shader_info` device extension (#773)
### Changed ### Changed

View file

@ -1,3 +1,5 @@
pub use self::buffer_marker::BufferMarker; pub use self::buffer_marker::BufferMarker;
pub use self::shader_info::{ShaderInfo, ShaderInfoResult};
mod buffer_marker; mod buffer_marker;
mod shader_info;

View file

@ -0,0 +1,86 @@
use crate::prelude::*;
use crate::vk;
use crate::{Device, Instance};
use std::ffi::CStr;
use std::mem;
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_AMD_shader_info.html>
#[derive(Clone)]
pub struct ShaderInfo {
handle: vk::Device,
fp: vk::AmdShaderInfoFn,
}
impl ShaderInfo {
pub fn new(instance: &Instance, device: &Device) -> Self {
let handle = device.handle();
let fp = vk::AmdShaderInfoFn::load(|name| unsafe {
mem::transmute(instance.get_device_proc_addr(handle, name.as_ptr()))
});
Self { handle, fp }
}
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkGetShaderInfoAMD.html>
#[inline]
pub unsafe fn get_shader_info(
&self,
pipeline: vk::Pipeline,
shader_stage: vk::ShaderStageFlags,
info_type: vk::ShaderInfoTypeAMD,
) -> VkResult<ShaderInfoResult> {
let load_data = |count: &mut usize, data: *mut u8| {
(self.fp.get_shader_info_amd)(
self.handle,
pipeline,
shader_stage,
info_type,
count,
data.cast(),
)
};
match info_type {
vk::ShaderInfoTypeAMD::STATISTICS => {
let mut statistics_info = mem::MaybeUninit::<vk::ShaderStatisticsInfoAMD>::uninit();
load_data(
&mut std::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),
}
}
pub const NAME: &'static CStr = vk::AmdShaderInfoFn::NAME;
#[inline]
pub fn fp(&self) -> &vk::AmdShaderInfoFn {
&self.fp
}
#[inline]
pub fn device(&self) -> vk::Device {
self.handle
}
}
#[derive(Clone)]
#[cfg_attr(feature = "debug", derive(Debug))]
pub enum ShaderInfoResult {
StatisticsInfo(vk::ShaderStatisticsInfoAMD),
Binary(Vec<u8>),
Disassembly(Vec<u8>),
}