Shader using method based on multiple platforms and related equipment
A shader and multi-platform technology, applied in the field of image processing, can solve problems such as complex cross-platform shader conversion
Pending Publication Date: 2022-04-15
0 Cites 0 Cited by
AI-Extracted Technical Summary
Problems solved by technology
 The technical problem to be solved by the present invention is that the conversion of the existing cross-platform shaders is relativ...
The invention discloses a shader using method based on multiple platforms and related equipment. The method comprises the following steps: acquiring an initial shader to be processed; according to a preset conversion format, converting the initial shader into a plurality of shader files corresponding to the shader format; generating a configuration file corresponding to the initial shader according to the first attribute value of the shader file and the second attribute value of the initial shader; when a rendering instruction is detected, retrieving the configuration file according to a shader format in the rendering instruction to obtain a target attribute value corresponding to the rendering format; according to the second attribute value, performing parameter configuration on a target shader corresponding to the rendering instruction to obtain a rendered shader; and based on the rendering shader, rendering a rendering file corresponding to the rendering instruction. According to the invention, convenient rendering can be realized on different rendering platforms.
Version controlSoftware design
ShaderMechanical engineering +2
- Experimental program(1)
 The present invention provides a method of using a multi-platform shader, in order to make the objects, technical solutions, and effects of the present invention, the following detailed description will be described in detail below with reference to the accompanying drawings. It will be appreciated that the specific embodiments described herein are intended to explain the invention and is not intended to limit the invention.
 Those skilled in the art will appreciate that unless specifically declared, the singular form "one", "one", "" "and" "", and "" "can also include multiple forms. It should be further understood that the phrase "comprising" in the specification of the present invention means that there is the features, integers, steps, operations, elements, and / or components, but do not exclude presence or addition of one or more other features. Integral, steps, operations, components, components, and / or groups. It should be understood that when the components are "connected" or "coupled" to another element, it can be directly connected or coupled to other elements, or there may be intermediate elements. Moreover, "connection" or "coupled" used here may include a wireless connection or wireless coupling. The wording "and / or" including one or more associated listed items and all combinations are all combined.
 Those skilled in the art will appreciate that all terms (including technical terms and scientific terms) used herein, unless otherwise defined. It should also be understood that those terms defined in a general dictionary should be understood to have meaningful meaning with the meaning of the context of the prior art, and unless it is a particular definition as it is, it will not be desirably or too The formal meaning is explained.
 Such as figure 1 As shown, the implementation provides a multi-platform-based coloring method for easy description, as a common server as an execution body, the server here is a device with data processing functions such as a tablet, computer, etc. Multi-platform-based coloring method includes the following steps:
 S10, get the initial shader to be processed.
 Specifically, the initial shader is a shader that can be used on a platform, the format of the initial shader can be any common shader, such as a shader in the GLSL format written in the opnegl shader language.
 The main function of the shader conversion program can be accepted by cmake, and the main function of the shader converter can accept multiple input parameters. These input parameters have external customizations that can specify input file paths, output file paths, input file names, and output file names. The following is an example of the parameter of the input and output:
 · InventPath: Enter the vertex shader file resource path;
 · Infragpath: Enter the fragment shader file resource path;
 · OUTVERTNAME: Output vertex shader file name;
 · OUTFRAGNAME: Output fragment shader file name;
 · OutjsonName: Output shader configuration file name;
 · OUTPATHNAME: Coloring resources and profile output paths.
 Such as figure 2 As shown, get the input file path and the input file name, the shader conversion project acquires the initial shader. Therefore, first obtain the shader name and shader address to be processed, then obtain the initial shader based on the shader name and the shader address.
 S20, according to the preset conversion format, convert the initial shader to a plurality of shader files corresponding to the shader format.
 Specifically, the initial shader needs to be converted as a conversion format as a conversion format, which is a shader than a shader platform, such as METAL, ESSL, HLSL, and SPIRV.
 After obtaining the initial shader (color matching of the GLSL format), it needs to be converted. There are many coloring modes that convert a format shader to another format, any shadlock conversion method can be used in this scheme.
 In order to facilitate the conversion of shader files, a shader is provided in this embodiment. In this embodiment, the open source library Glslang and Spirv_cross provided by the KHRONOSGROUP organization were introduced. After getting the initial shader, convert the initial shader into SPV metadata through the GLSLANG library, and written to the corresponding .spv file. The SPV metadata is then entered to the SPIRV-CROSS converter, and the SPIRV-CROSS converter can convert files in the SPIR-V format to other format files, so the SPV metadata can be converted into a shader file corresponding to the conversion format. Such as image 3 As shown, the language type of the input initial shader is GLSL. After the SPIRV-CROSS conversion, the output language type includes METAL, ELSL, and HLSL, the file format of the shader file is Metal, GLSL, and HLSL.
 S30, generates a configuration file corresponding to the initial shader based on the first attribute value of the shader file and the second attribute value of the initial shader.
 Specifically, after the conversion-converted shader file, the shader's name, function name, shader phase, etc. can be obtained. For example, the format of the shader file is HLSL, its file name is "Vertex_1_tex_map.vert.hlsl", the call function name is the main function, its shader phase is the vertices (VERT) phase. Among them, the shader stage also includes Frag (fragment), Geom (geometry), TESC (segmentation control), TESE (subdivision calculation), CoMP (calculated) and other stages. The file name determines that the name of the shader that needs to be rendered, the function name determines which function to enter the content to be rendered when rendering, the shader phase is used to define the main purpose of this shader, which can determine How to select and call the shader file when subsequent rendering, and therefore, these can determine the information used by the shader file as the first attribute value of the shader file.
 The initial shader has a certain processing logic and processing parameters inside the initial shader, and these processing logic and processing parameters do not necessarily retain after the shader conversion. Therefore, in order to ensure that the converted shader file can be processed according to the processing logic and parameters of the initial shader, the processing logic and processing parameters are used as the second attribute value. The second attribute value can include a Layout List, a texture array, a Uniform block (UNIFORMBLOCK).
 The second attribute value can be extracted when it acquires the initial shader, and the first attribute value can be generated when different shader files generates. After getting the first property value and the second property value, you can get the configuration file in a preset empty file in a certain writing rule.
 It is worth noting that empty files do not refer to files with no content, but it has been file descriptions, but no files that have not been written to the first property value and the second attribute value, such as Figure 4 As shown, there is a part of the file description with a part of the first attribute value and the second attribute value written in an empty file. The shader conversion project employed in this embodiment is a C ++ language, and therefore, an example of the configuration file is displayed in the C ++ language. Since the profile is too long, it is described in several paragraphs.
 The front part of the configuration file (first line to the fourth line) is the file instructions, and then describes the first property value of the few shaders of GLSL, GLSLES, HLSL, METAL, SPIRV, and then describes the list of the Layout list. Texture arrays and concrete information of UNIFORM blocks.
 In order to facilitate subsequent search retries, in this scenario, the profile is formatted in JSON format. JSON is a lightweight data exchange format, easy to read and write, and it is also easy to analyze and generate, as long as JSON's grammar The rules, the definition of data parameters can be free to play. Such as image 3 As shown, the configuration file can be generated by TPROGRAM editing.
 S40, when the rendering instruction is detected, the configuration file is retrieved based on the shader format in the rendering instruction to obtain the target attribute value corresponding to the rendering format.
 Specifically, when you need to render a rendering object, generate rendering instructions, the rendering command contains information that requires rendered objects, which uses information on the shaders for rendering. When the rendering instruction is detected, the configuration file is retrieved according to the shader format in the rendering command, and the first attribute value corresponding to it is obtained, that is, the target property value.
 For example, the shader format in the current rendering instruction is HLSL, retrieves the configuration file directly, only one HLSL shader in the configuration file, so the first property value of HLSL is used as the target attribute value.
 Further, the color filter file in the HLSL format contains a vertex shader and fragment shader. In the rendering instruction, the rendering type, the rendering type includes vertex rendering, fragment rendering, etc. Therefore, when the target attribute value is further determined, the configuration file is retrieved according to the shader format in the rendering command, and the corresponding first attribute value to the corresponding first attribute value is used as the candidate attribute value. According to the rendering type in the rendering command, determine the target attribute value in the candidate attribute value.
 S50, according to the second attribute value, the target shader corresponding to the rendering command is configured to obtain a rendered shader.
 Specifically, after the target attribute value is determined, the color filter file corresponding to the target property value can be called based on the target attribute value, that is, the target shader. At the same time, the specific parameters in the target shader need to be configured according to the second attribute value. Such as Figure 7 ~ 9 As shown in the list, the specific information of the Layout list, the texture array, and the Uniform block is recorded in the configuration file, which can assign the second attribute value to the target shader to obtain the rendering shader.
In this embodiment, the Layout list includes a vertex shader property object location (index), a property name (Name), data type (type), and data type description, which includes "aposition" and "atexattr1", The data type can include a type such as a floating point. Texture arrays include Texture Binding, Location (INDEX), Texture Name (Name), Texture Type (Type), and Textesc. Uniform block information includes information of several plurality of Uniform blocks, each information including binding, name (Name), block, uniform block parameters (Parameters). Uniform block parameters include block properties (NAME), offset, data type (Type), data type description, default (Value).
 Further, when the parameter configuration is performed, there are some parameters, such as Figure 9 The Uniform block section, the value value can be empty, which means the default value in the initial shader. However, when the target shader is configured, the default value of the target shader is used as the second attribute value of the target shader when the corresponding second attribute value is null value.
 Further, the target shader can be a shader file in a shader file, or another self-compiled shader. For example, a self-compilation shader can be created in advance, which can be connected to the interface of other shader files to tune the part of the other shader files, and when the rendering command corresponds to the self-compiled shader Based on the second attribute value, the parameter configuration of the self-compiled shader is completed.
 When the target shader includes self-compiling shaders, Figure 5 As shown, the first attribute value also includes a built-in shader, ie, whether the shader text is a coloring shader built into a self-compiled shader. If so, the shader text is no longer called, but directly using the built-in shader as a shader as a rendering.
 S60, rendering the rendering file corresponding to the rendering command based on the rendering shader.
 Specifically, due to a variety of formats of the conversion shader file, for the same rendering file, different types of shading files can be rendered to implement cross-platform rendering, and no longer need to compile them in multiple platforms. Both can be rendered.
 Based on the above-mentioned multi-platform color use method, the above-described invention also provides a multi-platform shaded use device, such as Figure 10 Show, including:
 The module 110 is acquired to obtain the initial shader to be processed;
 The conversion module 120 is configured to convert the initial shader to a plurality of shader files corresponding to the shader format according to a preset conversion format;
 Generating module 130 generates a profile corresponding to the initial shader according to the first attribute value of the shader file and the primary shader;
 The retrieval module 140 is used to retrieve the configuration file based on the coloring device format in the rendering instruction, and obtain the target attribute value corresponding to the rendering format;
 The configuration module 150 is configured to configure the target shader corresponding to the rendering command according to the second attribute value to obtain a rendered shader;
 The rendering module 160 is used to render the rendering file corresponding to the rendering command based on the rendering shader.
 The multi-platform-based coloring device is used, wherein the acquisition module 110 is specifically used:
 Get the shader name and shader address to be processed;
 The initial shader is acquired based on the shader name and the shader address.
 The retrieval module 140 is specifically used by:
 According to the shader format in the rendering instruction, the configuration file is retrieved, and the corresponding first attribute value is used as the candidate attribute value;
 Determine the target attribute value in the candidate attribute value based on the rendering type in the rendering instruction.
 The multi-platform-based coloring device is used, wherein the conversion module 120 is for:
 Convert the initial shader to SPV metadata and input the SPV metadata into a preset SPIRV-CROSS;
 Depending on the preset conversion format, control the SPIRV-CROSS to convert the SPV metadata into a shader file corresponding to the shader format.
 The multi-platform-based coloring device is used, wherein the format of the configuration file is a JSON format.
 The multi-platform-based coloring device is used, wherein the first attribute value includes a file name, a function name, whether it is a built-in shader and a shader phase.
 The multi-platform-based coloring device is used, wherein the second attribute value includes a Layout list, a texture array, and UNIFORM block information.
 Based on the above-mentioned multi-platform-based coloring method, the present invention also provides a terminal device, such as Figure 11 As shown, it includes at least one processor 20; display screen 21; and memory 22, may also include a communication interface 23 and a bus 24. The processor 20, the display screen 21, the memory 22, and the communication interface 23 can be completed with each other through the bus 24. The display 21 is set to display the user boot interface preset in the initial setting mode. Communication interface 23 can transmit information. The processor 20 can call the logic command in the memory 22 to perform the method in the above embodiment.
 Further, the logic commands in the above memory 22 can be implemented in the form of a software functional unit and as a stand-alone product sales or use, can be stored in a computer readable computer readable storage medium.
 The memory 22 can be set to a program command or module corresponding to a memory software program, a computer executable program, such as a method in the present disclosure embodiment. The processor 20 performs functional application and data processing by running the software program, command or module stored in the memory 22, that is, the method in the above embodiment is implemented.
 The memory 22 can include a storage program area and a storage data area, wherein the storage program area can store the operating system, at least one of the applications required; the storage data area can store data created according to the use of the terminal device. Further, the memory 22 can include a high speed random access memory, and may also include a non-volatile memory. For example, a U disk, mobile hard disk, read-only memory, RAM, Random Access Memory, RAM, a disk, or optical disk, can store a medium that can store program code, or a temporary Computer readable storage medium.
 Further, the specific process of the above-described computer readable storage medium and a plurality of command processors in the terminal device is loaded and executed in the above method, and it will not be described herein.
 It will be noted in that the above embodiment is intended to illustrate the technical solutions of the present invention, not to limit the invention; The technical solutions described in the foregoing examples are modified, or part of the technical features in which these modifications or replacements do not allow the nature of the corresponding technical solutions from the spirit and scope of the technical solutions of the present invention.
Description & Claims & Application Information
We can also present the details of the Description, Claims and Application information to help users get a comprehensive understanding of the technical details of the patent, such as background art, summary of invention, brief description of drawings, description of embodiments, and other original content. On the other hand, users can also determine the specific scope of protection of the technology through the list of claims; as well as understand the changes in the life cycle of the technology with the presentation of the patent timeline. Login to view more.