CN116703693A - Image rendering method and electronic device - Google Patents
Image rendering method and electronic device Download PDFInfo
- Publication number
- CN116703693A CN116703693A CN202310227425.5A CN202310227425A CN116703693A CN 116703693 A CN116703693 A CN 116703693A CN 202310227425 A CN202310227425 A CN 202310227425A CN 116703693 A CN116703693 A CN 116703693A
- Authority
- CN
- China
- Prior art keywords
- model
- function
- electronic device
- module
- rendering
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000009877 rendering Methods 0.000 title claims abstract description 166
- 238000000034 method Methods 0.000 title claims abstract description 148
- 238000012545 processing Methods 0.000 claims abstract description 160
- 230000006870 function Effects 0.000 claims description 239
- 239000011159 matrix material Substances 0.000 claims description 130
- 238000003860 storage Methods 0.000 claims description 130
- 230000008569 process Effects 0.000 claims description 81
- 238000004364 calculation method Methods 0.000 claims description 63
- 230000015654 memory Effects 0.000 claims description 50
- 230000007246 mechanism Effects 0.000 abstract description 25
- 238000004040 coloring Methods 0.000 abstract description 23
- 230000009467 reduction Effects 0.000 abstract description 3
- 239000008186 active pharmaceutical agent Substances 0.000 description 62
- 239000000872 buffer Substances 0.000 description 56
- 238000013461 design Methods 0.000 description 23
- 238000007726 management method Methods 0.000 description 21
- 238000004891 communication Methods 0.000 description 18
- 230000009466 transformation Effects 0.000 description 16
- 238000010295 mobile communication Methods 0.000 description 11
- 238000004458 analytical method Methods 0.000 description 10
- 238000010586 diagram Methods 0.000 description 10
- 230000000694 effects Effects 0.000 description 10
- 230000005236 sound signal Effects 0.000 description 10
- 239000000203 mixture Substances 0.000 description 7
- 238000012546 transfer Methods 0.000 description 7
- 238000005516 engineering process Methods 0.000 description 6
- 230000005540 biological transmission Effects 0.000 description 5
- 238000012986 modification Methods 0.000 description 5
- 230000004048 modification Effects 0.000 description 5
- 229920001621 AMOLED Polymers 0.000 description 4
- 238000013528 artificial neural network Methods 0.000 description 4
- 210000000988 bone and bone Anatomy 0.000 description 4
- 230000020169 heat generation Effects 0.000 description 4
- 238000012216 screening Methods 0.000 description 4
- 230000001960 triggered effect Effects 0.000 description 4
- SPBWHPXCWJLQRU-FITJORAGSA-N 4-amino-8-[(2r,3r,4s,5r)-3,4-dihydroxy-5-(hydroxymethyl)oxolan-2-yl]-5-oxopyrido[2,3-d]pyrimidine-6-carboxamide Chemical compound C12=NC=NC(N)=C2C(=O)C(C(=O)N)=CN1[C@@H]1O[C@H](CO)[C@@H](O)[C@H]1O SPBWHPXCWJLQRU-FITJORAGSA-N 0.000 description 3
- 230000001133 acceleration Effects 0.000 description 3
- 230000003044 adaptive effect Effects 0.000 description 3
- 230000008859 change Effects 0.000 description 3
- 238000004590 computer program Methods 0.000 description 3
- 239000004065 semiconductor Substances 0.000 description 3
- 230000003190 augmentative effect Effects 0.000 description 2
- 238000004422 calculation algorithm Methods 0.000 description 2
- 230000000295 complement effect Effects 0.000 description 2
- 238000013500 data storage Methods 0.000 description 2
- 238000001514 detection method Methods 0.000 description 2
- 230000003993 interaction Effects 0.000 description 2
- 239000004973 liquid crystal related substance Substances 0.000 description 2
- 230000003287 optical effect Effects 0.000 description 2
- 230000008447 perception Effects 0.000 description 2
- 239000002096 quantum dot Substances 0.000 description 2
- 239000007787 solid Substances 0.000 description 2
- 230000003068 static effect Effects 0.000 description 2
- 239000013598 vector Substances 0.000 description 2
- 230000000007 visual effect Effects 0.000 description 2
- 230000009471 action Effects 0.000 description 1
- 230000003416 augmentation Effects 0.000 description 1
- 238000010009 beating Methods 0.000 description 1
- 230000009286 beneficial effect Effects 0.000 description 1
- 238000013529 biological neural network Methods 0.000 description 1
- 230000036772 blood pressure Effects 0.000 description 1
- 210000004556 brain Anatomy 0.000 description 1
- 230000001413 cellular effect Effects 0.000 description 1
- 230000019771 cognition Effects 0.000 description 1
- 239000003086 colorant Substances 0.000 description 1
- 239000004020 conductor Substances 0.000 description 1
- 238000009826 distribution Methods 0.000 description 1
- 238000007667 floating Methods 0.000 description 1
- 239000012634 fragment Substances 0.000 description 1
- 230000004927 fusion Effects 0.000 description 1
- 230000036541 health Effects 0.000 description 1
- 230000001976 improved effect Effects 0.000 description 1
- 230000006872 improvement Effects 0.000 description 1
- 230000001939 inductive effect Effects 0.000 description 1
- 230000007774 longterm Effects 0.000 description 1
- 210000002569 neuron Anatomy 0.000 description 1
- 239000013307 optical fiber Substances 0.000 description 1
- 238000005457 optimization Methods 0.000 description 1
- 230000005855 radiation Effects 0.000 description 1
- 230000004044 response Effects 0.000 description 1
- 230000001755 vocal effect Effects 0.000 description 1
- 239000011800 void material Substances 0.000 description 1
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T1/00—General purpose image data processing
- G06T1/20—Processor architectures; Processor configuration, e.g. pipelining
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T1/00—General purpose image data processing
- G06T1/60—Memory management
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T15/00—3D [Three Dimensional] image rendering
- G06T15/10—Geometric effects
- G06T15/20—Perspective computation
- G06T15/205—Image-based rendering
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T15/00—3D [Three Dimensional] image rendering
- G06T15/50—Lighting effects
- G06T15/80—Shading
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Computer Graphics (AREA)
- Computing Systems (AREA)
- Geometry (AREA)
- Image Generation (AREA)
Abstract
Description
本申请是分案申请,原申请的申请号是202110951444.3,原申请日是2021年8月18日,原申请的全部内容通过引用结合在本申请中。This application is a divisional application, the application number of the original application is 202110951444.3, and the original application date is August 18, 2021. The entire content of the original application is incorporated in this application by reference.
技术领域technical field
本申请涉及图像处理技术领域,尤其涉及一种图像渲染方法及电子设备。The present application relates to the technical field of image processing, in particular to an image rendering method and electronic equipment.
背景技术Background technique
电子设备在对图像进行渲染处理时,包括对图像的着色处理。示例性的,电子设备的图形处理器(graphics processing unit,GPU)可以分别对图像的每个像素进行着色,进而完成对整个图像的着色处理。When an electronic device renders an image, it includes coloring the image. Exemplarily, a graphics processing unit (graphics processing unit, GPU) of the electronic device may color each pixel of the image separately, and then complete the coloring process of the entire image.
随着图像的像素的提高,对图像的着色处理会对电子设备产生较高的渲染负荷,如增加渲染过程中的算力和功耗开销。With the increase of the pixels of the image, the coloring process of the image will generate a higher rendering load on the electronic device, such as increasing the computing power and power consumption during the rendering process.
发明内容Contents of the invention
本申请实施例提供一种图像渲染方法和电子设备,可以实现通过可变速率着色机制降低渲染开销,同时不会由于着色速率的降低产生对用户体验的影响。Embodiments of the present application provide an image rendering method and an electronic device, which can reduce rendering overhead through a variable rate shading mechanism without affecting user experience due to the reduction of shading rate.
为了达到上述目的,本申请实施例采用如下技术方案:In order to achieve the above purpose, the embodiment of the present application adopts the following technical solutions:
第一方面,提供一种图像渲染方法,应用于电子设备,该电子设备中安装有应用程序,该方法包括:获取该应用程序下发的第一渲染命令,该第一渲染命令用于绘制第一模型。确定该第一模型的第一着色速率。根据该第一渲染命令和该第一着色速率绘制该第一模型。In a first aspect, an image rendering method is provided, which is applied to an electronic device, and an application program is installed in the electronic device. The method includes: acquiring a first rendering command issued by the application program, and the first rendering command is used to draw the first a model. A first shading rate for the first model is determined. The first model is rendered according to the first rendering command and the first shading rate.
基于该方案,提供了一种对不同的模型进行不同速率着色的方案示例。在本示例中,电子设备可以根据对不同模型的渲染命令,确定各个模型的着色速率。进而以渲染命令(即Drawcall)为粒度,对模型的绘制等渲染操作进行不同的速率着色,进而对部分模型进行低速率着色,由此节省着色过程中的渲染开销,如算力开销,发热等。Based on this scheme, an example of a scheme for coloring different models at different rates is provided. In this example, the electronic device can determine the shading rate of each model according to rendering commands for different models. Then, with the rendering command (Drawcall) as the granularity, the rendering operations such as model drawing are shaded at different rates, and some models are shaded at a low rate, thereby saving the rendering overhead during the shader process, such as computing power overhead, heat generation, etc. .
在一种可能的设计中,该确定该第一模型的第一着色速率,包括:根据该第一渲染命令,确定该第一模型的深度,该第一模型的深度用于标识该第一模型在观察空间或者裁剪空间中到观察者之间的距离,该第一模型的深度越大,该第一模型到该观察者之间的距离越远。根据该第一模型的深度,确定该第一着色速率。基于该方案,提供了一种确定不同模型的着色速率的机制。示例性的,可以根据不同模型的深度,确定对应的着色速率。可以理解的是,深度越大,则该模型在图像中距离用户就越远,因此可以采用较低速率着色,节省渲染开销。In a possible design, the determining the first shading rate of the first model includes: determining the depth of the first model according to the first rendering command, where the depth of the first model is used to identify the first model In the observation space or the clipping space, the greater the depth of the first model is, the farther the distance between the first model and the observer is. The first shading rate is determined according to the depth of the first model. Based on this scheme, a mechanism is provided to determine the shading rate of different models. Exemplarily, the corresponding shading rate can be determined according to the depth of different models. It can be understood that the greater the depth, the farther the model is from the user in the image, so lower rate shading can be used to save rendering overhead.
在一种可能的设计中,该根据该第一渲染命令,确定该第一模型的深度,包括:根据该第一渲染命令,确定该第一模型的n个顶点的深度。根据该n个顶点的深度,确定该第一模型的深度。其中,n个顶点包括在该第一模型的顶点中。基于该方案,提供了一种确定模型深度的方案示例。示例性的,可以根据模型的顶点的深度,确定模型的深度。其中,模型的顶点的深度可以是观察空间或者裁剪空间或者其他能够用于标识顶点到用户距离的深度。在本示例中,n可以等于模型的最大顶点数。这样就可以根据模型的所有顶点深度,确定模型的深度。在另一些实施例中,n可以小于模型的最大顶点数,如n个顶点可以是模型的所有顶点中随机选取的n个顶点。由此可以节省计算模型顶点过程中的计算量。In a possible design, the determining the depth of the first model according to the first rendering command includes: determining the depths of n vertices of the first model according to the first rendering command. Determine the depth of the first model according to the depths of the n vertices. Wherein, n vertices are included in the vertices of the first model. Based on this scheme, an example scheme for determining the depth of a model is provided. Exemplarily, the depth of the model may be determined according to the depth of the vertices of the model. Wherein, the depth of the vertex of the model may be the observation space or the clipping space or other depths that can be used to identify the distance from the vertex to the user. In this example, n can be equal to the maximum number of vertices of the model. In this way, the depth of the model can be determined according to the depth of all vertices of the model. In some other embodiments, n may be less than the maximum number of vertices of the model, for example, n vertices may be randomly selected n vertices from all vertices of the model. In this way, the calculation amount in the process of calculating the vertices of the model can be saved.
在一种可能的设计中,该方法还包括:获取该应用程序下发的第二渲染命令,该第二渲染命令用于绘制第二模型。确定该第二模型的第二着色速率。根据该第二渲染命令和该第二着色速率绘制该第二模型。该第一模型和该第二模型包括在同一个帧图像中,该第一着色速率和该第二着色速率不同。基于该方案,电子设备还可以进行第二模型的可变速率着色。在一些情况下,第二模型的相关参数(如深度信息)与第一模型不同,二者对应的着色速率也不同。In a possible design, the method further includes: acquiring a second rendering command issued by the application program, where the second rendering command is used to draw the second model. A second shading rate for the second model is determined. The second model is rendered according to the second rendering command and the second shading rate. The first model and the second model are included in the same frame image, and the first shading rate and the second shading rate are different. Based on this scheme, the electronic device can also perform variable rate shading of the second model. In some cases, the relevant parameters of the second model (such as depth information) are different from those of the first model, and the corresponding shading rates of the two models are also different.
在一种可能的设计中,该电子设备中配置有拦截模块以及数据处理模块,该获取该应用程序下发的第一渲染命令,包括。该拦截模块拦截该第一渲染命令。该拦截模块将拦截的第一函数和第二函数传输给该数据处理模块。该第一函数是携带第一参数的函数,该第二函数是携带第二参数的函数,该第一参数是该应用程序传递顶点数据过程中携带的参数,该第二参数是该应用程序传递MVP矩阵过程中携带的参数。基于该方案,提供了一种具体的拦截命令的方案示例。在本示例中,拦截模块可以拦截全量的第一渲染命令,并将第一渲染命令中携带第一参数和第二参数的指令(或函数)传输给数据处理模块,实现对有用数据的拦截。其中有用数据可以是顶点相关数据以及MVP矩阵。In a possible design, the electronic device is configured with an interception module and a data processing module, and the acquisition of the first rendering command issued by the application program includes. The interception module intercepts the first rendering command. The interception module transmits the intercepted first function and second function to the data processing module. The first function is a function carrying a first parameter, the second function is a function carrying a second parameter, the first parameter is a parameter carried in the process of transferring vertex data by the application program, and the second parameter is a function passed by the application program Parameters carried in the MVP matrix process. Based on this solution, a specific example of a solution for intercepting commands is provided. In this example, the interception module can intercept all the first rendering commands, and transmit the instruction (or function) carrying the first parameter and the second parameter in the first rendering command to the data processing module, so as to realize the interception of useful data. The useful data may be vertex related data and MVP matrix.
在一种可能的设计中,该方法还包括:该拦截模块将该第一渲染命令中,该第一函数和该第二函数之外的函数回调给该电子设备的图形库。基于该方案,提供了一种回调机制。可以理解的是,在原生逻辑中,第一渲染命令可以被下发给图形库进行处理。在本示例中,拦截模块可以在拦截第一函数和第二函数之后,将其他部分命令传输给图形库,以保证正常渲染逻辑的运行。In a possible design, the method further includes: the intercepting module calling back functions other than the first function and the second function in the first rendering command to a graphics library of the electronic device. Based on this solution, a callback mechanism is provided. It can be understood that, in the native logic, the first rendering command can be sent to the graphics library for processing. In this example, after intercepting the first function and the second function, the interception module can transmit other part of commands to the graphics library, so as to ensure the normal operation of the rendering logic.
在一种可能的设计中,在该拦截模块将拦截的第一函数和第二函数传输给该数据处理模块之后,该方法还包括:该数据处理模块根据该第一函数和该第二函数,确定该第一模型对应的顶点坐标的第一存储位置,以及该第一MVP矩阵的第二存储位置,该第一存储位置和该第二存储位置包括在第一存储区域中,该第一存储区域是该电子设备的处理器能够调取的存储区域。基于该方案,提供了一种确定顶点坐标和MVP矩阵的方案示例。例如,携带第一参数的第一函数,可以用于指示当前Drawcall所对应模型的顶点坐标的缓存ID。那么数据处理模块就可以根据该第一函数,解析出第一模型的顶点坐标的缓存ID。进而根据预设的或者第一函数指示的属性以及偏移量等参数,确定顶点坐标的具体存储位置。数据处理模块还可以基于类似的逻辑获取MVP矩阵。其中,数据处理模块确定的存储位置可以是备份存储的数据的存储位置,由此可以保证其他模块的正常调用。In a possible design, after the interception module transmits the intercepted first function and second function to the data processing module, the method further includes: the data processing module, according to the first function and the second function, Determine the first storage location of the vertex coordinates corresponding to the first model, and the second storage location of the first MVP matrix, the first storage location and the second storage location are included in the first storage area, the first storage A region is a memory region that can be accessed by the processor of the electronic device. Based on this scheme, an example scheme for determining vertex coordinates and MVP matrix is provided. For example, the first function carrying the first parameter may be used to indicate the cache ID of the vertex coordinates of the model corresponding to the current Drawcall. Then the data processing module can analyze the cache ID of the vertex coordinates of the first model according to the first function. Further, the specific storage location of the vertex coordinates is determined according to parameters such as preset or attributes indicated by the first function and offsets. The data processing module can also obtain the MVP matrix based on similar logic. Wherein, the storage location determined by the data processing module may be a storage location of backup stored data, thereby ensuring normal calling of other modules.
在一种可能的设计中,该方法还包括:该数据处理模块将该第一函数和第二函数回调给该电子设备的图形库。基于该方案,提供了又一种回调机制。示例性的,拦截模块已经将第一命令中除第一函数和第二函数之外的函数进行了回调,那么数据处理模块可以回调第一函数和第二函数,实现第一渲染命令的全量回调,从而保证渲染逻辑的准确执行。In a possible design, the method further includes: the data processing module calling back the first function and the second function to a graphics library of the electronic device. Based on this solution, another callback mechanism is provided. Exemplarily, the interception module has already called back the functions in the first command except the first function and the second function, then the data processing module can call back the first function and the second function to realize the full callback of the first rendering command , so as to ensure the accurate execution of the rendering logic.
在一种可能的设计中,在获取该应用程序下发的第一渲染命令之前,该方法还包括:该拦截模块拦截该应用程序下发的第三渲染命令,该第三渲染命令用于将该应用程序运行过程中使用的第一数据存储在第二存储区域中,该第二存储区域是该电子设备的GPU使用的存储区域,该第一数据包括该第一模型的顶点坐标以及该第一MVP矩阵。该拦截模块将第三函数和第四函数传输给数据处理模块,该第三函数携带该第一参数,该第四函数携带该第二参数。该数据处理模块将该第三函数和该第四函数对应的数据存储在该第一存储区域中。基于该方案,提供了一种备份存储数据的机制。可以理解的是,在上述第一渲染命令(或者第二渲染命令)中,可以通过调用第三渲染命令已经加载到GPU的数据实现对应的渲染指示。该加载到GPU的数据对于其他模块是不可见的,因此,在本示例中,通过该备份存储机制,在CPU可调度的存储空间中备份存储加载的数据,从而保证在游戏运行过程中,各个模块在需要确定模型深度时,对该加载数据的顺利调用。In a possible design, before acquiring the first rendering command issued by the application, the method further includes: the interception module intercepts a third rendering command issued by the application, and the third rendering command is used to The first data used during the running of the application program is stored in the second storage area, the second storage area is the storage area used by the GPU of the electronic device, and the first data includes the vertex coordinates of the first model and the second storage area. An MVP matrix. The interception module transmits the third function and the fourth function to the data processing module, the third function carries the first parameter, and the fourth function carries the second parameter. The data processing module stores data corresponding to the third function and the fourth function in the first storage area. Based on the solution, a mechanism for backing up stored data is provided. It can be understood that, in the first rendering command (or the second rendering command), the corresponding rendering instruction can be implemented by invoking the data that has been loaded into the GPU by the third rendering command. The data loaded to the GPU is invisible to other modules. Therefore, in this example, through the backup storage mechanism, the loaded data is backed up and stored in the CPU schedulable storage space, thus ensuring that each A smooth call to the loaded data when the module needs to determine the depth of the model.
在一种可能的设计中,该方法还包括:该拦截模块将该第三渲染命令中,该第三函数和该第四函数之外的函数回调给该电子设备的图形库。基于该方案,提供了又一种回调机制。由此使得在加载过程中,电子设备可以对第三函数和第四函数之外的指令进行正确加载。In a possible design, the method further includes: the intercepting module calling back functions other than the third function and the fourth function in the third rendering command to a graphics library of the electronic device. Based on this solution, another callback mechanism is provided. Therefore, during the loading process, the electronic device can correctly load instructions other than the third function and the fourth function.
在一种可能的设计中,该方法还包括:该数据处理模块将该第三函数和该第四函数回调给该电子设备的图形库。基于该方案,提供了又一种回调机制。由此使得在加载过程中,电子设备可以对第三函数和第四函数进行正确加载。示例性的,该回调机制的执行可以是数据处理模块完成第三函数和第四函数的备份存储之后进行的。In a possible design, the method further includes: the data processing module calling back the third function and the fourth function to a graphics library of the electronic device. Based on this solution, another callback mechanism is provided. Therefore, during the loading process, the electronic device can correctly load the third function and the fourth function. Exemplarily, the execution of the callback mechanism may be performed after the data processing module completes backup storage of the third function and the fourth function.
在一种可能的设计中,该方法还包括:该数据处理模块存储第一对应关系,该第一对应关系用于指示相同数据在该第一存储区域的存储地址与在该第二存储区域的存储地址之间的对应关系。基于该方案,提供了一种数据正确调用的机制。可以理解的是,在备份存储的过程中,不能将数据存储在内存中为GPU配置的区域。在本示例中,可以通过存储备份存储的地址,与原生命令中指示的地址之间的对应关系,使得后续可以根据原生命令准确找到备份存储的对应的数据。In a possible design, the method further includes: the data processing module stores a first correspondence, and the first correspondence is used to indicate the storage address of the same data in the first storage area and the address of the same data in the second storage area. Correspondence between storage addresses. Based on the scheme, a mechanism for correct data calling is provided. It is understandable that during backup storage, data cannot be stored in the area of memory configured for the GPU. In this example, by storing the correspondence between the address of the backup storage and the address indicated in the native command, the corresponding data of the backup storage can be accurately found subsequently according to the native command.
在一种可能的设计中,该数据处理模块根据该第一函数和该第二函数,确定该第一模型对应的顶点坐标的第一存储位置,以及该第一MVP矩阵的第二存储位置,包括:该数据处理模块根据该第一函数指示的缓存位置,以及该第一对应关系,确定该第一模型对应的顶点坐标的第一存储位置。该数据处理模块根据该第二函数指示的缓存位置,以及该第一对应关系,确定该第一MVP矩阵的第二存储位置。基于该方案,提供了一种确定当前Drawcall对应顶点坐标和MVP矩阵的方案示例,比如,结合当前命令指示的缓存位置,以及对应关系,就可以在备份存储中找到对应的数据。该数据就可以是当前Drawcall所指示的第一模型的顶点坐标和MVP矩阵。In a possible design, the data processing module determines the first storage location of the vertex coordinates corresponding to the first model and the second storage location of the first MVP matrix according to the first function and the second function, The method includes: the data processing module determines the first storage location of the vertex coordinates corresponding to the first model according to the cache location indicated by the first function and the first corresponding relationship. The data processing module determines a second storage location of the first MVP matrix according to the cache location indicated by the second function and the first correspondence. Based on this solution, an example of a solution for determining the vertex coordinates and MVP matrix corresponding to the current Drawcall is provided. For example, in combination with the cache location indicated by the current command and the corresponding relationship, the corresponding data can be found in the backup storage. The data may be the vertex coordinates and the MVP matrix of the first model indicated by the current Drawcall.
在一种可能的设计中,该电子设备中还配置有计算模块,该根据该第一渲染命令,确定该第一模型的n个顶点的深度,包括:该拦截模块在拦截到该第一渲染命令中的绘制元素Drawelement的情况下,该计算模块根据该第一模型对应的顶点坐标,以及该第一MVP矩阵,计算该n个顶点的深度。其中,该第一模型对应的顶点数据是该计算模块从该第一存储位置获取的,该第一MVP矩阵是该计算模块从该第二存储位置获取的。基于该方案,提供了一种计算模型深度的触发机制。比如,可以在拦截到应用下发Drawelement的情况下,确定已经完成了顶点坐标,MVP矩阵等数据的指示,由此即可根据上述方案中确定的当前Drawcall指示的顶点坐标和MVP矩阵的存储位置,调取对应的数据进行计算。In a possible design, the electronic device is further equipped with a calculation module, and determining the depths of n vertices of the first model according to the first rendering command includes: the interception module intercepts the first rendering In the case of the drawing element Drawelement in the command, the calculation module calculates the depths of the n vertices according to the vertex coordinates corresponding to the first model and the first MVP matrix. Wherein, the vertex data corresponding to the first model is obtained by the calculation module from the first storage location, and the first MVP matrix is obtained by the calculation module from the second storage location. Based on this scheme, a trigger mechanism for computing model depth is provided. For example, it can be determined that the instruction of data such as vertex coordinates and MVP matrix has been completed when the Drawelement issued by the application is intercepted, so that the vertex coordinates indicated by the current Drawcall and the storage location of the MVP matrix determined in the above scheme can be determined. , call the corresponding data for calculation.
在一种可能的设计中,该根据该n个顶点的深度,确定该第一模型的深度,包括:该计算模块将该第一模型的深度确定为该n个顶点的深度的均值。基于该方案,提供了一种具体的根据顶点深度确定模型深度的方案示例。比如模型深度可以为选取的n个顶点深度的均值。In a possible design, the determining the depth of the first model according to the depths of the n vertices includes: the calculation module determining the depth of the first model as an average value of the depths of the n vertices. Based on this solution, a specific solution example for determining the depth of a model according to the depth of a vertex is provided. For example, the model depth may be the mean value of the depths of the selected n vertices.
在一种可能的设计中,该电子设备中还配置有决策模块,该方法还包括:该计算模块将该第一模型的深度传输给该决策模块。该决策模块根据该第一模型的深度,从预设的第二对应关系中,查找与该第一模型的深度匹配的表项。该决策模块将该匹配的表项指示的着色速率确定为该第一着色速率。基于该方案,提供了一种根据模型深度确定对应的着色速率的方案示例。例如,根据模型深度所处的预设的深度范围,可以在第二对应关系中,找到匹配的表项,该表象可以指示一个预设的着色速率。那么该预设的着色速率就可以是与当前模型的深度对应的第一着色速率。In a possible design, a decision module is further configured in the electronic device, and the method further includes: the calculation module transmits the depth of the first model to the decision module. According to the depth of the first model, the decision-making module searches for an entry matching the depth of the first model from the preset second correspondence. The decision module determines the shading rate indicated by the matching entry as the first shading rate. Based on this solution, an example of a solution for determining the corresponding shading rate according to the model depth is provided. For example, according to the preset depth range of the model depth, a matching entry can be found in the second correspondence, and the representation can indicate a preset shading rate. Then the preset shading rate may be the first shading rate corresponding to the depth of the current model.
在一种可能的设计中,该方法还包括:该决策模块向该图形库传输指示该第一着色速率的着色指令。基于该方案,提供了一种触发根据第一着色速率进行着色的方案机制。比如,在确定第一模型使用第一着色速率之后,决策模块可以调用图形库中与第一着色速率对应的API。在一些实现中,可以通过发送第一着色速率对应的着色指令实现该API的调用。In a possible design, the method further includes: the decision module transmits a shading instruction indicating the first shading rate to the graphics library. Based on this scheme, a scheme mechanism that triggers shading according to the first shading rate is provided. For example, after determining that the first model uses the first shading rate, the decision module may call an API corresponding to the first shading rate in the graphics library. In some implementations, calling the API may be implemented by sending a shading instruction corresponding to the first shading rate.
在一种可能的设计中,该根据该第一渲染命令和该第一着色速率绘制该第一模型,包括:该图形库根据该拦截模块和该数据处理模块回调的函数,调用与该第一渲染命令对应的第一应用编程接口API。该图形库根据该着色指令调用与该第一着色速率对应的第一可变速率着色API。该图形库根据该第一API以及该第一可变速率着色API,向该电子设备的GPU下发渲染指令,以便于该GPU根据该第一着色速率执行对该第一模型的渲染操作。基于该方案,提供了一种GPU对第一模型执行可变速率着色的方案机制。示例性的,基于前述回调机制,GPU可以收到第一渲染命令(第二渲染命令)的所有指示。此外,GPU还可以接收到根据第一着色速率调取的对应API所指示的指令。因此,GPU就可以实现根据第一着色速率对第一渲染命令所指示绘制的第一模型进行渲染操作。实现对绘制模型的着色速率的灵活调整。In a possible design, the rendering of the first model according to the first rendering command and the first shading rate includes: the graphics library calls the function corresponding to the first The first application programming interface API corresponding to the rendering command. The graphics library calls a first variable rate shading API corresponding to the first shading rate according to the shading instruction. The graphics library sends a rendering instruction to the GPU of the electronic device according to the first API and the first variable-rate shading API, so that the GPU performs a rendering operation on the first model according to the first shading rate. Based on the solution, a solution mechanism for GPU to perform variable rate shading on the first model is provided. Exemplarily, based on the aforementioned callback mechanism, the GPU may receive all instructions of the first rendering command (second rendering command). In addition, the GPU may also receive instructions indicated by corresponding APIs invoked according to the first shading rate. Therefore, the GPU can render the first model indicated by the first rendering command according to the first shading rate. Realize the flexible adjustment of the shading rate of the drawing model.
第二方面,提供一种电子设备,电子设备包括一个或多个处理器和一个或多个存储器;一个或多个存储器与一个或多个处理器耦合,一个或多个存储器存储有计算机指令;当一个或多个处理器执行计算机指令时,使得电子设备执行如上述第一方面以及各种可能的设计中任一种的图像渲染方法。In a second aspect, an electronic device is provided, and the electronic device includes one or more processors and one or more memories; the one or more memories are coupled to the one or more processors, and the one or more memories store computer instructions; When one or more processors execute computer instructions, the electronic device is made to execute the image rendering method according to the first aspect above and any one of various possible designs.
第三方面,本申请实施例提供一种图像渲染装置,该装置可以包括:处理器、存储器。存储器用于存储计算机可执行程序代码,程序代码包括指令。当处理器执行指令时,指令使电子设备执行如第一方面以及各种可能的设计中任一种的图像渲染方法。In a third aspect, the embodiment of the present application provides an image rendering apparatus, and the apparatus may include: a processor and a memory. The memory is used to store computer-executable program code, which includes instructions. When the processor executes the instructions, the instructions cause the electronic device to execute the image rendering method according to the first aspect and any one of various possible designs.
第四方面,提供一种计算机可读存储介质,计算机可读存储介质包括计算机指令,当计算机指令运行时,执行如上述第一方面以及各种可能的设计中任一种的图像渲染方法。In a fourth aspect, a computer-readable storage medium is provided, the computer-readable storage medium includes computer instructions, and when the computer instructions are run, the image rendering method in the above-mentioned first aspect and any one of various possible designs is executed.
应当理解的是,上述第二方面,第三方面,第四方面提供的技术方案,其技术特征均可对应到第一方面及其可能的设计中提供的图像渲染方法,因此能够达到的有益效果类似,此处不再赘述。It should be understood that the technical features of the technical solutions provided by the second aspect, the third aspect, and the fourth aspect can all correspond to the image rendering method provided in the first aspect and its possible design, so the beneficial effects that can be achieved Similar and will not be repeated here.
附图说明Description of drawings
图1为一种坐标空间的示意图;Fig. 1 is a schematic diagram of a coordinate space;
图2为一种可变速率着色的示意图;Fig. 2 is a schematic diagram of a variable rate shading;
图3为本申请实施例提供的一种电子设备的组成示意图;FIG. 3 is a schematic diagram of the composition of an electronic device provided in an embodiment of the present application;
图4为本申请实施例提供的一种电子设备的软件组成示意图;FIG. 4 is a schematic diagram of the software composition of an electronic device provided in an embodiment of the present application;
图5为本申请实施例提供的一种渲染过程的示意图;FIG. 5 is a schematic diagram of a rendering process provided by an embodiment of the present application;
图6为本申请实施例提供的一种图像渲染方法的流程示意图;FIG. 6 is a schematic flowchart of an image rendering method provided by an embodiment of the present application;
图7为本申请实施例提供的一种图像渲染方法的流程示意图;FIG. 7 is a schematic flowchart of an image rendering method provided by an embodiment of the present application;
图8为本申请实施例提供的一种图像渲染方法的流程示意图;FIG. 8 is a schematic flowchart of an image rendering method provided by an embodiment of the present application;
图9为本申请实施例提供的一种图像渲染方法的流程示意图;FIG. 9 is a schematic flowchart of an image rendering method provided by an embodiment of the present application;
图10为本申请实施例提供的一种图像渲染方法的流程示意图;FIG. 10 is a schematic flowchart of an image rendering method provided by an embodiment of the present application;
图11为本申请实施例提供的一种图像渲染方法的流程示意图;FIG. 11 is a schematic flowchart of an image rendering method provided by an embodiment of the present application;
图12为本申请实施例提供的一种图像渲染方法的流程示意图;FIG. 12 is a schematic flowchart of an image rendering method provided by an embodiment of the present application;
图13为本申请实施例提供的一种图像渲染结果的对比示意图;FIG. 13 is a schematic diagram of a comparison of image rendering results provided by the embodiment of the present application;
图14为本申请实施例提供的一种电子设备的组成示意图。FIG. 14 is a schematic composition diagram of an electronic device provided by an embodiment of the present application.
具体实施方式Detailed ways
电子设备可以根据其中安装的应用程序下发的渲染命令,进行不同帧图像的渲染,从而获取各个帧图像对应的显示数据,进而控制显示器根据这些显示数据实现各个帧图像的显示。The electronic device can render different frames of images according to the rendering commands issued by the installed application program, so as to obtain the display data corresponding to each frame of images, and then control the display to display each frame of images according to the display data.
在进行图像渲染的过程,电子设备需要确定当前帧图像中包括的一个或多个对象的顶点位置。During the image rendering process, the electronic device needs to determine the vertex positions of one or more objects included in the current frame image.
示例性的,应用程序下发的渲染命令中,可以包括对象的顶点坐标。在一些实现中,该渲染命令中包括的顶点坐标可以是基于对象自身的局部坐标系的坐标。在本申请中,对象基于局部坐标系的分布空间可以称为局部空间(Local Space)。电子设备为了能够确定对象在显示屏上各个顶点的坐标,可以基于局部空间中对象的坐标进行矩阵变换。由此获取对象在基于显示屏的空间(如称为屏幕空间(Screen Space))坐标系下的坐标。Exemplarily, the rendering command issued by the application may include the vertex coordinates of the object. In some implementations, the vertex coordinates included in the rendering command may be coordinates based on the object's own local coordinate system. In this application, the distribution space of objects based on the local coordinate system may be referred to as a local space (Local Space). In order to determine the coordinates of each vertex of the object on the display screen, the electronic device may perform matrix transformation based on the coordinates of the object in the local space. In this way, the coordinates of the object in the coordinate system based on the display screen space (such as called screen space (Screen Space)) are obtained.
作为一种示例,电子设备可以通过局部空间向世界空间(World Space)向观察空间(View Space)向裁剪空间(Clip Space)向屏幕空间(Screen Space)的矩阵变换处理,将对象的各个顶点在局部空间下的局部坐标转换为屏幕空间下的坐标。As an example, the electronic device can process each vertex of the object in Local coordinates in local space are converted to coordinates in screen space.
示例性的,参考图1,示出了一种坐标由局部空间向世界空间向观察空间向裁剪空间的矩阵变换的逻辑过程示意。在本示例中,应用程序下发的渲染命令中,可以包括对物体1的渲染。如图1所示,在局部空间中,坐标系可以是基于物体1的。比如,局部空间中的坐标系原点可以是设置在物体1的中心,或者一个顶点所在的位置等。应用程序可以在下发对物体1的渲染命令中,携带该局部空间的坐标系下,物体1的各个顶点的坐标,即局部坐标。电子设备可以通过应用程序下发的M矩阵,将局部空间中的坐标转换为世界空间中的坐标。其中,世界空间可以是相对于局部空间更大的区域。比如,以应用程序下发的渲染命令用于进行游戏图像的渲染为例。局部空间可以对应能够覆盖某一个对象(如物体1)的较小区域。而世界空间可以对应游戏中,包括物体1以及其他物体(如物体2)的一张地图的区域。电子设备可以将局部空间中的局部坐标,结合M矩阵进行M矩阵变换,从而获取物体1在世界空间中的坐标。类似的,在应用程序下发了在该帧图像中的对物体2的渲染命令的情况下,通过上述M矩阵变换,电子设备还可以获取物体2在世界空间中的坐标。Exemplarily, referring to FIG. 1 , it shows a logical process of matrix transformation of coordinates from local space to world space to observation space to clipping space. In this example, the rendering command issued by the application may include the rendering of object 1. As shown in FIG. 1 , in local space, the coordinate system may be based on an object 1 . For example, the origin of the coordinate system in the local space may be set at the center of the object 1, or where a vertex is located, and so on. The application program may carry the coordinates of each vertex of the object 1 in the coordinate system of the local space, that is, the local coordinates, in the rendering command issued to the object 1 . The electronic device can convert the coordinates in the local space to the coordinates in the world space through the M matrix issued by the application program. Wherein, the world space may be a larger area than the local space. For example, take a rendering command issued by an application program for rendering a game image as an example. The local space may correspond to a smaller area that can cover a certain object (such as object 1). The world space may correspond to an area of a map including object 1 and other objects (such as object 2) in the game. The electronic device can combine the local coordinates in the local space with the M matrix to perform M matrix transformation, so as to obtain the coordinates of the object 1 in the world space. Similarly, when the application program issues a rendering command for the object 2 in the image frame, the electronic device can also obtain the coordinates of the object 2 in the world space through the above-mentioned M matrix transformation.
在获取当前帧图像中,各个物体的顶点在世界空间中的坐标之后,电子设备可以根据应用程序下发的V矩阵,将世界空间中的坐标,转换为观察空间中的坐标。可以理解的是,世界空间中的坐标可以是三维空间中的坐标。而电子设备在向用户展示帧图像时,各个对象(如物体1,物体2等)则是在二维的显示屏上进行显示的。在使用不同的观察角度观察世界空间中的对象时,则会看到不同的二维画面。该观察角度可以是与在世界空间中设置的摄像机(或者观察者)的位置相关的。在本示例中,与摄像机位置对应的坐标空间可以称为观察空间。示例性的,以摄像机设置在世界空间中的y轴正方向为例。那么基于V矩阵的变换,就可以获取在该摄像机位置对应的观察空间中,物体1和物体2的各个顶点的坐标。如图1所示,由于摄像机位于y轴正方向,向下进行拍摄,因此对应在观察空间中的物体1和物体2可以呈现为俯视效果。After acquiring the coordinates of vertices of each object in the world space in the current frame image, the electronic device can convert the coordinates in the world space into coordinates in the observation space according to the V matrix issued by the application program. It can be understood that the coordinates in world space may be coordinates in three-dimensional space. When the electronic device displays frame images to the user, various objects (such as object 1, object 2, etc.) are displayed on a two-dimensional display screen. When observing objects in world space with different viewing angles, you will see different two-dimensional pictures. The viewing angle may be relative to the position of the camera (or observer) set in world space. In this example, the coordinate space corresponding to the camera position may be referred to as the viewing space. As an example, take the camera set in the positive direction of the y-axis in the world space as an example. Then based on the transformation of the V matrix, the coordinates of the vertices of the object 1 and object 2 in the observation space corresponding to the camera position can be obtained. As shown in FIG. 1 , since the camera is located in the positive direction of the y-axis and shoots downwards, the objects 1 and 2 corresponding to the observation space can be presented as a top view effect.
在电子设备获取观察空间中的各个对象的坐标后,可以将其投影到裁剪坐标。该裁剪坐标对应的坐标空间可以称为裁剪空间。可以理解的是,在进行V矩阵变换过程中,可以是对世界空间中的较大区域的变换,因此获取的图像范围可能是比较大的。而由于电子设备显示屏的尺寸有限,因此可能无法将该观察空间中的所有对象同时进行显示。在本示例中,电子设备就可以将观察空间中的各个对象的坐标,投影到裁剪空间中。在投影到裁剪空间中后,能够显示在显示屏上的对象的坐标可以在-1.0到1.0的范围内。而对于无法显示在显示屏上的部分对象的坐标,则可以在-1.0到1.0的范围之外。这样,电子设备就可以根据坐标在-1.0到1.0范围内的顶点坐标进行对应的显示。示例性的,电子设备可以根据应用程序下发的P矩阵,对观察空间中的各个坐标进行P矩阵变换,从而获取各个坐标对应的在裁剪空间中的裁剪坐标。After the electronic device acquires the coordinates of each object in the viewing space, it can project them to the clipping coordinates. The coordinate space corresponding to the clipping coordinates may be called clipping space. It can be understood that, in the process of performing the V matrix transformation, it may be a transformation of a larger area in the world space, so the acquired image range may be relatively large. However, due to the limited size of the display screen of the electronic device, it may not be possible to display all objects in the observation space at the same time. In this example, the electronic device can project the coordinates of each object in the observation space into the clipping space. After projection into clip space, the coordinates of objects that can be displayed on the display can be in the range of -1.0 to 1.0. And for the coordinates of some objects that cannot be displayed on the display screen, they can be outside the range of -1.0 to 1.0. In this way, the electronic device can perform corresponding display according to the vertex coordinates whose coordinates are within the range of -1.0 to 1.0. Exemplarily, the electronic device may perform P-matrix transformation on each coordinate in the viewing space according to the P-matrix issued by the application program, so as to obtain the clipping coordinates corresponding to each coordinate in the clipping space.
可以理解的是,通过上述MVP矩阵的变换(即M矩阵变换,V矩阵变换,以及P矩阵变换),电子设备就能够获取在显示屏上显示的各个对象的顶点的坐标(即裁剪坐标)。接着,电子设备还可以将裁剪坐标变换为屏幕坐标,比如,使用视口变换(Viewport Transform)将位于-1.0到1.0范围的坐标变换到由glViewport函数所定义的坐标范围内。最后变换出来的坐标将会送到光栅器,将其转化为片段,进而获取与各个像素对应的显示数据。基于这些显示数据,电子设备就可以控制显示屏进行对应的显示。It can be understood that, through the transformation of the above MVP matrix (ie M matrix transformation, V matrix transformation, and P matrix transformation), the electronic device can obtain the coordinates (ie clipping coordinates) of the vertices of each object displayed on the display screen. Next, the electronic device can also transform the clipping coordinates into screen coordinates, for example, use a viewport transform (Viewport Transform) to transform the coordinates in the range of -1.0 to 1.0 into the coordinate range defined by the glViewport function. The final transformed coordinates will be sent to the rasterizer, which will be converted into fragments, and then the display data corresponding to each pixel will be obtained. Based on these display data, the electronic device can control the display screen to perform corresponding display.
电子设备在进行图像的渲染过程中,除了需要根据上述方案确定各个对象的顶点坐标之外,还需要对当前帧图像中的各个像素进行着色,即确定各个像素的颜色数据。从而根据各个像素的颜色数据,控制显示器在对应的像素位置进行对应颜色的显示。In the image rendering process of the electronic device, in addition to determining the vertex coordinates of each object according to the above scheme, it is also necessary to color each pixel in the current frame image, that is, determine the color data of each pixel. Therefore, according to the color data of each pixel, the display is controlled to display the corresponding color at the corresponding pixel position.
在一些实现中,电子设备可以在渲染过程中,以一个像素为单位,对每个像素进行着色,从而实现对整个帧图像的着色。随着电子设备显示屏的分辨率以及刷新率的提升,加上需要渲染的帧图像的场景越来越复杂,基于一个像素的着色会对电子设备的渲染过程造成较大的内存和功耗的开销,进而出现发热或者掉帧现象,影响用户体验。需要说明的是,在本申请的一些实现中,渲染过程以及着色的过程,可以是由电子设备中设置的GPU等具有图形处理功能的部件实现的。In some implementations, the electronic device may color each pixel in units of one pixel during the rendering process, so as to achieve coloring of the entire frame image. With the improvement of the resolution and refresh rate of the display screen of the electronic device, and the scene of the frame image that needs to be rendered becomes more and more complex, the coloring based on one pixel will cause a large memory and power consumption in the rendering process of the electronic device. Overhead, resulting in heat generation or frame drop phenomenon, affecting user experience. It should be noted that, in some implementations of the present application, the rendering process and the coloring process may be implemented by components with graphics processing functions such as a GPU set in the electronic device.
为了应对上述问题,一些电子设备可以通过提供可变速率着色的功能,降低着色过程中对内存和功耗的开销。In order to deal with the above problems, some electronic devices can reduce memory and power consumption overhead during the coloring process by providing a variable rate coloring function.
示例性的,在一般的着色机制下,电子设备可以分别使用着色器,对一个像素进行着色。完成该像素的着色操作之后,电子设备可以使用着色器,对另一个像素进行着色。比如,结合图2中的(a),电子设备可以使用着色器,对位于第一行第一列的像素进行着色。完成该第一行第一列的像素的着色之后,电子设备可以使用着色器,对其他像素,如第一行第二列的像素进行着色。这样,要完成如图2中的(a)所示的5*5的像素的着色,电子设备就需要使用着色器进行至少25次着色操作。需要说明的是,结合前述说明,上述通过着色器进行着色的过程可以是电子设备中的GPU执行的。在GPU具有较强的并行处理能力时,比如GPU可以同时通过着色器对3个像素分别进行着色,那么电子设备也可以通过着色器并行地实现多个像素(如3个像素)的着色操作。然而多发并行处理的过程虽然能够节省处理时间,但是并不会减少电子设备在进行着色操作的过程中的负荷。为了便于说明,以下以电子设备中的GPU同一时刻使用着色器对1个像素进行着色为例进行说明。Exemplarily, under a general coloring mechanism, an electronic device may use a shader to color a pixel. After the pixel is shaded, the electronic device can use the shader to shade another pixel. For example, in combination with (a) in FIG. 2 , the electronic device can use a shader to color the pixels located in the first row and the first column. After the coloring of the pixels in the first row and the first column is completed, the electronic device may use a shader to color other pixels, such as the pixels in the first row and the second column. In this way, to complete the shading of 5*5 pixels as shown in (a) in FIG. 2 , the electronic device needs to use the shader to perform at least 25 shading operations. It should be noted that, with reference to the foregoing description, the above-mentioned process of performing coloring through a shader may be executed by a GPU in an electronic device. When the GPU has a strong parallel processing capability, for example, the GPU can simultaneously color three pixels through the shader, and then the electronic device can also implement the coloring operation of multiple pixels (such as three pixels) in parallel through the shader. However, although the multi-issue parallel processing process can save processing time, it will not reduce the load of the electronic device during the coloring operation. For the convenience of description, the GPU in the electronic device uses a shader to color one pixel at the same time as an example.
与以单个像素为单位进行着色操作相对的,在电子设备使用可变速率着色功能的情况下,电子设备可以使用着色器,通过一次着色操作完成对多个像素的着色。比如,以一次着色操作可以完成对4个像素的着色为例。结合图2中的(b),电子设备可以通过一次着色操作,实现对第一列第一个像素到第二列第二个像素的着色。这样,通过可变速率着色,电子设备就可以通过更少的着色操作,完成在对图像渲染过程中的着色。As opposed to performing a shading operation in units of a single pixel, when the electronic device uses a variable-rate shading function, the electronic device can use a shader to complete the shading of multiple pixels through a single shading operation. For example, take a coloring operation that can complete the coloring of 4 pixels as an example. In combination with (b) in FIG. 2 , the electronic device can color the first pixel in the first column to the second pixel in the second column through one coloring operation. In this way, through variable rate shading, the electronic device can complete the shading in the image rendering process with fewer shading operations.
可以理解的是,可变速率着色后的像素组成的图像的颜色精细度会低于一般的着色机制(即以一个像素为粒度的着色操作)获取的像素组成的图像。那么,如何合理地使用可变速率着色,同时不会使得用户对图像的观感产生明显的影响,就成为了可变速率着色功能使用的关键。It can be understood that the color fineness of the image composed of pixels after variable rate shading is lower than that of an image composed of pixels obtained by a general shading mechanism (ie, a shading operation with a granularity of one pixel). Then, how to reasonably use variable rate shading without significantly affecting the user's perception of the image becomes the key to using the variable rate shading function.
为了解决上述问题,本申请实施例提供的渲染方案,能够合理地选取帧图像中需要使用可变速率着色功能的区域,使得电子设备可以通过可变速率着色功能降低渲染过程中的功耗和发热的同时,渲染获取的图像不会对用户的观感产生明显的影响。由此即可在降低电子设备的功耗和发热的同时,提升用户体验。In order to solve the above problems, the rendering solution provided by the embodiment of the present application can reasonably select the area in the frame image that needs to use the variable rate shading function, so that the electronic device can reduce the power consumption and heat generation in the rendering process through the variable rate shading function At the same time, rendering the acquired image will not have a significant impact on the user's perception. In this way, the user experience can be improved while reducing the power consumption and heat generation of the electronic device.
以下结合附图对本申请实施例提供的方案进行详细说明。The solutions provided by the embodiments of the present application will be described in detail below in conjunction with the accompanying drawings.
需要说明的是,本申请实施例提供的渲染方法,可以应用在用户的电子设备中。比如,该电子设备可以是手机、平板电脑、个人数字助理(personal digital assistant,PDA)、增强现实(augmented reality,AR)\虚拟现实(virtual reality,VR)设备、媒体播放器等便携式移动设备,该电子设备也可以是智能手表等能够提供拍摄能力的可穿戴电子设备。本申请实施例对该设备的具体形态不作特殊限制。It should be noted that the rendering method provided in the embodiment of the present application may be applied in a user's electronic device. For example, the electronic device may be a portable mobile device such as a mobile phone, a tablet computer, a personal digital assistant (personal digital assistant, PDA), an augmented reality (augmented reality, AR)/virtual reality (virtual reality, VR) device, a media player, etc. The electronic device may also be a wearable electronic device capable of providing shooting capabilities, such as a smart watch. The embodiment of the present application does not specifically limit the specific form of the device.
请参考图3,为本申请实施例提供的一种电子设备300的结构示意图。Please refer to FIG. 3 , which is a schematic structural diagram of an electronic device 300 provided in an embodiment of the present application.
如图3所示,该电子设备300可以包括处理器310,外部存储器接口320,内部存储器321,通用串行总线(universal serial bus,USB)接口330,充电管理模块340,电源管理模块341,电池342,天线1,天线2,移动通信模块350,无线通信模块360,音频模块370,扬声器370A,受话器370B,麦克风370C,耳机接口370D,传感器模块380,按键390,马达391,指示器392,摄像头393,显示屏394,以及用户标识模块(subscriber identification module,SIM)卡接口395等。其中,传感器模块380可以包括压力传感器,陀螺仪传感器,气压传感器,磁传感器,加速度传感器,距离传感器,接近光传感器,指纹传感器,温度传感器,触摸传感器,环境光传感器,骨传导传感器等。As shown in Figure 3, the electronic device 300 may include a processor 310, an external memory interface 320, an internal memory 321, a universal serial bus (universal serial bus, USB) interface 330, a charging management module 340, a power management module 341, a battery 342, antenna 1, antenna 2, mobile communication module 350, wireless communication module 360, audio module 370, speaker 370A, receiver 370B, microphone 370C, earphone jack 370D, sensor module 380, button 390, motor 391, indicator 392, camera 393, a display screen 394, and a subscriber identification module (subscriber identification module, SIM) card interface 395, etc. Wherein, the sensor module 380 may include a pressure sensor, a gyroscope sensor, an air pressure sensor, a magnetic sensor, an acceleration sensor, a distance sensor, a proximity light sensor, a fingerprint sensor, a temperature sensor, a touch sensor, an ambient light sensor, a bone conduction sensor, and the like.
可以理解的是,本实施例示意的结构并不构成对电子设备300的具体限定。在另一些实施例中,电子设备300可以包括比图示更多或更少的部件,或者组合某些部件,或者拆分某些部件,或者不同的部件布置。图示的部件可以以硬件,软件或软件和硬件的组合实现。It can be understood that the structure shown in this embodiment does not constitute a specific limitation on the electronic device 300 . In other embodiments, the electronic device 300 may include more or fewer components than shown, or combine certain components, or separate certain components, or arrange different components. The illustrated components can be realized in hardware, software or a combination of software and hardware.
处理器310可以包括一个或多个处理单元,例如:处理器310可以包括中央处理器(Central Processing Unit,CPU),应用处理器(application processor,AP),调制解调处理器,GPU,图像信号处理器(image signal processor,ISP),控制器,存储器,视频编解码器,数字信号处理器(digital signal processor,DSP),基带处理器,和/或神经网络处理器(neural-network processing unit,NPU)等。其中,不同的处理单元可以是独立的器件,也可以集成在一个或多个处理器310中。作为一种示例,在本申请中,ISP可以对图像进行处理,如该处理可以包括自动曝光(Automatic Exposure)、自动对焦(Automatic Focus)、自动白平衡(Automatic White Balance)、去噪、背光补偿、色彩增强等处理。其中,自动曝光,自动对焦,以及自动白平衡的处理也可以称为3A处理。经过处理后,ISP就可以进行获取对应的照片。该过程也可称为ISP的成片操作。The processor 310 may include one or more processing units, for example: the processor 310 may include a central processing unit (Central Processing Unit, CPU), an application processor (application processor, AP), a modem processor, a GPU, an image signal processor (image signal processor, ISP), controller, memory, video codec, digital signal processor (digital signal processor, DSP), baseband processor, and/or neural network processor (neural-network processing unit, NPU) and so on. Wherein, different processing units may be independent devices, or may be integrated in one or more processors 310 . As an example, in this application, the ISP can process the image, such as the processing can include automatic exposure (Automatic Exposure), automatic focus (Automatic Focus), automatic white balance (Automatic White Balance), denoising, backlight compensation , color enhancement and other processing. Among them, the processing of automatic exposure, automatic focus, and automatic white balance can also be called 3A processing. After processing, the ISP can obtain the corresponding photos. This process may also be referred to as the slice operation of the ISP.
在一些实施例中,处理器310可以包括一个或多个接口。接口可以包括集成电路(inter-integrated circuit,I2C)接口,集成电路内置音频(inter-integrated circuitsound,I2S)接口,脉冲编码调制(pulse code modulation,PCM)接口,通用异步收发传输器(universal asynchronous receiver/transmitter,UART)接口,移动产业处理器接口(mobile industry processor interface,MIPI),通用输入输出(general-purposeinput/output,GPIO)接口,用户标识模块(subscriber identity module,SIM)接口,和/或通用串行总线(universal serial bus,USB)接口等。In some embodiments, processor 310 may include one or more interfaces. The interface may include an integrated circuit (inter-integrated circuit, I2C) interface, an integrated circuit built-in audio (inter-integrated circuitsound, I2S) interface, a pulse code modulation (pulse code modulation, PCM) interface, a universal asynchronous receiver (universal asynchronous receiver) /transmitter, UART) interface, mobile industry processor interface (mobile industry processor interface, MIPI), general-purpose input and output (general-purpose input/output, GPIO) interface, subscriber identity module (subscriber identity module, SIM) interface, and/or A universal serial bus (universal serial bus, USB) interface, etc.
电子设备300可以通过ISP,摄像头393,视频编解码器,GPU,显示屏394以及应用处理器等实现拍摄功能。The electronic device 300 can realize the shooting function through an ISP, a camera 393 , a video codec, a GPU, a display screen 394 , and an application processor.
ISP用于处理摄像头393反馈的数据。例如,拍照时,打开快门,光线通过镜头被传递到摄像头393感光元件上,光信号转换为电信号,摄像头393感光元件将所述电信号传递给ISP处理,转化为肉眼可见的图像。ISP还可以对图像的噪点,亮度,肤色进行算法优化。ISP还可以对拍摄场景的曝光,色温等参数优化。在一些实施例中,ISP可以设置在摄像头393中。The ISP is used for processing the data fed back by the camera 393 . For example, when taking a picture, open the shutter, the light is transmitted to the photosensitive element of the camera 393 through the lens, and the light signal is converted into an electrical signal, and the photosensitive element of the camera 393 transmits the electrical signal to the ISP for processing, and converts it into an image visible to the naked eye. ISP can also perform algorithm optimization on image noise, brightness, and skin color. ISP can also optimize the exposure, color temperature and other parameters of the shooting scene. In some embodiments, the ISP may be located in the camera 393 .
摄像头393用于捕获静态图像或视频。物体通过镜头生成光学图像投射到感光元件。感光元件可以是电荷耦合器件(charge coupled device,CCD)或互补金属氧化物半导体(complementary metal-oxide-semiconductor,CMOS)光电晶体管。感光元件把光信号转换成电信号,之后将电信号传递给ISP转换成数字图像信号。ISP将数字图像信号输出到DSP加工处理。DSP将数字图像信号转换成标准的RGB,YUV等格式的图像信号。在一些实施例中,电子设备300可以包括1个或N个摄像头393,N为大于1的正整数。Camera 393 is used to capture still images or video. The object generates an optical image through the lens and projects it to the photosensitive element. The photosensitive element may be a charge coupled device (charge coupled device, CCD) or a complementary metal-oxide-semiconductor (complementary metal-oxide-semiconductor, CMOS) phototransistor. The photosensitive element converts the light signal into an electrical signal, and then transmits the electrical signal to the ISP to convert it into a digital image signal. The ISP outputs the digital image signal to the DSP for processing. DSP converts digital image signals into standard RGB, YUV and other image signals. In some embodiments, the electronic device 300 may include 1 or N cameras 393, where N is a positive integer greater than 1.
数字信号处理器用于处理数字信号,除了可以处理数字图像信号,还可以处理其他数字信号。例如,当电子设备300在频点选择时,数字信号处理器用于对频点能量进行傅里叶变换等。Digital signal processors are used to process digital signals. In addition to digital image signals, they can also process other digital signals. For example, when the electronic device 300 selects a frequency point, the digital signal processor is used to perform Fourier transform on the energy of the frequency point.
视频编解码器用于对数字视频压缩或解压缩。电子设备300可以支持一种或多种视频编解码器。这样,电子设备300可以播放或录制多种编码格式的视频,例如:动态图像专家组(moving picture experts group,MPEG)1,MPEG2,MPEG3,MPEG4等。Video codecs are used to compress or decompress digital video. The electronic device 300 may support one or more video codecs. In this way, the electronic device 300 can play or record videos in various encoding formats, for example: moving picture experts group (moving picture experts group, MPEG) 1, MPEG2, MPEG3, MPEG4 and so on.
NPU为神经网络(neural-network,NN)计算处理器,通过借鉴生物神经网络结构,例如借鉴人脑神经元之间传递模式,对输入信息快速处理,还可以不断的自学习。通过NPU可以实现电子设备300的智能认知等应用,例如:图像识别,人脸识别,语音识别,文本理解等。The NPU is a neural-network (NN) computing processor. By referring to the structure of biological neural networks, such as the transfer mode between neurons in the human brain, it can quickly process input information and continuously learn by itself. Applications such as intelligent cognition of the electronic device 300 can be realized through the NPU, such as image recognition, face recognition, speech recognition, text understanding, and the like.
充电管理模块340用于从充电器接收充电输入。其中,充电器可以是无线充电器,也可以是有线充电器。在一些有线充电的实施例中,充电管理模块340可以通过USB接口330接收有线充电器的充电输入。在一些无线充电的实施例中,充电管理模块340可以通过电子设备300的无线充电线圈接收无线充电输入。充电管理模块340为电池342充电的同时,还可以通过电源管理模块341为电子设备300供电。The charging management module 340 is configured to receive charging input from the charger. Wherein, the charger may be a wireless charger or a wired charger. In some wired charging embodiments, the charging management module 340 can receive charging input from a wired charger through the USB interface 330 . In some wireless charging embodiments, the charging management module 340 may receive wireless charging input through a wireless charging coil of the electronic device 300 . While the charging management module 340 is charging the battery 342 , it can also supply power to the electronic device 300 through the power management module 341 .
电源管理模块341用于连接电池342,充电管理模块340与处理器310。电源管理模块341接收电池342和/或充电管理模块340的输入,为处理器310,内部存储器321,外部存储器,显示屏394,摄像头393,和无线通信模块360等供电。电源管理模块341还可以用于监测电池342容量,电池342循环次数,电池342健康状态(漏电,阻抗)等参数。在其他一些实施例中,电源管理模块341也可以设置于处理器310中。在另一些实施例中,电源管理模块341和充电管理模块340也可以设置于同一个器件中。The power management module 341 is used for connecting the battery 342 , the charging management module 340 and the processor 310 . The power management module 341 receives the input of the battery 342 and/or the charging management module 340, and supplies power for the processor 310, the internal memory 321, the external memory, the display screen 394, the camera 393, and the wireless communication module 360, etc. The power management module 341 can also be used to monitor parameters such as the capacity of the battery 342 , the number of cycles of the battery 342 , and the state of health of the battery 342 (leakage, impedance). In some other embodiments, the power management module 341 may also be disposed in the processor 310 . In some other embodiments, the power management module 341 and the charging management module 340 may also be set in the same device.
电子设备300的无线通信功能可以通过天线1,天线2,移动通信模块350,无线通信模块360,调制解调处理器310以及基带处理器310等实现。The wireless communication function of the electronic device 300 can be realized by the antenna 1 , the antenna 2 , the mobile communication module 350 , the wireless communication module 360 , the modem processor 310 and the baseband processor 310 .
天线1和天线2用于发射和接收电磁波信号。电子设备300中的每个天线可用于覆盖单个或多个通信频带。不同的天线还可以复用,以提高天线的利用率。例如:可以将天线1复用为无线局域网的分集天线。在另外一些实施例中,天线可以和调谐开关结合使用。Antenna 1 and Antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in electronic device 300 may be used to cover single or multiple communication frequency bands. Different antennas can also be multiplexed to improve the utilization of the antennas. For example: Antenna 1 can be multiplexed as a diversity antenna of a wireless local area network. In other embodiments, the antenna may be used in conjunction with a tuning switch.
移动通信模块350可以提供应用在电子设备300上的包括2G/3G/4G/5G等无线通信的解决方案。移动通信模块350可以包括至少一个滤波器,开关,功率放大器,低噪声放大器(low noise amplifier,LNA)等。移动通信模块350可以由天线1接收电磁波,并对接收的电磁波进行滤波,放大等处理,传送至调制解调处理器进行解调。移动通信模块350还可以对经调制解调处理器调制后的信号放大,经天线1转为电磁波辐射出去。在一些实施例中,移动通信模块350的至少部分功能模块可以被设置于处理器310中。在一些实施例中,移动通信模块350的至少部分功能模块可以与处理器310的至少部分模块被设置在同一个器件中。The mobile communication module 350 can provide wireless communication solutions including 2G/3G/4G/5G applied on the electronic device 300 . The mobile communication module 350 may include at least one filter, switch, power amplifier, low noise amplifier (low noise amplifier, LNA) and the like. The mobile communication module 350 can receive electromagnetic waves through the antenna 1, filter and amplify the received electromagnetic waves, and send them to the modem processor for demodulation. The mobile communication module 350 can also amplify the signal modulated by the modem processor, convert it into electromagnetic wave and radiate it through the antenna 1 . In some embodiments, at least part of the functional modules of the mobile communication module 350 may be set in the processor 310 . In some embodiments, at least part of the functional modules of the mobile communication module 350 and at least part of the modules of the processor 310 may be set in the same device.
调制解调处理器可以包括调制器和解调器。其中,调制器用于将待发送的低频基带信号调制成中高频信号。解调器用于将接收的电磁波信号解调为低频基带信号。随后解调器将解调得到的低频基带信号传送至基带处理器处理。低频基带信号经基带处理器处理后,被传递给应用处理器。应用处理器通过音频设备(不限于扬声器370A,受话器370B等)输出声音信号,或通过显示屏394显示图像或视频。在一些实施例中,调制解调处理器可以是独立的器件。在另一些实施例中,调制解调处理器可以独立于处理器310,与移动通信模块350或其他功能模块设置在同一个器件中。A modem processor may include a modulator and a demodulator. Wherein, the modulator is used for modulating the low-frequency baseband signal to be transmitted into a medium-high frequency signal. The demodulator is used to demodulate the received electromagnetic wave signal into a low frequency baseband signal. Then the demodulator sends the demodulated low-frequency baseband signal to the baseband processor for processing. The low-frequency baseband signal is passed to the application processor after being processed by the baseband processor. The application processor outputs sound signals through audio equipment (not limited to speaker 370A, receiver 370B, etc.), or displays images or videos through display screen 394 . In some embodiments, the modem processor may be a stand-alone device. In some other embodiments, the modem processor may be independent from the processor 310, and be set in the same device as the mobile communication module 350 or other functional modules.
无线通信模块360可以提供应用在电子设备300上的包括无线局域网(wirelesslocal area networks,WLAN)(如无线保真(wireless fidelity,Wi-Fi)网络),蓝牙(bluetooth,BT),全球导航卫星系统(global navigation satellite system,GNSS),调频(frequency modulation,FM),近距离无线通信技术(near field communication,NFC),红外技术(infrared,IR)等无线通信的解决方案。无线通信模块360可以是集成至少一个通信处理模块的一个或多个器件。无线通信模块360经由天线2接收电磁波,将电磁波信号调频以及滤波处理,将处理后的信号发送到处理器310。无线通信模块360还可以从处理器310接收待发送的信号,对其进行调频,放大,经天线2转为电磁波辐射出去。The wireless communication module 360 can provide applications on the electronic device 300 including wireless local area networks (wireless local area networks, WLAN) (such as wireless fidelity (wireless fidelity, Wi-Fi) network), bluetooth (bluetooth, BT), global navigation satellite system (global navigation satellite system, GNSS), frequency modulation (frequency modulation, FM), near field communication technology (near field communication, NFC), infrared technology (infrared, IR) and other wireless communication solutions. The wireless communication module 360 may be one or more devices integrating at least one communication processing module. The wireless communication module 360 receives electromagnetic waves via the antenna 2 , frequency-modulates and filters the electromagnetic wave signals, and sends the processed signals to the processor 310 . The wireless communication module 360 can also receive the signal to be sent from the processor 310 , frequency-modulate it, amplify it, and convert it into electromagnetic waves through the antenna 2 for radiation.
在一些实施例中,电子设备300的天线1和移动通信模块350耦合,天线2和无线通信模块360耦合,使得电子设备300可以通过无线通信技术与网络以及其他设备通信。所述无线通信技术可以包括全球移动通讯系统(global system for mobile communications,GSM),通用分组无线服务(general packet radio service,GPRS),码分多址接入(codedivision multiple access,CDMA),宽带码分多址(wideband code division multipleaccess,WCDMA),时分码分多址(time-division code division multiple access,TD-SCDMA),长期演进(long term evolution,LTE),BT,GNSS,WLAN,NFC,FM,和/或IR技术等。所述GNSS可以包括全球卫星定位系统(global positioning system,GPS),全球导航卫星系统(global navigation satellite system,GLONASS),北斗卫星导航系统(beidounavigation satellite system,BDS),准天顶卫星系统(quasi-zenith satellitesystem,QZSS)和/或星基增强系统(satellite based augmentation systems,SBAS)。In some embodiments, the antenna 1 of the electronic device 300 is coupled to the mobile communication module 350, and the antenna 2 is coupled to the wireless communication module 360, so that the electronic device 300 can communicate with the network and other devices through wireless communication technology. The wireless communication technology may include global system for mobile communications (GSM), general packet radio service (general packet radio service, GPRS), code division multiple access (codedivision multiple access, CDMA), wideband code Wideband code division multiple access (WCDMA), time-division code division multiple access (TD-SCDMA), long term evolution (LTE), BT, GNSS, WLAN, NFC, FM , and/or IR technology, etc. The GNSS may include a global positioning system (global positioning system, GPS), a global navigation satellite system (global navigation satellite system, GLONASS), a Beidou satellite navigation system (beidounavigation satellite system, BDS), a quasi-zenith satellite system (quasi- zenith satellite system (QZSS) and/or satellite based augmentation systems (SBAS).
电子设备300通过GPU,显示屏394,以及应用处理器310等实现显示功能。GPU为图像处理的微处理器,连接显示屏394和应用处理器。GPU用于执行数学和几何计算,用于图形渲染。处理器310可包括一个或多个GPU,其执行程序指令以生成或改变显示信息。The electronic device 300 implements a display function through a GPU, a display screen 394 , and an application processor 310 . The GPU is a microprocessor for image processing, connected to the display screen 394 and the application processor. GPUs are used to perform mathematical and geometric calculations for graphics rendering. Processor 310 may include one or more GPUs that execute program instructions to generate or alter display information.
显示屏394用于显示图像,视频等。显示屏394包括显示面板。显示面板可以采用液晶显示屏394(liquid crystal display,LCD),有机发光二极管(organic light-emittingdiode,OLED),有源矩阵有机发光二极体或主动矩阵有机发光二极体(active-matrixorganic light emitting diode,AMOLED),柔性发光二极管(flex light-emittingdiode,FLED),Miniled,MicroLed,Micro-oLed,量子点发光二极管(quantum dot lightemitting diodes,QLED)等。在一些实施例中,电子设备300可以包括1个或N个显示屏394,N为大于1的正整数。The display screen 394 is used to display images, videos and the like. Display 394 includes a display panel. The display panel can be a liquid crystal display 394 (liquid crystal display, LCD), an organic light-emitting diode (organic light-emitting diode, OLED), an active matrix organic light-emitting diode or an active-matrix organic light emitting diode (active-matrix organic light emitting diode). diode, AMOLED), flexible light-emitting diode (flex light-emitting diode, FLED), Miniled, MicroLed, Micro-oLed, quantum dot light-emitting diodes (quantum dot light emitting diodes, QLED), etc. In some embodiments, the electronic device 300 may include 1 or N display screens 394, where N is a positive integer greater than 1.
外部存储器接口320可以用于连接外部存储卡,例如Micro SD卡,实现扩展电子设备300的存储能力。外部存储卡通过外部存储器接口320与处理器310通信,实现数据存储功能。例如将音乐,视频等文件保存在外部存储卡中。The external memory interface 320 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 300 . The external memory card communicates with the processor 310 through the external memory interface 320 to implement a data storage function. Such as saving music, video and other files in the external memory card.
内部存储器321可以用于存储计算机可执行程序代码,所述可执行程序代码包括指令。处理器310通过运行存储在内部存储器321的指令,从而执行电子设备300的各种功能应用以及数据处理。内部存储器321可以包括存储程序区和存储数据区。其中,存储程序区可存储操作系统,至少一个功能所需的应用程序(比如声音播放功能,图像播放功能等)等。存储数据区可存储电子设备300使用过程中所创建的数据(比如音频数据,电话本等)等。此外,内部存储器321可以包括高速随机存取存储器,还可以包括非易失性存储器,例如至少一个磁盘存储器件,闪存器件,通用闪存存储器(universal flash storage,UFS)等。The internal memory 321 may be used to store computer-executable program code, which includes instructions. The processor 310 executes various functional applications and data processing of the electronic device 300 by executing instructions stored in the internal memory 321 . The internal memory 321 may include an area for storing programs and an area for storing data. Wherein, the stored program area can store an operating system, at least one application program required by a function (such as a sound playing function, an image playing function, etc.) and the like. The storage data area can store data (such as audio data, phone book, etc.) created during the use of the electronic device 300 . In addition, the internal memory 321 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one magnetic disk storage device, flash memory device, universal flash storage (universal flash storage, UFS) and the like.
电子设备300可以通过音频模块370,扬声器370A,受话器370B,麦克风370C,耳机接口370D,以及应用处理器310等实现音频功能。例如音乐播放,录音等。The electronic device 300 can realize the audio function through the audio module 370 , the speaker 370A, the receiver 370B, the microphone 370C, the earphone interface 370D, and the application processor 310 . Such as music playback, recording, etc.
音频模块370用于将数字音频信息转换成模拟音频信号输出,也用于将模拟音频输入转换为数字音频信号。音频模块370还可以用于对音频信号编码和解码。在一些实施例中,音频模块370可以设置于处理器310中,或将音频模块370的部分功能模块设置于处理器310中。扬声器370A,也称“喇叭”,用于将音频电信号转换为声音信号。电子设备300可以通过扬声器370A收听音乐,或收听免提通话。受话器370B,也称“听筒”,用于将音频电信号转换成声音信号。当电子设备300接听电话或语音信息时,可以通过将受话器370B靠近人耳接听语音。麦克风370C,也称“话筒”,“传声器”,用于将声音信号转换为电信号。当拨打电话或发送语音信息或需要通过语音助手触发电子设备300执行某些功能时,用户可以通过人嘴靠近麦克风370C发声,将声音信号输入到麦克风370C。电子设备300可以设置至少一个麦克风370C。在另一些实施例中,电子设备300可以设置两个麦克风370C,除了采集声音信号,还可以实现降噪功能。在另一些实施例中,电子设备300还可以设置三个,四个或更多麦克风370C,实现采集声音信号,降噪,还可以识别声音来源,实现定向录音功能等。耳机接口370D用于连接有线耳机。耳机接口370D可以是USB接口330,也可以是3.5mm的开放移动电子设备300平台(open mobile terminal platform,OMTP)标准接口,美国蜂窝电信工业协会(cellular telecommunications industry association of the USA,CTIA)标准接口。The audio module 370 is used to convert digital audio information into analog audio signal output, and is also used to convert analog audio input into digital audio signal. The audio module 370 may also be used to encode and decode audio signals. In some embodiments, the audio module 370 can be set in the processor 310 , or some functional modules of the audio module 370 can be set in the processor 310 . Speaker 370A, also called "horn", is used to convert audio electrical signals into sound signals. Electronic device 300 can listen to music through speaker 370A, or listen to hands-free calls. Receiver 370B, also called "earpiece", is used to convert audio electrical signals into audio signals. When the electronic device 300 receives a call or a voice message, the receiver 370B can be placed close to the human ear to receive the voice. The microphone 370C, also called "microphone" or "microphone", is used to convert sound signals into electrical signals. When making a call or sending a voice message, or needing to trigger the electronic device 300 to perform certain functions through the voice assistant, the user can make a sound by approaching the microphone 370C with a human mouth, and input the sound signal into the microphone 370C. The electronic device 300 may be provided with at least one microphone 370C. In some other embodiments, the electronic device 300 may be provided with two microphones 370C, which may also implement a noise reduction function in addition to collecting sound signals. In some other embodiments, the electronic device 300 can also be provided with three, four or more microphones 370C, so as to collect sound signals, reduce noise, identify sound sources, and realize directional recording functions, etc. The earphone interface 370D is used to connect wired earphones. The earphone interface 370D may be a USB interface 330, or a 3.5mm open mobile terminal platform (open mobile terminal platform, OMTP) standard interface, or a cellular telecommunications industry association of the USA (CTIA) standard interface. .
触摸传感器,也称“触控面板”。触摸传感器可以设置于显示屏394,由触摸传感器与显示屏394组成触摸屏,也称“触控屏”。触摸传感器用于检测作用于其上或附近的触摸操作。触摸传感器可以将检测到的触摸操作传递给应用处理器,以确定触摸事件类型。在一些实施例中,可以通过显示屏394提供与触摸操作相关的视觉输出。在另一些实施例中,触摸传感器也可以设置于电子设备300的表面,与显示屏394所处的位置不同。Touch sensor, also known as "touch panel". The touch sensor can be arranged on the display screen 394, and the touch sensor and the display screen 394 form a touch screen, also called “touch screen”. The touch sensor is used to detect a touch operation on or near it. The touch sensor can pass the detected touch operation to the application processor to determine the type of touch event. In some embodiments, the visual output related to the touch operation can be provided through the display screen 394 . In some other embodiments, the touch sensor can also be disposed on the surface of the electronic device 300 , which is different from the position of the display screen 394 .
压力传感器用于感受压力信号,可以将压力信号转换成电信号。在一些实施例中,压力传感器可以设置于显示屏394。压力传感器的种类很多,如电阻式压力传感器,电感式压力传感器,电容式压力传感器等。电容式压力传感器可以是包括至少两个具有导电材料的平行板。当有力作用于压力传感器,电极之间的电容改变。电子设备300根据电容的变化确定压力的强度。当有触摸操作作用于显示屏394,电子设备300根据压力传感器检测所述触摸操作强度。电子设备300也可以根据压力传感器的检测信号计算触摸的位置。在一些实施例中,作用于相同触摸位置,但不同触摸操作强度的触摸操作,可以对应不同的操作指令。例如:当有触摸操作强度小于第一压力阈值的触摸操作作用于短消息应用图标时,执行查看短消息的指令。当有触摸操作强度大于或等于第一压力阈值的触摸操作作用于短消息应用图标时,执行新建短消息的指令。陀螺仪传感器可以用于确定电子设备300的运动姿态。加速度传感器可检测电子设备300在各个方向上(一般为三轴)加速度的大小。距离传感器,用于测量距离。电子设备300可以通过红外或激光测量距离。电子设备300可以利用接近光传感器检测用户手持电子设备300贴近耳朵通话,以便自动熄灭屏幕达到省电的目的。环境光传感器用于感知环境光亮度。指纹传感器用于采集指纹。温度传感器用于检测温度。在一些实施例中,电子设备300利用温度传感器检测的温度,执行温度处理策略。音频模块370可以基于所述骨传导传感器获取的声部振动骨块的振动信号,解析出语音信号,实现语音功能。应用处理器可以基于所述骨传导传感器获取的血压跳动信号解析心率信息,实现心率检测功能。The pressure sensor is used to sense the pressure signal and convert the pressure signal into an electrical signal. In some embodiments, a pressure sensor may be located on display screen 394 . There are many types of pressure sensors, such as resistive pressure sensors, inductive pressure sensors, and capacitive pressure sensors. A capacitive pressure sensor may be comprised of at least two parallel plates with conductive material. When a force is applied to the pressure sensor, the capacitance between the electrodes changes. The electronic device 300 determines the intensity of pressure according to the change in capacitance. When a touch operation acts on the display screen 394, the electronic device 300 detects the intensity of the touch operation according to the pressure sensor. The electronic device 300 may also calculate the touched position according to the detection signal of the pressure sensor. In some embodiments, touch operations acting on the same touch position but with different touch operation intensities may correspond to different operation instructions. For example: when a touch operation with a touch operation intensity less than the first pressure threshold acts on the short message application icon, an instruction to view short messages is executed. When a touch operation whose intensity is greater than or equal to the first pressure threshold acts on the icon of the short message application, the instruction of creating a new short message is executed. The gyro sensor can be used to determine the motion posture of the electronic device 300 . The acceleration sensor can detect the acceleration of the electronic device 300 in various directions (generally three axes). Distance sensor for measuring distance. The electronic device 300 can measure the distance by infrared or laser. The electronic device 300 can use the proximity light sensor to detect that the user holds the electronic device 300 close to the ear to make a call, so as to automatically turn off the screen to save power. The ambient light sensor is used to sense the ambient light brightness. The fingerprint sensor is used to collect fingerprints. A temperature sensor is used to detect temperature. In some embodiments, the electronic device 300 uses the temperature detected by the temperature sensor to implement a temperature processing strategy. The audio module 370 can analyze the voice signal based on the vibration signal of the vibrating bone mass of the vocal part acquired by the bone conduction sensor, so as to realize the voice function. The application processor can analyze the heart rate information based on the blood pressure beating signal acquired by the bone conduction sensor, so as to realize the heart rate detection function.
按键390包括开机键,音量键等。马达391可以产生振动提示。指示器392可以是指示灯,可以用于指示充电状态,电量变化,也可以用于指示消息,未接来电,通知等。SIM卡接口395用于连接SIM卡。电子设备300可以支持1个或N个SIM卡接口395,N为大于1的正整数。SIM卡接口395可以支持Nano SIM卡,Micro SIM卡,SIM卡等。同一个SIM卡接口395可以同时插入多张卡。SIM卡接口395也可以兼容不同类型的SIM卡。SIM卡接口395也可以兼容外部存储卡。电子设备300通过SIM卡和网络交互,实现通话以及数据通信等功能。在一些实施例中,电子设备300采用eSIM,即:嵌入式SIM卡。eSIM卡可以嵌在电子设备300中,不能和电子设备300分离。The keys 390 include a power key, a volume key and the like. The motor 391 can generate a vibrating prompt. The indicator 392 can be an indicator light, which can be used to indicate the charging status, the change of the battery capacity, and can also be used to indicate messages, missed calls, notifications and the like. The SIM card interface 395 is used for connecting a SIM card. The electronic device 300 may support 1 or N SIM card interfaces 395, where N is a positive integer greater than 1. SIM card interface 395 can support Nano SIM card, Micro SIM card, SIM card and so on. Multiple cards can be inserted into the same SIM card interface 395 at the same time. The SIM card interface 395 is also compatible with different types of SIM cards. The SIM card interface 395 is also compatible with external memory cards. The electronic device 300 interacts with the network through the SIM card to implement functions such as calling and data communication. In some embodiments, the electronic device 300 adopts an eSIM, that is, an embedded SIM card. The eSIM card can be embedded in the electronic device 300 and cannot be separated from the electronic device 300 .
本申请实施例提供的渲染方法均能够应用于具有如图3所示的组成的电子设备中。All the rendering methods provided in the embodiments of the present application can be applied to an electronic device having the composition as shown in FIG. 3 .
需要说明的是,上述图3及其说明仅为本申请实施例提供的方案的一种应用载体的示例。图3的组成并不构成对本申请实施例所述的方案的限定。在另一些实施例中,电子设备还可以具有比图3所示组成更多或更少的部件。It should be noted that the foregoing FIG. 3 and its description are only an example of an application carrier of the solution provided by the embodiment of the present application. The composition in FIG. 3 does not constitute a limitation to the solution described in the embodiment of the present application. In other embodiments, the electronic device may also have more or fewer components than those shown in FIG. 3 .
在如图3所示的示例中,提供了电子设备的硬件组成。在一些实施例中,电子设备还可以通过其各个硬件部件(如图3所示的硬件组成),运行操作系统。在该操作系统中,可以设置有不同的软件分层,从而实现不同程序的运行。In the example shown in FIG. 3 , the hardware composition of the electronic device is provided. In some embodiments, the electronic device can also run an operating system through its various hardware components (the hardware composition shown in FIG. 3 ). In the operating system, different software layers can be set, so as to realize the running of different programs.
示例性的,图4为本申请实施例提供的一种电子设备的软件组成的示意图。如图4所示,该电子设备可以包括应用层401,框架层402,系统库403,以及硬件层404等。Exemplarily, FIG. 4 is a schematic diagram of a software composition of an electronic device provided in an embodiment of the present application. As shown in FIG. 4 , the electronic device may include an application layer 401 , a framework layer 402 , a system library 403 , and a hardware layer 404 .
其中,应用层401也可以称为应用程序层,或者应用(application,APP)层。在一些实现中,应用程序层可以包括一系列应用程序包。应用程序包可以包括相机,图库,日历,通话,地图,导航,WLAN,蓝牙,音乐,视频,短信息等应用程序。应用程序包还可以包括需要通过渲染图像向用户展示图片或者视频的应用程序。比如,该应用层401中包括的应用程序可以为游戏类应用程序,例如和等。Wherein, the application layer 401 may also be called an application program layer, or an application (application, APP) layer. In some implementations, the application layer can include a series of application packages. Application packages can include applications such as camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, and SMS. The application package can also include applications that need to display pictures or videos to users by rendering images. For example, the application program included in the application layer 401 may be a game application program, such as and wait.
框架层402也可以称为应用程序框架层。该框架层402可以为应用层401的应用程序提供应用编程接口(application programming interface,API)和编程框架。框架层402包括一些预先定义的函数。Framework layer 402 may also be called an application framework layer. The framework layer 402 can provide an application programming interface (application programming interface, API) and a programming framework for the application program of the application layer 401 . Framework layer 402 includes some predefined functions.
示例性的,框架层402可以包括窗口管理器,内容提供器,视图系统,资源管理器,通知管理器,活动管理器,输入管理器等。窗口管理器提供窗口管理服务(Window ManagerService,WMS),WMS可以用于窗口管理、窗口动画管理、surface管理以及作为输入系统的中转站。内容提供器用来存放和获取数据,并使这些数据可以被应用程序访问。该数据可以包括视频,图像,音频,拨打和接听的电话,浏览历史和书签,电话簿等。视图系统包括可视控件,例如显示文字的控件,显示图片的控件等。视图系统可用于构建应用程序。显示界面可以由一个或多个视图组成的。例如,包括短信通知图标的显示界面,可以包括显示文字的视图以及显示图片的视图。资源管理器为应用程序提供各种资源,比如本地化字符串,图标,图片,布局文件,视频文件等等。通知管理器使应用程序可以在状态栏中显示通知信息,可以用于传达告知类型的消息,可以短暂停留后自动消失,无需用户交互。比如通知管理器被用于告知下载完成,消息提醒等。通知管理器还可以是以图表或者滚动条文本形式出现在系统顶部状态栏的通知,例如后台运行的应用程序的通知,还可以是以对话窗口形式出现在屏幕上的通知。例如在状态栏提示文本信息,发出提示音,电子设备振动,指示灯闪烁等。活动管理器可以提供活动管理服务(Activity Manager Service,AMS),AMS可以用于系统组件(例如活动、服务、内容提供者、广播接收器)的启动、切换、调度以及应用进程的管理和调度工作。输入管理器可以提供输入管理服务(Input Manager Service,IMS),IMS可以用于管理系统的输入,例如触摸屏输入、按键输入、传感器输入等。IMS从输入设备节点取出事件,通过和WMS的交互,将事件分配至合适的窗口。Exemplarily, the framework layer 402 may include a window manager, a content provider, a view system, a resource manager, a notification manager, an activity manager, an input manager, and the like. The window manager provides a window management service (Window Manager Service, WMS). WMS can be used for window management, window animation management, surface management, and as a transfer station for the input system. Content providers are used to store and retrieve data and make it accessible to applications. This data can include videos, images, audio, calls made and received, browsing history and bookmarks, phonebook, etc. The view system includes visual controls, such as controls for displaying text, controls for displaying pictures, and so on. The view system can be used to build applications. A display interface can consist of one or more views. For example, a display interface including a text message notification icon may include a view for displaying text and a view for displaying pictures. The resource manager provides various resources for the application, such as localized strings, icons, pictures, layout files, video files, and so on. The notification manager enables the application to display notification information in the status bar, which can be used to convey notification-type messages, and can automatically disappear after a short stay without user interaction. For example, the notification manager is used to notify the download completion, message reminder, etc. The notification manager can also be a notification that appears on the top status bar of the system in the form of a chart or scroll bar text, such as a notification of an application running in the background, or a notification that appears on the screen in the form of a dialog window. For example, prompting text information in the status bar, issuing a prompt sound, vibrating the electronic device, and flashing the indicator light, etc. The activity manager can provide activity management service (Activity Manager Service, AMS), and AMS can be used for system components (such as activities, services, content providers, broadcast receivers) to start, switch, schedule, and manage and schedule application processes . The input manager may provide an input management service (Input Manager Service, IMS), and the IMS may be used to manage system inputs, such as touch screen input, key input, sensor input, and the like. IMS fetches events from input device nodes, and distributes events to appropriate windows through interaction with WMS.
在本申请实施例中,在框架层402中可以设置一个或多个功能模块,用于实现本申请实施例提供的渲染方案。示例性的,框架层402中可以设置有拦截模块,数据处理模块,计算模块,以及决策模块等。在后续示例中,将会对上述各个模块的功能进行详细说明。In the embodiment of the present application, one or more functional modules may be set in the framework layer 402 to implement the rendering solution provided in the embodiment of the present application. Exemplarily, the framework layer 402 may be provided with an interception module, a data processing module, a calculation module, and a decision-making module. In subsequent examples, the functions of the above modules will be described in detail.
系统库403可以包括多个功能模块。例如:表面管理器(surface manager),媒体框架(Media Framework),标准C库(Standard C library,libc),嵌入式系统的开放图形库(OpenGL for Embedded Systems,OpenGL ES)、Vulkan、SQLite、Webkit等。The system library 403 may include multiple functional modules. For example: surface manager (surface manager), media framework (Media Framework), standard C library (Standard C library, libc), open graphics library for embedded systems (OpenGL for Embedded Systems, OpenGL ES), Vulkan, SQLite, Webkit wait.
其中,表面管理器用于对显示子系统进行管理,并且为多个应用程序提供了2D和3D图层的融合。媒体框架支持多种常用的音频,视频格式回放和录制,以及静态图像文件等。媒体库可以支持多种音视频编码格式,例如:动态图像专家组4(Moving PicturesExperts Group,MPEG4),H.264,动态影像专家压缩标准音频层面3(Moving PictureExperts Group Audio Layer3,MP3),高级音频编码(Advanced Audio Coding,AAC),自适应多码解码(Adaptive Multi-Rate,AMR),联合图像专家组(Joint Photographic ExpertsGroup,JPEG,或称为JPG),便携式网络图形(Portable Network Graphics,PNG)等。OpenGLES和/或Vulkan提供应用程序中2D图形和3D图形的绘制和操作。SQLite为电子设备400的应用程序提供轻量级关系型数据库。在一些实现中,系统库403中的OpenGL ES能够提供可变速率着色功能。那么,电子设备可以在需要针对某一个绘制命令(Drawcall)执行可变速率着色时,调用OpenGL ES中的可变速率着色API,与其他指令一同实现对当前Drawcall的可变速率着色。比如,电子设备可以使用较低的速率(如2×1,2×2,4×2,4×4等)对当前Drawcall进行着色,由此降低对当前Drawcall进行着色产生的开销。Among them, the surface manager is used to manage the display subsystem, and provides the fusion of 2D and 3D layers for multiple applications. The media framework supports playback and recording of various commonly used audio and video formats, as well as still image files. The media library can support multiple audio and video encoding formats, such as: Moving Pictures Experts Group 4 (Moving Pictures Experts Group, MPEG4), H.264, Moving Picture Experts Group Audio Layer 3 (Moving Picture Experts Group Audio Layer3, MP3), advanced audio Coding (Advanced Audio Coding, AAC), adaptive multi-code decoding (Adaptive Multi-Rate, AMR), Joint Photographic Experts Group (Joint Photographic Experts Group, JPEG, or called JPG), portable network graphics (Portable Network Graphics, PNG) wait. OpenGLES and/or Vulkan provide drawing and manipulation of 2D graphics and 3D graphics in applications. SQLite provides a lightweight relational database for applications of the electronic device 400 . In some implementations, OpenGL ES in system library 403 can provide variable rate shading functionality. Then, when the electronic device needs to perform variable-rate shading for a drawing command (Drawcall), it can call the variable-rate shading API in OpenGL ES to implement variable-rate shading for the current Drawcall together with other instructions. For example, the electronic device may use a lower rate (such as 2×1, 2×2, 4×2, 4×4, etc.) to render the current Drawcall, thereby reducing the overhead caused by rendering the current Drawcall.
在如图4的示例中,电子设备中还可以包括硬件层404。该硬件层404中可以包括处理器(如CPU,GPU等),以及具有存储功能的部件(如如图3所示的内部存储器321等)。在一些实现中,CPU可以用于控制框架层402中的各个模块实现其各自的功能,GPU可以用于根据框架层402中各个模块处理后的指令所调用的图形库(如OpenGL ES)中的API执行相应的渲染处理。In the example shown in FIG. 4 , the electronic device may further include a hardware layer 404 . The hardware layer 404 may include a processor (such as a CPU, a GPU, etc.), and a component with a storage function (such as the internal memory 321 shown in FIG. 3 , etc.). In some implementations, the CPU can be used to control each module in the framework layer 402 to realize its respective functions, and the GPU can be used for the graphics library (such as OpenGL ES) that is called according to the instructions processed by each module in the framework layer 402. The API performs the corresponding rendering processing.
为了能够对本申请实施例提供的软件架构中各个层的功能进行更加清楚的说明,以下以图像渲染为例,对具有如图4所示软件组成的各个组件的功能实现进行举例说明。In order to illustrate the functions of each layer in the software architecture provided by the embodiment of the present application more clearly, image rendering is taken as an example below to illustrate the function implementation of each component with software components as shown in FIG. 4 .
示例性的,请参考图5。应用层中的应用程序在需要进行图像渲染时,可以下发渲染命令。在以下说明中,应用程序下发的一个渲染命令也可以称为一个Drawcall。在不同示例中,该渲染命令可以包括不同的内容。比如,在一些实施例中,以应用程序需要渲染帧图像中的图形为例。在下发的渲染命令中可以包括该需要被渲染的图形的顶点数据。在一些实现中,该顶点数据可以用于指示待渲染的图形的顶点的坐标。该坐标可以是基于局部空间的坐标。在渲染命令中,还可以包括如图1所示的说明中的MVP矩阵,以及一个或多个绘制元素(Drawelement)。框架层402可以在接收到该渲染命令之后,将渲染命令转换为渲染指令,在渲染指令中可以携带上述顶点数据,MVP矩阵,以及一个或多个Drawelement等。在一些实现中,框架层402还可以根据应用程序的指示,从系统库403的图形库中获取当前Drawcall所需的API,以便使用该API对应的功能指示其他模块(如GPU)进行渲染操作。示例性的,电子设备可以在Drawelement之前,确定可变速率着色过程中所要使用的参数。电子设备还可以通过调用可变速率着色API,结合前述参数,发送可变着色指令。实现对后续Drawelement的可变速率着色。以硬件层404中的GPU执行渲染为例。GPU可以获取可变着色指令,并响应于该可变着色指令,使用对应的参数指示的着色速率执行Drawelement。For example, please refer to FIG. 5 . When an application in the application layer needs to render an image, it can issue a rendering command. In the following description, a rendering command issued by an application may also be called a Drawcall. In different examples, the rendering command may include different content. For example, in some embodiments, an application program needs to render graphics in a frame image as an example. Vertex data of the graphics to be rendered may be included in the rendered command issued. In some implementations, this vertex data can be used to indicate the coordinates of the vertices of the graph to be rendered. The coordinates may be local space based coordinates. In the rendering command, the MVP matrix in the description as shown in FIG. 1 and one or more drawing elements (Drawelement) may also be included. After receiving the rendering command, the framework layer 402 may convert the rendering command into a rendering instruction, and the rendering instruction may carry the above-mentioned vertex data, MVP matrix, and one or more Drawelements. In some implementations, the framework layer 402 can also obtain the API required by the current Drawcall from the graphics library of the system library 403 according to the instruction of the application program, so as to instruct other modules (such as GPU) to perform rendering operations using the functions corresponding to the API. Exemplarily, the electronic device may determine the parameters to be used in the variable rate shading process before the Drawelement. The electronic device can also send a variable shading command by calling the variable rate shading API in combination with the aforementioned parameters. Implements variable rate shading of subsequent Drawelements. Take the rendering performed by the GPU in the hardware layer 404 as an example. The GPU may acquire a variable shading instruction, and in response to the variable shading instruction, execute the Drawelement using a shading rate indicated by a corresponding parameter.
本申请实施例提供的渲染方法也可以应用于具有如图4所示的软件组成的电子设备中。以下结合如图4所示的软件组成,对本申请实施例提供的方案进行说明。The rendering method provided by the embodiment of the present application may also be applied to an electronic device with software components as shown in FIG. 4 . The solution provided by the embodiment of the present application will be described below in conjunction with the software composition shown in FIG. 4 .
需要说明的是,在以下示例中,为了能够更加清楚地对本申请提供的方案进行说明,根据不同的功能,对电子设备进行模块划分,该模块划分可以理解为具有如图3或图4所示组成的电子设备的另一种划分形式。某个功能究竟以硬件还是计算机软件驱动硬件的方式来执行,取决于技术方案的特定应用和设计约束条件。专业技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本申请的范围。It should be noted that in the following examples, in order to more clearly describe the solution provided by this application, the electronic equipment is divided into modules according to different functions, and the module division can be understood as having Another form of division of composed electronic equipment. Whether a certain function is executed by hardware or computer software drives hardware depends on the specific application and design constraints of the technical solution. Skilled artisans may use different methods to implement the described functions for each specific application, but such implementation should not be regarded as exceeding the scope of the present application.
本申请实施例可以根据本申请实施例提供的方案对其中涉及的电子设备进行功能模块的划分,例如,可以对应各个功能划分各个功能模块,也可以将两个或两个以上的功能集成在一个处理模块中。上述集成的模块既可以采用硬件的形式实现,也可以采用软件功能模块的形式实现。需要说明的是,本申请实施例中对模块的划分是示意性的,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式。The embodiment of the present application can divide the functional modules of the electronic equipment involved according to the solution provided by the embodiment of the present application. For example, each functional module can be divided corresponding to each function, or two or more functions can be integrated into one processing module. The above-mentioned integrated modules can be implemented in the form of hardware or in the form of software function 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, and there may be other division methods in actual implementation.
示例性的,电子设备的框架层402中可以设置有拦截模块,数据处理模块,计算模块,以及决策模块。Exemplarily, the framework layer 402 of the electronic device may be provided with an interception module, a data processing module, a calculation module, and a decision-making module.
基于本申请实施例提供的渲染方法,电子设备可以通过其中设置的各个模块,拦截来自应用程序(如游戏应用)的渲染命令。电子设备还可以从这些渲染命令中筛选获取当前渲染命令中包括的各个顶点的顶点数据。在该顶点数据中可以包括顶点坐标。电子设备还可以获取以及当前渲染命令所对应的MVP矩阵。电子设备可以根据上述顶点坐标以及MVP矩阵,确定各个顶点的深度。进而根据该各个顶点的深度确定当前Drawcall所要绘制的模型的深度。其中模型的深度越大,则表明模型在当前帧图像中,与观察者的距离越远。对应的,模型的深度越小,则表明模型与观察者的距离越近。可以理解的是,距离观察者(即用户)较远的模型,一般不会被用户所关注,而距离用户较近的模型,可能是用户所关注的模型。因此,本申请实施例提供的方案中,可以对具有较大深度的模型进行较低速率的着色,从而在不影响用户体验的情况下,降低着色对应的渲染开销。相对的,对具有较小深度的模型,电子设备可以对其进行较高速率的着色,从而实现对该模型的精确着色,提升模型在当前帧图像中的显示质量,进而达到提升用户体验的效果。Based on the rendering method provided by the embodiment of the present application, the electronic device can intercept a rendering command from an application program (such as a game application) through various modules set therein. The electronic device can also filter and obtain the vertex data of each vertex included in the current rendering command from these rendering commands. Vertex coordinates may be included in this vertex data. The electronic device may also acquire the MVP matrix corresponding to the current rendering command. The electronic device can determine the depth of each vertex according to the vertex coordinates and the MVP matrix. Further, the depth of the model to be drawn by the current Drawcall is determined according to the depth of each vertex. The greater the depth of the model, the farther the model is from the observer in the current frame image. Correspondingly, the smaller the depth of the model, the closer the distance between the model and the observer. It can be understood that the models that are far away from the observer (that is, the user) are generally not followed by the user, while the models that are close to the user may be the models that the user pays attention to. Therefore, in the solution provided by the embodiment of the present application, a model with a greater depth can be rendered at a lower rate, thereby reducing the rendering overhead corresponding to the rendering without affecting the user experience. In contrast, for a model with a small depth, the electronic device can color it at a higher rate, so as to achieve accurate coloring of the model, improve the display quality of the model in the current frame image, and achieve the effect of improving user experience .
以下结合上述模块划分,对本申请实施例提供的渲染方法的具体实现进行详细说明。为了便于说明,以下示例中,以下发渲染命令的应用程序为游戏应用,该游戏应用使用OpenGL图形库为例进行说明。应当理解的是,在其他的不同渲染引擎/渲染环境下,实施机制类似,仅对应的函数可能存在差异。The specific implementation of the rendering method provided by the embodiment of the present application will be described in detail below in combination with the above module division. For ease of description, in the following examples, the application program that issues rendering commands is a game application, and the game application uses the OpenGL graphics library as an example for illustration. It should be understood that, in other different rendering engines/rendering environments, the implementation mechanisms are similar, and only the corresponding functions may be different.
在游戏开始运行时(或游戏加载时),游戏应用可以加载后续帧图像的渲染过程中可能要使用的数据。在一些实现中,在游戏加载时加载的数据可以包括后续渲染过程中可能使用到的所有模型的顶点数据以及一个或多个帧图像的MVP矩阵。在另一些实现中,在一次游戏加载时可能只会加载一部分模型的顶点数据。这样,在需要使用到新的模型时,电子设备就可以再次执行加载过程,将该新的模型的顶点数据加载到GPU中。或者,电子设备可以通过在下发的渲染指令中携带该新的模型的顶点数据,实现顶点数据的加载。在另一些实现中,游戏应用还可以在游戏加载过程中只进行顶点数据的传输,而对于每帧图像都可能不同的MVP矩阵,游戏应用可以在游戏运行过程中,进行该MVP矩阵的传输。在本申请实施例中,顶点数据可以包括顶点坐标,该顶点坐标可以是基于局部空间的坐标。When the game starts running (or when the game loads), the game application can load data that may be used during the rendering of subsequent frame images. In some implementations, the data loaded when the game is loaded may include vertex data of all models that may be used in a subsequent rendering process and MVP matrices of one or more frame images. In other implementations, only a portion of the model's vertex data may be loaded during a game load. In this way, when a new model needs to be used, the electronic device can execute the loading process again to load the vertex data of the new model into the GPU. Alternatively, the electronic device may load the vertex data by carrying the vertex data of the new model in the issued rendering instruction. In other implementations, the game application can only transmit vertex data during the game loading process, and for the MVP matrix that may be different for each frame of image, the game application can transmit the MVP matrix during the game running process. In the embodiment of the present application, the vertex data may include vertex coordinates, and the vertex coordinates may be coordinates based on local space.
为了便于说明,以下示例中,以游戏通过一次加载,实现所有模型的顶点坐标,以及MVP矩阵的加载为例。For the sake of illustration, in the following example, the game is loaded once to realize the vertex coordinates of all models and the loading of the MVP matrix as an example.
在本示例中,通过游戏加载,游戏应用可以通过包括多个指令的命令,传输所有可能用到模型的顶点坐标以及一个或多个MVP矩阵。通过这些指令,模型的顶点坐标以及MVP矩阵可以被存储到GPU所能够调用的内存空间中。In this example, through game loading, the game application can transmit all possible vertex coordinates of the model and one or more MVP matrices through a command including multiple instructions. Through these instructions, the vertex coordinates of the model and the MVP matrix can be stored in the memory space that the GPU can call.
示例性的,在游戏启动时,游戏应用可以下发命令1,用于实现上述加载过程。在一些实施例中,以在该命令1中包括glGenbuffers函数,glBindbuffer函数,glBufferdata函数,glBufferSubData函数中的一个或多个为例。Exemplarily, when the game is started, the game application may issue command 1 to implement the above loading process. In some embodiments, one or more of glGenbuffers function, glBindbuffer function, glBufferdata function and glBufferSubData function are included in the command 1 as an example.
其中,glGenbuffers函数可以用于创建缓存。即在电子设备的内存中划分一个或多个存储空间,每个存储空间都可以具有一个标识(ID)。该划分的存储空间可以用于存储渲染过程中的各项数据。比如,一些缓存可以用于存储模型的顶点坐标,一些缓存可以用于存储MVP矩阵等。Among them, the glGenbuffers function can be used to create a buffer. That is, one or more storage spaces are divided in the memory of the electronic device, and each storage space may have an identifier (ID). The divided storage space can be used to store various data in the rendering process. For example, some caches can be used to store the vertex coordinates of the model, some caches can be used to store the MVP matrix, etc.
glBindbuffer函数可以用于绑定缓存。通过该函数的绑定,就可以将后续的操作绑定在对应的缓存上。比如,以创建的缓存包括缓存1,缓存2,缓存3为例。通过glBindbuffer(1),就可以将后续的操作绑定在缓存1上。例如,后续操作包括写入数据(如顶点坐标)的操作,那么电子设备就可以将顶点坐标写入到缓存1进行存储。The glBindbuffer function can be used to bind buffers. Through the binding of this function, subsequent operations can be bound to the corresponding cache. For example, take the created caches including cache 1, cache 2, and cache 3 as an example. Through glBindbuffer(1), subsequent operations can be bound to buffer 1. For example, if the subsequent operation includes an operation of writing data (such as vertex coordinates), then the electronic device can write the vertex coordinates into the buffer 1 for storage.
glBufferdata函数可以用于传递数据。示例性的,在glBufferdata函数携带的数据非空(NULL),则电子设备就可以将该glBufferdata函数携带的数据(或者数据的指针)存储到已经绑定的缓存上。比如,在glBufferdata函数携带有顶点坐标时,则电子设备就可以将该顶点坐标存储到已经绑定的帧缓冲上。又如,在glBufferdata函数携带有顶点坐标的索引时,则电子设备就可以将该顶点坐标索引存储到已经绑定的帧缓冲上。The glBufferdata function can be used to pass data. Exemplarily, if the data carried by the glBufferdata function is not empty (NULL), the electronic device can store the data (or data pointer) carried by the glBufferdata function in the bound buffer. For example, when the glBufferdata function carries vertex coordinates, the electronic device can store the vertex coordinates in the bound frame buffer. For another example, when the glBufferdata function carries the index of the vertex coordinates, the electronic device can store the index of the vertex coordinates in the bound frame buffer.
glBufferSubData函数可以用于数据的更新。比如,游戏应用可以通过该glBufferSubData函数,实现对顶点坐标中的一部分或全部进行更新。从而达到指示电子设备(如GPU)根据新的顶点坐标进行绘制渲染的效果。glBufferSubData function can be used for data update. For example, a game application can update part or all of the vertex coordinates through the glBufferSubData function. In this way, an effect of instructing an electronic device (such as a GPU) to draw and render according to the new vertex coordinates is achieved.
在本申请实施例中,电子设备可以对命令1的指令流进行拦截,由此获取传输顶点数据以及MVP矩阵的指令。电子设备还可以对这些获取的指令进行备份存储。如,电子设备可以将这些数据存储在内存中CPU能够调用的区域。由此使得在游戏运行之前,电子设备的内存中就可以存储有后续渲染过程中可能用到的顶点数据(如顶点坐标)以及MVP矩阵。可以理解的是,原生命令(如命令1中的指令流)是用于将数据传输到GPU所能够调用的存储区域的,因此,通过本示例中的备份存储,使得CPU也可以具有对顶点数据和MVP矩阵的调用能力,由此保证后续方案的实现。In the embodiment of the present application, the electronic device may intercept the instruction stream of command 1, thereby obtaining the instruction for transmitting the vertex data and the MVP matrix. The electronic device can also backup and store the acquired instructions. For example, an electronic device may store these data in an area in the memory that the CPU can call. Therefore, before the game is run, the memory of the electronic device can store the vertex data (such as vertex coordinates) and the MVP matrix that may be used in the subsequent rendering process. It can be understood that the native command (such as the instruction stream in command 1) is used to transfer data to the storage area that the GPU can call. Therefore, through the backup storage in this example, the CPU can also have vertex data and the calling ability of the MVP matrix, thereby ensuring the realization of subsequent solutions.
示例性的,如图6所示,电子设备中的拦截模块可以拦截命令1中包括的glGenbuffers函数,glBindbuffer函数,glBufferdata函数,glBufferSubData函数。拦截模块还可以将这些函数传输给数据处理模块进行分析处理。如数据处理模块可以筛选来自拦截模块的函数中,携带参数1的函数。其中,参数1可以为指示用于进行顶点相关数据传输的参数。这样,数据处理模块就可以获取传输顶点数据相关的指令。那么基于这些筛选获取的函数,数据处理模块就可以执行对顶点数据的备份存储。Exemplarily, as shown in FIG. 6 , the interception module in the electronic device can intercept the glGenbuffers function, the glBindbuffer function, the glBufferdata function, and the glBufferSubData function included in the command 1. The interception module can also transmit these functions to the data processing module for analysis and processing. For example, the data processing module can filter the function with parameter 1 among the functions from the interception module. Wherein, parameter 1 may be a parameter indicating to transmit vertex-related data. In this way, the data processing module can obtain instructions related to transmitting vertex data. Then, based on the functions obtained through these screenings, the data processing module can perform backup storage of vertex data.
其中,该参数1可以是通过离线分析获取的。在一些实施例中,该参数1可以预先保存在电子设备(如数据处理模块)中,以便于数据处理模块可以基于该参数1执行对顶点数据相关指令的筛选。作为一种可能的实现,该参数1可以包括GL_ELEMENT_ARRAY_BUFFER和/或GL_ARRAY_BUFFER。Wherein, the parameter 1 may be obtained through offline analysis. In some embodiments, the parameter 1 may be pre-stored in an electronic device (such as a data processing module), so that the data processing module may perform screening of instructions related to vertex data based on the parameter 1 . As a possible implementation, the parameter 1 may include GL_ELEMENT_ARRAY_BUFFER and/or GL_ARRAY_BUFFER.
与针对顶点数据指令的拦截以及备份存储类似的,拦截模块拦截的拦截命令1中包括的glGenbuffers函数,glBindbuffer函数,glBufferdata函数,glBufferSubData函数也可以用于进行MVP矩阵的传输。Similar to the interception and backup storage for vertex data instructions, the glGenbuffers function, glBindbuffer function, glBufferdata function, and glBufferSubData function included in the interception command 1 intercepted by the interception module can also be used to transmit the MVP matrix.
那么,数据处理模块也可以可以筛选来自拦截模块的函数中,携带参数2的函数,来获取用于传输MVP矩阵的函数。其中,参数2可以为指示用于进行MVP矩阵传输的参数。这样,数据处理模块就可以获取传输MVP矩阵相关的指令。那么基于这些筛选获取的函数,数据处理模块就可以执行对MVP矩阵的备份存储。Then, the data processing module can also filter the function carrying parameter 2 among the functions from the interception module to obtain the function for transmitting the MVP matrix. Wherein, parameter 2 may be a parameter indicating to perform MVP matrix transmission. In this way, the data processing module can obtain instructions related to transmitting the MVP matrix. Then, based on these functions obtained through screening, the data processing module can perform backup storage of the MVP matrix.
其中,该参数2可以是通过离线分析获取的。在一些实施例中,该参数2可以预先保存在电子设备(如数据处理模块)中,以便于数据处理模块可以基于该参数2执行对MVP矩阵相关指令的筛选。作为一种可能的实现,该参数2可以包括GL_UNIFORM_BUFFER。Wherein, the parameter 2 may be obtained through offline analysis. In some embodiments, the parameter 2 may be pre-stored in an electronic device (such as a data processing module), so that the data processing module may perform screening of instructions related to the MVP matrix based on the parameter 2 . As a possible implementation, the parameter 2 may include GL_UNIFORM_BUFFER.
上述示例中,是以拦截模块将所有拦截的指令不经过处理直接传输给数据处理模块进行分析处理为例进行说明的。在本申请的另一些实施例中,该拦截模块还可以具有基础分析能力。比如,拦截模块可以只拦截携带有参数1以及参数2的glGenbuffers函数,glBindbuffer函数,glBufferdata函数,glBufferSubData函数。其中,参数1可以为指示用于进行顶点相关数据传输的参数。参数2可以为指示用于进行MVP矩阵传输的参数。In the above example, the interception module directly transmits all intercepted instructions to the data processing module for analysis and processing without processing. In some other embodiments of the present application, the interception module may also have basic analysis capabilities. For example, the interception module can only intercept the glGenbuffers function, glBindbuffer function, glBufferdata function, and glBufferSubData function that carry parameter 1 and parameter 2. Wherein, parameter 1 may be a parameter indicating to transmit vertex-related data. Parameter 2 may be a parameter indicating to perform MVP matrix transmission.
这样,数据处理模块就可以直接对来自拦截模块的指令进行备份存储。由此可以减轻数据处理模块的数据处理压力。In this way, the data processing module can directly back up and store the instructions from the interception module. In this way, the data processing pressure of the data processing module can be reduced.
以下示例中,如图6所示的示例,以拦截模块拦截顶点相关指令(如携带参数1的指令)以及MVP相关指令(如携带参数2的指令)传输给数据处理模块进行备份存储为例进行说明。In the following example, as shown in Figure 6, the interception module intercepts vertex-related instructions (such as instructions carrying parameter 1) and MVP-related instructions (such as instructions carrying parameter 2) and transmits them to the data processing module for backup storage. illustrate.
本申请实施例中涉及的备份存储,可以通过跳转表的形式实现。该跳转表可以用于指示原生ID与备份ID的对应关系。其中,原生ID可以为命令1中携带函数所指示需要操作的缓存ID。备份ID可以为在内存中配置的,可以被CPU调用的用于进行数据的备份存储的缓存ID。The backup storage involved in the embodiment of the present application may be implemented in the form of a jump table. The jump table can be used to indicate the correspondence between the original ID and the backup ID. Wherein, the original ID may be the ID of the cache that needs to be operated as indicated by the function carried in command 1. The backup ID may be a cache ID configured in the memory and called by the CPU for backing up and storing data.
示例性的,以拦截模块拦截的顶点数据相关指令的函数包括如下函数为例:Exemplarily, the functions of the vertex data-related instructions intercepted by the interception module include the following functions as an example:
glGenbuffers(GL_ARRAY_BUFFER,1)//为顶点数据创建缓存,缓存ID为1;glGenbuffers(GL_ARRAY_BUFFER, 1)//Create a buffer for vertex data, the buffer ID is 1;
glBindbuffer(GL_ARRAY_BUFFER,1)//为顶点数据绑定ID为1的缓存;glBindbuffer(GL_ARRAY_BUFFER, 1)//Bind the buffer whose ID is 1 for the vertex data;
glBufferdata(GL_ARRAY_BUFFER,data1)//向已经绑定的缓存写入data1;glBufferdata(GL_ARRAY_BUFFER, data1)//write data1 to the bound buffer;
glBufferSubData(GL_ARRAY_BUFFER,data2)//更新已经绑定的缓存中的数据为data2。glBufferSubData(GL_ARRAY_BUFFER, data2)//Update the data in the bound buffer to data2.
那么,该示例中的原生ID就可以为1。以对应的备份ID为11为例。Then, the original ID in this example can be 1. Take the corresponding backup ID as 11 as an example.
根据拦截的glGenbuffers(GL_ARRAY_BUFFER,1),数据处理模块就可以在备份缓存中创建ID为与1对应的11的缓存。According to the intercepted glGenbuffers(GL_ARRAY_BUFFER, 1), the data processing module can create a cache whose ID is 11 corresponding to 1 in the backup cache.
根据拦截的glBindbuffer(GL_ARRAY_BUFFER,1),数据处理模块就可以控制后续操作在ID为与1对应的11的缓存上进行。According to the intercepted glBindbuffer(GL_ARRAY_BUFFER, 1), the data processing module can control subsequent operations to be performed on the cache whose ID is 11 corresponding to 1.
根据拦截的glBufferdata(GL_ARRAY_BUFFER,data1),数据处理模块就可以将data1写入备份缓存中的ID为11的存储空间中。According to the intercepted glBufferdata (GL_ARRAY_BUFFER, data1), the data processing module can write data1 into the storage space with ID 11 in the backup cache.
根据拦截的glBufferSubData(GL_ARRAY_BUFFER,data2),数据处理模块就可以将data2更新到备份缓存中的ID为11的存储空间中。According to the intercepted glBufferSubData(GL_ARRAY_BUFFER, data2), the data processing module can update data2 to the storage space with ID 11 in the backup cache.
其中,data1和data2可以包括顶点数据,如顶点坐标,顶点的法向量等。Among them, data1 and data2 can include vertex data, such as vertex coordinates, normal vectors of vertices, etc.
由此,就可以实现对命令1中携带的顶点数据相关指令的备份存储。In this way, the backup storage of the vertex data-related instructions carried in the command 1 can be realized.
与顶点数据的备份存储类似的,数据处理模块还可以对MVP矩阵进行备份存储。Similar to the backup storage of vertex data, the data processing module can also backup and store the MVP matrix.
示例性的,以拦截模块拦截的MVP矩阵相关指令的函数包括如下函数为例:Exemplarily, the functions of the MVP matrix-related instructions intercepted by the interception module include the following functions as an example:
glGenbuffers(GL_UNIFORM_BUFFER,2)//为统一变量(如MVP矩阵)创建缓存,缓存ID为2;glGenbuffers(GL_UNIFORM_BUFFER, 2)//Create a cache for uniform variables (such as MVP matrix), and the cache ID is 2;
glBindbuffer(GL_UNIFORM_BUFFER,2)//为统一变量(如MVP矩阵)绑定ID为2的缓存;glBindbuffer(GL_UNIFORM_BUFFER, 2)//Bind the buffer with ID 2 for the uniform variable (such as MVP matrix);
glBufferdata(GL_UNIFORM_BUFFER,data3)//向已经绑定的缓存写入data3;glBufferdata(GL_UNIFORM_BUFFER, data3)//write data3 to the bound buffer;
glBufferSubData(GL_UNIFORM_BUFFER,data4)//更新已经绑定的缓存中的数据为data4。glBufferSubData(GL_UNIFORM_BUFFER, data4)//Update the data in the bound buffer to data4.
其中,data3和data4可以包括MVP矩阵。Wherein, data3 and data4 may include the MVP matrix.
那么,该示例中的原生ID就可以为2。以对应的备份ID为22为例。Then, the original ID in this example can be 2. Take the corresponding backup ID as 22 as an example.
根据拦截的glGenbuffers(GL_UNIFORM_BUFFER,2),数据处理模块就可以在备份缓存中创建ID为与2对应的22的缓存。该ID为22的备份缓存可以用于存储统一变量对应的数据,如该统一变量可以包括MVP矩阵。According to the intercepted glGenbuffers(GL_UNIFORM_BUFFER, 2), the data processing module can create a cache whose ID is 22 corresponding to 2 in the backup cache. The backup cache whose ID is 22 may be used to store data corresponding to the uniform variable, for example, the uniform variable may include an MVP matrix.
根据拦截的glBindbuffer(GL_UNIFORM_BUFFER,2),数据处理模块就可以控制后续操作在ID为与2对应的22的缓存上进行。According to the intercepted glBindbuffer(GL_UNIFORM_BUFFER, 2), the data processing module can control the subsequent operations to be performed on the cache whose ID is 22 corresponding to 2.
根据拦截的glBufferdata(GL_UNIFORM_BUFFER,data3),数据处理模块就可以将data3写入备份缓存中的ID为22的存储空间中。According to the intercepted glBufferdata (GL_UNIFORM_BUFFER, data3), the data processing module can write data3 into the storage space whose ID is 22 in the backup cache.
根据拦截的glBufferSubData(GL_UNIFORM_BUFFER,data4),数据处理模块就可以将data4更新到备份缓存中的ID为22的存储空间中。According to the intercepted glBufferSubData(GL_UNIFORM_BUFFER, data4), the data processing module can update data4 to the storage space with ID 22 in the backup cache.
其中,data3和data4可以包括MVP矩阵,如M矩阵,VP矩阵等。Wherein, data3 and data4 may include MVP matrix, such as M matrix, VP matrix and so on.
由此,就可以实现对命令1中携带的MVP矩阵相关指令的备份存储。In this way, the backup storage of the MVP matrix-related instructions carried in the command 1 can be realized.
在对指令以及相关数据进行备份存储之外,数据处理模块还可以存储包括原生ID与备份ID的对应关系的跳转表,从而可以根据后续应用下发的命令中的ID,准确地找到备份存储中对应数据的ID。In addition to backing up instructions and related data, the data processing module can also store a jump table including the correspondence between the original ID and the backup ID, so that the backup storage can be accurately found according to the ID in the command issued by the subsequent application. The ID of the corresponding data in .
例如,如下表1示出了跳转表的一种示例。For example, Table 1 below shows an example of a jump table.
表1Table 1
基于表1,在游戏应用下发指示对ID为1的缓存执行操作时,电子设备就可以确定在备份ID为11的存储空间中可以保存有对应的数据。类似的,在游戏应用下发指示对ID为2的缓存执行操作时,电子设备就可以确定在备份ID为22的存储空间中可以保存有对应的数据。Based on Table 1, when the game application issues an instruction to perform an operation on the cache whose ID is 1, the electronic device can determine that corresponding data can be stored in the storage space whose backup ID is 11. Similarly, when the game application issues an instruction to perform an operation on the cache whose ID is 2, the electronic device can determine that corresponding data can be stored in the storage space whose backup ID is 22.
需要说明的是,为了保证命令1的顺利执行,在本示例中,拦截模块还可以将没有携带参数1或参数2的指令(如回调指令a)回调给图形库,以便于通过调用图形库中对应的接口,控制硬件层中的部件(如GPU)执行对应的功能。在另一些实现中,数据处理模块还可以在完成对顶点数据以及MVP矩阵的备份存储之后,将来自拦截模块的指令(如回调指令b)回调给图形库,以便通过调用图形库中对应的接口,控制硬件层中的部件(如GPU)执行对应的功能。It should be noted that, in order to ensure the smooth execution of command 1, in this example, the interception module can also call back the command that does not carry parameter 1 or parameter 2 (such as callback command a) to the graphics library, so as to call the graphics library The corresponding interface controls components in the hardware layer (such as GPU) to perform corresponding functions. In other implementations, the data processing module can also call back the instructions from the interception module (such as callback instruction b) to the graphics library after completing the backup storage of the vertex data and the MVP matrix, so that by calling the corresponding interface in the graphics library , to control components in the hardware layer (such as GPU) to execute corresponding functions.
这样,在实现对顶点数据以及MVP矩阵的备份存储的同时,也能够实现对命令1的完整执行,从而不会影响后续游戏应用下发的命令的执行。In this way, while realizing the backup storage of the vertex data and the MVP matrix, the complete execution of the command 1 can also be realized, so that the execution of the commands issued by the subsequent game application will not be affected.
在本申请实施例中,根据加载过程中的备份存储的数据,电子设备可以实现对游戏运行过程中命令的相关处理,从而确定当前命令(即当前Drawcall)所要绘制模型的顶点坐标以及当前Drawcall对应的MVP矩阵。In the embodiment of the present application, according to the data stored in the backup during the loading process, the electronic device can realize the related processing of the commands during the running of the game, so as to determine the vertex coordinates of the model to be drawn by the current command (that is, the current Drawcall) and the corresponding vertex coordinates of the current Drawcall. The MVP matrix.
示例性的,结合图7。在游戏运行过程中,游戏应用可以发出命令2。其中,该命令2可以用于实现包括对模型的绘制。For example, refer to FIG. 7 . While the game is running, the game application can issue commands 2 . Among them, the command 2 can be used to implement including drawing the model.
可以理解的是,结合前述说明,要绘制的模型的顶点数据以及MVP矩阵可以是已经通过命令1加载的。也就是说,这些数据可以是已经存储在GPU可以调用的内存空间中的。那么,在命令2中,可以通过指示需要使用的顶点数据以及MVP矩阵的相关参数,以便GPU可以从已经加载的数据中获取对应的顶点数据和MVP矩阵,从而进行对应模型的绘制。It can be understood that, in combination with the foregoing description, the vertex data and the MVP matrix of the model to be drawn may have been loaded through command 1. That is to say, these data may already be stored in the memory space that the GPU can call. Then, in command 2, you can draw the corresponding model by indicating the vertex data to be used and the relevant parameters of the MVP matrix, so that the GPU can obtain the corresponding vertex data and MVP matrix from the loaded data.
在本示例中,在游戏下发的该命令2中可以包括多个指令(即函数)组成的指令流。为了实现上述功能,在命令2中可以包括绑定缓存的函数,指示顶点数据解析方式的函数,指示MVP矩阵相关参数的函数。In this example, the command 2 issued by the game may include an instruction stream composed of multiple instructions (that is, functions). In order to realize the above functions, the command 2 may include the function of binding the cache, the function indicating the vertex data parsing method, and the function indicating the related parameters of the MVP matrix.
作为一种可能的实现,在命令2中可以至少包括以下指令:As a possible implementation, at least the following instructions can be included in command 2:
绑定缓存的函数,如glBindbuffer函数;Binding cache functions, such as glBindbuffer function;
用于指示顶点数据解析方式的glVertexAttribPoint函数;The glVertexAttribPoint function used to indicate how the vertex data is parsed;
用于指示MVP矩阵相关参数的glBindBufferRange函数。The glBindBufferRange function used to indicate the parameters related to the MVP matrix.
那么,拦截模块可以用于在该游戏运行的过程中,拦截上述指令。在一些实施例中,拦截模块可以拦截包括glBindbuffer函数,glVertexAttribPoint函数的顶点相关指令。拦截模块还可以拦截包括glBindBufferRange函数的MVP相关指令。拦截模块还可以将该顶点相关指令以及MVP相关指令传输给数据处理模块进行解析。Then, the interception module can be used to intercept the above instructions during the running of the game. In some embodiments, the interception module can intercept vertex-related instructions including glBindbuffer function and glVertexAttribPoint function. The interception module can also intercept MVP-related instructions including the glBindBufferRange function. The interception module can also transmit the vertex-related instructions and the MVP-related instructions to the data processing module for analysis.
类似于上述加载过程中的数据拦截的说明,在本示例中,拦截模块也可以具有一定的数据解析能力。那么,拦截模块可以拦截携带有参数1(如GL_ELEMENT_ARRAY_BUFFER和/或GL_ARRAY_BUFFER)的glBindbuffer函数,以及glVertexAttribPoint函数。拦截模块还可以拦截携带有参数2(如GL_UNIFORM_BUFFER)的glBindBufferRange函数。Similar to the above description of data interception in the loading process, in this example, the interception module may also have certain data parsing capabilities. Then, the interception module can intercept the glBindbuffer function carrying parameter 1 (such as GL_ELEMENT_ARRAY_BUFFER and/or GL_ARRAY_BUFFER), and the glVertexAttribPoint function. The interception module can also intercept the glBindBufferRange function carrying parameter 2 (such as GL_UNIFORM_BUFFER).
那么,数据处理模块可以在接收到携带有参数1的glBindbuffer函数以及glVertexAttribPoint函数后,据此确定当前Drawcall所要使用的顶点坐标。Then, the data processing module can determine the vertex coordinates to be used by the current Drawcall after receiving the glBindbuffer function and the glVertexAttribPoint function carrying parameter 1.
在本申请的一些实施例中,数据处理模块可以结合本地存储的参数3,确定当前Drawcall所要使用的顶点坐标。该参数3可以是对当前游戏的静态分析确定的。In some embodiments of the present application, the data processing module may determine the vertex coordinates to be used by the current Drawcall in combination with the locally stored parameter 3 . The parameter 3 may be determined through static analysis of the current game.
可以理解的是,在顶点数据中可以包括多项顶点的相关数据。不同的数据可以存储在不同的属性(attribute)中。比如,attitude0可以用于存储顶点坐标,attribute1可以用于存储顶点法向量等。对于一个游戏应用而言,其在工作过程中所用于存储顶点坐标的属性的ID(如0)一般是不会变化的。因此,在本示例中,参数3中可以包括当前游戏用于存储顶点坐标的属性的ID(如0)。It can be understood that the vertex data may include multiple items of vertex related data. Different data can be stored in different attributes. For example, attitude0 can be used to store vertex coordinates, attribute1 can be used to store vertex normal vectors, etc. For a game application, the ID (such as 0) of the attribute used to store the vertex coordinates generally does not change during the working process. Therefore, in this example, parameter 3 may include the ID (eg 0) of the attribute used by the current game to store the vertex coordinates.
这样,数据处理模块在接收到来自拦截模块的指令后,可以根据glVertexAttribPoint函数所指示的存储数据的属性ID是否与参数3匹配,确定该glVertexAttribPoint函数是否用于进行顶点数据的传输。在glVertexAttribPoint函数指示的属性ID与参数3匹配的情况下,数据处理模块就可以确定该glVertexAttribPoint函数是顶点坐标相关的函数。In this way, after receiving the instruction from the interception module, the data processing module can determine whether the glVertexAttribPoint function is used for vertex data transmission according to whether the attribute ID of the stored data indicated by the glVertexAttribPoint function matches parameter 3. When the attribute ID indicated by the glVertexAttribPoint function matches parameter 3, the data processing module can determine that the glVertexAttribPoint function is a function related to vertex coordinates.
那么,数据处理模块就可以根据该glVertexAttribPoint函数之前,通过glBindbuffer函数绑定的缓存ID,确定当前Drawcall所指示的顶点数据的存储位置。数据处理模块可以据此确定当前Drawcall所指示的顶点坐标在备份存储的缓存中的存储位置。Then, the data processing module can determine the storage location of the vertex data indicated by the current Drawcall according to the cache ID bound by the glBindbuffer function before the glVertexAttribPoint function. Based on this, the data processing module can determine the storage location of the vertex coordinates indicated by the current Drawcall in the cache of the backup storage.
例如,数据处理模块接收到来自拦截模块的指令包括:For example, the instructions received by the data processing module from the interception module include:
glBindbuffer(GL_ARRAY_BUFFER,1)//绑定ID为1的缓存;glBindbuffer(GL_ARRAY_BUFFER, 1)//Bind buffer with ID 1;
glVertexAttribPoint(0,3,GL_FLOAT,GL_FALSE,3*sizeof(float),(void*_0))//各个参数按照先后顺序分别指示:属性值为0,每组数据包括3个值(如XYZ),类型为浮点类型,不需要进行标准化,步长为3*4,起始地址为0。glVertexAttribPoint(0, 3, GL_FLOAT, GL_FALSE, 3*sizeof(float), (void*_0))// Each parameter is indicated in sequence: the attribute value is 0, and each group of data includes 3 values (such as XYZ), The type is a floating point type and does not need to be standardized. The step size is 3*4 and the starting address is 0.
以参数3指示的属性ID为0为例。Take the property ID indicated by parameter 3 as 0 as an example.
数据处理模块可以确定glVertexAttribPoint函数指示的属性ID(如0)与参数3匹配,那么该glVertexAttribPoint函数所绑定的ID,即glVertexAttribPoint函数之前的glBindbuffer(GL_ARRAY_BUFFER,1)所绑定的ID为1的缓存,为用于传递当前Drawcall所要绘制模型的顶点数据的缓存。The data processing module can determine that the attribute ID (such as 0) indicated by the glVertexAttribPoint function matches the parameter 3, then the ID bound to the glVertexAttribPoint function, that is, the buffer with ID 1 bound to glBindbuffer(GL_ARRAY_BUFFER, 1) before the glVertexAttribPoint function , which is used to transfer the vertex data cache of the model to be drawn by the current Drawcall.
接着,数据处理模块可以根据原生ID与备份ID的对应关系(如表1),确定在备份存储的数据中,存储当前Drawcall所要绘制模型的顶点坐标的缓存ID为11。接着,根据glVertexAttribPoint函数所指示的属性ID(也就是参数3所指示的ID)以及偏移量,确定该模型的各个顶点的顶点坐标。Next, the data processing module can determine, according to the correspondence between the original ID and the backup ID (as shown in Table 1), that in the data stored in the backup, the cache ID for storing the vertex coordinates of the model to be drawn by the current Drawcall is 11. Next, determine the vertex coordinates of each vertex of the model according to the attribute ID indicated by the glVertexAttribPoint function (that is, the ID indicated by parameter 3) and the offset.
上述说明详细阐述了当前Drawcall要绘制模型(简称为当前模型)的顶点坐标的获取方式。以下对当前模型对应的MVP矩阵的获取进行说明。The above description elaborates in detail how to obtain the vertex coordinates of the model to be drawn by the current Drawcall (referred to as the current model for short). The acquisition of the MVP matrix corresponding to the current model is described below.
结合前述游戏运行过程中,拦截模块还可以拦截携带有参数2(如GL_UNIFORM_BUFFER)的glBindBufferRange函数。Combined with the aforementioned game running process, the interception module can also intercept the glBindBufferRange function with parameter 2 (such as GL_UNIFORM_BUFFER).
该携带有参数2的glBindBufferRange函数可以被传输给数据处理模块进行处理。The glBindBufferRange function carrying parameter 2 can be transmitted to the data processing module for processing.
示例性的,在本申请的一些实施例中,数据处理模块可以结合本地存储的参数4,确定当前Drawcall所要使用的MVP矩阵。该参数4可以是对当前游戏的静态分析确定的。Exemplarily, in some embodiments of the present application, the data processing module may combine the locally stored parameter 4 to determine the MVP matrix to be used by the current Drawcall. The parameter 4 may be determined by static analysis of the current game.
在一些实施例中,该参数4可以包括存储M矩阵,和/或VP矩阵的偏移量。可以理解的是,对于确定的游戏应用,在对应缓存中存储M矩阵的偏移量,以及VP矩阵的偏移量一般是不会变化的。因此,本示例中,数据处理模块可以根据该参数4,结合拦截到的glBindBufferRange函数携带的参数,确定该拦截到的glBindBufferRange函数是否用于传输当前Drawcall对应的MVP矩阵。In some embodiments, the parameter 4 may include an offset to store the M matrix, and/or the VP matrix. It can be understood that, for a certain game application, the offset of the M matrix and the offset of the VP matrix are generally not changed in the corresponding cache. Therefore, in this example, the data processing module can determine whether the intercepted glBindBufferRange function is used to transmit the MVP matrix corresponding to the current Drawcall according to the parameter 4 and the parameters carried by the intercepted glBindBufferRange function.
在数据处理模块确定glBindBufferRange函数携带的偏移量与参数4匹配的情况下,则数据处理模块就可以确定该glBindBufferRange函数是用于传输当前Drawcall对应的MVP矩阵的。When the data processing module determines that the offset carried by the glBindBufferRange function matches parameter 4, the data processing module can determine that the glBindBufferRange function is used to transmit the MVP matrix corresponding to the current Drawcall.
那么数据处理模块就可以根据该glBindBufferRange函数所指示的缓存ID,以及上述跳转表(如表1),确定在备份存储中,存储当前Drawcall对应的MVP矩阵的缓存ID。此外,还可以根据glBindBufferRange函数所指示的偏移量(或参数4指示的偏移量)确在该缓存中M矩阵和VP矩阵具体的存储位置。Then the data processing module can determine the cache ID of the MVP matrix corresponding to the current Drawcall stored in the backup storage according to the cache ID indicated by the glBindBufferRange function and the above jump table (such as Table 1). In addition, the specific storage locations of the M matrix and the VP matrix in the cache can also be determined according to the offset indicated by the glBindBufferRange function (or the offset indicated by parameter 4).
例如,数据处理模块接收到来自拦截模块的指令包括:For example, the instructions received by the data processing module from the interception module include:
glBindBufferRange(GL_UNIFORM_BUFFER,2,0,152)//各个参数按照先后顺序指示的含义为:目标为GL_UNIFORM_BUFFER,缓存ID为2,偏移量首地址为0,数据大小为152。glBindBufferRange(GL_UNIFORM_BUFFER, 2, 0, 152)//The meanings indicated by each parameter in sequence are: the target is GL_UNIFORM_BUFFER, the buffer ID is 2, the first offset address is 0, and the data size is 152.
以参数4指示的偏移量首地址0,数据大小为152为例。Take the first offset address indicated by parameter 4 as 0 and the data size as 152 as an example.
数据处理模块可以确定当前拦截到的glBindBufferRange函数指示的偏移量与参数4匹配,那么该glBindBufferRange函数是用于传递当前Drawcall对应MVP矩阵的。因此,根据glBindBufferRange函数所指示的ID(如2),数据处理模块就可以确定当前Drawcall对应的MVP矩阵对应的原生ID为2。The data processing module can determine that the offset indicated by the currently intercepted glBindBufferRange function matches parameter 4, then the glBindBufferRange function is used to transfer the MVP matrix corresponding to the current Drawcall. Therefore, according to the ID (such as 2) indicated by the glBindBufferRange function, the data processing module can determine that the native ID corresponding to the MVP matrix corresponding to the current Drawcall is 2.
接着,数据处理模块可以根据原生ID与备份ID的对应关系(如表1),确定在备份存储的数据中,存储当前Drawcall所要绘制模型的MVP矩阵的缓存ID为22。根据glBindBufferRange函数所指示的偏移量(也就是参数4所指示的偏移量),数据处理模块就可以确定该模型的MVP矩阵。Next, the data processing module can determine, according to the correspondence between the original ID and the backup ID (as shown in Table 1), that the cache ID of the MVP matrix storing the model to be drawn by the current Drawcall is 22 in the data stored in the backup. According to the offset indicated by the glBindBufferRange function (that is, the offset indicated by parameter 4), the data processing module can determine the MVP matrix of the model.
需要说明的是,在本示例中,类似前述备份存储的过程,拦截模块还可以通过回调指令c,实现对命令2中,与顶点数据以及MVP矩阵不相关的指令的回调。数据处理模块可以通过回调指令d,实现对命令2中,与顶点数据以及MVP矩阵相关的指令的回调。It should be noted that, in this example, similar to the aforementioned backup and storage process, the interception module can also implement the callback of commands not related to vertex data and MVP matrix in command 2 by calling back command c. The data processing module can call back instructions related to vertex data and MVP matrix in command 2 by calling back instruction d.
为了能够使得本领域技术人员能更加清楚地了解本申请实施例提供方案中,关于游戏加载过程中数据的备份存储过程,以及游戏运行过程中顶点数据和MVP矩阵的确定过程,以下从指令流的角度,对该过程中各个模块的功能进行示例性说明。In order to enable those skilled in the art to more clearly understand the solution provided by the embodiment of the present application, regarding the backup storage process of data during the game loading process, and the determination process of vertex data and MVP matrix during the game running process, the following is from the instruction flow From a perspective, the functions of each module in the process are illustrated.
示例性的,请参考图8,为本申请实施例提供的游戏加载(或启动)时,对数据备份存储的流程示意图。如图8所示,该过程可以包括:For example, please refer to FIG. 8 , which is a schematic flowchart of data backup and storage when the game is loaded (or started) according to the embodiment of the present application. As shown in Figure 8, the process can include:
S801、在接收到指令P后,确定指令P是否是顶点相关指令。S801. After receiving an instruction P, determine whether the instruction P is a vertex-related instruction.
在本示例中,在游戏加载时,游戏应用可以发出指令P,该指令P可以用于进行顶点数据的加载。In this example, when the game is loaded, the game application can issue an instruction P, and the instruction P can be used to load vertex data.
在指令P为顶点相关指令的情况下,执行以下S802。在指令P不是顶点相关指令的情况下,执行以下S811。If the instruction P is a vertex-related instruction, the following S802 is executed. If the instruction P is not a vertex-related instruction, the following S811 is executed.
结合前述示例,该顶点相关指令可以包括携带有参数1的函数。如携带有参数1的glGenbuffers函数,glBindbuffer函数,glBufferdata函数,glBufferSubData函数等。With reference to the foregoing example, the vertex-related instruction may include a function carrying parameter 1. For example, the glGenbuffers function, glBindbuffer function, glBufferdata function, glBufferSubData function, etc. that carry parameter 1.
S802、拦截模块向数据处理模块发送顶点相关指令。其中,该顶点相关指令可以包括指令P。S802. The interception module sends a vertex-related instruction to the data processing module. Wherein, the vertex-related instruction may include instruction P.
S803、数据处理模块控制内存备份存储顶点相关数据。S803. The data processing module controls the memory backup to store vertex-related data.
其中,本示例中的内存可以对应到上述示例中的缓存。该内存(或缓存)可以是电子设备的内部存储介质中,可以被CPU调用的部分存储空间。Among them, the memory in this example can correspond to the cache in the above example. The memory (or cache) may be a part of the storage space in the internal storage medium of the electronic device that can be called by the CPU.
上述S801-S803中,关于顶点数据的拦截,分析,存储等过程,与前述说明中的具体实现类似,此处不再赘述。由此即可实现对顶点数据的备份存储。In the above S801-S803, the interception, analysis, storage and other processes of vertex data are similar to the specific implementation in the foregoing description, and will not be repeated here. In this way, the backup storage of vertex data can be realized.
在本申请的一些实施例中,在执行S803的过程中,数据处理模块还可以存储原生ID与备份ID的对应关系,用于后续数据的调用。In some embodiments of the present application, during the execution of S803, the data processing module may also store the correspondence between the original ID and the backup ID for subsequent data call.
电子设备在执行该S801-S803的过程中,还可以通过指令回调,实现游戏应用发出的命令的正常运行,如实现数据的正常加载。示例性的,该过程可以包括:In the process of executing S801-S803, the electronic device can also implement the normal operation of the command issued by the game application through the command callback, such as realizing the normal loading of data. Exemplarily, the process may include:
S811、拦截模块向图形库回调指令1-1。S811. The interception module calls back the instruction 1-1 to the graphics library.
示例性的,在指令P不是顶点相关指令的情况下,拦截模块可以将该指令回调给图形库。例如,该指令1-1可以包括指令P。Exemplarily, in the case that the instruction P is not a vertex-related instruction, the interception module may call back the instruction to the graphics library. For example, the instruction 1-1 may include instruction P.
S812、图形库调取相关API 1-1。其中,该相关API 1-1可以是为了实现回调指令1-1的功能所调用的API。S812. The graphics library calls related APIs 1-1. Wherein, the relevant API 1-1 may be an API called to realize the function of the callback instruction 1-1.
S813、图形库向GPU发送指令1-1。在该指令1-1中可以携带API 1-1对应的代码。S813. The graphics library sends an instruction 1-1 to the GPU. The code corresponding to API 1-1 may be carried in the instruction 1-1.
S814、GPU执行指令1-1对应的操作。S814. The GPU executes the operation corresponding to the instruction 1-1.
与拦截模块类似的,数据处理模块也可以对顶点相关指令进行回调。示例性的,该过程可以包括:Similar to the interception module, the data processing module can also call back vertex-related instructions. Exemplarily, the process may include:
S815、数据处理模块向图形库回调指令1-2。该指令1-2可以包括拦截模块拦截并传输给数据处理模块的指令。比如,该指令可以包括指令P中的顶点相关指令。S815. The data processing module calls back the instruction 1-2 to the graphics library. The instructions 1-2 may include instructions intercepted by the interception module and transmitted to the data processing module. For example, the instruction may include a vertex-related instruction in instruction P.
S816、图形库调取相关API 1-2。该API 1-2可以是为了实现回调指令1-2的功能所调用的API。S816. The graphics library calls related APIs 1-2. The API 1-2 may be an API called to realize the function of the callback instruction 1-2.
S817、图形库向GPU发送指令1-2。在该指令1-2中可以携带API 1-2对应的代码。S817. The graphics library sends instructions 1-2 to the GPU. The code corresponding to API 1-2 can be carried in the instruction 1-2.
S818、GPU执行指令1-2对应的操作。S818. The GPU executes the operation corresponding to the instruction 1-2.
由此,通过S811-S818,就实现了对指令P中所有数据的回调,从而顺利实现指令P中数据的加载。Thus, through S811-S818, the callback of all the data in the instruction P is realized, thereby successfully realizing the loading of the data in the instruction P.
在本示例中,电子设备还可以通过如下流程实现对MVP矩阵的备份存储。示例性的,该过程可以包括:In this example, the electronic device may also implement backup storage of the MVP matrix through the following process. Exemplarily, the process may include:
S804、在接收到指令Q后,确定指令Q是否是MVP相关指令。S804. After receiving the instruction Q, determine whether the instruction Q is an MVP-related instruction.
在本示例中,在游戏加载时,游戏应用可以发出指令Q,该指令Q可以用于进行MVP数据的加载。拦截模块可以拦截该指令Q中包括的携带参数2的函数。In this example, when the game is loaded, the game application can issue an instruction Q, which can be used to load MVP data. The interception module may intercept the function carrying parameter 2 included in the instruction Q.
如携带有参数2的glGenbuffers函数,glBindbuffer函数,glBufferdata函数,glBufferSubData函数等。For example, the glGenbuffers function, glBindbuffer function, glBufferdata function, glBufferSubData function, etc. that carry parameter 2.
在指令Q为MVP相关指令的情况下,执行以下S805。在指令P不是MVP相关指令的情况下,执行以下S821。In the case that the command Q is an MVP-related command, the following S805 is executed. If the instruction P is not an MVP-related instruction, the following S821 is executed.
S805、拦截模块向数据处理模块发送MVP相关指令。其中,该MVP相关指令可以包括指令Q。S805. The interception module sends MVP related instructions to the data processing module. Wherein, the MVP-related instruction may include instruction Q.
S806、数据处理模块控制内存备份存储MVP相关数据。S806. The data processing module controls the memory to back up and store MVP-related data.
上述S804-S806中,关于MVP矩阵的拦截,分析,存储等过程,与前述说明中的具体实现类似,此处不再赘述。由此即可实现对MVP矩阵的备份存储。In the above S804-S806, the interception, analysis, storage and other processes of the MVP matrix are similar to the specific implementation in the foregoing description, and will not be repeated here. In this way, the backup storage of the MVP matrix can be realized.
类似于前述关于顶点数据的回调过程,在本示例中,电子设备也可以对MVP指令进行回调,实现MVP矩阵的正常加载。示例性的,该过程可以包括:Similar to the aforementioned callback process on vertex data, in this example, the electronic device can also call back the MVP instruction to implement normal loading of the MVP matrix. Exemplarily, the process may include:
S821、拦截模块向图形库回调指令2-1。S821. The interception module calls back the instruction 2-1 to the graphics library.
示例性的,在指令P不是MVP相关指令的情况下,拦截模块可以将该指令回调给图形库。例如,该指令2-1可以包括指令Q。Exemplarily, in the case that the instruction P is not an MVP-related instruction, the interception module may call back the instruction to the graphics library. For example, the instruction 2-1 may include instruction Q.
S822、图形库调取相关API 2-1。其中,该相关API 2-1可以是为了实现回调指令2-1的功能所调用的API。S822. The graphics library calls related APIs 2-1. Wherein, the relevant API 2-1 may be an API called to realize the function of the callback instruction 2-1.
S823、图形库向GPU发送指令2-1。在该指令2-1中可以携带API 2-1对应的代码。S823. The graphics library sends the instruction 2-1 to the GPU. The code corresponding to API 2-1 may be carried in the instruction 2-1.
S824、GPU执行指令2-1对应的操作。S824. The GPU executes the operation corresponding to the instruction 2-1.
与拦截模块类似的,数据处理模块也可以对MVP相关指令进行回调。示例性的,该过程可以包括:Similar to the interception module, the data processing module can also call back MVP-related instructions. Exemplarily, the process may include:
S825、数据处理模块向图形库回调指令2-2。该指令2-2可以包括拦截模块拦截并传输给数据处理模块的指令。比如,该指令可以包括指令Q中的MVP相关指令。S825. The data processing module calls back the instruction 2-2 to the graphics library. The instruction 2-2 may include an instruction intercepted by the intercepting module and transmitted to the data processing module. For example, the instruction may include an MVP-related instruction in instruction Q.
S826、图形库调取相关API 2-2。该API 2-2可以是为了实现回调指令2-2的功能所调用的API。S826. The graphic library calls related API 2-2. The API 2-2 may be an API called to realize the function of the callback instruction 2-2.
S827、图形库向GPU发送指令2-2。在该指令2-2中可以携带API 2-2对应的代码。S827. The graphics library sends the instruction 2-2 to the GPU. The code corresponding to API 2-2 may be carried in the instruction 2-2.
S828、GPU执行指令2-2对应的操作。S828. The GPU executes the operation corresponding to the instruction 2-2.
由此,通过S821-S828,就实现了对指令Q中所有指令的回调,从而顺利实现指令Q中数据的加载。Thus, through S821-S828, the callback of all the instructions in the instruction Q is realized, thereby successfully realizing the loading of the data in the instruction Q.
下面结合从指令流的角度,对游戏运行过程中,当前Drawcall所要绘制模型对应的顶点坐标和MVP矩阵的确定过程进行举例说明。In the following, from the perspective of instruction flow, an example will be given to illustrate the process of determining the vertex coordinates and MVP matrix corresponding to the model to be drawn by the current Drawcall during the running of the game.
示例性的,结合图9,以游戏应用在运行过程中发出指令N用于指示当前模型的顶点数据为例。该过程可以包括:Exemplarily, with reference to FIG. 9 , it is taken as an example that a game application issues an instruction N to indicate vertex data of the current model during running. The process can include:
S901、在接收到指令N之后,拦截模块确定指令N是否是顶点相关指令。S901. After receiving the instruction N, the interception module determines whether the instruction N is a vertex-related instruction.
在本示例中,该顶点相关指令可以为指令N中携带的用于指示当前Drawcall所要绘制模型对应的顶点数据的指令。在一些实施例中,这些指令可以携带有与顶点数据相关的参数1。结合前述说明,该顶点相关指令可以包括glVertexAttribPoint函数,以及对应的glBindbuffer函数等。In this example, the vertex-related instruction may be an instruction carried in the instruction N for indicating the vertex data corresponding to the model to be drawn by the current Drawcall. In some embodiments, these instructions may carry a parameter 1 related to vertex data. With reference to the foregoing description, the vertex-related instructions may include a glVertexAttribPoint function, a corresponding glBindbuffer function, and the like.
在指令N是顶点相关指令的情况下,可以执行以下S902。在指令N不是顶点相关指令的情况下,可以执行对指令N的回调,如执行S911。In a case where the instruction N is a vertex-related instruction, the following S902 may be executed. In the case that the instruction N is not a vertex-related instruction, a callback to the instruction N may be executed, such as executing S911.
S902、拦截模块向数据处理模块发送顶点相关指令。其中,该顶点相关指令可以包括指令N。S902. The interception module sends a vertex-related instruction to the data processing module. Wherein, the vertex-related instruction may include instruction N.
S903、数据处理模块确定传输顶点数据的缓存ID。S903. The data processing module determines a buffer ID for transmitting vertex data.
示例性的,数据处理模块可以在拦截模块拦截的glVertexAttribPoint函数所指示的属性ID,与预设的参数3匹配时,确定当前拦截的函数是用于指示当前Drawcall所要绘制模型对应的顶点数据的。Exemplarily, the data processing module may determine that the currently intercepted function is used to indicate the vertex data corresponding to the model to be drawn by the current Drawcall when the attribute ID indicated by the glVertexAttribPoint function intercepted by the interception module matches the preset parameter 3.
那么数据处理模块就可以根据glVertexAttribPoint函数之前的glBindbuffer函数,确定传输顶点数据的缓存ID。该缓存ID可以为原生ID。Then the data processing module can determine the buffer ID for transmitting vertex data according to the glBindbuffer function before the glVertexAttribPoint function. The cache ID can be an original ID.
S904、数据处理模块确定顶点数据的备份存储中的存储位置。S904. The data processing module determines a storage location in the backup storage of the vertex data.
示例性的,数据处理模块可以根据包括原生ID与备份ID的对应关系的跳转表,确定与当前原生ID对应的备份ID。由此即可确定当前Drawcall所要绘制模型对应的顶点数据在备份存储中的缓存ID。此外还可以根据顶点坐标所在属性ID以及偏移量,准确获取各个顶点坐标在备份存储中的存储位置。Exemplarily, the data processing module may determine the backup ID corresponding to the current original ID according to a jump table including the correspondence between the original ID and the backup ID. Thus, the buffer ID of the vertex data corresponding to the model to be drawn by the current Drawcall in the backup storage can be determined. In addition, the storage location of each vertex coordinate in the backup storage can be accurately obtained according to the attribute ID and the offset of the vertex coordinate.
在本申请的一些实施例中,在确定顶点数据的备份存储中的存储位置之后,数据处理模块可以将该顶点坐标转存到预设位置1,以便后续调用。在另一些实施例中,在确定顶点数据的备份存储中的存储位置之后,数据处理模块可以对备份存储中存储当前Drawcall对应顶点坐标的位置进行标记,以便后续调用。In some embodiments of the present application, after determining the storage location in the backup storage of the vertex data, the data processing module may transfer the vertex coordinates to the preset location 1 for subsequent calling. In some other embodiments, after determining the storage location in the backup storage of the vertex data, the data processing module may mark the location in the backup storage that stores the coordinates of the vertex corresponding to the current Drawcall for subsequent calls.
需要说明的是,为了保证指令N的正常运行,本申请实施例中,拦截模块以及数据处理模块还可以进行指令回调。示例性的,该过程可以包括:It should be noted that, in order to ensure the normal operation of the instruction N, in the embodiment of the present application, the interception module and the data processing module may also perform instruction callback. Exemplarily, the process may include:
S911、拦截模块向图形库回调指令3-1。S911. The interception module calls back the instruction 3-1 to the graphics library.
示例性的,在指令N不是顶点相关指令的情况下,可以执行该步骤实现对指令N的回调。在一些实施例中,该指令3-1可以包括指令N。Exemplarily, in the case that the instruction N is not a vertex-related instruction, this step may be performed to implement a callback to the instruction N. In some embodiments, the instruction 3-1 may include instruction N.
S912、图形库调取相关API 3-1。该API 3-1可以是图形库中为了实现指令3-1对应功能的API。S912. The graphics library calls related APIs 3-1. The API 3-1 may be an API in a graphics library for realizing the function corresponding to the instruction 3-1.
S913、图形库向GPU发送指令3-1。该指令3-1可以包括API 3-1对应的代码。S913. The graphics library sends an instruction 3-1 to the GPU. The instruction 3-1 may include codes corresponding to the API 3-1.
S914、GPU执行指令3-1对应的操作。S914. The GPU executes the operation corresponding to the instruction 3-1.
需要说明的是,在一些实施例中,上述S911-S914的执行,可以是在S902之后执行的。It should be noted that, in some embodiments, the execution of the above S911-S914 may be executed after S902.
与拦截模块类似的,数据处理模块也可以执行指令回调。示例性的,该过程可以包括:Similar to the interception module, the data processing module can also execute instruction callbacks. Exemplarily, the process may include:
S915、数据处理模块向图形库回调指令3-2。S915. The data processing module calls back the instruction 3-2 to the graphics library.
示例性的,该指令3-2可以包括指令N中,拦截模块拦截的顶点相关指令。Exemplarily, the instruction 3-2 may include the vertex-related instructions intercepted by the interception module in the instruction N.
S916、图形库调取相关API 3-2。该API 3-2可以是图形库中为了实现指令3-2对应功能的API。S916. The graphic library calls related API 3-2. The API 3-2 may be an API in a graphics library for realizing the function corresponding to the instruction 3-2.
S917、图形库向GPU发送指令3-2。该指令3-2可以包括API 3-2对应的代码。S917. The graphics library sends the instruction 3-2 to the GPU. The instructions 3-2 may include codes corresponding to the API 3-2.
S918、GPU执行指令3-2对应的操作。S918. The GPU executes the operation corresponding to the instruction 3-2.
在一些实施例中,上述S915-S918的执行,可以是在S904之后执行的。In some embodiments, the above S915-S918 may be performed after S904.
由此,就实现了指令N的全量回调,从而保证指令N的正常执行。Thus, the full callback of instruction N is realized, thereby ensuring the normal execution of instruction N.
在本示例中,电子设备还可以通过如下流程确定当前Drawcall对应的MVP矩阵在备份存储中的存储位置。示例性的,结合图9,以游戏应用在运行过程中发出指令M用于指示当前模型的MVP矩阵为例。该过程可以包括:In this example, the electronic device may also determine the storage location of the MVP matrix corresponding to the current Drawcall in the backup storage through the following process. Exemplarily, with reference to FIG. 9 , it is taken as an example that a game application issues an instruction M to indicate the MVP matrix of the current model during running. The process can include:
S905、在接收到指令M之后,拦截模块确定指令N是否是MVP相关指令。S905. After receiving the instruction M, the interception module determines whether the instruction N is an MVP-related instruction.
在本示例中,该MVP相关指令可以为指令M中携带的用于指示当前Drawcall所要绘制模型对应的MVP矩阵的指令。在一些实施例中,这些指令可以携带有与MVP矩阵相关的参数2。结合前述说明,该MVP相关指令可以包括glBindBufferRange函数等。In this example, the MVP-related instruction may be an instruction carried in the instruction M for indicating the MVP matrix corresponding to the model to be drawn by the current Drawcall. In some embodiments, these instructions may carry a parameter 2 related to the MVP matrix. With reference to the foregoing description, the MVP-related instructions may include a glBindBufferRange function and the like.
在指令M是MVP相关指令的情况下,可以执行以下S906。在指令M不是MVP相关指令的情况下,可以执行对指令M的回调,如执行S921。In the case that the instruction M is an MVP-related instruction, the following S906 may be executed. In the case that the instruction M is not an MVP-related instruction, a callback to the instruction M may be executed, such as executing S921.
S906、拦截模块向数据处理模块发送MVP相关指令。S906. The interception module sends MVP related instructions to the data processing module.
S907、数据处理模块确定传输MVP矩阵的缓存ID。S907. The data processing module determines the cache ID of the transmission MVP matrix.
示例性的,数据处理模块可以在拦截模块拦截的glBindBufferRange函数所指示的偏移量,与预设的参数4匹配时,确定当前拦截的函数是用于指示当前Drawcall所要绘制模型对应的MVP矩阵的。Exemplarily, the data processing module can determine that the currently intercepted function is used to indicate the MVP matrix corresponding to the model to be drawn by the current Drawcall when the offset indicated by the glBindBufferRange function intercepted by the interception module matches the preset parameter 4 .
那么数据处理模块就可以根据glBindBufferRange函数指示的缓存的ID,确定传输MVP矩阵的缓存ID。该缓存ID可以为原生ID。Then the data processing module can determine the cache ID for transmitting the MVP matrix according to the cache ID indicated by the glBindBufferRange function. The cache ID can be an original ID.
S908、数据处理模块确定MVP矩阵的备份存储中的存储位置。S908. The data processing module determines a storage location in the backup storage of the MVP matrix.
示例性的,数据处理模块可以根据包括原生ID与备份ID的对应关系的跳转表,确定与当前原生ID对应的备份ID。由此即可确定当前Drawcall所要绘制模型对应的MVP矩阵在备份存储中的缓存ID。此外还可以根据MVP矩阵的偏移量,准确获取M矩阵,和/或VP矩阵在备份存储中的存储位置。Exemplarily, the data processing module may determine the backup ID corresponding to the current original ID according to a jump table including the correspondence between the original ID and the backup ID. From this, the cache ID of the MVP matrix corresponding to the model to be drawn by the current Drawcall in the backup storage can be determined. In addition, the M matrix and/or the storage location of the VP matrix in the backup storage can be accurately acquired according to the offset of the MVP matrix.
在本申请的一些实施例中,类似于前述顶点数据的处理,在确定MVP矩阵的备份存储中的存储位置之后,数据处理模块可以将该MVP矩阵转存到预设位置2,以便后续调用。在另一些实施例中,在确定MVP矩阵的备份存储中的存储位置之后,数据处理模块可以对备份存储中存储当前Drawcall对应MVP矩阵的位置进行标记,以便后续调用。In some embodiments of the present application, similar to the processing of the aforementioned vertex data, after determining the storage location in the backup storage of the MVP matrix, the data processing module can dump the MVP matrix to the preset location 2 for subsequent recall. In some other embodiments, after determining the storage location in the backup storage of the MVP matrix, the data processing module may mark the location in the backup storage that stores the MVP matrix corresponding to the current Drawcall for subsequent calling.
需要说明的是,为了保证指令M的正常运行,本申请实施例中,拦截模块以及数据处理模块还可以进行指令回调。示例性的,该过程可以包括:It should be noted that, in order to ensure the normal operation of the instruction M, in the embodiment of the present application, the interception module and the data processing module may also perform instruction callback. Exemplarily, the process may include:
S921、拦截模块向图形库回调指令4-1。S921. The interception module calls back the instruction 4-1 to the graphics library.
示例性的,在指令M不是MVP相关指令的情况下,可以执行该步骤实现对指令M的回调。在一些实施例中,该指令4-1可以包括指令M。Exemplarily, in the case that the instruction M is not an MVP-related instruction, this step may be performed to implement a callback to the instruction M. In some embodiments, the instruction 4-1 may include an instruction M.
S922、图形库调取相关API 4-1。该API 4-1可以是图形库中为了实现指令4-1对应功能的API。S922. The graphic library calls related API 4-1. The API 4-1 may be an API in the graphics library for realizing the function corresponding to the instruction 4-1.
S923、图形库向GPU发送指令4-1。该指令4-1可以包括API 4-1对应的代码。S923. The graphics library sends the instruction 4-1 to the GPU. The instruction 4-1 may include codes corresponding to the API 4-1.
S924、GPU执行指令4-1对应的操作。S924. The GPU executes the operation corresponding to the instruction 4-1.
需要说明的是,在一些实施例中,上述S921-S924的执行,可以是在S906之后执行的。It should be noted that, in some embodiments, the execution of the above S921-S924 may be executed after S906.
与拦截模块类似的,数据处理模块也可以执行指令回调。示例性的,该过程可以包括:Similar to the interception module, the data processing module can also execute instruction callbacks. Exemplarily, the process may include:
S925、数据处理模块向图形库回调指令4-2。S925. The data processing module calls back the instruction 4-2 to the graphics library.
示例性的,该指令4-2可以包括指令M中,拦截模块拦截的MVP相关指令。Exemplarily, the instruction 4-2 may include an MVP-related instruction intercepted by the interception module in the instruction M.
S926、图形库调取相关API 4-2。该API 4-2可以是图形库中为了实现指令4-2对应功能的API。S926. The graphic library calls related API 4-2. The API 4-2 may be an API in the graphics library for realizing the function corresponding to the instruction 4-2.
S927、图形库向GPU发送指令4-2。该指令4-2可以包括API 4-2对应的代码。S927. The graphics library sends the instruction 4-2 to the GPU. The instructions 4-2 may include codes corresponding to the API 4-2.
S928、GPU执行指令4-2对应的操作。S928. The GPU executes the operation corresponding to the instruction 4-2.
在一些实施例中,上述S925-S928的执行,可以是在S908之后执行的。In some embodiments, the above S925-S928 may be performed after S908.
由此,就实现了指令N的全量回调,从而保证指令M的正常执行。Thus, the full callback of instruction N is realized, thereby ensuring the normal execution of instruction M.
通过上述示例,电子设备就可以获取当前Drawcall对应模型的顶点坐标以及MVP矩阵。Through the above example, the electronic device can obtain the vertex coordinates and the MVP matrix of the model corresponding to the current Drawcall.
在本申请实施例中,电子设备还可以据此计算当前模型的深度,并进而使用合理的着色速率对该模型进行渲染处理。In the embodiment of the present application, the electronic device can also calculate the depth of the current model based on this, and then use a reasonable shading rate to render the model.
示例性的,结合图10计算模块,可以用于根据内存中存储的顶点坐标以及MVP矩阵,确定当前drawcall所要绘制的图形(或模型)的深度。Exemplarily, in conjunction with the calculation module in FIG. 10 , it can be used to determine the depth of the graph (or model) to be drawn by the current drawcall according to the vertex coordinates and the MVP matrix stored in the memory.
其中,模型的深度可以通过该模型上的部分或全部顶点的深度确定。Wherein, the depth of the model can be determined by the depth of some or all vertices on the model.
以下首先对顶点的深度确定方式进行说明。The method of determining the depth of vertices will be firstly described below.
示例性的,在一些实施例中,在拦截模块拦截到Drawelement的情况下,可以触发计算模块对各个顶点的深度的计算。Exemplarily, in some embodiments, when the interception module intercepts the Drawelement, the calculation module may be triggered to calculate the depth of each vertex.
可以理解的是,在本申请实施例中,计算模块可以通过计算各个顶点的深度,配合决策模块确定是否要对部分顶点进行低速率着色。因此,在本申请的不同实现中,计算模块计算各个顶点的深度的触发机制可以是不同的。只要在向GPU下发对应的drawelement之前,计算模块和/或决策模块能够知晓对该drawelement对应的顶点深度即可。比如,在本示例中,计算模块对各个顶点的深度的计算,可以是由拦击模块拦截到drawelement触发的。在另一些实现中,计算模块也可以在内存中缓存了顶点坐标以及MVP矩阵参数之后,即触发对各个顶点的深度的计算,这样计算模块可以将计算获取的深度信息存储在内存中,以便于后续使用。It can be understood that, in the embodiment of the present application, the calculation module may cooperate with the decision-making module to determine whether to perform low-rate shading on some vertices by calculating the depth of each vertex. Therefore, in different implementations of the present application, the triggering mechanism for the calculation module to calculate the depth of each vertex may be different. As long as the calculation module and/or the decision module can know the vertex depth corresponding to the drawelement before delivering the corresponding drawelement to the GPU. For example, in this example, the calculation of the depth of each vertex by the calculation module may be triggered by intercepting the drawelement by the interception module. In other implementations, the calculation module can also trigger the calculation of the depth of each vertex after the vertex coordinates and MVP matrix parameters are cached in the memory, so that the calculation module can store the depth information obtained by calculation in the memory, so that Subsequent use.
在本申请的一些实施例中,计算模块可以根据数据处理模块确定的当前Drawcall对应的顶点坐标以及MVP矩阵的存储地址,调用对应的数据,计算获取各个顶点的深度信息。In some embodiments of the present application, the calculation module may call corresponding data according to the vertex coordinates corresponding to the current Drawcall determined by the data processing module and the storage address of the MVP matrix, and calculate and obtain the depth information of each vertex.
示例性的,以顶点坐标指示的顶点1的局部坐标为(x1,y1,z1)为例。计算模块可以根据以下公式(1),对顶点1的局部坐标进行MVP变换,进而确定顶点1在裁剪空间(或屏幕空间)中的深度。Exemplarily, take the local coordinates of vertex 1 indicated by the vertex coordinates as (x1, y1, z1) as an example. The calculation module can perform MVP transformation on the local coordinates of the vertex 1 according to the following formula (1), and then determine the depth of the vertex 1 in the clipping space (or screen space).
裁剪坐标=P·V·M·(x1,y1,z1)……公式(1)。Clipping coordinates=P·V·M·(x1, y1, z1)...Formula (1).
以计算获取的顶点1的裁剪坐标为(x2,y2,z2)为例。那么计算模块可以确定当前顶点1的深度为z2。Take the obtained clipping coordinates of vertex 1 as (x2, y2, z2) as an example. Then the calculation module can determine that the depth of the current vertex 1 is z2.
与上述顶点1类似的,计算模块可以对当前drawcall中对应的模型的其他顶点进行深度计算,以获取各个顶点的深度情况。可以理解的是,该深度可以为裁剪空间下的深度。深度越深,则表明该顶点(或模型)在当前帧图像显示过程中距离用户观察位置越远,因此在对该具有较大深度的顶点(或模型)执行较低速率着色时,不会被用户所察觉。Similar to the above vertex 1, the calculation module can perform depth calculation on other vertices of the model corresponding to the current drawcall to obtain the depth of each vertex. It can be understood that the depth may be the depth in the clipping space. The deeper the depth, the farther the vertex (or model) is from the user's observation position during the current frame image display process, so when performing lower rate shading on the vertex (or model) with a larger depth, it will not be perceived by the user.
结合上述顶点深度的计算方式,在本申请的一些实施例中,电子设备可以据此确定当前drawcall对应模型的深度。In combination with the above calculation method of vertex depth, in some embodiments of the present application, the electronic device can determine the depth of the model corresponding to the current drawcall accordingly.
示例性的,作为一种可能的实现方式,电子设备可以计算当前模型的所有顶点的深度,并将这些深度的均值作为模型的深度。比如,计算模块可以在触发深度计算的情况下,从存储器中调取当前存储的所有顶点坐标,并根据MVP矩阵,按照上述公式(1)进行矩阵变换,从而获取各个顶点的裁剪坐标,进而获取各个顶点的深度。电子设备可以取这些顶点深度的均值,作为该模型的深度。Exemplarily, as a possible implementation manner, the electronic device may calculate the depths of all vertices of the current model, and use an average of these depths as the depth of the model. For example, when the depth calculation is triggered, the calculation module can retrieve all the currently stored vertex coordinates from the memory, and perform matrix transformation according to the above formula (1) according to the MVP matrix, so as to obtain the clipping coordinates of each vertex, and then obtain The depth of each vertex. The electronic device can take the average of these vertex depths as the depth of the model.
需要说明的是,一般而言,即使一个drawcall对应的模型的顶点数量也是非常庞大的。因此,在本申请的一些实现方式中,电子设备可以从内存中存储的顶点坐标中,选取一部分计算深度,并据此确定当前模型的深度。从而达到降低计算开销的效果。It should be noted that, generally speaking, the number of vertices of a model corresponding to a drawcall is very large. Therefore, in some implementation manners of the present application, the electronic device may select a part of the calculated depth from the vertex coordinates stored in the memory, and determine the depth of the current model accordingly. So as to achieve the effect of reducing the calculation cost.
示例性的,电子设备可以根据预设的顶点数量(如n个),从当前drawcall对应模型的顶点中,随机选取n个顶点。通过确定这n个顶点的深度,并取均值从而获取当前模型的深度。Exemplarily, the electronic device may randomly select n vertices from the vertices of the model corresponding to the current drawcall according to a preset number of vertices (such as n). The depth of the current model is obtained by determining the depth of the n vertices and taking the mean value.
作为一种可能的实现,计算模块可以在触发深度计算的情况下,从存储器中调取当前存储的所有顶点坐标中,随机的n个顶点坐标。计算模块可以根据MVP矩阵,按照上述公式(1)对着n个顶点坐标分别进行矩阵变换,从而获取这n个顶点的裁剪坐标。计算模块可以根据这n个顶点的裁剪坐标,获取各个顶点的深度。计算模块还可以根据获取的n个顶点的深度,进行加权平均计算,从而获取该模型的深度。其中,加权平均中涉及的权重,可以是预先设置的,也可以是灵活调整的。As a possible implementation, the calculation module can recall n random vertex coordinates among all currently stored vertex coordinates from the memory when the depth calculation is triggered. The calculation module can perform matrix transformation on the coordinates of the n vertices according to the above formula (1) according to the MVP matrix, so as to obtain the clipping coordinates of the n vertices. The calculation module can obtain the depth of each vertex according to the clipping coordinates of the n vertices. The calculation module can also perform weighted average calculation according to the obtained depths of the n vertices, so as to obtain the depth of the model. Wherein, the weight involved in the weighted average may be preset or flexibly adjusted.
需要说明的是,上述示例中,是以计算模块从存储器中调取顶点坐标时,就实现了n个顶点的随机选取为例进行说明的。在另一些实现中,计算模块还可以从存储器中调取所有存储的顶点坐标,在进行深度计算时,计算模块可以从调取的所有顶点坐标中,选取n个顶点坐标进行深度计算,其他顶点坐标不作处理或者丢弃。由此也可以实现n个顶点坐标的随机选取。It should be noted that, in the above example, the random selection of n vertices is realized as an example when the calculation module retrieves the coordinates of vertices from the memory. In other implementations, the calculation module can also recall all stored vertex coordinates from the memory. When performing depth calculations, the calculation module can select n vertex coordinates from all the recalled vertex coordinates for depth calculation. Other vertices The coordinates are not processed or discarded. In this way, the random selection of n vertex coordinates can also be realized.
在本申请的另一些实施例中,电子设备可以根据当前drawcall对应模型的大小,采取不同的策略确定该模型的深度。其中,模型的大小可以通过顶点数量进行标识。In some other embodiments of the present application, the electronic device may adopt different strategies to determine the depth of the model according to the size of the model corresponding to the current drawcall. Among them, the size of the model can be identified by the number of vertices.
以拦截模块拦截到drawelement触发计算模块的深度计算为例。Take the interception module to intercept the depth calculation of the drawelement trigger calculation module as an example.
电子设备可以根据拦截到的drawelement中指示的GLsizel count数值,确定当前模型的顶点数量。The electronic device can determine the number of vertices of the current model according to the GLsizeel count value indicated in the intercepted drawelement.
电子设备可以根据该确定的顶点数量,与预设的顶点数量阈值的大小关系,确定当前模型为大模型或小模型。比如,该顶点数量阈值可以为5000。那么,当count值大于5000时,则认为当前模型为大模型。对应的,当count值小于5000时,则认为当前模型为小模型。The electronic device may determine that the current model is a large model or a small model according to a size relationship between the determined number of vertices and a preset threshold of the number of vertices. For example, the vertex quantity threshold may be 5000. Then, when the count value is greater than 5000, the current model is considered to be a large model. Correspondingly, when the count value is less than 5000, the current model is considered to be a small model.
本申请实施例分别针对大模型和小模型,提供不同的深度计算策略,以便于更加合理地计算模型深度。The embodiments of the present application provide different depth calculation strategies for large models and small models, so as to calculate the model depth more reasonably.
示例性的,对于大模型,电子设备可以选取当前模型的所有顶点中,x,y,z分量最大或最小的6个顶点。计算着6个顶点的深度,并取均值,确定为当前模型的深度。Exemplarily, for a large model, the electronic device may select 6 vertices with the largest or smallest x, y, and z components among all vertices of the current model. The depth of the 6 vertices is calculated, and the average value is taken to determine the depth of the current model.
比如,以当前模型的顶点中,x分量最大的顶点P1坐标为(xmax,y1,z1),x分量最小的顶点P2坐标为(xmin,y2,z2),y分量最大的顶点P3坐标为(x3,ymax,z3),y分量最小的顶点P4坐标为(x4,ymin,z4),z分量最大的顶点P5坐标为(x5,y5,zmax),x分量最小的顶点P6坐标为(x6,y6,zmin)为例。For example, among the vertices of the current model, the coordinates of the vertex P1 with the largest x component are (x max , y1, z1), the coordinates of the vertex P2 with the smallest x component are (x min , y2, z2), and the coordinates of the vertex P3 with the largest y component is (x3, y max , z3), the coordinate of the vertex P4 with the smallest y component is (x4, y min , z4), the coordinate of the vertex P5 with the largest z component is (x5, y5, z max ), and the vertex P6 with the smallest x component The coordinates are (x6, y6, z min ) as an example.
经过MVP矩阵变换之后,P1-P6在裁剪坐标下的坐标分别为:P1(x’ max,y’1,z’1),P2(x’ min,y’2,z’2),P3(x’3,y’ max,z’3),P4(x’4,y’ min,z’4),P5(x’5,y’5,z’ max),P6(x’6,y’6,z’ min)。After MVP matrix transformation, the coordinates of P1-P6 under the clipping coordinates are: P1(x ' max , y ' 1, z ' 1), P2(x ' min , y ' 2, z ' 2), P3( x'3 , y'max , z'3 ), P4( x'4 , y'min , z'4 ), P5(x'5 , y'5 , z'max ), P6( x'6 , y ' 6, z'min ) .
那么,电子设备可以确定当前模型的深度为(z’1+z’2+z’3+z’4+z’ max+z’ min)/6。Then, the electronic device can determine that the depth of the current model is (z ' 1+z ' 2+z ' 3+z ' 4+z ' max +z ' min )/6.
在另一些实现中,对于小模型,电子设备可以在当前模型的所有顶点中,随机选取n个顶点。计算这n个顶点的深度,并取均值作为当前模型的深度。例如,该n可以是预先配置的,如n可以在20-100之间取任意整数。In other implementations, for a small model, the electronic device may randomly select n vertices from all vertices of the current model. Calculate the depth of these n vertices, and take the mean value as the depth of the current model. For example, the n may be pre-configured, for example, n may be any integer between 20-100.
可以理解的是,在上述示例中,对于大模型,电子设备可以选取最边缘的顶点用于计算模型的深度,从而使得在模型的不同顶点深度差异较大的情况下,能够通过该计算方法真实准确地标识大模型的深度。而对于小模型,由于模型尺寸的限制,因此该模型不同顶点的深度不会有较大差别,因此,在本示例中,可以从模型上选取预设个数(或者随机个数)的顶点,分别计算其深度并取均值确定为该模型的深度。It can be understood that, in the above example, for a large model, the electronic device can select the edgemost vertices to calculate the depth of the model, so that when the depth of different vertices of the model differs greatly, the calculation method can be used to truly Accurately identify the depth of large models. For a small model, due to the limitation of the model size, the depth of different vertices of the model will not be greatly different. Therefore, in this example, a preset number (or a random number) of vertices can be selected from the model. Calculate their depths respectively and take the mean value to determine the depth of the model.
需要说明的是,上述示例中,是以裁剪坐标下的z坐标值作为对应顶点的深度为例进行说明的。在本申请的另一些实施例中,顶点的深度还可以是根据裁剪坐标下的z坐标值确定的。示例性的,顶点深度可以根据标准化设备坐标(Normalized Device Coordinate,NDC)下的顶点的z坐标确定。例如,在获取顶点在裁剪空间中的坐标之后,可以通过透视除法,获取NDC空间中的z坐标。这样,该NDC空间中的z坐标就可以用于标识该顶点的深度。此外,上述示例中,根据裁剪空间的深度z确定模型深度,用于标识该模型在展示给用户时的图像中的远近程度,仅为一种可能的实现。在本申请另一些示例中,模型的远近程度(即模型的深度)还可以通过该模型在观察空间中的基于观察坐标的模长标识的。也就是说,模型的远近程度也可以是在观察空间中,根据模型到摄像机的距离确定的。It should be noted that, in the above example, the z coordinate value under the clipping coordinates is taken as the depth of the corresponding vertex as an example for illustration. In other embodiments of the present application, the depth of the vertex may also be determined according to the z coordinate value under the clipping coordinates. Exemplarily, the vertex depth may be determined according to the z-coordinate of the vertex under normalized device coordinates (Normalized Device Coordinate, NDC). For example, after obtaining the coordinates of the vertex in the clip space, the z coordinate in the NDC space can be obtained by perspective division. In this way, the z-coordinate in the NDC space can be used to identify the depth of the vertex. In addition, in the above example, determining the depth of the model according to the depth z of the clipping space is used to identify the distance of the model in the image displayed to the user, which is only a possible implementation. In other examples of the present application, the distance of the model (that is, the depth of the model) can also be identified by the model length based on the observation coordinates of the model in the observation space. That is to say, the distance of the model can also be determined according to the distance from the model to the camera in the observation space.
可以看到,本申请的上述说明中,电子设备中的各个模块,可以通过获取模型的顶点坐标,并对这些顶点坐标进行处理,获取模型的深度。在本申请的另一些实现中,电子设备中的各个模块还可以通过获取其他模型的信息,确定模型的深度。示例性的,以获取模型的包围盒信息确定模型的深度为例。拦截模块可以用于将渲染命令中的包围盒信息相关指令进行拦截,并将这些信息传输给数据处理模块。数据处理模块和/或计算模块可以用于根据拦截获取的包围盒信息,确定当前模型的深度。It can be seen that in the above description of the present application, each module in the electronic device can obtain the depth of the model by obtaining the vertex coordinates of the model and processing these vertex coordinates. In some other implementations of the present application, each module in the electronic device may also determine the depth of the model by obtaining information of other models. Exemplarily, take obtaining the bounding box information of the model to determine the depth of the model as an example. The interception module can be used to intercept bounding box information-related instructions in the rendering command, and transmit the information to the data processing module. The data processing module and/or the calculation module can be used to determine the depth of the current model according to the bounding box information obtained by interception.
这样,电子设备就可以通过计算模块的计算,获取当前drawcall对应模型的深度。In this way, the electronic device can obtain the depth of the model corresponding to the current drawcall through the calculation of the calculation module.
在本申请实施例中,计算模块可以配合决策模块,确定是否对当前drawcall对应模型执行可变速率着色,如对当前drawcall对应模型执行较低速率着色。In this embodiment of the present application, the calculation module may cooperate with the decision module to determine whether to perform variable rate shading on the model corresponding to the current drawcall, for example, perform lower rate shading on the model corresponding to the current drawcall.
示例性的,决策模块可以根据计算模块计算获取的模型的深度,确定对该模型执行的着色速率。在本申请实施例中,决策模块中可以配置有(或者从内存中调取)不同模型深度对应的着色速率。如果当前的模型深度对应的着色速率为较低的着色速率(即着色速率小于以1个像素为单位的着色速率)时,决策模块可以在向硬件层传递该drawcall对应的drawelement时,从系统库的图形库中调取对应的可变速率着色API。Exemplarily, the decision module may determine the shading rate performed on the model according to the depth of the model calculated and obtained by the calculation module. In the embodiment of the present application, the decision module may be configured with (or retrieved from memory) shading rates corresponding to different model depths. If the shading rate corresponding to the current model depth is a lower shading rate (that is, the shading rate is less than the shading rate in units of 1 pixel), the decision-making module can transfer the drawelement corresponding to the drawcall to the hardware layer, from the system library The corresponding variable rate shading API is called in the graphics library of .
作为一种示例,以下表2示出了一种模型深度与着色速率的对应关系示意。As an example, Table 2 below shows a schematic representation of the correspondence relationship between model depth and shading rate.
表2Table 2
如表2所示,在模型深度小于10的情况下,则决策模块可以确定当前模型使用1×1的着色速率进行着色。即当前模型的深度较小,不需要使用可变速率着色机制。那么决策模块可以不需调用可变速率着色API,而直接将游戏应用下发的渲染命令对应的渲染指令下发给硬件层(如下发给硬件层的GPU),以便于GPU以1个像素为单位,执行当前渲染命令的渲染操作。As shown in Table 2, when the depth of the model is less than 10, the decision-making module can determine that the current model uses a shading rate of 1×1 for shading. That is, the depth of the current model is small, and there is no need to use the variable rate shading mechanism. Then the decision-making module does not need to call the variable rate shading API, but directly sends the rendering command corresponding to the rendering command issued by the game application to the hardware layer (sent to the GPU of the hardware layer as follows), so that the GPU uses 1 pixel as the Unit to perform rendering operations for the current rendering command.
在模型深度大于10且小于或等于50的情况下,则决策模块可以确定当前模型使用2×1的着色速率进行着色。那么决策模块可以在向硬件层(如硬件层的GPU)下发渲染命令对应的渲染指令时,调用可变速率着色API,并将着色速率设置为2×1,以便于GPU通过2×1的着色速率执行当前渲染命令的渲染操作。In the case that the model depth is greater than 10 and less than or equal to 50, the decision module may determine that the current model uses 2×1 shading rate for shading. Then the decision-making module can call the variable rate shading API and set the shading rate to 2×1 so that the GPU can pass the 2×1 The shading rate performs the rendering operations of the current rendering command.
在模型深度大于50且小于或等于100的情况下,则决策模块可以确定当前模型使用2×2的着色速率进行着色。那么决策模块可以在向硬件层(如硬件层的GPU)下发渲染命令对应的渲染指令时,调用可变速率着色API,并将着色速率设置为2×2,以便于GPU通过2×2的着色速率执行当前渲染命令的渲染操作。In the case that the model depth is greater than 50 and less than or equal to 100, the decision module may determine that the current model uses 2×2 shading rate for shading. Then the decision-making module can call the variable rate shading API and set the shading rate to 2×2, so that the GPU can pass the 2×2 The shading rate performs the rendering operations of the current rendering command.
在模型深度大于100且小于或等于200的情况下,则决策模块可以确定当前模型使用4×2的着色速率进行着色。那么决策模块可以在向硬件层(如硬件层的GPU)下发渲染命令对应的渲染指令时,调用可变速率着色API,并将着色速率设置为4×2,以便于GPU通过4×2的着色速率执行当前渲染命令的渲染操作。In the case that the model depth is greater than 100 and less than or equal to 200, the decision module may determine that the current model uses 4×2 shading rate for shading. Then the decision-making module can call the variable rate shading API and set the shading rate to 4×2, so that the GPU can pass the 4×2 The shading rate performs the rendering operations of the current rendering command.
在模型深度大于200的情况下,则决策模块可以确定当前模型使用4×4的着色速率进行着色。那么决策模块可以在向硬件层(如硬件层的GPU)下发渲染命令对应的渲染指令时,调用可变速率着色API,并将着色速率设置为4×4,以便于GPU通过4×4的着色速率执行当前渲染命令的渲染操作。If the depth of the model is greater than 200, the decision module may determine that the current model uses 4×4 shading rate for shading. Then the decision-making module can call the variable rate shading API and set the shading rate to 4×4, so that the GPU can pass the 4×4 The shading rate performs the rendering operations of the current rendering command.
此外,拦截模块还可以将命令2的其他指令回调给图形库,以便通过调用图形库中对应的API,可以采用上述方案中确定的着色速率执行对应的渲染操作。In addition, the interception module can also call back other instructions of command 2 to the graphics library, so that by calling the corresponding API in the graphics library, the corresponding rendering operation can be performed at the shading rate determined in the above solution.
为了使得本领域技术人员能够更加清楚地明确本申请实施例提供的方案,以下从指令流的角度,对本申请实施例提供的方案继续进行说明。示例性的,参考图11,该流程可以包括:In order to enable those skilled in the art to more clearly understand the solutions provided by the embodiments of the present application, the following continues to describe the solutions provided by the embodiments of the present application from the perspective of instruction flow. Exemplarily, referring to FIG. 11, the process may include:
S1101、拦截模块以及数据处理模块确定当前模型在备份存储中的顶点坐标和MVP矩阵。S1101. The interception module and the data processing module determine the vertex coordinates and the MVP matrix of the current model in the backup storage.
示例性的,拦截模块可以根据游戏应用下发的指令N,确定当前模型的顶点坐标在备份存储中的存储位置。数据处理模块可以根据游戏应用下发的指令M,确定当前模型的MVP矩阵在备份存储中的存储位置。Exemplarily, the interception module may determine the storage location of the vertex coordinates of the current model in the backup storage according to the instruction N issued by the game application. The data processing module can determine the storage location of the MVP matrix of the current model in the backup storage according to the instruction M issued by the game application.
该S1101的具体执行过程,可以参考图9的相关说明,此处不再赘述。For the specific execution process of S1101 , reference may be made to the relevant description in FIG. 9 , which will not be repeated here.
S1102、计算模块从内存中获取顶点坐标以及MVP矩阵。S1102. The calculation module obtains the vertex coordinates and the MVP matrix from the memory.
示例性的,在数据处理模块将顶点坐标以及MVP矩阵存储到特定位置的情况下,计算模块可以从该特定位置获取顶点坐标以及MVP矩阵。在另一些实施例中,在数据处理模块对顶点坐标以及MVP矩阵的存储位置作了标识的情况下,计算模块可以根据该标识,从内存中获取顶点坐标以及MVP矩阵。Exemplarily, in the case that the data processing module stores the vertex coordinates and the MVP matrix in a specific location, the calculation module can obtain the vertex coordinates and the MVP matrix from the specific location. In some other embodiments, when the data processing module identifies the storage locations of the vertex coordinates and the MVP matrix, the calculation module can obtain the vertex coordinates and the MVP matrix from the memory according to the identification.
在本申请的一些实施例中,计算模块获取顶点坐标以及MVP矩阵可以是游戏应用下发指令R之后进行的。其中,该指令R中可以包括一个或多个Drawelement。In some embodiments of the present application, the computing module may obtain the vertex coordinates and the MVP matrix after the game application issues the instruction R. Wherein, the instruction R may include one or more Drawelements.
示例性的,拦截模块可以在接收到指令R时,指示计算模块执行该S1102。Exemplarily, the interception module may instruct the calculation module to execute S1102 when receiving the instruction R.
S1103、计算模块计算模型深度。S1103. The calculation module calculates the model depth.
S1104、计算模块向决策模块发送模型深度。S1104. The calculation module sends the model depth to the decision module.
S1105、决策模块确定当前模型的着色速率1。S1105. The decision module determines the shading rate 1 of the current model.
其中,确定模型深度,以及根据模型深度确定对应的着色速率(如着色速率1)的过程,可以参考上述说明,此处不再赘述。Wherein, the process of determining the model depth and determining the corresponding shading rate (such as shading rate 1) according to the model depth can refer to the above description, and will not be repeated here.
S1106、决策模块调用图形库的调用对应API。示例性的,该对应API可以是与着色速率1对应的可变速率着色API 1。S1106. The decision-making module calls the corresponding API of the graphics library. Exemplarily, the corresponding API may be variable rate shading API 1 corresponding to shading rate 1.
S1107、图形库对应调用可变速率着色API 1。S1107. The graphics library correspondingly calls the variable rate shading API 1.
这样,电子设备就可以根据模型的深度,调用图形库中对应的API,以便于控制硬件层中的部件(如GPU)执行对应的可变速率着色。In this way, the electronic device can call the corresponding API in the graphics library according to the depth of the model, so as to control the components in the hardware layer (such as GPU) to perform corresponding variable-rate shading.
结合前述说明,在本示例中,电子设备可以在执行上述S1101-S1107之外,将接收到的游戏应用的命令进行指令回调,从而使得指令得到正确执行。With reference to the foregoing description, in this example, the electronic device may, in addition to executing the above S1101-S1107, perform an instruction callback on the received command of the game application, so that the instruction is correctly executed.
示例性的,该过程可以包括:Exemplarily, the process may include:
S1108、拦截模块以及数据处理模块回调相关指令。S1108, the interception module and the data processing module call back related instructions.
其中,该相关指令可以包括指令N对应的回调指令3-1,回调指令3-2,以及指令M对应的回调指令4-1,回调指令4-2。该回调过程以及内容请参考图9的说明,此处不再赘述。Wherein, the relevant instructions may include a callback instruction 3-1 and a callback instruction 3-2 corresponding to the instruction N, and a callback instruction 4-1 and a callback instruction 4-2 corresponding to the instruction M. Please refer to the description of FIG. 9 for the callback process and content, and details are not repeated here.
在本示例中,该相关指令还可以包括指令R的指令。In this example, the related instruction may also include an instruction R.
S1109、图形库调用对应的API。该对应API可以包括用于实现指令N,指令M以及指令R所指示功能的API。S1109. The graphics library calls the corresponding API. The corresponding API may include an API for realizing the functions indicated by the instruction N, the instruction M, and the instruction R.
S1110、图形库向GPU发送指令2。该指令2可以包括上述通过调用API获取的对应代码。示例性的,该指令2中可以包括调用可变速率着色API 1获取的对应代码,基于该代码可以实现着色速率1的可变速率着色。S1110. The graphics library sends instruction 2 to the GPU. The instruction 2 may include the above-mentioned corresponding code obtained by calling the API. Exemplarily, the instruction 2 may include the corresponding code obtained by calling the variable rate shading API 1, and the variable rate shading of the shading rate 1 can be realized based on the code.
S1111、GPU执行基于着色速率1对应的渲染操作。S1111. The GPU executes a rendering operation corresponding to the shading rate 1.
这样,电子设备就能够实现以drawcall为粒度,根据当前渲染命令中模型的深度,灵活调整可变速率着色的使用机制,从而达到在不影响用户体验的同时,降低着色处理过程中的渲染开销的效果。In this way, the electronic device can flexibly adjust the use mechanism of variable rate shading according to the depth of the model in the current rendering command at the granularity of drawcall, so as to achieve the goal of reducing the rendering overhead in the shading process without affecting the user experience. Effect.
应当理解的是,上述示例中,是以游戏应用下发命令进行一个模型绘制为例,对其中的具体实施细节进行说明的。在实际实施过程中,游戏应用可以下发多个命令,进行多个模型的绘制。在各个模型的绘制过程中,也可以采用上述方案实现根据各个模型的深度对其进行自适应的可变速率着色。It should be understood that, in the above example, a game application sends a command to draw a model as an example, and the specific implementation details thereof are described. In the actual implementation process, the game application can issue multiple commands to draw multiple models. In the drawing process of each model, the above solution can also be used to implement adaptive variable rate shading according to the depth of each model.
示例性的,以命令1用于进行数据加载,命令2用于绘制模型1,命令3用于绘制模型2为例。Exemplarily, command 1 is used to load data, command 2 is used to draw model 1, and command 3 is used to draw model 2 as an example.
参考图12,游戏应用可以分别下发命令1,命令2,以及命令3。Referring to FIG. 12 , the game application can issue command 1, command 2, and command 3 respectively.
对于命令1,框架层设置的各个模块可以根据如图6或图8所示的方案进行顶点数据和/或MVP矩阵的备份存储。同时,框架层中的各个模块还可以结合如图8所示的回调机制,实现命令1对应数据的加载。比如,框架层可以根据命令1,调用图形库中响应的API,以便向GPU下发命令1对应的指令1,从而完成数据的加载。For command 1, each module set at the framework layer can perform backup storage of vertex data and/or MVP matrix according to the scheme shown in FIG. 6 or FIG. 8 . At the same time, each module in the framework layer can also combine the callback mechanism shown in Figure 8 to realize the loading of data corresponding to command 1. For example, the framework layer can call the corresponding API in the graphics library according to the command 1, so as to issue the command 1 corresponding to the command 1 to the GPU, so as to complete the data loading.
对于命令2,框架层设置的各个模块可以根据如图7,图9,图10以及图11所示的方案,根据确定该命令2要绘制的模型1的深度,进而确定模型1对应的着色速率(如着色速率1)。结合回调机制,框架层可以基于命令2,以及着色速率1,调用图形库中对应的API,以便向GPU下发指令2。GPU就可以根据该指令2,按照着色速率1的着色参数,进行模型1的绘制。由此即可获取如图12所示的模型1。作为一种示例,该模型1可以被存储在预先分配的与命令2对应的帧缓冲(如帧缓冲1)中。For command 2, each module set in the framework layer can determine the corresponding shading rate of model 1 according to the depth of model 1 to be drawn by the command 2 according to the scheme shown in Fig. 7, Fig. 9, Fig. 10 and Fig. 11 (such as shader rate 1). Combined with the callback mechanism, the framework layer can call the corresponding API in the graphics library based on command 2 and shading rate 1, so as to issue command 2 to the GPU. According to the instruction 2, the GPU can draw the model 1 according to the shading parameters of the shading rate 1. Thus, model 1 as shown in FIG. 12 can be obtained. As an example, the model 1 may be stored in a pre-allocated frame buffer corresponding to the command 2 (such as frame buffer 1).
类似于命令2,对于命令3,框架层设置的各个模块可以根据如图7,图9,图10以及图11所示的方案,根据确定该命令3要绘制的模型2的深度,进而确定模型2对应的着色速率(如着色速率2)。结合回调机制,框架层可以基于命令3,以及着色速率2,调用图形库中对应的API,以便向GPU下发指令3。GPU就可以根据该指令3,按照着色速率2的着色参数,进行模型2的绘制。由此即可获取如图12所示的模型2。作为一种示例,该模型1可以被存储在预先分配的与命令2对应的帧缓冲(如帧缓冲2)中。Similar to command 2, for command 3, each module set at the framework layer can be determined according to the scheme shown in Figure 7, Figure 9, Figure 10 and Figure 11, and then determine the model according to the depth of the model 2 to be drawn by the command 3 2 corresponds to a shading rate (such as shading rate 2). Combined with the callback mechanism, the framework layer can call the corresponding API in the graphics library based on command 3 and shading rate 2, so as to issue command 3 to the GPU. According to the instruction 3, the GPU can draw the model 2 according to the shading parameters of the shading rate 2. Thus, the model 2 shown in FIG. 12 can be obtained. As an example, the model 1 may be stored in a pre-allocated frame buffer corresponding to the command 2 (such as frame buffer 2).
以模型1和模型2属于同一个帧图像为例。在展示该帧图像之前,GPU还可以将帧缓冲1和帧缓冲2上的图像渲染到一个基础帧缓冲(如帧缓冲0)上,从而获取该帧图像的全量内容。示例性的,参考图13,GPU可以将模型1和模型2渲染到同一个画布上。Take model 1 and model 2 belonging to the same frame image as an example. Before displaying the frame image, the GPU can also render the images on frame buffer 1 and frame buffer 2 to a basic frame buffer (such as frame buffer 0), so as to obtain the full content of the frame image. Exemplarily, referring to FIG. 13 , the GPU can render model 1 and model 2 on the same canvas.
应当理解的是,由于采用了本申请实施例提供的可变速率着色的机制,对于不同深度的模型的深度可以是不同的。以模型1的深度小于模型2的深度为例。即模型1更加靠近用户,而模型2会距离用户远一些。结合前述说明,对于深度较小的模型1,可以采用较高的着色速率对其进行着色。比如,以模型1的着色速率为1×1为例。那么对模型1的着色过程中,可以以一个像素为单位,以此对模型1包括的各个像素进行着色。对应的,对于深度较大的模型2,可以采用较低的着色速率对其进行着色。比如,以模型2的着色速率为2×2为例。那么对模型2的着色过程中,可以以2×2个像素为单位,以此对模型2包括像素进行着色。It should be understood that due to the adoption of the variable rate shading mechanism provided by the embodiment of the present application, the depths of models with different depths may be different. Take the example where the depth of model 1 is less than that of model 2. That is, model 1 is closer to the user, while model 2 is farther away from the user. In combination with the foregoing description, for model 1 with a smaller depth, it can be shaded with a higher shading rate. For example, take model 1 with a shading rate of 1×1 as an example. Then, in the coloring process of the model 1, each pixel included in the model 1 may be colored in units of one pixel. Correspondingly, for the model 2 with a larger depth, it can be shaded with a lower shading rate. For example, take model 2 with a shading rate of 2×2. Then, in the coloring process of the model 2, the pixels included in the model 2 can be colored in units of 2×2 pixels.
由此,完成着色操作之后(如完成所有渲染操作,并将两个模型渲染到一个画布上之后),在模型1包括的像素中,就可以看到每个像素的颜色都可以是不同的。而对于模型2包括的像素中,就会存在大量相邻的2×2个像素的颜色相同或相近。由此,就能够使得对于距离用户较近的模型的色彩得到更加精确的渲染和展示。对应的,距离用户较远的模型的色彩粒度可以较大,由此节省对应的渲染开销。Thus, after the coloring operation is completed (for example, after all rendering operations are completed and the two models are rendered on a canvas), among the pixels included in model 1, it can be seen that the color of each pixel can be different. For the pixels included in model 2, there will be a large number of adjacent 2×2 pixels with the same or similar colors. As a result, the color of the model closer to the user can be rendered and displayed more accurately. Correspondingly, the color granularity of the model farther away from the user can be larger, thereby saving the corresponding rendering overhead.
上述主要从电子设备的角度对本申请实施例提供的方案进行了介绍。为了实现上述功能,其包含了执行各个功能相应的硬件结构和/或软件模块。本领域技术人员应该很容易意识到,结合本文中所公开的实施例描述的各示例的单元及算法步骤,本申请能够以硬件或硬件和计算机软件的结合形式来实现。某个功能究竟以硬件还是计算机软件驱动硬件的方式来执行,取决于技术方案的特定应用和设计约束条件。专业技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本申请的范围。The foregoing mainly introduces the solutions provided by the embodiments of the present application from the perspective of electronic devices. In order to realize the above functions, it includes corresponding hardware structures and/or software modules for performing various functions. Those skilled in the art should easily realize that the present application can be implemented in the form of hardware or a combination of hardware and computer software in combination with the units and algorithm steps of each example described in the embodiments disclosed herein. Whether a certain function is executed by hardware or computer software drives hardware depends on the specific application and design constraints of the technical solution. Skilled artisans may use different methods to implement the described functions for each specific application, but such implementation should not be regarded as exceeding the scope of the present application.
本申请实施例可以根据上述方法示例对其中涉及的设备进行功能模块的划分,例如,可以对应各个功能划分各个功能模块,也可以将两个或两个以上的功能集成在一个处理模块中。上述集成的模块既可以采用硬件的形式实现,也可以采用软件功能模块的形式实现。需要说明的是,本申请实施例中对模块的划分是示意性的,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式。The embodiments of the present application may divide the involved devices into functional modules according to the above method example, for example, each functional module may be divided corresponding to each function, or two or more functions may be integrated into one processing module. The above-mentioned integrated modules can be implemented in the form of hardware or in the form of software function 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, and there may be other division methods in actual implementation.
示例性的,图14示出了的一种电子设备1400的组成示意图。如图14所示,该电子设备1400可以包括:处理器1401和存储器1402。该存储器1402用于存储计算机执行指令。示例性的,在一些实施例中,当该处理器1401执行该存储器1402存储的指令时,可以使得该电子设备1400执行上述实施例中任一种所示的图像渲染方法。Exemplarily, FIG. 14 shows a schematic composition diagram of an electronic device 1400 . As shown in FIG. 14 , the electronic device 1400 may include: a processor 1401 and a memory 1402 . The memory 1402 is used to store computer-executable instructions. Exemplarily, in some embodiments, when the processor 1401 executes the instruction stored in the memory 1402, the electronic device 1400 may be made to execute the image rendering method shown in any one of the above embodiments.
需要说明的是,上述方法实施例涉及的各步骤的所有相关内容均可以援引到对应功能模块的功能描述,在此不再赘述。It should be noted that all relevant content of the steps involved in the above method embodiments can be referred to the function description of the corresponding function module, and will not be repeated here.
在上述实施例中的功能或动作或操作或步骤等,可以全部或部分地通过软件、硬件、固件或者其任意组合来实现。当使用软件程序实现时,可以全部或部分地以计算机程序产品的形式来实现。该计算机程序产品包括一个或多个计算机指令。在计算机上加载和执行计算机程序指令时,全部或部分地产生按照本申请实施例所述的流程或功能。所述计算机可以是通用计算机、专用计算机、计算机网络、或者其他可编程装置。所述计算机指令可以存储在计算机可读存储介质中,或者从一个计算机可读存储介质向另一个计算机可读存储介质传输,例如,所述计算机指令可以从一个网站站点、计算机、服务器或者数据中心通过有线(例如同轴电缆、光纤、数字用户线(digital subscriber line,DSL))或无线(例如红外、无线、微波等)方式向另一个网站站点、计算机、服务器或数据中心进行传输。所述计算机可读存储介质可以是计算机能够存取的任何可用介质或者是包括一个或多个可以用介质集成的服务器、数据中心等数据存储设备。所述可用介质可以是磁性介质(例如,软盘、硬盘、磁带),光介质(例如,DVD)、或者半导体介质(例如固态硬盘(solid state disk,SSD))等。The functions or actions or operations or steps in the above-mentioned embodiments may be fully or partially implemented by software, hardware, firmware or any combination thereof. When implemented using a software program, it may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on the computer, the processes or functions according to the embodiments of the present application will be generated in whole or in part. The computer can be a general purpose computer, a special purpose computer, a computer network, or other programmable devices. The computer instructions may be stored in or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions may be transmitted from a website, computer, server, or data center Transmission to another website site, computer, server or data center by wired (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (such as infrared, wireless, microwave, etc.). The computer-readable storage medium may be any available medium that can be accessed by a computer, or may include one or more data storage devices such as servers and data centers that can be integrated with the medium. The available medium may be a magnetic medium (such as a floppy disk, a hard disk, or a magnetic tape), an optical medium (such as a DVD), or a semiconductor medium (such as a solid state disk (solid state disk, SSD)) and the like.
尽管结合具体特征及其实施例对本申请进行了描述,显而易见的,在不脱离本申请的精神和范围的情况下,可对其进行各种修改和组合。相应地,本说明书和附图仅仅是所附权利要求所界定的本申请的示例性说明,且视为已覆盖本申请范围内的任意和所有修改、变化、组合或等同物。显然,本领域的技术人员可以对本申请进行各种改动和变型而不脱离本申请的精神和范围。这样,倘若本申请的这些修改和变型属于本申请权利要求及其等同技术的范围之内,则本申请也意图包括这些改动和变型在内。Although the application has been described in conjunction with specific features and embodiments thereof, it will be apparent that various modifications and combinations can be made thereto without departing from the spirit and scope of the application. Accordingly, the specification and drawings are merely illustrative of the application as defined by the appended claims and are deemed to cover any and all modifications, variations, combinations or equivalents within the scope of this application. Obviously, those skilled in the art can make various changes and modifications to the application without departing from the spirit and scope of the application. In this way, if these modifications and variations of the application fall within the scope of the claims of the application and their equivalent technologies, the application also intends to include these modifications and variations.
Claims (19)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202310227425.5A CN116703693A (en) | 2021-08-18 | 2021-08-18 | Image rendering method and electronic device |
Applications Claiming Priority (2)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202310227425.5A CN116703693A (en) | 2021-08-18 | 2021-08-18 | Image rendering method and electronic device |
CN202110951444.3A CN113837920B (en) | 2021-08-18 | 2021-08-18 | Image rendering method and electronic device |
Related Parent Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202110951444.3A Division CN113837920B (en) | 2021-08-18 | 2021-08-18 | Image rendering method and electronic device |
Publications (1)
Publication Number | Publication Date |
---|---|
CN116703693A true CN116703693A (en) | 2023-09-05 |
Family
ID=78960776
Family Applications (2)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202310227425.5A Pending CN116703693A (en) | 2021-08-18 | 2021-08-18 | Image rendering method and electronic device |
CN202110951444.3A Active CN113837920B (en) | 2021-08-18 | 2021-08-18 | Image rendering method and electronic device |
Family Applications After (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202110951444.3A Active CN113837920B (en) | 2021-08-18 | 2021-08-18 | Image rendering method and electronic device |
Country Status (1)
Country | Link |
---|---|
CN (2) | CN116703693A (en) |
Families Citing this family (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN115082609B (en) * | 2022-06-14 | 2025-02-14 | Oppo广东移动通信有限公司 | Image rendering method, device, storage medium and electronic device |
CN117635789A (en) * | 2022-08-18 | 2024-03-01 | 华为技术有限公司 | Coloring methods, coloring devices and electronic equipment |
CN117710404A (en) * | 2022-09-07 | 2024-03-15 | 荣耀终端有限公司 | Image processing method and electronic device |
CN116401062B (en) * | 2023-04-13 | 2023-09-12 | 北京大学 | A server-less resource processing method, device and electronic equipment |
US20240386648A1 (en) * | 2023-05-19 | 2024-11-21 | Mediatek Inc. | Method for performing automatic activation control regarding variable rate shading, and associated apparatus |
Family Cites Families (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US10275547B2 (en) * | 2015-06-03 | 2019-04-30 | The Mathworks, Inc. | Method and system for assessing performance of arbitrarily large arrays |
US9916682B2 (en) * | 2015-10-28 | 2018-03-13 | Intel Corporation | Variable precision shading |
CN106504185B (en) * | 2016-10-26 | 2020-04-07 | 腾讯科技(深圳)有限公司 | Rendering optimization method and device |
CN111062858B (en) * | 2019-12-27 | 2023-09-15 | 西安芯瞳半导体技术有限公司 | Efficient advance rendering method, device and computer storage medium |
-
2021
- 2021-08-18 CN CN202310227425.5A patent/CN116703693A/en active Pending
- 2021-08-18 CN CN202110951444.3A patent/CN113837920B/en active Active
Also Published As
Publication number | Publication date |
---|---|
CN113837920A (en) | 2021-12-24 |
CN113837920B (en) | 2023-03-10 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN115473957B (en) | Image processing method and electronic device | |
CN113837920B (en) | Image rendering method and electronic device | |
CN109559270B (en) | Image processing method and electronic equipment | |
US20220107821A1 (en) | User interface layout method and electronic device | |
WO2022161119A1 (en) | Display method and electronic device | |
CN113254120A (en) | Data processing method and related device | |
WO2022095744A1 (en) | Vr display control method, electronic device, and computer readable storage medium | |
CN113935898A (en) | Image processing method, system, electronic device and computer readable storage medium | |
US12079537B2 (en) | Screen projection method and system, and related apparatus | |
WO2023016014A1 (en) | Video editing method and electronic device | |
CN115145436B (en) | Icon processing method and electronic equipment | |
CN116055627B (en) | Screen-off control method, electronic equipment and storage medium | |
WO2022078116A1 (en) | Brush effect picture generation method, image editing method and device, and storage medium | |
CN116095224A (en) | Notification display method and terminal device | |
CN117692714B (en) | Video display method, electronic device, computer program product, and storage medium | |
CN114356186A (en) | Method for realizing dragging shadow animation effect and related equipment | |
CN117764853B (en) | Face image enhancement method and electronic equipment | |
CN116266159B (en) | Page fault exception handling method and electronic equipment | |
US20240201932A1 (en) | Display method, electronic device, and system | |
CN112783993B (en) | Content synchronization method for multiple authorized spaces based on digital map | |
CN116704075A (en) | Image processing method, device and storage medium | |
WO2024046010A1 (en) | Interface display method, and device and system | |
CN117917632A (en) | Display method, electronic equipment and system | |
CN119254914A (en) | Image processing method, device and electronic equipment | |
CN119088253A (en) | Interaction method, electronic device and computer readable storage medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
CB02 | Change of applicant information |
Country or region after: China Address after: Unit 3401, unit a, building 6, Shenye Zhongcheng, No. 8089, Hongli West Road, Donghai community, Xiangmihu street, Futian District, Shenzhen, Guangdong 518040 Applicant after: Honor Terminal Co.,Ltd. Address before: 3401, unit a, building 6, Shenye Zhongcheng, No. 8089, Hongli West Road, Donghai community, Xiangmihu street, Futian District, Shenzhen, Guangdong Applicant before: Honor Device Co.,Ltd. Country or region before: China |