mirror of
https://github.com/compiler-explorer/compiler-explorer.git
synced 2025-12-27 10:33:59 -05:00
Add SPIRV-Cross and SPIRV-Reflect (#7056)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
compilers=&spirv-opt:&spirv-val
|
||||
compilers=&spirv-opt:&spirv-val:&spirv-cross:&spirv-reflect
|
||||
defaultCompiler=spirv-opt
|
||||
|
||||
supportsBinary=false
|
||||
@@ -15,7 +15,19 @@ group.spirv-val.baseName=SPIRV-Tools Validator
|
||||
group.spirv-val.compilers=spirv-val
|
||||
group.spirv-val.compilerType=spirv-tools
|
||||
|
||||
group.spirv-cross.groupName=Translate
|
||||
group.spirv-cross.baseName=SPIRV-Cross
|
||||
group.spirv-cross.compilers=spirv-cross
|
||||
group.spirv-cross.compilerType=spirv-tools
|
||||
|
||||
group.spirv-reflect.groupName=Reflection
|
||||
group.spirv-reflect.baseName=SPIRV-Reflect
|
||||
group.spirv-reflect.compilers=spirv-reflect
|
||||
group.spirv-reflect.compilerType=spirv-tools
|
||||
|
||||
assemblerPath=/opt/compiler-explorer/SPIRV-Tools-master/build/tools/spirv-as
|
||||
disassemblerPath=/opt/compiler-explorer/SPIRV-Tools-master/build/tools/spirv-dis
|
||||
compiler.spirv-opt.exe=/opt/compiler-explorer/SPIRV-Tools-master/build/tools/spirv-opt
|
||||
compiler.spirv-val.exe=/opt/compiler-explorer/SPIRV-Tools-master/build/tools/spirv-val
|
||||
compiler.spirv-cross.exe=/usr/bin/spirv-cross
|
||||
compiler.spirv-reflect.exe=/usr/bin/spirv-reflect
|
||||
|
||||
@@ -43,6 +43,7 @@ import * as utils from '../utils.js';
|
||||
export class SPIRVToolsCompiler extends BaseCompiler {
|
||||
protected assemblerPath: string;
|
||||
protected disassemblerPath: string;
|
||||
protected spirvAsm: SPIRVAsmParser;
|
||||
|
||||
static get key() {
|
||||
return 'spirv-tools';
|
||||
@@ -51,7 +52,7 @@ export class SPIRVToolsCompiler extends BaseCompiler {
|
||||
constructor(compilerInfo: PreliminaryCompilerInfo, env: CompilationEnvironment) {
|
||||
super(compilerInfo, env);
|
||||
|
||||
this.asm = new SPIRVAsmParser(this.compilerProps);
|
||||
this.spirvAsm = new SPIRVAsmParser(this.compilerProps);
|
||||
|
||||
// spirv-as
|
||||
this.assemblerPath = this.compilerProps<string>('assemblerPath');
|
||||
@@ -137,17 +138,24 @@ export class SPIRVToolsCompiler extends BaseCompiler {
|
||||
return result;
|
||||
}
|
||||
|
||||
const spvasmFilename = path.join(sourceDir, this.outputFilebase + '.spvasm');
|
||||
// needs to update options depending on the tool
|
||||
const isValidator = compiler.endsWith('spirv-val');
|
||||
const isNonSprivOutput = compiler.endsWith('spirv-cross') || compiler.endsWith('spirv-reflect');
|
||||
if (isValidator) {
|
||||
// there is no output file, so remove what we added in optionsForFilter
|
||||
options = options.splice(2);
|
||||
options = this.unmergeSpirvTargetEnv(options);
|
||||
} else if (isNonSprivOutput) {
|
||||
options = options.splice(2);
|
||||
options.push('--output', spvasmFilename);
|
||||
} else {
|
||||
options = this.mergeSpirvTargetEnv(options);
|
||||
}
|
||||
|
||||
// have tools input a binary and output it to same binary temp file
|
||||
// Unless we don't want to run spirv-dis, we still save to a .spvasm because we don't know the compiler
|
||||
// at getOutputFilename() and can just adjust the parsing in processAsm()
|
||||
for (const i in options) {
|
||||
if (options[i] === inputFilename) {
|
||||
options[i] = spvBinFilename;
|
||||
@@ -161,7 +169,8 @@ export class SPIRVToolsCompiler extends BaseCompiler {
|
||||
if (isValidator) {
|
||||
result.validatorTool = true;
|
||||
}
|
||||
if (spvBin.code !== 0 || !(await utils.fileExists(spvBinFilename)) || isValidator) {
|
||||
|
||||
if (spvBin.code !== 0 || !(await utils.fileExists(spvBinFilename)) || isValidator || isNonSprivOutput) {
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -177,4 +186,12 @@ export class SPIRVToolsCompiler extends BaseCompiler {
|
||||
result = this.transformToCompilationResult(spvasmOutput, spvBinFilename);
|
||||
return result;
|
||||
}
|
||||
|
||||
override async processAsm(result, filters: ParseFiltersAndOutputOptions, options: string[]) {
|
||||
if (result.asm.startsWith('; SPIR-V')) {
|
||||
return this.spirvAsm.processAsm(result.asm, filters);
|
||||
}
|
||||
// If not SPIR-V, just display as plain text to be safe
|
||||
return super.processAsm(result, filters, options);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user