From 26e7067f61a7850ab5bcea68943fdbf702c7a4f8 Mon Sep 17 00:00:00 2001 From: Peter Harris Date: Tue, 17 Nov 2026 23:47:09 +0000 Subject: [PATCH 1/2] Changelog cleanup --- Docs/ChangeLog-6x.md | 93 +++++++++++++++--------------- Source/astcenc_lz_optimize.cpp | 1 + Test/astc_profile_report.py | 102 +++++++++++++++++++++++---------- 3 files changed, 122 insertions(+), 74 deletions(-) diff --git a/Docs/ChangeLog-6x.md b/Docs/ChangeLog-6x.md index b0af52995..60514776b 100644 --- a/Docs/ChangeLog-6x.md +++ b/Docs/ChangeLog-6x.md @@ -11,8 +11,13 @@ at 3.9 GHz, running `astcenc` using AVX2 and 12 threads. **Status:** In development. -The 6.0.0 release is a major release, adding support for AVX-512 and making -significant performance optimizations to all of the ISA variants. +The 6.0.0 release is a major release, adding support for Rate-Distortion +Optimization (RDO) to both CLI and library, and support for AVX-512 as a +library backend. There is also significant performance uplifit across all +backends, and numerous small improvements to image quality and stability. + +Thank you to Epic Games for the contribution of the LZ RDO implementation, and +to AMD for the contribution of the AVX-512 backend. This release includes changes to the public interface in the `astcenc.h` header. We always recommend rebuilding your client-side code using the @@ -23,23 +28,29 @@ header from the same release to avoid compatibility issues. and decompression output. A zero stride selects tightly packed rows. * **API Change:** Use `size_t` for image dimensions, context thread counts, and thread indices in the library API. + * **API Change:** Add support for rate-distortion optimization to reduce + size of bundled ASTC texture assets. Enable by setting the config flag + `ASTCENC_FLG_USE_LZ_RDO` and setting the appropriate `lz_rdo_lambda` + level (0 = no RDO, 20 = light RDO, 40 = moderate RDO ...). * **API Change:** Decompressing images containing invalid encodings, or HDR encodings in an LDR profile, now return an identifiable `ASTCENC_ERR_BAD_BLOCK` return code. The image will still be decompressed, - using the specified error color for the format in use for the bad blocks. - The command line tool will write the image, emit a warning, and exit with - code 2 for these failures. Functional errors continue to use exit code 1. - * **CLI Change:** Writing to an LDR output file format, such as PNG, when - testing HDR input is now supported. The tool will output multiple files, - one for each active integer f-stop exposure level. + using the specified block error color for the ASTC profile in use. The + command line tool will write the image, emit a warning, and exit with code + 2 for these failures. Functional errors continue to use exit code 1. + * **CLI Change:** Add support for rate-distortion optimization to reduce + size of bundled ASTC texture assets. Enable by passing the `-rdo-lambda` + command line option. See API Change above for details. * **Feature:** Add an AVX-512 SIMD backend to the library, with a corresponding command line tool variant operating on 512-bit vectors. AVX-512 performance can be slower than AVX2 for smaller block sizes. - * **Change:** Require C++20 to build the codec, replacing local library + * **Build Change:** AVX2 builds now also require BMI and BMI2. + functions with new standard library operations where possible. + * **Build Change:** Require C++20 to build the codec, replacing local library functions with new standard library operations where possible. - * **Change:** Minimum supported compiler versions increased to Clang 18, GCC - 13, and Visual Studio 2022. Minimum supported CMake version increased to - 3.21. + * **Build Change:** Minimum supported compiler versions increased to Clang + 18, GCC 13, and Visual Studio 2022. Minimum supported CMake version + increased to 3.21. * **Codec library updates:** * **Bug fix:** Disable dual-plane encoding at a zero correlation cutoff. * **Bug fix:** Preserve HDR endpoint mode bits when quantization rounds down @@ -47,73 +58,65 @@ header from the same release to avoid compatibility issues. * **Bug fix:** Wait for outstanding tasks to finish before releasing shared buffers when compression is cancelled. * **Bug fix:** Remove a data race when reporting compression progress. - * **Bug fix:** Remove data races when initializing configurations and - allocating contexts concurrently. + * **Bug fix:** Remove incorrectly shared data that could cause concurrently + initializing contexts to use an incorrect configuration. * **Bug fix:** Preserve the error threshold inherited by child contexts, avoiding a second conversion from dB. * **Image quality:** Reduce visible HDR artifacts with perceptual mode enabled by weighting logarithmic channel errors according to geomean of channel brightness. - * **Optimization:** Hoist loop invariant weight diff calculation out of the - `compute_ideal_weights_for_decimation()` refinement loop. - * **Optimization:** Precompute an infilled weight set for the realign loop - in `realign_weights_decimated()`, rebuilding set entries if a decimated - weight changes, rather than always recomputing the infilled value every - loop iteration. + * **Optimization:** Restructuture partition candidate selection by processing + multiple candidates in parallel on wider vector hardware, one candidate for + every 128-bits in the available SIMD vectors. This significantly improves + performance on 256-bit and 512-bit vector hardware. + * **Optimization:** Specialize a simpler partition candidate selection for + luminance-only blocks, as we know that direction is always through the + origin. + * **Optimization:** Specialize many data paths for luminance+alpha data, + which is commonly used for normal maps. * **Optimization:** Use analytical calculation of weight change error diffs in `realign_weights_decimated()` and `realign_weights_undecimated()`. Changes compute simpler linear and quadratic error coefficients, and then compute the up and down candidate deltas. - * **Optimization:** Hoist loop invariant channel weight out of loop in - `realign_weights_decimated()`. - * **Optimization:** Use analytical calculation of moments in - `recompute_ideal_colors_1plane()` after the loop, reducing the amount of - calculation in the loop. + * **Optimization:** Precompute an infilled weight set for the realign loop + in `realign_weights_decimated()`, rebuilding set entries if a decimated + weight changes, rather than always recomputing the infilled value every + loop iteration. * **Optimization:** Reuse RGB partition metrics computed during ideal weight generation when selecting endpoint formats, avoiding a duplicate texel scan. - * **Optimization:** Reuse RGB partition metrics from grayscale RGBA statistics - during single-plane endpoint selection, improving normal map compression - performance. * **Optimization:** Skip RGB+lumashift endpoint error calculations for LDR blocks, as this encoding is only available for HDR. * **Optimization:** Interpolate deltas in `lerp_color_int()` and unrolled specialization, saving one multiply. - * **Optimization:** Hoist loop invariant error accumulator calculation out of - deeper nested `..._find_best_combination...()` selector loops. * **Optimization:** Directly copy non-decimated weight grids when unpacking symbolic blocks, avoiding redundant interpolation. - * **Optimization:** Specialize `compute_avgs_and_dirs_4_comp()` for blocks - with identical `RGB` components, skipping duplicate `GB` calculations. - This significantly improves normal map compression performance. * **Optimization:** Use SoA-style SIMD batches for k-means cluster assignment. - * **Optimization:** Batch partition candidate ranking for RGB and RRRA, - improving performance for wider SIMD vector hardware. - * **Optimization:** Specialize `compute_partition_averages_rgba()` for blocks - with identical `RGB` components, skipping duplicate `GB` calculations. - This significantly improves normal map compression performance. - * **Optimization:** Specialize RGBA partition-error scoring for blocks with - identical `RGB` components, reusing channel gathers, projection products, - and residual calculations while preserving channel weights and error sums. - * **Optimization:** Specialize endpoint refitting for LDR blocks with - identical `RGB` components and zero requested `GB` weights, fitting only `R` - and `A`. This improves normal map compression performance. * **Optimization:** Avoid constructing three- and four-partition endpoint-format combinations that exceed the allowed endpoint integer limit. * **Optimization:** Split multi-partition endpoint-format searches by quantization level to skip unreachable high-precision combinations. + * **Optimization:** Specialize ISE decoding at compile-time into functions + per quant level to help with RDO performance. + * **Optimization:** Optimized implementaiton of unorm16_to_sf16 to help with + RDO performance. * **Optimization:** Use NEON combined shift-and-insert for byte packing in `interleave_rgba8()`. * **Optimization:** Use SVE narrowing stores in the 4-wide implementation of `pack_and_store_low_bytes()`. * **Command line tool updates:** + * **CLI Change:** Writing to an LDR output file format, such as PNG, when + test compressing an HDR image is now supported. The tool will output + multiple files, one for each active integer f-stop exposure level. * **Feature:** Report SSIM for LDR images and exposure-averaged mSSIM for HDR images in test mode. HDR exposures follow the `-mpsnr` range. + * **Feature:** Report DEFLATE compression when using RDO. Note - requires + CLI to be built with zlib and is not enabled in our release binaries. * **Change:** Automatically center HDR image quality metric exposures on the original image's geometric mean luminance, covering two stops either side. An explicit `-mpsnr` range overrides automatic exposure selection. * **Feature:** Add crop region support for compression. Crop regions are - extracted using image coordinate space before flipping or preprocessing. + extracted in the image coordinate space before flipping or preprocessing. * **Build system updates:** * **Bug fix:** Restore Clang compression performance by disabling unintended floating-point trapping, retaining precise arithmetic and the configured diff --git a/Source/astcenc_lz_optimize.cpp b/Source/astcenc_lz_optimize.cpp index ff5d3aed1..be2a4748e 100644 --- a/Source/astcenc_lz_optimize.cpp +++ b/Source/astcenc_lz_optimize.cpp @@ -1,6 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 // ---------------------------------------------------------------------------- // Copyright 2026 Epic Games, Inc. All Rights Reserved. +// Copyright 2026 Arm Limited // // Licensed under the Apache License, Version 2.0 (the "License"); you may not // use this file except in compliance with the License. You may obtain a copy diff --git a/Test/astc_profile_report.py b/Test/astc_profile_report.py index 10fa0c275..12f393156 100755 --- a/Test/astc_profile_report.py +++ b/Test/astc_profile_report.py @@ -16,7 +16,7 @@ # under the License. # ----------------------------------------------------------------------------- ''' -Benchmark three astcenc binaries and plot RGB, normal-map, and HDR throughput. +Benchmark three astcenc binaries and plot luminance, RGB, RGBA, normal-map, and HDR throughput. Requires Python 3.10 or newer and the packages in requirements.txt. Shared profiling helpers live in testlib beside this script. The report layout does not depend on an external template. @@ -25,13 +25,14 @@ python3 Test/astc_profile_report.py ./release-avx2 ./main-avx2 ./main-avx512 -Default images are the KodakMnt RGB and normal montages and HDRIHaven Canarywharf, under Images -beside this script. Use --rgb-image, --normal-image, and --hdr-image when copying the script -elsewhere with testlib. The HDR input is a Radiance .hdr image. Binaries can be paths or commands -on PATH. Use matched build options and give the script exclusive use of the machine during +Default images are the KodakMnt luminance, RGB, correlated-alpha RGBA, non-correlated-alpha RGBA, +and normal montages and HDRIHaven Canarywharf, under Images beside this script. Use --l-image, +--rgb-image, --rgba-ca-image, --rgba-nca-image, --normal-image, and --hdr-image when copying the +script elsewhere with testlib. The HDR input is a Radiance .hdr image. Binaries can be paths or +commands on PATH. Use matched build options and give the script exclusive use of the machine during measurement. -Runs 4x4, 6x6, and 8x8 at -thorough, -medium, and -fast for all three images. Each case has one +Runs 4x4, 6x6, and 8x8 at -thorough, -medium, and -fast for every image. Each case has one warmup and at most ten measured rounds, with 12 codec threads. Early stopping requires half the requested rounds, rounded up and capped at four, with at least two rounds for statistics. Then stop a case when every binary's 95% timing confidence interval has a half-width within 1% of its mean. @@ -41,11 +42,12 @@ -3 to +1 f-stop window across binary versions, matching the current compressor's automatic exposure for Canarywharf. -Writes report.md, report.json, six {rgb,nml,hdr}-{perf_abs,perf_rel}.png files, and three -{rgb,nml,hdr}-qual.png files in the output directory. Each quality -plot shows signed B-A changes for baseline versus new AVX2 in two metric panels: -PSNR and SSIM for RGB, PSNR and mean angular error for normals, and mPSNR and mSSIM for HDR. Metrics -missing from older binaries are marked unavailable. The default output directory is +Writes report.md, report.json, and per-image plots named +{l,rgb,rgba-ca,rgba-nca,nml,hdr}-{perf_abs,perf_rel,qual}.png in the output directory. +Each quality plot shows signed B-A changes for baseline versus new AVX2 in up to two metric panels: +PSNR and SSIM for luminance, RGB, and RGBA, PSNR and mean angular error for normals, and mPSNR and +mSSIM for HDR. SSIM panels are omitted when the baseline reports no SSIM measurements. Other missing +metrics are marked unavailable. The default output directory is x_profiles/report-YYMMDD-HH.MM. Existing files with these names are overwritten. Tables report coding seconds; plots report MTex/s or throughput relative to A = 100%. Throughput is image texels divided by the unrounded mean coding time. Warmups are excluded from means. There is no checkpoint @@ -55,6 +57,7 @@ import argparse from dataclasses import asdict from datetime import datetime +from functools import partial import json from pathlib import Path import platform @@ -83,14 +86,21 @@ ) SCENARIOS = [(block, preset) for block in ('4x4', '6x6', '8x8') for preset in ('-thorough', '-medium', '-fast')] -QUALITY = ('PSNR (LDR-RGB)', 'SSIM (LDR-RGB)', 'Mean Angular Error', +QUALITY = ('PSNR (LDR-RGB)', 'SSIM (LDR-RGB)', 'PSNR (LDR-RGBA)', 'SSIM (LDR-RGBA)', + 'Mean Angular Error', 'Worst Angular Error', 'mPSNR (RGB)', 'mSSIM (RGB)') HDR_FSTOPS = (-3, 1) CONFIDENCE = 0.95 PRECISION = 0.01 QUALITY_PLOTS = { + 'L': (('PSNR (LDR-RGB)', 'PSNR', 'dB', 'higher'), + ('SSIM (LDR-RGB)', 'SSIM', '', 'higher')), 'RGB': (('PSNR (LDR-RGB)', 'PSNR', 'dB', 'higher'), ('SSIM (LDR-RGB)', 'SSIM', '', 'higher')), + 'RGBA-CA': (('PSNR (LDR-RGBA)', 'PSNR', 'dB', 'higher'), + ('SSIM (LDR-RGBA)', 'SSIM', '', 'higher')), + 'RGBA-NCA': (('PSNR (LDR-RGBA)', 'PSNR', 'dB', 'higher'), + ('SSIM (LDR-RGBA)', 'SSIM', '', 'higher')), 'Normal': (('PSNR (LDR-RGB)', 'PSNR', 'dB', 'higher'), ('Mean Angular Error', 'Mean angular error', 'degrees', 'lower')), 'HDR': (('mPSNR (RGB)', 'mPSNR', 'dB', 'higher'), @@ -171,13 +181,14 @@ def image_size(path: Path) -> tuple[int, int]: return width, height -def run_codec(binary: str, arguments: list[str]) -> CodecResult: +def run_codec(binary: str, arguments: list[str], image: str) -> CodecResult: ''' Run the shared codec reader and require the metrics used by this report. Args: binary: The executable path. arguments: The codec command-line arguments. + image: The report image role selecting the required quality metrics. Return: The coding time and available report quality metrics. @@ -186,12 +197,9 @@ def run_codec(binary: str, arguments: list[str]) -> CodecResult: ValueError: A required report metric is missing. ''' result = execute_codec(binary, arguments) - required = ['PSNR (LDR-RGB)'] + required = [QUALITY_PLOTS[image][0][0]] - if arguments[0] in ('-th', '-tH'): - required = ['mPSNR (RGB)'] - - if '-normal' in arguments: + if image == 'Normal': required.append('Mean Angular Error') # Required metrics fail immediately; optional metrics remain unavailable on older binaries @@ -204,13 +212,14 @@ def run_codec(binary: str, arguments: list[str]) -> CodecResult: return CodecResult(time=result.time, quality=quality) -def measure_case(binaries: dict[str, Any], args: list[str], runs: int, warmups: int, +def measure_case(binaries: dict[str, Any], image: str, args: list[str], runs: int, warmups: int, confidence: float, precision: float) -> dict[str, Any]: ''' Collect one scenario using shared serial precision sampling. Args: binaries: Binary paths and identities keyed by role. + image: The report image role selecting the required quality metrics. args: The codec arguments shared by all binaries. runs: The maximum number of measured rounds. warmups: The number of excluded warmup rounds. @@ -222,7 +231,7 @@ def measure_case(binaries: dict[str, Any], args: list[str], runs: int, warmups: ''' paths = {name: binaries[name]['path'] for name in BINARY_NAMES} samples = collect_precision_samples(paths, args, runs, warmups, confidence, precision, - run_codec) + partial(run_codec, image=image)) return asdict(samples) @@ -291,7 +300,8 @@ def collect_samples(binaries: dict[str, Any], images: dict[str, Any], key = f'{image}-{block}-{preset.removeprefix("-")}' args = codec_args(image, meta['path'], Path(tmp) / 'output', block, preset, threads) print(f'Case {len(cases) + 1}/{total}: {key}', flush=True) - cases[key] = measure_case(binaries, args, runs, warmups, confidence, precision) + cases[key] = measure_case(binaries, image, args, runs, warmups, + confidence, precision) return cases @@ -414,7 +424,7 @@ def timing_rows(data: dict[str, Any], image: str, a: str, b: str) -> list[str]: def write_report(out_dir: Path, data: dict[str, Any]) -> None: ''' - Write nine comparison tables and their measurement provenance. + Write comparison tables and their measurement provenance. Args: out_dir: The directory containing the report artifacts. @@ -492,7 +502,7 @@ def new_figure(size: tuple[int, int], panels: int) -> tuple[Any, Any]: figure = Figure(figsize=size, facecolor=BACKGROUND_COLOR) FigureCanvasAgg(figure) - return figure, figure.subplots(panels, 1) + return figure, figure.subplots(panels, 1, squeeze=False)[:, 0] def perf_rates(data: dict[str, Any], image: str, pair: tuple[str, str], @@ -581,7 +591,7 @@ def plot_perf_panel(ax: Any, data: dict[str, Any], image: str, pair: tuple[str, def plot_charts(out_dir: Path, data: dict[str, Any]) -> None: ''' - Write RGB, normal-map, and HDR absolute and relative throughput plots. + Write absolute and relative throughput plots for every image. Args: out_dir: The directory containing the report artifacts. @@ -728,7 +738,7 @@ def plot_quality_panel(ax: Any, data: dict[str, Any], image: str, def plot_quality_changes(out_dir: Path, data: dict[str, Any]) -> None: ''' - Plot two signed quality changes for baseline versus new AVX2. + Plot signed quality changes for baseline versus new AVX2. Args: out_dir: The directory containing the report artifacts. @@ -742,15 +752,34 @@ def plot_quality_changes(out_dir: Path, data: dict[str, Any]) -> None: if tag == 'normal': tag = 'nml' - figure, axes = new_figure((14, 11), 2) - figure.subplots_adjust(left=0.09, right=0.985, bottom=0.08, top=0.85, hspace=0.65) + metrics = [] + + for info in QUALITY_PLOTS[image]: + metric = info[0] + if 'SSIM' in metric: + is_baseline_ssim_available = any( + mean_quality(data['cases'][f'{image}-{block}-{preset.removeprefix("-")}'], + SETS[0][0], metric) is not None + for block, preset in SCENARIOS) + + if not is_baseline_ssim_available: + continue + + metrics.append(info) + + # Preserve room for titles and legends when the SSIM panel is omitted + height = 5 * len(metrics) + 1 + figure, axes = new_figure((14, height), len(metrics)) + figure.subplots_adjust(left=0.09, right=0.985, bottom=0.88 / height, + top=1.0 - 1.65 / height, hspace=0.65) title = metadata['title'] figure.suptitle(f'{title} | quality change vs baseline', fontsize=22, y=0.985, fontweight='bold') - figure.text(0.5, 0.93, 'Signed B − A differences; baseline A = 0 | ' + thresholds, + figure.text(0.5, 1.0 - 0.77 / height, + 'Signed B − A differences; baseline A = 0 | ' + thresholds, ha='center') - for ax, info in zip(axes, QUALITY_PLOTS[image]): + for ax, info in zip(axes, metrics): plot_quality_panel(ax, data, image, info) output = out_dir / f'{tag}-qual.png' @@ -771,7 +800,10 @@ def describe_images(args: argparse.Namespace) -> dict[str, Any]: hdr_name = args.hdr_image.stem.removeprefix('hdr-rgb-').capitalize() images = [ + ('L', 'Kodak Luminance', args.l_image), ('RGB', 'Kodak RGB', args.rgb_image), + ('RGBA-CA', 'Kodak RGBA (correlated alpha)', args.rgba_ca_image), + ('RGBA-NCA', 'Kodak RGBA (non-correlated alpha)', args.rgba_nca_image), ('Normal', 'Kodak Normal', args.normal_image), ('HDR', f'{hdr_name} HDR', args.hdr_image) ] @@ -838,10 +870,22 @@ def parse_command_line() -> argparse.Namespace: images = Path(__file__).resolve().parent / 'Images' kodak = images / 'KodakMnt' + parser.add_argument( + '--l-image', type=Path, default=kodak / 'LDR-L/ldr-l-montage.png', + help='luminance image (default: Kodak L Montage)') + parser.add_argument( '--rgb-image', type=Path, default=kodak / 'LDR-RGB/ldr-rgb-montage.png', help='RGB image (default: Kodak RGB Montage)') + parser.add_argument( + '--rgba-ca-image', type=Path, default=kodak / 'LDR-RGBA/ldr-rgba-montage+ca.png', + help='RGBA image with correlated alpha (default: Kodak RGBA CA Montage)') + + parser.add_argument( + '--rgba-nca-image', type=Path, default=kodak / 'LDR-RGBA/ldr-rgba-montage+nca.png', + help='RGBA image with non-correlated alpha (default: Kodak RGBA NCA Montage)') + parser.add_argument( '--normal-image', type=Path, default=kodak / 'LDR-XY/ldr-xy-montage.png', help='XY image (default: Kodak XY Montage)') From 05bab73c93a09806d2cd9ac0245683a11385e228 Mon Sep 17 00:00:00 2001 From: Peter Harris Date: Wed, 18 Nov 2026 00:07:53 +0000 Subject: [PATCH 2/2] More cleanup --- README.md | 3 +- Test/astc_profile_report.py | 64 ++++++++++++++++++++++++++++++++++--- 2 files changed, 61 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 8e8dbda39..7564d6c23 100644 --- a/README.md +++ b/README.md @@ -109,8 +109,7 @@ Support is provided for three architecture slices: We recommend using the latest stable release tag for production development. The `main` branch is an active development branch for the compressor. It is -currently a development branch for the new 6.x major release series, and -subject to breaking API changes. +currently the development branch for the 6.x major release series. The `5.x` and `4.x` branches are stable support branches for older release series. They are no longer under active development, but continue to get bug diff --git a/Test/astc_profile_report.py b/Test/astc_profile_report.py index 12f393156..05d07eab2 100755 --- a/Test/astc_profile_report.py +++ b/Test/astc_profile_report.py @@ -15,6 +15,7 @@ # License for the specific language governing permissions and limitations # under the License. # ----------------------------------------------------------------------------- +# pylint: disable=too-many-lines ''' Benchmark three astcenc binaries and plot luminance, RGB, RGBA, normal-map, and HDR throughput. @@ -44,6 +45,8 @@ Writes report.md, report.json, and per-image plots named {l,rgb,rgba-ca,rgba-nca,nml,hdr}-{perf_abs,perf_rel,qual}.png in the output directory. +Summary plots named summary-{avx2,avx512}-{perf_abs,perf_rel}.png compare the baseline AVX2 with +each latest binary, stacking image types in channel-count order. Each quality plot shows signed B-A changes for baseline versus new AVX2 in up to two metric panels: PSNR and SSIM for luminance, RGB, and RGBA, PSNR and mean angular error for normals, and mPSNR and mSSIM for HDR. SSIM panels are omitted when the baseline reports no SSIM measurements. Other missing @@ -51,7 +54,7 @@ x_profiles/report-YYMMDD-HH.MM. Existing files with these names are overwritten. Tables report coding seconds; plots report MTex/s or throughput relative to A = 100%. Throughput is image texels divided by the unrounded mean coding time. Warmups are excluded from means. There is no checkpoint -or resume support. +or resume support. All plots are 800 pixels wide, preserving their aspect ratios. ''' import argparse @@ -92,6 +95,15 @@ HDR_FSTOPS = (-3, 1) CONFIDENCE = 0.95 PRECISION = 0.01 +PLOT_WIDTH = 800 +IMAGE_CHANNEL_COUNTS = { + 'L': 1, + 'Normal': 2, # Two independent components encoded as RRRA + 'RGB': 3, + 'HDR': 3, + 'RGBA-CA': 4, + 'RGBA-NCA': 4, +} QUALITY_PLOTS = { 'L': (('PSNR (LDR-RGB)', 'PSNR', 'dB', 'higher'), ('SSIM (LDR-RGB)', 'SSIM', '', 'higher')), @@ -482,7 +494,7 @@ def add_comparison_legend(ax: Any, a: str, b: str, is_change: bool = False) -> N title=f'A: {BINARY_NAMES[a]} | B: {BINARY_NAMES[b]}') -def new_figure(size: tuple[int, int], panels: int) -> tuple[Any, Any]: +def new_figure(size: tuple[float, float], panels: int) -> tuple[Any, Any]: ''' Create a figure with vertically stacked panels and a headless rendering canvas. @@ -624,7 +636,50 @@ def plot_charts(out_dir: Path, data: dict[str, Any]) -> None: plot_perf_panel(axes[index], data, image, pair, is_relative) output = out_dir / f'{tag}-{suffix}.png' - figure.savefig(output, dpi=180) + figure.savefig(output, dpi=PLOT_WIDTH / figure.get_figwidth()) + print(f'Wrote {output}', flush=True) + + +def plot_summary_charts(out_dir: Path, data: dict[str, Any]) -> None: + ''' + Compare baseline AVX2 with each latest binary using stacked images and a shared legend. + + Args: + out_dir: The directory containing the report artifacts. + data: The settings, dimensions, and measurements. + ''' + images = sorted(data['images'], key=IMAGE_CHANNEL_COUNTS.__getitem__) + thresholds = sampling_threshold_text(data) + + for pair in SETS[:2]: + a, b = pair + + for is_relative in (False, True): + suffix = 'perf_abs' + scale = 'absolute' + + if is_relative: + suffix = 'perf_rel' + scale = 'relative' + + height = 3.75 * len(images) + figure, axes = new_figure((14, height), len(images)) + figure.subplots_adjust(left=0.075, right=0.985, bottom=1.125 / height, + top=1.0 - 1.8 / height, hspace=0.57) + figure.suptitle(f'{BINARY_NAMES[a]} vs {BINARY_NAMES[b]} | {scale} throughput', + fontsize=22, y=1.0 - 0.375 / height, fontweight='bold') + figure.text(0.5, 1.0 - 0.825 / height, + f'{data["threads"]} threads | {thresholds}', ha='center') + + for ax, image in zip(axes, images): + plot_perf_panel(ax, data, image, pair, is_relative) + ax.set_title(data['images'][image]['title'], loc='left', pad=35) + + if ax is not axes[0]: + ax.get_legend().remove() + + output = out_dir / f'summary-{b.removeprefix("main-")}-{suffix}.png' + figure.savefig(output, dpi=PLOT_WIDTH / figure.get_figwidth()) print(f'Wrote {output}', flush=True) @@ -783,7 +838,7 @@ def plot_quality_changes(out_dir: Path, data: dict[str, Any]) -> None: plot_quality_panel(ax, data, image, info) output = out_dir / f'{tag}-qual.png' - figure.savefig(output, dpi=180) + figure.savefig(output, dpi=PLOT_WIDTH / figure.get_figwidth()) print(f'Wrote {output}', flush=True) @@ -839,6 +894,7 @@ def save_report(out_dir: Path, data: dict[str, Any]) -> None: write_report(out_dir, data) plot_charts(out_dir, data) + plot_summary_charts(out_dir, data) plot_quality_changes(out_dir, data) report_path = out_dir / 'report.md' print(f'Report: {report_path}\nRaw measurements: {raw_path}')