Skip to content

Conversation

muenstc
Copy link
Contributor

@muenstc muenstc commented Sep 30, 2025

Adds a depth bias task that allows to specify a small depth offset to modify the depth buffer.
Useful when rendering multiple frame passes that share the depth buffer to avoid z-fighting in case another frame pass is rendering the same or similar geometry again.

When MSAA is enabled at the moment we need to copy the modified depth back into the msaa depth buffer. Added another special copy task for this. Eventually, we should bias the msaa depth buffer directly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this file identical to test/data/assets/usd/test_zdepth_fight_red_only.usd ?

TestHelpers::TestStage stage1(context->_backend);
const std::string filepath1 =
#if defined(__APPLE__)
TestHelpers::getAssetsDataFolder().string() + "/usd/test_zdepth_fight_red_only_osx.usd";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is a different file needed for osx?

#if defined(__ANDROID__) || TARGET_OS_IPHONE == 1
TEST(TestViewportToolbox, DISABLED_TestZFightingMultisampling)
#else
TEST(TestViewportToolbox, TestZFightingMultisampling)
Copy link
Contributor

@sebastienberube-adsk sebastienberube-adsk Oct 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest moving the common code into a function used by both tests.
See this for example:

#if defined(__ANDROID__)
TEST(TestViewportToolbox, DISABLED_TestMsaaNoSkyNoCopyNoColorCorrectionAAOff)
#else
TEST(TestViewportToolbox, TestMsaaNoSkyNoCopyNoColorCorrectionAAOff)
#endif
{
MsaaTestSettings testSettings;
testSettings.msaaSampleCount = 1;
testSettings.enableMsaa = false;
testSettings.enableColorCorrection = false;
testSettings.enableLights = true;
testSettings.createCopyTask = false;
testSettings.createSkyDome = false;
testSettings.wireframeSecondPass = false;
testSettings.renderSize = pxr::GfVec2i(300, 200);
TestMultiSampling(testSettings, std::string(test_info_->name()));
}
// FIXME: wireframe does not work on macOS/Metal.
// Refer to https://forum.aousd.org/t/hdstorm-mesh-wires-drawing-issue-in-usd-24-05-on-macos/1523
// FIXME: IOS does not support the SkyDomeTask.
// Refer to OGSMOD-8001
// FIXME: Android does not support multiple frame passes.
// Refer to OGSMOD-8002
#if defined(__APPLE__) || defined(__ANDROID__)
TEST(TestViewportToolbox, DISABLED_TestMsaaWireframeAA4x)
#else
TEST(TestViewportToolbox, TestMsaaWireframeAA4x)
#endif
{
MsaaTestSettings testSettings;
testSettings.msaaSampleCount = 4;
testSettings.enableMsaa = true;
testSettings.enableColorCorrection = true;
testSettings.enableLights = false;
testSettings.createCopyTask = true;
testSettings.createSkyDome = true;
testSettings.wireframeSecondPass = true;
testSettings.renderSize = pxr::GfVec2i(300, 200);
TestMultiSampling(testSettings, std::string(test_info_->name()));
}

Differences between your 2 tests are minimal:

  • msaaSampleCount
  • enableMultisampling
  • this block with MSAA only:
// Add the CopyDepthToDepthMsaa task to copy the depth-biased depth to the MSAA depth buffer
    {
        // Defines the 'CopyDepthToDepthMsaa' task update function.
        auto fnCommitCopyDepth = [&](hvt::TaskManager::GetTaskValueFn const& fnGetValue,
                                     hvt::TaskManager::SetTaskValueFn const& fnSetValue)
        {
            const pxr::VtValue value = fnGetValue(pxr::HdTokens->params);
            hvt::CopyDepthToDepthMsaaTaskParams params;
            if (value.IsHolding<hvt::CopyDepthToDepthMsaaTaskParams>()) {
                params = value.Get<hvt::CopyDepthToDepthMsaaTaskParams>();
            }
            
            // Set source as resolved depth and target as MSAA depth
            params.sourceDepthAovName = pxr::HdAovTokens->depth;
            params.targetDepthAovName = pxr::TfToken("depthMSAA");

            fnSetValue(pxr::HdTokens->params, pxr::VtValue(params));
        };

        // Add the CopyDepthToDepthMsaa task after the DepthBias task
        const pxr::SdfPath depthBiasTaskPath = instance1.sceneFramePass->GetTaskManager()->GetTaskPath(
            hvt::DepthBiasTask::GetToken());

        instance1.sceneFramePass->GetTaskManager()->AddTask<hvt::CopyDepthToDepthMsaaTask>(
            hvt::CopyDepthToDepthMsaaTask::GetToken(), hvt::CopyDepthToDepthMsaaTaskParams(), 
            fnCommitCopyDepth, depthBiasTaskPath,
            hvt::TaskManager::InsertionOrder::insertAfter);
    }

}
}

bool CopyDepthToDepthMsaaTask::_CreateShaderResources()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see a lot of code in CopyDepthToDepthMsaaTask that is highly similar to the CopyTask.
The differences are mostly strings, tokens, variable names.

I wonder if we should centralize the code or not.
Perhaps it is not worth it at this stage, as we don't even know if this will be kept in the future, given the current refactor happening with the RenderBufferManager (the CopyTask will likely be eliminated with that refactor).

In any case, make sure to check with @AdamFelt how this can work with the planned refactor. Your work relies and touches a couple of areas that are being eliminated or moved (CopyTask, Context MSAA buffers, etc). This might be an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants