tgjones / shader-playground

Shader playground website for exploring HLSL, GLSL, SPIR-V compilers
http://shader-playground.timjones.io
BSD 2-Clause "Simplified" License
585 stars 46 forks source link

Support DXBC, DXIL, and SPIR-V output for Slang #93

Closed tangent-vector closed 3 years ago

tangent-vector commented 3 years ago

It would be great if Shader Playground showed DXBC, DXIL, and SPIR-V as available output formats for the Slang compiler.

The intended workflow for Slang is that if a user wants a particular output format like DXBC, DXIL, or SPIR-V they should ask the Slang compiler to produce it directly. The means by which the Slang compiler produces that output is intended to be treated as an implementation detail.

Right now, the Shader Playground website does not list several of the output formats supported by Slang, and instead expects/requires users to produce HLSL/GLSL output and then add another compiler to the chain to get their desired output format.

Putting the onus on the user to set up a downstream compiler and its options creates a risk that they will not set those options in a way that is consistent with the output the upstream compiler produced. The Slang compiler carefully selects the flags and options it uses when invoking downstream compilers to make sure that they operate in the right mode for the HLSL/GLSL that was generated.

As another example, Slang currently generates SPIR-V output via glslang, but it uses its own bundled version of glslang to do so. At certain points in the past the version of glslang bundled with Slang has included bug fixes and features that were not yet live on top-of-tree glslang, so that correct SPIR-V generation for certain programs would not be possible with a compilation chain on Shader Playground. Futhermore, it is likely that in some future version the Slang compiler will switch to generating SPIR-V directly rather than via glslang; we would like this shift to be transparent to users, which is only possible if they allow Slang to handle the details of SPIR-V generation under the hood.

tgjones commented 3 years ago

This is resolved by @jsmall-nvidia's work in #96. Thank you @jsmall-nvidia! I tweaked it a little to make it work with Shader Playground's pipelines so that e.g. the SPIR-V output can be pipelined to another compiler.

Here's an example of outputting DXIL: http://shader-playground.timjones.io/e6e929327363141fee891e17490f806b