A method and system for managing three-dimensional graphics primitives based on spatial encoding
Patent Information
- Application Number
- CN202611068987.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-17
- Publication Date
- 2026-10-09
AI Technical Summary
这种“访问顺序与存储顺序不一致”的矛盾,使得同一局部几何区域内的空间邻近图元在显存中未能连续存储,GPU缓存系统无法利用空间局部性原理预取有效数据,从而成为制约高分辨率、高帧率渲染性能的关键瓶颈
[0044]第一,显著提升GPU缓存命中率。本发明依据空间编码对图元属性缓冲区进行一致重排,使空间邻近的图元在显存中连续存储,将随机聚集访问转化为更易合并的内存事务,有效提升L1/L2缓存命中率并减少无效显存带宽占用。
Smart Images

Figure CN122887671A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of computer graphics, GPU parallel computing and data storage layout optimization, and in particular to a three-dimensional primitive memory management method and system based on spatial coding. Background Technology
[0002] With the rapid development of technologies such as virtual reality, augmented reality, and digital twins, the demands for realism and real-time performance in scene rendering are increasing. Explicit 3D representation methods based on 3D Gaussian Splatting (3DGS) have attracted widespread attention due to their excellent real-time new perspective synthesis capabilities. In these methods, scenes are typically represented by hundreds of thousands to millions of 3D primitives (such as Gaussian ellipsoids, point clouds, voxels, or particles), each containing attributes such as center position, scale, rotation, opacity, color, and spherical harmonics. During rendering, the system first projects visible primitives into screen space and sorts them according to screen tiles and depth information. Then, the GPU thread group reads the attribute data of each primitive and performs pixel-by-pixel alpha blending, ultimately synthesizing the rendered image.
[0003] However, in the rendering pipeline described above, the primitive indexes after binning and depth sorting exhibit a significant random distribution relative to their original storage locations in video memory. Specifically, the sorting operation rearranges the originally unordered primitives according to tile ID and depth, resulting in multiple primitives within the same tile that need to be processed consecutively by the same GPU thread group having their actual storage addresses scattered across different locations in video memory. When the GPU thread group reads the attribute data of these primitives in parallel, multiple threads obtain data from these scattered video memory addresses, forming a typical random gathering access pattern. This access pattern severely undermines the GPU's ability to coalesce memory transactions—threads within the same warp, which should complete the data reading of consecutive addresses through a single merged memory transaction, are forced to initiate multiple independent, unaligned memory access transactions. Since each memory access is performed in units of a complete L1 cache line (typically 128 bytes), even if a thread only needs to read a small number of bytes, the entire cache line will be loaded, while most of the data remains unused. This ineffective cache line over-reading not only wastes a lot of valuable video memory bandwidth, but also pollutes the L1 / L2 cache with scattered access addresses, resulting in a significant decrease in cache hit rate and frequent memory access wait states in the rendering pipeline.
[0004] The root cause of the above problems lies in the fact that existing 3D primitive rendering systems lack data layout optimization for primitive spatial locality at the memory management level. Specifically, the sorted index order reflects the visibility and depth relationship in screen space, rather than the geometric proximity relationship of primitives in world space; while the storage order of the attribute buffer in memory still maintains the original order during training or loading, which is seriously misaligned with the sorted access order. This contradiction of "inconsistent access order and storage order" means that spatially adjacent primitives within the same local geometric region are not stored contiguously in memory, and the GPU caching system cannot utilize the principle of spatial locality to prefetch effective data, thus becoming a key bottleneck restricting the performance of high-resolution, high-frame-rate rendering. Summary of the Invention
[0005] In view of the above-mentioned shortcomings in the fields of computer graphics, GPU parallel computing and data storage layout optimization, the present invention provides a three-dimensional primitive memory management method and system based on spatial coding. By encoding the spatial position of three-dimensional primitives and rearranging the attribute buffer according to the encoding value, spatially adjacent primitives are stored continuously in video memory, thereby improving the GPU cache hit rate, reducing invalid video memory bandwidth occupation, and significantly improving rendering efficiency.
[0006] To achieve the above objectives, the embodiments of the present invention adopt the following technical solutions:
[0007] A 3D primitive memory management method based on spatial coding includes:
[0008] Obtain a set of 3D primitives in the scene to be rendered and an attribute array corresponding to each 3D primitive, wherein the attribute array includes at least the center position data of each 3D primitive;
[0009] Calculate the spatial bounding box of the scene based on the center position data of each of the three-dimensional primitives;
[0010] Based on the spatial bounding box, the center position data of each of the three-dimensional primitives are normalized and quantized into three-dimensional grid coordinates;
[0011] Spatial encoding is performed on the coordinates of each of the three-dimensional grids to generate one-dimensional spatial encoding values that correspond one-to-one with each of the three-dimensional primitives;
[0012] A sorting key is constructed based on the one-dimensional spatial encoding value, and all the three-dimensional primitives are sorted to obtain an arrangement for mapping the original index to the new index;
[0013] According to the arrangement, the attribute arrays corresponding to each of the three-dimensional primitives are uniformly rearranged to form an attribute buffer with spatial encoding order.
[0014] According to one aspect of the present invention, the step of normalizing and quantizing the center position data of each of the three-dimensional primitives into three-dimensional mesh coordinates based on the spatial bounding box specifically includes:
[0015] Based on the spatial bounding box, the center position data of each of the three-dimensional primitives are normalized to a predetermined numerical range;
[0016] Each normalized coordinate component is quantized into integer grid coordinates of a predetermined precision.
[0017] According to one aspect of the invention, the integer grid coordinates with predetermined precision are any one of 10-bit integer precision, 16-bit integer precision, or 21-bit integer precision.
[0018] According to one aspect of the present invention, the spatial encoding is Morton encoding, and the step of spatially encoding the coordinates of each of the three-dimensional meshes specifically includes:
[0019] The binary bit strings of the quantized three-dimensional mesh coordinates are extracted in the x-axis, y-axis and z-axis directions respectively;
[0020] The binary bits in the x-axis, y-axis and z-axis directions are sequentially interleaved in order from least significant bit to most significant bit to generate a one-dimensional Morton code value.
[0021] According to one aspect of the invention, the spatial encoding is any one of Hilbert curve encoding, Peano curve encoding, Z-order curve variant encoding, BVH leaf node order encoding, kd leaf order encoding, or octree preorder traversal encoding.
[0022] According to one aspect of the present invention, the attribute array is stored in the video memory in the form of a structure array, an array structure, or a combination of both; the attribute array further includes any one or more of the following: scale parameters, rotation parameters, covariance matrix, opacity value, color value, spherical harmonic coefficient, semantic identifier, or hierarchical identifier for each of the three-dimensional primitives.
[0023] According to one aspect of the present invention, after uniformly rearranging the attribute arrays corresponding to each of the three-dimensional primitives according to the arrangement to form an attribute buffer with spatial encoding order, the method further includes:
[0024] Based on the sorting results, establish a reverse mapping from the old index to the new index;
[0025] Obtain the reference relationships in the scenario that depend on the original index. The reference relationships include any one or more of the following: hierarchical structure index, tuple group index, training residual index, visibility list index, external reference index, or debug index.
[0026] Based on the reverse mapping, all original indices in the reference relationship are updated to the corresponding new indices.
[0027] According to one aspect of the invention, it further includes:
[0028] In the runtime rendering pipeline, primitive attributes are read based on the rearranged attribute buffer;
[0029] The reading operation includes at least one or more of the following: projection operation of projecting 3D primitives onto screen space, binning operation of screen space tiles, sorting operation of depth value, sub-tile culling operation, or rasterization alpha blending operation.
[0030] According to one aspect of the invention, a block incremental update step is also included:
[0031] The scene is divided into multiple independent spatial blocks, and a corresponding block table is configured for each spatial block;
[0032] When a change in the attribute or spatial position of a 3D primitive within a local spatial block is detected, the local spatial bounding box, local spatial code, and local sorting of the local spatial block that has changed are recalculated only for the local spatial block that has changed.
[0033] The arrangement of primitives within the local spatial block is updated based on the recalculated local sort, and the mapping relationship between the global index and the local index is maintained through the block table.
[0034] A spatial coding-based 3D primitive memory management system includes:
[0035] The acquisition module acquires a set of 3D primitives in the scene to be rendered and an attribute array corresponding to each 3D primitive, wherein the attribute array includes at least the center position data of each 3D primitive.
[0036] The bounding box calculation module calculates the spatial bounding box of the scene based on the center position data of each of the three-dimensional primitives.
[0037] The quantization module normalizes and quantizes the center position data of each of the three-dimensional primitives into three-dimensional grid coordinates based on the spatial bounding box.
[0038] The spatial encoding module performs spatial encoding on the coordinates of each of the three-dimensional grids to generate a one-dimensional spatial encoding value that corresponds one-to-one with each of the three-dimensional primitives.
[0039] The sorting module constructs a sorting key based on the one-dimensional spatial encoding value and sorts all the three-dimensional primitives to obtain an arrangement for mapping the original index to the new index.
[0040] The rearrangement module rearranges the attribute arrays corresponding to each of the three-dimensional primitives in a consistent manner according to the arrangement, forming an attribute buffer with spatial encoding order;
[0041] The mapping update module is used to establish a reverse mapping from the old index to the new index based on the sorting result, and update all reference relationships in the scenario that depend on the original index to the corresponding new index according to the reverse mapping.
[0042] The block update module is used to divide the scene into multiple independent spatial blocks. When a change in the 3D primitives within a local spatial block is detected, the local spatial bounding box, local spatial encoding, and local sorting are recalculated only for the local spatial block that has changed. The mapping relationship between the global index and the local index is maintained through the block table.
[0043] Advantages of implementing this invention:
[0044] First, it significantly improves GPU cache hit rate. This invention performs consistent rearrangement of primitive attribute buffers based on spatial encoding, enabling spatially adjacent primitives to be stored contiguously in video memory. This transforms random clustered access into more easily merged memory transactions, effectively improving L1 / L2 cache hit rate and reducing invalid video memory bandwidth usage.
[0045] Second, zero visual quality loss. This invention only changes the storage order of primitive attribute data, without changing the geometric parameters, projection model, sorting rules, or color synthesis formula of the primitives. It is a pure data layout optimization, which improves performance while maintaining the same rendering quality as before optimization.
[0046] Third, it is compatible with multiple encoding schemes and primitive types. This invention supports multiple spatial encoding methods such as Morton encoding, Hilbert curve encoding, Peano curve encoding, Z-order variants, BVH leaf node order, kd leaf order, or octree preorder traversal, and is not dependent on a specific primitive type. It can be applied to any set of 3D primitives with spatial position attributes, such as 3D Gaussian splashes, point clouds, voxels, and particles.
[0047] Fourth, it supports static offline optimization and dynamic incremental updates. For static scenarios, it can perform a one-time full reordering and persist the results for reuse; for dynamic scenarios, it provides a block-based incremental update mechanism, which only performs reordering on local spatial blocks that have changed, and maintains a global index mapping through a block table to avoid full sorting for each frame, thus balancing the benefits of cache locality and dynamic responsiveness.
[0048] Fifth, it can work in conjunction with various rendering optimization techniques. This invention is orthogonal and non-conflicting with higher-level rendering optimization techniques such as adaptive binning, sub-tile culling, view frustum pruning, level of detail switching, primitive pruning, and model compression. It can be seamlessly integrated into existing rendering pipelines to generate synergistic performance benefits. Attached Figure Description
[0049] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0050] Figure 1 This is a flowchart illustrating a three-dimensional primitive memory management method based on spatial coding as described in this invention.
[0051] Figure 2 This is a schematic diagram of the attribute buffer rearrangement described in this invention;
[0052] Figure 3 This is a schematic diagram illustrating the cache locality effect described in this invention;
[0053] Figure 4 This is a comparison diagram of the cache locality effect without spatial coding described in this invention;
[0054] Figure 5 This is a comparison diagram of the cache locality effect using Morton space coding as described in this invention;
[0055] Figure 6 This is a schematic diagram of the optional block update described in this invention;
[0056] Figure 7 This is a flowchart illustrating a three-dimensional primitive memory management system based on spatial coding. Detailed Implementation
[0057] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0058] Example 1
[0059] like Figure 1 As shown, a 3D primitive memory management method based on spatial coding includes the following steps:
[0060] This embodiment uses a static 3D Gaussian Splatting scene as an example to illustrate in detail the specific implementation of the spatial coding-based 3D primitive memory management method provided by the present invention.
[0061] Step S1: Obtain a set of 3D primitives in the scene to be rendered and an attribute array corresponding to each 3D primitive. The attribute array shall include at least the center position data of each 3D primitive.
[0062] In this embodiment, the scene to be rendered is a static indoor scene, for which a 3D Gaussian splash model has been trained. The 3D primitive set of this scene, containing approximately 500,000 3D Gaussian primitives, is loaded from the storage medium. Each 3D primitive corresponds to an array of attributes, including: center position coordinates (x, y, z), scale parameters (3D scaling vector), rotation parameters (quaternions or rotation matrix), opacity value (alpha), and spherical harmonic coefficients (used to represent view-dependent colors). These attribute arrays are stored in CPU memory using a Structure of Array (SoA) structure, meaning each attribute is stored as an independent array, with similar attributes arranged contiguously in memory to facilitate subsequent SIMD batch processing.
[0063] Step S2: Calculate the spatial bounding box of the scene based on the center position data of each of the three-dimensional primitives;
[0064] Iterate through the center coordinates of all 3D Gaussian primitives and calculate the global axis-aligned bounding box (AABB) of the scene. Specifically, find the minimum and maximum values of all center points along the x, y, and z axes to obtain the minimum corner coordinates p_min = (x_min, y_min, z_min) and the maximum corner coordinates p_max = (x_max, y_max, z_max).
[0065] Step S3: Based on the spatial bounding box, normalize and quantize the center position data of each of the three-dimensional primitives into three-dimensional grid coordinates;
[0066] Based on the scene AABB calculated in step S2, the center position p=(x, y, z) of each 3D primitive is mapped from world space to normalized coordinate space. Specifically, for the center position p of the primitive, each coordinate component is normalized and quantized according to the following formula to obtain the quantized coordinate q:
[0067]
[0068] Here, ε is a very small positive value (e.g., 10^(-6)) used to prevent division by zero errors when the length of the AABB in a certain dimension is zero; b is the number of quantization bits, which is taken as b=21 in this embodiment, so that each coordinate component can be quantized into integer grid coordinates qx, qy, qz between 0 and 2,097,151. The quantization precision of 21 bits is sufficient to accommodate the encoded value within the range of 64-bit integers while maintaining sub-millimeter spatial resolution.
[0069] Step S4: Spatial encoding is performed on the coordinates of each of the three-dimensional meshes to generate one-dimensional spatial encoding values that correspond one-to-one with each of the three-dimensional primitives;
[0070] This embodiment uses Morton coding as the spatial encoding method. For each primitive's quantized 3D grid coordinates (qx, qy, qz), the binary bit strings of qx, qy, and qz are extracted respectively, and interleaved in order from least significant bit to most significant bit to form a one-dimensional Morton code value. Specifically, the 0th bit of qx, the 0th bit of qy, and the 0th bit of qz are arranged sequentially as the least significant bit group of the code, followed by the 1st bit of qx, the 1st bit of qy, and the 1st bit of qz, and so on, until all bits are interleaved. Since b=21 in this embodiment, the Morton code formed after interleaving is 63 bits, which can be accommodated in a 64-bit unsigned integer. A key characteristic of this encoding is that adjacent primitives in 3D space have coded proximity on the Morton curve, that is, the closer the 3D spatial distance between two primitives, the smaller the difference in their Morton code values in the more significant bits.
[0071] Step S5: Construct a sorting key based on the one-dimensional spatial encoding value, and sort all the three-dimensional primitives to obtain an arrangement for mapping the original index to the new index;
[0072] Using the Morton code value generated in step S4 as the primary key and the original index of each primitive as the secondary key, a key-value pair sequence is constructed. Subsequently, a stable sort is performed on all key-value pairs on the CPU. Stable sorting ensures that when two primitives have the same Morton code (usually occurring within the same grid point of the quantized grid), their relative order remains unchanged, which is crucial for the deterministic updating of subsequent reference relationships.
[0073] After sorting, we obtain the permutation `perm` and the mapping from new indices to old indices. Specifically, `perm` is an array of length N (where N is the total number of primitives), and `perm[k]` represents the original primitive index corresponding to the k-th position after sorting. Simultaneously, a reverse mapping `inv_perm` is established, satisfying `inv_perm[perm[k]] = k`, meaning `inv_perm` records the new index position of each original index after rearrangement, used for subsequent updates to external reference relationships.
[0074] Step S6: According to the arrangement, the attribute arrays corresponding to each of the three-dimensional primitives are uniformly rearranged to form an attribute buffer with spatial encoding order.
[0075] Following the perm arrangement obtained in step S5, a consistent rearrangement is performed on all primitive attribute arrays. For the SoA storage layout used in this embodiment, the specific operation is as follows: traverse the perm arrangement, and copy the corresponding elements from each attribute array (center position, scale, rotation, opacity, spherical harmonic coefficient) to the new array according to the new index order. For example, after rearranging the center position array, the value of the k-th element in the new array is equal to the value of the perm[k]-th element in the original array. All attribute arrays use the same perm arrangement to ensure that the index positions of all attributes of the same primitive in the new buffer are consistent. Figure 2 As shown, each attribute array is rearranged using the same permutation, so that spatially similar primitives are continuous or approximately continuous in memory.
[0076] After the rearrangement is complete, the new attribute buffer is uploaded from CPU memory to GPU memory to replace the original attribute buffer. Since the rearranged data is arranged in Morton code order in GPU memory, spatially adjacent primitives are contiguous or nearly contiguous in GPU memory addresses, laying the foundation for efficient GPU access in the future.
[0077] Steps S1 to S6 are executed by the CPU and completed in one go during the scene loading phase. Steps S7 to S9 are also completed on the CPU, with steps S7 and S9 completed during the loading phase, and step S8 continuously executed in each subsequent frame rendering loop. Each step is explained in detail below.
[0078] Step S7: Update the relevant reference relationships based on the reverse mapping;
[0079] Since this embodiment is a static scene, there are no dynamic primitives or incremental training residual indexes in the scene. However, there are still two types of external reference relationships in the scene data structure that depend on the original indexes: one is the scene's Level of Detail (LOD) structure index, which records the grouping information of the primitive's level in different LOD levels; the other is the debug index, used to locate specific primitives during rendering debugging. Based on the reverse mapping inv_perm established in step S5, the system traverses each index value in the above reference relationships and replaces it with the corresponding new index value in inv_perm. This update operation is performed after the attribute buffer reordering is completed in step six and before the rendering loop starts, ensuring the index consistency of the entire scene data structure. After the update, all indexes in the scene point to the reordered new positions, and the subsequent rendering module directly uses the new indexes to access attributes without additional address translation or lookup operations.
[0080] Step S8: In the runtime rendering pipeline, perform primitive attribute reading operations based on the rearranged attribute buffer;
[0081] After the attribute buffer is rearranged and uploaded to the GPU memory, the system enters the real-time rendering loop. In each frame of rendering, the GPU thread group accesses the primitive attribute data sequentially according to each stage of the rendering pipeline:
[0082] During the preprocessing stage, each thread reads the center position coordinates and covariance parameters from the rearranged attribute buffer, projects the 3D Gaussian primitives onto the screen space, calculates their coverage on the screen, and obtains the screen space bounding box of each primitive.
[0083] During the binning and sorting phase, the system generates key-value pairs based on the overlap between each primitive and screen tiles, and sorts them by tile ID and depth value. Primitive indices within the same tile are aggregated and sorted by depth. The primitive access order generated by this process is determined by the tile and depth, and is independent of the physical storage order of the attribute buffer in video memory—this is precisely the value of this invention: although the access order is still arranged by tile / depth, the storage order has been adjusted to be organized by spatial proximity. Since primitives clustered within the same tile are usually located in close geometric regions in world space, these primitives are highly likely to be located in contiguous storage areas in the rearranged attribute buffer. The probability of GPU thread group memory access addresses falling into the same or adjacent cache lines is much higher than before rearrangement. Figure 3 As shown, after spatial encoding rearrangement, GPU threads are more likely to hit the same or adjacent cache lines when accessing primitive attributes in the same local region. Figure 4 and Figure 5 The comparison of cache locality effects with and without Morton space encoding is shown. Morton space encoding maintains color continuity in local areas, reflecting better memory access continuity.
[0084] In the sub-tile removal stage, the system further refines the visibility judgment, retaining only primitives that contribute to the final pixel, thereby reducing invalid calculations in the rasterization stage.
[0085] During the rasterization stage, GPU threads read the color, opacity, and other attributes of each primitive in parallel, perform pixel-by-pixel alpha blending, and synthesize the final rendered image.
[0086] Throughout all stages of the rendering pipeline, the GPU thread group accesses the attribute buffer based on the rearranged new index, without requiring any structural modifications to the rendering pipeline itself—this invention only changes the data storage layout, without altering the computational logic, sorting rules, or color synthesis formulas of the rendering process.
[0087] Step S9: Output the rearranged map data asset or output the rendering result based on the rearranged data asset.
[0088] After the rearrangement is complete, the rearranged attribute buffer and its corresponding index mapping relationship are saved to disk, forming an optimized graph data asset file. When loading the scene subsequently, this data asset can be read directly from the disk and uploaded to the GPU, without having to repeat the rearrangement calculations in steps S1 to S6, significantly shortening the scene loading time.
[0089] During real-time rendering, the reconstructed image frame generated in step S8 is output to the display device. In addition, after the full reordering is completed, a reordering log file is output, recording the index mapping relationship before and after the reordering, for developers to verify the correctness of the reordering or as a baseline reference for subsequent incremental updates.
[0090] It should be noted that steps S7 to S9 above are preferred embodiments of this invention. Step S7 (updating reference relationships) is activated when external index references exist in the scene; if no such references exist, it can be omitted. Step S8 (runtime reading) is the specific implementation of applying the rearranged attribute buffer to the rendering process; its effect of improving cache hit rate has been verified in the experimental section. Step S9 (outputting assets or results) is the data persistence and rendering result output step. Steps S7 to S9 are not necessary steps for implementing the core memory management method of this invention. The above preferred steps correspond to the dependent claims of this invention. Those skilled in the art should understand that even if the above preferred steps are omitted, the technical solution defined by this invention can still fully achieve the inventive objective of "continuous storage of spatially adjacent primitives in video memory and improvement of cache hit rate."
[0091] Example 2
[0092] Example 1 addresses the global spatial coding reordering of all primitives in a static scene, suitable for scenes with hundreds of thousands to millions of primitives. However, in large-scale urban scenes, the total number of 3D primitives can reach millions or even tens of millions. If the global sorting method of Example 1 is directly adopted, the computational load and memory overhead of a single sorting will increase significantly. Furthermore, in urban scenes, cameras typically only cover local areas, and the caching benefits of global reordering cannot be effectively utilized in areas far from the camera, resulting in a waste of computational resources. In this example, a block-based spatial coding reordering method is provided. By dividing the scene into multiple spatial blocks and performing reordering independently within each block, computational complexity is reduced and view frustum-dependent streaming loading is supported. Specifically, the following steps are included:
[0093] Step A1: Divide the scene into multiple city tiles or spatial blocks according to geographic space. Each spatial block covers a local geographic area, such as a street block or a group of buildings. Group the 3D primitives contained in each spatial block into the same primitive group to form a coarse-grained spatial grouping.
[0094] Step A2: Perform local spatial encoding rearrangement for each spatial block. For a given spatial block, calculate the local axis-aligned bounding box of the block based on the center positions of all primitives within the block, normalize and quantize the center positions of each primitive within the block into local 3D mesh coordinates, and generate local Morton codes.
[0095] Step A3: Using the local Morton encoding as the sorting key, perform a stable sorting of the primitives within the block to obtain the local permutation perm_block of the spatial block. Then, according to this permutation, perform a consistent rearrangement of the attribute arrays of the primitives within the block so that the spatially adjacent primitives within the block are stored contiguously in the video memory.
[0096] Step A4: Establish a block table, recording the number of each spatial block, its memory base address offset, the number of primitives within the block, and the reverse mapping from the old index to the new index. During rendering, first select the spatial blocks to be loaded based on the view frustum culling result or LOD level, and then access the primitive attributes within the selected spatial blocks according to the spatial encoding order. For spatial blocks culled by the view frustum, their data is not loaded to reduce external memory I / O and GPU memory usage.
[0097] It should be noted that the difference between this embodiment and Embodiment 1 is that Embodiment 1 uses a single global AABB and global sorting, which is suitable for scenes with compact scenes where the camera can cover most of the primitives; while this embodiment uses a multi-level block strategy, where each spatial block independently calculates its local AABB, sorts it independently, and establishes a block table for management. This is suitable for urban scenes with a wide scene range where the camera only covers a part of the scene. While retaining the benefits of cache locality, it supports view frustum-related streaming loading and external memory scheduling.
[0098] Example 3
[0099] Both Embodiment 1 and Embodiment 2 are designed for static scenes, assuming that the center position and attributes of all primitives remain unchanged after loading. Therefore, spatial encoding reordering can be completed offline or at loading time. However, in practical applications, scenes often contain a small number of dynamic primitives, such as moving characters, vehicles, or interactive objects, whose center positions and attributes change over time. Re-performing spatial encoding reordering for all scene primitives every frame would be computationally expensive; if no reordering is performed, the cache locality of the dynamic primitive portion cannot be guaranteed. In this embodiment, a static-dynamic separation memory management method is provided, processing static and dynamic primitives separately to balance the benefits of cache locality and dynamic responsiveness. Figure 6 As shown, for dynamic or block-based scenarios, static and dynamic buffers can be managed separately, and local rearrangement can be performed on the changing space blocks. Specifically, this includes the following steps:
[0100] Step B1: Divide the 3D primitives in the scene into a static primitive set and a dynamic primitive set. The static primitive set refers to primitives in the scene whose position and attributes do not change over time, such as background elements such as buildings, ground, and fixed facilities; the dynamic primitive set refers to primitives whose position or attributes may change, such as moving objects or interactive objects.
[0101] Step B2: Perform offline spatial encoding rearrangement on the static primitive set. Calculate the global AABB based on the center positions of all static primitives, generate Morton codes, and perform a stable sort. Then, rearrange the attribute arrays of the static primitives into a static attribute buffer according to the sorted arrangement and upload it to the GPU memory. This rearrangement operation is performed only once during scene loading and remains unchanged during subsequent rendering.
[0102] Step B3: For the dynamic primitive set, perform incremental sorting or local reordering at intervals of one frame or several frames. For each frame, obtain the current center position of the dynamic primitive, calculate its spatial encoding, sort it, form a dynamic attribute buffer, and upload it to the GPU memory. The number of dynamic primitives is usually much smaller than that of static primitives, so the computational cost of reordering per frame is controllable. For scenarios with low requirements for spatial locality among dynamic primitives, only the dynamically primitives that have changed are reordered locally, rather than being fully sorted.
[0103] Step B4: During the rendering stage, the static attribute buffer and the dynamic attribute buffer are binned separately, and the binning results of the two are merged and sent to the rasterization pipeline.
[0104] It should be noted that the difference between this embodiment and Embodiment 1 is as follows: Embodiment 1 treats all primitives in the entire scene as static and performs a one-time global reordering, which cannot handle primitives whose positions change during runtime; while this embodiment divides primitives into two sets: static and dynamic. The static set still uses spatial encoding reordering as in Embodiment 1 to obtain cache locality benefits, while the dynamic set performs independent incremental sorting frame by frame. Since the static part usually occupies the vast majority of primitives in the scene, the cache locality benefits mainly come from the static buffer; the dynamic part accounts for a smaller proportion, and its sorting overhead is controllable, while the system gains real-time response capability to dynamic content. The above-mentioned static-dynamic separation strategy fully utilizes the cache locality benefits of the static part while maintaining the real-time update capability of the dynamic scene.
[0105] Example 4
[0106] Examples one through three all employ Morton coding as the spatial coding method. Morton coding generates one-dimensional coded values by bit interleaving the binary bits of three-dimensional grid coordinates. Its advantages lie in its simple computation and fast coding speed. However, Morton coding has certain limitations in preserving spatial locality—when two primitives are adjacent in three-dimensional space, their Morton coded values are usually adjacent, but the reverse is not necessarily true. That is, Morton coding exhibits a certain "jump" phenomenon, which may cause a small number of primitives that were originally spatially adjacent to fail to maintain complete continuity after sorting. In this example, a spatial coding rearrangement method based on Hilbert curve coding is provided to further optimize the preservation effect of spatial locality. Specifically, it includes the following steps:
[0107] Step C1: Obtain the set of 3D primitives in the scene to be rendered and the attribute array corresponding to each 3D primitive. The attribute array shall include at least the center position data of each 3D primitive.
[0108] Step C2: Traverse the center position of all primitives and calculate the spatial bounding box of the scene.
[0109] Step C3: Based on the spatial bounding box, normalize and quantize the center position data of each primitive into three-dimensional grid coordinates.
[0110] Step C4: Perform Hilbert curve encoding on each 3D grid coordinate to generate a one-dimensional Hilbert code value corresponding to each 3D primitive. Specifically, the quantized 3D grid coordinates (qx, qy, qz) are mapped onto a Hilbert curve. The Hilbert curve has continuity and good spatial preservation properties, which can map neighboring points in high-dimensional space to neighboring points on a one-dimensional curve, and there is no "jump" problem of Morton encoding.
[0111] Step C5: Construct sorted key-value pairs using the Hilbert encoded value as the primary key and the original primitive index as the secondary key, perform stable sorting, and obtain the permutation perm from the new index to the old index, and the reverse mapping inv_perm from the old index to the new index.
[0112] Step C6: According to the perm arrangement, the attribute arrays corresponding to each primitive are uniformly rearranged to form an attribute buffer with spatial encoding order.
[0113] It should be noted that the difference between this embodiment and Embodiment 1 lies in the spatial encoding method: Embodiment 1 uses Morton encoding, which generates encoded values by bit interleaving the binary bits of the 3D coordinates; while this embodiment uses Hilbert curve encoding, which generates encoded values by mapping the 3D mesh coordinates to Hilbert curves. Hilbert curve encoding has a slightly higher computational complexity than Morton encoding, and is suitable for rendering scenarios with higher requirements for cache locality, especially for applications where primitives are densely distributed and spatial proximity has a significant impact on rendering performance.
[0114] Example 5
[0115] like Figure 7 As shown, a 3D primitive memory management system based on spatial coding includes:
[0116] The acquisition module M1 acquires a set of 3D primitives in the scene to be rendered and an attribute array corresponding to each 3D primitive. The attribute array includes at least the center position data of each 3D primitive.
[0117] The bounding box calculation module M2 calculates the spatial bounding box of the scene based on the center position data of each of the three-dimensional primitives.
[0118] The quantization module M3 normalizes and quantizes the center position data of each of the three-dimensional primitives into three-dimensional grid coordinates according to the spatial bounding box.
[0119] The spatial encoding module M4 performs spatial encoding on the coordinates of each of the three-dimensional grids to generate a one-dimensional spatial encoding value that corresponds one-to-one with each of the three-dimensional primitives.
[0120] The sorting module M5 constructs a sorting key based on the one-dimensional spatial encoding value and sorts all the three-dimensional primitives to obtain an arrangement for mapping the original index to the new index.
[0121] The rearrangement module M6 rearranges the attribute arrays corresponding to each of the three-dimensional primitives in a consistent manner according to the arrangement, forming an attribute buffer with spatial encoding order;
[0122] The mapping update module M7 is used to establish a reverse mapping from the old index to the new index based on the sorting result, and update all reference relationships in the scene that depend on the original index to the corresponding new index according to the reverse mapping.
[0123] The block update module M8 is used to divide the scene into multiple independent spatial blocks. When a change in the 3D primitives within a local spatial block is detected, the local spatial bounding box, local spatial encoding, and local sorting are recalculated only for the local spatial block that has changed. The mapping relationship between the global index and the local index is maintained through the block table.
[0124] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A three-dimensional primitive memory management method based on spatial coding, characterized in that, include: Obtain a set of 3D primitives in the scene to be rendered and an attribute array corresponding to each 3D primitive, wherein the attribute array includes at least the center position data of each 3D primitive; Calculate the spatial bounding box of the scene based on the center position data of each of the three-dimensional primitives; Based on the spatial bounding box, the center position data of each of the three-dimensional primitives are normalized and quantized into three-dimensional grid coordinates; Spatial encoding is performed on the coordinates of each of the three-dimensional grids to generate one-dimensional spatial encoding values that correspond one-to-one with each of the three-dimensional primitives; A sorting key is constructed based on the one-dimensional spatial encoding value, and all the three-dimensional primitives are sorted to obtain an arrangement for mapping the original index to the new index; According to the arrangement, the attribute arrays corresponding to each of the three-dimensional primitives are uniformly rearranged to form an attribute buffer with spatial encoding order.
2. The three-dimensional primitive memory management method based on spatial coding according to claim 1, characterized in that, The step of normalizing and quantizing the center position data of each of the three-dimensional primitives into three-dimensional mesh coordinates based on the spatial bounding box specifically includes: Based on the spatial bounding box, the center position data of each of the three-dimensional primitives are normalized to a predetermined numerical range; Each normalized coordinate component is quantized into integer grid coordinates of a predetermined precision.
3. The three-dimensional primitive memory management method based on spatial coding according to claim 2, characterized in that, The integer grid coordinates with the predetermined precision are any one of 10-bit integer precision, 16-bit integer precision, or 21-bit integer precision.
4. The three-dimensional primitive memory management method based on spatial coding according to claim 1, characterized in that, The spatial encoding is Morton encoding, and the step of spatially encoding the coordinates of each of the three-dimensional meshes specifically includes: The binary bit strings of the quantized three-dimensional mesh coordinates are extracted in the x-axis, y-axis and z-axis directions respectively; The binary bits in the x-axis, y-axis and z-axis directions are sequentially interleaved in order from least significant bit to most significant bit to generate a one-dimensional Morton code value.
5. The three-dimensional primitive memory management method based on spatial coding according to claim 1, characterized in that, The spatial encoding is any one of Hilbert curve encoding, Peano curve encoding, Z-order curve variant encoding, BVH leaf node order encoding, kd leaf order encoding, or octree preorder traversal encoding.
6. The three-dimensional primitive memory management method based on spatial coding according to claim 1, characterized in that, The attribute array is stored in the video memory in the form of a structure array, an array structure, or a combination of both; the attribute array also includes any one or more of the following: scale parameters, rotation parameters, covariance matrix, opacity value, color value, spherical harmonic coefficient, semantic identifier, or hierarchical identifier for each of the three-dimensional primitives.
7. The three-dimensional primitive memory management method based on spatial coding according to claim 1, characterized in that, After uniformly rearranging the attribute arrays corresponding to each of the three-dimensional primitives according to the aforementioned arrangement to form an attribute buffer with spatial encoding order, the method further includes: Based on the sorting results, establish a reverse mapping from the old index to the new index; Obtain the reference relationships in the scenario that depend on the original index. The reference relationships include any one or more of the following: hierarchical structure index, tuple group index, training residual index, visibility list index, external reference index, or debug index. Based on the reverse mapping, all original indices in the reference relationship are updated to the corresponding new indices.
8. The three-dimensional primitive memory management method based on spatial coding according to claim 1, characterized in that, Also includes: In the runtime rendering pipeline, primitive attributes are read based on the rearranged attribute buffer; The reading operation includes at least one or more of the following: projection operation of projecting 3D primitives onto screen space, binning operation of screen space tiles, sorting operation of depth value, sub-tile culling operation, or rasterization alpha blending operation.
9. The three-dimensional primitive memory management method based on spatial coding according to claim 1, characterized in that, It also includes the block incremental update step: The scene is divided into multiple independent spatial blocks, and a corresponding block table is configured for each spatial block; When a change in the attribute or spatial position of a 3D primitive within a local spatial block is detected, the local spatial bounding box, local spatial code, and local sorting of the local spatial block that has changed are recalculated only for the local spatial block that has changed. The arrangement of primitives within the local spatial block is updated based on the recalculated local sort, and the mapping relationship between the global index and the local index is maintained through the block table.
10. A three-dimensional primitive memory management system based on spatial coding, characterized in that, The spatial coding-based 3D primitive memory management method according to any one of claims 1 to 9 includes: The acquisition module acquires a set of 3D primitives in the scene to be rendered and an attribute array corresponding to each 3D primitive, wherein the attribute array includes at least the center position data of each 3D primitive. The bounding box calculation module calculates the spatial bounding box of the scene based on the center position data of each of the three-dimensional primitives. The quantization module normalizes and quantizes the center position data of each of the three-dimensional primitives into three-dimensional grid coordinates based on the spatial bounding box. The spatial encoding module performs spatial encoding on the coordinates of each of the three-dimensional grids to generate a one-dimensional spatial encoding value that corresponds one-to-one with each of the three-dimensional primitives. The sorting module constructs a sorting key based on the one-dimensional spatial encoding value and sorts all the three-dimensional primitives to obtain an arrangement for mapping the original index to the new index. The rearrangement module rearranges the attribute arrays corresponding to each of the three-dimensional primitives in a consistent manner according to the arrangement, forming an attribute buffer with spatial encoding order; The mapping update module is used to establish a reverse mapping from the old index to the new index based on the sorting result, and update all reference relationships in the scenario that depend on the original index to the corresponding new index according to the reverse mapping. The block update module is used to divide the scene into multiple independent spatial blocks. When a change in the 3D primitives within a local spatial block is detected, the local spatial bounding box, local spatial encoding, and local sorting are recalculated only for the local spatial block that has changed. The mapping relationship between the global index and the local index is maintained through the block table.