Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.

Commit 48d3a94

Browse files
committed
Add ability for the viewport to override the depth clamp range
1 parent c5e8000 commit 48d3a94

File tree

9 files changed

+59
-0
lines changed

9 files changed

+59
-0
lines changed

inc/core/palCmdBuffer.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1859,6 +1859,13 @@ struct Viewport
18591859
PointOrigin origin; ///< Origin of the viewport relative to NDC. UpperLeft or LowerLeft.
18601860
};
18611861

1862+
/// Specifies range for user-defined depth clamp
1863+
struct DepthClamp
1864+
{
1865+
float minDepth; ///< Minimum depth value after viewport transform.
1866+
float maxDepth; ///< Maximum depth value after viewport transform.
1867+
};
1868+
18621869
/// Specifies the viewport transform parameters for setting a single viewport.
18631870
/// @see ICmdBuffer::CmdSetViewport
18641871
struct ViewportParams
@@ -1872,6 +1879,8 @@ struct ViewportParams
18721879
float horzClipRatio; ///< The ratio between guardband clip rect width and viewport width.
18731880
float vertClipRatio; ///< The ratio between guardband clip rect height and viewport height.
18741881
DepthRange depthRange; ///< Specifies the target range of Z values
1882+
DepthClamp depthClampOverride; ///< Specifies the clamp range of Z values for DepthClampMode::Viewport.
1883+
/// minDepth > maxDepth means that the override is not active.
18751884
// Define viewports array at the end of the structure as it is common to only access the first N from the CPU.
18761885
Viewport viewports[MaxViewports]; ///< Array of desciptors for each viewport.
18771886
};

