WIP: reconstruct color kernels, camera tables and native inspector; integration checks pending

这个提交包含在:
mac 于 2026-10-31 01:16:08 +08:00 提交
1 父节点 10987dd6bc
当前提交 2f11e8bd0f
52 个文件已更改
+11421 -835

没有与搜索条件相匹配的文件

+33
查看文件
@@ -0,0 +1,33 @@
#!/usr/bin/env python3
"""Build the versioned AIR arithmetic and Dayu's authored Metal boundary."""
from pathlib import Path
import argparse
import subprocess
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--output', required=True, type=Path)
parser.add_argument('--intermediates', required=True, type=Path)
args = parser.parse_args()
root = Path(__file__).resolve().parent.parent
work = args.intermediates.resolve()
work.mkdir(parents=True, exist_ok=True)
args.output.parent.mkdir(parents=True, exist_ok=True)
objects = []
for name in ('DYGradeKernel', 'DYStatisticsKernel', 'DYLUTExportKernel'):
target = work / (name + '.air')
subprocess.run(['xcrun', 'metal-opt', str(root / 'tools/kernels' / (name + '.ll')),
'-o', str(target)], check=True)
objects.append(str(target))
wrapper = work / 'DYGradeWrapper.air'
subprocess.run(['xcrun', '-sdk', 'macosx', 'metal', '-std=metal3.1',
'-mmacosx-version-min=14.6', '-c',
str(root / '大鱼调色/Plugin/DYGrade.metal'), '-o', str(wrapper)], check=True)
subprocess.run(['xcrun', '-sdk', 'macosx', 'metallib', str(wrapper), *objects,
'-o', str(args.output)], check=True)
print(args.output)
if __name__ == '__main__':
main()
+9
查看文件
@@ -0,0 +1,9 @@
#!/usr/bin/env python3
"""Review selected paths before invoking. Never stages unrelated paths."""
import pathlib,os,hashlib,json,subprocess,shutil,sys
root=pathlib.Path(__file__).resolve().parent.parent;remote='https://dayu.media/git/dayu/dayu-color.git';lock=pathlib.Path('/Users/mac/.codex/git-backup-locks')/(hashlib.sha256(remote.encode()).hexdigest()+'.lock')
lock.parent.mkdir(parents=True,exist_ok=True);lock.mkdir();(lock/'owner.json').write_text(json.dumps(dict(PID=os.getpid(),cwd=str(root),remote=remote)))
def run(*a):return subprocess.check_output(a,cwd=root,text=True).strip()
try:
run('git','add','-A','--',*sys.argv[2:]);print(run('git','diff','--cached','--stat'));print(run('git','commit','-m',sys.argv[1]));print(run('git','push','origin','HEAD'));sha=run('git','rev-parse','HEAD');assert run('git','ls-remote','origin','refs/heads/main').split()[0]==sha;print('REMOTE_VERIFIED '+sha)
finally:shutil.rmtree(lock)
+25
查看文件
@@ -0,0 +1,25 @@
#!/usr/bin/env python3
"""One-time extraction of the explicitly supplied app's input color tables.
Production builds consume the committed compressed float tables, never the app.
"""
from pathlib import Path
import argparse,array,struct,zlib,hashlib,json
p=argparse.ArgumentParser();p.add_argument('source',type=Path);a=p.parse_args()
root=Path(__file__).resolve().parent.parent;out=root/'大鱼调色/Plugin/Resources/InputLUTs';out.mkdir(parents=True,exist_ok=True)
manifest=[]
for src in sorted(a.source.glob('*.cube')):
n=0;rgb=array.array('f');lo=[0.,0.,0.];hi=[1.,1.,1.]
for raw in src.read_text().splitlines():
s=raw.split('#',1)[0].strip().split()
if not s:continue
if s[0]=='LUT_3D_SIZE':n=int(s[1])
elif s[0]=='DOMAIN_MIN':lo=list(map(float,s[1:4]))
elif s[0]=='DOMAIN_MAX':hi=list(map(float,s[1:4]))
elif len(s)==3:
try:rgb.extend([*map(float,s),1.])
except ValueError:pass
assert len(rgb)==n**3*4,(src,n,len(rgb))
blob=struct.pack('<4sII6f',b'DYLT',n,len(rgb)*4,*lo,*hi)+zlib.compress(rgb.tobytes(),9)
dest=out/(src.stem+'.dylut');dest.write_bytes(blob)
manifest.append(dict(file=dest.name,dimension=n,source=src.name,sourceSHA256=hashlib.sha256(src.read_bytes()).hexdigest(),sha256=hashlib.sha256(blob).hexdigest()))
(out/'manifest.json').write_text(json.dumps(manifest,indent=2)+'\n');print(len(manifest),'input LUTs imported')
文件差异过大,未显示。 加载差异
文件差异过大,未显示。 加载差异
+683
查看文件
@@ -0,0 +1,683 @@
; Reconstructed numeric instruction graph; see PROVENANCE.json.
source_filename = "dyWhitesSceneStatistics"
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024-n8:16:32"
target triple = "air64_v26-apple-macosx14.6.0"
%"struct.metal::_atomic" = type { i32 }
%struct._texture_2d_t = type opaque
%struct._texture_3d_t = type opaque
%struct.DYUniforms = type { float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, <4 x float>, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, <4 x float>, float, float, float, float, float, float, float, float, float, float, float, float, <4 x float>, <2 x float>, <2 x float>, <2 x float>, <4 x float>, <4 x float>, <4 x float>, <4 x float>, <4 x float>, <4 x float>, <3 x float>, <3 x float>, float, float, float, <4 x float>, <4 x float>, <3 x float>, <3 x float>, float, float, float, float, float, float, float, <3 x float>, <3 x float>, <3 x float>, <3 x float>, float, <3 x float>, float, <4 x float>, <4 x float>, <4 x float>, <4 x float>, <4 x float>, float, <4 x float>, <2 x float>, <2 x float>, float, float, <3 x float>, <3 x float>, <3 x float>, <4 x float>, <4 x float>, <4 x float>, <4 x float>, <4 x float>, <4 x float>, <4 x float>, <4 x float> }
%struct._sampler_t = type opaque
@_ZZ21dyWhitesSceneStatisticsN5metal9texture2dIDhLNS_6accessE0EvEENS_9texture3dIfLS1_0EvEERU11MTLconstantK17DYUniformsPU9MTLdevicefjE9histogram = internal addrspace(3) global [256 x %"struct.metal::_atomic"] zeroinitializer, align 4
@_ZL14lgChromaScales = internal unnamed_addr addrspace(2) constant [6 x [7 x [33 x float]]] [[7 x [33 x float]] [[33 x float] [float 0x3FD5539260000000, float 0x3FD5C51660000000, float 0x3FD6369120000000, float 0x3FD6A820A0000000, float 0x3FD71B7180000000, float 0x3FD793B380000000, float 0x3FD8143720000000, float 0x3FD89EEBC0000000, float 0x3FD932D480000000, float 0x3FD9CC4500000000, float 0x3FDA66CA80000000, float 0x3FDAFFA180000000, float 0x3FDB9AC380000000, float 0x3FDC469EA0000000, float 0x3FDD1DF7A0000000, float 0x3FDE466680000000, float 0x3FDFEFC400000000, float 0x3FE128C5E0000000, float 0x3FE2D262C0000000, float 0x3FE50EF9A0000000, float 0x3FE7F41DC0000000, float 0x3FEB90E840000000, float 0x3FEFEDE5C0000000, float 0x3FF284E6E0000000, float 0x3FF56CF9E0000000, float 0x3FF8A4FB20000000, float 0x3FFC1E07C0000000, float 0x3FFFC4BCA0000000, float 0x4001C125C0000000, float 0x4003A22440000000, float 0x4005828680000000, float 0x400762A900000000, float 3.000000e+00], [33 x float] [float 0x3FE1F31A80000000, float 0x3FE24DE8E0000000, float 0x3FE2A8B740000000, float 0x3FE303BAE0000000, float 0x3FE35F6CA0000000, float 0x3FE3BC16C0000000, float 0x3FE4191BA0000000, float 0x3FE474DDE0000000, float 0x3FE4CCBE60000000, float 0x3FE51DE2E0000000, float 0x3FE5665720000000, float 0x3FE5A66EC0000000, float 0x3FE5E39FA0000000, float 0x3FE628DD60000000, float 0x3FE686D9C0000000, float 0x3FE712B8E0000000, float 0x3FE7E53BC0000000, float 0x3FE918EDE0000000, float 0x3FEAC65460000000, float 0x3FED000600000000, float 0x3FEFD1CBC0000000, float 0x3FF1A01C40000000, float 0x3FF3A49220000000, float 0x3FF5F09740000000, float 0x3FF87A2140000000, float 0x3FFB32BD40000000, float 0x3FFE07CFC0000000, float 0x4000716740000000, float 0x4001D82BA0000000, float 0x40033A7F80000000, float 0x40049B5280000000, float 0x4005FBE960000000, float 0x40075C77E0000000], [33 x float] [float 0x3FE7F5C200000000, float 0x3FE83A93C0000000, float 0x3FE87F6480000000, float 0x3FE8C44680000000, float 0x3FE90932A0000000, float 0x3FE94DB660000000, float 0x3FE990E6C0000000, float 0x3FE9D17D80000000, float 0x3FEA0E1F80000000, float 0x3FEA45F500000000, float 0x3FEA790DE0000000, float 0x3FEAA8C9E0000000, float 0x3FEAD89140000000, float 0x3FEB0D8580000000, float 0x3FEB4E9660000000, float 0x3FEBA37DE0000000, float 0x3FEC1491E0000000, float 0x3FECAA2A20000000, float 0x3FED6AEC40000000, float 0x3FEE5B2220000000, float 0x3FEF7D8160000000, float 0x3FF0699360000000, float 0x3FF12DD280000000, float 0x3FF20A4520000000, float 0x3FF2FCA360000000, float 0x3FF4018DA0000000, float 0x3FF5149A40000000, float 0x3FF63061C0000000, float 0x3FF74F84E0000000, float 0x3FF8702520000000, float 0x3FF9917700000000, float 0x3FFAB2EC00000000, float 0x3FFBD45F20000000], [33 x float] [float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00], [33 x float] [float 0x3FF504ADC0000000, float 0x3FF4CAC1C0000000, float 0x3FF490D400000000, float 0x3FF456E480000000, float 0x3FF41D6020000000, float 0x3FF3E50440000000, float 0x3FF3AE70C0000000, float 0x3FF379C960000000, float 0x3FF3467A40000000, float 0x3FF3133100000000, float 0x3FF2DDE360000000, float 0x3FF2A40480000000, float 0x3FF26314A0000000, float 0x3FF2195140000000, float 0x3FF1C5C000000000, float 0x3FF168BA40000000, float 0x3FF1032380000000, float 0x3FF095A6C0000000, float 0x3FF0209900000000, float 0x3FEF46E860000000, float 0x3FEE3A39C0000000, float 0x3FED19CC40000000, float 0x3FEBE56FC0000000, float 0x3FEA9DF900000000, float 0x3FE94531C0000000, float 0x3FE7DDEF20000000, float 0x3FE66C2280000000, float 0x3FE4F4A6A0000000, float 0x3FE37C2DE0000000, float 0x3FE203E780000000, float 0x3FE08BC2E0000000, float 0x3FDE274940000000, float 0x3FDB371320000000], [33 x float] [float 0x3FFB7E1FE0000000, float 0x3FFAD91140000000, float 0x3FFA33FE80000000, float 0x3FF98F0400000000, float 0x3FF8EB3BA0000000, float 0x3FF849DCE0000000, float 0x3FF7AB1A80000000, float 0x3FF70DCEE0000000, float 0x3FF66FC380000000, float 0x3FF5CE2DA0000000, float 0x3FF525E8A0000000, float 0x3FF4745D60000000, float 0x3FF3B89A20000000, float 0x3FF2F2E140000000, float 0x3FF223F0E0000000, float 0x3FF14E6A20000000, float 0x3FF0751420000000, float 0x3FEF338C60000000, float 0x3FED7B4CC0000000, float 0x3FEBC12040000000, float 0x3FEA02EA20000000, float 0x3FE83F26E0000000, float 0x3FE6755F40000000, float 0x3FE4A5FC40000000, float 0x3FE2D22AA0000000, float 0x3FE0FBC120000000, float 0x3FDE4AAF00000000, float 0x3Line truncated
@_ZL12lgToneCurves = internal unnamed_addr addrspace(2) constant [6 x [7 x [33 x float]]] [[7 x [33 x float]] [[33 x float] [float 0.000000e+00, float 0x3F7EFB2800000000, float 0x3F92B7BF00000000, float 0x3F9DC082A0000000, float 0x3FA4701620000000, float 0x3FAA13EE40000000, float 0x3FAFD60B80000000, float 0x3FB2DED580000000, float 0x3FB5E8BC60000000, float 0x3FB90EAA20000000, float 0x3FBC562380000000, float 0x3FBFC3E500000000, float 0x3FC1AA9480000000, float 0x3FC3836200000000, float 0x3FC56C95E0000000, float 0x3FC76663C0000000, float 0x3FC972CBA0000000, float 0x3FCB9752E0000000, float 0x3FCDDA49A0000000, float 0x3FD0204540000000, float 0x3FD1658120000000, float 0x3FD2BE4620000000, float 0x3FD42C9C80000000, float 0x3FD5B32400000000, float 0x3FD753C8C0000000, float 0x3FD91188C0000000, float 0x3FDAF29A80000000, float 0x3FDD025C80000000, float 0x3FDF4FB240000000, float 0x3FE0ED37A0000000, float 0x3FE245FC00000000, float 0x3FE3A4C540000000, float 0x3FE504BAA0000000], [33 x float] [float 0.000000e+00, float 0x3F9095A5C0000000, float 0x3FA1B21240000000, float 0x3FAB1B1AE0000000, float 0x3FB2489580000000, float 0x3FB7168280000000, float 0x3FBC011E80000000, float 0x3FC0867C40000000, float 0x3FC31DE900000000, float 0x3FC5C74F20000000, float 0x3FC8805AE0000000, float 0x3FCB453100000000, float 0x3FCE118AA0000000, float 0x3FD0717940000000, float 0x3FD1DD37E0000000, float 0x3FD34D9520000000, float 0x3FD4C5D3C0000000, float 0x3FD64B2040000000, float 0x3FD7E28D80000000, float 0x3FD98FD200000000, float 0x3FDB53C960000000, float 0x3FDD2F94E0000000, float 0x3FDF245E20000000, float 0x3FE099B4E0000000, float 0x3FE1AEDF60000000, float 0x3FE2D36E60000000, float 0x3FE40BE240000000, float 0x3FE560CA20000000, float 0x3FE6DA1B00000000, float 0x3FE86DA020000000, float 0x3FEA0E3160000000, float 0x3FEBB263C0000000, float 0x3FED574A20000000], [33 x float] [float 0.000000e+00, float 0x3F973B9760000000, float 0x3FA7E40980000000, float 0x3FB2166020000000, float 0x3FB842B8E0000000, float 0x3FBE814D20000000, float 0x3FC26BF3C0000000, float 0x3FC5A3A200000000, float 0x3FC8E6E0A0000000, float 0x3FCC344100000000, float 0x3FCF8926A0000000, float 0x3FD17172A0000000, float 0x3FD31FB3A0000000, float 0x3FD4CEEBA0000000, float 0x3FD6800360000000, float 0x3FD834F7A0000000, float 0x3FD9F12D80000000, float 0x3FDBB92360000000, float 0x3FDD90A4A0000000, float 0x3FDF797860000000, float 0x3FE0B924C0000000, float 0x3FE1BCD960000000, float 0x3FE2C77460000000, float 0x3FE3D91600000000, float 0x3FE4F21220000000, float 0x3FE612F7C0000000, float 0x3FE73C8AA0000000, float 0x3FE86F7FC0000000, float 0x3FE9ABD640000000, float 0x3FEAEF1540000000, float 0x3FEC3614E0000000, float 0x3FED7E6080000000, float 0x3FEEC6FE40000000], [33 x float] [float 0.000000e+00, float 3.125000e-02, float 6.250000e-02, float 9.375000e-02, float 1.250000e-01, float 1.562500e-01, float 1.875000e-01, float 2.187500e-01, float 2.500000e-01, float 2.812500e-01, float 3.125000e-01, float 3.437500e-01, float 3.750000e-01, float 4.062500e-01, float 4.375000e-01, float 4.687500e-01, float 5.000000e-01, float 5.312500e-01, float 5.625000e-01, float 5.937500e-01, float 6.250000e-01, float 6.562500e-01, float 6.875000e-01, float 7.187500e-01, float 7.500000e-01, float 7.812500e-01, float 8.125000e-01, float 8.437500e-01, float 8.750000e-01, float 9.062500e-01, float 9.375000e-01, float 9.687500e-01, float 1.000000e+00], [33 x float] [float 0x3F66796E80000000, float 0x3FA6139860000000, float 0x3FB55F0060000000, float 0x3FBFABA880000000, float 0x3FC4EEFFC0000000, float 0x3FC9F30D60000000, float 0x3FCEE184A0000000, float 0x3FD1DF9C00000000, float 0x3FD448D240000000, float 0x3FD6AE2640000000, float 0x3FD91020C0000000, float 0x3FDB6D61E0000000, float 0x3FDDC32D80000000, float 0x3FE006EE80000000, float 0x3FE124AD60000000, float 0x3FE2397140000000, float 0x3FE344DBA0000000, float 0x3FE4474200000000, float 0x3FE541B340000000, float 0x3FE6356760000000, float 0x3FE723E2C0000000, float 0x3FE80D93E0000000, float 0x3FE8F20800000000, float 0x3FE9D032E0000000, float 0x3FEAA72C60000000, float 0x3FEB764340000000, float 0x3FEC3D3D00000000, float 0x3FECFCCCE0000000, float 0x3FEDB68340000000, float 0x3FEE6C52E0000000, float 0x3FEF2005E0000000, float 0x3FEFD2EE00000000, float 1.000000e+00], [33 x float] [float 0x3F7FEE9D60000000, float 0x3FAE6517E0000000, float 0x3FBC62A280000000, float 0x3FC4B98CA0000000, float 0x3FCB1A9FE0000000, float 0x3FD0A2B4A0000000, float 0x3FD39E8880000000, float 0x3FD68704E0000000, float 0x3FD9617000000000, float 0x3FDC2F5BE0000000, float 0x3FDEEDE940000000, float 0x3FE0CACDA0000000, float 0x3FE20FCE00000000, float 0x3FE3437C20000000, float 0x3FE4646780000000, float 0x3FE5733B40000000, float 0x3FE6716C20000000, float 0x3FE75FEE20000000, float 0x3FE83FFC40000000, float 0x3FE91338A0000000, float 0x3FE9DCA500000000, float 0x3FEA9D5CE0000000, float 0x3FEB549B00000000, float 0x3FEC005020000000, float 0x3FEC9EFBE0000000, float 0x3FED303E40000000, float 0x3FEDB53A20000000, float 0x3FEE3099A0000000, floLine truncated
@_ZL11lgToneModes = internal unnamed_addr addrspace(2) constant [6 x [7 x float]] [[7 x float] [float 0.000000e+00, float 0.000000e+00, float 0.000000e+00, float 0.000000e+00, float 0.000000e+00, float 0.000000e+00, float 1.000000e+00], [7 x float] zeroinitializer, [7 x float] zeroinitializer, [7 x float] zeroinitializer, [7 x float] zeroinitializer, [7 x float] [float 1.000000e+00, float 1.000000e+00, float 0.000000e+00, float 0.000000e+00, float 0.000000e+00, float 0.000000e+00, float 0.000000e+00]], align 4
@_ZL7lgStops = internal unnamed_addr addrspace(2) constant [7 x float] [float -1.000000e+02, float -5.000000e+01, float -2.500000e+01, float 0.000000e+00, float 2.500000e+01, float 5.000000e+01, float 1.000000e+02], align 4
@__air_sampler_state = internal addrspace(2) constant i64 -9188470239253755319, align 8
; Function Attrs: convergent nounwind
define void @dyWhitesSceneStatistics(%struct._texture_2d_t addrspace(1)* %0, %struct._texture_3d_t addrspace(1)* nocapture readonly %1, %struct.DYUniforms addrspace(2)* nocapture readnone dereferenceable(944) "air-buffer-no-alias" %2, float addrspace(1)* nocapture "air-buffer-no-alias" %3, i32 %4) local_unnamed_addr #0 {
%6 = zext i32 %4 to i64
%7 = getelementptr inbounds [256 x %"struct.metal::_atomic"], [256 x %"struct.metal::_atomic"] addrspace(3)* @_ZZ21dyWhitesSceneStatisticsN5metal9texture2dIDhLNS_6accessE0EvEENS_9texture3dIfLS1_0EvEERU11MTLconstantK17DYUniformsPU9MTLdevicefjE9histogram, i64 0, i64 %6, i32 0
tail call void @air.atomic.local.store.i32(i32 addrspace(3)* nocapture %7, i32 0, i32 0, i32 1, i1 true) #2
tail call void @air.wg.barrier(i32 2, i32 1) #7
%8 = icmp ult i32 %4, 65536
br i1 %8, label %9, label %13
9: ; preds = %5
%10 = and i32 %4, 255
%11 = tail call fast float @air.convert.f.f32.u.i32(i32 %10) #1
%12 = insertelement <2 x float> undef, float %11, i64 0
br label %15
13: ; preds = %78, %5
tail call void @air.wg.barrier(i32 2, i32 1) #7
%14 = icmp eq i32 %4, 0
br i1 %14, label %84, label %130
15: ; preds = %78, %9
%16 = phi i32 [ %79, %78 ], [ %4, %9 ]
%17 = lshr i32 %16, 8
%18 = tail call fast float @air.convert.f.f32.u.i32(i32 %17) #1
%19 = insertelement <2 x float> %12, float %18, i64 1
%20 = fadd fast <2 x float> %19, <float 5.000000e-01, float 5.000000e-01>
%21 = fmul fast <2 x float> %20, <float 3.906250e-03, float 3.906250e-03>
%22 = tail call { <4 x half>, i8 } @air.sample_texture_2d.v4f16(%struct._texture_2d_t addrspace(1)* nocapture readonly %0, %struct._sampler_t addrspace(2)* nocapture readonly bitcast (i64 addrspace(2)* @__air_sampler_state to %struct._sampler_t addrspace(2)*), <2 x float> %21, i1 true, <2 x i32> zeroinitializer, i1 false, float 0.000000e+00, float 0.000000e+00, i32 0) #4
%23 = extractvalue { <4 x half>, i8 } %22, 0
%24 = extractelement <4 x half> %23, i64 3
%25 = fcmp fast ugt half %24, 0xH0000
br i1 %25, label %26, label %78
26: ; preds = %15
%27 = shufflevector <4 x half> %23, <4 x half> undef, <3 x i32> <i32 0, i32 1, i32 2>
%28 = tail call fast <3 x float> @air.convert.f.v3f32.f.v3f16(<3 x half> %27) #1
%29 = tail call fast <3 x float> @air.fast_fmax.v3f32(<3 x float> %28, <3 x float> zeroinitializer) #1
%30 = tail call fast <3 x float> @air.fast_pow.v3f32(<3 x float> %29, <3 x float> <float 0x3FDAAAAAA0000000, float 0x3FDAAAAAA0000000, float 0x3FDAAAAAA0000000>) #1
%31 = fmul fast <3 x float> %30, <float 0x3FF0E147A0000000, float 0x3FF0E147A0000000, float 0x3FF0E147A0000000>
%32 = fadd fast <3 x float> %31, <float 0xBFAC28F5C0000000, float 0xBFAC28F5C0000000, float 0xBFAC28F5C0000000>
%33 = fmul fast <3 x float> %28, <float 0x4029D70A40000000, float 0x4029D70A40000000, float 0x4029D70A40000000>
%34 = fcmp fast ole <3 x float> %28, <float 0x3F69A5C380000000, float 0x3F69A5C380000000, float 0x3F69A5C380000000>
%35 = select reassoc nsz arcp contract afn <3 x i1> %34, <3 x float> %33, <3 x float> %32
%36 = tail call fast fastcc <3 x float> @_ZL13applyExposureDv3_fRU11MTLconstantK17DYUniforms(<3 x float> %35, %struct.DYUniforms addrspace(2)* dereferenceable(944) %2) #8
%37 = tail call fast float @air.fast_clamp.f32(float 1.000000e+00, float 0.000000e+00, float 1.000000e+00) #1
%38 = fcmp fast ugt float %37, 0x3EE4F8B580000000
br i1 %38, label %39, label %58
39: ; preds = %26
%40 = tail call i32 @air.get_width_texture_3d(%struct._texture_3d_t addrspace(1)* nocapture readonly %1, i32 0) #5, !alias.scope !24, !noalias !27
%41 = tail call fast float @air.convert.f.f32.u.i32(i32 %40) #1
%42 = tail call fast <3 x float> @air.fast_clamp.v3f32(<3 x float> %36, <3 x float> zeroinitializer, <3 x float> <float 1.000000e+00, float 1.000000e+00, float 1.000000e+00>) #1
%43 = fadd fast float %41, -1.000000e+00
%44 = fdiv fast float %43, %41
%45 = insertelement <3 x float> undef, float %44, i64 0
%46 = shufflevector <3 x float> %45, <3 x float> undef, <3 x i32> zeroinitializer
%47 = fmul fast <3 x float> %46, %42
%48 = fdiv fast float 5.000000e-01, %41
%49 = insertelement <3 x float> undef, float %48, i64 0
%50 = shufflevector <3 x float> %49, <3 x float> undef, <3 x i32> zeroinitializer
%51 = fadd fast <3 x float> %47, %50
%52 = tail call { <4 x float>, i8 } @air.sample_texture_3d.v4f32(%struct._texture_3d_t addrspace(1)* nocapture readonly %1, %struct._sampler_t addrspace(2)* nocapture readonly bitcast (i64 addrspace(2)* @__air_sampler_state to %struct._sampler_t addrspace(2)*), <3 x float> %51, i1 true, <3 x i32> zeroinitializer, i1 false, float 0.000000e+00, float 0.000000e+00, i32 0) #4
%53 = extractvalue { <4 x float>, i8 } %52, 0
%54 = shufflevector <4 x float> %53, <4 x float> undef, <3 x i32> <i32 0, i32 1, i32 2>
%55 = insertelement <3 x float> undef, float %37, i64 0
%56 = shufflevector <3 x float> %55, <3 x float> undef, <3 x i32> zeroinitializer
%57 = tail call fast <3 x float> @air.mix.v3f32(<3 x float> %36, <3 x float> %54, <3 x float> %56) #1
br label %58
58: ; preds = %39, %26
%59 = phi <3 x float> [ %57, %39 ], [ %36, %26 ]
%60 = tail call fast fastcc <3 x float> @_ZL26applyToneAfterWhiteBalanceDv3_fRU11MTLconstantK17DYUniforms(<3 x float> %59, %struct.DYUniforms addrspace(2)* dereferenceable(944) %2) #8
%61 = tail call fast float @air.dot.v3f32(<3 x float> %60, <3 x float> <float 0x3FCB367A00000000, float 0x3FE6E2EB20000000, float 0x3FB27BB300000000>) #1
%62 = tail call fast float @air.fast_clamp.f32(float %61, float 0.000000e+00, float 1.000000e+00) #1
%63 = fmul fast float %62, 2.550000e+02
%64 = tail call i32 @air.convert.u.i32.f.f32(float %63) #1
%65 = tail call i32 @air.min.u.i32(i32 %64, i32 254) #1
%66 = tail call fast float @air.convert.f.f32.u.i32(i32 %65) #1
%67 = fsub fast float %63, %66
%68 = fmul fast float %67, 1.024000e+03
%69 = tail call i32 @air.convert.u.i32.f.f32(float %68) #1
%70 = zext i32 %65 to i64
%71 = sub i32 1024, %69
%72 = getelementptr inbounds [256 x %"struct.metal::_atomic"], [256 x %"struct.metal::_atomic"] addrspace(3)* @_ZZ21dyWhitesSceneStatisticsN5metal9texture2dIDhLNS_6accessE0EvEENS_9texture3dIfLS1_0EvEERU11MTLconstantK17DYUniformsPU9MTLdevicefjE9histogram, i64 0, i64 %70, i32 0
%73 = tail call i32 @air.atomic.local.add.u.i32(i32 addrspace(3)* nocapture %72, i32 %71, i32 0, i32 1, i1 true) #2
%74 = add i32 %65, 1
%75 = zext i32 %74 to i64
%76 = getelementptr inbounds [256 x %"struct.metal::_atomic"], [256 x %"struct.metal::_atomic"] addrspace(3)* @_ZZ21dyWhitesSceneStatisticsN5metal9texture2dIDhLNS_6accessE0EvEENS_9texture3dIfLS1_0EvEERU11MTLconstantK17DYUniformsPU9MTLdevicefjE9histogram, i64 0, i64 %75, i32 0
%77 = tail call i32 @air.atomic.local.add.u.i32(i32 addrspace(3)* nocapture %76, i32 %69, i32 0, i32 1, i1 true) #2
br label %78
78: ; preds = %58, %15
%79 = add nuw nsw i32 %16, 256
%80 = icmp ult i32 %16, 65280
br i1 %80, label %15, label %13, !llvm.loop !30
81: ; preds = %84
%82 = fmul fast float %91, 0x3FEEB851E0000000
%83 = fmul fast float %91, 0x3FEFD70A40000000
br label %96
84: ; preds = %84, %13
%85 = phi float [ %91, %84 ], [ 0.000000e+00, %13 ]
%86 = phi i32 [ %92, %84 ], [ 0, %13 ]
%87 = zext i32 %86 to i64
%88 = getelementptr inbounds [256 x %"struct.metal::_atomic"], [256 x %"struct.metal::_atomic"] addrspace(3)* @_ZZ21dyWhitesSceneStatisticsN5metal9texture2dIDhLNS_6accessE0EvEENS_9texture3dIfLS1_0EvEERU11MTLconstantK17DYUniformsPU9MTLdevicefjE9histogram, i64 0, i64 %87, i32 0
%89 = tail call i32 @air.atomic.local.load.i32(i32 addrspace(3)* nocapture %88, i32 0, i32 1, i1 true) #2
%90 = tail call fast float @air.convert.f.f32.u.i32(i32 %89) #1
%91 = fadd fast float %90, %85
%92 = add nuw nsw i32 %86, 1
%93 = icmp eq i32 %92, 256
br i1 %93, label %81, label %84, !llvm.loop !32
94: ; preds = %120
%95 = fcmp fast ogt float %91, 0.000000e+00
br i1 %95, label %124, label %128
96: ; preds = %120, %81
%97 = phi i32 [ 0, %81 ], [ %122, %120 ]
%98 = phi float [ 0.000000e+00, %81 ], [ %121, %120 ]
%99 = phi float [ 0.000000e+00, %81 ], [ %105, %120 ]
%100 = zext i32 %97 to i64
%101 = getelementptr inbounds [256 x %"struct.metal::_atomic"], [256 x %"struct.metal::_atomic"] addrspace(3)* @_ZZ21dyWhitesSceneStatisticsN5metal9texture2dIDhLNS_6accessE0EvEENS_9texture3dIfLS1_0EvEERU11MTLconstantK17DYUniformsPU9MTLdevicefjE9histogram, i64 0, i64 %100, i32 0
%102 = tail call i32 @air.atomic.local.load.i32(i32 addrspace(3)* nocapture %101, i32 0, i32 1, i1 true) #2
%103 = tail call fast float @air.convert.f.f32.u.i32(i32 %102) #1
%104 = tail call fast float @air.fast_fmax.f32(float %82, float %99) #1
%105 = fadd fast float %103, %99
%106 = tail call fast float @air.fast_fmin.f32(float %83, float %105) #1
%107 = fcmp fast ogt float %106, %104
br i1 %107, label %108, label %120
108: ; preds = %96
%109 = tail call fast float @air.convert.f.f32.u.i32(i32 %97) #1
%110 = fadd fast float %106, %104
%111 = fmul fast float %110, 5.000000e-01
%112 = fsub fast float %111, %99
%113 = fdiv fast float %112, %103
%114 = fadd fast float %113, -5.000000e-01
%115 = fadd fast float %114, %109
%116 = fsub fast float %106, %104
%117 = fmul fast float %116, 0x3F70101020000000
%118 = fmul fast float %117, %115
%119 = fadd fast float %118, %98
br label %120
120: ; preds = %108, %96
%121 = phi float [ %119, %108 ], [ %98, %96 ]
%122 = add nuw nsw i32 %97, 1
%123 = icmp eq i32 %122, 256
br i1 %123, label %94, label %96, !llvm.loop !33
124: ; preds = %94
%125 = fmul fast float %91, 0x3FA1EB8600000000
%126 = fdiv fast float %121, %125
%127 = tail call fast float @air.fast_clamp.f32(float %126, float 0x3FD6666660000000, float 1.000000e+00) #1
br label %128
128: ; preds = %124, %94
%129 = phi float [ %127, %124 ], [ 1.000000e+00, %94 ]
store float %129, float addrspace(1)* %3, align 4, !tbaa !34, !alias.scope !38, !noalias !39
br label %130
130: ; preds = %128, %13
ret void
}
; Function Attrs: nounwind readnone
declare float @air.fast_clamp.f32(float, float, float) local_unnamed_addr #1
; Function Attrs: nounwind readnone
declare float @air.convert.f.f32.u.i32(i32) local_unnamed_addr #1
; Function Attrs: nounwind readnone
declare float @air.fast_fmin.f32(float, float) local_unnamed_addr #1
; Function Attrs: nounwind readnone
declare float @air.fast_fmax.f32(float, float) local_unnamed_addr #1
; Function Attrs: nounwind
declare i32 @air.atomic.local.load.i32(i32 addrspace(3)* nocapture, i32, i32, i1) local_unnamed_addr #2
; Function Attrs: nounwind
declare i32 @air.atomic.local.add.u.i32(i32 addrspace(3)* nocapture, i32, i32, i32, i1) local_unnamed_addr #2
; Function Attrs: nounwind readnone
declare i32 @air.convert.u.i32.f.f32(float) local_unnamed_addr #1
; Function Attrs: nounwind readnone
declare i32 @air.min.u.i32(i32, i32) local_unnamed_addr #1
; Function Attrs: nounwind readnone
declare float @air.dot.v3f32(<3 x float>, <3 x float>) local_unnamed_addr #1
; Function Attrs: inlinehint nounwind readnone
define internal fastcc <3 x float> @_ZL26applyToneAfterWhiteBalanceDv3_fRU11MTLconstantK17DYUniforms(<3 x float> %0, %struct.DYUniforms addrspace(2)* nocapture readonly dereferenceable(944) %1) unnamed_addr #3 {
%3 = getelementptr inbounds %struct.DYUniforms, %struct.DYUniforms addrspace(2)* %1, i64 0, i32 31
%4 = load float, float addrspace(2)* %3, align 8, !tbaa !40
%5 = fcmp fast ugt float %4, 5.000000e-01
br i1 %5, label %6, label %122
6: ; preds = %2
%7 = getelementptr inbounds %struct.DYUniforms, %struct.DYUniforms addrspace(2)* %1, i64 0, i32 18
%8 = load float, float addrspace(2)* %7, align 4, !tbaa !42
%9 = fcmp fast ogt float %8, 5.000000e-01
%10 = getelementptr inbounds %struct.DYUniforms, %struct.DYUniforms addrspace(2)* %1, i64 0, i32 1
%11 = load float, float addrspace(2)* %10, align 4
%12 = select fast i1 %9, float %11, float 0.000000e+00
%13 = tail call fast float @air.fast_fabs.f32(float %12) #1
%14 = fcmp fast olt float %13, 0x3E7AD7F2A0000000
br i1 %14, label %44, label %15
15: ; preds = %6
%16 = tail call fast float @air.fast_clamp.f32(float %12, float -1.000000e+02, float 1.000000e+02) #1
br label %17
17: ; preds = %20, %15
%18 = phi i32 [ 0, %15 ], [ %21, %20 ]
%19 = icmp eq i32 %18, 5
br i1 %19, label %26, label %20
20: ; preds = %17
%21 = add nuw nsw i32 %18, 1
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds [7 x float], [7 x float] addrspace(2)* @_ZL7lgStops, i64 0, i64 %22
%24 = load float, float addrspace(2)* %23, align 4, !tbaa !34
%25 = fcmp fast ogt float %24, %16
br i1 %25, label %26, label %17, !llvm.loop !43
26: ; preds = %20, %17
%27 = icmp ult i32 %18, 5
%28 = select i1 %27, i32 %18, i32 5
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds [7 x float], [7 x float] addrspace(2)* @_ZL7lgStops, i64 0, i64 %29
%31 = load float, float addrspace(2)* %30, align 4, !tbaa !34
%32 = fsub fast float %16, %31
%33 = add nuw nsw i32 %28, 1
%34 = zext i32 %33 to i64
%35 = getelementptr inbounds [7 x float], [7 x float] addrspace(2)* @_ZL7lgStops, i64 0, i64 %34
%36 = load float, float addrspace(2)* %35, align 4, !tbaa !34
%37 = fsub fast float %36, %31
%38 = fdiv fast float %32, %37
%39 = tail call fast fastcc <3 x float> @_ZL10toneAtStopDv3_fii(<3 x float> %0, i32 1, i32 %28) #9
%40 = tail call fast fastcc <3 x float> @_ZL10toneAtStopDv3_fii(<3 x float> %0, i32 1, i32 %33) #9
%41 = insertelement <3 x float> undef, float %38, i64 0
%42 = shufflevector <3 x float> %41, <3 x float> undef, <3 x i32> zeroinitializer
%43 = tail call fast <3 x float> @air.mix.v3f32(<3 x float> %39, <3 x float> %40, <3 x float> %42) #1
br label %44
44: ; preds = %26, %6
%45 = phi <3 x float> [ %43, %26 ], [ %0, %6 ]
%46 = getelementptr inbounds %struct.DYUniforms, %struct.DYUniforms addrspace(2)* %1, i64 0, i32 19
%47 = load float, float addrspace(2)* %46, align 8, !tbaa !44
%48 = fcmp fast ogt float %47, 5.000000e-01
%49 = getelementptr inbounds %struct.DYUniforms, %struct.DYUniforms addrspace(2)* %1, i64 0, i32 2
%50 = load float, float addrspace(2)* %49, align 8
%51 = select fast i1 %48, float %50, float 0.000000e+00
%52 = tail call fast float @air.fast_fabs.f32(float %51) #1
%53 = fcmp fast olt float %52, 0x3E7AD7F2A0000000
br i1 %53, label %83, label %54
54: ; preds = %44
%55 = tail call fast float @air.fast_clamp.f32(float %51, float -1.000000e+02, float 1.000000e+02) #1
br label %56
56: ; preds = %59, %54
%57 = phi i32 [ 0, %54 ], [ %60, %59 ]
%58 = icmp eq i32 %57, 5
br i1 %58, label %65, label %59
59: ; preds = %56
%60 = add nuw nsw i32 %57, 1
%61 = zext i32 %60 to i64
%62 = getelementptr inbounds [7 x float], [7 x float] addrspace(2)* @_ZL7lgStops, i64 0, i64 %61
%63 = load float, float addrspace(2)* %62, align 4, !tbaa !34
%64 = fcmp fast ogt float %63, %55
br i1 %64, label %65, label %56, !llvm.loop !43
65: ; preds = %59, %56
%66 = icmp ult i32 %57, 5
%67 = select i1 %66, i32 %57, i32 5
%68 = zext i32 %67 to i64
%69 = getelementptr inbounds [7 x float], [7 x float] addrspace(2)* @_ZL7lgStops, i64 0, i64 %68
%70 = load float, float addrspace(2)* %69, align 4, !tbaa !34
%71 = fsub fast float %55, %70
%72 = add nuw nsw i32 %67, 1
%73 = zext i32 %72 to i64
%74 = getelementptr inbounds [7 x float], [7 x float] addrspace(2)* @_ZL7lgStops, i64 0, i64 %73
%75 = load float, float addrspace(2)* %74, align 4, !tbaa !34
%76 = fsub fast float %75, %70
%77 = fdiv fast float %71, %76
%78 = tail call fast fastcc <3 x float> @_ZL10toneAtStopDv3_fii(<3 x float> %45, i32 2, i32 %67) #9
%79 = tail call fast fastcc <3 x float> @_ZL10toneAtStopDv3_fii(<3 x float> %45, i32 2, i32 %72) #9
%80 = insertelement <3 x float> undef, float %77, i64 0
%81 = shufflevector <3 x float> %80, <3 x float> undef, <3 x i32> zeroinitializer
%82 = tail call fast <3 x float> @air.mix.v3f32(<3 x float> %78, <3 x float> %79, <3 x float> %81) #1
br label %83
83: ; preds = %65, %44
%84 = phi <3 x float> [ %82, %65 ], [ %45, %44 ]
%85 = getelementptr inbounds %struct.DYUniforms, %struct.DYUniforms addrspace(2)* %1, i64 0, i32 20
%86 = load float, float addrspace(2)* %85, align 4, !tbaa !45
%87 = fcmp fast ogt float %86, 5.000000e-01
%88 = getelementptr inbounds %struct.DYUniforms, %struct.DYUniforms addrspace(2)* %1, i64 0, i32 3
%89 = load float, float addrspace(2)* %88, align 4
%90 = select fast i1 %87, float %89, float 0.000000e+00
%91 = tail call fast float @air.fast_fabs.f32(float %90) #1
%92 = fcmp fast olt float %91, 0x3E7AD7F2A0000000
br i1 %92, label %122, label %93
93: ; preds = %83
%94 = tail call fast float @air.fast_clamp.f32(float %90, float -1.000000e+02, float 1.000000e+02) #1
br label %95
95: ; preds = %98, %93
%96 = phi i32 [ 0, %93 ], [ %99, %98 ]
%97 = icmp eq i32 %96, 5
br i1 %97, label %104, label %98
98: ; preds = %95
%99 = add nuw nsw i32 %96, 1
%100 = zext i32 %99 to i64
%101 = getelementptr inbounds [7 x float], [7 x float] addrspace(2)* @_ZL7lgStops, i64 0, i64 %100
%102 = load float, float addrspace(2)* %101, align 4, !tbaa !34
%103 = fcmp fast ogt float %102, %94
br i1 %103, label %104, label %95, !llvm.loop !43
104: ; preds = %98, %95
%105 = icmp ult i32 %96, 5
%106 = select i1 %105, i32 %96, i32 5
%107 = zext i32 %106 to i64
%108 = getelementptr inbounds [7 x float], [7 x float] addrspace(2)* @_ZL7lgStops, i64 0, i64 %107
%109 = load float, float addrspace(2)* %108, align 4, !tbaa !34
%110 = fsub fast float %94, %109
%111 = add nuw nsw i32 %106, 1
%112 = zext i32 %111 to i64
%113 = getelementptr inbounds [7 x float], [7 x float] addrspace(2)* @_ZL7lgStops, i64 0, i64 %112
%114 = load float, float addrspace(2)* %113, align 4, !tbaa !34
%115 = fsub fast float %114, %109
%116 = fdiv fast float %110, %115
%117 = tail call fast fastcc <3 x float> @_ZL10toneAtStopDv3_fii(<3 x float> %84, i32 3, i32 %106) #9
%118 = tail call fast fastcc <3 x float> @_ZL10toneAtStopDv3_fii(<3 x float> %84, i32 3, i32 %111) #9
%119 = insertelement <3 x float> undef, float %116, i64 0
%120 = shufflevector <3 x float> %119, <3 x float> undef, <3 x i32> zeroinitializer
%121 = tail call fast <3 x float> @air.mix.v3f32(<3 x float> %117, <3 x float> %118, <3 x float> %120) #1
br label %122
122: ; preds = %104, %83, %2
%123 = phi <3 x float> [ %0, %2 ], [ %121, %104 ], [ %84, %83 ]
ret <3 x float> %123
}
; Function Attrs: nounwind readnone
declare <3 x float> @air.mix.v3f32(<3 x float>, <3 x float>, <3 x float>) local_unnamed_addr #1
; Function Attrs: inlinehint nounwind readnone
define internal fastcc <3 x float> @_ZL10toneAtStopDv3_fii(<3 x float> %0, i32 %1, i32 %2) unnamed_addr #3 {
%4 = icmp eq i32 %2, 3
br i1 %4, label %91, label %5
5: ; preds = %3
%6 = zext i32 %1 to i64
%7 = sext i32 %2 to i64
%8 = getelementptr inbounds [6 x [7 x float]], [6 x [7 x float]] addrspace(2)* @_ZL11lgToneModes, i64 0, i64 %6, i64 %7
%9 = load float, float addrspace(2)* %8, align 4, !tbaa !34
%10 = fcmp fast ogt float %9, 5.000000e-01
br i1 %10, label %11, label %60
11: ; preds = %5
%12 = extractelement <3 x float> %0, i64 0
%13 = tail call fast float @air.fast_clamp.f32(float %12, float 0.000000e+00, float 1.000000e+00) #1
%14 = fmul fast float %13, 3.200000e+01
%15 = tail call i32 @air.convert.s.i32.f.f32(float %14) #1
%16 = tail call i32 @air.min.s.i32(i32 %15, i32 31) #1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [6 x [7 x [33 x float]]], [6 x [7 x [33 x float]]] addrspace(2)* @_ZL12lgToneCurves, i64 0, i64 %6, i64 %7, i64 %17
%19 = load float, float addrspace(2)* %18, align 4, !tbaa !34
%20 = add nsw i32 %16, 1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [6 x [7 x [33 x float]]], [6 x [7 x [33 x float]]] addrspace(2)* @_ZL12lgToneCurves, i64 0, i64 %6, i64 %7, i64 %21
%23 = load float, float addrspace(2)* %22, align 4, !tbaa !34
%24 = tail call fast float @air.convert.f.f32.s.i32(i32 %16) #1
%25 = fsub fast float %14, %24
%26 = tail call fast float @air.mix.f32(float %19, float %23, float %25) #1
%27 = insertelement <3 x float> undef, float %26, i64 0
%28 = extractelement <3 x float> %0, i64 1
%29 = tail call fast float @air.fast_clamp.f32(float %28, float 0.000000e+00, float 1.000000e+00) #1
%30 = fmul fast float %29, 3.200000e+01
%31 = tail call i32 @air.convert.s.i32.f.f32(float %30) #1
%32 = tail call i32 @air.min.s.i32(i32 %31, i32 31) #1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [6 x [7 x [33 x float]]], [6 x [7 x [33 x float]]] addrspace(2)* @_ZL12lgToneCurves, i64 0, i64 %6, i64 %7, i64 %33
%35 = load float, float addrspace(2)* %34, align 4, !tbaa !34
%36 = add nsw i32 %32, 1
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [6 x [7 x [33 x float]]], [6 x [7 x [33 x float]]] addrspace(2)* @_ZL12lgToneCurves, i64 0, i64 %6, i64 %7, i64 %37
%39 = load float, float addrspace(2)* %38, align 4, !tbaa !34
%40 = tail call fast float @air.convert.f.f32.s.i32(i32 %32) #1
%41 = fsub fast float %30, %40
%42 = tail call fast float @air.mix.f32(float %35, float %39, float %41) #1
%43 = insertelement <3 x float> %27, float %42, i64 1
%44 = extractelement <3 x float> %0, i64 2
%45 = tail call fast float @air.fast_clamp.f32(float %44, float 0.000000e+00, float 1.000000e+00) #1
%46 = fmul fast float %45, 3.200000e+01
%47 = tail call i32 @air.convert.s.i32.f.f32(float %46) #1
%48 = tail call i32 @air.min.s.i32(i32 %47, i32 31) #1
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [6 x [7 x [33 x float]]], [6 x [7 x [33 x float]]] addrspace(2)* @_ZL12lgToneCurves, i64 0, i64 %6, i64 %7, i64 %49
%51 = load float, float addrspace(2)* %50, align 4, !tbaa !34
%52 = add nsw i32 %48, 1
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [6 x [7 x [33 x float]]], [6 x [7 x [33 x float]]] addrspace(2)* @_ZL12lgToneCurves, i64 0, i64 %6, i64 %7, i64 %53
%55 = load float, float addrspace(2)* %54, align 4, !tbaa !34
%56 = tail call fast float @air.convert.f.f32.s.i32(i32 %48) #1
%57 = fsub fast float %46, %56
%58 = tail call fast float @air.mix.f32(float %51, float %55, float %57) #1
%59 = insertelement <3 x float> %43, float %58, i64 2
br label %91
60: ; preds = %5
%61 = tail call fast float @air.dot.v3f32(<3 x float> %0, <3 x float> <float 0x3FCB367A00000000, float 0x3FE6E2EB20000000, float 0x3FB27BB300000000>) #1
%62 = tail call fast float @air.fast_clamp.f32(float %61, float 0.000000e+00, float 1.000000e+00) #1
%63 = fmul fast float %62, 3.200000e+01
%64 = tail call i32 @air.convert.s.i32.f.f32(float %63) #1
%65 = tail call i32 @air.min.s.i32(i32 %64, i32 31) #1
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [6 x [7 x [33 x float]]], [6 x [7 x [33 x float]]] addrspace(2)* @_ZL12lgToneCurves, i64 0, i64 %6, i64 %7, i64 %66
%68 = load float, float addrspace(2)* %67, align 4, !tbaa !34
%69 = add nsw i32 %65, 1
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds [6 x [7 x [33 x float]]], [6 x [7 x [33 x float]]] addrspace(2)* @_ZL12lgToneCurves, i64 0, i64 %6, i64 %7, i64 %70
%72 = load float, float addrspace(2)* %71, align 4, !tbaa !34
%73 = tail call fast float @air.convert.f.f32.s.i32(i32 %65) #1
%74 = fsub fast float %63, %73
%75 = tail call fast float @air.mix.f32(float %68, float %72, float %74) #1
%76 = getelementptr inbounds [6 x [7 x [33 x float]]], [6 x [7 x [33 x float]]] addrspace(2)* @_ZL14lgChromaScales, i64 0, i64 %6, i64 %7, i64 %66
%77 = load float, float addrspace(2)* %76, align 4, !tbaa !34
%78 = getelementptr inbounds [6 x [7 x [33 x float]]], [6 x [7 x [33 x float]]] addrspace(2)* @_ZL14lgChromaScales, i64 0, i64 %6, i64 %7, i64 %70
%79 = load float, float addrspace(2)* %78, align 4, !tbaa !34
%80 = tail call fast float @air.mix.f32(float %77, float %79, float %74) #1
%81 = insertelement <3 x float> undef, float %75, i64 0
%82 = shufflevector <3 x float> %81, <3 x float> undef, <3 x i32> zeroinitializer
%83 = insertelement <3 x float> undef, float %61, i64 0
%84 = shufflevector <3 x float> %83, <3 x float> undef, <3 x i32> zeroinitializer
%85 = fsub fast <3 x float> %0, %84
%86 = insertelement <3 x float> undef, float %80, i64 0
%87 = shufflevector <3 x float> %86, <3 x float> undef, <3 x i32> zeroinitializer
%88 = fmul fast <3 x float> %87, %85
%89 = fadd fast <3 x float> %88, %82
%90 = tail call fast <3 x float> @air.fast_clamp.v3f32(<3 x float> %89, <3 x float> zeroinitializer, <3 x float> <float 1.000000e+00, float 1.000000e+00, float 1.000000e+00>) #1
br label %91
91: ; preds = %60, %11, %3
%92 = phi <3 x float> [ %0, %3 ], [ %59, %11 ], [ %90, %60 ]
ret <3 x float> %92
}
; Function Attrs: nounwind readnone
declare <3 x float> @air.fast_clamp.v3f32(<3 x float>, <3 x float>, <3 x float>) local_unnamed_addr #1
; Function Attrs: nounwind readnone
declare float @air.mix.f32(float, float, float) local_unnamed_addr #1
; Function Attrs: nounwind readnone
declare float @air.convert.f.f32.s.i32(i32) local_unnamed_addr #1
; Function Attrs: nounwind readnone
declare i32 @air.min.s.i32(i32, i32) local_unnamed_addr #1
; Function Attrs: nounwind readnone
declare i32 @air.convert.s.i32.f.f32(float) local_unnamed_addr #1
; Function Attrs: nounwind readnone
declare float @air.fast_fabs.f32(float) local_unnamed_addr #1
; Function Attrs: argmemonly convergent nounwind readonly
declare { <4 x float>, i8 } @air.sample_texture_3d.v4f32(%struct._texture_3d_t addrspace(1)* nocapture readonly, %struct._sampler_t addrspace(2)* nocapture readonly, <3 x float>, i1, <3 x i32>, i1, float, float, i32) local_unnamed_addr #4
; Function Attrs: argmemonly nounwind readonly
declare i32 @air.get_width_texture_3d(%struct._texture_3d_t addrspace(1)* nocapture readonly, i32) local_unnamed_addr #5
; Function Attrs: inlinehint nounwind readnone
define internal fastcc <3 x float> @_ZL13applyExposureDv3_fRU11MTLconstantK17DYUniforms(<3 x float> %0, %struct.DYUniforms addrspace(2)* nocapture readonly dereferenceable(944) %1) unnamed_addr #6 {
%3 = getelementptr inbounds %struct.DYUniforms, %struct.DYUniforms addrspace(2)* %1, i64 0, i32 31
%4 = load float, float addrspace(2)* %3, align 8, !tbaa !40
%5 = fcmp fast ugt float %4, 5.000000e-01
br i1 %5, label %6, label %73
6: ; preds = %2
%7 = getelementptr inbounds %struct.DYUniforms, %struct.DYUniforms addrspace(2)* %1, i64 0, i32 17
%8 = load float, float addrspace(2)* %7, align 16, !tbaa !46
%9 = fcmp fast ogt float %8, 5.000000e-01
br i1 %9, label %10, label %14
10: ; preds = %6
%11 = getelementptr inbounds %struct.DYUniforms, %struct.DYUniforms addrspace(2)* %1, i64 0, i32 0
%12 = load float, float addrspace(2)* %11, align 16, !tbaa !47
%13 = tail call fast float @air.fast_clamp.f32(float %12, float -5.000000e+00, float 5.000000e+00) #1
br label %14
14: ; preds = %10, %6
%15 = phi float [ %13, %10 ], [ 0.000000e+00, %6 ]
%16 = fmul fast float %15, 5.000000e+01
%17 = tail call fast float @air.fast_fabs.f32(float %16) #1
%18 = fcmp fast olt float %17, 0x3E7AD7F2A0000000
br i1 %18, label %48, label %19
19: ; preds = %14
%20 = tail call fast float @air.fast_clamp.f32(float %16, float -1.000000e+02, float 1.000000e+02) #1
br label %21
21: ; preds = %24, %19
%22 = phi i32 [ 0, %19 ], [ %25, %24 ]
%23 = icmp eq i32 %22, 5
br i1 %23, label %30, label %24
24: ; preds = %21
%25 = add nuw nsw i32 %22, 1
%26 = zext i32 %25 to i64
%27 = getelementptr inbounds [7 x float], [7 x float] addrspace(2)* @_ZL7lgStops, i64 0, i64 %26
%28 = load float, float addrspace(2)* %27, align 4, !tbaa !34
%29 = fcmp fast ogt float %28, %20
br i1 %29, label %30, label %21, !llvm.loop !43
30: ; preds = %24, %21
%31 = icmp ult i32 %22, 5
%32 = select i1 %31, i32 %22, i32 5
%33 = zext i32 %32 to i64
%34 = getelementptr inbounds [7 x float], [7 x float] addrspace(2)* @_ZL7lgStops, i64 0, i64 %33
%35 = load float, float addrspace(2)* %34, align 4, !tbaa !34
%36 = fsub fast float %20, %35
%37 = add nuw nsw i32 %32, 1
%38 = zext i32 %37 to i64
%39 = getelementptr inbounds [7 x float], [7 x float] addrspace(2)* @_ZL7lgStops, i64 0, i64 %38
%40 = load float, float addrspace(2)* %39, align 4, !tbaa !34
%41 = fsub fast float %40, %35
%42 = fdiv fast float %36, %41
%43 = tail call fast fastcc <3 x float> @_ZL10toneAtStopDv3_fii(<3 x float> %0, i32 0, i32 %32) #9
%44 = tail call fast fastcc <3 x float> @_ZL10toneAtStopDv3_fii(<3 x float> %0, i32 0, i32 %37) #9
%45 = insertelement <3 x float> undef, float %42, i64 0
%46 = shufflevector <3 x float> %45, <3 x float> undef, <3 x i32> zeroinitializer
%47 = tail call fast <3 x float> @air.mix.v3f32(<3 x float> %43, <3 x float> %44, <3 x float> %46) #1
br label %48
48: ; preds = %30, %14
%49 = phi <3 x float> [ %47, %30 ], [ %0, %14 ]
%50 = tail call fast float @air.fast_fabs.f32(float %15) #1
%51 = fcmp fast ogt float %50, 2.000000e+00
br i1 %51, label %52, label %73
52: ; preds = %48
%53 = fadd fast <3 x float> %49, <float 0x3FAC28F5C0000000, float 0x3FAC28F5C0000000, float 0x3FAC28F5C0000000>
%54 = fmul fast <3 x float> %53, <float 0x3FEE54EDE0000000, float 0x3FEE54EDE0000000, float 0x3FEE54EDE0000000>
%55 = tail call fast <3 x float> @air.fast_fmax.v3f32(<3 x float> %54, <3 x float> zeroinitializer) #1
%56 = tail call fast <3 x float> @air.fast_pow.v3f32(<3 x float> %55, <3 x float> <float 0x4003333340000000, float 0x4003333340000000, float 0x4003333340000000>) #1
%57 = fmul fast <3 x float> %49, <float 0x3FB3D07220000000, float 0x3FB3D07220000000, float 0x3FB3D07220000000>
%58 = fcmp fast ole <3 x float> %49, <float 0x3FA4B5DCC0000000, float 0x3FA4B5DCC0000000, float 0x3FA4B5DCC0000000>
%59 = select reassoc nsz arcp contract afn <3 x i1> %58, <3 x float> %57, <3 x float> %56
%60 = tail call fast float @air.fast_clamp.f32(float %15, float -2.000000e+00, float 2.000000e+00) #1
%61 = fsub fast float %15, %60
%62 = tail call fast float @air.fast_exp2.f32(float %61) #1
%63 = insertelement <3 x float> undef, float %62, i64 0
%64 = shufflevector <3 x float> %63, <3 x float> undef, <3 x i32> zeroinitializer
%65 = fmul fast <3 x float> %64, %59
%66 = tail call fast <3 x float> @air.fast_fmax.v3f32(<3 x float> %65, <3 x float> zeroinitializer) #1
%67 = tail call fast <3 x float> @air.fast_pow.v3f32(<3 x float> %66, <3 x float> <float 0x3FDAAAAAA0000000, float 0x3FDAAAAAA0000000, float 0x3FDAAAAAA0000000>) #1
%68 = fmul fast <3 x float> %67, <float 0x3FF0E147A0000000, float 0x3FF0E147A0000000, float 0x3FF0E147A0000000>
%69 = fadd fast <3 x float> %68, <float 0xBFAC28F5C0000000, float 0xBFAC28F5C0000000, float 0xBFAC28F5C0000000>
%70 = fmul fast <3 x float> %65, <float 0x4029D70A40000000, float 0x4029D70A40000000, float 0x4029D70A40000000>
%71 = fcmp fast ole <3 x float> %65, <float 0x3F69A5C380000000, float 0x3F69A5C380000000, float 0x3F69A5C380000000>
%72 = select reassoc nsz arcp contract afn <3 x i1> %71, <3 x float> %70, <3 x float> %69
br label %73
73: ; preds = %52, %48, %2
%74 = phi <3 x float> [ %0, %2 ], [ %72, %52 ], [ %49, %48 ]
ret <3 x float> %74
}
; Function Attrs: nounwind readnone
declare <3 x float> @air.fast_pow.v3f32(<3 x float>, <3 x float>) local_unnamed_addr #1
; Function Attrs: nounwind readnone
declare <3 x float> @air.fast_fmax.v3f32(<3 x float>, <3 x float>) local_unnamed_addr #1
; Function Attrs: nounwind readnone
declare float @air.fast_exp2.f32(float) local_unnamed_addr #1
; Function Attrs: nounwind readnone
declare <3 x float> @air.convert.f.v3f32.f.v3f16(<3 x half>) local_unnamed_addr #1
; Function Attrs: argmemonly convergent nounwind readonly
declare { <4 x half>, i8 } @air.sample_texture_2d.v4f16(%struct._texture_2d_t addrspace(1)* nocapture readonly, %struct._sampler_t addrspace(2)* nocapture readonly, <2 x float>, i1, <2 x i32>, i1, float, float, i32) local_unnamed_addr #4
; Function Attrs: convergent nounwind
declare void @air.wg.barrier(i32, i32) local_unnamed_addr #7
; Function Attrs: nounwind
declare void @air.atomic.local.store.i32(i32 addrspace(3)* nocapture, i32, i32, i32, i1) local_unnamed_addr #2
attributes #0 = { convergent nounwind "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="128" "no-builtins" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="true" }
attributes #1 = { nounwind readnone }
attributes #2 = { nounwind }
attributes #3 = { inlinehint nounwind readnone "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="96" "no-builtins" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="true" }
attributes #4 = { argmemonly convergent nounwind readonly }
attributes #5 = { argmemonly nounwind readonly }
attributes #6 = { inlinehint nounwind readnone "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="96" "no-builtins" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="true" }
attributes #7 = { convergent nounwind }
attributes #8 = { nobuiltin "no-builtins" }
attributes #9 = { nobuiltin nounwind "no-builtins" }
!llvm.module.flags = !{!0, !1, !2, !3, !4, !5, !6, !7}
!llvm.ident = !{!8}
!air.version = !{!9}
!air.language_version = !{!10}
!air.compile_options = !{!11, !12, !13}
!air.kernel = !{!14}
!air.sampler_states = !{!23}
!0 = !{i32 2, !"SDK Version", [2 x i32] [i32 15, i32 5]}
!1 = !{i32 1, !"wchar_size", i32 4}
!2 = !{i32 7, !"air.max_device_buffers", i32 31}
!3 = !{i32 7, !"air.max_constant_buffers", i32 31}
!4 = !{i32 7, !"air.max_threadgroup_buffers", i32 31}
!5 = !{i32 7, !"air.max_textures", i32 128}
!6 = !{i32 7, !"air.max_read_write_textures", i32 8}
!7 = !{i32 7, !"air.max_samplers", i32 16}
!8 = !{!"Apple metal version 32023.620 (metalfe-32023.620)"}
!9 = !{i32 2, i32 6, i32 0}
!10 = !{!"Metal", i32 3, i32 0, i32 0}
!11 = !{!"air.compile.denorms_disable"}
!12 = !{!"air.compile.fast_math_enable"}
!13 = !{!"air.compile.framebuffer_fetch_enable"}
!14 = !{void (%struct._texture_2d_t addrspace(1)*, %struct._texture_3d_t addrspace(1)*, %struct.DYUniforms addrspace(2)*, float addrspace(1)*, i32)* @dyWhitesSceneStatistics, !15, !16}
!15 = !{}
!16 = !{!17, !18, !19, !21, !22}
!17 = !{i32 0, !"air.texture", !"air.location_index", i32 0, i32 1, !"air.sample", !"air.arg_type_name", !"texture2d<half, sample>", !"air.arg_name", !"source"}
!18 = !{i32 1, !"air.texture", !"air.location_index", i32 1, i32 1, !"air.sample", !"air.arg_type_name", !"texture3d<float, sample>", !"air.arg_name", !"whiteBalanceTexture"}
!19 = !{i32 2, !"air.buffer", !"air.buffer_size", i32 944, !"air.location_index", i32 0, i32 1, !"air.read", !"air.address_space", i32 2, !"air.struct_type_info", !20, !"air.arg_type_size", i32 944, !"air.arg_type_align_size", i32 16, !"air.arg_type_name", !"DYUniforms", !"air.arg_name", !"uniforms"}
!20 = !{i32 0, i32 4, i32 0, !"float", !"exposure", i32 4, i32 4, i32 0, !"float", !"contrast", i32 8, i32 4, i32 0, !"float", !"highlights", i32 12, i32 4, i32 0, !"float", !"shadows", i32 16, i32 4, i32 0, !"float", !"whites", i32 20, i32 4, i32 0, !"float", !"blacks", i32 24, i32 4, i32 0, !"float", !"temperature", i32 28, i32 4, i32 0, !"float", !"tint", i32 32, i32 4, i32 0, !"float", !"saturation", i32 36, i32 4, i32 0, !"float", !"vibrance", i32 40, i32 4, i32 0, !"float", !"texture", i32 44, i32 4, i32 0, !"float", !"clarity", i32 48, i32 4, i32 0, !"float", !"dehaze", i32 52, i32 4, i32 0, !"float", !"inputProfile", i32 56, i32 4, i32 0, !"float", !"preLUTStrength", i32 60, i32 4, i32 0, !"float", !"postLUTStrength", i32 64, i32 16, i32 0, !"float4", !"extraPostLUTStrengths", i32 80, i32 4, i32 0, !"float", !"exposureEnabled", i32 84, i32 4, i32 0, !"float", !"contrastEnabled", i32 88, i32 4, i32 0, !"float", !"highlightsEnabled", i32 92, i32 4, i32 0, !"float", !"shadowsEnabled", i32 96, i32 4, i32 0, !"float", !"whitesEnabled", i32 100, i32 4, i32 0, !"float", !"blacksEnabled", i32 104, i32 4, i32 0, !"float", !"temperatureEnabled", i32 108, i32 4, i32 0, !"float", !"tintEnabled", i32 112, i32 4, i32 0, !"float", !"saturationEnabled", i32 116, i32 4, i32 0, !"float", !"vibranceEnabled", i32 120, i32 4, i32 0, !"float", !"textureEnabled", i32 124, i32 4, i32 0, !"float", !"clarityEnabled", i32 128, i32 4, i32 0, !"float", !"dehazeEnabled", i32 132, i32 4, i32 0, !"float", !"inputSectionEnabled", i32 136, i32 4, i32 0, !"float", !"baseSectionEnabled", i32 140, i32 4, i32 0, !"float", !"colorSectionEnabled", i32 144, i32 4, i32 0, !"float", !"lookSectionEnabled", i32 160, i32 16, i32 0, !"float4", !"extraLookSectionEnableds", i32 176, i32 4, i32 0, !"float", !"curveSectionEnabled", i32 180, i32 4, i32 0, !"float", !"hslSectionEnabled", i32 184, i32 4, i32 0, !"float", !"curveShadows", i32 188, i32 4, i32 0, !"float", !"curveDarks", i32 192, i32 4, i32 0, !"float", !"curveLights", i32 196, i32 4, i32 0, !"float", !"curveHighlights", i32 200, i32 4, i32 0, !"float", !"redCurveShadows", i32 204, i32 4, i32 0, !"float", !"redCurveHighlights", i32 208, i32 4, i32 0, !"float", !"greenCurveShadows", i32 212, i32 4, i32 0, !"float", !"greenCurveHighlights", i32 216, i32 4, i32 0, !"float", !"blueCurveShadows", i32 220, i32 4, i32 0, !"float", !"blueCurveHighlights", i32 224, i32 16, i32 0, !"float4", !"curveX", i32 240, i32 8, i32 0, !"float2", !"redCurveX", i32 248, i32 8, i32 0, !"float2", !"greenCurveX", i32 256, i32 8, i32 0, !"float2", !"blueCurveX", i32 272, i32 16, i32 0, !"float4", !"hslHueA", i32 288, i32 16, i32 0, !"float4", !"hslHueB", i32 304, i32 16, i32 0, !"float4", !"hslSatA", i32 320, i32 16, i32 0, !"float4", !"hslSatB", i32 336, i32 16, i32 0, !"float4", !"hslLumA", i32 352, i32 16, i32 0, !"float4", !"hslLumB", i32 368, i32 16, i32 0, !"float3", !"hslCustomSample", i32 384, i32 16, i32 0, !"float3", !"hslCustomAdjust", i32 400, i32 4, i32 0, !"float", !"colorGradingSectionEnabled", i32 404, i32 4, i32 0, !"float", !"colorGradingBlending", i32 408, i32 4, i32 0, !"float", !"colorGradingBalance", i32 416, i32 16, i32 0, !"float4", !"colorGradingHueSatA", i32 432, i32 16, i32 0, !"float4", !"colorGradingHueSatB", i32 448, i32 16, i32 0, !"float3", !"colorGradingLuma", i32 464, i32 16, i32 0, !"float3", !"skinProtection", i32 480, i32 4, i32 0, !"float", !"primariesSectionEnabled", i32 484, i32 4, i32 0, !"float", !"redPrimaryHue", i32 488, i32 4, i32 0, !"float", !"redPrimarySaturation", i32 492, i32 4, i32 0, !"float", !"greenPrimaryHue", i32 496, i32 4, i32 0, !"float", !"greenPrimarySaturation", i32 500, i32 4, i32 0, !"float", !"bluePrimaryHue", i32 504, i32 4, i32 0, !"float", !"bluePrimarySaturation", i32 512, i32 16, i32 0, !"float3", !"primariesM0", i32 528, i32 16, i32 0, !"float3", !"primariesM1", i32 544, i32 16, i32 0, !"float3", !"primariesM2", i32 560, i32 16, i32 0, !"float3", !"hslCustomRange", i32 576, i32 4, i32 0, !"float", !"hslCustomVisualize", i32 592, i32 16, i32 0, !"float3", !"colorGradingGlobal", i32 608, i32 4, i32 0, !"float", !"levelsSectionEnabled", i32 624, i32 16, i32 0, !"float4", !"levelsInputBlack", i32 640, i32 16, i32 0, !"float4", !"levelsGamma", i32 656, i32 16, i32 0, !"float4", !"levelsInputWhite", i32 672, i32 16, i32 0, !"float4", !"levelsOutputBlack", i32 688, i32 16, i32 0, !"float4", !"levelsOutputWhite", i32 704, i32 4, i32 0, !"float", !"blackWhiteSectionEnabled", i32 720, i32 16, i32 0, !"float4", !"blackWhiteMixA", i32 736, i32 8, i32 0, !"float2", !"blackWhiteMixB", i32 744, i32 8, i32 0, !"float2", !"blackWhiteTint", i32 752, i32 4, i32 0, !"float", !"colorBalanceSectionEnabled", i32 756, i32 4, i32 0, !"float", !"colorBalancePreserveLuminosity", i32 768, i32 16, i32 0, !"float3", !"colorBalanceShadows", i32 784, i32 16, i32 0, !"float3", !"colorBalanceMidtones", i32 800, i32 16, i32 0, !"float3", !"colorBalanceHighlights", i32 816, i32 Line truncated
!21 = !{i32 3, !"air.buffer", !"air.location_index", i32 1, i32 1, !"air.read_write", !"air.address_space", i32 1, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"float", !"air.arg_name", !"sceneLevel"}
!22 = !{i32 4, !"air.thread_index_in_threadgroup", !"air.arg_type_name", !"uint", !"air.arg_name", !"tid"}
!23 = !{!"air.sampler_state", i64 addrspace(2)* @__air_sampler_state}
!24 = !{!25}
!25 = distinct !{!25, !26, !"air-alias-scope-textures"}
!26 = distinct !{!26, !"air-alias-scopes(dyWhitesSceneStatistics)"}
!27 = !{!28, !29}
!28 = distinct !{!28, !26, !"air-alias-scope-arg(2)"}
!29 = distinct !{!29, !26, !"air-alias-scope-arg(3)"}
!30 = distinct !{!30, !31}
!31 = !{!"llvm.loop.mustprogress"}
!32 = distinct !{!32, !31}
!33 = distinct !{!33, !31}
!34 = !{!35, !35, i64 0}
!35 = !{!"float", !36, i64 0}
!36 = !{!"omnipotent char", !37, i64 0}
!37 = !{!"Simple C++ TBAA"}
!38 = !{!29}
!39 = !{!25, !28}
!40 = !{!41, !35, i64 136}
!41 = !{!"_ZTS17DYUniforms", !35, i64 0, !35, i64 4, !35, i64 8, !35, i64 12, !35, i64 16, !35, i64 20, !35, i64 24, !35, i64 28, !35, i64 32, !35, i64 36, !35, i64 40, !35, i64 44, !35, i64 48, !35, i64 52, !35, i64 56, !35, i64 60, !36, i64 64, !35, i64 80, !35, i64 84, !35, i64 88, !35, i64 92, !35, i64 96, !35, i64 100, !35, i64 104, !35, i64 108, !35, i64 112, !35, i64 116, !35, i64 120, !35, i64 124, !35, i64 128, !35, i64 132, !35, i64 136, !35, i64 140, !35, i64 144, !36, i64 160, !35, i64 176, !35, i64 180, !35, i64 184, !35, i64 188, !35, i64 192, !35, i64 196, !35, i64 200, !35, i64 204, !35, i64 208, !35, i64 212, !35, i64 216, !35, i64 220, !36, i64 224, !36, i64 240, !36, i64 248, !36, i64 256, !36, i64 272, !36, i64 288, !36, i64 304, !36, i64 320, !36, i64 336, !36, i64 352, !36, i64 368, !36, i64 384, !35, i64 400, !35, i64 404, !35, i64 408, !36, i64 416, !36, i64 432, !36, i64 448, !36, i64 464, !35, i64 480, !35, i64 484, !35, i64 488, !35, i64 492, !35, i64 496, !35, i64 500, !35, i64 504, !36, i64 512, !36, i64 528, !36, i64 544, !36, i64 560, !35, i64 576, !36, i64 592, !35, i64 608, !36, i64 624, !36, i64 640, !36, i64 656, !36, i64 672, !36, i64 688, !35, i64 704, !36, i64 720, !36, i64 736, !36, i64 744, !35, i64 752, !35, i64 756, !36, i64 768, !36, i64 784, !36, i64 800, !36, i64 816, !36, i64 832, !36, i64 848, !36, i64 864, !36, i64 880, !36, i64 896, !36, i64 912, !36, i64 928}
!42 = !{!41, !35, i64 84}
!43 = distinct !{!43, !31}
!44 = !{!41, !35, i64 88}
!45 = !{!41, !35, i64 92}
!46 = !{!41, !35, i64 80}
!47 = !{!41, !35, i64 0}
+59
查看文件
@@ -0,0 +1,59 @@
{
"artifact": "/Library/Plug-Ins/FxPlug/LumiGrade.app/Contents/PlugIns/LumiGrade XPC Service.pluginkit/Contents/Resources/default.metallib",
"sha256": "dfb294c9584d3ff23d3ff660c2a2a80c506b31893caf731babd6f4ddddb8fb77",
"size": 162272,
"source_authority": "shipped-artifact; static instruction graph, not original source",
"tool": "xcrun metal-opt -S (Apple Metal Toolchain 27.1)",
"source_modules": [
{
"path": "module0.air",
"offset": 971,
"size": 26272,
"bitcode_size": 26252,
"cputype": 4294967295
},
{
"path": "module1.air",
"offset": 27243,
"size": 50196,
"bitcode_size": 50176,
"cputype": 4294967295
},
{
"path": "module2.air",
"offset": 77451,
"size": 3808,
"bitcode_size": 3788,
"cputype": 4294967295
},
{
"path": "module3.air",
"offset": 81259,
"size": 57312,
"bitcode_size": 57292,
"cputype": 4294967295
},
{
"path": "module4.air",
"offset": 138571,
"size": 4480,
"bitcode_size": 4460,
"cputype": 4294967295
}
],
"changes": [
"DYGradeKernel is callable color helper, texture-center sample and alpha boundary owned by DYGrade.metal",
"Trial licensing/watermark entry paths, function, glyph table and metadata removed; no authorization or network logic included",
"Uniform type renamed to DYUniforms with exact 944-byte layout",
"Statistics and LUT export kernels renamed to Dayu names; math preserved",
"CPU-generated white-balance, HSL-mixer, color-grading 3D LUT data remains external input",
"AIR target deployment raised from macOS13.0/AIR2.5 to macOS14.6/AIR2.6 for linking with the current Metal toolchain; numeric operations unchanged",
"Required sampler-state metadata preserved when extracting callable arithmetic helper"
],
"coverage": "Static exact arithmetic retained for finite target version; runtime parity requires independent GPU samples, CPU LUT generation and host integration.",
"versioned_source_sha256": {
"tools/kernels/DYGradeKernel.ll": "94901d0ba327d697272be669a5fc29aca0ec98295036ef9fb316584c15f0bf1e",
"tools/kernels/DYStatisticsKernel.ll": "30b7a5108671247372a78944ecaf1d600fd5e40f41a9febb7d6e39265727d3e3",
"tools/kernels/DYLUTExportKernel.ll": "f386258f59bbe5f429edd5977c0eaadba4315a2864ddc5c75e25c9dd4260de54"
}
}
+41
查看文件
@@ -0,0 +1,41 @@
# 可重建调色内核
生产构建只读取本目录的 LLVM AIR 文本和项目的 `DYGrade.metal`,不读取原厂 App、原始 metallib、网络或授权状态。来源、原始模块范围和改动见 `PROVENANCE.json`。这些文本是从已交付着色器还原的指令图,不是原始 Metal 源码。
```sh
python3 tools/build_kernels.py --output /absolute/default.metallib --intermediates /absolute/cache
```
`DYGradeKernel.ll` 保留参考颜色数学:线性输入转 sRGB 编码域 → 输入 LUT → RGB 三原色矩阵 → 曝光 → 白平衡 LUT → 对比/高光/阴影 → 自适应白场 → 黑场 → 局部纹理/清晰度/去雾 → 主及 RGB 曲线 → 主及 RGB 色阶 → 色彩平衡 → 8 色 HSL LUT 与自定义 HSL → 分级 LUT → 自然饱和/饱和度 → 黑白 → 5 层风格 LUT → 肤色保护 → 线性输出。中性参数直接返回输入;各章节和单项旁路保留。原许可、水印、字形表及其参数已移除。
CPU 和 Metal 共用 `DYUniforms.h`。大小 944 字节、16 字节对齐,102 个字段逐一检查偏移。普通调整中性为 0;色阶 white 为 255、gamma 为 1;黑白模式默认关闭;额外曲线点的 X 小于 0 表示该点不存在。白平衡、8 色 HSL 和分级由 CPU 生成 3D LUT,不能拿 identity 占位声称完成这些功能。
`dyVertex` 使用 buffer0 `DYVertex2D[4]`、buffer1 `uint2 viewport`;像素位置围绕输出中心,UV 对应输入纹理。`dyFragment` 绑定:
| 位置 | 纹理 |
| --- | --- |
| 0 | linear straight RGBA source |
| 1 | 输入 3D LUT |
| 2–6 | 按顺序混合的 5 层风格 LUT |
| 7 | HSL mixer 3D LUT |
| 8 | 白平衡 3D LUT |
| 9 | 色彩分级 3D LUT |
fragment buffer0 为 `DYUniforms`,buffer1 为 `float sceneLevel`,buffer2 必须绑定 16 字节 `DYRenderOptions`。其首 uint `outputPremultiplied` 控制处理后是否乘回 alpha,其余为 0。source 应已是 straight RGB;若宿主提供预乘颜色,先运行 `dyUnpremultiply`(texture0 读源、texture1 写不同的 RGBA16Float 目标),统计与所有邻域采样都使用该 straight 纹理。alpha<=0 输出 RGBA0;非零 alpha 保留输入 alpha。半精度转换会产生量化误差。
`dyPreview` 为每实例缩略采样核:texture0 straight linear source、buffer0 写 `float4[4096]`;调度64×64,每格按归一化中心采样,RGB使用标准sRGB分段编码,alpha原样保留。不夹断HDR或负值;CPU用途自行决定显示、统计的有效范围。
局部滤镜最大采样半径 18×1.7=30.6 像素;tile 请求至少 32 像素 halo,并设置正确的 UV。自适应白场必须采用全帧统计;不能逐 tile 算独立白场。
`dyWhitesSceneStatistics` 绑定 texture0 source、texture1 白平衡 LUT、buffer0 uniforms、buffer1 写 float。必须只调度 1 个 threadgroup、每组 256 个线程。固定取 256×256 均匀网格,跳过 alpha<=0;统计 96%–99.5% 亮度区间,结果钳制 0.35–1。此路径按参考行为不执行输入 LUT/三原色矩阵。
`dyLUTExportKernel` 绑定 texture0–8 为上表 1–9;buffer0 uniforms、buffer1 写 float RGB、buffer2 uint cubeSize;调度 cubeSize³ 个线性线程。输出 red-fastest RGB triples(每格3个float)。空间纹理/清晰度无法写进 3D LUT,参考导出路径本身也省略这些操作。自适应白场按导出核既定逻辑处理,不能把导出 LUT 等同于任意画面渲染。
GPU 检查只运行命令行,不启动测试 App:
```sh
xcrun clang++ -std=c++17 -fobjc-arc -framework Foundation -framework Metal tools/verify_gpu.mm -o /absolute/cache/verify_gpu
/absolute/cache/verify_gpu /absolute/default.metallib verification/GPU.json
```
验证工具只读加载安装的原厂着色器作为独立数学对照,不把其库放进交付物。测试状态、设备、哈希、最大误差和未覆盖范围保存在报告中。原 GPU 的 half 输入/输出在此保留,不能将报告解释为原生 32 位 HDR 精度或宿主导出验收。
+78
查看文件
@@ -0,0 +1,78 @@
// Focused reconstruction checks: source data integrity, texture axis order and table endpoints.
#define DY_COLOR_TABLES_TESTING 1
#import "../大鱼调色/Plugin/DYColorTables.h"
#import <CommonCrypto/CommonDigest.h>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
static void require(bool condition,const char *message){if(!condition){fprintf(stderr,"FAIL: %s\n",message);exit(1);}}
static void closeColor(vector_float3 a,vector_float3 b,const char *message,float tolerance=3e-6f){require(simd_reduce_max(simd_abs(a-b))<=tolerance,message);}
static vector_float3 cubeColor(NSData *data,int r,int g,int b){auto p=(const vector_float4 *)data.bytes;vector_float4 c=p[(b*33+g)*33+r];return {c.x,c.y,c.z};}
static vector_float3 referenceSample(NSData *tables,int table,vector_float3 c){
const uint8_t *bytes=(const uint8_t *)tables.bytes;
int cell[3];double f[3],sum[3]={0,0,0};
for(int i=0;i<3;i++){double position=std::fmin(1.,std::fmax(0.,double(c[i])))*16.;cell[i]=std::min(15,int(position));f[i]=position-cell[i];}
for(int dr=0;dr<2;dr++)for(int dg=0;dg<2;dg++)for(int db=0;db<2;db++){
double w=(dr?f[0]:1-f[0])*(dg?f[1]:1-f[1])*(db?f[2]:1-f[2]);
size_t at=(table*17*17*17+((cell[0]+dr)*17+cell[1]+dg)*17+cell[2]+db)*3;
for(int i=0;i<3;i++)sum[i]+=double(bytes[at+i])*w/255.;
}
return {(float)sum[0],(float)sum[1],(float)sum[2]};
}
int main(int argc,const char *argv[]){@autoreleasepool{
require(argc==2,"usage: verify_color_tables <DayuColorTables.bin>");
NSData *file=[NSData dataWithContentsOfFile:[NSString stringWithUTF8String:argv[1]]];require(file!=nil,"table resource exists");
uint8_t digest[CC_SHA256_DIGEST_LENGTH];CC_SHA256(file.bytes,(CC_LONG)file.length,digest);
char hex[65];for(int i=0;i<32;i++)snprintf(hex+i*2,3,"%02x",digest[i]);
require(strcmp(hex,"e67ff4dbcce35cb7765752acff4405be5c934d913ef1396b2ca3fc6dc8a85190")==0,"MIT upstream source table SHA-256");
NSError *error=nil;NSData *tables=DYDecodeColorTables(file,&error);require(tables.length==763*17*17*17*3,"decoded dimensions");require(error==nil,"successful decode has no error");
require(DYDecodeColorTables([NSData dataWithBytes:"bad" length:3],&error)==nil&&error!=nil,"invalid resource is rejected");
NSMutableData *wrong=[file mutableCopy];((uint8_t *)wrong.mutableBytes)[4]=16;error=nil;require(DYDecodeColorTables(wrong,&error)==nil&&error!=nil,"incompatible lattice is rejected");[wrong release];
// Off-grid and boundary queries use an independent double-precision oracle.
const vector_float3 samples[]={{0,0,0},{1,1,1},{.123f,.679f,.324f},{.95f,.02f,.38f},{.25f,.5f,.75f},{1.2f,-.1f,.66f}};
for(int index:{0,40,80,285,325,365,455,601,637,762})for(auto c:samples)
closeColor(DYSampleColorTable(tables,index,c),referenceSample(tables,index,c),"17³ source trilinear sampling");
// White balance interpolates the four neighboring temperature/tint tables.
NSData *wb=DYComposeWhiteBalance(tables,12.5f,-37.5f);
for(int b:{0,7,32})for(int g:{0,19,32})for(int r:{0,11,32}){
vector_float3 c={(float)r/32.f,(float)g/32.f,(float)b/32.f};
vector_float3 expected=(referenceSample(tables,38,c)+referenceSample(tables,39,c)+referenceSample(tables,47,c)+referenceSample(tables,48,c))*.25f;
closeColor(cubeColor(wb,r,g,b),expected,"WB bilinear table blend and R-fastest texture order");
}
float zero[8]={0};
NSData *neutral=DYComposeHSL(tables,zero,zero,zero);
for(int b:{0,13,32})for(int g:{0,7,32})for(int r:{0,21,32})
closeColor(cubeColor(neutral,r,g,b),(vector_float3){r/32.f,g/32.f,b/32.f},"neutral HSL identity",0);
for(int kind=0;kind<3;kind++)for(int color=0;color<8;color++){
float h[8]={0},s[8]={0},l[8]={0};float *values[3]={l,s,h};values[kind][color]=100;
NSData *out=DYComposeHSL(tables,h,s,l);
int table=285+(kind*8+color)*5+4;
vector_float3 c={.3125f,.6875f,.125f};
closeColor(cubeColor(out,10,22,4),referenceSample(tables,table,c),"all 24 HSL controls select the correct endpoint table");
}
// A single full-strength wheel must reduce to its exact measured endpoint.
const int endpoint[4]={601,529,565,637};
for(int wheel=0;wheel<4;wheel++){
float p[14]={0};p[wheel*3+1]=100;p[12]=50;
NSData *out=DYComposeGrading(tables,p);
closeColor(cubeColor(out,9,20,29),referenceSample(tables,endpoint[wheel],(vector_float3){9/32.f,20/32.f,29/32.f}),"grading wheel endpoint order");
p[wheel*3]=360;NSData *wrapped=DYComposeGrading(tables,p);
require([wrapped isEqualToData:out],"grading hue wraps 360 to zero");
}
const int luminanceEndpoint[4]={752,747,757,762};
for(int wheel=0;wheel<4;wheel++){
float p[14]={0};p[wheel*3+2]=100;
NSData *out=DYComposeGrading(tables,p);
closeColor(cubeColor(out,9,20,29),referenceSample(tables,luminanceEndpoint[wheel],(vector_float3){9/32.f,20/32.f,29/32.f}),"grading luminance endpoint order");
}
DYUniforms u={};[DYColorTables fillPrimaries:&u];
closeColor(u.primariesM0,(vector_float3){1,0,0},"neutral primaries column0",0);closeColor(u.primariesM1,(vector_float3){0,1,0},"neutral primaries column1",0);closeColor(u.primariesM2,(vector_float3){0,0,1},"neutral primaries column2",0);
for(int control=0;control<6;control++){
DYUniforms v={};float *fields[]={&v.redPrimaryHue,&v.redPrimarySaturation,&v.greenPrimaryHue,&v.greenPrimarySaturation,&v.bluePrimaryHue,&v.bluePrimarySaturation};*fields[control]=50;[DYColorTables fillPrimaries:&v];
closeColor(v.primariesM0+v.primariesM1+v.primariesM2,(vector_float3){1,1,1},"primaries preserves the D65 white point",2e-5f);
require(simd_reduce_max(simd_abs(v.primariesM0-(vector_float3){1,0,0}))+simd_reduce_max(simd_abs(v.primariesM1-(vector_float3){0,1,0}))+simd_reduce_max(simd_abs(v.primariesM2-(vector_float3){0,0,1}))>1e-4f,"all six primary controls change the matrix");
}
printf("PASS: resource integrity, rejection, trilinear oracle, WB blend, 24 HSL endpoints, 4 grading wheels, hue wrapping, 4 luminance endpoints and 6 primaries\n");
}}
+218
查看文件
@@ -0,0 +1,218 @@
// Independent, headless oracle check. Reference application is read only and
// never used by production builds. See tools/kernels/README.md for scope.
#import <Foundation/Foundation.h>
#import <Metal/Metal.h>
#include <CommonCrypto/CommonDigest.h>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include "../大鱼调色/Plugin/DYUniforms.h"
static id<MTLDevice> gpu;
static id<MTLCommandQueue> queue;
using Pixels = std::vector<__fp16>;
static void need(bool valid, NSString* message) {
if (!valid) @throw [NSException exceptionWithName:@"GPUVerification" reason:message userInfo:nil];
}
static void finish(id<MTLCommandBuffer> commands) {
[commands commit]; [commands waitUntilCompleted];
need(commands.status == MTLCommandBufferStatusCompleted, commands.error.description ?: @"GPU command failed");
}
static NSString* digest(NSString* path) {
NSData* data = [NSData dataWithContentsOfFile:path]; need(data != nil, path);
unsigned char hash[CC_SHA256_DIGEST_LENGTH]; CC_SHA256(data.bytes, (CC_LONG)data.length, hash);
NSMutableString* result = [NSMutableString string];
for (unsigned char byte : hash) [result appendFormat:@"%02x", byte];
return result;
}
static DYUniforms defaults() {
DYUniforms u = {};
u.exposureEnabled=u.contrastEnabled=u.highlightsEnabled=u.shadowsEnabled=1;
u.whitesEnabled=u.blacksEnabled=u.temperatureEnabled=u.tintEnabled=1;
u.saturationEnabled=u.vibranceEnabled=u.textureEnabled=u.clarityEnabled=u.dehazeEnabled=1;
u.inputSectionEnabled=u.baseSectionEnabled=u.colorSectionEnabled=u.lookSectionEnabled=1;
u.extraLookSectionEnableds = (DYFloat4){1,1,1,1};
u.curveSectionEnabled = u.hslSectionEnabled = u.colorGradingSectionEnabled = 1;
u.primariesSectionEnabled = u.levelsSectionEnabled = u.colorBalanceSectionEnabled = 1;
u.levelsGamma = (DYFloat4){1,1,1,1};
u.levelsInputWhite = u.levelsOutputWhite = (DYFloat4){255,255,255,255};
u.curveX = (DYFloat4){.2f,.4f,.6f,.8f};
u.redCurveX = u.greenCurveX = u.blueCurveX = (DYFloat2){.25f,.75f};
u.curveExtraX = u.redCurveExtraX = u.greenCurveExtraX = u.blueCurveExtraX = (DYFloat4){-1,-1,-1,-1};
u.primariesM0 = (DYFloat3){1,0,0}; u.primariesM1 = (DYFloat3){0,1,0}; u.primariesM2 = (DYFloat3){0,0,1};
u.colorBalancePreserveLuminosity = 1;
u.hslCustomRange = (DYFloat3){.08f,.4f,.4f};
return u;
}
static id<MTLTexture> image(const Pixels& values, NSUInteger width, NSUInteger height) {
MTLTextureDescriptor* d = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatRGBA16Float width:width height:height mipmapped:NO];
d.storageMode = MTLStorageModeShared; d.usage = MTLTextureUsageShaderRead | MTLTextureUsageRenderTarget | MTLTextureUsageShaderWrite;
id<MTLTexture> result = [gpu newTextureWithDescriptor:d]; need(result != nil, @"source texture");
if (!values.empty()) [result replaceRegion:MTLRegionMake2D(0,0,width,height) mipmapLevel:0 withBytes:values.data() bytesPerRow:width*8];
return result;
}
static id<MTLTexture> lut(bool transformed) {
const NSUInteger n = 17;
MTLTextureDescriptor* d = [[MTLTextureDescriptor alloc] init];
d.textureType = MTLTextureType3D; d.pixelFormat = MTLPixelFormatRGBA32Float;
d.width = d.height = d.depth = n; d.storageMode = MTLStorageModeShared; d.usage = MTLTextureUsageShaderRead;
std::vector<float> values(n*n*n*4);
for (NSUInteger z=0; z<n; ++z) for (NSUInteger y=0; y<n; ++y) for (NSUInteger x=0; x<n; ++x) {
float r=float(x)/(n-1), g=float(y)/(n-1), b=float(z)/(n-1); NSUInteger p=((z*n+y)*n+x)*4;
values[p] = transformed ? .82f*r+.09f*g+.02f : r;
values[p+1] = transformed ? .87f*g+.03f*b+.01f : g;
values[p+2] = transformed ? .78f*b+.07f*r+.03f : b;
values[p+3] = 1;
}
id<MTLTexture> result = [gpu newTextureWithDescriptor:d]; need(result != nil, @"LUT texture");
[result replaceRegion:MTLRegionMake3D(0,0,0,n,n,n) mipmapLevel:0 slice:0 withBytes:values.data() bytesPerRow:n*16 bytesPerImage:n*n*16];
return result;
}
static id<MTLRenderPipelineState> renderPipeline(id<MTLLibrary> library, bool dayu) {
MTLRenderPipelineDescriptor* d = [[MTLRenderPipelineDescriptor alloc] init];
d.vertexFunction = [library newFunctionWithName:dayu ? @"dyVertex" : @"vertexShader"];
d.fragmentFunction = [library newFunctionWithName:dayu ? @"dyFragment" : @"fragmentShader"];
d.colorAttachments[0].pixelFormat = MTLPixelFormatRGBA16Float;
NSError* error = nil; id<MTLRenderPipelineState> p = [gpu newRenderPipelineStateWithDescriptor:d error:&error];
need(p != nil, error.description ?: @"render pipeline"); return p;
}
static Pixels render(id<MTLRenderPipelineState> pipeline, bool dayu, id<MTLTexture> source,
NSArray<id<MTLTexture>>* textures, const DYUniforms& u, NSUInteger width, NSUInteger height,
float u0=0, float u1=1, bool premultiplied=false) {
id<MTLTexture> destination=image({},width,height);
MTLRenderPassDescriptor* pass=[MTLRenderPassDescriptor renderPassDescriptor];
pass.colorAttachments[0].texture=destination; pass.colorAttachments[0].loadAction=MTLLoadActionClear;
pass.colorAttachments[0].storeAction=MTLStoreActionStore;
id<MTLCommandBuffer> commands=[queue commandBuffer]; id<MTLRenderCommandEncoder> e=[commands renderCommandEncoderWithDescriptor:pass];
[e setRenderPipelineState:pipeline];
float hw=width*.5f, hh=height*.5f;
DYVertex2D vertices[]={{{hw,-hh},{u1,1}},{{-hw,-hh},{u0,1}},{{hw,hh},{u1,0}},{{-hw,hh},{u0,0}}};
vector_uint2 viewport={(unsigned)width,(unsigned)height};
[e setVertexBytes:vertices length:sizeof(vertices) atIndex:0]; [e setVertexBytes:&viewport length:sizeof(viewport) atIndex:1];
[e setFragmentTexture:source atIndex:0];
for (NSUInteger i=0;i<textures.count;++i) [e setFragmentTexture:textures[i] atIndex:i+1];
[e setFragmentBytes:&u length:sizeof(u) atIndex:0]; float scene=.73f; [e setFragmentBytes:&scene length:4 atIndex:1];
if(dayu) { DYRenderOptions options={}; options.outputPremultiplied=premultiplied; [e setFragmentBytes:&options length:sizeof(options) atIndex:2]; }
else { float disabledWatermark[8]={}; [e setFragmentBytes:disabledWatermark length:sizeof(disabledWatermark) atIndex:2]; }
[e drawPrimitives:MTLPrimitiveTypeTriangleStrip vertexStart:0 vertexCount:4]; [e endEncoding]; finish(commands);
Pixels output(width*height*4); [destination getBytes:output.data() bytesPerRow:width*8 fromRegion:MTLRegionMake2D(0,0,width,height) mipmapLevel:0]; return output;
}
static NSDictionary* compare(NSString* name, const Pixels& a, const Pixels& b, bool skipZeroAlphaRGB=false, double tolerance=0) {
need(a.size()==b.size(),@"image sizes differ"); size_t compared=0, different=0; double maxError=0;
for(size_t i=0;i<a.size();++i) {
if(skipZeroAlphaRGB && i%4!=3 && a[(i/4)*4+3]==0) continue;
double delta=std::abs(double(a[i])-double(b[i]));
need(std::isfinite(delta),@"non-finite output"); ++compared; if(delta>tolerance)++different; maxError=std::max(maxError,delta);
}
return @{@"name":name,@"components":@(compared),@"differentAboveTolerance":@(different),@"maxAbsoluteError":@(maxError),@"tolerance":@(tolerance),@"pass":@(different==0)};
}
static NSDictionary* statistics(id<MTLLibrary> reference,id<MTLLibrary> dayu,id<MTLTexture> source,id<MTLTexture> identity,const DYUniforms& u) {
float values[2]={}; id<MTLLibrary> libraries[]={reference,dayu}; NSString* names[]={@"whitesSceneStatistics",@"dyWhitesSceneStatistics"};
for(int i=0;i<2;++i) {
NSError* error=nil; id<MTLComputePipelineState> p=[gpu newComputePipelineStateWithFunction:[libraries[i] newFunctionWithName:names[i]] error:&error]; need(p!=nil,error.description);
id<MTLBuffer> result=[gpu newBufferWithLength:4 options:MTLResourceStorageModeShared];
id<MTLCommandBuffer> cb=[queue commandBuffer];id<MTLComputeCommandEncoder> e=[cb computeCommandEncoder];[e setComputePipelineState:p];
[e setTexture:source atIndex:0];[e setTexture:identity atIndex:1];[e setBytes:&u length:sizeof(u) atIndex:0];[e setBuffer:result offset:0 atIndex:1];
[e dispatchThreadgroups:MTLSizeMake(1,1,1) threadsPerThreadgroup:MTLSizeMake(256,1,1)];[e endEncoding];finish(cb);memcpy(&values[i],result.contents,4);
}
return @{@"name":@"scene-statistics",@"reference":@(values[0]),@"dayu":@(values[1]),@"pass":@(memcmp(values,values+1,4)==0)};
}
static NSDictionary* exportLUT(id<MTLLibrary> reference,id<MTLLibrary> dayu,NSArray<id<MTLTexture>>* textures,const DYUniforms& u) {
const unsigned n=17; const size_t components=n*n*n*3;std::vector<float> outputs[2];
id<MTLLibrary> libraries[]={reference,dayu};NSString* names[]={@"lutExportKernel",@"dyLUTExportKernel"};
for(int i=0;i<2;++i) {
NSError* error=nil; id<MTLComputePipelineState> p=[gpu newComputePipelineStateWithFunction:[libraries[i] newFunctionWithName:names[i]] error:&error];need(p!=nil,error.description);
id<MTLBuffer> result=[gpu newBufferWithLength:components*4 options:MTLResourceStorageModeShared];
id<MTLCommandBuffer> cb=[queue commandBuffer];id<MTLComputeCommandEncoder> e=[cb computeCommandEncoder];[e setComputePipelineState:p];
for(NSUInteger t=0;t<textures.count;++t)[e setTexture:textures[t] atIndex:t];
[e setBytes:&u length:sizeof(u) atIndex:0];[e setBuffer:result offset:0 atIndex:1];[e setBytes:&n length:4 atIndex:2];
[e dispatchThreads:MTLSizeMake(n*n*n,1,1) threadsPerThreadgroup:MTLSizeMake(64,1,1)];[e endEncoding];finish(cb);
outputs[i].resize(components);memcpy(outputs[i].data(),result.contents,components*4);
}
size_t differences=0;double maxError=0;for(size_t j=0;j<components;++j){double d=std::abs(double(outputs[0][j])-outputs[1][j]);need(std::isfinite(d),@"nonfinite LUT");if(d>0)++differences;maxError=std::max(maxError,d);}
return @{@"name":@"LUT-export-17",@"components":@(components),@"differentComponents":@(differences),@"maxAbsoluteError":@(maxError),@"pass":@(differences==0)};
}
static Pixels unpremultiply(id<MTLLibrary> library,id<MTLTexture> source) {
NSError* error=nil;
auto pipeline=[gpu newComputePipelineStateWithFunction:[library newFunctionWithName:@"dyUnpremultiply"] error:&error];need(pipeline!=nil,error.description);
auto destination=image({},source.width,source.height);
auto cb=[queue commandBuffer];auto e=[cb computeCommandEncoder];[e setComputePipelineState:pipeline];
[e setTexture:source atIndex:0];[e setTexture:destination atIndex:1];
[e dispatchThreads:MTLSizeMake(source.width,source.height,1) threadsPerThreadgroup:MTLSizeMake(16,16,1)];[e endEncoding];finish(cb);
Pixels output(source.width*source.height*4);[destination getBytes:output.data() bytesPerRow:source.width*8 fromRegion:MTLRegionMake2D(0,0,source.width,source.height) mipmapLevel:0];return output;
}
static NSDictionary* preview(id<MTLLibrary> library) {
NSError* error=nil;auto pipeline=[gpu newComputePipelineStateWithFunction:[library newFunctionWithName:@"dyPreview"] error:&error];need(pipeline!=nil,error.description);
size_t compared=0,different=0;double maxError=0;
for(float level:{-.1f,0.f,.0031308f,.18f,1.f,2.f}) {
Pixels input(8*8*4);for(size_t p=0;p<input.size();p+=4){input[p]=input[p+1]=input[p+2]=(__fp16)level;input[p+3]=(__fp16).375f;}
auto source=image(input,8,8);auto output=[gpu newBufferWithLength:64*64*16 options:MTLResourceStorageModeShared];
auto cb=[queue commandBuffer];auto e=[cb computeCommandEncoder];[e setComputePipelineState:pipeline];[e setTexture:source atIndex:0];[e setBuffer:output offset:0 atIndex:0];
[e dispatchThreads:MTLSizeMake(64,64,1) threadsPerThreadgroup:MTLSizeMake(16,16,1)];[e endEncoding];finish(cb);
float value=float((__fp16)level),encoded=value<=.0031308f?value*12.92f:1.055f*std::pow(value,1.f/2.4f)-.055f;
const float* actual=(const float*)output.contents;for(size_t p=0;p<64*64*4;++p){float target=p%4==3?.375f:encoded;double d=std::abs(double(actual[p])-target);need(std::isfinite(d),@"nonfinite preview");++compared;if(d>2e-6)++different;maxError=std::max(maxError,d);}
}
return @{@"name":@"64x64-preview-sRGB-alpha-HDR-negative",@"components":@(compared),@"differentAboveTolerance":@(different),@"maxAbsoluteError":@(maxError),@"tolerance":@(2e-6),@"pass":@(different==0)};
}
int main(int argc,const char* argv[]) { @autoreleasepool { @try {
need(argc==3,@"Usage: verify_gpu /absolute/dayu.metallib /absolute/report.json");
gpu=MTLCreateSystemDefaultDevice();need(gpu!=nil,@"Metal unavailable");queue=[gpu newCommandQueue];
NSString* original=@"/Library/Plug-Ins/FxPlug/LumiGrade.app/Contents/PlugIns/LumiGrade XPC Service.pluginkit/Contents/Resources/default.metallib";
NSString* current=[NSString stringWithUTF8String:argv[1]];NSError* error=nil;
id<MTLLibrary> ref=[gpu newLibraryWithURL:[NSURL fileURLWithPath:original] error:&error];need(ref!=nil,error.description);
id<MTLLibrary> ours=[gpu newLibraryWithURL:[NSURL fileURLWithPath:current] error:&error];need(ours!=nil,error.description);
auto rp=renderPipeline(ref,false), dp=renderPipeline(ours,true);auto identity=lut(false), altered=lut(true);
NSArray* textures=@[identity,identity,identity,identity,identity,identity,identity,identity,identity];
const NSUInteger w=256,h=128;Pixels input(w*h*4);uint32_t rng=0x75423981;
for(NSUInteger y=0;y<h;++y)for(NSUInteger x=0;x<w;++x){size_t p=(y*w+x)*4;for(int c=0;c<3;++c){rng=rng*1664525+1013904223;float v=(rng>>8)*(1.0f/16777215);if(y<32)v=float(x)/255;if(y>=96)v=v*2-.1f;input[p+c]=(__fp16)v;}input[p+3]=1;}
auto source=image(input,w,h);NSMutableArray* cases=[NSMutableArray array];
auto runCase=[&](NSString* name,DYUniforms u,NSArray* tex){Pixels a=render(rp,false,source,tex,u,w,h),b=render(dp,true,source,tex,u,w,h);[cases addObject:compare(name,a,b)];};
DYUniforms u=defaults();runCase(@"neutral",u,textures);
for(float v:{-5.f,-1.25f,.65f,5.f}){u=defaults();u.exposure=v;runCase([NSString stringWithFormat:@"exposure-%g",v],u,textures);}
u=defaults();u.contrast=55;u.highlights=-48;u.shadows=62;u.whites=70;u.blacks=-65;runCase(@"tone-combined",u,textures);
u=defaults();u.contrast=-65;u.highlights=72;u.shadows=-55;u.whites=-72;u.blacks=48;runCase(@"tone-opposite",u,textures);
for(float v:{-65.f,65.f}){u=defaults();u.texture=v;runCase([NSString stringWithFormat:@"texture-%g",v],u,textures);u=defaults();u.clarity=v;runCase([NSString stringWithFormat:@"clarity-%g",v],u,textures);u=defaults();u.dehaze=v;runCase([NSString stringWithFormat:@"dehaze-%g",v],u,textures);}
u=defaults();u.saturation=38;u.vibrance=72;runCase(@"saturation-vibrance",u,textures);
u=defaults();u.curveShadows=-12;u.curveDarks=8;u.curveLights=15;u.curveHighlights=-8;u.redCurveShadows=13;u.greenCurveHighlights=-9;u.blueCurveShadows=5;u.curveExtraX=(DYFloat4){.1f,.3f,-1,-1};u.curveExtra=(DYFloat4){3,-6,0,0};runCase(@"master-RGB-extra-curves",u,textures);
u=defaults();u.levelsInputBlack=(DYFloat4){5,8,3,12};u.levelsInputWhite=(DYFloat4){246,238,241,245};u.levelsGamma=(DYFloat4){1.1f,.87f,1.25f,.94f};u.levelsOutputBlack=(DYFloat4){2,3,0,4};u.levelsOutputWhite=(DYFloat4){250,248,240,252};runCase(@"master-RGB-levels",u,textures);
u=defaults();u.hslCustomSample=(DYFloat3){.05f,.5f,.5f};u.hslCustomAdjust=(DYFloat3){25,-35,20};runCase(@"custom-HSL",u,textures);u.hslCustomVisualize=1;runCase(@"custom-HSL-visualization",u,textures);
u=defaults();u.blackWhiteSectionEnabled=1;u.blackWhiteMixA=(DYFloat4){25,-15,40,-30};u.blackWhiteMixB=(DYFloat2){15,-10};u.blackWhiteTint=(DYFloat2){.13f,.2f};runCase(@"black-white-mixer-tint",u,textures);
u=defaults();u.colorBalanceShadows=(DYFloat3){18,-12,6};u.colorBalanceMidtones=(DYFloat3){-9,14,-6};u.colorBalanceHighlights=(DYFloat3){8,2,-15};runCase(@"color-balance-preserve",u,textures);u.colorBalancePreserveLuminosity=0;runCase(@"color-balance",u,textures);
u=defaults();u.redPrimaryHue=25;u.primariesM0=(DYFloat3){.9f,.08f,.02f};u.primariesM1=(DYFloat3){.04f,.92f,.04f};u.primariesM2=(DYFloat3){.02f,.06f,.92f};runCase(@"primary-matrix",u,textures);
NSArray* lookTextures=@[altered,altered,altered,altered,altered,altered,identity,identity,identity];
u=defaults();u.preLUTStrength=.43f;u.postLUTStrength=.61f;u.extraPostLUTStrengths=(DYFloat4){.2f,.4f,.6f,.8f};runCase(@"pre-LUT-and-five-look-mixes",u,lookTextures);
u.skinProtection=(DYFloat3){.65f,.4f,.2f};u.exposure=.7f;u.contrast=20;u.curveDarks=-5;u.texture=25;u.clarity=-15;u.saturation=10;runCase(@"mixed-chain-skin-protection",u,lookTextures);
[cases addObject:statistics(ref,ours,source,identity,u)];[cases addObject:exportLUT(ref,ours,lookTextures,u)];
// Real cropped input tile with a 32 px halo, not a resized full-frame sample.
Pixels crop(192*h*4);for(NSUInteger y=0;y<h;++y)memcpy(crop.data()+y*192*4,input.data()+(y*w+32)*4,192*8);
Pixels full=render(dp,true,source,textures,u,w,h), expected(128*h*4);
for(NSUInteger y=0;y<h;++y)memcpy(expected.data()+y*128*4,full.data()+(y*w+64)*4,128*8);
Pixels tile=render(dp,true,image(crop,192,h),textures,u,128,h,32.f/192,160.f/192);
[cases addObject:compare(@"cropped-tile-32px-halo",expected,tile,false,.001)];
// Alpha is tested against the declared Dayu boundary, independent of original
// hidden RGB behavior at alpha zero. Premultiply only after grading.
Pixels alphaInput=input;for(size_t p=0;p<alphaInput.size();p+=4){alphaInput[p+3]=(__fp16)((p/4)%5*.25f);if(alphaInput[p+3]==0)alphaInput[p]=alphaInput[p+1]=alphaInput[p+2]=0;}
auto alphaSource=image(alphaInput,w,h);u=defaults();u.exposure=.65f;
Pixels alphaRef=render(rp,false,alphaSource,textures,u,w,h),alphaDayu=render(dp,true,alphaSource,textures,u,w,h);
[cases addObject:compare(@"straight-alpha-nonzero-oracle",alphaRef,alphaDayu,true)];
Pixels premultExpected=alphaDayu;for(size_t p=0;p<premultExpected.size();p+=4)for(int c=0;c<3;++c)premultExpected[p+c]=(__fp16)(float(premultExpected[p+c])*float(premultExpected[p+3]));
Pixels premult=render(dp,true,alphaSource,textures,u,w,h,0,1,true);[cases addObject:compare(@"output-premultiplication",premultExpected,premult)];
size_t badTransparent=0;for(size_t p=0;p<alphaDayu.size();p+=4)if(alphaInput[p+3]==0)for(int c=0;c<4;++c)if(alphaDayu[p+c]!=0)++badTransparent;
[cases addObject:@{@"name":@"zero-alpha-black",@"nonzeroComponents":@(badTransparent),@"pass":@(badTransparent==0)}];
u=defaults();Pixels neutralAlpha=render(dp,true,alphaSource,textures,u,w,h);[cases addObject:compare(@"neutral-straight-alpha",alphaInput,neutralAlpha)];
Pixels premultInput=alphaInput;for(size_t p=0;p<premultInput.size();p+=4)for(int c=0;c<3;++c)premultInput[p+c]=(__fp16)(float(premultInput[p+c])*float(premultInput[p+3]));
Pixels unpremultExpected=premultInput;for(size_t p=0;p<unpremultExpected.size();p+=4)for(int c=0;c<3;++c)unpremultExpected[p+c]=unpremultExpected[p+3]>0?(__fp16)(float(unpremultExpected[p+c])/float(unpremultExpected[p+3])):(__fp16)0;
Pixels recovered=unpremultiply(ours,image(premultInput,w,h));[cases addObject:compare(@"unpremultiply-compute-boundary",unpremultExpected,recovered)];
Pixels neutralPremult=render(dp,true,image(recovered,w,h),textures,u,w,h,0,1,true);[cases addObject:compare(@"neutral-premultiplied-roundtrip",premultInput,neutralPremult,false,.001)];
[cases addObject:preview(ours)];
bool passed=true;for(NSDictionary* row in cases)if(![row[@"pass"] boolValue])passed=false;
NSDictionary* report=@{@"pass":@(passed),@"gpu":gpu.name,@"os":[NSProcessInfo processInfo].operatingSystemVersionString,
@"referenceMetallibSHA256":digest(original),@"reconstructedMetallibSHA256":digest(current),@"imageSize":@[@(w),@(h)],
@"testCount":@(cases.count),@"cases":cases,@"scope":@"Direct GPU arithmetic and boundary checks; no GUI application was launched or modified.",
@"limitations":@[@"White balance, 8-color HSL mixer and color-grading texture generation use identity placeholders; CPU lookup-table reconstruction is outside this report.",@"Finite sample states; not exhaustive values or every host/GPU.",@"Tile test uses 32-pixel horizontal halo, full vertical input, fixed shared scene statistic.",@"16-bit float source/output follows the reference GPU ABI; premultiplied conversion and tile coordinate rounding allow absolute 0.001 tolerance. Host dispatch, save/reopen and actual FCP export remain separate."]};
NSData* data=[NSJSONSerialization dataWithJSONObject:report options:NSJSONWritingPrettyPrinted error:&error];need(data!=nil,error.description);
NSString* destination=[NSString stringWithUTF8String:argv[2]];need([data writeToFile:destination atomically:YES],destination);
printf("%s: %lu GPU checks\n",passed?"PASS":"FAIL",(unsigned long)cases.count);return passed?0:1;
} @catch(NSException* e) { fprintf(stderr,"%s\n",e.reason.UTF8String);return 2; } } }