WO2021253641A1 - Shading language translation method - Google Patents
Shading language translation method Download PDFInfo
- Publication number
- WO2021253641A1 WO2021253641A1 PCT/CN2020/112548 CN2020112548W WO2021253641A1 WO 2021253641 A1 WO2021253641 A1 WO 2021253641A1 CN 2020112548 W CN2020112548 W CN 2020112548W WO 2021253641 A1 WO2021253641 A1 WO 2021253641A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- function
- variable
- information
- type
- name
- Prior art date
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/40—Transformation of program code
- G06F8/41—Compilation
- G06F8/42—Syntactic analysis
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T15/00—3D [Three Dimensional] image rendering
- G06T15/005—General purpose rendering architectures
Definitions
- This application relates to the field of data processing technology, and in particular to a coloring language translation method.
- Shading Language is a type of shading language specifically used to program shaders.
- HLSL high-level shader language
- Microsoft an operating system developed by Microsoft
- the present invention is proposed to provide a coloring language translation method that overcomes the above-mentioned problems or at least partially solves or alleviates the above-mentioned problems.
- a color language translation method which includes: performing syntax analysis on a first code file corresponding to the first coloring language to obtain an abstract syntax tree of the first code file; The keywords of multiple nodes in the tree are analyzed to obtain the coloring language information of the first code file; according to the set information mapping rules, the coloring language information of the first code file is translated to obtain the second A second code file corresponding to the coloring language; wherein the information mapping rule is determined according to the grammatical rules of the first coloring language and the second coloring language.
- node analysis is performed based on the abstract syntax tree, and the original syntax structure of the code file of the original coloring language is retained.
- node-based keyword analysis realizes the corresponding translation between different types of information, which is conducive to improving the readability of the translation results; in addition, the information mapping rules can be updated according to actual needs to improve The scalability of the language translation method is improved, and the new coloring language grammar can be supported quickly and conveniently.
- FIG. 1 is a schematic flowchart of a coloring language translation method provided by an exemplary embodiment of this application;
- FIG. 2 is a schematic flowchart of a coloring language translation method provided by another exemplary embodiment of this application.
- FIG. 3 is a schematic structural diagram of an electronic device provided by an exemplary embodiment of this application.
- FIG. 4 is a schematic structural diagram of a server provided by an exemplary embodiment of this application.
- Fig. 5 is a schematic structural diagram of a computing program product provided by an exemplary embodiment of the application.
- FIG. 1 is a schematic flowchart of a coloring language translation method provided by an exemplary embodiment of the application. As shown in FIG. 1, the method includes:
- Step 101 Perform syntax analysis on a first code file corresponding to the first coloring language to obtain an abstract syntax tree of the first code file.
- Step 102 Analyze keywords of multiple nodes in the abstract syntax tree to obtain the coloring language information of the first code file.
- Step 103 Translate the coloring language information of the first code file according to the set information mapping rule to obtain a second code file corresponding to the second coloring language; wherein, the information mapping rule is based on the first coloring language.
- the language and the grammatical rules of the second coloring language are determined.
- the abstract syntax tree (Abstract Syntax Tree, AST) is an abstract representation of the source code syntax structure. It expresses the grammatical structure of the source code in a tree structure, and a node on the tree structure represents a structure in the source code.
- the key of the node may be the key of the variable corresponding to the node.
- the keyword can be the name of the variable in the code corresponding to the node, or the character string contained in the variable, which is not limited in this embodiment.
- the operation of obtaining the abstract syntax tree of the first code file can be implemented based on the syntax tree generator, which is not limited in this embodiment.
- the HlslParser open source software can be used to extract the abstract syntax tree of source.hlsl to obtain source_AST.
- mapping rule includes: a variable mapping rule between the first shading language and the second shading language; and/or, a function between the first shading language and the second shading language Mapping rules.
- variable mapping rule and the function mapping rule are determined according to the grammar rules of the first shading language and the second shading language.
- the variable mapping rule is used to translate the variables involved in the coloring language information of the first code file, so as to translate the variables in the first code file into variables that conform to the grammar of the second coloring language.
- the function mapping rule is used to translate the functions included in the shading language information of the first code file, so as to translate the functions in the first code file into a function conforming to the syntax of the second shading language.
- the first shading language is applicable to the first platform
- the second shading language is applicable to the second platform.
- the first platform and the second platform may be platforms equipped with different operating systems.
- the shading language suitable for the first platform can be translated into the shading language suitable for the second platform, so as to realize the cross-platform flexible use of the shading language.
- node analysis is performed based on the abstract syntax tree, and the original syntax structure of the code file of the original coloring language is retained.
- node-based keyword analysis realizes the corresponding translation between different types of information, which is conducive to improving the readability of the translation results; in addition, the information mapping rules can be updated according to actual needs to improve The scalability of the language translation method is improved, and the new coloring language grammar can be supported quickly and conveniently.
- Reserved keywords cannot be used as variable names or process names. Therefore, in order to avoid using reserved keywords, the first code file can be preprocessed, which will be illustrated below.
- variable to be processed may be determined from the first code file, and the name of the variable to be processed contains the same character string as the reserved keyword in the translation tool. Next, the name of the variable to be processed can be modified to avoid the occurrence of reserved keywords during the translation process.
- the variable to be processed includes at least one of a global parameter variable named Buffer, a variable whose name contains the character string Texture, and a variable whose name contains the character string Buffer.
- the name Buffer of the global parameter variable in the first code file may be set to Cbuffer; and the name of the variable in the first code file may be The texture of is set to texture; or, the Buffer in the name of the variable in the first code file is set to buffer.
- Step 103 of the foregoing embodiment records a solution for analyzing the keywords of multiple nodes in the abstract syntax tree to obtain the coloring language information of the first code file.
- the first code The coloring language information of the file includes: information about the global parameter variable structure in the first code file, information about the resources in the first code file, information about the structure in the first code file, and the first code file. At least one of the function information in the code file.
- Shader involved in the following embodiments refers to a code file that stores a shading language, for example, an HLSL file, a GLSL file, or a SPIR-V file, and will not be explained one by one in the following.
- the key variable corresponding to the node is determined according to the type keyword of the node; then, the key variable corresponding to the node is analyzed to obtain the The coloring language information corresponding to the node. After traversing the abstract syntax tree, the coloring language information corresponding to each of the multiple nodes can be obtained, and then the coloring language information of the first code file can be obtained according to the coloring language information corresponding to each of the multiple nodes.
- the basic type of the node can be determined based on the type keyword of the node, and the basic type of the node is used to describe the coloring language information stored by the node.
- the type keyword of the node may include: at least one of a global parameter-passing variable structure, class definition, structure definition, variable, function definition, function declaration, sampler, and function call type.
- the node type keywords and the corresponding shader functions can be as shown in Table 1 below:
- the key variable corresponding to the node refers to the variable that stores the coloring language information of the node.
- the coloring language information stored in the node can be obtained.
- the key variable of the node is also different.
- the key variable of the node may be a register allocation variable (RegisterAllocationOptData variable), and the register allocation variable contains the register information of the resource.
- the key variables of the node may include: a function type (FunctionType) variable, a function parameter variable (FunctionParamsOptData), and a code block variable (Block).
- the FunctionType variable stores the return type information of the function
- FunctionParamsOptData stores the parameter information of the function
- Block contains all the statements inside the function.
- the node when the basic type of a node is a function call (FunctionCall), the node will have an argument variable (ArgumentList), which contains the parameters passed in when the function is called.
- ArgumentList an argument variable
- the node when the basic type of the node is a structure (Struct), the node will have a class member declaration variable (ClassMemberDeclarations), which contains the member variable information in the structure.
- ClassMemberDeclarations class member declaration variable
- the key variable of the node can be determined according to the type keyword of the node, and the key variable of the node can be analyzed to obtain the coloring language information corresponding to the node.
- the type keyword of the node is a global parameter variable structure
- the type variables and name variables of the child nodes of the node are parsed to obtain the global parameter variable structure contained in the global parameter variable structure Type and name; the type and name of the global parameter variable contained in the global parameter variable structure should be stored in the variable dictionary.
- the basic type of a certain high-level node in the abstract syntax tree is "CBuffer”
- all child nodes of the node can be parsed.
- each sub-node can parse out the information of a global parameter variable.
- the type variable (Type variable) and name variable (Name variable) of the child node are obtained. Then, save the information of all global parameter-passing variables in the global parameter-passing variable structure into a global variable dictionary.
- the global variable dictionary can be recorded as GVariableDictionary.
- the name variable and register allocation variable of the node are parsed to obtain the name and register address of the resource; the name and register address of the resource correspond to Saved in the resource dictionary.
- the resource includes: at least one of a texture resource, a buffer resource, and a register resource.
- a texture resource at least one of a texture resource, a buffer resource, and a register resource.
- the value of the type variable of the node contains a string representing the texture resource
- the value of the name variable of the node is obtained as the name of the texture resource; then, the register allocation variable of the node is parsed to obtain the The register address of the texture resource; then, the name of the texture resource and the register address are correspondingly saved in the texture dictionary.
- the Name variable value of this node can be recorded as the name of the texture resource corresponding to the node, and the RegisterAllocationOptData of this node can be parsed. Variable, get register address. Then, save the texture resource and the corresponding register address in a global texture resource dictionary, which is recorded as GTexutreDictionary.
- the value of the type variable of the node contains a character string representing the buffer resource
- the value of the name variable of the node is obtained as the name of the buffer resource; then, the register allocation variable of the node is parsed to Obtain the register address of the buffer resource; then, the name of the buffer resource and the register address are correspondingly saved in the buffer dictionary.
- the Name variable value of this node can be recorded as the name of the Buffer resource, and the RegisterAllocationOptData variable of this node can be parsed to obtain The address of the register corresponding to the Buffer resource.
- the Buffer resource and its corresponding register address in a global register resource dictionary, which is recorded as GBufferDictionary.
- the value of the name variable of the node is obtained as the name of the sampler; then, the register allocation variable of the node is parsed to obtain the register address of the sampler; then, Save the sampler's name and register address correspondingly in the sampler resource dictionary.
- the Name variable of this node can be recorded as the name of the sampler resource, and the RegisterAllocationOptData variable of this node can be parsed to obtain the sampler resource The address of the register. Then, record the sampler resource and its register address in a global sampler resource dictionary, and record it as GSamplerDictionary.
- the abstract syntax tree can be traversed to obtain information about all texture resources, all buffer resources, and all sampler resources in the first code file.
- the information of all texture resources in the first code can be stored in GtexutreDictionary
- all buffer resources can be stored in GbufferDictionary
- all sampler resources can be stored in GsamplerDictionary, which will not be repeated here.
- the function type variable and name variable of the node are parsed to obtain the return type and function name of the first function, and the The type and name of the formal parameter variable are written into the information of the first function.
- the function type variable is the Type variable of the node
- the name variable is the Name variable of the node.
- all function information can be recorded in a global dictionary, which is recorded as GFunctionDictionary.
- GFunctionDictionary When the basic type of the node in the abstract syntax tree is "FunctionDefinition” or “FunctionDeclaration”, this node can be recorded as Fnode, and the function corresponding to this node is recorded as function F0.
- Fnode When the basic type of the node in the abstract syntax tree is "FunctionDefinition" or "FunctionDeclaration", this node can be recorded as Fnode, and the function corresponding to this node is recorded as function F0.
- Fnode the function corresponding to this node is recorded as function F0.
- the type variable and the name variable of the child node of the function parameter variable of the node may be parsed to obtain the type and name of the formal parameter variable of the first function.
- the function parameter variable can be the FunctionParamsOptData variable corresponding to the node.
- Each sub-node of a function parameter variable represents a formal parameter variable. Therefore, the type and name of each formal parameter variable of the first function can be obtained by analyzing the type variable and name variable of each sub-node of the function parameter variable.
- the formal parameter variable of the first function includes a formal parameter variable with an out or inout attribute
- the formal parameter variable with an out or inout attribute is recorded in the information of the first function.
- each child node of the FunctionParamsOptData variable represents a formal parameter variable, and the type and name of each formal parameter variable can be obtained according to the Type and Name variables of each child node. Among them, if the type of one or more formal parameter variables is modified with out or inout, these variable information can be additionally recorded in the information of the function F0.
- the subtree corresponding to any child node of the code block variable of the node can be obtained; if the type of the first node in the subtree is a function call, the name variable and the actual parameter of the first node are parsed Variable to get the function name and parameter passing information corresponding to the first node; then, in the function dictionary, query the function name corresponding to the first node and the target function corresponding to the parameter passing information as the calling function of the first function .
- the code block variable can be the Block variable corresponding to the node.
- a subtree with the child node as the root node can be obtained as the subtree corresponding to the child node.
- the actual parameter variable may be the ArgumentList variable of the first node.
- the first node refers to any node in the subtree whose type is a function call.
- each child node of the Block variable represents each statement implemented by the function.
- a (any) child node of Block be FNode_B_C, and obtain the subtree with FNode_B_C as the root node from the abstract syntax tree, and analyze the subtree.
- the basic type of a node in the subtree is "FunctionCall”
- a function name can be obtained according to the value of the Name variable of the node, and the formal parameter information can be parsed from the ArgumentList variable of the node.
- each child node of ArgumentList represents a function to pass parameters. Then, according to the function name and parameter information obtained by the analysis, go to the GFunctionDictionary to find it. If the corresponding function is found, record this function as F1, then add F1 to the list of calling functions of function F0.
- Embodiment D Optionally, if the second node in the subtree uses the first global resource, the information of the first global resource is written into the information of the first function; the first global resource includes texture At least one of resources, buffer resources, and sampler resources.
- Embodiment E Optionally, if the third node in the subtree uses the first global parameter passing variable, the information of the first global parameter passing variable is written into the information of the first function.
- the coloring information of the first function corresponding to the node can be obtained, and then the information of the first function can be stored in the function dictionary.
- the function information defines the main member variables as shown in Table 3:
- all the functions in the first code file are obtained, and after all the function information is recorded in the function dictionary, the functions in the function dictionary can be further filtered to determine the first code file. A function actually used when the code is running, thereby reducing the workload of subsequent function translation operations.
- determine the entry function from the function dictionary starting from the entry function, use a depth-first search method to search for each function called by the entry function; record the searched function called by the entry function to the target Function collection.
- the GFunctionDictionary generated in the foregoing embodiment can be traversed, and when the name of a certain function is found to be "main", it is determined that this function is the entry function, which is recorded as MainFunc. Then, starting from the entry function, use the depth-first search method to search for each function it calls. Record the searched function into a global dictionary and record it as GusedFunction.
- the function in the GusedFunction dictionary represents the set of functions actually used in the current shader. Furthermore, functions that are not called can be removed in the subsequent function translation process, which reduces the amount of translation calculations and streamlines the translation results.
- the type keyword of the node is a structure definition
- the name variable of the node and the child nodes of the class member declaration variable are parsed to obtain the name of the first structure corresponding to the node and the first structure
- the information of the class members included; the name of the first structure and the information of the class members included in the first structure are stored in the global linked list.
- the function dictionary may be traversed to determine the entry function from the function dictionary; if the first structure matches the return type of the entry function, the first structure is determined A structure is an output type structure; if the first structure matches the type of the formal parameter variable of the entry function, it is determined that the first structure is an input type structure.
- the Name variable value of the node can be recorded as the name of the structure corresponding to the node.
- each child node of the ClassMemberDeclarations variable of the node represents a structure member. Therefore, each child node of the ClassMemberDeclarations variable can be parsed to obtain all structure member information of the structure to be structured. Then, you can save all structure member information in the structure. Among them, after obtaining the information of all the structures in the first code, the information of all the structures can be stored in a global linked list, which is recorded as GStructList.
- the GFunctionDictionary generated in the foregoing embodiment can be traversed, and when the name of a certain function is found to be "main", this function is the entry function, which is recorded as MainFunc.
- the abstract syntax tree of the first code file can be traversed to obtain the coloring language information of each node. Then, according to the coloring language information of the multiple nodes, the coloring language information of the first code file can be obtained.
- the coloring language information of the first code may include: resource information contained in the resource dictionary, global parameter information contained in the variable dictionary, structure information contained in the global linked list, and information contained in the objective function set. Function information.
- the coloring language information of the first code file can be translated to obtain the second code file.
- the second code file is adapted to the syntax of the second shading language.
- the set information mapping rules may include at least one of variable mapping rules and function mapping rules.
- the variable mapping rule and the function mapping rule can be pre-defined according to the grammatical requirements of the second coloring language, which is not limited in this embodiment.
- the information mapping rules can be updated according to requirements. For example, the mapping relationship between words and words, structure and structure can be flexibly added, and the scalability is strong, and the new coloring can be easily and quickly supported. Language grammar.
- the second shading language may be Metal shading language or GLSL shading language.
- Metal is a low-level, low-overhead hardware-accelerated application program interface that takes into account both graphics and computing functions. It can be applied to systems after IOS 8.0.
- GLSL shading language is the shading language used by OpenGL, and it is a high-level shading language based on C language.
- the first platform can be implemented as a platform equipped with Windows operating system (an operating system developed by Microsoft Corporation), and the second platform can be implemented as a platform equipped with IOS (iPhone Operation System, an operating system developed by Apple). System platform or platform equipped with Android (operating system developed by Google) operating system.
- Windows operating system an operating system developed by Microsoft Corporation
- IOS iPhone Operation System, an operating system developed by Apple
- variable mapping rule can be as shown in the following HLSL to Metal variable keyword mapping table, and the function mapping rule can be as the following HLSL to Metal function The mapping table is shown.
- variable keyword mapping table from HLSL to Metal is shown in Table 4 below:
- variable dictionary obtained from the analysis of the foregoing embodiment can be translated.
- the global parameter variable in the variable dictionary can be mapped to the member variable of the first target structure.
- all global parameter variables in the first code file of the first target structure are used as member variables of the first target structure.
- a structure can be used to organize the global parameter variable in the GVariableDictionary, and each global parameter variable is used as a member variable of this structure.
- the structure can be named Uniform.
- a typical translation example can be shown in Table 6 below:
- the structure in the global linked list obtained by the analysis of the foregoing embodiment can be translated.
- the following will exemplify the implementation of translating the structure in the first code file by taking the first structure in the global linked list as an example.
- the first structure can be obtained from the global linked list generated in the foregoing embodiment. Then, the variables in the first structure can be translated according to the variable mapping rules, so as to map the first structure into a second structure conforming to the grammar of the second shading language.
- the type of the variable in each structure can be mapped from HLSL grammar to Metal grammar according to the variable keyword mapping relationship shown in Table 4 .
- the first structure is a structure of the input type of the vertex shader
- the attribute numbers are the same.
- the input type of Metal can be generated, and the data can be organized by structure.
- attribute number (attribute number) of each variable in the translated structure should be consistent with the ATTRIBUTE number (attribute number) in the original HLSL.
- a typical translation example can be shown in Table 7 below:
- the input type of the fragment shader shader is handled in the same way as the output type of the vertex shader shader.
- the attribute in the first structure is mapped to the variable of SV_POSITION
- the variables in the second structure add the [[position]] tag to the mapped variables.
- the variable whose attribute is SV_Target in the first structure is mapped to the variable in the second structure.
- Add [[color]] to the mapped variable, and synchronize the number of the variable whose attribute is SV_Target.
- the first function is obtained from the target function set; the first function is translated according to the information of the first function and the function mapping rule, so as to map the first function to conform to the second shading language The second function of the syntax.
- the function mapping rule can be pre-defined according to the grammatical requirements of the second coloring language, which is not limited in this embodiment.
- the inline keyword is added before the return type of the second function.
- a third structure is generated in the second function; according to the transmission of the formal parameter variable with out or inout attribute
- at least one formal parameter variable is defined in sequence in the third structure; wherein, the type of the at least one formal parameter variable is the same as the type of the formal parameter variable with the out or inout attribute, and the at least one formal parameter variable
- the name is prefixed with output parameters.
- the name of the third structure is determined according to the function name of the first function and the type of the formal parameter.
- the return type of the first function can also be determined from the information of the first function; if the return type of the first function is not empty, a return parameter variable is defined in the third structure; the return parameter The variable has the same return type as the first function.
- the first target structure is obtained by mapping the global parameter passing variables in the variable dictionary, and the member variables in the first target structure may include all global parameter passing variables in the variable dictionary.
- the information of the first global resource is placed in addition to the first target structure Before other formal parameters outside the body.
- the order of the first global resource in the formal parameter of the second function is: buffer resource, texture resource, sampler resource;
- the resources within any one of the first global resources are sorted according to the size of the register corresponding to the resource.
- the first function when translating the first function according to the information of the first function and the function mapping rules: if the first function is an entry function, declare the first target in the formal parameter variable of the entry function Structure, buffer resources in the resource dictionary, texture resources in the resource dictionary, and sampler resources in the resource dictionary;
- a buffer mark is added after the first target structure and the buffer resource
- a texture mark is added after the texture resource
- a sampler mark is added after the sampler resource.
- the stage keyword is used to mark the formal parameters of the input type
- a keyword representing a vertex (vertex) is added before the return type of the first function.
- a keyword representing a fragment (fragment) is added before the return type of the first function.
- Metal function parameters do not support out and inout keywords.
- a structure is first generated before the Metal function definition is generated. The name of the structure is determined according to the function name and the type of the function parameter. Then, according to the parameter passing order of using the out and inout attribute parameters, the variables of the same type as the parameters can be defined in the structure in sequence, and the prefix of the name is outParam. If the return type of the function is not empty, you also need to define a variable of the same type as the return type in the structure, with the name returnParam. When generating a function return statement, return this structure variable, which contains the out/inout parameter value to be returned and the return value of the function itself.
- Table 10 A typical translation example can be shown in Table 10 below:
- the entry function in HLSL can be translated into an entry function that conforms to Metal grammar.
- the entry function of Metal needs to list all resource information and global parameter variable structure in the formal parameters. Among them, Texture, Buffer and Sampler resources can be obtained from GTextureDictionary, GBufferDictionary and GSamplerDictionary, and the global parameter variable structure is previously defined Uniform structure.
- the Shader uses the stage keyword to mark the parameters input by the Shader. For the vertex shader, add the vertex keyword before the function return type; for the fragment shader, add the fragment keyword before the return type.
- the coloring language information of the node obtained by analyzing the code file corresponding to the HLSL can be translated to obtain the code file corresponding to the Metal coloring language. That is, as shown in Figure 2, the HLSL Shader file is translated into a MetalShader file. Furthermore, the shader can be programmed on the IOS platform to facilitate the development of 3D graphics programs that can be used by devices such as iPhone, iPad, and iPod Touch.
- the implementation of the second shading language as the GLSL shading language will be used as an example to illustrate.
- variable mapping rules can be as shown in the following HLSL to GLSL variable keyword mapping table, and the function mapping rules can be as the following HLSL to GLSL functions The mapping table is shown.
- variable keyword mapping table from HLSL to GLSL is shown in Table 15 below:
- variable dictionary obtained from the analysis of the foregoing embodiment can be translated.
- the global parameter variable in the variable dictionary can be mapped to the member variable of the second target structure.
- all global parameter variables in the first code file are used as member variables of the second target structure.
- a structure can be used to organize the global parameter variable in the GVariableDictionary, and each global parameter variable is used as a member variable of this structure.
- the structure is modified by uniform and can be named cb.
- a uniform variable block (Uniform Buffer Object, UBO) can be defined, and the second target structure can be stored in the uniform variable block; the abstract syntax tree is traversed, if The name of the current node traversed is the same as the name of any global parameter variable stored in the uniform variable block, and the name identifier of the uniform variable block is added before the name of the current node.
- UBO Uniform Buffer Object
- the uniform variable block is used to store the buffer object of the uniform type variable in the shading language.
- UBO allows the uniform variable to be shared in different shading language programs, and the setting and setting of uniform type variables can also be realized in the shading language program. renew.
- GLSL's global parameter-passing variable structure needs to use layout to set the set modifier and binding modifier.
- the global parameter-passing variable structure can be obtained from the pre-generated variable dictionary; then, layout is used to set the set modifier and binding modifier of the global parameter-passing variable structure.
- the binding value is consistent with its corresponding register (register) value in the HLSL resource.
- the value of the set modifier can be set to 0, and the set modifier is used for subsequent Vulkan (an application program interface) translation.
- any resource to be translated can be obtained from the resource dictionary; then, use layout to set the binding modifier of the resource to be translated, and add the uniform keyword before the variable type of the resource to be translated;
- the value of the binding modifier is determined according to the value of the register of the resource to be translated.
- the type variable of the resource when translating the variable type of the resource to be translated, can be mapped in combination with the variable keyword mapping table to obtain the translated type variable of the resource. Go into details one by one.
- the information of Texture resources can be obtained from GTextureDictionary.
- the layout can be used to set the binding modifier, and the binding value is the register value of the corresponding resource in HLSL.
- the variable type of the translated resource is determined according to the variable keyword mapping table, and the uniform keyword is added before the translated variable type.
- the Buffer resource information can be obtained from GBufferDictionary.
- layout can be used to set the binding modifier, and the binding value can be obtained according to the register value of the corresponding resource in HLSL.
- the variable type of the translated resource is determined according to the variable keyword mapping table, and the uniform keyword is added before the translated variable type.
- Sampler resources do not need to be translated.
- the variables in the first structure can be translated according to the variable mapping rules to map the first structure into a second structure conforming to the grammar of the second shading language.
- the input type and output type corresponding to the first structure can be respectively translated into the input variable and output variable of the second structure. That is to say, when translating the structure in HLSL into the structure in GLSL, because the structure definition of GLSL is consistent with the structure definition of HLSL, the information of all the structures can be obtained from the global linked list GStrcutList, according to the variable Keyword mapping table, mapping the types of variables in the structure from the HLSL syntax to the GLSL definition can realize the translation operation of the structure.
- the input and output variables of GLSL can be generated according to the input and output types obtained by parsing HLSL.
- each output and output variable of GLSL needs to be globally defined in Shader. Therefore, when translating the structure of HLSL to GLSL, if it is found that the current structure type is the input and output type of Shader, the structure is no longer defined in GLSL, but the name of the structure is defined as a float type. , To facilitate subsequent translation.
- a part of the non-special member variables in the structure can be defined as the global parameter variable of GLSL Shader, and the translation of the variable type is processed through the variable keyword mapping table.
- the layout keyword is used to define the location modifier for the input variable in the second structure, and when the input variable in the second structure is declared , Add the in keyword before entering the variable type in the second structure; wherein, the value of the location modifier is consistent with the attribute number of the variable in the first structure. That is to say, for the input type of the vertex shader, each input variable after translation can be defined with the layout keyword to define the location modifier, and the location value is consistent with the ATTRIBUTE number of the corresponding variable in HLSL. At the same time, when declaring each GLSL input variable, you need to add the in keyword before the type of the input variable to indicate that this variable is an input variable.
- the reserved keyword gl_Positon is used to replace the variable whose attribute is SV_POSITION; and, when the second structure is declared When inputting variables in the second structure, add the out keyword before the type of the input variable in the second structure.
- the HLSL output variable with the SV_POSITION attribute can be replaced by the reserved keyword gl_Positon in GLSL, and in the Shader entry function of GLSL, gl_Positon can be directly assigned without additional declaration. .
- the layout keyword is used to define the location attribute value in the Shader of GLSL.
- the structure of "output. variable name" is processed.
- variable name in the structure of the output type has the SV_Position attribute, replace "output.variable name” with gl_Position, otherwise replace "output.variable name” with the global output variable name corresponding to GLSL. Since the Shader output type of HLSL is processed by the macro definition, there is no need to translate the Shader output type definition in the entry function. In this way, the translation process can be simplified without affecting the function of the Shader.
- the origin_upper_left modifier is set in the layout and the SV_POSITION Add the in keyword before the variable type of the attribute variable, and set the variable name to gl_FragCoord. That is to say, for the input type of the fragment coloring shader, when translating the variable with the SV_POSITION attribute in HLSL, you can set the origin_upper_left modifier in the layout, and add the in keyword before the variable type, and add the variable The name is set to gl_FragCoord.
- the translation method is similar to the output type of the vertex shader. The difference is that the in keyword is added before the translated variable instead of the out keyword.
- the Shader input type When translating the input type in the Shader entry function, the Shader input type can be found from the formal parameters of the entry function, and the variable name corresponding to this type can be recorded as input.
- the structure of "input. variable name” When translating the Shader entry function, the structure of "input. variable name" is processed. If the variable name corresponding to the variable in the input type structure has the SV_POSITION attribute, use gl_FragCoord to replace "output.variable name”, otherwise use the global input variable name corresponding to GLSL to replace "input.variable name”.
- the layout keyword is used to set the location modifier for the output variable in the second structure obtained by translation, and the value of the location modifier is It is consistent with the SV_Target attribute number of the corresponding variable in the first structure, and the out keyword is added before the type of the output variable in the second structure. That is to say, for the output type of the fragment coloring shader, when translating into the output variable of GLSL, you can use layout to set the location modifier. The location value is consistent with the SV_Target attribute number of the corresponding variable in HLSL, and it must be before the variable type. Add the out keyword.
- the function definition method of GLSL is roughly the same as that of HLSL function, and the difference in usage is mainly reflected in the aspect of reading resources.
- GLSL's Texture and Buffer's resource reading functions are different in structure from HLSL.
- the first function is a resource reading function
- the second function obtained by the translation is In the function, write the type of the resource to be read, the location of the resource to be read, and other parameters in the body of the second function.
- the read function structure used by HLSL is as follows:
- the structure of the read function used by GLSL is as follows:
- the structure of the read function used by HLSL is as follows:
- the structure of the read function used by GLSL is as follows:
- the resource dictionary acquired in the foregoing embodiment contains all resource information in the Shader, including resource variable types and variable names.
- the function call statement in Shader if the name of the function caller in HLSL is a global resource name, and the calling function is the built-in resource reading function of HLSL, it can be judged that the current statement is a resource reading statement.
- the text of the resource variable of this function before the resource reading function is no longer printed to the GLSL Shader, and the resource variable is set as the first parameter of the reading function.
- the sampler parameter of the resource reading function in HLSL can be omitted during translation.
- the read function name can be translated according to the function key mapping table.
- the HLSL Shader file can be translated into the GLSL Shader file.
- the GLSL Shader file and the HLSL Shader file have a one-to-one correspondence effect on words, and are highly readable, which is convenient for subsequent optimization and error adjustment on the target platform.
- SPIR-V is a modern binary low-level intermediate representation language used in many APIs (Application Programming Interface) such as Vulkan, OpenCL, and OpenGL.
- Vulkan is a low-overhead, cross-platform application program interface for two-dimensional and three-dimensional graphics and computing. Similar to OpenGL, Vulkan is designed for real-time 3D graphics programs on all platforms.
- the execution subject of each step of the method provided in the foregoing embodiment may be the same device, or the method may also be executed by different devices.
- the execution subject of steps 201 to 204 may be device A; for another example, the execution subject of steps 201 and 202 may be device A, and the execution subject of step 203 may be device B; and so on.
- FIG. 3 is a schematic structural diagram of an electronic device provided by an exemplary embodiment of the present application. As shown in FIG. 3, the electronic device includes a memory 301 and a processor 302.
- the memory 301 is used to store computer programs and can be configured to store other various data to support operations on the electronic device. Examples of such data include instructions for any application or method operated on an electronic device, contact data, phone book data, messages, pictures, videos, etc.
- the memory 301 can be implemented by any type of volatile or non-volatile storage device or their combination, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable Except programmable read only memory (EPROM), programmable read only memory (PROM), read only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
- SRAM static random access memory
- EEPROM electrically erasable programmable read-only memory
- EPROM erasable except programmable read only memory
- PROM programmable read only memory
- ROM read only memory
- magnetic memory flash memory
- flash memory magnetic disk or optical disk.
- the processor 302 is coupled with the memory 301, and is configured to execute a computer program in the memory 301, so as to perform a syntax analysis on a first code file corresponding to the first shading language to obtain an abstract syntax tree of the first code file; Analyze the keywords of multiple nodes in the abstract syntax tree to obtain the coloring language information of the first code file; perform the coloring language information of the first code file according to the set information mapping rules Translate to obtain a second code file corresponding to the second shading language; wherein the information mapping rule is determined according to the grammatical rules of the first shading language and the second shading language.
- mapping rule includes at least one of the following: a variable mapping rule between the first shading language and the second shading language; one of the first shading language and the second shading language Function mapping rules between.
- the processor 302 is further configured to: determine a variable to be processed from the first code file, and the name of the variable to be processed contains the same character string as the reserved keyword in the translation tool; The name of the variable to be processed is modified to avoid using reserved keywords as variable names in the second code file.
- variable to be processed includes at least one of a global parameter variable named Buffer, a variable whose name includes the character string Texture, and a variable whose name includes the character string Buffer.
- the coloring language information of the first code file includes: information about global parameters in the first code file, information about resources in the first code file, and the first code At least one of structure information in the file and function information in the first code file.
- the processor 302 analyzes keywords of multiple nodes in the abstract syntax tree to obtain the coloring language information of the first code file, it is specifically configured to: target the multiple nodes For any node in the node, determine the key variable corresponding to the node according to the type keyword of the node; analyze the key variable corresponding to the node to obtain the coloring language information corresponding to the node; according to the multiple The coloring language information corresponding to the respective nodes is used to obtain the coloring language information of the first code file.
- the processor 302 analyzes the key variable corresponding to the node to obtain the coloring language information corresponding to the node, it is specifically used for: if the type keyword of the node is a global parameter variable structure , The type variables and name variables of the child nodes of the node are analyzed to obtain the type and name of the global parameter-passing variable contained in the global parameter-passing variable structure; the global parameter-passing variable structure contained in the global The type and name of the passed parameter variable are stored in the variable dictionary.
- the processor 302 analyzes the key variable corresponding to the node to obtain the coloring language information corresponding to the node, it is specifically configured to: if the type keyword of the node contains a character string representing a resource, Then, the name variable and the register allocation variable of the node are parsed to obtain the name and register address of the resource; the name and register address of the resource are correspondingly saved in the resource dictionary.
- the resources include: at least one of texture resources, buffer resources, and register resources.
- the processor 302 analyzes the key variable corresponding to the node to obtain the coloring language information corresponding to the node, it is specifically used for: if the type keyword of the node is a function definition or a function declaration, Parse the function type variable and name variable of the node to obtain the return type and function name of the first function corresponding to the node; use the return type and function name of the first function as the information of the first function , And save the information of the first function in the function dictionary.
- the processor 302 is further configured to: parse the type variable and the name variable of the child node of the function parameter variable of the node to obtain the type and name of the formal parameter variable of the first function, and compare the The type and name of the formal parameter variable of the first function are written into the information of the first function; if the formal parameter variable of the first function includes a formal parameter variable with out or inout attribute, then the In the function information, the formal parameter variable with the out or inout attribute is recorded.
- the processor 302 is further configured to: obtain a subtree corresponding to any child node of the code block variable of the node; if the type of the first node in the subtree is a function call, parse the The name variable and actual parameter variable of the first node are used to obtain the function name and parameter passing information corresponding to the first node; in the function dictionary, the function name corresponding to the first node and the target corresponding to the parameter passing information are queried Function as a calling function of the first function, and writing the calling function into the information of the first function.
- the processor 302 is further configured to: if the second node in the subtree uses the first global resource, write the information of the first global resource into the information of the first function;
- the first global resource includes at least one of a texture resource, a buffer resource, and a sampler resource; if the third node in the subtree uses the first global parameter variable, the first global parameter is transmitted The information of the parameter is written into the information of the first function.
- the processor 302 is further configured to: determine an entry function from the function dictionary; starting from the entry function, use a depth-first search method to search for each function called by the entry function; The function called by the entry function is recorded in the target function set.
- the processor 302 parses the respective key variables of the multiple nodes to obtain the coloring language information of the first code file, it is specifically configured to: if the type keyword of the node is a structure Body definition, the name variable of the node and the child node of the class member declaration variable are parsed to obtain the name of the first structure corresponding to the node and the information of the class member contained in the first structure; The name of the first structure and the information of the class members contained in the first structure are stored in the global linked list.
- the processor 302 is further configured to: traverse the function dictionary to determine an entry function from the function dictionary; if the first structure body matches the return type of the entry function, determine all The first structure is an output type structure; if the first structure matches the type of the formal parameter variable of the entry function, it is determined that the first structure is an input type structure.
- the processor 302 when the processor 302 translates the coloring language information of the first code file according to the set information mapping rule, it is specifically configured to: obtain the first structure from the global linked list; According to the variable mapping rules, the variables in the first structure are translated to map the first structure into a second structure conforming to the grammar of the second shading language.
- the processor 302 when the processor 302 translates the variables in the first structure according to the variable mapping rules, it is specifically configured to: if the first structure is the structure of the input type of the vertex shader, Set the attribute number of the variable in the second structure obtained by mapping to be consistent with the attribute number of the variable in the first structure; if the first structure is the structure of the output type of the vertex shader or Is the input type structure of the fragment shader, after mapping the variable with the attribute SV_POSITION in the first structure to the variable in the second structure, add [[position] to the mapped variable ] Identification; if the first structure is a structure of the output type of the fragment shader, after mapping the variable whose attribute is SV_Target in the first structure to the variable in the second structure, Add [[color]] to the mapped variable, and synchronize the number of the variable whose attribute is SV_Target.
- the processor 302 when the processor 302 translates the coloring language information of the first code file according to the set information mapping rule, it is specifically configured to: map the global parameter variable in the variable dictionary to The member variable of the first target structure.
- the processor 302 is specifically configured to: obtain the first function from the target function set when translating the shading language information of the first code file according to the set information mapping rule; According to the variable mapping rule and/or the function mapping rule, the first function is translated to map the first function to a second function conforming to the grammar of the second shading language.
- the processor 302 interprets the first function according to the information of the first function and the function mapping rules, it is specifically configured to: if the first function is not an entry function, then Add the inline keyword before the return type of the second function.
- the processor 302 interprets the first function according to the information of the first function and the function mapping rules, it is specifically configured to: if the information of the first function records that there is out or The formal parameter variable of the inout attribute generates a third structure in the second function; according to the parameter transfer order of the formal parameter variable with the out or inout attribute, at least one is defined in the third structure in turn A formal parameter variable; wherein the type of the at least one formal parameter variable is the same as the type of the formal parameter variable with the out or inout attribute, and the name of the at least one formal parameter variable is provided with an output parameter prefix.
- the processor 302 is further configured to: determine the return type of the first function from the information of the first function; if the return type of the first function is not empty, perform the A return parameter variable is defined in the structure; the return parameter variable is the same as the return type of the first function.
- the processor 302 when the processor 302 translates the first function according to the information of the first function and the function mapping rule, it is specifically configured to: if the first function is determined according to the information of the first function, The function uses the first global parameter variable, when generating the formal parameter information of the second function, the first target structure is used as the first formal parameter of the second function; If the information of the first function determines that the first function uses the first global resource, when the formal parameter information of the second function is generated, the information of the first global resource is placed in addition to the first global resource. Before a formal parameter other than the target structure.
- the order of the first global resource in the formal parameters of the second function is: buffer resource, texture resource, sampler resource; wherein, any one of the first global resources is global
- the resources inside the resource are sorted according to the size of the register corresponding to the resource.
- the processor 302 interprets the first function according to the information of the first function and the function mapping rules, it is specifically configured to: if the first function is an entry function, perform the In the formal parameter variable of the entry function, declare the first target structure, the buffer resource in the resource dictionary, the texture resource in the resource dictionary, and the sampler resource in the resource dictionary; Add a buffer mark after the first target structure and the buffer resource, add a texture mark after the texture resource, and add a sampler mark after the sampler resource.
- the processor 302 is further configured to perform at least one of the following operations: in the formal parameter variable of the first function, the stage keyword is used to mark the formal parameter of the input type; if the first function and vertex coloring If the first function corresponds to the fragment shader, add the keyword representing the fragment before the return type of the first function. Keywords.
- the first code file is a code file of the HLSL shading language
- the second code file is a code file corresponding to the Metal shading language.
- the processor 302 when the processor 302 translates the coloring language information of the first code file according to the set information mapping rule, it is specifically configured to: map the global parameter variable in the variable dictionary to Member variables of the second target structure; define a uniform variable block, and store the second target structure in the uniform variable block; traverse the abstract syntax tree, if the name of the current node traversed is consistent with the If the name of any global parameter variable stored in the uniform variable block is the same, the name identifier of the uniform variable block is added before the name of the current node.
- processor 302 is further configured to: obtain the global parameter passing variable structure from the variable dictionary; use layout to set the set modifier and binding modifier of the global parameter passing variable structure.
- the processor 302 when the processor 302 translates the coloring language information of the first code file according to the set information mapping rule, it is specifically configured to: obtain any resource to be translated from the resource dictionary ; Use layout to set the binding modifier of the resource to be translated, and add a uniform keyword before the variable type of the resource to be translated; wherein the value of the binding modifier is based on the register of the resource to be translated The value is OK.
- the processor 302 when the processor 302 translates the coloring language information of the first code file, it is specifically configured to: obtain the first structure from the global linked list; Translate the variables in the first structure to map the first structure to a second structure conforming to the grammar of the second shading language; translate the input type and output type corresponding to the first structure respectively Are the input variables and output variables of the second structure; if the first structure is the input type structure of the vertex shader, the layout keyword is used to define location for the input variables in the second structure Modifier, and when declaring the input variable in the second structure, add the in keyword before the type of the input variable in the second structure; wherein, the value of the location modifier is the same as that of the first The attribute numbers of the variables in the structure are the same; if the first structure is the output type structure of the vertex shader, when translating the first structure, the reserved keyword gl_Positon is used instead of the variable whose attribute is SV_POSITION ; And, when declaring the input variable in the second structure, add the
- the processor 302 may perform at least one of the following operations when translating the first function according to the information of the first function and the function mapping rule: acquiring the target function set The first function; according to the variable mapping rule and/or the function mapping rule, the information of the first function is translated, so as to map the first function to the first function conforming to the grammar of the second shading language Second function; if the first function is a resource reading function, in the second function obtained by translation, the type of the resource to be read, the location of the resource to be read, and other parameters are written in the In the function body of the second function; if the first function is an entry function, the return value of the second function obtained by mapping the first function is set to void.
- the processor 302 is further configured to: the first code file is a code file of the HLSL shading language; the second code file is a code file corresponding to the GLSL shading language.
- the electronic device further includes: a communication component 303, a display 304, a power supply component 305, an audio component 306 and other components. Only part of the components are schematically shown in FIG. 3, which does not mean that the electronic device only includes the components shown in FIG. 3.
- the communication component 303 is configured to facilitate wired or wireless communication between the device where the communication component is located and other devices.
- the device where the communication component is located can access a wireless network based on a communication standard, such as WiFi, 2G, 3G, 4G, or 5G, or a combination of them.
- the communication component receives a broadcast signal or broadcast related information from an external broadcast management system via a broadcast channel.
- the communication component may be based on near field communication (NFC) technology, radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology, and other technologies to realise.
- NFC near field communication
- RFID radio frequency identification
- IrDA infrared data association
- UWB ultra-wideband
- Bluetooth Bluetooth
- the display component 304 includes a screen, and the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from the user.
- the touch panel includes one or more touch sensors to sense touch, sliding, and gestures on the touch panel. The touch sensor may not only sense the boundary of a touch or slide action, but also detect the duration and pressure related to the touch or slide operation.
- the power supply component 305 provides power for various components of the equipment where the power supply component is located.
- the power supply component may include a power management system, one or more power supplies, and other components associated with the generation, management, and distribution of power for the equipment where the power supply component is located.
- node analysis is performed based on the abstract syntax tree, and the original syntax structure of the code file of the original coloring language is retained.
- node-based keyword analysis realizes the corresponding translation between different types of information, which is conducive to improving the readability of the translation results; in addition, the information mapping rules can be updated according to actual needs to improve The scalability of the language translation method is improved, and the new coloring language grammar can be supported quickly and conveniently.
- the embodiments of the present application also provide a computer-readable storage medium storing a computer program, and when the computer program is executed, the steps that can be executed by the electronic device in the foregoing method embodiments can be implemented.
- the various component embodiments of the present invention may be implemented by hardware, or by software modules running on one or more processors, or by a combination of them.
- a microprocessor or a digital signal processor (DSP) may be used in practice to implement some or all of the functions of some or all of the components in the electronic device of the embodiment of the present invention.
- DSP digital signal processor
- the present invention can also be implemented as a device or device program (for example, a computer program and a computer program product) for executing part or all of the methods described herein.
- Such a program for realizing the present invention may be stored on a computer-readable medium, or may have the form of one or more signals.
- Such a signal can be downloaded from an Internet website, or provided on a carrier signal, or provided in any other form.
- FIG. 4 shows a server, such as an application server, that can implement the shading language translation method of the present invention.
- the server traditionally includes a processor 410 and a computer program product in the form of a memory 420 or a computer-readable medium.
- the memory 420 may be an electronic memory such as flash memory, EEPROM (Electrically Erasable Programmable Read Only Memory), EPROM, hard disk, or ROM.
- the memory 420 has a storage space 430 for executing the program code 431 of any method step in the foregoing method.
- the storage space 430 for program codes may include various program codes 431 respectively used to implement various steps in the above method. These program codes can be read from or written into one or more computer program products.
- Such computer program products include program code carriers such as hard disks, compact disks (CDs), memory cards, or floppy disks.
- Such a computer program product is usually a portable or fixed storage unit as described with reference to FIG. 5.
- the storage unit may have storage segments, storage space, etc., arranged similarly to the storage 420 in the server of FIG. 4.
- the program code can be compressed in a suitable form, for example.
- the storage unit includes computer-readable codes 431', that is, codes that can be read by, for example, a processor such as 410, which, when run by a server, causes the server to perform the steps in the method described above.
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- Computer Graphics (AREA)
- Software Systems (AREA)
- Devices For Executing Special Programs (AREA)
Abstract
A shading language translation method. In the method, an abstract syntax tree of a code file in the original shading language is obtained, and keywords of nodes in the abstract syntax tree are analyzed to obtain shading language information contained in the code file in the original shading language. In combination with a set information mapping rule, the shading language information can be translated to obtain a code file in another shading language. In this process, node analysis is performed on the basis of the abstract syntax tree, and the original syntactic structure of the code file in the original shading language is retained. Moreover, analysis is performed on the basis of the keywords of the nodes, so that corresponding translations among different types of information are realized, and the improvement of the readability of translation results is facilitated; in addition, the information mapping rule can be updated according to actual needs, so that the expansibility of a language translation method is improved, and the quick support for a new shading language syntax is facilitated.
Description
交叉引用cross reference
本申请引用于2020年6月15日递交的名称为“着色语言翻译方法”的第2020105396814号中国专利申请,其通过引用被全部并入本申请。This application is cited in the Chinese Patent Application No. 2020105396814 named "Method of Coloring Language Translation" filed on June 15, 2020, which is fully incorporated into this application by reference.
本申请涉及数据处理技术领域,尤其涉及一种着色语言翻译方法。This application relates to the field of data processing technology, and in particular to a coloring language translation method.
着色语言(Shading Language),是一类专门用于为着色器进行编程的着色语言。目前,由微软开发并拥有的一种高阶着色器语言(High Level Shader Language,HLSL)较受业界欢迎。但是,HLSL只能工作在Windows(微软开发的一种操作系统)平台上,进而导致运行有其他操作系统的目标平台存在使用受限的问题。Shading Language (Shading Language) is a type of shading language specifically used to program shaders. At present, a high-level shader language (HLSL) developed and owned by Microsoft is more popular in the industry. However, HLSL can only work on Windows (an operating system developed by Microsoft) platform, which in turn leads to the problem of restricted use of target platforms running other operating systems.
现有技术中,存在一种通过反汇编操作将HLSL的代码翻译为目标平台可使用的代码的方式。但是,反汇编操作翻译得到的代码具有可读性较差的缺陷,不利于在目标平台上进行优化和调试。因此,有待提出一种新的解决方案。In the prior art, there is a way of translating HLSL code into code usable by the target platform through a disassembly operation. However, the code obtained by disassembly operation translation has the defect of poor readability, which is not conducive to optimization and debugging on the target platform. Therefore, a new solution needs to be proposed.
发明内容Summary of the invention
鉴于上述问题,提出了本发明以便提供一种克服上述问题或者至少部分地解决或者减缓上述问题的着色语言翻译方法。In view of the above-mentioned problems, the present invention is proposed to provide a coloring language translation method that overcomes the above-mentioned problems or at least partially solves or alleviates the above-mentioned problems.
根据本发明的一个方面,提供了一种色语言翻译方法,包括:对第一着色语言对应的第一代码文件进行语法分析,得到所述第一代码文件的抽象语法树;对所述抽象语法树中的多个节点的关键字进行分析,以获取所述第一代码文件的着色语言信息;根据设定的信息映射规则,对所述第一代码文件的着色语言信息进行翻译,得到第二着色语言对应的第二代码文件;其中,所述信息映射规则根据所述第一着色语言和所述第二着色语言的语法规则确定。According to one aspect of the present invention, a color language translation method is provided, which includes: performing syntax analysis on a first code file corresponding to the first coloring language to obtain an abstract syntax tree of the first code file; The keywords of multiple nodes in the tree are analyzed to obtain the coloring language information of the first code file; according to the set information mapping rules, the coloring language information of the first code file is translated to obtain the second A second code file corresponding to the coloring language; wherein the information mapping rule is determined according to the grammatical rules of the first coloring language and the second coloring language.
本发明的有益效果为:基于抽象语法树进行节点分析,保留了原着色语言的代码文件原有的语法结构。与此同时,基于节点的关键字进行分析,实现了不同类型的信息之间的对应翻译,有利于提升翻译结果的可读性;除此之外,信息映射规则可根据实际需求进行更新,提升了语言翻译方法的可拓展性,方便快速地支持新的着色语言语法。The beneficial effects of the present invention are: node analysis is performed based on the abstract syntax tree, and the original syntax structure of the code file of the original coloring language is retained. At the same time, node-based keyword analysis realizes the corresponding translation between different types of information, which is conducive to improving the readability of the translation results; in addition, the information mapping rules can be updated according to actual needs to improve The scalability of the language translation method is improved, and the new coloring language grammar can be supported quickly and conveniently.
上述说明仅是本发明技术方案的概述,为了能够更清楚了解本发明的技术手段, 而可依照说明书的内容予以实施,并且为了让本发明的上述和其它目的、特征和优点能够更明显易懂,以下特举本发明的具体实施方式。The above description is only an overview of the technical solution of the present invention. In order to understand the technical means of the present invention more clearly, it can be implemented in accordance with the content of the specification, and in order to make the above and other objectives, features and advantages of the present invention more obvious and understandable. In the following, specific embodiments of the present invention will be cited.
通过阅读下文优选实施方式的详细描述,各种其他的优点和益处对于本领域普通技术人员将变得清楚明了。附图仅用于示出优选实施方式的目的,而并不认为是对本发明的限制。而且在整个附图中,用相同的参考符号表示相同的部件。在附图中:By reading the detailed description of the preferred embodiments below, various other advantages and benefits will become clear to those of ordinary skill in the art. The drawings are only used for the purpose of illustrating the preferred embodiments, and are not considered as a limitation to the present invention. Also, throughout the drawings, the same reference symbols are used to denote the same components. In the attached picture:
图1为本申请一示例性实施例提供的着色语言翻译方法的流程示意图;FIG. 1 is a schematic flowchart of a coloring language translation method provided by an exemplary embodiment of this application;
图2为本申请另一示例性实施例提供的着色语言翻译方法的流程示意图;2 is a schematic flowchart of a coloring language translation method provided by another exemplary embodiment of this application;
图3为本申请一示例性实施例提供的电子设备的结构示意图;FIG. 3 is a schematic structural diagram of an electronic device provided by an exemplary embodiment of this application;
图4为本申请一示例性实施例提供的服务器的结构示意图;FIG. 4 is a schematic structural diagram of a server provided by an exemplary embodiment of this application;
图5为本申请一示例性实施例提供的计算程序产品的结构示意图。Fig. 5 is a schematic structural diagram of a computing program product provided by an exemplary embodiment of the application.
下面结合附图和具体的实施方式对本发明作进一步的描述。The present invention will be further described below in conjunction with the drawings and specific embodiments.
为使本发明实施例的目的、技术方案和优点更加清楚,下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。In order to make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be described clearly and completely in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments It is a part of the embodiments of the present invention, but not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative work shall fall within the protection scope of the present invention.
针对现有的着色语言翻译方法无法翻译得到可读性较高的翻译结果的技术问题,在本申请一些实施例中,提供了一种解决方案,以下结合附图,详细说明本申请各实施例提供的技术方案。In view of the technical problem that the existing coloring language translation method cannot translate and obtain a highly readable translation result, in some embodiments of the present application, a solution is provided. The following describes each embodiment of the present application in detail with reference to the accompanying drawings. Provide technical solutions.
图1为本申请一示例性实施例提供的着色语言翻译方法的流程示意图,如图1所示,该方法包括:FIG. 1 is a schematic flowchart of a coloring language translation method provided by an exemplary embodiment of the application. As shown in FIG. 1, the method includes:
步骤101、对第一着色语言对应的第一代码文件进行语法分析,得到所述第一代码文件的抽象语法树。Step 101: Perform syntax analysis on a first code file corresponding to the first coloring language to obtain an abstract syntax tree of the first code file.
步骤102、对所述抽象语法树中的多个节点的关键字进行分析,以获取所述第一代码文件的着色语言信息。Step 102: Analyze keywords of multiple nodes in the abstract syntax tree to obtain the coloring language information of the first code file.
步骤103、根据设定的信息映射规则,对所述第一代码文件的着色语言信息进行翻译,得到第二着色语言对应的第二代码文件;其中,所述信息映射规则根据所述第一着色语言和所述第二着色语言的语法规则确定。Step 103: Translate the coloring language information of the first code file according to the set information mapping rule to obtain a second code file corresponding to the second coloring language; wherein, the information mapping rule is based on the first coloring language. The language and the grammatical rules of the second coloring language are determined.
其中,抽象语法树(Abstract Syntax Tree,AST)是源代码语法结构的一种抽象表示。 它以树状结构表现源代码的语法结构,树状结构上的一个节点表示源代码中的一种结构。Among them, the abstract syntax tree (Abstract Syntax Tree, AST) is an abstract representation of the source code syntax structure. It expresses the grammatical structure of the source code in a tree structure, and a node on the tree structure represents a structure in the source code.
其中,节点的关键字,可以是节点对应的变量的关键字。该关键字可以是节点对应的代码中的变量名称,或者变量包含的字符串,本实施例不做限制。Among them, the key of the node may be the key of the variable corresponding to the node. The keyword can be the name of the variable in the code corresponding to the node, or the character string contained in the variable, which is not limited in this embodiment.
其中,获取第一代码文件的抽象语法树的操作,可基于语法树生成器实现,本实施例不做限制。例如,第一代码文件实现为HLSL着色语言的source.hlsl文件时,可采用HlslParser开源软件提取source.hlsl的抽象语法树,得到source_AST。Wherein, the operation of obtaining the abstract syntax tree of the first code file can be implemented based on the syntax tree generator, which is not limited in this embodiment. For example, when the first code file is implemented as the source.hlsl file of the HLSL shading language, the HlslParser open source software can be used to extract the abstract syntax tree of source.hlsl to obtain source_AST.
其中,所述映射规则,包括:所述第一着色语言和所述第二着色语言之间的变量映射规则;和/或,所述第一着色语言和所述第二着色语言之间的函数映射规则。Wherein, the mapping rule includes: a variable mapping rule between the first shading language and the second shading language; and/or, a function between the first shading language and the second shading language Mapping rules.
其中,所述变量映射规则和所述函数映射规则根据所述第一着色语言和所述第二着色语言的语法规则确定。变量映射规则,用于对第一代码文件的着色语言信息涉及到的变量进行翻译,以将第一代码文件中的变量翻译为符合第二着色语言的语法的变量。函数映射规则,用于对第一代码文件的着色语言信息包含的函数进行翻译,以将第一代码文件中的函数翻译为符合第二着色语言的语法的函数。Wherein, the variable mapping rule and the function mapping rule are determined according to the grammar rules of the first shading language and the second shading language. The variable mapping rule is used to translate the variables involved in the coloring language information of the first code file, so as to translate the variables in the first code file into variables that conform to the grammar of the second coloring language. The function mapping rule is used to translate the functions included in the shading language information of the first code file, so as to translate the functions in the first code file into a function conforming to the syntax of the second shading language.
其中,第一着色语言适用于第一平台,第二着色语言适用于第二平台,第一平台和第二平台可以是搭载不同操作系统的平台。基于本实施例,可将适用于第一平台的着色语言翻译成适用于第二平台的着色语言,以便于实现着色语言的跨平台灵活使用。Among them, the first shading language is applicable to the first platform, and the second shading language is applicable to the second platform. The first platform and the second platform may be platforms equipped with different operating systems. Based on this embodiment, the shading language suitable for the first platform can be translated into the shading language suitable for the second platform, so as to realize the cross-platform flexible use of the shading language.
在本实施例中,基于抽象语法树进行节点分析,保留了原着色语言的代码文件原有的语法结构。与此同时,基于节点的关键字进行分析,实现了不同类型的信息之间的对应翻译,有利于提升翻译结果的可读性;除此之外,信息映射规则可根据实际需求进行更新,提升了语言翻译方法的可拓展性,方便快速地支持新的着色语言语法。In this embodiment, node analysis is performed based on the abstract syntax tree, and the original syntax structure of the code file of the original coloring language is retained. At the same time, node-based keyword analysis realizes the corresponding translation between different types of information, which is conducive to improving the readability of the translation results; in addition, the information mapping rules can be updated according to actual needs to improve The scalability of the language translation method is improved, and the new coloring language grammar can be supported quickly and conveniently.
通常,翻译工具内部对部分字进行了定义,这部分字被称为保留关键字(reserved word)。保留关键字不可作为变量名或过程名使用,因此,为避免使用保留关键字,可对第一代码文件进行预处理,以下将进行示例性说明。Generally, some words are defined internally in translation tools, and these words are called reserved words. Reserved keywords cannot be used as variable names or process names. Therefore, in order to avoid using reserved keywords, the first code file can be preprocessed, which will be illustrated below.
在一些可选的实施例中,可从所述第一代码文件中,确定待处理的变量,该待处理的变量的名称包含与翻译工具中的保留关键字相同的字符串。接下来,可对所述待处理的变量的名称进行修改,以避免在翻译过程中出现保留关键字。In some optional embodiments, the variable to be processed may be determined from the first code file, and the name of the variable to be processed contains the same character string as the reserved keyword in the translation tool. Next, the name of the variable to be processed can be modified to avoid the occurrence of reserved keywords during the translation process.
可选地,所述待处理的变量,包括:名称为Buffer的全局传参变量、名称包含字符串Texture的变量以及名称包含字符串Buffer的变量中的至少一种。可选地,对所述待处理的变量的名称进行修改时,可将所述第一代码文件中的全局传参变量的名称Buffer设置为Cbuffer;将所述第一代码文件中变量的名称中的Texture,设置为texture;或者,将所述第一代码文件中变量的名称中的Buffer,设置为buffer。Optionally, the variable to be processed includes at least one of a global parameter variable named Buffer, a variable whose name contains the character string Texture, and a variable whose name contains the character string Buffer. Optionally, when the name of the variable to be processed is modified, the name Buffer of the global parameter variable in the first code file may be set to Cbuffer; and the name of the variable in the first code file may be The texture of is set to texture; or, the Buffer in the name of the variable in the first code file is set to buffer.
前述实施例的步骤103记载了对该抽象语法树中的多个节点的关键字进行分析,以获取该第一代码文件的着色语言信息的方案,在一些可选的实施例中,第一代码文件的着色语言信息,包括:该第一代码文件中的全局传参变量结构体的信息、该第一代码文件中的资源的信息、该第一代码文件中的结构体的信息以及该第一代码文件中的函数的信息中的至少一种。Step 103 of the foregoing embodiment records a solution for analyzing the keywords of multiple nodes in the abstract syntax tree to obtain the coloring language information of the first code file. In some optional embodiments, the first code The coloring language information of the file includes: information about the global parameter variable structure in the first code file, information about the resources in the first code file, information about the structure in the first code file, and the first code file. At least one of the function information in the code file.
以下将以该多个节点中的任一节点为例,对分析节点的关键字的过程进行示例性说明。In the following, taking any one of the multiple nodes as an example, the process of analyzing the keywords of the node will be exemplified.
需要说明的是,下述各实施例中涉及到的Shader,指的是保存有着色语言的代码文件,例如,HLSL文件、GLSL的文件或者SPIR-V文件,后续不再一一进行解释。It should be noted that the Shader involved in the following embodiments refers to a code file that stores a shading language, for example, an HLSL file, a GLSL file, or a SPIR-V file, and will not be explained one by one in the following.
在一些可选的实施例中,针对该多个节点中的任一节点,根据该节点的类型关键字,确定该节点对应的关键变量;接着,对该节点对应的关键变量进行解析,得到该节点对应的着色语言信息。遍历抽象语法树之后,可获取到多个节点各自对应的着色语言信息,接着,可根据该多个节点各自对应的着色语言信息,获取该第一代码文件的着色语言信息。In some optional embodiments, for any node of the plurality of nodes, the key variable corresponding to the node is determined according to the type keyword of the node; then, the key variable corresponding to the node is analyzed to obtain the The coloring language information corresponding to the node. After traversing the abstract syntax tree, the coloring language information corresponding to each of the multiple nodes can be obtained, and then the coloring language information of the first code file can be obtained according to the coloring language information corresponding to each of the multiple nodes.
对于节点而言,基于节点的类型关键字可以确定节点的基本类型,节点的基本类型用于描述节点存储的着色语言信息。For nodes, the basic type of the node can be determined based on the type keyword of the node, and the basic type of the node is used to describe the coloring language information stored by the node.
可选地,节点的类型关键字,可包括:全局传参变量结构体、类定义、结构体定义、变量、函数定义、函数声明、采样器以及函数调用类型中的至少一种。Optionally, the type keyword of the node may include: at least one of a global parameter-passing variable structure, class definition, structure definition, variable, function definition, function declaration, sampler, and function call type.
以第一代码文件实现为HLSL的代码文件为例,HLSL的代码文件中,节点的类型关键字以及对应的着色器功能可如以下表1所示:Taking the first code file implemented as an HLSL code file as an example, in the HLSL code file, the node type keywords and the corresponding shader functions can be as shown in Table 1 below:
表1Table 1
节点的基本类型Basic types of nodes | Shader功能Shader function |
CBufferCBuffer | 全局传参变量结构体Global parameter variable structure |
ClassClass | 类定义Class definition |
StructStruct | 结构体定义Structure definition |
VariableVariable | 变量variable |
FunctionDefinitionFunctionDefinition | 函数定义Function definition |
FunctionDeclarationFunctionDeclaration | 函数声明Function declaration |
SamplerStateSamplerState | 采样器Sampler |
FunctionCallFunctionCall | 函数调用Function call |
其中,节点对应的关键变量,指的是存储有节点的着色语言信息的变量,对这些关键变量进行分析,可获取节点存储的着色语言信息。其中,节点的类型关键字不同 时,节点的关键变量也不同。Among them, the key variable corresponding to the node refers to the variable that stores the coloring language information of the node. By analyzing these key variables, the coloring language information stored in the node can be obtained. Among them, when the node type keyword is different, the key variable of the node is also different.
例如,当节点存储的是资源信息时,节点的关键变量可以是寄存器分配变量(RegisterAllocationOptData变量),该寄存器分配变量包含有资源的寄存器信息。For example, when the node stores resource information, the key variable of the node may be a register allocation variable (RegisterAllocationOptData variable), and the register allocation variable contains the register information of the resource.
例如,当节点的类型为函数定义(FunctionDefinition)或函数声明(FunctionDeclaration)时,节点的关键变量可以包括:函数类型(FunctionType)变量、函数参数变量(FunctionParamsOptData)和代码块变量(Block)。其中,FunctionType变量存有函数的返回类型的信息,FunctionParamsOptData存有函数的参数信息,Block内包含函数内部的所有语句。For example, when the type of the node is a function definition (FunctionDefinition) or a function declaration (FunctionDeclaration), the key variables of the node may include: a function type (FunctionType) variable, a function parameter variable (FunctionParamsOptData), and a code block variable (Block). Among them, the FunctionType variable stores the return type information of the function, FunctionParamsOptData stores the parameter information of the function, and the Block contains all the statements inside the function.
例如,当节点的基本类型为函数调用(FunctionCall)时,节点将具有实参变量(ArgumentList),该实参变量包含了函数调用时传入的参数。For example, when the basic type of a node is a function call (FunctionCall), the node will have an argument variable (ArgumentList), which contains the parameters passed in when the function is called.
又例如,当节点的基本类型为结构体(Struct)时,节点将具有类成员声明变量(ClassMemberDeclarations),此变量包含了结构体内的成员变量信息。For another example, when the basic type of the node is a structure (Struct), the node will have a class member declaration variable (ClassMemberDeclarations), which contains the member variable information in the structure.
基于上述,可根据节点的类型关键字,确定节点的关键变量,并对节点的关键变量进行分析,以得到该节点对应的着色语言信息。Based on the above, the key variable of the node can be determined according to the type keyword of the node, and the key variable of the node can be analyzed to obtain the coloring language information corresponding to the node.
可选地,若该节点的类型关键字为全局传参变量结构体,则对该节点的子节点的类型变量和名称变量进行解析,得到该全局传参变量结构体包含的全局传参变量的类型和名称;该将该全局传参变量结构体包含的全局传参变量的类型和名称保存在变量字典中。Optionally, if the type keyword of the node is a global parameter variable structure, then the type variables and name variables of the child nodes of the node are parsed to obtain the global parameter variable structure contained in the global parameter variable structure Type and name; the type and name of the global parameter variable contained in the global parameter variable structure should be stored in the variable dictionary.
继续以HLSL代码文件为例,当抽象语法树中,某一高级节点的基本类型为“CBuffer”时,可对该节点的所有子节点进行解析。其中,每个子结点可解析出一个全局传参变量的信息。针对每个子节点,通过解析该子节点的类型变量(Type变量)和名称变量(Name变量),得到该子节点对应的全局传参变量的名称和类型。接着,将全局传参变量结构体中的所有全局传参变量的信息保存到一个全局的变量字典中。可选地,该全局变量字典可被记为GVariableDictionary。Continuing to take the HLSL code file as an example, when the basic type of a certain high-level node in the abstract syntax tree is "CBuffer", all child nodes of the node can be parsed. Among them, each sub-node can parse out the information of a global parameter variable. For each child node, by analyzing the type variable (Type variable) and name variable (Name variable) of the child node, the name and type of the global parameter variable corresponding to the child node are obtained. Then, save the information of all global parameter-passing variables in the global parameter-passing variable structure into a global variable dictionary. Optionally, the global variable dictionary can be recorded as GVariableDictionary.
可选地,若该节点的类型关键字包含表示资源的字符串,则解析该节点的名称变量和寄存器分配变量,以获取该资源的名称和寄存器地址;将该资源的名称和寄存器地址,对应保存在资源字典中。Optionally, if the type keyword of the node contains a character string representing a resource, the name variable and register allocation variable of the node are parsed to obtain the name and register address of the resource; the name and register address of the resource correspond to Saved in the resource dictionary.
可选地,该资源包括:纹理资源、缓冲器资源以及寄存器资源中的至少一中。以下将分别结合上述多种资源进行说明。Optionally, the resource includes: at least one of a texture resource, a buffer resource, and a register resource. The following will be described in combination with the above-mentioned multiple resources.
可选地,若该节点的类型变量的值包含表示纹理资源的字符串,则获取该节点的名称变量的值,作为该纹理资源的名称;接着,解析该节点的寄存器分配变量,以获 取该纹理资源的寄存器地址;接着,将该纹理资源的名称和寄存器地址对应保存在纹理字典中。Optionally, if the value of the type variable of the node contains a string representing the texture resource, the value of the name variable of the node is obtained as the name of the texture resource; then, the register allocation variable of the node is parsed to obtain the The register address of the texture resource; then, the name of the texture resource and the register address are correspondingly saved in the texture dictionary.
继续以HLSL代码文件为例,当语法树节点的Type变量值为包含字符串“Texture”时,则可记录此节点的Name变量值为该节点对应的纹理资源的名称,同时解析此节点的RegisterAllocationOptData变量,获取寄存器地址。接着,将纹理资源和对应的寄存器地址保存到一个全局的纹理资源字典中,记为GTexutreDictionary。Continuing to take the HLSL code file as an example, when the Type variable value of the syntax tree node contains the string "Texture", the Name variable value of this node can be recorded as the name of the texture resource corresponding to the node, and the RegisterAllocationOptData of this node can be parsed. Variable, get register address. Then, save the texture resource and the corresponding register address in a global texture resource dictionary, which is recorded as GTexutreDictionary.
可选地,若该节点的类型变量的值包含表示缓冲器资源的字符串,则获取该节点的名称变量的值,作为该缓冲器资源的名称;接着,解析该节点的寄存器分配变量,以获取该缓冲器资源的寄存器地址;接着,将该缓冲器资源的名称和寄存器地址对应保存在缓冲器字典中。Optionally, if the value of the type variable of the node contains a character string representing the buffer resource, the value of the name variable of the node is obtained as the name of the buffer resource; then, the register allocation variable of the node is parsed to Obtain the register address of the buffer resource; then, the name of the buffer resource and the register address are correspondingly saved in the buffer dictionary.
继续以HLSL代码文件为例,当语法树节点的Type变量值为包含字符串“Buffer”时,则可记录此节点的Name变量值为Buffer资源的名称,同时解析此节点的RegisterAllocationOptData变量,以获取该Buffer资源对应的寄存器地址。接着,将Buffer资源及其对应的寄存器地址保存到一个全局的寄存器资源字典中,记为GBufferDictionary。Continuing to take the HLSL code file as an example, when the Type variable value of the syntax tree node contains the string "Buffer", the Name variable value of this node can be recorded as the name of the Buffer resource, and the RegisterAllocationOptData variable of this node can be parsed to obtain The address of the register corresponding to the Buffer resource. Next, save the Buffer resource and its corresponding register address in a global register resource dictionary, which is recorded as GBufferDictionary.
可选地,若该节点的类型为采样器,则获取该节点的名称变量的值,作为采样器的名称;接着,解析该节点的寄存器分配变量,以获取该采样器的寄存器地址;接着,将该采样器的名称和寄存器地址对应保存在采样器资源字典中。Optionally, if the type of the node is a sampler, the value of the name variable of the node is obtained as the name of the sampler; then, the register allocation variable of the node is parsed to obtain the register address of the sampler; then, Save the sampler's name and register address correspondingly in the sampler resource dictionary.
继续以HLSL代码文件为例,当语法树高级节点的基本类型为“SamplerState”时,可记录此节点的Name变量值为采样器资源的名称,同时解析此节点的RegisterAllocationOptData变量,获取该采样器资源的寄存器地址。接着,将采样器资源及其寄存器地址记录到一个全局的采样器资源字典中,记为GSamplerDictionary。Continuing to take the HLSL code file as an example, when the basic type of the advanced node of the syntax tree is "SamplerState", the Name variable of this node can be recorded as the name of the sampler resource, and the RegisterAllocationOptData variable of this node can be parsed to obtain the sampler resource The address of the register. Then, record the sampler resource and its register address in a global sampler resource dictionary, and record it as GSamplerDictionary.
应当理解,执行上述实施方式时,可遍历抽象语法树,以获取第一代码文件中的所有的纹理资源、所有的缓冲器资源以及所有的采样器资源的信息。其中,第一代码中所有的纹理资源的信息可被保存在GtexutreDictionary中,所有的缓冲器资源可被保存在GbufferDictionary中,所有的采样器资源可被保存在GsamplerDictionary中,不再赘述。It should be understood that when the foregoing implementation manner is executed, the abstract syntax tree can be traversed to obtain information about all texture resources, all buffer resources, and all sampler resources in the first code file. Among them, the information of all texture resources in the first code can be stored in GtexutreDictionary, all buffer resources can be stored in GbufferDictionary, and all sampler resources can be stored in GsamplerDictionary, which will not be repeated here.
可选地,若该节点的类型关键字为函数定义或函数声明,则解析该节点的函数类型变量和名称变量,以获取该第一函数的返回类型和函数名,并将该第一函数的形参变量的类型和名称写入该第一函数的信息。Optionally, if the type keyword of the node is a function definition or a function declaration, the function type variable and name variable of the node are parsed to obtain the return type and function name of the first function, and the The type and name of the formal parameter variable are written into the information of the first function.
其中,函数类型变量,即该节点的Type变量,名称变量,即该节点的Name变量。Among them, the function type variable is the Type variable of the node, and the name variable is the Name variable of the node.
继续以HLSL代码文件为例,在这种实施方式中,可将所有函数信息记录到一个全局的字典中,记为GFunctionDictionary。当抽象语法树中,节点的基本类型为“FunctionDefinition”或“FunctionDeclaration”时,可记此节点为Fnode,记此节点对应的函数为函数F0。接着,从FNode的FunctionType变量中获取函数F0的返回类型,从Name变量中获取函数F0的函数名。Continuing to take the HLSL code file as an example, in this implementation manner, all function information can be recorded in a global dictionary, which is recorded as GFunctionDictionary. When the basic type of the node in the abstract syntax tree is "FunctionDefinition" or "FunctionDeclaration", this node can be recorded as Fnode, and the function corresponding to this node is recorded as function F0. Next, get the return type of function F0 from the FunctionType variable of FNode, and get the function name of function F0 from the Name variable.
进一步可选地,可解析该节点的函数参数变量的子节点的类型变量和名称变量,以获取该第一函数的形参变量的类型和名称。Further optionally, the type variable and the name variable of the child node of the function parameter variable of the node may be parsed to obtain the type and name of the formal parameter variable of the first function.
其中,函数参数变量,可以为节点对应的FunctionParamsOptData变量。函数参数变量的每个子结点表示一个形参变量,因此,可通过分析函数参数变量的每个子节点的类型变量和名称变量,获取第一函数的每个形参变量的类型和名称。Among them, the function parameter variable can be the FunctionParamsOptData variable corresponding to the node. Each sub-node of a function parameter variable represents a formal parameter variable. Therefore, the type and name of each formal parameter variable of the first function can be obtained by analyzing the type variable and name variable of each sub-node of the function parameter variable.
可选地,若该第一函数的形参变量中,包括具有out或者inout属性的形参变量,则在该第一函数的信息中,记录该具有out或者inout属性的形参变量。Optionally, if the formal parameter variable of the first function includes a formal parameter variable with an out or inout attribute, then the formal parameter variable with an out or inout attribute is recorded in the information of the first function.
承接上述HLSL的例子,可分析FNode的FunctionParamsOptData变量的子节点。FunctionParamsOptData变量的每个子结点表示一个形参变量,可根据每个子节点的Type和Name变量,获取每个形参变量的类型和名称。其中,若某个或者多个形参变量的类型有out或者inout修饰,则可在函数F0的信息中额外记录这些变量信息。Following the above HLSL example, the child nodes of the FunctionParamsOptData variable of FNode can be analyzed. Each child node of the FunctionParamsOptData variable represents a formal parameter variable, and the type and name of each formal parameter variable can be obtained according to the Type and Name variables of each child node. Among them, if the type of one or more formal parameter variables is modified with out or inout, these variable information can be additionally recorded in the information of the function F0.
进一步可选地,可获取该节点的代码块变量的任一子节点对应的子树;若该子树中的第一节点的类型为函数调用,则解析该第一节点的名称变量和实参变量,得到该第一节点对应的函数名以及传参信息;接着,在该函数字典中,查询与该第一节点对应的函数名和传参信息对应的目标函数,作为该第一函数的调用函数。其中,代码块变量,可以为节点对应的Block变量。针对代码块变量的任一子节点,可获取以该子节点的为根节点的子树,作为该子节点对应的子树。Further optionally, the subtree corresponding to any child node of the code block variable of the node can be obtained; if the type of the first node in the subtree is a function call, the name variable and the actual parameter of the first node are parsed Variable to get the function name and parameter passing information corresponding to the first node; then, in the function dictionary, query the function name corresponding to the first node and the target function corresponding to the parameter passing information as the calling function of the first function . Among them, the code block variable can be the Block variable corresponding to the node. For any child node of the code block variable, a subtree with the child node as the root node can be obtained as the subtree corresponding to the child node.
其中,实参变量,可以是第一节点的ArgumentList变量。其中,该第一节点,指的是子树中的任意一个类型为函数调用的节点。Among them, the actual parameter variable may be the ArgumentList variable of the first node. Among them, the first node refers to any node in the subtree whose type is a function call.
继续承接上述HLSL的例子,可分析FNode的Block变量,Block变量的每个子节点代表函数实现的每条语句。记Block的某个(任意一个)子节点为FNode_B_C,并从抽象语法树中,获取以FNode_B_C为根节点的子树,并对该子树进行分析。当子树中有某个节点基本类型为“FunctionCall”时,可根据节点的Name变量值获取一函数名,从节点的ArgumentList变量解析出形参信息。其中,ArgumentList的每个子节点表示一个函数传参。接着,根据解析得到的函数名和传参信息,去GFunctionDictionary查找。若查找到对应的函数,记此函数为F1,则将F1加入到函数F0函数的调用函数名单中。Continuing with the above HLSL example, we can analyze the Block variable of FNode. Each child node of the Block variable represents each statement implemented by the function. Let a (any) child node of Block be FNode_B_C, and obtain the subtree with FNode_B_C as the root node from the abstract syntax tree, and analyze the subtree. When the basic type of a node in the subtree is "FunctionCall", a function name can be obtained according to the value of the Name variable of the node, and the formal parameter information can be parsed from the ArgumentList variable of the node. Among them, each child node of ArgumentList represents a function to pass parameters. Then, according to the function name and parameter information obtained by the analysis, go to the GFunctionDictionary to find it. If the corresponding function is found, record this function as F1, then add F1 to the list of calling functions of function F0.
可选地,在上述实施例的基础上,基于该子树,还可进一步获取第一函数使用的 资源的信息。以下将进行示例性说明。Optionally, on the basis of the foregoing embodiment, based on the subtree, information about the resources used by the first function can be further obtained. An exemplary description will be given below.
实施方式D:可选地,若该子树中的第二节点使用了第一全局资源,则将该第一全局资源的信息写入该第一函数的信息中;该第一全局资源包括纹理资源、缓冲器资源以及采样器资源中的至少一种。Embodiment D: Optionally, if the second node in the subtree uses the first global resource, the information of the first global resource is written into the information of the first function; the first global resource includes texture At least one of resources, buffer resources, and sampler resources.
继续承接上述HLSL的例子,可继续对以FNode_B_C为根节点的子树进行分析,当发现子树中某个节点使用了某个全局资源时,将此全局资源的信息记录到函数F0的信息中。其中,若函数F0使用了多种全局资源,例如Buffer,Texture和采样器资源,则可分别对Buffer,Texture和采样器资源进行记录。Continuing to follow the above HLSL example, we can continue to analyze the subtree with FNode_B_C as the root node. When a certain node in the subtree is found to use a certain global resource, record the information of this global resource in the information of function F0 . Among them, if function F0 uses multiple global resources, such as Buffer, Texture and sampler resources, you can record Buffer, Texture and sampler resources respectively.
实施方式E:可选地,若该子树中的第三节点使用了第一全局传参变量,则将该第一全局传参变量的信息写入该第一函数的信息中。Embodiment E: Optionally, if the third node in the subtree uses the first global parameter passing variable, the information of the first global parameter passing variable is written into the information of the first function.
应当理解,在本文中,采用“第一”、“第二”、“第三”等词汇对需要描述的对象进行限定,仅用于方便描述和区分名称相同或者相似的对象,并不对上述对象的时间顺序、位置顺序或者等级构成任何限制,后续不再一一解释。It should be understood that in this article, the terms "first", "second", "third" and other terms are used to limit the objects that need to be described, which are only used to facilitate the description and distinguishing of objects with the same or similar names, and do not apply to the above-mentioned objects. The chronological order, positional order or level constitute any restriction, and will not be explained one by one in the following.
继续承接上述HLSL的例子,可继续对以FNode_B_C为根节点的子树进行分析,当发现子树中某个节点使用了全局传参变量时,则在函数F0的信息里记录此全局传参变量信息。Continuing with the above HLSL example, we can continue to analyze the subtree with FNode_B_C as the root node. When it is found that a node in the subtree uses a global parameter variable, record this global parameter variable in the information of function F0 information.
基于上述各实施例,可获取到节点对应的第一函数的着色信息,接着,可将第一函数的信息保存在函数字典中。Based on the foregoing embodiments, the coloring information of the first function corresponding to the node can be obtained, and then the information of the first function can be stored in the function dictionary.
其中,在记录第一函数的信息时,用于记录参数变量的变量信息中,定义了如表2所示的主要成员变量:Among them, when recording the information of the first function, in the variable information used to record the parameter variable, the main member variables shown in Table 2 are defined:
表2Table 2
在记录第一函数的信息时,函数信息中,定义了如表3所示的主要成员变量:When recording the information of the first function, the function information defines the main member variables as shown in Table 3:
表3table 3
在一些可选的实施例中,根据抽象语法树,获取第一代码文件中的所有函数,并将所有函数逇信息记录在函数字典之后,可进一步对函数字典中的函数进行筛选,以确定第一代码运行时实际使用的函数,进而降低后续的函数翻译操作的工作量。In some optional embodiments, according to the abstract syntax tree, all the functions in the first code file are obtained, and after all the function information is recorded in the function dictionary, the functions in the function dictionary can be further filtered to determine the first code file. A function actually used when the code is running, thereby reducing the workload of subsequent function translation operations.
可选地,从该函数字典中确定入口函数;从该入口函数开始,采用深度优先搜索的方式,搜索该入口函数调用的每个函数;将搜索到的该入口函数调用的函数,记录到目标函数集合中。Optionally, determine the entry function from the function dictionary; starting from the entry function, use a depth-first search method to search for each function called by the entry function; record the searched function called by the entry function to the target Function collection.
继续以HLSL代码文件为例,可遍历前述实施例生成的GFunctionDictionary,当发现某个函数的名称为“main”时,确定此函数即为入口函数,记为MainFunc。接着,从入口函数开始,使用深度优先搜索的方式,搜索其调用的每个函数。将搜索到的函数记录到一个全局的词典中,记为GusedFunction。GusedFunction词典中的函数,表示当前着色器中实际用到的函数集合。进而,可在后续的函数翻译过程中去除没有调用的函数,降低翻译的计算量,精简翻译结果。Continuing to take the HLSL code file as an example, the GFunctionDictionary generated in the foregoing embodiment can be traversed, and when the name of a certain function is found to be "main", it is determined that this function is the entry function, which is recorded as MainFunc. Then, starting from the entry function, use the depth-first search method to search for each function it calls. Record the searched function into a global dictionary and record it as GusedFunction. The function in the GusedFunction dictionary represents the set of functions actually used in the current shader. Furthermore, functions that are not called can be removed in the subsequent function translation process, which reduces the amount of translation calculations and streamlines the translation results.
可选地,若该节点的类型关键字为结构体定义,则解析该节点的名称变量和类成员声明变量的子节点,以获取该节点对应的第一结构体的名称和该第一结构体包含的类成员的信息;将该第一结构体的名称和该第一结构体包含的类成员的信息保存在全局链表中。Optionally, if the type keyword of the node is a structure definition, the name variable of the node and the child nodes of the class member declaration variable are parsed to obtain the name of the first structure corresponding to the node and the first structure The information of the class members included; the name of the first structure and the information of the class members included in the first structure are stored in the global linked list.
可选地,为进一步获取第一结构体的类型,可遍历该函数字典,以从该函数字典 中确定入口函数;若该第一结构体与该入口函数的返回类型适配,则确定该第一结构体为输出类型的结构体;若该第一结构体与该入口函数的形参变量的类型适配,则确定该第一结构体为输入类型的结构体。Optionally, in order to further obtain the type of the first structure, the function dictionary may be traversed to determine the entry function from the function dictionary; if the first structure matches the return type of the entry function, the first structure is determined A structure is an output type structure; if the first structure matches the type of the formal parameter variable of the entry function, it is determined that the first structure is an input type structure.
继续以HLSL代码文件为例,当抽象语法树中的节点的基本类型为“Struct”时,可记录该节点的Name变量值为该节点对应的结构体的名称。其中,该节点的ClassMemberDeclarations变量的每个子节点表示一个结构体成员,因此,可解析ClassMemberDeclarations变量的每个子节点,以获取待结构体的所有结构体成员信息。接着,可将所有结构体成员信息保存在该结构体中。其中,获取到第一代码中的所有结构体的信息后,可将所有结构体的信息保存在一个全局链表中,记为GStructList。Continuing to take the HLSL code file as an example, when the basic type of the node in the abstract syntax tree is "Struct", the Name variable value of the node can be recorded as the name of the structure corresponding to the node. Among them, each child node of the ClassMemberDeclarations variable of the node represents a structure member. Therefore, each child node of the ClassMemberDeclarations variable can be parsed to obtain all structure member information of the structure to be structured. Then, you can save all structure member information in the structure. Among them, after obtaining the information of all the structures in the first code, the information of all the structures can be stored in a global linked list, which is recorded as GStructList.
接着,可遍历前述实施例生成的GFunctionDictionary,当发现某个函数的名称为“main”时,此函数即为入口函数,记为MainFunc。接着,在GStrcutList中寻找与MainFunc的返回类型对应的结构体,若找到,则记该找到的结构体为输出类型的结构体。同时,在GStrcutList中寻找与MainFunc的形参类型对应的结构体,若找到,则记录该找到的为输入类型的结构体。Then, the GFunctionDictionary generated in the foregoing embodiment can be traversed, and when the name of a certain function is found to be "main", this function is the entry function, which is recorded as MainFunc. Next, search for the structure corresponding to the return type of MainFunc in GStrcutList, and if found, record the found structure as the structure of the output type. At the same time, search for the structure corresponding to the type of the MainFunc formal parameter in GStrcutList, and if found, record the structure of the input type that is found.
基于上述各实施例提供的节点分析方法,可遍历第一代码文件的抽象语法树,得到每个节点的着色语言信息。接着,根据多个节点的着色语言信息,可得到第一代码文件的着色语言信息。根据前述实施例的记载,第一代码的着色语言信息可包括:资源字典包含的资源的信息、变量字典包含的全局传参变量的信息、全局链表包含的结构体的信息以及目标函数集合包含的函数的信息。Based on the node analysis method provided by the foregoing embodiments, the abstract syntax tree of the first code file can be traversed to obtain the coloring language information of each node. Then, according to the coloring language information of the multiple nodes, the coloring language information of the first code file can be obtained. According to the record in the foregoing embodiment, the coloring language information of the first code may include: resource information contained in the resource dictionary, global parameter information contained in the variable dictionary, structure information contained in the global linked list, and information contained in the objective function set. Function information.
接下来,可基于设定的信息映射规则,对第一代码文件的着色语言信息进行翻译,以得到第二代码文件。其中,第二代码文件与第二着色语言的语法适配。Next, based on the set information mapping rules, the coloring language information of the first code file can be translated to obtain the second code file. Among them, the second code file is adapted to the syntax of the second shading language.
其中,设定的信息映射规则,可包括:变量映射规则以及函数映射规则中的至少一种。其中,变量映射规则和函数映射规则,可根据第二着色语言的语法要求进行预先定义,本实施例不做限制。The set information mapping rules may include at least one of variable mapping rules and function mapping rules. Among them, the variable mapping rule and the function mapping rule can be pre-defined according to the grammatical requirements of the second coloring language, which is not limited in this embodiment.
值得说明的是,在本实施例中,信息映射规则可根据需求进行更新,例如,可灵活添加词与词、结构与结构之间的映射关系,可拓展性强,方便快速地支持新的着色语言语法。It is worth noting that in this embodiment, the information mapping rules can be updated according to requirements. For example, the mapping relationship between words and words, structure and structure can be flexibly added, and the scalability is strong, and the new coloring can be easily and quickly supported. Language grammar.
其中,第二着色语言,可以是Metal着色语言,或者GLSL着色语言。Among them, the second shading language may be Metal shading language or GLSL shading language.
其中,Metal是一个兼顾图形与计算功能的,面向底层、低开销的硬件加速应用程序接口,可应用在IOS 8.0版本之后的系统上。GLSL着色语言是OpenGL使用的着色语言,是一个以C语言为基础的高阶着色语言。Among them, Metal is a low-level, low-overhead hardware-accelerated application program interface that takes into account both graphics and computing functions. It can be applied to systems after IOS 8.0. GLSL shading language is the shading language used by OpenGL, and it is a high-level shading language based on C language.
相应的,第一平台,可以实现为搭载有Windows操作系统(一种微软公司开发的操作系统)的平台,第二平台可以实现为搭载有IOS(iPhone Operation System,苹果公司开发的操作系统)操作系统的平台或者搭载有Android(谷歌公司开发的操作系统)操作系统的平台。Correspondingly, the first platform can be implemented as a platform equipped with Windows operating system (an operating system developed by Microsoft Corporation), and the second platform can be implemented as a platform equipped with IOS (iPhone Operation System, an operating system developed by Apple). System platform or platform equipped with Android (operating system developed by Google) operating system.
以下将首先以第二着色语言实现为Metal着色语言为例进行示例性说明。The following will firstly take the implementation of the second shading language as the Metal shading language as an example to illustrate.
第一着色语言实现为HLSL、第二着色语言实现为Metal着色语言时,变量映射规则可如以下的HLSL到Metal的变量关键字映射表所示,函数映射规则可如以下的HLSL到Metal的函数映射表所示。When the first shading language is implemented as HLSL and the second shading language is implemented as the Metal shading language, the variable mapping rule can be as shown in the following HLSL to Metal variable keyword mapping table, and the function mapping rule can be as the following HLSL to Metal function The mapping table is shown.
其中,HLSL到Metal的变量关键字映射表如以下表4所示:Among them, the variable keyword mapping table from HLSL to Metal is shown in Table 4 below:
表4Table 4
HLSLHLSL | MetalMetal |
SamplerStateSamplerState | samplersampler |
Texture1DTexture1D | texture1d<float>texture1d<float> |
Texture2DTexture2D | Texture2d<float>Texture2d<float> |
Texture3DTexture3D | Texture3d<float>Texture3d<float> |
Texture1DArrayTexture1DArray | texture1d_array<float>texture1d_array<float> |
Texture2DArrayTexture2DArray | Texture2d_array<float>Texture2d_array<float> |
TextureCubeTextureCube | texturecube<float>texturecube<float> |
TextureCubeArrayTextureCubeArray | Texturecube_array<float>Texturecube_array<float> |
Texture2DMSTexture2DMS | texture2d_ms<float>texture2d_ms<float> |
SV_DispatchThreadIDSV_DispatchThreadID | [[thread_position_in_grid]][[thread_position_in_grid]] |
SV_GroupIDSV_GroupID | [[threadgroup_position_in_grid]][[threadgroup_position_in_grid]] |
SV_GroupIndexSV_GroupIndex | [[thread_index_in_threadgroup]][[thread_index_in_threadgroup]] |
SV_GroupThreadIDSV_GroupThreadID | [[thread_position_in_threadgroup]][[thread_position_in_threadgroup]] |
matrixmatrix | float4x4float4x4 |
doubledouble | floatfloat |
其中,HLSL到Metal的函数关键字映射关系如以下表5所示:Among them, the function keyword mapping relationship from HLSL to Metal is shown in Table 5 below:
表5table 5
HLSLHLSL | MetalMetal |
reversebitsreversebits | reverse_bitsreverse_bits |
ddyddy | dfdydfdy |
ddxddx | dfdxdfdx |
asuintasuint | as_type<uint>as_type<uint> |
asintasint | as_type<int>as_type<int> |
asfloatasfloat | as_type<float>as_type<float> |
fracfrac | fractfract |
SampleLevelSampleLevel | samplesample |
SampleSample | samplesample |
SampleGradSampleGrad | samplesample |
GatherAlphaGatherAlpha | gathergather |
LoadLoad | readread |
首先,可对前述实施例分析得到的变量字典进行翻译。可选地,可将该变量字典中的全局传参变量,映射为第一目标结构体的成员变量。也就是说,第一目标结构体第一代码文件中的所有全局传参变量,均作为该第一目标结构体的成员变量。First, the variable dictionary obtained from the analysis of the foregoing embodiment can be translated. Optionally, the global parameter variable in the variable dictionary can be mapped to the member variable of the first target structure. In other words, all global parameter variables in the first code file of the first target structure are used as member variables of the first target structure.
继续承接前述HLSL的例子,可采用一个结构体组织GVariableDictionary中的全局传参变量,每个全局传参变量都作为此结构体的成员变量。在本实施例中,该结构体可命名为Uniform。一个典型的翻译样例可如下表6所示:Continuing to continue the aforementioned HLSL example, a structure can be used to organize the global parameter variable in the GVariableDictionary, and each global parameter variable is used as a member variable of this structure. In this embodiment, the structure can be named Uniform. A typical translation example can be shown in Table 6 below:
表6Table 6
接下来,可对前述实施例分析得到的全局链表中的结构体进行翻译。以下将以全局链表中的第一结构体为例,对翻译第一代码文件中的结构体的实施方式进行示例性说明。Next, the structure in the global linked list obtained by the analysis of the foregoing embodiment can be translated. The following will exemplify the implementation of translating the structure in the first code file by taking the first structure in the global linked list as an example.
可选地,首先,可从前述实施例生成的该全局链表中,获取该第一结构体。接着,可根据变量映射规则,对该第一结构体中的变量进行翻译,以将该第一结构体映射为符合第二着色语言的语法的第二结构体。Optionally, first, the first structure can be obtained from the global linked list generated in the foregoing embodiment. Then, the variables in the first structure can be translated according to the variable mapping rules, so as to map the first structure into a second structure conforming to the grammar of the second shading language.
以HLSL翻译为Metal为例,对全局链表中的所有结构体信息进行翻译时,可根据表4所示变量关键字映射关系,将每个结构体中的变量的类型从HLSL语法映射到Metal语法。Taking the translation of HLSL to Metal as an example, when translating all the structure information in the global linked list, the type of the variable in each structure can be mapped from HLSL grammar to Metal grammar according to the variable keyword mapping relationship shown in Table 4 .
可选地,若所述第一结构体为顶点着色器的输入类型的结构体,则设置映射得到的所述第二结构体中的变量的属性编号与所述第一结构体中的变量的属性编号一致。Optionally, if the first structure is a structure of the input type of the vertex shader, set the attribute number of the variable in the second structure obtained by mapping and the value of the variable in the first structure. The attribute numbers are the same.
继续以HLSL翻译为Metal为例,可根据解析HLSL得到的输入、输出类型,生成Metal的输入类型,并用结构体组织数据。Continue to take the translation of HLSL to Metal as an example. According to the input and output types obtained by parsing HLSL, the input type of Metal can be generated, and the data can be organized by structure.
对于顶点着色Shader的输入类型,翻译后结构体内每个变量的attribute编号(属性编号)要与原HLSL中ATTRIBUTE编号(属性编号)保持一致。一种典型的翻译样例可如以下表7所示:For the input type of vertex shader, the attribute number (attribute number) of each variable in the translated structure should be consistent with the ATTRIBUTE number (attribute number) in the original HLSL. A typical translation example can be shown in Table 7 below:
表7Table 7
对于片元着色Shader的输入类型,与顶点着色Shader的输出类型处理方式相同。The input type of the fragment shader shader is handled in the same way as the output type of the vertex shader shader.
可选地,若所述第一结构体为顶点着色器的输出类型的结构体或者片元着色器Shader的输入类型的结构体,则将所述第一结构体中的属性为SV_POSITION的变量映射为所述第二结构体中的变量后,为映射得到的变量添加[[position]]标识。Optionally, if the first structure is the output type structure of the vertex shader or the input type structure of the fragment shader Shader, then the attribute in the first structure is mapped to the variable of SV_POSITION After the variables in the second structure, add the [[position]] tag to the mapped variables.
继续以HLSL翻译为Metal为例,对于顶点着色Shader的输出类型,将HLSL中属性为SV_POSITION的变量翻译成Metal对应的变量后,为翻译得到的变量添加[[position]]标识。除上述列举的变量之外,HLSL中的其他变量无需再翻译其属性信息。一种典型的翻译样例可如以下表8所示:Continue to take the translation of HLSL to Metal as an example. For the output type of the vertex shader, after translating the variable whose attribute is SV_POSITION in HLSL into the variable corresponding to Metal, add the [[position]] mark to the translated variable. In addition to the variables listed above, other variables in HLSL do not need to translate their attribute information. A typical translation example can be shown in Table 8 below:
表8Table 8
可选地,若所述第一结构体为片元着色器的输出类型的结构体,则将所述第一结构体中的属性为SV_Target的变量映射为所述第二结构体中的变量后,为映射得到的变量添加[[color]]标识,且同步所述属性为SV_Target的变量的编号。Optionally, if the first structure is a structure of the output type of the fragment shader, the variable whose attribute is SV_Target in the first structure is mapped to the variable in the second structure. , Add [[color]] to the mapped variable, and synchronize the number of the variable whose attribute is SV_Target.
继续以HLSL翻译为Metal为例,对于片元着色Shader的输出类型,将HLSL中属性为SV_Target的变量翻译成Metal对应的变量后,为翻译得到的变量添加color标识,且翻译前后的变量的编号保持一致。一种典型的翻译样例可如以下表9所示:Continue to take the translation of HLSL to Metal as an example. For the output type of the fragment color shader, after translating the variable whose attribute is SV_Target in HLSL into the variable corresponding to Metal, add the color identifier to the translated variable, and the number of the variable before and after the translation. be consistent. A typical translation example can be shown in Table 9 below:
表9Table 9
接下来,可对前述分析得到的目标函数集合中的函数进行翻译。以下将继续以目标函数集合中的第一函数为例,对第一代码文件中的函数的翻译操作进行示例性说明。Next, the functions in the set of objective functions obtained from the foregoing analysis can be translated. The following will continue to take the first function in the target function set as an example to illustrate the translation operation of the function in the first code file.
可选地,从该目标函数集合中获取该第一函数;根据该第一函数的信息以及函数映射规则,对该第一函数进行翻译,以将该第一函数映射为符合该第二着色语言的语法的第二函数。Optionally, the first function is obtained from the target function set; the first function is translated according to the information of the first function and the function mapping rule, so as to map the first function to conform to the second shading language The second function of the syntax.
其中,函数映射规则,可根据可第二着色语言的语法要求进行预先定义,本实施例不做限制。Among them, the function mapping rule can be pre-defined according to the grammatical requirements of the second coloring language, which is not limited in this embodiment.
可选地,根据该第一函数的信息以及函数映射规则,对该第一函数进行翻译时:若该第一函数不为入口函数,则在该第二函数的返回类型之前添加inline关键字。Optionally, when translating the first function according to the information of the first function and the function mapping rules: if the first function is not an entry function, the inline keyword is added before the return type of the second function.
可选地,若该第一函数的信息中记录有具有out或者inout属性的形参变量,则在该第二函数中生成第三结构体;根据该具有out或者inout属性的形参变量的传参顺序,在该第三结构体中依次定义至少一个形参变量;其中,该至少一个形参变量的类型与该具有out或者inout属性的形参变量的类型相同,且该至少一个形参变量的名称设有输出参数前缀。其中,第三结构体的名称,根据第一函数的函数名和形参的类型确定。Optionally, if a formal parameter variable with out or inout attribute is recorded in the information of the first function, a third structure is generated in the second function; according to the transmission of the formal parameter variable with out or inout attribute In the order of parameters, at least one formal parameter variable is defined in sequence in the third structure; wherein, the type of the at least one formal parameter variable is the same as the type of the formal parameter variable with the out or inout attribute, and the at least one formal parameter variable The name is prefixed with output parameters. Among them, the name of the third structure is determined according to the function name of the first function and the type of the formal parameter.
可选地,还可从该第一函数的信息中确定该第一函数的返回类型;若该第一函数的返回类型不为空,则在该第三结构体内定义返回参数变量;该返回参数变量与该第一函数的返回类型相同。Optionally, the return type of the first function can also be determined from the information of the first function; if the return type of the first function is not empty, a return parameter variable is defined in the third structure; the return parameter The variable has the same return type as the first function.
可选地,根据该第一函数的信息以及函数映射规则,对该第一函数进行翻译时,若根据该第一函数的信息确定该第一函数使用了该第一全局传参变量,则在生成该第二函数的形参信息时,将该第一目标结构体作为该第二函数的第一个形参。其中,第 一目标结构体为,对变量字典中的全局传参变量进行映射得到的,第一目标结构体中的成员变量可包括变量字典中的所有全局传参变量。Optionally, when translating the first function according to the information of the first function and the function mapping rules, if it is determined according to the information of the first function that the first function uses the first global parameter variable, then When generating the formal parameter information of the second function, use the first target structure as the first formal parameter of the second function. Among them, the first target structure is obtained by mapping the global parameter passing variables in the variable dictionary, and the member variables in the first target structure may include all global parameter passing variables in the variable dictionary.
若根据该第一函数的信息确定该第一函数使用了该第一全局资源,则在生成该第二函数的形参信息时,将该第一全局资源的信息放置在除该第一目标结构体之外的其他形参之前。If it is determined based on the information of the first function that the first function uses the first global resource, then when generating the formal parameter information of the second function, the information of the first global resource is placed in addition to the first target structure Before other formal parameters outside the body.
其中,该第一全局资源在该第二函数的形参中的顺序为:缓冲器资源、纹理资源、采样器资源;Wherein, the order of the first global resource in the formal parameter of the second function is: buffer resource, texture resource, sampler resource;
其中,该第一全局资源中的任一种全局资源内部的资源,依据资源对应的寄存器的大小进行排序。Wherein, the resources within any one of the first global resources are sorted according to the size of the register corresponding to the resource.
可选地,根据该第一函数的信息以及函数映射规则,对该第一函数进行翻译时:若该第一函数为入口函数,则在该入口函数的形参变量中,声明该第一目标结构体、该资源字典中的缓冲器资源、该资源字典中的纹理资源以及该资源字典中的采样器资源;Optionally, when translating the first function according to the information of the first function and the function mapping rules: if the first function is an entry function, declare the first target in the formal parameter variable of the entry function Structure, buffer resources in the resource dictionary, texture resources in the resource dictionary, and sampler resources in the resource dictionary;
其中,在该第一目标结构体和该缓冲器资源之后添加缓冲器标记,在该纹理资源之后添加纹理标记,在该采样器资源之后添加采样器标记。Wherein, a buffer mark is added after the first target structure and the buffer resource, a texture mark is added after the texture resource, and a sampler mark is added after the sampler resource.
可选地,在该第一函数的形参变量中,采用stage关键字标记输入类型的形参;Optionally, in the formal parameter variables of the first function, the stage keyword is used to mark the formal parameters of the input type;
可选地,若该第一函数与顶点着色器对应,则在该第一函数的返回类型前添加表示顶点(vertex)的关键字。Optionally, if the first function corresponds to a vertex shader, a keyword representing a vertex (vertex) is added before the return type of the first function.
可选地,若该第一函数与片元着色器对应,则在该第一函数的返回类型前添加表示片元(fragment)的关键字。Optionally, if the first function corresponds to a fragment shader, a keyword representing a fragment (fragment) is added before the return type of the first function.
继续以HLSL翻译为Metal为例,对上述记载的函数翻译过程进行进一步说明。在翻译函数时只翻译GUsedFunction中记录的函数。除Shader入口函数以外,Metal的所有函数要在函数返回类型前添加inline关键字。Metal函数定义方式与HLSL定义大致相同,在使用上与HLSL的不同之处主要有以下不同:Continue to take the translation of HLSL to Metal as an example to further explain the function translation process described above. When translating functions, only the functions recorded in GUsedFunction are translated. Except for the Shader entry function, all functions of Metal should add the inline keyword before the function return type. The Metal function definition method is roughly the same as the HLSL definition, and the main differences in use from HLSL are as follows:
一、Metal的函数形参不支持out、inout关键字。在翻译使用到out、inout属性形参的HLSL函数时,在生成Metal函数定义之前首先生成一个结构体,结构体的名称根据函数名和函数形参的类型来决定。接着,可依据使用out、inout属性形参的传参顺序,在该结构体内依次定义与形参类型相同的变量,名称的前缀为outParam。若函数的返回类型不为空,则还需在结构体内定义与返回类型相同类型的变量,名称为returnParam。在生成函数返回语句时,返回此结构体变量,变量中包含了要返回的out/inout形参值以及函数本身的返回值。一种典型的翻译样例可如以下表10所示:1. Metal function parameters do not support out and inout keywords. When translating HLSL functions that use out and inout attribute parameters, a structure is first generated before the Metal function definition is generated. The name of the structure is determined according to the function name and the type of the function parameter. Then, according to the parameter passing order of using the out and inout attribute parameters, the variables of the same type as the parameters can be defined in the structure in sequence, and the prefix of the name is outParam. If the return type of the function is not empty, you also need to define a variable of the same type as the return type in the structure, with the name returnParam. When generating a function return statement, return this structure variable, which contains the out/inout parameter value to be returned and the return value of the function itself. A typical translation example can be shown in Table 10 below:
表10Table 10
在其他函数调用此函数时,使用逗号表达式进行处理,在调用处返回结构体值,并将结构体中的变量依据形参顺序对函数形参依次赋值,若有returnParam参数,则以returnParam作为结尾。一种典型的翻译样例如以下表11所示:When other functions call this function, use the comma expression to process, return the structure value at the call site, and assign the function parameters to the function parameters according to the order of the variables in the structure. If there is a returnParam parameter, use returnParam as end. A typical translation example is shown in Table 11 below:
表11Table 11
二、Metal的函数不能像HLSL那样直接获取全局传参变量,而是需要将全局传参变量从其父函数传入。因此,在生成函数的形参信息时,若函数中使用了全局传参 变量,则将全局传参变量结构体加入并置于函数第一个形参的位置。在函数内部使用全局传参变量时,要通过全局传参变量结构体形参来进行访问。也就是说,在调用此函数时,需要将Uniform变量名加入并置于第一个传参的位置。一种典型的翻译样例可如以下表12所示:Second, Metal's function cannot directly obtain the global parameter variable like HLSL, but needs to pass the global parameter variable from its parent function. Therefore, when generating the formal parameter information of the function, if the global parameter-passing variable is used in the function, the global parameter-passing variable structure is added and placed in the position of the first formal parameter of the function. When using global parameter-passing variables within a function, it is necessary to access it through the global parameter-passing variable structure parameter. In other words, when calling this function, the Uniform variable name needs to be added and placed in the position of the first parameter. A typical translation example can be shown in Table 12 below:
表12Table 12
三、Metal的函数不能像HLSL那样直接获取资源变量,而是需要将资源变量从其父函数作为参数传入。因此,在生成函数的形参信息时,若函数中使用了资源信息,则将使用的所有资源信息加入形参,并放置在除全局传参变量结构体外的所有形参之前。若有多种资源,则加入顺序为:首先加入Buffer资源参数,随后加入Textue资源参数,最后加入Sampler资源参数,其中,每种参数的内部顺序依据寄存器值从小到大进行排列。所有资源都已在预处理时存到了函数的信息内,因此,资源类型名在翻译时可通过变量映射表进行映射。在调用此函数时,可根据函数的信息中记录使用的全局资源信息,在函数传参中的对应位置加入资源名称。一种典型的翻译样例可如以下表13所示:3. Metal functions cannot directly obtain resource variables like HLSL, but need to pass in resource variables from its parent function as a parameter. Therefore, when generating the formal parameter information of a function, if resource information is used in the function, all the resource information used is added to the formal parameters and placed before all the formal parameters except the global parameter variable structure. If there are multiple resources, the order of addition is: first add the Buffer resource parameter, then add the Textue resource parameter, and finally add the Sampler resource parameter. Among them, the internal order of each parameter is arranged according to the register value from small to large. All resources have been stored in the function information during preprocessing. Therefore, the resource type name can be mapped through the variable mapping table during translation. When calling this function, you can add the resource name in the corresponding position in the function parameter according to the global resource information recorded in the function information. A typical translation example can be shown in Table 13 below:
表13Table 13
接着,可将HLSL中的入口函数翻译成符合Metal语法的入口函数。Then, the entry function in HLSL can be translated into an entry function that conforms to Metal grammar.
Metal的入口函数需要在形参中列出所有的资源信息和全局传参变量结构体,其中,Texture、Buffer和Sampler资源可从GTextureDictionary、GBufferDictionary和GSamplerDictionary中获取,全局传参变量结构体为之前定义的Uniform结构体。The entry function of Metal needs to list all resource information and global parameter variable structure in the formal parameters. Among them, Texture, Buffer and Sampler resources can be obtained from GTextureDictionary, GBufferDictionary and GSamplerDictionary, and the global parameter variable structure is previously defined Uniform structure.
其中,Uniform结构体和Buffer资源在形参中声明时要在其后添加[[buffer(n)]],n为寄存器值。Texture资源在形参中声明时要在其后添加[[texture(n)]],n为寄存器值。Sampler资源在形参中声明时要在其后添加[[sampler(n)]],n为寄存器值。Among them, when the Uniform structure and Buffer resource are declared in the formal parameters, [[buffer(n)]] should be added after it, and n is the register value. When the Texture resource is declared in the formal parameter, [[texture(n)]] should be added after it, and n is the register value. When the Sampler resource is declared in the formal parameter, add [[sampler(n)]] after it, and n is the register value.
同时,Shader采用stage关键字标记Shader输入的形参。对于顶点着色Shader,在函数返回类型前添加添加vertex关键字;对于片元着色Shader,在返回类型前添加添加fragment关键字。At the same time, the Shader uses the stage keyword to mark the parameters input by the Shader. For the vertex shader, add the vertex keyword before the function return type; for the fragment shader, add the fragment keyword before the return type.
一个片元着色翻译的例子如以下表14所示:An example of fragment coloring translation is shown in Table 14 below:
表14Table 14
基于上述各实施例,可将解析HLSL对应的代码文件得到的节点的着色语言信息进行翻译,得到Metal着色语言对应的代码文件。即,如图2所示,将HLSL Shader文件翻译为MetalShader文件。进而,可在IOS平台上实现对着色器进行编程,以便于开发可供iPhone、iPad和iPod Touch等设备使用的3D图形程序。Based on the foregoing embodiments, the coloring language information of the node obtained by analyzing the code file corresponding to the HLSL can be translated to obtain the code file corresponding to the Metal coloring language. That is, as shown in Figure 2, the HLSL Shader file is translated into a MetalShader file. Furthermore, the shader can be programmed on the IOS platform to facilitate the development of 3D graphics programs that can be used by devices such as iPhone, iPad, and iPod Touch.
接下来,将以第二着色语言实现为GLSL着色语言为例进行示例性说明。Next, the implementation of the second shading language as the GLSL shading language will be used as an example to illustrate.
第一着色语言实现为HLSL、第二着色语言实现为GLSL着色语言时,变量映射规则可如以下的HLSL到GLSL的变量关键字映射表所示,函数映射规则可如以下的HLSL到GLSL的函数映射表所示。When the first shading language is implemented as HLSL and the second shading language is implemented as GLSL, the variable mapping rules can be as shown in the following HLSL to GLSL variable keyword mapping table, and the function mapping rules can be as the following HLSL to GLSL functions The mapping table is shown.
其中,HLSL到GLSL的变量关键字映射表如以下表15所示:Among them, the variable keyword mapping table from HLSL to GLSL is shown in Table 15 below:
表15Table 15
HLSLHLSL | GLSLGLSL |
Texture1DTexture1D | sampler1Dsampler1D |
Texture2DTexture2D | Sampler2DSampler2D |
Texture3DTexture3D | Sampler3DSampler3D |
Texture1DArrayTexture1DArray | sampler1DArraysampler1DArray |
Texture2DArrayTexture2DArray | sampler2DArraysampler2DArray |
TextureCubeTextureCube | samplerCubesamplerCube |
Texture2DMSTexture2DMS | sampler2DMSsampler2DMS |
RWTexture2DRWTexture2D | image2Dimage2D |
Buffer<float>Buffer<float> | samplerBuffersamplerBuffer |
Buffer<float2>Buffer<float2> | samplerBuffersamplerBuffer |
Buffer<float3>Buffer<float3> | samplerBuffersamplerBuffer |
Buffer<float4>Buffer<float4> | samplerBuffersamplerBuffer |
RWBuffer<float>RWBuffer<float> | imageBufferimageBuffer |
RWBuffer<float2>RWBuffer<float2> | imageBufferimageBuffer |
RWBuffer<float3>RWBuffer<float3> | imageBufferimageBuffer |
RWBuffer<float4>RWBuffer<float4> | imageBufferimageBuffer |
SV_DispatchThreadIDSV_DispatchThreadID | gl_GlobalInvocationIDgl_GlobalInvocationID |
SV_GroupIDSV_GroupID | gl_WorkGroupIDgl_WorkGroupID |
SV_GroupIndexSV_GroupIndex | gl_LocalInvocationIndexgl_LocalInvocationIndex |
SV_GroupThreadIDSV_GroupThreadID | gl_LocalInvocationIDgl_LocalInvocationID |
float4float4 | vec4vec4 |
float3float3 | vec3vec3 |
float2float2 | vec2vec2 |
float4x4float4x4 | mat4mat4 |
float3x3float3x3 | mat3mat3 |
float3x2float3x2 | mat3x2mat3x2 |
half4half4 | vec4vec4 |
Half3Half3 | vec3vec3 |
Half2Half2 | vec2vec2 |
halfhalf | floatfloat |
int4int4 | ivec4ivec4 |
int3int3 | ivec3ivec3 |
int2int2 | ivec2ivec2 |
uint4uint4 | uvec4uvec4 |
uint3uint3 | uvec3uvec3 |
uint2uint2 | uvec2uvec2 |
其中,HLSL到GLSL的函数关键字映射关系如以下表16所示:Among them, the function keyword mapping relationship from HLSL to GLSL is shown in Table 16 below:
表16Table 16
HLSLHLSL | GLSLGLSL |
lerplerp | mixmix |
fracfrac | fractfract |
ddxddx | dFdxdFdx |
ddx_coarseddx_coarse | dFDxCoarsedFDxCoarse |
ddx_fineddx_fine | dFDxFinedFDxFine |
ddyddy | dFdydFdy |
ddy_coarseddy_coarse | dFDyCoarsedFDyCoarse |
ddy_fineddy_fine | dFDyFinedFDyFine |
madmad | fmafma |
SampleLevelSampleLevel | textureLodtextureLod |
SampleSample | texturetexture |
SampleGradSampleGrad | textureGradtextureGrad |
GatherAlphaGatherAlpha | textureGathertextureGather |
LoadLoad | texelFetchtexelFetch |
首先,可对前述实施例分析得到的变量字典进行翻译。可选地,可将该变量字典中的全局传参变量,映射为第二目标结构体的成员变量。也就是说,第一代码文件中的所有全局传参变量,均作为该第二目标结构体的成员变量。First, the variable dictionary obtained from the analysis of the foregoing embodiment can be translated. Optionally, the global parameter variable in the variable dictionary can be mapped to the member variable of the second target structure. In other words, all global parameter variables in the first code file are used as member variables of the second target structure.
继续承接前述HLSL的例子,可采用一个结构体组织GVariableDictionary中的全局传参变量,每个全局传参变量都作为此结构体的成员变量。在本实施例中,该结构体采用uniform进行修饰,并可命名为cb。Continuing to continue the aforementioned HLSL example, a structure can be used to organize the global parameter variable in the GVariableDictionary, and each global parameter variable is used as a member variable of this structure. In this embodiment, the structure is modified by uniform and can be named cb.
可选地,在声明第二目标结构体的同时,可定义统一变量块(Uniform Buffer Object,UBO),并将该第二目标结构体存储在该统一变量块中;遍历该抽象语法树,若遍历到的当前节点的名称与该统一变量块中存储的任一全局传参变量的名称相同,则在该当前节点的名称之前添加该统一变量块的名称标识。Optionally, while declaring the second target structure, a uniform variable block (Uniform Buffer Object, UBO) can be defined, and the second target structure can be stored in the uniform variable block; the abstract syntax tree is traversed, if The name of the current node traversed is the same as the name of any global parameter variable stored in the uniform variable block, and the name identifier of the uniform variable block is added before the name of the current node.
其中,统一变量块,用于存储着色语言中uniform类型变量的缓冲区对象,使用UBO可以让uniform变量在不同的着色语言程序中实现共用,也可以在着色语言程序中实现uniform类型变量的设置与更新。Among them, the uniform variable block is used to store the buffer object of the uniform type variable in the shading language. Using UBO allows the uniform variable to be shared in different shading language programs, and the setting and setting of uniform type variables can also be realized in the shading language program. renew.
例如,以HLSL翻译为GLSL为例,在声明名称为cb的结构体的同时,可定义一个名为ubo的cb变量。接着,在GLSL的着色语言信息中,通过名称为ubo的变量访问全局传参变量。当在遍历抽象语法树时,若当前节点的名称为某个全局传参变量的名称,则在将该当前节点翻译成GLSL时,可在该节点名称前添加文本“ubo.”。For example, taking the translation of HLSL to GLSL as an example, while declaring a structure named cb, you can define a cb variable named ubo. Then, in the coloring language information of GLSL, the global parameter variable is accessed through the variable named ubo. When traversing the abstract syntax tree, if the name of the current node is the name of a global parameter variable, when the current node is translated into GLSL, the text "ubo." can be added before the node name.
一种典型的翻译样例可如下表17所示:A typical translation example can be shown in Table 17 below:
表17Table 17
接下来,可对变量字典中的全局传参变量结构体进行翻译。GLSL的全局传参变量结构体需要用layout设置set修饰符和binding修饰符。基于此,可选地,可从预先生成的该变量字典中获取该全局传参变量结构体;接着,采用layout设置该全局传参变量结构体的set修饰符和binding修饰符。其中,binding值与其在HLSL资源中对应的register(寄存器)值保持一致。其中,set修饰符的值可设为0,set修饰符用于后续的Vulkan(一种应用程序接口)翻译使用。Next, you can translate the global parameter variable structure in the variable dictionary. GLSL's global parameter-passing variable structure needs to use layout to set the set modifier and binding modifier. Based on this, optionally, the global parameter-passing variable structure can be obtained from the pre-generated variable dictionary; then, layout is used to set the set modifier and binding modifier of the global parameter-passing variable structure. Among them, the binding value is consistent with its corresponding register (register) value in the HLSL resource. Among them, the value of the set modifier can be set to 0, and the set modifier is used for subsequent Vulkan (an application program interface) translation.
接下来,可对资源字典中的资源进行翻译。Next, you can translate the resources in the resource dictionary.
可选地,可从该资源字典中获取任意一种待翻译的资源;接着,采用layout设置该待翻译的资源的binding修饰符,并在该待翻译的资源的变量类型前添加uniform关键字;其中,该binding修饰符的值根据该待翻译的资源的寄存器的值确定。其中,除上述修饰符之外,对该待翻译的资源的变量类型进行翻译时,可结合变量关键字映射表,对该资源的类型变量进行映射,得到该资源翻译后的类型变量,不再一一赘述。Optionally, any resource to be translated can be obtained from the resource dictionary; then, use layout to set the binding modifier of the resource to be translated, and add the uniform keyword before the variable type of the resource to be translated; Wherein, the value of the binding modifier is determined according to the value of the register of the resource to be translated. Among them, in addition to the above modifiers, when translating the variable type of the resource to be translated, the type variable of the resource can be mapped in combination with the variable keyword mapping table to obtain the translated type variable of the resource. Go into details one by one.
以HLSL翻译为GLSL为例,可从GTextureDictionary中获取Texture资源的信息。针对每个Texture资源,在将其翻译成GLSL中的对应资源时,可用layout设置binding修饰符,binding值为HLSL中对应资源的register值。翻译后的资源的变量类型根据变量关键字映射表来确定,并在翻译得到的变量类型前添加uniform关键字。Taking the translation of HLSL to GLSL as an example, the information of Texture resources can be obtained from GTextureDictionary. For each Texture resource, when translating it into the corresponding resource in GLSL, the layout can be used to set the binding modifier, and the binding value is the register value of the corresponding resource in HLSL. The variable type of the translated resource is determined according to the variable keyword mapping table, and the uniform keyword is added before the translated variable type.
其中,可从GBufferDictionary中获取Buffer资源的信息。针对每个Buffer资源,在将其翻译成GLSL中对应的资源时,可采用layout设置binding修饰符,binding值可根据HLSL中对应资源的register值得到。翻译后的资源的变量类型根据变量关键字映射表来确定,并在翻译得到的变量类型前添加uniform关键字。其中,Sampler资源无需进行翻译。Among them, the Buffer resource information can be obtained from GBufferDictionary. For each Buffer resource, when translating it into the corresponding resource in GLSL, layout can be used to set the binding modifier, and the binding value can be obtained according to the register value of the corresponding resource in HLSL. The variable type of the translated resource is determined according to the variable keyword mapping table, and the uniform keyword is added before the translated variable type. Among them, Sampler resources do not need to be translated.
一种典型的资源翻译结果,可如以下表18所示:A typical resource translation result can be shown in Table 18 below:
表18Table 18
接下来,可对前述实施例分析得到的全局链表中得到结构体进行翻译。Next, the structure obtained in the global linked list obtained by the analysis of the foregoing embodiment can be translated.
以全局链表中的第一结构体为例,可根据变量映射规则,对第一结构体中的变量进行翻译,以将第一结构体映射为符合第二着色语言的语法的第二结构体。其中,可将第一结构体对应的输入类型以及输出类型,分别翻译为第二结构体的输入变量以及输出变量。也就是说,将HLSL中的结构体翻译成GLSL中的结构体时,由于GLSL的结构体定义与HLSL的结构体定义一致,因此,可从全局链表GStrcutList中获取所有结构体的信息,根据变量关键字映射表,将结构体中变量的类型从HLSL语法映射到GLSL定义即可实现结构体的翻译操作。在翻译的过程中,可根据解析HLSL得到的输入、输出类型生成GLSL的输入、输出变量。Taking the first structure in the global linked list as an example, the variables in the first structure can be translated according to the variable mapping rules to map the first structure into a second structure conforming to the grammar of the second shading language. Among them, the input type and output type corresponding to the first structure can be respectively translated into the input variable and output variable of the second structure. That is to say, when translating the structure in HLSL into the structure in GLSL, because the structure definition of GLSL is consistent with the structure definition of HLSL, the information of all the structures can be obtained from the global linked list GStrcutList, according to the variable Keyword mapping table, mapping the types of variables in the structure from the HLSL syntax to the GLSL definition can realize the translation operation of the structure. In the translation process, the input and output variables of GLSL can be generated according to the input and output types obtained by parsing HLSL.
其中,GLSL每个输出、输出变量都需要在Shader中进行全局定义。因此,在翻译HLSL的结构体到GLSL时,若发现当前结构体类型是Shader的输入、输出类型,则不再在GLSL中定义此结构体,而是将此结构体的名称宏定义为float类型,方便后续的翻译。此外,可将结构体中的一部分非特殊的成员变量定义为GLSL的Shader的全局传参变量,其中,变量类型的翻译通过变量关键字映射表处理。Among them, each output and output variable of GLSL needs to be globally defined in Shader. Therefore, when translating the structure of HLSL to GLSL, if it is found that the current structure type is the input and output type of Shader, the structure is no longer defined in GLSL, but the name of the structure is defined as a float type. , To facilitate subsequent translation. In addition, a part of the non-special member variables in the structure can be defined as the global parameter variable of GLSL Shader, and the translation of the variable type is processed through the variable keyword mapping table.
结构体的另一部分特殊的成员变量,可根据如下方式进行处理:The special member variables of another part of the structure can be processed as follows:
若该第一结构体为顶点着色器的输入类型的结构体,则对该第二结构体中的输入变量采用layout关键字定义location修饰符,并在声明该第二结构体中的输入变量时,在该第二结构体中输入变量的类型前添加in关键字;其中,该location修饰符的值与 该第一结构体中的变量的属性编号一致。也就是说,对于顶点着色Shader的输入类型,翻译后的每个输入变量可用layout关键字定义location修饰符,location值与HLSL中对应变量的ATTRIBUTE编号保持一致。同时,对每个GLSL的输入变量进行声明时,需要在输入变量的类型前添加in关键字,表示此变量是输入变量。在Shader的入口函数中翻译输入类型时,可从入口函数的形参中找到Shader输入类型,并记录下此类型对应的变量名,记为input。在翻译Shader的入口函数时,将所有“input.变量名”的结构替换成对应的GLSL全局传参变量名。If the first structure is a structure of the input type of the vertex shader, the layout keyword is used to define the location modifier for the input variable in the second structure, and when the input variable in the second structure is declared , Add the in keyword before entering the variable type in the second structure; wherein, the value of the location modifier is consistent with the attribute number of the variable in the first structure. That is to say, for the input type of the vertex shader, each input variable after translation can be defined with the layout keyword to define the location modifier, and the location value is consistent with the ATTRIBUTE number of the corresponding variable in HLSL. At the same time, when declaring each GLSL input variable, you need to add the in keyword before the type of the input variable to indicate that this variable is an input variable. When translating the input type in the entry function of the Shader, you can find the input type of the Shader from the formal parameters of the entry function, and record the variable name corresponding to this type, denoted as input. When translating the entry function of Shader, replace all the structure of "input.variable name" with the corresponding GLSL global parameter variable name.
其中,若该第一结构体为顶点着色器的输出类型的结构体,则在翻译该第一结构体时,采用保留关键字gl_Positon代替属性为SV_POSITION的变量;以及,在声明该第二结构体中的输入变量时,在该第二结构体中的输入变量的类型之前添加out关键字。也就是说,对于顶点着色Shader的输出类型,可将带有SV_POSITION属性的HLSL输出变量在GLSL中用保留关键字gl_Positon代替,并在GLSL在Shader入口函数中,直接对gl_Positon进行赋值,无需额外声明。Among them, if the first structure is a structure of the output type of the vertex shader, when translating the first structure, the reserved keyword gl_Positon is used to replace the variable whose attribute is SV_POSITION; and, when the second structure is declared When inputting variables in the second structure, add the out keyword before the type of the input variable in the second structure. In other words, for the output type of the vertex shader, the HLSL output variable with the SV_POSITION attribute can be replaced by the reserved keyword gl_Positon in GLSL, and in the Shader entry function of GLSL, gl_Positon can be directly assigned without additional declaration. .
对于HLSL中的其他输出变量,在GLSL的Shader中采用layout关键字定义location属性值。同时,在声明每个GLSL的输出变量时,可在输出变量的类型前添加out关键字,表示此变量是输出变量。在Shader的入口函数中翻译输出类型时,可从入口函数的语句中找到Shader输出类型定义的变量,记录下此变量名为output。在翻译Shader的入口函数时,处理“output.变量名”的结构。若变量名在输出类型的结构体中对应的变量有SV_Position属性,则用gl_Position替换“output.变量名”,否则用GLSL对应的全局输出变量名替换“output.变量名”。由于用宏定义处理的HLSL的Shader输出类型,所以不用再翻译入口函数中的Shader输出类型定义,这样,可在不影响Shader的功能的情况下,简化翻译流程。For other output variables in HLSL, the layout keyword is used to define the location attribute value in the Shader of GLSL. At the same time, when declaring each GLSL output variable, you can add the out keyword before the type of the output variable to indicate that this variable is an output variable. When translating the output type in the entry function of the Shader, you can find the variable defined by the output type of the Shader from the statement of the entry function, and record the variable name as output. When translating Shader's entry function, the structure of "output. variable name" is processed. If the variable name in the structure of the output type has the SV_Position attribute, replace "output.variable name" with gl_Position, otherwise replace "output.variable name" with the global output variable name corresponding to GLSL. Since the Shader output type of HLSL is processed by the macro definition, there is no need to translate the Shader output type definition in the entry function. In this way, the translation process can be simplified without affecting the function of the Shader.
对顶点着色Shader的输入、输出类型的翻译样例可如以下表格19所示:A translation example of the input and output types of the vertex shader can be shown in Table 19 below:
表19Table 19
其中,若该第一结构体为片元着色器的输入类型的结构体,则对该第一结构体中具有SV_POSITION属性的变量进行翻译时,在layout中设置origin_upper_left修饰符,并在该具有SV_POSITION属性的变量的变量类型之前添加in关键字,并设置变量名为gl_FragCoord。也就是说,对于片元着色Shader的输入类型,对HLSL中的带有SV_POSITION属性变量进行翻译时,可在layout中设置origin_upper_left修饰符,同时在该变量类型前添加in关键字,并将该变量名设为gl_FragCoord。Among them, if the first structure is the input type structure of the fragment shader, when translating the variable with the SV_POSITION attribute in the first structure, the origin_upper_left modifier is set in the layout and the SV_POSITION Add the in keyword before the variable type of the attribute variable, and set the variable name to gl_FragCoord. That is to say, for the input type of the fragment coloring shader, when translating the variable with the SV_POSITION attribute in HLSL, you can set the origin_upper_left modifier in the layout, and add the in keyword before the variable type, and add the variable The name is set to gl_FragCoord.
对于HLSL输入类型的其他成员变量,翻译方式与顶点着色Shader的输出类型相似,区别点在于:在翻译得到的变量前添加in关键字,而不是添加out关键字。For other member variables of the HLSL input type, the translation method is similar to the output type of the vertex shader. The difference is that the in keyword is added before the translated variable instead of the out keyword.
在Shader入口函数中翻译输入类型时,可从入口函数的形参中找到Shader输入类型,并记录下此类型对应的变量名,记为input。在翻译Shader入口函数时,处理“input.变量名”的结构。若变量名在输入类型的结构体中对应的变量有SV_POSITION属性,则采用gl_FragCoord替换“output.变量名”,否则采用GLSL对应的全局输入变量名替换“input.变量名”。When translating the input type in the Shader entry function, the Shader input type can be found from the formal parameters of the entry function, and the variable name corresponding to this type can be recorded as input. When translating the Shader entry function, the structure of "input. variable name" is processed. If the variable name corresponding to the variable in the input type structure has the SV_POSITION attribute, use gl_FragCoord to replace "output.variable name", otherwise use the global input variable name corresponding to GLSL to replace "input.variable name".
其中,若该第一结构体为片元着色器的输出类型的结构体,则对翻译得到的该第二结构体中的输出变量采用layout关键字设置location修饰符,其中该location修饰符的值与该第一结构体中对应的变量的SV_Target属性编号一致,且在该第二结构体中的输出变量的类型之前添加out关键字。也就是说,对于片元着色Shader的输出类型,翻译成GLSL的输出变量时,可采用layout设置location修饰符,location值与HLSL中对应的变量的SV_Target属性编号保持一致,同时要在变量类型前添加out关键字。Wherein, if the first structure is a structure of the output type of the fragment shader, the layout keyword is used to set the location modifier for the output variable in the second structure obtained by translation, and the value of the location modifier is It is consistent with the SV_Target attribute number of the corresponding variable in the first structure, and the out keyword is added before the type of the output variable in the second structure. That is to say, for the output type of the fragment coloring shader, when translating into the output variable of GLSL, you can use layout to set the location modifier. The location value is consistent with the SV_Target attribute number of the corresponding variable in HLSL, and it must be before the variable type. Add the out keyword.
在Shader入口函数中翻译输出类型时,从入口函数的语句中找到Shader输出类 型定义的变量,记录下此变量名为output。在翻译Shader入口函数时,将HLSL中所有的“output.变量名”的结构替换成对应的GLSL全局传参变量名。When translating the output type in the Shader entry function, find the variable defined by the Shader output type from the entry function statement, and record the variable name as output. When translating the Shader entry function, replace all the structures of "output. variable name" in HLSL with the corresponding GLSL global parameter variable name.
对片元着色Shader的输入、输出类型的翻译样例可如以下表20所示:A translation example of the input and output types of the Shader for the fragment coloring can be shown in Table 20 below:
表20Table 20
接下来,可对目标函数集合中的函数进行翻译。Next, the functions in the objective function set can be translated.
除入口函数外,GLSL的函数定义方式与HLSL的函数的定义方式大致相同,在使用上的区别主要体现在读取资源方面。GLSL的Texture和Buffer的资源读取函数与HLSL在结构上不同。继续以目标函数集合中的第一函数为例,若第一函数为资源读取函数,则将第一函数翻译成符合第二着色语言的语法规则的第二函数时,在翻译得到的第二函数中,将被读取的资源的类型、被读取的资源的位置以及其他参数写在第二函数的函数体中。以下将进行示例性说明。Except for the entry function, the function definition method of GLSL is roughly the same as that of HLSL function, and the difference in usage is mainly reflected in the aspect of reading resources. GLSL's Texture and Buffer's resource reading functions are different in structure from HLSL. Continue to take the first function in the objective function set as an example. If the first function is a resource reading function, when the first function is translated into a second function that conforms to the grammatical rules of the second shading language, the second function obtained by the translation is In the function, write the type of the resource to be read, the location of the resource to be read, and other parameters in the body of the second function. An exemplary description will be given below.
对于纹理资源,HLSL使用的读取函数结构如下:For texture resources, the read function structure used by HLSL is as follows:
“纹理资源.读取函数(采样器,读取位置,其他参数)”"Texture resource. Read function (sampler, read position, other parameters)"
而GLSL使用的读取函数结构如下:The structure of the read function used by GLSL is as follows:
“读取函数(纹理资源,读取位置,其他参数)”"Read function (texture resource, read location, other parameters)"
对于Buffer资源,HLSL使用的读取函数结构如下:For Buffer resources, the structure of the read function used by HLSL is as follows:
“Buffer资源.读取函数(读取位置,其他参数)”"Buffer resource. Read function (read position, other parameters)"
GLSL使用的读取函数结构如下:The structure of the read function used by GLSL is as follows:
“读取函数(Buffer资源,读取位置,其他参数)”"Read function (Buffer resource, read position, other parameters)"
前述实施例获取到的资源字典中,包含Shader中所有的资源信息,包括资源变量类型和变量名。在翻译Shader中的函数调用语句时,若HLSL中函数调用者的名称为某个全局资源名,且调用函数为HLSL的内置的资源读取函数时,即可判断当前语句为资源读取语句。在将其翻译为GLSL时,不再向GLSL的Shader中打印此函数在资源读取函数之前的资源变量文本,并将资源变量设为读取函数的第一个参数。对于纹理资源,在翻译时可省略HLSL中资源读取函数的采样器参数。读取函数名称可根据函数关键字映射表进行翻译。The resource dictionary acquired in the foregoing embodiment contains all resource information in the Shader, including resource variable types and variable names. When translating the function call statement in Shader, if the name of the function caller in HLSL is a global resource name, and the calling function is the built-in resource reading function of HLSL, it can be judged that the current statement is a resource reading statement. When translating it into GLSL, the text of the resource variable of this function before the resource reading function is no longer printed to the GLSL Shader, and the resource variable is set as the first parameter of the reading function. For texture resources, the sampler parameter of the resource reading function in HLSL can be omitted during translation. The read function name can be translated according to the function key mapping table.
一种典型的对资源读取的翻译样例可如下表21所示:A typical translation example for resource reading can be shown in Table 21 below:
表21Table 21
在翻译Shader入口函数时,GLSL的入口函数返回值为void,且没有形参列表。一个片元着色翻译的例子如下表22所示:When translating the Shader entry function, the return value of the GLSL entry function is void, and there is no formal parameter list. An example of fragment coloring translation is shown in Table 22 below:
表22Table 22
基于上述实施例,可将HLSL Shader文件翻译为GLSL Shader文件。其中,GLSL Shader文件跟HLSL Shader文件在单词上具有一一对应的效果,可读性高,方便后续在目标平台的优化和调错。Based on the above embodiment, the HLSL Shader file can be translated into the GLSL Shader file. Among them, the GLSL Shader file and the HLSL Shader file have a one-to-one correspondence effect on words, and are highly readable, which is convenient for subsequent optimization and error adjustment on the target platform.
接下来,可使用Khronos提供的glslang工具,将第翻译得到的GLSL Shader文件翻译成SPIR-V文件,如图2所示。其中,SPIR-V,是一种现代二进制低级中间表示语言,用于Vulkan、OpenCL、OpenGL等许多API(Application Programming Interface,应用程序编程接口)。其中,Vulkan,是一个低开销、跨平台的二维、三维图形与计算的应用程序接口,与OpenGL类似,Vulkan针对全平台即时3D图形程序而设计。Next, you can use the glslang tool provided by Khronos to translate the translated GLSL Shader file into a SPIR-V file, as shown in Figure 2. Among them, SPIR-V is a modern binary low-level intermediate representation language used in many APIs (Application Programming Interface) such as Vulkan, OpenCL, and OpenGL. Among them, Vulkan is a low-overhead, cross-platform application program interface for two-dimensional and three-dimensional graphics and computing. Similar to OpenGL, Vulkan is designed for real-time 3D graphics programs on all platforms.
需要说明的是,上述实施例所提供方法的各步骤的执行主体均可以是同一设备,或者,该方法也由不同设备作为执行主体。比如,步骤201至步骤204的执行主体可以为设备A;又比如,步骤201和202的执行主体可以为设备A,步骤203的执行主体可以为设备B;等等。It should be noted that the execution subject of each step of the method provided in the foregoing embodiment may be the same device, or the method may also be executed by different devices. For example, the execution subject of steps 201 to 204 may be device A; for another example, the execution subject of steps 201 and 202 may be device A, and the execution subject of step 203 may be device B; and so on.
另外,在上述实施例及附图中的描述的一些流程中,包含了按照特定顺序出现的多个操作,但是应该清楚了解,这些操作可以不按照其在本文中出现的顺序来执行或并行执行,操作的序号如201、202等,仅仅是用于区分开各个不同的操作,序号本身不代表任何的执行顺序。另外,这些流程可以包括更多或更少的操作,并且这些操作可以按顺序执行或并行执行。需要说明的是,本文中的“第一”、“第二”等描述,是用于区分不同的消息、设备、模块等,不代表先后顺序,也不限定“第一”和“第二”是不同的类型。In addition, in some of the processes described in the above-mentioned embodiments and drawings, multiple operations appearing in a specific order are included, but it should be clearly understood that these operations may be performed out of the order in which they appear in this document or performed in parallel. The sequence numbers of operations, such as 201, 202, etc., are only used to distinguish different operations, and the sequence numbers themselves do not represent any execution order. In addition, these processes may include more or fewer operations, and these operations may be executed sequentially or in parallel. It should be noted that the descriptions of "first" and "second" in this article are used to distinguish different messages, devices, modules, etc., and do not represent a sequence, nor do they limit the "first" and "second" Are different types.
图3是本申请一示例性实施例提供的电子设备的结构示意图,如图3所示,该电子设备包括:存储器301以及处理器302。FIG. 3 is a schematic structural diagram of an electronic device provided by an exemplary embodiment of the present application. As shown in FIG. 3, the electronic device includes a memory 301 and a processor 302.
存储器301,用于存储计算机程序,并可被配置为存储其它各种数据以支持在电子设备上的操作。这些数据的示例包括用于在电子设备上操作的任何应用程序或方法的指令,联系人数据,电话簿数据,消息,图片,视频等。The memory 301 is used to store computer programs and can be configured to store other various data to support operations on the electronic device. Examples of such data include instructions for any application or method operated on an electronic device, contact data, phone book data, messages, pictures, videos, etc.
其中,存储器301可以由任何类型的易失性或非易失性存储设备或者它们的组合实现,如静态随机存取存储器(SRAM),电可擦除可编程只读存储器(EEPROM),可擦除可编程只读存储器(EPROM),可编程只读存储器(PROM),只读存储器(ROM),磁存储器,快闪存储器,磁盘或光盘。Among them, the memory 301 can be implemented by any type of volatile or non-volatile storage device or their combination, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable Except programmable read only memory (EPROM), programmable read only memory (PROM), read only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
处理器302,与存储器301耦合,用于执行存储器301中的计算机程序,以用于:对第一着色语言对应的第一代码文件进行语法分析,得到所述第一代码文件的抽象语法树;对所述抽象语法树中的多个节点的关键字进行分析,以获取所述第一代码文件的着色语言信息;根据设定的信息映射规则,对所述第一代码文件的着色语言信息进行翻译,得到第二着色语言对应的第二代码文件;其中,所述信息映射规则根据所述第一着色语言和所述第二着色语言的语法规则确定。The processor 302 is coupled with the memory 301, and is configured to execute a computer program in the memory 301, so as to perform a syntax analysis on a first code file corresponding to the first shading language to obtain an abstract syntax tree of the first code file; Analyze the keywords of multiple nodes in the abstract syntax tree to obtain the coloring language information of the first code file; perform the coloring language information of the first code file according to the set information mapping rules Translate to obtain a second code file corresponding to the second shading language; wherein the information mapping rule is determined according to the grammatical rules of the first shading language and the second shading language.
进一步可选地,所述映射规则,包括以下至少一种:所述第一着色语言和所述第二着色语言之间的变量映射规则;所述第一着色语言和所述第二着色语言之间的函数映射规则。Further optionally, the mapping rule includes at least one of the following: a variable mapping rule between the first shading language and the second shading language; one of the first shading language and the second shading language Function mapping rules between.
进一步可选地,处理器302还用于:从所述第一代码文件中,确定待处理的变量,所述待处理的变量的名称包含与翻译工具中的保留关键字相同的字符串;对所述待处 理的变量的名称进行修改,以避免在所述第二代码文件中使用保留关键字作为变量名。Further optionally, the processor 302 is further configured to: determine a variable to be processed from the first code file, and the name of the variable to be processed contains the same character string as the reserved keyword in the translation tool; The name of the variable to be processed is modified to avoid using reserved keywords as variable names in the second code file.
进一步可选地,所述待处理的变量,包括:名称为Buffer的全局传参变量、名称包含字符串Texture的变量以及名称包含字符串Buffer的变量中的至少一种。Further optionally, the variable to be processed includes at least one of a global parameter variable named Buffer, a variable whose name includes the character string Texture, and a variable whose name includes the character string Buffer.
进一步可选地,所述第一代码文件的着色语言信息,包括:所述第一代码文件中的全局传参变量的信息、所述第一代码文件中的资源的信息、所述第一代码文件中的结构体的信息以及所述第一代码文件中的函数的信息中的至少一种。Further optionally, the coloring language information of the first code file includes: information about global parameters in the first code file, information about resources in the first code file, and the first code At least one of structure information in the file and function information in the first code file.
进一步可选地,处理器302在对所述抽象语法树中的多个节点的关键字进行分析,以获取所述第一代码文件的着色语言信息时,具体用于:针对所述多个节点中的任一节点,根据所述节点的类型关键字,确定所述节点对应的关键变量;对所述节点对应的关键变量进行解析,得到所述节点对应的着色语言信息;根据所述多个节点各自对应的着色语言信息,获取所述第一代码文件的着色语言信息。Further optionally, when the processor 302 analyzes keywords of multiple nodes in the abstract syntax tree to obtain the coloring language information of the first code file, it is specifically configured to: target the multiple nodes For any node in the node, determine the key variable corresponding to the node according to the type keyword of the node; analyze the key variable corresponding to the node to obtain the coloring language information corresponding to the node; according to the multiple The coloring language information corresponding to the respective nodes is used to obtain the coloring language information of the first code file.
进一步可选地,处理器302在对所述节点对应的关键变量进行分析,得到所述节点对应的着色语言信息时,具体用于:若所述节点的类型关键字为全局传参变量结构体,则对所述节点的子节点的类型变量和名称变量进行解析,得到所述全局传参变量结构体包含的全局传参变量的类型和名称;将所述全局传参变量结构体包含的全局传参变量的类型和名称保存在变量字典中。Further optionally, when the processor 302 analyzes the key variable corresponding to the node to obtain the coloring language information corresponding to the node, it is specifically used for: if the type keyword of the node is a global parameter variable structure , The type variables and name variables of the child nodes of the node are analyzed to obtain the type and name of the global parameter-passing variable contained in the global parameter-passing variable structure; the global parameter-passing variable structure contained in the global The type and name of the passed parameter variable are stored in the variable dictionary.
进一步可选地,处理器302在对所述节点对应的关键变量进行分析,得到所述节点对应的着色语言信息时,具体用于:若所述节点的类型关键字包含表示资源的字符串,则解析所述节点的名称变量和寄存器分配变量,以获取所述资源的名称和寄存器地址;将所述资源的名称和寄存器地址,对应保存在资源字典中。Further optionally, when the processor 302 analyzes the key variable corresponding to the node to obtain the coloring language information corresponding to the node, it is specifically configured to: if the type keyword of the node contains a character string representing a resource, Then, the name variable and the register allocation variable of the node are parsed to obtain the name and register address of the resource; the name and register address of the resource are correspondingly saved in the resource dictionary.
进一步可选地,所述资源包括:纹理资源、缓冲器资源以及寄存器资源中的至少一中。Further optionally, the resources include: at least one of texture resources, buffer resources, and register resources.
进一步可选地,处理器302在对所述节点对应的关键变量进行分析,得到所述节点对应的着色语言信息时,具体用于:若所述节点的类型关键字为函数定义或函数声明,则解析所述节点的函数类型变量和名称变量,以获取所述节点对应的第一函数的返回类型和函数名;将所述第一函数的返回类型和函数名作为所述第一函数的信息,并将所述第一函数的信息保存在函数字典中。Further optionally, when the processor 302 analyzes the key variable corresponding to the node to obtain the coloring language information corresponding to the node, it is specifically used for: if the type keyword of the node is a function definition or a function declaration, Parse the function type variable and name variable of the node to obtain the return type and function name of the first function corresponding to the node; use the return type and function name of the first function as the information of the first function , And save the information of the first function in the function dictionary.
进一步可选地,处理器302还用于:解析所述节点的函数参数变量的子节点的类型变量和名称变量,以获取所述第一函数的形参变量的类型和名称,并将所述第一函数的形参变量的类型和名称写入所述第一函数的信息;若所述第一函数的形参变量中,包括具有out或者inout属性的形参变量,则在所述第一函数的信息中,记录所述具有out或者inout属性的形参变量。Further optionally, the processor 302 is further configured to: parse the type variable and the name variable of the child node of the function parameter variable of the node to obtain the type and name of the formal parameter variable of the first function, and compare the The type and name of the formal parameter variable of the first function are written into the information of the first function; if the formal parameter variable of the first function includes a formal parameter variable with out or inout attribute, then the In the function information, the formal parameter variable with the out or inout attribute is recorded.
进一步可选地,处理器302还用于:获取所述节点的代码块变量的任一子节点对 应的子树;若所述子树中的第一节点的类型为函数调用,则解析所述第一节点的名称变量和实参变量,得到所述第一节点对应的函数名以及传参信息;在所述函数字典中,查询与所述第一节点对应的函数名和传参信息对应的目标函数,作为所述第一函数的调用函数,并将所述调用函数写入所述第一函数的信息中。Further optionally, the processor 302 is further configured to: obtain a subtree corresponding to any child node of the code block variable of the node; if the type of the first node in the subtree is a function call, parse the The name variable and actual parameter variable of the first node are used to obtain the function name and parameter passing information corresponding to the first node; in the function dictionary, the function name corresponding to the first node and the target corresponding to the parameter passing information are queried Function as a calling function of the first function, and writing the calling function into the information of the first function.
进一步可选地,处理器302还用于:若所述子树中的第二节点使用了第一全局资源,则将所述第一全局资源的信息写入所述第一函数的信息中;所述第一全局资源包括纹理资源、缓冲器资源以及采样器资源中的至少一种;若所述子树中的第三节点使用了第一全局传参变量,则将所述第一全局传参变量的信息写入所述第一函数的信息中。Further optionally, the processor 302 is further configured to: if the second node in the subtree uses the first global resource, write the information of the first global resource into the information of the first function; The first global resource includes at least one of a texture resource, a buffer resource, and a sampler resource; if the third node in the subtree uses the first global parameter variable, the first global parameter is transmitted The information of the parameter is written into the information of the first function.
进一步可选地,处理器302还用于:从所述函数字典中确定入口函数;从所述入口函数开始,采用深度优先搜索的方式,搜索所述入口函数调用的每个函数;将搜索到的所述入口函数调用的函数,记录到目标函数集合中。Further optionally, the processor 302 is further configured to: determine an entry function from the function dictionary; starting from the entry function, use a depth-first search method to search for each function called by the entry function; The function called by the entry function is recorded in the target function set.
进一步可选地,处理器302在对所述多个节点各自的关键变量进行解析,以获取所述第一代码文件的着色语言信息时,具体用于:若所述节点的类型关键字为结构体定义,则解析所述节点的名称变量和类成员声明变量的子节点,以获取所述节点对应的第一结构体的名称和所述第一结构体包含的类成员的信息;将所述第一结构体的名称和所述第一结构体包含的类成员的信息保存在全局链表中。Further optionally, when the processor 302 parses the respective key variables of the multiple nodes to obtain the coloring language information of the first code file, it is specifically configured to: if the type keyword of the node is a structure Body definition, the name variable of the node and the child node of the class member declaration variable are parsed to obtain the name of the first structure corresponding to the node and the information of the class member contained in the first structure; The name of the first structure and the information of the class members contained in the first structure are stored in the global linked list.
进一步可选地,处理器302还用于:遍历所述函数字典,以从所述函数字典中确定入口函数;若所述第一结构体与所述入口函数的返回类型适配,则确定所述第一结构体为输出类型的结构体;若所述第一结构体与所述入口函数的形参变量的类型适配,则确定所述第一结构体为输入类型的结构体。Further optionally, the processor 302 is further configured to: traverse the function dictionary to determine an entry function from the function dictionary; if the first structure body matches the return type of the entry function, determine all The first structure is an output type structure; if the first structure matches the type of the formal parameter variable of the entry function, it is determined that the first structure is an input type structure.
进一步可选地,处理器302在根据设定的信息映射规则,对所述第一代码文件的着色语言信息进行翻译时,具体用于:从所述全局链表中获取所述第一结构体;根据变量映射规则,对所述第一结构体中的变量进行翻译,以将所述第一结构体映射为符合第二着色语言的语法的第二结构体。Further optionally, when the processor 302 translates the coloring language information of the first code file according to the set information mapping rule, it is specifically configured to: obtain the first structure from the global linked list; According to the variable mapping rules, the variables in the first structure are translated to map the first structure into a second structure conforming to the grammar of the second shading language.
进一步可选地,处理器302在根据变量映射规则,对所述第一结构体中的变量进行翻译时,具体用于:若所述第一结构体为顶点着色器的输入类型的结构体,则设置映射得到的所述第二结构体中的变量的属性编号与所述第一结构体中的变量的属性编号一致;若所述第一结构体为顶点着色器的输出类型的结构体或者为片元着色器的输入类型的结构体,则将所述第一结构体中的属性为SV_POSITION的变量映射为所述第二结构体中的变量后,为映射得到的变量添加[[position]]标识;若所述第一结构体为片元着色器的输出类型的结构体,则将所述第一结构体中的属性为SV_Target的变量映射为所述第二结构体中的变量后,为映射得到的变量添加[[color]]标识,且同步所 述属性为SV_Target的变量的编号。Further optionally, when the processor 302 translates the variables in the first structure according to the variable mapping rules, it is specifically configured to: if the first structure is the structure of the input type of the vertex shader, Set the attribute number of the variable in the second structure obtained by mapping to be consistent with the attribute number of the variable in the first structure; if the first structure is the structure of the output type of the vertex shader or Is the input type structure of the fragment shader, after mapping the variable with the attribute SV_POSITION in the first structure to the variable in the second structure, add [[position] to the mapped variable ] Identification; if the first structure is a structure of the output type of the fragment shader, after mapping the variable whose attribute is SV_Target in the first structure to the variable in the second structure, Add [[color]] to the mapped variable, and synchronize the number of the variable whose attribute is SV_Target.
进一步可选地,处理器302在根据设定的信息映射规则,对所述第一代码文件的着色语言信息进行翻译时,具体用于:将所述变量字典中的全局传参变量,映射为第一目标结构体的成员变量。Further optionally, when the processor 302 translates the coloring language information of the first code file according to the set information mapping rule, it is specifically configured to: map the global parameter variable in the variable dictionary to The member variable of the first target structure.
进一步可选地,处理器302在根据设定的信息映射规则,对所述第一代码文件的着色语言信息进行翻译时,具体用于:从所述目标函数集合中获取所述第一函数;根据所述变量映射规则和/或所述函数映射规则,对所述第一函数进行翻译,以将所述第一函数映射为符合所述第二着色语言的语法的第二函数。Further optionally, the processor 302 is specifically configured to: obtain the first function from the target function set when translating the shading language information of the first code file according to the set information mapping rule; According to the variable mapping rule and/or the function mapping rule, the first function is translated to map the first function to a second function conforming to the grammar of the second shading language.
进一步可选地,处理器302在根据所述第一函数的信息以及函数映射规则,对所述第一函数进行翻译时,具体用于:若所述第一函数不为入口函数,则在所述第二函数的返回类型之前添加inline关键字。Further optionally, when the processor 302 interprets the first function according to the information of the first function and the function mapping rules, it is specifically configured to: if the first function is not an entry function, then Add the inline keyword before the return type of the second function.
进一步可选地,处理器302在根据所述第一函数的信息以及函数映射规则,对所述第一函数进行翻译时,具体用于:若所述第一函数的信息中记录有具有out或者inout属性的形参变量,则在所述第二函数中生成第三结构体;根据所述具有out或者inout属性的形参变量的传参顺序,在所述第三结构体中依次定义至少一个形参变量;其中,所述至少一个形参变量的类型与所述具有out或者inout属性的形参变量的类型相同,且所述至少一个形参变量的名称设有输出参数前缀。Further optionally, when the processor 302 interprets the first function according to the information of the first function and the function mapping rules, it is specifically configured to: if the information of the first function records that there is out or The formal parameter variable of the inout attribute generates a third structure in the second function; according to the parameter transfer order of the formal parameter variable with the out or inout attribute, at least one is defined in the third structure in turn A formal parameter variable; wherein the type of the at least one formal parameter variable is the same as the type of the formal parameter variable with the out or inout attribute, and the name of the at least one formal parameter variable is provided with an output parameter prefix.
进一步可选地,处理器302还用于:从所述第一函数的信息中确定所述第一函数的返回类型;若所述第一函数的返回类型不为空,则在所述第三结构体内定义返回参数变量;所述返回参数变量与所述第一函数的返回类型相同。Further optionally, the processor 302 is further configured to: determine the return type of the first function from the information of the first function; if the return type of the first function is not empty, perform the A return parameter variable is defined in the structure; the return parameter variable is the same as the return type of the first function.
进一步可选地,处理器302在根据所述第一函数的信息以及函数映射规则,对所述第一函数进行翻译时,具体用于:若根据所述第一函数的信息确定所述第一函数使用了所述第一全局传参变量,则在生成所述第二函数的形参信息时,将所述第一目标结构体作为所述第二函数的第一个形参;若根据所述第一函数的信息确定所述第一函数使用了所述第一全局资源,则在生成所述第二函数的形参信息时,将所述第一全局资源的信息放置在除所述第一目标结构体之外的其他形参之前。Further optionally, when the processor 302 translates the first function according to the information of the first function and the function mapping rule, it is specifically configured to: if the first function is determined according to the information of the first function, The function uses the first global parameter variable, when generating the formal parameter information of the second function, the first target structure is used as the first formal parameter of the second function; If the information of the first function determines that the first function uses the first global resource, when the formal parameter information of the second function is generated, the information of the first global resource is placed in addition to the first global resource. Before a formal parameter other than the target structure.
进一步可选地,所述第一全局资源在所述第二函数的形参中的顺序为:缓冲器资源、纹理资源、采样器资源;其中,所述第一全局资源中的任一种全局资源内部的资源,依据资源对应的寄存器的大小进行排序。Further optionally, the order of the first global resource in the formal parameters of the second function is: buffer resource, texture resource, sampler resource; wherein, any one of the first global resources is global The resources inside the resource are sorted according to the size of the register corresponding to the resource.
进一步可选地,处理器302在根据所述第一函数的信息以及函数映射规则,对所述第一函数进行翻译时,具体用于:若所述第一函数为入口函数,则在所述入口函数的形参变量中,声明所述第一目标结构体、所述资源字典中的缓冲器资源、所述资源字典中的纹理资源以及所述资源字典中的采样器资源;其中,在所述第一目标结构体 和所述缓冲器资源之后添加缓冲器标记,在所述纹理资源之后添加纹理标记,在所述采样器资源之后添加采样器标记。Further optionally, when the processor 302 interprets the first function according to the information of the first function and the function mapping rules, it is specifically configured to: if the first function is an entry function, perform the In the formal parameter variable of the entry function, declare the first target structure, the buffer resource in the resource dictionary, the texture resource in the resource dictionary, and the sampler resource in the resource dictionary; Add a buffer mark after the first target structure and the buffer resource, add a texture mark after the texture resource, and add a sampler mark after the sampler resource.
进一步可选地,处理器302还用于执行以下至少一种操作:在所述第一函数的形参变量中,采用stage关键字标记输入类型的形参;若所述第一函数与顶点着色器对应,则在所述第一函数的返回类型前添加表示顶点的关键字;若所述第一函数与片元着色器对应,则在所述第一函数的返回类型前添加表示片元的关键字。Further optionally, the processor 302 is further configured to perform at least one of the following operations: in the formal parameter variable of the first function, the stage keyword is used to mark the formal parameter of the input type; if the first function and vertex coloring If the first function corresponds to the fragment shader, add the keyword representing the fragment before the return type of the first function. Keywords.
进一步可选地,所述第一代码文件为HLSL着色语言的代码文件;所述第二代码文件为Metal着色语言对应的代码文件。Further optionally, the first code file is a code file of the HLSL shading language; the second code file is a code file corresponding to the Metal shading language.
进一步可选地,处理器302在根据设定的信息映射规则,对所述第一代码文件的着色语言信息进行翻译时,具体用于:将所述变量字典中的全局传参变量,映射为第二目标结构体的成员变量;定义统一变量块,并将所述第二目标结构体存储在所述统一变量块中;遍历所述抽象语法树,若遍历到的当前节点的名称与所述统一变量块中存储的任一全局传参变量的名称相同,则在所述当前节点的名称之前添加所述统一变量块的名称标识。Further optionally, when the processor 302 translates the coloring language information of the first code file according to the set information mapping rule, it is specifically configured to: map the global parameter variable in the variable dictionary to Member variables of the second target structure; define a uniform variable block, and store the second target structure in the uniform variable block; traverse the abstract syntax tree, if the name of the current node traversed is consistent with the If the name of any global parameter variable stored in the uniform variable block is the same, the name identifier of the uniform variable block is added before the name of the current node.
进一步可选地,处理器302还用于:从所述变量字典中获取所述全局传参变量结构体;采用layout设置所述全局传参变量结构体的set修饰符和binding修饰符。Further optionally, the processor 302 is further configured to: obtain the global parameter passing variable structure from the variable dictionary; use layout to set the set modifier and binding modifier of the global parameter passing variable structure.
进一步可选地,处理器302在根据设定的信息映射规则,对所述第一代码文件的着色语言信息进行翻译时,具体用于:从所述资源字典中获取任意一种待翻译的资源;采用layout设置所述待翻译的资源的binding修饰符,并在所述待翻译的资源的变量类型前添加uniform关键字;其中,所述binding修饰符的值根据所述待翻译的资源的寄存器的值确定。Further optionally, when the processor 302 translates the coloring language information of the first code file according to the set information mapping rule, it is specifically configured to: obtain any resource to be translated from the resource dictionary ; Use layout to set the binding modifier of the resource to be translated, and add a uniform keyword before the variable type of the resource to be translated; wherein the value of the binding modifier is based on the register of the resource to be translated The value is OK.
进一步可选地,处理器302在对所述第一代码文件的着色语言信息进行翻译时,具体用于:从所述全局链表中获取所述第一结构体;根据变量映射规则,对所述第一结构体中的变量进行翻译,以将所述第一结构体映射为符合第二着色语言的语法的第二结构体;将所述第一结构体对应的输入类型以及输出类型,分别翻译为所述第二结构体的输入变量以及输出变量;若所述第一结构体为顶点着色器的输入类型的结构体,则对所述第二结构体中的输入变量采用layout关键字定义location修饰符,并在声明所述第二结构体中的输入变量时,在所述第二结构体中输入变量的类型前添加in关键字;其中,所述location修饰符的值与所述第一结构体中的变量的属性编号一致;若所述第一结构体为顶点着色器的输出类型的结构体,则在翻译所述第一结构体时,采用保留关键字gl_Positon代替属性为SV_POSITION的变量;以及,在声明所述第二结构体中的输入变量时,在所述第二结构体中的输入变量的类型之前添加out关键字;若所述第一结构体为片元着色器的输入类型的结构体,则对所述第一结构体中具有 SV_POSITION属性的变量进行翻译时,在layout中设置origin_upper_left修饰符,并在所述具有SV_POSITION属性的变量的变量类型之前添加in关键字,并设置变量名为gl_FragCoord;若所述第一结构体为片元着色器的输出类型的结构体,则对翻译得到的所述第二结构体中的输出变量采用layout关键字设置location修饰符,其中所述location修饰符的值与所述第一结构体中对应的变量的SV_Target属性编号一致,且在所述第二结构体中的输出变量的类型之前添加out关键字。Further optionally, when the processor 302 translates the coloring language information of the first code file, it is specifically configured to: obtain the first structure from the global linked list; Translate the variables in the first structure to map the first structure to a second structure conforming to the grammar of the second shading language; translate the input type and output type corresponding to the first structure respectively Are the input variables and output variables of the second structure; if the first structure is the input type structure of the vertex shader, the layout keyword is used to define location for the input variables in the second structure Modifier, and when declaring the input variable in the second structure, add the in keyword before the type of the input variable in the second structure; wherein, the value of the location modifier is the same as that of the first The attribute numbers of the variables in the structure are the same; if the first structure is the output type structure of the vertex shader, when translating the first structure, the reserved keyword gl_Positon is used instead of the variable whose attribute is SV_POSITION ; And, when declaring the input variable in the second structure, add the out keyword before the type of the input variable in the second structure; if the first structure is the input of the fragment shader Type structure, when translating the variable with the SV_POSITION attribute in the first structure, set the origin_upper_left modifier in the layout, and add the in keyword before the variable type of the variable with the SV_POSITION attribute, and Set the variable name to gl_FragCoord; if the first structure is a structure of the output type of the fragment shader, use the layout keyword to set the location modifier for the output variable in the second structure obtained by translation, where The value of the location modifier is consistent with the SV_Target attribute number of the corresponding variable in the first structure, and the out keyword is added before the type of the output variable in the second structure.
进一步可选地,处理器302在根据所述第一函数的信息以及函数映射规则,对所述第一函数进行翻译时,可执行以下至少一种操作:从所述目标函数集合中获取所述第一函数;根据所述变量映射规则和/或所述函数映射规则,对所述第一函数的信息进行翻译,以将所述第一函数映射为符合所述第二着色语言的语法的第二函数;若所述第一函数为资源读取函数,则在翻译得到的所述第二函数中,将被读取的资源的类型、被读取的资源的位置以及其他参数写在所述第二函数的函数体中;若所述第一函数为入口函数,则将所述第一函数映射得到的所述第二函数的返回值设为void。Further optionally, the processor 302 may perform at least one of the following operations when translating the first function according to the information of the first function and the function mapping rule: acquiring the target function set The first function; according to the variable mapping rule and/or the function mapping rule, the information of the first function is translated, so as to map the first function to the first function conforming to the grammar of the second shading language Second function; if the first function is a resource reading function, in the second function obtained by translation, the type of the resource to be read, the location of the resource to be read, and other parameters are written in the In the function body of the second function; if the first function is an entry function, the return value of the second function obtained by mapping the first function is set to void.
进一步可选地,处理器302还用于:所述第一代码文件为HLSL着色语言的代码文件;所述第二代码文件为GLSL着色语言对应的代码文件。Further optionally, the processor 302 is further configured to: the first code file is a code file of the HLSL shading language; the second code file is a code file corresponding to the GLSL shading language.
进一步,如图3所示,该电子设备还包括:通信组件303、显示器304、电源组件305、音频组件306等其它组件。图3中仅示意性给出部分组件,并不意味着电子设备只包括图3所示组件。Furthermore, as shown in FIG. 3, the electronic device further includes: a communication component 303, a display 304, a power supply component 305, an audio component 306 and other components. Only part of the components are schematically shown in FIG. 3, which does not mean that the electronic device only includes the components shown in FIG. 3.
其中,通信组件303被配置为便于通信组件所在设备和其他设备之间有线或无线方式的通信。通信组件所在设备可以接入基于通信标准的无线网络,如WiFi,2G、3G、4G或5G,或它们的组合。在一个示例性实施例中,通信组件经由广播信道接收来自外部广播管理系统的广播信号或广播相关信息。在一个示例性实施例中,通信组件可基于近场通信(NFC)技术、射频识别(RFID)技术、红外数据协会(IrDA)技术、超宽带(UWB)技术、蓝牙(BT)技术和其他技术来实现。The communication component 303 is configured to facilitate wired or wireless communication between the device where the communication component is located and other devices. The device where the communication component is located can access a wireless network based on a communication standard, such as WiFi, 2G, 3G, 4G, or 5G, or a combination of them. In an exemplary embodiment, the communication component receives a broadcast signal or broadcast related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component may be based on near field communication (NFC) technology, radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology, and other technologies to realise.
其中,显示组件304包括屏幕,其屏幕可以包括液晶显示器(LCD)和触摸面板(TP)。如果屏幕包括触摸面板,屏幕可以被实现为触摸屏,以接收来自用户的输入信号。触摸面板包括一个或多个触摸传感器以感测触摸、滑动和触摸面板上的手势。所述触摸传感器可以不仅感测触摸或滑动动作的边界,而且还检测与所述触摸或滑动操作相关的持续时间和压力。Among them, the display component 304 includes a screen, and the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touch, sliding, and gestures on the touch panel. The touch sensor may not only sense the boundary of a touch or slide action, but also detect the duration and pressure related to the touch or slide operation.
其中,电源组件305,为电源组件所在设备的各种组件提供电力。电源组件可以包括电源管理系统,一个或多个电源,及其他与为电源组件所在设备生成、管理和分配电力相关联的组件。Among them, the power supply component 305 provides power for various components of the equipment where the power supply component is located. The power supply component may include a power management system, one or more power supplies, and other components associated with the generation, management, and distribution of power for the equipment where the power supply component is located.
本实施例,基于抽象语法树进行节点分析,保留了原着色语言的代码文件原有的 语法结构。与此同时,基于节点的关键字进行分析,实现了不同类型的信息之间的对应翻译,有利于提升翻译结果的可读性;除此之外,信息映射规则可根据实际需求进行更新,提升了语言翻译方法的可拓展性,方便快速地支持新的着色语言语法。In this embodiment, node analysis is performed based on the abstract syntax tree, and the original syntax structure of the code file of the original coloring language is retained. At the same time, node-based keyword analysis realizes the corresponding translation between different types of information, which is conducive to improving the readability of the translation results; in addition, the information mapping rules can be updated according to actual needs to improve The scalability of the language translation method is improved, and the new coloring language grammar can be supported quickly and conveniently.
相应地,本申请实施例还提供一种存储有计算机程序的计算机可读存储介质,计算机程序被执行时能够实现上述方法实施例中可由电子设备执行的各步骤。Correspondingly, the embodiments of the present application also provide a computer-readable storage medium storing a computer program, and when the computer program is executed, the steps that can be executed by the electronic device in the foregoing method embodiments can be implemented.
本发明的各个部件实施例可以以硬件实现,或者以在一个或者多个处理器上运行的软件模块实现,或者以它们的组合实现。本领域的技术人员应当理解,可以在实践中使用微处理器或者数字信号处理器(DSP)来实现本发明实施例的电子设备中的一些或者全部部件的一些或者全部功能。本发明还可以实现为用于执行这里所描述的方法的一部分或者全部的设备或者装置程序(例如,计算机程序和计算机程序产品)。这样的实现本发明的程序可以存储在计算机可读介质上,或者可以具有一个或者多个信号的形式。这样的信号可以从因特网网站上下载得到,或者在载体信号上提供,或者以任何其他形式提供。The various component embodiments of the present invention may be implemented by hardware, or by software modules running on one or more processors, or by a combination of them. Those skilled in the art should understand that a microprocessor or a digital signal processor (DSP) may be used in practice to implement some or all of the functions of some or all of the components in the electronic device of the embodiment of the present invention. The present invention can also be implemented as a device or device program (for example, a computer program and a computer program product) for executing part or all of the methods described herein. Such a program for realizing the present invention may be stored on a computer-readable medium, or may have the form of one or more signals. Such a signal can be downloaded from an Internet website, or provided on a carrier signal, or provided in any other form.
例如,图4示出了可以实现本发明的着色语言翻译方法的服务器,例如应用服务器。该服务器传统上包括处理器410和以存储器420形式的计算机程序产品或者计算机可读介质。存储器420可以是诸如闪存、EEPROM(电可擦除可编程只读存储器)、EPROM、硬盘或者ROM之类的电子存储器。存储器420具有用于执行上述方法中的任何方法步骤的程序代码431的存储空间430。例如,用于程序代码的存储空间430可以包括分别用于实现上面的方法中的各种步骤的各个程序代码431。这些程序代码可以从一个或者多个计算机程序产品中读出或者写入到这一个或者多个计算机程序产品中。这些计算机程序产品包括诸如硬盘,紧致盘(CD)、存储卡或者软盘之类的程序代码载体。这样的计算机程序产品通常为如参考图5所述的便携式或者固定存储单元。该存储单元可以具有与图4的服务器中的存储器420类似布置的存储段、存储空间等。程序代码可以例如以适当形式进行压缩。通常,存储单元包括计算机可读代码431’,即可以由例如诸如410之类的处理器读取的代码,这些代码当由服务器运行时,导致该服务器执行上面所描述的方法中的各个步骤。For example, FIG. 4 shows a server, such as an application server, that can implement the shading language translation method of the present invention. The server traditionally includes a processor 410 and a computer program product in the form of a memory 420 or a computer-readable medium. The memory 420 may be an electronic memory such as flash memory, EEPROM (Electrically Erasable Programmable Read Only Memory), EPROM, hard disk, or ROM. The memory 420 has a storage space 430 for executing the program code 431 of any method step in the foregoing method. For example, the storage space 430 for program codes may include various program codes 431 respectively used to implement various steps in the above method. These program codes can be read from or written into one or more computer program products. These computer program products include program code carriers such as hard disks, compact disks (CDs), memory cards, or floppy disks. Such a computer program product is usually a portable or fixed storage unit as described with reference to FIG. 5. The storage unit may have storage segments, storage space, etc., arranged similarly to the storage 420 in the server of FIG. 4. The program code can be compressed in a suitable form, for example. Generally, the storage unit includes computer-readable codes 431', that is, codes that can be read by, for example, a processor such as 410, which, when run by a server, causes the server to perform the steps in the method described above.
本文中所称的“一个实施例”、“实施例”或者“一个或者多个实施例”意味着,结合实施例描述的特定特征、结构或者特性包括在本发明的至少一个实施例中。此外,请注意,这里“在一个实施例中”的词语例子不一定全指同一个实施例。The “one embodiment”, “an embodiment” or “one or more embodiments” referred to herein means that a specific feature, structure or characteristic described in conjunction with the embodiment is included in at least one embodiment of the present invention. In addition, please note that the word examples "in one embodiment" here do not necessarily all refer to the same embodiment.
在此处所提供的说明书中,说明了大量具体细节。然而,能够理解,本发明的实施例可以在没有这些具体细节的情况下被实践。在一些实例中,并未详细示出 公知的方法、结构和技术,以便不模糊对本说明书的理解。In the instructions provided here, a lot of specific details are explained. However, it can be understood that the embodiments of the present invention can be practiced without these specific details. In some instances, well-known methods, structures, and technologies are not shown in detail, so as not to obscure the understanding of this specification.
应该注意的是上述实施例对本发明进行说明而不是对本发明进行限制,并且本领域技术人员在不脱离所附权利要求的范围的情况下可设计出替换实施例。在权利要求中,不应将位于括号之间的任何参考符号构造成对权利要求的限制。单词“包含”不排除存在未列在权利要求中的元件或步骤。位于元件之前的单词“一”或“一个”不排除存在多个这样的元件。本发明可以借助于包括有若干不同元件的硬件以及借助于适当编程的计算机来实现。在列举了若干装置的单元权利要求中,这些装置中的若干个可以是通过同一个硬件项来具体体现。单词第一、第二、以及第三等的使用不表示任何顺序。可将这些单词解释为名称。It should be noted that the above-mentioned embodiments illustrate rather than limit the present invention, and those skilled in the art can design alternative embodiments without departing from the scope of the appended claims. In the claims, any reference signs placed between parentheses should not be constructed as a limitation to the claims. The word "comprising" does not exclude the presence of elements or steps not listed in the claims. The word "a" or "an" preceding an element does not exclude the presence of multiple such elements. The invention can be implemented by means of hardware comprising several different elements and by means of a suitably programmed computer. In the unit claims that list several devices, several of these devices may be embodied in the same hardware item. The use of the words first, second, and third, etc. do not indicate any order. These words can be interpreted as names.
此外,还应当注意,本说明书中使用的语言主要是为了可读性和教导的目的而选择的,而不是为了解释或者限定本发明的主题而选择的。因此,在不偏离所附权利要求书的范围和精神的情况下,对于本技术领域的普通技术人员来说许多修改和变更都是显而易见的。对于本发明的范围,对本发明所做的公开是说明性的,而非限制性的,本发明的范围由所附权利要求书限定。In addition, it should also be noted that the language used in this specification is mainly selected for readability and teaching purposes, not for explaining or limiting the subject of the present invention. Therefore, without departing from the scope and spirit of the appended claims, many modifications and changes are obvious to those of ordinary skill in the art. For the scope of the present invention, the disclosure of the present invention is illustrative rather than restrictive, and the scope of the present invention is defined by the appended claims.
Claims (24)
- 一种着色语言翻译方法,其特征在于,包括:A coloring language translation method, which is characterized in that it includes:对第一平台的第一着色语言对应的第一代码文件进行语法分析以得到所述第一代码文件的抽象语法树;Performing syntax analysis on the first code file corresponding to the first coloring language of the first platform to obtain an abstract syntax tree of the first code file;对所述抽象语法树中的多个节点的类型关键字进行分析以确定所述多个节点各自对应的关键变量,并利用所述关键变量,获取所述第一代码文件的着色语言信息;Analyzing the type keywords of the multiple nodes in the abstract syntax tree to determine the key variables corresponding to each of the multiple nodes, and using the key variables to obtain the coloring language information of the first code file;根据所述第一着色语言和第二平台的第二着色语言之间的变量映射规则和/或所述第一着色语言和所述第二着色语言之间的函数映射规则,对所述第一代码文件的着色语言信息进行翻译,以得到所述第二着色语言对应的第二代码文件;According to the variable mapping rules between the first coloring language and the second coloring language of the second platform and/or the function mapping rules between the first coloring language and the second coloring language, the first coloring language Translating the coloring language information of the code file to obtain a second code file corresponding to the second coloring language;其中,所述变量映射规则和所述函数映射规则根据所述第一着色语言和所述第二着色语言的语法规则确定。Wherein, the variable mapping rule and the function mapping rule are determined according to the grammar rules of the first shading language and the second shading language.
- 根据权利要求1所述的方法,其特征在于,还包括:The method according to claim 1, further comprising:从所述第一代码文件中确定待处理的变量,所述待处理的变量的名称包含与翻译工具中的保留关键字相同的字符串;Determine the variable to be processed from the first code file, and the name of the variable to be processed contains the same character string as the reserved keyword in the translation tool;对所述待处理的变量的名称进行修改。Modify the name of the variable to be processed.
- 根据权利要求1所述的方法,其特征在于,所述第一代码文件的着色语言信息,包括:The method according to claim 1, wherein the shading language information of the first code file comprises:所述第一代码文件中的全局传参变量的信息、所述第一代码文件中的资源的信息、所述第一代码文件中的结构体的信息以及所述第一代码文件中的函数的信息中的至少一种。Information about the global parameters in the first code file, information about the resources in the first code file, information about the structure in the first code file, and information about the functions in the first code file At least one of the information.
- 根据权利要求3所述的方法,其特征在于,利用所述关键变量,获取所述第一代码文件的着色语言信息,包括:The method according to claim 3, wherein using the key variable to obtain the coloring language information of the first code file comprises:针对所述多个节点中的任一节点,若所述节点的类型关键字为全局传参变量结构体,则对所述节点的子节点的类型变量和名称变量进行解析,得到所述全局传参变量结构体包含的全局传参变量的类型和名称;For any one of the multiple nodes, if the type keyword of the node is a global parameter variable structure, then the type variables and name variables of the child nodes of the node are parsed to obtain the global transmission The type and name of the global parameter variable contained in the parameter variable structure;将所述全局传参变量结构体包含的全局传参变量的类型和名称保存在变量字典中。The type and name of the global parameter-passing variable contained in the global parameter-passing variable structure are stored in the variable dictionary.
- 根据权利要求4所述的方法,其特征在于,利用所述关键变量,获取所述第一代码文件的着色语言信息,包括:The method according to claim 4, wherein using the key variable to obtain the coloring language information of the first code file comprises:若所述节点的类型关键字包含表示资源的字符串,则解析所述节点的名称变量和寄存器分配变量,以获取所述资源的名称和寄存器地址;If the type keyword of the node contains a character string representing a resource, parse the name variable and register allocation variable of the node to obtain the name and register address of the resource;将所述资源的名称和寄存器地址,对应保存在资源字典中;Save the name and register address of the resource in the resource dictionary correspondingly;其中,所述资源包括:纹理资源、缓冲器资源以及寄存器资源中的至少一中。Wherein, the resources include: at least one of texture resources, buffer resources, and register resources.
- 根据权利要求5所述的方法,其特征在于,利用所述关键变量,获取所述第一代码文件的着色语言信息,包括:The method according to claim 5, wherein using the key variable to obtain the coloring language information of the first code file comprises:若所述节点的类型关键字为函数定义或函数声明,则解析所述节点的函数类型变量和名称变量,以获取所述节点对应的第一函数的返回类型和函数名;If the type keyword of the node is a function definition or a function declaration, parse the function type variable and the name variable of the node to obtain the return type and function name of the first function corresponding to the node;将所述第一函数的返回类型和函数名作为所述第一函数的信息,并将所述第一函数的信息保存在函数字典中。The return type and function name of the first function are used as the information of the first function, and the information of the first function is stored in a function dictionary.
- 根据权利要求6所述的方法,其特征在于,还包括:The method according to claim 6, further comprising:解析所述节点的函数参数变量的子节点的类型变量和名称变量,以获取所述第一函数的形参变量的类型和名称,并将所述第一函数的形参变量的类型和名称写入所述第一函数的信息;Parse the type variable and name variable of the child node of the function parameter variable of the node to obtain the type and name of the formal parameter variable of the first function, and write the type and name of the formal parameter variable of the first function Enter the information of the first function;若所述第一函数的形参变量中,包括具有out或者inout属性的形参变量,则在所述第一函数的信息中,记录所述具有out或者inout属性的形参变量。If the formal parameter variable of the first function includes a formal parameter variable with an out or inout attribute, then the formal parameter variable with an out or inout attribute is recorded in the information of the first function.
- 根据权利要求7所述的方法,其特征在于,还包括:The method according to claim 7, further comprising:获取所述节点的代码块变量的任一子节点对应的子树;Acquiring a subtree corresponding to any child node of the code block variable of the node;若所述子树中的第一节点的类型为函数调用,则解析所述第一节点的名称变量和实参变量,得到所述第一节点对应的函数名以及传参信息;If the type of the first node in the subtree is a function call, parse the name variable and the actual parameter variable of the first node to obtain the function name and parameter transfer information corresponding to the first node;在所述函数字典中,查询与所述第一节点对应的函数名和传参信息对应的目标函数,作为所述第一函数的调用函数,并将所述调用函数写入所述第一函数的信息中。In the function dictionary, query the function name corresponding to the first node and the target function corresponding to the parameter passing information as the calling function of the first function, and write the calling function into the first function Information.
- 根据权利要求8所述的方法,其特征在于,还包括:The method according to claim 8, further comprising:若所述子树中的第二节点使用了第一全局资源,则将所述第一全局资源的信息写入所述第一函数的信息中;所述第一全局资源包括纹理资源、缓冲器资源以及采样器资源中的至少一种;If the second node in the subtree uses the first global resource, the information of the first global resource is written into the information of the first function; the first global resource includes texture resources, buffers At least one of resources and sampler resources;若所述子树中的第三节点使用了第一全局传参变量,则将所述第一全局传参变量的信息写入所述第一函数的信息中。If the third node in the subtree uses the first global parameter passing variable, the information of the first global parameter passing variable is written into the information of the first function.
- 根据权利要求9所述的方法,其特征在于,还包括:The method according to claim 9, further comprising:从所述函数字典中确定入口函数;Determine the entry function from the function dictionary;从所述入口函数开始,采用深度优先搜索的方式,搜索所述入口函数调用的每个函数;Starting from the entry function, a depth-first search method is adopted to search for each function called by the entry function;将搜索到的所述入口函数调用的函数,记录到目标函数集合中。Record the searched function called by the entry function into the target function set.
- 根据权利要求10所述的方法,其特征在于,利用所述关键变量,获取所述第一代码文件的着色语言信息,包括:The method according to claim 10, wherein using the key variable to obtain the coloring language information of the first code file comprises:若所述节点的类型关键字为结构体定义,则解析所述节点的名称变量和类成员声 明变量的子节点,以获取所述节点对应的第一结构体的名称和所述第一结构体包含的类成员的信息;If the type keyword of the node is a structure definition, the name variable of the node and the child nodes of the class member declaration variable are parsed to obtain the name of the first structure corresponding to the node and the first structure Contains information about class members;将所述第一结构体的名称和所述第一结构体包含的类成员的信息保存在全局链表中。The name of the first structure and the information of the class members contained in the first structure are stored in a global linked list.
- 根据权利要求11所述的方法,其特征在于,还包括:The method according to claim 11, further comprising:遍历所述函数字典,以从所述函数字典中确定入口函数;Traverse the function dictionary to determine the entry function from the function dictionary;若所述第一结构体与所述入口函数的返回类型适配,则确定所述第一结构体为输出类型的结构体;If the first structure body matches the return type of the entry function, it is determined that the first structure body is an output type structure body;若所述第一结构体与所述入口函数的形参变量的类型适配,则确定所述第一结构体为输入类型的结构体。If the first structure body matches the type of the formal parameter variable of the entry function, it is determined that the first structure body is an input type structure body.
- 根据权利要求12所述的方法,其特征在于,根据设定的信息映射规则,对所述第一代码文件的着色语言信息进行翻译,包括:The method according to claim 12, wherein the translation of the coloring language information of the first code file according to a set information mapping rule comprises:从所述全局链表中获取所述第一结构体;Obtaining the first structure from the global linked list;根据所述变量映射规则,对所述第一结构体中的变量进行翻译,以将所述第一结构体映射为符合第二着色语言的语法的第二结构体;Translating the variables in the first structure according to the variable mapping rule to map the first structure into a second structure conforming to the grammar of the second shading language;若所述第一结构体为顶点着色器的输入类型的结构体,则设置映射得到的所述第二结构体中的变量的属性编号与所述第一结构体中的变量的属性编号一致;If the first structure is a structure of the input type of the vertex shader, setting the attribute number of the variable in the second structure obtained by mapping to be consistent with the attribute number of the variable in the first structure;若所述第一结构体为顶点着色器的输出类型的结构体或者为片元着色器的输入类型的结构体,则将所述第一结构体中的属性为SV_POSITION的变量映射为所述第二结构体中的变量后,为映射得到的变量添加[[position]]标识;If the first structure is the structure of the output type of the vertex shader or the structure of the input type of the fragment shader, then the variable with the attribute SV_POSITION in the first structure is mapped to the first structure After the variables in the second structure, add [[position]] to the mapped variables;若所述第一结构体为片元着色器的输出类型的结构体,则将所述第一结构体中的属性为SV_Target的变量映射为所述第二结构体中的变量后,为映射得到的变量添加[[color]]标识,且同步所述属性为SV_Target的变量的编号。If the first structure is a structure of the output type of the fragment shader, after mapping the variable whose attribute is SV_Target in the first structure to the variable in the second structure, it is obtained by mapping Add the [[color]] mark to the variable, and synchronize the number of the variable with SV_Target as the attribute.
- 根据权利要求12所述的方法,其特征在于对所述第一代码文件的着色语言信息进行翻译,包括:The method according to claim 12, characterized in that translating the shading language information of the first code file comprises:将所述变量字典中的全局传参变量,映射为第一目标结构体的成员变量。Map the global parameter variable in the variable dictionary to the member variable of the first target structure.
- 根据权利要求14所述的方法,其特征在于,对所述第一代码文件的着色语言信息进行翻译,包括:The method according to claim 14, wherein translating the shading language information of the first code file comprises:从所述目标函数集合中获取所述第一函数;Obtaining the first function from the set of objective functions;根据所述变量映射规则和/或所述函数映射规则,对所述第一函数进行翻译,以将所述第一函数映射为符合所述第二着色语言的语法的第二函数;Translating the first function according to the variable mapping rule and/or the function mapping rule to map the first function to a second function conforming to the grammar of the second shading language;若所述第一函数不为入口函数,则在所述第二函数的返回类型之前添加inline关键字;If the first function is not an entry function, add the inline keyword before the return type of the second function;若所述第一函数的信息中记录有具有out或者inout属性的形参变量,则在所述第二函数中生成第三结构体;根据所述具有out或者inout属性的形参变量的传参顺序,在所述第三结构体中依次定义至少一个形参变量;其中,所述至少一个形参变量的类型与所述具有out或者inout属性的形参变量的类型相同,且所述至少一个形参变量的名称设有输出参数前缀;If a formal parameter variable with an out or inout attribute is recorded in the information of the first function, a third structure is generated in the second function; according to the parameter passing of the formal parameter variable with the out or inout attribute Sequence, define at least one formal parameter variable in the third structure; wherein the type of the at least one formal parameter variable is the same as the type of the formal parameter variable with the out or inout attribute, and the at least one The name of the formal parameter variable is set with the output parameter prefix;若根据所述第一函数的信息确定所述第一函数的返回类型不为空,则在所述第三结构体内定义返回参数变量;所述返回参数变量与所述第一函数的返回类型相同;If it is determined according to the information of the first function that the return type of the first function is not empty, a return parameter variable is defined in the third structure; the return parameter variable is the same as the return type of the first function ;若根据所述第一函数的信息确定所述第一函数使用了所述第一全局传参变量,则在生成所述第二函数的形参信息时,将所述第一目标结构体作为所述第二函数的第一个形参;If it is determined according to the information of the first function that the first function uses the first global parameter variable, when generating the formal parameter information of the second function, the first target structure is used as the State the first parameter of the second function;若根据所述第一函数的信息确定所述第一函数使用了所述第一全局资源,则在生成所述第二函数的形参信息时,将所述第一全局资源的信息放置在除所述第一目标结构体之外的其他形参之前;If it is determined according to the information of the first function that the first function uses the first global resource, when generating the formal parameter information of the second function, the information of the first global resource is placed in the Before the other formal parameters except the first target structure;若所述第一函数为入口函数,则在所述入口函数的形参变量中,声明所述第一目标结构体、所述资源字典中的缓冲器资源、所述资源字典中的纹理资源以及所述资源字典中的采样器资源;其中,在所述第一目标结构体和所述缓冲器资源之后添加缓冲器标记,在所述纹理资源之后添加纹理标记,在所述采样器资源之后添加采样器标记;If the first function is an entry function, in the formal parameter variable of the entry function, declare the first target structure, the buffer resource in the resource dictionary, the texture resource in the resource dictionary, and The sampler resource in the resource dictionary; wherein a buffer mark is added after the first target structure and the buffer resource, a texture mark is added after the texture resource, and a texture mark is added after the sampler resource Sampler tag;在所述第一函数的形参变量中,采用stage关键字标记输入类型的形参;In the formal parameter variables of the first function, the stage keyword is used to mark the formal parameters of the input type;若所述第一函数与顶点着色器对应,则在所述第一函数的返回类型前添加表示顶点的关键字;If the first function corresponds to a vertex shader, add a keyword representing a vertex before the return type of the first function;若所述第一函数与片元着色器对应,则在所述第一函数的返回类型前添加表示片元的关键字。If the first function corresponds to a fragment shader, a keyword representing the fragment is added before the return type of the first function.
- 根据权利要求13-15任一项所述的方法,其特征在于,所述第一代码文件为HLSL着色语言的代码文件;所述第二代码文件为Metal着色语言对应的代码文件。The method according to any one of claims 13-15, wherein the first code file is a code file of the HLSL shading language; and the second code file is a code file corresponding to the Metal shading language.
- 根据权利要求12所述的方法,其特征在于,对所述第一代码文件的着色语言信息进行翻译,包括:The method according to claim 12, wherein translating the shading language information of the first code file comprises:将所述变量字典中的全局传参变量,映射为第二目标结构体的成员变量;Mapping the global parameter variable in the variable dictionary to the member variable of the second target structure;定义统一变量块,并将所述第二目标结构体存储在所述统一变量块中;Define a uniform variable block, and store the second target structure in the uniform variable block;遍历所述抽象语法树,若遍历到的当前节点的名称与所述统一变量块中存储的任一全局传参变量的名称相同,则在所述当前节点的名称之前添加所述统一变量块的名称标识。Traverse the abstract syntax tree, if the name of the current node traversed is the same as the name of any global parameter variable stored in the uniform variable block, add the name of the uniform variable block before the name of the current node Name identification.
- 根据权利要求12所述的方法,其特征在于,还包括:The method according to claim 12, further comprising:从所述变量字典中获取所述全局传参变量结构体;Obtain the global parameter variable structure from the variable dictionary;采用layout设置所述全局传参变量结构体的set修饰符和binding修饰符。Use layout to set the set modifier and binding modifier of the global parameter variable structure.
- 根据权利要求12所述的方法,其特征在于,对所述第一代码文件的着色语言信息进行翻译,包括:The method according to claim 12, wherein translating the shading language information of the first code file comprises:从所述资源字典中获取任意一种待翻译的资源;Obtain any resource to be translated from the resource dictionary;采用layout设置所述待翻译的资源的binding修饰符,并在所述待翻译的资源的变量类型前添加uniform关键字;Use layout to set the binding modifier of the resource to be translated, and add a uniform keyword before the variable type of the resource to be translated;其中,所述binding修饰符的值根据所述待翻译的资源的寄存器的值确定。Wherein, the value of the binding modifier is determined according to the value of the register of the resource to be translated.
- 根据权利要求12所述的方法,其特征在于,对所述第一代码文件的着色语言信息进行翻译,包括:The method according to claim 12, wherein translating the shading language information of the first code file comprises:从所述全局链表中获取所述第一结构体;Obtaining the first structure from the global linked list;根据变量映射规则,对所述第一结构体中的变量进行翻译,以将所述第一结构体映射为符合第二着色语言的语法的第二结构体;Translating the variables in the first structure according to the variable mapping rule to map the first structure into a second structure conforming to the grammar of the second shading language;将所述第一结构体对应的输入类型以及输出类型,分别翻译为所述第二结构体的输入变量以及输出变量;Translate the input type and output type corresponding to the first structure into input variables and output variables of the second structure, respectively;若所述第一结构体为顶点着色器的输入类型的结构体,则对所述第二结构体中的输入变量采用layout关键字定义location修饰符,并在声明所述第二结构体中的输入变量时,在所述第二结构体中输入变量的类型前添加in关键字;其中,所述location修饰符的值与所述第一结构体中的变量的属性编号一致;If the first structure is the input type structure of the vertex shader, the layout keyword is used to define the location modifier for the input variables in the second structure, and the location modifier in the second structure is declared When inputting a variable, add the in keyword before the type of the variable in the second structure; wherein, the value of the location modifier is consistent with the attribute number of the variable in the first structure;若所述第一结构体为顶点着色器的输出类型的结构体,则在翻译所述第一结构体时,采用保留关键字gl_Positon代替属性为SV_POSITION的变量;以及,在声明所述第二结构体中的输入变量时,在所述第二结构体中的输入变量的类型之前添加out关键字;If the first structure is a structure of the output type of the vertex shader, when translating the first structure, the reserved keyword gl_Positon is used to replace the variable whose attribute is SV_POSITION; and, when the second structure is declared When inputting variables in the body, add the out keyword before the type of the input variable in the second structure;若所述第一结构体为片元着色器的输入类型的结构体,则对所述第一结构体中具有SV_POSITION属性的变量进行翻译时,在layout中设置origin_upper_left修饰符,并在所述具有SV_POSITION属性的变量的变量类型之前添加in关键字,并设置变量名为gl_FragCoord;If the first structure is the input type structure of the fragment shader, when translating the variable with the SV_POSITION attribute in the first structure, the origin_upper_left modifier is set in the layout, and the Add the in keyword before the variable type of the variable of the SV_POSITION attribute, and set the variable name to gl_FragCoord;若所述第一结构体为片元着色器的输出类型的结构体,则对翻译得到的所述第二结构体中的输出变量采用layout关键字设置location修饰符,其中所述location修饰符的值与所述第一结构体中对应的变量的SV_Target属性编号一致,且在所述第二结构体中的输出变量的类型之前添加out关键字。If the first structure is the structure of the output type of the fragment shader, then the layout keyword is used to set the location modifier for the output variable in the second structure obtained by translation, and the location modifier of the location modifier is The value is consistent with the SV_Target attribute number of the corresponding variable in the first structure, and the out keyword is added before the type of the output variable in the second structure.
- 根据权利要求20所述的方法,其特征在于,根据所述第一函数的信息以及函数映射规则,对所述第一函数进行翻译,包括执行以下至少一种操作:The method according to claim 20, wherein the translation of the first function according to the information of the first function and the function mapping rule comprises performing at least one of the following operations:从所述目标函数集合中获取所述第一函数;Obtaining the first function from the set of objective functions;根据所述变量映射规则和/或所述函数映射规则,对所述第一函数的信息进行翻译,以将所述第一函数映射为符合所述第二着色语言的语法的第二函数;Translating the information of the first function according to the variable mapping rule and/or the function mapping rule to map the first function to a second function conforming to the grammar of the second shading language;若所述第一函数为资源读取函数,则在翻译得到的所述第二函数中,将被读取的资源的类型、被读取的资源的位置以及其他参数写在所述第二函数的函数体中;If the first function is a resource reading function, in the second function obtained by translation, write the type of the resource to be read, the location of the resource to be read, and other parameters in the second function In the body of the function;若所述第一函数为入口函数,则将所述第一函数映射得到的所述第二函数的返回值设为void。If the first function is an entry function, the return value of the second function obtained by mapping the first function is set to void.
- 根据权利要求17-21任一项所述的方法,其特征在于,所述第一代码文件为HLSL着色语言的代码文件;所述第二代码文件为GLSL着色语言对应的代码文件。The method according to any one of claims 17-21, wherein the first code file is a code file of HLSL shading language; and the second code file is a code file corresponding to GLSL shading language.
- 一种计算机程序,包括计算机可读代码,当所述计算机可读代码在服务器上运行时,导致所述服务器执行根据权利要求1-22中的任一个所述的网站扫描方法。A computer program comprising computer readable code, when the computer readable code runs on a server, causes the server to execute the website scanning method according to any one of claims 1-22.
- 一种计算机可读介质,其中存储了如权利要求23所述的计算机程序。A computer readable medium in which the computer program according to claim 23 is stored.
Applications Claiming Priority (2)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010539681.4A CN111488155B (en) | 2020-06-15 | 2020-06-15 | Coloring language translation method |
CN202010539681.4 | 2020-06-15 |
Publications (1)
Publication Number | Publication Date |
---|---|
WO2021253641A1 true WO2021253641A1 (en) | 2021-12-23 |
Family
ID=71813475
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
PCT/CN2020/112548 WO2021253641A1 (en) | 2020-06-15 | 2020-08-31 | Shading language translation method |
Country Status (2)
Country | Link |
---|---|
CN (1) | CN111488155B (en) |
WO (1) | WO2021253641A1 (en) |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN117270962A (en) * | 2023-11-22 | 2023-12-22 | 北京渲光科技有限公司 | Method and device for processing coloring language, storage medium and electronic equipment |
CN117648391A (en) * | 2023-11-28 | 2024-03-05 | 开普勒卫星科技(武汉)有限公司 | GNSS track data storage and query method and database system |
Families Citing this family (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111488155B (en) * | 2020-06-15 | 2020-09-22 | 完美世界(北京)软件科技发展有限公司 | Coloring language translation method |
CN112258411B (en) * | 2020-10-22 | 2021-07-13 | 浙江大学 | Shader automatic filtering method, device and system based on function approximation of definition domain and value domain |
Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20090122062A1 (en) * | 2007-11-09 | 2009-05-14 | Lucasfilm Entertainment Company Ltd. | Translating Renderman Shading Language Code |
CN106415496A (en) * | 2014-05-30 | 2017-02-15 | 苹果公司 | Unified intermediate representation |
CN107771319A (en) * | 2015-06-07 | 2018-03-06 | 苹果公司 | Encapsulation image storehouse and the graphics engine and environment of hardware |
CN110147235A (en) * | 2019-03-29 | 2019-08-20 | 中国科学院信息工程研究所 | Semantic comparison method and device between a kind of source code and binary code |
CN111091612A (en) * | 2019-10-09 | 2020-05-01 | 中国船舶重工集团公司第七0九研究所 | Coloring language machine code generation method and device of abstract object code architecture |
CN111488155A (en) * | 2020-06-15 | 2020-08-04 | 完美世界(北京)软件科技发展有限公司 | Coloring language translation method |
Family Cites Families (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN100461132C (en) * | 2007-03-02 | 2009-02-11 | 北京邮电大学 | Software safety code analyzer based on static analysis of source code and testing method therefor |
US9027007B2 (en) * | 2013-03-06 | 2015-05-05 | Qualcomm Incorporated | Reducing excessive compilation times |
-
2020
- 2020-06-15 CN CN202010539681.4A patent/CN111488155B/en active Active
- 2020-08-31 WO PCT/CN2020/112548 patent/WO2021253641A1/en active Application Filing
Patent Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20090122062A1 (en) * | 2007-11-09 | 2009-05-14 | Lucasfilm Entertainment Company Ltd. | Translating Renderman Shading Language Code |
CN106415496A (en) * | 2014-05-30 | 2017-02-15 | 苹果公司 | Unified intermediate representation |
CN107771319A (en) * | 2015-06-07 | 2018-03-06 | 苹果公司 | Encapsulation image storehouse and the graphics engine and environment of hardware |
CN110147235A (en) * | 2019-03-29 | 2019-08-20 | 中国科学院信息工程研究所 | Semantic comparison method and device between a kind of source code and binary code |
CN111091612A (en) * | 2019-10-09 | 2020-05-01 | 中国船舶重工集团公司第七0九研究所 | Coloring language machine code generation method and device of abstract object code architecture |
CN111488155A (en) * | 2020-06-15 | 2020-08-04 | 完美世界(北京)软件科技发展有限公司 | Coloring language translation method |
Cited By (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN117270962A (en) * | 2023-11-22 | 2023-12-22 | 北京渲光科技有限公司 | Method and device for processing coloring language, storage medium and electronic equipment |
CN117270962B (en) * | 2023-11-22 | 2024-02-09 | 北京渲光科技有限公司 | Method and device for processing coloring language, storage medium and electronic equipment |
CN117648391A (en) * | 2023-11-28 | 2024-03-05 | 开普勒卫星科技(武汉)有限公司 | GNSS track data storage and query method and database system |
Also Published As
Publication number | Publication date |
---|---|
CN111488155A (en) | 2020-08-04 |
CN111488155B (en) | 2020-09-22 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
WO2021253641A1 (en) | Shading language translation method | |
CN106970819B (en) | C program code specification checking device based on PRD L rule description language | |
US11023500B2 (en) | Systems and methods for code parsing and lineage detection | |
WO2021017735A1 (en) | Smart contract formal verification method, electronic apparatus and storage medium | |
US9122540B2 (en) | Transformation of computer programs and eliminating errors | |
CN103955538B (en) | HBase data persistence and query methods and HBase system | |
CN113641701B (en) | Data query method, system, heterogeneous acceleration platform and storage medium | |
JP5791149B2 (en) | Computer-implemented method, computer program, and data processing system for database query optimization | |
CN108984155A (en) | Flow chart of data processing setting method and device | |
US9104724B2 (en) | Dynamic bridging of application and data servers | |
CN109491658A (en) | The generation method and device of computer-executable code data | |
KR101877828B1 (en) | User interface integrated platform system based on artificial intelligence | |
CN106844369B (en) | Objectification SQL sentence construction method and apparatus | |
US20120158742A1 (en) | Managing documents using weighted prevalence data for statements | |
WO2021259290A1 (en) | Stored procedure conversion method and apparatus, and device and storage medium | |
CN113468204A (en) | Data query method, device, equipment and medium | |
CN113962597A (en) | Data analysis method and device, electronic equipment and storage medium | |
CN113806429A (en) | Canvas type log analysis method based on large data stream processing framework | |
US10223086B2 (en) | Systems and methods for code parsing and lineage detection | |
US20070282804A1 (en) | Apparatus and method for extracting database information from a report | |
CN105573763A (en) | Embedded system modeling method supporting RTOS | |
CN112597171A (en) | Table relation visualization method and device, electronic equipment and storage medium | |
EP4145357A1 (en) | Automatic denoising of machine learning projects | |
CN114969044B (en) | Materialized column creation method and data query method based on data lake | |
CN116756184B (en) | Database instance processing method, device, equipment, storage medium and program product |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 20940511 Country of ref document: EP Kind code of ref document: A1 |
|
NENP | Non-entry into the national phase |
Ref country code: DE |
|
122 | Ep: pct application non-entry in european phase |
Ref document number: 20940511 Country of ref document: EP Kind code of ref document: A1 |