Skip to content

Instantly share code, notes, and snippets.

What is "Work Expansion"

In a gpu-driven renderer "work expansion" is a commonly occuring problem. "Work Expansion" means that a single item of work spawns N following work items. Typically one work item will be executed by one shader thread/invocation.

An example for work expansion is gpu driven meshlet culling following mesh culling. In this example a "work item" is culling a mesh, where each mesh cull work item spawns N following meshlet cull work items.

There are many diverse cases of this problem and many solutions. Some are trivial to solve, for example, when N (how many work items are spawned) is fixed.

# Simulator for depth comparison error (i.e. z-fighting)
# Nathan Reed, June 2015
# Written for Python 3.4; requires numpy
import math
import numpy as np
import optparse
# Parse command-line options
parser = optparse.OptionParser()
@wiseConst
wiseConst / JetBrainsTrial.bat
Created April 3, 2025 06:33 — forked from MrPaXe/JetBrainsTrial.bat
Infinite Jetbrains Resharper trial
:: This bat file can be used to renew Resharper C# and Resharper C++ every time it runs out
:: It most likely works for all Jetbrains tools, however, I did not test this.
:: I was not able to find the original author for the reg key and the folders that needs to be deleted so if that is you feel free to reach out for credit
@echo off
setlocal enableDelayedExpansion
:confirm
echo Did you stop all Jetbrains services?
echo Jetbrains toolbox AND any other tool using it such as Rider, Visual Studio, ...
@wiseConst
wiseConst / bounds-frag.glsl
Created April 3, 2025 14:19 — forked from zeux/bounds-frag.glsl
Shader code used in "Approximate projected bounds" article, used for profiling with offline cycle estimation tools.
#version 450
// 2D Polyhedral Bounds of a Clipped, Perspective-Projected 3D Sphere. Michael Mara, Morgan McGuire. 2013
bool projectSphereView(vec3 c, float r, float znear, float P00, float P11, out vec4 aabb)
{
if (c.z < r + znear) return false;
vec3 cr = c * r;
float czr2 = c.z * c.z - r * r;
@wiseConst
wiseConst / sphere_screen_extents.h
Created April 3, 2025 14:20 — forked from JarkkoPFC/sphere_screen_extents.h
Calculates view space 3D sphere extents on the screen
struct vec3f {float x, y, z;};
struct vec4f {float x, y, z, w;};
struct mat44f {vec4f x, y, z, w;};
//============================================================================
// sphere_screen_extents
//============================================================================
// Calculates the exact screen extents xyzw=[left, bottom, right, top] in
// normalized screen coordinates [-1, 1] for a sphere in view space. For
// performance, the projection matrix (v2p) is assumed to be setup so that
@wiseConst
wiseConst / 3_byte_tangent_frames.md
Last active June 17, 2025 05:59
3 BYTE TANGENT FRAMES + bitmask array for TBN sign. Doom Eternal 2020

3-Byte Tangent Frame Encoding (Doom Eternal 2020)

This method stores a full TBN frame using just 3 bytes per vertex (plus a bitfield), instead of the traditional 28 bytes (normal: vec3, tangent: vec4). It leverages octahedral encoding for normals and a rotation angle for tangent reconstruction.

Motivation

Storing both glm::vec3 normal and glm::vec4 tangent is costly. Since the bitangent can be reconstructed via a cross product, we only need:

  • A unit normal (encoded in 2 bytes)
  • An angle to rotate a base tangent around the normal (1 byte)
@wiseConst
wiseConst / gpr.md
Created April 9, 2025 07:55 — forked from pyoneerC/gpr.md
List of free resources to study graphics programming.
@wiseConst
wiseConst / projection.hpp
Created April 9, 2025 07:57 — forked from pezcode/projection.hpp
Reversed Z + infinite far plane projection matrices with GLM
// these matrices are for left-handed coordinate systems, with depth mapped to [1;0]
// the derivation for other matrices is analogous
// to get a perspective matrix with reversed z, simply swap the near and far plane
glm::mat4 perspectiveFovReverseZLH_ZO(float fov, float width, float height, float zNear, float zFar) {
return glm::perspectiveFovLH_ZO(fov, width, height, zFar, zNear);
};
// now let zFar go towards infinity
glm::mat4 infinitePerspectiveFovReverseZLH_ZO(float fov, float width, float height, float zNear) {
// cofactor matrix. drop-in replacement for the traditional transpose(inverse(m)) normal matrix calculation.
// this is a substantial performance improvement.
// short form found via shadertoy: https://www.shadertoy.com/view/3s33z
mat3 cofactor(mat4 m) {
return mat3(
cross(m[1].xyz, m[2].xyz),
cross(m[2].xyz, m[0].xyz),
cross(m[0].xyz, m[1].xyz)
);
}