Tile depth clamping method, apparatus, device, and storage medium

CN122049168BActive Publication Date: 2026-08-21MOORE THREADS TECHNOLOGY (SHANGHAI) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202610499428.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2026-04-15
Publication Date
2026-08-21
Estimated Expiration
2046-04-15

AI Technical Summary

Technical Problem

该方案中,由于钳位后的深度不再代表原始几何深度,因此修改顶点深度会导致透视插值错误,可能引入伪影(artifacts),如在影子映射(shadow mapping)、排序渲染(order-independent transparency)、透明物体或薄几何体中出现深度偏差等,降低了渲染的准确性和稳定性

Benefits of technology

[0027]本公开提供的技术方案与现有技术相比具有如下有益效果:本公开实施例中,通过在光栅化阶段之后、深度测试之前,获取片元的深度值;对片元的深度值进行深度钳位处理,得到片元的目标深度值;对目标深度值进行深度测试,以根据深度测试结果确定是否保留片元。由此可以在光栅化阶段之后且在深度测试之前对片元的深度值进行深度钳位处理,无需在图元剪裁或顶点后变换阶段进行深度值的深度钳位,在画质上采用片元级深度钳位而非顶点级修改,确保透视插值深度值的几何正确性,从根本上消除了顶点深度钳位引发的阴影偏差、透明排序错误等伪影,提高了渲染的准确性和稳定性。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122049168B_ABST
    Figure CN122049168B_ABST
Patent Text Reader

Abstract

The present disclosure provides a kind of slice element depth clamping method, device, equipment and storage medium, it is related to graphics processing technical field.The present disclosure obtains the depth value of slice element by being after rasterization stage, before depth test;The depth value of slice element is carried out depth clamping processing, obtains the target depth value of slice element;The depth test is carried out to target depth value, to determine whether to keep slice element according to depth test result.Therefore, the depth value of slice element can be carried out depth clamping processing after rasterization stage and before depth test, it is unnecessary to carry out the depth clamping of depth value in primitive clipping or vertex post-transform stage, adopts slice element level depth clamping instead of vertex level modification, ensures the geometric correctness of perspective interpolation depth value, fundamentally eliminates the artifacts such as shadow deviation, transparent ordering error caused by vertex depth clamping, improves the accuracy and stability of rendering.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of graphics processing technology, and in particular to a fragment depth clamping method, apparatus, device, and storage medium. Background Technology

[0002] Currently, in graphics processing units (GPUs), depth clamping is an important rendering pipeline function. Depth clamping can prevent geometric clipping when the depth value of a vertex or fragment exceeds the viewport depth range. Instead, it clamps the depth value directly to the nearest legal boundary, thus ensuring that the fragment can still participate in depth testing and shading.

[0003] In related technologies, depth clamping on the GPU occurs during the vertex processing stage. After the GPU performs vertex processing on the primitives, the vertex coordinates of the primitives are transformed to homogeneous clipping space. At this point, depth clamping is activated, directly modifying the depth value (z-coordinate) of the vertex to clamp it within the viewport depth range. Subsequently, during the rasterization stage, perspective interpolation is performed on the clamped vertices to generate the interpolated depth of the fragment. In this approach, since the clamped depth no longer represents the original geometric depth, modifying the vertex depth can lead to perspective interpolation errors, potentially introducing artifacts such as depth deviations in shadow mapping, order-independent transparency, transparent objects, or thin geometry, thus reducing the accuracy and stability of rendering. Summary of the Invention

[0004] To address the problems existing in the aforementioned related technologies, this disclosure provides a fragment depth clamping method, apparatus, device, and storage medium.

[0005] The first aspect of this disclosure provides a fragment depth clamping method, including:

[0006] After generating the interpolated depth value of the fragment during the rasterization stage and before the depth test, the interpolated depth value is determined as the depth value to be processed. The depth value to be processed is subjected to depth clamping processing to obtain the first target depth value of the fragment. The first target depth value is then subjected to depth testing.

[0007] Optionally, the above-mentioned depth clamping processing of the depth value to obtain the target depth value of the fragment includes:

[0008] When the depth value is an interpolated depth value generated during the rasterization stage, the current rendering condition is single-channel rendering mode, and the depth clamping function is enabled, the depth value is subjected to depth clamping processing to obtain the first target depth value of the fragment; when the depth value is a depth value modified by the pixel shader, the current rendering condition is single-channel rendering mode, and the depth clamping function is enabled, the depth value is subjected to depth clamping processing to obtain the second target depth value of the fragment.

[0009] Optionally, the above-mentioned depth test on the target depth value to determine whether to retain the fragment based on the depth test result includes: performing an early depth test on the first target depth value to obtain a first depth test result, and determining whether to retain the fragment corresponding to the first target depth value based on the first depth test result; performing a delayed depth test on the second target depth value based on the first depth test result to obtain a second depth test result, and determining whether to retain the fragment corresponding to the second target depth value based on the second depth test result.

[0010] Optionally, the above-mentioned method of performing an advance depth test on the first target depth value to obtain a first depth test result, and determining whether to retain the fragment corresponding to the first target depth value based on the first depth test result, includes: comparing the first target depth value with the first buffer depth value corresponding to the first pixel position in the current depth buffer to obtain a first depth test result, wherein the first pixel position is the pixel position to which the first target depth value belongs; if the first depth test result is that the first target depth value is less than the first buffer depth value, updating the first buffer depth value in the current depth buffer to the first target depth value, and determining the updated current depth buffer as the first depth buffer; if the first depth test result is that the first target depth value is greater than or equal to the first buffer depth value, deleting the fragment corresponding to the first target depth value.

[0011] Optionally, the above-mentioned method of performing a delayed depth test on the second target depth value based on the first depth test result to obtain a second depth test result, and determining whether to retain the fragment corresponding to the second target depth value based on the second depth test result, includes: comparing the second target depth value with the second buffer depth value corresponding to the second pixel position in the first depth buffer to obtain a second depth test result, wherein the second pixel position is the pixel position to which the second target depth value belongs; if the second depth test result is that the second target depth value is less than the second buffer depth value, updating the second buffer depth value in the first depth buffer to the second target depth value, and determining the updated first depth buffer as the second depth buffer; if the second depth test result is that the second target depth value is greater than or equal to the second buffer depth value, deleting the fragment corresponding to the second target depth value.

[0012] Optionally, the above-mentioned depth clamping processing to obtain the target depth value of the fragment includes: when the depth value type is an interpolated depth value generated during the rasterization stage, the current rendering condition is the first channel in the dual-channel rendering mode, and the depth clamping function is enabled, performing depth clamping processing on the depth value to obtain the third target depth value of the fragment; when the depth value type is an interpolated depth value generated during the rasterization stage, the current rendering condition is the second channel in the dual-channel rendering mode, and the depth clamping function is enabled, performing depth clamping processing on the depth value to obtain the fourth target depth value of the fragment; and when the depth value type is a depth value modified by the pixel shader, the current rendering condition is the second channel in the dual-channel rendering mode, performing depth clamping processing on the depth value to obtain the fifth target depth value of the fragment.

[0013] Optionally, the above-mentioned depth testing of the target depth value to determine whether to retain fragments based on the depth test results includes: performing an early depth test on the third target depth value to obtain a third depth test result, and determining whether to retain the fragments corresponding to the third target depth value based on the third depth test result; performing an early depth test on the fourth target depth value based on the third depth test result to obtain a fourth depth test result, and determining whether to retain the fragments corresponding to the fourth target depth value based on the fourth depth test result; and performing a delayed depth test on the fifth target depth value based on the fourth depth test result to obtain a fifth depth test result, and determining whether to retain the fragments corresponding to the fifth target depth value based on the fifth depth test result.

[0014] Optionally, the above-mentioned depth test on the third target depth value to obtain the third depth test result, and the determination of whether to retain the fragment corresponding to the third target depth value based on the third depth test result, includes: comparing the third target depth value with the third buffer depth value corresponding to the third pixel position in the current depth buffer to obtain the third depth test result, wherein the third pixel position is the pixel position to which the third target depth value belongs; if the third depth test result is that the third target depth value is less than the third buffer depth value, updating the third buffer depth value in the current depth buffer to the third target depth value, and determining the updated current depth buffer as the third depth buffer; if the third depth test result is that the third target depth value is greater than or equal to the third buffer depth value, deleting the fragment corresponding to the third target depth value.

[0015] Optionally, the above-mentioned method of performing a depth test on the fourth target depth value based on the third depth test result to obtain a fourth depth test result, and determining whether to retain the fragment corresponding to the fourth target depth value based on the fourth depth test result, includes: comparing the fourth target depth value with the fourth buffer depth value corresponding to the fourth pixel position in the third depth buffer to obtain a fourth depth test result, wherein the fourth pixel position is the pixel position to which the fourth target depth value belongs; if the fourth depth test result is that the fourth target depth value is less than the fourth buffer depth value, updating the fourth buffer depth value in the third depth buffer to the fourth target depth value, and determining the updated third depth buffer as the fourth depth buffer; if the fourth depth test result is that the fourth target depth value is greater than or equal to the fourth buffer depth value, deleting the fragment corresponding to the fourth target depth value.

[0016] Optionally, the above-mentioned method of performing a depth test on the fifth target depth value based on the fourth depth test result to obtain a fifth depth test result, and determining whether to retain the fragment corresponding to the fifth target depth value based on the fifth depth test result, includes: comparing the fifth target depth value with the fifth buffer depth value corresponding to the fifth pixel position in the fourth depth buffer to obtain a fifth depth test result, wherein the fifth pixel position is the pixel position to which the fifth target depth value belongs; if the fifth depth test result is that the fifth target depth value is less than the fifth buffer depth value, updating the fifth buffer depth value in the fourth depth buffer to the fifth target depth value, and determining the updated fourth depth buffer as the fifth depth buffer; if the fifth depth test result is that the fifth target depth value is greater than or equal to the fifth buffer depth value, deleting the fragment corresponding to the fifth target depth value.

[0017] Optionally, the above method further includes: obtaining the type flag corresponding to the depth value; if the type flag corresponding to the depth value is an interpolation flag, determining that the type of the depth value is an interpolated depth value generated in the rasterization stage; if the type flag corresponding to the depth value is a non-interpolation flag, determining that the type of the depth value is a depth value modified by the pixel shader.

[0018] Optionally, the above method further includes: obtaining the current rendering mode flag, the current rendering channel flag, and the current depth clamp flag; when the rendering mode flag is a single-channel mode flag and the depth clamp flag is enabled, determining that the rendering condition is a single-channel rendering mode and the depth clamp function is enabled; when the rendering mode flag is a dual-channel mode flag, the rendering channel flag is a first channel flag, and the depth clamp flag is enabled, determining that the rendering condition is the first channel in the dual-channel rendering mode and the depth clamp function is enabled; when the rendering mode flag is a dual-channel mode flag, the rendering channel flag is a second channel flag, and the depth clamp flag is enabled, determining that the rendering condition is the second channel in the dual-channel rendering mode and the depth clamp function is enabled; when the rendering mode flag is a dual-channel mode flag and the rendering channel flag is a second channel flag, determining that the rendering condition is the second channel in the dual-channel rendering mode.

[0019] Optionally, the above-mentioned depth clamping processing of the depth value to obtain the target depth value of the fragment includes: normalizing the depth value to obtain the normalized depth value corresponding to the depth value; obtaining the target viewport depth range corresponding to the fragment; clamping the normalized depth value to the target viewport depth range to generate the target depth value of the fragment.

[0020] Optionally, the above-mentioned normalization processing of the depth value to obtain the normalized depth value corresponding to the depth value includes: performing floating-point special value detection on the depth value to obtain the numerical type of the depth value; when the numerical type of the depth value is a target type, determining the minimum depth value in the depth value interval corresponding to the current depth buffer as the normalized depth value corresponding to the depth value, wherein the target type includes at least one of NOT number, denormalized number, and negative infinity; when the numerical type of the depth value is positive infinity, determining the maximum depth value in the depth value interval corresponding to the current depth buffer as the normalized depth value corresponding to the depth value; and when the numerical type of the depth value is a normal floating-point number, determining the depth value as the normalized depth value corresponding to the depth value.

[0021] Optionally, obtaining the target viewport depth range corresponding to the fragment includes: obtaining the target viewport group identifier and the target viewport identifier corresponding to the fragment; determining the target viewport register group corresponding to the target viewport group identifier in a preset number of viewport register groups, wherein each viewport register group includes multiple viewport depth range registers, and each viewport depth range register stores a viewport depth range; determining the target viewport depth range register corresponding to the target viewport identifier in the target viewport register group; and determining the viewport depth range in the target viewport depth range register as the target viewport depth range corresponding to the fragment.

[0022] Optionally, before determining the target viewport register group corresponding to the target viewport group identifier among the preset number of viewport register groups, the method further includes: configuring the rendering state before generating fragments in the rasterization stage; the rendering state includes the viewport depth range and viewport identifier corresponding to each viewport; configuring the viewport depth range register corresponding to each viewport identifier for each viewport identifier, and writing the viewport depth range corresponding to the viewport identifier into the viewport depth range register corresponding to the viewport identifier; grouping the viewport depth range registers corresponding to multiple viewport identifiers according to a preset grouping rule to obtain a preset number of viewport register groups, and configuring the viewport group identifier corresponding to each viewport register group.

[0023] Optionally, the above-mentioned method of clamping the normalized depth value to the target viewport depth range to generate the target depth value of the fragment includes: reading the minimum and maximum target viewport depth values ​​within the target viewport depth range; clamping the normalized depth value to the minimum target viewport depth when the normalized depth value is less than the minimum target viewport depth; clamping the normalized depth value to the maximum target viewport depth when the normalized depth value is greater than the maximum target viewport depth; and determining the normalized depth value as the target depth value of the fragment when the normalized depth value is between the minimum and maximum target viewport depth values.

[0024] A second aspect of this disclosure provides a fragment depth clamping device, comprising: an acquisition module for acquiring a fragment depth value after rasterization and before depth testing; a first depth clamping module for performing depth clamping processing on the depth value to obtain a target depth value of the fragment; and a depth testing module for performing depth testing on the target depth value to determine whether to retain the fragment based on the depth testing result.

[0025] A third aspect of this disclosure provides a computer device, including a memory and a processor, wherein the memory stores a computer program that, when executed by the processor, implements the fragment depth clamping method of the first aspect described above.

[0026] A fourth aspect of this disclosure provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the fragment depth clamping method of the first aspect described above.

[0027] Compared with existing technologies, the technical solution provided in this disclosure has the following beneficial effects: In the embodiments of this disclosure, the depth value of the fragment is obtained after the rasterization stage and before the depth test; the depth value of the fragment is subjected to depth clamping processing to obtain the target depth value of the fragment; the target depth value is subjected to depth testing to determine whether to retain the fragment based on the depth test result. Therefore, the depth value of the fragment can be depth clamped after the rasterization stage and before the depth test, eliminating the need for depth clamping of the depth value during primitive clipping or post-vertex transformation stages. This fragment-level depth clamping, rather than vertex-level modification, ensures the geometric correctness of the perspective interpolation depth value, fundamentally eliminating artifacts such as shadow deviation and transparency sorting errors caused by vertex depth clamping, and improving the accuracy and stability of rendering.

[0028] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and are not intended to limit this disclosure. Attached Figure Description

[0029] The accompanying drawings, which are incorporated in and form a part of this specification, illustrate embodiments consistent with this disclosure and, together with the description, serve to explain the principles of this disclosure.

[0030] To more clearly illustrate the technical solutions in the embodiments of this disclosure or the prior art, the accompanying drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0031] Figure 1 This is a flowchart of a fragment depth clamping method provided in an embodiment of this disclosure.

[0032] Figure 2 This is a flowchart of a tile-based deferred rendering method provided in an embodiment of this disclosure.

[0033] Figure 3 This is a flowchart of another fragment depth clamping method provided in the embodiments of this disclosure.

[0034] Figure 4 This is a flowchart of another fragment depth clamping method provided in the embodiments of this disclosure.

[0035] Figure 5 This is a flowchart of another tile-based deferred rendering method provided in this embodiment of the disclosure.

[0036] Figure 6 This is a flowchart of another fragment depth clamping method provided in the embodiments of this disclosure.

[0037] Figure 7This is a flowchart of another fragment depth clamping method provided in the embodiments of this disclosure.

[0038] Figure 8 This is a schematic diagram of a viewport register group provided in an embodiment of this disclosure.

[0039] Figure 9 This is a flowchart of another fragment depth clamping method provided in the embodiments of this disclosure.

[0040] Figure 10 This is a schematic diagram of the structure of a fragment depth clamping device provided in an embodiment of this disclosure.

[0041] Figure 11 This is a schematic diagram of the structure of a computer device provided in an embodiment of this disclosure. Detailed Implementation

[0042] To better understand the above-mentioned objectives, features, and advantages of this disclosure, the solutions disclosed herein will be further described below. It should be noted that, unless otherwise specified, the embodiments and features described herein can be combined with each other.

[0043] Numerous specific details are set forth in the following description in order to provide a full understanding of this disclosure, but this disclosure may also be implemented in other ways different from those described herein; obviously, the embodiments in the specification are only some, and not all, of the embodiments of this disclosure.

[0044] It should be understood that the steps described in the method embodiments of this disclosure may be performed in different orders and / or in parallel. Furthermore, the method embodiments may include additional steps and / or omit the steps shown. The scope of this disclosure is not limited in this respect.

[0045] It should be noted that, in this document, relational terms such as "first" and "second" are used merely 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. 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. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0046] It should be noted that the terms "a" and "a plurality of" used in this disclosure are illustrative rather than restrictive, and those skilled in the art should understand that, unless otherwise expressly indicated in the context, they should be understood as "one or more".

[0047] To better understand the inventive concept of the embodiments of this disclosure, the technical solutions of the embodiments of this disclosure will be described below in conjunction with exemplary embodiments.

[0048] The fragment depth clamping method provided in this disclosure can be executed by a graphics processing unit (GPU) located within a computer device, which can be understood as any electronic device with processing and computing capabilities.

[0049] Figure 1 This is a flowchart of a fragment depth clamping method provided in an embodiment of this disclosure, which can be executed by a graphics processor located within a computer device. Figure 1 As shown, the fragment depth clamping method provided in this embodiment includes the following steps 110-130.

[0050] Step 110: After the rasterization stage and before the depth test, obtain the depth value of the fragment.

[0051] In this embodiment of the disclosure, the graphics processing unit (GPU) within the computer device can respond to a single draw call instruction for a primitive by performing vertex shader processing on the primitive during the vertex processing stage, transforming the vertex coordinates of the primitive to homogeneous clip space; subsequently, during the rasterization stage, the primitive is rasterized based on the vertex data processed by the vertex shader, and the interpolated depth value of the fragment corresponding to the primitive is generated through perspective interpolation. After generating the interpolated depth value of the fragment during the rasterization stage and before the depth test, the depth value of the fragment can be obtained.

[0052] The rasterization stage follows the primitive clipping stage and the post-vertex transformation stage.

[0053] The rasterization stage is responsible for performing perspective interpolation on the vertices of geometric primitives (such as triangles, line segments, etc.), converting the geometric primitives into fragments, and generating an interpolated depth value for each fragment. Each fragment corresponds to a pixel position in the frame buffer, but it has not yet been decided whether it will be displayed in the end.

[0054] Step 120: Perform depth clamping on the depth value of the fragment to obtain the target depth value of the fragment.

[0055] In this embodiment of the disclosure, after obtaining the depth value of the fragment, the graphics processor in the computer device can perform depth clamping processing on the depth value of the fragment to obtain the target depth value of the fragment.

[0056] Step 130: Perform a depth test on the target depth value to determine whether to retain the fragment based on the depth test results.

[0057] In this embodiment of the disclosure, after obtaining the target depth value of the fragment, the graphics processor in the computer device can perform a depth test on the target depth value of the fragment to determine whether to retain the fragment based on the depth test result.

[0058] In this embodiment, the depth value of a fragment is obtained after the rasterization stage and before the depth test; the depth value of the fragment is depth-clamped to obtain the target depth value of the fragment; and the target depth value is depth-tested to determine whether to retain the fragment based on the depth test result. This allows depth clamping of the depth value after the interpolated depth value of the fragment is generated during the rasterization stage and before the depth test, eliminating the need for depth clamping during primitive clipping or post-vertex transformation stages. This fragment-level depth clamping, rather than vertex-level modification, ensures the geometric correctness of the perspective interpolated depth value, fundamentally eliminating artifacts such as shadow deviation and transparency sorting errors caused by vertex depth clamping, thus improving the accuracy and stability of rendering.

[0059] Early-Z testing is a depth test performed by the GPU before pixel shading is applied to fragments. It can remove occluded fragments in advance, thereby reducing expensive pixel shading calls and memory accesses, and reducing overdraw and power consumption. Late-Z testing, on the other hand, is a depth test performed after pixel shading is applied to fragments. It allows for the processing of advanced effects that require pixel shading information, but it cannot avoid the calculation of occluded fragments, thus increasing overdraw and resource overhead.

[0060] Tile-Based Deferred Rendering (TBDR) is a GPU-based rendering technique that divides the screen into multiple tiles and processes pixels in on-chip cache. It first collects all the geometric information within a tile, performs depth testing and hidden surface removal (HSR), determines which pixels are ultimately visible, and only performs expensive pixel shading calculations on these visible pixels. This can significantly reduce overdraw, reduce memory access and computational redundancy, reduce memory bandwidth consumption, and improve rendering throughput and efficiency.

