Shader loading method and device, electronic equipment and storage medium

By preloading shader code files in the electronic device cache and matching and compiling the information of shaders to be loaded at startup, the problem of long shader compilation time is solved, thus improving image display and program startup speed.

CN121900832APending Publication Date: 2026-04-21CHINA TELECOM CLOUD TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
CHINA TELECOM CLOUD TECH CO LTD
Filing Date
2025-11-27
Publication Date
2026-04-21

AI Technical Summary

Technical Problem

In existing technologies, the compilation and association process of shaders results in long compilation times when the program starts, affecting image display and program startup speed.

Method used

Shader encoding files are preloaded in the cache of electronic devices. By matching and compiling the information of shaders to be loaded at startup, the target shader encoding file is determined, and only shaders that have not been loaded are encoded. The cache stores the already loaded shader encoding files.

Benefits of technology

It shortens the shader compilation time and improves image display speed and program startup and running speed.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121900832A_ABST
    Figure CN121900832A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a shader loading method and device, electronic equipment and a storage medium, and the method comprises the steps: obtaining to-be-loaded shader information when an open graphics library program is started; matching the information of the to-be-loaded shader with a preloaded shader coding file, and determining a first target loaded shader coding file; when the first target loading shader coding file is empty, compiling based on the to-be-loaded shader information, and determining a second target loading shader coding file; the second target loading shader coding file is loaded; and when the first target loading shader coding file is not empty, loading the first target loading shader coding file. According to the embodiment of the invention, the compiling time of the shader can be shortened, so that the image display speed and the program starting running speed are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of image rendering technology, and in particular to a shader loading method, a shader loading device, an electronic device, and a storage medium. Background Technology

[0002] Because each program needs to code its own shaders when it starts up, and the current startup process requires compiling each shader, and the compilation and association process is relatively slow, the compilation time at program startup is long, resulting in low display speed and program startup speed. Summary of the Invention

[0003] In view of the above problems, embodiments of the present invention are proposed to provide a shader loading method, a shader loading apparatus, an electronic device, and a storage medium that overcome or at least partially solve the above problems.

[0004] To address the aforementioned problems, in a first aspect of this invention, an embodiment discloses a shader loading method applied in an electronic device. The electronic device is equipped with a cache, which stores preloaded shader encoding files. The method includes: When the Open Graphics Library program starts, it obtains information about the shaders to be loaded. The information of the shader to be loaded is matched with the preloaded shader encoding file to determine the first target shader encoding file to be loaded. When the first target shader encoding file is empty, compilation is performed based on the information of the shader to be loaded to determine the second target shader encoding file; Load the shader encoding file from the second target; If the first target load shader encoding file is not empty, load the first target load shader encoding file.

[0005] Optionally, the shader information to be loaded includes a first shader key string, the preloaded shader encoding file includes a second shader key string, and the step of matching the shader information to be loaded with the preloaded shader encoding file to determine the first target shader encoding file includes: Match the first shader key string with the second shader key string; When the first shader key string matches the second shader key string, the preloaded shader encoding file corresponding to the second shader key string is determined as the first target loaded shader encoding file; When the first shader key string does not match the second shader key string, it is determined that the first target load shader encoding file is empty.

[0006] Optionally, the method further includes: Associate the second target loaded shader encoding file with the information of the shader to be loaded to generate association information; The second target load shader encoding file and the associated information are stored in the cache to update the preload shader encoding file.

[0007] Optionally, the step of associating the second target loaded shader encoding file with the shader information to be loaded to generate association information includes: The second target shader encoding file and the shader information to be loaded are hashed to generate a hash value; The hash value is identified as the associated information.

[0008] Optionally, the shader information to be loaded includes the graphics card model and driver version, and the step of hashing the second target shader encoding file with the shader information to be loaded to generate a hash value includes: The string corresponding to the graphics card model, the string corresponding to the driver version, and the string corresponding to the second target loading shader encoding file are hashed to generate a hash value.

[0009] Optionally, the method further includes: Determine the number of matches in the preloaded shader encoding file; The preloaded shader encoding file is cached based on the number of matches.

[0010] Optionally, the step of managing the cache of the preloaded shader encoding file based on the number of matches includes: When the cache reaches its storage limit, the preloaded shader encoding files are sorted in descending order based on the number of matches to determine the buffer sequence. The preloaded shader encoding file is deleted based on the order in the buffer sequence.

