Class GPUBorderExtractor
GPU-accelerated border pixel extraction using compute shaders. Replaces CPU-heavy median filter + junction detection + border pixel extraction.
Pipeline:
- MedianFilter kernel - Smooth province ID noise (3x3 mode filter) on GPU
- DetectBorderPixels kernel - Find all border pixels with province pair IDs
- DetectJunctions kernel - Find pixels where 3+ provinces meet
- CPU readback - Group border pixels by province pair for chaining
Follows GPUProvinceNeighborDetector patterns:
- Static class, AppendStructuredBuffer, CopyCount readback
- Binary disk cache with magic + version header
public static class GPUBorderExtractor
- Inheritance
-
objectGPUBorderExtractor
Properties
IsAvailable
public static bool IsAvailable { get; }
Property Value
- bool
Methods
ExtractBorderPixelsGPU(Texture)
Extract border pixels using GPU compute shaders. Returns border pixels grouped by province pair, ready for chaining/smoothing.
public static GPUBorderExtractor.ExtractionResult ExtractBorderPixelsGPU(Texture provinceIDTexture)
Parameters
provinceIDTextureTexture
Returns
Initialize()
Initialize the compute shader.
public static bool Initialize()
Returns
- bool
SaveCache(string, Dictionary<(ushort, ushort), List<Vector2>>, Dictionary<Vector2, int>)
Save border extraction data to disk cache. Stored as provinces.png.borders alongside the source image.
public static void SaveCache(string provincesImagePath, Dictionary<(ushort, ushort), List<Vector2>> bordersByPair, Dictionary<Vector2, int> junctions)
Parameters
provincesImagePathstringPath to provinces.png - cache stored as provinces.png.borders
bordersByPairDictionary<(ushort, ushort), List<Vector2>>junctionsDictionary<Vector2, int>
TryLoadCache(string)
Try to load border extraction data from disk cache. Cache invalidates when provinces.png is newer than the cache file. Format: [BRDR 4B][version 4B][pairCount 4B][junctionCount 4B] [pairs: provinceA(2B) provinceB(2B) pixelCount(4B) pixels(x:2B,y:2B)...] [junctions: x(2B) y(2B) count(4B)...]
public static GPUBorderExtractor.ExtractionResult TryLoadCache(string provincesImagePath)
Parameters
provincesImagePathstringPath to provinces.png - cache stored as provinces.png.borders