This commit is contained in:
2024-12-30 17:23:32 +00:00
parent 3d401b0ae1
commit f78d9debf5
+78 -43
View File
@@ -1,5 +1,5 @@
#![feature(variant_count)] #![feature(variant_count)]
use std::{io::Cursor, sync::Arc, time::Instant}; use std::{default, io::Cursor, sync::Arc, time::Instant};
use bytemuck::{Pod, Zeroable}; use bytemuck::{Pod, Zeroable};
use cgmath::{Deg, EuclideanSpace, Euler, Matrix3, Matrix4, Point3, Rad, SquareMatrix, Vector3}; use cgmath::{Deg, EuclideanSpace, Euler, Matrix3, Matrix4, Point3, Rad, SquareMatrix, Vector3};
@@ -8,12 +8,12 @@ use instruction_set::InputTypes;
use rayon::prelude::*; use rayon::prelude::*;
use vulkano::{ use vulkano::{
buffer::{ buffer::{
allocator::{SubbufferAllocator, SubbufferAllocatorCreateInfo}, allocator::{SubbufferAllocator, SubbufferAllocatorCreateInfo}, Buffer, BufferAllocateInfo, BufferCreateInfo, BufferUsage, Subbuffer
Buffer, BufferAllocateInfo, BufferUsage, Subbuffer,
}, },
command_buffer::{ command_buffer::{
allocator::StandardCommandBufferAllocator, AutoCommandBufferBuilder, CommandBufferUsage, allocator::StandardCommandBufferAllocator, AutoCommandBufferBuilder, CommandBufferUsage,
CopyBufferInfo, PrimaryCommandBufferAbstract, RenderPassBeginInfo, SubpassContents, CopyBufferInfo, PrimaryCommandBufferAbstract, RenderPassBeginInfo, SubpassBeginInfo,
SubpassContents, SubpassEndInfo,
}, },
descriptor_set::{ descriptor_set::{
allocator::StandardDescriptorSetAllocator, PersistentDescriptorSet, WriteDescriptorSet, allocator::StandardDescriptorSetAllocator, PersistentDescriptorSet, WriteDescriptorSet,
@@ -28,8 +28,9 @@ use vulkano::{
AttachmentImage, ImageAccess, ImageUsage, SampleCount, SwapchainImage, AttachmentImage, ImageAccess, ImageUsage, SampleCount, SwapchainImage,
}, },
instance::{Instance, InstanceCreateInfo, InstanceExtensions}, instance::{Instance, InstanceCreateInfo, InstanceExtensions},
memory::allocator::{MemoryAllocatePreference, MemoryUsage, StandardMemoryAllocator}, memory::allocator::{AllocationCreateInfo, MemoryAllocatePreference, MemoryTypeFilter, MemoryUsage, StandardMemoryAllocator},
pipeline::{ pipeline::{
compute::ComputePipelineCreateInfo,
graphics::{ graphics::{
depth_stencil::DepthStencilState, depth_stencil::DepthStencilState,
input_assembly::InputAssemblyState, input_assembly::InputAssemblyState,
@@ -38,7 +39,8 @@ use vulkano::{
vertex_input::Vertex, vertex_input::Vertex,
viewport::{Viewport, ViewportState}, viewport::{Viewport, ViewportState},
}, },
GraphicsPipeline, Pipeline, PipelineBindPoint, GraphicsPipeline, Pipeline, PipelineBindPoint, PipelineShaderStageCreateFlags,
PipelineShaderStageCreateInfo,
StateMode::Fixed, StateMode::Fixed,
}, },
render_pass::{Framebuffer, FramebufferCreateInfo, RenderPass, Subpass}, render_pass::{Framebuffer, FramebufferCreateInfo, RenderPass, Subpass},
@@ -48,7 +50,7 @@ use vulkano::{
SwapchainCreationError, SwapchainPresentInfo, SwapchainCreationError, SwapchainPresentInfo,
}, },
sync::{self, FlushError, GpuFuture}, sync::{self, FlushError, GpuFuture},
VulkanLibrary, Version, VulkanLibrary,
}; };
use vulkano_win::VkSurfaceBuild; use vulkano_win::VkSurfaceBuild;
use winit::{ use winit::{
@@ -83,9 +85,10 @@ fn main() {
enabled_extensions: InstanceExtensions { enabled_extensions: InstanceExtensions {
..required_extensions ..required_extensions
}, },
// Enable enumerating devices that use non-conformant vulkan implementations. (ex. engine_name: Some("ImplEng".to_owned()),
// MoltenVK) engine_version: Version::major_minor(0, 1),
enumerate_portability: true, application_name: Some(env!("CARGO_PKG_NAME").to_owned()),
application_version: env!("CARGO_PKG_VERSION"),
..Default::default() ..Default::default()
}, },
) )
@@ -364,12 +367,23 @@ fn main() {
use vulkano::pipeline::ComputePipeline; use vulkano::pipeline::ComputePipeline;
let compute_layout = PipelineLayout::new(
device.clone(),
PipelineDescriptorSetLayoutCreateInfo::from_stages(&stages)
.into_pipeline_layout_create_info(device.clone())
.unwrap(),
)
.unwrap();
let compute_pipeline = ComputePipeline::new( let compute_pipeline = ComputePipeline::new(
device.clone(), device.clone(),
compute_shader.entry_point("main").unwrap(),
&(),
None, None,
|_| {}, ComputePipelineCreateInfo {
stage: PipelineShaderStageCreateInfo::new(compute_shader.entry_point("main").unwrap()),
base_pipeline: None,
layout: compute_layout,
..default::Default()
},
) )
.expect("failed to create compute pipeline"); .expect("failed to create compute pipeline");
@@ -379,41 +393,41 @@ fn main() {
device.clone(), device.clone(),
attachments: { attachments: {
intermediary: { intermediary: {
load: Clear,
store: DontCare,
format: swapchain.image_format(), format: swapchain.image_format(),
samples: 4, samples: 4,
load_op: Clear,
store_op: DontCare,
}, },
color: { color: {
load: DontCare,
store: Store,
format: swapchain.image_format(), format: swapchain.image_format(),
samples: 1, samples: 1,
load_op: DontCare,
store_op: Store,
}, },
multi_depth: { multi_depth: {
load: Clear,
store: DontCare,
format: Format::D16_UNORM, format: Format::D16_UNORM,
samples: 4, samples: 4,
} load_op: Clear,
store_op: DontCare,
},
}, },
passes: [{ passes: [{
color: [intermediary], color: [intermediary],
color_resolve: [color],
depth_stencil: {multi_depth}, depth_stencil: {multi_depth},
input: [], input: [],
resolve: [color]
},{ },{
color: [color], color: [color],
depth_stencil: {}, depth_stencil: {},
input: [] input: [],
}] }]
) )
.unwrap(); .unwrap();
let mut viewport = Viewport { let mut viewport = Viewport {
origin: [0.0, 0.0], offset: [0.0, 0.0],
dimensions: [0.0, 0.0], extent: [0.0, 0.0],
depth_range: 0.0..1.0, depth_range: 0.0..=1.0,
}; };
let mut gstate = GState::default(); let mut gstate = GState::default();
@@ -452,7 +466,8 @@ fn main() {
let mut recreate_swapchain = false; let mut recreate_swapchain = false;
let mut previous_frame_end = Some(sync::now(device.clone()).boxed()); let mut previous_frame_end = Some(sync::now(device.clone()).boxed());
let descriptor_set_allocator = StandardDescriptorSetAllocator::new(device.clone()); let descriptor_set_allocator =
StandardDescriptorSetAllocator::new(device.clone(), Default::default());
let uniform_buffer = SubbufferAllocator::new( let uniform_buffer = SubbufferAllocator::new(
memory_allocator.clone(), memory_allocator.clone(),
@@ -468,10 +483,11 @@ fn main() {
surface.clone(), surface.clone(),
queue.clone(), queue.clone(),
Subpass::from(render_pass.clone(), 1).unwrap(), Subpass::from(render_pass.clone(), 1).unwrap(),
images[0].format(),
GuiConfig { GuiConfig {
preferred_format: Some(images[0].format()), allow_srgb_render_target: true,
is_overlay: true, is_overlay: true,
samples: SampleCount::Sample4, samples: SampleCount::Sample4,
}, },
); );
@@ -562,7 +578,11 @@ fn main() {
looking = s == &ElementState::Pressed; looking = s == &ElementState::Pressed;
} }
}, },
WindowEvent::KeyboardInput { input, .. } => match input.virtual_keycode { WindowEvent::KeyboardInput {
device_id: _,
event: input,
is_synthetic: _,
} => match input.virtual_keycode {
Some(VirtualKeyCode::W) => { Some(VirtualKeyCode::W) => {
keys.w = input.state == ElementState::Pressed; keys.w = input.state == ElementState::Pressed;
}, },
@@ -963,7 +983,10 @@ fn main() {
framebuffers[image_index as usize].clone(), framebuffers[image_index as usize].clone(),
) )
}, },
SubpassContents::Inline, SubpassBeginInfo {
contents: SubpassContents::Inline,
..default::Default()
},
) )
.unwrap() .unwrap()
.set_viewport(0, [viewport.clone()]) .set_viewport(0, [viewport.clone()])
@@ -1019,11 +1042,17 @@ fn main() {
} }
builder builder
.next_subpass(SubpassContents::SecondaryCommandBuffers) .next_subpass(
Default::default(),
SubpassBeginInfo {
contents: SubpassContents::SecondaryCommandBuffers,
..default::Default()
},
)
.unwrap() .unwrap()
.execute_commands(guicb) .execute_commands(guicb)
.unwrap() .unwrap()
.end_render_pass() .end_render_pass(Default::default())
.unwrap(); .unwrap();
let command_buffer = builder.build().unwrap(); let command_buffer = builder.build().unwrap();
@@ -1141,8 +1170,8 @@ where
.vertex_shader(mesh_vs.entry_point("main").unwrap(), ()) .vertex_shader(mesh_vs.entry_point("main").unwrap(), ())
.viewport_state(ViewportState::viewport_fixed_scissor_irrelevant([ .viewport_state(ViewportState::viewport_fixed_scissor_irrelevant([
Viewport { Viewport {
origin: [0.0, 0.0], offset: [0.0, 0.0],
dimensions: [dimensions[0] as f32, dimensions[1] as f32], extent: [dimensions[0] as f32, dimensions[1] as f32],
depth_range: 0.0..1.0, depth_range: 0.0..1.0,
}, },
])) ]))
@@ -1171,8 +1200,8 @@ where
.input_assembly_state(InputAssemblyState::new()) .input_assembly_state(InputAssemblyState::new())
.viewport_state(ViewportState::viewport_fixed_scissor_irrelevant([ .viewport_state(ViewportState::viewport_fixed_scissor_irrelevant([
Viewport { Viewport {
origin: [0.0, 0.0], offset: [0.0, 0.0],
dimensions: [dimensions[0] as f32, dimensions[1] as f32], extent: [dimensions[0] as f32, dimensions[1] as f32],
depth_range: 0.0..1.0, depth_range: 0.0..1.0,
}, },
])) ]))
@@ -1256,9 +1285,12 @@ where
{ {
let buffer = Buffer::new_slice( let buffer = Buffer::new_slice(
allocator, allocator,
BufferAllocateInfo { BufferCreateInfo {
buffer_usage: BufferUsage::STORAGE_BUFFER | BufferUsage::TRANSFER_DST, usage: BufferUsage::STORAGE_BUFFER | BufferUsage::TRANSFER_DST,
memory_usage: MemoryUsage::GpuOnly, ..Default::default()
},
AllocationCreateInfo {
memory_type_filter: MemoryTypeFilter::PREFER_DEVICE,
allocate_preference: MemoryAllocatePreference::AlwaysAllocate, allocate_preference: MemoryAllocatePreference::AlwaysAllocate,
..Default::default() ..Default::default()
}, },
@@ -1594,9 +1626,12 @@ fn object_size_dependent_setup(
let fragment_masks_buffer = Buffer::new_slice( let fragment_masks_buffer = Buffer::new_slice(
&allocator, &allocator,
BufferCreateInfo {
usage:BufferUsage::STORAGE_BUFFER,
..Default::default()
},
BufferAllocateInfo { BufferAllocateInfo {
buffer_usage: BufferUsage::STORAGE_BUFFER, memory_type_filter: MemoryTypeFilter::PREFER_DEVICE,
memory_usage: MemoryUsage::GpuOnly,
allocate_preference: MemoryAllocatePreference::AlwaysAllocate, allocate_preference: MemoryAllocatePreference::AlwaysAllocate,
..Default::default() ..Default::default()
}, },
@@ -1608,7 +1643,7 @@ fn object_size_dependent_setup(
allocator.clone(), allocator.clone(),
SubbufferAllocatorCreateInfo { SubbufferAllocatorCreateInfo {
buffer_usage: BufferUsage::TRANSFER_SRC, buffer_usage: BufferUsage::TRANSFER_SRC,
memory_usage: MemoryUsage::Upload, memory_type_filter: MemoryTypeFilter::PREFER_HOST | MemoryTypeFilter::HOST_SEQUENTIAL_WRITE,
..Default::default() ..Default::default()
}, },
); );