CN117270962B - Method and device for processing coloring language, storage medium and electronic equipment - Google Patents

Method and device for processing coloring language, storage medium and electronic equipment Download PDF

Info

Publication number
CN117270962B
CN117270962B CN202311560320.8A CN202311560320A CN117270962B CN 117270962 B CN117270962 B CN 117270962B CN 202311560320 A CN202311560320 A CN 202311560320A CN 117270962 B CN117270962 B CN 117270962B
Authority
CN
China
Prior art keywords
target
language
file
coloring
glsl
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202311560320.8A
Other languages
Chinese (zh)
Other versions
CN117270962A (en
Inventor
刘锦
胡梓楠
崔铭
冯星
张志恒
方顺
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Xuanguang Technology Co ltd
Original Assignee
Beijing Xuanguang Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Xuanguang Technology Co ltd filed Critical Beijing Xuanguang Technology Co ltd
Priority to CN202311560320.8A priority Critical patent/CN117270962B/en
Publication of CN117270962A publication Critical patent/CN117270962A/en
Application granted granted Critical
Publication of CN117270962B publication Critical patent/CN117270962B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/76Adapting program code to run in a different environment; Porting
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/71Version control; Configuration management

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Security & Cryptography (AREA)
  • Stored Programmes (AREA)

Abstract

Some embodiments of the present application provide a method, an apparatus, a storage medium, and an electronic device for processing a coloring language, where the method includes: determining a parameter to be processed, wherein the parameter to be processed comprises: the method comprises the steps of coloring a language GLSL file, a current shader loader type, a target platform type and a target loader type corresponding to the GLSL file; preprocessing the GLSL file to obtain a code character string; translating the code character string according to the target platform type to generate a target coloring language corresponding to the target loader type; and determining a standard coloring language through the target coloring language, and packaging and storing. According to the method and the device, cross-platform compiling of the GLSL file can be achieved, so that the generated target coloring language is applicable to any type of target platform type, and the adaptability is wide.

Description

Method and device for processing coloring language, storage medium and electronic equipment
Technical Field
The present application relates to the field of rendering technologies, and in particular, to a method, an apparatus, a storage medium, and an electronic device for processing a coloring language.
Background
A Shader (Shader) is a computer program running on a GPU to achieve some rendering effects.
The same rendering effect generally needs to be adapted to various different types of machines, however, the graphics rendering interfaces commonly used by the different types of machines are different, and the coloring languages used by the graphics rendering interfaces are different, so that the same rendering effect is difficult to be adapted to the different types of machines. Currently, a rendering effect is intended to be implemented on different versions of different platforms, requiring programmers to write different loader languages for different platforms and versions. Poor universality among the loader languages directly leads to the multiplication of the working pressure of programmers, and reduces the realization efficiency of the rendering effect.
Therefore, how to provide a method for efficiently and universally processing coloring languages is a technical problem to be solved.
Disclosure of Invention
An object of some embodiments of the present application is to provide a method, an apparatus, a storage medium, and an electronic device for processing a coloring language, by which translation of a coloring language file can be implemented through a technical solution of the embodiments of the present application, so that a target coloring language obtained by translation is adapted to different platforms and versions, which has better universality, improves implementation efficiency of a rendering effect, and reduces working pressure of a programmer.
In a first aspect, some embodiments of the present application provide a method of processing a shading language, comprising: determining a parameter to be processed, wherein the parameter to be processed comprises: the method comprises the steps of coloring a language GLSL file, a current shader loader type, a target platform type and a target loader type corresponding to the GLSL file; preprocessing the GLSL file to obtain a code character string; translating the code character string according to the target platform type to generate a target coloring language corresponding to the target loader type; and determining a standard coloring language through the target coloring language, and packaging and storing.
Some embodiments of the present application translate code strings obtained by preprocessing GLSL files in parameters to be processed to obtain a target coloring language of a target loader type, and finally package and store the target coloring language. Some embodiments of the application are based on GLSL files, and can translate into target coloring languages of various different platforms and versions, so that only one language can be translated to each platform of a loader and code configuration of different versions of the same platform is realized, the universality is good, the realization efficiency of rendering effect is improved, and the working pressure of programmers is reduced.
In some embodiments, the preprocessing the GLSL file to obtain a code string includes: adding macro definition rules corresponding to the target platform types; and reading and processing the GLSL file by utilizing the macro definition rule to obtain the code character string.
According to the method and the device, the GLSL file is preprocessed by adding the macro definition rule corresponding to the target platform type to obtain the code character string, so that the GLSL file can be effectively processed, and code support is provided for follow-up.
In some embodiments, the reading and processing the GLSL file using the macro definition rule to obtain the code string includes: reading the character strings in the GLSL file, and adding the character strings conforming to the macro definition rule into the code character strings; and integrating and adding the specified header file in the GLSL file into the code character string.
Some embodiments of the present application classify and integrate character strings in GLSL by macro definition rules to obtain code character strings, which can provide effective code support for subsequent translation.
In some embodiments, the translating the code string according to the target platform type to generate a target shading language corresponding to the target loader type includes: dividing the code character string according to GLSL grammar to obtain word segmentation result; carrying out grammar analysis on the word segmentation result to obtain an initial abstract grammar tree; translating the initial abstract syntax tree into a target abstract syntax tree corresponding to a target loader type of the target platform type; generating the target coloring language corresponding to the target abstract syntax tree.
Some embodiments of the present application may implement cross-platform compilation of GLSL files by splitting, parsing, and translating code strings to generate corresponding target coloring languages.
In some embodiments, prior to the generating the target shading language corresponding to the target abstract syntax tree, the method further comprises: functions associated with the shading language master function are placed in a first set and global variables associated with the shading language master function are placed in a second set.
Some embodiments of the present application may subsequently implement efficient translation by sorting the functions and global variables associated with the main function of the colored language.
In some embodiments, the determining, by the target shading language, a standard shading language, and storing in a package, includes: acquiring the standard coloring language by judging whether the target platform type is a drawing application program interface Vulkan platform; and converting the standard coloring language into a binary file, and packaging and storing the binary file into a target file.
Some embodiments of the present application may ensure the accuracy of post-translation packaged storage by determining a standard shading language by making a decision on the target platform type.
In some embodiments, the obtaining the standard shading language by determining whether the target platform type is a drawing application program interface Vulkan platform comprises: if the target platform type is the Vulkan platform, processing the target coloring language to generate a standard coloring language; and if the target platform type is not the Vulkan platform, taking the target coloring language as the standard coloring language.
According to the method and the device, whether the target coloring language is processed and stored or not can be confirmed by confirming whether the target coloring language is the Vulkan platform or not, targeted processing of the Vulkan platform can be achieved, and adaptability is good.
In a second aspect, some embodiments of the present application provide an apparatus for processing a coloring language, comprising: the input module is used for determining parameters to be processed, wherein the parameters to be processed comprise: the method comprises the steps of coloring a language GLSL file, a current shader loader type, a target platform type and a target loader type corresponding to the GLSL file; the preprocessing module is used for preprocessing the GLSL file to obtain a code character string; the generation module is used for translating the code character strings according to the target platform type and generating a target coloring language corresponding to the target loader type; and the packaging storage module is used for determining a standard coloring language through the target coloring language and packaging and storing the standard coloring language.
In a third aspect, some embodiments of the present application provide a computer readable storage medium having stored thereon a computer program which, when executed by a processor, performs a method according to any of the embodiments of the first aspect.
In a fourth aspect, some embodiments of the present application provide an electronic device comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein the processor, when executing the program, can implement a method according to any of the embodiments of the first aspect.
In a fifth aspect, some embodiments of the present application provide a computer program product comprising a computer program, wherein the computer program, when executed by a processor, is adapted to carry out the method according to any of the embodiments of the first aspect.
Drawings
In order to more clearly illustrate the technical solutions of some embodiments of the present application, the drawings that are required to be used in some embodiments of the present application will be briefly described below, it should be understood that the following drawings only illustrate some embodiments of the present application and should not be considered as limiting the scope, and other related drawings may be obtained according to these drawings without inventive effort to a person having ordinary skill in the art.
FIG. 1 is a system diagram of a processing shading language provided by some embodiments of the present application;
FIG. 2 is one of the flow charts of the method of processing a shading language provided in some embodiments of the present application;
FIG. 3 is a flow chart of a method of path splicing function processing provided in some embodiments of the present application;
FIG. 4 is a second flowchart of a method for processing a coloring language according to some embodiments of the present application;
FIG. 5 is a block diagram of an apparatus for processing a coloring language according to some embodiments of the present application;
fig. 6 is a schematic diagram of an electronic device according to some embodiments of the present application.
Detailed Description
The technical solutions in some embodiments of the present application will be described below with reference to the drawings in some embodiments of the present application.
It should be noted that: like reference numerals and letters denote like items in the following figures, and thus once an item is defined in one figure, no further definition or explanation thereof is necessary in the following figures. Meanwhile, in the description of the present application, the terms "first", "second", and the like are used only to distinguish the description, and are not to be construed as indicating or implying relative importance.
In the related art, three loader languages written more often by a programmer are respectively: GLSL (OpenGL Shading Language) based on the OpenGL API (Application Programming Interface ), HLSL (High Level Shading Language) based on DirectX developed by microsoft, apple corporation developed a Metal language based on apple machines. However, these loader languages are incompatible, and a particular platform can only use a particular loader language. Because of the different machine configurations and different supported versions, a rendering effect in a game is intended to be implemented on different versions of a plurality of different platforms, and many loader language files need to be written. For example, when developing graphics rendering programs on embedded devices, it is necessary to write the Gles shader code that is suitable for the embedded device; GLSL is used when developing graphics rendering programs on desktop devices. Because OpenGLES is adaptively cut and adapted on the basis of OpenGL according to the characteristics of embedded equipment; therefore, shader code suitable for embedded devices cannot run on desktop devices; similarly, shader code that is suitable for desktop devices cannot run directly on embedded devices.
Because of the configuration and system of the devices, the versions of the required loader are different, and there is a limit to the conversion between different versions of the same language. In order to be suitable for all commonly used devices, if the same rendering effect is to be realized, developers are required to write in different versions of the loader language of all platforms once, so that development efficiency is greatly reduced, and in order to be required to know the characteristics of all the loader languages, development thresholds are also greatly improved.
In view of this, some embodiments of the present application provide an efficient method for processing a coloring language, which is based on a GLSL file, and after a code string is obtained by preprocessing the GLSL file, the code string is translated based on a target platform type, so as to generate a target coloring language adapted to the target platform type, and package and store the target coloring language. According to the embodiment of the application, the development efficiency of the same rendering effect can be improved, efficient loader cross-platform compiling is achieved, the development threshold is reduced, and the application is wide.
The overall composition of a system for processing a coloring language provided in some embodiments of the present application is described below by way of example in conjunction with fig. 1.
As shown in fig. 1, some embodiments of the present application provide a system for processing a shading language, the system comprising: a terminal 100 and a processing server 200. Specifically, the terminal 100 may input corresponding parameters to be processed by a programmer to the processing server 200. After obtaining the parameters to be processed, the loader compiler in the processing server 200 may preprocess the GLSL file to obtain a code string, then translate the code string based on the target platform type to generate a target coloring language corresponding to the target loader type, and package and store the target coloring language.
In some embodiments of the present application, the terminal 100 may be a mobile terminal or a non-portable computer terminal, which is not specifically limited herein.
In other embodiments of the present application, if the terminal 100 has the functions of preprocessing, translating, generating and storing the GLSL file in a packaged manner, the processing server 200 may not be provided. The flexible setting can be specifically performed according to actual situations, and the embodiment of the application is not limited to this.
The implementation of the process shading language performed by the processing server 200 provided in some embodiments of the present application is described below by way of example in conjunction with fig. 2.
Referring to fig. 2, fig. 2 is a flowchart of a method for processing a coloring language according to some embodiments of the present application, where the method for processing a coloring language includes:
s210, determining parameters to be processed, wherein the parameters to be processed comprise: the method comprises the steps of coloring a language GLSL file, a current shader loader type, a target platform type and a target loader type corresponding to the GLSL file.
For example, in some embodiments of the present application, the underlying GLSL file is first determined, then its current loader type is determined, and the target platform type and target loader type to which to transition are determined. The GLSL may distinguish the rendering types of the servers according to the file suffixes. Specifically, the programmer writes the shader language based on the GLSL language, and adds specific writing rules related to GLSL that must be complied with, so that the embodiment of the application can convert the specific writing GLSL file into different versions of the target shader language of multiple platforms. It should be noted that, since a high version may support a low version of features, a low version may not support a high version of features for the most part, a programmer needs to write GLSL high version language as much as possible, e.g., some feature support for optical tracking is required above GLSL 4.6 version.
S220, preprocessing the GLSL file to obtain a code character string.
For example, in some embodiments of the present application, the GLSL file may be pre-processed to obtain a code string for further processing.
In some embodiments of the present application, S220 may include: adding macro definition rules corresponding to the target platform types; and reading and processing the GLSL file by utilizing the macro definition rule to obtain the code character string.
For example, in some embodiments of the present application, each platform has its own proprietary characteristics, which cannot be determined when parsing, and if some proprietary errors occur, serious problems are caused, which easily directly result in rendering effect errors of other platforms. Embodiments of the present application define a writing rule that writes different features of the current platform than other platforms under the platform macro definition condition compilation. Taking a metal platform as an example, the writing mode is as follows:
#if define(METAL_SHADER)
the part of the writing metal platform and other platforms have different characteristics
#else
Other platform characteristics
#endif
In the code, the metal_header is a macro definition (i.e., macro definition rule) of the METAL platform, and the macro definition is added without manual addition by a programmer, and the header parser automatically performs addition according to the type of the target platform when parsing. The GLSL file may be processed by macro definition, outputting a result_str string (as a specific example of a code string).
In some embodiments of the present application, S220 may include: reading the character strings in the GLSL file, and adding the character strings conforming to the macro definition rule into the code character strings; and integrating and adding the specified header file in the GLSL file into the code character string.
For example, in some embodiments of the present application, GLSL file preprocessing is to process out the macro definition and integrate all relevant codes of the header file of the include (as a specific example of a specified header file) together, and put the codes into a code string to facilitate the processing of the next step. For example, a preprocessing function preprofunc () is designed, the function is input into a directory where a public version library and a function library of a current version are located, a GLSL file string Str is input, and a macro definition of a platform is added, and output is a result_str string.
Specifically, word-by-word extraction is performed on the character string Str of the GLSL file, non-macro correlation and head file correlation are encountered, and the character string Str is directly put into result_str in sequence without processing. The method comprises the steps of replacing and analyzing the related requirements of the macro definition, putting the required requirements into a result_str, and removing some unnecessary codes according to the macro definition (specifically, automatically removing according to the writing content in the macro definition codes). When encountering the keyword "include", path splicing function processing needs to be performed on the header file (for a specific implementation procedure of path splicing function processing, see the method embodiments provided below). And establishing an IncludeDirs set for storing the absolute paths of the processed header files, judging whether the header files are processed according to the current absolute paths of the header files, namely judging whether the IncludeDirs exist or not, if so, the header files are processed, and directly jumping to the Include for processing. If the current absolute path does not exist, the error is reported to exit the process. If the current absolute path exists and is not processed, the string Str_i of the current path file is extracted and put into a preprocessFunc () function for processing, the obtained string is put into result_str in sequence, and the current absolute path is stored into IncludeDirs. By the recursion processing, the character string Str of the GLSL file can be completely read, and the result_str obtained at this time is a result after preprocessing.
And S230, translating the code character string according to the target platform type to generate a target coloring language corresponding to the target loader type.
For example, in some embodiments of the present application, the result_str is translated to generate the corresponding target shading language by requiring translation of the adapted target platform type.
In some embodiments of the present application, S230 may include: dividing the code character string according to GLSL grammar to obtain word segmentation result; carrying out grammar analysis on the word segmentation result to obtain an initial abstract grammar tree; translating the initial abstract syntax tree into a target abstract syntax tree corresponding to a target loader type of the target platform type; generating the target coloring language corresponding to the target abstract syntax tree.
For example, in some embodiments of the present application, the abstract syntax tree (Abstract syntax tree, ash) is a tree representation of the abstract syntax structure of source code, with each node on the tree representing a structure in the source code. Specifically, result_str is split into individual smallest syntax elements (as a specific example of a word segmentation result), wherein the syntax element split is processed according to the GLSL syntax. Analyzing the split grammar units, and establishing a relation between the grammar units to obtain an initial ash (namely an initial abstract grammar tree). Then according to the initial ash and the version needing to be translated, translating to obtain the target ash (namely a target abstract syntax tree) of the loader language of other platform versions (as target platform types), and then generating target codes (as a specific example of target coloring language) corresponding to the target loader types according to the target ash.
It should be understood that the reason for the conversion between different loader languages is that the difference between the loader languages is that the keywords and the type names are different (for example, vec2 is a expression in GLSL, float2 is a expression in HLSL), and some writing rules are slightly different, but basically the grammar rules corresponding to the same level can be found, and translation can be achieved by the correspondence between grammars.
In order to reduce code redundancy and reduce memory occupation, in some embodiments of the present application, performing S220 may further include: functions associated with the shading language master function are placed in a first set and global variables associated with the shading language master function are placed in a second set.
For example, in some embodiments of the present application, before object code generation, functions to which all master functions are directly or indirectly referenced may be collected into set_func (as one specific example of a first set), and global variables to which master functions are directly or indirectly referenced are collected into set_var (as one specific example of a second set). Starting from the main function of the code string (the main function is the starting function of the program executing the coloring language, typically main function), the functions indirectly or directly used by the main function and the global variables are collected and put into set_func and set_var respectively. At the time of translation, only the functions and variables in the translations set_func and set_var need to be processed. Redundant codes can be removed through the processing of the step, and the occupation amount of physical memory and the occupation amount of GPU are reduced.
In some embodiments of the present application, special cases are also generally referred to in the translation process, and the following exemplary processes for handling the special cases are described as examples.
During translation, the writing of the same meaning of different versions may be different, so that the corresponding relation between the morphemes of different versions (particularly, the key of language, the type and the like) can be saved in the code, and the corresponding relation is saved in different arrays, and the different arrays are put in the same position. If there is no word with other writing that can be replaced, this position is marked error.
In one embodiment, for the case where the word (or string) of the semantic meaning currently required to be translated does not exist in the language supported by the target platform type, a position flag error is encountered, and at this time, the exit is directly reported by mistake.
In another embodiment, when there is an unsupported function in the language of the target shading language to be translated, it is necessary to determine whether the remaining functions can be replaced. If so, then a replacement is performed (e.g., where multiple word senses may be translated into one word), otherwise an error-reporting process is performed. For example, the textegather function is supported in GLSL, not in gles 3.0 but supporting the texture function, the texture may implement the textegather similar function, and the textegather function may be replaced with the texture function for processing when translating gles 3.0.
In another embodiment, features that require unified processing in the target language (features that need to be processed by the same type of loader) may be automatically written to the loader (i.e., the target shading language) when they are generated. For example, when a high version of GLSL translates to gles310, where gles requires global int to higp requirements, "precision highp int" may be added directly after version writing.
It will be appreciated that in addition to the above-described several special cases, other special handling cases may exist in the translation process, and the embodiments of the present application are not limited thereto, and may be specifically adapted according to the actually encountered cases.
S240, determining a standard coloring language through the target coloring language, and packaging and storing.
In some embodiments of the present application, S240 may include: acquiring the standard coloring language by judging whether the target platform type is a drawing application program interface Vulkan platform; and converting the standard coloring language into a binary file, and packaging and storing the binary file into a target file.
For example, in some embodiments of the present application, for a particular Vulkan platform, a decision may be made first to retrieve the standard shading language and then to package the standard shading language. The specific mode of packing and storing is as follows: the generated loader file (as a specific example of a standard coloring language) is converted into a binary and put into a pack file (as a specific example of a target file). An xml file is arranged under the peer directory of the pack to record the information such as the name stored in the pack file, the position and the size in the pack file. When in use, the needed pack file can be found according to the xml file information. In the actual use process, the number of the loader files of one game scene can reach tens of thousands, and the files can be greatly reduced by putting the loader files into a pack for use, and the function of encrypting the files can be achieved.
In some embodiments of the present application, S240 may include: if the target platform type is the Vulkan platform, processing the target coloring language to generate a standard coloring language; and if the target platform type is not the Vulkan platform, taking the target coloring language as the standard coloring language.
For example, in some embodiments of the present application, for a specific Vulkan platform, a standard GLSL format loader file corresponding to the target shading language is obtained, and a glslangvalidder tool is used to compile the loader file to generate a spv file (pair-v file, that is, a shading language file used by Vulkan). The GLSL syntax can be re-checked by using the glslangValidator tool, which is a GLSL reference compiler customized by the OpenGL standard custom official Khronos Group, to perform the final spv compilation. If the compiling fails, the exiting program does not carry out the next packing storage processing, and gives error prompt to the user (or programmer), and the user can continue compiling after modifying. And if the compiling is successful, the next step of packing and storing operation is continued. If the target coloring language is the Vulkan platform, the target coloring language is the final generated loader file.
The implementation of the above-described "path splicing function processing" is exemplarily described below with reference to fig. 3.
In some embodiments of the present application, it is necessary to prepare the function library before performing the path splicing function processing. Specifically, the user can customize the function library according to the requirement, and the function library can comprise function libraries of different platforms. Because the implementation functions of the same rendering effect are written in different platforms or versions, function libraries of different platforms and different versions can be created. For example, for lighting effects, if light-chasing is supported, light-chasing can be implemented, and light-chasing features can only be supported in high-version languages, so low-version ones are implemented in other ways. And the folder directory where the function library is located can be written into a corresponding configuration file, and different functions can be called when the function library is used. If the user needs to use the files in the function libraries, the user does not need to write a lengthy absolute path, and only needs to write a relative path when referring. For example: the version number of SladerLib# is established under the c \A\B\folder (the name is not added with a specific version number, or a function library which can be used by any version), and the function file is placed under the SladerLib folder after the c \A\B\file is placed. For example, when writing in a loader, the following writing method is adopted:
#include“ShaderLib\shaderFuncTest.h”;
when writing in include, the version number is not required to be written, and the judgment and analysis of the version are completed by a loader analyzer. The suffix of the file is not limited and is a readable text file. The library catalog ShaderLib can be provided with subfolders, and relative paths of the ShaderLib files are written.
Referring to fig. 3, fig. 3 is a flowchart of a method for processing a path splicing function according to some embodiments of the present application, where the method for processing a path splicing function includes:
s310, a writing path of the header file is acquired.
For example, as a specific example of the present application, a header_str path (i.e., a writing path) is input.
S320, judging whether the writing path is in the function library, if so, executing S350, otherwise, executing S330.
For example, as a specific example of the present application, it is determined whether the header_str path is in the function library. The judging mode is as follows: and splicing all function library catalogues and public library catalogues of the current version number with the Header_str one by one, searching whether spliced paths exist or not, outputting spliced paths if the paths exist, and outputting the spliced paths as absolute paths subsequently. Otherwise, the following determination is continued.
S330, judging whether the writing path is a relative path, if so, executing S350, otherwise, executing S340.
For example, as a specific example of the present application, the header_str is determined by performing the relative path, that is, the folder path where the current Header file is located and the header_str are spliced, querying whether the currently spliced path exists, if so, outputting the spliced path, and if so, outputting the spliced path as an absolute path. Otherwise, continuing the next step of judgment.
S340, judging whether the writing path is an absolute path, if so, executing S360, otherwise, outputting Error.
For example, as a specific example of the present application, an absolute path determination is made on a header_str, directly querying whether a current path exists for the header_str, and if so, directly outputting the absolute path subsequently.
S350, outputting the splicing path.
S360, outputting an absolute path.
The specific process of handling coloring languages provided in some embodiments of the present application is described below by way of example in conjunction with fig. 4.
Referring to fig. 4, fig. 4 is a flowchart of a method for processing a coloring language according to some embodiments of the present application.
The above-described process is exemplarily set forth below.
S410, the GLSL file, the current shader type, the target platform type and the target shader type corresponding to the GLSL file are obtained.
For example, as a specific example of the present application, a GLSL file, a platform type, and a loader type, which are written to be completed according to the GLSL rule, are input into the terminal 100 so that the processing server 200 can acquire in time.
S420, adding macro definition rules corresponding to the target platform types.
For example, as a specific example of the present application, macro definition rules corresponding to platform types are added.
S430, reading and processing the GLSL file by utilizing the macro definition rule to obtain the code character string.
For example, as a specific example of the present application, the GLSL file is preprocessed according to the platform macro definition rule, and the header file and the macro definition are processed to obtain a code string.
S440, translating the code character strings according to the target platform type to generate a target coloring language corresponding to the target loader type.
For example, as a specific example of the present application, this code string is parsed out of the GLSL code abstract syntax tree (ash), and translated into the target shading language by a translator according to the ash and platform types and the loader version types.
S450, judging whether the target platform type is a Vulkan platform, if so, executing S460, otherwise, executing S470.
S460, compiling the target coloring language to generate a standard coloring language.
For example, as a specific example of the present application, for a vulkan platform, a corresponding version of GLSL is generated from the required loader version, and then a corresponding spv file (i.e., a standard coloring file) is generated using a glslangavalitter tool.
S470, taking the target coloring language as a standard coloring language.
S480, converting the standard coloring language into a binary file, and packaging and storing the binary file into a target file.
For example, as a specific example of the present application, a standard coloring language is binary packed and stored.
It will be appreciated that the specific implementation of S410 to S480 may refer to the method embodiments provided above, and detailed descriptions are omitted here as appropriate to avoid repetition.
From the method embodiments provided above, the present application can translate a specific GLSL language to other platforms and versions of the available loader language. The target language supports GLSL, HLSL, gles, metal and the like, so that cross-platform implementation of a rendering effect is realized, development manpower is greatly saved, and development efficiency is improved. Moreover, the function library in the GLSL is constructed and used, so that the function library can be shared and used, different compatibility of the same function name is realized, and the difficulty of high-to-low version translation (or translation) is simplified. The generated loader file is converted into binary stream to be packed and put into the pack file for use, so that the file structure is optimized, the loader file is encrypted to a certain extent, and the safety is improved.
Referring to fig. 5, fig. 5 illustrates a block diagram of an apparatus for processing a coloring language according to some embodiments of the present application. It should be understood that the apparatus for processing a coloring language corresponds to the above method embodiments, and is capable of performing the steps involved in the above method embodiments, and specific functions of the apparatus for processing a coloring language may be referred to the above description, and detailed descriptions thereof are omitted herein as appropriate to avoid redundancy.
The apparatus for processing a shading language of fig. 5 comprises at least one software functional module capable of being stored in a memory in the form of software or firmware or being solidified in the apparatus for processing a shading language, the apparatus for processing a shading language comprising: an input module 510, configured to determine parameters to be processed, where the parameters to be processed include: the method comprises the steps of coloring a language GLSL file, a current shader loader type, a target platform type and a target loader type corresponding to the GLSL file; a preprocessing module 520, configured to preprocess the GLSL file to obtain a code string; a generating module 530, configured to translate the code string according to the target platform type, and generate a target coloring language corresponding to the target loader type; and the packaging storage module 540 is used for determining a standard coloring language through the target coloring language and performing packaging storage.
It will be clear to those skilled in the art that, for convenience and brevity of description, reference may be made to the corresponding procedure in the foregoing method for the specific working procedure of the apparatus described above, and this will not be repeated here.
Some embodiments of the present application also provide a computer readable storage medium having stored thereon a computer program, which when executed by a processor, may implement operations of the method corresponding to any of the above-described methods provided by the above-described embodiments.
Some embodiments of the present application further provide a computer program product, where the computer program product includes a computer program, where the computer program when executed by a processor may implement operations of a method corresponding to any of the foregoing methods provided by the foregoing embodiments.
As shown in fig. 6, some embodiments of the present application provide an electronic device 600, the electronic device 600 comprising: memory 610, processor 620, and a computer program stored on memory 610 and executable on processor 620, wherein processor 620 may implement a method as in any of the embodiments described above when reading a program from memory 610 and executing the program via bus 630.
The processor 620 may process the digital signals and may include various computing structures. Such as a complex instruction set computer architecture, a reduced instruction set computer architecture, or an architecture that implements a combination of instruction sets. In some examples, the processor 620 may be a microprocessor.
Memory 610 may be used for storing instructions to be executed by processor 620 or data related to execution of the instructions. Such instructions and/or data may include code to implement some or all of the functions of one or more modules described in embodiments of the present application. The processor 620 of the disclosed embodiments may be configured to execute instructions in the memory 610 to implement the methods shown above. Memory 610 includes dynamic random access memory, static random access memory, flash memory, optical memory, or other memory known to those skilled in the art.
The foregoing is merely exemplary embodiments of the present application and is not intended to limit the scope of the present application, and various modifications and variations may be suggested to one skilled in the art. Any modification, equivalent replacement, improvement, etc. made within the spirit and principles of the present application should be included in the protection scope of the present application. It should be noted that: like reference numerals and letters denote like items in the following figures, and thus once an item is defined in one figure, no further definition or explanation thereof is necessary in the following figures.
The foregoing is merely specific embodiments of the present application, but the scope of the present application is not limited thereto, and any person skilled in the art can easily think about changes or substitutions within the technical scope of the present application, and the changes and substitutions are intended to be covered by the scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.
It is noted that relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.

Claims (8)

1. A method of processing a coloring language, comprising:
determining a parameter to be processed, wherein the parameter to be processed comprises: the method comprises the steps of coloring a language GLSL file, a current shader loader type, a target platform type and a target loader type corresponding to the GLSL file;
preprocessing the GLSL file to obtain a code character string;
translating the code character string according to the target platform type to generate a target coloring language corresponding to the target loader type;
determining a standard coloring language through the target coloring language, and packaging and storing;
the preprocessing the GLSL file to obtain a code string includes:
reading character strings in the GLSL file by utilizing macro definition rules corresponding to the target platform types, replacing and analyzing words related to the macro definition rules, and then putting the words into the code character strings; deleting irrelevant codes by using the macro definition rules;
and acquiring a header file containing the include key words by using the macro definition rule, and confirming that a processed header file absolute path corresponding to the header file exists in the include Dirs set in the code character string.
2. The method of claim 1, wherein translating the code string according to the target platform type to generate a target shading language corresponding to the target loader type comprises:
dividing the code character string according to GLSL grammar to obtain word segmentation result;
carrying out grammar analysis on the word segmentation result to obtain an initial abstract grammar tree;
translating the initial abstract syntax tree into a target abstract syntax tree corresponding to a target loader type of the target platform type;
generating the target coloring language corresponding to the target abstract syntax tree.
3. The method of claim 2, wherein prior to the generating the target shading language corresponding to the target abstract syntax tree, the method further comprises:
functions associated with the shading language master function are placed in a first set and global variables associated with the shading language master function are placed in a second set.
4. The method of claim 1, wherein said determining a standard shading language from said target shading language and storing in a package, comprises:
acquiring the standard coloring language by judging whether the target platform type is a drawing application program interface Vulkan platform;
and converting the standard coloring language into a binary file, and packaging and storing the binary file into a target file.
5. The method of claim 4, wherein the obtaining the standard shading language by determining whether the target platform type is a drawing application program interface Vulkan platform comprises:
if the target platform type is the Vulkan platform, processing the target coloring language to generate a standard coloring language;
and if the target platform type is not the Vulkan platform, taking the target coloring language as the standard coloring language.
6. An apparatus for processing a coloring language, wherein the apparatus is for performing the method of claim 1, the apparatus comprising:
the input module is used for determining parameters to be processed, wherein the parameters to be processed comprise: the method comprises the steps of coloring a language GLSL file, a current shader loader type, a target platform type and a target loader type corresponding to the GLSL file;
the preprocessing module is used for preprocessing the GLSL file to obtain a code character string;
the generation module is used for translating the code character strings according to the target platform type and generating a target coloring language corresponding to the target loader type;
and the packaging storage module is used for determining a standard coloring language through the target coloring language and packaging and storing the standard coloring language.
7. A computer readable storage medium, characterized in that the computer readable storage medium has stored thereon a computer program, wherein the computer program when run by a processor performs the method according to any of claims 1-5.
8. An electronic device comprising a memory, a processor, and a computer program stored on the memory and running on the processor, wherein the computer program when run by the processor performs the method of any one of claims 1-5.
CN202311560320.8A 2023-11-22 2023-11-22 Method and device for processing coloring language, storage medium and electronic equipment Active CN117270962B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311560320.8A CN117270962B (en) 2023-11-22 2023-11-22 Method and device for processing coloring language, storage medium and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311560320.8A CN117270962B (en) 2023-11-22 2023-11-22 Method and device for processing coloring language, storage medium and electronic equipment

Publications (2)

Publication Number Publication Date
CN117270962A CN117270962A (en) 2023-12-22
CN117270962B true CN117270962B (en) 2024-02-09

Family

ID=89208452

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311560320.8A Active CN117270962B (en) 2023-11-22 2023-11-22 Method and device for processing coloring language, storage medium and electronic equipment

Country Status (1)

Country Link
CN (1) CN117270962B (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2009059110A (en) * 2007-08-30 2009-03-19 Toshiba Corp Information processor and program
CN111091612A (en) * 2019-10-09 2020-05-01 中国船舶重工集团公司第七0九研究所 Coloring language machine code generation method and device of abstract object code architecture
WO2021253641A1 (en) * 2020-06-15 2021-12-23 完美世界(北京)软件科技发展有限公司 Shading language translation method
CN114816972A (en) * 2021-01-22 2022-07-29 腾讯科技(深圳)有限公司 Coloring language testing method and device, electronic equipment and storage medium

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8203558B2 (en) * 2008-01-28 2012-06-19 Apple Inc. Dynamic shader generation

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2009059110A (en) * 2007-08-30 2009-03-19 Toshiba Corp Information processor and program
CN111091612A (en) * 2019-10-09 2020-05-01 中国船舶重工集团公司第七0九研究所 Coloring language machine code generation method and device of abstract object code architecture
WO2021253641A1 (en) * 2020-06-15 2021-12-23 完美世界(北京)软件科技发展有限公司 Shading language translation method
CN114816972A (en) * 2021-01-22 2022-07-29 腾讯科技(深圳)有限公司 Coloring language testing method and device, electronic equipment and storage medium

Also Published As

Publication number Publication date
CN117270962A (en) 2023-12-22

Similar Documents

Publication Publication Date Title
US9086931B2 (en) System for translating diverse programming languages
CN108139891B (en) Method and system for generating suggestions to correct undefined token errors
US9965259B2 (en) System for translating diverse programming languages
US8407667B2 (en) Inferring missing type information for reflection
US6434742B1 (en) Symbol for automatically renaming symbols in files during the compiling of the files
US8099721B2 (en) Parsing of declarations in all branches of preprocessor conditionals
US8239823B2 (en) Generating libraries for reflection without project compilation
CN110502227B (en) Code complement method and device, storage medium and electronic equipment
US20130152061A1 (en) Full fidelity parse tree for programming language processing
US10303467B2 (en) Target typing-dependent combinatorial code analysis
CN112379917B (en) Browser compatibility improving method, device, equipment and storage medium
CN115509514B (en) Front-end data simulation method, device, equipment and medium
CN114153459A (en) Interface document generation method and device
CN111651165A (en) Integration method of programming language, programming software system and electronic device
CN107463421B (en) Compiling and executing method and system of static flow model
CN109947711B (en) Automatic multi-language file management method in IOS project development process
CN111352631B (en) Interface compatibility detection method and device
CN117270962B (en) Method and device for processing coloring language, storage medium and electronic equipment
CN111475150A (en) Cross-language binding method, device, equipment and storage medium
CN116595967A (en) Natural language rule writing method based on text and related device
CN111258802A (en) Method for capturing application program crash information and related equipment
KR102614967B1 (en) Automation system and method for extracting intermediate representation based semantics of javascript
CN114816356A (en) System and method for generating HTTP request code based on interface document
CN110737431B (en) Software development method, development platform, terminal device and storage medium
CN113687833A (en) Hybrid compiling method, hybrid compiling system, compiler, and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant