Skip to content

Instantly share code, notes, and snippets.

View graphitemaster's full-sized avatar
🎩
Building my dream game

Dale Weiler graphitemaster

🎩
Building my dream game
View GitHub Profile
@graphitemaster
graphitemaster / nvbug.c
Last active July 16, 2017 02:11
nvbug work around data races atfork handlers
/* The following is an implementation of pthread_atfork that
* does absolutely nothing when nvidia is being used for rendering.
*
* This is needed because nvidia adds atfork handlers which are not
* async-signal safe and contain minor data-races which can lead to
* unexpected crashes.
*
* For example from valgrind's helgrind
*
* ==17309== Possible data race during write of size 1 at 0x3EEEC5E0 by thread #27
@graphitemaster
graphitemaster / NEWAUTO.md
Last active March 8, 2016 07:52
C++ "new auto" proposal

Proposal: "new auto"

Exibit:

class A {
    A();
    T *a;
};
@graphitemaster
graphitemaster / T0.md
Last active May 6, 2024 10:18
Vulkan Tutorial

Tutorial 0

What is Vulkan

Vulkan is a low-overhead, cross-platform 3D graphics and compute API.

Vulkan targets

Vulkan targets high-performance realtime 3D graphics applications such as games and interactive media across multiple platforms providing higher performance and lower CPU usage.

@graphitemaster
graphitemaster / WORKING_AROUND_OFFSETOF_LIMITATIONS.MD
Last active February 29, 2024 08:49
Working around offsetof limitations in C++

Working around offsetof limitations in C++:

There is sometimes a situation in which one needs to get the relative offset of a structure field, common examples of this include serialization frameworks which aid to serialize objects, vertex attributes for rendering (D3D, GL.), etc.

The most common technique for getting this information is through the offsetof macro defined in stddef.h. Unfortunately using the macro in C++ comes with a new set of restrictions that prevent some (subjectively valid) uses of it.

@graphitemaster
graphitemaster / gist:f8e6666c48fbedf6e554
Last active January 21, 2023 21:22
Engine achievements
Achievement Engine/Game Why it's bad
storing world space positions in gbuffer STALKER, F.E.A.R. Depth buffer can be used to derive position saving a lot of memory bandwidth
uploaded texture upside down Various engines, mostly Quake derived. Difficult to debug with tools like apitrace, nsight, pix, renderdoc, etc
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/file.h>
#include <sys/mman.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
@graphitemaster
graphitemaster / cyclic.h
Created January 24, 2014 19:31
How to prevent cyclic includes in C/C++
#if NAME_HDR == 1
# warning "Cyclic include"
#endif
#ifndef NAME_HDR
#define NAME_HDR 1
put_stuff_here;
#undef NAME_HDR
// church numerals and lambda calculus in C++ using meta-template
// programming, everything evaluated at compile-time. This code should
// never be used in the real world. If I catch people using this for
// real-world code just because it's awesome I will track said people
// down and have a length discussion on why their existance is the
// reason I need to question the ethics of writing this code in the
// first place.
// all code is licensed under MIT under one condition, never actually
// use this code in real world programs, you can share it, and modify it
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <stdint.h>
#include <pthread.h>
#include <unistd.h> // sleep()
struct Point {
@graphitemaster
graphitemaster / chip8.cfg
Created July 19, 2013 22:30
Cubescript Magic
emu_rom = [
0x22 0xFC 0x6B 0x0C 0x6C 0x3F 0x6D 0x0C 0xA2 0xEA 0xDA 0xB6 0xDC 0xD6 0x6E 0x00 0x22 0xD4 0x66 0x03 0x68
0x02 0x60 0x60 0xF0 0x15 0xF0 0x07 0x30 0x00 0x12 0x1A 0xC7 0x17 0x77 0x08 0x69 0xFF 0xA2 0xF0 0xD6 0x71
0xA2 0xEA 0xDA 0xB6 0xDC 0xD6 0x60 0x01 0xE0 0xA1 0x7B 0xFE 0x60 0x04 0xE0 0xA1 0x7B 0x02 0x60 0x1F 0x8B
0x02 0xDA 0xB6 0x60 0x0C 0xE0 0xA1 0x7D 0xFE 0x60 0x0D 0xE0 0xA1 0x7D 0x02 0x60 0x1F 0x8D 0x02 0xDC 0xD6
0xA2 0xF0 0xD6 0x71 0x86 0x84 0x87 0x94 0x60 0x3F 0x86 0x02 0x61 0x1F 0x87 0x12 0x46 0x00 0x12 0x78 0x46
0x3F 0x12 0x82 0x47 0x1F 0x69 0xFF 0x47 0x00 0x69 0x01 0xD6 0x71 0x12 0x2A 0x68 0x02 0x63 0x01 0x80 0x70
0x80 0xB5 0x12 0x8A 0x68 0xFE 0x63 0x0A 0x80 0x70 0x80 0xD5 0x3F 0x01 0x12 0xA2 0x61 0x02 0x80 0x15 0x3F
0x01 0x12 0xBA 0x80 0x15 0x3F 0x01 0x12 0xC8 0x80 0x15 0x3F 0x01 0x12 0xC2 0x60 0x20 0xF0 0x18 0x22 0xD4
0x8E 0x34 0x22 0xD4 0x66 0x3E 0x33 0x01 0x66 0x03 0x68 0xFE 0x33 0x01 0x68 0x02 0x12 0x16 0x79 0xFF 0x49