[0061] For example, Figure 2 It is a flowchart of tile-based deferred rendering, such as Figure 2As shown, the tile-based deferred rendering process includes the following steps: the geometry data of the graphics undergoes vertex processing, clipping, projection and culling, tile partitioning, rasterization, hidden face removal (HSR), depth testing, tag buffer processing (recording which fragment corresponds to each pixel position), texture sampling and shading, alpha testing, and alpha blending. Finally, the on-chip color buffer is written back to the frame buffer in system memory.

[0062] In related technologies, during the pixel shading stage after rasterization, such as single-pass and dual-pass rendering modes, the pixel shading stage allows users to manually modify fragment depth values. If the modified depth value exceeds the viewport depth range, it increases the probability of undefined behavior during rendering, reducing accuracy and stability. Furthermore, this approach cannot perform depth testing before pixel shading, forcing all fragments to undergo pixel shading, leading to increased overdraw, increased pixel shading calls and memory accesses, and increased bandwidth and computational overhead. Tile-based deferred rendering architecture relies on tile-level pre-deep testing to reduce memory access. The inability to perform pre-deep testing completely violates this design principle of TBDR, increasing computational overhead and reducing efficiency.

[0063] Figure 3 This is a flowchart of a fragment depth clamping method provided in an embodiment of this disclosure, which can be executed by a graphics processor located within a computer device. Figure 3 As shown, the fragment depth clamping method provided in this embodiment includes the following steps 310-350.

[0064] Step 310: After the rasterization stage and before the depth test, obtain the depth value of the fragment.

[0065] Step 320: When the fragment depth value is of type interpolated depth value generated during the rasterization stage, the current rendering condition is single-channel rendering mode, and the depth clamping function is enabled, perform depth clamping processing on the fragment depth value to obtain the first target depth value of the fragment.

[0066] In this embodiment of the disclosure, when the type of the fragment depth value is the interpolated depth value generated during the rasterization stage, the current rendering condition is single-channel rendering mode, and the depth clamping function is enabled, the graphics processor in the computer device can perform depth clamping processing on the fragment depth value to obtain the first target depth value of the fragment.

[0067] Single-pass rendering mode can be understood as a rendering mode that completes fragment processing through only one rendering pass during a single rendering execution.

[0068] The deep clamping function being enabled can be understood as the deep clamping function being turned on.

[0069] In some embodiments, a type flag corresponding to the depth value of a fragment can be obtained; if the type flag corresponding to the depth value is an interpolation flag, it can be determined that the type of the depth value of the fragment is an interpolation depth value generated during the rasterization stage.

[0070] For example, if the type flag corresponding to the depth value of a fragment is the interpolation flag interpolated_depth==TRUE, it can be determined that the depth type of the fragment's depth value is the interpolated depth value generated during the rasterization stage.

[0071] In some embodiments, the current rendering mode flag, the current rendering channel flag, and the current depth clamp flag can be obtained; if the rendering mode flag is a single-channel mode flag and the depth clamp flag is an enabled flag, it is determined that the rendering condition is a single-channel rendering mode and the depth clamp function is enabled.

[0072] The graphics processor can read the current rendering mode flag, the current rendering pass flag, and the current depth clamp flag from the control stream of the rendering pipeline.

[0073] Rendering mode flags can include single-pass mode flags or dual-pass mode flags. For example, the single-pass mode flag can be one_pass_only; the dual-pass mode flag can be two_pass.

[0074] The depth clamp flag can be understood as identification information indicating the state of the depth clamp function. The depth clamp flag can include an enable flag or a disable flag.

[0075] For example, the depth clamping flag can be `depthclamp_en`. Alternatively, the depth clamping flag can be represented using a boolean variable.

[0076] The depth clamping flag is an enable flag, which can be understood as a flag used to indicate that the depth clamping function is enabled (on). When the depth clamping flag is enabled, it means that the depth clamping function is enabled, that is, the depth clamping function is on.

[0077] The depth clamp flag being disabled can be understood as a flag used to indicate that the depth clamp function is in a disabled (off) state. When the depth clamp flag is disabled, it means that the depth clamp function is in a disabled state, that is, the depth clamp function is in a closed state.

[0078] For example, if the rendering mode flag is set to the single-pass mode flag one_pass_only and the depth clamp flag is set to the enable flag depthclamp_en==TRUE, it can be determined that the rendering condition is single-pass rendering mode and the depth clamp function is enabled.

[0079] Therefore, the type of fragment depth value can be accurately determined by the type flag corresponding to the depth value, and the rendering conditions can be accurately determined by the rendering mode flag and the depth clamp flag.

[0080] Step 330: Perform an advance depth test on the first target depth value to obtain the first depth test result, and determine whether to retain the fragment corresponding to the first target depth value based on the first depth test result.

[0081] In this embodiment of the disclosure, after performing depth clamping processing on the depth values ​​of fragments generated during the rasterization stage to obtain a first target depth value for the fragments, the graphics processor within the computer device can perform a depth test on the first target depth value to obtain a first depth test result. Based on the first depth test result, it can determine whether to retain the fragment corresponding to the first target depth value. Therefore, early-Z testing of the fragment depth value can be performed, i.e., depth testing of the fragment depth value before pixel shading is executed. This allows for the early removal of occluded fragments, thereby reducing expensive pixel shading calls and memory accesses, and lowering overdraw and power consumption.

[0082] Step 340: When the depth value type is the pixel shader modified depth value, the current rendering condition is single-channel rendering mode and the depth clamping function is enabled, perform depth clamping processing on the fragment depth value to obtain the second target depth value of the fragment.

[0083] In this embodiment of the disclosure, when the type of the fragment's depth value is the pixel shader-modified depth value, the current rendering condition is single-channel rendering mode, and the depth clamping function is enabled, the graphics processor in the computer device can perform depth clamping processing on the pixel shader-modified depth value to obtain the second target depth value of the fragment.

[0084] The modified depth value of the pixel shader can be understood as the depth value of the fragment output by the pixel shader after modifying the interpolated depth value of the fragment during the pixel shading process.

[0085] Step 350: Based on the first depth test result, perform a delayed depth test on the second target depth value to obtain the second depth test result, and determine whether to retain the fragment corresponding to the second target depth value based on the second depth test result.

[0086] In this embodiment of the disclosure, after performing depth clamping processing on the depth value of the fragment to obtain a second target depth value of the fragment, and performing an advance depth test on the first target depth value to obtain a first depth test result, the graphics processor in the computer device can perform a delayed depth test on the second target depth value based on the first depth test result to obtain a second depth test result, and determine whether to retain the fragment corresponding to the second target depth value based on the second depth test result. Thus, depth clamping can be performed on the depth value modified by the pixel shader to obtain a second target depth value, and a depth test can be performed on the second target depth value based on the first depth test result after the advance depth test to obtain a second depth test result.

[0087] In some embodiments, steps 310-350 may include S11-S17.

[0088] S11. After the rasterization stage and before the depth test, obtain the depth value of the fragment.

[0089] S12. When the fragment depth value is of type interpolated depth value generated during the rasterization stage, the current rendering condition is single-channel rendering mode, and the depth clamping function is enabled, perform depth clamping processing on the fragment depth value to obtain the first target depth value of the fragment.

[0090] S13. Compare the first target depth value with the first buffer depth value corresponding to the first pixel position in the current depth buffer to obtain the first depth test result, wherein the first pixel position is the pixel position to which the first target depth value belongs.

[0091] The depth buffer can be understood as a dedicated storage area for storing the depth value corresponding to each pixel position. The depth values ​​in the depth buffer are used to perform depth comparisons during the graphics rendering process to determine the occlusion relationship between different geometric fragments.

[0092] For example, the depth value range corresponding to the depth buffer can be [+0.0, +1.0].

[0093] S14. If the first depth test result is that the first target depth value is less than the first buffer depth value, update the first buffer depth value in the current depth buffer to the first target depth value, and determine the updated current depth buffer as the first depth buffer; if the first depth test result is that the first target depth value is greater than or equal to the first buffer depth value, delete the fragment corresponding to the first target depth value.

[0094] In this embodiment of the disclosure, if the first depth test result is that the first target depth value is less than the first buffer depth value, it means that the fragment corresponding to the first target depth value is in front of the fragment corresponding to the first buffer depth value, and the fragment corresponding to the first buffer depth value is occluded by the fragment corresponding to the first target depth value. Therefore, the first buffer depth value in the current depth buffer can be updated to the first target depth value, and the updated current depth buffer can be determined as the first depth buffer.

[0095] If the first target depth value is greater than the first buffer depth value in the first depth test, it means that the fragment corresponding to the first target depth value is behind the fragment corresponding to the first buffer depth value, and the fragment corresponding to the first target depth value is occluded by the fragment corresponding to the first buffer depth value. Therefore, the fragment corresponding to the first target depth value can be deleted.

[0096] If the first depth test result shows that the first target depth value is equal to the first buffer depth value, it means that the fragment corresponding to the first target depth value coincides with the fragment corresponding to the first buffer depth value. Therefore, the fragment corresponding to the first target depth value can be deleted.

[0097] It should be noted that if the first target depth value is less than the first buffer depth value in the first depth test, it means that the first target depth value has passed the depth test. The graphics processor can then perform pixel shading on the fragments corresponding to the first target depth value based on the pixel shader to obtain the depth value after pixel shading.

[0098] S15. When the depth value is a pixel shader modified depth value, the current rendering condition is single-channel rendering mode, and the depth clamping function is enabled, perform depth clamping processing on the fragment depth value to obtain the second target depth value of the fragment.

[0099] S16. Compare the second target depth value with the second buffer depth value corresponding to the second pixel position in the first depth buffer to obtain the second depth test result, wherein the second pixel position is the pixel position to which the second target depth value belongs.

[0100] In this embodiment, since the second target depth value is the depth value of the fragment obtained by depth clamping the depth value modified by the pixel shader, it is necessary to perform a depth test on the second target depth value. After obtaining the first depth buffer, the graphics processor can compare the second target depth value with the second buffer depth value corresponding to the second pixel position in the first depth buffer to obtain the second depth test result, wherein the second pixel position is the pixel position to which the second target depth value belongs.

[0101] S17. If the second depth test result is that the second target depth value is less than the second buffer depth value, update the second buffer depth value in the first depth buffer to the second target depth value, and determine the updated first depth buffer as the second depth buffer; if the second depth test result is that the second target depth value is greater than or equal to the second buffer depth value, delete the fragment corresponding to the second target depth value.

[0102] In this embodiment of the disclosure, when the second target depth value is less than the second buffer depth value, it means that the fragment corresponding to the second target depth value is in front of the fragment corresponding to the second buffer depth value, and the fragment corresponding to the second buffer depth value is occluded by the fragment corresponding to the second target depth value. Therefore, the second buffer depth value in the first depth buffer can be updated to the second target depth value, and the updated first depth buffer can be determined as the second depth buffer.

[0103] If the second target depth value is greater than the second buffer depth value, it means that the fragment corresponding to the second target depth value is behind the fragment corresponding to the second buffer depth value, and the fragment corresponding to the second target depth value is occluded by the fragment corresponding to the second buffer depth value. Therefore, the fragment corresponding to the second target depth value can be deleted.

[0104] If the second target depth value is equal to the second buffer depth value, it means that the fragment corresponding to the second target depth value coincides with the fragment corresponding to the second buffer depth value, so the fragment corresponding to the second target depth value can be deleted.

[0105] In this embodiment, after generating the interpolated depth value of the fragment during the rasterization stage, depth clamping processing is performed on the interpolated depth value of the fragment in a single-channel rendering mode to obtain a first target depth value of the fragment. Then, an early depth test is performed on the first target depth value to obtain a first depth test result and a depth buffer updated by the first depth test result. Next, based on the pixel shader, the first target depth value that has passed the depth test is subjected to pixel shading processing to obtain a depth value after pixel shading processing. When the depth value after pixel shading processing is the depth value modified by the pixel shader, depth clamping processing is performed on the depth value to obtain a second target depth value of the fragment. Then, a delayed depth test is performed on the second target depth value according to the depth buffer updated by the first depth test result to obtain a second depth test result and a depth buffer updated by the second depth test result.

[0106] Therefore, depth clamping of depth values ​​is eliminated during primitive clipping or post-vertex transformation stages. Fragment-level depth clamping, rather than vertex-level modification, ensures the geometric correctness of perspective interpolation depth values, fundamentally eliminating artifacts such as shadow deviation and transparency sorting errors caused by vertex depth clamping, thus improving rendering accuracy and stability. Furthermore, in single-pass rendering mode, fragment depth clamping and early depth testing can be performed before pixel shading, allowing occluded fragments to be culled before pixel shading. This reduces expensive pixel shading calls and memory accesses, lowers overdraw and power consumption, and leverages the advantages of tile-based deferred rendering architecture in reducing memory access and computational redundancy, improving rendering efficiency and accuracy. Moreover, it also allows for depth value modification even when the pixel shader is modified. The method performs depth clamping and deferred depth testing on fragment depth values, which forces the depth values ​​output by the pixel shader to always be clamped, ensuring that the fragment depth values ​​are within the viewport depth range. This guarantees the stability and consistency of depth values, reduces the probability of undefined behavior during rendering, and improves the stability and consistency of rendering. Furthermore, in the tile-based deferred rendering architecture, advance depth testing can be implemented, allowing occluded fragments to be culled before pixel shading. This reduces expensive pixel shading calls and memory accesses, lowers overdraw and power consumption, and ensures that the tile-based deferred rendering architecture reduces memory access and computational redundancy. This improves the rendering efficiency and accuracy of tile-based deferred rendering and also prevents tile data corruption caused by abnormal depth values, achieving hardware-level safety and optimization.

[0107] Figure 4 This is a flowchart of a fragment depth clamping method provided in an embodiment of this disclosure, which can be executed by a graphics processor located within a computer device. Figure 3 As shown, the fragment depth clamping method provided in this embodiment includes the following steps 410-470.

[0108] Step 410: After the rasterization stage and before the depth test, obtain the depth value of the fragment.

[0109] Step 420: When the fragment depth value is of type interpolated depth value generated during the rasterization stage, the current rendering condition is the first channel in the dual-channel rendering mode and the depth clamping function is enabled, perform depth clamping processing on the fragment depth value to obtain the third target depth value of the fragment.

[0110] In this embodiment of the disclosure, when the type of the fragment depth value is the interpolated depth value generated during the rasterization stage, the current rendering condition is the first channel in the dual-channel rendering mode, and the depth clamping function is enabled, the graphics processor in the computer device can perform depth clamping processing on the fragment depth value to obtain the third target depth value of the fragment.

[0111] Dual-channel rendering mode can be understood as a rendering mode in which, during a single rendering process, the same group or related primitives are rendered sequentially through two rendering channels (the first channel and the second channel) that are distinguished in time or logic.

[0112] In dual-channel rendering mode, the first channel can be understood as the rendering channel that is executed before the second channel. It is used to perform the initial rendering processing of fragments and generate the corresponding fragment processing results.

[0113] In some embodiments, a type flag corresponding to the depth value of a fragment can be obtained; if the type flag corresponding to the depth value is an interpolation flag, it can be determined that the type of the depth value of the fragment is an interpolation depth value generated during the rasterization stage.

[0114] In some embodiments, the current rendering mode flag, the current rendering channel flag, and the current depth clamp flag can be obtained; if the rendering mode flag is a dual-channel mode flag, the rendering channel flag is a first channel flag, and the depth clamp flag is an enabled flag, the rendering condition is determined to be the first channel in the dual-channel rendering mode and the depth clamp function is enabled.

[0115] The rendering pass flags can include either a first pass flag or a second pass flag. For example, the first pass flag can be 1st_pass; the second pass flag can be 2nd_psss.

[0116] For example, if the rendering mode flag is set to the two-pass mode flag (two_pass), the rendering channel flag is set to the first channel flag (1st_pass), and the depth clamp flag is set to the enable flag (depthclamp_en==TRUE), it can be determined that the rendering condition is the first channel in the two-pass rendering mode and the depth clamp function is enabled.

[0117] Therefore, the type of fragment depth value can be accurately determined by the type flag corresponding to the depth value, and the rendering conditions can be accurately determined by the rendering mode flag and the depth clamp flag.

[0118] Step 430: Perform an advance depth test on the third target depth value to obtain the third depth test result, and determine whether to retain the fragment corresponding to the third target depth value based on the third depth test result.

[0119] In this embodiment of the disclosure, after performing depth clamping processing on the interpolated depth values ​​of the fragments generated in the rasterization stage to obtain a third target depth value for the fragments, the graphics processor in the computer device can perform an advance depth test on the third target depth value to obtain a third depth test result, and determine whether to retain the fragment corresponding to the third target depth value based on the third depth test result. Thus, an advance depth test can be performed on the interpolated depth values ​​of the fragments generated in the rasterization stage to obtain a third depth test result.

[0120] In some embodiments, in the first channel of the dual-channel rendering mode, after performing a preliminary depth test on the third target depth value and obtaining the third depth test result, the image processor can end the rendering process of the fragment and directly output the third depth test result.

[0121] Step 440: When the fragment depth value is of type interpolated depth value generated during the rasterization stage, the current rendering condition is the second channel in the dual-channel rendering mode, and the depth clamping function is enabled, perform depth clamping processing on the fragment depth value to obtain the fourth target depth value of the fragment.

[0122] In this embodiment of the disclosure, when the type of the fragment depth value is the interpolated depth value generated during the rasterization stage, the current rendering condition is the second channel in the dual-channel rendering mode, and the depth clamping function is enabled, the graphics processor in the computer device can perform depth clamping processing on the fragment depth value to obtain the fourth target depth value of the fragment.

[0123] In dual-channel rendering mode, the second channel can be understood as the rendering channel that is executed after the first channel. It is used to further process fragments based on the rendering of the first channel.

[0124] In some embodiments, the type flag corresponding to the depth value of a fragment can be obtained; if the type flag corresponding to the depth value is an interpolation flag, the type of the depth value of the fragment can be determined to be an interpolation depth value.

[0125] In some embodiments, the current rendering mode flag, the current rendering channel flag, and the current depth clamp flag can be obtained; if the rendering mode flag is a dual-channel mode flag, the rendering channel flag is a second channel flag, and the depth clamp flag is an enabled flag, it is determined that the rendering condition is the second channel in the dual-channel rendering mode and the depth clamp function is enabled.

[0126] For example, if the second rendering mode flag is the two-pass mode flag two_pass, the second rendering channel flag is the second channel flag 2nd_psss, and the second depth clamp flag is the enable flag depthclamp_en==TRUE, it can be determined that the second rendering condition is the second channel in the two-pass rendering mode and the depth clamp function is enabled.

[0127] Therefore, the type of fragment depth value can be accurately determined by the type flag corresponding to the depth value, and the rendering conditions can be accurately determined by the rendering mode flag and the depth clamp flag.

[0128] Step 450: Based on the third depth test result, perform an advance depth test on the fourth target depth value to obtain the fourth depth test result, and determine whether to retain the fragment corresponding to the fourth target depth value based on the fourth depth test result.

[0129] In this embodiment of the disclosure, after obtaining the third depth test result and the fourth target depth value of the fragment, the graphics processor in the computer device can perform a depth test on the fourth target depth value based on the third depth test result to obtain the fourth depth test result, and determine whether to retain the fragment corresponding to the fourth target depth value based on the fourth depth test result. Thus, the depth value of the fragment can be pre-tested based on the third depth test result to obtain the fourth depth test result.

[0130] Step 460: When the fragment's depth value is of type Pixel Shader Modified Depth Value and the current rendering condition is the second channel in Dual-Channel Rendering Mode, perform Depth Clamping on the depth value to obtain the fifth target depth value of the fragment.

[0131] In this embodiment of the disclosure, when the type of the fragment's depth value is the pixel shader-modified depth value and the current rendering condition is the second channel in the dual-channel rendering mode, the graphics processor can perform depth clamping processing on the pixel shader-modified depth value to obtain the fifth target depth value of the fragment.

[0132] The modified depth value of the pixel shader can be understood as the depth value of the fragment output by the pixel shader after modifying the interpolated depth value of the fragment during the pixel shading process.

[0133] In some embodiments, the graphics processor in the computer device can obtain the current rendering mode flag, the current rendering channel flag, and the current depth clamp flag; if the rendering mode flag is a dual-channel mode flag and the rendering channel flag is a second channel flag, the current rendering condition is determined to be the second channel in the dual-channel rendering mode.

[0134] Step 470: Based on the fourth depth test result, perform a delayed depth test on the fifth target depth value to obtain the fifth depth test result, and determine whether to retain the fragment corresponding to the fifth target depth value based on the fifth depth test result.

[0135] In this embodiment of the disclosure, after obtaining the fourth depth test result and the fifth target depth value, the graphics processor can perform a delayed depth test on the fifth target depth value based on the fourth depth test result to obtain the fifth depth test result, and determine whether to retain the fragment corresponding to the fifth target depth value based on the fifth depth test result. Thus, depth clamping can be applied to the depth value modified by the pixel shader to obtain the fifth target depth value, and a delayed depth test can be performed on the fifth target depth value based on the fourth depth test result after the advance depth test to obtain the fifth depth test result.

[0136] In some embodiments, steps 410-470 may include S21-S30.

[0137] S21. After the rasterization stage and before the depth test, obtain the depth value of the fragment.

[0138] S22. When the fragment depth value is of type interpolated depth value generated during the rasterization stage, the current rendering condition is the first channel in the dual-channel rendering mode, and the depth clamping function is enabled, perform depth clamping processing on the fragment depth value to obtain the third target depth value of the fragment.

[0139] S23. Compare the third target depth value with the third buffer depth value corresponding to the third pixel position in the current depth buffer to obtain the third depth test result, where the third pixel position is the pixel position to which the third target depth value belongs.

