upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/scripts/shader_stats.py
diff options
context:
space:
mode:
authorReallyCrin <137194442+ReallyCrin@users.noreply.github.com>2026-11-23 13:30:44 -0800
committerReallyCrin <137194442+ReallyCrin@users.noreply.github.com>2026-11-23 13:30:44 -0800
commit9a0a1a2d5fe4e7f0786cf0d34564249f1fede278 (patch)
tree46597851c45c0a2fec90a21626b856591b3b566d /scripts/shader_stats.py
parent5d74c272363f2703265d44e6aaab1a1df8ddfaf3 (diff)
Preserve exact integral decimal counters in shader statistics
Diffstat (limited to 'scripts/shader_stats.py')
-rw-r--r--scripts/shader_stats.py23
1 files changed, 14 insertions, 9 deletions
diff --git a/scripts/shader_stats.py b/scripts/shader_stats.py
index fb95a1843..34b61cd8a 100644
--- a/scripts/shader_stats.py
+++ b/scripts/shader_stats.py
@@ -24,6 +24,7 @@ import os
24import statistics 24import statistics
25import sys 25import sys
26from collections import defaultdict 26from collections import defaultdict
27from decimal import Decimal, InvalidOperation
27 28
28sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "tools")) 29sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "tools"))
29import shader_ir # noqa: E402 30import shader_ir # noqa: E402
@@ -81,17 +82,21 @@ def load_stats(path):
81 82
82def number(raw): 83def number(raw):
83 """The exact int, or else the finite float, a raw value holds; None if it is missing or not such a number.""" 84 """The exact int, or else the finite float, a raw value holds; None if it is missing or not such a number."""
84 if raw is None: 85 try:
86 value = float(raw)
87 except (TypeError, ValueError, OverflowError):
88 return None
89 if not math.isfinite(value):
85 return None 90 return None
86 for parse in (int, float): 91 if value.is_integer():
92 # Beyond 2**53, converting the rounded float back to int can change the counter.
87 try: 93 try:
88 value = parse(raw) 94 exact = Decimal(raw)
89 if not math.isfinite(value): 95 except InvalidOperation:
90 return None 96 return value
91 return int(value) if isinstance(value, float) and value.is_integer() else value 97 if exact == exact.to_integral_value():
92 except (TypeError, ValueError, OverflowError): 98 return int(exact)
93 pass 99 return value
94 return None
95 100
96 101
97def shader_row(name, stage, st, src): 102def shader_row(name, stage, st, src):