Skip to content

Instantly share code, notes, and snippets.

@RandyGaul
RandyGaul / htable.h
Last active May 24, 2024 13:03
Polymorphic C hash table macros
// Polymorphic hashtable API in C
//
// We get value semantics here for hset and hget (see comments below).
// An extra layer of indirection is internally used so we can sort {k,v} pairs, e.g. for priority queue.
// The main trick is the use of comma in C. Any statement in C takes on the value of the expression
// in the final comma, not any of the prior. We can use that to "return" a value in `hget` while running
// a few expressions beforehand. Since the user type is a pointer to a value we get polymorphism by
// the indirection or array operator `*h` or `h[0]`.
//
// Original inspired from these resources by Per Vognsen and Micha Mettke
@slembcke
slembcke / frame-timing.c
Last active June 18, 2023 19:05
Filter frame timing to try and remove scheduler jitter.
double delta_time_filtered(double dt_nanos){
// Warm start the filter by assuming 60 Hz.
static double x[] = {1.6e7, 1.6e7, 1.6e7}, y[] = {1.6e7, 1.6e7, 1.6e7};
// IIR filter coefficients. 2rd order lowpass butterworth at 1/128 the sample rate.
static const double b[] = {6.321391700454014e-5, 0.00012642783400908025, 6.321391700454014e-5};
static const double a[] = {1.0, -1.9681971279272976, 0.9684499835953156};
// Apply IIR filter coefficients.
double value = b[0]*dt_nanos;
for(uint i = 2; i > 0; i--){
@vurtun
vurtun / sort.c
Last active January 11, 2023 15:22
// ref: http://www.codercorner.com/RadixSortRevisited.htm
// http://stereopsis.com/radix.html
// int/float: https://github.com/lshamis/FloatRadixSort
// string: https://github.com/rantala/string-sorting/blob/master/src/msd_ce.cpp
struct str {
const char *str;
const char *end;
int len;
};
@kch86
kch86 / gist:e96a22ae97fd7c17a68d7a03c3c7ae87
Last active May 1, 2022 21:39
d3d11 debug layer and windows 10 graphics tool install
1. windows update
1a. Right click on the windows icon in the task bar, select Settings, select Apps, and then click Manage optional features.
1b. Click Add a feature
1c. In the Optional features list, select Graphics Tools and then click Install.
2. that doesn't work, here's the hail mary:
* Run regedit.exe
* Navigate to folder HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU\
* Double click on entry UseWUServer, change the value to 0, click OK
* Reboot
@mmozeiko
mmozeiko / shader.hlsl
Last active November 7, 2024 20:23
compute shader for rendering monospaced glyphs in grid
//
struct TerminalCell
{
// cell index into GlyphTexture, should be two 16-bit (x,y) values packed: "x | (y << 16)"
uint GlyphIndex;
// 0xAABBGGRR encoded colors, nonzero alpha for Foreground indicates to render colored-glyph
// which means use RGB values from GlyphTexture directly as output, not as ClearType blending weights
uint Foreground;
#include <TinyCRT/TinyCRT.h>
#include <TinyCRT/TinyWindows.h>
namespace
{
constexpr uint64_t time100NSecsPerSec = 10000000;
uint64_t FileTimeToU64(FILETIME ft)
{
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)

How do you descriptor set?

Descriptor sets have vexed me at every step of development. They're new and different and they have a lot of rules which aren't all that obvious. This document will hopefully lay out everything in one convenient place that I - and also you - can refer to

First, let's talk about what we're trying to do

Use Case

Most renderers need some way for shaders to access resources like textures, buffers, etc. For the Vulkan API, this way is the almighty descriptor set. Descriptors, as I understand them, are essentially a pointer to a resource. You update your descriptor sets with your resources, then you bind the descriptor sets to your command buffer, then shaders involved in subsequent drawcalls can look at the descriptors to know what resources they should actually read from. I'm not entirely sure why there's this indirection - and in fact, on AMD GPUs descriptor sets are actually just pointers - but the indirection exists, and we all have to find a way to deal with it

@raysan5
raysan5 / custom_game_engines_small_study.md
Last active November 19, 2024 15:34
A small state-of-the-art study on custom engines

CUSTOM GAME ENGINES: A Small Study

a_plague_tale

A couple of weeks ago I played (and finished) A Plague Tale, a game by Asobo Studio. I was really captivated by the game, not only by the beautiful graphics but also by the story and the locations in the game. I decided to investigate a bit about the game tech and I was surprised to see it was developed with a custom engine by a relatively small studio. I know there are some companies using custom engines but it's very difficult to find a detailed market study with that kind of information curated and updated. So this article.

Nowadays lots of companies choose engines like Unreal or Unity for their games (or that's what lot of people think) because d