Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
985e8c3
Fix mipmapCount check and Apply(updateMipmaps) for compressed ASTC te…
web-flow Nov 26, 2026
56644db
Clamp mipmap dimensions to at least 1 for non-square textures
web-flow Nov 26, 2026
9339924
Return null from CompressTexture when CompressImage or block size val…
web-flow Nov 26, 2026
e2861d7
Fix normal map flag conflict with UseAlphaWeight and BGRA normal swizzle
web-flow Nov 26, 2026
979b2ec
Use UIntPtr for size_t data_len in astcenc_compress_image P/Invoke
web-flow Nov 26, 2026
79391d9
Fix cross-platform P/Invoke bindings and Windows x64 plugin importer …
web-flow Nov 26, 2026
391977e
Eliminate per-pixel BitConverter GC allocations in pixel data writers
web-flow Nov 26, 2026
df9aba7
Add zero-copy fast path for 4-channel RGBA formats and pointer-based …
web-flow Nov 26, 2026
bef138e
Add reusable AstcContext, multi-threaded/async compression, and SelfD…
web-flow Nov 26, 2026
15ab871
Encode only mip level 0 in EncodeToASTC to comply with standard .astc…
web-flow Nov 26, 2026
9d6510b
Remove unmanaged allocation and finalizer overhead from AstcHeader
web-flow Nov 26, 2026
7ee9c2d
Add ARM-software/astc-encoder v5.7.1 as git submodule under ThirdPart…
Overflowu Nov 26, 2026
06a4a56
Add GitHub Actions workflow to cross-compile astc-encoder native plugins
Overflowu Nov 26, 2026
98cbfbf
Use macos-latest runner instead of retired macos-14
Overflowu Nov 26, 2026
8cc3a2c
Upgrade astc-encoder native plugins and C# NativeAPI bindings to v5.7.1
Overflowu Nov 26, 2026
35fa23d
Update README.md for astc-encoder v5.7.1, AstcContext, async/multi-th…
Overflowu Nov 26, 2026
c5987e3
Strip debug symbols from Android shared libraries in CI and prebuilt …
Overflowu Nov 26, 2026
bd04bb8
Move AstcContext.Create off the main thread in CompressTextureAsync
Overflowu Nov 26, 2026
836297c
Fix potential unmanaged memory leak on allocation failure in ImageExt…
Overflowu Nov 26, 2026
d39aa95
Add CancellationToken support to async compression using astcenc_comp…
Overflowu Nov 26, 2026
a585670
Bump package version to 2.0.0 in package.json
Overflowu Nov 26, 2026
b4631b1
Upgrade GitHub Actions versions to Node 24-ready releases
Overflowu Nov 26, 2026
f12876b
Move NativeAPI bindings into Aperture.Astcenc.Runtime.NativeAPI names…
Overflowu Nov 26, 2026
c88d716
Make UseAlphaWeight opt-in and set a_scale_radius=1 when enabled
Overflowu Nov 26, 2026
8f9965b
Preserve full 16-bit UNorm precision by feeding F32 data instead of F16
Overflowu Nov 26, 2026
578aafe
Expose AstcRaw.Length/CopyTo/ToArray and improve validation and error…
Overflowu Nov 26, 2026
a10279d
Clean up Sample.cs file writing, ImageExtensions visibility, and nami…
Overflowu Nov 26, 2026
c869423
Sync README.md with opt-in alpha weight, CancellationToken, F32 16-bi…
Overflowu Nov 26, 2026
e67f331
Add GPU Compute Shader ASTC compression backend with unified EncodeBa…
Overflowu Nov 26, 2026
089ddfc
Default EncodeBackend to Auto across all Encoder APIs
Overflowu Nov 26, 2026
0d7bb9f
Extract native CPU ASTC compression backend into AstcCpuBackend
Overflowu Nov 26, 2026
7772b23
Fix double-free when GPU async readback completes after cancellation
Overflowu Nov 26, 2026
fe5709a
Bind CommandBuffer encode temp RT lifetime to the command buffer
Overflowu Nov 26, 2026
43672c3
Handle sRGB-sourced Normal maps consistently in GPU and CPU backends
Overflowu Nov 26, 2026
38588ae
Compare sRGB-encoded min/max before void-extent constant block detection
Overflowu Nov 26, 2026
2923772
Report accurate CPU native library availability per platform
Overflowu Nov 26, 2026
986bbd0
Fall back to sync GPU readback when AsyncGPUReadback is unsupported
Overflowu Nov 26, 2026
b11da83
Reject depth, stencil, and integer formats in GPU backend input check
Overflowu Nov 26, 2026
d25ef1a
Reset GPU backend static shader cache on subsystem registration and quit
Overflowu Nov 26, 2026
1887ff9
Document vertical coordinate orientation convention for GPU encoding
Overflowu Nov 26, 2026
e4c34e4
Use persistentDataPath on device and clean up output texture in Sample
Overflowu Nov 26, 2026
4d854a5
Make AstcRaw.Dispose thread-safe with Interlocked.Exchange
Overflowu Nov 26, 2026
7802452
Harden ImageExtensions against 32-bit offset overflow and buffer leaks
Overflowu Nov 26, 2026
b6ecdfc
Validate source, mips, format, and block-aligned coords in GPU Encode
Overflowu Nov 26, 2026
bc9467c
Guard CompressToTexture and Compress against non-ASTC standalone GPUs
Overflowu Nov 26, 2026
23fbcbc
Batch 2-partition seed search 4-wide to cut HLSL texture fetches by 4x
Overflowu Nov 26, 2026
298d04b
Require isReadable for GPU in-place Compress and clarify documentation
Overflowu Nov 26, 2026
a629098
Skip GPU-only CopyTexture path in CompressInPlace when keeping textur…
Overflowu Nov 26, 2026
084e030
Reject partial mipmap chains in in-place Compress before Reinitialize
Overflowu Nov 26, 2026
8e6357c
Reject MSAA RenderTextures in GPU backend input check
Overflowu Nov 26, 2026
06ebd8d
Require CopyTextureSupport.RTToTexture and ASTC format support in GPU…
Overflowu Nov 26, 2026
148286a
Prevent Texture2D and ComputeBuffer leaks on exception paths
Overflowu Nov 26, 2026
ef86eb4
Sanitize non-finite and negative HDR values before Void-Extent scan
Overflowu Nov 26, 2026
dce3839
Reject signed normalized (SNorm) formats in GPU backend input check
Overflowu Nov 26, 2026
635e62c
Make AstcContext.Dispose thread-safe with Interlocked.Exchange
Overflowu Nov 26, 2026
695c408
Reuse CreateBlockRTDescriptor in GPU CompressInPlace
Overflowu Nov 26, 2026
fce0fd9
Initialize epCodes before inout calls in HLSL error evaluation helpers
Overflowu Nov 26, 2026
5bd6159
Use scalar sRGB conversion for Normal R/G channels in HLSL
Overflowu Nov 26, 2026
999bc40
Add bilingual English and Simplified Chinese README with language swi…
Overflowu Nov 26, 2026
73c5e9e
Upgrade GPU HLSL encoder with Fast-only kernels, CEM 11 HDR delta, dy…
Overflowu Nov 26, 2026
34e2215
Add astcenc decompression P/Invoke bindings and AstcHeader.TryParse
Overflowu Nov 26, 2026
95f6a04
Optimize CPU pixel transfer and async snapshots, add parentContext sh…
Overflowu Nov 26, 2026
a1c52b4
Harden GPU backend validation, dispatch Fast kernels, avoid LOH readb…
Overflowu Nov 26, 2026
9021268
Add AstcCompressOptions, CompressToTextureAsync, GetTargetAstcFormat,…
Overflowu Nov 26, 2026
ed92a4d
Ignore generated sample ASTC output, add package license metadata, an…
Overflowu Nov 26, 2026
d566fb0
Add GPU mipmap generation integrated with ASTC compression
Overflowu Nov 26, 2026
cf23cab
Add KTX v1 ASTC container and persistent disk cache
Overflowu Nov 26, 2026
d4687ee
Add Editor visual benchmark and quality inspector window
Overflowu Nov 26, 2026
c0b6209
Add on-chip packed pixel cache for <=6x6 LDR blocks in GPU shader
Overflowu Nov 26, 2026
bdf6d33
Add frame-budgeted AstcCompressionQueue with pooled AstcContext table…
Overflowu Nov 26, 2026
7f7e10a
Add Cubemap/Texture2DArray slice support and raw pixel compression APIs
Overflowu Nov 26, 2026
9c5d7db
Add optional Unity Job System (IJobParallelFor) scheduling for CPU co…
Overflowu Nov 26, 2026
11e4999
Add EditMode golden cross-decode and container unit test suite
Overflowu Nov 26, 2026
c318553
Add Linux x64, Windows AVX2, iOS XCFramework CI builds and shader/met…
Overflowu Nov 26, 2026
48240c0
Add CHANGELOG.md, bump package version to 2.3.0, and update bilingual…
Overflowu Nov 26, 2026
d93a08d
Fix astcenc.xcframework copy path in package-plugins CI job
Overflowu Nov 27, 2026
31adb80
Fix Cubemap constructor argument order to match Unity API
Overflowu Nov 27, 2026
f35028a
Fix parentContext use-after-free, post-await texture access, and Astc…
Overflowu Nov 27, 2026
13ac17b
Harden AstcKtxContainer.TryDecode against integer overflow and malfor…
Overflowu Nov 27, 2026
7fa84e5
Fix HDR readable copy and GGGR normal-map unpacking in AstcBenchmarkW…
Overflowu Nov 27, 2026
de61fdf
Fix NPOT odd-dimension mip filtering and guard HDR mip generation on …
Overflowu Nov 27, 2026
c2dfb35
Guard CompressRawPixelsAsync against 32-bit allocation overflow
Overflowu Nov 27, 2026
cef3c35
Use File.Replace for atomic disk cache writes and avoid redundant KTX…
Overflowu Nov 27, 2026
675dfeb
Validate decompression bitness/bounds, slice upper bounds, and preloa…
Overflowu Nov 27, 2026
4b2fb21
Reduce GPU shader VGPR footprint with per-block ASTC_MAX_GRID and add…
Overflowu Nov 27, 2026
8d4ad62
Use fast sqrt sRGB approximation and 8x4 threadgroups for >=8x8 GPU k…
Overflowu Nov 27, 2026
d7509ab
Add zero-readback GPU mipmap generation + ASTC encoding in single Com…
Overflowu Nov 27, 2026
7b0ed6e
Add Windows x64 runtime AVX2 dispatch with automatic SSE4.1 fallback
Overflowu Nov 27, 2026
33adada
Add zero-alloc CompressRawPixelsInto and batch GPU CommandBuffers in …
Overflowu Nov 27, 2026
2ab7a1f
Update bilingual READMEs with latest GPU/CPU optimizations and platfo…
Overflowu Nov 27, 2026
5d95735
Add automated ASTC performance benchmark suite and upgrade AstcBenchm…
web-flow Nov 27, 2026
5a5fdda
Enable GPU zero-readback CopyTexture path for non-multiple block dime…
Overflowu Nov 27, 2026
5284135
Hoist 2P hash, reuse same-grid weight projections, drop worst-channel…
Overflowu Nov 27, 2026
21fbbc2
Pool native AstcContext across all static CPU entry points and fix Co…
Overflowu Nov 27, 2026
c48a42f
Package Windows x64 astcenc-avx2-shared.dll and include it in commit_…
Overflowu Nov 27, 2026
2747b3a
Refactor bilingual READMEs and split API/Architecture into docs/
Overflowu Nov 27, 2026
e4bac74
Add multi-platform Unity CI build and E2E test pipeline (#3)
Overflowu Nov 28, 2026
195cdb2
Add automated GitHub Actions performance benchmark pipeline and READM…
web-flow Nov 28, 2026
a888fe1
Trigger performance benchmark workflow on ci/performance-benchmarks b…
web-flow Nov 28, 2026
31d2bb7
Fix Encoder ambiguity (CS0104) and NativeArray using var (CS1654) in …
Overflowu Nov 28, 2026
9edcc9c
Use macos-latest runner label instead of deprecated macos-14
Overflowu Nov 28, 2026
d3223a5
Fix Unity 2021.3 Metal reversebits shader compile bug, UTF-8 BOM pars…
Overflowu Nov 28, 2026
8532d0f
Populate hardware-verified benchmark results and baseline from CI run…
Overflowu Nov 28, 2026
3f65700
Merge ci/performance-benchmarks into develop
Overflowu Nov 28, 2026
ebd7f32
chore(ci): move root scripts directory to .github/scripts
web-flow Nov 28, 2026
f103494
chore(ci): make performance-benchmarks workflow manual-only
web-flow Nov 28, 2026
e8f0b60
fix(gpu): canonicalize endpoints and flip weights on swap in candidat…
Overflowu Nov 28, 2026
8cbff95
fix(gpu): recognize 16-bit half-float and UFloat HDR formats in GPU b…
Overflowu Nov 28, 2026
a818529
chore(ci,upm): move CIBuildScript out of UPM package and fix CI branc…
Overflowu Nov 28, 2026
5e8d51e
docs(release): update v2.3.0 changelog, UPM package metadata, and CI …
Overflowu Nov 28, 2026
39b7bb3
docs: align READMEs and API.md examples with current codebase
Overflowu Nov 28, 2026
6611cb1
chore(ci): make unity-multiplatform-e2e workflow manual-only
Overflowu Nov 28, 2026
d3d7fa7
chore(ci): make shader verification manual, exclude master from nativ…
Overflowu Nov 28, 2026
f9859fa
chore(upm): add root LICENSE, package README, and Samples~/BasicUsage
Overflowu Nov 28, 2026
e26e4ec
chore(upm): remove package-local README.md
Overflowu Nov 28, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
326 changes: 326 additions & 0 deletions .github/scripts/bench-native-cpu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,326 @@
#!/usr/bin/env python3
"""
Cross-platform zero-dependency native CPU ASTC benchmark runner (ctypes -> astc-encoder v5.7.1).
Works directly against the prebuilt Plugins/ binaries on Windows (SSE4.1 & AVX2), macOS (ARM64 NEON),
and Linux (SSE4.1 / AVX2), outputting structured JSON for CI summaries and README automation.
"""

import argparse
import concurrent.futures
import ctypes
import datetime
import json
import math
import os
import platform
import statistics
import subprocess
import time

ASTCENC_PRF_LDR = 1
ASTCENC_TYPE_U8 = 0
ASTCENC_FLG_DECOMPRESS_ONLY = 1 << 4
ASTCENC_FLG_SELF_DECOMPRESS_ONLY = 1 << 5


class AstcencSwizzle(ctypes.Structure):
_fields_ = [
("r", ctypes.c_int),
("g", ctypes.c_int),
("b", ctypes.c_int),
("a", ctypes.c_int),
]


class AstcencImage(ctypes.Structure):
_fields_ = [
("dim_x", ctypes.c_uint32),
("dim_y", ctypes.c_uint32),
("dim_z", ctypes.c_uint32),
("data_type", ctypes.c_int),
("data", ctypes.POINTER(ctypes.c_void_p)),
]


class AstcNativeLib:
def __init__(self, path: str):
self.path = path
self.lib = ctypes.CDLL(path)

self.config_init = self.lib.astcenc_config_init
self.config_init.argtypes = [
ctypes.c_int, ctypes.c_uint32, ctypes.c_uint32, ctypes.c_uint32,
ctypes.c_float, ctypes.c_uint32, ctypes.c_void_p,
]
self.config_init.restype = ctypes.c_int

self.context_alloc = self.lib.astcenc_context_alloc
self.context_alloc.argtypes = [
ctypes.c_void_p, ctypes.c_uint32, ctypes.POINTER(ctypes.c_void_p), ctypes.c_void_p,
]
self.context_alloc.restype = ctypes.c_int

self.compress_image = self.lib.astcenc_compress_image
self.compress_image.argtypes = [
ctypes.c_void_p, ctypes.POINTER(AstcencImage), ctypes.POINTER(AstcencSwizzle),
ctypes.c_void_p, ctypes.c_size_t, ctypes.c_uint32,
]
self.compress_image.restype = ctypes.c_int

self.compress_reset = self.lib.astcenc_compress_reset
self.compress_reset.argtypes = [ctypes.c_void_p]
self.compress_reset.restype = ctypes.c_int

self.decompress_image = self.lib.astcenc_decompress_image
self.decompress_image.argtypes = [
ctypes.c_void_p, ctypes.c_void_p, ctypes.c_size_t,
ctypes.POINTER(AstcencImage), ctypes.POINTER(AstcencSwizzle), ctypes.c_uint32,
]
self.decompress_image.restype = ctypes.c_int

self.decompress_reset = self.lib.astcenc_decompress_reset
self.decompress_reset.argtypes = [ctypes.c_void_p]
self.decompress_reset.restype = ctypes.c_int

self.context_free = self.lib.astcenc_context_free
self.context_free.argtypes = [ctypes.c_void_p]
self.context_free.restype = None


def create_procedural_rgba8(width: int, height: int) -> bytearray:
buf = bytearray(width * height * 4)
pi = math.pi
w_den = max(1, width - 1)
h_den = max(1, height - 1)
w_q = width // 4
h_q = height // 4
idx = 0
for y in range(height):
v = y / h_den
y_chk = y >> 3
for x in range(width):
if x < w_q and y < h_q:
buf[idx] = 96
buf[idx + 1] = 144
buf[idx + 2] = 192
buf[idx + 3] = 255
else:
u = x / w_den
wave = 0.5 + 0.5 * math.sin((u * 18.0 + v * 12.0) * pi)
chk = 0.15 if (((x >> 3) + y_chk) & 1) == 0 else -0.15
r = int(round((u * 0.7 + wave * 0.3 + chk) * 255.0))
g = int(round((v * 0.7 + (1.0 - wave) * 0.3 - chk) * 255.0))
b = int(round(((u + v) * 0.4 + wave * 0.2) * 255.0))
a = int(round((0.2 + 0.8 * abs(math.sin((u - v) * 4.0 * pi))) * 255.0))
buf[idx] = 0 if r < 0 else (255 if r > 255 else r)
buf[idx + 1] = 0 if g < 0 else (255 if g > 255 else g)
buf[idx + 2] = 0 if b < 0 else (255 if b > 255 else b)
buf[idx + 3] = 0 if a < 0 else (255 if a > 255 else a)
idx += 4
return buf


def detect_cpu_model() -> str:
sys_name = platform.system()
try:
if sys_name == "Darwin":
return subprocess.check_output(["sysctl", "-n", "machdep.cpu.brand_string"], text=True).strip()
if sys_name == "Linux":
with open("/proc/cpuinfo", "r", encoding="utf-8") as f:
for line in f:
if line.startswith("model name"):
return line.split(":", 1)[1].strip()
if sys_name == "Windows":
out = subprocess.check_output(
["powershell", "-NoProfile", "-Command", "(Get-CimInstance Win32_Processor).Name"],
text=True,
).strip()
if out:
return out
except Exception:
pass
return platform.processor() or platform.machine()


def measure_fn(warmup: int, iterations: int, total_pixels: int, fn):
for _ in range(warmup):
fn()
samples = []
for _ in range(iterations):
t0 = time.perf_counter()
fn()
t1 = time.perf_counter()
samples.append((t1 - t0) * 1000.0)
samples.sort()
median_ms = statistics.median(samples)
p95_idx = min(len(samples) - 1, max(0, math.ceil(len(samples) * 0.95) - 1))
mpix_s = ((total_pixels / 1e6) / (median_ms / 1000.0)) if median_ms > 1e-6 else 0.0
return {
"MinMs": round(samples[0], 3),
"MedianMs": round(median_ms, 3),
"MeanMs": round(sum(samples) / len(samples), 3),
"P95Ms": round(samples[p95_idx], 3),
"MaxMs": round(samples[-1], 3),
"ThroughputMPixPerSec": round(mpix_s, 3),
}


def run_lib_benchmarks(lib_path: str, isa_label: str, width: int, height: int, rgba_buf: bytearray, threads: int, warmup: int, iterations: int):
api = AstcNativeLib(lib_path)
src_arr = (ctypes.c_uint8 * len(rgba_buf)).from_buffer(rgba_buf)
src_ptr = ctypes.c_void_p(ctypes.addressof(src_arr))
slices = (ctypes.c_void_p * 1)(src_ptr)
swz = AstcencSwizzle(0, 1, 2, 3)

blocks = [("ASTC_4x4", 4), ("ASTC_6x6", 6), ("ASTC_8x8", 8), ("ASTC_12x12", 12)]
qualities = [("Fast", 10.0), ("Medium", 60.0)]
results = []

with concurrent.futures.ThreadPoolExecutor(max_workers=threads) as pool:
for bs_name, dim in blocks:
out_len = ((width + dim - 1) // dim) * ((height + dim - 1) // dim) * 16
out_buf = (ctypes.c_uint8 * out_len)()
out_ptr = ctypes.c_void_p(ctypes.addressof(out_buf))

for q_name, q_val in qualities:
cfg = ctypes.create_string_buffer(256)
rc = api.config_init(ASTCENC_PRF_LDR, dim, dim, 1, q_val, ASTCENC_FLG_SELF_DECOMPRESS_ONLY, cfg)
if rc != 0:
raise RuntimeError(f"astcenc_config_init failed ({rc}) for {bs_name} {q_name}")

ctx = ctypes.c_void_p()
rc = api.context_alloc(cfg, threads, ctypes.byref(ctx), None)
if rc != 0:
raise RuntimeError(f"astcenc_context_alloc failed ({rc}) for {bs_name} {q_name}")

try:
def do_compress():
if threads <= 1:
img = AstcencImage(width, height, 1, ASTCENC_TYPE_U8, slices)
api.compress_image(ctx, ctypes.byref(img), ctypes.byref(swz), out_ptr, out_len, 0)
else:
futs = []
for t in range(threads):
def worker(ti=t):
img = AstcencImage(width, height, 1, ASTCENC_TYPE_U8, slices)
api.compress_image(ctx, ctypes.byref(img), ctypes.byref(swz), out_ptr, out_len, ti)
futs.append(pool.submit(worker))
for f in futs:
f.result()
api.compress_reset(ctx)

st = measure_fn(warmup, iterations, width * height, do_compress)
results.append({
"Name": f"Native_{isa_label}_{width}_{bs_name}_{q_name}_{threads}T",
"Category": "Native_CPU",
"ISA": isa_label,
"Resolution": f"{width}x{height}",
"BlockSize": bs_name,
"Quality": q_name,
"Threads": threads,
"OutputBytes": out_len,
**st,
})
finally:
api.context_free(ctx)

# Decompression benchmark on ASTC_6x6
dim = 6
out_len = ((width + dim - 1) // dim) * ((height + dim - 1) // dim) * 16
out_buf = (ctypes.c_uint8 * out_len)()
out_ptr = ctypes.c_void_p(ctypes.addressof(out_buf))
dec_buf = (ctypes.c_uint8 * (width * height * 4))()
dec_slices = (ctypes.c_void_p * 1)(ctypes.c_void_p(ctypes.addressof(dec_buf)))

cfg = ctypes.create_string_buffer(256)
api.config_init(ASTCENC_PRF_LDR, dim, dim, 1, 10.0, ASTCENC_FLG_SELF_DECOMPRESS_ONLY, cfg)
cctx = ctypes.c_void_p()
api.context_alloc(cfg, threads, ctypes.byref(cctx), None)
img = AstcencImage(width, height, 1, ASTCENC_TYPE_U8, slices)
api.compress_image(cctx, ctypes.byref(img), ctypes.byref(swz), out_ptr, out_len, 0)
api.context_free(cctx)

dcfg = ctypes.create_string_buffer(256)
api.config_init(ASTCENC_PRF_LDR, dim, dim, 1, 0.0, ASTCENC_FLG_DECOMPRESS_ONLY, dcfg)
dctx = ctypes.c_void_p()
api.context_alloc(dcfg, threads, ctypes.byref(dctx), None)
try:
def do_decompress():
if threads <= 1:
dimg = AstcencImage(width, height, 1, ASTCENC_TYPE_U8, dec_slices)
api.decompress_image(dctx, out_ptr, out_len, ctypes.byref(dimg), ctypes.byref(swz), 0)
else:
futs = []
for t in range(threads):
def worker(ti=t):
dimg = AstcencImage(width, height, 1, ASTCENC_TYPE_U8, dec_slices)
api.decompress_image(dctx, out_ptr, out_len, ctypes.byref(dimg), ctypes.byref(swz), ti)
futs.append(pool.submit(worker))
for f in futs:
f.result()
api.decompress_reset(dctx)

st = measure_fn(warmup, max(iterations, 7), width * height, do_decompress)
results.append({
"Name": f"Native_{isa_label}_Decompress_{width}_ASTC_6x6_{threads}T",
"Category": "Native_CPU_Decompress",
"ISA": isa_label,
"Resolution": f"{width}x{height}",
"BlockSize": "ASTC_6x6",
"Quality": "N/A",
"Threads": threads,
"OutputBytes": width * height * 4,
**st,
})
finally:
api.context_free(dctx)

return results


def main():
parser = argparse.ArgumentParser(description="Native CPU astc-encoder benchmark runner")
parser.add_argument("--lib", action="append", required=True, help="ISA=PATH pair (e.g. AVX2=path/to/dll)")
parser.add_argument("--size", type=int, default=512, help="Square test texture dimension (default: 512)")
parser.add_argument("--threads", type=int, default=0, help="Worker thread count (0 = auto min(cores, 4))")
parser.add_argument("--warmup", type=int, default=1)
parser.add_argument("--iterations", type=int, default=5)
parser.add_argument("--out", required=True, help="Output JSON report path")
args = parser.parse_args()

cores = os.cpu_count() or 1
threads = args.threads if args.threads > 0 else max(1, min(cores, 4))
rgba = create_procedural_rgba8(args.size, args.size)

report = {
"SchemaVersion": "1.0",
"TimestampUtc": datetime.datetime.now(datetime.timezone.utc).isoformat(),
"GitCommit": os.environ.get("GITHUB_SHA", ""),
"Platform": f"{platform.system()} {platform.machine()}",
"CpuModel": detect_cpu_model(),
"CpuCores": cores,
"ThreadsUsed": threads,
"Results": [],
}

for spec in args.lib:
if "=" not in spec:
raise ValueError(f"--lib expects ISA=PATH, got: {spec}")
isa, path = spec.split("=", 1)
if not os.path.exists(path):
raise FileNotFoundError(f"Native library not found: {path}")
print(f"[bench-native-cpu] Running {isa} ({path}) with {threads} threads on {args.size}x{args.size}...")
report["Results"].extend(
run_lib_benchmarks(path, isa, args.size, args.size, rgba, threads, args.warmup, args.iterations)
)

out_dir = os.path.dirname(os.path.abspath(args.out))
if out_dir:
os.makedirs(out_dir, exist_ok=True)
with open(args.out, "w", encoding="utf-8") as f:
json.dump(report, f, indent=2)
print(f"[bench-native-cpu] Wrote {len(report['Results'])} results to {args.out}")


if __name__ == "__main__":
main()
Loading
Loading