src/core/hw/gfxip/gfx12/gfx12UniversalCmdBuffer.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,6 +1357,13 @@ void UniversalCmdBuffer::WriteViewports(
13571357
}
13581358
else
13591359
#endif
1360+
if (static_cast<DepthClampMode>(m_graphicsState.depthClampMode) == DepthClampMode::Viewport &&
1361+
vpParams.depthClampOverride.minDepth <= vpParams.depthClampOverride.maxDepth)
1362+
{
1363+
viewportRegs.vp[i].zMin.f32All = vpParams.depthClampOverride.minDepth;
1364+
viewportRegs.vp[i].zMax.f32All = vpParams.depthClampOverride.maxDepth;
1365+
}
1366+
else
13601367
{
13611368
viewportRegs.vp[i].zMin.f32All = Min(viewport.minDepth, viewport.maxDepth);
13621369
viewportRegs.vp[i].zMax.f32All = Max(viewport.minDepth, viewport.maxDepth);

src/core/hw/gfxip/gfx9/gfx9UniversalCmdBuffer.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7711,6 +7711,13 @@ uint32* UniversalCmdBuffer::ValidateViewports(
77117711
}
77127712
else
77137713
#endif
7714+
if (static_cast<DepthClampMode>(m_graphicsState.depthClampMode) == DepthClampMode::Viewport &&
7715+
params.depthClampOverride.minDepth <= params.depthClampOverride.maxDepth)
7716+
{
7717+
pZMinMaxImg->zMin.f32All = params.depthClampOverride.minDepth;
7718+
pZMinMaxImg->zMax.f32All = params.depthClampOverride.maxDepth;
7719+
}
7720+
else
77147721
{
77157722
pZMinMaxImg->zMin.f32All = Min(viewport.minDepth, viewport.maxDepth);
77167723
pZMinMaxImg->zMax.f32All = Max(viewport.minDepth, viewport.maxDepth);

src/core/hw/gfxip/rpm/gfx12/gfx12RsrcProcMgr.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,6 +1319,7 @@ void RsrcProcMgr::DepthStencilClearGraphics(
13191319
viewportInfo.vertClipRatio = FLT_MAX;
13201320
viewportInfo.vertDiscardRatio = 1.0f;
13211321
viewportInfo.depthRange = DepthRange::ZeroToOne;
1322+
viewportInfo.depthClampOverride = { 1.0f, 0.0f };
13221323

13231324
ScissorRectParams scissorInfo = {};
13241325
scissorInfo.count = 1;

src/core/hw/gfxip/rpm/gfx9/gfx9RsrcProcMgr.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,6 +1185,7 @@ bool RsrcProcMgr::ExpandDepthStencil(
11851185
viewportInfo.vertClipRatio = FLT_MAX;
11861186
viewportInfo.vertDiscardRatio = 1.0f;
11871187
viewportInfo.depthRange = DepthRange::ZeroToOne;
1188+
viewportInfo.depthClampOverride = { 1.0f, 0.0f };
11881189

11891190
ScissorRectParams scissorInfo = { };
11901191
scissorInfo.count = 1;
@@ -2020,6 +2021,7 @@ void RsrcProcMgr::ResolveImageDepthStencilCopy(
20202021
viewportInfo.vertClipRatio = FLT_MAX;
20212022
viewportInfo.vertDiscardRatio = 1.0f;
20222023
viewportInfo.depthRange = DepthRange::ZeroToOne;
2024+
viewportInfo.depthClampOverride = { 1.0f, 0.0f };
20232025

20242026
ScissorRectParams scissorInfo = {};
20252027
scissorInfo.count = 1;
@@ -2248,6 +2250,7 @@ void RsrcProcMgr::HwlResolveImageGraphics(
22482250
viewportInfo.vertClipRatio = FLT_MAX;
22492251
viewportInfo.vertDiscardRatio = 1.0f;
22502252
viewportInfo.depthRange = DepthRange::ZeroToOne;
2253+
viewportInfo.depthClampOverride = { 1.0f, 0.0f };
22512254

22522255
ScissorRectParams scissorInfo = { };
22532256
scissorInfo.count = 1;
@@ -2771,6 +2774,7 @@ void RsrcProcMgr::DepthStencilClearGraphics(
27712774
viewportInfo.vertClipRatio = FLT_MAX;
27722775
viewportInfo.vertDiscardRatio = 1.0f;
27732776
viewportInfo.depthRange = DepthRange::ZeroToOne;
2777+
viewportInfo.depthClampOverride = { 1.0f, 0.0f };
27742778

27752779
ScissorRectParams scissorInfo = { };
27762780
scissorInfo.count = 1;

src/core/hw/gfxip/rpm/rsrcProcMgr.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3368,6 +3368,7 @@ void RsrcProcMgr::CmdClearBoundDepthStencilTargets(
33683368
viewportInfo.vertClipRatio = FLT_MAX;
33693369
viewportInfo.vertDiscardRatio = 1.0f;
33703370
viewportInfo.depthRange = DepthRange::ZeroToOne;
3371+
viewportInfo.depthClampOverride = { 1.0f, 0.0f };
33713372

33723373
ScissorRectParams scissorInfo = { };
33733374
scissorInfo.count = 1;
@@ -3450,6 +3451,7 @@ void RsrcProcMgr::CmdClearBoundColorTargets(
34503451
viewportInfo.vertClipRatio = FLT_MAX;
34513452
viewportInfo.vertDiscardRatio = 1.0f;
34523453
viewportInfo.depthRange = DepthRange::ZeroToOne;
3454+
viewportInfo.depthClampOverride = { 1.0f, 0.0f };
34533455

34543456
ScissorRectParams scissorInfo = { };
34553457
scissorInfo.count = 1;
@@ -5595,6 +5597,7 @@ void RsrcProcMgr::ResummarizeDepthStencil(
55955597
viewportInfo.vertClipRatio = FLT_MAX;
55965598
viewportInfo.vertDiscardRatio = 1.0f;
55975599
viewportInfo.depthRange = DepthRange::ZeroToOne;
5600+
viewportInfo.depthClampOverride = { 1.0f, 0.0f };
55985601

55995602
ScissorRectParams scissorInfo = { };
56005603
scissorInfo.count = 1;
@@ -5876,6 +5879,7 @@ void RsrcProcMgr::SlowClearGraphics(
58765879
viewportInfo.vertClipRatio = FLT_MAX;
58775880
viewportInfo.vertDiscardRatio = 1.0f;
58785881
viewportInfo.depthRange = DepthRange::ZeroToOne;
5882+
viewportInfo.depthClampOverride = { 1.0f, 0.0f };
58795883

58805884
const bool is3dImage = (createInfo.imageType == ImageType::Tex3d);
58815885
ColorTargetViewCreateInfo colorViewInfo = { };
@@ -6016,6 +6020,7 @@ void RsrcProcMgr::GenericColorBlit(
60166020
viewportInfo.vertClipRatio = FLT_MAX;
60176021
viewportInfo.vertDiscardRatio = 1.0f;
60186022
viewportInfo.depthRange = DepthRange::ZeroToOne;
6023+
viewportInfo.depthClampOverride = { 1.0f, 0.0f };
60196024

60206025
ColorTargetViewInternalCreateInfo colorViewInfoInternal = { };
60216026
colorViewInfoInternal.flags.dccDecompress = (pipeline == RpmGfxPipeline::DccDecompress);
@@ -6381,6 +6386,7 @@ void RsrcProcMgr::ResolveImageDepthStencilGraphics(
63816386
viewportInfo.vertClipRatio = FLT_MAX;
63826387
viewportInfo.vertDiscardRatio = 1.0f;
63836388
viewportInfo.depthRange = DepthRange::ZeroToOne;
6389+
viewportInfo.depthClampOverride = { 1.0f, 0.0f };
63846390

63856391
ScissorRectParams scissorInfo = { };
63866392
scissorInfo.count = 1;
@@ -6593,6 +6599,7 @@ void RsrcProcMgr::ResolveImageFixedFunc(
65936599
viewportInfo.vertClipRatio = FLT_MAX;
65946600
viewportInfo.vertDiscardRatio = 1.0f;
65956601
viewportInfo.depthRange = DepthRange::ZeroToOne;
6602+
viewportInfo.depthClampOverride = { 1.0f, 0.0f };
65966603

65976604
ScissorRectParams scissorInfo = { };
65986605
scissorInfo.count = 1;
@@ -6868,6 +6875,7 @@ void RsrcProcMgr::ScaledCopyImageGraphics(
68686875
viewportInfo.vertClipRatio = FLT_MAX;
68696876
viewportInfo.vertDiscardRatio = 1.0f;
68706877
viewportInfo.depthRange = DepthRange::ZeroToOne;
6878+
viewportInfo.depthClampOverride = { 1.0f, 0.0f };
68716879

68726880
ScissorRectParams scissorInfo = {};
68736881
scissorInfo.count = 1;
@@ -7660,6 +7668,7 @@ void RsrcProcMgr::CopyDepthStencilImageGraphics(
76607668
viewportInfo.vertClipRatio = FLT_MAX;
76617669
viewportInfo.vertDiscardRatio = 1.0f;
76627670
viewportInfo.depthRange = DepthRange::ZeroToOne;
7671+
viewportInfo.depthClampOverride = { 1.0f, 0.0f };
76637672

76647673
ScissorRectParams scissorInfo = { };
76657674
scissorInfo.count = 1;
@@ -7988,6 +7997,7 @@ void RsrcProcMgr::CopyColorImageGraphics(
79887997
viewportInfo.vertClipRatio = FLT_MAX;
79897998
viewportInfo.vertDiscardRatio = 1.0f;
79907999
viewportInfo.depthRange = DepthRange::ZeroToOne;
8000+
viewportInfo.depthClampOverride = { 1.0f, 0.0f };
79918001

79928002
ScissorRectParams scissorInfo = { };
79938003
scissorInfo.count = 1;

src/core/hw/gfxip/universalCmdBuffer.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@ void UniversalCmdBuffer::ResetState()
244244
m_graphicsState.viewportState.vertClipRatio = 1.0f;
245245
m_graphicsState.viewportState.vertDiscardRatio = 1.0f;
246246

247+
// No depth clamp override by default
248+
m_graphicsState.viewportState.depthClampOverride = { 1.0f, 0.0f };
247249
}
248250

249251
// =====================================================================================================================
@@ -746,6 +748,8 @@ void UniversalCmdBuffer::SetGraphicsState(
746748
(restoreViewports.vertDiscardRatio != currentViewports.vertDiscardRatio) ||
747749
(restoreViewports.horzClipRatio != currentViewports.horzClipRatio) ||
748750
(restoreViewports.vertClipRatio != currentViewports.vertClipRatio) ||
751+
(restoreViewports.depthClampOverride.minDepth != currentViewports.depthClampOverride.minDepth) ||
752+
(restoreViewports.depthClampOverride.maxDepth != currentViewports.depthClampOverride.maxDepth) ||
749753
(memcmp(&restoreViewports.viewports[0],
750754
&currentViewports.viewports[0],
751755
restoreViewports.count * sizeof(restoreViewports.viewports[0])) != 0))

src/core/layers/cmdBufferLogger/cmdBufferLoggerCmdBuffer.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2142,6 +2142,12 @@ static void ViewportParamsToString(
21422142
Snprintf(pString, StringLength, " depthRange = %s",
21432143
(params.depthRange == DepthRange::ZeroToOne) ? "ZeroToOne" : "NegativeOneToOne");
21442144
pCmdBuffer->GetNextLayer()->CmdCommentString(pString);
2145+
pCmdBuffer->GetNextLayer()->CmdCommentString(" depthClampOverride = {");
2146+
Snprintf(pString, StringLength, " \tminDepth = %f", viewport.depthClampOverride.minDepth);
2147+
pCmdBuffer->GetNextLayer()->CmdCommentString(pString);
2148+
Snprintf(pString, StringLength, " \tmaxDepth = %f", viewport.depthClampOverride.maxDepth);
2149+
pCmdBuffer->GetNextLayer()->CmdCommentString(pString);
2150+
pCmdBuffer->GetNextLayer()->CmdCommentString(" } // depthClampOverride");
21452151

21462152
pCmdBuffer->GetNextLayer()->CmdCommentString("] // params");
21472153

src/core/layers/interfaceLogger/interfaceLoggerLogContextStruct.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4145,6 +4145,16 @@ void LogContext::Struct(
41454145
EndMap();
41464146
}
41474147

4148+
// =====================================================================================================================
4149+
void LogContext::Struct(
4150+
const DepthClamp& value)
4151+
{
4152+
BeginMap(false);
4153+
KeyAndValue("minDepth", value.minDepth);
4154+
KeyAndValue("maxDepth", value.maxDepth);
4155+
EndMap();
4156+
}
4157+
41484158
// =====================================================================================================================
41494159
void LogContext::Struct(
41504160
const ViewportParams& value)
@@ -4170,6 +4180,7 @@ void LogContext::Struct(
41704180
KeyAndValue("vertDiscardRatio", value.vertDiscardRatio);
41714181
KeyAndValue("horzClipRatio", value.horzClipRatio);
41724182
KeyAndValue("vertClipRatio", value.vertClipRatio);
4183+
KeyAndValue("depthClampOverride", value.depthClampOverride);
41734184
EndMap();
41744185
}
41754186

0 commit comments

Comments
 (0)