Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions ash/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1547,7 +1547,10 @@ impl Device {
&self,
allocate_info: &vk::DescriptorSetAllocateInfo<'_>,
) -> VkResult<Vec<vk::DescriptorSet>> {
let mut desc_set = Vec::with_capacity(allocate_info.descriptor_set_count as usize);
let mut desc_set = Vec::new();
desc_set
.try_reserve(allocate_info.descriptor_set_count as usize)
.map_err(|_| vk::Result::ERROR_OUT_OF_HOST_MEMORY)?;
(self.device_fn_1_0.allocate_descriptor_sets)(
self.handle(),
allocate_info,
Expand Down Expand Up @@ -2153,7 +2156,10 @@ impl Device {
create_infos: &[vk::GraphicsPipelineCreateInfo<'_>],
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> Result<Vec<vk::Pipeline>, (Vec<vk::Pipeline>, vk::Result)> {
let mut pipelines = Vec::with_capacity(create_infos.len());
let mut pipelines = Vec::new();
pipelines
.try_reserve(create_infos.len())
.map_err(|_| (Vec::new(), vk::Result::ERROR_OUT_OF_HOST_MEMORY))?;
let err_code = (self.device_fn_1_0.create_graphics_pipelines)(
self.handle(),
pipeline_cache,
Expand Down Expand Up @@ -2181,7 +2187,10 @@ impl Device {
create_infos: &[vk::ComputePipelineCreateInfo<'_>],
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> Result<Vec<vk::Pipeline>, (Vec<vk::Pipeline>, vk::Result)> {
let mut pipelines = Vec::with_capacity(create_infos.len());
let mut pipelines = Vec::new();
pipelines
.try_reserve(create_infos.len())
.map_err(|_| (Vec::new(), vk::Result::ERROR_OUT_OF_HOST_MEMORY))?;
let err_code = (self.device_fn_1_0.create_compute_pipelines)(
self.handle(),
pipeline_cache,
Expand Down Expand Up @@ -2542,7 +2551,10 @@ impl Device {
&self,
allocate_info: &vk::CommandBufferAllocateInfo<'_>,
) -> VkResult<Vec<vk::CommandBuffer>> {
let mut buffers = Vec::with_capacity(allocate_info.command_buffer_count as usize);
let mut buffers = Vec::new();
buffers
.try_reserve(allocate_info.command_buffer_count as usize)
.map_err(|_| vk::Result::ERROR_OUT_OF_HOST_MEMORY)?;
(self.device_fn_1_0.allocate_command_buffers)(
self.handle(),
allocate_info,
Expand Down
5 changes: 4 additions & 1 deletion ash/src/extensions/amdx/shader_enqueue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ impl crate::amdx::shader_enqueue::Device {
create_infos: &[vk::ExecutionGraphPipelineCreateInfoAMDX<'_>],
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> Result<Vec<vk::Pipeline>, (Vec<vk::Pipeline>, vk::Result)> {
let mut pipelines = Vec::with_capacity(create_infos.len());
let mut pipelines = Vec::new();
pipelines
.try_reserve(create_infos.len())
.map_err(|_| (Vec::new(), vk::Result::ERROR_OUT_OF_HOST_MEMORY))?;
let err_code = (self.fp.create_execution_graph_pipelines_amdx)(
self.handle,
pipeline_cache,
Expand Down
5 changes: 4 additions & 1 deletion ash/src/extensions/ext/calibrated_timestamps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ impl crate::ext::calibrated_timestamps::Device {
&self,
info: &[vk::CalibratedTimestampInfoEXT<'_>],
) -> VkResult<(Vec<u64>, u64)> {
let mut timestamps = Vec::with_capacity(info.len());
let mut timestamps = Vec::new();
timestamps
.try_reserve(info.len())
.map_err(|_| vk::Result::ERROR_OUT_OF_HOST_MEMORY)?;
let mut max_deviation = mem::MaybeUninit::uninit();
let max_deviation = (self.fp.get_calibrated_timestamps_ext)(
self.handle,
Expand Down
5 changes: 4 additions & 1 deletion ash/src/extensions/ext/shader_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ impl crate::ext::shader_object::Device {
create_infos: &[vk::ShaderCreateInfoEXT<'_>],
allocator: Option<&vk::AllocationCallbacks<'_>>,
) -> Result<Vec<vk::ShaderEXT>, (Vec<vk::ShaderEXT>, vk::Result)> {
let mut shaders = Vec::with_capacity(create_infos.len());
let mut shaders = Vec::new();
shaders
.try_reserve(create_infos.len())
.map_err(|_| (Vec::new(), vk::Result::ERROR_OUT_OF_HOST_MEMORY))?;
let err_code = (self.fp.create_shaders_ext)(
self.handle,
create_infos.len() as u32,
Expand Down
5 changes: 4 additions & 1 deletion ash/src/extensions/khr/calibrated_timestamps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ impl crate::khr::calibrated_timestamps::Device {
&self,
info: &[vk::CalibratedTimestampInfoKHR<'_>],
) -> VkResult<(Vec<u64>, u64)> {
let mut timestamps = Vec::with_capacity(info.len());
let mut timestamps = Vec::new();
timestamps
.try_reserve(info.len())
.map_err(|_| vk::Result::ERROR_OUT_OF_HOST_MEMORY)?;
let mut max_deviation = mem::MaybeUninit::uninit();
let max_deviation = (self.fp.get_calibrated_timestamps_khr)(
self.handle,
Expand Down
5 changes: 4 additions & 1 deletion ash/src/extensions/khr/display_swapchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ impl crate::khr::display_swapchain::Device {
create_infos: &[vk::SwapchainCreateInfoKHR<'_>],
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> VkResult<Vec<vk::SwapchainKHR>> {
let mut swapchains = Vec::with_capacity(create_infos.len());
let mut swapchains = Vec::new();
swapchains
.try_reserve(create_infos.len())
.map_err(|_| vk::Result::ERROR_OUT_OF_HOST_MEMORY)?;
(self.fp.create_shared_swapchains_khr)(
self.handle,
create_infos.len() as u32,
Expand Down
13 changes: 10 additions & 3 deletions ash/src/extensions/khr/ray_tracing_pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ impl crate::khr::ray_tracing_pipeline::Device {
create_infos: &[vk::RayTracingPipelineCreateInfoKHR<'_>],
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> Result<Vec<vk::Pipeline>, (Vec<vk::Pipeline>, vk::Result)> {
let mut pipelines = Vec::with_capacity(create_infos.len());
let mut pipelines = Vec::new();
pipelines
.try_reserve(create_infos.len())
.map_err(|_| (Vec::new(), vk::Result::ERROR_OUT_OF_HOST_MEMORY))?;
let err_code = (self.fp.create_ray_tracing_pipelines_khr)(
self.handle,
deferred_operation,
Expand All @@ -70,7 +73,9 @@ impl crate::khr::ray_tracing_pipeline::Device {
group_count: u32,
data_size: usize,
) -> VkResult<Vec<u8>> {
let mut data = Vec::<u8>::with_capacity(data_size);
let mut data = Vec::<u8>::new();
data.try_reserve(data_size)
.map_err(|_| vk::Result::ERROR_OUT_OF_HOST_MEMORY)?;
(self.fp.get_ray_tracing_shader_group_handles_khr)(
self.handle,
pipeline,
Expand All @@ -91,7 +96,9 @@ impl crate::khr::ray_tracing_pipeline::Device {
group_count: u32,
data_size: usize,
) -> VkResult<Vec<u8>> {
let mut data = Vec::<u8>::with_capacity(data_size);
let mut data = Vec::<u8>::new();
data.try_reserve(data_size)
.map_err(|_| vk::Result::ERROR_OUT_OF_HOST_MEMORY)?;
(self
.fp
.get_ray_tracing_capture_replay_shader_group_handles_khr)(
Expand Down
5 changes: 4 additions & 1 deletion ash/src/extensions/nv/ray_tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,10 @@ impl crate::nv::ray_tracing::Device {
create_infos: &[vk::RayTracingPipelineCreateInfoNV<'_>],
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> Result<Vec<vk::Pipeline>, (Vec<vk::Pipeline>, vk::Result)> {
let mut pipelines = Vec::with_capacity(create_infos.len());
let mut pipelines = Vec::new();
pipelines
.try_reserve(create_infos.len())
.map_err(|_| (Vec::new(), vk::Result::ERROR_OUT_OF_HOST_MEMORY))?;
let err_code = (self.fp.create_ray_tracing_pipelines_nv)(
self.handle,
pipeline_cache,
Expand Down
12 changes: 9 additions & 3 deletions ash/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ where
loop {
let mut count = N::default();
f(&mut count, ptr::null_mut()).result()?;
let mut data =
Vec::with_capacity(count.try_into().expect("`N` failed to convert to `usize`"));
let mut data = Vec::new();
data.try_reserve(count.try_into().expect("`N` failed to convert to `usize`"))
.map_err(|_| vk::Result::ERROR_OUT_OF_HOST_MEMORY)?;

let err_code = f(&mut count, data.as_mut_ptr());
if err_code != vk::Result::INCOMPLETE {
Expand Down Expand Up @@ -89,7 +90,12 @@ where
loop {
let mut count = N::default();
f(&mut count, ptr::null_mut()).result()?;
let mut data = alloc::vec![Default::default(); count.try_into().expect("`N` failed to convert to `usize`")];

let count_usize: usize = count.try_into().expect("`N` failed to convert to `usize`");
let mut data = Vec::<T>::new();
data.try_reserve(count_usize)
.map_err(|_| vk::Result::ERROR_OUT_OF_HOST_MEMORY)?;
data.resize_with(count_usize, Default::default);

let err_code = f(&mut count, data.as_mut_ptr());
if err_code != vk::Result::INCOMPLETE {
Expand Down