Skip to content

Instantly share code, notes, and snippets.

View nanokatze's full-sized avatar

Constantine Shablia nanokatze

View GitHub Profile
@nanokatze
nanokatze / forward progress crimes.slang
Last active April 16, 2024 22:51
LZ4 decompressor for Vulkan written in Slang
typedef uint64_t size_t;
typedef uint64_t uintptr_t;
struct Queue<T> {
// pop side would really benefit from a lock tbh
uint32_t head;
uint32_t tail;
T buf[1];
};
/*
$ cc -O1 tsc_lol.c
$ ./a.out
1187.867 ms
11.879 ns per clock_gettime CLOCK_MONOTONIC
*/
#define _POSIX_C_SOURCE 199309L
#include <stdio.h>
#include <stdint.h>
typedef struct StringBuilder StringBuilder;
struct StringBuilder {
char *data;
size_t len;
size_t cap;
};
static void sbprintf(StringBuilder*, const char*, ...) __attribute__((format(printf, 2, 3)));
int

A good way to think about a buffer or an image descriptor is to imagine it as a very fat pointer. This is, in fact, not too far removed from reality, as we shall see.

Taking a peek at radv, we find the uniform buffer and storage buffer descriptors to be a 4-word tuple, where the first two words make up the address, followed by length in bytes for bounds checking and an extra word, which holds format information and bounds checking behavior [^1].

Similarly, the sampled image descriptor is a 16-word tuple containing an

vec4
qconj(vec4 x)
{
return vec4(-x.xyz, x.w);
}
vec4
qmul(vec4 x, vec4 y)
{
return vec4(
#define _POSIX_C_SOURCE 200809L
#include <stdatomic.h>
#include <stddef.h>
#include <stdio.h>
/*
#include <windows.h>
*/
#include <pthread.h>
#include <assert.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include "printf2.h"
size_t
vfprintf2(FILE *stream, const char *format, va_list ap)
{