Skip to content

Instantly share code, notes, and snippets.

@samloeschen
samloeschen / LinearArena.cs
Created August 8, 2025 18:33
an unsafe linear arena allocator for .net 8
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Generic = System.Collections.Generic;
public unsafe class LinearArena : IDisposable {
public byte* _buffer;
nint _offset;
nint _capacity;
nint _generation;
@samloeschen
samloeschen / objloader.zig
Created July 21, 2025 12:25
very basic obj loader in zig
const std = @import("std");
const math = @import("math.zig");
const ObjLineType = enum {
Vertex,
Normal,
Texcoord,
Face,
};
@samloeschen
samloeschen / deferred.wgsl
Created October 3, 2023 03:12
simple gbuffer shader in wgsl
@group(0) @binding(0) var gBufferNormal: texture_2d<f32>;
@group(0) @binding(1) var gBufferAlbedo: texture_2d<f32>;
@group(0) @binding(2) var gBufferDepth: texture_depth_2d;
struct LightData {
position : vec4<f32>,
color : vec3<f32>,
radius : f32,
}
@samloeschen
samloeschen / Arena.cs
Last active July 27, 2023 14:12
C# unmanaged arena allocator and collections for it
using System;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using Range = System.Range;
public unsafe struct Arena {
UnmanagedArray<Optional<Block>> _blocks;
int _currentBlockIndex;
@samloeschen
samloeschen / main.odin
Last active March 23, 2023 21:12
odin M1 alignment error repro
package main
import "core:fmt"
DangerStruct :: struct {
guid: u128,
value: u64,
}
SafeStruct1 :: struct {
@samloeschen
samloeschen / GlobalID.cs
Last active January 18, 2023 04:15
GlobalID
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine;
using Object = UnityEngine.Object;
// This is a System.Guid, except it can be serialized by Unity,
// so it can be used to permanently store the ID of an entity.
@samloeschen
samloeschen / main.odin
Created June 5, 2022 19:21
d3d11 hello triangle in odin
package main
import "core:fmt"
import "vendor:directx/d3d11"
import "vendor:directx/d3d_compiler"
import "vendor:directx/dxgi"
import SDL "vendor:sdl2"
import "core:unicode/utf16"
WINDOW_WIDTH : i32 = 1280
@samloeschen
samloeschen / main.rs
Created December 18, 2021 15:18
wgpu-hello-triangle
use std::borrow::Cow;
use winit::{
event::*,
event_loop::{ControlFlow, EventLoop},
window::Window,
};
struct AppState {
surface: wgpu::Surface,
device: wgpu::Device,
@samloeschen
samloeschen / Bezier.cs
Last active November 29, 2021 21:54
Bezier Length Estimation
using UnityEngine;
using Unity.Mathematics;
using static Unity.Mathematics.math;
[ExecuteInEditMode]
public class Bezier : MonoBehaviour {
public Vector3 a;
public Vector3 b;
public Vector3 c;
@samloeschen
samloeschen / MathematicsTests.cs
Last active March 4, 2021 01:40
Mathf vs Mathematics
using Unity.Mathematics;
using UnityEngine;
using System.Diagnostics;
public class MathematicsTests : MonoBehaviour {
const int NUM_TESTS = 1_000_000;
void Test() {
Matrix4x4 identityMatrix4x4 = Matrix4x4.identity;