[0140] S24. If the third depth test result is that the third target depth value is less than the third buffer depth value, update the third buffer depth value in the current depth buffer to the third target depth value, and determine the updated current depth buffer as the third depth buffer; if the third depth test result is that the third target depth value is greater than or equal to the third buffer depth value, delete the fragment corresponding to the third target depth value.

[0141] In this embodiment of the disclosure, when the third target depth value is less than the third buffer depth value, it means that the fragment corresponding to the third target depth value is in front of the fragment corresponding to the third buffer depth value, and the fragment corresponding to the third buffer depth value is occluded by the fragment corresponding to the third target depth value. Therefore, the third buffer depth value in the current depth buffer can be updated to the third target depth value, and the updated current depth buffer can be determined as the third depth buffer.

[0142] If the third target depth value is greater than the third buffer depth value, it means that the fragment corresponding to the third target depth value is behind the fragment corresponding to the third buffer depth value, and the fragment corresponding to the third target depth value is occluded by the fragment corresponding to the third buffer depth value. Therefore, the fragment corresponding to the third target depth value can be deleted.

[0143] If the third target depth value is equal to the third buffer depth value, it means that the fragment corresponding to the third target depth value coincides with the fragment corresponding to the third buffer depth value, so the fragment corresponding to the third target depth value can be deleted.

[0144] S25. When the fragment depth value is of type interpolated depth value generated during the rasterization stage, the current rendering condition is the second channel in the dual-channel rendering mode, and the depth clamping function is enabled, perform depth clamping processing on the fragment depth value to obtain the fourth target depth value of the fragment.

[0145] S26. Compare the fourth target depth value with the fourth buffer depth value corresponding to the fourth pixel position in the third depth buffer to obtain the fourth depth test result, where the fourth pixel position is the pixel position to which the fourth target depth value belongs.

[0146] S27. If the fourth depth test result is that the fourth target depth value is less than the fourth buffer depth value, update the fourth buffer depth value in the third depth buffer to the fourth target depth value, and determine the updated third depth buffer as the fourth depth buffer; if the fourth depth test result is that the fourth target depth value is greater than or equal to the fourth buffer depth value, delete the fragment corresponding to the fourth target depth value.

[0147] In this embodiment of the disclosure, when the fourth target depth value is less than the fourth buffer depth value, it means that the fragment corresponding to the fourth target depth value is in front of the fragment corresponding to the fourth buffer depth value, and the fragment corresponding to the fourth buffer depth value is occluded by the fragment corresponding to the fourth target depth value. Therefore, the fourth buffer depth value in the third depth buffer can be updated to the fourth target depth value, and the updated third depth buffer can be determined as the fourth depth buffer.

[0148] If the fourth target depth value is greater than the fourth buffer depth value, it means that the fragment corresponding to the fourth target depth value is behind the fragment corresponding to the fourth buffer depth value, and the fragment corresponding to the fourth target depth value is occluded by the fragment corresponding to the fourth buffer depth value. Therefore, the fragment corresponding to the fourth target depth value can be deleted.

[0149] If the fourth target depth value is equal to the fourth buffer depth value, it means that the fragment corresponding to the fourth target depth value coincides with the fragment corresponding to the fourth buffer depth value. Therefore, the fragment corresponding to the fourth target depth value can be deleted.

[0150] S28. When the type of the fragment's depth value is the pixel shader modified depth value and the current rendering condition is the second channel in the dual-channel rendering mode, perform depth clamping processing on the depth value to obtain the fifth target depth value of the fragment.

[0151] S29. Compare the fifth target depth value with the fifth buffer depth value corresponding to the fifth pixel position in the fourth depth buffer to obtain the fifth depth test result, where the fifth pixel position is the pixel position to which the fifth target depth value belongs.

[0152] S30. If the fifth depth test result shows that the fifth target depth value is less than the fifth buffer depth value, update the fifth buffer depth value in the fourth depth buffer to the fifth target depth value, and determine the updated fourth depth buffer as the fifth depth buffer; if the fifth depth test result shows that the fifth target depth value is greater than or equal to the fifth buffer depth value, delete the fragment corresponding to the fifth target depth value.

[0153] In this embodiment of the disclosure, when the fifth target depth value is less than the fifth buffer depth value, it means that the fragment corresponding to the fifth target depth value is in front of the fragment corresponding to the fifth buffer depth value, and the fragment corresponding to the fifth buffer depth value is occluded by the fragment corresponding to the fifth target depth value. Therefore, the fifth buffer depth value in the fourth depth buffer can be updated to the fifth target depth value, and the updated fourth depth buffer can be determined as the fifth depth buffer.

[0154] If the fifth target depth value is greater than the fifth buffer depth value, it means that the fragment corresponding to the fifth target depth value is behind the fragment corresponding to the fifth buffer depth value, and the fragment corresponding to the fifth target depth value is occluded by the fragment corresponding to the fifth buffer depth value. Therefore, the fragment corresponding to the fifth target depth value can be deleted.

[0155] If the fifth target depth value is equal to the fifth buffer depth value, it means that the fragment corresponding to the fifth target depth value coincides with the fragment corresponding to the fifth buffer depth value, so the fragment corresponding to the fifth target depth value can be deleted.

[0156] In this embodiment, after generating the interpolated depth value of the fragment during the rasterization stage, the interpolated depth value of the fragment is first depth-clamped in the first channel of the dual-channel rendering mode to obtain a third target depth value of the fragment. Then, an advance depth test is performed on the third target depth value to obtain a third depth test result and a depth buffer updated by the third depth test result. Then, the interpolated depth value of the fragment is depth-clamped in the second channel of the dual-channel rendering mode to obtain a fourth target depth value. Then, based on the depth buffer updated by the third depth test result, an advance depth test is performed on the fourth target depth value to obtain a fourth depth test result and a depth buffer updated by the fourth depth test result. Then, based on the pixel shader, the fourth target depth value that passed the depth test is pixel-shaded to obtain a pixel-shaded depth value. When the pixel-shaded depth value is the depth value modified by the pixel shader, the pixel-shaded depth value is depth-clamped to obtain a fifth target depth value of the fragment. Then, a delayed depth test is performed on the fifth target depth value to obtain a fifth depth test result. Based on the fifth depth test result, it is determined whether to retain the fragment corresponding to the fifth target depth value.

[0157] Therefore, depth clamping of depth values ​​is eliminated during primitive clipping or post-vertex transformation stages. Fragment-level depth clamping, rather than vertex-level modification, ensures the geometric correctness of perspective interpolated depth values, fundamentally eliminating artifacts such as shadow deviation and transparency sorting errors caused by vertex depth clamping, thus improving rendering accuracy. Furthermore, in the first channel of the dual-channel rendering mode, depth clamping and early depth testing can be performed on the interpolated depth values ​​generated during the rasterization stage to obtain the third depth test result and the depth buffer updated by the third depth test result. Then, in the second channel of the dual-channel rendering mode, depth clamping is performed on the interpolated depth values ​​generated during the rasterization stage, and early depth testing is performed on the interpolated depth values ​​after depth clamping based on the depth buffer updated by the third depth test result. This allows for the early culling of occluded fragments before pixel shading, thereby reducing expensive pixel shading calls and memory accesses, reducing overdraw and power consumption, and improving the tile-based deferred rendering architecture by reducing memory access and computational redundancy. Advantages include improved rendering efficiency and accuracy; furthermore, in the second channel of the dual-channel rendering mode, after pixel shading of fragments after pre-tested depth, depth clamping and deferred depth testing are performed on the fragment depth values ​​when the pixel shader modifies the depth values. This forces the depth values ​​output by the pixel shader to always be clamped, ensuring that the fragment depth values ​​are within the viewport depth range, guaranteeing the stability and consistency of depth values, reducing the probability of undefined behavior during rendering, and improving rendering stability and consistency. Moreover, in the tile-based deferred rendering architecture, pre-testing can be implemented, allowing occluded fragments to be culled before pixel shading, thereby reducing expensive pixel shading calls and memory accesses, reducing overdraw and power consumption, ensuring the advantages of tile-based deferred rendering architecture in reducing memory access and computational redundancy, improving the rendering efficiency and accuracy of tile-based deferred rendering, and preventing tile data corruption caused by abnormal depth values, achieving hardware-level safety and optimization.

[0158] For example, Figure 5 This is another type of tile-based deferred rendering flowchart, such as Figure 5 As shown, the tile-based deferred rendering process includes the following steps: after the geometric data of the graphics undergoes vertex processing, clipping, projection and culling, tile partitioning, and rasterization, the interpolated depth values ​​of the fragments generated in the rasterization stage can be processed by depth clamping. Then, hidden face removal and depth testing, label buffer processing (recording which fragment corresponds to each pixel position), texture sampling and shading, transparency testing, transparency blending, and other processing are performed. Finally, the final result of the on-chip color buffer is written back to the frame buffer in system memory.

[0159] Therefore, in the tile-based deferred rendering process, depth testing can be performed in advance, and occluded fragments can be removed before pixel shading, thereby reducing expensive pixel shading calls and memory accesses, reducing overdraw and power consumption, ensuring the advantages of tile-based deferred rendering architecture in reducing memory access and computational redundancy, improving the rendering efficiency and accuracy of tile-based deferred rendering, and preventing tile data chaos caused by abnormal depth values, thus achieving hardware-level safety and optimization.

[0160] In some embodiments, the graphics processor in the computer device can obtain a type flag corresponding to the depth value of a fragment; if the type flag corresponding to the depth value is an interpolation flag, the type of the depth value is determined to be an interpolated depth value generated during the rasterization stage; if the type flag corresponding to the depth value is a non-interpolation flag, the type of the depth value is determined to be a depth value modified by the pixel shader.

[0161] In some embodiments, the graphics processor in the computer device can obtain the current rendering mode flag, the current rendering channel flag, and the current depth clamp flag; if the rendering mode flag is a single-channel mode flag and the depth clamp flag is enabled, it determines that the current rendering condition is a single-channel rendering mode and the depth clamp function is enabled; if the rendering mode flag is a dual-channel mode flag, the rendering channel flag is a first channel flag, and the depth clamp flag is enabled, it determines that the current rendering condition is the first channel in the dual-channel rendering mode and the depth clamp function is enabled; if the rendering mode flag is a dual-channel mode flag, the rendering channel flag is a second channel flag, and the depth clamp flag is enabled, it determines that the current rendering condition is the second channel in the dual-channel rendering mode and the depth clamp function is enabled; if the rendering mode flag is a dual-channel mode flag and the rendering channel flag is a second channel flag, it determines that the current rendering condition is the second channel in the dual-channel rendering mode.

[0162] Therefore, the type of fragment depth value can be accurately determined by the type flag corresponding to the depth value, and the rendering conditions can be accurately determined by the rendering mode flag and the depth clamp flag.

