Code optimization method and device, electronic equipment, storage medium and program product

By extracting the code to be optimized during game development, performing test tasks and trimming unnecessary variant information, the memory usage problem caused by the excessive number of shader variants is solved and system performance and efficiency are improved.

CN119336617APending Publication Date: 2025-01-21ZHUHAI KINGSOFT ONLINE GAME TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411418181.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-11
Publication Date
2025-01-21

AI Technical Summary

Technical Problem

As game features increase, the number of shaders and variants increases dramatically, resulting in the final Shader bytecode taking up a lot of memory and reducing keywords negatively affecting performance.

Method used

By obtaining the code to be optimized of the target program, a test task is performed to determine the actually referenced variant information, and based on this information, the shader variant information in the code to be optimized is trimmed to generate the target optimized code.

Benefits of technology

It effectively avoids the variant explosion problem caused by keyword combinations, greatly reduces the number of final Shader bytecodes and memory usage, and improves the overall efficiency of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119336617A_ABST
    Figure CN119336617A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a code optimization method and device, electronic equipment, a storage medium and a program product, and the code optimization method comprises the steps that a to-be-optimized code of a target program is acquired, and the to-be-optimized code comprises shader variant information; a test task for the target program is executed to obtain a test result, target variant information is determined according to the test result, and the target variant information is variant information referenced by the test task; on the basis of the target variant information, shader variant information in the to-be-optimized code is cut, and a target optimized code is obtained. According to the method, the to-be-optimized code is extracted, the test task is executed, the actually referenced target variant information is determined according to the test result, and the original variant information is optimized by utilizing the target variant information, so that variant explosion caused by keyword multiplication combination is avoided, the number of final Shader byte codes and memory occupation are greatly reduced, and the overall efficiency of a system is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present invention relate to the field of computer technology, and in particular to a code optimization method, device, electronic device, storage medium and program product. Background Art

[0002] In game development, in order to achieve rich visual effects, developers usually use complex shader technology. Shaders are responsible for handling different stages in graphics rendering, including lighting, shadows, texture mapping, and special effects. In order to meet the needs of various visual effects, developers need to write multiple shader codes and create corresponding variant codes for each effect. Variant codes allow specific functions to be enabled or disabled through different keywords and macro definitions, so that the rendering process can dynamically adapt to various scenarios and needs.

[0003] However, as the number of game features continues to increase, the number of shaders and variants has also increased dramatically. Each variant corresponds to a compiled shader bytecode, resulting in the final Shader bytecode occupying a large amount of memory. In related technologies, although reducing keywords can reduce the number of variants, it is necessary to add complex conditional judgments (such as if statements) in the shader, which will have a negative impact on performance.

[0004] Therefore, a code optimization method is urgently needed to optimize the number of variants. Summary of the invention

[0005] In view of this, an embodiment of the present invention provides a code optimization method. One or more embodiments of the present invention also relate to a code optimization device, a computing device, a computer-readable storage medium and a computer program product to solve the technical defects existing in the prior art.

[0006] According to a first aspect of an embodiment of the present invention, a code optimization method is provided, comprising: Obtaining the code to be optimized of the target program, wherein the code to be optimized includes shader variant information; Execute a test task for the target program to obtain a test result, and determine target variant information according to the test result, wherein the target variant information is variant information referenced by the test task; Based on the target variant information, a trimming process is performed on the shader variant information in the code to be optimized to obtain the target optimized code.

[0007] According to a second aspect of an embodiment of the present invention, there is provided a code optimization device, comprising: An acquisition module is configured to acquire the to-be-optimized code of the target program, wherein the to-be-optimized code includes shader variant information; A determination module is configured to execute a test task for a target program to obtain a test result, and determine target variant information according to the test result, wherein the target variant information is variant information referenced by the test task; The trimming module is configured to perform trimming processing on the shader variant information in the code to be optimized based on the target variant information to obtain the target optimized code.

[0008] According to a third aspect of an embodiment of the present invention, there is provided a computing device, including: Memory and processor; The memory is used to store computer programs / instructions, and the processor is used to execute the computer programs / instructions. When the computer programs / instructions are executed by the processor, the steps of the above-mentioned code optimization method are implemented.

[0009] According to a fourth aspect of an embodiment of the present invention, a computer-readable storage medium is provided, which stores a computer program / instruction, and the computer program / instruction implements the steps of the above-mentioned code optimization method when executed by a processor.

[0010] According to a fifth aspect of an embodiment of the present invention, there is provided a computer program product, comprising a computer program / instruction, which implements the steps of the above-mentioned code optimization method when executed by a processor.

