diff --git a/build.rs b/build.rs index a1bbbf1dcaae06d2ca8c4874a83c95e9a49f5fa5..4b5b92caff547a6b525177a43dcfe2fc5fbd5ffd 100644 --- a/build.rs +++ b/build.rs @@ -1,4 +1,5 @@ use std::env; +use std::fmt::format; use std::fs; use std::fs::File; use std::io; @@ -12,19 +13,112 @@ fn main() -> io::Result<()> { let dest_path = Path::new(&out_dir).join("instructionset.rs"); let f = File::open("src/instructionset.glsl")?; let f = BufReader::new(f); - let mut out = " + let mut out = "#[allow(non_snake_case)] + #[derive(Clone, Copy, Debug, PartialEq, Eq)] + pub enum InputTypes{ + #[allow(non_snake_case)] + Float, + #[allow(non_snake_case)] + Vec2, + #[allow(non_snake_case)] + Vec3, + #[allow(non_snake_case)] + Vec4, + #[allow(non_snake_case)] + Mat2, + #[allow(non_snake_case)] + Mat3, + #[allow(non_snake_case)] + Mat4, + } + #[repr(u16)] + #[allow(non_snake_case)] + #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum InstructionSet{ " .to_owned(); - for l in f.lines() { + let mut outputimpl = " + pub fn output(&self) -> Vec<InputTypes> + { + match self { + + " + .to_owned(); + + let mut inputimpl = " + pub fn input(&self) -> Vec<InputTypes> + { + match self { + + " + .to_owned(); + + for (index, l) in f.lines().enumerate() { let line = l?; - out += &line[11..line.len() - 12]; - out += ",\n"; + let entries = line.split("//").map(str::trim).collect::<Vec<&str>>(); + if entries[0].len() == 0 { + continue; + } + + let name = &entries[0][11..entries[0].len() - 12]; + + out += &format!( + "#[allow(non_snake_case)]\n#[allow(dead_code)]\n{}={},\n", + name, index + ); + + inputimpl += &format!( + "#[allow(non_snake_case)]\nInstructionSet::{} => vec![", + name + ); + for input in entries[1].split(" ").map(str::trim) { + if input.len() == 0 { + continue; + } + match input { + "F" => inputimpl += "InputTypes::Float,", + "V2" => inputimpl += "InputTypes::Vec2,", + "V3" => inputimpl += "InputTypes::Vec3,", + "V4" => inputimpl += "InputTypes::Vec4,", + "M2" => inputimpl += "InputTypes::Mat2,", + "M3" => inputimpl += "InputTypes::Mat3,", + "M4" => inputimpl += "InputTypes::Mat4,", + _ => panic!("unknown input?? [{}]", input), + } + } + inputimpl += "],\n"; + + outputimpl += &format!( + "#[allow(non_snake_case)]\nInstructionSet::{} => vec![", + name + ); + for output in entries[2].split(" ").map(str::trim) { + if output.len() == 0 { + continue; + } + match output { + "F" => outputimpl += "InputTypes::Float,", + "V2" => outputimpl += "InputTypes::Vec2,", + "V3" => outputimpl += "InputTypes::Vec3,", + "V4" => outputimpl += "InputTypes::Vec4,", + "M2" => outputimpl += "InputTypes::Mat2,", + "M3" => outputimpl += "InputTypes::Mat3,", + "M4" => outputimpl += "InputTypes::Mat4,", + _ => panic!("unknown output?? [{}]", output), + } + } + outputimpl += "],\n"; } out += "}"; + inputimpl += "}}"; + outputimpl += "}}"; + out += "#[allow(non_snake_case)]\nimpl InstructionSet {\n"; + out += &inputimpl; + out += &outputimpl; + out += "}"; fs::write(&dest_path, out).unwrap(); println!("cargo:rerun-if-changed=build.rs"); diff --git a/src/frag.glsl b/src/frag.glsl index 18fc53d5b86900c884ecb60e56fb88e04bc990cf..b5433c9b64eb77b1f125865b7f3ab9fcb925bdbe 100644 --- a/src/frag.glsl +++ b/src/frag.glsl @@ -2,6 +2,7 @@ #version 460 #extension GL_EXT_mesh_shader:require +#define DescriptionIndex gl_PrimitiveID>>11 #include "include.glsl" #ifdef implicit @@ -107,8 +108,10 @@ void main(){ vec3 raydir=normalize(raypos-(inverse(pc.world)*vec4(camera_uniforms.campos,1)).xyz); //raypos-=vec3(5); - //f_color=vec4(raydir,1.); - //return; + /*f_color=vec4(raydir,1.); + return;*/ + /*f_color=vertexInput.position; + return;*/ #ifdef debug f_color=vec4(sceneoverride(raypos,false),1); @@ -116,14 +119,14 @@ void main(){ #endif vec2 td=spheretracing(raypos,raydir,p); - #ifdef debug + /*#ifdef debug f_color=vec4(td,0,1); return; - #endif + #endif*/ vec3 n=getNormal(p,td.y); if(td.y<EPSILON) { - f_color=vec4(1.); + //f_color=vec4(1.); f_color=vec4(shading(n),1.); vec4 tpoint=camera_uniforms.proj*camera_uniforms.view*pc.world*vec4(p,1); diff --git a/src/implicit.mesh.glsl b/src/implicit.mesh.glsl index 182c116f6f1152a38695d68ce9368508332d270f..0719e88ac18608f641ab618295019f969e2cf200 100644 --- a/src/implicit.mesh.glsl +++ b/src/implicit.mesh.glsl @@ -3,6 +3,8 @@ #version 460 #extension GL_EXT_mesh_shader:require +uint DescriptionIndex; + #include "include.glsl" #include "intervals.glsl" @@ -14,35 +16,40 @@ 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 + //uint objectindex; //4 +}; //total = 992 bytes +taskPayloadSharedEXT MeshMasks meshmasks; + layout(set=0,binding=20)restrict writeonly buffer fragmentMasks{ uint8_t masks[][masklen]; }fragmentpassmasks; void main() { + uint localindex = uint(meshmasks.enabled[gl_WorkGroupID.x]); + DescriptionIndex = meshmasks.globalindex/2; //clear_stacks(); - default_mask(); - - #define CLIPCHECK 65536 - - float[6]bounds={ - CLIPCHECK-sceneoverride(vec3(CLIPCHECK,0,0),false), - CLIPCHECK-sceneoverride(vec3(0,CLIPCHECK,0),false), - CLIPCHECK-sceneoverride(vec3(0,0,CLIPCHECK),false), - -CLIPCHECK+sceneoverride(vec3(-CLIPCHECK,0,0),false), - -CLIPCHECK+sceneoverride(vec3(0,-CLIPCHECK,0),false), - -CLIPCHECK+sceneoverride(vec3(0,0,-CLIPCHECK),false), - }; + //default_mask(); + mask = meshmasks.masks[gl_WorkGroupID.x]; + vec3 bottomleft = meshmasks.bottomleft; + vec3 topright = meshmasks.topright; vec4[8]positions={ - vec4(bounds[3],bounds[4],bounds[5],1.), - vec4(bounds[3],bounds[4],bounds[2],1.), - vec4(bounds[3],bounds[1],bounds[5],1.), - vec4(bounds[3],bounds[1],bounds[2],1.), - vec4(bounds[0],bounds[4],bounds[5],1.), - vec4(bounds[0],bounds[4],bounds[2],1.), - vec4(bounds[0],bounds[1],bounds[5],1.), - vec4(bounds[0],bounds[1],bounds[2],1.), + 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.), }; //This can be optimised @@ -51,21 +58,41 @@ void main() uint vindex = gl_LocalInvocationID.x*8; uint pindex = gl_LocalInvocationID.x*6; - int GlobalInvocationIndex = int(gl_GlobalInvocationID.z*gl_NumWorkGroups.x*gl_NumWorkGroups.y+gl_GlobalInvocationID.y*gl_NumWorkGroups.x+gl_GlobalInvocationID.x); - + int GlobalInvocationIndex = int((meshmasks.globalindex*32+localindex)*32+gl_LocalInvocationID.x); + //adjust scale and position for (int i = 0; i<8; i++) { - positions[i] *= vec4(0.25,0.25,0.25,1.); - positions[i].x += (bounds[0]-bounds[3])*0.25 * (mod(gl_LocalInvocationID.x,4.)-1.5); - positions[i].y += (bounds[1]-bounds[4])*0.25 * (mod(floor(gl_LocalInvocationID.x/4.),4.)-1.5); - positions[i].z += (bounds[2]-bounds[5])*0.25 * (floor(gl_LocalInvocationID.x/16.)-1.5+gl_WorkGroupID.z*2.); + positions[i] *= vec4(0.25,0.25,0.5,1.); + positions[i].x += (topright.x-bottomleft.x)*0.25 * (mod(localindex,4.)-1.5); + positions[i].y += (topright.y-bottomleft.y)*0.25 * (mod(floor(localindex/4.),4.)-1.5); + positions[i].z += ((topright.z-bottomleft.z)*0.5 * (floor(localindex/16.)-0.5) + (topright.z+bottomleft.z)*0.25); + } + + vec4 localtopright=positions[0]; + vec4 localbottomleft=positions[7]; + + for (int i = 0; i<8; i++) + { + positions[i] *= vec4(0.25,0.25,0.5,1.); + positions[i].x += (localtopright.x-localbottomleft.x)*(0.25) * (mod(gl_LocalInvocationID.x,4.)-1.5) + (localtopright.x+localbottomleft.x)*0.375; + positions[i].y += (localtopright.y-localbottomleft.y)*(0.25) * (mod(floor(gl_LocalInvocationID.x/4.),4.)-1.5) + (localtopright.y+localbottomleft.y)*0.375; + positions[i].z += (localtopright.z-localbottomleft.z)*(0.5) * (floor(gl_LocalInvocationID.x/16.)-0.5) + (localtopright.z+localbottomleft.z)*0.25; } bvec3 signingvec=greaterThan((inverse(pc.world)*vec4(camera_uniforms.campos,1)).xyz,(positions[0].xyz+positions[7].xyz)/2); float[2] check = scene(vec3[2](vec3(positions[0].xyz),vec3(positions[7].xyz)), true); - if ((check[0] < 0) && (check[1] > 0)) + + gl_MeshPrimitivesEXT[pindex+0].gl_PrimitiveID=GlobalInvocationIndex; + gl_MeshPrimitivesEXT[pindex+1].gl_PrimitiveID=GlobalInvocationIndex; + gl_MeshPrimitivesEXT[pindex+2].gl_PrimitiveID=GlobalInvocationIndex; + gl_MeshPrimitivesEXT[pindex+3].gl_PrimitiveID=GlobalInvocationIndex; + gl_MeshPrimitivesEXT[pindex+4].gl_PrimitiveID=GlobalInvocationIndex; + gl_MeshPrimitivesEXT[pindex+5].gl_PrimitiveID=GlobalInvocationIndex; + + if ((check[0] < 0) && (check[1] > 0) && (gl_WorkGroupID.x < 32)) + //if (true) { fragmentpassmasks.masks[GlobalInvocationIndex]=mask; @@ -85,6 +112,14 @@ void main() vertexOutput[vindex+5].position=(positions[5]); vertexOutput[vindex+6].position=(positions[6]); vertexOutput[vindex+7].position=(positions[7]); + /*vertexOutput[vindex+0].position=vec4(bottomleft,1.); + vertexOutput[vindex+1].position=vec4(bottomleft.x,bottomleft.y,topright.z,1.); + vertexOutput[vindex+2].position=vec4(bottomleft.x,topright.y,bottomleft.z,1.); + vertexOutput[vindex+3].position=vec4(bottomleft.x,topright.y,topright.z,1.); + vertexOutput[vindex+4].position=vec4(topright.x,bottomleft.y,bottomleft.z,1.); + vertexOutput[vindex+5].position=vec4(topright.x,bottomleft.y,topright.z,1.); + vertexOutput[vindex+6].position=vec4(topright.x,topright.y,bottomleft.z,1.); + vertexOutput[vindex+7].position=vec4(topright,1.);*/ if(signingvec.x){ gl_PrimitiveTriangleIndicesEXT[pindex+0]=uvec3(4,5,6)+uvec3(vindex); @@ -108,22 +143,16 @@ void main() gl_PrimitiveTriangleIndicesEXT[pindex+5]=uvec3(2,4,6)+uvec3(vindex); } - gl_MeshPrimitivesEXT[pindex+0].gl_PrimitiveID=GlobalInvocationIndex; - gl_MeshPrimitivesEXT[pindex+1].gl_PrimitiveID=GlobalInvocationIndex; - gl_MeshPrimitivesEXT[pindex+2].gl_PrimitiveID=GlobalInvocationIndex; - gl_MeshPrimitivesEXT[pindex+3].gl_PrimitiveID=GlobalInvocationIndex; - gl_MeshPrimitivesEXT[pindex+4].gl_PrimitiveID=GlobalInvocationIndex; - gl_MeshPrimitivesEXT[pindex+5].gl_PrimitiveID=GlobalInvocationIndex; } else { - gl_MeshVerticesEXT[vindex+0].gl_Position=vec4(0,0,0,1); - gl_MeshVerticesEXT[vindex+1].gl_Position=vec4(0,0,0,1); - gl_MeshVerticesEXT[vindex+2].gl_Position=vec4(0,0,0,1); - gl_MeshVerticesEXT[vindex+3].gl_Position=vec4(0,0,0,1); - gl_MeshVerticesEXT[vindex+4].gl_Position=vec4(0,0,0,1); - gl_MeshVerticesEXT[vindex+5].gl_Position=vec4(0,0,0,1); - gl_MeshVerticesEXT[vindex+6].gl_Position=vec4(0,0,0,1); - gl_MeshVerticesEXT[vindex+7].gl_Position=vec4(0,0,0,1); + gl_MeshVerticesEXT[vindex+0].gl_Position=mvp*(vec4(0,0,0,1)); + gl_MeshVerticesEXT[vindex+1].gl_Position=mvp*(vec4(0,0,0,1)); + gl_MeshVerticesEXT[vindex+2].gl_Position=mvp*(vec4(0,0,0,1)); + gl_MeshVerticesEXT[vindex+3].gl_Position=mvp*(vec4(0,0,0,1)); + gl_MeshVerticesEXT[vindex+4].gl_Position=mvp*(vec4(0,0,0,1)); + gl_MeshVerticesEXT[vindex+5].gl_Position=mvp*(vec4(0,0,0,1)); + gl_MeshVerticesEXT[vindex+6].gl_Position=mvp*(vec4(0,0,0,1)); + gl_MeshVerticesEXT[vindex+7].gl_Position=mvp*(vec4(0,0,0,1)); gl_PrimitiveTriangleIndicesEXT[pindex+0]=uvec3(vindex); gl_PrimitiveTriangleIndicesEXT[pindex+1]=uvec3(vindex); @@ -131,12 +160,5 @@ void main() gl_PrimitiveTriangleIndicesEXT[pindex+3]=uvec3(vindex); gl_PrimitiveTriangleIndicesEXT[pindex+4]=uvec3(vindex); gl_PrimitiveTriangleIndicesEXT[pindex+5]=uvec3(vindex); - - gl_MeshPrimitivesEXT[pindex+0].gl_PrimitiveID=0; - gl_MeshPrimitivesEXT[pindex+1].gl_PrimitiveID=0; - gl_MeshPrimitivesEXT[pindex+2].gl_PrimitiveID=0; - gl_MeshPrimitivesEXT[pindex+3].gl_PrimitiveID=0; - gl_MeshPrimitivesEXT[pindex+4].gl_PrimitiveID=0; - gl_MeshPrimitivesEXT[pindex+5].gl_PrimitiveID=0; } } \ No newline at end of file diff --git a/src/implicit.task.glsl b/src/implicit.task.glsl new file mode 100644 index 0000000000000000000000000000000000000000..01beb21b497a3453e52c954a811592dc68267717 --- /dev/null +++ b/src/implicit.task.glsl @@ -0,0 +1,92 @@ +// Implicit Mesh shader + +#version 460 +#extension GL_EXT_mesh_shader:require + +#define DescriptionIndex gl_WorkGroupID.x + +#include "include.glsl" +#include "intervals.glsl" + +layout(local_size_x=32,local_size_y=1,local_size_z=1)in; + +struct MeshMasks +{ + uint8_t masks[32][masklen]; //928 + uint8_t enabled[32]; //32 + vec3 bottomleft; //12 + vec3 topright; //12 + uint globalindex; //4 + //uint objectindex; //4 +}; //total = 992 bytes +taskPayloadSharedEXT MeshMasks meshmasks; + +shared uint index; + +void main() +{ + //clear_stacks(); + default_mask(); + meshmasks.masks[gl_LocalInvocationID.x] = mask; + + if (gl_LocalInvocationID.x==0) + { + index=0; + } + + #define CLIPCHECK 65536 + + float[6]bounds={ + CLIPCHECK-sceneoverride(vec3(CLIPCHECK,0,0),false), + CLIPCHECK-sceneoverride(vec3(0,CLIPCHECK,0),false), + CLIPCHECK-sceneoverride(vec3(0,0,CLIPCHECK),false), + -CLIPCHECK+sceneoverride(vec3(-CLIPCHECK,0,0),false), + -CLIPCHECK+sceneoverride(vec3(0,-CLIPCHECK,0),false), + -CLIPCHECK+sceneoverride(vec3(0,0,-CLIPCHECK),false), + }; + /*const float[6]bounds={ + 1,1,1,-1,-1,-1, + };*/ + + vec3 bottomleft = vec3(bounds[3],bounds[4],bounds[5]); + vec3 topright = vec3(bounds[0],bounds[1],bounds[2]); + vec3 center = (topright + bottomleft) / 2; + +#define adjust(var) var -= center;\ + var *= vec3(0.25,0.25,0.25);\ + var.x += (bounds[0]-bounds[3]) * 0.25 * (mod(gl_LocalInvocationID.x,4.)-1.5) ;\ + var.y += (bounds[1]-bounds[4]) * 0.25 * (mod(floor(gl_LocalInvocationID.x/4.),4.)-1.5) ;\ + var.z += (bounds[2]-bounds[5]) * 0.25 * (floor(gl_LocalInvocationID.x/16.)-1.5+gl_WorkGroupID.z*2.) ;\ + var += center; + + + adjust(bottomleft); + adjust(topright); + + barrier(); + + float[2] check = scene(vec3[2](bottomleft,topright), false); + //float[2] check = scene(vec3[2](vec3(bounds[3],bounds[4],bounds[5]),vec3(bounds[0],bounds[1],bounds[2])), false); + + if ((check[0] < 0) && (check[1] > 0)) + //if ((bottomleft.x >= -1) && (bottomleft.y >= -1) && (bottomleft.z >= -1) && (topright.x <= 1) && (topright.y <= 1) && (topright.z <= 1)) + //if ((gl_LocalInvocationID.x == 0) && (bottomleft.x >= 0)) + { + uint localindex = atomicAdd(index, 1); + //if (localindex < 32) { + meshmasks.masks[localindex]=mask; + meshmasks.enabled[localindex]=uint8_t(gl_LocalInvocationID.x); + //} + } + + if (gl_LocalInvocationID.x==0) + { + meshmasks.bottomleft = vec3(bounds[3],bounds[4],(bounds[5]*0.5) + ((bounds[2]-bounds[5])*0.5 * (-0.5+gl_WorkGroupID.z))); + meshmasks.topright = vec3(bounds[0],bounds[1],(bounds[2]*0.5) + ((bounds[2]-bounds[5])*0.5 * (-0.5+gl_WorkGroupID.z))); + meshmasks.globalindex = gl_WorkGroupID.x*2+gl_WorkGroupID.z; + //meshmasks.objectindex = DescriptionIndex; + } + + barrier(); + EmitMeshTasksEXT(index,1,1); +} \ No newline at end of file diff --git a/src/instructionset.glsl b/src/instructionset.glsl index 007bb5892651b5e2d7c065fc1fa4b0610906e088..81432a4ad6e511fd4092f0abb729f94d7cb947ee 100644 --- a/src/instructionset.glsl +++ b/src/instructionset.glsl @@ -1,219 +1,219 @@ -const uint OPNop=__LINE__-1; -const uint OPStop=__LINE__-1; -const uint OPAddFloatFloat=__LINE__-1; -const uint OPAddVec2Vec2=__LINE__-1; -const uint OPAddVec2Float=__LINE__-1; -const uint OPAddVec3Vec3=__LINE__-1; -const uint OPAddVec3Float=__LINE__-1; -const uint OPAddVec4Vec4=__LINE__-1; -const uint OPAddVec4Float=__LINE__-1; -const uint OPSubFloatFloat=__LINE__-1; -const uint OPSubVec2Vec2=__LINE__-1; -const uint OPSubVec2Float=__LINE__-1; -const uint OPSubVec3Vec3=__LINE__-1; -const uint OPSubVec3Float=__LINE__-1; -const uint OPSubVec4Vec4=__LINE__-1; -const uint OPSubVec4Float=__LINE__-1; -const uint OPMulFloatFloat=__LINE__-1; -const uint OPMulVec2Vec2=__LINE__-1; -const uint OPMulVec2Float=__LINE__-1; -const uint OPMulVec3Vec3=__LINE__-1; -const uint OPMulVec3Float=__LINE__-1; -const uint OPMulVec4Vec4=__LINE__-1; -const uint OPMulVec4Float=__LINE__-1; -const uint OPDivFloatFloat=__LINE__-1; -const uint OPDivVec2Vec2=__LINE__-1; -const uint OPDivVec2Float=__LINE__-1; -const uint OPDivVec3Vec3=__LINE__-1; -const uint OPDivVec3Float=__LINE__-1; -const uint OPDivVec4Vec4=__LINE__-1; -const uint OPDivVec4Float=__LINE__-1; -const uint OPModFloatFloat=__LINE__-1; -const uint OPModVec2Vec2=__LINE__-1; -const uint OPModVec2Float=__LINE__-1; -const uint OPModVec3Vec3=__LINE__-1; -const uint OPModVec3Float=__LINE__-1; -const uint OPModVec4Vec4=__LINE__-1; -const uint OPModVec4Float=__LINE__-1; -const uint OPPowFloatFloat=__LINE__-1; -const uint OPPowVec2Vec2=__LINE__-1; -const uint OPPowVec3Vec3=__LINE__-1; -const uint OPPowVec4Vec4=__LINE__-1; -const uint OPCrossVec3=__LINE__-1; -const uint OPDotVec2=__LINE__-1; -const uint OPDotVec3=__LINE__-1; -const uint OPDotVec4=__LINE__-1; -const uint OPLengthVec2=__LINE__-1; -const uint OPLengthVec3=__LINE__-1; -const uint OPLengthVec4=__LINE__-1; -const uint OPDistanceVec2=__LINE__-1; -const uint OPDistanceVec3=__LINE__-1; -const uint OPDistanceVec4=__LINE__-1; -const uint OPNormalizeVec2=__LINE__-1; -const uint OPNormalizeVec3=__LINE__-1; -const uint OPNormalizeVec4=__LINE__-1; -const uint OPAbsFloat=__LINE__-1; -const uint OPSignFloat=__LINE__-1; -const uint OPFloorFloat=__LINE__-1; -const uint OPCeilFloat=__LINE__-1; -const uint OPFractFloat=__LINE__-1; -const uint OPSqrtFloat=__LINE__-1; -const uint OPInverseSqrtFloat=__LINE__-1; -const uint OPExpFloat=__LINE__-1; -const uint OPExp2Float=__LINE__-1; -const uint OPLogFloat=__LINE__-1; -const uint OPLog2Float=__LINE__-1; -const uint OPSinFloat=__LINE__-1; -const uint OPCosFloat=__LINE__-1; -const uint OPTanFloat=__LINE__-1; -const uint OPAsinFloat=__LINE__-1; -const uint OPAcosFloat=__LINE__-1; -const uint OPAtanFloat=__LINE__-1; -const uint OPMinFloat=__LINE__-1; -const uint OPMaxFloat=__LINE__-1; -const uint OPSmoothMinFloat=__LINE__-1; -const uint OPSmoothMaxFloat=__LINE__-1; -const uint OPMinMaterialFloat=__LINE__-1; -const uint OPMaxMaterialFloat=__LINE__-1; -const uint OPSmoothMinMaterialFloat=__LINE__-1; -const uint OPSmoothMaxMaterialFloat=__LINE__-1; -const uint OPDupFloat=__LINE__-1; -const uint OPDup2Float=__LINE__-1; -const uint OPDup3Float=__LINE__-1; -const uint OPDup4Float=__LINE__-1; -const uint OPAbsVec2=__LINE__-1; -const uint OPSignVec2=__LINE__-1; -const uint OPFloorVec2=__LINE__-1; -const uint OPCeilVec2=__LINE__-1; -const uint OPFractVec2=__LINE__-1; -const uint OPSqrtVec2=__LINE__-1; -const uint OPInverseSqrtVec2=__LINE__-1; -const uint OPExpVec2=__LINE__-1; -const uint OPExp2Vec2=__LINE__-1; -const uint OPLogVec2=__LINE__-1; -const uint OPLog2Vec2=__LINE__-1; -const uint OPSinVec2=__LINE__-1; -const uint OPCosVec2=__LINE__-1; -const uint OPTanVec2=__LINE__-1; -const uint OPAsinVec2=__LINE__-1; -const uint OPAcosVec2=__LINE__-1; -const uint OPAtanVec2=__LINE__-1; -const uint OPMinVec2=__LINE__-1; -const uint OPMaxVec2=__LINE__-1; -const uint OPDupVec2=__LINE__-1; -const uint OPDup2Vec2=__LINE__-1; -const uint OPDup3Vec2=__LINE__-1; -const uint OPDup4Vec2=__LINE__-1; -const uint OPAbsVec3=__LINE__-1; -const uint OPSignVec3=__LINE__-1; -const uint OPFloorVec3=__LINE__-1; -const uint OPCeilVec3=__LINE__-1; -const uint OPFractVec3=__LINE__-1; -const uint OPSqrtVec3=__LINE__-1; -const uint OPInverseSqrtVec3=__LINE__-1; -const uint OPExpVec3=__LINE__-1; -const uint OPExp2Vec3=__LINE__-1; -const uint OPLogVec3=__LINE__-1; -const uint OPLog2Vec3=__LINE__-1; -const uint OPSinVec3=__LINE__-1; -const uint OPCosVec3=__LINE__-1; -const uint OPTanVec3=__LINE__-1; -const uint OPAsinVec3=__LINE__-1; -const uint OPAcosVec3=__LINE__-1; -const uint OPAtanVec3=__LINE__-1; -const uint OPMinVec3=__LINE__-1; -const uint OPMaxVec3=__LINE__-1; -const uint OPDupVec3=__LINE__-1; -const uint OPDup2Vec3=__LINE__-1; -const uint OPDup3Vec3=__LINE__-1; -const uint OPDup4Vec3=__LINE__-1; -const uint OPAbsVec4=__LINE__-1; -const uint OPSignVec4=__LINE__-1; -const uint OPFloorVec4=__LINE__-1; -const uint OPCeilVec4=__LINE__-1; -const uint OPFractVec4=__LINE__-1; -const uint OPSqrtVec4=__LINE__-1; -const uint OPInverseSqrtVec4=__LINE__-1; -const uint OPExpVec4=__LINE__-1; -const uint OPExp2Vec4=__LINE__-1; -const uint OPLogVec4=__LINE__-1; -const uint OPLog2Vec4=__LINE__-1; -const uint OPSinVec4=__LINE__-1; -const uint OPCosVec4=__LINE__-1; -const uint OPTanVec4=__LINE__-1; -const uint OPAsinVec4=__LINE__-1; -const uint OPAcosVec4=__LINE__-1; -const uint OPAtanVec4=__LINE__-1; -const uint OPMinVec4=__LINE__-1; -const uint OPMaxVec4=__LINE__-1; -const uint OPDupVec4=__LINE__-1; -const uint OPDup2Vec4=__LINE__-1; -const uint OPDup3Vec4=__LINE__-1; -const uint OPDup4Vec4=__LINE__-1; -const uint OPPromoteFloatFloatVec2=__LINE__-1; -const uint OPPromoteFloatFloatFloatVec3=__LINE__-1; -const uint OPPromoteFloatFloatFloatFloatVec4=__LINE__-1; -const uint OPPromoteVec2FloatVec3=__LINE__-1; -const uint OPPromoteVec2FloatFloatVec4=__LINE__-1; -const uint OPPromoteVec2Vec2Vec4=__LINE__-1; -const uint OPPromoteVec3FloatVec4=__LINE__-1; -const uint OPAcoshFloat=__LINE__-1; -const uint OPAcoshVec2=__LINE__-1; -const uint OPAcoshVec3=__LINE__-1; -const uint OPAcoshVec4=__LINE__-1; -const uint OPAsinhFloat=__LINE__-1; -const uint OPAsinhVec2=__LINE__-1; -const uint OPAsinhVec3=__LINE__-1; -const uint OPAsinhVec4=__LINE__-1; -const uint OPAtanhFloat=__LINE__-1; -const uint OPAtanhVec2=__LINE__-1; -const uint OPAtanhVec3=__LINE__-1; -const uint OPAtanhVec4=__LINE__-1; -const uint OPCoshFloat=__LINE__-1; -const uint OPCoshVec2=__LINE__-1; -const uint OPCoshVec3=__LINE__-1; -const uint OPCoshVec4=__LINE__-1; -const uint OPSinhFloat=__LINE__-1; -const uint OPSinhVec2=__LINE__-1; -const uint OPSinhVec3=__LINE__-1; -const uint OPSinhVec4=__LINE__-1; -const uint OPTanhFloat=__LINE__-1; -const uint OPTanhVec2=__LINE__-1; -const uint OPTanhVec3=__LINE__-1; -const uint OPTanhVec4=__LINE__-1; -const uint OPRoundFloat=__LINE__-1; -const uint OPRoundVec2=__LINE__-1; -const uint OPRoundVec3=__LINE__-1; -const uint OPRoundVec4=__LINE__-1; -const uint OPTruncFloat=__LINE__-1; -const uint OPTruncVec2=__LINE__-1; -const uint OPTruncVec3=__LINE__-1; -const uint OPTruncVec4=__LINE__-1; -const uint OPFMAFloat=__LINE__-1; -const uint OPFMAVec2=__LINE__-1; -const uint OPFMAVec3=__LINE__-1; -const uint OPFMAVec4=__LINE__-1; -const uint OPClampFloatFloat=__LINE__-1; -const uint OPClampVec2Vec2=__LINE__-1; -const uint OPClampVec2Float=__LINE__-1; -const uint OPClampVec3Vec3=__LINE__-1; -const uint OPClampVec3Float=__LINE__-1; -const uint OPClampVec4Vec4=__LINE__-1; -const uint OPClampVec4Float=__LINE__-1; -const uint OPMixFloatFloat=__LINE__-1; -const uint OPMixVec2Vec2=__LINE__-1; -const uint OPMixVec2Float=__LINE__-1; -const uint OPMixVec3Vec3=__LINE__-1; -const uint OPMixVec3Float=__LINE__-1; -const uint OPMixVec4Vec4=__LINE__-1; -const uint OPMixVec4Float=__LINE__-1; -const uint OPSquareFloat=__LINE__-1; -const uint OPCubeFloat=__LINE__-1; -const uint OPSquareVec2=__LINE__-1; -const uint OPCubeVec2=__LINE__-1; -const uint OPSquareVec3=__LINE__-1; -const uint OPCubeVec3=__LINE__-1; -const uint OPSquareVec4=__LINE__-1; -const uint OPCubeVec4=__LINE__-1; -const uint OPSDFSphere=__LINE__-1; -const uint OPInvalid=__LINE__-1; \ No newline at end of file +const uint OPNop=__LINE__-1; // // +const uint OPStop=__LINE__-1; //F // +const uint OPAddFloatFloat=__LINE__-1; //F F //F +const uint OPAddVec2Vec2=__LINE__-1; //V2 V2 //V2 +const uint OPAddVec2Float=__LINE__-1; //V2 F //V2 +const uint OPAddVec3Vec3=__LINE__-1; //V3 V3 //V3 +const uint OPAddVec3Float=__LINE__-1; //V3 F //V3 +const uint OPAddVec4Vec4=__LINE__-1; //V4 V4 //V4 +const uint OPAddVec4Float=__LINE__-1; //V4 F //V4 +const uint OPSubFloatFloat=__LINE__-1; //F F //F +const uint OPSubVec2Vec2=__LINE__-1; //V2 V2 //V2 +const uint OPSubVec2Float=__LINE__-1; //V2 F //V2 +const uint OPSubVec3Vec3=__LINE__-1; //V3 V3 //V3 +const uint OPSubVec3Float=__LINE__-1; //V3 F //V3 +const uint OPSubVec4Vec4=__LINE__-1; //V4 V4 //V4 +const uint OPSubVec4Float=__LINE__-1; //V4 F //V4 +const uint OPMulFloatFloat=__LINE__-1; //F F //F +const uint OPMulVec2Vec2=__LINE__-1; //V2 V2 //V2 +const uint OPMulVec2Float=__LINE__-1; //V2 F //V2 +const uint OPMulVec3Vec3=__LINE__-1; //V3 V3 //V3 +const uint OPMulVec3Float=__LINE__-1; //V3 F //V3 +const uint OPMulVec4Vec4=__LINE__-1; //V4 V4 //V4 +const uint OPMulVec4Float=__LINE__-1; //V4 F //V4 +const uint OPDivFloatFloat=__LINE__-1; //F F //F +const uint OPDivVec2Vec2=__LINE__-1; //V2 V2 //V2 +const uint OPDivVec2Float=__LINE__-1; //V2 F //V2 +const uint OPDivVec3Vec3=__LINE__-1; //V3 V3 //V3 +const uint OPDivVec3Float=__LINE__-1; //V3 F //V3 +const uint OPDivVec4Vec4=__LINE__-1; //V4 V4 //V4 +const uint OPDivVec4Float=__LINE__-1; //V4 F //V4 +const uint OPModFloatFloat=__LINE__-1; //F F //F +const uint OPModVec2Vec2=__LINE__-1; //V2 V2 //V2 +const uint OPModVec2Float=__LINE__-1; //V2 F //V2 +const uint OPModVec3Vec3=__LINE__-1; //V3 V3 //V3 +const uint OPModVec3Float=__LINE__-1; //V3 F //V3 +const uint OPModVec4Vec4=__LINE__-1; //V4 V4 //V4 +const uint OPModVec4Float=__LINE__-1; //V4 F //V4 +const uint OPPowFloatFloat=__LINE__-1; //F F //F +const uint OPPowVec2Vec2=__LINE__-1; //V2 V2 //V2 +const uint OPPowVec3Vec3=__LINE__-1; //V3 V3 //V3 +const uint OPPowVec4Vec4=__LINE__-1; //V4 V4 //V4 +const uint OPCrossVec3=__LINE__-1; //V3 V3 //V3 +const uint OPDotVec2=__LINE__-1; //V2 V2 //F +const uint OPDotVec3=__LINE__-1; //V3 V3 //F +const uint OPDotVec4=__LINE__-1; //V4 V4 //F +const uint OPLengthVec2=__LINE__-1; //V2 //F +const uint OPLengthVec3=__LINE__-1; //V3 //F +const uint OPLengthVec4=__LINE__-1; //V4 //F +const uint OPDistanceVec2=__LINE__-1; //V2 V2 //F +const uint OPDistanceVec3=__LINE__-1; //V3 V3 //F +const uint OPDistanceVec4=__LINE__-1; //V4 V4 //F +const uint OPNormalizeVec2=__LINE__-1; //V2 //V2 +const uint OPNormalizeVec3=__LINE__-1; //V2 //V2 +const uint OPNormalizeVec4=__LINE__-1; //V4 //V4 +const uint OPAbsFloat=__LINE__-1; //F //F +const uint OPSignFloat=__LINE__-1; //F //F +const uint OPFloorFloat=__LINE__-1; //F //F +const uint OPCeilFloat=__LINE__-1; //F //F +const uint OPFractFloat=__LINE__-1; //F //F +const uint OPSqrtFloat=__LINE__-1; //F //F +const uint OPInverseSqrtFloat=__LINE__-1; //F //F +const uint OPExpFloat=__LINE__-1; //F //F +const uint OPExp2Float=__LINE__-1; //F //F +const uint OPLogFloat=__LINE__-1; //F //F +const uint OPLog2Float=__LINE__-1; //F //F +const uint OPSinFloat=__LINE__-1; //F //F +const uint OPCosFloat=__LINE__-1; //F //F +const uint OPTanFloat=__LINE__-1; //F //F +const uint OPAsinFloat=__LINE__-1; //F //F +const uint OPAcosFloat=__LINE__-1; //F //F +const uint OPAtanFloat=__LINE__-1; //F //F +const uint OPMinFloat=__LINE__-1; //F F //F +const uint OPMaxFloat=__LINE__-1; //F F //F +const uint OPSmoothMinFloat=__LINE__-1; //F F F //F +const uint OPSmoothMaxFloat=__LINE__-1; //F F F //F +const uint OPMinMaterialFloat=__LINE__-1; //F F //F +const uint OPMaxMaterialFloat=__LINE__-1; //F F //F +const uint OPSmoothMinMaterialFloat=__LINE__-1; //F F F //F +const uint OPSmoothMaxMaterialFloat=__LINE__-1; //F F F //F +const uint OPDupFloat=__LINE__-1; //F //F F +const uint OPDup2Float=__LINE__-1; //F //F F +const uint OPDup3Float=__LINE__-1; //F //F F +const uint OPDup4Float=__LINE__-1; //F //F F +const uint OPAbsVec2=__LINE__-1; //V2 //V2 +const uint OPSignVec2=__LINE__-1; //V2 //V2 +const uint OPFloorVec2=__LINE__-1; //V2 //V2 +const uint OPCeilVec2=__LINE__-1; //V2 //V2 +const uint OPFractVec2=__LINE__-1; //V2 //V2 +const uint OPSqrtVec2=__LINE__-1; //V2 //V2 +const uint OPInverseSqrtVec2=__LINE__-1; //V2 //V2 +const uint OPExpVec2=__LINE__-1; //V2 //V2 +const uint OPExp2Vec2=__LINE__-1; //V2 //V2 +const uint OPLogVec2=__LINE__-1; //V2 //V2 +const uint OPLog2Vec2=__LINE__-1; //V2 //V2 +const uint OPSinVec2=__LINE__-1; //V2 //V2 +const uint OPCosVec2=__LINE__-1; //V2 //V2 +const uint OPTanVec2=__LINE__-1; //V2 //V2 +const uint OPAsinVec2=__LINE__-1; //V2 //V2 +const uint OPAcosVec2=__LINE__-1; //V2 //V2 +const uint OPAtanVec2=__LINE__-1; //V2 //V2 +const uint OPMinVec2=__LINE__-1; //V2 V2 //V2 +const uint OPMaxVec2=__LINE__-1; //V2 V2 //V2 +const uint OPDupVec2=__LINE__-1; //V2 //V2 V2 +const uint OPDup2Vec2=__LINE__-1; //V2 //V2 V2 +const uint OPDup3Vec2=__LINE__-1; //V2 //V2 V2 +const uint OPDup4Vec2=__LINE__-1; //V2 //V2 V2 +const uint OPAbsVec3=__LINE__-1; //V3 //V3 +const uint OPSignVec3=__LINE__-1; //V3 //V3 +const uint OPFloorVec3=__LINE__-1; //V3 //V3 +const uint OPCeilVec3=__LINE__-1; //V3 //V3 +const uint OPFractVec3=__LINE__-1; //V3 //V3 +const uint OPSqrtVec3=__LINE__-1; //V3 //V3 +const uint OPInverseSqrtVec3=__LINE__-1; //V3 //V3 +const uint OPExpVec3=__LINE__-1; //V3 //V3 +const uint OPExp2Vec3=__LINE__-1; //V3 //V3 +const uint OPLogVec3=__LINE__-1; //V3 //V3 +const uint OPLog2Vec3=__LINE__-1; //V3 //V3 +const uint OPSinVec3=__LINE__-1; //V3 //V3 +const uint OPCosVec3=__LINE__-1; //V3 //V3 +const uint OPTanVec3=__LINE__-1; //V3 //V3 +const uint OPAsinVec3=__LINE__-1; //V3 //V3 +const uint OPAcosVec3=__LINE__-1; //V3 //V3 +const uint OPAtanVec3=__LINE__-1; //V3 //V3 +const uint OPMinVec3=__LINE__-1; //V3 V3 //V3 +const uint OPMaxVec3=__LINE__-1; //V3 V3 //V3 +const uint OPDupVec3=__LINE__-1; //V3 //V3 V3 +const uint OPDup2Vec3=__LINE__-1; //V3 //V3 V3 +const uint OPDup3Vec3=__LINE__-1; //V3 //V3 V3 +const uint OPDup4Vec3=__LINE__-1; //V3 //V3 V3 +const uint OPAbsVec4=__LINE__-1; //V4 //V4 +const uint OPSignVec4=__LINE__-1; //V4 //V4 +const uint OPFloorVec4=__LINE__-1; //V4 //V4 +const uint OPCeilVec4=__LINE__-1; //V4 //V4 +const uint OPFractVec4=__LINE__-1; //V4 //V4 +const uint OPSqrtVec4=__LINE__-1; //V4 //V4 +const uint OPInverseSqrtVec4=__LINE__-1; //V4 //V4 +const uint OPExpVec4=__LINE__-1; //V4 //V4 +const uint OPExp2Vec4=__LINE__-1; //V4 //V4 +const uint OPLogVec4=__LINE__-1; //V4 //V4 +const uint OPLog2Vec4=__LINE__-1; //V4 //V4 +const uint OPSinVec4=__LINE__-1; //V4 //V4 +const uint OPCosVec4=__LINE__-1; //V4 //V4 +const uint OPTanVec4=__LINE__-1; //V4 //V4 +const uint OPAsinVec4=__LINE__-1; //V4 //V4 +const uint OPAcosVec4=__LINE__-1; //V4 //V4 +const uint OPAtanVec4=__LINE__-1; //V4 //V4 +const uint OPMinVec4=__LINE__-1; //V4 V4 //V4 +const uint OPMaxVec4=__LINE__-1; //V4 V4 //V4 +const uint OPDupVec4=__LINE__-1; //V4 //V4 V4 +const uint OPDup2Vec4=__LINE__-1; //V4 //V4 V4 +const uint OPDup3Vec4=__LINE__-1; //V4 //V4 V4 +const uint OPDup4Vec4=__LINE__-1; //V4 //V4 V4 +const uint OPPromoteFloatFloatVec2=__LINE__-1; //F F //V2 +const uint OPPromoteFloatFloatFloatVec3=__LINE__-1; //F F F //V3 +const uint OPPromoteFloatFloatFloatFloatVec4=__LINE__-1; //F F F F //V4 +const uint OPPromoteVec2FloatVec3=__LINE__-1; //V2 F //V3 +const uint OPPromoteVec2FloatFloatVec4=__LINE__-1; //V2 F F //V4 +const uint OPPromoteVec2Vec2Vec4=__LINE__-1; //V2 V2 //V4 +const uint OPPromoteVec3FloatVec4=__LINE__-1; //V3 F //V4 +const uint OPAcoshFloat=__LINE__-1; //F //F +const uint OPAcoshVec2=__LINE__-1; //V2 //V2 +const uint OPAcoshVec3=__LINE__-1; //V3 //V3 +const uint OPAcoshVec4=__LINE__-1; //V4 //V4 +const uint OPAsinhFloat=__LINE__-1; //F //F +const uint OPAsinhVec2=__LINE__-1; //V2 //V2 +const uint OPAsinhVec3=__LINE__-1; //V3 //V3 +const uint OPAsinhVec4=__LINE__-1; //V4 //V4 +const uint OPAtanhFloat=__LINE__-1; //F //F +const uint OPAtanhVec2=__LINE__-1; //V2 //V2 +const uint OPAtanhVec3=__LINE__-1; //V3 //V3 +const uint OPAtanhVec4=__LINE__-1; //V4 //V4 +const uint OPCoshFloat=__LINE__-1; //F //F +const uint OPCoshVec2=__LINE__-1; //V2 //V2 +const uint OPCoshVec3=__LINE__-1; //V3 //V3 +const uint OPCoshVec4=__LINE__-1; //V4 //V4 +const uint OPSinhFloat=__LINE__-1; //F //F +const uint OPSinhVec2=__LINE__-1; //V2 //V2 +const uint OPSinhVec3=__LINE__-1; //V3 //V3 +const uint OPSinhVec4=__LINE__-1; //V4 //V4 +const uint OPTanhFloat=__LINE__-1; //F //F +const uint OPTanhVec2=__LINE__-1; //V2 //V2 +const uint OPTanhVec3=__LINE__-1; //V3 //V3 +const uint OPTanhVec4=__LINE__-1; //V4 //V4 +const uint OPRoundFloat=__LINE__-1; //F //F +const uint OPRoundVec2=__LINE__-1; //V2 //V2 +const uint OPRoundVec3=__LINE__-1; //V3 //V3 +const uint OPRoundVec4=__LINE__-1; //V4 //V4 +const uint OPTruncFloat=__LINE__-1; //F //F +const uint OPTruncVec2=__LINE__-1; //V2 //V2 +const uint OPTruncVec3=__LINE__-1; //V3 //V3 +const uint OPTruncVec4=__LINE__-1; //V4 //V4 +const uint OPFMAFloat=__LINE__-1; //F //F +const uint OPFMAVec2=__LINE__-1; //V2 //V2 +const uint OPFMAVec3=__LINE__-1; //V3 //V3 +const uint OPFMAVec4=__LINE__-1; //V4 //V4 +const uint OPClampFloatFloat=__LINE__-1; //F F F //F +const uint OPClampVec2Vec2=__LINE__-1; //V2 V2 V2 //V2 +const uint OPClampVec2Float=__LINE__-1; //V2 F F //V2 +const uint OPClampVec3Vec3=__LINE__-1; //V3 V3 V3 //V3 +const uint OPClampVec3Float=__LINE__-1; //V3 F F //V3 +const uint OPClampVec4Vec4=__LINE__-1; //V4 V4 V4 //V4 +const uint OPClampVec4Float=__LINE__-1; //V4 F F //V4 +const uint OPMixFloatFloat=__LINE__-1; //F F F //F +const uint OPMixVec2Vec2=__LINE__-1; //V2 V2 V2 //V2 +const uint OPMixVec2Float=__LINE__-1; //V2 V2 F //V2 +const uint OPMixVec3Vec3=__LINE__-1; //V3 V3 V3 //V3 +const uint OPMixVec3Float=__LINE__-1; //V3 V3 F //V3 +const uint OPMixVec4Vec4=__LINE__-1; //V4 V4 V4 //V4 +const uint OPMixVec4Float=__LINE__-1; //V4 V4 F //V4 +const uint OPSquareFloat=__LINE__-1; //F //F +const uint OPCubeFloat=__LINE__-1; //F //F +const uint OPSquareVec2=__LINE__-1; //V2 //V2 +const uint OPCubeVec2=__LINE__-1; //V2 //V2 +const uint OPSquareVec3=__LINE__-1; //V3 //V3 +const uint OPCubeVec3=__LINE__-1; //V3 //V3 +const uint OPSquareVec4=__LINE__-1; //V4 //V4 +const uint OPCubeVec4=__LINE__-1; //V4 //V4 +const uint OPSDFSphere=__LINE__-1; //F V3 //F +const uint OPInvalid=__LINE__-1; // // \ No newline at end of file diff --git a/src/interpreter.rs b/src/interpreter.rs new file mode 100644 index 0000000000000000000000000000000000000000..1ec71da17a7953ac054f5504cfb37b835e9e3925 --- /dev/null +++ b/src/interpreter.rs @@ -0,0 +1,3092 @@ +use crate::instruction_set::InstructionSet; + +use cgmath::{ + Deg, EuclideanSpace, Euler, Matrix2, Matrix3, Matrix4, Point3, Rad, SquareMatrix, Vector2, + Vector3, Vector4, +}; + +struct Interpreter<'csg> +{ + float_stack: [[f32;2];8], + float_stack_head: usize, + vec2_stack: [[Vector2;2];8], + vec2_stack_head: usize, + vec3_stack: [[Vector3;2];8], + vec3_stack_head: usize, + vec4_stack: [[Vector4;2];8], + vec4_stack_head: usize, + mat2_stack: [[Matrix2;2];1], + mat2_stack_head: usize, + mat3_stack: [[Matrix3;2];1], + mat3_stack_head: usize, + mat4_stack: [[Matrix4;2];1], + mat4_stack_head: usize, + + 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, +} +impl<'csg> Interpreter<'csg> +{ + +fn push_float(f: [f32;2]) -> () { + float_stack[float_stack_head]=f; + float_stack_head+=1; +} + +fn pull_float(c: bool) -> [f32;2] { + if c { + let f = fconst.floats[float_const_head]; + float_const_head+=1; + return float[2](f,f); + } + else { + return float_stack[--float_stack_head]; + } +} + +float cpull_float(){ + return fconst.floats[float_const_head++]; +} + +void push_vec2(vec2 f[2]){ + vec2_stack[vec2_stack_head++]=f; +} + +vec2[2]pull_vec2(bool c){ + if (c) { + vec2 f = v2const.vec2s[vec2_const_head++]; + return vec2[2](f,f); + } + else { + return vec2_stack[--vec2_stack_head]; + } +} + +vec2 cpull_vec2(){ + return v2const.vec2s[vec2_const_head++]; +} + +void push_vec3(vec3 f[2]){ + vec3_stack[vec3_stack_head++]=f; +} + +vec3[2]pull_vec3(bool c){ + if (c) { + vec3 f = v3const.vec3s[vec3_const_head++]; + return vec3[2](f,f); + } + else { + return vec3_stack[--vec3_stack_head]; + } +} + +vec3 cpull_vec3(){ + return v3const.vec3s[vec3_const_head++]; +} + +void push_vec4(vec4 f[2]){ + vec4_stack[vec4_stack_head++]=f; +} + +vec4[2]pull_vec4(bool c){ + if (c) { + vec4 f = v4const.vec4s[vec4_const_head++]; + return vec4[2](f,f); + } + else { + return vec4_stack[--vec4_stack_head]; + } +} + +vec4 cpull_vec4(){ + return v4const.vec4s[vec4_const_head++]; +} + +void push_mat2(mat2 f[2]){ + mat2_stack[mat2_stack_head++]=f; +} + +mat2[2]pull_mat2(bool c){ + if (c) { + mat2 f = m2const.mat2s[mat2_const_head++]; + return mat2[2](f,f); + } + else { + return mat2_stack[--mat2_stack_head]; + } +} + +mat2 cpull_mat2(){ + return m2const.mat2s[mat2_const_head++]; +} + +void push_mat3(mat3 f[2]){ + mat3_stack[mat3_stack_head++]=f; +} + +mat3[2]pull_mat3(bool c){ + if (c) { + mat3 f = m3const.mat3s[mat3_const_head++]; + return mat3[2](f,f); + } + else { + return mat3_stack[--mat3_stack_head]; + } +} + +mat3 cpull_mat3(){ + return m3const.mat3s[mat3_const_head++]; +} + +void push_mat4(mat4 f[2]){ + mat4_stack[mat4_stack_head++]=f; +} + +mat4[2]pull_mat4(bool c){ + if (c) { + mat4 f = m4const.mat4s[mat4_const_head++]; + return mat4[2](f,f); + } + else { + return mat4_stack[--mat4_stack_head]; + } +} + +mat4 cpull_mat4(){ + return m4const.mat4s[mat4_const_head++]; +} + +void clear_stacks() +{ + float_stack_head=0; + vec2_stack_head=0; + vec3_stack_head=0; + vec4_stack_head=0; + mat2_stack_head=0; + mat3_stack_head=0; + mat4_stack_head=0; + 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; +} + +const int masklen = 29; +uint8_t mask[masklen]; + +void default_mask() +{ + mask=uint8_t[29]( + uint8_t(255), + uint8_t(255), + uint8_t(255), + uint8_t(255), + uint8_t(255), + uint8_t(255), + uint8_t(255), + uint8_t(255), + uint8_t(255), + uint8_t(255), + uint8_t(255), + uint8_t(255), + uint8_t(255), + uint8_t(255), + uint8_t(255), + uint8_t(255), + uint8_t(255), + uint8_t(255), + uint8_t(255), + uint8_t(255), + uint8_t(255), + uint8_t(255), + uint8_t(255), + uint8_t(255), + uint8_t(255), + uint8_t(255), + uint8_t(255), + uint8_t(255), + uint8_t(255) + ); +} + +//monotonic +#define multiply {\ + temp[0]=in1[0]*in2[0];\ + temp[1]=in1[0]*in2[1];\ + temp[2]=in1[1]*in2[0];\ + temp[3]=in1[1]*in2[1];\ + in1[0]=min(temp[0],min(temp[1],min(temp[2],temp[3])));\ + in1[1]=max(temp[0],max(temp[1],max(temp[2],temp[3])));\ +} +//monotonic +#define divide {\ + temp[0]=in1[0]/in2[0];\ + temp[1]=in1[0]/in2[1];\ + temp[2]=in1[1]/in2[0];\ + temp[3]=in1[1]/in2[1];\ + in1[0]=min(temp[0],min(temp[1],min(temp[2],temp[3])));\ + in1[1]=max(temp[0],max(temp[1],max(temp[2],temp[3])));\ +} +//monotonic +#define add {\ + in1[0]+=in2[0];\ + in1[1]+=in2[1];\ +} +//monotonic +#define subtract {\ + in1[0]-=in2[1];\ + in1[1]-=in2[0];\ +} +//??? +//THIS IS NOT CORRECT! This is very hard to calculate, and as such the upper bound is over-estimated. +//However, it IS accurate if in2 is constant. +//EDIT: Actually, on further inspection, this may just be entirely incorrect. Who knows, frankly. +#define modulo {\ + temp[0]=in1[0]/in2[0];\ + temp[1]=in1[0]/in2[1];\ + temp[2]=in1[1]/in2[0];\ + temp[3]=in1[1]/in2[1];\ + mixer1=mix(mixer1,lessThan(min(temp[0],min(temp[1],min(temp[2],temp[3]))),zero),greaterThan(max(temp[0],max(temp[1],max(temp[2],temp[3]))),zero));\ + temp[0]=mod(in1[0],in2[0]);\ + temp[1]=mod(in1[0],in2[1]);\ + temp[2]=mod(in1[1],in2[0]);\ + temp[3]=mod(in1[1],in2[1]);\ + in1[0]=mix(min(temp[0],min(temp[1],min(temp[2],temp[3]))),zero,mixer1);\ + in1[1]=mix(max(temp[0],max(temp[1],max(temp[2],temp[3]))),highest,mixer1);\ +} +//always monotonic for x>0 +#define power {\ + temp[0]=pow(in1[0],in2[0]);\ + temp[1]=pow(in1[0],in2[1]);\ + temp[2]=pow(in1[1],in2[0]);\ + temp[3]=pow(in1[1],in2[1]);\ + in1[0]=min(temp[0],min(temp[1],min(temp[2],temp[3])));\ + in1[1]=max(temp[0],max(temp[1],max(temp[2],temp[3])));\ +} +//handled +#define dist {\ + float out1[2];\ + mixer=mix(mixer,greaterThan(in1[1]-in2[0],zero),lessThan(in1[0]-in2[1],zero));\ + out1[0]=length(mix(min(abs(in1[0]-in2[1]),abs(in1[1]-in2[0])),zero,mixer));\ + out1[1]=length(max(abs(in1[0]-in2[1]),abs(in1[1]-in2[0])));\ +} +//variable +#define dotprod {\ + float[2] out1;\ + float a=dot(in1[0],in2[0]);\ + float b=dot(in1[0],in2[1]);\ + float c=dot(in1[1],in2[0]);\ + float d=dot(in1[1],in2[1]);\ + out1[0]=min(a,min(b,min(c,d)));\ + out1[1]=max(a,max(b,max(c,d)));\ +} +//monotonic +#define clampof {\ + in1[0]=clamp(in1[0],in2[0],in3[0]);\ + in1[1]=clamp(in1[1],in2[1],in3[1]);\ +} +//monotonic +#define mixof {\ + in1[0]=mix(in1[0],in2[0],in3[0]);\ + in1[1]=mix(in1[1],in2[1],in3[1]);\ +} +//monotonic +#define fmaof {\ + multiply;\ + in2=in3;\ + add;\ +} +//variable +#define square {\ + mixer=mix(mixer,greaterThan(in1[1],zero),lessThan(in1[0],zero));\ + out1[0]=mix(min(in1[0]*in1[0],in1[1]*in1[1]),zero,mixer);\ + out1[1]=max(in1[0]*in1[0],in1[1]*in1[1]);\ +} +//monotonic +#define cube {\ + out1[0]=in1[0]*in1[0]*in1[0];\ + out1[0]=in1[1]*in1[1]*in1[1];\ +} +//mess +#define len {\ + float out1[2];\ + mixer=mix(mixer,greaterThan(in1[1],zero),lessThan(in1[0],zero));\ + out1[0]=length(mix(min(abs(in1[0]),abs(in1[1])),zero,mixer));\ + out1[1]=length(max(abs(in1[0]),abs(in1[1])));\ +} +//monotonic +#define mattranspose {\ + in1[0]=transpose(in1[0]);\ + in1[1]=transpose(in1[1]);\ +} +//unused +#define matdeterminant {\ + temp[0]=determinant(in1[0]);\ + temp[1]=determinant(in1[1]);\ + in1[0]=min(temp[0],temp[1]);\ + in1[1]=max(temp[0],temp[1]);\ +} +//unused +#define matinvert {\ + temp[0]=inverse(in1[0]);\ + temp[1]=inverse(in1[1]);\ + in1[0]=min(temp[0],temp[1]);\ + in1[1]=max(temp[0],temp[1]);\ +} +//handled +#define absolute {\ + mixer=mix(mixer,greaterThan(in1[1],zero),lessThan(in1[0],zero));\ + temp[0]=abs(in1[0]);\ + temp[1]=abs(in1[1]);\ + in1[0]=mix(min(temp[0],temp[1]),zero,mixer);\ + in1[1]=max(temp[0],temp[1]);\ +} +//monotonic +#define signof {\ + in1[0]=sign(in1[0]);\ + in1[1]=sign(in1[1]);\ +} +//monotonic +#define floorof {\ + in1[0]=floor(in1[0]);\ + in1[1]=floor(in1[1]);\ +} +//monotonic +#define ceilingof {\ + in1[0]=ceil(in1[0]);\ + in1[1]=ceil(in1[1]);\ +} +//handled +//If the integer component changes across the interval, then we've managed to hit +//a discontinuity, and the max and min are constant. +//Otherwise, it's monotonic. +#define fractionalof {\ + mixer = equal(floor(in1[0]),floor(in1[1]));\ + in1[0]=mix(zero,fract(in1[0]),mixer);\ + in1[1]=mix(one,fract(in1[1]),mixer);\ +} +//monotonic +#define squarerootof {\ + in1[0]=sqrt(in1[0]);\ + in1[1]=sqrt(in1[1]);\ +} +//monotonic +#define inversesquarerootof {\ + temp[0]=inversesqrt(in1[0]);\ + in1[0]=inversesqrt(in1[1]);\ + in1[1]=temp[0];\ +} +//monotonic +#define exponentof {\ + in1[0]=exp(in1[0]);\ + in1[1]=exp(in1[1]);\ +} +//monotonic +#define exponent2of {\ + in1[0]=exp2(in1[0]);\ + in1[1]=exp2(in1[0]);\ +} +//monotonic +#define logarithmof {\ + in1[0]=log(in1[0]);\ + in1[1]=log(in1[1]);\ +} +//monotonic +#define logarithm2of {\ + in1[0]=log2(in1[0]);\ + in1[1]=log2(in1[1]);\ +} +#define PI 3.1415926536 +//handled +#define sineof {\ + mixer1=equal(floor((in1[0]/PI)+0.5),floor((in1[1]/PI)+0.5));\ + upper=mod(floor((in1[1]/PI)+0.5),2);\ + mixer2=greaterThan(floor((in1[1]/PI)+0.5)-floor((in1[0]/PI)+0.5),one);\ + temp[0]=sin(in1[0]);\ + temp[1]=sin(in1[1]);\ + in1[0]=mix(minusone,min(temp[0],temp[1]),mix(mix(equal(upper,one),vfalse,mixer2),vtrue,mixer1));\ + in1[1]=mix(one,max(temp[0],temp[1]),mix(mix(equal(upper,zero),vfalse,mixer2),vtrue,mixer1));\ +} +//handled +#define cosineof {\ + mixer1=equal(floor((in1[0]/PI)),floor((in1[1]/PI)));\ + upper=mod(floor((in1[1]/PI)),2);\ + mixer2=greaterThan(floor((in1[1]/PI))-floor((in1[0]/PI)),one);\ + temp[0]=cos(in1[0]);\ + temp[1]=cos(in1[1]);\ + in1[0]=mix(minusone,min(temp[0],temp[1]),mix(mix(equal(upper,zero),vfalse,mixer2),vtrue,mixer1));\ + in1[1]=mix(one,max(temp[0],temp[1]),mix(mix(equal(upper,one),vfalse,mixer2),vtrue,mixer1));\ +} +//handled +#define tangentof {\ + mixer1=equal(floor((in1[0]/PI)),floor((in1[1]/PI)));\ + in1[0]=mix(inf*-1.,tan(in1[0]),mixer1);\ + in1[1]=mix(inf,tan(in1[1]),mixer1);\ +} +//monotonic +#define arcsineof {\ + in1[0]=asin(in1[0]);\ + in1[1]=asin(in1[1]);\ +} +//negatively monotonic +#define arccosineof {\ + temp[0]=acos(in1[1]);\ + temp[1]=acos(in1[0]);\ + in1[0]=temp[0];\ + in1[1]=temp[1];\ +} +//monotonic +#define arctangentof {\ + in1[0]=atan(in1[0]);\ + in1[1]=atan(in1[1]);\ +} +//monotonic +#define hyperbolicsineof {\ + in1[0]=sinh(in1[0]);\ + in1[1]=sinh(in1[1]);\ +} +//handled +#define hyperboliccosineof {\ + mixer=mix(mixer,greaterThan(in1[1],zero),lessThan(in1[0],zero));\ + out1[0]=mix(min(cosh(in1[0]),cosh(in1[1])),one,mixer);\ + out1[1]=max(cosh(in1[0]),cosh(in1[1]));\ +} +//monotonic +#define hyperbolictangentof {\ + in1[0]=tanh(in1[0]);\ + in1[1]=tanh(in1[1]);\ +} +//monotonic +#define hyperbolicarcsineof {\ + in1[0]=asinh(in1[0]);\ + in1[1]=asinh(in1[1]);\ +} +//monotonic +#define hyperbolicarccosineof {\ + in1[0]=acosh(in1[0]);\ + in1[1]=acosh(in1[1]);\ +} +//monotonic +#define hyperbolicarctangentof {\ + in1[0]=atanh(in1[0]);\ + in1[1]=atanh(in1[1]);\ +} +//obvious +#define minimum {\ + in1[0]=min(in1[0],in2[0]);\ + in1[1]=min(in1[1],in2[1]);\ +} +//obvious +#define maximum {\ + in1[0]=max(in1[0],in2[0]);\ + in1[1]=max(in1[1],in2[1]);\ +} +//monotonic +#define roundof {\ + in1[0]=round(in1[0]);\ + in1[1]=round(in1[1]);\ +} +//truncate +#define truncof {\ + in1[0]=trunc(in1[0]);\ + in1[1]=trunc(in1[1]);\ +} + +Description desc; +//0 - prune nothing +//1 - prune myself +//2 - prune myself and children +uint8_t pruneallchecks[(masklen*8)+1]; + +void pruneall (int pos) { + uint8_t[2] deps; + for (int i = pos-1; i >= 0; i--) + { + deps = depinfo.dependencies[desc.dependencies+i]; + if (deps[1] != 255) { + switch (int((pruneallchecks[deps[0]] << 4) | (pruneallchecks[deps[1]] << 2) | (pruneallchecks[i] << 0))) + { + case ((2 << 4) | (2 << 2) | (2 << 0)): + case ((2 << 4) | (1 << 2) | (2 << 0)): + case ((2 << 4) | (0 << 2) | (2 << 0)): + case ((1 << 4) | (2 << 2) | (2 << 0)): + case ((1 << 4) | (1 << 2) | (2 << 0)): + case ((1 << 4) | (0 << 2) | (2 << 0)): + case ((0 << 4) | (2 << 2) | (2 << 0)): + case ((0 << 4) | (1 << 2) | (2 << 0)): + case ((0 << 4) | (0 << 2) | (2 << 0)): + + case ((2 << 4) | (2 << 2) | (1 << 0)): + case ((2 << 4) | (2 << 2) | (0 << 0)): + case ((2 << 4) | (1 << 2) | (1 << 0)): + case ((1 << 4) | (2 << 2) | (1 << 0)): + pruneallchecks[i]=uint8_t(2); + mask[i>>3] &= uint8_t(~(1<<(i&7))); + break; + + case ((2 << 4) | (1 << 2) | (0 << 0)): + case ((2 << 4) | (0 << 2) | (0 << 0)): + case ((1 << 4) | (2 << 2) | (0 << 0)): + case ((0 << 4) | (2 << 2) | (0 << 0)): + case ((0 << 4) | (0 << 2) | (1 << 0)): + case ((1 << 4) | (1 << 2) | (1 << 0)): + case ((2 << 4) | (0 << 2) | (1 << 0)): + case ((0 << 4) | (2 << 2) | (1 << 0)): + case ((0 << 4) | (1 << 2) | (1 << 0)): + case ((1 << 4) | (0 << 2) | (1 << 0)): + pruneallchecks[i]=uint8_t(1); + mask[i>>3] &= uint8_t(~(1<<(i&7))); + break; + + case ((1 << 4) | (1 << 2) | (0 << 0)): + case ((1 << 4) | (0 << 2) | (0 << 0)): + case ((0 << 4) | (1 << 2) | (0 << 0)): + case ((0 << 4) | (0 << 2) | (0 << 0)): + default: + break; + } + } + else if (pruneallchecks[i] > 0) + { + mask[i>>3] &= uint8_t(~(1<<(i&7))); + } + else if (pruneallchecks[deps[0]] > 1) { + pruneallchecks[i]=uint8_t(2); + mask[i>>3] &= uint8_t(~(1<<(i&7))); + } + } +} + +void prunesome (int pos, bool prunemask[6]) { + uint8_t[2] deps; + int maskindex = 0; + for (int i = 0; i < pos; i++) + { + deps = depinfo.dependencies[desc.dependencies+i]; + if (deps[1] != 255) { + if (deps[0] == pos) { + if (prunemask[maskindex++]) { + pruneallchecks[i]++; + } + } + if (deps[1] == pos) { + if (prunemask[maskindex++]) { + pruneallchecks[i]++; + } + } + //pruneallchecks[i] = min(pruneallchecks[i],2); + } + else if (deps[0] == pos) { + if (prunemask[maskindex++]) { + pruneallchecks[i]=uint8_t(2); + } + } + } +} + +void passthroughself (int pos) { + pruneallchecks[pos]=uint8_t(1); +} +void pruneself (int pos) { + pruneallchecks[pos]=uint8_t(2); +} + +#define maskdefine (mask[major_position]&(1<<minor_position))==0 +#define inputmask1(m_in_1) if(maskdefine){\ + if(ifconst(0)) {m_in_1++;}\ + break;\ +} +#define inputmask2(m_in_1,m_in_2) if(maskdefine){\ + if(ifconst(0)) {m_in_1++;}\ + if(ifconst(1)) {m_in_2++;}\ + break;\ +} +#define inputmask3(m_in_1,m_in_2,m_in_3) if(maskdefine){\ + if(ifconst(0)) {m_in_1++;}\ + if(ifconst(1)) {m_in_2++;}\ + if(ifconst(2)) {m_in_3++;}\ + break;\ +} +#define inputmask4(m_in_1,m_in_2,m_in_3,m_in_4) if(maskdefine){\ + if(ifconst(0)) {m_in_1++;}\ + if(ifconst(1)) {m_in_2++;}\ + if(ifconst(2)) {m_in_3++;}\ + if(ifconst(3)) {m_in_4++;}\ + break;\ +} +#define inputmask5(m_in_1,m_in_2,m_in_3,m_in_4,m_in_5) if(maskdefine){\ + if(ifconst(0)) {m_in_1++;}\ + if(ifconst(1)) {m_in_2++;}\ + if(ifconst(2)) {m_in_3++;}\ + if(ifconst(3)) {m_in_4++;}\ + if(ifconst(4)) {m_in_5++;}\ + break;\ +} +#define inputmask6(m_in_1,m_in_2,m_in_3,m_in_4,m_in_5,m_in_6) if(maskdefine){\ + if(ifconst(0)) {m_in_1++;}\ + if(ifconst(1)) {m_in_2++;}\ + if(ifconst(2)) {m_in_3++;}\ + if(ifconst(3)) {m_in_4++;}\ + if(ifconst(4)) {m_in_5++;}\ + if(ifconst(5)) {m_in_6++;}\ + break;\ +} + +#define minpruning if (all(lessThan(in1[1],in2[0]))) {\ + prunesome(OPPos,bool[6](false,true,false,false,false,false));\ + passthroughself(OPPos);\ +} else if (all(lessThan(in2[1],in1[0]))) {\ + prunesome(OPPos,bool[6](true,false,false,false,false,false));\ + passthroughself(OPPos);\ +} + +#define maxpruning if (all(greaterThan(in1[0],in2[1]))) {\ + prunesome(OPPos,bool[6](false,true,false,false,false,false));\ + passthroughself(OPPos);\ +} else if (all(greaterThan(in2[0],in1[1]))) {\ + prunesome(OPPos,bool[6](true,false,false,false,false,false));\ + passthroughself(OPPos);\ +} + +#ifdef debug +vec3 scene(vec3 p[2], bool prune) +#else +float[2]scene(vec3 p[2], bool prune) +#endif +{ + uint major_position=0; + uint minor_position=0; + + uint minor_integer_cache[8]; + + desc = scene_description.desc[gl_GlobalInvocationID.x]; + + clear_stacks(); + push_vec3(p); + + bool cont=true; + + while(cont){ + if(minor_position==0){ + get_caches; + } + /*#ifdef debug + if((minor_integer_cache[minor_position]&1023)==OPStop) { + return vec3(0.,0.,1.); + } + if((minor_integer_cache[minor_position]&1023)==OPSDFSphere) { + return vec3(1.,0.,0.); + } + return vec3(0.,1.,0.); + #endif*/ + + switch(minor_integer_cache[minor_position]&1023) + { + #define ifconst(pos) (minor_integer_cache[minor_position] & (1 << (15 - pos))) > 0 + #define OPPos int((major_position<<3)|minor_position) + case OPAddFloatFloat:{ + inputmask2(float_const_head,float_const_head); + float[2]in1=pull_float(ifconst(0)); + float[2]in2=pull_float(ifconst(1)); + add; + push_float(in1); + } + break; + case OPAddVec2Vec2:{ + inputmask2(vec2_const_head,vec2_const_head); + vec2[2]in1=pull_vec2(ifconst(0)); + vec2[2]in2=pull_vec2(ifconst(1)); + add; + push_vec2(in1); + } + break; + case OPAddVec2Float:{ + inputmask2(vec2_const_head,float_const_head); + vec2[2]in1=pull_vec2(ifconst(0)); + float[2]in2=pull_float(ifconst(1)); + add; + push_vec2(in1); + } + break; + case OPAddVec3Vec3:{ + inputmask2(vec3_const_head,vec3_const_head); + vec3[2]in1=pull_vec3(ifconst(0)); + vec3[2]in2=pull_vec3(ifconst(1)); + add; + push_vec3(in1); + } + break; + case OPAddVec3Float:{ + inputmask2(vec3_const_head,float_const_head); + vec3[2]in1=pull_vec3(ifconst(0)); + float[2]in2=pull_float(ifconst(1)); + add; + push_vec3(in1); + } + break; + case OPAddVec4Vec4:{ + inputmask2(vec4_const_head,vec4_const_head); + vec4[2]in1=pull_vec4(ifconst(0)); + vec4[2]in2=pull_vec4(ifconst(1)); + add; + push_vec4(in1); + } + break; + case OPAddVec4Float:{ + inputmask2(vec4_const_head,float_const_head); + vec4[2]in1=pull_vec4(ifconst(0)); + float[2]in2=pull_float(ifconst(1)); + add; + push_vec4(in1); + } + break; + + case OPSubFloatFloat:{ + inputmask2(float_const_head,float_const_head); + float[2]in1=pull_float(ifconst(0)); + float[2]in2=pull_float(ifconst(1)); + subtract; + push_float(in1); + } + break; + case OPSubVec2Vec2:{ + inputmask2(vec2_const_head,vec2_const_head); + vec2[2]in1=pull_vec2(ifconst(0)); + vec2[2]in2=pull_vec2(ifconst(1)); + subtract; + push_vec2(in1); + } + break; + case OPSubVec2Float:{ + inputmask2(vec2_const_head,float_const_head); + vec2[2]in1=pull_vec2(ifconst(0)); + float[2]in2=pull_float(ifconst(1)); + subtract; + push_vec2(in1); + } + break; + case OPSubVec3Vec3:{ + inputmask2(vec3_const_head,vec3_const_head); + vec3[2]in1=pull_vec3(ifconst(0)); + vec3[2]in2=pull_vec3(ifconst(1)); + subtract; + push_vec3(in1); + } + break; + case OPSubVec3Float:{ + inputmask2(vec3_const_head,float_const_head); + vec3[2]in1=pull_vec3(ifconst(0)); + float[2]in2=pull_float(ifconst(1)); + subtract; + push_vec3(in1); + } + break; + case OPSubVec4Vec4:{ + inputmask2(vec4_const_head,vec4_const_head); + vec4[2]in1=pull_vec4(ifconst(0)); + vec4[2]in2=pull_vec4(ifconst(1)); + subtract; + push_vec4(in1); + } + break; + case OPSubVec4Float:{ + inputmask2(vec4_const_head,float_const_head); + vec4[2]in1=pull_vec4(ifconst(0)); + float[2]in2=pull_float(ifconst(1)); + subtract; + push_vec4(in1); + } + break; + + case OPMulFloatFloat:{ + inputmask2(float_const_head,float_const_head); + float[2]in1=pull_float(ifconst(0)); + float[2]in2=pull_float(ifconst(1)); + float[4]temp; + multiply; + push_float(in1); + } + break; + case OPMulVec2Vec2:{ + inputmask2(vec2_const_head,vec2_const_head); + vec2[2]in1=pull_vec2(ifconst(0)); + vec2[2]in2=pull_vec2(ifconst(1)); + vec2[4]temp; + multiply; + push_vec2(in1); + } + break; + case OPMulVec2Float:{ + inputmask2(vec2_const_head,float_const_head); + vec2[2]in1=pull_vec2(ifconst(0)); + float[2]in2=pull_float(ifconst(1)); + vec2[4]temp; + multiply; + push_vec2(in1); + } + break; + case OPMulVec3Vec3:{ + inputmask2(vec3_const_head,vec3_const_head); + vec3[2]in1=pull_vec3(ifconst(0)); + vec3[2]in2=pull_vec3(ifconst(1)); + vec3[4]temp; + multiply; + push_vec3(in1); + } + break; + case OPMulVec3Float:{ + inputmask2(vec3_const_head,float_const_head); + vec3[2]in1=pull_vec3(ifconst(0)); + float[2]in2=pull_float(ifconst(1)); + vec3[4]temp; + multiply; + push_vec3(in1); + } + break; + case OPMulVec4Vec4:{ + inputmask2(vec4_const_head,vec4_const_head); + vec4[2]in1=pull_vec4(ifconst(0)); + vec4[2]in2=pull_vec4(ifconst(1)); + vec4[4]temp; + multiply; + push_vec4(in1); + } + break; + case OPMulVec4Float:{ + inputmask2(vec4_const_head,float_const_head); + vec4[2]in1=pull_vec4(ifconst(0)); + float[2]in2=pull_float(ifconst(1)); + vec4[4]temp; + multiply; + push_vec4(in1); + } + break; + + case OPDivFloatFloat:{ + inputmask2(float_const_head,float_const_head); + float[2]in1=pull_float(ifconst(0)); + float[2]in2=pull_float(ifconst(1)); + float[4]temp; + divide; + push_float(in1); + } + break; + case OPDivVec2Vec2:{ + inputmask2(vec2_const_head,vec2_const_head); + vec2[2]in1=pull_vec2(ifconst(0)); + vec2[2]in2=pull_vec2(ifconst(1)); + vec2[4]temp; + divide; + push_vec2(in1); + } + break; + case OPDivVec2Float:{ + inputmask2(vec2_const_head,float_const_head); + vec2[2]in1=pull_vec2(ifconst(0)); + float[2]in2=pull_float(ifconst(1)); + vec2[4]temp; + divide; + push_vec2(in1); + } + break; + case OPDivVec3Vec3:{ + inputmask2(vec3_const_head,vec3_const_head); + vec3[2]in1=pull_vec3(ifconst(0)); + vec3[2]in2=pull_vec3(ifconst(1)); + vec3[4]temp; + divide; + push_vec3(in1); + } + break; + case OPDivVec3Float:{ + inputmask2(vec3_const_head,float_const_head); + vec3[2]in1=pull_vec3(ifconst(0)); + float[2]in2=pull_float(ifconst(1)); + vec3[4]temp; + divide; + push_vec3(in1); + } + break; + case OPDivVec4Vec4:{ + inputmask2(vec4_const_head,vec4_const_head); + vec4[2]in1=pull_vec4(ifconst(0)); + vec4[2]in2=pull_vec4(ifconst(1)); + vec4[4]temp; + divide; + push_vec4(in1); + } + break; + case OPDivVec4Float:{ + inputmask2(vec4_const_head,float_const_head); + vec4[2]in1=pull_vec4(ifconst(0)); + float[2]in2=pull_float(ifconst(1)); + vec4[4]temp; + divide; + push_vec4(in1); + } + break; + + case OPPowFloatFloat:{ + inputmask2(float_const_head,float_const_head); + float[2]in1=pull_float(ifconst(0)); + float[2]in2=pull_float(ifconst(1)); + float[4]temp; + power; + push_float(in1); + } + break; + case OPPowVec2Vec2:{ + inputmask2(vec2_const_head,vec2_const_head); + vec2[2]in1=pull_vec2(ifconst(0)); + vec2[2]in2=pull_vec2(ifconst(1)); + vec2[4]temp; + power; + push_vec2(in1); + } + break; + case OPPowVec3Vec3:{ + inputmask2(vec3_const_head,vec3_const_head); + vec3[2]in1=pull_vec3(ifconst(0)); + vec3[2]in2=pull_vec3(ifconst(1)); + vec3[4]temp; + power; + push_vec3(in1); + } + break; + case OPPowVec4Vec4:{ + inputmask2(vec4_const_head,vec4_const_head); + vec4[2]in1=pull_vec4(ifconst(0)); + vec4[2]in2=pull_vec4(ifconst(1)); + vec4[4]temp; + power; + push_vec4(in1); + } + break; + + case OPModFloatFloat:{ + inputmask2(float_const_head,float_const_head); + float[2]in1=pull_float(ifconst(0)); + float[2]in2=pull_float(ifconst(1)); + float a=in1[0]/in2[0]; + float b=in1[0]/in2[1]; + float c=in1[1]/in2[0]; + float d=in1[1]/in2[1]; + if ((min(a,min(b,min(c,d))) < 0) && (max(a,max(b,max(c,d))) > 0)) + { + in1[0]=0; + in1[1]=in2[1]; + } + else { + a=mod(in1[0],in2[0]); + b=mod(in1[0],in2[1]); + c=mod(in1[1],in2[0]); + d=mod(in1[1],in2[1]); + in1[0]=min(a,min(b,min(c,d))); + in1[1]=max(a,max(b,max(c,d))); + } + push_float(in1); + } + break; + case OPModVec2Vec2:{ + inputmask2(vec2_const_head,vec2_const_head); + vec2[2]in1=pull_vec2(ifconst(0)); + vec2[2]in2=pull_vec2(ifconst(1)); + vec2[4]temp; + bvec2 mixer1 = bvec2(false); + vec2 zero = vec2(0); + vec2 highest = in2[1]; + modulo; + push_vec2(in1); + } + break; + case OPModVec2Float:{ + inputmask2(vec2_const_head,float_const_head); + vec2[2]in1=pull_vec2(ifconst(0)); + float[2]in2=pull_float(ifconst(1)); + vec2[4]temp; + bvec2 mixer1 = bvec2(false); + vec2 zero = vec2(0); + vec2 highest = vec2(in2[1]); + modulo; + push_vec2(in1); + } + break; + case OPModVec3Vec3:{ + inputmask2(vec3_const_head,vec3_const_head); + vec3[2]in1=pull_vec3(ifconst(0)); + vec3[2]in2=pull_vec3(ifconst(1)); + vec3[4]temp; + bvec3 mixer1 = bvec3(false); + vec3 zero = vec3(0); + vec3 highest = in2[1]; + modulo; + push_vec3(in1); + } + break; + case OPModVec3Float:{ + inputmask2(vec3_const_head,float_const_head); + vec3[2]in1=pull_vec3(ifconst(0)); + float[2]in2=pull_float(ifconst(1)); + vec3[4]temp; + bvec3 mixer1 = bvec3(false); + vec3 zero = vec3(0); + vec3 highest = vec3(in2[1]); + modulo; + push_vec3(in1); + } + break; + case OPModVec4Vec4:{ + inputmask2(vec4_const_head,vec4_const_head); + vec4[2]in1=pull_vec4(ifconst(0)); + vec4[2]in2=pull_vec4(ifconst(1)); + vec4[4]temp; + bvec4 mixer1 = bvec4(false); + vec4 zero = vec4(0); + vec4 highest = in2[1]; + modulo; + push_vec4(in1); + } + break; + case OPModVec4Float:{ + inputmask2(vec4_const_head,float_const_head); + vec4[2]in1=pull_vec4(ifconst(0)); + float[2]in2=pull_float(ifconst(1)); + vec4[4]temp; + bvec4 mixer1 = bvec4(false); + vec4 zero = vec4(0); + vec4 highest = vec4(in2[1]); + modulo; + push_vec4(in1); + } + break; + + + case OPCrossVec3:{ + inputmask2(vec3_const_head,vec3_const_head); + /*#define getminmaxleft minleft = min(minleft, check); maxleft = max(maxleft, check); + #define getminmaxright minright = min(minright, check); maxright = max(maxright, check); + #define resetminmax minleft = 9999999999; minright = minleft; maxleft = -9999999999; maxright = maxleft; + vec3[2]in1=pull_vec3(ifconst(0)); + vec3[2]in2=pull_vec3(ifconst(1)); + vec3 outmax; + vec3 outmin; + float check; + float maxleft; + float minleft; + float maxright; + float minright; + + resetminmax; + check = (in1[0].y*in2[0].z); getminmaxleft; + check = (in1[0].y*in2[1].z); getminmaxleft; + check = (in1[1].y*in2[0].z); getminmaxleft; + check = (in1[1].y*in2[1].z); getminmaxleft; + check = (in1[0].z*in2[0].y); getminmaxright; + check = (in1[0].z*in2[1].y); getminmaxright; + check = (in1[1].z*in2[0].y); getminmaxright; + check = (in1[1].z*in2[1].y); getminmaxright; + + outmax.x = maxleft - minright; outmin.x = minleft - maxright; + + resetminmax; + check = (in1[0].z*in2[0].x); getminmaxleft; + check = (in1[0].z*in2[1].x); getminmaxleft; + check = (in1[1].z*in2[0].x); getminmaxleft; + check = (in1[1].z*in2[1].x); getminmaxleft; + check = (in1[0].x*in2[0].z); getminmaxright; + check = (in1[0].x*in2[1].z); getminmaxright; + check = (in1[1].x*in2[0].z); getminmaxright; + check = (in1[1].x*in2[1].z); getminmaxright; + + outmax.y = maxleft - minright; outmin.y = minleft - maxright; + + resetminmax; + check = (in1[0].x*in2[0].y); getminmaxleft; + check = (in1[0].x*in2[1].y); getminmaxleft; + check = (in1[1].x*in2[0].y); getminmaxleft; + check = (in1[1].x*in2[1].y); getminmaxleft; + check = (in1[0].y*in2[0].x); getminmaxright; + check = (in1[0].y*in2[1].x); getminmaxright; + check = (in1[1].y*in2[0].x); getminmaxright; + check = (in1[1].y*in2[1].x); getminmaxright; + + outmax.z = maxleft - minright; outmin.z = minleft - maxright; + + push_vec3(vec3[2](outmin,outmax));*/ + + vec3[2]in1=pull_vec3(ifconst(0)); + vec3[2]in2=pull_vec3(ifconst(1)); + + vec3 a=cross(in1[0],in2[0]); + vec3 b=cross(in1[0],in2[1]); + vec3 c=cross(in1[1],in2[0]); + vec3 d=cross(in1[1],in2[1]); + + push_vec3(vec3[2]( + min(a,min(b,min(c,d))), + max(a,max(b,max(c,d))) + )); + } + break; + + case OPDotVec2:{ + inputmask2(vec2_const_head,vec2_const_head); + vec2[2]in1=pull_vec2(ifconst(0)); + vec2[2]in2=pull_vec2(ifconst(1)); + float[2]out1; + dotprod; + push_float(out1); + } + break; + case OPDotVec3:{ + inputmask2(vec3_const_head,vec3_const_head); + vec3[2]in1=pull_vec3(ifconst(0)); + vec3[2]in2=pull_vec3(ifconst(1)); + float[2]out1; + dotprod; + push_float(out1); + } + break; + case OPDotVec4:{ + inputmask2(vec4_const_head,vec4_const_head); + vec4[2]in1=pull_vec4(ifconst(0)); + vec4[2]in2=pull_vec4(ifconst(1)); + float[2]out1; + dotprod; + push_float(out1); + } + break; + + case OPLengthVec2:{ + inputmask1(vec2_const_head); + vec2[2]in1=pull_vec2(ifconst(0)); + bvec2 mixer = bvec2(false); + vec2 zero = vec2(0); + float[2]out1; + len; + push_float(out1); + } + break; + case OPLengthVec3:{ + inputmask1(vec3_const_head); + vec3[2]in1=pull_vec3(ifconst(0)); + bvec3 mixer = bvec3(false); + vec3 zero = vec3(0); + float[2]out1; + len; + push_float(out1); + } + break; + case OPLengthVec4:{ + inputmask1(vec4_const_head); + vec4[2]in1=pull_vec4(ifconst(0)); + bvec4 mixer = bvec4(false); + vec4 zero = vec4(0); + float[2]out1; + len; + push_float(out1); + } + break; + + case OPDistanceVec2:{ + inputmask2(vec2_const_head,vec2_const_head); + vec2[2]in1=pull_vec2(ifconst(0)); + vec2[2]in2=pull_vec2(ifconst(1)); + bvec2 mixer = bvec2(false); + vec2 zero = vec2(0); + float[2]out1; + dist; + push_float(out1); + } + break; + case OPDistanceVec3:{ + inputmask2(vec3_const_head,vec3_const_head); + vec3[2]in1=pull_vec3(ifconst(0)); + vec3[2]in2=pull_vec3(ifconst(1)); + bvec3 mixer = bvec3(false); + vec3 zero = vec3(0); + float[2]out1; + len; + push_float(out1); + } + break; + case OPDistanceVec4:{ + inputmask2(vec4_const_head,vec4_const_head); + vec4[2]in1=pull_vec4(ifconst(0)); + vec4[2]in2=pull_vec4(ifconst(1)); + bvec4 mixer = bvec4(false); + vec4 zero = vec4(0); + float[2]out1; + dist; + push_float(out1); + } + break; + + case OPAbsFloat: { + inputmask1(float_const_head); + float[2]in1=pull_float(ifconst(0)); + float a=abs(in1[0]); + float b=abs(in1[1]); + if ((in1[1] > 0) && (in1[0] < 0)) + { + in1[0] = 0; + } + else + { + in1[0]=min(a,b); + } + in1[1]=max(a,b); + push_float(in1); + } + break; + case OPSignFloat: { + inputmask1(float_const_head); + float[2]in1=pull_float(ifconst(0)); + float[2]temp; + signof; + push_float(in1); + } + break; + case OPFloorFloat: { + inputmask1(float_const_head); + float[2]in1=pull_float(ifconst(0)); + float[2]temp; + floorof; + push_float(in1); + } + break; + case OPCeilFloat: { + inputmask1(float_const_head); + float[2]in1=pull_float(ifconst(0)); + float[2]temp; + ceilingof; + push_float(in1); + } + break; + case OPFractFloat: { + inputmask1(float_const_head); + float[2]in1=pull_float(ifconst(0)); + float[2]temp; + if (floor(in1[0]) == floor(in1[1])) { + in1[0] = fract(in1[0]); + in1[1] = fract(in1[1]); + } + else { + in1[0] = 0; + in1[1] = 1; + } + push_float(in1); + } + break; + case OPSqrtFloat: { + inputmask1(float_const_head); + float[2]in1=pull_float(ifconst(0)); + float[2]temp; + squarerootof; + push_float(in1); + } + break; + case OPInverseSqrtFloat: { + inputmask1(float_const_head); + float[2]in1=pull_float(ifconst(0)); + float[2]temp; + inversesquarerootof; + push_float(in1); + } + break; + case OPExpFloat: { + inputmask1(float_const_head); + float[2]in1=pull_float(ifconst(0)); + float[2]temp; + exponentof; + push_float(in1); + } + break; + case OPExp2Float: { + inputmask1(float_const_head); + float[2]in1=pull_float(ifconst(0)); + float[2]temp; + exponent2of; + push_float(in1); + } + break; + case OPLogFloat: { + inputmask1(float_const_head); + float[2]in1=pull_float(ifconst(0)); + float[2]temp; + logarithmof; + push_float(in1); + } + break; + case OPLog2Float: { + inputmask1(float_const_head); + float[2]in1=pull_float(ifconst(0)); + float[2]temp; + logarithm2of; + push_float(in1); + } + break; + case OPSinFloat: { + inputmask1(float_const_head); + float[2]in1=pull_float(ifconst(0)); + float a=sin(in1[0]); + float b=sin(in1[1]); + if (floor((in1[0]/PI)+0.5) == floor((in1[1]/PI)+0.5)) { + in1[0] = min(a,b); + in1[1] = max(a,b); + } + else if (floor((in1[1]/PI)+0.5)-floor((in1[0]/PI)+0.5) > 1) + { + in1[0] = -1; + in1[1] = 1; + } + else if (mod(floor((in1[1]/PI)+0.5),2) == 0) { + in1[0] = min(a,b); + in1[1] = 1; + } + else { + in1[0] = -1; + in1[1] = max(a,b); + } + push_float(in1); + } + break; + case OPCosFloat: { + inputmask1(float_const_head); + float[2]in1=pull_float(ifconst(0)); + float a=cos(in1[0]); + float b=cos(in1[1]); + if (floor((in1[0]/PI)) == floor((in1[1]/PI))) { + in1[0] = min(a,b); + in1[1] = max(a,b); + } + else if (floor((in1[1]/PI))-floor((in1[0]/PI)) > 1) + { + in1[0] = -1; + in1[1] = 1; + } + else if (mod(floor((in1[1]/PI)),2) == 1) { + in1[0] = min(a,b); + in1[1] = 1; + } + else { + in1[0] = -1; + in1[1] = max(a,b); + } + push_float(in1); + } + break; + case OPTanFloat: { + inputmask1(float_const_head); + float[2]in1=pull_float(ifconst(0)); + if (floor((in1[0]/PI)) == floor((in1[1]/PI))) + { + in1[0] = NINFINITY; + in1[1] = INFINITY; + } + else { + in1[0] = tan(in1[0]); + in1[1] = tan(in1[1]); + } + push_float(in1); + } + break; + case OPAsinFloat: { + inputmask1(float_const_head); + float[2]in1=pull_float(ifconst(0)); + float[2]temp; + arcsineof; + push_float(in1); + } + break; + case OPAcosFloat: { + inputmask1(float_const_head); + float[2]in1=pull_float(ifconst(0)); + float[2]temp; + arccosineof; + push_float(in1); + } + break; + case OPAtanFloat: { + inputmask1(float_const_head); + float[2]in1=pull_float(ifconst(0)); + float[2]temp; + arctangentof; + push_float(in1); + } + break; + case OPAcoshFloat:{ + inputmask1(float_const_head); + float[2]in1=pull_float(ifconst(0)); + float[2]temp; + hyperbolicarccosineof; + push_float(in1); + } + break; + case OPAsinhFloat:{ + inputmask1(float_const_head); + float[2]in1=pull_float(ifconst(0)); + float[2]temp; + hyperbolicarcsineof; + push_float(in1); + } + break; + case OPAtanhFloat:{ + inputmask1(float_const_head); + float[2]in1=pull_float(ifconst(0)); + float[2]temp; + hyperbolicarctangentof; + push_float(in1); + } + break; + case OPCoshFloat:{ + inputmask1(float_const_head); + float[2]in1=pull_float(ifconst(0)); + if ((in1[1] > 0) && (in1[0] < 0)) + { + in1[0] = 1; + } + else { + in1[0] = min(cosh(in1[0]),cosh(in1[1])); + } + in1[1] = max(cosh(in1[0]),cosh(in1[1])); + push_float(in1); + } + break; + case OPSinhFloat:{ + inputmask1(float_const_head); + float[2]in1=pull_float(ifconst(0)); + float[2]temp; + hyperbolicsineof; + push_float(in1); + } + break; + case OPTanhFloat:{ + inputmask1(float_const_head); + float[2]in1=pull_float(ifconst(0)); + float[2]temp; + hyperbolictangentof; + push_float(in1); + } + break; + case OPRoundFloat:{ + inputmask1(float_const_head); + float[2]in1=pull_float(ifconst(0)); + float[2]temp; + roundof; + push_float(in1); + } + break; + case OPTruncFloat:{ + inputmask1(float_const_head); + float[2]in1=pull_float(ifconst(0)); + float[2]temp; + truncof; + push_float(in1); + } + break; + case OPMinMaterialFloat: + case OPMinFloat: { + inputmask2(float_const_head,float_const_head); + float[2]in1=pull_float(ifconst(0)); + float[2]in2=pull_float(ifconst(1)); + if (in1[1] < in2[0]) + { + prunesome(OPPos,bool[6](false,true,false,false,false,false)); + passthroughself(OPPos); + } else if (in2[1] < in1[0]) + { + prunesome(OPPos,bool[6](true,false,false,false,false,false)); + passthroughself(OPPos); + } + float[2]temp; + minimum; + push_float(in1); + } + break; + case OPMaxMaterialFloat: + case OPMaxFloat: { + inputmask2(float_const_head,float_const_head); + float[2]in1=pull_float(ifconst(0)); + float[2]in2=pull_float(ifconst(1)); + if (in1[0] > in2[1]) + { + prunesome(OPPos,bool[6](false,true,false,false,false,false)); + passthroughself(OPPos); + } else if (in2[0] > in1[1]) + { + prunesome(OPPos,bool[6](true,false,false,false,false,false)); + passthroughself(OPPos); + } + float[2]temp; + maximum; + push_float(in1); + } + break; + case OPFMAFloat: { + inputmask3(float_const_head,float_const_head,float_const_head); + float[2]in1=pull_float(ifconst(0)); + float[2]in2=pull_float(ifconst(1)); + float[2]in3=pull_float(ifconst(2)); + float[4]temp; + fmaof; + push_float(in1); + } + break; + + case OPAbsVec2: { + inputmask1(vec2_const_head); + vec2[2]in1=pull_vec2(ifconst(0)); + vec2[2]temp; + bvec2 mixer = bvec2(false); + vec2 zero = vec2(0); + absolute; + push_vec2(in1); + } + break; + case OPSignVec2: { + inputmask1(vec2_const_head); + vec2[2]in1=pull_vec2(ifconst(0)); + vec2[2]temp; + signof; + push_vec2(in1); + } + break; + case OPFloorVec2: { + inputmask1(vec2_const_head); + vec2[2]in1=pull_vec2(ifconst(0)); + vec2[2]temp; + floorof; + push_vec2(in1); + } + break; + case OPCeilVec2: { + inputmask1(vec2_const_head); + vec2[2]in1=pull_vec2(ifconst(0)); + vec2[2]temp; + ceilingof; + push_vec2(in1); + } + break; + case OPFractVec2: { + inputmask1(vec2_const_head); + vec2[2]in1=pull_vec2(ifconst(0)); + vec2[2]temp; + bvec2 mixer = bvec2(false); + vec2 zero = vec2(0); + vec2 one = vec2(1); + fractionalof; + push_vec2(in1); + } + break; + case OPSqrtVec2: { + inputmask1(vec2_const_head); + vec2[2]in1=pull_vec2(ifconst(0)); + vec2[2]temp; + squarerootof; + push_vec2(in1); + } + break; + case OPInverseSqrtVec2: { + inputmask1(vec2_const_head); + vec2[2]in1=pull_vec2(ifconst(0)); + vec2[2]temp; + inversesquarerootof; + push_vec2(in1); + } + break; + case OPExpVec2: { + inputmask1(vec2_const_head); + vec2[2]in1=pull_vec2(ifconst(0)); + vec2[2]temp; + exponentof; + push_vec2(in1); + } + break; + case OPExp2Vec2: { + inputmask1(vec2_const_head); + vec2[2]in1=pull_vec2(ifconst(0)); + vec2[2]temp; + exponent2of; + push_vec2(in1); + } + break; + case OPLogVec2: { + inputmask1(vec2_const_head); + vec2[2]in1=pull_vec2(ifconst(0)); + vec2[2]temp; + logarithmof; + push_vec2(in1); + } + break; + case OPLog2Vec2: { + inputmask1(vec2_const_head); + vec2[2]in1=pull_vec2(ifconst(0)); + vec2[2]temp; + logarithm2of; + push_vec2(in1); + } + break; + case OPSinVec2: { + inputmask1(vec2_const_head); + vec2[2]in1=pull_vec2(ifconst(0)); + vec2[2]temp; + bvec2 mixer1 = bvec2(false); + bvec2 mixer2 = bvec2(false); + bvec2 vfalse = bvec2(false); + bvec2 vtrue = bvec2(true); + vec2 upper; + vec2 one = vec2(1); + vec2 zero = vec2(0); + vec2 minusone = vec2(-1); + sineof; + push_vec2(in1); + } + break; + case OPCosVec2: { + inputmask1(vec2_const_head); + vec2[2]in1=pull_vec2(ifconst(0)); + vec2[2]temp; + bvec2 mixer1 = bvec2(false); + bvec2 mixer2 = bvec2(false); + bvec2 vfalse = bvec2(false); + bvec2 vtrue = bvec2(true); + vec2 upper; + vec2 one = vec2(1); + vec2 zero = vec2(0); + vec2 minusone = vec2(-1); + cosineof; + push_vec2(in1); + } + break; + case OPTanVec2: { + inputmask1(vec2_const_head); + vec2[2]in1=pull_vec2(ifconst(0)); + vec2[2]temp; + bvec2 mixer1 = bvec2(false); + vec2 inf = vec2(INFINITY); + tangentof; + push_vec2(in1); + } + break; + case OPAsinVec2: { + inputmask1(vec2_const_head); + vec2[2]in1=pull_vec2(ifconst(0)); + vec2[2]temp; + arcsineof; + push_vec2(in1); + } + break; + case OPAcosVec2: { + inputmask1(vec2_const_head); + vec2[2]in1=pull_vec2(ifconst(0)); + vec2[2]temp; + arccosineof; + push_vec2(in1); + } + break; + case OPAtanVec2: { + inputmask1(vec2_const_head); + vec2[2]in1=pull_vec2(ifconst(0)); + vec2[2]temp; + arctangentof; + push_vec2(in1); + } + break; + case OPAcoshVec2:{ + inputmask1(vec2_const_head); + vec2[2]in1=pull_vec2(ifconst(0)); + vec2[2]temp; + hyperbolicarccosineof; + push_vec2(in1); + } + break; + case OPAsinhVec2:{ + inputmask1(vec2_const_head); + vec2[2]in1=pull_vec2(ifconst(0)); + vec2[2]temp; + hyperbolicarcsineof; + push_vec2(in1); + } + break; + case OPAtanhVec2:{ + inputmask1(vec2_const_head); + vec2[2]in1=pull_vec2(ifconst(0)); + vec2[2]temp; + hyperbolicarctangentof; + push_vec2(in1); + } + break; + case OPCoshVec2:{ + inputmask1(vec2_const_head); + vec2[2]in1=pull_vec2(ifconst(0)); + vec2[2]temp; + bvec2 mixer = bvec2(false); + vec2 one = vec2(1); + vec2 zero = vec2(0); + vec2[2] out1; + hyperboliccosineof; + push_vec2(out1); + } + break; + case OPSinhVec2:{ + inputmask1(vec2_const_head); + vec2[2]in1=pull_vec2(ifconst(0)); + vec2[2]temp; + hyperbolicsineof; + push_vec2(in1); + } + break; + case OPTanhVec2:{ + inputmask1(vec2_const_head); + vec2[2]in1=pull_vec2(ifconst(0)); + vec2[2]temp; + hyperbolictangentof; + push_vec2(in1); + } + break; + case OPRoundVec2:{ + inputmask1(vec2_const_head); + vec2[2]in1=pull_vec2(ifconst(0)); + vec2[2]temp; + roundof; + push_vec2(in1); + } + break; + case OPTruncVec2:{ + inputmask1(vec2_const_head); + vec2[2]in1=pull_vec2(ifconst(0)); + vec2[2]temp; + truncof; + push_vec2(in1); + } + break; + case OPMinVec2: { + inputmask2(vec2_const_head,vec2_const_head); + vec2[2]in1=pull_vec2(ifconst(0)); + vec2[2]in2=pull_vec2(ifconst(1)); + minpruning; + vec2[2]temp; + minimum; + push_vec2(in1); + } + break; + case OPMaxVec2: { + inputmask2(vec2_const_head,vec2_const_head); + vec2[2]in1=pull_vec2(ifconst(0)); + vec2[2]in2=pull_vec2(ifconst(1)); + maxpruning; + vec2[2]temp; + maximum; + push_vec2(in1); + } + break; + case OPFMAVec2: { + inputmask3(vec2_const_head,vec2_const_head,vec2_const_head); + vec2[2]in1=pull_vec2(ifconst(0)); + vec2[2]in2=pull_vec2(ifconst(1)); + vec2[2]in3=pull_vec2(ifconst(2)); + vec2[4]temp; + fmaof; + push_vec2(in1); + } + break; + + case OPAbsVec3: { + inputmask1(vec3_const_head); + vec3[2]in1=pull_vec3(ifconst(0)); + vec3[2]temp; + bvec3 mixer = bvec3(false); + vec3 zero = vec3(0); + absolute; + push_vec3(in1); + } + break; + case OPSignVec3: { + inputmask1(vec3_const_head); + vec3[2]in1=pull_vec3(ifconst(0)); + vec3[2]temp; + signof; + push_vec3(in1); + } + break; + case OPFloorVec3: { + inputmask1(vec3_const_head); + vec3[2]in1=pull_vec3(ifconst(0)); + vec3[2]temp; + floorof; + push_vec3(in1); + } + break; + case OPCeilVec3: { + inputmask1(vec3_const_head); + vec3[2]in1=pull_vec3(ifconst(0)); + vec3[2]temp; + ceilingof; + push_vec3(in1); + } + break; + case OPFractVec3: { + inputmask1(vec3_const_head); + vec3[2]in1=pull_vec3(ifconst(0)); + vec3[2]temp; + bvec3 mixer = bvec3(false); + vec3 zero = vec3(0); + vec3 one = vec3(1); + fractionalof; + push_vec3(in1); + } + break; + case OPSqrtVec3: { + inputmask1(vec3_const_head); + vec3[2]in1=pull_vec3(ifconst(0)); + vec3[2]temp; + squarerootof; + push_vec3(in1); + } + break; + case OPInverseSqrtVec3: { + inputmask1(vec3_const_head); + vec3[2]in1=pull_vec3(ifconst(0)); + vec3[2]temp; + inversesquarerootof; + push_vec3(in1); + } + break; + case OPExpVec3: { + inputmask1(vec3_const_head); + vec3[2]in1=pull_vec3(ifconst(0)); + vec3[2]temp; + exponentof; + push_vec3(in1); + } + break; + case OPExp2Vec3: { + inputmask1(vec3_const_head); + vec3[2]in1=pull_vec3(ifconst(0)); + vec3[2]temp; + exponent2of; + push_vec3(in1); + } + break; + case OPLogVec3: { + inputmask1(vec3_const_head); + vec3[2]in1=pull_vec3(ifconst(0)); + vec3[2]temp; + logarithmof; + push_vec3(in1); + } + break; + case OPLog2Vec3: { + inputmask1(vec3_const_head); + vec3[2]in1=pull_vec3(ifconst(0)); + vec3[2]temp; + logarithm2of; + push_vec3(in1); + } + break; + case OPSinVec3: { + inputmask1(vec3_const_head); + vec3[2]in1=pull_vec3(ifconst(0)); + vec3[2]temp; + bvec3 mixer1 = bvec3(false); + bvec3 mixer2 = bvec3(false); + bvec3 vfalse = bvec3(false); + bvec3 vtrue = bvec3(true); + vec3 upper; + vec3 one = vec3(1); + vec3 zero = vec3(0); + vec3 minusone = vec3(-1); + sineof; + push_vec3(in1); + } + break; + case OPCosVec3: { + inputmask1(vec3_const_head); + vec3[2]in1=pull_vec3(ifconst(0)); + vec3[2]temp; + bvec3 mixer1 = bvec3(false); + bvec3 mixer2 = bvec3(false); + bvec3 vfalse = bvec3(false); + bvec3 vtrue = bvec3(true); + vec3 upper; + vec3 one = vec3(1); + vec3 zero = vec3(0); + vec3 minusone = vec3(-1); + cosineof; + push_vec3(in1); + } + break; + case OPTanVec3: { + inputmask1(vec3_const_head); + vec3[2]in1=pull_vec3(ifconst(0)); + vec3[2]temp; + bvec3 mixer1 = bvec3(false); + vec3 inf = vec3(INFINITY); + tangentof; + push_vec3(in1); + } + break; + case OPAsinVec3: { + inputmask1(vec3_const_head); + vec3[2]in1=pull_vec3(ifconst(0)); + vec3[2]temp; + arcsineof; + push_vec3(in1); + } + break; + case OPAcosVec3: { + inputmask1(vec3_const_head); + vec3[2]in1=pull_vec3(ifconst(0)); + vec3[2]temp; + arccosineof; + push_vec3(in1); + } + break; + case OPAtanVec3: { + inputmask1(vec3_const_head); + vec3[2]in1=pull_vec3(ifconst(0)); + vec3[2]temp; + arctangentof; + push_vec3(in1); + } + break; + case OPAcoshVec3:{ + inputmask1(vec3_const_head); + vec3[2]in1=pull_vec3(ifconst(0)); + vec3[2]temp; + hyperbolicarccosineof; + push_vec3(in1); + } + break; + case OPAsinhVec3:{ + inputmask1(vec3_const_head); + vec3[2]in1=pull_vec3(ifconst(0)); + vec3[2]temp; + hyperbolicarcsineof; + push_vec3(in1); + } + break; + case OPAtanhVec3:{ + inputmask1(vec3_const_head); + vec3[2]in1=pull_vec3(ifconst(0)); + vec3[2]temp; + hyperbolicarctangentof; + push_vec3(in1); + } + break; + case OPCoshVec3:{ + inputmask1(vec3_const_head); + vec3[2]in1=pull_vec3(ifconst(0)); + vec3[2]temp; + bvec3 mixer = bvec3(false); + vec3 one = vec3(1); + vec3 zero = vec3(0); + vec3[2] out1; + hyperboliccosineof; + push_vec3(out1); + } + break; + case OPSinhVec3:{ + inputmask1(vec3_const_head); + vec3[2]in1=pull_vec3(ifconst(0)); + vec3[2]temp; + hyperbolicsineof; + push_vec3(in1); + } + break; + case OPTanhVec3:{ + inputmask1(vec3_const_head); + vec3[2]in1=pull_vec3(ifconst(0)); + vec3[2]temp; + hyperbolictangentof; + push_vec3(in1); + } + break; + case OPRoundVec3:{ + inputmask1(vec3_const_head); + vec3[2]in1=pull_vec3(ifconst(0)); + vec3[2]temp; + roundof; + push_vec3(in1); + } + break; + case OPTruncVec3:{ + inputmask1(vec3_const_head); + vec3[2]in1=pull_vec3(ifconst(0)); + vec3[2]temp; + truncof; + push_vec3(in1); + } + break; + case OPMinVec3: { + inputmask2(vec3_const_head,vec3_const_head); + vec3[2]in1=pull_vec3(ifconst(0)); + vec3[2]in2=pull_vec3(ifconst(1)); + minpruning; + vec3[2]temp; + minimum; + push_vec3(in1); + } + break; + case OPMaxVec3: { + inputmask2(vec3_const_head,vec3_const_head); + vec3[2]in1=pull_vec3(ifconst(0)); + vec3[2]in2=pull_vec3(ifconst(1)); + maxpruning; + vec3[2]temp; + maximum; + push_vec3(in1); + } + break; + case OPFMAVec3: { + inputmask3(vec3_const_head,vec3_const_head,vec3_const_head); + vec3[2]in1=pull_vec3(ifconst(0)); + vec3[2]in2=pull_vec3(ifconst(1)); + vec3[2]in3=pull_vec3(ifconst(2)); + vec3[4]temp; + fmaof; + push_vec3(in1); + } + break; + + case OPAbsVec4: { + inputmask1(vec4_const_head); + vec4[2]in1=pull_vec4(ifconst(0)); + vec4[2]temp; + bvec4 mixer = bvec4(false); + vec4 zero = vec4(0); + absolute; + push_vec4(in1); + } + break; + case OPSignVec4: { + inputmask1(vec4_const_head); + vec4[2]in1=pull_vec4(ifconst(0)); + vec4[2]temp; + signof; + push_vec4(in1); + } + break; + case OPFloorVec4: { + inputmask1(vec4_const_head); + vec4[2]in1=pull_vec4(ifconst(0)); + vec4[2]temp; + floorof; + push_vec4(in1); + } + break; + case OPCeilVec4: { + inputmask1(vec4_const_head); + vec4[2]in1=pull_vec4(ifconst(0)); + vec4[2]temp; + ceilingof; + push_vec4(in1); + } + break; + case OPFractVec4: { + inputmask1(vec4_const_head); + vec4[2]in1=pull_vec4(ifconst(0)); + vec4[2]temp; + bvec4 mixer = bvec4(false); + vec4 zero = vec4(0); + vec4 one = vec4(1); + fractionalof; + push_vec4(in1); + } + break; + case OPSqrtVec4: { + inputmask1(vec4_const_head); + vec4[2]in1=pull_vec4(ifconst(0)); + vec4[2]temp; + squarerootof; + push_vec4(in1); + } + break; + case OPInverseSqrtVec4: { + inputmask1(vec4_const_head); + vec4[2]in1=pull_vec4(ifconst(0)); + vec4[2]temp; + inversesquarerootof; + push_vec4(in1); + } + break; + case OPExpVec4: { + inputmask1(vec4_const_head); + vec4[2]in1=pull_vec4(ifconst(0)); + vec4[2]temp; + exponentof; + push_vec4(in1); + } + break; + case OPExp2Vec4: { + inputmask1(vec4_const_head); + vec4[2]in1=pull_vec4(ifconst(0)); + vec4[2]temp; + exponent2of; + push_vec4(in1); + } + break; + case OPLogVec4: { + inputmask1(vec4_const_head); + vec4[2]in1=pull_vec4(ifconst(0)); + vec4[2]temp; + logarithmof; + push_vec4(in1); + } + break; + case OPLog2Vec4: { + inputmask1(vec4_const_head); + vec4[2]in1=pull_vec4(ifconst(0)); + vec4[2]temp; + logarithm2of; + push_vec4(in1); + } + break; + case OPSinVec4: { + inputmask1(vec4_const_head); + vec4[2]in1=pull_vec4(ifconst(0)); + vec4[2]temp; + bvec4 mixer1 = bvec4(false); + bvec4 mixer2 = bvec4(false); + bvec4 vfalse = bvec4(false); + bvec4 vtrue = bvec4(true); + vec4 upper; + vec4 one = vec4(1); + vec4 zero = vec4(0); + vec4 minusone = vec4(-1); + sineof; + push_vec4(in1); + } + break; + case OPCosVec4: { + inputmask1(vec4_const_head); + vec4[2]in1=pull_vec4(ifconst(0)); + vec4[2]temp; + bvec4 mixer1 = bvec4(false); + bvec4 mixer2 = bvec4(false); + bvec4 vfalse = bvec4(false); + bvec4 vtrue = bvec4(true); + vec4 upper; + vec4 one = vec4(1); + vec4 zero = vec4(0); + vec4 minusone = vec4(-1); + cosineof; + push_vec4(in1); + } + break; + case OPTanVec4: { + inputmask1(vec4_const_head); + vec4[2]in1=pull_vec4(ifconst(0)); + vec4[2]temp; + bvec4 mixer1 = bvec4(false); + vec4 inf = vec4(INFINITY); + tangentof; + push_vec4(in1); + } + break; + case OPAsinVec4: { + inputmask1(vec4_const_head); + vec4[2]in1=pull_vec4(ifconst(0)); + vec4[2]temp; + arcsineof; + push_vec4(in1); + } + break; + case OPAcosVec4: { + inputmask1(vec4_const_head); + vec4[2]in1=pull_vec4(ifconst(0)); + vec4[2]temp; + arccosineof; + push_vec4(in1); + } + break; + case OPAtanVec4: { + inputmask1(vec4_const_head); + vec4[2]in1=pull_vec4(ifconst(0)); + vec4[2]temp; + arctangentof; + push_vec4(in1); + } + break; + case OPAcoshVec4:{ + inputmask1(vec4_const_head); + vec4[2]in1=pull_vec4(ifconst(0)); + vec4[2]temp; + hyperbolicarccosineof; + push_vec4(in1); + } + break; + case OPAsinhVec4:{ + inputmask1(vec4_const_head); + vec4[2]in1=pull_vec4(ifconst(0)); + vec4[2]temp; + hyperbolicarcsineof; + push_vec4(in1); + } + break; + case OPAtanhVec4:{ + inputmask1(vec4_const_head); + vec4[2]in1=pull_vec4(ifconst(0)); + vec4[2]temp; + hyperbolicarctangentof; + push_vec4(in1); + } + break; + case OPCoshVec4:{ + inputmask1(vec4_const_head); + vec4[2]in1=pull_vec4(ifconst(0)); + vec4[2]temp; + bvec4 mixer = bvec4(false); + vec4 one = vec4(1); + vec4 zero = vec4(0); + vec4[2] out1; + hyperboliccosineof; + push_vec4(out1); + } + break; + case OPSinhVec4:{ + inputmask1(vec4_const_head); + vec4[2]in1=pull_vec4(ifconst(0)); + vec4[2]temp; + hyperbolicsineof; + push_vec4(in1); + } + break; + case OPTanhVec4:{ + inputmask1(vec4_const_head); + vec4[2]in1=pull_vec4(ifconst(0)); + vec4[2]temp; + hyperbolictangentof; + push_vec4(in1); + } + break; + case OPRoundVec4:{ + inputmask1(vec4_const_head); + vec4[2]in1=pull_vec4(ifconst(0)); + vec4[2]temp; + roundof; + push_vec4(in1); + } + break; + case OPTruncVec4:{ + inputmask1(vec4_const_head); + vec4[2]in1=pull_vec4(ifconst(0)); + vec4[2]temp; + truncof; + push_vec4(in1); + } + break; + case OPMinVec4: { + inputmask2(vec4_const_head,vec4_const_head); + vec4[2]in1=pull_vec4(ifconst(0)); + vec4[2]in2=pull_vec4(ifconst(1)); + minpruning; + vec4[2]temp; + minimum; + push_vec4(in1); + } + break; + case OPMaxVec4: { + inputmask2(vec4_const_head,vec4_const_head); + vec4[2]in1=pull_vec4(ifconst(0)); + vec4[2]in2=pull_vec4(ifconst(1)); + maxpruning; + vec4[2]temp; + maximum; + push_vec4(in1); + } + break; + case OPFMAVec4: { + inputmask3(vec4_const_head,vec4_const_head,vec4_const_head); + vec4[2]in1=pull_vec4(ifconst(0)); + vec4[2]in2=pull_vec4(ifconst(1)); + vec4[2]in3=pull_vec4(ifconst(2)); + vec4[4]temp; + fmaof; + push_vec4(in1); + } + break; + + case OPClampFloatFloat:{ + inputmask3(float_const_head,float_const_head,float_const_head); + float[2]in1=pull_float(ifconst(0)); + float[2]in2=pull_float(ifconst(1)); + float[2]in3=pull_float(ifconst(2)); + clampof; + push_float(in1); + } + break; + case OPMixFloatFloat:{ + inputmask3(float_const_head,float_const_head,float_const_head); + float[2]in1=pull_float(ifconst(0)); + float[2]in2=pull_float(ifconst(1)); + float[2]in3=pull_float(ifconst(2)); + mixof; + push_float(in1); + } + break; + case OPClampVec2Vec2:{ + inputmask3(vec2_const_head,vec2_const_head,vec2_const_head); + vec2[2]in1=pull_vec2(ifconst(0)); + vec2[2]in2=pull_vec2(ifconst(1)); + vec2[2]in3=pull_vec2(ifconst(2)); + clampof; + push_vec2(in1); + } + break; + case OPMixVec2Vec2:{ + inputmask3(vec2_const_head,vec2_const_head,vec2_const_head); + vec2[2]in1=pull_vec2(ifconst(0)); + vec2[2]in2=pull_vec2(ifconst(1)); + vec2[2]in3=pull_vec2(ifconst(2)); + mixof; + push_vec2(in1); + } + break; + case OPClampVec2Float:{ + inputmask3(vec2_const_head,float_const_head,float_const_head); + vec2[2]in1=pull_vec2(ifconst(0)); + float[2]in2=pull_float(ifconst(1)); + float[2]in3=pull_float(ifconst(2)); + clampof; + push_vec2(in1); + } + break; + case OPMixVec2Float:{ + inputmask3(vec2_const_head,vec2_const_head,float_const_head); + vec2[2]in1=pull_vec2(ifconst(0)); + vec2[2]in2=pull_vec2(ifconst(1)); + float[2]in3=pull_float(ifconst(2)); + mixof; + push_vec2(in1); + } + break; + case OPClampVec3Vec3:{ + inputmask3(vec3_const_head,vec3_const_head,vec3_const_head); + vec3[2]in1=pull_vec3(ifconst(0)); + vec3[2]in2=pull_vec3(ifconst(1)); + vec3[2]in3=pull_vec3(ifconst(2)); + clampof; + push_vec3(in1); + } + break; + case OPMixVec3Vec3:{ + inputmask3(vec3_const_head,vec3_const_head,vec3_const_head); + vec3[2]in1=pull_vec3(ifconst(0)); + vec3[2]in2=pull_vec3(ifconst(1)); + vec3[2]in3=pull_vec3(ifconst(2)); + mixof; + push_vec3(in1); + } + break; + case OPClampVec3Float:{ + inputmask3(vec3_const_head,float_const_head,float_const_head); + vec3[2]in1=pull_vec3(ifconst(0)); + float[2]in2=pull_float(ifconst(1)); + float[2]in3=pull_float(ifconst(2)); + clampof; + push_vec3(in1); + } + break; + case OPMixVec3Float:{ + inputmask3(vec3_const_head,vec3_const_head,float_const_head); + vec3[2]in1=pull_vec3(ifconst(0)); + vec3[2]in2=pull_vec3(ifconst(1)); + float[2]in3=pull_float(ifconst(2)); + mixof; + push_vec3(in1); + } + break; + case OPClampVec4Vec4:{ + inputmask3(vec4_const_head,vec4_const_head,vec4_const_head); + vec4[2]in1=pull_vec4(ifconst(0)); + vec4[2]in2=pull_vec4(ifconst(1)); + vec4[2]in3=pull_vec4(ifconst(2)); + clampof; + push_vec4(in1); + } + break; + case OPMixVec4Vec4:{ + inputmask3(vec4_const_head,vec4_const_head,vec4_const_head); + vec4[2]in1=pull_vec4(ifconst(0)); + vec4[2]in2=pull_vec4(ifconst(1)); + vec4[2]in3=pull_vec4(ifconst(2)); + mixof; + push_vec4(in1); + } + break; + case OPClampVec4Float:{ + inputmask3(vec4_const_head,float_const_head,float_const_head); + vec4[2]in1=pull_vec4(ifconst(0)); + float[2]in2=pull_float(ifconst(1)); + float[2]in3=pull_float(ifconst(2)); + clampof; + push_vec4(in1); + } + break; + case OPMixVec4Float:{ + inputmask3(vec4_const_head,vec4_const_head,float_const_head); + vec4[2]in1=pull_vec4(ifconst(0)); + vec4[2]in2=pull_vec4(ifconst(1)); + float[2]in3=pull_float(ifconst(2)); + mixof; + push_vec4(in1); + } + break; + + case OPNormalizeVec2:{ + inputmask1(vec2_const_head); + vec2[2]in1=pull_vec2(ifconst(0)); + bvec2 mixer=mix(bvec2(false),greaterThan(in1[1],vec2(0)),lessThan(in1[0],vec2(0))); + vec2 smallest=mix(min(abs(in1[0]),abs(in1[1])),vec2(0),mixer); + vec2 largest=max(abs(in1[0]),abs(in1[1])); + vec2 outmax=max(vec2( + in1[1].x/length(vec2(in1[1].x,smallest.y)), + in1[1].y/length(vec2(smallest.x,in1[1].y)) + ), + vec2( + in1[1].x/length(vec2(in1[1].x,largest.y)), + in1[1].y/length(vec2(largest.x,in1[1].y)) + ) + ); + vec2 outmin=min(vec2( + in1[0].x/length(vec2(in1[0].x,smallest.y)), + in1[0].y/length(vec2(smallest.x,in1[0].y)) + ), + vec2( + in1[0].x/length(vec2(in1[0].x,largest.y)), + in1[0].y/length(vec2(largest.x,in1[0].y)) + ) + ); + push_vec2(vec2[2](outmin,outmax)); + } + break; + case OPNormalizeVec3:{ + inputmask1(vec3_const_head); + vec3[2]in1=pull_vec3(ifconst(0)); + bvec3 mixer=mix(bvec3(false),greaterThan(in1[1],vec3(0)),lessThan(in1[0],vec3(0))); + vec3 smallest=mix(min(abs(in1[0]),abs(in1[1])),vec3(0),mixer); + vec3 largest=max(abs(in1[0]),abs(in1[1])); + vec3 outmax=max(vec3( + in1[1].x/length(vec3(in1[1].x,smallest.y,smallest.z)), + in1[1].y/length(vec3(smallest.x,in1[1].y,smallest.z)), + in1[1].z/length(vec3(smallest.x,smallest.y,in1[1].z)) + ), + vec3( + in1[1].x/length(vec3(in1[1].x,largest.y,largest.z)), + in1[1].y/length(vec3(largest.x,in1[1].y,largest.z)), + in1[1].z/length(vec3(largest.x,largest.y,in1[1].z)) + ) + ); + vec3 outmin=min(vec3( + in1[0].x/length(vec3(in1[0].x,smallest.y,smallest.z)), + in1[0].y/length(vec3(smallest.x,in1[0].y,smallest.z)), + in1[0].z/length(vec3(smallest.x,smallest.y,in1[0].z)) + ), + vec3( + in1[0].x/length(vec3(in1[0].x,largest.y,largest.z)), + in1[0].y/length(vec3(largest.x,in1[0].y,largest.z)), + in1[0].z/length(vec3(largest.x,largest.y,in1[0].z)) + ) + ); + push_vec3(vec3[2](outmin,outmax)); + } + break; + case OPNormalizeVec4:{ + inputmask1(vec4_const_head); + vec4[2]in1=pull_vec4(ifconst(0)); + bvec4 mixer=mix(bvec4(false),greaterThan(in1[1],vec4(0)),lessThan(in1[0],vec4(0))); + vec4 smallest=mix(min(abs(in1[0]),abs(in1[1])),vec4(0),mixer); + vec4 largest=max(abs(in1[0]),abs(in1[1])); + vec4 outmax=max(vec4( + in1[1].x/length(vec4(in1[1].x,smallest.y,smallest.z,smallest.w)), + in1[1].y/length(vec4(smallest.x,in1[1].y,smallest.z,smallest.w)), + in1[1].z/length(vec4(smallest.x,smallest.y,in1[1].z,smallest.w)), + in1[1].w/length(vec4(smallest.x,smallest.y,smallest.z,in1[1].w)) + ), + vec4( + in1[1].x/length(vec4(in1[1].x,largest.y,largest.z,largest.w)), + in1[1].y/length(vec4(largest.x,in1[1].y,largest.z,largest.w)), + in1[1].z/length(vec4(largest.x,largest.y,in1[1].z,largest.w)), + in1[1].w/length(vec4(largest.x,largest.y,largest.z,in1[1].w)) + ) + ); + vec4 outmin=min(vec4( + in1[0].x/length(vec4(in1[0].x,smallest.y,smallest.z,smallest.w)), + in1[0].y/length(vec4(smallest.x,in1[0].y,smallest.z,smallest.w)), + in1[0].z/length(vec4(smallest.x,smallest.y,in1[0].z,smallest.w)), + in1[0].w/length(vec4(smallest.x,smallest.y,smallest.z,in1[0].w)) + ), + vec4( + in1[0].x/length(vec4(in1[0].x,largest.y,largest.z,largest.w)), + in1[0].y/length(vec4(largest.x,in1[0].y,largest.z,largest.w)), + in1[0].z/length(vec4(largest.x,largest.y,in1[0].z,largest.w)), + in1[0].w/length(vec4(largest.x,largest.y,largest.z,in1[0].w)) + ) + ); + push_vec4(vec4[2](outmin,outmax)); + } + break; + + case OPPromoteFloatFloatVec2:{ + inputmask2(float_const_head,float_const_head); + float[2] a = pull_float(ifconst(0)); + float[2] b = pull_float(ifconst(1)); + push_vec2(vec2[2](vec2(a[0],b[0]),vec2(a[1],b[1]))); + } + break; + case OPPromoteFloatFloatFloatVec3:{ + inputmask3(float_const_head,float_const_head,float_const_head); + float[2] a = pull_float(ifconst(0)); + float[2] b = pull_float(ifconst(1)); + float[2] c = pull_float(ifconst(2)); + push_vec3(vec3[2](vec3(a[0],b[0],c[0]),vec3(a[1],b[1],c[1]))); + } + break; + case OPPromoteVec2FloatVec3:{ + inputmask2(vec2_const_head,float_const_head); + vec2[2] a = pull_vec2(ifconst(0)); + float[2] b = pull_float(ifconst(1)); + push_vec3(vec3[2](vec3(a[0],b[0]),vec3(a[1],b[1]))); + } + break; + case OPPromoteFloatFloatFloatFloatVec4:{ + inputmask4(float_const_head,float_const_head,float_const_head,float_const_head); + float[2] a = pull_float(ifconst(0)); + float[2] b = pull_float(ifconst(1)); + float[2] c = pull_float(ifconst(2)); + float[2] d = pull_float(ifconst(3)); + push_vec4(vec4[2](vec4(a[0],b[0],c[0],d[0]),vec4(a[1],b[1],c[1],d[1]))); + } + break; + case OPPromoteVec2FloatFloatVec4:{ + inputmask3(vec2_const_head,float_const_head,float_const_head); + vec2[2] a = pull_vec2(ifconst(0)); + float[2] b = pull_float(ifconst(1)); + float[2] c = pull_float(ifconst(2)); + push_vec4(vec4[2](vec4(a[0],b[0],c[0]),vec4(a[1],b[1],c[1]))); + } + break; + case OPPromoteVec3FloatVec4:{ + inputmask2(vec3_const_head,float_const_head); + vec3[2] a = pull_vec3(ifconst(0)); + float[2] b = pull_float(ifconst(1)); + push_vec4(vec4[2](vec4(a[0],b[0]),vec4(a[1],b[1]))); + } + break; + case OPPromoteVec2Vec2Vec4:{ + inputmask2(vec2_const_head,vec2_const_head); + vec2[2] a = pull_vec2(ifconst(0)); + vec2[2] b = pull_vec2(ifconst(1)); + push_vec4(vec4[2](vec4(a[0],b[0]),vec4(a[1],b[1]))); + } + break; + + /* + case OPDemoteMat2Float:{ + mat2[2] mat2temp=pull_mat2(ifconst(0)); + push_float(float[2](mat2temp[0][1].y,mat2temp[1][1].y)); + push_float(float[2](mat2temp[0][1].x,mat2temp[1][1].x)); + push_float(float[2](mat2temp[0][0].y,mat2temp[1][0].y)); + push_float(float[2](mat2temp[0][0].x,mat2temp[1][0].x)); + } + break; + case OPDemoteMat2Vec2:{ + mat2[2] mat2temp=pull_mat2(ifconst(0)); + push_vec2(vec2[2](mat2temp[0][1],mat2temp[1][1])); + push_vec2(vec2[2](mat2temp[0][0],mat2temp[1][0])); + } + break; + case OPDemoteMat3Vec3:{ + mat3[2] mat3temp=pull_mat3(ifconst(0)); + push_vec3(vec3[2](mat3temp[0][2],mat3temp[1][2])); + push_vec3(vec3[2](mat3temp[0][1],mat3temp[1][1])); + push_vec3(vec3[2](mat3temp[0][0],mat3temp[1][0])); + } + break; + case OPDemoteMat4Vec4:{ + mat4[2] mat4temp=pull_mat4(ifconst(0)); + push_vec4(vec4[2](mat4temp[0][3],mat4temp[1][3])); + push_vec4(vec4[2](mat4temp[0][2],mat4temp[1][2])); + push_vec4(vec4[2](mat4temp[0][1],mat4temp[1][1])); + push_vec4(vec4[2](mat4temp[0][0],mat4temp[1][0])); + } + break; + case OPDemoteMat2Vec4:{ + mat2[2] mat2temp=pull_mat2(ifconst(0)); + push_vec4(vec4[2](vec4(mat2temp[0][0],mat2temp[0][1]),vec4(mat2temp[1][0],mat2temp[1][1]))); + } + break; + case OPDemoteVec2FloatFloat:{ + vec2[2] vec2temp=pull_vec2(ifconst(0)); + push_float(float[2](vec2temp[0].y,vec2temp[1].y)); + push_float(float[2](vec2temp[0].x,vec2temp[1].x)); + } + break; + case OPDemoteVec3FloatFloatFloat:{ + vec3[2] vec3temp=pull_vec3(ifconst(0)); + push_float(float[2](vec3temp[0].z,vec3temp[1].z)); + push_float(float[2](vec3temp[0].y,vec3temp[1].y)); + push_float(float[2](vec3temp[0].x,vec3temp[1].x)); + } + break; + case OPDemoteVec4FloatFloatFloatFloat:{ + vec4[2] vec4temp=pull_vec4(ifconst(0)); + push_float(float[2](vec4temp[0].w,vec4temp[1].w)); + push_float(float[2](vec4temp[0].z,vec4temp[1].z)); + push_float(float[2](vec4temp[0].y,vec4temp[1].y)); + push_float(float[2](vec4temp[0].x,vec4temp[1].x)); + } + break; + */ + + case OPSquareFloat:{ + inputmask1(float_const_head); + float[2] in1 = pull_float(ifconst(0)); + float[2] out1; + if (in1[1] > 0 && in1[0] < 0) + { + out1[0] = 0; + } + else { + out1[0] = min(in1[0]*in1[0],in1[1]*in1[1]); + } + out1[1]=max(in1[0]*in1[0],in1[1]*in1[1]); + push_float(out1); + } + break; + case OPCubeFloat:{ + inputmask1(float_const_head); + float[2] in1 = pull_float(ifconst(0)); + float[2] out1; + bool mixer = false; + float zero = 0; + cube; + push_float(out1); + } + break; + case OPSquareVec2:{ + inputmask1(vec2_const_head); + vec2[2] in1 = pull_vec2(ifconst(0)); + vec2[2] out1; + bvec2 mixer = bvec2(false); + vec2 zero = vec2(0); + square; + push_vec2(out1); + } + break; + case OPCubeVec2:{ + inputmask1(vec2_const_head); + vec2[2] in1 = pull_vec2(ifconst(0)); + vec2[2] out1; + bvec2 mixer = bvec2(false); + vec2 zero = vec2(0); + cube; + push_vec2(out1); + } + break; + case OPSquareVec3:{ + inputmask1(vec3_const_head); + vec3[2] in1 = pull_vec3(ifconst(0)); + vec3[2] out1; + bvec3 mixer = bvec3(false); + vec3 zero = vec3(0); + square; + push_vec3(out1); + } + break; + case OPCubeVec3:{ + inputmask1(vec3_const_head); + vec3[2] in1 = pull_vec3(ifconst(0)); + vec3[2] out1; + bvec3 mixer = bvec3(false); + vec3 zero = vec3(0); + cube; + push_vec3(out1); + } + break; + case OPSquareVec4:{ + inputmask1(vec4_const_head); + vec4[2] in1 = pull_vec4(ifconst(0)); + vec4[2] out1; + bvec4 mixer = bvec4(false); + vec4 zero = vec4(0); + square; + push_vec4(out1); + } + break; + case OPCubeVec4:{ + inputmask1(vec4_const_head); + vec4[2] in1 = pull_vec4(ifconst(0)); + vec4[2] out1; + bvec4 mixer = bvec4(false); + vec4 zero = vec4(0); + cube; + push_vec4(out1); + } + break; + + case OPSmoothMinMaterialFloat: + case OPSmoothMinFloat:{ + if(maskdefine){ + if(ifconst(0)) {float_const_head++;} + if(ifconst(1)) {float_const_head++;} + float_const_head++; + break; + } + float k=cpull_float(); + float[2] a=pull_float(ifconst(0)); + float[2] b=pull_float(ifconst(1)); + float hmin=max(k-abs(a[0]-b[0]),0.); + float hmax=max(k-abs(a[1]-b[1]),0.); + float smin=min(a[0],b[0])-hmin*hmin*.25/k; + float smax=min(a[1],b[1])-hmax*hmax*.25/k; + push_float(float[2](smin,smax)); + } + break; + case OPSmoothMaxMaterialFloat: + case OPSmoothMaxFloat:{ + if(maskdefine){ + if(ifconst(0)) {float_const_head++;} + if(ifconst(1)) {float_const_head++;} + float_const_head++; + break; + } + float k=cpull_float(); + float[2] a=pull_float(ifconst(0)); + float[2] b=pull_float(ifconst(1)); + float hmin=max(k-abs(a[0]-b[0]),0.); + float hmax=max(k-abs(a[1]-b[1]),0.); + float smin=max(a[0],b[0])+hmin*hmin*.25/k; + float smax=max(a[1],b[1])+hmax*hmax*.25/k; + push_float(float[2](smin,smax)); + } + break; + + /* + case OPSwap2Float:{ + float[2]floattemp=float_stack[float_stack_head-1]; + float_stack[float_stack_head-1]=float_stack[float_stack_head-2]; + float_stack[float_stack_head-2]=floattemp; + } + break; + case OPSwap3Float:{ + float[2]floattemp=float_stack[float_stack_head-1]; + float_stack[float_stack_head-1]=float_stack[float_stack_head-3]; + float_stack[float_stack_head-3]=floattemp; + } + break; + case OPSwap4Float:{ + float[2]floattemp=float_stack[float_stack_head-1]; + float_stack[float_stack_head-1]=float_stack[float_stack_head-4]; + float_stack[float_stack_head-4]=floattemp; + } + */ + break; + case OPDupFloat:{ + push_float(float_stack[float_stack_head-1]); + } + break; + case OPDup2Float:{ + push_float(float_stack[float_stack_head-2]); + } + break; + case OPDup3Float:{ + push_float(float_stack[float_stack_head-3]); + } + break; + case OPDup4Float:{ + push_float(float_stack[float_stack_head-4]); + } + break; + /* + case OPDropFloat:{ + float_stack_head--; + } + break; + case OPDrop2Float:{ + float_stack[float_stack_head-2]=float_stack[float_stack_head-1]; + float_stack_head--; + } + break; + case OPDrop3Float:{ + float_stack[float_stack_head-3]=float_stack[float_stack_head-2]; + float_stack[float_stack_head-2]=float_stack[float_stack_head-1]; + float_stack_head--; + } + break; + case OPDrop4Float:{ + float_stack[float_stack_head-4]=float_stack[float_stack_head-3]; + float_stack[float_stack_head-3]=float_stack[float_stack_head-2]; + float_stack[float_stack_head-2]=float_stack[float_stack_head-1]; + float_stack_head--; + } + break; + */ + /* + case OPSwap2Vec2:{ + vec2[2]vec2temp=vec2_stack[vec2_stack_head-1]; + vec2_stack[vec2_stack_head-1]=vec2_stack[vec2_stack_head-2]; + vec2_stack[vec2_stack_head-2]=vec2temp; + } + break; + case OPSwap3Vec2:{ + vec2[2]vec2temp=vec2_stack[vec2_stack_head-1]; + vec2_stack[vec2_stack_head-1]=vec2_stack[vec2_stack_head-3]; + vec2_stack[vec2_stack_head-3]=vec2temp; + } + break; + case OPSwap4Vec2:{ + vec2[2]vec2temp=vec2_stack[vec2_stack_head-1]; + vec2_stack[vec2_stack_head-1]=vec2_stack[vec2_stack_head-4]; + vec2_stack[vec2_stack_head-4]=vec2temp; + } + break; + */ + case OPDupVec2:{ + push_vec2(vec2_stack[vec2_stack_head-1]); + } + break; + case OPDup2Vec2:{ + push_vec2(vec2_stack[vec2_stack_head-2]); + } + break; + case OPDup3Vec2:{ + push_vec2(vec2_stack[vec2_stack_head-3]); + } + break; + case OPDup4Vec2:{ + push_vec2(vec2_stack[vec2_stack_head-4]); + } + break; + /* + case OPDropVec2:{ + vec2_stack_head--; + } + break; + case OPDrop2Vec2:{ + vec2_stack[vec2_stack_head-2]=vec2_stack[vec2_stack_head-1]; + vec2_stack_head--; + } + break; + case OPDrop3Vec2:{ + vec2_stack[vec2_stack_head-3]=vec2_stack[vec2_stack_head-2]; + vec2_stack[vec2_stack_head-2]=vec2_stack[vec2_stack_head-1]; + vec2_stack_head--; + } + break; + case OPDrop4Vec2:{ + vec2_stack[vec2_stack_head-4]=vec2_stack[vec2_stack_head-3]; + vec2_stack[vec2_stack_head-3]=vec2_stack[vec2_stack_head-2]; + vec2_stack[vec2_stack_head-2]=vec2_stack[vec2_stack_head-1]; + vec2_stack_head--; + } + break; + */ + /* + case OPSwap2Vec3:{ + vec3[2]vec3temp=vec3_stack[vec3_stack_head-1]; + vec3_stack[vec3_stack_head-1]=vec3_stack[vec3_stack_head-2]; + vec3_stack[vec3_stack_head-2]=vec3temp; + } + break; + case OPSwap3Vec3:{ + vec3[2]vec3temp=vec3_stack[vec3_stack_head-1]; + vec3_stack[vec3_stack_head-1]=vec3_stack[vec3_stack_head-3]; + vec3_stack[vec3_stack_head-3]=vec3temp; + } + break; + case OPSwap4Vec3:{ + vec3[2]vec3temp=vec3_stack[vec3_stack_head-1]; + vec3_stack[vec3_stack_head-1]=vec3_stack[vec3_stack_head-4]; + vec3_stack[vec3_stack_head-4]=vec3temp; + } + break; + */ + case OPDupVec3:{ + push_vec3(vec3_stack[vec3_stack_head-1]); + } + break; + case OPDup2Vec3:{ + push_vec3(vec3_stack[vec3_stack_head-2]); + } + break; + case OPDup3Vec3:{ + push_vec3(vec3_stack[vec3_stack_head-3]); + } + break; + case OPDup4Vec3:{ + push_vec3(vec3_stack[vec3_stack_head-4]); + } + break; + /* + case OPDropVec3:{ + vec3_stack_head--; + } + break; + case OPDrop2Vec3:{ + vec3_stack[vec3_stack_head-2]=vec3_stack[vec3_stack_head-1]; + vec3_stack_head--; + } + break; + case OPDrop3Vec3:{ + vec3_stack[vec3_stack_head-3]=vec3_stack[vec3_stack_head-2]; + vec3_stack[vec3_stack_head-2]=vec3_stack[vec3_stack_head-1]; + vec3_stack_head--; + } + break; + case OPDrop4Vec3:{ + vec3_stack[vec3_stack_head-4]=vec3_stack[vec3_stack_head-3]; + vec3_stack[vec3_stack_head-3]=vec3_stack[vec3_stack_head-2]; + vec3_stack[vec3_stack_head-2]=vec3_stack[vec3_stack_head-1]; + vec3_stack_head--; + } + break; + */ + /* + case OPSwap2Vec4:{ + vec4[2]vec4temp=vec4_stack[vec4_stack_head-1]; + vec4_stack[vec4_stack_head-1]=vec4_stack[vec4_stack_head-2]; + vec4_stack[vec4_stack_head-2]=vec4temp; + } + break; + case OPSwap3Vec4:{ + vec4[2]vec4temp=vec4_stack[vec4_stack_head-1]; + vec4_stack[vec4_stack_head-1]=vec4_stack[vec4_stack_head-3]; + vec4_stack[vec4_stack_head-3]=vec4temp; + } + break; + case OPSwap4Vec4:{ + vec4[2]vec4temp=vec4_stack[vec4_stack_head-1]; + vec4_stack[vec4_stack_head-1]=vec4_stack[vec4_stack_head-4]; + vec4_stack[vec4_stack_head-4]=vec4temp; + } + break; + */ + case OPDupVec4:{ + push_vec4(vec4_stack[vec4_stack_head-1]); + } + break; + case OPDup2Vec4:{ + push_vec4(vec4_stack[vec4_stack_head-2]); + } + break; + case OPDup3Vec4:{ + push_vec4(vec4_stack[vec4_stack_head-3]); + } + break; + case OPDup4Vec4:{ + push_vec4(vec4_stack[vec4_stack_head-4]); + } + break; + /* + case OPDropVec4:{ + vec4_stack_head--; + } + break; + case OPDrop2Vec4:{ + vec4_stack[vec4_stack_head-2]=vec4_stack[vec4_stack_head-1]; + vec4_stack_head--; + } + break; + case OPDrop3Vec4:{ + vec4_stack[vec4_stack_head-3]=vec4_stack[vec4_stack_head-2]; + vec4_stack[vec4_stack_head-2]=vec4_stack[vec4_stack_head-1]; + vec4_stack_head--; + } + break; + case OPDrop4Vec4:{ + vec4_stack[vec4_stack_head-4]=vec4_stack[vec4_stack_head-3]; + vec4_stack[vec4_stack_head-3]=vec4_stack[vec4_stack_head-2]; + vec4_stack[vec4_stack_head-2]=vec4_stack[vec4_stack_head-1]; + vec4_stack_head--; + } + break; + */ + + + case OPSDFSphere: + { + inputmask2(float_const_head,vec3_const_head); + float[2] in2=pull_float(ifconst(0)); + /*#ifdef debug + return vec3(in2[0],in2[1],0.); + #endif*/ + vec3[2] in1=pull_vec3(ifconst(1)); + /*#ifdef debug + return in1[0]; + #endif*/ + float[2] out1; + + bvec3 mixer=mix(bvec3(false),greaterThan(in1[1],vec3(0)),lessThan(in1[0],vec3(0))); + out1[0]=length(mix(min(abs(in1[0]),abs(in1[1])),vec3(0),mixer))-in2[1]; + out1[1]=length(max(abs(in1[0]),abs(in1[1])))-in2[0]; + + #ifdef debug + //return vec3(out1[0],out1[1],0.); + #endif + + push_float(out1); + } + break; + + case OPNop: + break; + case OPStop: + pruneall(uint8_t((major_position<<3)|minor_position)); + #ifdef debug + return vec3(pull_float(ifconst(0))[0]); + #else + return pull_float(ifconst(0)); + #endif + case OPInvalid: + default: + #ifdef debug + return vec3(float(minor_integer_cache[minor_position])); + #else + return float[2](0,0); + #endif + } + + minor_position++; + if(minor_position==8) + { + minor_position=0; + major_position++; + if(major_position==masklen) + { + pruneall(uint8_t((masklen*8))); + #ifdef debug + return vec3(pull_float(false)[0]); + #else + return pull_float(false); + #endif + } + } + } +} + +#ifdef debug +vec3 sceneoverride(vec3 p, bool m) +{ + return scene(vec3[2](p,p), false); +} +#else +float sceneoverride(vec3 p, bool m) +{ + return scene(vec3[2](p,p), false)[0]; +} +#endif + +} \ No newline at end of file diff --git a/src/intervals.glsl b/src/intervals.glsl index 1f1fad6209d9f2b8a6898a766ef0f3dd37931668..726ed697f0f030a0f6547bbaa17d7c04df813036 100644 --- a/src/intervals.glsl +++ b/src/intervals.glsl @@ -17,8 +17,10 @@ struct Description{ uint mat2s; uint mat3s; uint mat4s; + uint mats; uint dependencies; }; +Description desc; layout(set=0,binding=2)restrict readonly buffer SceneDescription{ Description desc[]; @@ -56,7 +58,7 @@ layout(set=0,binding=12)restrict readonly buffer DepInfo{ }depinfo; // unpack integers -#define get_caches u32vec4 major_unpack=scenes.opcodes[major_position+desc.scene];\ +#define get_caches u32vec4 major_unpack=scenes.opcodes[desc.scene+major_position];\ minor_integer_cache[0]=major_unpack.x&65535;\ minor_integer_cache[1]=major_unpack.x>>16;\ minor_integer_cache[2]=major_unpack.y&65535;\ @@ -88,6 +90,7 @@ uint vec4_const_head=0; uint mat2_const_head=0; uint mat3_const_head=0; uint mat4_const_head=0; +uint mat_const_head=0; void push_float(float f[2]){ float_stack[float_stack_head++]=f; @@ -95,7 +98,7 @@ void push_float(float f[2]){ float[2]pull_float(bool c){ if (c) { - float f = fconst.floats[float_const_head++]; + float f = fconst.floats[desc.floats+float_const_head++]; return float[2](f,f); } else { @@ -104,7 +107,7 @@ float[2]pull_float(bool c){ } float cpull_float(){ - return fconst.floats[float_const_head++]; + return fconst.floats[desc.floats+float_const_head++]; } void push_vec2(vec2 f[2]){ @@ -113,7 +116,7 @@ void push_vec2(vec2 f[2]){ vec2[2]pull_vec2(bool c){ if (c) { - vec2 f = v2const.vec2s[vec2_const_head++]; + vec2 f = v2const.vec2s[desc.vec2s+vec2_const_head++]; return vec2[2](f,f); } else { @@ -122,7 +125,7 @@ vec2[2]pull_vec2(bool c){ } vec2 cpull_vec2(){ - return v2const.vec2s[vec2_const_head++]; + return v2const.vec2s[desc.vec2s+vec2_const_head++]; } void push_vec3(vec3 f[2]){ @@ -131,7 +134,7 @@ void push_vec3(vec3 f[2]){ vec3[2]pull_vec3(bool c){ if (c) { - vec3 f = v3const.vec3s[vec3_const_head++]; + vec3 f = v3const.vec3s[desc.vec3s+vec3_const_head++]; return vec3[2](f,f); } else { @@ -140,7 +143,7 @@ vec3[2]pull_vec3(bool c){ } vec3 cpull_vec3(){ - return v3const.vec3s[vec3_const_head++]; + return v3const.vec3s[desc.vec3s+vec3_const_head++]; } void push_vec4(vec4 f[2]){ @@ -149,7 +152,7 @@ void push_vec4(vec4 f[2]){ vec4[2]pull_vec4(bool c){ if (c) { - vec4 f = v4const.vec4s[vec4_const_head++]; + vec4 f = v4const.vec4s[desc.vec4s+vec4_const_head++]; return vec4[2](f,f); } else { @@ -158,7 +161,7 @@ vec4[2]pull_vec4(bool c){ } vec4 cpull_vec4(){ - return v4const.vec4s[vec4_const_head++]; + return v4const.vec4s[desc.vec4s+vec4_const_head++]; } void push_mat2(mat2 f[2]){ @@ -167,7 +170,7 @@ void push_mat2(mat2 f[2]){ mat2[2]pull_mat2(bool c){ if (c) { - mat2 f = m2const.mat2s[mat2_const_head++]; + mat2 f = m2const.mat2s[desc.mat2s+mat2_const_head++]; return mat2[2](f,f); } else { @@ -176,7 +179,7 @@ mat2[2]pull_mat2(bool c){ } mat2 cpull_mat2(){ - return m2const.mat2s[mat2_const_head++]; + return m2const.mat2s[desc.mat2s+mat2_const_head++]; } void push_mat3(mat3 f[2]){ @@ -185,7 +188,7 @@ void push_mat3(mat3 f[2]){ mat3[2]pull_mat3(bool c){ if (c) { - mat3 f = m3const.mat3s[mat3_const_head++]; + mat3 f = m3const.mat3s[desc.mat3s+mat3_const_head++]; return mat3[2](f,f); } else { @@ -194,7 +197,7 @@ mat3[2]pull_mat3(bool c){ } mat3 cpull_mat3(){ - return m3const.mat3s[mat3_const_head++]; + return m3const.mat3s[desc.mat3s+mat3_const_head++]; } void push_mat4(mat4 f[2]){ @@ -203,7 +206,7 @@ void push_mat4(mat4 f[2]){ mat4[2]pull_mat4(bool c){ if (c) { - mat4 f = m4const.mat4s[mat4_const_head++]; + mat4 f = m4const.mat4s[desc.mat4s+mat4_const_head++]; return mat4[2](f,f); } else { @@ -212,7 +215,7 @@ mat4[2]pull_mat4(bool c){ } mat4 cpull_mat4(){ - return m4const.mat4s[mat4_const_head++]; + return m4const.mat4s[desc.mat4s+mat4_const_head++]; } void clear_stacks() @@ -231,6 +234,7 @@ void clear_stacks() mat2_const_head=0; mat3_const_head=0; mat4_const_head=0; + mat_const_head=0; } const int masklen = 29; @@ -554,7 +558,6 @@ void default_mask() in1[1]=trunc(in1[1]);\ } -Description desc; //0 - prune nothing //1 - prune myself //2 - prune myself and children @@ -694,21 +697,21 @@ void pruneself (int pos) { break;\ } -#define minpruning if (all(lessThan(in1[1],in2[0]))) {\ +#define minpruning if (prune) { if (all(lessThan(in1[1],in2[0]))) {\ prunesome(OPPos,bool[6](false,true,false,false,false,false));\ passthroughself(OPPos);\ } else if (all(lessThan(in2[1],in1[0]))) {\ prunesome(OPPos,bool[6](true,false,false,false,false,false));\ passthroughself(OPPos);\ -} +}} -#define maxpruning if (all(greaterThan(in1[0],in2[1]))) {\ +#define maxpruning if (prune) { if (all(greaterThan(in1[0],in2[1]))) {\ prunesome(OPPos,bool[6](false,true,false,false,false,false));\ passthroughself(OPPos);\ } else if (all(greaterThan(in2[0],in1[1]))) {\ prunesome(OPPos,bool[6](true,false,false,false,false,false));\ passthroughself(OPPos);\ -} +}} #ifdef debug vec3 scene(vec3 p[2], bool prune) @@ -721,7 +724,7 @@ float[2]scene(vec3 p[2], bool prune) uint minor_integer_cache[8]; - desc = scene_description.desc[gl_GlobalInvocationID.x]; + desc = scene_description.desc[(DescriptionIndex)+1]; clear_stacks(); push_vec3(p); @@ -732,15 +735,22 @@ float[2]scene(vec3 p[2], bool prune) if(minor_position==0){ get_caches; } - /*#ifdef debug - if((minor_integer_cache[minor_position]&1023)==OPStop) { + #ifdef debug + /*if((minor_integer_cache[minor_position]&1023)==OPStop) { return vec3(0.,0.,1.); } if((minor_integer_cache[minor_position]&1023)==OPSDFSphere) { return vec3(1.,0.,0.); + }*/ + /*if((minor_integer_cache[minor_position] & (1 << (15 - 1))) > 0) { + return vec3(1.,0.,0.); } - return vec3(0.,1.,0.); - #endif*/ + if((minor_integer_cache[minor_position] & (1 << (15 - 0))) > 0) { + return vec3(0.,0.,1.); + }*/ + //return vec3(0.,1.,0.); + return vec3(desc.floats,desc.scene,DescriptionIndex); + #endif switch(minor_integer_cache[minor_position]&1023) { @@ -1552,6 +1562,7 @@ float[2]scene(vec3 p[2], bool prune) inputmask2(float_const_head,float_const_head); float[2]in1=pull_float(ifconst(0)); float[2]in2=pull_float(ifconst(1)); + if (prune) { if (in1[1] < in2[0]) { prunesome(OPPos,bool[6](false,true,false,false,false,false)); @@ -1560,7 +1571,7 @@ float[2]scene(vec3 p[2], bool prune) { prunesome(OPPos,bool[6](true,false,false,false,false,false)); passthroughself(OPPos); - } + }} float[2]temp; minimum; push_float(in1); @@ -1571,6 +1582,7 @@ float[2]scene(vec3 p[2], bool prune) inputmask2(float_const_head,float_const_head); float[2]in1=pull_float(ifconst(0)); float[2]in2=pull_float(ifconst(1)); + if (prune) { if (in1[0] > in2[1]) { prunesome(OPPos,bool[6](false,true,false,false,false,false)); @@ -1579,7 +1591,7 @@ float[2]scene(vec3 p[2], bool prune) { prunesome(OPPos,bool[6](true,false,false,false,false,false)); passthroughself(OPPos); - } + }} float[2]temp; maximum; push_float(in1); @@ -3072,9 +3084,13 @@ float[2]scene(vec3 p[2], bool prune) { inputmask2(float_const_head,vec3_const_head); float[2] in2=pull_float(ifconst(0)); - /*#ifdef debug - return vec3(in2[0],in2[1],0.); - #endif*/ + #ifdef debug + if (in2[0] == in2[1] && in2[0] == 0.2) + {return vec3(in2[0],in2[1],0.); + }else{ + return vec3(in2[0],in2[1],1.); + } + #endif vec3[2] in1=pull_vec3(ifconst(1)); /*#ifdef debug return in1[0]; @@ -3096,6 +3112,7 @@ float[2]scene(vec3 p[2], bool prune) case OPNop: break; case OPStop: + if (prune) pruneall(uint8_t((major_position<<3)|minor_position)); #ifdef debug return vec3(pull_float(ifconst(0))[0]); @@ -3118,6 +3135,7 @@ float[2]scene(vec3 p[2], bool prune) major_position++; if(major_position==masklen) { + if (prune) pruneall(uint8_t((masklen*8))); #ifdef debug return vec3(pull_float(false)[0]); diff --git a/src/main.rs b/src/main.rs index 5218fb5336252a27d0948ef0546089200dc54d24..f09a56f63d1d1c9098a3017b597481692b393907 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,8 @@ use cgmath::{ Deg, EuclideanSpace, Euler, Matrix2, Matrix3, Matrix4, Point3, Rad, SquareMatrix, Vector2, Vector3, Vector4, }; +use instruction_set::InputTypes; +use vulkano::command_buffer::{CopyBufferInfo, PrimaryCommandBufferAbstract}; use std::io::Cursor; use std::{sync::Arc, time::Instant}; use vulkano::buffer::allocator::{SubbufferAllocator, SubbufferAllocatorCreateInfo}; @@ -10,7 +12,7 @@ use vulkano::buffer::{Buffer, BufferAllocateInfo, Subbuffer}; use vulkano::command_buffer::allocator::StandardCommandBufferAllocator; use vulkano::descriptor_set::allocator::StandardDescriptorSetAllocator; use vulkano::descriptor_set::{PersistentDescriptorSet, WriteDescriptorSet}; -use vulkano::device::{DeviceOwned, Features, QueueFlags}; +use vulkano::device::{DeviceOwned, Features, QueueFlags, Queue}; use vulkano::format::Format; use vulkano::half::f16; use vulkano::image::view::ImageViewCreateInfo; @@ -105,7 +107,7 @@ fn main() { ..DeviceExtensions::empty() }; - let (physical_device, queue_family_index) = instance + let (physical_device, (queue_family_index, transfer_index)) = instance .enumerate_physical_devices() .unwrap() .filter(|p| p.supported_extensions().contains(&device_extensions)) @@ -116,8 +118,21 @@ fn main() { .position(|(i, q)| { q.queue_flags.intersects(QueueFlags::GRAPHICS) && p.surface_support(i as u32, &surface).unwrap_or(false) - }) - .map(|i| (p, i as u32)) + }).and_then( | graphics| { + p.queue_family_properties() + .iter() + .enumerate() + .position(|(i, q)| { + q.queue_flags.intersects(QueueFlags::TRANSFER) && i != graphics + }).or_else( || { + p.queue_family_properties() + .iter() + .enumerate() + .position(|(i, q)| { + q.queue_flags.intersects(QueueFlags::TRANSFER) + })} + + ).map(|i| (graphics as u32, i as u32))}).map(|i| (p, i)) }) .min_by_key(|(p, _)| { // We assign a lower score to device types that are likely to be faster/better. @@ -146,6 +161,10 @@ fn main() { queue_create_infos: vec![QueueCreateInfo { queue_family_index, ..Default::default() + }, + QueueCreateInfo { + queue_family_index: transfer_index, + ..Default::default() }], enabled_features: Features { mesh_shader: true, @@ -165,6 +184,7 @@ fn main() { .expect("Unable to initialize device"); let queue = queues.next().expect("Unable to retrieve queues"); + let transfer_queue = queues.next().expect("Unable to retrieve queues"); let (mut swapchain, images) = { let surface_capabilities = device @@ -251,6 +271,20 @@ fn main() { } } + mod implicit_ts { + vulkano_shaders::shader! { + ty: "task", + path: "src/implicit.task.glsl", + types_meta: { + use bytemuck::{Pod, Zeroable}; + + #[derive(Clone, Copy, Zeroable, Pod, Debug)] + }, + vulkan_version: "1.2", + spirv_version: "1.5" + } + } + mod implicit_fs { vulkano_shaders::shader! { ty: "fragment", @@ -295,6 +329,13 @@ fn main() { ::std::sync::Arc<::vulkano::shader::ShaderModule>, ::vulkano::shader::ShaderCreationError, >), + ((implicit_ts::load) + as fn( + ::std::sync::Arc<::vulkano::device::Device>, + ) -> Result< + ::std::sync::Arc<::vulkano::shader::ShaderModule>, + ::vulkano::shader::ShaderCreationError, + >), ((implicit_fs::load) as fn( ::std::sync::Arc<::vulkano::device::Device>, @@ -313,7 +354,8 @@ fn main() { let mesh_fs = pariter[1].clone(); let implicit_ms = pariter[2].clone(); - let implicit_fs = pariter[3].clone(); + let implicit_ts = pariter[3].clone(); + let implicit_fs = pariter[4].clone(); drop(pariter); @@ -367,6 +409,7 @@ fn main() { &mesh_vs, &mesh_fs, &implicit_ms, + &implicit_ts, &implicit_fs, &images, render_pass.clone(), @@ -448,7 +491,7 @@ fn main() { .lights .push(Light::new([-4., 6., -8.], [8., 4., 1.], 0.05)); - let fragment_masks_buffer = object_size_dependent_setup(&memory_allocator, &gstate); + let subbuffers = object_size_dependent_setup(memory_allocator.clone(), &gstate, &command_buffer_allocator, transfer_queue.clone()); let mut render_start = Instant::now(); @@ -547,6 +590,7 @@ fn main() { &mesh_vs, &mesh_fs, &implicit_ms, + &implicit_ts, &implicit_fs, &new_images, render_pass.clone(), @@ -652,125 +696,6 @@ fn main() { sub }; - let mut data = [[0u32; 4]; 29]; - - let parts = vec![ - //CSGPart::opcode(InstructionSet::OPDupVec3, 0b000000), - //CSGPart::opcode(InstructionSet::OPSubVec3Vec3, 0b010000), - CSGPart::opcode(InstructionSet::OPSDFSphere, 0b100000), - //CSGPart::opcode(InstructionSet::OPAddVec3Vec3, 0b010000), - //CSGPart::opcode(InstructionSet::OPSDFSphere, 0b100000), - //CSGPart::opcode(InstructionSet::OPSmoothMinFloat, 0b000000), - CSGPart::opcode(InstructionSet::OPStop, 0b000000), - ]; - - let dependencies: Vec<[u8; 2]> = vec![[1, 255], [255, 255]]; - - let floats: Vec<f32> = vec![0.2, 0.2, 0.05]; - - let vec2s: Vec<[f32; 2]> = vec![[0.; 2]]; - - let vec3s: Vec<[f32; 3]> = vec![[0., 0.2, 0.], [0., 0.2, 0.]]; - - let vec4s: Vec<[f32; 4]> = vec![[0.; 4]]; - - let mat2s: Vec<[f32; 4]> = vec![[0.; 4]]; - - let mat3s: Vec<[f32; 9]> = vec![[0.; 9]]; - - let mat4s: Vec<[f32; 16]> = vec![[0.; 16]]; - - let mats: Vec<[f32; 16]> = vec![[0.; 16]]; - - let mut lower = true; - let mut minor = 0; - let mut major = 0; - - for part in parts { - data[major][minor] |= (part.code as u32) << (if lower { 0 } else { 16 }); - - lower = !lower; - if lower { - minor += 1; - if minor == 4 { - minor = 0; - major += 1; - if major == 29 { - panic!("CSGParts Too full!"); - } - } - } - } - - //println!("data: {:?}, {:?}", data[0][0], data[0][1]); - let desc = implicit_fs::ty::Description { - scene: 0, - floats: 0, - vec2s: 0, - vec3s: 0, - vec4s: 0, - mat2s: 0, - mat3s: 0, - mat4s: 0, - dependencies: 0, - }; - - let descvec = vec![desc]; - - fn new_desc( - input: &[implicit_fs::ty::Description], - ) -> &implicit_fs::ty::SceneDescription { - unsafe { ::std::mem::transmute(input) } - } - - let csg_object = uniform_buffer - .allocate_slice((descvec.len() as u64).max(1)) - .unwrap(); - csg_object.write().unwrap().copy_from_slice(&descvec[..]); - let csg_opcodes = uniform_buffer - .allocate_slice((data.len() as u64).max(1)) - .unwrap(); - csg_opcodes.write().unwrap().copy_from_slice(&data[..]); - let csg_floats = uniform_buffer - .allocate_slice((floats.len() as u64).max(1)) - .unwrap(); - csg_floats.write().unwrap().copy_from_slice(&floats[..]); - let csg_vec2s = uniform_buffer - .allocate_slice((vec2s.len() as u64).max(1)) - .unwrap(); - csg_vec2s.write().unwrap().copy_from_slice(&vec2s[..]); - let csg_vec3s = uniform_buffer - .allocate_slice((vec3s.len() as u64).max(1)) - .unwrap(); - csg_vec3s.write().unwrap().copy_from_slice(&vec3s[..]); - let csg_vec4s = uniform_buffer - .allocate_slice((vec4s.len() as u64).max(1)) - .unwrap(); - csg_vec4s.write().unwrap().copy_from_slice(&vec4s[..]); - let csg_mat2s = uniform_buffer - .allocate_slice((mat2s.len() as u64).max(1)) - .unwrap(); - csg_mat2s.write().unwrap().copy_from_slice(&mat2s[..]); - let csg_mat3s = uniform_buffer - .allocate_slice((mat3s.len() as u64).max(1)) - .unwrap(); - csg_mat3s.write().unwrap().copy_from_slice(&mat3s[..]); - let csg_mat4s = uniform_buffer - .allocate_slice((mat4s.len() as u64).max(1)) - .unwrap(); - csg_mat4s.write().unwrap().copy_from_slice(&mat4s[..]); - let csg_mats = uniform_buffer - .allocate_slice((mats.len() as u64).max(1)) - .unwrap(); - csg_mats.write().unwrap().copy_from_slice(&mats[..]); - let csg_depends = uniform_buffer - .allocate_slice((dependencies.len() as u64).max(1)) - .unwrap(); - csg_depends - .write() - .unwrap() - .copy_from_slice(&dependencies[..]); - let mesh_layout = mesh_pipeline.layout().set_layouts().get(0).unwrap(); let mesh_set = PersistentDescriptorSet::new( &descriptor_set_allocator, @@ -789,18 +714,18 @@ fn main() { [ WriteDescriptorSet::buffer(0, uniform_buffer_subbuffer.clone()), WriteDescriptorSet::buffer(1, cam_set.clone()), - WriteDescriptorSet::buffer(2, csg_object.clone()), - WriteDescriptorSet::buffer(3, csg_opcodes.clone()), - WriteDescriptorSet::buffer(4, csg_floats.clone()), - WriteDescriptorSet::buffer(5, csg_vec2s.clone()), - WriteDescriptorSet::buffer(6, csg_vec3s.clone()), - WriteDescriptorSet::buffer(7, csg_vec4s.clone()), - //WriteDescriptorSet::buffer(8, csg_mat2s.clone()), - //WriteDescriptorSet::buffer(9, csg_mat3s.clone()), - //WriteDescriptorSet::buffer(10, csg_mat4s.clone()), - //WriteDescriptorSet::buffer(11, csg_mats.clone()), - WriteDescriptorSet::buffer(12, csg_depends.clone()), - WriteDescriptorSet::buffer(20, fragment_masks_buffer.clone()), + WriteDescriptorSet::buffer(2, subbuffers.desc.clone()), + WriteDescriptorSet::buffer(3, subbuffers.scene.clone()), + WriteDescriptorSet::buffer(4, subbuffers.floats.clone()), + WriteDescriptorSet::buffer(5, subbuffers.vec2s.clone()), + WriteDescriptorSet::buffer(6, subbuffers.vec3s.clone()), + WriteDescriptorSet::buffer(7, subbuffers.vec4s.clone()), + //WriteDescriptorSet::buffer(8, subbuffers.mat2s.clone()), + //WriteDescriptorSet::buffer(9, subbuffers.mat3s.clone()), + //WriteDescriptorSet::buffer(10, subbuffers.mat4s.clone()), + //WriteDescriptorSet::buffer(11, subbuffers.mats.clone()), + WriteDescriptorSet::buffer(12, subbuffers.deps.clone()), + WriteDescriptorSet::buffer(20, subbuffers.masks.clone()), ], ) .unwrap(); @@ -944,6 +869,7 @@ fn window_size_dependent_setup<Mms>( mesh_vs: &ShaderModule, mesh_fs: &ShaderModule, implicit_ms: &ShaderModule, + implicit_ts: &ShaderModule, implicit_fs: &ShaderModule, images: &[Arc<SwapchainImage>], render_pass: Arc<RenderPass>, @@ -1049,6 +975,7 @@ where }, ])) .fragment_shader(implicit_fs.entry_point("main").unwrap(), specs) + .task_shader(implicit_ts.entry_point("main").unwrap(), ()) .mesh_shader(implicit_ms.entry_point("main").unwrap(), ()) .depth_stencil_state(DepthStencilState::simple_depth_test()) .rasterization_state(RasterizationState { @@ -1072,20 +999,365 @@ where ([mesh_pipeline, implicit_pipeline], framebuffers) } -fn object_size_dependent_setup( +struct Subbuffers { + masks: Subbuffer<[[u8; 29]]>, + floats: Subbuffer<[f32]>, + vec2s: Subbuffer<[[f32; 2]]>, + vec3s: Subbuffer<[[f32; 3]]>, + vec4s: Subbuffer<[[f32; 4]]>, + mat2s: Subbuffer<[[[f32; 2]; 2]]>, + mat3s: Subbuffer<[[[f32; 3]; 3]]>, + mat4s: Subbuffer<[[[f32; 4]; 4]]>, + mats: Subbuffer<[[[f32; 4]; 4]]>, + scene: Subbuffer<[[u32; 4]]>, + deps: Subbuffer<[[u8; 2]]>, + desc: Subbuffer<[[u32; 10]]>, +} + +impl PartialEq<InputTypes> for Inputs { + fn eq(&self, other: &InputTypes) -> bool { + match self { + &Inputs::Variable => true, + &Inputs::Float(_) => *other == InputTypes::Float, + &Inputs::Vec2(_) => *other == InputTypes::Vec2, + &Inputs::Vec3(_) => *other == InputTypes::Vec3, + &Inputs::Vec4(_) => *other == InputTypes::Vec4, + &Inputs::Mat2(_) => *other == InputTypes::Mat2, + &Inputs::Mat3(_) => *other == InputTypes::Mat3, + &Inputs::Mat4(_) => *other == InputTypes::Mat4, + } + } +} + +fn gpu_buffer<T>( + input: Vec<T>, allocator: &StandardMemoryAllocator, + sub_allocator: &SubbufferAllocator, + command_allocator: &StandardCommandBufferAllocator, + transfer_queue: Arc<Queue>, +) -> Subbuffer<[T]> +where + T: bytemuck::Pod + Send + Sync +{ + let buffer = Buffer::new_slice( + allocator, + BufferAllocateInfo { + buffer_usage: BufferUsage::STORAGE_BUFFER | BufferUsage::TRANSFER_DST, + memory_usage: MemoryUsage::GpuOnly, + allocate_preference: MemoryAllocatePreference::AlwaysAllocate, + ..Default::default() + }, + (input.len()) as u64, + ) + .unwrap(); + + let staging = sub_allocator.allocate_slice(input.len() as u64).unwrap(); + staging.write().unwrap().copy_from_slice(&input[..]); + + let mut builder = AutoCommandBufferBuilder::primary( + command_allocator, + transfer_queue.queue_family_index(), + CommandBufferUsage::OneTimeSubmit, + ) + .unwrap(); + builder.copy_buffer(CopyBufferInfo::buffers( + staging, + buffer.clone()) + ).unwrap(); + let commands = builder.build().unwrap(); + + commands.execute(transfer_queue.clone()) + .unwrap() + .then_signal_fence_and_flush() + .unwrap() + .wait(None) + .unwrap(); + + buffer +} + +fn object_size_dependent_setup( + allocator: Arc<StandardMemoryAllocator>, state: &GState, -) -> Subbuffer<[[u8; 29]]> { + command_allocator: &StandardCommandBufferAllocator, + queue: Arc<Queue>, +) -> Subbuffers { + let mut floats: Vec<f32> = vec![Default::default()]; + let mut vec2s: Vec<[f32; 2]> = vec![Default::default()]; + let mut vec3s: Vec<[f32; 3]> = vec![Default::default()]; + let mut vec4s: Vec<[f32; 4]> = vec![Default::default()]; + let mut mat2s: Vec<[[f32; 2]; 2]> = vec![Default::default()]; + let mut mat3s: Vec<[[f32; 3]; 3]> = vec![Default::default()]; + let mut mat4s: Vec<[[f32; 4]; 4]> = vec![Default::default()]; + let mut mats: Vec<[[f32; 4]; 4]> = vec![Default::default()]; + let mut scene: Vec<[u32; 4]> = vec![Default::default()]; + let mut deps: Vec<[u8; 2]> = vec![Default::default()]; + let mut desc: Vec<[u32; 10]> = vec![Default::default()]; + + 'nextcsg: for csg in &state.csg { + let mut data: Vec<[u32; 4]> = vec![]; + + let to_push = [ + scene.len() as u32, + floats.len() as u32, + vec2s.len() as u32, + vec3s.len() as u32, + vec4s.len() as u32, + mat2s.len() as u32, + mat3s.len() as u32, + mat4s.len() as u32, + mats.len() as u32, + deps.len() as u32, + ]; + + let parts = vec![ + //CSGPart::opcode(InstructionSet::OPDupVec3, vec![Inputs::Variable]), + //CSGPart::opcode(InstructionSet::OPSubVec3Vec3, vec![Inputs::Variable, Inputs::Vec3([0., 0.2, 0.].into())]), + CSGPart::opcode( + InstructionSet::OPSDFSphere, + vec![Inputs::Float(1.0), Inputs::Variable], + ), + //CSGPart::opcode(InstructionSet::OPAddVec3Vec3, 0b010000), + //CSGPart::opcode(InstructionSet::OPSDFSphere, 0b100000), + //CSGPart::opcode(InstructionSet::OPSmoothMinFloat, 0b000000), + CSGPart::opcode(InstructionSet::OPStop, vec![Inputs::Variable]), + ]; + + let mut dependencies: Vec<[u8; 2]> = vec![]; + for _ in 0..parts.len() { + dependencies.push([u8::MAX, u8::MAX]); + } + + let mut runtime_floats: Vec<usize> = vec![]; + let mut runtime_vec2s: Vec<usize> = vec![]; + let mut runtime_vec3s: Vec<usize> = vec![usize::MAX]; + let mut runtime_vec4s: Vec<usize> = vec![]; + let mut runtime_mat2s: Vec<usize> = vec![]; + let mut runtime_mat3s: Vec<usize> = vec![]; + let mut runtime_mat4s: Vec<usize> = vec![]; + + for (index, part) in parts.iter().enumerate() { + let inputs = part.opcode.input(); + for (expected, actual) in inputs.iter().zip(part.constants.iter()) { + if actual != expected { + eprintln!( + "csg {} is invalid ({:?} != {:?})", + csg.name, actual, expected + ); + continue 'nextcsg; + } + if actual == &Inputs::Variable { + match expected { + &InputTypes::Float => match runtime_floats.pop() { + Some(u) => { + if dependencies[u][0] != u8::MAX { + dependencies[u][1] = index as u8 + } else { + dependencies[u][0] = index as u8 + } + } + None => { + eprintln!("csg {} underflowed on floats", csg.name); + continue 'nextcsg; + } + }, + &InputTypes::Vec2 => match runtime_vec2s.pop() { + Some(u) => { + if dependencies[u][0] != u8::MAX { + dependencies[u][1] = index as u8 + } else { + dependencies[u][0] = index as u8 + } + } + None => { + eprintln!("csg {} underflowed on vec2s", csg.name); + continue 'nextcsg; + } + }, + &InputTypes::Vec3 => match runtime_vec3s.pop() { + Some(u) => { + if u != usize::MAX { + if dependencies[u][0] != u8::MAX { + dependencies[u][1] = index as u8 + } else { + dependencies[u][0] = index as u8 + } + } + } + None => { + eprintln!("csg {} underflowed on vec3s", csg.name); + continue 'nextcsg; + } + }, + &InputTypes::Vec4 => match runtime_vec4s.pop() { + Some(u) => { + if dependencies[u][0] != u8::MAX { + dependencies[u][1] = index as u8 + } else { + dependencies[u][0] = index as u8 + } + } + None => { + eprintln!("csg {} underflowed on vec4s", csg.name); + continue 'nextcsg; + } + }, + &InputTypes::Mat2 => match runtime_mat2s.pop() { + Some(u) => { + if dependencies[u][0] != u8::MAX { + dependencies[u][1] = index as u8 + } else { + dependencies[u][0] = index as u8 + } + } + None => { + eprintln!("csg {} underflowed on mat2s", csg.name); + continue 'nextcsg; + } + }, + &InputTypes::Mat3 => match runtime_mat3s.pop() { + Some(u) => { + if dependencies[u][0] != u8::MAX { + dependencies[u][1] = index as u8 + } else { + dependencies[u][0] = index as u8 + } + } + None => { + eprintln!("csg {} underflowed on mat3s", csg.name); + continue 'nextcsg; + } + }, + &InputTypes::Mat4 => match runtime_mat4s.pop() { + Some(u) => { + if dependencies[u][0] != u8::MAX { + dependencies[u][1] = index as u8 + } else { + dependencies[u][0] = index as u8 + } + } + None => { + eprintln!("csg {} underflowed on mat4s", csg.name); + continue 'nextcsg; + } + }, + } + } else { + match actual { + &Inputs::Float(f) => floats.push(f), + &Inputs::Vec2(f) => vec2s.push(f.into()), + &Inputs::Vec3(f) => vec3s.push(f.into()), + &Inputs::Vec4(f) => vec4s.push(f.into()), + &Inputs::Mat2(f) => mat2s.push(f.into()), + &Inputs::Mat3(f) => mat3s.push(f.into()), + &Inputs::Mat4(f) => mat4s.push(f.into()), + &Inputs::Variable => unreachable!(), + } + } + } + let outputs = part.opcode.output(); + for output in outputs { + match output { + InputTypes::Float => runtime_floats.push(index), + InputTypes::Vec2 => runtime_vec2s.push(index), + InputTypes::Vec3 => runtime_vec3s.push(index), + InputTypes::Vec4 => runtime_vec4s.push(index), + InputTypes::Mat2 => runtime_mat2s.push(index), + InputTypes::Mat3 => runtime_mat3s.push(index), + InputTypes::Mat4 => runtime_mat4s.push(index), + } + } + } + + let mut lower = true; + let mut minor = 0; + let mut major = 0; + + for part in parts { + if major == data.len() { + data.push([0; 4]); + } + data[major][minor] |= (part.code as u32) << (if lower { 0 } else { 16 }); + + lower = !lower; + if lower { + minor += 1; + if minor == 4 { + minor = 0; + major += 1; + if major == 29 { + panic!("CSGParts Too full!"); + } + } + } + } + + desc.push(to_push); + + scene.append(&mut data); + + deps.append(&mut dependencies); + + + } + + println!("floats: {:?}", floats); + println!("vec2s: {:?}", vec2s); + println!("vec3s: {:?}", vec3s); + println!("vec4s: {:?}", vec4s); + println!("mat2s: {:?}", mat2s); + println!("mat3s: {:?}", mat3s); + println!("mat4s: {:?}", mat4s); + println!("mats: {:?}", mats); + println!("scene: {:?}", scene); + println!("deps: {:?}", deps); + println!("desc: {:?}", desc); + let fragment_masks_buffer = Buffer::new_slice( - allocator.clone(), + &allocator, BufferAllocateInfo { buffer_usage: BufferUsage::STORAGE_BUFFER, memory_usage: MemoryUsage::GpuOnly, allocate_preference: MemoryAllocatePreference::AlwaysAllocate, ..Default::default() }, - (state.csg.len() * (4 * 4 * 4) * (3 * 3 * 3) * 29) as u64, + ((desc.len()-1) * (4 * 4 * 4) * (4 * 4 * 2) * 29) as u64, ) .unwrap(); - fragment_masks_buffer + + let staging = SubbufferAllocator::new( + allocator.clone(), + SubbufferAllocatorCreateInfo { + buffer_usage: BufferUsage::TRANSFER_SRC, + memory_usage: MemoryUsage::Upload, + ..Default::default() + }, + ); + + let csg_scene = gpu_buffer(scene, &allocator, &staging, command_allocator, queue.clone()); + let csg_desc = gpu_buffer(desc, &allocator, &staging, command_allocator, queue.clone()); + let csg_floats = gpu_buffer(floats, &allocator, &staging, command_allocator, queue.clone()); + let csg_vec2s = gpu_buffer(vec2s, &allocator, &staging, command_allocator, queue.clone()); + let csg_vec3s = gpu_buffer(vec3s, &allocator, &staging, command_allocator, queue.clone()); + let csg_vec4s = gpu_buffer(vec4s, &allocator, &staging, command_allocator, queue.clone()); + let csg_mat2s = gpu_buffer(mat2s, &allocator, &staging, command_allocator, queue.clone()); + let csg_mat3s = gpu_buffer(mat3s, &allocator, &staging, command_allocator, queue.clone()); + let csg_mat4s = gpu_buffer(mat4s, &allocator, &staging, command_allocator, queue.clone()); + let csg_mats = gpu_buffer(mats, &allocator, &staging, command_allocator, queue.clone()); + let csg_deps = gpu_buffer(deps, &allocator, &staging, command_allocator, queue.clone()); + + Subbuffers { + masks: fragment_masks_buffer, + floats: csg_floats, + vec2s: csg_vec2s, + vec3s: csg_vec3s, + vec4s: csg_vec4s, + mat2s: csg_mat2s, + mat3s: csg_mat3s, + mat4s: csg_mat4s, + mats: csg_mats, + scene: csg_scene, + deps: csg_deps, + desc: csg_desc, + } } diff --git a/src/objects.rs b/src/objects.rs index 744239b473e06ec8a156dd87f2a95fe59d9293ab..f50a700d1aa18157d598c00eb91e172784aeed30 100644 --- a/src/objects.rs +++ b/src/objects.rs @@ -1,11 +1,15 @@ use std::{ collections::HashMap, + default, io::{Cursor, Read}, mem, }; use bytemuck::{Pod, Zeroable}; -use cgmath::{Deg, EuclideanSpace, Euler, Matrix3, Point3, SquareMatrix, Vector3}; +use cgmath::{ + Deg, EuclideanSpace, Euler, Matrix2, Matrix3, Matrix4, Point3, SquareMatrix, Vector2, Vector3, + Vector4, +}; use obj::{LoadConfig, ObjData, ObjError}; use serde::{Deserialize, Serialize}; use vulkano::{ @@ -45,30 +49,63 @@ pub struct Mesh { #[derive(Debug)] pub struct CSG { pub name: String, - pub parts: Subbuffer<[CSGPart]>, + pub parts: Vec<CSGPart>, pub pos: Point3<f32>, pub rot: Euler<Deg<f32>>, pub scale: Vector3<f32>, } +#[derive(Clone, Debug, Default, PartialEq)] +pub enum Inputs { + #[default] + Variable, + Float(f32), + Vec2(Vector2<f32>), + Vec3(Vector3<f32>), + Vec4(Vector4<f32>), + Mat2(Matrix2<f32>), + Mat3(Matrix3<f32>), + Mat4(Matrix4<f32>), +} + #[repr(C)] -#[derive(Clone, Copy, Debug, Default, Zeroable, Pod, Vertex)] +#[derive(Clone, Debug)] pub struct CSGPart { - #[format(R16_SFLOAT)] pub code: u16, + pub opcode: InstructionSet, + pub constants: Vec<Inputs>, + pub material: Option<Matrix4<f32>>, } impl CSGPart { - pub fn opcode(opcode: InstructionSet, flags: u16) -> CSGPart { + pub fn opcode(opcode: InstructionSet, inputs: Vec<Inputs>) -> CSGPart { CSGPart { - code: (opcode as u16 & 1023) | flags << 10, + 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 fn literal(literal: f16) -> CSGPart { - CSGPart { - code: literal.to_bits(), - } + pub fn opcode_with_material( + opcode: InstructionSet, + inputs: Vec<Inputs>, + material: Matrix4<f32>, + ) -> CSGPart { + let mut c = CSGPart::opcode(opcode, inputs); + c.material = Some(material); + c } } @@ -326,7 +363,7 @@ pub fn load_csg( .iter() .map(|inpart| { let ty = inpart.get("type").ok_or("no type!")?.as_str(); - let mut csgpart = CSGPart::literal(0u8.into()); + let mut csgpart = CSGPart::opcode(InstructionSet::OPNop, vec![]); match ty { "sphere" => { let blend = get_f32(&inpart, "blend")?; @@ -342,18 +379,8 @@ pub fn load_csg( }) .collect::<Result<Vec<CSGPart>, String>>()?; - let parts_buffer = Buffer::from_iter( - memory_allocator, - BufferAllocateInfo { - buffer_usage: BufferUsage::VERTEX_BUFFER, - ..Default::default() - }, - parts, - ) - .unwrap(); - Ok(CSG { - parts: parts_buffer, + parts, pos: Point3 { x: 0., y: 0.,