Skip to content

Commit

Permalink
Unify all image types (vulkano-rs#2247)
Browse files Browse the repository at this point in the history
* Move `Image` to the `image` module

* Unify all image types

* Fix tests

* Fix examples

* Oopsie

* Don't re-export `ImageViewType`

* Fix docs

* Fix gl-interop example
  • Loading branch information
marc0246 authored and hakolao committed Feb 20, 2024
1 parent 606817a commit 2ce10df
Show file tree
Hide file tree
Showing 70 changed files with 2,105 additions and 3,962 deletions.
25 changes: 14 additions & 11 deletions examples/src/bin/async-update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ use vulkano::{
image::{
sampler::{Sampler, SamplerCreateInfo},
view::ImageView,
ImageAccess, ImageDimensions, ImageUsage, StorageImage, SwapchainImage,
Image, ImageCreateInfo, ImageDimensions, ImageUsage,
},
instance::{Instance, InstanceCreateFlags, InstanceCreateInfo},
memory::allocator::{AllocationCreateInfo, MemoryUsage, StandardMemoryAllocator},
Expand Down Expand Up @@ -238,7 +238,6 @@ fn main() {
device.clone(),
surface,
SwapchainCreateInfo {
// Some drivers report `min_image_count=1` but fullscreen mode requires at least 2.
min_image_count: surface_capabilities.min_image_count.max(2),
image_format,
image_extent: window.inner_size().into(),
Expand Down Expand Up @@ -313,15 +312,19 @@ fn main() {
// Create two textures, where at any point in time one is used exclusively for reading and one
// is used exclusively for writing, swapping the two after each update.
let textures = [(); 2].map(|_| {
StorageImage::new(
Image::new(
&memory_allocator,
ImageDimensions::Dim2d {
width: TRANSFER_GRANULARITY * 2,
height: TRANSFER_GRANULARITY * 2,
array_layers: 1,
ImageCreateInfo {
dimensions: ImageDimensions::Dim2d {
width: TRANSFER_GRANULARITY * 2,
height: TRANSFER_GRANULARITY * 2,
array_layers: 1,
},
format: Some(Format::R8G8B8A8_UNORM),
usage: ImageUsage::TRANSFER_DST | ImageUsage::SAMPLED,
..Default::default()
},
Format::R8G8B8A8_UNORM,
None,
AllocationCreateInfo::default(),
)
.unwrap()
});
Expand Down Expand Up @@ -685,7 +688,7 @@ fn main() {
fn run_worker(
channel: mpsc::Receiver<()>,
transfer_queue: Arc<Queue>,
textures: [Arc<StorageImage>; 2],
textures: [Arc<Image>; 2],
current_texture_index: Arc<AtomicBool>,
current_generation: Arc<AtomicU64>,
swapchain_image_count: u32,
Expand Down Expand Up @@ -844,7 +847,7 @@ fn run_worker(

/// This function is called once during initialization, then again whenever the window is resized.
fn window_size_dependent_setup(
images: &[Arc<SwapchainImage>],
images: &[Arc<Image>],
render_pass: Arc<RenderPass>,
viewport: &mut Viewport,
) -> Vec<Arc<Framebuffer>> {
Expand Down
6 changes: 3 additions & 3 deletions examples/src/bin/buffer-allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use vulkano::{
physical::PhysicalDeviceType, Device, DeviceCreateInfo, DeviceExtensions, QueueCreateInfo,
QueueFlags,
},
image::{view::ImageView, ImageAccess, ImageUsage, SwapchainImage},
image::{view::ImageView, Image, ImageUsage},
instance::{Instance, InstanceCreateFlags, InstanceCreateInfo},
memory::allocator::StandardMemoryAllocator,
pipeline::{
Expand Down Expand Up @@ -140,7 +140,6 @@ fn main() {
device.clone(),
surface,
SwapchainCreateInfo {
// Some drivers report `min_image_count=1` but fullscreen mode requires at least 2.
min_image_count: surface_capabilities.min_image_count.max(2),
image_format,
image_extent: window.inner_size().into(),
Expand Down Expand Up @@ -247,6 +246,7 @@ fn main() {
)
.unwrap();
let subpass = Subpass::from(render_pass.clone(), 0).unwrap();

GraphicsPipeline::new(
device.clone(),
None,
Expand Down Expand Up @@ -427,7 +427,7 @@ fn main() {

/// This function is called once during initialization, then again whenever the window is resized.
fn window_size_dependent_setup(
images: &[Arc<SwapchainImage>],
images: &[Arc<Image>],
render_pass: Arc<RenderPass>,
viewport: &mut Viewport,
) -> Vec<Arc<Framebuffer>> {
Expand Down
5 changes: 2 additions & 3 deletions examples/src/bin/clear_attachments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use vulkano::{
physical::PhysicalDeviceType, Device, DeviceCreateInfo, DeviceExtensions, QueueCreateInfo,
QueueFlags,
},
image::{view::ImageView, ImageUsage, SwapchainImage},
image::{view::ImageView, Image, ImageUsage},
instance::{Instance, InstanceCreateFlags, InstanceCreateInfo},
render_pass::{Framebuffer, FramebufferCreateInfo, RenderPass},
swapchain::{
Expand Down Expand Up @@ -119,7 +119,6 @@ fn main() {
device.clone(),
surface,
SwapchainCreateInfo {
// Some drivers report `min_image_count=1` but fullscreen mode requires at least 2.
min_image_count: surface_capabilities.min_image_count.max(2),
image_format,
image_extent: window.inner_size().into(),
Expand Down Expand Up @@ -299,7 +298,7 @@ fn main() {

/// This function is called once during initialization, then again whenever the window is resized.
fn window_size_dependent_setup(
images: &[Arc<SwapchainImage>],
images: &[Arc<Image>],
render_pass: Arc<RenderPass>,
) -> Vec<Arc<Framebuffer>> {
images
Expand Down
37 changes: 1 addition & 36 deletions examples/src/bin/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,16 @@

use std::sync::Arc;
use vulkano::{
command_buffer::{
allocator::StandardCommandBufferAllocator, AutoCommandBufferBuilder, CommandBufferUsage,
},
device::{
physical::PhysicalDeviceType, Device, DeviceCreateInfo, DeviceExtensions, QueueCreateInfo,
},
format::Format,
image::{ImageDimensions, ImmutableImage, MipmapsCount},
instance::{
debug::{
DebugUtilsMessageSeverity, DebugUtilsMessageType, DebugUtilsMessenger,
DebugUtilsMessengerCreateInfo,
},
Instance, InstanceCreateFlags, InstanceCreateInfo, InstanceExtensions,
},
memory::allocator::StandardMemoryAllocator,
VulkanLibrary,
};

Expand Down Expand Up @@ -151,7 +145,7 @@ fn main() {
})
.expect("no device available");

let (device, mut queues) = Device::new(
let (_device, mut _queues) = Device::new(
physical_device,
DeviceCreateInfo {
enabled_extensions: device_extensions,
Expand All @@ -163,35 +157,6 @@ fn main() {
},
)
.expect("failed to create device");
let queue = queues.next().unwrap();

let command_buffer_allocator =
StandardCommandBufferAllocator::new(device.clone(), Default::default());
let mut command_buffer_builder = AutoCommandBufferBuilder::primary(
&command_buffer_allocator,
queue.queue_family_index(),
CommandBufferUsage::OneTimeSubmit,
)
.unwrap();

// Create an image in order to generate some additional logging:
let pixel_format = Format::R8G8B8A8_UINT;
let dimensions = ImageDimensions::Dim2d {
width: 4096,
height: 4096,
array_layers: 1,
};
static DATA: [[u8; 4]; 4096 * 4096] = [[0; 4]; 4096 * 4096];
let memory_allocator = StandardMemoryAllocator::new_default(device);
let _ = ImmutableImage::from_iter(
&memory_allocator,
DATA.iter().copied(),
dimensions,
MipmapsCount::One,
pixel_format,
&mut command_buffer_builder,
)
.unwrap();

// (At this point you should see a bunch of messages printed to the terminal window -
// have fun debugging!)
Expand Down
5 changes: 3 additions & 2 deletions examples/src/bin/deferred/frame/ambient_lighting_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use vulkano::{
allocator::StandardDescriptorSetAllocator, PersistentDescriptorSet, WriteDescriptorSet,
},
device::Queue,
image::ImageViewAbstract,
image::view::ImageView,
memory::allocator::{AllocationCreateInfo, MemoryAllocator, MemoryUsage},
pipeline::{
graphics::{
Expand Down Expand Up @@ -109,6 +109,7 @@ impl AmbientLightingSystem {
.unwrap(),
)
.unwrap();

GraphicsPipeline::new(
device.clone(),
None,
Expand Down Expand Up @@ -162,7 +163,7 @@ impl AmbientLightingSystem {
pub fn draw(
&self,
viewport_dimensions: [u32; 2],
color_input: Arc<dyn ImageViewAbstract + 'static>,
color_input: Arc<ImageView>,
ambient_color: [f32; 3],
) -> Arc<SecondaryAutoCommandBuffer> {
let push_constants = fs::PushConstants {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use vulkano::{
allocator::StandardDescriptorSetAllocator, PersistentDescriptorSet, WriteDescriptorSet,
},
device::Queue,
image::ImageViewAbstract,
image::view::ImageView,
memory::allocator::{AllocationCreateInfo, MemoryAllocator, MemoryUsage},
pipeline::{
graphics::{
Expand Down Expand Up @@ -112,6 +112,7 @@ impl DirectionalLightingSystem {
.unwrap(),
)
.unwrap();

GraphicsPipeline::new(
device.clone(),
None,
Expand Down Expand Up @@ -172,8 +173,8 @@ impl DirectionalLightingSystem {
pub fn draw(
&self,
viewport_dimensions: [u32; 2],
color_input: Arc<dyn ImageViewAbstract + 'static>,
normals_input: Arc<dyn ImageViewAbstract + 'static>,
color_input: Arc<ImageView>,
normals_input: Arc<ImageView>,
direction: Vector3<f32>,
color: [f32; 3],
) -> Arc<SecondaryAutoCommandBuffer> {
Expand Down
9 changes: 5 additions & 4 deletions examples/src/bin/deferred/frame/point_lighting_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use vulkano::{
allocator::StandardDescriptorSetAllocator, PersistentDescriptorSet, WriteDescriptorSet,
},
device::Queue,
image::ImageViewAbstract,
image::view::ImageView,
memory::allocator::{AllocationCreateInfo, MemoryAllocator, MemoryUsage},
pipeline::{
graphics::{
Expand Down Expand Up @@ -109,6 +109,7 @@ impl PointLightingSystem {
.unwrap(),
)
.unwrap();

GraphicsPipeline::new(
device.clone(),
None,
Expand Down Expand Up @@ -179,9 +180,9 @@ impl PointLightingSystem {
pub fn draw(
&self,
viewport_dimensions: [u32; 2],
color_input: Arc<dyn ImageViewAbstract + 'static>,
normals_input: Arc<dyn ImageViewAbstract + 'static>,
depth_input: Arc<dyn ImageViewAbstract + 'static>,
color_input: Arc<ImageView>,
normals_input: Arc<ImageView>,
depth_input: Arc<ImageView>,
screen_to_world: Matrix4<f32>,
position: Vector3<f32>,
color: [f32; 3],
Expand Down
Loading

0 comments on commit 2ce10df

Please sign in to comment.