Terrain data preparation and rendering method and apparatus
Patent Information
- Application Number
- CN202611314203.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-27
- Publication Date
- 2026-10-20
AI Technical Summary
[0004]然而,在视点快速移动或新区域首次进入视野时,大量瓦片数据尚未加载,需要等待地形数据加载完成后才能执行渲染任务,从而出现了因地形数据未就绪而使得渲染任务阻塞等待的问题,这会导致帧率下降和画面卡顿
[0028]综上,在本公开提供的地形数据的准备与渲染方法中,后台线程与前台线程协作执行。后台线程在向第一存储区域写入第一地形数据的过程中,前台线程会从已就绪的第二存储区域获取第二地形数据执行渲染任务,即在同一时间内后台线程与前台线程操作不同的存储区域,互不干扰。而且,在后台线程完成第一地形数据的写入后,前台线程会基于第一存储区域中的第一地形数据执行渲染任务,且后台线程会向第二存储区域写入第三地形数据,两个存储区域的写入和读取交替进行,从而确保前台线程在任意时刻均有已就绪的存储区域可供读取地形数据。因此,本公开提供的地形数据的准备与渲染方法,能够保证前台线程在任意情况下均有已就绪的地形数据可供渲染,无需等待后台线程完成地形数据的加载,从而实现前台线程的渲染任务永不阻塞,保证帧率稳定。
Smart Images

