Skip to content

Instantly share code, notes, and snippets.

View jeremyong's full-sized avatar
⌨️

Jeremy Ong jeremyong

⌨️
View GitHub Profile
@jeremyong
jeremyong / JeremyTeX Terms of Use.txt
Created March 23, 2024 21:52
JeremyTeX Terms of Use
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
The JeremyTeX Confluence plugin does not store, submit, or retain any data in any way. All rendering is done client-side and internet communication exists strictly between the browser and Confluence.
@jeremyong
jeremyong / Function.hpp
Created December 15, 2023 16:50
std::function replacement using inlined storage
#pragma once
#include <concepts>
#include <core/Utility.hpp>
#include <new>
#include <string.h>
// A movable function adapted from LLVM's unique function. Assumes
// relocatability.
template <typename F>
// The MIT License
// Copyright 2022 Jeremy Ong
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE S
@jeremyong
jeremyong / is_it_safe.cpp
Last active May 21, 2021 20:23
Crowdsourcing review of lock free initialization/deinitialization routine
// Suppose we have two functions load() and unload() that take a finite amount of time to complete and are not threadsafe.
// They also cannot run at the same time. It is invalid to call load before a pending unload is finished, and it is invalid
// to call unload before a previous call to load has finished. Basically, we are either in a "fully loaded" state, or a
// "fully unloaded" state.
void load();
void unload();
// Furthermore, suppose we have two functions, start() and finish(). The first time we call start, load must
// run to completion before entering the body of start(). After the final call to finish, unload should be called unless

Art of Debugging

Obligatory disclaimer, this is all opinion and cannot possibly generalize to all problems, workflows, environments, etc. This is meant primarily as a launching point for an open-ended discussion on best practices in debugging code. This is a sketch of what may be a brief book that covers each point below with anecdotes, examples, and techniques.

Hypothesis 0

The ultimate goal of a debugging session is to rule out possibilities until only one remains. All applications of best practices, techniques, and tools should be pointed at this purpose (contextualize all points below against this statement). Debugging is first and foremost a critical thinking problem, and presence of mind is your most critical asset. Establish a mental model but do not be afraid to invalidate it as the investigation unfolds.

sherlock

Hypothesis 1

Assembly generated from code implemented here

AVX enabled

Motor (dual-quat) applied to a point:

 mov rax, rdi
  vmovaps xmm0, xmmword ptr [rsi]
  vmovaps xmm1, xmmword ptr [rsi + 16]

sent to the C++ SG14 working group

I actually came across an interesting idea that I would love to see in the language while working on a shader reflection library (participants here in the game engine community already have likely worked with these systems ad nauseum).

One feature graphics engineers use liberally and to good effect in shader code is "component swizzling." Suppose we have a vec4 which is a packed struct of four single-precision floats. We can perform operations such as the following

vec4 color = ... // Some color value with components rgba
color.rr; // This is a vec2 initialized with values {color.r, color.r}
color.zyz; // Equivalent to a vec3 initialized with {color.z, color.y, color.z}
#pragma once
#include <vector>
#include <vulkan/vulkan.hpp>
namespace vkf
{
template <typename Type, typename Dispatch = vk::DispatchLoaderStatic>
class VkUniqueVector
@jeremyong
jeremyong / tarball_exe.sh
Last active June 10, 2016 20:37
Creating a tarball from an executable that includes all dynamically linked libraries
#!/usr/bin/env bash
# This function takes a target executable and replicates its link dependencies to the target directory
# Also copies the dependencies to the bin subdirectory of the target
# Arg 1: executable
# Arg 2: output directory
copy_dependencies()
{
echo "Emitting linking dependencies of $1 to $2..."