Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions inc/core/palCmdBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -1859,6 +1859,13 @@ struct Viewport
PointOrigin origin; ///< Origin of the viewport relative to NDC. UpperLeft or LowerLeft.
};

/// Specifies range for user-defined depth clamp
struct DepthClamp
{
float minDepth; ///< Minimum depth value after viewport transform.
float maxDepth; ///< Maximum depth value after viewport transform.
};

/// Specifies the viewport transform parameters for setting a single viewport.
/// @see ICmdBuffer::CmdSetViewport
struct ViewportParams
Expand All @@ -1872,6 +1879,8 @@ struct ViewportParams
float horzClipRatio; ///< The ratio between guardband clip rect width and viewport width.
float vertClipRatio; ///< The ratio between guardband clip rect height and viewport height.
DepthRange depthRange; ///< Specifies the target range of Z values
DepthClamp depthClampOverride; ///< Specifies the clamp range of Z values for DepthClampMode::Viewport.
/// minDepth > maxDepth means that the override is not active.
// Define viewports array at the end of the structure as it is common to only access the first N from the CPU.
Viewport viewports[MaxViewports]; ///< Array of desciptors for each viewport.
};
Expand Down
7 changes: 7 additions & 0 deletions src/core/hw/gfxip/gfx12/gfx12UniversalCmdBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1357,6 +1357,13 @@ void UniversalCmdBuffer::WriteViewports(
}
else
#endif
if (static_cast<DepthClampMode>(m_graphicsState.depthClampMode) == DepthClampMode::Viewport &&
vpParams.depthClampOverride.minDepth <= vpParams.depthClampOverride.maxDepth)
{
viewportRegs.vp[i].zMin.f32All = vpParams.depthClampOverride.minDepth;
viewportRegs.vp[i].zMax.f32All = vpParams.depthClampOverride.maxDepth;
}
else
{
viewportRegs.vp[i].zMin.f32All = Min(viewport.minDepth, viewport.maxDepth);
viewportRegs.vp[i].zMax.f32All = Max(viewport.minDepth, viewport.maxDepth);
Expand Down
7 changes: 7 additions & 0 deletions src/core/hw/gfxip/gfx9/gfx9UniversalCmdBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7711,6 +7711,13 @@ uint32* UniversalCmdBuffer::ValidateViewports(
}
else
#endif
if (static_cast<DepthClampMode>(m_graphicsState.depthClampMode) == DepthClampMode::Viewport &&
params.depthClampOverride.minDepth <= params.depthClampOverride.maxDepth)
{
pZMinMaxImg->zMin.f32All = params.depthClampOverride.minDepth;
pZMinMaxImg->zMax.f32All = params.depthClampOverride.maxDepth;
}
else
{
pZMinMaxImg->zMin.f32All = Min(viewport.minDepth, viewport.maxDepth);
pZMinMaxImg->zMax.f32All = Max(viewport.minDepth, viewport.maxDepth);
Expand Down
1 change: 1 addition & 0 deletions src/core/hw/gfxip/rpm/gfx12/gfx12RsrcProcMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1319,6 +1319,7 @@ void RsrcProcMgr::DepthStencilClearGraphics(
viewportInfo.vertClipRatio = FLT_MAX;
viewportInfo.vertDiscardRatio = 1.0f;
viewportInfo.depthRange = DepthRange::ZeroToOne;
viewportInfo.depthClampOverride = { 1.0f, 0.0f };

ScissorRectParams scissorInfo = {};
scissorInfo.count = 1;
Expand Down
4 changes: 4 additions & 0 deletions src/core/hw/gfxip/rpm/gfx9/gfx9RsrcProcMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1185,6 +1185,7 @@ bool RsrcProcMgr::ExpandDepthStencil(
viewportInfo.vertClipRatio = FLT_MAX;
viewportInfo.vertDiscardRatio = 1.0f;
viewportInfo.depthRange = DepthRange::ZeroToOne;
viewportInfo.depthClampOverride = { 1.0f, 0.0f };

ScissorRectParams scissorInfo = { };
scissorInfo.count = 1;
Expand Down Expand Up @@ -2020,6 +2021,7 @@ void RsrcProcMgr::ResolveImageDepthStencilCopy(
viewportInfo.vertClipRatio = FLT_MAX;
viewportInfo.vertDiscardRatio = 1.0f;
viewportInfo.depthRange = DepthRange::ZeroToOne;
viewportInfo.depthClampOverride = { 1.0f, 0.0f };

ScissorRectParams scissorInfo = {};
scissorInfo.count = 1;
Expand Down Expand Up @@ -2248,6 +2250,7 @@ void RsrcProcMgr::HwlResolveImageGraphics(
viewportInfo.vertClipRatio = FLT_MAX;
viewportInfo.vertDiscardRatio = 1.0f;
viewportInfo.depthRange = DepthRange::ZeroToOne;
viewportInfo.depthClampOverride = { 1.0f, 0.0f };

ScissorRectParams scissorInfo = { };
scissorInfo.count = 1;
Expand Down Expand Up @@ -2771,6 +2774,7 @@ void RsrcProcMgr::DepthStencilClearGraphics(
viewportInfo.vertClipRatio = FLT_MAX;
viewportInfo.vertDiscardRatio = 1.0f;
viewportInfo.depthRange = DepthRange::ZeroToOne;
viewportInfo.depthClampOverride = { 1.0f, 0.0f };

ScissorRectParams scissorInfo = { };
scissorInfo.count = 1;
Expand Down
10 changes: 10 additions & 0 deletions src/core/hw/gfxip/rpm/rsrcProcMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3368,6 +3368,7 @@ void RsrcProcMgr::CmdClearBoundDepthStencilTargets(
viewportInfo.vertClipRatio = FLT_MAX;
viewportInfo.vertDiscardRatio = 1.0f;
viewportInfo.depthRange = DepthRange::ZeroToOne;
viewportInfo.depthClampOverride = { 1.0f, 0.0f };

ScissorRectParams scissorInfo = { };
scissorInfo.count = 1;
Expand Down Expand Up @@ -3450,6 +3451,7 @@ void RsrcProcMgr::CmdClearBoundColorTargets(
viewportInfo.vertClipRatio = FLT_MAX;
viewportInfo.vertDiscardRatio = 1.0f;
viewportInfo.depthRange = DepthRange::ZeroToOne;
viewportInfo.depthClampOverride = { 1.0f, 0.0f };

ScissorRectParams scissorInfo = { };
scissorInfo.count = 1;
Expand Down Expand Up @@ -5595,6 +5597,7 @@ void RsrcProcMgr::ResummarizeDepthStencil(
viewportInfo.vertClipRatio = FLT_MAX;
viewportInfo.vertDiscardRatio = 1.0f;
viewportInfo.depthRange = DepthRange::ZeroToOne;
viewportInfo.depthClampOverride = { 1.0f, 0.0f };

ScissorRectParams scissorInfo = { };
scissorInfo.count = 1;
Expand Down Expand Up @@ -5876,6 +5879,7 @@ void RsrcProcMgr::SlowClearGraphics(
viewportInfo.vertClipRatio = FLT_MAX;
viewportInfo.vertDiscardRatio = 1.0f;
viewportInfo.depthRange = DepthRange::ZeroToOne;
viewportInfo.depthClampOverride = { 1.0f, 0.0f };

const bool is3dImage = (createInfo.imageType == ImageType::Tex3d);
ColorTargetViewCreateInfo colorViewInfo = { };
Expand Down Expand Up @@ -6016,6 +6020,7 @@ void RsrcProcMgr::GenericColorBlit(
viewportInfo.vertClipRatio = FLT_MAX;
viewportInfo.vertDiscardRatio = 1.0f;
viewportInfo.depthRange = DepthRange::ZeroToOne;
viewportInfo.depthClampOverride = { 1.0f, 0.0f };

ColorTargetViewInternalCreateInfo colorViewInfoInternal = { };
colorViewInfoInternal.flags.dccDecompress = (pipeline == RpmGfxPipeline::DccDecompress);
Expand Down Expand Up @@ -6381,6 +6386,7 @@ void RsrcProcMgr::ResolveImageDepthStencilGraphics(
viewportInfo.vertClipRatio = FLT_MAX;
viewportInfo.vertDiscardRatio = 1.0f;
viewportInfo.depthRange = DepthRange::ZeroToOne;
viewportInfo.depthClampOverride = { 1.0f, 0.0f };

ScissorRectParams scissorInfo = { };
scissorInfo.count = 1;
Expand Down Expand Up @@ -6593,6 +6599,7 @@ void RsrcProcMgr::ResolveImageFixedFunc(
viewportInfo.vertClipRatio = FLT_MAX;
viewportInfo.vertDiscardRatio = 1.0f;
viewportInfo.depthRange = DepthRange::ZeroToOne;
viewportInfo.depthClampOverride = { 1.0f, 0.0f };

ScissorRectParams scissorInfo = { };
scissorInfo.count = 1;
Expand Down Expand Up @@ -6868,6 +6875,7 @@ void RsrcProcMgr::ScaledCopyImageGraphics(
viewportInfo.vertClipRatio = FLT_MAX;
viewportInfo.vertDiscardRatio = 1.0f;
viewportInfo.depthRange = DepthRange::ZeroToOne;
viewportInfo.depthClampOverride = { 1.0f, 0.0f };

ScissorRectParams scissorInfo = {};
scissorInfo.count = 1;
Expand Down Expand Up @@ -7660,6 +7668,7 @@ void RsrcProcMgr::CopyDepthStencilImageGraphics(
viewportInfo.vertClipRatio = FLT_MAX;
viewportInfo.vertDiscardRatio = 1.0f;
viewportInfo.depthRange = DepthRange::ZeroToOne;
viewportInfo.depthClampOverride = { 1.0f, 0.0f };

ScissorRectParams scissorInfo = { };
scissorInfo.count = 1;
Expand Down Expand Up @@ -7988,6 +7997,7 @@ void RsrcProcMgr::CopyColorImageGraphics(
viewportInfo.vertClipRatio = FLT_MAX;
viewportInfo.vertDiscardRatio = 1.0f;
viewportInfo.depthRange = DepthRange::ZeroToOne;
viewportInfo.depthClampOverride = { 1.0f, 0.0f };

ScissorRectParams scissorInfo = { };
scissorInfo.count = 1;
Expand Down
4 changes: 4 additions & 0 deletions src/core/hw/gfxip/universalCmdBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ void UniversalCmdBuffer::ResetState()
m_graphicsState.viewportState.vertClipRatio = 1.0f;
m_graphicsState.viewportState.vertDiscardRatio = 1.0f;

// No depth clamp override by default
m_graphicsState.viewportState.depthClampOverride = { 1.0f, 0.0f };
}

// =====================================================================================================================
Expand Down Expand Up @@ -746,6 +748,8 @@ void UniversalCmdBuffer::SetGraphicsState(
(restoreViewports.vertDiscardRatio != currentViewports.vertDiscardRatio) ||
(restoreViewports.horzClipRatio != currentViewports.horzClipRatio) ||
(restoreViewports.vertClipRatio != currentViewports.vertClipRatio) ||
(restoreViewports.depthClampOverride.minDepth != currentViewports.depthClampOverride.minDepth) ||
(restoreViewports.depthClampOverride.maxDepth != currentViewports.depthClampOverride.maxDepth) ||
(memcmp(&restoreViewports.viewports[0],
&currentViewports.viewports[0],
restoreViewports.count * sizeof(restoreViewports.viewports[0])) != 0))
Expand Down
6 changes: 6 additions & 0 deletions src/core/layers/cmdBufferLogger/cmdBufferLoggerCmdBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2142,6 +2142,12 @@ static void ViewportParamsToString(
Snprintf(pString, StringLength, " depthRange = %s",
(params.depthRange == DepthRange::ZeroToOne) ? "ZeroToOne" : "NegativeOneToOne");
pCmdBuffer->GetNextLayer()->CmdCommentString(pString);
pCmdBuffer->GetNextLayer()->CmdCommentString(" depthClampOverride = {");
Snprintf(pString, StringLength, " \tminDepth = %f", viewport.depthClampOverride.minDepth);
pCmdBuffer->GetNextLayer()->CmdCommentString(pString);
Snprintf(pString, StringLength, " \tmaxDepth = %f", viewport.depthClampOverride.maxDepth);
pCmdBuffer->GetNextLayer()->CmdCommentString(pString);
pCmdBuffer->GetNextLayer()->CmdCommentString(" } // depthClampOverride");

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4145,6 +4145,16 @@ void LogContext::Struct(
EndMap();
}

// =====================================================================================================================
void LogContext::Struct(
const DepthClamp& value)
{
BeginMap(false);
KeyAndValue("minDepth", value.minDepth);
KeyAndValue("maxDepth", value.maxDepth);
EndMap();
}

// =====================================================================================================================
void LogContext::Struct(
const ViewportParams& value)
Expand All @@ -4170,6 +4180,7 @@ void LogContext::Struct(
KeyAndValue("vertDiscardRatio", value.vertDiscardRatio);
KeyAndValue("horzClipRatio", value.horzClipRatio);
KeyAndValue("vertClipRatio", value.vertClipRatio);
KeyAndValue("depthClampOverride", value.depthClampOverride);
EndMap();
}

Expand Down