Image rendering method and device, equipment and storage medium
By obtaining the hardware and rendering performance information of the terminal device, determining the optimization strategy of the shader source code, compiling and optimizing the generated target shader, the problem of low image rendering efficiency on low-configuration terminal devices is solved and efficient rendering is achieved.
Patent Information
- Application Number
- CN202510552219.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-29
- Publication Date
- 2025-09-05
AI Technical Summary
The existing technology has low image rendering efficiency, high resource consumption and long time consumption on low-configuration terminal devices.
By obtaining the hardware environment information and rendering performance information of the terminal device, the target compilation optimization strategy of the shader source code is determined, and compilation and optimization are performed to generate the target shader for image rendering.
It improves image rendering efficiency, reduces resource consumption and time, and is suitable for low-configuration terminal devices.
Smart Images

Figure CN120599110A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image rendering technology, and in particular to an image rendering method, apparatus, device and storage medium. Background Art
[0002] With the rapid development of computer graphics, real-time rendering has been widely used in games, virtual reality and other fields. The current rendering method usually uses a fixed rendering pipeline through a specified graphics interface and shader. Usually, the process of calling the graphics interface for rendering consumes a lot of resources and takes a long time, which has low running efficiency on terminal devices with lower configuration.
[0003] Therefore, how to improve the efficiency of image rendering is an urgent problem to be solved. Summary of the Invention
[0004] The main purpose of this application is to provide an image rendering method, apparatus, device and storage medium, aiming to improve the efficiency of image rendering.
[0005] In a first aspect, the present application provides an image rendering method, the image rendering method comprising the following steps:
[0006] In response to an image rendering request, obtaining corresponding shader source code to be compiled;
[0007] Determining a target compilation optimization strategy for the shader source code based on the hardware environment information and rendering performance information of the terminal device;
[0008] According to the target compilation optimization strategy, the shader source code is compiled and optimized to obtain a target shader, and image rendering is performed according to the target shader.
[0009] In a second aspect, the present application further provides an image rendering device, comprising an acquisition module, a determination module, and a generation module, wherein:
[0010] The acquisition module is used to obtain the corresponding shader source code to be compiled in response to the image rendering request;
[0011] The determining module is used to determine the target compilation optimization strategy of the shader source code according to the hardware environment information and rendering performance information of the terminal device;
[0012] The generation module is used to compile and optimize the shader source code according to the target compilation optimization strategy to obtain a target shader, and perform image rendering according to the target shader.
[0013] In a third aspect, the present application also provides a terminal device, which includes a processor, a memory, and a computer program stored in the memory and executable by the processor, wherein when the computer program is executed by the processor, the steps of the image rendering method as described above are implemented.
[0014] In a fourth aspect, the present application further provides a computer-readable storage medium, on which a computer program is stored, wherein when the computer program is executed by a processor, the steps of the image rendering method as described above are implemented.
[0015] The present application provides an image rendering method, apparatus, device and storage medium. The present application obtains the corresponding shader source code to be compiled in response to an image rendering request; determines the target compilation optimization strategy of the shader source code based on the hardware environment information and rendering performance information of the terminal device; compiles and optimizes the shader source code according to the target compilation optimization strategy to obtain a target shader, and performs image rendering according to the target shader. The present application can accurately determine the target compilation optimization strategy of the shader source code through the hardware environment information and rendering performance information of the terminal device, and compiles and optimizes the shader source code according to the target compilation optimization strategy to obtain a target shader, and then performs image rendering through the target shader, which can efficiently generate rendered images. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following is a brief introduction to the drawings required for use in the description of the embodiments. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0017] Figure 1 A flowchart of an image rendering method provided in an embodiment of the present application;
[0018] Figure 2 for Figure 1 A schematic diagram of the sub-step flow of the image rendering method in FIG.
[0019] Figure 3 A schematic diagram of a flow chart of another image rendering method provided in an embodiment of the present application;
[0020] Figure 4 A schematic block diagram of an image rendering device provided in an embodiment of the present application;
[0021] Figure 5 A schematic block diagram of another image rendering device provided in an embodiment of the present application;
[0022] Figure 6A schematic block diagram of the structure of a terminal device provided in an embodiment of the present application.
[0023] The realization of the objectives, functional features and advantages of this application will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0024] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0025] The flowcharts shown in the accompanying drawings are for illustrative purposes only and do not necessarily include all contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps may be decomposed, combined, or partially merged, so the actual execution order may vary depending on the actual situation.
[0026] With the rapid development of computer graphics, real-time rendering has been widely used in games, virtual reality and other fields. The current rendering method usually uses a fixed rendering pipeline through a specified graphics interface and shader. Usually, the process of calling the graphics interface for rendering consumes a lot of resources and takes a long time, which has low running efficiency on terminal devices with lower configuration.
[0027] To address the above-mentioned issues, embodiments of the present application provide an image rendering method, apparatus, device, and storage medium. The image rendering method includes, in response to an image rendering request, obtaining corresponding shader source code to be compiled; determining a target compilation optimization strategy for the shader source code based on the hardware environment information and rendering performance information of the terminal device; compiling and optimizing the shader source code according to the target compilation optimization strategy to obtain a target shader; and performing image rendering based on the target shader.
[0028] The image rendering method can be applied to terminal devices, which may be electronic devices such as mobile phones, tablet computers, laptop computers, desktop computers, personal digital assistants, and wearable devices.
[0029] The following describes some embodiments of the present application in detail with reference to the accompanying drawings. In the absence of conflict, the following embodiments and features therein may be combined with each other.
[0030] Please refer to Figure 1 , Figure 1 A flowchart of an image rendering method provided in an embodiment of the present application.
[0031] like Figure 1 As shown, the image rendering method includes steps S101 to S103.
[0032] Step S101: In response to an image rendering request, obtain corresponding shader source code to be compiled.
[0033] The shader source code is a shader code, and the shader source code can be compiled to obtain a shader, and the shader can be used for image rendering.
[0034] In some embodiments, an image rendering request is received, and a corresponding shader source code to be compiled is obtained according to the image rendering request. The shader source code with compilation can be accurately obtained according to the image rendering request.
[0035] In some embodiments, the image rendering request may be obtained by automatically generating the image rendering request according to the image rendering purpose when image rendering is required. The image rendering request can be accurately generated according to the image rendering purpose.
[0036] In some embodiments, the image rendering request may be obtained by obtaining an image rendering task generated by a user on a terminal device and generating an image rendering request based on the image rendering task. The image rendering request can be accurately generated based on the image rendering task generated by the user on the terminal device.
[0037] It should be noted that the user can choose the way to control the generation of image rendering tasks in the terminal device according to actual conditions. The embodiments of the present application do not make specific limitations on this. For example, the terminal device is a mobile phone, and the text for generating a fireworks image is clicked on the screen of the mobile phone. According to the user's instruction to click on the text for generating a fireworks image on the screen, an image rendering task is generated.
[0038] In some embodiments, the method for obtaining the corresponding shader source code to be compiled can be: obtaining a preset mapping relationship table between an image rendering request and a shader source code, querying the shader source code corresponding to the image rendering request from the mapping relationship table, and obtaining the shader source code to be compiled. Among them, the mapping relationship table is established in advance based on the image rendering request and the shader source code. The mapping relationship table can be established according to actual conditions, and the embodiments of the present application do not specifically limit this. The shader source code to be compiled can be accurately queried through the mapping relationship table.
[0039] It should be noted that the shader source code to be compiled is the shader source code that needs to be optimized. The shader source code to be compiled also directly generates a shader, and then the shader is rendered, but the generated image fails to achieve the preset effect.
[0040] Step S102: Determine a target compilation optimization strategy for the shader source code based on the hardware environment information and rendering performance information of the terminal device.
[0041] The target compilation optimization strategy is a strategy for optimizing shader source code to improve image rendering efficiency.
[0042] In some embodiments, as Figure 2 As shown, step S102 includes sub-steps S1021 and S1022.
[0043] Sub-step S1021: Acquire multiple compilation optimization strategies corresponding to the hardware environment information.
[0044] The hardware environment information is the processor information and memory controller information of the graphics processing unit (GPU) of the terminal device. The compilation optimization strategy is used to compile and optimize the shader source code, and the compilation optimization strategy includes a shader structure optimization strategy, a shader parameter optimization strategy, and a shader algorithm optimization strategy. The shader structure includes but is not limited to vertex shaders, pixel shaders, geometry shaders, and tessellation shaders; shader parameters include but are not limited to floating-point attributes, color attributes, texture attributes, and vector attributes; and shader algorithms include but are not limited to Gaussian blur algorithms and ray tracing algorithms.
[0045] In some embodiments, a mapping relationship table between preset hardware environment information and compilation optimization strategies is obtained, and the compilation optimization strategy corresponding to the hardware environment information is queried from the mapping relationship table. The mapping relationship table is pre-established based on the hardware environment and the compilation optimization strategy. The mapping relationship table can be set according to actual conditions, and this embodiment of the present application does not specifically limit this. The mapping relationship table can accurately obtain the compilation optimization strategy corresponding to the hardware environment information.
[0046] It should be noted that the compilation optimization strategy may include at least one shader structure optimization strategy, a shader parameter optimization strategy, and / or a shader algorithm optimization strategy. For example, the compilation optimization strategy includes two shader structure optimization strategies, five shader parameter optimization strategies, and three shader algorithm optimization strategies. For another example, the compilation optimization strategy includes four shader structure optimization strategies and two shader parameter optimization strategies.
[0047] Sub-step S1022: Selecting the compilation optimization strategy that matches the rendering performance information from the multiple compilation optimization strategies as the target compilation optimization strategy.
[0048] The rendering performance information includes GPU load information, GPU memory usage information, and GPU display frame rate information.
[0049] In some embodiments, a mapping relationship table between preset rendering performance information and compilation optimization strategies is obtained, the compilation optimization strategy corresponding to the rendering performance information is matched from the mapping relationship table, and the compilation optimization strategy is determined as the target compilation optimization strategy. The mapping relationship table is pre-established based on the rendering performance information and the compilation optimization strategy. The mapping relationship table can be established according to actual conditions, and the embodiments of the present application do not specifically limit this. The target compilation optimization strategy can be accurately queried through the mapping relationship table.
[0050] Exemplarily, when it is determined that the GPU load is greater than or equal to a preset GPU load, and the GPU load is matched from the mapping relationship table to be greater than or equal to the preset GPU load, the compilation optimization strategy includes a shader parameter optimization strategy and a shader algorithm optimization strategy, wherein the shader parameter optimization strategy is to reduce detail parameters, and the shader algorithm optimization strategy is to reduce computational complexity. By compiling and optimizing the shader source code through the optimization strategies of reducing detail parameters and reducing computational complexity, the efficiency of image rendering can be effectively improved.
[0051] Step S103 : compile and optimize the shader source code according to the target compilation optimization strategy to obtain a target shader, and perform image rendering according to the target shader.
[0052] The target shader is an executable program obtained by compiling and optimizing the shader source code.
[0053] In some embodiments, the target compilation optimization strategy is used to obtain the corresponding optimized source code, and the shader source code is updated according to the optimized source code to obtain the target shader source code; the target shader source code is compiled to obtain the target shader, and the image is rendered according to the target shader to obtain the target image. Compiling and optimizing the shader source code using the target compilation optimization strategy to obtain the target shader can effectively improve the efficiency of image rendering.
[0054] In some embodiments, the method for obtaining the corresponding optimized source code according to the target compilation optimization strategy can be: obtaining a mapping relationship table between a preset target compilation optimization strategy and the optimized source code, and querying the optimized source code corresponding to the target compilation optimization strategy from the mapping relationship table. Among them, the mapping relationship table is established in advance based on the target compilation optimization strategy and the optimized source code. The mapping relationship table can be set according to actual conditions, and the embodiments of the present application do not make specific restrictions on this. Through the mapping relationship table, the target compilation optimization strategy can be accurately obtained to obtain the corresponding optimized source code, which can effectively improve the accuracy of image rendering.
[0055] In some embodiments, image rendering is performed based on a target shader and texture data in a cache of a terminal device, where the texture data is pre-loaded into the cache in response to an image rendering request, and the cache is a GPU cache. Using the cached texture data for image rendering can effectively improve image rendering efficiency.
[0056] In some embodiments, texture data is obtained and the frequency of use of the texture data within a preset time is determined. If the frequency of use of the texture data within the preset time is greater than or equal to the preset frequency of use, the texture data is stored in a cache. The preset time and the preset frequency of use can be set according to actual conditions, and the embodiments of the present application do not specifically limit this. For example, the preset time can be set to 5 seconds, and the preset frequency of use can be set to 10 times. Storing texture data with a frequency of use greater than or equal to the preset frequency of use in a cache can improve the efficiency of texture data loading during image rendering.
[0057] In some embodiments, the usage frequency of texture data in the cache is obtained, and texture data in the cache with a usage frequency lower than a preset usage frequency is moved to the main memory of the terminal device. By moving texture data in the cache with a usage frequency lower than the preset usage frequency to the main memory of the terminal device, the storage pressure of the cache is reduced and the utilization rate of the cache is improved.
[0058] It should be noted that the texture data in the cache can be used by different target shaders; and / or the texture data in the cache is compressed. By setting the texture data in the cache to be used by different target shaders, it is possible to effectively avoid repeated caching and loading of resources, reduce the pressure on bandwidth and cache, and greatly improve resource utilization. By compressing the texture data in the cache, it is possible to effectively reduce video memory occupancy and bandwidth occupancy, and effectively improve texture data transmission efficiency and loading efficiency. Among them, the compression of texture data can be set according to actual conditions, and the embodiments of the present application do not make specific limitations on this.
[0059] In some embodiments, the image rendering task corresponding to the target shader is divided into multiple image rendering subtasks; and multiple computing units in the terminal device are called to process the multiple image rendering subtasks in parallel. By dividing the image rendering task corresponding to the target shader into multiple image rendering subtasks, multiple computing units can be used to perform parallel processing, effectively improving image rendering efficiency.
[0060] In some embodiments, the image rendering task corresponding to the target shader may be divided into multiple image rendering subtasks by evenly dividing the image rendering task corresponding to the target shader into the multiple image rendering subtasks. By evenly dividing the image rendering task corresponding to the target shader into the multiple image rendering subtasks, each computing unit can calculate the same number of image rendering subtasks, thereby improving image rendering efficiency.
[0061] In some embodiments, the image rendering task corresponding to the target shader can be divided into multiple image rendering subtasks by obtaining the task characteristics and task dependencies of each image rendering task and dividing the image rendering task into multiple image rendering subtasks. Dividing the image rendering tasks based on the task characteristics and task dependencies can effectively improve image rendering efficiency.
[0062] In some embodiments, multiple computing units in a terminal device may be called upon to perform parallel processing of multiple image rendering subtasks by obtaining the computing power of each computing unit and the computing power required to compute each image rendering subtask; then, based on the computing power of each computing unit and the computing power required to compute each image rendering subtask, each computing unit is matched with an image rendering subtask that it can process within its capabilities; each computing unit processes the assigned image rendering subtask to obtain a rendered image. By assigning each computing unit an image rendering subtask that it can process within its capabilities, image rendering can be efficiently completed.
[0063] It should be noted that if there is an image rendering subtask that matches a computing unit that can process it, the image rendering subtask is further divided to generate smaller image rendering subtasks so that the computing unit can complete the image rendering task.
[0064] It should be noted that the various computing units are configured to communicate synchronously so that the various computing units can share and synchronize data when performing image rendering, thereby ensuring data consistency and correctness.
[0065] The computing framework for parallel processing can be selected according to actual conditions, and the embodiment of the present application does not specifically limit this. For example, the computing framework can be CUDA and OpenCL.
[0066] The image rendering method provided in the above embodiment obtains the corresponding shader source code to be compiled in response to an image rendering request; determines the target compilation optimization strategy of the shader source code based on the hardware environment information and rendering performance information of the terminal device; compiles and optimizes the shader source code according to the target compilation optimization strategy to obtain the target shader, and performs image rendering according to the target shader. The present application can accurately determine the target compilation optimization strategy of the shader source code through the hardware environment information and rendering performance information of the terminal device, and compiles and optimizes the shader source code according to the target compilation optimization strategy to obtain the target shader, and then performs image rendering through the target shader, which can efficiently generate rendered images.
[0067] Please refer to Figure 3 , Figure 3 A flowchart of another image rendering method provided in an embodiment of the present application.
[0068] like Figure 3 As shown, the image rendering method includes steps S201 to S205.
[0069] Step S201: In response to an image rendering request, obtain corresponding shader source code to be compiled.
[0070] In some embodiments, an image rendering request is received, and a corresponding shader source code to be compiled is obtained according to the image rendering request. The shader source code with compilation can be accurately obtained according to the image rendering request.
[0071] Step S202: Analyze the instructions in the shader source code to obtain instruction analysis results, and determine redundant instructions and / or invalid instructions in the shader source code based on the instruction analysis results.
[0072] The instructions in the shader source code are parsed to determine whether there are instructions with the same data stream; if there are at least two instructions with the same instruction data stream, the at least two instructions are determined to be redundant instructions; instructions that have no effect on the rendering result are determined to be invalid instructions.
[0073] Step S203: Merge the redundant instructions in the shader source code and / or delete invalid instructions in the shader source code to update the shader source code.
[0074] Merge redundant instructions in the shader source code to reduce the number of instructions, and / or delete invalid instructions in the shader source code to update the shader source code. By merging redundant instructions and / or deleting invalid instructions, the efficiency of image rendering can be effectively improved.
[0075] In some embodiments, the dependency relationships between instructions in the shader source code are determined based on the instruction analysis results; based on the dependency relationships, the instructions in the shader source code are reordered to obtain optimized shader source code. Reordering the instructions based on the dependency relationships can improve image rendering efficiency.
[0076] In some embodiments, whether there is a resource occupancy conflict between the instructions in the shader source code is determined based on the instruction analysis results. If there are at least two or more instructions with resource occupancy conflicts, the priorities between the conflicting instructions are obtained, and resource scheduling and allocation are performed from high to low according to the priority of each conflicting instruction.
[0077] Step S204: Determine a target compilation optimization strategy for the shader source code based on the hardware environment information and rendering performance information of the terminal device.
[0078] In some embodiments, a mapping relationship table between preset hardware environment information and compilation optimization strategies is obtained, and the compilation optimization strategy corresponding to the hardware environment information is queried from the mapping relationship table. The mapping relationship table is pre-established based on the hardware environment and the compilation optimization strategy. The mapping relationship table can be set according to actual conditions, and this embodiment of the present application does not specifically limit this. The mapping relationship table can accurately obtain the compilation optimization strategy corresponding to the hardware environment information.
[0079] In some embodiments, a mapping relationship table between preset rendering performance information and compilation optimization strategies is obtained, the compilation optimization strategy corresponding to the rendering performance information is matched from the mapping relationship table, and the compilation optimization strategy is determined as the target compilation optimization strategy. The mapping relationship table is pre-established based on the rendering performance information and the compilation optimization strategy. The mapping relationship table can be established according to actual conditions, and the embodiments of the present application do not specifically limit this. The target compilation optimization strategy can be accurately queried through the mapping relationship table.
[0080] Step S205 : compile and optimize the shader source code according to the target compilation optimization strategy to obtain a target shader, and perform image rendering according to the target shader.
[0081] In some embodiments, the target compilation optimization strategy is used to obtain the corresponding optimized source code, and the shader source code is updated according to the optimized source code to obtain the target shader source code; the target shader source code is compiled to obtain the target shader, and the image is rendered according to the target shader to obtain the target image. Compiling and optimizing the shader source code using the target compilation optimization strategy to obtain the target shader can effectively improve the efficiency of image rendering.
[0082] The image rendering method in the above embodiment obtains the corresponding shader source code to be compiled in response to an image rendering request; analyzes the instructions in the shader source code to obtain instruction analysis results, and determines redundant instructions and / or invalid instructions in the shader source code based on the instruction analysis results; merges the redundant instructions in the shader source code and / or deletes the invalid instructions in the shader source code to update the shader source code; determines the target compilation optimization strategy of the shader source code based on the hardware environment information and rendering performance information of the terminal device; compiles and optimizes the shader source code based on the target compilation optimization strategy to obtain a target shader, and performs image rendering based on the target shader. The present application can effectively improve image rendering efficiency by merging redundant instructions in the shader source code and / or deleting invalid instructions in the shader source code.
[0083] See also Figure 4 , Figure 4 A schematic block diagram of an image rendering device provided in an embodiment of the present application.
[0084] like Figure 4 As shown, the image rendering apparatus 300 includes an acquisition module 310, a determination module 320, and a generation module 330, wherein:
[0085] The acquisition module 310 is used to obtain the corresponding shader source code to be compiled in response to the image rendering request;
[0086] The determining module 320 is configured to determine a target compilation optimization strategy for the shader source code based on the hardware environment information and rendering performance information of the terminal device;
[0087] The generating module 330 is configured to compile and optimize the shader source code according to the target compilation optimization strategy to obtain a target shader, and perform image rendering according to the target shader.
[0088] In some embodiments, the determining module 320 is further configured to:
[0089] Acquire multiple compilation optimization strategies corresponding to the hardware environment information;
[0090] The compilation optimization strategy that matches the rendering performance information is selected from the multiple compilation optimization strategies as the target compilation optimization strategy.
[0091] In some embodiments, the generating module 330 is further configured to:
[0092] Image rendering is performed according to the target shader and texture data in a cache of the terminal device, the texture data being pre-loaded in the cache in response to the image rendering request.
[0093] In some embodiments, the image rendering device 300 is further configured to:
[0094] The usage frequency of the texture data in the cache is obtained, and the texture data in the cache whose usage frequency is lower than a preset usage frequency is moved to the main memory of the terminal device.
[0095] In some embodiments, the image rendering device 300 is further configured to:
[0096] Dividing the image rendering task corresponding to the target shader into a plurality of image rendering subtasks;
[0097] Multiple computing units in the terminal device are called to process the multiple image rendering subtasks in parallel.
[0098] It should be noted that those skilled in the art can clearly understand that for the convenience and brevity of description, the specific working process of the above-mentioned image rendering device can refer to the corresponding process in the aforementioned image rendering method embodiment, and will not be repeated here.
[0099] See also Figure 5 , Figure 5 A schematic block diagram of another image rendering device provided in an embodiment of the present application.
[0100] like Figure 5 As shown, the image rendering apparatus 400 includes an acquisition module 410, a generation module 420, a determination module 430, and an update module 440, wherein:
[0101] The acquisition module 410 is used to obtain the corresponding shader source code to be compiled in response to the image rendering request;
[0102] The generating module 420 is configured to analyze the instructions in the shader source code to obtain instruction analysis results;
[0103] The determining module 430 is configured to determine redundant instructions and / or invalid instructions in the shader source code according to the instruction analysis result;
[0104] The updating module 440 is configured to merge the redundant instructions in the shader source code and / or delete invalid instructions in the shader source code to update the shader source code;
[0105] The determination module 430 is configured to determine a target compilation optimization strategy for the shader source code based on the hardware environment information and rendering performance information of the terminal device;
[0106] The generating module 420 is further configured to compile and optimize the shader source code according to the target compilation optimization strategy to obtain a target shader, and perform image rendering according to the target shader.
[0107] In some embodiments, the image rendering device 400 is further configured to:
[0108] Determine the dependency relationship between the instructions in the shader source code according to the instruction analysis result;
[0109] According to the dependency relationship, the instructions in the shader source code are reordered to obtain optimized shader source code.
[0110] It should be noted that those skilled in the art can clearly understand that for the convenience and brevity of description, the specific working process of the above-mentioned image rendering device can refer to the corresponding process in the aforementioned image rendering method embodiment, and will not be repeated here.
[0111] See also Figure 6 , Figure 6 A schematic block diagram of the structure of a terminal device provided in an embodiment of the present application.
[0112] like Figure 6 As shown, the terminal device 500 includes a processor 502 and a memory 503 connected via a system bus 501, wherein the memory 503 may include a storage medium and an internal memory.
[0113] The storage medium may store a computer program including program instructions, which, when executed, may enable a processor to perform any one of the image rendering methods.
[0114] The processor 502 is used to provide computing and control capabilities to support the operation of the entire terminal device.
[0115] The internal memory provides an environment for the operation of the computer program in the storage medium. When the computer program is executed by the processor, the processor can execute any image rendering method.
[0116] Those skilled in the art will understand that Figure 6 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the terminal device to which the solution of the present application is applied. The specific terminal device may include more or fewer components than shown in the figure, or combine certain components, or have a different component arrangement.
[0117] It should be understood that the processor 502 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor.
[0118] In one embodiment, the processor 502 is configured to execute a computer program stored in a memory to implement the following steps:
[0119] In response to an image rendering request, obtaining corresponding shader source code to be compiled;
[0120] Determining a target compilation optimization strategy for the shader source code based on the hardware environment information and rendering performance information of the terminal device;
[0121] According to the target compilation optimization strategy, the shader source code is compiled and optimized to obtain a target shader, and image rendering is performed according to the target shader.
[0122] In one embodiment, before determining the target compilation optimization strategy of the shader source code according to the hardware environment and rendering performance of the terminal device, the processor 502 is further configured to implement:
[0123] Analyzing instructions in the shader source code to obtain instruction analysis results, and determining redundant instructions and / or invalid instructions in the shader source code based on the instruction analysis results;
[0124] The redundant instructions in the shader source code are merged and / or invalid instructions in the shader source code are deleted to update the shader source code.
[0125] In one embodiment, after implementing the merging of the redundant instructions in the shader source code and / or deleting the invalid instructions in the shader source code to update the shader source code, the processor 502 is further configured to implement:
[0126] Determine the dependency relationship between the instructions in the shader source code according to the instruction analysis result;
[0127] According to the dependency relationship, the instructions in the shader source code are reordered to obtain optimized shader source code.
[0128] In one embodiment, when determining the target compilation optimization strategy of the shader source code based on the hardware environment information and rendering performance information of the terminal device, the processor 502 is configured to implement:
[0129] Acquire multiple compilation optimization strategies corresponding to the hardware environment information;
[0130] The compilation optimization strategy that matches the rendering performance information is selected from the multiple compilation optimization strategies as the target compilation optimization strategy.
[0131] In one embodiment, when implementing the image rendering according to the target shader, the processor 502 is configured to implement:
[0132] Image rendering is performed according to the target shader and texture data in a cache of the terminal device, the texture data being pre-loaded in the cache in response to the image rendering request.
[0133] In one embodiment, the processor 502 is further configured to implement:
[0134] The usage frequency of the texture data in the cache is obtained, and the texture data in the cache whose usage frequency is lower than a preset usage frequency is moved to the main memory of the terminal device.
[0135] In one embodiment, when implementing the image rendering according to the target shader, the processor 502 is configured to implement:
[0136] Dividing the image rendering task corresponding to the target shader into a plurality of image rendering subtasks;
[0137] Multiple computing units in the terminal device are called to process the multiple image rendering subtasks in parallel.
[0138] It should be noted that those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the terminal device described above can refer to the corresponding process in the aforementioned image rendering method embodiment, and will not be repeated here.
[0139] An embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored. The computer program includes program instructions. The method implemented when the program instructions are executed can refer to the various embodiments of the image rendering method of the present application.
[0140] The computer-readable storage medium may be an internal storage unit of the terminal device described in the aforementioned embodiment, such as a hard disk or memory of the terminal device. The computer-readable storage medium may be non-volatile or volatile. The computer-readable storage medium may also be an external storage device of the terminal device, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash memory card, etc., equipped on the terminal device.
[0141] It should be understood that the terms used in this specification are only for the purpose of describing specific embodiments and are not intended to limit the present application. As used in this specification, the singular forms "a", "an", and "the" are intended to include the plural forms unless the context clearly indicates otherwise.
[0142] It should also be understood that the term "and / or" used in this specification refers to any combination of one or more of the associated listed items and all possible combinations, including these combinations. It should be noted that, in this article, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or system that includes a series of elements includes not only those elements, but also other elements that are not explicitly listed, or also includes elements that are inherent to such process, method, article or system. In the absence of further restrictions, an element defined by the sentence "including a..." does not exclude the presence of other identical elements in the process, method, article or system that includes the element.
[0143] The serial numbers of the embodiments of the present application are for descriptive purposes only and do not represent the merits of the embodiments. The above description is only a specific embodiment of the present application, but the scope of protection of the present application is not limited thereto. Any person skilled in the art can easily think of various equivalent modifications or replacements within the technical scope disclosed in the present application, and these modifications or replacements should be included in the scope of protection of the present application.
Claims
1. An image rendering method, characterized in that: Applied to a terminal device, the method includes: In response to an image rendering request, obtaining corresponding shader source code to be compiled; Determining a target compilation optimization strategy for the shader source code based on the hardware environment information and rendering performance information of the terminal device; According to the target compilation optimization strategy, the shader source code is compiled and optimized to obtain a target shader, and image rendering is performed according to the target shader.
2. The image rendering method according to claim 1, wherein: Before determining the target compilation optimization strategy of the shader source code according to the hardware environment and rendering performance of the terminal device, the method further includes: Analyzing instructions in the shader source code to obtain instruction analysis results, and determining redundant instructions and / or invalid instructions in the shader source code based on the instruction analysis results; The redundant instructions in the shader source code are merged and / or invalid instructions in the shader source code are deleted to update the shader source code.
3. The image rendering method according to claim 2, wherein: After merging the redundant instructions in the shader source code and / or deleting invalid instructions in the shader source code to update the shader source code, the method further includes: Determine the dependency relationship between the instructions in the shader source code according to the instruction analysis result; According to the dependency relationship, the instructions in the shader source code are reordered to obtain optimized shader source code.
4. The image rendering method according to claim 1, wherein: Determining a target compilation optimization strategy for the shader source code based on the hardware environment information and rendering performance information of the terminal device includes: Acquire multiple compilation optimization strategies corresponding to the hardware environment information; The compilation optimization strategy that matches the rendering performance information is selected from the multiple compilation optimization strategies as the target compilation optimization strategy.
5. The image rendering method according to claim 1, wherein: The performing image rendering according to the target shader includes: Image rendering is performed according to the target shader and texture data in a cache of the terminal device, the texture data being pre-loaded in the cache in response to the image rendering request.
6. The image rendering method according to claim 1, wherein: The method further comprises: The usage frequency of the texture data in the cache is obtained, and the texture data in the cache whose usage frequency is lower than a preset usage frequency is moved to the main memory of the terminal device.
7. The image rendering method according to claim 1, wherein: The performing image rendering according to the target shader includes: Dividing the image rendering task corresponding to the target shader into a plurality of image rendering subtasks; Multiple computing units in the terminal device are called to process the multiple image rendering subtasks in parallel.
8. An image rendering device, characterized in that: The image rendering device includes an acquisition module, a determination module and a generation module, wherein: The acquisition module is used to obtain the corresponding shader source code to be compiled in response to the image rendering request; The determining module is used to determine the target compilation optimization strategy of the shader source code according to the hardware environment information and rendering performance information of the terminal device; The generation module is used to compile and optimize the shader source code according to the target compilation optimization strategy to obtain a target shader, and perform image rendering according to the target shader.
9. A terminal device, characterized in that: The terminal device includes a processor, a memory, and a computer program stored in the memory and executable by the processor, wherein when the computer program is executed by the processor, the steps of the image rendering method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, wherein when the computer program is executed by a processor, the steps of the image rendering method according to any one of claims 1 to 7 are implemented.
Citation Information
Cited By
Shader adjusting method and device, computer equipment and storage medium
CN120953463A
Shader adjustment methods, apparatus, computer equipment, and storage media
CN120953463B