--wip-- [skip ci]

This commit is contained in:
2025-07-08 23:20:20 +01:00
parent e4eb599744
commit 52cc5c7385
11 changed files with 2338 additions and 803 deletions
+8
View File
@@ -8,4 +8,12 @@ layout(set = 1, binding = 0) uniform Object {
uint material;
} object_uniforms;
float scene(vec4 p) {
return 0.0;
}
vec2 interval_scene(vec4 pl, vec4 ph) {
return vec2(0.0);
}
#endif
-4
View File
@@ -198,10 +198,6 @@ pub(crate) enum InstructionSet {
OPSmoothMaxMaterial = ((1 * 64) + 62),
#[allow(non_snake_case)]
#[allow(dead_code)]
/// Returns the cross product of two Vec3s.
OPCross = ((0 * 64) + 62),
#[allow(non_snake_case)]
#[allow(dead_code)]
/// Returns the distance to a sphere.
OPSDFSphere = ((3 * 64) + 61),
#[allow(non_snake_case)]
+2 -22
View File
@@ -20,6 +20,8 @@ pub const VALUE_05: Value = Value::splat(0.5);
pub const VALUE_M1: Value = Value::splat(-1.0);
pub const VALUE_2: Value = Value::splat(2.0);
pub const VALUE_PI: Value = Value::splat(core::f32::consts::PI);
pub const VALUE_PI_2: Value = Value::splat(core::f32::consts::FRAC_PI_2);
pub const VALUE_TAU: Value = Value::splat(core::f32::consts::TAU);
pub fn glsign(f: Value) -> Value {
if BYTECODE_IMITATES_GLSL {
@@ -159,17 +161,6 @@ impl<'csg> PointInterpreter<'csg> {
self.param_two(instruction, |val_a, val_b| val_a.simd_max(val_b));
},
SSAMaxMaterial => todo!(),
SSACross => {
let a_x = self.load(instruction.inputs[0]);
let a_y = self.load(instruction.inputs[1]);
let a_z = self.load(instruction.inputs[2]);
let b_x = self.load(instruction.inputs[3]);
let b_y = self.load(instruction.inputs[4]);
let b_z = self.load(instruction.inputs[5]);
self.store(instruction.outputs[0], (a_y * b_z) + (a_z * b_y));
self.store(instruction.outputs[1], (a_z * b_x) + (a_x * b_z));
self.store(instruction.outputs[2], (a_x * b_y) + (a_y * b_x));
},
SSADot => {
let val_a = (0..instruction.opcode.size)
.map(|i| self.load(instruction.inputs[i as usize]))
@@ -536,17 +527,6 @@ impl<'csg> IntervalInterpreter<'csg> {
self.param_two(instruction, |val_a, val_b| val_a.max_choice(val_b).0);
},
SSAMaxMaterial => todo!(),
SSACross => {
let a_x = self.load(instruction.inputs[0]);
let a_y = self.load(instruction.inputs[1]);
let a_z = self.load(instruction.inputs[2]);
let b_x = self.load(instruction.inputs[3]);
let b_y = self.load(instruction.inputs[4]);
let b_z = self.load(instruction.inputs[5]);
self.store(instruction.outputs[0], (a_y * b_z) + (a_z * b_y));
self.store(instruction.outputs[1], (a_z * b_x) + (a_x * b_z));
self.store(instruction.outputs[2], (a_x * b_y) + (a_y * b_x));
},
SSADot => {
let val_a = (0..instruction.opcode.size)
.map(|i| self.load(instruction.inputs[i as usize]))
-7
View File
@@ -13,13 +13,6 @@ layout(location = 0) out vec4 f_color;
vec3 calculate_view_position(float depth)
{
vec4 view_position = camera_uniforms.inv_proj_view * vec4(v_pos, depth, 1.0);
//vec4 view_position = vec4(
// fma(camera_uniforms.inv_proj_view[0][0], v_pos.x, camera_uniforms.inv_proj_view[3][0]),
// fma(camera_uniforms.inv_proj_view[1][1], v_pos.y, camera_uniforms.inv_proj_view[3][1]),
// fma(camera_uniforms.inv_proj_view[2][2], depth, camera_uniforms.inv_proj_view[3][2]),
// fma(camera_uniforms.inv_proj_view[2][3], depth, camera_uniforms.inv_proj_view[3][3])
// );
return (view_position.xyz / view_position.w);
}
+45 -5
View File
@@ -43,7 +43,7 @@ use vulkano::{
Device, DeviceCreateInfo, DeviceExtensions, DeviceFeatures, DeviceOwned, Queue,
QueueCreateInfo, QueueFlags, physical::PhysicalDeviceType,
},
format::{ClearValue, Format},
format::{ClearValue, Format, FormatFeatures},
image::{
Image, ImageAspects, ImageCreateInfo, ImageSubresourceRange, ImageType, ImageUsage,
SampleCount,
@@ -186,6 +186,7 @@ const CUBE_VERTEX: [IVertex; VERTEX_COUNT] = [
struct App {
instance: Arc<Instance>,
device: Arc<Device>,
depth_format: Format,
graphics_queue: Arc<Queue>,
transfer_queue: Arc<Queue>,
memory_allocator: Arc<StandardMemoryAllocator>,
@@ -321,6 +322,33 @@ impl App {
physical_device.properties().device_type,
);
let depth_format = if physical_device
.format_properties(Format::D24_UNORM_S8_UINT)
.unwrap()
.optimal_tiling_features
.contains(FormatFeatures::DEPTH_STENCIL_ATTACHMENT)
{
Format::D24_UNORM_S8_UINT
} else if physical_device
.format_properties(Format::D16_UNORM_S8_UINT)
.unwrap()
.optimal_tiling_features
.contains(FormatFeatures::DEPTH_STENCIL_ATTACHMENT)
{
Format::D16_UNORM_S8_UINT
} else if physical_device
.format_properties(Format::D32_SFLOAT_S8_UINT)
.unwrap()
.optimal_tiling_features
.contains(FormatFeatures::DEPTH_STENCIL_ATTACHMENT)
{
Format::D32_SFLOAT_S8_UINT
} else {
panic!("Could not find suitable depth format!");
};
info!("Using depth format {:?}", depth_format);
let (device, mut queues) = Device::new(
physical_device,
DeviceCreateInfo {
@@ -448,6 +476,7 @@ impl App {
App {
instance,
device,
depth_format,
graphics_queue,
transfer_queue,
memory_allocator,
@@ -659,7 +688,7 @@ impl ApplicationHandler for App {
store_op: DontCare,
},
depth: {
format: Format::D24_UNORM_S8_UINT,
format: self.depth_format,
samples: 1,
load_op: Clear,
store_op: DontCare,
@@ -701,7 +730,12 @@ impl ApplicationHandler for App {
ao_r_m_buffer,
normal_buffer,
depth_buffer,
) = framebuffer_generation(&images, &render_pass, &self.memory_allocator);
) = framebuffer_generation(
&images,
&render_pass,
&self.memory_allocator,
self.depth_format,
);
let lighting_pipeline = pipeline_recompile(
&render_pass,
@@ -1301,7 +1335,12 @@ impl App {
rcx.ao_r_m_buffer,
rcx.normal_buffer,
rcx.depth_buffer,
) = framebuffer_generation(&new_images, &rcx.render_pass, &self.memory_allocator);
) = framebuffer_generation(
&new_images,
&rcx.render_pass,
&self.memory_allocator,
self.depth_format,
);
rcx.viewport.extent[0] = window_size.width as f32;
rcx.viewport.extent[1] = window_size.height as f32 * -1.;
@@ -1486,6 +1525,7 @@ fn framebuffer_generation(
images: &[Arc<Image>],
render_pass: &Arc<RenderPass>,
allocator: &Arc<StandardMemoryAllocator>,
depth_format: Format,
) -> (
Vec<Arc<Framebuffer>>,
Arc<ImageView>,
@@ -1498,7 +1538,7 @@ fn framebuffer_generation(
allocator.clone(),
ImageCreateInfo {
image_type: ImageType::Dim2d,
format: Format::D24_UNORM_S8_UINT,
format: depth_format,
extent: images[0].extent(),
usage: ImageUsage::DEPTH_STENCIL_ATTACHMENT
| ImageUsage::INPUT_ATTACHMENT
-11
View File
@@ -14,20 +14,9 @@ layout(location = 0) out vec4 f_color;
layout(location = 1) out vec4 f_normal;
layout(location = 2) out vec4 f_ao_r_m;
float scene(vec4 p) {
return length(p.xyz) - 1.0;
}
vec3 calculate_view_position(float depth)
{
vec4 view_position = camera_uniforms.inv_proj_view * vec4(v_pos, depth, 1.0);
//vec4 view_position = vec4(
// fma(camera_uniforms.inv_proj_view[0][0], v_pos.x, camera_uniforms.inv_proj_view[3][0]),
// fma(camera_uniforms.inv_proj_view[1][1], v_pos.y, camera_uniforms.inv_proj_view[3][1]),
// fma(camera_uniforms.inv_proj_view[2][2], depth, camera_uniforms.inv_proj_view[3][2]),
// fma(camera_uniforms.inv_proj_view[2][3], depth, camera_uniforms.inv_proj_view[3][3])
// );
return (view_position.xyz / view_position.w);
}
+2264 -709
View File
File diff suppressed because it is too large Load Diff
+4 -7
View File
@@ -174,11 +174,6 @@ pub fn thread_loop(recv: mpmc::Receiver<WorkItem>, send: mpsc::SyncSender<WorkCo
);
},
WorkItem::GetPushConstants(csg, time, frame_index, index) => {
let mut push_constants = PushConstantData {
world: Mat4::IDENTITY.to_cols_array_2d(),
inv_world: Mat4::IDENTITY.to_cols_array_2d(),
};
let csg = csg.read().unwrap();
let world = Mat4::from_translation(csg.pos * 0.01)
@@ -190,8 +185,10 @@ pub fn thread_loop(recv: mpmc::Receiver<WorkItem>, send: mpsc::SyncSender<WorkCo
)
* Mat4::from_scale(csg.scale * 2.0);
push_constants.world = world.to_cols_array_2d();
push_constants.inv_world = world.inverse().to_cols_array_2d();
let push_constants = PushConstantData {
world: world.to_cols_array_2d(),
inv_world: world.inverse().to_cols_array_2d(),
};
interval_check(&csg, index as u32 + 1, time, frame_index);
+1 -5
View File
@@ -11,10 +11,6 @@ layout(depth_greater) out float gl_FragDepth;
layout(location = 0) out uint material;
float scene(vec4 p) {
return length(p.xyz) - 1.0;
}
const float EPSILON = .001;
const uint MAX_STEPS = 50;
const float NEARPLANE = 0.;
@@ -26,7 +22,7 @@ vec2 spheretracing(vec3 ori, vec3 dir, out vec3 p) {
td.y = scene(vec4(p, camera_uniforms.campos_and_time.w)) * .98;
td.x += td.y;
p = fma(dir, vec3(td.x), ori);
for (int i = 0; i < MAX_STEPS && td.y > EPSILON && td.x < FARPLANE; i++) {
for (int i = 0; td.y > EPSILON && td.x < FARPLANE; i++) {
td.y = scene(vec4(p, camera_uniforms.campos_and_time.w)) * .98;
td.x += td.y;
p = fma(dir, vec3(td.x), ori);
+14 -33
View File
@@ -7,8 +7,8 @@ use std::simd::{
use crate::{
interpreter::{
Mask, VALUE_0, VALUE_1, VALUE_2, VALUE_05, VALUE_M1, VALUE_NAN, VALUE_PI, Value, glfract,
glsign,
Mask, VALUE_0, VALUE_1, VALUE_2, VALUE_05, VALUE_M1, VALUE_NAN, VALUE_PI, VALUE_PI_2,
VALUE_TAU, Value, glfract, glsign,
},
vm::choice::{Choice, VChoice},
};
@@ -40,6 +40,7 @@ impl Interval {
pub const NAN: Self = Self::const_splat(core::f32::NAN);
pub const ONE: Self = Self::const_splat(1.0);
pub const PI: Self = Self::const_splat(core::f32::consts::PI);
pub const PI_2: Self = Self::const_splat(core::f32::consts::FRAC_PI_2);
pub const ZERO: Self = Self::const_splat(0.0);
/// Builds a new interval
@@ -164,47 +165,27 @@ impl Interval {
/// Computes the sine of the interval
#[inline]
pub fn sin(self) -> Self {
let same_cycle = ((self.lower / VALUE_PI) + VALUE_05)
.floor()
.simd_eq(((self.upper / VALUE_PI) + VALUE_05).floor());
let up = (((self.upper / VALUE_PI) + VALUE_05).floor()) % (VALUE_2);
let whole_cycle = (((self.upper / VALUE_PI) + VALUE_05).floor()
- ((self.lower / VALUE_PI) + VALUE_05).floor())
.simd_gt(VALUE_1);
let temp0 = self.lower.sin();
let temp1 = self.upper.sin();
let lower = self.has_nan().select(
VALUE_NAN,
((!whole_cycle & (up.simd_eq(VALUE_1))) | same_cycle)
.select(temp0.simd_min(temp1), VALUE_M1),
);
let upper = self.has_nan().select(
VALUE_NAN,
((!whole_cycle & (up.simd_eq(VALUE_0))) | same_cycle)
.select(temp0.simd_max(temp1), VALUE_1),
);
Interval::new(lower, upper)
(self - Self::PI_2).cos()
}
/// Computes the cosine of the interval
#[inline]
pub fn cos(self) -> Self {
let same_cycle = (self.lower / VALUE_PI)
.floor()
.simd_eq((self.upper / VALUE_PI).floor());
let up = ((self.upper / VALUE_PI).floor()) % (VALUE_2);
let whole_cycle =
((self.upper / VALUE_PI).floor() - (self.lower / VALUE_PI).floor()).simd_gt(VALUE_1);
let lower_cycle = (self.lower / VALUE_PI).floor();
let upper_cycle = (self.upper / VALUE_PI).floor();
let same_cycle = lower_cycle.simd_eq(upper_cycle);
let cycle = upper_cycle % VALUE_2;
let within_one_cycle = (upper_cycle - lower_cycle).simd_eq(VALUE_1);
let temp0 = self.lower.cos();
let temp1 = self.upper.cos();
let lower = self.has_nan().select(
VALUE_NAN,
((!whole_cycle & (up.simd_eq(VALUE_0))) | same_cycle)
(same_cycle | (within_one_cycle & (cycle.simd_eq(VALUE_0))))
.select(temp0.simd_min(temp1), VALUE_M1),
);
let upper = self.has_nan().select(
VALUE_NAN,
((!whole_cycle & (up.simd_eq(VALUE_1))) | same_cycle)
(same_cycle | (within_one_cycle & (cycle.simd_eq(VALUE_1))))
.select(temp0.simd_max(temp1), VALUE_1),
);
Interval::new(lower, upper)
@@ -350,8 +331,8 @@ impl Interval {
);
(
Interval::new(
has_nan.select(VALUE_NAN, self.lower.simd_min(rhs.lower)),
has_nan.select(VALUE_NAN, self.upper.simd_min(rhs.upper)),
has_nan.select(VALUE_NAN, self.lower.simd_max(rhs.lower)),
has_nan.select(VALUE_NAN, self.upper.simd_max(rhs.upper)),
),
VChoice(choice),
)
@@ -629,7 +610,7 @@ impl std::ops::Rem<Interval> for Interval {
);
let upper = has_nan.select(
VALUE_NAN,
(other_constant & floors).select(self.upper % rhs.lower, rhs.upper.abs()),
(other_constant & floors).select(self.upper % rhs.lower, rhs.abs().upper),
);
Interval::new(lower, upper)