[0011] An embodiment of the present invention realizes obtaining the code to be optimized of the target program, wherein the code to be optimized includes shader variant information; executing a test task for the target program to obtain a test result, and determining the target variant information according to the test result, wherein the target variant information is the variant information referenced by the test task; based on the target variant information, performing a trimming process on the shader variant information in the code to be optimized to obtain the target optimized code. By extracting the code to be optimized and executing the test task, determining the target variant information actually referenced according to the test result, and then using the target variant information to optimize the original variant information, the variant explosion caused by the keyword multiplication combination is avoided, thereby greatly reducing the number of final Shader bytecodes and memory usage, and improving the overall efficiency of the system. BRIEF DESCRIPTION OF THE DRAWINGS

[0012] Figure 1 is an interactive schematic diagram of a code optimization system provided by an embodiment of the present invention; Figure 2 is a flow chart of a code optimization method provided by an embodiment of the present invention; Figure 3 is a process flow chart of a code optimization method provided by an embodiment of the present invention; Figure 4 It is a structural schematic diagram of a code optimization device provided by an embodiment of the present invention; Figure 5 It is a structural block diagram of a computing device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0013] Many specific details are set forth in the following description to facilitate a full understanding of the present invention. However, the present invention can be implemented in many other ways than those described herein, and those skilled in the art can make similar generalizations without violating the connotation of the present invention, so the present invention is not limited to the specific implementation disclosed below.

[0014] The terms used in one or more embodiments of the present invention are only for the purpose of describing specific embodiments, and are not intended to limit one or more embodiments of the present invention. The singular forms of "a", "said" and "the" used in one or more embodiments of the present invention and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used in one or more embodiments of the present invention refers to and includes any or all possible combinations of one or more associated listed items.

[0015] It should be understood that, although the terms first, second, etc. may be used to describe various information in one or more embodiments of the present invention, these information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of one or more embodiments of the present invention, the first may also be referred to as the second, and similarly, the second may also be referred to as the first. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".

[0016] In addition, it should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in one or more embodiments of the present invention are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.

[0017] First, the terms involved in one or more embodiments of the present invention are explained.

[0018] A shader is a computational program used to process and render images in computer graphics. It specifies how to map the surface or pixels of a 3D model to the screen. Shaders usually run on a graphics processing unit (GPU) to control image effects such as lighting, color, and texture.

[0019] multi_compile: A shader instruction in the Unity engine that is used to compile multiple shader variants based on multiple conditions. All specified variants will be compiled into the final shader program. It is suitable for situations where shaders need to be used under different conditions (such as different rendering modes, lighting settings, etc.).

[0020] shader_feature: A shader instruction in the Unity engine. The instruction is used to compile shader variants that only use these features. Only when these features are used will the variants be compiled into the final shader program. It is suitable for having multiple optional features in the shader, and the corresponding variants need to be compiled only when they are actually used.

[0021] In the development of large-scale 3A games, Shader is a key technology to improve the picture quality. By writing different Shaders, developers can achieve various visual effects, such as advanced lighting, complex texture mapping, and detailed material effects to enhance the visual performance of the game. However, with the increase of game functions and the improvement of visual effects, the number and number of Shader variants will also increase significantly. Shader variants are different Shader versions generated by different compilation conditions (such as function switches, lighting modes, etc.), which are usually controlled by keywords. For example, a game may need to support different lighting modes, fog effects, and shadow effects, and each mode will generate corresponding variants.

[0022] Managing shader variants presents several challenges. First, the number of variants grows exponentially with the number of keywords. For example, a combination of two keywords (such as KeyA1, KeyA2) and a combination of three keywords (such as KeyB1, KeyB2, KeyB3) will produce 6 variants (2*3=6). If you add another multi_compile keyword, the number of variants will double, resulting in a doubling of the final shader bytecode memory requirements. Too many shader variants will lead to increased memory usage and longer compilation times, which puts pressure on the game's performance and resource management. Although reducing keywords can reduce the number of variants, this may require adding additional conditional judgments to the shader code, which may reduce the execution efficiency of the shader and affect rendering performance. This problem forms a typical trade-off dilemma: the contradiction between reducing the number of variants and maintaining high performance and rich features.

[0023] In response to the above problems, a code optimization method is provided in the present invention. The present invention also relates to a code optimization system, a code optimization device, a computing device, a computer-readable storage medium, and a computer program product, which are described in detail one by one in the following embodiments.

