mirror of
https://github.com/compiler-explorer/compiler-explorer.git
synced 2025-12-27 10:33:59 -05:00
Add preliminary HLSL support (#3932)
* 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>
This commit is contained in:
13
examples/hlsl/default.hlsl
Normal file
13
examples/hlsl/default.hlsl
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
// The entry point and target profile are needed to compile this example:
|
||||||
|
// -T ps_6_6 -E PSMain
|
||||||
|
|
||||||
|
struct PSInput
|
||||||
|
{
|
||||||
|
float4 position : SV_Position;
|
||||||
|
float4 color : COLOR0;
|
||||||
|
};
|
||||||
|
|
||||||
|
float4 PSMain(PSInput input) : SV_Target0
|
||||||
|
{
|
||||||
|
return input.color * input.color;
|
||||||
|
}
|
||||||
@@ -53,6 +53,7 @@ export {GCCCompiler} from './gcc';
|
|||||||
export {GCCRSCompiler} from './gccrs';
|
export {GCCRSCompiler} from './gccrs';
|
||||||
export {GolangCompiler} from './golang';
|
export {GolangCompiler} from './golang';
|
||||||
export {HaskellCompiler} from './haskell';
|
export {HaskellCompiler} from './haskell';
|
||||||
|
export {HLSLCompiler} from './hlsl';
|
||||||
export {ISPCCompiler} from './ispc';
|
export {ISPCCompiler} from './ispc';
|
||||||
export {JaktCompiler} from './jakt';
|
export {JaktCompiler} from './jakt';
|
||||||
export {JavaCompiler} from './java';
|
export {JavaCompiler} from './java';
|
||||||
|
|||||||
51
lib/compilers/hlsl.js
Normal file
51
lib/compilers/hlsl.js
Normal file
@@ -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');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -293,6 +293,16 @@ const definitions: Record<LanguageKey, LanguageDefinition> = {
|
|||||||
formatter: null,
|
formatter: null,
|
||||||
previewFilter: null,
|
previewFilter: null,
|
||||||
},
|
},
|
||||||
|
hlsl: {
|
||||||
|
name: 'HLSL',
|
||||||
|
monaco: 'hlsl',
|
||||||
|
extensions: ['.hlsl', '.hlsli'],
|
||||||
|
alias: [],
|
||||||
|
logoUrl: null,
|
||||||
|
logoUrlDark: null,
|
||||||
|
formatter: null,
|
||||||
|
previewFilter: null,
|
||||||
|
},
|
||||||
ispc: {
|
ispc: {
|
||||||
name: 'ispc',
|
name: 'ispc',
|
||||||
monaco: 'ispc',
|
monaco: 'ispc',
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ import './erlang-mode';
|
|||||||
import './fortran-mode';
|
import './fortran-mode';
|
||||||
import './gccdump-rtl-gimple-mode';
|
import './gccdump-rtl-gimple-mode';
|
||||||
import './haskell-mode';
|
import './haskell-mode';
|
||||||
|
import './hlsl-mode';
|
||||||
import './ispc-mode';
|
import './ispc-mode';
|
||||||
import './jakt-mode';
|
import './jakt-mode';
|
||||||
import './llvm-ir-mode';
|
import './llvm-ir-mode';
|
||||||
|
|||||||
321
static/modes/hlsl-mode.ts
Normal file
321
static/modes/hlsl-mode.ts
Normal file
@@ -0,0 +1,321 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
const monaco = require('monaco-editor');
|
||||||
|
const cpp = require('monaco-editor/esm/vs/basic-languages/cpp/cpp');
|
||||||
|
|
||||||
|
function definition() {
|
||||||
|
const hlsl = $.extend(true, {}, cpp.language);
|
||||||
|
|
||||||
|
function addKeywords(keywords) {
|
||||||
|
for (let i = 0; i < keywords.length; ++i) {
|
||||||
|
hlsl.keywords.push(keywords[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function vectorMatrixTypes(basename) {
|
||||||
|
const types: string[] = [];
|
||||||
|
for (let i = 1; i !== 5; ++i) {
|
||||||
|
for (let j = 1; j !== 5; ++j) {
|
||||||
|
types.push(`${basename}${i}x${j}`);
|
||||||
|
}
|
||||||
|
types.push(`${basename}${i}`);
|
||||||
|
}
|
||||||
|
return types;
|
||||||
|
}
|
||||||
|
|
||||||
|
addKeywords(vectorMatrixTypes('bool'));
|
||||||
|
addKeywords(vectorMatrixTypes('uint'));
|
||||||
|
addKeywords(vectorMatrixTypes('float'));
|
||||||
|
addKeywords(vectorMatrixTypes('int'));
|
||||||
|
|
||||||
|
function resource(name) {
|
||||||
|
return [name, `RW${name}`];
|
||||||
|
}
|
||||||
|
|
||||||
|
addKeywords(resource('Buffer'));
|
||||||
|
addKeywords(resource('Texture1D'));
|
||||||
|
addKeywords(resource('Texture1DArray'));
|
||||||
|
addKeywords(resource('Texture2D'));
|
||||||
|
addKeywords(resource('Texture2DArray'));
|
||||||
|
addKeywords(resource('Texture3D'));
|
||||||
|
addKeywords(resource('TextureCube'));
|
||||||
|
addKeywords(resource('TextureCubeArray'));
|
||||||
|
addKeywords(resource('Texture2DMS'));
|
||||||
|
addKeywords(resource('Texture2DMSArray'));
|
||||||
|
addKeywords(resource('ByteAddressBuffer'));
|
||||||
|
addKeywords(resource('StructuredBuffer'));
|
||||||
|
addKeywords(resource('ConstantBuffer'));
|
||||||
|
|
||||||
|
addKeywords([
|
||||||
|
'out',
|
||||||
|
'inout',
|
||||||
|
'vector',
|
||||||
|
'matrix',
|
||||||
|
'uint',
|
||||||
|
|
||||||
|
'SamplerState',
|
||||||
|
'SamplerComparisonState',
|
||||||
|
|
||||||
|
// Additional resource yypes
|
||||||
|
'AppendStructuredBuffer',
|
||||||
|
'ConsumeStructuredBuffer',
|
||||||
|
|
||||||
|
// Intrinsic functions
|
||||||
|
'abort',
|
||||||
|
'abs',
|
||||||
|
'acos',
|
||||||
|
'all',
|
||||||
|
'AllMemoryBarrier',
|
||||||
|
'AllMemoryBarrierWithGroupSync',
|
||||||
|
'any',
|
||||||
|
'asdouble',
|
||||||
|
'asfloat',
|
||||||
|
'asin',
|
||||||
|
'asint',
|
||||||
|
'asuint',
|
||||||
|
'atan',
|
||||||
|
'atan2',
|
||||||
|
'ceil',
|
||||||
|
'CheckAccessFullyMapped',
|
||||||
|
'clamp',
|
||||||
|
'clip',
|
||||||
|
'cos',
|
||||||
|
'cosh',
|
||||||
|
'countbits',
|
||||||
|
'cross',
|
||||||
|
'ddx',
|
||||||
|
'ddx_coarse',
|
||||||
|
'ddx_fine',
|
||||||
|
'ddy',
|
||||||
|
'ddy_coarse',
|
||||||
|
'ddy_fine',
|
||||||
|
'degrees',
|
||||||
|
'determinant',
|
||||||
|
'DeviceMemoryBarrier',
|
||||||
|
'DeviceMemoryBarrierWithGroupSync',
|
||||||
|
'distance',
|
||||||
|
'dot',
|
||||||
|
'dst',
|
||||||
|
'errorf',
|
||||||
|
'EvaluateAttributeCentroid',
|
||||||
|
'EvaluateAttributeAtSample',
|
||||||
|
'EvaluateAttributeSnapped',
|
||||||
|
'exp',
|
||||||
|
'exp2',
|
||||||
|
'f16tof32',
|
||||||
|
'f32tof16',
|
||||||
|
'faceforward',
|
||||||
|
'firstbithigh',
|
||||||
|
'firstbitlow',
|
||||||
|
'floor',
|
||||||
|
'fma',
|
||||||
|
'fmod',
|
||||||
|
'frac',
|
||||||
|
'frexp',
|
||||||
|
'fwidth',
|
||||||
|
'GetRenderTargetSampleCount',
|
||||||
|
'GetRenderTargetSamplePosition',
|
||||||
|
'GroupMemoryBarrier',
|
||||||
|
'GroupMemoryBarrierWithGroupSync',
|
||||||
|
'InterlockedAdd',
|
||||||
|
'InterlockedAnd',
|
||||||
|
'InterlockedCompareExchange',
|
||||||
|
'InterlockedExchange',
|
||||||
|
'InterlockedMax',
|
||||||
|
'InterlockedMin',
|
||||||
|
'InterlockedOr',
|
||||||
|
'InterlockedXor',
|
||||||
|
'isfinite',
|
||||||
|
'isinf',
|
||||||
|
'isnan',
|
||||||
|
'ldexp',
|
||||||
|
'length',
|
||||||
|
'lerp',
|
||||||
|
'lit',
|
||||||
|
'log',
|
||||||
|
'log10',
|
||||||
|
'log2',
|
||||||
|
'mad',
|
||||||
|
'max',
|
||||||
|
'min',
|
||||||
|
'modf',
|
||||||
|
'msad4',
|
||||||
|
'mul',
|
||||||
|
'noise',
|
||||||
|
'normalize',
|
||||||
|
'pow',
|
||||||
|
'Process2DQuadTessFactorsAvg',
|
||||||
|
'Process2DQuadTessFactorsMax',
|
||||||
|
'Process2DQuadTessFactorsMin',
|
||||||
|
'ProcessIsolineTessFactors',
|
||||||
|
'ProcessQuadTessFactorsAvg',
|
||||||
|
'ProcessQuadTessFactorsMax',
|
||||||
|
'ProcessQuadTessFactorsMin',
|
||||||
|
'ProcessTriTessFactorsAvg',
|
||||||
|
'ProcessTriTessFactorsMax',
|
||||||
|
'ProcessTriTessFactorsMin',
|
||||||
|
'radians',
|
||||||
|
'rcp',
|
||||||
|
'reflect',
|
||||||
|
'refract',
|
||||||
|
'reversebits',
|
||||||
|
'round',
|
||||||
|
'rsqrt',
|
||||||
|
'saturate',
|
||||||
|
'sign',
|
||||||
|
'sin',
|
||||||
|
'sincos',
|
||||||
|
'sinh',
|
||||||
|
'smoothstep',
|
||||||
|
'sqrt',
|
||||||
|
'step',
|
||||||
|
'tan',
|
||||||
|
'tanh',
|
||||||
|
'tex1D',
|
||||||
|
'tex1Dbias',
|
||||||
|
'tex1Dgrad',
|
||||||
|
'tex1Dlod',
|
||||||
|
'tex1Dproj',
|
||||||
|
'tex2D',
|
||||||
|
'tex2Dbias',
|
||||||
|
'tex2Dgrad',
|
||||||
|
'tex2Dlod',
|
||||||
|
'tex2Dproj',
|
||||||
|
'tex3D',
|
||||||
|
'tex3Dbias',
|
||||||
|
'tex3Dgrad',
|
||||||
|
'tex3Dlod',
|
||||||
|
'tex3Dproj',
|
||||||
|
'texCUBE',
|
||||||
|
'texCUBEbias',
|
||||||
|
'texCUBEgrad',
|
||||||
|
'texCUBElod',
|
||||||
|
'texCUBEproj',
|
||||||
|
'transpose',
|
||||||
|
'trunc',
|
||||||
|
|
||||||
|
// Wave intrinsics
|
||||||
|
'WaveIsFirstLane',
|
||||||
|
'WaveGetLaneCount',
|
||||||
|
'WaveGetLaneIndex',
|
||||||
|
'WaveActiveAnyTrue',
|
||||||
|
'WaveActiveAllTrue',
|
||||||
|
'WaveActiveBallot',
|
||||||
|
'WaveReadLaneFirst',
|
||||||
|
'WaveReadLaneAt',
|
||||||
|
'WaveActiveAllEqual',
|
||||||
|
'WaveActiveCountBits',
|
||||||
|
'WaveActiveSum',
|
||||||
|
'WaveActiveProduct',
|
||||||
|
'WaveActiveBitAnd',
|
||||||
|
'WaveActiveBitOr',
|
||||||
|
'WaveActiveBitXor',
|
||||||
|
'WaveActiveMin',
|
||||||
|
'WaveActiveMax',
|
||||||
|
'WavePrefixCountBits',
|
||||||
|
'WavePrefixProduct',
|
||||||
|
'WavePrefixSum',
|
||||||
|
'QuadReadAcrossX',
|
||||||
|
'QuadReadAcrossY',
|
||||||
|
'QuadReadAcrossDiagonal',
|
||||||
|
'QuadReadLaneAt',
|
||||||
|
// SM6.5 wave intrinsics
|
||||||
|
'WaveMatch',
|
||||||
|
'WaveMultiPrefixSum',
|
||||||
|
'WaveMultiPrefixProduct',
|
||||||
|
'WaveMultiPrefixCountBits',
|
||||||
|
'WaveMultiPrefixAnd',
|
||||||
|
'WaveMultiPrefixOr',
|
||||||
|
'WaveMultiPrefixXor',
|
||||||
|
|
||||||
|
// Raytracing intrinsics
|
||||||
|
'RayTracingAccelerationStructure',
|
||||||
|
'AcceptHitAndEndSearch',
|
||||||
|
'CallShader',
|
||||||
|
'IgnoreHit',
|
||||||
|
'PrimitiveIndex',
|
||||||
|
'ReportHit',
|
||||||
|
'TraceRay',
|
||||||
|
'DispatchRaysIndex',
|
||||||
|
'DispatchRaysDimensions',
|
||||||
|
'WorldRayOrigin',
|
||||||
|
'WorldRayDirection',
|
||||||
|
'RayTMin',
|
||||||
|
'RayTCurrent',
|
||||||
|
'RayFlags',
|
||||||
|
'InstanceIndex',
|
||||||
|
'InstanceID',
|
||||||
|
'ObjectRayOrigin',
|
||||||
|
'ObjectRayDirection',
|
||||||
|
'ObjectToWorld3x4',
|
||||||
|
'ObjectToWorld4x3',
|
||||||
|
'WorldToObject3x4',
|
||||||
|
'WorldToObject4x3',
|
||||||
|
'HitKind',
|
||||||
|
|
||||||
|
// SM6.4
|
||||||
|
'dot4add_u8packed',
|
||||||
|
'dot4add_i8packed',
|
||||||
|
'dot2add',
|
||||||
|
|
||||||
|
// Compute + mesh/amplification shaders
|
||||||
|
'numthreads',
|
||||||
|
'outputtopology',
|
||||||
|
'DispatchMesh',
|
||||||
|
'groupshared',
|
||||||
|
|
||||||
|
// SM6.6
|
||||||
|
'InterlockedCompareStore',
|
||||||
|
'InterlockedCompareStoreFloatBitwise',
|
||||||
|
'InterlockedCompareExchangeFloatBitwise',
|
||||||
|
'ResourceDescriptorHeap',
|
||||||
|
'SamplerDescriptorHeap',
|
||||||
|
'IsHelperLane',
|
||||||
|
'uint8_t4_packed',
|
||||||
|
'int8_t4_packed',
|
||||||
|
'unpack_s8s16',
|
||||||
|
'unpack_u8u16',
|
||||||
|
'unpack_s8s32',
|
||||||
|
'unpack_u8u32',
|
||||||
|
'pack_u8',
|
||||||
|
'pack_s8',
|
||||||
|
'pack_clamp_u8',
|
||||||
|
'pack_clamp_s8',
|
||||||
|
'WaveSize',
|
||||||
|
'raypayload',
|
||||||
|
|
||||||
|
// SM6.7
|
||||||
|
'QuadAll',
|
||||||
|
'QuadAny',
|
||||||
|
'WaveOpsIncludeHelperLanes',
|
||||||
|
]);
|
||||||
|
|
||||||
|
return hlsl;
|
||||||
|
}
|
||||||
|
|
||||||
|
monaco.languages.register({id: 'hlsl'});
|
||||||
|
monaco.languages.setMonarchTokensProvider('hlsl', definition());
|
||||||
|
|
||||||
|
export {};
|
||||||
@@ -39,6 +39,7 @@ export type LanguageKey =
|
|||||||
| 'go'
|
| 'go'
|
||||||
| 'ispc'
|
| 'ispc'
|
||||||
| 'haskell'
|
| 'haskell'
|
||||||
|
| 'hlsl'
|
||||||
| 'java'
|
| 'java'
|
||||||
| 'kotlin'
|
| 'kotlin'
|
||||||
| 'scala'
|
| 'scala'
|
||||||
|
|||||||
Reference in New Issue
Block a user