Method for accelerating dynamic text rendering of code editor based on GPU context awareness

By establishing a multi-dimensional semantic tagging system and GPU context awareness technology, the problems of weak semantic expression, high interaction latency, and low structural layout efficiency in existing code editors have been solved, achieving efficient dynamic text rendering and meeting real-time requirements.

CN121255165BActive Publication Date: 2026-04-07北京麟卓信息科技有限公司
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-12-04
Publication Date
2026-04-07

AI Technical Summary

Technical Problem

Existing code editors' dynamic text rendering methods cannot effectively perceive semantics, resolve interaction conflicts, or reduce latency, resulting in weak semantic expression capabilities, high latency in updating interactive styles, and low efficiency in structural layout calculations. This fails to meet real-time requirements and leads to a disconnect between enhancement effects and semantics.

Method used

By establishing a multi-dimensional semantic tagging system and utilizing GPU context-aware technology, semantic sub-dimensions of characters are extracted and character semantic tags are generated, which are cached in semantic tag SSBOs to construct semantic rule textures; structural units are identified and encoded as structural layout SSBOs; the shader is calculated to assign semantic, interaction, structural, and effect weights to generate style weight textures; the vertex shader calculates character positions in parallel, and the fragment shader blends rendering effects in layers.

Benefits of technology

It achieves semantic awareness, conflict-free interaction, and zero-latency dynamic text rendering, improving the semantic expression capability, interaction response speed, and layout calculation efficiency of the code editor, and meeting the real-time requirement of 60fps.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121255165B_ABST
    Figure CN121255165B_ABST
Patent Text Reader

Abstract

This invention discloses a GPU-based context-aware code editor dynamic text rendering acceleration method. It establishes a multi-dimensional semantic tagging system including variables, functions, errors, and structures. Semantic sub-dimensions of characters are extracted and processed to generate character semantic tags, which are then cached in semantic tag SSBOs. A mapping rule between semantic tags and rendering styles is constructed, and the CPU encodes the semantic rules into semantic rule textures. Structural units and their layout attributes are identified, and the CPU encodes them into structural textures and uploads them to the GPU's structural layout SSBOs. The compute shader reads two types of SSBOs and assigns four weights—semantic, interactive, structural, and effect—to the characters. After determining the fusion coefficients, it generates style-weighted textures. The vertex shader calculates the final screen position of the character in parallel based on the structural unit to which the character belongs. The fragment shader reads the two types of SSBOs, each texture, and the final screen position output by the vertex shader, and fuses them layer by layer according to the weight order to complete pixel-level character rendering.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of computer software development technology, specifically relating to a method for accelerating dynamic text rendering in a GPU-based context-aware code editor. Background Technology

[0002] Dynamic text rendering in code editors differs from ordinary text rendering. It must simultaneously meet core requirements such as semantic relevance where styles change with code semantics, real-time interaction with no delay for high-frequency operations, and structural adaptability where layout dynamically adjusts with code folding.

