This commit is contained in:
2024-12-31 15:47:03 +00:00
parent f78d9debf5
commit 94f8e0502a
3 changed files with 1219 additions and 1237 deletions
Generated
+589 -700
View File
File diff suppressed because it is too large Load Diff
+7 -6
View File
@@ -9,7 +9,6 @@ edition = "2021"
vulkano = "0.34" vulkano = "0.34"
vulkano-shaders = "0.34" vulkano-shaders = "0.34"
winit = "0.30" winit = "0.30"
vulkano-win = "0.34"
vulkano-util = "0.34" vulkano-util = "0.34"
obj = "0.10" obj = "0.10"
@@ -35,8 +34,10 @@ rand = "0.8.5"
# using latest gits # using latest gits
[patch.crates-io] [patch.crates-io]
vulkano = { git = "https://github.com/vulkano-rs/vulkano" } vulkano = { git = "https://github.com/Molive-0/vulkano" }
vulkano-shaders = { git = "https://github.com/vulkano-rs/vulkano" } vulkano-macros = { git = "https://github.com/Molive-0/vulkano" }
vulkano-win = { git = "https://github.com/vulkano-rs/vulkano" } vulkano-shaders = { git = "https://github.com/Molive-0/vulkano" }
vulkano-util = { git = "https://github.com/vulkano-rs/vulkano" } vulkano-taskgraph = { git = "https://github.com/Molive-0/vulkano" }
egui_winit_vulkano = { git = "https://github.com/hakolao/egui_winit_vulkano" } vulkano-util = { git = "https://github.com/Molive-0/vulkano" }
vulkano-win = { git = "https://github.com/Molive-0/vulkano" }
egui_winit_vulkano = { git = "https://github.com/Molive-0/egui_winit_vulkano" }
+230 -138
View File
@@ -1,5 +1,5 @@
#![feature(variant_count)] #![feature(variant_count)]
use std::{default, io::Cursor, sync::Arc, time::Instant}; use std::{default, error::Error, 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,55 +8,58 @@ use instruction_set::InputTypes;
use rayon::prelude::*; use rayon::prelude::*;
use vulkano::{ use vulkano::{
buffer::{ buffer::{
allocator::{SubbufferAllocator, SubbufferAllocatorCreateInfo}, Buffer, BufferAllocateInfo, BufferCreateInfo, BufferUsage, Subbuffer allocator::{SubbufferAllocator, SubbufferAllocatorCreateInfo},
Buffer, BufferCreateInfo, BufferUsage, Subbuffer,
}, },
command_buffer::{ command_buffer::{
allocator::StandardCommandBufferAllocator, AutoCommandBufferBuilder, CommandBufferUsage, allocator::StandardCommandBufferAllocator, AutoCommandBufferBuilder, CommandBufferUsage,
CopyBufferInfo, PrimaryCommandBufferAbstract, RenderPassBeginInfo, SubpassBeginInfo, CopyBufferInfo, PrimaryCommandBufferAbstract, RenderPassBeginInfo, SubpassBeginInfo,
SubpassContents, SubpassEndInfo, SubpassContents,
},
descriptor_set::{
allocator::StandardDescriptorSetAllocator, PersistentDescriptorSet, WriteDescriptorSet,
}, },
descriptor_set::{allocator::StandardDescriptorSetAllocator, WriteDescriptorSet},
device::{ device::{
physical::PhysicalDeviceType, Device, DeviceCreateInfo, DeviceExtensions, DeviceOwned, physical::PhysicalDeviceType, Device, DeviceCreateInfo, DeviceExtensions, DeviceFeatures,
Features, Queue, QueueCreateInfo, QueueFlags, DeviceOwned, Queue, QueueCreateInfo, QueueFlags,
}, },
format::Format, format::Format,
image::{ image::{
view::{ImageView, ImageViewCreateInfo}, view::{ImageView, ImageViewCreateInfo},
AttachmentImage, ImageAccess, ImageUsage, SampleCount, SwapchainImage, Image, ImageCreateInfo, ImageType, ImageUsage, SampleCount,
}, },
instance::{Instance, InstanceCreateInfo, InstanceExtensions}, instance::{Instance, InstanceCreateInfo, InstanceExtensions},
memory::allocator::{AllocationCreateInfo, MemoryAllocatePreference, MemoryTypeFilter, MemoryUsage, StandardMemoryAllocator}, memory::allocator::{
AllocationCreateInfo, MemoryAllocatePreference, MemoryTypeFilter, StandardMemoryAllocator,
},
pipeline::{ pipeline::{
compute::ComputePipelineCreateInfo, compute::ComputePipelineCreateInfo,
graphics::{ graphics::{
depth_stencil::DepthStencilState, color_blend::{ColorBlendAttachmentState, ColorBlendState},
depth_stencil::{DepthState, DepthStencilState},
input_assembly::InputAssemblyState, input_assembly::InputAssemblyState,
multisample::MultisampleState, multisample::MultisampleState,
rasterization::{CullMode, FrontFace::Clockwise, RasterizationState}, rasterization::{CullMode, FrontFace::Clockwise, RasterizationState},
vertex_input::Vertex, vertex_input::Vertex,
viewport::{Viewport, ViewportState}, viewport::{Viewport, ViewportState},
GraphicsPipelineCreateInfo,
}, },
GraphicsPipeline, Pipeline, PipelineBindPoint, PipelineShaderStageCreateFlags, layout::PipelineDescriptorSetLayoutCreateInfo,
GraphicsPipeline, Pipeline, PipelineBindPoint, PipelineLayout,
PipelineShaderStageCreateInfo, PipelineShaderStageCreateInfo,
StateMode::Fixed,
}, },
render_pass::{Framebuffer, FramebufferCreateInfo, RenderPass, Subpass}, render_pass::{Framebuffer, FramebufferCreateInfo, RenderPass, Subpass},
shader::{ShaderModule, SpecializationConstants}, shader::ShaderModule,
swapchain::{ swapchain::{
acquire_next_image, AcquireError, PresentMode, Swapchain, SwapchainCreateInfo, acquire_next_image, PresentMode, Surface, Swapchain, SwapchainCreateInfo,
SwapchainCreationError, SwapchainPresentInfo, SwapchainPresentInfo,
}, },
sync::{self, FlushError, GpuFuture}, sync::{self, GpuFuture},
Version, VulkanLibrary, Version, VulkanLibrary,
}; };
use vulkano_win::VkSurfaceBuild;
use winit::{ use winit::{
event::{DeviceEvent, ElementState, Event, MouseButton, VirtualKeyCode, WindowEvent}, application::ApplicationHandler,
event_loop::{ControlFlow, EventLoop}, event::{DeviceEvent, ElementState, Event, MouseButton, WindowEvent},
window::{Window, WindowBuilder}, event_loop::{ActiveEventLoop, ControlFlow, EventLoop},
window::{Window, WindowAttributes},
}; };
mod gui; mod gui;
@@ -73,11 +76,38 @@ use crate::instruction_set::InstructionSet;
mod interpreter; mod interpreter;
pub(crate) type MemoryAllocator = StandardMemoryAllocator; fn main() -> Result<(), impl Error> {
let event_loop = EventLoop::new().unwrap();
let mut app = App::new(&event_loop);
fn main() { event_loop.run_app(&mut app)
}
struct App {
instance: Arc<Instance>,
device: Arc<Device>,
graphics_queue: Arc<Queue>,
transfer_queue: Arc<Queue>,
memory_allocator: Arc<StandardMemoryAllocator>,
command_buffer_allocator: Arc<StandardCommandBufferAllocator>,
rcx: Option<RenderContext>,
}
struct RenderContext {
window: Arc<Window>,
swapchain: Arc<Swapchain>,
render_pass: Arc<RenderPass>,
framebuffers: Vec<Arc<Framebuffer>>,
pipeline: Arc<GraphicsPipeline>,
viewport: Viewport,
recreate_swapchain: bool,
previous_frame_end: Option<Box<dyn GpuFuture>>,
}
impl App {
fn new(event_loop: &EventLoop<()>) -> Self {
let library = VulkanLibrary::new().expect("Vulkan is not installed???"); let library = VulkanLibrary::new().expect("Vulkan is not installed???");
let required_extensions = vulkano_win::required_extensions(&library); let required_extensions = Surface::required_extensions(&library);
let instance = Instance::new( let instance = Instance::new(
library, library,
@@ -94,12 +124,6 @@ fn main() {
) )
.unwrap(); .unwrap();
let event_loop = EventLoop::new();
let surface = WindowBuilder::new()
.with_title("Implicit Surfaces")
.build_vk_surface(&event_loop, instance.clone())
.unwrap();
let device_extensions = DeviceExtensions { let device_extensions = DeviceExtensions {
khr_swapchain: true, khr_swapchain: true,
ext_mesh_shader: true, ext_mesh_shader: true,
@@ -107,7 +131,7 @@ fn main() {
..DeviceExtensions::empty() ..DeviceExtensions::empty()
}; };
let (physical_device, (queue_family_index, transfer_index)) = instance let (physical_device, (graphics_queue_index, transfer_queue_index)) = instance
.enumerate_physical_devices() .enumerate_physical_devices()
.unwrap() .unwrap()
.filter(|p| p.supported_extensions().contains(&device_extensions)) .filter(|p| p.supported_extensions().contains(&device_extensions))
@@ -117,7 +141,8 @@ fn main() {
.enumerate() .enumerate()
.position(|(i, q)| { .position(|(i, q)| {
q.queue_flags.intersects(QueueFlags::GRAPHICS) q.queue_flags.intersects(QueueFlags::GRAPHICS)
&& p.surface_support(i as u32, &surface).unwrap_or(false) && p.presentation_support(i as u32, event_loop)
.unwrap_or(false)
}) })
.and_then(|graphics| { .and_then(|graphics| {
p.queue_family_properties() p.queue_family_properties()
@@ -127,10 +152,9 @@ fn main() {
q.queue_flags.intersects(QueueFlags::TRANSFER) && i != graphics q.queue_flags.intersects(QueueFlags::TRANSFER) && i != graphics
}) })
.or_else(|| { .or_else(|| {
p.queue_family_properties() p.queue_family_properties().iter().enumerate().position(
.iter() |(_i, q)| q.queue_flags.intersects(QueueFlags::TRANSFER),
.enumerate() )
.position(|(_i, q)| q.queue_flags.intersects(QueueFlags::TRANSFER))
}) })
.map(|i| (graphics as u32, i as u32)) .map(|i| (graphics as u32, i as u32))
}) })
@@ -165,15 +189,15 @@ fn main() {
enabled_extensions: device_extensions, enabled_extensions: device_extensions,
queue_create_infos: vec![ queue_create_infos: vec![
QueueCreateInfo { QueueCreateInfo {
queue_family_index, queue_family_index: graphics_queue_index,
..Default::default() ..Default::default()
}, },
QueueCreateInfo { QueueCreateInfo {
queue_family_index: transfer_index, queue_family_index: transfer_queue_index,
..Default::default() ..Default::default()
}, },
], ],
enabled_features: Features { enabled_features: DeviceFeatures {
mesh_shader: true, mesh_shader: true,
task_shader: true, task_shader: true,
sample_rate_shading: true, sample_rate_shading: true,
@@ -183,41 +207,69 @@ fn main() {
storage_buffer8_bit_access: true, storage_buffer8_bit_access: true,
geometry_shader: true, geometry_shader: true,
primitive_fragment_shading_rate: true, primitive_fragment_shading_rate: true,
..Features::empty() ..DeviceFeatures::empty()
}, },
..Default::default() ..Default::default()
}, },
) )
.expect("Unable to initialize device"); .expect("Unable to initialize device");
let queue = queues.next().expect("Unable to retrieve queues"); let graphics_queue = queues.next().expect("Unable to retrieve queues");
let transfer_queue = queues.next().expect("Unable to retrieve queues"); let transfer_queue = queues.next().expect("Unable to retrieve queues");
let memory_allocator = Arc::new(StandardMemoryAllocator::new_default(device.clone()));
let command_buffer_allocator =
StandardCommandBufferAllocator::new(device.clone(), Default::default());
App {
instance,
device,
graphics_queue,
transfer_queue,
memory_allocator,
command_buffer_allocator,
rcx: None,
}
}
}
impl ApplicationHandler for App {
fn resumed(&mut self, event_loop: &ActiveEventLoop) {
let window = Arc::new(
event_loop
.create_window(WindowAttributes {
title: "Implicit Surfaces".to_owned(),
..Window::default_attributes()
})
.unwrap(),
);
let surface = Surface::from_window(self.instance.clone(), window.clone()).unwrap();
let window_size = window.inner_size();
let (mut swapchain, images) = { let (mut swapchain, images) = {
let surface_capabilities = device let surface_capabilities = self
.device
.physical_device() .physical_device()
.surface_capabilities(&surface, Default::default()) .surface_capabilities(&surface, Default::default())
.unwrap(); .unwrap();
let image_format = Some( let (image_format, _) = self
device .device
.physical_device() .physical_device()
.surface_formats(&surface, Default::default()) .surface_formats(&surface, Default::default())
.unwrap()[0] .unwrap()[0];
.0,
);
let window = surface.object().unwrap().downcast_ref::<Window>().unwrap();
Swapchain::new( Swapchain::new(
device.clone(), self.device.clone(),
surface.clone(), surface,
SwapchainCreateInfo { SwapchainCreateInfo {
min_image_count: 3 min_image_count: 3
.max(surface_capabilities.min_image_count) .max(surface_capabilities.min_image_count)
.min(surface_capabilities.max_image_count.unwrap_or(u32::MAX)), .min(surface_capabilities.max_image_count.unwrap_or(u32::MAX)),
image_format, image_format,
image_extent: window.inner_size().into(), image_extent: window_size.into(),
image_usage: ImageUsage::COLOR_ATTACHMENT, image_usage: ImageUsage::COLOR_ATTACHMENT,
@@ -239,8 +291,8 @@ fn main() {
vulkano_shaders::shader! { vulkano_shaders::shader! {
ty: "vertex", ty: "vertex",
path: "src/triangle.vert.glsl", path: "src/triangle.vert.glsl",
vulkan_version: "1.2", vulkan_version: "1.3",
spirv_version: "1.5", spirv_version: "1.6",
custom_derives: [Debug, Clone, Copy], custom_derives: [Debug, Clone, Copy],
} }
} }
@@ -249,8 +301,8 @@ fn main() {
vulkano_shaders::shader! { vulkano_shaders::shader! {
ty: "fragment", ty: "fragment",
path: "src/frag.glsl", path: "src/frag.glsl",
vulkan_version: "1.2", vulkan_version: "1.3",
spirv_version: "1.5", spirv_version: "1.6",
define: [("triangle","1")], define: [("triangle","1")],
custom_derives: [Debug, Clone, Copy], custom_derives: [Debug, Clone, Copy],
} }
@@ -260,8 +312,8 @@ fn main() {
vulkano_shaders::shader! { vulkano_shaders::shader! {
ty: "mesh", ty: "mesh",
path: "src/implicit.mesh.glsl", path: "src/implicit.mesh.glsl",
vulkan_version: "1.2", vulkan_version: "1.3",
spirv_version: "1.5", spirv_version: "1.6",
custom_derives: [Debug, Clone, Copy], custom_derives: [Debug, Clone, Copy],
} }
} }
@@ -270,8 +322,8 @@ fn main() {
vulkano_shaders::shader! { vulkano_shaders::shader! {
ty: "task", ty: "task",
path: "src/implicit.task.glsl", path: "src/implicit.task.glsl",
vulkan_version: "1.2", vulkan_version: "1.3",
spirv_version: "1.5", spirv_version: "1.6",
custom_derives: [Debug, Clone, Copy], custom_derives: [Debug, Clone, Copy],
} }
} }
@@ -280,8 +332,8 @@ fn main() {
vulkano_shaders::shader! { vulkano_shaders::shader! {
ty: "fragment", ty: "fragment",
path: "src/frag.glsl", path: "src/frag.glsl",
vulkan_version: "1.2", vulkan_version: "1.3",
spirv_version: "1.5", spirv_version: "1.6",
define: [("implicit","1")], define: [("implicit","1")],
custom_derives: [Debug, Clone, Copy], custom_derives: [Debug, Clone, Copy],
} }
@@ -291,8 +343,8 @@ fn main() {
vulkano_shaders::shader! { vulkano_shaders::shader! {
ty: "compute", ty: "compute",
path: "src/fuzz.comp.glsl", path: "src/fuzz.comp.glsl",
vulkan_version: "1.2", vulkan_version: "1.3",
spirv_version: "1.5", spirv_version: "1.6",
custom_derives: [Debug, Clone, Copy], custom_derives: [Debug, Clone, Copy],
} }
} }
@@ -302,7 +354,7 @@ fn main() {
::std::sync::Arc<::vulkano::device::Device>, ::std::sync::Arc<::vulkano::device::Device>,
) -> Result< ) -> Result<
::std::sync::Arc<::vulkano::shader::ShaderModule>, ::std::sync::Arc<::vulkano::shader::ShaderModule>,
::vulkano::shader::ShaderCreationError, ::vulkano::Validated<::vulkano::VulkanError>,
>, >,
> = vec![ > = vec![
((mesh_vs::load) ((mesh_vs::load)
@@ -310,48 +362,48 @@ fn main() {
::std::sync::Arc<::vulkano::device::Device>, ::std::sync::Arc<::vulkano::device::Device>,
) -> Result< ) -> Result<
::std::sync::Arc<::vulkano::shader::ShaderModule>, ::std::sync::Arc<::vulkano::shader::ShaderModule>,
::vulkano::shader::ShaderCreationError, ::vulkano::Validated<::vulkano::VulkanError>,
>), >),
((mesh_fs::load) ((mesh_fs::load)
as fn( as fn(
::std::sync::Arc<::vulkano::device::Device>, ::std::sync::Arc<::vulkano::device::Device>,
) -> Result< ) -> Result<
::std::sync::Arc<::vulkano::shader::ShaderModule>, ::std::sync::Arc<::vulkano::shader::ShaderModule>,
::vulkano::shader::ShaderCreationError, ::vulkano::Validated<::vulkano::VulkanError>,
>), >),
((implicit_ms::load) ((implicit_ms::load)
as fn( as fn(
::std::sync::Arc<::vulkano::device::Device>, ::std::sync::Arc<::vulkano::device::Device>,
) -> Result< ) -> Result<
::std::sync::Arc<::vulkano::shader::ShaderModule>, ::std::sync::Arc<::vulkano::shader::ShaderModule>,
::vulkano::shader::ShaderCreationError, ::vulkano::Validated<::vulkano::VulkanError>,
>), >),
((implicit_ts::load) ((implicit_ts::load)
as fn( as fn(
::std::sync::Arc<::vulkano::device::Device>, ::std::sync::Arc<::vulkano::device::Device>,
) -> Result< ) -> Result<
::std::sync::Arc<::vulkano::shader::ShaderModule>, ::std::sync::Arc<::vulkano::shader::ShaderModule>,
::vulkano::shader::ShaderCreationError, ::vulkano::Validated<::vulkano::VulkanError>,
>), >),
((implicit_fs::load) ((implicit_fs::load)
as fn( as fn(
::std::sync::Arc<::vulkano::device::Device>, ::std::sync::Arc<::vulkano::device::Device>,
) -> Result< ) -> Result<
::std::sync::Arc<::vulkano::shader::ShaderModule>, ::std::sync::Arc<::vulkano::shader::ShaderModule>,
::vulkano::shader::ShaderCreationError, ::vulkano::Validated<::vulkano::VulkanError>,
>), >),
((cs::load) ((cs::load)
as fn( as fn(
::std::sync::Arc<::vulkano::device::Device>, ::std::sync::Arc<::vulkano::device::Device>,
) -> Result< ) -> Result<
::std::sync::Arc<::vulkano::shader::ShaderModule>, ::std::sync::Arc<::vulkano::shader::ShaderModule>,
::vulkano::shader::ShaderCreationError, ::vulkano::Validated<::vulkano::VulkanError>,
>), >),
]; ];
let pariter = loaders let pariter = loaders
.par_iter() .par_iter()
.map(|load| load(device.clone()).unwrap()) .map(|load| load(self.device.clone()).unwrap())
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let mesh_vs = pariter[0].clone(); let mesh_vs = pariter[0].clone();
@@ -367,30 +419,33 @@ fn main() {
use vulkano::pipeline::ComputePipeline; use vulkano::pipeline::ComputePipeline;
let compute_layout = PipelineLayout::new( let compute_stage =
device.clone(), PipelineShaderStageCreateInfo::new(compute_shader.entry_point("main").unwrap());
PipelineDescriptorSetLayoutCreateInfo::from_stages(&stages)
.into_pipeline_layout_create_info(device.clone()) let pipeline_layout = PipelineLayout::new(
self.device.clone(),
PipelineDescriptorSetLayoutCreateInfo::from_stages([
mesh_vs,
mesh_fs,
implicit_ms,
implicit_ts,
implicit_fs,
compute_stage,
])
.into_pipeline_layout_create_info(self.device.clone())
.unwrap(), .unwrap(),
) )
.unwrap(); .unwrap();
let compute_pipeline = ComputePipeline::new( let compute_pipeline = ComputePipeline::new(
device.clone(), self.device.clone(),
None, None,
ComputePipelineCreateInfo { ComputePipelineCreateInfo::stage_layout(compute_stage, pipeline_layout),
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");
let memory_allocator = Arc::new(MemoryAllocator::new_default(device.clone()));
let render_pass = vulkano::ordered_passes_renderpass!( let render_pass = vulkano::ordered_passes_renderpass!(
device.clone(), self.device.clone(),
attachments: { attachments: {
intermediary: { intermediary: {
format: swapchain.image_format(), format: swapchain.image_format(),
@@ -435,7 +490,7 @@ fn main() {
//let [RES_X, RES_Y] = images[0].dimensions().width_height(); //let [RES_X, RES_Y] = images[0].dimensions().width_height();
let ([mut mesh_pipeline, mut implicit_pipeline], mut framebuffers) = let ([mut mesh_pipeline, mut implicit_pipeline], mut framebuffers) =
window_size_dependent_setup( window_size_dependent_setup(
&memory_allocator, &self.memory_allocator,
&mesh_vs, &mesh_vs,
&mesh_fs, &mesh_fs,
&implicit_ms, &implicit_ms,
@@ -460,9 +515,6 @@ fn main() {
gstate.debug.brute_force, gstate.debug.brute_force,
); );
let command_buffer_allocator =
StandardCommandBufferAllocator::new(device.clone(), Default::default());
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());
@@ -550,8 +602,14 @@ fn main() {
let mut prevdub = PreviousDebug::default(); let mut prevdub = PreviousDebug::default();
let mut render_start = Instant::now(); let mut render_start = Instant::now();
}
event_loop.run(move |event, _, control_flow| { fn window_event(
&mut self,
event_loop: &ActiveEventLoop,
window_id: winit::window::WindowId,
event: WindowEvent,
) {
if let Event::WindowEvent { event: we, .. } = &event { if let Event::WindowEvent { event: we, .. } = &event {
if !gui.update(we) { if !gui.update(we) {
match &we { match &we {
@@ -642,7 +700,9 @@ fn main() {
..swapchain.create_info() ..swapchain.create_info()
}) { }) {
Ok(r) => r, Ok(r) => r,
Err(SwapchainCreationError::ImageExtentNotSupported { .. }) => return, Err(SwapchainCreationError::ImageExtentNotSupported { .. }) => {
return;
},
Err(e) => panic!("Failed to recreate swapchain: {e:?}"), Err(e) => panic!("Failed to recreate swapchain: {e:?}"),
}; };
@@ -845,7 +905,8 @@ fn main() {
InstructionSet::OPSDFSphere, InstructionSet::OPSDFSphere,
vec![Inputs::Float(1.2), Inputs::Variable], vec![Inputs::Float(1.2), Inputs::Variable],
), ),
//CSGPart::opcode(InstructionSet::OPSDFBox, vec![Inputs::Variable, //CSGPart::opcode(InstructionSet::OPSDFBox,
// vec![Inputs::Variable,
// Inputs::Vec3([0.7, 0.7, 0.7].into())]), // Inputs::Vec3([0.7, 0.7, 0.7].into())]),
CSGPart::opcode( CSGPart::opcode(
InstructionSet::OPMinFloat, InstructionSet::OPMinFloat,
@@ -899,10 +960,12 @@ fn main() {
WriteDescriptorSet::buffer(7, compute_subbuffers.vec4s.clone()), WriteDescriptorSet::buffer(7, compute_subbuffers.vec4s.clone()),
//WriteDescriptorSet::buffer(8, compute_subbuffers.mat2s.clone()), //WriteDescriptorSet::buffer(8, compute_subbuffers.mat2s.clone()),
//WriteDescriptorSet::buffer(9, compute_subbuffers.mat3s.clone()), //WriteDescriptorSet::buffer(9, compute_subbuffers.mat3s.clone()),
//WriteDescriptorSet::buffer(10, compute_subbuffers.mat4s.clone()), //WriteDescriptorSet::buffer(10,
// compute_subbuffers.mat4s.clone()),
// WriteDescriptorSet::buffer(11, compute_subbuffers.mats.clone()), // WriteDescriptorSet::buffer(11, compute_subbuffers.mats.clone()),
WriteDescriptorSet::buffer(12, compute_subbuffers.deps), WriteDescriptorSet::buffer(12, compute_subbuffers.deps),
//WriteDescriptorSet::buffer(20, compute_subbuffers.masks.clone()), //WriteDescriptorSet::buffer(20,
// compute_subbuffers.masks.clone()),
WriteDescriptorSet::buffer(30, compute_result_buffer.clone()), WriteDescriptorSet::buffer(30, compute_result_buffer.clone()),
], ],
) )
@@ -1085,7 +1148,7 @@ fn main() {
}, },
_ => (), _ => (),
} }
}); }
} }
/// This method is called once during initialization, then again whenever the /// This method is called once during initialization, then again whenever the
@@ -1097,8 +1160,8 @@ fn window_size_dependent_setup<Fs, Ms, Ts>(
implicit_ms: &ShaderModule, implicit_ms: &ShaderModule,
implicit_ts: &ShaderModule, implicit_ts: &ShaderModule,
implicit_fs: &ShaderModule, implicit_fs: &ShaderModule,
images: &[Arc<SwapchainImage>], images: &[Arc<Image>],
render_pass: Arc<RenderPass>, render_pass: &Arc<RenderPass>,
viewport: &mut Viewport, viewport: &mut Viewport,
implicit_fs_specs: Fs, implicit_fs_specs: Fs,
implicit_ms_specs: Ms, implicit_ms_specs: Ms,
@@ -1110,34 +1173,40 @@ where
Ms: SpecializationConstants + Clone, Ms: SpecializationConstants + Clone,
Ts: SpecializationConstants + Clone, Ts: SpecializationConstants + Clone,
{ {
let dimensions = images[0].dimensions().width_height(); let dimensions = images[0].extent();
viewport.dimensions = [dimensions[0] as f32, dimensions[1] as f32]; viewport.dimensions = [dimensions[0] as f32, dimensions[1] as f32];
let depth_buffer = ImageView::new_default( let depth_buffer = ImageView::new_default(
AttachmentImage::transient_multisampled( Image::new(
allocator, allocator.clone(),
dimensions, ImageCreateInfo {
SampleCount::Sample4, image_type: ImageType::Dim2d,
Format::D16_UNORM, // D24_UNORM_S8_UINT format: Format::D16_UNORM,
extent: images[0].extent(),
usage: ImageUsage::DEPTH_STENCIL_ATTACHMENT | ImageUsage::TRANSIENT_ATTACHMENT,
samples: SampleCount::Sample4,
..Default::default()
},
AllocationCreateInfo::default(),
) )
.unwrap(), .unwrap(),
) )
.unwrap(); .unwrap();
let intermediary_image = AttachmentImage::transient_multisampled( let intermediary = ImageView::new_default(
allocator, Image::new(
dimensions, allocator.clone(),
SampleCount::Sample4, ImageCreateInfo {
images[0].format(), image_type: ImageType::Dim2d,
) format: images[0].format(),
.unwrap(); extent: dimensions,
let intermediary = ImageView::new(
intermediary_image.clone(),
ImageViewCreateInfo {
usage: ImageUsage::COLOR_ATTACHMENT | ImageUsage::TRANSIENT_ATTACHMENT, usage: ImageUsage::COLOR_ATTACHMENT | ImageUsage::TRANSIENT_ATTACHMENT,
..ImageViewCreateInfo::from_image(&intermediary_image) samples: SampleCount::Sample4,
..Default::default()
}, },
AllocationCreateInfo::default(),
)
.unwrap(),
) )
.unwrap(); .unwrap();
@@ -1148,7 +1217,7 @@ where
image.clone(), image.clone(),
ImageViewCreateInfo { ImageViewCreateInfo {
usage: ImageUsage::COLOR_ATTACHMENT | ImageUsage::TRANSFER_DST, usage: ImageUsage::COLOR_ATTACHMENT | ImageUsage::TRANSFER_DST,
..ImageViewCreateInfo::from_image(&intermediary_image) ..ImageViewCreateInfo::from_image(&image)
}, },
) )
.unwrap(); .unwrap();
@@ -1163,34 +1232,56 @@ where
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let mesh_pipeline = GraphicsPipeline::start() let mesh_pipeline = {
.render_pass(Subpass::from(render_pass.clone(), 0).unwrap()) let vertex_input_state = OVertex::per_vertex();
.vertex_input_state(OVertex::per_vertex()) let stages = [
.input_assembly_state(InputAssemblyState::new()) PipelineShaderStageCreateInfo::new(mesh_vs.entry_point("main").unwrap()),
.vertex_shader(mesh_vs.entry_point("main").unwrap(), ()) PipelineShaderStageCreateInfo::new(mesh_fs.entry_point("main").unwrap()),
.viewport_state(ViewportState::viewport_fixed_scissor_irrelevant([ ];
Viewport { let subpass = Subpass::from(render_pass.clone(), 0).unwrap();
GraphicsPipeline::new(
device.clone(),
None,
GraphicsPipelineCreateInfo {
stages: stages.into_iter().collect(),
vertex_input_state: Some(vertex_input_state),
input_assembly_state: Some(InputAssemblyState::default()),
viewport_state: Some(ViewportState {
viewports: [Viewport {
offset: [0.0, 0.0], offset: [0.0, 0.0],
extent: [dimensions[0] as f32, dimensions[1] as f32], extent: window_size.into(),
depth_range: 0.0..1.0, depth_range: 0.0..=1.0,
}, }]
])) .into_iter()
.fragment_shader(mesh_fs.entry_point("main").unwrap(), ()) .collect(),
.depth_stencil_state(DepthStencilState::simple_depth_test()) ..Default::default()
.rasterization_state(RasterizationState { }),
front_face: Fixed(Clockwise), rasterization_state: Some(RasterizationState {
cull_mode: Fixed(CullMode::Back), front_face: Clockwise,
cull_mode: CullMode::Back,
..RasterizationState::default() ..RasterizationState::default()
}) }),
.multisample_state(MultisampleState { depth_stencil_state: Some(DepthStencilState {
depth: Some(DepthState::simple()),
..Default::default()
}),
multisample_state: Some(MultisampleState {
rasterization_samples: Subpass::from(render_pass.clone(), 0) rasterization_samples: Subpass::from(render_pass.clone(), 0)
.unwrap() .unwrap()
.num_samples() .num_samples()
.unwrap(), .unwrap(),
..Default::default() ..Default::default()
}) }),
.build(allocator.device().clone()) color_blend_state: Some(ColorBlendState::with_attachment_states(
.unwrap(); subpass.num_color_attachments(),
ColorBlendAttachmentState::default(),
)),
subpass: Some(subpass.into()),
..GraphicsPipelineCreateInfo::layout(layout)
},
)
};
println!("Recompiling implicit pipeline... (may take up to 10 minutes)"); println!("Recompiling implicit pipeline... (may take up to 10 minutes)");
@@ -1643,7 +1734,8 @@ fn object_size_dependent_setup(
allocator.clone(), allocator.clone(),
SubbufferAllocatorCreateInfo { SubbufferAllocatorCreateInfo {
buffer_usage: BufferUsage::TRANSFER_SRC, buffer_usage: BufferUsage::TRANSFER_SRC,
memory_type_filter: MemoryTypeFilter::PREFER_HOST | MemoryTypeFilter::HOST_SEQUENTIAL_WRITE, memory_type_filter: MemoryTypeFilter::PREFER_HOST
| MemoryTypeFilter::HOST_SEQUENTIAL_WRITE,
..Default::default() ..Default::default()
}, },
); );