Processing method and device of API, storage medium and program product

CN121807563BActive Publication Date: 2026-10-09MOORE THREADS TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202512010471.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-12-29
Publication Date
2026-10-09
Estimated Expiration
2045-12-29

AI Technical Summary

Technical Problem

[0003]目前主流的图形驱动程序对API的处理效率过低,且API的生成效率也较低,导致图形渲染帧率低,反馈到使用AP的用户侧的直观感受是运行AP时画面卡顿

Benefits of technology

[0020] According to another aspect of this disclosure, a non-volatile computer-readable storage medium is provided, on which a computer program is stored, which, when executed by a processor, implements the steps of the above-described method.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121807563B_ABST
    Figure CN121807563B_ABST
Patent Text Reader

Abstract

The present disclosure relates to the field of graphics processing, and provides a processing method and device of API, a storage medium and a program product. The method comprises: a main thread of a graphics driver creating a rendering thread and a buffer pool inside the graphics driver, the rendering thread being parallel to the main thread; the main thread receiving and recording an API from an application program, and returning a completion signal corresponding to a current set of APIs to the application program after recording the current set of APIs; the main thread writing at least one set of recorded APIs into the buffer pool; and the rendering thread accessing the buffer pool to obtain the APIs, decoding the obtained APIs into instructions executable by a graphics processor hardware, and outputting the instructions to the graphics processor hardware for execution. The processing method of API can improve the graphics rendering frame rate and reduce the screen freezing phenomenon when the user side runs the API.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of graphics processing, and more particularly to a method, apparatus, storage medium, and program product for processing an API. Background Technology

[0002] A graphics driver acts as a bridge between an application (AP) and the graphics processing unit (GPU) hardware. When an AP runs on the GPU, it invokes the graphics driver. The graphics driver receives the Application Programming Interface (API) from the AP, processes the API to obtain executable instructions for the GPU hardware, and sends these instructions to the GPU hardware for execution to achieve graphics rendering and generate the images required by the AP. Therefore, the efficiency of the graphics driver directly determines the smoothness of the AP's visuals.

[0003] Currently, mainstream graphics drivers have excessively low API processing efficiency and low API generation efficiency, resulting in low graphics rendering frame rates. This manifests as stuttering on the user side of the application processing unit (AP). Such stuttering is unacceptable for some APs (such as gaming APs and industrial APs), necessitating optimization of the API processing methods. Summary of the Invention

[0004] In view of this, this disclosure provides an API processing method, apparatus, storage medium, and program product. The API processing method of this disclosure can improve the graphics rendering frame rate and reduce screen stuttering when the user is running the API.

[0005] According to one aspect of this disclosure, an API processing method is provided, the method comprising: a main thread of a graphics driver creating a rendering thread and a buffer pool within the graphics driver, the rendering thread running in parallel with the main thread; the main thread receiving and recording APIs from an application, and after recording a current set of APIs, returning a completion signal corresponding to the current set of APIs to the application; the main thread writing at least one set of recorded APIs into the buffer pool; the rendering thread accessing the buffer pool to obtain APIs, decoding the retrieved APIs into graphics processor hardware executable instructions, and outputting the instructions to the graphics processor hardware for execution.

[0006] In one possible implementation, the main thread receives and records APIs from the application, including: the main thread records each set of received APIs to the state machine of the graphics driver; the main thread writes at least one set of recorded APIs into the buffer pool, including: determining whether the current set of APIs meets a first preset condition; when the current set of APIs meets the first preset condition, merging all APIs recorded by the state machine into a single set of APIs and writing it into the buffer pool.

[0007] In one possible implementation, the state machine also records at least one rendering attribute, and determining whether the current set of APIs meets the first preset condition includes: if the current set of APIs includes APIs that change any one of the rendering attributes recorded by the state machine after execution, then the current set of APIs meets the first preset condition.

[0008] In one possible implementation, when the current set of APIs satisfies a first preset condition, the method further includes: updating the rendering attributes recorded by the state machine according to the current set of APIs.

[0009] In one possible implementation, the rendering thread includes multiple parallel sub-threads. The rendering thread accesses the buffer pool to obtain APIs, decodes the retrieved APIs into graphics processor hardware executable instructions, and outputs the instructions to the graphics processor hardware for execution. This includes: each sub-thread accessing the buffer pool to obtain at least one set of APIs; each sub-thread decoding the retrieved APIs into graphics processor hardware executable instructions, and outputting the instructions to the graphics processor hardware for execution.

[0010] In one possible implementation, the baseline value for the number of APIs that each sub-thread is allowed to process at one time is the same and equal to a first threshold. The step of determining whether the current group of APIs meets the first preset condition also includes: if the total number of APIs recorded by the state machine is greater than the first threshold, it is determined that the current group of APIs meets the first preset condition.

[0011] In one possible implementation, the baseline value for the number of APIs that each sub-thread is allowed to process at one time is different, with the minimum baseline value being a second threshold. The step of determining whether the current group of APIs meets the first preset condition also includes: if the total number of APIs recorded by the state machine is greater than the second threshold, then the current group of APIs is determined to meet the first preset condition.

