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