Skip to content

Instantly share code, notes, and snippets.

@seanbaxter
seanbaxter / life.cxx
Last active July 12, 2021 16:26
Game of life with CIA
#include <cstdio>
#include <cstdlib>
#include <unistd.h>
// A board is uniquely determined by its height, width and cell data.
// The timestep is not part of the board.
template<int height, int width, int... cells>
struct board_t {
// Convert the cell data to a string constant.
static const char string[] {
import generators ;
using clang : : /usr/bin/circle ;
generators.override clang.compile.c.pch : pch.default-c-pch-generator ;
generators.override clang.compile.c++.pch : pch.default-cpp-pch-generator ;
@seanbaxter
seanbaxter / triangle.cxx
Created September 25, 2020 21:18
single-source vulkan triangle
#include <stdio.h>
#include <memory>
#include <iostream>
#include <fstream>
#include <vulkan/common.h>
// Shader interface helper variables.
template<auto index, typename type_t = @enum_type(index)>
[[using spirv: in, location((int)index)]]
type_t shader_in;
@seanbaxter
seanbaxter / sprites.cxx
Last active September 11, 2020 02:13
compiled sprites with SW framebuffer
#include <stb_image.h>
#include <string>
#include <vector>
#include <gl3w/GL/gl3w.h>
#include <GLFW/glfw3.h>
template<typename type_t>
const char* enum_to_string(type_t e) {
static_assert(std::is_enum_v<type_t>);
switch(e) {
@seanbaxter
seanbaxter / appglfw.hxx
Last active March 24, 2021 06:25
Circle glTF viewer. C++ shaders.
#pragma once
// #include <imgui.h>
// #include <examples/imgui_impl_glfw.h>
// #include <examples/imgui_impl_opengl3.h>
#include <stb_image.h>
#include <gl3w/GL/gl3w.h>
#include <GLFW/glfw3.h>
#include <cmath>
#include <cstdio>
#include <cfloat>
@seanbaxter
seanbaxter / Terminal
Last active August 12, 2020 21:32
Loading vert + tesc shader in one module segfaults nv driver in first call to glSpecializeShader.
$ glslc --target-env=opengl --target-spv=spv1.5 -o vert.spv vert.vert
$ glslc --target-env=opengl --target-spv=spv1.5 -o tesc.spv tesc.tesc
$ spirv-link vert.spv tesc.spv -o program.spv
$ clang++-9 segfault.cxx -lGL -lgl3w -lsfml-system -lsfml-window -lsfml-graphics -o segfault
$ ./segfault
Loaded spv: 1908 bytes
spv loaded
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff1dc7a54 in ?? () from /usr/lib/x86_64-linux-gnu/libnvidia-glcore.so.450.57
@seanbaxter
seanbaxter / bitfield.cxx
Created October 10, 2019 16:10
Bitfield width specifiers
#include <cstdio>
int read_value(const char* prompt) {
puts(prompt);
int x = 0;
scanf("%d", &x);
return x;
}
struct S {
#include <cstdio>
#include <type_traits>
#include <algorithm>
#include <utility>
#include <map>
#include <vector>
#include <tuple>
template<typename type_t>
struct foo_t {
'A,E Au aoeu
aoe
u
aoeu
aoe
count = 2048 ( 0) { 2, 4, 8, 16, 32, 32, 32, 32, 32} = 190
count = 2049 ( 1) { 1, 2, 4, 8, 16, 32, 32, 32, 32} = 159
count = 2050 ( 2) { 1, 2, 4, 8, 16, 32, 32, 32, 32} = 159
count = 2051 ( 3) { 1, 1, 2, 4, 8, 16, 16, 16, 16} = 80
count = 2052 ( 4) { 1, 1, 2, 4, 8, 16, 16, 16, 24} = 88
count = 2053 ( 5) { 1, 1, 2, 4, 8, 16, 16, 16, 24} = 88
count = 2054 ( 6) { 1, 1, 2, 4, 8, 16, 16, 16, 24} = 88
count = 2055 ( 7) { 1, 1, 1, 2, 4, 8, 8, 8, 16} = 49
count = 2056 ( 8) { 1, 1, 1, 2, 4, 8, 8, 12, 20} = 57
count = 2057 ( 9) { 1, 1, 1, 2, 4, 8, 8, 12, 20} = 57