HLSL Compiler

来源:互联网 发布:mysql my.cnf 路径 编辑:程序博客网 时间:2024/06/10 13:59

(See also DirectX-Shaders and DirectX-ToDo )

Many projects - Wine included - could use an open source HLSL compiler.

Wine in particular needs one that accepts the DirectX HLSL and outputs the DirectX shader bytecode. At the moment it's enough to target Direct3D 9 HLSL/bytecode, later Wine will also need to extend it to Direct3D 10 and 11.

There are several ways to approach building a compiler:

  • write an ad hoc compiler using lex and yacc, without much of an optimizer (like Mesa has for GLSL)
  • ditto, but use a well-known IR representation so a good optimizer could be borrowed later
  • write the compiler using an existing compiler toolkit (like LLVM or maybe Open64)

It's not clear yet what the best path is, they probably all merit some exploration.

Here are a few HLSL-compiler-like things that have been spotted in the wild:

Wine patches

  • http://repo.or.cz/w/wine/hlsl-compiler.git - Matijn Woudt and Matteo Bruni's sandbox for their wine HLSL compiler work

Compilers that read HLSL (and their target languages)

  • http://sourceforge.net/projects/hlsl2glsl (GLSL) (2006)

  • http://code.google.com/p/hlsl2glslfork (GLSL) (2008)

  • http://icculus.org/mojoshader (GLSL, ARB_*_program) (HLSL parser just started in 2010)

  • http://marc.info/?l=wine-devel&m=127125529916136&w=2 (Stefan Doesinger's HLSL compiler, 2006... need better link)

Parsers

  • http://developer.nvidia.com/object/cg_compiler_code.html (nvidia's 2002 opensourced CG parser)

Compiler Backends that output shader assembly

  • http://sourceforge.net/projects/llvmptxbackend/ (LLVM IR -> PTX) (GPL, so not mergable into LLVM tree)

Glue to interface Mesa's ad-hoc GLSL compiler to LLVM IR

  • http://cgit.freedesktop.org/mesa/mesa/tree/src/gallium/auxiliary/gallivm (GLSL -> X86 SSE specific LLVM IR?)

Related Pages

  • http://www.prog.uni-saarland.de/projects/anysl (home of llvmptxbackend)

  • http://llvm.org/docs/BitCodeFormat.html (LLVM IR file format)

  • http://aras-p.info/blog/2010/05/21/compiling-hlsl-into-glsl-in-2010/

  • http://graphics.stanford.edu/~danielrh/babelshader.html (converts MS shader assembly to ARB shader assembly) (2003)

Not very related pages

  • http://en.wikipedia.org/wiki/OpenCL (OpenCL is an HLSL-like language, but targets computation rather than graphics, and there aren't any open source implementations?)

  • http://en.wikipedia.org/wiki/CUDA (ditto)

  • http://www.tungstengraphics.com/wiki/files/tgsi.pdf (404, but archive.org still has it, sha1sum df05ca5e4252026782179cdeaf65af63d1d82040 )

Discussion

  • http://www.radeonhd.org/?page=archive_display&c=radeon&m=4&y=2010&d=2010-4-01 "... in Wine we want HLSL -> llvm -> d3d_asm and then d3d_asm -> GLSL (->llvm -> tgsi) ..."


CategoryCompilers CategoryGraphics

0 0