[0011] In a second aspect, embodiments of the present invention disclose a shader loading apparatus applied in an electronic device, the electronic device being provided with a cache storing preloaded shader encoding files, the apparatus comprising: The acquisition module is used to acquire information about shaders to be loaded when the Open Graphics Library program starts. A matching module is used to match the information of the shader to be loaded with the preloaded shader encoding file to determine the first target shader encoding file to be loaded. The encoding module is used to compile based on the information of the shader to be loaded when the first target loading shader encoding file is empty, and to determine the second target loading shader encoding file. The first loading module is used to load the second target shader encoding file; The second loading module is used to load the first target loading shader encoding file when the first target loading shader encoding file is not empty.

[0012] In a third aspect of the invention, an embodiment of the invention discloses an electronic device, including a processor, a memory, and a computer program stored in the memory and capable of running on the processor, wherein the computer program, when executed by the processor, implements the steps of the shader loading method as described above.

[0013] In a fourth aspect, embodiments of the present invention disclose a computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of the shader loading method as described above.

[0014] The embodiments of the present invention have the following advantages: This invention, in its embodiments, obtains information about shaders to be loaded when the open graphics library program starts; matches this information with preloaded shader encoding files to determine a first target shader encoding file; if the first target shader encoding file is empty, compiles based on the information about the shaders to be loaded to determine a second target shader encoding file; loads the second target shader encoding file; and if the first target shader encoding file is not empty, loads the first target shader encoding file. By using a cache to store preloaded shader encoding files that have already been loaded, during shader loading, the first target shader encoding file corresponding to the already loaded shaders can be directly called, and encoding is only performed on unloaded shaders to determine the second target shader encoding file, thereby shortening compilation time and improving image display speed and program startup and running speed. Attached Figure Description

[0015] Figure 1 This is a flowchart illustrating the steps of an embodiment of a shader loading method according to the present invention; Figure 2 This is a flowchart illustrating the steps of another embodiment of the shader loading method of the present invention; Figure 3 This is a schematic diagram of a hash processing method according to the present invention; Figure 4 This is a schematic diagram of cache management according to the present invention; Figure 5 This is a flowchart illustrating an example of a shader loading method according to the present invention; Figure 6 This is a structural block diagram of an embodiment of a shader loading device according to the present invention; Figure 7 This is a structural block diagram of an electronic device provided in an embodiment of the present invention; Figure 8 This is a structural block diagram of a storage medium provided in an embodiment of the present invention. Detailed Implementation

[0016] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments.

[0017] In this embodiment of the invention, the shader can be a shader from OpenGL (Open Graphics Library). OpenGL is a cross-language, cross-platform application programming interface (API) for rendering 2D and 3D vector graphics. This interface consists of nearly 350 different function calls, used for everything from simple graphics drawing to complex 3D scene rendering. OpenGL is one of the most widely accepted APIs for processing 2D / 3D graphics in the video industry. OpenGL supports multiple operating systems, including Windows, Unix-like systems, Linux, and macOS, making applications developed based on OpenGL highly portable. OpenGL is language-independent and supports bindings for multiple programming languages. OpenGL is commonly used in fields such as CAD, virtual reality, scientific visualization programs, and video game development. Its efficient graphics rendering capabilities and rich API enable developers to create high-quality graphics effects. The technical details include texture mapping, rendering workflow, coordinate systems, and the Shader Language (GLSL). Shaders can be coded using GLSL. GLSL, short for OpenGL Shader Language, is the language used for shading programming in OpenGL. It allows developers to write short, custom programs that execute on the GPU (Graphics Processing Unit) of a graphics card, replacing parts of the traditional fixed rendering pipeline, such as view transformations and projection transformations, making different layers of the rendering pipeline programmable. A shader language is a high-level shader language used to write vertex shaders, fragment shaders, and other types of shader programs. GLSL provides rich syntax and built-in functions, enabling developers to write flexible and efficient shader code. Currently, programs that directly or indirectly use OpenGL for rendering basically require GLSL to render and ultimately display images. Therefore, GLSL plays a crucial role in OpenGL. An OpenGL program typically has one or more shader programs. Before using shaders, OpenGL rendering requires compiling and linking them, and the compilation time directly determines the speed of image display and program startup. Because the shader code in GLSL is a human-readable coding language, the graphics card needs to compile it into machine code that it can recognize before using it. Therefore, each program needs to code its own shaders when it starts up, and the compilation and linking process is relatively slow, especially for complex shaders. To address this, the implementation process of this invention is proposed.

