Path: blob/main/src/vs/editor/browser/gpu/renderStrategy/fullFileRenderStrategy.wgsl.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { TextureAtlas } from '../atlas/textureAtlas.js';6import { TextureAtlasPage } from '../atlas/textureAtlasPage.js';7import { BindingId } from '../gpu.js';89export const fullFileRenderStrategyWgsl = /*wgsl*/ `10struct GlyphInfo {11position: vec2f,12size: vec2f,13origin: vec2f,14};1516struct Vertex {17@location(0) position: vec2f,18};1920struct Cell {21position: vec2f,22unused1: vec2f,23glyphIndex: f32,24textureIndex: f3225};2627struct LayoutInfo {28canvasDims: vec2f,29viewportOffset: vec2f,30viewportDims: vec2f,31}3233struct ScrollOffset {34offset: vec2f35}3637struct VSOutput {38@builtin(position) position: vec4f,39@location(1) layerIndex: f32,40@location(0) texcoord: vec2f,41};4243// Uniforms44@group(0) @binding(${BindingId.LayoutInfoUniform}) var<uniform> layoutInfo: LayoutInfo;45@group(0) @binding(${BindingId.AtlasDimensionsUniform}) var<uniform> atlasDims: vec2f;46@group(0) @binding(${BindingId.ScrollOffset}) var<uniform> scrollOffset: ScrollOffset;4748// Storage buffers49@group(0) @binding(${BindingId.GlyphInfo}) var<storage, read> glyphInfo: array<array<GlyphInfo, ${TextureAtlasPage.maximumGlyphCount}>, ${TextureAtlas.maximumPageCount}>;50@group(0) @binding(${BindingId.Cells}) var<storage, read> cells: array<Cell>;5152@vertex fn vs(53vert: Vertex,54@builtin(instance_index) instanceIndex: u32,55@builtin(vertex_index) vertexIndex : u3256) -> VSOutput {57let cell = cells[instanceIndex];58var glyph = glyphInfo[u32(cell.textureIndex)][u32(cell.glyphIndex)];5960var vsOut: VSOutput;61// Multiple vert.position by 2,-2 to get it into clipspace which ranged from -1 to 162vsOut.position = vec4f(63// Make everything relative to top left instead of center64vec2f(-1, 1) +65((vert.position * vec2f(2, -2)) / layoutInfo.canvasDims) * glyph.size +66((cell.position * vec2f(2, -2)) / layoutInfo.canvasDims) +67((glyph.origin * vec2f(2, -2)) / layoutInfo.canvasDims) +68(((layoutInfo.viewportOffset - scrollOffset.offset * vec2(1, -1)) * 2) / layoutInfo.canvasDims),690.0,701.071);7273vsOut.layerIndex = cell.textureIndex;74// Textures are flipped from natural direction on the y-axis, so flip it back75vsOut.texcoord = vert.position;76vsOut.texcoord = (77// Glyph offset (0-1)78(glyph.position / atlasDims) +79// Glyph coordinate (0-1)80(vsOut.texcoord * (glyph.size / atlasDims))81);8283return vsOut;84}8586@group(0) @binding(${BindingId.TextureSampler}) var ourSampler: sampler;87@group(0) @binding(${BindingId.Texture}) var ourTexture: texture_2d_array<f32>;8889@fragment fn fs(vsOut: VSOutput) -> @location(0) vec4f {90return textureSample(ourTexture, ourSampler, vsOut.texcoord, u32(vsOut.layerIndex));91}92`;939495