Figure FT_1 
Figure FT_2 
Figure FT_3
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of 3D model rendering technology, specifically to a method and apparatus for preparing and rendering terrain data. Background Technology
[0002] In the field of computer graphics, real-time rendering of large-scale terrain is one of the core technologies for systems such as 3D geographic information systems, flight simulation systems, and digital earth applications.
[0003] In relevant terrain rendering systems, data preparation and rendering execution are usually performed sequentially in the same thread. Due to the massive amount of terrain data, the system cannot load all the terrain data at once, and typically adopts an on-demand loading strategy, loading only the terrain data within the current field of view.
[0004] However, when the viewpoint moves quickly or a new area enters the field of view for the first time, a large amount of tile data has not yet been loaded. The rendering task can only be executed after the terrain data is loaded. This results in the rendering task being blocked due to the terrain data not being ready, which leads to a drop in frame rate and screen stuttering.
[0005] Therefore, how to avoid rendering tasks being blocked and waiting due to unavailable terrain data during the processing of terrain data has become an urgent technical problem to be solved. Summary of the Invention
[0006] This disclosure provides a method and apparatus for preparing and rendering terrain data, which can avoid the problem of rendering tasks being blocked and waiting due to unprepared terrain data.
[0007] In a first aspect, embodiments of this disclosure provide a method for preparing and rendering terrain data. This method is executed collaboratively by a background thread and a foreground thread. The method includes: during the process of the background thread writing first terrain data to a first storage area, the foreground thread performs a rendering task based on second terrain data in a second storage area, where the second terrain data in the second storage area is terrain data pre-written by the background thread; after the background thread writes the first terrain data to the first storage area, the foreground thread performs a rendering task based on the first terrain data in the first storage area, and the background thread writes third terrain data to the second storage area; during the process of the foreground thread selecting new terrain data, if no new terrain data is detected within a maximum data waiting time, the foreground thread performs a rendering task based on the second terrain data in the second storage area, where the maximum data waiting time is less than the target frame interval.
[0008] Optionally, the background thread writes the first terrain data to the first storage area, including: the background thread obtaining a data preparation request from the task queue, the data preparation request including the storage address of the original data; the background thread obtaining the original data from the memory based on the storage address; the background thread decoding the original data to obtain the first terrain data; the background thread obtaining rendering indication information, the rendering indication information used to indicate that the foreground thread is using the second storage area; the background thread determining the first storage area not used by the foreground thread based on the rendering indication information; and the background thread storing the decoded first terrain data into the first storage area, the first storage area corresponding to the first buffer information, the first buffer information including the storage address of the first storage area.
[0009] Optionally, after the background thread stores the decoded first terrain data in the first storage area, the method further includes: the background thread updating the first buffer information to obtain updated first buffer information, the updated first buffer information including the storage address of the first storage area, status information and a ready timestamp, the status information being used to indicate the ready state; the background thread updating the rendering instruction information to obtain updated rendering instruction information, the updated rendering instruction information being used to indicate that the foreground thread is using the first storage area; and the background thread sending a data ready notification to the foreground thread through a ready notification channel, the data ready notification being used to indicate that the first storage area stores first terrain data that can be read.
[0010] Optionally, the foreground thread performs a rendering task based on the second terrain data in the second storage area, including: the foreground thread obtaining second buffer information, the second buffer information including the storage address, status information and ready timestamp of the second storage area; the foreground thread determining the second storage area based on the storage address in the second buffer information, the second storage area storing the second terrain data; the foreground thread obtaining the second terrain data in the second storage area; and the foreground thread performing a rendering task based on the second terrain data.
[0011] Optionally, the foreground thread obtaining the second buffer information includes: the foreground thread obtaining rendering indication information, which indicates the buffer information that the foreground thread should currently use; and the foreground thread determining the second buffer information based on the rendering indication information.
[0012] Optionally, the foreground thread obtains the second buffer information, including: the foreground thread determining at least two buffer information pieces in the multi-buffer information area whose status information is ready; the foreground thread comparing the ready timestamps of the at least two buffer information pieces to determine the second buffer information with the latest ready timestamp.
[0013] Optionally, before the background thread writes the first terrain data to the first storage area, the method further includes: if there is no buffer information in the multi-buffer information area with the state information in the ready state, the foreground thread uses the default terrain data to perform the rendering task.
[0014] Optionally, the foreground thread performs a rendering task based on the second terrain data in the second storage area, including: the foreground thread generates a first image frame based on the second terrain data in the second storage area at a target frame rate, wherein the target frame rate is a fixed frame rate set in the frame rate controller.
[0015] Optionally, the foreground thread generates a first image frame based on the second terrain data in the second storage area at a target frame rate, including: when the foreground thread starts generating the first image frame based on the second terrain data in the second storage area at the target frame rate, the foreground thread records the start time of generating the first image frame; after the foreground thread generates the first image frame at the target frame rate, the foreground thread records the end time of generating the first image frame; the foreground thread determines the actual time taken to generate the first image frame based on the end time and the start time; the foreground thread determines the target frame interval time based on the target frame rate, wherein the target frame rate and the target frame interval time are reciprocals of each other; if the actual time taken is less than the target frame interval time, the foreground thread waits for the difference between the target frame interval time and the actual time taken before starting to generate the next image frame; if the actual time taken is greater than or equal to the target frame interval time, the foreground thread immediately starts generating the next image frame.
[0016] Optionally, the background thread and the foreground thread can reside in the same process, or the background thread and the foreground thread can reside in different processes.
[0017] Secondly, embodiments of this disclosure provide a terrain data preparation and rendering apparatus, comprising: a writing module for writing first terrain data to a first storage area; and, after writing the first terrain data to the first storage area, writing third terrain data to a second storage area; a rendering module for performing a rendering task based on second terrain data in the second storage area during the process of the writing module writing the first terrain data to the first storage area, wherein the second terrain data in the second storage area is terrain data pre-written by the writing module; and, after the writing module writes the first terrain data to the first storage area, performing a rendering task based on the first terrain data in the first storage area; and, during the process of selecting new terrain data, if no new terrain data is detected to be ready within a maximum data waiting time, performing a rendering task based on the second terrain data in the second storage area, wherein the maximum data waiting time is less than the target frame interval time.
[0018] Optionally, the writing module is specifically used to obtain data preparation requests from the task queue, the data preparation requests including the storage address of the original data; obtain the original data from the memory based on the storage address; decode the original data to obtain the first terrain data; obtain rendering instruction information; determine the unused first storage area based on the rendering instruction information; and store the decoded first terrain data into the first storage area, the first storage area corresponding to the first buffer information, the first buffer information including the storage address of the first storage area.
[0019] Optionally, the writing module is specifically used to update the first buffer information to obtain the updated first buffer information, which includes the storage address of the first storage area, status information, and a ready timestamp. The status information is used to indicate the ready status. The module also updates the rendering instruction information to obtain the updated rendering instruction information. Finally, the module sends a data ready notification through the ready notification channel, which indicates that the first storage area stores first terrain data that can be read.
[0020] Optionally, a rendering module is used to obtain second buffer information, which includes the storage address, status information, and ready timestamp of the second storage area; determine the second storage area based on the storage address in the second buffer information, where the second storage area stores the second terrain data; obtain the second terrain data in the second storage area; and perform a rendering task based on the second terrain data.
[0021] Optionally, a rendering module is used to obtain rendering instruction information and determine the second buffer information based on the rendering instruction information.
[0022] Optionally, the rendering module is specifically used to determine at least two buffer information pieces in the multi-buffered information area whose status information is in a ready state; compare the ready timestamps of the at least two buffer information pieces, and determine the second buffer information piece with the latest ready timestamp.
[0023] Optionally, a rendering module is used to perform rendering tasks using default terrain data when there is no buffer information in the multi-buffered information area that is in a ready state.
[0024] Optionally, the rendering module is specifically used to record the start time of generating the first image frame when generating the first image frame based on the second terrain data in the second storage area at a target frame rate.
[0025] Optionally, the rendering module is specifically used to: record the end time of generating the first image frame after generating the first image frame at the target frame rate; determine the actual time taken to generate the first image frame based on the end time and the start time; determine the target frame interval time based on the target frame rate, wherein the target frame rate and the target frame interval time are reciprocals of each other; if the actual time taken is less than the target frame interval time, wait for the difference between the target frame interval time and the actual time taken before starting to generate the next image frame; if the actual time taken is greater than or equal to the target frame interval time, start generating the next image frame immediately.
[0026] Thirdly, embodiments of this disclosure provide a computer-readable storage medium storing a computer program that, when executed, implements the method described in the first aspect.
[0027] Fourthly, embodiments of this disclosure provide an electronic device, including a memory and a processor; the memory is used to store a computer program; the processor is used to execute the computer program stored in the memory, and when the computer program is executed, it implements the method of the first aspect described above.
[0028] In summary, in the terrain data preparation and rendering method provided in this disclosure, the background thread and the foreground thread collaborate. While the background thread is writing the first terrain data to the first storage area, the foreground thread retrieves the second terrain data from the ready second storage area to perform the rendering task. That is, the background thread and the foreground thread operate on different storage areas simultaneously without interfering with each other. Furthermore, after the background thread completes writing the first terrain data, the foreground thread performs the rendering task based on the first terrain data in the first storage area, and the background thread writes the third terrain data to the second storage area. The writing and reading of the two storage areas alternate, ensuring that the foreground thread always has ready storage areas available for reading terrain data. Therefore, the terrain data preparation and rendering method provided in this disclosure guarantees that the foreground thread always has ready terrain data available for rendering under any circumstances, without waiting for the background thread to complete loading the terrain data. This ensures that the foreground thread's rendering task is never blocked, guaranteeing a stable frame rate.
[0029] In addition, if no new data is detected within the preset maximum data waiting time, the foreground thread continues to perform rendering tasks based on the terrain data in the existing storage area, so that the foreground thread will not be blocked while waiting for new data, thus preventing the frame rate drop caused by data loading delay. Attached Figure Description
[0030] The accompanying drawings, which are included to provide a further understanding of this disclosure and form part of this disclosure, illustrate exemplary embodiments of the present disclosure and are used to explain the disclosure, but do not constitute an undue limitation of the disclosure. In the drawings: Figure 1 This is a schematic diagram of a scenario provided in this disclosure; Figure 2 This is another scenario illustration provided in this disclosure; Figure 3 This is yet another scenario illustration provided in this disclosure; Figure 4 This is yet another scenario illustration provided in this disclosure; Figure 5 A flowchart illustrating a method for preparing and rendering terrain data according to an embodiment of this disclosure; Figure 6 A structural block diagram of a terrain data preparation and rendering apparatus provided in an embodiment of this disclosure; Figure 7 This is a structural block diagram of an electronic device provided in an embodiment of the present disclosure. Detailed Implementation
[0031] The present disclosure will be further described in detail below with reference to the accompanying drawings and embodiments. Through these descriptions, the features and advantages of the present disclosure will become clearer and more apparent.
[0032] The term “exemplary” as used herein means “serving as an example, embodiment, or illustration.” Any embodiment illustrated herein as “exemplary” is not necessarily to be construed as superior to or better than other embodiments. Although various aspects of embodiments are shown in the accompanying drawings, the drawings are not necessarily drawn to scale unless specifically indicated otherwise.
[0033] Furthermore, the technical features involved in the different embodiments of this disclosure described below can be combined with each other as long as they do not conflict with each other.
[0034] In relevant terrain rendering systems, data preparation and rendering execution are usually performed sequentially in the same thread.
[0035] Due to the massive amount of terrain data, multi-resolution tiling techniques based on Level of Detail (LOD) are typically used to organize and manage terrain data.
[0036] In the traditional data preparation and rendering process, firstly, the set of tiles to be displayed is calculated based on the viewpoint position. Then, it is checked whether the data for each tile has been loaded into memory. If the data is not ready, a loading request is initiated, and the process waits for loading to complete. Finally, rendering is performed using the ready data.
[0037] However, when the viewpoint moves quickly or a new area enters the field of view for the first time, a large amount of tile data has not yet been loaded. The rendering task can only be executed after the terrain data is loaded. This results in the rendering task being blocked due to the terrain data not being ready, which leads to a drop in frame rate and screen stuttering.
[0038] To address the aforementioned technical problems, this disclosure provides a method for preparing and rendering terrain data. This method is executed collaboratively by a background thread and a foreground thread. The method includes: during the process of the background thread writing first terrain data to a first storage area, the foreground thread performs a rendering task based on second terrain data in a second storage area, where the second terrain data in the second storage area is terrain data pre-written by the background thread; after the background thread writes the first terrain data to the first storage area, the foreground thread performs a rendering task based on the first terrain data in the first storage area, and the background thread writes third terrain data to the second storage area.
[0039] In the terrain data preparation and rendering method provided in this disclosure, background threads and foreground threads collaborate. While the background thread writes first terrain data to the first storage area, the foreground thread retrieves second terrain data from the ready second storage area to perform the rendering task. That is, the background thread and foreground thread operate on different storage areas simultaneously without interfering with each other. Furthermore, after the background thread completes writing the first terrain data, the foreground thread performs the rendering task based on the first terrain data in the first storage area, and the background thread writes third terrain data to the second storage area. The writing and reading of the two storage areas alternate, ensuring that the foreground thread always has ready storage areas available for terrain data to read. Therefore, the terrain data preparation and rendering method provided in this disclosure guarantees that the foreground thread always has ready terrain data available for rendering under any circumstances, without waiting for the background thread to complete loading the terrain data. This ensures that the foreground thread's rendering task is never blocked, guaranteeing a stable frame rate.
[0040] To facilitate understanding, the preparation and rendering methods of the terrain data provided in this disclosure will be described in detail below with reference to the accompanying drawings.
[0041] Please see Figure 1 and Figure 2 As shown, Figure 1 This is a schematic diagram of a scenario provided in this disclosure. Figure 2 This is another scenario illustration provided in this disclosure.
[0042] exist Figure 1 and Figure 2The example shown illustrates a background thread 100, a foreground thread 200, and a multi-buffered information area 300. The multi-buffered information area 300 includes storage area A and storage area B, which are buffered frames within the multi-buffered information area 300.
[0043] It should be noted that in this disclosure, "storage area" and "buffer frame" are the same concept. Each storage area contains corresponding buffer information, which is used to store the status information, ready timestamp, and pointer to the terrain data in the graphics processor's video memory of the buffer frame.
[0044] Furthermore, this disclosure uses two storage areas as an example for illustration, but this does not constitute a limitation of this disclosure. In practical applications, the multi-buffered information area 300 may also include N storage areas (buffer frames), where N is an integer greater than or equal to 3. When the multi-buffered information area 300 includes three or more buffer frames, the background thread can gradually update different terrain data in multiple storage areas, while the foreground thread always selects the terrain data in the latest ready storage area to perform the rendering task, thereby providing a smoother data transition in scenarios with high data update frequency and significant differences in foreground and background processing speeds. Those skilled in the art should understand that the above-described extended applications of N storage areas should all fall within the protection scope of this disclosure.
[0045] Furthermore, background thread 100 can also be called background data preparation thread 100, and foreground thread 200 can also be called foreground rendering thread 200.
[0046] The foreground thread 200 and background thread 100 mentioned in this disclosure are both threads of the Central Processing Unit (CPU), which are scheduled and executed by the operating system.
[0047] Graphics Processing Unit Memory (VRAM) is a dedicated high-speed memory located on the graphics processing unit (GPU) used to store resources such as texture data, vertex data, and frame buffers required by the GPU during the rendering process.
[0048] Unlike system memory (RAM) accessed by the central processing unit (CPU), video memory has higher bandwidth and lower access latency, which can meet the data throughput requirements of massive parallel computing in GPUs.
[0049] In this embodiment of the disclosure, the background thread 100 uploads the prepared terrain data to the video memory of the graphics processor and stores a pointer to the terrain data in storage area A or storage area B, so that the foreground thread 200 can read the corresponding terrain data from the video memory of the graphics processor through the pointer during rendering.
[0050] By pre-storing terrain data in the graphics processor's video memory, the foreground thread 200 does not need to wait for the terrain data to be transferred from system memory to video memory when submitting rendering commands, further ensuring the continuity and real-time performance of the rendering task.
[0051] The following is combined Figure 1 and Figure 2 The example shown illustrates the methods for preparing and rendering terrain data provided in this disclosure: Please combine Figure 1 As shown, background thread 100 pre-writes terrain data Y into the graphics processor's video memory, so that storage area B stores a pointer to the ready terrain data Y.
[0052] Then, background thread 100 begins writing terrain data X into the graphics processor's video memory, so that storage area A stores a pointer to terrain data X. During this process, foreground thread 200 reads a pointer to terrain data Y from storage area B, retrieves terrain data Y from the graphics processor's video memory based on this pointer, and performs a rendering task based on terrain data Y.
[0053] In other words, within the same time period, background thread 100 and foreground thread 200 operate on different storage areas within the multi-buffered information area 300 without interfering with each other.
[0054] Please combine Figure 2 As shown, after background thread 100 writes terrain data X into the graphics processor's video memory and stores the pointer to terrain data X in storage area A, storage area A stores the pointer to the ready terrain data X.
[0055] At this point, the foreground thread 200 switches to storage area A, reads a pointer to terrain data X from storage area A, retrieves terrain data X from the graphics processor's video memory based on the pointer, and performs a rendering task based on terrain data X.
[0056] Meanwhile, background thread 100 begins writing terrain data Z into the graphics processor's video memory and stores a pointer to terrain data Z in storage area B. In other words, background thread 100 prepares the terrain data required for the next frame's rendering in storage area B.
[0057] pass Figure 1 and Figure 2As shown in the example, background thread 100 and foreground thread 200 alternately use storage area A and storage area B, forming a ping-pong switching mechanism. At any given time, when background thread 100 writes a pointer to terrain data to one storage area, foreground thread 200 reads a pointer to ready terrain data from another storage area and retrieves the terrain data from the graphics processor's video memory based on that pointer to execute the rendering task. The two threads always operate on different storage areas, thus ensuring that foreground thread 200 can continue to execute the rendering task without waiting for background thread 100 to finish loading data.
[0058] Therefore, the terrain data preparation and rendering method provided in this disclosure can ensure that the foreground thread 200 has ready terrain data for rendering under any circumstances, without waiting for the background thread 100 to complete the loading of terrain data, thereby ensuring that the rendering task of the foreground thread 200 is never blocked and ensuring a stable frame rate.
[0059] Please see Figure 3 As shown, Figure 3 This is another scenario illustration provided in this disclosure.
[0060] The following is combined Figure 3 The example shown details the execution process of the background thread 100 provided in this disclosure, which writes terrain data X into the graphics processor's video memory, stores a pointer to the terrain data X in storage area A, and updates buffer information, rendering instruction information, and sends a data ready notification after the write is completed. Step 1: Background thread 100 retrieves data from task queue 400 to prepare request q1.
[0061] The data preparation request q1 contains the storage address of the original data S1, which indicates the storage location of the original data S1 in the memory 500.
[0062] For example, the storage device 500 can be a local disk or a remote server, and this disclosure does not limit it in this way.
[0063] It should be noted that task queue 400 is a First-In-First-Out (FIFO) queue used to store pending data preparation requests. Background thread 100 continuously monitors task queue 400. When there is a pending data preparation request in task queue 400, background thread 100 retrieves a data preparation request from the head of task queue 400 for processing. When task queue 400 is empty, background thread 100 enters a low-power waiting state until a new data preparation request arrives in task queue 400.
[0064] Step 2: Background thread 100 retrieves the original data S1 from memory 500 based on the storage address in the data preparation request q1.
[0065] Step 3: Background thread 100 decodes the raw data S1 to obtain terrain data X usable by the graphics processor.
[0066] For example, the decoding process may include operations such as image decompression and elevation data format conversion on the original data S1, so that the decoded terrain data X can be directly read and processed by the graphics processing unit (GPU).
[0067] Step 4: Background thread 100 obtains rendering instruction information R1.
[0068] Among them, the rendering instruction information R1 is used to indicate the storage area currently being used by the foreground thread 200.
[0069] like Figure 3 As shown, the foreground thread 200 is currently reading a pointer to terrain data Y from storage area B, and using this pointer to retrieve terrain data Y from the graphics processor's video memory to perform a rendering task. The rendering instruction information R1 indicates that the foreground thread 200 is using storage area B.
[0070] Step 5: Based on the rendering instruction information R1, background thread 100 determines that the currently unused storage area of foreground thread 200 is storage area A, and identifies storage area A as the write target.
[0071] Since the rendering instruction information R1 indicates that the foreground thread 200 is using storage area B, the background thread 100 determines that storage area A is a storage area that the foreground thread 200 is not currently using, and determines storage area A as the write target.
[0072] Step 6: Background thread 100 writes the decoded terrain data X into the graphics processor's video memory and stores the pointer to the terrain data X in storage area A.
[0073] like Figure 3 As shown, background thread 100 writes terrain data X into the graphics processor's video memory and stores a pointer to the terrain data X in storage area A. At this time, storage area A stores a pointer to the prepared terrain data X.
[0074] In addition, storage area A corresponds to buffer information H1, which is used to manage the status of terrain data in storage area A.
[0075] For example, buffer information H1 may include the storage address of storage area A, status information, and ready timestamp.
[0076] The status information is used to indicate the current status of storage area A, such as being in a write state or in a ready state.
[0077] The ready timestamp is used to indicate when the terrain data in storage area A becomes ready.
[0078] Accordingly, storage area B corresponds to buffer information H2, which is used to manage the status of terrain data in storage area B.
[0079] For example, buffer information H2 may include the storage address, status information, and ready timestamp of storage area B.
[0080] Step 7: Background thread 100 updates the buffer information H1 to obtain the updated buffer information H1.
[0081] After background thread 100 stores the pointer to terrain data X into storage area A, background thread 100 updates the buffer information H1.
[0082] The updated buffer information H1 includes the storage address of storage area A, status information, and ready timestamp. The status information is used to indicate that storage area A is currently in a ready state.
[0083] Step 8: Background thread 100 updates the rendering instruction information R1 to obtain the updated rendering instruction information R1.
[0084] Background thread 100 updates the rendering indication information R1 from indicating that foreground thread 200 is using storage area B to indicating that foreground thread 200 is using storage area A.
[0085] In other words, background thread 100 switches the data source of foreground thread 200 from storage area B to storage area A by updating rendering instruction information R1.
[0086] Step 9: Background thread 100 sends a data ready notification T1 to foreground thread 200 through ready notification channel 600.
[0087] The data ready notification T1 indicates that storage area A contains a pointer to readable terrain data X. Upon receiving the data ready notification T1, the foreground thread 200 determines that storage area A should be used based on the updated rendering instruction information R1, retrieves the pointer to the terrain data X from storage area A, and uses this pointer to retrieve the terrain data X from the graphics processor's video memory to perform the rendering task.
[0088] At this point, background thread 100 has completed the entire process of writing terrain data X into the graphics processor's video memory, storing the pointer to terrain data X in storage area A, updating buffer information H1, updating rendering instruction information R1, and sending data ready notification T1 after the writing is complete.
[0089] The following is combined Figure 3 The example shown provides a detailed description of the process by which the foreground thread 200 performs rendering tasks based on terrain data Y, as provided in this disclosure: Step 1: Foreground thread 200 retrieves buffer information H2.
[0090] like Figure 3 As shown, foreground thread 200 needs to obtain the currently available terrain data to perform the rendering task, and first obtains the buffer information H2.
[0091] Among them, buffer information H2 corresponds to storage area B. Buffer information H2 includes the storage address, status information, and ready timestamp of storage area B. The status information is used to indicate the current status of storage area B, such as being in a writing state or a ready state; the ready timestamp is used to indicate the moment when the terrain data in storage area B becomes ready.
[0092] The specific methods by which foreground thread 200 obtains buffered information H2 may include, but are not limited to, the following two: Method 1: Obtain buffer information H2 through rendering instruction information R1.
[0093] like Figure 3 As shown, foreground thread 200 obtains rendering instruction information R1. Rendering instruction information R1 is used to indicate the buffer information that foreground thread 200 should currently use.
[0094] For example, rendering instruction information R1 can indicate that the buffer information that the foreground thread 200 should currently use is buffer information H2.
[0095] Foreground thread 200 determines buffer information H2 based on rendering instruction information R1.
[0096] In other words, the foreground thread 200 can directly know which buffer information should be used by reading the rendering instruction information R1, without having to traverse all buffer information to search.
[0097] Method 2: Obtain buffer information H2 by traversing and comparing.
[0098] like Figure 3 As shown, the foreground thread 200 determines at least two buffers in the multi-buffer information area 300 whose status information is in the ready state.
[0099] In this embodiment of the disclosure, the multi-buffered information area 300 includes at least buffered information H1 and buffered information H2.
[0100] Foreground thread 200 checks the status information of buffer information H1 and buffer information H2 respectively, and determines that the buffer information in the ready state is the one in the ready state.
[0101] Assuming that both buffer information H1 and buffer information H2 are in a ready state, the foreground thread 200 compares the ready timestamp of buffer information H1 with the ready timestamp of buffer information H2, and selects the buffer information with the latest ready timestamp as the buffer information to be used at the moment.
[0102] If the ready timestamp of buffer information H2 is newer than the ready timestamp of buffer information H1, then the foreground thread 200 determines that buffer information H2 is the buffer information that should be used at the moment.
[0103] Step 2: Foreground thread 200 determines storage area B based on the storage address in buffer information H2.
[0104] Among them, the buffer information H2 obtained by the foreground thread 200 includes the storage address of storage area B, and the foreground thread 200 determines storage area B based on the storage address.
[0105] Step 3: Foreground thread 200 obtains a pointer to terrain data Y from storage area B, and retrieves terrain data Y from the graphics processor's video memory based on this pointer.
[0106] Step 4: Foreground thread 200 performs rendering tasks based on terrain data Y.
[0107] Among them, after the foreground thread 200 obtains the terrain data Y, it performs the rendering task based on the terrain data Y.
[0108] Please see Figure 4 As shown, Figure 4 This is another scenario illustration provided in this disclosure.
[0109] The following is combined Figure 4 The example shown provides a detailed description of the downgrade rendering process provided in this disclosure: Step 1: Foreground thread 200 will check the status information of each buffer in the multi-buffer information area 300.
[0110] Step 2: If there is no buffer information in the multi-buffer information area 300 with a ready state, the foreground thread 200 uses the default terrain data to perform the rendering task.
[0111] like Figure 4As shown, the multi-buffered information area 300 includes buffered information H1 and buffered information H2. The foreground thread 200 detects the status information of buffered information H1 and buffered information H2 respectively.
[0112] Among them, the state information of buffer information H1 is in a non-ready state, and the state information of buffer information H2 is also in a non-ready state. That is to say, there is no buffer information in the multi-buffer information area 300 with a ready state.
[0113] This scenario typically occurs during system cold starts or under abnormal conditions.
[0114] For example, when the system is first started, the background thread 100 has not yet completed the preparation of any terrain data, and neither storage area A nor storage area B stores pointers to ready terrain data. Accordingly, the status information of buffer information H1 and buffer information H2 both indicate a non-ready state.
[0115] If foreground thread 200 detects that there is no buffer information in the multi-buffer information area 300 with a ready state, it cannot obtain ready terrain data from the graphics processor's video memory. In this case, foreground thread 200 performs the rendering task using default terrain data.
[0116] For example, the default terrain data can be a preset lowest-level base texture or solid color fill data to ensure uninterrupted image output.
[0117] In other words, even if no buffered information is ready in the multi-buffered information area 300, the foreground thread 200 can still perform rendering tasks without being blocked or waiting due to lack of data.
[0118] pass Figure 4 As shown in the example, the terrain data preparation and rendering method provided in this disclosure ensures that, in the absence of buffer information with a ready state in the multi-buffer information area 300, the foreground thread 200 uses the default terrain data to perform the rendering task, thereby ensuring that the foreground thread 200 always has data available for rendering and ensuring that the rendering task is never blocked.
[0119] The following is combined Figure 1 The example shown provides a detailed description of the timeout skipping process provided in this disclosure: like Figure 1 As shown, background thread 100 is writing terrain data X into the graphics processor's video memory and storing a pointer to terrain data X in storage area A.
[0120] During this process, the foreground thread 200 reads a pointer to the terrain data Y from storage area B, retrieves the terrain data Y from the graphics processor's video memory based on the pointer, and performs a rendering task based on the terrain data Y.
[0121] While background thread 100 is writing terrain data X to storage area A, foreground thread 200 continuously checks whether new terrain data is ready.
[0122] Specifically, the foreground thread 200 starts timing when the detection starts and continuously checks whether a pointer to terrain data X has been stored in storage area A.
[0123] For example, it can detect things like Figure 3 Has the buffer information H1 shown been updated to the ready state?
[0124] If, within the preset maximum data waiting time, the foreground thread 200 detects that the terrain data X in storage area A is ready, then the foreground thread 200 switches to storage area A, obtains a pointer to the terrain data X from storage area A, and obtains the terrain data X from the graphics processor's video memory according to the pointer and executes the rendering task.
[0125] If the foreground thread 200 does not detect that the terrain data X in storage area A is ready within the preset maximum data waiting time, the foreground thread 200 will no longer wait, but will continue to execute the rendering task based on the terrain data Y in storage area B.
[0126] For example, the maximum data wait time is much less than the target frame interval time for the foreground thread 200.
[0127] For example, the target frame interval is 16.67 milliseconds (corresponding to 60 frames / second), and the maximum data waiting time can be set to 2 milliseconds.
[0128] In other words, when rendering each frame, the foreground thread 200 waits for new data to be ready for a maximum of 2 milliseconds. If the timeout occurs, it will give up waiting and directly use the existing data for rendering.
[0129] pass Figure 1 As shown in the example, during the process of background thread 100 writing terrain data X to storage area A, if the foreground thread 200 does not detect that terrain data X is ready within the maximum data waiting time, the foreground thread 200 will not wait indefinitely, but will continue to execute the rendering task based on the terrain data Y in storage area B, thereby ensuring that the foreground thread 200 will not be blocked due to waiting for new data to be ready.
[0130] The following is combined Figure 1 The example shown provides a detailed description of the frame rate control process provided in this disclosure: like Figure 1 As shown, background thread 100 pre-writes terrain data Y into storage area B in the graphics processor's video memory, so that storage area B stores the ready terrain data Y, and foreground thread 200 performs rendering tasks based on terrain data Y.
[0131] It should be noted that foreground thread 200 performs rendering tasks at the target frame rate. The target frame rate is a fixed frame rate set in the frame rate controller.
[0132] For example, the target frame rate could be 60 frames per second, which corresponds to approximately 16.67 milliseconds per frame.
[0133] Specifically, foreground thread 200 determines the target frame interval time based on the target frame rate, and the target frame rate and the target frame interval time are reciprocals of each other.
[0134] For example, when the target frame rate is 60 frames per second, the target frame interval is 16.67 milliseconds; when the target frame rate is 30 frames per second, the target frame interval is 33.33 milliseconds.
[0135] When foreground thread 200 starts generating the first image frame, foreground thread 200 records the start time of generating the first image frame.
[0136] After the foreground thread 200 generates the first image frame, the foreground thread 200 records the end time of generating the first image frame.
[0137] Foreground thread 200 calculates the actual time taken to generate the first image frame based on the start and end times.
[0138] For example, if the start time is t_start and the end time is t_end, then the actual time elapsed is dt = t_end - t_start.
[0139] Foreground thread 200 compares the actual time taken with the target frame interval.
[0140] If the actual time taken is less than the target frame interval, the foreground thread 200 waits for the difference between the target frame interval and the actual time taken before starting to generate the next image frame.
[0141] In other words, if this frame is completed ahead of schedule, the foreground thread 200 waits for the remaining time so that the next frame can start at the scheduled time.
[0142] If the actual time taken is greater than or equal to the target frame interval, the foreground thread 200 immediately begins generating the next image frame.
[0143] In other words, if the current frame times out, the foreground thread 200 will no longer wait and will immediately start the next frame to avoid latency accumulation.
[0144] In this way, foreground thread 200 executes rendering tasks through target frame rate control, ensuring a stable frame rate for the rendered output.
[0145] The following is combined Figure 3 The example shown illustrates the lock-free switching mechanism of atomic pointers provided in this disclosure: After background thread 100 writes terrain data X to storage area A and completes the update of buffer information H1, background thread 100 updates rendering instruction information R1.
[0146] It should be noted that the rendering instruction information R1 is an atomic variable, stored in the shared memory area of the CPU memory.
[0147] Background thread 100 updates the rendering indication information R1 from indicating that foreground thread 200 is using storage area B to indicating that foreground thread 200 is using storage area A through an atomic operation.
[0148] This atomic operation is a single atomic instruction and does not require locking.
[0149] In other words, after the background thread 100 completes the data writing, it only needs to perform one atomic pointer switching operation to switch the data source of the foreground thread 200 from storage area B to storage area A.
[0150] Because this operation is atomic, when foreground thread 200 reads rendering indicator information R1 at any time, the value it reads is either the value before the switch (indicating storage area B) or the value after the switch (indicating storage area A), and it will not read intermediate states or partially updated values. This avoids the thread blocking and lock contention overhead caused by locking in traditional solutions, and realizes lock-free switching between foreground and background threads.
[0151] At the start of each frame rendering, foreground thread 200 atomically reads the rendering instruction information R1 to obtain the buffer information to be used. For example, such as Figure 3 As shown, after the background thread 100 completes the switch, the foreground thread 200 atomically reads the rendering instruction information R1, determines that the buffer information to be used is the buffer information H1, then obtains a pointer to the terrain data X from the storage area A, and executes the rendering task by obtaining the terrain data X from the graphics processor's video memory according to the pointer.
[0152] The following is combined Figure 1 The example shown further illustrates the specific process by which the foreground thread 200 performs rendering tasks based on terrain data Y, as provided in this disclosure: exist Figure 1In the example shown, the foreground thread 200 reads a pointer to terrain data Y from storage area B, retrieves terrain data Y from the graphics processor's video memory based on the pointer, and then performs a rendering task based on the terrain data Y.
[0153] Specifically, the foreground thread 200 binds the terrain data Y to the graphics processor's rendering pipeline, including binding vertex buffers and texture resources. The foreground thread 200 sets shader parameters and calls drawing commands to submit the terrain data Y to the graphics processor for rendering.
[0154] Through the above steps, the foreground thread 200 completes the rendering task of one frame based on terrain data Y.
[0155] See Figure 5 , Figure 5 This is a flowchart illustrating a method for preparing and rendering terrain data according to an embodiment of this disclosure. Figure 5 As shown, the method may include the following steps.
[0156] Step S101: During the process of writing the first terrain data to the first storage area by the background thread, the foreground thread performs the rendering task based on the second terrain data in the second storage area.
[0157] The second terrain data in the second storage area is terrain data pre-written by a background thread.
[0158] Step S102: After the background thread writes the first terrain data to the first storage area, the foreground thread executes the rendering task based on the first terrain data in the first storage area, and the background thread writes the third terrain data to the second storage area.
[0159] Step S103: During the process of selecting new terrain data in the foreground thread, if no new terrain data is detected to be ready within the maximum data waiting time, the foreground thread executes the rendering task based on the second terrain data in the second storage area.
[0160] Among them, the maximum data waiting time is less than the target frame interval time. It should be noted that, in this disclosure, "writing terrain data to the storage area" means that the background thread writes the terrain data to the graphics processor's video memory and stores a pointer to that terrain data in the storage area. "Reading terrain data from the storage area" means that the foreground thread obtains a pointer to the terrain data from the storage area and retrieves the terrain data from the graphics processor's video memory based on that pointer. Further details will not be elaborated upon below.
[0161] like Figure 5As shown, in the terrain data preparation and rendering method provided in this disclosure, the background thread and the foreground thread cooperate in execution. While the background thread is writing the first terrain data to the first storage area, the foreground thread retrieves the second terrain data from the ready second storage area to perform the rendering task. That is, the background thread and the foreground thread operate on different storage areas simultaneously without interfering with each other. Furthermore, after the background thread completes writing the first terrain data, the foreground thread performs the rendering task based on the first terrain data in the first storage area, and the background thread writes the third terrain data to the second storage area. The writing and reading of the two storage areas alternate, ensuring that the foreground thread always has ready storage areas available for reading terrain data. Therefore, the terrain data preparation and rendering method provided in this disclosure guarantees that the foreground thread always has ready terrain data available for rendering under any circumstances, without waiting for the background thread to complete loading the terrain data, thus ensuring that the foreground thread's rendering task is never blocked and guaranteeing a stable frame rate.
[0162] In addition, if no new data is detected within the preset maximum data waiting time, the foreground thread continues to perform rendering tasks based on the terrain data in the existing storage area, so that the foreground thread will not be blocked while waiting for new data, thus preventing the frame rate drop caused by data loading delay.
[0163] In some embodiments, Figure 5 In the method shown, the background thread writes first terrain data to the first storage area, including: the background thread obtaining a data preparation request from the task queue, the data preparation request including the storage address of the original data; the background thread obtaining the original data from the memory based on the storage address; the background thread decoding the original data to obtain the first terrain data; the background thread obtaining rendering indication information, the rendering indication information used to indicate that the foreground thread is using the second storage area; the background thread determining the first storage area not used by the foreground thread based on the rendering indication information; and the background thread storing the decoded first terrain data into the first storage area, the first storage area corresponding to first buffer information, the first buffer information including the storage address of the first storage area.
[0164] The background thread retrieves data preparation requests from the task queue, obtains raw data from the memory according to the storage address, and decodes the raw data to obtain terrain data. This allows the background thread to obtain and process raw terrain data asynchronously, avoiding blocking of the foreground thread due to data preparation and improving the efficiency and flexibility of data preparation.
[0165] In some embodiments, Figure 5In the method shown, after the background thread stores the decoded first terrain data in the first storage area, the method further includes: the background thread updating the first buffer information to obtain updated first buffer information, the updated first buffer information including the storage address of the first storage area, status information and a ready timestamp, the status information being used to indicate the ready state; the background thread updating the rendering instruction information to obtain updated rendering instruction information, the updated rendering instruction information being used to indicate that the foreground thread is using the first storage area; and the background thread sending a data ready notification to the foreground thread through a ready notification channel, the data ready notification being used to indicate that the first storage area stores first terrain data that can be read.
[0166] In this process, after the background thread stores the terrain data in the storage area, it updates the buffer information, updates the rendering indication information, and sends a data ready notification through the ready notification channel. This allows the foreground thread to be aware of the new data ready status in a timely manner, achieving seamless switching of the storage area and ensuring efficient communication and data synchronization between the foreground and background threads.
[0167] In some embodiments, Figure 5 In the method shown, the foreground thread performs a rendering task based on the second terrain data in the second storage area, including: the foreground thread obtaining second buffer information, which includes the storage address, status information, and ready timestamp of the second storage area; the foreground thread determining the second storage area based on the storage address in the second buffer information, where the second terrain data is stored; the foreground thread obtaining the second terrain data in the second storage area; and the foreground thread performing a rendering task based on the second terrain data.
[0168] The foreground thread obtains buffer information, determines the storage area based on the storage address in the buffer information, and retrieves the terrain data in the storage area to perform rendering tasks. This enables the foreground thread to quickly locate the ready terrain data and perform rendering, improving the data acquisition efficiency and rendering continuity of the foreground thread.
[0169] In some embodiments, Figure 5 In the method shown, the foreground thread obtaining the second buffer information includes: the foreground thread obtaining rendering indication information, which is used to indicate the buffer information that the foreground thread should currently use; and the foreground thread determining the second buffer information based on the rendering indication information.
[0170] In this process, the foreground thread obtains rendering instruction information and determines buffer information based on the rendering instruction information. This allows the foreground thread to directly know the buffer information that should be used at the moment, without having to traverse all buffer information to search, which further improves data acquisition efficiency.
[0171] In some embodiments, Figure 5In the method shown, the foreground thread obtains the second buffer information, including: the foreground thread determining at least two buffer information in the multi-buffer information area whose status information is ready; the foreground thread comparing the ready timestamps of the at least two buffer information to determine the second buffer information with the latest ready timestamp.
[0172] Specifically, the foreground thread detects buffer information in the multi-buffer information area that is in the ready state, and compares the ready timestamps of each buffer information to determine the latest buffer information. This ensures that when there are multiple ready buffer information in the multi-buffer information area, the foreground thread can accurately select the latest terrain data to execute the rendering task, thus guaranteeing that the foreground thread always uses the latest available data and improving rendering quality.
[0173] In some embodiments, Figure 5 In the method shown, before the background thread writes the first terrain data to the first storage area, the method further includes: if there is no buffer information in the multi-buffer information area with the state information in the ready state, the foreground thread uses the default terrain data to perform the rendering task.
[0174] When there is no buffer information in the multi-buffer information area that is in a ready state, the foreground thread uses the default terrain data to perform the rendering task. This allows the foreground thread to continue to perform the rendering task without blocking, even in the event of a system cold start or an abnormal situation, thus further ensuring frame rate stability.
[0175] In some embodiments, Figure 5 In the method shown, the foreground thread performs a rendering task based on the second terrain data in the second storage area, including: the foreground thread generates a first image frame based on the second terrain data in the second storage area at a target frame rate, where the target frame rate is a fixed frame rate set in the frame rate controller.
[0176] The foreground thread generates the first image frame based on the second terrain data in the second storage area at the target frame rate, which enables the foreground thread to perform rendering tasks at a preset fixed frame rate, ensuring the stability of the frame rate of the rendering output.
[0177] In some embodiments, Figure 5In the method shown, the foreground thread generates a first image frame based on second terrain data in a second storage area at a target frame rate, including: when the foreground thread starts generating the first image frame based on the second terrain data in the second storage area at the target frame rate, the foreground thread records the start time of generating the first image frame; after the foreground thread generates the first image frame at the target frame rate, the foreground thread records the end time of generating the first image frame; the foreground thread determines the actual time taken to generate the first image frame based on the end time and the start time; the foreground thread determines the target frame interval time based on the target frame rate, wherein the target frame rate and the target frame interval time are reciprocals of each other; if the actual time taken is less than the target frame interval time, the foreground thread waits for the difference between the target frame interval time and the actual time taken before starting to generate the next image frame; if the actual time taken is greater than or equal to the target frame interval time, the foreground thread immediately starts generating the next image frame.
[0178] The foreground thread records the start and end times of each frame and calculates the actual time consumed. When the actual time consumed is less than the target frame interval, it waits for the difference before starting the next frame. When the actual time consumed is greater than or equal to the target frame interval, it starts the next frame immediately. This allows the foreground thread to precisely control the rendering rhythm of each frame. When the rendering is completed ahead of schedule, it waits for the remaining time to ensure a uniform frame interval. When the rendering times out, it starts the next frame immediately to avoid the accumulation of delays, thus further ensuring the smoothness and stability of the rendering output.
[0179] In some embodiments, Figure 5 In the methods shown, the background thread and the foreground thread are either in the same process or in different processes.
[0180] The fact that the background thread and the foreground thread are located in the same process or different processes allows the technical solution disclosed herein to flexibly adapt to different system architecture requirements, thereby improving the applicability and scalability of the solution.
[0181] See Figure 6 , Figure 6 This is a structural block diagram of a terrain data preparation and rendering apparatus provided in an embodiment of this disclosure. Figure 6 As shown, the terrain data preparation and rendering apparatus 800 may include a writing module 801 and a rendering module 802.
[0182] The write module 801 is used to write first terrain data to a first storage area; and, after writing the first terrain data to the first storage area, to write third terrain data to a second storage area.
[0183] The rendering module 802 is used to perform a rendering task based on the second terrain data in the second storage area during the process of the writing module writing the first terrain data to the first storage area, wherein the second terrain data in the second storage area is terrain data pre-written by the writing module; and to perform a rendering task based on the first terrain data in the first storage area after the writing module writes the first terrain data to the first storage area; and during the process of selecting new terrain data, if no new terrain data is detected to be ready within the maximum data waiting time, the rendering task is performed based on the second terrain data in the second storage area, wherein the maximum data waiting time is less than the target frame interval time.
[0184] In some embodiments, the writing module 801 is specifically used to obtain a data preparation request in the task queue, the data preparation request including the storage address of the original data; obtain the original data in the memory based on the storage address; decode the original data to obtain first terrain data; obtain rendering instruction information; determine an unused first storage area based on the rendering instruction information; and store the decoded first terrain data in the first storage area, the first storage area corresponding to first buffer information, the first buffer information including the storage address of the first storage area.
[0185] In some embodiments, the writing module 801 is specifically used to update the first buffer information to obtain updated first buffer information, the updated first buffer information including the storage address of the first storage area, status information and ready timestamp, the status information being used to indicate the ready state; update the rendering instruction information to obtain updated rendering instruction information; and send a data ready notification through the ready notification channel, the data ready notification being used to indicate that the first storage area stores first terrain data that can be read.
[0186] In some embodiments, the rendering module 802 is specifically used to obtain second buffer information, the second buffer information including the storage address, status information and ready timestamp of the second storage area; determine the second storage area based on the storage address in the second buffer information, the second storage area storing second terrain data; obtain the second terrain data in the second storage area; and perform a rendering task based on the second terrain data.
[0187] In some embodiments, the rendering module 802 is specifically used to obtain rendering instruction information and determine second buffer information based on the rendering instruction information.
[0188] In some embodiments, the rendering module 802 is specifically used to determine at least two buffer information pieces in the multi-buffer information area whose status information is in a ready state; compare the ready timestamps of the at least two buffer information pieces, and determine the second buffer information piece with the latest ready timestamp.
[0189] In some embodiments, the rendering module 802 is specifically used to perform a rendering task using default terrain data when there is no buffer information in the multi-buffer information area with the state information in a ready state.
[0190] In some embodiments, the rendering module 802 is specifically configured to record the start time of generating the first image frame when generating the first image frame based on the second terrain data in the second storage area at a target frame rate.
[0191] In some embodiments, the rendering module 802 is specifically configured to: record the end time of generating the first image frame after generating the first image frame at the target frame rate; determine the actual time taken to generate the first image frame based on the end time and the start time; determine the target frame interval time based on the target frame rate, wherein the target frame rate and the target frame interval time are reciprocals of each other; if the actual time taken is less than the target frame interval time, wait for the difference between the target frame interval time and the actual time taken before starting to generate the next image frame; if the actual time taken is greater than or equal to the target frame interval time, immediately start generating the next image frame.
[0192] See Figure 7 , Figure 7 This is a structural block diagram of an electronic device provided in an embodiment of this disclosure. Figure 7 As shown, the electronic device 900 may include a processor 901 and a memory 902. A program or instructions stored in the memory 902 and executable on the processor 901 implements the various processes of the terrain data preparation and rendering method embodiments described above, achieving the same technical effects. To avoid repetition, these processes will not be elaborated upon here. It should be noted that the electronic devices in this disclosure include mobile electronic devices and non-mobile electronic devices.
[0193] This disclosure also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the various processes of the above-described terrain data preparation and rendering method embodiments and achieves the same technical effects. To avoid repetition, these will not be described again here.
[0194] The processor is the processor in the electronic device described in the above embodiments. The readable storage medium includes computer-readable storage media, such as computer read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.
[0195] This disclosure also provides a chip, which includes a processor and a communication interface. The communication interface and the processor are coupled. The processor is used to run programs or instructions to implement the various processes of the above-described terrain data preparation and rendering method embodiments, and can achieve the same technical effect. To avoid repetition, it will not be described again here.
[0196] It should be understood that the chip mentioned in the embodiments of this disclosure may also be referred to as a system-on-a-chip, system chip, chip system, or system-on-a-chip, etc.
[0197] This disclosure is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this disclosure. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions.
[0198] These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing device to produce a machine, such that the instructions, which are executable by the processor of the computer or other programmable data processing device, produce instructions for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0199] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0200] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0201] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to interchangeably. Each embodiment focuses on describing the differences from other embodiments. In particular, the device and system embodiments are basically similar to the method embodiments, so the descriptions are relatively simple; relevant parts can be referred to the descriptions of the method embodiments. In this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations.
[0202] Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. The terms "upper," "lower," etc., indicating orientation or positional relationships based on the orientation or positional relationships shown in the accompanying drawings, are used only for the convenience of describing this disclosure and for simplifying the description, and are not intended to indicate or imply that the device or element referred to must have a particular orientation, be constructed or operated in a particular orientation, and therefore should not be construed as a limitation of this disclosure.
[0203] Unless otherwise expressly specified and limited, the terms "installation," "connection," and "linkage" should be interpreted broadly. For example, they can refer to fixed connections, detachable connections, or integral connections; they can refer to mechanical connections or electrical connections; they can refer to direct connections or indirect connections through an intermediate medium; and they can refer to the internal connection between two components. Those skilled in the art can understand the specific meaning of the above terms in this disclosure according to the specific circumstances.
[0204] It should be noted that, unless otherwise specified, the embodiments and features described in this disclosure can be combined with each other. This disclosure is not limited to any single aspect, nor to any single embodiment, nor to any combination and / or substitution of these aspects and / or embodiments. Moreover, each aspect and / or embodiment of this disclosure can be used alone or in combination with one or more other aspects and / or embodiments thereof.
[0205] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this disclosure, and not to limit them. Although this disclosure has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this disclosure, and they should all be covered within the scope of the claims and specification of this disclosure.
Claims
1. A method for preparing and rendering terrain data, characterized in that, The method is executed collaboratively by a background thread and a foreground thread, and the method includes: During the process of the background thread writing the first terrain data to the first storage area, the foreground thread performs a rendering task based on the second terrain data in the second storage area, where the second terrain data in the second storage area is the terrain data pre-written by the background thread; After the background thread writes the first terrain data to the first storage area, the foreground thread performs a rendering task based on the first terrain data in the first storage area, and the background thread writes the third terrain data to the second storage area. During the process of the foreground thread selecting new terrain data, if no new terrain data is detected to be ready within the maximum data waiting time, the foreground thread performs a rendering task based on the second terrain data in the second storage area, wherein the maximum data waiting time is less than the target frame interval time.
2. The method as described in claim 1, characterized in that, The background thread writes the first terrain data to the first storage area, including: The background thread retrieves a data preparation request from the task queue, and the data preparation request includes the storage address of the original data. The background thread retrieves the original data from the memory based on the storage address; The background thread decodes the raw data to obtain the first terrain data. The background thread obtains rendering instruction information, which is used to indicate that the foreground thread is using the second storage area; The background thread determines the first storage area that is not used by the foreground thread based on the rendering instruction information; The background thread stores the decoded first terrain data in the first storage area, which corresponds to the first buffer information, including the storage address of the first storage area.
3. The method as described in claim 2, characterized in that, After the background thread stores the decoded first terrain data in the first storage area, the method further includes: The background thread updates the first buffer information to obtain updated first buffer information. The updated first buffer information includes the storage address of the first storage area, status information, and ready timestamp. The status information is used to indicate the ready status. The background thread updates the rendering indication information to obtain updated rendering indication information, which is used to indicate that the foreground thread is using the first storage area; The background thread sends a data ready notification to the foreground thread through a ready notification channel. The data ready notification indicates that the first storage area contains first terrain data that can be read.
4. The method as described in claim 1, characterized in that, The foreground thread performs rendering tasks based on the second terrain data in the second storage area, including: The foreground thread obtains the second buffer information, which includes the storage address, status information, and ready timestamp of the second storage area. The foreground thread determines the second storage area based on the storage address in the second buffer information, and the second storage area stores the second terrain data. The foreground thread acquires the second terrain data in the second storage area; The foreground thread performs rendering tasks based on the second terrain data.
5. The method as described in claim 4, characterized in that, The foreground thread obtains the second buffer information including: The foreground thread obtains rendering instruction information, which is used to indicate the buffer information that the foreground thread should currently use. The foreground thread determines the second buffer information based on the rendering instruction information.
6. The method as described in claim 4, characterized in that, The foreground thread obtains the second buffer information, including: The foreground thread determines at least two buffers in the multi-buffer information area whose status information is ready; The foreground thread compares the ready timestamps of the at least two buffer information to determine the second buffer information with the latest ready timestamp.
7. The method as described in claim 1, characterized in that, Before the background thread writes the first terrain data to the first storage area, the method further includes: If there is no buffer information in the multi-buffered information area that is in a ready state, the foreground thread uses the default terrain data to perform the rendering task.
8. The method as described in claim 1, characterized in that, The foreground thread performs rendering tasks based on the second terrain data in the second storage area, including: The foreground thread generates a first image frame based on the second terrain data in the second storage area at a target frame rate, wherein the target frame rate is a fixed frame rate set in the frame rate controller.
9. The method as described in claim 8, characterized in that, The foreground thread generates the first image frame based on the second terrain data in the second storage area at a target frame rate, including: When the foreground thread starts generating the first image frame based on the second terrain data in the second storage area at the target frame rate, the foreground thread records the start time of generating the first image frame; After the foreground thread generates the first image frame at the target frame rate, the foreground thread records the end time of generating the first image frame. The foreground thread determines the actual time consumed by the first image frame based on the end time and the start time; The foreground thread determines the target frame interval time based on the target frame rate, wherein the target frame rate and the target frame interval time are reciprocals of each other; If the actual time consumed is less than the target frame interval time, the foreground thread waits for the difference between the target frame interval time and the actual time consumed before starting to generate the next image frame. If the actual time consumed is greater than or equal to the target frame interval time, the foreground thread immediately begins generating the next image frame.
10. The method according to any one of claims 1-9, characterized in that, The background thread and the foreground thread are located in the same process, or the background thread and the foreground thread are located in different processes.
11. A device for preparing and rendering terrain data, characterized in that, The device includes: The writing module is used to write first terrain data to a first storage area; and, after writing the first terrain data to the first storage area, to write third terrain data to a second storage area. A rendering module is configured to perform a rendering task based on second terrain data in a second storage area during the process of the writing module writing first terrain data to a first storage area, wherein the second terrain data in the second storage area is terrain data pre-written by the writing module; and to perform a rendering task based on the first terrain data in the first storage area after the writing module writes the first terrain data to the first storage area; and to perform a rendering task based on the second terrain data in the second storage area during the process of selecting new terrain data, wherein if no new terrain data is detected to be ready within a maximum data waiting time, the rendering task is performed based on the second terrain data in the second storage area, wherein the maximum data waiting time is less than the target frame interval time.
12. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the method of any one of claims 1-10.
13. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor for executing a computer program stored in the memory, wherein when the computer program is executed, it implements the method of any one of claims 1-10.