[0012] According to another aspect of this disclosure, an API processing apparatus is provided, the apparatus comprising: a creation module for a main thread of a graphics driver to create a rendering thread and a buffer pool within the graphics driver, the rendering thread running in parallel with the main thread; a recording and feedback module for the main thread to receive and record APIs from an application, and after recording a current set of APIs, to return a completion signal corresponding to the current set of APIs to the application; a writing module for the main thread to write at least one set of recorded APIs into the buffer pool; and a decoding and output module for the rendering thread to access the buffer pool to obtain APIs, decode the retrieved APIs into graphics processor hardware executable instructions, and output the instructions to the graphics processor hardware for execution.

[0013] In one possible implementation, the main thread receives and records APIs from the application, including: the main thread records each set of received APIs to the state machine of the graphics driver; the main thread writes at least one set of recorded APIs into the buffer pool, including: determining whether the current set of APIs meets a first preset condition; when the current set of APIs meets the first preset condition, merging all APIs recorded by the state machine into a single set of APIs and writing it into the buffer pool.

[0014] In one possible implementation, the state machine also records at least one rendering attribute, and determining whether the current set of APIs meets the first preset condition includes: if the current set of APIs includes APIs that change any one of the rendering attributes recorded by the state machine after execution, then the current set of APIs meets the first preset condition.

[0015] In one possible implementation, the apparatus further includes an update module, configured to update the rendering attributes recorded by the state machine according to the current set of APIs when the current set of APIs satisfies a first preset condition.

[0016] In one possible implementation, the rendering thread includes multiple parallel sub-threads. The rendering thread accesses the buffer pool to obtain APIs, decodes the retrieved APIs into graphics processor hardware executable instructions, and outputs the instructions to the graphics processor hardware for execution. This includes: each sub-thread accessing the buffer pool to obtain at least one set of APIs; each sub-thread decoding the retrieved APIs into graphics processor hardware executable instructions, and outputting the instructions to the graphics processor hardware for execution.

[0017] In one possible implementation, the baseline value for the number of APIs that each sub-thread is allowed to process at one time is the same and equal to a first threshold. The step of determining whether the current group of APIs meets the first preset condition also includes: if the total number of APIs recorded by the state machine is greater than the first threshold, it is determined that the current group of APIs meets the first preset condition.

[0018] In one possible implementation, the baseline value for the number of APIs that each sub-thread is allowed to process at one time is different, with the minimum baseline value being a second threshold. The step of determining whether the current group of APIs meets the first preset condition also includes: if the total number of APIs recorded by the state machine is greater than the second threshold, then the current group of APIs is determined to meet the first preset condition.

[0019] According to another aspect of this disclosure, an electronic device is provided, including a memory, a processor, and a computer program stored in the memory, wherein the processor executes the computer program to implement the steps of the above-described method.

[0020] According to another aspect of this disclosure, a non-volatile computer-readable storage medium is provided, on which a computer program is stored, which, when executed by a processor, implements the steps of the above-described method.

[0021] According to another aspect of this disclosure, a computer program product is provided, including a computer program or a non-volatile computer-readable storage medium carrying the computer program, wherein the computer program, when executed by a processor, implements the steps of the above-described method.

[0022] According to the API processing method of this disclosure, the main thread of the graphics driver creates a rendering thread and a buffer pool within the graphics driver, and the rendering thread runs in parallel with the main thread. The main thread receives and records APIs from the application, and after recording the current set of APIs, returns a completion signal corresponding to the current set of APIs to the application. The main thread writes at least one set of recorded APIs into the buffer pool. The rendering thread accesses the buffer pool to obtain APIs, decodes the retrieved APIs into instructions executable by the graphics processor hardware, and outputs the instructions to the graphics processor hardware for execution. Since the main thread can record APIs, it does not need to wait for a set of APIs to complete before returning a completion signal corresponding to that set of APIs to the AP. The increased speed of API generation by the main thread is beneficial to improving graphics rendering efficiency. The main thread and the rendering thread are independent of each other and do not affect each other; the main thread and the rendering thread can work in parallel, improving API processing efficiency and thus improving graphics rendering frame rate. In summary, the API processing method of this disclosure can improve API processing efficiency and the efficiency of AP API generation, thereby improving graphics rendering frame rate and reducing screen stuttering when the AP is running on the user side.

[0023] Other features and aspects of this disclosure will become clear from the following detailed description of exemplary embodiments with reference to the accompanying drawings. Attached Figure Description

[0024] The accompanying drawings, which are included in and form part of this specification, illustrate exemplary embodiments, features, and aspects of this disclosure together with the specification and serve to explain the principles of this disclosure.

[0025] Figure 1 Exemplary application scenarios of API processing methods according to embodiments of this disclosure are shown.

[0026] Figure 2 A schematic diagram illustrating the flow of an API processing method according to an embodiment of this disclosure is shown.

