Shader code compilation method, device, computer equipment and storage medium
By obtaining shader codes containing target shader codes for different rendering platforms and generating compilation results for respective platforms, the problem in the existing technology that developers need to write codes for each platform is solved, and efficient multi-platform shader code compilation is achieved.
Patent Information
- Application Number
- CN202111444221.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-30
- Publication Date
- 2025-01-24
- Estimated Expiration
- 2041-11-30
AI Technical Summary
In the prior art, developers need to write shader codes for each device platform and generate corresponding scene rendering data, resulting in high time and labor costs and low efficiency.
Provide a method of compiling the color device code. By obtaining the color device code that contains the target color device code suitable for different rendering platforms, the compilation result of the respective platform is generated. Specific steps include obtaining the color device code to be compiled. Based on the first and second target color device code and the third target color device code to generate the corresponding compilation results.
This method can save time costs and labor costs, improve development efficiency, and realize the compilation operation of the color device code of multiple rendering platforms.
Smart Images

Figure CN114115905B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technology, and in particular to a shader code compilation method, device, computer equipment and storage medium. Background Art
[0002] Currently, with the development of device platforms, there are multiple platforms including Microsoft's PC, Apple's Metal, Android's Adreno and Mali.
[0003] In the related art, developers often need to write a set of shader codes for each platform respectively, and generate scene rendering data for scene rendering on each platform after compilation. This method takes high time and labor costs and is inefficient. Summary of the invention
[0004] The embodiments of the present disclosure at least provide a method, apparatus, computer device and storage medium for compiling shader code.
[0005] In a first aspect, an embodiment of the present disclosure provides a method for compiling a shader code, comprising:
[0006] Obtain shader code to be compiled; wherein the shader code includes a first target shader code applicable to a first rendering platform, a second target shader code applicable to a second rendering platform, and a third target shader code applicable to both the first rendering platform and the second rendering platform; the first rendering platform and the second rendering platform are used to perform content rendering under the same type of operating system; the rendering feature information in the first geometry buffer of the first rendering platform referred to by the third target shader code is the same as the rendering feature information in the second geometry buffer of the second rendering platform referred to by the third target shader code;
[0007] Based on the first target shader code and the third target shader code, a first compilation result corresponding to the first rendering platform is generated; and based on the second target shader code and the third target shader code, a second compilation result corresponding to the second rendering platform is generated.
[0008] In a possible implementation, the rendering feature information in the first geometry buffer includes object self-luminous information, fog effect information, normal information, roughness information, metal rendering information, reflectivity information, occlusion information, environment information, shadow information, and fog effect intensity information; the rendering feature information in the second geometry buffer includes object self-luminous information, fog effect information, normal information, roughness information, metal rendering information, reflectivity information, occlusion information, environment information, and depth information.
[0009] In one possible implementation, the rendering feature information referred to by the third target shader code includes object self-luminous information, fog effect information, normal information, roughness information, metal rendering information, reflectivity information, and occlusion information; the rendering feature information referred to by the first target shader code includes environment information, shadow information, and fog effect intensity information; and the rendering feature information referred to by the second target shader code includes environment information and depth information.
[0010] In a possible implementation, the first target shader code and the second target shader code are located in a target code section in the shader code to be compiled, and the shader code in the target code section is annotated by a preprocessing instruction Pragma to indicate that the compilation of the first target shader code and the compilation of the second target shader code are respectively performed in the target code section.
[0011] In a possible implementation, the first rendering platform is the Adreno platform of the Android operating system, and the first compilation result is used to perform delayed rendering on the Adreno platform; the second rendering platform is the Mali platform of the Android operating system, and the second compilation result is used to perform delayed rendering on the Mali platform.
[0012] In a possible implementation manner, the shader code further includes a fourth target shader code applicable to a third rendering platform and a fifth target shader code applicable to a fourth rendering platform;
[0013] The method further comprises:
[0014] Based on the fourth target shader code, a third compilation result corresponding to the third rendering platform is generated; and based on the fifth target shader code, a fourth compilation result corresponding to the fourth rendering platform is generated.
[0015] In a possible implementation, the third rendering platform is a PC platform, and the third rendering platform is used to render content under a Microsoft operating system; the fourth rendering platform is a Metal platform, and the fourth rendering platform is used to render content under an iOS operating system;
[0016] When the third rendering platform is a PC platform and the fourth rendering platform is a Metal platform, the fourth target shader code is the same as the fifth target shader code.
[0017] In a second aspect, an embodiment of the present disclosure further provides a shader code compilation device, comprising:
[0018] an acquisition module, configured to acquire shader codes to be compiled; wherein the shader codes include a first target shader code applicable to a first rendering platform, a second target shader code applicable to a second rendering platform, and a third target shader code applicable to both the first rendering platform and the second rendering platform; the first rendering platform and the second rendering platform are used to perform content rendering under the same type of operating system; the rendering feature information in a first geometry buffer of the first rendering platform referred to by the third target shader code is the same as the rendering feature information in a second geometry buffer of the second rendering platform referred to by the third target shader code;
[0019] A generation module is used to generate a first compilation result corresponding to the first rendering platform based on the first target shader code and the third target shader code; and to generate a second compilation result corresponding to the second rendering platform based on the second target shader code and the third target shader code.
[0020] In a possible implementation, the rendering feature information in the first geometry buffer includes object self-luminous information, fog effect information, normal information, roughness information, metal rendering information, reflectivity information, occlusion information, environment information, shadow information, and fog effect intensity information; the rendering feature information in the second geometry buffer includes object self-luminous information, fog effect information, normal information, roughness information, metal rendering information, reflectivity information, occlusion information, environment information, and depth information.
[0021] In one possible implementation, the rendering feature information referred to by the third target shader code includes object self-luminous information, fog effect information, normal information, roughness information, metal rendering information, reflectivity information, and occlusion information; the rendering feature information referred to by the first target shader code includes environment information, shadow information, and fog effect intensity information; and the rendering feature information referred to by the second target shader code includes environment information and depth information.
[0022] In a possible implementation, the first target shader code and the second target shader code are located in a target code section in the shader code to be compiled, and the shader code in the target code section is annotated by a preprocessing instruction Pragma to indicate that the compilation of the first target shader code and the compilation of the second target shader code are respectively performed in the target code section.
[0023] In a possible implementation, the first rendering platform is the Adreno platform of the Android operating system, and the first compilation result is used to perform delayed rendering on the Adreno platform; the second rendering platform is the Mali platform of the Android operating system, and the second compilation result is used to perform delayed rendering on the Mali platform.
[0024] In a possible implementation manner, the shader code further includes a fourth target shader code applicable to a third rendering platform and a fifth target shader code applicable to a fourth rendering platform;
[0025] The generation module is also used for:
[0026] Based on the fourth target shader code, a third compilation result corresponding to the third rendering platform is generated; and based on the fifth target shader code, a fourth compilation result corresponding to the fourth rendering platform is generated.
[0027] In a possible implementation, the third rendering platform is a PC platform, and the third rendering platform is used to render content under a Microsoft operating system; the fourth rendering platform is a Metal platform, and the fourth rendering platform is used to render content under an iOS operating system;
[0028] When the third rendering platform is a PC platform and the fourth rendering platform is a Metal platform, the fourth target shader code is the same as the fifth target shader code.
[0029] In a third aspect, an embodiment of the present disclosure further provides a computer device, comprising: a processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the computer device is running, the processor and the memory communicate via the bus, and when the machine-readable instructions are executed by the processor, the steps of the above-mentioned first aspect, or any possible implementation of the first aspect are performed.
[0030] In a fourth aspect, an embodiment of the present disclosure further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the above-mentioned first aspect or any possible implementation of the first aspect are executed.
[0031] The shader code compilation method, apparatus, computer equipment and storage medium provided in the embodiments of the present disclosure obtain shader code including a first target shader code applicable to a first rendering platform, a second target shader code applicable to a second rendering platform, and a third target shader code applicable to both the first rendering platform and the second rendering platform; based on the first target shader code and the third target shader code, a first compilation result corresponding to the first rendering platform is generated; and based on the second target shader code and the third target shader code, a second compilation result corresponding to the second rendering platform is generated. In this way, by writing a set of shader codes and compiling them, the shader code compilation operation under multiple rendering platforms can be completed, thereby saving time and labor costs and improving development efficiency.
[0032] In order to make the above-mentioned objectives, features and advantages of the present disclosure more obvious and easy to understand, preferred embodiments are specifically cited below and described in detail with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the following is a brief introduction to the drawings required for use in the embodiments. The drawings herein are incorporated into the specification and constitute a part of the specification. These drawings illustrate embodiments consistent with the present disclosure and are used together with the specification to illustrate the technical solutions of the present disclosure. It should be understood that the following drawings only illustrate certain embodiments of the present disclosure and should not be regarded as limiting the scope. For ordinary technicians in this field, other relevant drawings can also be obtained based on these drawings without creative work.
[0034] Figure 1 A flowchart of a shader code compilation method provided by an embodiment of the present disclosure is shown;
[0035] Figure 2 A schematic diagram of the architecture of a shader code compiling device provided by an embodiment of the present disclosure is shown;
[0036] Figure 3 A schematic diagram of the structure of a computer device provided by an embodiment of the present disclosure is shown. DETAILED DESCRIPTION
[0037] In order to make the purpose, technical scheme and advantages of the embodiments of the present disclosure clearer, the technical scheme in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are only part of the embodiments of the present disclosure, rather than all of the embodiments. The components of the embodiments of the present disclosure generally described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present disclosure provided in the drawings is not intended to limit the scope of the present disclosure for protection, but merely represents the selected embodiments of the present disclosure. Based on the embodiments of the present disclosure, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present disclosure.
[0038] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, further definition and explanation thereof is not required in subsequent drawings.
[0039] The term "and / or" herein only describes an association relationship, indicating that three relationships may exist. For example, A and / or B may represent the following three situations: A exists alone, A and B exist at the same time, and B exists alone. In addition, the term "at least one" herein represents any combination of at least two of any one or more of a plurality of. For example, including at least one of A, B, and C may represent including any one or more elements selected from the set consisting of A, B, and C.
[0040] Research has found that in related technologies, developers often need to write a set of shader codes for each platform, and generate scene rendering data for scene rendering on each platform after compilation. This method has high time and labor costs and is inefficient.
[0041] Based on the above research, the present disclosure provides a shader code compilation method, apparatus, computer equipment and storage medium, by obtaining a shader code including a first target shader code applicable to a first rendering platform, a second target shader code applicable to a second rendering platform, and a third target shader code applicable to both the first rendering platform and the second rendering platform; based on the first target shader code and the third target shader code, a first compilation result corresponding to the first rendering platform is generated; and based on the second target shader code and the third target shader code, a second compilation result corresponding to the second rendering platform is generated. In this way, by writing a set of shader codes and compiling them, the shader code compilation operation under multiple rendering platforms can be completed, thereby saving time and labor costs and improving development efficiency.
[0042] To facilitate understanding of the present embodiment, a shader code compilation method disclosed in the embodiment of the present disclosure is first introduced in detail. The execution subject of the shader code compilation method provided in the embodiment of the present disclosure is generally a computer device with certain computing capabilities, and the computer device includes, for example: a terminal device or a server or other processing device, and the terminal device may be a user equipment (UE), a mobile device, a user terminal, etc. In some possible implementations, the shader code compilation method may be implemented by a processor calling a computer-readable instruction stored in a memory.
[0043] See also Figure 1 As shown, it is a flowchart of a shader code compilation method provided by an embodiment of the present disclosure, the method includes S101-S102, wherein:
[0044] S101: Obtain shader code to be compiled; wherein the shader code includes a first target shader code applicable to a first rendering platform, a second target shader code applicable to a second rendering platform, and a third target shader code applicable to both the first rendering platform and the second rendering platform; the first rendering platform and the second rendering platform are used to perform content rendering under the same type of operating system; the rendering feature information in a first geometry buffer of the first rendering platform referred to by the third target shader code is the same as the rendering feature information in a second geometry buffer of the second rendering platform referred to by the third target shader code.
[0045] S102: Generate a first compilation result corresponding to the first rendering platform based on the first target shader code and the third target shader code; and generate a second compilation result corresponding to the second rendering platform based on the second target shader code and the third target shader code.
[0046] The following is a detailed description of the above steps.
[0047] For S101, the first rendering platform may be the Adreno platform of the Android operating system; the second rendering platform may be the Mali platform of the Android operating system; the shader code may also include a fourth target shader code applicable to a third rendering platform, and a fifth target shader code applicable to a fourth rendering platform, the third rendering platform may be the PC platform of the Microsoft operating system, and the fourth rendering platform may be the Metal platform of the iOS operating system.
[0048] Specifically, the rendering feature information in the first geometry buffer includes at least one of object self-luminous information, fog effect information, normal information, roughness information, metal rendering information, reflectivity information, occlusion information, environment information, shadow information, and fog effect intensity information; the rendering feature information in the second geometry buffer includes at least one of object self-luminous information, fog effect information, normal information, roughness information, metal rendering information, reflectivity information, occlusion information, environment information, and depth information.
[0049] Exemplarily, the buffer data in the first geometry buffer may be as shown in Table 1 below:
[0050] Table 1
[0051] MRT0 blend add emission&Fog(R11G11B10) MRT1 encodeNormal.xy,roughness,metallic(scattering strength)(RGBA8) MRT2 albedo,occlusion(RGBA8) MRT3 envReflectionSlot,0,shadowMask,fogStrength(RGBA8)
[0052] In Table 1, MRT0 to MRT3 represent rendering targets 0 to 3. The rendering targets are video memory buffers used to render pixels. The shader can perform scene rendering through the rendering targets. The Multiple Render Targets (MRT) technology can perform scene rendering according to each rendering target at different stages of scene rendering through the binding relationship between the rendering feature information stored in the buffer and the rendering target, thereby improving the scene rendering efficiency.
[0053] Specifically, in the first row of Table 1, R11G11B10 indicates that the RT format when storing rendering feature information is R11G11B10 format, and the rendering feature information used by MRT0 is object self-luminous information emission and fog effect information Fog, and the fog effect information Fog includes fog effect color information FogColor and fog effect strength information FogStrength. When the geometry buffer stores the rendering feature information corresponding to MRT0, it can perform data processing on each rendering feature information according to a preset rule, and store the "emission*FogStrength+FogColor" obtained after the data processing, so that when the rendering feature information is used for vertex delayed rendering, the "emission*FogStrength+FogColor" stored in MRT0 is superimposed (summed) with the lighting color (lighting)*fog strength (FogStrength) by blend add, so as to perform fog effect rendering in the vertex rendering pipeline;
[0054] In the second row of Table 1, the RGBA8 indicates that the RT format for storing rendering feature information is the RGBA8 format, and the rendering feature information used by the MRT1 is the normal information encodeNormal.xy, the roughness information roughness, and the metal rendering information metallic (the scattering strength information scatteringstrength can be used when some materials do not use the metal rendering information);
[0055] In the third row of Table 1, the RGBA8 indicates that the RT format for storing rendering feature information is the RGBA8 format, and the rendering feature information used by the MRT2 is the reflectivity information albedo and the occlusion information occlusion. The albedo can be stored in the form of a scattering color map of the object surface, and the occlusion can be stored in the form of an ambient light occlusion map. The corresponding rendering feature information can be obtained by sampling the map;
[0056] In the fourth row of Table 1, the RGBA8 indicates that the RT format for storing rendering feature information is the RGBA8 format, the rendering feature information used by the MRT3 is the environment information envReflectionSlot, the shadow information shadowMask, and the fog effect strength information fogStrength, and 0 indicates a reserved bit.
[0057] Exemplarily, the buffer data in the second geometry buffer may be as shown in Table 2 below:
[0058] Table 2
[0059] MRT0 blend add emission&Fog(R11G11B10) MRT1 encodeNormal.xy,roughness,metallic(scattering strength)(RGBA8) MRT2 albedo,occlusion(RGBA8) MRT3 envReflectionSlot,depth(R32f)
[0060] In Table 2, the contents represented by MRT0~MRT2 are the same as those represented by MRT0~MRT2 in the above Table 1, which are not repeated here. In addition, in the 4th row of Table 2, the R32f indicates that the RT format for storing rendering feature information is the R32 floating point texture format, and the rendering feature information used by the MRT3 is the environment information envReflectionSlot and the depth information depth. When encoding, the envReflectionSlot can have 2 bits and the depth can have 30 bits, so that it can be completely encoded into the MRT3 with a data length of 32 bits (the data length of the R32f format is 32 bits).
[0061] Furthermore, through the buffer data in the above-mentioned first geometry buffer and the second geometry buffer, it can be known that the rendering feature information referred to by the third target shader code includes object self-luminous information, fog effect information, normal information, roughness information, metal rendering information, reflectivity information, and occlusion information (that is, the rendering feature information corresponding to the same MRT0~MRT2 in the first buffer and the second buffer), the rendering feature information referred to by the first target shader code includes environment information, shadow information, and fog effect intensity information (that is, the rendering feature information corresponding to MRT3 corresponding to the first buffer), and the rendering feature information referred to by the second target shader code includes environment information and depth information (that is, the rendering feature information corresponding to MRT3 corresponding to the second buffer).
[0062] In addition, when the third rendering platform is a PC platform and the fourth rendering platform is a Metal platform, the buffer data in the third geometry buffer of the third rendering platform referred to by the fourth target shader code and the buffer data in the fourth geometry buffer of the fourth rendering platform referred to by the fifth target shader code may be the same, and the buffer data in the third geometry buffer and the fourth geometry buffer may be as shown in Table 3 below:
[0063] Table 3
[0064] MRT0 blend add emission&Fog(R11G11B10) MRT1 RT1Depth(R32F) MRT2 encodeNormal.xy,roughness,metallic(scattering strength)(RGBA8) MRT3 albedo,occlusion(RGBA8) MRT4 envReflectionSlot,0,shadowMask,fogStrength(RGBA8)
[0065] In Table 3, the contents represented by MTR0, MTR2, MRT3, and MRT4 are respectively the same as those represented by MRT0, MTR1, MRT2, and MRT3 in Table 1 above, and are not repeated here. In addition, in the second row of Table 3, the R32f indicates that the RT format when storing the rendering feature information is the R32 floating point texture format, and the rendering feature information used by the MRT2 is the depth information depth. When encoding, the depth can have 32 bits, so that it can be completely encoded into the MRT2 with a data length of 32 bits (the data length of the R32f format is 32 bits).
[0066] In summary, by setting the rendering feature information in the geometry buffer for the rendering platforms corresponding to each operating system, the rendering effects of each rendering platform can be similar during delayed rendering, avoiding the situation where the rendering effects of the same rendering scene on different rendering platforms are significantly different.
[0067] In actual applications, since the rendering feature information of the geometric buffers corresponding to the first rendering platform and the second rendering platform are relatively similar, the shader code corresponding to the first rendering platform and the shader code corresponding to the second rendering platform are relatively similar. In order to improve code utilization, the shader code corresponding to the first rendering platform and the shader code corresponding to the second rendering platform can be merged for development. The merged shader code can include a first target shader code applicable to the first rendering platform, a second target shader code applicable to the second rendering platform, and a third target shader code applicable to both the first rendering platform and the second rendering platform.
[0068] In a possible implementation, the first target shader code and the second target shader code are located in a target code section in the shader code to be compiled, and the shader code in the target code section is annotated by a preprocessing instruction Pragma to indicate that the compilation of the first target shader code and the compilation of the second target shader code are respectively performed in the target code section.
[0069] Exemplarily, the shader code of the target code segment may be:
[0070] [DefinePragma(symbol: "gl_ext pls0ut SV_Target0 G_Target0 layout(r11f_g11f_b10f)......")]
[0071] In the above shader code, the compilation mode of rendering target 0 (i.e. Target0) can be set through the definition of Pragma macro. When compiling rendering target 0, the editing result of the first rendering platform is compiled, and SV_Target0 is translated into G_Target0 on the second rendering platform for compilation. The specific data structure of G_Target0 can be in the format of R11G11B10.
[0072] In this way, by marking the target code section with the Pragma macro, the compiler can compile the shader code according to the preset compilation method (that is, when compiling to the preset rendering target, translate it into the content of different rendering platforms for compilation to obtain two compilation results). At the target code section, a section of shader code will be used to compile the compilation results corresponding to the first rendering platform and the second rendering platform respectively; on the other hand, by taking different logical branches according to different rendering platforms during compilation, it is possible to avoid increasing memory for variants, save computing resources consumed when compiling shader code, and improve code compilation efficiency.
[0073] S102: Generate a first compilation result corresponding to the first rendering platform based on the first target shader code and the third target shader code; and generate a second compilation result corresponding to the second rendering platform based on the second target shader code and the third target shader code.
[0074] Here, the first compilation result is used for performing delayed rendering on the Adreno platform, and the second compilation result is used for performing delayed rendering on the Mali platform.
[0075] In a possible implementation, a third compilation result corresponding to the third rendering platform may be generated based on the fourth target shader code; and a fourth compilation result corresponding to the fourth rendering platform may be generated based on the fifth target shader code.
[0076] Among them, the third rendering platform is used for content rendering under the Microsoft operating system, for example, delayed rendering can be performed based on the third compilation result; the fourth rendering platform is used for content rendering under the iOS operating system, for example, delayed rendering can be performed based on the fourth compilation result.
[0077] Specifically, when performing the delayed rendering, the following two steps may be included:
[0078] In the first step, the scene in the area to be rendered can be rendered by storing the rendering feature information (such as normal vector, reflection coefficient, etc.) in the geometry buffer to achieve preliminary rendering of the area to be rendered; in the second step, the stored rendering feature information can be read from the geometry buffer, and the rendering content such as pixel color can be calculated based on the rendering feature information, so as to perform more refined scene rendering based on the calculation results, thereby achieving a more realistic scene rendering effect.
[0079] The shader code compilation method provided by the embodiment of the present disclosure obtains a shader code including a first target shader code applicable to a first rendering platform, a second target shader code applicable to a second rendering platform, and a third target shader code applicable to both the first rendering platform and the second rendering platform; based on the first target shader code and the third target shader code, a first compilation result corresponding to the first rendering platform is generated; and based on the second target shader code and the third target shader code, a second compilation result corresponding to the second rendering platform is generated. In this way, by writing a set of shader codes and compiling them, the shader code compilation operation under multiple rendering platforms can be completed, thereby saving time and labor costs and improving development efficiency.
[0080] Those skilled in the art will appreciate that, in the above method of specific implementation, the order in which the steps are written does not imply a strict execution order and does not constitute any limitation on the implementation process. The specific execution order of the steps should be determined by their functions and possible internal logic.
[0081] Based on the same inventive concept, the embodiments of the present disclosure also provide a shader code compilation device corresponding to the shader code compilation method. Since the principle of solving the problem by the device in the embodiments of the present disclosure is similar to the above-mentioned shader code compilation method in the embodiments of the present disclosure, the implementation of the device can refer to the implementation of the method, and the repeated parts will not be repeated.
[0082] Reference Figure 2 As shown, it is a schematic diagram of the architecture of a shader code compilation device provided by an embodiment of the present disclosure, and the device includes: an acquisition module 201 and a generation module 202; wherein,
[0083] The acquisition module 201 is used to acquire a shader code to be compiled; wherein the shader code includes a first target shader code applicable to a first rendering platform, a second target shader code applicable to a second rendering platform, and a third target shader code applicable to both the first rendering platform and the second rendering platform; the first rendering platform and the second rendering platform are used to perform content rendering under the same type of operating system; the rendering feature information in the first geometry buffer of the first rendering platform referred to by the third target shader code is the same as the rendering feature information in the second geometry buffer of the second rendering platform referred to by the third target shader code;
[0084] The generation module 202 is used to generate a first compilation result corresponding to the first rendering platform based on the first target shader code and the third target shader code; and to generate a second compilation result corresponding to the second rendering platform based on the second target shader code and the third target shader code.
[0085] In a possible implementation, the rendering feature information in the first geometry buffer includes object self-luminous information, fog effect information, normal information, roughness information, metal rendering information, reflectivity information, occlusion information, environment information, shadow information, and fog effect intensity information; the rendering feature information in the second geometry buffer includes object self-luminous information, fog effect information, normal information, roughness information, metal rendering information, reflectivity information, occlusion information, environment information, and depth information.
[0086] In one possible implementation, the rendering feature information referred to by the third target shader code includes object self-luminous information, fog effect information, normal information, roughness information, metal rendering information, reflectivity information, and occlusion information; the rendering feature information referred to by the first target shader code includes environment information, shadow information, and fog effect intensity information; and the rendering feature information referred to by the second target shader code includes environment information and depth information.
[0087] In a possible implementation, the first target shader code and the second target shader code are located in a target code section in the shader code to be compiled, and the shader code in the target code section is annotated by a preprocessing instruction Pragma to indicate that the compilation of the first target shader code and the compilation of the second target shader code are respectively performed in the target code section.
[0088] In a possible implementation, the first rendering platform is the Adreno platform of the Android operating system, and the first compilation result is used to perform delayed rendering on the Adreno platform; the second rendering platform is the Mali platform of the Android operating system, and the second compilation result is used to perform delayed rendering on the Mali platform.
[0089] In a possible implementation manner, the shader code further includes a fourth target shader code applicable to a third rendering platform and a fifth target shader code applicable to a fourth rendering platform;
[0090] The generating module 202 is also used for:
[0091] Based on the fourth target shader code, a third compilation result corresponding to the third rendering platform is generated; and based on the fifth target shader code, a fourth compilation result corresponding to the fourth rendering platform is generated.
[0092] In a possible implementation, the third rendering platform is a PC platform, and the third rendering platform is used to render content under a Microsoft operating system; the fourth rendering platform is a Metal platform, and the fourth rendering platform is used to render content under an iOS operating system;
[0093] When the third rendering platform is a PC platform and the fourth rendering platform is a Metal platform, the fourth target shader code is the same as the fifth target shader code.
[0094] The shader code compilation device provided in the embodiment of the present disclosure obtains a shader code including a first target shader code applicable to a first rendering platform, a second target shader code applicable to a second rendering platform, and a third target shader code applicable to both the first rendering platform and the second rendering platform; based on the first target shader code and the third target shader code, generates a first compilation result corresponding to the first rendering platform; and based on the second target shader code and the third target shader code, generates a second compilation result corresponding to the second rendering platform. In this way, by writing a set of shader codes and compiling them, the shader code compilation operation under multiple rendering platforms can be completed, thereby saving time and labor costs and improving development efficiency.
[0095] For descriptions of the processing flow of each module in the device and the interaction flow between each module, reference may be made to the relevant descriptions in the above method embodiment, which will not be described in detail here.
[0096] Based on the same technical concept, the embodiment of the present disclosure also provides a computer device. Figure 3 As shown, it is a schematic diagram of the structure of a computer device 300 provided in an embodiment of the present disclosure, including a processor 301, a memory 302, and a bus 303. Among them, the memory 302 is used to store execution instructions, including a memory 3021 and an external memory 3022; the memory 3021 here is also called an internal memory, which is used to temporarily store the operation data in the processor 301, and the data exchanged with the external memory 3022 such as a hard disk. The processor 301 exchanges data with the external memory 3022 through the memory 3021. When the computer device 300 is running, the processor 301 communicates with the memory 302 through the bus 303, so that the processor 301 executes the following instructions:
[0097] Obtain shader code to be compiled; wherein the shader code includes a first target shader code applicable to a first rendering platform, a second target shader code applicable to a second rendering platform, and a third target shader code applicable to both the first rendering platform and the second rendering platform; the first rendering platform and the second rendering platform are used to perform content rendering under the same type of operating system; the rendering feature information in the first geometry buffer of the first rendering platform referred to by the third target shader code is the same as the rendering feature information in the second geometry buffer of the second rendering platform referred to by the third target shader code;
[0098] Based on the first target shader code and the third target shader code, a first compilation result corresponding to the first rendering platform is generated; and based on the second target shader code and the third target shader code, a second compilation result corresponding to the second rendering platform is generated.
[0099] In a possible implementation, in the instructions of the processor 301, the rendering feature information in the first geometry buffer includes object self-luminous information, fog effect information, normal information, roughness information, metal rendering information, reflectivity information, occlusion information, environment information, shadow information, and fog effect intensity information; the rendering feature information in the second geometry buffer includes object self-luminous information, fog effect information, normal information, roughness information, metal rendering information, reflectivity information, occlusion information, environment information, and depth information.
[0100] In one possible implementation, in the instructions of the processor 301, the rendering feature information referred to by the third target shader code includes object self-luminous information, fog effect information, normal information, roughness information, metal rendering information, reflectivity information, and occlusion information; the rendering feature information referred to by the first target shader code includes environment information, shadow information, and fog effect intensity information; and the rendering feature information referred to by the second target shader code includes environment information and depth information.
[0101] In a possible implementation, in the instructions of the processor 301, the first target shader code and the second target shader code are located in a target code section in the shader code to be compiled, and the shader code in the target code section is annotated by a preprocessing instruction Pragma to indicate that the compilation of the first target shader code and the compilation of the second target shader code are respectively executed in the target code section.
[0102] In a possible implementation, in the instructions of the processor 301, the first rendering platform is the Adreno platform of the Android operating system, and the first compilation result is used to perform delayed rendering on the Adreno platform; the second rendering platform is the Mali platform of the Android operating system, and the second compilation result is used to perform delayed rendering on the Mali platform.
[0103] In a possible implementation manner, in the instruction of the processor 301, the shader code further includes a fourth target shader code applicable to a third rendering platform, and a fifth target shader code applicable to a fourth rendering platform;
[0104] Also includes:
[0105] Based on the fourth target shader code, a third compilation result corresponding to the third rendering platform is generated; and based on the fifth target shader code, a fourth compilation result corresponding to the fourth rendering platform is generated.
[0106] In a possible implementation, in the instruction of the processor 301, the third rendering platform is a PC platform, and the third rendering platform is used to render content under a Microsoft operating system; the fourth rendering platform is a Metal platform, and the fourth rendering platform is used to render content under an iOS operating system;
[0107] When the third rendering platform is a PC platform and the fourth rendering platform is a Metal platform, the fourth target shader code is the same as the fifth target shader code.
[0108] The present disclosure also provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the shader code compilation method described in the above method embodiment are executed. The storage medium can be a volatile or non-volatile computer-readable storage medium.
[0109] The disclosed embodiments also provide a computer program product, which carries a program code. The program code includes instructions that can be used to execute the steps of the shader code compilation method described in the above method embodiment. For details, please refer to the above method embodiment, which will not be repeated here.
[0110] The computer program product may be implemented in hardware, software or a combination thereof. In one optional embodiment, the computer program product is implemented as a computer storage medium. In another optional embodiment, the computer program product is implemented as a software product, such as a software development kit (SDK).
[0111] Those skilled in the art can clearly understand that, for the convenience and simplicity of description, the specific working process of the system and device described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here. In the several embodiments provided in the present disclosure, it should be understood that the disclosed system, device and method can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, and the indirect coupling or communication connection of the device or unit can be electrical, mechanical or other forms.
[0112] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0113] In addition, each functional unit in each embodiment of the present disclosure may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0114] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a non-volatile computer-readable storage medium that is executable by a processor. Based on this understanding, the technical solution of the present disclosure, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present disclosure. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0115] Finally, it should be noted that the above-described embodiments are only specific implementation methods of the present disclosure, which are used to illustrate the technical solutions of the present disclosure, rather than to limit them. The protection scope of the present disclosure is not limited thereto. Although the present disclosure is described in detail with reference to the above-described embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the above-described embodiments within the technical scope disclosed in the present disclosure, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present disclosure, and should be included in the protection scope of the present disclosure. Therefore, the protection scope of the present disclosure should be based on the protection scope of the claims.
Claims
1. A method for compiling a shader code, characterized in that: include: Obtain shader code to be compiled; wherein the shader code includes a first target shader code applicable to a first rendering platform, a second target shader code applicable to a second rendering platform, and a third target shader code applicable to both the first rendering platform and the second rendering platform; the first rendering platform and the second rendering platform are used to perform content rendering under the same type of operating system; the rendering feature information in the first geometry buffer of the first rendering platform referred to by the first target shader code is different from the rendering feature information in the second geometry buffer of the second rendering platform referred to by the second target shader code; the rendering feature information in the first geometry buffer of the first rendering platform referred to by the third target shader code is the same as the rendering feature information in the second geometry buffer of the second rendering platform referred to; Based on the first target shader code and the third target shader code, a first compilation result corresponding to the first rendering platform is generated; and based on the second target shader code and the third target shader code, a second compilation result corresponding to the second rendering platform is generated.
2. The method according to claim 1, characterized in that The rendering feature information in the first geometry buffer includes object self-luminous information, fog effect information, normal information, roughness information, metal rendering information, reflectivity information, occlusion information, environment information, shadow information, and fog effect intensity information; the rendering feature information in the second geometry buffer includes object self-luminous information, fog effect information, normal information, roughness information, metal rendering information, reflectivity information, occlusion information, environment information, and depth information.
3. The method according to claim 2, characterized in that The rendering feature information referred to by the third target shader code includes object self-luminous information, fog effect information, normal information, roughness information, metal rendering information, reflectivity information, and occlusion information; the rendering feature information referred to by the first target shader code includes environment information, shadow information, and fog effect intensity information; and the rendering feature information referred to by the second target shader code includes environment information and depth information.
4. The method according to claim 1, characterized in that: The first target shader code and the second target shader code are located in a target code section in the shader code to be compiled, and the shader code in the target code section is annotated by a preprocessing instruction Pragma to indicate that the compilation of the first target shader code and the compilation of the second target shader code are respectively performed in the target code section.
5. The method according to claim 1, characterized in that The first rendering platform is the Adreno platform of the Android operating system, and the first compilation result is used for delayed rendering on the Adreno platform; the second rendering platform is the Mali platform of the Android operating system, and the second compilation result is used for delayed rendering on the Mali platform.
6. The method according to claim 1, characterized in that The shader code further includes a fourth target shader code applicable to a third rendering platform and a fifth target shader code applicable to a fourth rendering platform; The method further comprises: Based on the fourth target shader code, generating a third compilation result corresponding to the third rendering platform; And, based on the fifth target shader code, a fourth compilation result corresponding to the fourth rendering platform is generated.
7. The method according to claim 6, characterized in that The third rendering platform is a PC platform, and the third rendering platform is used for content rendering under a Microsoft operating system; the fourth rendering platform is a Metal platform, and the fourth rendering platform is used for content rendering under an iOS operating system; When the third rendering platform is a PC platform and the fourth rendering platform is a Metal platform, the fourth target shader code is the same as the fifth target shader code.
8. A shader code compiling device, characterized in that: include: an acquisition module, configured to acquire shader codes to be compiled; wherein the shader codes include a first target shader code applicable to a first rendering platform, a second target shader code applicable to a second rendering platform, and a third target shader code applicable to both the first rendering platform and the second rendering platform; the first rendering platform and the second rendering platform are configured to perform content rendering under the same type of operating system; the rendering feature information in a first geometry buffer of the first rendering platform referred to by the first target shader code is different from the rendering feature information in a second geometry buffer of the second rendering platform referred to by the second target shader code; the rendering feature information in the first geometry buffer of the first rendering platform referred to by the third target shader code is the same as the rendering feature information in the second geometry buffer of the second rendering platform referred to; A generation module is used to generate a first compilation result corresponding to the first rendering platform based on the first target shader code and the third target shader code; and to generate a second compilation result corresponding to the second rendering platform based on the second target shader code and the third target shader code.
9. A computer device, characterized in that: include: A processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the computer device is running, the processor and the memory communicate via the bus, and when the machine-readable instructions are executed by the processor, the steps of the shader code compilation method as described in any one of claims 1 to 7 are performed.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the shader code compiling method according to any one of claims 1 to 7 are executed.
Citation Information
Patent Citations
Shader parse method and device
CN105446704A