Image rendering method, device, computer equipment and storage medium
By combining the rendering channel with pre-compiled target shaders, the problem of low rendering efficiency on low-configured terminal devices is solved, and efficient image rendering processing is achieved to meet the needs of different platforms.
Patent Information
- Application Number
- CN202011395294.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-03
- Publication Date
- 2025-01-10
- Estimated Expiration
- 2041-01-10
AI Technical Summary
The existing rendering methods are inefficient in running on low-configured terminal devices and consume a lot of resources, resulting in long rendering processing time.
The pre-compiled target shader calls the graphics interface corresponding to the application, merges the rendering channels with dependencies, and performs image rendering processing, avoids intermediate result data being written to system memory and reduces bandwidth consumption.
It effectively improves the efficiency of image rendering processing, reduces resource consumption, adapts to different operating platforms, and improves rendering performance.
Smart Images

Figure CN112381918B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and in particular to an image rendering method, apparatus, computer equipment and storage medium. Background Art
[0002] Rendering is one of the important research topics in 3D computer graphics. In the graphics processing pipeline, rendering is the last important step, through which the final display effect of the model and animation is obtained. With the increasing complexity of computer graphics, rendering has become an increasingly important technology and is widely used in computer and video games, simulations, film and television special effects, and visual design. There are currently various rendering tools that can be integrated into larger modeling or animation packages.
[0003] The current rendering method is usually to use a fixed rendering pipeline through a specified graphics interface and shader for rendering processing. Usually, in the process of calling the graphics interface for rendering processing, a large amount of resources and a long time are consumed, and the operating efficiency is low on terminal devices with lower configuration. Summary of the invention
[0004] Based on this, it is necessary to provide an image rendering method, apparatus, computer device and storage medium that can effectively reduce resource consumption and effectively improve rendering efficiency in response to the above technical problems.
[0005] An image rendering method, the method comprising:
[0006] After obtaining the rendering instructions triggered by the application,
[0007] Calling a target shader corresponding to the graphics interface of the application from pre-compiled shaders for different types of graphics interfaces in the rendering engine; the pre-compiled shader is generated by compiling an original shader of the rendering engine;
[0008] Acquire scene data corresponding to the rendering target according to the rendering instruction, and write the scene data into a cache block;
[0009] Based on the target shader, merging rendering passes corresponding to the rendering target and having a dependency relationship into a same rendering pass in a cache block;
[0010] Performing image rendering processing on the scene data in the cache block in the same rendering pass to obtain an image rendering result in the cache block.
[0011] An image rendering device, the device comprising:
[0012] A target shader calling module is used to call a target shader corresponding to the graphics interface of the application from the pre-compiled shaders for different types of graphics interfaces in the rendering engine after obtaining the rendering instruction triggered by the application; the pre-compiled shader is generated by compiling the original shader of the rendering engine;
[0013] A data acquisition module, used for acquiring scene data corresponding to a rendering target according to the rendering instruction, and writing the scene data into a cache block;
[0014] A rendering processing module is used to merge the rendering channels with dependencies corresponding to the rendering target into the same rendering channel in a cache block based on the target shader; and perform image rendering processing on the scene data in the cache block in the same rendering channel to obtain an image rendering result in the cache block.
[0015] In one embodiment, the above-mentioned image rendering device also includes a shader compilation module, which is used to configure explicit description functions and marking functions corresponding to each type of graphics interface in the original shader of the rendering engine, so as to compile a shader corresponding to each of the graphics interfaces; wherein the explicit description function is used to add description information of each of the rendering channels; and the marking function is used to mark the start rendering identifier and the end rendering identifier of the merged rendering channel.
[0016] In one embodiment, the shader compilation module is also used to configure explicit description functions and marking functions corresponding to different types of graphics processors in the original shader of the rendering engine for each type of graphics interface, so as to compile shaders corresponding to each type of the graphics interface.
[0017] In one embodiment, the target shader calling module is also used to run the rendering engine in the application when the application starts running; the rendering hardware interface layer of the rendering engine includes different types of graphics interfaces; according to the running platform type of the application, determine from the different types of graphics interfaces the type of graphics interface in the application that corresponds to the running platform type.
[0018] In one embodiment, the target shader includes explicit description functions and marking functions corresponding to different types of graphics processors; the target shader calling module is also used to call the explicit description function and marking function corresponding to the type of the graphics processor from the target shader through the graphics processor; through the target shader, according to the explicit description function and marking function, the rendering channels with dependencies corresponding to the rendering target are merged into the same rendering channel in the cache block to perform image rendering processing.
[0019] In one embodiment, the rendering processing module is also used to obtain the description information corresponding to each of the rendering channels according to the explicit description function through the target shader; determine the rendering target corresponding to each of the rendering channels and the dependency relationship between the rendering channels according to the description information corresponding to each of the rendering channels; and merge the rendering channels with dependency relationships corresponding to the same rendering target into the same rendering channel corresponding to the rendering target in the cache block according to the marking function.
[0020] In one embodiment, the scene data corresponding to each pixel is stored in a cache block; the rendering processing module is also used to call the threads corresponding to each pixel respectively, and execute the called threads in parallel to perform image rendering processing on the merged rendering channel through the target shader and the scene data.
[0021] In one embodiment, the rendering processing module is further used to mark the start rendering identifier and the end rendering identifier corresponding to each rendering channel having a dependency relationship with the rendering target;
[0022] The target shader performs image rendering processing on the merged rendering channel according to the scene data in the cache block, and writes the intermediate results obtained by each rendering channel between the start rendering identifier and the end rendering identifier into the cache block respectively, so as to obtain the final image rendering result in the cache block.
[0023] In one embodiment, the rendering processing module is also used to perform image rendering processing on the merged rendering channel according to the scene data in the current cache block through the target shader, and store the obtained intermediate results to the corresponding position in the cache block; after the image rendering processing of the merged rendering channel is completed according to the scene data in the current cache block, the next cache block is used as the current cache block, and the step of performing image rendering processing on the merged rendering channel according to the scene data in the current cache block through the target shader is repeated.
[0024] In one embodiment, the rendering processing module is also used to obtain the intermediate results obtained by each rendering channel; write the intermediate results corresponding to each pixel into a corresponding cache block respectively; the byte occupancy of the intermediate results corresponding to each pixel does not exceed the memory capacity of each cache block.
[0025] In one embodiment, the rendering channel includes a texture sampling channel and a lighting shading channel; the rendering processing module is also used to perform image rendering processing on the texture sampling channel through the target shader according to the scene data in the cache block, and write the texture result data of the texture sampling channel into the cache block; perform image rendering processing on the lighting shading channel through the target shader according to the texture result data in the cache block, and write the shading result data of the lighting shading channel into the cache block.
[0026] In one embodiment, the rendering processing module is also used to read texture result data corresponding to each pixel from the pixel position corresponding to each pixel in the cache block; the texture result data includes material attributes corresponding to each pixel; according to the material attributes corresponding to each pixel, a lighting model matching the material attributes is obtained; and through the target shader, in the screen space, image rendering processing is performed on the lighting shading channel corresponding to each pixel according to the lighting model corresponding to each pixel and each of the texture result data.
[0027] A computer device comprises a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:
[0028] After obtaining the rendering instructions triggered by the application,
[0029] Calling a target shader corresponding to the graphics interface of the application from pre-compiled shaders for different types of graphics interfaces in the rendering engine; the pre-compiled shader is generated by compiling an original shader of the rendering engine;
[0030] Acquire scene data corresponding to the rendering target according to the rendering instruction, and write the scene data into a cache block;
[0031] Based on the target shader, merging rendering passes corresponding to the rendering target and having a dependency relationship into a same rendering pass in a cache block;
[0032] Performing image rendering processing on the scene data in the cache block in the same rendering pass to obtain an image rendering result in the cache block.
[0033] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements the following steps:
[0034] After obtaining the rendering instructions triggered by the application,
[0035] Calling a target shader corresponding to the graphics interface of the application from pre-compiled shaders for different types of graphics interfaces in the rendering engine; the pre-compiled shader is generated by compiling an original shader of the rendering engine;
[0036] Acquire scene data corresponding to the rendering target according to the rendering instruction, and write the scene data into a cache block;
[0037] Based on the target shader, merging rendering passes corresponding to the rendering target and having a dependency relationship into a same rendering pass in a cache block;
[0038] Performing image rendering processing on the scene data in the cache block in the same rendering pass to obtain an image rendering result in the cache block.
[0039] A computer program product or a computer program, wherein the computer program product or the computer program comprises computer instructions, wherein the computer instructions are stored in a computer-readable storage medium; a processor of the computer device reads the computer instructions from the computer-readable storage medium, and when the processor executes the computer instructions, the following steps are implemented:
[0040] After obtaining the rendering instructions triggered by the application,
[0041] Calling a target shader corresponding to the graphics interface of the application from pre-compiled shaders for different types of graphics interfaces in the rendering engine; the pre-compiled shader is generated by compiling an original shader of the rendering engine;
[0042] Acquire scene data corresponding to the rendering target according to the rendering instruction, and write the scene data into a cache block;
[0043] Based on the target shader, merging rendering passes corresponding to the rendering target and having a dependency relationship into a same rendering pass in a cache block;
[0044] Performing image rendering processing on the scene data in the cache block in the same rendering pass to obtain an image rendering result in the cache block.
[0045] The above-mentioned image rendering method, device, computer equipment and storage medium, after obtaining the rendering instruction triggered by the application, call the target shader corresponding to the graphics interface of the application from the shader pre-compiled for different types of graphics interfaces in the rendering engine; because the pre-compiled shader is compiled and generated by the original shader of the rendering engine, when the application is running, it can flexibly call the target shader corresponding to the corresponding image interface according to the type of the current operating platform of the application, so that it can adapt to various operating platforms. The terminal then obtains the scene data corresponding to the rendering target according to the rendering instruction, and writes the scene data into the cache block; through the target shader, according to the scene data in the cache block, the rendering channels with dependencies corresponding to the rendering target are merged into the same rendering channel in the cache block for image rendering processing, so as to obtain the image rendering result in the cache block. This avoids the large amount of data reading and writing consumption caused by writing the intermediate result data obtained by each rendering channel into the system memory, thereby effectively reducing the bandwidth consumption in the image rendering process, and then effectively improving the efficiency of the image rendering process. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] Figure 1 A diagram showing an application environment of an image rendering method in an embodiment;
[0047] Figure 2 is a schematic flow chart of an image rendering method in one embodiment;
[0048] Figure 3 A schematic diagram of compiling shaders corresponding to various graphics interface types in one embodiment;
[0049] Figure 4 A schematic diagram of a project setting interface of a rendering engine editor in one embodiment;
[0050] Figure 5 A schematic diagram of merging rendering passes in one embodiment;
[0051] Figure 6 is a flowchart of an image rendering method in another embodiment;
[0052] Figure 7 A schematic diagram of an image rendering effect of an image frame in one embodiment;
[0053] Figure 8 is a structural block diagram of an image rendering device in one embodiment;
[0054] Fig. 9 is a structural block diagram of an image rendering device in another embodiment;
[0055] Fig.10 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0056] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0057] The image rendering method provided in this application can be applied to Figure 1 In the application environment shown. Among them, the terminal 102 communicates with the server 104 through the network. After the terminal 102 starts the application, it obtains the scene data of the image to be rendered from the server 104 of the corresponding application. After obtaining the rendering instruction triggered by the application, the terminal 102 calls the target shader corresponding to the graphics interface of the application from the pre-compiled shaders for different types of graphics interfaces in the rendering engine; the pre-compiled shader is compiled and generated by compiling the original shader of the rendering engine; according to the rendering instruction, the scene data corresponding to the rendering target is obtained, and the scene data is written into the cache block; through the target shader, according to the scene data in the cache block, the rendering channels with dependencies corresponding to the rendering target are merged into the same rendering channel for image rendering processing to obtain the image rendering result in the cache block.
[0058] Among them, the terminal 102 can be, but is not limited to, various personal computers, laptops, smart phones, tablet computers and portable wearable devices, and the server 104 can be implemented by an independent server or a server cluster composed of multiple servers. The server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms. The terminal can be a smart phone, tablet computer, laptop computer, desktop computer, smart speaker, smart watch, etc., but is not limited to this. The terminal and the server can be directly or indirectly connected via wired or wireless communication, and this application is not limited here.
[0059] Cloud technology refers to a hosting technology that unifies hardware, software, network and other resources in a wide area network or local area network to achieve data computing, storage, processing and sharing. Cloud technology is a general term for network technology, information technology, integration technology, management platform technology, application technology, etc. based on the cloud computing business model. It can form a resource pool that can be used on demand and is flexible and convenient. Cloud computing technology will become an important support. The background services of technical network systems require a large amount of computing and storage resources, such as video websites, picture websites and more portal websites. With the high development and application of the Internet industry, in the future, each item may have its own identification mark, and all need to be transmitted to the background system for logical processing. Data of different levels will be processed separately. All kinds of industry data require strong system backing support, which can only be achieved through cloud computing.
[0060] Computer Vision Technology (Computer Vision, CV) Computer vision is a science that studies how to make machines "see". To put it more concretely, it refers to the use of cameras and computers to replace human eyes to identify, follow and measure targets, and further perform graphics processing to make computer processing into images that are more suitable for human eye observation or transmission to instrument detection. As a scientific discipline, computer vision studies related theories and technologies, and attempts to establish an artificial intelligence system that can obtain information from images or multidimensional data. Computer vision technology generally includes image processing, image recognition, image semantic understanding, image retrieval, OCR, video processing, video semantic understanding, video content / behavior recognition, three-dimensional object reconstruction, 3D technology, virtual reality, augmented reality, synchronous positioning and map construction, and other technologies, as well as common biometric recognition technologies such as face recognition and fingerprint recognition. It can be understood that the image rendering method of the present application is based on computer vision technology to perform image rendering processing on the image to be rendered, and can effectively improve the efficiency of image rendering processing.
[0061] In one embodiment, Figure 2 As shown, an image rendering method is provided, which is applied to Figure 1 The terminal in is used as an example to illustrate, including the following steps:
[0062] S202, after obtaining the rendering instruction triggered by the application, call the target shader corresponding to the graphics interface of the application from the pre-compiled shaders for different types of graphics interfaces in the rendering engine; the pre-compiled shader is compiled and generated by the original shader of the rendering engine.
[0063] Image rendering in computer graphics refers to the process of projecting the object model in a three-dimensional scene into a digital image in two dimensions according to the set environment, material, lighting and rendering parameters. It is also the process of converting the three-dimensional light energy transfer process into a two-dimensional image. The scene and entity are represented in three-dimensional form, which is closer to the real world and is easy to manipulate and transform. In the graphics pipeline, rendering is the last important step, through which the final display effect of the model and animation is obtained.
[0064] A rendering engine is a pre-written core component or system that can realize image rendering, such as the core component of some interactive real-time image applications. The rendering engine can be used to quickly establish the image rendering function required by the application to assist the operation of the program.
[0065] It can be understood that the terminal includes a graphics processor, a memory and a display screen. Among them, the memory includes a system memory corresponding to the system memory and a cache memory for high-speed data exchange, and the cache memory includes a cache block. An application is deployed in the terminal, and a rendering engine is deployed in the application. When the terminal runs the rendering engine through the application, the graphics processor can calculate all effects such as models, animations, light and shadow, special effects, etc. in real time, and display the rendering effect on the display screen of the terminal. For example, the rendering engines in the game application include Unreal Engine, Unity Engine, etc.
[0066] Among them, the renderer or shader in the application is usually built based on the underlying graphics API (Application Programming Interface). The graphics interface is responsible for communicating with the hardware of the terminal to perform image rendering processing using a rasterization method suitable for the hardware architecture. For example, commonly used graphics interfaces include Metal graphics interface, Vulkan graphics interface, OpenGL (Open Graphics Library) graphics interface, OpenGLES (OpenGL for Embedded Systems) graphics interface, etc. Among them, Metal is a low-level rendering application programming interface. Vulkan is a cross-platform 2D and 3D drawing application programming interface. OpenGL is a cross-language, cross-platform application programming interface for rendering 2D and 3D vector graphics. OpenGL ES is a subset of the OpenGL three-dimensional graphics interface, designed for embedded devices such as mobile terminals, handheld devices, and handheld game consoles.
[0067] Among them, shaders are editable programs used to achieve image rendering and can replace fixed rendering pipelines. Shaders include vertex shaders and pixel shaders. Vertex shaders are mainly responsible for the calculation of vertex geometric relationships, while pixel shaders are mainly responsible for the calculation of source color, etc. Shaders replace traditional fixed rendering pipelines and can achieve related calculations in 3D graphics. Due to their editability, various image effects can be achieved without being restricted by the fixed rendering pipeline of the graphics card.
[0068] It can be understood that a shader is an algorithm program interspersed in the rendering pipeline, which is responsible for combining the input vertex data with the input texture or color in a specified way and then outputting it. Usually, the graphics processor reads the corresponding input texture through the target shader, and renders the image frame input by the target shader through the rendering pipeline of the graphics processor. Then the rendered image frame is written to the frame buffer for caching, and finally output to the terminal screen.
[0069] Among them, a rendering engine is deployed in the application, and pre-compiled shaders corresponding to different types of graphics interfaces are deployed in the rendering engine. Among them, the shaders corresponding to different types of graphics interfaces are generated by compiling the original shaders of the rendering engine and can be run in the graphics processor of the terminal. It can be understood that the original shader of the rendering engine refers to the open source shader script in the rendering engine. The original shader of the rendering engine usually only supports specified graphics interfaces, and the functional support for different types of graphics interfaces is different.
[0070] By calling the graphics interface corresponding to the current operating platform type of the application, the target shader adapted to the graphics interface can be obtained to adapt to the operating platforms of different terminals, thereby being able to flexibly call the pre-compiled shader adapted to the graphics interface of the application.
[0071] When the terminal starts the application, it runs the application and the rendering engine in the application. During the running process, the application can send a series of rendering instructions to the terminal to perform image rendering processing on the image scene that the application needs to display, so as to display the corresponding image effect on the terminal interface.
[0072] After the terminal obtains the rendering instruction triggered by the application, it calls the target shader corresponding to the application's graphics interface from the pre-compiled shaders for different types of graphics interfaces in the rendering engine through the terminal's GPU (Graphics Processing Unit). The terminal's graphics processor performs corresponding image rendering processing on the image frame to be rendered in the application through the called target shader.
[0073] S204, acquiring scene data corresponding to the rendering target according to the rendering instruction, and writing the scene data into a cache block.
[0074] Among them, in computer graphics processing, the rendering target is a buffer in the computer memory used to draw the image frame to be rendered, that is, a video memory buffer including the information that needs to be drawn for the image frame to be rendered. It can be understood that the rendering target is a buffer used to record the output result after pixel rendering. The rendering target corresponds to a continuous memory area, and multiple memory areas can exist at the same time, indicating that there are multiple rendering targets.
[0075] The graphics pipeline has a default render target called the back buffer, which contains a portion of the video memory for the next image frame to be drawn. Typically, most game applications draw a large amount of content outside the back buffer to other render targets, and then compile each image element and combine the image elements to form the final back buffer. It can be understood that in some scenarios, a to-be-rendered image frame can have multiple render targets. By drawing different parts of a to-be-rendered image frame on different render targets and then compositing the render targets belonging to the to-be-rendered image frame, the final image rendering result corresponding to the to-be-rendered image frame can be obtained.
[0076] Scene data refers to various scene information corresponding to the graphic objects in the image frame to be rendered, such as color, vertex data, texture data, material category, indirect lighting, normal vector, reflectivity, normal and other data. Among them, texture refers to a specific surface feature of an object, that is, the surface feature corresponding to the graphic object in the image frame to be rendered. Different object surfaces will produce different texture images. For the rendering target, the terminal can obtain the scene data corresponding to the currently processed rendering target, for example, all the scene data corresponding to the image frame to be rendered, or part of the scene data corresponding to the image frame to be rendered.
[0077] The cache block is a subset of cache resources allocated based on the cache memory. These resource subsets are called TileMemory, i.e., cache blocks. Storing the data to be processed in the cache memory can effectively improve the data read and write performance and processing efficiency. The size of each cache block is determined by the graphics processor driver of the terminal. The graphics processor can determine what information is stored in each cache block through the rendering pipeline.
[0078] When rendering, the graphics processor of the terminal will process the screen pixels in blocks. The calculation result data of each pixel will be stored in a dedicated cache of the graphics processor first. After the calculation of the entire pixel is completed, the image rendering result will be written out to the external video memory. For example, this cache is called Threadgroup Memory on Apple-type graphics processors, Tile Buffer on Mali-type graphics processors, and Gmem memory on Adreno-type graphics processors. These can all be collectively referred to as cache blocks.
[0079] It can be understood that the image frame to be rendered includes multiple graphic objects to be rendered. Graphic objects are graphic elements to be drawn, such as various graphic elements such as people, vehicles, and houses. Graphic objects can be drawn and generated according to corresponding scene data. Usually, the scene data corresponding to the image frame to be rendered is stored in the installation package of the application. The scene data corresponding to the image frame to be rendered can be retrieved from the installation package of the application, and the retrieved scene data can be subjected to image rendering processing.
[0080] When the terminal renders an image, after acquiring scene data corresponding to the rendering target according to the rendering instruction, the acquired scene data is first written into the cache block, so that the image rendering processing is performed directly on the corresponding rendering target in the cache according to the scene data through the target shader.
[0081] S206 , based on the target shader, merging the rendering passes corresponding to the rendering target and having a dependency relationship into the same rendering pass in the cache block.
[0082] It is understandable that by recompiling the original shader based on the rendering engine, shaders corresponding to different types of graphics interfaces can be obtained respectively. The pre-compiled shaders corresponding to each type of graphics interface can all implement the optimized processing method of the delayed rendering pipeline based on the cache block. That is, they can all support writing the intermediate result data obtained from each rendering channel with a dependency relationship for the rendering target into the cache block first, so as to perform delayed rendering processing in the cache library, and finally write the image rendering result obtained in the cache block into the system memory.
[0083] The dependency relationship refers to the relationship that a change in one activity will affect another activity. It can be understood that each rendering channel with a dependency relationship means a rendering channel with data dependency among multiple rendering channels. That is, the data of one rendering channel will affect the processing of another rendering channel. For example, if the processing of one rendering channel depends on the data corresponding to another rendering channel, it means that the two rendering channels have a dependency relationship. The term "multiple" refers to more than two.
[0084] Among them, a rendering channel, namely RenderPass, refers to a rendering process for a rendering object, that is, a set of rendering instructions submitted by an application to a graphics processor at one time. It can also be understood that a rendering channel is a single run of the rendering pipeline. Which graphics objects are to be rendered by each rendering channel, these rendering channels constitute the rendering pipeline. For example, a rendering channel can include a GBuffer Pass geometry buffer channel, a Shading Pass lighting shading channel, etc. Among them, GBuffer Pass in the deferred rendering pipeline refers to a step of outputting various attributes of all visible objects to multiple textures for subsequent lighting calculations. GBuffer refers to a geometric buffer including position information, lighting information, normal information, material category, tangent information, texture information, etc. The result output by GBuffer Pass is an intermediate result. For example, 4 textures are usually required for storage. Shading Pass is a process of further performing lighting shading processing based on the intermediate result output by GBuffer Pass. It can be understood that the intermediate result represents the data output by each rendering channel during the image rendering process. Further image rendering processing based on these intermediate results can obtain the final image rendering result.
[0085] It is understandable that the rendering pipeline is also called the rendering pipeline, which is an independent parallel processing unit inside the display chip that processes graphics signals. The rendering pipeline is a set of special channels in the display core that is responsible for coloring the graphics. The number of rendering pipelines is generally expressed as the number of pixel rendering pipelines multiplied by the number of texture units per pipeline. The rendering pipeline usually includes an application stage, a geometry stage, and a raster stage. The main function of the graphics rendering pipeline is to generate a rendered two-dimensional image based on a given virtual camera, three-dimensional objects, and light sources.
[0086] In multi-pass rendering technology, an object usually requires multiple rendering operations, and the results of each rendering process will be accumulated to the final rendering result. A rendering pass renders the intermediate result data of the image frame into the cache block of the cache memory. The rendering passes for the same rendering target are interdependent, and the subsequent rendering passes will use the data of the previous rendering passes, such as depth information, geometry information, etc. The result data obtained by the last rendering pass is the final image rendering result. Therefore, the rendering pass can be understood as a series of image rendering processing steps.
[0087] Specifically, image rendering processing can be performed by using a delayed rendering method, that is, a delayed rendering pipeline is used for image rendering processing. Among them, delayed rendering is to render the scene that does not receive lighting to the geometry buffer first, and the geometry buffer renders the scene data to the texture corresponding to the graphic object in the image frame to be rendered, and then performs lighting processing on the data rendered to the texture. It can be understood that the geometry buffer is used to render the scene data to the texture corresponding to the graphic object in the image frame to be rendered. The use of delayed rendering can avoid the lighting calculation of invisible pixels, allow the shading range of the light source to be controlled by the light source geometry, can render a large number of light sources, and can effectively improve the rendering efficiency of multi-light source scenes. For scenes with a large number of light sources and objects, the efficiency of delayed rendering far exceeds that of forward rendering, and delayed rendering can greatly reduce the computational pressure of the pixel shader.
[0088] It can be understood that each rendering channel includes corresponding drawing commands, such as drawing commands for each image object. Merging rendering channels into the same rendering channel means combining the drawing commands of multiple rendering channels into a drawing command of an overall rendering channel, and the merged rendering channels can be used as sub-rendering channels in the overall rendering channel.
[0089] After the terminal obtains the scene data, the graphics processor uses the target shader to process the rendering channels corresponding to the rendering target according to the scene data. Among them, the target shader combines the drawing commands of the rendering channels with dependencies corresponding to the rendering target in the cache block in the process of image rendering processing into a drawing command of a whole rendering channel, so as to realize the merging of the rendering channels with dependencies into the same rendering channel, thereby being able to execute the drawing commands corresponding to the original rendering channels in the merged same rendering channel, so that the intermediate results obtained after processing the drawing commands in the same rendering channel are all written into the cache block. It can be understood that after the drawing commands of multiple rendering channels are combined into the drawing commands of a whole rendering channel, the drawing commands in the merged rendering channel are all processed in the same data reading and writing method. That is, the data required for each drawing command is read from the cache block, and then the intermediate results output after executing each drawing command are also written into the cache block. As a result, the calculations of each merged rendering channel are all processed in the cache block, so that the intermediate result data obtained after processing each merged rendering channel can be ensured not to be written into the system memory.
[0090] S208, performing image rendering processing on the scene data in the cache block in the same rendering channel to obtain an image rendering result in the cache block.
[0091] It can be understood that the image rendering result is the final result obtained after a series of rendering passes are processed for the rendering target.
[0092] It is understandable that the cache exchanges data with the processor before the system memory, so the data is directly extracted from the cache and processed, and the data reading rate and processing speed are faster.
[0093] The graphics processor of the terminal merges the rendering channels with dependencies corresponding to the rendering target in the cache block through the target shader, and then performs image rendering processing on the scene data in the cache block in the same merged rendering channel, and writes the final image rendering result into the cache block to obtain the image rendering result in the cache block. In this way, the calculations of the merged rendering channels can be effectively processed in the cache block, so as to obtain the image rendering result in the cache block.
[0094] In one embodiment, the graphics processor of the terminal further writes the final image rendering result obtained in the cache block into the system memory. Specifically, the image rendering result can be written into the frame buffer of the system memory, so that the display screen of the terminal reads the image rendering result from the frame buffer to display the image rendering result on the display screen of the terminal.
[0095] In the traditional way, when processing each rendering channel, the intermediate result data obtained by each rendering channel needs to be written back to the system memory. When processing the next rendering channel, the corresponding intermediate result data is read from the system memory for image rendering processing. However, in the process of processing each rendering channel in this way, a large amount of read and write data is required for calculation, which will cause great pressure on bandwidth. In addition, the graphics processor and the central processor of the existing mobile terminal usually share the same physical memory architecture, which will increase the pressure on the graphics processor and cause hardware resource waste.
[0096] In the above-mentioned image rendering method, after the terminal obtains the rendering instruction triggered by the application, it calls the target shader corresponding to the application's graphics interface from the pre-compiled shaders for different types of graphics interfaces in the rendering engine; since the pre-compiled shader is compiled and generated by the original shader of the rendering engine, when the application is running, it can flexibly call the shader corresponding to the corresponding image interface according to the type of the current operating platform of the application, so that it can adapt to various operating platforms. The terminal then obtains the scene data of the rendering target according to the rendering instruction and writes the scene data into the cache block; through the target shader, according to the scene data in the cache block, the rendering channels with dependencies corresponding to the rendering target are merged into the same rendering channel for image rendering processing, and then the image rendering results obtained in the cache block are written into the system memory, thereby avoiding the large amount of data reading and writing consumption caused by writing the intermediate result data obtained by each rendering channel into the system memory, thereby effectively reducing the bandwidth consumption in the image rendering process, and then effectively improving the efficiency of image rendering processing.
[0097] In one embodiment, before calling the target shader corresponding to the graphics interface of the application from the shader pre-compiled for different types of graphics interfaces in the rendering engine, it also includes: in the original shader of the rendering engine, respectively configuring the explicit description function and the marking function corresponding to each type of graphics interface to compile the shader corresponding to each graphics interface; wherein the explicit description function is used to add description information of each rendering channel; the marking function is used to mark the start rendering identifier and the end rendering identifier of the merged rendering channel.
[0098] The pre-compiled shader is generated by compiling the original shader of the rendering engine. Therefore, before calling the target shader corresponding to the graphics interface of the application, it is also necessary to pre-compile the shaders corresponding to different types of graphics interfaces.
[0099] Developers can compile the rendering engine through the corresponding compilation end during the process of compiling the application, or directly obtain a pre-written rendering engine and deploy it in the application. Then, based on the original shader already in the rendering engine, compile shaders corresponding to different types of graphics interfaces.
[0100] Specifically, in the process of compiling shaders corresponding to various graphics interfaces based on the original shaders, explicit description functions and marking functions corresponding to various types of graphics interfaces are configured respectively, thereby generating shaders corresponding to various graphics interfaces. For example, when the rendering engine packages the project, the original shaders in the rendering engine can be compiled to generate shaders corresponding to various types of graphics interfaces.
[0101] For explicit description functions, the corresponding explicit description functions can be configured in the shader to add description information of each rendering channel and input and output parameter information of each rendering channel through the explicit description function to determine which rendering targets need to be read and written to establish dependencies between the rendering channels.
[0102] As for the marking function, the marking function can be configured in the shader to mark the start rendering mark before the first rendering pass, such as BeginRenderPass, according to the rendering sequence of each rendering pass, and mark the end rendering mark after the last rendering pass, such as EndRenderPass, to ensure that the intermediate data obtained by each rendering pass is not written out to the system memory.
[0103] In this embodiment, the shaders compiled corresponding to various types of graphics interfaces all support image rendering processing based on cache blocks. Support for the use of cache blocks is provided for mainstream graphics interfaces corresponding to mobile terminal platforms, such as Metal-type graphics interfaces, OpenGLES-type graphics interfaces, Vulkan-type graphics interfaces, etc. For example, Metal-type graphics interfaces can support fragment function input attributes, such as Fragment Function InputAttribute. OpenGLES-type graphics interfaces can support frame buffer read attributes, such as FramebufferFetch, and pixel local storage attributes, such as PixelLocalStorage. These features provide different degrees of support for cache blocks.
[0104] Take Metal, OpenGLES, and Vulkan graphics interfaces as examples. Figure 3 As shown, it is a schematic diagram of compiling shaders corresponding to each type of graphics interface in one embodiment. Specifically, in the process of compiling shaders at the compiling end, in the shader based on HLSL (High Level Shader Language, high-level shader language), the original shader of the rendering engine is compiled by HLSLcc (HLSL Cross Compiler, high-level shader language cross compiler) to compile into shader languages corresponding to each graphics interface. Then, in the process of translating the original shader into the target platform shader language, compatible shader codes are generated for different shader languages and different operating platform types. And in the process of compiling, the built-in functions supporting the deferred rendering pipeline based on the cache block are configured in the shaders of each graphics interface respectively to represent the reading of the cache block, and the shaders corresponding to each type of graphics interface after compilation can all realize the optimized processing method of the deferred rendering pipeline based on the cache block. Thus, the shaders corresponding to each type of graphics interface are obtained.
[0105] Furthermore, in the rendering pipeline, due to the differences between various types of operating platforms, different execution paths may be taken on some platforms. Therefore, corresponding execution paths for various types of operating platforms can also be configured. In the rendering pipeline, it is necessary to detect the support status of the current operating platform and execute the corresponding configured execution path.
[0106] For Vulkan-type graphics interfaces, you only need to configure the display description function of the rendering channel to correspond to the various structures required by the Vulkan-type graphics interface, and configure the read and write operations of each rendering channel to be consistent.
[0107] For OpenGLES and Metal graphics interfaces, the operation of merging rendering channels is implicit relative to Vulkan graphics interfaces. Implicit means that both the interface and the class can be accessed. Therefore, when the graphics processor runs the rendering engine, it can directly call the display description function and the marking function pre-configured for the graphics interface. As long as the target shader called by the rendering layer is not executed in advance before the rendering end marker, it can be guaranteed that the rendering channels with dependencies are merged.
[0108] In one of the embodiments, for OpenGLES type graphics interfaces and Metal type graphics interfaces, correlation attributes can also be configured for each rendering channel to set incoherent attribute information for the frame buffer corresponding to the rendering channels that have no dependency. During the image rendering process, the target shader can obtain the attribute information in the correlation attribute according to the dependency between the rendering channels to identify the rendering channels with incoherent attributes. For example, on the Qualcomm platform, the correlation attributes of each rendering channel can be configured by using the FramebufferFetchNonCoherent function. For incoherent rendering channels corresponding to the same pixel on the cache block, the graphics processor uses different threads for image rendering. This can reduce the synchronization between different threads of the same pixel on the cache block to increase the rendering processing performance.
[0109] In one of the embodiments, in the process of configuring the rendering engine, the selection of the rendering pipeline for the mobile terminal platform and whether to turn on the switch based on TileMemory optimization can be added in the project setting interface of the rendering engine editor. For example, as shown in Figure 4, it is the project setting interface of the rendering engine editor, and the project setting interface includes the option of the shading path of the mobile platform and the option of enabling optimized rendering based on cache blocks. Among them, when the option of the shading path of the mobile platform is set to 2, it means that the deferred rendering pipeline is enabled. When the option of enabling optimized rendering based on cache blocks is selected, it means that bandwidth optimization based on cache blocks is enabled. After the deferred rendering pipeline and the bandwidth optimization function based on cache blocks are turned on, the deferred rendering pipeline can be used on mobile devices to support a large number of light sources under low power consumption.
[0110] In one embodiment, in the original shader of the rendering engine, explicit description functions and marking functions corresponding to each type of graphics interface are respectively configured to compile the shader corresponding to each graphics interface, including: in the original shader of the rendering engine, for each type of graphics interface, explicit description functions and marking functions corresponding to different types of graphics processors are respectively configured to compile the shader corresponding to each type of graphics interface.
[0111] Among them, since different types of graphics processors have different support for the extension programs of various types of graphics interfaces, it is necessary to configure corresponding explicit description functions and marking functions using appropriate extension programs for different types of graphics processors, so as to optimize the configuration of the shaders corresponding to each type of graphics interface. That is, in the shader corresponding to each type of graphics interface, multiple explicit description functions and marking functions corresponding to different types of graphics processors are also configured.
[0112] For example, for shaders corresponding to OpenGLES type graphics interfaces, for Mali type graphics processors, an extension based on pixel local storage is used to perform optimized configuration based on cache blocks, for example, the extension based on pixel local storage can use the EXT_shader_pixel_local_storage extension. For graphics processors other than Mali type, an extension based on frame buffer reading can be used to perform optimized configuration based on cache blocks, for example, the extension based on frame buffer reading can use the EXT_shader_framebuffer_fetch extension.
[0113] Among them, for the extension program based on pixel local storage, such as Pixel Local Storage. Since the extension program based on pixel local storage in the original shader does not support MRT (Multiple Render Target). Therefore, the display description function can be flexibly configured in the shader corresponding to each type of graphics interface. Once the runtime detects that the shader has set an explicit description function, all rendering targets except the current rendering target will be removed when constructing each rendering channel. For example, this can be achieved by setting Subpass Hint, that is, the rendering channel prompt information.
[0114] In addition, since the pixel local storage extension does not support the Fixed Function Blending method, that is, the method of using the corresponding hardware unit in the graphics processor for blending, that is, the method of combining the extension with the hardware unit in the graphics processor for software and hardware processing, that is, the graphics processor can use software programs such as compilable shaders to occupy, allocate and call resources on the rendering pipeline (i.e., hardware unit) in the graphics processor. In the process of using the pixel local storage-based extension, all rendering channels are all programmed using the Programmable Blending method (i.e., the function merging method), so that the rendering pipeline can be adjusted during the rendering process.
[0115] Due to the extension of pixel local storage, a structure is required to be declared in the shader, and the member variables in the structure represent the variables that will be stored in the cache block. Therefore, by using the custom built-in functions in the shader, such as "FramebufferFetchMRT0()-FramebufferFetchMRT7()", the read of the cache block is represented, such as the serial number 0-7 represents the read of the rendering target 0-7. During the processing, if the use of the above functions is detected, a declaration of a structure based on pixel local storage is added to the shader. The structure contains all the variables stored in the cache block. Then the reference to the above built-in function is converted to the reading of the structure member based on the pixel local storage extension. The writing of each member in the shader does not use the method of adding additional built-in functions, but provides a method of directly using text replacement in the shader. This will not add too much complexity to the shader, such as too much branch processing for different types of operating platforms.
[0116] Each shader that uses the pixel local storage extension must declare a structure containing all member variables to be stored in the cache block. Each shader may call different functions during operation, resulting in each shader not knowing which members are in the complete pixel local storage extension structure when processing. Therefore, by defining built-in functions in the shader, that is, explicitly describing functions such as "CTGNumberOfColorsToKeepInTileMem()", the shader is informed of how many rendering targets there are in total, which will be stored in the cache block as structure variables.
[0117] Some extensions based on pixel local storage do not support writing structure members and rendering targets at the same time. Therefore, it is necessary to indicate that the shader in the current rendering channel is the last batch of shaders that use the extension based on pixel local storage. By configuring another built-in function in the shader, that is, the marking function, such as "CTGPLSColorResolvePass()", to indicate that the current rendering channel is the last rendering channel. The intermediate results of each rendering channel will not continue to be written to the structure of pixel local storage, but will be written to the cache block corresponding to the rendering target. Therefore, by adopting an extension based on pixel local storage, all adjacent rendering channels that use the structure of pixel local storage can be merged into one rendering channel.
[0118] The configuration process in the shader corresponding to the Vulkan type graphics interface is similar to the above method. For example, on operating platforms other than the Mali type, such as Adreno, PowerVR, etc., an extension based on frame buffer reading is used for optimization configuration, such as the EXT_shader_framebuffer_fetch extension. Similar to the above configuration method, the reading of cache blocks is represented by configuring built-in functions for the shader. In the shader corresponding to the OpenGLES type graphics interface, these functions are parsed into shader syntax supported by the extension based on frame buffer reading, including declaring each rendering target to be read as an input attribute in the shader, and replacing the built-in function with a direct reference to the rendering target attribute.
[0119] For shaders corresponding to Metal-type graphics interfaces, the way to configure explicit description functions and tag functions is similar to the above configuration method for extensions based on frame buffer reading. Similarly, the return value of the shader can be replaced by a custom built-in function. The difference is that it must be replaced with the syntax rules required by the Metal-type graphics interface, that is, the render target to be read must be added as an input parameter in the parameter list of the shader's entry function, and the correct Raster Order Group raster group sequence must be set to obtain correct and high-performance read and write synchronization.
[0120] In this embodiment, by detecting the current extension support status in the shader, different paths are selected for implementation, so that different types of operating platforms can use the same shader, avoiding the performance loss that may be caused by compiling multiple shaders.
[0121] In one embodiment, the above method also includes: when the application starts running, running the rendering engine in the application; the rendering hardware interface layer of the rendering engine includes different types of graphics interfaces; according to the running platform type of the application, determining the type of graphics interface corresponding to the running platform type in the application from the different types of graphics interfaces.
[0122] The rendering engine includes a rendering hardware interface layer, namely RHI (Render hardware interface), which is a unified interface. The rendering hardware interface layer in the rendering engine corresponds to multiple graphics interfaces. Calling the rendering hardware interface in the rendering engine means determining the shader and corresponding implementation corresponding to the currently used graphics interface when the rendering engine is initialized, so as to ensure that the rendering engine runs the same on different types of operating platforms.
[0123] It can be understood that the graphics processor also includes a rendering layer. The rendering layer of the graphics processor processes the corresponding rendering tasks by calling the interface of the rendering hardware interface layer of the rendering engine. Different types of operating platforms have different corresponding implementations of the graphics interface of the rendering hardware interface layer. Therefore, when the engine packages the project, you can choose to package the implementation of shaders corresponding to various types of graphics interfaces into the rendering engine. When the application is initialized, the type of the current operating platform will be detected to call the shader corresponding to the appropriate graphics interface for image rendering processing. For example, for Windows-type operating platforms, you can choose the shader corresponding to the DirectX-type graphics interface; for Android-type operating platforms, you can choose the shader corresponding to the Vulkan-type graphics interface.
[0124] After the rendering engine is started, the various graphics interfaces in the rendering hardware interface layer of the Unreal Engine are provided to the rendering layer for use to adapt to different types of operating platforms.
[0125] In this embodiment, the terminal detects the type of the current operating platform of the application when the program is started and initialized. When the application is started and run, the rendering engine in the application is run at the same time. The graphics processor of the terminal determines the type of graphics interface corresponding to the operating platform type in the application from different types of graphics interfaces according to the operating platform type of the application, thereby being able to call a shader adapted to the current operating platform type to perform efficient image rendering processing.
[0126] In one embodiment, a target shader includes explicit description functions and marking functions corresponding to different types of graphics processors; based on the target shader, rendering channels with dependencies corresponding to the rendering target are merged into the same rendering channel in a cache block, including: calling, through the graphics processor, the explicit description function and marking function corresponding to the type of the graphics processor from the target shader; through the target shader, according to the called explicit description function and marking function, merging, in the cache block, rendering channels with dependencies corresponding to the rendering target into the same rendering channel.
[0127] There are many types of graphics processors, such as Mali type, Apple type, Adreno type, etc. For different types of graphics processors, explicit description functions and marking functions adapted to various types of graphics processors can be configured in shaders corresponding to each graphics interface.
[0128] When the terminal runs the application, it detects the functions configured for each type of graphics processor in the called target shader, and then calls the explicit description function and the marking function corresponding to the type of graphics processor from the target shader through the graphics processor.
[0129] The terminal then merges the rendering channels with dependencies corresponding to the rendering target into the same rendering channel through the target shader according to the called explicit description function and marking function, so as to perform image rendering processing on the merged rendering channels in the cache block.
[0130] In this embodiment, by configuring explicit description functions and marking functions adapted to various types of graphics processors in the shaders corresponding to each graphics interface, the performance loss that may be caused by compiling multiple shaders for different types of graphics processors is avoided, effectively saving resource consumption.
[0131] In one embodiment, through a target shader, rendering channels with dependencies corresponding to rendering targets are merged into the same rendering channel in a cache block according to an explicit description function and a marking function, including: obtaining description information corresponding to each rendering channel according to an explicit description function through the target shader; determining a rendering target corresponding to each rendering channel and a dependency relationship between the rendering channels according to the description information corresponding to each rendering channel; and merging rendering channels with dependencies corresponding to the same rendering target in the cache block according to the marking function into the same rendering channel corresponding to the rendering target.
[0132] The description information refers to information used to describe the properties of each rendering channel, such as various property information such as input parameters and output parameters of each rendering channel. Through the description information, various property information such as input parameters and output parameters of each rendering channel can be explicitly obtained, thereby clearly knowing which rendering targets correspond to bandwidth savings.
[0133] When the graphics processor of the terminal performs image rendering processing through the shader, the description information corresponding to each rendering channel can be obtained through the display description function in the shader. Since the description information includes various attribute parameters such as the input parameters and output parameters of each rendering channel, the rendering target corresponding to each rendering channel and the dependency relationship between the rendering channels can be determined based on the description information.
[0134] A rendering pass can be thought of as the process of rendering a geometry to a texture or screen at a time. Any number of geometric objects, i.e., graphic objects, can also be rendered in one rendering pass. Usually, some rendering effects require multiple rendering passes to achieve. For example, a house is first rendered to a texture map, and then the texture map is blurred with a rendering pass, and the result is output to another texture to get a blurred house scene. This is usually not effectively achieved in one rendering pass. The rendering engine can determine how many rendering passes are in each image frame. Which graphic objects are to be rendered by each rendering pass, and these rendering passes constitute the rendering pipeline. Therefore, the rendering engine can decide how many rendering passes the rendering pipeline contains, and the rendering pipeline determines the final rendering effect of the rendering engine.
[0135] Each rendering pass may also include a sub-rendering pass. For example, each rendering pass RenderPass may include multiple sub-rendering passes Subpass. These rendering passes or system rendering passes may be merged under certain conditions. Figure 5As shown, it is a schematic diagram of merging rendering channels in one embodiment. For example, the rendering channel includes a geometry buffer channel GBuffer Pass, a decal channel DecalPass, and a lighting channel ShadingPass, and these three rendering channels can be regarded as sub-rendering channels Subpass. By adding corresponding description information to the rendering channel by the target shader, it can be determined that these three rendering channels are rendering channels with dependencies on the rendering target. These three sub-rendering channels Subpass are merged to form a rendering channel RenderPass, so that the reading and writing of the intermediate result data obtained by the merged rendering channels are all performed in the cache block. In this way, the bandwidth in the image rendering process can be effectively saved.
[0136] Specifically, the graphics processor further merges the rendering channels with dependencies corresponding to the same rendering target in the cache block according to the marking function into the same rendering channel corresponding to the rendering target. The graphics processor of the terminal performs image rendering processing on the merged rendering channels according to the scene data in the cache block through the target shader.
[0137] In this embodiment, during the image rendering process, the target shader calls the pre-compiled display description function and the marking function, so that the rendering channels with dependencies corresponding to the same rendering target can be effectively merged into the same rendering channel in the cache block. Therefore, the intermediate data between the merged rendering channels can be stored in the buffer block instead of being written out to the system, thereby effectively saving bandwidth.
[0138] In one embodiment, scene data corresponding to each pixel is stored in a cache block; image rendering processing is performed on the scene data in the cache block in the same rendering channel to obtain an image rendering result in the cache block, including: calling threads corresponding to each pixel respectively, and executing the called threads in parallel to perform image rendering processing on the merged rendering channel through a target shader and scene data.
[0139] Among them, a pixel refers to the smallest unit in an image represented by a digital sequence. A pixel is composed of small squares in the image, and each small square has a clear position and an assigned color value. The color and position of the small square determine the appearance of the image.
[0140] It can be understood that a pixel is the smallest unit in an image frame to be rendered. The image frame to be rendered includes one or more graphic objects, and one graphic object may be composed of one or more pixels.
[0141] Among them, the graphics processor can adopt multi-threaded synchronous processing during the image rendering process. By pre-compiling the shaders corresponding to various types of graphics interfaces, the shaders corresponding to various types of graphics interfaces can support multi-threaded rendering from the architecture. Specifically, through the configured explicit description function, the description information of each rendering channel is explicitly displayed, and then the dependency between the rendering channels is determined based on the description information, and then the parallelism is increased based on the dependency to ensure correct thread synchronization. For example, by adding corresponding sequence attribute information to the input parameters and output parameters of each rendering channel, the corresponding objects that need to be processed by synchronous threads can be determined.
[0142] For example, for shaders corresponding to OpenGLES type graphics interfaces, the description information of each rendering channel is explicitly displayed through the configured explicit description function, and then the dependency between rendering channels is determined based on the description information, and then the parallelism is increased based on the dependency to ensure correct thread synchronization. Among them, the shaders corresponding to the OpenGLES graphics interface, for the extensions based on pixel local storage and the extensions based on frame buffer reading, determine the objects that need to be processed by the synchronized threads through the dependency set between rendering channels.
[0143] For shaders corresponding to Vulkan graphics interfaces, you can also set dependencies between rendering channels to ensure thread synchronization between rendering channels. For example, the synchronization between Drawcall commands within the same Subpass can be controlled using pipeline isolation PipelineBarrier.
[0144] For shaders corresponding to Metal-type graphics interfaces, different raster group sequence properties, namely Raster Order Group, can be set for different output variables in the shader to ensure thread synchronization between rendering channels.
[0145] When the graphics processor of the terminal performs image rendering processing through the shader, the graphics processor calls the thread corresponding to each pixel and executes the called threads in parallel to perform image rendering processing on the merged rendering channel through the target shader and scene data. Specifically, each thread of the graphics processor calculates one pixel and stores the intermediate result data in the cache blocks corresponding to each pixel. Threads for different pixels on a cache block are executed in parallel, and for different threads of the same pixel, read and write synchronization is maintained at the same time.
[0146] In this embodiment, the graphics processor calls the thread corresponding to each pixel respectively, and executes the called threads in parallel, so that thread synchronous rendering can be effectively achieved, thereby effectively improving rendering efficiency.
[0147] In one embodiment, image rendering processing is performed on scene data in a cache block in the same rendering channel to obtain an image rendering result in the cache block, including: marking a start rendering identifier and an end rendering identifier corresponding to each rendering channel having a dependency relationship with a rendering target; performing image rendering processing on the merged rendering channels according to the scene data in the cache block through a target shader, and writing intermediate results obtained from each rendering channel between the start rendering identifier and the end rendering identifier into the cache block respectively to obtain a final image rendering result in the cache block.
[0148] The target shader includes a pre-configured marking function for marking the start rendering mark and the end rendering mark of the rendering channel for each rendering target. Therefore, when the graphics processor calls the target shader to process each rendering channel, the start rendering mark and the end rendering mark of the rendering channel for the current rendering target can be marked by the marking function configured in the target shader.
[0149] Specifically, the graphics processor determines the rendering channels with dependencies according to the description information of each rendering channel through the target shader. Then, for each rendering channel with dependencies corresponding to the rendering target, the start rendering identifier and the end rendering identifier in these rendering channels are marked. The graphics processor then performs image rendering processing on the merged rendering channels according to the scene data in the cache block through the target shader, and writes the intermediate results obtained by each rendering channel between the start rendering identifier and the end rendering identifier into the cache block respectively, so as to obtain the final image rendering result in the cache block. This ensures that the intermediate data are all written into the cache block and will not be written out of the system memory.
[0150] For example, a start rendering flag BeginRenderPass and an end rendering flag EndRenderPass can be defined through the marker function configured in the target shader to start and end one or more rendering passes to complete a rendering operation of rendering a certain number of objects to a texture. For example, the start rendering flag and the end rendering flag of the marker can be represented by the following code:
[0151] BeginRenderPass 1 / / indicates the start rendering mark of the first rendering pass marked;
[0152] Draw(sun) / / indicates the drawing command for the graphic object being the sun in the first rendering channel;
[0153] Draw(house) / / indicates the drawing command for the graphic object being a house in the first rendering pass;
[0154] Draw(grass) / / indicates the drawing command for the graphic object being grass in the first rendering pass;
[0155] EndRenderPass / / Indicates the end rendering mark of the marked first rendering channel;
[0156] BeginRenderPass 2 / / indicates the start rendering mark of the marked second rendering pass;
[0157] Draw(...) / / represents the drawing commands for each graphic object in the second rendering channel;
[0158] EndRenderPass / / Indicates the end rendering marker of the marked second rendering channel.
[0159] The above code indicates that each time the rendering ends and EndRenderPass is reached, all rendering instructions will be submitted to the graphics processor for execution until the final rendering result is output to the texture pointed to by the rendering target.
[0160] Furthermore, if certain conditions are met, that is, if the above two rendering channels RenderPass are rendering channels with dependencies corresponding to the rendering target, the two rendering channels can be merged into one rendering channel RenderPass. For example, the above two rendering channels RenderPass1 and RenderPass2 can be set as sub-rendering channels Subpass1 and sub-rendering channels Subpass2 of the same rendering channel. For example, the start rendering identifier and the end rendering identifier of the marker can be represented by the following code:
[0161] BeginRenderPass 1 / / indicates the start rendering mark of the first rendering pass marked;
[0162] Draw(sun) / / indicates the drawing command for the graphic object being the sun in the first rendering channel;
[0163] Draw(house) / / indicates the drawing command for the graphic object being a house in the first rendering pass;
[0164] Draw(grass) / / indicates the drawing command for the graphic object being grass in the first rendering pass;
[0165] NextSubpass() / / Indicates the drawing command of the next sub-rendering channel in the first rendering channel;
[0166] Draw(...) / / represents the drawing commands for each graphic object in the next sub-rendering channel in the first rendering channel;
[0167] EndRenderPass / / Indicates the end rendering mark of the marked first rendering channel.
[0168] Therefore, the output of Subpass 1 will be retained in the cache block instead of being directly output to the system memory, that is, the corresponding texture. Therefore, Subpass 2 can directly read the intermediate result data of Subpass 1 from the corresponding cache block, thus effectively saving bandwidth.
[0169] In one embodiment, image rendering processing is performed on scene data in a cache block in the same rendering channel to obtain an image rendering result in the cache block, including: performing image rendering processing on a merged rendering channel according to scene data in a current cache block through a target shader, and storing the obtained intermediate result to a corresponding position in the cache block; after image rendering processing is completed on the merged rendering channel according to the scene data in the current cache block, taking the next cache block as the current cache block, and repeating the step of performing image rendering processing on the merged rendering channel according to the scene data in the current cache block through the target shader.
[0170] Each cache block stores scene data corresponding to one or more pixels.
[0171] In the process of performing image rendering processing on the merged rendering channel, the graphics processor of the terminal can perform image rendering processing on the merged rendering channel through target shading, first according to the scene data in the current cache block, and at the same time store the intermediate results obtained by each rendering channel to the corresponding position in the cache block.
[0172] Then the graphics processor uses the next cache block as the current cache block, and repeats the steps of performing image rendering processing on the merged rendering pass using the scene data in the current cache block. That is, the graphics processor will switch to the next cache block only after executing all merged rendering passes on each cache block, and repeat the process on the next cache block. This can effectively improve the efficiency of image rendering processing for each pixel.
[0173] In one embodiment, the intermediate results are stored in corresponding positions in the cache block, including: obtaining the intermediate results obtained by each rendering channel; writing the intermediate results corresponding to each pixel into a corresponding cache block respectively; the byte occupancy of the intermediate results corresponding to each pixel does not exceed the memory capacity of each cache block.
[0174] The scene data and intermediate results corresponding to each pixel are stored in a corresponding cache block respectively.
[0175] Specifically, after the graphics processor of the terminal processes the merged rendering channels through the target shader, it obtains the intermediate results obtained by each rendering channel, and writes the intermediate results corresponding to each pixel into a corresponding cache block. Therefore, each pixel corresponds to the pixel data stored in the cache block one by one, that is, when each pixel performs rendering calculations through the target shader, it only needs to read the data of the corresponding pixel from the corresponding position of the current corresponding cache block.
[0176] Among them, the byte occupancy of the intermediate result corresponding to each pixel does not exceed the memory capacity of each cache block, ensuring that the amount of stored data does not exceed the size of each cache block. If the byte occupancy corresponding to each pixel exceeds the memory capacity of each cache block, the graphics processor will be forced to reduce the memory occupancy size of the data to be stored in each cache block, which will result in a certain performance degradation. For example, the memory capacity of each cache block can be specifically 16 bytes, then the byte occupancy of the intermediate result corresponding to each pixel can store 16 bytes of information for each pixel. By setting the byte occupancy of the intermediate result corresponding to each pixel, the data processing performance and efficiency in the image rendering process can be effectively guaranteed.
[0177] In one embodiment, a rendering channel includes a texture sampling channel and a lighting shading channel; image rendering processing is performed on scene data in a cache block in the same rendering channel to obtain an image rendering result in the cache block, including: performing image rendering processing on the texture sampling channel according to the scene data in the cache block through a target shader, and writing the texture result data of the texture sampling channel into the cache block; performing image rendering processing on the lighting shading channel according to the texture result data in the cache block through a target shader, and writing the shading result data of the lighting shading channel into the cache block.
[0178] Among them, the rendering pass includes a texture sampling pass and a lighting shading pass. For example, the texture sampling pass can be a GBuffer Pass, and the lighting shading pass can be a Lighting Pass. In the deferred rendering pipeline, a GBuffer Pass refers to a step of outputting the various attributes of all visible objects to multiple textures for subsequent lighting calculations. For example, the texture sampling pass can use multiple rendering targets to generate the corresponding geometry buffer, that is, in one drawing, the color, normal, material category, world space coordinates, etc. are rendered into the corresponding texture array respectively.
[0179] When the graphics processor of the terminal performs image rendering processing on the merged rendering channel, the target shader first performs the processing of the texture sampling channel according to the scene data in the cache block, and writes the texture result data of the texture sampling channel into the cache block, so that each operation of the graphics processor directly extracts the intermediate result of the previous calculation from the cache block for corresponding calculation processing.
[0180] Then the graphics processor continues to process the illumination shading channel according to the texture result data in the cache block through the target shader, and writes the shading result data of the illumination shading channel into the cache block. After all the merged rendering channels are processed, the final image rendering result corresponding to the graphics frame to be rendered can be obtained and still written into the cache block. Then the image rendering result in the cache block is written into the system memory to display the rendered image frame on the terminal screen. This avoids the large amount of data reading and writing consumption caused by writing the intermediate result data obtained by each rendering channel into the system memory, thereby effectively reducing the bandwidth consumption in the image rendering process, and then effectively improving the efficiency of the image rendering process.
[0181] In one embodiment, Figure 6 As shown, another image rendering method is provided, including:
[0182] S602, after obtaining the rendering instruction triggered by the application, call the target shader corresponding to the graphics interface of the application from the pre-compiled shaders for different types of graphics interfaces in the rendering engine; the pre-compiled shader is compiled and generated by the original shader of the rendering engine.
[0183] S604, acquiring scene data corresponding to the rendering target according to the rendering instruction, and writing the scene data into a cache block.
[0184] S606 , determining the rendering targets corresponding to the rendering channels and the dependency relationships between the rendering channels according to the description information corresponding to the rendering channels.
[0185] S608, merging the rendering channels corresponding to the same rendering target and having a dependency relationship into the same rendering channel corresponding to the rendering target; the merged rendering channel includes a texture sampling channel and a lighting shading channel.
[0186] S610, performing image rendering processing on the texture sampling channel according to the scene data in the cache block through the target shader, and writing the texture result data of the texture sampling channel into the cache block.
[0187] S612, reading texture result data corresponding to each pixel from the pixel position corresponding to each pixel in the cache block; the texture result data includes material attributes corresponding to each pixel.
[0188] S614, according to the material attributes corresponding to each pixel, obtain the lighting model that matches the material attributes; through the target shader, in the screen space, according to the lighting model corresponding to each pixel and each texture result data, perform image rendering processing on the lighting shading channel corresponding to each pixel, and write the shading result data of the lighting shading channel into the cache block.
[0189] The texture result data includes the material attributes corresponding to each pixel. Different material attributes can be processed by lighting and shading through corresponding lighting models.
[0190] The terminal's graphics processor uses the target shader to process the texture sampling channel according to the scene data in the cache block, and writes the texture result data of the texture sampling channel into the cache block. After that,
[0191] Specifically, when the graphics processor performs the processing of the lighting shading channel through the target shader, it reads the texture result data corresponding to each pixel from the pixel position corresponding to each pixel in the cache block. Then, according to the material attribute corresponding to the current pixel, a suitable lighting model is selected for calculation. The graphics processor then performs the processing of the lighting shading channel corresponding to each pixel in the screen space through the target shader according to the lighting model corresponding to each pixel and each texture result data.
[0192] Since the entire scene has been rendered to the texture, the lighting shading channel of the lighting calculation only needs to directly read the corresponding texture result data from these texture results, that is, the corresponding cache block. This process can be calculated in the screen space. In this way, the complexity of the lighting calculation that originally needed to be performed in three-dimensional space is reduced to two-dimensional screen space, thereby greatly saving the amount of calculation.
[0193] In a specific application scenario, the above-mentioned image rendering method is applied to a game application. The game application includes a rendering engine, and the rendering engine can be a rendering engine obtained by recompiling the Unreal Engine. The Unreal Engine includes the original shader, and the shader corresponding to different types of graphics interfaces is generated by recompiling the Unreal Engine.
[0194] The user can start the game application through the corresponding terminal. After the game application is started, the rendering engine runs and sends rendering instructions to the known graphics processor.
[0195] After the graphics processor of the terminal obtains the rendering instruction triggered by the game application, it calls the target shader corresponding to the graphics interface of the application from the pre-compiled shaders for different types of graphics interfaces in the rendering engine. The graphics processor of the terminal then obtains the scene data of the rendering target according to the rendering instruction and writes the scene data into the cache block. Then, through the called target shader, according to the scene data in the cache block, the rendering channels with dependencies corresponding to the rendering target are merged into the same rendering channel for image rendering processing, and the final image rendering result is written into the cache block, and finally the image rendering result obtained in the cache block is written into the system memory.
[0196] Specifically, the graphics processor performs image rendering processing on the merged rendering channel through the deferred rendering pipeline, wherein the merged rendering channel may include a texture sampling channel and a lighting shading channel.
[0197] In this embodiment, by first performing image rendering processing on the texture sampling channel, and then using the delay pipeline to perform image rendering processing on the lighting shading channel according to the obtained texture result data, multiple light sources of different colors can be rendered more efficiently, thereby effectively improving the rendering efficiency of multi-light source scenes.
[0198] like Figure 7 FIG. 1 is a schematic diagram of the image rendering effect of one of the image frames. In this case, the delay pipeline can be used to effectively display multiple light sources of different colors, thereby supporting a large number of light sources, making the rendered image more realistic, and effectively improving the rendering efficiency of multi-light source scenes.
[0199] In another specific application scenario, the above image rendering method can also be applied to applications with image editing functions, such as various image editing software, photo editing software, and video software with image editing functions. The application with image editing function includes a rendering engine, and the rendering engine includes pre-compiled shaders for different types of graphics interfaces.
[0200] After the user starts the application with image editing function through the corresponding terminal, the application can be used to edit images with various effects. For example, the image to be rendered can be an original image or a continuous image frame, or an image captured by a camera device, etc. The user can add various filter effects to the original image or continuous image frames through the application with image editing function to achieve various filter effects. The application can edit the image to be rendered, and during the image editing process, the application sends a rendering instruction to the graphics processor of the terminal.
[0201] After the graphics processor obtains the rendering instruction triggered by the application, it calls the target shader corresponding to the graphics interface of the application from the shaders pre-compiled for different types of graphics interfaces in the rendering engine. Therefore, when the application is running, it can flexibly call the target shader corresponding to the corresponding image interface according to the type of the current operating platform of the application, so that it can adapt to various operating platforms. The graphics processor then obtains the scene data of the rendering target according to the rendering instruction and writes the scene data into the cache block. Among them, the scene data includes the scene data corresponding to the image to be rendered, and also includes the filter scene data corresponding to the filter effect selected by the user.
[0202] The graphics processor then merges the rendering channels with dependencies corresponding to the rendering target through the called target shader according to the scene data in the cache block. The graphics processor performs image rendering processing on the merged rendering channels through the deferred rendering pipeline. The merged rendering channels may include a texture sampling channel and a lighting shading channel. After the texture sampling channel is firstly rendered, the lighting shading channel is rendered according to the obtained texture result data, thereby effectively improving the rendering efficiency of multi-light source scenes and obtaining better rendering effects.
[0203] The graphics processor writes the final image rendering result into the cache block, and finally writes the image rendering result obtained in the cache block into the system memory, so as to display the rendered image on the terminal screen according to the image rendering result in the system memory. This can not only effectively reduce the bandwidth consumption in the image rendering process, but also effectively improve the efficiency of the image rendering process.
[0204] It should be understood that although Figure 2 , 6 The steps in the flowchart are shown in sequence as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified in this document, there is no strict order restriction for the execution of these steps, and these steps can be executed in other orders. Moreover, Figure 2 , 6 At least part of the steps may include multiple steps or multiple stages. These steps or stages are not necessarily performed at the same time, but can be performed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed in turn or alternately with other steps or at least part of the steps or stages in other steps.
[0205] In one embodiment, Figure 8As shown, an image rendering device 800 is provided. The device can adopt a software module or a hardware module, or a combination of the two to become a part of a computer device. The device specifically includes: a target shader calling module 802, a data acquisition module 804, a rendering processing module 806 and a data writing module 808, wherein:
[0206] The target shader calling module 802 is used to call the target shader corresponding to the graphics interface of the application from the pre-compiled shaders for different types of graphics interfaces in the rendering engine after obtaining the rendering instruction triggered by the application; the pre-compiled shader is generated by compiling the original shader of the rendering engine;
[0207] The data acquisition module 804 is used to acquire scene data corresponding to the rendering target according to the rendering instruction, and write the scene data into the cache block;
[0208] The rendering processing module 806 is used to merge the rendering channels with dependencies corresponding to the rendering targets into the same rendering channel in the cache block based on the target shader; and perform image rendering processing on the scene data in the cache block in the same rendering channel to obtain the image rendering result in the cache block.
[0209] In one embodiment, Fig. 9 As shown, the above-mentioned image rendering device also includes a shader compilation module 801, which is used to configure explicit description functions and marking functions corresponding to various types of graphics interfaces in the original shader of the rendering engine, so as to compile shaders corresponding to each graphics interface; wherein the explicit description function is used to add description information of each rendering channel; the marking function is used to mark the start rendering identifier and the end rendering identifier of the merged rendering channel.
[0210] In one embodiment, the shader compilation module is also used to configure 801 explicit description functions and marking functions corresponding to different types of graphics processors in the original shader of the rendering engine for each type of graphics interface, so as to compile shaders corresponding to each type of graphics interface.
[0211] In one embodiment, the target shader calling module 802 is also used to run the rendering engine in the application when the application starts running; the rendering hardware interface layer of the rendering engine includes different types of graphics interfaces; according to the running platform type of the application, the type of graphics interface corresponding to the running platform type in the application is determined from the different types of graphics interfaces.
[0212] In one embodiment, the target shader includes explicit description functions and marking functions corresponding to different types of graphics processors; the target shader calling module 802 is also used to call the explicit description function and marking function corresponding to the type of graphics processor from the target shader through the graphics processor; through the target shader, according to the called explicit description function and marking function, the rendering channels with dependencies corresponding to the rendering target are merged into the same rendering channel in the cache block.
[0213] In one embodiment, the rendering processing module 806 is also used to obtain the description information corresponding to each of the rendering channels according to the explicit description function through the target shader; determine the rendering target corresponding to each of the rendering channels and the dependency relationship between the rendering channels according to the description information corresponding to each of the rendering channels; and merge the rendering channels with dependency relationships corresponding to the same rendering target into the same rendering channel corresponding to the rendering target in the cache block according to the marking function.
[0214] In one embodiment, the scene data corresponding to each pixel is stored in a cache block; the rendering processing module 806 is also used to call the threads corresponding to each pixel respectively, and execute the called threads in parallel to perform image rendering processing on the merged rendering channel through the target shader and scene data.
[0215] In one embodiment, the rendering processing module 806 is further used to mark the start rendering identifier and the end rendering identifier corresponding to each rendering channel having a dependency relationship with the rendering target;
[0216] The merged rendering channel is subjected to image rendering processing through the target shader according to the scene data in the cache block, and the intermediate results obtained from each rendering channel between the start rendering identifier and the end rendering identifier are written into the cache block respectively to obtain the final image rendering result in the cache block.
[0217] In one embodiment, the rendering processing module 806 is also used to perform image rendering processing on the merged rendering channel according to the scene data in the current cache block through the target shader, and store the obtained intermediate results to the corresponding position in the cache block; after the image rendering processing of the merged rendering channel is completed according to the scene data in the current cache block, the next cache block is used as the current cache block, and the step of performing image rendering processing on the merged rendering channel according to the scene data in the current cache block is repeated through the target shader.
[0218] In one embodiment, the rendering processing module 806 is also used to obtain the intermediate results obtained by each rendering channel; the intermediate results corresponding to each pixel are written into a corresponding cache block respectively; the byte occupancy of the intermediate results corresponding to each pixel does not exceed the memory capacity of each cache block.
[0219] In one embodiment, the rendering channel includes a texture sampling channel and a lighting shading channel; the rendering processing module 806 is also used to perform image rendering processing on the texture sampling channel through a target shader according to the scene data in the cache block, and write the texture result data of the texture sampling channel into the cache block; perform image rendering processing on the lighting shading channel through a target shader according to the texture result data in the cache block, and write the shading result data of the lighting shading channel into the cache block.
[0220] In one embodiment, the rendering processing module 806 is also used to read the texture result data corresponding to each pixel from the pixel position corresponding to each pixel in the cache block; the texture result data includes the material attributes corresponding to each pixel; according to the material attributes corresponding to each pixel, a lighting model matching the material attributes is obtained; and through the target shader, in the screen space, according to the lighting model corresponding to each pixel and each texture result data, image rendering processing is performed on the lighting shading channel corresponding to each pixel.
[0221] For the specific definition of the image rendering device, please refer to the definition of the image rendering method above, which will not be repeated here. Each module in the above image rendering device can be implemented in whole or in part by software, hardware and a combination thereof. The above modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
[0222] In one embodiment, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as follows: Fig.10As shown. The computer device includes a processor, a memory, a communication interface, a display screen and an input device connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be achieved through WIFI, an operator network, NFC (near field communication) or other technologies. When the computer program is executed by the processor, an image rendering method is implemented. The display screen of the computer device can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device can be a touch layer covered on the display screen, or a key, trackball or touchpad set on the computer device housing, or an external keyboard, touchpad or mouse, etc.
[0223] Those skilled in the art will understand that Fig.10 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0224] In one embodiment, a computer device is further provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above method embodiments when executing the computer program.
[0225] In one embodiment, a computer-readable storage medium is provided, storing a computer program, which implements the steps in the above method embodiments when executed by a processor.
[0226] In one embodiment, a computer program product or computer program is provided, the computer program product or computer program includes computer instructions, the computer instructions are stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device performs the steps in the above-mentioned method embodiments.
[0227] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory or optical memory, etc. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM).
[0228] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0229] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the attached claims.
Claims
1. An image rendering method, characterized in that: The method comprises: When the application is started, a rendering engine in the application is run; the rendering hardware interface layer of the rendering engine includes different types of graphic interfaces; According to the type of the running platform of the application, determining, from the different types of graphic interfaces, a type of graphic interface in the application corresponding to the running platform type; After obtaining the rendering instructions triggered by the application, Calling a target shader corresponding to the graphics interface of the application from pre-compiled shaders for different types of graphics interfaces in the rendering engine; the pre-compiled shader is generated by compiling an original shader of the rendering engine; Acquire scene data corresponding to the rendering target according to the rendering instruction, and write the scene data into a cache block; Based on the target shader, merging rendering passes corresponding to the rendering target and having a dependency relationship into a same rendering pass in a cache block; Performing image rendering processing on the scene data in the cache block in the same rendering pass to obtain an image rendering result in the cache block.
2. The method according to claim 1, characterized in that Before calling the target shader corresponding to the graphics interface of the application program from the shaders precompiled for different types of graphics interfaces in the rendering engine, the method further includes: In the original shader of the rendering engine, respectively configure explicit description functions and marking functions corresponding to various types of graphics interfaces to compile and obtain shaders corresponding to the respective graphics interfaces; The explicit description function is used to add description information of each rendering channel; and the marking function is used to mark the start rendering identifier and the end rendering identifier of the merged rendering channel.
3. The method according to claim 2, characterized in that In the original shader of the rendering engine, explicit description functions and marking functions corresponding to various types of graphics interfaces are respectively configured to compile and obtain shaders corresponding to each of the graphics interfaces, including: In the original shader of the rendering engine, for each type of graphics interface, explicit description functions and marking functions corresponding to different types of graphics processors are respectively configured to compile and obtain shaders corresponding to each type of the graphics interface.
4. The method according to claim 1, characterized in that: The target shader includes explicit description functions and marking functions corresponding to different types of graphics processors; and based on the target shader, merging the rendering channels corresponding to the rendering target and having dependencies into the same rendering channel in the cache block includes: By means of a graphics processor, calling from the target shader an explicit description function and a tag function corresponding to the type of the graphics processor; By means of the target shader, rendering channels with dependency relationships corresponding to the rendering target are merged into the same rendering channel in a cache block according to the explicit description function and the marking function.
5. The method according to claim 4, characterized in that The step of merging the rendering channels corresponding to the rendering target and having a dependency relationship into the same rendering channel in a cache block by the target shader according to the explicit description function and the marking function includes: Obtaining description information corresponding to each of the rendering channels according to the explicit description function through the target shader; Determine, according to the description information corresponding to each of the rendering passes, the rendering targets corresponding to each of the rendering passes, and the dependency relationship between the rendering passes; According to the marking function, the rendering channels corresponding to the same rendering target and having dependency relationships are merged into the same rendering channel corresponding to the rendering target in the cache block.
6. The method according to claim 1, characterized in that The scene data corresponding to each pixel is stored in a cache block; The performing image rendering processing on the scene data in the cache block in the same rendering channel to obtain an image rendering result in the cache block includes: The threads corresponding to each pixel are called respectively, and the called threads are executed in parallel to perform image rendering processing on the merged rendering channel through the target shader and the scene data.
7. The method according to claim 1, characterized in that The performing image rendering processing on the scene data in the cache block in the same rendering channel to obtain an image rendering result in the cache block includes: For each of the rendering channels corresponding to the rendering target and having a dependency relationship, marking a start rendering identifier and an end rendering identifier corresponding to each of the rendering channels; The target shader performs image rendering processing on the merged rendering channel according to the scene data in the cache block, and writes the intermediate results obtained by each rendering channel between the start rendering identifier and the end rendering identifier into the cache block respectively, so as to obtain the final image rendering result in the cache block.
8. The method according to claim 1, characterized in that The performing image rendering processing on the scene data in the cache block in the same rendering channel includes: Performing image rendering processing on the merged rendering channel according to the scene data in a current cache block through the target shader, and storing the obtained intermediate result to a corresponding position in the cache block; After image rendering processing is completed for the merged rendering channel according to the scene data in the current cache block, the next cache block is used as the current cache block, and the step of performing image rendering processing on the merged rendering channel according to the scene data in the current cache block through the target shader is repeated.
9. The method according to claim 8, characterized in that The step of storing the obtained intermediate result to a corresponding position in the cache block includes: Obtaining intermediate results obtained by each of the rendering passes; The intermediate result corresponding to each pixel is written into a corresponding cache block respectively; the byte occupation amount of the intermediate result corresponding to each pixel does not exceed the memory capacity of each cache block.
10. The method according to any one of claims 1 to 9, characterized in that: The rendering channel includes a texture sampling channel and a lighting shading channel; the image rendering process is performed on the scene data in the cache block in the same rendering channel, including: Through the target shader, according to the scene data in the cache block, the texture sampling channel is subjected to image rendering processing, and the texture result data of the texture sampling channel is written into the cache block; The target shader is used to perform image rendering processing on the illumination shading channel according to the texture result data in the cache block, and the shading result data of the illumination shading channel is written into the cache block.
11. The method according to claim 10, characterized in that The step of performing image rendering processing on the illumination shading channel according to the texture result data in the cache block by using the target shader includes: Reading texture result data corresponding to each pixel from the pixel position corresponding to each pixel in the cache block; the texture result data includes material attributes corresponding to each pixel; According to the material attributes corresponding to each pixel, a lighting model matching the material attributes is obtained; The target shader performs image rendering processing on the illumination shading channel corresponding to each pixel in the screen space according to the illumination model corresponding to each pixel and each of the texture result data.
12. An image rendering device, characterized in that: The device comprises: A target shader calling module is used to run the rendering engine in the application when the application is started; the rendering hardware interface layer of the rendering engine includes different types of graphics interfaces; according to the running platform type of the application, the type of graphics interface corresponding to the running platform type in the application is determined from the different types of graphics interfaces; after obtaining the rendering instruction triggered by the application, the target shader corresponding to the graphics interface of the application is called from the shaders pre-compiled for different types of graphics interfaces in the rendering engine; the pre-compiled shader is generated by compiling the original shader of the rendering engine; A data acquisition module, used for acquiring scene data corresponding to a rendering target according to the rendering instruction, and writing the scene data into a cache block; A rendering processing module is used to merge the rendering channels with dependencies corresponding to the rendering target into the same rendering channel in a cache block based on the target shader; and perform image rendering processing on the scene data in the cache block in the same rendering channel to obtain an image rendering result in the cache block.
13. The device according to claim 12, characterized in that The device also includes: A shader compilation module is used to configure explicit description functions and marking functions corresponding to various types of graphics interfaces in the original shader of the rendering engine, so as to compile shaders corresponding to each of the graphics interfaces; wherein the explicit description function is used to add description information of each of the rendering channels; and the marking function is used to mark the start rendering identifier and the end rendering identifier of the merged rendering channel.
14. The device according to claim 13, characterized in that The shader compilation module is also used to configure explicit description functions and marking functions corresponding to different types of graphics processors in the original shader of the rendering engine for each type of graphics interface, so as to compile shaders corresponding to each type of the graphics interface.
15. The device according to claim 12, characterized in that The target shader includes explicit description functions and marking functions corresponding to different types of graphics processors; the rendering processing module is also used to call the explicit description function and marking function corresponding to the type of the graphics processor from the target shader through the graphics processor; through the target shader, according to the explicit description function and the marking function, the rendering channels with dependencies corresponding to the rendering target are merged into the same rendering channel in the cache block.
16. The device according to claim 15, characterized in that The rendering processing module is further used to obtain description information corresponding to each of the rendering channels according to the explicit description function through the target shader; determine the rendering target corresponding to each of the rendering channels and the dependency relationship between the rendering channels according to the description information corresponding to each of the rendering channels; According to the marking function, the rendering channels corresponding to the same rendering target and having dependency relationships are merged into the same rendering channel corresponding to the rendering target in the cache block.
17. The device according to claim 12, characterized in that The scene data corresponding to each pixel is stored in a cache block; the rendering processing module is also used to call the threads corresponding to each pixel respectively, and execute the called threads in parallel to perform image rendering processing on the merged rendering channel through the target shader and the scene data.
18. The device according to claim 12, characterized in that The rendering processing module is further used to mark the start rendering identifier and the end rendering identifier corresponding to each rendering channel having a dependency relationship with the rendering target; The target shader performs image rendering processing on the merged rendering channel according to the scene data in the cache block, and writes the intermediate results obtained by each rendering channel between the start rendering identifier and the end rendering identifier into the cache block respectively, so as to obtain the final image rendering result in the cache block.
19. The device according to claim 12, characterized in that The rendering processing module is further used to perform image rendering processing on the merged rendering channel according to the scene data in a current cache block through the target shader, and store the obtained intermediate result to a corresponding position in the cache block; After image rendering processing is completed for the merged rendering channel according to the scene data in the current cache block, the next cache block is used as the current cache block, and the step of performing image rendering processing on the merged rendering channel according to the scene data in the current cache block through the target shader is repeated.
20. The device according to claim 19, characterized in that The rendering processing module is also used to obtain the intermediate results obtained by each rendering channel; write the intermediate results corresponding to each pixel into a corresponding cache block respectively; The byte occupation of the intermediate result corresponding to each of the pixels does not exceed the memory capacity of each of the cache blocks.
21. The device according to any one of claims 12 to 20, characterized in that The rendering channel includes a texture sampling channel and a lighting shading channel; the rendering processing module is also used to perform image rendering processing on the texture sampling channel through the target shader according to the scene data in the cache block, and write the texture result data of the texture sampling channel into the cache block; The target shader is used to perform image rendering processing on the illumination shading channel according to the texture result data in the cache block, and the shading result data of the illumination shading channel is written into the cache block.
22. The device according to claim 21, characterized in that The rendering processing module is also used to read the texture result data corresponding to each pixel from the pixel position corresponding to each pixel in the cache block; the texture result data includes the material attributes corresponding to each pixel; according to the material attributes corresponding to each pixel, a lighting model matching the material attributes is obtained; through the target shader, in the screen space, according to the lighting model corresponding to each pixel and each of the texture result data, image rendering processing is performed on the lighting shading channel corresponding to each pixel.
23. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 11 are implemented.
24. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 11 are implemented.
25. A computer program product, comprising computer instructions, which, when executed by a processor, implement the steps of the method according to any one of claims 1 to 11.
Citation Information
Patent Citations
Image rendering method, image rendering device and electronic device
CN106997610A
Shader reorganization method and device
CN107133909A