[0027] Figure 3 A schematic diagram illustrating the flow of an API processing method according to an embodiment of this disclosure is shown.

[0028] Figure 4 A schematic diagram illustrating the flow of an API processing method according to an embodiment of this disclosure is shown.

[0029] Figure 5 A schematic diagram showing the structure of an API processing apparatus according to an embodiment of the present disclosure is provided.

[0030] Figure 6 A block diagram of an electronic device 1900 according to an embodiment of the present disclosure is shown. Detailed Implementation

[0031] Various exemplary embodiments, features, and aspects of this disclosure will now be described in detail with reference to the accompanying drawings. The same reference numerals in the drawings denote elements that have the same or similar functions. Although various aspects of the embodiments are shown in the drawings, they are not necessarily drawn to scale unless specifically indicated otherwise.

[0032] As used herein, the terms “comprising,” “including,” “having,” or variations thereof are open-ended and include one or more of the stated features, integrals, elements, steps, components, or functions, but do not exclude the presence or addition of one or more other features, integrals, elements, steps, components, functions, or groups thereof.

[0033] When an element is referred to as “connected,” “coupled,” “responding,” or a variation thereof relative to another element, it may be directly connected, coupled, or responding to another element, or there may be an intermediate element present.

[0034] Although the terms first, second, third, etc., may be used herein to describe various elements / operations, these elements / operations should not be limited by these terms. These terms are only used to distinguish one element / operation from another. Therefore, without departing from the teachings of the inventive concept, a first element / operation in some embodiments may be referred to as a second element / operation in other embodiments.

[0035] The term “exemplary” as used herein means “serving as an example, embodiment, or illustration.” Any embodiment illustrated herein as “exemplary” is not necessarily to be construed as superior to or better than other embodiments.

[0036] Furthermore, to better illustrate this disclosure, numerous specific details are set forth in the following detailed description. Those skilled in the art will understand that this disclosure can be practiced without certain specific details. In some instances, methods, means, components, and circuits well known to those skilled in the art have not been described in detail in order to highlight the main points of this disclosure.

[0037] It should be noted that the information (including but not limited to user device information, user personal information, etc.), data (including but not limited to data used for analysis, data stored, data displayed, etc.) and signals involved in this application are all authorized by the user or fully authorized by all parties, and the collection, use and processing of related data must comply with the relevant laws, regulations and standards of the relevant regions.

[0038] The mainstream API processing method provided by current graphics drivers is as follows: APIs issued by the application processing unit (AP) are processed serially within a single thread. Specifically, when processing each set of APIs, the API is decoded to obtain instructions executable by the GPU hardware. These instructions are then sent to the GPU hardware for execution. Once the decoded instructions for that set of APIs have been executed, the execution of that set of APIs is complete, and a completion signal corresponding to that set of APIs is returned to the AP. Upon receiving the completion signal, the AP begins generating new APIs. Finally, after the entire frame is rendered, the image is displayed on the user's terminal screen.

[0039] The drawback of this method is that the efficiency of processing the API with a single thread is too low, resulting in a low frame rate for graphics rendering and causing stuttering on the user-side application screen. This stuttering is even more pronounced in scenarios with heavy API load.

[0040] In view of this, this disclosure provides an API processing method, apparatus, storage medium, and program product. The API processing method of this disclosure can improve the graphics rendering frame rate and reduce screen stuttering when the user is running the API.

[0041] Figure 1Exemplary application scenarios of API processing methods according to embodiments of this disclosure are shown.

[0042] like Figure 1 As shown, the API processing method of this disclosure embodiment can be executed by the CPU on the first device to optimize the graphics driver running on the CPU.

[0043] The first device can be a terminal device or a server, and the specific type of the first device is not limited in the embodiments disclosed herein.

[0044] Assume the first device is a user terminal, and the first device also includes a GPU. The user runs an application program (AP) on the GPU of the first device, and the AP generates an API and outputs the API to the graphics driver.

[0045] The graphics driver receives the API from the AP, processes the API using the API processing method of this embodiment, obtains GPU hardware executable instructions, and sends the instructions to the GPU for execution via the CPU hardware to achieve graphics rendering and generate the screen required by the AP.

[0046] The first device will display the generated image on its own screen to the user.

[0047] Figure 2 A schematic diagram illustrating the flow of an API processing method according to an embodiment of this disclosure is shown.

[0048] In one possible implementation, such as Figure 1 As shown, the method includes steps S21-S24:

[0049] In step S21, the main thread of the graphics driver creates a rendering thread and a buffer pool inside the graphics driver, and the rendering thread runs in parallel with the main thread.

[0050] In step S22, the main thread receives and records the APIs from the application, and after recording the current set of APIs, returns a completion signal corresponding to the current set of APIs to the application.

[0051] In step S23, the main thread writes at least one set of APIs recorded into the buffer pool.

[0052] Step S24: The rendering thread accesses the buffer pool to obtain the API, decodes the retrieved API into instructions executable by the graphics processor hardware, and outputs the instructions to the graphics processor hardware for execution.

