A data processing method and related apparatus
By arranging multiple attribute data into contiguous storage space in the GPU and using attribute selectors to determine the address, the inefficiency caused by conditional judgments in the GPU rendering process is solved, achieving a more efficient rendering process.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-10-28
- Publication Date
- 2026-03-17
AI Technical Summary
During graphics processing unit (GPU) rendering, the rendering efficiency is low because conditional judgments need to be frequently executed to select multiple attribute data.
The GPU arranges multiple attribute data of the same type into a contiguous storage space and directly determines the address of the target attribute data through the attribute selector, avoiding conditional judgment.
It improves GPU rendering efficiency, reduces the number of conditional checks, and enhances instruction execution efficiency.
Smart Images

Figure CN114511657B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a data processing method and related apparatus. Background Technology
[0002] Rendering refers to the process of projecting a model in a 3D scene into a 2D image according to the set environment, lighting, materials and rendering parameters. The generated 2D image can well reflect the 3D scene.
[0003] Currently, in mobile devices or other types of computers, the rendering process is typically handled by the Graphics Processing Unit (GPU). When a scene needs to be rendered, the central processing unit (CPU) transmits the material to be rendered and its required attribute data, such as positional, color, or texture attributes, to the GPU, which then renders the material based on the attribute data.
[0004] However, in related technologies, when multiple attribute data are available for the source material, the GPU needs to frequently perform conditional checks during rendering to select the attribute data actually required by the source material. Because the GPU frequently performs these conditional checks, its execution logic is complex, resulting in low rendering efficiency. Summary of the Invention
[0005] This application provides a data processing method in which the GPU arranges multiple attribute data of the same type into a data space, so that the GPU can directly determine the address of the target attribute data in a contiguous storage space based on the attribute selector, thereby directly obtaining the target data. This avoids conditional judgment in the GPU, ensures that the GPU can have high instruction execution efficiency, and improves the rendering efficiency of the GPU.
[0006] This application provides a data processing method applicable to an electronic device with a CPU and a GPU, capable of performing an image rendering process. The method includes: the GPU acquiring rendering data sent by the CPU, the rendering data being, for example, vertex data or fragment data, and including multiple attribute data of the same attribute type, such as multiple texture coordinate attribute data, multiple color attribute data, or multiple weight attribute data. The GPU stores the multiple attribute data in a contiguous storage space, which may be, for example, an array space. The array space is a contiguous memory block used to store the ordered multiple attribute data, i.e., the multiple attribute data are stored in a contiguous address space. The GPU acquires an attribute selector corresponding to a material to be rendered, the attribute selector being used to select attribute data for rendering the material, the attribute selector being, for example, carried within the material to be rendered, and capable of indicating any one of the multiple attribute data. Based on the attribute selector, the GPU determines the address of a target attribute data in the contiguous storage space, the target attribute data being used to render the material. The GPU acquires the target attribute data in the contiguous storage space based on the address to achieve the rendering of the material.
[0007] In this scheme, after the GPU obtains the rendering data sent by the CPU, the GPU arranges multiple attribute data of the same type in the rendering data into the data space. This allows the GPU to directly determine the address of the target attribute data in the contiguous storage space based on the attribute selector, thereby obtaining the target data. This avoids conditional judgments in the GPU, ensuring that the GPU has high instruction execution efficiency and improving the rendering efficiency of the GPU.
[0008] In one possible implementation, the GPU arranges multiple attribute data in an ordered manner into a contiguous storage space. Specifically, this can include: the GPU arranging the multiple attribute data into the contiguous storage space according to the storage order of the attribute data in the rendering data. That is, the GPU can arrange the multiple attribute data according to the order in which the attribute data is stored in the rendering data; the earlier the attribute data is stored in the rendering data, the earlier it is in the contiguous storage space.
[0009] In one possible implementation, the method further includes: the GPU acquiring indication information sent by the CPU, which indicates the location information of multiple attribute data in the rendering data. For example, when the CPU stores the corresponding attribute data through a pre-defined storage location, the location represents the position of each attribute data, and each location can store one corresponding attribute data. The indication information acquired by the GPU may include a mapping relationship between attribute data and locations. The GPU arranges the multiple attribute data into the contiguous storage space according to the storage order of the multiple attribute data in the rendering data, which may include: the GPU determining the location of each attribute data in the rendering data based on the indication information (e.g., the mapping relationship between attribute data and locations). The GPU arranges the multiple attribute data into the contiguous storage space according to the order between the locations corresponding to each attribute data. For example, the GPU can arrange the multiple attribute data into the contiguous storage space according to the numbering order between locations, where the smaller the location number, the earlier the corresponding attribute data is in the contiguous storage space.
[0010] In this scheme, the GPU determines the position of each attribute data in multiple attribute data based on the indication information, and determines the arrangement order of the attribute data in contiguous storage space based on the positional relationship between each attribute data, thereby realizing the arrangement of multiple attribute data into contiguous storage space and ensuring the feasibility of the scheme.
[0011] In one possible implementation, for multiple attribute data of the same attribute type in vertex data, the CPU can assign a corresponding attribute index to each attribute data to indicate each attribute data. For example, for UV attribute data 0, UV attribute data 1, UV attribute data 2, and UV attribute data 3, the attribute indices assigned by the CPU can be 0, 1, 2, and 3, respectively. Based on the attribute index, any one of the multiple attribute data can be uniquely identified. Furthermore, in order for the GPU to select the target attribute data corresponding to the material to be rendered, the CPU can assign a corresponding attribute selector to the material to be rendered. This attribute selector can actually be the attribute index corresponding to the target attribute data. Therefore, the indication information sent by the CPU can include the mapping relationship between the attribute index and the location in the rendering data, where the attribute index represents each attribute data among the multiple attribute data. Based on the mapping relationship in the indication information and the attribute selector, the GPU can determine the location of each attribute data in the vertex data. By establishing the mapping relationship between the attribute index of the attribute data and the location, the amount of data in the indication information can be reduced while effectively indicating the location corresponding to the attribute data, thus saving transmission bandwidth.
[0012] In one possible implementation, a location within the rendering data is used to store one or more attribute data items of the same type. For example, if the vertex data includes multiple attribute data items of the same type, and the space of a location is sufficient to support storing multiple such attribute data items, then more than one attribute data item can be stored in a single location, and the attribute data items stored in the same location must be of the same type. Simply put, after determining that the vertex data includes multiple attribute data items of the same type, the CPU can determine whether a location can simultaneously store multiple such attribute data items based on the data length of the attribute data items of the same type. If so, multiple attribute data items of the same type are stored in one location; otherwise, the multiple attribute data items of the same type are stored separately in multiple locations. By storing multiple attribute data items of the same type in one location, the number of locations can be reduced, saving memory resources.
[0013] This approach arranges multiple attribute data of the same type in the rendering data into contiguous storage spaces, and then determines the address of the target attribute data based on the attribute selector, thereby retrieving the target attribute data. Therefore, compared to related technologies that can only store one attribute data in a location, this approach can store attribute data of multiple attribute types in a location without affecting the GPU's normal retrieval of the target attribute data. This reduces the number of locations required and saves memory resources.
[0014] In one possible implementation, the GPU determines the address of the target attribute data in a contiguous memory space based on the attribute selector. Specifically, this can include: determining the address of the target attribute data in a contiguous memory space based on the attribute selector and the data length of the target attribute data; wherein the data lengths of the multiple attribute data are the same. That is, since the multiple attribute data in the data space are of the same attribute type, their data lengths are identical. Therefore, given that the address range of the data space and the number of attribute data in the data space are known, the address corresponding to each attribute data can be determined based on the storage order of each attribute data in the data space. For example, the address range of the contiguous memory space obtained by arranging UV attribute data 0, UV attribute data 1, UV attribute data 2, and UV attribute data 3 is 0-7, and the data length of each attribute data in this contiguous memory space is 2. Therefore, when the attribute selectors are 0-3, the address of the target attribute data corresponding to the attribute selector can be obtained based on the value of the attribute selector and the length of the attribute data. For example, when the attribute selector is 0, the address of the target attribute data can be determined to be 0-1; when the attribute selector is 2, the address of the target attribute data can be determined to be 4-5.
[0015] In one possible implementation, the method further includes: the GPU obtaining the starting address of the contiguous storage space; and the GPU determining the address of the target attribute data in the contiguous storage space based on the attribute selector and the data length of the target attribute data, including: determining the starting address of the target attribute data in the contiguous storage space based on the starting address of the contiguous storage space and the product of the attribute selector and the data length; and determining the ending address of the target attribute data in the contiguous storage space based on the starting address of the target attribute data in the contiguous storage space and the data length. For example, when the data length is 2, the attribute selector is S, and the starting address of the contiguous storage space is N, the starting address of the target attribute data in the contiguous storage space is N+2*S, and the ending address of the target attribute data in the contiguous storage space is N+2*S+1.
[0016] In one possible implementation, the rendering data is determined by the CPU based on the material to be rendered. The attribute data included in the rendering data consists entirely of the attribute data required for rendering the material. Simply put, the rendering standard for a material may contain multiple attribute data types with the same attribute type, such as six types of UV attribute data. However, during the actual rendering process, the material to be rendered may not need all the attribute types from the rendering standard; for example, it may only need four types of UV attribute data. In this case, the CPU can pre-determine the attribute data required for rendering the material based on the attribute types needed, thus avoiding transmitting attribute data of all attribute types in the rendering data and saving transmission bandwidth.
[0017] In one possible implementation, the rendering data includes position attribute data, normal vector attribute data, color attribute data, texture coordinate attribute data, tangent attribute data, joint attribute data, and / or weight attribute data.
[0018] A second aspect of this application provides an electronic device comprising: a processing unit and an acquisition unit; the acquisition unit is configured to acquire rendering data sent by a CPU, the rendering data including multiple attribute data, the multiple attribute data having the same attribute type; the processing unit is configured to arrange the multiple attribute data into a contiguous storage space; the acquisition unit is further configured to acquire an attribute selector corresponding to a material to be rendered, the attribute selector being used to select attribute data for rendering the material to be rendered; the processing unit is further configured to determine the address of target attribute data in the contiguous storage space based on the attribute selector, the target attribute data being used to render the material to be rendered; the processing unit is further configured to acquire the target attribute data in the contiguous storage space based on the address.
[0019] In one possible implementation, the processing unit is also used to: arrange multiple attribute data into a contiguous storage space according to the storage order of the multiple attribute data in the rendering data.
[0020] In one possible implementation, the acquisition unit is further configured to acquire instruction information sent by the CPU, the instruction information being used to indicate the position information of multiple attribute data in the rendering data; the processing unit is further configured to determine the storage position of each of the multiple attribute data in the rendering data according to the instruction information; the processing unit is further configured to arrange the multiple attribute data into a contiguous storage space according to the order of their storage positions.
[0021] In one possible implementation, the indication information includes a mapping between the attribute index and its storage location in the rendered data, whereby the attribute index is used to represent each of the multiple attribute data.
[0022] In one possible implementation, the storage location in the rendering data is used to store attribute data of one or more attribute types.
[0023] In one possible implementation, the processing unit is further configured to determine the address of the target attribute data in a contiguous storage space based on the data lengths of the attribute selector and the target attribute data; wherein the data lengths of multiple attribute data are the same.
[0024] In one possible implementation, the acquisition unit is further configured to acquire the starting address of the contiguous storage space; the processing unit is further configured to determine the starting address of the target attribute data in the contiguous storage space based on the starting address of the contiguous storage space and the product of the attribute selector and the data length; and to determine the ending address of the target attribute data in the contiguous storage space based on the starting address of the target attribute data in the contiguous storage space and the data length.
[0025] In one possible implementation, the rendering data is determined by the CPU based on the material to be rendered, and the attribute data included in the rendering data are all attribute data required when rendering the material to be rendered.
[0026] In one possible implementation, the rendering data includes position attribute data, normal vector attribute data, color attribute data, texture coordinate attribute data, tangent attribute data, joint attribute data, and / or weight attribute data.
[0027] A third aspect of this application provides an electronic device comprising: a processor, a non-volatile memory, and a volatile memory; wherein the non-volatile memory or the volatile memory stores computer-readable instructions; and the processor reads the computer-readable instructions to enable the electronic device to implement a method as described in any of the implementations of the first aspect.
[0028] A fourth aspect of this application provides a computer-readable storage medium storing a computer program that, when run on a computer, causes the computer to perform a method as described in any of the implementations of the first aspect.
[0029] The fifth aspect of this application provides a computer program product that, when run on a computer, causes the computer to perform a method as described in any of the implementations of the first aspect.
[0030] A sixth aspect of this application provides a chip including one or more processors. Part or all of the processors are used to read and execute a computer program stored in a memory to perform the methods in any possible implementation of any of the above aspects. Optionally, the chip includes a memory, which is connected to the processor via a circuit or wire. Optionally, the chip also includes a communication interface, to which the processor is connected. The communication interface is used to receive data and / or information to be processed, the processor obtains the data and / or information from the communication interface, processes the data and / or information, and outputs the processing result through the communication interface. The communication interface can be an input / output interface. The methods provided in this application can be implemented by a single chip or by multiple chips working together. Attached Figure Description
[0031] Figure 1 This is a schematic diagram of the process for obtaining attribute data in a related technology.
[0032] Figure 2 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application;
[0033] Figure 3 A flowchart illustrating a data processing method 300 provided in an embodiment of this application;
[0034] Figure 4 This is a schematic diagram illustrating the storage of attribute data provided in an embodiment of this application;
[0035] Figure 5 This is a schematic diagram illustrating the arrangement of attribute data into a contiguous storage space, as provided in an embodiment of this application.
[0036] Figure 6 A schematic diagram of a contiguous storage space provided in an embodiment of this application;
[0037] Figure 7 This is a schematic diagram of GPU rearrangement attribute data provided in an embodiment of this application;
[0038] Figure 8 This is a schematic diagram of the structure of an electronic device 800 provided in an embodiment of this application. Detailed Implementation
[0039] The embodiments of this application are described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. As those skilled in the art will recognize, with the development of technology and the emergence of new scenarios, the technical solutions provided by the embodiments of this application are also applicable to similar technical problems.
[0040] The terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments described herein can be implemented in a sequence other than that illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or device that includes a series of steps or modules is not necessarily limited to those explicitly listed, but may include other steps or modules not explicitly listed or inherent to such processes, methods, products, or devices. The naming or numbering of steps appearing in this application does not imply that the steps in the method flow must be performed in the chronological / logical order indicated by the naming or numbering. The execution order of named or numbered process steps can be changed according to the desired technical purpose, as long as the same or similar technical effect is achieved.
[0041] With the development of computer technology, more and more applications, such as games and video applications, require the display of high-quality images on electronic devices. These images are usually rendered by the electronic device based on models in a 3D scene.
[0042] Currently, in electronic devices, the rendering process is typically handled by the Graphics Processing Unit (GPU). When a scene needs to be rendered, the CPU transmits the material to be rendered and its required attribute data, such as positional, color, or texture attributes, to the GPU, which then renders the material based on this attribute data. As 3D scenes in applications become increasingly complex, the attribute data used to render the material also becomes more complex. For some attributes of the material to be rendered, there may often be multiple attribute data of the same type, such as three texture attributes or seven color attributes.
[0043] In related technologies, when multiple attribute data of the same type are available for selection in the source material, the GPU often needs to frequently perform conditional judgments when rendering a vertex or fragment to select the actual attribute data required for that vertex or fragment. Because the GPU frequently performs conditional judgments, its execution logic is complex, leading to a decrease in GPU rendering efficiency.
[0044] For example, when the CPU transmits vertex attribute data to the GPU, multiple locations are often created to carry the attribute data, with different attribute data residing in different locations. Suppose the CPU transmits four attribute data of the same type to the GPU: attribute data 0, attribute data 1, attribute data 2, and attribute data 3, and these four attribute data are located in location 0, location 1, location 2, and location 3, respectively. Then, when the GPU renders a vertex, it can obtain the attribute selector corresponding to that vertex, and then execute corresponding conditional statements based on the value of the attribute selector, thereby obtaining the attribute data corresponding to that attribute selector.
[0045] Specifically, GPUs can perform conditional checks by calling if-else or switch-case statements. For example, a simple example of a GPU using an if-else statement for conditional checks is shown below:
[0046] if (s == 0) use location0 / / If s equals 0, then retrieve the attribute data of location0.
[0047] else if (s == 1) use location1 / / If s equals 1, then get the attribute data of location1
[0048] else if (s == 2) use location2 / / If s equals 2, then get the attribute data of location2
[0049] else if (s == 3) use location3 / / If s equals 3, then get the attribute data of location3
[0050] You can also refer to Figure 1 , Figure 1 This is a flowchart illustrating the process of obtaining attribute data in a related technology. Combined with the example above and... Figure 1 It can be seen that when the GPU needs to select the attribute data corresponding to the attribute selector from multiple attribute data of the same attribute type, the GPU often needs to execute multiple conditional judgments to select the required attribute data. When there is a large amount of attribute data of the same attribute type, the GPU may need to execute multiple conditional judgment statements to obtain the required attribute data, resulting in low GPU instruction execution efficiency and reduced GPU rendering efficiency.
[0051] In view of this, embodiments of this application provide a data processing method in which the GPU arranges multiple attribute data of the same attribute type into a data space, so that the GPU can directly determine the address of the target attribute data in a contiguous storage space based on the attribute selector, thereby directly obtaining the target data, avoiding conditional judgment in the GPU, ensuring that the GPU can have high instruction execution efficiency, and improving the rendering efficiency of the GPU.
[0052] The data processing method in this embodiment can be executed by an electronic device. This electronic device includes a CPU and a GPU, capable of rendering images. Exemplarily, this electronic device can be a mobile phone, tablet computer, laptop computer, personal computer (PC), mobile internet device (MID), wearable device, virtual reality (VR) device, augmented reality (AR) device, wireless electronic device in industrial control, wireless electronic device in self-driving, wireless electronic device in remote medical surgery, wireless electronic device in smart grid, wireless electronic device in transportation safety, wireless electronic device in smart city, wireless electronic device in smart home, etc. This electronic device can be a device running Android, iOS, Windows, or other operating systems.
[0053] To facilitate understanding, the following will be combined with... Figure 2 This section provides a detailed description of the specific structure of the electronic device. Please refer to [reference needed]. Figure 2 , Figure 2 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application.
[0054] In one possible embodiment, such as Figure 2 As shown, the electronic device 2000 may include: a central processing unit 2001, a graphics processor 2002, a display device 2003, and a memory 2004. Optionally, the electronic device 2000 may further include at least one communication bus. Figure 2 (Not shown in the image) is used to enable communication between various components.
[0055] It should be understood that the various components in the electronic device 2000 can also be coupled to each other via other connectors, which may include various interfaces, transmission lines, or buses. The various components in the electronic device 2000 can also be connected radially with the central processing unit 2001 at its center. In various embodiments of this application, coupling refers to mutual electrical connection or communication, including direct connection or indirect connection via other devices.
[0056] There are various ways to connect the CPU 2001 and the GPU 2002, and it is not limited to these methods. Figure 2 As shown in the diagram. In electronic device 2000, the central processing unit 2001 and the graphics processor 2002 can be located on the same chip or they can be separate chips.
[0057] The following is a brief introduction to the functions of the central processing unit 2001, graphics processing unit 2002, display device 2003, and memory 2004.
[0058] Central Processing Unit 2001: Used to run Operating System 2005 and Applications 2006. Applications 2006 can be graphics-based applications, such as games, video players, etc. Operating System 2005 provides a system graphics library interface. Applications 2006 use this system graphics library interface, along with drivers provided by Operating System 2005, such as user-mode and / or kernel-mode graphics library drivers, to generate instruction streams for rendering graphics or image frames, as well as the necessary rendering data. The system graphics library includes, but is not limited to, OpenGL ES (Open Graphics Library for Embedded System), the Kronos Platform Graphics Interface, or Vulkan (a cross-platform graphics application programming interface). The instruction stream contains a series of instructions, which are typically calls to the system graphics library interface.
[0059] Optionally, the central processing unit 2001 may include at least one of the following types of processors: application processor, one or more microprocessors, digital signal processor (DSP), microcontroller unit (MCU), or artificial intelligence processor, etc.
[0060] The central processing unit 2001 may further include necessary hardware accelerators, such as application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or integrated circuits for implementing logic operations. The processor 2001 may be coupled to one or more data buses for transferring data and instructions between the various components of the electronic device 2000.
[0061] The graphics processing unit (GPU) 2002 receives the graphics instruction stream sent by the processor 2001, generates rendering targets through the rendering pipeline, and displays the rendering targets on the display device 2003 through the operating system's layer compositing display module. The rendering pipeline, also known as the rendering pipeline, pixel pipeline, or pixel pipeline, is a parallel processing unit within the GPU 2002 used to process graphics signals. The GPU 2002 may include multiple rendering pipelines, which can process graphics signals independently and in parallel. For example, the rendering pipeline can perform a series of operations during the rendering of graphics or image frames; typical operations may include vertex processing, primitive processing, rasterization, fragment processing, etc.
[0062] Optionally, the graphics processor 2002 may include a general-purpose graphics processor that executes software, such as a GPU or other types of dedicated graphics processing units.
[0063] Display device 2003: Used to display various images generated by electronic device 2000, which may be the graphical user interface (GUI) of the operating system or image data (including still images and video data) processed by graphics processor 2002.
[0064] Optionally, the display device 2003 may include any suitable type of display screen, such as a liquid crystal display (LCD), a plasma display, or an organic light-emitting diode (OLED) display.
[0065] Memory 2004 is the transmission channel between the central processing unit 2001 and the graphics processor 2002, and can be double data rate synchronous dynamic random access memory (DDR SDRAM) or other types of cache.
[0066] The above describes the specific structure of the electronic device used in the data processing method provided in the embodiments of this application. The following will describe in detail the flow of the data processing method provided in the embodiments of this application.
[0067] Please refer to Figure 3 , Figure 3 This is a flowchart illustrating a data processing method 300 provided in an embodiment of this application. Figure 3 As shown, the data processing method 300 includes the following steps.
[0068] Step 301: The GPU obtains the rendering data sent by the CPU. The rendering data includes multiple attribute data, and the attribute types of the multiple attribute data are the same.
[0069] In this embodiment, the rendering data can be vertex data or fragment data. In the field of image processing, a vertex can be understood as a point in space, which can be represented by its spatial coordinates. Generally speaking, vertices are the most basic elements used to define the area to be rendered. By rendering each vertex in the scene, the entire scene can be rendered. Typically, each vertex has corresponding vertex data, which represents the attribute data required for rendering that vertex. For example, vertex data may include position attribute data, normal attribute data, color attribute data, texture coordinate (UV) attribute data, tangent attribute data, joint attribute data, or target weight attribute data. Different vertices may have different attribute data, and the types of attribute data included in the vertex data of different vertices may also be different. For example, the vertex data corresponding to vertex A includes position attribute data, color attribute data, and texture coordinate attribute data; the vertex data corresponding to vertex B includes position attribute data, normal attribute data, color attribute data, and texture coordinate attribute data.
[0070] Typically, after rendering vertices, the GPU can combine multiple vertices into primitives (such as points, line segments, or polygons), and then convert these primitives into fragments through rasterization. These fragments can ultimately be converted into pixel data in an image. Rasterization is the process of converting primitives into a two-dimensional image. Each point in the resulting two-dimensional image contains data such as color, depth, and texture. A point in this two-dimensional image and its related information are called a fragment.
[0071] Similarly, each fragment typically also has corresponding fragment data, which represents the data required to render that fragment. The fragment data can also include the various attribute data mentioned above.
[0072] In one possible example, the rendering data is determined by the CPU based on the material to be rendered. The attribute data included in the rendering data consists of all the attribute data required to render the material. Simply put, the rendering standard for the material may contain multiple attribute data types with the same attribute type, such as six types of UV attribute data. However, during the actual rendering process, the material to be rendered may not need all the attribute types from the rendering standard; for example, it may only need four types of UV attribute data. In this case, the CPU can pre-determine the attribute data required to render the material based on the attribute types needed, thus avoiding transmitting attribute data of all attribute types in the rendering data and saving transmission bandwidth.
[0073] For ease of description, the following will use vertex data as the rendering data as an example to introduce the data processing method provided in the embodiments of this application.
[0074] In this embodiment, during the rendering process of an image, the GPU can receive vertex data and rendering material sent by the CPU. The GPU renders the rendering material based on the received vertex data to obtain a rendered image that can be displayed on a display device. The vertex data received by the GPU includes multiple attribute data of the same type, such as multiple UV attribute data, multiple color attribute data, or multiple joints attribute data. This embodiment does not specifically limit the attribute types of these multiple attribute data.
[0075] It should be understood that multiple sets of attribute data can exist simultaneously in vertex data, each set including multiple attribute data of the same attribute type. For example, vertex data may include multiple UV attribute data and multiple color attribute data. Alternatively, vertex data may contain only one set of attribute data, which includes multiple attribute data of the same attribute type. For example, vertex data may contain only multiple UV attribute data, and only one attribute data of each of other attribute types. For ease of description, the following description uses the example of vertex data containing only one attribute type with multiple attribute data of the same type to illustrate the data processing method 300 provided in this application embodiment.
[0076] In a possible example, since the attribute data in vertex data is mostly 2D, 3D, or 4D vector data, the CPU can store the corresponding attribute data through pre-defined storage locations. Here, a location represents the position of each attribute data point, and each location can store one corresponding attribute data point. See also... Figure 4 , Figure 4 This is a schematic diagram illustrating the storage of attribute data as provided in an embodiment of this application. For example... Figure 4 As shown on the left, the vertex data includes six attribute data: position, UV data 0, UV data 1, UV data 2, UV data 3, and normal. These six attribute data are stored sequentially in six locations, from location 0 to location 5. The data length that a location can store is fixed; for example, the maximum data length a location can store is the length of a 4-dimensional vector. Figure 4 The `vec4(vector4)` shown indicates that a location can store at most one 4-dimensional vector. However, in reality, not all attribute data stored in a location is a 4-dimensional vector. For example, the `position` attribute data is a 3-dimensional vector, the `UV` attribute data is a 2-dimensional vector, and the `normal` attribute data is a 3-dimensional vector. Therefore, the actual length of the attribute data stored in a location can be the length of a 2-dimensional vector, a 3-dimensional vector, or a 4-dimensional vector.
[0077] In another possible example, when the vertex data includes multiple attribute data of the same attribute type, and the location has sufficient space to support storing multiple attribute data of the same attribute, more than one attribute data can be stored in one location, and the attribute data stored in the same location have the same attribute type. For example... Figure 4As shown on the right, for UV attribute data 0, UV attribute data 1, UV attribute data 2, and UV attribute data 3, which are all 2-dimensional vectors, a single location can store two UV attribute data simultaneously. Therefore, UV attribute data 0 and UV attribute data 1 can be stored in location 1 at the same time, while UV attribute data 2 and UV attribute data 3 can be stored in location 2 at the same time.
[0078] In practical applications, after determining that the vertex data includes multiple attribute data of the same type, the CPU can determine whether a location can simultaneously store multiple data of that attribute type based on the data length of the attribute data of the same type. If so, multiple data of the same attribute type are stored in one location; otherwise, the multiple data of the same attribute type are stored in separate locations. By storing multiple data of the same attribute type in one location, the number of locations can be reduced, saving memory resources.
[0079] In step 302, the GPU arranges multiple attribute data into a contiguous storage space.
[0080] In this embodiment, after receiving vertex data, the GPU can identify multiple attribute data points belonging to the same attribute type within the vertex data. These attribute data points are then arranged sequentially into a contiguous storage space. This contiguous storage space can be, for example, an array space. An array refers to an ordered sequence of elements, where the elements have the same data type. An array space can be a contiguous block of memory used to store the array. By arranging multiple attribute data points into a contiguous storage space, these multiple attribute data points can be stored within this contiguous memory block.
[0081] In one possible example, the GPU may arrange multiple attribute data into the contiguous storage space according to the order in which the attribute data is stored in the rendering data. That is, the GPU may arrange multiple attribute data according to the order in which the attribute data is stored in the rendering data, that is, the earlier the attribute data is stored in the rendering data, the earlier it is in the contiguous storage space.
[0082] In one possible example, the vertex data sent by the CPU may include other attribute data besides the aforementioned attribute data. Therefore, to distinguish these multiple attribute data from the other attribute data, the GPU can determine the position of these multiple attribute data within the vertex data based on indication information indicating the location of the attribute data.
[0083] For example, the GPU receives instruction information sent by the CPU, which indicates the location information of multiple attribute data in vertex data; the GPU determines the location of each attribute data in the vertex data according to the instruction information; the GPU arranges the multiple attribute data into contiguous storage space according to the order of the locations. Specifically, the GPU may arrange the multiple attribute data into contiguous storage space according to the numbering of the multiple locations where the multiple attribute data reside. See also... Figure 5 , Figure 5 This is a schematic diagram illustrating the arrangement of attribute data into a contiguous storage space, as provided in an embodiment of this application. Figure 5 As shown, UV data 0 and UV data 1 located in location 1, and UV data 2 and UV data 3 located in location 2 are arranged sequentially into contiguous storage spaces according to their location numbers. Within these contiguous storage spaces, UV attribute data 0, UV attribute data 1, UV attribute data 2, and UV attribute data 3 are arranged sequentially from address 0 to address 7, with each UV attribute data occupying the same data length within the contiguous storage space.
[0084] In one possible example, the indication information may include a mapping between attribute data and locations in the vertex data. Based on this mapping, the GPU can determine the location of each attribute data point in the vertex data. For example, for... Figure 4 In the example shown on the right, the indication information obtained by the GPU can be seen in Table 1:
[0085] Table 1
[0086] Location Attribute data Location0 Position attribute data Location1 UV attribute data 0, UV attribute data 1 Location2 UV attribute data 2, UV attribute data 3 Location3 Normal attribute data
[0087] As shown in Table 1, based on this indication information, the GPU can determine the attribute data stored in each location, thereby determining the location where multiple attribute data of the same attribute type are stored. In this way, the GPU can retrieve the multiple attribute data from the location where they reside and arrange them sequentially into contiguous storage spaces.
[0088] Step 303: The GPU obtains the attribute selector corresponding to the material to be rendered. This attribute selector is used to select the attribute data of the material to be rendered.
[0089] During the GPU rendering process, the GPU can obtain the attribute selector corresponding to the material to be rendered. This attribute selector can be carried in the material to be rendered to select the attribute data for rendering the material.
[0090] It should be understood that for multiple attribute data of the same type in vertex data, the CPU can assign a corresponding attribute index to each attribute data to indicate each attribute data. For example, for UV attribute data 0, UV attribute data 1, UV attribute data 2, and UV attribute data 3, the attribute indices assigned by the CPU can be 0, 1, 2, and 3, respectively. Based on the attribute index, any one of the multiple attribute data can be uniquely identified. Furthermore, in order for the GPU to select the target attribute data corresponding to the material to be rendered, the CPU can assign a corresponding attribute selector to the material to be rendered. This attribute selector can actually be the attribute index corresponding to the target attribute data. Therefore, based on the attribute selector, the GPU can uniquely determine the target attribute data used to render the material.
[0091] Step 304: Based on the attribute selector, the GPU determines the address of the target attribute data in a contiguous storage space. This target attribute data is used to render the material to be rendered.
[0092] In one possible example, since multiple attribute data in the data space are of the same attribute type and have the same data length, given that the address range of the data space and the number of attribute data in the data space are known, the address corresponding to each attribute data can be determined based on the storage order of each attribute data in the data space.
[0093] For example, after obtaining the attribute selector used to determine the attribute data, the GPU can determine the address of the target attribute data in contiguous memory space based on the attribute selector and the data length of the target attribute data. Specifically, the GPU can obtain the starting address of the contiguous memory space; then, based on the starting address of the contiguous memory space and the product of the attribute selector and the data length, the GPU determines the starting address of the target attribute data in the contiguous memory space; and based on the starting address of the target attribute data in the contiguous memory space and the data length, the GPU determines the ending address of the target attribute data in the contiguous memory space.
[0094] Please refer to Figure 6 , Figure 6 This is a schematic diagram of a contiguous storage space provided in an embodiment of this application. For example... Figure 6As shown, the address range of the contiguous storage space obtained by arranging UV attribute data 0, UV attribute data 1, UV attribute data 2, and UV attribute data 3 is 0-7, and the data length of each attribute data in the contiguous storage space is 2. Therefore, when the attribute selectors are 0-3, the address of the target attribute data corresponding to the attribute selector can be obtained based on the value of the attribute selector and the data length of the attribute data. That is, the address of the target attribute data is [2*S, 2*S+1], where S represents the value of the attribute selector. For example, when the attribute selector is 0, the address of the target attribute data can be determined to be 0-1; when the attribute selector is 2, the address of the target attribute data can be determined to be 4-5.
[0095] Figure 5 The example used a contiguous memory space starting at address 0. In practical applications, the starting address of the contiguous memory space can also be non-zero. The GPU can still determine the address of the target attribute data based on the attribute selector. For example, with a data length of 2, an attribute selector of S, and a starting address of N for the contiguous memory space, the starting address of the target attribute data in the contiguous memory space would be N+2*S, and the ending address of the target attribute data in the contiguous memory space would be N+2*S+1.
[0096] For example, suppose the address range of the contiguous storage space obtained by arranging UV attribute data 0, UV attribute data 1, UV attribute data 2, and UV attribute data 3 is 15-22, and the data length of each attribute data in the contiguous storage space is 2. Then, when the attribute selectors are 0-3, the address of the target attribute data corresponding to the attribute selector can be obtained based on the value of the attribute selector, the data length of the attribute data, and the starting address of the contiguous storage space, that is, the address of the target attribute data is [15+2*S, 15+2*S+1]. For example, when the attribute selector is 0, the address of the target attribute data can be determined to be 15-16; when the attribute selector is 2, the address of the target attribute data can be determined to be 19-20.
[0097] Step 305: The GPU retrieves the target attribute data from contiguous storage space based on the address.
[0098] After determining the address where the target attribute data is located, the GPU can obtain the target attribute data from that address and then perform rendering of the material to be rendered based on the target attribute data.
[0099] In this embodiment, after the GPU obtains the rendering data sent by the CPU, the GPU arranges multiple attribute data of the same attribute type in the rendering data into the data space. This allows the GPU to directly determine the address of the target attribute data in the contiguous storage space based on the attribute selector, thereby obtaining the target data. This avoids conditional judgment in the GPU, ensuring that the GPU has high instruction execution efficiency and improving the rendering efficiency of the GPU.
[0100] The above details the process by which the GPU acquires target attribute data. To facilitate understanding, the following section will use specific examples to explain in detail the process by which the GPU arranges multiple attribute data of the same type into contiguous storage space.
[0101] Please refer to Figure 7 , Figure 7 This is a schematic diagram illustrating a GPU rearrangement of attribute data provided in an embodiment of this application. Figure 7 As shown, the CPU can send vertex data and indication information to the GPU. The vertex data includes four locations: location0, location1, location2, and location3. These four locations sequentially store position attribute data (x0, y0, z0), UV attribute data 0 (s0, t0), normal attribute data (x1, y1, z1), and UV attribute data 1 (s1, t1). The indication information includes the mapping relationship between locations and attribute data, indicating the attribute data stored in each location.
[0102] Based on the vertex data and indication information described above, the GPU can rearrange the acquired vertex data. For example, the GPU can store position attribute data, UV attribute data, and normal attribute data—three different attribute types—in different address spaces, and label the attribute type of the attribute data stored in each address space. Specifically, the GPU can store the position attribute data from location 0 in address space 1, the normal attribute data from location 2 in address space 2, and the UV attribute data 0 and UV attribute data 1 from locations 1 and 3 in address space 3. Furthermore, UV attribute data 0 and UV attribute data 1 are stored in address space 3 according to the numbering order of their corresponding locations, meaning UV attribute data 0 precedes UV attribute data 1. Thus, during GPU rendering, when the GPU needs to access UV attribute data, it can determine the specific address of the corresponding UV attribute data in address space 3 based on the attribute selector, thereby retrieving the UV attribute data.
[0103] exist Figures 1 to 7 Based on the corresponding embodiments, in order to better implement the above-described solutions of the embodiments of this application, related equipment for implementing the above solutions is also provided below. For details, please refer to... Figure 8 , Figure 8 This is a schematic diagram of the structure of an electronic device 800 provided in an embodiment of this application. The electronic device 800 includes a processing unit 801 and an acquisition unit 802. The acquisition unit 802 is used to acquire rendering data sent by the CPU, the rendering data including multiple attribute data, the multiple attribute data having the same attribute type; the processing unit 801 is used to arrange the multiple attribute data into a contiguous storage space; the acquisition unit 802 is also used to acquire an attribute selector corresponding to the material to be rendered, the attribute selector being used to select attribute data for rendering the material to be rendered; the processing unit 801 is also used to determine the address of the target attribute data in the contiguous storage space according to the attribute selector, the target attribute data being used to render the material to be rendered; the processing unit 801 is also used to acquire the target attribute data in the contiguous storage space according to the address.
[0104] In one possible implementation, the processing unit 801 is further configured to: arrange multiple attribute data into a contiguous storage space according to the storage order of the multiple attribute data in the rendering data.
[0105] In one possible implementation, the acquisition unit 802 is further configured to acquire instruction information sent by the CPU, the instruction information being used to indicate the position information of multiple attribute data in the rendering data; the processing unit 801 is further configured to determine the storage location of each of the multiple attribute data in the rendering data according to the instruction information; the processing unit 801 is further configured to arrange the multiple attribute data into consecutive storage spaces according to the order of their storage locations.
[0106] In one possible implementation, the indication information includes a mapping between the attribute index and its storage location in the rendered data, whereby the attribute index is used to represent each of the multiple attribute data.
[0107] In one possible implementation, the storage location in the rendering data is used to store attribute data of one or more attribute types.
[0108] In one possible implementation, the processing unit 801 is further configured to determine the address of the target attribute data in a contiguous storage space based on the data length of the attribute selector and the target attribute data; wherein the data lengths of multiple attribute data are the same.
[0109] In one possible implementation, the acquisition unit 802 is further configured to acquire the starting address of the contiguous storage space; the processing unit 801 is further configured to determine the starting address of the target attribute data in the contiguous storage space based on the starting address of the contiguous storage space and the product of the attribute selector and the data length; and to determine the ending address of the target attribute data in the contiguous storage space based on the starting address of the target attribute data in the contiguous storage space and the data length.
[0110] In one possible implementation, the rendering data is determined by the CPU based on the material to be rendered, and the attribute data included in the rendering data are all attribute data required when rendering the material to be rendered.
[0111] In one possible implementation, the rendering data includes position attribute data, normal vector attribute data, color attribute data, texture coordinate attribute data, tangent attribute data, joint attribute data, and / or weight attribute data.
[0112] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0113] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection between apparatuses or units through some interfaces, and may be electrical, mechanical, or other forms.
[0114] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0115] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0116] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory, random access memory, magnetic disks, or optical disks.
Claims
1. A data processing method, characterized by, The method comprises the following steps: A graphics processing unit (GPU) acquires rendering data and indication information sent by a central processing unit (CPU), wherein the rendering data comprises a plurality of attribute data, the attribute data has the same attribute type, and the indication information is used to indicate position information of the attribute data in the rendering data; The GPU arranges the attribute data in an ordered manner to a continuous storage space according to the position information indicated by the indication information; The GPU acquires an attribute selection sub corresponding to a to-be-rendered material, wherein the attribute selection sub is used to select attribute data for rendering the to-be-rendered material; According to the attribute selection sub, the GPU determines an address of target attribute data in the continuous storage space, wherein the target attribute data is used to render the to-be-rendered material, and the attribute selection sub is an index corresponding to the target attribute data; The GPU acquires the target attribute data in the continuous storage space according to the address.
2. The data processing method according to claim 1, characterized in that, The method further comprises the following steps: The GPU arranges the attribute data in an ordered manner to a continuous storage space according to the position information indicated by the indication information; The GPU arranges the attribute data in an ordered manner to a continuous storage space according to the position information indicated by the indication information; 3. The data processing method according to claim 2, wherein the GPU arranges the attribute data in an ordered manner to a continuous storage space according to the position information indicated by the indication information, comprising: The GPU determines a storage position of each attribute data in the rendering data according to the indication information; The GPU arranges the attribute data in an ordered manner to a continuous storage space according to the storage position.
4. The data processing method according to claim 3, characterized in that, The indication information comprises a mapping relationship between an attribute index and a storage position in the rendering data, wherein the attribute index is used to represent each attribute data in the attribute data.
5. The data processing method according to claim 3 or 4, characterized in that, One storage position in the rendering data is used to store one or more attribute data of the same attribute type.
6. The data processing method according to any one of claims 1 to 4, characterized by, The GPU determines the address of the target attribute data in the continuous storage space according to the attribute selection sub and a data length of the target attribute data, wherein the attribute data has the same data length. The method further comprises the following steps: The GPU acquires a first address of the continuous storage space; 7. The data processing method according to claim 6, characterized in that, The GPU determines the first address of the target attribute data in the continuous storage space according to the first address of the continuous storage space and a product of the attribute selection sub and the data length; and The GPU determines a last address of the target attribute data in the continuous storage space according to the first address of the target attribute data in the continuous storage space and the data length. 8. The data processing method according to any one of claims 1 to 4, characterized by, The rendering data is determined by the CPU based on the material to be rendered, and attribute data included in the rendering data is all attribute data required for rendering the material to be rendered.
9. The data processing method according to any one of claims 1 to 4, characterized by, The rendering data includes position attribute data, normal vector attribute data, color attribute data, texture coordinate attribute data, tangent attribute data, joint attribute data, and / or weight attribute data.
10. An electronic device, comprising: The GPU is configured to: obtain rendering data sent by the CPU, the rendering data including a plurality of attribute data and indication information, the plurality of attribute data being of the same attribute type, and the indication information being used to indicate position information of the plurality of attribute data in the rendering data; arrange the plurality of attribute data in an ordered manner to a continuous storage space according to the position information indicated by the indication information; obtain an attribute selection sub corresponding to the material to be rendered, the attribute selection sub being used to select attribute data for rendering the material to be rendered, the attribute selection sub being an index corresponding to the target attribute data; determine an address of the target attribute data in the continuous storage space according to the attribute selection sub, the target attribute data being used to render the material to be rendered; obtain the target attribute data in the continuous storage space according to the address.
11. The electronic device of claim 10, wherein, The GPU is further configured to:
12. The electronic device of claim 11, wherein, arrange the plurality of attribute data in the continuous storage space in the storage order of the plurality of attribute data in the rendering data. The GPU is further configured to: determine a storage position of each attribute data in the rendering data according to the indication information; 13. The electronic device of claim 12, wherein, arrange the plurality of attribute data in the continuous storage space in the order of the storage positions.
14. The electronic device of claim 12 or 13, wherein, The indication information includes a mapping relationship between an attribute index and a storage position in the rendering data, and the attribute index is used to represent each attribute data in the plurality of attribute data.
15. The electronic device of any one of claims 10 to 13, wherein, One storage position in the rendering data is used to store one or more attribute data of the same attribute type. The GPU is further configured to: determine the address of the target attribute data in the continuous storage space according to the attribute selection sub and a data length of the target attribute data; 16. The electronic device of claim 15, wherein, wherein the plurality of attribute data are of the same data length. The GPU is further configured to: obtain a first address of the continuous storage space; determine a first address of the target attribute data in the continuous storage space according to the first address of the continuous storage space and a product of the attribute selection sub and the data length; 17. The electronic device of any one of claims 10-13, wherein, determine a last address of the target attribute data in the continuous storage space according to the first address of the target attribute data in the continuous storage space and the data length.
18. The electronic device of any one of claims 10-13, wherein, The rendering data is determined by the CPU based on the material to be rendered, and attribute data included in the rendering data is all attribute data required for rendering the material to be rendered. The rendering data includes position attribute data, normal vector attribute data, color attribute data, texture coordinate attribute data, tangent attribute data, joint attribute data, and / or weight attribute data.
19. A computer-readable storage medium, characterized in that, comprising computer readable instructions which, when executed on a computer, cause the computer to perform the method of any one of claims 1 to 9.
20. A computer program product, characterised in that, comprising computer readable instructions which, when executed on a computer, cause the computer to perform the method of any one of claims 1 to 9.
Citation Information
Patent Citations
Memory access method and device, computer equipment and storage medium
CN111338988A