<div class="gmail_quote">On Mon, Mar 28, 2011 at 9:22 PM, Charles Davis <span dir="ltr"><<a href="mailto:cdavis@mymail.mines.edu">cdavis@mymail.mines.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Here's the other of my proposals for this year's Google Summer of Code.<br>
(The first is on cfe-dev.) It was suggested to me by Dan Kegel (from the<br>
Wine project, they really want this).<br>
<br>
Title: Microsoft Direct3D shader bytecode backend<br>
<br>
Abstract:<br>
<br>
There is a distinct lack of open-source frameworks for compiling HLSL,<br>
the shader language used by Direct3D, into bytecode that D3D can<br>
understand. Currently, the only such framework is Ryan Gordon's<br>
MojoShader, whose HLSL compiler component is still under heavy<br>
development. By utilizing LLVM, it may be possible to generate<br>
high-performance shader code from HLSL, just as Apple is known to do for<br>
GLSL. The first step is a backend to generate D3D bytecode from LLVM IR.<br>
<br>
Content:<br>
<br>
1. Proposal<br>
<br>
Currently, there are very few open-source frameworks for compiling<br>
High-Level Shader Language (HLSL) into shader bytecode that can be<br>
understood by Direct3D, a popular interface to 3D hardware in games.<br>
This is because Microsoft provides its own interface in its D3DX (and<br>
underlying D3DCompiler) DLLs. Most games therefore end up using D3DX to<br>
compile their Direct3D shaders.<br>
<br>
Microsoft seems to have paid no attention to optimization of the<br>
resulting shader code, though. With LLVM, we can do better.<br></blockquote><div><br></div><div>Do you have any sources for this?  In my experience, fxc is able to do some clever tricks such as replacing if-then-else conditions with predicated instructions and swizzles.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>
By using LLVM's optimizers, programs can potentially generate<br>
high-performance shader code that works well on the platform on which<br>
they are running. In addition, an open-source implementation would allow<br>
the compiler to be embedded in many different applications--not the<br>
least of which is Wine, which is in desperate need of a working shader<br>
compiler.<br></blockquote><div><br></div><div>I'm a bit confused how Wine would take advantage of a Direct3D bytecode compiler.  Would they not want to re-compile Direct3D bytecode (most often shipped with games in binary form instead of HLSL source) to something an OpenGL implementation on *nix could handle?</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>
The first step to this HLSL compiler is an LLVM backend for generating<br>
D3D shader bytecode from LLVM IR. Therefore, I intend to implement such<br>
a backend. Because implementing a full backend is a daunting task, I<br>
intend to implement just enough to get simple examples working with<br>
Wine's Direct3D implementation.<br></blockquote><div><br></div><div>Could you be a bit more specific on your goals?  A few quick questions that come to mind are:</div><div><br></div><div>1. What shader models will you aim to support?</div>
<div>2. What types of shared will you aim to support?  e.g. vertex, pixel, geometry, hull</div><div>3. How do you propose to handle vertex buffer semantics?  e.g. POSITION0, TEXCOORD0, NORMAL, etc.</div><div><br></div><div>
Perhaps a simple example would be nice, showing a very simple LLVM IR input and the (proposed) bytecode output.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<br>
2. Interest<br>
<br>
Over the past few years, I've become interested in graphics programming.<br>
I'm also interested in learning how to design backends for LLVM.<br>
<br>
3. Usefulness to LLVM<br>
<br>
This should increase adoption of LLVM, particularly by games and other<br>
3D graphical applications that use Direct3D.<br>
<br>
4. Prior knowledge in compilers and LLVM in particular<br>
<br>
I have been working with LLVM since the fall of 2009. I have a little<br>
experience working with the x86 backend, but no experience writing my<br>
own backend. I have, however, read the documents on building a new<br>
backend, and I am very familiar with the TableGen syntax.<br>
<br>
5. Academic, industry, etc. experience<br>
<br>
I am a student at the Colorado School of Mines studying in Computer<br>
Science. I am a Senior by year and credits, and I am set to graduate in<br>
December of 2011. In addition, I have contributed to several open-source<br>
projects, including Wine and LLVM.<br>
<br>
6. Contact information<br>
<br>
 - E-mail: <a href="mailto:cdavis@mymail.mines.edu">cdavis@mymail.mines.edu</a><br>
 - IRC nick: cdavis5x<br>
<br>
Chip<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
</blockquote></div><br><br clear="all"><br>-- <br><br><div>Thanks,</div><div><br></div><div>Justin Holewinski</div><br>