Add unit test for creating mulitple set from pool
This commit is contained in:
parent
b852dd3cdf
commit
591aba8c12
2 changed files with 119 additions and 1 deletions
|
@ -338,3 +338,73 @@ impl Drop for DescriptorSet {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::prelude::*;
|
||||
use anyhow::Result;
|
||||
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
fn create_vk_handles() -> Result<(Arc<Device>, Arc<Mutex<Queue>>)> {
|
||||
let instance = Instance::new(
|
||||
VkApplicationInfo::new(
|
||||
&VkString::new("Test: image::to_file"),
|
||||
1,
|
||||
&VkString::new("no name"),
|
||||
1,
|
||||
VK_MAKE_VERSION(1, 3, 0),
|
||||
),
|
||||
VulkanDebugInfo::default(),
|
||||
InstanceExtensions::default(),
|
||||
)?;
|
||||
|
||||
let physical_device = PhysicalDevice::new(instance)?;
|
||||
|
||||
let queue_info = Queue::create_non_presentable_request_info(
|
||||
&physical_device,
|
||||
VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_TRANSFER_BIT,
|
||||
)?;
|
||||
|
||||
let device = Device::new(
|
||||
physical_device,
|
||||
DeviceExtensions::default(),
|
||||
&[queue_info.queue_create_info],
|
||||
DeviceFeatures::default(),
|
||||
)?;
|
||||
|
||||
let queue = device.get_queue(queue_info.queue_family_index, queue_info.queue_index);
|
||||
|
||||
Ok((device, queue))
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
fn create_multiple_sets_from_one_pool() -> Result<()> {
|
||||
const DESCRIPTOR_COUNT: u32 = 2;
|
||||
|
||||
let (device, _queue) = create_vk_handles()?;
|
||||
|
||||
let descriptor_layout = DescriptorSetLayout::builder()
|
||||
.add_layout_binding(
|
||||
0,
|
||||
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
||||
VK_SHADER_STAGE_FRAGMENT_BIT,
|
||||
0,
|
||||
)
|
||||
.change_descriptor_count(DESCRIPTOR_COUNT)
|
||||
.build(device.clone())?;
|
||||
|
||||
let descriptor_pool = DescriptorPool::builder()
|
||||
.set_layout(descriptor_layout.clone())
|
||||
.build(device.clone())?;
|
||||
|
||||
let descriptors: Result<Vec<Arc<DescriptorSet>>> = (0..DESCRIPTOR_COUNT)
|
||||
.map(|_| descriptor_pool.prepare_set().allocate())
|
||||
.collect();
|
||||
|
||||
assert!(descriptors.is_ok(), "{}", descriptors.err().unwrap());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,9 +44,57 @@ pub enum VkResult {
|
|||
VK_ERROR_PIPELINE_COMPILE_REQUIRED_EXT = 1_000_297_000,
|
||||
}
|
||||
|
||||
impl VkResult {
|
||||
pub fn as_str(&self) -> &str {
|
||||
match self {
|
||||
VK_SUCCESS => "VK_SUCCESS",
|
||||
VK_NOT_READY => "VK_NOT_READY",
|
||||
VK_TIMEOUT => "VK_TIMEOUT",
|
||||
VK_EVENT_SET => "VK_EVENT_SET",
|
||||
VK_EVENT_RESET => "VK_EVENT_RESET",
|
||||
VK_INCOMPLETE => "VK_INCOMPLETE",
|
||||
VK_ERROR_OUT_OF_HOST_MEMORY => "VK_ERROR_OUT_OF_HOST_MEMORY",
|
||||
VK_ERROR_OUT_OF_DEVICE_MEMORY => "VK_ERROR_OUT_OF_DEVICE_MEMORY",
|
||||
VK_ERROR_INITIALIZATION_FAILED => "VK_ERROR_INITIALIZATION_FAILED",
|
||||
VK_ERROR_DEVICE_LOST => "VK_ERROR_DEVICE_LOST",
|
||||
VK_ERROR_MEMORY_MAP_FAILED => "VK_ERROR_MEMORY_MAP_FAILED",
|
||||
VK_ERROR_LAYER_NOT_PRESENT => "VK_ERROR_LAYER_NOT_PRESENT",
|
||||
VK_ERROR_EXTENSION_NOT_PRESENT => "VK_ERROR_EXTENSION_NOT_PRESENT",
|
||||
VK_ERROR_FEATURE_NOT_PRESENT => "VK_ERROR_FEATURE_NOT_PRESENT",
|
||||
VK_ERROR_INCOMPATIBLE_DRIVER => "VK_ERROR_INCOMPATIBLE_DRIVER",
|
||||
VK_ERROR_TOO_MANY_OBJECTS => "VK_ERROR_TOO_MANY_OBJECTS",
|
||||
VK_ERROR_FORMAT_NOT_SUPPORTED => "VK_ERROR_FORMAT_NOT_SUPPORTED",
|
||||
VK_ERROR_FRAGMENTED_POOL => "VK_ERROR_FRAGMENTED_POOL",
|
||||
VK_ERROR_OUT_OF_POOL_MEMORY => "VK_ERROR_OUT_OF_POOL_MEMORY",
|
||||
VK_ERROR_INVALID_EXTERNAL_HANDLE => "VK_ERROR_INVALID_EXTERNAL_HANDLE",
|
||||
VK_ERROR_SURFACE_LOST_KHR => "VK_ERROR_SURFACE_LOST_KHR",
|
||||
VK_ERROR_NATIVE_WINDOW_IN_USE_KHR => "VK_ERROR_NATIVE_WINDOW_IN_USE_KHR",
|
||||
VK_SUBOPTIMAL_KHR => "VK_SUBOPTIMAL_KHR",
|
||||
VK_ERROR_OUT_OF_DATE_KHR => "VK_ERROR_OUT_OF_DATE_KHR",
|
||||
VK_ERROR_INCOMPATIBLE_DISPLAY_KHR => "VK_ERROR_INCOMPATIBLE_DISPLAY_KHR",
|
||||
VK_ERROR_VALIDATION_FAILED_EXT => "VK_ERROR_VALIDATION_FAILED_EXT",
|
||||
VK_ERROR_INVALID_SHADER_NV => "VK_ERROR_INVALID_SHADER_NV",
|
||||
VK_ERROR_INVALID_DRM_FORMAT_MODIFIER_PLANE_LAYOUT_EXT => {
|
||||
"VK_ERROR_INVALID_DRM_FORMAT_MODIFIER_PLANE_LAYOUT_EXT"
|
||||
}
|
||||
VK_ERROR_FRAGMENTATION_EXT => "VK_ERROR_FRAGMENTATION_EXT",
|
||||
VK_ERROR_NOT_PERMITTED_EXT => "VK_ERROR_NOT_PERMITTED_EXT",
|
||||
VK_ERROR_INVALID_DEVICE_ADDRESS_EXT => "VK_ERROR_INVALID_DEVICE_ADDRESS_EXT",
|
||||
VK_ERROR_FULL_SCREEN_EXCLUSIVE_MODE_LOST_EXT => {
|
||||
"VK_ERROR_FULL_SCREEN_EXCLUSIVE_MODE_LOST_EXT"
|
||||
}
|
||||
VK_THREAD_IDLE_KHR => "VK_THREAD_IDLE_KHR",
|
||||
VK_THREAD_DONE_KHR => "VK_THREAD_DONE_KHR",
|
||||
VK_OPERATION_DEFERRED_KHR => "VK_OPERATION_DEFERRED_KHR",
|
||||
VK_OPERATION_NOT_DEFERRED_KHR => "VK_OPERATION_NOT_DEFERRED_KHR",
|
||||
VK_ERROR_PIPELINE_COMPILE_REQUIRED_EXT => "VK_ERROR_PIPELINE_COMPILE_REQUIRED_EXT",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for VkResult {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
f.write_str("Result from a vulkan api call")
|
||||
write!(f, "Result from a vulkan api call ({})", self.as_str())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue