Code generation method, device, computer readable medium and program product

By automatically generating dispatch code, the complexity of manually writing binding code in the integration of GLSL shaders and C++ renderers is solved, the efficiency, accuracy and maintainability of code generation are improved, and the development process is simplified.

CN119356682BActive Publication Date: 2025-09-30SHANGHAI BILIBILI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411397270.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-10-08
Publication Date
2025-09-30
Estimated Expiration
2044-10-08

AI Technical Summary

Technical Problem

In the existing technology, GLSL shaders and C++ renderers run in different environments, resulting in the need to manually write a large amount of complex "binding code" to integrate GLSL shader code into the C++ renderer. In addition, different developers have different writing habits, resulting in inconsistent performance and difficult maintenance.

Method used

By parsing the shader code, generating parsing results, and automatically generating scheduling codes based on multiple code templates to represent the renderer's scheduling process for the shader, it ensures that multiple code templates correspond one-to-one to multiple links in the scheduling process, thereby improving generation efficiency, accuracy, and maintainability.

Benefits of technology

It realizes automatic generation of scheduling code, improves the efficiency, accuracy and maintainability of code generation, simplifies the binding code writing process, and reduces the maintenance difficulty.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119356682B_ABST
    Figure CN119356682B_ABST
Patent Text Reader

Abstract

The present application provides a code generation method, device, computer-readable medium, and program product. A specific implementation of the present application includes: parsing shader code to generate a parsing result; and generating, based on the parsing result and multiple code templates, a scheduling code for representing the process of scheduling a renderer for a shader, wherein the multiple code templates correspond one-to-one to multiple steps in the scheduling process. The present application provides a method for automatically generating scheduling code that indicates the process of scheduling a renderer for a shader, thereby improving the efficiency, accuracy, consistency, and maintainability of scheduling code generation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a code generation method, device, computer-readable medium, and program product. Background Art

[0002] GLSL (OpenGL Shading Language) shaders run on the GPU (Graphics Processing Unit), while the C++ renderer runs on the CPU (Central Processing Unit). Because GLSL shaders and C++ renderers run in different environments and use different data types and memory management methods, integrating GLSL shader code into the C++ renderer typically requires manually writing a large amount of "binding code." This "binding code" is the code segment in the C++ renderer that interacts with the GLSL shader. Manually writing code is time-consuming and complex. Furthermore, due to different understandings and writing habits of different developers, the performance of code written by different developers varies, making subsequent maintenance difficult.

[0003] This section is intended to provide a background or context to the embodiments of the present application that are recited in the claims. Nothing herein is admitted to be prior art by virtue of its inclusion in this section. Summary of the Invention

[0004] Multiple aspects of the present application provide a code generation method, device, computer-readable storage medium and program product for automatically generating scheduling code that instructs a renderer on a shader scheduling process, thereby improving the accuracy, consistency and maintainability of the scheduling code.

[0005] In one aspect of the present application, a code generation method is provided, comprising: parsing the code of a shader and generating a parsing result; generating a scheduling code for characterizing the scheduling process of a renderer for a shader based on the parsing result and a plurality of code templates, wherein the plurality of code templates correspond one-to-one to a plurality of links in the scheduling process.

[0006] On the other hand, the present application provides a code generation device, including: a parsing module, configured to parse the code of the shader and generate a parsing result; a generation module, configured to generate a scheduling code for representing the scheduling process of the renderer for the shader based on the parsing result and multiple code templates, wherein the multiple code templates correspond one-to-one to multiple links in the scheduling process.

[0007] Another aspect of the present application provides an electronic device comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the code generation method shown above.

[0008] In another aspect of the present application, a computer-readable storage medium is provided, on which computer program instructions are stored. The computer program instructions can be executed by a processor to implement the code generation method shown above.

[0009] In another aspect of the present application, a computer program product is provided, comprising a computer program, wherein when the computer program is executed by a processor, the code generation method as shown above is implemented.

[0010] In the solution provided in the embodiment of the present application, a parsing result is generated by parsing the code of the shader; based on the parsing result and multiple code templates, a scheduling code is generated to characterize the scheduling process of the renderer to the shader, wherein the multiple code templates correspond one-to-one to multiple links in the scheduling process, thereby providing a method for automatically generating a scheduling code that indicates the scheduling process of the renderer to the shader, thereby improving the generation efficiency, accuracy, consistency and maintainability of the scheduling code. BRIEF DESCRIPTION OF THE DRAWINGS

[0011] In order to more clearly illustrate the technical solutions in the embodiments of the present application, a brief introduction will be given below to the drawings required for use in the embodiments or descriptions of the prior art. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0012] Other features, objects and advantages of the present application will become more apparent upon reading the detailed description of non-limiting embodiments made with reference to the following drawings:

[0013] Figure 1 A flowchart of a code generation method provided in one embodiment of the present application;

[0014] Figure 2 A flowchart of a code generation method provided in another embodiment of the present application;

[0015] Figure 3 A schematic diagram of the structure of a code generation device provided in one embodiment of the present application;

[0016] Figure 4 This is a structural diagram of a device suitable for implementing the solution in the embodiment of the present application. The same or similar reference numerals in the accompanying drawings represent the same or similar components. DETAILED DESCRIPTION

[0017] To make the purpose, technical solutions, and advantages of the embodiments of this application more clear, the technical solutions in the embodiments of this application will be clearly and completely described below in conjunction with the drawings in the embodiments of this application. Obviously, the described embodiments are part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.

[0018] In a typical configuration of the present application, the terminal and the equipment of the service network each include one or more processors (CPUs), input / output interfaces, network interfaces and memories.

[0019] Memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.

[0020] Computer-readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology for information storage. The information can be computer program instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc-read only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic tape disk storage or other magnetic storage devices or any other non-transmission medium that can be used to store information that can be accessed by a computing device.

[0021] An embodiment of the present application provides a code generation method, which parses the code of a shader to generate a parsing result; based on the parsing result and multiple code templates, generates a scheduling code for characterizing the scheduling process of a renderer for a shader, wherein the multiple code templates correspond one-to-one to multiple links in the scheduling process, thereby automatically generating a scheduling code indicating the scheduling process of a renderer for a shader, thereby improving the accuracy, consistency and maintainability of the scheduling code.

[0022] In actual scenarios, the execution subject of this method can be a user device, or a device formed by integrating a user device and a network device through a network, or an application running on the above device. The above user device includes but is not limited to various terminal devices such as computers, mobile phones, tablets, smart watches, and bracelets. The above network device includes but is not limited to network hosts, single network servers, multiple network server sets, or cloud computing-based computer collections, which can be used to implement some processing functions when setting an alarm. Here, the cloud is composed of a large number of hosts or network servers based on cloud computing (Cloud Computing), where cloud computing is a type of distributed computing, a virtual computer composed of a group of loosely coupled computers.

[0023] Figure 1 The following is a process flow of a code generation method provided by an embodiment of the present application. The code generation method includes at least the following processing steps:

[0024] Step 101: parse the shader code and generate a parsing result.

[0025] In this embodiment, the execution subject can obtain the source code of the shader remotely or locally via a wired network connection or a wireless network connection, and parse the source code of the shader to determine the variable parameters and the processing logic for the variable parameters included in the source code. The shader can be various types of shaders, including but not limited to vertex shaders and fragment shaders.

[0026] As an example, an automated script scans the shader source code, identifying all declared uniform variables, input interfaces, output interfaces, and samplers (textures) and other variable parameters. Furthermore, using GLSL's standardized annotations, it extracts common variable declarations and type information.

[0027] After determining the variable parameters, the purpose and flow of each variable are determined by analyzing the function body in the shader source code, thereby determining the processing logic of the variable parameters.

[0028] Step 102 : Generate a scheduling code for representing a scheduling process of a renderer to a shader based on the parsing result and a plurality of code templates.

[0029] Among them, multiple code templates correspond one-to-one to multiple links in the scheduling process.

[0030] The renderer's scheduling of shaders can be divided into multiple stages based on key nodes. For example, these stages include data transfer and call stages. The data transfer stage represents the process of transferring data from the renderer to the shader, while the call stage represents the process of the renderer calling the shader to perform the rendering task.

[0031] For each of the multiple links, fill in the unfilled items in the code template corresponding to the link according to the analysis results to obtain the sub-scheduling code corresponding to the link; according to the timing relationship between the multiple links, combine the multiple sub-scheduling codes corresponding to the multiple links one by one to obtain the scheduling code.

[0032] For each link in multiple links, the code template corresponding to the link can be obtained in the following way: the developer writes standard execution code based on the information processing process required by the link, removes the part of the standard code that can be dynamically replaced (for example, variable parameters), and obtains the code template corresponding to the link.

[0033] To further illustrate the difference between this embodiment and the prior art, the following GLSL code example of a fragment shader is given:

[0034] #version 330core

[0035] layout(location=0)in vec3 aPos;

[0036] layout(location=1)in vec3 aColor;

[0037] out vec3 ourColor;

[0038] uniformint x;

[0039] uniform vec2 y;

[0040] uniform mat4 z;

[0041] uniform sampler2D texture1;

[0042] uniform sampler2D texture2;

[0043] void main()

[0044] {

[0045] / / Customized main function code for calculation and output

[0046]

[0047] }

[0048] The fragment shader code above explicitly declares five attributes labeled "uniform," including int, vec2, mat4, and sampler2D. These attributes must be passed in wherever GLSL code is used. The attributes identified by sampler2D are samplers, meaning a texture must be passed in. In this example, two textures are required. The main() function handles these attributes and is customized to the shader's functionality.

[0049] In the normal manual code writing process, you need to set the five properties mentioned above in the C++ code you write, including three uniforms and two sampler2Ds, as shown in the following pseudo code:

[0050] / / Set x

[0051] glUseProgram(program)

[0052] auto location1=glGetUniformLocation(program,"x")

[0053] glUniform1i(location1,param1)

[0054] / / Set y

[0055] auto location2=glGetUniformLocation(program,“y”)

[0056] glUniform2f(location2,param2)

[0057] / / Set z

[0058] auto location3=glGetUniformLocation(program,“z”)

[0059] glUniformMatrix4fv(location3,param3)

[0060] / / Set texture1

[0061] glActiveTexture(GL_TEXTURE0);

[0062] glBindTexture(GL_TEXTURE_2D,texture0)

[0063] auto location4=glGetUniformLocation(program."texture1")

[0064] glUniform1i(location4,0)

[0065] / / Set texture2

[0066] glActiveTexture(GL_TEXTURE1);

[0067] glBindTexture(GL_TEXTURE_2D,texture1)

[0068] auto location5=glGetUniformLocation(program."texture2")

[0069] glUniform1i(location5,1)

[0070]

[0071] When the GLSL shader code finally needs to be executed, call the following function:

[0072] glDrawArrays()

[0073] As you can see, the amount of C++ code that needs to be written manually is large and complex, and the functions that need to be called are different depending on the types such as int, float, mat, and sampler2D.

[0074] In this embodiment, based on the analysis results of the shader source code and multiple code templates corresponding to multiple links in the scheduling process, scheduling code can be automatically generated to represent the renderer's scheduling process of the shader. While improving the code generation efficiency, the accuracy, consistency and maintainability of the scheduling code are improved.

[0075] In some optional implementations of this embodiment, the execution entity may perform step 101 as follows:

[0076] The first step is to generate an initial scheduling code for representing the scheduling process according to the parsing result and multiple code templates.

[0077] As an example, for each of the multiple links, fill in the unfilled items in the code template corresponding to the link according to the analysis results to obtain the sub-scheduling code corresponding to the link; according to the timing relationship between the multiple links, combine the multiple sub-scheduling codes corresponding to the multiple links one by one to obtain the initial scheduling code.

[0078] The second step is to merge the codes corresponding to the same type of scheduling operations in the initial scheduling code to obtain the scheduling code.

[0079] In this implementation, the scheduling operation refers to any operation in the process of scheduling the shader by the renderer, represented by the code in the initial scheduling code, such as an assignment operation to a variable.

[0080] Taking the above shader code as an example, in the data transmission link, variables X, Y, Z, texture1 and texture2 need to be set, which includes five setup operations. Among them, the setup operations of X, Y, and Z are the same type of scheduling operations, and the setup operations of texture1 and texture2 are the same type of scheduling operations.

[0081] By merging the code corresponding to similar dispatch operations, the five setup operations within the dispatch code can be reduced to two setup operations. This means that the setup operations for X, Y, and Z are treated as one, and the setup operations for texture1 and texture2 are treated as one. This reduces the number of communications between the CPU deploying the renderer and the GPU deploying the shader, thereby improving data processing efficiency. It should be noted that the code corresponding to similar dispatch operations can be merged within the sub-dispatching code corresponding to each link.

[0082] In some optional implementations of this embodiment, the multiple code templates include a data transmission template, and the multiple links include a data transmission link.

[0083] In this implementation, the execution subject may perform the first step as follows: generating data transmission code corresponding to the data transmission link in the initial scheduling code according to the variable parameters and data transmission template corresponding to the shader in the parsing result.

[0084] The data transfer code is used to instruct the renderer to pass target data corresponding to the variable parameter to the shader.

[0085] As an example, the automated script code is used to automatically fill in the data transfer template according to the variable parameters corresponding to the shader in the parsing result, and generate the data transfer code corresponding to the GLSL shader.

[0086] Among them, the data transmission template can be obtained in the following way: the developer writes the standard data transmission code based on the information processing process required by the renderer to the data transmission link of the shader, and removes the part of the standard data transmission code that can be dynamically replaced (for example, variable parameters) to obtain the data transmission template.

[0087] In this implementation, data transmission code for the data transmission link of the renderer to the shader is generated based on the parsing results and the data transmission template, thereby improving the generation efficiency, accuracy, consistency and maintainability of the data transmission code.

[0088] In some optional implementations of this embodiment, the execution subject may perform the automatic generation process of the data transmission code in the following manner:

[0089] First, the initial data transmission code is generated according to the variable parameters and the data transmission template.

[0090] In this implementation, an automated script code is used to automatically fill in a data transmission template according to variable parameters corresponding to the shader in the parsing result, and generate an initial data transmission code corresponding to the GLSL shader.

[0091] Then, according to the processing logic corresponding to the variable parameters in the parsing result, unused redundant variable parameters in the variable parameters are determined.

[0092] In some cases, the variable parameters declared in the shader code may not be used in the function body. Based on whether the shader processing logic uses the declared variable parameters, the variable parameters declared in the shader can be classified. If there are variable parameters that are not used by the processing logic, they are determined to be redundant variable parameters.

[0093] Finally, the codes corresponding to the redundant variable parameters in the initial data transmission code are deleted to obtain the data transmission code.

[0094] Because the extra variables are not used in the shader's processing logic, data transfer operations on them are meaningless. By deleting the code corresponding to the extra variables in the initial data transfer code, the data transfer code is streamlined, avoiding the performance loss caused by invalid operations on extra variables during the data transfer process.

[0095] In some optional implementations of this embodiment, the multiple code templates include a calling template, and the multiple links include a calling link.

[0096] In this implementation, the execution subject may perform the first step in the following manner: generating a calling code corresponding to the calling link in the initial scheduling code according to the parsing result and the calling template.

[0097] The calling code is used to indicate that the renderer calls the shader to perform the rendering task. For example, the calling code is specifically the code that uses the variable parameters in the shader.

[0098] As an example, automated script code is used to automatically fill in a call template based on the variable parameters and processing logic corresponding to the shader in the parsing result, and generate a call code corresponding to the GLSL shader.

[0099] Among them, the calling template can be obtained in the following way: the developer writes the standard calling code based on the information processing process required by the renderer to call the shader, and removes the part of the standard calling code that can be dynamically replaced (for example, variable parameters) to obtain the calling template.

[0100] In this implementation, the call code of the renderer's call to the shader is generated according to the parsing result and the call template, thereby improving the generation efficiency, accuracy, consistency and maintainability of the call code.

[0101] In some optional implementations of this embodiment, the execution entity may perform the second step in the following manner:

[0102] The codes corresponding to the same type of scheduling operations in the initial scheduling code are merged, and the environment recovery code is added to the initial scheduling code to obtain the scheduling code.

[0103] The environment restoration code is used to represent that after the shader completes the rendering task, the rendering environment is restored to its original state before the rendering task is executed.

[0104] OpenGL context and state management are crucial in graphics programming and rendering. OpenGL's state machine model means that every call to an OpenGL function may modify its internal state, such as the current shader, texture bindings, and vertex attributes. These state changes affect subsequent rendering operations. For GLSL shaders, the rendering context is the OpenGL context.

[0105] The purpose of restoring the rendering environment to its original state is to ensure that each rendering task (or renderer component) has a clean and consistent environment state when it is executed, avoiding unpredictable behavior of the current task due to state changes of the previous rendering task.

[0106] Before executing a rendering task, the current OpenGL state (such as currently bound textures, shaders, vertex arrays, etc.) needs to be recorded. This is usually done by querying the original state of OpenGL or using a custom data structure to track state changes. After saving the current state, the rendering task can freely change the state of OpenGL to execute its specific rendering logic. After the rendering task is completed, the previously saved state information is used to restore the OpenGL state to its original state before rendering began. This ensures that subsequent rendering tasks will not be affected by changes to the current task state.

[0107] In this implementation, in addition to merging similar scheduling operations in the code to improve scheduling efficiency, the scheduling code can also automatically restore the rendering environment to its original state before executing the rendering task, avoiding modifications to the rendering environment that affect other rendering tasks, making rendering tasks more controllable.

[0108] In some optional implementations of this embodiment, the execution subject may further perform the following operation: generating a renderer adapted to the shader according to the initialization template.

[0109] As an example, according to the initialization template, the following operations are performed to generate a renderer adapted for the shader: First, you need to create an instance of a renderer class. This class will contain all rendering-related states and logic. Then, inside the renderer object, you first need to initialize the graphics device (such as the OpenGL context, DirectX device, etc.). This step depends on the graphics API (Application Programming Interface) used. Then, load and compile the shader code. This usually includes vertex shaders and fragment shaders. Then, as needed, create other resources required for rendering, such as vertex buffers, index buffers, textures, etc. Then, you need to bind the shader program to the rendering pipeline and set up all necessary resources (such as vertex buffers, textures, etc.).

[0110] In this implementation, based on the generation of scheduling codes based on multiple code templates corresponding to multiple links of the scheduling process, a renderer adapted to the shader can be further generated according to the initialization template, thereby improving the information processing efficiency and accuracy of the entire process from generating the renderer to the renderer scheduling the shader.

[0111] In some optional implementations of this embodiment, the execution subject may further perform the following operations: updating the code template and / or the initialization template according to the received template update operation.

[0112] As an example, developers can update and optimize the code template and / or initialization template according to their own needs and actual conditions, and after obtaining the code template and / or initialization template, send a template update operation to the above-mentioned execution entity to update the code template and / or initialization template.

[0113] In this implementation, based on the iterative update of the code template and the initialization template, the matching degree between the target and the user needs and the actual situation can be maintained, thereby ensuring the usability and accuracy of the template.

[0114] In some optional implementations of this embodiment, the execution subject may further perform the following operations: executing a scheduling code to instruct a renderer to schedule a shader to perform a rendering task.

[0115] For example, the scheduling code includes sub-scheduling codes corresponding to multiple steps in the scheduling process. For each step, the sub-scheduling code corresponding to that step is executed to complete the processing task of that step. This continues until the sub-scheduling code for each step is completed according to the timing relationship between the multiple steps, thereby instructing the renderer to schedule the shader to perform the rendering task.

[0116] In this implementation, based on the automatically generated scheduling code, the renderer schedules the shader to execute the rendering task, thereby improving the execution efficiency and convenience of the rendering task.

[0117] In some optional implementations of this embodiment, the execution subject may instruct the renderer to schedule the shader to perform the rendering task based on the scheduling code in the following manner:

[0118] First, the data transfer code in the dispatch code is executed to instruct the renderer to transfer the target data to the shader.

[0119] The data transfer code in the scheduling code is the result of merging similar scheduling operations and removing the code corresponding to redundant variable parameters. This merging reduces the number of communications between the CPU and GPU during the data transfer process, improving communication efficiency. Removing the code corresponding to redundant variable parameters simplifies the data transfer code and increases its effectiveness. Consequently, executing the automatically generated data transfer code helps improve the convenience and efficiency of the data transfer process.

[0120] Then, the calling code in the dispatch code is executed to instruct the renderer to call the shader and perform the rendering task according to the target data.

[0121] The call code within the dispatch code is a call code that combines similar dispatch operations, reducing the number of communications between the CPU and GPU during the call process and improving communication efficiency. Therefore, executing the automatically generated data transfer code helps improve the convenience and efficiency of the call process.

[0122] Figure 2 The following is a process flow of a code generation method provided by an embodiment of the present application. The code generation method includes at least the following processing steps:

[0123] Step 201: parse the shader code and generate a parsing result.

[0124] Step 202: Generate initial data transmission code according to the variable parameters and data transmission template corresponding to the shader in the parsing result.

[0125] Step 203: determining unused redundant variable parameters in the variable parameters according to the processing logic corresponding to the variable parameters in the analysis result.

[0126] Step 204: Delete the codes corresponding to the redundant variable parameters in the initial data transmission code to obtain the data transmission code.

[0127] The data transfer code is used to instruct the renderer to pass target data corresponding to the variable parameter to the shader.

[0128] Step 205: Generate a calling code corresponding to the calling link in the initial scheduling code according to the parsing result and the calling template.

[0129] The calling code is used to indicate that the renderer calls the shader to perform the rendering task.

[0130] Step 206: Combine the data transmission code and the calling code to obtain an initial scheduling code.

[0131] Step 207: merge the codes corresponding to the same type of scheduling operations in the initial scheduling code, and add the environment recovery code to the initial scheduling code to obtain the scheduling code.

[0132] The environment restoration code is used to represent that after the shader completes the rendering task, the rendering environment is restored to its original state before the rendering task is executed.

[0133] Step 208: Execute the scheduling code to instruct the renderer to schedule the shader to perform the rendering task.

[0134] It can be seen from this embodiment that Figure 1 Compared with the corresponding embodiments, the code generation method in this embodiment specifically describes the generation process of data transmission code, the generation process of calling code, and the code performance optimization process of merging similar operations and adding environment recovery code. While improving the generation efficiency, accuracy, consistency and maintainability of the scheduling code, it further improves the information processing efficiency of the renderer's scheduling process of the shader based on the scheduling code.

[0135] In addition, the embodiment of the present application also provides a code generation device, the structure of which is as follows: Figure 3 shown.

[0136] A code generation device includes: a parsing module 301, configured to parse the code of a shader and generate a parsing result; a generation module 302, configured to generate a scheduling code for representing a renderer's scheduling process for the shader based on the parsing result and multiple code templates, wherein the multiple code templates correspond one-to-one to multiple links in the scheduling process.

[0137] In some optional implementations of this embodiment, the generation module 302 is further configured to: generate an initial scheduling code for characterizing the scheduling process based on the parsing results and multiple code templates; and merge codes corresponding to similar scheduling operations in the initial scheduling code to obtain a scheduling code.

[0138] In some optional implementations of this embodiment, multiple code templates include data transmission templates, multiple links include data transmission links, and the generation module 302 is further configured to: generate data transmission codes corresponding to the data transmission links in the initial scheduling code based on the variable parameters and data transmission templates corresponding to the shader in the parsing results, wherein the data transmission code is used to instruct the renderer to pass the target data corresponding to the variable parameters to the shader.

[0139] In some optional implementations of this embodiment, the generation module 302 is further configured to: generate an initial data transmission code based on the variable parameters and the data transmission template; determine the unused redundant variable parameters in the variable parameters based on the processing logic corresponding to the variable parameters in the parsing results; delete the code corresponding to the redundant variable parameters in the initial data transmission code to obtain the data transmission code.

[0140] In some optional implementations of this embodiment, multiple code templates include a calling template, multiple links include a calling link, and the generation module 302 is further configured to: generate a calling code corresponding to the calling link in the initial scheduling code based on the parsing results and the calling template, wherein the calling code is used to represent an instruction for the renderer to call the shader to perform the rendering task.

[0141] In some optional implementations of this embodiment, the generation module 302 is further configured to: merge the codes corresponding to similar scheduling operations in the initial scheduling code, and add the environment recovery code to the initial scheduling code to obtain the scheduling code, wherein the environment recovery code is used to represent that after the shader completes the rendering task, the rendering environment is restored to its original state before executing the rendering task.

[0142] In some optional implementations of this embodiment, the above-mentioned device further includes: an initialization module (not shown in the figure) configured to generate a renderer adapted to the shader according to the initialization template.

[0143] In some optional implementations of this embodiment, the above-mentioned device further includes: an updating module (not shown in the figure) configured to update the code template and / or the initialization template according to the received template updating operation.

[0144] In some optional implementations of this embodiment, the above-mentioned device further includes: an execution module (not shown in the figure) configured to execute a scheduling code to instruct the renderer to schedule the shader to perform a rendering task.

[0145] In some optional implementations of this embodiment, the execution module is further configured to: execute the data transfer code in the scheduling code, instructing the renderer to transfer target data to the shader; execute the calling code in the scheduling code, instructing the renderer to call the shader and perform the rendering task according to the target data.