[0024] See also Figure 1 , Figure 1 This is an interactive schematic diagram of a code optimization system provided by an embodiment of the present invention. The code optimization system includes a user end and a server end, wherein the user end is used to send the code to be optimized of the target program to the server end, and the server end is used to obtain the code to be optimized of the target program, wherein the code to be optimized includes shader variant information, and a test task for the target program is executed to obtain a test result, and target variant information is determined according to the test result, wherein the target variant information is the variant information referenced by the test task, and based on the target variant information, the shader variant information in the code to be optimized is trimmed to obtain the target optimized code.

[0025] Applied to the code optimization system, the optimization of shader variants is achieved through the collaboration of the user and server. The user is responsible for extracting and sending the code to be optimized containing all possible variants to the server. After receiving these codes, the server performs test tasks to determine the actual shader variants used, and identifies and determines the variant information actually referenced based on the test results. Subsequently, the server trims the variant information in the code to be optimized, removes redundant variants, and generates optimized code. This process effectively avoids the variant explosion problem caused by keyword combinations, greatly reduces the number of final shader bytecodes and memory usage, thereby improving the overall efficiency of the system.

[0026] See also Figure 2 , Figure 2 It is a flowchart of a code optimization method provided by an embodiment of the present invention, which specifically includes the following steps.

[0027] Step 202: Obtain the code to be optimized of the target program, wherein the code to be optimized includes shader variant information.

[0028] The code to be optimized refers to the program code that needs to be improved or optimized. In this context, the shader variant information refers to different shader variant configurations related to graphics rendering, which are usually used to optimize graphics rendering effects and performance.

[0029] In practice, the system first analyzes the target program's code to identify the parts that need to be optimized. The code to be optimized includes shader variant information, which describes the different shader configurations and variants used in the rendering process. The system extracts this information from the target program, which usually involves identifying and recording all used shader variants and their corresponding parameter settings. The system then organizes this information for subsequent optimization processing. This process may involve parsing the program code, identifying the use of shader variants, and collecting relevant performance data.

[0030] In a specific embodiment of the present invention, it is assumed that the target program contains multiple shader variants for graphics rendering, such as variants for different lighting conditions or material effects. The system extracts information about these shader variants from the target program, such as the configuration parameters and usage frequency of each variant. The system analyzes this information, identifies performance bottlenecks or redundant variant configurations, and prepares for subsequent optimization steps.

[0031] Step 204: Execute the test task for the target program to obtain the test result, and determine the target variant information according to the test result, wherein the target variant information is the variant information referenced by the test task.

[0032] The test task refers to the process of comprehensively checking and evaluating the target program, with the goal of traversing each branch, step, and content of the program and identifying the shader variant information actually referenced. The target variant information refers to the shader variant configuration actually used during the test.

[0033] In actual applications, when the system executes the test task, it systematically traverses all branches and steps in the target program. This means that the system will check every possible execution path in the program and evaluate which shader variant information is actually called under different conditions. The purpose of the test task is to ensure that the target program is fully tested to identify the variant information actually used by the user. For example, the system may simulate different operating environments, input data, or user operations to ensure that all possible variant usages are covered.

[0034] By traversing each branch and step of the program, the system records which variant information is referenced during the actual operation and generates test results. These results help the system determine which variant information is used by users in specific situations, that is, the variant information that is actually used. Based on this data, the system can optimize the program, remove redundant variants, or adjust existing variant configurations to improve performance or resource utilization.

[0035] Furthermore, a test task for the target program is executed to obtain a test result, and target variant information is determined according to the test result, including: in the shader variant information, material variant information related to the material and non-material variant information unrelated to the material are determined; based on the non-material variant information, a test task for the target program is executed to obtain a test result; according to the test result, first variant information referenced by the test task is determined in the non-material variant information; and the first variant information is combined with the material variant information to obtain the target variant information.

[0036] Among them, material variant information refers to the variant configuration of the referenced material; non-material variant information refers to the variant configuration that does not reference the material; and first variant information refers to the non-material variant information referenced in the test task.

[0037] In practical applications, it is first necessary to distinguish between material variant information related to materials and non-material variant information unrelated to materials in the shader variant information. For example, the system will check the configuration items in the shader variant information to find out those parts involving materials (such as texture mapping, color mixing, etc.) as material variant information, and other parts not involving materials (such as lighting model, shadow calculation, etc.) as non-material variant information. Next, the system performs test tasks for the target program based on the non-material variant information and records the test results. The test task may include running a series of scene rendering or performance tests to verify the performance under different non-material variant information. Based on the test results, the system will determine which variant information is referenced by the test task in the non-material variant information. These referenced information are called first variant information. Finally, the system combines the determined first variant information with the previous material variant information to obtain the complete target variant information. For example, if the test finds that a certain lighting model (part of the non-material variant information) performs well, then this part of information will be combined with specific texture mapping information (part of the material variant information) to form the final target variant information.

[0038] In a specific embodiment of the present invention, it is assumed that there is a shader configuration information in a game engine, which includes material-related configurations (such as texture coordinate transformation, color mixing mode, etc.) and material-independent configurations (such as lighting model, shadow calculation method, etc.). The system first identifies the configuration items related to the material as material variant information, such as texture coordinate transformation and color mixing mode. Then, the system identifies the configuration items unrelated to the material as non-material variant information, such as lighting model and shadow calculation method. Next, the system performs a test task based on the lighting model and shadow calculation method in the non-material variant information and records the test results. Assuming that the test results show that a certain lighting model performs best, then the lighting model information will be determined as the first variant information. Finally, the system combines the determined best lighting model information with the previously identified texture coordinate transformation and color mixing mode information to obtain the final target variant information.

[0039] Based on this, since the default material variant information cannot be optimized, we found the actually referenced part in the non-material variant information and combined it with the material variant information to obtain the target variant information that is actually referenced. This ensures that the overall performance can be improved by optimizing the non-material configuration without changing the material configuration.

[0040] Furthermore, based on the non-material variant information, a test task for the target program is executed to obtain a test result, including: deleting the non-material variant information to obtain a test code; using the test code to execute the test task for the target program, determining the variant information to be supplemented, and using the variant information to be supplemented as the test result, wherein the variant information to be supplemented is the non-material variant information required to execute the test task.

[0041] The variant information to be supplemented is non-material variant information required for executing the test task.

[0042] In actual applications, the system will delete all non-material variant information and generate a test code that only contains material variant information. This test code is generated without any non-material variant information. Next, the target program is tested using this generated test code. The purpose of this test is to determine which non-material variant information is necessary, that is, the non-material variant information that was mistakenly deleted when performing the test task. The test results will help the system identify these necessary non-material variant information, which is called the variant information to be supplemented.

[0043] In a specific embodiment of the present invention, it is assumed that the target program contains multiple non-material variant configurations. The system first deletes all non-material variant information and creates a test code containing only material variants. Then, the system uses this test code to perform a test task on the target program. By analyzing the test results, the system identifies which non-material variant information is necessary, and this necessary information is the variant information to be supplemented.

[0044] Based on this, by deleting all non-material variant information and performing the test, the system can effectively identify the non-material variant information that is actually needed. This method can help the system accurately determine the non-material variant information to be supplemented, ensuring that the final test task can cover all necessary variant configurations, thereby optimizing the completeness and accuracy of the test.

[0045] Step 206: Based on the target variant information, perform a trimming process on the shader variant information in the code to be optimized to obtain the target optimized code.

[0046] In actual applications, when the system performs pruning, it will delete redundant variant configurations that are not mentioned in the target variant information. Pruning helps reduce unnecessary code and resources, thereby improving program performance and efficiency. The processed code only retains the variant information actually needed, ensuring the simplicity and efficiency of the code. Finally, the target optimized code generated by the system contains the shader variant information after pruning, making the program more efficient and resource utilization more reasonable during execution.

[0047] In a specific embodiment of the present invention, it is assumed that there are multiple shader variant configurations in the target program. After testing, the system determines that some variant configurations are actually used. The system trims all variants in the optimized code based on these target variant information and deletes those variant configurations that are not actually used. The target optimized code finally generated only retains the variant configurations that are actually used, thereby optimizing the execution efficiency and resource usage of the program.

[0048] Furthermore, based on the target variant information, the shader variant information in the code to be optimized is trimmed to obtain the target optimized code, including: deleting variant information different from the target variant information in the shader variant information, and obtaining the optimized code based on the remaining variant information.

[0049] In actual applications, the system will review all shader variant information in the code to be optimized and identify which variant information is different from the target variant information. Then, these variant configurations that do not conform to the target variant information are deleted, leaving only the variant information that is consistent with the target variant information. Based on these remaining variant information, the system generates optimized code.

[0050] In a specific embodiment of the present invention, it is assumed that the target variant information includes a set of shader variants that need to be retained, and the code to be optimized includes multiple shader variants. The system first compares the variant information in the code to be optimized with the target variant information, and deletes all variant configurations that are inconsistent with the target variant information. Finally, the system generates optimized code based on the remaining variants that are consistent with the target variant information.