[0053] For example, after the graphics driver is invoked by the API, it begins initialization, which generates a main thread. In step S21, the main thread can create a rendering thread and a buffer pool within the graphics driver, where the rendering thread and the main thread can run in parallel. The rendering thread is responsible for decoding the API, and the buffer pool is responsible for caching the API.

[0054] The data structure of the buffer pool can be configured, such as PacketHeader, OpCode, etc., as long as the buffer pool can store APIs. This embodiment of the disclosure does not limit the specific data structure of the buffer pool.

[0055] Suppose the application program (AP) requires drawing a screen containing multiple points. To achieve this, the AP needs to generate N sets of APIs (N is a positive integer). In one example, a set of APIs might include the glBegin(GL_POINTS) … glEnd() API. The AP sends a set of APIs to the graphics driver at a time.

[0056] In step S22, the main thread receives and records the APIs from the AP. After recording a set of APIs, the main thread can return a completion signal corresponding to that set of APIs to the AP. After receiving the completion signal corresponding to that set of APIs, the AP starts generating the next set of APIs and continues to issue APIs.

[0057] Because the main thread can record APIs, it doesn't need to wait for a set of APIs to complete before returning a completion signal for that set to the application processor (AP). This increased speed of API generation by the main thread improves graphics rendering efficiency.

[0058] In step S23, the main thread can write at least one set of recorded APIs into the buffer pool. In step S24, the rendering thread can access the buffer pool to obtain APIs, decode the retrieved APIs into GPU hardware executable instructions, and output the instructions to the GPU hardware for execution. Each time the rendering thread accesses the buffer pool, it can obtain APIs in groups or in any number of groups. This embodiment of the disclosure does not limit the specific method by which the rendering thread accesses the buffer pool to obtain APIs.

[0059] The rendering thread can repeat step S24 until all APIs have been executed. After executing the instructions, the GPU hardware can draw the image required by the AP. The main thread and the rendering thread are independent of each other and do not affect each other. The main thread and the rendering thread can work in parallel, which improves the processing efficiency of the API and helps to improve the graphics rendering frame rate.

[0060] According to the API processing method of this disclosure, the main thread of the graphics driver creates a rendering thread and a buffer pool within the graphics driver, and the rendering thread runs in parallel with the main thread. The main thread receives and records APIs from the application, and after recording the current set of APIs, returns a completion signal corresponding to the current set of APIs to the application. The main thread writes at least one set of recorded APIs into the buffer pool. The rendering thread accesses the buffer pool to obtain APIs, decodes the retrieved APIs into instructions executable by the graphics processor hardware, and outputs the instructions to the graphics processor hardware for execution. Since the main thread can record APIs, it does not need to wait for a set of APIs to complete before returning a completion signal corresponding to that set of APIs to the AP. The increased speed of API generation by the main thread is beneficial to improving graphics rendering efficiency. The main thread and the rendering thread are independent of each other and do not affect each other; the main thread and the rendering thread can work in parallel, improving API processing efficiency and thus improving graphics rendering frame rate. In summary, the API processing method of this disclosure can improve API processing efficiency and the efficiency of AP API generation, thereby improving graphics rendering frame rate and reducing screen stuttering when the AP is running on the user side.

[0061] Figure 3 A schematic diagram illustrating the flow of an API processing method according to an embodiment of this disclosure is shown.

[0062] like Figure 3 As shown, in one possible implementation, in step S22, the main thread receiving and recording APIs from the application includes: the main thread recording each set of APIs received to the state machine of the graphics driver.

[0063] Step S23 includes: determining whether the current group of APIs meets the first preset condition; when the current group of APIs meets the first preset condition, merging all APIs recorded by the state machine into a group of APIs and writing them into the buffer pool.

[0064] For example, a graphics driver includes a state machine, which is a state transition model used to manage the operations and resources of graphics hardware (such as a GPU). By defining different states and the rules for transitions between states, it ensures that the graphics driver can run efficiently and stably when handling various graphics tasks.

[0065] In this embodiment of the disclosure, the state machine is also used to record APIs. The main thread can record each set of received APIs to the state machine of the graphics driver.

[0066] exist Figure 3In the example, for each set of APIs recorded, the main thread can determine whether that set of APIs meets a first preset condition. When the current set of APIs meets the first preset condition, all APIs recorded by the state machine (including at least one set of APIs issued by the AP) are merged into one set of APIs and written to the buffer pool. By merging multiple sets of APIs into one, the multiple accesses to the buffer pool that would otherwise require the main thread can be reduced to one. This reduces the load on the graphics driver, further improves the API processing efficiency of the graphics driver, and enhances the performance of the graphics driver.

[0067] In another example, after recording a set of APIs, the main thread may not need to determine whether the current set of APIs meets the first preset condition, nor merge the APIs, and may directly write the set of APIs into the buffer pool. This disclosure does not restrict whether the APIs recorded by the state machine must be merged.

