mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-05-23 22:13:38 +00:00
### Description
See
454996d496
for manual changes (excluded auto-generated formatting changes)
### Why
Because the toolsets for old clang-format is out-of-date. This reduces
the development efficiency.
- The NPM package `clang-format` is already in maintenance mode. not
updated since 2 years ago.
- The VSCode extension for clang-format is not maintained for a while,
and a recent Node.js security update made it not working at all in
Windows.
No one in community seems interested in fixing those.
Choose Prettier as it is the most popular TS/JS formatter.
### How to merge
It's easy to break the build:
- Be careful of any new commits on main not included in this PR.
- Be careful that after this PR is merged, other PRs that already passed
CI can merge.
So, make sure there is no new commits before merging this one, and
invalidate js PRs that already passed CI, force them to merge to latest.
103 lines
2.3 KiB
TypeScript
103 lines
2.3 KiB
TypeScript
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
// Licensed under the MIT License.
|
|
|
|
/**
|
|
* represent a version irrelevant abstraction of for GLSL source code
|
|
*/
|
|
export interface Glsl {
|
|
readonly version: string;
|
|
readonly attribute: string;
|
|
readonly varyingVertex: string;
|
|
readonly varyingFrag: string;
|
|
readonly texture2D: string;
|
|
readonly output: string;
|
|
readonly outputDeclaration: string;
|
|
}
|
|
|
|
const GLSL_ES_2_0: Glsl = {
|
|
version: '',
|
|
attribute: 'attribute',
|
|
varyingVertex: 'varying',
|
|
varyingFrag: 'varying',
|
|
texture2D: 'texture2D',
|
|
output: 'gl_FragColor',
|
|
outputDeclaration: '',
|
|
};
|
|
const GLSL_ES_3_0: Glsl = {
|
|
version: '#version 300 es',
|
|
attribute: 'in',
|
|
varyingVertex: 'out',
|
|
varyingFrag: 'in',
|
|
texture2D: 'texture',
|
|
output: 'outputColor',
|
|
outputDeclaration: 'out vec4 outputColor;',
|
|
};
|
|
|
|
export function getGlsl(version: 1 | 2) {
|
|
return version === 1 ? GLSL_ES_2_0 : GLSL_ES_3_0;
|
|
}
|
|
|
|
export function getVertexShaderSource(version: 1 | 2): string {
|
|
const glsl = getGlsl(version);
|
|
return `${glsl.version}
|
|
precision highp float;
|
|
${glsl.attribute} vec3 position;
|
|
${glsl.attribute} vec2 textureCoord;
|
|
|
|
${glsl.varyingVertex} vec2 TexCoords;
|
|
|
|
void main()
|
|
{
|
|
gl_Position = vec4(position, 1.0);
|
|
TexCoords = textureCoord;
|
|
}`;
|
|
}
|
|
|
|
export function getFragShaderPreamble(version: 1 | 2): string {
|
|
const glsl = getGlsl(version);
|
|
return `${glsl.version}
|
|
precision highp float;
|
|
precision highp int;
|
|
precision highp sampler2D;
|
|
${glsl.varyingFrag} vec2 TexCoords;
|
|
${glsl.outputDeclaration}
|
|
const vec2 halfCR = vec2(0.5, 0.5);
|
|
|
|
// Custom vector types to handle higher dimenalities.
|
|
struct ivec5
|
|
{
|
|
int x;
|
|
int y;
|
|
int z;
|
|
int w;
|
|
int u;
|
|
};
|
|
|
|
struct ivec6
|
|
{
|
|
int x;
|
|
int y;
|
|
int z;
|
|
int w;
|
|
int u;
|
|
int v;
|
|
};
|
|
|
|
int imod(int x, int y) {
|
|
return x - y * (x / y);
|
|
}
|
|
|
|
`;
|
|
}
|
|
|
|
export function getDefaultFragShaderMain(version: 1 | 2, outputShapeLength: number): string {
|
|
const glsl = getGlsl(version);
|
|
return `
|
|
void main() {
|
|
int indices[${outputShapeLength}];
|
|
toVec(TexCoords, indices);
|
|
vec4 result = vec4(process(indices));
|
|
${glsl.output} = result;
|
|
}
|
|
`;
|
|
}
|