add brute force

This commit is contained in:
John Hunter
2023-04-27 14:19:14 +01:00
parent 950b48018e
commit cb2721dca8
5 changed files with 125 additions and 44 deletions
+22 -1
View File
@@ -8,6 +8,7 @@
#ifdef implicit
layout (constant_id = 0) const bool DISABLE_TRACE = false;
layout (constant_id = 1) const bool BRUTE_FORCE = false;
layout(location=0)in VertexInput
{
@@ -53,7 +54,7 @@ const uint MAX_STEPS=1;
const float EPSILON=.0001;
const uint MAX_STEPS=50;
#define NEARPLANE 0.
#define FARPLANE length(vec3(10))
float FARPLANE;
#define gl_GlobalInvocationID uvec3(1)
#endif
#define interval_frags
@@ -109,7 +110,27 @@ vec2 spheretracing(vec3 ori,vec3 dir,out vec3 p){
//Implicit Surface Entrypoint
void main(){
//default_mask();
if (BRUTE_FORCE)
{
default_mask();
}
else {
mask = fragmentpassmasks.masks[gl_PrimitiveID];
}
#ifndef debug
desc = scene_description.desc[(DescriptionIndex)+1];
vec3 bottomleft = vec3(desc.bounds[3],desc.bounds[4],desc.bounds[5]);
vec3 topright = vec3(desc.bounds[0],desc.bounds[1],desc.bounds[2]);
if (BRUTE_FORCE)
{
FARPLANE = length((topright-bottomleft));
}
else {
FARPLANE = length((topright-bottomleft) * vec3(0.25*0.25,0.25*0.25,0.25*0.5));
}
#endif
vec3 raypos=vertexInput.position.xyz;
vec3 p;
vec3 raydir=normalize(raypos-(inverse(pc.world)*vec4(camera_uniforms.campos,1)).xyz);
+2
View File
@@ -17,6 +17,7 @@ pub struct PreviousDebug {
pub disable_meshscale1: bool,
pub disable_meshscale2: bool,
pub disable_taskcull: bool,
pub brute_force: bool,
}
#[derive(Debug)]
@@ -138,6 +139,7 @@ pub fn gui_up(gui: &mut Gui, state: &mut GState) {
ui.toggle_value(&mut state.debug.disable_meshscale1, "Disable mesh shader scaling part 1");
ui.toggle_value(&mut state.debug.disable_meshscale2, "Disable mesh shader scaling part 2");
ui.toggle_value(&mut state.debug.disable_taskcull, "Disable task shader culling");
ui.toggle_value(&mut state.debug.brute_force, "Brute force the render (use no new techniques)");
});
});
});
+74 -8
View File
@@ -11,6 +11,7 @@ uint DescriptionIndex;
layout (constant_id = 0) const bool DISABLE_TRACE = false;
layout (constant_id = 1) const bool DISABLE_SCALING_1 = false;
layout (constant_id = 2) const bool DISABLE_SCALING_2 = false;
layout (constant_id = 3) const bool BRUTE_FORCE = false;
layout(local_size_x=32,local_size_y=1,local_size_z=1)in;
layout(triangles,max_vertices=256,max_primitives=192)out;
@@ -36,11 +37,77 @@ layout(set=0,binding=20, std430)restrict writeonly buffer fragmentMasks{
void main()
{
uint localindex = uint(meshmasks.enabled[gl_WorkGroupID.x]);
DescriptionIndex = meshmasks.globalindex/2;
//clear_stacks();
//default_mask();
mask = meshmasks.masks[gl_WorkGroupID.x];
mat4 mvp=camera_uniforms.proj*camera_uniforms.view*pc.world;
uint vindex = gl_LocalInvocationID.x*8;
uint pindex = gl_LocalInvocationID.x*6;
if (BRUTE_FORCE)
{
SetMeshOutputsEXT(8,6);
float[6]bounds=scene_description.desc[gl_WorkGroupID.x+1].bounds;
vec3 bottomleft = vec3(bounds[3],bounds[4],bounds[5]);
vec3 topright = vec3(bounds[0],bounds[1],bounds[2]);
vec4[8]positions={
vec4(bottomleft,1.),
vec4(bottomleft.x,bottomleft.y,topright.z,1.),
vec4(bottomleft.x,topright.y,bottomleft.z,1.),
vec4(bottomleft.x,topright.y,topright.z,1.),
vec4(topright.x,bottomleft.y,bottomleft.z,1.),
vec4(topright.x,bottomleft.y,topright.z,1.),
vec4(topright.x,topright.y,bottomleft.z,1.),
vec4(topright,1.),
};
bvec3 signingvec=greaterThan((inverse(pc.world)*vec4(camera_uniforms.campos,1)).xyz,(topright+bottomleft)/2);
gl_MeshVerticesEXT[0].gl_Position=mvp*(positions[0]);
gl_MeshVerticesEXT[1].gl_Position=mvp*(positions[1]);
gl_MeshVerticesEXT[2].gl_Position=mvp*(positions[2]);
gl_MeshVerticesEXT[3].gl_Position=mvp*(positions[3]);
gl_MeshVerticesEXT[4].gl_Position=mvp*(positions[4]);
gl_MeshVerticesEXT[5].gl_Position=mvp*(positions[5]);
gl_MeshVerticesEXT[6].gl_Position=mvp*(positions[6]);
gl_MeshVerticesEXT[7].gl_Position=mvp*(positions[7]);
vertexOutput[0].position=(positions[0]);
vertexOutput[1].position=(positions[1]);
vertexOutput[2].position=(positions[2]);
vertexOutput[3].position=(positions[3]);
vertexOutput[4].position=(positions[4]);
vertexOutput[5].position=(positions[5]);
vertexOutput[6].position=(positions[6]);
vertexOutput[7].position=(positions[7]);
if(signingvec.x){
gl_PrimitiveTriangleIndicesEXT[0]=uvec3(4,5,6);
gl_PrimitiveTriangleIndicesEXT[1]=uvec3(5,6,7);
}else{
gl_PrimitiveTriangleIndicesEXT[0]=uvec3(0,1,2);
gl_PrimitiveTriangleIndicesEXT[1]=uvec3(1,2,3);
}
if(signingvec.y){
gl_PrimitiveTriangleIndicesEXT[2]=uvec3(2,3,6);
gl_PrimitiveTriangleIndicesEXT[3]=uvec3(7,3,6);
}else{
gl_PrimitiveTriangleIndicesEXT[2]=uvec3(0,1,4);
gl_PrimitiveTriangleIndicesEXT[3]=uvec3(5,1,4);
}
if(signingvec.z){
gl_PrimitiveTriangleIndicesEXT[4]=uvec3(1,3,5);
gl_PrimitiveTriangleIndicesEXT[5]=uvec3(3,5,7);
}else{
gl_PrimitiveTriangleIndicesEXT[4]=uvec3(0,2,4);
gl_PrimitiveTriangleIndicesEXT[5]=uvec3(2,4,6);
}
return;
}
//This can be optimised
SetMeshOutputsEXT(256,192);
vec3 bottomleft = meshmasks.bottomleft;
vec3 topright = meshmasks.topright;
vec3 center = (topright + bottomleft) / 2.;
@@ -56,11 +123,10 @@ void main()
vec4(topright,1.),
};
//This can be optimised
SetMeshOutputsEXT(256,192);
mat4 mvp=camera_uniforms.proj*camera_uniforms.view*pc.world;
uint vindex = gl_LocalInvocationID.x*8;
uint pindex = gl_LocalInvocationID.x*6;
uint localindex = uint(meshmasks.enabled[gl_WorkGroupID.x]);
DescriptionIndex = meshmasks.globalindex/2;
mask = meshmasks.masks[gl_WorkGroupID.x];
int GlobalInvocationIndex = int((meshmasks.globalindex*32+localindex)*32+gl_LocalInvocationID.x);
-23
View File
@@ -14,15 +14,6 @@ pub struct Interpreter<'csg> {
mat2_stack: Vec<Mat2>,
mat3_stack: Vec<Mat3>,
mat4_stack: Vec<Mat4>,
float_const_head: usize,
vec2_const_head: usize,
vec3_const_head: usize,
vec4_const_head: usize,
mat2_const_head: usize,
mat3_const_head: usize,
mat4_const_head: usize,
csg: &'csg CSG,
}
@@ -712,13 +703,6 @@ impl<'csg> Interpreter<'csg> {
mat2_stack: vec![],
mat3_stack: vec![],
mat4_stack: vec![],
float_const_head: 0,
vec2_const_head: 0,
vec3_const_head: 0,
vec4_const_head: 0,
mat2_const_head: 0,
mat3_const_head: 0,
mat4_const_head: 0,
csg,
}
}
@@ -731,13 +715,6 @@ impl<'csg> Interpreter<'csg> {
self.mat2_stack.clear();
self.mat3_stack.clear();
self.mat4_stack.clear();
self.float_const_head = 0;
self.vec2_const_head = 0;
self.vec3_const_head = 0;
self.vec4_const_head = 0;
self.mat2_const_head = 0;
self.mat3_const_head = 0;
self.mat4_const_head = 0;
}
//const masklen: usize = 29;
+24 -9
View File
@@ -432,11 +432,14 @@ fn main() {
render_pass.clone(),
&mut viewport,
implicit_fs::SpecializationConstants {DISABLE_TRACE:gstate.debug.bounding_boxes as u32},
implicit_fs::SpecializationConstants {DISABLE_TRACE:gstate.debug.bounding_boxes as u32,
BRUTE_FORCE:gstate.debug.brute_force as u32,},
implicit_ms::SpecializationConstants {DISABLE_TRACE:gstate.debug.disable_meshcull as u32,
DISABLE_SCALING_1:gstate.debug.disable_meshscale1 as u32,
DISABLE_SCALING_2:gstate.debug.disable_meshscale2 as u32},
DISABLE_SCALING_2:gstate.debug.disable_meshscale2 as u32,
BRUTE_FORCE:gstate.debug.brute_force as u32,},
implicit_ts::SpecializationConstants {DISABLE_TRACE:gstate.debug.disable_taskcull as u32},
gstate.debug.brute_force,
);
let command_buffer_allocator =
@@ -625,11 +628,14 @@ fn main() {
&new_images,
render_pass.clone(),
&mut viewport,
implicit_fs::SpecializationConstants {DISABLE_TRACE:gstate.debug.bounding_boxes as u32},
implicit_fs::SpecializationConstants {DISABLE_TRACE:gstate.debug.bounding_boxes as u32,
BRUTE_FORCE:gstate.debug.brute_force as u32},
implicit_ms::SpecializationConstants {DISABLE_TRACE:gstate.debug.disable_meshcull as u32,
DISABLE_SCALING_1:gstate.debug.disable_meshscale1 as u32,
DISABLE_SCALING_2:gstate.debug.disable_meshscale2 as u32},
DISABLE_SCALING_2:gstate.debug.disable_meshscale2 as u32,
BRUTE_FORCE:gstate.debug.brute_force as u32},
implicit_ts::SpecializationConstants {DISABLE_TRACE:gstate.debug.disable_taskcull as u32},
gstate.debug.brute_force,
);
recreate_swapchain = false;
prevdub = gstate.debug;
@@ -1006,6 +1012,7 @@ fn window_size_dependent_setup<Fs,Ms,Ts>(
implicit_fs_specs: Fs,
implicit_ms_specs: Ms,
implicit_ts_specs: Ts,
brute_force: bool,
) -> ([Arc<GraphicsPipeline>; 2], Vec<Arc<Framebuffer>>)
where
Fs: SpecializationConstants + Clone,
@@ -1096,7 +1103,7 @@ where
println!("Recompiling implicit pipeline... (may take up to 10 minutes)");
let implicit_pipeline = GraphicsPipeline::start()
let mut implicit_pipeline = GraphicsPipeline::start()
.render_pass(Subpass::from(render_pass.clone(), 0).unwrap())
.vertex_input_state(OVertex::per_vertex())
.input_assembly_state(InputAssemblyState::new())
@@ -1108,7 +1115,6 @@ where
},
]))
.fragment_shader(implicit_fs.entry_point("main").unwrap(), implicit_fs_specs)
.task_shader(implicit_ts.entry_point("main").unwrap(), implicit_ts_specs)
.mesh_shader(implicit_ms.entry_point("main").unwrap(), implicit_ms_specs)
.depth_stencil_state(DepthStencilState::simple_depth_test())
.rasterization_state(RasterizationState {
@@ -1123,13 +1129,22 @@ where
.unwrap(),
sample_shading: Some(0.5),
..Default::default()
})
});
let built_implicit_pipeline =
if !brute_force {
implicit_pipeline.task_shader(implicit_ts.entry_point("main").unwrap(),implicit_ts_specs)
.build(allocator.device().clone())
.unwrap();
.unwrap()
} else {
implicit_pipeline
.build(allocator.device().clone())
.unwrap()
};
println!("Implicit pipeline compiled");
([mesh_pipeline, implicit_pipeline], framebuffers)
([mesh_pipeline, built_implicit_pipeline], framebuffers)
}