[0163] In some embodiments of this disclosure, the depth value of the fragment is depth-clamped as described above to obtain the target depth value of the fragment, which can be executed by the graphics processor in the computer device. Figure 6 A flowchart of a fragment depth clamping method is provided, such as... Figure 6 As shown, the fragment depth clamping method provided in this embodiment includes the following steps 610-630.

[0164] Step 610: Normalize the depth value of the fragment to obtain the normalized depth value corresponding to the depth value of the fragment.

[0165] In this embodiment of the disclosure, after obtaining the depth value of the fragment, the graphics processor in the computer device can normalize the depth value of the fragment using a special number normalizer, mapping the depth value to the depth value range corresponding to the current depth buffer, and obtaining the normalized depth value corresponding to the depth value.

[0166] The depth buffer can be understood as a dedicated storage area for storing the depth value corresponding to each pixel position. The depth values ​​in the depth buffer are used to perform depth comparisons during the graphics rendering process to determine the occlusion relationship between different geometric fragments.

[0167] For example, the depth value range corresponding to the depth buffer can be [+0.0, +1.0].

[0168] In this context, the minimum depth value in the depth value range corresponding to the depth buffer represents the depth closest to the observer, and the maximum depth value in the depth value range corresponding to the depth buffer represents the depth farthest from the observer.

[0169] In some embodiments, the above-described normalization process for the depth value to obtain the normalized depth value corresponding to the depth value may include steps 6101-6104.

[0170] Step 6101: Perform floating-point special value detection on the depth value to obtain the numerical type of the depth value.

[0171] In this embodiment of the disclosure, the graphics processor in the computer device can perform floating-point special value detection on the depth value to obtain the numerical type of the depth value.

[0172] Step 6102: When the numerical type of the depth value is the target type, determine the minimum depth value in the depth value interval corresponding to the current depth buffer as the normalized depth value corresponding to the depth value. The target type includes at least one of the following: non-number, non-normalized number, and negative infinity.

[0173] In this embodiment of the disclosure, when the numerical type of the depth value is a target type, the graphics processor can determine the minimum depth value in the depth value interval corresponding to the current depth buffer as the normalized depth value corresponding to that depth value. The target type can include at least one of Not a Number (NaN), denormalized number, and negative infinity (-Inf).

[0174] Step 6103: When the numerical type of the depth value is positive infinity, determine the maximum depth value in the depth value interval corresponding to the current depth buffer as the normalized depth value corresponding to the depth value.

[0175] In this embodiment of the disclosure, when the numerical type of the depth value is a positive infinity number (+Inf), the graphics processor can determine the maximum depth value in the depth value range corresponding to the current depth buffer as the normalized depth value corresponding to the depth value.

[0176] Step 6104: If the depth value is of normal floating-point type, determine the depth value as the normalized depth value corresponding to the depth value.

[0177] In this embodiment of the disclosure, when the numerical type of the depth value is a normal floating-point number, the graphics processor can determine the depth value as the normalized depth value corresponding to the depth value.

[0178] For example, if the depth value range corresponding to the depth buffer is [+0.0, +1.0]: when the numeric type of the depth value is NOT a number, the normalized depth value corresponding to the depth value is +0.0; when the numeric type of the depth value is a denormalized number, the normalized depth value corresponding to the depth value is +0.0; when the numeric type of the depth value is negative infinity, the normalized depth value corresponding to the depth value is +0.0; when the numeric type of the depth value is positive infinity, the normalized depth value corresponding to the depth value is +1.0; when the numeric type of the depth value is a normal floating-point number, the normalized depth value corresponding to the depth value is the depth value itself.

[0179] Therefore, by normalizing floating-point outliers, abnormal depth values ​​can be prevented from interfering with subsequent depth tests, effectively avoiding undefined behavior and hardware depth buffer overflow, ensuring the stability of depth values, and improving the robustness of depth values.

[0180] Step 620: Obtain the target viewport depth range corresponding to the fragment.

[0181] In this embodiment of the disclosure, the graphics processor in the computer device can obtain the target viewport depth range corresponding to the fragment.

[0182] The target viewport depth range can be understood as the depth range of the target viewport corresponding to the fragment.

[0183] The viewport depth range can be understood as the range of depth values ​​of the viewport. The viewport depth range can be the interval of depth values ​​composed of the minimum and maximum viewport depth values.

[0184] A viewport can be understood as the specific display area on the frame buffer (usually the screen) where a fragment or graphic is rendered. A viewport is usually a rectangular area. Simply put, the viewport tells the GPU "which area of ​​the screen to display the rendered image in".

[0185] The minimum viewport depth can be understood as the depth value of the near plane corresponding to the viewport.

[0186] The maximum viewport depth can be understood as the depth value of the far plane corresponding to the viewport.

[0187] In other words, the viewport depth range can be an interval consisting of the depth value of the near clipping plane corresponding to the viewport and the depth value of the far clipping plane corresponding to the viewport.

[0188] Step 630: Fit the normalized depth value to the target viewport depth range to generate the target depth value of the fragment.

[0189] In this embodiment of the disclosure, after obtaining the target viewport depth range corresponding to the fragment, the graphics processor in the computer device can clamp the normalized depth value of the fragment to the target viewport depth range to generate the target depth value of the fragment, that is, the target depth value is within the target viewport depth range.

[0190] For example, when the target viewport depth range is [+0.0, +1.0], the graphics processor can clamp the depth value to be processed to [+0.0, +1.0] and generate the target depth value of the fragment, that is, the target depth value is within the target viewport depth range [+0.0, +1.0].

[0191] In some embodiments, the above-described method of clamping the normalized depth value to the target viewport depth range to generate the target depth value of the fragment may include steps 6301-6304.

[0192] Step 6301: Read the minimum and maximum target viewport depth values ​​within the target viewport depth range.

[0193] Step 6302: If the normalized depth value is less than the minimum target viewport depth, clamp the normalized depth value to the minimum target viewport depth.

[0194] Step 6303: If the normalized depth value is greater than the maximum target viewport depth, clamp the normalized depth value to the maximum target viewport depth.

[0195] Step 6304: If the normalized depth value is between the minimum and maximum target viewport depth, the normalized depth value is determined as the target depth value of the fragment.

[0196] In this embodiment, by normalizing the depth value of a fragment, a normalized depth value corresponding to the fragment's depth value is obtained. This avoids abnormal depth values ​​interfering with subsequent depth testing, effectively prevents undefined behavior and hardware depth buffer overflow, ensures the stability of the depth value, and improves its robustness. The target viewport depth range corresponding to the fragment is obtained; the normalized depth value is clamped to the target viewport depth range to generate the target depth value of the fragment. This allows the depth value to be accurately clamped to the target viewport depth range corresponding to the fragment, improving the accuracy of depth clamping.

[0197] In related technologies, multi-viewport rendering requires rapid switching of viewport depth range, but the switching cost of viewport depth range in related architectures is high. In Virtual Reality (VR), Cascaded Shadow Map (CSM), and multi-viewport, frequent switching of viewport depth range requires resetting the pipeline, resulting in increased overhead.

[0198] To address the problem of switching viewport depth ranges in multi-viewport rendering scenes in related technologies, in some embodiments of this disclosure, the aforementioned depth clamping processing of fragment depth values ​​is performed to obtain the target depth value of the fragment, which can be executed by the graphics processor in the computer device. Figure 7 A flowchart of a fragment depth clamping method is provided, such as... Figure 7 As shown, the fragment depth clamping method provided in this embodiment includes the following steps 710-760.

[0199] Step 710: Normalize the depth value of the fragment to obtain the normalized depth value corresponding to the depth value of the fragment.

[0200] Step 720: Obtain the target viewport group identifier and target viewport identifier corresponding to the fragment.

[0201] In this embodiment of the present disclosure, the graphics processor in the computer device can read the target viewport group identifier and the target viewport identifier corresponding to the fragment from the control flow of the rendering pipeline according to the rendering state.

[0202] For example, the target viewport group identifier corresponding to a fragment can be determined based on the viewport group configuration associated with the rendering channel corresponding to the fragment; the target viewport identifier corresponding to a fragment can be determined based on the viewport index information associated with the primitive that generates the fragment.

[0203] The viewport group identifier (vptgroup_id) can be understood as identification information that can uniquely identify the viewport register group.

[0204] The target viewport group identifier can be understood as the identification information that can uniquely identify the target viewport register group.

[0205] The viewport identifier (vpt_id) can be understood as identification information that can uniquely determine the viewport depth range register.

[0206] The target viewport identifier can be understood as the identification information that can uniquely determine the target viewport depth range register.

[0207] Step 730: In a preset number of viewport register groups, determine the target viewport register group corresponding to the target viewport group identifier. Each viewport register group includes multiple viewport depth range registers, and each viewport depth range register stores a viewport depth range.

[0208] In this embodiment of the disclosure, the computer device is pre-configured with multiple viewport register groups. Each viewport register group may include multiple viewport depth range registers (REG_VPT_ZRANGE). Each viewport depth range register stores a viewport depth range, which may include a minimum viewport depth (vpt_zmin) and a maximum viewport depth (vpt_zmax).

[0209] A register can be understood as a high-speed storage component inside a graphics processor used to temporarily store instructions, data, and addresses.

[0210] The preset quantity can be set as needed, for example, 2, but there is no limit here.

