Compute PSO creation refactor

This commit is contained in:
Dzmitry Malyshau 2018-06-05 13:42:34 -04:00
parent 6e0ce965bf
commit f89c417b89

View file

@ -594,16 +594,15 @@ pub extern "C" fn gfxCreateDevice(
#[inline] #[inline]
pub extern "C" fn gfxDestroyDevice(gpu: VkDevice, _pAllocator: *const VkAllocationCallbacks) { pub extern "C" fn gfxDestroyDevice(gpu: VkDevice, _pAllocator: *const VkAllocationCallbacks) {
// release all the owned command queues // release all the owned command queues
if let Some(d) = gpu.unbox() { if let Some(mut d) = gpu.unbox() {
#[cfg(feature = "renderdoc")] #[cfg(feature = "renderdoc")]
{ {
use renderdoc::api::RenderDocV100; use renderdoc::api::RenderDocV100;
let device = gpu.capturing as *mut c_void; let device = gpu.capturing as *mut c_void;
let mut d = d;
d.renderdoc.end_frame_capture(device as *mut _, ptr::null()); d.renderdoc.end_frame_capture(device as *mut _, ptr::null());
} }
for (_, family) in d.queues { for (_, family) in d.queues.drain() {
for queue in family { for queue in family {
let _ = queue.unbox(); let _ = queue.unbox();
} }
@ -1487,7 +1486,7 @@ pub extern "C" fn gfxCreateGraphicsPipelines(
.pSpecializationInfo .pSpecializationInfo
.as_ref() .as_ref()
.map(conv::map_specialization_info) .map(conv::map_specialization_info)
.unwrap_or(vec![]) .unwrap_or_default()
}; };
shader_stages.push(( shader_stages.push((
@ -1866,69 +1865,74 @@ pub extern "C" fn gfxCreateComputePipelines(
slice::from_raw_parts(pCreateInfos, createInfoCount as _) slice::from_raw_parts(pCreateInfos, createInfoCount as _)
}; };
let mut shader_stages = Vec::with_capacity(infos.len());
// Collect all information which we will borrow later. Need to work around // Collect all information which we will borrow later. Need to work around
// the borrow checker here. // the borrow checker here.
// TODO: try to refactor it once we have a more generic API // TODO: try to refactor it once we have a more generic API
for info in infos { let shader_stages = infos
let name = unsafe { CStr::from_ptr(info.stage.pName).to_owned() }; .iter()
let specialization = unsafe { info.stage .map(|info| {
.pSpecializationInfo let name = unsafe { CStr::from_ptr(info.stage.pName).to_owned() };
.as_ref() let specialization = unsafe { info.stage
.map(conv::map_specialization_info) .pSpecializationInfo
.unwrap_or(vec![]) .as_ref()
}; .map(conv::map_specialization_info)
.unwrap_or_default()
};
shader_stages.push(( (
name.into_string().unwrap(), name.into_string().unwrap(),
specialization, specialization,
)); )
} })
.collect::<Vec<_>>();
let descs = infos.into_iter().zip(&shader_stages).map(|(info, &(ref entry, ref specialization))| { let descs = infos
let shader = pso::EntryPoint { .into_iter()
entry, .zip(&shader_stages)
module: &*info.stage.module, .map(|(info, &(ref entry, ref specialization))| {
specialization, let shader = pso::EntryPoint {
}; entry,
let layout = &*info.layout; module: &*info.stage.module,
specialization,
};
let layout = &*info.layout;
let flags = { let flags = {
let mut flags = pso::PipelineCreationFlags::empty(); let mut flags = pso::PipelineCreationFlags::empty();
if info.flags & VkPipelineCreateFlagBits::VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT as u32 != 0 { if info.flags & VkPipelineCreateFlagBits::VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT as u32 != 0 {
flags |= pso::PipelineCreationFlags::DISABLE_OPTIMIZATION; flags |= pso::PipelineCreationFlags::DISABLE_OPTIMIZATION;
} }
if info.flags & VkPipelineCreateFlagBits::VK_PIPELINE_CREATE_ALLOW_DERIVATIVES_BIT as u32 != 0 { if info.flags & VkPipelineCreateFlagBits::VK_PIPELINE_CREATE_ALLOW_DERIVATIVES_BIT as u32 != 0 {
flags |= pso::PipelineCreationFlags::ALLOW_DERIVATIVES; flags |= pso::PipelineCreationFlags::ALLOW_DERIVATIVES;
}
flags
};
let parent = {
let is_derivative = info.flags & VkPipelineCreateFlagBits::VK_PIPELINE_CREATE_DERIVATIVE_BIT as u32 != 0;
if let Some(base_pso) = info.basePipelineHandle.as_ref() {
match *base_pso {
Pipeline::Graphics(_) => panic!("Base pipeline handle must be a compute pipeline"),
Pipeline::Compute(ref pso) => pso::BasePipeline::Pipeline(pso),
} }
} else if is_derivative && info.basePipelineIndex > 0 {
pso::BasePipeline::Index(info.basePipelineIndex as _)
} else {
pso::BasePipeline::None // TODO
}
};
pso::ComputePipelineDesc { flags
shader, };
layout,
flags, let parent = {
parent, let is_derivative = info.flags & VkPipelineCreateFlagBits::VK_PIPELINE_CREATE_DERIVATIVE_BIT as u32 != 0;
}
}).collect::<Vec<_>>(); if let Some(base_pso) = info.basePipelineHandle.as_ref() {
match *base_pso {
Pipeline::Graphics(_) => panic!("Base pipeline handle must be a compute pipeline"),
Pipeline::Compute(ref pso) => pso::BasePipeline::Pipeline(pso),
}
} else if is_derivative && info.basePipelineIndex > 0 {
pso::BasePipeline::Index(info.basePipelineIndex as _)
} else {
pso::BasePipeline::None // TODO
}
};
pso::ComputePipelineDesc {
shader,
layout,
flags,
parent,
}
})
.collect::<Vec<_>>();
let pipelines = gpu.device.create_compute_pipelines(&descs); let pipelines = gpu.device.create_compute_pipelines(&descs);