diff options
author | Jeremy Ong <jeremycong@gmail.com> | 2022-08-09 05:32:19 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-09 07:32:19 -0500 |
commit | d928bccf5a23c482837a3be007434607f1ac268a (patch) | |
tree | 38f59be0a19b04919399d963aee07c66b155cbe4 /lib/compilers | |
parent | 6c278766e1c94bf046d1b574237c33d88ba59f91 (diff) | |
download | compiler-explorer-d928bccf5a23c482837a3be007434607f1ac268a.tar.gz compiler-explorer-d928bccf5a23c482837a3be007434607f1ac268a.zip |
Add preliminary HLSL support (#3932)gh-3870
* Add preliminary HLSL support
- Adds a new language mode to monaco, extending the base C++ layer with
HLSL intrinsics and types
- Adds a new `HLSLCompiler` class
- Adds a sample pixel shader
The compiler used to test this locally is the [DirectX Shader
Compiler](https://github.com/microsoft/DirectXShaderCompiler) (aka DXC),
which needs to also be added to the
[infra](https://github.com/compiler-explorer/infra) project.
Some guidance is needed before this PR can be merged:
1. While DXC can run on Linux, there are no binaries available so this
compiler must be built. Are there examples that show how we should do
this as part of the infra CI/CD? Should we build and host it
separately instead? The build process for DXC on Linux is relatively
straightforward and documented
[here](https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DxcOnUnix.rst).
2. The example code doesn't compile unless the user also supplies
additional compiler flags `-T ps_6_6 -E PSMain`. Is there a way to
load these flags conditionally only if the sample is loaded?
3. Technically, DXC emits DXIL IR (based on LLVM IR) and I am wondering
if it's possible to extend an existing LLVM backend. In addition, the
`-spirv` compiler flag could be emitted to target the SPIR-V backend
instead, so I'm curious if there is a good way to express the target
backend.
Signed-off-by: Jeremy Ong <jeremycong@gmail.com>
* Fix copyright dates, remove unnecessary strict usage, and remove
placeholder logo
Signed-off-by: Jeremy Ong <jeremycong@gmail.com>
* Rebase and remove unneeded HLSL logo
Signed-off-by: Jeremy Ong <jeremycong@gmail.com>
* Fix lint errors
Signed-off-by: Jeremy Ong <jeremycong@gmail.com>
* Simply HLSL sample and remove default config
Signed-off-by: Jeremy Ong <jeremycong@gmail.com>
Diffstat (limited to 'lib/compilers')
-rw-r--r-- | lib/compilers/_all.js | 1 | ||||
-rw-r--r-- | lib/compilers/hlsl.js | 51 |
2 files changed, 52 insertions, 0 deletions
diff --git a/lib/compilers/_all.js b/lib/compilers/_all.js index 83cb3738c..18c4f20aa 100644 --- a/lib/compilers/_all.js +++ b/lib/compilers/_all.js @@ -53,6 +53,7 @@ export {GCCCompiler} from './gcc'; export {GCCRSCompiler} from './gccrs'; export {GolangCompiler} from './golang'; export {HaskellCompiler} from './haskell'; +export {HLSLCompiler} from './hlsl'; export {ISPCCompiler} from './ispc'; export {JaktCompiler} from './jakt'; export {JavaCompiler} from './java'; diff --git a/lib/compilers/hlsl.js b/lib/compilers/hlsl.js new file mode 100644 index 000000000..25858839e --- /dev/null +++ b/lib/compilers/hlsl.js @@ -0,0 +1,51 @@ +// Copyright (c) 2022, Compiler Explorer Authors +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. + +import path from 'path'; + +import {BaseCompiler} from '../base-compiler'; + +export class HLSLCompiler extends BaseCompiler { + static get key() { + return 'hlsl'; + } + + constructor(info, env) { + super(info, env); + + this.compiler.supportsIntel = false; + } + + /* eslint-disable no-unused-vars */ + optionsForFilter(filters, outputFilename) { + return [ + `-Fc ${outputFilename}`, // Output object + ]; + } + /* eslint-enable no-unused-vars */ + + getIrOutputFilename(inputFilename) { + return this.getOutputFilename(path.dirname(inputFilename), this.outputFilebase).replace('.s', '.dxil'); + } +} |