Skip to content

Instantly share code, notes, and snippets.

View mmozeiko's full-sized avatar

Mārtiņš Možeiko mmozeiko

View GitHub Profile
@mmozeiko
mmozeiko / snapdragonx.txt
Created October 16, 2024 03:54
Snapdragon X Elite PMC sources on Windows
Maximum selectable profile sources: 12.
Id Name Interval Min Max
--------------------------------------------------------------
0 Timer 10000 1221 1000000
2 TotalIssues 65536 4096 2147483647
4 LoadInstructions 65536 4096 2147483647
6 BranchInstructions 65536 4096 2147483647
8 DcacheMisses 65536 4096 2147483647
9 IcacheMisses 65536 4096 2147483647
@mmozeiko
mmozeiko / callstack_dump.c
Last active December 17, 2024 11:32
dumps callstack of all threads in a single process
#include <windows.h>
#include <dbghelp.h>
#include <tlhelp32.h>
#include <stdlib.h>
#include <stdio.h>
#pragma comment (lib, "dbghelp")
#pragma comment (lib, "advapi32")
int main(int argc, char* argv[])
@mmozeiko
mmozeiko / MagicRingBuffer.h
Last active November 24, 2024 22:23
Magic RingBuffer for Windows, Linux and macOS
#pragma once
//
// Magic Ring Buffer
// https://gist.github.com/mmozeiko/3b09a340f3c53e5eaed699a1aea95250
//
// Sets up memory mapping so the same memory block follows itself in virtual address space:
//
// [abcd...xyz][abc...xyz]
//
@mmozeiko
mmozeiko / wic.h
Last active April 29, 2024 00:06
simple wrapper to load or save D3D11 texture from/to image file with Windows Imaging Component
#pragma once
#define COBJMACROS
#include <windows.h>
#include <d3d11.h>
//
// interface
//
@mmozeiko
mmozeiko / _miniperf_readme.md
Last active December 10, 2024 10:42
get PMU counter values with ETW, perf or kperf

MiniPerf

Example of how to capture CPU counters with ETW on Windows, perf on Linux or kperf on Apple.

Using ETW needs somewhat recently updated Windows 10 or 11. Not sure about exact version.

Currently tested on:

  • etw on Qualcomm Snapdragon X Elite, Windows 11, arm64
  • etw on AMD Zen 3, Windows 11 (with virtualization enabled in BIOS)
@mmozeiko
mmozeiko / armv8_tsc.h
Last active November 4, 2024 22:12
armv8 timer & cycle counter
#pragma once
#if defined(__linux__)
# define _GNU_SOURCE
# include <sched.h>
# include <unistd.h>
# include <sys/syscall.h>
# include <linux/perf_event.h>
#elif defined(_WIN32)
# include <intrin.h>
@mmozeiko
mmozeiko / preview.c
Last active October 12, 2024 23:38
windows shell preview handler example
// example of using Windows Preview Handler
// https://learn.microsoft.com/en-us/windows/win32/shell/preview-handlers
#define COBJMACROS
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <shlwapi.h>
#include <shellapi.h>
#include <shobjidl.h>
@mmozeiko
mmozeiko / win32_webgpu.c
Last active December 20, 2024 12:54
setting up and using WebGPU in C using Dawn
// example how to set up WebGPU rendering on Windows in C
// uses Dawn implementation of WebGPU: https://dawn.googlesource.com/dawn/
// download pre-built Dawn webgpu.h/dll/lib files from https://github.com/mmozeiko/build-dawn/releases/latest
#include "webgpu.h"
#define _CRT_SECURE_NO_DEPRECATE
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
@mmozeiko
mmozeiko / upng.h
Last active October 8, 2024 03:47
uncompressed png writer & reader
#pragma once
// uncompressed png writer & reader
// supports only 8-bit and 16-bit formats
// Performance comparison for 8192x8192 BGRA8 image (256MB)
// Compiled with "clang -O2", AVX2 requires extra "-mavx2" or "/arch:AVX2" argument
//
// For libpng (compressed) uses default libpng/zlib compression settings
// For libpng (uncompressed) case following two functions are used:
@mmozeiko
mmozeiko / !README.md
Last active December 18, 2024 12:03
Download MSVC compiler/linker & Windows SDK without installing full Visual Studio

This downloads standalone MSVC compiler, linker & other tools, also headers/libraries from Windows SDK into portable folder, without installing Visual Studio. Has bare minimum components - no UWP/Store/WindowsRT stuff, just files & tools for native desktop app development.

Run py.exe portable-msvc.py and it will download output into msvc folder. By default it will download latest available MSVC & Windows SDK - currently v14.40.33807 and v10.0.26100.0.

You can list available versions with py.exe portable-msvc.py --show-versions and then pass versions you want with --msvc-version and --sdk-version arguments.

To use cl.exe/link.exe first run setup_TARGET.bat - after that PATH/INCLUDE/LIB env variables will be updated to use all the tools as usual. You can also use clang-cl.exe with these includes & libraries.

To use clang-cl.exe without running setup.bat, pass extra /winsysroot msvc argument (msvc is folder name where output is stored).