Skip to content

Instantly share code, notes, and snippets.

View subgroup.glsl
#version 460
#extension GL_KHR_shader_subgroup_vote: require
layout (location = 0) in float lightDistanceSqared;
layout (location = 0) out vec4 fragColor;
void main()
{
const int radius = 5;
#if 0
@Trass3r
Trass3r / containers-are-expensive.cpp
Last active Nov 27, 2020
comparing implementations of 'is x in a set of numbers' - https://godbolt.org/z/9en4qv
View containers-are-expensive.cpp
int baseline(int x)
{
switch (x)
{
case 0:
case 2:
case 8:
case 15:
case 16:
return 5;
@Trass3r
Trass3r / CompressWSLdisks.ps1
Created Nov 23, 2020
Reduces disk space taken by the WSL and Docker vhdx files
View CompressWSLdisks.ps1
$ErrorActionPreference = "Stop"
$files = Get-ChildItem -Path C:\Users -Recurse -Include "ext4.vhdx" -Force -ErrorAction SilentlyContinue | Select-Object FullName, Length
wsl sudo fstrim /
foreach ($file in $files) {
echo "Compacting $file"
wsl --shutdown
Mount-VHD -Path $file.FullName -ReadOnly
@Trass3r
Trass3r / buildWSL2kernel.sh
Last active Feb 4, 2021
build WSL2 Linux 'next' kernel with clang LTO
View buildWSL2kernel.sh
git clone https://github.com/nathanchance/WSL2-Linux-Kernel
cd WSL2-Linux-Kernel
cp arch/x86/configs/wsl2_defconfig .config
./scripts/config -d XFS_FS -d NFS_FS -d NFSD -d BTRFS_FS -d F2FS_FS -d SUNRPC -d X86_X32 -d X86_16BIT -e CPU_FREQ -e CPU_FREQ_STAT -e CPU_FREQ_GOV_USERSPACE -e CPU_FREQ_GOV_ONDEMAND -e X86_INTEL_PSTATE -e SCHED_MC_PRIO -e PROFILING -e PERF_EVENTS_INTEL_UNCORE -e PERF_EVENTS_INTEL_RAPL -e PERF_EVENTS_INTEL_CSTATE -e ENERGY_MODEL -e INTEL_IDLE -e MODULE_COMPRESS_LZ4 -e KERNEL_LZ4 -e CC_OPTIMIZE_FOR_PERFORMANCE_O3 -e LD_DEAD_CODE_DATA_ELIMINATION -e BPF_JIT -e LTO_CLANG -d CFI_CLANG -d STACKPROTECTOR -e OPROFILE -e OPROFILE_EVENT_MULTIPLEX
# ./scripts/config -e KALLSYMS -e HIGH_RES_TIMERS -e FTRACE -e KPROBES -m LTTNG -e MODULES
# -e KALLSYMS_ALL for probe 'writeback'
# KPROBES requires MODULES
make LLVM=1 LLVM_IAS=1 menuconfig
time make LLVM=1 LLVM_IAS=1 KCFLAGS='-march=skylake' -j8
sudo make LLVM=1 LLVM_IAS=1 KCFLAGS='-march=skylake' -j8 -C tools/perf install DESTDIR=/usr/local
@Trass3r
Trass3r / static_foreach.cpp
Last active Nov 13, 2020
C++17 foreach over tuple implementation
View static_foreach.cpp
// https://godbolt.org/z/9vWYd8
#include <utility> // forward, integer_sequence
#include <tuple> // get
namespace detail {
template <typename F, typename Tuple, std::size_t... I>
constexpr void static_foreach_impl(Tuple&& t, F&& f, std::index_sequence<I...>)
{
// assume f is a simple FunctionObject, so just call instead of std::invoke
@Trass3r
Trass3r / CompactVHDX.ps1
Created Oct 16, 2020
compact a Hyper-V disk file
View CompactVHDX.ps1
$vhdx=$args[0]
Mount-VHD $vhdx -ReadOnly
Optimize-VHD $vhdx -Mode Full
Dismount-VHD $vhdx
@Trass3r
Trass3r / rungitgc.sh
Created Oct 16, 2020
run git gc on every git repo in the current directory
View rungitgc.sh
find . -name .git -type d -prune -execdir pwd \; -execdir git gc --aggressive --prune=now \;
@Trass3r
Trass3r / fix vmwp.bat
Created Sep 24, 2020
enable hardware performance counters in WSL2
View fix vmwp.bat
REM open cmd.exe as admin
wsl --shutdown
icacls vmwp.exe /grant Administratoren:F
move vmwp.exe vmwp__.exe
REM Create a patched vmwp.exe replacing the first line of bytes with the second:
REM 0F B6 43 64 41 89 47 64 0F B6 43 65 41 89 47 68 0F B6 43 66 41 89 47 6C 0F B6 43 67 41 89 47 70
REM 41 C7 47 64 01 00 00 00 41 C7 47 68 01 00 00 00 41 C7 47 6C 01 00 00 00 41 C7 47 70 01 00 00 00
View gtest-parameterized-tests.cpp
#define TEST_PV(testsuite, testname, ...) \
class testsuite##Parameterized : public testsuite, \
public ::testing::WithParamInterface<decltype(GTEST_GET_FIRST_(__VA_ARGS__))> {}; \
INSTANTIATE_TEST_SUITE_P(, testsuite##Parameterized, ::testing::Values(__VA_ARGS__)); \
TEST_P(testsuite##Parameterized, testname)
@Trass3r
Trass3r / foridx.cpp
Created Jul 28, 2020
C++17 range-for with index macro: https://godbolt.org/z/Yd4j8G
View foridx.cpp
#include <stdint.h>
#include <stddef.h>
#include <stdio.h>
#include <math.h>
#define for_i(...) \
if (decltype(sizeof(0)) i_next = 0; true) \
for (__VA_ARGS__) \
if (auto i = i_next++; true)