Skip to content

Instantly share code, notes, and snippets.

View ncthbrt's full-sized avatar
🧶
Coding

Natalie Cuthbert ncthbrt

🧶
Coding
View GitHub Profile
alias main = ReduceBuffer with {
alias Op = SumBinaryOp<F32>;
const block_area: u32 = 4u;
const work_size: u32 = 18u;
const threads: u32 = 10u;
}::main;
struct Sum<N> {
sum: N::T
}
@ncthbrt
ncthbrt / StoneberryGenericReduction.re
Last active September 30, 2024 20:05
An example of a generic GPU reduction in WESL
// Module signature that simply exposes the single type T. Could perhaps later be sugared to elide the module in follow-up
// work
mod sig Type {
type T;
}
// Module signature that exposes a single constant `value`. Could perhaps later be sugared to elide the module in follow-up work
mod sig Const<Type: Type> {
const value: Type::T;
}
@ncthbrt
ncthbrt / particle_effect.wgsl
Last active August 29, 2024 11:40
Dream outcome
pub mod make_particle_effect<particle: particle_module<acc>, spawner: spawner_module<particle, acc>, acc: acceleration_structure_module, group_index: u32>: particle_effect {
use bevy_globals::time;
use bevy_hanabi::vfx_common::{
IndirectBuffer, ParticleGroup, RenderEffectMetadata, RenderGroupIndirect, SimParams,
seed, tau, pcg_hash, to_float01, frand, frand2, frand3, frand4,
rand_uniform_f, rand_uniform_vec2, rand_uniform_vec3, rand_uniform_vec4, proj
}
pub type Particle = particle::Particle;
struct ParticleBuffer {

Module System

New keyword mod allows declaration of a sub-module. This allows discovery of modules within a crate as well as providing a single entry point for processing preprocessor directives. Modules follow rust rules such that if a crate is called x which has a sub-module a, the canonical name for the module will be x::a. x::a is added to x's symbol scope. Additional keywords self, super, and crate allow users to refer to modules relative to the current module.

Future work

  • Allowing declaration of sub module code inline to the parent module
  • Rust macro that creates a set of shader modules embedded in the code based off of rust/cargo file resolution logic. These would also include the encased shader types in the rust code if no preprocessor directives would influence the result.
  • Allow modules in the same crate to mutually import symbols from one another. This will require parsing wgsl to generate the headers.
  • Later: Extension to the language to allow for definition of mo
@ncthbrt
ncthbrt / BadOutput.msl
Last active January 5, 2024 08:44
Weird behavioural differences between cli and c api?
#include <simd/simd.h>
using namespace metal;
struct FrameData
{
float4x4 projectionMatrix;
float4x4 projectionMatrixInv;
float4x4 viewMatrix;
float4x4 viewMatrixInv;
@ncthbrt
ncthbrt / SketchSystems.spec
Last active October 26, 2018 13:15
DeviceTracking
DeviceTracking
NotOnItinerary*
setItinerary -> OnItinerary
updateLocation -> NotOnItinerary
OnItinerary
clearItinerary -> NotOnItinerary
setItinerary -> OnItinerary
OnTime*
arrived at final destination -> NotOnItinerary
irrecoverably late -> FailedItinerary
@ncthbrt
ncthbrt / Easing.cs
Last active September 24, 2018 20:06 — forked from xanathar/Easing.cs
Robert Penner's easing equations for Unity
/**
* Easing
* Animates the value of a float property between two target values using
* Robert Penner's easing equations for interpolation over a specified Duration.
*
* Original Author: Darren David darren-code@lookorfeel.com
*
* Ported to be easily used in Unity by Marco Mastropaolo
*
* Credit/Thanks:
@ncthbrt
ncthbrt / .gitattributes
Last active October 12, 2018 08:43
GIT LFS setup
## Yaml Merge
*.anim merge=unityyamlmerge
*.asset merge=unityyamlmerge
*.controller merge=unityyamlmerge
*.mat merge=unityyamlmerge
*.meta merge=unityyamlmerge
*.physicsMaterial merge=unityyamlmerge
*.physicsMaterial2D merge=unityyamlmerge
*.prefab merge=unityyamlmerge
*.unity merge=unityyamlmerge
@ncthbrt
ncthbrt / dissolve.shader
Created June 20, 2018 15:23 — forked from benloong/UIDissolve.shader
Dissolve shader for Unity
Shader "Unlit/DissolveEffectShader"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_NoiseTex ("Texture", 2D) = "white" {}
[MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
_EdgeColour1 ("Edge colour 1", Color) = (1.0, 1.0, 1.0, 1.0)
_EdgeColour2 ("Edge colour 2", Color) = (1.0, 1.0, 1.0, 1.0)
_Level ("Dissolution level", Range (0.0, 1.0)) = 0.1
exception RouteDoesNotMatch
exception MalformedRouteString of string
exception MalformedQueryString of string
exception MalformedQueryParameter of string* string* exn
type 'ty path =
| End: unit path
| Constant: string* 'ty path -> 'ty path
| String: string* 'ty path -> (string* 'ty) path
| Int: string* 'ty path -> (int* 'ty) path