Method, device, storage medium and program product for generating shader file
By writing shader template files in an interpreted language and generating shader files using an interface program, the problem of low verification efficiency of shader modules in existing technologies is solved, and the efficiency of shader file generation and GPU chip development is improved.
Patent Information
- Application Number
- CN202410382713.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-29
- Publication Date
- 2024-11-22
- Estimated Expiration
- 2044-03-29
AI Technical Summary
In the existing technology, the verification efficiency of the shader module is low, which leads to low development efficiency of GPU chips. In addition, the shader file generation efficiency is low, making it difficult to reuse and modify.
Shader template files are written using an interpreted language, and instruction information is passed to the program module of a compiled language through an interface program to generate shader files. The files are generated using the instruction and operand range indicated by the schema file, and constraint information and random generation of instructions and operands are supported.
It improves the efficiency of shader file generation, enhances the reusability of shader modules and the development efficiency of GPU chips, and reduces the workload of users manually assigning operands.
Smart Images

Figure CN118192952B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of image processing technology, and in particular to a method, device, storage medium and program product for generating a shader file. Background Art
[0002] In the development process of graphics processing unit (GPU) chips, it is usually necessary to develop a GPU behavior model to build a virtualization platform for early software development. In order to ensure the accuracy of the functions of the GPU behavior model, it is necessary to perform necessary verification work on it, and the verification of the shader module is an important part of it. The verification efficiency of the shader module will directly affect the development efficiency of the GPU chip. Therefore, how to improve the verification efficiency of the shader module has become a problem that needs to be solved urgently. Summary of the invention
[0003] In view of this, the embodiments of the present disclosure provide a method, device, storage medium and program product for generating a shader file to solve at least one problem existing in the prior art.
[0004] To achieve the above objectives, the technical solution of the embodiment of the present disclosure is implemented as follows:
[0005] In a first aspect, an embodiment of the present disclosure provides a method for generating a shader file, comprising:
[0006] Obtaining a shader template file through a first program module; the shader template file is written in a first language; the first language includes an interpreted language; the shader template file includes instruction information;
[0007] Executing the shader template file to call a first interface program to pass the instruction information in the shader template file to a second program module; the second program module is written in a second language; the second language includes a compiled language;
[0008] The second program module generates a shader file according to the instruction information.
[0009] In an optional embodiment, the method further includes:
[0010] Acquire an architecture file through the second program module; the architecture file is used to indicate instructions and operands available for the shader file;
[0011] The second program module generates a shader file according to the instruction information, including:
[0012] The second program module generates a shader file according to the instruction information within the range of instructions and operands indicated by the architecture file.
[0013] In an optional implementation, the architecture file includes: an instruction information file, the instruction information file includes an instruction set and an operand set corresponding to each instruction in the instruction set; the second program module generates a shader file according to the instruction information within the range of instructions and operands indicated by the architecture file, including:
[0014] Querying the instruction information file, and determining the operand set corresponding to each instruction in the instruction information according to the instruction set and the operand set;
[0015] Generate an operand corresponding to each instruction according to the operand set;
[0016] Generate the instruction according to the operand corresponding to each instruction;
[0017] The shader file is generated according to the generated multiple instructions.
[0018] In an optional implementation, the instruction information includes constraint information of operands, and the constraint information of operands is used to constrain an optional set of operands; the architecture file further includes: an operand information file, and the operand information file includes an optional set of elements of each operand and a selection weight of each element in the optional set; and generating operands corresponding to each instruction according to the operand set includes:
[0019] Determining the selectable set and the selection weight of the elements of each operand in the operand set according to the operand information file;
[0020] Determining the constrained optional set according to the constraint information of the operands;
[0021] The operand is randomly generated according to the selection weight of each element in the optional set after the constraint.
[0022] In an optional implementation, the executing the shader template file to call the first interface program to pass the instruction information in the shader template file to the second program module includes:
[0023] The first program module executes the shader template file to call the first interface program to sequentially send the instruction information of each instruction to be generated to the second program module;
[0024] The second program module calls a second interface program, receives the instruction information of each instruction to be generated in sequence, and converts the instruction information from the first language to the second language.
[0025] In an optional implementation, generating the shader file according to the generated multiple instructions includes:
[0026] Generating an instruction assembly of the instructions according to the generated multiple instructions;
[0027] The instruction assembly is converted into the shader file.
[0028] In an optional embodiment, the method further includes:
[0029] After each instruction is generated, generation completion information of the instruction is generated;
[0030] The second interface program is called to convert the generation completion information of the instruction from the second language to the first language and send it to the first interface program, wherein the generation completion information is used to instruct the first interface program to send instruction information of the next instruction.
[0031] In an optional embodiment, the method further includes:
[0032] After receiving the generation completion information of the last instruction, the first interface program transmits the assembly command to the second program module;
[0033] The generating the assembly of the instruction comprises:
[0034] In response to the assembly command, all generated instructions are packaged to generate an assembly of the instructions.
[0035] In a second aspect, an embodiment of the present disclosure provides a device for generating a shader file, comprising:
[0036] A first program module is configured to: obtain a shader template file; the shader template file is written in a first language; the first language includes an interpreted language; the shader template file includes instruction information; execute the shader template file to call a first interface program to pass the instruction information in the shader template file to a second program module; the second program module is written in a second language; the second language includes a compiled language;
[0037] The second program module is configured to generate a shader file according to the instruction information.
[0038] In an optional implementation, the second program module includes:
[0039] An architecture file parser is configured to: obtain an architecture file; the architecture file is used to indicate instructions and operands available for the shader file;
[0040] The shader file generation module is configured to generate a shader file according to the instruction information within the range of instructions and operands indicated by the architecture file.
[0041] In an optional implementation, the architecture file includes: an instruction information file, the instruction information file includes an instruction set and an operand set corresponding to each instruction in the instruction set; the shader file generation module includes:
[0042] The instruction generator is configured to: query the instruction information file, and determine the operand set corresponding to each instruction in the instruction information according to the instruction set and the operand set;
[0043] An operand generator is configured to: generate an operand corresponding to each instruction according to the operand set;
[0044] The instruction generator is further configured to: generate the instruction according to the operand corresponding to each instruction;
[0045] The instruction assembler is configured to generate the shader file according to the generated multiple instructions.
[0046] In an optional implementation, the instruction information includes constraint information of operands, and the constraint information of operands is used to constrain an optional set of operands; the architecture file further includes: an operand information file, and the operand information file includes an optional set of elements of each operand and a selection weight of each element in the optional set;
[0047] The operand generator is specifically configured to: determine the optional set and the selection weight of the elements of each operand in the operand set according to the operand information file; determine the optional set after constraints according to the constraint information of the operand; and randomly generate the operand according to the selection weight of each element in the optional set after constraints.
[0048] In an optional implementation, the first interface program is further configured to: sequentially send the instruction information of each instruction to be generated to the second program module;
[0049] The second program module also includes:
[0050] The second interface program is configured to: sequentially receive the instruction information of each instruction to be generated, and convert the instruction information from the first language to the second language.
[0051] In an optional implementation, the instruction generator is further configured to: generate an instruction assembly of the instructions according to the generated multiple instructions;
[0052] The instruction assembler is specifically configured to convert the instruction assembly into the shader file.
[0053] In an optional implementation, the instruction generator is further configured to: generate generation completion information of the instruction each time after generating an instruction; the generation completion information is used to instruct the first interface program to send instruction information of the next instruction;
[0054] The second interface program is further configured to: convert the generation completion information of the instruction from the second language into the first language and send the converted information to the first interface program.
[0055] In an optional implementation, the first interface program is further configured to: after receiving the generation completion information of the last instruction, pass the assembly command to the second program module;
[0056] The instruction generator is specifically configured to: in response to the assembly command, pack all generated instructions to generate an assembly of the instructions.
[0057] In a third aspect, an embodiment of the present disclosure provides a computer device, comprising a memory, a processor, and a computer program stored in the memory; when the processor executes the computer program, the method for generating a shader file described in any of the above embodiments is implemented.
[0058] In a fourth aspect, an embodiment of the present disclosure provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method for generating a shader file described in any of the above embodiments is implemented.
[0059] In a fifth aspect, an embodiment of the present disclosure provides a computer program product, wherein the computer program product includes a computer program, and when the computer program is executed by a processor, the method for generating a shader file described in any of the above embodiments is implemented.
[0060] In the technical solution provided by the present disclosure, the first program module can obtain a shader template file, and call a first interface program to pass the instruction information in the shader template file to the second program module, and the second program module can further generate a shader template file according to the instruction information within the range of instructions and operands indicated by the architecture file. On the one hand, the shader template file can be written in an interpreted language. Compared with directly using a compiled language to write a shader assembly, using an interpreted language to write a shader template file can greatly improve the writing efficiency, thereby improving the generation efficiency of the shader file; on the other hand, the user only needs to provide a shader template file and an architecture file, without having to assign values to the operands of each instruction in the shader file, thereby further improving the generation efficiency of the shader file. BRIEF DESCRIPTION OF THE DRAWINGS
[0061] Figure 1 A schematic diagram of a method for generating a shader file provided in an embodiment of the present disclosure Figure 1 ;
[0062] Figure 2 Schematic diagram of a device for generating a shader file provided in an embodiment of the present disclosure Figure 1 ;
[0063] Figure 3 A schematic diagram of a method for generating a shader file provided in an embodiment of the present disclosure Figure 2 ;
[0064] Figure 4 A schematic diagram of a flow chart of a method for generating operands provided in an embodiment of the present disclosure;
[0065] Figure 5 A schematic diagram of a method for generating a shader file provided in an embodiment of the present disclosure Figure 3 ;
[0066] Figure 6 Schematic diagram of a device for generating a shader file provided in an embodiment of the present disclosure Figure 2 ;
[0067] Figure 7 Schematic diagram of a device for generating a shader file provided in an embodiment of the present disclosure Figure 3 ;
[0068] Figure 8 A schematic diagram of a computer device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0069] The exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the specific embodiments set forth herein. On the contrary, these embodiments are provided in order to enable a more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.
[0070] In the following description, a large number of specific details are given to provide a more thorough understanding of the present disclosure. However, it is obvious to those skilled in the art that the present disclosure can be implemented without one or more of these details. In other examples, in order to avoid confusion with the present disclosure, some technical features known in the art are not described; that is, all features of actual embodiments are not described here, and well-known functions and structures are not described in detail.
[0071] In the drawings, like reference numerals refer to like elements throughout.
[0072] It should be understood that spatial relationship terms such as "under", "below", "below", "under", "above", "above", etc., may be used here for convenience of description to describe the relationship between an element or feature shown in the figure and other elements or features. It should be understood that in addition to the orientation shown in the figure, the spatial relationship terms are intended to also include different orientations of the device in use and operation. For example, if the device in the accompanying drawings is turned over, then the elements or features described as "under other elements" or "under it" or "under it" will be oriented as "on" other elements or features. Therefore, the exemplary terms "under" and "under" may include both upper and lower orientations. The device can be oriented otherwise (rotated 90 degrees or other orientations) and the spatial description terms used herein are interpreted accordingly.
[0073] The purpose of the terms used herein is only to describe specific embodiments and is not intended to be a limitation of the present disclosure. When used herein, the singular forms "one", "an" and "said / the" are also intended to include plural forms, unless the context clearly indicates otherwise. It should also be understood that the terms "consisting of" and / or "comprising", when used in this specification, determine the presence of the features, integers, steps, operations, elements and / or parts, but do not exclude the presence or addition of one or more other features, integers, steps, operations, elements, parts and / or groups. When used herein, the term "and / or" includes any and all combinations of the relevant listed items.
[0074] In the process of GPU chip development, it is usually necessary to develop a GPU behavior model to build a virtualization platform for early software development. In order to ensure the accuracy of the functions of the GPU behavior model, it is necessary to perform necessary verification work on it. The verification of the shader module is an important part of it. The verification efficiency of the shader module will directly affect the development efficiency of the GPU chip.
[0075] In the verification process of the shader module, it is necessary to construct a large number of shader use cases of different scenes for testing. The traditional shader use case construction method requires the user to hand-write the shader assembly, and then convert the shader assembly into a shader file through the GPU assembler, or requires the user to hand-write the shader high-level language, and then generate the shader file through the GPU compiler. Here, the shader file is a binary file that the GPU can directly execute. However, by the user hand-writing the shader assembly or the hand-writing shader high-level language to generate the shader file, the user needs to design each instruction according to the function of the shader and assign each operand (Operand) in each instruction, the workload is large, resulting in a low efficiency of the shader file generation. In addition, if the architecture of the shader changes, the entire use case needs to be rewritten, and the use case that has been written cannot be modified and reused, resulting in poor reusability of the shader use case, and then also causing the problem of low efficiency of shader file generation. Therefore, how to improve the generation efficiency of the shader file has become a problem to be solved at present.
[0076] In this regard, the present disclosure proposes the following implementation modes.
[0077] The present invention provides a method for generating a shader file. Figure 1 A schematic diagram of a method for generating a shader file provided in an embodiment of the present disclosure Figure 1 ,like Figure 1 As shown, the method for generating a shader file includes the following steps:
[0078] Step S10: obtaining a shader template file through a first program module; the shader template file is written in a first language; the first language includes an interpreted language; the shader template file includes instruction information;
[0079] Step S20: executing the shader template file to call the first interface program to pass the instruction information in the shader template file to a second program module; the second program module is written in a second language; the second language includes a compiled language;
[0080] Step S30: the second program module generates a shader file according to the instruction information.
[0081] In the disclosed embodiment, a shader file may be generated using a shader file generating device including a first program module and a second program module. Figure 2 Schematic diagram of a shader file generation device provided in an embodiment of the present disclosure Figure 1 , below, we will combine Figure 1 and Figure 2 The method for generating a shader file provided in an embodiment of the present disclosure is described.
[0082] In some embodiments, the process of executing step S10 may include: obtaining a shader template file 300 through the first program module 100, the shader template file 300 is written in a first language, the first language includes an interpreted language, and the shader template file 300 includes instruction information.
[0083] In the disclosed embodiment, the first program module 100 may obtain a shader template file 300 written in a first language, the shader template file 300 including instruction information, which may be used to indicate basic information of each instruction in an instruction sequence required to generate the shader file.
[0084] In some specific examples, the first language may be one of Python, JavaScript, Perl, and Shell.
[0085] In some embodiments, Figure 2 As shown, the first program module 100 may include a first interface program 101 .
[0086] In a specific example, the first interface program 101 may include an application programming interface (API), which may be user-oriented and allow the user to input the shader template file 300 .
[0087] In some embodiments, the process of executing step S20 may include: executing the shader template file 300 to call the first interface program 101 to pass the instruction information in the shader template file 300 to the second program module 200 .
[0088] In the embodiment of the present disclosure, the second program module 200 is written in a second language, and the second language includes a compiled language.
[0089] In some specific examples, the second language may be one of C++, C, Delphi, and Golang.
[0090] In some embodiments, the process of executing step S30 may include: the second program module 200 generates a shader file 500 according to the instruction information.
[0091] In the embodiment of the present disclosure, the shader template file can be written and input by the user, and the shader file 500 can be generated according to the instruction information in the shader template file 300 input by the user. The first program module 100 can pass the instruction information in the shader template file 300 to the second program module 200, and the second program module 200 can further generate the shader file 500 according to the instruction information. The shader template file 300 can be written in a first language, and the first language includes an interpreted language, that is, the user only needs to write the shader template file 300 in an interpreted language. Compared with directly using a compiled language to write a shader assembly, using an interpreted language to write the shader template file 300 can improve the writing efficiency, thereby improving the generation efficiency of the shader file 500.
[0092] In some embodiments, the method for generating a shader file also includes: obtaining an architecture file 400 through a second program module 200, the architecture file 400 being used to indicate instructions and operands available for the shader file; the process of executing step S30 may include: the second program module 200 generates a shader file 500 according to the instruction information within the range of instructions and operands indicated by the architecture file 400.
[0093] In the disclosed embodiment, the second program module 200 can obtain the architecture file 400, which is used to indicate the instructions and operands available for the shader file. All instructions included in the instruction information in the shader template file 300 and the operands included in each instruction should be within the range of instructions and operands indicated by the architecture file 400, that is, the second program module 200 needs to generate a shader file 500 according to the instruction information within the range of instructions and operands indicated by the architecture file.
[0094] In some specific examples, the architecture file 400 can be written in XML format or JSON format.
[0095] In some embodiments, the architecture file 400 may include an instruction information file, where the instruction information file includes an instruction set and an operand set corresponding to each instruction in the instruction set.
[0096] Figure 3 A schematic diagram of a method for generating a shader file provided in an embodiment of the present disclosure Figure 2 , combined with reference Figure 1 and Figure 3 , Figure 1 Step S30 may include Figure 3 Steps S301 to S304 in the embodiment, that is, the specific process of executing step S30 may include:
[0097] Step S301, querying the instruction information file, and determining the operand set corresponding to each instruction in the instruction information according to the instruction set and the operand set;
[0098] Step S302, generating operands corresponding to each instruction according to the operand set;
[0099] Step S303, generating the instruction according to the operand corresponding to each instruction;
[0100] Step S304, generating the shader file according to the generated multiple instructions.
[0101] In the embodiment of the present disclosure, after receiving the instruction information, the second program module 200 can query the instruction information file based on the instruction information. For example, the instruction information may include the name of the instruction to be generated. By querying the instruction information file by the name of the instruction to be generated, the operand set corresponding to the instruction to be generated can be obtained, that is, all operands required to generate the instruction.
[0102] In the embodiment of the present disclosure, after determining the operand set corresponding to each instruction in the instruction information, the second program module 200 can generate the operands corresponding to each instruction, and generate instructions based on all the operands corresponding to each generated instruction, and finally generate a shader file 500 based on the generated multiple instructions.
[0103] In some embodiments, the instruction information includes constraint information of the operands, and the constraint information of the operands is used to constrain the optional set of operands; the architecture file 400 also includes: an operand information file, the operand information file includes an optional set of elements of each operand and the selection weight of each element in the optional set.
[0104] In an embodiment of the present disclosure, the process of generating an instruction may include generating operands in an operand set corresponding to the instruction one by one.
[0105] Figure 4 A flow chart of a method for generating operands provided in an embodiment of the present disclosure, in conjunction with reference to Figure 3 and Figure 4 , Figure 3 Step S302 in may include Figure 4 Steps S3021 to S3023 in the above, i.e., the specific process of executing step S302 may include:
[0106] Step S3021, determining the selectable set and the selection weight of the elements of each operand in the operand set according to the operand information file;
[0107] Step S3022, determining the constrained optional set according to the constraint information of the operand;
[0108] Step S3023: randomly generate the operand according to the selection weight of each element in the optional set after the constraint.
[0109] In the disclosed embodiment, the second program module 200 can query the operand information file based on the operand set of the instruction to be generated to determine the optional set and selection weight of the elements of each operand in the operand set, and then can use the operand constraint information provided by the user to constrain the optional set of the operand to determine the constrained optional set, and finally can randomly generate the operand according to the selection weight of each element in the constrained optional set, that is, the user only needs to provide the constraint information of the operand, and there is no need to assign a value to each operand, thereby reducing the user's workload and improving the efficiency of generating shader files.
[0110] In some embodiments, refer back to Figure 2 The second program module 200 may include a second interface program 201, which can implement cross-language conversion between the first language and the second language.
[0111] In a specific example, the first language may be Python, the second language may be C++, and the second interface program 201 may include Pybind, which may implement cross-language conversion between Python and C++.
[0112] In some embodiments, in conjunction with reference Figure 1 and Figure 2 The specific process of executing step S20 may include: the first program module 100 executes the shader template file 300 to call the first interface program 101 to send the instruction information of each instruction to be generated to the second program module 200 in turn; the second program module 200 calls the second interface program 201 to receive the instruction information of each instruction to be generated in turn, and converts the instruction information from the first language to the second language.
[0113] In the embodiment of the present disclosure, instructions can be generated one by one, that is, the first program module 100 can call the first interface program 101 to send the instruction information of an instruction to be generated to the second program module 200, and the second program module 200 can call the second interface program 201 to receive the instruction information of the instruction to be generated, and convert the instruction information from the first language to the second language. After the second program module 200 generates an instruction according to the instruction information, it can generate generation completion information of the instruction, and call the second interface program 201 to convert the generation completion information of the instruction from the second language to the first language and send it to the first interface program 101. The generation completion information is used to instruct the first interface program 101 to send the instruction information of the next instruction. In response to the generation completion information, the first interface program 101 can send the instruction information of the next instruction to the second interface program 201, thereby realizing the generation of instructions one by one.
[0114] In some embodiments, Figure 5 A schematic diagram of a method for generating a shader file provided in an embodiment of the present disclosure Figure 3 , combined with reference Figure 3 and Figure 5 The specific process of executing step S304 may include: step S3041, generating an instruction assembly of the instructions according to the generated multiple instructions; step S3042, converting the instruction assembly into the shader file.
[0115] In some specific examples, the method for generating a shader file also includes: after receiving the generation completion information of the last instruction, the first interface program 101 passes the assembly command to the second program module 200, and the specific process of executing step S3041 may include: in response to the assembly command, packing all generated instructions to generate an assembly of instructions.
[0116] In the disclosed embodiment, the architecture file can be written and input by the user, and the architecture file is related to the architecture version of the GPU. When the architecture version of the GPU is fixed, the user only needs to write the architecture file once, that is, the shader file applicable to different use cases under the same architecture version can be generated by modifying the shader template file without modifying the architecture file, so that the generation efficiency of the shader file under the same GPU architecture version can be improved. In addition, since the shader template file can be written in an interpreted language, the efficiency of writing and modifying the shader template file is significantly improved relative to the efficiency of directly writing and modifying the shader assembly. When the architecture version of the GPU is updated, the user can update the architecture file, and then continue to generate the shader file applicable to different use cases under the updated architecture version by modifying the shader template file. That is, the generation method of the shader file provided by the disclosed embodiment can realize the modification and reuse of the architecture file and the shader template file, and the user does not need to write the shader assembly for the specific use case under each specific architecture version, so that the generation efficiency of the shader file can be effectively improved, thereby improving the verification efficiency of the shader module and the development efficiency of the GPU chip.
[0117] Based on a concept similar to the above-mentioned method for generating a shader file, the present disclosure also provides a device for generating a shader file. Figure 6 Schematic diagram of a device for generating a shader file provided in an embodiment of the present disclosure Figure 2 ,like Figure 6 As shown, the device for generating a shader file includes a first program module 100 and a second program module 200 .
[0118] In some embodiments, the first program module 100 is configured to: obtain a shader template file 300; the shader template file 300 is written in a first language; the first language includes an interpreted language; the shader template file 300 includes instruction information; execute the shader template file 300 to call the first interface program 101 to pass the instruction information in the shader template file to the second program module 200; the second program module 200 is written in a second language; the second language includes a compiled language; the second program module 200 is configured to: generate a shader file 500 according to the instruction information.
[0119] In some embodiments, the second program module 200 includes: an architecture file parser 202, configured to: obtain an architecture file 400; the architecture file 400 is used to indicate instructions and operands available for the shader file; and a shader file generation module 203, configured to: generate a shader file 500 according to instruction generation information within the range of instructions and operands indicated by the architecture file 400.
[0120] In some specific examples, the first language may be one of Python, JavaScript, Perl, and Shell; the second language may be one of C++, C, Delphi, and Golang.
[0121] In some specific examples, the architecture file 400 may be an XML format file or a JSON format file.
[0122] In some specific examples, Figure 7 Schematic diagram of a device for generating a shader file provided in an embodiment of the present disclosure Figure 3 , combined with reference Figure 6 and Figure 7 The architecture file 400 may include: an instruction information file 401 and an operand information file 402, wherein the instruction information file 401 includes an instruction set and an operand set corresponding to each instruction in the instruction set, and the operand information file 402 includes an optional set of elements of each operand and a selection weight of each element in the optional set.
[0123] In some embodiments, in conjunction with reference Figure 6 and Figure 7 The shader file generation module 203 may include: an instruction generator 2031, configured to: query the instruction information file 401, and determine the operand set corresponding to each instruction in the instruction information according to the instruction set and operand set in the instruction information file 401; an operand generator 2032, configured to: generate the operand corresponding to each instruction according to the operand set; the instruction generator 2031 is also configured to: generate instructions according to the operand corresponding to each instruction; an instruction assembler 2033, configured to: generate a shader file 500 according to the generated multiple instructions.
[0124] In some embodiments, the instruction information includes constraint information of the operands, and the constraint information of the operands is used to constrain the optional set of the operands. The operand generator 2032 is specifically configured to: determine the optional set and selection weight of the elements of each operand in the operand set according to the operand information file; determine the constrained optional set according to the constraint information of the operands; and randomly generate operands according to the selection weight of each element in the constrained optional set.
[0125] In some specific examples, combined with reference Figure 6 and Figure 7, the architecture file parser 202 may include an instruction information parser 2021 and an operand information parser 2022, wherein the instruction information parser 2021 may be configured to: obtain and parse the instruction information file 401 during the initialization phase of the second program module 200, and the instruction generator 2031 may query the instruction information parser 2021 for the instruction set and operand set in the instruction information file 401; the operand information parser 2022 may be configured to: obtain and parse the operand information file 402 during the initialization phase of the second program module 200, and the operand generator 2032 may query the operand information parser 2022 for the optional set of operand elements in the operand information file 402 and the selection weight of each element in the optional set.
[0126] In some embodiments, the first interface program 101 is also configured to: send the instruction information of each instruction to be generated to the second program module 200 in turn; the second program module 200 also includes: the second interface program 201, which is configured to: receive the instruction information of each instruction to be generated in turn, and convert the instruction information from the first language to the second language.
[0127] In some embodiments, the instruction generator 2031 is further configured to: generate an instruction assembly of instructions based on the generated multiple instructions; the instruction assembler 2033 is specifically configured to: convert the instruction assembly into a shader file 500.
[0128] In some embodiments, the instruction generator 2031 is also configured to: generate instruction generation completion information each time an instruction is generated; the generation completion information is used to instruct the first interface program 101 to send instruction information for the next instruction; the second interface program 201 is also configured to: convert the instruction generation completion information from the second language to the first language and send it to the first interface program 101.
[0129] In some embodiments, the first interface program 101 is also configured to: after receiving the generation completion information of the last instruction, pass the assembly command to the second program module 200; the instruction generator 2031 is specifically configured to: in response to the assembly command, package all generated instructions to generate an assembly of instructions.
[0130] In some specific examples, the first language may be Python, the second language may be C++, the first interface program 101 may include an API, and the second interface program 201 may include Pybind, which may implement cross-language conversion between Python and C++.
[0131] In the embodiment of the present disclosure, a shader file generation device can obtain a shader template file and an architecture file input by a user, and generate a shader template file according to the instruction information in the shader template file within the range of instructions and operands indicated by the architecture file. Using the shader file generation device, when the GPU architecture version remains unchanged, the user only needs to write the shader template file in an interpreted language and write the architecture file once. The shader file generation device can generate an instruction assembly of the instructions by generating instructions one by one, and convert the instruction assembly into a shader file. As a result, the user no longer needs to write a shader assembly for a specific use case under each specific architecture version, thereby effectively improving the generation efficiency of the shader file, improving the verification efficiency of the shader module, and improving the development efficiency of the GPU chip.
[0132] In some specific examples, the shader file generating device may be a software program, the first program module 100 may be a front-end module of the software program, and the second program module 200 may be a back-end module of the software program.
[0133] In the solution provided by the present disclosure, an implementation idea of decoupling software programs from GPU architecture is adopted. In the new GPU architecture, users can reuse use case templates by modifying the architecture file and making a small amount of changes to the use case template.
[0134] The present disclosure provides a computer device, Figure 8 A schematic diagram of a computer device provided in an embodiment of the present disclosure, such as Figure 8 As shown, the computer device 600 includes: a processor 601 and a memory 602, wherein the memory 602 stores a computer program 6021 that can be run on the processor 601, and when the processor 601 executes the computer program 6021, the method for generating a shader file in any of the above embodiments can be implemented.
[0135] In some embodiments, the memory 602 stores a computer program 6021 that can be run on the processor. The memory 602 is configured to store instructions and applications executable by the processor 601. It can also cache data to be processed or processed by the processor 601 and various modules in the computer device 600 (for example, image data, audio data, voice communication data, and video communication data), which can be implemented through flash memory (FLASH) or random access memory (Random Access Memory, RAM).
[0136] In some embodiments, the processor 601 implements the steps of any of the above-mentioned task processing methods when executing the program. The processor 601 generally controls the overall operation of the computer device 600.
[0137] An embodiment of the present disclosure provides a computer storage medium, which stores one or more programs. The one or more programs can be executed by one or more processors to implement the method for generating a shader file in any of the above embodiments.
[0138] The embodiments of the present disclosure also provide a computer program product, which includes a computer program. When the computer program is executed by a processor, the method for generating a shader file in any of the above embodiments can be implemented.
[0139] In some specific examples, the processor may be at least one of an Application Specific Integrated Circuit (ASIC), a Digital Signal Processor (DSP), a Digital Signal Processing Device (DSPD), a Programmable Logic Device (PLD), a Field Programmable Gate Array (FPGA), a Central Processing Unit (CPU), a controller, a microcontroller, and a microprocessor. It is understandable that the electronic device that implements the functions of the processor may also be other, and the embodiments of the present disclosure are not specifically limited.
[0140] In some specific examples, the above-mentioned computer storage medium / memory can be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), a magnetic random access memory (FRAM), a flash memory (Flash Memory), a magnetic surface memory, an optical disc, or a compact disc read-only memory (CD-ROM) and the like; it can also be various terminals including one or any combination of the above-mentioned memories, such as a mobile phone, a computer, a tablet device, a personal digital assistant, etc.
[0141] The methods disclosed in several method embodiments provided in the present disclosure can be arbitrarily combined without conflict to obtain new method embodiments.
[0142] The features disclosed in several device embodiments provided in the present disclosure may be arbitrarily combined without conflict to obtain new device embodiments.
[0143] The above description is only a specific implementation mode of the present disclosure, but the protection scope of the present disclosure is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present disclosure, which should be included in the protection scope of the present disclosure.
Claims
1. A method for generating a shader file, characterized in that: include: Obtaining a shader template file through a first program module; The shader template file is written in a first language; The first language includes an interpreted language; the shader template file includes instruction information; Executing the shader template file to call a first interface program to pass the instruction information in the shader template file to a second program module; the second program module is written in a second language; the second language includes a compiled language; Acquiring a framework file through the second program module; The architecture file is used to indicate the instructions and operands available to the shader file; the architecture file includes: an operand information file, the operand information file includes an optional set of elements of each operand and a selection weight of each element in the optional set; wherein the operand is randomly generated according to the optional set and the selection weight; The second program module generates a shader file according to the instruction information and the operands; wherein the shader file is a binary file executed by a graphics processor GPU.
2. The method for generating a shader file according to claim 1, characterized in that: The second program module generates a shader file according to the instruction information, including: The second program module generates a shader file according to the instruction information within the range of instructions and operands indicated by the architecture file.
3. The method for generating a shader file according to claim 2, characterized in that: The architecture file includes: an instruction information file, the instruction information file includes an instruction set and an operand set corresponding to each instruction in the instruction set; the second program module generates a shader file according to the instruction information within the range of the instructions and operands indicated by the architecture file, including: Querying the instruction information file, and determining the operand set corresponding to each instruction in the instruction information according to the instruction set and the operand set; Generate an operand corresponding to each instruction according to the operand set; Generate the instruction according to the operand corresponding to each instruction; The shader file is generated according to the generated multiple instructions.
4. The method for generating a shader file according to claim 3, characterized in that: The instruction information includes constraint information of operands, and the constraint information of operands is used to constrain an optional set of operands; Generating an operand corresponding to each instruction according to the operand set includes: Determining the selectable set and the selection weight of the elements of each operand in the operand set according to the operand information file; Determining the constrained optional set according to the constraint information of the operands; The operand is randomly generated according to the selection weight of each element in the optional set after the constraint.
5. The method for generating a shader file according to claim 3, characterized in that: The executing the shader template file to call the first interface program to pass the instruction information in the shader template file to the second program module includes: The first program module executes the shader template file to call the first interface program to sequentially send the instruction information of each instruction to be generated to the second program module; The second program module calls a second interface program, receives the instruction information of each instruction to be generated in sequence, and converts the instruction information from the first language to the second language.
6. The method for generating a shader file according to claim 5, characterized in that: Generating the shader file according to the generated multiple instructions includes: Generating an instruction assembly of the instructions according to the generated multiple instructions; The instruction assembly is converted into the shader file.
7. The method for generating a shader file according to claim 6, characterized in that: The method further comprises: After each instruction is generated, generation completion information of the instruction is generated; The second interface program is called to convert the generation completion information of the instruction from the second language to the first language and send it to the first interface program, wherein the generation completion information is used to instruct the first interface program to send instruction information of the next instruction.
8. The method for generating a shader file according to claim 7, characterized in that: The method further comprises: After receiving the generation completion information of the last instruction, the first interface program transmits the assembly command to the second program module; The generating of the assembly of the instructions comprises: In response to the assembly command, all generated instructions are packaged to generate an assembly of the instructions.
9. A device for generating a shader file, characterized in that: include: The first program module is configured to: obtain a shader template file; The shader template file is written in a first language; The first language includes an interpreted language; the shader template file includes instruction information; the shader template file is executed to call a first interface program to pass the instruction information in the shader template file to a second program module; The second program module is written in a second language; the second language includes a compiled language; The second program module includes: an architecture file parser, configured to: obtain an architecture file; the architecture file is used to indicate instructions and operands available to the shader file; the architecture file includes: an operand information file, the operand information file includes an optional set of elements of each operand and a selection weight of each element in the optional set; wherein the operand is randomly generated according to the optional set and the selection weight; The second program module is configured to: generate a shader file according to the instruction information and the operand; wherein the shader file is a binary file executed by a GPU.
10. The device for generating a shader file according to claim 9, characterized in that: The second program module includes: The shader file generation module is configured to generate a shader file according to the instruction information within the range of instructions and operands indicated by the architecture file.
11. The device for generating a shader file according to claim 10, characterized in that: The architecture file includes: an instruction information file, the instruction information file includes an instruction set and an operand set corresponding to each instruction in the instruction set; the shader file generation module includes: The instruction generator is configured to: query the instruction information file, and determine the operand set corresponding to each instruction in the instruction information according to the instruction set and the operand set; An operand generator is configured to: generate an operand corresponding to each instruction according to the operand set; The instruction generator is further configured to: generate the instruction according to the operand corresponding to each instruction; The instruction assembler is configured to generate the shader file according to the generated multiple instructions.
12. The device for generating a shader file according to claim 11, characterized in that: The instruction information includes constraint information of operands, and the constraint information of operands is used to constrain an optional set of operands; The operand generator is specifically configured to: determine the optional set and the selection weight of the elements of each operand in the operand set according to the operand information file; determine the optional set after the constraints according to the constraint information of the operand; The operand is randomly generated according to the selection weight of each element in the optional set after the constraint.
13. The device for generating a shader file according to claim 11, characterized in that: The first interface program is further configured to: sequentially send the instruction information of each instruction to be generated to the second program module; The second program module also includes: The second interface program is configured to: sequentially receive the instruction information of each instruction to be generated, and convert the instruction information from the first language to the second language.
14. The device for generating a shader file according to claim 13, characterized in that: The instruction generator is further configured to: generate an instruction assembly of the instructions according to the generated multiple instructions; The instruction assembler is specifically configured to convert the instruction assembly into the shader file.
15. The device for generating a shader file according to claim 14, characterized in that: The instruction generator is further configured to: generate generation completion information of the instruction each time after generating an instruction; the generation completion information is used to instruct the first interface program to send instruction information of the next instruction; The second interface program is further configured to: convert the generation completion information of the instruction from the second language into the first language and send the converted information to the first interface program.
16. The device for generating a shader file according to claim 15, characterized in that: The first interface program is further configured to: after receiving the generation completion information of the last instruction, pass the assembly command to the second program module; The instruction generator is specifically configured to: in response to the assembly command, pack all generated instructions to generate an assembly of the instructions.
17. A computer device, characterized in that: The computer device includes a memory, a processor, and a computer program stored in the memory; when the processor executes the computer program, the method for generating a shader file according to any one of claims 1 to 8 is implemented.
18. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method for generating a shader file according to any one of claims 1 to 8 is implemented.
19. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the method for generating a shader file according to any one of claims 1 to 8 is implemented.
