Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autodesk: Add HgiAttachmentResolveFilter for depth texture in HgiMetal #3092

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
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
6 changes: 4 additions & 2 deletions pxr/imaging/hgi/attachmentDesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ bool operator==(
lhs.srcAlphaBlendFactor == rhs.srcAlphaBlendFactor &&
lhs.dstAlphaBlendFactor == rhs.dstAlphaBlendFactor &&
lhs.alphaBlendOp == rhs.alphaBlendOp &&
lhs.blendConstantColor == rhs.blendConstantColor;
lhs.blendConstantColor == rhs.blendConstantColor &&
lhs.resolveFilter == rhs.resolveFilter;
}

bool operator!=(
Expand Down Expand Up @@ -72,7 +73,8 @@ std::ostream& operator<<(
<< "srcAlphaBlendFactor: " << attachment.srcAlphaBlendFactor << ", "
<< "dstAlphaBlendFactor: " << attachment.dstAlphaBlendFactor << ", "
<< "alphaBlendOp: " << attachment.alphaBlendOp << ", "
<< "blendConstantColor: " << attachment.blendConstantColor <<
<< "blendConstantColor: " << attachment.blendConstantColor << ", "
<< "resolveFilter: " << attachment.resolveFilter <<
"}";
return out;
}
Expand Down
2 changes: 2 additions & 0 deletions pxr/imaging/hgi/attachmentDesc.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ struct HgiAttachmentDesc
, dstAlphaBlendFactor(HgiBlendFactorZero)
, alphaBlendOp(HgiBlendOpAdd)
, blendConstantColor(0.0f, 0.0f, 0.0f, 0.0f)
, resolveFilter(HgiAttachmentResolveFilterDefault)
{}

HgiFormat format;
Expand All @@ -96,6 +97,7 @@ struct HgiAttachmentDesc
HgiBlendFactor dstAlphaBlendFactor;
HgiBlendOp alphaBlendOp;
GfVec4f blendConstantColor;
HgiAttachmentResolveFilter resolveFilter;
};

using HgiAttachmentDescVector = std::vector<HgiAttachmentDesc>;
Expand Down
28 changes: 28 additions & 0 deletions pxr/imaging/hgi/enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,34 @@ enum HgiAttachmentStoreOp
HgiAttachmentStoreOpCount
};

/// \enum HgiAttachmentResolveFilter
///
/// Describes what will happen to the attachment pixel data after MSAA resolving.
///
/// <ul>
/// <li>HgiAttachmentResolveFilterDefault:
/// The attachment pixel value will be determined by the default mode which can vary across different APIs.</li>
/// <li>HgiAttachmentResolveFilterSample0:
/// The attachment pixel value will be the value of the first sample.</li>
/// <li>HgiAttachmentResolveFilterMin:
/// The attachment pixel value will be the minimum value of all the samples.</li>
/// <li>HgiAttachmentResolveFilterMax:
/// The attachment pixel value will be the maximum value of all the samples.</li>
/// <li>HgiAttachmentResolveFilterAverage:
/// The attachment pixel value will be the average value of all the samples..</li>
/// </ul>
///
enum HgiAttachmentResolveFilter
{
HgiAttachmentResolveFilterDefault = 0,
HgiAttachmentResolveFilterSample0,
HgiAttachmentResolveFilterMin,
HgiAttachmentResolveFilterMax,
HgiAttachmentResolveFilterAverage,

HgiAttachmentResolveFilterCount
};

/// \enum HgiBufferUsageBits
///
/// Describes the properties and usage of the buffer.
Expand Down
19 changes: 19 additions & 0 deletions pxr/imaging/hgiMetal/graphicsCmds.mm
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,19 @@
}
}

static MTLMultisampleDepthResolveFilter
_HgiMultiSampleResolveFilterToMTLMultiSampleDepthResolveFilter(HgiAttachmentResolveFilter filter)
{
if (filter == HgiAttachmentResolveFilterSample0)
return MTLMultisampleDepthResolveFilterSample0;
else if (filter == HgiAttachmentResolveFilterMin)
return MTLMultisampleDepthResolveFilterMin;
else if (filter == HgiAttachmentResolveFilterMax)
return MTLMultisampleDepthResolveFilterMax;
else
return MTLMultisampleDepthResolveFilterSample0;
}

HgiMetalGraphicsCmds::HgiMetalGraphicsCmds(
HgiMetal* hgi,
HgiGraphicsCmdsDesc const& desc)
Expand Down Expand Up @@ -208,6 +221,12 @@
metalDepthAttachment.resolveTexture =
resolveTexture->GetTextureId();

if (hgiDepthAttachment.resolveFilter != HgiAttachmentResolveFilterDefault)
{
metalDepthAttachment.depthResolveFilter =
_HgiMultiSampleResolveFilterToMTLMultiSampleDepthResolveFilter(hgiDepthAttachment.resolveFilter);
}

if (hgiDepthAttachment.storeOp == HgiAttachmentStoreOpStore) {
metalDepthAttachment.storeAction =
MTLStoreActionStoreAndMultisampleResolve;
Expand Down
Loading