Files
mirage/tools/compiler_cmd.py
2025-06-19 16:01:19 +08:00

56 lines
1.3 KiB
Python

#!/usr/bin/env python3
"""
Slang Compiler - Command Generation
"""
from exe_finder import slangc_path
from global_vars import global_vars
from shader_reflection_type import *
def make_cmd(source_file: str, target: TargetFormat, stage: Stage, entry_point: str, output_path: str):
"""生成编译命令"""
target_flag = {
TargetFormat.GLSL: 'glsl',
TargetFormat.DXBC: 'dxbc',
TargetFormat.MSL: 'metal',
}[target]
stage_flag = {
Stage.VERTEX: 'vertex',
Stage.FRAGMENT: 'fragment',
Stage.COMPUTE: 'compute'
}[stage]
cmd = [
slangc_path,
source_file,
'-no-mangle',
'-lang', 'slang',
'-entry', entry_point,
'-target', target_flag,
'-stage', stage_flag,
'-matrix-layout-row-major',
'-o', output_path,
]
if global_vars.debug:
cmd.extend([
'-g3', # 生成调试信息
'-O0', # 禁用优化,便于调试和验证
])
else:
cmd.extend([
'-g0', # 禁用调试信息
'-O3' # 启用高级优化
])
# 添加包含路径
for include_path in global_vars.include_dirs:
cmd.extend(['-I', include_path])
if target == TargetFormat.DXBC:
cmd.extend(['-profile', 'sm_5_0'])
return cmd