WIP restore primary CST controls and defer main output; shader and Release build pass
这个提交包含在:
1 父节点
2cf93fafe5
当前提交
0b1b4454b4
16 个文件已更改
+130
-24
没有与搜索条件相匹配的文件
@@ -4,6 +4,7 @@ from pathlib import Path
|
||||
import argparse
|
||||
import subprocess
|
||||
from build_masked_kernel import masked_kernel
|
||||
from float_air_boundary import float_boundary
|
||||
|
||||
|
||||
def main():
|
||||
@@ -23,6 +24,10 @@ def main():
|
||||
generated = work / 'DYGradeMasked.ll'
|
||||
generated.write_text(masked_kernel(source.read_text()))
|
||||
source = generated
|
||||
if name in ('CSTKernel', 'BasisKernel'):
|
||||
generated = work / (name + 'Float.ll')
|
||||
generated.write_text(float_boundary(source.read_text(), name))
|
||||
source = generated
|
||||
subprocess.run(['xcrun', 'metal-opt', str(source),
|
||||
'-o', str(target)], check=True)
|
||||
objects.append(str(target))
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
"""Add float boundary entry points; preserve all original AIR and arithmetic.
|
||||
|
||||
The recovered arithmetic already calculates in float. Only its sample entry and
|
||||
return were half. The new CST pipeline must not quantize every domain crossing.
|
||||
Legacy entry points remain byte-for-byte in the module and keep their behavior.
|
||||
"""
|
||||
import re
|
||||
|
||||
|
||||
def float_boundary(source, kind):
|
||||
name, size, first, rgb, tag = {
|
||||
'CSTKernel': ('cst', '9CSTParams', (7, 8), 2040, 6),
|
||||
'BasisKernel': ('basis', '11BasisParams', (8, 9), 247, 8),
|
||||
}[kind]
|
||||
old = f'_Z{len(name)+4}{name}_airDv4_DhRU11MTLconstantK{size}'
|
||||
new_name = name + '_float_air'
|
||||
new = f'_Z{len(new_name)}{new_name}Dv4_fRU11MTLconstantK{size}'
|
||||
match = re.search(r'define <4 x float> @' + re.escape(old) + r'\(.*?\n}', source, re.S)
|
||||
assert match, 'Versioned AIR entry changed; review the boundary adapter'
|
||||
function = match.group().replace(old, new, 1).replace('<4 x half> noundef %sample', '<4 x float> noundef %sample', 1)
|
||||
entry = (f' %v{first[0]} = shufflevector <4 x half> %sample, <4 x half> poison, <3 x i32> <i32 0, i32 1, i32 2>\n'
|
||||
f' %v{first[1]} = tail call fast <3 x float> @air.convert.f.v3f32.f.v3f16(<3 x half> %v{first[0]}) #{tag}')
|
||||
assert function.count(entry) == 1
|
||||
function = function.replace(entry, f' %v{first[1]} = shufflevector <4 x float> %sample, <4 x float> poison, <3 x i32> <i32 0, i32 1, i32 2>')
|
||||
exit = (f' %v{rgb+1} = tail call fast <3 x half> @air.convert.f.v3f16.f.v3f32(<3 x float> %v{rgb}) #{tag}\n'
|
||||
f' %v{rgb+2} = shufflevector <3 x half> %v{rgb+1}, <3 x half> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 undef>\n'
|
||||
f' %v{rgb+3} = shufflevector <4 x half> %v{rgb+2}, <4 x half> %sample, <4 x i32> <i32 0, i32 1, i32 2, i32 7>\n'
|
||||
f' %v{rgb+4} = tail call fast <4 x float> @air.convert.f.v4f32.f.v4f16(<4 x half> %v{rgb+3}) #{tag}\n'
|
||||
f' ret <4 x float> %v{rgb+4}')
|
||||
assert function.count(exit) == 1
|
||||
function = function.replace(exit, f' %dayuRGB = shufflevector <3 x float> %v{rgb}, <3 x float> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 undef>\n %dayuRGBA = shufflevector <4 x float> %dayuRGB, <4 x float> %sample, <4 x i32> <i32 0, i32 1, i32 2, i32 7>\n ret <4 x float> %dayuRGBA')
|
||||
return source[:match.end()] + '\n\n; Dayu float boundary, arithmetic unchanged.\n' + function + source[match.end():]
|
||||
在新工单中引用
屏蔽一个用户