use crate::runtime::Instance;
pub(super) enum SyncCommands {
Core,
Khr(ash::khr::synchronization2::Device),
}
pub(super) enum RenderingCommands {
Core,
Khr(ash::khr::dynamic_rendering::Device),
}
impl RenderingCommands {
pub(super) fn new(instance: &Instance, device: &ash::Device, api_version: u32) -> Self {
if api_version >= ash::vk::API_VERSION_1_3 {
Self::Core
} else {
Self::Khr(ash::khr::dynamic_rendering::Device::new(
instance.raw(),
device,
))
}
}
pub(super) unsafe fn begin(
&self,
device: &ash::Device,
command: ash::vk::CommandBuffer,
info: &ash::vk::RenderingInfo<'_>,
) {
unsafe {
match self {
Self::Core => device.cmd_begin_rendering(command, info),
Self::Khr(khr) => khr.cmd_begin_rendering(command, info),
}
}
}
pub(super) unsafe fn end(&self, device: &ash::Device, command: ash::vk::CommandBuffer) {
unsafe {
match self {
Self::Core => device.cmd_end_rendering(command),
Self::Khr(khr) => khr.cmd_end_rendering(command),
}
}
}
}
impl SyncCommands {
pub(super) fn new(instance: &Instance, device: &ash::Device, api_version: u32) -> Self {
if api_version >= ash::vk::API_VERSION_1_3 {
Self::Core
} else {
Self::Khr(ash::khr::synchronization2::Device::new(
instance.raw(),
device,
))
}
}
pub(super) unsafe fn pipeline_barrier(
&self,
device: &ash::Device,
command: ash::vk::CommandBuffer,
dependency: &ash::vk::DependencyInfo<'_>,
) {
unsafe {
match self {
Self::Core => device.cmd_pipeline_barrier2(command, dependency),
Self::Khr(khr) => khr.cmd_pipeline_barrier2(command, dependency),
}
}
}
pub(super) unsafe fn submit(
&self,
device: &ash::Device,
queue: ash::vk::Queue,
submits: &[ash::vk::SubmitInfo2<'_>],
fence: ash::vk::Fence,
) -> std::result::Result<(), ash::vk::Result> {
unsafe {
match self {
Self::Core => device.queue_submit2(queue, submits, fence),
Self::Khr(khr) => khr.queue_submit2(queue, submits, fence),
}
}
}
pub(super) unsafe fn write_timestamp(
&self,
device: &ash::Device,
command: ash::vk::CommandBuffer,
stage: ash::vk::PipelineStageFlags2,
pool: ash::vk::QueryPool,
query: u32,
) {
unsafe {
match self {
Self::Core => device.cmd_write_timestamp2(command, stage, pool, query),
Self::Khr(khr) => khr.cmd_write_timestamp2(command, stage, pool, query),
}
}
}
}
#[cfg(test)]
#[path = "../../../../test/rs/runtime/commands_unit.rs"]
mod tests;