Table of Contents

Class GPUBorderExtractor

Namespace
Map.Rendering.Border
Assembly
MapAssembly.dll

GPU-accelerated border pixel extraction using compute shaders. Replaces CPU-heavy median filter + junction detection + border pixel extraction.

Pipeline:

  1. MedianFilter kernel - Smooth province ID noise (3x3 mode filter) on GPU
  2. DetectBorderPixels kernel - Find all border pixels with province pair IDs
  3. DetectJunctions kernel - Find pixels where 3+ provinces meet
  4. 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
object
GPUBorderExtractor

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

provinceIDTexture Texture

Returns

GPUBorderExtractor.ExtractionResult

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

provincesImagePath string

Path to provinces.png - cache stored as provinces.png.borders

bordersByPair Dictionary<(ushort, ushort), List<Vector2>>
junctions Dictionary<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

provincesImagePath string

Path to provinces.png - cache stored as provinces.png.borders

Returns

GPUBorderExtractor.ExtractionResult