Skip to content

Commit

Permalink
Replace builders with lifetimes/setters directly on Vulkan structs (#602
Browse files Browse the repository at this point in the history
)

* Replace builders with lifetimes/setters directly on Vulkan structs

* Inline setters
  • Loading branch information
Ralith authored Mar 29, 2022
1 parent e43e9c0 commit 71bb3d3
Show file tree
Hide file tree
Showing 14 changed files with 10,186 additions and 29,693 deletions.
4 changes: 2 additions & 2 deletions ash-window/examples/winit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ fn main() -> Result<(), Box<dyn Error>> {
unsafe {
let entry = ash::Entry::linked();
let surface_extensions = ash_window::enumerate_required_extensions(&window)?;
let app_desc = vk::ApplicationInfo::builder().api_version(vk::make_api_version(0, 1, 0, 0));
let instance_desc = vk::InstanceCreateInfo::builder()
let app_desc = vk::ApplicationInfo::default().api_version(vk::make_api_version(0, 1, 0, 0));
let instance_desc = vk::InstanceCreateInfo::default()
.application_info(&app_desc)
.enabled_extension_names(surface_extensions);

Expand Down
14 changes: 7 additions & 7 deletions ash-window/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub unsafe fn create_surface(
match window_handle.raw_window_handle() {
#[cfg(target_os = "windows")]
RawWindowHandle::Windows(handle) => {
let surface_desc = vk::Win32SurfaceCreateInfoKHR::builder()
let surface_desc = vk::Win32SurfaceCreateInfoKHR::default()
.hinstance(handle.hinstance)
.hwnd(handle.hwnd);
let surface_fn = khr::Win32Surface::new(entry, instance);
Expand All @@ -41,7 +41,7 @@ pub unsafe fn create_surface(
target_os = "openbsd"
))]
RawWindowHandle::Wayland(handle) => {
let surface_desc = vk::WaylandSurfaceCreateInfoKHR::builder()
let surface_desc = vk::WaylandSurfaceCreateInfoKHR::default()
.display(handle.display)
.surface(handle.surface);
let surface_fn = khr::WaylandSurface::new(entry, instance);
Expand All @@ -56,7 +56,7 @@ pub unsafe fn create_surface(
target_os = "openbsd"
))]
RawWindowHandle::Xlib(handle) => {
let surface_desc = vk::XlibSurfaceCreateInfoKHR::builder()
let surface_desc = vk::XlibSurfaceCreateInfoKHR::default()
.dpy(handle.display as *mut _)
.window(handle.window);
let surface_fn = khr::XlibSurface::new(entry, instance);
Expand All @@ -71,7 +71,7 @@ pub unsafe fn create_surface(
target_os = "openbsd"
))]
RawWindowHandle::Xcb(handle) => {
let surface_desc = vk::XcbSurfaceCreateInfoKHR::builder()
let surface_desc = vk::XcbSurfaceCreateInfoKHR::default()
.connection(handle.connection)
.window(handle.window);
let surface_fn = khr::XcbSurface::new(entry, instance);
Expand All @@ -81,7 +81,7 @@ pub unsafe fn create_surface(
#[cfg(any(target_os = "android"))]
RawWindowHandle::Android(handle) => {
let surface_desc =
vk::AndroidSurfaceCreateInfoKHR::builder().window(handle.a_native_window);
vk::AndroidSurfaceCreateInfoKHR::default().window(handle.a_native_window);
let surface_fn = khr::AndroidSurface::new(entry, instance);
surface_fn.create_android_surface(&surface_desc, allocation_callbacks)
}
Expand All @@ -95,7 +95,7 @@ pub unsafe fn create_surface(
Layer::None => return Err(vk::Result::ERROR_INITIALIZATION_FAILED),
};

let surface_desc = vk::MetalSurfaceCreateInfoEXT::builder().layer(&*layer);
let surface_desc = vk::MetalSurfaceCreateInfoEXT::default().layer(&*layer);
let surface_fn = ext::MetalSurface::new(entry, instance);
surface_fn.create_metal_surface(&surface_desc, allocation_callbacks)
}
Expand All @@ -109,7 +109,7 @@ pub unsafe fn create_surface(
Layer::None => return Err(vk::Result::ERROR_INITIALIZATION_FAILED),
};

let surface_desc = vk::MetalSurfaceCreateInfoEXT::builder().layer(&*layer);
let surface_desc = vk::MetalSurfaceCreateInfoEXT::default().layer(&*layer);
let surface_fn = ext::MetalSurface::new(entry, instance);
surface_fn.create_metal_surface(&surface_desc, allocation_callbacks)
}
Expand Down
2 changes: 1 addition & 1 deletion ash/src/extensions/ext/physical_device_drm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ impl PhysicalDeviceDrm {
) -> vk::PhysicalDeviceDrmPropertiesEXT {
let mut props_drm = vk::PhysicalDeviceDrmPropertiesEXT::default();
{
let mut props = vk::PhysicalDeviceProperties2::builder().push_next(&mut props_drm);
let mut props = vk::PhysicalDeviceProperties2::default().push_next(&mut props_drm);
instance.get_physical_device_properties2(pdevice, &mut props);
}
props_drm
Expand Down
2 changes: 1 addition & 1 deletion ash/src/extensions/khr/acceleration_structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl AccelerationStructure {
) -> vk::PhysicalDeviceAccelerationStructurePropertiesKHR {
let mut props_rt = vk::PhysicalDeviceAccelerationStructurePropertiesKHR::default();
{
let mut props = vk::PhysicalDeviceProperties2::builder().push_next(&mut props_rt);
let mut props = vk::PhysicalDeviceProperties2::default().push_next(&mut props_rt);
instance.get_physical_device_properties2(pdevice, &mut props);
}
props_rt
Expand Down
2 changes: 1 addition & 1 deletion ash/src/extensions/khr/ray_tracing_pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl RayTracingPipeline {
) -> vk::PhysicalDeviceRayTracingPipelinePropertiesKHR {
let mut props_rt = vk::PhysicalDeviceRayTracingPipelinePropertiesKHR::default();
{
let mut props = vk::PhysicalDeviceProperties2::builder().push_next(&mut props_rt);
let mut props = vk::PhysicalDeviceProperties2::default().push_next(&mut props_rt);
instance.get_physical_device_properties2(pdevice, &mut props);
}
props_rt
Expand Down
2 changes: 1 addition & 1 deletion ash/src/extensions/nv/ray_tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl RayTracing {
) -> vk::PhysicalDeviceRayTracingPropertiesNV {
let mut props_rt = vk::PhysicalDeviceRayTracingPropertiesNV::default();
{
let mut props = vk::PhysicalDeviceProperties2::builder().push_next(&mut props_rt);
let mut props = vk::PhysicalDeviceProperties2::default().push_next(&mut props_rt);
instance.get_physical_device_properties2(pdevice, &mut props);
}
props_rt
Expand Down
6 changes: 3 additions & 3 deletions ash/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ mod tests {
use super::vk;
#[test]
fn test_ptr_chains() {
let mut variable_pointers = vk::PhysicalDeviceVariablePointerFeatures::builder();
let mut corner = vk::PhysicalDeviceCornerSampledImageFeaturesNV::builder();
let mut variable_pointers = vk::PhysicalDeviceVariablePointerFeatures::default();
let mut corner = vk::PhysicalDeviceCornerSampledImageFeaturesNV::default();
let chain = vec![
<*mut _>::cast(&mut variable_pointers),
<*mut _>::cast(&mut corner),
];
let mut device_create_info = vk::DeviceCreateInfo::builder()
let mut device_create_info = vk::DeviceCreateInfo::default()
.push_next(&mut corner)
.push_next(&mut variable_pointers);
let chain2: Vec<*mut vk::BaseOutStructure> = unsafe {
Expand Down
Loading

0 comments on commit 71bb3d3

Please sign in to comment.