[0068] In one possible implementation, the state machine also records at least one rendering attribute and determines whether the current set of APIs meets the first preset condition, including: if the current set of APIs includes APIs that change any one of the rendering attributes recorded by the state machine after execution, it is determined that the current set of APIs meets the first preset condition.

[0069] For example, the state machine can also record at least one rendering attribute. The rendering attribute is information related to graphics rendering, and may include numerical attributes such as line width, and capability attributes such as the activation state (on / off) of transparency testing and the activation state (on / off) of depth testing. This disclosure does not limit which specific rendering attributes the state machine records.

[0070] Some APIs change rendering properties after execution. Therefore, determining whether the current set of APIs meets the first preset condition can include: if the current set of APIs includes APIs that change any rendering property recorded in the state machine after execution, then the current set of APIs is determined to meet the first preset condition.

[0071] For example, an application (AP) can adjust the linewidth value for graphics rendering by calling the `glLineWidth` API. The floating-point value set in `glLineWidth` is the adjusted linewidth value. Since the state machine records the linewidth value, the main thread can determine whether the API execution changes the rendering attributes recorded in the state machine based on the value set in `glLineWidth` and the linewidth value currently recorded in the state machine. For instance, if the current set of APIs includes `glLineWidth` and its value is 2.0, and the current linewidth value recorded in the state machine is 1.0, then `glLineWidth` is the API that changes the rendering attributes recorded in the state machine after execution, and the current set of APIs meets the first preset condition.

[0072] For example, an app can also control whether a certain capability attribute is enabled or disabled by calling the glEnable(cap) / glDisable(cap) API. For instance, when the cap value is GL_ALPHA_TEST, glEnable(GL_ALPHA_TEST) enables the transparency test for graphics rendering, and glDisable(GL_ALPHA_TEST) disables it. When the cap value is GL_DEPTH_TEST, glEnable(GL_DEPTH_TEST) enables the depth test for graphics rendering, and glDisable(GL_DEPTH_TEST) disables it. Since the state machine records these capability attributes, the main thread can determine whether the API execution changes the rendering attributes recorded by the state machine based on the API type of glEnable(cap) / glDisable(cap), the cap value, and the same capability attribute currently recorded by the state machine. For example, if the current set of APIs includes glDisable(GL_ALPHA_TEST), and the state machine currently records that the transparency test is enabled, then glDisable(GL_ALPHA_TEST) is the API that changes the rendering attributes recorded by the state machine after execution, and the current set of APIs meets the first preset condition.

[0073] Those skilled in the art will understand that there are more ways to determine whether the current set of APIs meets the first preset condition than the examples above. For instance, if a rendering attribute remains unchanged for a long time, the state machine may record a large number of APIs, but the buffer pool may be empty, causing the rendering thread to be idle due to the lack of APIs from the buffer pool. Therefore, determining whether the current set of APIs meets the first preset condition could include: if the current set of APIs includes APIs that change any rendering attribute recorded in the state machine after execution, or if the total number of APIs recorded in the state machine after recording the current set of APIs reaches a preset threshold, then the current set of APIs meets the first preset condition. This approach avoids a decrease in API processing efficiency caused by rendering threads being idle.

[0074] In one possible implementation, when the current set of APIs satisfies a first preset condition, the method further includes:

[0075] Update the rendering properties of the state machine record based on the current set of APIs.

[0076] For example, when a set of APIs meets the first preset condition, the rendering properties recorded by the state machine can be updated in real time to ensure that the driver can run efficiently and stably when handling various graphics tasks. The updated rendering properties are the rendering properties after the API execution.

[0077] Figure 4 A schematic diagram illustrating the flow of an API processing method according to an embodiment of this disclosure is shown.

[0078] like Figure 4 As shown, in one possible implementation, the rendering thread comprises multiple parallel sub-threads, and step S24 includes:

[0079] Step S241: Each child thread accesses the buffer pool to obtain at least one set of APIs;

[0080] In step S242, each sub-thread decodes the retrieved API into instructions executable by the graphics processor hardware and outputs the instructions to the graphics processor hardware for execution.

[0081] For example, a rendering thread can include multiple sub-threads, which can run in parallel.

[0082] Each child thread can access the buffer pool to retrieve at least one set of APIs. The number of API sets retrieved can be determined based on the quantity of each API set and the processing capacity of the child thread. In one example, each child thread can retrieve only one set of APIs at a time when accessing the buffer pool, minimizing idle child threads and maximizing child thread utilization. In another example, each child thread can retrieve as many APIs as possible at once based on its processing capacity to reduce the number of times the child thread accesses the buffer pool and reduce the complexity of child thread access to the buffer pool.

[0083] Each sub-thread can decode the retrieved API into instructions executable by the graphics processor hardware and output the instructions to the graphics processor hardware for execution.

[0084] By using multiple sub-threads to retrieve and decode the API in parallel, API processing efficiency is further improved.

[0085] In one possible implementation, the baseline value for the number of APIs that each sub-thread is allowed to process at one time is the same and equal to the first threshold. Determining whether the current group of APIs meets the first preset condition also includes: if the total number of APIs recorded by the state machine is greater than the first threshold, determining that the current group of APIs meets the first preset condition.

