This commit is contained in:
2026-10-07 20:42:38 +01:00
commit 13518decc0
7 changed files with 1699 additions and 0 deletions
+101
View File
@@ -0,0 +1,101 @@
fn main() {
env_logger::init();
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor::new_without_display_handle());
let adapter =
pollster::block_on(instance.request_adapter(&wgpu::RequestAdapterOptions::default()))
.expect("Failed to create adapter");
log::info!("Running on Adapter: {:#?}", adapter.get_info());
let downlevel_capabilities = adapter.get_downlevel_capabilities();
if !downlevel_capabilities
.flags
.contains(wgpu::DownlevelFlags::COMPUTE_SHADERS)
{
panic!("Adapter does not support compute shaders");
}
let (device, _) = pollster::block_on(adapter.request_device(&wgpu::DeviceDescriptor {
label: None,
required_features: wgpu::Features::BUFFER_BINDING_ARRAY
| wgpu::Features::TEXTURE_BINDING_ARRAY
| wgpu::Features::STORAGE_RESOURCE_BINDING_ARRAY
| wgpu::Features::SAMPLED_TEXTURE_AND_STORAGE_BUFFER_ARRAY_NON_UNIFORM_INDEXING
| wgpu::Features::STORAGE_TEXTURE_ARRAY_NON_UNIFORM_INDEXING
| wgpu::Features::PARTIALLY_BOUND_BINDING_ARRAY,
required_limits: wgpu::Limits::downlevel_defaults(),
experimental_features: wgpu::ExperimentalFeatures::disabled(),
memory_hints: wgpu::MemoryHints::MemoryUsage,
trace: wgpu::Trace::Off,
}))
.expect("Failed to create device");
log::info!("Creating WGSL module...");
let wgsl_module = device.create_shader_module(wgpu::include_wgsl!("shader.wgsl"));
log::logger().flush();
log::info!("Creating SPV module...");
let spv_module = device.create_shader_module(wgpu::include_spirv!("shader.spv"));
log::logger().flush();
let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
label: None,
entries: &[
wgpu::BindGroupLayoutEntry {
binding: 0,
visibility: wgpu::ShaderStages::COMPUTE,
ty: wgpu::BindingType::Buffer {
ty: wgpu::BufferBindingType::Storage { read_only: false },
min_binding_size: None,
has_dynamic_offset: false,
},
count: Some(core::num::NonZeroU32::new(500).unwrap()),
},
wgpu::BindGroupLayoutEntry {
binding: 1,
visibility: wgpu::ShaderStages::COMPUTE,
ty: wgpu::BindingType::Buffer {
ty: wgpu::BufferBindingType::Storage { read_only: true },
min_binding_size: None,
has_dynamic_offset: false,
},
count: Some(core::num::NonZeroU32::new(500).unwrap()),
},
],
});
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
label: None,
bind_group_layouts: &[Some(&bind_group_layout)],
immediate_size: 0,
});
log::info!("Creating WGSL pipeline...");
let wgsl_pipeline = device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
label: None,
layout: Some(&pipeline_layout),
module: &wgsl_module,
entry_point: Some("main"),
compilation_options: wgpu::PipelineCompilationOptions::default(),
cache: None,
});
log::logger().flush();
log::info!("Creating SPV module...");
let spv_pipeline = device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
label: None,
layout: Some(&pipeline_layout),
module: &spv_module,
entry_point: Some("main"),
compilation_options: wgpu::PipelineCompilationOptions::default(),
cache: None,
});
log::logger().flush();
log::info!("WGSL module: {wgsl_module:?}");
log::info!("SPV module: {spv_module:?}");
log::info!("WGSL pipeline: {wgsl_pipeline:?}");
log::info!("SPV pipeline: {spv_pipeline:?}");
}
+18
View File
@@ -0,0 +1,18 @@
enable wgpu_binding_array;
struct Thing {
pad_a: u32,
pad_b: u32,
}
struct ThingBuffer {
metadata: array<Thing>,
}
@group(0) @binding(0)
var<storage, read_write> thing_buffers_rw: binding_array<ThingBuffer>;
@group(0) @binding(1)
var<storage> thing_buffers_ro: binding_array<ThingBuffer>;
@compute @workgroup_size(8, 8, 8)
fn main() {}