Skip to content

Instantly share code, notes, and snippets.

@cshenton
cshenton / d3d11_speedtest.c
Last active March 25, 2024 01:04
Seeing how fast a d3d11 swapchain can go.
#include <assert.h>
#include <stdio.h>
#include <time.h>
#define COBJMACROS
#include <windows.h>
#include <d3d11_1.h>
#include <d3dcompiler.h>
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
@cshenton
cshenton / d3d11_triangle.c
Last active March 7, 2024 21:33
D3D11 Triangle in C99
#include <assert.h>
#define COBJMACROS
#include <windows.h>
#include <d3d11_1.h>
#include <d3dcompiler.h>
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define TITLE "D3D11 Triangle C"
@cshenton
cshenton / block_allocator.odin
Last active March 25, 2024 00:45
Allocator based on Sebastian Aaltonen's Offset Allocator, for suballocating GPU heaps
package block_allocator
// Allocator based on Sebastian Aaltonen's Offset Allocator:
// https://github.com/sebbbi/OffsetAllocator/blob/main/offsetAllocator.cpp
import "core:fmt"
import "core:math/bits"
import "core:math/rand"
assert_allocator_layout_good :: proc(allocator: ^Block_Allocator) {
@cshenton
cshenton / client.c
Created August 8, 2021 10:45
Enet Simple Example
#include <stdio.h>
#define _WINSOCK_DEPRECATED_NO_WARNINGS
#define ENET_IMPLEMENTATION
#include "enet.h"
int main()
{
if (enet_initialize() != 0)
{
@cshenton
cshenton / array_info.zig
Last active December 23, 2019 05:08
arrayInfo programming
const std = @import("std");
const ArrayInfo = struct {
rank: usize,
child: type,
};
fn arrayInfo(comptime artype: type) ArrayInfo {
var rank: usize = 0;
var currentType: type = artype;
@cshenton
cshenton / ones_zeros.zig
Created December 19, 2019 05:03
Ones, Zeros in Zig
const expect = @import("std").testing.expect;
/// The additive identity for this scalar type.
inline fn zero(comptime T: type) T {
return 0;
}
/// The multiplicative identity for this scalar type.
inline fn one(comptime T: type) T {
return 1;
@cshenton
cshenton / vector_ternary_if.zig
Last active December 19, 2019 01:30
Zig Vector Ternary If
const assert = @import("std").debug.assert;
fn make_mask_3_f32(cond: [3]bool) [3]f32 {
var mask: [3]f32 = undefined;
const ar_cond: [3]bool = cond;
comptime var i = 0;
inline while (i < 3) : (i += 1) {
mask[i] = if (ar_cond[i]) 1.0 else 0.0;
}
package main
import (
"fmt"
"math/rand"
"time"
)
// This program starts numProcs goroutines which each generate numSteps random
// numbers and prints the amount of time it takes.
@cshenton
cshenton / woops.go
Last active September 4, 2018 14:59
// This program starts N goroutines which each generate numSteps random
// numbers and prints the amount of time it takes.
//
// See if you can you figure out why it doesn't parallelise properly.
package main
import (
"fmt"
"math/rand"
"time"
@cshenton
cshenton / latency.txt
Created March 27, 2018 12:09 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD