Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/editor/browser/gpu/renderStrategy/fullFileRenderStrategy.wgsl.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { TextureAtlas } from '../atlas/textureAtlas.js';
7
import { TextureAtlasPage } from '../atlas/textureAtlasPage.js';
8
import { BindingId } from '../gpu.js';
9
10
export const fullFileRenderStrategyWgsl = /*wgsl*/ `
11
struct GlyphInfo {
12
position: vec2f,
13
size: vec2f,
14
origin: vec2f,
15
};
16
17
struct Vertex {
18
@location(0) position: vec2f,
19
};
20
21
struct Cell {
22
position: vec2f,
23
unused1: vec2f,
24
glyphIndex: f32,
25
textureIndex: f32
26
};
27
28
struct LayoutInfo {
29
canvasDims: vec2f,
30
viewportOffset: vec2f,
31
viewportDims: vec2f,
32
}
33
34
struct ScrollOffset {
35
offset: vec2f
36
}
37
38
struct VSOutput {
39
@builtin(position) position: vec4f,
40
@location(1) layerIndex: f32,
41
@location(0) texcoord: vec2f,
42
};
43
44
// Uniforms
45
@group(0) @binding(${BindingId.LayoutInfoUniform}) var<uniform> layoutInfo: LayoutInfo;
46
@group(0) @binding(${BindingId.AtlasDimensionsUniform}) var<uniform> atlasDims: vec2f;
47
@group(0) @binding(${BindingId.ScrollOffset}) var<uniform> scrollOffset: ScrollOffset;
48
49
// Storage buffers
50
@group(0) @binding(${BindingId.GlyphInfo}) var<storage, read> glyphInfo: array<array<GlyphInfo, ${TextureAtlasPage.maximumGlyphCount}>, ${TextureAtlas.maximumPageCount}>;
51
@group(0) @binding(${BindingId.Cells}) var<storage, read> cells: array<Cell>;
52
53
@vertex fn vs(
54
vert: Vertex,
55
@builtin(instance_index) instanceIndex: u32,
56
@builtin(vertex_index) vertexIndex : u32
57
) -> VSOutput {
58
let cell = cells[instanceIndex];
59
var glyph = glyphInfo[u32(cell.textureIndex)][u32(cell.glyphIndex)];
60
61
var vsOut: VSOutput;
62
// Multiple vert.position by 2,-2 to get it into clipspace which ranged from -1 to 1
63
vsOut.position = vec4f(
64
// Make everything relative to top left instead of center
65
vec2f(-1, 1) +
66
((vert.position * vec2f(2, -2)) / layoutInfo.canvasDims) * glyph.size +
67
((cell.position * vec2f(2, -2)) / layoutInfo.canvasDims) +
68
((glyph.origin * vec2f(2, -2)) / layoutInfo.canvasDims) +
69
(((layoutInfo.viewportOffset - scrollOffset.offset * vec2(1, -1)) * 2) / layoutInfo.canvasDims),
70
0.0,
71
1.0
72
);
73
74
vsOut.layerIndex = cell.textureIndex;
75
// Textures are flipped from natural direction on the y-axis, so flip it back
76
vsOut.texcoord = vert.position;
77
vsOut.texcoord = (
78
// Glyph offset (0-1)
79
(glyph.position / atlasDims) +
80
// Glyph coordinate (0-1)
81
(vsOut.texcoord * (glyph.size / atlasDims))
82
);
83
84
return vsOut;
85
}
86
87
@group(0) @binding(${BindingId.TextureSampler}) var ourSampler: sampler;
88
@group(0) @binding(${BindingId.Texture}) var ourTexture: texture_2d_array<f32>;
89
90
@fragment fn fs(vsOut: VSOutput) -> @location(0) vec4f {
91
return textureSample(ourTexture, ourSampler, vsOut.texcoord, u32(vsOut.layerIndex));
92
}
93
`;
94
95