Skip to content

Commit

Permalink
[hdx, hgi, hgiGL, hgiVulkan] For hgi backends such as Metal that do n…
Browse files Browse the repository at this point in the history
…ot support

depth stencil readback, only read the depth buffer in HdxPickTask.

Contribution: Jon Creighton, David Yu

(Internal change: 2217079)
  • Loading branch information
clach authored and pixar-oss committed Feb 22, 2022
1 parent 2d0d276 commit 0b0db2e
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 14 deletions.
35 changes: 22 additions & 13 deletions pxr/imaging/hdx/pickTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,6 @@ _IsStormRenderer(HdRenderDelegate *renderDelegate)
return true;
}

// Generated renderbuffers
static TfTokenVector _aovOutputs {
HdAovTokens->primId,
HdAovTokens->instanceId,
HdAovTokens->elementId,
HdAovTokens->edgeId,
HdAovTokens->pointId,
HdAovTokens->Neye,
HdAovTokens->depthStencil
};
TF_DEFINE_PRIVATE_TOKENS(_tokens,
(widgetDepthStencil)
);
Expand All @@ -116,6 +106,7 @@ HdxPickTask::HdxPickTask(HdSceneDelegate* delegate, SdfPath const& id)
, _index(nullptr)
, _hgi(nullptr)
, _pickableDepthIndex(0)
, _depthToken(HdAovTokens->depthStencil)
{
}

Expand Down Expand Up @@ -172,11 +163,28 @@ HdxPickTask::_CreateAovBindings()
std::static_pointer_cast<HdStResourceRegistry>(
_index->GetResourceRegistry());

HdRenderDelegate *renderDelegate = _index->GetRenderDelegate();
HdRenderDelegate const * renderDelegate = _index->GetRenderDelegate();

GfVec3i dimensions(_contextParams.resolution[0],
_contextParams.resolution[1], 1);

bool const stencilReadback = _hgi->GetCapabilities()->
IsSet(HgiDeviceCapabilitiesBitsStencilReadback);

_depthToken = stencilReadback ? HdAovTokens->depthStencil
: HdAovTokens->depth;

// Generated renderbuffers
TfTokenVector const _aovOutputs {
HdAovTokens->primId,
HdAovTokens->instanceId,
HdAovTokens->elementId,
HdAovTokens->edgeId,
HdAovTokens->pointId,
HdAovTokens->Neye,
_depthToken
};

// Add the new renderbuffers.
for (size_t i = 0; i < _aovOutputs.size(); ++i) {
TfToken const & aovOutput = _aovOutputs[i];
Expand All @@ -201,7 +209,8 @@ HdxPickTask::_CreateAovBindings()

_pickableAovBindings.push_back(binding);

if (HdAovHasDepthStencilSemantic(aovOutput)) {
if (HdAovHasDepthSemantic(aovOutput) ||
HdAovHasDepthStencilSemantic(aovOutput)) {
_pickableDepthIndex = i;
_occluderAovBinding = binding;
}
Expand Down Expand Up @@ -661,7 +670,7 @@ HdxPickTask::Execute(HdTaskContext* ctx)

std::vector<uint8_t> depths;
float const * depthPtr =
_ReadAovBuffer<float>(HdAovTokens->depthStencil, &depths);
_ReadAovBuffer<float>(_depthToken, &depths);

// For un-projection, get the current depth range.
GLfloat p[2];
Expand Down
1 change: 1 addition & 0 deletions pxr/imaging/hdx/pickTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ class HdxPickTask : public HdTask
HdRenderPassAovBindingVector _pickableAovBindings;
HdRenderPassAovBinding _occluderAovBinding;
size_t _pickableDepthIndex;
TfToken _depthToken;
std::unique_ptr<HdStRenderBuffer> _widgetDepthStencilBuffer;
HdRenderPassAovBindingVector _widgetAovBindings;

Expand Down
5 changes: 4 additions & 1 deletion pxr/imaging/hgi/enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ using HgiBits = uint32_t;
/// Use CPP padding for shader language structures</li>
/// <li>HgiDeviceCapabilitiesBitsConservativeRaster:
/// The device supports conservative rasterization</li>
/// <li>HgiDeviceCapabilitiesBitsStencilReadback:
/// Supports reading back the stencil buffer from GPU to CPU.</li>
/// </ul>
///
enum HgiDeviceCapabilitiesBits : HgiBits
Expand All @@ -78,7 +80,8 @@ enum HgiDeviceCapabilitiesBits : HgiBits
HgiDeviceCapabilitiesBitsShaderDoublePrecision = 1 << 8,
HgiDeviceCapabilitiesBitsDepthRangeMinusOnetoOne = 1 << 9,
HgiDeviceCapabilitiesBitsCppShaderPadding = 1 << 10,
HgiDeviceCapabilitiesBitsConservativeRaster = 1 << 11
HgiDeviceCapabilitiesBitsConservativeRaster = 1 << 11,
HgiDeviceCapabilitiesBitsStencilReadback = 1 << 12
};

using HgiDeviceCapabilities = HgiBits;
Expand Down
2 changes: 2 additions & 0 deletions pxr/imaging/hgiGL/capabilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ HgiGLCapabilities::_LoadCapabilities()
true);
_SetFlag(HgiDeviceCapabilitiesBitsConservativeRaster,
conservativeRasterEnabled);
_SetFlag(HgiDeviceCapabilitiesBitsStencilReadback,
true);

if (TfDebug::IsEnabled(HGI_DEBUG_DEVICE_CAPABILITIES)) {
std::cout
Expand Down
1 change: 1 addition & 0 deletions pxr/imaging/hgiVulkan/capabilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ HgiVulkanCapabilities::HgiVulkanCapabilities(HgiVulkanDevice* device)
_SetFlag(HgiDeviceCapabilitiesBitsDepthRangeMinusOnetoOne, false);
_SetFlag(HgiDeviceCapabilitiesBitsConservativeRaster,
conservativeRasterEnabled);
_SetFlag(HgiDeviceCapabilitiesBitsStencilReadback, true);
}

HgiVulkanCapabilities::~HgiVulkanCapabilities() = default;
Expand Down

0 comments on commit 0b0db2e

Please sign in to comment.