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: Stabilizing HgiVulkan #2553

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
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
13 changes: 13 additions & 0 deletions build_scripts/build_usd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1688,6 +1688,11 @@ def InstallUSD(context, force, buildArgs):
else:
extraArgs.append('-DPXR_BUILD_TUTORIALS=OFF')

if context.buildVulkan:
extraArgs.append('-DPXR_ENABLE_VULKAN_SUPPORT=ON')
else:
extraArgs.append('-DPXR_ENABLE_VULKAN_SUPPORT=OFF')

if context.buildTools:
extraArgs.append('-DPXR_BUILD_USD_TOOLS=ON')
else:
Expand Down Expand Up @@ -1960,6 +1965,11 @@ def InstallUSD(context, force, buildArgs):
subgroup.add_argument("--no-tutorials", dest="build_tutorials", action="store_false",
help="Do not build tutorials")
subgroup = group.add_mutually_exclusive_group()
subgroup.add_argument("--vulkan", dest="build_vulkan", action="store_true",
default=False, help="Build vulkan (default)")
subgroup.add_argument("--no-vulkan", dest="build_vulkan", action="store_false",
help="Do not build vulkan")
subgroup = group.add_mutually_exclusive_group()
subgroup.add_argument("--tools", dest="build_tools", action="store_true",
default=True, help="Build USD tools (default)")
subgroup.add_argument("--no-tools", dest="build_tools", action="store_false",
Expand Down Expand Up @@ -2199,6 +2209,7 @@ def __init__(self, args):
self.buildPython = args.build_python
self.buildExamples = args.build_examples
self.buildTutorials = args.build_tutorials
self.buildVulkan = args.build_vulkan
self.buildTools = args.build_tools

# - Imaging
Expand Down Expand Up @@ -2469,6 +2480,7 @@ def _JoinVersion(v):
Tests {buildTests}
Examples {buildExamples}
Tutorials {buildTutorials}
Vulkan {buildVulkan}
Tools {buildTools}
Alembic Plugin {buildAlembic}
HDF5 support: {enableHDF5}
Expand Down Expand Up @@ -2530,6 +2542,7 @@ def FormatBuildArguments(buildArgs):
buildTests=("On" if context.buildTests else "Off"),
buildExamples=("On" if context.buildExamples else "Off"),
buildTutorials=("On" if context.buildTutorials else "Off"),
buildVulkan=("On" if context.buildVulkan else "Off"),
buildTools=("On" if context.buildTools else "Off"),
buildAlembic=("On" if context.buildAlembic else "Off"),
buildDraco=("On" if context.buildDraco else "Off"),
Expand Down
6 changes: 5 additions & 1 deletion cmake/defaults/Packages.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,11 @@ if (PXR_BUILD_IMAGING)
list(APPEND VULKAN_LIBS Vulkan::Vulkan)

# Find the extra vulkan libraries we need
set(EXTRA_VULKAN_LIBS shaderc_combined)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(EXTRA_VULKAN_LIBS shaderc_combinedd)
else()
set(EXTRA_VULKAN_LIBS shaderc_combined)
endif()
foreach(EXTRA_LIBRARY ${EXTRA_VULKAN_LIBS})
find_library("${EXTRA_LIBRARY}_PATH" NAMES "${EXTRA_LIBRARY}" PATHS $ENV{VULKAN_SDK}/lib)
list(APPEND VULKAN_LIBS "${${EXTRA_LIBRARY}_PATH}")
Expand Down
2 changes: 1 addition & 1 deletion extras/imaging/examples/hdTiny/rendererPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ HdTinyRendererPlugin::DeleteRenderDelegate(HdRenderDelegate *renderDelegate)
}

bool
HdTinyRendererPlugin::IsSupported(bool /* gpuEnabled */) const
HdTinyRendererPlugin::IsSupported(bool /* gpuEnabled */, TfToken /*hgiToken*/) const
{
// Nothing more to check for now, we assume if the plugin loads correctly
// it is supported.
Expand Down
2 changes: 1 addition & 1 deletion extras/imaging/examples/hdTiny/rendererPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class HdTinyRendererPlugin final : public HdRendererPlugin
HdRenderDelegate *renderDelegate) override;

/// Checks to see if the plugin is supported on the running system.
virtual bool IsSupported(bool gpuEnabled = true) const override;
virtual bool IsSupported(bool gpuEnabled = true, TfToken hgiToken = TfToken("")) const override;

private:
// This class does not support copying.
Expand Down
2 changes: 1 addition & 1 deletion pxr/imaging/hd/renderPassState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ HdRenderPassState::HdRenderPassState()
, _blendEnabled(false)
, _alphaToCoverageEnabled(false)
, _colorMaskUseDefault(true)
, _useMultiSampleAov(true)
, _useMultiSampleAov(false)
, _conservativeRasterizationEnabled(false)
, _stepSize(0.f)
, _stepSizeLighting(0.f)
Expand Down
9 changes: 8 additions & 1 deletion pxr/imaging/hd/rendererPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,14 @@ HdRendererPlugin::~HdRendererPlugin() = default;
HdPluginRenderDelegateUniqueHandle
HdRendererPlugin::CreateDelegate(HdRenderSettingsMap const& settingsMap)
{
if (!IsSupported()) {
TfToken backendToken;

auto iter = settingsMap.find(TfToken("HgiBackend"));
if (iter != settingsMap.end()) {
backendToken = iter->second.Get<TfToken>();
}

if (!IsSupported(true, backendToken)) {
return nullptr;
}

Expand Down
2 changes: 1 addition & 1 deletion pxr/imaging/hd/rendererPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class HdRendererPlugin : public HfPluginBase {
/// parameter indicates if the GPU is available for use by the plugin in
/// case this information is necessary to make this determination.
///
virtual bool IsSupported(bool gpuEnabled = true) const = 0;
virtual bool IsSupported(bool gpuEnabled = true, TfToken token = TfToken("")) const = 0;

protected:
HdRendererPlugin() = default;
Expand Down
39 changes: 39 additions & 0 deletions pxr/imaging/hdSt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ set(optionalLibs "")
set(optionalIncludeDirs "")
set(optionalPublicClasses "")
set(optionalPrivateClasses "")
set(optionalPrivatehgiUnitTestClasses "")
if (${PXR_ENABLE_MATERIALX_SUPPORT})
list(APPEND optionalLibs
MaterialXGenShader
Expand All @@ -37,6 +38,9 @@ if (PXR_ENABLE_PTEX_SUPPORT)
list(APPEND optionalIncludeDirs ${PTEX_INCLUDE_DIR})
list(APPEND optionalPublicClasses ptexMipmapTextureLoader)
endif()
if (${PXR_ENABLE_VULKAN_SUPPORT})
list(APPEND optionalPrivatehgiUnitTestClasses hgiUnitTestHelper)
endif()

pxr_library(hdSt
LIBRARIES
Expand Down Expand Up @@ -179,6 +183,7 @@ pxr_library(hdSt
volumeShader
volumeShaderKey
${optionalPrivateClasses}
${optionalPrivatehgiUnitTestClasses}

RESOURCE_FILES
plugInfo.json
Expand Down Expand Up @@ -223,3 +228,37 @@ pxr_build_test(testHdStBasicDrawing
testenv/testHdStBasicDrawing.cpp
)
endif()

if (${PXR_ENABLE_VULKAN_SUPPORT})

pxr_install_test_dir(
SRC testenv/testHdStCommand
DEST testHdStCommand
)

pxr_build_test(testHdStCommand
LIBRARIES
hdSt
hgi

CPPFILES
testenv/testHdStCommand.cpp
)

pxr_register_test(testHdStCommand
#Valid command line options for this unit test are :
# -write <fileaname> // writes render output to disk
# for image based comparison with baseline
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdStCommand -write testHdStCommand_triangle.png"
IMAGE_DIFF_COMPARE
testHdStCommand_triangle.png
FAIL 1
FAIL_PERCENT 0.001
PERCEPTUAL
EXPECTED_RETURN_CODE 0
ENV
HGI_ENABLE_VULKAN=1
HGIVULKAN_DEBUG=1
HGIVULKAN_DEBUG_VERBOSE=1
)
endif()
25 changes: 20 additions & 5 deletions pxr/imaging/hdSt/codeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,16 @@
#include <sstream>
#include <unordered_map>

#ifdef PXR_VULKAN_SUPPORT_ENABLED
#define PXR_DISABLE_OSD
#endif

#if defined(__APPLE__)
#include <opensubdiv/osd/mtlPatchShaderSource.h>
#else
#include <opensubdiv/osd/glslPatchShaderSource.h>
#if !defined(PXR_DISABLE_OSD)
#include <opensubdiv/osd/glslPatchShaderSource.h>
#endif
#endif

PXR_NAMESPACE_OPEN_SCOPE
Expand Down Expand Up @@ -146,8 +152,14 @@ TF_DEFINE_PRIVATE_TOKENS(
(early_fragment_tests)
);

// For now, looks like for Vulkan path, we require HGI Resource Generation path enabled
#ifdef PXR_VULKAN_SUPPORT_ENABLED
TF_DEFINE_ENV_SETTING(HDST_ENABLE_HGI_RESOURCE_GENERATION, true,
"Enable Hgi resource generation for codeGen");
#else
TF_DEFINE_ENV_SETTING(HDST_ENABLE_HGI_RESOURCE_GENERATION, false,
"Enable Hgi resource generation for codeGen");
"Enable Hgi resource generation for codeGen");
#endif

/* static */
bool
Expand Down Expand Up @@ -1607,7 +1619,7 @@ _GetOSDCommonShaderSource()
<< "\n";

ss << OpenSubdiv::Osd::MTLPatchShaderSource::GetCommonShaderSource();
#else
#elif !defined(PXR_DISABLE_OSD)
ss << "FORWARD_DECL(MAT4 GetProjectionMatrix());\n"
<< "FORWARD_DECL(float GetTessLevel());\n"
<< "mat4 OsdModelViewMatrix() { return mat4(1); }\n"
Expand All @@ -1630,7 +1642,7 @@ _GetOSDPatchBasisShaderSource()
#if defined(__APPLE__)
ss << "#define OSD_PATCH_BASIS_METAL\n";
ss << OpenSubdiv::Osd::MTLPatchShaderSource::GetPatchBasisShaderSource();
#else
#elif !defined(PXR_DISABLE_OSD)
ss << "#define OSD_PATCH_BASIS_GLSL\n";
ss << OpenSubdiv::Osd::GLSLPatchShaderSource::GetPatchBasisShaderSource();
#endif
Expand Down Expand Up @@ -2910,7 +2922,10 @@ HdSt_CodeGen::_CompileWithGeneratedHgiResources(
resourceGen._GenerateHgiTextureResources(&gsDesc,
HdShaderTokens->geometryShader, _resTextures, _metaData);

std::string const declarations = _genDefines.str() + _genDecl.str();
std::string declarations = _genDefines.str() + _genDecl.str();
#ifdef PXR_DISABLE_OSD
declarations += _osd.str();
#endif
std::string const source = _genAccessors.str() + _genGS.str();

gsDesc.shaderCodeDeclarations = declarations.c_str();
Expand Down
7 changes: 6 additions & 1 deletion pxr/imaging/hdSt/commandBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,12 @@ HdStCommandBuffer::ExecuteDraw(
// draw batches
//
for (auto const& batch : _drawBatches) {
batch->ExecuteDraw(gfxCmds, renderPassState, resourceRegistry);
// Unless Aov attachments are cached again through another executing task,
// we do not want to reapply the load operations.
// Except the first batch, all following batch using other render passes
// will not use pre-defined load operations that may include clearing on
// load operation.
batch->ExecuteDraw(gfxCmds, renderPassState, resourceRegistry, (batch == _drawBatches.front()));
}

HD_PERF_COUNTER_SET(HdPerfTokens->drawBatches, _drawBatches.size());
Expand Down
3 changes: 2 additions & 1 deletion pxr/imaging/hdSt/drawBatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ class HdSt_DrawBatch
virtual void ExecuteDraw(
HgiGraphicsCmds *gfxCmds,
HdStRenderPassStateSharedPtr const &renderPassState,
HdStResourceRegistrySharedPtr const & resourceRegistry) = 0;
HdStResourceRegistrySharedPtr const & resourceRegistry,
bool applyUserDefinedAovDesc = false) = 0;

/// Let the batch know that one of it's draw item instances has changed
/// NOTE: This callback is called from multiple threads, so needs to be
Expand Down
Loading