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

#[inline]ing adjustments and minor syntax/formatting changes #2016

Merged
merged 2 commits into from
Oct 4, 2022
Merged
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
2 changes: 0 additions & 2 deletions vulkano-shaders/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,14 +290,12 @@ pub enum Error {
}

impl From<IoError> for Error {
#[inline]
fn from(err: IoError) -> Error {
Error::IoError(err)
}
}

impl From<SpirvError> for Error {
#[inline]
fn from(err: SpirvError) -> Error {
Error::SpirvError(err)
}
Expand Down
11 changes: 10 additions & 1 deletion vulkano-util/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub struct VulkanoConfig {
}

impl Default for VulkanoConfig {
#[inline]
fn default() -> Self {
let device_extensions = DeviceExtensions {
khr_swapchain: true,
Expand Down Expand Up @@ -88,7 +89,7 @@ impl Default for VulkanoConfig {
/// in the creation of [`VulkanoWindowRenderer`](crate::renderer::VulkanoWindowRenderer) through
/// [`VulkanoWindows`](crate::window::VulkanoWindows).
///
/// ## Example
/// ## Examples
///
/// ```no_run
/// use vulkano_util::context::{VulkanoConfig, VulkanoContext};
Expand All @@ -107,6 +108,7 @@ pub struct VulkanoContext {
}

impl Default for VulkanoContext {
#[inline]
fn default() -> Self {
VulkanoContext::new(VulkanoConfig::default())
}
Expand Down Expand Up @@ -245,16 +247,19 @@ impl VulkanoContext {
}

/// Returns the name of the device.
#[inline]
pub fn device_name(&self) -> &str {
&self.device.physical_device().properties().device_name
}

/// Returns the type of the device.
#[inline]
pub fn device_type(&self) -> PhysicalDeviceType {
self.device.physical_device().properties().device_type
}

/// Returns the maximum memory allocation of the device.
#[inline]
pub fn max_memory(&self) -> u32 {
self.device
.physical_device()
Expand All @@ -263,23 +268,27 @@ impl VulkanoContext {
}

/// Returns the instance.
#[inline]
pub fn instance(&self) -> &Arc<Instance> {
&self.instance
}

/// Returns the device.
#[inline]
pub fn device(&self) -> &Arc<Device> {
&self.device
}

/// Returns the graphics queue.
#[inline]
pub fn graphics_queue(&self) -> &Arc<Queue> {
&self.graphics_queue
}

/// Returns the compute queue.
///
/// Depending on your device, this might be the same as graphics queue.
#[inline]
pub fn compute_queue(&self) -> &Arc<Queue> {
&self.compute_queue
}
Expand Down
75 changes: 49 additions & 26 deletions vulkano-util/src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ pub type DeviceImageView = Arc<ImageView<StorageImage>>;
/// Most common image format
pub const DEFAULT_IMAGE_FORMAT: Format = Format::R8G8B8A8_UNORM;

/// A window renderer struct holding the winit window surface and functionality for organizing your render
/// between frames.
/// A window renderer struct holding the winit window surface and functionality for organizing your
/// render between frames.
///
/// Begin rendering with [`VulkanoWindowRenderer::acquire`] and finish with [`VulkanoWindowRenderer::present`].
/// Between those, you should execute your command buffers.
/// Begin rendering with [`VulkanoWindowRenderer::acquire`] and finish with
/// [`VulkanoWindowRenderer::present`]. Between those, you should execute your command buffers.
///
/// The intended usage of this struct is through [`crate::window::VulkanoWindows`].
pub struct VulkanoWindowRenderer {
Expand All @@ -56,8 +56,9 @@ pub struct VulkanoWindowRenderer {
}

impl VulkanoWindowRenderer {
/// Creates a new [`VulkanoWindowRenderer`] which is used to orchestrate your rendering with Vulkano.
/// Pass [`WindowDescriptor`] and optionally a function modifying the [`SwapchainCreateInfo`](vulkano::swapchain::SwapchainCreateInfo) parameters.
/// Creates a new [`VulkanoWindowRenderer`] which is used to orchestrate your rendering with
/// Vulkano. Pass [`WindowDescriptor`] and optionally a function modifying the
/// [`SwapchainCreateInfo`](vulkano::swapchain::SwapchainCreateInfo) parameters.
pub fn new(
vulkano_context: &VulkanoContext,
window: winit::window::Window,
Expand Down Expand Up @@ -142,62 +143,73 @@ impl VulkanoWindowRenderer {
}

/// Set window renderer present mode. This triggers a swapchain recreation.
#[inline]
pub fn set_present_mode(&mut self, present_mode: vulkano::swapchain::PresentMode) {
if self.present_mode != present_mode {
self.present_mode = present_mode;
self.recreate_swapchain = true;
}
}

/// Return swapchain image format
/// Return swapchain image format.
#[inline]
pub fn swapchain_format(&self) -> Format {
self.final_views[self.image_index as usize]
.format()
.unwrap()
}

/// Returns the index of last swapchain image that is the next render target
/// Returns the index of last swapchain image that is the next render target.
#[inline]
pub fn image_index(&self) -> u32 {
self.image_index
}

/// Graphics queue of this window. You also can access this through [`VulkanoContext`]
/// Graphics queue of this window. You also can access this through [`VulkanoContext`].
#[inline]
pub fn graphics_queue(&self) -> Arc<Queue> {
self.graphics_queue.clone()
}

/// Compute queue of this window. You can also access this through [`VulkanoContext`]
/// Compute queue of this window. You can also access this through [`VulkanoContext`].
#[inline]
pub fn compute_queue(&self) -> Arc<Queue> {
self.compute_queue.clone()
}

/// Render target surface
/// Render target surface.
#[inline]
pub fn surface(&self) -> Arc<Surface<Window>> {
self.surface.clone()
}

/// Winit window (you can manipulate window through this).
#[inline]
pub fn window(&self) -> &Window {
self.surface.window()
}

/// Size of the physical window
/// Size of the physical window.
#[inline]
pub fn window_size(&self) -> [f32; 2] {
let size = self.window().inner_size();
[size.width as f32, size.height as f32]
}

/// Size of the final swapchain image (surface)
/// Size of the final swapchain image (surface).
#[inline]
pub fn swapchain_image_size(&self) -> [u32; 2] {
self.final_views[0].image().dimensions().width_height()
}

/// Return the current swapchain image view
/// Return the current swapchain image view.
#[inline]
pub fn swapchain_image_view(&self) -> SwapchainImageView {
self.final_views[self.image_index as usize].clone()
}

/// Return scale factor accounted window size
/// Return scale factor accounted window size.
#[inline]
pub fn resolution(&self) -> [f32; 2] {
let size = self.window().inner_size();
let scale_factor = self.window().scale_factor();
Expand All @@ -207,17 +219,21 @@ impl VulkanoWindowRenderer {
]
}

#[inline]
pub fn aspect_ratio(&self) -> f32 {
let dims = self.window_size();
dims[0] / dims[1]
}

/// Resize swapchain and camera view images at the beginning of next frame based on window dimensions
/// Resize swapchain and camera view images at the beginning of next frame based on window
/// dimensions.
#[inline]
pub fn resize(&mut self) {
self.recreate_swapchain = true;
}

/// Add interim image view that resizes with window
/// Add interim image view that resizes with window.
#[inline]
pub fn add_additional_image_view(&mut self, key: usize, format: Format, usage: ImageUsage) {
let size = self.swapchain_image_size();
let image = StorageImage::general_purpose_image_view(
Expand All @@ -230,20 +246,24 @@ impl VulkanoWindowRenderer {
self.additional_image_views.insert(key, image);
}

/// Get additional image view by key
/// Get additional image view by key.
#[inline]
pub fn get_additional_image_view(&mut self, key: usize) -> DeviceImageView {
self.additional_image_views.get(&key).unwrap().clone()
}

/// Remove additional image by key
/// Remove additional image by key.
#[inline]
pub fn remove_additional_image_view(&mut self, key: usize) {
self.additional_image_views.remove(&key);
}

/// Begin your rendering by calling `acquire`.
/// Returns a [`GpuFuture`](vulkano::sync::GpuFuture) representing the time after which the swapchain image has been acquired
/// and previous frame ended.
/// Execute your command buffers after calling this function and finish rendering by calling [`VulkanoWindowRenderer::present`].
/// Returns a [`GpuFuture`](vulkano::sync::GpuFuture) representing the time after which the
/// swapchain image has been acquired and previous frame ended.
/// Execute your command buffers after calling this function and finish rendering by calling
/// [`VulkanoWindowRenderer::present`].
#[inline]
pub fn acquire(&mut self) -> std::result::Result<Box<dyn GpuFuture>, AcquireError> {
// Recreate swap chain if needed (when resizing of window occurs or swapchain is outdated)
// Also resize render views if needed
Expand Down Expand Up @@ -272,10 +292,13 @@ impl VulkanoWindowRenderer {
Ok(future.boxed())
}

/// Finishes rendering by presenting the swapchain. Pass your last future as an input to this function.
/// Finishes rendering by presenting the swapchain. Pass your last future as an input to this
/// function.
///
/// Depending on your implementation, you may want to wait on your future. For example, a compute shader
/// dispatch using an image that's being later drawn should probably be waited on.
/// Depending on your implementation, you may want to wait on your future. For example, a
/// compute shader dispatch using an image that's being later drawn should probably be waited
/// on.
#[inline]
pub fn present(&mut self, after_future: Box<dyn GpuFuture>, wait_future: bool) {
let future = after_future
.then_swapchain_present(
Expand Down Expand Up @@ -313,7 +336,7 @@ impl VulkanoWindowRenderer {
}
}

/// Recreates swapchain images and image views which follow the window size
/// Recreates swapchain images and image views which follow the window size.
fn recreate_swapchain_and_views(&mut self) {
let dimensions: [u32; 2] = self.window().inner_size().into();
let (new_swapchain, new_images) = match self.swapchain.recreate(SwapchainCreateInfo {
Expand Down
Loading