Render from spatial texture

This commit is contained in:
2026-04-20 22:28:48 +01:00
parent df92cf4517
commit 0dd28f9bbd
6 changed files with 295 additions and 26 deletions
@@ -0,0 +1,11 @@
#ifndef implicit_spatial_tex_include
#define implicit_spatial_tex_include
uniform layout(set = 3, binding = 0) sampler3D spatial_texture;
float spatial_scene(vec3 p) {
vec3 actual = (p - object.lowest_corner) / object.dimensions;
return texture(spatial_texture, actual).x;
}
#endif
@@ -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_BRUTE_FORCE) {
return;
}
object = objects.objects[pc.object_index];
vec3 internal_pos = vec3(gl_GlobalInvocationID);
vec3 mid_point = (((internal_pos + 0.5) / 64.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,8 +1,12 @@
#version 460 #version 460
#extension GL_EXT_ray_tracing : require #extension GL_EXT_ray_tracing : require
#extension GL_GOOGLE_include_directive:require #extension GL_GOOGLE_include_directive:require
#include "include.glsl" #include "include.glsl"
#include "implicit_include.glsl" //#include "implicit_include.glsl"
Object object;
#include "implicit_spatial_tex.glsl"
const float EPSILON = .001; const float EPSILON = .001;
@@ -24,7 +28,7 @@ vec2 box_intersection(in vec3 ro, in vec3 rd, vec3 box_size)
} }
void main() { void main() {
Object object = objects.objects[gl_InstanceID]; object = objects.objects[gl_InstanceID];
vec3 internal_pos = vec3( vec3 internal_pos = vec3(
float((gl_PrimitiveID >> (object.subdivision_log2 * 2)) & ((1 << object.subdivision_log2) - 1)) float((gl_PrimitiveID >> (object.subdivision_log2 * 2)) & ((1 << object.subdivision_log2) - 1))
@@ -63,7 +67,7 @@ void main() {
float total_dist = near_plane; float total_dist = near_plane;
vec3 p = fma(raydir, vec3(total_dist), raypos); vec3 p = fma(raydir, vec3(total_dist), raypos);
for (uint i = 0; i < MAX_STEPS; i++) { for (uint i = 0; i < MAX_STEPS; i++) {
float dist = scene(vec4(p, camera_uniforms.campos_and_time.w)); float dist = spatial_scene(p);
total_dist += dist; total_dist += dist;
p = fma(raydir, vec3(total_dist), raypos); p = fma(raydir, vec3(total_dist), raypos);
if (abs(dist) < EPSILON) { if (abs(dist) < EPSILON) {
+147 -13
View File
@@ -7,6 +7,7 @@ const VSYNC: bool = true;
const COMPUTE_FUZZING: bool = false; const COMPUTE_FUZZING: bool = false;
const ROBUST: bool = false; const ROBUST: bool = false;
const DUMP_AABBS: bool = false; const DUMP_AABBS: bool = false;
const DUMP_SPATIAL_TEXTURES: bool = false;
const DEFAULT_SUBDIVISION: u32 = 16; const DEFAULT_SUBDIVISION: u32 = 16;
const MAXIMUM_SUBDIVISION: u32 = 64; const MAXIMUM_SUBDIVISION: u32 = 64;
@@ -62,7 +63,11 @@ use vulkano::{
Device, DeviceCreateInfo, DeviceExtensions, DeviceFeatures, DeviceOwned, Queue, Device, DeviceCreateInfo, DeviceExtensions, DeviceFeatures, DeviceOwned, Queue,
QueueCreateInfo, QueueFlags, physical::PhysicalDeviceType, 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::{
Instance, InstanceCreateInfo, InstanceExtensions, Instance, InstanceCreateInfo, InstanceExtensions,
debug::{ debug::{
@@ -91,6 +96,8 @@ use vulkano::{
self, AccessConflict, GpuFuture, HostAccessError, PipelineStage, future::FenceSignalFuture, self, AccessConflict, GpuFuture, HostAccessError, PipelineStage, future::FenceSignalFuture,
}, },
}; };
#[cfg(target_family = "unix")]
use winit::platform::{wayland::EventLoopBuilderExtWayland, x11::EventLoopBuilderExtX11};
use winit::{ use winit::{
application::ApplicationHandler, application::ApplicationHandler,
event::{DeviceEvent, ElementState, MouseButton, WindowEvent}, event::{DeviceEvent, ElementState, MouseButton, WindowEvent},
@@ -155,6 +162,9 @@ fn main() -> Result<(), impl Error> {
// force args to be handled // force args to be handled
let _ = ARGS.cdl; 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 event_loop = EventLoop::builder().build().unwrap();
let mut app = App::new(&event_loop); let mut app = App::new(&event_loop);
@@ -211,6 +221,7 @@ struct App {
transform_buffer: Subbuffer<[[[f32; 4]; 3]]>, transform_buffer: Subbuffer<[[[f32; 4]; 3]]>,
transform_buffer_pointer: Arc<AtomicU64>, transform_buffer_pointer: Arc<AtomicU64>,
pipeline_cache: Arc<PipelineCache>, pipeline_cache: Arc<PipelineCache>,
spatial_texture_sampler: Arc<Sampler>,
recreate_pipelines: bool, recreate_pipelines: bool,
draw_gui: bool, draw_gui: bool,
gstate: GState, gstate: GState,
@@ -716,12 +727,24 @@ impl App {
} }
define_replacement_module!("enable_gen.comp"); define_replacement_module!("enable_gen.comp");
define_replacement_module!("spatial_texture.comp");
define_replacement_module!("fuzz.comp"); define_replacement_module!("fuzz.comp");
define_replacement_module!("normals.rchit"); define_replacement_module!("normals.rchit");
define_replacement_module!("trace.rint"); define_replacement_module!("trace.rint");
let replacement_modules = Arc::new(RwLock::new(replacement_modules)); 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) = let (thread_work_creation_sender, thread_work_creation_receiver) =
mpmc::sync_channel::<WorkItem>(256); mpmc::sync_channel::<WorkItem>(256);
let (thread_work_completion_sender, thread_work_completion_receiver) = let (thread_work_completion_sender, thread_work_completion_receiver) =
@@ -791,6 +814,7 @@ impl App {
index_buffer_pointer, index_buffer_pointer,
transform_buffer_pointer, transform_buffer_pointer,
pipeline_cache, pipeline_cache,
spatial_texture_sampler,
csg_count: gstate.csg.len(), csg_count: gstate.csg.len(),
recreate_pipelines: false, recreate_pipelines: false,
draw_gui: true, 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 { mod fuzz_cs {
vulkano_shaders::shader! { vulkano_shaders::shader! {
bytes: "shaders_out/replacement/fuzz.comp.glsl.spv", bytes: "shaders_out/replacement/fuzz.comp.glsl.spv",
@@ -1153,6 +1186,7 @@ impl ApplicationHandler for App {
self.replacement_modules.clone(), self.replacement_modules.clone(),
self.pipeline_cache.clone(), self.pipeline_cache.clone(),
self.previous_debug, self.previous_debug,
self.memory_allocator.clone(),
self.aabb_allocator.clone(), self.aabb_allocator.clone(),
self.descriptor_set_allocator.clone(), self.descriptor_set_allocator.clone(),
self.transform_buffer_pointer.clone(), self.transform_buffer_pointer.clone(),
@@ -1285,7 +1319,12 @@ impl App {
&self, &self,
rcx: &mut RenderContext, rcx: &mut RenderContext,
index: usize, 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_layout1 = &rcx.rt_pipeline.layout().set_layouts()[0];
let rt_set1 = DescriptorSet::new( let rt_set1 = DescriptorSet::new(
self.descriptor_set_allocator.clone(), self.descriptor_set_allocator.clone(),
@@ -1326,7 +1365,20 @@ impl App {
) )
.unwrap(); .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( fn get_enable_gen_descriptor_sets(
@@ -1367,7 +1419,7 @@ impl App {
) { ) {
for (i, csg) in self.gstate.csg.iter().enumerate() { for (i, csg) in self.gstate.csg.iter().enumerate() {
let csg = csg.read().unwrap(); let csg = csg.read().unwrap();
if csg.state == objects::State::Running { if csg.state == objects::State::Running || csg.blas == None {
builder builder
.bind_pipeline_compute(csg.enable_gen_pipeline.clone()) .bind_pipeline_compute(csg.enable_gen_pipeline.clone())
.unwrap() .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([64 / 8, 64 / 8, 64 / 8]) }.unwrap();
}
}
}
fn add_commands_raytrace( fn add_commands_raytrace(
&self, &self,
builder: &mut AutoCommandBufferBuilder<PrimaryAutoCommandBuffer>, builder: &mut AutoCommandBufferBuilder<PrimaryAutoCommandBuffer>,
@@ -1413,13 +1535,14 @@ impl App {
rt_set1: Arc<DescriptorSet>, rt_set1: Arc<DescriptorSet>,
rt_set2: Arc<DescriptorSet>, rt_set2: Arc<DescriptorSet>,
rt_set3: Arc<DescriptorSet>, rt_set3: Arc<DescriptorSet>,
rt_set4: Arc<DescriptorSet>,
) { ) {
builder builder
.bind_descriptor_sets( .bind_descriptor_sets(
PipelineBindPoint::RayTracing, PipelineBindPoint::RayTracing,
rcx.rt_pipeline.layout().clone(), rcx.rt_pipeline.layout().clone(),
0, 0,
vec![rt_set1, rt_set2, rt_set3], vec![rt_set1, rt_set2, rt_set3, rt_set4],
) )
.unwrap() .unwrap()
.bind_pipeline_ray_tracing(rcx.rt_pipeline.clone()) .bind_pipeline_ray_tracing(rcx.rt_pipeline.clone())
@@ -1625,6 +1748,7 @@ impl App {
self.replacement_modules.clone(), self.replacement_modules.clone(),
self.pipeline_cache.clone(), self.pipeline_cache.clone(),
self.previous_debug, self.previous_debug,
self.memory_allocator.clone(),
self.aabb_allocator.clone(), self.aabb_allocator.clone(),
self.descriptor_set_allocator.clone(), self.descriptor_set_allocator.clone(),
self.transform_buffer_pointer.clone(), self.transform_buffer_pointer.clone(),
@@ -1855,6 +1979,7 @@ impl App {
self.replacement_modules.clone(), self.replacement_modules.clone(),
self.pipeline_cache.clone(), self.pipeline_cache.clone(),
self.previous_debug, self.previous_debug,
self.memory_allocator.clone(),
self.aabb_allocator.clone(), self.aabb_allocator.clone(),
self.descriptor_set_allocator.clone(), self.descriptor_set_allocator.clone(),
self.transform_buffer_pointer.clone(), self.transform_buffer_pointer.clone(),
@@ -1924,7 +2049,8 @@ impl App {
let mut push_constants_left = 0; let mut push_constants_left = 0;
for (i, csg) in self.gstate.csg.iter().enumerate() { 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 self.thread_work_creation
.send(WorkItem::GetPushConstants(csg.clone(), self.time, i)) .send(WorkItem::GetPushConstants(csg.clone(), self.time, i))
.unwrap(); .unwrap();
@@ -1978,6 +2104,16 @@ impl App {
self.add_commands_enable_gen(&mut builder, enable_gen_set1.unwrap(), image_index); 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( rcx.scene[image_index] = Scene::new(
&self.device, &self.device,
&mut builder, &mut builder,
@@ -1991,9 +2127,12 @@ impl App {
image_index, 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 { unsafe {
builder builder
@@ -2077,11 +2216,6 @@ impl App {
} }
if DUMP_AABBS { 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() { for csg in self.gstate.csg.iter() {
let csg = csg.read().unwrap(); let csg = csg.read().unwrap();
let mut reader = csg.aabb_buffer[image_index].read(); let mut reader = csg.aabb_buffer[image_index].read();
+9 -5
View File
@@ -15,6 +15,7 @@ use vulkano::{
acceleration_structure::AccelerationStructure, acceleration_structure::AccelerationStructure,
buffer::Subbuffer, buffer::Subbuffer,
descriptor_set::DescriptorSet, descriptor_set::DescriptorSet,
image::view::ImageView,
pipeline::{ComputePipeline, graphics::vertex_input::Vertex}, pipeline::{ComputePipeline, graphics::vertex_input::Vertex},
shader::ShaderModule, shader::ShaderModule,
}; };
@@ -94,11 +95,14 @@ pub(crate) struct CSG {
pub(crate) dimensions: Vec3, pub(crate) dimensions: Vec3,
pub(crate) lowest_corner: Vec3, pub(crate) lowest_corner: Vec3,
pub(crate) replacement_modules: Arc<RwLock<HashMap<String, Arc<ShaderModule>>>>, pub(crate) replacement_modules: Arc<RwLock<HashMap<String, Arc<ShaderModule>>>>,
pub(crate) fuzz_pipeline: Arc<ComputePipeline>, pub(crate) fuzz_pipeline: Arc<ComputePipeline>,
pub(crate) enable_gen_pipeline: Arc<ComputePipeline>, pub(crate) enable_gen_pipeline: Arc<ComputePipeline>,
pub(crate) aabb_buffer: Vec<Subbuffer<[u8]>>, pub(crate) spatial_texture_pipeline: Arc<ComputePipeline>,
pub(crate) enable_gen_descriptor_set: Vec<Arc<DescriptorSet>>, 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 { impl Default for Position {
+88 -5
View File
@@ -20,6 +20,9 @@ use vulkano::{
buffer::{Subbuffer, allocator::SubbufferAllocator}, buffer::{Subbuffer, allocator::SubbufferAllocator},
descriptor_set::{DescriptorSet, WriteDescriptorSet, allocator::DescriptorSetAllocator}, descriptor_set::{DescriptorSet, WriteDescriptorSet, allocator::DescriptorSetAllocator},
device::Device, device::Device,
format::Format,
image::{Image, ImageCreateFlags, ImageCreateInfo, ImageType, ImageUsage, view::ImageView},
memory::allocator::{AllocationCreateInfo, MemoryAllocator},
pipeline::{ pipeline::{
ComputePipeline, Pipeline, PipelineLayout, PipelineShaderStageCreateInfo, ComputePipeline, Pipeline, PipelineLayout, PipelineShaderStageCreateInfo,
cache::PipelineCache, compute::ComputePipelineCreateInfo, cache::PipelineCache, compute::ComputePipelineCreateInfo,
@@ -43,6 +46,7 @@ pub enum WorkItem {
Arc<RwLock<HashMap<String, Module>>>, Arc<RwLock<HashMap<String, Module>>>,
Arc<PipelineCache>, Arc<PipelineCache>,
PreviousDebug, PreviousDebug,
Arc<dyn MemoryAllocator + 'static>,
Arc<Mutex<SubbufferAllocator>>, Arc<Mutex<SubbufferAllocator>>,
Arc<dyn DescriptorSetAllocator>, Arc<dyn DescriptorSetAllocator>,
Arc<AtomicU64>, Arc<AtomicU64>,
@@ -82,6 +86,7 @@ pub fn thread_loop(recv: mpmc::Receiver<WorkItem>, send: mpsc::SyncSender<WorkCo
replacement_modules, replacement_modules,
cache, cache,
debug, debug,
memory_allocator,
aabb_allocator, aabb_allocator,
descriptor_set_allocator, descriptor_set_allocator,
transform_buffer_pointer, 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 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); deferred_pipelines_recompile(device, cache, replacement_modules.clone(), debug);
let aabb_buffer: Vec<Subbuffer<[u8]>> = (0..frames) let aabb_buffer: Vec<Subbuffer<[u8]>> = (0..frames)
@@ -136,12 +141,53 @@ pub fn thread_loop(recv: mpmc::Receiver<WorkItem>, send: mpsc::SyncSender<WorkCo
}) })
.collect(); .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: [
MAXIMUM_SUBDIVISION,
MAXIMUM_SUBDIVISION,
MAXIMUM_SUBDIVISION,
],
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 = let transform_offset =
transform_buffer_pointer.fetch_add(1, Ordering::Relaxed) as usize; transform_buffer_pointer.fetch_add(1, Ordering::Relaxed) as usize;
assert!(transform_offset + 1 <= MAX_TRANSFORM_BUFFER as usize); assert!(transform_offset + 1 <= MAX_TRANSFORM_BUFFER as usize);
let csg = Arc::new(RwLock::new(CSG { let csg = Arc::new(RwLock::new(CSG {
name: format!("example {}", rand::random::<u8>()), name: format!("example {}", rand::random::<u16>()),
_seed: seed, _seed: seed,
parts, parts,
position: Position { position: Position {
@@ -152,9 +198,12 @@ pub fn thread_loop(recv: mpmc::Receiver<WorkItem>, send: mpsc::SyncSender<WorkCo
replacement_modules, replacement_modules,
fuzz_pipeline, fuzz_pipeline,
enable_gen_pipeline, enable_gen_pipeline,
spatial_texture_pipeline,
subdivision, subdivision,
aabb_buffer, aabb_buffer,
enable_gen_descriptor_set, enable_gen_descriptor_set,
spatial_texture,
spatial_texture_descriptor_set,
dimensions: Default::default(), dimensions: Default::default(),
lowest_corner: Default::default(), lowest_corner: Default::default(),
state: objects::State::Running, state: objects::State::Running,
@@ -202,7 +251,11 @@ pub fn thread_loop(recv: mpmc::Receiver<WorkItem>, send: mpsc::SyncSender<WorkCo
WorkItem::RecompilePipelines(csg, device, cache, debug, index) => { WorkItem::RecompilePipelines(csg, device, cache, debug, index) => {
let csg_start = Instant::now(); let csg_start = Instant::now();
let mut csg = csg.write().unwrap(); 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, device,
cache, cache,
csg.replacement_modules.clone(), csg.replacement_modules.clone(),
@@ -227,7 +280,11 @@ fn deferred_pipelines_recompile(
cache: Arc<PipelineCache>, cache: Arc<PipelineCache>,
replacement_modules: Arc<RwLock<HashMap<String, Arc<ShaderModule>>>>, replacement_modules: Arc<RwLock<HashMap<String, Arc<ShaderModule>>>>,
debug: PreviousDebug, debug: PreviousDebug,
) -> (Arc<ComputePipeline>, Arc<ComputePipeline>) { ) -> (
Arc<ComputePipeline>,
Arc<ComputePipeline>,
Arc<ComputePipeline>,
) {
let specs = get_spec_constants(&debug); let specs = get_spec_constants(&debug);
let replacement_modules = replacement_modules.read().unwrap(); let replacement_modules = replacement_modules.read().unwrap();
@@ -281,7 +338,33 @@ fn deferred_pipelines_recompile(
) )
.expect("failed to create enable_gen pipeline"); .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 { fn create_csg(seed: u64) -> SSATape {