Compare commits
2 Commits
df92cf4517
...
45762855bc
| Author | SHA1 | Date | |
|---|---|---|---|
|
45762855bc
|
|||
|
0dd28f9bbd
|
@@ -13,6 +13,7 @@ layout(constant_id = 8) const bool SPEC_SHOW_MATERIAL3 = false;
|
||||
layout(constant_id = 9) const bool SPEC_SHOW_ALL = false;
|
||||
layout(constant_id = 10) const bool SPEC_DISABLE_AO = false;
|
||||
layout(constant_id = 11) const bool SPEC_USE_LINEAR_AO = false;
|
||||
layout(constant_id = 12) const bool SPEC_USE_SPATIAL_TEXTURE = false;
|
||||
|
||||
layout(set = 0, binding = 0) uniform Lights {
|
||||
vec4[32] pos;
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
#version 460
|
||||
#extension GL_GOOGLE_include_directive:require
|
||||
#include "implicit_include.glsl"
|
||||
|
||||
uniform layout(set = 1, binding = 0, r16f) writeonly image3D spatial_texture;
|
||||
|
||||
layout(push_constant, std430) uniform PushConstantData {
|
||||
uint object_index;
|
||||
} pc;
|
||||
|
||||
layout(local_size_x = 8, local_size_y = 8, local_size_z = 8) in;
|
||||
|
||||
const float NAN = 0.0 / 0.0;
|
||||
|
||||
Object object;
|
||||
|
||||
void main() {
|
||||
if (!SPEC_USE_SPATIAL_TEXTURE) {
|
||||
return;
|
||||
}
|
||||
|
||||
object = objects.objects[pc.object_index];
|
||||
|
||||
vec3 internal_pos = vec3(gl_GlobalInvocationID);
|
||||
vec3 mid_point = (((internal_pos + 0.5) / 32.0)
|
||||
* object.dimensions) + object.lowest_corner;
|
||||
|
||||
float s = scene(
|
||||
vec4(mid_point, camera_uniforms.campos_and_time.w)
|
||||
);
|
||||
|
||||
imageStore(spatial_texture, ivec3(gl_GlobalInvocationID), vec4(s, 0, 0, 0));
|
||||
}
|
||||
@@ -1,9 +1,15 @@
|
||||
#version 460
|
||||
#extension GL_EXT_ray_tracing : require
|
||||
#extension GL_GOOGLE_include_directive:require
|
||||
|
||||
#include "include.glsl"
|
||||
|
||||
uniform layout(set = 3, binding = 0) sampler3D spatial_texture;
|
||||
|
||||
#include "implicit_include.glsl"
|
||||
|
||||
Object object;
|
||||
|
||||
const float EPSILON = .001;
|
||||
|
||||
const uint MAX_STEPS = 50;
|
||||
@@ -23,8 +29,13 @@ vec2 box_intersection(in vec3 ro, in vec3 rd, vec3 box_size)
|
||||
return vec2(tN, tF);
|
||||
}
|
||||
|
||||
float spatial_scene(vec3 p) {
|
||||
vec3 actual = (p - object.lowest_corner) / object.dimensions;
|
||||
return texture(spatial_texture, actual).x;
|
||||
}
|
||||
|
||||
void main() {
|
||||
Object object = objects.objects[gl_InstanceID];
|
||||
object = objects.objects[gl_InstanceID];
|
||||
|
||||
vec3 internal_pos = vec3(
|
||||
float((gl_PrimitiveID >> (object.subdivision_log2 * 2)) & ((1 << object.subdivision_log2) - 1))
|
||||
@@ -63,7 +74,7 @@ void main() {
|
||||
float total_dist = near_plane;
|
||||
vec3 p = fma(raydir, vec3(total_dist), raypos);
|
||||
for (uint i = 0; i < MAX_STEPS; i++) {
|
||||
float dist = scene(vec4(p, camera_uniforms.campos_and_time.w));
|
||||
float dist = SPEC_USE_SPATIAL_TEXTURE ? spatial_scene(p) : scene(vec4(p, camera_uniforms.campos_and_time.w));
|
||||
total_dist += dist;
|
||||
p = fma(raydir, vec3(total_dist), raypos);
|
||||
if (abs(dist) < EPSILON) {
|
||||
|
||||
+17
-12
@@ -15,18 +15,19 @@ fn sized_text(ui: &mut egui::Ui, text: impl Into<String>, size: f32) {
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
|
||||
pub(crate) struct PreviousDebug {
|
||||
pub(crate) bounding_boxes: bool,
|
||||
pub(crate) brute_force: bool,
|
||||
pub(crate) show_normals: bool,
|
||||
pub(crate) show_depth: bool,
|
||||
pub(crate) show_position: bool,
|
||||
pub(crate) show_albedo: bool,
|
||||
pub(crate) show_material1: bool,
|
||||
pub(crate) show_material2: bool,
|
||||
pub(crate) show_material3: bool,
|
||||
pub(crate) show_all: bool,
|
||||
pub(crate) disable_ao: bool,
|
||||
pub(crate) use_linear_ao: bool,
|
||||
pub(crate) bounding_boxes: bool,
|
||||
pub(crate) brute_force: bool,
|
||||
pub(crate) show_normals: bool,
|
||||
pub(crate) show_depth: bool,
|
||||
pub(crate) show_position: bool,
|
||||
pub(crate) show_albedo: bool,
|
||||
pub(crate) show_material1: bool,
|
||||
pub(crate) show_material2: bool,
|
||||
pub(crate) show_material3: bool,
|
||||
pub(crate) show_all: bool,
|
||||
pub(crate) disable_ao: bool,
|
||||
pub(crate) use_linear_ao: bool,
|
||||
pub(crate) use_spatial_textures: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -345,6 +346,10 @@ pub(crate) fn gui_up(gui: &mut Gui, state: &mut GState) {
|
||||
&mut state.debug.use_linear_ao,
|
||||
"Use linear falloff for occlusion calculation",
|
||||
);
|
||||
ui.toggle_value(
|
||||
&mut state.debug.use_spatial_textures,
|
||||
"Use spatial textures rather than tracing directly to the surface",
|
||||
);
|
||||
|
||||
state.recreate_pipelines = ui.button("Force recompile pipelines").clicked();
|
||||
state.reset_time = ui.button("Reset time to 0").clicked();
|
||||
|
||||
+152
-13
@@ -7,6 +7,7 @@ const VSYNC: bool = true;
|
||||
const COMPUTE_FUZZING: bool = false;
|
||||
const ROBUST: bool = false;
|
||||
const DUMP_AABBS: bool = false;
|
||||
const DUMP_SPATIAL_TEXTURES: bool = false;
|
||||
|
||||
const DEFAULT_SUBDIVISION: u32 = 16;
|
||||
const MAXIMUM_SUBDIVISION: u32 = 64;
|
||||
@@ -62,7 +63,11 @@ use vulkano::{
|
||||
Device, DeviceCreateInfo, DeviceExtensions, DeviceFeatures, DeviceOwned, Queue,
|
||||
QueueCreateInfo, QueueFlags, physical::PhysicalDeviceType,
|
||||
},
|
||||
image::{Image, ImageFormatInfo, ImageUsage, SampleCount, view::ImageView},
|
||||
image::{
|
||||
Image, ImageFormatInfo, ImageUsage, SampleCount,
|
||||
sampler::{Filter, Sampler, SamplerAddressMode, SamplerCreateInfo},
|
||||
view::ImageView,
|
||||
},
|
||||
instance::{
|
||||
Instance, InstanceCreateInfo, InstanceExtensions,
|
||||
debug::{
|
||||
@@ -91,6 +96,8 @@ use vulkano::{
|
||||
self, AccessConflict, GpuFuture, HostAccessError, PipelineStage, future::FenceSignalFuture,
|
||||
},
|
||||
};
|
||||
#[cfg(target_family = "unix")]
|
||||
use winit::platform::{wayland::EventLoopBuilderExtWayland, x11::EventLoopBuilderExtX11};
|
||||
use winit::{
|
||||
application::ApplicationHandler,
|
||||
event::{DeviceEvent, ElementState, MouseButton, WindowEvent},
|
||||
@@ -155,6 +162,9 @@ fn main() -> Result<(), impl Error> {
|
||||
// force args to be handled
|
||||
let _ = ARGS.cdl;
|
||||
|
||||
#[cfg(target_family = "unix")]
|
||||
let event_loop = EventLoop::builder().with_x11().build().unwrap();
|
||||
#[cfg(not(target_family = "unix"))]
|
||||
let event_loop = EventLoop::builder().build().unwrap();
|
||||
let mut app = App::new(&event_loop);
|
||||
|
||||
@@ -211,6 +221,7 @@ struct App {
|
||||
transform_buffer: Subbuffer<[[[f32; 4]; 3]]>,
|
||||
transform_buffer_pointer: Arc<AtomicU64>,
|
||||
pipeline_cache: Arc<PipelineCache>,
|
||||
spatial_texture_sampler: Arc<Sampler>,
|
||||
recreate_pipelines: bool,
|
||||
draw_gui: bool,
|
||||
gstate: GState,
|
||||
@@ -716,12 +727,24 @@ impl App {
|
||||
}
|
||||
|
||||
define_replacement_module!("enable_gen.comp");
|
||||
define_replacement_module!("spatial_texture.comp");
|
||||
define_replacement_module!("fuzz.comp");
|
||||
define_replacement_module!("normals.rchit");
|
||||
define_replacement_module!("trace.rint");
|
||||
|
||||
let replacement_modules = Arc::new(RwLock::new(replacement_modules));
|
||||
|
||||
let spatial_texture_sampler = Sampler::new(
|
||||
device.clone(),
|
||||
SamplerCreateInfo {
|
||||
mag_filter: Filter::Linear,
|
||||
min_filter: Filter::Linear,
|
||||
address_mode: [SamplerAddressMode::ClampToEdge; 3],
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let (thread_work_creation_sender, thread_work_creation_receiver) =
|
||||
mpmc::sync_channel::<WorkItem>(256);
|
||||
let (thread_work_completion_sender, thread_work_completion_receiver) =
|
||||
@@ -791,6 +814,7 @@ impl App {
|
||||
index_buffer_pointer,
|
||||
transform_buffer_pointer,
|
||||
pipeline_cache,
|
||||
spatial_texture_sampler,
|
||||
csg_count: gstate.csg.len(),
|
||||
recreate_pipelines: false,
|
||||
draw_gui: true,
|
||||
@@ -819,6 +843,15 @@ mod enable_gen_cs {
|
||||
}
|
||||
}
|
||||
|
||||
mod spatial_texture_cs {
|
||||
vulkano_shaders::shader! {
|
||||
bytes: "shaders_out/replacement/spatial_texture.comp.glsl.spv",
|
||||
vulkan_version: "1.3",
|
||||
spirv_version: "1.6",
|
||||
custom_derives: [Debug, Clone, Copy, Default],
|
||||
}
|
||||
}
|
||||
|
||||
mod fuzz_cs {
|
||||
vulkano_shaders::shader! {
|
||||
bytes: "shaders_out/replacement/fuzz.comp.glsl.spv",
|
||||
@@ -1153,6 +1186,7 @@ impl ApplicationHandler for App {
|
||||
self.replacement_modules.clone(),
|
||||
self.pipeline_cache.clone(),
|
||||
self.previous_debug,
|
||||
self.memory_allocator.clone(),
|
||||
self.aabb_allocator.clone(),
|
||||
self.descriptor_set_allocator.clone(),
|
||||
self.transform_buffer_pointer.clone(),
|
||||
@@ -1285,7 +1319,12 @@ impl App {
|
||||
&self,
|
||||
rcx: &mut RenderContext,
|
||||
index: usize,
|
||||
) -> (Arc<DescriptorSet>, Arc<DescriptorSet>, Arc<DescriptorSet>) {
|
||||
) -> (
|
||||
Arc<DescriptorSet>,
|
||||
Arc<DescriptorSet>,
|
||||
Arc<DescriptorSet>,
|
||||
Arc<DescriptorSet>,
|
||||
) {
|
||||
let rt_layout1 = &rcx.rt_pipeline.layout().set_layouts()[0];
|
||||
let rt_set1 = DescriptorSet::new(
|
||||
self.descriptor_set_allocator.clone(),
|
||||
@@ -1326,7 +1365,20 @@ impl App {
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
(rt_set1, rt_set2, rt_set3)
|
||||
let rt_layout4 = &rcx.rt_pipeline.layout().set_layouts()[3];
|
||||
let rt_set4 = DescriptorSet::new(
|
||||
self.descriptor_set_allocator.clone(),
|
||||
rt_layout4.clone(),
|
||||
[WriteDescriptorSet::image_view_sampler(
|
||||
0,
|
||||
self.gstate.csg[0].read().unwrap().spatial_texture[index].clone(),
|
||||
self.spatial_texture_sampler.clone(),
|
||||
)],
|
||||
[],
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
(rt_set1, rt_set2, rt_set3, rt_set4)
|
||||
}
|
||||
|
||||
fn get_enable_gen_descriptor_sets(
|
||||
@@ -1367,7 +1419,7 @@ impl App {
|
||||
) {
|
||||
for (i, csg) in self.gstate.csg.iter().enumerate() {
|
||||
let csg = csg.read().unwrap();
|
||||
if csg.state == objects::State::Running {
|
||||
if csg.state == objects::State::Running || csg.blas == None {
|
||||
builder
|
||||
.bind_pipeline_compute(csg.enable_gen_pipeline.clone())
|
||||
.unwrap()
|
||||
@@ -1406,6 +1458,76 @@ impl App {
|
||||
}
|
||||
}
|
||||
|
||||
fn get_spatial_texture_descriptor_sets(
|
||||
&self,
|
||||
rcx: &mut RenderContext,
|
||||
index: usize,
|
||||
) -> Option<Arc<DescriptorSet>> {
|
||||
let spatial_texture_set1 = if self.csg_count > 0 {
|
||||
let spatial_texture_layout = &self.gstate.csg[0]
|
||||
.read()
|
||||
.unwrap()
|
||||
.spatial_texture_pipeline
|
||||
.layout()
|
||||
.set_layouts()[0]
|
||||
.clone();
|
||||
let spatial_texture_set = DescriptorSet::new(
|
||||
self.descriptor_set_allocator.clone(),
|
||||
spatial_texture_layout.clone(),
|
||||
[
|
||||
WriteDescriptorSet::buffer(1, rcx.camera_buffers[index].clone()),
|
||||
WriteDescriptorSet::buffer(4, self.object_buffer.clone()),
|
||||
],
|
||||
[],
|
||||
)
|
||||
.unwrap();
|
||||
Some(spatial_texture_set)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
spatial_texture_set1
|
||||
}
|
||||
|
||||
fn add_commands_spatial_texture(
|
||||
&self,
|
||||
builder: &mut AutoCommandBufferBuilder<PrimaryAutoCommandBuffer>,
|
||||
spatial_texture_set: Arc<DescriptorSet>,
|
||||
frame_index: usize,
|
||||
) {
|
||||
for (i, csg) in self.gstate.csg.iter().enumerate() {
|
||||
let csg = csg.read().unwrap();
|
||||
if csg.state == objects::State::Running || csg.blas == None {
|
||||
builder
|
||||
.bind_pipeline_compute(csg.spatial_texture_pipeline.clone())
|
||||
.unwrap()
|
||||
.bind_descriptor_sets(
|
||||
PipelineBindPoint::Compute,
|
||||
csg.spatial_texture_pipeline.layout().clone(),
|
||||
0,
|
||||
vec![
|
||||
spatial_texture_set.clone(),
|
||||
csg.spatial_texture_descriptor_set[frame_index].clone(),
|
||||
],
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
builder
|
||||
.push_constants(
|
||||
csg.spatial_texture_pipeline.layout().clone(),
|
||||
0,
|
||||
spatial_texture_cs::PushConstantData {
|
||||
object_index: (self.gstate.meshes.len() + i) as u32,
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
debug_assert_eq!(csg.subdivision % 8, 0);
|
||||
|
||||
unsafe { builder.dispatch([32 / 8, 32 / 8, 32 / 8]) }.unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn add_commands_raytrace(
|
||||
&self,
|
||||
builder: &mut AutoCommandBufferBuilder<PrimaryAutoCommandBuffer>,
|
||||
@@ -1413,13 +1535,14 @@ impl App {
|
||||
rt_set1: Arc<DescriptorSet>,
|
||||
rt_set2: Arc<DescriptorSet>,
|
||||
rt_set3: Arc<DescriptorSet>,
|
||||
rt_set4: Arc<DescriptorSet>,
|
||||
) {
|
||||
builder
|
||||
.bind_descriptor_sets(
|
||||
PipelineBindPoint::RayTracing,
|
||||
rcx.rt_pipeline.layout().clone(),
|
||||
0,
|
||||
vec![rt_set1, rt_set2, rt_set3],
|
||||
vec![rt_set1, rt_set2, rt_set3, rt_set4],
|
||||
)
|
||||
.unwrap()
|
||||
.bind_pipeline_ray_tracing(rcx.rt_pipeline.clone())
|
||||
@@ -1625,6 +1748,7 @@ impl App {
|
||||
self.replacement_modules.clone(),
|
||||
self.pipeline_cache.clone(),
|
||||
self.previous_debug,
|
||||
self.memory_allocator.clone(),
|
||||
self.aabb_allocator.clone(),
|
||||
self.descriptor_set_allocator.clone(),
|
||||
self.transform_buffer_pointer.clone(),
|
||||
@@ -1855,6 +1979,7 @@ impl App {
|
||||
self.replacement_modules.clone(),
|
||||
self.pipeline_cache.clone(),
|
||||
self.previous_debug,
|
||||
self.memory_allocator.clone(),
|
||||
self.aabb_allocator.clone(),
|
||||
self.descriptor_set_allocator.clone(),
|
||||
self.transform_buffer_pointer.clone(),
|
||||
@@ -1924,7 +2049,8 @@ impl App {
|
||||
|
||||
let mut push_constants_left = 0;
|
||||
for (i, csg) in self.gstate.csg.iter().enumerate() {
|
||||
if csg.read().unwrap().state == objects::State::Running {
|
||||
let read = csg.read().unwrap();
|
||||
if read.state == objects::State::Running || read.blas == None {
|
||||
self.thread_work_creation
|
||||
.send(WorkItem::GetPushConstants(csg.clone(), self.time, i))
|
||||
.unwrap();
|
||||
@@ -1978,6 +2104,16 @@ impl App {
|
||||
self.add_commands_enable_gen(&mut builder, enable_gen_set1.unwrap(), image_index);
|
||||
}
|
||||
|
||||
let spatial_texture_set1 = self.get_spatial_texture_descriptor_sets(rcx, image_index);
|
||||
|
||||
if !self.gstate.csg.is_empty() {
|
||||
self.add_commands_spatial_texture(
|
||||
&mut builder,
|
||||
spatial_texture_set1.unwrap(),
|
||||
image_index,
|
||||
);
|
||||
}
|
||||
|
||||
rcx.scene[image_index] = Scene::new(
|
||||
&self.device,
|
||||
&mut builder,
|
||||
@@ -1991,9 +2127,12 @@ impl App {
|
||||
image_index,
|
||||
);
|
||||
|
||||
let (rt_set1, rt_set2, rt_set3) = self.get_rt_descriptor_sets(rcx, image_index);
|
||||
if !self.gstate.csg.is_empty() {
|
||||
let (rt_set1, rt_set2, rt_set3, rt_set4) =
|
||||
self.get_rt_descriptor_sets(rcx, image_index);
|
||||
|
||||
self.add_commands_raytrace(&mut builder, rcx, rt_set1, rt_set2, rt_set3);
|
||||
self.add_commands_raytrace(&mut builder, rcx, rt_set1, rt_set2, rt_set3, rt_set4);
|
||||
}
|
||||
|
||||
unsafe {
|
||||
builder
|
||||
@@ -2077,11 +2216,6 @@ impl App {
|
||||
}
|
||||
|
||||
if DUMP_AABBS {
|
||||
for future in rcx.previous_frame_end.iter_mut().flatten() {
|
||||
future.wait(None).unwrap();
|
||||
future.cleanup_finished();
|
||||
}
|
||||
|
||||
for csg in self.gstate.csg.iter() {
|
||||
let csg = csg.read().unwrap();
|
||||
let mut reader = csg.aabb_buffer[image_index].read();
|
||||
@@ -2131,6 +2265,7 @@ fn get_spec_constants(debug: &PreviousDebug) -> HashMap<u32, SpecializationConst
|
||||
const SPEC_SHOW_ALL: u32 = 9;
|
||||
const SPEC_DISABLE_AO: u32 = 10;
|
||||
const SPEC_USE_LINEAR_AO: u32 = 11;
|
||||
const SPEC_USE_SPATIAL_TEXTURE: u32 = 12;
|
||||
|
||||
let mut spec_constants = HashMap::with_capacity(6);
|
||||
spec_constants.insert(
|
||||
@@ -2178,6 +2313,10 @@ fn get_spec_constants(debug: &PreviousDebug) -> HashMap<u32, SpecializationConst
|
||||
SPEC_USE_LINEAR_AO,
|
||||
SpecializationConstant::Bool(debug.use_linear_ao),
|
||||
);
|
||||
spec_constants.insert(
|
||||
SPEC_USE_SPATIAL_TEXTURE,
|
||||
SpecializationConstant::Bool(debug.use_spatial_textures),
|
||||
);
|
||||
|
||||
trace!("Specs: {:?}", spec_constants);
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ use vulkano::{
|
||||
acceleration_structure::AccelerationStructure,
|
||||
buffer::Subbuffer,
|
||||
descriptor_set::DescriptorSet,
|
||||
image::view::ImageView,
|
||||
pipeline::{ComputePipeline, graphics::vertex_input::Vertex},
|
||||
shader::ShaderModule,
|
||||
};
|
||||
@@ -94,11 +95,14 @@ pub(crate) struct CSG {
|
||||
pub(crate) dimensions: Vec3,
|
||||
pub(crate) lowest_corner: Vec3,
|
||||
|
||||
pub(crate) replacement_modules: Arc<RwLock<HashMap<String, Arc<ShaderModule>>>>,
|
||||
pub(crate) fuzz_pipeline: Arc<ComputePipeline>,
|
||||
pub(crate) enable_gen_pipeline: Arc<ComputePipeline>,
|
||||
pub(crate) aabb_buffer: Vec<Subbuffer<[u8]>>,
|
||||
pub(crate) enable_gen_descriptor_set: Vec<Arc<DescriptorSet>>,
|
||||
pub(crate) replacement_modules: Arc<RwLock<HashMap<String, Arc<ShaderModule>>>>,
|
||||
pub(crate) fuzz_pipeline: Arc<ComputePipeline>,
|
||||
pub(crate) enable_gen_pipeline: Arc<ComputePipeline>,
|
||||
pub(crate) spatial_texture_pipeline: Arc<ComputePipeline>,
|
||||
pub(crate) aabb_buffer: Vec<Subbuffer<[u8]>>,
|
||||
pub(crate) enable_gen_descriptor_set: Vec<Arc<DescriptorSet>>,
|
||||
pub(crate) spatial_texture: Vec<Arc<ImageView>>,
|
||||
pub(crate) spatial_texture_descriptor_set: Vec<Arc<DescriptorSet>>,
|
||||
}
|
||||
|
||||
impl Default for Position {
|
||||
|
||||
@@ -20,6 +20,9 @@ use vulkano::{
|
||||
buffer::{Subbuffer, allocator::SubbufferAllocator},
|
||||
descriptor_set::{DescriptorSet, WriteDescriptorSet, allocator::DescriptorSetAllocator},
|
||||
device::Device,
|
||||
format::Format,
|
||||
image::{Image, ImageCreateFlags, ImageCreateInfo, ImageType, ImageUsage, view::ImageView},
|
||||
memory::allocator::{AllocationCreateInfo, MemoryAllocator},
|
||||
pipeline::{
|
||||
ComputePipeline, Pipeline, PipelineLayout, PipelineShaderStageCreateInfo,
|
||||
cache::PipelineCache, compute::ComputePipelineCreateInfo,
|
||||
@@ -43,6 +46,7 @@ pub enum WorkItem {
|
||||
Arc<RwLock<HashMap<String, Module>>>,
|
||||
Arc<PipelineCache>,
|
||||
PreviousDebug,
|
||||
Arc<dyn MemoryAllocator + 'static>,
|
||||
Arc<Mutex<SubbufferAllocator>>,
|
||||
Arc<dyn DescriptorSetAllocator>,
|
||||
Arc<AtomicU64>,
|
||||
@@ -82,6 +86,7 @@ pub fn thread_loop(recv: mpmc::Receiver<WorkItem>, send: mpsc::SyncSender<WorkCo
|
||||
replacement_modules,
|
||||
cache,
|
||||
debug,
|
||||
memory_allocator,
|
||||
aabb_allocator,
|
||||
descriptor_set_allocator,
|
||||
transform_buffer_pointer,
|
||||
@@ -103,7 +108,7 @@ pub fn thread_loop(recv: mpmc::Receiver<WorkItem>, send: mpsc::SyncSender<WorkCo
|
||||
|
||||
let replacement_modules = Arc::new(RwLock::new(new_replacement_modules));
|
||||
|
||||
let (fuzz_pipeline, enable_gen_pipeline) =
|
||||
let (fuzz_pipeline, enable_gen_pipeline, spatial_texture_pipeline) =
|
||||
deferred_pipelines_recompile(device, cache, replacement_modules.clone(), debug);
|
||||
|
||||
let aabb_buffer: Vec<Subbuffer<[u8]>> = (0..frames)
|
||||
@@ -136,12 +141,49 @@ pub fn thread_loop(recv: mpmc::Receiver<WorkItem>, send: mpsc::SyncSender<WorkCo
|
||||
})
|
||||
.collect();
|
||||
|
||||
let spatial_texture: Vec<Arc<ImageView>> = (0..frames)
|
||||
.map(|_| {
|
||||
let image = Image::new(
|
||||
memory_allocator.clone(),
|
||||
ImageCreateInfo {
|
||||
flags: ImageCreateFlags::empty(),
|
||||
image_type: ImageType::Dim3d,
|
||||
format: Format::R16_SFLOAT,
|
||||
view_formats: vec![Format::R16_SFLOAT],
|
||||
extent: [32, 32, 32],
|
||||
usage: ImageUsage::STORAGE | ImageUsage::SAMPLED,
|
||||
..Default::default()
|
||||
},
|
||||
AllocationCreateInfo::default(),
|
||||
)
|
||||
.unwrap();
|
||||
ImageView::new_default(image).unwrap()
|
||||
})
|
||||
.collect();
|
||||
|
||||
let spatial_texture_layout =
|
||||
spatial_texture_pipeline.layout().set_layouts()[1].clone();
|
||||
let spatial_texture_descriptor_set = (0..frames)
|
||||
.map(|f| {
|
||||
DescriptorSet::new(
|
||||
descriptor_set_allocator.clone(),
|
||||
spatial_texture_layout.clone(),
|
||||
[WriteDescriptorSet::image_view(
|
||||
0,
|
||||
spatial_texture[f as usize].clone(),
|
||||
)],
|
||||
[],
|
||||
)
|
||||
.unwrap()
|
||||
})
|
||||
.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>()),
|
||||
name: format!("example {}", rand::random::<u16>()),
|
||||
_seed: seed,
|
||||
parts,
|
||||
position: Position {
|
||||
@@ -152,9 +194,12 @@ pub fn thread_loop(recv: mpmc::Receiver<WorkItem>, send: mpsc::SyncSender<WorkCo
|
||||
replacement_modules,
|
||||
fuzz_pipeline,
|
||||
enable_gen_pipeline,
|
||||
spatial_texture_pipeline,
|
||||
subdivision,
|
||||
aabb_buffer,
|
||||
enable_gen_descriptor_set,
|
||||
spatial_texture,
|
||||
spatial_texture_descriptor_set,
|
||||
dimensions: Default::default(),
|
||||
lowest_corner: Default::default(),
|
||||
state: objects::State::Running,
|
||||
@@ -202,7 +247,11 @@ pub fn thread_loop(recv: mpmc::Receiver<WorkItem>, send: mpsc::SyncSender<WorkCo
|
||||
WorkItem::RecompilePipelines(csg, device, cache, debug, index) => {
|
||||
let csg_start = Instant::now();
|
||||
let mut csg = csg.write().unwrap();
|
||||
(csg.fuzz_pipeline, csg.enable_gen_pipeline) = deferred_pipelines_recompile(
|
||||
(
|
||||
csg.fuzz_pipeline,
|
||||
csg.enable_gen_pipeline,
|
||||
csg.spatial_texture_pipeline,
|
||||
) = deferred_pipelines_recompile(
|
||||
device,
|
||||
cache,
|
||||
csg.replacement_modules.clone(),
|
||||
@@ -227,7 +276,11 @@ fn deferred_pipelines_recompile(
|
||||
cache: Arc<PipelineCache>,
|
||||
replacement_modules: Arc<RwLock<HashMap<String, Arc<ShaderModule>>>>,
|
||||
debug: PreviousDebug,
|
||||
) -> (Arc<ComputePipeline>, Arc<ComputePipeline>) {
|
||||
) -> (
|
||||
Arc<ComputePipeline>,
|
||||
Arc<ComputePipeline>,
|
||||
Arc<ComputePipeline>,
|
||||
) {
|
||||
let specs = get_spec_constants(&debug);
|
||||
|
||||
let replacement_modules = replacement_modules.read().unwrap();
|
||||
@@ -281,7 +334,33 @@ fn deferred_pipelines_recompile(
|
||||
)
|
||||
.expect("failed to create enable_gen pipeline");
|
||||
|
||||
(fuzz_pipeline, enable_gen_pipeline)
|
||||
let spatial_texture_cs_info = PipelineShaderStageCreateInfo::new(
|
||||
replacement_modules["spatial_texture.comp"]
|
||||
.specialize(specs.clone())
|
||||
.unwrap()
|
||||
.single_entry_point()
|
||||
.unwrap(),
|
||||
);
|
||||
|
||||
let spatial_texture_pipeline_layout = PipelineLayout::new(
|
||||
device.clone(),
|
||||
PipelineDescriptorSetLayoutCreateInfo::from_stages([&spatial_texture_cs_info])
|
||||
.into_pipeline_layout_create_info(device.clone())
|
||||
.unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let spatial_texture_pipeline = ComputePipeline::new(
|
||||
device.clone(),
|
||||
Some(cache.clone()),
|
||||
ComputePipelineCreateInfo::stage_layout(
|
||||
spatial_texture_cs_info,
|
||||
spatial_texture_pipeline_layout.clone(),
|
||||
),
|
||||
)
|
||||
.expect("failed to create spatial_texture pipeline");
|
||||
|
||||
(fuzz_pipeline, enable_gen_pipeline, spatial_texture_pipeline)
|
||||
}
|
||||
|
||||
fn create_csg(seed: u64) -> SSATape {
|
||||
|
||||
Reference in New Issue
Block a user