First attempt at a GPU runner
Currently failing with an error I don't understand: ``` wgpu error: Validation Error Caused by: In Device::create_shader_module, label = '...\image_binary.spv' Shader '...\image_binary.spv' parsing error: InvalidTypeWidth(1) ```
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
[package]
|
||||
name = "image-binary"
|
||||
version.workspace = true
|
||||
authors.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
repository.workspace = true
|
||||
|
||||
[dependencies]
|
||||
enkou-shaders = { path = "../../enkou-shaders" }
|
||||
glam.workspace = true
|
||||
spirv-std.workspace = true
|
||||
wgpu = { workspace = true, optional = true }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
@@ -0,0 +1,82 @@
|
||||
//! # Binary image
|
||||
#![cfg_attr(target_arch = "spirv", no_std)]
|
||||
use enkou_shaders::camera::Camera;
|
||||
use enkou_shaders::chaos_game::ChaosGame;
|
||||
use enkou_shaders::rng::xoshiro256starstar_from_seed;
|
||||
use enkou_shaders::transform::Transform;
|
||||
use enkou_shaders::variation::Variation;
|
||||
use glam::{UVec2, UVec4};
|
||||
use spirv_std::spirv;
|
||||
|
||||
#[cfg(feature = "wgpu")]
|
||||
pub use wgpu::*;
|
||||
|
||||
const IMAGE_QUALITY: f32 = 1.0;
|
||||
const ITERATIONS_FUSE: u32 = 20;
|
||||
|
||||
/// Sierpinski Gasket
|
||||
#[spirv(compute(entry_point_name = "main_image_binary", threads(1)))]
|
||||
pub fn main_image_binary(
|
||||
#[spirv(storage_buffer, descriptor_set = 0, binding = 0)] image_dimensions: &UVec2,
|
||||
#[spirv(storage_buffer, descriptor_set = 0, binding = 1)] transforms: &[Transform],
|
||||
#[spirv(storage_buffer, descriptor_set = 0, binding = 2)] weights: &[f32],
|
||||
#[spirv(storage_buffer, descriptor_set = 0, binding = 3)] variations: &[Variation],
|
||||
#[spirv(storage_buffer, descriptor_set = 0, binding = 4)] camera: &Camera,
|
||||
#[spirv(storage_buffer, descriptor_set = 0, binding = 5)] image_buffer: &mut [UVec4],
|
||||
) {
|
||||
// Initialize RNG and run the chaos game
|
||||
let mut rng = xoshiro256starstar_from_seed([4; 32]);
|
||||
let mut chaos_game = ChaosGame::new(&mut rng, transforms, weights, variations);
|
||||
|
||||
// Discard the first few iterations
|
||||
for _ in 0..ITERATIONS_FUSE {
|
||||
chaos_game.next().unwrap();
|
||||
}
|
||||
|
||||
// Plot the remaining points generated by the chaos game
|
||||
let iterations = (image_dimensions.as_vec2().element_product() * IMAGE_QUALITY) as u32;
|
||||
for _ in 0..iterations {
|
||||
let ifs_point = chaos_game.next().unwrap();
|
||||
let pixel_point = camera.transform_point_to_image(ifs_point);
|
||||
|
||||
if let Some(pixel_point) = pixel_point {
|
||||
let pixel_index = pixel_point.y * image_dimensions.x + pixel_point.x;
|
||||
image_buffer[pixel_index as usize] = UVec4::splat(255);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "wgpu")]
|
||||
pub mod wgpu {
|
||||
const fn bgle(binding: u32, read_only: bool) -> wgpu::BindGroupLayoutEntry {
|
||||
wgpu::BindGroupLayoutEntry {
|
||||
binding,
|
||||
visibility: wgpu::ShaderStages::COMPUTE,
|
||||
ty: wgpu::BindingType::Buffer {
|
||||
ty: wgpu::BufferBindingType::Storage { read_only },
|
||||
has_dynamic_offset: false,
|
||||
min_binding_size: None,
|
||||
},
|
||||
count: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub const BGLE_IMAGE_DIMENSIONS: wgpu::BindGroupLayoutEntry = bgle(0, true);
|
||||
pub const BGLE_TRANSFORMS: wgpu::BindGroupLayoutEntry = bgle(1, true);
|
||||
pub const BGLE_WEIGHTS: wgpu::BindGroupLayoutEntry = bgle(2, true);
|
||||
pub const BGLE_VARIATIONS: wgpu::BindGroupLayoutEntry = bgle(3, true);
|
||||
pub const BGLE_CAMERA: wgpu::BindGroupLayoutEntry = bgle(4, true);
|
||||
pub const BGLE_IMAGE_BUFFER: wgpu::BindGroupLayoutEntry = bgle(5, false);
|
||||
|
||||
pub const BIND_GROUP_IMAGE_BINARY: wgpu::BindGroupLayoutDescriptor = wgpu::BindGroupLayoutDescriptor {
|
||||
label: Some("main_image_binary"),
|
||||
entries: &[
|
||||
BGLE_IMAGE_DIMENSIONS,
|
||||
BGLE_TRANSFORMS,
|
||||
BGLE_WEIGHTS,
|
||||
BGLE_VARIATIONS,
|
||||
BGLE_CAMERA,
|
||||
BGLE_IMAGE_BUFFER,
|
||||
],
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user