[0146] In the code generation device provided by the embodiment of the present application, the parsing module parses the code of the shader and generates a parsing result; the generation module generates a scheduling code for characterizing the scheduling process of the renderer to the shader based on the parsing result and multiple code templates, wherein the multiple code templates correspond one-to-one to multiple links in the scheduling process, thereby providing a device for automatically generating a scheduling code that indicates the scheduling process of the renderer to the shader, thereby improving the generation efficiency, accuracy, consistency and maintainability of the scheduling code.

[0147] Based on the same inventive concept, an electronic device is also provided in an embodiment of the present application. The method corresponding to the electronic device can be the code generation method in the aforementioned embodiment, and its principle of solving the problem is similar to that of the method. The electronic device provided in an embodiment of the present application includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the methods and / or technical solutions of the aforementioned multiple embodiments of the present application.

[0148] The electronic device may be a user device, or a device formed by integrating a user device and a network device via a network, or an application running on the device. The user device includes, but is not limited to, computers, mobile phones, tablet computers, smart watches, wristbands, and other terminal devices. The network device includes, but is not limited to, network hosts, single network servers, multiple network server sets, or cloud computing-based computer collections, and can be used to implement some of the processing functions required for setting an alarm. Here, the cloud is composed of a large number of hosts or network servers based on cloud computing. Cloud computing is a type of distributed computing, consisting of a virtual computer composed of a group of loosely coupled computers.

[0149] Figure 4 The structure of a device suitable for implementing the method and / or technical solution in the embodiment of the present application is shown. The device 400 includes a central processing unit (CPU) 401, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 402 or the program loaded from the storage part 408 into the random access memory (RAM) 403. Various programs and data required for system operation are also stored in the RAM 403. The CPU 401, ROM 402 and RAM 403 are connected to each other through a bus 404. An input / output (I / O) interface 405 is also connected to the bus 404.

[0150] The following components are connected to the I / O interface 405: an input section 406 including a keyboard, a mouse, a touch screen, a microphone, an infrared sensor, etc.; an output section 407 including devices such as a cathode ray tube (CRT), a liquid crystal display (LCD), an LED display, an OLED display, etc., and a speaker; a storage section 408 including one or more computer-readable media such as a hard disk, an optical disk, a magnetic disk, a semiconductor memory, etc.; and a communication section 409 including a network interface card such as a LAN (Local Area Network) card, a modem, etc. The communication section 409 performs communication processing via a network such as the Internet.

[0151] In particular, the methods and / or embodiments in the embodiments of the present application can be implemented as computer software programs. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes program code for executing the method shown in the flowchart. When the computer program is executed by the central processing unit (CPU) 401, the above-mentioned functions defined in the method of the present application are performed.

[0152] Another embodiment of the present application further provides a computer-readable storage medium having computer program instructions stored thereon. The computer program instructions can be executed by a processor to implement the methods and / or technical solutions of any one or more embodiments of the present application.

[0153] Specifically, the present embodiment can adopt any combination of one or more computer-readable media. The computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. The computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or component, or any combination thereof. More specific examples (non-exhaustive list) of computer-readable storage media include: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In this document, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device.

[0154] A computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, which carries computer-readable program code. This propagated data signal may take a variety of forms, including, but not limited to, electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transport a program for use by or in conjunction with an instruction execution system, apparatus, or device.

[0155] Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.

[0156] Computer program code for performing the operations of the present application can be written in one or more programming languages, or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, C++, and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a stand-alone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computer (e.g., through the Internet using an Internet service provider).

[0157] The flow chart or block diagram in the accompanying drawings illustrate the possible architecture, functions and operations of the equipment, methods and computer program products according to various embodiments of the present application. In this regard, each box in the flow chart or block diagram can represent a module, program segment or a part of code, and the module, program segment or a part of code include one or more executable instructions for realizing the logical function of the specification. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a sequence different from that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flow chart, and the combination of the boxes in the block diagram and / or flow chart can be implemented with a dedicated system for hardware that performs the function or operation of the specification, or can be implemented with a combination of dedicated hardware and computer instructions.

[0158] Those skilled in the art will clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0159] In the several embodiments provided in this application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or page components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.

[0160] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.

[0161] In addition, the functional units in the various embodiments of the present application may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or in the form of hardware plus software functional units.

[0162] The above-mentioned integrated unit implemented in the form of a software functional unit can be stored in a computer-readable storage medium. The above-mentioned software functional unit is stored in a storage medium and includes a number of instructions for causing a computer device (which can be a personal computer, server, or network device, etc.) or a processor to execute some steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and other media that can store program code.

[0163] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.

[0164] Furthermore, it is clear that the word "comprising" does not exclude other units or steps, and the singular does not exclude the plural. Multiple units or devices recited in a device claim may also be implemented by a single unit or device through software or hardware. Terms such as "first" and "second" are used to indicate names and do not imply any particular order.

Claims

1. A code generation method, wherein: The method comprises: Parse the shader code and generate parsing results; Generate, based on the parsing result and a plurality of code templates, a scheduling code for representing a scheduling process of a renderer for the shader, wherein the plurality of code templates correspond one-to-one to a plurality of links in the scheduling process, the plurality of code templates include a data transmission template, and the plurality of links include a data transmission link; The generating, based on the parsing result and a plurality of code templates, a scheduling code for representing a scheduling process of the renderer to the shader, comprises: Generating an initial scheduling code for representing the scheduling process according to the parsing result and the multiple code templates, including: generating a data transmission code corresponding to the data transmission link in the initial scheduling code according to the variable parameters corresponding to the shader in the parsing result and the data transmission template, wherein the data transmission code is used to instruct the renderer to transfer target data corresponding to the variable parameters to the shader; The codes corresponding to the same type of scheduling operations in the initial scheduling code are merged to obtain the scheduling code.

2. The method according to claim 1, wherein The step of generating a data transmission code corresponding to the data transmission link in the initial scheduling code according to the variable parameters corresponding to the shader in the parsing result and the data transmission template includes: generating an initial data transmission code according to the variable parameters and the data transmission template; Determining unused redundant variable parameters among the variable parameters according to the processing logic corresponding to the variable parameters in the analysis result; The codes corresponding to the redundant variable parameters in the initial data transmission code are deleted to obtain the data transmission code.

3. The method according to claim 1, wherein The plurality of code templates include a calling template, the plurality of links include a calling link, and Generating an initial scheduling code for representing the scheduling process according to the parsing result and the multiple code templates includes: A calling code corresponding to the calling link in the initial scheduling code is generated according to the parsing result and the calling template, wherein the calling code is used to indicate that the renderer calls the shader to perform a rendering task.

4. The method according to claim 1, wherein The merging of codes corresponding to similar scheduling operations in the initial scheduling code to obtain the scheduling code includes: Merge codes corresponding to similar scheduling operations in the initial scheduling code, and add environment recovery code to the initial scheduling code to obtain the scheduling code, wherein the environment recovery code is used to represent that after the shader completes the rendering task, the rendering environment is restored to its original state before executing the rendering task.

5. The method according to any one of claims 1 to 4, wherein Also includes: A renderer adapted to the shader is generated according to the initialization template.

6. The method according to claim 5, wherein: Also includes: According to the received template update operation, the code template and / or the initialization template is updated.

7. The method according to claim 3, wherein: Also includes: The scheduling code is executed to instruct the renderer to schedule the shader to perform the rendering task.

8. The method according to claim 7, wherein: The executing the scheduling code to instruct the renderer to schedule the shader to perform the rendering task includes: Executing a data transmission code in the scheduling code to instruct the renderer to transmit the target data to the shader; The calling code in the scheduling code is executed to instruct the renderer to call the shader and perform the rendering task according to the target data.

9. A code generating device, wherein: The device comprises: The parsing module is configured to parse the shader code and generate parsing results; a generation module configured to generate a scheduling code for representing a scheduling process of a renderer for the shader based on the parsing result and a plurality of code templates, wherein the plurality of code templates correspond one-to-one to a plurality of links in the scheduling process, the plurality of code templates include a data transmission template, and the plurality of links include a data transmission link; The generation module is further configured to: Generating an initial scheduling code for representing the scheduling process according to the parsing result and the multiple code templates, including: generating a data transmission code corresponding to the data transmission link in the initial scheduling code according to the variable parameters corresponding to the shader in the parsing result and the data transmission template, wherein the data transmission code is used to instruct the renderer to transfer target data corresponding to the variable parameters to the shader; The codes corresponding to the same type of scheduling operations in the initial scheduling code are merged to obtain the scheduling code.

10. An electronic device, comprising: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 8.

11. A computer-readable medium having computer program instructions stored thereon, wherein the computer program instructions can be executed by a processor to implement the method according to any one of claims 1 to 8.

12. A computer program product comprising a computer program, wherein when the computer program is executed by a processor, the method according to any one of claims 1 to 8 is implemented.