Skip to content

Instantly share code, notes, and snippets.

void assert_func(int cond, const char *msg) {
if (!cond) {
fprintf(stderr, "assert failed: %s\n", msg);
abort();
}
}
#define assert_helper(x, y, ...) assert_func(x, y)
#define assert(x, ...) assert_helper((x), ## __VA_ARGS__, #x)
@zeux
zeux / clang27.md
Last active January 27, 2024 11:45
How does clang 2.7 hold up in 2021?

A friend recently learned about Proebsting's law and mentioned it to me off hand. I knew about the law's existence but I never really asked myself - do I believe in it?

For people who aren't aware, Proebsting's law states:

Compiler Advances Double Computing Power Every 18 Years

Which is to say, if you upgrade your compiler every 18 years, you would expect on average your code to double in performance on the same hardware.

Let's C about this

Sizes

(html+js+wasm)

Non-emscripten: 19,964 bytes
Emscripten:     11,086 bytes
@simonrenger
simonrenger / memoy_managment_cpp_resource_list.md
Last active May 9, 2024 08:27
C++ Memory Management Resource List

State of Roblox graphics API across all platforms, with percentage deltas since EOY 2019. Updated December 27 2020.

Windows

API Share
Direct3D 11+ 89% (+4%)
Direct3D 10.1 7% (-2%)
Direct3D 10.0 3.5% (-1.5%)
Direct3D 9 0.5% (-0.5%)
@bkaradzic
bkaradzic / idl.md
Last active March 26, 2023 22:12
bgfx is switching to IDL to generate API

bgfx is switching to IDL to generate API

bgfx main API is using basic C++ that looks like C, but it's C++ enough that can't be used directly in C projects. C is important as it provides ability to bind API to other languages, and also as sanity check for API design.

Every time API changes manual process of process for adding/changing API for C99 bindings was changing header declarations of function and function type for interface virtual table (I'll use bgfx::createVertexBuffer function as an example):

/* ... bunch of funcs ... */

/**/
BGFX_C_API bgfx_vertex_buffer_handle_t bgfx_create_vertex_buffer(
@d7samurai
d7samurai / .readme.md
Last active May 20, 2024 15:08
Minimal D3D11

Minimal D3D11

Minimal D3D11 reference implementation: An uncluttered Direct3D 11 setup + basic rendering primer and API familiarizer. Complete, runnable Windows application contained in a single function and laid out in a linear, step-by-step fashion that should be easy to follow from the code alone. ~200 LOC. No modern C++, OOP or (other) obscuring cruft. View on YouTube

hollowcube

Also check out Minimal D3D11 pt2, reconfigured for instanced rendering and with a smaller, tighter, simplified overall code structure, or Minimal D3D11 pt3, with shadowmapping + showcasing a range of alternative setup and rendering techniques.

@evanw
evanw / 0_stackify.ts
Last active March 24, 2024 00:02
Example "stackify" algorithm for turning SSA into WASM
// This code demonstrates a simplified "stackification" algorithm to turn
// instructions in a basic block back into a tree. This is useful when
// generating WebAssembly code from assembly instructions in SSA form.
//
// It's the algorithm used by LLVM's WebAssembly backend, viewable here:
// https://github.com/llvm-mirror/llvm/blob/master/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp
type InsKind =
'Add' |
'LocalSet' |
@niklas-ourmachinery
niklas-ourmachinery / identifying-controls-in-an-imgui.md
Last active January 24, 2023 06:09
Identifying controls in an IMGUI

Identifying controls in an IMGUI

In an IMGUI we need a way to identify which control is active or hot. For example, when we press a key, which text box does the text go to.

Possible options:

  1. Sequential number (Unity)

Each control drawn gets a sequentially increasing number.