[0086] For example, a baseline value can be preset for the number of APIs that each sub-thread is allowed to process at one time. Assuming that each sub-thread has the same processing capacity, the baseline value for the number of APIs that each sub-thread is allowed to process at one time can be the same. The baseline value can be set according to the application scenario requirements. For example, if it is desired to reduce the number of times the buffer pool is accessed, the baseline value can be set to a larger value. If it is desired to speed up API processing efficiency, the baseline value can be set to a smaller value. This disclosure embodiment does not limit the specific value of the baseline value.

[0087] Assuming a baseline value of the number of APIs each child thread is allowed to process at one time is a first threshold, determining whether the current group of APIs meets the first preset condition can include: if the total number of APIs recorded by the state machine is greater than the first threshold, then the current group of APIs is determined to meet the first preset condition. In this case, it can avoid the state machine accumulating too many APIs, reduce the number of idle child threads, and effectively utilize multiple child threads.

[0088] In one possible implementation, the baseline value for the number of APIs that each sub-thread is allowed to process at one time is different, with the minimum baseline value being a second threshold. Determining whether the current group of APIs meets the first preset condition also includes: if the total number of APIs recorded by the state machine is greater than the second threshold, then the current group of APIs meets the first preset condition.

[0089] For example, a baseline value can be preset for the number of APIs that each sub-thread is allowed to process at one time. Assuming that each sub-thread has different processing capabilities, the baseline value for the number of APIs that each sub-thread is allowed to process at one time can be different, and the specific baseline value set for each sub-thread can be matched to its own processing capability. The baseline value can be set according to the application scenario requirements. For example, if it is desired to reduce the number of times the buffer pool is accessed, the baseline value can be set to a larger value. If it is desired to speed up API processing efficiency, the baseline value can be set to a smaller value. This disclosure does not limit the specific value of the baseline value.

[0090] Assuming the minimum baseline value preset for each sub-thread is the second threshold, determining whether the current set of APIs meets the first preset condition also includes: if the total number of APIs recorded by the state machine is greater than the second threshold, then the current set of APIs is determined to meet the first preset condition. In this case, it can avoid the state machine accumulating too many APIs, reduce the number of idle sub-threads, and effectively utilize multiple sub-threads. Furthermore, since the second threshold is the minimum baseline value preset for each sub-thread, for sub-threads with smaller baseline values, the computational power requirement of any set of APIs obtained from the buffer pool will not exceed their own processing capacity; for sub-threads with larger baseline values, multiple sets of APIs can be obtained at once to fully utilize the sub-thread's processing capacity, improving the flexibility of sub-threads in processing APIs.

[0091] The API processing method proposed in this disclosure transforms the original single-threaded graphics driver into a multi-threaded one, fully utilizing the parallel capabilities of modern multi-core CPUs. Furthermore, it merges some APIs when writing them to the buffer pool, reducing the load on the graphics driver and GPU hardware. These measures can significantly improve the performance of the application running on the GPU, especially the frame rate in API-intensive scenarios. Actual testing shows that, for some applications, the API processing method proposed in this disclosure can increase the frame rate by 20% to 300%.

[0092] This disclosure also proposes an API processing apparatus. Figure 5 A schematic diagram showing the structure of an API processing apparatus according to an embodiment of the present disclosure is provided.

[0093] like Figure 5 As shown, in one possible implementation, the device includes:

[0094] Module 51 is created for the main thread of the graphics driver to create a rendering thread and a buffer pool within the graphics driver, wherein the rendering thread runs in parallel with the main thread.

[0095] The recording and feedback module 52 is used for the main thread to receive and record APIs from the application, and after recording the current set of APIs, to return a completion signal corresponding to the current set of APIs to the application;

[0096] The writing module 53 is used by the main thread to write at least one set of APIs recorded into the buffer pool;

[0097] The decoding and output module 54 is used for the rendering thread to access the buffer pool to obtain API, decode the retrieved API into instructions executable by the graphics processor hardware, and output the instructions to the graphics processor hardware for execution.

[0098] In one possible implementation, the main thread receives and records APIs from the application, including: the main thread records each set of received APIs to the state machine of the graphics driver; the main thread writes at least one set of recorded APIs into the buffer pool, including: determining whether the current set of APIs meets a first preset condition; when the current set of APIs meets the first preset condition, merging all APIs recorded by the state machine into a single set of APIs and writing it into the buffer pool.

[0099] In one possible implementation, the state machine also records at least one rendering attribute, and determining whether the current set of APIs meets the first preset condition includes: if the current set of APIs includes APIs that change any one of the rendering attributes recorded by the state machine after execution, then the current set of APIs meets the first preset condition.

[0100] In one possible implementation, the apparatus further includes an update module, configured to update the rendering attributes recorded by the state machine according to the current set of APIs when the current set of APIs satisfies a first preset condition.

[0101] In one possible implementation, the rendering thread includes multiple parallel sub-threads. The rendering thread accesses the buffer pool to obtain APIs, decodes the retrieved APIs into graphics processor hardware executable instructions, and outputs the instructions to the graphics processor hardware for execution. This includes: each sub-thread accessing the buffer pool to obtain at least one set of APIs; each sub-thread decoding the retrieved APIs into graphics processor hardware executable instructions, and outputting the instructions to the graphics processor hardware for execution.

[0102] In one possible implementation, the baseline value for the number of APIs that each sub-thread is allowed to process at one time is the same and equal to a first threshold. The step of determining whether the current group of APIs meets the first preset condition also includes: if the total number of APIs recorded by the state machine is greater than the first threshold, it is determined that the current group of APIs meets the first preset condition.

[0103] In one possible implementation, the baseline value for the number of APIs that each sub-thread is allowed to process at one time is different, with the minimum baseline value being a second threshold. The step of determining whether the current group of APIs meets the first preset condition also includes: if the total number of APIs recorded by the state machine is greater than the second threshold, then the current group of APIs is determined to meet the first preset condition.

[0104] In some embodiments, the functions or modules of the apparatus provided in this disclosure can be used to perform the methods described in the above method embodiments. The specific implementation can be referred to the description of the above method embodiments, and for the sake of brevity, it will not be repeated here.

[0105] This disclosure also provides an electronic device, including a memory, a processor, and a computer program stored in the memory, wherein the processor executes the computer program to implement the steps of the above method.

[0106] This disclosure also provides a non-volatile computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the steps of the above-described method.

[0107] This disclosure also provides a computer program product, including a computer program or a non-volatile computer-readable storage medium carrying the computer program, wherein the computer program, when executed by a processor, implements the steps of the above method.

[0108] Figure 6 A block diagram of an electronic device 1900 according to an embodiment of the present disclosure is shown. For example, the electronic device 1900 may be provided as a server or a terminal device. (Refer to...) Figure 6 The electronic device 1900 includes a processing component 1922, which further includes one or more processors, and a memory resource represented by a memory 1932 for storing instructions, such as application programs, that can be executed by the processing component 1922. The application programs stored in the memory 1932 may include one or more modules, each corresponding to a set of instructions. Furthermore, the processing component 1922 is configured to execute instructions to perform the methods described above.

[0109] Electronic device 1900 may also include a power supply component 1926 configured to perform power management of electronic device 1900, a wired or wireless network interface 1950 configured to connect electronic device 1900 to a network, and an input / output interface 1958 (I / O interface). Electronic device 1900 can operate on an operating system, such as Windows Server, stored in memory 1932. TM Mac OS X TM Unix TMLinux TM FreeBSD TM Or similar.

[0110] In an exemplary embodiment, a non-volatile computer-readable storage medium is also provided, such as a memory 1932 including computer program instructions that can be executed by a processing component 1922 of an electronic device 1900 to perform the above-described method.

[0111] Computer-readable storage media can be tangible devices capable of holding and storing programs / instructions used by instruction execution devices. Computer-readable storage media can be, for example—but not limited to—electrical storage devices, magnetic storage devices, optical storage devices, electromagnetic storage devices, semiconductor storage devices, or any suitable combination of the foregoing. More specific examples (a non-exhaustive list) of computer-readable storage media include: portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), static random access memory (SRAM), portable compact disc read-only memory (CD-ROM), digital multifunction disc (DVD), memory sticks, floppy disks, mechanical encoding devices, such as punch cards or recessed protrusions storing instructions thereon, and any suitable combination of the foregoing. The computer-readable storage media used herein are not to be construed as transient signals themselves, such as radio waves or other freely propagating electromagnetic waves, electromagnetic waves propagating through waveguides or other transmission media (e.g., light pulses through fiber optic cables), or electrical signals transmitted through wires.

[0112] The computer program (or computer-readable program instructions) described herein can be downloaded from a computer-readable storage medium to various computing / processing devices, or downloaded via a network, such as the Internet, local area network, wide area network, and / or wireless network, to an external computer or external storage device. The network may include copper transmission cables, fiber optic transmission, wireless transmission, routers, firewalls, switches, gateway computers, and / or edge servers. A network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards them to the computer-readable storage medium in the respective computing / processing device.

[0113] The computer program (or computer program instructions) used to perform the operations of this disclosure may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-dependent instructions, microcode, firmware instructions, state setting data, or source code or object code written in any combination of one or more programming languages, including object-oriented programming languages ​​such as Smalltalk, C++, etc., and conventional procedural programming languages ​​such as the "C" language or similar programming languages. The computer-readable program instructions may execute entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or may be connected to an external computer (e.g., via the Internet using an Internet service provider). In some embodiments, electronic circuitry, such as programmable logic circuitry, field-programmable gate arrays (FPGAs), or programmable logic arrays (PLAs), is personalized by utilizing state information from the computer-readable program instructions to implement various aspects of this disclosure.

[0114] Various aspects of this disclosure are described herein with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this disclosure. It should be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer-readable program instructions.

