Replace builders with lifetimes/setters directly on Vulkan structs (#602)

* Replace builders with lifetimes/setters directly on Vulkan structs

* Inline setters
This commit is contained in:
Benjamin Saunders 2022-03-29 10:15:14 -07:00 committed by GitHub
parent e43e9c0c9b
commit 71bb3d337c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 10112 additions and 29619 deletions

View file

@ -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);

View file

@ -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);
@ -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);
@ -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);
@ -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);
@ -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)
}
@ -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)
}
@ -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)
}

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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 {

View file

@ -45,198 +45,216 @@ pub type ChromaLocationKHR = ChromaLocation;
pub type SamplerReductionModeEXT = SamplerReductionMode;
pub type ShaderFloatControlsIndependenceKHR = ShaderFloatControlsIndependence;
pub type DriverIdKHR = DriverId;
pub type DevicePrivateDataCreateInfoEXT = DevicePrivateDataCreateInfo;
pub type PrivateDataSlotCreateInfoEXT = PrivateDataSlotCreateInfo;
pub type PhysicalDevicePrivateDataFeaturesEXT = PhysicalDevicePrivateDataFeatures;
pub type PhysicalDeviceFeatures2KHR = PhysicalDeviceFeatures2;
pub type PhysicalDeviceProperties2KHR = PhysicalDeviceProperties2;
pub type FormatProperties2KHR = FormatProperties2;
pub type ImageFormatProperties2KHR = ImageFormatProperties2;
pub type PhysicalDeviceImageFormatInfo2KHR = PhysicalDeviceImageFormatInfo2;
pub type QueueFamilyProperties2KHR = QueueFamilyProperties2;
pub type PhysicalDeviceMemoryProperties2KHR = PhysicalDeviceMemoryProperties2;
pub type SparseImageFormatProperties2KHR = SparseImageFormatProperties2;
pub type PhysicalDeviceSparseImageFormatInfo2KHR = PhysicalDeviceSparseImageFormatInfo2;
pub type DevicePrivateDataCreateInfoEXT<'a> = DevicePrivateDataCreateInfo<'a>;
pub type PrivateDataSlotCreateInfoEXT<'a> = PrivateDataSlotCreateInfo<'a>;
pub type PhysicalDevicePrivateDataFeaturesEXT<'a> = PhysicalDevicePrivateDataFeatures<'a>;
pub type PhysicalDeviceFeatures2KHR<'a> = PhysicalDeviceFeatures2<'a>;
pub type PhysicalDeviceProperties2KHR<'a> = PhysicalDeviceProperties2<'a>;
pub type FormatProperties2KHR<'a> = FormatProperties2<'a>;
pub type ImageFormatProperties2KHR<'a> = ImageFormatProperties2<'a>;
pub type PhysicalDeviceImageFormatInfo2KHR<'a> = PhysicalDeviceImageFormatInfo2<'a>;
pub type QueueFamilyProperties2KHR<'a> = QueueFamilyProperties2<'a>;
pub type PhysicalDeviceMemoryProperties2KHR<'a> = PhysicalDeviceMemoryProperties2<'a>;
pub type SparseImageFormatProperties2KHR<'a> = SparseImageFormatProperties2<'a>;
pub type PhysicalDeviceSparseImageFormatInfo2KHR<'a> = PhysicalDeviceSparseImageFormatInfo2<'a>;
pub type ConformanceVersionKHR = ConformanceVersion;
pub type PhysicalDeviceDriverPropertiesKHR = PhysicalDeviceDriverProperties;
pub type PhysicalDeviceVariablePointersFeaturesKHR = PhysicalDeviceVariablePointersFeatures;
pub type PhysicalDeviceVariablePointerFeaturesKHR = PhysicalDeviceVariablePointersFeatures;
pub type PhysicalDeviceVariablePointerFeatures = PhysicalDeviceVariablePointersFeatures;
pub type PhysicalDeviceDriverPropertiesKHR<'a> = PhysicalDeviceDriverProperties<'a>;
pub type PhysicalDeviceVariablePointersFeaturesKHR<'a> = PhysicalDeviceVariablePointersFeatures<'a>;
pub type PhysicalDeviceVariablePointerFeaturesKHR<'a> = PhysicalDeviceVariablePointersFeatures<'a>;
pub type PhysicalDeviceVariablePointerFeatures<'a> = PhysicalDeviceVariablePointersFeatures<'a>;
pub type ExternalMemoryPropertiesKHR = ExternalMemoryProperties;
pub type PhysicalDeviceExternalImageFormatInfoKHR = PhysicalDeviceExternalImageFormatInfo;
pub type ExternalImageFormatPropertiesKHR = ExternalImageFormatProperties;
pub type PhysicalDeviceExternalBufferInfoKHR = PhysicalDeviceExternalBufferInfo;
pub type ExternalBufferPropertiesKHR = ExternalBufferProperties;
pub type PhysicalDeviceIDPropertiesKHR = PhysicalDeviceIDProperties;
pub type ExternalMemoryImageCreateInfoKHR = ExternalMemoryImageCreateInfo;
pub type ExternalMemoryBufferCreateInfoKHR = ExternalMemoryBufferCreateInfo;
pub type ExportMemoryAllocateInfoKHR = ExportMemoryAllocateInfo;
pub type PhysicalDeviceExternalSemaphoreInfoKHR = PhysicalDeviceExternalSemaphoreInfo;
pub type ExternalSemaphorePropertiesKHR = ExternalSemaphoreProperties;
pub type ExportSemaphoreCreateInfoKHR = ExportSemaphoreCreateInfo;
pub type PhysicalDeviceExternalFenceInfoKHR = PhysicalDeviceExternalFenceInfo;
pub type ExternalFencePropertiesKHR = ExternalFenceProperties;
pub type ExportFenceCreateInfoKHR = ExportFenceCreateInfo;
pub type PhysicalDeviceMultiviewFeaturesKHR = PhysicalDeviceMultiviewFeatures;
pub type PhysicalDeviceMultiviewPropertiesKHR = PhysicalDeviceMultiviewProperties;
pub type RenderPassMultiviewCreateInfoKHR = RenderPassMultiviewCreateInfo;
pub type PhysicalDeviceGroupPropertiesKHR = PhysicalDeviceGroupProperties;
pub type MemoryAllocateFlagsInfoKHR = MemoryAllocateFlagsInfo;
pub type BindBufferMemoryInfoKHR = BindBufferMemoryInfo;
pub type BindBufferMemoryDeviceGroupInfoKHR = BindBufferMemoryDeviceGroupInfo;
pub type BindImageMemoryInfoKHR = BindImageMemoryInfo;
pub type BindImageMemoryDeviceGroupInfoKHR = BindImageMemoryDeviceGroupInfo;
pub type DeviceGroupRenderPassBeginInfoKHR = DeviceGroupRenderPassBeginInfo;
pub type DeviceGroupCommandBufferBeginInfoKHR = DeviceGroupCommandBufferBeginInfo;
pub type DeviceGroupSubmitInfoKHR = DeviceGroupSubmitInfo;
pub type DeviceGroupBindSparseInfoKHR = DeviceGroupBindSparseInfo;
pub type DeviceGroupDeviceCreateInfoKHR = DeviceGroupDeviceCreateInfo;
pub type PhysicalDeviceExternalImageFormatInfoKHR<'a> = PhysicalDeviceExternalImageFormatInfo<'a>;
pub type ExternalImageFormatPropertiesKHR<'a> = ExternalImageFormatProperties<'a>;
pub type PhysicalDeviceExternalBufferInfoKHR<'a> = PhysicalDeviceExternalBufferInfo<'a>;
pub type ExternalBufferPropertiesKHR<'a> = ExternalBufferProperties<'a>;
pub type PhysicalDeviceIDPropertiesKHR<'a> = PhysicalDeviceIDProperties<'a>;
pub type ExternalMemoryImageCreateInfoKHR<'a> = ExternalMemoryImageCreateInfo<'a>;
pub type ExternalMemoryBufferCreateInfoKHR<'a> = ExternalMemoryBufferCreateInfo<'a>;
pub type ExportMemoryAllocateInfoKHR<'a> = ExportMemoryAllocateInfo<'a>;
pub type PhysicalDeviceExternalSemaphoreInfoKHR<'a> = PhysicalDeviceExternalSemaphoreInfo<'a>;
pub type ExternalSemaphorePropertiesKHR<'a> = ExternalSemaphoreProperties<'a>;
pub type ExportSemaphoreCreateInfoKHR<'a> = ExportSemaphoreCreateInfo<'a>;
pub type PhysicalDeviceExternalFenceInfoKHR<'a> = PhysicalDeviceExternalFenceInfo<'a>;
pub type ExternalFencePropertiesKHR<'a> = ExternalFenceProperties<'a>;
pub type ExportFenceCreateInfoKHR<'a> = ExportFenceCreateInfo<'a>;
pub type PhysicalDeviceMultiviewFeaturesKHR<'a> = PhysicalDeviceMultiviewFeatures<'a>;
pub type PhysicalDeviceMultiviewPropertiesKHR<'a> = PhysicalDeviceMultiviewProperties<'a>;
pub type RenderPassMultiviewCreateInfoKHR<'a> = RenderPassMultiviewCreateInfo<'a>;
pub type PhysicalDeviceGroupPropertiesKHR<'a> = PhysicalDeviceGroupProperties<'a>;
pub type MemoryAllocateFlagsInfoKHR<'a> = MemoryAllocateFlagsInfo<'a>;
pub type BindBufferMemoryInfoKHR<'a> = BindBufferMemoryInfo<'a>;
pub type BindBufferMemoryDeviceGroupInfoKHR<'a> = BindBufferMemoryDeviceGroupInfo<'a>;
pub type BindImageMemoryInfoKHR<'a> = BindImageMemoryInfo<'a>;
pub type BindImageMemoryDeviceGroupInfoKHR<'a> = BindImageMemoryDeviceGroupInfo<'a>;
pub type DeviceGroupRenderPassBeginInfoKHR<'a> = DeviceGroupRenderPassBeginInfo<'a>;
pub type DeviceGroupCommandBufferBeginInfoKHR<'a> = DeviceGroupCommandBufferBeginInfo<'a>;
pub type DeviceGroupSubmitInfoKHR<'a> = DeviceGroupSubmitInfo<'a>;
pub type DeviceGroupBindSparseInfoKHR<'a> = DeviceGroupBindSparseInfo<'a>;
pub type DeviceGroupDeviceCreateInfoKHR<'a> = DeviceGroupDeviceCreateInfo<'a>;
pub type DescriptorUpdateTemplateEntryKHR = DescriptorUpdateTemplateEntry;
pub type DescriptorUpdateTemplateCreateInfoKHR = DescriptorUpdateTemplateCreateInfo;
pub type DescriptorUpdateTemplateCreateInfoKHR<'a> = DescriptorUpdateTemplateCreateInfo<'a>;
pub type InputAttachmentAspectReferenceKHR = InputAttachmentAspectReference;
pub type RenderPassInputAttachmentAspectCreateInfoKHR = RenderPassInputAttachmentAspectCreateInfo;
pub type PhysicalDevice16BitStorageFeaturesKHR = PhysicalDevice16BitStorageFeatures;
pub type PhysicalDeviceShaderSubgroupExtendedTypesFeaturesKHR =
PhysicalDeviceShaderSubgroupExtendedTypesFeatures;
pub type BufferMemoryRequirementsInfo2KHR = BufferMemoryRequirementsInfo2;
pub type DeviceBufferMemoryRequirementsKHR = DeviceBufferMemoryRequirements;
pub type ImageMemoryRequirementsInfo2KHR = ImageMemoryRequirementsInfo2;
pub type ImageSparseMemoryRequirementsInfo2KHR = ImageSparseMemoryRequirementsInfo2;
pub type DeviceImageMemoryRequirementsKHR = DeviceImageMemoryRequirements;
pub type MemoryRequirements2KHR = MemoryRequirements2;
pub type SparseImageMemoryRequirements2KHR = SparseImageMemoryRequirements2;
pub type PhysicalDevicePointClippingPropertiesKHR = PhysicalDevicePointClippingProperties;
pub type MemoryDedicatedRequirementsKHR = MemoryDedicatedRequirements;
pub type MemoryDedicatedAllocateInfoKHR = MemoryDedicatedAllocateInfo;
pub type ImageViewUsageCreateInfoKHR = ImageViewUsageCreateInfo;
pub type PipelineTessellationDomainOriginStateCreateInfoKHR =
PipelineTessellationDomainOriginStateCreateInfo;
pub type SamplerYcbcrConversionInfoKHR = SamplerYcbcrConversionInfo;
pub type SamplerYcbcrConversionCreateInfoKHR = SamplerYcbcrConversionCreateInfo;
pub type BindImagePlaneMemoryInfoKHR = BindImagePlaneMemoryInfo;
pub type ImagePlaneMemoryRequirementsInfoKHR = ImagePlaneMemoryRequirementsInfo;
pub type PhysicalDeviceSamplerYcbcrConversionFeaturesKHR =
PhysicalDeviceSamplerYcbcrConversionFeatures;
pub type SamplerYcbcrConversionImageFormatPropertiesKHR =
SamplerYcbcrConversionImageFormatProperties;
pub type PhysicalDeviceSamplerFilterMinmaxPropertiesEXT =
PhysicalDeviceSamplerFilterMinmaxProperties;
pub type SamplerReductionModeCreateInfoEXT = SamplerReductionModeCreateInfo;
pub type PhysicalDeviceInlineUniformBlockFeaturesEXT = PhysicalDeviceInlineUniformBlockFeatures;
pub type PhysicalDeviceInlineUniformBlockPropertiesEXT = PhysicalDeviceInlineUniformBlockProperties;
pub type WriteDescriptorSetInlineUniformBlockEXT = WriteDescriptorSetInlineUniformBlock;
pub type DescriptorPoolInlineUniformBlockCreateInfoEXT = DescriptorPoolInlineUniformBlockCreateInfo;
pub type ImageFormatListCreateInfoKHR = ImageFormatListCreateInfo;
pub type PhysicalDeviceMaintenance3PropertiesKHR = PhysicalDeviceMaintenance3Properties;
pub type PhysicalDeviceMaintenance4FeaturesKHR = PhysicalDeviceMaintenance4Features;
pub type PhysicalDeviceMaintenance4PropertiesKHR = PhysicalDeviceMaintenance4Properties;
pub type DescriptorSetLayoutSupportKHR = DescriptorSetLayoutSupport;
pub type PhysicalDeviceShaderDrawParameterFeatures = PhysicalDeviceShaderDrawParametersFeatures;
pub type PhysicalDeviceShaderFloat16Int8FeaturesKHR = PhysicalDeviceShaderFloat16Int8Features;
pub type PhysicalDeviceFloat16Int8FeaturesKHR = PhysicalDeviceShaderFloat16Int8Features;
pub type PhysicalDeviceFloatControlsPropertiesKHR = PhysicalDeviceFloatControlsProperties;
pub type PhysicalDeviceHostQueryResetFeaturesEXT = PhysicalDeviceHostQueryResetFeatures;
pub type DeviceQueueGlobalPriorityCreateInfoEXT = DeviceQueueGlobalPriorityCreateInfoKHR;
pub type PhysicalDeviceGlobalPriorityQueryFeaturesEXT =
PhysicalDeviceGlobalPriorityQueryFeaturesKHR;
pub type QueueFamilyGlobalPriorityPropertiesEXT = QueueFamilyGlobalPriorityPropertiesKHR;
pub type PhysicalDeviceDescriptorIndexingFeaturesEXT = PhysicalDeviceDescriptorIndexingFeatures;
pub type PhysicalDeviceDescriptorIndexingPropertiesEXT = PhysicalDeviceDescriptorIndexingProperties;
pub type DescriptorSetLayoutBindingFlagsCreateInfoEXT = DescriptorSetLayoutBindingFlagsCreateInfo;
pub type DescriptorSetVariableDescriptorCountAllocateInfoEXT =
DescriptorSetVariableDescriptorCountAllocateInfo;
pub type DescriptorSetVariableDescriptorCountLayoutSupportEXT =
DescriptorSetVariableDescriptorCountLayoutSupport;
pub type AttachmentDescription2KHR = AttachmentDescription2;
pub type AttachmentReference2KHR = AttachmentReference2;
pub type SubpassDescription2KHR = SubpassDescription2;
pub type SubpassDependency2KHR = SubpassDependency2;
pub type RenderPassCreateInfo2KHR = RenderPassCreateInfo2;
pub type SubpassBeginInfoKHR = SubpassBeginInfo;
pub type SubpassEndInfoKHR = SubpassEndInfo;
pub type PhysicalDeviceTimelineSemaphoreFeaturesKHR = PhysicalDeviceTimelineSemaphoreFeatures;
pub type PhysicalDeviceTimelineSemaphorePropertiesKHR = PhysicalDeviceTimelineSemaphoreProperties;
pub type SemaphoreTypeCreateInfoKHR = SemaphoreTypeCreateInfo;
pub type TimelineSemaphoreSubmitInfoKHR = TimelineSemaphoreSubmitInfo;
pub type SemaphoreWaitInfoKHR = SemaphoreWaitInfo;
pub type SemaphoreSignalInfoKHR = SemaphoreSignalInfo;
pub type PhysicalDevice8BitStorageFeaturesKHR = PhysicalDevice8BitStorageFeatures;
pub type PhysicalDeviceVulkanMemoryModelFeaturesKHR = PhysicalDeviceVulkanMemoryModelFeatures;
pub type PhysicalDeviceShaderAtomicInt64FeaturesKHR = PhysicalDeviceShaderAtomicInt64Features;
pub type PhysicalDeviceDepthStencilResolvePropertiesKHR =
PhysicalDeviceDepthStencilResolveProperties;
pub type SubpassDescriptionDepthStencilResolveKHR = SubpassDescriptionDepthStencilResolve;
pub type ImageStencilUsageCreateInfoEXT = ImageStencilUsageCreateInfo;
pub type PhysicalDeviceScalarBlockLayoutFeaturesEXT = PhysicalDeviceScalarBlockLayoutFeatures;
pub type PhysicalDeviceUniformBufferStandardLayoutFeaturesKHR =
PhysicalDeviceUniformBufferStandardLayoutFeatures;
pub type PhysicalDeviceBufferDeviceAddressFeaturesKHR = PhysicalDeviceBufferDeviceAddressFeatures;
pub type PhysicalDeviceBufferAddressFeaturesEXT = PhysicalDeviceBufferDeviceAddressFeaturesEXT;
pub type BufferDeviceAddressInfoKHR = BufferDeviceAddressInfo;
pub type BufferDeviceAddressInfoEXT = BufferDeviceAddressInfo;
pub type BufferOpaqueCaptureAddressCreateInfoKHR = BufferOpaqueCaptureAddressCreateInfo;
pub type PhysicalDeviceImagelessFramebufferFeaturesKHR = PhysicalDeviceImagelessFramebufferFeatures;
pub type FramebufferAttachmentsCreateInfoKHR = FramebufferAttachmentsCreateInfo;
pub type FramebufferAttachmentImageInfoKHR = FramebufferAttachmentImageInfo;
pub type RenderPassAttachmentBeginInfoKHR = RenderPassAttachmentBeginInfo;
pub type PhysicalDeviceTextureCompressionASTCHDRFeaturesEXT =
PhysicalDeviceTextureCompressionASTCHDRFeatures;
pub type RenderPassInputAttachmentAspectCreateInfoKHR<'a> =
RenderPassInputAttachmentAspectCreateInfo<'a>;
pub type PhysicalDevice16BitStorageFeaturesKHR<'a> = PhysicalDevice16BitStorageFeatures<'a>;
pub type PhysicalDeviceShaderSubgroupExtendedTypesFeaturesKHR<'a> =
PhysicalDeviceShaderSubgroupExtendedTypesFeatures<'a>;
pub type BufferMemoryRequirementsInfo2KHR<'a> = BufferMemoryRequirementsInfo2<'a>;
pub type DeviceBufferMemoryRequirementsKHR<'a> = DeviceBufferMemoryRequirements<'a>;
pub type ImageMemoryRequirementsInfo2KHR<'a> = ImageMemoryRequirementsInfo2<'a>;
pub type ImageSparseMemoryRequirementsInfo2KHR<'a> = ImageSparseMemoryRequirementsInfo2<'a>;
pub type DeviceImageMemoryRequirementsKHR<'a> = DeviceImageMemoryRequirements<'a>;
pub type MemoryRequirements2KHR<'a> = MemoryRequirements2<'a>;
pub type SparseImageMemoryRequirements2KHR<'a> = SparseImageMemoryRequirements2<'a>;
pub type PhysicalDevicePointClippingPropertiesKHR<'a> = PhysicalDevicePointClippingProperties<'a>;
pub type MemoryDedicatedRequirementsKHR<'a> = MemoryDedicatedRequirements<'a>;
pub type MemoryDedicatedAllocateInfoKHR<'a> = MemoryDedicatedAllocateInfo<'a>;
pub type ImageViewUsageCreateInfoKHR<'a> = ImageViewUsageCreateInfo<'a>;
pub type PipelineTessellationDomainOriginStateCreateInfoKHR<'a> =
PipelineTessellationDomainOriginStateCreateInfo<'a>;
pub type SamplerYcbcrConversionInfoKHR<'a> = SamplerYcbcrConversionInfo<'a>;
pub type SamplerYcbcrConversionCreateInfoKHR<'a> = SamplerYcbcrConversionCreateInfo<'a>;
pub type BindImagePlaneMemoryInfoKHR<'a> = BindImagePlaneMemoryInfo<'a>;
pub type ImagePlaneMemoryRequirementsInfoKHR<'a> = ImagePlaneMemoryRequirementsInfo<'a>;
pub type PhysicalDeviceSamplerYcbcrConversionFeaturesKHR<'a> =
PhysicalDeviceSamplerYcbcrConversionFeatures<'a>;
pub type SamplerYcbcrConversionImageFormatPropertiesKHR<'a> =
SamplerYcbcrConversionImageFormatProperties<'a>;
pub type PhysicalDeviceSamplerFilterMinmaxPropertiesEXT<'a> =
PhysicalDeviceSamplerFilterMinmaxProperties<'a>;
pub type SamplerReductionModeCreateInfoEXT<'a> = SamplerReductionModeCreateInfo<'a>;
pub type PhysicalDeviceInlineUniformBlockFeaturesEXT<'a> =
PhysicalDeviceInlineUniformBlockFeatures<'a>;
pub type PhysicalDeviceInlineUniformBlockPropertiesEXT<'a> =
PhysicalDeviceInlineUniformBlockProperties<'a>;
pub type WriteDescriptorSetInlineUniformBlockEXT<'a> = WriteDescriptorSetInlineUniformBlock<'a>;
pub type DescriptorPoolInlineUniformBlockCreateInfoEXT<'a> =
DescriptorPoolInlineUniformBlockCreateInfo<'a>;
pub type ImageFormatListCreateInfoKHR<'a> = ImageFormatListCreateInfo<'a>;
pub type PhysicalDeviceMaintenance3PropertiesKHR<'a> = PhysicalDeviceMaintenance3Properties<'a>;
pub type PhysicalDeviceMaintenance4FeaturesKHR<'a> = PhysicalDeviceMaintenance4Features<'a>;
pub type PhysicalDeviceMaintenance4PropertiesKHR<'a> = PhysicalDeviceMaintenance4Properties<'a>;
pub type DescriptorSetLayoutSupportKHR<'a> = DescriptorSetLayoutSupport<'a>;
pub type PhysicalDeviceShaderDrawParameterFeatures<'a> =
PhysicalDeviceShaderDrawParametersFeatures<'a>;
pub type PhysicalDeviceShaderFloat16Int8FeaturesKHR<'a> =
PhysicalDeviceShaderFloat16Int8Features<'a>;
pub type PhysicalDeviceFloat16Int8FeaturesKHR<'a> = PhysicalDeviceShaderFloat16Int8Features<'a>;
pub type PhysicalDeviceFloatControlsPropertiesKHR<'a> = PhysicalDeviceFloatControlsProperties<'a>;
pub type PhysicalDeviceHostQueryResetFeaturesEXT<'a> = PhysicalDeviceHostQueryResetFeatures<'a>;
pub type DeviceQueueGlobalPriorityCreateInfoEXT<'a> = DeviceQueueGlobalPriorityCreateInfoKHR<'a>;
pub type PhysicalDeviceGlobalPriorityQueryFeaturesEXT<'a> =
PhysicalDeviceGlobalPriorityQueryFeaturesKHR<'a>;
pub type QueueFamilyGlobalPriorityPropertiesEXT<'a> = QueueFamilyGlobalPriorityPropertiesKHR<'a>;
pub type PhysicalDeviceDescriptorIndexingFeaturesEXT<'a> =
PhysicalDeviceDescriptorIndexingFeatures<'a>;
pub type PhysicalDeviceDescriptorIndexingPropertiesEXT<'a> =
PhysicalDeviceDescriptorIndexingProperties<'a>;
pub type DescriptorSetLayoutBindingFlagsCreateInfoEXT<'a> =
DescriptorSetLayoutBindingFlagsCreateInfo<'a>;
pub type DescriptorSetVariableDescriptorCountAllocateInfoEXT<'a> =
DescriptorSetVariableDescriptorCountAllocateInfo<'a>;
pub type DescriptorSetVariableDescriptorCountLayoutSupportEXT<'a> =
DescriptorSetVariableDescriptorCountLayoutSupport<'a>;
pub type AttachmentDescription2KHR<'a> = AttachmentDescription2<'a>;
pub type AttachmentReference2KHR<'a> = AttachmentReference2<'a>;
pub type SubpassDescription2KHR<'a> = SubpassDescription2<'a>;
pub type SubpassDependency2KHR<'a> = SubpassDependency2<'a>;
pub type RenderPassCreateInfo2KHR<'a> = RenderPassCreateInfo2<'a>;
pub type SubpassBeginInfoKHR<'a> = SubpassBeginInfo<'a>;
pub type SubpassEndInfoKHR<'a> = SubpassEndInfo<'a>;
pub type PhysicalDeviceTimelineSemaphoreFeaturesKHR<'a> =
PhysicalDeviceTimelineSemaphoreFeatures<'a>;
pub type PhysicalDeviceTimelineSemaphorePropertiesKHR<'a> =
PhysicalDeviceTimelineSemaphoreProperties<'a>;
pub type SemaphoreTypeCreateInfoKHR<'a> = SemaphoreTypeCreateInfo<'a>;
pub type TimelineSemaphoreSubmitInfoKHR<'a> = TimelineSemaphoreSubmitInfo<'a>;
pub type SemaphoreWaitInfoKHR<'a> = SemaphoreWaitInfo<'a>;
pub type SemaphoreSignalInfoKHR<'a> = SemaphoreSignalInfo<'a>;
pub type PhysicalDevice8BitStorageFeaturesKHR<'a> = PhysicalDevice8BitStorageFeatures<'a>;
pub type PhysicalDeviceVulkanMemoryModelFeaturesKHR<'a> =
PhysicalDeviceVulkanMemoryModelFeatures<'a>;
pub type PhysicalDeviceShaderAtomicInt64FeaturesKHR<'a> =
PhysicalDeviceShaderAtomicInt64Features<'a>;
pub type PhysicalDeviceDepthStencilResolvePropertiesKHR<'a> =
PhysicalDeviceDepthStencilResolveProperties<'a>;
pub type SubpassDescriptionDepthStencilResolveKHR<'a> = SubpassDescriptionDepthStencilResolve<'a>;
pub type ImageStencilUsageCreateInfoEXT<'a> = ImageStencilUsageCreateInfo<'a>;
pub type PhysicalDeviceScalarBlockLayoutFeaturesEXT<'a> =
PhysicalDeviceScalarBlockLayoutFeatures<'a>;
pub type PhysicalDeviceUniformBufferStandardLayoutFeaturesKHR<'a> =
PhysicalDeviceUniformBufferStandardLayoutFeatures<'a>;
pub type PhysicalDeviceBufferDeviceAddressFeaturesKHR<'a> =
PhysicalDeviceBufferDeviceAddressFeatures<'a>;
pub type PhysicalDeviceBufferAddressFeaturesEXT<'a> =
PhysicalDeviceBufferDeviceAddressFeaturesEXT<'a>;
pub type BufferDeviceAddressInfoKHR<'a> = BufferDeviceAddressInfo<'a>;
pub type BufferDeviceAddressInfoEXT<'a> = BufferDeviceAddressInfo<'a>;
pub type BufferOpaqueCaptureAddressCreateInfoKHR<'a> = BufferOpaqueCaptureAddressCreateInfo<'a>;
pub type PhysicalDeviceImagelessFramebufferFeaturesKHR<'a> =
PhysicalDeviceImagelessFramebufferFeatures<'a>;
pub type FramebufferAttachmentsCreateInfoKHR<'a> = FramebufferAttachmentsCreateInfo<'a>;
pub type FramebufferAttachmentImageInfoKHR<'a> = FramebufferAttachmentImageInfo<'a>;
pub type RenderPassAttachmentBeginInfoKHR<'a> = RenderPassAttachmentBeginInfo<'a>;
pub type PhysicalDeviceTextureCompressionASTCHDRFeaturesEXT<'a> =
PhysicalDeviceTextureCompressionASTCHDRFeatures<'a>;
pub type PipelineCreationFeedbackEXT = PipelineCreationFeedback;
pub type PipelineCreationFeedbackCreateInfoEXT = PipelineCreationFeedbackCreateInfo;
pub type QueryPoolCreateInfoINTEL = QueryPoolPerformanceQueryCreateInfoINTEL;
pub type PhysicalDeviceSeparateDepthStencilLayoutsFeaturesKHR =
PhysicalDeviceSeparateDepthStencilLayoutsFeatures;
pub type AttachmentReferenceStencilLayoutKHR = AttachmentReferenceStencilLayout;
pub type AttachmentDescriptionStencilLayoutKHR = AttachmentDescriptionStencilLayout;
pub type PhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT =
PhysicalDeviceShaderDemoteToHelperInvocationFeatures;
pub type PhysicalDeviceTexelBufferAlignmentPropertiesEXT =
PhysicalDeviceTexelBufferAlignmentProperties;
pub type PhysicalDeviceSubgroupSizeControlFeaturesEXT = PhysicalDeviceSubgroupSizeControlFeatures;
pub type PhysicalDeviceSubgroupSizeControlPropertiesEXT =
PhysicalDeviceSubgroupSizeControlProperties;
pub type PipelineShaderStageRequiredSubgroupSizeCreateInfoEXT =
PipelineShaderStageRequiredSubgroupSizeCreateInfo;
pub type MemoryOpaqueCaptureAddressAllocateInfoKHR = MemoryOpaqueCaptureAddressAllocateInfo;
pub type DeviceMemoryOpaqueCaptureAddressInfoKHR = DeviceMemoryOpaqueCaptureAddressInfo;
pub type PhysicalDevicePipelineCreationCacheControlFeaturesEXT =
PhysicalDevicePipelineCreationCacheControlFeatures;
pub type PhysicalDeviceToolPropertiesEXT = PhysicalDeviceToolProperties;
pub type PipelineCreationFeedbackCreateInfoEXT<'a> = PipelineCreationFeedbackCreateInfo<'a>;
pub type QueryPoolCreateInfoINTEL<'a> = QueryPoolPerformanceQueryCreateInfoINTEL<'a>;
pub type PhysicalDeviceSeparateDepthStencilLayoutsFeaturesKHR<'a> =
PhysicalDeviceSeparateDepthStencilLayoutsFeatures<'a>;
pub type AttachmentReferenceStencilLayoutKHR<'a> = AttachmentReferenceStencilLayout<'a>;
pub type AttachmentDescriptionStencilLayoutKHR<'a> = AttachmentDescriptionStencilLayout<'a>;
pub type PhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT<'a> =
PhysicalDeviceShaderDemoteToHelperInvocationFeatures<'a>;
pub type PhysicalDeviceTexelBufferAlignmentPropertiesEXT<'a> =
PhysicalDeviceTexelBufferAlignmentProperties<'a>;
pub type PhysicalDeviceSubgroupSizeControlFeaturesEXT<'a> =
PhysicalDeviceSubgroupSizeControlFeatures<'a>;
pub type PhysicalDeviceSubgroupSizeControlPropertiesEXT<'a> =
PhysicalDeviceSubgroupSizeControlProperties<'a>;
pub type PipelineShaderStageRequiredSubgroupSizeCreateInfoEXT<'a> =
PipelineShaderStageRequiredSubgroupSizeCreateInfo<'a>;
pub type MemoryOpaqueCaptureAddressAllocateInfoKHR<'a> = MemoryOpaqueCaptureAddressAllocateInfo<'a>;
pub type DeviceMemoryOpaqueCaptureAddressInfoKHR<'a> = DeviceMemoryOpaqueCaptureAddressInfo<'a>;
pub type PhysicalDevicePipelineCreationCacheControlFeaturesEXT<'a> =
PhysicalDevicePipelineCreationCacheControlFeatures<'a>;
pub type PhysicalDeviceToolPropertiesEXT<'a> = PhysicalDeviceToolProperties<'a>;
pub type AabbPositionsNV = AabbPositionsKHR;
pub type TransformMatrixNV = TransformMatrixKHR;
pub type AccelerationStructureInstanceNV = AccelerationStructureInstanceKHR;
pub type PhysicalDeviceZeroInitializeWorkgroupMemoryFeaturesKHR =
PhysicalDeviceZeroInitializeWorkgroupMemoryFeatures;
pub type PhysicalDeviceImageRobustnessFeaturesEXT = PhysicalDeviceImageRobustnessFeatures;
pub type BufferCopy2KHR = BufferCopy2;
pub type ImageCopy2KHR = ImageCopy2;
pub type ImageBlit2KHR = ImageBlit2;
pub type BufferImageCopy2KHR = BufferImageCopy2;
pub type ImageResolve2KHR = ImageResolve2;
pub type CopyBufferInfo2KHR = CopyBufferInfo2;
pub type CopyImageInfo2KHR = CopyImageInfo2;
pub type BlitImageInfo2KHR = BlitImageInfo2;
pub type CopyBufferToImageInfo2KHR = CopyBufferToImageInfo2;
pub type CopyImageToBufferInfo2KHR = CopyImageToBufferInfo2;
pub type ResolveImageInfo2KHR = ResolveImageInfo2;
pub type PhysicalDeviceShaderTerminateInvocationFeaturesKHR =
PhysicalDeviceShaderTerminateInvocationFeatures;
pub type MemoryBarrier2KHR = MemoryBarrier2;
pub type ImageMemoryBarrier2KHR = ImageMemoryBarrier2;
pub type BufferMemoryBarrier2KHR = BufferMemoryBarrier2;
pub type DependencyInfoKHR = DependencyInfo;
pub type SemaphoreSubmitInfoKHR = SemaphoreSubmitInfo;
pub type CommandBufferSubmitInfoKHR = CommandBufferSubmitInfo;
pub type SubmitInfo2KHR = SubmitInfo2;
pub type PhysicalDeviceSynchronization2FeaturesKHR = PhysicalDeviceSynchronization2Features;
pub type PhysicalDeviceShaderIntegerDotProductFeaturesKHR =
PhysicalDeviceShaderIntegerDotProductFeatures;
pub type PhysicalDeviceShaderIntegerDotProductPropertiesKHR =
PhysicalDeviceShaderIntegerDotProductProperties;
pub type FormatProperties3KHR = FormatProperties3;
pub type PipelineRenderingCreateInfoKHR = PipelineRenderingCreateInfo;
pub type RenderingInfoKHR = RenderingInfo;
pub type RenderingAttachmentInfoKHR = RenderingAttachmentInfo;
pub type PhysicalDeviceDynamicRenderingFeaturesKHR = PhysicalDeviceDynamicRenderingFeatures;
pub type CommandBufferInheritanceRenderingInfoKHR = CommandBufferInheritanceRenderingInfo;
pub type AttachmentSampleCountInfoNV = AttachmentSampleCountInfoAMD;
pub type PhysicalDeviceZeroInitializeWorkgroupMemoryFeaturesKHR<'a> =
PhysicalDeviceZeroInitializeWorkgroupMemoryFeatures<'a>;
pub type PhysicalDeviceImageRobustnessFeaturesEXT<'a> = PhysicalDeviceImageRobustnessFeatures<'a>;
pub type BufferCopy2KHR<'a> = BufferCopy2<'a>;
pub type ImageCopy2KHR<'a> = ImageCopy2<'a>;
pub type ImageBlit2KHR<'a> = ImageBlit2<'a>;
pub type BufferImageCopy2KHR<'a> = BufferImageCopy2<'a>;
pub type ImageResolve2KHR<'a> = ImageResolve2<'a>;
pub type CopyBufferInfo2KHR<'a> = CopyBufferInfo2<'a>;
pub type CopyImageInfo2KHR<'a> = CopyImageInfo2<'a>;
pub type BlitImageInfo2KHR<'a> = BlitImageInfo2<'a>;
pub type CopyBufferToImageInfo2KHR<'a> = CopyBufferToImageInfo2<'a>;
pub type CopyImageToBufferInfo2KHR<'a> = CopyImageToBufferInfo2<'a>;
pub type ResolveImageInfo2KHR<'a> = ResolveImageInfo2<'a>;
pub type PhysicalDeviceShaderTerminateInvocationFeaturesKHR<'a> =
PhysicalDeviceShaderTerminateInvocationFeatures<'a>;
pub type MemoryBarrier2KHR<'a> = MemoryBarrier2<'a>;
pub type ImageMemoryBarrier2KHR<'a> = ImageMemoryBarrier2<'a>;
pub type BufferMemoryBarrier2KHR<'a> = BufferMemoryBarrier2<'a>;
pub type DependencyInfoKHR<'a> = DependencyInfo<'a>;
pub type SemaphoreSubmitInfoKHR<'a> = SemaphoreSubmitInfo<'a>;
pub type CommandBufferSubmitInfoKHR<'a> = CommandBufferSubmitInfo<'a>;
pub type SubmitInfo2KHR<'a> = SubmitInfo2<'a>;
pub type PhysicalDeviceSynchronization2FeaturesKHR<'a> = PhysicalDeviceSynchronization2Features<'a>;
pub type PhysicalDeviceShaderIntegerDotProductFeaturesKHR<'a> =
PhysicalDeviceShaderIntegerDotProductFeatures<'a>;
pub type PhysicalDeviceShaderIntegerDotProductPropertiesKHR<'a> =
PhysicalDeviceShaderIntegerDotProductProperties<'a>;
pub type FormatProperties3KHR<'a> = FormatProperties3<'a>;
pub type PipelineRenderingCreateInfoKHR<'a> = PipelineRenderingCreateInfo<'a>;
pub type RenderingInfoKHR<'a> = RenderingInfo<'a>;
pub type RenderingAttachmentInfoKHR<'a> = RenderingAttachmentInfo<'a>;
pub type PhysicalDeviceDynamicRenderingFeaturesKHR<'a> = PhysicalDeviceDynamicRenderingFeatures<'a>;
pub type CommandBufferInheritanceRenderingInfoKHR<'a> = CommandBufferInheritanceRenderingInfo<'a>;
pub type AttachmentSampleCountInfoNV<'a> = AttachmentSampleCountInfoAMD<'a>;

File diff suppressed because it is too large Load diff

View file

@ -4,7 +4,7 @@ use ash::vk::{PhysicalDeviceProperties, PipelineColorBlendStateCreateInfo};
fn assert_struct_field_is_array() {
let pipeline_cache_uuid: [u8; 16] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
let _ = PhysicalDeviceProperties::builder().pipeline_cache_uuid(pipeline_cache_uuid);
let _ = PhysicalDeviceProperties::default().pipeline_cache_uuid(pipeline_cache_uuid);
let _ = PhysicalDeviceProperties {
pipeline_cache_uuid,
@ -13,7 +13,7 @@ fn assert_struct_field_is_array() {
let blend_constants: [f32; 4] = [0.0, 0.0, 0.0, 0.0];
let _ = PipelineColorBlendStateCreateInfo::builder().blend_constants(blend_constants);
let _ = PipelineColorBlendStateCreateInfo::default().blend_constants(blend_constants);
let _ = PipelineColorBlendStateCreateInfo {
blend_constants,

View file

@ -62,12 +62,12 @@ fn main() {
..Default::default()
}];
let subpass = vk::SubpassDescription::builder()
let subpass = vk::SubpassDescription::default()
.color_attachments(&color_attachment_refs)
.depth_stencil_attachment(&depth_attachment_ref)
.pipeline_bind_point(vk::PipelineBindPoint::GRAPHICS);
let renderpass_create_info = vk::RenderPassCreateInfo::builder()
let renderpass_create_info = vk::RenderPassCreateInfo::default()
.attachments(&renderpass_attachments)
.subpasses(std::slice::from_ref(&subpass))
.dependencies(&dependencies);
@ -82,7 +82,7 @@ fn main() {
.iter()
.map(|&present_image_view| {
let framebuffer_attachments = [present_image_view, base.depth_image_view];
let frame_buffer_create_info = vk::FramebufferCreateInfo::builder()
let frame_buffer_create_info = vk::FramebufferCreateInfo::default()
.render_pass(renderpass)
.attachments(&framebuffer_attachments)
.width(base.surface_resolution.width)
@ -378,12 +378,11 @@ fn main() {
&[],
&[texture_barrier],
);
let buffer_copy_regions = vk::BufferImageCopy::builder()
let buffer_copy_regions = vk::BufferImageCopy::default()
.image_subresource(
vk::ImageSubresourceLayers::builder()
vk::ImageSubresourceLayers::default()
.aspect_mask(vk::ImageAspectFlags::COLOR)
.layer_count(1)
.build(),
.layer_count(1),
)
.image_extent(image_extent.into());
@ -392,7 +391,7 @@ fn main() {
image_buffer,
texture_image,
vk::ImageLayout::TRANSFER_DST_OPTIMAL,
&[buffer_copy_regions.build()],
&[buffer_copy_regions],
);
let texture_barrier_end = vk::ImageMemoryBarrier {
src_access_mask: vk::AccessFlags::TRANSFER_WRITE,
@ -467,7 +466,7 @@ fn main() {
descriptor_count: 1,
},
];
let descriptor_pool_info = vk::DescriptorPoolCreateInfo::builder()
let descriptor_pool_info = vk::DescriptorPoolCreateInfo::default()
.pool_sizes(&descriptor_sizes)
.max_sets(1);
@ -491,14 +490,14 @@ fn main() {
},
];
let descriptor_info =
vk::DescriptorSetLayoutCreateInfo::builder().bindings(&desc_layout_bindings);
vk::DescriptorSetLayoutCreateInfo::default().bindings(&desc_layout_bindings);
let desc_set_layouts = [base
.device
.create_descriptor_set_layout(&descriptor_info, None)
.unwrap()];
let desc_alloc_info = vk::DescriptorSetAllocateInfo::builder()
let desc_alloc_info = vk::DescriptorSetAllocateInfo::default()
.descriptor_pool(descriptor_pool)
.set_layouts(&desc_set_layouts);
let descriptor_sets = base
@ -542,11 +541,11 @@ fn main() {
let vertex_code =
read_spv(&mut vertex_spv_file).expect("Failed to read vertex shader spv file");
let vertex_shader_info = vk::ShaderModuleCreateInfo::builder().code(&vertex_code);
let vertex_shader_info = vk::ShaderModuleCreateInfo::default().code(&vertex_code);
let frag_code =
read_spv(&mut frag_spv_file).expect("Failed to read fragment shader spv file");
let frag_shader_info = vk::ShaderModuleCreateInfo::builder().code(&frag_code);
let frag_shader_info = vk::ShaderModuleCreateInfo::default().code(&frag_code);
let vertex_shader_module = base
.device
@ -559,7 +558,7 @@ fn main() {
.expect("Fragment shader module error");
let layout_create_info =
vk::PipelineLayoutCreateInfo::builder().set_layouts(&desc_set_layouts);
vk::PipelineLayoutCreateInfo::default().set_layouts(&desc_set_layouts);
let pipeline_layout = base
.device
@ -600,7 +599,7 @@ fn main() {
offset: offset_of!(Vertex, uv) as u32,
},
];
let vertex_input_state_info = vk::PipelineVertexInputStateCreateInfo::builder()
let vertex_input_state_info = vk::PipelineVertexInputStateCreateInfo::default()
.vertex_attribute_descriptions(&vertex_input_attribute_descriptions)
.vertex_binding_descriptions(&vertex_input_binding_descriptions);
@ -617,7 +616,7 @@ fn main() {
max_depth: 1.0,
}];
let scissors = [base.surface_resolution.into()];
let viewport_state_info = vk::PipelineViewportStateCreateInfo::builder()
let viewport_state_info = vk::PipelineViewportStateCreateInfo::default()
.scissors(&scissors)
.viewports(&viewports);
@ -628,7 +627,7 @@ fn main() {
..Default::default()
};
let multisample_state_info = vk::PipelineMultisampleStateCreateInfo::builder()
let multisample_state_info = vk::PipelineMultisampleStateCreateInfo::default()
.rasterization_samples(vk::SampleCountFlags::TYPE_1);
let noop_stencil_state = vk::StencilOpState {
@ -658,15 +657,15 @@ fn main() {
alpha_blend_op: vk::BlendOp::ADD,
color_write_mask: vk::ColorComponentFlags::RGBA,
}];
let color_blend_state = vk::PipelineColorBlendStateCreateInfo::builder()
let color_blend_state = vk::PipelineColorBlendStateCreateInfo::default()
.logic_op(vk::LogicOp::CLEAR)
.attachments(&color_blend_attachment_states);
let dynamic_state = [vk::DynamicState::VIEWPORT, vk::DynamicState::SCISSOR];
let dynamic_state_info =
vk::PipelineDynamicStateCreateInfo::builder().dynamic_states(&dynamic_state);
vk::PipelineDynamicStateCreateInfo::default().dynamic_states(&dynamic_state);
let graphic_pipeline_infos = vk::GraphicsPipelineCreateInfo::builder()
let graphic_pipeline_infos = vk::GraphicsPipelineCreateInfo::default()
.stages(&shader_stage_create_infos)
.vertex_input_state(&vertex_input_state_info)
.input_assembly_state(&vertex_input_assembly_state_info)
@ -681,11 +680,7 @@ fn main() {
let graphics_pipelines = base
.device
.create_graphics_pipelines(
vk::PipelineCache::null(),
&[graphic_pipeline_infos.build()],
None,
)
.create_graphics_pipelines(vk::PipelineCache::null(), &[graphic_pipeline_infos], None)
.unwrap();
let graphic_pipeline = graphics_pipelines[0];
@ -714,7 +709,7 @@ fn main() {
},
];
let render_pass_begin_info = vk::RenderPassBeginInfo::builder()
let render_pass_begin_info = vk::RenderPassBeginInfo::default()
.render_pass(renderpass)
.framebuffer(framebuffers[present_index as usize])
.render_area(base.surface_resolution.into())

View file

@ -51,12 +51,12 @@ fn main() {
..Default::default()
}];
let subpass = vk::SubpassDescription::builder()
let subpass = vk::SubpassDescription::default()
.color_attachments(&color_attachment_refs)
.depth_stencil_attachment(&depth_attachment_ref)
.pipeline_bind_point(vk::PipelineBindPoint::GRAPHICS);
let renderpass_create_info = vk::RenderPassCreateInfo::builder()
let renderpass_create_info = vk::RenderPassCreateInfo::default()
.attachments(&renderpass_attachments)
.subpasses(std::slice::from_ref(&subpass))
.dependencies(&dependencies);
@ -71,7 +71,7 @@ fn main() {
.iter()
.map(|&present_image_view| {
let framebuffer_attachments = [present_image_view, base.depth_image_view];
let frame_buffer_create_info = vk::FramebufferCreateInfo::builder()
let frame_buffer_create_info = vk::FramebufferCreateInfo::default()
.render_pass(renderpass)
.attachments(&framebuffer_attachments)
.width(base.surface_resolution.width)
@ -85,7 +85,7 @@ fn main() {
.collect();
let index_buffer_data = [0u32, 1, 2];
let index_buffer_info = vk::BufferCreateInfo::builder()
let index_buffer_info = vk::BufferCreateInfo::default()
.size(std::mem::size_of_val(&index_buffer_data) as u64)
.usage(vk::BufferUsageFlags::INDEX_BUFFER)
.sharing_mode(vk::SharingMode::EXCLUSIVE);
@ -203,11 +203,11 @@ fn main() {
let vertex_code =
read_spv(&mut vertex_spv_file).expect("Failed to read vertex shader spv file");
let vertex_shader_info = vk::ShaderModuleCreateInfo::builder().code(&vertex_code);
let vertex_shader_info = vk::ShaderModuleCreateInfo::default().code(&vertex_code);
let frag_code =
read_spv(&mut frag_spv_file).expect("Failed to read fragment shader spv file");
let frag_shader_info = vk::ShaderModuleCreateInfo::builder().code(&frag_code);
let frag_shader_info = vk::ShaderModuleCreateInfo::default().code(&frag_code);
let vertex_shader_module = base
.device
@ -262,7 +262,7 @@ fn main() {
},
];
let vertex_input_state_info = vk::PipelineVertexInputStateCreateInfo::builder()
let vertex_input_state_info = vk::PipelineVertexInputStateCreateInfo::default()
.vertex_attribute_descriptions(&vertex_input_attribute_descriptions)
.vertex_binding_descriptions(&vertex_input_binding_descriptions);
let vertex_input_assembly_state_info = vk::PipelineInputAssemblyStateCreateInfo {
@ -278,7 +278,7 @@ fn main() {
max_depth: 1.0,
}];
let scissors = [base.surface_resolution.into()];
let viewport_state_info = vk::PipelineViewportStateCreateInfo::builder()
let viewport_state_info = vk::PipelineViewportStateCreateInfo::default()
.scissors(&scissors)
.viewports(&viewports);
@ -318,15 +318,15 @@ fn main() {
alpha_blend_op: vk::BlendOp::ADD,
color_write_mask: vk::ColorComponentFlags::RGBA,
}];
let color_blend_state = vk::PipelineColorBlendStateCreateInfo::builder()
let color_blend_state = vk::PipelineColorBlendStateCreateInfo::default()
.logic_op(vk::LogicOp::CLEAR)
.attachments(&color_blend_attachment_states);
let dynamic_state = [vk::DynamicState::VIEWPORT, vk::DynamicState::SCISSOR];
let dynamic_state_info =
vk::PipelineDynamicStateCreateInfo::builder().dynamic_states(&dynamic_state);
vk::PipelineDynamicStateCreateInfo::default().dynamic_states(&dynamic_state);
let graphic_pipeline_info = vk::GraphicsPipelineCreateInfo::builder()
let graphic_pipeline_info = vk::GraphicsPipelineCreateInfo::default()
.stages(&shader_stage_create_infos)
.vertex_input_state(&vertex_input_state_info)
.input_assembly_state(&vertex_input_assembly_state_info)
@ -341,11 +341,7 @@ fn main() {
let graphics_pipelines = base
.device
.create_graphics_pipelines(
vk::PipelineCache::null(),
&[graphic_pipeline_info.build()],
None,
)
.create_graphics_pipelines(vk::PipelineCache::null(), &[graphic_pipeline_info], None)
.expect("Unable to create graphics pipeline");
let graphic_pipeline = graphics_pipelines[0];
@ -374,7 +370,7 @@ fn main() {
},
];
let render_pass_begin_info = vk::RenderPassBeginInfo::builder()
let render_pass_begin_info = vk::RenderPassBeginInfo::default()
.render_pass(renderpass)
.framebuffer(framebuffers[present_index as usize])
.render_area(base.surface_resolution.into())
@ -430,7 +426,7 @@ fn main() {
let wait_semaphors = [base.rendering_complete_semaphore];
let swapchains = [base.swapchain];
let image_indices = [present_index];
let present_info = vk::PresentInfoKHR::builder()
let present_info = vk::PresentInfoKHR::default()
.wait_semaphores(&wait_semaphors) // &base.rendering_complete_semaphore)
.swapchains(&swapchains)
.image_indices(&image_indices);

View file

@ -63,7 +63,7 @@ pub fn record_submit_commandbuffer<F: FnOnce(&Device, vk::CommandBuffer)>(
)
.expect("Reset command buffer failed.");
let command_buffer_begin_info = vk::CommandBufferBeginInfo::builder()
let command_buffer_begin_info = vk::CommandBufferBeginInfo::default()
.flags(vk::CommandBufferUsageFlags::ONE_TIME_SUBMIT);
device
@ -76,18 +76,14 @@ pub fn record_submit_commandbuffer<F: FnOnce(&Device, vk::CommandBuffer)>(
let command_buffers = vec![command_buffer];
let submit_info = vk::SubmitInfo::builder()
let submit_info = vk::SubmitInfo::default()
.wait_semaphores(wait_semaphores)
.wait_dst_stage_mask(wait_mask)
.command_buffers(&command_buffers)
.signal_semaphores(signal_semaphores);
device
.queue_submit(
submit_queue,
&[submit_info.build()],
command_buffer_reuse_fence,
)
.queue_submit(submit_queue, &[submit_info], command_buffer_reuse_fence)
.expect("queue submit failed.");
}
}
@ -233,14 +229,14 @@ impl ExampleBase {
.to_vec();
extension_names.push(DebugUtils::name().as_ptr());
let appinfo = vk::ApplicationInfo::builder()
let appinfo = vk::ApplicationInfo::default()
.application_name(app_name)
.application_version(0)
.engine_name(app_name)
.engine_version(0)
.api_version(vk::make_api_version(0, 1, 0, 0));
let create_info = vk::InstanceCreateInfo::builder()
let create_info = vk::InstanceCreateInfo::default()
.application_info(&appinfo)
.enabled_layer_names(&layers_names_raw)
.enabled_extension_names(&extension_names);
@ -249,7 +245,7 @@ impl ExampleBase {
.create_instance(&create_info, None)
.expect("Instance creation error");
let debug_info = vk::DebugUtilsMessengerCreateInfoEXT::builder()
let debug_info = vk::DebugUtilsMessengerCreateInfoEXT::default()
.message_severity(
vk::DebugUtilsMessageSeverityFlagsEXT::ERROR
| vk::DebugUtilsMessageSeverityFlagsEXT::WARNING
@ -304,11 +300,11 @@ impl ExampleBase {
};
let priorities = [1.0];
let queue_info = vk::DeviceQueueCreateInfo::builder()
let queue_info = vk::DeviceQueueCreateInfo::default()
.queue_family_index(queue_family_index)
.queue_priorities(&priorities);
let device_create_info = vk::DeviceCreateInfo::builder()
let device_create_info = vk::DeviceCreateInfo::default()
.queue_create_infos(std::slice::from_ref(&queue_info))
.enabled_extension_names(&device_extension_names_raw)
.enabled_features(&features);
@ -357,7 +353,7 @@ impl ExampleBase {
.unwrap_or(vk::PresentModeKHR::FIFO);
let swapchain_loader = Swapchain::new(&instance, &device);
let swapchain_create_info = vk::SwapchainCreateInfoKHR::builder()
let swapchain_create_info = vk::SwapchainCreateInfoKHR::default()
.surface(surface)
.min_image_count(desired_image_count)
.image_color_space(surface_format.color_space)
@ -375,13 +371,13 @@ impl ExampleBase {
.create_swapchain(&swapchain_create_info, None)
.unwrap();
let pool_create_info = vk::CommandPoolCreateInfo::builder()
let pool_create_info = vk::CommandPoolCreateInfo::default()
.flags(vk::CommandPoolCreateFlags::RESET_COMMAND_BUFFER)
.queue_family_index(queue_family_index);
let pool = device.create_command_pool(&pool_create_info, None).unwrap();
let command_buffer_allocate_info = vk::CommandBufferAllocateInfo::builder()
let command_buffer_allocate_info = vk::CommandBufferAllocateInfo::default()
.command_buffer_count(2)
.command_pool(pool)
.level(vk::CommandBufferLevel::PRIMARY);
@ -396,7 +392,7 @@ impl ExampleBase {
let present_image_views: Vec<vk::ImageView> = present_images
.iter()
.map(|&image| {
let create_view_info = vk::ImageViewCreateInfo::builder()
let create_view_info = vk::ImageViewCreateInfo::default()
.view_type(vk::ImageViewType::TYPE_2D)
.format(surface_format.format)
.components(vk::ComponentMapping {
@ -417,7 +413,7 @@ impl ExampleBase {
})
.collect();
let device_memory_properties = instance.get_physical_device_memory_properties(pdevice);
let depth_image_create_info = vk::ImageCreateInfo::builder()
let depth_image_create_info = vk::ImageCreateInfo::default()
.image_type(vk::ImageType::TYPE_2D)
.format(vk::Format::D16_UNORM)
.extent(surface_resolution.into())
@ -437,7 +433,7 @@ impl ExampleBase {
)
.expect("Unable to find suitable memory index for depth image.");
let depth_image_allocate_info = vk::MemoryAllocateInfo::builder()
let depth_image_allocate_info = vk::MemoryAllocateInfo::default()
.allocation_size(depth_image_memory_req.size)
.memory_type_index(depth_image_memory_index);
@ -450,7 +446,7 @@ impl ExampleBase {
.expect("Unable to bind depth image memory");
let fence_create_info =
vk::FenceCreateInfo::builder().flags(vk::FenceCreateFlags::SIGNALED);
vk::FenceCreateInfo::default().flags(vk::FenceCreateFlags::SIGNALED);
let draw_commands_reuse_fence = device
.create_fence(&fence_create_info, None)
@ -468,7 +464,7 @@ impl ExampleBase {
&[],
&[],
|device, setup_command_buffer| {
let layout_transition_barriers = vk::ImageMemoryBarrier::builder()
let layout_transition_barriers = vk::ImageMemoryBarrier::default()
.image(depth_image)
.dst_access_mask(
vk::AccessFlags::DEPTH_STENCIL_ATTACHMENT_READ
@ -477,11 +473,10 @@ impl ExampleBase {
.new_layout(vk::ImageLayout::DEPTH_STENCIL_ATTACHMENT_OPTIMAL)
.old_layout(vk::ImageLayout::UNDEFINED)
.subresource_range(
vk::ImageSubresourceRange::builder()
vk::ImageSubresourceRange::default()
.aspect_mask(vk::ImageAspectFlags::DEPTH)
.layer_count(1)
.level_count(1)
.build(),
.level_count(1),
);
device.cmd_pipeline_barrier(
@ -491,18 +486,17 @@ impl ExampleBase {
vk::DependencyFlags::empty(),
&[],
&[],
&[layout_transition_barriers.build()],
&[layout_transition_barriers],
);
},
);
let depth_image_view_info = vk::ImageViewCreateInfo::builder()
let depth_image_view_info = vk::ImageViewCreateInfo::default()
.subresource_range(
vk::ImageSubresourceRange::builder()
vk::ImageSubresourceRange::default()
.aspect_mask(vk::ImageAspectFlags::DEPTH)
.level_count(1)
.layer_count(1)
.build(),
.layer_count(1),
)
.image(depth_image)
.format(depth_image_create_info.format)

View file

@ -1375,7 +1375,7 @@ fn is_static_array(field: &vkxml::Field) -> bool {
.map(|ty| matches!(ty, vkxml::ArrayType::Static))
.unwrap_or(false)
}
pub fn derive_default(_struct: &vkxml::Struct) -> Option<TokenStream> {
pub fn derive_default(_struct: &vkxml::Struct, has_lifetime: bool) -> Option<TokenStream> {
let name = name_to_tokens(&_struct.name);
let members = _struct
.elements
@ -1427,20 +1427,27 @@ pub fn derive_default(_struct: &vkxml::Struct) -> Option<TokenStream> {
}
}
});
let lifetime = has_lifetime.then(|| quote!(<'_>));
let marker = has_lifetime.then(|| quote!(_marker: PhantomData,));
let q = quote! {
impl ::std::default::Default for #name {
impl ::std::default::Default for #name #lifetime {
fn default() -> Self {
Self {
#(
#default_fields
),*
#default_fields,
)*
#marker
}
}
}
};
Some(q)
}
pub fn derive_debug(_struct: &vkxml::Struct, union_types: &HashSet<&str>) -> Option<TokenStream> {
pub fn derive_debug(
_struct: &vkxml::Struct,
union_types: &HashSet<&str>,
has_lifetime: bool,
) -> Option<TokenStream> {
let name = name_to_tokens(&_struct.name);
let members = _struct
.elements
@ -1487,9 +1494,10 @@ pub fn derive_debug(_struct: &vkxml::Struct, union_types: &HashSet<&str>) -> Opt
}
});
let name_str = name.to_string();
let lifetime = has_lifetime.then(|| quote!(<'_>));
let q = quote! {
#[cfg(feature = "debug")]
impl fmt::Debug for #name {
impl fmt::Debug for #name #lifetime {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt.debug_struct(#name_str)
#(#debug_fields)*
@ -1503,6 +1511,7 @@ pub fn derive_debug(_struct: &vkxml::Struct, union_types: &HashSet<&str>) -> Opt
pub fn derive_setters(
struct_: &vkxml::Struct,
root_structs: &HashSet<Ident>,
has_lifetimes: &HashSet<Ident>,
) -> Option<TokenStream> {
if &struct_.name == "VkBaseInStructure"
|| &struct_.name == "VkBaseOutStructure"
@ -1513,7 +1522,6 @@ pub fn derive_setters(
}
let name = name_to_tokens(&struct_.name);
let name_builder = name_to_tokens(&(struct_.name.clone() + "Builder"));
let members = struct_
.elements
@ -1576,9 +1584,10 @@ pub fn derive_setters(
// Unique cases
if name == "pCode" {
return Some(quote!{
#[inline]
pub fn code(mut self, code: &'a [u32]) -> Self {
self.inner.code_size = code.len() * 4;
self.inner.p_code = code.as_ptr();
self.code_size = code.len() * 4;
self.p_code = code.as_ptr();
self
}
});
@ -1591,8 +1600,9 @@ pub fn derive_setters(
///
/// See <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/VkPipelineMultisampleStateCreateInfo.html#_description>
/// for more details.
#[inline]
pub fn sample_mask(mut self, sample_mask: &'a [SampleMask]) -> Self {
self.inner.p_sample_mask = if sample_mask.is_empty() {
self.p_sample_mask = if sample_mask.is_empty() {
std::ptr::null()
} else {
sample_mask.as_ptr()
@ -1604,9 +1614,10 @@ pub fn derive_setters(
if name == "ppGeometries" {
return Some(quote!{
pub fn geometries_ptrs(mut self, geometries: &'a [&'a AccelerationStructureGeometryKHR]) -> Self {
self.inner.geometry_count = geometries.len() as _;
self.inner.pp_geometries = geometries.as_ptr() as *const *const _;
#[inline]
pub fn geometries_ptrs(mut self, geometries: &'a [&'a AccelerationStructureGeometryKHR<'a>]) -> Self {
self.geometry_count = geometries.len() as _;
self.pp_geometries = geometries.as_ptr() as *const *const _;
self
}
});
@ -1619,8 +1630,9 @@ pub fn derive_setters(
assert!(field.null_terminate);
assert_eq!(field.size, None);
return Some(quote!{
#[inline]
pub fn #param_ident_short(mut self, #param_ident_short: &'a ::std::ffi::CStr) -> Self {
self.inner.#param_ident = #param_ident_short.as_ptr();
self.#param_ident = #param_ident_short.as_ptr();
self
}
});
@ -1665,15 +1677,16 @@ pub fn derive_setters(
quote!(as _)
};
quote!(self.inner.#array_size_ident = #param_ident_short.len()#cast;)
quote!(self.#array_size_ident = #param_ident_short.len()#cast;)
};
let mutable = if field.is_const { quote!() } else { quote!(mut) };
return Some(quote! {
#[inline]
pub fn #param_ident_short(mut self, #param_ident_short: &'a #mutable #slice_param_ty_tokens) -> Self {
#set_size_stmt
self.inner.#param_ident = #param_ident_short#ptr;
self.#param_ident = #param_ident_short#ptr;
self
}
});
@ -1683,8 +1696,9 @@ pub fn derive_setters(
if field.basetype == "VkBool32" {
return Some(quote!{
#[inline]
pub fn #param_ident_short(mut self, #param_ident_short: bool) -> Self {
self.inner.#param_ident = #param_ident_short.into();
self.#param_ident = #param_ident_short.into();
self
}
});
@ -1697,9 +1711,14 @@ pub fn derive_setters(
param_ty_tokens
};
let lifetime = has_lifetimes
.contains(&name_to_tokens(&field.basetype))
.then(|| quote!(<'a>));
Some(quote!{
pub fn #param_ident_short(mut self, #param_ident_short: #param_ty_tokens) -> Self {
self.inner.#param_ident = #param_ident_short;
#[inline]
pub fn #param_ident_short(mut self, #param_ident_short: #param_ty_tokens #lifetime) -> Self {
self.#param_ident = #param_ident_short;
self
}
})
@ -1722,7 +1741,7 @@ pub fn derive_setters(
/// Prepends the given extension struct between the root and the first pointer. This
/// method only exists on structs that can be passed to a function directly. Only
/// valid extension structs can be pushed into the chain.
/// If the chain looks like `A -> B -> C`, and you call `builder.push_next(&mut D)`, then the
/// If the chain looks like `A -> B -> C`, and you call `x.push_next(&mut D)`, then the
/// chain will look like `A -> D -> B -> C`.
pub fn push_next<T: #extends_name>(mut self, next: &'a mut T) -> Self {
unsafe {
@ -1737,8 +1756,8 @@ pub fn derive_setters(
// ^^^^^^
// next chain
let last_next = ptr_chain_iter(next).last().unwrap();
(*last_next).p_next = self.inner.p_next as _;
self.inner.p_next = next_ptr;
(*last_next).p_next = self.p_next as _;
self.p_next = next_ptr;
}
self
}
@ -1755,6 +1774,8 @@ pub fn derive_setters(
quote!()
};
let lifetime = has_lifetimes.contains(&name).then(|| quote!(<'a>));
// If the struct extends something we need to implement the traits.
let impl_extend_trait = struct_
.extends
@ -1762,57 +1783,18 @@ pub fn derive_setters(
.flat_map(|extends| extends.split(','))
.map(|extends| format_ident!("Extends{}", name_to_tokens(extends)))
.map(|extends| {
quote! {
unsafe impl #extends for #name_builder<'_> {}
unsafe impl #extends for #name {}
}
// Extension structs always have a pNext, and therefore always have a lifetime.
quote!(unsafe impl #extends for #name<'_> {})
});
let q = quote! {
impl #name {
pub fn builder<'a>() -> #name_builder<'a> {
#name_builder {
inner: Self::default(),
marker: ::std::marker::PhantomData,
}
}
}
#[repr(transparent)]
pub struct #name_builder<'a> {
inner: #name,
marker: ::std::marker::PhantomData<&'a ()>,
}
#(#impl_extend_trait)*
#next_trait
impl<'a> ::std::ops::Deref for #name_builder<'a> {
type Target = #name;
fn deref(&self) -> &Self::Target {
&self.inner
}
}
impl<'a> ::std::ops::DerefMut for #name_builder<'a> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.inner
}
}
impl<'a> #name_builder<'a> {
impl #lifetime #name #lifetime {
#(#setters)*
#next_function
/// Calling build will **discard** all the lifetime information. Only call this if
/// necessary! Builders implement `Deref` targeting their corresponding Vulkan struct,
/// so references to builders can be passed directly to Vulkan functions.
pub fn build(self) -> #name {
self.inner
}
}
};
@ -1834,6 +1816,7 @@ pub fn generate_struct(
_struct: &vkxml::Struct,
root_structs: &HashSet<Ident>,
union_types: &HashSet<&str>,
has_lifetimes: &HashSet<Ident>,
) -> TokenStream {
let name = name_to_tokens(&_struct.name);
if &_struct.name == "VkTransformMatrixKHR" {
@ -1916,14 +1899,24 @@ pub fn generate_struct(
.map(|r| r.to_tokens(field.is_const));
quote!(#pointer Self)
} else {
field.type_tokens(false)
let lifetime = has_lifetimes
.contains(&name_to_tokens(&field.basetype))
.then(|| quote!(<'a>));
let ty = field.type_tokens(false);
quote!(#ty #lifetime)
};
quote! {pub #param_ident: #param_ty_tokens}
});
let debug_tokens = derive_debug(_struct, union_types);
let default_tokens = derive_default(_struct);
let setter_tokens = derive_setters(_struct, root_structs);
let has_lifetime = has_lifetimes.contains(&name);
let (lifetimes, marker) = match has_lifetime {
true => (quote!(<'a>), quote!(pub _marker: PhantomData<&'a ()>,)),
false => (quote!(), quote!()),
};
let debug_tokens = derive_debug(_struct, union_types, has_lifetime);
let default_tokens = derive_default(_struct, has_lifetime);
let setter_tokens = derive_setters(_struct, root_structs, has_lifetimes);
let manual_derive_tokens = manual_derives(_struct);
let dbg_str = if debug_tokens.is_none() {
quote!(#[cfg_attr(feature = "debug", derive(Debug))])
@ -1941,8 +1934,9 @@ pub fn generate_struct(
#dbg_str
#[derive(Copy, Clone, #default_str #manual_derive_tokens)]
#[doc = #khronos_link]
pub struct #name {
pub struct #name #lifetimes {
#(#params,)*
#marker
}
#debug_tokens
#default_tokens
@ -1998,24 +1992,28 @@ fn generate_funcptr(fnptr: &vkxml::FunctionPointer) -> TokenStream {
}
}
fn generate_union(union: &vkxml::Union) -> TokenStream {
fn generate_union(union: &vkxml::Union, has_lifetimes: &HashSet<Ident>) -> TokenStream {
let name = name_to_tokens(&union.name);
let fields = union.elements.iter().map(|field| {
let name = field.param_ident();
let ty = field.type_tokens(false);
let lifetime = has_lifetimes
.contains(&name_to_tokens(&field.basetype))
.then(|| quote!(<'a>));
quote! {
pub #name: #ty
pub #name: #ty #lifetime
}
});
let khronos_link = khronos_link(&union.name);
let lifetime = has_lifetimes.contains(&name).then(|| quote!(<'a>));
quote! {
#[repr(C)]
#[derive(Copy, Clone)]
#[doc = #khronos_link]
pub union #name {
pub union #name #lifetime {
#(#fields),*
}
impl ::std::default::Default for #name {
impl #lifetime ::std::default::Default for #name #lifetime {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
}
@ -2039,6 +2037,7 @@ pub fn generate_definition(
definition: &vkxml::DefinitionsElement,
union_types: &HashSet<&str>,
root_structs: &HashSet<Ident>,
has_lifetimes: &HashSet<Ident>,
bitflags_cache: &mut HashSet<Ident>,
const_values: &mut BTreeMap<Ident, ConstantTypeInfo>,
identifier_renames: &mut BTreeMap<String, Ident>,
@ -2048,15 +2047,18 @@ pub fn generate_definition(
Some(generate_define(define, identifier_renames))
}
vkxml::DefinitionsElement::Typedef(ref typedef) => Some(generate_typedef(typedef)),
vkxml::DefinitionsElement::Struct(ref _struct) => {
Some(generate_struct(_struct, root_structs, union_types))
}
vkxml::DefinitionsElement::Struct(ref _struct) => Some(generate_struct(
_struct,
root_structs,
union_types,
has_lifetimes,
)),
vkxml::DefinitionsElement::Bitmask(ref mask) => {
generate_bitmask(mask, bitflags_cache, const_values)
}
vkxml::DefinitionsElement::Handle(ref handle) => generate_handle(handle),
vkxml::DefinitionsElement::FuncPtr(ref fp) => Some(generate_funcptr(fp)),
vkxml::DefinitionsElement::Union(ref union) => Some(generate_union(union)),
vkxml::DefinitionsElement::Union(ref union) => Some(generate_union(union, has_lifetimes)),
_ => None,
}
}
@ -2309,6 +2311,7 @@ pub fn extract_native_types(registry: &vk_parse::Registry) -> (Vec<(String, Stri
}
pub fn generate_aliases_of_types(
types: &vk_parse::Types,
has_lifetimes: &HashSet<Ident>,
ty_cache: &mut HashSet<Ident>,
) -> TokenStream {
let aliases = types
@ -2323,8 +2326,10 @@ pub fn generate_aliases_of_types(
return None;
};
let alias_ident = name_to_tokens(alias);
let tokens = quote! {
pub type #name_ident = #alias_ident;
let tokens = if has_lifetimes.contains(&alias_ident) {
quote!(pub type #name_ident<'a> = #alias_ident<'a>;)
} else {
quote!(pub type #name_ident = #alias_ident;)
};
Some(tokens)
});
@ -2343,13 +2348,6 @@ pub fn write_source_code<P: AsRef<Path>>(vk_headers_dir: &Path, src_dir: P) {
.find_map(get_variant!(vk_parse::RegistryChild::Extensions))
.map(|ext| &ext.children)
.expect("extension");
let mut ty_cache = HashSet::new();
let aliases: Vec<_> = spec2
.0
.iter()
.filter_map(get_variant!(vk_parse::RegistryChild::Types))
.map(|ty| generate_aliases_of_types(ty, &mut ty_cache))
.collect();
let spec = vk_parse::parse_file_as_vkxml(&vk_xml).expect("Invalid xml file.");
let cmd_aliases: HashMap<String, String> = spec2
@ -2439,6 +2437,37 @@ pub fn write_source_code<P: AsRef<Path>>(vk_headers_dir: &Path, src_dir: P) {
let mut identifier_renames = BTreeMap::new();
// Identify structs that need a lifetime annotation
// Note that this relies on `vk.xml` defining types before they are used,
// as is required in C(++) too.
let mut has_lifetimes = definitions
.iter()
.filter_map(get_variant!(vkxml::DefinitionsElement::Struct))
.filter_map(|s| {
s.elements
.iter()
.filter_map(get_variant!(vkxml::StructElement::Member))
.any(|x| x.reference.is_some())
.then(|| name_to_tokens(&s.name))
})
.collect::<HashSet<Ident>>();
for def in &definitions {
match def {
vkxml::DefinitionsElement::Struct(s) => s
.elements
.iter()
.filter_map(get_variant!(vkxml::StructElement::Member))
.any(|field| has_lifetimes.contains(&name_to_tokens(&field.basetype)))
.then(|| has_lifetimes.insert(name_to_tokens(&s.name))),
vkxml::DefinitionsElement::Union(u) => u
.elements
.iter()
.any(|field| has_lifetimes.contains(&name_to_tokens(&field.basetype)))
.then(|| has_lifetimes.insert(name_to_tokens(&u.name))),
_ => continue,
};
}
let root_structs = root_structs(&definitions);
let definition_code: Vec<_> = definitions
.into_iter()
@ -2447,6 +2476,7 @@ pub fn write_source_code<P: AsRef<Path>>(vk_headers_dir: &Path, src_dir: P) {
def,
&union_types,
&root_structs,
&has_lifetimes,
&mut bitflags_cache,
&mut const_values,
&mut identifier_renames,
@ -2454,6 +2484,14 @@ pub fn write_source_code<P: AsRef<Path>>(vk_headers_dir: &Path, src_dir: P) {
})
.collect();
let mut ty_cache = HashSet::new();
let aliases: Vec<_> = spec2
.0
.iter()
.filter_map(get_variant!(vk_parse::RegistryChild::Types))
.map(|ty| generate_aliases_of_types(ty, &has_lifetimes, &mut ty_cache))
.collect();
let feature_code: Vec<_> = features
.iter()
.map(|feature| generate_feature(feature, &commands, &mut fn_cache))
@ -2494,6 +2532,7 @@ pub fn write_source_code<P: AsRef<Path>>(vk_headers_dir: &Path, src_dir: P) {
};
let definition_code = quote! {
use std::marker::PhantomData;
use std::fmt;
use std::os::raw::*;
use crate::vk::{Handle, ptr_chain_iter};