Image rendering method and device, equipment, medium and product
By employing a multi-threaded approach to concurrently execute drawing and resource processing subtasks in image rendering, the problem of long rendering times in large-scale game programs is solved, thereby improving rendering efficiency.
Patent Information
- Application Number
- CN202410591547.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-13
- Publication Date
- 2025-11-14
AI Technical Summary
In large-scale game programs, image rendering takes a long time, resulting in low rendering efficiency and affecting the overall effect of the program.
The rendering task is executed concurrently using multiple threads. The first rendering thread handles the drawing subtask, and the second rendering thread handles the resource processing subtask. The corresponding instructions are obtained and executed respectively to reduce the rendering time.
By executing rendering tasks concurrently using multiple threads, rendering time is reduced, performance bottlenecks are avoided, and rendering efficiency and overall program performance are improved.
Smart Images

Figure CN120950191A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to an image rendering method, apparatus, device, medium and product. Background Technology
[0002] With the development of internet technology, rendering has become a common requirement in image processing. Rendering generally refers to the process of using software to generate images from models in order to present realistic image effects.
[0003] Currently, the image rendering process has shortcomings. For example, when dealing with some large-scale game programs, the large amount of data that needs to be rendered can lead to high rendering time, resulting in low rendering efficiency and affecting the overall effect of the program. Summary of the Invention
[0004] This application provides an image rendering method, apparatus, device, medium, and product to reduce rendering time and improve rendering efficiency.
[0005] The embodiments of this application disclose the following technical solutions:
[0006] In a first aspect, embodiments of this application provide an image rendering method, including:
[0007] Start the first rendering thread and the second rendering thread. The first rendering thread is used to execute the drawing sub-task in the rendering task to be executed, and the second rendering thread is used to execute the resource processing sub-task in the rendering task.
[0008] The first instruction corresponding to the drawing subtask is obtained through the first rendering thread, and the second instruction corresponding to the resource processing subtask is obtained through the second rendering thread.
[0009] The first instruction is executed through the first rendering thread, and the second instruction is executed through the second rendering thread.
[0010] Secondly, embodiments of this application provide an image rendering apparatus, comprising:
[0011] The startup module is used to start the first rendering thread and the second rendering thread. The first rendering thread is used to execute the drawing sub-task in the rendering task to be executed, and the second rendering thread is used to execute the resource processing sub-task in the rendering task.
[0012] The acquisition module is used to acquire a first instruction corresponding to the drawing subtask through the first rendering thread, and to acquire a second instruction corresponding to the resource processing subtask through the second rendering thread.
[0013] The first execution module is configured to execute the first instruction through the first rendering thread and execute the second instruction through the second rendering thread.
[0014] Thirdly, embodiments of this application provide an image rendering device, the device including a processor and a memory:
[0015] The memory is used to store computer programs and to transfer the computer programs to the processor;
[0016] The processor is configured to execute the steps of the image rendering method provided in the first aspect according to the instructions in the computer program.
[0017] Fourthly, embodiments of this application provide a computer-readable storage medium for storing program code for performing the steps of the image rendering method provided in the first aspect above.
[0018] Fifthly, embodiments of this application provide a computer program product, including a computer program or instructions, which, when executed by a processor, implement the steps of the image rendering method provided in the first aspect.
[0019] As can be seen from the above technical solutions, the embodiments of this application have the following advantages:
[0020] In this embodiment, a first rendering thread for executing the drawing sub-tasks within the rendering task to be executed, and a second rendering thread for executing the resource processing sub-tasks within the rendering task, can be started first. Then, a first instruction corresponding to the drawing sub-task and a second instruction corresponding to the resource processing sub-task can be obtained. The first instruction is executed by the first rendering thread, and the second instruction is executed by the second rendering thread. In this way, the drawing sub-tasks within the rendering task can be shared by the first rendering thread (i.e., the first instruction is executed by the first rendering thread), and the resource processing sub-tasks within the rendering task can be shared by the second rendering thread (i.e., the second instruction is executed by the second rendering thread). This multi-threaded concurrent execution of the rendering task reduces rendering time and avoids the performance bottleneck caused by using a single thread to execute the rendering task, thereby optimizing rendering performance and improving rendering efficiency. Attached Figure Description
[0021] Figure 1 A flowchart illustrating an image rendering method provided in an embodiment of this application;
[0022] Figure 2 A schematic diagram of a multi-threaded architecture for an image rendering method provided in an embodiment of this application;
[0023] Figure 3aA schematic diagram illustrating the execution time of a first rendering thread as provided in an embodiment of this application;
[0024] Figure 3b A schematic diagram illustrating the execution time of a second rendering thread as provided in an embodiment of this application;
[0025] Figure 4 This is a schematic diagram of the structure of an image rendering apparatus provided in an embodiment of this application;
[0026] Figure 5 This application provides a schematic diagram of the structure of a server according to an embodiment of the present application.
[0027] Figure 6 This is a schematic diagram of the structure of a terminal device provided in an embodiment of this application. Detailed Implementation
[0028] As mentioned earlier, the image rendering process has inherent limitations. Taking game programs as an example, in single-threaded mode, a single thread is needed to execute both game logic and rendering tasks. In multi-threaded mode, the main thread executes the game logic tasks, while a separate rendering thread handles the rendering tasks. Single-threaded mode can handle simple casual game scenarios but cannot meet the rendering requirements of large-scale game programs. Therefore, multi-threaded mode is typically used for image rendering in large-scale game programs. However, when only one rendering thread performs the rendering tasks, the large amount of data to be rendered can lead to high rendering time, heavy load on the rendering thread, and a performance bottleneck, resulting in low rendering efficiency and affecting the overall quality of the program.
[0029] To address the aforementioned issues, this application provides an image rendering method that may include: firstly, starting a first rendering thread for executing a drawing subtask within a rendering task to be executed, and a second rendering thread for executing a resource processing subtask within the rendering task; then, obtaining a first instruction corresponding to the drawing subtask and a second instruction corresponding to the resource processing subtask; executing the first instruction through the first rendering thread and the second instruction through the second rendering thread. In this way, the first rendering thread can share the drawing subtask within the rendering task (i.e., execute the first instruction), and the second rendering thread can share the resource processing subtask within the rendering task (i.e., execute the second instruction). This multi-threaded concurrent execution of the rendering task reduces rendering time, avoids the performance bottleneck caused by using a single thread to execute the rendering task, thereby optimizing rendering performance and improving rendering efficiency.
[0030] It should be noted that the embodiments of this application do not limit the executing entity of the technical solution of this application. For example, the image rendering method provided in the embodiments of this application can be applied to a user terminal or a server, or it can be processed collaboratively by a user terminal and a server. As an example, the user terminal includes, but is not limited to, mobile phones, computers, smart voice interaction devices, smart home appliances, vehicle terminals, aircraft, etc. The server can be a standalone server, a cluster server, or a cloud server.
[0031] For ease of understanding, the terminology that may be involved in the embodiments of this application will be introduced below.
[0032] A thread is the smallest unit of computation that an operating system can schedule. A thread refers to a single, sequential flow of control within a process. Multiple threads can run concurrently within a process, each executing different tasks in parallel.
[0033] Rendering optimization refers to identifying performance bottlenecks in image rendering and making targeted optimizations to improve program efficiency.
[0034] Computer vision (CV) is a science that studies how to enable machines to "see." More specifically, it refers to machine vision, which uses cameras and computers to replace human eyes for target recognition and measurement, and further performs image processing to create images more suitable for human observation or transmission to instruments. As a scientific discipline, computer vision researches related theories and technologies, attempting to build artificial intelligence systems capable of extracting information from images or multi-dimensional data. Computer vision technologies typically include image processing, image recognition, image semantic understanding, image retrieval, OCR, video processing, video semantic understanding, video content / behavior recognition, 3D object reconstruction, 3D technology, virtual reality, augmented reality, simultaneous localization and mapping (SLAM), and common biometric recognition technologies such as facial recognition and fingerprint recognition. In this embodiment, image rendering can be performed using computer vision technology, and rendering time can be reduced by introducing multiple threads to concurrently execute rendering tasks. Specifically, a first rendering thread executes a first instruction to share the resource processing sub-tasks in the rendering task, and a second rendering thread executes a second instruction to share the resource processing sub-tasks in the rendering task, thereby optimizing rendering performance and improving rendering efficiency.
[0035] To enable those skilled in the art to better understand the present invention, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0036] Figure 1 This is a flowchart illustrating an image rendering method provided in an embodiment of this application. (In conjunction with...) Figure 1 As shown, the image rendering method provided in this application embodiment may include:
[0037] S101: Start the first rendering thread and the second rendering thread.
[0038] Figure 2 This is a schematic diagram of a multi-threaded architecture for an image rendering method provided in an embodiment of this application. In this embodiment, combined with... Figure 2 As shown, the first rendering thread, denoted as RHIThread, can be used to execute the drawing subtasks within the rendering task to be executed. The second rendering thread, denoted as DRThread, can be used to execute the resource processing subtasks within the rendering task. Specifically, the rendering task to be executed may include a clipping subtask ( Figure 2 (Culling) and sorting subtasks ( Figure 2 The subtasks are categorized into Sorting, Drawing, and Resource Processing. Sorting involves removing objects from the scene; Sorting involves reordering the rendering of objects; and Drawing involves rendering objects, such as terrain, character clothing, and building vegetation. Figure 2 (referred to as BasePass) and drawing scene shadows ( Figure 2 (referred to as ShadowPass in Chinese); resource processing subtasks can refer to the processing of rendering resources, such as the creation and transfer of texture resources. Figure 2 (This is referred to as TextureLock / Unlock) and the compilation of the rendering shader. Figure 2 (referred to as ShaderCompile) and the creation of various render buffers ( Figure 2 (This is referred to as BufferCreate, etc.)
[0039] Correspondingly, the image rendering method provided in this application embodiment may further include: executing the main logic task through the main thread, and executing other subtasks in the rendering task, excluding the drawing subtask and the resource processing subtask, through a third rendering thread. Taking a game program as an example, Figure 2 In this context, the main thread is denoted as Game, and it is used to execute the game logic of the game program, that is, the main logic task. Figure 2 The third rendering thread is denoted as Tick world; the third rendering thread is denoted as Render, which is used to execute other subtasks in the rendering task besides the drawing subtask and the resource processing subtask, such as the clipping subtask and the sorting subtask mentioned above.
[0040] It should be noted that, in Figure 2 In this diagram, a thread is represented by an arrow, and a task is represented by a block diagram. Based on this, tasks executed in parallel within the same frame are represented using block diagrams with the same line width. For example, the task in the first frame is executed using a solid-line block, the task in the second frame using a dashed-line block, and the task in the third frame using a dotted-line block. Furthermore... Figure 2 This is for illustrative purposes only and does not show all the tasks performed in each frame.
[0041] In practical applications, the third rendering thread has the capability to execute the entire rendering task. However, since the first and second rendering threads can focus on the drawing subtasks and resource processing subtasks respectively, reducing the workload on the third rendering thread, in this embodiment, when the first and second rendering threads are running, the third rendering thread can only be used to execute subtasks other than the drawing and resource processing subtasks. Furthermore, the first rendering thread has the capability to execute both drawing and resource processing subtasks. To further distribute the workload, when the second rendering thread is running, the first rendering thread can only be used to execute drawing subtasks. Therefore, in practical applications, the third rendering thread, capable of handling the entire rendering task, can be in a default running state. Thus, after the drawing subtask is created, in... Figure 2In the multi-threaded architecture shown, we can first determine whether the first rendering thread is running. If the first rendering thread is running, it can directly handle the drawing subtasks; if the first rendering thread is not running, the third rendering thread, which is in a default running state, will handle the drawing subtasks. After the resource processing subtask is created, we can further check whether both the first and second rendering threads are running. If the second rendering thread is running, it can handle the resource processing subtasks; if the second rendering thread is not running but the first rendering thread is running, it can execute the resource processing subtasks; if neither the first nor the second rendering thread is running, the third rendering thread, which is in a default running state, will directly execute the resource processing subtasks. It is evident that because the third rendering thread is running by default, when the first and second rendering threads are running, the three rendering threads can each focus on different subtasks within the rendering task, thus effectively reducing blocking in the overall rendering task and distributing workload. When the first and / or second rendering threads are not running, the three rendering threads can also complement each other in executing their respective subtasks, thereby avoiding rendering task failure. In this way, by using three threads to handle the entire rendering task, multi-threaded concurrent execution of the rendering task can be adopted to reduce rendering time, thereby further optimizing rendering performance and improving rendering efficiency. Based on this, the startup process of the first and second rendering threads is not specifically limited in this embodiment of the application; for ease of understanding, an exemplary description is provided below.
[0042] As one possible implementation, the startup process of the first rendering thread may include: calling a first startup function to start the first rendering thread when a predefined second macro instruction is enabled. The thread creation function internally called by this first startup function can be used to create the first rendering thread. Specifically, the predefined second macro instruction can be PLATFORM_ENABLE_RHI_THREAD, which can act as a compiler switch to control whether the first rendering thread is started at compile time. When the second macro instruction PLATFORM_ENABLE_RHI_THREAD is set to "true" or another value indicating "start", the compilation process can include code related to the first rendering thread, and the first rendering thread can be started at runtime. Further, the first startup function can be FRHIThread::Get().Start(), which starts the first rendering thread when it is called. Specifically, regarding the first startup function mentioned above, the FRHIThread class is a thread class that encapsulates the functionality corresponding to the first rendering thread; the Get() method can be used as a singleton pattern implementation to obtain a unique instance of the FRHIThread class, thereby ensuring that there is only one FRHIThread object in the entire multi-threaded architecture, making it easy to access and control the FRHIThread object; the Start() method can be used to start the first rendering thread in the FRHIThread class.
[0043] Therefore, in practical applications, enabling the second macro instruction PLATFORM_ENABLE_RHI_THREAD will further trigger the overall startup of the first rendering thread. This process mainly relies on the first startup function FRHIThread::Get().Start(). Within this first startup function, Get() can be used to obtain an instance of the first rendering thread, and Start() can be used to start the first rendering thread. Furthermore, in Start(), the thread creation function FRunnableThread::Create() can be used to create the first rendering thread. In this way, by starting the first rendering thread, it can handle the drawing subtasks, reducing rendering time and providing more efficient rendering performance through multi-threaded concurrent execution of rendering tasks.
[0044] As another possible implementation, the startup process of the second rendering thread may include: calling a second startup function to start the second rendering thread when a predefined third macro instruction is enabled. The thread creation function called internally by the second startup function can be used to create the second rendering thread. Specifically, the predefined third macro instruction can be `ENABLE_DRIVER_RESOURCE_THREAD`, which can act as a compiler switch to control whether the second rendering thread is started at compile time. When the third macro instruction `ENABLE_DRIVER_RESOURCE_THREAD` is set to "true" or another value indicating "start", the compilation process can include code related to the second rendering thread, and the second rendering thread can be started at runtime. Further, the second startup function can be `FDRThread::Get().Start()`, which starts the second rendering thread when it is called. Specifically, the FDRThread class, which is the second startup function mentioned above, is a thread class that encapsulates the functionality corresponding to the second rendering thread. The Get() method can be implemented as a singleton pattern to obtain a unique instance of the FDRThread class, so that there is only one FDRThread object in the entire multi-threaded architecture, making it easy to access and control the FDRThread object. The Start() method can be used to start the second rendering thread in the FDRThread class.
[0045] Therefore, in practical applications, enabling the third macro directive `ENABLE_DRIVER_RESOURCE_THREAD` will further trigger the overall startup of the second rendering thread. This process mainly relies on the second startup function `FDRThread::Get().Start()`. In this function, `Get()` can be used to obtain an instance of the second rendering thread, and `Start()` can be used to start it. Furthermore, within `Start()`, the thread creation function `FRunnableThread::Create()` can be called to create the second rendering thread. In this way, by starting the second rendering thread, it can handle resource processing subtasks, reducing rendering time and providing more efficient rendering performance through multi-threaded concurrent execution of rendering tasks.
[0046] S102: Obtain the first instruction corresponding to the drawing subtask through the first rendering thread, and obtain the second instruction corresponding to the resource processing subtask through the second rendering thread.
[0047] In practical applications, the process of obtaining the first instruction can include: determining the instruction corresponding to the drawing subtask as the first instruction through the first rendering thread; calling the instruction allocation function to add the first instruction to the task list corresponding to the first rendering thread, where the task list can include multiple candidate first instructions to be executed; and retrieving the first instruction from the task list based on its order. In this way, by storing the first instruction in the task list corresponding to the first rendering thread, subsequent first rendering threads can quickly retrieve the first instruction from the task list according to its order, thus facilitating the fast and accurate execution of the first instruction.
[0048] Specifically, the process of determining the instruction corresponding to the drawing subtask as the first instruction can include: determining the drawing method based on the drawing subtask through the first rendering thread; and determining the instruction corresponding to the drawing method as the first instruction based on the drawing method. As mentioned earlier, drawing subtasks can include rendering objects, such as drawing terrain, drawing character clothing, drawing buildings and vegetation, and drawing scene shadows. Different drawing subtasks correspond to different drawing methods, and different drawing methods correspond to different instructions. For example, for the `DrawPrimitive` drawing method, points, lines, or triangles can be drawn based on a specified vertex array to form an image. Correspondingly, the first instruction corresponding to this drawing method can be represented as `FRHICommandDrawPrimitive`. For the `DrawIndexedPrimitive` drawing method, a vertex buffer and an index buffer can be set. The vertex buffer stores information such as the position, color, and texture coordinates of each vertex, while the index buffer stores the vertex index information. Subsequently, specified lines or triangles can be drawn to form an image. Correspondingly, the first instruction corresponding to this drawing method can be represented as `FRHICommandDrawIndexedPrimitive`. This is merely an illustrative example and does not limit the actual drawing subtasks performed in the embodiments of this application.
[0049] Furthermore, the task list corresponding to the first rendering thread can be a CommandLink, which refers to the data structure used to store the first instruction in the first rendering thread. The task list also includes multiple candidate first instructions to be executed. These candidate first instructions can be stored in the task list according to the order of each frame image. Therefore, the order of the first instructions in the task list can also be stored based on the order of the frame image corresponding to the drawing subtask.
[0050] Furthermore, as mentioned earlier, when the first and second rendering threads are not running, the entire rendering task is executed by the third rendering thread; while when the first rendering thread is running, it handles the drawing subtasks within the rendering task. Therefore, when the first rendering thread is running, after determining the first instruction, it can be further added to the task list corresponding to the first rendering thread by calling the instruction allocation function. The instruction allocation function can be AllocCommand, which is responsible for allocating the instruction content on the heap and initializing the instruction. After the instruction is allocated and initialized, it can be added to the task list. The first instruction can be FRHICommandDrawPrimitive or FRHICommandDrawIndexedPrimitive; FRHICommandDrawPrimitive can be used to represent instructions for drawing basic primitives (such as points, lines, or triangles); FRHICommandDrawIndexedPrimitive can be used to represent instructions for drawing indexed primitives (triangles with shared vertices defined using an index array). By adding the first instruction to the task list corresponding to the first rendering thread, and the task list also includes multiple candidate first instructions to be executed, the first instruction can be buffered through the task list, so that the first rendering thread can retrieve the first instruction to be executed later.
[0051] In practical applications, the process of acquiring the second instruction may include: determining, through the second rendering thread, the instruction corresponding to the resource processing subtask as the second instruction; storing the second instruction in the task memory corresponding to the second rendering thread, the task memory including multiple candidate second instructions to be executed; and retrieving the second instruction from the task memory based on the order of the second instructions in the task memory. Thus, by storing the second instruction in the task memory corresponding to the second rendering thread, subsequent second rendering threads can quickly retrieve the second instruction from the task memory according to the order in which the second instructions are located, thereby facilitating the fast and accurate execution of the second instruction.
[0052] Specifically, the process of determining the instruction corresponding to the resource processing subtask as the second instruction can include: calling the task creation function through the second rendering thread to create an initial instruction based on the resource processing subtask; and encapsulating the initial instruction to obtain the second instruction. As mentioned earlier, the resource processing subtask can include processing rendering resources, such as creating and transferring texture resources, compiling rendering shaders, and creating various rendering buffers. Furthermore, when the first rendering thread is running and the second rendering thread is not running, the resource processing subtask is executed by the first rendering thread; while when the second rendering thread is running, it shares the resource processing subtask. Based on this, taking texture resource creation as an example, in practical applications, if the second rendering thread is not running when creating texture resources, the resource processing subtask will be created as the first instruction FRHICommandGLCommand and enter the processing of the first rendering thread, resulting in a longer waiting time for the entire first rendering thread. If a second rendering thread is started, the resource processing subtask will be created as an initial instruction FDRCommand specifically for processing by the second rendering thread, and then encapsulated to obtain a second instruction FDRThreadTask. Specifically, in practical applications, the initial instruction can be FDRCommand, representing the class corresponding to the resource processing subtask, while the encapsulated second instruction can be FDRThreadTask, representing the class that encapsulates the initial instruction and can be executed in the second rendering thread. The initial instruction FDRCommand's creation function FConstructor can be triggered by the task creation function CreateTask, thus creating the initial instruction FDRCommand. Then, the initial instruction FDRCommand can be encapsulated to obtain the second instruction FDRThreadTask, and stored in the task storage TaskStorage to implement instruction caching, so that the second instruction can be retrieved and executed sequentially later.
[0053] Furthermore, the task storage corresponding to the aforementioned second rendering thread can be TaskStorage, which refers to the data structure used to store second instructions in the second rendering thread. The task storage also includes multiple candidate second instructions to be executed. These candidate second instructions can be stored in the task storage according to the order of each frame image. Therefore, the order of the second instructions in the task storage can also be stored based on the order of the frame image corresponding to the resource processing subtask.
[0054] Furthermore, as mentioned earlier, when the first rendering thread is running and the second rendering thread is not running, the resource processing subtasks are executed by the first rendering thread; however, when the second rendering thread is running, it shares the resource processing subtasks. Therefore, when the second rendering thread is running, after determining the second instruction, the second instruction can be further saved to the TaskStorage corresponding to the second rendering thread. In this way, since the TaskStorage also contains multiple candidate second instructions to be executed, the second instruction can be buffered using the TaskStorage, so that the second rendering thread can retrieve the second instruction to be executed later.
[0055] S103: Execute the first instruction through the first rendering thread, and execute the second instruction through the second rendering thread.
[0056] In the embodiments of this application, the execution process of the first instruction and the second instruction, namely step S103, is not specifically limited. For ease of understanding, an exemplary description is given below.
[0057] In one possible implementation, step S103, for the first instruction, may include: calling a first execution function through a first rendering thread. The first execution function can be used to obtain the rendering context corresponding to the first instruction and call a method within that rendering context. This method can then be used to call the first native rendering function corresponding to the first instruction to execute the first instruction. In this way, by ultimately calling the first native rendering function through the first execution function, the powerful capabilities of the first native rendering function can be leveraged to more efficiently complete the drawing subtask.
[0058] Specifically, the first execution function mentioned above can be `Execute()`, which is responsible for executing the first instruction `FRHICommandDrawPrimitive` or `FRHICommandDrawIndexedPrimitive`. Correspondingly, for the first instruction, its predefined first macro instruction can be `INTERNAL_DECORATOR`, used to call methods in the underlying rendering context. Specifically, the definition of this first macro instruction is: `#define INTERNAL_DECORATOR(Method)CmdList.GetContext().Method`. That is, the first macro instruction `INTERNAL_DECORATOR` is expanded to `CmdList.GetContext().Method`, thereby obtaining an object from the context corresponding to the first instruction and calling the method of that object. Here, `GetContext()` can be used to return a pointer to the rendering context associated with the first instruction, which can be a class instance that encapsulates the aforementioned first native function call. In this way, the first native function can be called to execute the drawing subtask through the first macro instruction `INTERNAL_DECORATOR`.
[0059] Furthermore, different rendering systems correspond to different first native rendering functions. For example, Direct3D (a 3D graphics programming interface) may include first native rendering functions such as DrawPrimitive or DrawIndexedPrimitive; OpenGL (a 2D and 3D vector graphics rendering system) may include first native rendering functions such as glDrawArrays or glDrawElements; Vulkan (a 2D and 3D rendering graphics and computing system) may include first native rendering functions such as vkCmdDraw or vkCmdDrawIndexed; and Metal (a 3D graphics and computing system) may include first native rendering functions such as drawPrimitives:vertexStart:vertexCount:. In other words, in the embodiments of this application, Figure 2 The multi-threaded architecture shown can be implemented based on any of the above rendering systems. Then, the first execution function can call the first native rendering function corresponding to the system, and the powerful capabilities of the first native rendering function can be used to complete the drawing sub-tasks more efficiently.
[0060] In another possible implementation, step S103, for the second instruction, may include: calling a second execution function through a second rendering thread. The second execution function can be used to call the second native rendering function corresponding to the second instruction to execute the second instruction. In this way, by ultimately calling the second native rendering function through the second execution function, the powerful capabilities of the second native rendering function can be leveraged to more efficiently complete the resource processing subtask.
[0061] Specifically, the aforementioned second execution function can be GLFunction(), which encapsulates the second native rendering function corresponding to the second instruction to execute the second instruction FDRThreadTask. Correspondingly, during the execution of the second instruction FDRThreadTask, the second execution function GLFunction() can be called, and the second execution function GLFunction() internally calls the second native rendering function to execute the resource processing subtask.
[0062] Furthermore, different rendering systems correspond to different second native rendering functions. For example, Direct3D may include second native rendering functions such as ID3D11Device::CreateBuffer: or ID3D11DeviceContext::Map, etc.; OpenGL may include second native rendering functions such as glCopyTexImage2D or glGenTextures, etc.; Vulkan may include second native rendering functions such as vkCreateImage or vkCmdCopyImage, etc.; and Metal may include second native rendering functions such as newTextureWithDescriptor: or encodeCommandsWithBlock:, etc. In other words, in the embodiments of this application, Figure 2 The multi-threaded architecture shown can be implemented based on any of the above rendering systems. Then, the second execution function can be used to call the corresponding second native rendering function of the system, and the powerful capabilities of the second native rendering function can be used to complete the resource processing subtask more efficiently.
[0063] In practical applications, embodiments of this application can also use simulation experiments to test the effect of reducing rendering time by concurrently executing drawing subtasks and resource processing subtasks using the first and second rendering threads. Specifically, Figure 3a This is a schematic diagram illustrating the runtime of a first rendering thread as provided in an embodiment of this application. Figure 3b This is a schematic diagram illustrating the runtime of a second rendering thread as provided in an embodiment of this application. (Combined with...) Figure 3aAs shown, when the first rendering thread runs to share the drawing subtasks, the time taken by the first rendering thread for the tasks of drawing terrain (DrawIndexedPrimitive Mat[Master_Borderland_Landscape]Res[Landscape]), drawing the character's shirt (DrawIndexedPrimitive Mat[Master_Mask_Base_Player]Res[AT_M_Shirt_01B]), and drawing the character's pants (DrawIndexedPrimitive Mat[Master_Mask_Base_Player]Res[AT_M_Pants_23A]) is 27.676ms (RHI Thread Execute). This demonstrates that by enabling the first rendering thread, sufficient parallelism of the rendering tasks can be achieved, avoiding the performance bottleneck caused by executing the entire rendering task solely through the third rendering thread. Combined with... Figure 3b As shown, when the second rendering thread runs to share the resource processing subtask, the time taken for the resource creation task (WaitForEvent) is 28.146ms, and the time taken for other loading tasks (Other TaskGraph Tasks) is 26.829ms. Among them, the time taken for locking the texture resource is 9.522ms, and the time taken for unlocking the texture resource is 4.052ms.
[0064] In addition, regarding the running effects of the first rendering thread and the second rendering thread, embodiments of this application may also provide Table 1 and Table 2 for illustrative purposes:
[0065] Table 1
[0066]
[0067] As shown in Table 1 above, when the device model, program version, and image quality frame rate are all the same, the average frame rate per second (FPS) when the first rendering thread is enabled can be increased from 35.4 FPS when it is not enabled to 64.9 FPS, which is a performance improvement of 83%.
[0068] Table 2
[0069]
[0070] As shown in Table 2 above, when the device model, program version, and frame rate are all the same, the stuttering rate when the second rendering thread is enabled can be reduced from 29.24% when it is not enabled to 14.41%, and the stuttering rate optimization reaches 51%.
[0071] Based on the above steps S101-S103, in this embodiment, a first rendering thread for executing the drawing sub-task in the rendering task to be executed, and a second rendering thread for executing the resource processing sub-task in the rendering task, can be started first. Then, a first instruction corresponding to the drawing sub-task and a second instruction corresponding to the resource processing sub-task can be obtained. The first instruction is stored in a first data structure corresponding to the first rendering thread, and the second instruction is stored in a second data structure corresponding to the second rendering thread. The first rendering thread then retrieves and executes the first instruction from the first data structure, and the second rendering thread retrieves and executes the second instruction from the second data structure. In this way, the first rendering thread can share the drawing sub-task in the rendering task, that is, execute the first instruction, and the second rendering thread can share the resource processing sub-task in the rendering task, that is, execute the second instruction. By using multiple threads to concurrently execute the rendering task, the rendering time can be reduced, avoiding the performance bottleneck caused by using a single thread to execute the rendering task, thereby optimizing rendering performance and improving rendering efficiency.
[0072] Based on the image rendering method provided in the foregoing embodiments, this application embodiment may also provide an image rendering apparatus. The image rendering apparatus will now be described in conjunction with the embodiments and accompanying drawings.
[0073] Figure 4 This is a schematic diagram of the structure of an image rendering apparatus provided in an embodiment of this application. (In conjunction with...) Figure 4 As shown, the image rendering apparatus provided in this application embodiment can be applied to a client. The image rendering apparatus 400 includes:
[0074] The startup module 401 is used to start a first rendering thread and a second rendering thread. The first rendering thread is used to execute the drawing sub-task in the rendering task to be executed, and the second rendering thread is used to execute the resource processing sub-task in the rendering task.
[0075] The acquisition module 402 is used to acquire the first instruction corresponding to the drawing subtask through the first rendering thread, and to acquire the second instruction corresponding to the resource processing subtask through the second rendering thread;
[0076] The first execution module 403 is used to execute the first instruction through the first rendering thread and execute the second instruction through the second rendering thread.
[0077] Optionally, the acquisition module 402 includes:
[0078] The first instruction determination module is used to determine, through the first rendering thread, the instruction corresponding to the drawing subtask as the first instruction;
[0079] The instruction addition module is used to call the instruction allocation function to add the first instruction to the task list corresponding to the first rendering thread, wherein the task list includes multiple candidate first instructions to be executed.
[0080] The first acquisition submodule is used to acquire the first instruction from the task chain list through the first rendering thread based on the order of the first instruction in the task chain list.
[0081] Optionally, the first execution module 403 includes:
[0082] The first execution submodule is used to call the first execution function through the first rendering thread. The first execution function has a predefined first macro instruction used to obtain the rendering context corresponding to the first instruction and call the method in the rendering context. The method in the rendering context is used to call the first native rendering function corresponding to the first instruction to execute the first instruction.
[0083] Optionally, the acquisition module 402 includes:
[0084] The second instruction determination module is used to determine, through the second rendering thread, the instruction corresponding to the resource processing subtask as the second instruction;
[0085] An instruction storage module is used to store the second instruction in the task storage corresponding to the second rendering thread, wherein the task storage includes a plurality of candidate second instructions to be executed;
[0086] The second acquisition submodule is used to acquire the second instruction from the task memory through the second rendering thread based on the order of the second instruction in the task memory.
[0087] Optionally, the first execution module 403 includes:
[0088] The first execution submodule is used to call the second execution function through the second rendering thread. The second execution function is used to call the second native rendering function corresponding to the second instruction to execute the second instruction.
[0089] Optionally, the startup module 401 includes:
[0090] The first startup submodule is used to call the first startup function to start the first rendering thread when the predefined second macro instruction is enabled. The first startup function internally calls the thread creation function to create the first rendering thread.
[0091] Optionally, the startup module 401 includes:
[0092] The second startup submodule is used to call the second startup function to start the second rendering thread when a predefined third macro instruction is enabled. The second startup function internally calls the thread creation function to create the second rendering thread.
[0093] Optionally, the image rendering apparatus 400 further includes:
[0094] The second execution module is used to execute the main logic task through the main thread, and to execute other sub-tasks in the rendering task other than the drawing sub-task and the resource processing sub-task through the third rendering thread.
[0095] The structure of the control equipment for implementing the above image rendering methods is described below for both server and terminal device configurations.
[0096] Figure 5 This is a schematic diagram of a server structure provided in an embodiment of this application. The server 900 can vary significantly due to different configurations or performance. It may include one or more central processing units (CPUs) 922 (e.g., one or more processors) and memory 932, and one or more storage media 930 (e.g., one or more mass storage devices) for storing application programs 942 or data 944. The memory 932 and storage media 930 can be temporary or persistent storage. The program stored in the storage media 930 may include one or more modules (not shown in the diagram), each module may include a series of instruction operations on the server. Furthermore, the CPU 922 may be configured to communicate with the storage media 930 and execute the series of instruction operations in the storage media 930 on the server 900.
[0097] Server 900 may also include one or more power supplies 926, one or more wired or wireless network interfaces 950, one or more input / output interfaces 958, and / or one or more operating systems 941, such as Windows Server. TM Mac OS X TM Unix TM Linux TM FreeBSD TM etc.
[0098] The steps performed by the server in the above embodiments can be based on this Figure 5 The server structure shown.
[0099] The CPU 922 is used in the following steps:
[0100] Start the first rendering thread and the second rendering thread. The first rendering thread is used to execute the drawing sub-task in the rendering task to be executed, and the second rendering thread is used to execute the resource processing sub-task in the rendering task.
[0101] The first instruction corresponding to the drawing subtask is obtained through the first rendering thread, and the second instruction corresponding to the resource processing subtask is obtained through the second rendering thread.
[0102] The first instruction is executed through the first rendering thread, and the second instruction is executed through the second rendering thread.
[0103] This application also provides another control device, such as... Figure 6 As shown, for ease of explanation, only the parts related to the embodiments of this application are shown. For specific technical details not disclosed, please refer to the method section of the embodiments of this application. The terminal can be any terminal device including mobile phones, tablets, personal digital assistants (PDAs), point-of-sale (POS) terminals, in-vehicle computers, etc. Taking a mobile phone as an example:
[0104] Figure 6 This is a block diagram illustrating a portion of the structure of a mobile phone related to the terminal provided in the embodiments of this application. (Reference) Figure 6 The mobile phone includes: a radio frequency (RF) circuit 1010, a memory 1020, an input unit 1030, a display unit 1040, a sensor 1050, an audio circuit 1060, a wireless fidelity (WiFi) module 1070, a processor 1080, and a power supply 1090, etc. Those skilled in the art will understand that... Figure 6 The mobile phone structure shown does not constitute a limitation on the mobile phone and may include more or fewer components than shown, or combine certain components, or have different component arrangements.
[0105] The following is combined with Figure 6 A detailed introduction to each component of a mobile phone:
[0106] The RF circuit 1010 can be used for receiving and transmitting signals during information transmission or calls. Specifically, it receives downlink information from the base station and processes it with the processor 1080; additionally, it transmits uplink data to the base station. Typically, the RF circuit 1010 includes, but is not limited to, an antenna, at least one amplifier, a transceiver, a coupler, a low-noise amplifier (LNA), a duplexer, etc. Furthermore, the RF circuit 1010 can also communicate wirelessly with networks and other devices. The aforementioned wireless communications may use any communication standard or protocol, including but not limited to Global System for Mobile Communications (GSM), General Packet Radio Service (GPRS), Code Division Multiple Access (CDMA), Wideband Code Division Multiple Access (WCDMA), Long Term Evolution (LTE), email, and Short Messaging Service (SMS).
[0107] The memory 1020 can be used to store software programs and modules. The processor 1080 executes various mobile phone functions and data processing by running the software programs and modules stored in the memory 1020. The memory 1020 may mainly include a program storage area and a data storage area. The program storage area may store the operating system, applications required for at least one function (such as sound playback function, image playback function, etc.), etc.; the data storage area may store data created according to the use of the mobile phone (such as audio data, phonebook, etc.). In addition, the memory 1020 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device.
[0108] The input unit 1030 can be used to receive input numerical or character information, and to generate key signal inputs related to user settings and function control of the mobile phone. Specifically, the input unit 1030 may include a touch panel 1031 and other input devices 1032. The touch panel 1031, also known as a touch screen, can collect touch operations performed by the user on or near it (such as operations performed by the user using a finger, stylus, or any suitable object or accessory on or near the touch panel 1031), and drive the corresponding connection devices according to a pre-set program. Optionally, the touch panel 1031 may include two parts: a touch detection device and a touch controller. The touch detection device detects the user's touch position and the signal generated by the touch operation, and transmits the signal to the touch controller; the touch controller receives touch information from the touch detection device, converts it into touch point coordinates, and sends it to the processor 1080, and can also receive and execute commands sent by the processor 1080. In addition, the touch panel 1031 can be implemented using various types such as resistive, capacitive, infrared, and surface acoustic wave. In addition to the touch panel 1031, the input unit 1030 may also include other input devices 1032. Specifically, other input devices 1032 may include, but are not limited to, one or more of the following: physical keyboard, function keys (such as volume control buttons, power buttons, etc.), trackball, mouse, joystick, etc.
[0109] The display unit 1040 can be used to display information input by the user or information provided to the user, as well as various menus of the mobile phone. The display unit 1040 may include a display panel 1041, which may optionally be configured as a Liquid Crystal Display (LCD), Organic Light-Emitting Diode (OLED), or similar display panel 1041. Further, a touch panel 1031 may cover the display panel 1041. When the touch panel 1031 detects a touch operation on or near it, it transmits the information to the processor 1080 to determine the type of touch event. Subsequently, the processor 1080 provides corresponding visual output on the display panel 1041 according to the type of touch event. Although in Figure 6 In this embodiment, the touch panel 1031 and the display panel 1041 are two separate components to realize the input and output functions of the mobile phone. However, in some embodiments, the touch panel 1031 and the display panel 1041 can be integrated to realize the input and output functions of the mobile phone.
[0110] The mobile phone may also include at least one sensor 1050, such as a light sensor, a motion sensor, and other sensors. Specifically, the light sensor may include an ambient light sensor and a proximity sensor. The ambient light sensor can adjust the brightness of the display panel 1041 according to the ambient light level, and the proximity sensor can turn off the display panel 1041 and / or the backlight when the phone is moved to the ear. As a type of motion sensor, an accelerometer sensor can detect the magnitude of acceleration in various directions (generally three axes). When stationary, it can detect the magnitude and direction of gravity and can be used for applications that recognize the phone's posture (such as landscape / portrait switching, related games, magnetometer posture calibration), vibration recognition-related functions (such as pedometer, taps), etc. Other sensors that may be configured in the mobile phone, such as gyroscopes, barometers, hygrometers, thermometers, and infrared sensors, will not be described in detail here.
[0111] The audio circuit 1060, speaker 1061, and microphone 1062 provide an audio interface between the user and the mobile phone. The audio circuit 1060 converts the received audio data into electrical signals and transmits them to the speaker 1061, where the speaker 1061 converts them into sound signals for output. On the other hand, the microphone 1062 converts the collected sound signals into electrical signals, which are then received by the audio circuit 1060, converted into audio data, and then processed by the processor 1080 before being transmitted via the RF circuit 1010 to, for example, another mobile phone, or the audio data can be output to the memory 1020 for further processing.
[0112] WiFi is a short-range wireless transmission technology. Through the WiFi module 1070, mobile phones can help users send and receive emails, browse web pages, and access streaming media, providing users with wireless broadband internet access. Although Figure 6 The WiFi module 1070 is shown, but it is understood that it is not an essential component of a mobile phone and can be omitted as needed without changing the essence of the invention.
[0113] The processor 1080 is the control center of the mobile phone, connecting various parts of the phone through various interfaces and lines. It executes software programs and / or modules stored in the memory 1020 and calls data stored in the memory 1020 to perform various functions and process data, thereby collecting overall data and information from the phone. Optionally, the processor 1080 may include one or more processing units; preferably, the processor 1080 may integrate an application processor and a modem processor, wherein the application processor mainly handles the operating system, user interface, and applications, and the modem processor mainly handles wireless communication. It is understood that the modem processor may not be integrated into the processor 1080.
[0114] The mobile phone also includes a power supply 1090 (such as a battery) that supplies power to various components. Preferably, the power supply can be logically connected to the processor 1080 through a power management system, thereby enabling functions such as charging, discharging, and power consumption management through the power management system.
[0115] Although not shown, mobile phones may also include a camera, Bluetooth module, etc., which will not be described in detail here.
[0116] In this embodiment of the application, the processor 1080 included in the terminal also has the following functions:
[0117] Start the first rendering thread and the second rendering thread. The first rendering thread is used to execute the drawing sub-task in the rendering task to be executed, and the second rendering thread is used to execute the resource processing sub-task in the rendering task.
[0118] The first instruction corresponding to the drawing subtask is obtained through the first rendering thread, and the second instruction corresponding to the resource processing subtask is obtained through the second rendering thread.
[0119] The first instruction is executed through the first rendering thread, and the second instruction is executed through the second rendering thread.
[0120] In this application embodiment, the terms "module" or "unit" refer to a computer program or part of a computer program that has a predetermined function and works with other related parts to achieve a predetermined goal, and can be implemented wholly or partially using software, hardware (such as processing circuitry or memory), or a combination thereof. Similarly, a processor (or multiple processors or memory) can be used to implement one or more modules or units. Furthermore, each module or unit can be part of an overall module or unit that includes the functionality of that module or unit.
[0121] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0122] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection between apparatuses or units through some interfaces, and may be electrical, mechanical, or other forms.
[0123] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0124] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0125] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes: USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, optical disks, and other media capable of storing program code.
[0126] The above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application.
Claims
1. An image rendering method, characterized in that, include: Start the first rendering thread and the second rendering thread. The first rendering thread is used to execute the drawing sub-task in the rendering task to be executed, and the second rendering thread is used to execute the resource processing sub-task in the rendering task. The first instruction corresponding to the drawing subtask is obtained through the first rendering thread, and the second instruction corresponding to the resource processing subtask is obtained through the second rendering thread. The first instruction is executed through the first rendering thread, and the second instruction is executed through the second rendering thread.
2. The image rendering method according to claim 1, characterized in that, The step of obtaining the first instruction corresponding to the drawing subtask through the first rendering thread includes: The first rendering thread determines the instruction corresponding to the drawing subtask as the first instruction. The instruction allocation function is called to add the first instruction to the task list corresponding to the first rendering thread, and the task list includes multiple candidate first instructions to be executed; Based on the order of the first instruction in the task chain, the first instruction is retrieved from the task chain by the first rendering thread.
3. The image rendering method according to claim 1, characterized in that, The execution of the first instruction through the first rendering thread includes: The first execution function is called by the first rendering thread. The first macro instruction in the first execution function is used to obtain the rendering context corresponding to the first instruction and call the method in the rendering context. The method in the rendering context is used to call the first native rendering function corresponding to the first instruction to execute the first instruction.
4. The image rendering method according to claim 1, characterized in that, The step of obtaining the second instruction corresponding to the resource processing subtask through the second rendering thread includes: The second rendering thread determines the instruction corresponding to the resource processing subtask as the second instruction. The second instruction is stored in the task memory corresponding to the second rendering thread, and the task memory includes a plurality of candidate second instructions to be executed; Based on the order of the second instructions in the task memory, the second instructions are retrieved from the task memory by the second rendering thread.
5. The image rendering method according to claim 1, characterized in that, The execution of the second instruction through the second rendering thread includes: The second rendering thread calls the second execution function, which is used to call the second native rendering function corresponding to the second instruction to execute the second instruction.
6. The image rendering method according to any one of claims 1 to 5, characterized in that, Starting the first rendering thread includes: When the predefined second macro instruction is enabled, the first startup function is called to start the first rendering thread, and the thread creation function called inside the first startup function is used to create the first rendering thread.
7. The image rendering method according to any one of claims 1 to 5, characterized in that, Starting the second rendering thread includes: When the predefined third macro instruction is enabled, the second startup function is called to start the second rendering thread, and the thread creation function called inside the second startup function is used to create the second rendering thread.
8. The image rendering method according to any one of claims 1 to 5, characterized in that, The image rendering method further includes: The main logic task is executed through the main thread, and the other sub-tasks in the rendering task, excluding the drawing sub-task and the resource processing sub-task, are executed through the third rendering thread.
9. An image rendering apparatus, characterized in that, include: The startup module is used to start the first rendering thread and the second rendering thread. The first rendering thread is used to execute the drawing sub-task in the rendering task to be executed, and the second rendering thread is used to execute the resource processing sub-task in the rendering task. The acquisition module is used to acquire a first instruction corresponding to the drawing subtask through the first rendering thread, and to acquire a second instruction corresponding to the resource processing subtask through the second rendering thread. The first execution module is configured to execute the first instruction through the first rendering thread and execute the second instruction through the second rendering thread.
10. An image rendering device, characterized in that, The device includes a processor and a memory: The memory is used to store computer programs and to transfer the computer programs to the processor; The processor is configured to execute the steps of the image rendering method according to any one of claims 1 to 8, based on instructions in the computer program.
11. A computer-readable storage medium, characterized in that, The computer-readable storage medium is used to store a computer program that, when executed by a terminal device, implements the steps of the image rendering method according to any one of claims 1 to 8.
12. A computer program product, characterized in that, It includes a computer program that, when executed by a terminal device, implements the steps of the image rendering method according to any one of claims 1 to 8.