[0115] These computer-readable program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing apparatus to produce a machine such that, when executed by the processor of the computer or other programmable data processing apparatus, they create means for implementing the functions / actions specified in one or more blocks of the flowchart and / or block diagram. These computer-readable program instructions can also be stored in a computer-readable storage medium that causes a computer, programmable data processing apparatus, and / or other device to operate in a particular manner; thus, the computer-readable medium storing the instructions comprises an article of manufacture that includes instructions for implementing aspects of the functions / actions specified in one or more blocks of the flowchart and / or block diagram.

[0116] Computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device to cause a series of operational steps to be performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, thereby causing the instructions executed on the computer, other programmable data processing apparatus, or other device to perform the functions / actions specified in one or more boxes of a flowchart and / or block diagram.

[0117] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present disclosure. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of an instruction containing one or more executable instructions for implementing a specified logical function. In some alternative implementations, the functions marked in the blocks may occur in a different order than those shown in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, may be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.

[0118] The various embodiments of this disclosure have been described above. These descriptions are exemplary and not exhaustive, nor are they limited to the disclosed embodiments. Many modifications and variations will be apparent to those skilled in the art without departing from the scope and spirit of the described embodiments. The terminology used herein is chosen to best explain the principles, practical application, or technical improvements to the embodiments in the market, or to enable others skilled in the art to understand the embodiments disclosed herein.

Claims

1. A method for processing an API, characterized in that, The method includes: The main thread of the graphics driver creates a rendering thread and a buffer pool within the graphics driver, and the rendering thread runs in parallel with the main thread. The main thread receives and records APIs from the application, and after recording the current set of APIs and before the rendering thread finishes executing the set of APIs, returns a completion signal corresponding to the current set of APIs to the application. The main thread writes at least one set of APIs recorded into the buffer pool; The rendering thread accesses the buffer pool to obtain the API, decodes the retrieved API into instructions executable by the graphics processor hardware, and outputs the instructions to the graphics processor hardware for execution.

2. The method according to claim 1, characterized in that, The main thread receives and records APIs from the application, including: the main thread records each set of received APIs into the state machine of the graphics driver. The main thread writes at least one set of APIs recorded into the buffer pool, including: determining whether the current set of APIs meets a first preset condition; when the current set of APIs meets the first preset condition, merging all APIs recorded by the state machine into one set of APIs and writing it into the buffer pool.

3. The method according to claim 2, characterized in that, The state machine also records at least one rendering attribute. Determining whether the current set of APIs meets the first preset condition includes: if the current set of APIs includes APIs that change any one of the rendering attributes recorded by the state machine after execution, then the current set of APIs meets the first preset condition.

4. The method according to claim 2, characterized in that, When the current set of APIs meets the first preset condition, the method further includes: Update the rendering properties of the state machine record according to the current set of APIs.

5. The method according to claim 2, characterized in that, The rendering thread comprises multiple sub-threads running in parallel. The rendering thread accesses the buffer pool to obtain an API, decodes the retrieved API into instructions executable by the graphics processor hardware, and outputs the instructions to the graphics processor hardware for execution, including: Each child thread accesses the buffer pool to obtain at least one set of APIs; Each sub-thread decodes the retrieved API into instructions executable by the graphics processor hardware, and outputs the instructions to the graphics processor hardware for execution.

6. The method according to claim 5, characterized in that, The baseline value for the number of APIs that each sub-thread is allowed to process at one time is the same and equal to the first threshold. The step of determining whether the current group of APIs meets the first preset condition also includes: if the total number of APIs recorded by the state machine is greater than the first threshold, it is determined that the current group of APIs meets the first preset condition.

7. The method according to claim 5, characterized in that, The baseline value for the number of APIs that each child thread is allowed to process at one time is different, with the minimum baseline value being the second threshold. The step of determining whether the current group of APIs meets the first preset condition further includes: if the total number of APIs recorded by the state machine is greater than the second threshold, then the current group of APIs meets the first preset condition.

8. An API processing apparatus, characterized in that, The device includes: A creation module is used by the main thread of the graphics driver to create a rendering thread and a buffer pool within the graphics driver, wherein the rendering thread runs in parallel with the main thread. The recording and feedback module is used for the main thread to receive and record APIs from the application, and after recording the current set of APIs and before the rendering thread finishes executing the set of APIs, to return a completion signal corresponding to the current set of APIs to the application. A writing module is used by the main thread to write at least one set of APIs recorded into the buffer pool; The decoding and output module is used for the rendering thread to access the buffer pool to obtain APIs, decode the retrieved APIs into instructions executable by the graphics processor hardware, and output the instructions to the graphics processor hardware for execution.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory, characterized in that, The processor executes the computer program to implement the steps of the method according to any one of claims 1 to 7.

10. A non-volatile computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 7.

11. A computer program product, comprising a computer program, or a non-volatile computer-readable storage medium carrying a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • CAD asynchronous rendering method and system based on double buffering

    CN112906087A

  • Rendering instruction transmission method, operating system, electronic equipment and storage medium

    CN117710183A