changed 2 years ago
Published Linked with GitHub

Blade

gfx, luminance, vulkano, wgpu, rafx, sierra
Yet another graphics library?


Motivation

Case: Rusty Vangers


Motivation: GPU evolves

Lots workloads where CPU costs are small:

  • AZDO (term from late OpenGL)
  • compute/ML workloads
  • Ray Tracing

Why not wgpu/hal?

Constraints


Lean


State tracking

No per-object state. No image layout transitions.
Global barriers between passes.

if let mut pass_encoder = encoder.compute() {
    let mut pipeline_encoder = pass_encoder.with(pipeline);
    pipeline_encoder.dispatch(..);
}

State tracking: example

  1. Create a resource
  2. Use in a compute/render/transder pass
  3. Submit the command encoder.

Binding model

No layouts. No descriptor sets.
No uniform buffers, just plain data.


Binding model: define group

#[derive(bytemuck::Pod)]
struct MyUniformStruct {
    data: u32
}
#[derive(blade::ShaderData)]
struct Foo {
    texture: blade::TextureView,
    uniform: MyUniformStruct,
}

Binding model: pipeline creation

let foo_layout = <Foo as blade::ShaderData>::layout();
context.create_pipeline(blade::ComputePipelineDescriptor {
  data_layouts: &[&foo_layout],
});

Binding model: binding

pass.bind(0, &Foo {
    texture: my_texture_view,
    uniform: MyUniformStruct { // plain data
        data: 1,
    },
});

Binding model: thoughts

Makes prototyping a breeze!

Was BG/BGL/PL a design mistake in WebGPU?


Lean: code size

Disclaimer: Blade is much incomplete!


But is it fast?

Can do around 20K draw calls per frame on a low-end laptop.


Mean

  • Totally unsafe: use at your own risk.
  • No tools: ask your local GPU vendor.
  • Incomplete: customize for your needs.

Mean: shortcuts

Who needs vertex buffers, anyway?

One context - one window.


Mean: no contract

All libraries: we got you!
Blade: bring your own maintainer

See What it feels like to be an open-source maintainer


Ergonomics

Resource objects: light and copyable.

pub struct Buffer {
    raw: vk::Buffer,
    memory_handle: usize,
    mapped_data: *mut u8,
}

Context: Has everything, internally synchronized.


API: Shaders

Validated(*) WGSL modules.
Without resource binding decorations!

var sprite_texture: texture_2d<f32>;
var sprite_sampler: sampler;

TL;DR: why use Blade?


Why not use Blade?


Demo & Questions

https://github.com/kvark/blade

Select a repo