Skip to content

Instantly share code, notes, and snippets.

@raphlinus
raphlinus / pctl_kernel.metal
Created August 28, 2019 15:43
Per tile command list kernel cross-compiled to Metal
// Methodology: start with pctl_kernel.hlsl from https://github.com/bzm3r/piet-dx12
// Expand includes by hand.
// Use http://shader-playground.timjones.io/
// Use DXC compiler, cs_6_0 profile, set entry point, SPIRV out
// Chain spirv-cross, Metal out
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
@raphlinus
raphlinus / rust_winrt_thoughts.md
Last active November 6, 2019 21:35
Thoughts on why Rust/WinRT is so important

Kenny Kerr posted My Rust adventure begins this morning, and I tweeted "This seems like a pretty big deal - Rust is uniquely able to bridge the gap between performant systems programming and the safe, high level abstractions needed to build applications." This was a strong statement, and sparked a little discussion, so I'd like to clarify a bit.

The main controversy was about whether Rust is truly unique in this regard, or whether other languages can possibly satisfy the requirement of being a solid foundation for operating systems while also avoiding the pitfalls of C and C++. I argue that this role requires a language to be suitable for a very wide range of problem domains. Latency-critical applications such as pro audio are a fairly minor niche, and the vast majority of things people do at computers don't require that kind of low-level control, but if supporting, say, pro audio is one of the requirements

@raphlinus
raphlinus / decompose_var.py
Created December 7, 2019 20:01
Script to decompose components with mismatched 2x2 matrix
# Script to decompose components with mismatched 2x2 matrix
# See https://github.com/googlefonts/fontmake/issues/595
for glyph in Glyphs.font.glyphs:
#print glyph
xforms = []
mismatch = []
for (i, layer) in enumerate(glyph.layers):
for (j, component) in enumerate(layer.components):
if i == 0:
xforms.append(component.transform)
@raphlinus
raphlinus / scene-graph.md
Created December 27, 2019 15:09
very rough draft of scene graph description for piet-metal

Scene graph

enum Node {
    Group(Group),
    Fill(Fill),
    Stroke(Stroke),
    Clip(Clip),
}
@raphlinus
raphlinus / druidwinter2020.md
Created December 29, 2019 17:26
Winter status update & 0.5 Roadmap

Winter status update & 0.5 Roadmap

Goals & Non-goals

Development of druid is currently driven by the needs of [Runebender], a font editor, and this will continue to be true for the scope of this roadmap. Runebender is a creative desktop application, supporting Windows, macOS, and Linux (via Gtk).

A major goal for Runebender, and thus druid, is to offer a polished user experience. There are many factors to this goal, including performance, a rich palette of interactions (thus a widget library to support them), and playing well with the native platform.

This last point deserves more explanation. The intent of druid is not that you can write a single program that will magically look and feel native on all supported platforms. It's questionable whether such a thing can be done, and chasing it leads to a "lowest common denominator" approach. Rather, the goal of druid is to make it possible to create an app which respects platform conventions and expectations around things like window management, menus

@raphlinus
raphlinus / kubelka.rs
Created January 22, 2020 18:38
Code for testing Kubelka-Munk based compositing
use std::path::Path;
use std::fs::File;
use std::io::BufWriter;
#[derive(Clone, Copy)]
struct LinearRGB {
r: f32,
g: f32,
b: f32,
}
@raphlinus
raphlinus / gen.hlsl
Last active February 1, 2020 08:36
output of current piet-metal-derive on piet-dx12 scene
inline uint extract_8bit_value(uint bit_shift, uint package) {
uint mask = 255;
uint result = (package >> bit_shift) & mask;
return result;
}
inline uint extract_16bit_value(uint bit_shift, uint package) {
uint mask = 65535;
uint result = (package >> bit_shift) & mask;
@raphlinus
raphlinus / piet-gpu-fancy-kernel-1.metal
Last active February 8, 2020 20:19
Pseudocode of the fancy (subgroup) version of piet-gpu's kernel 1 (simplified)
struct StackElement {
PietGroupRef group;
uint index;
float2 offset; // Maybe pack as short2?
}
kernel1(Buf scene, PietGroupRef root) {
StackElement stack[MAX_STACK];
uint stack_ix = 0;
uint tos_group = root;
@raphlinus
raphlinus / bitmap_transpose.metal
Created February 8, 2020 21:11
32x32 matrix transpose in metal using subgroups
inline uint shuffle_round(uint a, uint m, ushort s) {
uint b = simd_shuffle_xor(a, s);
uint c;
if ((tix & s) == 0) {
c = b << s;
} else {
m = ~m;
c = b >> s;
}
return (a & m) | (c & ~m);
@raphlinus
raphlinus / piet-gpu-simple-kernel-1.metal
Created February 10, 2020 18:22
Non-subgroup version of graph traversal
struct StackElement {
PietGroupRef group;
uint index;
float2 offset; // Maybe pack as short2?
}
kernel1(Buf scene, PietGroupRef root) {
StackElement stack[MAX_STACK];
uint stack_ix = 0;
uint group = root;