[0018] Reference Figure 1This document illustrates a flowchart of an embodiment of a shader loading method according to the present invention. The shader loading method is used in an electronic device, which is equipped with a cache that stores preloaded shader encoding files. The electronic device described in this embodiment can run OpenGL programs, i.e., open-source graphics library programs. The electronic device is equipped with a cache that stores preloaded shader encoding files. The preloaded shader encoding files are the encoding files corresponding to shaders that have already been loaded before the current shader loading. There can be multiple preloaded shader encoding files. The encoding format of the preloaded shader encoding files can use encoding files of different bases. For example, the preloaded shader encoding files can be binary encoding files.

[0019] The shader loading method may specifically include the following steps: Step 101: When the Open Graphics Library program starts, obtain the information of the shaders to be loaded; When an electronic device launches an open graphics library program, it can obtain information about the shaders to be loaded, including their parameters such as name and encoding language file.

[0020] Step 102: Match the information of the shader to be loaded with the preloaded shader encoding file to determine the first target shader encoding file; The information of the shader to be loaded can be matched one by one with the preloaded shader code files to determine the corresponding first target shader code file. The first target shader code file is the shader code file in the preloaded shader code files that matches the information of the shader to be loaded. The first target shader code file can be a real shader code file, that is, there exists a shader code file that matches the information of the shader to be loaded. The first target shader code file can also be empty, that is, there is no shader code file that matches the information of the shader to be loaded.

[0021] Step 103: When the first target loading shader encoding file is empty, compile based on the information of the shader to be loaded to determine the second target loading shader encoding file; If the first target shader encoding file is empty, it means that the shader corresponding to the shader information to be loaded has not been loaded before. Therefore, the shader information to be loaded can be encoded to generate a second target shader encoding file. The second target shader encoding file is the encoding file corresponding to the shader information to be loaded. The second target shader encoding file is generated using the same encoding format as the preloaded shader encoding file. If the preloaded shader encoding file is a binary file, the second target shader encoding file can also be a binary file.

[0022] Step 104: Load the second target's shader encoding file; Load the second target shader encoding file to complete the loading of the shader to be loaded.

[0023] Step 105: If the first target load shader encoding file is not empty, load the first target load shader encoding file.

[0024] If the first target shader encoding file is not empty, it means that the shader corresponding to the shader information to be loaded has already been loaded. The first target shader encoding file can be loaded directly to complete the loading of the shader to be loaded.

[0025] This invention, in its embodiments, obtains information about shaders to be loaded when the open graphics library program starts; matches this information with preloaded shader encoding files to determine a first target shader encoding file; if the first target shader encoding file is empty, compiles based on the information about the shaders to be loaded to determine a second target shader encoding file; loads the second target shader encoding file; and if the first target shader encoding file is not empty, loads the first target shader encoding file. By using a cache to store preloaded shader encoding files that have already been loaded, during shader loading, the first target shader encoding file corresponding to the already loaded shaders can be directly called, and encoding is only performed on unloaded shaders to determine the second target shader encoding file, thereby shortening compilation time and improving image display speed and program startup and running speed.

[0026] Reference Figure 2 This diagram illustrates a flowchart of another embodiment of the shader loading method of the present invention. The shader loading method is used in an electronic device, which is equipped with a cache that stores pre-loaded shader encoding files. Specifically, the shader loading method may include the following steps: Step 201: When the Open Graphics Library program starts, obtain the information of the shaders to be loaded; When an open graphics library program starts, it can generate information about the shader to be loaded based on the parameters of the shader to be loaded. This information about the shader to be loaded can then be retrieved.

[0027] Step 202: Match the information of the shader to be loaded with the preloaded shader encoding file to determine the first target shader encoding file; The identifiers of the shaders in the shader information to be loaded are matched with the identifiers of the shaders corresponding to each shader encoding file in the preloaded shader encoding file, and the first target shader encoding file is determined based on the matching results.

