{
 "id": "block-texture-compression",
 "title": "Block texture compression (BC7 / ASTC)",
 "aliases": [
  "BC7",
  "ASTC",
  "BCn",
  "Block Compression",
  "BC5",
  "VRAM Texture Compression"
 ],
 "domain": "performance",
 "subdomain": "texture compression",
 "stage": "performance",
 "realtime": "offline",
 "platforms": [
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "mobile-gpu",
  "unity",
  "unreal"
 ],
 "year_introduced": 2012,
 "inputs": [
  "texture"
 ],
 "outputs": [
  "texture"
 ],
 "style": "both",
 "dynamic": "both",
 "summary": "Fixed-rate GPU block formats such as BC7 on desktop and ASTC on mobile keep textures compressed in video memory, shrinking bandwidth and footprint at some quality loss.",
 "how_it_works": "Images are split into small blocks, 4x4 for BC7 and variable sizes from 4x4 to 12x12 for ASTC. Each block stores two or more endpoint colours, optional partition choices and per-texel weights. The GPU decodes blocks on the fly during sampling, so memory use and fetch bandwidth drop by 4x to over 10x with random access preserved.\n\nEncoders search partitions, modes and weights per block to minimise error; slower settings give better quality. Data is lossy and offline-encoded, with separate handling for normals, HDR and alpha.",
 "when_to_use": "Choose BC7 for high-quality desktop colour and ASTC where mobile support is needed or flexible bitrates help. Prefer `basis-universal-ktx2` when one file must transcode to whichever format the device supports. Prefer uncompressed or lossless only for lookup tables and tiny UI.",
 "cost": {
  "class": "cheap",
  "notes": "Decoding is free in hardware; encoding is the offline cost."
 },
 "failure_modes": [
  "Block artifacts and colour banding on smooth gradients",
  "Normals suffer without a dedicated two-channel layout",
  "Hardware support differs: ASTC absent on many desktop GPUs, BC7 absent on most mobile",
  "Chroma bleeding at sharp colour edges within a block"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1201/b16721-26",
   "type": "chapter",
   "title": "Adaptive Scalable Texture Compression",
   "authors": [],
   "year": 2014,
   "venue": "GPU Pro 5",
   "url": "https://doi.org/10.1201/b16721-26",
   "ids": {
    "doi": "10.1201/b16721-26"
   },
   "license": null,
   "extra": {
    "csl_type": "book-chapter"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1201/b16721-26",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1201/b16721-26",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1201/b16721-26",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1201/b16721-26",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1201/b16721-26",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "anon2014adaptive"
  },
  {
   "role": "implementation",
   "key": "gh:arm-software/astc-encoder",
   "type": "code",
   "title": "ARM-software/astc-encoder",
   "description": "The Arm ASTC Encoder, a compressor command line tool and codec library for the Adaptive Scalable Texture Compression image format.",
   "authors": [
    "ARM-software"
   ],
   "year": 2015,
   "venue": "GitHub",
   "url": "https://github.com/ARM-software/astc-encoder",
   "ids": {
    "repo": "ARM-software/astc-encoder"
   },
   "license": "Apache-2.0",
   "extra": {
    "stars": 1325,
    "stars_checked": "2026-11-29",
    "archived": false,
    "fork": false,
    "pushed_at": "2026-11-28T14:44:52Z",
    "language": "C++",
    "homepage": "https://developer.arm.com/mobile-graphics-and-gaming",
    "license_name": "Apache License 2.0"
   },
   "provenance": {
    "title": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/ARM-software/astc-encoder",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/ARM-software/astc-encoder",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/ARM-software/astc-encoder",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/ARM-software/astc-encoder",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/ARM-software/astc-encoder",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "license": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/ARM-software/astc-encoder",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": null,
   "__bib": "armsoftware2015software"
  },
  {
   "role": "implementation",
   "key": "gh:richgel999/bc7enc_rdo",
   "type": "code",
   "title": "richgel999/bc7enc_rdo",
   "description": "RDO BC1-7 GPU texture encoders",
   "authors": [
    "richgel999"
   ],
   "year": 2021,
   "venue": "GitHub",
   "url": "https://github.com/richgel999/bc7enc_rdo",
   "ids": {
    "repo": "richgel999/bc7enc_rdo"
   },
   "license": "NOASSERTION",
   "extra": {
    "stars": 292,
    "stars_checked": "2026-11-29",
    "archived": false,
    "fork": false,
    "pushed_at": "2026-07-31T02:35:20Z",
    "language": "C++",
    "homepage": null,
    "license_name": "Other"
   },
   "provenance": {
    "title": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/richgel999/bc7enc_rdo",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/richgel999/bc7enc_rdo",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/richgel999/bc7enc_rdo",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/richgel999/bc7enc_rdo",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/richgel999/bc7enc_rdo",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "license": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/richgel999/bc7enc_rdo",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": null,
   "__bib": "richgel2021richgel999"
  }
 ],
 "presets": [
  {
   "id": "block-texture-compression-live",
   "title": "Block Texture Compression (BC7/ASTC) — 4x4 endpoint quantization & partitions (left) vs uncompressed (right)",
   "runtime": "glsl-fragment",
   "params": {
    "P_BLOCK_PX": 10,
    "P_PARTITIONS": 1,
    "P_ERROR_VIS": 0,
    "P_SPLIT": 0.5
   },
   "basis": "original",
   "license_note": "MIT — written for this index.",
   "code": "const float P_BLOCK_PX = 10.0; // P Block Size px [4.0, 22.0, 1.0]\nconst float P_PARTITIONS = 1.0; // P Dual Partition [0.0, 1.0, 1.0]\nconst float P_ERROR_VIS = 0.0; // P Error Heat Mode [0.0, 1.0, 0.05]\nconst float P_SPLIT = 0.50; // P Compressed / Source [0.0, 1.0, 0.02]\n\n// High-frequency colorful test chart combining sharp diagonal color edges, smooth gradients & fine rings\nvec3 sourceTexture(vec2 uv, float t) {\n  vec2 p = uv;\n  float r = length(p - vec2(0.0, 0.02));\n  float a = atan(p.y - 0.02, p.x);\n\n  // Smooth chromatic gradient backdrop\n  vec3 bg = 0.5 + 0.45 * cos(vec3(0.0, 2.094, 4.188) + p.x * 2.6 + p.y * 1.9 + t * 0.35);\n\n  // Sharp contrasting diagonal color bar (classic worst-case for 1-subset BC1/DXT1, solved by BC7 2-subset partitions!)\n  float diag = p.x * 0.78 + p.y * 0.62 - 0.08 * sin(t * 0.6);\n  vec3 stripeCol = (diag > 0.0) ? vec3(0.98, 0.34, 0.14) : vec3(0.08, 0.78, 0.88);\n  float band = smoothstep(0.16, 0.15, abs(diag));\n  vec3 col = mix(bg * 0.68, stripeCol, band * 0.85);\n\n  // Concentric high-contrast metallic rings\n  float ring = smoothstep(0.024, 0.014, abs(fract(r * 6.5 - t * 0.18) - 0.5));\n  float inner = smoothstep(0.38, 0.36, r);\n  vec3 ringCol = mix(vec3(0.96, 0.86, 0.24), vec3(0.86, 0.22, 0.72), 0.5 + 0.5 * sin(a * 4.0));\n  col = mix(col, ringCol, ring * inner * 0.92);\n\n  // Fine checker patch at bottom-left to stress 4x4 block endpoint interpolation\n  if (p.x < -0.15 && p.y < -0.12) {\n    float chk = mod(floor(p.x * 26.0) + floor(p.y * 26.0), 2.0);\n    col = mix(vec3(0.10, 0.14, 0.22), vec3(0.95, 0.90, 0.78), chk);\n  }\n  return clamp(col, 0.0, 1.0);\n}\n\n// Quantize a single 4x4 block subset along its principal min/max color line (4 levels = 2-bit BC index)\nvec3 compressSubset(vec2 blockOrigin, vec2 blockSize, vec2 texelUV, int subsetId, bool dualPart, float t) {\n  vec3 cMin = vec3(1e5);\n  vec3 cMax = vec3(-1e5);\n  vec3 cSum = vec3(0.0);\n  float count = 0.0;\n\n  // Sample 4x4 texels inside the block to fit the endpoint pair (E0, E1)\n  for (int y = 0; y < 4; y++) {\n    for (int x = 0; x < 4; x++) {\n      vec2 local = (vec2(float(x), float(y)) + 0.5) * 0.25;\n      int sid = (dualPart && (local.x + local.y > 1.0)) ? 1 : 0;\n      if (sid != subsetId) continue;\n      vec3 c = sourceTexture(blockOrigin + local * blockSize, t);\n      cMin = min(cMin, c);\n      cMax = max(cMax, c);\n      cSum += c;\n      count += 1.0;\n    }\n  }\n  if (count < 0.5) return sourceTexture(texelUV, t);\n\n  // 5-6-5 / 7-bit endpoint quantization\n  float qSteps = dualPart ? 31.0 : 15.0;\n  vec3 e0 = floor(cMin * qSteps + 0.5) / qSteps;\n  vec3 e1 = floor(cMax * qSteps + 0.5) / qSteps;\n\n  // Project current texel onto endpoint line segment (e0 -> e1) and quantize to 2-bit index {0, 1/3, 2/3, 1}\n  vec3 cur = sourceTexture(texelUV, t);\n  vec3 axis = e1 - e0;\n  float denom = dot(axis, axis);\n  float alpha = (denom > 1e-5) ? clamp(dot(cur - e0, axis) / denom, 0.0, 1.0) : 0.0;\n  float idx = floor(alpha * 3.0 + 0.5) / 3.0;\n  return mix(e0, e1, idx);\n}\n\nvec3 aces(vec3 x) {\n  x = max(x, 0.0);\n  return (x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14);\n}\n\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord) {\n  vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;\n  float screenX = fragCoord.x / max(iResolution.x, 1.0);\n  float split = clamp(P_SPLIT, 0.0, 1.0);\n  bool isSource = screenX >= split;\n  float blockPx = clamp(floor(P_BLOCK_PX + 0.5), 4.0, 24.0);\n  bool dualPart = P_PARTITIONS > 0.5;\n  float errVis = clamp(P_ERROR_VIS, 0.0, 1.0);\n\n  vec3 orig = sourceTexture(uv, iTime);\n  vec3 col = orig;\n\n  if (!isSource) {\n    // Snap to 4x4 texel block coordinates in screen space\n    float blockWorld = (blockPx * 4.0) / max(iResolution.y, 1.0);\n    vec2 bId = floor(uv / blockWorld);\n    vec2 bLocal = fract(uv / blockWorld);\n    vec2 bOrigin = bId * blockWorld;\n\n    // Quantize current fragment to its 4x4 texel center\n    vec2 texCenter = (floor(bLocal * 4.0) + 0.5) * 0.25;\n    vec2 texUV = bOrigin + texCenter * blockWorld;\n    int sid = (dualPart && (texCenter.x + texCenter.y > 1.0)) ? 1 : 0;\n\n    vec3 decoded = compressSubset(bOrigin, vec2(blockWorld), texUV, sid, dualPart, iTime);\n\n    // Optional amplified RMS compression error heatmap (shows why 2-subset BC7 beats 1-subset BC1!)\n    float err = length(decoded - orig) * 4.2;\n    vec3 errCol = mix(vec3(0.05, 0.14, 0.30), vec3(1.0, 0.36, 0.12), clamp(err, 0.0, 1.0));\n    errCol = mix(errCol, vec3(1.0, 0.96, 0.45), smoothstep(0.75, 1.4, err));\n\n    col = mix(decoded, errCol, errVis);\n\n    // Crisp 4x4 block boundary overlay & diagonal partition line if dual-subset active\n    float bEdge = smoothstep(0.035, 0.008, min(min(bLocal.x, 1.0 - bLocal.x), min(bLocal.y, 1.0 - bLocal.y)));\n    col = mix(col, vec3(0.04, 0.06, 0.10), bEdge * 0.42);\n    if (dualPart) {\n      float pLine = smoothstep(0.025, 0.005, abs(bLocal.x + bLocal.y - 1.0));\n      col = mix(col, vec3(0.95, 0.98, 1.0), pLine * 0.18);\n    }\n  }\n\n  float sep = smoothstep(0.0035, 0.0008, abs(screenX - split));\n  col = mix(col, vec3(0.95, 0.97, 1.0), sep);\n\n  fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);\n}",
   "execution_fidelity": "conceptual-diagram",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-30",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "block-texture-compression",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T19:53:25.000Z",
     "renderer": "Headless EGL Tesla T4/PCIe/SSE2, OpenGL 3.30 Core, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.6567,
      "std": 0.1408,
      "min": 0.3505,
      "max": 0.9014
     },
     "image": "/specimens/block-texture-compression-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "basis-universal-ktx2"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "basis-universal-ktx2",
   "why": "Supercompressed KTX2 transcodes at load time into BC7 or ASTC for the device."
  }
 ],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-29T15:51:27.588Z",
  "draft": "data/drafts/performance/block-texture-compression.json"
 },
 "solves": [
  "texture memory is too high on the gpu",
  "bandwidth bound from sampling big uncompressed textures",
  "need gpu-native compressed textures for fast sampling",
  "color banding or blockiness after compressing textures"
 ],
 "authority": "2014",
 "url": "https://texelatlas.vercel.app/t/block-texture-compression/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 18.14,
  "tier": "moderate",
  "p50_ms": 0.5623,
  "p95_ms": 0.5796,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 36,
  "preset_id": "block-texture-compression-live",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 15.28,
   "tier": "moderate",
   "p50_ms": 0.243,
   "p95_ms": 0.2456,
   "speedup_x": 2.31,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 11.72,
   "tier": "moderate",
   "p50_ms": 0.3375,
   "p95_ms": 0.3391,
   "speedup_x": 1.67,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}