42 lines
1.0 KiB
Python
42 lines
1.0 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
SDL3_GPU Slang Compiler - Command Generation
|
|
"""
|
|
from shader_types import TargetFormat, ShaderStage
|
|
from slangc_finder import slangc_path
|
|
|
|
|
|
def make_cmd(source_file: str, target: TargetFormat, stage: ShaderStage, entry_point: str, include_paths,
|
|
output_path: str):
|
|
"""生成编译命令"""
|
|
target_flag = {
|
|
TargetFormat.SPIRV: 'spirv',
|
|
TargetFormat.DXIL: 'dxil',
|
|
TargetFormat.DXBC: 'dxbc',
|
|
TargetFormat.MSL: 'metal'
|
|
}[target]
|
|
|
|
stage_flag = {
|
|
ShaderStage.VERTEX: 'vertex',
|
|
ShaderStage.FRAGMENT: 'fragment',
|
|
ShaderStage.COMPUTE: 'compute'
|
|
}[stage]
|
|
|
|
cmd = [
|
|
slangc_path,
|
|
source_file,
|
|
'-entry', entry_point,
|
|
'-o', output_path,
|
|
'-target', target_flag,
|
|
'-stage', stage_flag,
|
|
]
|
|
# 添加包含路径
|
|
for include_path in include_paths:
|
|
cmd.extend(['-I', include_path])
|
|
|
|
if target in [TargetFormat.DXIL, TargetFormat.DXBC]:
|
|
cmd.extend(['-profile', 'sm_6_6'])
|
|
|
|
return cmd
|
|
|