Skip to content

Instantly share code, notes, and snippets.

@dondragmer
dondragmer / BitonicSort.hsl
Last active April 15, 2025 09:21
An optimized bitonic sorting compute shader. Has no bank conflicts, uses shader model 6.6 wave interstices, and works with different sort sizes and per-wave lane counts.
RWBuffer<uint> SortBuffer : register(u0);
static const uint sSortSize = 1024; // can be any power of up to 1024 (the max threads in a group)
// to avoid all bank conflicts there needs to be a space of padding inserted at every multiple of every power of the wave size
// (if an index is a multiple of several powers of the wave size a pad needs to be added for each)
// the smallest wave size possible is 4, so the most padding needed is (sort size) * (1/4 + 1/16 + 1/64 ...)
// which convergets to (sort size) / 3;
static const uint sGroupsharedSortValuesToPaddingRatio = 3;
@h3r2tic
h3r2tic / restir-meets-surfel-lighting-breakdown.md
Created November 23, 2021 02:15
A quick breakdown of lighting in the `restir-meets-surfel` branch of my renderer

A quick breakdown of lighting in the restir-meets-surfel branch of my renderer, where I revive some olde surfel experiments, and generously sprinkle ReSTIR on top.

General remarks

Please note that this is all based on work-in-progress experimental software, and represents a single snapshot in development history. Things will certainly change 😛

Due to how I'm capturing this, there's frame-to-frame variability, e.g. different rays being shot, TAA shimmering slightly. Some of the images come from a dedicated visualization pass, and are anti-aliased, and some show internal buffers which are not anti-aliased.

Final images

@dondragmer
dondragmer / PrefixSort.compute
Created January 20, 2021 23:32
An optimized GPU counting sort
#pragma use_dxc //enable SM 6.0 features, in Unity this is only supported on version 2020.2.0a8 or later with D3D12 enabled
#pragma kernel CountTotalsInBlock
#pragma kernel BlockCountPostfixSum
#pragma kernel CalculateOffsetsForEachKey
#pragma kernel FinalSort
uint _FirstBitToSort;
int _NumElements;
int _NumBlocks;
bool _ShouldSortPayload;