还是老套路,用一张图说清楚Microsoft Shader Conductor针对Shader的跨平台处理方案。
[plantuml]
title MS-SC cross-platform shader solution\nhttps://tis.ac.cn/blog/kongdeyou/shader_cross_platform_compile_mssc/
partition Source {
  :HLSL>
}
partition “Microsoft Shader Conductor” {
partition Microsoft {
  :DirectX Shader Compiler;
  split
    :DXIL CodeGen;
    partition DX12.1 {
      :DX-IL]
    }
    kill
  split again
    :SPIRV CodeGen;
    partition Vulkan {
      :SPIRV]
    }
  end split
}
partition Khronos {
  :SPIRV-Cross;
  split
    :HLSL Compiler;
    partition DX9~12 {
      :HLSL>
    }
  split again
    :GLSL Compiler;
    partition OpenGL(ES) {
      split
        :GLSL>
      split again
        :ESSL>
      end split
    }
  split again
    :MSL Compiler;
    partition Metal {
      :Metal SL>
    }
  end split
}
}
:……;
[/plantuml]
微软也给我们提供了一个Shader的跨平台处理方案,而且这个方案还是成环的,以HLSL作为源,经过一圈的转换后,最后又能回到HLSL。
微软的Microsoft Shader Conductor工具已经开源,但是它没有实现一个编译器或是反编译器,它只是把现有的官方开源工具组合到了一起,实现HLSL语言到其他语言的转换。我们得感谢Khronos组织做了一个SPIRV-Cross,SPIRV-Cross是一个真正的反编译器,通过SPIRV-Cross,我们能将SPIRV字节码反编译出HLSL、GLSL、MSL的代码。再结合微软自家的DirectX Shader Compiler,它能将HLSL语言编译为SPIRV字节码。至此,Microsoft Shader Conductor的前向部分使用DirectX Shader Compiler,后向部分使用SPIRV-Cross,实现了以HLSL作为源语言,转换为其他语言的任务。
调研做到这里,主观给我的印象是,微软的方案比Unreal和Unity似乎更加完备些,但是同时也看到Microsoft Shader Conductor项目的ReadMe文档里写了这么一段:
Note that this project is still in an early stage, and it is under active development.
amm…接下来,打算踩踩Microsoft Shader Conductor这个坑了(撸袖子)
协议
本文以上内容遵循CC BY-ND 4.0协议,署名-禁止演绎。
转载请注明出处:https://tis.ac.cn/blog/kongdeyou/shader_cross_platform_compile_mssc/
并署名:kongdeyou(https://tis.ac.cn/blog/author/kongdeyou/)
 
                 
            