[0051] Based on this, by trimming the shader variant information, the system can effectively remove the parts that do not match the target variant information. In this way, the optimized code will only contain the variant configuration related to the target variant information, improving the efficiency and pertinence of the code. This optimization method not only reduces unnecessary variant configurations, but also improves the performance and maintainability of the program, making the final code more concise and efficient.

[0052] Furthermore, based on the target variant information, the shader variant information in the code to be optimized is trimmed, and after the target optimized code is obtained, the method also includes: receiving a trimming request, wherein the trimming request includes the variant information to be trimmed; based on the variant information to be trimmed, performing secondary trimming on the shader variant information to obtain a secondary optimized code.

[0053] The variant information to be trimmed is the shader variant configuration that needs to be further processed, which is used to perform fine-grained optimization on the code.

[0054] In actual applications, the system first performs trimming processing on the shader variant information in the code to be optimized based on the target variant information to obtain the target optimized code. This means that the system will remove those unreferenced shader variant configurations based on the previously determined target variant information and retain the actually referenced parts. For example, if the target variant information indicates that a certain lighting model and texture mapping are actually referenced, the system will retain these configurations and remove other unreferenced configurations.

[0055] After the initial cropping is completed, the system can also receive cropping requests. The cropping request includes the information of the variants to be cropped, that is, the configuration information of the variants that need to be further removed. For example, if after the initial cropping, the user finds that a specific lighting model is no longer needed, the cropping request can be used to specify the information to remove the lighting model.

[0056] Based on the variant information to be trimmed, the system will perform secondary trimming on the shader variant information to obtain secondary optimized code. For example, the system will further remove the specified configuration from the shader variant information based on the variant information to be trimmed in the trimming request, thereby generating a more streamlined secondary optimized code. This process can be repeated multiple times until all trimming requirements are met.

[0057] In a specific embodiment of the present invention, it is assumed that the target optimized code obtained after the initial cropping already includes the illumination model and texture mapping configuration that are actually referenced. At this time, if the user finds that a specific illumination model is no longer needed, the information of the illumination model can be removed by sending a cropping request. The cropping request contains the information of the variant to be cropped, that is, the illumination model to be removed is specified. After receiving the cropping request, the system will further remove the specified illumination model configuration according to the information of the variant to be cropped in the request, thereby obtaining a more streamlined secondary optimization code. For example, if two illumination models A and B are retained after the initial cropping, but the removal of model A is specified in the cropping request, then the final secondary optimization code will only contain model B and other necessary configurations.

[0058] Based on this, by receiving cropping requests and performing secondary cropping based on the information of the variant to be cropped, the system can continuously optimize the shader variant information to ensure that the final optimized code only contains the configuration actually required. This method not only improves the simplicity of the code, but also further improves rendering efficiency and performance. The system can dynamically adjust the shader configuration according to user needs to ensure that each cropping can achieve the best optimization effect, thereby minimizing unnecessary computing burden without affecting rendering quality.

[0059] Furthermore, after executing the test task for the target program to obtain the test result and determining the target variant information according to the test result, the method further includes: when the target variant information includes the variant information to be trimmed, adding the variant information to be trimmed to the shader variant information.

[0060] The target variant information is the required variant information, while the pending variant information is the variant information that is determined to be retained during the testing process but is not yet included. This step is generally a leak-proof mechanism to ensure that all required variant information is correctly included in the final shader variant information.

[0061] In actual applications, the system first performs a test task for the target program and determines the target variant information based on the test results. This means that the system will verify which variant information is actually referenced and required through a series of tests. For example, the system may run multiple scene rendering or performance tests to determine which lighting models, texture mapping and other configurations are actually required, and determine this information as the target variant information.

[0062] After the target variant information is determined, the system will check whether the target variant information completely contains all the necessary information. If the target variant information includes pending variant information, that is, variant information that is determined to be retained during testing but is not yet included, the system will add this pending variant information to the shader variant information. For example, if the test results show that a specific lighting model is not referenced in the initial test, but is required in subsequent actual application scenarios, the system will add this lighting model information back to the shader variant information.

[0063] In a specific embodiment of the present invention, it is assumed that several necessary illumination models and texture mapping configurations are determined as target variant information after preliminary testing. In the subsequent actual use process, the system finds that there is another illumination model that is not referenced in the initial test, but is necessary in some special scenarios. At this time, the system will add this additional illumination model information as the variant information to be tailored to the shader variant information to ensure that the final shader configuration is complete.

