Graphical pipeline creation method, apparatus, and electronic device
By creating the graphics pipeline from pre-compiled binary data obtained from the pipeline cache, the problem of CPU resource consumption during graphics pipeline compilation is solved, resulting in faster graphics pipeline creation and reduced display lag on electronic devices.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- VIVO MOBILE COMM CO LTD
- Filing Date
- 2026-03-20
- Publication Date
- 2026-06-09
AI Technical Summary
The compilation process of the graphics pipeline consumes a lot of CPU resources, which can cause frame drops or stuttering during the display of electronic devices.
By obtaining pre-compiled graphics pipeline binary data, graphics pipelines are created from the pipeline cache, avoiding on-site compilation and directly creating graphics pipelines using pre-compiled binary data.
Significantly shortens graphics pipeline creation time, avoids rendering thread blocking, and reduces frame drops or stuttering during electronic device display.
Smart Images

Figure CN122176142A_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of computer technology, specifically relating to a method, apparatus, and electronic device for creating a graphics pipeline. Background Technology
[0002] Currently, when an application needs to render a scene, the corresponding graphics pipeline must first be created and compiled. During this process, the graphics card driver needs to compile all the information that constitutes the graphics pipeline (such as shader code, state parameters, etc.) to generate executable machine code adapted to the current graphics card hardware.
[0003] However, compiling the graphics pipeline is a typical computationally intensive task, significantly consuming Central Processing Unit (CPU) resources and taking a long time. Since the rendering thread responsible for updating the screen must wait for the graphics pipeline to complete compilation before it can continue executing subsequent drawing commands, this rendering thread will be blocked. This can cause frame drops or stuttering on electronic devices during display. Summary of the Invention
[0004] The purpose of this application is to provide a method, apparatus, and electronic device for creating graphics pipelines, which can reduce frame drops or stuttering during the display of electronic devices.
[0005] In a first aspect, embodiments of this application provide a method for creating a graphics pipeline. The method includes: obtaining graphics pipeline creation request information sent by a first application; the graphics pipeline creation request information is used to request the creation of a first graphics pipeline; obtaining pre-compiled binary data of the first graphics pipeline from a pipeline cache through the graphics card driver of an electronic device; the pipeline cache includes binary data of at least one graphics pipeline after pre-compilation; and creating the first graphics pipeline based on the pre-compiled binary data.
[0006] Thus, since the pre-compiled binary data of the first graphics pipeline can be obtained from the pipeline cache, the first graphics pipeline can be created directly using this pre-compiled binary data without having to compile the construction information of the first graphics pipeline on-site. This significantly shortens the creation time of the first graphics pipeline, avoids rendering thread blocking, and reduces frame drops or stuttering during electronic device display.
[0007] In one possible implementation, before obtaining the graphics pipeline creation request information sent by the first application, the method further includes: obtaining a first description file; the first description file is used to describe the creation information of at least one graphics pipeline; creating at least one graphics pipeline based on the first description file; and precompiling the at least one graphics pipeline through the graphics card driver to obtain precompiled binary data of at least one graphics pipeline.
[0008] Thus, since at least one graphics pipeline can be created in advance based on the first description file, and the at least one graphics pipeline can be pre-compiled to obtain pre-compiled binary data of at least one graphics pipeline, the graphics pipeline can be created directly using these pre-compiled binary data in the future, without having to compile the construction information of the graphics pipeline on-site. This significantly shortens the creation time of the first graphics pipeline, avoids rendering thread blocking, and reduces frame drops or stuttering during the display of electronic devices.
[0009] In one possible implementation, the first description file mentioned above includes multiple resource data blocks; each resource data block corresponds to a resource object; each resource data block includes: the resource type of the resource object, the resource object construction information, and the resource object identifier; wherein, the resource object includes any one of the following: a graphics pipeline, or a resource object referenced when creating a graphics pipeline.
[0010] In one possible implementation, when the creation of the first resource object requires a reference to the second resource object, the construction information of the first resource object includes a first resource object identifier; wherein, the first resource object construction information is the resource object construction information included in the first resource data block; the first resource data block is the resource data block corresponding to the first resource object among multiple resource data blocks; and the first resource object identifier is the resource object identifier of the second resource object.
[0011] In one possible implementation, the creation of at least one graphics pipeline based on the first description file includes: parsing the first description file to obtain multiple resource data blocks; determining at least one first sequence based on the multiple resource data blocks; the first sequence is used to indicate the creation order of the graphics pipeline and the third resource object; the third resource object is a resource object that needs to be referenced when creating the graphics pipeline; and creating at least one graphics pipeline according to at least one first sequence.
[0012] Thus, since the electronic device can determine the creation order between the graphics pipeline and the resource objects that need to be referenced to create the graphics pipeline, i.e. the first sequence mentioned above, the electronic device can accurately complete the creation of the graphics pipeline according to the creation order, thereby improving the reliability of the pre-created graphics pipeline of the electronic device.
[0013] In one possible implementation, determining at least one first sequence based on multiple resource data blocks includes: constructing at least two first mapping tables based on the resource types of resource objects corresponding to the multiple resource data blocks; each first mapping table stores a mapping relationship between at least one resource object identifier and at least one resource object construction information; all resource object identifiers stored in each first mapping table indicate the same resource type of the resource objects; and, if the second resource object construction information includes a second resource object identifier, determining a third mapping table storing the second resource object identifier from the at least two first mapping tables; the second resource object construction information is any resource object construction information in the second mapping table; the second mapping table is a mapping table among the at least two first mapping tables, and the resource type of the resource object indicated by the resource object identifier in the second mapping table is a graphics pipeline; and determining a first sequence corresponding to the second resource object construction information based on the second resource object construction information and the third resource object construction information in the third mapping table; the third resource object construction information is the resource object construction information corresponding to the second resource object identifier; the first sequence is used to indicate the creation order between the second graphics pipeline and the fourth resource object; the second graphics pipeline is the graphics pipeline corresponding to the second resource object construction information; and the fourth resource object is the resource object corresponding to the second resource object identifier.
[0014] In this way, since multiple resource data blocks in the first description file can be processed into tables that record the mapping relationship between resource object identifiers and resource object construction information structures, the electronic device can locate which table to look up based on the resource type, and then quickly find the corresponding resource object construction information based on the resource object identifier as an index, so as to quickly generate the corresponding first sequence. This allows the electronic device to accurately complete the creation of the graphics pipeline according to the first sequence, thereby improving the reliability of the pre-created graphics pipeline of the electronic device.
[0015] In one possible implementation, creating at least one graphics pipeline according to at least one first sequence includes: according to the first sequence corresponding to the second resource object construction information, based on the second resource object identifier included in the second resource object construction information, obtaining third resource object construction information corresponding to the second resource object identifier from a third mapping table storing the second resource object identifier; and creating a fourth resource object based on the third resource object construction information to obtain a first resource handle of the fourth resource object; and creating a second graphics pipeline corresponding to the second resource object construction information based on the second resource object construction information and the first resource handle.
[0016] Thus, since the electronic device can locate the table to be searched according to the resource type in the first sequence mentioned above, and then quickly find the corresponding resource object construction information based on the resource object identifier, the corresponding resource object can be created quickly, thereby improving the efficiency of the electronic device in pre-creating the graphics pipeline.
[0017] In one possible implementation, the creation of the second graphics pipeline corresponding to the second resource object construction information based on the second resource object construction information and the first resource handle includes: obtaining the second resource object construction information from the second mapping table; and if the second resource object construction information includes a second resource object identifier, updating the second resource object identifier in the second resource object construction information to the first resource handle, and creating the second graphics pipeline corresponding to the second resource object construction information based on the updated second resource object construction information.
[0018] Thus, since the resource object identifier included in the second resource object construction information can be replaced with the corresponding first resource handle, the second graphics pipeline can be successfully created, thereby improving the reliability of the electronic device in creating the graphics pipeline.
[0019] In one possible implementation, updating the second resource object identifier in the second resource object construction information to the first resource handle includes: searching for the first resource handle corresponding to the second resource object identifier in the fourth mapping table, and updating the second resource object identifier in the second resource object construction information to the first resource handle.
[0020] Thus, after creating a resource object and obtaining its resource handle, the resource handle and resource object identifier of the resource object can be stored in the fourth mapping table. Therefore, when the second resource object identifier is included in the second resource object construction information, the first resource handle corresponding to the second resource object identifier can be quickly and accurately obtained by querying the fourth mapping table. Then, the second resource object identifier included in the second resource object construction information can be replaced with the corresponding first resource handle to successfully create the second graphics pipeline, thereby improving the reliability of the electronic device in creating graphics pipelines.
[0021] In one possible implementation, before creating the second graphics pipeline corresponding to the second resource object construction information based on the second resource object construction information and the first resource handle, the method further includes: constructing a fourth mapping table; and storing the mapping relationship between the second resource object identifier and the first resource handle in the fourth mapping table.
[0022] Thus, after creating a resource object and obtaining its resource handle, the resource handle and its resource object identifier can be stored in the fourth mapping table. Therefore, when the second resource object construction information includes the second resource object identifier, the first resource handle corresponding to the second resource object identifier can be quickly and accurately obtained by querying the fourth mapping table.
[0023] In one possible implementation, before obtaining the first description file, the method further includes: if the second application creates a third graphics pipeline, intercepting and saving fourth resource object construction information, wherein the fourth resource object construction information is the resource object construction information corresponding to the third graphics pipeline; if the fourth resource object construction information contains a second resource handle, replacing the second resource handle with a third resource object identifier to obtain updated fourth resource object construction information; the second resource handle is the resource handle corresponding to a fifth resource object; the third resource object identifier is the resource object identifier corresponding to the fifth resource object; and based on the updated fourth resource object construction information, generating a resource data block corresponding to the third graphics pipeline, wherein the resource data block corresponding to the third graphics pipeline is the resource data block in the first description file.
[0024] Thus, since electronic devices can replace the resource handle in the resource object construction information with the resource object identifier of the corresponding resource object, the generated resource data block can be applied to different electronic devices. This avoids the problem that when the resource data block is stored in different models of electronic devices without replacing the resource handle, the resource object construction information cannot be restored based on the resource data block, and thus the corresponding resource object cannot be reconstructed.
[0025] In one possible implementation, before replacing the second resource handle with the third resource object identifier to obtain the updated fourth resource object construction information when the fourth resource object construction information includes the second resource handle, the method further includes: intercepting and saving the fifth resource object construction information and the second resource handle when the second application creates a fifth resource object; the fifth resource object construction information is the resource object construction information corresponding to the fifth resource object; the second resource handle is the resource handle corresponding to the fifth resource object, which is obtained after the graphics card driver successfully creates the fifth resource object; calculating the third resource object identifier corresponding to the fifth resource object based on the fifth resource object construction information; and recording the mapping relationship between the third resource object identifier and the second resource handle.
[0026] Thus, since the mapping relationship between resource object identifiers and resource handles can be recorded, when a resource object construction information contains a certain resource handle, the electronic device can replace the resource handle in the resource object construction information with the resource object identifier of the corresponding resource object based on the mapping relationship. Therefore, the generated resource data block can be applied to different electronic devices, ensuring the reliability of subsequent resource object creation based on the resource data block.
[0027] Secondly, embodiments of this application provide a graphics pipeline creation apparatus, which includes a processing module. The processing module is configured to: acquire graphics pipeline creation request information sent by a first application; the graphics pipeline creation request information is used to request the creation of a first graphics pipeline; and acquire pre-compiled binary data of the first graphics pipeline from a pipeline cache via the graphics card driver of an electronic device; the pipeline cache includes pre-compiled binary data of at least one graphics pipeline; and create the first graphics pipeline based on the pre-compiled binary data.
[0028] In one possible implementation, the above-mentioned processing module is further configured to obtain a first description file before obtaining the graphics pipeline creation request information sent by the first application; the first description file is used to describe the creation information of at least one graphics pipeline; and create at least one graphics pipeline based on the first description file; and pre-compile at least one graphics pipeline through the graphics card driver to obtain pre-compiled binary data of at least one graphics pipeline.
[0029] In one possible implementation, the first description file mentioned above includes multiple resource data blocks; each resource data block corresponds to a resource object; each resource data block includes: the resource type of the resource object, the resource object construction information, and the resource object identifier; wherein, the resource object includes any one of the following: a graphics pipeline, or a resource object referenced when creating a graphics pipeline.
[0030] In one possible implementation, when the creation of the first resource object requires a reference to the second resource object, the construction information of the first resource object includes a first resource object identifier; wherein, the first resource object construction information is the resource object construction information included in the first resource data block; the first resource data block is the resource data block corresponding to the first resource object among multiple resource data blocks; and the first resource object identifier is the resource object identifier of the second resource object.
[0031] In one possible implementation, the aforementioned processing module is specifically used to parse the first description file to obtain multiple resource data blocks; and based on the multiple resource data blocks, determine at least one first sequence; the first sequence is used to indicate the creation order of the graphics pipeline and the third resource object; the third resource object is the resource object that needs to be referenced when creating the graphics pipeline; and create at least one graphics pipeline according to at least one first sequence.
[0032] In one possible implementation, the aforementioned processing module is specifically configured to construct at least two first mapping tables based on the resource types of resource objects corresponding to multiple resource data blocks; each first mapping table stores a mapping relationship between at least one resource object identifier and at least one resource object construction information; all resource object identifiers stored in each first mapping table indicate the same resource type of the resource objects; and, if the second resource object construction information includes the second resource object identifier, determine a third mapping table storing the second resource object identifier from the at least two first mapping tables; the second resource object construction information is any resource object construction information in the second mapping table; the second mapping table is a mapping table among the at least two first mapping tables, and the resource type of the resource object indicated by the resource object identifier in the second mapping table is a graphics pipeline; and, based on the second resource object construction information and the third resource object construction information in the third mapping table, determine a first sequence corresponding to the second resource object construction information; the third resource object construction information is the resource object construction information corresponding to the second resource object identifier; the first sequence is used to indicate the creation order between the second graphics pipeline and the fourth resource object; the second graphics pipeline is the graphics pipeline corresponding to the second resource object construction information; and the fourth resource object is the resource object corresponding to the second resource object identifier.
[0033] In one possible implementation, the above-mentioned processing module is specifically used to obtain, according to the first sequence corresponding to the second resource object construction information, and based on the second resource object identifier included in the second resource object construction information, obtain the third resource object construction information corresponding to the second resource object identifier from the third mapping table storing the second resource object identifier; and based on the third resource object construction information, create a fourth resource object to obtain the first resource handle of the fourth resource object; and based on the second resource object construction information and the first resource handle, create a second graphics pipeline corresponding to the second resource object construction information.
[0034] In one possible implementation, the above processing module is specifically used to obtain the second resource object construction information from the second mapping table; and if the second resource object construction information includes a second resource object identifier, update the second resource object identifier in the second resource object construction information to a first resource handle, and create a second graphics pipeline corresponding to the second resource object construction information based on the updated second resource object construction information.
[0035] In one possible implementation, the aforementioned processing module is specifically used to look up the first resource handle corresponding to the second resource object identifier from the fourth mapping table, and update the second resource object identifier in the second resource object construction information to the first resource handle.
[0036] In one possible implementation, the above processing module is further configured to construct a fourth mapping table before creating the second graphics pipeline corresponding to the second resource object construction information based on the second resource object construction information and the first resource handle; and store the mapping relationship between the second resource object identifier and the first resource handle in the fourth mapping table.
[0037] In one possible implementation, the aforementioned processing module is further configured to, before obtaining the first description file, intercept and save fourth resource object construction information when the second application creates the third graphics pipeline, wherein the fourth resource object construction information is the resource object construction information corresponding to the third graphics pipeline; and if the fourth resource object construction information contains a second resource handle, replace the second resource handle with a third resource object identifier to obtain updated fourth resource object construction information; wherein the second resource handle is the resource handle corresponding to the fifth resource object; the third resource object identifier is the resource object identifier corresponding to the fifth resource object; and generate a resource data block corresponding to the third graphics pipeline based on the updated fourth resource object construction information, wherein the resource data block corresponding to the third graphics pipeline is the resource data block in the first description file.
[0038] In one possible implementation, the aforementioned processing module is further configured to, when the fourth resource object construction information includes a second resource handle, replace the second resource handle with a third resource object identifier to obtain the updated fourth resource object construction information, and before the second application creates a fifth resource object, intercept and save the fifth resource object construction information and the second resource handle; the fifth resource object construction information is the resource object construction information corresponding to the fifth resource object; the second resource handle is the resource handle corresponding to the fifth resource object, which is obtained after the graphics card driver successfully creates the fifth resource object; and calculate the third resource object identifier corresponding to the fifth resource object based on the fifth resource object construction information; and record the mapping relationship between the third resource object identifier and the second resource handle.
[0039] Thirdly, embodiments of this application provide an electronic device including a processor and a memory, wherein the memory stores programs or instructions executable on the processor, and the programs or instructions, when executed by the processor, implement the steps of the method described in the first aspect.
[0040] Fourthly, embodiments of this application provide a readable storage medium on which a program or instructions are stored, which, when executed by a processor, implement the steps of the method described in the first aspect.
[0041] Fifthly, embodiments of this application provide a chip, the chip including a processor and a communication interface, the communication interface being coupled to the processor, the processor being used to run programs or instructions to implement the method as described in the first aspect.
[0042] In a sixth aspect, embodiments of this application provide a computer program product stored in a storage medium, which is executed by at least one processor to implement the method described in the first aspect.
[0043] In this embodiment, a graphics pipeline creation request information sent by a first application is obtained; the graphics pipeline creation request information is used to request the creation of a first graphics pipeline; through the graphics card driver of the electronic device, the pre-compiled binary data of the first graphics pipeline is obtained from the pipeline cache, and the pre-compiled binary data is loaded; the pipeline cache includes binary data after pre-compiling at least one graphics pipeline; based on the pre-compiled binary data, the first graphics pipeline is created. In this solution, since the pre-compiled binary data of the first graphics pipeline can be obtained from the pipeline cache, the first graphics pipeline can be created directly through this pre-compiled binary data, without having to compile the construction information of the first graphics pipeline on-site, thereby significantly shortening the creation time of the first graphics pipeline, avoiding rendering thread blocking, and thus reducing frame drops or stuttering during the display of the electronic device. Attached Figure Description
[0044] Figure 1 This is a schematic diagram illustrating an example of the creation timing of a graphical pipeline provided in some embodiments of this application;
[0045] Figure 2 This is a flowchart of a graphical pipeline creation method provided in some embodiments of this application;
[0046] Figure 3 This is a flowchart of a graphical pipeline creation method provided in some embodiments of this application;
[0047] Figure 4 These are schematic diagrams illustrating examples of resource interception provided in some embodiments of this application;
[0048] Figure 5 This is a schematic diagram of the structure of a graphical pipeline creation apparatus provided in some embodiments of this application;
[0049] Figure 6 These are schematic diagrams of the hardware structure of electronic devices provided in some embodiments of this application;
[0050] Figure 7 These are schematic diagrams of the hardware structure of electronic devices provided in some embodiments of this application. Detailed Implementation
[0051] The technical solutions of the embodiments of this application will be clearly described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application are within the scope of protection of this application.
[0052] The terms "first," "second," etc., used in this application's specification are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such terms can be used interchangeably where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein, and the objects distinguished by "first," "second," etc., are generally of the same class, without limiting the number of objects. For example, a first object can be one or more, where "more" means at least two. Furthermore, in the specification, "and / or" indicates at least one of the connected objects, and the character " / " generally indicates that the preceding and following objects are in an "or" relationship.
[0053] The terms "at least one" and "at least one of" in this application's specification refer to any one, any two, or a combination of two or more of the included objects. For example, "at least one of a, b, and c" can mean "a", "b", "c", "a and b", "a and c", "b and c", and "a, b, and c", where a, b, and c can be single or multiple, and multiple means at least two. Similarly, "at least two" means two or more, and its meaning is similar to "at least one". The identifiers in this application are text, symbols, images, etc., used to indicate information, and can use controls or other containers as carriers for displaying information, including but not limited to text identifiers, symbol identifiers, and image identifiers.
[0054] The terminology used in the implementation section of this application is only for explaining specific embodiments of this application and is not intended to limit this application. The terminology involved in the embodiments of this application is explained below.
[0055] Resource Handle: A temporary numerical identifier representing a specific resource in the graphics card's video memory. It is randomly assigned by the graphics card driver during the current program execution. Characteristic: Volatility. For the same resource (e.g., an identical sampler configuration), the handle assigned today might be 1001, but after restarting the phone tomorrow, the handle might be 2048. Its role in this application: Resource handles are objects we need to "eliminate" and "replace." Because they are random and cannot be reused across devices or time periods, we must replace them with stable "unique identifiers" during the recording phase. A simple analogy: It's like checking into a hotel and receiving a room key (handle). Today you stay in room 101, and the key only works for room 101. Next week, you might stay in room 205, and the previous key will be invalid. But your ID number (unique identifier) remains unchanged.
[0056] Resource Object Identifier (Hash): A fixed-length digital fingerprint generated based on the resource's content (parameter configuration) using a specific mathematical algorithm (such as the FNV-1a hash algorithm). Characteristic: Stability. As long as the resource's content (such as color, size, and format) remains unchanged, the calculated value will always be the same regardless of the phone used or the time of calculation. Its role in this application: It serves as the resource's "ID number," used to replace unstable "handles" in storage files, enabling cross-device identification. A simple analogy: a person's ID number.
[0057] FNV-1a (Fowler–Noll–Vo variant 1a) is a non-cryptographic hash algorithm that maps data of arbitrary length to a 64-bit positive integer by performing an exclusive OR (XOR) operation on each field in a data block and prime multiplication. This algorithm is extremely fast and ensures that even small changes to the input data (such as modifying a single configuration bit) will result in a significant change in the generated "unique identifier" (avalanche effect), making it ideal for deduplication and indexing.
[0058] Graphics Pipeline: The "pipeline" state object used by the graphics card for graphics rendering. It is a very complex collection containing all the instructions that tell the graphics card "how to draw," such as shader programs, rasterization states, and blending modes. Its role in this application: This is the final target object that this application will construct. Because constructing it is very time-consuming (requiring code compilation), we will pre-record and replay it.
[0059] Pipeline Cache: Binary data generated after the graphics card driver compiles the "pipeline". Its role in this application: This is the output of this solution. With it, the driver can directly load this cache the next time the program runs, skipping the cumbersome compilation process and instantly entering the application interface. A simple analogy: pre-cooked food. Without pre-cooking, when a customer orders (program runs), the chef has to buy, cut, and cook the ingredients on the spot (real-time compilation), which is very slow; with pre-cooked food (cache), it can be heated up and served immediately.
[0060] The rendering context is the "environment" or "session state" through which an application communicates with the Graphics Processing Unit (GPU). In Vulkan, it is specifically represented by objects such as VkInstance and VkDevice. It records who is currently operating the graphics card, what configuration is being used to operate the graphics card, and what memory the graphics card has allocated to the current program. Without this context, the graphics card cannot recognize and execute any instructions issued by the application (such as "create a buffer") because it does not know who these instructions belong to. Its role in this application: It is a prerequisite for the creation of any resources (pipelines, samplers, etc.). A simple analogy: an artist's studio (workbench). The graphics card is the artist (the one doing the work). The application is the client (the one making the request). The context is the studio. A client cannot just randomly ask an artist to paint on the street; they must invite the artist into a studio with prepared paints, canvas, and lighting before the artist can begin working. Note: Different applications (such as games and browsers) have their own independent studios and do not interfere with each other.
[0061] Virtual Rendering Context: This application constructs an invisible, background rendering context for "pre-compilation." It possesses a complete and valid device handle (capable of calling driver interfaces normally), but it is not connected to the display screen (does not output images) and does not handle user input (such as touch or clicks). It typically runs in a separate background thread, completely isolated from the main program's rendering business logic. Its role in this application: It serves as a vehicle for achieving "detachment from business logic" and "resource reconstruction." By constructing this virtual environment, we can "trick" the graphics card driver into thinking, "I need to draw now, quickly compile the pipeline for me," even without application business logic. The graphics card driver cannot distinguish between a "rehearsal" and "real-world application," and it will compile the resources and cache them. When the application business logic actually begins (entering the real rendering context), these caches can be directly reused.
[0062] Serialization and Deserialization: Serialization converts complex, interconnected object structures (3D data) in memory into a continuous stream of bytes or text (2D data) for writing to a file for storage. Deserialization is the reverse operation, reading data from a file and reconstructing the object in memory. In this application, step 201 is deserialization (reading from disk), and step 906 is serialization (storing to disk). A simple analogy: packing and reassembling detachable furniture. Serialization: Disassembling the assembled cabinet into individual panels and packing them into a flat cardboard box (storing a file). Deserialization: Taking the panels out of the box and reassembling them into the cabinet according to the instructions (restoring the object in memory).
[0063] Dereference and Data Cleaning: In programming, a pointer stores only a memory address (e.g., 0x1234ABCD), which points to the actual location where the data is stored. Dereference is the process of "finding the real data by following the address." Its role in this application: During recording, we cannot store the address 0x1234ABCD (because the address will change the next time it runs); we must store the actual content stored at that address. This is called "cleaning." A simple analogy: If I write "Go to the third shelf in the library" on a piece of paper (this is a pointer), you might not find the book because it might have been checked out. I must photocopy the contents of the book (this is dereference / cleaning), so that no matter how the bookshelf changes, the content is preserved.
[0064] Hook (or intercept): A legitimate system programming technique that allows us to forcibly insert our own code before or after an application calls a system function (such as creating a resource). Its role in this application: We need to secretly "copy" the parameters of the resource creation function without the application's knowledge. A common analogy: wiretapping or intercepting mail. A sends a letter to B, C intercepts the letter at the post office, makes a copy for record-keeping, and then sends the letter to B. Neither A nor B knows of C's existence.
[0065] Dependency Tree: A hierarchical reference relationship between resources. A depends on B, and B depends on C. Its role in this application: This relationship must be clearly defined. If A is created first, creation will fail because B does not yet exist. A simple analogy: the order in which a house is built. The roof (pipes) depends on the walls (pipeline layout), and the walls depend on the foundation (descriptor layout). You cannot build the roof first.
[0066] The Vulkan Graphics Pipeline's Resource Dependency Tree and Build Sequence: In the Vulkan architecture, the Graphics Pipeline is not an isolated object, but a composite object composed of nested and combined basic resources. This nesting relationship forms a "resource dependency tree," such as... Figure 1 As shown: The dependency structure of the graph pipeline includes the root node, first-level dependencies, and multi-level nested dependencies:
[0067] Root node: Graphics Pipeline (VkPipeline).
[0068] First-level dependencies: Pipelines directly reference pipeline layout (VkPipelineLayout) resource handles, shader stage structures (VkPipelineShaderStageCreateInfo), etc.
[0069] Multi-level nested dependencies: A first-level dependent object may continue to reference resources at lower levels.
[0070] For example, the resource "PipelineLayoutCreateInfo" internally depends on "DescriptorSetLayout".
[0071] For example, the resource "Shader Stage Structure (VkPipelineShaderStageCreateInfo)" internally depends on the "Shader Module (VkShaderModule) resource handle".
[0072] The construction sequence of the graphics pipeline: When creating resource objects, the application (developer) must follow a strict "resource dependency" order. That is, leaf nodes (e.g., descriptor layout resource handles) must be created first. Only after obtaining their handles can intermediate nodes (e.g., pipeline layout resource handles) be created. Finally, these resource handles can be used to create the root node, i.e., the graphics pipeline. If the resource dependencies are not constructed in the correct order, the graphics pipeline cannot be built correctly.
[0073] Topological sorting: An algorithm used to transform a dependency tree into a linear list of tasks to be executed, ensuring that all its prerequisite tasks have been completed before any task is executed. Its role in this application: In the second stage (replay), it's used to determine the order in which tasks are created. A simple analogy: the instructions for Lego bricks. The instructions use a sorting method to tell you that you must assemble the base first, then the body, and finally the wheels.
[0074] JSON format: A lightweight data exchange format that is easy for humans to read and write, and also easy for machines to parse and generate. A common analogy: a "standardized shopping list".
[0075] Key-value pairs: The most basic unit of data in JSON and hash tables. They consist of a "key" (equivalent to a label or name) and a "value" (equivalent to content). Example: "Name": "Zhang San", where "Name" is the key and "Zhang San" is the value. "Age": 25, where "Age" is the key and 25 is the value. Applications in this application: Mapping tables: {handle: unique identifier}; File storage: {unique identifier: {specific construction parameters...}}.
[0076] Vulkan Graphics Pipeline Technology Overview: With the rapid improvement of mobile terminal and desktop hardware performance, Vulkan, as a new generation of cross-platform, low-overhead graphics API, is widely used in high-performance games, virtual reality (VR), and professional graphics design software. Unlike the traditional OpenGL API, Vulkan adopts an "explicit control" design philosophy, one of the core objects of which is the graphics pipeline. The graphics pipeline can be understood as a pipeline inside the GPU. It encapsulates all the state information required to draw an object, mainly including:
[0077] Shader modules, such as vertex shaders and fragment shaders, are pieces of code that run on the GPU and are usually in the form of SPIR-V (an intermediate language format).
[0078] Fixed function states: such as rasterization mode (whether to draw lines or triangles), depth test (to determine object occlusion relationships), color blending (for semi-transparent effects), etc.
[0079] Resource layout: such as pipeline layout, describes how shaders read external data such as textures and matrices.
[0080] When an application is running and needs to render a scene, a pipeline object must first be created and compiled. During this process, the graphics card driver compiles all the information used to build the pipeline, ultimately generating machine instruction code that can be understood by the current graphics card hardware.
[0081] The graphical pipeline creation method provided in this application will be described in detail below with reference to the accompanying drawings, through specific embodiments and application scenarios.
[0082] The graphical pipeline creation method provided in this application embodiment can be applied to scenarios where graphical pipelines are created.
[0083] The preview image display method provided in this application can be executed by a graphics pipeline creation device, which can be an electronic device, or a functional module or entity within an electronic device. The following description uses an electronic device as an example to illustrate the technical solution provided in this application.
[0084] This application provides a method for creating a graphical pipeline. Figure 2 A flowchart illustrating a graphical pipeline creation method provided in an embodiment of this application is shown. Figure 2 As shown, the graphical pipeline creation method provided in this application embodiment may include the following steps 201 to 203.
[0085] Step 201: The electronic device obtains the graphics pipeline creation request information sent by the first application.
[0086] In some embodiments of this application, the above-mentioned graphics pipeline creation request information is used to request the creation of a first graphics pipeline.
[0087] In some embodiments of this application, the first application described above can be any application that needs to create a graphics pipeline.
[0088] Examples include: game applications, engineering applications, 3D modeling applications, virtual reality (VR) applications, and augmented reality (AR) applications.
[0089] In some embodiments of this application, the first graphics pipeline can be any graphics pipeline that the electronic device can create, such as a forward rendering pipeline, a deferred shading pipeline, a chunked forward rendering pipeline, etc. The specific implementation can be determined according to actual usage requirements, and this application does not limit this.
[0090] For example, when the first application starts, the first application may request the creation of a graphics pipeline.
[0091] For example, when 3D modeling software is opened, it can request the creation of pipelines for different viewport display modes such as wireframe, solid shading, and material preview.
[0092] For example, when the first application resources are loaded, the first application may request the creation of a graphics pipeline.
[0093] For example, when entering an underwater level in a game application, the game application can request the creation of a dedicated rendering pipeline for rendering distortion effects.
[0094] Step 202: The electronic device obtains the pre-compiled binary data of the first graphics pipeline from the pipeline cache through the graphics card driver of the electronic device.
[0095] In some embodiments of this application, the pipeline cache includes pre-compiled binary data of at least one graphics pipeline.
[0096] It is understandable that the pipeline cache mentioned above can also be understood as: the binary data generated by the graphics driver after the "graphics pipeline" is pre-compiled.
[0097] In some embodiments of this application, after the electronic device obtains the graphics pipeline creation request information sent by the first application, the graphics card driver of the electronic device can search for the pre-compiled binary data of the first graphics pipeline from the pipeline cache, and load the pre-compiled binary data after finding it.
[0098] Step 203: The electronic device creates the first graphics pipeline based on the pre-compiled binary data.
[0099] In some embodiments of this application, the electronic device may load pre-compiled binary data to create a first graphics pipeline.
[0100] Specifically, electronic devices can load pre-compiled binary data through the graphics card driver, and then generate a renderable first graphics pipeline based on the loaded binary data.
[0101] In the graphics pipeline creation method provided in this application embodiment, since the pre-compiled binary data of the first graphics pipeline can be obtained from the pipeline cache, the first graphics pipeline can be created directly through the pre-compiled binary data without having to compile the construction information of the first graphics pipeline on-site. This significantly shortens the creation time of the first graphics pipeline, avoids rendering thread blocking, and reduces frame drops or stuttering during the display of electronic devices.
[0102] In some embodiments of this application, combined with Figure 2 ,like Figure 3 As shown, prior to step 201 above, the graphical pipeline creation method provided in this application embodiment further includes steps 301 to 303 as described below.
[0103] Step 301: The electronic device obtains the first description file.
[0104] In some embodiments of this application, the first description file described above is used to describe the creation information of at least one graphics pipeline.
[0105] In some embodiments of this application, the first description file described above may be stored locally.
[0106] In some embodiments of this application, the first description file described above may be deployed on electronic devices via OTA upgrades or pre-installation.
[0107] In some embodiments of this application, the first description file mentioned above includes multiple resource data blocks; each resource data block corresponds to a resource object; each resource data block includes: the resource type of the resource object, the resource object construction information, and the resource object identifier.
[0108] In some embodiments of this application, the above-mentioned resource object construction information can be understood as a resource object construction information structure, which includes the resource type and resource object identifier of the resource object.
[0109] In some embodiments of this application, the resource objects mentioned above include any one of the following: a graphics pipeline, or resource objects that need to be referenced when creating a graphics pipeline.
[0110] In some embodiments of this application, the resource objects referenced for creating the graphics pipeline can be understood as resource objects on which the graphics pipeline depends. For example, when creating a graphics pipeline requires first creating a shader, the resource object referenced for creating the graphics pipeline is the shader.
[0111] In some embodiments of this application, when the creation of a first resource object requires referencing a second resource object, the first resource object construction information includes a first resource object identifier; wherein, the first resource object construction information is the resource object construction information included in the first resource data block; the first resource data block is the resource data block corresponding to the first resource object among a plurality of resource data blocks; and the first resource object identifier is the resource object identifier of the second resource object.
[0112] In some embodiments of this application, since each resource data block includes a resource object identifier for the corresponding resource object, which is used to uniquely indicate a certain resource object, and when the creation of the first resource object requires referencing the second resource object, the first resource object construction information corresponding to the first resource object also includes the first resource object identifier of the second resource object, not the resource handle, the resource object construction information corresponding to the second resource object can be found based on the first resource object identifier, so that after the second resource object is successfully created, the first resource object can be successfully created, that is, the first resource object can be reconstructed in any type of electronic device.
[0113] Step 302: The electronic device creates at least one graphics pipeline based on the first description file.
[0114] Step 303: The electronic device pre-compiles at least one graphics pipeline through the graphics card driver to obtain pre-compiled binary data of at least one graphics pipeline.
[0115] Thus, since at least one graphics pipeline can be created in advance based on the first description file, and the at least one graphics pipeline can be pre-compiled to obtain pre-compiled binary data of at least one graphics pipeline, the graphics pipeline can be created directly using these pre-compiled binary data in the future, without having to compile the construction information of the graphics pipeline on-site. This significantly shortens the creation time of the first graphics pipeline, avoids rendering thread blocking, and reduces frame drops or stuttering during the display of electronic devices.
[0116] In some embodiments of this application, step 302 can be specifically implemented by steps 401 to 403 as described below.
[0117] Step 401: The electronic device parses the first description file to obtain multiple resource data blocks.
[0118] Step 402: The electronic device determines at least one first sequence based on multiple resource data blocks.
[0119] In some embodiments of this application, the first sequence is used to indicate the creation order of the graphics pipeline and the third resource object; the third resource object is a resource object that needs to be referenced when creating the graphics pipeline.
[0120] In some embodiments of this application, the first sequence described above can be understood as an ordered linear execution sequence.
[0121] In some embodiments of this application, the first sequence may include resource object identifiers of third resource objects and resource object identifiers of graphics pipelines arranged in sequence. The electronic device may determine the creation order of the third resource object and the graphics pipeline based on the arrangement order of the resource object identifiers of the third resource object and the resource object identifiers of the graphics pipeline.
[0122] In some embodiments of this application, the first sequence described above may be a topological sort.
[0123] Understandably, since Vulkan resource creation must strictly follow a sequence (i.e., child resources must be created before parent resources), and the data stored in the first description file is flattened, the core of step 402 is to transform the flattened data into an ordered linear execution list.
[0124] It is understandable that pipeline resource construction must follow dependency timing (i.e., child resources such as samplers and layouts must be created before the parent resource pipeline can be created). This application designs a deep recursive scanning and topology sorting algorithm. This algorithm can automatically identify the dependency tree between resources by statically parsing the description file without the involvement of application business logic, and reorganize the flattened storage data into a strictly ordered linear execution list, ensuring that the reconstruction process will not encounter "dependency missing" or "deadlock".
[0125] In some embodiments of this application, step 402 can be specifically implemented by steps 501 to 503 as described below.
[0126] Step 501: The electronic device constructs at least two first mapping tables based on the resource types of the resource objects corresponding to multiple resource data blocks.
[0127] In some embodiments of this application, each first mapping table stores a mapping relationship between at least one resource object identifier and at least one resource object construction information; all resource object identifiers stored in each first mapping table indicate the same resource type of the resource objects.
[0128] It is understood that an electronic device can resolve multiple resource data blocks into at least two first mapping tables classified by resource type (Tag), with each first mapping table corresponding to a resource type.
[0129] For example, an electronic device can construct three first mapping tables based on the resource types of resource objects corresponding to multiple resource data blocks. The resource type corresponding to the first first mapping table is graphics pipeline, and the resource type corresponding to at least one resource object identifier stored in this first mapping table is graphics pipeline. The resource type corresponding to the second first mapping table is pipeline layout, and the resource type corresponding to at least one resource object identifier stored in this first mapping table is pipeline layout. The resource type corresponding to the third first mapping table is descriptor set layout, and the resource type corresponding to at least one resource object identifier stored in this first mapping table is descriptor set layout.
[0130] In some embodiments of this application, each first mapping table records a collection of structured objects of {resource object identifier: resource object construction information}.
[0131] In some embodiments of this application, the above-mentioned resource object identifier can be understood as a unique identifier for a resource object.
[0132] In some embodiments of this application, the above-mentioned resource object construction information can be understood as resource general standard construction information.
[0133] In this way, the first description file is processed by the electronic device into a series of "tables" that record the mapping relationship between resource object identifiers and resource object construction information structures. The electronic device can locate which table to look up based on the resource type, and quickly find the corresponding general standard construction information structure object using the resource object identifier (Hash) as an index.
[0134] Step 502: If the second resource object construction information includes a second resource object identifier, the electronic device determines a third mapping table storing the second resource object identifier from at least two first mapping tables.
[0135] In some embodiments of this application, the second resource object construction information is any resource object construction information in the second mapping table; the second mapping table is a mapping table of at least two first mapping tables, and the resource type of the resource object indicated by the resource object identifier in the second mapping table is a graphics pipeline.
[0136] It is understandable that if the second resource object construction information includes the second resource object identifier, the creation of the second graphics pipeline can be considered to require a reference to the fourth resource object. Therefore, it is necessary to determine the creation order of the second graphics pipeline and the fourth resource object for subsequent creation of the second graphics pipeline.
[0137] In some embodiments of this application, the second graphics pipeline is the graphics pipeline corresponding to the second resource object construction information.
[0138] In some embodiments of this application, the aforementioned fourth resource object is the resource object corresponding to the second resource object identifier. It can also be understood as: the fourth resource object is the resource object referenced when creating the second graphics pipeline.
[0139] For example, if the pipelineLayouts collection contains pipeline layout construction information with hash 33b8d83bdc97ec64, and the pipeline layout resource object internally references the descriptor set construction information with hash cb3985cfac50f424 from the descriptorSetLayouts collection, then the pipeline layout construction information includes the resource object identifier: cb3985cfac50f424.
[0140] In some embodiments of this application, if a third mapping table storing the second resource object identifier is not determined from at least two first mapping tables, the current scan is terminated, and the first sequence corresponding to the second resource object construction information is marked as invalid, i.e., the second graphics pipeline cannot be reconstructed.
[0141] In some embodiments of this application, when the second resource object construction information does not include other resource object identifiers, the electronic device can determine that the creation of the second graphics pipeline does not depend on other resource objects, and the electronic device can directly create the second graphics pipeline.
[0142] In some embodiments of this application, the electronic device may employ a depth-first scanning algorithm to perform a dependency scan on the construction information of the second resource object in order to establish a first sequence corresponding to the construction information of the second resource object.
[0143] Step 503: The electronic device determines the first sequence corresponding to the second resource object construction information based on the second resource object construction information and the third resource object construction information in the third mapping table.
[0144] In some embodiments of this application, the third resource object construction information is the resource object construction information corresponding to the second resource object identifier.
[0145] In some embodiments of this application, the first sequence described above is used to indicate the creation order between the second graphics pipeline and the fourth resource object.
[0146] In some embodiments of this application, the first sequence mentioned above can also be understood as: the first sequence corresponding to the second graphics pipeline.
[0147] It is understandable that when the second resource object construction information includes the second resource object identifier, the electronic device needs to first determine the third mapping table storing the second resource object identifier, and then obtain the third resource object construction information corresponding to the second resource object identifier from the third mapping table, so as to determine the first sequence corresponding to the second resource object construction information based on the second resource object construction information and the third resource object construction information.
[0148] In some embodiments of this application, when the resource object identifiers of other resource objects are not included in the third resource object construction information, the electronic device can determine that the creation of the second graphics pipeline depends only on the fourth resource object. Then, the second resource object identifier corresponding to the fourth resource object and the resource object identifier corresponding to the second graphics pipeline can be added sequentially to the first sequence corresponding to the second resource object construction information. That is, the first sequence corresponding to the second resource object construction information is determined to be: the fourth resource object is created first, and then the second graphics pipeline is created.
[0149] For example: Suppose the fourth resource object is a pipeline layout. The construction information of the third resource object corresponding to the pipeline layout does not include resource object identifiers of other resource objects. The electronic device can determine that the creation of the second graphics pipeline depends only on the pipeline layout. Then, it can add the second resource object identifier corresponding to the pipeline layout and the resource object identifier corresponding to the second graphics pipeline to the first sequence corresponding to the construction information of the second resource object in sequence. That is, the first sequence corresponding to the construction information of the second resource object is determined to be: first create the pipeline layout, then create the second graphics pipeline.
[0150] In some embodiments of this application, when the third resource object construction information includes a fourth resource object identifier, the electronic device can determine a fifth mapping table storing the fourth resource object identifier from at least two first mapping tables, and then obtain the sixth resource object construction information corresponding to the fourth resource object identifier from the fifth mapping table. When the sixth resource object construction information does not include other resource object identifiers, the electronic device can determine that the creation of the fourth resource object depends on the sixth resource object, and the sixth resource object is the resource object corresponding to the fourth resource object identifier. Then, the electronic device can sequentially add the fourth resource object identifier corresponding to the sixth resource object, the second resource object identifier corresponding to the fourth resource object, and the resource object identifier corresponding to the second graphics pipeline to the first sequence corresponding to the second resource object construction information. That is, the first sequence corresponding to the second resource object construction information is determined to be: first create the sixth resource object, then create the fourth resource object, and then create the second graphics pipeline.
[0151] For example: Suppose the fourth resource object is a pipeline layout, the third resource object construction information corresponding to the pipeline layout includes the resource object identifier of the descriptor set layout, and the sixth resource object construction information corresponding to the descriptor set layout does not include other resource object identifiers. The electronic device can determine that the creation of the second graphics pipeline depends on the pipeline layout, and the creation of the pipeline layout depends on the descriptor set layout. Then, it can sequentially add the fourth resource object identifier corresponding to the descriptor set layout, the second resource object identifier corresponding to the pipeline layout, and the resource object identifier corresponding to the second graphics pipeline to the first sequence corresponding to the second resource object construction information. That is, the first sequence corresponding to the second resource object construction information is determined to be: first create the descriptor set layout, then create the pipeline layout, and finally create the second graphics pipeline.
[0152] In some embodiments of this application, the second graphics pipeline itself is added to the first sequence only after all resource objects on which the creation of the second graphics pipeline depends have been scanned and added to the first sequence, so as to ensure the construction timing.
[0153] It is understandable that the electronic device can first look up the second mapping table corresponding to the resource type "image pipeline" from at least two first mapping tables, and then, for each resource object construction information in the second mapping table, the electronic device can determine a first sequence, which is used to indicate the creation order between the graphics pipeline corresponding to each resource object construction information and the resource objects that the graphics pipeline depends on.
[0154] In some embodiments of this application, the electronic device may employ a depth-first scanning algorithm to perform a dependency scan on all resource object construction information in the second mapping table, in order to establish a first sequence corresponding to each resource object construction information:
[0155] Specifically, in the second mapping table for resource type "Graphics Pipeline," each structured object record {Resource Object Identifier: Resource Object Construction Information} is a "root node." The electronic device can use the final "Graphics Pipeline" as the root node and traverse the fields of resource object construction information in each structured object record. If it encounters a field storing the "Resource Object Identifier," it indicates a dependency, and the processing of the current resource object can be paused. The process then jumps to the sub-resource object corresponding to that hash for recursive scanning. The sub-resource object can be found in the first mapping table corresponding to the sub-resource type. If no corresponding sub-resource object is found, the scan ends, and the execution list is marked as invalid, meaning the graphics pipeline object cannot be reconstructed.
[0156] In the above process, a resource object is only added to the first sequence after all its child dependencies have been scanned and added to the first sequence, to ensure the build order. If a resource object's hash is already in the first sequence during the scan, it is skipped, i.e., deduplication is performed, ensuring that each resource object is created only once.
[0157] Finally, the electronic device can obtain a strictly ordered sequence of operations. The beginning of the sequence must be resource objects without dependencies, such as shader modules and samplers, while the end of the sequence must be the graphics pipeline objects with the most complex dependencies.
[0158] In this way, since multiple resource data blocks in the first description file can be processed into tables that record the mapping relationship between resource object identifiers and resource object construction information structures, the electronic device can locate which table to look up based on the resource type, and then quickly find the corresponding resource object construction information based on the resource object identifier as an index, so as to quickly generate the corresponding first sequence. This allows the electronic device to accurately complete the creation of the graphics pipeline according to the first sequence, thereby improving the reliability of the pre-created graphics pipeline of the electronic device.
[0159] Step 403: The electronic device creates at least one graphics pipeline according to at least one first sequence.
[0160] Thus, since the electronic device can determine the creation order between the graphics pipeline and the resource objects that need to be referenced to create the graphics pipeline, i.e. the first sequence mentioned above, the electronic device can accurately complete the creation of the graphics pipeline according to the creation order, thereby improving the reliability of the pre-created graphics pipeline of the electronic device.
[0161] In some embodiments of this application, step 403 can be specifically implemented by steps 601 to 603 as described below.
[0162] Step 601: The electronic device obtains the third resource object construction information corresponding to the second resource object identifier from the third mapping table storing the second resource object identifier, based on the first sequence corresponding to the second resource object construction information and the second resource object identifier included in the second resource object construction information.
[0163] Step 602: The electronic device constructs information based on the third resource object, creates a fourth resource object, and obtains the first resource handle of the fourth resource object.
[0164] In some embodiments of this application, the electronic device can read the static numerical parameters in the third resource object construction information and fill the static numerical parameters into the corresponding fields of the Vulkan creation structure (CreateInfo) to obtain the creation structure corresponding to the fourth resource object. Then, the Vulkan creation structure is compiled to create the fourth resource object corresponding to the third resource object construction information.
[0165] In some embodiments of this application, in a virtual rendering context, an electronic device can call the Vulkan interface to submit the construction information of a third resource object to the graphics card driver so as to create a fourth resource object through the graphics card driver. After the display driver returns success, the electronic device can obtain the first resource handle of the fourth resource object in the current runtime environment.
[0166] Understandably, to achieve resource creation independent of business logic, the electronic device first needs to ensure it is in a valid virtual rendering context. This virtual rendering context holds a valid VkDevice logical device handle but is not involved in any specific screen drawing tasks. Within this virtual rendering context, when the electronic device calls the Vulkan interface, the driver interprets it as a normal business request and proceeds with resource creation.
[0167] For example, the Vulkan interface described above may include any of the following: vkCreatePipelineLayout, vkCreateDescriptorSetLayout, or vkCreateShaderModule.
[0168] Step 603: The electronic device creates the second graphics pipeline corresponding to the second resource object construction information based on the second resource object construction information and the first resource handle.
[0169] It is understandable that the electronic device can retrieve the resource object construction information corresponding to the resource object identifiers from at least two first mapping tables in sequence according to the order of the resource object identifiers in the first sequence, and reconstruct the resource objects, that is, reconstruct them sequentially from the dependent resource objects at the head of the sequence to the graphics pipeline objects at the tail of the sequence.
[0170] In some embodiments of this application, when the electronic device determines the first sequence corresponding to the second graphics pipeline, it can directly write the resource object construction information of the second graphics pipeline and the fourth resource object into the first sequence. In this way, when creating the fourth resource object and the second graphics pipeline according to the first sequence, the electronic device can save the time of obtaining the corresponding resource object construction information from at least two first mapping tables, thereby improving the efficiency of creating the second graphics pipeline.
[0171] As can be understood, this application implements an independent reconstruction mechanism that does not depend on application rendering logic. The system constructs a virtual rendering context and creates resources sequentially according to a linear execution list. Dynamic injection: When creating upper-level resources, the system uses a reverse mapping pool {unique identifier: new runtime handle} to dynamically replace the hash in the description file with the newly generated real handle in the current virtual context. In this way, the system "tricks" the graphics card driver into thinking that this is a normal business request, thus enabling the pre-compilation and cache generation of the pipeline to be completed without relying on the application's business logic, completely solving the first-frame stuttering problem.
[0172] Thus, since the electronic device can locate the table to be searched according to the resource type in the first sequence mentioned above, and then quickly find the corresponding resource object construction information based on the resource object identifier, the corresponding resource object can be created quickly, thereby improving the efficiency of the electronic device in pre-creating the graphics pipeline.
[0173] In some embodiments of this application, step 603 can be specifically implemented by steps 701 and 702 as described below.
[0174] Step 701: The electronic device obtains the construction information of the second resource object from the second mapping table.
[0175] Step 702: If the second resource object construction information includes a second resource object identifier, the electronic device updates the second resource object identifier in the second resource object construction information to a first resource handle, and creates a second graphics pipeline corresponding to the second resource object construction information based on the updated second resource object construction information.
[0176] In some embodiments of this application, the electronic device can read the static numerical parameters in the updated second resource object construction information, fill the static numerical parameters into the corresponding fields of the Vulkan creation structure (CreateInfo) to obtain the creation structure corresponding to the second graphics pipeline, and then compile the Vulkan creation structure to create the second graphics pipeline corresponding to the second resource object construction information.
[0177] In some embodiments of this application, in a virtual rendering context, an electronic device can call the Vulkan interface for building a graphics pipeline to submit updated second resource object building information to the graphics card driver in order to create a second graphics pipeline through the graphics card driver.
[0178] In some embodiments of this application, resource objects successfully created by the graphics card driver are temporarily stored in the graphics card driver's internal cache, and the resource handle returned to the application is merely a reference to the successfully constructed resource object. Electronic devices can explicitly obtain the pipeline cache (VkPipelineCache) through the interface provided by Vulkan.
[0179] Thus, since the second resource object identifier included in the second resource object construction information can be replaced with the corresponding first resource handle, the second graphics pipeline can be successfully created, thereby improving the reliability of the electronic device in creating the graphics pipeline.
[0180] In some embodiments of this application, the step 702 above, "the electronic device updates the second resource object identifier in the second resource object construction information to the first resource handle", can be specifically implemented through the following step 702a.
[0181] Step 702a: The electronic device searches for the first resource handle corresponding to the second resource object identifier in the fourth mapping table, and updates the second resource object identifier in the second resource object construction information to the first resource handle.
[0182] It is understood that when the second resource object construction information includes a second resource object identifier, the electronic device can look up the first resource handle corresponding to the second resource object identifier in the fourth mapping table. After finding the first resource handle corresponding to the second resource object identifier, the electronic device can replace the second resource object identifier in the second resource object construction information with the found first resource handle to construct the second graphics pipeline.
[0183] Thus, after creating a resource object and obtaining its resource handle, the resource handle and its identifier can be stored in the fourth mapping table. Therefore, when the second resource object's construction information includes the second resource object identifier, the first resource handle corresponding to the second resource object identifier can be quickly and accurately obtained by querying the fourth mapping table. Then, the second resource object identifier included in the second resource object's construction information can be replaced with the corresponding first resource handle to successfully create the second graphics pipeline, thereby improving the reliability of the electronic device in creating graphics pipelines.
[0184] In some embodiments of this application, before step 603 above, the graphical pipeline creation method provided in this application further includes the following steps 801 and 802.
[0185] Step 801: The electronic device constructs the fourth mapping table.
[0186] In some embodiments of this application, the electronic device may construct a fourth mapping table in memory.
[0187] In some embodiments of this application, the electronic device may construct a fourth mapping table for each resource type.
[0188] In some embodiments of this application, the fourth mapping table described above can be understood as a key-value container, where the key is the resource object identifier of the resource object and the value is the actual runtime resource handle obtained after the resource object is reconstructed on the current electronic device.
[0189] Step 802: The electronic device stores the mapping relationship between the second resource object identifier and the first resource handle into the fourth mapping table.
[0190] For example, after the electronic device obtains the first resource handle of the fourth resource object, the electronic device can register and write the mapping relationship between the second resource object identifier and the first resource handle in the fourth mapping table as {the second resource object identifier corresponding to the fourth resource object: the first resource handle in the current runtime environment}, so that when the second resource object construction information includes the second resource object identifier, the electronic device can obtain the first resource handle corresponding to the second resource object identifier by looking up the fourth mapping table.
[0191] Thus, after creating a resource object and obtaining its resource handle, the resource handle and its resource object identifier can be stored in the fourth mapping table. Therefore, when the second resource object construction information includes the second resource object identifier, the first resource handle corresponding to the second resource object identifier can be quickly and accurately obtained by querying the fourth mapping table.
[0192] Thus, this application, without any application business logic involved, uses a data-driven approach to "trick" the driver into completing the time-consuming pipeline construction work. When the actual application business logic requests to create the same pipeline, and finds a directly usable pipeline cache, the driver will skip the time-consuming construction work, achieving "zero-latency" loading.
[0193] In some embodiments of this application, the process of creating at least one graphics pipeline based on the first description file can be understood as a second stage. Before the second stage, there is a first stage, which is used to "record" the graphics pipeline creation process during application runtime and save it as the first description file.
[0194] It is understood that this application comprises two core phases: the first phase, the recording phase, involves the structuring and persistence of pipeline construction information; the second phase, the reconstruction phase, involves pre-compilation processing based on general description data.
[0195] In some embodiments of this application, the first description file described above may be recorded and generated by the developer in the first stage and deployed on electronic devices via OTA upgrades or pre-installation.
[0196] In some embodiments of this application, prior to step 301 above, the graphical pipeline creation method provided in this application further includes steps 901 to 903 as described below.
[0197] Step 901: In the case of the second application creating the third graphics pipeline, the electronic device intercepts and saves the fourth resource object construction information.
[0198] In some embodiments of this application, the aforementioned fourth resource object construction information is the resource object construction information corresponding to the third graphics pipeline.
[0199] In some embodiments of this application, when the second application calls the Vulkan interface to create a third graphics pipeline, the electronic device can create the third graphics pipeline through the graphics card driver based on the fourth resource object construction information passed in by the second application, and return a successfully created third resource handle. The electronic device can intercept and save the fourth resource object construction information and the third resource handle.
[0200] In some embodiments of this application, the second application described above can be any application that needs to create a graphics pipeline.
[0201] For example: game applications, engineering applications, 3D modeling applications, VR applications, AR applications.
[0202] In some embodiments of this application, the electronic device can intervene in the above-mentioned calling process through a Hook mechanism (hook interception technology) to intercept and save the fourth resource object construction information and the third resource handle.
[0203] For example: save the VkShaderModuleCreateInfo passed in when creating the shader module, and the resource handle returned after successful shader creation: VkShaderModule.
[0204] In some embodiments of this application, the third graphics pipeline can be any graphics pipeline that an electronic device can create.
[0205] It should be noted that the interception is not only aimed at the final `vkCreateGraphicsPipelines` function (which creates the graphics pipeline), but also covers functions such as... Figure 1 The "Resource Dependency Tree" shows the creation functions for all types of resources, such as vkCreatePipelineLayout, vkCreateDescriptorSetLayout, vkCreateShaderModule, etc.
[0206] In some embodiments of this application, such as Figure 4 As shown in (a), this is the case where there is no Hook mechanism to intercept Vulkan interface calls. Figure 4 As shown in (b), the Hook mechanism is used to intercept Vulkan interface calls. When an application calls a Vulkan interface, the system can use the Hook mechanism to perform some "pre-processing operations" before the actual Vulkan interface call is made, without the application's awareness, or to perform some "post-processing operations" after the Vulkan interface call returns. In this application, it is necessary to intercept and save the resource object construction information used to create the resource object, as well as the resource handle returned to the application by the graphics card driver after successful creation. The resource handle needs to be obtained in the post-processing stage.
[0207] Step 902: If the fourth resource object construction information contains the second resource handle, the electronic device replaces the second resource handle with the third resource object identifier to obtain the updated fourth resource object construction information.
[0208] In some embodiments of this application, the second resource handle is the resource handle corresponding to the fifth resource object, and the third resource object identifier is the resource object identifier corresponding to the fifth resource object.
[0209] In some embodiments of this application, after the electronic device obtains the updated fourth resource object construction information, it can calculate the fifth resource object identifier corresponding to the third graphics pipeline based on the updated fourth resource object construction information, and then record the mapping relationship between the fifth resource object identifier and the third resource handle.
[0210] It should be noted that the detailed steps for calculating the fifth resource object identifier corresponding to the third graphics pipeline and recording the mapping relationship between the fifth resource object identifier and the third resource handle can be found in the following embodiment, which describes the calculation of the third resource object identifier corresponding to the fifth resource object and the recording of the mapping relationship between the third resource object identifier and the second resource handle. It will not be repeated here.
[0211] In some embodiments of this application, the electronic device replaces the second resource handle with the third resource object identifier to obtain updated fourth resource object construction information, which can be understood as cleaning the fourth resource object construction information.
[0212] In some embodiments of this application, the resource handle returned by the graphics card driver for the aforementioned temporary resource handle is a memory address randomly allocated in the current runtime environment. Its value is random and valid only within the current lifetime. However, this application needs to record the dependencies contained in the "resource dependency tree" of the graphics pipeline in order to rebuild the graphics pipeline on the next runtime or on a different device. Therefore, it is necessary to replace the dependent resource handle with the resource object identifier of the dependent resource object.
[0213] For example, the process of replacing a resource handle with a resource object identifier is as follows:
[0214] (1) Identify the handle field
[0215] Analyze the construction information of the fifth resource object currently intercepted to locate the handle fields that represent all resource references.
[0216] For example, when creating a VkPipelineLayout, the VkPipelineLayoutCreateInfo structure contains an array of VkDescriptorSetLayout resource handles.
[0217] (2) Lookup and Replace
[0218] Using these resource handle values, look up the corresponding resource object identifier in at least two sixth-level mapping tables. If the identifier cannot be found, the recording of this pipeline build will be marked as failed.
[0219] It's important to note that for resource objects that don't depend on other resource handles, such as the construction of shader modules, there's no process of replacing temporary resource handles. The resource object identifier can be directly calculated in step 904, and the mapping relationship between the resource handle and the resource object identifier can be stored in at least two sixth mapping tables corresponding to the resource type. However, for resource objects that depend on other resource handles, such as the construction of pipeline layouts or the final pipeline, the resource handles and resource object descriptors of the resources they depend on can already be obtained by querying at least two sixth mapping tables.
[0220] (3) Rewrite data
[0221] Replace the resource handle value in the structure with the found resource object identifier.
[0222] Therefore, this application introduces a deep data cleaning mechanism during the recording phase to address the random memory addresses (pointers) and non-critical status bits contained in Vulkan build information. By dereferencing pointers to obtain the actual data content, "dirty data" strongly bound to the current runtime environment is removed, transforming the original "black-box binary assets" into structured, general-purpose semantic description data that can be reused across platforms and devices, such as in JSON format. This allows the same description file to be parsed and used on devices with different GPU architectures.
[0223] In some embodiments of this application, the cleaning of the fourth resource object construction information by the electronic device may also include: pointer dereference processing and processing of debugging information that is not related to the graphics pipeline construction itself.
[0224] In some embodiments of this application, the aforementioned fourth resource object construction information may include structure information extended using pointers, some debugging information unrelated to the graphics pipeline construction itself, and a large number of temporary resource handles pointing to lower-level resources. To achieve cross-device reuse, electronic devices need to clean (remove or replace) this data.
[0225] In some embodiments of this application, for structure information extended using pointers, the Vulkan structure contains a large number of pointers, such as the pNext field in the VkPipelineLayoutCreateInfo structure, which is a pointer to the extended information. Each time the application starts, the memory address allocated by the operating system is random; for example, it might be 0x1234 this time and 0x2378 next time. Therefore, this address lacks universality and cannot be stored directly. Instead, it must be dereferenced, that is, the actual data content it points to must be found and recorded.
[0226] It is also important to note that the structure pointed to by such a pointer field may contain other pointers, such as pNext, i.e., multiple levels of nesting. As long as the value of the pointer field is not nullptr, i.e., the value is not 0, it should be dereferenced to obtain the actual data it points to and record it.
[0227] In some embodiments of this application, the debugging information that is not related to the construction of the graphical pipeline itself can be: flag information that affects the semantics of the creation process but does not affect the semantics of the final pipeline.
[0228] It's understandable that the flags in a Vulkan struct might contain flags that only affect the current runtime behavior but not the rendering result of the pipeline itself. These flags need to be removed to avoid affecting the generality of the recorded information.
[0229] For example, when calling the `vkCreateGraphicsPipelines` function to build a graphics pipeline, intercepting the `VkGraphicsPipelineCreateInfo` parameter passed in, its internal flags may contain the following flag information that needs to be removed:
[0230] VK_PIPELINE_CREATE_EARLY_RETURN_ON_FAILURE_BIT_EXT represents the "failure handling policy flag," which is not part of the general information used for pipeline construction and needs to be removed.
[0231] VK_PIPELINE_CREATE_FAIL_ON_PIPELINE_COMPILE_REQUIRED_BIT indicates that the pipeline must be built using a binary cache, which is a traditional caching scheme and is the exact opposite of the technical solution in this application, so it needs to be eliminated.
[0232] Step 903: The electronic device generates the resource data block corresponding to the third graphics pipeline based on the updated fourth resource object construction information.
[0233] In some embodiments of this application, the resource data block corresponding to the third graphics pipeline is the resource data block in the first description file.
[0234] Thus, since electronic devices can replace the resource handle in the resource object construction information with the resource object identifier of the corresponding resource object, the generated resource data block can be applied to different electronic devices. This avoids the problem that when the resource data block is stored in different models of electronic devices without replacing the resource handle, the resource object construction information cannot be restored based on the resource data block, and thus the corresponding resource object cannot be reconstructed.
[0235] In some embodiments of this application, before step 902 above, the graphical pipeline creation method provided in this application further includes steps 904 to 906 as described below.
[0236] Step 904: In the case of the second application creating a fifth resource object, the electronic device intercepts and saves the fifth resource object construction information and the second resource handle.
[0237] In some embodiments of this application, the aforementioned fifth resource object construction information is the resource object construction information corresponding to the fifth resource object; the second resource handle is the resource handle corresponding to the fifth resource object; the second resource handle is obtained after the graphics card driver successfully creates the fifth resource object.
[0238] It should be noted that for the detailed steps of the electronic device intercepting and saving the construction information of the fifth resource object and the second resource handle, please refer to the description of the electronic device intercepting and saving the construction information of the fourth resource object and the third resource handle in the above embodiments, which will not be repeated here.
[0239] Step 905: The electronic device calculates the identifier of the third resource object corresponding to the fifth resource object based on the information constructed by the fifth resource object.
[0240] In some embodiments of this application, before the electronic device calculates the third resource object identifier corresponding to the fifth resource object based on the fifth resource object construction information, the fifth resource object construction information can be cleaned to obtain updated fifth resource object construction information. Then, based on the updated fifth resource object construction information, the third resource object identifier corresponding to the fifth resource object is calculated.
[0241] It should be noted that for the detailed steps of cleaning the construction information of the fifth resource object by the electronic device to obtain the updated construction information of the fifth resource object, please refer to the description of cleaning the construction information of the fourth resource object to obtain the updated construction information of the fourth resource object in the above embodiment, which will not be repeated here.
[0242] In some embodiments of this application, when the fifth resource object construction information does not contain other resource handles, the electronic device can generate a resource data block corresponding to the fifth resource object based on the fifth resource object construction information.
[0243] It should be noted that for the detailed steps of generating the resource data block corresponding to the fifth resource object for the electronic device, please refer to the description of generating the resource data block corresponding to the third graphics pipeline in the above embodiment, which will not be repeated here.
[0244] In some embodiments of this application, the electronic device can use a hash algorithm to perform operations on the fields in the fifth resource object construction information to calculate the third resource object identifier.
[0245] In some embodiments of this application, the aforementioned third resource object identifier can also be understood as the resource object identifier corresponding to the fifth resource object construction information.
[0246] In some embodiments of this application, the electronic device can generate a unique "digital fingerprint" for each resource object using a hash algorithm, that is, the resource object identifier of the resource object, which is also the unique identifier of the resource object.
[0247] For example, the hash algorithm described above can be FNV-1a.
[0248] For example, a resource object identifier can be represented in a computer as a 64-bit positive integer. This 64-bit positive integer refers to a numerical representation that uses 64 binary bits to store a value, used to represent a non-negative integer value, and the range of values that can be represented is [0, 2^64−1].
[0249] In some embodiments of this application, the aforementioned resource object identifier can be understood as the "identity card number" of the fifth resource object in the standardized description library. This resource object identifier is used to uniquely identify the fifth resource object within the electronic device, avoiding the repeated storage or reconstruction of resource objects with completely identical construction parameters.
[0250] It is understandable that in a computer system, in order to distinguish whether two resource objects are the same, it is usually necessary to compare each of their bytes. In order to process efficiently, this application can generate a unique resource object identifier for each resource object.
[0251] In some embodiments of this application, if two resource objects of the same type generate the same resource object identifier, then the contents of the two resource objects are considered to be completely identical and can be reused.
[0252] In some embodiments of this application, the primary purpose of the first stage is to save general information during the graphics pipeline construction process and to enable cross-device reconstruction. Therefore, to improve the reusability of resource objects, a unique identifier is calculated for all resource object construction information structures ending with `CreateInfo`. For example, the graphics pipeline construction information structure includes a construction information structure for the pipeline shader stage (`VkPipelineShaderStageCreateInfo`).
[0253] Step 906: The electronic device records the mapping relationship between the third resource object identifier and the second resource handle.
[0254] In some embodiments of this application, the electronic device may store the mapping relationship between the third resource object identifier and the second resource handle in the seventh mapping table of at least two sixth mapping tables.
[0255] In some embodiments of this application, the electronic device may establish at least two sixth mapping tables in memory, each sixth mapping table corresponding to a resource type, and each sixth mapping table is used to store the mapping relationship between at least one resource handle and at least one resource object identifier.
[0256] In some embodiments of this application, the resource type corresponding to the seventh mapping table is the same as the resource type of the fifth resource object.
[0257] It is understandable that a sixth mapping table can be pre-built in the memory of electronic devices for each resource type of resource object.
[0258] For example, when the second application is preparing to create a pipeline layout resource (VkPipelineLayout), since the pipeline layout depends on the resource object "DescriptorSetLayout", the second application must first create a "DescriptorSetLayout".
[0259] Assuming the driver successfully creates the "Descriptor Set Layout" and returns its resource handle (Handle_A), and the "Descriptor Set Layout" does not depend on other resource objects, and its unique resource object identifier is calculated to be Hash_A, then a record {Handle_A:Hash_A} will be added to the sixth mapping table of the "Descriptor Set Layout" resource type in memory.
[0260] Then, the second application can continue to create the "pipeline layout," whose resource object construction information structure references the resource handle (Handle_A) of the previously created "descriptor set layout." The driver successfully creates the "pipeline layout" and returns its resource handle (Handle_B). Because the "pipeline layout" depends on the resource handle of the "descriptor set layout," when cleaning the resource object construction information of the "pipeline layout," it is necessary to first replace the referenced resource handle (Handle_A) of the "descriptor set layout" with its resource object identifier (Hash_A). After calculating the resource object identifier of the "pipeline layout" as Hash_B, a record {Handle_B:Hash_B} can be added to the sixth mapping table of the "pipeline layout" resource type in memory.
[0261] Example 1: Suppose we calculate the unique identifier of VkDescriptorSetLayoutCreateInfo in a certain business logic;
[0262] In Vulkan, the resource object VkDescriptorSetLayoutCreateInfo is used to construct an information structure to describe information related to the "DescriptorSetLayout". Its structure definition and assignment in this example (see " / / ") are as follows:
[0263] typedef struct VkDescriptorSetLayoutCreateInfo{
[0264] VkStructureType sType; / / VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO
[0265] const void* pNext; / / nullptr
[0266] VkDescriptorSetLayoutCreateFlags flags; / / 0
[0267] uint32_t bindingCount; / / 1
[0268] const VkDescriptorSetLayoutBinding* pBindings; / / 0x000055f9b594b68
[0269] } VkDescriptorSetLayoutCreateInfo;
[0270] / / You, one second ago | 1 author (You)
[0271] typedef struct VkDescriptorSetLayoutBinding {
[0272] uint32_t binding; / / 6
[0273] VkDescriptorType descriptorType; / / 1
[0274] uint32_t descriptorCount; / / 7
[0275] VkShaderStageFlags stageFlags; / / 17
[0276] const VkSampler* pImmutableSamplers; / / nullptr
[0277] } VkDescriptorSetLayoutBinding;
[0278] "
[0279] Among them, sType is used to describe the structure type and does not participate in the calculation of the unique identifier.
[0280] pNext is used to describe the extended information of the structure. In this example, it is assumed that there is no extended information, and the value is empty (nullptr), which is not included in the calculation.
[0281] Then the remaining data is "cleaned", including:
[0282] [Pointer Dereferencing] `pBindings` is a pointer to an array containing `bindingCount` `VkDescriptorSetLayoutBinding` structures. In this example, `bindingCount` is 1, so the array pointed to by `pBindings` contains only one `VkDescriptorSetLayoutBinding` structure. It needs to be dereferenced to retrieve the actual data.
[0283] [Temporary Resource Handle Replacement] In the VkDescriptorSetLayoutBinding structure, pImmutableSamplers is also a pointer to an array of sampler handles (VkSampler), but in this example, its value is nullptr, indicating that VkDescriptorSetLayoutBinding does not depend on sampler resource handles in this example.
[0284]
Handling of irrelevant flags
[0285] Finally, each cleaned field is arranged in a memory data block according to its order in the structure. The order in the structure follows the official Vulkan specification, inherently possessing universality. This is then input into the FNV-1a hash algorithm to generate a unique identifier for the VkDescriptorSetLayoutCreateInfo resource construction information structure: cb3985cfac50f424, a 64-bit positive integer represented in hexadecimal.
[0286] Example 2: Suppose we calculate the unique identifier of VkPipelineLayoutCreateInfo in a certain business logic, and this resource depends on the VkDescriptorSetLayout resource handle obtained by constructing VkDescriptorSetLayoutCreateInfo in Example 1;
[0287] In Vulkan, the VkPipelineLayoutCreateInfo structure is used to describe information related to "PipelineLayout". Its structure definition and assignment in this example (see " / / ") are as follows:
[0288] typedef struct VkPushConstantRange {
[0289] VkShaderStageFlags stageFlags; / / 17
[0290] uint32_t offset; / / 0
[0291] uint32_t size; / / 32
[0292] VkPushConstantRange;
[0293] You, 2 seconds ago | 1 author (You)
[0294] typedef struct VkPipelineLayoutCreateInfo {
[0295] VkStructureType sType; / / VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO
[0296] const void* pNext; / / nullptr
[0297] VkPipelineLayoutCreateFlags flags; / / 0
[0298] uint32_t setLayoutCount; / / 1
[0299] const VkDescriptorSetLayout* pSetLayouts; / / 0x00006d5abaf6430
[0300] uint32_t pushConstantRangeCount; / / 1
[0301] const VkPushConstantRange* pPushConstantRanges; / / 0x000055f9b446f64
[0302] } VkPipelineLayoutCreateInfo;
[0303] "
[0304] Among them, sType is used to describe the structure type and does not participate in the calculation of the unique identifier.
[0305] pNext is used to describe the extended information of the structure. In this example, it is assumed that there is no extended information, and the value is empty (nullptr), which is not included in the calculation.
[0306] Then the remaining data is "cleaned", including:
[0307] The `setLayoutCount` value of 1 indicates that the array of `VkDescriptorSetLayout` handles pointed to by the `pSetLayouts` pointer contains one `VkDescriptorSetLayout` resource handle. In Example 1, the handle value returned from the successful driver construction is 0000006d5baf6430. According to the construction sequence described in "Essential Knowledge," the `VkDescriptorSetLayout` has been constructed, and the unique descriptor corresponding to this handle value can be found in the mapping table established in step 103. Here, we know from Example 1 that the unique descriptor value is cb3985cfac50f424. Therefore, this handle in the array needs to be replaced with this unique descriptor.
[0308] [Pointer Dereference Handling] A value of 1 for `pushConstantRanges` indicates that the `pPushConstantRanges` pointer points to an array of `VkPushConstantRange` structures that contains a `VkPushConstantRange` structure object. Similar to the dereferencing of the `VkDescriptorSetLayoutBinding` structure in Example 1 to obtain the actual data, here we dereference `pPushConstantRanges` to obtain the actual data in the `VkPushConstantRange` structure, namely `stageFlags`, `offset`, and `size`.
[0309]
Handling of irrelevant flags
[0310] Finally, similar to Example 1, each cleaned field is arranged in memory data blocks according to its order in the structure. Then, it is input into the FNV-1a hash algorithm to generate a unique identifier for the VkPipelineLayoutCreateInfo resource construction information structure: 33b8d83bdc97ec64.
[0311] Thus, addressing the technical challenge of Vulkan resource references relying on temporary resource handles (which are only valid within a single runtime cycle and cannot be persisted), this application innovatively introduces the FNV-1a hash algorithm. During the recording phase: the hash value of the resource content is calculated as a unique identifier, and a mapping table of {runtime handle: unique identifier} is established. During serialization, all references to handles are replaced with references to the stable hash. During the storage phase: a storage structure with "resource type + unique identifier" as a dual index is constructed, achieving stable persistence of resource reference relationships.
[0312] In some embodiments of this application, the electronic device can intercept multiple resource object creation information and corresponding resource handles to generate resource data blocks corresponding to multiple resource objects. Then, the electronic device can store the resource data blocks corresponding to multiple resource objects to obtain the first description file mentioned above.
[0313] In some embodiments of this application, the electronic device can intercept resource object creation information of different applications to generate resource data blocks corresponding to multiple resource objects.
[0314] In some embodiments of this application, the electronic device can receive multiple resource data blocks generated by other devices, and then aggregate the multiple resource data blocks generated by other devices to generate the aforementioned first description file. That is, the first description file can be composed of multiple resource data blocks generated by multiple electronic devices.
[0315] It is understandable that for each resource object construction information structure used to create a resource object, after data cleaning and generation of resource identifiers, it can enter the persistent storage stage. This application aims to convert discrete resource object construction information in memory into storable and transmittable structured resource data blocks (Blobs). To support efficient resource playback and parsing, a dual indexing mechanism of "resource type + resource object identifier" is used to organize the data. The storage process specifically includes the following three sub-steps:
[0316] (1) Deduplication check based on resource type
[0317] Electronic devices can maintain a runtime index table categorized by resource type. When a resource object needs to be stored, the electronic device first determines the resource object's type tag. For example, when processing VkDescriptorSetLayoutCreateInfo, the corresponding resource tag is "descriptorSetLayouts". The electronic device then looks up the resource object identifier of the current resource object in the corresponding resource type index table.
[0318] Then, if the resource object is found, it means that the current resource object has been recorded, and the electronic device skips the subsequent serialization and writing steps. This ensures that throughout the entire application lifecycle, regardless of how many identical samplers or pipelines are created, only one copy remains on the disk. If the resource object is not found, it means that this is a new resource object, and the subsequent serialization process begins.
[0319] (2) Hierarchical data structure encapsulation
[0320] Electronic devices convert the cleaned resource object construction information into structured data and encapsulate it in two layers.
[0321] In some embodiments of this application, the data format of the structured data can be JSON format.
[0322] In some embodiments of this application, the inner encapsulation of the two-layer encapsulation is indexed by the unique identifier of the resource object: a structured data object is created with the unique identifier as the key and the cleaned resource object construction information as the value. The outer encapsulation of the two-layer encapsulation is indexed by the resource type: an outer object is created with the resource type name as the key, for example, "descriptorSetLayouts", and the inner encapsulation object as the value.
[0323] In this way, each structured resource data block generated comes with its own type description, such as:
[0324] {
[0325] "Resource Type": {
[0326] "Unique Identifier ID": { ...
[0328] Building Information ...
[0330] }
[0331] }
[0332] }
[0333] (3) Persistent writing and index update
[0334] The electronic device writes the structured data block containing the double-layer encapsulation information to the storage medium (file), and at the same time adds the resource object identifier of the resource object to the index table at runtime for subsequent deduplication checks of the resource object.
[0335] Example 3, building upon Example 1, assumes the electronic device first creates a "DescriptorSetLayout". This is a basic resource that does not depend on other Vulkan resource objects.
[0336] (1) Resource identification and preparation
[0337] The resource type is VkDescriptorSetLayout, and the corresponding resource type tag name is descriptorSetLayouts.
[0338] The unique identifier is cb3985cfac50f424.
[0339] Cleaned build information data:
[0340] flags=0, bindingCount=1.
[0341] The array of VkDescriptorSetLayoutBinding structures pointed to by pBindings contains a VkDescriptorSetLayoutBinding structure with the following structure: binding=6, descriptorType=1, descriptorCount=7, stageFlags=17, and pImmutableSamplers=nullptr (no dependencies).
[0342] (2) Structured packaging
[0343] Assuming the data is new, the electronic device checks and finds that the hash does not exist, so it performs serialization and generates a JSON data block with the following structure:
[0344] {
[0345] / / Outer index: Resource type tag
[0346] "descriptorSetLayouts": {
[0347] / / Inner index: Unique identifier Hash
[0348] "cb3985cfac50f424": {
[0349] / / Real data: Cleaned build information
[0350] "flags": 0,
[0351] "bindings": [
[0352] / / This indicates that there are 1 VkDescriptorSetLayoutBinding structure data entries with bindingCount=1.
[0353] {
[0354] "binding": 6,
[0355] "descriptorType": 1,
[0356] "descriptorCount": 7,
[0357] "stageFlags": 17,
[0358] "immutableSamplers": [] / / Empty indicates no dependencies
[0359] } ]
[0361] }
[0362] },
[0363] }
[0364] (3) Storage
[0365] Write the complete data block to the first descriptor file and mark it in memory: the type descriptorSetLayouts already contains the resource with hash cb3985cfac50f424, for subsequent deduplication of resources.
[0366] Example 4, combined with Example 2, uses VkVkPipelineLayoutCreateInfo as an example to store a VkPipelineLayout resource that depends on the descriptor collection layout in Example 3.
[0367] (1) Resource identification and preparation
[0368] The resource type is VkPipelineLayout, and the corresponding resource type tag name is pipelineLayouts.
[0369] The unique identifier is 33b8d83bdc97ec64.
[0370] Cleaned resource object construction information data:
[0371] flags=0, setLayoutCount=1, pushConstantRanges.
[0372] The pointer pSetLayouts points to an array of VkDescriptorSetLayout handles containing a VkDescriptorSetLayout resource handle. This needs to be replaced with the corresponding unique identifier. In this example, the replacement value is the Hash in Example 1: cb3985cfac50f424.
[0373] The pointer pPushConstantRanges points to an array of VkPushConstantRange structures, which contains a VkPushConstantRange structure with stageFlags=17, size=32, and offset=0.
[0374] (2) Structured packaging
[0375] Assuming the data is new, the electronic device checks and finds that the hash does not exist, so it performs serialization and generates a JSON data block with the following structure:
[0376] {
[0377] / / Outer index: Resource type tag (note that this has changed to pipelineLayouts)
[0378] "pipelineLayouts": {
[0379] / / Inner index: Unique identifier Hash
[0380] "33b8d83bdc97ec64": {
[0381] / / Real data
[0382] "flags": 0,
[0383] "pushConstantRanges": [
[0384] { "stageFlags": 17, "size": 32, "offset": 0}
[0385] ],
[0386] / / Key point: The setLayouts field here references the Hash from Example 3.
[0387] / / When reconstructing the parsed file data, the specific definition will be looked up in the table of type "descriptorSetLayouts" based on this hash.
[0388] "descriptorSetLayouts": [
[0389] "cb3985cfac50f424" ]
[0391] }
[0392] },
[0393] }
[0394] (3) Storage
[0395] The data block is appended to the first description file.
[0396] In some embodiments of this application, the goal of the first stage is to "record" the pipeline creation process during application runtime and save it as a generic description file. The goal of the second stage is to achieve pipeline pre-compilation that is completely decoupled from business logic. Without running application business logic, the system uses only the "pipeline build information description file" generated in the first stage to rebuild the resource dependency chain from scratch in memory and trigger the graphics card driver to complete pipeline compilation, generating a pipeline resource handle (VkPipeline). Through the VkPipeline pipeline resource handle, the successfully built pipeline cache resources on the current device can be obtained. Thus, when the application executes business logic and finds available pipeline cache resources, the driver will directly skip the time-consuming compilation stage and proceed directly to the next step of the rendering process. The core logic of the second stage is actually the complete reverse process of the first stage. To aid understanding, Table 1 below shows how the two stages perfectly close the loop.
[0397] Table 1
[0398]
[0399] In related technologies, in order to alleviate the problem of frame drops or stuttering during the display of electronic devices, the Vulkan standard provides the VkPipelineCache mechanism, which allows developers to export the binary results of driver compilation and reuse them in the next run. However, this caching scheme based on "compiled products" has the following fundamental defects: (1) Strong binding between hardware and driver, not portable: The binary data exported by VkPipelineCache is the product of compilation for a specific GPU model and a specific driver version. Once the user's mobile phone model changes, or even just the system upgrade causes the driver version to change, the cache file will immediately become invalid. The cost for developers to pre-install a universal cache file for Android models with extremely severe fragmentation in the cloud is extremely high. (2) The "black box" of data is unresolvable and unmaintainable: The binary format is proprietary and opaque to the graphics card manufacturer. Developers cannot parse the number of pipelines or specific parameters contained therein, nor can they perform incremental updates or deduplication. Once the game business logic is slightly adjusted, such as changing the blending mode of a certain material, the old entire cache file must be discarded, and developers need to rerun all scenes of the game to re-collect data, which is extremely costly to maintain. (3) Dependence on the execution of business logic: Traditional solutions require the actual game logic to be executed in order to trigger the pipeline creation process. This means that it is impossible to pre-compile without business code during the "black screen stage" or "loading stage" before the game starts.
[0400] The core objective of this application is to break the limitations of existing technologies that tightly bind pipeline caching to hardware, proposing a novel approach of "process recording and on-demand reconstruction." Instead of storing the compiled binary black-box results, it stores the "recipe" required to build the pipeline—that is, the cleaned build parameters. By transforming pipeline build information into structured, parsable, device-independent, and universally descriptive data, and combining it with a reconstruction mechanism, it enables pre-compilation by the mobile phone's graphics card driver through "replaying the recipe" on any device at any time, without needing to run the specific business logic of the application. This allows the necessary pipeline resources to be pre-compiled and generated before actual runtime scenarios.
[0401] This application's embodiments achieve: Cross-platform reuse: Breaking the traditional binary cache's strong binding to specific GPU hardware. Through deep data cleaning and hash mapping technology, runtime handles are transformed into device-independent general-purpose structured data, enabling pipeline assets to be distributed and reused across devices and driver versions. Efficient reconstruction and management: Based on linear build sequences generated by topology sorting and dynamic handle injection technology, complex resource dependency reconstruction independent of business logic is achieved. Simultaneously, the dual-index structure supports global deduplication, significantly reducing storage volume and facilitating version management. Support for efficient incremental recording and version iteration: Existing binary caches are "black boxes," and once the application is updated, such as adding special effects, the old cache often becomes invalid, requiring a full re-run of the entire scene for full recording. This invention transforms pipeline information into granular, structured data. When application functions are added, only incremental recording of the newly added pipeline data is needed and merged, without requiring a full re-recording, greatly reducing the maintenance cost of version iteration.
[0402] It should be noted that the above-described method embodiments, or the various possible implementations of the method embodiments, can be executed individually, or, provided there are no contradictions, they can be combined with each other. The specific implementation can be determined according to actual usage requirements, and this application embodiment does not impose any restrictions on this.
[0403] It should be noted that the graphical pipeline creation method provided in this application embodiment can be executed by a graphical pipeline creation device. This application embodiment uses a graphical pipeline creation device executing the graphical pipeline creation method as an example to illustrate the graphical pipeline creation device provided in this application embodiment.
[0404] Figure 5 A schematic diagram of a possible structure of the graphic pipeline creation apparatus involved in an embodiment of this application is shown. For example... Figure 5 As shown, the graphics pipeline creation device 70 may include a processing module 71.
[0405] The processing module 71 is used to obtain graphics pipeline creation request information sent by the first application; the graphics pipeline creation request information is used to request the creation of the first graphics pipeline; and through the graphics card driver of the electronic device, obtain the pre-compiled binary data of the first graphics pipeline from the pipeline cache; the pipeline cache includes binary data after pre-compiling at least one graphics pipeline; and create the first graphics pipeline based on the pre-compiled binary data.
[0406] In the graphics pipeline creation apparatus provided in this application embodiment, since the pre-compiled binary data of the first graphics pipeline can be obtained from the pipeline cache, the first graphics pipeline can be created directly through the pre-compiled binary data without having to compile the construction information of the first graphics pipeline on-site. This significantly shortens the creation time of the first graphics pipeline, avoids rendering thread blocking, and reduces frame drops or stuttering during the display of electronic devices.
[0407] In one possible implementation, the processing module 71 is further configured to obtain a first description file before obtaining the graphics pipeline creation request information sent by the first application; the first description file is used to describe the creation information of at least one graphics pipeline; and create at least one graphics pipeline based on the first description file; and pre-compile at least one graphics pipeline through the graphics card driver to obtain pre-compiled binary data of at least one graphics pipeline.
[0408] In one possible implementation, the first description file mentioned above includes multiple resource data blocks; each resource data block corresponds to a resource object; each resource data block includes: the resource type of the resource object, the resource object construction information, and the resource object identifier; wherein, the resource object includes any one of the following: a graphics pipeline, or a resource object referenced when creating a graphics pipeline.
[0409] In one possible implementation, when the creation of the first resource object requires a reference to the second resource object, the construction information of the first resource object includes a first resource object identifier; wherein, the first resource object construction information is the resource object construction information included in the first resource data block; the first resource data block is the resource data block corresponding to the first resource object among multiple resource data blocks; and the first resource object identifier is the resource object identifier of the second resource object.
[0410] In one possible implementation, the processing module 71 is specifically used to parse the first description file to obtain multiple resource data blocks; and based on the multiple resource data blocks, determine at least one first sequence; the first sequence is used to indicate the creation order of the graphics pipeline and the third resource object; the third resource object is the resource object that needs to be referenced when creating the graphics pipeline; and create at least one graphics pipeline according to at least one first sequence.
[0411] In one possible implementation, the processing module 71 is specifically configured to construct at least two first mapping tables based on the resource types of resource objects corresponding to multiple resource data blocks; each first mapping table stores a mapping relationship between at least one resource object identifier and at least one resource object construction information; all resource object identifiers stored in each first mapping table indicate the same resource type of the resource objects; and, if the second resource object construction information includes the second resource object identifier, determine a third mapping table storing the second resource object identifier from the at least two first mapping tables; the second resource object construction information is any resource object construction information in the second mapping table; the second mapping table is a mapping table among the at least two first mapping tables, and the resource type of the resource object indicated by the resource object identifier in the second mapping table is a graphics pipeline; and, based on the second resource object construction information and the third resource object construction information in the third mapping table, determine a first sequence corresponding to the second resource object construction information; the third resource object construction information is the resource object construction information corresponding to the second resource object identifier; the first sequence is used to indicate the creation order between the second graphics pipeline and the fourth resource object; the second graphics pipeline is the graphics pipeline corresponding to the second resource object construction information; and the fourth resource object is the resource object corresponding to the second resource object identifier.
[0412] In one possible implementation, the processing module 71 is specifically configured to: obtain, according to the first sequence corresponding to the second resource object construction information, based on the second resource object identifier included in the second resource object construction information, obtain the third resource object construction information corresponding to the second resource object identifier from the third mapping table storing the second resource object identifier; create a fourth resource object based on the third resource object construction information to obtain the first resource handle of the fourth resource object; and create a second graphics pipeline corresponding to the second resource object construction information based on the second resource object construction information and the first resource handle.
[0413] In one possible implementation, the processing module 71 is specifically used to obtain the second resource object construction information from the second mapping table; and if the second resource object construction information includes a second resource object identifier, update the second resource object identifier in the second resource object construction information to a first resource handle, and create a second graphics pipeline corresponding to the second resource object construction information based on the updated second resource object construction information.
[0414] In one possible implementation, the processing module 71 is specifically used to look up the first resource handle corresponding to the second resource object identifier from the fourth mapping table, and update the second resource object identifier in the second resource object construction information to the first resource handle.
[0415] In one possible implementation, the processing module 71 is further configured to construct a fourth mapping table before creating the second graphics pipeline corresponding to the second resource object construction information based on the second resource object construction information and the first resource handle; and store the mapping relationship between the second resource object identifier and the first resource handle in the fourth mapping table.
[0416] In one possible implementation, the processing module 71 is further configured to, before obtaining the first description file, if the second application creates a third graphics pipeline, intercept and save fourth resource object construction information, wherein the fourth resource object construction information is the resource object construction information corresponding to the third graphics pipeline; and if the fourth resource object construction information contains a second resource handle, replace the second resource handle with a third resource object identifier to obtain updated fourth resource object construction information; wherein the second resource handle is the resource handle corresponding to the fifth resource object; the third resource object identifier is the resource object identifier corresponding to the fifth resource object; and based on the updated fourth resource object construction information, generate a resource data block corresponding to the third graphics pipeline, wherein the resource data block corresponding to the third graphics pipeline is the resource data block in the first description file.
[0417] In one possible implementation, the processing module 71 is further configured to, when the fourth resource object construction information contains a second resource handle, replace the second resource handle with a third resource object identifier to obtain the updated fourth resource object construction information, and before the second application creates a fifth resource object, intercept and save the fifth resource object construction information and the second resource handle; the fifth resource object construction information is the resource object construction information corresponding to the fifth resource object; the second resource handle is the resource handle corresponding to the fifth resource object, which is obtained after the graphics card driver successfully creates the fifth resource object; and calculate the third resource object identifier corresponding to the fifth resource object based on the fifth resource object construction information; and record the mapping relationship between the third resource object identifier and the second resource handle.
[0418] The graphics pipeline creation device in this application embodiment can be an electronic device or a component within an electronic device, such as an integrated circuit or a chip. The electronic device can be a terminal or other devices besides a terminal. For example, the electronic device can be a mobile phone, tablet computer, laptop computer, PDA, in-vehicle electronic device, mobile internet device (MID), augmented reality (AR) / virtual reality (VR) device, robot, wearable device, ultra-mobile personal computer (UMPC), netbook, or personal digital assistant (PDA), etc. It can also be a server, network attached storage (NAS), personal computer (PC), television (TV), ATM, or self-service machine, etc. This application embodiment does not specifically limit the device.
[0419] The graphical pipeline creation device in this application embodiment can be a device with an operating system. This operating system can be Android, iOS, or other possible operating systems; this application embodiment does not specifically limit it.
[0420] The graphical pipeline creation apparatus provided in this application embodiment can implement all the processes implemented in the above method embodiments, and will not be described again here to avoid repetition.
[0421] Optionally, such as Figure 6 As shown, this application embodiment also provides an electronic device 90, including a processor 91 and a memory 92. The memory 92 stores a program or instructions that can run on the processor 91. When the program or instructions are executed by the processor 91, they implement the various steps of the above-described graphics pipeline creation method embodiment and can achieve the same technical effect. To avoid repetition, they will not be described again here.
[0422] It should be noted that the electronic devices in the embodiments of this application include the mobile electronic devices and non-mobile electronic devices described above.
[0423] Figure 7 A schematic diagram of the hardware structure of an electronic device to implement an embodiment of this application.
[0424] The electronic device 100 includes, but is not limited to, components such as: radio frequency unit 101, network module 102, audio output unit 103, input unit 104, sensor 105, display unit 106, user input unit 107, interface unit 108, memory 109, and processor 110.
[0425] Those skilled in the art will understand that the electronic device 100 may also include a power supply (such as a battery) for supplying power to various components. The power supply may be logically connected to the processor 110 through a power management system, thereby enabling functions such as managing charging, discharging, and power consumption through the power management system. Figure 7 The electronic device structure shown does not constitute a limitation on the electronic device. The electronic device may include more or fewer components than shown, or combine certain components, or have different component arrangements, which will not be elaborated here.
[0426] The processor 110 is configured to acquire graphics pipeline creation request information sent by a first application; the graphics pipeline creation request information is used to request the creation of a first graphics pipeline; and acquire pre-compiled binary data of the first graphics pipeline from the pipeline cache through the graphics card driver of the electronic device; the pipeline cache includes binary data after pre-compiling at least one graphics pipeline; and create the first graphics pipeline based on the pre-compiled binary data.
[0427] In the electronic device provided in this application embodiment, since the pre-compiled binary data of the first graphics pipeline can be obtained from the pipeline cache, the first graphics pipeline can be created directly through the pre-compiled binary data without having to compile the construction information of the first graphics pipeline on-site. This significantly shortens the creation time of the first graphics pipeline, avoids rendering thread blocking, and reduces frame drops or stuttering during the display of the electronic device.
[0428] Optionally, the processor 110 is further configured to obtain a first description file before obtaining graphics pipeline creation request information sent by the first application; the first description file is used to describe the creation information of at least one graphics pipeline; and create at least one graphics pipeline based on the first description file; and pre-compile at least one graphics pipeline through the graphics card driver to obtain pre-compiled binary data of at least one graphics pipeline.
[0429] Optionally, the first description file mentioned above includes multiple resource data blocks; each resource data block corresponds to a resource object; each resource data block includes: the resource type of the resource object, the resource object construction information, and the resource object identifier; wherein, the resource object includes any one of the following: a graphics pipeline, or a resource object referenced when creating a graphics pipeline.
[0430] Optionally, when the creation of the first resource object requires referencing the second resource object, the construction information of the first resource object includes a first resource object identifier; wherein, the construction information of the first resource object is the resource object construction information included in the first resource data block; the first resource data block is the resource data block corresponding to the first resource object among multiple resource data blocks; and the first resource object identifier is the resource object identifier of the second resource object.
[0431] Optionally, the processor 110 is specifically configured to parse the first description file to obtain multiple resource data blocks; and based on the multiple resource data blocks, determine at least one first sequence; the first sequence is used to indicate the creation order of the graphics pipeline and the third resource object; the third resource object is a resource object that needs to be referenced when creating the graphics pipeline; and create at least one graphics pipeline according to at least one first sequence.
[0432] Optionally, the processor 110 is specifically configured to construct at least two first mapping tables based on the resource types of resource objects corresponding to multiple resource data blocks; each first mapping table stores a mapping relationship between at least one resource object identifier and at least one resource object construction information; all resource object identifiers stored in each first mapping table indicate the same resource type of the resource objects; and, if the second resource object construction information includes the second resource object identifier, determine a third mapping table storing the second resource object identifier from the at least two first mapping tables; the second resource object construction information is any resource object construction information in the second mapping table; the second mapping table is a mapping table among the at least two first mapping tables, and the resource type of the resource object indicated by the resource object identifier in the second mapping table is a graphics pipeline; and, based on the second resource object construction information and the third resource object construction information in the third mapping table, determine a first sequence corresponding to the second resource object construction information; the third resource object construction information is the resource object construction information corresponding to the second resource object identifier; the first sequence is used to indicate the creation order between the second graphics pipeline and the fourth resource object; the second graphics pipeline is the graphics pipeline corresponding to the second resource object construction information; and the fourth resource object is the resource object corresponding to the second resource object identifier.
[0433] Optionally, the processor 110 is specifically configured to: obtain, according to the first sequence corresponding to the second resource object construction information, based on the second resource object identifier included in the second resource object construction information, obtain the third resource object construction information corresponding to the second resource object identifier from the third mapping table storing the second resource object identifier; and create a fourth resource object based on the third resource object construction information to obtain the first resource handle of the fourth resource object; and create a second graphics pipeline corresponding to the second resource object construction information based on the second resource object construction information and the first resource handle.
[0434] Optionally, the processor 110 is specifically configured to obtain second resource object construction information from the second mapping table; and if the second resource object construction information includes a second resource object identifier, update the second resource object identifier in the second resource object construction information to a first resource handle, and create a second graphics pipeline corresponding to the second resource object construction information based on the updated second resource object construction information.
[0435] Optionally, the processor 110 is specifically configured to look up the first resource handle corresponding to the second resource object identifier from the fourth mapping table, and update the second resource object identifier in the second resource object construction information to the first resource handle.
[0436] Optionally, the processor 110 is further configured to construct a fourth mapping table before creating the second graphics pipeline corresponding to the second resource object construction information based on the second resource object construction information and the first resource handle; and to store the mapping relationship between the second resource object identifier and the first resource handle in the fourth mapping table.
[0437] Optionally, the processor 110 is further configured to, before obtaining the first description file, if the second application creates a third graphics pipeline, intercept and save fourth resource object construction information, wherein the fourth resource object construction information is the resource object construction information corresponding to the third graphics pipeline; and if the fourth resource object construction information contains a second resource handle, replace the second resource handle with a third resource object identifier to obtain updated fourth resource object construction information; wherein the second resource handle is the resource handle corresponding to the fifth resource object; the third resource object identifier is the resource object identifier corresponding to the fifth resource object; and based on the updated fourth resource object construction information, generate a resource data block corresponding to the third graphics pipeline, wherein the resource data block corresponding to the third graphics pipeline is the resource data block in the first description file.
[0438] Optionally, the processor 110 is further configured to, when the second resource object construction information contains a second resource handle, before replacing the second resource handle with a third resource object identifier to obtain updated fourth resource object construction information, intercept and save the fifth resource object construction information and the second resource handle when the second application creates a fifth resource object; the fifth resource object construction information is the resource object construction information corresponding to the fifth resource object; the second resource handle is the resource handle corresponding to the fifth resource object, which is obtained after the graphics card driver successfully creates the fifth resource object; and calculate the third resource object identifier corresponding to the fifth resource object based on the fifth resource object construction information; and record the mapping relationship between the third resource object identifier and the second resource handle.
[0439] The electronic device provided in this application embodiment can implement the various processes implemented in the above method embodiments and achieve the same technical effect. To avoid repetition, it will not be described again here.
[0440] For details on the beneficial effects of the various implementation methods in this embodiment, please refer to the beneficial effects of the corresponding implementation methods in the above method embodiments. To avoid repetition, these will not be repeated here.
[0441] It should be understood that, in this embodiment, the input unit 104 may include a GPU 1041 and a microphone 1042. The graphics processor 1041 processes image data of still images or videos obtained by an image capture device (such as a camera) in video capture mode or image capture mode. The display unit 106 may include a display panel 1061, which may be configured in the form of a liquid crystal display, an organic light-emitting diode, or the like. The user input unit 107 includes at least one of a touch panel 1071 and other input devices 1072. The touch panel 1071 is also called a touch screen. The touch panel 1071 may include a touch detection device and a touch controller. Other input devices 1072 may include, but are not limited to, physical keyboards, function keys (such as volume control buttons, power buttons, etc.), trackballs, mice, and joysticks, which will not be described in detail here.
[0442] The memory 109 can be used to store software programs and various data. The memory 109 may primarily include a first storage area for storing programs or instructions and a second storage area for storing data. The first storage area may store the operating system, application programs or instructions required for at least one function (such as sound playback, image playback, etc.). Furthermore, the memory 109 may include volatile memory or non-volatile memory, or both. The non-volatile memory may be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. Volatile memory can be random access memory (RAM), static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDRSDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM), and direct memory bus RAM (DRRAM). The memory 109 in the embodiments of this application includes, but is not limited to, these and any other suitable types of memory.
[0443] Processor 110 may include one or more processing units; optionally, processor 110 integrates an application processor and a modem processor, wherein the application processor mainly handles operations involving the operating system, user interface, and applications, and the modem processor mainly handles wireless communication signals, such as a baseband processor. It is understood that the aforementioned modem processor may also not be integrated into processor 110.
[0444] This application also provides a readable storage medium storing a program or instructions. When the program or instructions are executed by a processor, they implement the various processes of the above method embodiments and achieve the same technical effect. To avoid repetition, they will not be described again here.
[0445] The processor is the processor in the electronic device described in the above embodiments. The readable storage medium includes computer-readable storage media, such as computer read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.
[0446] This application embodiment also provides a chip, which includes a processor and a communication interface. The communication interface is coupled to the processor. The processor is used to run programs or instructions to implement the various processes of the above method embodiments and achieve the same technical effect. To avoid repetition, it will not be described again here.
[0447] It should be understood that the chip mentioned in the embodiments of this application may also be referred to as a system-on-a-chip, system chip, chip system, or system-on-a-chip, etc.
[0448] This application provides a computer program product, which is stored in a storage medium and executed by at least one processor to implement the various processes of the above method embodiments and achieve the same technical effects. To avoid repetition, it will not be described again here.
[0449] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus 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 apparatus. 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 apparatus that includes that element. Furthermore, it should be noted that the scope of the methods and apparatuses in the embodiments of this application is not limited to performing functions in the order shown or discussed, but may also include performing functions substantially simultaneously or in the reverse order, depending on the functions involved. For example, the described methods may be performed in a different order than described, and various steps may be added, omitted, or combined. Additionally, features described with reference to certain examples may be combined in other examples.
[0450] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a computer software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods described in the various embodiments of this application.
[0451] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of this application.
Claims
1. A method for creating a graphical pipeline, characterized in that, The method includes: Obtain the graphics pipeline creation request information sent by the first application; the graphics pipeline creation request information is used to request the creation of the first graphics pipeline; The pre-compiled binary data of the first graphics pipeline is obtained from the pipeline cache through the graphics card driver of the electronic device; the pipeline cache includes pre-compiled binary data of at least one graphics pipeline. Based on the pre-compiled binary data, a first graphics pipeline is created.
2. The method according to claim 1, characterized in that, Before obtaining the graphics pipeline creation request information sent by the first application, the method further includes: Obtain a first description file; the first description file is used to describe the creation information of the at least one graphics pipeline; Based on the first description file, create at least one graphics pipeline; The graphics card driver is used to precompile the at least one graphics pipeline to obtain precompiled binary data for the at least one graphics pipeline.
3. The method according to claim 2, characterized in that, The first description file includes multiple resource data blocks; each resource data block corresponds to a resource object; each resource data block includes: the resource type of the resource object, the resource object construction information, and the resource object identifier; The resource objects include any of the following: graphics pipeline, or resource objects that need to be referenced when creating a graphics pipeline.
4. The method according to claim 3, characterized in that, When the creation of a first resource object requires a reference to a second resource object, the first resource object construction information includes a first resource object identifier; wherein, the first resource object construction information is the resource object construction information included in the first resource data block; the first resource data block is the resource data block corresponding to the first resource object among the plurality of resource data blocks; and the first resource object identifier is the resource object identifier of the second resource object.
5. The method according to any one of claims 2 to 4, characterized in that, The step of creating at least one graphics pipeline based on the first description file includes: Parse the first description file to obtain multiple resource data blocks; Based on the plurality of resource data blocks, at least one first sequence is determined; the first sequence is used to indicate the creation order of the graphics pipeline and the third resource object; the third resource object is a resource object that needs to be referenced when creating the graphics pipeline; Create at least one graphics pipeline according to the at least one first sequence.
6. The method according to claim 5, characterized in that, Determining at least one first sequence based on the plurality of resource data blocks includes: Based on the resource types of the resource objects corresponding to the plurality of resource data blocks, at least two first mapping tables are constructed; each first mapping table stores a mapping relationship between at least one resource object identifier and at least one resource object construction information; all resource object identifiers stored in each first mapping table indicate the same resource type of the resource objects. If the second resource object construction information includes a second resource object identifier, a third mapping table storing the second resource object identifier is determined from the at least two first mapping tables; the second resource object construction information is any resource object construction information in the second mapping table; the second mapping table is a mapping table in the at least two first mapping tables, and the resource type of the resource object indicated by the resource object identifier in the second mapping table is a graphics pipeline; Based on the second resource object construction information and the third resource object construction information in the third mapping table, a first sequence corresponding to the second resource object construction information is determined; the third resource object construction information is the resource object construction information corresponding to the second resource object identifier; the first sequence is used to indicate the creation order between the second graphics pipeline and the fourth resource object; the second graphics pipeline is the graphics pipeline corresponding to the second resource object construction information; the fourth resource object is the resource object corresponding to the second resource object identifier.
7. The method according to claim 6, characterized in that, Creating at least one graphics pipeline according to the at least one first sequence includes: According to the first sequence corresponding to the second resource object construction information, and based on the second resource object identifier included in the second resource object construction information, the third resource object construction information corresponding to the second resource object identifier is obtained from the third mapping table storing the second resource object identifier; Based on the construction information of the third resource object, a fourth resource object is created, and the first resource handle of the fourth resource object is obtained. Based on the second resource object construction information and the first resource handle, a second graphics pipeline corresponding to the second resource object construction information is created.
8. The method according to claim 7, characterized in that, The step of creating a second graphics pipeline corresponding to the second resource object construction information based on the second resource object construction information and the first resource handle includes: Obtain the construction information of the second resource object from the second mapping table; If the second resource object construction information includes the second resource object identifier, the second resource object identifier in the second resource object construction information is updated to the first resource handle, and a second graphics pipeline corresponding to the second resource object construction information is created based on the updated second resource object construction information.
9. The method according to claim 8, characterized in that, The step of updating the second resource object identifier in the second resource object construction information to the first resource handle includes: From the fourth mapping table, find the first resource handle corresponding to the second resource object identifier, and update the second resource object identifier in the second resource object construction information to the first resource handle.
10. The method according to claim 9, characterized in that, Before creating the second graphics pipeline corresponding to the second resource object construction information based on the second resource object construction information and the first resource handle, the method further includes: Construct the fourth mapping table; The mapping relationship between the second resource object identifier and the first resource handle is stored in the fourth mapping table.
11. The method according to claim 2, characterized in that, Before obtaining the first description file, the method further includes: When the second application creates a third graphics pipeline, intercept and save the fourth resource object construction information, which is the resource object construction information corresponding to the third graphics pipeline. If the fourth resource object construction information includes a second resource handle, the second resource handle is replaced with a third resource object identifier to obtain the updated fourth resource object construction information; the second resource handle is the resource handle corresponding to the fifth resource object; the third resource object identifier is the resource object identifier corresponding to the fifth resource object. Based on the updated fourth resource object construction information, a resource data block corresponding to the third graphics pipeline is generated, and the resource data block corresponding to the third graphics pipeline is the resource data block in the first description file.
12. The method according to claim 11, characterized in that, Before replacing the second resource handle with a third resource object identifier to obtain the updated fourth resource object construction information, when the fourth resource object construction information includes a second resource handle, the method further includes: When the second application creates the fifth resource object, the fifth resource object construction information and the second resource handle are intercepted and saved; the fifth resource object construction information is the resource object construction information corresponding to the fifth resource object; the second resource handle is the resource handle corresponding to the fifth resource object, and the second resource handle is obtained after the graphics card driver successfully creates the fifth resource object; Based on the construction information of the fifth resource object, the identifier of the third resource object corresponding to the fifth resource object is calculated; Record the mapping relationship between the third resource object identifier and the second resource handle.
13. A graphical pipeline creation device, characterized in that, The graphics pipeline creation device includes: a processing module; The processing module is configured to obtain graphics pipeline creation request information sent by a first application; the graphics pipeline creation request information is used to request the creation of a first graphics pipeline; and obtain pre-compiled binary data of the first graphics pipeline from the pipeline cache through the graphics card driver of the electronic device; the pipeline cache includes binary data after pre-compiling at least one graphics pipeline; and create the first graphics pipeline based on the pre-compiled binary data.
14. The apparatus according to claim 13, characterized in that, The processing module is further configured to obtain a first description file before obtaining the graphics pipeline creation request information sent by the first application; the first description file is used to describe the creation information of the at least one graphics pipeline; and create at least one graphics pipeline based on the first description file; And through the graphics card driver, the at least one graphics pipeline is pre-compiled to obtain the pre-compiled binary data of the at least one graphics pipeline.
15. The apparatus according to claim 14, characterized in that, The first description file includes multiple resource data blocks; each resource data block corresponds to a resource object; each resource data block includes: the resource type of the resource object, the resource object construction information, and the resource object identifier; The resource objects include any of the following: graphics pipeline, or resource objects that need to be referenced when creating a graphics pipeline.
16. The apparatus according to claim 15, characterized in that, When the creation of a first resource object requires a reference to a second resource object, the first resource object construction information includes a first resource object identifier; wherein, the first resource object construction information is the resource object construction information included in the first resource data block; the first resource data block is the resource data block corresponding to the first resource object among the plurality of resource data blocks; and the first resource object identifier is the resource object identifier of the second resource object.
17. The apparatus according to any one of claims 14 to 16, characterized in that, The processing module is specifically used to parse the first description file to obtain multiple resource data blocks; and based on the multiple resource data blocks, to determine at least one first sequence; the first sequence is used to indicate the creation order of the graphics pipeline and the third resource object; The third resource object is a resource object that needs to be referenced to create a graphics pipeline; and at least one graphics pipeline is created according to the at least one first sequence.
18. The apparatus according to claim 17, characterized in that, The processing module is specifically used to construct at least two first mapping tables based on the resource types of the resource objects corresponding to the plurality of resource data blocks; each first mapping table stores a mapping relationship between at least one resource object identifier and at least one resource object construction information; all resource object identifiers stored in each first mapping table indicate the same resource type of the resource objects. If the second resource object construction information includes a second resource object identifier, a third mapping table storing the second resource object identifier is determined from the at least two first mapping tables; the second resource object construction information is any resource object construction information in the second mapping table. The second mapping table is one of the at least two first mapping tables, and the resource type of the resource object indicated by the resource object identifier in the second mapping table is a graphics pipeline; and based on the second resource object construction information and the third resource object construction information in the third mapping table, a first sequence corresponding to the second resource object construction information is determined; the third resource object construction information is the resource object construction information corresponding to the second resource object identifier; the first sequence is used to indicate the creation order between the second graphics pipeline and the fourth resource object; the second graphics pipeline is the graphics pipeline corresponding to the second resource object construction information; the fourth resource object is the resource object corresponding to the second resource object identifier.
19. The apparatus according to claim 18, characterized in that, The processing module is specifically configured to, according to the first sequence corresponding to the second resource object construction information, obtain the third resource object construction information corresponding to the second resource object identifier from the third mapping table storing the second resource object identifier based on the second resource object identifier included in the second resource object construction information; and create a fourth resource object based on the third resource object construction information to obtain the first resource handle of the fourth resource object; And based on the second resource object construction information and the first resource handle, create a second graphics pipeline corresponding to the second resource object construction information.
20. The apparatus according to claim 19, characterized in that, The processing module is specifically used to obtain the second resource object construction information from the second mapping table; and if the second resource object construction information includes the second resource object identifier, update the second resource object identifier in the second resource object construction information to the first resource handle, and create the second graphics pipeline corresponding to the second resource object construction information based on the updated second resource object construction information.
21. The apparatus according to claim 20, characterized in that, The processing module is specifically used to find the first resource handle corresponding to the second resource object identifier from the fourth mapping table, and update the second resource object identifier in the second resource object construction information to the first resource handle.
22. The apparatus according to claim 21, characterized in that, The processing module is further configured to construct a fourth mapping table before creating the second graphics pipeline corresponding to the second resource object construction information based on the second resource object construction information and the first resource handle; and store the mapping relationship between the second resource object identifier and the first resource handle in the fourth mapping table.
23. The apparatus according to claim 14, characterized in that, The processing module is further configured to, before obtaining the first description file, intercept and save fourth resource object construction information when the second application creates the third graphics pipeline, wherein the fourth resource object construction information is the resource object construction information corresponding to the third graphics pipeline; and if the fourth resource object construction information contains a second resource handle, replace the second resource handle with a third resource object identifier to obtain the updated fourth resource object construction information; wherein the second resource handle is the resource handle corresponding to the fifth resource object; The third resource object identifier is the resource object identifier corresponding to the fifth resource object; and based on the updated fourth resource object construction information, a resource data block corresponding to the third graphics pipeline is generated, and the resource data block corresponding to the third graphics pipeline is the resource data block in the first description file.
24. The apparatus according to claim 23, characterized in that, The processing module is further configured to, when the fourth resource object construction information contains a second resource handle, before replacing the second resource handle with a third resource object identifier to obtain the updated fourth resource object construction information, intercept and save the fifth resource object construction information and the second resource handle when the second application creates the fifth resource object; the fifth resource object construction information is the resource object construction information corresponding to the fifth resource object; the second resource handle is the resource handle corresponding to the fifth resource object, which is obtained after the graphics card driver successfully creates the fifth resource object; and calculate the third resource object identifier corresponding to the fifth resource object based on the fifth resource object construction information; and record the mapping relationship between the third resource object identifier and the second resource handle.
25. An electronic device, characterized in that, It includes a processor and a memory, the memory storing a program or instructions that can run on the processor, the program or instructions being executed by the processor to implement the steps of the graphics pipeline creation method as described in any one of claims 1 to 12.