3434
3535import argparse
3636from pathlib import Path
37+ import re
3738import sys
3839from typing import Optional
3940
@@ -342,8 +343,7 @@ def get_encoder_params(encoder_name: str, reference_name: str,
342343 _ , version , simd = encoder_name .split ('-' )
343344
344345 # Version-specific variants
345- compatible_prefixes = ['5.' ]
346- if any (True for x in compatible_prefixes if version .startswith (x )):
346+ if re .match (r'[0-9]+\.' , version ):
347347 encoder = te .Encoder2xRel (version , simd )
348348 name = f'reference-{ version } -{ simd } '
349349 out_dir = f'Test/Images/{ test_set_name } '
@@ -366,6 +366,29 @@ def get_encoder_params(encoder_name: str, reference_name: str,
366366 return (encoder , name , out_dir , used_reference_name )
367367
368368
369+ def find_reference_encoders (test_dir : Path ) -> list [str ]:
370+ '''
371+ Find reference encoders with result CSVs in the image tree.
372+
373+ Args:
374+ test_dir: The root of the test image tree.
375+
376+ Return:
377+ The sorted, unique reference encoder names.
378+ '''
379+ quality_pattern = '|' .join (TEST_QUALITIES )
380+ result_pattern = re .compile (
381+ rf'astc_reference-(.+)_(?:{ quality_pattern } )_results\.csv' )
382+ reference_encoders = set ()
383+
384+ for result_file in test_dir .rglob ('astc_reference-*_results.csv' ):
385+ match = result_pattern .fullmatch (result_file .name )
386+ if match and result_file .is_file ():
387+ reference_encoders .add (f'ref-{ match .group (1 )} ' )
388+
389+ return sorted (reference_encoders )
390+
391+
369392def parse_command_line ():
370393 '''
371394 Parse the command line.
@@ -374,17 +397,10 @@ def parse_command_line():
374397 Namespace: The parsed command line container.
375398 '''
376399 parser = argparse .ArgumentParser ()
400+ test_dir = Path (__file__ ).parent / 'Images'
377401
378402 # All reference encoders
379- reference_encoders = [
380- 'rebuild' ,
381-
382- 'ref-5.7-neon' ,
383- 'ref-5.7-sse2' , 'ref-5.7-sse4.1' , 'ref-5.7-avx2' ,
384-
385- 'ref-main-neon' , 'ref-main-sve_256' , 'ref-main-sve_128' ,
386- 'ref-main-sse2' , 'ref-main-sse4.1' , 'ref-main-avx2'
387- ]
403+ reference_encoders = ['rebuild' ] + find_reference_encoders (test_dir )
388404
389405 # All test encoders
390406 test_encoders = [
@@ -403,12 +419,13 @@ def parse_command_line():
403419 'sse2' , 'sse4.1' , 'avx2'
404420 ]
405421
406- encoder_choices = reference_encoders + test_encoders
422+ encoder_choices = list ( test_encoders )
407423 encoder_choices .append ('all-aarch64' )
408424 encoder_choices .append ('all-x86' )
409425
410426 parser .add_argument ('--encoder' , dest = 'encoders' , default = 'avx2' ,
411- choices = encoder_choices , help = 'test encoder variant' )
427+ help = 'test encoder variant or '
428+ 'ref-<version>-<variant>' )
412429
413430 parser .add_argument ('--reference' , default = 'ref-main-avx2' ,
414431 choices = reference_encoders ,
@@ -426,8 +443,6 @@ def parse_command_line():
426443 parser .add_argument ('--block-size' , dest = 'block_sizes' , action = 'append' ,
427444 choices = block_size_choices , help = 'test block size' )
428445
429- test_dir = Path (__file__ ).parent / 'Images'
430-
431446 test_set_choices = [x .name for x in test_dir .iterdir () if x .is_dir ()]
432447 test_set_choices .sort ()
433448 test_set_choices .append ('all' )
@@ -458,6 +473,13 @@ def parse_command_line():
458473
459474 args = parser .parse_args ()
460475
476+ # Allow new reference encoders before their result CSVs have been generated
477+ if args .encoders not in encoder_choices :
478+ pattern = r'ref-(?:main|[0-9]+\.[^-]+)-(.+)'
479+ match = re .fullmatch (pattern , args .encoders )
480+ if (match is None ) or (match .group (1 ) not in test_encoders ):
481+ parser .error (f'--encoder: invalid choice: { args .encoders !r} ' )
482+
461483 # Turn things into canonical format lists
462484 if args .encoders == 'all-aarch64' :
463485 args .encoders = test_encoders_arm64
0 commit comments