Skip to content

Instantly share code, notes, and snippets.

View MrSmith33's full-sized avatar

Andrey Penechko MrSmith33

View GitHub Profile
@bkaradzic
bkaradzic / idl.md
Last active February 3, 2025 14:50
bgfx is switching to IDL to generate API

bgfx is switching to IDL to generate API

bgfx main API is using basic C++ that looks like C, but it's C++ enough that can't be used directly in C projects. C is important as it provides ability to bind API to other languages, and also as sanity check for API design.

Every time API changes manual process of process for adding/changing API for C99 bindings was changing header declarations of function and function type for interface virtual table (I'll use bgfx::createVertexBuffer function as an example):

/* ... bunch of funcs ... */

/**/
BGFX_C_API bgfx_vertex_buffer_handle_t bgfx_create_vertex_buffer(
typedef T = int;
var segs: T**;
var seg: T*;
var segcap = 1;
var segidx = 1;
func grow() {
seg = 0;
asetcap(seg, segcap);
apush(segs, seg);

State of Roblox graphics API across all platforms, with percentage deltas since EOY 2018. Updated December 29 2019.

Windows

API Share
Direct3D 11+ 85% (+5%)
Direct3D 10.1 8.5% (-1.5%)
Direct3D 10.0 5.5% (-2.5%)
Direct3D 9 1% (-1%)

Deterministic save load in Factorio

One of the key parts of the save/load process in Factorio is that it must be deterministic. This means that for a given save file (when no external factors change) saving, exiting, and loading the save shouldn't change any observable behavior.

There are a few reasons and benefits for this strict requirement:

  • Without it: You couldn't join a running multiplayer game (and by proxy save, exit, and resume one)
  • Without it: the replay system wouldn't work if you ever saved, exited, and resumed playing.
  • With it: we can easily test that saving and loading produces no observable change letting us know we implemented save/load correctly.
  • With it: you won't see things change randomly as a result of "reloading" like you do in so many other games.
/// https://en.wikipedia.org/wiki/Activation_function
module stage2.nn.activationfunctions;
import std.math : exp, pow, E, tanh, atan, abs, sqrt, log, sin, cos, PI;
struct ActivationFunction {
double function(double x, double arg) activation;
double function(double x, double arg) derivative;
double arg;
}
//
// Author: Jonathan Blow
// Version: 1
// Date: 31 August, 2018
//
// This code is released under the MIT license, which you can find at
//
// https://opensource.org/licenses/MIT
//
//
Umbra3 Occlusion Culling
https://www.gamasutra.com/view/feature/164660/sponsored_feature_next_generation_.php?print=1
https://umbra3d.com/blog/occlusion-culling-solving-the-visibility-problem-part-ii/
https://support.umbra3d.com/hc/en-us/articles/213354709-Latest-Version-3-4-12
UnrealEngine Culling
http://timhobsonue4.snappages.com/culling-visibilityculling.htm
https://api.unrealengine.com/udk/Three/VisibilityCulling.html
http://timhobsonue4.snappages.com/culling-precomputed-visibility-volumes
Intel Software Occlusion Culling
https://software.intel.com/en-us/articles/software-occlusion-culling
@spyesx
spyesx / youtube_watch_later.js
Last active June 16, 2024 13:38
Get URLs of your youtube watch later playlist
// Execute this in the console of on your own playlist
var videos = document.querySelectorAll('.yt-simple-endpoint.style-scope.ytd-playlist-video-renderer');
var r = [];
var json = [];
r.forEach.call(videos, function(video) {
var url = 'https://www.youtube.com' + video.getAttribute('href');
url = url.split('&list=WL&index=');
url = url[0];

why doesn't radfft support AVX on PC?

So there's two separate issues here: using instructions added in AVX and using 256-bit wide vectors. The former turns out to be much easier than the latter for our use case.

Problem number 1 was that you positively need to put AVX code in a separate file with different compiler settings (/arch:AVX for VC++, -mavx for GCC/Clang) that make all SSE code emitted also use VEX encoding, and at the time radfft was written there was no way in CDep to set compiler flags for just one file, just for the overall build.

[There's the GCC "target" annotations on individual funcs, which in principle fix this, but I ran into nasty problems with this for several compiler versions, and VC++ has no equivalent, so we're not currently using that and just sticking with different compilation units.]

The other issue is to do with CPU power management.