A graphics processing method and device
By introducing a second virtual address space in the GPU and remapping image data in non-native formats into local formats, the memory and bandwidth problems when the GPU samples and renders non-native format data are solved, and low-cost graphics processing is achieved.
Patent Information
- Application Number
- CN201980078870.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-05-27
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2039-05-27
AI Technical Summary
When the GPU samples or renders graphics data in non-native formats, it requires additional cache areas and format conversion processors, resulting in large memory consumption, high bandwidth costs, and wasted power consumption.
By introducing a second virtual address space into the GPU, image data in non-native formats are remapped into local formats, avoiding additional cache area applications and format conversion processors, and allowing the GPU to directly access non-native format data.
It reduces memory consumption, avoids latency and bandwidth waste, reduces power consumption, and enables the GPU to sample and render non-native format graphics data in a low-cost manner.
Smart Images

Figure CN113168322B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of chip technology, and in particular to a graphics processing method and device. Background Art
[0002] Graphics Processing Unit (GPU) can be used to perform complex mathematical and geometric calculations, which are necessary for graphics rendering. Its basic working principle is based on a three-dimensional endpoint model, and makes corresponding transformations according to the perspective principle, and samples the materials (texture) corresponding to these endpoints at the same time, and writes the rendered results to the frame buffer. The cache of GPU sampled materials is usually called the texture buffer. For GPU, it can only support sampling of texture buffers of a certain format. Similarly, GPU can only support the cache of rendering targets of a certain format. In some scenarios, the data format stored in the buffer is often not supported by the GPU locally. When the GPU needs to sample this data format, the commonly used method is to convert the GPU non-local format display into the GPU local format and store it in the intermediate buffer for GPU sampling. Alternatively, when the GPU needs to render into this data format, the GPU first renders into the local format according to the sampling result, and then converts the local format data display into non-local format data and stores it in the intermediate buffer. This method requires applying for additional buffers, consumes memory, and generates additional delays, wastes bandwidth, and also wastes power consumption, and has a high cost. Summary of the invention
[0003] The embodiments of the present application provide a graphics processing method and device, which can solve the problems of large memory consumption and high bandwidth cost when a GPU samples graphics data in a non-native format or needs to render graphics data in a non-native format.
[0004] In a first aspect, a graphics processing method is provided, comprising: obtaining a first virtual address to be accessed by a graphics processor GPU, the first virtual address belonging to a first virtual address space; obtaining a second virtual address according to the first virtual address, the second virtual address belonging to a second virtual address space. The second virtual address space is different from the first virtual address space, the second virtual address space and the first virtual address space are mapped to the same first physical address space, the physical address mapped by the first virtual address corresponds to image data in a first format, and the physical address mapped by the second virtual address corresponds to image data in a second format.
[0005] It can be understood that the embodiment of the present application reconstructs a second virtual address space, which is different from the first virtual address space. The present application can map the address in the first virtual address space to an address in the newly added second virtual address space, and the physical address mapped by the second virtual address in the newly added second virtual address space corresponds to the graphic data in the second format, and the image data in the second format is different from the image data in the first format. For example, if the image data in the first format is image data that the GPU cannot directly access, and the image data in the second format is image data that the GPU can access, the embodiment of the present application realizes the conversion of the image format by mapping the address to a newly added virtual address space, without the need for the image format processor to perform format conversion, the GPU can access images in non-local formats, avoid applying for additional local GPU cache, avoid multiple migrations between the format conversion processor and the cache, reduce memory consumption, avoid delays, and save bandwidth and power consumption.
[0006] In a possible design, obtaining the second virtual address according to the first virtual address specifically includes: translating the first virtual address into an intermediate virtual address, which is a virtual address in the second virtual address space; and mapping the intermediate virtual address to the second virtual address in the second virtual address space. When the first virtual address is a first virtual address in a non-local format, the intermediate virtual address can be understood as an intermediate virtual address in a non-local format, and the second virtual address can be understood as a second virtual address in a local format. That is to say, when obtaining the second virtual address, it is necessary to perform an address translation from the first virtual address to the intermediate virtual address and an address mapping from the intermediate virtual address to the second virtual address. The address mapping from the intermediate virtual address to the second virtual address can be understood as completing a pixel-level address mapping in the newly added second virtual address space, so that the GPU can access the image data corresponding to the physical address according to the second virtual address, and obtain the image data in the second format of the local format.
[0007] The embodiment of the present application adds a second virtual address space between the existing first virtual address space and the first physical address space, and completes pixel-level address mapping in the newly added second virtual address space, mapping the address of the image in a non-native format to the address of the image in a local format accessible to the GPU. Furthermore, the embodiment of the present application splits the one-time address translation of the first virtual address to the first physical address in the prior art into two address translations and one pixel-level address mapping: translation of the first virtual address to the intermediate virtual address, pixel-level address mapping of the intermediate virtual address to the second virtual address, and translation of the second virtual address to the first physical address, so that the GPU can read or render images in non-native formats without explicit format conversion, avoid applying for additional local GPU cache, avoid multiple migrations between the format conversion processor and the cache, reduce memory consumption, avoid delays, and save bandwidth and power consumption.
[0008] In one possible design, translating the first virtual address into an intermediate virtual address specifically includes: obtaining the intermediate virtual address corresponding to the first virtual address in the second virtual address space according to a first mapping relationship, where the first mapping relationship is a mapping relationship between the first virtual address space and the second virtual address space. The first mapping relationship can be stored in a memory management unit MMU of the GPU. In an embodiment of the present application, the MMU can be integrated inside the GPU or located outside the GPU, which is not limited in the present application.
[0009] In one possible design, after obtaining the second virtual address according to the first virtual address, the method further includes: obtaining the first physical address corresponding to the second virtual address in the first physical address space according to a second mapping relationship, where the second mapping relationship is a mapping relationship between the second virtual address space and the first physical address space.
[0010] It can be understood that the present application translates the first virtual address into an intermediate virtual address after the first address translation, and then goes through an address mapping, that is, mapping the intermediate virtual address into a second virtual address, and then goes through an address translation, translating the second virtual address into a first physical address. The intermediate virtual address in the non-local format before format mapping and the second virtual address in the local format after format mapping both belong to this continuous second virtual address space, but the arrangement method has changed. When the GPU accesses the real physical address in the non-local format according to the order of the second virtual address in the local format, the second virtual address space accesses the graphics data in the local format, that is, the GPU reads or writes the image data in the order of the converted graphics data in the local format. Therefore, the virtualization method of the present application can make the GPU sampling process do not need an additional format conversion buffer, and also omits the actual format conversion process, so that the GPU can sample non-local format graphics data in a low-cost manner. Similarly, when the non-native format physical address of the actual rendering data is obtained according to the second virtual address space, the order of rendering the graphics data according to the non-native format physical address is rendered in the order of the local format graphics data for the GPU. Therefore, the virtualization method of the present application can make the GPU rendering process do not require an additional format conversion buffer, and also omits the actual format conversion process, thereby enabling the GPU to render local format graphics data to non-native format memory in a low-cost manner.
[0011] In one possible design, before obtaining the second virtual address based on the first virtual address, the method also includes: obtaining a graphics processing request sent to the GPU, the graphics processing request including a first virtual address space and a first physical address space; and constructing a second virtual address space based on the first virtual address space and the first physical address space.
[0012] That is to say, when the application sends a graphics processing request to the GPU, the embodiment of the present application can intercept the graphics processing request through the virtualization software agent, thereby constructing a second virtual address space according to the request. It should be understood that the embodiment of the present application first maps the discrete first physical address space and the first virtual address space to a continuous second virtual address space, and then converts the non-native format graphics data into the local format graphics data in this virtual continuous space. The format conversion of the embodiment of the present application is achieved by changing the address arrangement in the virtual space.
[0013] In one possible design, the method further includes: obtaining a first mapping relationship and a second mapping relationship according to the first virtual address space and the first physical address space.
[0014] In one possible design, a second virtual address space is constructed based on the first virtual address space and the first physical address space, specifically including: obtaining the size of a physical memory page PP corresponding to the first physical address space and the size of a virtual memory page VP corresponding to the first virtual address space; mapping the first physical address space to a continuous virtual memory space to obtain a second virtual address space, and the size of a virtual physical memory page VPP corresponding to the second virtual address space is larger than the size of PP and the size of VP.
[0015] The purpose of doing this is to cover the first virtual address space and the first physical address space of the real physical address with the second virtual address space constructed by the present application, so as to establish a first mapping relationship between the first virtual address space and the second virtual address space, and a second mapping relationship between the second virtual address space and the first physical address space.
[0016] In a possible design, obtaining the second virtual address according to the first virtual address includes:
[0017] Translate the first virtual address into an intermediate virtual address; determine whether the intermediate virtual address belongs to the second virtual address space; when the intermediate virtual address belongs to the second virtual address space, map the intermediate virtual address to the second virtual address in the second virtual address space. Because the GPU's MMU maintains multiple mapping relationships, the virtual address translated by the MMU may be the actual physical address of other cache areas, rather than the virtual address in the second virtual address space, so judgment and filtering are required here. In other words, the intermediate virtual address obtained by the MMU is not necessarily the virtual address in the first mapping relationship.
[0018] In a possible design, mapping the intermediate virtual address to the second virtual address in the second virtual address space specifically includes: obtaining the pixel coordinates corresponding to the intermediate virtual address; and obtaining the second virtual address according to the pixel coordinates. This is an implementation process of the above-mentioned pixel-level address mapping. The second virtual address in a local format can be obtained through the pixel coordinates, so that the image data of the real physical address can be accessed through the second virtual address in a local format to obtain the image data in a local format.
[0019] In a possible design, the image data in the first format is compressed data that the GPU needs to read, and the compressed data includes multiple compressed graphic blocks. The intermediate virtual address is mapped to the second virtual address in the second virtual address space, including: obtaining the pixel coordinates corresponding to the intermediate virtual address; obtaining the compression offset information of the target compressed graphic block corresponding to the intermediate virtual address according to the pixel coordinates; calculating the second virtual address according to the compression offset information; the method also includes: decompressing the read target compressed graphic block. This is to take into account that when performing pixel-level address conversion, the image data in a non-native format stored in the memory may be image data in a compressed format. Accordingly, when sampling to obtain the image data, the image data also needs to be decompressed.
[0020] In a possible design, the image data in the first format is compressed data to be written by the GPU, and the intermediate virtual address is mapped to the second virtual address in the second virtual address space, including obtaining the pixel coordinates corresponding to the intermediate virtual address; obtaining the address of the header data of the compressed data to be written according to the pixel coordinates; and obtaining the second virtual address according to the address of the header data. That is, when writing data, considering that the compressed data is stored in the memory, when storing the image data in the local format into the memory in the non-local format, the second virtual address of the compressed format data is obtained, so that the data village is placed in the memory of the physical address according to the second virtual address.
[0021] In one possible design, the intermediate virtual address is mapped to the second virtual address in the second virtual address space, including: obtaining the pixel coordinates corresponding to the intermediate virtual address; obtaining the signature of the pixel corresponding to the pixel coordinates; obtaining the second virtual address corresponding to the signature according to the signature; if the image data in the first format is encrypted data that the GPU needs to read, the method also includes: decrypting the read image data and sending the decrypted image data to the GPU. This situation takes into account that the image data stored in the memory is in an encrypted format, so when performing pixel-level address mapping, the second virtual address in the encrypted format must be obtained.
[0022] In a second aspect, a graphics processing device is provided, wherein the device comprises a graphics processor GPU and a hardware virtualization manager, wherein:
[0023] A GPU is used to obtain a first virtual address to be accessed, the first virtual address belongs to a first virtual address space; a hardware virtualization manager is used to obtain a second virtual address according to the first virtual address, the second virtual address belongs to a second virtual address space; wherein the second virtual address space is different from the first virtual address space, the second virtual address space and the first virtual address space are mapped to the same first physical address space, the physical address mapped by the first virtual address corresponds to image data in a first format, and the physical address mapped by the second virtual address corresponds to image data in a second format.
[0024] In one possible design, the GPU includes a first memory management unit MMU, and the hardware virtualization manager includes a format conversion processor; the first MMU is used to translate the first virtual address into an intermediate virtual address, which is a virtual address in a second virtual address space; the format conversion processor is used to map the intermediate virtual address to a second virtual address in the second virtual address space.
[0025] In a possible design, the first MMU is used to obtain an intermediate virtual address corresponding to the first virtual address in the second virtual address space according to a first mapping relationship, where the first mapping relationship is a mapping relationship between the first virtual address space and the second virtual address space.
[0026] In one possible design, the first MMU is used for: the hardware virtualization manager includes a second MMU, and the second MMU is used for: obtaining the first physical address corresponding to the second virtual address in the first physical address space according to a second mapping relationship, and the second mapping relationship is a mapping relationship between the second virtual address space and the first physical address space.
[0027] In one possible design, the device also includes a central processing unit (CPU), on which a virtualization software agent runs, and the virtualization software agent is used to: obtain a graphics processing request sent to the GPU, the graphics processing request including a first virtual address space and a first physical address space; and construct a second virtual address space based on the first virtual address space and the first physical address space.
[0028] In a possible design, the virtualization software agent is further used to obtain a first mapping relationship and a second mapping relationship according to the first virtual address space and the first physical address space.
[0029] In one possible design, the virtualization software agent is specifically used to: obtain the size of the physical memory page PP corresponding to the first physical address space and the size of the virtual memory page VP corresponding to the first virtual address space; map the first physical address space to a continuous virtual memory space to obtain a second virtual address space, and the size of the virtual physical memory page VPP corresponding to the second virtual address space is larger than the size of PP and the size of VP.
[0030] In one possible design, the GPU includes a first MMU, and the hardware virtualization manager includes a snoop filter and a format conversion processor; the first MMU is used to translate the first virtual address into an intermediate virtual address; the snoop filter is used to determine whether the intermediate virtual address belongs to the second virtual address space; when the intermediate virtual address belongs to the second virtual address space, the intermediate virtual address is sent to the format conversion processor; the format conversion processor is used to map the intermediate virtual address to the second virtual address in the second virtual address space.
[0031] In a possible design, the format conversion processor is specifically used to: obtain pixel coordinates corresponding to the intermediate virtual address; and obtain the second virtual address according to the pixel coordinates.
[0032] In one possible design, the image data in the first format is compressed data that the GPU needs to read, and the compressed data includes multiple compressed graphic blocks; the format conversion processor is specifically used to: obtain the pixel coordinates corresponding to the intermediate virtual address; obtain the compression offset information of the target compressed graphic block corresponding to the intermediate virtual address according to the pixel coordinates; calculate the second virtual address according to the compression offset information; the format conversion processor is also used to: decompress the read target compressed graphic block.
[0033] In one possible design, the image data in the first format is compressed data to be written by the GPU; the format conversion processor is specifically used to: obtain the pixel coordinates corresponding to the intermediate virtual address; obtain the address of the header data of the compressed data to be written according to the pixel coordinates; and obtain the second virtual address according to the address of the header data.
[0034] In one possible design, the format conversion processor is specifically used to: obtain the pixel coordinates corresponding to the intermediate virtual address; obtain the signature of the pixel corresponding to the pixel coordinates; obtain the second virtual address corresponding to the signature based on the signature; if the image data in the first format is encrypted data that the GPU needs to read, the format conversion processor is also used to: decrypt the read image data and send the decrypted image data to the GPU.
[0035] The first virtual address mentioned in the first and second aspects above may be equivalent to the target virtual address in the virtual address space mentioned in the third and fourth aspects to be introduced below; the first virtual address space mentioned in the first and second aspects above is equivalent to the virtual address space mentioned in the third and fourth aspects; the second virtual address space mentioned in the first and second aspects above is equivalent to the virtual physical address space mentioned in the third and fourth aspects; the first physical address space mentioned in the first and second aspects above is equivalent to the physical address space mentioned in the third and fourth aspects; the intermediate virtual address mentioned in the first and second aspects above is equivalent to the intermediate physical address mentioned in the third and fourth aspects; the second virtual address mentioned in the first and second aspects above is equivalent to the target virtual physical address mentioned in the third and fourth aspects; the first physical address mentioned in the first and second aspects above is equivalent to the target physical address mentioned in the third and fourth aspects; when the intermediate physical address in the third and fourth aspects belongs to the second virtual address space, the intermediate physical address mentioned in the third and fourth aspects is the first virtual physical address, then the first virtual physical address is equivalent to the intermediate virtual address mentioned in the first and second aspects.
[0036] In a third aspect, a graphics processing method is provided, including: a virtualization software agent constructs a virtual physical address space, the virtual physical address space is a memory space outside the virtual address space and the physical address space; a hardware virtualization manager maps the address of the non-native format image data to be accessed in the virtual physical address space to obtain a target virtual physical address of the local format image data; obtains a target physical address corresponding to the target virtual physical address, and accesses the image data in the target physical address. The physical address mapped by the virtual address in the virtual address space corresponds to the image data in the first format, and the physical address mapped by the target virtual physical address in the virtual physical address space corresponds to the image data in the second format.
[0037] The embodiment of the present application adds a virtual-physical address space between the existing virtual address space and the physical address space, and completes pixel-level address mapping in this newly added virtual-physical address space, mapping the address of an image in a non-native format to the address of an image in a local format accessible to the GPU. Furthermore, the embodiment of the present application splits the single address mapping of virtual address to physical address in the prior art into two address mappings: virtual address to virtual-physical address, and virtual-physical address to physical address mapping, so that the GPU can read or render images in non-native formats without explicit format conversion, avoiding the application for additional local GPU cache, avoiding multiple migrations between the format conversion processor and the cache, reducing memory consumption, avoiding delays, and saving bandwidth and power consumption.
[0038] It should be understood that the embodiment of the present application maps the discrete physical address to a continuous virtual physical memory page VPP address space (virtual physical address space), and then changes the address arrangement in this virtual continuous space. The physical address mapped by the changed virtual address corresponds to the image data in the second format. Specifically, the image data in the physical address space is accessed in the order of the changed virtual address to obtain the image data in the second format. The format conversion of the embodiment of the present application is achieved by changing the address arrangement in the virtual space. The VPP address of the non-local format before the format mapping and the VPP address of the local format after the format mapping both belong to this continuous VPP address space, but the arrangement has changed. When the GPU accesses the real physical address of the non-local format according to the sequence of the mapped virtual physical address, the graphics data in the local format is accessed, that is, the GPU reads or writes the image data in the order of the converted local format graphics data. Therefore, the virtualization method of the present application can make the GPU sampling process do not need an additional format conversion buffer, and also omits the actual format conversion process, so that the GPU can sample the graphics data in the non-local format in a low-cost manner. Similarly, when the physical address of the non-native format of the actual rendering data is obtained according to the virtual physical address, the order of rendering the graphics data according to the physical address of the non-native format is rendered in the order of the graphics data in the local format for the GPU. Therefore, the virtualization method of the present application can make the GPU rendering process do not require an additional format conversion buffer, and also omits the actual format conversion process, thereby enabling the GPU to render local format graphics data to non-native format memory in a low-cost manner.
[0039] In a possible design, before the hardware virtualization manager maps the address of the non-native format image data to be accessed in the virtual physical address space, the method also includes: obtaining the target virtual address to be accessed by the graphics processor GPU; the memory management unit MMU of the GPU obtains a first virtual physical address in the virtual physical address space corresponding to the target virtual address according to a first mapping relationship, and the first mapping relationship is a mapping relationship between the virtual address space and the virtual physical address space; the hardware virtualization manager maps the address of the non-native format image data to be accessed in the virtual physical address space to obtain the target virtual physical address of the local format image data, specifically including: the hardware virtualization manager maps the first virtual physical address in the virtual physical address space to obtain the target virtual physical address.
[0040] In one possible design, obtaining the target physical address corresponding to the target virtual physical address specifically includes: the second MMU in the hardware virtualization manager obtains the target physical address corresponding to the target virtual physical address according to a second mapping relationship, and the second mapping relationship is a mapping relationship between the virtual physical address space and the physical address space.
[0041] In one possible design, before the virtualization software agent constructs the virtual physical address space, the method also includes: obtaining a graphics processing request sent to the GPU, the graphics processing request including the virtual address space and the physical address space of the non-native format image; the virtualization software agent constructs the virtual physical address space, specifically including: the virtualization software agent constructs the virtual physical address space according to the virtual address space and the physical address space.
[0042] In a possible design, when the virtualization software agent constructs a virtual physical address space according to the virtual address space and the physical address space, a first mapping relationship and a second mapping relationship are also obtained.
[0043] In one possible design, the virtualization software agent builds a virtual physical address space, including:
[0044] The size of the physical memory page PP and the size of the virtual memory page VP corresponding to the physical address space are obtained; the virtual physical address space is constructed according to the size of PP and the size of VP, and the size of the virtual physical memory page VPP corresponding to the virtual physical address space is larger than the size of PP and the size of VP.
[0045] In one possible design, the hardware virtualization manager includes a filter and a format conversion processor. Before the hardware virtualization manager maps the address of the non-native format image data to be accessed in the virtual physical address space, the method also includes: obtaining the target virtual address to be accessed by the graphics processor GPU; the memory management unit MMU of the GPU maps the target virtual address to an intermediate physical address; the filter determines whether the intermediate physical address belongs to the virtual physical address space; when the intermediate physical address belongs to the virtual physical address space, the filter determines the intermediate physical address as the first virtual physical address and sends it to the format conversion processor; the format conversion processor performs pixel-level format mapping on the first virtual physical address in the virtual physical address space to obtain the target virtual physical address.
[0046] In one possible design, the hardware virtualization manager maps the first virtual physical address in the virtual physical address space to obtain a target virtual physical address, including: obtaining pixel coordinates corresponding to the first virtual physical address; and obtaining a target virtual physical address corresponding to the pixel coordinates based on the pixel coordinates.
[0047] In one possible design, the non-native format image data to be accessed is compressed data that the GPU needs to read, and the compressed data includes multiple compressed graphic blocks. The hardware virtualization manager maps the first virtual physical address in the virtual physical address space to obtain a target virtual physical address, including: obtaining pixel coordinates corresponding to the first virtual physical address; obtaining compression offset information of the target compressed graphic block corresponding to the first virtual physical address according to the pixel coordinates; and calculating the target virtual physical address according to the compression offset information. The method also includes: decompressing the read target compressed graphic block.
[0048] In one possible design, the non-native format image data to be accessed is compressed data to be written by the GPU, including: obtaining pixel coordinates corresponding to a first virtual physical address; the hardware virtualization manager maps the first virtual physical address in the virtual physical address space to obtain a target virtual physical address; and obtaining the address of header data of the compressed data to be written according to the pixel coordinates; and obtaining the target virtual physical address according to the address of the header data.
[0049] In one possible design, the hardware virtualization manager maps the first virtual physical address in the virtual physical address space to obtain a target virtual physical address, including: obtaining pixel coordinates corresponding to the first virtual physical address; obtaining a signature of a pixel corresponding to the pixel coordinates; obtaining a target virtual physical address corresponding to the signature based on the signature; if the non-native format image data to be accessed is encrypted data that the GPU needs to read, the method also includes: decrypting the read image data and sending the decrypted image data to the GPU.
[0050] In a fourth aspect, a graphics processing device is provided, which includes a graphics processor GPU, a central processing unit CPU and a hardware virtualization manager, wherein a virtualization software agent runs on the CPU, wherein: the virtualization software agent is used to construct a virtual physical address space, and the virtual physical address space is a memory space outside the virtual address space and the physical address space; the hardware virtualization manager is used to map the address of non-native format image data to be accessed in the virtual physical address space to obtain a target virtual physical address of the local format image data; the hardware virtualization manager is also used to obtain a target physical address corresponding to the target virtual physical address, and access the image data in the target physical address.
[0051] In a possible design, the virtualization software agent is also used to: obtain a target virtual address to be accessed by a graphics processor GPU; the GPU also includes a memory management unit MMU, and the MMU is used to obtain a first virtual physical address in a virtual physical address space corresponding to the target virtual address according to a first mapping relationship, and the first mapping relationship is a mapping relationship between the virtual address space and the virtual physical address space; the hardware virtualization manager is used to map the first virtual physical address in the virtual physical address space to obtain the target virtual physical address.
[0052] In one possible design, the hardware virtualization manager includes a second MMU, and the second MMU is used to obtain a target physical address corresponding to the target virtual physical address according to a second mapping relationship, where the second mapping relationship is a mapping relationship between a virtual physical address space and a physical address space.
[0053] In one possible design, the virtualization software agent is further used to: obtain a graphics processing request sent to the GPU, the graphics processing request including a virtual address space and a physical address space of a non-native format image; and the virtualization software agent is used to: construct a virtual physical address space based on the virtual address space and the physical address space.
[0054] In a possible design, the virtualization software agent is further used to obtain the first mapping relationship and the second mapping relationship when constructing the virtual physical address space according to the virtual address space and the physical address space.
[0055] In a possible design, a virtualization software agent is used to obtain the size of a physical memory page PP and a size of a virtual memory VP corresponding to a physical address space; a virtual physical address space is constructed according to the size of PP and the size of VP, and the size of a virtual physical memory page VPP corresponding to the virtual physical address space is larger than the size of PP and the size of VP.
[0056] In one possible design, the hardware virtualization manager includes a snoop filter and a format conversion processor;
[0057] A snoop filter is used to obtain a target virtual address to be accessed by a graphics processor GPU; the MMU of the GPU is used to map the target virtual address to an intermediate physical address; the snoop filter is used to determine whether the intermediate physical address belongs to the virtual physical address space; when the intermediate physical address belongs to the virtual physical address space, the intermediate physical address is determined as a first virtual physical address and sent to a format conversion processor; the format conversion processor is used to perform pixel-level format mapping on the first virtual physical address in the virtual physical address space to obtain a target virtual physical address.
[0058] In a possible design, the hardware virtualization manager is used to obtain pixel coordinates corresponding to the first virtual physical address; and obtain a target virtual physical address corresponding to the pixel coordinates according to the pixel coordinates.
[0059] In one possible design, the non-native format image data to be accessed is compressed data that the GPU needs to read, and the compressed data includes multiple compressed graphic blocks. The hardware virtualization manager is used to obtain pixel coordinates corresponding to a first virtual physical address; obtain compression offset information of a target compressed graphic block corresponding to the first virtual physical address according to the pixel coordinates; calculate the target virtual physical address according to the compression offset information; the hardware virtualization manager is also used to decompress the read target compressed graphic block.
[0060] In one possible design, the non-native format image data to be accessed is compressed data to be written by the GPU, and the hardware virtualization manager is used to obtain the pixel coordinates corresponding to the first virtual physical address; the hardware virtualization manager maps the first virtual physical address in the virtual physical address space to obtain the target virtual physical address; obtains the address of the header data of the compressed data to be written according to the pixel coordinates; and obtains the target virtual physical address according to the address of the header data.
[0061] In one possible design, the hardware virtualization manager is used to obtain the pixel coordinates corresponding to the first virtual physical address; obtain the signature of the pixel corresponding to the pixel coordinates; obtain the target virtual physical address corresponding to the signature based on the signature; the hardware virtualization manager is also used to decrypt the read image data and send the decrypted image data to the GPU.
[0062] In a fifth aspect, a graphics processing method is provided, comprising: obtaining a first virtual address to be accessed, the first virtual address belonging to a first virtual address space; translating the first virtual address into an intermediate virtual address, the intermediate virtual address belonging to a second virtual address space, and the intermediate virtual address can be mapped to a second virtual address in the second virtual address space; wherein the second virtual address space is different from the first virtual address space, the second virtual address space and the first virtual address space are mapped to the same first physical address space, the physical address mapped by the first virtual address corresponds to image data in a first format, and the physical address mapped by the second virtual address corresponds to image data in a second format.
[0063] Therefore, the embodiments of the present application can achieve pixel-level address mapping in this newly added second virtual address space, mapping the address of an image in a non-native format such as a first format to the address of an image in a local format such as a second format accessible to the GPU, so that the GPU can read or render images in non-native formats without the need for explicit format conversion, avoiding the application of additional local GPU cache, avoiding multiple migrations between the format conversion processor and the cache, reducing memory consumption, avoiding delays, and saving bandwidth and power consumption.
[0064] In one possible design, translating the first virtual address into an intermediate virtual address specifically includes: obtaining the intermediate virtual address corresponding to the first virtual address in the second virtual address space according to a first mapping relationship, where the first mapping relationship is a mapping relationship between the first virtual address space and the second virtual address space.
[0065] In one possible design, before generating the first virtual address to be accessed, the method further includes: receiving the first virtual address space and the second virtual address space; and establishing a first mapping relationship.
[0066] In a sixth aspect, a GPU is provided, the GPU comprising a transmission interface and a memory management unit MMU, wherein: the transmission interface is used to obtain a first virtual address to be accessed, the first virtual address belongs to a first virtual address space; the MMU is used to translate the first virtual address into an intermediate virtual address, the intermediate virtual address belongs to a second virtual address space, and the intermediate virtual address can be mapped to a second virtual address in the second virtual address space; wherein the second virtual address space is different from the first virtual address space, the second virtual address space and the first virtual address space are mapped to the same first physical address space, the physical address mapped by the first virtual address corresponds to image data in a first format, and the physical address mapped by the second virtual address corresponds to image data in a second format.
[0067] In a possible design, the MMU is used to obtain an intermediate virtual address corresponding to the first virtual address in the second virtual address space according to a first mapping relationship, where the first mapping relationship is a mapping relationship between the first virtual address space and the second virtual address space.
[0068] In a possible design, the MMU is used to: receive a first virtual address space and a second virtual address space; and establish a first mapping relationship.
[0069] Therefore, the order of sampling the graphic data according to the PP address of the non-local format is actually sampled according to the address order of the local format for the GPU. Then, for the sampling process, the sampling order when the GPU finally samples the graphic data can be different from the sampling order when the GPU actually samples the graphic data according to the real physical address. When the sampling order changes, the sampled graphic data is the graphic data of the local format that the GPU can recognize and process. Therefore, the order of the graphic data finally read from the memory according to the physical address of the non-local format is the graphic format that the GPU can recognize. Similarly, for the rendering process, when the GPU renders the graphic data in the local format, it can first correspond the graphic data in the local format according to the virtual local format physical address VPP of the present application, and then correspond VPP to the physical address of the non-local format. In this way, when the GPU wants to write the graphic data in the local format into the memory of the non-local format, the graphic data finally written into the memory is still written according to the physical address of the non-local format. The graphic data written into the memory is the graphic data of the non-local format that the GPU cannot recognize. BRIEF DESCRIPTION OF THE DRAWINGS
[0070] Figure 1 A schematic diagram of a scene for sampling and rendering to a non-native format using a prior art technique;
[0071] Figure 2 This is a schematic diagram of the functional modules inside a GPU;
[0072] Figure 2A A schematic diagram of an address mapping relationship when sampling or rendering data in a prior art;
[0073] Figure 2B A schematic diagram comparing an address space structure provided in an embodiment of the present application with an address space structure of the prior art;
[0074] Figure 2C A schematic diagram of an address mapping relationship provided in an embodiment of the present application;
[0075] Figure 2D A schematic diagram of an address mapping relationship provided for an embodiment of the present application;
[0076] Figure 2E A schematic diagram of an address mapping relationship provided in an embodiment of the present application;
[0077] Figure 2F A schematic diagram of an address mapping relationship when sampling or rendering non-native format data provided in an embodiment of the present application;
[0078] Figure 2G A schematic diagram of a process for sampling or rendering non-native format data provided by the present embodiment;
[0079] Figure 3 A schematic diagram of the structure of a terminal device provided in an embodiment of the present application;
[0080] Figure 4 A schematic diagram of the structure of a SoC provided in an embodiment of the present application;
[0081] Figure 5 A flowchart of a graphics processing method provided in an embodiment of the present application;
[0082] Figure 6 A diagram of the hardware and software architecture for sampling non-native format graphic data provided in an embodiment of the present application;
[0083] Figure 7 A flowchart of a graphics processing method provided in an embodiment of the present application;
[0084] Figure 8 A schematic diagram of the structure of a terminal device provided in an embodiment of the present application;
[0085] Fig. 9 A schematic diagram of the structure of a terminal device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0086] For ease of understanding, some examples of concepts related to this application are provided for reference, as shown below:
[0087] GPU: Also known as display core, visual processor or display chip, it is a microprocessor specially used for image computing on personal computers, workstations, game consoles and some mobile devices (such as tablets, smart phones, etc.). For example, the uses of GPU include: converting and driving the display information required by the computer system, providing line scanning signals to the display, controlling the correct display of the display, etc. GPU is an important component connecting the display and the mainboard of the personal computer, and is also one of the important devices for "human-computer dialogue".
[0088] Virtual address: The logical address used by a program to access memory.
[0089] Physical address: The address placed on the addressing bus. If the central processing unit (CPU) performs a read operation, the circuit can read the data in the physical memory of the corresponding address and transmit it to the data bus according to the value of each bit of the physical address. If the CPU performs a write operation, the circuit can write the content on the data bus to the physical memory of the corresponding address according to the value of each bit of the physical address.
[0090] Memory Management Unit (MMU): It is the control circuit used to manage virtual memory and physical memory in the CPU. It is also responsible for mapping virtual addresses to physical addresses and providing hardware mechanism for memory access authorization, multi-user multi-process operating system.
[0091] In a typical scenario, Figure 1 As shown, this scene is used to post-process and render the video stream captured by the surveillance camera 100, and the rendering result is output after secondary encoding by the encoding processor 105. Specifically, the original video stream of the surveillance camera 100 is encoded in the encoder 101, and the encoding result is written into the non-native format cache 106 in a non-GPU local format, wherein the encoder 101 integrated on the system-level chip (System on Chip, SoC) is usually a specific private format bound to the supplier, containing various information on transformation, compression and intellectual property protection. The GPU 103 cannot directly sample this private format, but can convert the private format into the GPU local format through the format conversion processor 102, and store the converted GPU local format graphics data in the local GPU cache 107. In this way, the GPU 103 can sample the graphics data from the local GPU cache 107 for GPU rendering, and the rendering result is written into the local GPU cache 108 in the GPU local format. However, the encoding processor 105 cannot directly accept the graphics data in the GPU local format in the local GPU cache 108, so another format conversion processor 104 is required to read the graphics data in the local GPU cache 108 through the bus, and then convert the format of the graphics data into a format acceptable to the encoding processor 105, and write the graphics data in the acceptable format into the non-local format cache 109 through the bus. In this way, each migration of data in this scenario includes the migration of the data between the cache and the processor, and it is necessary to apply for additional cache space, which not only consumes memory, but also generates delays and wastes bandwidth and power consumption, and is costly.
[0092] For the above-mentioned scenario where the GPU samples or renders graphics data in a non-native format, the present application can be used in the process of GPU sampling or rendering graphics, and can sample or render graphics in a non-native format for the GPU at a low cost.
[0093] Here we first introduce the functional units inside the GPU in this application. Figure 2 Shown is a schematic diagram of the functional unit structure inside the GPU.
[0094] Currently, GPU architecture has gradually evolved from fixed-function pipelines to programmable shader processor architectures. Figure 2, shader processors can be divided into at least three categories: vertex shader, pixel shader and geometry shader. Among them, the vertex processor program contains instructions for operating a vertex instance. The pixel processor program contains instructions for processing a pixel, usually including sampling the material of the pixel from the texture sample buffer, calculating the reflection of the light source on the pixel, to obtain the final shading result. The geometry processor program is used to instruct the GPU to do geometry processing. Although different types of shaders run different types of programs, in terms of hardware structure, it is usually a normalized architecture running a normalized instruction set. The instruction set includes arithmetic, memory load / store and shift similar to general scalar processors. Each instruction of the front end of these shader processors runs on multiple data instances, that is, the usual single instruction multiple data structure. These shader processors also need to communicate with the fixed function pipeline to complete the graphics function. The graphics function includes a rasterizer and a texture mapper. The rasterizer is used to calculate and generate the pixels corresponding to each shaded fragment. The texture mapper is used to calculate the address of the final material point (texel) to be taken after the perspective transformation. The shader processor and the fixed pipeline will be mapped to the virtual address. In memory management, the page is the smallest unit of the address space. All virtual addresses that an application can use are called virtual address space. The virtual address space is usually divided into smaller granularities, virtual memory pages (Virtual page, VP). A virtual address space consists of a series of virtual addresses. The virtual address space will be mapped to the real double data rate (Double Data Rate, DDR) space, that is, the physical address space. The physical address space is also divided into a series of physical memory pages (Physical Page, PP). The size of VP and PP can usually be the same, for example, 4KB. For the process, virtual addresses are used. Each process maintains a separate page table. The page table is an array structure that stores the status of each VP, including whether it is mapped or cached. When a process is executed and needs to access the value stored in the virtual address: the CPU will first find the VP where the virtual address is located, and then find the value corresponding to the page number of the VP in the page table according to the page table, and then obtain the physical address in the PP corresponding to the virtual address according to the physical page number corresponding to the value. This process can be called address translation from virtual address to physical address. In simple terms, address translation refers to the process of finding the physical address from the virtual address when the cache hits.
[0095] Usually, the memory management unit (MMU) of graphics is used to manage the mapping relationship between virtual address space and physical address space. The translation of virtual address to physical address is completed by MMU, or the physical address corresponding to the virtual address is obtained based on the mapping relationship between virtual address space and physical address space stored in MMU. For example, a material buffer (the area storing graphics data) is mapped to a continuous virtual address space in the texture mapper, and is mapped to a bunch of scattered physical pages in the DDR space.
[0096] Taking the rendering process as an example, when a pixel processor renders a pixel, it sends a material sampling instruction to the texture mapper. The texture mapper sends the calculated virtual address of the texel to the bus interface unit (BIU), and finds the physical address corresponding to the virtual address through the MMU connected to the BIU. For the tile based architecture used by the current system, rendering is performed at the granularity of sheet materials (tiles), and the intermediate rendering results can be stored in the render target buffer according to the physical address. In some instances, the system will have an L2 cache. For the sampling process, in some instances, the system will have an L2 cache (level 2cache). If the currently sampled texel is not found in the L2 cache, the texel read operation will read the content in the material buffer (texture buffer) through a bus operation.
[0097] As mentioned in the above process, the MMU manages the mapping relationship between the virtual address space requested by the application and the physical address space. In other words, the MMU stores a mapping table that translates the virtual address into the physical address. The contents of this table are managed by the operating system. Figure 2A The figure shows a schematic diagram of the prior art using a virtual address to translate an address in the MMU to obtain a physical address, and then using the physical address to access data in the main memory. Figure 2B ,and Figure 2B The difference between the prior art shown in (1) is that the present application adds a second virtual address space between the first virtual address space (equivalent to the virtual address space in the prior art) and the first physical address space (equivalent to the physical address space in the prior art), see Figure 2BIn (2), the second virtual address space can be divided into a series of virtual physical memory pages (Virtual Physical Page, VPP), the second virtual address space is a space different from the first virtual address space and the first physical address space, the second virtual address space and the first virtual address space are mapped to the same physical address space, the physical address mapped by the first virtual address corresponds to the image data in the first format, and the physical address mapped by the second virtual address corresponds to the image data in the second format. The method of the embodiment of the present application relates to a virtualization software agent and a hardware virtualization manager. The second virtual address space is constructed by the virtualization software agent. If the image data in the first format is image data in a non-native format that cannot be directly accessed by the GPU, and the image data in the second format is image data in a local format that can be accessed by the GPU, the hardware virtualization manager can subsequently complete the pixel-level address mapping between the local format and the non-native format for the data to be accessed in the constructed second virtual address space. Correspondingly, the embodiment of the present application splits the mapping relationship between the first virtual address in the first virtual address space and the first physical address in the first physical address space into a first mapping relationship and a second mapping relationship, wherein the first mapping relationship is a mapping relationship between the first virtual address and the second virtual address in the second virtual address space, and the second mapping relationship is a mapping relationship between the second virtual address and the first physical address, the first mapping relationship is stored in the first MMU of the GPU, and the second mapping relationship is stored in the second MMU of the hardware virtualization manager. When executing a process, when it is necessary to access the value stored in the first virtual address, the first virtual address is first translated into the second virtual address in the second virtual address space according to the first mapping relationship in the MMU, and then the second virtual address is translated into the first physical address according to the second mapping relationship in the second MMU, that is, the embodiment of the present application implements access to the actual physical address through two address translations. Since a second virtual address space is added in the embodiment of the present application, and pixel-level address mapping of the image format is completed in this second virtual address space, the GPU can access images in non-native formats without performing explicit format conversion, that is, there is no need for the format conversion processor 102 to convert the private format into the local format, and the format processor 104 to convert the local format into a format acceptable to the encoder, and there is no need to apply for additional local GPU cache 107 and local GPU cache 108, which avoids multiple migrations of data between the processor and the cache, reduces memory consumption, avoids delays, and saves bandwidth and power consumption.
[0098] Exemplary, reference Figure 2C, taking the sampling process as an example, if the GPU sends multiple access requests in sequence, each access request accesses a first virtual address, before the GPU sends the access request, it needs to first perform address mapping according to the first mapping relationship. At this time, the above translation of the first virtual address into the second virtual address in the second virtual address space according to the first mapping relationship in the MMU of the GPU can be understood as follows: If the order of the first virtual addresses accessed by the GPU is VP1-VP2-VP3-…, the physical address PP1-PP2-PP3-… mapped to the order of the first virtual addresses VP1-VP2-VP3-… corresponds to the image data in the first format. According to the first mapping relationship, the intermediate virtual address VPP1-VPP2-VPP3-… corresponding to the first virtual address can be obtained, then the multiple access requests sent by the GPU actually carry an intermediate virtual address respectively, and the order in which the intermediate virtual addresses are sent is VPP1-VPP2-VPP3-…. Then, pixel-level address mapping of the image format is completed in this virtual second virtual address space, and the intermediate virtual address of the non-native format is mapped to the second virtual address of the local format. For example, VPP1 is mapped to VPP4, VPP2 is mapped to VPP2, and VPP3 is mapped to VPP1, so that the GPU obtains the first physical address corresponding to the second virtual address according to the second virtual address of the local format and the second mapping relationship, which is used when actually accessing the non-native format data. In this way, the GPU can access the non-native format graphic data according to the second virtual address of the local format. Figure 2C , the order of the second virtual address after pixel-level address mapping is VPP4-VPP2-VPP1-…, the physical address mapped according to the order of the second virtual address VPP4-VPP2-VPP1-… corresponds to the image data in the second format, and the second virtual address is translated into the first physical address according to the second mapping relationship in the second MMU, which can be understood as obtaining the first physical address after the second address translation according to the order of the second virtual address VPP4-VPP2-VPP1-… and the second mapping relationship, and the order of the first physical address is PP4-PP2-PP1-…, and then the graphics data in the memory are accessed according to the order of the first physical address PP4-PP2-PP1-…, and the order of the first physical address PP4-PP2-PP1-… corresponds to the image data in the second format, if the image data in the first format is image data in a non-local format that cannot be directly accessed by the GPU, and the image data in the second format is image data in a local format that can be accessed by the GPU, the GPU can sample the graphics format in the local format from the image data in the non-local format.
[0099] like Figure 2D As shown, it is a schematic diagram of an exemplary image format read before address mapping provided by an embodiment of the present application, such as Figure 2E The figure shows an exemplary image format read after address mapping.
[0100] The second virtual address space is constructed according to the first physical address space and the first virtual address space, that is, a continuous virtual memory space is opened according to the size of the first physical address space and the first virtual address space, and the continuous virtual memory space is used as the second virtual address space, and the memory page of the space is the virtual physical memory page VPP. The first virtual address space ( Figure 2D The memory page of the virtual address space shown in the figure) is the virtual memory page VP, and the first physical address space ( Figure 2D The memory page of the first physical address space (the physical address space shown in the figure) is the physical memory page PP. It should be understood that the size of the constructed virtual physical address VPP is larger than the size of VP and the size of PP. Before address mapping, the order of accessing the pixels stored in the first physical address space is X1Y1 in PP1, X2Y2 in PP2, X3Y3 in PP3, X4Y4 in PP4, and X5Y5 in PP5. At this time, the image data read out is the image data of the first format (format 1). The embodiment of the present application constructs a second virtual address space ( Figure 2D The address is mapped in the virtual physical address space (shown in FIG), changing the order of address access, which is equivalent to changing the arrangement of image pixels, such as Figure 2E As shown, in the second virtual address space ( Figure 2E After address mapping is performed in the virtual physical address space (shown in FIG. 1 ), VPP1 is mapped to VPP2, VPP2 is mapped to VPP4, VPP3 is mapped to VPP1, VPP4 is mapped to VPP5, and VPP5 is mapped to VPP5, accessing the first physical address space ( Figure 2E The order of pixels stored in the physical address space (as shown in the figure) becomes X2Y2 in PP2, X4Y4 in PP4, X1Y1 in PP1, X5Y5 in PP5, and X3Y3 in PP3. The pixel arrangement order of the read image data has changed. At this time, the read image data is image data in the second format (Format 2).
[0101] The embodiment of the present application maps addresses in the newly constructed second virtual address space, changes the order of addresses of read pixels, which is equivalent to changing the arrangement of pixels of the read image data. Optionally, the image in the first format is an image in a non-native format that the GPU cannot access, and the image in the second format is an image in a local format that the GPU can directly access. Therefore, there is no need for explicit format conversion, and the GPU can access image data in a non-native format to obtain image data in a local format.
[0102] Exemplarily, the second virtual address space proposed in the embodiment of the present application can be a continuous address determined according to the size of the first physical address space corresponding to the process and the size of the first virtual address space. For example, the size of the first virtual address space is 396KB, the first physical address space is divided into 100 discrete VPs, and the size of each VP is 4KB. Then the size of the second virtual address space needs to be greater than 400KB, so that the second virtual address space can replace the first physical address space, establish a first mapping relationship between the first virtual address space and the second virtual address space, and a second mapping relationship between the second virtual address space and the first physical address space.
[0103] Thus, based on the second virtual address space proposed in this application, Figure 2FAs shown, if the GPU samples or renders graphics data in a non-native format, the MMU of the GPU stores a mapping relationship between the VP address range (first virtual address space) in a non-native format requested by the application and the VPP address range (second virtual address space) in a non-native format proposed in this application, that is, the MMU of the GPU stores a first mapping relationship query table that translates the first virtual address into the second virtual address. For example, the query table in the MMU of an existing GPU includes a mapping between the first virtual address space 0x8000 and the first physical address space 0x6453. In the present application, when the GPU accesses memory in a non-native format, upon obtaining the mapping relationship between the first virtual address space 0x8000 and the first physical address space 0x6453, the mapping relationship can be split into a first mapping relationship between the first virtual address space 0x8000 and the second virtual address space 0x0, and a second mapping relationship between the second virtual address space 0x0 and the first physical address space 0x6453, and then the query table in the MMU of the GPU is reloaded so that the query table in the MMU of the GPU includes the first mapping relationship between the first virtual address space 0x8000 and the second virtual address space 0x0, and correspondingly, the second mapping relationship between the second virtual address space 0x0 and the first physical address space 0x6453 is stored in the second MMU of the virtualization hardware processor. When obtaining the physical address through the virtual address, the first virtual address 0x8000 can be first translated to obtain the second virtual address 0x0, and then the second virtual address 0x0 can be translated to obtain the first physical address 0x6453 of the real access data. Based on this, the present application adopts a virtualization method to enable the GPU to sample or render non-local format graphics data. This virtualization method does not require an offline explicit conversion stage, and can complete the sampling and rendering of non-local format graphics online. The virtualization software agent can intercept the application program's graphics application program interface (Application Programming Interface, API) call to the GPU. Based on this call, the virtualization software agent can virtualize a sampling buffer or a rendering target buffer that the GPU can directly access. These virtualized buffers can be called buffers corresponding to the VPP in the local format. In the buffer corresponding to the virtualized VPP, the non-local format graphics data is converted into local format graphics data. The format conversion of the embodiment of the present application is achieved by changing the arrangement of addresses in the virtual space. In one example, the virtualization software agent can construct a VPP address space (second virtual address space) based on the VP address space (first virtual address space) and PP address space (first physical address space) applied for when the application makes a graphics API call to the GPU. The PP address mapped by the VP address space corresponds to image data in a first format, i.e., image data in a non-native format.Exemplarily, a first mapping relationship between the VP address space and the VPP address space, and a second mapping relationship between the VPP address space and the PP address space are obtained based on the VP address space and the PP address space, wherein the first mapping relationship is stored in the MMU of the GPU, and the second mapping relationship is stored in the second MMU of the hardware virtualization manager, and the VPP address space is a continuous virtual address space. Then, the hardware virtualization manager obtains the target VPP address to be accessed by the GPU, and completes the pixel-level address mapping of the image data format in the VPP address space. The graphics data accessed by the PP address mapped by the target VPP address in the local format is the image data in the second format, that is, the graphics data in the local format accessible to the GPU. Then, the hardware virtualization manager obtains the target PP address based on the local format target VPP address after format mapping and the second mapping relationship stored in the second MMU, so that the GPU reads the graphics data from the target PP address or writes the graphics data to the target PP address. Since the arrangement of the PP address in the non-local format obtained during the sampling process is calculated according to the target VPP address in the local format, the order of sampling the graphic data according to the PP address in the non-local format is actually sampled according to the target VPP address order in the local format. Therefore, for the sampling process, the sampling order when the GPU finally samples the graphic data can be different from the sampling order when the GPU actually samples the graphic data according to the real physical address. When the sampling order changes, the sampled graphic data is the graphic data in the local format that the GPU can recognize and process. Therefore, the order of the graphic data finally read from the memory according to the PP address in the non-local format is the graphic format that the GPU can recognize. Similarly, for the rendering process, when the GPU renders the graphic data in the local format, it can first obtain the graphic data in the local format according to the virtual physical address VPP address of this application, and then obtain the PP address in the non-local format according to the VPP address. In this way, when the GPU wants to write the graphic data in the local format into the memory in the non-local format, the graphic data finally written into the memory is still written according to the PP address in the non-local format. The graphic data written into the memory is the graphic data in the non-local format that the GPU cannot recognize. In this way, the present application does not require a display format conversion stage when sampling or rendering non-native format graphics, for example, it does not require. Figure 1 The process of converting the private format into the GPU local format by the format conversion processor 102, and the ... Figure 1 The process in which the format conversion processor 104 reads the graphics data in the local GPU cache 108 through the bus, and then converts the format of the graphics data into a format acceptable to the encoding processor 105. In addition, the buffer that does not require format conversion, for example, does not require Figure 1The local GPU cache 107 and the local GPU cache 108 in the embodiment. In comparison, the sampling and rendering process of the present application can be as follows: Figure 2G As shown, through virtualization, GPU 103 can sample the non-local format cache 106 through the intermediate layer constructed by the second virtual address space, and GPU 103 can render data to the non-local format cache 109 through the intermediate layer of the second virtual address space, which greatly reduces the processing latency and bandwidth of the system, reduces the usage of system memory, and reduces the cost of the display conversion processor.
[0104] The virtualization software agent mentioned in the above process can be implemented in the form of software, and the corresponding software program code can be stored in the memory of the terminal device and executed by the CPU; the hardware virtualization manager can be implemented in a combination of hardware and software, and its hardware structure can be set on the bus inside the device together with the GPU, and the corresponding software program code can be stored in the memory of the terminal device. In an optional case, the virtualization software agent, the hardware virtualization manager and the GPU are integrated on the same SOC.
[0105] The embodiments of the present application can be used in a process of processing graphics by a terminal device capable of displaying graphics. The terminal device can be a mobile terminal or a non-mobile terminal. For example, a mobile terminal can be a mobile phone, a tablet computer, or other mobile devices with a display function. A non-mobile terminal can be, for example, a personal computer or other devices with a display function. Figure 3 The structure of the terminal device shown in FIG. 1 includes a display, a processor, a memory, a transceiver, and a bus, and the memory includes the above-mentioned memory. The processor may include a SoC, in which the reference Figure 4 , GPU, hardware virtualization manager, vector permutate unit (VPU), CPU, image signal processing (ISP), cache, dynamic random access memory (DRAM) controller and bus can be arranged, GPU, VPU, CPU, ISP, cache and DRAM controller can be coupled through connectors, it should be understood that in various embodiments of the present application, coupling refers to mutual connection in a specific manner, including direct connection or indirect connection through other devices, for example, it can be connected through various interfaces, transmission lines or buses, etc. These interfaces are usually electrical communication interfaces, but it is not ruled out that they may be mechanical interfaces or other forms of interfaces, which are not limited in this embodiment. The embodiments of the present application can be specifically applied to the process of graphics sampling and rendering of SoC.
[0106] According to the above description, the embodiment of the present application provides a graphics processing method, which includes the following steps:
[0107] 1) The terminal device obtains a first virtual address to be accessed by a graphics processor GPU, where the first virtual address belongs to a first virtual address space.
[0108] The physical address mapped by the first virtual address corresponds to image data in a first format.
[0109] 2) The terminal device obtains a second virtual address according to the first virtual address, and the second virtual address belongs to a second virtual address space.
[0110] The second virtual address space is different from the first virtual address space, the second virtual address space and the first virtual address space are mapped to the same first physical address space, and the physical address mapped by the second virtual address space corresponds to the image data in the second format.
[0111] It can be known that the embodiment of the present application reconstructs a second virtual address space, which is different from the first virtual address space. The present application can map the address in the first virtual address space to an address in the newly added second virtual address space, and the physical address mapped by the second virtual address in the newly added second virtual address space corresponds to the graphic data in the second format, and the image data in the second format is different from the image data in the first format. For example, if the image data in the first format is image data that the GPU cannot directly access, and the image data in the second format is image data that the GPU can access, the embodiment of the present application realizes the conversion of the image format by mapping the address to a newly added virtual address space, without the need for the image format processor to perform format conversion, the GPU can access images in non-local formats, avoid applying for additional local GPU cache, avoid multiple migrations between the format conversion processor and the cache, reduce memory consumption, avoid delays, and save bandwidth and power consumption.
[0112] The above-mentioned obtaining of the second virtual address according to the first virtual address may include: translating the first virtual address into an intermediate virtual address through the first MMU in the GPU, the intermediate virtual address being a virtual address in the second virtual address space; and mapping the intermediate virtual address to the second virtual address in the second virtual address space through the hardware virtualization manager. When the first virtual address is a first virtual address in a non-local format, the intermediate virtual address can be understood as an intermediate virtual address in a non-local format, and the second virtual address can be understood as a second virtual address in a local format. That is to say, when obtaining the second virtual address, it is necessary to perform an address translation from the first virtual address to the intermediate virtual address and an address mapping from the intermediate virtual address to the second virtual address. The address mapping from the intermediate virtual address to the second virtual address can be understood as completing pixel-level address mapping in the newly added second virtual address space, so that the GPU can access the image data corresponding to the physical address according to the second virtual address, and obtain image data in the second format of the local format.
[0113] The above-mentioned translation of the first virtual address into the intermediate virtual address may include: the first MMU in the GPU may obtain the intermediate virtual address corresponding to the first virtual address in the second virtual address space according to the first mapping relationship, and the first mapping relationship is the mapping relationship between the first virtual address space and the second virtual address space. The first mapping relationship may be stored in the memory management unit MMU of the GPU. In the embodiment of the present application, the first MMU may be integrated inside the GPU or may be located outside the GPU, which is not limited in the present application.
[0114] After obtaining the second virtual address according to the first virtual address, the method may further include: obtaining the first physical address corresponding to the second virtual address in the first physical address space according to the second mapping relationship through the hardware virtualization manager, and the second mapping relationship is the mapping relationship between the second virtual address space and the first physical address space. It can be understood that the present application translates the first virtual address into an intermediate virtual address after the first address translation, and then after an address mapping, the intermediate virtual address is mapped into the second virtual address, and then after an address translation, the second virtual address is translated into the first physical address. The intermediate virtual address of the non-local format before format mapping and the second virtual address of the local format after format mapping both belong to this continuous second virtual address space, but the arrangement method has changed. When the GPU accesses the real physical address of the non-local format according to the order of the second virtual address of the local format, the second virtual address space accesses the graphics data of the local format, that is, the GPU reads or writes the image data in the order of the converted graphics data of the local format. Therefore, the present application can make the GPU sampling process do not need an additional format conversion buffer, and also omit the actual process of format conversion, so that the GPU can sample the graphics data of the non-local format in a low-cost manner. Similarly, when the non-native format physical address of the actual rendering data is obtained according to the second virtual address space, the order of rendering the graphics data according to the non-native format physical address is rendered in the order of the local format graphics data for the GPU. Therefore, the virtualization method of the present application can make the GPU rendering process do not require an additional format conversion buffer, and also omits the actual format conversion process, thereby enabling the GPU to render local format graphics data to non-native format memory in a low-cost manner.
[0115] Since the present application needs to reconstruct a second virtual address space, before obtaining the second virtual address according to the first virtual address, the method may also include: obtaining a graphics processing request sent to the GPU through a virtualization software agent, the graphics processing request includes a first virtual address space and a first physical address space, so that the second virtual address space can be constructed according to the first virtual address space and the first physical address space. In other words, when the application sends a graphics processing request to the GPU, the embodiment of the present application can intercept the graphics processing request through the virtualization software agent, thereby constructing a second virtual address space according to the request. It should be understood that the embodiment of the present application first maps the discrete first physical address space and the first virtual address space to a continuous second virtual address space, and then converts the non-local format graphics data into local format graphics data in this virtual continuous space. The format conversion of the embodiment of the present application is achieved by changing the address arrangement in the virtual space.
[0116] In this way, after the second virtual address space is constructed, the first mapping relationship and the second mapping relationship can be obtained according to the first virtual address space and the first physical address space.
[0117] As for how to obtain the second virtual address space, the present application provides a possible design that can be: the virtualization software agent obtains the size of the physical memory page PP corresponding to the first physical address space and the size of the virtual memory page VP corresponding to the first virtual address space, maps the first physical address space to a continuous virtual memory space, and obtains the second virtual address space, and the size of the virtual physical memory page VPP corresponding to the second virtual address space is larger than the size of PP and the size of VP. The purpose of this is to cover the first virtual address space and the first physical address space of the real physical address with the second virtual address space constructed by the present application, so as to establish the first mapping relationship between the first virtual address space and the second virtual address space, and the second mapping relationship between the second virtual address space and the first physical address space.
[0118] The above-mentioned obtaining of the second virtual address according to the first virtual address may include: translating the first virtual address into an intermediate virtual address; determining whether the intermediate virtual address belongs to the second virtual address space; and when the intermediate virtual address belongs to the second virtual address space, mapping the intermediate virtual address to the second virtual address in the second virtual address space. Because the MMU of the GPU maintains multiple mapping relationships, the virtual address translated by the MMU may be the actual physical address of other cache areas, rather than the virtual address in the second virtual address space, so judgment and filtering are required here. In other words, the intermediate virtual address obtained by the MMU is not necessarily the virtual address in the first mapping relationship.
[0119] The above-mentioned mapping of the intermediate virtual address to the second virtual address in the second virtual address space may include: obtaining the pixel coordinates corresponding to the intermediate virtual address; and obtaining the second virtual address according to the pixel coordinates. This is an implementation process of the above-mentioned pixel-level address mapping, and the second virtual address in a local format can be obtained through the pixel coordinates, so that the image data of the real physical address can be accessed through the second virtual address in the local format to obtain the image data in the local format.
[0120] If the image data in the first format is compressed data that the GPU needs to read, and the compressed data includes multiple compressed graphic blocks, mapping the intermediate virtual address to the second virtual address in the second virtual address space may include: obtaining the pixel coordinates corresponding to the intermediate virtual address; obtaining the compression offset information of the target compressed graphic block corresponding to the intermediate virtual address according to the pixel coordinates; calculating the second virtual address according to the compression offset information; the method also includes: decompressing the read target compressed graphic block. This is to take into account that when performing pixel-level address conversion, the image data in the non-native format stored in the memory may be compressed image data. Accordingly, when sampling to obtain the image data, the image data also needs to be decompressed.
[0121] If the image data in the first format is compressed data to be written by the GPU, the intermediate virtual address is mapped to the second virtual address in the second virtual address space, including obtaining the pixel coordinates corresponding to the intermediate virtual address; obtaining the address of the header data of the compressed data to be written according to the pixel coordinates; and obtaining the second virtual address according to the address of the header data. That is, when writing data, considering that the compressed data is stored in the memory, when storing the image data in the local format into the memory in the non-local format, the second virtual address of the compressed format data is obtained, so that the data is placed in the memory of the physical address according to the second virtual address.
[0122] If the image data in the first format stored in the memory is in an encrypted format, then mapping the intermediate virtual address to the second virtual address in the second virtual address space may include: obtaining the pixel coordinates corresponding to the intermediate virtual address; obtaining the signature of the pixel corresponding to the pixel coordinates; obtaining the second virtual address corresponding to the signature according to the signature; if the image data in the first format is encrypted data that the GPU needs to read, the method also includes: decrypting the read image data and sending the decrypted image data to the GPU. This situation takes into account that the image data stored in the memory is in an encrypted format, so when performing pixel-level address mapping, the second virtual address in the encrypted format must be obtained.
[0123] Through the above description, the embodiment of the present application can realize the GPU directly accessing image data in a non-native format by adding a second virtual address space.
[0124] The following is an example of how this application samples and renders non-native format graphic data. Figure 5 , the embodiment of the present application provides a graphics processing method, taking the sampling process as an example, the method includes:
[0125] 501. A virtualization software agent intercepts a graphics processing request sent by an application to a GPU, where the graphics processing request includes a non-native VP address space and a non-native PP address space requested by the application.
[0126] refer to Figure 6 , Figure 6 The software and hardware architecture diagram of the present application for sampling non-native format graphic data is shown. When an application instructs the GPU to sample graphic data, the application can send a graphic processing request to the GPU, and the graphic processing request carries the resources required for sampling, and the resources include the material buffer requested by the application. Since the memory sampled by the GPU stores graphic data in a non-native format for the GPU, the material buffer includes a non-native format VP address space and a non-native format PP address space. At this time, the virtual software agent can intercept the graphic processing request sent by the application to the GPU to parse the graphic processing request.
[0127] 502. The virtualization software agent constructs a VPP address space according to the VP address space and the PP address space. The VPP address space is a continuous virtual address space.
[0128] Exemplarily, the virtualization software agent may parse the intercepted graphics processing request to obtain the non-local format VP address space and the non-local format PP address space in the graphics processing request, and further, obtain the first mapping relationship between the VP address space and the VPP address space according to the mapping relationship between the VP address space and the PP address space, and construct the VPP address space by the second mapping relationship between the VPP address space and the PP address space. Here, the VPP address space can be calculated by the size of the PP and the size of the VP, which has been explained above and will not be repeated here. The GPU can read the graphics data in the local format according to the VPP address, and correspondingly, the GPU can also write the rendered local format image into the VPP address. In other words, the second virtual address is obtained virtually, not a real physical address, and the data read or written by the GPU from this virtual physical address is the graphics data in the local format that the GPU can access. In other words, when the non-local format PP address is converted to the second virtual address, the pixel arrangement format of the graphics data changes, and the buffered image obtained according to the mapped VPP is arranged in the pixel format in the local format, and this local format graphics data can be directly accessed by the GPU.
[0129] Among them, the local format refers to the GPU native format, which refers to the image format that is intrinsically supported by the GPU hardware and can be read and written by the GPU. Commonly used local formats are defined by the graphics API. For example, when the graphics API is Open Graphics Library (OpenGL), OpenGL ES (OpenGL for Embedded Systems) and Direct3D with 3D specification interface, the commonly used local formats are: RGBA8888, RGBA16F, RGB10A2, SRGB8_A8_ASTC_3x3x3, etc.
[0130] Non-native formats refer to formats that cannot be directly read or written by the GPU. For example, non-native formats include all formats that are not supported by the graphics API. These formats are generally generated by application scenarios outside the graphics community. For example, non-native formats include Y10U10V10LPacked, Y10U10V10 compressed format, ICE, and Y10U10V10.
[0131] Since the graphics data corresponding to the physical address in the non-native format is stored in the memory, the following steps also need to obtain the PP address in the non-native format used when the real sampling data is obtained according to the VPP address space. Therefore, the method also includes:
[0132] 503. The virtualization software agent sends the first mapping relationship to the GPU, and sends the second mapping relationship and the VPP address space to the hardware virtualization manager.
[0133] The VPP address in the VPP address space is used to replace the PP address in the PP address space in the MMU of the GPU, and a first mapping relationship between the VP address in the VP address space and the VPP address in the VPP address space is established in the MMU of the GPU. It should be noted that in the embodiment of the present application, the hardware structure and software program of the GPU have not been changed, and the VPP address space is stored in the MMU of the GPU, which is not perceived by the GPU and is received passively. In the prior art, what the GPU ultimately sends to the memory when reading and writing data is the real physical address, and since the MMU in the present application does not store the real physical address, what is stored is the mapping relationship between the VP address in the non-local format and the VPP address in the VPP address range, therefore, when the GPU reads and writes data in the non-local format, what is sent to the memory is the VPP address in the non-local format obtained by address translation of the VP address in the non-local format.
[0134] refer to Figure 6, the hardware virtualization manager may include a snoop filter, a format conversion processor, and a second MMU. The snoop filter is used to determine whether the physical address of the graphics data read by the GPU is within the VPP address range. The format conversion processor is used to perform pixel-level address mapping in the second virtual space, convert the VPP address (intermediate virtual address) sent by the GPU when reading the graphics data into a target VPP address (second virtual address) in a local format, and decompress or decrypt the graphics data to be read. The second MMU stores a second mapping relationship, which is a mapping relationship between the VPP address space and the PP address space. The second mapping relationship here can be that the virtualization software agent configures the second mapping relationship into the second MMU when constructing the VPP address space. The implementation method thereof can be: the virtualization software agent sends configuration information to the second MMU, and the configuration information includes the second mapping relationship.
[0135] Based on this, sending the VPP address space and the second mapping relationship to the hardware virtualization manager may include: sending the VPP address space to the snoop filter, and sending the second mapping relationship to the second MMU. In this way, when the snoop filter stores the VPP address space, when the GPU samples the graphic data, each time a graphic data is read, one graphic data corresponds to a VP address and a PP address, and similarly, it also corresponds to a VPP address. If the GPU wants to read the graphic data, the MMU of the GPU maintains multiple mapping tables. If the memory to be sampled by the GPU stores the graphic data in the local format, and the MMU of the GPU stores the real physical address, then the GPU sends the real physical address to the memory, and the real physical address snooped by the hardware virtualization manager through the snoop filter is not in the VPP address space, and the hardware virtualization manager can discard the received real physical address. In other words, the snoop filter will filter out the physical addresses that are not in the VPP address space.
[0136] 504. The hardware virtualization manager parses the access command of the GPU to obtain the intermediate virtual address carried in the access command.
[0137] Specifically, the snoop filter in the hardware virtualization manager parses the GPU access command.
[0138] 505. The hardware virtualization manager determines whether the intermediate virtual address is within the VPP address space.
[0139] As mentioned above, when the GPU samples graphics data in a local format, the intermediate virtual address carried in the GPU's access command is the actual PP address when the data is sampled, and the snoop filter will detect that the PP address is not within the VPP address range; if the GPU samples graphics data in a non-local format, the snoop filter will detect that the intermediate virtual address carried in the GPU's access command is within the virtual VPP address space of this application.
[0140] 506. If the intermediate virtual address is in the VPP address space, the hardware virtualization manager determines that the intermediate virtual address is a first VPP address in the VPP space.
[0141] That is, the snoop filter determines that the intermediate virtual address is a VPP address in the VPP space.
[0142] 507 . The hardware virtualization manager performs format mapping on the first VPP address to obtain a target VPP address in a local format.
[0143] Specifically, the snoop filter sends the first VPP address to the format conversion processor so that the format conversion processor converts the first VPP address into a target VPP address. The reason why the first VPP address needs to be converted into a target VPP address is that there are many situations in which the pixel format stored in the memory is a compressed format or an encrypted format. In other words, the target VPP address is the VPP address corresponding to the pixel format in the memory after address conversion.
[0144] Therefore, the format conversion processor converting the first VPP address into the target VPP address can be adapted to a variety of scenarios. The embodiment of the present application illustrates the scenario with the following three examples.
[0145] 1) The format conversion processor obtains the pixel coordinates (x, y) corresponding to the first VPP address according to the first VPP address, and then obtains the target VPP address corresponding to the pixel coordinates (x, y) according to the pixel coordinates (x, y).
[0146] An example of obtaining a target VPP address corresponding to a pixel coordinate (x, y) according to the pixel coordinate (x, y) may be as follows;
[0147] const uint TileW; / / 32
[0148] const uint TileH; / / 32
[0149] const uint WidthInTile=(ImageWidth+TileW-1) / TileW;
[0150] / / Tiling Address Transform
[0151] uint TileX = x / TileW;
[0152] uint TileY = y / TileH;
[0153] uint TileOffsetX=x%TileW;
[0154] uint TileOffsetY=y%TileH;
[0155] PixelAddress=(TileY*WidthInTile+TileX)*(TileW*TileH)+TileOffsetY*TileW+TileX
[0156] When sampling and rendering are performed at the tile granularity, TileW and TileH represent the width and height of the pixel tile bound to the first VPP address in the non-local format, and WidthInTile represents the sequence of tiles. In this way, the coordinates of the pixel tile (TileX, TileY) and the deviation coordinates of the pixel tlie (TileOffsetX, TileOffsetY) can be calculated based on the pixel coordinates (x, y) of the first VPP address in the non-local format and the width and height of the pixel tile. Finally, the target VPP address PixelAddress in the local format is calculated based on the width and height of the pixel tile: TileW and TileH, the coordinates of the pixel tile (TileX, TileY), and the deviation coordinates of the pixel tlie (TileOffsetX, TileOffsetY).
[0157] In this case, after the graphics data is read according to the physical address of the non-native format finally obtained, when the graphics data is to be transmitted back to the GPU, the data can be directly fed back to the GPU from the memory.
[0158] 2) When the format of the graphic data stored in the memory is a compressed format, in order to randomly access it at any location in the memory, these compressed formats are usually block-based, that is, each frame of graphics is divided into different graphic blocks, and these graphic blocks can be lossless or lossless formats. The embodiment of the present application takes lossless compression based on graphic blocks as an example for explanation.
[0159] Based on this, when the format conversion processor is to convert the first VPP address into the target VPP address, the format conversion processor may first obtain the pixel coordinates (x, y) corresponding to the first VPP address according to the first VPP address, obtain the index of the graphic block to be obtained by the first VPP address according to the pixel coordinates (x, y), and then obtain the header data of the graphic block corresponding to the index pre-stored by the format conversion processor according to the index, read the compression offset information of the header data stored in the header data, and then obtain the target VPP address corresponding to the graphic block according to the compression offset information of the header data. The compression offset information of the header data can be understood as the address of the header data.
[0160] 3) Texture samplers in some GPUs are protected by digital rights management. Therefore, not only ordinary graphics data but also additional signatures are encoded into the memory, that is, the graphics data stored in the memory is encrypted data, and multiple layers of authentication are required to obtain the data when sampling the graphics data. In this case, to implement the format conversion processor to convert the first VPP address into the target VPP address, the format conversion processor can first be controlled to obtain the pixel coordinates (x, y) corresponding to the first VPP address according to the first VPP address, and then decode the signature, that is, obtain the signature of the pixel corresponding to the pixel coordinates (x, y) according to the pixel coordinates (x, y), and then obtain the target VPP address corresponding to the signature pre-stored in the format conversion processor according to the pixel signature.
[0161] In this case, after the graphics data is read according to the physical address in the non-native format, when the graphics data is to be transmitted back to the GPU, since the graphics data stored in the memory is encrypted data, the method also includes: the format conversion processor decrypts the read graphics data and sends the decrypted graphics data to the GPU.
[0162] 508. The hardware virtualization manager obtains a target PP address (first physical address) according to the target VPP address and the second mapping relationship, so that the GPU reads the graphics data from the target PP address.
[0163] After the format conversion processor obtains the target VPP address, the target VPP address can be transmitted to the second MMU. Since the second MMU stores the second mapping relationship, the second MMU can search for the non-native format PP address corresponding to the target VPP address according to the second mapping relationship, and then the second MMU sends the found non-native format PP address to the memory to read the non-native format graphic data corresponding to the non-native format PP address from the memory.
[0164] Therefore, in an embodiment of the present application, the MMU in the GPU stores the correspondence between the virtual physical address range of the VPP address range and the VP address range. Since the address arrangement can reflect the arrangement when sampling graphic data, the arrangement of the second virtual address proposed in the present application is the arrangement of the physical address corresponding to the graphics data in the local format of the GPU. Therefore, when the physical address in the non-local format is obtained when the real sampled data is obtained according to the second virtual address, the order of sampling the graphic data according to the physical address in the non-local format is the order of the converted local format graphic data for the GPU. Therefore, the virtualization method of the present application can make the GPU sampling process do not need an additional format conversion buffer, and also omits the actual format conversion process, thereby enabling the GPU to sample non-local format graphic data in a low-cost manner.
[0165] Similar to the sampling process, the present application also provides a graphics processing method, taking the process of enabling GPU rendering to a non-native format buffer as an example, such as Figure 7 As shown, the method includes:
[0166] 701. The virtualization software agent intercepts a graphics processing request and graphics data sent by an application to a GPU, wherein the graphics processing request includes a non-native VP address space and a non-native PP address space requested by the application.
[0167] The implementation of step 701 is similar to the implementation of step 501, except that when the virtualization software agent intercepts the graphics processing request, it also intercepts the graphics data to be written into the memory. The graphics data is in the GPU local format, and the embodiment of the present application is to write the graphics data in the GPU local format into the memory in a non-local format.
[0168] It is understandable that the graphic data may also be sent directly by the application to the GPU without being intercepted by the virtualization software agent.
[0169] 702. The virtualization software agent constructs a VPP address space according to the VP address space and the PP address space. The VPP address space is a continuous virtual address space.
[0170] The implementation of step 702 is similar to the implementation of step 502. The difference is that the VPP address space is used to enable the GPU to render graphics data in a local format according to the address sequence of the local format. Similarly, due to the different address sequences, the format of the graphics data rendered according to the address is also different. In this way, although the graphics data stored in the memory is graphics data in a non-local format, the application program applies for a VP address space in a non-local format and a PP address space in a non-local format, but when the GPU wants to render the graphics data in the local format into the memory in a non-local format, the GPU can first obtain the graphics data in the local format according to the address sequence of the VPP address in the local format proposed in this application, so as to facilitate the subsequent mapping of the VPP address to the PP address in the non-local format. When the graphics data in the local format is stored in the memory, the graphics data in the local format can be written into the memory according to the PP address in the non-local format, so that the graphics data stored in the memory is ultimately non-local format.
[0171] 703. The virtualization software agent sends the first mapping relationship to the GPU, and sends the second mapping relationship and the VPP address space to the hardware virtualization manager.
[0172] The implementation of step 703 is similar to the implementation of step 503, except that if the virtualization software agent also intercepts the graphics data, the virtualization software agent also needs to send the graphics data to the GPU so that the GPU writes the intercepted graphics data into the memory through the hardware virtualization manager. The snooping filter is used to determine whether the physical address of the graphics data rendered by the GPU is within the VPP address range. The format conversion processor is used to convert the first VPP address sent by the GPU when rendering the graphics data into a target VPP address, and compress or encrypt the graphics data to be written.
[0173] 704. The hardware virtualization manager parses the access command of the GPU to obtain the intermediate virtual address carried in the access command.
[0174] 705 . The hardware virtualization manager determines whether the intermediate virtual address is within the VPP address space.
[0175] The implementation of step 705 may refer to the above step 505 .
[0176] 706. If the intermediate virtual address is in the VPP address space, the hardware virtualization manager determines that the intermediate virtual address is a first VPP address in the VPP space.
[0177] 707 . The hardware virtualization manager performs format mapping on the first VPP address to obtain a target VPP address in a local format.
[0178] Specifically, the snoop filter sends the first VPP address and the graphics data received from the GPU to the format conversion processor, and controls the format conversion processor to convert the first VPP address into a target VPP address. Similar to step 507, the format conversion processor performs address conversion also taking into account the different pixel formats in the memory.
[0179] Similarly, during GPU rendering, controlling the format conversion processor to convert the first VPP address into the target VPP address can also be applied to a variety of scenarios:
[0180] For one scenario, please refer to the description in case 1) in step 508 .
[0181] Another scenario is similar to the situation 2) in step 508, except that the graphics data to be rendered also needs to be compressed during the address conversion process. Specifically, if the pixel format stored in the memory is a compressed format, and the GPU needs to write graphics data into the memory, then in order to implement the format conversion processor to convert the first VPP address into the target VPP address, the format conversion processor can be controlled to obtain the pixel coordinates (x, y) corresponding to the first VPP address according to the first VPP address; calculate the index of the graphic block corresponding to the graphic data according to the pixel coordinates (x, y), obtain the header data of the graphic block according to the index, and compress the header data and the graphic data; store the correspondence between the compressed header data and the index in the format converter, so that the correspondence can be used in the subsequent sampling process. Then, the target VPP address corresponding to the graphic block is calculated according to the address of the header data.
[0182] Another scenario is similar to the situation 3) in step 508, except that when converting the first VPP address to the target VPP address, if the pixel format stored in the memory is an encrypted format, the format conversion processor also needs to encrypt the graphic data to be written. The specific encryption method can be implemented using a simple stream cipher or a relatively complex private cipher of a block cipher, which is not limited in this application.
[0183] 708. The hardware virtualization manager obtains a target PP address (first physical address) according to the target VPP address and the second mapping relationship, so that the GPU writes graphics data into the target PP address.
[0184] When the format conversion processor obtains the target VPP address, it sends the target VPP address and the compressed or encrypted graphics data to the second MMU; the second MMU searches for the PP address in the non-native format corresponding to the target VPP address according to the stored second mapping relationship, and the second MMU sends the graphics data to the memory according to the found PP address, so as to write the graphics data into the memory in the non-native format according to the PP address.
[0185] Therefore, in an embodiment of the present application, the MMU in the GPU stores a virtual physical address such as the VPP address, that is, the second virtual address space. Since the address arrangement can reflect the arrangement when rendering graphics data, the virtual physical address arrangement proposed in the present application is the arrangement of the physical address corresponding to the graphics data in the local format of the GPU. Therefore, when the non-local format physical address of the corresponding real rendering data is obtained according to the virtual physical address, the order of rendering the graphics data according to the non-local format physical address is rendered in the order of the graphics data in the local format for the GPU. Therefore, the virtualization method of the present application can make the GPU rendering process do not require an additional format conversion buffer, and also omits the actual format conversion process, thereby enabling the GPU to render local format graphics data to non-local format memory in a low-cost manner.
[0186] The above mainly introduces the solution provided by the embodiment of the present application from the perspective of the terminal device. It is understandable that in order to realize the above functions, the terminal device includes a hardware structure and / or software module corresponding to each function. Those skilled in the art should easily realize that, in combination with the units and algorithm steps of each example described in the embodiments disclosed herein, the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present application.
[0187] The embodiment of the present application can divide the functional modules of the terminal device according to the above method example. For example, each functional module can be divided according to each function, or two or more functions can be integrated into one processing module. The above integrated module can be implemented in the form of hardware or in the form of software functional modules. It should be noted that the division of modules in the embodiment of the present application is schematic and is only a logical function division. There may be other division methods in actual implementation.
[0188] In the case of dividing each functional module into corresponding functional modules, Figure 8 A possible structural diagram of a terminal device involved in the above embodiment is shown. The terminal device may include a graphics processing device, which may be used to perform Figure 5 The corresponding method steps and Figure 7 The terminal device 80 includes: an acquisition unit 801, a transmission unit 802 and a determination unit 803. The acquisition unit 801 is used to support the terminal device to execute Figure 5In the processes 501, 502, 504, 507 and 508, Figure 7 The processes 701, 702, 704, 707 and 708 in FIG. 8; the transmission unit 802 is used to perform Figure 5 In the process 503, Figure 7 The process 703 in the determination unit 803 is used to support the terminal device 80 to execute Figure 5 In process 505 and 506, Figure 7 The processes 705 and 706 in the above method embodiment are shown in FIG. 1 . All relevant contents of each step involved in the above method embodiment can be referred to the functional description of the corresponding functional module, and will not be repeated here.
[0189] In the case of an integrated unit, Fig. 9 A possible structural diagram of the terminal device involved in the above embodiment is shown. The terminal device 90 includes: a processing module 902 and a communication module 903. The processing module 902 is used to control and manage the actions of the terminal device. For example, the processing module 902 is used to support the terminal device to execute Figure 5 Process 501-508, Figure 7 The communication module 903 is used to support the communication between the terminal device and other network entities. The terminal device may also include a storage module 901 for storing program code and data of the terminal device, the program code and data including the program code and data of the virtualization software agent and the hardware virtualization manager of the present application.
[0190] Among them, the processing module 902 can be a processor or a controller, for example, a central processing unit (CPU), a general processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, transistor logic devices, hardware components or any combination thereof. It can implement or execute various exemplary logic boxes, modules and circuits described in conjunction with the disclosure of the present application. The processor can also be a combination that implements a computing function, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, and the like. The communication module 903 can be a transceiver, a transceiver circuit or a communication interface, and the like. The storage module 901 can be a memory. The memory includes the program code and data of the virtualization software agent and the hardware virtualization manager of the present application. The processor includes the hardware structure of the hardware virtualization manager of the present application.
[0191] When the processing module 902 is a processor, the communication module 903 is a transceiver, and the storage module 901 is a memory, the terminal device involved in the embodiment of the present application can be Figure 3 The terminal device shown.
[0192] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any changes or substitutions within the technical scope disclosed by the present invention should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.
Claims
1. A graphics processing method, characterized in that: include: Obtaining a first virtual address to be accessed by a graphics processor GPU, where the first virtual address belongs to a first virtual address space; Obtain a second virtual address according to the first virtual address, where the second virtual address belongs to a second virtual address space; The second virtual address space is different from the first virtual address space, the second virtual address space and the first virtual address space are mapped to the same first physical address space, the physical address mapped by the first virtual address corresponds to image data in a first format, and the physical address mapped by the second virtual address corresponds to image data in a second format.
2. The method according to claim 1, characterized in that The obtaining the second virtual address according to the first virtual address specifically includes: translating the first virtual address into an intermediate virtual address, the intermediate virtual address being a virtual address in the second virtual address space; The intermediate virtual address is mapped to the second virtual address in the second virtual address space.
3. The method according to claim 2, characterized in that The translating the first virtual address into an intermediate virtual address specifically includes: The intermediate virtual address corresponding to the first virtual address in the second virtual address space is obtained according to a first mapping relationship, where the first mapping relationship is a mapping relationship between the first virtual address space and the second virtual address space.
4. The method according to claim 3, characterized in that After obtaining the second virtual address according to the first virtual address, the method further includes: A first physical address corresponding to the second virtual address in the first physical address space is obtained according to a second mapping relationship, where the second mapping relationship is a mapping relationship between the second virtual address space and the first physical address space.
5. The method according to claim 4, characterized in that Before obtaining the second virtual address according to the first virtual address, the method further includes: Acquire a graphics processing request sent to the GPU, the graphics processing request including the first virtual address space and the first physical address space; The second virtual address space is constructed according to the first virtual address space and the first physical address space.
6. The method according to claim 5, characterized in that The method further comprises: The first mapping relationship and the second mapping relationship are obtained according to the first virtual address space and the first physical address space.
7. The method according to claim 5 or 6, characterized in that: The constructing the second virtual address space according to the first virtual address space and the first physical address space specifically includes: Obtaining a size of a physical memory page PP corresponding to the first physical address space and a size of a virtual memory page VP corresponding to the first virtual address space; The first physical address space is mapped into a continuous virtual memory space to obtain the second virtual address space, and the size of a virtual physical memory page VPP corresponding to the second virtual address space is larger than the size of the PP and the size of the VP.
8. The method according to claim 1, characterized in that The obtaining the second virtual address according to the first virtual address comprises: translating the first virtual address into an intermediate virtual address; Determining whether the intermediate virtual address belongs to the second virtual address space; When the intermediate virtual address belongs to the second virtual address space, the intermediate virtual address is mapped to the second virtual address in the second virtual address space.
9. The method according to claim 2, characterized in that: Mapping the intermediate virtual address to the second virtual address in the second virtual address space specifically includes: Obtaining pixel coordinates corresponding to the intermediate virtual address; The second virtual address is obtained according to the pixel coordinates.
10. The method according to claim 2, characterized in that The image data in the first format is compressed data to be read by the GPU, the compressed data includes a plurality of compressed graphic blocks, and mapping the intermediate virtual address to the second virtual address in the second virtual address space includes: Obtaining pixel coordinates corresponding to the intermediate virtual address; Acquire compression offset information of a target compressed graphic block corresponding to the intermediate virtual address according to the pixel coordinates; Calculate the second virtual address according to the compression offset information; The method further comprises: The read target compressed graphic block is decompressed.
11. The method according to claim 2, characterized in that The image data in the first format is compressed data to be written by the GPU, and mapping the intermediate virtual address to the second virtual address in the second virtual address space includes: Obtaining pixel coordinates corresponding to the intermediate virtual address; Acquire the address of the header data of the compressed data to be written according to the pixel coordinates; The second virtual address is obtained according to the address of the header data.
12. The method according to claim 2, characterized in that: Mapping the intermediate virtual address to the second virtual address in the second virtual address space includes: Obtaining pixel coordinates corresponding to the intermediate virtual address; Obtaining a signature of a pixel corresponding to the pixel coordinates; Acquire the second virtual address corresponding to the signature according to the signature; If the image data in the first format is encrypted data that the GPU needs to read, the method further includes: The read image data is decrypted, and the decrypted image data is sent to the GPU.
13. A graphics processing device, characterized in that: The device comprises a graphics processor GPU and a hardware virtualization manager, wherein: The GPU is used to obtain a first virtual address to be accessed, where the first virtual address belongs to a first virtual address space; A hardware virtualization manager, configured to obtain a second virtual address according to the first virtual address, wherein the second virtual address belongs to a second virtual address space; The second virtual address space is different from the first virtual address space, the second virtual address space and the first virtual address space are mapped to the same first physical address space, the physical address mapped by the first virtual address corresponds to image data in a first format, and the physical address mapped by the second virtual address corresponds to image data in a second format.
14. The device according to claim 13, characterized in that The GPU includes a first memory management unit MMU, and the hardware virtualization manager includes a format conversion processor; The first MMU is used to translate the first virtual address into an intermediate virtual address, where the intermediate virtual address is a virtual address in the second virtual address space; The format conversion processor is used to map the intermediate virtual address to the second virtual address in the second virtual address space.
15. The device according to claim 14, characterized in that The first MMU is used for: The intermediate virtual address corresponding to the first virtual address in the second virtual address space is obtained according to a first mapping relationship, where the first mapping relationship is a mapping relationship between the first virtual address space and the second virtual address space.
16. The device according to claim 15, characterized in that The hardware virtualization manager includes a second MMU, wherein the second MMU is configured to: A first physical address corresponding to the second virtual address in the first physical address space is obtained according to a second mapping relationship, where the second mapping relationship is a mapping relationship between the second virtual address space and the first physical address space.
17. The device according to claim 16, characterized in that The device further includes a central processing unit (CPU), on which a virtualization software agent runs, and the virtualization software agent is used to: Acquire a graphics processing request sent to the GPU, the graphics processing request including the first virtual address space and the first physical address space; The second virtual address space is constructed according to the first virtual address space and the first physical address space.
18. The device according to claim 17, characterized in that The virtualization software agent is also used for: The first mapping relationship and the second mapping relationship are obtained according to the first virtual address space and the first physical address space.
19. The device according to claim 17 or 18, characterized in that The virtualization software agent is specifically used for: Obtaining a size of a physical memory page PP corresponding to the first physical address space and a size of a virtual memory page VP corresponding to the first virtual address space; The first physical address space is mapped into a continuous virtual memory space to obtain the second virtual address space, and the size of the virtual physical memory page VPP corresponding to the second virtual address space is larger than the size of the PP and the size of the VP.
20. The device according to claim 13, characterized in that The GPU includes a first MMU, and the hardware virtualization manager includes a snoop filter and a format conversion processor; The first MMU is used to: translate the first virtual address into an intermediate virtual address; The snoop filter is used to: Determining whether the intermediate virtual address belongs to the second virtual address space; When the intermediate virtual address belongs to the second virtual address space, sending the intermediate virtual address to the format conversion processor; The format conversion processor is used for mapping the intermediate virtual address to the second virtual address in the second virtual address space.
21. The device according to claim 14, characterized in that The format conversion processor is specifically used for: Obtaining pixel coordinates corresponding to the intermediate virtual address; The second virtual address is obtained according to the pixel coordinates.
22. The device according to claim 14, characterized in that The image data in the first format is compressed data to be read by the GPU, and the compressed data includes a plurality of compressed graphic blocks; The format conversion processor is specifically used for: Obtaining pixel coordinates corresponding to the intermediate virtual address; Acquire compression offset information of a target compressed graphic block corresponding to the intermediate virtual address according to the pixel coordinates; Calculate the second virtual address according to the compression offset information; The format conversion processor is also used for: The read target compressed graphic block is decompressed.
23. The device according to claim 14, characterized in that The image data in the first format is compressed data to be written by the GPU; the format conversion processor is used to: Obtaining pixel coordinates corresponding to the intermediate virtual address; Acquire the address of the header data of the compressed data to be written according to the pixel coordinates; The second virtual address is obtained according to the address of the header data.
24. The device according to claim 14, characterized in that The format conversion processor is used for: Obtaining pixel coordinates corresponding to the intermediate virtual address; Obtaining a signature of a pixel corresponding to the pixel coordinates; Acquire the second virtual address corresponding to the signature according to the signature; If the image data in the first format is encrypted data to be read by the GPU, the format conversion processor is further configured to: The read image data is decrypted, and the decrypted image data is sent to the GPU.
25. A graphics processing method, characterized in that: include: Obtaining a first virtual address to be accessed, where the first virtual address belongs to a first virtual address space; translating the first virtual address into an intermediate virtual address, the intermediate virtual address belonging to a second virtual address space, and the intermediate virtual address being mappable to a second virtual address in the second virtual address space; The second virtual address space is different from the first virtual address space, the second virtual address space and the first virtual address space are mapped to the same first physical address space, the physical address mapped by the first virtual address corresponds to image data in a first format, and the physical address mapped by the second virtual address corresponds to image data in a second format.
26. The method according to claim 25, characterized in that The translating the first virtual address into an intermediate virtual address specifically includes: The intermediate virtual address corresponding to the first virtual address in the second virtual address space is obtained according to a first mapping relationship, where the first mapping relationship is a mapping relationship between the first virtual address space and the second virtual address space.
27. A graphics processor GPU, characterized in that: The GPU includes a transmission interface and a memory management unit MMU, wherein: The transmission interface is used to obtain a first virtual address to be accessed, where the first virtual address belongs to a first virtual address space; The MMU is configured to translate the first virtual address into an intermediate virtual address, the intermediate virtual address belonging to a second virtual address space, and the intermediate virtual address can be mapped to a second virtual address in the second virtual address space; The second virtual address space is different from the first virtual address space, the second virtual address space and the first virtual address space are mapped to the same first physical address space, the physical address mapped by the first virtual address corresponds to image data in a first format, and the physical address mapped by the second virtual address corresponds to image data in a second format.
28. The GPU according to claim 27, characterized in that The MMU is specifically used for: The intermediate virtual address corresponding to the first virtual address in the second virtual address space is obtained according to a first mapping relationship, where the first mapping relationship is a mapping relationship between the first virtual address space and the second virtual address space.
Citation Information
Patent Citations
Virtual disk file format conversion method and device
CN108664523A
A scheduling method and device for a graphic rendering buffer compression table
CN109727183A
Virtual memory translation with pre-fetch prediction
US20080276066A1