[0064] Based on this, by checking and adding the variant information to be trimmed in the target variant information, the system can ensure that all required variant information is correctly included in the final shader variant information. This method not only improves the completeness of the configuration, but also avoids problems caused by missing required configuration. The system can dynamically adjust and supplement the missing variant information to ensure the best rendering effect and performance in all application scenarios. Through this leak-filling mechanism, the system can cover actual needs more comprehensively, thereby improving the quality and reliability of the final optimized code.

[0065] An embodiment of the present invention realizes obtaining the code to be optimized of the target program, wherein the code to be optimized includes shader variant information; executing a test task for the target program to obtain a test result, and determining the target variant information according to the test result, wherein the target variant information is the variant information referenced by the test task; based on the target variant information, performing a trimming process on the shader variant information in the code to be optimized to obtain the target optimized code. By extracting the code to be optimized and executing the test task, determining the target variant information actually referenced according to the test result, and then using the target variant information to optimize the original variant information, the variant explosion caused by the keyword multiplication combination is avoided, thereby greatly reducing the number of final Shader bytecodes and memory usage, and improving the overall efficiency of the system.

[0066] The following combination Figure 3 , taking the application of the code optimization method provided by the present invention in shader variant optimization as an example, the code optimization method is further described. Figure 3 It is a process flow chart of a code optimization method provided by an embodiment of the present invention, which specifically includes the following steps.

[0067] Step 302: Variant keyword replacement.

[0068] Specifically, in shader development, the multi_compile keyword will generate a large number of variant combinations, resulting in a sharp increase in the number of variants. To solve this problem, shader_feature can be used instead of multi_compile as much as possible. The shader_feature keyword can be used to more finely control the generation of variants, thereby reducing the number of useless variants. Through Unity's packaged material collection function, the system automatically identifies and removes variants that are not used in actual materials, further optimizing the number of shader variants.

[0069] Step 304: Add a variant collector.

[0070] Specifically, in order to ensure that the variants generated by shader_feature in the Shader will not be deleted by mistake, the shaderVariant variant collector needs to be introduced. This tool is used to force the retention of variants that are actually needed in the game, even if these variants may be cut off by default. The variant collector will ensure that these necessary variants are always present in the compiled Shader and will not be removed during the optimization process, thus avoiding runtime problems caused by missing variants.

[0071] Step 306: Automated variant analysis and collection.

[0072] Specifically, when the game is running, if the shader variant does not match, an error log will be triggered. By modifying the source code, the system can automatically output log information when a variant is missing. These logs will be collected and uploaded to the analysis platform. By analyzing these logs, the system can identify the missing variants. This process is fully automated without manual intervention. These missing variants are added to the .shaderVariant variant collector through automated scripts to ensure that all necessary variants are correctly compiled to the GPU.

[0073] Step 308: Optimize the variant actually used.

[0074] Specifically, after the above steps, although many variants have been optimized, the variants actually used in the game may account for less than 10% of all variants. Therefore, secondary pruning is required. The system will further optimize the variants based on the actual game data and remove all unused variants. This process can significantly reduce the number of final Shader variants, further optimize memory usage and compilation time, and thus improve game performance.

[0075] Step 310: Circular leak repair.

[0076] Specifically, in order to deal with possible variant cutting errors, the system implements a loop filling mechanism. If missing variants are found during the secondary cutting process, these missing variants will be recollected through step 306. By analyzing the error logs when the game is running, the automated system will add these missing variants back to the variant collector. This loop mechanism ensures the accuracy of variant optimization and ensures that all actually required variants are correctly processed and retained.

[0077] Applied to this method, by replacing the keyword multi_compile with shader_feature and introducing an automated variant collection and pruning mechanism, the system effectively solves the problem of too many variants caused by keyword multiplication combinations. Ultimately, only the variants that are actually used are compiled and packaged, greatly reducing the number of shader variants. This optimization significantly reduces memory usage, packaging and compilation time, loading time, and package size, while the pruning and leak-proofing process is fully automated, ensuring the efficiency and accuracy of the optimization.

[0078] Corresponding to the above method embodiment, the present invention also provides a code optimization device embodiment, Figure 4 FIG. 1 is a schematic diagram of a code optimization device provided by an embodiment of the present invention. Figure 4 As shown, the device comprises: An acquisition module 402 is configured to acquire the code to be optimized of the target program, wherein the code to be optimized includes shader variant information; The determination module 404 is configured to execute a test task for the target program to obtain a test result, and determine target variant information according to the test result, wherein the target variant information is variant information referenced by the test task; The trimming module 406 is configured to perform trimming processing on the shader variant information in the code to be optimized based on the target variant information to obtain the target optimized code.

