--wip-- [skip ci]
This commit is contained in:
@@ -6,7 +6,7 @@ import sys
|
||||
import subprocess
|
||||
import re
|
||||
|
||||
TARGET_ENV = "vulkan1.3"
|
||||
TARGET_ENV = "vulkan1.4"
|
||||
SHADERS_OUT = "shaders_out"
|
||||
SHADERS_BASE = "shaders"
|
||||
SHADERS_INCLUDE = f"{SHADERS_BASE}/include"
|
||||
|
||||
@@ -64,12 +64,26 @@ struct Object {
|
||||
float sheen_tint;
|
||||
float clear_coat_gloss;
|
||||
float clear_coat;
|
||||
|
||||
// TRANSFORM
|
||||
uint transform_offset;
|
||||
};
|
||||
|
||||
layout(set = 0, binding = 4, std430) restrict readonly buffer Objects {
|
||||
Object objects[];
|
||||
} objects;
|
||||
|
||||
struct Transform {
|
||||
vec3 x;
|
||||
vec3 y;
|
||||
vec3 z;
|
||||
vec3 w;
|
||||
};
|
||||
|
||||
layout(set = 0, binding = 5, std430) restrict readonly buffer Transforms {
|
||||
Transform transforms[];
|
||||
} transforms;
|
||||
|
||||
struct TenTenTenTwo {
|
||||
uint data;
|
||||
};
|
||||
|
||||
@@ -22,12 +22,12 @@ void main() {
|
||||
|
||||
// interpolate with barycentric coordinates
|
||||
vec3 barys = vec3(1.0f - baryCoord.x - baryCoord.y, baryCoord.x, baryCoord.y);
|
||||
vec3 localNormal = normalize(v0.normal * barys.x + v1.normal * barys.y + v2.normal * barys.z).xyz;
|
||||
//vec3 localPosition = (v0.pos * barys.x + v1.pos * barys.y + v2.pos * barys.z).xyz;
|
||||
vec3 local_normal = normalize(v0.normal * barys.x + v1.normal * barys.y + v2.normal * barys.z).xyz;
|
||||
|
||||
// transform to world space
|
||||
vec3 normal = normalize((gl_ObjectToWorldEXT * vec4(localNormal, 1.0)).xyz);
|
||||
//vec3 position = gl_ObjectToWorldEXT * vec4(localPosition, 1.0);
|
||||
Transform t = transforms.transforms[obj.transform_offset];
|
||||
mat3 object_transform = mat3(t.x, t.y, t.z);
|
||||
vec3 normal = normalize((inverse(object_transform) * local_normal).xyz);
|
||||
|
||||
hit_value.normal = normal;
|
||||
hit_value.base_color = tttt_compress(obj.colour_and_roughness.xyz);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
layout(location = 0) rayPayloadEXT RTGBuffer hit_value;
|
||||
|
||||
layout(set = 1, binding = 0) uniform accelerationStructureEXT top_level_as;
|
||||
layout(set = 2, binding = 0, rgba32f) uniform image2D image;
|
||||
layout(set = 2, binding = 0) uniform writeonly image2D image;
|
||||
|
||||
vec3 shading(vec3 position, vec3 direction, vec3 base_color, vec3 normal, vec3 material1, vec3 material2, vec3 material3)
|
||||
{
|
||||
|
||||
@@ -130,20 +130,18 @@ pub(crate) fn gui_up(gui: &mut Gui, state: &mut GState) {
|
||||
let meshes_len = state.meshes.len();
|
||||
let csg_len = state.csg.len();
|
||||
let lights_len = state.lights.len();
|
||||
let allow_mesh_delete = meshes_len > 1 || csg_len > 0;
|
||||
let allow_csg_delete = meshes_len > 0 || csg_len > 1;
|
||||
ui.heading(format!("Meshes ({})", meshes_len));
|
||||
let mut meshdel = vec![false; meshes_len];
|
||||
for (i, mesh) in state.meshes.iter_mut().enumerate() {
|
||||
ui.collapsing(mesh.name.clone(), |ui| {
|
||||
if allow_mesh_delete {
|
||||
if meshes_len > 1 || csg_len > 0 {
|
||||
meshdel[i] = ui.small_button("remove mesh").clicked();
|
||||
}
|
||||
draw_position(ui, &mut mesh.position);
|
||||
draw_material(ui, &mut mesh.material);
|
||||
});
|
||||
}
|
||||
if allow_mesh_delete && ui.small_button("remove all meshes").clicked() {
|
||||
if csg_len > 0 && ui.small_button("remove all meshes").clicked() {
|
||||
for del in meshdel.iter_mut() {
|
||||
*del = true;
|
||||
}
|
||||
@@ -187,7 +185,7 @@ pub(crate) fn gui_up(gui: &mut Gui, state: &mut GState) {
|
||||
if state.csg.len() < 32 && ui.small_button("add all csgs").clicked() {
|
||||
state.new_csgs_needed = (32 - state.csg.len()) as u8;
|
||||
}
|
||||
if allow_csg_delete && ui.small_button("remove all csgs").clicked() {
|
||||
if meshes_len > 0 && ui.small_button("remove all csgs").clicked() {
|
||||
for del in csgdel.iter_mut() {
|
||||
*del = true;
|
||||
}
|
||||
|
||||
+141
-292
@@ -4,12 +4,13 @@
|
||||
|
||||
const DUMP_SPV_TO_FILE: bool = false;
|
||||
const PIPELINE_CACHING: bool = false;
|
||||
const IGNORE_STENCIL: bool = true;
|
||||
const VSYNC: bool = true;
|
||||
const COMPUTE_FUZZING: bool = false;
|
||||
const ROBUST: bool = false;
|
||||
const DUMP_AABBS: bool = false;
|
||||
|
||||
const CRASH_DIAGNOSTIC_LAYER: bool = true;
|
||||
|
||||
const DEFAULT_SUBDIVISION: u32 = 16;
|
||||
const MAXIMUM_SUBDIVISION: u32 = 64;
|
||||
const MINUMUM_SUBDIVISION: u32 = 8;
|
||||
@@ -64,16 +65,15 @@ use vulkano::{
|
||||
Device, DeviceCreateInfo, DeviceExtensions, DeviceFeatures, DeviceOwned, Queue,
|
||||
QueueCreateInfo, QueueFlags, physical::PhysicalDeviceType,
|
||||
},
|
||||
format::{Format, FormatFeatures},
|
||||
image::{
|
||||
Image, ImageAspects, ImageCreateInfo, ImageFormatInfo, ImageSubresourceRange, ImageType,
|
||||
ImageUsage, SampleCount,
|
||||
view::{ImageView, ImageViewCreateInfo},
|
||||
},
|
||||
instance::{Instance, InstanceCreateInfo, InstanceExtensions},
|
||||
memory::allocator::{
|
||||
AllocationCreateInfo, MemoryAllocator, MemoryTypeFilter, StandardMemoryAllocator,
|
||||
image::{Image, ImageFormatInfo, ImageUsage, SampleCount, view::ImageView},
|
||||
instance::{
|
||||
Instance, InstanceCreateInfo, InstanceExtensions,
|
||||
debug::{
|
||||
DebugUtilsMessageSeverity, DebugUtilsMessageType, DebugUtilsMessengerCallback,
|
||||
DebugUtilsMessengerCreateInfo,
|
||||
},
|
||||
},
|
||||
memory::allocator::{MemoryAllocator, MemoryTypeFilter, StandardMemoryAllocator},
|
||||
pipeline::{
|
||||
Pipeline, PipelineBindPoint, PipelineLayout, PipelineShaderStageCreateInfo,
|
||||
cache::{PipelineCache, PipelineCacheCreateInfo},
|
||||
@@ -85,7 +85,6 @@ use vulkano::{
|
||||
},
|
||||
},
|
||||
query::{QueryPool, QueryPoolCreateInfo, QueryResultFlags, QueryType},
|
||||
render_pass::{Framebuffer, FramebufferCreateInfo, RenderPass},
|
||||
shader::{ShaderModule, ShaderModuleCreateInfo, SpecializationConstant},
|
||||
swapchain::{
|
||||
PresentMode, Surface, SurfaceInfo, Swapchain, SwapchainCreateInfo, SwapchainPresentInfo,
|
||||
@@ -177,7 +176,6 @@ impl Default for CState {
|
||||
struct App {
|
||||
instance: Arc<Instance>,
|
||||
device: Arc<Device>,
|
||||
depth_format: Format,
|
||||
graphics_queue: Arc<Queue>,
|
||||
_transfer_queue: Arc<Queue>,
|
||||
compute_queue: Arc<Queue>,
|
||||
@@ -215,13 +213,7 @@ struct App {
|
||||
struct RenderContext {
|
||||
window: Arc<Window>,
|
||||
swapchain: Arc<Swapchain>,
|
||||
render_pass: Arc<RenderPass>,
|
||||
framebuffers: Vec<(Arc<ImageView>, Arc<Framebuffer>)>,
|
||||
color_buffer: Arc<ImageView>,
|
||||
material_buffer: Arc<ImageView>,
|
||||
ao_r_m_buffer: Arc<ImageView>,
|
||||
normal_buffer: Arc<ImageView>,
|
||||
depth_buffer: Arc<ImageView>,
|
||||
framebuffers: Vec<Arc<ImageView>>,
|
||||
camera_buffers: Vec<Subbuffer<enable_gen_cs::Camera>>,
|
||||
lights_buffers: Vec<Subbuffer<enable_gen_cs::Lights>>,
|
||||
shader_modules: Arc<RwLock<HashMap<String, Arc<ShaderModule>>>>,
|
||||
@@ -250,6 +242,44 @@ impl App {
|
||||
let library = VulkanLibrary::new().expect("Vulkan is not installed???");
|
||||
let required_extensions = Surface::required_extensions(event_loop).unwrap();
|
||||
|
||||
let mut debug_create_info = DebugUtilsMessengerCreateInfo::user_callback(unsafe {
|
||||
DebugUtilsMessengerCallback::new(|message_severity, message_type, callback_data| {
|
||||
let severity = if message_severity.intersects(DebugUtilsMessageSeverity::ERROR) {
|
||||
log::Level::Error
|
||||
} else if message_severity.intersects(DebugUtilsMessageSeverity::WARNING) {
|
||||
log::Level::Warn
|
||||
} else if message_severity.intersects(DebugUtilsMessageSeverity::INFO) {
|
||||
log::Level::Info
|
||||
} else if message_severity.intersects(DebugUtilsMessageSeverity::VERBOSE) {
|
||||
log::Level::Debug
|
||||
} else {
|
||||
unreachable!();
|
||||
};
|
||||
|
||||
let ty = if message_type.intersects(DebugUtilsMessageType::GENERAL) {
|
||||
"general"
|
||||
} else if message_type.intersects(DebugUtilsMessageType::VALIDATION) {
|
||||
"validation"
|
||||
} else if message_type.intersects(DebugUtilsMessageType::PERFORMANCE) {
|
||||
"performance"
|
||||
} else {
|
||||
unreachable!();
|
||||
};
|
||||
|
||||
log::log!(
|
||||
severity,
|
||||
"{} {}: {}",
|
||||
callback_data.message_id_name.unwrap_or("unknown"),
|
||||
ty,
|
||||
callback_data.message
|
||||
);
|
||||
})
|
||||
});
|
||||
|
||||
debug_create_info.message_severity |= DebugUtilsMessageSeverity::INFO;
|
||||
debug_create_info.message_type |=
|
||||
DebugUtilsMessageType::VALIDATION | DebugUtilsMessageType::PERFORMANCE;
|
||||
|
||||
let instance = Instance::new(
|
||||
library,
|
||||
InstanceCreateInfo {
|
||||
@@ -257,18 +287,29 @@ impl App {
|
||||
ext_swapchain_colorspace: true,
|
||||
khr_get_surface_capabilities2: true,
|
||||
ext_surface_maintenance1: true,
|
||||
ext_debug_utils: true,
|
||||
..required_extensions
|
||||
},
|
||||
enabled_layers: if CRASH_DIAGNOSTIC_LAYER {
|
||||
vec![
|
||||
"VK_LAYER_KHRONOS_validation".into(),
|
||||
"VK_LAYER_LUNARG_crash_diagnostic".into(),
|
||||
]
|
||||
} else {
|
||||
vec!["VK_LAYER_KHRONOS_validation".into()]
|
||||
},
|
||||
engine_name: Some("Tape Drive".to_owned()),
|
||||
engine_version: Version::major_minor(0, 1),
|
||||
application_name: Some(env!("CARGO_PKG_NAME").to_owned()),
|
||||
application_version: app_version(),
|
||||
max_api_version: Some(Version::V1_4),
|
||||
debug_utils_messengers: vec![debug_create_info],
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let device_extensions = DeviceExtensions {
|
||||
let mut device_extensions = DeviceExtensions {
|
||||
khr_swapchain: true,
|
||||
ext_swapchain_maintenance1: true,
|
||||
khr_ray_tracing_pipeline: true,
|
||||
@@ -283,7 +324,7 @@ impl App {
|
||||
..DeviceExtensions::empty()
|
||||
};
|
||||
|
||||
let device_features = DeviceFeatures {
|
||||
let mut device_features = DeviceFeatures {
|
||||
// core
|
||||
shader_int16: true,
|
||||
shader_int64: true,
|
||||
@@ -304,6 +345,7 @@ impl App {
|
||||
descriptor_indexing: true,
|
||||
uniform_buffer_standard_layout: true,
|
||||
shader_subgroup_extended_types: true,
|
||||
shader_storage_image_write_without_format: true,
|
||||
separate_depth_stencil_layouts: true,
|
||||
host_query_reset: true,
|
||||
buffer_device_address: true,
|
||||
@@ -348,7 +390,7 @@ impl App {
|
||||
instance
|
||||
.enumerate_physical_devices()
|
||||
.unwrap()
|
||||
.filter(|p| p.api_version() >= Version::V1_3)
|
||||
.filter(|p| p.api_version() >= Version::V1_4)
|
||||
.filter(|p| {
|
||||
p.supported_extensions().contains(&device_extensions)
|
||||
&& p.supported_features().contains(&device_features)
|
||||
@@ -426,38 +468,6 @@ impl App {
|
||||
info!("Transfer queue index: {}", transfer_queue_index);
|
||||
info!("Compute queue index: {}", compute_queue_index);
|
||||
|
||||
const DEPTH_FORMAT_ORDERING: [Format; 4] = [
|
||||
Format::D24_UNORM_S8_UINT,
|
||||
Format::X8_D24_UNORM_PACK32,
|
||||
Format::D32_SFLOAT_S8_UINT,
|
||||
Format::D16_UNORM_S8_UINT,
|
||||
];
|
||||
|
||||
const DEPTH_FORMAT_ORDERING_IGNORE_STENCIL: [Format; 6] = [
|
||||
Format::D32_SFLOAT,
|
||||
Format::D24_UNORM_S8_UINT,
|
||||
Format::X8_D24_UNORM_PACK32,
|
||||
Format::D32_SFLOAT_S8_UINT,
|
||||
Format::D16_UNORM,
|
||||
Format::D16_UNORM_S8_UINT,
|
||||
];
|
||||
|
||||
let depth_format = *(if IGNORE_STENCIL {
|
||||
DEPTH_FORMAT_ORDERING_IGNORE_STENCIL.iter()
|
||||
} else {
|
||||
DEPTH_FORMAT_ORDERING.iter()
|
||||
})
|
||||
.find(|format| {
|
||||
physical_device
|
||||
.format_properties(**format)
|
||||
.unwrap()
|
||||
.optimal_tiling_features
|
||||
.contains(FormatFeatures::DEPTH_STENCIL_ATTACHMENT)
|
||||
})
|
||||
.expect("Could not find suitable depth format!");
|
||||
|
||||
info!("Using depth format {:?}", depth_format);
|
||||
|
||||
let mut queue_create_infos = vec![];
|
||||
if !queue_create_infos
|
||||
.iter()
|
||||
@@ -487,6 +497,66 @@ impl App {
|
||||
});
|
||||
}
|
||||
|
||||
if CRASH_DIAGNOSTIC_LAYER {
|
||||
device_extensions.ext_device_fault = true;
|
||||
device_extensions.ext_device_address_binding_report = true;
|
||||
device_features.device_fault = true;
|
||||
if physical_device
|
||||
.supported_extensions()
|
||||
.contains(&DeviceExtensions {
|
||||
amd_buffer_marker: true,
|
||||
..Default::default()
|
||||
})
|
||||
{
|
||||
device_extensions.amd_buffer_marker = true;
|
||||
}
|
||||
if physical_device
|
||||
.supported_extensions()
|
||||
.contains(&DeviceExtensions {
|
||||
amd_device_coherent_memory: true,
|
||||
..Default::default()
|
||||
})
|
||||
{
|
||||
device_extensions.amd_device_coherent_memory = true;
|
||||
}
|
||||
if physical_device
|
||||
.supported_extensions()
|
||||
.contains(&DeviceExtensions {
|
||||
nv_device_diagnostic_checkpoints: true,
|
||||
..Default::default()
|
||||
})
|
||||
{
|
||||
device_extensions.nv_device_diagnostic_checkpoints = true;
|
||||
}
|
||||
if physical_device
|
||||
.supported_features()
|
||||
.contains(&DeviceFeatures {
|
||||
device_coherent_memory: true,
|
||||
..Default::default()
|
||||
})
|
||||
{
|
||||
device_features.device_coherent_memory = true;
|
||||
}
|
||||
if physical_device
|
||||
.supported_features()
|
||||
.contains(&DeviceFeatures {
|
||||
device_fault_vendor_binary: true,
|
||||
..Default::default()
|
||||
})
|
||||
{
|
||||
device_features.device_fault_vendor_binary = true;
|
||||
}
|
||||
if physical_device
|
||||
.supported_features()
|
||||
.contains(&DeviceFeatures {
|
||||
report_address_binding: true,
|
||||
..Default::default()
|
||||
})
|
||||
{
|
||||
device_features.report_address_binding = true;
|
||||
}
|
||||
}
|
||||
|
||||
let (device, queues) = Device::new(
|
||||
physical_device,
|
||||
DeviceCreateInfo {
|
||||
@@ -686,7 +756,6 @@ impl App {
|
||||
App {
|
||||
instance,
|
||||
device,
|
||||
depth_format,
|
||||
graphics_queue,
|
||||
_transfer_queue: transfer_queue,
|
||||
compute_queue,
|
||||
@@ -866,83 +935,13 @@ impl ApplicationHandler for App {
|
||||
|
||||
let shader_modules = Arc::new(RwLock::new(shader_modules));
|
||||
|
||||
let render_pass = vulkano::ordered_passes_renderpass!(
|
||||
self.device.clone(),
|
||||
attachments: {
|
||||
final_color: {
|
||||
format: swapchain.image_format(),
|
||||
samples: 1,
|
||||
load_op: Clear,
|
||||
store_op: Store,
|
||||
},
|
||||
material: {
|
||||
format: Format::R16_UINT,
|
||||
samples: 1,
|
||||
load_op: Clear,
|
||||
store_op: DontCare,
|
||||
},
|
||||
color: {
|
||||
format: Format::A2B10G10R10_UNORM_PACK32,
|
||||
samples: 1,
|
||||
load_op: Clear,
|
||||
store_op: DontCare,
|
||||
},
|
||||
ao_r_m: {
|
||||
format: Format::A2B10G10R10_UNORM_PACK32,
|
||||
samples: 1,
|
||||
load_op: Clear,
|
||||
store_op: DontCare,
|
||||
},
|
||||
normals: {
|
||||
format: Format::R16G16B16A16_SFLOAT,
|
||||
samples: 1,
|
||||
load_op: Clear,
|
||||
store_op: DontCare,
|
||||
},
|
||||
depth: {
|
||||
format: self.depth_format,
|
||||
samples: 1,
|
||||
load_op: Clear,
|
||||
store_op: DontCare,
|
||||
},
|
||||
},
|
||||
passes: [{
|
||||
color: [material],
|
||||
depth_stencil: {depth},
|
||||
input: [],
|
||||
},
|
||||
{
|
||||
color: [color, normals, ao_r_m],
|
||||
depth_stencil: {},
|
||||
input: [material, depth],
|
||||
},
|
||||
{
|
||||
color: [final_color],
|
||||
depth_stencil: {},
|
||||
input: [color, normals, ao_r_m, depth, material],
|
||||
}]
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let viewport = Viewport {
|
||||
offset: [0.0, window_size.height as f32],
|
||||
extent: [window_size.width as f32, -(window_size.height as f32)],
|
||||
depth_range: 0.0..=1.0,
|
||||
};
|
||||
|
||||
let (
|
||||
framebuffers,
|
||||
color_buffer,
|
||||
material_buffer,
|
||||
ao_r_m_buffer,
|
||||
normal_buffer,
|
||||
depth_buffer,
|
||||
) = framebuffer_generation(
|
||||
&images,
|
||||
&render_pass,
|
||||
&self.memory_allocator,
|
||||
self.depth_format,
|
||||
);
|
||||
let framebuffers = framebuffer_generation(&images);
|
||||
|
||||
let (rt_pipeline, rt_shader_binding_table) = pipeline_recompile(
|
||||
&self.memory_allocator,
|
||||
@@ -1012,16 +1011,14 @@ impl ApplicationHandler for App {
|
||||
query_create_info.query_count = 2;
|
||||
let time_query_pool = QueryPool::new(self.device.clone(), query_create_info).unwrap();
|
||||
|
||||
//unsafe {
|
||||
// time_query_pool.reset(0..2).unwrap();
|
||||
//}
|
||||
|
||||
*self.rcx.lock().unwrap() = Some(RenderContext {
|
||||
window,
|
||||
swapchain,
|
||||
render_pass,
|
||||
framebuffers,
|
||||
color_buffer,
|
||||
material_buffer,
|
||||
ao_r_m_buffer,
|
||||
normal_buffer,
|
||||
depth_buffer,
|
||||
camera_buffers,
|
||||
lights_buffers,
|
||||
shader_modules,
|
||||
@@ -1136,6 +1133,7 @@ impl ApplicationHandler for App {
|
||||
self.previous_debug,
|
||||
self.aabb_allocator.clone(),
|
||||
self.descriptor_set_allocator.clone(),
|
||||
self.transform_buffer_pointer.clone(),
|
||||
rcx.swapchain.image_count(),
|
||||
DEFAULT_SUBDIVISION,
|
||||
rand::random(),
|
||||
@@ -1281,6 +1279,7 @@ impl App {
|
||||
WriteDescriptorSet::buffer(2, self.vertex_buffer.clone()),
|
||||
WriteDescriptorSet::buffer(3, self.index_buffer.clone()),
|
||||
WriteDescriptorSet::buffer(4, self.object_buffer.clone()),
|
||||
WriteDescriptorSet::buffer(5, self.transform_buffer.clone()),
|
||||
],
|
||||
[],
|
||||
)
|
||||
@@ -1304,7 +1303,7 @@ impl App {
|
||||
rt_layout3.clone(),
|
||||
[WriteDescriptorSet::image_view(
|
||||
0,
|
||||
rcx.framebuffers[index].0.clone(),
|
||||
rcx.framebuffers[index].clone(),
|
||||
)],
|
||||
[],
|
||||
)
|
||||
@@ -1400,7 +1399,7 @@ impl App {
|
||||
.bind_pipeline_ray_tracing(rcx.rt_pipeline.clone())
|
||||
.unwrap();
|
||||
|
||||
let extent = rcx.framebuffers[0].0.image().extent();
|
||||
let extent = rcx.framebuffers[0].image().extent();
|
||||
|
||||
unsafe { builder.trace_rays(rcx.rt_shader_binding_table.addresses().clone(), extent) }
|
||||
.unwrap();
|
||||
@@ -1409,7 +1408,7 @@ impl App {
|
||||
fn handle_work_complete(&mut self, work: WorkComplete) {
|
||||
match work {
|
||||
WorkComplete::CreateCSG(csg, index) => {
|
||||
if index < 0 {
|
||||
if index < 0 || self.gstate.csg.len() <= index as usize {
|
||||
self.gstate.csg.push(csg);
|
||||
} else {
|
||||
self.gstate.csg[index as usize] = csg;
|
||||
@@ -1602,6 +1601,7 @@ impl App {
|
||||
self.previous_debug,
|
||||
self.aabb_allocator.clone(),
|
||||
self.descriptor_set_allocator.clone(),
|
||||
self.transform_buffer_pointer.clone(),
|
||||
rcx.swapchain.image_count(),
|
||||
DEFAULT_SUBDIVISION,
|
||||
rand::random(),
|
||||
@@ -1831,6 +1831,7 @@ impl App {
|
||||
self.previous_debug,
|
||||
self.aabb_allocator.clone(),
|
||||
self.descriptor_set_allocator.clone(),
|
||||
self.transform_buffer_pointer.clone(),
|
||||
rcx.swapchain.image_count(),
|
||||
DEFAULT_SUBDIVISION,
|
||||
rand::random(),
|
||||
@@ -1863,19 +1864,7 @@ impl App {
|
||||
.expect("Failed to recreate swapchain");
|
||||
|
||||
rcx.swapchain = new_swapchain;
|
||||
(
|
||||
rcx.framebuffers,
|
||||
rcx.color_buffer,
|
||||
rcx.material_buffer,
|
||||
rcx.ao_r_m_buffer,
|
||||
rcx.normal_buffer,
|
||||
rcx.depth_buffer,
|
||||
) = framebuffer_generation(
|
||||
&new_images,
|
||||
&rcx.render_pass,
|
||||
&self.memory_allocator,
|
||||
self.depth_format,
|
||||
);
|
||||
rcx.framebuffers = framebuffer_generation(&new_images);
|
||||
|
||||
rcx.viewport.extent[0] = window_size.width as f32;
|
||||
rcx.viewport.extent[1] = -(window_size.height as f32);
|
||||
@@ -2014,7 +2003,7 @@ impl App {
|
||||
|
||||
let future = if self.draw_gui {
|
||||
rcx.gui
|
||||
.draw_on_image(future, rcx.framebuffers[image_index].0.clone())
|
||||
.draw_on_image(future, rcx.framebuffers[image_index].clone())
|
||||
} else {
|
||||
future.boxed()
|
||||
};
|
||||
@@ -2089,153 +2078,13 @@ impl App {
|
||||
|
||||
/// This method is called once during initialization, then again whenever the
|
||||
/// window is resized
|
||||
fn framebuffer_generation(
|
||||
images: &[Arc<Image>],
|
||||
render_pass: &Arc<RenderPass>,
|
||||
allocator: &Arc<dyn MemoryAllocator>,
|
||||
depth_format: Format,
|
||||
) -> (
|
||||
Vec<(Arc<ImageView>, Arc<Framebuffer>)>,
|
||||
Arc<ImageView>,
|
||||
Arc<ImageView>,
|
||||
Arc<ImageView>,
|
||||
Arc<ImageView>,
|
||||
Arc<ImageView>,
|
||||
) {
|
||||
let depth_buffer = Image::new(
|
||||
allocator.clone(),
|
||||
ImageCreateInfo {
|
||||
image_type: ImageType::Dim2d,
|
||||
format: depth_format,
|
||||
extent: images[0].extent(),
|
||||
usage: ImageUsage::DEPTH_STENCIL_ATTACHMENT
|
||||
| ImageUsage::INPUT_ATTACHMENT
|
||||
| ImageUsage::TRANSIENT_ATTACHMENT,
|
||||
..Default::default()
|
||||
},
|
||||
AllocationCreateInfo::default(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let depth_buffer_ds = ImageView::new_default(depth_buffer.clone()).unwrap();
|
||||
let depth_buffer_d = ImageView::new(
|
||||
depth_buffer.clone(),
|
||||
ImageViewCreateInfo {
|
||||
subresource_range: ImageSubresourceRange {
|
||||
aspects: ImageAspects::DEPTH,
|
||||
mip_levels: 0..1,
|
||||
array_layers: 0..1,
|
||||
},
|
||||
..ImageViewCreateInfo::from_image(&depth_buffer.clone())
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let color_buffer = ImageView::new_default(
|
||||
Image::new(
|
||||
allocator.clone(),
|
||||
ImageCreateInfo {
|
||||
image_type: ImageType::Dim2d,
|
||||
format: Format::A2B10G10R10_UNORM_PACK32,
|
||||
extent: images[0].extent(),
|
||||
usage: ImageUsage::COLOR_ATTACHMENT
|
||||
| ImageUsage::INPUT_ATTACHMENT
|
||||
| ImageUsage::TRANSIENT_ATTACHMENT,
|
||||
..Default::default()
|
||||
},
|
||||
AllocationCreateInfo::default(),
|
||||
)
|
||||
.unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let material_buffer = ImageView::new_default(
|
||||
Image::new(
|
||||
allocator.clone(),
|
||||
ImageCreateInfo {
|
||||
image_type: ImageType::Dim2d,
|
||||
format: Format::R16_UINT,
|
||||
extent: images[0].extent(),
|
||||
usage: ImageUsage::COLOR_ATTACHMENT
|
||||
| ImageUsage::INPUT_ATTACHMENT
|
||||
| ImageUsage::TRANSIENT_ATTACHMENT,
|
||||
..Default::default()
|
||||
},
|
||||
AllocationCreateInfo::default(),
|
||||
)
|
||||
.unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let ao_r_m_buffer = ImageView::new_default(
|
||||
Image::new(
|
||||
allocator.clone(),
|
||||
ImageCreateInfo {
|
||||
image_type: ImageType::Dim2d,
|
||||
format: Format::A2B10G10R10_UNORM_PACK32,
|
||||
extent: images[0].extent(),
|
||||
usage: ImageUsage::COLOR_ATTACHMENT
|
||||
| ImageUsage::INPUT_ATTACHMENT
|
||||
| ImageUsage::TRANSIENT_ATTACHMENT,
|
||||
..Default::default()
|
||||
},
|
||||
AllocationCreateInfo::default(),
|
||||
)
|
||||
.unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let normal_buffer = ImageView::new_default(
|
||||
Image::new(
|
||||
allocator.clone(),
|
||||
ImageCreateInfo {
|
||||
image_type: ImageType::Dim2d,
|
||||
format: Format::R16G16B16A16_SFLOAT,
|
||||
extent: images[0].extent(),
|
||||
usage: ImageUsage::COLOR_ATTACHMENT
|
||||
| ImageUsage::INPUT_ATTACHMENT
|
||||
| ImageUsage::TRANSIENT_ATTACHMENT,
|
||||
..Default::default()
|
||||
},
|
||||
AllocationCreateInfo::default(),
|
||||
)
|
||||
.unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
fn framebuffer_generation(images: &[Arc<Image>]) -> Vec<Arc<ImageView>> {
|
||||
let framebuffers = images
|
||||
.iter()
|
||||
.map(|image| {
|
||||
let image_view = ImageView::new_default(image.clone()).unwrap();
|
||||
|
||||
let framebuffer = Framebuffer::new(
|
||||
render_pass.clone(),
|
||||
FramebufferCreateInfo {
|
||||
attachments: vec![
|
||||
image_view.clone(),
|
||||
material_buffer.clone(),
|
||||
color_buffer.clone(),
|
||||
ao_r_m_buffer.clone(),
|
||||
normal_buffer.clone(),
|
||||
depth_buffer_ds.clone(),
|
||||
],
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
(image_view, framebuffer)
|
||||
})
|
||||
.map(|image| ImageView::new_default(image.clone()).unwrap())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
(
|
||||
framebuffers,
|
||||
color_buffer,
|
||||
material_buffer,
|
||||
ao_r_m_buffer,
|
||||
normal_buffer,
|
||||
depth_buffer_d,
|
||||
)
|
||||
framebuffers
|
||||
}
|
||||
|
||||
fn get_spec_constants(debug: &PreviousDebug) -> HashMap<u32, SpecializationConstant> {
|
||||
|
||||
@@ -18,7 +18,7 @@ use vulkano::{
|
||||
shader::ShaderModule,
|
||||
};
|
||||
|
||||
use crate::ssa::SSATape;
|
||||
use crate::{MAX_INDEX_BUFFER, MAX_TRANSFORM_BUFFER, MAX_VERTEX_BUFFER, ssa::SSATape};
|
||||
|
||||
pub(crate) const PLATONIC_SOLIDS: [(&str, &[u8]); 1] =
|
||||
[("Buny", include_bytes!("../data/bunny.obj"))];
|
||||
@@ -169,10 +169,12 @@ pub(crate) fn load_obj(
|
||||
|
||||
let vertex_offset =
|
||||
vertex_buffer_pointer.fetch_add(vertices.len() as u64, Ordering::Relaxed) as usize;
|
||||
assert!(vertex_offset + vertices.len() <= MAX_VERTEX_BUFFER as usize);
|
||||
let index_offset =
|
||||
index_buffer_pointer.fetch_add(indices.len() as u64, Ordering::Relaxed) as usize;
|
||||
assert!(index_offset + indices.len() <= MAX_INDEX_BUFFER as usize);
|
||||
let transform_offset = transform_buffer_pointer.fetch_add(1, Ordering::Relaxed) as usize;
|
||||
|
||||
assert!(transform_offset + 1 <= MAX_TRANSFORM_BUFFER as usize);
|
||||
{
|
||||
let mut write = vertex_buffer.write().unwrap();
|
||||
write[vertex_offset..(vertex_offset + vertices.len())].copy_from_slice(&vertices);
|
||||
|
||||
@@ -175,6 +175,7 @@ fn upload_mesh_data(
|
||||
sheen_tint: mesh.material.sheen_tint,
|
||||
clear_coat_gloss: mesh.material.clear_coat_gloss,
|
||||
clear_coat: mesh.material.clear_coat,
|
||||
transform_offset: mesh.position.transform_offset as u32,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
@@ -209,6 +210,7 @@ fn upload_csg_data(
|
||||
sheen_tint: csg.material.sheen_tint,
|
||||
clear_coat_gloss: csg.material.clear_coat_gloss,
|
||||
clear_coat: csg.material.clear_coat,
|
||||
transform_offset: csg.position.transform_offset as u32,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
|
||||
@@ -2,7 +2,11 @@ use std::{
|
||||
fs::File,
|
||||
io::Write,
|
||||
simd::StdFloat,
|
||||
sync::{Arc, Mutex, RwLock, mpmc, mpsc},
|
||||
sync::{
|
||||
Arc, Mutex, RwLock,
|
||||
atomic::{AtomicU64, Ordering},
|
||||
mpmc, mpsc,
|
||||
},
|
||||
time::Instant,
|
||||
};
|
||||
|
||||
@@ -25,10 +29,10 @@ use vulkano::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
DUMP_SPV_TO_FILE, MAXIMUM_SUBDIVISION, get_spec_constants,
|
||||
DUMP_SPV_TO_FILE, MAX_TRANSFORM_BUFFER, MAXIMUM_SUBDIVISION, get_spec_constants,
|
||||
gui::PreviousDebug,
|
||||
interpreters::point::PointInterpreter,
|
||||
objects::CSG,
|
||||
objects::{CSG, Position},
|
||||
ssa::{SSAInput, SSAOpcode, SSAOpcodeSized, SSATape},
|
||||
};
|
||||
|
||||
@@ -41,6 +45,7 @@ pub enum WorkItem {
|
||||
PreviousDebug,
|
||||
Arc<Mutex<SubbufferAllocator>>,
|
||||
Arc<dyn DescriptorSetAllocator>,
|
||||
Arc<AtomicU64>,
|
||||
u32,
|
||||
u32,
|
||||
u64,
|
||||
@@ -79,6 +84,7 @@ pub fn thread_loop(recv: mpmc::Receiver<WorkItem>, send: mpsc::SyncSender<WorkCo
|
||||
debug,
|
||||
aabb_allocator,
|
||||
descriptor_set_allocator,
|
||||
transform_buffer_pointer,
|
||||
frames,
|
||||
subdivision,
|
||||
seed,
|
||||
@@ -130,11 +136,18 @@ pub fn thread_loop(recv: mpmc::Receiver<WorkItem>, send: mpsc::SyncSender<WorkCo
|
||||
})
|
||||
.collect();
|
||||
|
||||
let transform_offset =
|
||||
transform_buffer_pointer.fetch_add(1, Ordering::Relaxed) as usize;
|
||||
assert!(transform_offset + 1 <= MAX_TRANSFORM_BUFFER as usize);
|
||||
|
||||
let csg = Arc::new(RwLock::new(CSG {
|
||||
name: format!("example {}", rand::random::<u8>()),
|
||||
_seed: seed,
|
||||
parts,
|
||||
position: Default::default(),
|
||||
position: Position {
|
||||
transform_offset: transform_offset as _,
|
||||
..Default::default()
|
||||
},
|
||||
material: Default::default(),
|
||||
replacement_modules,
|
||||
fuzz_pipeline,
|
||||
|
||||
Reference in New Issue
Block a user