[0211] For example, Figure 8 This is a schematic diagram of a viewport register set, such as... Figure 8As shown, when the preset quantity is 2, two viewport register groups are pre-configured in the viewport register group 800 within the computer device, named viewport register group 0 (vptgroup0) and viewport register group 1 (vptgroup1), respectively; the viewport group identifier of viewport register group 0 is 0; the viewport group identifier of viewport register group 1 is 1; each viewport register group includes 16 64-bit viewport depth range registers, wherein viewport register group 0 includes the viewport depth range register 0 (REG_VPT_ Viewport register group 1 comprises 16 viewport depth range registers, from viewport depth range register 15 (REG_VPT_ZRANGE15) to viewport depth range register 16 (REG_VPT_ZRANGE16) to viewport depth range register 31 (REG_VPT_ZRANGE31). Each viewport depth range register stores a viewport depth range, which may include a minimum viewport depth (vpt_zmin 32-bit LSB) and a maximum viewport depth (vpt_zmax 32-bit MSB). The storage format for the minimum and maximum viewport depths can be fp32 (32-bit FloatingPoint) format, with the lower 32 significant bits used to store the minimum viewport depth (vpt_zmin 32-bit LSB) and the higher 32 significant bits used to store the maximum viewport depth (vpt_zmax 32-bit MSB).

[0212] REG_VPT_ZRANGE stands for Register Viewport Z Range, which represents the viewport depth range register.

[0213] LSB stands for Least Significant Bit, representing the least significant bit.

[0214] MSB stands for Most Significant Bit, representing the most significant bit.

[0215] The fp32 format can be understood as a binary format for representing real numbers in a computer. It uses 32 bits (4 bytes) to store a number, and its structure consists of three parts: 1 sign bit (indicating positive or negative), 8 exponent bits (determining the range of values), and 23 mantissa bits (determining precision).

[0216] In this embodiment of the present disclosure, after obtaining the target viewport group identifier and the target viewport identifier corresponding to the fragment, the graphics processor in the computer device can select the target viewport register group corresponding to the target viewport group identifier from a preset number of viewport register groups.

[0217] Step 740: In the target viewport register group, determine the target viewport depth range register corresponding to the target viewport identifier.

[0218] In this embodiment of the disclosure, there is a one-to-one correspondence between viewport identifiers and viewport depth range registers in the computer device. The graphics processor in the computer device can select the target viewport depth range register corresponding to the target viewport identifier from the target viewport register group corresponding to the target viewport group identifier.

[0219] The target viewport depth range register can be understood as the viewport depth range register corresponding to the target viewport.

[0220] Continuing with the above Figure 8 For example, if the target viewport group identifier is 0 (vptgroup_id=0) and the target viewport identifier is 3 (vpt_id=3), then the target viewport register group corresponding to the target viewport group identifier 0 is the viewport register group 0. In the viewport register group 0, the viewport depth range register 2 (REG_VPT_ZRANGE2) corresponding to the viewport identifier 3 is selected as the target viewport depth range register.

[0221] Continuing with the above Figure 8 For example, if the target viewport group identifier is 1 (vptgroup_id=1) and the target viewport identifier is 3 (vpt_id=3), then the target viewport register group corresponding to the target viewport group identifier 1 is the viewport register group 1. In the viewport register group 1, the viewport depth range register 18 (REG_VPT_ZRANGE18) corresponding to the target viewport identifier 3 is selected as the target viewport depth range register.

[0222] Step 750: Determine the viewport depth range in the target viewport depth range register as the target viewport depth range corresponding to the fragment.

[0223] In this embodiment of the disclosure, after obtaining the target viewport depth range register corresponding to the fragment, the graphics processor in the computer device can read the viewport depth range in the target viewport depth range register and determine the viewport depth range in the target viewport depth range register as the target viewport depth range corresponding to the fragment. The target viewport depth range may include a minimum target viewport depth and a maximum target viewport depth.

[0224] Step 760: Fit the normalized depth value to the target viewport depth range to generate the target depth value of the fragment.

[0225] In this embodiment, by normalizing the depth value of a fragment, a normalized depth value is obtained. This avoids abnormal depth values ​​from interfering with subsequent depth clamping and depth testing, effectively preventing undefined behavior and hardware depth buffer overflow, ensuring the stability of the depth value, improving its robustness, and enhancing the accuracy and reliability of subsequent depth clamping and depth testing. By using the target viewport group identifier and target viewport identifier corresponding to the fragment, the target viewport depth range corresponding to the fragment can be accurately and quickly determined. The normalized depth value is clamped to the target viewport depth range to generate the fragment's depth value. The target depth value can be accurately clamped to the target viewport depth range corresponding to the fragment, improving the accuracy of depth clamping. Furthermore, by determining and reading the corresponding viewport depth range from the preset viewport register group based on the viewport group identifier and viewport identifier corresponding to the fragment in a single draw call, without resetting the pipeline or re-initiating the draw call, the overhead of switching viewport depth ranges in multi-viewport rendering is reduced, enabling fast switching of multi-viewport depth ranges and providing the ability to quickly switch depth ranges in a single rendering, thereby improving rendering efficiency and performance in multi-viewport scenes.

[0226] In some embodiments of this disclosure, before determining the target viewport register group corresponding to the target viewport group identifier among a preset number of viewport register groups, the graphics processor in the computer device may execute... Figure 9 A flowchart of a fragment depth clamping method is provided, such as... Figure 9 As shown, the fragment depth clamping method provided in this embodiment includes the following steps 910-930.

[0227] Step 910: Before generating fragments in the rasterization stage, configure the rendering state, which includes the viewport depth range and viewport identifier for each viewport.

[0228] In this embodiment of the disclosure, before generating fragments in the rasterization stage, the graphics processor in the computer device can configure the rendering state, which may include the viewport depth range and viewport identifier for each viewport.

[0229] Step 920: For each viewport identifier, configure the viewport depth range register corresponding to the viewport identifier and write the viewport depth range corresponding to the viewport identifier into the viewport depth range register corresponding to the viewport identifier.

[0230] Step 930: According to the preset grouping rules, group the viewport depth range registers corresponding to multiple viewport identifiers to obtain a preset number of viewport register groups, and configure the viewport group identifier corresponding to each viewport register group.

[0231] Preset grouping rules can be set as needed; no restrictions are imposed here.

[0232] This embodiment of the disclosure configures the viewport depth range, viewport identifier, viewport depth range register corresponding to each viewport, a preset number of viewport register groups, and a viewport group identifier corresponding to each viewport register group. This enables the accurate and rapid determination of the target viewport depth range corresponding to a fragment using the target viewport group identifier and target viewport identifier. The normalized depth value is clamped to the target viewport depth range, generating the target depth value for the fragment. This accurately clamps the depth value to the target viewport depth range corresponding to the fragment, improving the accuracy of depth clamping. Furthermore, by determining and reading the corresponding viewport depth range from the preset viewport register group based on the viewport group identifier and viewport identifier corresponding to the fragment in a single rendering call, without reconfiguring the rendering state or re-initiating the rendering call, the call overhead and state switching overhead in multi-viewport rendering are reduced. This achieves rapid switching of multi-viewport depth ranges and provides the ability to quickly switch depth ranges in a single rendering.

[0233] Figure 10 This is a schematic diagram of a fragment depth clamping device provided in an embodiment of this disclosure. This device can be understood as the aforementioned computer device or a functional module within the aforementioned computer device. For example... Figure 10 As shown, the fragment depth clamping device 1000 includes the following modules.

[0234] The acquisition module 1010 is used to acquire the depth value of the fragment after the rasterization stage and before the depth test.

[0235] The first depth clamping module 1020 is used to perform depth clamping processing on the depth value to obtain the target depth value of the fragment.

[0236] The depth testing module 1030 is used to perform a depth test on the target depth value in order to determine whether to retain the fragment based on the depth test results.

[0237] The fragment depth clamping device provided in this disclosure can implement the method of any of the above embodiments, and its execution mode and beneficial effects are similar, so they will not be described again here.

[0238] This disclosure also provides a computer device, which includes a processor and a memory, wherein the memory stores a computer program. When the computer program is executed by the processor, it can implement the methods of any of the above embodiments. The execution method and beneficial effects are similar, and will not be described again here.

[0239] The computer device in this disclosure can be understood as any device with processing and computing capabilities, including but not limited to electronic devices such as smartphones, laptops, personal digital assistants (PDAs), tablet computers (PADs), portable multimedia players (PMPs), in-vehicle terminals, wearable devices, digital TVs, desktop computers, smart home devices, etc.

[0240] Figure 11 This is a schematic diagram of the structure of a computer device provided in an embodiment of this disclosure, such as... Figure 11 As shown, the computer device 1100 may include a processor 1110 and a memory 1120. The memory 1120 stores a computer program 1121. When the computer program 1121 is executed by the processor 1110, it can implement the method provided in any of the above embodiments. The execution mode and beneficial effects are similar and will not be described again here.

[0241] Of course, for the sake of simplicity, Figure 11 Only some of the components of the computer device 1100 relevant to the present invention are shown in this illustration; components such as buses, input / output interfaces, input devices, and output devices are omitted. In addition, the computer device 1100 may include any other suitable components depending on the specific application.

[0242] This disclosure provides a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, it can implement the methods of any of the above embodiments. The execution method and beneficial effects are similar, and will not be described again here.

[0243] The aforementioned computer-readable storage medium may be any combination of one or more readable media. A readable medium may be a readable signal medium or a readable storage medium. A readable storage medium may, for example, include, but is not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatuses, or devices, or any combination thereof. More specific examples of readable storage media (a non-exhaustive list) include: electrical connections having one or more wires, portable disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.

[0244] The computer program described above can be written in any combination of one or more programming languages ​​to perform the operations of the embodiments of this disclosure. The programming languages ​​include object-oriented programming languages ​​such as Java and C++, as well as conventional procedural programming languages ​​such as C or similar languages. The program code can be executed entirely on the user's computer device, partially on the user's device, as a standalone software package, partially on the user's computer device and partially on a remote computer device, or entirely on a remote computer device or server.

[0245] The above description is merely a preferred embodiment of this disclosure and an explanation of the technical principles employed. Those skilled in the art should understand that the scope of this disclosure is not limited to technical solutions formed by specific combinations of the above-described technical features, but should also cover other technical solutions formed by arbitrary combinations of the above-described technical features or their equivalents without departing from the above-described concept. For example, technical solutions formed by substituting the above features with (but not limited to) technical features disclosed in this disclosure that have similar functions.

[0246] Furthermore, while the operations are described in a specific order, this should not be construed as requiring these operations to be performed in the specific order shown or in a sequential order. In certain environments, multitasking and parallel processing may be advantageous. Similarly, while several specific implementation details are included in the above discussion, these should not be construed as limiting the scope of this disclosure. Certain features described in the context of individual embodiments may also be implemented in combination in a single embodiment. Conversely, various features described in the context of a single embodiment may also be implemented individually or in any suitable sub-combination in multiple embodiments.

[0247] The above description is merely a specific embodiment of this disclosure, enabling those skilled in the art to understand or implement it. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this disclosure. Therefore, this disclosure is not to be limited to the embodiments described herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A fragment depth clamping method, characterized in that, include: After the rasterization stage and before the depth test, obtain the depth value of the fragment; The depth value is subjected to depth clamping processing to obtain the target depth value of the fragment; A depth test is performed on the target depth value to determine whether to retain the fragment based on the depth test result; wherein, the step of performing depth clamping processing on the depth value to obtain the target depth value of the fragment includes: when the type of the depth value is an interpolated depth value generated during the rasterization stage, the current rendering condition is a single-channel rendering mode, and the depth clamping function is enabled, performing depth clamping processing on the depth value to obtain a first target depth value of the fragment; when the type of the depth value is a depth value modified by the pixel shader, the current rendering condition is a single-channel rendering mode, and the depth clamping function is enabled, performing depth clamping processing on the depth value to obtain a second target depth value of the fragment; The step of performing depth clamping processing on the depth value to obtain the target depth value of the fragment includes: acquiring the target viewport group identifier and the target viewport identifier corresponding to the fragment; determining the target viewport register group corresponding to the target viewport group identifier from a preset number of viewport register groups; determining the target viewport depth range register corresponding to the target viewport identifier from the target viewport register group, and determining the viewport depth range in the target viewport depth range register as the target viewport depth range corresponding to the fragment; clamping the depth value to the target viewport depth range to generate the target depth value of the fragment.

2. The method according to claim 1, characterized in that, The step of performing a depth test on the target depth value to determine whether to retain the fragment based on the depth test result includes: Perform an advance depth test on the first target depth value to obtain a first depth test result, and determine whether to retain the fragment corresponding to the first target depth value based on the first depth test result; Based on the first depth test result, a delayed depth test is performed on the second target depth value to obtain a second depth test result, and based on the second depth test result, it is determined whether to retain the fragment corresponding to the second target depth value.

3. The method according to claim 2, characterized in that, The step of performing an advance depth test on the first target depth value to obtain a first depth test result, and determining whether to retain the fragment corresponding to the first target depth value based on the first depth test result, includes: The first target depth value is compared with the first buffer depth value corresponding to the first pixel position in the current depth buffer to obtain the first depth test result, wherein the first pixel position is the pixel position to which the first target depth value belongs; If the first depth test result is that the first target depth value is less than the first buffer depth value, the first buffer depth value in the current depth buffer is updated to the first target depth value, and the updated current depth buffer is determined as the first depth buffer. If the first depth test result indicates that the first target depth value is greater than or equal to the first buffer depth value, delete the fragment corresponding to the first target depth value.

4. The method according to claim 3, characterized in that, The step of performing a delayed depth test on the second target depth value based on the first depth test result to obtain a second depth test result, and determining whether to retain the fragment corresponding to the second target depth value based on the second depth test result, includes: The second target depth value is compared with the second buffer depth value corresponding to the second pixel position in the first depth buffer to obtain the second depth test result, wherein the second pixel position is the pixel position to which the second target depth value belongs; If the second depth test result is that the second target depth value is less than the second buffer depth value, the second buffer depth value in the first depth buffer is updated to the second target depth value, and the updated first depth buffer is determined as the second depth buffer. If the second depth test result indicates that the second target depth value is greater than or equal to the second buffer depth value, delete the fragment corresponding to the second target depth value.

5. The method according to claim 1, characterized in that, The process of performing depth clamping on the depth value to obtain the target depth value of the fragment includes: When the depth value is an interpolated depth value generated during the rasterization stage, the current rendering condition is the first channel in the dual-channel rendering mode, and the depth clamping function is enabled, the depth value is subjected to depth clamping processing to obtain the third target depth value of the fragment. When the depth value is an interpolated depth value generated during the rasterization stage, the current rendering condition is the second channel in the dual-channel rendering mode, and the depth clamping function is enabled, the depth value is subjected to depth clamping processing to obtain the fourth target depth value of the fragment. When the depth value is a pixel shader modified depth value and the current rendering condition is the second channel in the dual-channel rendering mode, the depth value is subjected to depth clamping processing to obtain the fifth target depth value of the fragment.

6. The method according to claim 5, characterized in that, The step of performing a depth test on the target depth value to determine whether to retain the fragment based on the depth test result includes: Perform an advance depth test on the third target depth value to obtain the third depth test result, and determine whether to retain the fragment corresponding to the third target depth value based on the third depth test result; Based on the third depth test result, an advance depth test is performed on the fourth target depth value to obtain the fourth depth test result, and it is determined whether to retain the fragment corresponding to the fourth target depth value based on the fourth depth test result. Based on the fourth depth test result, a delayed depth test is performed on the fifth target depth value to obtain the fifth depth test result, and it is determined whether to retain the fragment corresponding to the fifth target depth value based on the fifth depth test result.

7. The method according to claim 6, characterized in that, The step of performing a depth test on the third target depth value to obtain a third depth test result, and determining whether to retain the fragment corresponding to the third target depth value based on the third depth test result, includes: The third target depth value is compared with the third buffer depth value corresponding to the third pixel position in the current depth buffer to obtain the third depth test result, wherein the third pixel position is the pixel position to which the third target depth value belongs; If the third depth test result is that the third target depth value is less than the third buffer depth value, the third buffer depth value in the current depth buffer is updated to the third target depth value, and the updated current depth buffer is determined as the third depth buffer. If the result of the third depth test is that the third target depth value is greater than or equal to the third buffer depth value, the fragment corresponding to the third target depth value is deleted.

8. The method according to claim 7, characterized in that, The step of performing a depth test on the fourth target depth value based on the third depth test result to obtain a fourth depth test result, and determining whether to retain the fragment corresponding to the fourth target depth value based on the fourth depth test result, includes: The fourth target depth value is compared with the fourth buffer depth value corresponding to the fourth pixel position in the third depth buffer to obtain the fourth depth test result, wherein the fourth pixel position is the pixel position to which the fourth target depth value belongs; If the fourth depth test result is that the fourth target depth value is less than the fourth buffer depth value, the fourth buffer depth value in the third depth buffer is updated to the fourth target depth value, and the updated third depth buffer is determined as the fourth depth buffer. If the fourth depth test result indicates that the fourth target depth value is greater than or equal to the fourth buffer depth value, the fragment corresponding to the fourth target depth value is deleted.

9. The method according to claim 8, characterized in that, The step of performing a depth test on the fifth target depth value based on the fourth depth test result to obtain a fifth depth test result, and determining whether to retain the fragment corresponding to the fifth target depth value based on the fifth depth test result, includes: The fifth target depth value is compared with the fifth buffer depth value corresponding to the fifth pixel position in the fourth depth buffer to obtain the fifth depth test result, wherein the fifth pixel position is the pixel position to which the fifth target depth value belongs; If the fifth depth test result is that the fifth target depth value is less than the fifth buffer depth value, the fifth buffer depth value in the fourth depth buffer is updated to the fifth target depth value, and the updated fourth depth buffer is determined as the fifth depth buffer. If the fifth depth test result indicates that the fifth target depth value is greater than or equal to the fifth buffer depth value, the fragment corresponding to the fifth target depth value is deleted.

10. The method according to claim 1 or 5, characterized in that, The method further includes: Obtain the type flag corresponding to the depth value; If the type flag corresponding to the depth value is an interpolation flag, the type of the depth value is determined to be an interpolated depth value generated during the rasterization stage; If the type flag corresponding to the depth value is a non-interpolation flag, the type of the depth value is determined to be a pixel shader modified depth value.

11. The method according to claim 1 or 5, characterized in that, The method further includes: Get the current rendering mode flag, the current rendering pass flag, and the current depth clamp flag; When the rendering mode flag is set to single-channel mode and the depth clamp flag is set to enable, it is determined that the rendering condition is single-channel rendering mode and the depth clamp function is enabled. When the rendering mode flag is a dual-channel mode flag, the rendering channel flag is a first channel flag, and the depth clamp flag is an enabled flag, it is determined that the rendering condition is the first channel in the dual-channel rendering mode and the depth clamp function is enabled. When the rendering mode flag is a dual-channel mode flag, the rendering channel flag is a second channel flag, and the depth clamping flag is an enabled flag, the rendering condition is determined to be the second channel in the dual-channel rendering mode and the depth clamping function is enabled. When the rendering mode flag is set to dual-channel mode and the rendering channel flag is set to second channel, the rendering condition is determined to be the second channel in dual-channel rendering mode.

12. The method according to claim 1, characterized in that, The step of clamping the depth value to the target viewport depth range and generating the target depth value of the fragment includes: The depth value is normalized to obtain the normalized depth value corresponding to the depth value; The normalized depth value is clamped to the target viewport depth range to generate the target depth value of the fragment.

13. The method according to claim 12, characterized in that, The normalization process for the depth value to obtain the normalized depth value includes: Perform floating-point special value detection on the depth value to obtain the numerical type of the depth value; When the numerical type of the depth value is a target type, the minimum depth value in the depth value interval corresponding to the current depth buffer is determined as the normalized depth value corresponding to the depth value. The target type includes at least one of not numbers, unnormalized numbers, and negative infinity. When the numerical type of the depth value is positive infinity, the maximum depth value in the depth value interval corresponding to the current depth buffer is determined as the normalized depth value corresponding to the depth value. If the depth value is of normal floating-point type, the depth value is determined as the normalized depth value corresponding to the depth value.

14. The method according to claim 12, characterized in that, Each of the viewport register groups includes multiple viewport depth range registers, and each viewport depth range register stores a viewport depth range.

15. The method according to claim 14, characterized in that, Before determining the target viewport register group corresponding to the target viewport group identifier among a preset number of viewport register groups, the method further includes: Before generating the fragments in the rasterization stage, the rendering state is configured, which includes the viewport depth range and viewport identifier for each viewport. For each viewport identifier, configure a viewport depth range register corresponding to the viewport identifier, and write the viewport depth range corresponding to the viewport identifier into the viewport depth range register corresponding to the viewport identifier; According to the preset grouping rules, the viewport depth range registers corresponding to multiple viewport identifiers are grouped to obtain a preset number of viewport register groups, and the viewport group identifier corresponding to each viewport register group is configured.

16. The method according to claim 12, characterized in that, The step of clamping the normalized depth value to the target viewport depth range to generate the target depth value of the fragment includes: Read the minimum and maximum target viewport depth values ​​within the target viewport depth range; If the normalized depth value is less than the minimum target viewport depth, the normalized depth value is clamped to the minimum target viewport depth. If the normalized depth value is greater than the maximum target viewport depth, the normalized depth value is clamped to the maximum target viewport depth. If the normalized depth value is between the minimum and maximum target viewport depth, the normalized depth value is determined as the target depth value of the fragment.

17. A fragment depth clamping device, characterized in that, include: The acquisition module is used to acquire the depth value of fragments after the rasterization stage and before the depth test; The first depth clamping module is used to perform depth clamping processing on the depth value to obtain the target depth value of the fragment; A depth testing module is used to perform a depth test on the target depth value, so as to determine whether to retain the fragment based on the depth test result; Specifically, the first depth clamping module is used to: perform depth clamping processing on the depth value when the type of the depth value is an interpolated depth value generated during the rasterization stage, the current rendering condition is a single-channel rendering mode, and the depth clamping function is enabled, to obtain a first target depth value for the fragment; and perform depth clamping processing on the depth value when the type of the depth value is a depth value modified by the pixel shader, the current rendering condition is a single-channel rendering mode, and the depth clamping function is enabled, to obtain a second target depth value for the fragment. The step of performing depth clamping processing on the depth value to obtain the target depth value of the fragment includes: acquiring the target viewport group identifier and the target viewport identifier corresponding to the fragment; determining the target viewport register group corresponding to the target viewport group identifier from a preset number of viewport register groups; determining the target viewport depth range register corresponding to the target viewport identifier from the target viewport register group, and determining the viewport depth range in the target viewport depth range register as the target viewport depth range corresponding to the fragment; clamping the depth value to the target viewport depth range to generate the target depth value of the fragment.

18. A computer device, characterized in that, include: A memory and a processor, wherein the memory stores a computer program that, when executed by the processor, implements the fragment depth clamping method as described in any one of claims 1-16.

19. A computer-readable storage medium, characterized in that, The storage medium stores a computer program that, when executed by a processor, implements the fragment depth clamping method as described in any one of claims 1-16.

Citation Information

Patent Citations

  • Triangular plate filling method in rasterization phase in graphic rendering

    CN102737401A

  • Water surface rendering method and apparatus

    CN108470369A