[0079] Optionally, the determination module 404 is further configured to determine material variant information related to the material and non-material variant information unrelated to the material in the shader variant information; based on the non-material variant information, execute a test task for the target program to obtain a test result; determine the first variant information referenced by the test task in the non-material variant information according to the test result; and combine the first variant information with the material variant information to obtain the target variant information.

[0080] Optionally, the determination module 404 is further configured to delete the non-material variant information and obtain the test code; use the test code to execute the test task for the target program, determine the variant information to be supplemented, and use the variant information to be supplemented as the test result, wherein the variant information to be supplemented is the non-material variant information required to execute the test task.

[0081] Optionally, the trimming module 406 is further configured to delete variant information different from the target variant information in the shader variant information, and obtain optimized code based on the remaining variant information.

[0082] Optionally, the code optimization device further includes a secondary trimming module configured to receive a trimming request, wherein the trimming request includes variant information to be trimmed; based on the variant information to be trimmed, perform secondary trimming processing on the shader variant information to obtain a secondary optimized code.

[0083] Optionally, the secondary cropping module is further configured to add the to-be-cropped variant information to the shader variant information when the target variant information includes the to-be-cropped variant information.

[0084] Applied to the code optimization device, first, the acquisition module 402 is responsible for extracting the code to be optimized of the target program, which contains the shader variant information. Then, the determination module 404 performs the test task for the target program, obtains the test results and determines the target variant information actually referenced based on the results, which is the key to optimization. Finally, the trimming module 406 uses the target variant information to perform trimming processing on the shader variants in the code to be optimized to generate the target optimized code. Through this process, the device avoids the surge in the number of variants caused by the keyword multiplication combination, greatly reduces the number of final Shader bytecodes and memory usage, and thus significantly improves the overall efficiency of the system.

[0085] The above is a schematic scheme of a code optimization device of this embodiment. It should be noted that the technical scheme of the code optimization device and the technical scheme of the above code optimization method belong to the same concept, and the details not described in detail in the technical scheme of the code optimization device can be referred to the description of the technical scheme of the above code optimization method.

[0086] Figure 5 The block diagram of a computing device 500 provided according to an embodiment of the present invention is shown. The components of the computing device 500 include but are not limited to a memory 510 and a processor 520. The processor 520 is connected to the memory 510 via a bus 530, and the database 550 is used to store data.

[0087] The computing device 500 also includes an access device 540 that enables the computing device 500 to communicate via one or more networks 560. Examples of these networks include a public switched telephone network (PSTN), a local area network (LAN), a wide area network (WAN), a personal area network (PAN), or a combination of communication networks such as the Internet. The access device 540 may include one or more of any type of network interface (e.g., a network interface card (NIC)) that is wired or wireless, such as an IEEE 802.11 wireless local area network (WLAN) wireless interface, a world-wide interoperability for microwave access (Wi-MAX) interface, an Ethernet interface, a universal serial bus (USB) interface, a cellular network interface, a Bluetooth interface, and a near field communication (NFC).

[0088] In one embodiment of the present invention, the above components of the computing device 500 and Figure 5 Other components not shown in the figure may also be connected to each other, for example, via a bus. It should be understood that Figure 5 The computing device structure block diagram shown is only for the purpose of illustration, and is not intended to limit the scope of the present invention. Those skilled in the art may add or replace other components as needed.

[0089] The computing device 500 may be any type of stationary or mobile computing device, including a mobile computer or mobile computing device (e.g., a tablet computer, a personal digital assistant, a laptop computer, a notebook computer, a netbook, etc.), a mobile phone (e.g., a smart phone), a wearable computing device (e.g., a smart watch, smart glasses, etc.), or other types of mobile devices, or a stationary computing device such as a desktop computer or a personal computer (PC). The computing device 500 may also be a mobile or stationary server.

[0090] The processor 520 is used to execute the following computer program / instruction, which implements the steps of the above-mentioned code optimization method when executed by the processor.

[0091] Each embodiment of the present invention is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the computing device embodiment, since it is basically similar to the code optimization method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the code optimization method embodiment.

[0092] An embodiment of the present invention further provides a computer-readable storage medium storing a computer program / instruction, which implements the steps of the above-mentioned code optimization method when executed by a processor.

[0093] Each embodiment of the present invention is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the computer-readable storage medium embodiment, since it is basically similar to the code optimization method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the code optimization method embodiment.

[0094] An embodiment of the present invention further provides a computer program product, including a computer program / instruction, which implements the steps of the above-mentioned code optimization method when executed by a processor.

