Skip to content

Instantly share code, notes, and snippets.

@zeux
zeux / nbody.s
Last active January 2, 2020 18:20
luaujit: nbody.lua when compiled using experimental Luau JIT engine. All assembly snippets only show inner loop body. Variants: scalar - using type info, records and basic block compiler to generate much more efficient inner loop; vector - scalar but with scalars replaced with first-class 3-component vector
# table type guard (memory safety)
cmp dword ptr [rdi + 12], 6
jne 1072 <.text+0x5ea>
# load array index and convert to integer (+ exactness check)
movsd xmm0, qword ptr [rdi + 256]
cvttsd2si eax, xmm0
cvtsi2sd xmm1, eax
ucomisd xmm1, xmm0
jne 1046 <.text+0x5ea>
# indices are 1-based; could remove this one with runtime changes
@zeux
zeux / islandize-reuv.cpp
Last active June 25, 2019 05:58
Isolate UV islands and move each island to 0..1 range if possible; this reduces the total UV range of the mesh.
unsigned int follow(std::vector<unsigned int>& ids, unsigned int v)
{
unsigned int nv = v;
while (ids[nv] != nv)
nv = ids[nv];
return ids[v] = nv;
}
size_t islandize(const std::vector<unsigned int>& indices, std::vector<unsigned int>& islands)
@zeux
zeux / half-spirv.md
Last active July 16, 2021 01:35
Notes on supporting half-precision computation in SPIRV based shader pipelines

The following assumes that HLSL source is used as an input for shader compilation, glslang is used to compile it to SPIRV, and then SPIRV-Cross is optionally used to compile the result to MSL/GLSL.

First, make sure you use min16floatN type instead of halfN type. This is necessary because glslang treats halfN type (with default compilation options) as floatN because unfortunately that's what DX10 does as well.

#define half min16float
#define half2 min16float2
#define half3 min16float3
void decomposeMatrix(const float* matrix, float translation[3], float rotation[4], float scale[3])
{
translation[0] = matrix[12];
translation[1] = matrix[13];
translation[2] = matrix[14];
// 0 1 2
// 4 5 6
// 8 9 10
float det =
@zeux
zeux / luau_features.pdf
Last active May 22, 2024 23:40
Frequently asked questions about the Lua VM work we (Roblox) are doing.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@zeux
zeux / murmur.h
Last active March 20, 2021 23:05
MurMurHash finalizers as 32-bit integer/pointer hashers
uint32_t murmur2(uint32_t h)
{
h ^= h >> 13;
h *= 0x5bd1e995;
h ^= h >> 15;
return h;
}
uint32_t murmur3(uint32_t h)
@zeux
zeux / simplifier.cpp
Created February 18, 2019 04:03
SIMD sloppy simplifier for "Flavors of SIMD" blog post
// This file is part of meshoptimizer library; see meshoptimizer.h for version/license details
#include "meshoptimizer.h"
#include <assert.h>
#include <float.h>
#include <math.h>
#include <string.h>
#ifndef TRACE
#define TRACE 0
@zeux
zeux / launch.json
Created February 12, 2019 07:03
Visual Studio Code launch.json for debugging with gdb via WSL
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "/mnt/c/work/meshoptimizer/build/debug/meshoptimizer",
"args": ["-d", "data/kitten.obj"],
"stopAtEntry": false,
@zeux
zeux / README.md
Last active January 19, 2019 16:31
Reproduction for 36 seconds of simplification time in debug when using MSVC 2017 x64 with default settings on buddha.obj
@zeux
zeux / README.md
Last active May 23, 2019 20:03
Simplifier variants