Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add VK_KHR_timeline_semaphore extension support #276

Merged
merged 8 commits into from
Mar 22, 2020

Conversation

zedrian
Copy link
Contributor

@zedrian zedrian commented Mar 16, 2020

Introduced ash::extensions::khr::TimelineSemaphore structure written by analogy with khr::Swapchain (except the fact that it does not hold any special functions besides those ones that are needed for extension loading).

Enabling timeline semaphore support in the application now:

let device_extension_names = [
    ash::extensions::khr::TimelineSemaphore::name().as_ptr(),
    // other device extensions
];

let mut timeline_semaphore_features = vk::PhysicalDeviceTimelineSemaphoreFeatures::builder()
    .timeline_semaphore(true);

let device_create_info = vk::DeviceCreateInfo::builder()
    .enabled_extension_names(&device_extension_names)
    .push_next(&mut timeline_semaphore_features)
    // other settings
    .build();
let device = unsafe { instance.create_device(physical_device, &device_create_info, None)? };

@zedrian
Copy link
Contributor Author

zedrian commented Mar 16, 2020

@farnoy I guess this PR may be interesting for you because you already requested this extension in #178

Copy link
Contributor

@farnoy farnoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this useful? KhrTimelineSemaphoreFn does not have any interesting functions itself.

The things that are of particular interest are (right now at least) defined on DeviceFnV1_2, like get_semaphore_counter_value. I believe these should be provided by your ash::extensions::TimelineSemaphore to be useful.

Either way, thank you for the effort, I just used the 1.2 versions myself.

@zedrian
Copy link
Contributor Author

zedrian commented Mar 16, 2020

@farnoy I tested on my side, functions related to timeline semaphores defined in DeviceFnV1_2 become available just using ash::device::Device, e.g.

unsafe { device.wait_semaphores(device.handle(), &semaphore_wait_info, std::u64::MAX).unwrap(); }

so you don't have to grab function pointers by yourself anymore.

@farnoy
Copy link
Contributor

farnoy commented Mar 16, 2020

Have you tested on a 1.0/1.1 application with this? I don't think that would work since the functions have a KHR suffix there. So using a DeviceFnV1_2.get_semaphore_counter_value would not work because it would try to load a vkGetSemaphoreCounterValue, whereas this extension should load vkGetSemaphoreCounterValueKHR.

@zedrian
Copy link
Contributor Author

zedrian commented Mar 16, 2020

@farnoy I tried this on API 1.1, and it doesn't work. As I understand, that happens because of VK_KHR_timeline_semaphore appeared in Vulkan 1.2.
Is this a problem?

@zedrian
Copy link
Contributor Author

zedrian commented Mar 16, 2020

@farnoy I misread your comment at first, sorry. Yes, it will not work because of the KHR suffix in older versions of Vulkan.

@Ralith
Copy link
Collaborator

Ralith commented Mar 17, 2020

The point is, the extension should provide access to the KHR-suffixed versions, and therefore be usable on 1.1 impls.

@zedrian
Copy link
Contributor Author

zedrian commented Mar 17, 2020

So expected implementation is that Vulkan 1.2 users call functions like

device.wait_semaphores(device.handle(), &semaphore_wait_info, timeout)?;

and Vulkan 1.1 users call functions like

timeline_semaphore_loader.wait_semaphores(&semaphore_wait_info, timeout)?;

right?

@farnoy
Copy link
Contributor

farnoy commented Mar 17, 2020

I would summarize it as:

1.2 users don't use this and call device.wait_semaphores(device.handle(), &semaphore_wait_info, timeout)?;

1.0/1.1 users need to enable the device extension and call timeline_semaphore_loader.wait_semaphores_khr(device.handle(), &semaphore_wait_info, timeout)?;

I think the suffix is usually preserved in ash, and the interface should be the same (because it is the same in the spec between the extension and 1.2 core)

@zedrian
Copy link
Contributor Author

zedrian commented Mar 17, 2020

BTW, VK_KHR_timeline_semaphore extension additionally requires VK_KHR_get_physical_device_properties2. But as I can see from my tests, it's enough to just add that extension name to the list of enabled extensions.

@zedrian
Copy link
Contributor Author

zedrian commented Mar 18, 2020

I added the *_khr functions to the TimelineSemaphore as discussed, so the following code is available now for Vulkan 1.0/1.1 users:

timeline_semaphore_loader.get_semaphore_counter_value_khr(device.handle(), semaphore)?;

timeline_semaphore_loader.wait_semaphores_khr(device.handle(), &semaphore_wait_info, timeout)?;
timeline_semaphore_loader.signal_semaphore_khr(device.handle(), &semaphore_signal_info, timeout)?;

Copy link
Contributor

@farnoy farnoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@MaikKlein
Copy link
Member

Hey thanks for the PR. Sorry for not responding sooner. I made a PR to include function aliases in extensions #279

pub struct KhrTimelineSemaphoreFn {
    pub get_semaphore_counter_value:
        extern "system" fn(device: Device, semaphore: Semaphore, p_value: *mut u64) -> Result,
    pub wait_semaphores: extern "system" fn(
        device: Device,
        p_wait_info: *const SemaphoreWaitInfo,
        timeout: u64,
    ) -> Result,
    pub signal_semaphore:
        extern "system" fn(device: Device, p_signal_info: *const SemaphoreSignalInfo) -> Result,
}

No need to fetch those function pointers yourself and we should update this PR when this is merged in.

@zedrian
Copy link
Contributor Author

zedrian commented Mar 21, 2020

That would be great! Waiting for #279.

Copy link
Member

@MaikKlein MaikKlein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! LGTM

@MaikKlein MaikKlein merged commit e84c1c4 into ash-rs:master Mar 22, 2020
@zedrian zedrian deleted the khr_timeline_semaphore branch March 22, 2020 15:08
gabdube pushed a commit to gabdube/ash that referenced this pull request Mar 23, 2020
* TimelineSemaphore struct added presenting `VK_KHR_timeline_semaphore` extension.

* Unused import removed.

* Empty newline added.

* TimelineSemaphore extension object now provides functions for work with timeline semaphores.

* Function pointers removed from TimelineSemaphore as no longer needed.
*_khr postfix removed from TimelineSemaphore functions to follow the same code style as in other extensions.

* Tiny code reformatting to fit Rustfmt requirements.

* Another attempt to fit Rustfmt requirements.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants