A memory allocation method and apparatus
By grouping rendering textures that support shared memory space within the rendering texture set and sharing memory, the problem of high memory consumption by rendering textures is solved, and efficient utilization of memory resources is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- BEIJING ZITIAO NETWORK TECH CO LTD
- Filing Date
- 2021-04-07
- Publication Date
- 2026-06-19
AI Technical Summary
Rendering textures consumes a huge amount of memory resources, and current technologies have not been able to effectively reduce this.
By obtaining the set of rendering textures, it is determined whether the rendering textures support sharing memory space. The rendering textures that support sharing memory space are divided into one or more rendering texture groups, and the same memory space is allocated to the rendering textures in the same group.
This reduces the memory consumption of rendering textures and improves memory utilization efficiency.
Smart Images

Figure CN115185670B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of rendering technology, and in particular to a memory allocation method and apparatus. Background Technology
[0002] Rendering is the final step in computer graphics (CG), and it is the stage that ultimately makes the image conform to a three-dimensional (3D) scene. By rendering the texture of the image, it can make the image clearer and more realistic.
[0003] Rendering systems typically employ both a Central Processing Unit (CPU) and a Graphics Processing Unit (GPU). During image rendering, the CPU and GPU work in parallel. The CPU adds rendering commands (Draw Calls) to the command buffer, invoking the graphics programming interface to perform rendering operations. The GPU reads the Draw Calls from the command buffer and executes them. In existing rendering system designs, the input to a Draw Call may not include a render texture (RT), or it may include one or more render textures. The output of a Draw Call is always a render texture; therefore, each Draw Call includes at least one render texture. Since rendering a single frame may require executing a large number of Draw Calls, the rendering system needs to allocate memory for each render texture in each Draw Call. A single RGBA format render texture with a resolution of 1280*720 requires 3.5MB of memory, demonstrating the significant memory consumption of render textures. Summary of the Invention
[0004] In view of this, the present invention provides a memory allocation method and apparatus for reducing the consumption of memory resources by rendering textures.
[0005] To achieve the above objectives, the embodiments of the present invention provide the following technical solutions:
[0006] In a first aspect, embodiments of the present invention provide a memory allocation method, comprising:
[0007] Obtain a set of rendering textures, which includes rendering textures for various rendering commands used to render the target image;
[0008] Determine whether each pair of rendering textures in the rendering texture set supports sharing memory space;
[0009] Based on whether the rendering textures in the rendering texture set support sharing memory space between each other, the rendering textures in the rendering texture set are divided into at least one rendering texture group, and the rendering textures belonging to the same rendering texture group support sharing memory space between each other.
[0010] Allocate the same memory space for rendering textures that belong to the same rendering texture group.
[0011] As an optional implementation of this invention, determining whether each pair of rendering textures in the rendering texture set supports sharing memory space includes:
[0012] Determine whether the properties of the first rendering texture are the same as those of the second rendering texture;
[0013] If the attributes of the first rendering texture are different from those of the second rendering texture, then it is determined that the first rendering texture and the second rendering texture do not support sharing memory space.
[0014] As an optional implementation of this invention, determining whether the attributes of the first rendering texture are the same as the attributes of the second rendering texture includes:
[0015] Determine whether the format and resolution of the first rendering texture are the same as those of the second rendering texture;
[0016] If the format of the first rendering texture is different from that of the second rendering texture, and / or the resolution of the first rendering texture is different from that of the second rendering texture, then it is determined that the attributes of the first rendering texture are different from those of the second rendering texture.
[0017] If the format of the first rendering texture is the same as that of the second rendering texture, and the resolution of the first rendering texture is the same as that of the second rendering texture, then it is determined that the attributes of the first rendering texture are the same as those of the second rendering texture.
[0018] As an optional implementation of this invention, determining whether each pair of rendering textures in the rendering texture set supports sharing memory space includes:
[0019] Determine whether the first rendering texture and the second rendering texture are the input and output of the same rendering command, respectively;
[0020] If the first rendering texture and the second rendering texture are the input and output of the same rendering command, then it is determined that the first rendering texture and the second rendering texture do not support sharing memory space.
[0021] As an optional implementation of this invention, determining whether each pair of rendering textures in the rendering texture set supports sharing memory space includes:
[0022] Determine whether the first rendering texture and the second rendering texture are the input and output of the same rendering command, respectively;
[0023] If the first rendering texture and the second rendering texture are the input and output of the same rendering command, then it is determined that the first rendering texture and the second rendering texture do not support sharing memory space.
[0024] As an optional implementation of this invention, determining whether each pair of rendering textures in the rendering texture set supports sharing memory space includes:
[0025] Determine whether a third rendering command needs to be executed after the first and second rendering commands are executed sequentially; the first rendering command includes a rendering command with a first rendering texture as output, the second rendering command includes a rendering command with a second rendering texture as output, and the third rendering command includes a rendering command with the first rendering texture as input;
[0026] If so, then it is determined that the first rendering texture and the second rendering texture do not support sharing memory space.
[0027] As an optional implementation of this invention, the step of determining whether a third rendering command needs to be executed after the first and second rendering commands are executed sequentially includes:
[0028] Obtain the rendering commands used to render the target image and the rendering textures of each rendering command;
[0029] Generate a directed acyclic graph using rendering commands as nodes and rendering textures as paths;
[0030] Perform topological sorting on the directed acyclic graph to generate a topological sequence of the directed acyclic graph;
[0031] Based on the topological sequence, determine whether a third rendering command is needed after executing the first and second rendering commands in sequence.
[0032] As an optional implementation of this invention, the step of determining whether a third rendering command needs to be executed after the first and second rendering commands are executed sequentially, based on the topology sequence, includes:
[0033] Determine whether the topology sequence includes the third rendering command located after the second rendering command;
[0034] If the rendering command sequence includes the third rendering command located after the second rendering command, then it is determined that the first rendering texture and the second rendering texture do not support memory space reuse.
[0035] As an optional implementation of this invention, the step of dividing the rendering textures in the rendering texture set into at least one rendering texture group based on whether each pair of rendering textures in the rendering texture set supports sharing memory space includes:
[0036] Determine whether the rendering textures in the rendering texture set support sharing the same memory space;
[0037] If so, then all rendering textures in the rendering texture set are treated as a single rendering texture group;
[0038] If the rendering texture set includes two rendering textures that do not support sharing a memory space, then one of the two rendering textures that do not support sharing a memory space is deleted from the rendering texture set, and the process returns to the step of determining whether the rendering textures in the rendering texture set support sharing the same memory space.
[0039] The set of rendering textures deleted from the rendering texture set is taken as the rendering texture set, and the step of determining whether the rendering textures in the rendering texture set support sharing the same memory space is returned.
[0040] As an optional implementation of this invention, allocating the same memory space for rendering textures belonging to the same rendering texture group includes:
[0041] Allocate the same memory space for rendering textures that belong to the same rendering texture group from the memory resource pool.
[0042] As an optional implementation of this invention, the method further includes:
[0043] After the target image is rendered, the memory space allocated to each rendering texture is switched from occupied to idle.
[0044] In a second aspect, embodiments of the present invention provide a memory allocation device, comprising:
[0045] An acquisition unit is used to acquire a set of rendering textures, the set of rendering textures including rendering textures for various rendering commands used to render the target image;
[0046] The processing unit is used to determine whether each pair of rendering textures in the rendering texture set supports sharing memory space;
[0047] A grouping unit is used to divide the rendering textures in the rendering texture set into at least one rendering texture group according to whether the rendering textures in the rendering texture set support sharing memory space. Rendering textures belonging to the same rendering texture group support sharing memory space.
[0048] An allocation unit is used to allocate the same memory space for rendering textures that belong to the same rendering texture group.
[0049] As an optional implementation of the present invention, the processing unit is specifically used to determine whether the attributes of the first rendering texture are the same as the attributes of the second rendering texture; if the attributes of the first rendering texture are different from the attributes of the second rendering texture, then it is determined that the first rendering texture and the second rendering texture do not support sharing memory space.
[0050] In an optional implementation of this invention, the processing unit is specifically configured to determine whether the format and resolution of the first rendering texture are the same as those of the second rendering texture; if the format of the first rendering texture is different from that of the second rendering texture, and / or the resolution of the first rendering texture is different from that of the second rendering texture, then it is determined that the attributes of the first rendering texture are different from those of the second rendering texture; if the format of the first rendering texture is the same as that of the second rendering texture, and the resolution of the first rendering texture is the same as that of the second rendering texture, then it is determined that the attributes of the first rendering texture are the same as those of the second rendering texture.
[0051] As an optional implementation of the present invention, the processing unit is specifically used to determine whether the first rendering texture and the second rendering texture are respectively the input and output of the same rendering command; if the first rendering texture and the second rendering texture are respectively the input and output of the same rendering command, then it is determined that the first rendering texture and the second rendering texture do not support sharing memory space.
[0052] As an optional implementation of the present invention, the processing unit is specifically used to determine whether the first rendering texture and the second rendering texture are respectively the input and output of the same rendering command; if the first rendering texture and the second rendering texture are respectively the input and output of the same rendering command, then it is determined that the first rendering texture and the second rendering texture do not support sharing memory space.
[0053] As an optional implementation of the present invention, the processing unit is specifically used to determine whether a third rendering command needs to be executed after the first rendering command and the second rendering command are executed in sequence; if so, it is determined that the first rendering texture and the second rendering texture do not support sharing memory space.
[0054] The first rendering command includes a rendering command that outputs a first rendering texture, the second rendering command includes a rendering command that outputs a second rendering texture, and the third rendering command includes a rendering command that inputs the first rendering texture.
[0055] As an optional implementation of this invention, the processing unit is specifically configured to acquire various rendering commands for rendering the target image and the rendering textures of each rendering command; generate a directed acyclic graph with the rendering commands as nodes and the rendering textures as paths; perform topological sorting on the directed acyclic graph to generate a topological sequence of the directed acyclic graph; and determine, based on the topological sequence, whether a third rendering command needs to be executed after the first and second rendering commands are executed sequentially.
[0056] As an optional implementation of the present invention, the processing unit is specifically used to determine whether the topology sequence includes the third rendering command located after the second rendering command; if the rendering command sequence includes the third rendering command located after the second rendering command, then it is determined that the first rendering texture and the second rendering texture do not support the reuse of memory space.
[0057] As an optional implementation of this invention, the grouping unit is specifically used to determine whether the rendering textures in the rendering texture set support sharing the same memory space; if so, all the rendering textures in the rendering texture set are grouped as a single rendering texture group; if the rendering texture set includes two rendering textures that do not support sharing the same memory space, one of the two rendering textures that do not support sharing the same memory space is deleted from the rendering texture set, and the process returns to the step of determining whether the rendering textures in the rendering texture set support sharing the same memory space; the set of rendering textures deleted from the rendering texture set is taken as the rendering texture set, and the process returns to the step of determining whether the rendering textures in the rendering texture set support sharing the same memory space.
[0058] As an optional implementation of the present invention, the allocation unit is specifically used to allocate the same memory space from the memory resource pool for rendering textures belonging to the same rendering texture group.
[0059] As an optional implementation of the present invention, the allocation unit is further configured to switch the state of the memory space allocated to each rendering texture from occupied state to idle state after the rendering of the target image is completed.
[0060] Thirdly, embodiments of the present invention provide an electronic device, including: a memory and a processor, wherein the memory is used to store a computer program; and the processor is used to execute the memory allocation method described in the first aspect or any optional embodiment of the first aspect when the computer program is invoked.
[0061] Fourthly, embodiments of the present invention provide a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the memory allocation method described in the first aspect or any optional implementation thereof.
[0062] Fifthly, embodiments of the present invention provide a computer program product, including a computer program / instruction, which, when executed by a processor, implements the memory allocation method described in the first aspect or any optional implementation of the first aspect.
[0063] The memory allocation method provided in this embodiment of the invention first obtains a set of rendering textures composed of rendering textures for each rendering command used to render a target image. Then, it determines whether each pair of rendering textures in the set supports sharing memory space. Based on this, the rendering textures in the set are divided into at least one rendering texture group. Finally, the same memory space is allocated to rendering textures belonging to the same rendering texture group. Because this embodiment of the invention can allocate rendering textures that support sharing memory space to the same rendering texture group based on whether they support it, and allocates one memory space to each rendering texture belonging to the same group, it reduces the memory resource consumption of rendering textures compared to the prior art where memory is allocated to each rendering texture individually. Attached Figure Description
[0064] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.
[0065] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0066] Figure 1 This is one of the flowcharts for a memory allocation method provided in an embodiment of the present invention;
[0067] Figure 2 A directed acyclic graph provided for embodiments of the present invention;
[0068] Figure 3 One of the schematic diagrams of the topological sequence provided in the embodiments of the present invention;
[0069] Figure 4 A second schematic diagram of the topological sequence provided in an embodiment of the present invention;
[0070] Figure 5 The second flowchart of the memory allocation method provided in the embodiments of the present invention;
[0071] Figure 6 A schematic diagram of a memory allocation device provided in an embodiment of the present invention;
[0072] Figure 7 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present invention. Detailed Implementation
[0073] To better understand the above-mentioned objectives, features, and advantages of the present invention, the solutions of the present invention will be further described below. It should be noted that, unless otherwise specified, the embodiments of the present invention and the features thereof can be combined with each other.
[0074] Many specific details are set forth in the following description in order to provide a full understanding of the invention, but the invention may also be practiced in other ways different from those described herein; obviously, the embodiments in the specification are only some embodiments of the invention, and not all embodiments.
[0075] In the embodiments of the present invention, the terms "exemplary" or "for example" are used to indicate that something is an example, illustration, or description. Any embodiment or design described as "exemplary" or "for example" in the embodiments of the present invention should not be construed as being more preferred or advantageous than other embodiments or designs. Specifically, the use of the terms "exemplary" or "for example" is intended to present the relevant concepts in a specific manner. Furthermore, in the description of the embodiments of the present invention, unless otherwise stated, "a plurality of" means two or more.
[0076] This invention provides a memory allocation method, referring to... Figure 1 As shown, the memory allocation method provided in this embodiment of the invention includes the following steps:
[0077] S101. Obtain the set of rendering textures.
[0078] The rendering texture set includes rendering textures for various rendering commands used to render the target image.
[0079] Specifically, when rendering the image frame corresponding to the target image begins, each rendering command (DrawCall) and the input and output rendering textures of each rendering command can be obtained, and the input and output rendering textures of all rendering commands can be combined to form the rendering texture set.
[0080] For example, the rendering commands used to render the target image include: rendering command A, rendering command B, rendering command C, rendering command D, rendering command E, rendering command F, and rendering command G. The rendering texture of rendering command A includes: output rendering texture 0; the rendering texture of rendering command B includes: input rendering texture 0 and output rendering texture 1; the rendering texture of rendering command C includes: input rendering texture 1 and output rendering texture 2; the rendering texture of rendering command D includes: input rendering texture 3 and output rendering texture 4; the rendering texture of rendering command E includes: input rendering texture 1, input rendering texture 2, input rendering texture 4 and output rendering texture 5; the rendering texture of rendering command F includes: input rendering texture 5 and output rendering texture 6; and the rendering texture of rendering command G includes: output rendering texture 3. Therefore, the obtained set of rendering textures is: {rendering texture 0, rendering texture 1, rendering texture 2, rendering texture 3, rendering texture 4, rendering texture 5, rendering texture 6}.
[0081] S102. Determine whether each pair of rendering textures in the rendering texture set supports sharing memory space.
[0082] That is, determining whether any two rendering textures in the rendering texture set support sharing memory space.
[0083] In this embodiment of the invention, supporting shared memory space between two objects means that one of the rendering textures can be stored in the shared memory space after the other rendering texture is deleted from the shared memory space, without affecting the execution of each rendering command, that is, without affecting the normal rendering of the target image.
[0084] Continuing from the example above, if the rendering texture set is: {rendering texture 0, rendering texture 1, rendering texture 2, rendering texture 3, rendering texture 4, rendering texture 5, rendering texture 6}, then it is necessary to determine... Whether the 21 rendering texture pairs support sharing memory space is as follows: [Rendering texture 0 and rendering texture 1], [Rendering texture 0 and rendering texture 2], [Rendering texture 0 and rendering texture 3], [Rendering texture 0 and rendering texture 4], [Rendering texture 0 and rendering texture 5], [Rendering texture 0 and rendering texture 6], [Rendering texture 1 and rendering texture 2], [Rendering texture 1 and rendering texture 3], [Rendering texture 1 and rendering texture 4], [Rendering texture 1 and rendering texture 5], [Rendering texture 1 and rendering texture 6], [Rendering texture 2 and rendering texture 3], [Rendering texture 2 and rendering texture 4], [Rendering texture 2 and rendering texture 5], [Rendering texture 2 and rendering texture 6], [Rendering texture 3 and rendering texture 4], [Rendering texture 3 and rendering texture 5], [Rendering texture 3 and rendering texture 6], [Rendering texture 4 and rendering texture 5], [Rendering texture 4 and rendering texture 6], [Rendering texture 5 and rendering texture 6].
[0085] S103. Based on whether the rendering textures in the rendering texture set support sharing memory space between each other, divide the rendering textures in the rendering texture set into at least one rendering texture group.
[0086] Among them, rendering textures belonging to the same rendering texture group can share memory space with each other.
[0087] For example, if rendering texture 0 and rendering texture 1 support sharing a memory space, rendering texture 0 and rendering texture 2 support sharing a memory space, and rendering texture 1 and rendering texture 2 support sharing a memory space, then rendering texture 0, rendering texture 1 and rendering texture 3 can be divided into a rendering texture group.
[0088] S104. Allocate the same memory space for rendering textures that belong to the same rendering texture group.
[0089] Continuing with the example above, if the rendering texture set {rendering texture 0, rendering texture 1, rendering texture 2, rendering texture 3, rendering texture 4, rendering texture 5, rendering texture 6} is divided into four rendering texture groups: [rendering texture 0, rendering texture 2, rendering texture 6], [rendering texture 1], [rendering texture 3, rendering texture 5], and [rendering texture 4], then four memory spaces need to be allocated. Compared to the existing technology that allocates one memory space for each rendering texture (e.g., the above seven rendering textures require seven memory spaces), the memory allocation method provided in this embodiment only requires four memory spaces, thus reducing the memory resource consumption of rendering textures.
[0090] The memory allocation method provided in this embodiment of the invention first obtains a set of rendering textures composed of rendering textures for each rendering command used to render a target image. Then, it determines whether each pair of rendering textures in the set supports sharing memory space. Based on this, the rendering textures in the set are divided into at least one rendering texture group. Finally, the same memory space is allocated to rendering textures belonging to the same rendering texture group. Because this embodiment of the invention can allocate rendering textures that support sharing memory space to the same rendering texture group based on whether they support it, and allocates one memory space to each rendering texture belonging to the same group, it reduces the memory resource consumption of rendering textures compared to the prior art where memory is allocated to each rendering texture individually.
[0091] As an optional embodiment of the present invention, step S102 (determining whether each rendering texture in the rendering texture set supports sharing memory space) includes:
[0092] Determine whether the properties of the first rendering texture are the same as those of the second rendering texture;
[0093] If the attributes of the first rendering texture are different from those of the second rendering texture, then it is determined that the first rendering texture and the second rendering texture do not support sharing memory space.
[0094] Further, optionally, the properties of the rendered texture include the format of the rendered texture and the resolution of the rendered texture.
[0095] That is, determining whether the attributes of the first rendering texture are the same as those of the second rendering texture includes: determining whether the format and resolution of the first rendering texture are the same as those of the second rendering texture;
[0096] Determine whether the format and resolution of the first rendering texture are the same as those of the second rendering texture;
[0097] If the format of the first rendering texture is different from that of the second rendering texture, and / or the resolution of the first rendering texture is different from that of the second rendering texture, then it is determined that the attributes of the first rendering texture are different from those of the second rendering texture.
[0098] If the format of the first rendering texture is the same as that of the second rendering texture, and the resolution of the first rendering texture is the same as that of the second rendering texture, then it is determined that the attributes of the first rendering texture are the same as those of the second rendering texture.
[0099] For example, one possible implementation for determining whether the format and resolution of the first rendered texture are the same as those of the second rendered texture is as follows:
[0100] Determine whether the format of the first rendering texture is the same as the format of the second rendering texture;
[0101] If the format of the first rendering texture is different from the format of the second rendering texture, then it is determined that the attributes of the first rendering texture are different from the attributes of the second rendering texture.
[0102] If the format of the first rendering texture is the same as the format of the second rendering texture, then determine whether the resolution of the first rendering texture is the same as the resolution of the second rendering texture.
[0103] If the resolution of the first rendering texture is different from the resolution of the second rendering texture, then it is determined that the attributes of the first rendering texture are different from the attributes of the second rendering texture.
[0104] If the resolution of the first rendering texture is the same as the resolution of the second rendering texture, then the attributes of the first rendering texture are determined to be the same as the attributes of the second rendering texture.
[0105] It should be noted that the above embodiments are illustrated by first determining whether the format of the rendered textures is the same and then determining whether the resolution of the rendered textures is the same. However, the embodiments of the present invention do not limit the order of determining whether the format of the rendered textures is the same and whether the resolution of the rendered textures is the same. It is possible to determine whether the format of the rendered textures is the same first and then determine whether the resolution of the rendered textures is the same, or to determine whether the resolution of the rendered textures is the same first and then determine whether the format of the rendered textures is the same, or to determine whether the format of the rendered textures is the same and whether the resolution of the rendered textures is the same at the same time.
[0106] When rendering images using rendering textures, the GPU uses normalized coordinates. If multiple rendering textures with different attributes share the same storage space, it will cause rendering anomalies. Therefore, when two rendering textures have different attributes, it is determined that the two rendering textures do not support sharing the same storage space, thereby avoiding the occurrence of rendering anomalies.
[0107] As an optional embodiment of the present invention, step S102 (determining whether each rendering texture in the rendering texture set supports sharing memory space) includes:
[0108] Determine whether the first rendering texture and the second rendering texture are the input and output of the same rendering command, respectively;
[0109] If the first rendering texture and the second rendering texture are the input and output of the same rendering command, then it is determined that the first rendering texture and the second rendering texture do not support sharing memory space.
[0110] If the first rendering texture and the second rendering texture are the input and output of the same rendering command, respectively, then when executing the rendering command, the GPU needs to simultaneously read from the first rendering texture and write to the second rendering texture in a shared memory space. However, the GPU does not support simultaneous read and write operations to the same memory space, leading to rendering anomalies. Therefore, if the first rendering texture and the second rendering texture are the input and output of the same rendering command, it is determined that the first rendering texture and the second rendering texture do not support sharing a memory space.
[0111] As an optional embodiment of the present invention, step S102 (determining whether each rendering texture in the rendering texture set supports sharing memory space) includes:
[0112] Determine whether a third rendering command is needed after executing the first and second rendering commands sequentially. The first rendering command includes a rendering command that outputs a first rendering texture, the second rendering command includes a rendering command that outputs a second rendering texture, and the third rendering command includes a rendering command that inputs the first rendering texture.
[0113] If so, then it is determined that the first rendering texture and the second rendering texture do not support sharing memory space.
[0114] It should be noted that, in the embodiments of the present invention, the sequential execution of the first rendering command and the second rendering command only means that the execution order of the first rendering command is before the execution order of the second rendering command, but does not limit the interval between the first rendering command and the second rendering command. The first rendering command and the second rendering command can be rendering commands executed adjacently (the interval between the first rendering command and the second rendering command is 0), or the first rendering command and the second rendering command can be rendering commands executed non-adjacently (the execution interval between the first rendering command and the second rendering command is greater than or equal to 1).
[0115] Since the second rendering texture output by the second rendering command reuses the memory space of the first rendering texture output by the first rendering command, the first rendering texture will be deleted from the shared memory space and the second rendering texture will be written into the shared memory space. After the first rendering texture is deleted from the shared memory space, if a third rendering command with the first rendering texture as input is to be executed, the rendering will be abnormal because the first rendering texture cannot be read. Therefore, if a third rendering command with the first rendering texture as input is to be executed after the first rendering command with the first rendering texture as output and the second rendering command with the second rendering texture as output are executed in sequence, it is determined that the first rendering texture and the second rendering texture do not support sharing the memory space.
[0116] Optionally, one implementation of determining whether a third rendering command needs to be executed after the first and second rendering commands have been executed sequentially may include the following steps a to d:
[0117] Step a: Obtain the rendering commands used to render the target image and the rendering textures for each rendering command.
[0118] Step b: Generate a Directed Acyclic Graph (DAG) using rendering commands as nodes and rendering textures as paths.
[0119] For example, the rendering commands used to render the target image include: rendering command A, rendering command B, rendering command C, rendering command D, rendering command E, rendering command F, and rendering command G. The rendering texture of rendering command A includes rendering texture 0; the rendering texture of rendering command B includes rendering texture 0 and rendering texture 1; the rendering texture of rendering command C includes rendering texture 1 and rendering texture 2; the rendering texture of rendering command D includes rendering texture 3 and rendering texture 4; the rendering texture of rendering command E includes rendering texture 1, rendering texture 2, and rendering texture 4; the rendering texture of rendering command F includes rendering texture 6; and the rendering texture of rendering command G includes rendering texture 3. Then, refer to... Figure 2As shown, the generated directed acyclic graph includes 7 nodes with rendering commands as nodes and 9 paths with rendering textures as paths. The 7 nodes are: rendering command A, rendering command B, rendering command C, rendering command D, rendering command E, rendering command F, and rendering command G. The 9 paths are: the path from rendering command A to rendering command B (rendering texture 0), the path from rendering command B to rendering command C (rendering texture 1), the path from rendering command B to rendering command D (rendering texture 1), the path from rendering command B to rendering command E (rendering texture 1), the path from rendering command C to rendering command E (rendering texture 2), the path from rendering command G to rendering command D (rendering texture 3), the path from rendering command D to rendering command E (rendering texture 4), the path from rendering command E to rendering command F (rendering texture 5), and the output path of rendering command F (rendering texture 6).
[0120] Step c: Perform topological sorting on the directed acyclic graph to generate a topological sequence of the directed acyclic graph.
[0121] Specifically, in this embodiment of the invention, topological sorting of the directed acyclic graph can refer to arranging all nodes in the directed acyclic graph into a linear sequence, such that for any pair of nodes u and v in the graph, if there exists a path from node u to node v, then node u is located before node v in the linear sequence.
[0122] Following the example above, for Figure 2 The topological sequence obtained by topological sorting the directed acyclic graph shown can be as follows: Figure 3 As shown, the order of the rendering commands is as follows: rendering command A, rendering command B, rendering command C, rendering command G, rendering command D, rendering command E, and rendering command F.
[0123] Furthermore, as illustrated in the previous example, for Figure 2 The topological sequence obtained by topological sorting the directed acyclic graph shown can also be as follows: Figure 4 As shown, the order of the rendering commands is as follows: rendering command A, rendering command G, rendering command B, rendering command C, rendering command D, rendering command E, and rendering command F.
[0124] It should be noted that there may be many possible topological sequences for generating the directed acyclic graph by performing topological sorting on the directed acyclic graph. In this embodiment of the invention, any one of them can be randomly generated.
[0125] Step d: Determine, based on the topological sequence, whether it is necessary to execute a rendering command with the second rendering texture as input after executing the rendering command with the first rendering texture as output.
[0126] Optionally, step d above (determining whether a rendering command with the second rendering texture as input needs to be executed after executing a rendering command with the first rendering texture as output, based on the topological sequence) includes:
[0127] Determine whether the topology sequence includes a second rendering command located after the first rendering command;
[0128] If the rendering command sequence includes a second rendering command located after the first rendering command, then it is determined that the first rendering texture and the second rendering texture do not support memory space reuse.
[0129] For example: in Figure 3 In the topology sequence shown, when determining whether rendering texture 1 and rendering texture 4 support sharing memory space, the rendering command D with rendering texture 4 as the output rendering texture is first determined. The topology sequence includes the rendering command E after rendering command D and with rendering texture 1 as the input. Therefore, it is determined that the first rendering texture and the second rendering texture do not support sharing memory space.
[0130] As a specific implementation of the memory allocation method provided in this embodiment of the invention, refer to Figure 5 As shown, the memory allocation scheme provided in this embodiment of the invention may specifically include the following steps:
[0131] S501, Obtain the set of rendering textures.
[0132] The rendering texture set includes rendering textures for various rendering commands used to render the target image.
[0133] Using the example above as an example, the following description will be based on the following example with the following rendering texture set: {rendering texture 0, rendering texture 1, rendering texture 2, rendering texture 3, rendering texture 4, rendering texture 5, rendering texture 6}.
[0134] S502. Determine whether the attributes of the first rendering texture are the same as those of the second rendering texture.
[0135] S503. Determine whether the first rendering texture and the second rendering texture are the input and output of the same rendering command, respectively.
[0136] S504. Determine whether a third rendering command needs to be executed after the first and second rendering commands have been executed in sequence.
[0137] The first rendering command includes a rendering command that outputs a first rendering texture, the second rendering command includes a rendering command that outputs a second rendering texture, and the third rendering command includes a rendering command that inputs the first rendering texture.
[0138] It should also be noted that the order in which steps S502, S503, and S504 are executed in this embodiment of the invention is not limited, and steps S502, S503, and S504 can be executed in any order. For example, step S502 can be executed first, then step S503, and finally step S504. Another example is that steps S502, S503, and S504 can be executed simultaneously.
[0139] In steps S502, S503, and S504 above, if the attributes of the first rendering texture are different from those of the second rendering texture, or if the first rendering texture and the second rendering texture are respectively the input and output of the same rendering command, or if a third rendering command needs to be executed after the first and second rendering commands are executed sequentially, then step S505 is executed. If the attributes of the first rendering texture are the same as those of the second rendering texture, or if the first rendering texture and the second rendering texture are not the input and output of the same rendering command, and if a third rendering command does not need to be executed after the first and second rendering commands are executed sequentially, then step S506 is executed.
[0140] S505, Determine that the first rendering texture and the second rendering texture do not support sharing memory space.
[0141] S506, Determine that the first rendering texture and the second rendering texture support sharing memory space.
[0142] It should be noted that when the rendering texture set is: {rendering texture 0, rendering texture 1, rendering texture 2, rendering texture 3, rendering texture 4, rendering texture 5, rendering texture 6}, it is necessary to specify the rendering texture pairs [rendering texture 0 and rendering texture 1], [rendering texture 0 and rendering texture 2], [rendering texture 0 and rendering texture 3], [rendering texture 0 and rendering texture 4], [rendering texture 0 and rendering texture 5], [rendering texture 0 and rendering texture 6], [rendering texture 1 and rendering texture 2], [rendering texture 1 and rendering texture 3], [rendering texture 1 and rendering texture 4], [rendering texture 1 and rendering texture 6], etc. The rendering textures in [Rendering Texture 5], [Rendering Texture 1 and Rendering Texture 6], [Rendering Texture 2 and Rendering Texture 3], [Rendering Texture 2 and Rendering Texture 4], [Rendering Texture 2 and Rendering Texture 5], [Rendering Texture 2 and Rendering Texture 6], [Rendering Texture 3 and Rendering Texture 4], [Rendering Texture 3 and Rendering Texture 5], [Rendering Texture 3 and Rendering Texture 6], [Rendering Texture 4 and Rendering Texture 5], [Rendering Texture 4 and Rendering Texture 6], and [Rendering Texture 5 and Rendering Texture 6] are respectively used as the first rendering texture and the second rendering texture to perform the above steps S502 to S506 once.
[0143] For example, for render texture 0 and render texture 1, since render texture 0 is the input of render command B and render texture 1 is the output of render command B, they are the input and output of the same render command, respectively. Therefore, render texture 0 and render texture 1 do not support sharing memory space.
[0144] For example, for render texture 2 and render texture 3, since after executing render command C (output of render texture 2) and render command G (output of render texture 3) in sequence, render command E (input of render texture 2) also needs to be executed, render texture 2 and render texture 3 do not support sharing memory space.
[0145] The topological sequence of directed acyclic graphs generated by each rendering command and the rendering texture of each rendering command, such as... Figure 3 As shown in Table 1, when all the properties of the rendered textures are the same, the results of determining whether each rendered texture supports sharing memory space can be seen below:
[0146] Table 1
[0147]
[0148] "Yes" indicates that the two corresponding rendering textures support sharing memory space, while "No" indicates that the two corresponding rendering textures do not support sharing memory space.
[0149] S507. Determine whether the rendering textures in the rendering texture set support sharing the same memory space.
[0150] Specifically, it can be determined whether the rendering textures in the rendering texture set support sharing the same memory space based on whether each pair of rendering textures in the rendering texture set supports sharing the same memory space. If any two rendering textures in the rendering texture set support sharing the same memory space, then it is determined that the rendering textures in the rendering texture set support sharing the same memory space. If one or more pairs of rendering textures in the rendering texture set do not support sharing the same memory space, then it is determined that the rendering textures in the rendering texture set do not support sharing the same memory space.
[0151] In step S507 above, if the rendering textures in the rendering texture set support sharing the same memory space, then step S508 is executed.
[0152] S508. Take all the rendering textures in the rendering texture set as a rendering texture group.
[0153] In step S507 above, if the rendering texture set includes two rendering textures that do not support sharing a memory space, then step S509 is executed.
[0154] S509. Delete one of the two rendering textures that do not support sharing a memory space from the rendering texture set, and return to execute the above step S507 (determine whether the rendering textures in the rendering texture set support sharing the same memory space).
[0155] The above steps S507 to S509 form a loop process. The end condition of this loop process is that the judgment result of S507 is that the rendering textures in the rendering texture set support sharing the same memory space, and the above step S508 (taking all the rendering textures in the rendering texture set as a rendering texture group) has been executed.
[0156] It should be noted that the rendering texture set in the embodiments of the present invention supports sharing the same memory space in two cases: one is that the rendering texture set includes multiple rendering textures, and any two rendering textures can share the same memory space; the other is that the rendering texture set includes only one rendering texture.
[0157] Continuing with the example shown in Table 1 above:
[0158] First iteration: Since rendering texture 0 and rendering texture 1 do not support shared memory space, rendering texture 1 is removed from the rendering texture set. The remaining rendering textures in the set are: {rendering texture 0, rendering texture 2, rendering texture 3, rendering texture 4, rendering texture 5, rendering texture 6}. At this point, the rendering texture set composed of the deleted textures is: {rendering texture 1}.
[0159] Second loop: Since rendering texture 2 and rendering texture 3 do not support memory reuse, rendering texture 2 is removed from the rendering texture set. The remaining rendering textures in the rendering texture set are: {rendering texture 0, rendering texture 3, rendering texture 4, rendering texture 5, rendering texture 6}. At this time, the rendering texture set composed of the deleted rendering textures is: {rendering texture 1, rendering texture 2}.
[0160] In the third iteration: Since rendering texture 3 and rendering texture 4 do not support shared memory space, rendering texture 4 is removed from the rendering texture set. The remaining rendering textures in the set are: {rendering texture 0, rendering texture 3, rendering texture 5, rendering texture 6}. At this point, the rendering texture set composed of the deleted rendering textures is: {rendering texture 1, rendering texture 2, rendering texture 4}.
[0161] Fourth iteration: Since rendering texture 5 and rendering texture 6 do not support shared memory space, rendering texture 5 is removed from the rendering texture set. The remaining rendering textures in the set are: {rendering texture 0, rendering texture 3, rendering texture 5}, and rendering textures 0, 3, and 5 all support shared memory space. The loop ends here, resulting in the first rendering texture group {rendering texture 0, rendering texture 3, rendering texture 5}. The rendered texture set formed by the deleted textures is: {rendering texture 1, rendering texture 2, rendering texture 4, rendering texture 6}.
[0162] When the cyclic process formed by S507 to S509 ends, the following step S510 is executed.
[0163] S510, The set of rendering textures deleted from the rendering texture set is taken as the rendering texture set, and the process returns to execute the above step S507 (the step of determining whether the rendering textures in the rendering texture set support sharing the same memory space).
[0164] Steps S507 to S510 above form another loop process. The termination condition of this loop process is still that the judgment result of S507 is that the rendering textures in the rendering texture set support sharing the same memory space, and step S508 above (taking all the rendering textures in the rendering texture set as a rendering texture group) is executed. At this time, the set composed of the rendering textures deleted from the rendering texture set is an empty set, and the loop ends.
[0165] Continuing from the example above:
[0166] The first loop: The rendered texture set formed by deleting rendered textures from the rendered texture set is: {Rendered Texture 1, Rendered Texture 2, Rendered Texture 4, Rendered Texture 6}. Since rendered texture 1 and rendered texture 2 do not share memory space, rendered texture 1 is deleted from the rendered texture set. The remaining rendered textures in the set are: {Rendered Texture 2, Rendered Texture 4, Rendered Texture 6}. Again, since rendered texture 2 and rendered texture 4 do not share memory space, rendered texture 4 is deleted from the rendered texture set. The remaining rendered textures in the set are: {Rendered Texture 2, Rendered Texture 6}, and rendered texture 2 and rendered texture 6 can share memory space. This results in the second rendered texture set: {Rendered Texture 2, Rendered Texture 6}. The rendered texture set formed by deleting rendered textures from the set again is: {Rendered Texture 1, Rendered Texture 4}.
[0167] The second loop: The rendered texture set formed by deleting rendered textures from the rendered texture set is: {rendered texture 1, rendered texture 4}. Since rendered texture 1 and rendered texture 4 do not support memory reuse, rendered texture 1 is deleted from the rendered texture set, and rendered texture 4 is treated as a single rendered texture group. The rendered texture set formed by deleting rendered textures from the rendered texture set again is: {rendered texture 1}.
[0168] The third loop: The rendering texture set composed of the rendering textures deleted from the rendering texture set is: {rendering texture 1}. There is no need to delete the rendering texture group from the rendering texture set. Rendering texture 1 is treated as a rendering texture group, and the loop ends.
[0169] Ultimately, the judgment results shown in Table 1 above yield four rendering texture groups, which are as follows:
[0170] {Render texture 0, Render texture 3, Render texture 5};
[0171] {Render texture 2, Render texture 6};
[0172] {Render Texture 4};
[0173] {Render Texture 1}.
[0174] S511: Allocate the same memory space for rendering textures that belong to the same rendering texture group.
[0175] That is, allocate the same memory space for rendering texture 0, rendering texture 3, and rendering texture 5 respectively, allocate the same memory space for rendering texture 2 and rendering texture 6 respectively, allocate a memory space for rendering texture 1, and allocate a memory space for rendering texture 4.
[0176] As an optional implementation of this invention, step S104 (allocating the same memory space for rendering textures belonging to the same rendering texture group) includes:
[0177] Allocate the same memory space for rendering textures that belong to the same rendering texture group from the memory resource pool.
[0178] In other words, using a resource pool to allocate memory for rendering textures belonging to the same rendering texture group can avoid the GPU having to request memory and then allocate it every time it needs to allocate memory, thereby improving memory allocation efficiency.
[0179] Furthermore, the method provided in this embodiment of the invention also includes: after rendering the target image, switching the state of the memory space allocated to each rendering texture from an occupied state to an idle state.
[0180] Returning memory to the memory resource pool promptly after use can improve memory utilization.
[0181] Based on the same inventive concept, as an implementation of the above method, this embodiment of the invention also provides a memory allocation device. This device embodiment corresponds to the aforementioned method embodiment. For ease of reading, this device embodiment will not repeat the details of the aforementioned method embodiment one by one, but it should be clear that the memory allocation device in this embodiment can correspondingly implement all the contents of the aforementioned method embodiment.
[0182] Figure 6 This is a schematic diagram of the structure of the memory allocation device provided in an embodiment of the present invention, as shown below. Figure 6 As shown, the memory allocation device 600 provided in this embodiment includes:
[0183] The acquisition unit 61 is used to acquire a set of rendering textures, the set of rendering textures including rendering textures of various rendering commands used to render the target image;
[0184] Processing unit 62 is used to determine whether each pair of rendering textures in the rendering texture set supports sharing memory space;
[0185] Grouping unit 63 is used to divide the rendering textures in the rendering texture set into at least one rendering texture group according to whether the rendering textures in the rendering texture set support sharing memory space between each other. Rendering textures belonging to the same rendering texture group support sharing memory space between each other.
[0186] Allocation unit 64 is used to allocate the same memory space for rendering textures belonging to the same rendering texture group.
[0187] As an optional implementation of the present invention, the processing unit 62 is specifically used to determine whether the attributes of the first rendering texture are the same as the attributes of the second rendering texture; if the attributes of the first rendering texture are different from the attributes of the second rendering texture, it is determined that the first rendering texture and the second rendering texture do not support sharing memory space.
[0188] As an optional implementation of this invention, the processing unit 62 is specifically used to determine whether the format and resolution of the first rendering texture are the same as the format and resolution of the second rendering texture; if the format of the first rendering texture is different from the format of the second rendering texture, and / or the resolution of the first rendering texture is different from the resolution of the second rendering texture, then it is determined that the attributes of the first rendering texture are different from the attributes of the second rendering texture; if the format of the first rendering texture is the same as the format of the second rendering texture, and the resolution of the first rendering texture is the same as the resolution of the second rendering texture, then it is determined that the attributes of the first rendering texture are the same as the attributes of the second rendering texture.
[0189] As an optional implementation of the present invention, the processing unit 62 is specifically used to determine whether the first rendering texture and the second rendering texture are respectively the input and output of the same rendering command; if the first rendering texture and the second rendering texture are respectively the input and output of the same rendering command, then it is determined that the first rendering texture and the second rendering texture do not support sharing memory space.
[0190] As an optional implementation of the present invention, the processing unit 62 is specifically used to determine whether the first rendering texture and the second rendering texture are respectively the input and output of the same rendering command; if the first rendering texture and the second rendering texture are respectively the input and output of the same rendering command, then it is determined that the first rendering texture and the second rendering texture do not support sharing memory space.
[0191] As an optional implementation of the present invention, the processing unit 62 is specifically used to determine whether a third rendering command needs to be executed after the first rendering command and the second rendering command are executed in sequence; if so, it is determined that the first rendering texture and the second rendering texture do not support sharing memory space.
[0192] The first rendering command includes a rendering command that outputs a first rendering texture, the second rendering command includes a rendering command that outputs a second rendering texture, and the third rendering command includes a rendering command that inputs the first rendering texture.
[0193] As an optional implementation of this invention, the processing unit 62 is specifically configured to acquire various rendering commands for rendering the target image and the rendering textures of each rendering command; generate a directed acyclic graph with the rendering commands as nodes and the rendering textures as paths; perform topological sorting on the directed acyclic graph to generate a topological sequence of the directed acyclic graph; and determine, based on the topological sequence, whether a third rendering command needs to be executed after the first and second rendering commands are executed sequentially.
[0194] As an optional implementation of the present invention, the processing unit 62 is specifically used to determine whether the topology sequence includes the third rendering command located after the second rendering command; if the rendering command sequence includes the third rendering command located after the second rendering command, then it is determined that the first rendering texture and the second rendering texture do not support the reuse of memory space.
[0195] As an optional implementation of this invention, the grouping unit 63 is specifically used to determine whether the rendering textures in the rendering texture set support sharing the same memory space; if so, all the rendering textures in the rendering texture set are grouped as a single rendering texture group; if the rendering texture set includes two rendering textures that do not support sharing the same memory space, one of the two rendering textures that do not support sharing the same memory space is deleted from the rendering texture set, and the process returns to the step of determining whether the rendering textures in the rendering texture set support sharing the same memory space; the set of rendering textures deleted from the rendering texture set is taken as the rendering texture set, and the process returns to the step of determining whether the rendering textures in the rendering texture set support sharing the same memory space.
[0196] As an optional implementation of the present invention, the allocation unit 64 is specifically used to allocate the same memory space from the memory resource pool for rendering textures belonging to the same rendering texture group.
[0197] As an optional implementation of the present invention, the allocation unit 64 is further configured to switch the state of the memory space allocated to each rendering texture from occupied state to idle state after the rendering of the target image is completed.
[0198] Based on the same inventive concept, embodiments of the present invention also provide an electronic device. Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention, such as... Figure 7 As shown, the electronic device provided in this embodiment includes a memory 71 and a processor 72. The memory 71 is used to store computer programs; the processor 72 is used to execute the steps of the memory allocation method provided in the above embodiment when the computer program is invoked.
[0199] This invention also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the memory allocation method provided in the above embodiments.
[0200] This invention also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the memory allocation method provided in the above embodiments.
[0201] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product implemented on one or more computer-usable storage media containing computer-usable program code.
[0202] The processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor can be a microprocessor or any conventional processor.
[0203] Memory may include non-persistent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, like read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0204] Computer-readable media include both permanent and non-permanent, removable and non-removable storage media. Storage media can store information using any method or technology; the information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media do not include transient computer-readable media, such as modulated data signals and carrier waves.
[0205] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. A memory allocation method, characterized by, include: Obtain a set of rendering textures, which includes rendering textures for various rendering commands used to render the target image; Determine whether each pair of rendering textures in the rendering texture set supports sharing memory space; Based on whether the rendering textures in the rendering texture set support sharing memory space between each other, the rendering textures in the rendering texture set are divided into at least one rendering texture group, and the rendering textures belonging to the same rendering texture group support sharing memory space between each other. Allocate the same memory space for rendering textures that belong to the same rendering texture group; Determining whether each pair of rendering textures in the rendering texture set supports sharing memory space includes: Determine whether the first rendering texture and the second rendering texture are the input and output of the same rendering command, respectively; If the first rendering texture and the second rendering texture are the input and output of the same rendering command, then it is determined that the first rendering texture and the second rendering texture do not support sharing memory space.
2. The method according to claim 1, characterized in that, Determining whether each pair of rendering textures in the rendering texture set supports sharing memory space includes: Determine whether the properties of the first rendering texture are the same as those of the second rendering texture; If the attributes of the first rendering texture are different from those of the second rendering texture, then it is determined that the first rendering texture and the second rendering texture do not support sharing memory space.
3. The method according to claim 2, characterized in that, The step of determining whether the attributes of the first rendering texture are the same as those of the second rendering texture includes: Determine whether the format and resolution of the first rendering texture are the same as those of the second rendering texture; If the format of the first rendering texture is different from that of the second rendering texture, and / or the resolution of the first rendering texture is different from that of the second rendering texture, then it is determined that the attributes of the first rendering texture are different from those of the second rendering texture. If the format of the first rendering texture is the same as that of the second rendering texture, and the resolution of the first rendering texture is the same as that of the second rendering texture, then it is determined that the attributes of the first rendering texture are the same as those of the second rendering texture.
4. The method according to claim 1, characterized in that, Determining whether each pair of rendering textures in the rendering texture set supports sharing memory space includes: Determine whether a third rendering command needs to be executed after the first and second rendering commands are executed sequentially; the first rendering command includes a rendering command with a first rendering texture as output, the second rendering command includes a rendering command with a second rendering texture as output, and the third rendering command includes a rendering command with the first rendering texture as input; If so, then it is determined that the first rendering texture and the second rendering texture do not support sharing memory space.
5. The method according to claim 4, characterized in that, The determination of whether a third rendering command needs to be executed after the first and second rendering commands have been executed sequentially includes: Obtain the rendering commands used to render the target image and the rendering textures of each rendering command; Generate a directed acyclic graph using rendering commands as nodes and rendering textures as paths; Perform topological sorting on the directed acyclic graph to generate a topological sequence of the directed acyclic graph; Based on the topological sequence, determine whether a third rendering command is needed after executing the first and second rendering commands in sequence.
6. The method according to claim 5, characterized in that, The step of determining whether a third rendering command needs to be executed after the first and second rendering commands are executed sequentially, based on the topology sequence, includes: Determine whether the topology sequence includes the third rendering command located after the second rendering command; If the rendering command sequence includes the third rendering command located after the second rendering command, then it is determined that the first rendering texture and the second rendering texture do not support memory space reuse.
7. The method according to claim 1, characterized in that, The step of dividing the rendering textures in the rendering texture set into at least one rendering texture group based on whether each pair of rendering textures in the rendering texture set supports sharing memory space includes: Determine whether the rendering textures in the rendering texture set support sharing the same memory space; If so, then all rendering textures in the rendering texture set are treated as a single rendering texture group; If the rendering texture set includes two rendering textures that do not support sharing a memory space, then one of the two rendering textures that do not support sharing a memory space is deleted from the rendering texture set, and the process returns to the step of determining whether the rendering textures in the rendering texture set support sharing the same memory space. The set of rendering textures deleted from the rendering texture set is taken as the rendering texture set, and the step of determining whether the rendering textures in the rendering texture set support sharing the same memory space is returned.
8. The method according to claim 1, characterized in that, Allocating the same memory space for rendering textures belonging to the same rendering texture group includes: Allocate the same memory space for rendering textures that belong to the same rendering texture group from the memory resource pool.
9. The method according to claim 8, characterized in that, The method further includes: After the target image is rendered, the memory space allocated to each rendering texture is switched from occupied to idle.
10. A memory allocation device, characterized in that, include: An acquisition unit is used to acquire a set of rendering textures, the set of rendering textures including rendering textures for various rendering commands used to render the target image; The processing unit is used to determine whether each pair of rendering textures in the rendering texture set supports sharing memory space; A grouping unit is used to divide the rendering textures in the rendering texture set into at least one rendering texture group according to whether the rendering textures in the rendering texture set support sharing memory space. Rendering textures belonging to the same rendering texture group support sharing memory space. An allocation unit is used to allocate the same memory space to rendering textures that belong to the same rendering texture group. The processing unit is used to determine whether the first rendering texture and the second rendering texture are the input and output of the same rendering command, respectively; if the first rendering texture and the second rendering texture are the input and output of the same rendering command, then it is determined that the first rendering texture and the second rendering texture do not support sharing memory space.
11. An electronic device, characterized in that, include: A memory and a processor, wherein the memory is used to store a computer program; and the processor is used to execute the memory allocation method according to any one of claims 1-9 when the computer program is invoked.
12. A computer-readable storage medium, characterized in that, It stores a computer program, which, when executed by a processor, implements the memory allocation method according to any one of claims 1-9.