convert the replacement modules to wesl
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
struct PackedAabb {
|
||||
min: vec3<f32>,
|
||||
max: vec3<f32>,
|
||||
}
|
||||
+20
-17
@@ -1,8 +1,7 @@
|
||||
import bevy_tape_load::render::aabb;
|
||||
import bevy_tape_load::render::metadata_types;
|
||||
import bevy_tape_load::render::implicit;
|
||||
|
||||
enable wgpu_binding_array;
|
||||
import package::aabb::PackedAabb;
|
||||
import package::metadata_types::TapeMetadata;
|
||||
import package::implicit::interval_scene;
|
||||
import package::NAN;
|
||||
|
||||
struct AabbBuffer {
|
||||
aabbs: array<PackedAabb>,
|
||||
@@ -26,7 +25,7 @@ struct InstanceTapeIds {
|
||||
@group(0) @binding(0)
|
||||
var<storage, read_write> aabb_buffers: binding_array<AabbBuffer>;
|
||||
@group(0) @binding(1)
|
||||
var<storage, read> tape_metadata_buffers: binding_array<TapeMetadataBuffer>;
|
||||
var<storage> tape_metadata_buffers: binding_array<TapeMetadataBuffer>;
|
||||
@group(0) @binding(2)
|
||||
var<storage> tape_ids: array<InstanceTapeIds>;
|
||||
|
||||
@@ -38,8 +37,6 @@ struct ComputeInput {
|
||||
@builtin(workgroup_id) workgroup_id: vec3u,
|
||||
}
|
||||
|
||||
const NAN: f32 = 0.0 / 0.0;
|
||||
|
||||
@compute @workgroup_size(8, 8, 8)
|
||||
fn enable_gen_entry(compute_input: ComputeInput) {
|
||||
let instance = tape_ids[push_constants.object_index];
|
||||
@@ -54,19 +51,25 @@ fn enable_gen_entry(compute_input: ComputeInput) {
|
||||
+ compute_input.global_invocation_id.x;
|
||||
|
||||
let internal_pos = vec3(
|
||||
((base_index >> (metadata.subdivision_log2 * 2))
|
||||
& ((1 << metadata.subdivision_log2) - 1)) / (1 << metadata.subdivision_log2),
|
||||
((base_index >> (metadata.subdivision_log2 * 1))
|
||||
& ((1 << metadata.subdivision_log2) - 1)) / (1 << metadata.subdivision_log2),
|
||||
((base_index >> (metadata.subdivision_log2 * 0))
|
||||
& ((1 << metadata.subdivision_log2) - 1)) / (1 << metadata.subdivision_log2),
|
||||
f32(
|
||||
(base_index >> (metadata.subdivision_log2 * 2))
|
||||
& u32((1 << metadata.subdivision_log2) - 1),
|
||||
) / f32(1 << metadata.subdivision_log2),
|
||||
f32(
|
||||
(base_index >> (metadata.subdivision_log2 * 1))
|
||||
& u32((1 << metadata.subdivision_log2) - 1),
|
||||
) / f32(1 << metadata.subdivision_log2),
|
||||
f32(
|
||||
(base_index >> (metadata.subdivision_log2 * 0))
|
||||
& u32((1 << metadata.subdivision_log2) - 1),
|
||||
) / f32(1 << metadata.subdivision_log2),
|
||||
);
|
||||
|
||||
let low_corner =
|
||||
(((vec3(0.0) / (1 << metadata.subdivision_log2)) + internal_pos) * metadata.dimensions)
|
||||
(((vec3(0.0f) / f32(1 << metadata.subdivision_log2)) + internal_pos) * metadata.dimensions)
|
||||
+ metadata.lowest_corner;
|
||||
let high_corner =
|
||||
(((vec3(1.0) / (1 << metadata.subdivision_log2)) + internal_pos) * metadata.dimensions)
|
||||
(((vec3(1.0f) / f32(1 << metadata.subdivision_log2)) + internal_pos) * metadata.dimensions)
|
||||
+ metadata.lowest_corner;
|
||||
|
||||
let interval = interval_scene(
|
||||
@@ -82,6 +85,6 @@ fn enable_gen_entry(compute_input: ComputeInput) {
|
||||
aabb.min = low_corner;
|
||||
aabb.max = high_corner;
|
||||
} else {
|
||||
aabb.min.x = NAN;
|
||||
aabb.min.x = NAN();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
fn scene(scene_input_one: vec4<f32>) -> f32 {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
fn interval_scene(
|
||||
interval_scene_input_one: vec4<f32>,
|
||||
interval_scene_input_two: vec4<f32>,
|
||||
) -> vec2<f32> {
|
||||
return vec2(0.0);
|
||||
}
|
||||
|
||||
fn gradient_scene(gradient_scene_input_one: vec4<f32>) -> vec4<f32> {
|
||||
return vec4(0.0);
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
#ifndef implicit_include
|
||||
#define implicit_include
|
||||
|
||||
#extension GL_GOOGLE_include_directive : require
|
||||
|
||||
float scene(vec4 scene_input_one) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
vec2 interval_scene(vec4 interval_scene_input_one, vec4 interval_scene_input_two) {
|
||||
return vec2(0.0);
|
||||
}
|
||||
|
||||
vec4 gradient_scene(vec4 gradient_scene_input_one) {
|
||||
return vec4(0.0);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,8 @@
|
||||
struct TapeMetadata {
|
||||
/// AABB for decompressing positions.
|
||||
lowest_corner: vec3<f32>,
|
||||
pad_a: u32,
|
||||
dimensions: vec3<f32>,
|
||||
pad_b: u32,
|
||||
subdivision_log2: u32,
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
enable wgpu_binding_array;
|
||||
|
||||
fn NAN() -> f32 {
|
||||
return bitcast<f32>(0xFFC00000u);
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
#version 460
|
||||
#extension GL_GOOGLE_include_directive : require
|
||||
#extension GL_EXT_buffer_reference : require
|
||||
#include "implicit_include.glsl"
|
||||
|
||||
struct PackedAabb {
|
||||
float min_x;
|
||||
float min_y;
|
||||
float min_z;
|
||||
float max_x;
|
||||
float max_y;
|
||||
float max_z;
|
||||
};
|
||||
|
||||
layout(std430, buffer_reference, buffer_reference_align = 8) writeonly buffer AabbBuffer {
|
||||
PackedAabb aabbs[];
|
||||
};
|
||||
|
||||
struct TapeMetadata {
|
||||
vec3 lowest_corner;
|
||||
uint pad_a;
|
||||
vec3 dimensions;
|
||||
uint pad_b;
|
||||
uint subdivision_log2;
|
||||
};
|
||||
|
||||
layout(std430, buffer_reference, buffer_reference_align = 8) readonly buffer TapeMetadataBuffer {
|
||||
TapeMetadata metadata[];
|
||||
};
|
||||
|
||||
struct InstanceTapeIds {
|
||||
uint aabb_buffer_id;
|
||||
uint aabb_buffer_offset;
|
||||
uint aabb_count;
|
||||
uint metadata_buffer_id;
|
||||
uint metadata_buffer_offset;
|
||||
};
|
||||
|
||||
layout(set = 0, binding = 0, std430) restrict readonly buffer AabbBufferArray {
|
||||
AabbBuffer buffers[];
|
||||
} aabb_buffers;
|
||||
layout(set = 0, binding = 1, std430) restrict readonly buffer TapeMetadataBufferArray {
|
||||
TapeMetadataBuffer buffers[];
|
||||
} tape_metadata_buffers;
|
||||
layout(set = 0, binding = 2, std430) restrict readonly buffer InstanceTapeIdsArray {
|
||||
InstanceTapeIds ids[];
|
||||
} tape_ids;
|
||||
|
||||
layout(push_constant, std430) uniform PushConstantData {
|
||||
uint object_index;
|
||||
float time;
|
||||
} pc;
|
||||
|
||||
layout(local_size_x = 8, local_size_y = 8, local_size_z = 8) in;
|
||||
|
||||
const float NAN = 0.0 / 0.0;
|
||||
|
||||
void main() {
|
||||
//if (SPEC_BRUTE_FORCE) {
|
||||
// return;
|
||||
//}
|
||||
|
||||
InstanceTapeIds instance = tape_ids.ids[pc.object_index];
|
||||
TapeMetadata metadata = tape_metadata_buffers.buffers[instance.metadata_buffer_id].metadata[instance.metadata_buffer_offset];
|
||||
AabbBuffer aabb_buffer = aabb_buffers.buffers[instance.aabb_buffer_id];
|
||||
|
||||
uvec3 total_invocations = gl_NumWorkGroups * gl_WorkGroupSize;
|
||||
uint base_index = (gl_GlobalInvocationID.z * total_invocations.x * total_invocations.y) +
|
||||
(gl_GlobalInvocationID.y * total_invocations.x) + gl_GlobalInvocationID.x;
|
||||
|
||||
vec3 internal_pos = vec3(
|
||||
float((base_index >> (metadata.subdivision_log2 * 2)) & ((1 << metadata.subdivision_log2) - 1))
|
||||
/ float(1 << metadata.subdivision_log2),
|
||||
float((base_index >> (metadata.subdivision_log2 * 1)) & ((1 << metadata.subdivision_log2) - 1))
|
||||
/ float(1 << metadata.subdivision_log2),
|
||||
float((base_index >> (metadata.subdivision_log2 * 0)) & ((1 << metadata.subdivision_log2) - 1))
|
||||
/ float(1 << metadata.subdivision_log2)
|
||||
);
|
||||
|
||||
vec3 low_corner = (((vec3(0.0) / float(1 << metadata.subdivision_log2)) + internal_pos)
|
||||
* metadata.dimensions) + metadata.lowest_corner;
|
||||
vec3 high_corner = (((vec3(1.0) / float(1 << metadata.subdivision_log2)) + internal_pos)
|
||||
* metadata.dimensions) + metadata.lowest_corner;
|
||||
|
||||
vec2 interval = interval_scene(
|
||||
vec4(low_corner, pc.time),
|
||||
vec4(high_corner, pc.time)
|
||||
);
|
||||
|
||||
bool enable = (interval.x < 0) && (interval.y > 0);
|
||||
|
||||
if (enable) {
|
||||
aabb_buffer.aabbs[instance.aabb_buffer_offset].min_x = low_corner.x;
|
||||
aabb_buffer.aabbs[instance.aabb_buffer_offset].min_y = low_corner.y;
|
||||
aabb_buffer.aabbs[instance.aabb_buffer_offset].min_z = low_corner.z;
|
||||
aabb_buffer.aabbs[instance.aabb_buffer_offset].max_x = high_corner.x;
|
||||
aabb_buffer.aabbs[instance.aabb_buffer_offset].max_y = high_corner.y;
|
||||
aabb_buffer.aabbs[instance.aabb_buffer_offset].max_z = high_corner.z;
|
||||
} else {
|
||||
aabb_buffer.aabbs[instance.aabb_buffer_offset].min_x = NAN;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user