[0095] The above is a schematic scheme of a computer program product of this embodiment. It should be noted that the technical scheme of the computer program product and the technical scheme of the above-mentioned code optimization method belong to the same concept, and the details not described in detail in the technical scheme of the computer program product can be referred to the description of the technical scheme of the above-mentioned code optimization method.

[0096] The above describes specific embodiments of the present invention. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the accompanying drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0097] The computer instructions include computer program codes, which may be in source code form, object code form, executable files or some intermediate forms, etc. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium, etc. It should be noted that the content contained in the computer-readable medium may be appropriately increased or decreased according to the requirements of patent practice. For example, in some regions, according to patent practice, computer-readable media do not include electric carrier signals and telecommunication signals.

[0098] It should be noted that, for the convenience of description, the aforementioned method embodiments are all described as a series of action combinations, but those skilled in the art should be aware that the embodiments of the present invention are not limited by the described action sequence, because according to the embodiments of the present invention, certain steps can be performed in other sequences or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the embodiments of the present invention.

[0099] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0100] The preferred embodiments of the present invention disclosed above are only used to help explain the present invention. The optional embodiments do not describe all the details in detail, nor do they limit the invention to the specific implementation methods described. Obviously, many modifications and changes can be made according to the content of the embodiments of the present invention. The present invention selects and specifically describes these embodiments in order to better explain the principles and practical applications of the embodiments of the present invention, so that those skilled in the art can understand and use the present invention well. The present invention is limited only by the claims and their full scope and equivalents.

Claims

1. A code optimization method, characterized in that: include: Obtaining the code to be optimized of the target program, wherein the code to be optimized includes shader variant information; Execute a test task for the target program to obtain a test result, and determine target variant information according to the test result, wherein the target variant information is variant information referenced by the test task; Based on the target variant information, a trimming process is performed on the shader variant information in the code to be optimized to obtain a target optimized code.

2. The method according to claim 1, characterized in that The executing the test task for the target program to obtain a test result, and determining the target variant information according to the test result, includes: In the shader variant information, material variant information related to the material and non-material variant information unrelated to the material are determined; Based on the non-material variant information, executing a test task for the target program to obtain a test result; Determine, in the non-material variant information, first variant information referenced by the test task according to the test result; The first variation information is combined with the material variation information to obtain the target variation information.

3. The method according to claim 2, characterized in that The performing of the test task for the target program based on the non-material variant information to obtain the test result includes: Deleting the non-material variant information to obtain a test code; The test code is used to execute a test task for the target program, to determine the variant information to be supplemented, and to use the variant information to be supplemented as the test result, wherein the variant information to be supplemented is non-material variant information required to execute the test task.

4. The method according to claim 1, characterized in that: The step of performing a trimming process on the shader variant information in the code to be optimized based on the target variant information to obtain a target optimized code includes: Variant information different from the target variant information is deleted from the shader variant information, and optimized code is obtained based on the remaining variant information.

5. The method according to claim 1, characterized in that After performing a trimming process on the shader variant information in the code to be optimized based on the target variant information to obtain the target optimized code, the method further includes: receiving a cropping request, wherein the cropping request includes information of a variant to be cropped; Based on the to-be-cut variant information, a secondary cutting process is performed on the shader variant information to obtain a secondary optimized code.

6. The method according to claim 5, characterized in that After executing the test task for the target program to obtain a test result and determining the target variant information according to the test result, the method further includes: In a case where the target variant information includes the to-be-tailored variant information, the to-be-tailored variant information is added to the shader variant information.

7. A code optimization device, characterized in that: include: An acquisition module is configured to acquire the code to be optimized of the target program, wherein the code to be optimized includes shader variant information; A determination module is configured to execute a test task for the target program to obtain a test result, and determine target variant information according to the test result, wherein the target variant information is variant information referenced by the test task; The trimming module is configured to perform trimming processing on the shader variant information in the code to be optimized based on the target variant information to obtain a target optimized code.

8. A computing device, characterized in that include: Memory and processor; The memory is used to store computer programs / instructions, and the processor is used to execute the computer programs / instructions. When the computer program / instructions are executed by the processor, the steps of the code optimization method according to any one of claims 1 to 6 are implemented.

9. A computer-readable storage medium, characterized in that: It stores a computer program / instruction, which, when executed by a processor, implements the steps of the code optimization method described in any one of claims 1 to 6.

10. A computer program product, characterized in that The method comprises a computer program / instruction, which, when executed by a processor, implements the steps of the code optimization method according to any one of claims 1 to 6.