[0028] In an optional embodiment of the present invention, the shader information to be loaded includes a first shader key string, the preloaded shader encoding file includes a second shader key string, and the step of matching the shader information to be loaded with the preloaded shader encoding file to determine the first target shader encoding file includes: Sub-step S2021: Match the first shader key string with the second shader key string; In this embodiment of the invention, the shader information to be loaded includes a first shader key string, and the preloaded shader encoding file includes a second shader key string. The first key string and the second key string are determined using the same cryptographic solution method. That is, the first key string and the second key string can be matched after being decrypted using the same decryption method. The first shader key string can be matched one by one with the second shader key string of each shader in the preloaded shader encoding file.

[0029] Sub-step S2022: When the first shader key string matches the second shader key string, the preloaded shader encoding file corresponding to the second shader key string is determined as the first target loaded shader encoding file; When the first shader key string matches the second shader key string, that is, the shader corresponding to the shader information to be loaded and the shader corresponding to the second shader key string are the same shader, the preloaded shader encoding file corresponding to the second shader key string can be determined as the first target loaded shader encoding file.

[0030] Sub-step S2023: When the first shader key string does not match the second shader key string, determine that the first target load shader encoding file is empty.

[0031] When the first shader key string does not match any of the second shader key strings, it means that the shader corresponding to the shader information to be loaded is different from the shader corresponding to the preloaded shader encoding file, and the first target shader encoding file can be empty.

[0032] Step 203: When the first target loading shader encoding file is empty, compile based on the information of the shader to be loaded to determine the second target loading shader encoding file; When the first target shader encoding file is empty, meaning the shader corresponding to the shader information to be loaded is being loaded for the first time, encoding can be performed based on the shader information to be loaded, and the generated encoding file is the second target shader encoding file. For example, if the shader information to be loaded includes a text document written by the user using GLSL, this GLSL text document can be compiled using functions such as glCompileShader and glLinkProgram, and the generated binary file will be the second target shader encoding file.

[0033] Step 204: Load the second target's shader encoding file; Then, the second target shader encoding file is loaded to complete the shader loading process. By compiling only the shaders loaded the first time, the overall amount of data for compiling shaders is reduced, thereby improving loading speed.

[0034] Step 205: If the first target load shader encoding file is not empty, load the first target load shader encoding file; If the first target load shader encoding file is not empty, the already loaded first target load shader encoding file can be directly called to complete the loading of the shader.

[0035] Step 206: Associate the second target loading shader encoding file with the information of the shader to be loaded to generate association information; Since the second target shader encoding file is the compiled encoding file of the shader loaded in the first instance, it can be cached. This allows for direct access to the second target shader encoding file the next time the corresponding shader is called, thus shortening loading time. Therefore, the second target shader encoding file can be associated with the information of the shader to be loaded to generate association information.

[0036] In an optional embodiment of the present invention, the step of associating the second target loading shader encoding file with the information of the shader to be loaded to generate association information includes: Sub-step S2061: Hash the second target loaded shader encoding file and the shader information to be loaded to generate a hash value; A hash algorithm can be used as a verification method. The second target shader encoding file and the information of the shader to be loaded are hashed together to generate a unique and corresponding hash value as the association key (index) between the second target shader encoding file and the information of the shader to be loaded.

[0037] Specifically, the information of the shader to be loaded includes the graphics card model and driver version. The step of hashing the second target shader encoding file and the information of the shader to be loaded to generate a hash value includes: hashing the string corresponding to the graphics card model, the string corresponding to the driver version, and the string corresponding to the second target shader encoding file to generate a hash value.

[0038] In practical applications, the information to be loaded for the shader includes the graphics card model and driver version. The graphics card model refers to the model of the graphics processor used by the electronic device, including its performance parameters. The driver version is the version number of the driver service for the electronic device. The strings corresponding to the graphics card model, the driver version, and the second target shader encoding file can be hashed to generate a hash value.

[0039] Sub-step S2062: The hash value is determined as the associated information.

[0040] The calculated hash value is used as the associated information.

[0041] For example, the MD5 algorithm can be used for hashing, such as... Figure 3 As shown, it retrieves the currently used graphics card model and driver version; retrieves all shader code required by the current shader program; performs MD5 hashing on the strings of graphics card model, driver version, and shader code, generates a new string, and returns the generated MD5 string as the key, serving as associated information.

[0042] Step 207: Store the second target loaded shader encoding file and the associated information in the cache to update the preloaded shader encoding file; The second target loads the shader encoding file and associated information together and writes them into the cache, thereby adding the contents of the preloaded shader encoding file, which is used to look up the corresponding shader in the preloaded shader encoding file next time.

[0043] Step 208: Determine the number of matches for the preloaded shader encoding file; It can also determine the number of times the preloaded shader encoding file is matched, and the frequency of calling the shader corresponding to the preloaded shader encoding file can be determined by the number of times the preloaded shader encoding file is matched.

[0044] Step 209: Perform cache management on the preloaded shader encoding file based on the number of matching.

[0045] Based on the number of matches, the frequency of calls is determined. The preloaded shader encoding file is then cached based on the call frequency, which can prevent the cache from becoming too large and affecting the operating performance of electronic devices.

[0046] In an optional embodiment of the present invention, the step of managing the cache of the preloaded shader encoding file based on the number of matches includes: when the cache reaches the storage limit, sorting the preloaded shader encoding file in descending order based on the number of matches to determine a buffer sequence; and deleting the preloaded shader encoding file based on the order in the buffer sequence.

[0047] Cache management can also be performed when the cache storage limit is reached. When the cache reaches its storage limit, the preloaded shader code files can be sorted in descending order based on the number of matches, that is, less frequently used preloaded shader code files are moved to the front, generating a buffer sequence. Following the order in this buffer sequence, the corresponding preloaded shader code files are deleted sequentially until the cache capacity meets the requirements.

[0048] For example, the process of cache management control can be referred to Figure 4 This sets a maximum limit on the number of shader programs that can be cached. Each time a cache file is searched, the count of the found cache files is incremented by one, and the files are sorted from largest to smallest based on their counts. If the maximum limit is exceeded, the cache file with the smallest count is deleted to ensure that space is not written to indefinitely.

[0049] To enable those skilled in the art to clearly understand the implementation process of the embodiments of the present invention, an example is used below for illustration. Please refer to the example provided. Figure 5 After the program starts, a key (information about the shader to be loaded) is generated for the shader to be used. This key is then used to look up the shader in the cache. If the shader is not cached, functions such as `glCompileShader` and `glLinkProgram` are called to compile it. Then, the compiled shader binary data is retrieved using the `glGetProgramBinary` function, written to disk, bound to the generated key, and written to the cache file for future lookups.

[0050] If the key is found in the cache, the compiled binary data previously written to disk is read into memory and loaded directly into the graphics card using the glProgramBinary function, saving compilation and linking time and processes.

[0051] It should be noted that, for the sake of simplicity, the method embodiments are all described as a series of actions. However, those skilled in the art should understand that the embodiments of the present invention are not limited to the described order of actions, because according to the embodiments of the present invention, some steps can be performed in other orders or simultaneously. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions involved are not necessarily essential to the embodiments of the present invention.

[0052] Reference Figure 6 The diagram illustrates a structural block diagram of an embodiment of a shader loading device according to the present invention. The shader loading device is applied in an electronic device, which is equipped with a cache storing pre-loaded shader encoding files. Specifically, the shader loading device may include the following modules: The acquisition module 601 is used to acquire information about shaders to be loaded when the Open Graphics Library program starts. The matching module 602 is used to match the information of the shader to be loaded with the preloaded shader encoding file to determine the first target loaded shader encoding file; Encoding module 603 is used to compile based on the information of the shader to be loaded when the first target loading shader encoding file is empty, and to determine the second target loading shader encoding file. The first loading module 604 is used to load the second target shader encoding file; The second loading module 605 is used to load the first target loading shader encoding file when the first target loading shader encoding file is not empty.

[0053] In an optional embodiment of the present invention, the shader information to be loaded includes a first shader key string, the preloaded shader encoding file includes a second shader key string, and the matching module 602 includes: A matching submodule is used to match the first shader key string with the second shader key string; The first determining submodule is used to determine the preloaded shader encoding file corresponding to the shader second key string as the first target loaded shader encoding file when the shader first key string matches the shader second key string; The second determining submodule is used to determine that the first target loaded shader encoding file is empty when the shader first key string does not match the shader second key string.

[0054] In an optional embodiment of the present invention, the device further includes: The association module is used to associate the second target loaded shader encoding file with the information of the shader to be loaded, and generate association information; A caching module is used to store the second target loaded shader encoding file and the associated information in the cache to update the preloaded shader encoding file.

[0055] In an optional embodiment of the present invention, the association module includes: The hash processing submodule is used to perform hash processing on the second target loaded shader encoding file and the shader information to be loaded to generate a hash value; The association submodule is used to determine the hash value as association information.

[0056] In an optional embodiment of the present invention, the shader information to be loaded includes the graphics card model and driver version, and the hash processing submodule includes: The hash unit is used to perform hash processing on the string corresponding to the graphics card model, the string corresponding to the driver version, and the string corresponding to the second target loading shader encoding file to generate a hash value.

[0057] In an optional embodiment of the present invention, the device further includes: The number of matches is determined by the number of matches in the preloaded shader encoding file. The management module is used to manage the cache of the preloaded shader encoding file based on the number of matching.

[0058] In an optional embodiment of the present invention, the management module includes: The sorting submodule is used to sort the preloaded shader encoding files in descending order based on the number of matches when the cache reaches its storage limit, and to determine the buffer sequence. A deletion submodule is used to delete the preloaded shader encoding file based on the order in the buffer sequence.

[0059] This invention, in its embodiments, obtains information about shaders to be loaded when the open graphics library program starts; matches this information with preloaded shader encoding files to determine a first target shader encoding file; if the first target shader encoding file is empty, compiles based on the information about the shaders to be loaded to determine a second target shader encoding file; loads the second target shader encoding file; and if the first target shader encoding file is not empty, loads the first target shader encoding file. By using a cache to store preloaded shader encoding files that have already been loaded, during shader loading, the first target shader encoding file corresponding to the already loaded shaders can be directly called, and encoding is only performed on unloaded shaders to determine the second target shader encoding file, thereby shortening compilation time and improving image display speed and program startup and running speed.

[0060] As the device embodiment is basically similar to the method embodiment, the description is relatively simple, and relevant parts can be found in the description of the method embodiment.

[0061] Reference Figure 7 The present invention also provides an electronic device, comprising: A processor 701 and a memory 702 are provided. The memory 702 stores a computer program executable by the processor 701. When the electronic device is controlled to run, the processor 701 executes the computer program to implement the shader loading method as described in any one of the embodiments of the present invention. The shader loading is applied in the electronic device, which is provided with a cache that stores preloaded shader encoding files. The method includes: When the Open Graphics Library program starts, it obtains information about the shaders to be loaded. The information of the shader to be loaded is matched with the preloaded shader encoding file to determine the first target shader encoding file to be loaded. When the first target shader encoding file is empty, compilation is performed based on the information of the shader to be loaded to determine the second target shader encoding file; Load the shader encoding file from the second target; If the first target load shader encoding file is not empty, load the first target load shader encoding file.

[0062] Optionally, the shader information to be loaded includes a first shader key string, the preloaded shader encoding file includes a second shader key string, and the step of matching the shader information to be loaded with the preloaded shader encoding file to determine the first target shader encoding file includes: Match the first shader key string with the second shader key string; When the first shader key string matches the second shader key string, the preloaded shader encoding file corresponding to the second shader key string is determined as the first target loaded shader encoding file; When the first shader key string does not match the second shader key string, it is determined that the first target load shader encoding file is empty.

[0063] Optionally, the method further includes: Associate the second target loaded shader encoding file with the information of the shader to be loaded to generate association information; The second target load shader encoding file and the associated information are stored in the cache to update the preload shader encoding file.

[0064] Optionally, the step of associating the second target loaded shader encoding file with the shader information to be loaded to generate association information includes: The second target shader encoding file and the shader information to be loaded are hashed to generate a hash value; The hash value is identified as the associated information.

[0065] Optionally, the shader information to be loaded includes the graphics card model and driver version, and the step of hashing the second target shader encoding file with the shader information to be loaded to generate a hash value includes: The string corresponding to the graphics card model, the string corresponding to the driver version, and the string corresponding to the second target loading shader encoding file are hashed to generate a hash value.

[0066] Optionally, the method further includes: Determine the number of matches in the preloaded shader encoding file; The preloaded shader encoding file is cached based on the number of matches.

[0067] Optionally, the step of managing the cache of the preloaded shader encoding file based on the number of matches includes: When the cache reaches its storage limit, the preloaded shader encoding files are sorted in descending order based on the number of matches to determine the buffer sequence. The preloaded shader encoding file is deleted based on the order in the buffer sequence.

[0068] This invention, in its embodiments, obtains information about shaders to be loaded when the open graphics library program starts; matches this information with preloaded shader encoding files to determine a first target shader encoding file; if the first target shader encoding file is empty, compiles based on the information about the shaders to be loaded to determine a second target shader encoding file; loads the second target shader encoding file; and if the first target shader encoding file is not empty, loads the first target shader encoding file. By using a cache to store preloaded shader encoding files that have already been loaded, during shader loading, the first target shader encoding file corresponding to the already loaded shaders can be directly called, and encoding is only performed on unloaded shaders to determine the second target shader encoding file, thereby shortening compilation time and improving image display speed and program startup and running speed.

[0069] The memory may include random access memory (RAM) or non-volatile memory, such as at least one disk storage device. Optionally, the memory may also be at least one storage device located remotely from the aforementioned processor.

[0070] The processors mentioned above can be general-purpose processors, including central processing units (CPUs), network processors (NPs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.

[0071] Reference Figure 8 This invention also provides a computer-readable storage medium 801, on which a computer program is stored. When the computer program is run by a processor, it executes the shader loading method as described in any one of the embodiments of this invention. The shader loading is applied in an electronic device, which is equipped with a cache containing pre-loaded shader encoding files. The method includes: When the Open Graphics Library program starts, it obtains information about the shaders to be loaded. The information of the shader to be loaded is matched with the preloaded shader encoding file to determine the first target shader encoding file to be loaded. When the first target shader encoding file is empty, compilation is performed based on the information of the shader to be loaded to determine the second target shader encoding file; Load the shader encoding file from the second target; If the first target load shader encoding file is not empty, load the first target load shader encoding file.

[0072] Optionally, the shader information to be loaded includes a first shader key string, the preloaded shader encoding file includes a second shader key string, and the step of matching the shader information to be loaded with the preloaded shader encoding file to determine the first target shader encoding file includes: Match the first shader key string with the second shader key string; When the first shader key string matches the second shader key string, the preloaded shader encoding file corresponding to the second shader key string is determined as the first target loaded shader encoding file; When the first shader key string does not match the second shader key string, it is determined that the first target load shader encoding file is empty.

[0073] Optionally, the method further includes: Associate the second target loaded shader encoding file with the information of the shader to be loaded to generate association information; The second target load shader encoding file and the associated information are stored in the cache to update the preload shader encoding file.

[0074] Optionally, the step of associating the second target loaded shader encoding file with the shader information to be loaded to generate association information includes: The second target shader encoding file and the shader information to be loaded are hashed to generate a hash value; The hash value is identified as the associated information.

[0075] Optionally, the shader information to be loaded includes the graphics card model and driver version, and the step of hashing the second target shader encoding file with the shader information to be loaded to generate a hash value includes: The string corresponding to the graphics card model, the string corresponding to the driver version, and the string corresponding to the second target loading shader encoding file are hashed to generate a hash value.

[0076] Optionally, the method further includes: Determine the number of matches in the preloaded shader encoding file; The preloaded shader encoding file is cached based on the number of matches.

[0077] Optionally, the step of managing the cache of the preloaded shader encoding file based on the number of matches includes: When the cache reaches its storage limit, the preloaded shader encoding files are sorted in descending order based on the number of matches to determine the buffer sequence. The preloaded shader encoding file is deleted based on the order in the buffer sequence.

[0078] This invention, in its embodiments, obtains information about shaders to be loaded when the open graphics library program starts; matches this information with preloaded shader encoding files to determine a first target shader encoding file; if the first target shader encoding file is empty, compiles based on the information about the shaders to be loaded to determine a second target shader encoding file; loads the second target shader encoding file; and if the first target shader encoding file is not empty, loads the first target shader encoding file. By using a cache to store preloaded shader encoding files that have already been loaded, during shader loading, the first target shader encoding file corresponding to the already loaded shaders can be directly called, and encoding is only performed on unloaded shaders to determine the second target shader encoding file, thereby shortening compilation time and improving image display speed and program startup and running speed.

[0079] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other.

[0080] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, apparatus, or computer program products. Therefore, embodiments of the present invention can take the form of entirely hardware embodiments, entirely software embodiments, or embodiments combining software and hardware aspects. Furthermore, embodiments of the present invention can take the form of computer program products implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0081] Embodiments of the present invention are described with reference to flowchart illustrations and / or block diagrams of methods, terminal devices (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing terminal device to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing terminal device, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0082] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing terminal device to operate in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0083] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal equipment, causing a series of operational steps to be performed on the computer or other programmable terminal equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable terminal equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0084] Although preferred embodiments of the present invention have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments as well as all changes and modifications falling within the scope of the embodiments of the present invention.

[0085] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or terminal device that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or terminal device. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or terminal device that includes said element.

[0086] The above provides a detailed description of a shader loading method, a shader loading device, an electronic device, and a storage medium provided by the present invention. Specific examples have been used to illustrate the principles and implementation methods of the present invention. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of the present invention. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of the present invention. Therefore, the content of this specification should not be construed as a limitation of the present invention.

Claims

1. A shader loading method, characterized in that, Applied to an electronic device, the electronic device is equipped with a cache, the cache storing preloaded shader encoding files, the method includes: When the Open Graphics Library program starts, it obtains information about the shaders to be loaded. The information of the shader to be loaded is matched with the preloaded shader encoding file to determine the first target shader encoding file to be loaded. When the first target shader encoding file is empty, compilation is performed based on the information of the shader to be loaded to determine the second target shader encoding file; Load the shader encoding file from the second target; If the first target load shader encoding file is not empty, load the first target load shader encoding file.

2. The method according to claim 1, characterized in that, The information of the shader to be loaded includes a first shader key string, and the preloaded shader encoding file includes a second shader key string. The step of matching the information of the shader to be loaded with the preloaded shader encoding file to determine the first target shader encoding file includes: Match the first shader key string with the second shader key string; When the first shader key string matches the second shader key string, the preloaded shader encoding file corresponding to the second shader key string is determined as the first target loaded shader encoding file; When the first shader key string does not match the second shader key string, it is determined that the first target load shader encoding file is empty.

3. The method according to claim 1, characterized in that, The method further includes: Associate the second target loaded shader encoding file with the information of the shader to be loaded to generate association information; The second target load shader encoding file and the associated information are stored in the cache to update the preload shader encoding file.

4. The method according to claim 3, characterized in that, The step of associating the second target loaded shader encoding file with the information of the shader to be loaded to generate association information includes: The second target shader encoding file and the shader information to be loaded are hashed to generate a hash value; The hash value is identified as the associated information.

5. The method according to claim 4, characterized in that, The information about the shader to be loaded includes the graphics card model and driver version. The step of hashing the second target shader encoding file with the information about the shader to be loaded to generate a hash value includes: The string corresponding to the graphics card model, the string corresponding to the driver version, and the string corresponding to the second target loading shader encoding file are hashed to generate a hash value.

6. The method according to claim 1, characterized in that, The method further includes: Determine the number of matches in the preloaded shader encoding file; The preloaded shader encoding file is cached based on the number of matches.

7. The method according to claim 1, characterized in that, The step of caching the preloaded shader encoding file based on the number of matches includes: When the cache reaches its storage limit, the preloaded shader encoding files are sorted in descending order based on the number of matches to determine the buffer sequence. The preloaded shader encoding file is deleted based on the order in the buffer sequence.

8. A shader loading apparatus, characterized in that, Applied in an electronic device, the electronic device is equipped with a cache, the cache storing preloaded shader encoding files, the device comprising: The acquisition module is used to acquire information about shaders to be loaded when the Open Graphics Library program starts. A matching module is used to match the information of the shader to be loaded with the preloaded shader encoding file to determine the first target shader encoding file to be loaded. The encoding module is used to compile based on the information of the shader to be loaded when the first target loading shader encoding file is empty, and to determine the second target loading shader encoding file. The first loading module is used to load the second target shader encoding file; The second loading module is used to load the first target loading shader encoding file when the first target loading shader encoding file is not empty.

9. An electronic device, characterized in that, It includes a processor, a memory, and a computer program stored in the memory and capable of running on the processor, wherein the computer program, when executed by the processor, implements the steps of the shader loading method as described in any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that, A computer program is stored on the computer-readable storage medium, which, when executed by a processor, implements the steps of the shader loading method as described in any one of claims 1 to 7.