Graph rendering method and system based on complex scene
By constructing a flat scene data structure and block rendering technology, the problem of low rendering efficiency of complex scenes is solved, efficient parallelism of CPU and GPU is achieved, interface call overhead is reduced, and rendering efficiency and user experience are improved.
Patent Information
- Application Number
- CN202310323072.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-29
- Publication Date
- 2024-10-01
AI Technical Summary
The graphics rendering method based on complex scenes in the existing technology has low rendering efficiency when rendering large-scale complex scenes, resulting in frequent lag problems in interactive scene browsing and editing operations.
By constructing the scene to be rendered as a flat scene data structure, grouping it into several rendering blocks, and counting and processing the primitive node status set and its global rendering data according to the rendering order, the multi-core and multi-threading of the CPU and GPU are used. Running in parallel reduces the interface calling overhead of traditional graphics driver calling interfaces and avoids the CPU and GPU waiting for each other.
It improves rendering efficiency, solves the lag problem during scene interactive browsing and editing operations, and improves user experience.
Smart Images

Figure CN118736090A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image rendering, and in particular to a graphics rendering method and system based on complex scenes. Background Art
[0002] As an important support for building information technology, 3D graphics rendering plays an important role as the main interface for human-computer interaction in building-related application software. In 3D graphics application software, after the user inputs the operation, the software must update and render the scene based on the user input to output a new picture, thereby completing the response to the user input. Under continuous user input, the software continuously updates and renders the scene, thereby completing continuous interactive response. Generally, to ensure a smooth interactive experience, the graphics software needs to reach a rendering rate of about 20 frames per second.
[0003] However, due to the complexity and multi-disciplinary nature of building information, the data carried by the software is very huge. When the amount of complex scene data is so large that it exceeds the load of CPU and GPU resources, the time required for rendering becomes non-negligible, making it difficult to ensure the frame rate required for a smooth interactive experience. The existing building information modeling (BIM) graphic display engine has low rendering efficiency when editing and displaying BIM large scene data with millions of elements, and there will be obvious freezes during scene interactive browsing and editing operations. Summary of the invention
[0004] In view of this, an embodiment of the present invention provides a complex scene-based graphics rendering method, device, electronic device and medium to overcome the problem that the complex scene-based graphics rendering method in the prior art has low rendering efficiency and often occurs freezes when rendering large-scale complex scenes.
[0005] According to a first aspect, an embodiment of the present invention provides a graphics rendering method based on a complex scene, which is applied to a CPU, and the method includes:
[0006] Constructing the scene to be rendered into a flattened scene data structure, wherein the data objects in the flattened scene data structure are primitive nodes in the scene to be rendered;
[0007] Grouping the primitive nodes in the flattened scene data structure to obtain a plurality of rendering blocks, wherein the rendering blocks store the corresponding relationship between each primitive node and the rendering block and the indirect rendering cache data of each primitive node;
[0008] Determine the rendering order of each rendering block;
[0009] Statistics are performed on the primitive node state set and the corresponding global rendering data of the current rendering block in accordance with the rendering order, and the statistical results are sent to the GPU so that the GPU renders the current rendering block based on the statistical results. In the process of the GPU rendering the current rendering block, statistics are performed on the primitive node state set and the corresponding global rendering data of the next rendering block corresponding to the next rendering order in accordance with the rendering order, and the next statistical result is sent to the GPU until the rendering of all rendering blocks is completed.
[0010] Optionally, the grouping of primitive nodes in the flattened scene data structure to obtain a plurality of rendering blocks includes:
[0011] Grouping the primitive nodes in the flattened scene data structure according to the priority and primitive type of each primitive node to obtain a plurality of rendering blocks; wherein the priority and primitive type of the primitive nodes in the same rendering block are the same;
[0012] Based on the identifier of each primitive node, a corresponding relationship between the rendering block and each primitive node is established, and the corresponding relationship is stored in the rendering block;
[0013] The indirect rendering data corresponding to each primitive node is stored in its corresponding rendering block.
[0014] Optionally, determining the rendering order of each rendering block includes:
[0015] The rendering order of each rendering block is determined according to the priority and primitive type of the primitive node corresponding to each rendering block.
[0016] Optionally, determining the rendering order of each rendering block according to the priority and primitive type of the primitive node corresponding to each rendering block includes:
[0017] Determine whether the primitive type of the current rendering block is a transparent primitive;
[0018] When the primitive type of the current rendering block is a transparent primitive, determining the rendering order of the current rendering block in the rendering blocks corresponding to all transparent primitives according to the priority of the primitive node corresponding to the current rendering block;
[0019] When the primitive type of the current rendering block is a non-transparent primitive, the rendering order of the current rendering block in the rendering blocks corresponding to all non-transparent primitives is determined according to the priority of the primitive node corresponding to the current rendering block, wherein the rendering order of the rendering blocks corresponding to each non-transparent primitive precedes the rendering order of the rendering blocks corresponding to each transparent primitive.
[0020] Optionally, the counting of the primitive node state set of the current rendering block and its corresponding global rendering data according to the rendering order includes:
[0021] Extracting a primitive index of each primitive node from the indirect rendering cache data of each primitive node of the current rendering block;
[0022] Based on the primitive index, corresponding primitive states are extracted from the rendering cache data of the scene to be rendered to form a primitive node state set, and global rendering data corresponding to each primitive index is extracted from the rendering cache data of the scene to be rendered.
[0023] Optionally, the method further comprises:
[0024] Get the rendering cache data of the scene to be rendered;
[0025] The rendering cache data is stored in a global paging manner.
[0026] According to a second aspect, an embodiment of the present invention further provides a complex scene-based graphics rendering method, which is applied to a GPU, and the method includes:
[0027] Receive a statistics result of a primitive node state set of a current rendering block and its corresponding global rendering data sent by the CPU, wherein the current rendering block is obtained by the CPU constructing a scene to be rendered into a flattened scene data structure and grouping primitive nodes in the flattened scene data structure;
[0028] The current rendering block is rendered based on the statistical result, and after the rendering is completed, the statistical result of the primitive node status set of the current rendering block and the corresponding global rendering data sent by the receiving CPU is returned until the rendering of all rendering blocks is completed. In the process of rendering the current rendering block, the CPU performs statistics on the primitive node status set and the corresponding global rendering data of the next rendering block corresponding to the next rendering order in the rendering order, and sends the next statistical result to the GPU.
[0029] Optionally, the rendering the current rendering block based on the statistical result includes:
[0030] Performing frustum clipping on each primitive node of the current rendering block, and removing primitive nodes blocked by the currently rendered nodes, to obtain primitive nodes to be rendered;
[0031] Determining a node rendering order of each to-be-rendered primitive node based on a rendering state of the to-be-rendered primitive node in the primitive node state set;
[0032] The global rendering data corresponding to each primitive node to be rendered is sequentially extracted according to the node rendering order for rendering.
[0033] Optionally, determining the node rendering order of each primitive node to be rendered based on the rendering status of the primitive node to be rendered in the primitive node status set includes:
[0034] Grouping the to-be-rendered primitive nodes based on the rendering status of the to-be-rendered primitive nodes in the primitive node status set;
[0035] The node rendering order of each to-be-rendered primitive node is determined based on the grouping result, wherein the node rendering order of the to-be-rendered primitive nodes having the same rendering state is the same.
[0036] According to a third aspect, an embodiment of the present invention further provides a complex scene-based graphics rendering system, comprising: a CPU and a GPU;
[0037] The CPU is used to construct a scene to be rendered into a flattened scene data structure, wherein the data objects in the flattened scene data structure are primitive nodes in the scene to be rendered; grouping the primitive nodes in the flattened scene data structure to obtain a plurality of rendering blocks, wherein the rendering blocks store the corresponding relationship between each primitive node and the rendering block and the indirect rendering cache data of each primitive node; determining the rendering order of each rendering block; and performing statistics on the primitive node state set of the current rendering block and its corresponding global rendering data according to the rendering order, and sending the statistical results to the GPU;
[0038] The GPU is used to receive the statistical results of the primitive node status set and the corresponding global rendering data of the current rendering block sent by the CPU; render the current rendering block based on the statistical results, and re-receive the statistical results of the primitive node status set and the corresponding global rendering data of the current rendering block sent by the CPU after the rendering is completed, until all rendering blocks are rendered. In the process of the GPU rendering the current rendering block, the CPU counts the primitive node status set and the corresponding global rendering data of the next rendering block corresponding to the next rendering order in the rendering order, and sends the next statistical result to the GPU.
[0039] The technical solution of the present invention has the following advantages:
[0040] The graphics rendering method and system based on complex scenes provided by the embodiments of the present invention utilize the CPU to construct the scene rendering data into a flat data structure, which is beneficial to the subsequent multi-core and multi-threaded parallel operation of the CPU and GPU, and solves the problem of low efficiency of the preparation rendering queue of the traditional graphics display engine. The primitive nodes in the flat data structure are grouped and rendered in blocks by the GPU in the order of rendering blocks, thereby reducing the huge interface call overhead caused by the traditional graphics driver calling the interface to draw primitives one by one. When the previous block of data is rendered in the GPU rendering thread, the CPU performs pre-rendering preparation work for the next block of data, avoiding the problem of the CPU and GPU waiting for each other in the traditional rendering engine, improving the parallelism of the CPU and GPU, and improving the rendering efficiency, and effectively solving the jamming problem during scene interactive browsing and editing operations. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0042] Figure 1 A schematic diagram of the structure of a graphics rendering system based on a complex scene according to an embodiment of the present invention;
[0043] Figure 2 It is a schematic diagram of interaction of graphics rendering based on complex scenes in an embodiment of the present invention;
[0044] Figure 3 A schematic diagram of a specific working process of the CPU and GPU in an embodiment of the present invention;
[0045] Figure 4 This is the effect picture after turning on GPU frustum clipping and occlusion culling;
[0046] Figure 5 This is the effect picture after GPU frustum clipping and occlusion culling are not enabled;
[0047] Figure 6 and Figure 7 All of them are display effect diagrams of BIM electromechanical scenes rendered using the rendering method provided by the embodiments of the present invention. DETAILED DESCRIPTION
[0048] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0049] In the description of the present invention, it should be noted that the terms “first”, “second” and “third” are only used for descriptive purposes and cannot be understood as indicating or implying relative importance.
[0050] The technical features involved in the different embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other.
[0051] In the existing technology, in order to ensure smooth interaction of ultra-large-scale scene graphics rendering, some software uses batch incremental rendering methods, primitive merging (static instance packaging and dynamic instance packaging), first frame optimization and other technologies to optimize the rendering efficiency of large scenes.
[0052] Batch incremental rendering is to divide the entire scene data to be rendered into multiple batches, render each batch to the buffer in turn, and finally submit the rendering results of the buffer to the display. When the software receives user input during the scene rendering process, regardless of whether the entire scene has been rendered, it will end the rendering as soon as possible (render the current batch being rendered and discard subsequent batches) and submit the results to the display for display, so as to process the new user input as soon as possible, thereby ensuring the smoothness of interactive feedback. This solution can ensure that there will be no lag problems during interactive operations of ultra-large-scale scene data, but there will be comparison update flickering problems during the editing process, resulting in a poor editing workflow experience.
[0053] First frame optimization technology refers to finding out the graphics elements of the scene's outer contour before the scene rendering begins. When rendering the full scene perspective, the scene's outer contour graphics elements are rendered first, and then the remaining graphics elements are rendered in batches. First frame optimization technology is an improvement on batch rendering technology, which can better solve the problem of a large number of graphics elements inside a single BIM building. When rendering in batches, it can improve the flickering phenomenon when the scene is displayed.
[0054] Static instance packing is to merge the geometric data of multiple primitives with the same material data in the scene into one primitive, so as to reduce rendering batches and improve rendering efficiency. Dynamic instance packing refers to packing models in the scene that reference the same geometric data but have different spatial positions using instanced rendering technology (Instancing Draw). Both static and dynamic instance packing have requirements for scene data material data and geometric data. If there are many rendering states and geometric data types in the scene, these two instance packing technologies cannot reduce the rendering batches in the scene. In addition, when editing and modifying the scene, the static instance packing technology needs to unpack the large packaged geometric data, and repack it after the modification. If there are many packaged primitives in the scene, unpacking and packing will cause lag problems.
[0055] Neither traditional batch rendering nor batch incremental rendering can completely solve the problem of obvious flickering when the scene is displayed when the entire scene needs to be refreshed and redrawn in the case of continuous interaction and changes in camera perspective. Especially in the case of ultra-large-scale scenes (millions of primitives), the current batch rendering method only reduces the rendering time of each frame by batching, but cannot reduce the time consumed in the process of primitive organization and cutting, resulting in obvious lag problems and affecting user experience.
[0056] In large scenes, the editing process of graphic batch merging technology may experience lags due to the need to unpack and repack. In BIM design software, due to the large number of editing operations, lags may occur frequently, affecting user efficiency and experience.
[0057] BIM's complex large-scale scene data has the following main characteristics: a large number of BIM components and scene nodes; a large number of triangles in the entire scene while the number of triangles in a single component is relatively small; a large number of internal components in a single BIM building; and a large number of editing operations on the design BIM platform.
[0058] Currently, many BIM graphic display engines have low rendering efficiency when editing and displaying BIM large scene data with millions of elements, low efficiency in multi-scene cropping of scene nodes, and are relatively laggy during scene interactive browsing and editing operations. There is currently no comprehensive solution for the optimization technology of BIM graphic display engines.
[0059] Based on the above problems, an embodiment of the present invention provides a graphics rendering system based on complex scenes, such as Figure 1 As shown, the system includes: a CPU and a GPU;
[0060] The CPU is used to construct the scene to be rendered into a flattened scene data structure, where the data objects in the flattened scene data structure are primitive nodes in the scene to be rendered; group the primitive nodes in the flattened scene data structure to obtain a number of rendering blocks, where the rendering blocks store the corresponding relationship between each primitive node and the rendering block and the indirect rendering cache data of each primitive node; determine the rendering order of each rendering block; and count the primitive node state set of the current rendering block and its corresponding global rendering data according to the rendering order, and send the statistical results to the GPU;
[0061] The GPU is used to receive the statistical results of the primitive node state set and the corresponding global rendering data of the current rendering block sent by the CPU; render the current rendering block based on the statistical results, and re-receive the statistical results of the primitive node state set and the corresponding global rendering data of the current rendering block sent by the CPU after the rendering is completed until all rendering blocks are rendered. In the process of the GPU rendering the current rendering block, the CPU counts the primitive node state set and the corresponding global rendering data of the next rendering block corresponding to the next rendering order in the rendering order, and sends the next statistical result to the GPU.
[0062] The detailed working process of the CPU and GPU can be found in the description of the relevant steps of the method embodiment below, which will not be described in detail here.
[0063] Through the coordinated cooperation of the above-mentioned components, the graphics rendering system based on complex scenes provided by the embodiment of the present invention utilizes the CPU to construct the scene rendering data into a flat data structure, which is beneficial to the subsequent multi-core and multi-threaded parallel operation of the CPU and GPU, and solves the problem of low efficiency of the preparation rendering queue of the traditional graphics display engine. By grouping the primitive nodes in the flat data structure, the GPU performs block rendering in the order of rendering blocks, reducing the huge interface call overhead caused by the traditional graphics driver calling the interface to draw primitives one by one. When the previous block of data is rendered in the GPU rendering thread, the CPU performs pre-rendering preparation work for the next block of data, avoiding the problem of CPU and GPU waiting for each other in the traditional rendering engine, improving the parallelism of the CPU and GPU, and improving the rendering efficiency, effectively solving the jamming problem during scene interactive browsing and editing operations.
[0064] The embodiment of the present invention also provides a graphics rendering method based on complex scenes, which is applied to the above-mentioned Figure 1 The CPU and GPU shown, such as Figure 2 As shown, the CPU is used to execute steps S101 to S105, and the GPU is used to execute steps S201 to S202.
[0065] Step S101: constructing a scene to be rendered into a flattened scene data structure.
[0066] The data objects in the flattened scene data structure are primitive nodes in the scene to be rendered.
[0067] Step S102: grouping the primitive nodes in the flattened scene data structure to obtain a number of rendering blocks.
[0068] The corresponding relationship between each primitive node and the rendering block and the indirect rendering cache data of each primitive node are stored in the rendering block. By constructing a flat rendering data organization structure that is conducive to parallel processing, the flat data structure is stored in blocks at the same time, and each block stores the rendering data of a certain number of primitive nodes. In each rendering block, the rendering index data of the primitive is mainly stored, and the actual rendering data of the primitive is not stored.
[0069] For example, the basis for establishing the rendering block is to first define the maximum number of primitives in the rendering block (61440 by default), and then group the primitives with the same priority according to their priority and primitive type (transparent or not). If the data in the rendering block is full, create a new rendering block to continue adding data. In order to correctly display transparent primitives, transparent primitives are preferentially allocated to the same rendering block.
[0070] The main functions and purposes of constructing rendering blocks are as follows: the rendering index data in the block adopts a flat data structure, which is conducive to the multi-core and multi-threaded parallel operation of the CPU and GPU, solving the problem of low efficiency of the preparation rendering queue of the traditional graphics display engine; and providing a basic data organization structure for the subsequent block rendering process. When using block rendering, while the previous block of data is being rendered in the rendering thread, the next block of data is being prepared before rendering, improving the parallelism between the CPU and GPU.
[0071] Specifically, in one embodiment, the CPU executes the above step S102 specifically including the following steps:
[0072] Step S21: grouping the primitive nodes in the flattened scene data structure according to the priority and primitive type of each primitive node to obtain a number of rendering blocks.
[0073] The priority and type of the primitive nodes in the same rendering block are the same. Specifically, the primitive type is divided into transparent primitives and non-transparent primitives according to whether they are transparent. The priority of the primitive node is the rendering priority of each primitive node pre-selected and specified by the scene to be rendered, such as: in a three-dimensional building, the priority of each primitive node is determined according to the order of the primitives from bottom to top. This is only an example, and the present invention is not limited to this.
[0074] Step S22: Based on the identifier of each primitive node, a corresponding relationship between the rendering block and each primitive node is established, and the corresponding relationship is stored in the rendering block.
[0075] Specifically, the rendering blocks are constructed at the same time as the scene is constructed. Through the creation, deletion and update notification events of the primitives in the scene, the primitive's RenderableId (i.e., primitive unique ID), StatesetId (i.e., rendering material unique ID), BoudingBox (primitive outer packaging box), and Transform (primitive position matrix) are synchronously updated to the DrawItem of the rendering block to establish the correspondence between the primitive nodes and the rendering blocks.
[0076] Step S23: storing the indirect rendering data corresponding to each primitive node in its corresponding rendering block.
[0077] Specifically, in order to make the data in the rendering block as lightweight as possible, occupy less memory and facilitate quick modification, the data organization of the rendering block mainly includes two data: the correspondence between the primitive node and the rendering block, and the other is the indirect rendering GPU cache data (IndirectComand Buffer) containing the primitives in the block.
[0078] Constructing indirect rendering data within the rendering block has two main functions and goals: reducing the huge interface call overhead caused by the traditional graphics driver calling the interface to draw each primitive one by one. It can cooperate with GPU clipping and culling, and GPU rendering state sorting to complete efficient clipping and rendering state sorting. The processed data can be directly rendered by the GPU without reading the data back to the CPU for processing.
[0079] Exemplarily, indirect rendering data requires setting the vertex data structure of the primitive. In the embodiment of the present invention, the non-indexed rendering data stream is rendered in the same way as the vertex indexed data stream using a default vertex index data stream (composed of numbers such as 0, 1, 2); in addition, the vertex data stream is passed in through the descriptor table instead of setting the vertex data stream interface through the new graphics driver interface DirectX12 and Vulkan, thereby realizing the rendering pipeline non-vertex structure type binding technology. This technology realizes that all indirect rendering data (Indirect Draw) in the block uses the same data interface, thereby ensuring the unity and simplicity of the primitive drawing data structure in the block.
[0080] Step S103: Determine the rendering order of each rendering block.
[0081] Specifically, in one embodiment, the CPU executes the above step S103 by determining the rendering order of each rendering block according to the priority and primitive type of the primitive node corresponding to each rendering block.
[0082] Exemplarily, it can be determined by judging whether the primitive type of the current rendering block is a transparent primitive; when the primitive type of the current rendering block is a transparent primitive, determining the rendering order of the current rendering block among all rendering blocks corresponding to transparent primitives according to the priority of the primitive node corresponding to the current rendering block; when the primitive type of the current rendering block is a non-transparent primitive, determining the rendering order of the current rendering block among all rendering blocks corresponding to non-transparent primitives according to the priority of the primitive node corresponding to the current rendering block, wherein the rendering order of the rendering blocks corresponding to each non-transparent primitive precedes the rendering order of the rendering blocks corresponding to each transparent primitive.
[0083] Step S104: statistics are collected on the primitive node state set of the current rendering block and its corresponding global rendering data in the rendering order, and the statistical results are sent to the GPU.
[0084] Specifically, in one embodiment, the CPU executes the above step S104 specifically including the following steps:
[0085] Step S41: extracting the primitive index of each primitive node from the indirect rendering cache data of each primitive node of the current rendering block.
[0086] Specifically, the primitive index of the primitive node includes primitive identifiers such as the primitive's RenderableId (i.e., primitive unique ID), StatesetId (i.e., rendering material unique ID), etc., so as to retrieve primitive-related rendering data using the primitive identifiers.
[0087] Step S42: extracting corresponding primitive states from the rendering cache data of the scene to be rendered based on the primitive index to form a primitive node state set, and extracting global rendering data corresponding to each primitive index from the rendering cache data of the scene to be rendered.
[0088] Specifically, the CPU obtains the rendering cache data of the scene to be rendered; and stores the rendering cache data in a global paging manner.
[0089] In actual applications, the above rendering cache data mainly includes: primitive material data cache (MaterialCache), primitive instance data cache (Renderable Cache), primitive indirect rendering data cache (IndirectCommand Buffer), and global parameter cache (Global Cache). In order to make the data in the rendering block as lightweight as possible, the material data cache (Material Cache) and primitive instance data cache (RenderableCache) are not stored in the rendering block, but are managed in a global paging manner. The corresponding cache data is created when the primitive and material object are created.
[0090] Exemplarily, the global parameter cache mainly includes camera viewport parameters, global rendering effect parameters, etc. The material data cache Materials GPU Cache mainly includes material lighting parameters and texture map index parameters. The primitive instance data cache Renderable GPU Cache mainly includes primitive spatial position information, maximum outer box information, and index value pointing to material cache. By extracting these data to form global rendering data, a data basis is provided for subsequent GPU rendering.
[0091] By building rendering cache data, the rendering parameters need to be temporarily collected and then set to the underlying graphics driver API, solving the performance bottleneck caused by rendering parameter settings. Basic data preparation is performed for GPU culling and GPU rendering state sorting in the subsequent rendering process.
[0092] Step S201: receiving the statistics of the primitive node state set of the current rendering block and its corresponding global rendering data sent by the CPU.
[0093] Step S202: Render the current rendering block based on the statistical result, and return to step S201 after the rendering is completed until all rendering blocks are rendered.
[0094] Specifically, in one embodiment, the GPU performs the above step S202 to render the current rendering block based on the statistical result, which specifically includes the following steps:
[0095] Step S221: perform frustum pruning on each primitive node of the current rendering block, and remove primitive nodes blocked by the currently rendered nodes to obtain primitive nodes to be rendered.
[0096] Specifically, through the combined use of GPU rendering state classification and GPU clipping occlusion culling, before the GPU rendering state is sorted, the GPU clipping occlusion culling algorithm completes the culling of primitives outside the view cone and occluded, and the culling information is marked on the rendering state Key. The rendering state Key consists of 32 integer data, the first 12 bits are the rasterization state ID, the next 16 bits are the shader ID, the next 3 bits are the primitive type ID, and the last bit is whether the primitive is visible. The culled primitives only need to set the last bit to 0, which indicates that the primitive will be removed from the rendering queue. When sorting the rendering states, primitives with the same rasterization ID and shader ID combination values in the same rendering state will be arranged adjacently, and primitives with the last bit being 0 will be arranged last. By counting the number of primitives whose last bit is not 0 in the same rendering state, the correct drawing queue for each rendering state can be obtained.
[0097] Step S222: determining a node rendering order of each primitive node to be rendered based on the rendering status of the primitive nodes to be rendered in the primitive node status set.
[0098] Specifically, the GPU groups each to-be-rendered primitive node based on the rendering status of the to-be-rendered primitive node in the primitive node status set; and determines the node rendering order of each to-be-rendered primitive node based on the grouping result, wherein the node rendering order of the to-be-rendered primitive nodes with the same rendering status is the same.
[0099] Step S223: extracting the global rendering data corresponding to each primitive node to be rendered in sequence according to the node rendering order for rendering.
[0100] Exemplarily, by using dynamic batching technology for rendering, there is no need to merge geometric data. Instead, by constructing auxiliary index information, the primitive drawing index ID is stored in the auxiliary index information, and multiple primitives are rendered at one time through the vertex programmable shader, thereby improving rendering efficiency.
[0101] Specifically, GPU is used to implement the classification of rendering states within a block. By mapping different rendering states to an Int type, a pair of mappings is constructed by the index of the sequence number of the primitive in the block and the rendering state Key.<Key,Index> , through GPU parallel sorting algorithm such as bitonic sorting algorithm, sort by key value, and then<Key,Index> That is, a rendering state queue is needed. The GPU can construct the indirect rendering data after state sorting through the serial number subscript index Index of the primitives in the block. Since the CPU has already counted the number of all rendering state categories in the block and the number of primitives contained in each category in parallel, each rendering state can be called once for indirect rendering data (Indirect Draw) to draw the primitives in the block under that rendering state. In this solution, the CPU only needs to count the number of rendering state categories, and does not need to build a rendering queue. The GPU directly sorts the rendering queue and constructs the number of rendering queues. Compared with the traditional rendering queue construction method, it can effectively improve rendering efficiency.
[0102] Step S105: while the GPU is rendering the current rendering block, statistics are collected on the primitive node state set and corresponding global rendering data of the next rendering block corresponding to the next rendering order according to the rendering order, and the next statistical result is sent to the GPU until all rendering blocks are rendered.
[0103] By preparing for the next block of data to be rendered while the previous block of data is being rendered in the rendering thread, the CPU and GPU work together to render a frame of the scene, avoiding the problem of the CPU and GPU waiting for each other in traditional rendering engines, improving the parallelism of the CPU and GPU, and improving rendering efficiency.
[0104] Specifically, Figure 3 As shown in the figure, by classifying the primitives in the scene into different rendering blocks, they are rendered block by block according to the priority. In the first block, after completing the parallel primitive state update and statistics of the CPU, the primitive state sorting, primitive frustum clipping and occlusion culling operations are subsequently submitted to the GPU's Compute Queue background command queue. After the command queue is completed, the background rendering command queue Graphic Queue is notified through the message mechanism to start rendering; the rendering process is executed by the GPU in the background and will not block the CPU operation, so the CPU can immediately start the next block primitive state update statistics and GPU Compute operation. The block rendering technology solves the problem that the traditional rendering engine needs extra CPU time to prepare the rendering data queue while the GPU may be idle, and the CPU is idle waiting while the GPU is drawing. After the GPU clipping is completed, the data does not need to be transferred back to the CPU for processing, but directly uses the GPU-Driven indirect rendering drawing technology (IndirectDraw) for efficient rendering.
[0105] The rendering state of the primitive is referred to as the primitive PSO (PipelineState Object), which refers to the rendering state collection in the process of drawing the primitive. DX12 or Vulkan sets various rendering states of the rendering pipeline by setting PSO. The vertex data format InputLayout is mainly obtained through the geometric data of the primitive CRenderable object, and the rendering state RenderState and rendering shader Shader are mainly obtained through the material CStateset object. PSO (rendering state collection) quickly searches the structure, can accelerate the structure without locks across threads, and stores PSO through a four-dimensional array association. The maintenance of this structure (adding new states) is in the main thread, and the working thread only checks but does not increase, which can ensure the query efficiency of multiple threads.
[0106] The multi-level indexing mechanism of the primitive PSO solves the problem of real-time PSO search efficiency. At the same time, the primitive PSO Key value is mapped through the Int32 type, laying the foundation for the parallel sorting of PSO through the GPU. The GPU parallel sorts the PSO Key values of the primitives. After the sorting is completed, the Key values with the same status will be sorted adjacently, so that the block data can batch render the primitives of different PSOs. Since the different PSO primitives in the block can also be batch rendered, it lays the foundation for all the primitives in the block to use the GPU for overall occlusion and culling operations. This supports the smooth rendering of millions of primitives.
[0107] In a rendering block, the rendering state sorting is transferred from the previous CPU sorting to the GPU, which reduces the CPU bottleneck and enables the indirect rendering (IndirectDraw) technology to be used in multiple PSO blocks, providing a basis for the next step of GPU culling. Figure 4 This is the effect picture after turning on GPU frustum clipping and occlusion culling. Figure 5 This is the effect picture after GPU frustum clipping and occlusion culling are not enabled. Figure 6 and Figure 7 It is a display effect diagram of the BIM electromechanical scene using block rendering.
[0108] In addition, in practical applications, in order to solve the needs of consistent rendering state, consistent rendering data format, and packaging of rendering vertex data in actual engineering applications, the technical solution provided by the embodiment of the present invention constructs a vertex index data stream without Vertex Input Layout through BindlessBuffer to avoid packaging of vertex index data streams of primitives. And introduce it into the IndirectCmd parameter construction of batch rendering, so as to realize the overall batch rendering of data in the rendering block. Among them, Bindless (Unbounded) is unbounded or unbounded binding, which refers to the technology of directly storing the GPU virtual address of Buffer / Texture in Bindless Buffer without traditional graphics API (such as glBindXXX function), and directly accessing Texture / Buffer data by indexing Bindless in the shader (Shader).
[0109] By using Bindless technology in block rendering, the following functions are achieved: Bindless mainly solves the overhead problem of binding resources to pipelines under traditional APIs, and also breaks through the hardware access restrictions of Shaders. Bindless can also reduce the number of DrawCalls, further reduce the interaction between CPU and GPU, and thus further improve performance. Bindless is also an indispensable basic component of modern rendering technologies such as GPU Driven Pipeline.
[0110] By executing the above steps, the graphics rendering method based on complex scenes provided by the embodiment of the present invention utilizes the CPU to construct the scene rendering data into a flat data structure, which is beneficial to the subsequent multi-core and multi-threaded parallel operation of the CPU and GPU, solves the problem of low efficiency of the preparation rendering queue of the traditional graphics display engine, and groups the primitive nodes in the flat data structure and performs block rendering by the GPU in the order of rendering blocks, thereby reducing the huge interface call overhead caused by the traditional graphics driver calling the interface to draw primitives one by one, and when the previous block of data is rendered in the GPU rendering thread, the CPU performs pre-rendering preparation work for the next block of data, avoiding the problem of CPU and GPU waiting for each other in the traditional rendering engine, improving the parallelism of the CPU and GPU, and improving the rendering efficiency, and effectively solving the jamming problem during scene interactive browsing and editing operations.
[0111] Although the embodiments of the present invention have been described in conjunction with the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present invention, and such modifications and variations are all within the scope defined by the appended claims.
Claims
1. A graphics rendering method based on complex scenes, applied to CPU, It is characterized in that The method comprises: Constructing the scene to be rendered into a flattened scene data structure, wherein the data objects in the flattened scene data structure are primitive nodes in the scene to be rendered; Grouping the primitive nodes in the flattened scene data structure to obtain a plurality of rendering blocks, wherein the rendering blocks store the corresponding relationship between each primitive node and the rendering block and the indirect rendering cache data of each primitive node; Determine the rendering order of each rendering block; Statistics are performed on the primitive node state set and the corresponding global rendering data of the current rendering block in accordance with the rendering order, and the statistical results are sent to the GPU so that the GPU renders the current rendering block based on the statistical results. In the process of the GPU rendering the current rendering block, statistics are performed on the primitive node state set and the corresponding global rendering data of the next rendering block corresponding to the next rendering order in accordance with the rendering order, and the next statistical result is sent to the GPU until the rendering of all rendering blocks is completed.
2. The method according to claim 1, It is characterized in that The step of grouping the primitive nodes in the flattened scene data structure to obtain a plurality of rendering blocks includes: Grouping the primitive nodes in the flattened scene data structure according to the priority and primitive type of each primitive node to obtain a plurality of rendering blocks; wherein the priority and primitive type of the primitive nodes in the same rendering block are the same; Based on the identifier of each primitive node, a corresponding relationship between the rendering block and each primitive node is established, and the corresponding relationship is stored in the rendering block; The indirect rendering data corresponding to each primitive node is stored in its corresponding rendering block.
3. The method according to claim 2, It is characterized in that Determining the rendering order of each rendering block includes: The rendering order of each rendering block is determined according to the priority and primitive type of the primitive node corresponding to each rendering block.
4. The method according to claim 3, It is characterized in that The step of determining the rendering order of each rendering block according to the priority and primitive type of the primitive node corresponding to each rendering block includes: Determine whether the primitive type of the current rendering block is a transparent primitive; When the primitive type of the current rendering block is a transparent primitive, determining the rendering order of the current rendering block in the rendering blocks corresponding to all transparent primitives according to the priority of the primitive node corresponding to the current rendering block; When the primitive type of the current rendering block is a non-transparent primitive, the rendering order of the current rendering block in the rendering blocks corresponding to all non-transparent primitives is determined according to the priority of the primitive node corresponding to the current rendering block, wherein the rendering order of the rendering blocks corresponding to each non-transparent primitive precedes the rendering order of the rendering blocks corresponding to each transparent primitive.
5. The method according to claim 1, It is characterized in that The counting of the primitive node state set of the current rendering block and the corresponding global rendering data according to the rendering order includes: Extracting a primitive index of each primitive node from the indirect rendering cache data of each primitive node of the current rendering block; Based on the primitive index, corresponding primitive states are extracted from the rendering cache data of the scene to be rendered to form a primitive node state set, and global rendering data corresponding to each primitive index is extracted from the rendering cache data of the scene to be rendered.
6. The method according to claim 5, It is characterized in that Also includes: Get the rendering cache data of the scene to be rendered; The rendering cache data is stored in a global paging manner.
7. A graphics rendering method based on complex scenes, applied to GPU, It is characterized in that The method comprises: Receive a statistics result of a primitive node state set of a current rendering block and its corresponding global rendering data sent by the CPU, wherein the current rendering block is obtained by the CPU constructing a scene to be rendered into a flattened scene data structure and grouping primitive nodes in the flattened scene data structure; The current rendering block is rendered based on the statistical result, and after the rendering is completed, the statistical result of the primitive node status set of the current rendering block and the corresponding global rendering data sent by the receiving CPU is returned until the rendering of all rendering blocks is completed. In the process of rendering the current rendering block, the CPU performs statistics on the primitive node status set and the corresponding global rendering data of the next rendering block corresponding to the next rendering order in the rendering order, and sends the next statistical result to the GPU.
8. The method according to claim 7, It is characterized in that The rendering of the current rendering block based on the statistical result includes: Performing frustum clipping on each primitive node of the current rendering block, and removing primitive nodes blocked by the currently rendered nodes, to obtain primitive nodes to be rendered; Determining a node rendering order of each to-be-rendered primitive node based on a rendering state of the to-be-rendered primitive node in the primitive node state set; The global rendering data corresponding to each primitive node to be rendered is sequentially extracted according to the node rendering order for rendering.
9. The method according to claim 8, It is characterized in that The determining the node rendering order of each to-be-rendered primitive node based on the rendering state of the to-be-rendered primitive node in the primitive node state set includes: Grouping the to-be-rendered primitive nodes based on the rendering status of the to-be-rendered primitive nodes in the primitive node status set; The node rendering order of each to-be-rendered primitive node is determined based on the grouping result, wherein the node rendering order of the to-be-rendered primitive nodes having the same rendering state is the same.
10. A graphics rendering system based on complex scenes, It is characterized in that include: CPU and GPU; The CPU is used to construct the scene to be rendered into a flattened scene data structure, where the data objects in the flattened scene data structure are primitive nodes in the scene to be rendered; Grouping the primitive nodes in the flattened scene data structure to obtain a plurality of rendering blocks, wherein the rendering blocks store the corresponding relationship between each primitive node and the rendering block and the indirect rendering cache data of each primitive node; Determine the rendering order of each rendering block; Counting the primitive node state set of the current rendering block and its corresponding global rendering data according to the rendering order, and sending the statistical results to the GPU; The GPU is used to receive the statistics of the primitive node state set of the current rendering block and its corresponding global rendering data sent by the CPU; The current rendering block is rendered based on the statistical results, and after the rendering is completed, the statistical results of the primitive node status set and the corresponding global rendering data of the current rendering block sent by the CPU are received again until the rendering of all rendering blocks is completed. In the process of the GPU rendering the current rendering block, the CPU counts the primitive node status set and the corresponding global rendering data of the next rendering block corresponding to the next rendering order in the rendering order, and sends the next statistical result to the GPU.
Citation Information
Cited By
Pixel processing device and method, graphics processor and electronic equipment
CN122368283A