[0003] Existing dynamic text rendering methods in code editors suffer from the following main problems: Static semantic and style mapping. While existing methods use a two-dimensional mapping table predefined by the CPU for syntax types and styles (e.g., keywords are red #FF5555, comments are gray #999999), they cannot relate to the semantic context of the code. For example, for the same variable type, styles cannot be differentiated in scenarios involving global variables, function parameters, and loop variables, resulting in weak semantic expression. Furthermore, when semantics change, the CPU needs to regenerate the mapping table and upload it to the GPU, leading to latency exceeding 30ms in large file scenarios. Interactive style conflicts are difficult to resolve. In complex interactions such as multi-cursor editing, overlapping selections, and hover tooltips, existing methods use a last-in-first-out style overriding logic, causing loss of visual information, such as the selection background color disappearing when multiple cursors are positioned within a selection. Users cannot determine the selection area. In addition, updating the interactive style requires redrawing the entire text area. For high-frequency operations, such as rapid movement of multiple cursors, the frame rate drops sharply to below 20fps. The layout calculation is inefficient when the structure changes. When the code is folded or expanded, the existing method requires the CPU to recalculate the line height and position of all text, generate new vertex data and upload it to the GPU. In a scenario with 100,000 lines of code, the layout calculation takes more than 50ms and the data upload takes more than 20ms, which is difficult to meet the real-time requirement of 60fps (16ms per frame). Moreover, the folded state is prone to jumps, resulting in a poor visual experience. The enhancement effects are disconnected from the semantics. The enhancement effects such as spelling errors, syntax errors, and breakpoint markers are fixed styles and cannot distinguish the error type and severity. The effect rendering depends on additional textures, which increases memory usage and sampling overhead.

[0004] In conclusion, existing code editors still cannot achieve dynamic text rendering that is semantically aware, resolves interaction conflicts, and reduces latency. Summary of the Invention

[0005] In view of this, the present invention provides a method for accelerating dynamic text rendering in a code editor based on GPU context awareness, which realizes dynamic text rendering with semantic awareness, no interaction conflicts, and zero structural latency.

[0006] The method for accelerating dynamic text rendering in a code editor based on GPU context awareness provided by this invention specifically includes the following steps:

[0007] The semantic type of characters in the code is extracted as a semantic sub-dimension. The character semantic label is obtained by ORing the binary values ​​of all semantic sub-dimensions and cached in the semantic label SSBO. The mapping between the character semantic label and the rendering style constitutes the semantic rule. The CPU encodes the semantic rule into a semantic rule texture, where the X-axis is the character semantic label, the Y-axis is the character context attribute, and the Z-axis is the character rendering style.

[0008] The code segments with independent logic are used as structural units. The layout attributes of the structural units are obtained, and the CPU encodes the layout attributes into structural textures and uploads them to the Structural Layout SSBO.

[0009] The compute shader reads the semantic tag SSBO, assigns semantic weights, structural weights, and effect weights to the characters, marks the visibility of structural units, assigns interaction weights by GPU atomic operations, determines the transparency of style overlay as the blending coefficient, and constructs a style weight texture with the same size as the text rendering viewport by semantic weights, interaction weights, structural weights, effect weights, and blending coefficients.

[0010] The vertex shader processes the vertex data of the character in parallel and calculates the final screen position of the character; the fragment shader reads the semantic tag SSBO and the structural layout SSBO to draw semantic enhancement effects, and determines the semantic style, structural style and interaction style of the character based on the semantic rule texture, style weight texture and the final screen position. The rendering effects are blended from the bottom layer, middle layer to the top layer to complete the pixel-level rendering of the character.

[0011] Furthermore, the semantic rule texture adopts RGBA32F floating-point format, nearest neighbor sampling, and disables mipmap.

[0012] Furthermore, the rendering style includes a base color, transparency, font style, and enhancement effects, including wavy lines and dashed lines.

[0013] Furthermore, the method of caching to semantic tags SSBO is as follows: for code text with a code size greater than a threshold, the CPU uses the OpenGL glBufferData function to upload it to the GPU, and only uploads the semantic tags of the changed characters when the code text changes.

[0014] Furthermore, the structural unit includes function units, code block units, macro definition units, and comment block units, and the layout attributes include structural unit ID, parent structural unit ID, start character index, end character index, base Y coordinate, total height, vertical offset after collapsing, character spacing scaling factor, whether it is collapsed, and whether it is visible.

[0015] Furthermore, the vertex shader processes the vertex data of the character in parallel to calculate the final screen position of the character as follows: the vertex shader searches for the structural unit to which the character belongs in the structure layout SSBO based on the global index of the character, calculates the fold offset of the character and the basic position of the character when the structural unit is folded, calculates the final position of the character based on the basic position, fold offset and scroll offset, and then converts the final position into clip space coordinates that the GPU can recognize through projection matrix transformation, which is the final screen position.

[0016] Furthermore, the vertex shader searches for the structural unit to which a character belongs in the SSBO based on the character's global index by using a binary search algorithm to search in the SSBO.

[0017] Furthermore, the vertex shader only processes characters located in the visible structural units.

[0018] Furthermore, based on the user's visual attention, the viewport importance is determined and the viewport is classified into a core area, a transition area, and an edge area. The core area is the central area of ​​the viewport, the transition area is the area adjacent to the core area, and the edge area is the outer area of ​​the transition area. The vertex shader marks the viewport level to which each pixel belongs and passes it to the fragment shader. The fragment shader configures rendering parameters differently according to the viewport level.

[0019] Furthermore, by monitoring key GPU load metrics through GPU timers, when the load metric is less than the minimum threshold, the sampling frequency of MSAA is reduced in the transition region and the pixel mapping ratio is reduced in the edge region; when the load metric is not less than the minimum threshold and is less than the maximum threshold, the sampling frequency of MSAA is reduced in the core region and the enhancement effect is disabled in the transition region; when the load metric is not less than the maximum threshold, the pixel mapping ratio is reduced in the core region and FXAA is disabled in the edge region. Beneficial effects

[0020] This invention establishes a multi-dimensional semantic tagging system encompassing variables, functions, errors, and structures. It extracts the semantic sub-dimensions of characters and generates character semantic tags through computation, which are then cached in semantic tag SSBOs. A mapping rule between semantic tags and rendering styles is constructed, and the CPU encodes the semantic rules into semantic rule textures. Structural units and their layout attributes are identified, and the CPU encodes them into structural textures and uploads them to the GPU's structural layout SSBOs. The compute shader reads two types of SSBOs and assigns four weights—semantic, interactive, structural, and effect—to the characters. After determining the fusion coefficients, it generates style-weighted textures. The vertex shader calculates the final screen position of the character in parallel based on the structural unit to which the character belongs. The fragment shader reads the two types of SSBOs, each texture, and the final screen position output by the vertex shader, and fuses them layer by layer according to the weight order to complete pixel-level rendering of the characters. Attached Figure Description

[0021] Figure 1 A flowchart illustrating the GPU-based context-aware code editor dynamic text rendering acceleration method provided by this invention. Detailed Implementation

[0022] The present invention will be described in detail below with reference to the accompanying drawings and embodiments.

[0023] The core idea of ​​the GPU-based context-aware code editor dynamic text rendering acceleration method provided by this invention is as follows: A multi-dimensional semantic tag system including variables, functions, errors, and structures is established; semantic sub-dimensions of characters are extracted and generated into character semantic tags through calculation; these tags are cached in semantic tag SSBOs; a mapping rule between semantic tags and rendering styles is constructed; the CPU encodes the semantic rules into semantic rule textures; structural units and their layout attributes are identified, and the CPU encodes them into structural textures and uploads them to the GPU's structural layout SSBOs; the compute shader reads two types of SSBOs and assigns four weights—semantic, interactive, structural, and effect—to the characters; after determining the fusion coefficients, a style weight texture is generated; the vertex shader calculates the final screen position of the character in parallel based on the structural unit to which the character belongs; the fragment shader reads the two types of SSBOs, each texture, and the final screen position output by the vertex shader, and fuses them layer by layer according to the weight order to complete pixel-level rendering of the characters.

[0024] The method for accelerating dynamic text rendering in a code editor based on GPU context awareness provided by this invention has the following process: Figure 1 As shown, the specific steps include:

[0025] Step 1: Establish a multi-dimensional semantic tagging system encompassing four dimensions: variables, functions, errors, and structures. Each semantic dimension contains multiple semantic sub-dimensions representing semantic types, and these sub-dimensions are represented by binary values. The code editor's parser extracts the semantic sub-dimensions of characters within the code. A bitwise OR operation is performed on the binary values ​​corresponding to all semantic sub-dimensions to obtain the character semantic tags. The mapping relationship between character semantic tags and rendering styles constitutes semantic rules. Semantic tag SSBOs are created for GPU storage. SSBOs are used to cache the character semantic tags of all characters, including the total number of characters and the character semantic tag array. The CPU encodes the semantic rules into a 3D semantic rule texture. In the 3D semantic rule texture, the X-axis represents the character semantic tags, the Y-axis represents the character context attributes, and the Z-axis represents the character rendering style.

[0026] Furthermore, the GPU optimization configuration for 3D semantic rule textures is as follows: RGBA32F floating-point format is adopted to ensure high-precision storage of style parameters; nearest neighbor sampling GL_NEAREST is used to avoid distortion of semantic rule parameter interpolation; mipmap is disabled to avoid rule confusion caused by the discrete mapping of semantic rules.

[0027] The rendering styles include base color, transparency and font style, and enhancement effects, such as wavy lines and dashed lines.

[0028] The CPU uploads character semantic tags to the Semantic Tag Optimization (SSBO) in the following way: for code text with a code size greater than a threshold, such as 100,000 lines of code text, the OpenGL glBufferData function is used to upload the code to the GPU in one go; and when the code text changes, the semantic tags of the characters that have changed are uploaded to avoid full retransmission.

[0029] Step 2: The code editor's parser identifies segments with independent logic in the code; these segments are called structural units. The layout attributes of these structural units are obtained. Structural units include function units, code block units, macro definition units, and comment block units. Layout attributes include structural unit ID, parent structural unit ID, start character index, end character index, base Y coordinate, total height, vertical offset after collapsing, character spacing scaling factor, whether it is collapsed, and whether it is visible. A Structural Layout Object (SSBO) is created to cache all structural units and their layout attributes, including the total number of structural units and the structural unit array. The CPU encodes the layout attributes of the structural units into 2D structural textures. The 2D structural texture includes the number of layers, layer resolution, and layer content. Each layer corresponds one-to-one with a structural unit; the number of layers is the number of structural units, the layer resolution is the number of layout attributes contained in the structural unit, and the layer content is the actual value of the layout attributes of the structural unit. The CPU uploads the 2D structural texture to the GPU's Structural Layout Object (SSBO).

[0030] Step 3: The compute shader reads the semantic tag SSBO and assigns semantic weights to the semantic sub-dimensions of the characters; when the user performs an interactive operation, the GPU atomic operations assign interaction weights to the characters related to the interactive operation; the compute shader reads the structural units in the structure layout SSBO, assigns structural weights to the collapsed parent nodes and collapsed child nodes respectively, and marks the visibility of the structural units; the compute shader reads the semantic tag SSBO and assigns effect weights to the semantic sub-dimensions under the error dimension; the transparency of the style overlay is determined and used as the blending coefficient; a 5-channel 2D style weight texture is constructed from semantic weights, interaction weights, structural weights, effect weights, and blending coefficients, and the size of the 2D style weight texture is consistent with the text rendering viewport.

[0031] Step 4: Using the instantiation rendering method, the character is used as an instance. The vertex shader processes the vertex data of each instance in parallel to calculate the final screen position of the character. The vertex data includes the local texture coordinates of the character, the global index of the character, and the basic width and spacing of the character.

[0032] Specifically, the vertex shader processes the vertex data of each instance in parallel to calculate the final screen position of the character. This includes: the vertex shader finds the structural unit to which the character belongs in the structured layout SSBO based on the character's global index, and when the structural unit is collapsed, calculates the character's collapse offset, calculates the character's base position, calculates the character's final position based on the base position, collapse offset, and scroll offset, and then converts the final position into clip space coordinates that the GPU can recognize, i.e., the final screen position, by transforming and adapting the viewport specifications through the projection matrix.

[0033] The fold offset is the sum of the fold offsets of all parent structural units of the character. The final position is calculated based on the base position, fold offset, and scroll offset. The specific formula is: final Y coordinate of character = base Y coordinate of character - sum of fold offsets of all parent structural units - scroll offset Y coordinate.

[0034] Furthermore, the vertex shader searches for the structural unit to which a character belongs in the Structured Layout SSBO based on the character's global index by using a binary search algorithm.

[0035] To further reduce unnecessary computations and improve computational efficiency, the vertex shader in this invention only processes characters located within visible structural units. Furthermore, the computation shader can update the visibility of structural units in real time based on their folding offset, specifically by calculating the maximum and minimum visible Y-coordinates visibleYMax and visibleYMin according to the following formulas:

[0036] visibleYMin=structUnit.baseY-foldedOffset-scrollOffsetY

[0037] visibleYMax=visibleYMin+structUnit.totalHeight*(structUnit.isFolded?0.1:1.0)

[0038] Where structUnit.baseY is the base Y coordinate of the character of the struct unit, foldedOffset is the folding offset, scrollOffsetY is the scrolling offset Y, structUnit.totalHeight is the height of the struct unit, and structUnit.isFolded indicates whether the struct unit has been folded;

[0039] If visibleYMax < 0 or visibleYMin > viewportHeight, the structural unit is invisible; otherwise, the structural unit is visible. Here, viewportHeight is the viewport height.

[0040] To avoid complex layer index calculations in vertex shaders, this invention creates an index buffer for 2D structured textures to store the mapping relationship between structure unit IDs and texture layers.

[0041] Step 5: The fragment shader reads the semantic tag SSBO and the structural layout SSBO, and draws the semantic enhancement effect according to the enhancement effect generation logic; it reads the 3D semantic rule texture, 2D style weight texture, viewport size, character texture coordinates, character global index, and the final screen position and scroll offset of the character generated by the vertex shader, samples the semantic weight, interaction weight, structural weight, effect weight, and blending coefficient of the current character, normalizes and calculates them to control the blending intensity of various styles, and obtains the semantic style parameters, structural style parameters, and interaction style parameters of the current character; it uses structural weight and blending coefficient to control folding and... The transparency of the unfolded background color serves as the base color for character display, achieving underlying structural style fusion. The semantic base color is combined with the glyph and then merged with the base color according to semantic weight, achieving mid-level semantic style fusion for semantic highlighting of keywords, annotations, etc. The transparency of the cursor and selection background color is controlled based on interaction weight, avoiding already merged background and semantic color areas, achieving mid-level interactive style fusion. For characters with semantic tags containing error markers and effective effect weights, enhancement effects such as error wavy lines are generated and merged to the top layer according to effect weights, achieving top-level enhancement effect fusion and completing pixel-level rendering of characters.

[0042] This application integrates four types of styles—structure, semantics, interaction, and enhancement effects—at the pixel level. Through layered weight fusion logic, it generates the final screen pixel color of characters in the code editor, achieving a unified presentation of multi-dimensional visual effects such as folded backgrounds, semantic highlighting, cursor and selection interaction, and error wavy lines. At the same time, it adapts character glyphs and style priorities.

[0043] Among them, the enhancement effect generation logic is the specific construction method of the enhancement effect, such as generating the vertices of the wavy line based on the sine curve.

[0044] Furthermore, in order to maintain stable rendering on both high-performance and low-performance devices, this invention dynamically adjusts the rendering accuracy through viewport importance hierarchy, specifically as follows:

[0045] The importance of the viewport is determined based on the user's visual attention. The viewport is divided into a core area, a transition area, and an edge area. The core area is the central area of ​​the viewport, the transition area is the area adjacent to the core area, and the edge area is the outer area of ​​the transition area. The vertex shader marks the viewport level of each pixel and passes it to the fragment shader for precision adjustment. The fragment shader configures rendering parameters differently according to the viewport level to reduce the GPU overhead in non-core areas.

[0046] The vertex shader marks the viewport level of each pixel by calculating the normalized coordinates of the pixel in the viewport, determining whether the pixel belongs to the core region, transition region or edge region in the vertical and horizontal directions, and determining the viewport level based on the region to which the pixel belongs.

[0047] The fragment shader configures rendering parameters differently based on the viewport level by adjusting the pixel mapping ratio through scaling the texture sampling coordinates. For example, the transition area uses a 1.25x scaling, corresponding to a 0.8:1 mapping. The MSAA level is also adjusted, with the core area set to 4xMSAA, the transition area to 2xMSAA, and the edge area to have no MSAA.

[0048] Furthermore, this invention provides a method for adjusting rendering parameters based on GPU load, specifically: monitoring key GPU load metrics, including frame time, fragment shader execution time percentage, and texture bandwidth utilization, through a GPU timer; reducing the number of MSAA samples in the transition region and further reducing the pixel mapping ratio in the edge region when the GPU is lightly overloaded; reducing the number of MSAA samples in the core region and disabling enhancement effects in the transition region when the GPU is moderately overloaded; reducing the pixel mapping ratio in the core region and disabling FXAA in the edge region when the GPU is heavily overloaded; and enabling enhancement effects in the edge region and increasing MSAA in the core region when the GPU is low-loaded, in order to improve visual quality.

[0049] Furthermore, the adjustment of rendering parameters adopts a smooth transition method, that is, all adjustments are completed in multiple frames to avoid visual jumps.

[0050] Furthermore, a weighted ALPHA blending model can be used to calculate the final color of the character by combining the rendering styles of semantics, interaction, structure, and effects based on semantic weights, interaction weights, structural weights, effect weights, and blending coefficients. Example

[0051] This embodiment takes an IDE as an example and adopts the GPU context-aware code editor dynamic text rendering acceleration method provided by this invention. It achieves stable rendering in large file and highly interactive scenarios through GPU-driven full-process semantic computation, multi-dimensional style weight fusion mechanism, and structured layout caching architecture. The specific process includes:

[0052] S1. Context-aware semantic rule compilation and encoding. This transforms the semantic information of the code into structured data that the GPU can directly parse, enabling real-time mapping from semantics to rendering styles. Unlike existing static mapping on the CPU, this achieves efficient GPU-side access to multi-dimensional semantics through 3D semantic rule textures and semantic tag SSBOs (Semantic Target Objects). SSBOs serve as shader storage buffer objects.

[0053] S1.1 Extraction and marking of code semantic dimensions.

[0054] S1.1.1 Semantic Dimension System Construction.

[0055] The code editor's parser (such as one based on ANTLR or Tree-sitter) extracts multi-dimensional semantic tags for each character in the text. The tag system contains 4 main categories and 12 sub-dimensions, each represented by 4 bits (16 bits in total, supporting 65,536 semantic combinations), as shown in Table 1.

[0056] Table 1 Multi-dimensional Semantic Tag System

[0057] S1.1.2, Generation of character-level semantic tags.

[0058] For each character in the code text, the parser determines all its semantic sub-dimensions. The binary values ​​corresponding to all semantic sub-dimensions are then ORed to generate a 16-bit unsigned integer character semantic label. For example, the semantic sub-dimension of the third character of the undefined variable `undefVar` includes local variables (0010) and semantic errors (0010). The semantic label obtained by ORing 0010 and 0010 is 0x0012.

[0059] S1.1.3. Construct Semantic Tag SSBO to realize GPU storage of semantic tags.

[0060] The semantic tags of all characters are stored in the GPU's shader storage buffer object SSBO. The data structure of SSBO is defined as follows:

[0061] / / CPU-side definition, used for data upload

[0062] struct SemanticSSBOData {

[0063] uint32_t charCount; / / Total number of characters (e.g., approximately 5 million characters for 100,000 lines of code)

[0064] uint16_t semanticTags[]; / / Array of character semantic tags (length = charCount)

[0065] };

[0066] / / GPU-side access (GLSL)

[0067] layout(std430, binding = 0) buffer SemanticSSBO {

[0068] uint charCount;

[0069] uint16_t semanticTags[];

[0070] };

[0071] For the data upload strategy, for 100,000 lines of code (approximately 5 million characters), the semantic tag array size is 5 million multiplied by 2 bytes, which equals 10MB. It is uploaded to the GPU in one go using the OpenGL glBufferData function. When the text is modified, the semantic tags of the modified characters are uploaded. For example, if 10 characters are modified, only 20 bytes are uploaded.

[0072] S1.2, 3D texture encoding of semantic rules serves as a mapping carrier from semantics to rendering style.

[0073] S1.2.1 Parameter definition of 3D semantic rule texture. Create a 256×256×4 3D texture SemanticRuleTexture to store the mapping relationship between semantic tags and rendering styles.

[0074] The X-axis represents the semantic tag index, with values ​​ranging from 0 to 255, corresponding to the high 8 bits of the semantic tag; the Y-axis represents the contextual attributes, with values ​​ranging from 0 to 255, storing supplementary contextual information about the semantics, such as error severity (0 for minor, 1 for moderate, 2 for severe) and variable lifecycle (0 for unused, 1 for used); the Z-axis represents the style parameter channels, with values ​​ranging from 0 to 3, corresponding to four types of style parameters. Each channel stores a 32-bit floating-point number in RGBA32F format, as shown in Table 2.

[0075] Table 2. Parameters Related to Rendering Style

[0076] S1.2.2 Texture filling of preprocessed semantic rules on the CPU side.

[0077] The CPU-side tools encode user-defined semantic rules, such as syntax errors being severely rendered as red text and a 2px red wavy line, into pixel values ​​for 3D textures. For example:

[0078] Semantic rules: Syntax error (the high 8 bits of the semantic tag are 0x21), severe (Y=2), the corresponding rendering style is a base color of red (1.0,0.0,0.0), an opacity of 1.0 to indicate opacity, a wavy line amplitude of 2.0px, and an effect color of (1.0,0.0,0.0) (red).

[0079] Encoding process: Write the above parameters into the (X=0x21, Y=2, Z=0)~(Z=3) pixels of the 3D texture, where the pixel value of Z=0 is (1.0,0.0,0.0,0.0), Z=1 is (1.0,1.0,0.0,0.0) (1.0 = transparency, 1.0 = bold), Z=2 is (2.0,0.0,0.0,0.0), and Z=3 is (1.0,0.0,0.0,0.0).

[0080] S1.2.3, GPU-optimized configuration for textures.

[0081] The RGBA32F floating-point format is used to ensure high-precision storage of style parameters, such as the ability to identify 0.1px difference in the amplitude of wavy lines; GL_NEAREST is used to avoid distortion in the parameter interpolation of semantic rules.

[0082] S2. Construction and dynamic updating of multi-dimensional style weight textures.

[0083] By constructing textures with four dimensions of weights—semantics, interaction, structure, and effects—and utilizing GPU parallel computing to dynamically update and resolve conflicts among these weights, the system addresses style overlay issues in complex interactions such as multiple cursors and overlapping selections. Unlike traditional last-in-first-out overlay logic, it achieves seamless fusion of multiple styles through quantified calculation of weight values.

[0084] S2.1 Definition of multi-dimensional weighting system.

[0085] S2.1.1 Weight Dimensions and Value Range:

[0086] Create a 5-channel 2D texture StyleWeightTexture with the same size as the text rendering viewport, such as 1920×1080. Each channel stores an 8-bit unsigned integer with a value range of 0 to 255 and a corresponding weight of 0.0 to 1.0. The definitions of each channel are shown in Table 3.

[0087] Table 3 Channel Definition Table

[0088] S2.1.2, Physical meaning of weights:

[0089] The weight value represents the contribution of the corresponding style to the final rendering result. The higher the weight, the greater the visual proportion of the style. For example, the semantic weight is 0.9 (229) and the interaction weight is 0.6 (153), which means that the semantic style contributes 90% and the interaction style contributes 60%, and the overlay is achieved through alpha blending; the blending coefficient is 0.8 (204), and the opacity of the overlaid style is 80%, avoiding complete coverage of the underlying style.

[0090] S2.2, GPU parallel computation of weights.

[0091] S2.2.1 Calculating Semantic Weights Based on Semantic Tags: The compute shader reads the semantic tags of the SemanticSSBO, assigns weight values ​​according to semantic type, and writes them to the R channel of StyleWeightTexture.

[0092] layout(local_size_x = 16, local_size_y = 16) in;

[0093] layout(rgba8ui, binding = 0) uniform uimage2D styleWeightImage;

[0094] layout(std430, binding = 1) buffer SemanticSSBO {

[0095] uint charCount;

[0096] uint16_t semanticTags[];

[0097] };

[0098] void main() {

[0099] / / Calculate the texture coordinates (viewport space) corresponding to the current thread.

[0100] ivec2 texelPos = ivec2(gl_GlobalInvocationID.xy);

[0101] uint charGlobalIdx = texelPos.y * imageSize(styleWeightImage).x +texelPos.x;

[0102] / / Boundary check (to avoid exceeding the total number of characters)

[0103] if (charGlobalIdx >= semanticSSBO.charCount) return;

[0104] / / Read semantic tags and parse types

[0105] uint16_t semanticTag = semanticSSBO.semanticTags[charGlobalIdx];

[0106] uint semanticType = (semanticTag >> 8) & 0xFF; / / Semantic type (high 8 bits)

[0107] / / Assign semantic weights (0 to 255)

[0108] uint semanticWeight = 50; / / Default: plain text (weight 0.2)

[0109] if (semanticType == 0x21) semanticWeight = 255; / / Syntax error (weight 1.0)

[0110] else if (semanticType == 0x11) semanticWeight = 180; / / Function definition (weight 0.7)

[0111] else if (semanticType == 0x04) semanticWeight = 120; / / Parameter variable (weight 0.47)

[0112] / / Read the current weighted texture value and update the R channel (semantic weight).

[0113] uvec4 currentWeights = imageLoad(styleWeightImage, texelPos);

[0114] currentWeights.r = semanticWeight;

[0115] imageStore(styleWeightImage, texelPos, currentWeights);

[0116] / / Update the fusion coefficient (the fusion coefficient corresponding to the semantic weight = semantic weight, ensuring opacity).

[0117] imageStore(styleWeightImageExtra, texelPos, uvec4(semanticWeight));

[0118] }

[0119] S2.2.2. Based on user operations, calculate interaction weights. When a user performs an interactive operation (such as clicking to create a cursor or dragging to select a region), update the G channel of StyleWeightTexture in real time through GPU atomic operations to avoid CPU-to-GPU data transfer latency.

[0120] Multi-cursor weight update: When the user creates a cursor at position (x=200, y=300), the G channel value of that pixel is updated to 220 (weight 0.86) using the OpenGL glTexSubImage2D function. If the cursor moves, the G channel value at the original position is first set to 0 using an atomic operation (atomicMin), and then the new position is set to 220. Overlapping selection weight update: When two selections overlap, the maximum weight value is taken using the atomicMax function. For example, selection 1 has a weight of 150, selection 2 has a weight of 180, and the G channel value of the overlapping area is 180 (taking the maximum value) to avoid weight overlap.

[0121] S2.2.3 Calculate the structural weights and effect weights.

[0122] Structural weights: The structural unit information of StructLayoutSSBO is read through Compute Shader, and the B channel weights of the folded parent node are assigned from 180 to 220, and the weights of the folded child nodes are assigned from 30 to 79.

[0123] Effect weights: Based on the error flags of SemanticSSBO, assign an A channel weight of 255 to syntax errors, 180 to warnings, and 0 to no effect.

[0124] S2.2.4, Mechanism for resolving weight conflicts.

[0125] The mathematical model for weighted fusion adopts a weighted Alpha fusion model, which superimposes the styles corresponding to the four-dimensional weights in priority order. The formula is as follows: Final color = (Semantic style color × Semantic weight × fusion coefficient) + (Interactive style color × Interactive weight × (1 - Semantic weight × fusion coefficient)) + (Structure style color × Structure weight × (1 - Semantic weight × fusion coefficient - Interactive weight × fusion coefficient)) + (Effect style color × Effect weight × (1 - Total preceding weight)), where the total preceding weight = Semantic weight × fusion coefficient + Interactive weight × fusion coefficient + Structure weight × fusion coefficient, ensuring that the color value after superposition is in the range of 0.0 to 1.0.

[0126] Example of resolving conflicts when multiple cursors overlap with a selection:

[0127] Hypothetical scenario: Multiple cursors (G channel weight 220, 0.86) overlap with a selection area (G channel weight 180, 0.71), semantic weight R255 is 1.0 (syntax error), and fusion coefficient R255 is 1.0.

[0128] Semantic style contribution: Red text × 1.0 × 1.0 is red;

[0129] Interactive style contribution: Cursor yellow background × 0.86 × (1 - 1.0 × 1.0) + Selection area blue background × 0.71 × (1 - 1.0 × 1.0) = 0;

[0130] Final result: Red text (semantic style) and a semi-transparent yellow cursor (by reducing the blending coefficient to 0.5, the interaction style contribution is yellow × 0.86 × 0.5 = 0.43), achieving the effect of overlaying red text and yellow cursor background without visual conflict.

[0131] S2.3 Optimization and management of weighted textures.

[0132] Local update strategy: When text is modified, only the weighted texture pixels corresponding to the modified characters are updated. For example, when 10 characters are modified, 10 pixels are updated. During interactive operations, only the pixels of the operation area are updated. For example, when the cursor moves, only 2 pixels are updated, namely the old position and the new position. When the structure changes, only the pixel area corresponding to the structural unit is updated. For example, when a function is folded, all the character pixels of the function are updated.

[0133] mipmap and anisotropic filtering: Generates a mipmap with weighted textures to ensure smooth transition of weight values ​​when text is scaled, avoiding blocky distortion; enables anisotropic filtering (4x) to ensure the accuracy of weight sampling when scrolling diagonally.

[0134] The multi-dimensional weight quantification system transforms the style importance of semantics, interaction, structure, and effect into computable weight values, breaking through the existing qualitative style coverage logic and achieving quantitative style fusion; it utilizes GPU atomic operations to achieve lock-free update of interaction weights, avoiding CPU-GPU data transmission latency, and reducing the interaction response latency in multi-cursor scenarios from 15ms to 2ms.

[0135] S3, Structured Layout Caching and GPU-side Layout Generation.

[0136] By using layout caching at the structural unit level, the global layout calculations currently performed on the CPU are migrated to the GPU, achieving zero-latency layout switching during code folding and unfolding. Unlike existing full recalculation methods, this embodiment stores layout data on a code structure basis, updating only the local layout when the structure changes.

[0137] S3.1 Division and definition of code structure units.

[0138] S3.1.1 Identification rules for structural units: The code editor's syntax analyzer identifies segments in the code that have independent logic as structural units, including: function units, which begin with a function definition, such as void func(), and end with a function closing bracket; code block units, which begin with a control statement such as if, for, or while and end with a left bracket and end with a right bracket; macro definition units, which begin with #define and end with a newline; and comment block units, which begin with / * and end with * / or / / .

[0139] S3.1.2, Attribute Definition of Structural Units: Define layout attributes for each structural unit and store them in StructLayoutSSBO. The structural unit attributes are defined as follows:

[0140] struct StructUnit {

[0141] uint32_t structID; / / Unique ID (e.g., function ID=1001, code block ID=2001)

[0142] uint32_t parentStructID; / / Parent structure unit ID (e.g., if block inside a function, parent ID=1001)

[0143] uint32_t startCharIdx; / / Starting character index (global index of the first character of the structure unit)

[0144] uint32_t endCharIdx; / / End character index (global index of the last character of the structure unit)

[0145] float baseY; / / Base Y coordinate (top Y coordinate when not collapsed, in pixels)

[0146] float totalHeight; / / Total height (height when not collapsed, pixels)

[0147] float foldedOffsetY; / / Vertical offset after folding (the Y-coordinate offset of the parent cell after the child cell is folded, in pixels)

[0148] float charSpacingScale; / / Character spacing scaling factor (folded sub-unit = 0.8, normal = 1.0)

[0149] bool isFolded; / / Whether the element is collapsed (true = collapsed, false = not collapsed)

[0150] bool isVisible; / / Whether it is visible (true = within the viewport, false = outside the viewport)

[0151] };

[0152] / / GPU-side SSBO definition (GLSL)

[0153] layout(std430, binding = 2) buffer StructLayoutSSBO {

[0154] uint structCount; / / Total number of struct units (approximately 5000 units for 100,000 lines of code)

[0155] StructUnit structUnits[]; / / Array of structural units

[0156] };

[0157] S3.2 Construction of structured layout cache (GPU texture array storage).

[0158] S3.2.1 Parameter configuration of StructLayoutTextureArray: Creates a 2D texture array StructLayoutTextureArray to store the layout state of each structural unit, including collapsed and unfolded states. The parameters are as follows: number of layers (e.g., 5000 layers, each layer corresponding to one structural unit); resolution per layer (e.g., 16×1 represents 16 pixels), storing 16 layout parameters, each pixel in RGBA32F format; the stored content consists of the 16 layout parameters of the structural unit corresponding to the 16 pixels of each layer, such as baseY for pixel 0, totalHeight for pixel 1, foldedOffsetY for pixel 2, charSpacingScale for pixel 3, etc.

[0159] S3.2.2 Initialization of the texture array: The CPU encodes the layout parameters of all structural units into the pixel values ​​of the texture array and uploads them to the GPU via glTexImage3D. The size of the texture array for 100,000 lines of code (5,000 structural units) is 5,000 × 16 × 1 × 16 bytes (RGBA32F), which is 512,000 bytes (approximately 500KB), with an upload latency of less than 0.1ms. When the state of a structural unit changes (such as folding or unfolding), only the pixel values ​​of the corresponding layer are updated. For example, when a function folds a unit, the corresponding texture layer pixel 2 is updated to foldedOffsetY, and pixel 7 is updated to isFolded, with an update latency of less than 0.05ms.

[0160] S3.3 Real-time generation of GPU-side layout.

[0161] Basic configuration for character instantiation rendering. Instantiated rendering is used to process text characters, with each character corresponding to one instance. Vertex data includes: vertex attribute 0, which is the local texture coordinates of the character (0.0 to 1.0, used for sampling the font atlas); instance attribute 1, which is the global index of the character (used to find its structural unit); and instance attribute 2, which is the character's base width and spacing (px).

[0162] In the vertex shader, a binary search algorithm is used to determine the structural unit to which a character belongs, based on its global index. When a structural unit collapses, the vertical offset of the child unit needs to be superimposed with the collapse offsets of all parent units.

[0163] S4, semantic enhancement effects and weighted fusion shader rendering.

[0164] Enhanced effects, such as error wavy lines and folded triangles, are generated programmatically using GPUs and linked to code semantics. Based on weight values, the entire process of basic styles, interactive styles, structural styles, and enhanced effects is integrated. Unlike existing effect rendering that relies on fixed textures, this example achieves dynamic association between effect parameters and semantics.

[0165] S4.1. Procedural generation of semantic enhancement effects.

[0166] Effect types and generation logic: Four types of semantic enhancement effects are generated based on semantic tags and structural attributes. All effects are computed programmatically via the GPU without the need for additional texture resources, as shown in Table 4.

[0167] Table 4 Effect Type Generation Logic Table

[0168] The procedural generation of error wavy lines in the fragment shader. The steps for generating red wavy lines for syntax errors are as follows: wavy line position calculation: the wavy line is located 2px below the character baseline, and its length is the same as the character width; sine curve parameters: amplitude is 2px (from semantic rule texture Z is 2 channels), wavelength is 6px, and phase is 0.

[0169] The procedural generation of folded triangles in the vertex and fragment shaders involves generating three vertices at the beginning of the row of the folded parent node to form an isosceles right triangle. The vertex positions change depending on the folding state: when folded (downward triangle), vertex 1 is (10, y), vertex 2 is (14, y+4), and vertex 3 is (18, y); when folded (rightward triangle), vertex 1 is (10, y), vertex 2 is (14, y-2), and vertex 3 is (14, y+2). The fragment shader then draws the triangle.

[0170] S4.2, The weighted fusion of multi-dimensional styles synthesizes the final color.

[0171] The fusion order and Z-axis hierarchy are arranged in a bottom-up Z-axis hierarchy to ensure correct visual logic: the bottom layer (Z=0) is the structural style, such as the background color of the collapsed parent node; the middle layer 1 (Z=1) is the semantic style, such as the red of the error text; the middle layer 2 (Z=2) is the interaction style, such as the yellow background of the cursor and the blue background of the selection area; the top layer (Z=3) is the enhancement effect, such as the wavy line of the error and the collapsed triangle.

[0172] S4.3, Font Sampling and Visual Optimization.

[0173] Subpixel sampling (LCD text optimization): The font atlas uses a subpixel format (such as Microsoft ClearType) to implement subpixel sampling in the fragment shader.

[0174] Anti-aliasing: Gaussian blur anti-aliasing is applied to the edges of the text and the enhancement effect, with a blur radius of 0.5px, to ensure smooth text and effect edges.

[0175] S5 features viewport-level rendering and adaptive GPU performance optimization.

[0176] By dynamically adjusting rendering precision through viewport importance grading and real-time GPU load monitoring, a stable 60fps rendering can be maintained on both high-performance devices (such as RTX 4090) and low-performance devices (such as AMD 550).

[0177] The viewport importance ranking rules and data basis are based on programmers' coding habits, dividing viewports into 3 importance levels. The proportion of each level and the rendering precision are shown in Table 5:

[0178] Table 5 Viewport Classification Table

[0179] The vertex shader performs GPU-side computation for hierarchical regions, calculating the viewport level to which the current pixel belongs and passing it to the fragment shader for precision adjustment.

[0180] / / Vertex shader: Viewport level calculation

[0181] out uint viewportGrade; / / 0 = core area, 1 = transition area, 2 = edge area

[0182] void main() {

[0183] / / Calculate the normalized coordinates (0.0~1.0) of the pixel within the viewport.

[0184] vec2 viewportNormPos = (gl_Position.xy / gl_Position.w + 1.0) / 2.0;

[0185] / / Determine the vertical level

[0186] bool isVerticalCore = (viewportNormPos.y >= 0.4 &&viewportNormPos.y <= 0.6);

[0187] bool isVerticalTransition = (viewportNormPos.y >= 0.1 &&viewportNormPos.y < 0.4) || (viewportNormPos.y > 0.6 && viewportNormPos.y <=0.9);

[0188] / / Determine the horizontal level

[0189] bool isHorizontalCore = (viewportNormPos.x >= 0.1 &&viewportNormPos.x <= 0.9);

[0190] bool isHorizontalTransition = (viewportNormPos.x >= 0.05 &&viewportNormPos.x < 0.1) || (viewportNormPos.x > 0.9 && viewportNormPos.x <=0.95);

[0191] / / Comprehensive judgment of viewport level (core area = vertical core + horizontal core, transition area = vertical transition or horizontal transition, edge area = others)

[0192] if (isVerticalCore && isHorizontalCore) {

[0193] viewportGrade = 0;

[0194] } else if (isVerticalTransition || isHorizontalTransition) {

[0195] viewportGrade = 1;

[0196] } else {

[0197] viewportGrade = 2;

[0198] }

[0199] }

[0200] Dynamic adjustment of rendering precision (based on viewport level)

[0201] Pixel mapping ratio adjustment: Adjust the texture sampling coordinates in the fragment shader according to the viewport level to achieve different pixel mapping ratios.

[0202] MSAA level and enhancement effects are adjusted by switching the GPU's rendering state and adjusting the MSAA level according to the viewport level:

[0203] Core area: Enable 4x MSAA;

[0204] Transition zone: Enable 2x MSAA;

[0205] Edge region: Disable MSAA, enable FXAA (Fast Approximate Anti-aliasing);

[0206] Enhancement adjustment: Disable anti-aliasing for wavy lines in the transition area, and completely disable enhancement in the edge area.

[0207] Real-time monitoring and feedback of GPU load, load monitoring metrics and implementation:

[0208] Monitor the following load metrics using GPU timers (such as OpenGL's QueryObject):

[0209] Frame time: Total rendering time per frame (target less than 16ms for 60fps).

[0210] Fragment shader execution time: A percentage greater than 50% indicates pixel computation overload;

[0211] Texture bandwidth: A sampling rate less than 80% of the GPU texture bandwidth indicates bandwidth overload.

[0212] Adaptive adjustment strategy: Triggers different adjustment actions based on load metrics, forming a feedback loop.

[0213] The adjustment is smooth, with all precision adjustments using a gradual transition (completed in 3 frames) to avoid visual jumps. For example, when the core area MSAA is reduced from 4x to 2x: Frame 1, 4x MSAA (weight 0.67) + 2x MSAA (weight 0.33); Frame 2, 4x MSAA (weight 0.33) + 2x MSAA (weight 0.67); Frame 3, completely switched to 2x MSAA.

[0214] Compared with the prior art, this embodiment has the following advantages:

[0215] Semantic rendering flexibility: Supports dynamic style generation of 65,536 semantic combinations; styles can be differentiated based on semantic context for the same syntax type, improving semantic expressiveness by 10 times; semantic update latency is reduced from 30ms to 1ms, meeting the needs of real-time syntax analysis; complex interaction compatibility: Multi-dimensional weight fusion resolves style conflicts between multiple cursors and overlapping selections, improving the visual integrity of interactive styles by 90%, reducing interaction response latency from 15ms to 2ms, and maintaining a 60fps frame rate even in multi-cursor editing scenarios with 100,000 lines of code; structural change efficiency: Structured layout caching reduces the latency of code folding and unfolding from 50ms to 0.5ms, reduces the data transfer volume of structure updates by 99% (from 10MB to 10KB), and eliminates visual jumps when switching folded states, improving the user experience; richness of enhancement effects: Semantic enhancement effects improve the visual differentiation of error types by 40%, increase the efficiency of user error recognition by 35%, require no additional texture resources, and reduce GPU memory usage by 80%.

[0216] In summary, the above are merely preferred embodiments of the present invention and are not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.

Claims

1. A method for accelerating dynamic text rendering in a code editor based on GPU context awareness, characterized in that, Specifically, the following steps are included: The semantic type of characters in the code is extracted as a semantic sub-dimension. The character semantic label is obtained by ORing the binary values ​​of all semantic sub-dimensions and cached in the semantic label SSBO. The mapping between the character semantic label and the rendering style constitutes the semantic rule. The CPU encodes the semantic rule into a semantic rule texture, where the X-axis is the semantic label, the Y-axis is the character context attribute, and the Z-axis is the character rendering style. The code segments with independent logic are used as structural units. The layout attributes of the structural units are obtained, and the CPU encodes the layout attributes into structural textures and uploads them to the Structural Layout SSBO. The compute shader reads the semantic tag SSBO, assigns semantic weights, structural weights, and effect weights to the characters, marks the visibility of structural units, assigns interaction weights by GPU atomic operations, determines the transparency of style overlay as the blending coefficient, and constructs a style weight texture with the same size as the text rendering viewport by semantic weights, interaction weights, structural weights, effect weights, and blending coefficients. The vertex shader processes the vertex data of the character in parallel and calculates the final screen position of the character; The fragment shader reads the semantic tag SSBO and the structural layout SSBO to draw semantic enhancement effects. Based on the semantic rule texture, style weight texture and the final screen position, it determines the semantic style, structural style and interaction style of the character. It blends the rendering effects from the bottom layer, middle layer to the top layer to complete the pixel-level rendering of the character. The vertex shader processes the vertex data of the character in parallel to calculate the final screen position of the character as follows: the vertex shader finds the structural unit to which the character belongs in the structure layout SSBO according to the global index of the character. When the structural unit is collapsed, it calculates the collapse offset of the character and the basic position of the character. Based on the basic position, collapse offset and roll offset, it calculates the final position of the character. Then, it converts the final position into clip space coordinates that the GPU can recognize through the projection matrix transformation, which is the final screen position.

2. The method for accelerating dynamic text rendering in a code editor according to claim 1, characterized in that, The semantic rule texture uses RGBA32F floating-point format, nearest neighbor sampling, and disables mipmap.

3. The method for accelerating dynamic text rendering in a code editor according to claim 1, characterized in that, The rendering style includes a base color, transparency, font style, and enhancement effects, including wavy lines and dashed lines.

4. The method for accelerating dynamic text rendering in a code editor according to claim 1, characterized in that, The method of caching to semantic tags (SSBO) is as follows: for code text with a code size greater than a threshold, the CPU uses the OpenGL glBufferData function to upload it to the GPU, and only uploads the semantic tags of the characters that have changed when the code text changes.

5. The method for accelerating dynamic text rendering in a code editor according to claim 1, characterized in that, The structural units include function units, code block units, macro definition units, and comment block units. The layout attributes include structural unit ID, parent structural unit ID, start character index, end character index, base Y coordinate, total height, vertical offset after collapsing, character spacing scaling factor, whether it is collapsed, and whether it is visible.

6. The method for accelerating dynamic text rendering in a code editor according to claim 1, characterized in that, The vertex shader searches for the structural unit to which a character belongs in the Structure Layout SSBO based on the character's global index by using a binary search algorithm.

7. The method for accelerating dynamic text rendering in a code editor according to claim 1, characterized in that, The vertex shader only processes characters located in visible structural units.

8. The method for accelerating dynamic text rendering in a code editor according to claim 1, characterized in that, The importance of the viewport is determined based on the user's visual attention. The viewport is divided into a core area, a transition area, and an edge area. The core area is the central area of ​​the viewport, the transition area is the area adjacent to the core area, and the edge area is the outer area of ​​the transition area. The vertex shader marks the viewport level to which each pixel belongs and passes it to the fragment shader. The fragment shader configures the rendering parameters differently according to the viewport level.

9. The method for accelerating dynamic text rendering in a code editor according to claim 8, characterized in that, By monitoring key GPU load metrics through GPU timers, the GPU reduces the number of MSAA samples in the transition area and reduces the pixel mapping ratio in the edge area when under light overload; reduces the number of MSAA samples in the core area and disables enhancement effects in the transition area when under moderate overload; reduces the pixel mapping ratio in the core area and disables FXAA in the edge area when under heavy overload; and enables enhancement effects in the edge area and increases MSAA in the core area when under low load.

Citation Information

Patent Citations

  • Dynamic high-performance batch text rendering method and system based on WebGL and program product

    CN116186240A

  • Code editor rendering method and device, equipment, medium and program product

    CN118132072A