Compilation method, readable storage medium, program product, and electronic device
By using different compilation methods to compile shaders based on their complexity and the complexity of the rendered content, the problem of performance and resource waste in electronic devices under a fixed compilation method is solved, achieving a balance between performance and power consumption.
Patent Information
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- HONOR DEVICE CO LTD
- Filing Date
- 2025-12-01
- Publication Date
- 2026-07-30
AI Technical Summary
When electronic devices use a fixed compilation method for shaders, it can lead to performance and resource waste or stuttering issues.
Depending on the complexity of the shader's source code and the complexity of the content to be rendered, different compilation methods are used, including direct compilation and optimized compilation, to avoid resource waste and lag.
It achieves a balance between the performance and power consumption of electronic devices, avoids the over-optimization of simple shaders and the under-optimization of complex shaders, and improves display performance.
Smart Images

Figure CN2025138960_30072026_PF_FP_ABST
Abstract
Description
A compilation method, a readable storage medium, a program product, and an electronic device.
[0001] This application claims priority to Chinese Patent Application No. 202510107929.2, filed on January 21, 2025, entitled "A compilation method, a readable storage medium, a program product and an electronic device", the entire contents of which are incorporated herein by reference. Technical Field
[0002] This application relates to the field of image processing technology, and more particularly to a compilation method, a readable storage medium, a program product, and an electronic device. Background Technology
[0003] A shader is a program used to render the interface that an application needs to display. In generating the interface, electronic devices typically first compile the application's shader from source code (e.g., code written in a high-level language such as High Level Shading Language (HLSL), Open Graphics Library Shading Language (GLSL), or C for Graphics (CG)) into code that the graphics processing unit (GPU) can recognize and run (e.g., code in an intermediate language such as DirectX Intermediate Language (DXIL) or Standard Portable Intermediate Representation-V (SPIR-V), hereinafter referred to as object code). Then, the GPU runs the shader's object code to render the interface the application needs to display.
[0004] However, electronic devices typically use a fixed compilation method to compile shaders, which affects the performance of electronic devices. Summary of the Invention
[0005] This application provides a compilation method, a readable storage medium, a program product, and an electronic device.
[0006] In a first aspect, a compilation method is provided for use in an electronic device. The method includes: detecting a compilation instruction for compiling the source code of a shader of a first application; compiling the source code of the shader using a first compilation method to obtain a first compilation result if a first condition is met; and compiling the source code of the shader using a second compilation method to obtain a second compilation result if the first condition is not met. The compilation complexity of the first compilation method is less than that of the second compilation method, and the factors determining the compilation complexity include at least one of the following: compilation time, computational resources used in compilation, and the number of optimization methods used in compilation.
[0007] Based on the above method, electronic devices can compile the source code of the shader for the first application using compilation methods with different levels of complexity, depending on whether the first condition is met. This avoids over-optimization of shaders with simple source code or simple rendered content (e.g., those meeting the first condition), which would lead to resource waste, while also avoiding insufficient optimization of shaders with complex source code or complex rendered content (e.g., those not meeting the first condition), which could cause stuttering. This achieves a balance between performance and power consumption in electronic devices.
[0008] In one possible implementation of the first aspect above, the first condition includes at least one of the following conditions: the first application is a preset application or a preset category application, the complexity of the shader's source code is less than a first threshold, the content to be rendered by the first application is a webpage, and the complexity of the content to be rendered by the shader is less than a second threshold.
[0009] In this implementation, if the first application is a preset application or a preset category of application, the complexity of the shader's source code is less than a first threshold, the content to be rendered by the first application is a webpage, and the complexity of the content to be rendered by the shader is less than one or more of the second thresholds, the electronic device can determine that the source code of the shader of the first application is simple or the content to be rendered is simple (simple scenario).
[0010] In one possible implementation of the first aspect above, the first condition further includes at least one of the following conditions: the frame rate of the image displayed by the first application is greater than a third threshold; the rendering time of the image of the first application is less than a fourth threshold.
[0011] In this implementation, besides the first application's shader source code being simple or the content to be rendered being simple, the electronic device must also meet the following conditions: the frame rate of the first application's displayed image must be greater than a third threshold and / or the rendering time of the first application's image must be less than a fourth threshold before the electronic device adopts the first compilation method for the first application's shader source code. This avoids the first application's interface stuttering due to insufficient shader source code optimization, preventing situations where the frame rate of the first application's displayed image is too low or the rendering time of the first application's image is too long.
[0012] In one possible implementation of the first aspect above, the complexity of the content to be rendered by the shader is determined based on one or more of the number of objects, the number of light sources, and the complexity of materials in the content to be rendered by the shader.
[0013] In one possible implementation of the first aspect above, the complexity of the source code of the shader is determined based on one or more of the following: the number of instructions in the source code, the number of branch instructions in the source code, the number of loop instructions in the source code, and the number of times the texture is sampled in the source code.
[0014] In one possible implementation of the first aspect above, the first compilation method is direct compilation and the second compilation method is optimized compilation; or, the first compilation method and the second compilation method are optimized compilation, and the number of optimization methods corresponding to optimized compilation in the first compilation method is less than the number of optimization methods corresponding to optimized compilation in the second compilation method.
[0015] In one possible implementation of the first aspect above, the electronic device includes a graphics processor, and: the compilation of the shader source code using the first compilation method to obtain a first compilation result includes: calling the graphics processor driver to compile the shader source code based on the first compilation parameters corresponding to the first compilation method to obtain the first compilation result; the compilation of the shader source code using the second compilation method to obtain a second compilation result includes: calling the graphics processor driver to compile the shader source code based on the second compilation parameters corresponding to the second compilation method to obtain the second compilation result.
[0016] In this implementation, the electronic device uses the compilation parameters corresponding to the first and second compilation methods respectively to compile the shader source code through the graphics processor driver, using the first and second compilation methods respectively.
[0017] In one possible implementation of the first aspect above, the second compilation method is determined based on at least one of the following information: the complexity of the shader's source code, the complexity of the content to be rendered by the shader; and, the greater the complexity of the shader's source code, the greater the compilation complexity of the second compilation method, and / or, the greater the complexity of the content to be rendered by the shader, the greater the compilation complexity of the second compilation method.
[0018] In this implementation, in complex scenarios (where the first condition is not met), the electronic device can use different compilation complexities to compile the shader's source code based on the complexity of the shader's source code and the complexity of the content the shader is to render, resulting in a second compilation result with different runtime efficiencies. This balances performance and display quality.
[0019] In one possible implementation of the first aspect above, the method further includes: when the source code of the shader is compiled using a first compilation method, rendering the display content of the first application based on the first compilation result; during the rendering of the display content of the first application based on the first compilation result, detecting that the frame rate of the image displayed by the first application is less than a fifth threshold and / or the rendering duration of the image of the first application is greater than a sixth threshold; recompiling the source code of the shader using a third compilation method, wherein the compilation complexity of the third compilation method is greater than the compilation complexity of the first compilation method.
[0020] In this implementation, when the shader source code is compiled using the first compilation method, the electronic device can, during the rendering process of the first application's display content based on the first compilation result, recompile the shader source code using a third compilation method with higher compilation complexity (e.g., employing more optimization techniques) if the first application's display performance is poor (low frame rate or excessive rendering time). Then, the electronic device can render the first application's display content based on the recompiled third compilation result. This improves the first application's display performance (increased frame rate or reduced rendering time), preventing stuttering.
[0021] In a second aspect, an electronic device is provided, comprising: one or more processors; one or more memories; the one or more memories storing one or more computer programs, the one or more computer programs including instructions that, when executed by the one or more processors, cause the electronic device to perform a compilation method as provided in any of the implementations of the first aspect above.
[0022] Thirdly, a computer-readable storage medium is provided, which stores computer-executable program instructions that, when executed on a computer, cause the computer to perform a compilation method provided by any of the implementations of the first aspect described above.
[0023] Fourthly, a computer program product is provided, which includes computer program code, such that when the computer program code is run on a computer, the computer executes a compilation method provided by any of the implementations in the first aspect described above.
[0024] It should be noted that the beneficial effects of the second to fourth aspects mentioned above can be referred to the description of the first aspect, and will not be repeated here. Attached Figure Description
[0025] Figure 1 illustrates a process for generating an image according to some embodiments of this application.
[0026] Figure 2 illustrates a flowchart of a compilation method according to some embodiments of this application.
[0027] Figure 3 illustrates a schematic diagram of a software architecture according to some embodiments of this application.
[0028] Figure 4 illustrates a process diagram of an image processing method according to some embodiments of this application.
[0029] Figure 5 shows a schematic diagram of the structure of an electronic device according to some embodiments of this application. Detailed Implementation
[0030] The embodiments of this application include, but are not limited to, compilation methods, readable storage media, program products, and terminal devices.
[0031] To facilitate understanding, the terminology used in this application will be introduced first.
[0032] (1) Shader
[0033] A shader is a program used to render the interface that an application needs to display. Shaders typically include vertex shaders, fragment shaders, and geometry shaders.
[0034] In the process of rendering the interface to be displayed by the application message program based on shaders: first, the application configures the shaders as source code, then the GPU driver compiles the shader source code into target code that the GPU can recognize or run, and finally the GPU renders the application interface by running the shader target code.
[0035] It should be noted that the way shaders are classified or named may differ depending on the GPU, graphics application programming interface, or graphics library. This application does not limit this in the embodiments.
[0036] It should be noted that the more complex the shader's source code, the longer it takes to compile the shader's source code.
[0037] (2) Direct compilation
[0038] Transcribing compilation refers to a compilation method that does not optimize the target code during the compilation of shader source code. Transcribing compilation of shader source code is fast and efficient, but the execution efficiency of the resulting target code is relatively low.
[0039] (3) Optimize compilation
[0040] Optimized compilation refers to a compilation method that optimizes the shader during the compilation process from its source code to target code, using one or more optimization techniques. These optimization techniques may include, but are not limited to: reducing redundant instructions in the shader's source code, adjusting GPU resources allocated to the shader based on its source code (such as GPU storage and computing resources), pre-compiling the shader source code, reducing the number of shaders, reducing texture sampling, and using low-precision data types instead of high-precision data types.
[0041] It should be noted that the more optimization methods are used in optimization compilation, the longer the compilation time required for optimization compilation, and the higher the execution efficiency of the compilation result obtained by optimization compilation.
[0042] It should be noted that the compilation time required to compile the shader source code through optimized compilation is longer than the compilation time required to compile the shader source code through direct compilation.
[0043] It should be noted that the optimization methods provided may differ for different types of GPUs or different GPU drivers. This application does not limit the specific optimization methods for optimizing the source code of shaders during the optimization compilation.
[0044] The technical solution of this application is described below with reference to the accompanying drawings.
[0045] It should be noted that the compilation method provided in this application can be applied to any electronic device, including but not limited to servers and terminal devices. For example, a terminal device can also be called a terminal, user equipment (UE), mobile station (MS), mobile terminal (MT), etc. Terminal devices can be mobile phones, smart TVs, wearable devices, tablets, desktop computers, laptops, computers with wireless transceiver capabilities, virtual reality (VR) terminal devices, augmented reality (AR) terminal devices, wireless terminals in industrial control, wireless terminals in self-driving, wireless terminals in remote medical surgery, wireless terminals in smart grids, wireless terminals in transportation safety, wireless terminals in smart cities, wireless terminals in smart homes, and so on. This application does not limit the electronic devices to which the compilation method is applicable.
[0046] To make it easier to understand, we will first introduce the process of how electronic devices generate images.
[0047] For example, FIG1 illustrates a schematic diagram of an image generation process according to some embodiments of the present application.
[0048] As shown in Figure 1, during the process of generating an application image on an electronic device, the CPU compiles the source code of the application's shaders into object code using a fixed compilation method. The CPU then sends the object code to the GPU. Finally, the GPU runs the object code to render the application's image.
[0049] It should be noted that the use of a CPU to actually compile the shader source code in the embodiments of this application is only an example. In other embodiments, any other processing unit may also be used to actually compile the shader source code, which is not limited here.
[0050] As described in the background section, electronic devices typically use a fixed compilation method (such as direct compilation or optimized compilation with a fixed optimization method) to compile the source code of shaders, which affects the performance of electronic devices.
[0051] For example, in cases where the compilation method is optimized compilation, if the shader source code is relatively simple or the content of the interface to be rendered by the shader is relatively simple, compiling the shader source code using optimized compilation will consume a longer compilation time. However, for cases with low complexity or simple content in the interface to be rendered by the shader, the increased time due to optimized compilation compared to direct compilation may be less than the reduced runtime of the optimized target code compared to the runtime of the directly compiled target code. Thus, using optimized compilation may actually increase the total compilation and execution time of the shader, resulting in a waste of computational resources.
[0052] For example, in cases where the compilation method is direct compilation, direct compilation can reduce compilation time when the shader source code is complex or the content of the interface to be rendered by the shader is complex. However, for cases with high complexity or complex content in the interface to be rendered by the shader, the target code obtained by direct compilation has lower execution efficiency and requires a longer runtime, which may cause the GPU to be unable to render the application interface in time, resulting in lag on the display of electronic devices.
[0053] In view of this, embodiments of this application provide a method for compiling shaders. In this method, after an electronic device detects a compilation request to compile the shaders of a first application, it can use different compilation methods to compile the shaders of the first application based on the complexity of the source code of the shaders of the first application and / or the complexity of the content in the interface to be rendered by the first application.
[0054] Specifically, when the source code of the shaders in the first application is relatively simple, and / or the interface to be rendered by the first application is relatively simple, the electronic device can use a first compilation method with lower compilation complexity (e.g., direct compilation, or optimized compilation with fewer optimization methods) to compile the source code of the shaders in the first application. When the source code of the shaders in the first application is relatively simple, and / or the interface to be rendered by the first application is relatively simple, the electronic device can use a second optimized compilation method with higher compilation complexity (e.g., optimized compilation, or optimized compilation with more optimization methods) to compile the source code of the shaders in the first application.
[0055] Based on the above approach, it is possible to avoid compiling the source code of the first application's shaders using a more complex compilation method when the source code of the first application's shaders is relatively simple, and / or the content of the interface to be rendered by the first application is relatively simple, thus avoiding resource waste. Furthermore, based on the above approach, it is also possible to avoid causing UI lag in the first application when the source code of the first application's shaders is highly complex, and / or the interface to be rendered by the first application is highly complex, without optimizing the shaders (or with insufficient optimization).
[0056] In some embodiments, the complexity of the shader's source code can be determined based on one or more of the following: the number of instructions, the number of branch instructions, the number of loop instructions, and the number of texture samples. The electronic device can compile the shader's source code for the first application using a first compilation method when the complexity of the shader's source code is less than a first threshold (equivalent to low complexity); and compile the shader's source code for the first application using a second compilation method when the complexity of the shader's source code is greater than or equal to the first threshold (equivalent to high complexity). Specifically, the greater the number of instructions in the shader's source code, the greater the complexity of the shader's source code; the greater the number of branch instructions in the shader's source code, the greater the complexity of the shader's source code; the greater the number of loop instructions in the shader's source code, the greater the complexity of the shader's source code; and the greater the number of texture samples in the shader's source code, the greater the complexity of the shader's source code.
[0057] For example, the complexity of a shader's source code can be determined based on the number of instructions, branch instructions, loop instructions, and texture sampling times in the shader's source code, using methods such as weighted summation, weighted average, and root mean square. For instance, taking weighted summation as an example, the complexity of the shader's source code can be expressed as follows (1). C S = a×N1+b×N2+c×N3+d×N4 (1)
[0058] In formula (1), C S The values represent the complexity of the shader source code; N1, N2, N3, and N4 represent the number of instructions, branch instructions, loop instructions, and texture sampling times in the shader source code, respectively; a, b, c, and d represent the weighting coefficients corresponding to the number of instructions, branch instructions, loop instructions, and texture sampling times in the shader source code, respectively. It should be noted that a, b, c, and d can be empirical or experimental values.
[0059] In some embodiments, for the weighting coefficients a, b, c, and d in formula (1), when the influence of the factors corresponding to one or more weighting coefficients (the number of instructions, the number of branch instructions, the number of loop instructions, and the number of texture samples) on the complexity of the shader's source code is not considered, the one or more weighting coefficients can be 0. For example, when evaluating the complexity of the shader's source code solely by the number of instructions in the shader's source code, b, c, and d can be 0; when evaluating the complexity of the shader's source code solely by the number of instructions and the number of branch instructions in the shader's source code, c and d can be 0; when evaluating the complexity of the shader's source code solely by the number of branch instructions and the number of loop instructions in the shader's source code, a and d can be 0.
[0060] It should be noted that in other embodiments, the complexity of the shader's source code can also be determined in other ways, which are not limited here.
[0061] In some embodiments, the complexity of the content to be rendered by the shader can be determined based on one or more of the number of objects, the number of light sources, and the complexity of materials in the content to be rendered. The electronic device can compile the source code of the shader for the first application using a first compilation method when the complexity of the content to be rendered is less than a second threshold (equivalent to a lower complexity of the content to be rendered); and compile the source code of the shader for the first application using a second compilation method when the complexity of the content to be rendered is greater than or equal to the first threshold (equivalent to a higher complexity of the source code of the shader). Specifically, the greater the number of objects in the content to be rendered, the greater the complexity of the content to be rendered; the greater the number of light sources in the content to be rendered, the greater the complexity of the content to be rendered; and the greater the complexity of materials (e.g., color, texture, roughness, etc.) in the content to be rendered, the greater the complexity of the content to be rendered.
[0062] For example, the complexity of the content to be rendered by the shader can be determined based on the number of objects, the number of light sources, and the complexity of materials in the content to be rendered by the shader, using methods such as weighted summation, weighted average, and root mean square. For instance, taking weighted summation as an example, the complexity of the content to be rendered by the shader can be expressed as the following formula (2). C U =e×N4+f×N5+g×N6 (2)
[0063] In formula (2), C UThe shader represents the complexity of the content to be rendered; N4, N5, and N6 represent the number of objects, the number of light sources, and the complexity of materials in the content to be rendered, respectively; e, f, and g represent the weighting coefficients corresponding to the number of objects, the number of light sources, and the complexity of materials in the content to be rendered, respectively. It should be noted that e, f, and g can be empirical or experimental values.
[0064] In some embodiments, for the weighting coefficients e, f, and g in formula (2), when the influence of the factors corresponding to one or more weighting coefficients (the number of objects, the number of light sources, and the complexity of materials in the content to be rendered by the shader) on the complexity of the content to be rendered by the shader is not considered, the one or more weighting coefficients can be 0. For example, when the complexity of the content to be rendered by the shader is evaluated only by the number of objects in the content to be rendered by the shader, f and g can be 0; when the complexity of the content to be rendered by the shader is evaluated only by the number of physical objects and the number of light sources in the content to be rendered by the shader, g can be 0.
[0065] In some embodiments, the material complexity of the content to be rendered by the shader can be determined based on factors such as the number of colors, the number of textures, and the surface roughness of the object to be rendered. Generally, a greater number of colors and textures results in greater material complexity; a higher surface roughness of the object, more light scattered from the surface, and more scattered light to be processed also contribute to greater material complexity. Optionally, in other embodiments, the material complexity of the content to be rendered can be determined in other ways, which are not limited here.
[0066] It should be noted that in other embodiments, the complexity of the content to be rendered by the shader can also be determined in other ways, which are not limited here. For example, if the GPU driver or graphics library provides an algorithm or function to calculate the complexity of the content to be rendered by the shader, the electronic device can determine the complexity of the content to be rendered by the shader by calling that algorithm or function.
[0067] In some embodiments, certain applications typically have low rendering performance requirements for the display interface (e.g., low resolution, low frame rate). Not optimizing the source code of the shaders for these applications will not cause the interface to lag. When the first application is this specific application, the electronic device can directly compile the source code of the shaders for the first application using the first compilation method, without needing to determine the complexity of the shader source code or the complexity of the content to be rendered, thus further saving resources.
[0068] For example, the application may be one or more pre-defined applications (hereinafter referred to as preset applications), or it may be one or more pre-defined categories of applications (hereinafter referred to as preset category applications). The electronic device may directly compile the source code of the shader of the first application using the first compilation method if the first application is a preset application or a preset category application.
[0069] In some embodiments, the preset application may be a browser or other applications. Optionally, different preset applications may be set in different electronic devices, and the specific name of the preset application is not limited in the embodiments of this application.
[0070] In some embodiments, the preset categories of applications can be browser applications, shopping applications, mini-program applications, or applications using a webview. Optionally, the preset categories may also include other applications, which are not limited here.
[0071] In some embodiments, since the content of a webpage is relatively simple or the rendering performance required by the webpage (e.g., rendering frame rate) is low, not optimizing the compilation of the shaders used to render the webpage usually does not affect the display effect of the webpage. Based on this, when the content currently displayed by the first application is a webpage (equivalent to the content that the first application wants to render through the shaders also being a webpage), the electronic device can also directly compile the source code of the shaders of the first application using the first compilation method.
[0072] In some embodiments, when the content displayed by the first application is a webpage, the electronic device may also take into account the complexity of the webpage (the content that the first application wants to render through the shader), and use a first compilation method to compile the source code of the shader of the first application when the complexity is less than a second threshold, or use a second compilation method to compile the source code of the shader of the first application when the complexity is greater than or equal to the second threshold.
[0073] In some embodiments, compilation complexity can be determined based on the compilation time of the compilation method, the computational resources consumed by the compilation method, and the number of optimization methods used during the compilation of the shader source code. For example, the more optimization methods used during the compilation of the shader source code, the greater the compilation complexity. Similarly, the more computational resources consumed during the compilation of the shader source code, the greater the compilation complexity. Furthermore, the longer the compilation time required to compile the shader source code, the greater the compilation complexity.
[0074] It should be noted that in other embodiments, the compilation complexity can also be determined in other ways, which are not limited here.
[0075] In some embodiments, the higher the compilation complexity of the compilation method, the higher the running efficiency of the compiled target code, and the shorter the rendering time required to render the same image.
[0076] The technical solution of this application will now be described with reference to Figure 2.
[0077] For example, FIG2 illustrates a flowchart of a compilation method according to some embodiments of this application. As shown in FIG2, the method includes:
[0078] S201, A compilation instruction was detected to compile the source code of the shader for the first application.
[0079] In some embodiments, when the first application starts or during the generation of an image of the first application, the electronic device can detect compilation instructions to compile the source code of the shader of the first application. For example, after the process or thread of the first application (or other threads or processes in the electronic device used to generate the source code of the shader) generates the source code of the shader based on the image to be drawn and rendered, the electronic device can detect instructions to compile the source code of the shader of the first application, triggering the compilation method provided in the embodiments of this application.
[0080] In other embodiments, the electronic device may also detect instructions to compile the source code of the shader for the first application in other circumstances, which is not limited here.
[0081] In some embodiments, the first application may have one or more shaders, and a compiler directive indicates that the source code to be compiled may be at least one shader. The at least one shader may be some or all of the shaders corresponding to the first application.
[0082] In some embodiments, the compilation directive indicates what to compile, which may be the source code of some or all of the shaders of the entire image corresponding to the first application in generating a frame of the display interface.
[0083] It should be noted that the shader corresponding to the first application may include one or more of the vertex shader, fragment shader, and geometry shader, or other forms of shaders, which are not limited here.
[0084] In some embodiments, after detecting the compilation instructions, the electronic device can determine whether a first condition is met, and based on the result of the determination, compile the source code of the shader of the first application using different compilation methods. For example, if the first condition is met, the electronic device can execute S202 to compile the source code of the shader using the first compilation method; if the first condition is not met, the electronic device can execute S203 to compile the source code of the shader using the second compilation method, wherein the compilation complexity of the first compilation method is less than the compilation complexity of the second compilation method.
[0085] S202, if the first condition is met, the source code of the shader of the first application is compiled using the first compilation method to obtain the first compilation result.
[0086] Under the condition that the first condition is met, the electronic device can use the first compilation method to compile the source code of the shader of the first application to obtain the first compilation result. The first compilation result can be target code that the GPU of the electronic device can recognize or run.
[0087] In some embodiments, the first condition includes at least one of the following: the first application is a preset application or an application of a preset category; the complexity of the shader's source code is less than a first threshold; the content to be rendered by the first application is a webpage; and the complexity of the content to be rendered by the shader is less than a second threshold. It should be noted that satisfying the above first condition indicates that the source code of the shader in the first application is relatively low in complexity, or the content to be rendered by the first application is low in complexity, or the first application has low requirements for rendering performance. Therefore, compiling the source code of the shader in the first application using the first compilation method (e.g., direct compilation or optimized compilation using fewer optimization methods) will speed up the compilation process, save compilation resources, and will not cause the interface of the first application to lag.
[0088] In some embodiments, the performance of the electronic device can also be taken into account. For example, the first condition may further include at least one of the following conditions: the frame rate of the displayed image of the first application is greater than a third threshold, and the rendering time of the displayed image of the first application is less than a fourth threshold. That is, satisfying the first condition may also be: satisfying at least one of the following conditions: the first application is a preset application or a preset category of application, the complexity of the shader's source code is less than the first threshold, the content to be rendered by the first application is a webpage, and the complexity of the content to be rendered by the shader is less than a second threshold, and satisfying at least one of the following conditions: the frame rate of the displayed image of the first application is greater than the third threshold, and the rendering time of the displayed image of the first application is less than the fourth threshold.
[0089] In some embodiments, the frame rate at which the first application displays an image can be the frame rate at which the first application renders its own image. For example, the frame rate at which a thread in the first application that renders an image (e.g., the rendering thread hereinafter) renders the image. Exemplarily, the rendering duration can be the average frame rate at which the first application renders images over a period of time (e.g., the number of images rendered over that period of time divided by the duration of that period of time), or the average rendering duration of one or more consecutive frames.
[0090] In some embodiments, the rendering time of the displayed image of the first application can be the rendering time of the first application rendering its own image. For example, the rendering time of the image rendered by the thread used to render the image in the first application (e.g., the rendering thread hereinafter). Exemplarily, the rendering time can be the average time of the first application rendering images over a period of time (e.g., the duration of the period of time divided by the number of images rendered by the first application over the period of time), or the average rendering time of one or more consecutive frames.
[0091] It should be noted that if the frame rate of the first application's displayed image is greater than the third threshold, it indicates that the first application's displayed image is not experiencing stuttering. Compiling the source code of the first application's shaders using the first compilation method, while limiting the frame rate of the first application's displayed image to be greater than the third threshold, will not cause the GPU to fail to render the first application's image in a timely manner by running the first compilation result. However, if the frame rate of the first application's displayed image is less than or equal to the third threshold, it indicates that the first application's displayed image is experiencing stuttering, and therefore the second compilation method is used to compile the source code of the first application's shaders.
[0092] It should be noted that if the rendering time of the first application's displayed image is less than the fourth threshold, it indicates that the rendering time of the first application's displayed image is short and no stuttering occurs. Compiling the source code of the first application's shaders using the first compilation method, while limiting the rendering time of the first application's displayed image to less than the fourth threshold, will not cause the GPU to fail to render the first application's image in a timely manner based on the first compilation result. However, if the rendering time of the first application's displayed image is greater than or equal to the fourth threshold, it indicates that stuttering may occur in the first application's displayed image; therefore, the source code of the first application's shaders is compiled using the second compilation method.
[0093] In some embodiments, the compilation complexity of the shader source code using the first compilation method is less than that using the second compilation method. The compilation complexity can be determined by the number of optimization methods applied to the shader source code during the compilation process.
[0094] For example, if the first compilation method is direct compilation, the second compilation method can be optimized compilation that uses one or more optimization methods to optimize the source code of the shader.
[0095] For example, when both the first and second compilation methods are optimized compilations, the number of optimization methods used by the second compilation method to optimize the shader source code can be greater than the number of optimization methods used by the first compilation method to optimize the shader source code.
[0096] In some embodiments, after obtaining the first compilation result, the electronic device can use the GPU to run the first compilation result to render the display content of the first application. In some embodiments, during the rendering process of the first application's display content using the GPU to run the first compilation result, the electronic device can detect the display performance of the first application (e.g., the frame rate of the images displayed by the first application, the rendering time of the images in the first application, etc.). If the electronic device detects that the display performance of the first application is low (indicating that the first application may experience lag), the electronic device can recompile the source code of the shaders of the first application based on a third compilation method to obtain a third compilation result. Then, the electronic device can use the GPU to run the third compilation result to render the display content of the first application. The compilation complexity of the third compilation method is greater than that of the first compilation method.
[0097] Based on the above approach, during the rendering of the image of the first application based on the first compilation result, if it is detected that the first application does not meet the first condition (e.g., the complexity of the content to be rendered increases to greater than or equal to the second threshold, and / or the frame rate of the image displayed by the first application decreases to less than or equal to the third threshold, and / or the rendering time of the image of the first application increases to greater than or equal to the fourth threshold), the shaders of the first application can be recompiled using a third compilation method with higher compilation complexity and higher execution efficiency of the compiled target code. In this way, the GPU can render the image of the first application using the more efficient third compilation result, avoiding stuttering caused by continuing to render the image of the first application using the first compilation result.
[0098] In some embodiments, during the rendering of an image of a first application based on a first compilation result, if it is detected that the frame rate of the image displayed by the first application is less than a fifth threshold and / or the rendering duration of the image of the first application is greater than a sixth threshold, the electronic device may recompile the shader of the first application using a third compilation method, which has higher compilation complexity and higher execution efficiency of the compiled target code. The fifth threshold may be the same as or different from the third threshold, and the sixth threshold may be the same as or different from the fourth threshold.
[0099] In some embodiments, when the first compilation method is direct compilation, the third compilation method can be optimized compilation. When both the first and third compilation methods are optimized compilations, the number of optimization methods used by the third compilation method to optimize the shader source code can be greater than the number of optimization methods used by the first compilation method to optimize the shader source code.
[0100] In some embodiments, the second compilation method and the third compilation method may be different, or the second compilation method and the third compilation method may be the same, which is not limited here.
[0101] S203, if the first condition is not met, the second compilation method is used to compile the shader source code to obtain the second compilation result.
[0102] In some embodiments, if the first condition is not met, the electronic device may use a second compilation method to compile the shader source code to obtain a second compilation result. The second compilation result may be target code that the GPU of the electronic device can recognize or run.
[0103] In some embodiments, the second compilation method may be determined based on at least one of the following: the complexity of the shader's source code, and the complexity of the content to be rendered by the shader. For example, the greater the complexity of the shader's source code and the greater the compilation complexity of the second compilation method (e.g., the greater the number of optimization methods employed), the higher the execution efficiency of the resulting second compilation; and / or, the greater the complexity of the content to be rendered by the shader and the greater the compilation complexity of the second compilation method (e.g., the greater the number of optimization methods employed), the higher the execution efficiency of the resulting second compilation. Based on this, if the first condition is not met, the electronic device may adjust the optimization method during the compilation process of the shader's source code for the first application based on the complexity of the shader's source code and / or the complexity of the content to be rendered by the shader.
[0104] In some embodiments, the compilation complexity of the first compilation method is less than that of the second compilation method. That is, the GPU is more efficient at rendering the image of the first application using the second compilation result than at rendering the image of the first application using the first compilation result.
[0105] In some embodiments, after obtaining the second compilation result, the GPU of the electronic device can render the image of the first application by running the second compilation result.
[0106] It should be noted that compiling the shader source code using the first, second, and third compilation methods can be implemented by the CPU of an electronic device, or by other processors such as coprocessors or neural network processors. This application does not specifically limit the hardware used for compilation.
[0107] Based on the above approach, electronic devices can compile the source code of the shader for the first application using compilation methods with different compilation complexities and different execution efficiencies of the resulting target code, depending on whether the first condition is met. This avoids both over-compiling shaders with simple source code or relatively simple rendering content, thus preventing resource waste, and under-optimizing shaders with complex source code or relatively complex rendering content, which could lead to UI lag, thereby improving the image processing performance of electronic devices.
[0108] The technical solution of this application will be introduced below in conjunction with the software architecture of electronic devices.
[0109] For example, FIG3 illustrates a schematic diagram of a software architecture according to some embodiments of the present application.
[0110] As shown in Figure 3, the software architecture of an electronic device can adopt a layered architecture, which divides the software into several layers, each with a clear role and division of labor. Layers communicate with each other through software interfaces. In some embodiments, the software architecture of an electronic device may include an application layer, a framework layer, and a kernel layer.
[0111] The application layer can include a series of application packages, such as the first application mentioned above. The application layer can run applications by calling the application programming interface (API) provided by the framework layer.
[0112] In some embodiments, the first application may include a main thread and / or a render thread. The render thread is used to render the image of the first application, such as drawing the content to be rendered, generating the source code of the shader based on the content to be rendered, calling the GPU driver (and / or the graphics library driver) to compile the source code of the shader to obtain the target code, and calling the GPU to run the target code to render the image of the first application, etc.
[0113] In some embodiments, after detecting an instruction to compile the source code of the shader of the first application, the rendering thread of the first application can compile the source code of the shader of the first application based on the compilation methods provided in the various embodiments of this application. For example, compilation can be performed using a first compilation method if a first condition is met, or using a second compilation method if the first condition is not met. Specific details can be found in the embodiment shown in Figure 2, which will not be elaborated upon here.
[0114] It should be noted that in some other embodiments, the rendering thread's functions can also be performed by the main thread or other threads, which is not limited here.
[0115] It should be noted that the first application can be any application. For example, the first application can be a system application in the operating system of an electronic device, or it can be a third-party application. The specific form, name, and function of the first application are not limited in the embodiments of this application.
[0116] The framework layer provides application programming interfaces (APIs) and programming frameworks for applications in the application layer. The framework layer includes predefined functions. For example, it may include scene detection modules, graphics libraries, etc. These graphics libraries may include one or more graphics libraries, such as the Open Graphics Library for Embedded Systems (OpenGL ES) or Vulkan (a graphics library).
[0117] The scene detection module can be used to detect whether the first condition is met. For example, if the rendering thread detects a compilation instruction to compile the source code of the shader for the first application, it can obtain the detection result of the scene detection module on the first condition, and compile the source code of the shader for the first application using different compilation methods based on the detection result.
[0118] In some embodiments, after compiling the source code of the shader of the first application, the scene detection module can further detect whether the first application meets the first condition (e.g., whether the complexity of the content to be rendered is less than the second threshold, whether the frame rate of the image displayed by the first application is greater than the third threshold, whether the rendering time of the image of the first application is less than the fourth threshold, etc.). If the first application is detected to not meet the first condition, the scene detection module can trigger the rendering thread (or other threads) to recompile the source code of the shader of the first application.
[0119] For example, after the source code of the shader for the first application has been compiled using the first compilation method, the electronic device can run the first compilation result to render the image of the first application. During the process of rendering the image of the first application using the first compilation result, if the scene detection module detects that the first application does not meet the first condition, it can trigger the rendering thread to compile the source code of the shader using the third compilation method to obtain the third compilation result.
[0120] The graphics library provides APIs (hereinafter referred to as the graphics APIs) for graphics processing to modules in applications or framework layers. Applications (such as rendering threads) can use the APIs provided by the graphics library to draw, render, and composite the images that the application needs to generate.
[0121] In some embodiments, the graphics API may include, but is not limited to, APIs for generating shader source code, APIs for establishing graphics processing pipelines, and APIs for compiling shader source code.
[0122] In some embodiments, the framework layer may also include other predefined functions, methods, or interfaces, which are not limited herein.
[0123] The kernel layer is the layer between hardware and software. In some embodiments, the kernel layer may include drivers for hardware in an electronic device, such as GPU drivers. Applications in the application layer or modules in the framework layer can invoke the corresponding hardware to implement related functions through the drivers for each hardware component.
[0124] In some embodiments, the GPU driver may provide APIs for compiling shader source code. For example, the GPU driver may provide APIs for compiling shader source code using different optimization methods.
[0125] For example, the GPU driver can provide different APIs for different compilation methods. When the rendering thread calls the GPU driver to compile the shader source code, it can use the APIs corresponding to the first to third compilation methods respectively to compile the source code of the shader for the first application.
[0126] For example, when the rendering thread establishes a pipeline using a graphics API (such as the `CreateGraphicsPipelines` function provided by Vulkan), it can create property descriptors (also known as compilation parameters) to indicate the compilation mode. When compiling the shader source code using the API provided by the graphics library or the GPU driver, the rendering thread can adjust the compilation mode by modifying the specific values of the property descriptors. For instance, the first to third compilation modes can correspond to the first, second, and third values of the property descriptors, respectively. The rendering thread can compile the source code of the shader for the first application using the first to third compilation modes by passing property descriptors with the first, second, and third values to the GPU driver, respectively.
[0127] In some embodiments, the GPU driver can integrate compilation methods corresponding to different graphics libraries. When an application processes an image using a particular graphics library, the application can compile the shader source code based on the driver corresponding to that graphics library integrated into the GPU.
[0128] In other embodiments, the kernel layer may also include more drivers, which is not limited here.
[0129] It should be noted that in other embodiments, the software architecture of the electronic device may include more layers (such as a native layer, a hardware abstraction layer (HAL), a service layer, etc.), and the modules may also be deployed to other layers, which is not limited here.
[0130] It should be noted that in some embodiments, layers that perform the same function may be called by other names, or layers that can perform the functions of multiple layers may be considered as one layer, or layers that can perform the functions of multiple layers may be divided into multiple layers. This application does not impose any limitations on these aspects.
[0131] It should be noted that the software architecture shown in Figure 3 is only an example. In other embodiments, the software architecture of the electronic device 10 may also adopt other architectures, which are not limited here.
[0132] In some embodiments, a scenario that satisfies the first condition can be referred to as a simple scenario, and a scenario that does not satisfy the first condition can be referred to as a complex scenario. Based on this, during the compilation of the source code of the shader of the first application, the electronic device can adopt different methods to compile the source code of the shader of the first application depending on whether the current scenario is simple or complex.
[0133] For example, Figure 4 illustrates a process diagram of an image processing method according to some embodiments of this application. As shown in Figure 4, the method includes:
[0134] S1, Scene Recognition.
[0135] Electronic devices can determine whether the current scene is a simple scene or a complex scene by detecting whether a first condition is met. For example, if the first condition is met, the electronic device can determine it is a simple scene; if the first condition is not met, the electronic device can determine it is a complex scene. For details regarding the first condition, please refer to the foregoing embodiments; it will not be repeated here.
[0136] For example, an electronic device can determine a scene through shader complexity analysis, such as by determining whether the current scene is a simple or complex scene based on whether the complexity of the source code of the shader in the first application is less than a first threshold, and / or whether the complexity of the content to be rendered by the shader is less than a second threshold. For instance, if the complexity of the source code of the shader in the first application is less than the first threshold, the electronic device can determine that the first condition is met. Similarly, if the complexity of the content to be rendered by the shader in the first application is less than the second threshold, the electronic device can determine that the first condition is met. Furthermore, if the complexity of the source code of the shader in the first application is less than the first threshold and the complexity of the content to be rendered by the shader in the first application is less than the second threshold, the electronic device can determine that the first condition is met.
[0137] In some embodiments, scene recognition can be performed using the aforementioned scene recognition module to identify simple and complex scenes.
[0138] S2, select the compilation method.
[0139] After determining the current scene, the electronic device can decide whether to perform compilation optimization based on the scene recognition results. For example, in the case of a simple scene, it is determined not to perform compilation optimization (or to perform compilation optimization with low compilation complexity); in the case of a complex scene, it is determined to perform compilation optimization (or to perform compilation optimization with high compilation complexity).
[0140] S3, compile directly.
[0141] If no compilation optimization is performed, the electronic device can directly compile the source code of the shader for the first application.
[0142] Alternatively, in a simple scenario, the electronic device can use the first compilation method to compile the source code of the shader for the first application.
[0143] S4, optimized compilation.
[0144] If compilation optimization is determined, the electronic device can optimize the compilation of the source code of the shader for the first application.
[0145] Optionally, in complex scenarios, electronic devices can use a second compilation method to compile the source code of the shader for the first application.
[0146] S5, rendering output.
[0147] After the target code of the shader is compiled, the electronic device can use the GPU to run the target code of the shader to render the image of the first application, and output the rendered image to the module for compositing or the module for displaying the image.
[0148] S6, dynamically adjusted.
[0149] During the process of processing the image of the first application based on the compiled target code, the electronic device can continue to identify the scene and dynamically adjust the compilation method according to the scene identification results.
[0150] For example, when the electronic device detects that the scene has changed from a simple scene to a complex scene (e.g., a scene that does not meet the first condition), it can switch to optimized compilation (or the second / third compilation method) to recompile the shaders of the first application to avoid stuttering.
[0151] For example, when optimizing compilation based on S4 (or the second compilation method), the electronic device can switch to direct compilation (or the first compilation method) to recompile the shaders of the first application when it detects that the scene has switched from a complex scene to a simple scene (e.g., from not meeting the first condition to meeting the first condition).
[0152] Based on S6, it is possible to balance the power consumption and display performance of electronic devices.
[0153] In some embodiments, the electronic device may perform image processing by repeating S1 to S6.
[0154] Based on S1 to S6 above, electronic devices can compile the source code of the application's shaders in different ways depending on the scenario. This avoids resource waste caused by over-optimization of the source code in simple scenarios (such as browsing web pages or running mini-programs), and also avoids interface lag caused by insufficient optimization of the source code in complex scenarios (such as videos, games, and display animations).
[0155] Furthermore, Figure 5 shows a schematic diagram of the structure of an electronic device according to some embodiments of this application.
[0156] As shown in Figure 5, the electronic device 10 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, a headphone jack 170D, a sensor module 180, buttons 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identity module (SIM) card interface 195. The sensor module 180 may include a pressure sensor 180A, one or more gyroscope sensors 180B, a barometric pressure sensor 180C, a magnetic sensor 180D, one or more accelerometers 180E, a distance sensor 180F, a proximity sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc.
[0157] It is understood that the structures illustrated in the embodiments of this application do not constitute a specific limitation on the electronic device 10. In other embodiments of this application, the electronic device 10 may include more or fewer components than illustrated, or combine some components, or split some components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
[0158] Processor 110 may include one or more processing units, such as application processor (AP), modem processor, graphics processing unit (GPU), image signal processor (ISP), controller, video codec, digital signal processor (DSP), baseband processor, and / or neural network processing unit (NPU). These different processing units may be independent devices or integrated into one or more processors.
[0159] The processor 110 may also include a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. This memory can store instructions or data that the processor 110 has just used or that are used repeatedly. When the processor 110 needs to use the instruction or data again, it can directly retrieve it from the aforementioned memory. This avoids repeated accesses, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.
[0160] In some embodiments, the processor 110 may compile the source code of the application's shaders using the compilation methods provided in the foregoing embodiments.
[0161] USB port 130 is a USB standard compliant interface, specifically a Mini USB port, Micro USB port, USB Type-C port, etc. USB port 130 can be used to connect a charger to charge electronic device 10, and can also be used for data transfer between electronic device 10 and peripheral devices. It can also be used to connect headphones for audio playback.
[0162] The charging management module 140 receives charging input from a charger, which can be a wireless charger or a wired charger. While charging the battery 142, the charging management module 140 can also supply power to the electronic device via the power management module 141.
[0163] The power management module 141 connects the battery 142, the charging management module 140, and the processor 110. The power management module 141 receives input from the battery 142 and / or the charging management module 140 to power the processor 110, internal memory 121, display screen 194, camera 193, and wireless communication module 160, etc. In some embodiments, the power management module 141 and the charging management module 140 may also be housed in the same device.
[0164] The wireless communication function of electronic device 10 can be implemented through antenna 1, antenna 2, mobile communication module 150, wireless communication module 160, modem processor, and baseband processor.
[0165] Antennas 1 and 2 are used to transmit and receive electromagnetic wave signals. Each antenna in electronic device 10 can be used to cover one or more communication frequency bands. Different antennas can also be multiplexed to improve antenna utilization. For example, antenna 1 can be multiplexed as a diversity antenna for a wireless local area network. In some other embodiments, the antennas can be used in conjunction with a tuning switch.
[0166] The mobile communication module 150 can provide solutions for wireless communication, including 2G / 3G / 4G / 5G, applied to the electronic device 10. The mobile communication module 150 may include at least one filter, switch, power amplifier, low noise amplifier (LNA), etc. The mobile communication module 150 can receive electromagnetic waves via the antenna 1, and perform filtering, amplification, and other processing on the received electromagnetic waves before transmitting them to the modem processor for demodulation. The mobile communication module 150 can also amplify the signal modulated by the modem processor and convert it into electromagnetic waves for radiation via the antenna 1. In some embodiments, at least some functional modules of the mobile communication module 150 may be housed in the processor 110. In some embodiments, at least some functional modules of the mobile communication module 150 and at least some modules of the processor 110 may be housed in the same device.
[0167] The wireless communication module 160 can provide solutions for wireless communication applications on the electronic device 10, including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), and infrared (IR) technologies. The wireless communication module 160 can be one or more devices integrating at least one communication processing module. The wireless communication module 160 receives electromagnetic waves via antenna 2, performs frequency modulation and filtering of the electromagnetic wave signals, and sends the processed signal to processor 110. The wireless communication module 160 can also receive signals to be transmitted from processor 110, perform frequency modulation and amplification, and convert them into electromagnetic waves for radiation via antenna 2.
[0168] In some embodiments, antenna 1 of electronic device 10 is coupled to mobile communication module 150, and antenna 2 is coupled to wireless communication module 160, enabling electronic device 10 to communicate with networks and other devices via wireless communication technology. The aforementioned wireless communication technology may include Global System for Mobile Communications (GSM), General Packet Radio Service (GPRS), Code Division Multiple Access (CDMA), Wideband Code Division Multiple Access (WCDMA), Time-Division Code Division Multiple Access (TD-SCDMA), Long Term Evolution (LTE), BT, GNSS, WLAN, NFC, FM, and / or IR technologies, etc. The aforementioned GNSS may include the Global Positioning System (GPS), the Global Navigation Satellite System (GLONASS), the BeiDou Navigation Satellite System (BDS), the Quasi-Zenith Satellite System (QZSS), and / or satellite-based augmentation systems (SBAS).
[0169] A GPU is a microprocessor for image processing, connected to the display screen 194 and the application processor. The GPU performs mathematical and geometric calculations for graphics rendering. Processor 110 may include one or more GPUs that execute program instructions to generate or modify display information. For example, in some embodiments, the GPU may be used to execute compiled shaders (object code) to render images for an application.
[0170] Display screen 194 is used to display images, videos, etc.
[0171] Electronic device 10 can perform shooting functions through ISP, camera 193, video codec, GPU, display 194 and application processor.
[0172] Camera 193 is used to capture still images or videos. An object is projected onto a photosensitive element through a lens to generate an optical image. In some embodiments, electronic device 10 may include one or N cameras 193, where N is a positive integer greater than 1.
[0173] The external storage interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 10. The external memory card communicates with the processor 110 through the external storage interface 120 to perform data storage functions. For example, music, video, and other files can be saved on the external memory card.
[0174] Internal memory 121 can be used to store computer executable program code, including instructions. Internal memory 121 may include a program storage area and a data storage area. The program storage area may store the operating system, application programs required for at least one function (such as sound playback, image playback, etc.), etc. The data storage area may store data created during the use of electronic device 10 (such as audio data, phonebook, etc.). In addition, internal memory 121 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, universal flash storage (UFS), etc. Processor 110 executes various functional applications and data processing of electronic device 10 by running instructions stored in internal memory 121 and / or instructions stored in memory located in the processor.
[0175] Electronic device 10 can implement audio functions such as music playback and recording through an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, a headphone jack 170D, and an application processor.
[0176] The audio module 170 is used to convert digital audio information into analog audio signals for output, and also to convert analog audio input into digital audio signals. The audio module 170 can also be used for encoding and decoding audio signals. In some embodiments, the audio module 170 may be located in the processor 110, or some functional modules of the audio module 170 may be located in the processor 110.
[0177] The speaker 170A, also known as a "loudspeaker," is used to convert audio electrical signals into sound signals. The electronic device 10 can listen to music or make hands-free calls through the speaker 170A.
[0178] The receiver 170B, also known as the "earpiece," is used to convert audio electrical signals into sound signals. When the electronic device 10 receives a telephone call or voice message, the receiver 170B can be brought close to the ear to hear the voice.
[0179] Microphone 170C, also known as a "microphone" or "voice transducer," is used to convert sound signals into electrical signals. When making a phone call or sending a voice message, the user can speak by bringing their mouth close to microphone 170C, inputting the sound signal into microphone 170C.
[0180] The 170D headphone jack is used to connect wired headphones.
[0181] Buttons 190 include a power button, volume buttons, etc. Buttons 190 can be mechanical buttons or touch-sensitive buttons. The electronic device 10 can receive button input and generate key signal inputs related to user settings and function control of the electronic device 10.
[0182] Motor 191 can generate vibration alerts.
[0183] Indicator 192 can be an indicator light, used to indicate charging status, power changes, or to indicate messages, missed calls, notifications, etc.
[0184] The SIM card interface 195 is used to connect the SIM card.
[0185] It should be noted that the electronic device to which this application embodiment applies may adopt the same or similar structure as electronic device 10, or may adopt a different structure than electronic device 10, which is hereby limited.
[0186] This application also provides a computer-readable storage medium storing one or more program instructions that, when executed on an electronic device, cause the electronic device to perform the compilation methods provided in the foregoing embodiments.
[0187] This application also provides a computer program product that, when run on an electronic device, causes the electronic device to execute the compilation methods provided in the foregoing embodiments.
[0188] It should be noted that the first to sixth thresholds and the first to third values in the foregoing embodiments can be empirical or experimental values. This application does not limit the specific values of the first to sixth thresholds and the first to third values in its embodiments.
[0189] It should be noted that the terminology used in the implementation section of the embodiments of this application is only used to explain the specific embodiments of this application and is not intended to limit this application. In the description of the embodiments of this application, unless otherwise stated, " / " means "or", for example, A / B can mean A or B; "and / or" in this document is merely a description of the association relationship of related obstacles, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, and B alone. In addition, in the description of the embodiments of this application, unless otherwise stated, "multiple" means two or more, "at least one" or "one or more" means one, two or more.
[0190] It should be noted that the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Therefore, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature.
[0191] References to "one embodiment" or "some embodiments" as used in this specification mean that one or more embodiments of this application include a specific feature, structure, or characteristic described in connection with that embodiment. Therefore, the phrases "in one embodiment," "in some embodiments," "in other embodiments," "in still other embodiments," etc., appearing in different parts of this specification do not necessarily refer to the same embodiment, but rather mean "one or more, but not all, embodiments," unless otherwise specifically emphasized. The terms "comprising," "including," "having," and variations thereof mean "including but not limited to," unless otherwise specifically emphasized.
[0192] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted through the computer-readable storage medium. The computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium accessible to a computer or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium, or a semiconductor medium, etc.
[0193] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. This program can be stored in a computer-readable storage medium, and when executed, it can include the processes described in the above method embodiments. The aforementioned storage medium includes various media capable of storing program code, such as read-only memory or random access memory, magnetic disks, or optical disks.
[0194] The above description is merely a specific implementation of the embodiments of this application, but the protection scope of the embodiments of this application is not limited thereto. Any changes or substitutions within the technical scope disclosed in the embodiments of this application should be covered within the protection scope of the embodiments of this application. Therefore, the protection scope of the embodiments of this application should be determined by the protection scope of the claims.
Claims
1. A compilation method applied to electronic devices, characterized in that, The method includes: Compilation instructions for compiling the source code of the shader in the first application were detected; Under the condition that the first condition is met, the source code of the shader is compiled using the first compilation method to obtain the first compilation result; If the first condition is not met, the source code of the shader is compiled using a second compilation method to obtain a second compilation result. The compilation complexity of the first compilation method is less than that of the second compilation method. The factors determining the compilation complexity include at least one of the following: compilation time, computational resources used in compilation, and the number of optimization methods used in compilation.
2. The method according to claim 1, characterized in that, The first condition includes at least one of the following: the first application is a preset application or a preset category of application, the complexity of the source code of the shader is less than a first threshold, the content to be rendered by the first application is a webpage, and the complexity of the content to be rendered by the shader is less than a second threshold.
3. The method according to claim 2, characterized in that, The first condition also includes at least one of the following conditions: The frame rate of the image displayed by the first application is greater than the third threshold; The rendering time of the image in the first application is less than the fourth threshold.
4. The method according to claim 2, characterized in that, The complexity of the content to be rendered by the shader is determined based on one or more of the following: the number of objects, the number of light sources, and the complexity of materials in the content to be rendered by the shader.
5. The method according to claim 2, characterized in that, The complexity of the shader's source code is determined based on one or more of the following: the number of instructions in the source code, the number of branch instructions in the source code, the number of loop instructions in the source code, and the number of times the texture is sampled in the source code.
6. The method according to any one of claims 1 to 5, characterized in that, The first compilation method is direct compilation, and the second compilation method is optimized compilation; Alternatively, the first compilation method and the second compilation method are optimized compilations, and the number of optimization methods corresponding to optimized compilation in the first compilation method is less than the number of optimization methods corresponding to optimized compilation in the second compilation method.
7. The method according to claim 1, characterized in that, The electronic device includes a graphics processor, and: The step of compiling the source code of the shader using the first compilation method to obtain the first compilation result includes: calling the driver of the graphics processor to compile the source code of the shader based on the first compilation parameters corresponding to the first compilation method, and obtaining the first compilation result; The step of compiling the source code of the shader using the second compilation method to obtain the second compilation result includes: calling the driver of the graphics processor to compile the source code of the shader based on the second compilation parameters corresponding to the second compilation method, and obtaining the second compilation result.
8. The method according to claim 1, characterized in that, The second compilation method is determined based on at least one of the following: the complexity of the shader's source code, the complexity of the content to be rendered by the shader; and, the greater the complexity of the shader's source code, the greater the compilation complexity of the second compilation method, and / or, the greater the complexity of the content to be rendered by the shader, the greater the compilation complexity of the second compilation method.
9. The method according to claim 1, characterized in that, The method includes: When the source code of the shader is compiled using the first compilation method, the display content of the first application is rendered based on the first compilation result; During the rendering process of the display content of the first application based on the first compilation result, it is detected that the frame rate of the image displayed by the first application is less than the fifth threshold and / or the rendering duration of the image of the first application is greater than the sixth threshold. The source code of the shader is recompiled using a third compilation method, wherein the compilation complexity of the third compilation method is greater than that of the first compilation method.
10. An electronic device, characterized in that, include: One or more processors; One or more memory units; The one or more memories store one or more computer programs, the one or more computer programs including instructions that, when executed by the one or more processors, cause the electronic device to implement the compilation method of any one of claims 1 to 9.
11. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable program instructions, which, when executed on a computer, cause the computer to implement the compilation method according to any one of claims 1 to 9.
12. A computer program product, characterized in that, The computer program product includes computer program code, which, when run on a computer, causes the computer to implement the compilation method according to any one of claims 1 to 9.