This commit is contained in:
2025-02-01 14:15:47 +00:00
parent a2c7ee9987
commit c71b187fae
16 changed files with 16590 additions and 7368 deletions
+4
View File
@@ -23,6 +23,10 @@ fn main() -> io::Result<()> {
for l in f.lines() {
let line = l?;
if line.starts_with("#") {
continue;
}
let entries = line.split("//").map(str::trim).collect::<Vec<&str>>();
if entries[0].is_empty() {
continue;
+8 -10
View File
@@ -2,14 +2,12 @@
#version 460
#extension GL_EXT_mesh_shader:require
#extension GL_GOOGLE_include_directive:require
#define DescriptionIndex gl_PrimitiveID>>11
#include "include.glsl"
#ifdef implicit
layout(constant_id = 0) const bool DISABLE_TRACE = false;
layout(constant_id = 5) const bool BRUTE_FORCE = false;
layout(location = 0) in VertexInput
{
vec4 position;
@@ -63,7 +61,7 @@ float FARPLANE;
#include "interpreter.glsl"
layout(set = 0, binding = 20, std430) restrict readonly buffer fragmentMasks {
uint8_t masks[][masklen];
uint8_t masks[][MASK_ARRAY_LENGTH];
} fragmentpassmasks;
#ifdef debug
@@ -91,20 +89,20 @@ vec2 spheretracing(vec3 ori, vec3 dir, out vec3 p) {
#else
vec3 getNormal(vec3 p, float dens) {
vec3 n;
n.x = scene(vec3(p.x + EPSILON, p.y, p.z), false);
n.y = scene(vec3(p.x, p.y + EPSILON, p.z), false);
n.z = scene(vec3(p.x, p.y, p.z + EPSILON), false);
n.x = scene(vec3(p.x + EPSILON, p.y, p.z), false).x;
n.y = scene(vec3(p.x, p.y + EPSILON, p.z), false).x;
n.z = scene(vec3(p.x, p.y, p.z + EPSILON), false).x;
return normalize(n - (scene(p, false)));
}
vec2 spheretracing(vec3 ori, vec3 dir, out vec3 p) {
vec2 td = vec2(NEARPLANE, 1.);
p = ori;
td.y = scene(p, false) * .9;
td.y = scene(p, false).x * .9;
td.x += td.y;
p = ori + dir * td.x;
for (int i = 0; i < MAX_STEPS && td.y > EPSILON && td.x < FARPLANE; i++) {
td.y = scene(p, false) * .9;
td.y = scene(p, false).x * .9;
td.x += td.y;
p = ori + dir * td.x;
}
@@ -142,7 +140,7 @@ void main() {
//f_color=vec4(raydir,1.);
if (DISABLE_TRACE) {
if (BOUNDING_BOXES) {
f_color = vertexInput.position;
return;
}
+1186
View File
File diff suppressed because it is too large Load Diff
+4 -19
View File
@@ -8,11 +8,6 @@ uint DescriptionIndex;
#include "include.glsl"
#include "intervals.glsl"
layout (constant_id = 1) const bool DISABLE_TRACE = false;
layout (constant_id = 2) const bool DISABLE_SCALING_1 = false;
layout (constant_id = 3) const bool DISABLE_SCALING_2 = false;
layout (constant_id = 5) 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;
@@ -21,18 +16,8 @@ layout(location=0)out VertexOutput
vec4 position;
}vertexOutput[];
struct MeshMasks
{
uint8_t masks[32][masklen]; //928
uint8_t enabled[32]; //32
vec3 bottomleft; //12
vec3 topright; //12
uint globalindex; //4
}; //total = 988 bytes
taskPayloadSharedEXT MeshMasks meshmasks;
layout(set=0,binding=20, std430)restrict writeonly buffer fragmentMasks{
uint8_t masks[][masklen];
uint8_t masks[][MASK_ARRAY_LENGTH];
}fragmentpassmasks;
void main()
@@ -131,7 +116,7 @@ void main()
int GlobalInvocationIndex = int((meshmasks.globalindex*32+localindex)*32+gl_LocalInvocationID.x);
//adjust scale and position
if (!DISABLE_SCALING_1) {
if (!DISABLE_MESHSCALING1) {
for (int i = 0; i<8; i++)
{
positions[i] *= vec4(0.25,0.25,0.5,1.);
@@ -144,7 +129,7 @@ void main()
vec4 localtopright=positions[0];
vec4 localbottomleft=positions[7];
if (!DISABLE_SCALING_2) {
if (!DISABLE_MESHSCALING2) {
for (int i = 0; i<8; i++)
{
positions[i] *= vec4(0.25,0.25,0.5,1.);
@@ -164,7 +149,7 @@ void main()
gl_MeshPrimitivesEXT[pindex+5].gl_PrimitiveID=GlobalInvocationIndex;
bool triangle_fine;
if (!DISABLE_TRACE) {
if (!DISABLE_MESHCULL) {
float[2] check = scene(vec3[2](vec3(positions[0].xyz),vec3(positions[7].xyz)), true);
triangle_fine = (check[0] <= 0) && (check[1] >= 0);
} else {
+2 -4
View File
@@ -8,13 +8,11 @@
#include "include.glsl"
#include "intervals.glsl"
layout (constant_id = 4) const bool DISABLE_TRACE = false;
layout(local_size_x=32,local_size_y=1,local_size_z=1)in;
struct MeshMasks
{
uint8_t masks[32][masklen]; //928
uint8_t masks[32][MASK_ARRAY_LENGTH]; //928
uint8_t enabled[32]; //32
vec3 bottomleft; //12
vec3 topright; //12
@@ -52,7 +50,7 @@ void main()
barrier();
bool triangle_fine;
if (!DISABLE_TRACE) {
if (!DISABLE_TASKCULL) {
float[2] check = scene(vec3[2](bottomleft,topright), true);
triangle_fine = (check[0] <= 0) && (check[1] >= 0);
} else {
+5
View File
@@ -1,3 +1,6 @@
#ifndef glsl_include
#define glsl_include
layout(push_constant)uniform PushConstantData{
mat4 world;
}pc;
@@ -13,3 +16,5 @@ layout(set=0,binding=1)uniform Camera{
mat4 proj;
vec3 campos;
}camera_uniforms;
#endif
+68 -63
View File
@@ -1,64 +1,69 @@
const uint OPCopy =0; // Returns the input. Useful for copying registers.
const uint OPAdd =1; // Adds a vector to a vector component-wise.
const uint OPSub =2; // Subtracts a vector from a vector component-wise.
const uint OPMul =3; // Multiplies a vector and a vector component-wise.
const uint OPDiv =4; // Divides a vector by a vector component-wise.
const uint OPMod =5; // Calculates a vector modulo a vector component-wise.
const uint OPRem =6; // Calculates a vector remainder a vector component-wise.
const uint OPPow =7; // Calculates a vector to the power of a vector component-wise.
const uint OPAtan2 =8; // Calculates a vector Atan2 a vector component-wise.
const uint OPMin =9; // Calculates the minimum of a vector and a vector component-wise.
const uint OPMax =10; // Calculates the maximum of a vector and a vector component-wise.
const uint OPNegate =11; // Returns the negation of all components of a vector.
const uint OPRound =12; // Returns all components of a vector rounded to the nearest integer.
const uint OPRoundEven =13; // Returns all components of a vector rounded to the nearest even integer.
const uint OPTrunc =14; // Returns all components of a vector rounded towards zero.
const uint OPAbs =15; // Returns the absolute value of all components of a vector.
const uint OPSign =16; // Returns the sign of all components of a vector.
const uint OPFloor =17; // Returns the floor of all components of a vector.
const uint OPCeil =18; // Returns the ceiling of all components of a vector.
const uint OPFract =19; // Returns the fractional part of all components of a vector.
const uint OPSin =20; // Returns the sine of all components of a vector.
const uint OPCos =21; // Returns the cosine of all components of a vector.
const uint OPTan =22; // Returns the tangent of all components of a vector.
const uint OPAsin =23; // Returns the arc sine of all components of a vector.
const uint OPAcos =24; // Returns the arc cosine of all components of a vector.
const uint OPAtan =25; // Returns the arc tangent of all components of a vector.
const uint OPSinh =26; // Returns the hyperbolic sine of all components of a vector.
const uint OPCosh =27; // Returns the hyperbolic cosine of all components of a vector.
const uint OPTanh =28; // Returns the hyperbolic tangent of all components of a vector.
const uint OPAsinh =29; // Returns the hyperbolic arc sine of all components of a vector.
const uint OPAcosh =30; // Returns the hyperbolic arc cosine of all components of a vector.
const uint OPAtanh =31; // Returns the hyperbolic arc tangent of all components of a vector.
const uint OPExp =32; // Returns e raised to all components of a vector.
const uint OPLog =33; // Returns the natural logarithm of all components of a vector.
const uint OPExp2 =34; // Returns 2 raised to all components of a vector.
const uint OPLog2 =35; // Returns the base 2 logarithm of all components of a vector.
const uint OPSqrt =36; // Returns the square root of all components of a vector.
const uint OPInverseSqrt =37; // Returns one over the square root of all components of a vector.
const uint OPSquare =38; // Returns the square of all components of a vector.
const uint OPCube =39; // Returns the cube of all components of a vector.
const uint OPSmoothMin =40; // Returns the smooth minimum between a vector and a vector, varied by a vector.
const uint OPSmoothMax =41; // Returns the smooth maximum between a vector and a vector, varied by a vector.
const uint OPClamp =42; // Clamps a vector between a vector and a vector.
const uint OPMix =43; // Mixes between a vector and a vector, varied by a vector.
const uint OPStep =44; // Steps between a vector and a vector, varied by a vector.
const uint OPSmoothStep =45; // Smooth Steps between a vector and a vector, varied by a vector.
const uint OPFMA =46; // Calculates a vector multiplied by a vector, then adds a vector.
const uint OPDot =47; // Returns the dot product of two vectors.
const uint OPLength =48; // Returns the length (magnitude) of a vector.
const uint OPDistance =49; // Returns the length (magnitude) of the vector between two vectors.
const uint OPNormalize =50; // Returns the normalised version of a vector.
#ifndef instruction_set
#define instruction_set
const uint OPNop =(0*64)+63; // No operation.
const uint OPStop =(1*64)+63; // Stops execution of the tape and returns 0.
const uint OPReturn =(2*64)+63; // Stops execution of the tape and returns a single value.
const uint OPPosition =(3*64)+63; // Returns the current position being sampled.
const uint OPMinMaterial =(0*64)+62; // Calculates the minimum of two Vec1s, and also carries over the relevant material metadata.
const uint OPMaxMaterial =(1*64)+62; // Calculates the maximum of two Vec1s, and also carries over the relevant material metadata.
const uint OPSmoothMinMaterial =(2*64)+62; // Returns the smooth minimum between a Vec1 and a Vec1, varied by a Vec1, and also carries over the relevant material metadata.
const uint OPSmoothMaxMaterial =(3*64)+62; // Returns the smooth maximum between a Vec1 and a Vec1, varied by a Vec1, and also carries over the relevant material metadata.
const uint OPCross =(0*64)+61; // Returns the cross product of two Vec3s.
const uint OPSDFSphere =(1*64)+61; // Returns the distance to a sphere.
const uint OPSDFBox =(2*64)+61; // Returns the distance to a box.
const uint OPSDFTorus =(3*64)+61; // Returns the distance to a torus.
const uint8_t OPCopy =uint8_t(0); // Returns the input. Useful for copying registers.
const uint8_t OPAdd =uint8_t(1); // Adds a vector to a vector component-wise.
const uint8_t OPSub =uint8_t(2); // Subtracts a vector from a vector component-wise.
const uint8_t OPMul =uint8_t(3); // Multiplies a vector and a vector component-wise.
const uint8_t OPDiv =uint8_t(4); // Divides a vector by a vector component-wise.
const uint8_t OPMod =uint8_t(5); // Calculates a vector modulo a vector component-wise.
const uint8_t OPRem =uint8_t(6); // Calculates a vector remainder a vector component-wise.
const uint8_t OPPow =uint8_t(7); // Calculates a vector to the power of a vector component-wise.
const uint8_t OPAtan2 =uint8_t(8); // Calculates a vector Atan2 a vector component-wise.
const uint8_t OPMin =uint8_t(9); // Calculates the minimum of a vector and a vector component-wise.
const uint8_t OPMax =uint8_t(10); // Calculates the maximum of a vector and a vector component-wise.
const uint8_t OPNegate =uint8_t(11); // Returns the negation of all components of a vector.
const uint8_t OPRound =uint8_t(12); // Returns all components of a vector rounded to the nearest integer, 0.5 away from zero.
const uint8_t OPRoundEven =uint8_t(13); // Returns all components of a vector rounded to the nearest integer, 0.5 to even.
const uint8_t OPTrunc =uint8_t(14); // Returns all components of a vector rounded to the nearest integer, 0.5 towards zero.
const uint8_t OPAbs =uint8_t(15); // Returns the absolute value of all components of a vector.
const uint8_t OPSign =uint8_t(16); // Returns the sign of all components of a vector.
const uint8_t OPFloor =uint8_t(17); // Returns the floor of all components of a vector.
const uint8_t OPCeil =uint8_t(18); // Returns the ceiling of all components of a vector.
const uint8_t OPFract =uint8_t(19); // Returns the fractional part of all components of a vector.
const uint8_t OPSin =uint8_t(20); // Returns the sine of all components of a vector.
const uint8_t OPCos =uint8_t(21); // Returns the cosine of all components of a vector.
const uint8_t OPTan =uint8_t(22); // Returns the tangent of all components of a vector.
const uint8_t OPAsin =uint8_t(23); // Returns the arc sine of all components of a vector.
const uint8_t OPAcos =uint8_t(24); // Returns the arc cosine of all components of a vector.
const uint8_t OPAtan =uint8_t(25); // Returns the arc tangent of all components of a vector.
const uint8_t OPSinh =uint8_t(26); // Returns the hyperbolic sine of all components of a vector.
const uint8_t OPCosh =uint8_t(27); // Returns the hyperbolic cosine of all components of a vector.
const uint8_t OPTanh =uint8_t(28); // Returns the hyperbolic tangent of all components of a vector.
const uint8_t OPAsinh =uint8_t(29); // Returns the hyperbolic arc sine of all components of a vector.
const uint8_t OPAcosh =uint8_t(30); // Returns the hyperbolic arc cosine of all components of a vector.
const uint8_t OPAtanh =uint8_t(31); // Returns the hyperbolic arc tangent of all components of a vector.
const uint8_t OPExp =uint8_t(32); // Returns e raised to all components of a vector.
const uint8_t OPLog =uint8_t(33); // Returns the natural logarithm of all components of a vector.
const uint8_t OPExp2 =uint8_t(34); // Returns 2 raised to all components of a vector.
const uint8_t OPLog2 =uint8_t(35); // Returns the base 2 logarithm of all components of a vector.
const uint8_t OPSqrt =uint8_t(36); // Returns the square root of all components of a vector.
const uint8_t OPInverseSqrt =uint8_t(37); // Returns one over the square root of all components of a vector.
const uint8_t OPSquare =uint8_t(38); // Returns the square of all components of a vector.
const uint8_t OPCube =uint8_t(39); // Returns the cube of all components of a vector.
const uint8_t OPSmoothMin =uint8_t(40); // Returns the smooth minimum between a vector and a vector, varied by a vector.
const uint8_t OPSmoothMax =uint8_t(41); // Returns the smooth maximum between a vector and a vector, varied by a vector.
const uint8_t OPClamp =uint8_t(42); // Clamps a vector between a vector and a vector.
const uint8_t OPMix =uint8_t(43); // Mixes between a vector and a vector, varied by a vector.
const uint8_t OPStep =uint8_t(44); // Steps between a vector and a vector, varied by a vector.
const uint8_t OPSmoothStep =uint8_t(45); // Smooth Steps between a vector and a vector, varied by a vector.
const uint8_t OPFMA =uint8_t(46); // Calculates a vector multiplied by a vector, then adds a vector.
const uint8_t OPDot =uint8_t(47); // Returns the dot product of two vectors.
const uint8_t OPLength =uint8_t(48); // Returns the length (magnitude) of a vector.
const uint8_t OPDistance =uint8_t(49); // Returns the length (magnitude) of the vector between two vectors.
const uint8_t OPNormalize =uint8_t(50); // Returns the normalised version of a vector.
const uint8_t OPNop =uint8_t((0*64)+63); // No operation.
const uint8_t OPStop =uint8_t((1*64)+63); // Stops execution of the tape and returns 0.
const uint8_t OPReturn =uint8_t((2*64)+63); // Stops execution of the tape and returns a single value.
const uint8_t OPPosition =uint8_t((3*64)+63); // Returns the current position being sampled.
const uint8_t OPMinMaterial =uint8_t((0*64)+62); // Calculates the minimum of two Vec1s, and also carries over the relevant material metadata.
const uint8_t OPMaxMaterial =uint8_t((1*64)+62); // Calculates the maximum of two Vec1s, and also carries over the relevant material metadata.
const uint8_t OPSmoothMinMaterial =uint8_t((2*64)+62); // Returns the smooth minimum between a Vec1 and a Vec1, varied by a Vec1, and also carries over the relevant material metadata.
const uint8_t OPSmoothMaxMaterial =uint8_t((3*64)+62); // Returns the smooth maximum between a Vec1 and a Vec1, varied by a Vec1, and also carries over the relevant material metadata.
const uint8_t OPCross =uint8_t((0*64)+61); // Returns the cross product of two Vec3s.
const uint8_t OPSDFSphere =uint8_t((1*64)+61); // Returns the distance to a sphere.
const uint8_t OPSDFBox =uint8_t((2*64)+61); // Returns the distance to a box.
const uint8_t OPSDFTorus =uint8_t((3*64)+61); // Returns the distance to a torus.
#endif
+565 -2241
View File
File diff suppressed because it is too large Load Diff
+355 -1557
View File
File diff suppressed because it is too large Load Diff
+3225 -2995
View File
File diff suppressed because it is too large Load Diff
+66 -58
View File
@@ -20,10 +20,10 @@ use bytemuck::{Pod, Zeroable};
use egui_winit_vulkano::{Gui, GuiConfig};
use foldhash::{HashMap, HashMapExt, HashSet};
use glam::{self, vec3, EulerRot, Mat3, Mat4, Vec3};
use instruction_set::InputTypes;
use log::{error, info, trace};
use rayon::prelude::*;
use simplelog::{CombinedLogger, Config, TermLogger, WriteLogger};
use ssa::{SSAInput, SSAOpcode, SSAOpcodeSized, SSATape};
use vulkano::{
buffer::{
allocator::{SubbufferAllocator, SubbufferAllocatorCreateInfo},
@@ -85,7 +85,6 @@ mod gui;
use crate::gui::*;
mod objects;
use crate::objects::*;
mod mcsg_deserialise;
mod ssa;
@@ -363,14 +362,70 @@ impl App {
.unwrap(),
);
gstate.csg.append(
&mut load_csg(
&memory_allocator,
&mut Cursor::new(CSG_SOLIDS[0].1),
CSG_SOLIDS[0].0.to_string(),
)
.unwrap(),
let mut tape = SSATape::default();
let pos = tape.push_instruction(
SSAOpcodeSized {
opcode: SSAOpcode::SSAPosition,
size: 1,
},
vec![],
);
let offset = tape.push_instruction(
SSAOpcodeSized {
opcode: SSAOpcode::SSAAdd,
size: 3,
},
vec![
pos[0],
pos[1],
pos[2],
SSAInput::Constant(1.7),
SSAInput::Constant(0.4),
SSAInput::Constant(1.7),
],
);
let sphere = tape.push_instruction(
SSAOpcodeSized {
opcode: SSAOpcode::SSASDFSphere,
size: 1,
},
vec![offset[0], offset[1], offset[2], SSAInput::Constant(0.5)],
);
let torus = tape.push_instruction(
SSAOpcodeSized {
opcode: SSAOpcode::SSASDFTorus,
size: 1,
},
vec![
pos[0],
pos[1],
pos[2],
SSAInput::Constant(0.3),
SSAInput::Constant(0.7),
],
);
let min = tape.push_instruction(
SSAOpcodeSized {
opcode: SSAOpcode::SSAMin,
size: 1,
},
vec![sphere[0], torus[0]],
);
tape.push_instruction(
SSAOpcodeSized {
opcode: SSAOpcode::SSAReturn,
size: 1,
},
min,
);
gstate.csg.push(CSG {
name: "example".to_string(),
parts: tape,
pos: Vec3::ZERO,
rot: Vec3::ZERO,
scale: Vec3::ONE,
});
gstate
.lights
@@ -1048,52 +1103,7 @@ impl App {
if COMPUTE_FUZZING {
let mut fake_csg = vec![];
for i in 0..1 {
fake_csg.push(CSG {
name: format!("fuzz_{i}"),
parts: vec![
CSGPart::opcode(
InstructionSet::OPMulVec3Float,
vec![Inputs::Variable, Inputs::Float(0.9)],
),
CSGPart::opcode(InstructionSet::OPDupVec3, vec![Inputs::Variable]),
CSGPart::opcode(
InstructionSet::OPAddVec3Vec3,
vec![Inputs::Variable, Inputs::Vec3(vec3(-0.7, i as f32, -0.7))],
),
CSGPart::opcode(
InstructionSet::OPSDFSphere,
vec![Inputs::Float(0.5), Inputs::Variable],
),
//CSGPart::opcode(InstructionSet::OPNop,vec![]),
//CSGPart::opcode(InstructionSet::OPDupVec3,
// vec![Inputs::Variable]),
// CSGPart::opcode(InstructionSet::OPAddVec3Vec3,
// vec![Inputs::Variable, Inputs::Vec3([-0.2, -0.2,
// -0.2].into())]),
// CSGPart::opcode(InstructionSet::OPAddVec3Vec3,
// vec![Inputs::Variable, Inputs::Vec3([-0.0, -0.0,
// -0.0].into())]),
CSGPart::opcode(
InstructionSet::OPSDFSphere,
vec![Inputs::Float(1.2), Inputs::Variable],
),
//CSGPart::opcode(InstructionSet::OPSDFBox,
// vec![Inputs::Variable,
// Inputs::Vec3([0.7, 0.7, 0.7].into())]),
CSGPart::opcode(
InstructionSet::OPMinFloat,
vec![Inputs::Variable, Inputs::Variable],
),
CSGPart::opcode(
InstructionSet::OPDivFloatFloat,
vec![Inputs::Variable, Inputs::Float(0.9)],
),
CSGPart::opcode(InstructionSet::OPStop, vec![Inputs::Variable]),
],
pos: Vec3::ZERO,
rot: Vec3::ZERO,
scale: Vec3::ONE,
})
fake_csg.push()
}
let (compute_subbuffers, scene) = object_size_dependent_setup(
@@ -1806,9 +1816,7 @@ fn object_size_dependent_setup(
let mut deps: Vec<[u8; 2]> = vec![Default::default()];
let mut desc: Vec<Description> = vec![Default::default()];
'nextcsg: for csg in state {
}
'nextcsg: for csg in state {}
trace!("floats: {floats:?}");
trace!("vec2s: {vec2s:?}");
+2 -43
View File
@@ -11,7 +11,7 @@ use vulkano::{
pipeline::graphics::vertex_input::Vertex,
};
use crate::instruction_set::InstructionSet;
use crate::ssa::SSATape;
pub(crate) const PLATONIC_SOLIDS: [(&str, &[u8]); 1] = [("Buny", include_bytes!("bunny.obj"))];
pub(crate) const CSG_SOLIDS: [(&str, &[u8]); 1] =
@@ -39,7 +39,7 @@ pub(crate) struct Mesh {
#[derive(Debug)]
pub(crate) struct CSG {
pub(crate) name: String,
pub(crate) parts: Vec<CSGPart>,
pub(crate) parts: SSATape,
pub(crate) pos: Vec3,
pub(crate) rot: Vec3,
pub(crate) scale: Vec3,
@@ -60,47 +60,6 @@ pub(crate) enum Inputs {
Mat4(Mat4),
}
#[repr(C)]
#[derive(Clone, Debug)]
pub(crate) struct CSGPart {
pub(crate) code: Vec<u8>,
pub(crate) opcode: InstructionSet,
pub(crate) inputs: Vec<u8>,
pub(crate) material: Option<Mat4>,
}
impl CSGPart {
pub(crate) fn opcode(opcode: InstructionSet, inputs: Vec<Inputs>) -> CSGPart {
CSGPart {
code: (opcode as u16 & 1023)
| inputs
.iter()
.enumerate()
.map(|(i, n)| {
if n != &Inputs::Variable {
1 << (15 - i)
} else {
0
}
})
.fold(0, |a, i| a | i),
opcode,
constants: inputs,
material: None,
}
}
pub(crate) fn opcode_with_material(
opcode: InstructionSet,
inputs: Vec<Inputs>,
material: Mat4,
) -> CSGPart {
let mut c = CSGPart::opcode(opcode, inputs);
c.material = Some(material);
c
}
}
pub(crate) fn load_obj(
memory_allocator: &Arc<StandardMemoryAllocator>,
input: &mut dyn Read,
+180
View File
@@ -0,0 +1,180 @@
#ifndef scene_bindings
#define scene_bindings
#include "spec_constants.glsl"
layout(set = 1, binding = 0, std430) uniform SceneDescription {
float[6] bounds;
} desc;
layout(set = 1, binding = 1, std430) uniform SceneBuf {
u32vec4 opcodes[MASK_ARRAY_LENGTH];
}
layout(set = 1, binding = 2, std430) uniform FloatConst {
u32vec4 floats[MASK_ARRAY_LENGTH];
}
layout(set = 1, binding = 3, std430) uniform Inputs {
u32vec4 inputs[MASK_ARRAY_LENGTH];
}
const uint8_t MASK_EXECUTE = 0;
const uint8_t MASK_PASS_P1 = 1;
const uint8_t MASK_PASS_P2 = 2;
const uint8_t MASK_PASS_P3 = 3;
const uint8_t MASK_PASS_P4 = 4;
uint8_t mask[MASK_ARRAY_LENGTH];
void default_mask()
{
for (int i = 0; i < MASK_ARRAY_LENGTH; i++) {
mask[i] = MASK_EXECUTE;
}
}
/// increments once for each opcode
uint program_counter = 0;
/// increments once for each nibble
uint nibble_counter = 0;
/// increments for each constant
uint const_counter = 0;
u32vec4 major_integer_unpack;
u32vec4 major_float_unpack;
float load_const() {
if ((const_counter % 4) == 0) {
major_float_unpack = floats.floats[desc.floats + (const_counter / 4)];
}
switch (const_counter % 4) {
case 0:
return uintBitsToFloat(major_integer_unpack.x);
case 1:
return uintBitsToFloat(major_integer_unpack.y);
case 2:
return uintBitsToFloat(major_integer_unpack.z);
case 3:
return uintBitsToFloat(major_integer_unpack.w);
}
}
uint8_t load_byte() {
if ((nibble_counter % 32) == 0) {
major_integer_unpack = scenes.opcodes[desc.scene + (nibble_counter / 32)];
}
switch ((nibble_counter / 2) % 16) {
case 0:
return uint8_t((major_integer_unpack.x >> 0) & 255);
case 1:
return uint8_t((major_integer_unpack.x >> 8) & 255);
case 2:
return uint8_t((major_integer_unpack.x >> 16) & 255);
case 3:
return uint8_t((major_integer_unpack.x >> 24) & 255);
case 4:
return uint8_t((major_integer_unpack.y >> 0) & 255);
case 5:
return uint8_t((major_integer_unpack.y >> 8) & 255);
case 6:
return uint8_t((major_integer_unpack.y >> 16) & 255);
case 7:
return uint8_t((major_integer_unpack.y >> 24) & 255);
case 8:
return uint8_t((major_integer_unpack.z >> 0) & 255);
case 9:
return uint8_t((major_integer_unpack.z >> 8) & 255);
case 10:
return uint8_t((major_integer_unpack.z >> 16) & 255);
case 11:
return uint8_t((major_integer_unpack.z >> 24) & 255);
case 12:
return uint8_t((major_integer_unpack.w >> 0) & 255);
case 13:
return uint8_t((major_integer_unpack.w >> 8) & 255);
case 14:
return uint8_t((major_integer_unpack.w >> 16) & 255);
case 15:
return uint8_t((major_integer_unpack.w >> 24) & 255);
}
}
uint8_t load_opcode() {
nibble_counter += 1;
nibble_counter &= (~1);
program_counter += 1;
return load_byte();
}
uint8_t load_register() {
if ((nibble_counter % 2) == 0) {
return uint8_t(load_byte() & 15);
}
else if ((nibble_counter % 2) == 1) {
return uint8_t(load_byte() >> 4);
}
}
uint8_t load_mask() {
return mask[program_counter];
}
#define unroll_instruction_set(index, name) \
const uint8_t OPCopy##name = uint8_t(OPCopy+(index<<6));\
const uint8_t OPAdd##name = uint8_t(OPAdd+(index<<6));\
const uint8_t OPSub##name = uint8_t(OPSub+(index<<6));\
const uint8_t OPMul##name = uint8_t(OPMul+(index<<6));\
const uint8_t OPDiv##name = uint8_t(OPDiv+(index<<6));\
const uint8_t OPMod##name = uint8_t(OPMod+(index<<6));\
const uint8_t OPRem##name = uint8_t(OPRem+(index<<6));\
const uint8_t OPPow##name = uint8_t(OPPow+(index<<6));\
const uint8_t OPAtan2##name = uint8_t(OPAtan2+(index<<6));\
const uint8_t OPMin##name = uint8_t(OPMin+(index<<6));\
const uint8_t OPMax##name = uint8_t(OPMax+(index<<6));\
const uint8_t OPNegate##name = uint8_t(OPNegate+(index<<6));\
const uint8_t OPRound##name = uint8_t(OPRound+(index<<6));\
const uint8_t OPRoundEven##name = uint8_t(OPRoundEven+(index<<6));\
const uint8_t OPTrunc##name = uint8_t(OPTrunc+(index<<6));\
const uint8_t OPAbs##name = uint8_t(OPAbs+(index<<6));\
const uint8_t OPSign##name = uint8_t(OPSign+(index<<6));\
const uint8_t OPFloor##name = uint8_t(OPFloor+(index<<6));\
const uint8_t OPCeil##name = uint8_t(OPCeil+(index<<6));\
const uint8_t OPFract##name = uint8_t(OPFract+(index<<6));\
const uint8_t OPSin##name = uint8_t(OPSin+(index<<6));\
const uint8_t OPCos##name = uint8_t(OPCos+(index<<6));\
const uint8_t OPTan##name = uint8_t(OPTan+(index<<6));\
const uint8_t OPAsin##name = uint8_t(OPAsin+(index<<6));\
const uint8_t OPAcos##name = uint8_t(OPAcos+(index<<6));\
const uint8_t OPAtan##name = uint8_t(OPAtan+(index<<6));\
const uint8_t OPSinh##name = uint8_t(OPSinh+(index<<6));\
const uint8_t OPCosh##name = uint8_t(OPCosh+(index<<6));\
const uint8_t OPTanh##name = uint8_t(OPTanh+(index<<6));\
const uint8_t OPAsinh##name = uint8_t(OPAsinh+(index<<6));\
const uint8_t OPAcosh##name = uint8_t(OPAcosh+(index<<6));\
const uint8_t OPAtanh##name = uint8_t(OPAtanh+(index<<6));\
const uint8_t OPExp##name = uint8_t(OPExp+(index<<6));\
const uint8_t OPLog##name = uint8_t(OPLog+(index<<6));\
const uint8_t OPExp2##name = uint8_t(OPExp2+(index<<6));\
const uint8_t OPLog2##name = uint8_t(OPLog2+(index<<6));\
const uint8_t OPSqrt##name = uint8_t(OPSqrt+(index<<6));\
const uint8_t OPInverseSqrt##name = uint8_t(OPInverseSqrt+(index<<6));\
const uint8_t OPSquare##name = uint8_t(OPSquare+(index<<6));\
const uint8_t OPCube##name = uint8_t(OPCube+(index<<6));\
const uint8_t OPSmoothMin##name = uint8_t(OPSmoothMin+(index<<6));\
const uint8_t OPSmoothMax##name = uint8_t(OPSmoothMax+(index<<6));\
const uint8_t OPClamp##name = uint8_t(OPClamp+(index<<6));\
const uint8_t OPMix##name = uint8_t(OPMix+(index<<6));\
const uint8_t OPStep##name = uint8_t(OPStep+(index<<6));\
const uint8_t OPSmoothStep##name = uint8_t(OPSmoothStep+(index<<6));\
const uint8_t OPFMA##name = uint8_t(OPFMA+(index<<6));\
const uint8_t OPDot##name = uint8_t(OPDot+(index<<6));\
const uint8_t OPLength##name = uint8_t(OPLength+(index<<6));\
const uint8_t OPDistance##name = uint8_t(OPDistance+(index<<6));\
const uint8_t OPNormalize##name = uint8_t(OPNormalize+(index<<6));
unroll_instruction_set(0, Vec1)
unroll_instruction_set(1, Vec2)
unroll_instruction_set(2, Vec3)
unroll_instruction_set(3, Vec4)
#endif
+15
View File
@@ -0,0 +1,15 @@
#ifndef spec_constants
#define spec_constants
layout(constant_id = 0) const bool BOUNDING_BOXES = false;
layout(constant_id = 1) const bool DISABLE_MESHCULL = false;
layout(constant_id = 2) const bool DISABLE_MESHSCALING1 = false;
layout(constant_id = 3) const bool DISABLE_MESHSCALING2 = false;
layout(constant_id = 4) const bool DISABLE_TASKCULL = false;
layout(constant_id = 5) const bool BRUTE_FORCE = false;
const uint MASK_ARRAY_LENGTH = 500;
layout(constant_id = 7) const uint EXECUTION_LIMIT = 500;
//#include "static_opcode_array.glsl"
#endif
+882 -95
View File
File diff suppressed because it is too large Load Diff
+10001 -261
View File
File diff suppressed because it is too large Load Diff