diff --git a/.github/workflows/buildusd.yml b/.github/workflows/buildusd.yml index a90a903aa5d..a5d8485e81d 100644 --- a/.github/workflows/buildusd.yml +++ b/.github/workflows/buildusd.yml @@ -24,8 +24,29 @@ jobs: with: require: 'write' username: ${{ github.event.comment.user.login }} + GetGitRef: + runs-on: ubuntu-20.04 + timeout-minutes: 5 + outputs: + ref: ${{ steps.setter.outputs.ref }} + steps: + - name: Get push ref + if: ${{ github.event_name == 'push' }} + run: | + echo "REF=${{ github.ref }}" >> $GITHUB_ENV + - name: Get PR ref + if: ${{ github.event.issue.pull_request }} + run: | + echo "REF=refs/pull/${{ github.event.issue.number }}/merge" >> $GITHUB_ENV + - name: Print ENV_VAR + run: | + echo "The value of REF is $REF" + - name: Set ENV_VAR + id: setter + run: | + echo "ref=$REF" >> "$GITHUB_OUTPUT" Linux: - needs: [GetUser] + needs: [GetUser, GetGitRef] if: ${{ (github.event.issue.pull_request && contains(github.event.comment.body, '/AzurePipelines run') && needs.GetUser.outputs.require-result == 'true' ) || github.event_name == 'push' }} runs-on: ubuntu-20.04 timeout-minutes: 120 @@ -33,6 +54,8 @@ jobs: - run: echo ${{ needs.GetUser.outputs.require-result }} - name: Checkout code uses: actions/checkout@v4 + with: + ref: ${{needs.GetGitRef.outputs.ref}} - name: Restore cached artifacts id: cache-usd-build-dependency uses: actions/cache/restore@v4 @@ -68,14 +91,16 @@ jobs: path: USDinst macOS: - needs: [GetUser] + needs: [GetUser, GetGitRef] if: ${{ (github.event.issue.pull_request && contains(github.event.comment.body, '/AzurePipelines run') && needs.GetUser.outputs.require-result == 'true' ) || github.event_name == 'push' }} - runs-on: macos-12 + runs-on: macos-13 timeout-minutes: 120 steps: - run: echo ${{ needs.GetUser.outputs.require-result }} - name: Checkout code uses: actions/checkout@v4 + with: + ref: ${{needs.GetGitRef.outputs.ref}} - name: Restore cached artifacts id: cache-usd-build-dependency uses: actions/cache/restore@v4 @@ -91,7 +116,7 @@ jobs: - name: Install dependencies run: | export PATH=/Applications/CMake.app/Contents/bin:$PATH - sudo xcode-select -s /Applications/Xcode_13.3.app/Contents/Developer + sudo xcode-select -s /Applications/Xcode_14.1.app/Contents/Developer # Set SYSTEM_VERSION_COMPAT while installing Python packages to # accommodate the macOS version numbering change from 10.x to 11 export SYSTEM_VERSION_COMPAT=1 @@ -115,7 +140,7 @@ jobs: path: USDinst Windows: - needs: [GetUser] + needs: [GetUser, GetGitRef] if: ${{ (github.event.issue.pull_request && contains(github.event.comment.body, '/AzurePipelines run') && needs.GetUser.outputs.require-result == 'true' ) || github.event_name == 'push' }} runs-on: windows-2019 timeout-minutes: 120 @@ -123,6 +148,8 @@ jobs: - run: echo ${{ needs.GetUser.outputs.require-result }} - name: Checkout code uses: actions/checkout@v4 + with: + ref: ${{needs.GetGitRef.outputs.ref}} - name: Restore cached artifacts id: cache-usd-build-dependency uses: actions/cache/restore@v4 diff --git a/.github/workflows/pypi.yml b/.github/workflows/pypi.yml index 7342f277924..1c662a8fcf0 100644 --- a/.github/workflows/pypi.yml +++ b/.github/workflows/pypi.yml @@ -25,9 +25,6 @@ jobs: strategy: matrix: PYTHON: - - TAG: cp37 - INTERPRETER: /opt/python/cp37-cp37m/bin/python - VERSION_SPEC: '3.7' - TAG: cp38 INTERPRETER: /opt/python/cp38-cp38/bin/python VERSION_SPEC: '3.8' @@ -100,9 +97,6 @@ jobs: strategy: matrix: PYTHON: - - VERSION_SPEC: '3.7' - INTERPRETER: python3.7 - TAG: cp37 - VERSION_SPEC: '3.8' INTERPRETER: python3.8 TAG: cp38 @@ -115,7 +109,7 @@ jobs: - VERSION_SPEC: '3.11' INTERPRETER: python3.11 TAG: cp311 - runs-on: macos-12 + runs-on: macos-13 timeout-minutes: 120 steps: - name: Checkout code @@ -131,7 +125,7 @@ jobs: ${{ matrix.PYTHON.INTERPRETER }} -m pip install delocate~=0.10.2 wheel - name: Build USD run: | - sudo xcode-select -s /Applications/Xcode_13.3.app/Contents/Developer + sudo xcode-select -s /Applications/Xcode_14.1.app/Contents/Developer ${{ matrix.PYTHON.INTERPRETER }} build_scripts/build_usd.py --build-args USD,"-DPXR_PY_UNDEFINED_DYNAMIC_LOOKUP=ON -DPXR_BUILD_USD_TOOLS=OFF -DPXR_INSTALL_LOCATION=../pluginfo" --no-materialx --no-imaging --no-examples --no-tutorials --generator Xcode --build-target universal --build $GITHUB_WORKSPACE/USDgen/build --src $GITHUB_WORKSPACE/USDgen/src $GITHUB_WORKSPACE/USDinst -v - name: Packaging USD run: | @@ -174,8 +168,6 @@ jobs: strategy: matrix: PYTHON: - - VERSION_SPEC: '3.7' - TAG: cp37 - VERSION_SPEC: '3.8' TAG: cp38 - VERSION_SPEC: '3.9' @@ -253,10 +245,6 @@ jobs: strategy: matrix: BUILD_CONFIG: - - NAME: Linux_Python37 - PYTHON_VERSION_SPEC: '3.7' - IMAGE: ubuntu-20.04 - PYTHON_INTERPRETER: python3 - NAME: Linux_Python38 PYTHON_VERSION_SPEC: '3.8' IMAGE: ubuntu-20.04 @@ -273,30 +261,22 @@ jobs: PYTHON_VERSION_SPEC: '3.11' IMAGE: ubuntu-20.04 PYTHON_INTERPRETER: python3 - - NAME: Mac_Python37 - PYTHON_VERSION_SPEC: '3.7' - IMAGE: macos-12 - PYTHON_INTERPRETER: python3 - NAME: Mac_Python38 PYTHON_VERSION_SPEC: '3.8' - IMAGE: macos-12 + IMAGE: macos-13 PYTHON_INTERPRETER: python3 - NAME: Mac_Python39 PYTHON_VERSION_SPEC: '3.9' - IMAGE: macos-12 + IMAGE: macos-13 PYTHON_INTERPRETER: python3 - NAME: Mac_Python310 PYTHON_VERSION_SPEC: '3.10' - IMAGE: macos-12 + IMAGE: macos-13 PYTHON_INTERPRETER: python3 - NAME: Mac_Python311 PYTHON_VERSION_SPEC: '3.11' - IMAGE: macos-12 + IMAGE: macos-13 PYTHON_INTERPRETER: python3 - - NAME: Windows_Python37 - PYTHON_VERSION_SPEC: '3.7' - IMAGE: windows-2019 - PYTHON_INTERPRETER: python3 - NAME: Windows_Python38 PYTHON_VERSION_SPEC: '3.8' IMAGE: windows-2019 diff --git a/BUILDING.md b/BUILDING.md index 6ff8de46cad..c2c16b0a042 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -36,7 +36,6 @@ Some examples: cmake \ -DTBB_ROOT_DIR=/path/to/tbb \ -DOPENSUBDIV_ROOT_DIR=/path/to/opensubdiv \ --DBOOST_ROOT=/path/to/boost \ /path/to/USD/source cmake --build . --target install -- -j @@ -51,7 +50,6 @@ cmake \ -G "Xcode" \ -DTBB_ROOT_DIR=/path/to/tbb \ -DOPENSUBDIV_ROOT_DIR=/path/to/opensubdiv \ --DBOOST_ROOT=/path/to/boost \ /path/to/USD/source cmake --build . --target install -- -j @@ -67,7 +65,6 @@ build USD. -G "Visual Studio 15 2017 Win64" ^ -DTBB_ROOT_DIR=C:\path\to\tbb ^ -DOPENSUBDIV_ROOT_DIR=C:\path\to\opensubdiv ^ --DBOOST_ROOT=C:\path\to\boost ^ \path\to\USD\source cmake --build . --target install -- /m:%NUMBER_OF_PROCESSORS% @@ -722,14 +719,7 @@ Client code can also override the default as needed. ## Build Issues FAQ -1. Boost_NO_BOOST_CMAKE: -We currently set Boost_NO_BOOST_CMAKE=ON explicitly in USD builds for all -platforms to avoid issues with Boost config files (introduced in Boost version -1.70) and python, program options component requirements. If the user wants -to use Boost specified config files for their USD build, specify --DBoost_NO_BOOST_CMAKE=OFF when running cmake. - -2. Windows and Python 3.8+ (non-Anaconda) +1. Windows and Python 3.8+ (non-Anaconda) Python 3.8 and later on Windows will no longer search PATH for DLL dependencies. Instead, clients can call `os.add_dll_directory(p)` to set paths to search. By default on that platform USD will iterate over PATH and add all paths using diff --git a/CHANGELOG.md b/CHANGELOG.md index 68e0ca21cf2..084e873cbf1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,532 @@ # Change Log +## [24.11] - 2024-10-25 + +### Build + +- Removed boost dependency from OpenUSD. Note that boost must still be supplied + when OpenVDB support is enabled due to its use of boost in headers. + +- OpenUSD now uses its own internal pxr_boost::python library for generating + Python bindings instead of boost::python. + - Types from OpenUSD like Usd.Stage will no longer interoperate with other C++ + code that have been wrapped with boost::python. Client code with Python + bindings that interoperate with OpenUSD types must be updated to use the new + pxr_boost::python library. In particular, schema libraries should be + regenerated to pick up the new library. + - Users can revert to the old behavior of using boost::python by specifying + `PXR_USE_BOOST_PYTHON=ON` when running CMake. This option is for testing and + transition purposes; it is deprecated and will be removed in a future release. + +- Added "--boost-python" option to build_usd.py for building OpenUSD's Python + bindings with boost::python. This option is for testing and transition + purposes; it is deprecated and will be removed in a future release. + Note that the build script will continue to build boost if it's needed by + optional dependencies. These include OpenImageIO and OpenVDB. + +- Enabled support for imaging and usdImaging on Apple embedded platforms. + (PR: [#3215](https://github.com/PixarAnimationStudios/OpenUSD/pull/3215)) + +- OpenUSD's internal namespace now includes the patch version to help + distinguish releases within the same year. + (PR: [#3167](https://github.com/PixarAnimationStudios/OpenUSD/pull/3167)) + +- Removed support for usd-core PyPI package for Python 3.6 and deprecated + support for Python 3.7. + +### USD + +- Updated Tf file utilities to ignore reparse points on network file systems on + Windows. Reparse points on these systems are unlikely to be accessible from + the remote machines. + (PR: [#2934](https://github.com/PixarAnimationStudios/OpenUSD/pull/2934)) + +- Updated pxrTslRobinMap to latest release, 1.3.0, using erase_fast instead + of erase when the returned iterator is not needed. + (PR: [#3253](https://github.com/PixarAnimationStudios/OpenUSD/pull/3253), + [#3255](https://github.com/PixarAnimationStudios/OpenUSD/pull/3255)) + +- Added support for named color spaces from the Color Interchange Forum to + GfColorSpace. + +- Added Gf.Color and Gf.ColorSpace Python bindings. + +- Removed overloads of GfMatrix4d::Transform, GfMatrix4d::TransformAffine, + GfMatrix4d::TransformDir, and GfRotation::TransformDir that take and return + GfVec3f, as they can potentially result in loss of precision. Matrix-vector + multiplication operators for double precision matrix types and single + precision vector types have also been removed. These were deprecated in 24.05. + +- Exposed Python bindings for ArAsset, enabling operations such as + ArResolver.OpenAsset(resolvedPath) to allow reading ArAsset buffers from + Python. + (PR: [#3318](https://github.com/PixarAnimationStudios/OpenUSD/pull/3318)) + +- Various updates and fixes made for relocates. + - Fixed a bug where ancestral relocates weren't properly elided, leading to + verification failures and crashes. + - Fixed a bug with Pcp dependencies where some prim indexes from nested + relocates aren't invalidated when one of the ancestral relocates is + updated. + +- Improved how Pcp generates changelists for muting/unmuting layers and + adding/removing sublayers, improving performance especially in large stages. + Change notifications to external clients remain unaffected, and legacy + behavior is retained for layers that may contain relocates. This optimization + is still in development and is disabled by default. It can be enabled + by setting the environment variable + PCP_ENABLE_MINIMAL_CHANGES_FOR_LAYER_OPERATIONS = 1. + +- Deprecated time sample related methods on SdfLayer, to be removed in the next + release. SdfAttributeSpec now owns these time sample related methods. + +- Converted NdrSdfTypeIndicator from a std::pair to a full class. + +- Removed residual member function declaration for SdfPath. + (PR: [#3254](https://github.com/PixarAnimationStudios/OpenUSD/pull/3254)) + +- Enhanced SdfCopySpec() to handle overlapping source/destination by copying the + source to a temporary anonymous layer first, then copying that temporary to + the destination. + (Issue: [#3095](https://github.com/PixarAnimationStudios/OpenUSD/issues/3095)) + +- Initial work done on animation curves in USD. + +- Fixed performance issue writing .usdc files with high time sample counts. + (Issue: [#3249](https://github.com/PixarAnimationStudios/OpenUSD/issues/3249)) + +- Reimplemented .usda text file parser using PEGTL. This removes a dependency on + lex/yacc and also provides some performance improvements. + (PR: [#3005](https://github.com/PixarAnimationStudios/OpenUSD/pull/3005), + [#3293](https://github.com/PixarAnimationStudios/OpenUSD/pull/3293), + [#3294](https://github.com/PixarAnimationStudios/OpenUSD/pull/3294)) + +- Fixed bugs in the namespace-editing code that caused unnecessary and incorrect + edits to children defined by upstream composition dependencies. + +- Various updates for new Validation framework: + - Updated UsdValidationError to include a name property, used along with the + validator name to create an error identifier. This identifier can be used to + categorize and filter errors, especially when a validator can generate + multiple errors of different types. The error identifier is of the form + "validatorName"."ErrorName" or "plugName":"validatorName"."ErrorName". + - Added UsdValidationContext concept, which can be constructed by selecting + validators using keywords, plugins, validator metadata, schema types, or + pre-selected sets of validators. Validators for ancestor schema types are + also considered when selecting validators for a validation context. Clients + can use Validate() API to validate a layer, stage, or a set of prims with + parallel execution and error collection. UsdValidationContext initialization + may load plugins in order to load the validators. UsdValidationContext is a + stateless context, which means that clients handle validation input and + result tracking. + - Updated UsdValidationRegistry to be immortal, which means that any + registered validators and validator suites are also immortal. + - Added schema validators using the new Validation framework: + - Added StageMetadata Validator for usdGeom domain. + (PR: [#3134](https://github.com/PixarAnimationStudios/OpenUSD/pull/3134)) + - Added StageMetadata Validator for core USD. + (PR: [#3125](https://github.com/PixarAnimationStudios/OpenUSD/pull/3125)) + - Added SkelBindingApiAppliedValidator and SkelBindingApiValidator for + usdSkel domain. + (PR: [#3166](https://github.com/PixarAnimationStudios/OpenUSD/pull/3166)) + - Added MaterialBindingApiAppliedValidator, EncapsulationRulesValidator for + usdShade domain. + (PR: [#3154](https://github.com/PixarAnimationStudios/OpenUSD/pull/3154)) + (PR: [#3227](https://github.com/PixarAnimationStudios/OpenUSD/pull/3227)) + - Added a Usdz Package Encapsulation Validator for usdUtils domain. + (PR: [#3206](https://github.com/PixarAnimationStudios/OpenUSD/pull/3206)) + - Added validators for UsdGeomSubsets + (PR: [#3123](https://github.com/PixarAnimationStudios/OpenUSD/pull/3123)) + - Updated UsdValidationErrorType to be registered as TfEnum. + (PR: [#3223](https://github.com/PixarAnimationStudios/OpenUSD/pull/3223)) + - Added Python bindings for UsdValidatorMetadata, UsdValidator, + UsdValidatorSuite, UsdValidationError, UsdValidationErrorSite, + UsdValidationErrorType and UsdValidationRegistry. + (PR: [#3232](https://github.com/PixarAnimationStudios/OpenUSD/pull/3232)) + (PR: [#3236](https://github.com/PixarAnimationStudios/OpenUSD/pull/3236)) + (PR: [#3242](https://github.com/PixarAnimationStudios/OpenUSD/pull/3242)) + +- Added support for `BlockCollection()` and `ResetCollection()` to + `UsdCollectionAPI` for expression-mode collections. Also added + `IsInExpressionMode()` and `IsInRelationshipsMode()` convenience APIs. + +- usdGenSchema now adds a schemaIdentifier field to schema plugInfo metadata. + When present, this field will be used as the schema's identifier in the schema + registry. If not, the alias under UsdSchemaBase will be used. + +- Updated usdGenSchema to generate helper files used in the build so that when + adding a new schema class to a schema library, users will just need to re-run + usdGenSchema instead of having to name the generated files manually in + CMakeLists.txt + +- Updated sdrOslParser to provide metadata (usdSchemaDef_* and + sdrGlobalConfig_*) used for schema generation via usdgenschemafromsdr. This + allows clients to generate USD schema from OSL shader definitions which are + registered via sdr. + +- Added a new usdSemantics module which includes a SemanticsLabelsAPI schema + for labeling prims with tokens. The implementation diverges slightly with + [the proposal](https://github.com/PixarAnimationStudios/OpenUSD-proposals/tree/main/proposals/semantic_schema) + with the taxonomy being after "labels" instead of before in the property name + (e.g., `semantics:labels:` instead of `semantics::labels`). + In addition to the schema, UsdSemanticsLabelsQuery provides a reference for + how ancestor labeling is expected to work and inherit. + (PR: [#3103](https://github.com/PixarAnimationStudios/OpenUSD/pull/3103)) + +- Added support for elementType "segment" to UsdGeomSubset, where "segment" + refers to a segment of a UsdGeomBasisCurves object. + +- Updated UsdLuxCylinderLight bounds computation to use X axis as major axis. + (Issue: [#3233](https://github.com/PixarAnimationStudios/OpenUSD/issues/3233), + PR: [#3246](https://github.com/PixarAnimationStudios/OpenUSD/pull/3246)) + +- Removed RenderDenoisePass from usdRender schemas. + +- Fixed crash in UsdSkelAnimQuery::ComputeJointLocalTransformComponents when + translate, rotate, or scale attributes are not present. + +- Updated UsdUtils.UpdateSchemaWithSdrNode to populate the shaderId attribute + for all shaderNodes across sourceTypes for the same identifier. + +- Added Python performance module under extras directory in support of local + performance testing and for tracking performance over OpenUSD releases. See + usdmeasureperformance.py and + [documentation](https://openusd.org/release/ref_performance_metrics.html) + for more details. + +### Hydra + +- Storm and HdPrman lighting/shading have been updated to be more consistent + when combining different material types and light types. Physically based + lighting and physically based materials have not changed; nor have camera + lights and fallback materials. However, camera lights and physically based + materials will appear brighter, and physically based lights and fallback + materials will appear darker, in order to produce correct lighting response. + +- Made change to allow the generative procedural resolving scene index to be + more easily toggled (via a new switchingSceneIndex). + +- Added a new filtering scene index: HdsiPrimTypeAndPathPruningSceneIndex. One + use case is to switch between camera and scene lights by changing the path + predicate. + +- Fixed a problem with motion blur when using HdRenderIndex::InsertSceneIndex, + where the shutter interval was not communicated from the render delegate to + emulation. Hence, emulation called GetContributingSampleTimesForInterval on an + HdSampledDataSource returned by the inserted scene index with a bad + startTime/endTime. + +- Overhauled HdExtComputationSchema and related schemas. In particular, + introduced HdExtComputationCpuCallback and changed the CPU callback data + source to return the new type. + +- Added typed getters and setters to HdExtComputationContext. + +- Introduced HdsiExtComputationDependencySceneIndex which clients can use + together with the HdsiExtComputationPrimvarPruningSceneIndex to evaluate and + invalidate ext computation primvars. + +- Added the WithOrientation method to PxOsdMeshTopology which behaves similar to + the WithScheme and WithHoleIndices methods. It returns a copy of the mesh + topology object except with the orientation set to the given orientation. + +- Added GeomUtilDiskMeshGenerator for generating disk-shaped meshes. + +- Fixed the GeomUtilCapsuleMeshGenerator so that the height, bottom radius, and + top radius of the cylindrical portion of the capsule is retained and the + spheres are adjusted to maintain continuity with the cylinder sides, as + defined in the documentation for UsdGeomCapsule. + +- Altered how the numCapAxial parameter works for GeomUtilCapsuleMeshGenerator + when the radii are different. When the radii differ, the numCapAxial parameter + is doubled and the number of cross-sections are divided between the top and + bottom hemispheres relative to the angle that each portion uses. This makes + the density of the mesh more even between the bottom and top when the radii + difference is large. + +- Added normals generation to the various mesh generation utility classes. + Similar to the point generation, the classes provide a method that returns the + number of normals and a method for generating the normals into a provided + container iterator. In addition, the interpolation mode of the normals can be + requested. + +- Made improvements to the light linking scene index. Added support for + non-nested native and point instancers and significantly improved invalidation + performance. + +- Prefixed predicate expressions with "hd" for clarity and deprecated existing + predicates. + +- Added render index API to allow batching of notices sent by the merging scene + index. + +- Fixed a subtle bug in the generative procedural resolving scene index to not + cook procedurals in response to scene queries. + +- Added RecipeMaterialOverride schema. + +- Added HdsiMaterialOverrideResolvingSceneIndex to resolve material overrides. + +- Fixed bug with loading monochrome .exr images. + (PR: [#3343](https://github.com/PixarAnimationStudios/OpenUSD/pull/3343)) + +### UsdImaging + +- Added support for UsdGeomPlane in Scene Index mode. + +- Added UsdImagingModelSchema for any prim that has UsdModelAPI data in Scene + Index mode, including models demoted to act as subcomponents within other + models. + +- Fixed a bug causing spurious warnings about "implementationSource" for lights. + +- Fixed an invalidation bug so that when a material is edited, prims with + that material bound will have their primvars correctly invalidated. + (Issue: [#2382](https://github.com/PixarAnimationStudios/OpenUSD/issues/2382)) + +- Fixed DeprecationWarning in usdviewq/appController.py caused by a regex + containing an invalid escape sequence. + (PR: [#2955](https://github.com/PixarAnimationStudios/OpenUSD/pull/2955)) + +- Added AOV light adapter for transporting USD AOV lights to Hydra. + +### Storm + +- Fixed Vulkan buffer leaks in HdSt_PipelineDrawBatch. + (PR: [#3313](https://github.com/PixarAnimationStudios/OpenUSD/pull/3313)) + +- Improved Lavapipe support, enabling the Vulkan driver as a software rasterizer + on macOS. + (PR: [#3121](https://github.com/PixarAnimationStudios/OpenUSD/pull/3121)) + +- Added support for configurable anisotropic filtering in Storm and Hgi. We now + disable anisotropy for certain texture/sampler uses such as dome light + textures and AOVs. + (PR: [#3216](https://github.com/PixarAnimationStudios/OpenUSD/pull/3216)) + +- Fixed deadlock when Vulkan command buffers are consumed faster than they are + executed. + (PR: [#3170](https://github.com/PixarAnimationStudios/OpenUSD/pull/3170)) + +- Updated simpleLights to increase the brightness when used with physically + based materials (for example, UsdPreviewSurface or MaterialX). + +- Updated fallback shading to decrease the brightness when used with physically + based lights (like UsdLux), for consistency with physically based materials. + +- Fixed displacement shading when using vertex or varying displacement + parameterization with Metal. + (Issue: [#3248](https://github.com/PixarAnimationStudios/OpenUSD/issues/3248)) + +- Updated drawing of selected mesh edges to eliminate the need to apply a depth + offset in the geometry shader. + +- Exposed an option in HdMeshReprDesc to enable generation of surface edge ids + for surface and hull geom styles which do not otherwise draw edges. This + option is disabled by default which avoids enabling geometry shader stages for + more use cases. + (PR: [#3071](https://github.com/PixarAnimationStudios/OpenUSD/pull/3071)) + +- Shaders for basis curves rprims that are rendered as ribbons are now provided + with a texture coordinate that varies over the width of the curve, via the + patchCoord argument to the shader terminal. + +- Fixed potential texture memory leak by explicitly calling garbage collection + of the necessary subsystem from resource registry's garbage collection. + +- Storm draw target clients no longer need to call + HdChangeTracker::MarkStateDirty when a draw target gets disabled and enabled. + Storm automatically does the necessary invalidation by tracking the version + number of the active draw target set in HdStRenderParam. + +- Fixed the deep selection resolve mode for the "pickPointsAndInstances" pick + target. + +- Fixed missing include in glslProgram. + (PR: [#3283](https://github.com/PixarAnimationStudios/OpenUSD/pull/3283)) + +### RenderMan Hydra Plugin + +- **Important**: Removed hdPrman for RenderMan 25. This was deprecated in USD + 24.08 + +- usdRiPxr schemas for rman26.3 are not bundled with OpenUSD and instead will be + installed during a OpenUSD build from the specified RenderMan location. + +- Added support for the official RenderMan PxrPrimvarAPI schema in HdPrman. + +- Fixed a bug with missing invalidation of time-varying primvars in Scene Index + mode. This would manifest as a stale primvar value after changing the input + scene time during a render. + +- Added HD_PRMAN_INTERACTIVE_RENDER_WITH_RENDER_SETTINGS which adds the render + settings' products to the task's AOV bindings in the render view. + +- Updated simpleLights (that is, lights set via + HdxTaskController::SetLightingState) to increase the brightness when used with + or without materials. + +- Added many preprocessor directives as needed to support compiling against USD + versions back to 22.05. + +- hdPrman now respects an env var called RMAN_XPU_GPUGCONFIG that can be set + with a comma delimited list of the indexes of the selected GPUs. + +- Updated the use of ri:checkpoint:exitat to work independently of + ri:checkpoint:interval being set. + +- Updated to use "Shutter settings" on the camera and ignore ri:shutter render + setting. + +- Updated PxrBakeTexture to correctly write to non tex files which exist on disk. + +- Fixed a bug where switching between VDB volumes that kept the same path name + would not update in the interactive render. + +- Fixed a bug where interactively editing the Material Sync Mode of a + PxrMeshLight would not trigger the expected update of the mesh light + geometry's visibility. Note that mesh light support is still in active + development and will be enabled in a future release. + +- Fixed a crash that could happen when switching between RenderMan Hydra + delegates in Katana. + +- Added support for environment variable HD_PRMAN_TEX_EXTS that accepts a + colon-separated list of extensions known to be tex compatible, e.g. "tex:txr". + +- Fixed a bug where UDIM textures used by the USDUvTexture node would be flipped + incorrectly. + +- Updated Volume prims with primvar named "vel" or "velocity" to infer the type + to be vector rather than float. + +- Support for the PRMAN_OSL_BEFORE_RIXPLUGINS environment variable to allow + resolving OSL shaders before C++. + +- Support finding MaterialX search paths at runtime based on a DCC install + location. + +- Support naming the hdPrman delegate something other than "Prman". + +- Support Ri:PixelFilterName and Ri:PixelFilterWidth options. + +- Various updates to SideFX Solaris support. + - Enabled the use of interactive denoiser from within Solaris. + - Fixed a bug where background renders in Solaris could lead to a crash if a + RIS render was already running interactively or if the output type of the + render was not set to "raster". + - Fixed a bug where pixelAspectRatio wasn't having the expected effect. + - Fixed some issues with MaterialX in Solaris. + - Fixed problem where hdPrman would keep rendering in the background when the + viewport switched to the GL renderer in Solaris. + - Improved data/display window calculation and removed clamp on overscan. + - Added support for aggregate volumes in Solaris. + - Added HD_PRMAN_HIDE_DEFAULT_DOMELIGHT_TEXTURE environment variable, which, + when set, forces any textured dome lights with a prefix of `` + or `` to be camera-invisible, as a temporary measure to + support Solaris. + +- Improved hdPrman compatibility with the Hush SideFX command line rendering + utility. + +- More work on hdPrman Hydra 2.0 transition. The following assumes a recent USD + version but does not require HD_PRMAN_EXPERIMENTAL_RILEY_SCENE_INDEX_OBSERVER. + The HdPrman_RileyGlobalsSceneIndex filtering scene index now computes some of + the Riley options to add a riley:globals prim. hdPrman's + HdsiPrimManagingSceneIndexObserver picks up the options on the riley:globals + prim and makes them contribute to the Riley::SetOptions call. + +- Fixed a bug where rendering a product without vars led to a crash in RenderMan. + +- Added support for PxrEnvDayLight. + +- Small performance cleanup for purpose-based visibility. + +### MaterialX + +- Made a change to how MaterialX node names are constructed from material + network node paths to support Solaris. This change only affects hdPrman built + as part of a DCC. + +- Fixed issue with Storm when rendering custom nodes that use the + node in their defining nodegraph, and either re-use that node's output or are + a multi-output node. + +- Fixed divide by zero issue in the calculation of a light's intensity value + inside Storm's MaterialX glslfx shader. + +- Added support for custom texture nodes in hdPrman. + +- Switched the USD name of surface shader nodes to use the MaterialX node name + instead of the NodeDef name. + (Issue: [#3100](https://github.com/PixarAnimationStudios/OpenUSD/issues/3100), + PR: [#3147](https://github.com/PixarAnimationStudios/OpenUSD/pull/3147)) + +- Fixed shadow support for MaterialX materials in Metal. + (Issue: [#3176](https://github.com/PixarAnimationStudios/OpenUSD/issues/3176), + PR: [#3264](https://github.com/PixarAnimationStudios/OpenUSD/pull/3264)) + +- Fixed testUsdMtlxFileFormat.py. + (PR: [#3147](https://github.com/PixarAnimationStudios/OpenUSD/pull/3147)) + +- Added more function tracing in UsdMtlx. + (PR: [#2806](https://github.com/PixarAnimationStudios/OpenUSD/pull/2806)) + +### Embree Hydra Plugin + +- Fixed a bug in HdEmbree random number generation. + (PR: [#3211](https://github.com/PixarAnimationStudios/OpenUSD/pull/3211)) + +- Added HDEMBREE_RANDOM_NUMBER_SEED to facilitate stable image testing. + (PR: [#3183](https://github.com/PixarAnimationStudios/OpenUSD/pull/3183)) + +- Typo fix and refactoring of ray hit code. + (PR: [#3185](https://github.com/PixarAnimationStudios/OpenUSD/pull/3185)) + +### usdview + +- Made a fix to correctly handle device pixel ratio with multi-display setups. + +- Added applied API schema data to the usdview "Meta Data" tab. + (Issue: [#1431](https://github.com/PixarAnimationStudios/OpenUSD/issues/1431)) + +### Documentation + +- Added new [performance metrics page](https://openusd.org/release/ref_performance_metrics.html) + to docs, used to publish metrics for each release, and describe how metrics + are measured. + +- Various documentation updates: + - Improvements to Hydra prim schema documentation. + - Updated docs to clarify schema strength ordering. + - Additional doc fixes. + (PR: [#2695](https://github.com/PixarAnimationStudios/OpenUSD/pull/2695), + [#3287](https://github.com/PixarAnimationStudios/OpenUSD/pull/3287)) + +- SIGGRAPH 2024 BoF slides PDF added to [Downloads page](https://openusd.org/release/dl_downloads.html). + +- [Contributing to USD](https://openusd.org/release/contributing_to_usd.html) + page updated with instructions to use when making major changes. + +- Added [Security Policy](https://github.com/PixarAnimationStudios/OpenUSD/blob/release/SECURITY.md) + with details on reporting security vulnerabilities with USD. + +- Switched .dox files in pxr/usd/usd to Markdown files (which addressed some + formatting issues), and renamed enclosing directory to "docs". We recommend + Markdown for new modules, as this makes the documentation more portable. + +- Updated URL to USD Assets Working Group "Primvar Interpolation" asset in the + Rendering with USD user guide. + (PR: [#3110](https://github.com/PixarAnimationStudios/OpenUSD/pull/3110)) + +### Security + +- Fixed crash when reading .usdc file with corrupt SdfSpecType values, see + [security advisory on github](https://github.com/PixarAnimationStudios/OpenUSD/security/advisories/GHSA-4j7j-gm3f-m63w). + +
+ Previous Releases + ## [24.08] - 2024-07-25 OpenUSD is now licensed under the Tomorrow Open Source Technology license. This @@ -621,8 +1148,6 @@ validators were also added: in relationship-mode vs expression-mode, and how the built-in properties affect membership determination in each mode. -
- Previous Releases ## [24.05] - 2024-04-19 diff --git a/README.md b/README.md index 4d5a2945077..3ae449e39b8 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,6 @@ Optional: Required: - [Python](https://python.org) - - [Boost](https://boost.org) **usdview** diff --git a/VERSIONS.md b/VERSIONS.md index c3caf2ed56e..5783e3f99d3 100644 --- a/VERSIONS.md +++ b/VERSIONS.md @@ -17,7 +17,6 @@ Our test machines have the following software versions installed. | C++ Compiler | gcc 9.3.1 | Apple clang 13.1.6 (Xcode 13.3)
Apple clang 15.0.0 (Xcode 15.4) for visionOS | Visual Studio 2017 15.9 | | CMake | 3.17.5 | 3.19.5 | 3.25.3 | | Python | 3.9.16 | 3.9.13 | 3.9.13 | -| Boost | 1.76.0 | 1.78.0 | 1.76.0 | | Intel TBB | 2020 Update 3 | 2018 Update 1, 2020 Update 3 | 2020 Update 3 | | OpenSubdiv | 3.6.0 | 3.6.0 | 3.6.0 | | OpenImageIO | 2.3.21.0 | 2.3.21.0 | 2.3.21.0 | diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 57364f62f78..6d36618ee51 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -25,12 +25,12 @@ jobs: - job: macOS timeoutInMinutes: 120 pool: - vmImage: 'macOS-12' + vmImage: 'macOS-13' steps: - script: | # Update PATH to ensure that pyside2-uic can be found export PATH=/Library/Frameworks/Python.framework/Versions/3.11/bin:$PATH - sudo xcode-select -s /Applications/Xcode_13.3.app/Contents/Developer + sudo xcode-select -s /Applications/Xcode_14.1.app/Contents/Developer # Set SYSTEM_VERSION_COMPAT while installing Python packages to # accommodate the macOS version numbering change from 10.x to 11 export SYSTEM_VERSION_COMPAT=1 @@ -51,7 +51,7 @@ jobs: steps: - script: | call C:\"Program Files (x86)"\"Microsoft Visual Studio"\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat - call set PYTHONLOCATION=C:\hostedtoolcache\windows\Python\3.7.9\x64 + call set PYTHONLOCATION=C:\hostedtoolcache\windows\Python\3.9.13\x64 call set PYTHONBIN=%PYTHONLOCATION%\python.exe call set PATH=%PYTHONLOCATION%;%PYTHONLOCATION%\Scripts;%PATH% call set BOOST_ROOT= diff --git a/azure-pypi-pipeline.yml b/azure-pypi-pipeline.yml index 23a20bfad71..38080877c46 100644 --- a/azure-pypi-pipeline.yml +++ b/azure-pypi-pipeline.yml @@ -45,12 +45,6 @@ stages: - job: Linux strategy: matrix: - Python36: - PYTHON_INTERPRETER: /opt/python/cp36-cp36m/bin/python - PYTHON_TAG: cp36 - Python37: - PYTHON_INTERPRETER: /opt/python/cp37-cp37m/bin/python - PYTHON_TAG: cp37 Python38: PYTHON_INTERPRETER: /opt/python/cp38-cp38/bin/python PYTHON_TAG: cp38 @@ -119,12 +113,6 @@ stages: - job: Windows strategy: matrix: - Python36: - PYTHON_VERSION_SPEC: 3.6 - PYTHON_TAG: cp36 - Python37: - PYTHON_VERSION_SPEC: 3.7 - PYTHON_TAG: cp37 Python38: PYTHON_VERSION_SPEC: 3.8 PYTHON_TAG: cp38 @@ -179,14 +167,6 @@ stages: - job: Mac strategy: matrix: - Python36: - PYTHON_VERSION_SPEC: 3.6 - PYTHON_INTERPRETER: python3.6 - PYTHON_TAG: cp36 - Python37: - PYTHON_VERSION_SPEC: 3.7 - PYTHON_INTERPRETER: python3.7 - PYTHON_TAG: cp37 Python38: PYTHON_VERSION_SPEC: 3.8 PYTHON_INTERPRETER: python3.8 @@ -209,14 +189,14 @@ stages: PYTHON_TAG: cp312 timeoutInMinutes: 180 pool: - vmImage: 'macOS-12' + vmImage: 'macOS-13' steps: - task: UsePythonVersion@0 inputs: versionSpec: $(PYTHON_VERSION_SPEC) addToPath: true - script: | - sudo xcode-select -s /Applications/Xcode_13.2.app/Contents/Developer + sudo xcode-select -s /Applications/Xcode_14.1.app/Contents/Developer $(PYTHON_INTERPRETER) build_scripts/build_usd.py --build-args USD,"-DPXR_PY_UNDEFINED_DYNAMIC_LOOKUP=ON -DPXR_BUILD_USD_TOOLS=OFF -DPXR_INSTALL_LOCATION=../pluginfo" --no-materialx --no-imaging --no-examples --no-tutorials --generator Xcode --build-target universal --build $HOME/USDgen/build --src $HOME/USDgen/src $HOME/USDinst -v displayName: 'Building USD' - bash: | @@ -284,14 +264,6 @@ stages: - job: Test_Install strategy: matrix: - Linux_Python36: - PYTHON_VERSION_SPEC: 3.6 - IMAGE: 'Ubuntu-20.04' - PYTHON_INTERPRETER: python3 - Linux_Python37: - PYTHON_VERSION_SPEC: 3.7 - IMAGE: 'Ubuntu-20.04' - PYTHON_INTERPRETER: python3 Linux_Python38: PYTHON_VERSION_SPEC: 3.8 IMAGE: 'Ubuntu-20.04' @@ -312,14 +284,6 @@ stages: PYTHON_VERSION_SPEC: 3.12 IMAGE: 'Ubuntu-20.04' PYTHON_INTERPRETER: python3 - Windows_Python36: - PYTHON_VERSION_SPEC: 3.6 - IMAGE: 'windows-2019' - PYTHON_INTERPRETER: python - Windows_Python37: - PYTHON_VERSION_SPEC: 3.7 - IMAGE: 'windows-2019' - PYTHON_INTERPRETER: python Windows_Python38: PYTHON_VERSION_SPEC: 3.8 IMAGE: 'windows-2019' @@ -340,33 +304,25 @@ stages: PYTHON_VERSION_SPEC: 3.12 IMAGE: 'windows-2019' PYTHON_INTERPRETER: python - Mac_Python36: - PYTHON_VERSION_SPEC: 3.6 - IMAGE: 'macOS-12' - PYTHON_INTERPRETER: python3 - Mac_Python37: - PYTHON_VERSION_SPEC: 3.7 - IMAGE: 'macOS-12' - PYTHON_INTERPRETER: python3 Mac_Python38: PYTHON_VERSION_SPEC: 3.8 - IMAGE: 'macOS-12' + IMAGE: 'macOS-13' PYTHON_INTERPRETER: python3 Mac_Python39: PYTHON_VERSION_SPEC: 3.9 - IMAGE: 'macOS-12' + IMAGE: 'macOS-13' PYTHON_INTERPRETER: python3 Mac_Python310: PYTHON_VERSION_SPEC: 3.10 - IMAGE: 'macOS-12' + IMAGE: 'macOS-13' PYTHON_INTERPRETER: python3 Mac_Python311: PYTHON_VERSION_SPEC: 3.11 - IMAGE: 'macOS-12' + IMAGE: 'macOS-13' PYTHON_INTERPRETER: python3 Mac_Python312: PYTHON_VERSION_SPEC: 3.12 - IMAGE: 'macOS-12' + IMAGE: 'macOS-13' PYTHON_INTERPRETER: python3 timeoutInMinutes: 10 pool: diff --git a/cmake/defaults/Version.cmake b/cmake/defaults/Version.cmake index e9657e399e4..6dd5d5f2d95 100644 --- a/cmake/defaults/Version.cmake +++ b/cmake/defaults/Version.cmake @@ -6,7 +6,7 @@ # # Versioning information set(PXR_MAJOR_VERSION "0") -set(PXR_MINOR_VERSION "24") -set(PXR_PATCH_VERSION "11") # NOTE: Must not have leading 0 for single digits +set(PXR_MINOR_VERSION "25") +set(PXR_PATCH_VERSION "2") # NOTE: Must not have leading 0 for single digits math(EXPR PXR_VERSION "${PXR_MAJOR_VERSION} * 10000 + ${PXR_MINOR_VERSION} * 100 + ${PXR_PATCH_VERSION}") diff --git a/cmake/defaults/msvcdefaults.cmake b/cmake/defaults/msvcdefaults.cmake index 13d77d0ae7e..e8823599ae0 100644 --- a/cmake/defaults/msvcdefaults.cmake +++ b/cmake/defaults/msvcdefaults.cmake @@ -11,6 +11,13 @@ set(_PXR_CXX_FLAGS "${_PXR_CXX_FLAGS} /EHsc") # Standards compliant. set(_PXR_CXX_FLAGS "${_PXR_CXX_FLAGS} /Zc:rvalueCast /Zc:strictStrings") +# Visual Studio sets the value of __cplusplus to 199711L regardless of +# the C++ standard actually being used, unless /Zc:__cplusplus is enabled. +# +# For more details, see: +# https://learn.microsoft.com/en-us/cpp/build/reference/zc-cplusplus +set(_PXR_CXX_FLAGS "${_PXR_CXX_FLAGS} /Zc:__cplusplus") + # The /Zc:inline option strips out the "arch_ctor_" symbols used for # library initialization by ARCH_CONSTRUCTOR starting in Visual Studio 2019, # causing release builds to fail. Disable the option for this and later diff --git a/cmake/macros/Public.cmake b/cmake/macros/Public.cmake index 1b809e738db..da4b0e2cb0b 100644 --- a/cmake/macros/Public.cmake +++ b/cmake/macros/Public.cmake @@ -658,7 +658,24 @@ function(pxr_test_scripts) endif() foreach(file ${ARGN}) - get_filename_component(destFile ${file} NAME_WE) + # Perform regex match to extract both source resource path and + # destination resource path. + # Regex match appropriately takes care of windows drive letter followed + # by a ":", which is also the token we use to separate the source and + # destination resource paths. + string(REGEX MATCHALL "([A-Za-z]:)?([^:]+)" file "${file}") + + list(LENGTH file n) + if (n EQUAL 1) + get_filename_component(destFile ${file} NAME_WE) + elseif (n EQUAL 2) + list(GET file 1 destFile) + list(GET file 0 file) + else() + message(FATAL_ERROR + "Failed to parse test file path ${file}") + endif() + # XXX -- We shouldn't have to install to run tests. install( PROGRAMS ${file} diff --git a/docs/doxygen/externalOverview.dox b/docs/doxygen/externalOverview.dox index 3f410a5d859..d70985e2485 100644 --- a/docs/doxygen/externalOverview.dox +++ b/docs/doxygen/externalOverview.dox @@ -105,7 +105,7 @@ Following is a deeper indexing of the four packages. - \ref tf_page_front module is a catch-all for low-level, commonly used services developed at Pixar, including facilities for memory - tracking, error reporting and debugging, string utilities, boost python + tracking, error reporting and debugging, string utilities, Python wrapping aids, threading/synchronization tools, registry and singleton management, smart pointers, and "observer pattern" support, which we call "notification". @@ -128,9 +128,8 @@ Following is a deeper indexing of the four packages. is able to recognize and serialize. It provides a copy-on-write array-type, VtArray, which is used for all array types in Usd, and an efficient type-erasure wrapper class, VtValue, that also provides datatype - conversion facilities and support for unboxing python objects from boost - python. VtValue is supported in all Usd API for getting and setting - values. + conversion facilities and support for unboxing Python objects. + VtValue is supported in all Usd API for getting and setting values. - \ref work_page_front module provides a thin abstraction layer on top of Intel's TBB (Thread Building Blocks), and is leveraged extensively in Usd diff --git a/docs/performance/24.11_linux_alab.yaml b/docs/performance/24.11_linux_alab.yaml new file mode 100644 index 00000000000..e663ce2e089 --- /dev/null +++ b/docs/performance/24.11_linux_alab.yaml @@ -0,0 +1,40 @@ +bring_up_the_ui: + max: 0.833684 + mean: 0.7791103 + min: 0.734001 +close_stage: + max: 0.090772 + mean: 0.0874594 + min: 0.084709 +configure_and_load_plugins: + max: 0.000148 + mean: 0.0001375 + min: 0.000131 +create_first_image: + max: 8.556198 + mean: 8.1684536 + min: 7.897517 +open_and_close_usdview: + max: 9.691212 + mean: 9.3458374 + min: 9.062105 +open_stage: + max: 0.516364 + mean: 0.4642872 + min: 0.39004 +reset_prim_browser: + max: 0.001795 + mean: 0.0017705 + min: 0.001751 +shut_down_hydra: + max: 0.165165 + mean: 0.1328269 + min: 0.12083 +tear_down_the_ui: + max: 0.038048 + mean: 0.032411 + min: 0.022262 +traverse_stage: + max: 0.007567 + mean: 0.007379999999999999 + min: 0.007251 diff --git a/docs/performance/24.11_linux_kitchenset.yaml b/docs/performance/24.11_linux_kitchenset.yaml new file mode 100644 index 00000000000..97ce174c342 --- /dev/null +++ b/docs/performance/24.11_linux_kitchenset.yaml @@ -0,0 +1,40 @@ +bring_up_the_ui: + max: 0.387106 + mean: 0.3487857 + min: 0.329509 +close_stage: + max: 0.007835 + mean: 0.0074928 + min: 0.007057 +configure_and_load_plugins: + max: 0.000144 + mean: 0.00013680000000000002 + min: 0.000129 +create_first_image: + max: 0.3028 + mean: 0.2903682 + min: 0.279229 +open_and_close_usdview: + max: 0.847958 + mean: 0.7911669 + min: 0.752613 +open_stage: + max: 0.107452 + mean: 0.0842476 + min: 0.069993 +reset_prim_browser: + max: 0.001205 + mean: 0.0011894 + min: 0.001163 +shut_down_hydra: + max: 0.009617 + mean: 0.0093791 + min: 0.009247 +tear_down_the_ui: + max: 0.009307 + mean: 0.0080869 + min: 0.006491 +traverse_stage: + max: 0.001312 + mean: 0.0012427 + min: 0.001213 diff --git a/docs/performance/24.11_linux_moorelane.yaml b/docs/performance/24.11_linux_moorelane.yaml new file mode 100644 index 00000000000..d8e463d34e2 --- /dev/null +++ b/docs/performance/24.11_linux_moorelane.yaml @@ -0,0 +1,40 @@ +bring_up_the_ui: + max: 0.617653 + mean: 0.603799 + min: 0.598502 +close_stage: + max: 0.02107 + mean: 0.0207992 + min: 0.020613 +configure_and_load_plugins: + max: 0.000177 + mean: 0.00014000000000000001 + min: 0.000131 +create_first_image: + max: 11.776089 + mean: 11.6368226 + min: 11.484618 +open_and_close_usdview: + max: 12.911434 + mean: 12.757864399999999 + min: 12.587016 +open_stage: + max: 0.094023 + mean: 0.0791025 + min: 0.075535 +reset_prim_browser: + max: 0.009577 + mean: 0.0094567 + min: 0.009369 +shut_down_hydra: + max: 0.138991 + mean: 0.1194904 + min: 0.103945 +tear_down_the_ui: + max: 0.117169 + mean: 0.113112 + min: 0.110088 +traverse_stage: + max: 0.001397 + mean: 0.0013728 + min: 0.001346 diff --git a/docs/performance/24.11_linux_shaderball.yaml b/docs/performance/24.11_linux_shaderball.yaml new file mode 100644 index 00000000000..bab10efddec --- /dev/null +++ b/docs/performance/24.11_linux_shaderball.yaml @@ -0,0 +1,40 @@ +bring_up_the_ui: + max: 0.43229 + mean: 0.4245096 + min: 0.419582 +close_stage: + max: 0.000754 + mean: 0.0006054 + min: 0.000499 +configure_and_load_plugins: + max: 0.000142 + mean: 0.0001347 + min: 0.000129 +create_first_image: + max: 2.904303 + mean: 2.8882178 + min: 2.870519 +open_and_close_usdview: + max: 3.479013 + mean: 3.464824 + min: 3.44698 +open_stage: + max: 0.150255 + mean: 0.1480813 + min: 0.144294 +reset_prim_browser: + max: 0.001618 + mean: 0.0015671 + min: 0.001534 +shut_down_hydra: + max: 0.022668 + mean: 0.0223569 + min: 0.022082 +tear_down_the_ui: + max: 0.011874 + mean: 0.0116779 + min: 0.011499 +traverse_stage: + max: 0.000408 + mean: 0.000371 + min: 0.000353 diff --git a/docs/performance/24.11_macos_alab.yaml b/docs/performance/24.11_macos_alab.yaml new file mode 100644 index 00000000000..379a2294c36 --- /dev/null +++ b/docs/performance/24.11_macos_alab.yaml @@ -0,0 +1,40 @@ +bring_up_the_ui: + max: 0.697076 + mean: 0.6728786999999999 + min: 0.659187 +close_stage: + max: 0.041104 + mean: 0.037702 + min: 0.034878 +configure_and_load_plugins: + max: 0.000113 + mean: 8.23e-05 + min: 7.6e-05 +create_first_image: + max: N/A + mean: N/A + min: N/A +open_and_close_usdview: + max: 5.956596 + mean: 5.824605200000001 + min: 5.66041 +open_stage: + max: 0.44761 + mean: 0.4308989 + min: 0.419115 +reset_prim_browser: + max: 0.00096 + mean: 0.0008801 + min: 0.000856 +shut_down_hydra: + max: 0.120492 + mean: 0.10805630000000001 + min: 0.100348 +tear_down_the_ui: + max: 0.01839 + mean: 0.0158125 + min: 0.013213 +traverse_stage: + max: 0.003488 + mean: 0.003359 + min: 0.003253 diff --git a/docs/performance/24.11_macos_kitchenset.yaml b/docs/performance/24.11_macos_kitchenset.yaml new file mode 100644 index 00000000000..48b059ae136 --- /dev/null +++ b/docs/performance/24.11_macos_kitchenset.yaml @@ -0,0 +1,40 @@ +bring_up_the_ui: + max: 0.330342 + mean: 0.2986121 + min: 0.285973 +close_stage: + max: 0.002519 + mean: 0.0023587 + min: 0.002246 +configure_and_load_plugins: + max: 0.000102 + mean: 8.19e-05 + min: 7.6e-05 +create_first_image: + max: N/A + mean: N/A + min: N/A +open_and_close_usdview: + max: 0.730075 + mean: 0.6935303 + min: 0.674505 +open_stage: + max: 0.09047 + mean: 0.0732717 + min: 0.06026 +reset_prim_browser: + max: 0.000624 + mean: 0.0005443 + min: 0.000491 +shut_down_hydra: + max: 0.013024 + mean: 0.0102488 + min: 0.006481 +tear_down_the_ui: + max: 0.015206 + mean: 0.0131009 + min: 0.01074 +traverse_stage: + max: 0.000696 + mean: 0.0005692 + min: 0.000534 diff --git a/docs/performance/24.11_macos_moorelane.yaml b/docs/performance/24.11_macos_moorelane.yaml new file mode 100644 index 00000000000..dac595425f6 --- /dev/null +++ b/docs/performance/24.11_macos_moorelane.yaml @@ -0,0 +1,40 @@ +bring_up_the_ui: + max: 0.47858 + mean: 0.4695382 + min: 0.45761 +close_stage: + max: 0.00522 + mean: 0.0036797 + min: 0.003298 +configure_and_load_plugins: + max: 7.9e-05 + mean: 7.47e-05 + min: 7.2e-05 +create_first_image: + max: N/A + mean: N/A + min: N/A +open_and_close_usdview: + max: 8.820797 + mean: 8.5296113 + min: 8.308413 +open_stage: + max: 0.086856 + mean: 0.0859231 + min: 0.085466 +reset_prim_browser: + max: 0.005902 + mean: 0.0055684 + min: 0.005406 +shut_down_hydra: + max: 0.28412 + mean: 0.2741197 + min: 0.222393 +tear_down_the_ui: + max: 0.045497 + mean: 0.0383143 + min: 0.035085 +traverse_stage: + max: 0.000605 + mean: 0.0005794 + min: 0.000564 diff --git a/docs/performance/24.11_macos_shaderball.yaml b/docs/performance/24.11_macos_shaderball.yaml new file mode 100644 index 00000000000..d39901392be --- /dev/null +++ b/docs/performance/24.11_macos_shaderball.yaml @@ -0,0 +1,40 @@ +bring_up_the_ui: + max: 0.343762 + mean: 0.3297607 + min: 0.317855 +close_stage: + max: 0.000296 + mean: 0.0002641 + min: 0.000241 +configure_and_load_plugins: + max: 9.8e-05 + mean: 8.26e-05 + min: 7.6e-05 +create_first_image: + max: N/A + mean: N/A + min: N/A +open_and_close_usdview: + max: 1.152715 + mean: 1.1196469 + min: 1.096133 +open_stage: + max: 0.098122 + mean: 0.0901067 + min: 0.088529 +reset_prim_browser: + max: 0.000821 + mean: 0.0006841 + min: 0.000646 +shut_down_hydra: + max: 0.014153 + mean: 0.0116556 + min: 0.009064 +tear_down_the_ui: + max: 0.016629 + mean: 0.014055 + min: 0.01147 +traverse_stage: + max: 0.000291 + mean: 0.0002508 + min: 0.000229 diff --git a/docs/performance/24.11_windows_alab.yaml b/docs/performance/24.11_windows_alab.yaml new file mode 100644 index 00000000000..165b55d2453 --- /dev/null +++ b/docs/performance/24.11_windows_alab.yaml @@ -0,0 +1,40 @@ +bring_up_the_ui: + max: 4.316167 + mean: 4.2385264 + min: 4.20729 +close_stage: + max: 0.364083 + mean: 0.35308 + min: 0.337716 +configure_and_load_plugins: + max: 0.000995 + mean: 0.0009473 + min: 0.000878 +create_first_image: + max: 11.738015 + mean: 11.290158 + min: 11.070572 +open_and_close_usdview: + max: 17.118413 + mean: 16.5591656 + min: 16.291877 +open_stage: + max: 0.465223 + mean: 0.4604347 + min: 0.453708 +reset_prim_browser: + max: 0.004434 + mean: 0.0042978 + min: 0.004152 +shut_down_hydra: + max: 0.384717 + mean: 0.2734629 + min: 0.219807 +tear_down_the_ui: + max: 0.309065 + mean: 0.2477569 + min: 0.122124 +traverse_stage: + max: 0.009832 + mean: 0.0080616 + min: 0.007263 diff --git a/docs/performance/24.11_windows_kitchenset.yaml b/docs/performance/24.11_windows_kitchenset.yaml new file mode 100644 index 00000000000..80a34d5e873 --- /dev/null +++ b/docs/performance/24.11_windows_kitchenset.yaml @@ -0,0 +1,40 @@ +bring_up_the_ui: + max: 4.095108 + mean: 3.9744485999999997 + min: 3.868397 +close_stage: + max: 0.024004 + mean: 0.0215864 + min: 0.019616 +configure_and_load_plugins: + max: 0.001014 + mean: 0.0009288 + min: 0.000885 +create_first_image: + max: 3.086248 + mean: 2.9800833 + min: 2.862769 +open_and_close_usdview: + max: 7.451705 + mean: 7.1910904 + min: 6.959639 +open_stage: + max: 0.177268 + mean: 0.1491912 + min: 0.13587 +reset_prim_browser: + max: 0.006285 + mean: 0.0041532 + min: 0.003499 +shut_down_hydra: + max: 0.023532 + mean: 0.0217044 + min: 0.020476 +tear_down_the_ui: + max: 0.110098 + mean: 0.060470300000000005 + min: 0.050172 +traverse_stage: + max: 0.002 + mean: 0.0019016 + min: 0.001795 diff --git a/docs/performance/24.11_windows_moorelane.yaml b/docs/performance/24.11_windows_moorelane.yaml new file mode 100644 index 00000000000..3ca24a90d33 --- /dev/null +++ b/docs/performance/24.11_windows_moorelane.yaml @@ -0,0 +1,40 @@ +bring_up_the_ui: + max: N/A + mean: N/A + min: N/A +close_stage: + max: N/A + mean: N/A + min: N/A +configure_and_load_plugins: + max: N/A + mean: N/A + min: N/A +create_first_image: + max: N/A + mean: N/A + min: N/A +open_and_close_usdview: + max: N/A + mean: N/A + min: N/A +open_stage: + max: N/A + mean: N/A + min: N/A +reset_prim_browser: + max: N/A + mean: N/A + min: N/A +shut_down_hydra: + max: N/A + mean: N/A + min: N/A +tear_down_the_ui: + max: N/A + mean: N/A + min: N/A +traverse_stage: + max: N/A + mean: N/A + min: N/A diff --git a/docs/performance/24.11_windows_shaderball.yaml b/docs/performance/24.11_windows_shaderball.yaml new file mode 100644 index 00000000000..fc6496fca12 --- /dev/null +++ b/docs/performance/24.11_windows_shaderball.yaml @@ -0,0 +1,40 @@ +bring_up_the_ui: + max: 4.444394 + mean: 4.0969829 + min: 4.007564 +close_stage: + max: 0.002616 + mean: 0.0017503 + min: 0.001371 +configure_and_load_plugins: + max: 0.00118 + mean: 0.0009801 + min: 0.00086 +create_first_image: + max: 4.963428 + mean: 4.7824023 + min: 4.546317 +open_and_close_usdview: + max: 9.518625 + mean: 9.09599 + min: 8.81436 +open_stage: + max: 0.320872 + mean: 0.2995894 + min: 0.284833 +reset_prim_browser: + max: 0.004614 + mean: 0.0041768 + min: 0.003919 +shut_down_hydra: + max: 0.04744 + mean: 0.0423858 + min: 0.040305 +tear_down_the_ui: + max: 0.057904 + mean: 0.0550358 + min: 0.050231 +traverse_stage: + max: 0.001217 + mean: 0.0011315 + min: 0.001047 diff --git a/docs/performance/linux.svg b/docs/performance/linux.svg new file mode 100644 index 00000000000..72324c5b8bb --- /dev/null +++ b/docs/performance/linux.svg @@ -0,0 +1,1457 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/performance/macos.svg b/docs/performance/macos.svg new file mode 100644 index 00000000000..f338f5f484f --- /dev/null +++ b/docs/performance/macos.svg @@ -0,0 +1,1536 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/performance/windows.svg b/docs/performance/windows.svg new file mode 100644 index 00000000000..ae18c642e89 --- /dev/null +++ b/docs/performance/windows.svg @@ -0,0 +1,1396 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/python/genPerformancePlots.py b/docs/python/genPerformancePlots.py index 2c6ff084356..a8e3f591605 100644 --- a/docs/python/genPerformancePlots.py +++ b/docs/python/genPerformancePlots.py @@ -41,6 +41,8 @@ def collectData(dataDir: str): with open(os.path.join(dataDir, yamlname)) as f: metrics = yaml.safe_load(f) time = metrics[METRIC_ID]["min"] + if type(time) is not float: + continue if asset not in data[platform]: data[platform][asset] = [] @@ -51,6 +53,12 @@ def collectData(dataDir: str): def exportCharts(data, outputDir: str): + markers = { + "alab": "d", + "kitchenset": "s", + "moorelane": "^", + "shaderball": "o" + } for platform, platformData in data.items(): fig, _ = plt.subplots() plt.close(fig) @@ -61,7 +69,7 @@ def exportCharts(data, outputDir: str): for asset, assetData in platformData.items(): releases = [d[0] for d in assetData] times = [d[1] for d in assetData] - plt.plot(releases, times, label=asset, marker='o') + plt.plot(releases, times, label=asset, marker=markers[asset]) plt.title(f"{platform} time to open and close usdview", fontweight="bold") diff --git a/docs/ref_performance_metrics.rst b/docs/ref_performance_metrics.rst index c60e0dbc740..d4b1ad055f2 100644 --- a/docs/ref_performance_metrics.rst +++ b/docs/ref_performance_metrics.rst @@ -103,6 +103,13 @@ The following graphs show the time (in seconds) to open and close :program:`usdview` for each asset. Graphs are provided for Linux, macOS, and Windows platforms (as described in :ref:`perf_environments`). +.. note:: + + For the 24.11 release, there are known issues with obtaining metrics for + the Moore Lane asset on Windows, and the create_first_image metric on + macOS. We are actively investigating these issues and will update + published metrics when these issues are resolved. + .. image:: performance/linux.svg :width: 500 diff --git a/docs/spec_usdpreviewsurface.rst b/docs/spec_usdpreviewsurface.rst index 56038a79976..81e5c7082c9 100644 --- a/docs/spec_usdpreviewsurface.rst +++ b/docs/spec_usdpreviewsurface.rst @@ -151,12 +151,14 @@ and :usda:`opacity`. Roughness for the second specular lobe. Clearcoat results are calculated using the same normal map data used by the primary specular lobe. +.. _updateopacity: + * **opacity - float - 1.0** When *opacity* is 1.0 then the gprim is fully opaque, if it is smaller than - 1.0 then the prim is translucent, when it is 0 the gprim is transparent. Note - that even a fully transparent object still receives lighting as, for example, - perfectly clear glass still has a specular response. + 1.0 then the prim is translucent, when it is 0 the gprim is fully transparent. + Fully transparent objects receive no lighting response, thus they always + serve as cutouts, even in "transparency mode". .. _addopacitythreshold: @@ -176,8 +178,8 @@ and :usda:`opacity`. interpreted; this "translucent or masked" behavior is common in engines and renderers, and makes the UsdPreviewSurface easier to interchange. It does imply, however, that it is not possible to faithfully recreate a - glassy/translucent material that also provides an opacity-based mask... so no - single-polygon glass leaves. + translucent material that also provides an opacity-based mask with a + non-zero opacityThreshold. .. _updateior: @@ -1073,10 +1075,20 @@ From version 2.3... of specular components, including the clearcoat when :math:`UsdPreviewSurface.clearcoat > 0`. -Version 2.5 - Current Head -########################## +Version 2.5 +########### From version 2.4... * :ref:`Updates UDIM specification to include tile 1100.` Changes the baseline UDIM tile support from 1001-1099, inclusive, to 1001-1100. This allows for a 10x10 grid of UDIM tiles. + +Version 2.6 - Current Head +########################## + +From version 2.5... + * :ref:`Updates description of UsdPreviewSurface behavior when opacity is 0. + ` + Removes the statement that materials with opacity = 0 still receive a + specular reflection, instead indicating that fully transparent materials + receive no lighting response. diff --git a/docs/spec_usdz.rst b/docs/spec_usdz.rst index 1d2ef2f6fcf..05a73580d34 100644 --- a/docs/spec_usdz.rst +++ b/docs/spec_usdz.rst @@ -5,7 +5,7 @@ Usdz File Format Specification .. include:: rolesAndUtils.rst .. include:: -Copyright |copy| 2018, Pixar Animation Studios, *version 1.2* +Copyright |copy| 2018, Pixar Animation Studios, *version 1.3* .. contents:: :local: @@ -198,6 +198,7 @@ Clients wishing to deliver "streamable content" `may wish to consider other layo * Otherwise, the packaging API will fail to run unless the Default Layer is manually specified. +.. _spec_usdz_file_types: File Types ---------- @@ -408,3 +409,13 @@ constraints. The toolset also includes: enforce stricter "web-compliant" rules that disallow certain advanced USD features that web-browsers do not yet support. +Changes, by Version +=================== + +Version 1.3 - Current Head +-------------------------- + +From version 1.2: + + * :ref:`Adds AV1 Image (AVIF) file support `. + AVIF is now a supported file type for images/textures. \ No newline at end of file diff --git a/docs/tut_authoring_variants.rst b/docs/tut_authoring_variants.rst index 25ec7a34d69..5f053cbc6c1 100644 --- a/docs/tut_authoring_variants.rst +++ b/docs/tut_authoring_variants.rst @@ -344,7 +344,7 @@ these files to a working directory and make them writable. .. image:: http://openusd.org/images/tut_authoring_variants_helloworld2.png #. In the interpreter you can see the variant selections that usdview authors to - the `session layer <#usdglossary-sessionlayer>`_ . This is the same sparse + the :ref:`session layer `. This is the same sparse override you would see if you referenced this layer into another one and authored the variant selection in the referencing layer. diff --git a/docs/tut_inspect_and_author_props.rst b/docs/tut_inspect_and_author_props.rst index 54b24027c2d..a2535fc67f0 100644 --- a/docs/tut_inspect_and_author_props.rst +++ b/docs/tut_inspect_and_author_props.rst @@ -79,7 +79,7 @@ Tutorial .. code-block:: pycon >>> radiusAttr = sphere.GetAttribute('radius') - >>> radiusAttr.Set(2) + >>> radiusAttr.Set(2) True >>> extentAttr.Set(extentAttr.Get() * 2) True diff --git a/docs/tut_setup_version_badge.rst b/docs/tut_setup_version_badge.rst index e4b5ca917bb..0e4f9f69d40 100644 --- a/docs/tut_setup_version_badge.rst +++ b/docs/tut_setup_version_badge.rst @@ -2,4 +2,4 @@ :fa:`cogs` :ref:`Configure your Environment ` - :fa:`check` Tested with `USD 24.08 `_ + :fa:`check` Tested with `USD 24.11 `_ diff --git a/docs/tut_traversing_stage.rst b/docs/tut_traversing_stage.rst index 75b584fbb85..e697ef1473b 100644 --- a/docs/tut_traversing_stage.rst +++ b/docs/tut_traversing_stage.rst @@ -78,7 +78,7 @@ folder to a working directory and make its contents writable. .. image:: http://openusd.org/images/tut_traversing_stage_refexample.png You can inspect the contents of the - `session layer <#usdglossary-sessionlayer>`_ in the interpreter to see + :ref:`session layer ` in the interpreter to see the authored deactivation opinion. .. code-block:: pycon diff --git a/docs/user_guides/namespace_editing.rst b/docs/user_guides/namespace_editing.rst index ec201d3ffa6..c5ca55dd26a 100644 --- a/docs/user_guides/namespace_editing.rst +++ b/docs/user_guides/namespace_editing.rst @@ -10,19 +10,26 @@ A namespace edit is an operation that removes or changes the namespace path of a **composed** prim or property on a stage. Edit operations currently include deleting and moving (renaming and/or reparenting) a composed prim or property. -While it is possible to do some of these operations using Sdf or UsdStage APIs, -these APIs can only edit prims or properties on a single layer. Namespace -editing handles edits for prims and properties that are composed from multiple -layers or other composition arcs. Using namespace editing lets you robustly -delete and move prims that have opinions throughout a LayerStack that you have -the authority to edit. Namespace editing also allows "non-destructive" -deletion and moving of prims defined in LayerStacks that you don't have the -authority to edit. +While it is possible to do some of these operations using Sdf or UsdStage APIs, +these APIs can only edit prims or properties on a single layer. Additionally, +any paths targeting the moved or deleted objects will need to be manually fixed. +Use namespace editing to easily and safely delete or move prims and properties +across the :ref:`LayerStack `. Namespace editing handles +edits for objects composed from multiple layers and handles changing +:ref:`EditTargets ` or fixing paths targeting the +edited objects, automatically. + +Namespace also provides non-destructive editing of prims defined across +composition arcs by adding the **relocates** composition arc if needed. +By using relocates, namespace editing ensures non-destructive edits by *not* +modifying the source of a composition arc. This is necessary for workflows where +you might not be able to make changes to the source of the composition +arc directly (e.g. you're referencing prims from assets maintained by a +different department that are also being referenced elsewhere). As a simple example, if you had :filename:`model.usda` with various prims: .. code-block:: usda - :caption: model.usda #usda 1.0 ( @@ -39,10 +46,9 @@ As a simple example, if you had :filename:`model.usda` with various prims: } And :filename:`main.usda`, which has :filename:`model.usda` as a sublayer and -overs for :sdfpath:`/modelScope` and :sdfpath:`/modelScope/model1`: +overrides for :sdfpath:`/modelScope` and :sdfpath:`/modelScope/model1`: .. code-block:: usda - :caption: main.usda #usda 1.0 ( @@ -60,15 +66,16 @@ overs for :sdfpath:`/modelScope` and :sdfpath:`/modelScope/model1`: } After loading :filename:`main.usda` into your stage, if you wanted to fully -remove :sdfpath:`/modelScope/model1` from your composed stage, using UsdStage +remove :sdfpath:`/modelScope/model1` from your composed stage using UsdStage APIs, you'd have to delete it twice: once in :filename:`main.usda`, and then, -after changing edit targets, again in the :filename:`model.usda` layer: +after changing :ref:`EditTargets `, again in the +:filename:`model.usda` layer: .. code-block:: python stage = Usd.Stage.Open("main.usda") - # This only removes model1 in model.usda, not + # This only removes model1 in main.usda, not # model1 in the model.usda layer removeResult = stage.RemovePrim("/modelScope/model1") @@ -77,8 +84,8 @@ after changing edit targets, again in the :filename:`model.usda` layer: # set the edit target to the model.usda layer and call RemovePrim() again Whereas using namespace editing will properly handle removing the prim from -both :filename:`main.usda` and :filename:`model.usda`, handling edit target -changes for you: +both :filename:`main.usda` and :filename:`model.usda` in a single edit +operation, handling edit target changes for you: .. code-block:: python @@ -86,19 +93,19 @@ changes for you: removeResult = editor.DeletePrimAtPath("/modelScope/model1") editor.ApplyEdits() -Namespace editing also handles issues such as making sure that paths to -and overrides of edited objects are still valid after renaming or reparenting +Namespace editing handles issues such as making sure that paths targeting +edited objects and overrides are still valid after renaming or reparenting prims. Namespace editing tries to fix any existing composition arcs, relationship targets, attribute connections, and overrides that used paths to renamed or reparented prims to use the new paths. -Namespace editing in a future update will also use **relocates** for more -complex edit scenarios. Relocates are another composition arc that maps a prim -path in a namespace to a new path location. For example, if you were referencing -a prim from :filename:`refModel.usda`: +Namespace editing will also use **relocates** for more complex edit scenarios. +Relocates are another composition arc that maps a prim path defined in a remote +:ref:`LayerStack ` (i.e. across a composition arc) to a +new path location in the local namespace. For an example of how namespace +editing uses relocates, if you had :filename:`refModel.usda`: .. code-block:: usda - :caption: refModel.usda def "modelA" () { @@ -107,16 +114,19 @@ a prim from :filename:`refModel.usda`: } } +Which is referenced in :filename:`main.usda`: + .. code-block:: usda - :caption: main.usda def "mainModelA" ( prepend references = @refModel.usda@ ) { -You will be able to use namespace editing to move or rename -:sdfpath:`/mainModelA/modelAChild` using relocates. +You might want to use namespace editing to move or rename +:sdfpath:`/mainModelA/modelAChild`. Because :sdfpath:`/mainModelA/modelAChild` +is composed across a reference composition arc, it can't be directly edited, +so namespace editing will use relocates to create the edit. .. code-block:: python @@ -125,6 +135,30 @@ You will be able to use namespace editing to move or rename removeResult = editor.MovePrimAtPath("/mainModelA/modelAChild", "/mainModelA/renamedChild") editor.ApplyEdits() +The resulting stage root layer for :file:`main.usda` will look like: + +.. code-block:: usda + + #usda 1.0 + ( + relocates = { + : + } + ) + + def "mainModelA" ( + prepend references = @refModel.usda@ + ) + { + } + +.. note:: + + **relocates** is a new composition arc for USD that is a separate feature + from namespace editing, and can be used independently of namespace editing. + +.. _nsedit_using_usdnamespaceeditor: + ************************ Using UsdNamespaceEditor ************************ @@ -147,7 +181,7 @@ rename or reparent prims and properties using :usdcpp:`UsdPrim` and When you call a :usdcpp:`UsdNamespaceEditor` edit operation, the operation paths are validated (e.g. the paths passed to :code:`MovePrimAtPath()` are checked to make sure they are valid paths), and then the operation is queued (to support -batches of operations, see :ref:`namespace_editing_batch_edits` below). To +batches of operations, see :ref:`nsedit_batch_edits` below). To execute individual edit operations, as the following examples do, call :code:`ApplyEdits()` after each operation call. @@ -204,6 +238,82 @@ Note that after renaming or reparenting a :usdcpp:`UsdPrim` or :usdcpp:`UsdProperty`, the :usdcpp:`UsdPrim` or :usdcpp:`UsdProperty` reference used in the operation will no longer be valid, as the path has changed. +.. _nsedit_setting_editor_options: + +Setting Editor Options +====================== + +When you create a namespace editor, you can optionally provide edit options +that control editor behavior. The current set of options are: + +* **allowRelocatesAuthoring**: If :code:`True` the namespace editor will use + relocates when needed to make edits. If :code:`False`, the namespace editor + will not use relocates and will issue errors when applying or validating edits + that require relocates. The default is :code:`True`. + +The following example creates the :code:`noRelocatesEditOptions` edit options, +disables :code:`noRelocatesEditOptions.allowRelocatesAuthoring`, and creates +a namespace editor for :code:`stage` with these options. + +.. code-block:: python + + noRelocatesEditOptions = Usd.NamespaceEditor.EditOptions() + noRelocatesEditOptions.allowRelocatesAuthoring = False + + # Create/use namespace editor that will not use relocates + noRelocatesEditor = Usd.NamespaceEditor(stage, noRelocatesEditOptions) + +.. _nsedit_working_with_relocates: + +Working With Relocates +====================== + +As mentioned earlier, namespace editing will use **relocates** if necessary +for edit operations across composition arcs. Namespace editing will add or +update relocates in the appropriate layer's metadata relocates list. The +following example shows layer metadata with a relocate added by a namespace +editing operation to rename :sdfpath:`/mainModelA/modelAChild` to +:sdfpath:`/mainModelA/renamedChild`: + +.. code-block:: usda + + #usda 1.0 + ( + relocates = { + : + } + ) + +For delete operations that require using relocates, namespace editing will +create a relocates mapping that maps a prim or property to a "deleted" target: + +.. code-block:: python + + # Delete a referenced prim, which will add a new relocates + editor.DeletePrimAtPath('/RootPrim/ChildInRef') + editor.ApplyEdits() + +.. code-block:: + + #usda 1.0 + ( + relocates = { + : <> + } + ) + +Note that the way in which relocates must "transfer" composed opinions prevents +you from re-defining a new prim at the deleted or moved target location: + +.. code-block:: python + + # Continuing from the earlier Python code, now try and define a prim at the + # deleted /RootPrim/ChildInRef path. This will result in a + # "Failed to define UsdPrim" error. + stage.DefinePrim('/RootPrim/ChildInRef') + +.. _nsedit_fixing_paths_for_moved_objects: + Fixing Paths For Moved Objects ============================== @@ -318,16 +428,108 @@ With the flattened results looking like: } } -.. note:: - Currently, direct edits across composition arcs, such as renaming just - :sdfpath:`/Shot1/shotAsset/assetChild` in the above example, is not supported - via namespace editing and will result in the following error (from - :code:`CanApplyEdits()` or :code:`ApplyEdits()`): "The prim to move requires - authoring relocates since it composes opinions introduced by ancestral - composition arcs; authoring relocates is not yet supported". Relocates will - be available in a future update. +.. _nsedit_fixing_edits_with_dependent_stages: -.. _namespace_editing_batch_edits: +Applying Edits to Dependent Stages +================================== + +In some situations, a namespace edit applied to one stage can impact other +**dependent stages**. A dependent stage is any additional stage open in the +current session that has a composition dependency on any layer edits made for +the editor's primary stage. For example, you might have a stage that has +references to prims in the editor's primary stage, and you might have edits +that rename or delete the referenced prims. + +By default, an editor only makes edits and fixes to the editor's primary stage. +However, you can add dependent stages to an editor via +:code:`AddDependentStage()` and the editor will make any necessary additional +edits in those dependent stages to update the composition dependencies +appropriately. + +For example, we might have the layer :filename:`layer1.usda`, which will get +composed into the stage for which we'll create a namespace editor. + +.. code-block:: usda + + #usda 1.0 + ( + ) + + def "Prim1" { + def "Child" { + } + } + + def "InternalRef1" ( + references = + ) { + over "Child" { + int overChildAttr + } + } + +We also have an additional layer :filename:`layer2.usda` that references prims +in :filename:`layer1.usda`: + +.. code-block:: usda + + #usda 1.0 + ( + ) + + def "OtherStageRef2" ( + references = @layer1.usda@ + ) { + int overChildAttr + } + +We can open both layers in separate stages, create a namespace editor for the +stage containing layer1, and add the stage containing layer2 as a dependent +stage. + +.. code-block:: python + + stage1 = Usd.Stage.Open("layer1.usda") + stage2 = Usd.Stage.Open("layer2.usda") + + # Create a namespace editor for stage1 + editor = Usd.NamespaceEditor(stage1) + + # Add stage2 as a dependent stage for our stage1 editor + editor.AddDependentStage(stage2) + + # Move /Prim1/Child to /Prim1/RenamedChild. This will not only + # update the prims and references in stage1, but also update the + # OtherStageRef2 reference in stage2 + editor.MovePrimAtPath('/Prim1/Child', '/Prim1/RenamedChild') + editor.ApplyEdits() + +After the edit, the root layer of stage2 looks like: + +.. code-block:: usda + + #usda 1.0 + + def "OtherStageRef2" ( + references = @layer1.usda@ + ) + { + int overChildAttr + } + +You can use :code:`RemoveDependentStage()` to remove any added dependent stages +before making a namespace edit, when you do not want the dependent stage +dependencies updated. + +If you have several dependent stages, you can set a list of dependent stages on +an editor using :code:`SetDependentStages()`. + +Note that namespace editing finds dependencies in dependent stages based on +what is currently loaded in those stages. If a stage has dependencies in +unloaded payloads, load mask filtered prims, unselected variants, or children of +inactive prims, the namespace editor cannot find and update those dependencies. + +.. _nsedit_batch_edits: Batch Edits =========== @@ -370,12 +572,16 @@ Executing batches of edits will usually be more efficient than applying each edit individually. USD will process the list of edits in a batch to determine the most efficient way to apply them. +.. _nsedit_editing_best_practices: + ******************************** Namespace Editing Best Practices ******************************** The following are some general best practices and caveats for namespace editing. +.. _nsedit_canapplyedits_validate_operations: + Use CanApplyEdits() To Validate Edit Operations =============================================== @@ -404,6 +610,8 @@ indicating the path does not resolve to a valid prim. else: # Handle error, using canApplyResult.whyNot as needed, etc. +.. _nsedit_builtin_properties_not_editable: + Built-In Properties From Schemas Are Not Editable ================================================= @@ -429,3 +637,35 @@ would fail. editor.DeletePropertyAtPath("/testSphere/customProp") # This is allowed editor.DeletePropertyAtPath("/testSphere/radius") # This is not allowed and will cause an error + +.. _nsedit_relocates_performance_impact: + +Be Aware of Relocates Performance Impact +======================================== + +If your namespace editing operations result in adding **relocates** to your +stage, this can increase the number of composition arcs in your stage, which +could impact stage composition performance. + +If you want to test whether a namespace edit will add relocates, you can +use an editor configured to disallow authoring relocates, and use +:code:`CanApplyEdits()` looking for any errors that indicate relocates would +be needed. + +.. code-block:: python + + # Create/use namespace editor that will not use relocates + noRelocatesEditOptions = Usd.NamespaceEditor.EditOptions() + noRelocatesEditOptions.allowRelocatesAuthoring = False + noRelocatesEditor = Usd.NamespaceEditor(stage, noRelocatesEditOptions) + + # Rename /mainModelA/modelAChild to /mainModelA/renamedChild + # This editor is configured to not use relocates, so an error will be shown + removeResult = noRelocatesEditor.MovePrimAtPath("/mainModelA/modelAChild", "/mainModelA/renamedChild") + applyResult = noRelocatesEditor.CanApplyEdits() + if applyResult is not True: + # We should get a "The prim to edit requires authoring relocates since + # it composes opinions introduced by ancestral composition arcs; + # relocates authoring must be enabled to perform this edit" error + print ("noRelocatesEditor: Cannot apply edits, reason: " + applyResult.whyNot) + \ No newline at end of file diff --git a/extras/usd/examples/usdObj/pch.h b/extras/usd/examples/usdObj/pch.h index 0050ec378e5..88470ee57d4 100644 --- a/extras/usd/examples/usdObj/pch.h +++ b/extras/usd/examples/usdObj/pch.h @@ -74,6 +74,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/extras/usd/examples/usdSchemaExamples/pch.h b/extras/usd/examples/usdSchemaExamples/pch.h index 6d53e8bfe4f..4852335387d 100644 --- a/extras/usd/examples/usdSchemaExamples/pch.h +++ b/extras/usd/examples/usdSchemaExamples/pch.h @@ -69,6 +69,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/pxr/base/arch/attributes.h b/pxr/base/arch/attributes.h index 1d2820d1e7d..42f9a6e875c 100644 --- a/pxr/base/arch/attributes.h +++ b/pxr/base/arch/attributes.h @@ -159,6 +159,7 @@ PXR_NAMESPACE_OPEN_SCOPE # define ARCH_SCANF_FUNCTION(_fmt, _firstArg) \ __attribute__((format(scanf, _fmt, _firstArg))) # define ARCH_NOINLINE __attribute__((noinline)) +# define ARCH_ALWAYS_INLINE __attribute__((always_inline)) # define ARCH_UNUSED_ARG __attribute__ ((unused)) # define ARCH_UNUSED_FUNCTION __attribute__((unused)) # define ARCH_USED_FUNCTION __attribute__((used)) @@ -169,6 +170,7 @@ PXR_NAMESPACE_OPEN_SCOPE # define ARCH_PRINTF_FUNCTION(_fmt, _firstArg) # define ARCH_SCANF_FUNCTION(_fmt, _firstArg) # define ARCH_NOINLINE // __declspec(noinline) +# define ARCH_ALWAYS_INLINE # define ARCH_UNUSED_ARG # define ARCH_UNUSED_FUNCTION # define ARCH_USED_FUNCTION diff --git a/pxr/base/gf/pch.h b/pxr/base/gf/pch.h index 7f010fc4806..c47bc475e60 100644 --- a/pxr/base/gf/pch.h +++ b/pxr/base/gf/pch.h @@ -54,6 +54,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/pxr/base/plug/pch.h b/pxr/base/plug/pch.h index 61a25c286bf..01267ce3ab8 100644 --- a/pxr/base/plug/pch.h +++ b/pxr/base/plug/pch.h @@ -82,6 +82,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/pxr/base/plug/testPlug.py b/pxr/base/plug/testPlug.py index ba8feed7da6..578e9cc62e2 100644 --- a/pxr/base/plug/testPlug.py +++ b/pxr/base/plug/testPlug.py @@ -327,5 +327,10 @@ def test_DebugCodeExistence(self): self.assertTrue('PLUG_INFO_SEARCH' in debugCodes) self.assertTrue('PLUG_REGISTRATION' in debugCodes) + def test_StlSequencesForPlugPluginPtr(self): + pd1 = Plug.Registry().GetPluginForType('TestPlugDerived1') + td1 = Plug._TestPlugBase1('TestPlugDerived1') + self.assertTrue(td1.TestAcceptPluginSequence([pd1])) + if __name__ == '__main__': unittest.main() diff --git a/pxr/base/plug/testPlugBase.h b/pxr/base/plug/testPlugBase.h index 9b17ae5aaa4..2bd210cd697 100644 --- a/pxr/base/plug/testPlugBase.h +++ b/pxr/base/plug/testPlugBase.h @@ -13,6 +13,7 @@ #include "pxr/base/tf/stringUtils.h" #include "pxr/base/tf/type.h" #include "pxr/base/tf/weakBase.h" +#include "pxr/base/plug/plugin.h" #include @@ -36,6 +37,10 @@ class _TestPlugBase : public TfRefBase, public TfWeakBase { return TfCreateRefPtr(new This()); } + bool TestAcceptPluginSequence(const PlugPluginPtrVector &plugins) { + return true; + } + PLUG_API static RefPtr Manufacture(const std::string & subclass); diff --git a/pxr/base/plug/wrapPlugin.cpp b/pxr/base/plug/wrapPlugin.cpp index 07929dbc5bf..2c87ed069a3 100644 --- a/pxr/base/plug/wrapPlugin.cpp +++ b/pxr/base/plug/wrapPlugin.cpp @@ -87,6 +87,7 @@ void wrapPlugin() (arg("path"), arg("verify") = true)) ; + TfPyRegisterStlSequencesFromPython(); // The call to JsConvertToContainerType in _ConvertDict creates // vectors of pxr_boost::python::objects for array values, so register diff --git a/pxr/base/plug/wrapTestPlugBase.cpp b/pxr/base/plug/wrapTestPlugBase.cpp index ea6f1725354..5037ec7c7e0 100644 --- a/pxr/base/plug/wrapTestPlugBase.cpp +++ b/pxr/base/plug/wrapTestPlugBase.cpp @@ -7,6 +7,8 @@ #include "pxr/pxr.h" #include "pxr/base/plug/testPlugBase.h" +#include "pxr/external/boost/python/def.hpp" +#include "pxr/external/boost/python/args.hpp" #include "pxr/base/tf/makePyConstructor.h" #include "pxr/base/tf/pyPtrHelpers.h" #include "pxr/base/tf/pyContainerConversions.h" @@ -33,6 +35,9 @@ void wrap_TestPlugBase(const std::string & name) .def("GetTypeName", &This::GetTypeName) + .def("TestAcceptPluginSequence", &This::TestAcceptPluginSequence, + (arg("plugins"))); + ; } diff --git a/pxr/base/tf/debugCodes.cpp b/pxr/base/tf/debugCodes.cpp index 936ca5c6ece..83281126275 100644 --- a/pxr/base/tf/debugCodes.cpp +++ b/pxr/base/tf/debugCodes.cpp @@ -13,8 +13,11 @@ PXR_NAMESPACE_OPEN_SCOPE TF_REGISTRY_FUNCTION(TfDebug) { TF_DEBUG_ENVIRONMENT_SYMBOL(TF_SCRIPT_MODULE_LOADER, - "show script module loading activity"); - TF_DEBUG_ENVIRONMENT_SYMBOL(TF_TYPE_REGISTRY, "show changes to the TfType registry"); + "show script module loading activity"); + TF_DEBUG_ENVIRONMENT_SYMBOL(TF_SCRIPT_MODULE_LOADER_EXTRA, + "show more script module loading activity"); + TF_DEBUG_ENVIRONMENT_SYMBOL(TF_TYPE_REGISTRY, + "show changes to the TfType registry"); TF_DEBUG_ENVIRONMENT_SYMBOL(TF_ATTACH_DEBUGGER_ON_ERROR, "attach/stop in a debugger for all errors"); TF_DEBUG_ENVIRONMENT_SYMBOL(TF_ATTACH_DEBUGGER_ON_FATAL_ERROR, diff --git a/pxr/base/tf/debugCodes.h b/pxr/base/tf/debugCodes.h index 7025b0c1a7d..e6d0aa3eb8b 100644 --- a/pxr/base/tf/debugCodes.h +++ b/pxr/base/tf/debugCodes.h @@ -26,6 +26,7 @@ TF_DEBUG_CODES( TF_DLCLOSE, TF_SCRIPT_MODULE_LOADER, + TF_SCRIPT_MODULE_LOADER_EXTRA, TF_TYPE_REGISTRY, diff --git a/pxr/base/tf/mallocTag.h b/pxr/base/tf/mallocTag.h index e4b326c9c05..d28522c01eb 100644 --- a/pxr/base/tf/mallocTag.h +++ b/pxr/base/tf/mallocTag.h @@ -474,28 +474,28 @@ PXR_NAMESPACE_CLOSE_SCOPE #define TF_MALLOC_TAG_NEW(name1, name2) \ /* this is for STL purposes */ \ - inline void* operator new(::std::size_t, void* ptr) { \ + ARCH_ALWAYS_INLINE inline void* operator new(::std::size_t, void* ptr) { \ return ptr; \ } \ \ - inline void* operator new(::std::size_t s) { \ + ARCH_ALWAYS_INLINE inline void* operator new(::std::size_t s) { \ PXR_NS::TfAutoMallocTag tag(name1, name2); \ return malloc(s); \ } \ \ - inline void* operator new[](::std::size_t s) { \ + ARCH_ALWAYS_INLINE inline void* operator new[](::std::size_t s) { \ PXR_NS::TfAutoMallocTag tag(name1, name2); \ return malloc(s); \ } \ \ /* Required due to the placement-new override above. */ \ - inline void operator delete(void* ptr, void* place) {} \ + ARCH_ALWAYS_INLINE inline void operator delete(void* ptr, void* place) {} \ \ - inline void operator delete(void* ptr, size_t) { \ + ARCH_ALWAYS_INLINE inline void operator delete(void* ptr, size_t) { \ free(ptr); \ } \ \ - inline void operator delete[] (void* ptr, size_t) { \ + ARCH_ALWAYS_INLINE inline void operator delete[] (void* ptr, size_t) { \ free(ptr); \ } \ diff --git a/pxr/base/tf/pch.h b/pxr/base/tf/pch.h index a7cf61b8b58..0a1e479030a 100644 --- a/pxr/base/tf/pch.h +++ b/pxr/base/tf/pch.h @@ -109,6 +109,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/pxr/base/tf/scriptModuleLoader.cpp b/pxr/base/tf/scriptModuleLoader.cpp index e1472ce7b6f..399a6d2309c 100644 --- a/pxr/base/tf/scriptModuleLoader.cpp +++ b/pxr/base/tf/scriptModuleLoader.cpp @@ -11,11 +11,10 @@ #include "pxr/base/tf/debug.h" #include "pxr/base/tf/debugCodes.h" #include "pxr/base/tf/instantiateSingleton.h" -#include "pxr/base/tf/iterator.h" +#include "pxr/base/tf/pyError.h" +#include "pxr/base/tf/pyExceptionState.h" #include "pxr/base/tf/pyUtils.h" #include "pxr/base/tf/registryManager.h" -#include "pxr/base/tf/stackTrace.h" -#include "pxr/base/tf/staticData.h" #include "pxr/base/tf/stringUtils.h" #include "pxr/base/arch/fileSystem.h" @@ -24,13 +23,103 @@ #include "pxr/external/boost/python/dict.hpp" #include "pxr/external/boost/python/handle.hpp" -#include +/* + +Notes for those who venture into this dark crevice: + +We build C++ libs that have python bindings into two shared libraries: 1, the +shared library with the compiled C++ code (`libFoo.so`), and 2, a shared library +with the C++/Python bindings (`_foo.so`). We do this so that we can write pure +C++ programs that link `libFoo.so` and do not pay to load the Python bindings. +The bindings libraries (`_foo.so`) have a shared library link dependency on +their corresponding C++ library (`libFoo.so`) so whenever a bindings lib loads, +the shared library loader automatically loads the main C++ lib. + +The job of the code in this file is to ensure that the Python bindings for +loaded C++ libraries are loaded whenever they are needed. + +When are they needed? There are a few scenarios. + +The most obvious is when a Python module is imported. Suppose libFoo depends on +libBar, and both have Python bindings. If we do `import Foo` in Python, we need +to ensure that the `Bar` module is imported and registers its bindings before +Foo registers its bindings, since Foo's bindings may depend on Bar's. For +example, if Foo wraps a class that derives a base class from Bar, that base +class must be wrapped first. This scenario could in principle be handled by +manually writing `import Bar` in Foo's __init__.py. But, that is prone both to +being forgotten, and to going undetected if Bar happens to be already loaded in +most of the scenarios when Foo is imported. And, as we'll see, that doesn't +solve the other main scenario. + +The other main scenario is when a C++ program initializes Python at some point +during its execution. In this case all currently loaded C++ libraries that have +Python bindings must load them immediately. Further, any C++ library that loads +in the future (via dlopen()) must also immediately import its bindings at load +time. This might sound surprising. Why should we need to eagerly import all +bindings like this? Surely if Python code needs to use the bindings it will +`import` those modules itself, no? Yes this is true, but there can be hidden, +indirect, undetectable dependencies that this does not handle due to +type-erasure. + +Consider a type-erased opaque 'box' container, analogous to `std::any`. Let's +call it `Any`. When an Any is converted to Python, it unboxes its held object +and converts that object to Python. So for example if an Any holding a string +is returned to Python, Python gets a string. An Any holding a double unboxes as +a Python float. An Any holding a FooObject unboxes it and uses its bindings to +convert it to Python. + +Now suppose we have libFoo and libBar. Bar has an Any-valued variable, and +provides a Python binding to access it: `Bar.GetAny()`. Foo depends on Bar, and +stores an Any holding a FooObject to Bar's Any. Now suppose a Python script +does `import Bar; Bar.GetAny()`. The call to `Bar.GetAny()` will fail unless +the bindings for the held FooObject have been imported. + +Whose responsibility is it to ensure they have been imported? Bar cannot know +to import them, since Bar does not depend on Foo -- it has no knowledge of Foo's +existence. The Python code that imported Bar similarly cannot have done it -- +there's no way for it to know ahead of time what type of object is stored in the +Any, and it may not know of Foo's existence either. The answer is that the +_only_ place that we can know for sure the bindings are needed is at the very +moment that a FooObject is requested to be converted to Python. Unfortunately, +we do not have a hook available for this today. It might be possible to build +one now that we have our own copy of boost.python interred, but that's not the +world we currently live in. + +In the meantime, we must do as we said above and load _all_ bindings when Python +is initialized, and then continue to load any bindings for any later-loaded C++ +libraries when they are loaded. + +The Mechanism: + +We build a small bit of initialization code into each C++ library with bindings +to advertise themselves to the TfScriptModuleLoader. These are the +`moduleDeps.cpp` files in `pxr/...`. The initializer calls +TfScriptModuleLoader::RegisterLibrary(), passing the lib name, its python module +name (suitable for `import`), and a list of the lib's direct dependencies. This +way the the loader knows both which libraries have bindings, and what they +directly depend on. + +Then, in a few key places, code calls LoadModules() or LoadModulesForLibrary() +to achieve the goals above. + +- Tf_PyInitWrapModule(), in tf/pyModule.cpp calls LoadModulesForLibrary(). This + function is called by Python when a bindings library is imported. This covers + the "import" scenario above. + +- TfPyInitialize(), in tf/pyInterpreter.cpp calls LoadModules() to ensure that + all bindings are loaded if a C++ program starts up the Python interpreter at + some point. + +- TfDlopen(), in tf/dl.cpp calls LoadModules() to ensure that all bindings are + loaded for any newly loaded C++ libraries if Python is already initialized. + +*/ PXR_NAMESPACE_OPEN_SCOPE TF_INSTANTIATE_SINGLETON(TfScriptModuleLoader); -using std::deque; +using std::pair; using std::string; using std::vector; @@ -39,85 +128,74 @@ using pxr_boost::python::dict; using pxr_boost::python::handle; using pxr_boost::python::object; - -TfScriptModuleLoader::TfScriptModuleLoader() -{ -} - -// CODE_COVERAGE_OFF_GCOV_BUG -TfScriptModuleLoader::~TfScriptModuleLoader() -// CODE_COVERAGE_ON_GCOV_BUG -{ -} +TfScriptModuleLoader::TfScriptModuleLoader() = default; +TfScriptModuleLoader::~TfScriptModuleLoader() = default; void TfScriptModuleLoader:: -RegisterLibrary(TfToken const &name, TfToken const &moduleName, +RegisterLibrary(TfToken const &lib, TfToken const &moduleName, vector const &predecessors) { - if (TfDebug::IsEnabled(TF_SCRIPT_MODULE_LOADER)) { TF_DEBUG(TF_SCRIPT_MODULE_LOADER) - .Msg("Registering library %s with predecessors: ", name.GetText()); - TF_FOR_ALL(pred, predecessors) { - TF_DEBUG(TF_SCRIPT_MODULE_LOADER).Msg("%s, ", pred->GetText()); - } - TF_DEBUG(TF_SCRIPT_MODULE_LOADER).Msg("\n"); + .Msg("SML: Registering lib %s with %spredecessors%s%s\n", + lib.GetText(), + predecessors.empty() ? "no " : "", + predecessors.empty() ? "" : " ", + TfStringJoin(predecessors.begin(), + predecessors.end(), ", ").c_str()); } + vector mutablePreds = predecessors; + std::sort(mutablePreds.begin(), mutablePreds.end()); + // Add library with predecessors. - vector &predsInTable = _libInfo[name].predecessors; - predsInTable = predecessors; - std::sort(predsInTable.begin(), predsInTable.end()); - _libsToModules[name] = moduleName; - - // Add this library as a successor to all predecessors. - TF_FOR_ALL(pred, predecessors) - _AddSuccessor(*pred, name); -} - -vector -TfScriptModuleLoader::GetModuleNames() const -{ - vector order; - vector ret; - _TopologicalSort(&order); - ret.reserve(order.size()); - TF_FOR_ALL(lib, order) { - _TokenToTokenMap::const_iterator i = _libsToModules.find(*lib); - if (i != _libsToModules.end()) - ret.push_back(i->second.GetString()); + TfSpinRWMutex::ScopedLock lock(_mutex); + bool success = _libInfo.emplace( + std::piecewise_construct, + std::make_tuple(lib), + std::make_tuple(moduleName, std::move(mutablePreds))).second; + lock.Release(); + + if (!success) { + TF_WARN("Library %s (with module '%s') already registered, repeated " + "registration ignored", lib.GetText(), moduleName.GetText()); } - return ret; } dict TfScriptModuleLoader::GetModulesDict() const { if (!TfPyIsInitialized()) { - TF_CODING_ERROR("Python is not initialized!"); + TF_CODING_ERROR("Python is not initialized."); return dict(); } - // Kick the registry function so any loaded libraries with script - // bindings register themselves with the script module loading system. + // Subscribe to the registry function so any loaded libraries with script + // bindings publish to this singleton. TfRegistryManager::GetInstance().SubscribeTo(); - TfPyLock lock; + // Collect the libs & module names, then release the lock. + TfSpinRWMutex::ScopedLock lock(_mutex, /*write=*/false); + // Make paired lib & module names. + vector> libAndModNames; + libAndModNames.reserve(_libInfo.size()); + for (auto const &[lib, info]: _libInfo) { + libAndModNames.emplace_back(lib, info.moduleName); + } + lock.Release(); + + // Take the python lock and build a dict. + TfPyLock pyLock; // Get the sys.modules dict from python, so we can see if modules are // already loaded. dict modulesDict(handle<>(borrowed(PyImport_GetModuleDict()))); - - vector order; dict ret; - _TopologicalSort(&order); - TF_FOR_ALL(lib, order) { - _TokenToTokenMap::const_iterator i = _libsToModules.find(*lib); - if (i != _libsToModules.end() && - modulesDict.has_key(i->second.GetText())) { - handle<> modHandle(PyImport_ImportModule(const_cast - (i->second.GetText()))); + + for (auto const &[lib, mod]: libAndModNames) { + if (modulesDict.has_key(mod.GetText())) { + handle<> modHandle(PyImport_ImportModule(mod.GetText())); // Use the upper-cased form of the library name as // the Python module name. @@ -142,9 +220,7 @@ TfScriptModuleLoader::GetModulesDict() const // // For now, we just upper-case the library name. // - string moduleName = TfStringCapitalize(lib->GetString()); - - ret[moduleName] = object(modHandle); + ret[TfStringCapitalize(lib.GetString())] = object(modHandle); } } return ret; @@ -158,16 +234,13 @@ TfScriptModuleLoader::WriteDotFile(string const &file) const TF_RUNTIME_ERROR("Could not open '%s' for writing.\n", file.c_str()); return; } - fprintf(out, "digraph Modules {\n"); - - TF_FOR_ALL(info, _libInfo) { - TF_FOR_ALL(successor, info->second.successors) { - fprintf(out, "\t%s -> %s;\n", info->first.GetText(), - successor->GetText()); + TfSpinRWMutex::ScopedLock lock(_mutex, /*write=*/false); + for (auto const &[lib, info]: _libInfo) { + for (TfToken const &pred: info.predecessors) { + fprintf(out, "\t%s -> %s;\n", lib.GetText(), pred.GetText()); } } - fprintf(out, "}\n"); fclose(out); } @@ -175,257 +248,147 @@ TfScriptModuleLoader::WriteDotFile(string const &file) const void TfScriptModuleLoader::LoadModules() { - _LoadModulesFor(TfToken()); -} + // Do nothing if Python is not initialized. + if (!TfPyIsInitialized()) { + return; + } + + // Subscribe to the registry function so any loaded libraries with script + // bindings publish to this singleton. + TfRegistryManager::GetInstance().SubscribeTo(); -void -TfScriptModuleLoader::LoadModulesForLibrary(TfToken const &name) { - _LoadModulesFor(name); -} + TF_DEBUG(TF_SCRIPT_MODULE_LOADER).Msg("SML: Begin loading all modules\n"); -bool -TfScriptModuleLoader::_HasTransitiveSuccessor(TfToken const &predecessor, - TfToken const &successor) const -{ - // This function does a simple DFS of the dependency dag, to determine if \a - // predecessor has \a successor somewhere in the transitive closure. - - vector predStack(1, predecessor); - TfToken::HashSet seenPreds; - - while (!predStack.empty()) { - TfToken pred = predStack.back(); - predStack.pop_back(); - - // A name counts as its own successor. - if (pred == successor) - return true; - - // Look up successors, and push ones not yet visted as possible - // predecessors. - _TokenToInfoMap::const_iterator i = _libInfo.find(pred); - if (i != _libInfo.end()) { - // Walk all the successors. - TF_FOR_ALL(j, i->second.successors) { - // Push those that haven't yet been visited on the stack. - if (seenPreds.insert(pred).second) - predStack.push_back(pred); - } + // Take the lock, then collect all the modules that aren't yet loaded into a + // vector. Then release the lock and call _LoadLibModules() to do the work. + TfSpinRWMutex::ScopedLock lock(_mutex); + vector<_LibAndInfo const *> toLoad; + for (auto iter = _libInfo.begin(), end = _libInfo.end(); + iter != end; ++iter) { + if (!iter->second.isLoaded) { + toLoad.push_back(std::addressof(*iter)); + } + else { + TF_DEBUG(TF_SCRIPT_MODULE_LOADER_EXTRA) + .Msg("SML: Skipping already-loaded %s\n", + iter->first.GetText()); } } - return false; -} + lock.Release(); -static bool _DidPyErrorOccur() -{ - TfPyLock pyLock; - return PyErr_Occurred(); + // Sort modules by lib name to provide a consistent load order. This isn't + // required for correctness but eliminates a source of nondeterminism. + std::sort(toLoad.begin(), toLoad.end(), + [](_LibAndInfo const *l, _LibAndInfo const *r) { + return l->first < r->first; + }); + _LoadLibModules(toLoad); + + TF_DEBUG(TF_SCRIPT_MODULE_LOADER).Msg("SML: End loading all modules\n"); } void -TfScriptModuleLoader::_LoadUpTo(TfToken const &name) +TfScriptModuleLoader +::_LoadLibModules(vector<_LibAndInfo const *> const &toLoad) const { - static size_t indent = 0; - string indentString; - char const *indentTxt = 0; - - if (TfDebug::IsEnabled(TF_SCRIPT_MODULE_LOADER)) { - indentString = std::string(indent * 2, ' '); - indentTxt = indentString.c_str(); - } - - // Don't do anything if the name isn't empty and it's not a name we know - // about. - if (!name.IsEmpty() && !_libInfo.count(name)) { - TF_DEBUG(TF_SCRIPT_MODULE_LOADER) - .Msg("%s*** Not loading modules for unknown lib '%s'\n", - indentTxt, name.GetText()); + if (toLoad.empty()) { return; } + + TfPyLock pyLock; + + for (_LibAndInfo const *libAndInfo: toLoad) { + auto const &[lib, info] = *libAndInfo; - // Otherwise load modules in topological dependency order until we - // encounter the requested module. - vector order; - if (name.IsEmpty()) { - _TopologicalSort(&order); - } else { - _GetOrderedDependencies(vector(1, name), &order); - } - - TF_DEBUG(TF_SCRIPT_MODULE_LOADER) - .Msg("%s_LoadUpTo('%s') {\n", indentTxt, name.GetText()); - TF_FOR_ALL(lib, order) { - // If we encounter the library we're loading on behalf of, quit. - // Mostly this is the last library in the order, but it may not be. - if (*lib == name) - break; - - if (_libsToModules.count(*lib) && !_loadedSet.count(*lib)) { + if (info.moduleName.IsEmpty()) { TF_DEBUG(TF_SCRIPT_MODULE_LOADER) - .Msg("%s Load('%s');\n", indentTxt, lib->GetText()); - _loadedSet.insert(*lib); - ++indent; - Tf_PyLoadScriptModule(_libsToModules[*lib]); - --indent; + .Msg("SML: Not loading unknown module for lib %s\n", + lib.GetText()); + continue; + } + if (info.isLoaded) { + TF_DEBUG(TF_SCRIPT_MODULE_LOADER_EXTRA) + .Msg("SML: Lib %s's module '%s' is already loaded\n", + lib.GetText(), info.moduleName.GetText()); + continue; } + + TF_DEBUG(TF_SCRIPT_MODULE_LOADER) + .Msg("SML: Loading lib %s's module '%s'\n", + lib.GetText(), info.moduleName.GetText()); - if (_DidPyErrorOccur()) { - TF_DEBUG(TF_SCRIPT_MODULE_LOADER).Msg("%s *error*\n", indentTxt); - break; + // Try to load the module. + if (!PyImport_ImportModule(info.moduleName.GetText())) { + // If an error occurred, warn about it with the python traceback, + // and continue. + TF_DEBUG(TF_SCRIPT_MODULE_LOADER) + .Msg("SML: Error loading lib %s's module '%s'\n", + lib.GetText(), info.moduleName.GetText()); + TfPyExceptionState exc = TfPyExceptionState::Fetch(); + string traceback = exc.GetExceptionString(); + TF_WARN("Error loading lib %s's module '%s':\n%s", + lib.GetText(), info.moduleName.GetText(), + traceback.c_str()); } + + // Mark the module loaded, even if there was an error. Otherwise we'll + // keep trying to load it and keep generating the same error. + info.isLoaded = true; } - - TF_DEBUG(TF_SCRIPT_MODULE_LOADER).Msg("%s}\n", indentTxt); } -void -TfScriptModuleLoader::_LoadModulesFor(TfToken const &inName) +TfScriptModuleLoader::_LibInfo const * +TfScriptModuleLoader::_FindInfo(TfToken const &lib) const { - // Don't load anything if python isn't initialized. - if (!TfPyIsInitialized()) - return; - if (_DidPyErrorOccur()) - return; - - ////////////////////////////////////////////////////////////////////////// - // This function handles requests to load modules in topological dependency - // order up to \a inName. Doing so may cause reentrant calls to this - // function. Handling reentrancy works as follows. There are two cases to - // consider. - // - // ----------------------------------------------------------------------- - // Case 1: The reentrant request is for a module that depends (transitively) - // on the module we're currently loading (or is a request to load all - // modules). - // - // In this case, we defer until after the current request is completed. - // We do this because the dependent library may attempt to load the - // library we're currently loading, which would fail. - // - // ------------------------------------------------------------------------ - // Case 2: The reentrant request is for a module that does not depend on the - // module we're currently loading. - // - // In this case, we immediately load the module and its dependencies. - // This is a dynamically discovered dependency of the module we're - // currently loading. - // - // We achieve this by keeping a queue of requests. We always push the - // request on the back of the queue. If we're the outermost call (i.e. not - // reentrant) we loop, processing the queue from the front to the back. For - // a reentrant call, in case 1 (above), we return immediately, deferring the - // work. In case 2 (above) we process the element on the back of the queue - // immediately and pop it. - // - - // Add this request to the remaining work to do. - _remainingLoadWork.push_back(inName); - - // Kick the registry function so any loaded libraries with script bindings - // register themselves with the script module loading system. - TfRegistryManager::GetInstance().SubscribeTo(); - - // If this is the outermost caller initiating loading, start processing the - // queue. - if (_remainingLoadWork.size() == 1) { - while (!_remainingLoadWork.empty() && !_DidPyErrorOccur()) { - // Note: we copy the front of the deque here, since _LoadUpTo may - // add items into the deque. _LoadUpTo currently doesn't access the - // reference-to-token it's passed after it might have modified the - // deque, but this is good defensive coding in case it's changed in - // the future to do so. - TfToken name = _remainingLoadWork.front(); - _LoadUpTo(name); - // We must pop the queue *after* processing, since reentrant calls - // need to see \a name on the front of the queue. See the access of - // _remainingLoadWork.front() below. - _remainingLoadWork.pop_front(); - } - - // Otherwise, this is a reentrant load request. If the reentrant - // request is not to load everything (empty token) and it's also not a - // (transitive) dependency of the library we're currently working on, - // then load it immediately. - } else if (!_remainingLoadWork.back().IsEmpty() && - !_HasTransitiveSuccessor(_remainingLoadWork.front(), - _remainingLoadWork.back())) { - TfToken name = _remainingLoadWork.back(); - _remainingLoadWork.pop_back(); - _LoadUpTo(name); - } + auto iter = _libInfo.find(lib); + return iter != _libInfo.end() ? &iter->second : nullptr; } void -TfScriptModuleLoader:: -_AddSuccessor(TfToken const &lib, TfToken const &successor) +TfScriptModuleLoader::LoadModulesForLibrary(TfToken const &lib) { - if (ARCH_UNLIKELY(lib == successor)) { - // CODE_COVERAGE_OFF Can only happen if there's a bug. - TF_FATAL_ERROR("Library '%s' cannot depend on itself.", lib.GetText()); + // Do nothing if Python is not running. + if (!TfPyIsInitialized()) { return; - // CODE_COVERAGE_ON } - // Add dependent as a dependent of lib. - vector *successors = &(_libInfo[lib].successors); - successors->insert(std::lower_bound(successors->begin(), - successors->end(), successor), - successor); -} - -void -TfScriptModuleLoader -::_GetOrderedDependenciesRecursive(TfToken const &lib, - TfToken::HashSet *seenLibs, - vector *result) const -{ - // If we've not yet visited this library, then visit its predecessors, and - // finally add it to the order. - if (seenLibs->insert(lib).second) { - TF_FOR_ALL(i, _libInfo.find(lib)->second.predecessors) - _GetOrderedDependenciesRecursive(*i, seenLibs, result); - - result->push_back(lib); + // Special-case calling LoadModulesForLibrary with empty token means all. + if (lib.IsEmpty()) { + TF_DEBUG(TF_SCRIPT_MODULE_LOADER).Msg( + "SML: Request to load modules for empty lib name -> load all\n"); + return LoadModules(); } -} -void -TfScriptModuleLoader:: -_GetOrderedDependencies(vector const &input, - vector *result) const -{ - TfToken::HashSet seenLibs; - TF_FOR_ALL(i, input) { - // If we haven't seen the current input yet, add its predecessors (and - // their dependencies) to the result. - if (seenLibs.insert(*i).second) { - TF_FOR_ALL(j, _libInfo.find(*i)->second.predecessors) - _GetOrderedDependenciesRecursive(*j, &seenLibs, result); + // Subscribe to the registry function so any loaded libraries with script + // bindings publish to this singleton. + TfRegistryManager::GetInstance().SubscribeTo(); + + // We only load direct dependencies, since when we run the initializer for + // the python bindings lib, it will call back into here to load _its_ + // dependencies, and we get the transitive loading that way. + + TF_DEBUG(TF_SCRIPT_MODULE_LOADER).Msg( + "SML: Begin loading %s's predecessors\n", lib.GetText()); + + // Take the lock, then collect all the modules that this lib directly + // depends on that aren't already loaded, add them to `toLoad`, then release + // the lock and load all the modules. + TfSpinRWMutex::ScopedLock lock(_mutex); + vector<_LibAndInfo const *> toLoad; + if (_LibInfo const *libInfo = _FindInfo(lib)) { + for (TfToken const &pred: libInfo->predecessors) { + auto iter = _libInfo.find(pred); + if (iter != _libInfo.end() && !iter->second.isLoaded) { + toLoad.push_back(std::addressof(*iter)); + } } } -} - - -void -TfScriptModuleLoader:: -_TopologicalSort(vector *result) const -{ - // Find all libs with no successors, then produce all ordered dependencies - // from them. - vector leaves; - TF_FOR_ALL(i, _libInfo) { - if (i->second.successors.empty()) - leaves.push_back(i->first); - } - - // Sort to ensure determinism. - std::sort(leaves.begin(), leaves.end()); - - // Find all the leaves' dependencies. - _GetOrderedDependencies(leaves, result); + lock.Release(); + + _LoadLibModules(toLoad); - // Add the leaves themselves, at the end. - result->insert(result->end(), leaves.begin(), leaves.end()); + TF_DEBUG(TF_SCRIPT_MODULE_LOADER).Msg( + "SML: End loading %s's predecessors\n", lib.GetText()); } PXR_NAMESPACE_CLOSE_SCOPE diff --git a/pxr/base/tf/scriptModuleLoader.h b/pxr/base/tf/scriptModuleLoader.h index d8d48e8eaae..2779c2b16e3 100644 --- a/pxr/base/tf/scriptModuleLoader.h +++ b/pxr/base/tf/scriptModuleLoader.h @@ -12,6 +12,7 @@ #include "pxr/base/tf/api.h" #include "pxr/base/tf/hash.h" #include "pxr/base/tf/singleton.h" +#include "pxr/base/tf/spinRWMutex.h" #include "pxr/base/tf/token.h" #include "pxr/base/tf/weakBase.h" @@ -21,9 +22,8 @@ #include "pxr/external/boost/python/dict.hpp" #include -#include "pxr/base/tf/hashmap.h" -#include "pxr/base/tf/hashset.h" #include +#include #include PXR_NAMESPACE_OPEN_SCOPE @@ -67,61 +67,46 @@ class TfScriptModuleLoader : public TfWeakBase { /// RegisterLibrary that depend on library \a name. TF_API void LoadModulesForLibrary(TfToken const &name); - - /// Return a list of all currently known modules in a valid dependency - /// order. - TF_API - std::vector GetModuleNames() const; - + /// Return a python dict containing all currently known modules under /// their canonical names. TF_API pxr_boost::python::dict GetModulesDict() const; - /// Write a graphviz dot-file for the dependency graph of all. currently - /// known libraries/modules to \a file. + /// Write a graphviz dot-file for the dependency graph of all currently + /// registered libraries/modules to \a file. TF_API void WriteDotFile(std::string const &file) const; private: + friend class TfSingleton; struct _LibInfo { - _LibInfo() {} - std::vector predecessors, successors; + _LibInfo() = default; + _LibInfo(TfToken const &moduleName, + std::vector &&predecessors) + : moduleName(moduleName) + , predecessors(predecessors) { } + + TfToken moduleName; + std::vector predecessors; + mutable std::atomic isLoaded = false; }; - typedef TfHashMap - _TokenToInfoMap; + using _LibInfoMap = + std::unordered_map; + + using _LibAndInfo = _LibInfoMap::value_type; - typedef TfHashMap - _TokenToTokenMap; - - typedef TfHashSet - _TokenSet; - TfScriptModuleLoader(); virtual ~TfScriptModuleLoader(); - friend class TfSingleton; + + _LibInfo const *_FindInfo(TfToken const &lib) const; + + void _LoadLibModules(std::vector<_LibAndInfo const *> const &toLoad) const; - void _AddSuccessor(TfToken const &lib, TfToken const &successor); - void _LoadModulesFor(TfToken const &name); - void _LoadUpTo(TfToken const &name); - void _GetOrderedDependenciesRecursive(TfToken const &lib, - TfToken::HashSet *seenLibs, - std::vector *result) const; - void _GetOrderedDependencies(std::vector const &input, - std::vector *result) const; - void _TopologicalSort(std::vector *result) const; - - bool _HasTransitiveSuccessor(TfToken const &predecessor, - TfToken const &successor) const; - - _TokenToInfoMap _libInfo; - _TokenToTokenMap _libsToModules; - _TokenSet _loadedSet; - - // This is only used to handle reentrant loading requests. - std::deque _remainingLoadWork; + _LibInfoMap _libInfo; + mutable TfSpinRWMutex _mutex; }; TF_API_TEMPLATE_CLASS(TfSingleton); diff --git a/pxr/base/tf/testenv/baseline/TfDebugTestEnv/non-specific/debugTestEnv.out b/pxr/base/tf/testenv/baseline/TfDebugTestEnv/non-specific/debugTestEnv.out index d14ee35e964..bfe77dbc3f6 100644 --- a/pxr/base/tf/testenv/baseline/TfDebugTestEnv/non-specific/debugTestEnv.out +++ b/pxr/base/tf/testenv/baseline/TfDebugTestEnv/non-specific/debugTestEnv.out @@ -23,5 +23,7 @@ TF_LOG_STACK_TRACE_ON_WARNING: TF_PRINT_ALL_POSTED_ERRORS_TO_STDERR: print all posted errors immediately, meaning that even errors that are expected and handled will be printed, producing possibly confusing output TF_SCRIPT_MODULE_LOADER : show script module loading activity +TF_SCRIPT_MODULE_LOADER_EXTRA: + show more script module loading activity TF_TYPE_REGISTRY : show changes to the TfType registry diff --git a/pxr/base/tf/testenv/baseline/testTfScriptModuleLoader/scriptModuleLoader.out b/pxr/base/tf/testenv/baseline/testTfScriptModuleLoader/scriptModuleLoader.out index d68d118571b..aec6b564802 100644 --- a/pxr/base/tf/testenv/baseline/testTfScriptModuleLoader/scriptModuleLoader.out +++ b/pxr/base/tf/testenv/baseline/testTfScriptModuleLoader/scriptModuleLoader.out @@ -1,45 +1,47 @@ # Test case: loading one library generates a request to load all # libraries, one of which attemps to import the library we're # currently loading. -Registering library LoadsAll with predecessors: -Registering library DepLoadsAll with predecessors: LoadsAll, -Registering library Other with predecessors: LoadsAll, +SML: Registering lib LoadsAll with no predecessors +SML: Registering lib DepLoadsAll with predecessors LoadsAll +SML: Registering lib Other with predecessors LoadsAll # This should attempt to (forwardly) load Other, which in turn tries # to import LoadsAll, which would fail, but we defer loading Other # until after LoadsAll is finished loading. -_LoadUpTo('DepLoadsAll') { - Load('LoadsAll'); - _LoadUpTo('LoadsAll') { - } -} -_LoadUpTo('') { - Load('DepLoadsAll'); - _LoadUpTo('DepLoadsAll') { - } - Load('Other'); - _LoadUpTo('Other') { - } -} +SML: Begin loading DepLoadsAll's predecessors +SML: Loading lib LoadsAll's module 'pxr.Tf.testenv.testTfScriptModuleLoader_LoadsAll' +SML: Begin loading LoadsAll's predecessors +SML: End loading LoadsAll's predecessors +SML: Request to load modules for empty lib name -> load all +SML: Begin loading all modules +SML: Loading lib DepLoadsAll's module 'pxr.Tf.testenv.testTfScriptModuleLoader_DepLoadsAll' +SML: Begin loading DepLoadsAll's predecessors +SML: Loading lib LoadsAll's module 'pxr.Tf.testenv.testTfScriptModuleLoader_LoadsAll' +SML: End loading DepLoadsAll's predecessors +SML: Loading lib Other's module 'pxr.Tf.testenv.testTfScriptModuleLoader_Other' +SML: Begin loading Other's predecessors +SML: End loading Other's predecessors +SML: End loading all modules +SML: End loading DepLoadsAll's predecessors # Registering a library that is totally independent, and raises an # error when loaded, but whose name comes first in dependency order. # Since there is no real dependency, the SML should not try to load # this module, which would cause an exception. -Registering library AAA_RaisesError with predecessors: +SML: Registering lib AAA_RaisesError with no predecessors # Test case: loading one library dynamically imports a new, # previously unknown dependent library, which registers further # dependencies, and expects them to load. -Registering library LoadsUnknown with predecessors: -Registering library Test with predecessors: LoadsUnknown, +SML: Registering lib LoadsUnknown with no predecessors +SML: Registering lib Test with predecessors LoadsUnknown # This should load LoadsUnknown, which loads Unknown dynamically, # which should request for Unknown's dependencies (NewDependency) to # load, which should work. -_LoadUpTo('Test') { - Load('LoadsUnknown'); - _LoadUpTo('LoadsUnknown') { - } -Registering library Unknown with predecessors: NewDynamicDependency, -Registering library NewDynamicDependency with predecessors: - _LoadUpTo('Unknown') { - Load('NewDynamicDependency'); - } -} +SML: Begin loading Test's predecessors +SML: Loading lib LoadsUnknown's module 'pxr.Tf.testenv.testTfScriptModuleLoader_LoadsUnknown' +SML: Begin loading LoadsUnknown's predecessors +SML: End loading LoadsUnknown's predecessors +SML: Registering lib Unknown with predecessors NewDynamicDependency +SML: Registering lib NewDynamicDependency with no predecessors +SML: Begin loading Unknown's predecessors +SML: Loading lib NewDynamicDependency's module 'sys' +SML: End loading Unknown's predecessors +SML: End loading Test's predecessors diff --git a/pxr/base/tf/testenv/testTfScriptModuleLoader.py b/pxr/base/tf/testenv/testTfScriptModuleLoader.py index a88f7a00ce3..092f9e7429e 100644 --- a/pxr/base/tf/testenv/testTfScriptModuleLoader.py +++ b/pxr/base/tf/testenv/testTfScriptModuleLoader.py @@ -5,8 +5,6 @@ # Licensed under the terms set forth in the LICENSE.txt file available at # https://openusd.org/license. # -from __future__ import print_function - from pxr import Tf import sys diff --git a/pxr/base/tf/wrapScriptModuleLoader.cpp b/pxr/base/tf/wrapScriptModuleLoader.cpp index f35a54a045c..1099f097eec 100644 --- a/pxr/base/tf/wrapScriptModuleLoader.cpp +++ b/pxr/base/tf/wrapScriptModuleLoader.cpp @@ -24,8 +24,6 @@ void wrapScriptModuleLoader() { class_, noncopyable>("ScriptModuleLoader", no_init) .def(TfPySingleton()) - .def("GetModuleNames", &This::GetModuleNames, - return_value_policy()) .def("GetModulesDict", &This::GetModulesDict) .def("WriteDotFile", &This::WriteDotFile) diff --git a/pxr/base/trace/pch.h b/pxr/base/trace/pch.h index 3f55f620a5d..a284f34fcfe 100644 --- a/pxr/base/trace/pch.h +++ b/pxr/base/trace/pch.h @@ -76,6 +76,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/pxr/base/ts/pch.h b/pxr/base/ts/pch.h index 4e45f17d93d..727470bbffa 100644 --- a/pxr/base/ts/pch.h +++ b/pxr/base/ts/pch.h @@ -67,6 +67,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/pxr/base/vt/pch.h b/pxr/base/vt/pch.h index 460eeb04cb7..28b79993992 100644 --- a/pxr/base/vt/pch.h +++ b/pxr/base/vt/pch.h @@ -72,6 +72,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/pxr/base/work/pch.h b/pxr/base/work/pch.h index 25bfece6577..0a10f750ff0 100644 --- a/pxr/base/work/pch.h +++ b/pxr/base/work/pch.h @@ -61,6 +61,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/pxr/external/boost/python/converter/obj_mgr_arg_from_python.hpp b/pxr/external/boost/python/converter/obj_mgr_arg_from_python.hpp index 8751e92d362..7ad954c92ec 100644 --- a/pxr/external/boost/python/converter/obj_mgr_arg_from_python.hpp +++ b/pxr/external/boost/python/converter/obj_mgr_arg_from_python.hpp @@ -58,6 +58,13 @@ struct object_manager_ref_arg_from_python typedef Ref result_type; object_manager_ref_arg_from_python(PyObject*); + + // Disallow copies to avoid double-destruction of object in m_result. + object_manager_ref_arg_from_python( + object_manager_ref_arg_from_python const&) = delete; + object_manager_ref_arg_from_python& operator=( + object_manager_ref_arg_from_python const&) = delete; + bool convertible() const; Ref operator()() const; ~object_manager_ref_arg_from_python(); diff --git a/pxr/external/boost/python/converter/rvalue_from_python_data.hpp b/pxr/external/boost/python/converter/rvalue_from_python_data.hpp index 24c1f61d588..64f84071984 100644 --- a/pxr/external/boost/python/converter/rvalue_from_python_data.hpp +++ b/pxr/external/boost/python/converter/rvalue_from_python_data.hpp @@ -118,6 +118,10 @@ struct rvalue_from_python_data : rvalue_from_python_storage // conversion, where the construct() function is already known. rvalue_from_python_data(void* convertible); + // Disallow copies to avoid double-destruction of object in storage. + rvalue_from_python_data(rvalue_from_python_data const&) = delete; + rvalue_from_python_data& operator=(rvalue_from_python_data const&) = delete; + // Destroys any object constructed in the storage. ~rvalue_from_python_data(); private: diff --git a/pxr/external/boost/python/detail/caller.hpp b/pxr/external/boost/python/detail/caller.hpp index c0e762c47dd..0cabb302878 100644 --- a/pxr/external/boost/python/detail/caller.hpp +++ b/pxr/external/boost/python/detail/caller.hpp @@ -218,12 +218,17 @@ struct caller }; -template +template struct caller_arity> { template - struct impl + struct impl; + + template + struct impl> { + using Sig = python::type_list; + impl(F f, Policies p) : m_data(f,p) {} PyObject* operator()(PyObject* args_, PyObject*) // eliminate @@ -231,39 +236,33 @@ struct caller_arity> // trailing // keyword dict { - typedef typename detail::mpl2::front::type result_t; + typedef Ret result_t; typedef typename select_result_converter::type result_converter; typedef typename Policies::argument_package argument_package; argument_package inner_args(args_); - // N... is a 0-based sequence of indexes corresponding to the - // expected arguments in args_. However, this must be offset by - // 1 to retrieve the corresponding argument type from Sig, since - // that type sequence begins with an additional entry representing - // the function's return type. - using arg_from_python_tuple = std::tuple< - arg_from_python::type>... - >; - arg_from_python_tuple t{ get(detail::mpl2::int_(), inner_args)... }; - - if ( (... || !std::get(t).convertible()) ) { - return 0; - } - - // all converters have been checked. Now we can do the - // precall part of the policy - if (!m_data.second().precall(inner_args)) - return 0; - - PyObject* result = detail::invoke( - detail::invoke_tag() - , create_result_converter(args_, (result_converter*)0, (result_converter*)0) - , m_data.first() - , std::get(t)... - ); + return [&](auto... arg) -> PyObject* + { + if ((!arg.convertible() || ...)) { + return 0; + } + + // all converters have been checked. Now we can do the + // precall part of the policy + if (!m_data.second().precall(inner_args)) + return 0; + + PyObject* result = detail::invoke( + detail::invoke_tag() + , create_result_converter(args_, (result_converter*)0, (result_converter*)0) + , m_data.first() + , arg... + ); - return m_data.second().postcall(inner_args, result); + return m_data.second().postcall(inner_args, result); + + }(arg_from_python(get(detail::mpl2::int_(), inner_args))...); } static unsigned min_arity() { return sizeof...(N); } diff --git a/pxr/imaging/cameraUtil/pch.h b/pxr/imaging/cameraUtil/pch.h index d4afe14ccdd..732f9191adf 100644 --- a/pxr/imaging/cameraUtil/pch.h +++ b/pxr/imaging/cameraUtil/pch.h @@ -48,6 +48,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/pxr/imaging/garch/pch.h b/pxr/imaging/garch/pch.h index b92e8639121..65911b2f896 100644 --- a/pxr/imaging/garch/pch.h +++ b/pxr/imaging/garch/pch.h @@ -67,6 +67,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/pxr/imaging/geomUtil/pch.h b/pxr/imaging/geomUtil/pch.h index f67c8707178..c619cdeb702 100644 --- a/pxr/imaging/geomUtil/pch.h +++ b/pxr/imaging/geomUtil/pch.h @@ -50,6 +50,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/pxr/imaging/glf/pch.h b/pxr/imaging/glf/pch.h index 381a5b9b567..72eaafa5159 100644 --- a/pxr/imaging/glf/pch.h +++ b/pxr/imaging/glf/pch.h @@ -87,6 +87,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/pxr/imaging/hd/CMakeLists.txt b/pxr/imaging/hd/CMakeLists.txt index 84bd7f4afa2..a79becac8ce 100644 --- a/pxr/imaging/hd/CMakeLists.txt +++ b/pxr/imaging/hd/CMakeLists.txt @@ -103,6 +103,8 @@ pxr_library(hd legacyDisplayStyleSchema legacyGeomSubsetSceneIndex legacyPrimSceneIndex + legacyTaskFactory + legacyTaskSchema lensDistortionSchema light lightSchema diff --git a/pxr/imaging/hd/codegenTemplates/schemaClass.h b/pxr/imaging/hd/codegenTemplates/schemaClass.h index aff00a12fe5..15254941e53 100644 --- a/pxr/imaging/hd/codegenTemplates/schemaClass.h +++ b/pxr/imaging/hd/codegenTemplates/schemaClass.h @@ -19,11 +19,12 @@ #define {{ HEADER_GUARD|snake }}_{{ FILE_NAME|snake }}_H /// \file - +{% if LIBRARY_API %} #include "{{ INCLUDE_PATH }}/api.h" +{%- endif -%} {%- if SCHEMA_INCLUDES is defined -%} -{%- for t in SCHEMA_INCLUDES %} +{% for t in SCHEMA_INCLUDES %} #include "{{ t | expand }}.h" {%- endfor -%} {%- endif %} @@ -75,7 +76,7 @@ PXR_NAMESPACE_OPEN_SCOPE {%- endfor -%} {%- endif %} -TF_DECLARE_PUBLIC_TOKENS({{SCHEMA_CLASS_NAME}}Tokens, {{ LIBRARY_API }}, +TF_DECLARE_PUBLIC_TOKENS({{SCHEMA_CLASS_NAME}}Tokens,{% if LIBRARY_API%} {{ LIBRARY_API }},{% endif %} {{ SCHEMA_CLASS_NAME|snake }}_TOKENS); //----------------------------------------------------------------------------- diff --git a/pxr/imaging/hd/dirtyBitsTranslator.cpp b/pxr/imaging/hd/dirtyBitsTranslator.cpp index 6bffdebe75e..fda98cf58b8 100644 --- a/pxr/imaging/hd/dirtyBitsTranslator.cpp +++ b/pxr/imaging/hd/dirtyBitsTranslator.cpp @@ -44,6 +44,7 @@ #include "pxr/imaging/hd/instanceSchema.h" #include "pxr/imaging/hd/integratorSchema.h" #include "pxr/imaging/hd/legacyDisplayStyleSchema.h" +#include "pxr/imaging/hd/legacyTaskSchema.h" #include "pxr/imaging/hd/lightSchema.h" #include "pxr/imaging/hd/materialBindingsSchema.h" #include "pxr/imaging/hd/materialConnectionSchema.h" @@ -396,7 +397,12 @@ HdDirtyBitsTranslator::InstancerDirtyBitsToLocatorSet(TfToken const& primType, set->append(HdXformSchema::GetDefaultLocator()); } if (bits & HdChangeTracker::DirtyCategories) { + // Note: We don't have a DirtyInstanceCategories bit. + // For point instancers, instance categories is not relevant (i.e. all + // instances are affected), so we invalidate both categories and + // instanceCategories locators. set->append(HdInstanceCategoriesSchema::GetDefaultLocator()); + set->append(HdCategoriesSchema::GetDefaultLocator()); } } @@ -934,8 +940,13 @@ HdDirtyBitsTranslator::InstancerLocatorSetToDirtyBits( HdDataSourceLocatorSet::const_iterator end = set.end(); HdDirtyBits bits = HdChangeTracker::Clean; + if (_FindLocator(HdCategoriesSchema::GetDefaultLocator(), end, &it)) { + // This is relevant for point instancers. + bits |= HdChangeTracker::DirtyCategories; + } if (_FindLocator(HdInstanceCategoriesSchema::GetDefaultLocator(), end, &it)) { // We don't have an instance categories dirty bit. + // This is relevant for native instancers. bits |= HdChangeTracker::DirtyCategories; } if (_FindLocator(HdInstancedBySchema::GetDefaultLocator(), end, &it)) { @@ -954,6 +965,43 @@ HdDirtyBitsTranslator::InstancerLocatorSetToDirtyBits( return bits; } +/*static*/ +HdDirtyBits +HdDirtyBitsTranslator::TaskLocatorSetToDirtyBits( + HdDataSourceLocatorSet const& set) +{ + HdDataSourceLocatorSet::const_iterator it = set.begin(); + + const HdDataSourceLocatorSet::const_iterator end = set.end(); + + if (it == end) { + return HdChangeTracker::Clean; + } + + // Note, for efficiency we search for locators in the set in order, so that + // we only end up making one trip through the set. If you add to this + // function, make sure you sort the addition by locator name, or + // _FindLocator won't work. + + if (*it == HdDataSourceLocator::EmptyLocator()) { + return HdChangeTracker::AllDirty; + } + + HdDirtyBits bits = HdChangeTracker::Clean; + + if (_FindLocator(HdLegacyTaskSchema::GetCollectionLocator(), end, &it)) { + bits |= HdChangeTracker::DirtyCollection; + } + if (_FindLocator(HdLegacyTaskSchema::GetParametersLocator(), end, &it)) { + bits |= HdChangeTracker::DirtyParams; + } + if (_FindLocator(HdLegacyTaskSchema::GetRenderTagsLocator(), end, &it)) { + bits |= HdChangeTracker::DirtyRenderTags; + } + + return bits; +} + /*static*/ HdDirtyBits HdDirtyBitsTranslator::BprimLocatorSetToDirtyBits( diff --git a/pxr/imaging/hd/dirtyBitsTranslator.h b/pxr/imaging/hd/dirtyBitsTranslator.h index 22e2bd19af3..e9a6f2a7442 100644 --- a/pxr/imaging/hd/dirtyBitsTranslator.h +++ b/pxr/imaging/hd/dirtyBitsTranslator.h @@ -48,7 +48,10 @@ class HdDirtyBitsTranslator HD_API static HdDirtyBits InstancerLocatorSetToDirtyBits(TfToken const& primType, HdDataSourceLocatorSet const& set); - + HD_API + static HdDirtyBits TaskLocatorSetToDirtyBits( + HdDataSourceLocatorSet const& set); + using LocatorSetToDirtyBitsFnc = std::function; diff --git a/pxr/imaging/hd/hdSchemaDefs.py b/pxr/imaging/hd/hdSchemaDefs.py index 302f89dec42..a4cc0ebfdac 100644 --- a/pxr/imaging/hd/hdSchemaDefs.py +++ b/pxr/imaging/hd/hdSchemaDefs.py @@ -866,6 +866,7 @@ SCHEMA_NAME = 'RenderBuffer', SCHEMA_TOKEN = 'renderBuffer', MEMBERS = [ + ('ALL_MEMBERS', '', dict(ADD_LOCATOR = True)), ('dimensions', T_VEC3I, {}), ('format', T_FORMAT, {}), ('multiSampled', T_BOOL, {}), @@ -1382,5 +1383,25 @@ ], ADD_DEFAULT_LOCATOR = True, ), + #-------------------------------------------------------------------------- + # legacyTask + dict( + SCHEMA_NAME = 'LegacyTask', + DOC = '''The {{ SCHEMA_CLASS_NAME }} specifies a Hydra task by providing + a task factory and data.''', + SCHEMA_TOKEN = 'task', + ADD_DEFAULT_LOCATOR = True, + MEMBERS = [ + ('ALL_MEMBERS', '', dict(ADD_LOCATOR = True)), + ('factory', 'HdLegacyTaskFactoryDataSource', {}), + ('parameters', T_SAMPLED, + dict(DOC = ''' + Parameters for task. Type depends on task type. + E.g. HdxRenderTaskParams if the factory produces HdxRenderTask + instances.''')), + ('collection', 'HdRprimCollectionDataSource', {}), + ('renderTags', 'HdTokenVectorDataSource', {}), + ], + ), ] diff --git a/pxr/imaging/hd/legacyTaskFactory.cpp b/pxr/imaging/hd/legacyTaskFactory.cpp new file mode 100644 index 00000000000..cec97b37d83 --- /dev/null +++ b/pxr/imaging/hd/legacyTaskFactory.cpp @@ -0,0 +1,14 @@ +// +// Copyright 2024 Pixar +// +// Licensed under the terms set forth in the LICENSE.txt file available at +// https://openusd.org/license. +// + +#include "pxr/imaging/hd/legacyTaskFactory.h" + +PXR_NAMESPACE_OPEN_SCOPE + +HdLegacyTaskFactory::~HdLegacyTaskFactory() = default; + +PXR_NAMESPACE_CLOSE_SCOPE diff --git a/pxr/imaging/hd/legacyTaskFactory.h b/pxr/imaging/hd/legacyTaskFactory.h new file mode 100644 index 00000000000..ad07f9469a0 --- /dev/null +++ b/pxr/imaging/hd/legacyTaskFactory.h @@ -0,0 +1,59 @@ +// +// Copyright 2024 Pixar +// +// Licensed under the terms set forth in the LICENSE.txt file available at +// https://openusd.org/license. +// +#ifndef PXR_IMAGING_HD_LEGACY_TASK_FACTORY_H +#define PXR_IMAGING_HD_LEGACY_TASK_FACTORY_H + +#include "pxr/pxr.h" +#include "pxr/imaging/hd/api.h" + +#include "pxr/usd/sdf/path.h" + +#include + +PXR_NAMESPACE_OPEN_SCOPE + +class HdSceneDelegate; +using HdTaskSharedPtr = std::shared_ptr; +using HdLegacyTaskFactorySharedPtr = std::shared_ptr; + +/// +/// \class HdLegacyTaskFactory +/// +/// An abstract base class to create implementations of HdTask. +/// +class HdLegacyTaskFactory +{ +public: + virtual HdTaskSharedPtr Create( + HdSceneDelegate * delegate, const SdfPath &id) = 0; + + HD_API + virtual ~HdLegacyTaskFactory(); +}; + +template +class HdLegacyTaskFactory_Impl : public HdLegacyTaskFactory +{ +public: + HdTaskSharedPtr Create( + HdSceneDelegate * const delegate, const SdfPath &id) override + { + return std::make_shared(delegate, id); + } +}; + +/// Given a subclass implementing HdTask, create a factory for that +/// subclass. +template +HdLegacyTaskFactorySharedPtr HdMakeLegacyTaskFactory() +{ + return std::make_shared>(); +} + +PXR_NAMESPACE_CLOSE_SCOPE + +#endif diff --git a/pxr/imaging/hd/legacyTaskSchema.cpp b/pxr/imaging/hd/legacyTaskSchema.cpp new file mode 100644 index 00000000000..55e6abcaa02 --- /dev/null +++ b/pxr/imaging/hd/legacyTaskSchema.cpp @@ -0,0 +1,209 @@ +// +// Copyright 2023 Pixar +// +// Licensed under the terms set forth in the LICENSE.txt file available at +// https://openusd.org/license. +// +//////////////////////////////////////////////////////////////////////// + +/* ************************************************************************** */ +/* ** ** */ +/* ** This file is generated by a script. ** */ +/* ** ** */ +/* ** Do not edit it directly (unless it is within a CUSTOM CODE section)! ** */ +/* ** Edit hdSchemaDefs.py instead to make changes. ** */ +/* ** ** */ +/* ************************************************************************** */ + +#include "pxr/imaging/hd/legacyTaskSchema.h" + +#include "pxr/imaging/hd/retainedDataSource.h" + +#include "pxr/base/trace/trace.h" + +// --(BEGIN CUSTOM CODE: Includes)-- +// --(END CUSTOM CODE: Includes)-- + +PXR_NAMESPACE_OPEN_SCOPE + +TF_DEFINE_PUBLIC_TOKENS(HdLegacyTaskSchemaTokens, + HD_LEGACY_TASK_SCHEMA_TOKENS); + +// --(BEGIN CUSTOM CODE: Schema Methods)-- +// --(END CUSTOM CODE: Schema Methods)-- + +HdLegacyTaskFactoryDataSourceHandle +HdLegacyTaskSchema::GetFactory() const +{ + return _GetTypedDataSource( + HdLegacyTaskSchemaTokens->factory); +} + +HdSampledDataSourceHandle +HdLegacyTaskSchema::GetParameters() const +{ + return _GetTypedDataSource( + HdLegacyTaskSchemaTokens->parameters); +} + +HdRprimCollectionDataSourceHandle +HdLegacyTaskSchema::GetCollection() const +{ + return _GetTypedDataSource( + HdLegacyTaskSchemaTokens->collection); +} + +HdTokenVectorDataSourceHandle +HdLegacyTaskSchema::GetRenderTags() const +{ + return _GetTypedDataSource( + HdLegacyTaskSchemaTokens->renderTags); +} + +/*static*/ +HdContainerDataSourceHandle +HdLegacyTaskSchema::BuildRetained( + const HdLegacyTaskFactoryDataSourceHandle &factory, + const HdSampledDataSourceHandle ¶meters, + const HdRprimCollectionDataSourceHandle &collection, + const HdTokenVectorDataSourceHandle &renderTags +) +{ + TfToken _names[4]; + HdDataSourceBaseHandle _values[4]; + + size_t _count = 0; + + if (factory) { + _names[_count] = HdLegacyTaskSchemaTokens->factory; + _values[_count++] = factory; + } + + if (parameters) { + _names[_count] = HdLegacyTaskSchemaTokens->parameters; + _values[_count++] = parameters; + } + + if (collection) { + _names[_count] = HdLegacyTaskSchemaTokens->collection; + _values[_count++] = collection; + } + + if (renderTags) { + _names[_count] = HdLegacyTaskSchemaTokens->renderTags; + _values[_count++] = renderTags; + } + return HdRetainedContainerDataSource::New(_count, _names, _values); +} + +HdLegacyTaskSchema::Builder & +HdLegacyTaskSchema::Builder::SetFactory( + const HdLegacyTaskFactoryDataSourceHandle &factory) +{ + _factory = factory; + return *this; +} + +HdLegacyTaskSchema::Builder & +HdLegacyTaskSchema::Builder::SetParameters( + const HdSampledDataSourceHandle ¶meters) +{ + _parameters = parameters; + return *this; +} + +HdLegacyTaskSchema::Builder & +HdLegacyTaskSchema::Builder::SetCollection( + const HdRprimCollectionDataSourceHandle &collection) +{ + _collection = collection; + return *this; +} + +HdLegacyTaskSchema::Builder & +HdLegacyTaskSchema::Builder::SetRenderTags( + const HdTokenVectorDataSourceHandle &renderTags) +{ + _renderTags = renderTags; + return *this; +} + +HdContainerDataSourceHandle +HdLegacyTaskSchema::Builder::Build() +{ + return HdLegacyTaskSchema::BuildRetained( + _factory, + _parameters, + _collection, + _renderTags + ); +} + +/*static*/ +HdLegacyTaskSchema +HdLegacyTaskSchema::GetFromParent( + const HdContainerDataSourceHandle &fromParentContainer) +{ + return HdLegacyTaskSchema( + fromParentContainer + ? HdContainerDataSource::Cast(fromParentContainer->Get( + HdLegacyTaskSchemaTokens->task)) + : nullptr); +} + +/*static*/ +const TfToken & +HdLegacyTaskSchema::GetSchemaToken() +{ + return HdLegacyTaskSchemaTokens->task; +} + +/*static*/ +const HdDataSourceLocator & +HdLegacyTaskSchema::GetDefaultLocator() +{ + static const HdDataSourceLocator locator(GetSchemaToken()); + return locator; +} + +/* static */ +const HdDataSourceLocator & +HdLegacyTaskSchema::GetFactoryLocator() +{ + static const HdDataSourceLocator locator = + GetDefaultLocator().Append( + HdLegacyTaskSchemaTokens->factory); + return locator; +} + +/* static */ +const HdDataSourceLocator & +HdLegacyTaskSchema::GetParametersLocator() +{ + static const HdDataSourceLocator locator = + GetDefaultLocator().Append( + HdLegacyTaskSchemaTokens->parameters); + return locator; +} + +/* static */ +const HdDataSourceLocator & +HdLegacyTaskSchema::GetCollectionLocator() +{ + static const HdDataSourceLocator locator = + GetDefaultLocator().Append( + HdLegacyTaskSchemaTokens->collection); + return locator; +} + +/* static */ +const HdDataSourceLocator & +HdLegacyTaskSchema::GetRenderTagsLocator() +{ + static const HdDataSourceLocator locator = + GetDefaultLocator().Append( + HdLegacyTaskSchemaTokens->renderTags); + return locator; +} + +PXR_NAMESPACE_CLOSE_SCOPE \ No newline at end of file diff --git a/pxr/imaging/hd/legacyTaskSchema.h b/pxr/imaging/hd/legacyTaskSchema.h new file mode 100644 index 00000000000..acd2f53edb6 --- /dev/null +++ b/pxr/imaging/hd/legacyTaskSchema.h @@ -0,0 +1,207 @@ +// +// Copyright 2023 Pixar +// +// Licensed under the terms set forth in the LICENSE.txt file available at +// https://openusd.org/license. +// +//////////////////////////////////////////////////////////////////////// + +/* ************************************************************************** */ +/* ** ** */ +/* ** This file is generated by a script. ** */ +/* ** ** */ +/* ** Do not edit it directly (unless it is within a CUSTOM CODE section)! ** */ +/* ** Edit hdSchemaDefs.py instead to make changes. ** */ +/* ** ** */ +/* ************************************************************************** */ + +#ifndef PXR_IMAGING_HD_LEGACY_TASK_SCHEMA_H +#define PXR_IMAGING_HD_LEGACY_TASK_SCHEMA_H + +/// \file + +#include "pxr/imaging/hd/api.h" + +#include "pxr/imaging/hd/schema.h" + +// --(BEGIN CUSTOM CODE: Includes)-- +#include "pxr/imaging/hd/rprimCollection.h" +// --(END CUSTOM CODE: Includes)-- + +PXR_NAMESPACE_OPEN_SCOPE + +// --(BEGIN CUSTOM CODE: Declares)-- + +using HdRprimCollectionDataSource = HdTypedSampledDataSource; +using HdRprimCollectionDataSourceHandle = HdRprimCollectionDataSource::Handle; + +using HdTokenVectorDataSource = HdTypedSampledDataSource; +using HdTokenVectorDataSourceHandle = HdTokenVectorDataSource::Handle; + +using HdLegacyTaskFactorySharedPtr = std::shared_ptr; +using HdLegacyTaskFactoryDataSource = + HdTypedSampledDataSource; +using HdLegacyTaskFactoryDataSourceHandle = + HdLegacyTaskFactoryDataSource::Handle; + + +// --(END CUSTOM CODE: Declares)-- + +#define HD_LEGACY_TASK_SCHEMA_TOKENS \ + (task) \ + (factory) \ + (parameters) \ + (collection) \ + (renderTags) \ + +TF_DECLARE_PUBLIC_TOKENS(HdLegacyTaskSchemaTokens, HD_API, + HD_LEGACY_TASK_SCHEMA_TOKENS); + +//----------------------------------------------------------------------------- + +// The HdLegacyTaskSchema specifies a Hydra task by providing a task factory +// and data. +// + +class HdLegacyTaskSchema : public HdSchema +{ +public: + /// \name Schema retrieval + /// @{ + + HdLegacyTaskSchema(HdContainerDataSourceHandle container) + : HdSchema(container) {} + + /// Retrieves a container data source with the schema's default name token + /// "task" from the parent container and constructs a + /// HdLegacyTaskSchema instance. + /// Because the requested container data source may not exist, the result + /// should be checked with IsDefined() or a bool comparison before use. + HD_API + static HdLegacyTaskSchema GetFromParent( + const HdContainerDataSourceHandle &fromParentContainer); + + /// @} + +// --(BEGIN CUSTOM CODE: Schema Methods)-- +// --(END CUSTOM CODE: Schema Methods)-- + + /// \name Member accessor + /// @{ + + HD_API + HdLegacyTaskFactoryDataSourceHandle GetFactory() const; + + /// Parameters for task. Type depends on task type. E.g. + /// HdxRenderTaskParams if the factory produces HdxRenderTask instances. + HD_API + HdSampledDataSourceHandle GetParameters() const; + + HD_API + HdRprimCollectionDataSourceHandle GetCollection() const; + + HD_API + HdTokenVectorDataSourceHandle GetRenderTags() const; + + /// @} + + /// \name Schema location + /// @{ + + /// Returns a token where the container representing this schema is found in + /// a container by default. + HD_API + static const TfToken &GetSchemaToken(); + + /// Returns an HdDataSourceLocator (relative to the prim-level data source) + /// where the container representing this schema is found by default. + HD_API + static const HdDataSourceLocator &GetDefaultLocator(); + + /// @} + + /// \name Data source locators for members + /// + /// The following methods return an HdDataSourceLocator (relative to the + /// prim-level data source) where the data source for a member can be found. + /// + /// This is often useful for checking intersection against the + /// HdDataSourceLocatorSet sent with HdDataSourceObserver::PrimsDirtied. + /// @{ + + /// Prim-level relative data source locator to locate factory. + HD_API + static const HdDataSourceLocator &GetFactoryLocator(); + + /// Prim-level relative data source locator to locate parameters. + HD_API + static const HdDataSourceLocator &GetParametersLocator(); + + /// Prim-level relative data source locator to locate collection. + HD_API + static const HdDataSourceLocator &GetCollectionLocator(); + + /// Prim-level relative data source locator to locate renderTags. + HD_API + static const HdDataSourceLocator &GetRenderTagsLocator(); + /// @} + + /// \name Schema construction + /// @{ + + /// \deprecated Use Builder instead. + /// + /// Builds a container data source which includes the provided child data + /// sources. Parameters with nullptr values are excluded. This is a + /// low-level interface. For cases in which it's desired to define + /// the container with a sparse set of child fields, the Builder class + /// is often more convenient and readable. + HD_API + static HdContainerDataSourceHandle + BuildRetained( + const HdLegacyTaskFactoryDataSourceHandle &factory, + const HdSampledDataSourceHandle ¶meters, + const HdRprimCollectionDataSourceHandle &collection, + const HdTokenVectorDataSourceHandle &renderTags + ); + + /// \class HdLegacyTaskSchema::Builder + /// + /// Utility class for setting sparse sets of child data source fields to be + /// filled as arguments into BuildRetained. Because all setter methods + /// return a reference to the instance, this can be used in the "builder + /// pattern" form. + class Builder + { + public: + HD_API + Builder &SetFactory( + const HdLegacyTaskFactoryDataSourceHandle &factory); + HD_API + Builder &SetParameters( + const HdSampledDataSourceHandle ¶meters); + HD_API + Builder &SetCollection( + const HdRprimCollectionDataSourceHandle &collection); + HD_API + Builder &SetRenderTags( + const HdTokenVectorDataSourceHandle &renderTags); + + /// Returns a container data source containing the members set thus far. + HD_API + HdContainerDataSourceHandle Build(); + + private: + HdLegacyTaskFactoryDataSourceHandle _factory; + HdSampledDataSourceHandle _parameters; + HdRprimCollectionDataSourceHandle _collection; + HdTokenVectorDataSourceHandle _renderTags; + + }; + + /// @} +}; + +PXR_NAMESPACE_CLOSE_SCOPE + +#endif \ No newline at end of file diff --git a/pxr/imaging/hd/pch.h b/pxr/imaging/hd/pch.h index 3736acbf238..7d86a2b6b3c 100644 --- a/pxr/imaging/hd/pch.h +++ b/pxr/imaging/hd/pch.h @@ -75,6 +75,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #if defined(__APPLE__) // Fix breakage caused by Python's pyport.h. diff --git a/pxr/imaging/hd/renderBufferSchema.cpp b/pxr/imaging/hd/renderBufferSchema.cpp index 6b8e3e7e3dd..ab65a3c3f6a 100644 --- a/pxr/imaging/hd/renderBufferSchema.cpp +++ b/pxr/imaging/hd/renderBufferSchema.cpp @@ -142,6 +142,36 @@ HdRenderBufferSchema::GetDefaultLocator() { static const HdDataSourceLocator locator(GetSchemaToken()); return locator; +} + +/* static */ +const HdDataSourceLocator & +HdRenderBufferSchema::GetDimensionsLocator() +{ + static const HdDataSourceLocator locator = + GetDefaultLocator().Append( + HdRenderBufferSchemaTokens->dimensions); + return locator; +} + +/* static */ +const HdDataSourceLocator & +HdRenderBufferSchema::GetFormatLocator() +{ + static const HdDataSourceLocator locator = + GetDefaultLocator().Append( + HdRenderBufferSchemaTokens->format); + return locator; +} + +/* static */ +const HdDataSourceLocator & +HdRenderBufferSchema::GetMultiSampledLocator() +{ + static const HdDataSourceLocator locator = + GetDefaultLocator().Append( + HdRenderBufferSchemaTokens->multiSampled); + return locator; } PXR_NAMESPACE_CLOSE_SCOPE \ No newline at end of file diff --git a/pxr/imaging/hd/renderBufferSchema.h b/pxr/imaging/hd/renderBufferSchema.h index c3558432236..2a8a5a43d54 100644 --- a/pxr/imaging/hd/renderBufferSchema.h +++ b/pxr/imaging/hd/renderBufferSchema.h @@ -94,6 +94,28 @@ class HdRenderBufferSchema : public HdSchema HD_API static const HdDataSourceLocator &GetDefaultLocator(); + /// @} + + /// \name Data source locators for members + /// + /// The following methods return an HdDataSourceLocator (relative to the + /// prim-level data source) where the data source for a member can be found. + /// + /// This is often useful for checking intersection against the + /// HdDataSourceLocatorSet sent with HdDataSourceObserver::PrimsDirtied. + /// @{ + + /// Prim-level relative data source locator to locate dimensions. + HD_API + static const HdDataSourceLocator &GetDimensionsLocator(); + + /// Prim-level relative data source locator to locate format. + HD_API + static const HdDataSourceLocator &GetFormatLocator(); + + /// Prim-level relative data source locator to locate multiSampled. + HD_API + static const HdDataSourceLocator &GetMultiSampledLocator(); /// @} /// \name Schema construction diff --git a/pxr/imaging/hd/renderIndex.cpp b/pxr/imaging/hd/renderIndex.cpp index 503a8fc27ea..dea05765bca 100644 --- a/pxr/imaging/hd/renderIndex.cpp +++ b/pxr/imaging/hd/renderIndex.cpp @@ -348,6 +348,7 @@ HdRenderIndex::_RemoveSubtree( _sprimIndex.RemoveSubtree(root, sceneDelegate, _tracker, _renderDelegate); _bprimIndex.RemoveSubtree(root, sceneDelegate, _tracker, _renderDelegate); _RemoveInstancerSubtree(root, sceneDelegate); + _RemoveTaskSubtree(root, sceneDelegate); } @@ -587,6 +588,7 @@ HdRenderIndex::_Clear() // Clear instancers. _RemoveInstancerSubtree(SdfPath::AbsoluteRootPath(), nullptr); + _RemoveTaskSubtree(SdfPath::AbsoluteRootPath(), nullptr); _instancerMap.clear(); } @@ -606,9 +608,20 @@ HdRenderIndex::_TrackDelegateTask(HdSceneDelegate* delegate, return; } - HdTaskSharedPtr task = taskCreateFnc(delegate, taskId); - _tracker.TaskInserted(taskId, task->GetInitialDirtyBitsMask()); - _taskMap.emplace(taskId, _TaskInfo{delegate, task}); + HdTaskSharedPtr const task = taskCreateFnc(delegate, taskId); + _InsertTask(delegate, taskId, task); +} + +void +HdRenderIndex::_InsertTask(HdSceneDelegate* delegate, + SdfPath const &id, + HdTaskSharedPtr const &task) +{ + HD_TRACE_FUNCTION(); + HF_MALLOC_TAG_FUNCTION(); + + _tracker.TaskInserted(id, task->GetInitialDirtyBitsMask()); + _taskMap.emplace(id, _TaskInfo{delegate, task}); } HdTaskSharedPtr const& @@ -650,7 +663,7 @@ HdRenderIndex::_RemoveTaskSubtree(const SdfPath &root, const SdfPath &id = it->first; const _TaskInfo &taskInfo = it->second; - if ((taskInfo.sceneDelegate == sceneDelegate) && + if ((sceneDelegate == nullptr || taskInfo.sceneDelegate == sceneDelegate ) && (id.HasPrefix(root))) { _tracker.TaskRemoved(id); diff --git a/pxr/imaging/hd/renderIndex.h b/pxr/imaging/hd/renderIndex.h index a718c772691..97b85d82b18 100644 --- a/pxr/imaging/hd/renderIndex.h +++ b/pxr/imaging/hd/renderIndex.h @@ -485,6 +485,9 @@ class HdRenderIndex final SdfPath const& bprimId); void _InsertInstancer(HdSceneDelegate* delegate, SdfPath const &id); + void _InsertTask(HdSceneDelegate* delegate, + SdfPath const &id, + HdTaskSharedPtr const &task); void _RemoveRprim(SdfPath const& id); void _RemoveSprim(TfToken const& typeId, SdfPath const& id); diff --git a/pxr/imaging/hd/sceneIndexAdapterSceneDelegate.cpp b/pxr/imaging/hd/sceneIndexAdapterSceneDelegate.cpp index 8919d6a4216..ec00c7a70a0 100644 --- a/pxr/imaging/hd/sceneIndexAdapterSceneDelegate.cpp +++ b/pxr/imaging/hd/sceneIndexAdapterSceneDelegate.cpp @@ -19,6 +19,8 @@ #include "pxr/imaging/hd/extComputationCpuCallback.h" #include "pxr/imaging/hd/field.h" #include "pxr/imaging/hd/geomSubset.h" +#include "pxr/imaging/hd/legacyTaskFactory.h" +#include "pxr/imaging/hd/legacyTaskSchema.h" #include "pxr/imaging/hd/light.h" #include "pxr/imaging/hd/material.h" #include "pxr/imaging/hd/meshTopology.h" @@ -194,6 +196,40 @@ HdSceneIndexAdapterSceneDelegate::_GetInputPrim(SdfPath const& id) // ---------------------------------------------------------------------------- // HdSceneIndexObserver interfaces +static +HdTaskSharedPtr _CreateTask(const HdSceneIndexPrim &prim, + HdSceneDelegate * const delegate, + const SdfPath &indexPath) +{ + const HdLegacyTaskSchema taskSchema = + HdLegacyTaskSchema::GetFromParent(prim.dataSource); + HdLegacyTaskFactoryDataSourceHandle const ds = + taskSchema.GetFactory(); + if (!ds) { + TF_CODING_ERROR( + "When adding task %s in HdSceneIndexAdapterSceneDelegate: " + "No factory data source in HdLegacyTaskSchema.", + indexPath.GetText()); + return nullptr; + } + HdLegacyTaskFactorySharedPtr const factory = ds->GetTypedValue(0.0f); + if (!factory) { + TF_CODING_ERROR( + "When adding task %s in HdSceneIndexAdapterSceneDelegate: " + "No factory in HdLegacyTaskSchema.", + indexPath.GetText()); + return nullptr; + } + HdTaskSharedPtr const task = factory->Create(delegate, indexPath); + if (!task) { + TF_CODING_ERROR( + "When adding task %s in HdSceneIndexAdapterSceneDelegate: " + "No task from factory in HdLegacyTaskSchema.", + indexPath.GetText()); + } + return task; +} + void HdSceneIndexAdapterSceneDelegate::_PrimAdded( const SdfPath &primPath, @@ -208,12 +244,13 @@ HdSceneIndexAdapterSceneDelegate::_PrimAdded( // and re-insert with the correct type. // (3) The prim exists, and has the right type; in this case, we don't // remove the prim but we should invalidate all of its properties. + // Note that we make an exception for tasks - which we handle like (2). bool isResync = false; if (it != _primCache.end()) { _PrimCacheEntry &entry = (*it).second; const TfToken &existingType = entry.primType; - if (primType != existingType) { + if (primType != existingType || primType == HdPrimTypeTokens->task) { if (GetRenderIndex().IsRprimTypeSupported(existingType)) { GetRenderIndex()._RemoveRprim(indexPath); } else if (GetRenderIndex().IsSprimTypeSupported(existingType)) { @@ -243,9 +280,14 @@ HdSceneIndexAdapterSceneDelegate::_PrimAdded( } else if (primType == HdPrimTypeTokens->geomSubset) { GetRenderIndex().GetChangeTracker()._MarkRprimDirty( indexPath.GetParentPath(), HdChangeTracker::DirtyTopology); + } else if (primType == HdPrimTypeTokens->task) { + if (HdTaskSharedPtr const task = + _CreateTask(_GetInputPrim(indexPath), this, indexPath)) { + GetRenderIndex()._InsertTask(this, indexPath, task); + } } } - + if (it != _primCache.end()) { _PrimCacheEntry & entry = (*it).second; @@ -362,6 +404,8 @@ HdSceneIndexAdapterSceneDelegate::PrimsRemoved( GetRenderIndex().GetChangeTracker()._MarkRprimDirty( entry.primPath.GetParentPath(), HdChangeTracker::DirtyTopology); + } else if (primType == HdPrimTypeTokens->task) { + GetRenderIndex().RemoveTask(entry.primPath); } } else { // Otherwise, there's a subtree and we need to call _RemoveSubtree. @@ -439,6 +483,14 @@ HdSceneIndexAdapterSceneDelegate::PrimsDirtied( } else if (primType == HdPrimTypeTokens->geomSubset) { GetRenderIndex().GetChangeTracker()._MarkRprimDirty( indexPath.GetParentPath(), HdChangeTracker::DirtyTopology); + } else if (primType == HdPrimTypeTokens->task) { + const HdDirtyBits dirtyBits = + HdDirtyBitsTranslator::TaskLocatorSetToDirtyBits( + entry.dirtyLocators); + if (dirtyBits != HdChangeTracker::Clean) { + GetRenderIndex().GetChangeTracker().MarkTaskDirty( + indexPath, dirtyBits); + } } if (entry.dirtyLocators.Intersects( @@ -477,11 +529,13 @@ _IsVisible(const HdContainerDataSourceHandle& primSource) } static SdfPath -_GetBoundMaterialPath(const HdContainerDataSourceHandle& ds) +_GetBoundMaterialPath( + const HdContainerDataSourceHandle& ds, + const TfToken& purpose) { if (const auto bindingsSchema = HdMaterialBindingsSchema::GetFromParent(ds)) { if (const HdMaterialBindingSchema bindingSchema = - bindingsSchema.GetMaterialBinding()) { + bindingsSchema.GetMaterialBinding(purpose)) { if (const HdPathDataSourceHandle ds = bindingSchema.GetPath()) { return ds->GetTypedValue(0.0f); } @@ -514,6 +568,7 @@ static void _GatherGeomSubsets( const SdfPath& parentPath, const HdSceneIndexBaseRefPtr& sceneIndex, + const TfToken& materialBindingPurpose, HdTopology* topology) { TF_VERIFY(topology); @@ -563,19 +618,20 @@ _GatherGeomSubsets( } continue; } - const SdfPath materialId = _GetBoundMaterialPath(child.dataSource); + const SdfPath materialId = _GetBoundMaterialPath( + child.dataSource, materialBindingPurpose); if (materialId.IsEmpty()) { continue; } subsets.push_back({ - + // XXX: Hard-coded face type since it is the only one supported. HdGeomSubset::Type::TypeFaceSet, childPath, materialId, indices }); } - + if (auto* topo = dynamic_cast(topology)) { topo->SetGeomSubsets(subsets); } @@ -597,10 +653,10 @@ HdSceneIndexAdapterSceneDelegate::GetMeshTopology(SdfPath const &id) return HdMeshTopology(); } - HdIntArrayDataSourceHandle faceVertexCountsDataSource = + HdIntArrayDataSourceHandle faceVertexCountsDataSource = meshTopologySchema.GetFaceVertexCounts(); - HdIntArrayDataSourceHandle faceVertexIndicesDataSource = + HdIntArrayDataSourceHandle faceVertexIndicesDataSource = meshTopologySchema.GetFaceVertexIndices(); if (!faceVertexCountsDataSource || !faceVertexIndicesDataSource) { @@ -608,7 +664,7 @@ HdSceneIndexAdapterSceneDelegate::GetMeshTopology(SdfPath const &id) } TfToken scheme = PxOsdOpenSubdivTokens->none; - if (HdTokenDataSourceHandle schemeDs = + if (HdTokenDataSourceHandle schemeDs = meshSchema.GetSubdivisionScheme()) { scheme = schemeDs->GetTypedValue(0.0f); } @@ -631,8 +687,10 @@ HdSceneIndexAdapterSceneDelegate::GetMeshTopology(SdfPath const &id) faceVertexCountsDataSource->GetTypedValue(0.0f), faceVertexIndicesDataSource->GetTypedValue(0.0f), holeIndices); - - _GatherGeomSubsets(id, _inputSceneIndex, &meshTopology); + + const TfToken purpose = + GetRenderIndex().GetRenderDelegate()->GetMaterialBindingPurpose(); + _GatherGeomSubsets(id, _inputSceneIndex, purpose, &meshTopology); return meshTopology; } @@ -644,7 +702,7 @@ HdSceneIndexAdapterSceneDelegate::GetDoubleSided(SdfPath const &id) HF_MALLOC_TAG_FUNCTION(); HdSceneIndexPrim prim = _GetInputPrim(id); - HdMeshSchema meshSchema = + HdMeshSchema meshSchema = HdMeshSchema::GetFromParent(prim.dataSource); if (meshSchema.IsDefined()) { HdBoolDataSourceHandle doubleSidedDs = meshSchema.GetDoubleSided(); @@ -654,7 +712,7 @@ HdSceneIndexAdapterSceneDelegate::GetDoubleSided(SdfPath const &id) } else if (prim.primType == HdPrimTypeTokens->basisCurves) { // TODO: We assume all basis curves are double-sided in Hydra. This is // inconsistent with the USD schema, which allows sidedness to be - // declared on the USD gprim. Note however that sidedness only + // declared on the USD gprim. Note however that sidedness only // affects basis curves with authored normals (i.e., ribbons). return true; } @@ -787,7 +845,7 @@ HdSceneIndexAdapterSceneDelegate::GetSubdivTags(SdfPath const &id) return tags; } -HdBasisCurvesTopology +HdBasisCurvesTopology HdSceneIndexAdapterSceneDelegate::GetBasisCurvesTopology(SdfPath const &id) { TRACE_FUNCTION(); @@ -804,7 +862,7 @@ HdSceneIndexAdapterSceneDelegate::GetBasisCurvesTopology(SdfPath const &id) return HdBasisCurvesTopology(); } - HdIntArrayDataSourceHandle curveVertexCountsDataSource = + HdIntArrayDataSourceHandle curveVertexCountsDataSource = bcTopologySchema.GetCurveVertexCounts(); if (!curveVertexCountsDataSource) { @@ -841,7 +899,9 @@ HdSceneIndexAdapterSceneDelegate::GetBasisCurvesTopology(SdfPath const &id) curveVertexCountsDataSource->GetTypedValue(0.0f), curveIndices); - _GatherGeomSubsets(id, _inputSceneIndex, &result); + const TfToken purpose = + GetRenderIndex().GetRenderDelegate()->GetMaterialBindingPurpose(); + _GatherGeomSubsets(id, _inputSceneIndex, purpose, &result); return result; } @@ -855,7 +915,7 @@ HdSceneIndexAdapterSceneDelegate::GetCategories(SdfPath const &id) static const VtArray emptyResult; - HdCategoriesSchema categoriesSchema = + HdCategoriesSchema categoriesSchema = HdCategoriesSchema::GetFromParent( prim.dataSource); @@ -906,7 +966,7 @@ HdSceneIndexAdapterSceneDelegate::GetVolumeFieldDescriptors( return result; } -SdfPath +SdfPath HdSceneIndexAdapterSceneDelegate::GetMaterialId(SdfPath const & id) { TRACE_FUNCTION(); @@ -916,8 +976,10 @@ HdSceneIndexAdapterSceneDelegate::GetMaterialId(SdfPath const & id) HdMaterialBindingsSchema materialBindings = HdMaterialBindingsSchema::GetFromParent( prim.dataSource); + const TfToken purpose = + GetRenderIndex().GetRenderDelegate()->GetMaterialBindingPurpose(); HdMaterialBindingSchema materialBinding = - materialBindings.GetMaterialBinding(); + materialBindings.GetMaterialBinding(purpose); if (HdPathDataSourceHandle const ds = materialBinding.GetPath()) { return ds->GetTypedValue(0.0f); } @@ -1017,9 +1079,9 @@ _GetHdParamsFromDataSource( } static -void +void _Walk( - const SdfPath & nodePath, + const SdfPath & nodePath, HdMaterialNodeContainerSchema nodesSchema, const TfTokenVector &renderContexts, std::unordered_set * visitedSet, @@ -1049,7 +1111,7 @@ _Walk( if (HdContainerDataSourceHandle idsDs = nodeSchema.GetRenderContextNodeIdentifiers()) { for (const TfToken &name : renderContexts) { - + if (name.IsEmpty() && !nodeId.IsEmpty()) { // The universal renderContext was requested, so // use the universal nodeId if we found one above. @@ -1078,24 +1140,24 @@ _Walk( if (!vectorSchema) { continue; } - + for (size_t i = 0 ; i < vectorSchema.GetNumElements() ; i++) { HdMaterialConnectionSchema connSchema = vectorSchema.GetElement(i); if (!connSchema.IsDefined()) { continue; } - + TfToken p = connSchema.GetUpstreamNodePath()->GetTypedValue(0); - TfToken n = + TfToken n = connSchema.GetUpstreamNodeOutputName()->GetTypedValue(0); _Walk(SdfPath(p.GetString()), nodesSchema, renderContexts, visitedSet, netHd); HdMaterialRelationship r; - r.inputId = SdfPath(p.GetString()); - r.inputName = n; - r.outputId = nodePath; + r.inputId = SdfPath(p.GetString()); + r.inputName = n; + r.outputId = nodePath; r.outputName=connName; netHd->relationships.push_back(r); } @@ -1119,9 +1181,9 @@ _ToMaterialNetworkMap( // to be included regardless of whether they are reachable via // a terminal. While 100% accuracy in emulation would require that // behavior to be enabled by default, it is generally not desireable - // as it leads to a lot of unnecessary data duplication across + // as it leads to a lot of unnecessary data duplication across // terminals. - // + // // A renderer which wants this behavior can configure its networks // with an "includeDisconnectedNodes" data source. bool includeDisconnectedNodes = false; @@ -1144,10 +1206,10 @@ _ToMaterialNetworkMap( HdMaterialConnectionContainerSchema terminalsSchema = netSchema.GetTerminals(); const TfTokenVector names = terminalsSchema.GetNames(); - + for (const auto & name : names) { visitedNodes.clear(); - + // Extract connections one by one HdMaterialConnectionSchema connSchema = terminalsSchema.Get(name); if (!connSchema.IsDefined()) { @@ -1175,7 +1237,7 @@ _ToMaterialNetworkMap( return matHd; } -VtValue +VtValue HdSceneIndexAdapterSceneDelegate::GetMaterialResource(SdfPath const & id) { TRACE_FUNCTION(); @@ -1230,7 +1292,7 @@ _ParamNameToLocator(TfToken const ¶mName) const TfTokenVector parts = _ToTokenVector( TfStringTokenize(paramName.GetString(), ":")); - + return HdDataSourceLocator(parts.size(), parts.data()); } @@ -1506,13 +1568,13 @@ _GetRenderSettings(HdSceneIndexPrim prim, TfToken const &key) if (key == HdRenderSettingsPrimTokens->namespacedSettings) { VtDictionary settings; - if (HdContainerDataSourceHandle namespacedSettingsDs = + if (HdContainerDataSourceHandle namespacedSettingsDs = rsSchema.GetNamespacedSettings()) { return VtValue(_ToDictionary(namespacedSettingsDs)); } } - + if (key == HdRenderSettingsPrimTokens->active) { if (HdBoolDataSourceHandle activeDS = rsSchema.GetActive()) { return VtValue(activeDS->GetTypedValue(0)); @@ -1522,7 +1584,7 @@ _GetRenderSettings(HdSceneIndexPrim prim, TfToken const &key) if (key == HdRenderSettingsPrimTokens->renderProducts) { if (HdRenderProductVectorSchema products = rsSchema.GetRenderProducts()) { - + return VtValue(_ToRenderProducts(products)); } } @@ -1530,7 +1592,7 @@ _GetRenderSettings(HdSceneIndexPrim prim, TfToken const &key) if (key == HdRenderSettingsPrimTokens->includedPurposes) { if (HdTokenArrayDataSourceHandle purposesDS = rsSchema.GetIncludedPurposes()) { - + return VtValue(purposesDS->GetTypedValue(0)); } } @@ -1538,7 +1600,7 @@ _GetRenderSettings(HdSceneIndexPrim prim, TfToken const &key) if (key == HdRenderSettingsPrimTokens->materialBindingPurposes) { if (HdTokenArrayDataSourceHandle purposesDS = rsSchema.GetMaterialBindingPurposes()) { - + return VtValue(purposesDS->GetTypedValue(0)); } } @@ -1546,7 +1608,7 @@ _GetRenderSettings(HdSceneIndexPrim prim, TfToken const &key) if (key == HdRenderSettingsPrimTokens->renderingColorSpace) { if (HdTokenDataSourceHandle colorSpaceDS = rsSchema.GetRenderingColorSpace()) { - + return VtValue(colorSpaceDS->GetTypedValue(0)); } } @@ -1554,7 +1616,7 @@ _GetRenderSettings(HdSceneIndexPrim prim, TfToken const &key) if (key == HdRenderSettingsPrimTokens->shutterInterval) { if (HdVec2dDataSourceHandle shutterIntervalDS = rsSchema.GetShutterInterval()) { - + return VtValue(shutterIntervalDS->GetTypedValue(0)); } } @@ -1853,7 +1915,7 @@ HdSceneIndexAdapterSceneDelegate::_ComputeExtCmpPrimvarDescriptors( std::move(descriptors)); } -VtValue +VtValue HdSceneIndexAdapterSceneDelegate::Get(SdfPath const &id, TfToken const &key) { TRACE_FUNCTION(); @@ -1881,7 +1943,7 @@ HdSceneIndexAdapterSceneDelegate::Get(SdfPath const &id, TfToken const &key) if (HdSampledDataSourceHandle valueDs = HdSampledDataSource::Cast(drawTarget->Get(key))) { return valueDs->GetValue(0.0f); - } + } } return VtValue(); @@ -2033,6 +2095,26 @@ HdSceneIndexAdapterSceneDelegate::Get(SdfPath const &id, TfToken const &key) } } + // For tasks. + if (const HdLegacyTaskSchema task = + HdLegacyTaskSchema::GetFromParent(prim.dataSource)) { + if (key == HdTokens->params) { + if (HdSampledDataSourceHandle const ds = task.GetParameters()) { + return ds->GetValue(0.0f); + } + } + if (key == HdTokens->collection) { + if (HdRprimCollectionDataSourceHandle const ds = task.GetCollection()) { + return ds->GetValue(0.0f); + } + } + if (key == HdTokens->renderTags) { + if (HdTokenVectorDataSourceHandle const ds = task.GetRenderTags()) { + return ds->GetValue(0.0f); + } + } + } + // Fallback for unknown prim conventions provided by emulated scene // delegate. if (HdTypedSampledDataSource::Handle sdDs = @@ -2047,15 +2129,15 @@ HdSceneIndexAdapterSceneDelegate::Get(SdfPath const &id, TfToken const &key) return VtValue(); } -VtValue -HdSceneIndexAdapterSceneDelegate::GetIndexedPrimvar(SdfPath const &id, +VtValue +HdSceneIndexAdapterSceneDelegate::GetIndexedPrimvar(SdfPath const &id, TfToken const &key, VtIntArray *outIndices) { return _GetPrimvar(id, key, outIndices); } -VtValue -HdSceneIndexAdapterSceneDelegate::_GetPrimvar(SdfPath const &id, +VtValue +HdSceneIndexAdapterSceneDelegate::_GetPrimvar(SdfPath const &id, TfToken const &key, VtIntArray *outIndices) { TRACE_FUNCTION(); @@ -2084,11 +2166,11 @@ HdSceneIndexAdapterSceneDelegate::_GetPrimvar( HdPrimvarsSchema primvars(primvarsDataSource); if (primvars) { if (HdPrimvarSchema primvar = primvars.GetPrimvar(key)) { - + if (outIndices) { if (HdSampledDataSourceHandle valueDataSource = primvar.GetIndexedPrimvarValue()) { - if (HdIntArrayDataSourceHandle + if (HdIntArrayDataSourceHandle indicesDataSource = primvar.GetIndices()) { *outIndices = indicesDataSource->GetTypedValue(0.f); } @@ -2109,7 +2191,7 @@ HdSceneIndexAdapterSceneDelegate::_GetPrimvar( size_t HdSceneIndexAdapterSceneDelegate::SamplePrimvar( SdfPath const &id, TfToken const &key, - size_t maxSampleCount, float *sampleTimes, + size_t maxSampleCount, float *sampleTimes, VtValue *sampleValues) { return _SamplePrimvar( @@ -2122,7 +2204,7 @@ size_t HdSceneIndexAdapterSceneDelegate::SamplePrimvar( SdfPath const &id, TfToken const &key, float startTime, float endTime, - size_t maxSampleCount, float *sampleTimes, + size_t maxSampleCount, float *sampleTimes, VtValue *sampleValues) { return _SamplePrimvar( @@ -2134,7 +2216,7 @@ HdSceneIndexAdapterSceneDelegate::SamplePrimvar( size_t HdSceneIndexAdapterSceneDelegate::SampleIndexedPrimvar( SdfPath const &id, TfToken const &key, - size_t maxSampleCount, float *sampleTimes, + size_t maxSampleCount, float *sampleTimes, VtValue *sampleValues, VtIntArray *sampleIndices) { return _SamplePrimvar( @@ -2147,7 +2229,7 @@ size_t HdSceneIndexAdapterSceneDelegate::SampleIndexedPrimvar( SdfPath const &id, TfToken const &key, float startTime, float endTime, - size_t maxSampleCount, float *sampleTimes, + size_t maxSampleCount, float *sampleTimes, VtValue *sampleValues, VtIntArray *sampleIndices) { return _SamplePrimvar( @@ -2160,7 +2242,7 @@ size_t HdSceneIndexAdapterSceneDelegate::_SamplePrimvar( SdfPath const &id, TfToken const &key, float startTime, float endTime, - size_t maxSampleCount, float *sampleTimes, + size_t maxSampleCount, float *sampleTimes, VtValue *sampleValues, VtIntArray *sampleIndices) { TRACE_FUNCTION(); @@ -2170,7 +2252,7 @@ HdSceneIndexAdapterSceneDelegate::_SamplePrimvar( HdSampledDataSourceHandle valueSource = nullptr; HdIntArrayDataSourceHandle indicesSource = nullptr; - + HdPrimvarsSchema primvars = HdPrimvarsSchema::GetFromParent(prim.dataSource); if (primvars) { @@ -2252,14 +2334,14 @@ HdSceneIndexAdapterSceneDelegate::_SamplePrimvar( sampleValues[i] = valueSource->GetValue(times[i]); if (sampleIndices) { if (indicesSource) { - // Can assume indices source has same sample times as primvar + // Can assume indices source has same sample times as primvar // value source. sampleIndices[i] = indicesSource->GetTypedValue(times[i]); } else { sampleIndices[i].clear(); } } - + } return authoredSamples; @@ -2722,6 +2804,20 @@ HdSceneIndexAdapterSceneDelegate::InvokeExtComputation( callback->Compute(context); } +TfTokenVector +HdSceneIndexAdapterSceneDelegate::GetTaskRenderTags(SdfPath const &taskId) +{ + TRACE_FUNCTION(); + HF_MALLOC_TAG_FUNCTION(); + const HdSceneIndexPrim prim = _GetInputPrim(taskId); + const HdLegacyTaskSchema task = HdLegacyTaskSchema::GetFromParent(prim.dataSource); + HdTokenVectorDataSourceHandle const ds = task.GetRenderTags(); + if (!ds) { + return {}; + } + return ds->GetTypedValue(0.0f); +} + void HdSceneIndexAdapterSceneDelegate::Sync(HdSyncRequestVector* request) { @@ -2744,7 +2840,7 @@ HdSceneIndexAdapterSceneDelegate::Sync(HdSyncRequestVector* request) return; } - HdTypedSampledDataSource::Handle ds = + HdTypedSampledDataSource::Handle ds = HdTypedSampledDataSource::Cast( prim.dataSource->Get( HdSceneIndexEmulationTokens->sceneDelegate)); @@ -2761,7 +2857,7 @@ HdSceneIndexAdapterSceneDelegate::Sync(HdSyncRequestVector* request) for (auto sd : _sceneDelegates) { if (TF_VERIFY(sd != nullptr)) { sd->Sync(request); - } + } } } diff --git a/pxr/imaging/hd/sceneIndexAdapterSceneDelegate.h b/pxr/imaging/hd/sceneIndexAdapterSceneDelegate.h index ab112c11c3b..7f497927a37 100644 --- a/pxr/imaging/hd/sceneIndexAdapterSceneDelegate.h +++ b/pxr/imaging/hd/sceneIndexAdapterSceneDelegate.h @@ -199,11 +199,12 @@ class HdSceneIndexAdapterSceneDelegate void InvokeExtComputation(SdfPath const &computationId, HdExtComputationContext *context) override; + TfTokenVector GetTaskRenderTags(SdfPath const &taskId) override; + void Sync(HdSyncRequestVector* request) override; void PostSyncCleanup() override; // NOTE: The remaining scene delegate functions aren't used for emulation: - // - GetTaskRenderTags // - GetScenePrimPath // - IsEnabled diff --git a/pxr/imaging/hd/tokens.h b/pxr/imaging/hd/tokens.h index 06eb28fdec6..26438478b2f 100644 --- a/pxr/imaging/hd/tokens.h +++ b/pxr/imaging/hd/tokens.h @@ -327,7 +327,8 @@ PXR_NAMESPACE_OPEN_SCOPE HD_SPRIMTYPE_TOKENS \ HD_BPRIMTYPE_TOKENS \ /* Scene-index-only prim types */ \ - (renderPass) + (renderPass) \ + (task) HD_API bool HdPrimTypeIsGprim(TfToken const& primType); diff --git a/pxr/imaging/hdGp/pch.h b/pxr/imaging/hdGp/pch.h index d09b5085207..042a1c5a5a2 100644 --- a/pxr/imaging/hdGp/pch.h +++ b/pxr/imaging/hdGp/pch.h @@ -65,6 +65,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #if defined(__APPLE__) // Fix breakage caused by Python's pyport.h. diff --git a/pxr/imaging/hdMtlx/pch.h b/pxr/imaging/hdMtlx/pch.h index 93019ca153b..ce52394a658 100644 --- a/pxr/imaging/hdMtlx/pch.h +++ b/pxr/imaging/hdMtlx/pch.h @@ -88,6 +88,7 @@ #include #endif // PXR_MATERIALX_SUPPORT_ENABLED #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/pxr/imaging/hdSt/CMakeLists.txt b/pxr/imaging/hdSt/CMakeLists.txt index 320036d5da3..407f022a3e4 100644 --- a/pxr/imaging/hdSt/CMakeLists.txt +++ b/pxr/imaging/hdSt/CMakeLists.txt @@ -170,6 +170,7 @@ pxr_library(hdSt pipelineDrawBatch pointsShaderKey quadrangulate + renderPassShaderKey resourceBinder shaderKey subdivision @@ -2324,7 +2325,7 @@ pxr_register_test(testHdStBufferArray COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdStBufferArray" EXPECTED_RETURN_CODE 0 STDOUT_REDIRECT testHdStBufferArray-Run1-stdout.txt - POST_COMMAND "diff -I drawingShader -I computeShader -I gpuMemoryUsed -I meshTopology -I basisCurvesTopology testHdStBufferArray-Run1-stdout.txt ${CMAKE_INSTALL_PREFIX}/tests/ctest/testHdStBufferArray/baseline/testHdStBufferArray-Run1-stdout.txt" + POST_COMMAND "diff -I drawingShader -I computeShader -I gpuMemoryUsed -I meshTopology -I basisCurvesTopology -I uboSize -I ssboSize testHdStBufferArray-Run1-stdout.txt ${CMAKE_INSTALL_PREFIX}/tests/ctest/testHdStBufferArray/baseline/testHdStBufferArray-Run1-stdout.txt" TESTENV testHdStBufferArray TESTENV testHdStBufferArray ENV TF_DEBUG=HD_SAFE_MODE @@ -2335,7 +2336,7 @@ pxr_register_test(testHdStBufferArrayInstancingDisabled COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdStBufferArray" EXPECTED_RETURN_CODE 0 STDOUT_REDIRECT testHdStBufferArrayInstancingDisabled-Run1-stdout.txt - POST_COMMAND "diff -I drawingShader -I computeShader -I gpuMemoryUsed -I meshTopology -I basisCurvesTopology testHdStBufferArrayInstancingDisabled-Run1-stdout.txt ${CMAKE_INSTALL_PREFIX}/tests/ctest/testHdStBufferArrayInstancingDisabled/baseline/testHdStBufferArrayInstancingDisabled-Run1-stdout.txt" + POST_COMMAND "diff -I drawingShader -I computeShader -I gpuMemoryUsed -I meshTopology -I basisCurvesTopology -I uboSize -I ssboSize testHdStBufferArrayInstancingDisabled-Run1-stdout.txt ${CMAKE_INSTALL_PREFIX}/tests/ctest/testHdStBufferArrayInstancingDisabled/baseline/testHdStBufferArrayInstancingDisabled-Run1-stdout.txt" TESTENV testHdStBufferArrayInstancingDisabled ENV HDST_ENABLE_RESOURCE_INSTANCING=0 @@ -2374,269 +2375,106 @@ pxr_register_test(testHdStClipPlanes2 ENV TF_DEBUG=HD_SAFE_MODE ) -pxr_register_test(testHdStCodeGen_GL_Mesh_Indirect - COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdStCodeGen --mesh | grep -v '// line'" - EXPECTED_RETURN_CODE 0 - STDOUT_REDIRECT codegen_mesh_indirect.out - POST_COMMAND "diff -I '\".*\.glslfx\"' codegen_mesh_indirect.out ${CMAKE_INSTALL_PREFIX}/tests/ctest/testHdStCodeGen_GL/baseline/codegen_mesh_indirect.out" - TESTENV testHdStCodeGen_GL - ENV - TF_DEBUG=HD_SAFE_MODE - HGIGL_ENABLE_BINDLESS_BUFFER=1 - HGIGL_ENABLE_BINDLESS_TEXTURE=1 - HGIGL_GLSL_VERSION=450 - HGI_ENABLE_VULKAN=0 -) -pxr_register_test(testHdStCodeGen_GL_Mesh_Bindless_Indirect - COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdStCodeGen --mesh --bindless | grep -v '// line'" - EXPECTED_RETURN_CODE 0 - STDOUT_REDIRECT codegen_mesh_bindless_indirect.out - POST_COMMAND "diff -I '\".*\.glslfx\"' codegen_mesh_bindless_indirect.out ${CMAKE_INSTALL_PREFIX}/tests/ctest/testHdStCodeGen_GL/baseline/codegen_mesh_bindless_indirect.out" - TESTENV testHdStCodeGen_GL - ENV - TF_DEBUG=HD_SAFE_MODE - HGIGL_ENABLE_BINDLESS_BUFFER=1 - HGIGL_ENABLE_BINDLESS_TEXTURE=1 - HGIGL_GLSL_VERSION=450 - HGI_ENABLE_VULKAN=0 -) -pxr_register_test(testHdStCodeGen_GL_Mesh_Bindless_Indirect_SmoothNormals - COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdStCodeGen --mesh --bindless --smoothNormals | grep -v '// line'" - EXPECTED_RETURN_CODE 0 - STDOUT_REDIRECT codegen_mesh_bindless_indirect_smoothNormals.out - POST_COMMAND "diff -I '\".*\.glslfx\"' codegen_mesh_bindless_indirect_smoothNormals.out ${CMAKE_INSTALL_PREFIX}/tests/ctest/testHdStCodeGen_GL/baseline/codegen_mesh_bindless_indirect_smoothNormals.out" - TESTENV testHdStCodeGen_GL - ENV - TF_DEBUG=HD_SAFE_MODE - HGIGL_ENABLE_BINDLESS_BUFFER=1 - HGIGL_ENABLE_BINDLESS_TEXTURE=1 - HGIGL_GLSL_VERSION=450 - HGI_ENABLE_VULKAN=0 -) -pxr_register_test(testHdStCodeGen_GL_Mesh_Bindless_Indirect_DoubleSided - COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdStCodeGen --mesh --bindless --doubleSided | grep -v '// line'" - EXPECTED_RETURN_CODE 0 - STDOUT_REDIRECT codegen_mesh_bindless_indirect_doubleSided.out - POST_COMMAND "diff -I '\".*\.glslfx\"' codegen_mesh_bindless_indirect_doubleSided.out ${CMAKE_INSTALL_PREFIX}/tests/ctest/testHdStCodeGen_GL/baseline/codegen_mesh_bindless_indirect_doubleSided.out" - TESTENV testHdStCodeGen_GL - ENV - TF_DEBUG=HD_SAFE_MODE - HGIGL_ENABLE_BINDLESS_BUFFER=1 - HGIGL_ENABLE_BINDLESS_TEXTURE=1 - HGIGL_GLSL_VERSION=450 - HGI_ENABLE_VULKAN=0 -) -pxr_register_test(testHdStCodeGen_GL_Mesh_Bindless_Indirect_FaceVarying - COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdStCodeGen --mesh --bindless --faceVarying | grep -v '// line'" - EXPECTED_RETURN_CODE 0 - STDOUT_REDIRECT codegen_mesh_bindless_indirect_faceVarying.out - POST_COMMAND "diff -I '\".*\.glslfx\"' codegen_mesh_bindless_indirect_faceVarying.out ${CMAKE_INSTALL_PREFIX}/tests/ctest/testHdStCodeGen_GL/baseline/codegen_mesh_bindless_indirect_faceVarying.out" - TESTENV testHdStCodeGen_GL - ENV - TF_DEBUG=HD_SAFE_MODE - HGIGL_ENABLE_BINDLESS_BUFFER=1 - HGIGL_ENABLE_BINDLESS_TEXTURE=1 - HGIGL_GLSL_VERSION=450 - HGI_ENABLE_VULKAN=0 -) -pxr_register_test(testHdStCodeGen_GL_Mesh_Indirect_Instance - COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdStCodeGen --mesh --instance | grep -v '// line'" - EXPECTED_RETURN_CODE 0 - STDOUT_REDIRECT codegen_mesh_indirect_instance.out - POST_COMMAND "diff -I '\".*\.glslfx\"' codegen_mesh_indirect_instance.out ${CMAKE_INSTALL_PREFIX}/tests/ctest/testHdStCodeGen_GL/baseline/codegen_mesh_indirect_instance.out" - TESTENV testHdStCodeGen_GL - ENV - TF_DEBUG=HD_SAFE_MODE - HGIGL_ENABLE_BINDLESS_BUFFER=1 - HGIGL_ENABLE_BINDLESS_TEXTURE=1 - HGIGL_GLSL_VERSION=450 - HGI_ENABLE_VULKAN=0 -) -pxr_register_test(testHdStCodeGen_GL_Mesh_Bindless_Indirect_Instance - COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdStCodeGen --mesh --bindless --instance | grep -v '// line'" - EXPECTED_RETURN_CODE 0 - STDOUT_REDIRECT codegen_mesh_bindless_indirect_instance.out - POST_COMMAND "diff -I '\".*\.glslfx\"' codegen_mesh_bindless_indirect_instance.out ${CMAKE_INSTALL_PREFIX}/tests/ctest/testHdStCodeGen_GL/baseline/codegen_mesh_bindless_indirect_instance.out" - TESTENV testHdStCodeGen_GL - ENV - TF_DEBUG=HD_SAFE_MODE - HGIGL_ENABLE_BINDLESS_BUFFER=1 - HGIGL_ENABLE_BINDLESS_TEXTURE=1 - HGIGL_GLSL_VERSION=450 - HGI_ENABLE_VULKAN=0 -) -pxr_register_test(testHdStCodeGen_GL_Mesh_EdgeOnly - COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdStCodeGen --mesh --edgeOnly | grep -v '// line'" - EXPECTED_RETURN_CODE 0 - STDOUT_REDIRECT codegen_mesh_edgeonly.out - POST_COMMAND "diff -I '\".*\.glslfx\"' codegen_mesh_edgeonly.out ${CMAKE_INSTALL_PREFIX}/tests/ctest/testHdStCodeGen_GL/baseline/codegen_mesh_edgeonly.out" - TESTENV testHdStCodeGen_GL - ENV - TF_DEBUG=HD_SAFE_MODE - HGIGL_ENABLE_BINDLESS_BUFFER=1 - HGIGL_ENABLE_BINDLESS_TEXTURE=1 - HGIGL_GLSL_VERSION=450 - HGI_ENABLE_VULKAN=0 -) -pxr_register_test(testHdStCodeGen_GL_Mesh_EdgeOnly_BlendWireframe - COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdStCodeGen --mesh --edgeOnly --blendWireframe | grep -v '// line'" - EXPECTED_RETURN_CODE 0 - STDOUT_REDIRECT codegen_mesh_edgeonly_blendwireframe.out - POST_COMMAND "diff -I '\".*\.glslfx\"' codegen_mesh_edgeonly_blendwireframe.out ${CMAKE_INSTALL_PREFIX}/tests/ctest/testHdStCodeGen_GL/baseline/codegen_mesh_edgeonly_blendwireframe.out" - TESTENV testHdStCodeGen_GL - ENV - TF_DEBUG=HD_SAFE_MODE - HGIGL_ENABLE_BINDLESS_BUFFER=1 - HGIGL_ENABLE_BINDLESS_TEXTURE=1 - HGIGL_GLSL_VERSION=450 - HGI_ENABLE_VULKAN=0 -) -pxr_register_test(testHdStCodeGen_GL_Curves_Bindless - COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdStCodeGen --curves --bindless | grep -v '// line'" - EXPECTED_RETURN_CODE 0 - STDOUT_REDIRECT codegen_curves_bindless.out - POST_COMMAND "diff -I '\".*\.glslfx\"' codegen_curves_bindless.out ${CMAKE_INSTALL_PREFIX}/tests/ctest/testHdStCodeGen_GL/baseline/codegen_curves_bindless.out" - TESTENV testHdStCodeGen_GL - ENV - TF_DEBUG=HD_SAFE_MODE - HGIGL_ENABLE_BINDLESS_BUFFER=1 - HGIGL_ENABLE_BINDLESS_TEXTURE=1 - HGIGL_GLSL_VERSION=450 - HGI_ENABLE_VULKAN=0 -) -pxr_register_test(testHdStCodeGen_GL_Curves_Indirect - COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdStCodeGen --curves | grep -v '// line'" - EXPECTED_RETURN_CODE 0 - STDOUT_REDIRECT codegen_curves_indirect.out - POST_COMMAND "diff -I '\".*\.glslfx\"' codegen_curves_indirect.out ${CMAKE_INSTALL_PREFIX}/tests/ctest/testHdStCodeGen_GL/baseline/codegen_curves_indirect.out" - TESTENV testHdStCodeGen_GL - ENV - TF_DEBUG=HD_SAFE_MODE - HGIGL_ENABLE_BINDLESS_BUFFER=1 - HGIGL_ENABLE_BINDLESS_TEXTURE=1 - HGIGL_GLSL_VERSION=450 - HGI_ENABLE_VULKAN=0 -) -pxr_register_test(testHdStCodeGen_GL_Points_Bindless - COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdStCodeGen --points --bindless | grep -v '// line'" - EXPECTED_RETURN_CODE 0 - STDOUT_REDIRECT codegen_points_bindless.out - POST_COMMAND "diff -I '\".*\.glslfx\"' codegen_points_bindless.out ${CMAKE_INSTALL_PREFIX}/tests/ctest/testHdStCodeGen_GL/baseline/codegen_points_bindless.out" - TESTENV testHdStCodeGen_GL - ENV - TF_DEBUG=HD_SAFE_MODE - HGIGL_ENABLE_BINDLESS_BUFFER=1 - HGIGL_ENABLE_BINDLESS_TEXTURE=1 - HGIGL_GLSL_VERSION=450 - HGI_ENABLE_VULKAN=0 -) -pxr_register_test(testHdStCodeGen_GL_Points_Indirect - COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdStCodeGen --points | grep -v '// line'" - EXPECTED_RETURN_CODE 0 - STDOUT_REDIRECT codegen_points_indirect.out - POST_COMMAND "diff -I '\".*\.glslfx\"' codegen_points_indirect.out ${CMAKE_INSTALL_PREFIX}/tests/ctest/testHdStCodeGen_GL/baseline/codegen_points_indirect.out" - TESTENV testHdStCodeGen_GL - ENV - TF_DEBUG=HD_SAFE_MODE - HGIGL_ENABLE_BINDLESS_BUFFER=1 - HGIGL_ENABLE_BINDLESS_TEXTURE=1 - HGIGL_GLSL_VERSION=450 - HGI_ENABLE_VULKAN=0 -) -# Skip Vulkan codegen tests if not supported by build. -if (${PXR_ENABLE_VULKAN_SUPPORT}) -pxr_register_test(testHdStCodeGen_Vulkan_Mesh_Indirect - COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdStCodeGen --mesh | grep -v '// line'" - EXPECTED_RETURN_CODE 0 - STDOUT_REDIRECT codegen_mesh_indirect.out - POST_COMMAND "diff -I '\".*\.glslfx\"' codegen_mesh_indirect.out ${CMAKE_INSTALL_PREFIX}/tests/ctest/testHdStCodeGen_Vulkan/baseline/codegen_mesh_indirect.out" - TESTENV testHdStCodeGen_Vulkan - ENV - TF_DEBUG=HD_SAFE_MODE - HGI_ENABLE_VULKAN=1 -) -pxr_register_test(testHdStCodeGen_Vulkan_Mesh_Indirect_SmoothNormals - COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdStCodeGen --mesh --smoothNormals | grep -v '// line'" - EXPECTED_RETURN_CODE 0 - STDOUT_REDIRECT codegen_mesh_indirect_smoothNormals.out - POST_COMMAND "diff -I '\".*\.glslfx\"' codegen_mesh_indirect_smoothNormals.out ${CMAKE_INSTALL_PREFIX}/tests/ctest/testHdStCodeGen_Vulkan/baseline/codegen_mesh_indirect_smoothNormals.out" - TESTENV testHdStCodeGen_Vulkan - ENV - TF_DEBUG=HD_SAFE_MODE - HGI_ENABLE_VULKAN=1 -) -pxr_register_test(testHdStCodeGen_Vulkan_Mesh_Indirect_DoubleSided - COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdStCodeGen --mesh --doubleSided | grep -v '// line'" - EXPECTED_RETURN_CODE 0 - STDOUT_REDIRECT codegen_mesh_indirect_doubleSided.out - POST_COMMAND "diff -I '\".*\.glslfx\"' codegen_mesh_indirect_doubleSided.out ${CMAKE_INSTALL_PREFIX}/tests/ctest/testHdStCodeGen_Vulkan/baseline/codegen_mesh_indirect_doubleSided.out" - TESTENV testHdStCodeGen_Vulkan - ENV - TF_DEBUG=HD_SAFE_MODE - HGI_ENABLE_VULKAN=1 -) -pxr_register_test(testHdStCodeGen_Vulkan_Mesh_Indirect_FaceVarying - COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdStCodeGen --mesh --faceVarying | grep -v '// line'" - EXPECTED_RETURN_CODE 0 - STDOUT_REDIRECT codegen_mesh_indirect_faceVarying.out - POST_COMMAND "diff -I '\".*\.glslfx\"' codegen_mesh_indirect_faceVarying.out ${CMAKE_INSTALL_PREFIX}/tests/ctest/testHdStCodeGen_Vulkan/baseline/codegen_mesh_indirect_faceVarying.out" - TESTENV testHdStCodeGen_Vulkan - ENV - TF_DEBUG=HD_SAFE_MODE - HGI_ENABLE_VULKAN=1 -) -pxr_register_test(testHdStCodeGen_Vulkan_Mesh_Indirect_Instance - COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdStCodeGen --mesh --instance | grep -v '// line'" - EXPECTED_RETURN_CODE 0 - STDOUT_REDIRECT codegen_mesh_indirect_instance.out - POST_COMMAND "diff -I '\".*\.glslfx\"' codegen_mesh_indirect_instance.out ${CMAKE_INSTALL_PREFIX}/tests/ctest/testHdStCodeGen_Vulkan/baseline/codegen_mesh_indirect_instance.out" - TESTENV testHdStCodeGen_Vulkan - ENV - TF_DEBUG=HD_SAFE_MODE - HGI_ENABLE_VULKAN=1 -) -pxr_register_test(testHdStCodeGen_Vulkan_Mesh_EdgeOnly - COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdStCodeGen --mesh --edgeOnly | grep -v '// line'" - EXPECTED_RETURN_CODE 0 - STDOUT_REDIRECT codegen_mesh_edgeonly.out - POST_COMMAND "diff -I '\".*\.glslfx\"' codegen_mesh_edgeonly.out ${CMAKE_INSTALL_PREFIX}/tests/ctest/testHdStCodeGen_Vulkan/baseline/codegen_mesh_edgeonly.out" - TESTENV testHdStCodeGen_Vulkan - ENV - TF_DEBUG=HD_SAFE_MODE - HGI_ENABLE_VULKAN=1 -) -pxr_register_test(testHdStCodeGen_Vulkan_Mesh_EdgeOnly_BlendWireframe - COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdStCodeGen --mesh --edgeOnly --blendWireframe | grep -v '// line'" - EXPECTED_RETURN_CODE 0 - STDOUT_REDIRECT codegen_mesh_edgeonly_blendwireframe.out - POST_COMMAND "diff -I '\".*\.glslfx\"' codegen_mesh_edgeonly_blendwireframe.out ${CMAKE_INSTALL_PREFIX}/tests/ctest/testHdStCodeGen_Vulkan/baseline/codegen_mesh_edgeonly_blendwireframe.out" - TESTENV testHdStCodeGen_Vulkan - ENV - TF_DEBUG=HD_SAFE_MODE - HGI_ENABLE_VULKAN=1 -) -pxr_register_test(testHdStCodeGen_Vulkan_Curves_Indirect - COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdStCodeGen --curves | grep -v '// line'" - EXPECTED_RETURN_CODE 0 - STDOUT_REDIRECT codegen_curves_indirect.out - POST_COMMAND "diff -I '\".*\.glslfx\"' codegen_curves_indirect.out ${CMAKE_INSTALL_PREFIX}/tests/ctest/testHdStCodeGen_Vulkan/baseline/codegen_curves_indirect.out" - TESTENV testHdStCodeGen_Vulkan - ENV - TF_DEBUG=HD_SAFE_MODE - HGI_ENABLE_VULKAN=1 -) -pxr_register_test(testHdStCodeGen_Vulkan_Points_Indirect - COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdStCodeGen --points | grep -v '// line'" - EXPECTED_RETURN_CODE 0 - STDOUT_REDIRECT codegen_points_indirect.out - POST_COMMAND "diff -I '\".*\.glslfx\"' codegen_points_indirect.out ${CMAKE_INSTALL_PREFIX}/tests/ctest/testHdStCodeGen_Vulkan/baseline/codegen_points_indirect.out" - TESTENV testHdStCodeGen_Vulkan - ENV - TF_DEBUG=HD_SAFE_MODE - HGI_ENABLE_VULKAN=1 -) -endif() # PXR_ENABLE_VULKAN_SUPPORT +function(register_codegen_tests suffix hgi_env) + pxr_register_test(testHdStCodeGen${suffix}_Mesh_Indirect + COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdStCodeGen --mesh | grep -v '// line'" + EXPECTED_RETURN_CODE 0 + STDOUT_REDIRECT codegen_mesh_indirect.out + POST_COMMAND "diff -I '\".*\.glslfx\"' codegen_mesh_indirect.out ${CMAKE_INSTALL_PREFIX}/tests/ctest/testHdStCodeGen${suffix}/baseline/codegen_mesh_indirect.out" + TESTENV testHdStCodeGen${suffix} + ENV + TF_DEBUG=HD_SAFE_MODE + ${hgi_env} + ) + pxr_register_test(testHdStCodeGen${suffix}_Mesh_Indirect_SmoothNormals + COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdStCodeGen --mesh --smoothNormals | grep -v '// line'" + EXPECTED_RETURN_CODE 0 + STDOUT_REDIRECT codegen_mesh_indirect_smoothNormals.out + POST_COMMAND "diff -I '\".*\.glslfx\"' codegen_mesh_indirect_smoothNormals.out ${CMAKE_INSTALL_PREFIX}/tests/ctest/testHdStCodeGen${suffix}/baseline/codegen_mesh_indirect_smoothNormals.out" + TESTENV testHdStCodeGen${suffix} + ENV + TF_DEBUG=HD_SAFE_MODE + ${hgi_env} + ) + pxr_register_test(testHdStCodeGen${suffix}_Mesh_Indirect_DoubleSided + COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdStCodeGen --mesh --doubleSided | grep -v '// line'" + EXPECTED_RETURN_CODE 0 + STDOUT_REDIRECT codegen_mesh_indirect_doubleSided.out + POST_COMMAND "diff -I '\".*\.glslfx\"' codegen_mesh_indirect_doubleSided.out ${CMAKE_INSTALL_PREFIX}/tests/ctest/testHdStCodeGen${suffix}/baseline/codegen_mesh_indirect_doubleSided.out" + TESTENV testHdStCodeGen${suffix} + ENV + TF_DEBUG=HD_SAFE_MODE + ${hgi_env} + ) + pxr_register_test(testHdStCodeGen${suffix}_Mesh_Indirect_FaceVarying + COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdStCodeGen --mesh --faceVarying | grep -v '// line'" + EXPECTED_RETURN_CODE 0 + STDOUT_REDIRECT codegen_mesh_indirect_faceVarying.out + POST_COMMAND "diff -I '\".*\.glslfx\"' codegen_mesh_indirect_faceVarying.out ${CMAKE_INSTALL_PREFIX}/tests/ctest/testHdStCodeGen${suffix}/baseline/codegen_mesh_indirect_faceVarying.out" + TESTENV testHdStCodeGen${suffix} + ENV + TF_DEBUG=HD_SAFE_MODE + ${hgi_env} + ) + pxr_register_test(testHdStCodeGen${suffix}_Mesh_Indirect_Instance + COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdStCodeGen --mesh --instance | grep -v '// line'" + EXPECTED_RETURN_CODE 0 + STDOUT_REDIRECT codegen_mesh_indirect_instance.out + POST_COMMAND "diff -I '\".*\.glslfx\"' codegen_mesh_indirect_instance.out ${CMAKE_INSTALL_PREFIX}/tests/ctest/testHdStCodeGen${suffix}/baseline/codegen_mesh_indirect_instance.out" + TESTENV testHdStCodeGen${suffix} + ENV + TF_DEBUG=HD_SAFE_MODE + ${hgi_env} + ) + pxr_register_test(testHdStCodeGen${suffix}_Mesh_EdgeOnly + COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdStCodeGen --mesh --edgeOnly | grep -v '// line'" + EXPECTED_RETURN_CODE 0 + STDOUT_REDIRECT codegen_mesh_edgeonly.out + POST_COMMAND "diff -I '\".*\.glslfx\"' codegen_mesh_edgeonly.out ${CMAKE_INSTALL_PREFIX}/tests/ctest/testHdStCodeGen${suffix}/baseline/codegen_mesh_edgeonly.out" + TESTENV testHdStCodeGen${suffix} + ENV + TF_DEBUG=HD_SAFE_MODE + ${hgi_env} + ) + pxr_register_test(testHdStCodeGen${suffix}_Mesh_EdgeOnly_BlendWireframe + COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdStCodeGen --mesh --edgeOnly --blendWireframe | grep -v '// line'" + EXPECTED_RETURN_CODE 0 + STDOUT_REDIRECT codegen_mesh_edgeonly_blendwireframe.out + POST_COMMAND "diff -I '\".*\.glslfx\"' codegen_mesh_edgeonly_blendwireframe.out ${CMAKE_INSTALL_PREFIX}/tests/ctest/testHdStCodeGen${suffix}/baseline/codegen_mesh_edgeonly_blendwireframe.out" + TESTENV testHdStCodeGen${suffix} + ENV + TF_DEBUG=HD_SAFE_MODE + ${hgi_env} + ) + pxr_register_test(testHdStCodeGen${suffix}_Curves_Indirect + COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdStCodeGen --curves | grep -v '// line'" + EXPECTED_RETURN_CODE 0 + STDOUT_REDIRECT codegen_curves_indirect.out + POST_COMMAND "diff -I '\".*\.glslfx\"' codegen_curves_indirect.out ${CMAKE_INSTALL_PREFIX}/tests/ctest/testHdStCodeGen${suffix}/baseline/codegen_curves_indirect.out" + TESTENV testHdStCodeGen${suffix} + ENV + TF_DEBUG=HD_SAFE_MODE + ${hgi_env} + ) + pxr_register_test(testHdStCodeGen${suffix}_Points_Indirect + COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdStCodeGen --points | grep -v '// line'" + EXPECTED_RETURN_CODE 0 + STDOUT_REDIRECT codegen_points_indirect.out + POST_COMMAND "diff -I '\".*\.glslfx\"' codegen_points_indirect.out ${CMAKE_INSTALL_PREFIX}/tests/ctest/testHdStCodeGen${suffix}/baseline/codegen_points_indirect.out" + TESTENV testHdStCodeGen${suffix} + ENV + TF_DEBUG=HD_SAFE_MODE + ${hgi_env} + ) +endfunction() +# OpenGL codegen tests require X11 to create a context +if(PXR_ENABLE_GL_SUPPORT AND X11_FOUND) + register_codegen_tests(_GL "HGI_ENABLE_VULKAN=0;HGIGL_ENABLE_BINDLESS_BUFFER=1;HGIGL_ENABLE_BINDLESS_TEXTURE=1;HGIGL_GLSL_VERSION=450") +endif() +if(PXR_ENABLE_VULKAN_SUPPORT) + register_codegen_tests(_Vulkan "HGI_ENABLE_VULKAN=1;") +endif() pxr_register_test(testHdStCurveDrawing_lv0_refined COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdStCurveDrawing --offscreen --repr refined --refineLevel 0 --write testHdStCurveDrawing_lv0_refined.png" @@ -2740,6 +2578,7 @@ pxr_register_test(testHdStDrawBatching HD_ENABLE_DOUBLE_MATRIX=1 HD_ENABLE_GPU_COUNT_VISIBLE_INSTANCES=1 HD_ENABLE_PACKED_NORMALS=0 + HGI_ENABLE_VULKAN=0 ) pxr_register_test(testHdStDrawItemIntegrity COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdStDrawItemIntegrity --offscreen" @@ -2825,12 +2664,14 @@ pxr_register_test(testHdStFaceCulling_FrontUnlessDoubleSided pxr_register_test(testHdStFrustumCullingCPU COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdStFrustumCulling --offscreen" EXPECTED_RETURN_CODE 0 + TESTENV testHdStFrustumCulling ENV HD_ENABLE_GPU_FRUSTUM_CULLING=0 ) pxr_register_test(testHdStFrustumCullingGPU COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdStFrustumCulling --offscreen" EXPECTED_RETURN_CODE 0 + TESTENV testHdStFrustumCulling ENV HD_ENABLE_GPU_FRUSTUM_CULLING=1 HD_ENABLE_GPU_COUNT_VISIBLE_INSTANCES=1 @@ -2895,7 +2736,7 @@ pxr_register_test(testHdStHWFaceCulling COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdStHWFaceCulling" EXPECTED_RETURN_CODE 0 STDOUT_REDIRECT testHdStHWFaceCulling-Run1-stdout.txt - POST_COMMAND "diff -I computeShader -I drawingShader -I gpuMemoryUsed testHdStHWFaceCulling-Run1-stdout.txt ${CMAKE_INSTALL_PREFIX}/tests/ctest/testHdStHWFaceCulling/baseline/testHdStHWFaceCulling-Run1-stdout.txt" + POST_COMMAND "diff -I computeShader -I drawingShader -I gpuMemoryUsed -I uboSize -I ssboSize testHdStHWFaceCulling-Run1-stdout.txt ${CMAKE_INSTALL_PREFIX}/tests/ctest/testHdStHWFaceCulling/baseline/testHdStHWFaceCulling-Run1-stdout.txt" TESTENV testHdStHWFaceCulling ) pxr_register_test(testHdStIndirectDrawBatchCodeGen @@ -3155,7 +2996,7 @@ pxr_register_test(testHdStPrimvars COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdStPrimvars" EXPECTED_RETURN_CODE 0 STDOUT_REDIRECT testHdStPrimvars-Run1-stdout.txt - POST_COMMAND "diff -I computeShader -I drawingShader -I gpuMemoryUsed testHdStPrimvars-Run1-stdout.txt ${CMAKE_INSTALL_PREFIX}/tests/ctest/testHdStPrimvars/baseline/testHdStPrimvars-Run1-stdout.txt" + POST_COMMAND "diff -I computeShader -I drawingShader -I gpuMemoryUsed -I uboSize -I ssboSize testHdStPrimvars-Run1-stdout.txt ${CMAKE_INSTALL_PREFIX}/tests/ctest/testHdStPrimvars/baseline/testHdStPrimvars-Run1-stdout.txt" TESTENV testHdStPrimvars ENV HDST_ENABLE_MATERIAL_PRIMVAR_FILTERING=0 @@ -3521,4 +3362,4 @@ pxr_register_test(testHdStShaders ENV TF_DEBUG=HD_SAFE_MODE ) -endif() # TARGET shared_libs +endif() # TARGET shared_libs \ No newline at end of file diff --git a/pxr/imaging/hdSt/codeGen.cpp b/pxr/imaging/hdSt/codeGen.cpp index 15a40a31855..2f419365674 100644 --- a/pxr/imaging/hdSt/codeGen.cpp +++ b/pxr/imaging/hdSt/codeGen.cpp @@ -35,7 +35,7 @@ #include "pxr/base/tf/hash.h" #include -#include +#include #if defined(__APPLE__) #include @@ -129,6 +129,7 @@ TF_DEFINE_PRIVATE_TOKENS( (triangle_strip) (early_fragment_tests) (OsdPerPatchVertexBezier) + (interstageDrawingCoord) ); TF_DEFINE_ENV_SETTING(HDST_ENABLE_HGI_RESOURCE_GENERATION, false, @@ -1589,67 +1590,174 @@ HdSt_CodeGen::_GetShaderResourceLayouts( } void -HdSt_CodeGen::_PlumbInterstageElements( - TfToken const &name, - TfToken const &dataType) +HdSt_CodeGen::_PlumbInterstageElements() { - // Add resource elements to plumb interstage elements, e.g. - // drawingCoord and interpolated primvar through active stages. + // Graphics devices impose limits on the number of input/output locations + // available. We can quickly exceeed such limits on low spec devices if we + // naively use one location per drawing coord. This is because arrays take + // one location per item, regardless of the item size. This means that: + // layout(location = 0) in int someCoord[gl_MaxPatchVertices] + // consumes as many locations (gl_MaxPatchVertices) as: + // layout(location = 0) in ivec4 someCoord[gl_MaxPatchVertices] + // while holding 4x fewer values. Instead if we do: + // layout(location = 0) in ivec4 someCoord[ + // divRoundUp(gl_MaxPatchVertices, 4)] + // and pack the coord values into the vector elements, we can use 4x fewer + // locations. In practice, since we have many coord in/out fields, it's + // simpler to pack across fields instead of within a field, but the idea is + // the same. This means that: + // flat layout(location = 0) in int someCoord1[gl_MaxPatchVertices]; + // flat layout(location = 1) in int someCoord2[gl_MaxPatchVertices]; + // < 7 more fields omitted > + // flat layout(location = 9) in int someCoord10[gl_MaxPatchVertices]; + // becomes: + // flat layout(location = 0) in ivec4 someCoord1To4[gl_MaxPatchVertices]; + // flat layout(location = 1) in ivec4 someCoord5to8[gl_MaxPatchVertices]; + // flat layout(location = 2) in ivec4 someCoord8to10[gl_MaxPatchVertices]; + // where someCoord1To4[i].x is someCoord1[i], someCoord1To4[i].y is + // someCoord2[i], someCoord1To4[i].z is someCoord3[i], someCoord1To4[i].w + // is someCoord4[i]. + // + // Ref: https://docs.vulkan.org/spec/latest/chapters/interfaces.html#interfaces-iointerfaces-locations - std::string const &baseName = name.GetString(); - TfToken const vs_outName( "vs_" + baseName); - TfToken const tcs_outName("tcs_" + baseName); - TfToken const tes_outName("tes_" + baseName); - TfToken const gs_outName( "gs_" + baseName); + // This code automates such packing. It identifies fields with the same + // scalar type, and groups them into 4 element vectors. It also generates + // mapping data, so the original field can be mapped to its vector + // component. - // Empty token for variables with no array size - TfToken const noArraySize; + struct _ProcessedElement { + TfToken name; + TfToken dataType; + }; + using _ProcessedElementVector = std::vector<_ProcessedElement>; - // Interstage variables of type "int" require "flat" interpolation - TfToken const &qualifier = - (dataType == _tokens->_int) ? _tokens->flat : _tokens->_default; + struct _ElementGroup { + TfToken commonDataType; + ElementVector elements; + }; + + _ProcessedElementVector processedElements; + std::vector<_ElementGroup> packedElementGroups; + std::map elementGroupsToFill; + for (auto const& element : _resInterstage) { + TfToken const& dataType = element.dataType; + if (dataType != _tokens->_int && dataType != _tokens->_float) { + processedElements.push_back({element.name, dataType}); + continue; + } - // Vertex attrib input for VS, PTCS, PTVS - _resAttrib.emplace_back(InOut::STAGE_OUT, Kind::VALUE, dataType, - vs_outName, noArraySize, qualifier); + // Add to an existing group, or create a new one. + _ElementGroup* group; + if (const auto iter = elementGroupsToFill.find(dataType); + iter != elementGroupsToFill.end()) { + group = &iter->second; + } else { + group = &elementGroupsToFill.try_emplace( + dataType, _ElementGroup{dataType}).first->second; + } - if (_hasTCS) { - _resTCS.emplace_back(InOut::STAGE_IN, Kind::VALUE, dataType, - vs_outName, _tokens->gl_MaxPatchVertices, qualifier); - _resTCS.emplace_back(InOut::STAGE_OUT, Kind::VALUE, dataType, - tcs_outName, _tokens->HD_NUM_PATCH_EVAL_VERTS, qualifier); + // When a group is full, move it to the fully packed groups list. + TF_VERIFY(group->elements.size() < 4); + group->elements.push_back(element); + if (group->elements.size() == 4) { + packedElementGroups.push_back(std::move(*group)); + elementGroupsToFill.erase(dataType); + } } - if (_hasTES) { - _resTES.emplace_back(InOut::STAGE_IN, Kind::VALUE, dataType, - tcs_outName, _tokens->gl_MaxPatchVertices, qualifier); - _resTES.emplace_back(InOut::STAGE_OUT, Kind::VALUE, dataType, - tes_outName, noArraySize, qualifier); + // Some groups won't be full if the number of elements is not cleanly + // divisible by 4. + for (auto& [_, group] : elementGroupsToFill) { + packedElementGroups.push_back(std::move(group)); } - // Geometry shader inputs come from previous active stage - if (_hasGS && _hasTES) { - _resGS.emplace_back(InOut::STAGE_IN, Kind::VALUE, dataType, - tes_outName, _tokens->HD_NUM_PRIMITIVE_VERTS, qualifier); - _resGS.emplace_back(InOut::STAGE_OUT, Kind::VALUE, dataType, - gs_outName, noArraySize, qualifier); - } else if (_hasGS) { - _resGS.emplace_back(InOut::STAGE_IN, Kind::VALUE, dataType, - vs_outName, _tokens->HD_NUM_PRIMITIVE_VERTS, qualifier); - _resGS.emplace_back(InOut::STAGE_OUT, Kind::VALUE, dataType, - gs_outName, noArraySize, qualifier); + // Generate the mapping data. + _resInterstagePackedMappings.clear(); + size_t packedElementGroup = 0; + for (const auto& [commonDataType, elements] : packedElementGroups) { + std::stringstream groupNameBuffer; + TfToken const groupName = TfToken( + _tokens->interstageDrawingCoord.GetString() + + std::to_string(packedElementGroup++)); + + for (size_t i = 0; i < elements.size(); i++) { + _PackedResourceMapping mapping; + mapping.groupName = groupName; + mapping.component = '[' + std::to_string(i) + ']'; + _resInterstagePackedMappings.try_emplace( + elements[i].name.GetString(), std::move(mapping)); + } + + if (commonDataType == _tokens->_int) { + processedElements.push_back({groupName, _tokens->ivec4}); + } else if (commonDataType == _tokens->_float) { + processedElements.push_back({groupName, _tokens->vec4}); + } else { + TF_CODING_ERROR("Invalid element group data type"); + } } - // Fragment shader inputs come from previous active stage - if (_hasGS) { - _resFS.emplace_back(InOut::STAGE_IN, Kind::VALUE, dataType, - gs_outName, noArraySize, qualifier); - } else if (_hasTES) { - _resFS.emplace_back(InOut::STAGE_IN, Kind::VALUE, dataType, - tes_outName, noArraySize, qualifier); - } else { - _resFS.emplace_back(InOut::STAGE_IN, Kind::VALUE, dataType, - vs_outName, noArraySize, qualifier); + for (auto const& [name, dataType] : processedElements) { + bool const isInteger = (dataType == _tokens->ivec4); + + // Add resource elements to plumb interstage elements, e.g. + // drawingCoord and interpolated primvar through active stages. + + std::string const &baseName = name.GetString(); + TfToken const vs_outName( "vs_" + baseName); + TfToken const tcs_outName("tcs_" + baseName); + TfToken const tes_outName("tes_" + baseName); + TfToken const gs_outName( "gs_" + baseName); + + // Empty token for variables with no array size + TfToken const noArraySize; + + // Interstage variables of base type "int" require "flat" interpolation + TfToken const &qualifier = isInteger ? + _tokens->flat : _tokens->_default; + + // Vertex attrib input for VS, PTCS, PTVS + _resAttrib.emplace_back(InOut::STAGE_OUT, Kind::VALUE, dataType, + vs_outName, noArraySize, qualifier); + + if (_hasTCS) { + _resTCS.emplace_back(InOut::STAGE_IN, Kind::VALUE, dataType, + vs_outName, _tokens->gl_MaxPatchVertices, qualifier); + _resTCS.emplace_back(InOut::STAGE_OUT, Kind::VALUE, dataType, + tcs_outName, _tokens->HD_NUM_PATCH_EVAL_VERTS, qualifier); + } + + if (_hasTES) { + _resTES.emplace_back(InOut::STAGE_IN, Kind::VALUE, dataType, + tcs_outName, _tokens->gl_MaxPatchVertices, qualifier); + _resTES.emplace_back(InOut::STAGE_OUT, Kind::VALUE, dataType, + tes_outName, noArraySize, qualifier); + } + + // Geometry shader inputs come from previous active stage + if (_hasGS && _hasTES) { + _resGS.emplace_back(InOut::STAGE_IN, Kind::VALUE, dataType, + tes_outName, _tokens->HD_NUM_PRIMITIVE_VERTS, qualifier); + _resGS.emplace_back(InOut::STAGE_OUT, Kind::VALUE, dataType, + gs_outName, noArraySize, qualifier); + } else if (_hasGS) { + _resGS.emplace_back(InOut::STAGE_IN, Kind::VALUE, dataType, + vs_outName, _tokens->HD_NUM_PRIMITIVE_VERTS, qualifier); + _resGS.emplace_back(InOut::STAGE_OUT, Kind::VALUE, dataType, + gs_outName, noArraySize, qualifier); + } + + // Fragment shader inputs come from previous active stage + if (_hasGS) { + _resFS.emplace_back(InOut::STAGE_IN, Kind::VALUE, dataType, + gs_outName, noArraySize, qualifier); + } else if (_hasTES) { + _resFS.emplace_back(InOut::STAGE_IN, Kind::VALUE, dataType, + tes_outName, noArraySize, qualifier); + } else { + _resFS.emplace_back(InOut::STAGE_IN, Kind::VALUE, dataType, + vs_outName, noArraySize, qualifier); + } } } @@ -2500,11 +2608,6 @@ HdSt_CodeGen::_CompileWithGeneratedGLSLResources( // Generator assigns attribute and binding locations _ResourceGenerator resourceGen; - // Create additional resource elements needed by interstage elements - for (auto const &element : _resInterstage) { - _PlumbInterstageElements(element.name, element.dataType); - } - // create GLSL program. HdStGLSLProgramSharedPtr glslProgram = std::make_shared(HdTokens->drawingShader, registry); @@ -2696,12 +2799,6 @@ HdSt_CodeGen::_CompileWithGeneratedHgiResources( // Generator assigns attribute and binding locations _ResourceGenerator resourceGen; - // Create additional resource elements needed by interstage elements. - // For compute-only shaders, we don't have a HdSt_GeometricShader. - for (auto const &element : _resInterstage) { - _PlumbInterstageElements(element.name, element.dataType); - } - // create GLSL program. HdStGLSLProgramSharedPtr glslProgram = std::make_shared(HdTokens->drawingShader, registry); @@ -4104,58 +4201,82 @@ static void _EmitFVarAccessor( << " { return HdGet_" << name << "(0); }\n"; } -// Helper function to generate the implementation of "GetDrawingCoord()". -static void -_GetDrawingCoord(std::stringstream &ss, - std::vector const &drawingCoordParams, - int const instanceIndexWidth, - char const *inputPrefix, - char const *inArraySize) +HdSt_CodeGen::_PackedResourceMapping +HdSt_CodeGen::_GetDrawingCoordMapping(std::string const& name) +{ + // Given a drawing coord un-prefixed name, return a mapping to + // a component in a vector of packed interstage drawing coords. + if (const auto iter = _resInterstagePackedMappings.find("dc_" + name); + iter != _resInterstagePackedMappings.end()) + { + return iter->second; + } + + return {TfToken(name), TfToken()}; +} + +void +HdSt_CodeGen::_GetDrawingCoord( + std::stringstream &ss, + std::vector const &drawingCoordParams, + int instanceIndexWidth, + char const *inputPrefix, + char const *inArraySize) { ss << "hd_drawingCoord GetDrawingCoord() { \n" << " hd_drawingCoord dc; \n"; for (std::string const & param : drawingCoordParams) { + const auto [groupName, component] = _GetDrawingCoordMapping(param); + ss << " dc." << param - << " = " << inputPrefix << param << inArraySize << ";\n"; + << " = " << inputPrefix << groupName << inArraySize << component + << ";\n"; } for(int i = 0; i < instanceIndexWidth; ++i) { - ss << " dc.instanceIndex[" << std::to_string(i) << "]" - << " = " << inputPrefix - << "instanceIndexI" << std::to_string(i) << inArraySize << ";\n"; + const auto [groupName, component] = _GetDrawingCoordMapping( + "instanceIndexI" + std::to_string(i)); + ss << " dc.instanceIndex[" << i << "]" + << " = " << inputPrefix << groupName << inArraySize << component + << ";\n"; } for(int i = 0; i < instanceIndexWidth-1; ++i) { - ss << " dc.instanceCoords[" << std::to_string(i) << "]" - << " = " << inputPrefix - << "instanceCoordsI" << std::to_string(i) << inArraySize << ";\n"; + const auto [groupName, component] = _GetDrawingCoordMapping( + "instanceCoordsI" + std::to_string(i)); + ss << " dc.instanceCoords[" << i << "]" + << " = " << inputPrefix << groupName << inArraySize << component + << ";\n"; } ss << " return dc; \n" << "}\n"; } -// Helper function to generate drawingCoord interstage processing. -static void -_ProcessDrawingCoord(std::stringstream &ss, - std::vector const &drawingCoordParams, - int const instanceIndexWidth, - char const *outputPrefix, - char const *outArraySize) +void +HdSt_CodeGen::_ProcessDrawingCoord( + std::stringstream &ss, + std::vector const &drawingCoordParams, + int instanceIndexWidth, + char const *outputPrefix, + char const *outArraySize) { ss << " hd_drawingCoord dc = GetDrawingCoord();\n"; for (std::string const & param : drawingCoordParams) { - ss << " " << outputPrefix << param << outArraySize - << " = " << "dc." << param << ";\n"; + const auto [groupName, component] = _GetDrawingCoordMapping(param); + ss << " " << outputPrefix << groupName << outArraySize << component + << " = " << "dc." << param << ";\n"; } for(int i = 0; i < instanceIndexWidth; ++i) { - std::string const index = std::to_string(i); - ss << " " << outputPrefix << "instanceIndexI" << index << outArraySize - << " = " << "dc.instanceIndex[" << index << "]" << ";\n"; + const auto [groupName, component] = _GetDrawingCoordMapping( + "instanceIndexI" + std::to_string(i)); + ss << " " << outputPrefix << groupName << outArraySize << component + << " = " << "dc.instanceIndex[" << i << "]" << ";\n"; } for(int i = 0; i < instanceIndexWidth-1; ++i) { - std::string const index = std::to_string(i); - ss << " " << outputPrefix << "instanceCoordsI" << index << outArraySize - << " = " << "dc.instanceCoords[" << index << "]" << ";\n"; + const auto [groupName, component] = _GetDrawingCoordMapping( + "instanceCoordsI" + std::to_string(i)); + ss << " " << outputPrefix << groupName << outArraySize << component + << " = " << "dc.instanceCoords[" << i << "]" << ";\n"; } } @@ -4276,6 +4397,34 @@ HdSt_CodeGen::_GenerateDrawingCoord( "varyingCoord" }; + const int instanceIndexWidth = _metaData->instancerNumLevels + 1; + + if (!_hasCS) { + for (std::string const & param : drawingCoordParams) { + TfToken const drawingCoordParamName("dc_" + param); + _AddInterstageElement(&_resInterstage, + HioGlslfxResourceLayout::InOut::NONE, + /*name=*/drawingCoordParamName, + /*dataType=*/_tokens->_int); + } + for (int i = 0; i < instanceIndexWidth; ++i) { + TfToken const name(TfStringPrintf("dc_instanceIndexI%d", i)); + _AddInterstageElement(&_resInterstage, + HioGlslfxResourceLayout::InOut::NONE, + /*name=*/name, + /*dataType=*/_tokens->_int); + } + for (int i = 0; i < instanceIndexWidth; ++i) { + TfToken const name(TfStringPrintf("dc_instanceCoordsI%d", i)); + _AddInterstageElement(&_resInterstage, + HioGlslfxResourceLayout::InOut::NONE, + /*name=*/name, + /*dataType=*/_tokens->_int); + } + + _PlumbInterstageElements(); + } + // common // // note: instanceCoords should be [HD_INSTANCER_NUM_LEVELS], but since @@ -4293,8 +4442,6 @@ HdSt_CodeGen::_GenerateDrawingCoord( _genDecl << "FORWARD_DECL(hd_drawingCoord GetDrawingCoord());\n" "FORWARD_DECL(int HgiGetBaseVertex());\n"; - int instanceIndexWidth = _metaData->instancerNumLevels + 1; - // vertex shader // [immediate] @@ -4324,7 +4471,10 @@ HdSt_CodeGen::_GenerateDrawingCoord( // patch instance offset exists on Apple Silicon. Use primitiveCoord // subtracted from the primitive ID for those cases if (requiresBasePrimitiveOffset) { - primitiveID << "int GetBasePrimitiveOffset() { return vs_dc_primitiveCoord; }\n"; + const auto [groupName, component] = + _GetDrawingCoordMapping("primitiveCoord"); + primitiveID << "int GetBasePrimitiveOffset() { return vs_" + << groupName << component << "; }\n"; _genPTCS << "int GetBasePrimitiveOffset() { return drawingCoord0[0].w; }\n"; _genPTVS << "int GetBasePrimitiveOffset() { return drawingCoord0[0].w; }\n"; } else { @@ -4589,30 +4739,6 @@ HdSt_CodeGen::_GenerateDrawingCoord( << " hd_instanceIndex r; r.indices[0] = 0; return r; }\n"; } - if (!_hasCS) { - for (std::string const & param : drawingCoordParams) { - TfToken const drawingCoordParamName("dc_" + param); - _AddInterstageElement(&_resInterstage, - HioGlslfxResourceLayout::InOut::NONE, - /*name=*/drawingCoordParamName, - /*dataType=*/_tokens->_int); - } - for (int i = 0; i < instanceIndexWidth; ++i) { - TfToken const name(TfStringPrintf("dc_instanceIndexI%d", i)); - _AddInterstageElement(&_resInterstage, - HioGlslfxResourceLayout::InOut::NONE, - /*name=*/name, - /*dataType=*/_tokens->_int); - } - for (int i = 0; i < instanceIndexWidth; ++i) { - TfToken const name(TfStringPrintf("dc_instanceCoordsI%d", i)); - _AddInterstageElement(&_resInterstage, - HioGlslfxResourceLayout::InOut::NONE, - /*name=*/name, - /*dataType=*/_tokens->_int); - } - } - _genVS << genAttr.str(); _genPTCS << genAttr.str(); _genPTVS << genAttr.str(); @@ -4715,52 +4841,52 @@ HdSt_CodeGen::_GenerateDrawingCoord( // VS/PTVS from attributes _ProcessDrawingCoord(_procVS, drawingCoordParams, instanceIndexWidth, - "vs_dc_", ""); + "vs_", ""); _ProcessDrawingCoord(_procPTVSOut, drawingCoordParams, instanceIndexWidth, - "vs_dc_", ""); + "vs_", ""); // TCS from VS if (_hasTCS) { _GetDrawingCoord(_genTCS, drawingCoordParams, instanceIndexWidth, - "vs_dc_", "[0]"); + "vs_", "[0]"); _ProcessDrawingCoord(_procTCS, drawingCoordParams, instanceIndexWidth, - "tcs_dc_", "[gl_InvocationID]"); + "tcs_", "[gl_InvocationID]"); } // TES from TCS if (_hasTES) { _GetDrawingCoord(_genTES, drawingCoordParams, instanceIndexWidth, - "tcs_dc_", "[0]"); + "tcs_", "[0]"); _ProcessDrawingCoord(_procTES, drawingCoordParams, instanceIndexWidth, - "tes_dc_", ""); + "tes_", ""); } // GS if (_hasGS && _hasTES) { // from TES _GetDrawingCoord(_genGS, drawingCoordParams, instanceIndexWidth, - "tes_dc_", "[0]"); + "tes_", "[0]"); } else if (_hasGS) { // from VS _GetDrawingCoord(_genGS, drawingCoordParams, instanceIndexWidth, - "vs_dc_", "[0]"); + "vs_", "[0]"); } _ProcessDrawingCoord(_procGS, drawingCoordParams, instanceIndexWidth, - "gs_dc_", ""); + "gs_", ""); // FS if (_hasGS) { // from GS _GetDrawingCoord(_genFS, drawingCoordParams, instanceIndexWidth, - "gs_dc_", ""); + "gs_", ""); } else if (_hasTES) { // from TES _GetDrawingCoord(_genFS, drawingCoordParams, instanceIndexWidth, - "tes_dc_", ""); + "tes_", ""); } else { // from VS/PTVS _GetDrawingCoord(_genFS, drawingCoordParams, instanceIndexWidth, - "vs_dc_", ""); + "vs_", ""); } } diff --git a/pxr/imaging/hdSt/codeGen.h b/pxr/imaging/hdSt/codeGen.h index b2fcb998651..fef9b6d2d48 100644 --- a/pxr/imaging/hdSt/codeGen.h +++ b/pxr/imaging/hdSt/codeGen.h @@ -14,7 +14,7 @@ #include "pxr/imaging/hdSt/glslProgram.h" #include "pxr/imaging/hio/glslfxResourceLayout.h" -#include +#include #include #include @@ -129,7 +129,30 @@ class HdSt_CodeGen std::string _GetFallbackScalarSwizzleString(TfToken const &returnType, TfToken const ¶mName); - void _PlumbInterstageElements(TfToken const &name, TfToken const &dataType); + void _PlumbInterstageElements(); + + // The packed field name (grouping vector) and name of its component that + // holds the resource. + struct _PackedResourceMapping { + TfToken groupName; + std::string component; + }; + + _PackedResourceMapping _GetDrawingCoordMapping(std::string const &name); + + void _GetDrawingCoord( + std::stringstream &ss, + std::vector const &drawingCoordParams, + int instanceIndexWidth, + char const *inputPrefix, + char const *inArraySize); + + void _ProcessDrawingCoord( + std::stringstream &ss, + std::vector const &drawingCoordParams, + int instanceIndexWidth, + char const *outputPrefix, + char const *outArraySize); void _GenerateComputeParameters(HgiShaderFunctionDesc *csDesc); @@ -171,6 +194,8 @@ class HdSt_CodeGen ElementVector _resCS; ElementVector _resInterstage; + std::unordered_map + _resInterstagePackedMappings; ElementVector _resCommon; ElementVector _resAttrib; diff --git a/pxr/imaging/hdSt/pch.h b/pxr/imaging/hdSt/pch.h index 8b268216efa..35272f1c789 100644 --- a/pxr/imaging/hdSt/pch.h +++ b/pxr/imaging/hdSt/pch.h @@ -109,6 +109,7 @@ #include #endif // PXR_MATERIALX_SUPPORT_ENABLED #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #if defined(__APPLE__) // Fix breakage caused by Python's pyport.h. diff --git a/pxr/imaging/hdSt/renderDelegate.cpp b/pxr/imaging/hdSt/renderDelegate.cpp index 37d22c51275..d35c0cf1c17 100644 --- a/pxr/imaging/hdSt/renderDelegate.cpp +++ b/pxr/imaging/hdSt/renderDelegate.cpp @@ -321,7 +321,7 @@ HdStRenderDelegate::GetDefaultAovDescriptor(TfToken const& name) const VtValue(HdDepthStencilType(1.0f, 0))); } else if (_AovHasIdSemantic(name)) { return HdAovDescriptor( - HdFormatUNorm8Vec4, colorDepthMSAA, VtValue(GfVec4f(0))); + HdFormatInt32, colorDepthMSAA, VtValue(-1)); } else if (name == HdAovTokens->Neye) { return HdAovDescriptor( HdFormatUNorm8Vec4, colorDepthMSAA, VtValue(GfVec4f(0))); diff --git a/pxr/imaging/hdSt/renderPassShader.cpp b/pxr/imaging/hdSt/renderPassShader.cpp index a6f3fc9dd2d..d3ba975e56f 100644 --- a/pxr/imaging/hdSt/renderPassShader.cpp +++ b/pxr/imaging/hdSt/renderPassShader.cpp @@ -13,6 +13,7 @@ #include "pxr/imaging/hdSt/materialParam.h" #include "pxr/imaging/hdSt/renderBuffer.h" #include "pxr/imaging/hdSt/renderPassShader.h" +#include "pxr/imaging/hdSt/renderPassShaderKey.h" #include "pxr/imaging/hdSt/resourceBinder.h" #include "pxr/imaging/hdSt/textureBinder.h" #include "pxr/imaging/hdSt/textureHandle.h" @@ -327,4 +328,49 @@ HdStRenderPassShader::UpdateAovInputTextures( } } +namespace { +size_t +_GetRenderPassShaderHash( + HdRenderPassAovBindingVector const &aovBindings, + const HdStRenderPassState * const renderPassState) +{ + size_t hash = 0; + + // Aov binding names determine the configuration of the render pass shader + // key. + for (const auto& aovBinding : aovBindings) { + hash = TfHash::Combine(hash, aovBinding.aovName); + } + + // We want each renderPassState to have its own renderPassShader, so + // include renderPassState in the hash. + hash = TfHash::Combine(hash, renderPassState); + + return hash; +} +} + +// static +HdStRenderPassShaderSharedPtr +HdStRenderPassShader::CreateRenderPassShaderFromAovs( + HdStRenderPassState *renderPassState, + HdStResourceRegistrySharedPtr const &resourceRegistry, + HdRenderPassAovBindingVector const &aovBindings) +{ + HdInstance renderPassShaderInstance = + resourceRegistry->RegisterRenderPassShader( + _GetRenderPassShaderHash(aovBindings, renderPassState)); + + if (renderPassShaderInstance.IsFirstInstance()) { + HdSt_RenderPassShaderKey shaderKey(aovBindings); + std::istringstream s(shaderKey.GetGlslfxString()); + HioGlslfxSharedPtr glslfx = std::make_shared(s); + + renderPassShaderInstance.SetValue( + std::make_shared(glslfx)); + } + + return renderPassShaderInstance.GetValue(); +} + PXR_NAMESPACE_CLOSE_SCOPE diff --git a/pxr/imaging/hdSt/renderPassShader.h b/pxr/imaging/hdSt/renderPassShader.h index 3b1dd3f3af3..34e4ef7b725 100644 --- a/pxr/imaging/hdSt/renderPassShader.h +++ b/pxr/imaging/hdSt/renderPassShader.h @@ -23,6 +23,7 @@ PXR_NAMESPACE_OPEN_SCOPE using HdStRenderPassShaderSharedPtr = std::shared_ptr; +class HdStRenderPassState; class HdRenderIndex; using HdRenderPassAovBindingVector = std::vector; @@ -84,6 +85,14 @@ class HdStRenderPassShader : public HdStShaderCode { HdRenderPassAovBindingVector const &aovInputBindings, HdRenderIndex * const renderIndex); + HDST_API + static + HdStRenderPassShaderSharedPtr + CreateRenderPassShaderFromAovs( + HdStRenderPassState *renderPassState, + HdStResourceRegistrySharedPtr const &resourceRegistry, + HdRenderPassAovBindingVector const &aovBindings); + private: HioGlslfxSharedPtr _glslfx; mutable size_t _hash; diff --git a/pxr/imaging/hdSt/renderPassShaderKey.cpp b/pxr/imaging/hdSt/renderPassShaderKey.cpp new file mode 100644 index 00000000000..3e08168cb8f --- /dev/null +++ b/pxr/imaging/hdSt/renderPassShaderKey.cpp @@ -0,0 +1,161 @@ +// +// Copyright 2024 Pixar +// +// Licensed under the terms set forth in the LICENSE.txt file available at +// https://openusd.org/license. +// +#include "pxr/pxr.h" +#include "pxr/imaging/hdSt/renderPassShaderKey.h" +#include "pxr/imaging/hd/tokens.h" + +#include "pxr/base/tf/staticTokens.h" + +PXR_NAMESPACE_OPEN_SCOPE + + +TF_DEFINE_PRIVATE_TOKENS( + _tokens, + // Glslfx files to include + ((renderPassGlslfx, "renderPass.glslfx")) + ((selectionGlslfx, "selection.glslfx")) + + // render pass mixins + ((renderPassCamera, "RenderPass.Camera")) + ((renderPassCameraFS, "RenderPass.CameraFS")) + ((renderPassApplyClipPlanes, "RenderPass.ApplyClipPlanes")) + ((renderPassApplyColorOverrides, "RenderPass.ApplyColorOverrides")) + ((renderPassRenderOutput, "RenderPass.RenderOutput")) + ((renderPassNoSelection, "RenderPass.NoSelection")) + ((renderPassNoColorOverrides, "RenderPass.NoColorOverrides")) + + // selection mixins + ((selectionDecodeUtils, "Selection.DecodeUtils")) + ((selectionComputeColor, "Selection.ComputeColor")) + + // Render AOV outputs mixins + ((renderPassRenderColor, "RenderPass.RenderColor")) + ((renderPassRenderColorNoOp, "RenderPass.RenderColorNoOp")) + + ((renderPassRenderId, "RenderPass.RenderId")) + ((renderPassRenderIdNoOp, "RenderPass.RenderIdNoOp")) + + ((renderPassRenderNeye, "RenderPass.RenderNeye")) + ((renderPassRenderNeyeNoOp, "RenderPass.RenderNeyeNoOp")) +); + +static +bool +_AovHasIdSemantic(TfToken const & name) +{ + // For now id render only means primId or instanceId. + return name == HdAovTokens->primId || + name == HdAovTokens->instanceId; +} + +HdSt_RenderPassShaderKey::HdSt_RenderPassShaderKey( + const HdRenderPassAovBindingVector& aovBindings) + : glslfx(_tokens->renderPassGlslfx) +{ + bool renderColor = false; + bool renderId = false; + bool renderNeye = false; + + for (size_t i = 0; i < aovBindings.size(); ++i) { + if (!renderColor && aovBindings[i].aovName == HdAovTokens->color) { + renderColor = true; + } + if (!renderId && _AovHasIdSemantic(aovBindings[i].aovName)) { + renderId = true; + } + if (!renderNeye && aovBindings[i].aovName == HdAovTokens->Neye) { + renderNeye = true; + } + } + + VS[0] = _tokens->renderPassCamera; + VS[1] = _tokens->renderPassApplyClipPlanes; + VS[2] = TfToken(); + + PTCS[0] = _tokens->renderPassCamera; + PTCS[1] = TfToken(); + + PTVS[0] = _tokens->renderPassCamera; + PTVS[1] = _tokens->renderPassApplyClipPlanes; + PTVS[2] = TfToken(); + + TCS[0] = _tokens->renderPassCamera; + TCS[1] = TfToken(); + + TES[0] = _tokens->renderPassCamera; + TES[1] = _tokens->renderPassApplyClipPlanes; + TES[2] = TfToken(); + + GS[0] = _tokens->renderPassCamera; + GS[1] = _tokens->renderPassApplyClipPlanes; + GS[2] = TfToken(); + + uint8_t fsIndex = 0; + FS[fsIndex++] = _tokens->renderPassCamera; + FS[fsIndex++] = _tokens->renderPassCameraFS; + + if (renderColor) { + FS[fsIndex++] = _tokens->selectionDecodeUtils; + FS[fsIndex++] = _tokens->selectionComputeColor; + FS[fsIndex++] = _tokens->renderPassApplyColorOverrides; + FS[fsIndex++] = _tokens->renderPassRenderColor; + } else { + FS[fsIndex++] = _tokens->renderPassNoSelection; + FS[fsIndex++] = _tokens->renderPassNoColorOverrides; + FS[fsIndex++] = _tokens->renderPassRenderColorNoOp; + } + + if (renderId) { + FS[fsIndex++] = _tokens->renderPassRenderId; + } else { + FS[fsIndex++] = _tokens->renderPassRenderIdNoOp; + } + + if (renderNeye) { + FS[fsIndex++] = _tokens->renderPassRenderNeye; + } else { + FS[fsIndex++] = _tokens->renderPassRenderNeyeNoOp; + } + + FS[fsIndex++] = _tokens->renderPassRenderOutput; + FS[fsIndex++] = TfToken(); +} + +HdSt_RenderPassShaderKey::~HdSt_RenderPassShaderKey() = default; + +std::string +HdSt_RenderPassShaderKey::GetGlslfxString() const +{ + std::stringstream ss; + + ss << "-- glslfx version 0.1\n"; + + if (!GetGlslfxFilename().IsEmpty()) { + ss << "#import $TOOLS/hdSt/shaders/" + << GetGlslfxFilename().GetText() << "\n"; + } + // Additionally need one more import. + ss << "#import $TOOLS/hdx/shaders/" << _tokens->selectionGlslfx << "\n"; + + ss << "-- configuration\n" + << "{\"techniques\": {\"default\": {\n"; + + bool firstStage = true; + ss << _JoinTokens("vertexShader", GetVS(), &firstStage); + ss << _JoinTokens("tessControlShader", GetTCS(), &firstStage); + ss << _JoinTokens("tessEvalShader", GetTES(), &firstStage); + ss << _JoinTokens("postTessControlShader", GetPTCS(), &firstStage); + ss << _JoinTokens("postTessVertexShader", GetPTVS(), &firstStage); + ss << _JoinTokens("geometryShader", GetGS(), &firstStage); + ss << _JoinTokens("fragmentShader", GetFS(), &firstStage); + ss << "}}}\n"; + + return ss.str(); +} + + +PXR_NAMESPACE_CLOSE_SCOPE \ No newline at end of file diff --git a/pxr/imaging/hdSt/renderPassShaderKey.h b/pxr/imaging/hdSt/renderPassShaderKey.h new file mode 100644 index 00000000000..151dbb19ca6 --- /dev/null +++ b/pxr/imaging/hdSt/renderPassShaderKey.h @@ -0,0 +1,54 @@ +// +// Copyright 2024 Pixar +// +// Licensed under the terms set forth in the LICENSE.txt file available at +// https://openusd.org/license. +// +#ifndef PXR_IMAGING_HD_ST_RENDER_PASS_SHADER_KEY_H +#define PXR_IMAGING_HD_ST_RENDER_PASS_SHADER_KEY_H + +#include "pxr/pxr.h" +#include "pxr/imaging/hdSt/geometricShader.h" +#include "pxr/imaging/hdSt/shaderKey.h" +#include "pxr/imaging/hd/aov.h" +#include "pxr/base/tf/token.h" + +PXR_NAMESPACE_OPEN_SCOPE + +struct HdSt_RenderPassShaderKey : public HdSt_ShaderKey +{ + HDST_API + HdSt_RenderPassShaderKey(const HdRenderPassAovBindingVector& aovBindings); + HDST_API + ~HdSt_RenderPassShaderKey(); + + TfToken const &GetGlslfxFilename() const override { return glslfx; } + TfToken const *GetVS() const override { return VS; } + TfToken const *GetPTCS() const override { return PTCS; } + TfToken const *GetPTVS() const override { return PTVS; } + TfToken const *GetTCS() const override { return TCS; } + TfToken const *GetTES() const override { return TES; } + TfToken const *GetGS() const override { return GS; } + TfToken const *GetFS() const override { return FS; } + + HDST_API + std::string GetGlslfxString() const override; + + // Unused for HdSt_RenderPassShaderKey. + HdSt_GeometricShader::PrimitiveType GetPrimitiveType() const override { + return HdSt_GeometricShader::PrimitiveType::PRIM_POINTS; + } + + TfToken glslfx; + TfToken VS[3]; + TfToken PTCS[2]; + TfToken PTVS[3]; + TfToken TCS[2]; + TfToken TES[3]; + TfToken GS[3]; + TfToken FS[10]; +}; + +PXR_NAMESPACE_CLOSE_SCOPE + +#endif // PXR_IMAGING_HD_ST_RENDER_PASS_SHADER_KEY_H \ No newline at end of file diff --git a/pxr/imaging/hdSt/renderPassState.cpp b/pxr/imaging/hdSt/renderPassState.cpp index 1cd4918f4dd..189a0a7ee79 100644 --- a/pxr/imaging/hdSt/renderPassState.cpp +++ b/pxr/imaging/hdSt/renderPassState.cpp @@ -490,11 +490,11 @@ HdStRenderPassState::SetLightingShader(HdStLightingShaderSharedPtr const &lighti } void -HdStRenderPassState::SetRenderPassShader(HdStRenderPassShaderSharedPtr const &renderPassShader) +HdStRenderPassState::SetRenderPassShader( + HdStRenderPassShaderSharedPtr const &renderPassShader) { _renderPassShader = renderPassShader; if (_renderPassStateBar) { - HdStBufferArrayRangeSharedPtr _renderPassStateBar_ = std::static_pointer_cast (_renderPassStateBar); @@ -856,6 +856,10 @@ GfVec4f _ToVec4f(const VtValue &v) const double val = v.UncheckedGet(); return GfVec4f(val); } + if (v.IsHolding()) { + const double val = v.UncheckedGet(); + return GfVec4f(val); + } if (v.IsHolding()) { const GfVec2f val = v.UncheckedGet(); return GfVec4f(val[0], val[1], 0.0, 1.0); diff --git a/pxr/imaging/hdSt/resourceRegistry.cpp b/pxr/imaging/hdSt/resourceRegistry.cpp index b4a06ded12f..cc62846c3c3 100644 --- a/pxr/imaging/hdSt/resourceRegistry.cpp +++ b/pxr/imaging/hdSt/resourceRegistry.cpp @@ -11,6 +11,7 @@ #include "pxr/imaging/hdSt/dispatchBuffer.h" #include "pxr/imaging/hdSt/glslProgram.h" #include "pxr/imaging/hdSt/interleavedMemoryManager.h" +#include "pxr/imaging/hdSt/renderPassShader.h" #include "pxr/imaging/hdSt/resourceRegistry.h" #include "pxr/imaging/hdSt/stagingBuffer.h" #include "pxr/imaging/hdSt/vboMemoryManager.h" @@ -137,6 +138,7 @@ HdStResourceRegistry::~HdStResourceRegistry() void HdStResourceRegistry::InvalidateShaderRegistry() { _geometricShaderRegistry.Invalidate(); + _renderPassShaderRegistry.Invalidate(); _glslfxFileRegistry.Invalidate(); #ifdef PXR_MATERIALX_SUPPORT_ENABLED _materialXShaderRegistry.Invalidate(); @@ -633,6 +635,13 @@ HdStResourceRegistry::RegisterGeometricShader( return _geometricShaderRegistry.GetInstance(id); } +HdInstance +HdStResourceRegistry::RegisterRenderPassShader( + HdInstance::ID id) +{ + return _renderPassShaderRegistry.GetInstance(id); +} + HdInstance HdStResourceRegistry::RegisterGLSLProgram( HdInstance::ID id) @@ -1097,6 +1106,7 @@ HdStResourceRegistry::_GarbageCollect() // Cleanup Shader registries _geometricShaderRegistry.GarbageCollect(); + _renderPassShaderRegistry.GarbageCollect(); _glslProgramRegistry.GarbageCollect(); _glslfxFileRegistry.GarbageCollect(); #ifdef PXR_MATERIALX_SUPPORT_ENABLED diff --git a/pxr/imaging/hdSt/resourceRegistry.h b/pxr/imaging/hdSt/resourceRegistry.h index d6f2b7e15c8..ae2e10a6b33 100644 --- a/pxr/imaging/hdSt/resourceRegistry.h +++ b/pxr/imaging/hdSt/resourceRegistry.h @@ -49,6 +49,8 @@ using HdStShaderCodePtr = std::weak_ptr; using HdSt_GeometricShaderSharedPtr = std::shared_ptr; +using HdStRenderPassShaderSharedPtr = + std::shared_ptr; using HdStTextureHandleSharedPtr = std::shared_ptr; @@ -396,6 +398,11 @@ class HdStResourceRegistry final : public HdResourceRegistry HdInstance RegisterGeometricShader(HdInstance::ID id); + /// Register a render pass shader. + HDST_API + HdInstance + RegisterRenderPassShader(HdInstance::ID id); + /// Register a GLSL program into the program registry. HDST_API HdInstance @@ -661,6 +668,10 @@ class HdStResourceRegistry final : public HdResourceRegistry // geometric shader registry HdInstanceRegistry _geometricShaderRegistry; + + // render pass shader registry + HdInstanceRegistry + _renderPassShaderRegistry; // glsl shader program registry HdInstanceRegistry diff --git a/pxr/imaging/hdSt/shaderKey.cpp b/pxr/imaging/hdSt/shaderKey.cpp index 2b9dbeec5fc..364ed9791ce 100644 --- a/pxr/imaging/hdSt/shaderKey.cpp +++ b/pxr/imaging/hdSt/shaderKey.cpp @@ -96,9 +96,10 @@ HdSt_ShaderKey::ComputeHash() const return hash; } -static +/*static*/ std::string -_JoinTokens(const char *stage, TfToken const *tokens, bool *firstStage) +HdSt_ShaderKey::_JoinTokens( + const char *stage, TfToken const *tokens, bool *firstStage) { if ((!tokens) || tokens->IsEmpty()) return std::string(); diff --git a/pxr/imaging/hdSt/shaderKey.h b/pxr/imaging/hdSt/shaderKey.h index fe2d3c699ce..36af8b254c2 100644 --- a/pxr/imaging/hdSt/shaderKey.h +++ b/pxr/imaging/hdSt/shaderKey.h @@ -20,7 +20,7 @@ PXR_NAMESPACE_OPEN_SCOPE // Abstract interface for geometric shader keys that may be used to // construct a geometric shader. struct HdSt_ShaderKey { - typedef size_t ID; + using ID = size_t; HDST_API virtual ~HdSt_ShaderKey(); @@ -30,11 +30,6 @@ struct HdSt_ShaderKey { HDST_API ID ComputeHash() const; - // Stitches the glslfx filename and the shader stage mixin names into - // a string for consumption by HioGlslfx. - HDST_API - std::string GetGlslfxString() const; - // ------------------------------------------------------------------------- // Virtual interface // ------------------------------------------------------------------------- @@ -45,6 +40,11 @@ struct HdSt_ShaderKey { // define any functions it uses. virtual TfToken const &GetGlslfxFilename() const = 0; + // Stitches the glslfx filename and the shader stage mixin names into + // a string for consumption by HioGlslfx. + HDST_API + virtual std::string GetGlslfxString() const; + // Each shader stage specifies the various mixins to stitch together // via their token names. The Get* flavor of methods return the first // token in the array. @@ -96,8 +96,13 @@ struct HdSt_ShaderKey { // of the face-varying primvar accessors. Only relevant for mesh prims with // face-varying primvars. HDST_API - virtual HdSt_GeometricShader::FvarPatchType GetFvarPatchType() const; + virtual HdSt_GeometricShader::FvarPatchType GetFvarPatchType() const; +protected: + + HDST_API + static std::string _JoinTokens( + const char *stage, TfToken const *tokens, bool *firstStage); }; diff --git a/pxr/imaging/hdSt/shaders/renderPass.glslfx b/pxr/imaging/hdSt/shaders/renderPass.glslfx index 95433df404a..c1d180b4feb 100644 --- a/pxr/imaging/hdSt/shaders/renderPass.glslfx +++ b/pxr/imaging/hdSt/shaders/renderPass.glslfx @@ -233,6 +233,17 @@ vec4 ApplyColorOverridesPostLighting(vec4 color) return color; } +-- glsl RenderPass.RenderOutput + +void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +{ + // Write to any desired AOVs here. The render pass shader configuation + // decides if any of these are no-ops. + RenderColor(color); + RenderId(); + RenderNeye(Neye); +} + -- layout RenderPass.RenderColor [ @@ -241,23 +252,76 @@ vec4 ApplyColorOverridesPostLighting(vec4 color) -- glsl RenderPass.RenderColor -void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +void RenderColor(vec4 color) { colorOut = color; } +-- glsl RenderPass.RenderColorNoOp + +void RenderColor(vec4 color) +{ + // do nothing +} + -- layout RenderPass.RenderId +[ + ["out", "int", "primIdOut"], + ["out", "int", "instanceIdOut"] +] + +-- glsl RenderPass.RenderId + +void RenderId() +{ + primIdOut = HdGet_primID(); + + // instanceIndex is a tuple of integers (num nested levels). + // for picking, we store global instanceId (instanceIndex[0]) in the + // selection framebuffer and then reconstruct the tuple in postprocess. + instanceIdOut = GetDrawingCoord().instanceIndex[0]; +} + +-- glsl RenderPass.RenderIdNoOp + +void RenderId() +{ + // do nothing +} + +-- layout RenderPass.RenderNeye + +[ + ["out", "vec4", "NeyeOut"] +] + +-- glsl RenderPass.RenderNeye + +void RenderNeye(vec3 Neye) +{ + NeyeOut = vec4(Neye, 1.0); +} + +-- glsl RenderPass.RenderNeyeNoOp + +void RenderNeye(vec3 Neye) +{ + // do nothing +} + +-- layout RenderPass.RenderIdNoIdAov + [ ["out", "vec4", "primIdOut"], ["out", "vec4", "instanceIdOut"] ] --- glsl RenderPass.RenderId +-- glsl RenderPass.RenderIdNoIdAov -// XXX: This whole snippet is a little sketchy and should ideally be replaced -// with AoVs. We generate "primId" and "instanceId", and depending on how -// the client called glDrawBuffers, they will get one or both. +// XXX: This snippet is legacy code soon to be deprecated. It is used when the +// client asks for an id render using HdxRenderTaskParams rather than via an id +// aov. vec4 IntToVec4(int id) { @@ -282,4 +346,4 @@ void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) // selection framebuffer and then reconstruct the tuple in postprocess. int instanceId = GetDrawingCoord().instanceIndex[0]; instanceIdOut = IntToVec4(instanceId); -} +} \ No newline at end of file diff --git a/pxr/imaging/hdSt/shaders/renderPassShader.glslfx b/pxr/imaging/hdSt/shaders/renderPassShader.glslfx index cae3277529d..dc1961135de 100644 --- a/pxr/imaging/hdSt/shaders/renderPassShader.glslfx +++ b/pxr/imaging/hdSt/shaders/renderPassShader.glslfx @@ -43,7 +43,10 @@ "RenderPass.CameraFS", "RenderPass.NoSelection", "RenderPass.ApplyColorOverrides", - "RenderPass.RenderColor" ] + "RenderPass.RenderColor", + "RenderPass.RenderIdNoOp", + "RenderPass.RenderNeyeNoOp", + "RenderPass.RenderOutput"] } } } diff --git a/pxr/imaging/hdSt/testenv/testHdStBarAllocationLimit.cpp b/pxr/imaging/hdSt/testenv/testHdStBarAllocationLimit.cpp index ec181a4e0e4..62fd5f07c45 100644 --- a/pxr/imaging/hdSt/testenv/testHdStBarAllocationLimit.cpp +++ b/pxr/imaging/hdSt/testenv/testHdStBarAllocationLimit.cpp @@ -9,6 +9,8 @@ #include "pxr/imaging/hdSt/unitTestGLDrawing.h" #include "pxr/imaging/hdSt/unitTestHelper.h" +#include "pxr/imaging/hgi/capabilities.h" + #include "pxr/base/gf/matrix4d.h" #include "pxr/base/gf/rotation.h" #include "pxr/base/gf/vec3d.h" @@ -119,11 +121,13 @@ My_TestGLDrawing::AddLargeCurve(HdUnitTestDelegate *delegate) HdInterpolation colorInterp, widthInterp, opacityInterp; colorInterp = widthInterp = opacityInterp = HdInterpolationConstant; - const size_t vboSizeLimit = 1 << 30; // see HD_MAX_VBO_SIZE - const size_t maxPointsInVBO = vboSizeLimit / sizeof(GfVec3f); - const size_t numControlVertsPerCurve = 1 << 2; + static constexpr size_t vboMaxSize = 1 << 30; // default for HD_MAX_VBO_SIZE + const size_t storageMaxSize = _driver->GetHgi()->GetCapabilities()-> + GetMaxShaderStorageBlockSize(); + const size_t maxPointsInVBO = std::min(storageMaxSize, vboMaxSize) / sizeof(GfVec3f); + static constexpr size_t numControlVertsPerCurve = 1 << 2; const size_t numCurves = maxPointsInVBO / numControlVertsPerCurve + 1; - + std::vector curveVertexCounts(numCurves, numControlVertsPerCurve); GfVec3f basePoints[] = { diff --git a/pxr/imaging/hdSt/testenv/testHdStBufferAggregation.cpp b/pxr/imaging/hdSt/testenv/testHdStBufferAggregation.cpp index a54842a1648..ce52d47289e 100644 --- a/pxr/imaging/hdSt/testenv/testHdStBufferAggregation.cpp +++ b/pxr/imaging/hdSt/testenv/testHdStBufferAggregation.cpp @@ -832,9 +832,10 @@ OverAggregationTest(HdStResourceRegistry *registry) // * 50 // 8 entries = 915MB // split into 7 buffers. - int count = 50; + static constexpr size_t count = 50; + static constexpr size_t countPerCommit = count / 2; std::vector ranges; - for (int i = 0; i < count/2; ++i) { + for (size_t i = 0; i < countPerCommit; ++i) { HdBufferSourceSharedPtrVector sources; sources.push_back( std::make_shared( @@ -854,9 +855,9 @@ OverAggregationTest(HdStResourceRegistry *registry) registry->Commit(); - // Schedule some more resources which will aggregate with the + // Schedule some more resources which will aggregate with the // previously committed resources. - for (int i = count/2; i < count; ++i) { + for (size_t i = countPerCommit; i < count; ++i) { HdBufferSourceSharedPtrVector sources; sources.push_back( std::make_shared( @@ -877,26 +878,36 @@ OverAggregationTest(HdStResourceRegistry *registry) registry->Commit(); // read - for (int i = 0; i < count; ++i) { + for (size_t i = 0; i < count; ++i) { VtValue const& rangeData = ranges[i]->ReadData(HdTokens->points); if (points != rangeData) { // XXX The below code is added for debugging why this test // sometimes fails. We suspect a floating-point compare issue where // we may need to have a small epsilon for comparing floats? TF_VERIFY(rangeData.IsHolding>()); - VtArray const& vec3fArray = + VtArray const& vec3fArray = rangeData.UncheckedGet>(); std::cerr << "point size: " << points.size() << std::endl; std::cerr << "rangeData size: " << vec3fArray.size() << std::endl; - for (size_t x=0; x maxFailureCountPrint) { + std::cerr << "And " << (failureCount - maxFailureCountPrint) << + " more failures omitted (" << (static_cast(failureCount) / + points.size() * 100) << "% failed)" << std::endl; + } + TF_VERIFY(false); } } @@ -905,8 +916,24 @@ OverAggregationTest(HdStResourceRegistry *registry) std::cerr << perfLog.GetCounter(HdStPerfTokens->copyBufferCpuToGpu) << "\n"; std::cerr << perfLog.GetCounter(HdStPerfTokens->copyBufferGpuToGpu) << "\n"; + // Relocation count depends on the VBO max size. Smaller size means more relocations. + // If it's the default 2^30, there will be 9 relocations. But smaller can have much more: + // For example Lavapipe limits the size to 2^27 and has 51 relocations. + static constexpr size_t vboMaxSize = 1 << 30; // default for HD_MAX_VBO_SIZE + const size_t storageMaxSize = + registry->GetHgi()->GetCapabilities()->GetMaxShaderStorageBlockSize(); + const size_t rangesPerBuffer = std::min(storageMaxSize, vboMaxSize) / + (points.size() * sizeof(GfVec3f)); + const size_t relocationsFirstCommit = + (countPerCommit - 1) / rangesPerBuffer + 1; + const size_t relocationsSecondCommit = + (countPerCommit - 1 + rangesPerBuffer) / rangesPerBuffer + 1; + const size_t totalRelocations = + relocationsFirstCommit + relocationsSecondCommit; + // check perf counters - TF_VERIFY(perfLog.GetCounter(HdPerfTokens->vboRelocated) == 9); + TF_VERIFY(perfLog.GetCounter( + HdPerfTokens->vboRelocated) == totalRelocations); TF_VERIFY(perfLog.GetCounter(HdStPerfTokens->copyBufferCpuToGpu) == 50); TF_VERIFY(perfLog.GetCounter(HdStPerfTokens->copyBufferGpuToGpu) == 1); @@ -1063,5 +1090,4 @@ int main(int argc, char *argv[]) std::cout << "FAILED" << std::endl; return EXIT_FAILURE; } -} - +} \ No newline at end of file diff --git a/pxr/imaging/hdSt/testenv/testHdStCodeGen.cpp b/pxr/imaging/hdSt/testenv/testHdStCodeGen.cpp index c20dcc256ba..9cffd2b1091 100644 --- a/pxr/imaging/hdSt/testenv/testHdStCodeGen.cpp +++ b/pxr/imaging/hdSt/testenv/testHdStCodeGen.cpp @@ -16,15 +16,20 @@ #include "pxr/imaging/hdSt/meshShaderKey.h" #include "pxr/imaging/hdSt/package.h" #include "pxr/imaging/hdSt/pointsShaderKey.h" +#include "pxr/imaging/hdSt/renderDelegate.h" #include "pxr/imaging/hdSt/renderPassShader.h" #include "pxr/imaging/hdSt/resourceBinder.h" #include "pxr/imaging/hdSt/resourceRegistry.h" #include "pxr/imaging/hd/drawingCoord.h" +#include "pxr/imaging/hd/driver.h" #include "pxr/imaging/hd/basisCurves.h" +#include "pxr/imaging/hd/renderIndex.h" #include "pxr/imaging/hd/rprimSharedData.h" #include "pxr/imaging/hd/tokens.h" +#include "pxr/imaging/hgi/tokens.h" + #include "pxr/imaging/glf/testGLContext.h" #include "pxr/imaging/hio/glslfx.h" #include "pxr/base/tf/errorMark.h" @@ -60,8 +65,7 @@ TF_DEFINE_PRIVATE_TOKENS( ); static bool -CodeGenTest(HdSt_ShaderKey const &key, bool useBindlessBuffer, - bool instance, bool smoothNormals) +CodeGenTest(HdSt_ShaderKey const &key, bool instance, bool smoothNormals) { TfErrorMark mark; @@ -71,8 +75,13 @@ CodeGenTest(HdSt_ShaderKey const &key, bool useBindlessBuffer, HdStDrawItem drawItem(&sharedData); static HgiUniquePtr hgi = Hgi::CreatePlatformDefaultHgi(); - static HdStResourceRegistrySharedPtr registry( - new HdStResourceRegistry(hgi.get())); + static HdDriver driver{HgiTokens->renderDriver, VtValue(hgi.get())}; + static HdStRenderDelegate renderDelegate; + static std::unique_ptr index( + HdRenderIndex::New(&renderDelegate, {&driver})); + HdStResourceRegistrySharedPtr const & registry = + std::static_pointer_cast( + index->GetResourceRegistry()); HdDrawingCoord *drawingCoord = drawItem.GetDrawingCoord(); @@ -300,11 +309,10 @@ CodeGenTest(HdSt_ShaderKey const &key, bool useBindlessBuffer, } bool -TestShader(HdSt_ShaderKey const &key, bool bindless, - bool instance, bool smoothNormals) +TestShader(HdSt_ShaderKey const &key, bool instance, bool smoothNormals) { bool success = true; - success &= CodeGenTest(key, bindless, instance, smoothNormals); + success &= CodeGenTest(key, instance, smoothNormals); return success; } @@ -324,7 +332,6 @@ int main(int argc, char *argv[]) bool mesh = false; bool curves = false; bool points = false; - bool bindless = false; HdMeshGeomStyle geomStyle = HdMeshGeomStyleSurf; for (int i=0; isurfaceShader, topologicalVisibility, /* isWidget */ false, false), - bindless, instance, false); + instance, false); } // points if (points) { success &= TestShader(HdSt_PointsShaderKey(), - bindless, instance, false); + instance, false); } if (success) { diff --git a/pxr/imaging/hdSt/testenv/testHdStCodeGen_GL/baseline/codegen_curves_bindless.out b/pxr/imaging/hdSt/testenv/testHdStCodeGen_GL/baseline/codegen_curves_bindless.out deleted file mode 100644 index 1379eaaab95..00000000000 --- a/pxr/imaging/hdSt/testenv/testHdStCodeGen_GL/baseline/codegen_curves_bindless.out +++ /dev/null @@ -1,2696 +0,0 @@ -------------------------------------------------------- --- glslfx version 0.1 -#import $TOOLS/hdSt/shaders/basisCurves.glslfx --- configuration -{"techniques": {"default": { -"vertexShader" : { "source" : ["Instancing.Transform", "Curves.Vertex.Wire", "Curves.Vertex.Normal.Implicit", "PointId.Vertex.None"] } -, "tessControlShader" : { "source" : ["Curves.CommonData", "Curves.TessFactorsGLSL", "Curves.CommonControl", "Curves.Tess.CurveData.Wire", "Curves.TessControl.Cubic.Wire"] } -, "tessEvalShader" : { "source" : ["Curves.CommonData", "Instancing.Transform", "Curves.Tess.CurveData.Wire", "Curves.TessEval.Cubic.Wire", "Curves.BezierBasis", "Curves.Cubic.VaryingInterpolation"] } -, "fragmentShader" : { "source" : ["Fragment.CommonTerminals", "Fragment.Surface", "Fragment.ScalarOverride", "PointId.Fragment.Fallback", "Visibility.Fragment.Fallback", "Curves.Fragment.Wire"] } -}}} -------------------------------------------------------- -======================================================= - VERTEX SHADER -======================================================= -#version 450 -#extension GL_NV_shader_buffer_load : require -#extension GL_NV_gpu_shader5 : require -#extension GL_ARB_bindless_texture : require -#extension GL_ARB_shader_draw_parameters : require -int HgiGetBaseVertex() { - return gl_BaseVertexARB; -} -#define REF(space,type) inout type -#define FORWARD_DECL(func_decl) func_decl; -#define ATOMIC_LOAD(a) (a) -#define ATOMIC_STORE(a, v) (a) = (v) -#define ATOMIC_ADD(a, v) atomicAdd(a, v) -#define ATOMIC_EXCHANGE(a, v) atomicExchange(a, v) -#define ATOMIC_COMP_SWAP(a, expected, desired) atomicCompSwap(a, expected, desired) -#define atomic_int int -#define atomic_uint uint - -#define HGI_HAS_DOUBLE_TYPE 1 - - -struct hgi_ivec3 { int x, y, z; }; -struct hgi_vec3 { float x, y, z; }; -struct hgi_dvec3 { double x, y, z; }; -struct hgi_mat3 { float m00, m01, m02, - m10, m11, m12, - m20, m21, m22; }; -struct hgi_dmat3 { double m00, m01, m02, - m10, m11, m12, - m20, m21, m22; }; - - -// //////// Codegen Defines //////// -#define HD_SHADER_API 2 -#define MAT4 mat4 -// Alias hgi vec and matrix types to hd. -#define hd_ivec3 hgi_ivec3 -#define hd_vec3 hgi_vec3 -#define hd_dvec3 hgi_dvec3 -#define hd_mat3 hgi_mat3 -#define hd_dmat3 hgi_dmat3 - -ivec3 hd_ivec3_get(hd_ivec3 v) { return ivec3(v.x, v.y, v.z); } -ivec3 hd_ivec3_get(ivec3 v) { return v; } -vec3 hd_vec3_get(hd_vec3 v) { return vec3(v.x, v.y, v.z); } -vec3 hd_vec3_get(vec3 v) { return v; } -dvec3 hd_dvec3_get(hd_dvec3 v) { return dvec3(v.x, v.y, v.z); } -dvec3 hd_dvec3_get(dvec3 v) { return v; } -mat3 hd_mat3_get(hd_mat3 v) { return mat3(v.m00, v.m01, v.m02, - v.m10, v.m11, v.m12, - v.m20, v.m21, v.m22); } -mat3 hd_mat3_get(mat3 v) { return v; } -dmat3 hd_dmat3_get(hd_dmat3 v) { return dmat3(v.m00, v.m01, v.m02, - v.m10, v.m11, v.m12, - v.m20, v.m21, v.m22); } -dmat3 hd_dmat3_get(dmat3 v) { return v; } -hd_ivec3 hd_ivec3_set(hd_ivec3 v) { return v; } -hd_ivec3 hd_ivec3_set(ivec3 v) { return hd_ivec3(v.x, v.y, v.z); } -hd_vec3 hd_vec3_set(hd_vec3 v) { return v; } -hd_vec3 hd_vec3_set(vec3 v) { return hd_vec3(v.x, v.y, v.z); } -hd_dvec3 hd_dvec3_set(hd_dvec3 v) { return v; } -hd_dvec3 hd_dvec3_set(dvec3 v) { return hd_dvec3(v.x, v.y, v.z); } -hd_mat3 hd_mat3_set(hd_mat3 v) { return v; } -hd_mat3 hd_mat3_set(mat3 v) { return hd_mat3(v[0][0], v[0][1], v[0][2], - v[1][0], v[1][1], v[1][2], - v[2][0], v[2][1], v[2][2]); } -hd_dmat3 hd_dmat3_set(hd_dmat3 v) { return v; } -hd_dmat3 hd_dmat3_set(dmat3 v) { return hd_dmat3(v[0][0], v[0][1], v[0][2], - v[1][0], v[1][1], v[1][2], - v[2][0], v[2][1], v[2][2]); } -int hd_int_get(int v) { return v; } -int hd_int_get(ivec2 v) { return v.x; } -int hd_int_get(ivec3 v) { return v.x; } -int hd_int_get(ivec4 v) { return v.x; } -vec3 hd_sample_udim(vec2 v) { -vec2 vf = floor(v); -return vec3(v.x - vf.x, v.y - vf.y, clamp(vf.x, 0.0, 10.0) + 10.0 * vf.y); -} -vec4 hd_vec4_2_10_10_10_get(int v) { - ivec4 unpacked = ivec4((v & 0x3ff) << 22, (v & 0xffc00) << 12, - (v & 0x3ff00000) << 2, (v & 0xc0000000)); - return vec4(unpacked) / 2147483647.0; } -int hd_vec4_2_10_10_10_set(vec4 v) { - return ( (int(v.x * 511.0) & 0x3ff) | - ((int(v.y * 511.0) & 0x3ff) << 10) | - ((int(v.z * 511.0) & 0x3ff) << 20) | - ((int(v.w) & 0x1) << 30)); } -vec2 hd_half2_get(uint v) { - return unpackHalf2x16(v); } -uint hd_half2_set(vec2 v) { - return packHalf2x16(v); } -vec4 hd_half4_get(uvec2 v) { - return vec4(unpackHalf2x16(v.x), unpackHalf2x16(v.y)); } -uvec2 hd_half4_set(vec4 v) { - return uvec2(packHalf2x16(v.xy), packHalf2x16(v.zw)); } -#define HD_NUM_PATCH_VERTS 4 -#define HD_NUM_PATCH_EVAL_VERTS 4 -#define HD_NUM_PRIMITIVE_VERTS 3 -#define HD_HAS_transform 1 -#define HD_HAS_transformInverse 1 -#define HD_HAS_color 1 -#define HD_HAS_primID 1 -#define HD_HAS_widths 1 -#define HD_INSTANCER_NUM_LEVELS 0 -#define HD_INSTANCE_INDEX_WIDTH 1 -#define HD_HAS_faceVisibility 1 -#define HD_HAS_points 1 -#define HD_HAS_normals 1 - - -// //////// Global Includes //////// - -// //////// Global Macros //////// - -// //////// Global Structs //////// - -// //////// Global Member Declarations //////// -uint hd_VertexID = gl_VertexID; -uint hd_InstanceID = gl_InstanceID; -uint hd_BaseInstance = 0; - -// //////// Global Function Definitions //////// - - -// //////// Codegen Decl //////// -struct hd_drawingCoord { - int modelCoord; - int constantCoord; - int elementCoord; - int primitiveCoord; - int fvarCoord; - int shaderCoord; - int vertexCoord; - int topologyVisibilityCoord; - int varyingCoord; - int instanceIndex[HD_INSTANCE_INDEX_WIDTH]; - int instanceCoords[HD_INSTANCE_INDEX_WIDTH]; -}; -FORWARD_DECL(hd_drawingCoord GetDrawingCoord()); -FORWARD_DECL(int HgiGetBaseVertex()); -struct hd_instanceIndex { int indices[HD_INSTANCE_INDEX_WIDTH]; }; -struct ConstantData10 { - mat4 transform; - mat4 transformInverse; - vec4 color; - vec4 primID; - float widths; -}; -FORWARD_DECL(int GetElementID()); -FORWARD_DECL(int GetAggregatedElementID()); -FORWARD_DECL(int GetPrimitiveEdgeId()); -FORWARD_DECL(float GetSelectedEdgeOpacity()); -layout (location = 2) in ivec4 drawingCoord0; -layout (location = 3) in ivec4 drawingCoord1; -layout (location = 4) in ivec2 drawingCoord2; -layout (location = 0) in vec3 points; -layout (location = 1) in vec3 normals; -out flat int vs_dc_modelCoord; -out flat int vs_dc_constantCoord; -out flat int vs_dc_elementCoord; -out flat int vs_dc_primitiveCoord; -out flat int vs_dc_fvarCoord; -out flat int vs_dc_shaderCoord; -out flat int vs_dc_vertexCoord; -out flat int vs_dc_topologyVisibilityCoord; -out flat int vs_dc_varyingCoord; -out flat int vs_dc_instanceIndexI0; -out flat int vs_dc_instanceCoordsI0; -layout(location = 0) uniform ConstantData10 *constantPrimvars; -layout(location = 1) uniform float *faceVisibility; -out CurveVertexData { - vec4 Peye; -} outData; -out PrimvarData { - vec3 points; - vec3 normals; -} outPrimvars; - -// //////// Codegen Accessors //////// -mat4 HdGet_transform(int localIndex) { - int index = GetDrawingCoord().constantCoord; - return mat4(constantPrimvars[index].transform); -} -mat4 HdGet_transform() { return HdGet_transform(0); } -mat4 HdGet_transformInverse(int localIndex) { - int index = GetDrawingCoord().constantCoord; - return mat4(constantPrimvars[index].transformInverse); -} -mat4 HdGet_transformInverse() { return HdGet_transformInverse(0); } -vec4 HdGet_color(int localIndex) { - int index = GetDrawingCoord().constantCoord; - return vec4(constantPrimvars[index].color); -} -vec4 HdGet_color() { return HdGet_color(0); } -float HdGetScalar_color(int localIndex) { return HdGet_color(localIndex).x; } -float HdGetScalar_color() { return HdGet_color(0).x; } -vec4 HdGet_primID(int localIndex) { - int index = GetDrawingCoord().constantCoord; - return vec4(constantPrimvars[index].primID); -} -vec4 HdGet_primID() { return HdGet_primID(0); } -float HdGetScalar_primID(int localIndex) { return HdGet_primID(localIndex).x; } -float HdGetScalar_primID() { return HdGet_primID(0).x; } -float HdGet_widths(int localIndex) { - int index = GetDrawingCoord().constantCoord; - return float(constantPrimvars[index].widths); -} -float HdGet_widths() { return HdGet_widths(0); } -float HdGetScalar_widths(int localIndex) { return HdGet_widths(localIndex); } -float HdGetScalar_widths() { return HdGet_widths(0); } - -// //////// Codegen VS Source //////// -#define HD_BINDLESS_BUFFERS_ENABLED -int GetBaseVertexOffset() { - return HgiGetBaseVertex(); -} -hd_instanceIndex GetInstanceIndex() { hd_instanceIndex r; r.indices[0] = 0; return r; } -hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = drawingCoord0.x; - dc.constantCoord = drawingCoord0.y; - dc.elementCoord = drawingCoord0.z; - dc.primitiveCoord = drawingCoord0.w; - dc.fvarCoord = drawingCoord1.x; - dc.shaderCoord = drawingCoord1.z; - dc.vertexCoord = drawingCoord1.w; - dc.topologyVisibilityCoord = drawingCoord2.x; - dc.varyingCoord = drawingCoord2.y; - hd_instanceIndex r = GetInstanceIndex(); - dc.instanceIndex[0] = r.indices[0]; - return dc; -} -vec3 HdGet_points(int localIndex) { return hd_vec3_get(points);} -vec3 HdGet_points() { return HdGet_points(0); } -float HdGetScalar_points(int localIndex) { return HdGet_points(localIndex).x; } -float HdGetScalar_points() { return HdGet_points(0).x; } -vec3 HdGet_normals(int localIndex) { return hd_vec3_get(normals);} -vec3 HdGet_normals() { return HdGet_normals(0); } -float HdGetScalar_normals(int localIndex) { return HdGet_normals(localIndex).x; } -float HdGetScalar_normals() { return HdGet_normals(0).x; } - -// //////// Codegen Proc VS //////// -void ProcessPrimvarsIn() { - hd_drawingCoord dc = GetDrawingCoord(); - vs_dc_modelCoord = dc.modelCoord; - vs_dc_constantCoord = dc.constantCoord; - vs_dc_elementCoord = dc.elementCoord; - vs_dc_primitiveCoord = dc.primitiveCoord; - vs_dc_fvarCoord = dc.fvarCoord; - vs_dc_shaderCoord = dc.shaderCoord; - vs_dc_vertexCoord = dc.vertexCoord; - vs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - vs_dc_varyingCoord = dc.varyingCoord; - vs_dc_instanceIndexI0 = dc.instanceIndex[0]; - outPrimvars.points = points; - outPrimvars.normals = normals; -} - -// --------------------------------------------------------------------------- -// global defines -// --------------------------------------------------------------------------- -// codeGen can override this range (currently not). -// quadro 4000's max is 189. -#ifndef HD_GL_POINT_SIZE_MAX -#define HD_GL_POINT_SIZE_MAX 100.0 -#endif -#ifndef HD_GL_POINT_SIZE_MIN -#define HD_GL_POINT_SIZE_MIN .45 -#endif - -// --------------------------------------------------------------------------- -// render pass states -// --------------------------------------------------------------------------- - -MAT4 GetWorldToViewMatrix() { -#if defined(HD_HAS_worldToViewMatrix) - return MAT4(HdGet_worldToViewMatrix()); -#else - return MAT4(1); -#endif -} -MAT4 GetWorldToViewInverseMatrix() { -#if defined(HD_HAS_worldToViewInverseMatrix) - return MAT4(HdGet_worldToViewInverseMatrix()); -#else - return MAT4(1); -#endif -} -MAT4 GetProjectionMatrix() { -#if defined(HD_HAS_projectionMatrix) - return MAT4(HdGet_projectionMatrix()); -#else - return MAT4(1); -#endif -} -vec3 GetPositionInWorldSpace(vec3 windowRelativeCoord) -{ -#if defined(HD_HAS_imageToWorldMatrix) - vec4 pImage = vec4(windowRelativeCoord, 1.0); - vec4 pWorld = vec4(HdGet_imageToWorldMatrix() * pImage); - return (pWorld / pWorld.w).xyz; -#else - return windowRelativeCoord; -#endif -} -float GetLightingBlendAmount() { -#if defined(HD_HAS_lightingBlendAmount) - return HdGet_lightingBlendAmount(); -#else - return 1; -#endif -} -vec4 GetViewport() { -#if defined(HD_HAS_viewport) - return HdGet_viewport(); -#else - return vec4(0,0,1,1); -#endif -} -float GetTessLevel() { -#if defined(HD_HAS_tessLevel) - return HdGet_tessLevel(); -#else - return 1; -#endif -} -float GetPointSize() { -#if defined(HD_HAS_pointSize) - return HdGet_pointSize(); -#else - return 3.0; -#endif -} -float GetPointSelectedSize() { -#if defined(HD_HAS_pointSelectedSize) - return HdGet_pointSelectedSize(); -#else - return 5.0; -#endif -} -vec4 GetWireframeColor() { -// Individual prims can specify an alternative wireframe color -// to one specified in the render pass. This is used in cases were -// there is not enough contrast with the normal one. -#if defined(HD_HAS_overrideWireframeColor) - return HdGet_overrideWireframeColor(); -#elif defined(HD_HAS_wireframeColor) - return HdGet_wireframeColor(); -#else - return vec4(0,0,0,0); -#endif -} -vec4 GetMaskColor() { -#if defined(HD_HAS_maskColor) - return HdGet_maskColor(); -#else - return vec4(0.5,0,0,1); -#endif -} -vec4 GetIndicatorColor() { -#if defined(HD_HAS_indicatorColor) - return HdGet_indicatorColor(); -#else - return vec4(0,0.5,0,1); -#endif -} - -bool ShouldDiscardByAlpha(vec4 color) -{ -#if defined(HD_HAS_alphaThreshold) - float alphaThreshold = HdGet_alphaThreshold(); -#else - float alphaThreshold = 0; -#endif - return (color.a < alphaThreshold); -} - -vec2 ApplyAxisAlignedAffineTransform(vec4 t, vec2 pt) -{ - return t.xy * pt + t.zw; -} - - - -void ApplyClipPlanes(vec4 Peye) -{ -#if defined(HD_HAS_numClipPlanes) -#if defined(HD_HAS_clipPlanes) - for (int i=0; i> 2); -} -int GetAggregatedElementID() { - return GetElementID() - + GetDrawingCoord().elementCoord; -} -int HdGet_edgeIndices(int localIndex) { - int index = GetPrimitiveIndex(); - return int(edgeIndices[index]); -} -int HdGet_edgeIndices() { return HdGet_edgeIndices(0); } -int HdGetScalar_edgeIndices(int localIndex) { return HdGet_edgeIndices(localIndex); } -int HdGetScalar_edgeIndices() { return HdGet_edgeIndices(0); } -int GetAuthoredEdgeId(int primitiveEdgeId) { - return primitiveEdgeId; -} -float HdGet_faceVisibility(int localIndex) { - int index = GetAggregatedElementID(); - return float(faceVisibility[index]); -} -float HdGet_faceVisibility() { return HdGet_faceVisibility(0); } -float HdGetScalar_faceVisibility(int localIndex) { return HdGet_faceVisibility(localIndex); } -float HdGetScalar_faceVisibility() { return HdGet_faceVisibility(0); } -vec3 HdGet_points(int localIndex) { - int index = localIndex; - return vec3(inPrimvars[index].points); -} -vec3 HdGet_points() { return HdGet_points(0); } -float HdGetScalar_points(int localIndex) { return HdGet_points(localIndex).x; } -float HdGetScalar_points() { return HdGet_points(0).x; } -vec3 HdGet_normals(int localIndex) { - int index = localIndex; - return vec3(inPrimvars[index].normals); -} -vec3 HdGet_normals() { return HdGet_normals(0); } -float HdGetScalar_normals(int localIndex) { return HdGet_normals(localIndex).x; } -float HdGetScalar_normals() { return HdGet_normals(0).x; } -vec2 HdGet_dispTextureCoord_Coarse(int localIndex) { - int fvarIndex = GetFVarIndex(localIndex); - return vec2(dispTextureCoord[fvarIndex]); -} -vec2 HdGet_dispTextureCoord(int localIndex, vec2 st) { - return (HdGet_dispTextureCoord_Coarse(0) * (1-st.x-st.y) + HdGet_dispTextureCoord_Coarse(1) * st.x + HdGet_dispTextureCoord_Coarse(2) * st.y); -} -FORWARD_DECL(vec4 GetPatchCoord(int index)); -FORWARD_DECL(vec2 GetPatchCoordLocalST()); -vec2 HdGet_dispTextureCoord(int localIndex) { - vec2 localST = GetPatchCoord(localIndex).xy; - return HdGet_dispTextureCoord(localIndex, localST); -} -vec2 HdGet_dispTextureCoord() { return HdGet_dispTextureCoord(0); } -FORWARD_DECL(vec4 GetPatchCoord(int localIndex)); -void ProcessSamplingTransforms(MAT4 instanceModelViewInverse) { -} - -// //////// Codegen Proc GS //////// -FORWARD_DECL(vec4 GetPatchCoord(int index)); -void ProcessPrimvarsOut(int index) { - vec2 localST = GetPatchCoord(index).xy; - const vec3 coords[3] = vec3[]( - vec3(1,0,0), vec3(0,1,0), vec3(0,0,1) - ); - hd_barycentricCoord = coords[index]; - hd_drawingCoord dc = GetDrawingCoord(); - gs_dc_modelCoord = dc.modelCoord; - gs_dc_constantCoord = dc.constantCoord; - gs_dc_elementCoord = dc.elementCoord; - gs_dc_primitiveCoord = dc.primitiveCoord; - gs_dc_fvarCoord = dc.fvarCoord; - gs_dc_shaderCoord = dc.shaderCoord; - gs_dc_vertexCoord = dc.vertexCoord; - gs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - gs_dc_varyingCoord = dc.varyingCoord; - gs_dc_instanceIndexI0 = dc.instanceIndex[0]; - outPrimvars.points = inPrimvars[index].points; - outPrimvars.normals = inPrimvars[index].normals; - outPrimvars.dispTextureCoord = HdGet_dispTextureCoord(index); -} - -// --------------------------------------------------------------------------- -// global defines -// --------------------------------------------------------------------------- -// codeGen can override this range (currently not). -// quadro 4000's max is 189. -#ifndef HD_GL_POINT_SIZE_MAX -#define HD_GL_POINT_SIZE_MAX 100.0 -#endif -#ifndef HD_GL_POINT_SIZE_MIN -#define HD_GL_POINT_SIZE_MIN .45 -#endif - -// --------------------------------------------------------------------------- -// render pass states -// --------------------------------------------------------------------------- - -MAT4 GetWorldToViewMatrix() { -#if defined(HD_HAS_worldToViewMatrix) - return MAT4(HdGet_worldToViewMatrix()); -#else - return MAT4(1); -#endif -} -MAT4 GetWorldToViewInverseMatrix() { -#if defined(HD_HAS_worldToViewInverseMatrix) - return MAT4(HdGet_worldToViewInverseMatrix()); -#else - return MAT4(1); -#endif -} -MAT4 GetProjectionMatrix() { -#if defined(HD_HAS_projectionMatrix) - return MAT4(HdGet_projectionMatrix()); -#else - return MAT4(1); -#endif -} -vec3 GetPositionInWorldSpace(vec3 windowRelativeCoord) -{ -#if defined(HD_HAS_imageToWorldMatrix) - vec4 pImage = vec4(windowRelativeCoord, 1.0); - vec4 pWorld = vec4(HdGet_imageToWorldMatrix() * pImage); - return (pWorld / pWorld.w).xyz; -#else - return windowRelativeCoord; -#endif -} -float GetLightingBlendAmount() { -#if defined(HD_HAS_lightingBlendAmount) - return HdGet_lightingBlendAmount(); -#else - return 1; -#endif -} -vec4 GetViewport() { -#if defined(HD_HAS_viewport) - return HdGet_viewport(); -#else - return vec4(0,0,1,1); -#endif -} -float GetTessLevel() { -#if defined(HD_HAS_tessLevel) - return HdGet_tessLevel(); -#else - return 1; -#endif -} -float GetPointSize() { -#if defined(HD_HAS_pointSize) - return HdGet_pointSize(); -#else - return 3.0; -#endif -} -float GetPointSelectedSize() { -#if defined(HD_HAS_pointSelectedSize) - return HdGet_pointSelectedSize(); -#else - return 5.0; -#endif -} -vec4 GetWireframeColor() { -// Individual prims can specify an alternative wireframe color -// to one specified in the render pass. This is used in cases were -// there is not enough contrast with the normal one. -#if defined(HD_HAS_overrideWireframeColor) - return HdGet_overrideWireframeColor(); -#elif defined(HD_HAS_wireframeColor) - return HdGet_wireframeColor(); -#else - return vec4(0,0,0,0); -#endif -} -vec4 GetMaskColor() { -#if defined(HD_HAS_maskColor) - return HdGet_maskColor(); -#else - return vec4(0.5,0,0,1); -#endif -} -vec4 GetIndicatorColor() { -#if defined(HD_HAS_indicatorColor) - return HdGet_indicatorColor(); -#else - return vec4(0,0.5,0,1); -#endif -} - -bool ShouldDiscardByAlpha(vec4 color) -{ -#if defined(HD_HAS_alphaThreshold) - float alphaThreshold = HdGet_alphaThreshold(); -#else - float alphaThreshold = 0; -#endif - return (color.a < alphaThreshold); -} - -vec2 ApplyAxisAlignedAffineTransform(vec4 t, vec2 pt) -{ - return t.xy * pt + t.zw; -} - - - -void ApplyClipPlanes(vec4 Peye) -{ -#if defined(HD_HAS_numClipPlanes) -#if defined(HD_HAS_clipPlanes) - for (int i=0; i 0.0) - normal = normalize(normal); - return normal; -} - -vec3 GetNormal(vec3 Neye, int index, vec2 localST) -{ - return GetNormal(Neye, index); -} - - - -vec3 GetTriGeometryNormal(vec3 Neye, vec4 Peye0, vec4 Peye1, vec4 Peye2, - bool isFlipped) -{ - return Neye; -} - -vec3 GetQuadGeometryNormal(vec3 Neye, - vec4 Peye0, vec4 Peye1, vec4 Peye2, vec4 Peye3, - bool isFlipped) -{ - return Neye; -} - - - -vec4 DisplacementTerminal(int index, vec4 Peye, vec3 Neye, vec4 patchCoord) -{ - return Peye; -} - - - -vec4 GetPatchCoord(int index) -{ - vec2 uv[3]; - uv[0] = vec2(0, 0); // (0, 0, 1); - uv[1] = vec2(1, 0); // (1, 0, 0); - uv[2] = vec2(0, 1); // (0, 1, 0); - - ivec3 patchParam = GetPatchParam(); - return InterpolatePatchCoordTriangle(uv[index], patchParam); -} - -void emit(int index, vec4 Peye, vec3 Neye) -{ - outData.Peye = Peye; - outData.Neye = Neye; - - gsPatchCoord = GetPatchCoord(index); - - gl_Position = vec4(GetProjectionMatrix() * outData.Peye); - ApplyClipPlanes(outData.Peye); - - ProcessPrimvarsOut(index); - - EmitVertex(); -} - -void main(void) -{ - gl_PrimitiveID = gl_PrimitiveIDIn; - - bool isFlipped = IsFlipped(); // consider handedness AND negative-scale - - vec3 Neye0 = GetNormal(inData[0].Neye, 0); - Neye0 = GetTriGeometryNormal(Neye0, inData[0].Peye, inData[1].Peye, - inData[2].Peye, isFlipped); - vec3 Neye1 = GetNormal(inData[1].Neye, 1); - Neye1 = GetTriGeometryNormal(Neye1, inData[0].Peye, inData[1].Peye, - inData[2].Peye, isFlipped); - vec3 Neye2 = GetNormal(inData[2].Neye, 2); - Neye2 = GetTriGeometryNormal(Neye2, inData[0].Peye, inData[1].Peye, - inData[2].Peye, isFlipped); - - vec4 Peye0 = DisplacementTerminal( - 0, inData[0].Peye, Neye0, GetPatchCoord(0)); - vec4 Peye1 = DisplacementTerminal( - 1, inData[1].Peye, Neye1, GetPatchCoord(1)); - vec4 Peye2 = DisplacementTerminal( - 2, inData[2].Peye, Neye2, GetPatchCoord(2)); - - // triangle 0: vertices (0,1,2) - emit(0, Peye0, Neye0); - emit(1, Peye1, Neye1); - emit(2, Peye2, Neye2); - - EndPrimitive(); -} - - -======================================================= - FRAGMENT SHADER -======================================================= -#version 450 -#extension GL_NV_shader_buffer_load : require -#extension GL_NV_gpu_shader5 : require -#extension GL_ARB_bindless_texture : require -#define REF(space,type) inout type -#define FORWARD_DECL(func_decl) func_decl; -#define ATOMIC_LOAD(a) (a) -#define ATOMIC_STORE(a, v) (a) = (v) -#define ATOMIC_ADD(a, v) atomicAdd(a, v) -#define ATOMIC_EXCHANGE(a, v) atomicExchange(a, v) -#define ATOMIC_COMP_SWAP(a, expected, desired) atomicCompSwap(a, expected, desired) -#define atomic_int int -#define atomic_uint uint - -#define HGI_HAS_DOUBLE_TYPE 1 - - -struct hgi_ivec3 { int x, y, z; }; -struct hgi_vec3 { float x, y, z; }; -struct hgi_dvec3 { double x, y, z; }; -struct hgi_mat3 { float m00, m01, m02, - m10, m11, m12, - m20, m21, m22; }; -struct hgi_dmat3 { double m00, m01, m02, - m10, m11, m12, - m20, m21, m22; }; - - - -// //////// Global Includes //////// - -// //////// Global Macros //////// - -// //////// Global Structs //////// - -// //////// Global Member Declarations //////// - -// //////// Global Function Definitions //////// - - -// //////// Codegen Defines //////// -#define HD_SHADER_API 2 -#define MAT4 mat4 -// Alias hgi vec and matrix types to hd. -#define hd_ivec3 hgi_ivec3 -#define hd_vec3 hgi_vec3 -#define hd_dvec3 hgi_dvec3 -#define hd_mat3 hgi_mat3 -#define hd_dmat3 hgi_dmat3 - -ivec3 hd_ivec3_get(hd_ivec3 v) { return ivec3(v.x, v.y, v.z); } -ivec3 hd_ivec3_get(ivec3 v) { return v; } -vec3 hd_vec3_get(hd_vec3 v) { return vec3(v.x, v.y, v.z); } -vec3 hd_vec3_get(vec3 v) { return v; } -dvec3 hd_dvec3_get(hd_dvec3 v) { return dvec3(v.x, v.y, v.z); } -dvec3 hd_dvec3_get(dvec3 v) { return v; } -mat3 hd_mat3_get(hd_mat3 v) { return mat3(v.m00, v.m01, v.m02, - v.m10, v.m11, v.m12, - v.m20, v.m21, v.m22); } -mat3 hd_mat3_get(mat3 v) { return v; } -dmat3 hd_dmat3_get(hd_dmat3 v) { return dmat3(v.m00, v.m01, v.m02, - v.m10, v.m11, v.m12, - v.m20, v.m21, v.m22); } -dmat3 hd_dmat3_get(dmat3 v) { return v; } -hd_ivec3 hd_ivec3_set(hd_ivec3 v) { return v; } -hd_ivec3 hd_ivec3_set(ivec3 v) { return hd_ivec3(v.x, v.y, v.z); } -hd_vec3 hd_vec3_set(hd_vec3 v) { return v; } -hd_vec3 hd_vec3_set(vec3 v) { return hd_vec3(v.x, v.y, v.z); } -hd_dvec3 hd_dvec3_set(hd_dvec3 v) { return v; } -hd_dvec3 hd_dvec3_set(dvec3 v) { return hd_dvec3(v.x, v.y, v.z); } -hd_mat3 hd_mat3_set(hd_mat3 v) { return v; } -hd_mat3 hd_mat3_set(mat3 v) { return hd_mat3(v[0][0], v[0][1], v[0][2], - v[1][0], v[1][1], v[1][2], - v[2][0], v[2][1], v[2][2]); } -hd_dmat3 hd_dmat3_set(hd_dmat3 v) { return v; } -hd_dmat3 hd_dmat3_set(dmat3 v) { return hd_dmat3(v[0][0], v[0][1], v[0][2], - v[1][0], v[1][1], v[1][2], - v[2][0], v[2][1], v[2][2]); } -int hd_int_get(int v) { return v; } -int hd_int_get(ivec2 v) { return v.x; } -int hd_int_get(ivec3 v) { return v.x; } -int hd_int_get(ivec4 v) { return v.x; } -vec3 hd_sample_udim(vec2 v) { -vec2 vf = floor(v); -return vec3(v.x - vf.x, v.y - vf.y, clamp(vf.x, 0.0, 10.0) + 10.0 * vf.y); -} -vec4 hd_vec4_2_10_10_10_get(int v) { - ivec4 unpacked = ivec4((v & 0x3ff) << 22, (v & 0xffc00) << 12, - (v & 0x3ff00000) << 2, (v & 0xc0000000)); - return vec4(unpacked) / 2147483647.0; } -int hd_vec4_2_10_10_10_set(vec4 v) { - return ( (int(v.x * 511.0) & 0x3ff) | - ((int(v.y * 511.0) & 0x3ff) << 10) | - ((int(v.z * 511.0) & 0x3ff) << 20) | - ((int(v.w) & 0x1) << 30)); } -vec2 hd_half2_get(uint v) { - return unpackHalf2x16(v); } -uint hd_half2_set(vec2 v) { - return packHalf2x16(v); } -vec4 hd_half4_get(uvec2 v) { - return vec4(unpackHalf2x16(v.x), unpackHalf2x16(v.y)); } -uvec2 hd_half4_set(vec4 v) { - return uvec2(packHalf2x16(v.xy), packHalf2x16(v.zw)); } -#define HD_NUM_PRIMITIVE_VERTS 3 -#define HD_HAS_transform 1 -#define HD_HAS_transformInverse 1 -#define HD_HAS_color 1 -#define HD_HAS_primID 1 -#define HD_HAS_widths 1 -#define HD_INSTANCER_NUM_LEVELS 0 -#define HD_INSTANCE_INDEX_WIDTH 1 -#define HD_HAS_faceVisibility 1 -#define HD_HAS_dispTextureCoord 1 -#define HD_HAS_points 1 -#define HD_HAS_normals 1 - -// //////// Codegen Decl //////// -struct hd_drawingCoord { - int modelCoord; - int constantCoord; - int elementCoord; - int primitiveCoord; - int fvarCoord; - int shaderCoord; - int vertexCoord; - int topologyVisibilityCoord; - int varyingCoord; - int instanceIndex[HD_INSTANCE_INDEX_WIDTH]; - int instanceCoords[HD_INSTANCE_INDEX_WIDTH]; -}; -FORWARD_DECL(hd_drawingCoord GetDrawingCoord()); -FORWARD_DECL(int HgiGetBaseVertex()); -struct hd_instanceIndex { int indices[HD_INSTANCE_INDEX_WIDTH]; }; -struct ConstantData10 { - mat4 transform; - mat4 transformInverse; - vec4 color; - vec4 primID; - float widths; -}; -FORWARD_DECL(int GetElementID()); -FORWARD_DECL(int GetAggregatedElementID()); -FORWARD_DECL(int GetPrimitiveEdgeId()); -FORWARD_DECL(float GetSelectedEdgeOpacity()); -layout(location = 0) uniform ConstantData10 *constantPrimvars; -layout(location = 1) uniform int *primitiveParam; -layout(location = 2) uniform int *edgeIndices; -layout(location = 3) uniform float *faceVisibility; -in vec4 gsPatchCoord; -in VertexData { - vec4 Peye; - vec3 Neye; -} inData; -layout (location = 0) out vec4 colorOut; -in noperspective vec3 hd_barycentricCoord; -in PrimvarData { - vec3 points; - vec3 normals; - vec2 dispTextureCoord; -} inPrimvars; -in flat int gs_dc_modelCoord; -in flat int gs_dc_constantCoord; -in flat int gs_dc_elementCoord; -in flat int gs_dc_primitiveCoord; -in flat int gs_dc_fvarCoord; -in flat int gs_dc_shaderCoord; -in flat int gs_dc_vertexCoord; -in flat int gs_dc_topologyVisibilityCoord; -in flat int gs_dc_varyingCoord; -in flat int gs_dc_instanceIndexI0; -in flat int gs_dc_instanceCoordsI0; -layout(location = 4) uniform vec2 *dispTextureCoord; -vec4 InterpolatePatchCoord(vec2 uv, ivec3 patchParam) -{ - // add 0.5 to integer values for more robust interpolation - return vec4(uv.x, uv.y, 0, patchParam.x+0.5f); -} -vec4 InterpolatePatchCoordTriangle(vec2 uv, ivec3 patchParam) -{ - return InterpolatePatchCoord(uv, patchParam); -} - -// //////// Codegen Accessors //////// -mat4 HdGet_transform(int localIndex) { - int index = GetDrawingCoord().constantCoord; - return mat4(constantPrimvars[index].transform); -} -mat4 HdGet_transform() { return HdGet_transform(0); } -mat4 HdGet_transformInverse(int localIndex) { - int index = GetDrawingCoord().constantCoord; - return mat4(constantPrimvars[index].transformInverse); -} -mat4 HdGet_transformInverse() { return HdGet_transformInverse(0); } -vec4 HdGet_color(int localIndex) { - int index = GetDrawingCoord().constantCoord; - return vec4(constantPrimvars[index].color); -} -vec4 HdGet_color() { return HdGet_color(0); } -float HdGetScalar_color(int localIndex) { return HdGet_color(localIndex).x; } -float HdGetScalar_color() { return HdGet_color(0).x; } -vec4 HdGet_primID(int localIndex) { - int index = GetDrawingCoord().constantCoord; - return vec4(constantPrimvars[index].primID); -} -vec4 HdGet_primID() { return HdGet_primID(0); } -float HdGetScalar_primID(int localIndex) { return HdGet_primID(localIndex).x; } -float HdGetScalar_primID() { return HdGet_primID(0).x; } -float HdGet_widths(int localIndex) { - int index = GetDrawingCoord().constantCoord; - return float(constantPrimvars[index].widths); -} -float HdGet_widths() { return HdGet_widths(0); } -float HdGetScalar_widths(int localIndex) { return HdGet_widths(localIndex); } -float HdGetScalar_widths() { return HdGet_widths(0); } - -// //////// Codegen FS Source //////// -#define HD_SHADER_SUPPORTS_DOUBLE_PRECISION -#define HD_MINUS_ONE_TO_ONE_DEPTH_RANGE -vec3 GetBarycentricCoord() { - return hd_barycentricCoord; -} -int GetPrimitiveID() { - return gl_PrimitiveID; -} -int GetPrimitiveIndex() { - return GetDrawingCoord().primitiveCoord + GetPrimitiveID(); -} -hd_drawingCoord GetDrawingCoord() { - hd_drawingCoord dc; - dc.modelCoord = gs_dc_modelCoord; - dc.constantCoord = gs_dc_constantCoord; - dc.elementCoord = gs_dc_elementCoord; - dc.primitiveCoord = gs_dc_primitiveCoord; - dc.fvarCoord = gs_dc_fvarCoord; - dc.shaderCoord = gs_dc_shaderCoord; - dc.vertexCoord = gs_dc_vertexCoord; - dc.topologyVisibilityCoord = gs_dc_topologyVisibilityCoord; - dc.varyingCoord = gs_dc_varyingCoord; - dc.instanceIndex[0] = gs_dc_instanceIndexI0; - return dc; -} -int HdGet_primitiveParam(int localIndex) { - int index = GetPrimitiveIndex(); - return int(primitiveParam[index]); -} -int HdGet_primitiveParam() { return HdGet_primitiveParam(0); } -int HdGetScalar_primitiveParam(int localIndex) { return HdGet_primitiveParam(localIndex); } -int HdGetScalar_primitiveParam() { return HdGet_primitiveParam(0); } -#if defined(HD_HAS_coarseFaceIndex) -FORWARD_DECL(int HdGetScalar_coarseFaceIndex()); -#endif -ivec3 GetPatchParam() { -#if defined(HD_HAS_coarseFaceIndex) - return ivec3(HdGetScalar_coarseFaceIndex(), 0, 0); -#else - return ivec3(GetPrimitiveID(), 0, 0); -#endif -} -int GetEdgeFlag() { - return (HdGet_primitiveParam() & 3); -} -int GetFVarIndex(int localIndex) { - int fvarCoord = GetDrawingCoord().fvarCoord; - int ptexIndex = GetPatchParam().x & 0xfffffff; - return fvarCoord + ptexIndex * 3 + localIndex; -} -int GetElementID() { - return (hd_int_get(HdGet_primitiveParam()) >> 2); -} -int GetAggregatedElementID() { - return GetElementID() - + GetDrawingCoord().elementCoord; -} -int HdGet_edgeIndices(int localIndex) { - int index = GetPrimitiveIndex(); - return int(edgeIndices[index]); -} -int HdGet_edgeIndices() { return HdGet_edgeIndices(0); } -int HdGetScalar_edgeIndices(int localIndex) { return HdGet_edgeIndices(localIndex); } -int HdGetScalar_edgeIndices() { return HdGet_edgeIndices(0); } -int GetAuthoredEdgeId(int primitiveEdgeId) { - return primitiveEdgeId; -} -float HdGet_faceVisibility(int localIndex) { - int index = GetAggregatedElementID(); - return float(faceVisibility[index]); -} -float HdGet_faceVisibility() { return HdGet_faceVisibility(0); } -float HdGetScalar_faceVisibility(int localIndex) { return HdGet_faceVisibility(localIndex); } -float HdGetScalar_faceVisibility() { return HdGet_faceVisibility(0); } -vec3 HdGet_points(int localIndex) { return vec3(inPrimvars.points);} -vec3 HdGet_points() { return HdGet_points(0); } -float HdGetScalar_points(int localIndex) { return HdGet_points(localIndex).x; } -float HdGetScalar_points() { return HdGet_points(0).x; } -vec3 HdGet_normals(int localIndex) { return vec3(inPrimvars.normals);} -vec3 HdGet_normals() { return HdGet_normals(0); } -float HdGetScalar_normals(int localIndex) { return HdGet_normals(localIndex).x; } -float HdGetScalar_normals() { return HdGet_normals(0).x; } -vec2 HdGet_dispTextureCoord(int localIndex) { return vec2(inPrimvars.dispTextureCoord);} -vec2 HdGet_dispTextureCoord() { return HdGet_dispTextureCoord(0); } -float HdGetScalar_dispTextureCoord(int localIndex) { return HdGet_dispTextureCoord(localIndex).x; } -float HdGetScalar_dispTextureCoord() { return HdGet_dispTextureCoord(0).x; } -FORWARD_DECL(vec4 GetPatchCoord(int index)); -void ProcessSamplingTransforms(MAT4 instanceModelViewInverse) { -} - -// --------------------------------------------------------------------------- -// global defines -// --------------------------------------------------------------------------- -// codeGen can override this range (currently not). -// quadro 4000's max is 189. -#ifndef HD_GL_POINT_SIZE_MAX -#define HD_GL_POINT_SIZE_MAX 100.0 -#endif -#ifndef HD_GL_POINT_SIZE_MIN -#define HD_GL_POINT_SIZE_MIN .45 -#endif - -// --------------------------------------------------------------------------- -// render pass states -// --------------------------------------------------------------------------- - -MAT4 GetWorldToViewMatrix() { -#if defined(HD_HAS_worldToViewMatrix) - return MAT4(HdGet_worldToViewMatrix()); -#else - return MAT4(1); -#endif -} -MAT4 GetWorldToViewInverseMatrix() { -#if defined(HD_HAS_worldToViewInverseMatrix) - return MAT4(HdGet_worldToViewInverseMatrix()); -#else - return MAT4(1); -#endif -} -MAT4 GetProjectionMatrix() { -#if defined(HD_HAS_projectionMatrix) - return MAT4(HdGet_projectionMatrix()); -#else - return MAT4(1); -#endif -} -vec3 GetPositionInWorldSpace(vec3 windowRelativeCoord) -{ -#if defined(HD_HAS_imageToWorldMatrix) - vec4 pImage = vec4(windowRelativeCoord, 1.0); - vec4 pWorld = vec4(HdGet_imageToWorldMatrix() * pImage); - return (pWorld / pWorld.w).xyz; -#else - return windowRelativeCoord; -#endif -} -float GetLightingBlendAmount() { -#if defined(HD_HAS_lightingBlendAmount) - return HdGet_lightingBlendAmount(); -#else - return 1; -#endif -} -vec4 GetViewport() { -#if defined(HD_HAS_viewport) - return HdGet_viewport(); -#else - return vec4(0,0,1,1); -#endif -} -float GetTessLevel() { -#if defined(HD_HAS_tessLevel) - return HdGet_tessLevel(); -#else - return 1; -#endif -} -float GetPointSize() { -#if defined(HD_HAS_pointSize) - return HdGet_pointSize(); -#else - return 3.0; -#endif -} -float GetPointSelectedSize() { -#if defined(HD_HAS_pointSelectedSize) - return HdGet_pointSelectedSize(); -#else - return 5.0; -#endif -} -vec4 GetWireframeColor() { -// Individual prims can specify an alternative wireframe color -// to one specified in the render pass. This is used in cases were -// there is not enough contrast with the normal one. -#if defined(HD_HAS_overrideWireframeColor) - return HdGet_overrideWireframeColor(); -#elif defined(HD_HAS_wireframeColor) - return HdGet_wireframeColor(); -#else - return vec4(0,0,0,0); -#endif -} -vec4 GetMaskColor() { -#if defined(HD_HAS_maskColor) - return HdGet_maskColor(); -#else - return vec4(0.5,0,0,1); -#endif -} -vec4 GetIndicatorColor() { -#if defined(HD_HAS_indicatorColor) - return HdGet_indicatorColor(); -#else - return vec4(0,0.5,0,1); -#endif -} - -bool ShouldDiscardByAlpha(vec4 color) -{ -#if defined(HD_HAS_alphaThreshold) - float alphaThreshold = HdGet_alphaThreshold(); -#else - float alphaThreshold = 0; -#endif - return (color.a < alphaThreshold); -} - -vec2 ApplyAxisAlignedAffineTransform(vec4 t, vec2 pt) -{ - return t.xy * pt + t.zw; -} - - - -vec2 HorizontallyNormalizedFilmbackCoordinates() -{ - const vec4 transform = -#ifdef HD_HAS_imageToHorizontallyNormalizedFilmback - HdGet_imageToHorizontallyNormalizedFilmback(); -#else - vec4(vec2(1.0), vec2(0.0)); -#endif - return ApplyAxisAlignedAffineTransform(transform, gl_FragCoord.xy); -} - - - -vec4 ApplySelectionColor(vec4 color) -{ - return color; -} - - - -// Forward declare selection functionality. -// XXX: Currently, the non-empty implementation of this is in hdx. -FORWARD_DECL(vec4 ApplySelectionColor(vec4 color)); - -// XXX: Make sure to update hdx/shaders/renderPass.glslfx when editing these -// color override methods, since they're currently duplicated. This is because -// we don't have a mixin token for color overrides in a render pass yet. -vec4 ApplyColorOverrides(vec4 color) -{ -#if defined(HD_HAS_overrideColor) - // Mix in override color - vec4 overrideColor = HdGet_overrideColor(); - color.rgb = mix(color.rgb, overrideColor.rgb, overrideColor.a); -#endif - return ApplySelectionColor(color); -} - -vec3 ApplyMaskColor(vec3 color, float weight, vec4 maskColor) -{ - float strength = maskColor.a * clamp(weight, 0.0, 1.0); - return mix(color, maskColor.rgb, strength); -} - -vec4 ApplyColorOverridesPostLighting(vec4 color) -{ - #if defined(HD_HAS_maskWeight) - float maskWeight = HdGet_maskWeight(); - vec4 maskColor = GetMaskColor(); - color.rgb = ApplyMaskColor(color.rgb, maskWeight, maskColor); - #endif - #if defined(HD_HAS_indicatorWeight) - float indicatorWeight = HdGet_indicatorWeight(); - vec4 indicatorColor = GetIndicatorColor(); - color.rgb = ApplyMaskColor(color.rgb, indicatorWeight, indicatorColor); - #endif - return color; -} - - - -void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) -{ - colorOut = color; -} - - -#ifndef HD_HAS_integrateLights -#define HD_HAS_integrateLights -#endif - -struct LightingContribution { - vec3 diffuse; -}; - -struct LightingInterfaceProperties { - float unused; -}; - -LightingContribution -integrateLightsDefault(vec4 Peye, vec3 Neye, LightingInterfaceProperties props) -{ - vec3 n = normalize(Neye); - - LightingContribution result; - result.diffuse = vec3(dot(n, vec3(0,0,1))); - - return result; -} - -LightingContribution -integrateLightsConstant(vec4 Peye, vec3 Neye, LightingInterfaceProperties props) -{ - LightingContribution result; - //pefectly diffuse white hemisphere contribution - result.diffuse = vec3(1); - - return result; -} - - - -FORWARD_DECL( - LightingContribution integrateLights(vec4 Peye, vec3 Neye, - LightingInterfaceProperties props)); - -vec3 FallbackLighting(in vec3 Peye, in vec3 Neye, in vec3 color) -{ - LightingInterfaceProperties props; - LightingContribution light = integrateLights(vec4(Peye, 1), Neye, props); - return color * light.diffuse; -} - - -vec4 surfaceShader(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) -{ - // lighting - color.rgb = FallbackLighting(Peye.xyz, Neye, color.rgb); - return color; -} - - -// quaternion to matrix. xyz = imaginary, w = real -MAT4 GetRotationMatrix(vec4 q) -{ - MAT4 r; - r[0].xyzw = vec4(1 - 2 * (q.y * q.y + q.z * q.z), - 2 * (q.x * q.y + q.z * q.w), - 2 * (q.x * q.z - q.y * q.w), - 0); - r[1].xyzw = vec4( 2 * (q.x * q.y - q.z * q.w), - 1 - 2 * (q.x * q.x + q.z * q.z), - 2 * (q.y * q.z + q.x * q.w), - 0); - r[2].xyzw = vec4( 2 * (q.x * q.z + q.y * q.w), - 2 * (q.y * q.z - q.x * q.w), - 1 - 2 * (q.x * q.x + q.y * q.y), - 0); - r[3] = vec4(0, 0, 0, 1); - return r; -} - -// --------------------------------------------------------------------------- - -MAT4 GetInstanceTransform(int level) -{ - MAT4 m = MAT4(1); -#ifdef HD_HAS_INSTANCE_hydra_instanceTransforms - m = HdGetInstance_hydra_instanceTransforms(level, MAT4(1)) * m; -#elif defined(HD_HAS_INSTANCE_instanceTransform) - m = HdGetInstance_instanceTransform(level, MAT4(1)) * m; -#endif - - // instance transform elements are applied: - // scale then rotate then translate - // i.e. (T * R * S) * position - -#ifdef HD_HAS_INSTANCE_hydra_instanceScales - vec3 s = HdGetInstance_hydra_instanceScales(level, /*default=*/vec3(1)); - m = MAT4(s.x, 0, 0, 0, - 0, s.y, 0, 0, - 0, 0, s.z, 0, - 0, 0, 0, 1) * m; -#elif defined(HD_HAS_INSTANCE_instanceScale) - vec3 s = HdGetInstance_scale(level, /*default=*/vec3(1)); - m = MAT4(s.x, 0, 0, 0, - 0, s.y, 0, 0, - 0, 0, s.z, 0, - 0, 0, 0, 1) * m; -#endif - -#ifdef HD_HAS_INSTANCE_hydra_instanceRotations // GfQuat(ix, iy, iz, real) - vec4 q = HdGetInstance_hydra_instanceRotations(level, /*default=*/vec4(0)); - m = GetRotationMatrix(q) * m; -#elif defined(HD_HAS_INSTANCE_rotate) - vec4 q = HdGetInstance_rotate(level, /*default=*/vec4(0)); - m = GetRotationMatrix(q) * m; -#endif - -#ifdef HD_HAS_INSTANCE_hydra_instanceTranslations - vec3 t = HdGetInstance_hydra_instanceTranslations(level, /*default=*/vec3(0)); - m = MAT4( 1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, 1, 0, - t.x, t.y, t.z, 1) * m; -#elif defined(HD_HAS_INSTANCE_translate) - vec3 t = HdGetInstance_translate(level, /*default=*/vec3(0)); - m = MAT4( 1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, 1, 0, - t.x, t.y, t.z, 1) * m; -#endif - return m; -} - -MAT4 GetInstanceTransformInverse(int level) -{ - MAT4 m = MAT4(1); - -#ifdef HD_HAS_INSTANCE_hydra_instanceTransforms - m = inverse(HdGetInstance_hydra_instanceTransforms(level, MAT4(1))) * m; -#elif defined(HD_HAS_INSTANCE_instanceTransform) - m = inverse(HdGetInstance_instanceTransform(level, MAT4(1))) * m; -#endif - -#ifdef HD_HAS_INSTANCE_hydra_instanceTranslations - vec3 it = -HdGetInstance_hydra_instanceTranslations(level, /*default=*/vec3(0)); // negate - m = MAT4( 1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, 1, 0, - it.x, it.y, it.z, 1) * m; -#elif defined(HD_HAS_INSTANCE_translate) - vec3 it = -HdGetInstance_translate(level, /*default=*/vec3(0)); // negate - m = MAT4( 1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, 1, 0, - it.x, it.y, it.z, 1) * m; -#endif - -#ifdef HD_HAS_INSTANCE_hydra_instanceRotations - vec4 q = HdGetInstance_hydra_instanceRotations(level, /*default=*/vec4(0)); - q.xyz = -q.xyz; // inverse rotataion axis - m = GetRotationMatrix(q) * m; -#elif defined(HD_HAS_INSTANCE_rotate) - vec4 q = HdGetInstance_rotate(level, /*default=*/vec4(0)); - q.xyz = -q.xyz; // inverse rotataion axis - m = GetRotationMatrix(q) * m; -#endif - -#ifdef HD_HAS_INSTANCE_hydra_instanceScales - vec3 is = 1.0/HdGetInstance_hydra_instanceScales(level, /*default=*/vec3(1)); // inverse scale - m = MAT4(is.x, 0, 0, 0, - 0, is.y, 0, 0, - 0, 0, is.z, 0, - 0, 0, 0, 1) * m; -#elif defined(HD_HAS_INSTANCE_scale) - vec3 is = 1.0/HdGetInstance_scale(level, /*default=*/vec3(1)); // inverse scale - m = MAT4(is.x, 0, 0, 0, - 0, is.y, 0, 0, - 0, 0, is.z, 0, - 0, 0, 0, 1) * m; -#endif - return m; -} - -// --------------------------------------------------------------------------- - -MAT4 GetInstanceTransform() -{ - MAT4 m = MAT4(1); -#ifdef HD_INSTANCER_NUM_LEVELS - for (int i = 0; i < HD_INSTANCER_NUM_LEVELS; ++i) { - m = GetInstanceTransform(i) * m; -#ifdef HD_HAS_instancerTransform - m = HdGet_instancerTransform(i) * m; -#endif - } -#endif - return m; -} - -MAT4 GetInstanceTransformInverse() -{ - MAT4 m = MAT4(1); -#ifdef HD_INSTANCER_NUM_LEVELS - for (int i = 0; i < HD_INSTANCER_NUM_LEVELS; ++i) { - m = m * GetInstanceTransformInverse(i); -#ifdef HD_HAS_instancerTransformInverse - m = m * HdGet_instancerTransformInverse(i); -#endif - } -#endif - return m; -} - -// --------------------------------------------------------------------------- - -MAT4 ApplyInstanceTransform(MAT4 m) -{ - return GetInstanceTransform() * m; -} - -MAT4 ApplyInstanceTransformInverse(MAT4 m) -{ - return m * GetInstanceTransformInverse(); -} - -bool IsFlipped() -{ -#if defined(HD_HAS_isFlipped) - bool flip = (HdGet_isFlipped() != 0); -#elif defined(HD_HAS_transform) - // The sign of the determinant indicates whether m flips handedness - bool flip = (determinant(HdGet_transform()) < 0.0); -#else - bool flip = false; -#endif - -#ifdef HD_HAS_INSTANCE_hydra_instanceScales - for (int i = 0; i < HD_INSTANCER_NUM_LEVELS; ++i) { - vec3 scale = HdGetInstance_hydra_instanceScales(i, /*default=*/vec3(1)); - flip = flip != ((sign(scale.x) * sign(scale.y) * sign(scale.z)) < 0); - } -#elif defined(HD_HAS_INSTANCE_scale) - for (int i = 0; i < HD_INSTANCER_NUM_LEVELS; ++i) { - vec3 scale = HdGetInstance_scale(i, /*default=*/vec3(1)); - flip = flip != ((sign(scale.x) * sign(scale.y) * sign(scale.z)) < 0); - } -#endif - -#ifdef HD_HAS_INSTANCE_hydra_instanceTransforms - for (int i = 0; i < HD_INSTANCER_NUM_LEVELS; ++i) { - MAT4 m = HdGetInstance_hydra_instanceTransforms(i, MAT4(1)); - flip = flip != (determinant(m) < 0.0); - } -#elif defined(HD_HAS_INSTANCE_instanceTransform) - for (int i = 0; i < HD_INSTANCER_NUM_LEVELS; ++i) { - MAT4 m = HdGetInstance_instanceTransform(i, MAT4(1)); - flip = flip != (determinant(m) < 0.0); - } -#endif - - return flip; -} - - -vec3 GetNormal(vec3 Neye, int index) -{ - return Neye; -} - -vec3 GetNormal(vec3 Neye, int index, vec2 localST) -{ - return GetNormal(Neye, index); -} - - - -vec3 GetShadingNormal(vec3 N, bool isFlipped) -{ - // the fragment shader takes already-flipped-normals. - // no need to flip here. - return N; -} - - - -void DiscardBasedOnShading(bool frontFacing, bool isFlipped) -{ - // Nothing to do since h/w face culling is used. -} - - - -vec4 ApplyEdgeColor(vec4 Cfill, vec4 patchCoord) -{ - return Cfill; -} - -// Return a large value, signifying that the fragment isn't near an edge. -float GetMinEdgeDistance() -{ - return 1000.0; -} - - - -vec3 GetEdgeParamTriangle() -{ - // Expand barycentric coordinates - vec2 param = GetPatchCoord(0).xy; - vec3 barycentric = vec3(param.x, param.y, 1 - param.x - param.y); - - // Match triangle edge order - return barycentric.yzx; -} - -vec3 GetEdgeDistanceTriangle() -{ - vec3 param = GetEdgeParamTriangle(); - return max(vec3(0.0), param / fwidth(param)); -} - -vec4 GetEdgeParamQuad() -{ - // Expand coordinates to opposite corners of quad - vec2 leftBottom = GetPatchCoord(0).xy; - vec2 rightTop = vec2(1.0) - leftBottom; - - // Match quad edge order - return vec4(leftBottom.y, rightTop.x, rightTop.y, leftBottom.x); -} - -vec4 GetEdgeDistanceQuad() -{ - vec4 param = GetEdgeParamQuad(); - return max(vec4(0.0), param / fwidth(param)); -} - - - -struct ReprStyle -{ - vec4 color; - bool usePrimvarColor; - bool usePrimvarAlpha; - bool applyColorOverride; - bool useSurfaceShaderColor; - bool useSurfaceShaderAlpha; -}; - -struct ScalarOverride -{ - bool enabled; - vec3 color; -}; - -FORWARD_DECL(ReprStyle GetReprStyle()); -FORWARD_DECL(ScalarOverride GetScalarOverride()); -FORWARD_DECL( - vec4 surfaceShader(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord)); -FORWARD_DECL(vec4 postSurfaceShader(vec4 Peye, vec3 Neye, vec4 color)); - -vec4 ShadingTerminal(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) -{ - ReprStyle reprStyle = GetReprStyle(); - - // Apply scalar override. - ScalarOverride scalarOverride = GetScalarOverride(); - if (scalarOverride.enabled) { - vec4 result; - - result.rgb = scalarOverride.color; - result.a = reprStyle.usePrimvarAlpha ? color.a: reprStyle.color.a; - - vec4 colorOverride = ApplyColorOverrides(result); - result = reprStyle.applyColorOverride ? colorOverride : result; - - return result; - } - - // Draw mode can override face color - vec4 reprColor; - - reprColor.rgb = reprStyle.usePrimvarColor ? color.rgb : reprStyle.color.rgb; - reprColor.a = reprStyle.usePrimvarAlpha ? color.a : reprStyle.color.a; - - // Compute color overrides - vec4 colorOverride = ApplyColorOverrides(reprColor); - reprColor = reprStyle.applyColorOverride ? colorOverride : reprColor; - - - // Surface shading can be expensive and also can contain undesirable - // side effects (like discards). So only run it for reprs that require it. - - if (reprStyle.useSurfaceShaderColor || - reprStyle.useSurfaceShaderAlpha) { - vec4 shadingColor; - - shadingColor = surfaceShader(Peye, - Neye, - reprColor, - patchCoord); - -#ifdef HD_HAS_postSurfaceShader - shadingColor = postSurfaceShader(Peye, - Neye, - shadingColor); -#endif - - reprColor.rgb = reprStyle.useSurfaceShaderColor ? - shadingColor.rgb : - reprColor.rgb; - - reprColor.a = reprStyle.useSurfaceShaderAlpha ? - shadingColor.a : - reprColor.a; - } - - vec4 baseColor = color; - baseColor = ApplyColorOverrides(baseColor); - - vec4 litColor = mix(baseColor, - reprColor, - GetLightingBlendAmount()); - - // Final overrides. - - return ApplyColorOverridesPostLighting(litColor); -} - - - -#ifdef HD_HAS_integrateLights -#ifndef HD_HAS_definedIntegrateLights -#define HD_HAS_definedIntegrateLights - -LightingContribution -integrateLights(vec4 Peye, vec3 Neye, LightingInterfaceProperties props) -{ - return integrateLightsDefault(Peye, Neye, props); -} - -#endif // HD_HAS_definedIntegrateLights -#endif - -ReprStyle GetReprStyle() -{ - ReprStyle reprStyle; - - reprStyle.color = vec4(0.0, 0.0, 0.0, 1.0); - reprStyle.usePrimvarColor = true; - reprStyle.usePrimvarAlpha = true; - reprStyle.applyColorOverride = true; - reprStyle.useSurfaceShaderColor = true; - reprStyle.useSurfaceShaderAlpha = true; - - return reprStyle; -} - - - -ScalarOverride GetScalarOverride() -{ - ScalarOverride result; - -#if defined(HD_HAS_scalarOverride) - result.enabled = true; - - // Allow a scalar value to override the color from the surface - // for previewing heatmaps. This is useful for editing workflows. -#if defined(HD_HAS_scalarOverrideColorRamp) - int rampCount = constantPrimvars[GetDrawingCoord().constantCoord]. - scalarOverrideColorRamp.length(); - float scalar = HdGet_scalarOverride() * float(rampCount - 1); - float baseIndex = floor(scalar); - float nextIndex = min(float(rampCount - 1), baseIndex + 1.0); - float interp = scalar - baseIndex; - result.color = mix(HdGet_scalarOverrideColorRamp(int(baseIndex)).rgb, - HdGet_scalarOverrideColorRamp(int(nextIndex)).rgb, - interp); -#else - // If no ramp is given just gamma correct the scalar as greyscale. - result.color = vec3(pow(HdGet_scalarOverride(), 2.2)); -#endif // HD_HAS_scalarOverrideColorRamp - -#else // HD_HAS_scalarOverride - result.enabled = false; - result.color = vec3(0.0, 0.0, 0.0); -#endif - - return result; -} - - - -// Determines whether a fragment is on or close to an unhidden triangle edge. -const float edgePickRadius = 2; // in viewport pixels -const float edgePickParametricRadius = 0.02; // in parametric space - -// For smooth looking edges, use an exponential falloff for the opacity. -// Note: We use a slower falloff fn than in meshWire.glslfx to make the -// selected edges stand out. -float SelectedEdgeFalloff(float d) { - return exp2(-1 * d * d); -} - - - -FORWARD_DECL(vec3 GetEdgeDistanceTriangle()); - -vec3 ComputeBaseFaceEdgeDistanceTriangle() -{ - return GetEdgeDistanceTriangle(); -} - -bool SelectWireframeFaceEdges() -{ - return false; -} - - - -float GetSelectedEdgeOpacity() -{ - float closestEdgeDistance = 0.0; - - // The sequence of comparisons should match GetPrimitiveEdgeId() - vec3 dist = ComputeBaseFaceEdgeDistanceTriangle(); - if (dist.x < edgePickRadius) { - closestEdgeDistance = dist.x; - } else if (dist.y < edgePickRadius) { - closestEdgeDistance = dist.y; - } else if (dist.z < edgePickRadius) { - closestEdgeDistance = dist.z; - } else { - return 0; - } - - return SelectedEdgeFalloff(closestEdgeDistance); -} - -// called from hdx/renderPass.glslfx and selection.glslfx -int GetPrimitiveEdgeId() -{ - // 2 (0,1,0) - // ^ - // e2 / \ e1 - // / \' - // (0,0,1) 0 ----- 1 (1,0,0) - // e0 - - int edgeId = -1; - - vec3 dist = ComputeBaseFaceEdgeDistanceTriangle(); - if (dist.x < edgePickRadius) { - edgeId = 0; - } else if (dist.y < edgePickRadius) { - edgeId = 1; - } else if (dist.z < edgePickRadius) { - edgeId = 2; - } else { - return -1; // Not on a mesh edge - } - - const int edgeFlag = GetEdgeFlag(); - const int meshEdgeIndex = HdGetScalar_edgeIndices(); - - // Translate face-edge to authored mesh-edge - if (edgeFlag == 0) { - edgeId = meshEdgeIndex + edgeId; // regular triangle face. - } else if ((bool(edgeFlag & 1) && edgeId == 2) || - (bool(edgeFlag & 2) && edgeId == 0)) { - edgeId = -1; // Not an authored mesh edge - } else { - edgeId = meshEdgeIndex + edgeId - 1; - } - return edgeId; -} - - - -int GetPointId() -{ - return -1; -} - - -void DiscardBasedOnTopologicalVisibility() -{ - // Nothing to do, since there's no authored opinion. -} - - - -vec4 GetInterpolatedPatchCoord() -{ - return gsPatchCoord; -} - - - -#ifndef HD_HAS_ptexFaceOffset -#define HD_HAS_ptexFaceOffset -int HdGet_ptexFaceOffset() -{ - return 0; -} -#endif - -vec4 GetPatchCoord(int localIndex) -{ - vec4 patchCoord = GetInterpolatedPatchCoord(); - return vec4(patchCoord.xyz, patchCoord.w + HdGet_ptexFaceOffset()); -} - -vec4 GetPatchCoord() -{ - return GetPatchCoord(0); -} - -vec3 ComputeScreenSpacePeye() -{ - return inData.Peye.xyz / inData.Peye.w; -} - -vec3 ComputeScreenSpaceNeye() -{ - vec3 Peye = ComputeScreenSpacePeye(); - vec3 Neye = normalize(cross(dFdx(Peye), dFdy(Peye))); - return (gl_FrontFacing ? Neye : -Neye); -} - -void main(void) -{ - bool isFlipped = IsFlipped(); - - DiscardBasedOnShading(gl_FrontFacing, isFlipped); - - DiscardBasedOnTopologicalVisibility(); - - vec4 color = vec4(0.5, 0.5, 0.5, 1); -#ifdef HD_HAS_displayColor - color.rgb = HdGet_displayColor().rgb; -#endif -#ifdef HD_HAS_displayOpacity - color.a = HdGet_displayOpacity(); -#endif - - vec3 Peye = ComputeScreenSpacePeye(); - - vec3 Neye = inData.Neye; - // Normalize Neye after rasterizer interpolation. - if (length(Neye) > 0.0) { - Neye = normalize(Neye); - } - // Give the shader key a chance to override the normal. - Neye = GetNormal(Neye, 0); - // Orient the normal for shading. - Neye = GetShadingNormal(Neye, isFlipped); - - vec4 patchCoord = GetPatchCoord(); - color = ShadingTerminal(vec4(Peye, 1), Neye, color, patchCoord); - - color = ApplyEdgeColor(color, patchCoord); - -#ifdef HD_MATERIAL_TAG_MASKED - if (ShouldDiscardByAlpha(color)) { - discard; - return; - } -#endif - - RenderOutput(vec4(Peye, 1), Neye, color, patchCoord); -} - -------------------------------------------------------- --- glslfx version 0.1 -#import $TOOLS/hdSt/shaders/mesh.glslfx --- configuration -{"techniques": {"default": { -"vertexShader" : { "source" : ["Instancing.Transform", "MeshNormal.Pass", "PointId.Vertex.None", "Mesh.Vertex"] } -, "geometryShader" : { "source" : ["Instancing.Transform", "MeshNormal.Flat", "MeshNormal.Geometry.NoFlat", "Geometry.NoCustomDisplacement", "Mesh.Geometry.Quad"] } -, "fragmentShader" : { "source" : ["Instancing.Transform", "MeshNormal.Pass", "MeshNormal.Fragment.SingleSided", "MeshFaceCull.Fragment.None", "MeshWire.Fragment.NoEdge", "MeshWire.Fragment.EdgeParam", "Fragment.CommonTerminals", "Fragment.Surface", "Fragment.ScalarOverride", "EdgeId.Fragment.Common", "EdgeId.Fragment.QuadSurface", "EdgeId.Fragment.QuadParam", "PointId.Fragment.Fallback", "Visibility.Fragment.Fallback", "Mesh.Fragment.PatchCoord", "Mesh.Fragment"] } -}}} -------------------------------------------------------- -======================================================= - VERTEX SHADER -======================================================= -#version 450 -#extension GL_NV_shader_buffer_load : require -#extension GL_NV_gpu_shader5 : require -#extension GL_ARB_bindless_texture : require -#extension GL_ARB_shader_draw_parameters : require -int HgiGetBaseVertex() { - return gl_BaseVertexARB; -} -#define REF(space,type) inout type -#define FORWARD_DECL(func_decl) func_decl; -#define ATOMIC_LOAD(a) (a) -#define ATOMIC_STORE(a, v) (a) = (v) -#define ATOMIC_ADD(a, v) atomicAdd(a, v) -#define ATOMIC_EXCHANGE(a, v) atomicExchange(a, v) -#define ATOMIC_COMP_SWAP(a, expected, desired) atomicCompSwap(a, expected, desired) -#define atomic_int int -#define atomic_uint uint - -#define HGI_HAS_DOUBLE_TYPE 1 - - -struct hgi_ivec3 { int x, y, z; }; -struct hgi_vec3 { float x, y, z; }; -struct hgi_dvec3 { double x, y, z; }; -struct hgi_mat3 { float m00, m01, m02, - m10, m11, m12, - m20, m21, m22; }; -struct hgi_dmat3 { double m00, m01, m02, - m10, m11, m12, - m20, m21, m22; }; - - -// //////// Codegen Defines //////// -#define HD_SHADER_API 2 -#define MAT4 mat4 -// Alias hgi vec and matrix types to hd. -#define hd_ivec3 hgi_ivec3 -#define hd_vec3 hgi_vec3 -#define hd_dvec3 hgi_dvec3 -#define hd_mat3 hgi_mat3 -#define hd_dmat3 hgi_dmat3 - -ivec3 hd_ivec3_get(hd_ivec3 v) { return ivec3(v.x, v.y, v.z); } -ivec3 hd_ivec3_get(ivec3 v) { return v; } -vec3 hd_vec3_get(hd_vec3 v) { return vec3(v.x, v.y, v.z); } -vec3 hd_vec3_get(vec3 v) { return v; } -dvec3 hd_dvec3_get(hd_dvec3 v) { return dvec3(v.x, v.y, v.z); } -dvec3 hd_dvec3_get(dvec3 v) { return v; } -mat3 hd_mat3_get(hd_mat3 v) { return mat3(v.m00, v.m01, v.m02, - v.m10, v.m11, v.m12, - v.m20, v.m21, v.m22); } -mat3 hd_mat3_get(mat3 v) { return v; } -dmat3 hd_dmat3_get(hd_dmat3 v) { return dmat3(v.m00, v.m01, v.m02, - v.m10, v.m11, v.m12, - v.m20, v.m21, v.m22); } -dmat3 hd_dmat3_get(dmat3 v) { return v; } -hd_ivec3 hd_ivec3_set(hd_ivec3 v) { return v; } -hd_ivec3 hd_ivec3_set(ivec3 v) { return hd_ivec3(v.x, v.y, v.z); } -hd_vec3 hd_vec3_set(hd_vec3 v) { return v; } -hd_vec3 hd_vec3_set(vec3 v) { return hd_vec3(v.x, v.y, v.z); } -hd_dvec3 hd_dvec3_set(hd_dvec3 v) { return v; } -hd_dvec3 hd_dvec3_set(dvec3 v) { return hd_dvec3(v.x, v.y, v.z); } -hd_mat3 hd_mat3_set(hd_mat3 v) { return v; } -hd_mat3 hd_mat3_set(mat3 v) { return hd_mat3(v[0][0], v[0][1], v[0][2], - v[1][0], v[1][1], v[1][2], - v[2][0], v[2][1], v[2][2]); } -hd_dmat3 hd_dmat3_set(hd_dmat3 v) { return v; } -hd_dmat3 hd_dmat3_set(dmat3 v) { return hd_dmat3(v[0][0], v[0][1], v[0][2], - v[1][0], v[1][1], v[1][2], - v[2][0], v[2][1], v[2][2]); } -int hd_int_get(int v) { return v; } -int hd_int_get(ivec2 v) { return v.x; } -int hd_int_get(ivec3 v) { return v.x; } -int hd_int_get(ivec4 v) { return v.x; } -vec3 hd_sample_udim(vec2 v) { -vec2 vf = floor(v); -return vec3(v.x - vf.x, v.y - vf.y, clamp(vf.x, 0.0, 10.0) + 10.0 * vf.y); -} -vec4 hd_vec4_2_10_10_10_get(int v) { - ivec4 unpacked = ivec4((v & 0x3ff) << 22, (v & 0xffc00) << 12, - (v & 0x3ff00000) << 2, (v & 0xc0000000)); - return vec4(unpacked) / 2147483647.0; } -int hd_vec4_2_10_10_10_set(vec4 v) { - return ( (int(v.x * 511.0) & 0x3ff) | - ((int(v.y * 511.0) & 0x3ff) << 10) | - ((int(v.z * 511.0) & 0x3ff) << 20) | - ((int(v.w) & 0x1) << 30)); } -vec2 hd_half2_get(uint v) { - return unpackHalf2x16(v); } -uint hd_half2_set(vec2 v) { - return packHalf2x16(v); } -vec4 hd_half4_get(uvec2 v) { - return vec4(unpackHalf2x16(v.x), unpackHalf2x16(v.y)); } -uvec2 hd_half4_set(vec4 v) { - return uvec2(packHalf2x16(v.xy), packHalf2x16(v.zw)); } -#define HD_NUM_PRIMITIVE_VERTS 4 -#define HD_HAS_transform 1 -#define HD_HAS_transformInverse 1 -#define HD_HAS_color 1 -#define HD_HAS_primID 1 -#define HD_HAS_widths 1 -#define HD_INSTANCER_NUM_LEVELS 0 -#define HD_INSTANCE_INDEX_WIDTH 1 -#define HD_HAS_faceVisibility 1 -#define HD_HAS_dispTextureCoord 1 -#define HD_HAS_points 1 -#define HD_HAS_normals 1 - - -// //////// Global Includes //////// - -// //////// Global Macros //////// - -// //////// Global Structs //////// - -// //////// Global Member Declarations //////// -uint hd_VertexID = gl_VertexID; -uint hd_InstanceID = gl_InstanceID; -uint hd_BaseInstance = 0; - -// //////// Global Function Definitions //////// - - -// //////// Codegen Decl //////// -struct hd_drawingCoord { - int modelCoord; - int constantCoord; - int elementCoord; - int primitiveCoord; - int fvarCoord; - int shaderCoord; - int vertexCoord; - int topologyVisibilityCoord; - int varyingCoord; - int instanceIndex[HD_INSTANCE_INDEX_WIDTH]; - int instanceCoords[HD_INSTANCE_INDEX_WIDTH]; -}; -FORWARD_DECL(hd_drawingCoord GetDrawingCoord()); -FORWARD_DECL(int HgiGetBaseVertex()); -struct hd_instanceIndex { int indices[HD_INSTANCE_INDEX_WIDTH]; }; -struct ConstantData10 { - mat4 transform; - mat4 transformInverse; - vec4 color; - vec4 primID; - float widths; -}; -FORWARD_DECL(int GetElementID()); -FORWARD_DECL(int GetAggregatedElementID()); -FORWARD_DECL(int GetPrimitiveEdgeId()); -FORWARD_DECL(float GetSelectedEdgeOpacity()); -layout (location = 2) in ivec4 drawingCoord0; -layout (location = 3) in ivec4 drawingCoord1; -layout (location = 4) in ivec2 drawingCoord2; -layout (location = 0) in vec3 points; -layout (location = 1) in vec3 normals; -out flat int vs_dc_modelCoord; -out flat int vs_dc_constantCoord; -out flat int vs_dc_elementCoord; -out flat int vs_dc_primitiveCoord; -out flat int vs_dc_fvarCoord; -out flat int vs_dc_shaderCoord; -out flat int vs_dc_vertexCoord; -out flat int vs_dc_topologyVisibilityCoord; -out flat int vs_dc_varyingCoord; -out flat int vs_dc_instanceIndexI0; -out flat int vs_dc_instanceCoordsI0; -layout(location = 0) uniform ConstantData10 *constantPrimvars; -layout(location = 1) uniform int *primitiveParam; -layout(location = 2) uniform ivec2 *edgeIndices; -layout(location = 3) uniform float *faceVisibility; -out VertexData { - vec4 Peye; - vec3 Neye; -} outData; -out PrimvarData { - vec3 points; - vec3 normals; -} outPrimvars; - -// //////// Codegen Accessors //////// -mat4 HdGet_transform(int localIndex) { - int index = GetDrawingCoord().constantCoord; - return mat4(constantPrimvars[index].transform); -} -mat4 HdGet_transform() { return HdGet_transform(0); } -mat4 HdGet_transformInverse(int localIndex) { - int index = GetDrawingCoord().constantCoord; - return mat4(constantPrimvars[index].transformInverse); -} -mat4 HdGet_transformInverse() { return HdGet_transformInverse(0); } -vec4 HdGet_color(int localIndex) { - int index = GetDrawingCoord().constantCoord; - return vec4(constantPrimvars[index].color); -} -vec4 HdGet_color() { return HdGet_color(0); } -float HdGetScalar_color(int localIndex) { return HdGet_color(localIndex).x; } -float HdGetScalar_color() { return HdGet_color(0).x; } -vec4 HdGet_primID(int localIndex) { - int index = GetDrawingCoord().constantCoord; - return vec4(constantPrimvars[index].primID); -} -vec4 HdGet_primID() { return HdGet_primID(0); } -float HdGetScalar_primID(int localIndex) { return HdGet_primID(localIndex).x; } -float HdGetScalar_primID() { return HdGet_primID(0).x; } -float HdGet_widths(int localIndex) { - int index = GetDrawingCoord().constantCoord; - return float(constantPrimvars[index].widths); -} -float HdGet_widths() { return HdGet_widths(0); } -float HdGetScalar_widths(int localIndex) { return HdGet_widths(localIndex); } -float HdGetScalar_widths() { return HdGet_widths(0); } - -// //////// Codegen VS Source //////// -#define HD_BINDLESS_BUFFERS_ENABLED -int GetBaseVertexOffset() { - return HgiGetBaseVertex(); -} -hd_instanceIndex GetInstanceIndex() { hd_instanceIndex r; r.indices[0] = 0; return r; } -hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = drawingCoord0.x; - dc.constantCoord = drawingCoord0.y; - dc.elementCoord = drawingCoord0.z; - dc.primitiveCoord = drawingCoord0.w; - dc.fvarCoord = drawingCoord1.x; - dc.shaderCoord = drawingCoord1.z; - dc.vertexCoord = drawingCoord1.w; - dc.topologyVisibilityCoord = drawingCoord2.x; - dc.varyingCoord = drawingCoord2.y; - hd_instanceIndex r = GetInstanceIndex(); - dc.instanceIndex[0] = r.indices[0]; - return dc; -} -vec3 HdGet_points(int localIndex) { return hd_vec3_get(points);} -vec3 HdGet_points() { return HdGet_points(0); } -float HdGetScalar_points(int localIndex) { return HdGet_points(localIndex).x; } -float HdGetScalar_points() { return HdGet_points(0).x; } -vec3 HdGet_normals(int localIndex) { return hd_vec3_get(normals);} -vec3 HdGet_normals() { return HdGet_normals(0); } -float HdGetScalar_normals(int localIndex) { return HdGet_normals(localIndex).x; } -float HdGetScalar_normals() { return HdGet_normals(0).x; } - -// //////// Codegen Proc VS //////// -void ProcessPrimvarsIn() { - hd_drawingCoord dc = GetDrawingCoord(); - vs_dc_modelCoord = dc.modelCoord; - vs_dc_constantCoord = dc.constantCoord; - vs_dc_elementCoord = dc.elementCoord; - vs_dc_primitiveCoord = dc.primitiveCoord; - vs_dc_fvarCoord = dc.fvarCoord; - vs_dc_shaderCoord = dc.shaderCoord; - vs_dc_vertexCoord = dc.vertexCoord; - vs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - vs_dc_varyingCoord = dc.varyingCoord; - vs_dc_instanceIndexI0 = dc.instanceIndex[0]; - outPrimvars.points = points; - outPrimvars.normals = normals; -} - -// --------------------------------------------------------------------------- -// global defines -// --------------------------------------------------------------------------- -// codeGen can override this range (currently not). -// quadro 4000's max is 189. -#ifndef HD_GL_POINT_SIZE_MAX -#define HD_GL_POINT_SIZE_MAX 100.0 -#endif -#ifndef HD_GL_POINT_SIZE_MIN -#define HD_GL_POINT_SIZE_MIN .45 -#endif - -// --------------------------------------------------------------------------- -// render pass states -// --------------------------------------------------------------------------- - -MAT4 GetWorldToViewMatrix() { -#if defined(HD_HAS_worldToViewMatrix) - return MAT4(HdGet_worldToViewMatrix()); -#else - return MAT4(1); -#endif -} -MAT4 GetWorldToViewInverseMatrix() { -#if defined(HD_HAS_worldToViewInverseMatrix) - return MAT4(HdGet_worldToViewInverseMatrix()); -#else - return MAT4(1); -#endif -} -MAT4 GetProjectionMatrix() { -#if defined(HD_HAS_projectionMatrix) - return MAT4(HdGet_projectionMatrix()); -#else - return MAT4(1); -#endif -} -vec3 GetPositionInWorldSpace(vec3 windowRelativeCoord) -{ -#if defined(HD_HAS_imageToWorldMatrix) - vec4 pImage = vec4(windowRelativeCoord, 1.0); - vec4 pWorld = vec4(HdGet_imageToWorldMatrix() * pImage); - return (pWorld / pWorld.w).xyz; -#else - return windowRelativeCoord; -#endif -} -float GetLightingBlendAmount() { -#if defined(HD_HAS_lightingBlendAmount) - return HdGet_lightingBlendAmount(); -#else - return 1; -#endif -} -vec4 GetViewport() { -#if defined(HD_HAS_viewport) - return HdGet_viewport(); -#else - return vec4(0,0,1,1); -#endif -} -float GetTessLevel() { -#if defined(HD_HAS_tessLevel) - return HdGet_tessLevel(); -#else - return 1; -#endif -} -float GetPointSize() { -#if defined(HD_HAS_pointSize) - return HdGet_pointSize(); -#else - return 3.0; -#endif -} -float GetPointSelectedSize() { -#if defined(HD_HAS_pointSelectedSize) - return HdGet_pointSelectedSize(); -#else - return 5.0; -#endif -} -vec4 GetWireframeColor() { -// Individual prims can specify an alternative wireframe color -// to one specified in the render pass. This is used in cases were -// there is not enough contrast with the normal one. -#if defined(HD_HAS_overrideWireframeColor) - return HdGet_overrideWireframeColor(); -#elif defined(HD_HAS_wireframeColor) - return HdGet_wireframeColor(); -#else - return vec4(0,0,0,0); -#endif -} -vec4 GetMaskColor() { -#if defined(HD_HAS_maskColor) - return HdGet_maskColor(); -#else - return vec4(0.5,0,0,1); -#endif -} -vec4 GetIndicatorColor() { -#if defined(HD_HAS_indicatorColor) - return HdGet_indicatorColor(); -#else - return vec4(0,0.5,0,1); -#endif -} - -bool ShouldDiscardByAlpha(vec4 color) -{ -#if defined(HD_HAS_alphaThreshold) - float alphaThreshold = HdGet_alphaThreshold(); -#else - float alphaThreshold = 0; -#endif - return (color.a < alphaThreshold); -} - -vec2 ApplyAxisAlignedAffineTransform(vec4 t, vec2 pt) -{ - return t.xy * pt + t.zw; -} - - - -void ApplyClipPlanes(vec4 Peye) -{ -#if defined(HD_HAS_numClipPlanes) -#if defined(HD_HAS_clipPlanes) - for (int i=0; i> 2); -} -int GetAggregatedElementID() { - return GetElementID() - + GetDrawingCoord().elementCoord; -} -ivec2 HdGet_edgeIndices(int localIndex) { - int index = GetPrimitiveIndex(); - return ivec2(edgeIndices[index]); -} -ivec2 HdGet_edgeIndices() { return HdGet_edgeIndices(0); } -int HdGetScalar_edgeIndices(int localIndex) { return HdGet_edgeIndices(localIndex).x; } -int HdGetScalar_edgeIndices() { return HdGet_edgeIndices(0).x; } -int GetAuthoredEdgeId(int primitiveEdgeId) { - return primitiveEdgeId; -} -float HdGet_faceVisibility(int localIndex) { - int index = GetAggregatedElementID(); - return float(faceVisibility[index]); -} -float HdGet_faceVisibility() { return HdGet_faceVisibility(0); } -float HdGetScalar_faceVisibility(int localIndex) { return HdGet_faceVisibility(localIndex); } -float HdGetScalar_faceVisibility() { return HdGet_faceVisibility(0); } -vec3 HdGet_points(int localIndex) { - int index = localIndex; - return vec3(inPrimvars[index].points); -} -vec3 HdGet_points() { return HdGet_points(0); } -float HdGetScalar_points(int localIndex) { return HdGet_points(localIndex).x; } -float HdGetScalar_points() { return HdGet_points(0).x; } -vec3 HdGet_normals(int localIndex) { - int index = localIndex; - return vec3(inPrimvars[index].normals); -} -vec3 HdGet_normals() { return HdGet_normals(0); } -float HdGetScalar_normals(int localIndex) { return HdGet_normals(localIndex).x; } -float HdGetScalar_normals() { return HdGet_normals(0).x; } -vec2 HdGet_dispTextureCoord_Coarse(int localIndex) { - int fvarIndex = GetFVarIndex(localIndex); - return vec2(dispTextureCoord[fvarIndex]); -} -vec2 HdGet_dispTextureCoord(int localIndex, vec2 st) { - return mix(mix(HdGet_dispTextureCoord_Coarse(0),HdGet_dispTextureCoord_Coarse(1), st.x),mix(HdGet_dispTextureCoord_Coarse(3),HdGet_dispTextureCoord_Coarse(2), st.x), st.y); -} -FORWARD_DECL(vec4 GetPatchCoord(int index)); -FORWARD_DECL(vec2 GetPatchCoordLocalST()); -vec2 HdGet_dispTextureCoord(int localIndex) { - vec2 localST = GetPatchCoord(localIndex).xy; - return HdGet_dispTextureCoord(localIndex, localST); -} -vec2 HdGet_dispTextureCoord() { return HdGet_dispTextureCoord(0); } -FORWARD_DECL(vec4 GetPatchCoord(int localIndex)); -void ProcessSamplingTransforms(MAT4 instanceModelViewInverse) { -} - -// //////// Codegen Proc GS //////// -FORWARD_DECL(vec4 GetPatchCoord(int index)); -void ProcessPrimvarsOut(int index) { - vec2 localST = GetPatchCoord(index).xy; - const vec3 coords[4] = vec3[]( - vec3(1,0,0), vec3(0,1,0), vec3(0,0,1), vec3(0,1,0) - ); - hd_barycentricCoord = coords[index]; - hd_drawingCoord dc = GetDrawingCoord(); - gs_dc_modelCoord = dc.modelCoord; - gs_dc_constantCoord = dc.constantCoord; - gs_dc_elementCoord = dc.elementCoord; - gs_dc_primitiveCoord = dc.primitiveCoord; - gs_dc_fvarCoord = dc.fvarCoord; - gs_dc_shaderCoord = dc.shaderCoord; - gs_dc_vertexCoord = dc.vertexCoord; - gs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - gs_dc_varyingCoord = dc.varyingCoord; - gs_dc_instanceIndexI0 = dc.instanceIndex[0]; - outPrimvars.points = inPrimvars[index].points; - outPrimvars.normals = inPrimvars[index].normals; - outPrimvars.dispTextureCoord = HdGet_dispTextureCoord(index); -} - -// --------------------------------------------------------------------------- -// global defines -// --------------------------------------------------------------------------- -// codeGen can override this range (currently not). -// quadro 4000's max is 189. -#ifndef HD_GL_POINT_SIZE_MAX -#define HD_GL_POINT_SIZE_MAX 100.0 -#endif -#ifndef HD_GL_POINT_SIZE_MIN -#define HD_GL_POINT_SIZE_MIN .45 -#endif - -// --------------------------------------------------------------------------- -// render pass states -// --------------------------------------------------------------------------- - -MAT4 GetWorldToViewMatrix() { -#if defined(HD_HAS_worldToViewMatrix) - return MAT4(HdGet_worldToViewMatrix()); -#else - return MAT4(1); -#endif -} -MAT4 GetWorldToViewInverseMatrix() { -#if defined(HD_HAS_worldToViewInverseMatrix) - return MAT4(HdGet_worldToViewInverseMatrix()); -#else - return MAT4(1); -#endif -} -MAT4 GetProjectionMatrix() { -#if defined(HD_HAS_projectionMatrix) - return MAT4(HdGet_projectionMatrix()); -#else - return MAT4(1); -#endif -} -vec3 GetPositionInWorldSpace(vec3 windowRelativeCoord) -{ -#if defined(HD_HAS_imageToWorldMatrix) - vec4 pImage = vec4(windowRelativeCoord, 1.0); - vec4 pWorld = vec4(HdGet_imageToWorldMatrix() * pImage); - return (pWorld / pWorld.w).xyz; -#else - return windowRelativeCoord; -#endif -} -float GetLightingBlendAmount() { -#if defined(HD_HAS_lightingBlendAmount) - return HdGet_lightingBlendAmount(); -#else - return 1; -#endif -} -vec4 GetViewport() { -#if defined(HD_HAS_viewport) - return HdGet_viewport(); -#else - return vec4(0,0,1,1); -#endif -} -float GetTessLevel() { -#if defined(HD_HAS_tessLevel) - return HdGet_tessLevel(); -#else - return 1; -#endif -} -float GetPointSize() { -#if defined(HD_HAS_pointSize) - return HdGet_pointSize(); -#else - return 3.0; -#endif -} -float GetPointSelectedSize() { -#if defined(HD_HAS_pointSelectedSize) - return HdGet_pointSelectedSize(); -#else - return 5.0; -#endif -} -vec4 GetWireframeColor() { -// Individual prims can specify an alternative wireframe color -// to one specified in the render pass. This is used in cases were -// there is not enough contrast with the normal one. -#if defined(HD_HAS_overrideWireframeColor) - return HdGet_overrideWireframeColor(); -#elif defined(HD_HAS_wireframeColor) - return HdGet_wireframeColor(); -#else - return vec4(0,0,0,0); -#endif -} -vec4 GetMaskColor() { -#if defined(HD_HAS_maskColor) - return HdGet_maskColor(); -#else - return vec4(0.5,0,0,1); -#endif -} -vec4 GetIndicatorColor() { -#if defined(HD_HAS_indicatorColor) - return HdGet_indicatorColor(); -#else - return vec4(0,0.5,0,1); -#endif -} - -bool ShouldDiscardByAlpha(vec4 color) -{ -#if defined(HD_HAS_alphaThreshold) - float alphaThreshold = HdGet_alphaThreshold(); -#else - float alphaThreshold = 0; -#endif - return (color.a < alphaThreshold); -} - -vec2 ApplyAxisAlignedAffineTransform(vec4 t, vec2 pt) -{ - return t.xy * pt + t.zw; -} - - - -void ApplyClipPlanes(vec4 Peye) -{ -#if defined(HD_HAS_numClipPlanes) -#if defined(HD_HAS_clipPlanes) - for (int i=0; i 0.0) - normal = normalize(normal); - return normal; -} - -vec3 GetNormal(vec3 Neye, int index, vec2 localST) -{ - return GetNormal(Neye, index); -} - - - -vec3 GetTriGeometryNormal(vec3 Neye, vec4 Peye0, vec4 Peye1, vec4 Peye2, - bool isFlipped) -{ - return Neye; -} - -vec3 GetQuadGeometryNormal(vec3 Neye, - vec4 Peye0, vec4 Peye1, vec4 Peye2, vec4 Peye3, - bool isFlipped) -{ - return Neye; -} - - - -vec4 DisplacementTerminal(int index, vec4 Peye, vec3 Neye, vec4 patchCoord) -{ - return Peye; -} - - - -vec4 GetPatchCoord(int index) -{ - vec2 uv[4]; - uv[0] = vec2(0, 0); - uv[1] = vec2(1, 0); - uv[2] = vec2(1, 1); - uv[3] = vec2(0, 1); - - ivec3 patchParam = GetPatchParam(); - return InterpolatePatchCoord(uv[index], patchParam); -} - -void emit(int index, vec4 Peye, vec3 Neye) -{ - outData.Peye = Peye; - outData.Neye = Neye; - - gsPatchCoord = GetPatchCoord(index); - - gl_Position = vec4(GetProjectionMatrix() * outData.Peye); - ApplyClipPlanes(outData.Peye); - - ProcessPrimvarsOut(index); - - EmitVertex(); -} - -void main(void) -{ - gl_PrimitiveID = gl_PrimitiveIDIn; - - bool isFlipped = IsFlipped(); // consider handedness AND negative-scale - - vec3 Neye0 = GetNormal(inData[0].Neye, 0); - Neye0 = GetQuadGeometryNormal(Neye0, inData[0].Peye, inData[1].Peye, - inData[2].Peye, inData[3].Peye, isFlipped); - vec3 Neye1 = GetNormal(inData[1].Neye, 1); - Neye1 = GetQuadGeometryNormal(Neye1, inData[0].Peye, inData[1].Peye, - inData[2].Peye, inData[3].Peye, isFlipped); - vec3 Neye2 = GetNormal(inData[2].Neye, 2); - Neye2 = GetQuadGeometryNormal(Neye2, inData[0].Peye, inData[1].Peye, - inData[2].Peye, inData[3].Peye, isFlipped); - vec3 Neye3 = GetNormal(inData[3].Neye, 3); - Neye3 = GetQuadGeometryNormal(Neye3, inData[0].Peye, inData[1].Peye, - inData[2].Peye, inData[3].Peye, isFlipped); - - vec4 Peye0 = DisplacementTerminal( - 0, inData[0].Peye, Neye0, GetPatchCoord(0)); - vec4 Peye1 = DisplacementTerminal( - 1, inData[1].Peye, Neye1, GetPatchCoord(1)); - vec4 Peye2 = DisplacementTerminal( - 2, inData[2].Peye, Neye2, GetPatchCoord(2)); - vec4 Peye3 = DisplacementTerminal( - 3, inData[3].Peye, Neye3, GetPatchCoord(3)); - - // Generate triangles (0,1,2) and (2,3,0) - // 3---2 - // | .| - // | . | - // |. | - // 0---1 - // The indices post-quadrangulation/subdivision follow the convention: - // 0 -> original (hull) vertex - // 1,3 -> edge vertices - // 2 -> center vertex - // - // By having index 2 in both the triangles, we ensure the pre-quadrangulated - // face's normal (at the center) is part of the rasterizer interpolation, - // which matters when we use smooth/limit normals. - // In the case of flat normals, we use the vertex positions, so it doesn't - // matter. - - // triangle 0: vertices (0,1,2) - emit(0, Peye0, Neye0); - emit(1, Peye1, Neye1); - emit(2, Peye2, Neye2); - EndPrimitive(); - - // triangle 1: vertices (2,3,0) - gl_PrimitiveID = gl_PrimitiveIDIn; - emit(2, Peye2, Neye2); - emit(3, Peye3, Neye3); - emit(0, Peye0, Neye0); - EndPrimitive(); -} - - -======================================================= - FRAGMENT SHADER -======================================================= -#version 450 -#extension GL_NV_shader_buffer_load : require -#extension GL_NV_gpu_shader5 : require -#extension GL_ARB_bindless_texture : require -#define REF(space,type) inout type -#define FORWARD_DECL(func_decl) func_decl; -#define ATOMIC_LOAD(a) (a) -#define ATOMIC_STORE(a, v) (a) = (v) -#define ATOMIC_ADD(a, v) atomicAdd(a, v) -#define ATOMIC_EXCHANGE(a, v) atomicExchange(a, v) -#define ATOMIC_COMP_SWAP(a, expected, desired) atomicCompSwap(a, expected, desired) -#define atomic_int int -#define atomic_uint uint - -#define HGI_HAS_DOUBLE_TYPE 1 - - -struct hgi_ivec3 { int x, y, z; }; -struct hgi_vec3 { float x, y, z; }; -struct hgi_dvec3 { double x, y, z; }; -struct hgi_mat3 { float m00, m01, m02, - m10, m11, m12, - m20, m21, m22; }; -struct hgi_dmat3 { double m00, m01, m02, - m10, m11, m12, - m20, m21, m22; }; - - - -// //////// Global Includes //////// - -// //////// Global Macros //////// - -// //////// Global Structs //////// - -// //////// Global Member Declarations //////// - -// //////// Global Function Definitions //////// - - -// //////// Codegen Defines //////// -#define HD_SHADER_API 2 -#define MAT4 mat4 -// Alias hgi vec and matrix types to hd. -#define hd_ivec3 hgi_ivec3 -#define hd_vec3 hgi_vec3 -#define hd_dvec3 hgi_dvec3 -#define hd_mat3 hgi_mat3 -#define hd_dmat3 hgi_dmat3 - -ivec3 hd_ivec3_get(hd_ivec3 v) { return ivec3(v.x, v.y, v.z); } -ivec3 hd_ivec3_get(ivec3 v) { return v; } -vec3 hd_vec3_get(hd_vec3 v) { return vec3(v.x, v.y, v.z); } -vec3 hd_vec3_get(vec3 v) { return v; } -dvec3 hd_dvec3_get(hd_dvec3 v) { return dvec3(v.x, v.y, v.z); } -dvec3 hd_dvec3_get(dvec3 v) { return v; } -mat3 hd_mat3_get(hd_mat3 v) { return mat3(v.m00, v.m01, v.m02, - v.m10, v.m11, v.m12, - v.m20, v.m21, v.m22); } -mat3 hd_mat3_get(mat3 v) { return v; } -dmat3 hd_dmat3_get(hd_dmat3 v) { return dmat3(v.m00, v.m01, v.m02, - v.m10, v.m11, v.m12, - v.m20, v.m21, v.m22); } -dmat3 hd_dmat3_get(dmat3 v) { return v; } -hd_ivec3 hd_ivec3_set(hd_ivec3 v) { return v; } -hd_ivec3 hd_ivec3_set(ivec3 v) { return hd_ivec3(v.x, v.y, v.z); } -hd_vec3 hd_vec3_set(hd_vec3 v) { return v; } -hd_vec3 hd_vec3_set(vec3 v) { return hd_vec3(v.x, v.y, v.z); } -hd_dvec3 hd_dvec3_set(hd_dvec3 v) { return v; } -hd_dvec3 hd_dvec3_set(dvec3 v) { return hd_dvec3(v.x, v.y, v.z); } -hd_mat3 hd_mat3_set(hd_mat3 v) { return v; } -hd_mat3 hd_mat3_set(mat3 v) { return hd_mat3(v[0][0], v[0][1], v[0][2], - v[1][0], v[1][1], v[1][2], - v[2][0], v[2][1], v[2][2]); } -hd_dmat3 hd_dmat3_set(hd_dmat3 v) { return v; } -hd_dmat3 hd_dmat3_set(dmat3 v) { return hd_dmat3(v[0][0], v[0][1], v[0][2], - v[1][0], v[1][1], v[1][2], - v[2][0], v[2][1], v[2][2]); } -int hd_int_get(int v) { return v; } -int hd_int_get(ivec2 v) { return v.x; } -int hd_int_get(ivec3 v) { return v.x; } -int hd_int_get(ivec4 v) { return v.x; } -vec3 hd_sample_udim(vec2 v) { -vec2 vf = floor(v); -return vec3(v.x - vf.x, v.y - vf.y, clamp(vf.x, 0.0, 10.0) + 10.0 * vf.y); -} -vec4 hd_vec4_2_10_10_10_get(int v) { - ivec4 unpacked = ivec4((v & 0x3ff) << 22, (v & 0xffc00) << 12, - (v & 0x3ff00000) << 2, (v & 0xc0000000)); - return vec4(unpacked) / 2147483647.0; } -int hd_vec4_2_10_10_10_set(vec4 v) { - return ( (int(v.x * 511.0) & 0x3ff) | - ((int(v.y * 511.0) & 0x3ff) << 10) | - ((int(v.z * 511.0) & 0x3ff) << 20) | - ((int(v.w) & 0x1) << 30)); } -vec2 hd_half2_get(uint v) { - return unpackHalf2x16(v); } -uint hd_half2_set(vec2 v) { - return packHalf2x16(v); } -vec4 hd_half4_get(uvec2 v) { - return vec4(unpackHalf2x16(v.x), unpackHalf2x16(v.y)); } -uvec2 hd_half4_set(vec4 v) { - return uvec2(packHalf2x16(v.xy), packHalf2x16(v.zw)); } -#define HD_NUM_PRIMITIVE_VERTS 4 -#define HD_HAS_transform 1 -#define HD_HAS_transformInverse 1 -#define HD_HAS_color 1 -#define HD_HAS_primID 1 -#define HD_HAS_widths 1 -#define HD_INSTANCER_NUM_LEVELS 0 -#define HD_INSTANCE_INDEX_WIDTH 1 -#define HD_HAS_faceVisibility 1 -#define HD_HAS_dispTextureCoord 1 -#define HD_HAS_points 1 -#define HD_HAS_normals 1 - -// //////// Codegen Decl //////// -struct hd_drawingCoord { - int modelCoord; - int constantCoord; - int elementCoord; - int primitiveCoord; - int fvarCoord; - int shaderCoord; - int vertexCoord; - int topologyVisibilityCoord; - int varyingCoord; - int instanceIndex[HD_INSTANCE_INDEX_WIDTH]; - int instanceCoords[HD_INSTANCE_INDEX_WIDTH]; -}; -FORWARD_DECL(hd_drawingCoord GetDrawingCoord()); -FORWARD_DECL(int HgiGetBaseVertex()); -struct hd_instanceIndex { int indices[HD_INSTANCE_INDEX_WIDTH]; }; -struct ConstantData10 { - mat4 transform; - mat4 transformInverse; - vec4 color; - vec4 primID; - float widths; -}; -FORWARD_DECL(int GetElementID()); -FORWARD_DECL(int GetAggregatedElementID()); -FORWARD_DECL(int GetPrimitiveEdgeId()); -FORWARD_DECL(float GetSelectedEdgeOpacity()); -layout(location = 0) uniform ConstantData10 *constantPrimvars; -layout(location = 1) uniform int *primitiveParam; -layout(location = 2) uniform ivec2 *edgeIndices; -layout(location = 3) uniform float *faceVisibility; -in vec4 gsPatchCoord; -in VertexData { - vec4 Peye; - vec3 Neye; -} inData; -layout (location = 0) out vec4 colorOut; -in noperspective vec3 hd_barycentricCoord; -in PrimvarData { - vec3 points; - vec3 normals; - vec2 dispTextureCoord; -} inPrimvars; -in flat int gs_dc_modelCoord; -in flat int gs_dc_constantCoord; -in flat int gs_dc_elementCoord; -in flat int gs_dc_primitiveCoord; -in flat int gs_dc_fvarCoord; -in flat int gs_dc_shaderCoord; -in flat int gs_dc_vertexCoord; -in flat int gs_dc_topologyVisibilityCoord; -in flat int gs_dc_varyingCoord; -in flat int gs_dc_instanceIndexI0; -in flat int gs_dc_instanceCoordsI0; -layout(location = 4) uniform vec2 *dispTextureCoord; -vec4 InterpolatePatchCoord(vec2 uv, ivec3 patchParam) -{ - // add 0.5 to integer values for more robust interpolation - return vec4(uv.x, uv.y, 0, patchParam.x+0.5f); -} -vec4 InterpolatePatchCoordTriangle(vec2 uv, ivec3 patchParam) -{ - return InterpolatePatchCoord(uv, patchParam); -} - -// //////// Codegen Accessors //////// -mat4 HdGet_transform(int localIndex) { - int index = GetDrawingCoord().constantCoord; - return mat4(constantPrimvars[index].transform); -} -mat4 HdGet_transform() { return HdGet_transform(0); } -mat4 HdGet_transformInverse(int localIndex) { - int index = GetDrawingCoord().constantCoord; - return mat4(constantPrimvars[index].transformInverse); -} -mat4 HdGet_transformInverse() { return HdGet_transformInverse(0); } -vec4 HdGet_color(int localIndex) { - int index = GetDrawingCoord().constantCoord; - return vec4(constantPrimvars[index].color); -} -vec4 HdGet_color() { return HdGet_color(0); } -float HdGetScalar_color(int localIndex) { return HdGet_color(localIndex).x; } -float HdGetScalar_color() { return HdGet_color(0).x; } -vec4 HdGet_primID(int localIndex) { - int index = GetDrawingCoord().constantCoord; - return vec4(constantPrimvars[index].primID); -} -vec4 HdGet_primID() { return HdGet_primID(0); } -float HdGetScalar_primID(int localIndex) { return HdGet_primID(localIndex).x; } -float HdGetScalar_primID() { return HdGet_primID(0).x; } -float HdGet_widths(int localIndex) { - int index = GetDrawingCoord().constantCoord; - return float(constantPrimvars[index].widths); -} -float HdGet_widths() { return HdGet_widths(0); } -float HdGetScalar_widths(int localIndex) { return HdGet_widths(localIndex); } -float HdGetScalar_widths() { return HdGet_widths(0); } - -// //////// Codegen FS Source //////// -#define HD_SHADER_SUPPORTS_DOUBLE_PRECISION -#define HD_MINUS_ONE_TO_ONE_DEPTH_RANGE -vec3 GetBarycentricCoord() { - return hd_barycentricCoord; -} -int GetPrimitiveID() { - return gl_PrimitiveID; -} -int GetPrimitiveIndex() { - return GetDrawingCoord().primitiveCoord + GetPrimitiveID(); -} -hd_drawingCoord GetDrawingCoord() { - hd_drawingCoord dc; - dc.modelCoord = gs_dc_modelCoord; - dc.constantCoord = gs_dc_constantCoord; - dc.elementCoord = gs_dc_elementCoord; - dc.primitiveCoord = gs_dc_primitiveCoord; - dc.fvarCoord = gs_dc_fvarCoord; - dc.shaderCoord = gs_dc_shaderCoord; - dc.vertexCoord = gs_dc_vertexCoord; - dc.topologyVisibilityCoord = gs_dc_topologyVisibilityCoord; - dc.varyingCoord = gs_dc_varyingCoord; - dc.instanceIndex[0] = gs_dc_instanceIndexI0; - return dc; -} -int HdGet_primitiveParam(int localIndex) { - int index = GetPrimitiveIndex(); - return int(primitiveParam[index]); -} -int HdGet_primitiveParam() { return HdGet_primitiveParam(0); } -int HdGetScalar_primitiveParam(int localIndex) { return HdGet_primitiveParam(localIndex); } -int HdGetScalar_primitiveParam() { return HdGet_primitiveParam(0); } -#if defined(HD_HAS_coarseFaceIndex) -FORWARD_DECL(int HdGetScalar_coarseFaceIndex()); -#endif -ivec3 GetPatchParam() { -#if defined(HD_HAS_coarseFaceIndex) - return ivec3(HdGetScalar_coarseFaceIndex(), 0, 0); -#else - return ivec3(GetPrimitiveID(), 0, 0); -#endif -} -int GetEdgeFlag() { - return (HdGet_primitiveParam() & 3); -} -int GetFVarIndex(int localIndex) { - int fvarCoord = GetDrawingCoord().fvarCoord; - int ptexIndex = GetPatchParam().x & 0xfffffff; - return fvarCoord + ptexIndex * 4 + localIndex; -} -int GetElementID() { - return (hd_int_get(HdGet_primitiveParam()) >> 2); -} -int GetAggregatedElementID() { - return GetElementID() - + GetDrawingCoord().elementCoord; -} -ivec2 HdGet_edgeIndices(int localIndex) { - int index = GetPrimitiveIndex(); - return ivec2(edgeIndices[index]); -} -ivec2 HdGet_edgeIndices() { return HdGet_edgeIndices(0); } -int HdGetScalar_edgeIndices(int localIndex) { return HdGet_edgeIndices(localIndex).x; } -int HdGetScalar_edgeIndices() { return HdGet_edgeIndices(0).x; } -int GetAuthoredEdgeId(int primitiveEdgeId) { - return primitiveEdgeId; -} -float HdGet_faceVisibility(int localIndex) { - int index = GetAggregatedElementID(); - return float(faceVisibility[index]); -} -float HdGet_faceVisibility() { return HdGet_faceVisibility(0); } -float HdGetScalar_faceVisibility(int localIndex) { return HdGet_faceVisibility(localIndex); } -float HdGetScalar_faceVisibility() { return HdGet_faceVisibility(0); } -vec3 HdGet_points(int localIndex) { return vec3(inPrimvars.points);} -vec3 HdGet_points() { return HdGet_points(0); } -float HdGetScalar_points(int localIndex) { return HdGet_points(localIndex).x; } -float HdGetScalar_points() { return HdGet_points(0).x; } -vec3 HdGet_normals(int localIndex) { return vec3(inPrimvars.normals);} -vec3 HdGet_normals() { return HdGet_normals(0); } -float HdGetScalar_normals(int localIndex) { return HdGet_normals(localIndex).x; } -float HdGetScalar_normals() { return HdGet_normals(0).x; } -vec2 HdGet_dispTextureCoord(int localIndex) { return vec2(inPrimvars.dispTextureCoord);} -vec2 HdGet_dispTextureCoord() { return HdGet_dispTextureCoord(0); } -float HdGetScalar_dispTextureCoord(int localIndex) { return HdGet_dispTextureCoord(localIndex).x; } -float HdGetScalar_dispTextureCoord() { return HdGet_dispTextureCoord(0).x; } -FORWARD_DECL(vec4 GetPatchCoord(int index)); -void ProcessSamplingTransforms(MAT4 instanceModelViewInverse) { -} - -// --------------------------------------------------------------------------- -// global defines -// --------------------------------------------------------------------------- -// codeGen can override this range (currently not). -// quadro 4000's max is 189. -#ifndef HD_GL_POINT_SIZE_MAX -#define HD_GL_POINT_SIZE_MAX 100.0 -#endif -#ifndef HD_GL_POINT_SIZE_MIN -#define HD_GL_POINT_SIZE_MIN .45 -#endif - -// --------------------------------------------------------------------------- -// render pass states -// --------------------------------------------------------------------------- - -MAT4 GetWorldToViewMatrix() { -#if defined(HD_HAS_worldToViewMatrix) - return MAT4(HdGet_worldToViewMatrix()); -#else - return MAT4(1); -#endif -} -MAT4 GetWorldToViewInverseMatrix() { -#if defined(HD_HAS_worldToViewInverseMatrix) - return MAT4(HdGet_worldToViewInverseMatrix()); -#else - return MAT4(1); -#endif -} -MAT4 GetProjectionMatrix() { -#if defined(HD_HAS_projectionMatrix) - return MAT4(HdGet_projectionMatrix()); -#else - return MAT4(1); -#endif -} -vec3 GetPositionInWorldSpace(vec3 windowRelativeCoord) -{ -#if defined(HD_HAS_imageToWorldMatrix) - vec4 pImage = vec4(windowRelativeCoord, 1.0); - vec4 pWorld = vec4(HdGet_imageToWorldMatrix() * pImage); - return (pWorld / pWorld.w).xyz; -#else - return windowRelativeCoord; -#endif -} -float GetLightingBlendAmount() { -#if defined(HD_HAS_lightingBlendAmount) - return HdGet_lightingBlendAmount(); -#else - return 1; -#endif -} -vec4 GetViewport() { -#if defined(HD_HAS_viewport) - return HdGet_viewport(); -#else - return vec4(0,0,1,1); -#endif -} -float GetTessLevel() { -#if defined(HD_HAS_tessLevel) - return HdGet_tessLevel(); -#else - return 1; -#endif -} -float GetPointSize() { -#if defined(HD_HAS_pointSize) - return HdGet_pointSize(); -#else - return 3.0; -#endif -} -float GetPointSelectedSize() { -#if defined(HD_HAS_pointSelectedSize) - return HdGet_pointSelectedSize(); -#else - return 5.0; -#endif -} -vec4 GetWireframeColor() { -// Individual prims can specify an alternative wireframe color -// to one specified in the render pass. This is used in cases were -// there is not enough contrast with the normal one. -#if defined(HD_HAS_overrideWireframeColor) - return HdGet_overrideWireframeColor(); -#elif defined(HD_HAS_wireframeColor) - return HdGet_wireframeColor(); -#else - return vec4(0,0,0,0); -#endif -} -vec4 GetMaskColor() { -#if defined(HD_HAS_maskColor) - return HdGet_maskColor(); -#else - return vec4(0.5,0,0,1); -#endif -} -vec4 GetIndicatorColor() { -#if defined(HD_HAS_indicatorColor) - return HdGet_indicatorColor(); -#else - return vec4(0,0.5,0,1); -#endif -} - -bool ShouldDiscardByAlpha(vec4 color) -{ -#if defined(HD_HAS_alphaThreshold) - float alphaThreshold = HdGet_alphaThreshold(); -#else - float alphaThreshold = 0; -#endif - return (color.a < alphaThreshold); -} - -vec2 ApplyAxisAlignedAffineTransform(vec4 t, vec2 pt) -{ - return t.xy * pt + t.zw; -} - - - -vec2 HorizontallyNormalizedFilmbackCoordinates() -{ - const vec4 transform = -#ifdef HD_HAS_imageToHorizontallyNormalizedFilmback - HdGet_imageToHorizontallyNormalizedFilmback(); -#else - vec4(vec2(1.0), vec2(0.0)); -#endif - return ApplyAxisAlignedAffineTransform(transform, gl_FragCoord.xy); -} - - - -vec4 ApplySelectionColor(vec4 color) -{ - return color; -} - - - -// Forward declare selection functionality. -// XXX: Currently, the non-empty implementation of this is in hdx. -FORWARD_DECL(vec4 ApplySelectionColor(vec4 color)); - -// XXX: Make sure to update hdx/shaders/renderPass.glslfx when editing these -// color override methods, since they're currently duplicated. This is because -// we don't have a mixin token for color overrides in a render pass yet. -vec4 ApplyColorOverrides(vec4 color) -{ -#if defined(HD_HAS_overrideColor) - // Mix in override color - vec4 overrideColor = HdGet_overrideColor(); - color.rgb = mix(color.rgb, overrideColor.rgb, overrideColor.a); -#endif - return ApplySelectionColor(color); -} - -vec3 ApplyMaskColor(vec3 color, float weight, vec4 maskColor) -{ - float strength = maskColor.a * clamp(weight, 0.0, 1.0); - return mix(color, maskColor.rgb, strength); -} - -vec4 ApplyColorOverridesPostLighting(vec4 color) -{ - #if defined(HD_HAS_maskWeight) - float maskWeight = HdGet_maskWeight(); - vec4 maskColor = GetMaskColor(); - color.rgb = ApplyMaskColor(color.rgb, maskWeight, maskColor); - #endif - #if defined(HD_HAS_indicatorWeight) - float indicatorWeight = HdGet_indicatorWeight(); - vec4 indicatorColor = GetIndicatorColor(); - color.rgb = ApplyMaskColor(color.rgb, indicatorWeight, indicatorColor); - #endif - return color; -} - - - -void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) -{ - colorOut = color; -} - - -#ifndef HD_HAS_integrateLights -#define HD_HAS_integrateLights -#endif - -struct LightingContribution { - vec3 diffuse; -}; - -struct LightingInterfaceProperties { - float unused; -}; - -LightingContribution -integrateLightsDefault(vec4 Peye, vec3 Neye, LightingInterfaceProperties props) -{ - vec3 n = normalize(Neye); - - LightingContribution result; - result.diffuse = vec3(dot(n, vec3(0,0,1))); - - return result; -} - -LightingContribution -integrateLightsConstant(vec4 Peye, vec3 Neye, LightingInterfaceProperties props) -{ - LightingContribution result; - //pefectly diffuse white hemisphere contribution - result.diffuse = vec3(1); - - return result; -} - - - -FORWARD_DECL( - LightingContribution integrateLights(vec4 Peye, vec3 Neye, - LightingInterfaceProperties props)); - -vec3 FallbackLighting(in vec3 Peye, in vec3 Neye, in vec3 color) -{ - LightingInterfaceProperties props; - LightingContribution light = integrateLights(vec4(Peye, 1), Neye, props); - return color * light.diffuse; -} - - -vec4 surfaceShader(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) -{ - // lighting - color.rgb = FallbackLighting(Peye.xyz, Neye, color.rgb); - return color; -} - - -// quaternion to matrix. xyz = imaginary, w = real -MAT4 GetRotationMatrix(vec4 q) -{ - MAT4 r; - r[0].xyzw = vec4(1 - 2 * (q.y * q.y + q.z * q.z), - 2 * (q.x * q.y + q.z * q.w), - 2 * (q.x * q.z - q.y * q.w), - 0); - r[1].xyzw = vec4( 2 * (q.x * q.y - q.z * q.w), - 1 - 2 * (q.x * q.x + q.z * q.z), - 2 * (q.y * q.z + q.x * q.w), - 0); - r[2].xyzw = vec4( 2 * (q.x * q.z + q.y * q.w), - 2 * (q.y * q.z - q.x * q.w), - 1 - 2 * (q.x * q.x + q.y * q.y), - 0); - r[3] = vec4(0, 0, 0, 1); - return r; -} - -// --------------------------------------------------------------------------- - -MAT4 GetInstanceTransform(int level) -{ - MAT4 m = MAT4(1); -#ifdef HD_HAS_INSTANCE_hydra_instanceTransforms - m = HdGetInstance_hydra_instanceTransforms(level, MAT4(1)) * m; -#elif defined(HD_HAS_INSTANCE_instanceTransform) - m = HdGetInstance_instanceTransform(level, MAT4(1)) * m; -#endif - - // instance transform elements are applied: - // scale then rotate then translate - // i.e. (T * R * S) * position - -#ifdef HD_HAS_INSTANCE_hydra_instanceScales - vec3 s = HdGetInstance_hydra_instanceScales(level, /*default=*/vec3(1)); - m = MAT4(s.x, 0, 0, 0, - 0, s.y, 0, 0, - 0, 0, s.z, 0, - 0, 0, 0, 1) * m; -#elif defined(HD_HAS_INSTANCE_instanceScale) - vec3 s = HdGetInstance_scale(level, /*default=*/vec3(1)); - m = MAT4(s.x, 0, 0, 0, - 0, s.y, 0, 0, - 0, 0, s.z, 0, - 0, 0, 0, 1) * m; -#endif - -#ifdef HD_HAS_INSTANCE_hydra_instanceRotations // GfQuat(ix, iy, iz, real) - vec4 q = HdGetInstance_hydra_instanceRotations(level, /*default=*/vec4(0)); - m = GetRotationMatrix(q) * m; -#elif defined(HD_HAS_INSTANCE_rotate) - vec4 q = HdGetInstance_rotate(level, /*default=*/vec4(0)); - m = GetRotationMatrix(q) * m; -#endif - -#ifdef HD_HAS_INSTANCE_hydra_instanceTranslations - vec3 t = HdGetInstance_hydra_instanceTranslations(level, /*default=*/vec3(0)); - m = MAT4( 1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, 1, 0, - t.x, t.y, t.z, 1) * m; -#elif defined(HD_HAS_INSTANCE_translate) - vec3 t = HdGetInstance_translate(level, /*default=*/vec3(0)); - m = MAT4( 1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, 1, 0, - t.x, t.y, t.z, 1) * m; -#endif - return m; -} - -MAT4 GetInstanceTransformInverse(int level) -{ - MAT4 m = MAT4(1); - -#ifdef HD_HAS_INSTANCE_hydra_instanceTransforms - m = inverse(HdGetInstance_hydra_instanceTransforms(level, MAT4(1))) * m; -#elif defined(HD_HAS_INSTANCE_instanceTransform) - m = inverse(HdGetInstance_instanceTransform(level, MAT4(1))) * m; -#endif - -#ifdef HD_HAS_INSTANCE_hydra_instanceTranslations - vec3 it = -HdGetInstance_hydra_instanceTranslations(level, /*default=*/vec3(0)); // negate - m = MAT4( 1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, 1, 0, - it.x, it.y, it.z, 1) * m; -#elif defined(HD_HAS_INSTANCE_translate) - vec3 it = -HdGetInstance_translate(level, /*default=*/vec3(0)); // negate - m = MAT4( 1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, 1, 0, - it.x, it.y, it.z, 1) * m; -#endif - -#ifdef HD_HAS_INSTANCE_hydra_instanceRotations - vec4 q = HdGetInstance_hydra_instanceRotations(level, /*default=*/vec4(0)); - q.xyz = -q.xyz; // inverse rotataion axis - m = GetRotationMatrix(q) * m; -#elif defined(HD_HAS_INSTANCE_rotate) - vec4 q = HdGetInstance_rotate(level, /*default=*/vec4(0)); - q.xyz = -q.xyz; // inverse rotataion axis - m = GetRotationMatrix(q) * m; -#endif - -#ifdef HD_HAS_INSTANCE_hydra_instanceScales - vec3 is = 1.0/HdGetInstance_hydra_instanceScales(level, /*default=*/vec3(1)); // inverse scale - m = MAT4(is.x, 0, 0, 0, - 0, is.y, 0, 0, - 0, 0, is.z, 0, - 0, 0, 0, 1) * m; -#elif defined(HD_HAS_INSTANCE_scale) - vec3 is = 1.0/HdGetInstance_scale(level, /*default=*/vec3(1)); // inverse scale - m = MAT4(is.x, 0, 0, 0, - 0, is.y, 0, 0, - 0, 0, is.z, 0, - 0, 0, 0, 1) * m; -#endif - return m; -} - -// --------------------------------------------------------------------------- - -MAT4 GetInstanceTransform() -{ - MAT4 m = MAT4(1); -#ifdef HD_INSTANCER_NUM_LEVELS - for (int i = 0; i < HD_INSTANCER_NUM_LEVELS; ++i) { - m = GetInstanceTransform(i) * m; -#ifdef HD_HAS_instancerTransform - m = HdGet_instancerTransform(i) * m; -#endif - } -#endif - return m; -} - -MAT4 GetInstanceTransformInverse() -{ - MAT4 m = MAT4(1); -#ifdef HD_INSTANCER_NUM_LEVELS - for (int i = 0; i < HD_INSTANCER_NUM_LEVELS; ++i) { - m = m * GetInstanceTransformInverse(i); -#ifdef HD_HAS_instancerTransformInverse - m = m * HdGet_instancerTransformInverse(i); -#endif - } -#endif - return m; -} - -// --------------------------------------------------------------------------- - -MAT4 ApplyInstanceTransform(MAT4 m) -{ - return GetInstanceTransform() * m; -} - -MAT4 ApplyInstanceTransformInverse(MAT4 m) -{ - return m * GetInstanceTransformInverse(); -} - -bool IsFlipped() -{ -#if defined(HD_HAS_isFlipped) - bool flip = (HdGet_isFlipped() != 0); -#elif defined(HD_HAS_transform) - // The sign of the determinant indicates whether m flips handedness - bool flip = (determinant(HdGet_transform()) < 0.0); -#else - bool flip = false; -#endif - -#ifdef HD_HAS_INSTANCE_hydra_instanceScales - for (int i = 0; i < HD_INSTANCER_NUM_LEVELS; ++i) { - vec3 scale = HdGetInstance_hydra_instanceScales(i, /*default=*/vec3(1)); - flip = flip != ((sign(scale.x) * sign(scale.y) * sign(scale.z)) < 0); - } -#elif defined(HD_HAS_INSTANCE_scale) - for (int i = 0; i < HD_INSTANCER_NUM_LEVELS; ++i) { - vec3 scale = HdGetInstance_scale(i, /*default=*/vec3(1)); - flip = flip != ((sign(scale.x) * sign(scale.y) * sign(scale.z)) < 0); - } -#endif - -#ifdef HD_HAS_INSTANCE_hydra_instanceTransforms - for (int i = 0; i < HD_INSTANCER_NUM_LEVELS; ++i) { - MAT4 m = HdGetInstance_hydra_instanceTransforms(i, MAT4(1)); - flip = flip != (determinant(m) < 0.0); - } -#elif defined(HD_HAS_INSTANCE_instanceTransform) - for (int i = 0; i < HD_INSTANCER_NUM_LEVELS; ++i) { - MAT4 m = HdGetInstance_instanceTransform(i, MAT4(1)); - flip = flip != (determinant(m) < 0.0); - } -#endif - - return flip; -} - - -vec3 GetNormal(vec3 Neye, int index) -{ - return Neye; -} - -vec3 GetNormal(vec3 Neye, int index, vec2 localST) -{ - return GetNormal(Neye, index); -} - - - -vec3 GetShadingNormal(vec3 N, bool isFlipped) -{ - // the fragment shader takes already-flipped-normals. - // no need to flip here. - return N; -} - - - -void DiscardBasedOnShading(bool frontFacing, bool isFlipped) -{ - // Nothing to do since h/w face culling is used. -} - - - -vec4 ApplyEdgeColor(vec4 Cfill, vec4 patchCoord) -{ - return Cfill; -} - -// Return a large value, signifying that the fragment isn't near an edge. -float GetMinEdgeDistance() -{ - return 1000.0; -} - - - -vec3 GetEdgeParamTriangle() -{ - // Expand barycentric coordinates - vec2 param = GetPatchCoord(0).xy; - vec3 barycentric = vec3(param.x, param.y, 1 - param.x - param.y); - - // Match triangle edge order - return barycentric.yzx; -} - -vec3 GetEdgeDistanceTriangle() -{ - vec3 param = GetEdgeParamTriangle(); - return max(vec3(0.0), param / fwidth(param)); -} - -vec4 GetEdgeParamQuad() -{ - // Expand coordinates to opposite corners of quad - vec2 leftBottom = GetPatchCoord(0).xy; - vec2 rightTop = vec2(1.0) - leftBottom; - - // Match quad edge order - return vec4(leftBottom.y, rightTop.x, rightTop.y, leftBottom.x); -} - -vec4 GetEdgeDistanceQuad() -{ - vec4 param = GetEdgeParamQuad(); - return max(vec4(0.0), param / fwidth(param)); -} - - - -struct ReprStyle -{ - vec4 color; - bool usePrimvarColor; - bool usePrimvarAlpha; - bool applyColorOverride; - bool useSurfaceShaderColor; - bool useSurfaceShaderAlpha; -}; - -struct ScalarOverride -{ - bool enabled; - vec3 color; -}; - -FORWARD_DECL(ReprStyle GetReprStyle()); -FORWARD_DECL(ScalarOverride GetScalarOverride()); -FORWARD_DECL( - vec4 surfaceShader(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord)); -FORWARD_DECL(vec4 postSurfaceShader(vec4 Peye, vec3 Neye, vec4 color)); - -vec4 ShadingTerminal(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) -{ - ReprStyle reprStyle = GetReprStyle(); - - // Apply scalar override. - ScalarOverride scalarOverride = GetScalarOverride(); - if (scalarOverride.enabled) { - vec4 result; - - result.rgb = scalarOverride.color; - result.a = reprStyle.usePrimvarAlpha ? color.a: reprStyle.color.a; - - vec4 colorOverride = ApplyColorOverrides(result); - result = reprStyle.applyColorOverride ? colorOverride : result; - - return result; - } - - // Draw mode can override face color - vec4 reprColor; - - reprColor.rgb = reprStyle.usePrimvarColor ? color.rgb : reprStyle.color.rgb; - reprColor.a = reprStyle.usePrimvarAlpha ? color.a : reprStyle.color.a; - - // Compute color overrides - vec4 colorOverride = ApplyColorOverrides(reprColor); - reprColor = reprStyle.applyColorOverride ? colorOverride : reprColor; - - - // Surface shading can be expensive and also can contain undesirable - // side effects (like discards). So only run it for reprs that require it. - - if (reprStyle.useSurfaceShaderColor || - reprStyle.useSurfaceShaderAlpha) { - vec4 shadingColor; - - shadingColor = surfaceShader(Peye, - Neye, - reprColor, - patchCoord); - -#ifdef HD_HAS_postSurfaceShader - shadingColor = postSurfaceShader(Peye, - Neye, - shadingColor); -#endif - - reprColor.rgb = reprStyle.useSurfaceShaderColor ? - shadingColor.rgb : - reprColor.rgb; - - reprColor.a = reprStyle.useSurfaceShaderAlpha ? - shadingColor.a : - reprColor.a; - } - - vec4 baseColor = color; - baseColor = ApplyColorOverrides(baseColor); - - vec4 litColor = mix(baseColor, - reprColor, - GetLightingBlendAmount()); - - // Final overrides. - - return ApplyColorOverridesPostLighting(litColor); -} - - - -#ifdef HD_HAS_integrateLights -#ifndef HD_HAS_definedIntegrateLights -#define HD_HAS_definedIntegrateLights - -LightingContribution -integrateLights(vec4 Peye, vec3 Neye, LightingInterfaceProperties props) -{ - return integrateLightsDefault(Peye, Neye, props); -} - -#endif // HD_HAS_definedIntegrateLights -#endif - -ReprStyle GetReprStyle() -{ - ReprStyle reprStyle; - - reprStyle.color = vec4(0.0, 0.0, 0.0, 1.0); - reprStyle.usePrimvarColor = true; - reprStyle.usePrimvarAlpha = true; - reprStyle.applyColorOverride = true; - reprStyle.useSurfaceShaderColor = true; - reprStyle.useSurfaceShaderAlpha = true; - - return reprStyle; -} - - - -ScalarOverride GetScalarOverride() -{ - ScalarOverride result; - -#if defined(HD_HAS_scalarOverride) - result.enabled = true; - - // Allow a scalar value to override the color from the surface - // for previewing heatmaps. This is useful for editing workflows. -#if defined(HD_HAS_scalarOverrideColorRamp) - int rampCount = constantPrimvars[GetDrawingCoord().constantCoord]. - scalarOverrideColorRamp.length(); - float scalar = HdGet_scalarOverride() * float(rampCount - 1); - float baseIndex = floor(scalar); - float nextIndex = min(float(rampCount - 1), baseIndex + 1.0); - float interp = scalar - baseIndex; - result.color = mix(HdGet_scalarOverrideColorRamp(int(baseIndex)).rgb, - HdGet_scalarOverrideColorRamp(int(nextIndex)).rgb, - interp); -#else - // If no ramp is given just gamma correct the scalar as greyscale. - result.color = vec3(pow(HdGet_scalarOverride(), 2.2)); -#endif // HD_HAS_scalarOverrideColorRamp - -#else // HD_HAS_scalarOverride - result.enabled = false; - result.color = vec3(0.0, 0.0, 0.0); -#endif - - return result; -} - - - -// Determines whether a fragment is on or close to an unhidden triangle edge. -const float edgePickRadius = 2; // in viewport pixels -const float edgePickParametricRadius = 0.02; // in parametric space - -// For smooth looking edges, use an exponential falloff for the opacity. -// Note: We use a slower falloff fn than in meshWire.glslfx to make the -// selected edges stand out. -float SelectedEdgeFalloff(float d) { - return exp2(-1 * d * d); -} - - - -vec4 ComputeBaseFaceEdgeDistanceQuad() -{ - return GetEdgeDistanceQuad(); -} - -bool SelectWireframeFaceEdges() -{ - return false; -} - - - -float GetSelectedEdgeOpacity() -{ - float closestEdgeDistance = 0.0; - - // The sequence of comparisons should match GetPrimitiveEdgeId() - vec4 dist = ComputeBaseFaceEdgeDistanceQuad(); - if (dist.x < edgePickRadius) { - closestEdgeDistance = dist.x; - } else if (dist.y < edgePickRadius) { - closestEdgeDistance = dist.y; - } else if (dist.z < edgePickRadius) { - closestEdgeDistance = dist.z; - } else if (dist.w < edgePickRadius) { - closestEdgeDistance = dist.w; - } else { - return 0; - } - - return SelectedEdgeFalloff(closestEdgeDistance); -} - -// called from hdx/renderPass.glslfx and selection.glslfx -int GetPrimitiveEdgeId() -{ - // e2 - // (0,1) 3 ------ 2 (1,1) - // | | - // e3 | | e1 - // | | - // (0,0) 0 ------ 1 (1,0) - // e0 - - int edgeId = -1; - - vec4 dist = ComputeBaseFaceEdgeDistanceQuad(); - if (dist.x < edgePickRadius) { - edgeId = 0; - } else if (dist.y < edgePickRadius) { - edgeId = 1; - } else if (dist.z < edgePickRadius) { - edgeId = 2; - } else if (dist.w < edgePickRadius) { - edgeId = 3; - } else { - return -1; // Not on a mesh edge - } - - const int edgeFlag = GetEdgeFlag(); - const ivec2 meshEdgeIndices = HdGet_edgeIndices(); - - // Translate face-edge to authored mesh-edge - if (edgeFlag == 0) { - edgeId = meshEdgeIndices[0] + edgeId; // regular quad face - } else if (edgeId == 0) { - edgeId = meshEdgeIndices[0]; - } else if (edgeId == 3) { - edgeId = meshEdgeIndices[1]; - } else { - edgeId = -1; // Not an authored mesh edge - } - return edgeId; -} - - -int GetPointId() -{ - return -1; -} - - -void DiscardBasedOnTopologicalVisibility() -{ - // Nothing to do, since there's no authored opinion. -} - - - -vec4 GetInterpolatedPatchCoord() -{ - return gsPatchCoord; -} - - - -#ifndef HD_HAS_ptexFaceOffset -#define HD_HAS_ptexFaceOffset -int HdGet_ptexFaceOffset() -{ - return 0; -} -#endif - -vec4 GetPatchCoord(int localIndex) -{ - vec4 patchCoord = GetInterpolatedPatchCoord(); - return vec4(patchCoord.xyz, patchCoord.w + HdGet_ptexFaceOffset()); -} - -vec4 GetPatchCoord() -{ - return GetPatchCoord(0); -} - -vec3 ComputeScreenSpacePeye() -{ - return inData.Peye.xyz / inData.Peye.w; -} - -vec3 ComputeScreenSpaceNeye() -{ - vec3 Peye = ComputeScreenSpacePeye(); - vec3 Neye = normalize(cross(dFdx(Peye), dFdy(Peye))); - return (gl_FrontFacing ? Neye : -Neye); -} - -void main(void) -{ - bool isFlipped = IsFlipped(); - - DiscardBasedOnShading(gl_FrontFacing, isFlipped); - - DiscardBasedOnTopologicalVisibility(); - - vec4 color = vec4(0.5, 0.5, 0.5, 1); -#ifdef HD_HAS_displayColor - color.rgb = HdGet_displayColor().rgb; -#endif -#ifdef HD_HAS_displayOpacity - color.a = HdGet_displayOpacity(); -#endif - - vec3 Peye = ComputeScreenSpacePeye(); - - vec3 Neye = inData.Neye; - // Normalize Neye after rasterizer interpolation. - if (length(Neye) > 0.0) { - Neye = normalize(Neye); - } - // Give the shader key a chance to override the normal. - Neye = GetNormal(Neye, 0); - // Orient the normal for shading. - Neye = GetShadingNormal(Neye, isFlipped); - - vec4 patchCoord = GetPatchCoord(); - color = ShadingTerminal(vec4(Peye, 1), Neye, color, patchCoord); - - color = ApplyEdgeColor(color, patchCoord); - -#ifdef HD_MATERIAL_TAG_MASKED - if (ShouldDiscardByAlpha(color)) { - discard; - return; - } -#endif - - RenderOutput(vec4(Peye, 1), Neye, color, patchCoord); -} - -OK diff --git a/pxr/imaging/hdSt/testenv/testHdStCodeGen_GL/baseline/codegen_mesh_bindless_indirect_instance.out b/pxr/imaging/hdSt/testenv/testHdStCodeGen_GL/baseline/codegen_mesh_bindless_indirect_instance.out deleted file mode 100644 index 63f827af517..00000000000 --- a/pxr/imaging/hdSt/testenv/testHdStCodeGen_GL/baseline/codegen_mesh_bindless_indirect_instance.out +++ /dev/null @@ -1,5603 +0,0 @@ -------------------------------------------------------- --- glslfx version 0.1 -#import $TOOLS/hdSt/shaders/mesh.glslfx --- configuration -{"techniques": {"default": { -"vertexShader" : { "source" : ["Instancing.Transform", "MeshNormal.Pass", "PointId.Vertex.None", "Mesh.Vertex"] } -, "geometryShader" : { "source" : ["Instancing.Transform", "MeshNormal.Flat", "MeshNormal.Geometry.NoFlat", "Geometry.NoCustomDisplacement", "Mesh.Geometry.Triangle"] } -, "fragmentShader" : { "source" : ["Instancing.Transform", "MeshNormal.Pass", "MeshNormal.Fragment.SingleSided", "MeshFaceCull.Fragment.None", "MeshWire.Fragment.NoEdge", "MeshWire.Fragment.EdgeParam", "Fragment.CommonTerminals", "Fragment.Surface", "Fragment.ScalarOverride", "EdgeId.Fragment.Common", "EdgeId.Fragment.TriangleSurface", "EdgeId.Fragment.TriangleParam", "PointId.Fragment.Fallback", "Visibility.Fragment.Fallback", "Mesh.Fragment.PatchCoord", "Mesh.Fragment"] } -}}} -------------------------------------------------------- -======================================================= - VERTEX SHADER -======================================================= -#version 450 -#extension GL_NV_shader_buffer_load : require -#extension GL_NV_gpu_shader5 : require -#extension GL_ARB_bindless_texture : require -#extension GL_ARB_shader_draw_parameters : require -int HgiGetBaseVertex() { - return gl_BaseVertexARB; -} -#define REF(space,type) inout type -#define FORWARD_DECL(func_decl) func_decl; -#define ATOMIC_LOAD(a) (a) -#define ATOMIC_STORE(a, v) (a) = (v) -#define ATOMIC_ADD(a, v) atomicAdd(a, v) -#define ATOMIC_EXCHANGE(a, v) atomicExchange(a, v) -#define ATOMIC_COMP_SWAP(a, expected, desired) atomicCompSwap(a, expected, desired) -#define atomic_int int -#define atomic_uint uint - -#define HGI_HAS_DOUBLE_TYPE 1 - - -struct hgi_ivec3 { int x, y, z; }; -struct hgi_vec3 { float x, y, z; }; -struct hgi_dvec3 { double x, y, z; }; -struct hgi_mat3 { float m00, m01, m02, - m10, m11, m12, - m20, m21, m22; }; -struct hgi_dmat3 { double m00, m01, m02, - m10, m11, m12, - m20, m21, m22; }; - - -// //////// Codegen Defines //////// -#define HD_SHADER_API 2 -#define MAT4 mat4 -// Alias hgi vec and matrix types to hd. -#define hd_ivec3 hgi_ivec3 -#define hd_vec3 hgi_vec3 -#define hd_dvec3 hgi_dvec3 -#define hd_mat3 hgi_mat3 -#define hd_dmat3 hgi_dmat3 - -ivec3 hd_ivec3_get(hd_ivec3 v) { return ivec3(v.x, v.y, v.z); } -ivec3 hd_ivec3_get(ivec3 v) { return v; } -vec3 hd_vec3_get(hd_vec3 v) { return vec3(v.x, v.y, v.z); } -vec3 hd_vec3_get(vec3 v) { return v; } -dvec3 hd_dvec3_get(hd_dvec3 v) { return dvec3(v.x, v.y, v.z); } -dvec3 hd_dvec3_get(dvec3 v) { return v; } -mat3 hd_mat3_get(hd_mat3 v) { return mat3(v.m00, v.m01, v.m02, - v.m10, v.m11, v.m12, - v.m20, v.m21, v.m22); } -mat3 hd_mat3_get(mat3 v) { return v; } -dmat3 hd_dmat3_get(hd_dmat3 v) { return dmat3(v.m00, v.m01, v.m02, - v.m10, v.m11, v.m12, - v.m20, v.m21, v.m22); } -dmat3 hd_dmat3_get(dmat3 v) { return v; } -hd_ivec3 hd_ivec3_set(hd_ivec3 v) { return v; } -hd_ivec3 hd_ivec3_set(ivec3 v) { return hd_ivec3(v.x, v.y, v.z); } -hd_vec3 hd_vec3_set(hd_vec3 v) { return v; } -hd_vec3 hd_vec3_set(vec3 v) { return hd_vec3(v.x, v.y, v.z); } -hd_dvec3 hd_dvec3_set(hd_dvec3 v) { return v; } -hd_dvec3 hd_dvec3_set(dvec3 v) { return hd_dvec3(v.x, v.y, v.z); } -hd_mat3 hd_mat3_set(hd_mat3 v) { return v; } -hd_mat3 hd_mat3_set(mat3 v) { return hd_mat3(v[0][0], v[0][1], v[0][2], - v[1][0], v[1][1], v[1][2], - v[2][0], v[2][1], v[2][2]); } -hd_dmat3 hd_dmat3_set(hd_dmat3 v) { return v; } -hd_dmat3 hd_dmat3_set(dmat3 v) { return hd_dmat3(v[0][0], v[0][1], v[0][2], - v[1][0], v[1][1], v[1][2], - v[2][0], v[2][1], v[2][2]); } -int hd_int_get(int v) { return v; } -int hd_int_get(ivec2 v) { return v.x; } -int hd_int_get(ivec3 v) { return v.x; } -int hd_int_get(ivec4 v) { return v.x; } -vec3 hd_sample_udim(vec2 v) { -vec2 vf = floor(v); -return vec3(v.x - vf.x, v.y - vf.y, clamp(vf.x, 0.0, 10.0) + 10.0 * vf.y); -} -vec4 hd_vec4_2_10_10_10_get(int v) { - ivec4 unpacked = ivec4((v & 0x3ff) << 22, (v & 0xffc00) << 12, - (v & 0x3ff00000) << 2, (v & 0xc0000000)); - return vec4(unpacked) / 2147483647.0; } -int hd_vec4_2_10_10_10_set(vec4 v) { - return ( (int(v.x * 511.0) & 0x3ff) | - ((int(v.y * 511.0) & 0x3ff) << 10) | - ((int(v.z * 511.0) & 0x3ff) << 20) | - ((int(v.w) & 0x1) << 30)); } -vec2 hd_half2_get(uint v) { - return unpackHalf2x16(v); } -uint hd_half2_set(vec2 v) { - return packHalf2x16(v); } -vec4 hd_half4_get(uvec2 v) { - return vec4(unpackHalf2x16(v.x), unpackHalf2x16(v.y)); } -uvec2 hd_half4_set(vec4 v) { - return uvec2(packHalf2x16(v.xy), packHalf2x16(v.zw)); } -#define HD_NUM_PRIMITIVE_VERTS 3 -#define HD_HAS_transform 1 -#define HD_HAS_transformInverse 1 -#define HD_HAS_color 1 -#define HD_HAS_primID 1 -#define HD_HAS_widths 1 -#define HD_HAS_INSTANCE_hydra_instanceTranslations 1 -#define HD_HAS_hydra_instanceTranslations_0 1 -#define HD_INSTANCER_NUM_LEVELS 1 -#define HD_INSTANCE_INDEX_WIDTH 2 -#define HD_HAS_faceVisibility 1 -#define HD_HAS_dispTextureCoord 1 -#define HD_HAS_points 1 -#define HD_HAS_normals 1 - - -// //////// Global Includes //////// - -// //////// Global Macros //////// - -// //////// Global Structs //////// - -// //////// Global Member Declarations //////// -uint hd_VertexID = gl_VertexID; -uint hd_InstanceID = gl_InstanceID; -uint hd_BaseInstance = 0; - -// //////// Global Function Definitions //////// - - -// //////// Codegen Decl //////// -struct hd_drawingCoord { - int modelCoord; - int constantCoord; - int elementCoord; - int primitiveCoord; - int fvarCoord; - int shaderCoord; - int vertexCoord; - int topologyVisibilityCoord; - int varyingCoord; - int instanceIndex[HD_INSTANCE_INDEX_WIDTH]; - int instanceCoords[HD_INSTANCE_INDEX_WIDTH]; -}; -FORWARD_DECL(hd_drawingCoord GetDrawingCoord()); -FORWARD_DECL(int HgiGetBaseVertex()); -struct hd_instanceIndex { int indices[HD_INSTANCE_INDEX_WIDTH]; }; -struct ConstantData10 { - mat4 transform; - mat4 transformInverse; - vec4 color; - vec4 primID; - float widths; -}; -FORWARD_DECL(int GetElementID()); -FORWARD_DECL(int GetAggregatedElementID()); -FORWARD_DECL(int GetPrimitiveEdgeId()); -FORWARD_DECL(float GetSelectedEdgeOpacity()); -layout (location = 2) in ivec4 drawingCoord0; -layout (location = 3) in ivec4 drawingCoord1; -layout (location = 4) in ivec2 drawingCoord2; -layout (location = 5) in int drawingCoordI0; -layout (location = 0) in vec3 points; -layout (location = 1) in vec3 normals; -out flat int vs_dc_modelCoord; -out flat int vs_dc_constantCoord; -out flat int vs_dc_elementCoord; -out flat int vs_dc_primitiveCoord; -out flat int vs_dc_fvarCoord; -out flat int vs_dc_shaderCoord; -out flat int vs_dc_vertexCoord; -out flat int vs_dc_topologyVisibilityCoord; -out flat int vs_dc_varyingCoord; -out flat int vs_dc_instanceIndexI0; -out flat int vs_dc_instanceIndexI1; -out flat int vs_dc_instanceCoordsI0; -out flat int vs_dc_instanceCoordsI1; -layout(location = 6) uniform int *instanceIndices; -layout(location = 7) uniform int *culledInstanceIndices; -layout(location = 0) uniform ConstantData10 *constantPrimvars; -layout(location = 1) uniform hd_vec3 *hydra_instanceTranslations_0; -layout(location = 2) uniform int *primitiveParam; -layout(location = 3) uniform int *edgeIndices; -layout(location = 4) uniform float *faceVisibility; -out VertexData { - vec4 Peye; - vec3 Neye; -} outData; -out PrimvarData { - vec3 points; - vec3 normals; -} outPrimvars; - -// //////// Codegen Accessors //////// -mat4 HdGet_transform(int localIndex) { - int index = GetDrawingCoord().constantCoord; - return mat4(constantPrimvars[index].transform); -} -mat4 HdGet_transform() { return HdGet_transform(0); } -mat4 HdGet_transformInverse(int localIndex) { - int index = GetDrawingCoord().constantCoord; - return mat4(constantPrimvars[index].transformInverse); -} -mat4 HdGet_transformInverse() { return HdGet_transformInverse(0); } -vec4 HdGet_color(int localIndex) { - int index = GetDrawingCoord().constantCoord; - return vec4(constantPrimvars[index].color); -} -vec4 HdGet_color() { return HdGet_color(0); } -float HdGetScalar_color(int localIndex) { return HdGet_color(localIndex).x; } -float HdGetScalar_color() { return HdGet_color(0).x; } -vec4 HdGet_primID(int localIndex) { - int index = GetDrawingCoord().constantCoord; - return vec4(constantPrimvars[index].primID); -} -vec4 HdGet_primID() { return HdGet_primID(0); } -float HdGetScalar_primID(int localIndex) { return HdGet_primID(localIndex).x; } -float HdGetScalar_primID() { return HdGet_primID(0).x; } -float HdGet_widths(int localIndex) { - int index = GetDrawingCoord().constantCoord; - return float(constantPrimvars[index].widths); -} -float HdGet_widths() { return HdGet_widths(0); } -float HdGetScalar_widths(int localIndex) { return HdGet_widths(localIndex); } -float HdGetScalar_widths() { return HdGet_widths(0); } -vec3 HdGet_hydra_instanceTranslations_0(int localIndex) { - int index = GetDrawingCoord().instanceCoords[0]; - return hd_vec3_get(hydra_instanceTranslations_0[index]); -} -vec3 HdGet_hydra_instanceTranslations_0() { return HdGet_hydra_instanceTranslations_0(0); } -float HdGetScalar_hydra_instanceTranslations_0(int localIndex) { return HdGet_hydra_instanceTranslations_0(localIndex).x; } -float HdGetScalar_hydra_instanceTranslations_0() { return HdGet_hydra_instanceTranslations_0(0).x; } -vec3 HdGetInstance_hydra_instanceTranslations(int level, vec3 defaultValue) { - if (level == 0) return HdGet_hydra_instanceTranslations_0(); - return defaultValue; -} -#if !defined(HD_HAS_hydra_instanceTranslations) -#define HD_HAS_hydra_instanceTranslations 1 -vec3 HdGet_hydra_instanceTranslations(int localIndex) { - return HdGet_hydra_instanceTranslations_0(); -} -vec3 HdGet_hydra_instanceTranslations() { return HdGet_hydra_instanceTranslations(0); } -#endif - -// //////// Codegen VS Source //////// -#define HD_BINDLESS_BUFFERS_ENABLED -int GetBaseInstanceIndexCoord() { - return drawingCoord1.y; -} -int GetCurrentInstance() { - return int(hd_InstanceID - hd_BaseInstance); -} -int GetInstanceIndexCoord() { - return GetBaseInstanceIndexCoord() + GetCurrentInstance() * HD_INSTANCE_INDEX_WIDTH; -} -int HdGet_culledInstanceIndices(int localIndex) { - int index = GetInstanceIndexCoord()+localIndex + 1; - return int(culledInstanceIndices[index]); -} -int HdGet_culledInstanceIndices() { return HdGet_culledInstanceIndices(0); } -int HdGetScalar_culledInstanceIndices(int localIndex) { return HdGet_culledInstanceIndices(localIndex); } -int HdGetScalar_culledInstanceIndices() { return HdGet_culledInstanceIndices(0); } -int GetBaseVertexOffset() { - return HgiGetBaseVertex(); -} -hd_instanceIndex GetInstanceIndex() { - hd_instanceIndex r; - for (int i = 0; i < HD_INSTANCE_INDEX_WIDTH; ++i) - r.indices[i] = HdGet_culledInstanceIndices(/*localIndex=*/i); - return r; -} -hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = drawingCoord0.x; - dc.constantCoord = drawingCoord0.y; - dc.elementCoord = drawingCoord0.z; - dc.primitiveCoord = drawingCoord0.w; - dc.fvarCoord = drawingCoord1.x; - dc.shaderCoord = drawingCoord1.z; - dc.vertexCoord = drawingCoord1.w; - dc.topologyVisibilityCoord = drawingCoord2.x; - dc.varyingCoord = drawingCoord2.y; - hd_instanceIndex r = GetInstanceIndex(); - dc.instanceIndex[0] = r.indices[0]; - dc.instanceIndex[1] = r.indices[1]; - dc.instanceCoords[0] = drawingCoordI0 + dc.instanceIndex[1]; - return dc; -} -vec3 HdGet_points(int localIndex) { return hd_vec3_get(points);} -vec3 HdGet_points() { return HdGet_points(0); } -float HdGetScalar_points(int localIndex) { return HdGet_points(localIndex).x; } -float HdGetScalar_points() { return HdGet_points(0).x; } -vec3 HdGet_normals(int localIndex) { return hd_vec3_get(normals);} -vec3 HdGet_normals() { return HdGet_normals(0); } -float HdGetScalar_normals(int localIndex) { return HdGet_normals(localIndex).x; } -float HdGetScalar_normals() { return HdGet_normals(0).x; } - -// //////// Codegen Proc VS //////// -void ProcessPrimvarsIn() { - hd_drawingCoord dc = GetDrawingCoord(); - vs_dc_modelCoord = dc.modelCoord; - vs_dc_constantCoord = dc.constantCoord; - vs_dc_elementCoord = dc.elementCoord; - vs_dc_primitiveCoord = dc.primitiveCoord; - vs_dc_fvarCoord = dc.fvarCoord; - vs_dc_shaderCoord = dc.shaderCoord; - vs_dc_vertexCoord = dc.vertexCoord; - vs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - vs_dc_varyingCoord = dc.varyingCoord; - vs_dc_instanceIndexI0 = dc.instanceIndex[0]; - vs_dc_instanceIndexI1 = dc.instanceIndex[1]; - vs_dc_instanceCoordsI0 = dc.instanceCoords[0]; - outPrimvars.points = points; - outPrimvars.normals = normals; -} - -// --------------------------------------------------------------------------- -// global defines -// --------------------------------------------------------------------------- -// codeGen can override this range (currently not). -// quadro 4000's max is 189. -#ifndef HD_GL_POINT_SIZE_MAX -#define HD_GL_POINT_SIZE_MAX 100.0 -#endif -#ifndef HD_GL_POINT_SIZE_MIN -#define HD_GL_POINT_SIZE_MIN .45 -#endif - -// --------------------------------------------------------------------------- -// render pass states -// --------------------------------------------------------------------------- - -MAT4 GetWorldToViewMatrix() { -#if defined(HD_HAS_worldToViewMatrix) - return MAT4(HdGet_worldToViewMatrix()); -#else - return MAT4(1); -#endif -} -MAT4 GetWorldToViewInverseMatrix() { -#if defined(HD_HAS_worldToViewInverseMatrix) - return MAT4(HdGet_worldToViewInverseMatrix()); -#else - return MAT4(1); -#endif -} -MAT4 GetProjectionMatrix() { -#if defined(HD_HAS_projectionMatrix) - return MAT4(HdGet_projectionMatrix()); -#else - return MAT4(1); -#endif -} -vec3 GetPositionInWorldSpace(vec3 windowRelativeCoord) -{ -#if defined(HD_HAS_imageToWorldMatrix) - vec4 pImage = vec4(windowRelativeCoord, 1.0); - vec4 pWorld = vec4(HdGet_imageToWorldMatrix() * pImage); - return (pWorld / pWorld.w).xyz; -#else - return windowRelativeCoord; -#endif -} -float GetLightingBlendAmount() { -#if defined(HD_HAS_lightingBlendAmount) - return HdGet_lightingBlendAmount(); -#else - return 1; -#endif -} -vec4 GetViewport() { -#if defined(HD_HAS_viewport) - return HdGet_viewport(); -#else - return vec4(0,0,1,1); -#endif -} -float GetTessLevel() { -#if defined(HD_HAS_tessLevel) - return HdGet_tessLevel(); -#else - return 1; -#endif -} -float GetPointSize() { -#if defined(HD_HAS_pointSize) - return HdGet_pointSize(); -#else - return 3.0; -#endif -} -float GetPointSelectedSize() { -#if defined(HD_HAS_pointSelectedSize) - return HdGet_pointSelectedSize(); -#else - return 5.0; -#endif -} -vec4 GetWireframeColor() { -// Individual prims can specify an alternative wireframe color -// to one specified in the render pass. This is used in cases were -// there is not enough contrast with the normal one. -#if defined(HD_HAS_overrideWireframeColor) - return HdGet_overrideWireframeColor(); -#elif defined(HD_HAS_wireframeColor) - return HdGet_wireframeColor(); -#else - return vec4(0,0,0,0); -#endif -} -vec4 GetMaskColor() { -#if defined(HD_HAS_maskColor) - return HdGet_maskColor(); -#else - return vec4(0.5,0,0,1); -#endif -} -vec4 GetIndicatorColor() { -#if defined(HD_HAS_indicatorColor) - return HdGet_indicatorColor(); -#else - return vec4(0,0.5,0,1); -#endif -} - -bool ShouldDiscardByAlpha(vec4 color) -{ -#if defined(HD_HAS_alphaThreshold) - float alphaThreshold = HdGet_alphaThreshold(); -#else - float alphaThreshold = 0; -#endif - return (color.a < alphaThreshold); -} - -vec2 ApplyAxisAlignedAffineTransform(vec4 t, vec2 pt) -{ - return t.xy * pt + t.zw; -} - - - -void ApplyClipPlanes(vec4 Peye) -{ -#if defined(HD_HAS_numClipPlanes) -#if defined(HD_HAS_clipPlanes) - for (int i=0; i> 2); -} -int GetAggregatedElementID() { - return GetElementID() - + GetDrawingCoord().elementCoord; -} -int HdGet_edgeIndices(int localIndex) { - int index = GetPrimitiveIndex(); - return int(edgeIndices[index]); -} -int HdGet_edgeIndices() { return HdGet_edgeIndices(0); } -int HdGetScalar_edgeIndices(int localIndex) { return HdGet_edgeIndices(localIndex); } -int HdGetScalar_edgeIndices() { return HdGet_edgeIndices(0); } -int GetAuthoredEdgeId(int primitiveEdgeId) { - return primitiveEdgeId; -} -float HdGet_faceVisibility(int localIndex) { - int index = GetAggregatedElementID(); - return float(faceVisibility[index]); -} -float HdGet_faceVisibility() { return HdGet_faceVisibility(0); } -float HdGetScalar_faceVisibility(int localIndex) { return HdGet_faceVisibility(localIndex); } -float HdGetScalar_faceVisibility() { return HdGet_faceVisibility(0); } -vec3 HdGet_points(int localIndex) { - int index = localIndex; - return vec3(inPrimvars[index].points); -} -vec3 HdGet_points() { return HdGet_points(0); } -float HdGetScalar_points(int localIndex) { return HdGet_points(localIndex).x; } -float HdGetScalar_points() { return HdGet_points(0).x; } -vec3 HdGet_normals(int localIndex) { - int index = localIndex; - return vec3(inPrimvars[index].normals); -} -vec3 HdGet_normals() { return HdGet_normals(0); } -float HdGetScalar_normals(int localIndex) { return HdGet_normals(localIndex).x; } -float HdGetScalar_normals() { return HdGet_normals(0).x; } -vec2 HdGet_dispTextureCoord_Coarse(int localIndex) { - int fvarIndex = GetFVarIndex(localIndex); - return vec2(dispTextureCoord[fvarIndex]); -} -vec2 HdGet_dispTextureCoord(int localIndex, vec2 st) { - return (HdGet_dispTextureCoord_Coarse(0) * (1-st.x-st.y) + HdGet_dispTextureCoord_Coarse(1) * st.x + HdGet_dispTextureCoord_Coarse(2) * st.y); -} -FORWARD_DECL(vec4 GetPatchCoord(int index)); -FORWARD_DECL(vec2 GetPatchCoordLocalST()); -vec2 HdGet_dispTextureCoord(int localIndex) { - vec2 localST = GetPatchCoord(localIndex).xy; - return HdGet_dispTextureCoord(localIndex, localST); -} -vec2 HdGet_dispTextureCoord() { return HdGet_dispTextureCoord(0); } -FORWARD_DECL(vec4 GetPatchCoord(int localIndex)); -void ProcessSamplingTransforms(MAT4 instanceModelViewInverse) { -} - -// //////// Codegen Proc GS //////// -FORWARD_DECL(vec4 GetPatchCoord(int index)); -void ProcessPrimvarsOut(int index) { - vec2 localST = GetPatchCoord(index).xy; - const vec3 coords[3] = vec3[]( - vec3(1,0,0), vec3(0,1,0), vec3(0,0,1) - ); - hd_barycentricCoord = coords[index]; - hd_drawingCoord dc = GetDrawingCoord(); - gs_dc_modelCoord = dc.modelCoord; - gs_dc_constantCoord = dc.constantCoord; - gs_dc_elementCoord = dc.elementCoord; - gs_dc_primitiveCoord = dc.primitiveCoord; - gs_dc_fvarCoord = dc.fvarCoord; - gs_dc_shaderCoord = dc.shaderCoord; - gs_dc_vertexCoord = dc.vertexCoord; - gs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - gs_dc_varyingCoord = dc.varyingCoord; - gs_dc_instanceIndexI0 = dc.instanceIndex[0]; - gs_dc_instanceIndexI1 = dc.instanceIndex[1]; - gs_dc_instanceCoordsI0 = dc.instanceCoords[0]; - outPrimvars.points = inPrimvars[index].points; - outPrimvars.normals = inPrimvars[index].normals; - outPrimvars.dispTextureCoord = HdGet_dispTextureCoord(index); -} - -// --------------------------------------------------------------------------- -// global defines -// --------------------------------------------------------------------------- -// codeGen can override this range (currently not). -// quadro 4000's max is 189. -#ifndef HD_GL_POINT_SIZE_MAX -#define HD_GL_POINT_SIZE_MAX 100.0 -#endif -#ifndef HD_GL_POINT_SIZE_MIN -#define HD_GL_POINT_SIZE_MIN .45 -#endif - -// --------------------------------------------------------------------------- -// render pass states -// --------------------------------------------------------------------------- - -MAT4 GetWorldToViewMatrix() { -#if defined(HD_HAS_worldToViewMatrix) - return MAT4(HdGet_worldToViewMatrix()); -#else - return MAT4(1); -#endif -} -MAT4 GetWorldToViewInverseMatrix() { -#if defined(HD_HAS_worldToViewInverseMatrix) - return MAT4(HdGet_worldToViewInverseMatrix()); -#else - return MAT4(1); -#endif -} -MAT4 GetProjectionMatrix() { -#if defined(HD_HAS_projectionMatrix) - return MAT4(HdGet_projectionMatrix()); -#else - return MAT4(1); -#endif -} -vec3 GetPositionInWorldSpace(vec3 windowRelativeCoord) -{ -#if defined(HD_HAS_imageToWorldMatrix) - vec4 pImage = vec4(windowRelativeCoord, 1.0); - vec4 pWorld = vec4(HdGet_imageToWorldMatrix() * pImage); - return (pWorld / pWorld.w).xyz; -#else - return windowRelativeCoord; -#endif -} -float GetLightingBlendAmount() { -#if defined(HD_HAS_lightingBlendAmount) - return HdGet_lightingBlendAmount(); -#else - return 1; -#endif -} -vec4 GetViewport() { -#if defined(HD_HAS_viewport) - return HdGet_viewport(); -#else - return vec4(0,0,1,1); -#endif -} -float GetTessLevel() { -#if defined(HD_HAS_tessLevel) - return HdGet_tessLevel(); -#else - return 1; -#endif -} -float GetPointSize() { -#if defined(HD_HAS_pointSize) - return HdGet_pointSize(); -#else - return 3.0; -#endif -} -float GetPointSelectedSize() { -#if defined(HD_HAS_pointSelectedSize) - return HdGet_pointSelectedSize(); -#else - return 5.0; -#endif -} -vec4 GetWireframeColor() { -// Individual prims can specify an alternative wireframe color -// to one specified in the render pass. This is used in cases were -// there is not enough contrast with the normal one. -#if defined(HD_HAS_overrideWireframeColor) - return HdGet_overrideWireframeColor(); -#elif defined(HD_HAS_wireframeColor) - return HdGet_wireframeColor(); -#else - return vec4(0,0,0,0); -#endif -} -vec4 GetMaskColor() { -#if defined(HD_HAS_maskColor) - return HdGet_maskColor(); -#else - return vec4(0.5,0,0,1); -#endif -} -vec4 GetIndicatorColor() { -#if defined(HD_HAS_indicatorColor) - return HdGet_indicatorColor(); -#else - return vec4(0,0.5,0,1); -#endif -} - -bool ShouldDiscardByAlpha(vec4 color) -{ -#if defined(HD_HAS_alphaThreshold) - float alphaThreshold = HdGet_alphaThreshold(); -#else - float alphaThreshold = 0; -#endif - return (color.a < alphaThreshold); -} - -vec2 ApplyAxisAlignedAffineTransform(vec4 t, vec2 pt) -{ - return t.xy * pt + t.zw; -} - - - -void ApplyClipPlanes(vec4 Peye) -{ -#if defined(HD_HAS_numClipPlanes) -#if defined(HD_HAS_clipPlanes) - for (int i=0; i 0.0) - normal = normalize(normal); - return normal; -} - -vec3 GetNormal(vec3 Neye, int index, vec2 localST) -{ - return GetNormal(Neye, index); -} - - - -vec3 GetTriGeometryNormal(vec3 Neye, vec4 Peye0, vec4 Peye1, vec4 Peye2, - bool isFlipped) -{ - return Neye; -} - -vec3 GetQuadGeometryNormal(vec3 Neye, - vec4 Peye0, vec4 Peye1, vec4 Peye2, vec4 Peye3, - bool isFlipped) -{ - return Neye; -} - - - -vec4 DisplacementTerminal(int index, vec4 Peye, vec3 Neye, vec4 patchCoord) -{ - return Peye; -} - - - -vec4 GetPatchCoord(int index) -{ - vec2 uv[3]; - uv[0] = vec2(0, 0); // (0, 0, 1); - uv[1] = vec2(1, 0); // (1, 0, 0); - uv[2] = vec2(0, 1); // (0, 1, 0); - - ivec3 patchParam = GetPatchParam(); - return InterpolatePatchCoordTriangle(uv[index], patchParam); -} - -void emit(int index, vec4 Peye, vec3 Neye) -{ - outData.Peye = Peye; - outData.Neye = Neye; - - gsPatchCoord = GetPatchCoord(index); - - gl_Position = vec4(GetProjectionMatrix() * outData.Peye); - ApplyClipPlanes(outData.Peye); - - ProcessPrimvarsOut(index); - - EmitVertex(); -} - -void main(void) -{ - gl_PrimitiveID = gl_PrimitiveIDIn; - - bool isFlipped = IsFlipped(); // consider handedness AND negative-scale - - vec3 Neye0 = GetNormal(inData[0].Neye, 0); - Neye0 = GetTriGeometryNormal(Neye0, inData[0].Peye, inData[1].Peye, - inData[2].Peye, isFlipped); - vec3 Neye1 = GetNormal(inData[1].Neye, 1); - Neye1 = GetTriGeometryNormal(Neye1, inData[0].Peye, inData[1].Peye, - inData[2].Peye, isFlipped); - vec3 Neye2 = GetNormal(inData[2].Neye, 2); - Neye2 = GetTriGeometryNormal(Neye2, inData[0].Peye, inData[1].Peye, - inData[2].Peye, isFlipped); - - vec4 Peye0 = DisplacementTerminal( - 0, inData[0].Peye, Neye0, GetPatchCoord(0)); - vec4 Peye1 = DisplacementTerminal( - 1, inData[1].Peye, Neye1, GetPatchCoord(1)); - vec4 Peye2 = DisplacementTerminal( - 2, inData[2].Peye, Neye2, GetPatchCoord(2)); - - // triangle 0: vertices (0,1,2) - emit(0, Peye0, Neye0); - emit(1, Peye1, Neye1); - emit(2, Peye2, Neye2); - - EndPrimitive(); -} - - -======================================================= - FRAGMENT SHADER -======================================================= -#version 450 -#extension GL_NV_shader_buffer_load : require -#extension GL_NV_gpu_shader5 : require -#extension GL_ARB_bindless_texture : require -#define REF(space,type) inout type -#define FORWARD_DECL(func_decl) func_decl; -#define ATOMIC_LOAD(a) (a) -#define ATOMIC_STORE(a, v) (a) = (v) -#define ATOMIC_ADD(a, v) atomicAdd(a, v) -#define ATOMIC_EXCHANGE(a, v) atomicExchange(a, v) -#define ATOMIC_COMP_SWAP(a, expected, desired) atomicCompSwap(a, expected, desired) -#define atomic_int int -#define atomic_uint uint - -#define HGI_HAS_DOUBLE_TYPE 1 - - -struct hgi_ivec3 { int x, y, z; }; -struct hgi_vec3 { float x, y, z; }; -struct hgi_dvec3 { double x, y, z; }; -struct hgi_mat3 { float m00, m01, m02, - m10, m11, m12, - m20, m21, m22; }; -struct hgi_dmat3 { double m00, m01, m02, - m10, m11, m12, - m20, m21, m22; }; - - - -// //////// Global Includes //////// - -// //////// Global Macros //////// - -// //////// Global Structs //////// - -// //////// Global Member Declarations //////// - -// //////// Global Function Definitions //////// - - -// //////// Codegen Defines //////// -#define HD_SHADER_API 2 -#define MAT4 mat4 -// Alias hgi vec and matrix types to hd. -#define hd_ivec3 hgi_ivec3 -#define hd_vec3 hgi_vec3 -#define hd_dvec3 hgi_dvec3 -#define hd_mat3 hgi_mat3 -#define hd_dmat3 hgi_dmat3 - -ivec3 hd_ivec3_get(hd_ivec3 v) { return ivec3(v.x, v.y, v.z); } -ivec3 hd_ivec3_get(ivec3 v) { return v; } -vec3 hd_vec3_get(hd_vec3 v) { return vec3(v.x, v.y, v.z); } -vec3 hd_vec3_get(vec3 v) { return v; } -dvec3 hd_dvec3_get(hd_dvec3 v) { return dvec3(v.x, v.y, v.z); } -dvec3 hd_dvec3_get(dvec3 v) { return v; } -mat3 hd_mat3_get(hd_mat3 v) { return mat3(v.m00, v.m01, v.m02, - v.m10, v.m11, v.m12, - v.m20, v.m21, v.m22); } -mat3 hd_mat3_get(mat3 v) { return v; } -dmat3 hd_dmat3_get(hd_dmat3 v) { return dmat3(v.m00, v.m01, v.m02, - v.m10, v.m11, v.m12, - v.m20, v.m21, v.m22); } -dmat3 hd_dmat3_get(dmat3 v) { return v; } -hd_ivec3 hd_ivec3_set(hd_ivec3 v) { return v; } -hd_ivec3 hd_ivec3_set(ivec3 v) { return hd_ivec3(v.x, v.y, v.z); } -hd_vec3 hd_vec3_set(hd_vec3 v) { return v; } -hd_vec3 hd_vec3_set(vec3 v) { return hd_vec3(v.x, v.y, v.z); } -hd_dvec3 hd_dvec3_set(hd_dvec3 v) { return v; } -hd_dvec3 hd_dvec3_set(dvec3 v) { return hd_dvec3(v.x, v.y, v.z); } -hd_mat3 hd_mat3_set(hd_mat3 v) { return v; } -hd_mat3 hd_mat3_set(mat3 v) { return hd_mat3(v[0][0], v[0][1], v[0][2], - v[1][0], v[1][1], v[1][2], - v[2][0], v[2][1], v[2][2]); } -hd_dmat3 hd_dmat3_set(hd_dmat3 v) { return v; } -hd_dmat3 hd_dmat3_set(dmat3 v) { return hd_dmat3(v[0][0], v[0][1], v[0][2], - v[1][0], v[1][1], v[1][2], - v[2][0], v[2][1], v[2][2]); } -int hd_int_get(int v) { return v; } -int hd_int_get(ivec2 v) { return v.x; } -int hd_int_get(ivec3 v) { return v.x; } -int hd_int_get(ivec4 v) { return v.x; } -vec3 hd_sample_udim(vec2 v) { -vec2 vf = floor(v); -return vec3(v.x - vf.x, v.y - vf.y, clamp(vf.x, 0.0, 10.0) + 10.0 * vf.y); -} -vec4 hd_vec4_2_10_10_10_get(int v) { - ivec4 unpacked = ivec4((v & 0x3ff) << 22, (v & 0xffc00) << 12, - (v & 0x3ff00000) << 2, (v & 0xc0000000)); - return vec4(unpacked) / 2147483647.0; } -int hd_vec4_2_10_10_10_set(vec4 v) { - return ( (int(v.x * 511.0) & 0x3ff) | - ((int(v.y * 511.0) & 0x3ff) << 10) | - ((int(v.z * 511.0) & 0x3ff) << 20) | - ((int(v.w) & 0x1) << 30)); } -vec2 hd_half2_get(uint v) { - return unpackHalf2x16(v); } -uint hd_half2_set(vec2 v) { - return packHalf2x16(v); } -vec4 hd_half4_get(uvec2 v) { - return vec4(unpackHalf2x16(v.x), unpackHalf2x16(v.y)); } -uvec2 hd_half4_set(vec4 v) { - return uvec2(packHalf2x16(v.xy), packHalf2x16(v.zw)); } -#define HD_NUM_PRIMITIVE_VERTS 3 -#define HD_HAS_transform 1 -#define HD_HAS_transformInverse 1 -#define HD_HAS_color 1 -#define HD_HAS_primID 1 -#define HD_HAS_widths 1 -#define HD_HAS_INSTANCE_hydra_instanceTranslations 1 -#define HD_HAS_hydra_instanceTranslations_0 1 -#define HD_INSTANCER_NUM_LEVELS 1 -#define HD_INSTANCE_INDEX_WIDTH 2 -#define HD_HAS_faceVisibility 1 -#define HD_HAS_dispTextureCoord 1 -#define HD_HAS_points 1 -#define HD_HAS_normals 1 - -// //////// Codegen Decl //////// -struct hd_drawingCoord { - int modelCoord; - int constantCoord; - int elementCoord; - int primitiveCoord; - int fvarCoord; - int shaderCoord; - int vertexCoord; - int topologyVisibilityCoord; - int varyingCoord; - int instanceIndex[HD_INSTANCE_INDEX_WIDTH]; - int instanceCoords[HD_INSTANCE_INDEX_WIDTH]; -}; -FORWARD_DECL(hd_drawingCoord GetDrawingCoord()); -FORWARD_DECL(int HgiGetBaseVertex()); -struct hd_instanceIndex { int indices[HD_INSTANCE_INDEX_WIDTH]; }; -struct ConstantData10 { - mat4 transform; - mat4 transformInverse; - vec4 color; - vec4 primID; - float widths; -}; -FORWARD_DECL(int GetElementID()); -FORWARD_DECL(int GetAggregatedElementID()); -FORWARD_DECL(int GetPrimitiveEdgeId()); -FORWARD_DECL(float GetSelectedEdgeOpacity()); -layout(location = 6) uniform int *instanceIndices; -layout(location = 7) uniform int *culledInstanceIndices; -layout(location = 0) uniform ConstantData10 *constantPrimvars; -layout(location = 1) uniform hd_vec3 *hydra_instanceTranslations_0; -layout(location = 2) uniform int *primitiveParam; -layout(location = 3) uniform int *edgeIndices; -layout(location = 4) uniform float *faceVisibility; -in vec4 gsPatchCoord; -in VertexData { - vec4 Peye; - vec3 Neye; -} inData; -layout (location = 0) out vec4 colorOut; -in noperspective vec3 hd_barycentricCoord; -in PrimvarData { - vec3 points; - vec3 normals; - vec2 dispTextureCoord; -} inPrimvars; -in flat int gs_dc_modelCoord; -in flat int gs_dc_constantCoord; -in flat int gs_dc_elementCoord; -in flat int gs_dc_primitiveCoord; -in flat int gs_dc_fvarCoord; -in flat int gs_dc_shaderCoord; -in flat int gs_dc_vertexCoord; -in flat int gs_dc_topologyVisibilityCoord; -in flat int gs_dc_varyingCoord; -in flat int gs_dc_instanceIndexI0; -in flat int gs_dc_instanceIndexI1; -in flat int gs_dc_instanceCoordsI0; -in flat int gs_dc_instanceCoordsI1; -layout(location = 5) uniform vec2 *dispTextureCoord; -vec4 InterpolatePatchCoord(vec2 uv, ivec3 patchParam) -{ - // add 0.5 to integer values for more robust interpolation - return vec4(uv.x, uv.y, 0, patchParam.x+0.5f); -} -vec4 InterpolatePatchCoordTriangle(vec2 uv, ivec3 patchParam) -{ - return InterpolatePatchCoord(uv, patchParam); -} - -// //////// Codegen Accessors //////// -mat4 HdGet_transform(int localIndex) { - int index = GetDrawingCoord().constantCoord; - return mat4(constantPrimvars[index].transform); -} -mat4 HdGet_transform() { return HdGet_transform(0); } -mat4 HdGet_transformInverse(int localIndex) { - int index = GetDrawingCoord().constantCoord; - return mat4(constantPrimvars[index].transformInverse); -} -mat4 HdGet_transformInverse() { return HdGet_transformInverse(0); } -vec4 HdGet_color(int localIndex) { - int index = GetDrawingCoord().constantCoord; - return vec4(constantPrimvars[index].color); -} -vec4 HdGet_color() { return HdGet_color(0); } -float HdGetScalar_color(int localIndex) { return HdGet_color(localIndex).x; } -float HdGetScalar_color() { return HdGet_color(0).x; } -vec4 HdGet_primID(int localIndex) { - int index = GetDrawingCoord().constantCoord; - return vec4(constantPrimvars[index].primID); -} -vec4 HdGet_primID() { return HdGet_primID(0); } -float HdGetScalar_primID(int localIndex) { return HdGet_primID(localIndex).x; } -float HdGetScalar_primID() { return HdGet_primID(0).x; } -float HdGet_widths(int localIndex) { - int index = GetDrawingCoord().constantCoord; - return float(constantPrimvars[index].widths); -} -float HdGet_widths() { return HdGet_widths(0); } -float HdGetScalar_widths(int localIndex) { return HdGet_widths(localIndex); } -float HdGetScalar_widths() { return HdGet_widths(0); } -vec3 HdGet_hydra_instanceTranslations_0(int localIndex) { - int index = GetDrawingCoord().instanceCoords[0]; - return hd_vec3_get(hydra_instanceTranslations_0[index]); -} -vec3 HdGet_hydra_instanceTranslations_0() { return HdGet_hydra_instanceTranslations_0(0); } -float HdGetScalar_hydra_instanceTranslations_0(int localIndex) { return HdGet_hydra_instanceTranslations_0(localIndex).x; } -float HdGetScalar_hydra_instanceTranslations_0() { return HdGet_hydra_instanceTranslations_0(0).x; } -vec3 HdGetInstance_hydra_instanceTranslations(int level, vec3 defaultValue) { - if (level == 0) return HdGet_hydra_instanceTranslations_0(); - return defaultValue; -} -#if !defined(HD_HAS_hydra_instanceTranslations) -#define HD_HAS_hydra_instanceTranslations 1 -vec3 HdGet_hydra_instanceTranslations(int localIndex) { - return HdGet_hydra_instanceTranslations_0(); -} -vec3 HdGet_hydra_instanceTranslations() { return HdGet_hydra_instanceTranslations(0); } -#endif - -// //////// Codegen FS Source //////// -#define HD_SHADER_SUPPORTS_DOUBLE_PRECISION -#define HD_MINUS_ONE_TO_ONE_DEPTH_RANGE -vec3 GetBarycentricCoord() { - return hd_barycentricCoord; -} -int GetPrimitiveID() { - return gl_PrimitiveID; -} -int GetPrimitiveIndex() { - return GetDrawingCoord().primitiveCoord + GetPrimitiveID(); -} -hd_drawingCoord GetDrawingCoord() { - hd_drawingCoord dc; - dc.modelCoord = gs_dc_modelCoord; - dc.constantCoord = gs_dc_constantCoord; - dc.elementCoord = gs_dc_elementCoord; - dc.primitiveCoord = gs_dc_primitiveCoord; - dc.fvarCoord = gs_dc_fvarCoord; - dc.shaderCoord = gs_dc_shaderCoord; - dc.vertexCoord = gs_dc_vertexCoord; - dc.topologyVisibilityCoord = gs_dc_topologyVisibilityCoord; - dc.varyingCoord = gs_dc_varyingCoord; - dc.instanceIndex[0] = gs_dc_instanceIndexI0; - dc.instanceIndex[1] = gs_dc_instanceIndexI1; - dc.instanceCoords[0] = gs_dc_instanceCoordsI0; - return dc; -} -int HdGet_primitiveParam(int localIndex) { - int index = GetPrimitiveIndex(); - return int(primitiveParam[index]); -} -int HdGet_primitiveParam() { return HdGet_primitiveParam(0); } -int HdGetScalar_primitiveParam(int localIndex) { return HdGet_primitiveParam(localIndex); } -int HdGetScalar_primitiveParam() { return HdGet_primitiveParam(0); } -#if defined(HD_HAS_coarseFaceIndex) -FORWARD_DECL(int HdGetScalar_coarseFaceIndex()); -#endif -ivec3 GetPatchParam() { -#if defined(HD_HAS_coarseFaceIndex) - return ivec3(HdGetScalar_coarseFaceIndex(), 0, 0); -#else - return ivec3(GetPrimitiveID(), 0, 0); -#endif -} -int GetEdgeFlag() { - return (HdGet_primitiveParam() & 3); -} -int GetFVarIndex(int localIndex) { - int fvarCoord = GetDrawingCoord().fvarCoord; - int ptexIndex = GetPatchParam().x & 0xfffffff; - return fvarCoord + ptexIndex * 3 + localIndex; -} -int GetElementID() { - return (hd_int_get(HdGet_primitiveParam()) >> 2); -} -int GetAggregatedElementID() { - return GetElementID() - + GetDrawingCoord().elementCoord; -} -int HdGet_edgeIndices(int localIndex) { - int index = GetPrimitiveIndex(); - return int(edgeIndices[index]); -} -int HdGet_edgeIndices() { return HdGet_edgeIndices(0); } -int HdGetScalar_edgeIndices(int localIndex) { return HdGet_edgeIndices(localIndex); } -int HdGetScalar_edgeIndices() { return HdGet_edgeIndices(0); } -int GetAuthoredEdgeId(int primitiveEdgeId) { - return primitiveEdgeId; -} -float HdGet_faceVisibility(int localIndex) { - int index = GetAggregatedElementID(); - return float(faceVisibility[index]); -} -float HdGet_faceVisibility() { return HdGet_faceVisibility(0); } -float HdGetScalar_faceVisibility(int localIndex) { return HdGet_faceVisibility(localIndex); } -float HdGetScalar_faceVisibility() { return HdGet_faceVisibility(0); } -vec3 HdGet_points(int localIndex) { return vec3(inPrimvars.points);} -vec3 HdGet_points() { return HdGet_points(0); } -float HdGetScalar_points(int localIndex) { return HdGet_points(localIndex).x; } -float HdGetScalar_points() { return HdGet_points(0).x; } -vec3 HdGet_normals(int localIndex) { return vec3(inPrimvars.normals);} -vec3 HdGet_normals() { return HdGet_normals(0); } -float HdGetScalar_normals(int localIndex) { return HdGet_normals(localIndex).x; } -float HdGetScalar_normals() { return HdGet_normals(0).x; } -vec2 HdGet_dispTextureCoord(int localIndex) { return vec2(inPrimvars.dispTextureCoord);} -vec2 HdGet_dispTextureCoord() { return HdGet_dispTextureCoord(0); } -float HdGetScalar_dispTextureCoord(int localIndex) { return HdGet_dispTextureCoord(localIndex).x; } -float HdGetScalar_dispTextureCoord() { return HdGet_dispTextureCoord(0).x; } -FORWARD_DECL(vec4 GetPatchCoord(int index)); -void ProcessSamplingTransforms(MAT4 instanceModelViewInverse) { -} - -// --------------------------------------------------------------------------- -// global defines -// --------------------------------------------------------------------------- -// codeGen can override this range (currently not). -// quadro 4000's max is 189. -#ifndef HD_GL_POINT_SIZE_MAX -#define HD_GL_POINT_SIZE_MAX 100.0 -#endif -#ifndef HD_GL_POINT_SIZE_MIN -#define HD_GL_POINT_SIZE_MIN .45 -#endif - -// --------------------------------------------------------------------------- -// render pass states -// --------------------------------------------------------------------------- - -MAT4 GetWorldToViewMatrix() { -#if defined(HD_HAS_worldToViewMatrix) - return MAT4(HdGet_worldToViewMatrix()); -#else - return MAT4(1); -#endif -} -MAT4 GetWorldToViewInverseMatrix() { -#if defined(HD_HAS_worldToViewInverseMatrix) - return MAT4(HdGet_worldToViewInverseMatrix()); -#else - return MAT4(1); -#endif -} -MAT4 GetProjectionMatrix() { -#if defined(HD_HAS_projectionMatrix) - return MAT4(HdGet_projectionMatrix()); -#else - return MAT4(1); -#endif -} -vec3 GetPositionInWorldSpace(vec3 windowRelativeCoord) -{ -#if defined(HD_HAS_imageToWorldMatrix) - vec4 pImage = vec4(windowRelativeCoord, 1.0); - vec4 pWorld = vec4(HdGet_imageToWorldMatrix() * pImage); - return (pWorld / pWorld.w).xyz; -#else - return windowRelativeCoord; -#endif -} -float GetLightingBlendAmount() { -#if defined(HD_HAS_lightingBlendAmount) - return HdGet_lightingBlendAmount(); -#else - return 1; -#endif -} -vec4 GetViewport() { -#if defined(HD_HAS_viewport) - return HdGet_viewport(); -#else - return vec4(0,0,1,1); -#endif -} -float GetTessLevel() { -#if defined(HD_HAS_tessLevel) - return HdGet_tessLevel(); -#else - return 1; -#endif -} -float GetPointSize() { -#if defined(HD_HAS_pointSize) - return HdGet_pointSize(); -#else - return 3.0; -#endif -} -float GetPointSelectedSize() { -#if defined(HD_HAS_pointSelectedSize) - return HdGet_pointSelectedSize(); -#else - return 5.0; -#endif -} -vec4 GetWireframeColor() { -// Individual prims can specify an alternative wireframe color -// to one specified in the render pass. This is used in cases were -// there is not enough contrast with the normal one. -#if defined(HD_HAS_overrideWireframeColor) - return HdGet_overrideWireframeColor(); -#elif defined(HD_HAS_wireframeColor) - return HdGet_wireframeColor(); -#else - return vec4(0,0,0,0); -#endif -} -vec4 GetMaskColor() { -#if defined(HD_HAS_maskColor) - return HdGet_maskColor(); -#else - return vec4(0.5,0,0,1); -#endif -} -vec4 GetIndicatorColor() { -#if defined(HD_HAS_indicatorColor) - return HdGet_indicatorColor(); -#else - return vec4(0,0.5,0,1); -#endif -} - -bool ShouldDiscardByAlpha(vec4 color) -{ -#if defined(HD_HAS_alphaThreshold) - float alphaThreshold = HdGet_alphaThreshold(); -#else - float alphaThreshold = 0; -#endif - return (color.a < alphaThreshold); -} - -vec2 ApplyAxisAlignedAffineTransform(vec4 t, vec2 pt) -{ - return t.xy * pt + t.zw; -} - - - -vec2 HorizontallyNormalizedFilmbackCoordinates() -{ - const vec4 transform = -#ifdef HD_HAS_imageToHorizontallyNormalizedFilmback - HdGet_imageToHorizontallyNormalizedFilmback(); -#else - vec4(vec2(1.0), vec2(0.0)); -#endif - return ApplyAxisAlignedAffineTransform(transform, gl_FragCoord.xy); -} - - - -vec4 ApplySelectionColor(vec4 color) -{ - return color; -} - - - -// Forward declare selection functionality. -// XXX: Currently, the non-empty implementation of this is in hdx. -FORWARD_DECL(vec4 ApplySelectionColor(vec4 color)); - -// XXX: Make sure to update hdx/shaders/renderPass.glslfx when editing these -// color override methods, since they're currently duplicated. This is because -// we don't have a mixin token for color overrides in a render pass yet. -vec4 ApplyColorOverrides(vec4 color) -{ -#if defined(HD_HAS_overrideColor) - // Mix in override color - vec4 overrideColor = HdGet_overrideColor(); - color.rgb = mix(color.rgb, overrideColor.rgb, overrideColor.a); -#endif - return ApplySelectionColor(color); -} - -vec3 ApplyMaskColor(vec3 color, float weight, vec4 maskColor) -{ - float strength = maskColor.a * clamp(weight, 0.0, 1.0); - return mix(color, maskColor.rgb, strength); -} - -vec4 ApplyColorOverridesPostLighting(vec4 color) -{ - #if defined(HD_HAS_maskWeight) - float maskWeight = HdGet_maskWeight(); - vec4 maskColor = GetMaskColor(); - color.rgb = ApplyMaskColor(color.rgb, maskWeight, maskColor); - #endif - #if defined(HD_HAS_indicatorWeight) - float indicatorWeight = HdGet_indicatorWeight(); - vec4 indicatorColor = GetIndicatorColor(); - color.rgb = ApplyMaskColor(color.rgb, indicatorWeight, indicatorColor); - #endif - return color; -} - - - -void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) -{ - colorOut = color; -} - - -#ifndef HD_HAS_integrateLights -#define HD_HAS_integrateLights -#endif - -struct LightingContribution { - vec3 diffuse; -}; - -struct LightingInterfaceProperties { - float unused; -}; - -LightingContribution -integrateLightsDefault(vec4 Peye, vec3 Neye, LightingInterfaceProperties props) -{ - vec3 n = normalize(Neye); - - LightingContribution result; - result.diffuse = vec3(dot(n, vec3(0,0,1))); - - return result; -} - -LightingContribution -integrateLightsConstant(vec4 Peye, vec3 Neye, LightingInterfaceProperties props) -{ - LightingContribution result; - //pefectly diffuse white hemisphere contribution - result.diffuse = vec3(1); - - return result; -} - - - -FORWARD_DECL( - LightingContribution integrateLights(vec4 Peye, vec3 Neye, - LightingInterfaceProperties props)); - -vec3 FallbackLighting(in vec3 Peye, in vec3 Neye, in vec3 color) -{ - LightingInterfaceProperties props; - LightingContribution light = integrateLights(vec4(Peye, 1), Neye, props); - return color * light.diffuse; -} - - -vec4 surfaceShader(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) -{ - // lighting - color.rgb = FallbackLighting(Peye.xyz, Neye, color.rgb); - return color; -} - - -// quaternion to matrix. xyz = imaginary, w = real -MAT4 GetRotationMatrix(vec4 q) -{ - MAT4 r; - r[0].xyzw = vec4(1 - 2 * (q.y * q.y + q.z * q.z), - 2 * (q.x * q.y + q.z * q.w), - 2 * (q.x * q.z - q.y * q.w), - 0); - r[1].xyzw = vec4( 2 * (q.x * q.y - q.z * q.w), - 1 - 2 * (q.x * q.x + q.z * q.z), - 2 * (q.y * q.z + q.x * q.w), - 0); - r[2].xyzw = vec4( 2 * (q.x * q.z + q.y * q.w), - 2 * (q.y * q.z - q.x * q.w), - 1 - 2 * (q.x * q.x + q.y * q.y), - 0); - r[3] = vec4(0, 0, 0, 1); - return r; -} - -// --------------------------------------------------------------------------- - -MAT4 GetInstanceTransform(int level) -{ - MAT4 m = MAT4(1); -#ifdef HD_HAS_INSTANCE_hydra_instanceTransforms - m = HdGetInstance_hydra_instanceTransforms(level, MAT4(1)) * m; -#elif defined(HD_HAS_INSTANCE_instanceTransform) - m = HdGetInstance_instanceTransform(level, MAT4(1)) * m; -#endif - - // instance transform elements are applied: - // scale then rotate then translate - // i.e. (T * R * S) * position - -#ifdef HD_HAS_INSTANCE_hydra_instanceScales - vec3 s = HdGetInstance_hydra_instanceScales(level, /*default=*/vec3(1)); - m = MAT4(s.x, 0, 0, 0, - 0, s.y, 0, 0, - 0, 0, s.z, 0, - 0, 0, 0, 1) * m; -#elif defined(HD_HAS_INSTANCE_instanceScale) - vec3 s = HdGetInstance_scale(level, /*default=*/vec3(1)); - m = MAT4(s.x, 0, 0, 0, - 0, s.y, 0, 0, - 0, 0, s.z, 0, - 0, 0, 0, 1) * m; -#endif - -#ifdef HD_HAS_INSTANCE_hydra_instanceRotations // GfQuat(ix, iy, iz, real) - vec4 q = HdGetInstance_hydra_instanceRotations(level, /*default=*/vec4(0)); - m = GetRotationMatrix(q) * m; -#elif defined(HD_HAS_INSTANCE_rotate) - vec4 q = HdGetInstance_rotate(level, /*default=*/vec4(0)); - m = GetRotationMatrix(q) * m; -#endif - -#ifdef HD_HAS_INSTANCE_hydra_instanceTranslations - vec3 t = HdGetInstance_hydra_instanceTranslations(level, /*default=*/vec3(0)); - m = MAT4( 1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, 1, 0, - t.x, t.y, t.z, 1) * m; -#elif defined(HD_HAS_INSTANCE_translate) - vec3 t = HdGetInstance_translate(level, /*default=*/vec3(0)); - m = MAT4( 1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, 1, 0, - t.x, t.y, t.z, 1) * m; -#endif - return m; -} - -MAT4 GetInstanceTransformInverse(int level) -{ - MAT4 m = MAT4(1); - -#ifdef HD_HAS_INSTANCE_hydra_instanceTransforms - m = inverse(HdGetInstance_hydra_instanceTransforms(level, MAT4(1))) * m; -#elif defined(HD_HAS_INSTANCE_instanceTransform) - m = inverse(HdGetInstance_instanceTransform(level, MAT4(1))) * m; -#endif - -#ifdef HD_HAS_INSTANCE_hydra_instanceTranslations - vec3 it = -HdGetInstance_hydra_instanceTranslations(level, /*default=*/vec3(0)); // negate - m = MAT4( 1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, 1, 0, - it.x, it.y, it.z, 1) * m; -#elif defined(HD_HAS_INSTANCE_translate) - vec3 it = -HdGetInstance_translate(level, /*default=*/vec3(0)); // negate - m = MAT4( 1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, 1, 0, - it.x, it.y, it.z, 1) * m; -#endif - -#ifdef HD_HAS_INSTANCE_hydra_instanceRotations - vec4 q = HdGetInstance_hydra_instanceRotations(level, /*default=*/vec4(0)); - q.xyz = -q.xyz; // inverse rotataion axis - m = GetRotationMatrix(q) * m; -#elif defined(HD_HAS_INSTANCE_rotate) - vec4 q = HdGetInstance_rotate(level, /*default=*/vec4(0)); - q.xyz = -q.xyz; // inverse rotataion axis - m = GetRotationMatrix(q) * m; -#endif - -#ifdef HD_HAS_INSTANCE_hydra_instanceScales - vec3 is = 1.0/HdGetInstance_hydra_instanceScales(level, /*default=*/vec3(1)); // inverse scale - m = MAT4(is.x, 0, 0, 0, - 0, is.y, 0, 0, - 0, 0, is.z, 0, - 0, 0, 0, 1) * m; -#elif defined(HD_HAS_INSTANCE_scale) - vec3 is = 1.0/HdGetInstance_scale(level, /*default=*/vec3(1)); // inverse scale - m = MAT4(is.x, 0, 0, 0, - 0, is.y, 0, 0, - 0, 0, is.z, 0, - 0, 0, 0, 1) * m; -#endif - return m; -} - -// --------------------------------------------------------------------------- - -MAT4 GetInstanceTransform() -{ - MAT4 m = MAT4(1); -#ifdef HD_INSTANCER_NUM_LEVELS - for (int i = 0; i < HD_INSTANCER_NUM_LEVELS; ++i) { - m = GetInstanceTransform(i) * m; -#ifdef HD_HAS_instancerTransform - m = HdGet_instancerTransform(i) * m; -#endif - } -#endif - return m; -} - -MAT4 GetInstanceTransformInverse() -{ - MAT4 m = MAT4(1); -#ifdef HD_INSTANCER_NUM_LEVELS - for (int i = 0; i < HD_INSTANCER_NUM_LEVELS; ++i) { - m = m * GetInstanceTransformInverse(i); -#ifdef HD_HAS_instancerTransformInverse - m = m * HdGet_instancerTransformInverse(i); -#endif - } -#endif - return m; -} - -// --------------------------------------------------------------------------- - -MAT4 ApplyInstanceTransform(MAT4 m) -{ - return GetInstanceTransform() * m; -} - -MAT4 ApplyInstanceTransformInverse(MAT4 m) -{ - return m * GetInstanceTransformInverse(); -} - -bool IsFlipped() -{ -#if defined(HD_HAS_isFlipped) - bool flip = (HdGet_isFlipped() != 0); -#elif defined(HD_HAS_transform) - // The sign of the determinant indicates whether m flips handedness - bool flip = (determinant(HdGet_transform()) < 0.0); -#else - bool flip = false; -#endif - -#ifdef HD_HAS_INSTANCE_hydra_instanceScales - for (int i = 0; i < HD_INSTANCER_NUM_LEVELS; ++i) { - vec3 scale = HdGetInstance_hydra_instanceScales(i, /*default=*/vec3(1)); - flip = flip != ((sign(scale.x) * sign(scale.y) * sign(scale.z)) < 0); - } -#elif defined(HD_HAS_INSTANCE_scale) - for (int i = 0; i < HD_INSTANCER_NUM_LEVELS; ++i) { - vec3 scale = HdGetInstance_scale(i, /*default=*/vec3(1)); - flip = flip != ((sign(scale.x) * sign(scale.y) * sign(scale.z)) < 0); - } -#endif - -#ifdef HD_HAS_INSTANCE_hydra_instanceTransforms - for (int i = 0; i < HD_INSTANCER_NUM_LEVELS; ++i) { - MAT4 m = HdGetInstance_hydra_instanceTransforms(i, MAT4(1)); - flip = flip != (determinant(m) < 0.0); - } -#elif defined(HD_HAS_INSTANCE_instanceTransform) - for (int i = 0; i < HD_INSTANCER_NUM_LEVELS; ++i) { - MAT4 m = HdGetInstance_instanceTransform(i, MAT4(1)); - flip = flip != (determinant(m) < 0.0); - } -#endif - - return flip; -} - - -vec3 GetNormal(vec3 Neye, int index) -{ - return Neye; -} - -vec3 GetNormal(vec3 Neye, int index, vec2 localST) -{ - return GetNormal(Neye, index); -} - - - -vec3 GetShadingNormal(vec3 N, bool isFlipped) -{ - // the fragment shader takes already-flipped-normals. - // no need to flip here. - return N; -} - - - -void DiscardBasedOnShading(bool frontFacing, bool isFlipped) -{ - // Nothing to do since h/w face culling is used. -} - - - -vec4 ApplyEdgeColor(vec4 Cfill, vec4 patchCoord) -{ - return Cfill; -} - -// Return a large value, signifying that the fragment isn't near an edge. -float GetMinEdgeDistance() -{ - return 1000.0; -} - - - -vec3 GetEdgeParamTriangle() -{ - // Expand barycentric coordinates - vec2 param = GetPatchCoord(0).xy; - vec3 barycentric = vec3(param.x, param.y, 1 - param.x - param.y); - - // Match triangle edge order - return barycentric.yzx; -} - -vec3 GetEdgeDistanceTriangle() -{ - vec3 param = GetEdgeParamTriangle(); - return max(vec3(0.0), param / fwidth(param)); -} - -vec4 GetEdgeParamQuad() -{ - // Expand coordinates to opposite corners of quad - vec2 leftBottom = GetPatchCoord(0).xy; - vec2 rightTop = vec2(1.0) - leftBottom; - - // Match quad edge order - return vec4(leftBottom.y, rightTop.x, rightTop.y, leftBottom.x); -} - -vec4 GetEdgeDistanceQuad() -{ - vec4 param = GetEdgeParamQuad(); - return max(vec4(0.0), param / fwidth(param)); -} - - - -struct ReprStyle -{ - vec4 color; - bool usePrimvarColor; - bool usePrimvarAlpha; - bool applyColorOverride; - bool useSurfaceShaderColor; - bool useSurfaceShaderAlpha; -}; - -struct ScalarOverride -{ - bool enabled; - vec3 color; -}; - -FORWARD_DECL(ReprStyle GetReprStyle()); -FORWARD_DECL(ScalarOverride GetScalarOverride()); -FORWARD_DECL( - vec4 surfaceShader(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord)); -FORWARD_DECL(vec4 postSurfaceShader(vec4 Peye, vec3 Neye, vec4 color)); - -vec4 ShadingTerminal(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) -{ - ReprStyle reprStyle = GetReprStyle(); - - // Apply scalar override. - ScalarOverride scalarOverride = GetScalarOverride(); - if (scalarOverride.enabled) { - vec4 result; - - result.rgb = scalarOverride.color; - result.a = reprStyle.usePrimvarAlpha ? color.a: reprStyle.color.a; - - vec4 colorOverride = ApplyColorOverrides(result); - result = reprStyle.applyColorOverride ? colorOverride : result; - - return result; - } - - // Draw mode can override face color - vec4 reprColor; - - reprColor.rgb = reprStyle.usePrimvarColor ? color.rgb : reprStyle.color.rgb; - reprColor.a = reprStyle.usePrimvarAlpha ? color.a : reprStyle.color.a; - - // Compute color overrides - vec4 colorOverride = ApplyColorOverrides(reprColor); - reprColor = reprStyle.applyColorOverride ? colorOverride : reprColor; - - - // Surface shading can be expensive and also can contain undesirable - // side effects (like discards). So only run it for reprs that require it. - - if (reprStyle.useSurfaceShaderColor || - reprStyle.useSurfaceShaderAlpha) { - vec4 shadingColor; - - shadingColor = surfaceShader(Peye, - Neye, - reprColor, - patchCoord); - -#ifdef HD_HAS_postSurfaceShader - shadingColor = postSurfaceShader(Peye, - Neye, - shadingColor); -#endif - - reprColor.rgb = reprStyle.useSurfaceShaderColor ? - shadingColor.rgb : - reprColor.rgb; - - reprColor.a = reprStyle.useSurfaceShaderAlpha ? - shadingColor.a : - reprColor.a; - } - - vec4 baseColor = color; - baseColor = ApplyColorOverrides(baseColor); - - vec4 litColor = mix(baseColor, - reprColor, - GetLightingBlendAmount()); - - // Final overrides. - - return ApplyColorOverridesPostLighting(litColor); -} - - - -#ifdef HD_HAS_integrateLights -#ifndef HD_HAS_definedIntegrateLights -#define HD_HAS_definedIntegrateLights - -LightingContribution -integrateLights(vec4 Peye, vec3 Neye, LightingInterfaceProperties props) -{ - return integrateLightsDefault(Peye, Neye, props); -} - -#endif // HD_HAS_definedIntegrateLights -#endif - -ReprStyle GetReprStyle() -{ - ReprStyle reprStyle; - - reprStyle.color = vec4(0.0, 0.0, 0.0, 1.0); - reprStyle.usePrimvarColor = true; - reprStyle.usePrimvarAlpha = true; - reprStyle.applyColorOverride = true; - reprStyle.useSurfaceShaderColor = true; - reprStyle.useSurfaceShaderAlpha = true; - - return reprStyle; -} - - - -ScalarOverride GetScalarOverride() -{ - ScalarOverride result; - -#if defined(HD_HAS_scalarOverride) - result.enabled = true; - - // Allow a scalar value to override the color from the surface - // for previewing heatmaps. This is useful for editing workflows. -#if defined(HD_HAS_scalarOverrideColorRamp) - int rampCount = constantPrimvars[GetDrawingCoord().constantCoord]. - scalarOverrideColorRamp.length(); - float scalar = HdGet_scalarOverride() * float(rampCount - 1); - float baseIndex = floor(scalar); - float nextIndex = min(float(rampCount - 1), baseIndex + 1.0); - float interp = scalar - baseIndex; - result.color = mix(HdGet_scalarOverrideColorRamp(int(baseIndex)).rgb, - HdGet_scalarOverrideColorRamp(int(nextIndex)).rgb, - interp); -#else - // If no ramp is given just gamma correct the scalar as greyscale. - result.color = vec3(pow(HdGet_scalarOverride(), 2.2)); -#endif // HD_HAS_scalarOverrideColorRamp - -#else // HD_HAS_scalarOverride - result.enabled = false; - result.color = vec3(0.0, 0.0, 0.0); -#endif - - return result; -} - - - -// Determines whether a fragment is on or close to an unhidden triangle edge. -const float edgePickRadius = 2; // in viewport pixels -const float edgePickParametricRadius = 0.02; // in parametric space - -// For smooth looking edges, use an exponential falloff for the opacity. -// Note: We use a slower falloff fn than in meshWire.glslfx to make the -// selected edges stand out. -float SelectedEdgeFalloff(float d) { - return exp2(-1 * d * d); -} - - - -FORWARD_DECL(vec3 GetEdgeDistanceTriangle()); - -vec3 ComputeBaseFaceEdgeDistanceTriangle() -{ - return GetEdgeDistanceTriangle(); -} - -bool SelectWireframeFaceEdges() -{ - return false; -} - - - -float GetSelectedEdgeOpacity() -{ - float closestEdgeDistance = 0.0; - - // The sequence of comparisons should match GetPrimitiveEdgeId() - vec3 dist = ComputeBaseFaceEdgeDistanceTriangle(); - if (dist.x < edgePickRadius) { - closestEdgeDistance = dist.x; - } else if (dist.y < edgePickRadius) { - closestEdgeDistance = dist.y; - } else if (dist.z < edgePickRadius) { - closestEdgeDistance = dist.z; - } else { - return 0; - } - - return SelectedEdgeFalloff(closestEdgeDistance); -} - -// called from hdx/renderPass.glslfx and selection.glslfx -int GetPrimitiveEdgeId() -{ - // 2 (0,1,0) - // ^ - // e2 / \ e1 - // / \' - // (0,0,1) 0 ----- 1 (1,0,0) - // e0 - - int edgeId = -1; - - vec3 dist = ComputeBaseFaceEdgeDistanceTriangle(); - if (dist.x < edgePickRadius) { - edgeId = 0; - } else if (dist.y < edgePickRadius) { - edgeId = 1; - } else if (dist.z < edgePickRadius) { - edgeId = 2; - } else { - return -1; // Not on a mesh edge - } - - const int edgeFlag = GetEdgeFlag(); - const int meshEdgeIndex = HdGetScalar_edgeIndices(); - - // Translate face-edge to authored mesh-edge - if (edgeFlag == 0) { - edgeId = meshEdgeIndex + edgeId; // regular triangle face. - } else if ((bool(edgeFlag & 1) && edgeId == 2) || - (bool(edgeFlag & 2) && edgeId == 0)) { - edgeId = -1; // Not an authored mesh edge - } else { - edgeId = meshEdgeIndex + edgeId - 1; - } - return edgeId; -} - - - -int GetPointId() -{ - return -1; -} - - -void DiscardBasedOnTopologicalVisibility() -{ - // Nothing to do, since there's no authored opinion. -} - - - -vec4 GetInterpolatedPatchCoord() -{ - return gsPatchCoord; -} - - - -#ifndef HD_HAS_ptexFaceOffset -#define HD_HAS_ptexFaceOffset -int HdGet_ptexFaceOffset() -{ - return 0; -} -#endif - -vec4 GetPatchCoord(int localIndex) -{ - vec4 patchCoord = GetInterpolatedPatchCoord(); - return vec4(patchCoord.xyz, patchCoord.w + HdGet_ptexFaceOffset()); -} - -vec4 GetPatchCoord() -{ - return GetPatchCoord(0); -} - -vec3 ComputeScreenSpacePeye() -{ - return inData.Peye.xyz / inData.Peye.w; -} - -vec3 ComputeScreenSpaceNeye() -{ - vec3 Peye = ComputeScreenSpacePeye(); - vec3 Neye = normalize(cross(dFdx(Peye), dFdy(Peye))); - return (gl_FrontFacing ? Neye : -Neye); -} - -void main(void) -{ - bool isFlipped = IsFlipped(); - - DiscardBasedOnShading(gl_FrontFacing, isFlipped); - - DiscardBasedOnTopologicalVisibility(); - - vec4 color = vec4(0.5, 0.5, 0.5, 1); -#ifdef HD_HAS_displayColor - color.rgb = HdGet_displayColor().rgb; -#endif -#ifdef HD_HAS_displayOpacity - color.a = HdGet_displayOpacity(); -#endif - - vec3 Peye = ComputeScreenSpacePeye(); - - vec3 Neye = inData.Neye; - // Normalize Neye after rasterizer interpolation. - if (length(Neye) > 0.0) { - Neye = normalize(Neye); - } - // Give the shader key a chance to override the normal. - Neye = GetNormal(Neye, 0); - // Orient the normal for shading. - Neye = GetShadingNormal(Neye, isFlipped); - - vec4 patchCoord = GetPatchCoord(); - color = ShadingTerminal(vec4(Peye, 1), Neye, color, patchCoord); - - color = ApplyEdgeColor(color, patchCoord); - -#ifdef HD_MATERIAL_TAG_MASKED - if (ShouldDiscardByAlpha(color)) { - discard; - return; - } -#endif - - RenderOutput(vec4(Peye, 1), Neye, color, patchCoord); -} - -------------------------------------------------------- --- glslfx version 0.1 -#import $TOOLS/hdSt/shaders/mesh.glslfx --- configuration -{"techniques": {"default": { -"vertexShader" : { "source" : ["Instancing.Transform", "MeshNormal.Pass", "PointId.Vertex.None", "Mesh.Vertex"] } -, "geometryShader" : { "source" : ["Instancing.Transform", "MeshNormal.Flat", "MeshNormal.Geometry.NoFlat", "Geometry.NoCustomDisplacement", "Mesh.Geometry.Quad"] } -, "fragmentShader" : { "source" : ["Instancing.Transform", "MeshNormal.Pass", "MeshNormal.Fragment.SingleSided", "MeshFaceCull.Fragment.None", "MeshWire.Fragment.NoEdge", "MeshWire.Fragment.EdgeParam", "Fragment.CommonTerminals", "Fragment.Surface", "Fragment.ScalarOverride", "EdgeId.Fragment.Common", "EdgeId.Fragment.QuadSurface", "EdgeId.Fragment.QuadParam", "PointId.Fragment.Fallback", "Visibility.Fragment.Fallback", "Mesh.Fragment.PatchCoord", "Mesh.Fragment"] } -}}} -------------------------------------------------------- -======================================================= - VERTEX SHADER -======================================================= -#version 450 -#extension GL_NV_shader_buffer_load : require -#extension GL_NV_gpu_shader5 : require -#extension GL_ARB_bindless_texture : require -#extension GL_ARB_shader_draw_parameters : require -int HgiGetBaseVertex() { - return gl_BaseVertexARB; -} -#define REF(space,type) inout type -#define FORWARD_DECL(func_decl) func_decl; -#define ATOMIC_LOAD(a) (a) -#define ATOMIC_STORE(a, v) (a) = (v) -#define ATOMIC_ADD(a, v) atomicAdd(a, v) -#define ATOMIC_EXCHANGE(a, v) atomicExchange(a, v) -#define ATOMIC_COMP_SWAP(a, expected, desired) atomicCompSwap(a, expected, desired) -#define atomic_int int -#define atomic_uint uint - -#define HGI_HAS_DOUBLE_TYPE 1 - - -struct hgi_ivec3 { int x, y, z; }; -struct hgi_vec3 { float x, y, z; }; -struct hgi_dvec3 { double x, y, z; }; -struct hgi_mat3 { float m00, m01, m02, - m10, m11, m12, - m20, m21, m22; }; -struct hgi_dmat3 { double m00, m01, m02, - m10, m11, m12, - m20, m21, m22; }; - - -// //////// Codegen Defines //////// -#define HD_SHADER_API 2 -#define MAT4 mat4 -// Alias hgi vec and matrix types to hd. -#define hd_ivec3 hgi_ivec3 -#define hd_vec3 hgi_vec3 -#define hd_dvec3 hgi_dvec3 -#define hd_mat3 hgi_mat3 -#define hd_dmat3 hgi_dmat3 - -ivec3 hd_ivec3_get(hd_ivec3 v) { return ivec3(v.x, v.y, v.z); } -ivec3 hd_ivec3_get(ivec3 v) { return v; } -vec3 hd_vec3_get(hd_vec3 v) { return vec3(v.x, v.y, v.z); } -vec3 hd_vec3_get(vec3 v) { return v; } -dvec3 hd_dvec3_get(hd_dvec3 v) { return dvec3(v.x, v.y, v.z); } -dvec3 hd_dvec3_get(dvec3 v) { return v; } -mat3 hd_mat3_get(hd_mat3 v) { return mat3(v.m00, v.m01, v.m02, - v.m10, v.m11, v.m12, - v.m20, v.m21, v.m22); } -mat3 hd_mat3_get(mat3 v) { return v; } -dmat3 hd_dmat3_get(hd_dmat3 v) { return dmat3(v.m00, v.m01, v.m02, - v.m10, v.m11, v.m12, - v.m20, v.m21, v.m22); } -dmat3 hd_dmat3_get(dmat3 v) { return v; } -hd_ivec3 hd_ivec3_set(hd_ivec3 v) { return v; } -hd_ivec3 hd_ivec3_set(ivec3 v) { return hd_ivec3(v.x, v.y, v.z); } -hd_vec3 hd_vec3_set(hd_vec3 v) { return v; } -hd_vec3 hd_vec3_set(vec3 v) { return hd_vec3(v.x, v.y, v.z); } -hd_dvec3 hd_dvec3_set(hd_dvec3 v) { return v; } -hd_dvec3 hd_dvec3_set(dvec3 v) { return hd_dvec3(v.x, v.y, v.z); } -hd_mat3 hd_mat3_set(hd_mat3 v) { return v; } -hd_mat3 hd_mat3_set(mat3 v) { return hd_mat3(v[0][0], v[0][1], v[0][2], - v[1][0], v[1][1], v[1][2], - v[2][0], v[2][1], v[2][2]); } -hd_dmat3 hd_dmat3_set(hd_dmat3 v) { return v; } -hd_dmat3 hd_dmat3_set(dmat3 v) { return hd_dmat3(v[0][0], v[0][1], v[0][2], - v[1][0], v[1][1], v[1][2], - v[2][0], v[2][1], v[2][2]); } -int hd_int_get(int v) { return v; } -int hd_int_get(ivec2 v) { return v.x; } -int hd_int_get(ivec3 v) { return v.x; } -int hd_int_get(ivec4 v) { return v.x; } -vec3 hd_sample_udim(vec2 v) { -vec2 vf = floor(v); -return vec3(v.x - vf.x, v.y - vf.y, clamp(vf.x, 0.0, 10.0) + 10.0 * vf.y); -} -vec4 hd_vec4_2_10_10_10_get(int v) { - ivec4 unpacked = ivec4((v & 0x3ff) << 22, (v & 0xffc00) << 12, - (v & 0x3ff00000) << 2, (v & 0xc0000000)); - return vec4(unpacked) / 2147483647.0; } -int hd_vec4_2_10_10_10_set(vec4 v) { - return ( (int(v.x * 511.0) & 0x3ff) | - ((int(v.y * 511.0) & 0x3ff) << 10) | - ((int(v.z * 511.0) & 0x3ff) << 20) | - ((int(v.w) & 0x1) << 30)); } -vec2 hd_half2_get(uint v) { - return unpackHalf2x16(v); } -uint hd_half2_set(vec2 v) { - return packHalf2x16(v); } -vec4 hd_half4_get(uvec2 v) { - return vec4(unpackHalf2x16(v.x), unpackHalf2x16(v.y)); } -uvec2 hd_half4_set(vec4 v) { - return uvec2(packHalf2x16(v.xy), packHalf2x16(v.zw)); } -#define HD_NUM_PRIMITIVE_VERTS 4 -#define HD_HAS_transform 1 -#define HD_HAS_transformInverse 1 -#define HD_HAS_color 1 -#define HD_HAS_primID 1 -#define HD_HAS_widths 1 -#define HD_HAS_INSTANCE_hydra_instanceTranslations 1 -#define HD_HAS_hydra_instanceTranslations_0 1 -#define HD_INSTANCER_NUM_LEVELS 1 -#define HD_INSTANCE_INDEX_WIDTH 2 -#define HD_HAS_faceVisibility 1 -#define HD_HAS_dispTextureCoord 1 -#define HD_HAS_points 1 -#define HD_HAS_normals 1 - - -// //////// Global Includes //////// - -// //////// Global Macros //////// - -// //////// Global Structs //////// - -// //////// Global Member Declarations //////// -uint hd_VertexID = gl_VertexID; -uint hd_InstanceID = gl_InstanceID; -uint hd_BaseInstance = 0; - -// //////// Global Function Definitions //////// - - -// //////// Codegen Decl //////// -struct hd_drawingCoord { - int modelCoord; - int constantCoord; - int elementCoord; - int primitiveCoord; - int fvarCoord; - int shaderCoord; - int vertexCoord; - int topologyVisibilityCoord; - int varyingCoord; - int instanceIndex[HD_INSTANCE_INDEX_WIDTH]; - int instanceCoords[HD_INSTANCE_INDEX_WIDTH]; -}; -FORWARD_DECL(hd_drawingCoord GetDrawingCoord()); -FORWARD_DECL(int HgiGetBaseVertex()); -struct hd_instanceIndex { int indices[HD_INSTANCE_INDEX_WIDTH]; }; -struct ConstantData10 { - mat4 transform; - mat4 transformInverse; - vec4 color; - vec4 primID; - float widths; -}; -FORWARD_DECL(int GetElementID()); -FORWARD_DECL(int GetAggregatedElementID()); -FORWARD_DECL(int GetPrimitiveEdgeId()); -FORWARD_DECL(float GetSelectedEdgeOpacity()); -layout (location = 2) in ivec4 drawingCoord0; -layout (location = 3) in ivec4 drawingCoord1; -layout (location = 4) in ivec2 drawingCoord2; -layout (location = 5) in int drawingCoordI0; -layout (location = 0) in vec3 points; -layout (location = 1) in vec3 normals; -out flat int vs_dc_modelCoord; -out flat int vs_dc_constantCoord; -out flat int vs_dc_elementCoord; -out flat int vs_dc_primitiveCoord; -out flat int vs_dc_fvarCoord; -out flat int vs_dc_shaderCoord; -out flat int vs_dc_vertexCoord; -out flat int vs_dc_topologyVisibilityCoord; -out flat int vs_dc_varyingCoord; -out flat int vs_dc_instanceIndexI0; -out flat int vs_dc_instanceIndexI1; -out flat int vs_dc_instanceCoordsI0; -out flat int vs_dc_instanceCoordsI1; -layout(location = 6) uniform int *instanceIndices; -layout(location = 7) uniform int *culledInstanceIndices; -layout(location = 0) uniform ConstantData10 *constantPrimvars; -layout(location = 1) uniform hd_vec3 *hydra_instanceTranslations_0; -layout(location = 2) uniform int *primitiveParam; -layout(location = 3) uniform ivec2 *edgeIndices; -layout(location = 4) uniform float *faceVisibility; -out VertexData { - vec4 Peye; - vec3 Neye; -} outData; -out PrimvarData { - vec3 points; - vec3 normals; -} outPrimvars; - -// //////// Codegen Accessors //////// -mat4 HdGet_transform(int localIndex) { - int index = GetDrawingCoord().constantCoord; - return mat4(constantPrimvars[index].transform); -} -mat4 HdGet_transform() { return HdGet_transform(0); } -mat4 HdGet_transformInverse(int localIndex) { - int index = GetDrawingCoord().constantCoord; - return mat4(constantPrimvars[index].transformInverse); -} -mat4 HdGet_transformInverse() { return HdGet_transformInverse(0); } -vec4 HdGet_color(int localIndex) { - int index = GetDrawingCoord().constantCoord; - return vec4(constantPrimvars[index].color); -} -vec4 HdGet_color() { return HdGet_color(0); } -float HdGetScalar_color(int localIndex) { return HdGet_color(localIndex).x; } -float HdGetScalar_color() { return HdGet_color(0).x; } -vec4 HdGet_primID(int localIndex) { - int index = GetDrawingCoord().constantCoord; - return vec4(constantPrimvars[index].primID); -} -vec4 HdGet_primID() { return HdGet_primID(0); } -float HdGetScalar_primID(int localIndex) { return HdGet_primID(localIndex).x; } -float HdGetScalar_primID() { return HdGet_primID(0).x; } -float HdGet_widths(int localIndex) { - int index = GetDrawingCoord().constantCoord; - return float(constantPrimvars[index].widths); -} -float HdGet_widths() { return HdGet_widths(0); } -float HdGetScalar_widths(int localIndex) { return HdGet_widths(localIndex); } -float HdGetScalar_widths() { return HdGet_widths(0); } -vec3 HdGet_hydra_instanceTranslations_0(int localIndex) { - int index = GetDrawingCoord().instanceCoords[0]; - return hd_vec3_get(hydra_instanceTranslations_0[index]); -} -vec3 HdGet_hydra_instanceTranslations_0() { return HdGet_hydra_instanceTranslations_0(0); } -float HdGetScalar_hydra_instanceTranslations_0(int localIndex) { return HdGet_hydra_instanceTranslations_0(localIndex).x; } -float HdGetScalar_hydra_instanceTranslations_0() { return HdGet_hydra_instanceTranslations_0(0).x; } -vec3 HdGetInstance_hydra_instanceTranslations(int level, vec3 defaultValue) { - if (level == 0) return HdGet_hydra_instanceTranslations_0(); - return defaultValue; -} -#if !defined(HD_HAS_hydra_instanceTranslations) -#define HD_HAS_hydra_instanceTranslations 1 -vec3 HdGet_hydra_instanceTranslations(int localIndex) { - return HdGet_hydra_instanceTranslations_0(); -} -vec3 HdGet_hydra_instanceTranslations() { return HdGet_hydra_instanceTranslations(0); } -#endif - -// //////// Codegen VS Source //////// -#define HD_BINDLESS_BUFFERS_ENABLED -int GetBaseInstanceIndexCoord() { - return drawingCoord1.y; -} -int GetCurrentInstance() { - return int(hd_InstanceID - hd_BaseInstance); -} -int GetInstanceIndexCoord() { - return GetBaseInstanceIndexCoord() + GetCurrentInstance() * HD_INSTANCE_INDEX_WIDTH; -} -int HdGet_culledInstanceIndices(int localIndex) { - int index = GetInstanceIndexCoord()+localIndex + 1; - return int(culledInstanceIndices[index]); -} -int HdGet_culledInstanceIndices() { return HdGet_culledInstanceIndices(0); } -int HdGetScalar_culledInstanceIndices(int localIndex) { return HdGet_culledInstanceIndices(localIndex); } -int HdGetScalar_culledInstanceIndices() { return HdGet_culledInstanceIndices(0); } -int GetBaseVertexOffset() { - return HgiGetBaseVertex(); -} -hd_instanceIndex GetInstanceIndex() { - hd_instanceIndex r; - for (int i = 0; i < HD_INSTANCE_INDEX_WIDTH; ++i) - r.indices[i] = HdGet_culledInstanceIndices(/*localIndex=*/i); - return r; -} -hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = drawingCoord0.x; - dc.constantCoord = drawingCoord0.y; - dc.elementCoord = drawingCoord0.z; - dc.primitiveCoord = drawingCoord0.w; - dc.fvarCoord = drawingCoord1.x; - dc.shaderCoord = drawingCoord1.z; - dc.vertexCoord = drawingCoord1.w; - dc.topologyVisibilityCoord = drawingCoord2.x; - dc.varyingCoord = drawingCoord2.y; - hd_instanceIndex r = GetInstanceIndex(); - dc.instanceIndex[0] = r.indices[0]; - dc.instanceIndex[1] = r.indices[1]; - dc.instanceCoords[0] = drawingCoordI0 + dc.instanceIndex[1]; - return dc; -} -vec3 HdGet_points(int localIndex) { return hd_vec3_get(points);} -vec3 HdGet_points() { return HdGet_points(0); } -float HdGetScalar_points(int localIndex) { return HdGet_points(localIndex).x; } -float HdGetScalar_points() { return HdGet_points(0).x; } -vec3 HdGet_normals(int localIndex) { return hd_vec3_get(normals);} -vec3 HdGet_normals() { return HdGet_normals(0); } -float HdGetScalar_normals(int localIndex) { return HdGet_normals(localIndex).x; } -float HdGetScalar_normals() { return HdGet_normals(0).x; } - -// //////// Codegen Proc VS //////// -void ProcessPrimvarsIn() { - hd_drawingCoord dc = GetDrawingCoord(); - vs_dc_modelCoord = dc.modelCoord; - vs_dc_constantCoord = dc.constantCoord; - vs_dc_elementCoord = dc.elementCoord; - vs_dc_primitiveCoord = dc.primitiveCoord; - vs_dc_fvarCoord = dc.fvarCoord; - vs_dc_shaderCoord = dc.shaderCoord; - vs_dc_vertexCoord = dc.vertexCoord; - vs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - vs_dc_varyingCoord = dc.varyingCoord; - vs_dc_instanceIndexI0 = dc.instanceIndex[0]; - vs_dc_instanceIndexI1 = dc.instanceIndex[1]; - vs_dc_instanceCoordsI0 = dc.instanceCoords[0]; - outPrimvars.points = points; - outPrimvars.normals = normals; -} - -// --------------------------------------------------------------------------- -// global defines -// --------------------------------------------------------------------------- -// codeGen can override this range (currently not). -// quadro 4000's max is 189. -#ifndef HD_GL_POINT_SIZE_MAX -#define HD_GL_POINT_SIZE_MAX 100.0 -#endif -#ifndef HD_GL_POINT_SIZE_MIN -#define HD_GL_POINT_SIZE_MIN .45 -#endif - -// --------------------------------------------------------------------------- -// render pass states -// --------------------------------------------------------------------------- - -MAT4 GetWorldToViewMatrix() { -#if defined(HD_HAS_worldToViewMatrix) - return MAT4(HdGet_worldToViewMatrix()); -#else - return MAT4(1); -#endif -} -MAT4 GetWorldToViewInverseMatrix() { -#if defined(HD_HAS_worldToViewInverseMatrix) - return MAT4(HdGet_worldToViewInverseMatrix()); -#else - return MAT4(1); -#endif -} -MAT4 GetProjectionMatrix() { -#if defined(HD_HAS_projectionMatrix) - return MAT4(HdGet_projectionMatrix()); -#else - return MAT4(1); -#endif -} -vec3 GetPositionInWorldSpace(vec3 windowRelativeCoord) -{ -#if defined(HD_HAS_imageToWorldMatrix) - vec4 pImage = vec4(windowRelativeCoord, 1.0); - vec4 pWorld = vec4(HdGet_imageToWorldMatrix() * pImage); - return (pWorld / pWorld.w).xyz; -#else - return windowRelativeCoord; -#endif -} -float GetLightingBlendAmount() { -#if defined(HD_HAS_lightingBlendAmount) - return HdGet_lightingBlendAmount(); -#else - return 1; -#endif -} -vec4 GetViewport() { -#if defined(HD_HAS_viewport) - return HdGet_viewport(); -#else - return vec4(0,0,1,1); -#endif -} -float GetTessLevel() { -#if defined(HD_HAS_tessLevel) - return HdGet_tessLevel(); -#else - return 1; -#endif -} -float GetPointSize() { -#if defined(HD_HAS_pointSize) - return HdGet_pointSize(); -#else - return 3.0; -#endif -} -float GetPointSelectedSize() { -#if defined(HD_HAS_pointSelectedSize) - return HdGet_pointSelectedSize(); -#else - return 5.0; -#endif -} -vec4 GetWireframeColor() { -// Individual prims can specify an alternative wireframe color -// to one specified in the render pass. This is used in cases were -// there is not enough contrast with the normal one. -#if defined(HD_HAS_overrideWireframeColor) - return HdGet_overrideWireframeColor(); -#elif defined(HD_HAS_wireframeColor) - return HdGet_wireframeColor(); -#else - return vec4(0,0,0,0); -#endif -} -vec4 GetMaskColor() { -#if defined(HD_HAS_maskColor) - return HdGet_maskColor(); -#else - return vec4(0.5,0,0,1); -#endif -} -vec4 GetIndicatorColor() { -#if defined(HD_HAS_indicatorColor) - return HdGet_indicatorColor(); -#else - return vec4(0,0.5,0,1); -#endif -} - -bool ShouldDiscardByAlpha(vec4 color) -{ -#if defined(HD_HAS_alphaThreshold) - float alphaThreshold = HdGet_alphaThreshold(); -#else - float alphaThreshold = 0; -#endif - return (color.a < alphaThreshold); -} - -vec2 ApplyAxisAlignedAffineTransform(vec4 t, vec2 pt) -{ - return t.xy * pt + t.zw; -} - - - -void ApplyClipPlanes(vec4 Peye) -{ -#if defined(HD_HAS_numClipPlanes) -#if defined(HD_HAS_clipPlanes) - for (int i=0; i> 2); -} -int GetAggregatedElementID() { - return GetElementID() - + GetDrawingCoord().elementCoord; -} -ivec2 HdGet_edgeIndices(int localIndex) { - int index = GetPrimitiveIndex(); - return ivec2(edgeIndices[index]); -} -ivec2 HdGet_edgeIndices() { return HdGet_edgeIndices(0); } -int HdGetScalar_edgeIndices(int localIndex) { return HdGet_edgeIndices(localIndex).x; } -int HdGetScalar_edgeIndices() { return HdGet_edgeIndices(0).x; } -int GetAuthoredEdgeId(int primitiveEdgeId) { - return primitiveEdgeId; -} -float HdGet_faceVisibility(int localIndex) { - int index = GetAggregatedElementID(); - return float(faceVisibility[index]); -} -float HdGet_faceVisibility() { return HdGet_faceVisibility(0); } -float HdGetScalar_faceVisibility(int localIndex) { return HdGet_faceVisibility(localIndex); } -float HdGetScalar_faceVisibility() { return HdGet_faceVisibility(0); } -vec3 HdGet_points(int localIndex) { - int index = localIndex; - return vec3(inPrimvars[index].points); -} -vec3 HdGet_points() { return HdGet_points(0); } -float HdGetScalar_points(int localIndex) { return HdGet_points(localIndex).x; } -float HdGetScalar_points() { return HdGet_points(0).x; } -vec3 HdGet_normals(int localIndex) { - int index = localIndex; - return vec3(inPrimvars[index].normals); -} -vec3 HdGet_normals() { return HdGet_normals(0); } -float HdGetScalar_normals(int localIndex) { return HdGet_normals(localIndex).x; } -float HdGetScalar_normals() { return HdGet_normals(0).x; } -vec2 HdGet_dispTextureCoord_Coarse(int localIndex) { - int fvarIndex = GetFVarIndex(localIndex); - return vec2(dispTextureCoord[fvarIndex]); -} -vec2 HdGet_dispTextureCoord(int localIndex, vec2 st) { - return mix(mix(HdGet_dispTextureCoord_Coarse(0),HdGet_dispTextureCoord_Coarse(1), st.x),mix(HdGet_dispTextureCoord_Coarse(3),HdGet_dispTextureCoord_Coarse(2), st.x), st.y); -} -FORWARD_DECL(vec4 GetPatchCoord(int index)); -FORWARD_DECL(vec2 GetPatchCoordLocalST()); -vec2 HdGet_dispTextureCoord(int localIndex) { - vec2 localST = GetPatchCoord(localIndex).xy; - return HdGet_dispTextureCoord(localIndex, localST); -} -vec2 HdGet_dispTextureCoord() { return HdGet_dispTextureCoord(0); } -FORWARD_DECL(vec4 GetPatchCoord(int localIndex)); -void ProcessSamplingTransforms(MAT4 instanceModelViewInverse) { -} - -// //////// Codegen Proc GS //////// -FORWARD_DECL(vec4 GetPatchCoord(int index)); -void ProcessPrimvarsOut(int index) { - vec2 localST = GetPatchCoord(index).xy; - const vec3 coords[4] = vec3[]( - vec3(1,0,0), vec3(0,1,0), vec3(0,0,1), vec3(0,1,0) - ); - hd_barycentricCoord = coords[index]; - hd_drawingCoord dc = GetDrawingCoord(); - gs_dc_modelCoord = dc.modelCoord; - gs_dc_constantCoord = dc.constantCoord; - gs_dc_elementCoord = dc.elementCoord; - gs_dc_primitiveCoord = dc.primitiveCoord; - gs_dc_fvarCoord = dc.fvarCoord; - gs_dc_shaderCoord = dc.shaderCoord; - gs_dc_vertexCoord = dc.vertexCoord; - gs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - gs_dc_varyingCoord = dc.varyingCoord; - gs_dc_instanceIndexI0 = dc.instanceIndex[0]; - gs_dc_instanceIndexI1 = dc.instanceIndex[1]; - gs_dc_instanceCoordsI0 = dc.instanceCoords[0]; - outPrimvars.points = inPrimvars[index].points; - outPrimvars.normals = inPrimvars[index].normals; - outPrimvars.dispTextureCoord = HdGet_dispTextureCoord(index); -} - -// --------------------------------------------------------------------------- -// global defines -// --------------------------------------------------------------------------- -// codeGen can override this range (currently not). -// quadro 4000's max is 189. -#ifndef HD_GL_POINT_SIZE_MAX -#define HD_GL_POINT_SIZE_MAX 100.0 -#endif -#ifndef HD_GL_POINT_SIZE_MIN -#define HD_GL_POINT_SIZE_MIN .45 -#endif - -// --------------------------------------------------------------------------- -// render pass states -// --------------------------------------------------------------------------- - -MAT4 GetWorldToViewMatrix() { -#if defined(HD_HAS_worldToViewMatrix) - return MAT4(HdGet_worldToViewMatrix()); -#else - return MAT4(1); -#endif -} -MAT4 GetWorldToViewInverseMatrix() { -#if defined(HD_HAS_worldToViewInverseMatrix) - return MAT4(HdGet_worldToViewInverseMatrix()); -#else - return MAT4(1); -#endif -} -MAT4 GetProjectionMatrix() { -#if defined(HD_HAS_projectionMatrix) - return MAT4(HdGet_projectionMatrix()); -#else - return MAT4(1); -#endif -} -vec3 GetPositionInWorldSpace(vec3 windowRelativeCoord) -{ -#if defined(HD_HAS_imageToWorldMatrix) - vec4 pImage = vec4(windowRelativeCoord, 1.0); - vec4 pWorld = vec4(HdGet_imageToWorldMatrix() * pImage); - return (pWorld / pWorld.w).xyz; -#else - return windowRelativeCoord; -#endif -} -float GetLightingBlendAmount() { -#if defined(HD_HAS_lightingBlendAmount) - return HdGet_lightingBlendAmount(); -#else - return 1; -#endif -} -vec4 GetViewport() { -#if defined(HD_HAS_viewport) - return HdGet_viewport(); -#else - return vec4(0,0,1,1); -#endif -} -float GetTessLevel() { -#if defined(HD_HAS_tessLevel) - return HdGet_tessLevel(); -#else - return 1; -#endif -} -float GetPointSize() { -#if defined(HD_HAS_pointSize) - return HdGet_pointSize(); -#else - return 3.0; -#endif -} -float GetPointSelectedSize() { -#if defined(HD_HAS_pointSelectedSize) - return HdGet_pointSelectedSize(); -#else - return 5.0; -#endif -} -vec4 GetWireframeColor() { -// Individual prims can specify an alternative wireframe color -// to one specified in the render pass. This is used in cases were -// there is not enough contrast with the normal one. -#if defined(HD_HAS_overrideWireframeColor) - return HdGet_overrideWireframeColor(); -#elif defined(HD_HAS_wireframeColor) - return HdGet_wireframeColor(); -#else - return vec4(0,0,0,0); -#endif -} -vec4 GetMaskColor() { -#if defined(HD_HAS_maskColor) - return HdGet_maskColor(); -#else - return vec4(0.5,0,0,1); -#endif -} -vec4 GetIndicatorColor() { -#if defined(HD_HAS_indicatorColor) - return HdGet_indicatorColor(); -#else - return vec4(0,0.5,0,1); -#endif -} - -bool ShouldDiscardByAlpha(vec4 color) -{ -#if defined(HD_HAS_alphaThreshold) - float alphaThreshold = HdGet_alphaThreshold(); -#else - float alphaThreshold = 0; -#endif - return (color.a < alphaThreshold); -} - -vec2 ApplyAxisAlignedAffineTransform(vec4 t, vec2 pt) -{ - return t.xy * pt + t.zw; -} - - - -void ApplyClipPlanes(vec4 Peye) -{ -#if defined(HD_HAS_numClipPlanes) -#if defined(HD_HAS_clipPlanes) - for (int i=0; i 0.0) - normal = normalize(normal); - return normal; -} - -vec3 GetNormal(vec3 Neye, int index, vec2 localST) -{ - return GetNormal(Neye, index); -} - - - -vec3 GetTriGeometryNormal(vec3 Neye, vec4 Peye0, vec4 Peye1, vec4 Peye2, - bool isFlipped) -{ - return Neye; -} - -vec3 GetQuadGeometryNormal(vec3 Neye, - vec4 Peye0, vec4 Peye1, vec4 Peye2, vec4 Peye3, - bool isFlipped) -{ - return Neye; -} - - - -vec4 DisplacementTerminal(int index, vec4 Peye, vec3 Neye, vec4 patchCoord) -{ - return Peye; -} - - - -vec4 GetPatchCoord(int index) -{ - vec2 uv[4]; - uv[0] = vec2(0, 0); - uv[1] = vec2(1, 0); - uv[2] = vec2(1, 1); - uv[3] = vec2(0, 1); - - ivec3 patchParam = GetPatchParam(); - return InterpolatePatchCoord(uv[index], patchParam); -} - -void emit(int index, vec4 Peye, vec3 Neye) -{ - outData.Peye = Peye; - outData.Neye = Neye; - - gsPatchCoord = GetPatchCoord(index); - - gl_Position = vec4(GetProjectionMatrix() * outData.Peye); - ApplyClipPlanes(outData.Peye); - - ProcessPrimvarsOut(index); - - EmitVertex(); -} - -void main(void) -{ - gl_PrimitiveID = gl_PrimitiveIDIn; - - bool isFlipped = IsFlipped(); // consider handedness AND negative-scale - - vec3 Neye0 = GetNormal(inData[0].Neye, 0); - Neye0 = GetQuadGeometryNormal(Neye0, inData[0].Peye, inData[1].Peye, - inData[2].Peye, inData[3].Peye, isFlipped); - vec3 Neye1 = GetNormal(inData[1].Neye, 1); - Neye1 = GetQuadGeometryNormal(Neye1, inData[0].Peye, inData[1].Peye, - inData[2].Peye, inData[3].Peye, isFlipped); - vec3 Neye2 = GetNormal(inData[2].Neye, 2); - Neye2 = GetQuadGeometryNormal(Neye2, inData[0].Peye, inData[1].Peye, - inData[2].Peye, inData[3].Peye, isFlipped); - vec3 Neye3 = GetNormal(inData[3].Neye, 3); - Neye3 = GetQuadGeometryNormal(Neye3, inData[0].Peye, inData[1].Peye, - inData[2].Peye, inData[3].Peye, isFlipped); - - vec4 Peye0 = DisplacementTerminal( - 0, inData[0].Peye, Neye0, GetPatchCoord(0)); - vec4 Peye1 = DisplacementTerminal( - 1, inData[1].Peye, Neye1, GetPatchCoord(1)); - vec4 Peye2 = DisplacementTerminal( - 2, inData[2].Peye, Neye2, GetPatchCoord(2)); - vec4 Peye3 = DisplacementTerminal( - 3, inData[3].Peye, Neye3, GetPatchCoord(3)); - - // Generate triangles (0,1,2) and (2,3,0) - // 3---2 - // | .| - // | . | - // |. | - // 0---1 - // The indices post-quadrangulation/subdivision follow the convention: - // 0 -> original (hull) vertex - // 1,3 -> edge vertices - // 2 -> center vertex - // - // By having index 2 in both the triangles, we ensure the pre-quadrangulated - // face's normal (at the center) is part of the rasterizer interpolation, - // which matters when we use smooth/limit normals. - // In the case of flat normals, we use the vertex positions, so it doesn't - // matter. - - // triangle 0: vertices (0,1,2) - emit(0, Peye0, Neye0); - emit(1, Peye1, Neye1); - emit(2, Peye2, Neye2); - EndPrimitive(); - - // triangle 1: vertices (2,3,0) - gl_PrimitiveID = gl_PrimitiveIDIn; - emit(2, Peye2, Neye2); - emit(3, Peye3, Neye3); - emit(0, Peye0, Neye0); - EndPrimitive(); -} - - -======================================================= - FRAGMENT SHADER -======================================================= -#version 450 -#extension GL_NV_shader_buffer_load : require -#extension GL_NV_gpu_shader5 : require -#extension GL_ARB_bindless_texture : require -#define REF(space,type) inout type -#define FORWARD_DECL(func_decl) func_decl; -#define ATOMIC_LOAD(a) (a) -#define ATOMIC_STORE(a, v) (a) = (v) -#define ATOMIC_ADD(a, v) atomicAdd(a, v) -#define ATOMIC_EXCHANGE(a, v) atomicExchange(a, v) -#define ATOMIC_COMP_SWAP(a, expected, desired) atomicCompSwap(a, expected, desired) -#define atomic_int int -#define atomic_uint uint - -#define HGI_HAS_DOUBLE_TYPE 1 - - -struct hgi_ivec3 { int x, y, z; }; -struct hgi_vec3 { float x, y, z; }; -struct hgi_dvec3 { double x, y, z; }; -struct hgi_mat3 { float m00, m01, m02, - m10, m11, m12, - m20, m21, m22; }; -struct hgi_dmat3 { double m00, m01, m02, - m10, m11, m12, - m20, m21, m22; }; - - - -// //////// Global Includes //////// - -// //////// Global Macros //////// - -// //////// Global Structs //////// - -// //////// Global Member Declarations //////// - -// //////// Global Function Definitions //////// - - -// //////// Codegen Defines //////// -#define HD_SHADER_API 2 -#define MAT4 mat4 -// Alias hgi vec and matrix types to hd. -#define hd_ivec3 hgi_ivec3 -#define hd_vec3 hgi_vec3 -#define hd_dvec3 hgi_dvec3 -#define hd_mat3 hgi_mat3 -#define hd_dmat3 hgi_dmat3 - -ivec3 hd_ivec3_get(hd_ivec3 v) { return ivec3(v.x, v.y, v.z); } -ivec3 hd_ivec3_get(ivec3 v) { return v; } -vec3 hd_vec3_get(hd_vec3 v) { return vec3(v.x, v.y, v.z); } -vec3 hd_vec3_get(vec3 v) { return v; } -dvec3 hd_dvec3_get(hd_dvec3 v) { return dvec3(v.x, v.y, v.z); } -dvec3 hd_dvec3_get(dvec3 v) { return v; } -mat3 hd_mat3_get(hd_mat3 v) { return mat3(v.m00, v.m01, v.m02, - v.m10, v.m11, v.m12, - v.m20, v.m21, v.m22); } -mat3 hd_mat3_get(mat3 v) { return v; } -dmat3 hd_dmat3_get(hd_dmat3 v) { return dmat3(v.m00, v.m01, v.m02, - v.m10, v.m11, v.m12, - v.m20, v.m21, v.m22); } -dmat3 hd_dmat3_get(dmat3 v) { return v; } -hd_ivec3 hd_ivec3_set(hd_ivec3 v) { return v; } -hd_ivec3 hd_ivec3_set(ivec3 v) { return hd_ivec3(v.x, v.y, v.z); } -hd_vec3 hd_vec3_set(hd_vec3 v) { return v; } -hd_vec3 hd_vec3_set(vec3 v) { return hd_vec3(v.x, v.y, v.z); } -hd_dvec3 hd_dvec3_set(hd_dvec3 v) { return v; } -hd_dvec3 hd_dvec3_set(dvec3 v) { return hd_dvec3(v.x, v.y, v.z); } -hd_mat3 hd_mat3_set(hd_mat3 v) { return v; } -hd_mat3 hd_mat3_set(mat3 v) { return hd_mat3(v[0][0], v[0][1], v[0][2], - v[1][0], v[1][1], v[1][2], - v[2][0], v[2][1], v[2][2]); } -hd_dmat3 hd_dmat3_set(hd_dmat3 v) { return v; } -hd_dmat3 hd_dmat3_set(dmat3 v) { return hd_dmat3(v[0][0], v[0][1], v[0][2], - v[1][0], v[1][1], v[1][2], - v[2][0], v[2][1], v[2][2]); } -int hd_int_get(int v) { return v; } -int hd_int_get(ivec2 v) { return v.x; } -int hd_int_get(ivec3 v) { return v.x; } -int hd_int_get(ivec4 v) { return v.x; } -vec3 hd_sample_udim(vec2 v) { -vec2 vf = floor(v); -return vec3(v.x - vf.x, v.y - vf.y, clamp(vf.x, 0.0, 10.0) + 10.0 * vf.y); -} -vec4 hd_vec4_2_10_10_10_get(int v) { - ivec4 unpacked = ivec4((v & 0x3ff) << 22, (v & 0xffc00) << 12, - (v & 0x3ff00000) << 2, (v & 0xc0000000)); - return vec4(unpacked) / 2147483647.0; } -int hd_vec4_2_10_10_10_set(vec4 v) { - return ( (int(v.x * 511.0) & 0x3ff) | - ((int(v.y * 511.0) & 0x3ff) << 10) | - ((int(v.z * 511.0) & 0x3ff) << 20) | - ((int(v.w) & 0x1) << 30)); } -vec2 hd_half2_get(uint v) { - return unpackHalf2x16(v); } -uint hd_half2_set(vec2 v) { - return packHalf2x16(v); } -vec4 hd_half4_get(uvec2 v) { - return vec4(unpackHalf2x16(v.x), unpackHalf2x16(v.y)); } -uvec2 hd_half4_set(vec4 v) { - return uvec2(packHalf2x16(v.xy), packHalf2x16(v.zw)); } -#define HD_NUM_PRIMITIVE_VERTS 4 -#define HD_HAS_transform 1 -#define HD_HAS_transformInverse 1 -#define HD_HAS_color 1 -#define HD_HAS_primID 1 -#define HD_HAS_widths 1 -#define HD_HAS_INSTANCE_hydra_instanceTranslations 1 -#define HD_HAS_hydra_instanceTranslations_0 1 -#define HD_INSTANCER_NUM_LEVELS 1 -#define HD_INSTANCE_INDEX_WIDTH 2 -#define HD_HAS_faceVisibility 1 -#define HD_HAS_dispTextureCoord 1 -#define HD_HAS_points 1 -#define HD_HAS_normals 1 - -// //////// Codegen Decl //////// -struct hd_drawingCoord { - int modelCoord; - int constantCoord; - int elementCoord; - int primitiveCoord; - int fvarCoord; - int shaderCoord; - int vertexCoord; - int topologyVisibilityCoord; - int varyingCoord; - int instanceIndex[HD_INSTANCE_INDEX_WIDTH]; - int instanceCoords[HD_INSTANCE_INDEX_WIDTH]; -}; -FORWARD_DECL(hd_drawingCoord GetDrawingCoord()); -FORWARD_DECL(int HgiGetBaseVertex()); -struct hd_instanceIndex { int indices[HD_INSTANCE_INDEX_WIDTH]; }; -struct ConstantData10 { - mat4 transform; - mat4 transformInverse; - vec4 color; - vec4 primID; - float widths; -}; -FORWARD_DECL(int GetElementID()); -FORWARD_DECL(int GetAggregatedElementID()); -FORWARD_DECL(int GetPrimitiveEdgeId()); -FORWARD_DECL(float GetSelectedEdgeOpacity()); -layout(location = 6) uniform int *instanceIndices; -layout(location = 7) uniform int *culledInstanceIndices; -layout(location = 0) uniform ConstantData10 *constantPrimvars; -layout(location = 1) uniform hd_vec3 *hydra_instanceTranslations_0; -layout(location = 2) uniform int *primitiveParam; -layout(location = 3) uniform ivec2 *edgeIndices; -layout(location = 4) uniform float *faceVisibility; -in vec4 gsPatchCoord; -in VertexData { - vec4 Peye; - vec3 Neye; -} inData; -layout (location = 0) out vec4 colorOut; -in noperspective vec3 hd_barycentricCoord; -in PrimvarData { - vec3 points; - vec3 normals; - vec2 dispTextureCoord; -} inPrimvars; -in flat int gs_dc_modelCoord; -in flat int gs_dc_constantCoord; -in flat int gs_dc_elementCoord; -in flat int gs_dc_primitiveCoord; -in flat int gs_dc_fvarCoord; -in flat int gs_dc_shaderCoord; -in flat int gs_dc_vertexCoord; -in flat int gs_dc_topologyVisibilityCoord; -in flat int gs_dc_varyingCoord; -in flat int gs_dc_instanceIndexI0; -in flat int gs_dc_instanceIndexI1; -in flat int gs_dc_instanceCoordsI0; -in flat int gs_dc_instanceCoordsI1; -layout(location = 5) uniform vec2 *dispTextureCoord; -vec4 InterpolatePatchCoord(vec2 uv, ivec3 patchParam) -{ - // add 0.5 to integer values for more robust interpolation - return vec4(uv.x, uv.y, 0, patchParam.x+0.5f); -} -vec4 InterpolatePatchCoordTriangle(vec2 uv, ivec3 patchParam) -{ - return InterpolatePatchCoord(uv, patchParam); -} - -// //////// Codegen Accessors //////// -mat4 HdGet_transform(int localIndex) { - int index = GetDrawingCoord().constantCoord; - return mat4(constantPrimvars[index].transform); -} -mat4 HdGet_transform() { return HdGet_transform(0); } -mat4 HdGet_transformInverse(int localIndex) { - int index = GetDrawingCoord().constantCoord; - return mat4(constantPrimvars[index].transformInverse); -} -mat4 HdGet_transformInverse() { return HdGet_transformInverse(0); } -vec4 HdGet_color(int localIndex) { - int index = GetDrawingCoord().constantCoord; - return vec4(constantPrimvars[index].color); -} -vec4 HdGet_color() { return HdGet_color(0); } -float HdGetScalar_color(int localIndex) { return HdGet_color(localIndex).x; } -float HdGetScalar_color() { return HdGet_color(0).x; } -vec4 HdGet_primID(int localIndex) { - int index = GetDrawingCoord().constantCoord; - return vec4(constantPrimvars[index].primID); -} -vec4 HdGet_primID() { return HdGet_primID(0); } -float HdGetScalar_primID(int localIndex) { return HdGet_primID(localIndex).x; } -float HdGetScalar_primID() { return HdGet_primID(0).x; } -float HdGet_widths(int localIndex) { - int index = GetDrawingCoord().constantCoord; - return float(constantPrimvars[index].widths); -} -float HdGet_widths() { return HdGet_widths(0); } -float HdGetScalar_widths(int localIndex) { return HdGet_widths(localIndex); } -float HdGetScalar_widths() { return HdGet_widths(0); } -vec3 HdGet_hydra_instanceTranslations_0(int localIndex) { - int index = GetDrawingCoord().instanceCoords[0]; - return hd_vec3_get(hydra_instanceTranslations_0[index]); -} -vec3 HdGet_hydra_instanceTranslations_0() { return HdGet_hydra_instanceTranslations_0(0); } -float HdGetScalar_hydra_instanceTranslations_0(int localIndex) { return HdGet_hydra_instanceTranslations_0(localIndex).x; } -float HdGetScalar_hydra_instanceTranslations_0() { return HdGet_hydra_instanceTranslations_0(0).x; } -vec3 HdGetInstance_hydra_instanceTranslations(int level, vec3 defaultValue) { - if (level == 0) return HdGet_hydra_instanceTranslations_0(); - return defaultValue; -} -#if !defined(HD_HAS_hydra_instanceTranslations) -#define HD_HAS_hydra_instanceTranslations 1 -vec3 HdGet_hydra_instanceTranslations(int localIndex) { - return HdGet_hydra_instanceTranslations_0(); -} -vec3 HdGet_hydra_instanceTranslations() { return HdGet_hydra_instanceTranslations(0); } -#endif - -// //////// Codegen FS Source //////// -#define HD_SHADER_SUPPORTS_DOUBLE_PRECISION -#define HD_MINUS_ONE_TO_ONE_DEPTH_RANGE -vec3 GetBarycentricCoord() { - return hd_barycentricCoord; -} -int GetPrimitiveID() { - return gl_PrimitiveID; -} -int GetPrimitiveIndex() { - return GetDrawingCoord().primitiveCoord + GetPrimitiveID(); -} -hd_drawingCoord GetDrawingCoord() { - hd_drawingCoord dc; - dc.modelCoord = gs_dc_modelCoord; - dc.constantCoord = gs_dc_constantCoord; - dc.elementCoord = gs_dc_elementCoord; - dc.primitiveCoord = gs_dc_primitiveCoord; - dc.fvarCoord = gs_dc_fvarCoord; - dc.shaderCoord = gs_dc_shaderCoord; - dc.vertexCoord = gs_dc_vertexCoord; - dc.topologyVisibilityCoord = gs_dc_topologyVisibilityCoord; - dc.varyingCoord = gs_dc_varyingCoord; - dc.instanceIndex[0] = gs_dc_instanceIndexI0; - dc.instanceIndex[1] = gs_dc_instanceIndexI1; - dc.instanceCoords[0] = gs_dc_instanceCoordsI0; - return dc; -} -int HdGet_primitiveParam(int localIndex) { - int index = GetPrimitiveIndex(); - return int(primitiveParam[index]); -} -int HdGet_primitiveParam() { return HdGet_primitiveParam(0); } -int HdGetScalar_primitiveParam(int localIndex) { return HdGet_primitiveParam(localIndex); } -int HdGetScalar_primitiveParam() { return HdGet_primitiveParam(0); } -#if defined(HD_HAS_coarseFaceIndex) -FORWARD_DECL(int HdGetScalar_coarseFaceIndex()); -#endif -ivec3 GetPatchParam() { -#if defined(HD_HAS_coarseFaceIndex) - return ivec3(HdGetScalar_coarseFaceIndex(), 0, 0); -#else - return ivec3(GetPrimitiveID(), 0, 0); -#endif -} -int GetEdgeFlag() { - return (HdGet_primitiveParam() & 3); -} -int GetFVarIndex(int localIndex) { - int fvarCoord = GetDrawingCoord().fvarCoord; - int ptexIndex = GetPatchParam().x & 0xfffffff; - return fvarCoord + ptexIndex * 4 + localIndex; -} -int GetElementID() { - return (hd_int_get(HdGet_primitiveParam()) >> 2); -} -int GetAggregatedElementID() { - return GetElementID() - + GetDrawingCoord().elementCoord; -} -ivec2 HdGet_edgeIndices(int localIndex) { - int index = GetPrimitiveIndex(); - return ivec2(edgeIndices[index]); -} -ivec2 HdGet_edgeIndices() { return HdGet_edgeIndices(0); } -int HdGetScalar_edgeIndices(int localIndex) { return HdGet_edgeIndices(localIndex).x; } -int HdGetScalar_edgeIndices() { return HdGet_edgeIndices(0).x; } -int GetAuthoredEdgeId(int primitiveEdgeId) { - return primitiveEdgeId; -} -float HdGet_faceVisibility(int localIndex) { - int index = GetAggregatedElementID(); - return float(faceVisibility[index]); -} -float HdGet_faceVisibility() { return HdGet_faceVisibility(0); } -float HdGetScalar_faceVisibility(int localIndex) { return HdGet_faceVisibility(localIndex); } -float HdGetScalar_faceVisibility() { return HdGet_faceVisibility(0); } -vec3 HdGet_points(int localIndex) { return vec3(inPrimvars.points);} -vec3 HdGet_points() { return HdGet_points(0); } -float HdGetScalar_points(int localIndex) { return HdGet_points(localIndex).x; } -float HdGetScalar_points() { return HdGet_points(0).x; } -vec3 HdGet_normals(int localIndex) { return vec3(inPrimvars.normals);} -vec3 HdGet_normals() { return HdGet_normals(0); } -float HdGetScalar_normals(int localIndex) { return HdGet_normals(localIndex).x; } -float HdGetScalar_normals() { return HdGet_normals(0).x; } -vec2 HdGet_dispTextureCoord(int localIndex) { return vec2(inPrimvars.dispTextureCoord);} -vec2 HdGet_dispTextureCoord() { return HdGet_dispTextureCoord(0); } -float HdGetScalar_dispTextureCoord(int localIndex) { return HdGet_dispTextureCoord(localIndex).x; } -float HdGetScalar_dispTextureCoord() { return HdGet_dispTextureCoord(0).x; } -FORWARD_DECL(vec4 GetPatchCoord(int index)); -void ProcessSamplingTransforms(MAT4 instanceModelViewInverse) { -} - -// --------------------------------------------------------------------------- -// global defines -// --------------------------------------------------------------------------- -// codeGen can override this range (currently not). -// quadro 4000's max is 189. -#ifndef HD_GL_POINT_SIZE_MAX -#define HD_GL_POINT_SIZE_MAX 100.0 -#endif -#ifndef HD_GL_POINT_SIZE_MIN -#define HD_GL_POINT_SIZE_MIN .45 -#endif - -// --------------------------------------------------------------------------- -// render pass states -// --------------------------------------------------------------------------- - -MAT4 GetWorldToViewMatrix() { -#if defined(HD_HAS_worldToViewMatrix) - return MAT4(HdGet_worldToViewMatrix()); -#else - return MAT4(1); -#endif -} -MAT4 GetWorldToViewInverseMatrix() { -#if defined(HD_HAS_worldToViewInverseMatrix) - return MAT4(HdGet_worldToViewInverseMatrix()); -#else - return MAT4(1); -#endif -} -MAT4 GetProjectionMatrix() { -#if defined(HD_HAS_projectionMatrix) - return MAT4(HdGet_projectionMatrix()); -#else - return MAT4(1); -#endif -} -vec3 GetPositionInWorldSpace(vec3 windowRelativeCoord) -{ -#if defined(HD_HAS_imageToWorldMatrix) - vec4 pImage = vec4(windowRelativeCoord, 1.0); - vec4 pWorld = vec4(HdGet_imageToWorldMatrix() * pImage); - return (pWorld / pWorld.w).xyz; -#else - return windowRelativeCoord; -#endif -} -float GetLightingBlendAmount() { -#if defined(HD_HAS_lightingBlendAmount) - return HdGet_lightingBlendAmount(); -#else - return 1; -#endif -} -vec4 GetViewport() { -#if defined(HD_HAS_viewport) - return HdGet_viewport(); -#else - return vec4(0,0,1,1); -#endif -} -float GetTessLevel() { -#if defined(HD_HAS_tessLevel) - return HdGet_tessLevel(); -#else - return 1; -#endif -} -float GetPointSize() { -#if defined(HD_HAS_pointSize) - return HdGet_pointSize(); -#else - return 3.0; -#endif -} -float GetPointSelectedSize() { -#if defined(HD_HAS_pointSelectedSize) - return HdGet_pointSelectedSize(); -#else - return 5.0; -#endif -} -vec4 GetWireframeColor() { -// Individual prims can specify an alternative wireframe color -// to one specified in the render pass. This is used in cases were -// there is not enough contrast with the normal one. -#if defined(HD_HAS_overrideWireframeColor) - return HdGet_overrideWireframeColor(); -#elif defined(HD_HAS_wireframeColor) - return HdGet_wireframeColor(); -#else - return vec4(0,0,0,0); -#endif -} -vec4 GetMaskColor() { -#if defined(HD_HAS_maskColor) - return HdGet_maskColor(); -#else - return vec4(0.5,0,0,1); -#endif -} -vec4 GetIndicatorColor() { -#if defined(HD_HAS_indicatorColor) - return HdGet_indicatorColor(); -#else - return vec4(0,0.5,0,1); -#endif -} - -bool ShouldDiscardByAlpha(vec4 color) -{ -#if defined(HD_HAS_alphaThreshold) - float alphaThreshold = HdGet_alphaThreshold(); -#else - float alphaThreshold = 0; -#endif - return (color.a < alphaThreshold); -} - -vec2 ApplyAxisAlignedAffineTransform(vec4 t, vec2 pt) -{ - return t.xy * pt + t.zw; -} - - - -vec2 HorizontallyNormalizedFilmbackCoordinates() -{ - const vec4 transform = -#ifdef HD_HAS_imageToHorizontallyNormalizedFilmback - HdGet_imageToHorizontallyNormalizedFilmback(); -#else - vec4(vec2(1.0), vec2(0.0)); -#endif - return ApplyAxisAlignedAffineTransform(transform, gl_FragCoord.xy); -} - - - -vec4 ApplySelectionColor(vec4 color) -{ - return color; -} - - - -// Forward declare selection functionality. -// XXX: Currently, the non-empty implementation of this is in hdx. -FORWARD_DECL(vec4 ApplySelectionColor(vec4 color)); - -// XXX: Make sure to update hdx/shaders/renderPass.glslfx when editing these -// color override methods, since they're currently duplicated. This is because -// we don't have a mixin token for color overrides in a render pass yet. -vec4 ApplyColorOverrides(vec4 color) -{ -#if defined(HD_HAS_overrideColor) - // Mix in override color - vec4 overrideColor = HdGet_overrideColor(); - color.rgb = mix(color.rgb, overrideColor.rgb, overrideColor.a); -#endif - return ApplySelectionColor(color); -} - -vec3 ApplyMaskColor(vec3 color, float weight, vec4 maskColor) -{ - float strength = maskColor.a * clamp(weight, 0.0, 1.0); - return mix(color, maskColor.rgb, strength); -} - -vec4 ApplyColorOverridesPostLighting(vec4 color) -{ - #if defined(HD_HAS_maskWeight) - float maskWeight = HdGet_maskWeight(); - vec4 maskColor = GetMaskColor(); - color.rgb = ApplyMaskColor(color.rgb, maskWeight, maskColor); - #endif - #if defined(HD_HAS_indicatorWeight) - float indicatorWeight = HdGet_indicatorWeight(); - vec4 indicatorColor = GetIndicatorColor(); - color.rgb = ApplyMaskColor(color.rgb, indicatorWeight, indicatorColor); - #endif - return color; -} - - - -void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) -{ - colorOut = color; -} - - -#ifndef HD_HAS_integrateLights -#define HD_HAS_integrateLights -#endif - -struct LightingContribution { - vec3 diffuse; -}; - -struct LightingInterfaceProperties { - float unused; -}; - -LightingContribution -integrateLightsDefault(vec4 Peye, vec3 Neye, LightingInterfaceProperties props) -{ - vec3 n = normalize(Neye); - - LightingContribution result; - result.diffuse = vec3(dot(n, vec3(0,0,1))); - - return result; -} - -LightingContribution -integrateLightsConstant(vec4 Peye, vec3 Neye, LightingInterfaceProperties props) -{ - LightingContribution result; - //pefectly diffuse white hemisphere contribution - result.diffuse = vec3(1); - - return result; -} - - - -FORWARD_DECL( - LightingContribution integrateLights(vec4 Peye, vec3 Neye, - LightingInterfaceProperties props)); - -vec3 FallbackLighting(in vec3 Peye, in vec3 Neye, in vec3 color) -{ - LightingInterfaceProperties props; - LightingContribution light = integrateLights(vec4(Peye, 1), Neye, props); - return color * light.diffuse; -} - - -vec4 surfaceShader(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) -{ - // lighting - color.rgb = FallbackLighting(Peye.xyz, Neye, color.rgb); - return color; -} - - -// quaternion to matrix. xyz = imaginary, w = real -MAT4 GetRotationMatrix(vec4 q) -{ - MAT4 r; - r[0].xyzw = vec4(1 - 2 * (q.y * q.y + q.z * q.z), - 2 * (q.x * q.y + q.z * q.w), - 2 * (q.x * q.z - q.y * q.w), - 0); - r[1].xyzw = vec4( 2 * (q.x * q.y - q.z * q.w), - 1 - 2 * (q.x * q.x + q.z * q.z), - 2 * (q.y * q.z + q.x * q.w), - 0); - r[2].xyzw = vec4( 2 * (q.x * q.z + q.y * q.w), - 2 * (q.y * q.z - q.x * q.w), - 1 - 2 * (q.x * q.x + q.y * q.y), - 0); - r[3] = vec4(0, 0, 0, 1); - return r; -} - -// --------------------------------------------------------------------------- - -MAT4 GetInstanceTransform(int level) -{ - MAT4 m = MAT4(1); -#ifdef HD_HAS_INSTANCE_hydra_instanceTransforms - m = HdGetInstance_hydra_instanceTransforms(level, MAT4(1)) * m; -#elif defined(HD_HAS_INSTANCE_instanceTransform) - m = HdGetInstance_instanceTransform(level, MAT4(1)) * m; -#endif - - // instance transform elements are applied: - // scale then rotate then translate - // i.e. (T * R * S) * position - -#ifdef HD_HAS_INSTANCE_hydra_instanceScales - vec3 s = HdGetInstance_hydra_instanceScales(level, /*default=*/vec3(1)); - m = MAT4(s.x, 0, 0, 0, - 0, s.y, 0, 0, - 0, 0, s.z, 0, - 0, 0, 0, 1) * m; -#elif defined(HD_HAS_INSTANCE_instanceScale) - vec3 s = HdGetInstance_scale(level, /*default=*/vec3(1)); - m = MAT4(s.x, 0, 0, 0, - 0, s.y, 0, 0, - 0, 0, s.z, 0, - 0, 0, 0, 1) * m; -#endif - -#ifdef HD_HAS_INSTANCE_hydra_instanceRotations // GfQuat(ix, iy, iz, real) - vec4 q = HdGetInstance_hydra_instanceRotations(level, /*default=*/vec4(0)); - m = GetRotationMatrix(q) * m; -#elif defined(HD_HAS_INSTANCE_rotate) - vec4 q = HdGetInstance_rotate(level, /*default=*/vec4(0)); - m = GetRotationMatrix(q) * m; -#endif - -#ifdef HD_HAS_INSTANCE_hydra_instanceTranslations - vec3 t = HdGetInstance_hydra_instanceTranslations(level, /*default=*/vec3(0)); - m = MAT4( 1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, 1, 0, - t.x, t.y, t.z, 1) * m; -#elif defined(HD_HAS_INSTANCE_translate) - vec3 t = HdGetInstance_translate(level, /*default=*/vec3(0)); - m = MAT4( 1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, 1, 0, - t.x, t.y, t.z, 1) * m; -#endif - return m; -} - -MAT4 GetInstanceTransformInverse(int level) -{ - MAT4 m = MAT4(1); - -#ifdef HD_HAS_INSTANCE_hydra_instanceTransforms - m = inverse(HdGetInstance_hydra_instanceTransforms(level, MAT4(1))) * m; -#elif defined(HD_HAS_INSTANCE_instanceTransform) - m = inverse(HdGetInstance_instanceTransform(level, MAT4(1))) * m; -#endif - -#ifdef HD_HAS_INSTANCE_hydra_instanceTranslations - vec3 it = -HdGetInstance_hydra_instanceTranslations(level, /*default=*/vec3(0)); // negate - m = MAT4( 1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, 1, 0, - it.x, it.y, it.z, 1) * m; -#elif defined(HD_HAS_INSTANCE_translate) - vec3 it = -HdGetInstance_translate(level, /*default=*/vec3(0)); // negate - m = MAT4( 1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, 1, 0, - it.x, it.y, it.z, 1) * m; -#endif - -#ifdef HD_HAS_INSTANCE_hydra_instanceRotations - vec4 q = HdGetInstance_hydra_instanceRotations(level, /*default=*/vec4(0)); - q.xyz = -q.xyz; // inverse rotataion axis - m = GetRotationMatrix(q) * m; -#elif defined(HD_HAS_INSTANCE_rotate) - vec4 q = HdGetInstance_rotate(level, /*default=*/vec4(0)); - q.xyz = -q.xyz; // inverse rotataion axis - m = GetRotationMatrix(q) * m; -#endif - -#ifdef HD_HAS_INSTANCE_hydra_instanceScales - vec3 is = 1.0/HdGetInstance_hydra_instanceScales(level, /*default=*/vec3(1)); // inverse scale - m = MAT4(is.x, 0, 0, 0, - 0, is.y, 0, 0, - 0, 0, is.z, 0, - 0, 0, 0, 1) * m; -#elif defined(HD_HAS_INSTANCE_scale) - vec3 is = 1.0/HdGetInstance_scale(level, /*default=*/vec3(1)); // inverse scale - m = MAT4(is.x, 0, 0, 0, - 0, is.y, 0, 0, - 0, 0, is.z, 0, - 0, 0, 0, 1) * m; -#endif - return m; -} - -// --------------------------------------------------------------------------- - -MAT4 GetInstanceTransform() -{ - MAT4 m = MAT4(1); -#ifdef HD_INSTANCER_NUM_LEVELS - for (int i = 0; i < HD_INSTANCER_NUM_LEVELS; ++i) { - m = GetInstanceTransform(i) * m; -#ifdef HD_HAS_instancerTransform - m = HdGet_instancerTransform(i) * m; -#endif - } -#endif - return m; -} - -MAT4 GetInstanceTransformInverse() -{ - MAT4 m = MAT4(1); -#ifdef HD_INSTANCER_NUM_LEVELS - for (int i = 0; i < HD_INSTANCER_NUM_LEVELS; ++i) { - m = m * GetInstanceTransformInverse(i); -#ifdef HD_HAS_instancerTransformInverse - m = m * HdGet_instancerTransformInverse(i); -#endif - } -#endif - return m; -} - -// --------------------------------------------------------------------------- - -MAT4 ApplyInstanceTransform(MAT4 m) -{ - return GetInstanceTransform() * m; -} - -MAT4 ApplyInstanceTransformInverse(MAT4 m) -{ - return m * GetInstanceTransformInverse(); -} - -bool IsFlipped() -{ -#if defined(HD_HAS_isFlipped) - bool flip = (HdGet_isFlipped() != 0); -#elif defined(HD_HAS_transform) - // The sign of the determinant indicates whether m flips handedness - bool flip = (determinant(HdGet_transform()) < 0.0); -#else - bool flip = false; -#endif - -#ifdef HD_HAS_INSTANCE_hydra_instanceScales - for (int i = 0; i < HD_INSTANCER_NUM_LEVELS; ++i) { - vec3 scale = HdGetInstance_hydra_instanceScales(i, /*default=*/vec3(1)); - flip = flip != ((sign(scale.x) * sign(scale.y) * sign(scale.z)) < 0); - } -#elif defined(HD_HAS_INSTANCE_scale) - for (int i = 0; i < HD_INSTANCER_NUM_LEVELS; ++i) { - vec3 scale = HdGetInstance_scale(i, /*default=*/vec3(1)); - flip = flip != ((sign(scale.x) * sign(scale.y) * sign(scale.z)) < 0); - } -#endif - -#ifdef HD_HAS_INSTANCE_hydra_instanceTransforms - for (int i = 0; i < HD_INSTANCER_NUM_LEVELS; ++i) { - MAT4 m = HdGetInstance_hydra_instanceTransforms(i, MAT4(1)); - flip = flip != (determinant(m) < 0.0); - } -#elif defined(HD_HAS_INSTANCE_instanceTransform) - for (int i = 0; i < HD_INSTANCER_NUM_LEVELS; ++i) { - MAT4 m = HdGetInstance_instanceTransform(i, MAT4(1)); - flip = flip != (determinant(m) < 0.0); - } -#endif - - return flip; -} - - -vec3 GetNormal(vec3 Neye, int index) -{ - return Neye; -} - -vec3 GetNormal(vec3 Neye, int index, vec2 localST) -{ - return GetNormal(Neye, index); -} - - - -vec3 GetShadingNormal(vec3 N, bool isFlipped) -{ - // the fragment shader takes already-flipped-normals. - // no need to flip here. - return N; -} - - - -void DiscardBasedOnShading(bool frontFacing, bool isFlipped) -{ - // Nothing to do since h/w face culling is used. -} - - - -vec4 ApplyEdgeColor(vec4 Cfill, vec4 patchCoord) -{ - return Cfill; -} - -// Return a large value, signifying that the fragment isn't near an edge. -float GetMinEdgeDistance() -{ - return 1000.0; -} - - - -vec3 GetEdgeParamTriangle() -{ - // Expand barycentric coordinates - vec2 param = GetPatchCoord(0).xy; - vec3 barycentric = vec3(param.x, param.y, 1 - param.x - param.y); - - // Match triangle edge order - return barycentric.yzx; -} - -vec3 GetEdgeDistanceTriangle() -{ - vec3 param = GetEdgeParamTriangle(); - return max(vec3(0.0), param / fwidth(param)); -} - -vec4 GetEdgeParamQuad() -{ - // Expand coordinates to opposite corners of quad - vec2 leftBottom = GetPatchCoord(0).xy; - vec2 rightTop = vec2(1.0) - leftBottom; - - // Match quad edge order - return vec4(leftBottom.y, rightTop.x, rightTop.y, leftBottom.x); -} - -vec4 GetEdgeDistanceQuad() -{ - vec4 param = GetEdgeParamQuad(); - return max(vec4(0.0), param / fwidth(param)); -} - - - -struct ReprStyle -{ - vec4 color; - bool usePrimvarColor; - bool usePrimvarAlpha; - bool applyColorOverride; - bool useSurfaceShaderColor; - bool useSurfaceShaderAlpha; -}; - -struct ScalarOverride -{ - bool enabled; - vec3 color; -}; - -FORWARD_DECL(ReprStyle GetReprStyle()); -FORWARD_DECL(ScalarOverride GetScalarOverride()); -FORWARD_DECL( - vec4 surfaceShader(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord)); -FORWARD_DECL(vec4 postSurfaceShader(vec4 Peye, vec3 Neye, vec4 color)); - -vec4 ShadingTerminal(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) -{ - ReprStyle reprStyle = GetReprStyle(); - - // Apply scalar override. - ScalarOverride scalarOverride = GetScalarOverride(); - if (scalarOverride.enabled) { - vec4 result; - - result.rgb = scalarOverride.color; - result.a = reprStyle.usePrimvarAlpha ? color.a: reprStyle.color.a; - - vec4 colorOverride = ApplyColorOverrides(result); - result = reprStyle.applyColorOverride ? colorOverride : result; - - return result; - } - - // Draw mode can override face color - vec4 reprColor; - - reprColor.rgb = reprStyle.usePrimvarColor ? color.rgb : reprStyle.color.rgb; - reprColor.a = reprStyle.usePrimvarAlpha ? color.a : reprStyle.color.a; - - // Compute color overrides - vec4 colorOverride = ApplyColorOverrides(reprColor); - reprColor = reprStyle.applyColorOverride ? colorOverride : reprColor; - - - // Surface shading can be expensive and also can contain undesirable - // side effects (like discards). So only run it for reprs that require it. - - if (reprStyle.useSurfaceShaderColor || - reprStyle.useSurfaceShaderAlpha) { - vec4 shadingColor; - - shadingColor = surfaceShader(Peye, - Neye, - reprColor, - patchCoord); - -#ifdef HD_HAS_postSurfaceShader - shadingColor = postSurfaceShader(Peye, - Neye, - shadingColor); -#endif - - reprColor.rgb = reprStyle.useSurfaceShaderColor ? - shadingColor.rgb : - reprColor.rgb; - - reprColor.a = reprStyle.useSurfaceShaderAlpha ? - shadingColor.a : - reprColor.a; - } - - vec4 baseColor = color; - baseColor = ApplyColorOverrides(baseColor); - - vec4 litColor = mix(baseColor, - reprColor, - GetLightingBlendAmount()); - - // Final overrides. - - return ApplyColorOverridesPostLighting(litColor); -} - - - -#ifdef HD_HAS_integrateLights -#ifndef HD_HAS_definedIntegrateLights -#define HD_HAS_definedIntegrateLights - -LightingContribution -integrateLights(vec4 Peye, vec3 Neye, LightingInterfaceProperties props) -{ - return integrateLightsDefault(Peye, Neye, props); -} - -#endif // HD_HAS_definedIntegrateLights -#endif - -ReprStyle GetReprStyle() -{ - ReprStyle reprStyle; - - reprStyle.color = vec4(0.0, 0.0, 0.0, 1.0); - reprStyle.usePrimvarColor = true; - reprStyle.usePrimvarAlpha = true; - reprStyle.applyColorOverride = true; - reprStyle.useSurfaceShaderColor = true; - reprStyle.useSurfaceShaderAlpha = true; - - return reprStyle; -} - - - -ScalarOverride GetScalarOverride() -{ - ScalarOverride result; - -#if defined(HD_HAS_scalarOverride) - result.enabled = true; - - // Allow a scalar value to override the color from the surface - // for previewing heatmaps. This is useful for editing workflows. -#if defined(HD_HAS_scalarOverrideColorRamp) - int rampCount = constantPrimvars[GetDrawingCoord().constantCoord]. - scalarOverrideColorRamp.length(); - float scalar = HdGet_scalarOverride() * float(rampCount - 1); - float baseIndex = floor(scalar); - float nextIndex = min(float(rampCount - 1), baseIndex + 1.0); - float interp = scalar - baseIndex; - result.color = mix(HdGet_scalarOverrideColorRamp(int(baseIndex)).rgb, - HdGet_scalarOverrideColorRamp(int(nextIndex)).rgb, - interp); -#else - // If no ramp is given just gamma correct the scalar as greyscale. - result.color = vec3(pow(HdGet_scalarOverride(), 2.2)); -#endif // HD_HAS_scalarOverrideColorRamp - -#else // HD_HAS_scalarOverride - result.enabled = false; - result.color = vec3(0.0, 0.0, 0.0); -#endif - - return result; -} - - - -// Determines whether a fragment is on or close to an unhidden triangle edge. -const float edgePickRadius = 2; // in viewport pixels -const float edgePickParametricRadius = 0.02; // in parametric space - -// For smooth looking edges, use an exponential falloff for the opacity. -// Note: We use a slower falloff fn than in meshWire.glslfx to make the -// selected edges stand out. -float SelectedEdgeFalloff(float d) { - return exp2(-1 * d * d); -} - - - -vec4 ComputeBaseFaceEdgeDistanceQuad() -{ - return GetEdgeDistanceQuad(); -} - -bool SelectWireframeFaceEdges() -{ - return false; -} - - - -float GetSelectedEdgeOpacity() -{ - float closestEdgeDistance = 0.0; - - // The sequence of comparisons should match GetPrimitiveEdgeId() - vec4 dist = ComputeBaseFaceEdgeDistanceQuad(); - if (dist.x < edgePickRadius) { - closestEdgeDistance = dist.x; - } else if (dist.y < edgePickRadius) { - closestEdgeDistance = dist.y; - } else if (dist.z < edgePickRadius) { - closestEdgeDistance = dist.z; - } else if (dist.w < edgePickRadius) { - closestEdgeDistance = dist.w; - } else { - return 0; - } - - return SelectedEdgeFalloff(closestEdgeDistance); -} - -// called from hdx/renderPass.glslfx and selection.glslfx -int GetPrimitiveEdgeId() -{ - // e2 - // (0,1) 3 ------ 2 (1,1) - // | | - // e3 | | e1 - // | | - // (0,0) 0 ------ 1 (1,0) - // e0 - - int edgeId = -1; - - vec4 dist = ComputeBaseFaceEdgeDistanceQuad(); - if (dist.x < edgePickRadius) { - edgeId = 0; - } else if (dist.y < edgePickRadius) { - edgeId = 1; - } else if (dist.z < edgePickRadius) { - edgeId = 2; - } else if (dist.w < edgePickRadius) { - edgeId = 3; - } else { - return -1; // Not on a mesh edge - } - - const int edgeFlag = GetEdgeFlag(); - const ivec2 meshEdgeIndices = HdGet_edgeIndices(); - - // Translate face-edge to authored mesh-edge - if (edgeFlag == 0) { - edgeId = meshEdgeIndices[0] + edgeId; // regular quad face - } else if (edgeId == 0) { - edgeId = meshEdgeIndices[0]; - } else if (edgeId == 3) { - edgeId = meshEdgeIndices[1]; - } else { - edgeId = -1; // Not an authored mesh edge - } - return edgeId; -} - - -int GetPointId() -{ - return -1; -} - - -void DiscardBasedOnTopologicalVisibility() -{ - // Nothing to do, since there's no authored opinion. -} - - - -vec4 GetInterpolatedPatchCoord() -{ - return gsPatchCoord; -} - - - -#ifndef HD_HAS_ptexFaceOffset -#define HD_HAS_ptexFaceOffset -int HdGet_ptexFaceOffset() -{ - return 0; -} -#endif - -vec4 GetPatchCoord(int localIndex) -{ - vec4 patchCoord = GetInterpolatedPatchCoord(); - return vec4(patchCoord.xyz, patchCoord.w + HdGet_ptexFaceOffset()); -} - -vec4 GetPatchCoord() -{ - return GetPatchCoord(0); -} - -vec3 ComputeScreenSpacePeye() -{ - return inData.Peye.xyz / inData.Peye.w; -} - -vec3 ComputeScreenSpaceNeye() -{ - vec3 Peye = ComputeScreenSpacePeye(); - vec3 Neye = normalize(cross(dFdx(Peye), dFdy(Peye))); - return (gl_FrontFacing ? Neye : -Neye); -} - -void main(void) -{ - bool isFlipped = IsFlipped(); - - DiscardBasedOnShading(gl_FrontFacing, isFlipped); - - DiscardBasedOnTopologicalVisibility(); - - vec4 color = vec4(0.5, 0.5, 0.5, 1); -#ifdef HD_HAS_displayColor - color.rgb = HdGet_displayColor().rgb; -#endif -#ifdef HD_HAS_displayOpacity - color.a = HdGet_displayOpacity(); -#endif - - vec3 Peye = ComputeScreenSpacePeye(); - - vec3 Neye = inData.Neye; - // Normalize Neye after rasterizer interpolation. - if (length(Neye) > 0.0) { - Neye = normalize(Neye); - } - // Give the shader key a chance to override the normal. - Neye = GetNormal(Neye, 0); - // Orient the normal for shading. - Neye = GetShadingNormal(Neye, isFlipped); - - vec4 patchCoord = GetPatchCoord(); - color = ShadingTerminal(vec4(Peye, 1), Neye, color, patchCoord); - - color = ApplyEdgeColor(color, patchCoord); - -#ifdef HD_MATERIAL_TAG_MASKED - if (ShouldDiscardByAlpha(color)) { - discard; - return; - } -#endif - - RenderOutput(vec4(Peye, 1), Neye, color, patchCoord); -} - -OK diff --git a/pxr/imaging/hdSt/testenv/testHdStCodeGen_GL/baseline/codegen_mesh_edgeonly.out b/pxr/imaging/hdSt/testenv/testHdStCodeGen_GL/baseline/codegen_mesh_edgeonly.out index cb6007195a6..86d45a5143e 100644 --- a/pxr/imaging/hdSt/testenv/testHdStCodeGen_GL/baseline/codegen_mesh_edgeonly.out +++ b/pxr/imaging/hdSt/testenv/testHdStCodeGen_GL/baseline/codegen_mesh_edgeonly.out @@ -162,22 +162,14 @@ FORWARD_DECL(int GetElementID()); FORWARD_DECL(int GetAggregatedElementID()); FORWARD_DECL(int GetPrimitiveEdgeId()); FORWARD_DECL(float GetSelectedEdgeOpacity()); +out flat ivec4 vs_interstageDrawingCoord0; +out flat ivec4 vs_interstageDrawingCoord1; +out flat ivec4 vs_interstageDrawingCoord2; layout (location = 2) in ivec4 drawingCoord0; layout (location = 3) in ivec4 drawingCoord1; layout (location = 4) in ivec2 drawingCoord2; layout (location = 0) in vec3 points; layout (location = 1) in vec3 normals; -out flat int vs_dc_modelCoord; -out flat int vs_dc_constantCoord; -out flat int vs_dc_elementCoord; -out flat int vs_dc_primitiveCoord; -out flat int vs_dc_fvarCoord; -out flat int vs_dc_shaderCoord; -out flat int vs_dc_vertexCoord; -out flat int vs_dc_topologyVisibilityCoord; -out flat int vs_dc_varyingCoord; -out flat int vs_dc_instanceIndexI0; -out flat int vs_dc_instanceCoordsI0; layout(location = 0) uniform ConstantData10 *constantPrimvars; layout(location = 1) uniform int *primitiveParam; layout(location = 2) uniform int *edgeIndices; @@ -256,16 +248,16 @@ float HdGetScalar_normals() { return HdGet_normals(0).x; } // //////// Codegen Proc VS //////// void ProcessPrimvarsIn() { hd_drawingCoord dc = GetDrawingCoord(); - vs_dc_modelCoord = dc.modelCoord; - vs_dc_constantCoord = dc.constantCoord; - vs_dc_elementCoord = dc.elementCoord; - vs_dc_primitiveCoord = dc.primitiveCoord; - vs_dc_fvarCoord = dc.fvarCoord; - vs_dc_shaderCoord = dc.shaderCoord; - vs_dc_vertexCoord = dc.vertexCoord; - vs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - vs_dc_varyingCoord = dc.varyingCoord; - vs_dc_instanceIndexI0 = dc.instanceIndex[0]; + vs_interstageDrawingCoord0[0] = dc.modelCoord; + vs_interstageDrawingCoord0[1] = dc.constantCoord; + vs_interstageDrawingCoord0[2] = dc.elementCoord; + vs_interstageDrawingCoord0[3] = dc.primitiveCoord; + vs_interstageDrawingCoord1[0] = dc.fvarCoord; + vs_interstageDrawingCoord1[1] = dc.shaderCoord; + vs_interstageDrawingCoord1[2] = dc.vertexCoord; + vs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + vs_interstageDrawingCoord2[0] = dc.varyingCoord; + vs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = points; outPrimvars.normals = normals; } @@ -851,6 +843,12 @@ out VertexData { } outData; out vec4 gsPatchCoord; out noperspective vec3 hd_barycentricCoord; +in flat ivec4 vs_interstageDrawingCoord0[HD_NUM_PRIMITIVE_VERTS]; +out flat ivec4 gs_interstageDrawingCoord0; +in flat ivec4 vs_interstageDrawingCoord1[HD_NUM_PRIMITIVE_VERTS]; +out flat ivec4 gs_interstageDrawingCoord1; +in flat ivec4 vs_interstageDrawingCoord2[HD_NUM_PRIMITIVE_VERTS]; +out flat ivec4 gs_interstageDrawingCoord2; in PrimvarData { vec3 points; vec3 normals; @@ -860,28 +858,6 @@ out PrimvarData { vec3 normals; vec2 dispTextureCoord; } outPrimvars; -in flat int vs_dc_modelCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_modelCoord; -in flat int vs_dc_constantCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_constantCoord; -in flat int vs_dc_elementCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_elementCoord; -in flat int vs_dc_primitiveCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_primitiveCoord; -in flat int vs_dc_fvarCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_fvarCoord; -in flat int vs_dc_shaderCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_shaderCoord; -in flat int vs_dc_vertexCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_vertexCoord; -in flat int vs_dc_topologyVisibilityCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_topologyVisibilityCoord; -in flat int vs_dc_varyingCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_varyingCoord; -in flat int vs_dc_instanceIndexI0[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_instanceIndexI0; -in flat int vs_dc_instanceCoordsI0[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_instanceCoordsI0; layout(location = 4) uniform vec2 *dispTextureCoord; // //////// Codegen Accessors //////// @@ -926,16 +902,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = vs_dc_modelCoord[0]; - dc.constantCoord = vs_dc_constantCoord[0]; - dc.elementCoord = vs_dc_elementCoord[0]; - dc.primitiveCoord = vs_dc_primitiveCoord[0]; - dc.fvarCoord = vs_dc_fvarCoord[0]; - dc.shaderCoord = vs_dc_shaderCoord[0]; - dc.vertexCoord = vs_dc_vertexCoord[0]; - dc.topologyVisibilityCoord = vs_dc_topologyVisibilityCoord[0]; - dc.varyingCoord = vs_dc_varyingCoord[0]; - dc.instanceIndex[0] = vs_dc_instanceIndexI0[0]; + dc.modelCoord = vs_interstageDrawingCoord0[0][0]; + dc.constantCoord = vs_interstageDrawingCoord0[0][1]; + dc.elementCoord = vs_interstageDrawingCoord0[0][2]; + dc.primitiveCoord = vs_interstageDrawingCoord0[0][3]; + dc.fvarCoord = vs_interstageDrawingCoord1[0][0]; + dc.shaderCoord = vs_interstageDrawingCoord1[0][1]; + dc.vertexCoord = vs_interstageDrawingCoord1[0][2]; + dc.topologyVisibilityCoord = vs_interstageDrawingCoord1[0][3]; + dc.varyingCoord = vs_interstageDrawingCoord2[0][0]; + dc.instanceIndex[0] = vs_interstageDrawingCoord2[0][1]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -1028,16 +1004,16 @@ void ProcessPrimvarsOut(int index) { ); hd_barycentricCoord = coords[index]; hd_drawingCoord dc = GetDrawingCoord(); - gs_dc_modelCoord = dc.modelCoord; - gs_dc_constantCoord = dc.constantCoord; - gs_dc_elementCoord = dc.elementCoord; - gs_dc_primitiveCoord = dc.primitiveCoord; - gs_dc_fvarCoord = dc.fvarCoord; - gs_dc_shaderCoord = dc.shaderCoord; - gs_dc_vertexCoord = dc.vertexCoord; - gs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - gs_dc_varyingCoord = dc.varyingCoord; - gs_dc_instanceIndexI0 = dc.instanceIndex[0]; + gs_interstageDrawingCoord0[0] = dc.modelCoord; + gs_interstageDrawingCoord0[1] = dc.constantCoord; + gs_interstageDrawingCoord0[2] = dc.elementCoord; + gs_interstageDrawingCoord0[3] = dc.primitiveCoord; + gs_interstageDrawingCoord1[0] = dc.fvarCoord; + gs_interstageDrawingCoord1[1] = dc.shaderCoord; + gs_interstageDrawingCoord1[2] = dc.vertexCoord; + gs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + gs_interstageDrawingCoord2[0] = dc.varyingCoord; + gs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = inPrimvars[index].points; outPrimvars.normals = inPrimvars[index].normals; outPrimvars.dispTextureCoord = HdGet_dispTextureCoord(index); @@ -1662,22 +1638,14 @@ in VertexData { } inData; layout (location = 0) out vec4 colorOut; in noperspective vec3 hd_barycentricCoord; +in flat ivec4 gs_interstageDrawingCoord0; +in flat ivec4 gs_interstageDrawingCoord1; +in flat ivec4 gs_interstageDrawingCoord2; in PrimvarData { vec3 points; vec3 normals; vec2 dispTextureCoord; } inPrimvars; -in flat int gs_dc_modelCoord; -in flat int gs_dc_constantCoord; -in flat int gs_dc_elementCoord; -in flat int gs_dc_primitiveCoord; -in flat int gs_dc_fvarCoord; -in flat int gs_dc_shaderCoord; -in flat int gs_dc_vertexCoord; -in flat int gs_dc_topologyVisibilityCoord; -in flat int gs_dc_varyingCoord; -in flat int gs_dc_instanceIndexI0; -in flat int gs_dc_instanceCoordsI0; layout(location = 4) uniform vec2 *dispTextureCoord; vec4 InterpolatePatchCoord(vec2 uv, ivec3 patchParam) { @@ -1736,16 +1704,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = gs_dc_modelCoord; - dc.constantCoord = gs_dc_constantCoord; - dc.elementCoord = gs_dc_elementCoord; - dc.primitiveCoord = gs_dc_primitiveCoord; - dc.fvarCoord = gs_dc_fvarCoord; - dc.shaderCoord = gs_dc_shaderCoord; - dc.vertexCoord = gs_dc_vertexCoord; - dc.topologyVisibilityCoord = gs_dc_topologyVisibilityCoord; - dc.varyingCoord = gs_dc_varyingCoord; - dc.instanceIndex[0] = gs_dc_instanceIndexI0; + dc.modelCoord = gs_interstageDrawingCoord0[0]; + dc.constantCoord = gs_interstageDrawingCoord0[1]; + dc.elementCoord = gs_interstageDrawingCoord0[2]; + dc.primitiveCoord = gs_interstageDrawingCoord0[3]; + dc.fvarCoord = gs_interstageDrawingCoord1[0]; + dc.shaderCoord = gs_interstageDrawingCoord1[1]; + dc.vertexCoord = gs_interstageDrawingCoord1[2]; + dc.topologyVisibilityCoord = gs_interstageDrawingCoord1[3]; + dc.varyingCoord = gs_interstageDrawingCoord2[0]; + dc.instanceIndex[0] = gs_interstageDrawingCoord2[1]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -1999,12 +1967,37 @@ vec4 ApplyColorOverridesPostLighting(vec4 color) -void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +void RenderColor(vec4 color) { colorOut = color; } + +void RenderId() +{ + // do nothing +} + + + +void RenderNeye(vec3 Neye) +{ + // do nothing +} + + + +void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +{ + // Write to any desired AOVs here. The render pass shader configuation + // decides if any of these are no-ops. + RenderColor(color); + RenderId(); + RenderNeye(Neye); +} + + #ifndef HD_HAS_integrateLights #define HD_HAS_integrateLights #endif @@ -2887,22 +2880,14 @@ FORWARD_DECL(int GetElementID()); FORWARD_DECL(int GetAggregatedElementID()); FORWARD_DECL(int GetPrimitiveEdgeId()); FORWARD_DECL(float GetSelectedEdgeOpacity()); +out flat ivec4 vs_interstageDrawingCoord0; +out flat ivec4 vs_interstageDrawingCoord1; +out flat ivec4 vs_interstageDrawingCoord2; layout (location = 2) in ivec4 drawingCoord0; layout (location = 3) in ivec4 drawingCoord1; layout (location = 4) in ivec2 drawingCoord2; layout (location = 0) in vec3 points; layout (location = 1) in vec3 normals; -out flat int vs_dc_modelCoord; -out flat int vs_dc_constantCoord; -out flat int vs_dc_elementCoord; -out flat int vs_dc_primitiveCoord; -out flat int vs_dc_fvarCoord; -out flat int vs_dc_shaderCoord; -out flat int vs_dc_vertexCoord; -out flat int vs_dc_topologyVisibilityCoord; -out flat int vs_dc_varyingCoord; -out flat int vs_dc_instanceIndexI0; -out flat int vs_dc_instanceCoordsI0; layout(location = 0) uniform ConstantData10 *constantPrimvars; layout(location = 1) uniform int *primitiveParam; layout(location = 2) uniform ivec2 *edgeIndices; @@ -2981,16 +2966,16 @@ float HdGetScalar_normals() { return HdGet_normals(0).x; } // //////// Codegen Proc VS //////// void ProcessPrimvarsIn() { hd_drawingCoord dc = GetDrawingCoord(); - vs_dc_modelCoord = dc.modelCoord; - vs_dc_constantCoord = dc.constantCoord; - vs_dc_elementCoord = dc.elementCoord; - vs_dc_primitiveCoord = dc.primitiveCoord; - vs_dc_fvarCoord = dc.fvarCoord; - vs_dc_shaderCoord = dc.shaderCoord; - vs_dc_vertexCoord = dc.vertexCoord; - vs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - vs_dc_varyingCoord = dc.varyingCoord; - vs_dc_instanceIndexI0 = dc.instanceIndex[0]; + vs_interstageDrawingCoord0[0] = dc.modelCoord; + vs_interstageDrawingCoord0[1] = dc.constantCoord; + vs_interstageDrawingCoord0[2] = dc.elementCoord; + vs_interstageDrawingCoord0[3] = dc.primitiveCoord; + vs_interstageDrawingCoord1[0] = dc.fvarCoord; + vs_interstageDrawingCoord1[1] = dc.shaderCoord; + vs_interstageDrawingCoord1[2] = dc.vertexCoord; + vs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + vs_interstageDrawingCoord2[0] = dc.varyingCoord; + vs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = points; outPrimvars.normals = normals; } @@ -3576,6 +3561,12 @@ out VertexData { } outData; out vec4 gsPatchCoord; out noperspective vec3 hd_barycentricCoord; +in flat ivec4 vs_interstageDrawingCoord0[HD_NUM_PRIMITIVE_VERTS]; +out flat ivec4 gs_interstageDrawingCoord0; +in flat ivec4 vs_interstageDrawingCoord1[HD_NUM_PRIMITIVE_VERTS]; +out flat ivec4 gs_interstageDrawingCoord1; +in flat ivec4 vs_interstageDrawingCoord2[HD_NUM_PRIMITIVE_VERTS]; +out flat ivec4 gs_interstageDrawingCoord2; in PrimvarData { vec3 points; vec3 normals; @@ -3585,28 +3576,6 @@ out PrimvarData { vec3 normals; vec2 dispTextureCoord; } outPrimvars; -in flat int vs_dc_modelCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_modelCoord; -in flat int vs_dc_constantCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_constantCoord; -in flat int vs_dc_elementCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_elementCoord; -in flat int vs_dc_primitiveCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_primitiveCoord; -in flat int vs_dc_fvarCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_fvarCoord; -in flat int vs_dc_shaderCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_shaderCoord; -in flat int vs_dc_vertexCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_vertexCoord; -in flat int vs_dc_topologyVisibilityCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_topologyVisibilityCoord; -in flat int vs_dc_varyingCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_varyingCoord; -in flat int vs_dc_instanceIndexI0[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_instanceIndexI0; -in flat int vs_dc_instanceCoordsI0[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_instanceCoordsI0; layout(location = 4) uniform vec2 *dispTextureCoord; // //////// Codegen Accessors //////// @@ -3651,16 +3620,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = vs_dc_modelCoord[0]; - dc.constantCoord = vs_dc_constantCoord[0]; - dc.elementCoord = vs_dc_elementCoord[0]; - dc.primitiveCoord = vs_dc_primitiveCoord[0]; - dc.fvarCoord = vs_dc_fvarCoord[0]; - dc.shaderCoord = vs_dc_shaderCoord[0]; - dc.vertexCoord = vs_dc_vertexCoord[0]; - dc.topologyVisibilityCoord = vs_dc_topologyVisibilityCoord[0]; - dc.varyingCoord = vs_dc_varyingCoord[0]; - dc.instanceIndex[0] = vs_dc_instanceIndexI0[0]; + dc.modelCoord = vs_interstageDrawingCoord0[0][0]; + dc.constantCoord = vs_interstageDrawingCoord0[0][1]; + dc.elementCoord = vs_interstageDrawingCoord0[0][2]; + dc.primitiveCoord = vs_interstageDrawingCoord0[0][3]; + dc.fvarCoord = vs_interstageDrawingCoord1[0][0]; + dc.shaderCoord = vs_interstageDrawingCoord1[0][1]; + dc.vertexCoord = vs_interstageDrawingCoord1[0][2]; + dc.topologyVisibilityCoord = vs_interstageDrawingCoord1[0][3]; + dc.varyingCoord = vs_interstageDrawingCoord2[0][0]; + dc.instanceIndex[0] = vs_interstageDrawingCoord2[0][1]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -3753,16 +3722,16 @@ void ProcessPrimvarsOut(int index) { ); hd_barycentricCoord = coords[index]; hd_drawingCoord dc = GetDrawingCoord(); - gs_dc_modelCoord = dc.modelCoord; - gs_dc_constantCoord = dc.constantCoord; - gs_dc_elementCoord = dc.elementCoord; - gs_dc_primitiveCoord = dc.primitiveCoord; - gs_dc_fvarCoord = dc.fvarCoord; - gs_dc_shaderCoord = dc.shaderCoord; - gs_dc_vertexCoord = dc.vertexCoord; - gs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - gs_dc_varyingCoord = dc.varyingCoord; - gs_dc_instanceIndexI0 = dc.instanceIndex[0]; + gs_interstageDrawingCoord0[0] = dc.modelCoord; + gs_interstageDrawingCoord0[1] = dc.constantCoord; + gs_interstageDrawingCoord0[2] = dc.elementCoord; + gs_interstageDrawingCoord0[3] = dc.primitiveCoord; + gs_interstageDrawingCoord1[0] = dc.fvarCoord; + gs_interstageDrawingCoord1[1] = dc.shaderCoord; + gs_interstageDrawingCoord1[2] = dc.vertexCoord; + gs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + gs_interstageDrawingCoord2[0] = dc.varyingCoord; + gs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = inPrimvars[index].points; outPrimvars.normals = inPrimvars[index].normals; outPrimvars.dispTextureCoord = HdGet_dispTextureCoord(index); @@ -4416,22 +4385,14 @@ in VertexData { } inData; layout (location = 0) out vec4 colorOut; in noperspective vec3 hd_barycentricCoord; +in flat ivec4 gs_interstageDrawingCoord0; +in flat ivec4 gs_interstageDrawingCoord1; +in flat ivec4 gs_interstageDrawingCoord2; in PrimvarData { vec3 points; vec3 normals; vec2 dispTextureCoord; } inPrimvars; -in flat int gs_dc_modelCoord; -in flat int gs_dc_constantCoord; -in flat int gs_dc_elementCoord; -in flat int gs_dc_primitiveCoord; -in flat int gs_dc_fvarCoord; -in flat int gs_dc_shaderCoord; -in flat int gs_dc_vertexCoord; -in flat int gs_dc_topologyVisibilityCoord; -in flat int gs_dc_varyingCoord; -in flat int gs_dc_instanceIndexI0; -in flat int gs_dc_instanceCoordsI0; layout(location = 4) uniform vec2 *dispTextureCoord; vec4 InterpolatePatchCoord(vec2 uv, ivec3 patchParam) { @@ -4490,16 +4451,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = gs_dc_modelCoord; - dc.constantCoord = gs_dc_constantCoord; - dc.elementCoord = gs_dc_elementCoord; - dc.primitiveCoord = gs_dc_primitiveCoord; - dc.fvarCoord = gs_dc_fvarCoord; - dc.shaderCoord = gs_dc_shaderCoord; - dc.vertexCoord = gs_dc_vertexCoord; - dc.topologyVisibilityCoord = gs_dc_topologyVisibilityCoord; - dc.varyingCoord = gs_dc_varyingCoord; - dc.instanceIndex[0] = gs_dc_instanceIndexI0; + dc.modelCoord = gs_interstageDrawingCoord0[0]; + dc.constantCoord = gs_interstageDrawingCoord0[1]; + dc.elementCoord = gs_interstageDrawingCoord0[2]; + dc.primitiveCoord = gs_interstageDrawingCoord0[3]; + dc.fvarCoord = gs_interstageDrawingCoord1[0]; + dc.shaderCoord = gs_interstageDrawingCoord1[1]; + dc.vertexCoord = gs_interstageDrawingCoord1[2]; + dc.topologyVisibilityCoord = gs_interstageDrawingCoord1[3]; + dc.varyingCoord = gs_interstageDrawingCoord2[0]; + dc.instanceIndex[0] = gs_interstageDrawingCoord2[1]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -4753,12 +4714,37 @@ vec4 ApplyColorOverridesPostLighting(vec4 color) -void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +void RenderColor(vec4 color) { colorOut = color; } + +void RenderId() +{ + // do nothing +} + + + +void RenderNeye(vec3 Neye) +{ + // do nothing +} + + + +void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +{ + // Write to any desired AOVs here. The render pass shader configuation + // decides if any of these are no-ops. + RenderColor(color); + RenderId(); + RenderNeye(Neye); +} + + #ifndef HD_HAS_integrateLights #define HD_HAS_integrateLights #endif diff --git a/pxr/imaging/hdSt/testenv/testHdStCodeGen_GL/baseline/codegen_mesh_edgeonly_blendwireframe.out b/pxr/imaging/hdSt/testenv/testHdStCodeGen_GL/baseline/codegen_mesh_edgeonly_blendwireframe.out index ac23cf5bda7..abbd8a00e85 100644 --- a/pxr/imaging/hdSt/testenv/testHdStCodeGen_GL/baseline/codegen_mesh_edgeonly_blendwireframe.out +++ b/pxr/imaging/hdSt/testenv/testHdStCodeGen_GL/baseline/codegen_mesh_edgeonly_blendwireframe.out @@ -162,22 +162,14 @@ FORWARD_DECL(int GetElementID()); FORWARD_DECL(int GetAggregatedElementID()); FORWARD_DECL(int GetPrimitiveEdgeId()); FORWARD_DECL(float GetSelectedEdgeOpacity()); +out flat ivec4 vs_interstageDrawingCoord0; +out flat ivec4 vs_interstageDrawingCoord1; +out flat ivec4 vs_interstageDrawingCoord2; layout (location = 2) in ivec4 drawingCoord0; layout (location = 3) in ivec4 drawingCoord1; layout (location = 4) in ivec2 drawingCoord2; layout (location = 0) in vec3 points; layout (location = 1) in vec3 normals; -out flat int vs_dc_modelCoord; -out flat int vs_dc_constantCoord; -out flat int vs_dc_elementCoord; -out flat int vs_dc_primitiveCoord; -out flat int vs_dc_fvarCoord; -out flat int vs_dc_shaderCoord; -out flat int vs_dc_vertexCoord; -out flat int vs_dc_topologyVisibilityCoord; -out flat int vs_dc_varyingCoord; -out flat int vs_dc_instanceIndexI0; -out flat int vs_dc_instanceCoordsI0; layout(location = 0) uniform ConstantData10 *constantPrimvars; layout(location = 1) uniform int *primitiveParam; layout(location = 2) uniform int *edgeIndices; @@ -256,16 +248,16 @@ float HdGetScalar_normals() { return HdGet_normals(0).x; } // //////// Codegen Proc VS //////// void ProcessPrimvarsIn() { hd_drawingCoord dc = GetDrawingCoord(); - vs_dc_modelCoord = dc.modelCoord; - vs_dc_constantCoord = dc.constantCoord; - vs_dc_elementCoord = dc.elementCoord; - vs_dc_primitiveCoord = dc.primitiveCoord; - vs_dc_fvarCoord = dc.fvarCoord; - vs_dc_shaderCoord = dc.shaderCoord; - vs_dc_vertexCoord = dc.vertexCoord; - vs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - vs_dc_varyingCoord = dc.varyingCoord; - vs_dc_instanceIndexI0 = dc.instanceIndex[0]; + vs_interstageDrawingCoord0[0] = dc.modelCoord; + vs_interstageDrawingCoord0[1] = dc.constantCoord; + vs_interstageDrawingCoord0[2] = dc.elementCoord; + vs_interstageDrawingCoord0[3] = dc.primitiveCoord; + vs_interstageDrawingCoord1[0] = dc.fvarCoord; + vs_interstageDrawingCoord1[1] = dc.shaderCoord; + vs_interstageDrawingCoord1[2] = dc.vertexCoord; + vs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + vs_interstageDrawingCoord2[0] = dc.varyingCoord; + vs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = points; outPrimvars.normals = normals; } @@ -851,6 +843,12 @@ out VertexData { } outData; out vec4 gsPatchCoord; out noperspective vec3 hd_barycentricCoord; +in flat ivec4 vs_interstageDrawingCoord0[HD_NUM_PRIMITIVE_VERTS]; +out flat ivec4 gs_interstageDrawingCoord0; +in flat ivec4 vs_interstageDrawingCoord1[HD_NUM_PRIMITIVE_VERTS]; +out flat ivec4 gs_interstageDrawingCoord1; +in flat ivec4 vs_interstageDrawingCoord2[HD_NUM_PRIMITIVE_VERTS]; +out flat ivec4 gs_interstageDrawingCoord2; in PrimvarData { vec3 points; vec3 normals; @@ -860,28 +858,6 @@ out PrimvarData { vec3 normals; vec2 dispTextureCoord; } outPrimvars; -in flat int vs_dc_modelCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_modelCoord; -in flat int vs_dc_constantCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_constantCoord; -in flat int vs_dc_elementCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_elementCoord; -in flat int vs_dc_primitiveCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_primitiveCoord; -in flat int vs_dc_fvarCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_fvarCoord; -in flat int vs_dc_shaderCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_shaderCoord; -in flat int vs_dc_vertexCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_vertexCoord; -in flat int vs_dc_topologyVisibilityCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_topologyVisibilityCoord; -in flat int vs_dc_varyingCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_varyingCoord; -in flat int vs_dc_instanceIndexI0[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_instanceIndexI0; -in flat int vs_dc_instanceCoordsI0[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_instanceCoordsI0; layout(location = 4) uniform vec2 *dispTextureCoord; // //////// Codegen Accessors //////// @@ -926,16 +902,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = vs_dc_modelCoord[0]; - dc.constantCoord = vs_dc_constantCoord[0]; - dc.elementCoord = vs_dc_elementCoord[0]; - dc.primitiveCoord = vs_dc_primitiveCoord[0]; - dc.fvarCoord = vs_dc_fvarCoord[0]; - dc.shaderCoord = vs_dc_shaderCoord[0]; - dc.vertexCoord = vs_dc_vertexCoord[0]; - dc.topologyVisibilityCoord = vs_dc_topologyVisibilityCoord[0]; - dc.varyingCoord = vs_dc_varyingCoord[0]; - dc.instanceIndex[0] = vs_dc_instanceIndexI0[0]; + dc.modelCoord = vs_interstageDrawingCoord0[0][0]; + dc.constantCoord = vs_interstageDrawingCoord0[0][1]; + dc.elementCoord = vs_interstageDrawingCoord0[0][2]; + dc.primitiveCoord = vs_interstageDrawingCoord0[0][3]; + dc.fvarCoord = vs_interstageDrawingCoord1[0][0]; + dc.shaderCoord = vs_interstageDrawingCoord1[0][1]; + dc.vertexCoord = vs_interstageDrawingCoord1[0][2]; + dc.topologyVisibilityCoord = vs_interstageDrawingCoord1[0][3]; + dc.varyingCoord = vs_interstageDrawingCoord2[0][0]; + dc.instanceIndex[0] = vs_interstageDrawingCoord2[0][1]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -1028,16 +1004,16 @@ void ProcessPrimvarsOut(int index) { ); hd_barycentricCoord = coords[index]; hd_drawingCoord dc = GetDrawingCoord(); - gs_dc_modelCoord = dc.modelCoord; - gs_dc_constantCoord = dc.constantCoord; - gs_dc_elementCoord = dc.elementCoord; - gs_dc_primitiveCoord = dc.primitiveCoord; - gs_dc_fvarCoord = dc.fvarCoord; - gs_dc_shaderCoord = dc.shaderCoord; - gs_dc_vertexCoord = dc.vertexCoord; - gs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - gs_dc_varyingCoord = dc.varyingCoord; - gs_dc_instanceIndexI0 = dc.instanceIndex[0]; + gs_interstageDrawingCoord0[0] = dc.modelCoord; + gs_interstageDrawingCoord0[1] = dc.constantCoord; + gs_interstageDrawingCoord0[2] = dc.elementCoord; + gs_interstageDrawingCoord0[3] = dc.primitiveCoord; + gs_interstageDrawingCoord1[0] = dc.fvarCoord; + gs_interstageDrawingCoord1[1] = dc.shaderCoord; + gs_interstageDrawingCoord1[2] = dc.vertexCoord; + gs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + gs_interstageDrawingCoord2[0] = dc.varyingCoord; + gs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = inPrimvars[index].points; outPrimvars.normals = inPrimvars[index].normals; outPrimvars.dispTextureCoord = HdGet_dispTextureCoord(index); @@ -1662,22 +1638,14 @@ in VertexData { } inData; layout (location = 0) out vec4 colorOut; in noperspective vec3 hd_barycentricCoord; +in flat ivec4 gs_interstageDrawingCoord0; +in flat ivec4 gs_interstageDrawingCoord1; +in flat ivec4 gs_interstageDrawingCoord2; in PrimvarData { vec3 points; vec3 normals; vec2 dispTextureCoord; } inPrimvars; -in flat int gs_dc_modelCoord; -in flat int gs_dc_constantCoord; -in flat int gs_dc_elementCoord; -in flat int gs_dc_primitiveCoord; -in flat int gs_dc_fvarCoord; -in flat int gs_dc_shaderCoord; -in flat int gs_dc_vertexCoord; -in flat int gs_dc_topologyVisibilityCoord; -in flat int gs_dc_varyingCoord; -in flat int gs_dc_instanceIndexI0; -in flat int gs_dc_instanceCoordsI0; layout(location = 4) uniform vec2 *dispTextureCoord; vec4 InterpolatePatchCoord(vec2 uv, ivec3 patchParam) { @@ -1736,16 +1704,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = gs_dc_modelCoord; - dc.constantCoord = gs_dc_constantCoord; - dc.elementCoord = gs_dc_elementCoord; - dc.primitiveCoord = gs_dc_primitiveCoord; - dc.fvarCoord = gs_dc_fvarCoord; - dc.shaderCoord = gs_dc_shaderCoord; - dc.vertexCoord = gs_dc_vertexCoord; - dc.topologyVisibilityCoord = gs_dc_topologyVisibilityCoord; - dc.varyingCoord = gs_dc_varyingCoord; - dc.instanceIndex[0] = gs_dc_instanceIndexI0; + dc.modelCoord = gs_interstageDrawingCoord0[0]; + dc.constantCoord = gs_interstageDrawingCoord0[1]; + dc.elementCoord = gs_interstageDrawingCoord0[2]; + dc.primitiveCoord = gs_interstageDrawingCoord0[3]; + dc.fvarCoord = gs_interstageDrawingCoord1[0]; + dc.shaderCoord = gs_interstageDrawingCoord1[1]; + dc.vertexCoord = gs_interstageDrawingCoord1[2]; + dc.topologyVisibilityCoord = gs_interstageDrawingCoord1[3]; + dc.varyingCoord = gs_interstageDrawingCoord2[0]; + dc.instanceIndex[0] = gs_interstageDrawingCoord2[1]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -1999,12 +1967,37 @@ vec4 ApplyColorOverridesPostLighting(vec4 color) -void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +void RenderColor(vec4 color) { colorOut = color; } + +void RenderId() +{ + // do nothing +} + + + +void RenderNeye(vec3 Neye) +{ + // do nothing +} + + + +void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +{ + // Write to any desired AOVs here. The render pass shader configuation + // decides if any of these are no-ops. + RenderColor(color); + RenderId(); + RenderNeye(Neye); +} + + #ifndef HD_HAS_integrateLights #define HD_HAS_integrateLights #endif @@ -2893,22 +2886,14 @@ FORWARD_DECL(int GetElementID()); FORWARD_DECL(int GetAggregatedElementID()); FORWARD_DECL(int GetPrimitiveEdgeId()); FORWARD_DECL(float GetSelectedEdgeOpacity()); +out flat ivec4 vs_interstageDrawingCoord0; +out flat ivec4 vs_interstageDrawingCoord1; +out flat ivec4 vs_interstageDrawingCoord2; layout (location = 2) in ivec4 drawingCoord0; layout (location = 3) in ivec4 drawingCoord1; layout (location = 4) in ivec2 drawingCoord2; layout (location = 0) in vec3 points; layout (location = 1) in vec3 normals; -out flat int vs_dc_modelCoord; -out flat int vs_dc_constantCoord; -out flat int vs_dc_elementCoord; -out flat int vs_dc_primitiveCoord; -out flat int vs_dc_fvarCoord; -out flat int vs_dc_shaderCoord; -out flat int vs_dc_vertexCoord; -out flat int vs_dc_topologyVisibilityCoord; -out flat int vs_dc_varyingCoord; -out flat int vs_dc_instanceIndexI0; -out flat int vs_dc_instanceCoordsI0; layout(location = 0) uniform ConstantData10 *constantPrimvars; layout(location = 1) uniform int *primitiveParam; layout(location = 2) uniform ivec2 *edgeIndices; @@ -2987,16 +2972,16 @@ float HdGetScalar_normals() { return HdGet_normals(0).x; } // //////// Codegen Proc VS //////// void ProcessPrimvarsIn() { hd_drawingCoord dc = GetDrawingCoord(); - vs_dc_modelCoord = dc.modelCoord; - vs_dc_constantCoord = dc.constantCoord; - vs_dc_elementCoord = dc.elementCoord; - vs_dc_primitiveCoord = dc.primitiveCoord; - vs_dc_fvarCoord = dc.fvarCoord; - vs_dc_shaderCoord = dc.shaderCoord; - vs_dc_vertexCoord = dc.vertexCoord; - vs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - vs_dc_varyingCoord = dc.varyingCoord; - vs_dc_instanceIndexI0 = dc.instanceIndex[0]; + vs_interstageDrawingCoord0[0] = dc.modelCoord; + vs_interstageDrawingCoord0[1] = dc.constantCoord; + vs_interstageDrawingCoord0[2] = dc.elementCoord; + vs_interstageDrawingCoord0[3] = dc.primitiveCoord; + vs_interstageDrawingCoord1[0] = dc.fvarCoord; + vs_interstageDrawingCoord1[1] = dc.shaderCoord; + vs_interstageDrawingCoord1[2] = dc.vertexCoord; + vs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + vs_interstageDrawingCoord2[0] = dc.varyingCoord; + vs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = points; outPrimvars.normals = normals; } @@ -3582,6 +3567,12 @@ out VertexData { } outData; out vec4 gsPatchCoord; out noperspective vec3 hd_barycentricCoord; +in flat ivec4 vs_interstageDrawingCoord0[HD_NUM_PRIMITIVE_VERTS]; +out flat ivec4 gs_interstageDrawingCoord0; +in flat ivec4 vs_interstageDrawingCoord1[HD_NUM_PRIMITIVE_VERTS]; +out flat ivec4 gs_interstageDrawingCoord1; +in flat ivec4 vs_interstageDrawingCoord2[HD_NUM_PRIMITIVE_VERTS]; +out flat ivec4 gs_interstageDrawingCoord2; in PrimvarData { vec3 points; vec3 normals; @@ -3591,28 +3582,6 @@ out PrimvarData { vec3 normals; vec2 dispTextureCoord; } outPrimvars; -in flat int vs_dc_modelCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_modelCoord; -in flat int vs_dc_constantCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_constantCoord; -in flat int vs_dc_elementCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_elementCoord; -in flat int vs_dc_primitiveCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_primitiveCoord; -in flat int vs_dc_fvarCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_fvarCoord; -in flat int vs_dc_shaderCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_shaderCoord; -in flat int vs_dc_vertexCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_vertexCoord; -in flat int vs_dc_topologyVisibilityCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_topologyVisibilityCoord; -in flat int vs_dc_varyingCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_varyingCoord; -in flat int vs_dc_instanceIndexI0[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_instanceIndexI0; -in flat int vs_dc_instanceCoordsI0[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_instanceCoordsI0; layout(location = 4) uniform vec2 *dispTextureCoord; // //////// Codegen Accessors //////// @@ -3657,16 +3626,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = vs_dc_modelCoord[0]; - dc.constantCoord = vs_dc_constantCoord[0]; - dc.elementCoord = vs_dc_elementCoord[0]; - dc.primitiveCoord = vs_dc_primitiveCoord[0]; - dc.fvarCoord = vs_dc_fvarCoord[0]; - dc.shaderCoord = vs_dc_shaderCoord[0]; - dc.vertexCoord = vs_dc_vertexCoord[0]; - dc.topologyVisibilityCoord = vs_dc_topologyVisibilityCoord[0]; - dc.varyingCoord = vs_dc_varyingCoord[0]; - dc.instanceIndex[0] = vs_dc_instanceIndexI0[0]; + dc.modelCoord = vs_interstageDrawingCoord0[0][0]; + dc.constantCoord = vs_interstageDrawingCoord0[0][1]; + dc.elementCoord = vs_interstageDrawingCoord0[0][2]; + dc.primitiveCoord = vs_interstageDrawingCoord0[0][3]; + dc.fvarCoord = vs_interstageDrawingCoord1[0][0]; + dc.shaderCoord = vs_interstageDrawingCoord1[0][1]; + dc.vertexCoord = vs_interstageDrawingCoord1[0][2]; + dc.topologyVisibilityCoord = vs_interstageDrawingCoord1[0][3]; + dc.varyingCoord = vs_interstageDrawingCoord2[0][0]; + dc.instanceIndex[0] = vs_interstageDrawingCoord2[0][1]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -3759,16 +3728,16 @@ void ProcessPrimvarsOut(int index) { ); hd_barycentricCoord = coords[index]; hd_drawingCoord dc = GetDrawingCoord(); - gs_dc_modelCoord = dc.modelCoord; - gs_dc_constantCoord = dc.constantCoord; - gs_dc_elementCoord = dc.elementCoord; - gs_dc_primitiveCoord = dc.primitiveCoord; - gs_dc_fvarCoord = dc.fvarCoord; - gs_dc_shaderCoord = dc.shaderCoord; - gs_dc_vertexCoord = dc.vertexCoord; - gs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - gs_dc_varyingCoord = dc.varyingCoord; - gs_dc_instanceIndexI0 = dc.instanceIndex[0]; + gs_interstageDrawingCoord0[0] = dc.modelCoord; + gs_interstageDrawingCoord0[1] = dc.constantCoord; + gs_interstageDrawingCoord0[2] = dc.elementCoord; + gs_interstageDrawingCoord0[3] = dc.primitiveCoord; + gs_interstageDrawingCoord1[0] = dc.fvarCoord; + gs_interstageDrawingCoord1[1] = dc.shaderCoord; + gs_interstageDrawingCoord1[2] = dc.vertexCoord; + gs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + gs_interstageDrawingCoord2[0] = dc.varyingCoord; + gs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = inPrimvars[index].points; outPrimvars.normals = inPrimvars[index].normals; outPrimvars.dispTextureCoord = HdGet_dispTextureCoord(index); @@ -4422,22 +4391,14 @@ in VertexData { } inData; layout (location = 0) out vec4 colorOut; in noperspective vec3 hd_barycentricCoord; +in flat ivec4 gs_interstageDrawingCoord0; +in flat ivec4 gs_interstageDrawingCoord1; +in flat ivec4 gs_interstageDrawingCoord2; in PrimvarData { vec3 points; vec3 normals; vec2 dispTextureCoord; } inPrimvars; -in flat int gs_dc_modelCoord; -in flat int gs_dc_constantCoord; -in flat int gs_dc_elementCoord; -in flat int gs_dc_primitiveCoord; -in flat int gs_dc_fvarCoord; -in flat int gs_dc_shaderCoord; -in flat int gs_dc_vertexCoord; -in flat int gs_dc_topologyVisibilityCoord; -in flat int gs_dc_varyingCoord; -in flat int gs_dc_instanceIndexI0; -in flat int gs_dc_instanceCoordsI0; layout(location = 4) uniform vec2 *dispTextureCoord; vec4 InterpolatePatchCoord(vec2 uv, ivec3 patchParam) { @@ -4496,16 +4457,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = gs_dc_modelCoord; - dc.constantCoord = gs_dc_constantCoord; - dc.elementCoord = gs_dc_elementCoord; - dc.primitiveCoord = gs_dc_primitiveCoord; - dc.fvarCoord = gs_dc_fvarCoord; - dc.shaderCoord = gs_dc_shaderCoord; - dc.vertexCoord = gs_dc_vertexCoord; - dc.topologyVisibilityCoord = gs_dc_topologyVisibilityCoord; - dc.varyingCoord = gs_dc_varyingCoord; - dc.instanceIndex[0] = gs_dc_instanceIndexI0; + dc.modelCoord = gs_interstageDrawingCoord0[0]; + dc.constantCoord = gs_interstageDrawingCoord0[1]; + dc.elementCoord = gs_interstageDrawingCoord0[2]; + dc.primitiveCoord = gs_interstageDrawingCoord0[3]; + dc.fvarCoord = gs_interstageDrawingCoord1[0]; + dc.shaderCoord = gs_interstageDrawingCoord1[1]; + dc.vertexCoord = gs_interstageDrawingCoord1[2]; + dc.topologyVisibilityCoord = gs_interstageDrawingCoord1[3]; + dc.varyingCoord = gs_interstageDrawingCoord2[0]; + dc.instanceIndex[0] = gs_interstageDrawingCoord2[1]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -4759,12 +4720,37 @@ vec4 ApplyColorOverridesPostLighting(vec4 color) -void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +void RenderColor(vec4 color) { colorOut = color; } + +void RenderId() +{ + // do nothing +} + + + +void RenderNeye(vec3 Neye) +{ + // do nothing +} + + + +void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +{ + // Write to any desired AOVs here. The render pass shader configuation + // decides if any of these are no-ops. + RenderColor(color); + RenderId(); + RenderNeye(Neye); +} + + #ifndef HD_HAS_integrateLights #define HD_HAS_integrateLights #endif diff --git a/pxr/imaging/hdSt/testenv/testHdStCodeGen_GL/baseline/codegen_mesh_indirect.out b/pxr/imaging/hdSt/testenv/testHdStCodeGen_GL/baseline/codegen_mesh_indirect.out index 59998b24c68..250423a51cd 100644 --- a/pxr/imaging/hdSt/testenv/testHdStCodeGen_GL/baseline/codegen_mesh_indirect.out +++ b/pxr/imaging/hdSt/testenv/testHdStCodeGen_GL/baseline/codegen_mesh_indirect.out @@ -162,22 +162,14 @@ FORWARD_DECL(int GetElementID()); FORWARD_DECL(int GetAggregatedElementID()); FORWARD_DECL(int GetPrimitiveEdgeId()); FORWARD_DECL(float GetSelectedEdgeOpacity()); +out flat ivec4 vs_interstageDrawingCoord0; +out flat ivec4 vs_interstageDrawingCoord1; +out flat ivec4 vs_interstageDrawingCoord2; layout (location = 2) in ivec4 drawingCoord0; layout (location = 3) in ivec4 drawingCoord1; layout (location = 4) in ivec2 drawingCoord2; layout (location = 0) in vec3 points; layout (location = 1) in vec3 normals; -out flat int vs_dc_modelCoord; -out flat int vs_dc_constantCoord; -out flat int vs_dc_elementCoord; -out flat int vs_dc_primitiveCoord; -out flat int vs_dc_fvarCoord; -out flat int vs_dc_shaderCoord; -out flat int vs_dc_vertexCoord; -out flat int vs_dc_topologyVisibilityCoord; -out flat int vs_dc_varyingCoord; -out flat int vs_dc_instanceIndexI0; -out flat int vs_dc_instanceCoordsI0; layout(location = 0) uniform ConstantData10 *constantPrimvars; layout(location = 1) uniform int *primitiveParam; layout(location = 2) uniform int *edgeIndices; @@ -256,16 +248,16 @@ float HdGetScalar_normals() { return HdGet_normals(0).x; } // //////// Codegen Proc VS //////// void ProcessPrimvarsIn() { hd_drawingCoord dc = GetDrawingCoord(); - vs_dc_modelCoord = dc.modelCoord; - vs_dc_constantCoord = dc.constantCoord; - vs_dc_elementCoord = dc.elementCoord; - vs_dc_primitiveCoord = dc.primitiveCoord; - vs_dc_fvarCoord = dc.fvarCoord; - vs_dc_shaderCoord = dc.shaderCoord; - vs_dc_vertexCoord = dc.vertexCoord; - vs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - vs_dc_varyingCoord = dc.varyingCoord; - vs_dc_instanceIndexI0 = dc.instanceIndex[0]; + vs_interstageDrawingCoord0[0] = dc.modelCoord; + vs_interstageDrawingCoord0[1] = dc.constantCoord; + vs_interstageDrawingCoord0[2] = dc.elementCoord; + vs_interstageDrawingCoord0[3] = dc.primitiveCoord; + vs_interstageDrawingCoord1[0] = dc.fvarCoord; + vs_interstageDrawingCoord1[1] = dc.shaderCoord; + vs_interstageDrawingCoord1[2] = dc.vertexCoord; + vs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + vs_interstageDrawingCoord2[0] = dc.varyingCoord; + vs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = points; outPrimvars.normals = normals; } @@ -851,6 +843,12 @@ out VertexData { } outData; out vec4 gsPatchCoord; out noperspective vec3 hd_barycentricCoord; +in flat ivec4 vs_interstageDrawingCoord0[HD_NUM_PRIMITIVE_VERTS]; +out flat ivec4 gs_interstageDrawingCoord0; +in flat ivec4 vs_interstageDrawingCoord1[HD_NUM_PRIMITIVE_VERTS]; +out flat ivec4 gs_interstageDrawingCoord1; +in flat ivec4 vs_interstageDrawingCoord2[HD_NUM_PRIMITIVE_VERTS]; +out flat ivec4 gs_interstageDrawingCoord2; in PrimvarData { vec3 points; vec3 normals; @@ -860,28 +858,6 @@ out PrimvarData { vec3 normals; vec2 dispTextureCoord; } outPrimvars; -in flat int vs_dc_modelCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_modelCoord; -in flat int vs_dc_constantCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_constantCoord; -in flat int vs_dc_elementCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_elementCoord; -in flat int vs_dc_primitiveCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_primitiveCoord; -in flat int vs_dc_fvarCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_fvarCoord; -in flat int vs_dc_shaderCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_shaderCoord; -in flat int vs_dc_vertexCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_vertexCoord; -in flat int vs_dc_topologyVisibilityCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_topologyVisibilityCoord; -in flat int vs_dc_varyingCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_varyingCoord; -in flat int vs_dc_instanceIndexI0[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_instanceIndexI0; -in flat int vs_dc_instanceCoordsI0[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_instanceCoordsI0; layout(location = 4) uniform vec2 *dispTextureCoord; // //////// Codegen Accessors //////// @@ -926,16 +902,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = vs_dc_modelCoord[0]; - dc.constantCoord = vs_dc_constantCoord[0]; - dc.elementCoord = vs_dc_elementCoord[0]; - dc.primitiveCoord = vs_dc_primitiveCoord[0]; - dc.fvarCoord = vs_dc_fvarCoord[0]; - dc.shaderCoord = vs_dc_shaderCoord[0]; - dc.vertexCoord = vs_dc_vertexCoord[0]; - dc.topologyVisibilityCoord = vs_dc_topologyVisibilityCoord[0]; - dc.varyingCoord = vs_dc_varyingCoord[0]; - dc.instanceIndex[0] = vs_dc_instanceIndexI0[0]; + dc.modelCoord = vs_interstageDrawingCoord0[0][0]; + dc.constantCoord = vs_interstageDrawingCoord0[0][1]; + dc.elementCoord = vs_interstageDrawingCoord0[0][2]; + dc.primitiveCoord = vs_interstageDrawingCoord0[0][3]; + dc.fvarCoord = vs_interstageDrawingCoord1[0][0]; + dc.shaderCoord = vs_interstageDrawingCoord1[0][1]; + dc.vertexCoord = vs_interstageDrawingCoord1[0][2]; + dc.topologyVisibilityCoord = vs_interstageDrawingCoord1[0][3]; + dc.varyingCoord = vs_interstageDrawingCoord2[0][0]; + dc.instanceIndex[0] = vs_interstageDrawingCoord2[0][1]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -1028,16 +1004,16 @@ void ProcessPrimvarsOut(int index) { ); hd_barycentricCoord = coords[index]; hd_drawingCoord dc = GetDrawingCoord(); - gs_dc_modelCoord = dc.modelCoord; - gs_dc_constantCoord = dc.constantCoord; - gs_dc_elementCoord = dc.elementCoord; - gs_dc_primitiveCoord = dc.primitiveCoord; - gs_dc_fvarCoord = dc.fvarCoord; - gs_dc_shaderCoord = dc.shaderCoord; - gs_dc_vertexCoord = dc.vertexCoord; - gs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - gs_dc_varyingCoord = dc.varyingCoord; - gs_dc_instanceIndexI0 = dc.instanceIndex[0]; + gs_interstageDrawingCoord0[0] = dc.modelCoord; + gs_interstageDrawingCoord0[1] = dc.constantCoord; + gs_interstageDrawingCoord0[2] = dc.elementCoord; + gs_interstageDrawingCoord0[3] = dc.primitiveCoord; + gs_interstageDrawingCoord1[0] = dc.fvarCoord; + gs_interstageDrawingCoord1[1] = dc.shaderCoord; + gs_interstageDrawingCoord1[2] = dc.vertexCoord; + gs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + gs_interstageDrawingCoord2[0] = dc.varyingCoord; + gs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = inPrimvars[index].points; outPrimvars.normals = inPrimvars[index].normals; outPrimvars.dispTextureCoord = HdGet_dispTextureCoord(index); @@ -1662,22 +1638,14 @@ in VertexData { } inData; layout (location = 0) out vec4 colorOut; in noperspective vec3 hd_barycentricCoord; +in flat ivec4 gs_interstageDrawingCoord0; +in flat ivec4 gs_interstageDrawingCoord1; +in flat ivec4 gs_interstageDrawingCoord2; in PrimvarData { vec3 points; vec3 normals; vec2 dispTextureCoord; } inPrimvars; -in flat int gs_dc_modelCoord; -in flat int gs_dc_constantCoord; -in flat int gs_dc_elementCoord; -in flat int gs_dc_primitiveCoord; -in flat int gs_dc_fvarCoord; -in flat int gs_dc_shaderCoord; -in flat int gs_dc_vertexCoord; -in flat int gs_dc_topologyVisibilityCoord; -in flat int gs_dc_varyingCoord; -in flat int gs_dc_instanceIndexI0; -in flat int gs_dc_instanceCoordsI0; layout(location = 4) uniform vec2 *dispTextureCoord; vec4 InterpolatePatchCoord(vec2 uv, ivec3 patchParam) { @@ -1736,16 +1704,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = gs_dc_modelCoord; - dc.constantCoord = gs_dc_constantCoord; - dc.elementCoord = gs_dc_elementCoord; - dc.primitiveCoord = gs_dc_primitiveCoord; - dc.fvarCoord = gs_dc_fvarCoord; - dc.shaderCoord = gs_dc_shaderCoord; - dc.vertexCoord = gs_dc_vertexCoord; - dc.topologyVisibilityCoord = gs_dc_topologyVisibilityCoord; - dc.varyingCoord = gs_dc_varyingCoord; - dc.instanceIndex[0] = gs_dc_instanceIndexI0; + dc.modelCoord = gs_interstageDrawingCoord0[0]; + dc.constantCoord = gs_interstageDrawingCoord0[1]; + dc.elementCoord = gs_interstageDrawingCoord0[2]; + dc.primitiveCoord = gs_interstageDrawingCoord0[3]; + dc.fvarCoord = gs_interstageDrawingCoord1[0]; + dc.shaderCoord = gs_interstageDrawingCoord1[1]; + dc.vertexCoord = gs_interstageDrawingCoord1[2]; + dc.topologyVisibilityCoord = gs_interstageDrawingCoord1[3]; + dc.varyingCoord = gs_interstageDrawingCoord2[0]; + dc.instanceIndex[0] = gs_interstageDrawingCoord2[1]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -1999,12 +1967,37 @@ vec4 ApplyColorOverridesPostLighting(vec4 color) -void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +void RenderColor(vec4 color) { colorOut = color; } + +void RenderId() +{ + // do nothing +} + + + +void RenderNeye(vec3 Neye) +{ + // do nothing +} + + + +void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +{ + // Write to any desired AOVs here. The render pass shader configuation + // decides if any of these are no-ops. + RenderColor(color); + RenderId(); + RenderNeye(Neye); +} + + #ifndef HD_HAS_integrateLights #define HD_HAS_integrateLights #endif @@ -2838,22 +2831,14 @@ FORWARD_DECL(int GetElementID()); FORWARD_DECL(int GetAggregatedElementID()); FORWARD_DECL(int GetPrimitiveEdgeId()); FORWARD_DECL(float GetSelectedEdgeOpacity()); +out flat ivec4 vs_interstageDrawingCoord0; +out flat ivec4 vs_interstageDrawingCoord1; +out flat ivec4 vs_interstageDrawingCoord2; layout (location = 2) in ivec4 drawingCoord0; layout (location = 3) in ivec4 drawingCoord1; layout (location = 4) in ivec2 drawingCoord2; layout (location = 0) in vec3 points; layout (location = 1) in vec3 normals; -out flat int vs_dc_modelCoord; -out flat int vs_dc_constantCoord; -out flat int vs_dc_elementCoord; -out flat int vs_dc_primitiveCoord; -out flat int vs_dc_fvarCoord; -out flat int vs_dc_shaderCoord; -out flat int vs_dc_vertexCoord; -out flat int vs_dc_topologyVisibilityCoord; -out flat int vs_dc_varyingCoord; -out flat int vs_dc_instanceIndexI0; -out flat int vs_dc_instanceCoordsI0; layout(location = 0) uniform ConstantData10 *constantPrimvars; layout(location = 1) uniform int *primitiveParam; layout(location = 2) uniform ivec2 *edgeIndices; @@ -2932,16 +2917,16 @@ float HdGetScalar_normals() { return HdGet_normals(0).x; } // //////// Codegen Proc VS //////// void ProcessPrimvarsIn() { hd_drawingCoord dc = GetDrawingCoord(); - vs_dc_modelCoord = dc.modelCoord; - vs_dc_constantCoord = dc.constantCoord; - vs_dc_elementCoord = dc.elementCoord; - vs_dc_primitiveCoord = dc.primitiveCoord; - vs_dc_fvarCoord = dc.fvarCoord; - vs_dc_shaderCoord = dc.shaderCoord; - vs_dc_vertexCoord = dc.vertexCoord; - vs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - vs_dc_varyingCoord = dc.varyingCoord; - vs_dc_instanceIndexI0 = dc.instanceIndex[0]; + vs_interstageDrawingCoord0[0] = dc.modelCoord; + vs_interstageDrawingCoord0[1] = dc.constantCoord; + vs_interstageDrawingCoord0[2] = dc.elementCoord; + vs_interstageDrawingCoord0[3] = dc.primitiveCoord; + vs_interstageDrawingCoord1[0] = dc.fvarCoord; + vs_interstageDrawingCoord1[1] = dc.shaderCoord; + vs_interstageDrawingCoord1[2] = dc.vertexCoord; + vs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + vs_interstageDrawingCoord2[0] = dc.varyingCoord; + vs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = points; outPrimvars.normals = normals; } @@ -3527,6 +3512,12 @@ out VertexData { } outData; out vec4 gsPatchCoord; out noperspective vec3 hd_barycentricCoord; +in flat ivec4 vs_interstageDrawingCoord0[HD_NUM_PRIMITIVE_VERTS]; +out flat ivec4 gs_interstageDrawingCoord0; +in flat ivec4 vs_interstageDrawingCoord1[HD_NUM_PRIMITIVE_VERTS]; +out flat ivec4 gs_interstageDrawingCoord1; +in flat ivec4 vs_interstageDrawingCoord2[HD_NUM_PRIMITIVE_VERTS]; +out flat ivec4 gs_interstageDrawingCoord2; in PrimvarData { vec3 points; vec3 normals; @@ -3536,28 +3527,6 @@ out PrimvarData { vec3 normals; vec2 dispTextureCoord; } outPrimvars; -in flat int vs_dc_modelCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_modelCoord; -in flat int vs_dc_constantCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_constantCoord; -in flat int vs_dc_elementCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_elementCoord; -in flat int vs_dc_primitiveCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_primitiveCoord; -in flat int vs_dc_fvarCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_fvarCoord; -in flat int vs_dc_shaderCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_shaderCoord; -in flat int vs_dc_vertexCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_vertexCoord; -in flat int vs_dc_topologyVisibilityCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_topologyVisibilityCoord; -in flat int vs_dc_varyingCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_varyingCoord; -in flat int vs_dc_instanceIndexI0[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_instanceIndexI0; -in flat int vs_dc_instanceCoordsI0[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_instanceCoordsI0; layout(location = 4) uniform vec2 *dispTextureCoord; // //////// Codegen Accessors //////// @@ -3602,16 +3571,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = vs_dc_modelCoord[0]; - dc.constantCoord = vs_dc_constantCoord[0]; - dc.elementCoord = vs_dc_elementCoord[0]; - dc.primitiveCoord = vs_dc_primitiveCoord[0]; - dc.fvarCoord = vs_dc_fvarCoord[0]; - dc.shaderCoord = vs_dc_shaderCoord[0]; - dc.vertexCoord = vs_dc_vertexCoord[0]; - dc.topologyVisibilityCoord = vs_dc_topologyVisibilityCoord[0]; - dc.varyingCoord = vs_dc_varyingCoord[0]; - dc.instanceIndex[0] = vs_dc_instanceIndexI0[0]; + dc.modelCoord = vs_interstageDrawingCoord0[0][0]; + dc.constantCoord = vs_interstageDrawingCoord0[0][1]; + dc.elementCoord = vs_interstageDrawingCoord0[0][2]; + dc.primitiveCoord = vs_interstageDrawingCoord0[0][3]; + dc.fvarCoord = vs_interstageDrawingCoord1[0][0]; + dc.shaderCoord = vs_interstageDrawingCoord1[0][1]; + dc.vertexCoord = vs_interstageDrawingCoord1[0][2]; + dc.topologyVisibilityCoord = vs_interstageDrawingCoord1[0][3]; + dc.varyingCoord = vs_interstageDrawingCoord2[0][0]; + dc.instanceIndex[0] = vs_interstageDrawingCoord2[0][1]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -3704,16 +3673,16 @@ void ProcessPrimvarsOut(int index) { ); hd_barycentricCoord = coords[index]; hd_drawingCoord dc = GetDrawingCoord(); - gs_dc_modelCoord = dc.modelCoord; - gs_dc_constantCoord = dc.constantCoord; - gs_dc_elementCoord = dc.elementCoord; - gs_dc_primitiveCoord = dc.primitiveCoord; - gs_dc_fvarCoord = dc.fvarCoord; - gs_dc_shaderCoord = dc.shaderCoord; - gs_dc_vertexCoord = dc.vertexCoord; - gs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - gs_dc_varyingCoord = dc.varyingCoord; - gs_dc_instanceIndexI0 = dc.instanceIndex[0]; + gs_interstageDrawingCoord0[0] = dc.modelCoord; + gs_interstageDrawingCoord0[1] = dc.constantCoord; + gs_interstageDrawingCoord0[2] = dc.elementCoord; + gs_interstageDrawingCoord0[3] = dc.primitiveCoord; + gs_interstageDrawingCoord1[0] = dc.fvarCoord; + gs_interstageDrawingCoord1[1] = dc.shaderCoord; + gs_interstageDrawingCoord1[2] = dc.vertexCoord; + gs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + gs_interstageDrawingCoord2[0] = dc.varyingCoord; + gs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = inPrimvars[index].points; outPrimvars.normals = inPrimvars[index].normals; outPrimvars.dispTextureCoord = HdGet_dispTextureCoord(index); @@ -4367,22 +4336,14 @@ in VertexData { } inData; layout (location = 0) out vec4 colorOut; in noperspective vec3 hd_barycentricCoord; +in flat ivec4 gs_interstageDrawingCoord0; +in flat ivec4 gs_interstageDrawingCoord1; +in flat ivec4 gs_interstageDrawingCoord2; in PrimvarData { vec3 points; vec3 normals; vec2 dispTextureCoord; } inPrimvars; -in flat int gs_dc_modelCoord; -in flat int gs_dc_constantCoord; -in flat int gs_dc_elementCoord; -in flat int gs_dc_primitiveCoord; -in flat int gs_dc_fvarCoord; -in flat int gs_dc_shaderCoord; -in flat int gs_dc_vertexCoord; -in flat int gs_dc_topologyVisibilityCoord; -in flat int gs_dc_varyingCoord; -in flat int gs_dc_instanceIndexI0; -in flat int gs_dc_instanceCoordsI0; layout(location = 4) uniform vec2 *dispTextureCoord; vec4 InterpolatePatchCoord(vec2 uv, ivec3 patchParam) { @@ -4441,16 +4402,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = gs_dc_modelCoord; - dc.constantCoord = gs_dc_constantCoord; - dc.elementCoord = gs_dc_elementCoord; - dc.primitiveCoord = gs_dc_primitiveCoord; - dc.fvarCoord = gs_dc_fvarCoord; - dc.shaderCoord = gs_dc_shaderCoord; - dc.vertexCoord = gs_dc_vertexCoord; - dc.topologyVisibilityCoord = gs_dc_topologyVisibilityCoord; - dc.varyingCoord = gs_dc_varyingCoord; - dc.instanceIndex[0] = gs_dc_instanceIndexI0; + dc.modelCoord = gs_interstageDrawingCoord0[0]; + dc.constantCoord = gs_interstageDrawingCoord0[1]; + dc.elementCoord = gs_interstageDrawingCoord0[2]; + dc.primitiveCoord = gs_interstageDrawingCoord0[3]; + dc.fvarCoord = gs_interstageDrawingCoord1[0]; + dc.shaderCoord = gs_interstageDrawingCoord1[1]; + dc.vertexCoord = gs_interstageDrawingCoord1[2]; + dc.topologyVisibilityCoord = gs_interstageDrawingCoord1[3]; + dc.varyingCoord = gs_interstageDrawingCoord2[0]; + dc.instanceIndex[0] = gs_interstageDrawingCoord2[1]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -4704,12 +4665,37 @@ vec4 ApplyColorOverridesPostLighting(vec4 color) -void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +void RenderColor(vec4 color) { colorOut = color; } + +void RenderId() +{ + // do nothing +} + + + +void RenderNeye(vec3 Neye) +{ + // do nothing +} + + + +void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +{ + // Write to any desired AOVs here. The render pass shader configuation + // decides if any of these are no-ops. + RenderColor(color); + RenderId(); + RenderNeye(Neye); +} + + #ifndef HD_HAS_integrateLights #define HD_HAS_integrateLights #endif diff --git a/pxr/imaging/hdSt/testenv/testHdStCodeGen_GL/baseline/codegen_mesh_bindless_indirect_doubleSided.out b/pxr/imaging/hdSt/testenv/testHdStCodeGen_GL/baseline/codegen_mesh_indirect_doubleSided.out similarity index 95% rename from pxr/imaging/hdSt/testenv/testHdStCodeGen_GL/baseline/codegen_mesh_bindless_indirect_doubleSided.out rename to pxr/imaging/hdSt/testenv/testHdStCodeGen_GL/baseline/codegen_mesh_indirect_doubleSided.out index d0d438b400f..531ef99eea6 100644 --- a/pxr/imaging/hdSt/testenv/testHdStCodeGen_GL/baseline/codegen_mesh_bindless_indirect_doubleSided.out +++ b/pxr/imaging/hdSt/testenv/testHdStCodeGen_GL/baseline/codegen_mesh_indirect_doubleSided.out @@ -162,22 +162,14 @@ FORWARD_DECL(int GetElementID()); FORWARD_DECL(int GetAggregatedElementID()); FORWARD_DECL(int GetPrimitiveEdgeId()); FORWARD_DECL(float GetSelectedEdgeOpacity()); +out flat ivec4 vs_interstageDrawingCoord0; +out flat ivec4 vs_interstageDrawingCoord1; +out flat ivec4 vs_interstageDrawingCoord2; layout (location = 2) in ivec4 drawingCoord0; layout (location = 3) in ivec4 drawingCoord1; layout (location = 4) in ivec2 drawingCoord2; layout (location = 0) in vec3 points; layout (location = 1) in vec3 normals; -out flat int vs_dc_modelCoord; -out flat int vs_dc_constantCoord; -out flat int vs_dc_elementCoord; -out flat int vs_dc_primitiveCoord; -out flat int vs_dc_fvarCoord; -out flat int vs_dc_shaderCoord; -out flat int vs_dc_vertexCoord; -out flat int vs_dc_topologyVisibilityCoord; -out flat int vs_dc_varyingCoord; -out flat int vs_dc_instanceIndexI0; -out flat int vs_dc_instanceCoordsI0; layout(location = 0) uniform ConstantData10 *constantPrimvars; layout(location = 1) uniform int *primitiveParam; layout(location = 2) uniform int *edgeIndices; @@ -256,16 +248,16 @@ float HdGetScalar_normals() { return HdGet_normals(0).x; } // //////// Codegen Proc VS //////// void ProcessPrimvarsIn() { hd_drawingCoord dc = GetDrawingCoord(); - vs_dc_modelCoord = dc.modelCoord; - vs_dc_constantCoord = dc.constantCoord; - vs_dc_elementCoord = dc.elementCoord; - vs_dc_primitiveCoord = dc.primitiveCoord; - vs_dc_fvarCoord = dc.fvarCoord; - vs_dc_shaderCoord = dc.shaderCoord; - vs_dc_vertexCoord = dc.vertexCoord; - vs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - vs_dc_varyingCoord = dc.varyingCoord; - vs_dc_instanceIndexI0 = dc.instanceIndex[0]; + vs_interstageDrawingCoord0[0] = dc.modelCoord; + vs_interstageDrawingCoord0[1] = dc.constantCoord; + vs_interstageDrawingCoord0[2] = dc.elementCoord; + vs_interstageDrawingCoord0[3] = dc.primitiveCoord; + vs_interstageDrawingCoord1[0] = dc.fvarCoord; + vs_interstageDrawingCoord1[1] = dc.shaderCoord; + vs_interstageDrawingCoord1[2] = dc.vertexCoord; + vs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + vs_interstageDrawingCoord2[0] = dc.varyingCoord; + vs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = points; outPrimvars.normals = normals; } @@ -851,6 +843,12 @@ out VertexData { } outData; out vec4 gsPatchCoord; out noperspective vec3 hd_barycentricCoord; +in flat ivec4 vs_interstageDrawingCoord0[HD_NUM_PRIMITIVE_VERTS]; +out flat ivec4 gs_interstageDrawingCoord0; +in flat ivec4 vs_interstageDrawingCoord1[HD_NUM_PRIMITIVE_VERTS]; +out flat ivec4 gs_interstageDrawingCoord1; +in flat ivec4 vs_interstageDrawingCoord2[HD_NUM_PRIMITIVE_VERTS]; +out flat ivec4 gs_interstageDrawingCoord2; in PrimvarData { vec3 points; vec3 normals; @@ -860,28 +858,6 @@ out PrimvarData { vec3 normals; vec2 dispTextureCoord; } outPrimvars; -in flat int vs_dc_modelCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_modelCoord; -in flat int vs_dc_constantCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_constantCoord; -in flat int vs_dc_elementCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_elementCoord; -in flat int vs_dc_primitiveCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_primitiveCoord; -in flat int vs_dc_fvarCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_fvarCoord; -in flat int vs_dc_shaderCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_shaderCoord; -in flat int vs_dc_vertexCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_vertexCoord; -in flat int vs_dc_topologyVisibilityCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_topologyVisibilityCoord; -in flat int vs_dc_varyingCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_varyingCoord; -in flat int vs_dc_instanceIndexI0[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_instanceIndexI0; -in flat int vs_dc_instanceCoordsI0[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_instanceCoordsI0; layout(location = 4) uniform vec2 *dispTextureCoord; // //////// Codegen Accessors //////// @@ -926,16 +902,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = vs_dc_modelCoord[0]; - dc.constantCoord = vs_dc_constantCoord[0]; - dc.elementCoord = vs_dc_elementCoord[0]; - dc.primitiveCoord = vs_dc_primitiveCoord[0]; - dc.fvarCoord = vs_dc_fvarCoord[0]; - dc.shaderCoord = vs_dc_shaderCoord[0]; - dc.vertexCoord = vs_dc_vertexCoord[0]; - dc.topologyVisibilityCoord = vs_dc_topologyVisibilityCoord[0]; - dc.varyingCoord = vs_dc_varyingCoord[0]; - dc.instanceIndex[0] = vs_dc_instanceIndexI0[0]; + dc.modelCoord = vs_interstageDrawingCoord0[0][0]; + dc.constantCoord = vs_interstageDrawingCoord0[0][1]; + dc.elementCoord = vs_interstageDrawingCoord0[0][2]; + dc.primitiveCoord = vs_interstageDrawingCoord0[0][3]; + dc.fvarCoord = vs_interstageDrawingCoord1[0][0]; + dc.shaderCoord = vs_interstageDrawingCoord1[0][1]; + dc.vertexCoord = vs_interstageDrawingCoord1[0][2]; + dc.topologyVisibilityCoord = vs_interstageDrawingCoord1[0][3]; + dc.varyingCoord = vs_interstageDrawingCoord2[0][0]; + dc.instanceIndex[0] = vs_interstageDrawingCoord2[0][1]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -1028,16 +1004,16 @@ void ProcessPrimvarsOut(int index) { ); hd_barycentricCoord = coords[index]; hd_drawingCoord dc = GetDrawingCoord(); - gs_dc_modelCoord = dc.modelCoord; - gs_dc_constantCoord = dc.constantCoord; - gs_dc_elementCoord = dc.elementCoord; - gs_dc_primitiveCoord = dc.primitiveCoord; - gs_dc_fvarCoord = dc.fvarCoord; - gs_dc_shaderCoord = dc.shaderCoord; - gs_dc_vertexCoord = dc.vertexCoord; - gs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - gs_dc_varyingCoord = dc.varyingCoord; - gs_dc_instanceIndexI0 = dc.instanceIndex[0]; + gs_interstageDrawingCoord0[0] = dc.modelCoord; + gs_interstageDrawingCoord0[1] = dc.constantCoord; + gs_interstageDrawingCoord0[2] = dc.elementCoord; + gs_interstageDrawingCoord0[3] = dc.primitiveCoord; + gs_interstageDrawingCoord1[0] = dc.fvarCoord; + gs_interstageDrawingCoord1[1] = dc.shaderCoord; + gs_interstageDrawingCoord1[2] = dc.vertexCoord; + gs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + gs_interstageDrawingCoord2[0] = dc.varyingCoord; + gs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = inPrimvars[index].points; outPrimvars.normals = inPrimvars[index].normals; outPrimvars.dispTextureCoord = HdGet_dispTextureCoord(index); @@ -1662,22 +1638,14 @@ in VertexData { } inData; layout (location = 0) out vec4 colorOut; in noperspective vec3 hd_barycentricCoord; +in flat ivec4 gs_interstageDrawingCoord0; +in flat ivec4 gs_interstageDrawingCoord1; +in flat ivec4 gs_interstageDrawingCoord2; in PrimvarData { vec3 points; vec3 normals; vec2 dispTextureCoord; } inPrimvars; -in flat int gs_dc_modelCoord; -in flat int gs_dc_constantCoord; -in flat int gs_dc_elementCoord; -in flat int gs_dc_primitiveCoord; -in flat int gs_dc_fvarCoord; -in flat int gs_dc_shaderCoord; -in flat int gs_dc_vertexCoord; -in flat int gs_dc_topologyVisibilityCoord; -in flat int gs_dc_varyingCoord; -in flat int gs_dc_instanceIndexI0; -in flat int gs_dc_instanceCoordsI0; layout(location = 4) uniform vec2 *dispTextureCoord; vec4 InterpolatePatchCoord(vec2 uv, ivec3 patchParam) { @@ -1736,16 +1704,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = gs_dc_modelCoord; - dc.constantCoord = gs_dc_constantCoord; - dc.elementCoord = gs_dc_elementCoord; - dc.primitiveCoord = gs_dc_primitiveCoord; - dc.fvarCoord = gs_dc_fvarCoord; - dc.shaderCoord = gs_dc_shaderCoord; - dc.vertexCoord = gs_dc_vertexCoord; - dc.topologyVisibilityCoord = gs_dc_topologyVisibilityCoord; - dc.varyingCoord = gs_dc_varyingCoord; - dc.instanceIndex[0] = gs_dc_instanceIndexI0; + dc.modelCoord = gs_interstageDrawingCoord0[0]; + dc.constantCoord = gs_interstageDrawingCoord0[1]; + dc.elementCoord = gs_interstageDrawingCoord0[2]; + dc.primitiveCoord = gs_interstageDrawingCoord0[3]; + dc.fvarCoord = gs_interstageDrawingCoord1[0]; + dc.shaderCoord = gs_interstageDrawingCoord1[1]; + dc.vertexCoord = gs_interstageDrawingCoord1[2]; + dc.topologyVisibilityCoord = gs_interstageDrawingCoord1[3]; + dc.varyingCoord = gs_interstageDrawingCoord2[0]; + dc.instanceIndex[0] = gs_interstageDrawingCoord2[1]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -1999,12 +1967,37 @@ vec4 ApplyColorOverridesPostLighting(vec4 color) -void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +void RenderColor(vec4 color) { colorOut = color; } + +void RenderId() +{ + // do nothing +} + + + +void RenderNeye(vec3 Neye) +{ + // do nothing +} + + + +void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +{ + // Write to any desired AOVs here. The render pass shader configuation + // decides if any of these are no-ops. + RenderColor(color); + RenderId(); + RenderNeye(Neye); +} + + #ifndef HD_HAS_integrateLights #define HD_HAS_integrateLights #endif @@ -2837,22 +2830,14 @@ FORWARD_DECL(int GetElementID()); FORWARD_DECL(int GetAggregatedElementID()); FORWARD_DECL(int GetPrimitiveEdgeId()); FORWARD_DECL(float GetSelectedEdgeOpacity()); +out flat ivec4 vs_interstageDrawingCoord0; +out flat ivec4 vs_interstageDrawingCoord1; +out flat ivec4 vs_interstageDrawingCoord2; layout (location = 2) in ivec4 drawingCoord0; layout (location = 3) in ivec4 drawingCoord1; layout (location = 4) in ivec2 drawingCoord2; layout (location = 0) in vec3 points; layout (location = 1) in vec3 normals; -out flat int vs_dc_modelCoord; -out flat int vs_dc_constantCoord; -out flat int vs_dc_elementCoord; -out flat int vs_dc_primitiveCoord; -out flat int vs_dc_fvarCoord; -out flat int vs_dc_shaderCoord; -out flat int vs_dc_vertexCoord; -out flat int vs_dc_topologyVisibilityCoord; -out flat int vs_dc_varyingCoord; -out flat int vs_dc_instanceIndexI0; -out flat int vs_dc_instanceCoordsI0; layout(location = 0) uniform ConstantData10 *constantPrimvars; layout(location = 1) uniform int *primitiveParam; layout(location = 2) uniform ivec2 *edgeIndices; @@ -2931,16 +2916,16 @@ float HdGetScalar_normals() { return HdGet_normals(0).x; } // //////// Codegen Proc VS //////// void ProcessPrimvarsIn() { hd_drawingCoord dc = GetDrawingCoord(); - vs_dc_modelCoord = dc.modelCoord; - vs_dc_constantCoord = dc.constantCoord; - vs_dc_elementCoord = dc.elementCoord; - vs_dc_primitiveCoord = dc.primitiveCoord; - vs_dc_fvarCoord = dc.fvarCoord; - vs_dc_shaderCoord = dc.shaderCoord; - vs_dc_vertexCoord = dc.vertexCoord; - vs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - vs_dc_varyingCoord = dc.varyingCoord; - vs_dc_instanceIndexI0 = dc.instanceIndex[0]; + vs_interstageDrawingCoord0[0] = dc.modelCoord; + vs_interstageDrawingCoord0[1] = dc.constantCoord; + vs_interstageDrawingCoord0[2] = dc.elementCoord; + vs_interstageDrawingCoord0[3] = dc.primitiveCoord; + vs_interstageDrawingCoord1[0] = dc.fvarCoord; + vs_interstageDrawingCoord1[1] = dc.shaderCoord; + vs_interstageDrawingCoord1[2] = dc.vertexCoord; + vs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + vs_interstageDrawingCoord2[0] = dc.varyingCoord; + vs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = points; outPrimvars.normals = normals; } @@ -3526,6 +3511,12 @@ out VertexData { } outData; out vec4 gsPatchCoord; out noperspective vec3 hd_barycentricCoord; +in flat ivec4 vs_interstageDrawingCoord0[HD_NUM_PRIMITIVE_VERTS]; +out flat ivec4 gs_interstageDrawingCoord0; +in flat ivec4 vs_interstageDrawingCoord1[HD_NUM_PRIMITIVE_VERTS]; +out flat ivec4 gs_interstageDrawingCoord1; +in flat ivec4 vs_interstageDrawingCoord2[HD_NUM_PRIMITIVE_VERTS]; +out flat ivec4 gs_interstageDrawingCoord2; in PrimvarData { vec3 points; vec3 normals; @@ -3535,28 +3526,6 @@ out PrimvarData { vec3 normals; vec2 dispTextureCoord; } outPrimvars; -in flat int vs_dc_modelCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_modelCoord; -in flat int vs_dc_constantCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_constantCoord; -in flat int vs_dc_elementCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_elementCoord; -in flat int vs_dc_primitiveCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_primitiveCoord; -in flat int vs_dc_fvarCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_fvarCoord; -in flat int vs_dc_shaderCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_shaderCoord; -in flat int vs_dc_vertexCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_vertexCoord; -in flat int vs_dc_topologyVisibilityCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_topologyVisibilityCoord; -in flat int vs_dc_varyingCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_varyingCoord; -in flat int vs_dc_instanceIndexI0[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_instanceIndexI0; -in flat int vs_dc_instanceCoordsI0[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_instanceCoordsI0; layout(location = 4) uniform vec2 *dispTextureCoord; // //////// Codegen Accessors //////// @@ -3601,16 +3570,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = vs_dc_modelCoord[0]; - dc.constantCoord = vs_dc_constantCoord[0]; - dc.elementCoord = vs_dc_elementCoord[0]; - dc.primitiveCoord = vs_dc_primitiveCoord[0]; - dc.fvarCoord = vs_dc_fvarCoord[0]; - dc.shaderCoord = vs_dc_shaderCoord[0]; - dc.vertexCoord = vs_dc_vertexCoord[0]; - dc.topologyVisibilityCoord = vs_dc_topologyVisibilityCoord[0]; - dc.varyingCoord = vs_dc_varyingCoord[0]; - dc.instanceIndex[0] = vs_dc_instanceIndexI0[0]; + dc.modelCoord = vs_interstageDrawingCoord0[0][0]; + dc.constantCoord = vs_interstageDrawingCoord0[0][1]; + dc.elementCoord = vs_interstageDrawingCoord0[0][2]; + dc.primitiveCoord = vs_interstageDrawingCoord0[0][3]; + dc.fvarCoord = vs_interstageDrawingCoord1[0][0]; + dc.shaderCoord = vs_interstageDrawingCoord1[0][1]; + dc.vertexCoord = vs_interstageDrawingCoord1[0][2]; + dc.topologyVisibilityCoord = vs_interstageDrawingCoord1[0][3]; + dc.varyingCoord = vs_interstageDrawingCoord2[0][0]; + dc.instanceIndex[0] = vs_interstageDrawingCoord2[0][1]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -3703,16 +3672,16 @@ void ProcessPrimvarsOut(int index) { ); hd_barycentricCoord = coords[index]; hd_drawingCoord dc = GetDrawingCoord(); - gs_dc_modelCoord = dc.modelCoord; - gs_dc_constantCoord = dc.constantCoord; - gs_dc_elementCoord = dc.elementCoord; - gs_dc_primitiveCoord = dc.primitiveCoord; - gs_dc_fvarCoord = dc.fvarCoord; - gs_dc_shaderCoord = dc.shaderCoord; - gs_dc_vertexCoord = dc.vertexCoord; - gs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - gs_dc_varyingCoord = dc.varyingCoord; - gs_dc_instanceIndexI0 = dc.instanceIndex[0]; + gs_interstageDrawingCoord0[0] = dc.modelCoord; + gs_interstageDrawingCoord0[1] = dc.constantCoord; + gs_interstageDrawingCoord0[2] = dc.elementCoord; + gs_interstageDrawingCoord0[3] = dc.primitiveCoord; + gs_interstageDrawingCoord1[0] = dc.fvarCoord; + gs_interstageDrawingCoord1[1] = dc.shaderCoord; + gs_interstageDrawingCoord1[2] = dc.vertexCoord; + gs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + gs_interstageDrawingCoord2[0] = dc.varyingCoord; + gs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = inPrimvars[index].points; outPrimvars.normals = inPrimvars[index].normals; outPrimvars.dispTextureCoord = HdGet_dispTextureCoord(index); @@ -4366,22 +4335,14 @@ in VertexData { } inData; layout (location = 0) out vec4 colorOut; in noperspective vec3 hd_barycentricCoord; +in flat ivec4 gs_interstageDrawingCoord0; +in flat ivec4 gs_interstageDrawingCoord1; +in flat ivec4 gs_interstageDrawingCoord2; in PrimvarData { vec3 points; vec3 normals; vec2 dispTextureCoord; } inPrimvars; -in flat int gs_dc_modelCoord; -in flat int gs_dc_constantCoord; -in flat int gs_dc_elementCoord; -in flat int gs_dc_primitiveCoord; -in flat int gs_dc_fvarCoord; -in flat int gs_dc_shaderCoord; -in flat int gs_dc_vertexCoord; -in flat int gs_dc_topologyVisibilityCoord; -in flat int gs_dc_varyingCoord; -in flat int gs_dc_instanceIndexI0; -in flat int gs_dc_instanceCoordsI0; layout(location = 4) uniform vec2 *dispTextureCoord; vec4 InterpolatePatchCoord(vec2 uv, ivec3 patchParam) { @@ -4440,16 +4401,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = gs_dc_modelCoord; - dc.constantCoord = gs_dc_constantCoord; - dc.elementCoord = gs_dc_elementCoord; - dc.primitiveCoord = gs_dc_primitiveCoord; - dc.fvarCoord = gs_dc_fvarCoord; - dc.shaderCoord = gs_dc_shaderCoord; - dc.vertexCoord = gs_dc_vertexCoord; - dc.topologyVisibilityCoord = gs_dc_topologyVisibilityCoord; - dc.varyingCoord = gs_dc_varyingCoord; - dc.instanceIndex[0] = gs_dc_instanceIndexI0; + dc.modelCoord = gs_interstageDrawingCoord0[0]; + dc.constantCoord = gs_interstageDrawingCoord0[1]; + dc.elementCoord = gs_interstageDrawingCoord0[2]; + dc.primitiveCoord = gs_interstageDrawingCoord0[3]; + dc.fvarCoord = gs_interstageDrawingCoord1[0]; + dc.shaderCoord = gs_interstageDrawingCoord1[1]; + dc.vertexCoord = gs_interstageDrawingCoord1[2]; + dc.topologyVisibilityCoord = gs_interstageDrawingCoord1[3]; + dc.varyingCoord = gs_interstageDrawingCoord2[0]; + dc.instanceIndex[0] = gs_interstageDrawingCoord2[1]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -4703,12 +4664,37 @@ vec4 ApplyColorOverridesPostLighting(vec4 color) -void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +void RenderColor(vec4 color) { colorOut = color; } + +void RenderId() +{ + // do nothing +} + + + +void RenderNeye(vec3 Neye) +{ + // do nothing +} + + + +void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +{ + // Write to any desired AOVs here. The render pass shader configuation + // decides if any of these are no-ops. + RenderColor(color); + RenderId(); + RenderNeye(Neye); +} + + #ifndef HD_HAS_integrateLights #define HD_HAS_integrateLights #endif diff --git a/pxr/imaging/hdSt/testenv/testHdStCodeGen_GL/baseline/codegen_mesh_bindless_indirect.out b/pxr/imaging/hdSt/testenv/testHdStCodeGen_GL/baseline/codegen_mesh_indirect_faceVarying.out similarity index 95% rename from pxr/imaging/hdSt/testenv/testHdStCodeGen_GL/baseline/codegen_mesh_bindless_indirect.out rename to pxr/imaging/hdSt/testenv/testHdStCodeGen_GL/baseline/codegen_mesh_indirect_faceVarying.out index 59998b24c68..250423a51cd 100644 --- a/pxr/imaging/hdSt/testenv/testHdStCodeGen_GL/baseline/codegen_mesh_bindless_indirect.out +++ b/pxr/imaging/hdSt/testenv/testHdStCodeGen_GL/baseline/codegen_mesh_indirect_faceVarying.out @@ -162,22 +162,14 @@ FORWARD_DECL(int GetElementID()); FORWARD_DECL(int GetAggregatedElementID()); FORWARD_DECL(int GetPrimitiveEdgeId()); FORWARD_DECL(float GetSelectedEdgeOpacity()); +out flat ivec4 vs_interstageDrawingCoord0; +out flat ivec4 vs_interstageDrawingCoord1; +out flat ivec4 vs_interstageDrawingCoord2; layout (location = 2) in ivec4 drawingCoord0; layout (location = 3) in ivec4 drawingCoord1; layout (location = 4) in ivec2 drawingCoord2; layout (location = 0) in vec3 points; layout (location = 1) in vec3 normals; -out flat int vs_dc_modelCoord; -out flat int vs_dc_constantCoord; -out flat int vs_dc_elementCoord; -out flat int vs_dc_primitiveCoord; -out flat int vs_dc_fvarCoord; -out flat int vs_dc_shaderCoord; -out flat int vs_dc_vertexCoord; -out flat int vs_dc_topologyVisibilityCoord; -out flat int vs_dc_varyingCoord; -out flat int vs_dc_instanceIndexI0; -out flat int vs_dc_instanceCoordsI0; layout(location = 0) uniform ConstantData10 *constantPrimvars; layout(location = 1) uniform int *primitiveParam; layout(location = 2) uniform int *edgeIndices; @@ -256,16 +248,16 @@ float HdGetScalar_normals() { return HdGet_normals(0).x; } // //////// Codegen Proc VS //////// void ProcessPrimvarsIn() { hd_drawingCoord dc = GetDrawingCoord(); - vs_dc_modelCoord = dc.modelCoord; - vs_dc_constantCoord = dc.constantCoord; - vs_dc_elementCoord = dc.elementCoord; - vs_dc_primitiveCoord = dc.primitiveCoord; - vs_dc_fvarCoord = dc.fvarCoord; - vs_dc_shaderCoord = dc.shaderCoord; - vs_dc_vertexCoord = dc.vertexCoord; - vs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - vs_dc_varyingCoord = dc.varyingCoord; - vs_dc_instanceIndexI0 = dc.instanceIndex[0]; + vs_interstageDrawingCoord0[0] = dc.modelCoord; + vs_interstageDrawingCoord0[1] = dc.constantCoord; + vs_interstageDrawingCoord0[2] = dc.elementCoord; + vs_interstageDrawingCoord0[3] = dc.primitiveCoord; + vs_interstageDrawingCoord1[0] = dc.fvarCoord; + vs_interstageDrawingCoord1[1] = dc.shaderCoord; + vs_interstageDrawingCoord1[2] = dc.vertexCoord; + vs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + vs_interstageDrawingCoord2[0] = dc.varyingCoord; + vs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = points; outPrimvars.normals = normals; } @@ -851,6 +843,12 @@ out VertexData { } outData; out vec4 gsPatchCoord; out noperspective vec3 hd_barycentricCoord; +in flat ivec4 vs_interstageDrawingCoord0[HD_NUM_PRIMITIVE_VERTS]; +out flat ivec4 gs_interstageDrawingCoord0; +in flat ivec4 vs_interstageDrawingCoord1[HD_NUM_PRIMITIVE_VERTS]; +out flat ivec4 gs_interstageDrawingCoord1; +in flat ivec4 vs_interstageDrawingCoord2[HD_NUM_PRIMITIVE_VERTS]; +out flat ivec4 gs_interstageDrawingCoord2; in PrimvarData { vec3 points; vec3 normals; @@ -860,28 +858,6 @@ out PrimvarData { vec3 normals; vec2 dispTextureCoord; } outPrimvars; -in flat int vs_dc_modelCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_modelCoord; -in flat int vs_dc_constantCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_constantCoord; -in flat int vs_dc_elementCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_elementCoord; -in flat int vs_dc_primitiveCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_primitiveCoord; -in flat int vs_dc_fvarCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_fvarCoord; -in flat int vs_dc_shaderCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_shaderCoord; -in flat int vs_dc_vertexCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_vertexCoord; -in flat int vs_dc_topologyVisibilityCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_topologyVisibilityCoord; -in flat int vs_dc_varyingCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_varyingCoord; -in flat int vs_dc_instanceIndexI0[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_instanceIndexI0; -in flat int vs_dc_instanceCoordsI0[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_instanceCoordsI0; layout(location = 4) uniform vec2 *dispTextureCoord; // //////// Codegen Accessors //////// @@ -926,16 +902,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = vs_dc_modelCoord[0]; - dc.constantCoord = vs_dc_constantCoord[0]; - dc.elementCoord = vs_dc_elementCoord[0]; - dc.primitiveCoord = vs_dc_primitiveCoord[0]; - dc.fvarCoord = vs_dc_fvarCoord[0]; - dc.shaderCoord = vs_dc_shaderCoord[0]; - dc.vertexCoord = vs_dc_vertexCoord[0]; - dc.topologyVisibilityCoord = vs_dc_topologyVisibilityCoord[0]; - dc.varyingCoord = vs_dc_varyingCoord[0]; - dc.instanceIndex[0] = vs_dc_instanceIndexI0[0]; + dc.modelCoord = vs_interstageDrawingCoord0[0][0]; + dc.constantCoord = vs_interstageDrawingCoord0[0][1]; + dc.elementCoord = vs_interstageDrawingCoord0[0][2]; + dc.primitiveCoord = vs_interstageDrawingCoord0[0][3]; + dc.fvarCoord = vs_interstageDrawingCoord1[0][0]; + dc.shaderCoord = vs_interstageDrawingCoord1[0][1]; + dc.vertexCoord = vs_interstageDrawingCoord1[0][2]; + dc.topologyVisibilityCoord = vs_interstageDrawingCoord1[0][3]; + dc.varyingCoord = vs_interstageDrawingCoord2[0][0]; + dc.instanceIndex[0] = vs_interstageDrawingCoord2[0][1]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -1028,16 +1004,16 @@ void ProcessPrimvarsOut(int index) { ); hd_barycentricCoord = coords[index]; hd_drawingCoord dc = GetDrawingCoord(); - gs_dc_modelCoord = dc.modelCoord; - gs_dc_constantCoord = dc.constantCoord; - gs_dc_elementCoord = dc.elementCoord; - gs_dc_primitiveCoord = dc.primitiveCoord; - gs_dc_fvarCoord = dc.fvarCoord; - gs_dc_shaderCoord = dc.shaderCoord; - gs_dc_vertexCoord = dc.vertexCoord; - gs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - gs_dc_varyingCoord = dc.varyingCoord; - gs_dc_instanceIndexI0 = dc.instanceIndex[0]; + gs_interstageDrawingCoord0[0] = dc.modelCoord; + gs_interstageDrawingCoord0[1] = dc.constantCoord; + gs_interstageDrawingCoord0[2] = dc.elementCoord; + gs_interstageDrawingCoord0[3] = dc.primitiveCoord; + gs_interstageDrawingCoord1[0] = dc.fvarCoord; + gs_interstageDrawingCoord1[1] = dc.shaderCoord; + gs_interstageDrawingCoord1[2] = dc.vertexCoord; + gs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + gs_interstageDrawingCoord2[0] = dc.varyingCoord; + gs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = inPrimvars[index].points; outPrimvars.normals = inPrimvars[index].normals; outPrimvars.dispTextureCoord = HdGet_dispTextureCoord(index); @@ -1662,22 +1638,14 @@ in VertexData { } inData; layout (location = 0) out vec4 colorOut; in noperspective vec3 hd_barycentricCoord; +in flat ivec4 gs_interstageDrawingCoord0; +in flat ivec4 gs_interstageDrawingCoord1; +in flat ivec4 gs_interstageDrawingCoord2; in PrimvarData { vec3 points; vec3 normals; vec2 dispTextureCoord; } inPrimvars; -in flat int gs_dc_modelCoord; -in flat int gs_dc_constantCoord; -in flat int gs_dc_elementCoord; -in flat int gs_dc_primitiveCoord; -in flat int gs_dc_fvarCoord; -in flat int gs_dc_shaderCoord; -in flat int gs_dc_vertexCoord; -in flat int gs_dc_topologyVisibilityCoord; -in flat int gs_dc_varyingCoord; -in flat int gs_dc_instanceIndexI0; -in flat int gs_dc_instanceCoordsI0; layout(location = 4) uniform vec2 *dispTextureCoord; vec4 InterpolatePatchCoord(vec2 uv, ivec3 patchParam) { @@ -1736,16 +1704,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = gs_dc_modelCoord; - dc.constantCoord = gs_dc_constantCoord; - dc.elementCoord = gs_dc_elementCoord; - dc.primitiveCoord = gs_dc_primitiveCoord; - dc.fvarCoord = gs_dc_fvarCoord; - dc.shaderCoord = gs_dc_shaderCoord; - dc.vertexCoord = gs_dc_vertexCoord; - dc.topologyVisibilityCoord = gs_dc_topologyVisibilityCoord; - dc.varyingCoord = gs_dc_varyingCoord; - dc.instanceIndex[0] = gs_dc_instanceIndexI0; + dc.modelCoord = gs_interstageDrawingCoord0[0]; + dc.constantCoord = gs_interstageDrawingCoord0[1]; + dc.elementCoord = gs_interstageDrawingCoord0[2]; + dc.primitiveCoord = gs_interstageDrawingCoord0[3]; + dc.fvarCoord = gs_interstageDrawingCoord1[0]; + dc.shaderCoord = gs_interstageDrawingCoord1[1]; + dc.vertexCoord = gs_interstageDrawingCoord1[2]; + dc.topologyVisibilityCoord = gs_interstageDrawingCoord1[3]; + dc.varyingCoord = gs_interstageDrawingCoord2[0]; + dc.instanceIndex[0] = gs_interstageDrawingCoord2[1]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -1999,12 +1967,37 @@ vec4 ApplyColorOverridesPostLighting(vec4 color) -void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +void RenderColor(vec4 color) { colorOut = color; } + +void RenderId() +{ + // do nothing +} + + + +void RenderNeye(vec3 Neye) +{ + // do nothing +} + + + +void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +{ + // Write to any desired AOVs here. The render pass shader configuation + // decides if any of these are no-ops. + RenderColor(color); + RenderId(); + RenderNeye(Neye); +} + + #ifndef HD_HAS_integrateLights #define HD_HAS_integrateLights #endif @@ -2838,22 +2831,14 @@ FORWARD_DECL(int GetElementID()); FORWARD_DECL(int GetAggregatedElementID()); FORWARD_DECL(int GetPrimitiveEdgeId()); FORWARD_DECL(float GetSelectedEdgeOpacity()); +out flat ivec4 vs_interstageDrawingCoord0; +out flat ivec4 vs_interstageDrawingCoord1; +out flat ivec4 vs_interstageDrawingCoord2; layout (location = 2) in ivec4 drawingCoord0; layout (location = 3) in ivec4 drawingCoord1; layout (location = 4) in ivec2 drawingCoord2; layout (location = 0) in vec3 points; layout (location = 1) in vec3 normals; -out flat int vs_dc_modelCoord; -out flat int vs_dc_constantCoord; -out flat int vs_dc_elementCoord; -out flat int vs_dc_primitiveCoord; -out flat int vs_dc_fvarCoord; -out flat int vs_dc_shaderCoord; -out flat int vs_dc_vertexCoord; -out flat int vs_dc_topologyVisibilityCoord; -out flat int vs_dc_varyingCoord; -out flat int vs_dc_instanceIndexI0; -out flat int vs_dc_instanceCoordsI0; layout(location = 0) uniform ConstantData10 *constantPrimvars; layout(location = 1) uniform int *primitiveParam; layout(location = 2) uniform ivec2 *edgeIndices; @@ -2932,16 +2917,16 @@ float HdGetScalar_normals() { return HdGet_normals(0).x; } // //////// Codegen Proc VS //////// void ProcessPrimvarsIn() { hd_drawingCoord dc = GetDrawingCoord(); - vs_dc_modelCoord = dc.modelCoord; - vs_dc_constantCoord = dc.constantCoord; - vs_dc_elementCoord = dc.elementCoord; - vs_dc_primitiveCoord = dc.primitiveCoord; - vs_dc_fvarCoord = dc.fvarCoord; - vs_dc_shaderCoord = dc.shaderCoord; - vs_dc_vertexCoord = dc.vertexCoord; - vs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - vs_dc_varyingCoord = dc.varyingCoord; - vs_dc_instanceIndexI0 = dc.instanceIndex[0]; + vs_interstageDrawingCoord0[0] = dc.modelCoord; + vs_interstageDrawingCoord0[1] = dc.constantCoord; + vs_interstageDrawingCoord0[2] = dc.elementCoord; + vs_interstageDrawingCoord0[3] = dc.primitiveCoord; + vs_interstageDrawingCoord1[0] = dc.fvarCoord; + vs_interstageDrawingCoord1[1] = dc.shaderCoord; + vs_interstageDrawingCoord1[2] = dc.vertexCoord; + vs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + vs_interstageDrawingCoord2[0] = dc.varyingCoord; + vs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = points; outPrimvars.normals = normals; } @@ -3527,6 +3512,12 @@ out VertexData { } outData; out vec4 gsPatchCoord; out noperspective vec3 hd_barycentricCoord; +in flat ivec4 vs_interstageDrawingCoord0[HD_NUM_PRIMITIVE_VERTS]; +out flat ivec4 gs_interstageDrawingCoord0; +in flat ivec4 vs_interstageDrawingCoord1[HD_NUM_PRIMITIVE_VERTS]; +out flat ivec4 gs_interstageDrawingCoord1; +in flat ivec4 vs_interstageDrawingCoord2[HD_NUM_PRIMITIVE_VERTS]; +out flat ivec4 gs_interstageDrawingCoord2; in PrimvarData { vec3 points; vec3 normals; @@ -3536,28 +3527,6 @@ out PrimvarData { vec3 normals; vec2 dispTextureCoord; } outPrimvars; -in flat int vs_dc_modelCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_modelCoord; -in flat int vs_dc_constantCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_constantCoord; -in flat int vs_dc_elementCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_elementCoord; -in flat int vs_dc_primitiveCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_primitiveCoord; -in flat int vs_dc_fvarCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_fvarCoord; -in flat int vs_dc_shaderCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_shaderCoord; -in flat int vs_dc_vertexCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_vertexCoord; -in flat int vs_dc_topologyVisibilityCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_topologyVisibilityCoord; -in flat int vs_dc_varyingCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_varyingCoord; -in flat int vs_dc_instanceIndexI0[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_instanceIndexI0; -in flat int vs_dc_instanceCoordsI0[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_instanceCoordsI0; layout(location = 4) uniform vec2 *dispTextureCoord; // //////// Codegen Accessors //////// @@ -3602,16 +3571,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = vs_dc_modelCoord[0]; - dc.constantCoord = vs_dc_constantCoord[0]; - dc.elementCoord = vs_dc_elementCoord[0]; - dc.primitiveCoord = vs_dc_primitiveCoord[0]; - dc.fvarCoord = vs_dc_fvarCoord[0]; - dc.shaderCoord = vs_dc_shaderCoord[0]; - dc.vertexCoord = vs_dc_vertexCoord[0]; - dc.topologyVisibilityCoord = vs_dc_topologyVisibilityCoord[0]; - dc.varyingCoord = vs_dc_varyingCoord[0]; - dc.instanceIndex[0] = vs_dc_instanceIndexI0[0]; + dc.modelCoord = vs_interstageDrawingCoord0[0][0]; + dc.constantCoord = vs_interstageDrawingCoord0[0][1]; + dc.elementCoord = vs_interstageDrawingCoord0[0][2]; + dc.primitiveCoord = vs_interstageDrawingCoord0[0][3]; + dc.fvarCoord = vs_interstageDrawingCoord1[0][0]; + dc.shaderCoord = vs_interstageDrawingCoord1[0][1]; + dc.vertexCoord = vs_interstageDrawingCoord1[0][2]; + dc.topologyVisibilityCoord = vs_interstageDrawingCoord1[0][3]; + dc.varyingCoord = vs_interstageDrawingCoord2[0][0]; + dc.instanceIndex[0] = vs_interstageDrawingCoord2[0][1]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -3704,16 +3673,16 @@ void ProcessPrimvarsOut(int index) { ); hd_barycentricCoord = coords[index]; hd_drawingCoord dc = GetDrawingCoord(); - gs_dc_modelCoord = dc.modelCoord; - gs_dc_constantCoord = dc.constantCoord; - gs_dc_elementCoord = dc.elementCoord; - gs_dc_primitiveCoord = dc.primitiveCoord; - gs_dc_fvarCoord = dc.fvarCoord; - gs_dc_shaderCoord = dc.shaderCoord; - gs_dc_vertexCoord = dc.vertexCoord; - gs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - gs_dc_varyingCoord = dc.varyingCoord; - gs_dc_instanceIndexI0 = dc.instanceIndex[0]; + gs_interstageDrawingCoord0[0] = dc.modelCoord; + gs_interstageDrawingCoord0[1] = dc.constantCoord; + gs_interstageDrawingCoord0[2] = dc.elementCoord; + gs_interstageDrawingCoord0[3] = dc.primitiveCoord; + gs_interstageDrawingCoord1[0] = dc.fvarCoord; + gs_interstageDrawingCoord1[1] = dc.shaderCoord; + gs_interstageDrawingCoord1[2] = dc.vertexCoord; + gs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + gs_interstageDrawingCoord2[0] = dc.varyingCoord; + gs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = inPrimvars[index].points; outPrimvars.normals = inPrimvars[index].normals; outPrimvars.dispTextureCoord = HdGet_dispTextureCoord(index); @@ -4367,22 +4336,14 @@ in VertexData { } inData; layout (location = 0) out vec4 colorOut; in noperspective vec3 hd_barycentricCoord; +in flat ivec4 gs_interstageDrawingCoord0; +in flat ivec4 gs_interstageDrawingCoord1; +in flat ivec4 gs_interstageDrawingCoord2; in PrimvarData { vec3 points; vec3 normals; vec2 dispTextureCoord; } inPrimvars; -in flat int gs_dc_modelCoord; -in flat int gs_dc_constantCoord; -in flat int gs_dc_elementCoord; -in flat int gs_dc_primitiveCoord; -in flat int gs_dc_fvarCoord; -in flat int gs_dc_shaderCoord; -in flat int gs_dc_vertexCoord; -in flat int gs_dc_topologyVisibilityCoord; -in flat int gs_dc_varyingCoord; -in flat int gs_dc_instanceIndexI0; -in flat int gs_dc_instanceCoordsI0; layout(location = 4) uniform vec2 *dispTextureCoord; vec4 InterpolatePatchCoord(vec2 uv, ivec3 patchParam) { @@ -4441,16 +4402,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = gs_dc_modelCoord; - dc.constantCoord = gs_dc_constantCoord; - dc.elementCoord = gs_dc_elementCoord; - dc.primitiveCoord = gs_dc_primitiveCoord; - dc.fvarCoord = gs_dc_fvarCoord; - dc.shaderCoord = gs_dc_shaderCoord; - dc.vertexCoord = gs_dc_vertexCoord; - dc.topologyVisibilityCoord = gs_dc_topologyVisibilityCoord; - dc.varyingCoord = gs_dc_varyingCoord; - dc.instanceIndex[0] = gs_dc_instanceIndexI0; + dc.modelCoord = gs_interstageDrawingCoord0[0]; + dc.constantCoord = gs_interstageDrawingCoord0[1]; + dc.elementCoord = gs_interstageDrawingCoord0[2]; + dc.primitiveCoord = gs_interstageDrawingCoord0[3]; + dc.fvarCoord = gs_interstageDrawingCoord1[0]; + dc.shaderCoord = gs_interstageDrawingCoord1[1]; + dc.vertexCoord = gs_interstageDrawingCoord1[2]; + dc.topologyVisibilityCoord = gs_interstageDrawingCoord1[3]; + dc.varyingCoord = gs_interstageDrawingCoord2[0]; + dc.instanceIndex[0] = gs_interstageDrawingCoord2[1]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -4704,12 +4665,37 @@ vec4 ApplyColorOverridesPostLighting(vec4 color) -void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +void RenderColor(vec4 color) { colorOut = color; } + +void RenderId() +{ + // do nothing +} + + + +void RenderNeye(vec3 Neye) +{ + // do nothing +} + + + +void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +{ + // Write to any desired AOVs here. The render pass shader configuation + // decides if any of these are no-ops. + RenderColor(color); + RenderId(); + RenderNeye(Neye); +} + + #ifndef HD_HAS_integrateLights #define HD_HAS_integrateLights #endif diff --git a/pxr/imaging/hdSt/testenv/testHdStCodeGen_GL/baseline/codegen_mesh_indirect_instance.out b/pxr/imaging/hdSt/testenv/testHdStCodeGen_GL/baseline/codegen_mesh_indirect_instance.out index 63f827af517..30328f80d7d 100644 --- a/pxr/imaging/hdSt/testenv/testHdStCodeGen_GL/baseline/codegen_mesh_indirect_instance.out +++ b/pxr/imaging/hdSt/testenv/testHdStCodeGen_GL/baseline/codegen_mesh_indirect_instance.out @@ -164,25 +164,16 @@ FORWARD_DECL(int GetElementID()); FORWARD_DECL(int GetAggregatedElementID()); FORWARD_DECL(int GetPrimitiveEdgeId()); FORWARD_DECL(float GetSelectedEdgeOpacity()); +out flat ivec4 vs_interstageDrawingCoord0; +out flat ivec4 vs_interstageDrawingCoord1; +out flat ivec4 vs_interstageDrawingCoord2; +out flat ivec4 vs_interstageDrawingCoord3; layout (location = 2) in ivec4 drawingCoord0; layout (location = 3) in ivec4 drawingCoord1; layout (location = 4) in ivec2 drawingCoord2; layout (location = 5) in int drawingCoordI0; layout (location = 0) in vec3 points; layout (location = 1) in vec3 normals; -out flat int vs_dc_modelCoord; -out flat int vs_dc_constantCoord; -out flat int vs_dc_elementCoord; -out flat int vs_dc_primitiveCoord; -out flat int vs_dc_fvarCoord; -out flat int vs_dc_shaderCoord; -out flat int vs_dc_vertexCoord; -out flat int vs_dc_topologyVisibilityCoord; -out flat int vs_dc_varyingCoord; -out flat int vs_dc_instanceIndexI0; -out flat int vs_dc_instanceIndexI1; -out flat int vs_dc_instanceCoordsI0; -out flat int vs_dc_instanceCoordsI1; layout(location = 6) uniform int *instanceIndices; layout(location = 7) uniform int *culledInstanceIndices; layout(location = 0) uniform ConstantData10 *constantPrimvars; @@ -305,18 +296,18 @@ float HdGetScalar_normals() { return HdGet_normals(0).x; } // //////// Codegen Proc VS //////// void ProcessPrimvarsIn() { hd_drawingCoord dc = GetDrawingCoord(); - vs_dc_modelCoord = dc.modelCoord; - vs_dc_constantCoord = dc.constantCoord; - vs_dc_elementCoord = dc.elementCoord; - vs_dc_primitiveCoord = dc.primitiveCoord; - vs_dc_fvarCoord = dc.fvarCoord; - vs_dc_shaderCoord = dc.shaderCoord; - vs_dc_vertexCoord = dc.vertexCoord; - vs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - vs_dc_varyingCoord = dc.varyingCoord; - vs_dc_instanceIndexI0 = dc.instanceIndex[0]; - vs_dc_instanceIndexI1 = dc.instanceIndex[1]; - vs_dc_instanceCoordsI0 = dc.instanceCoords[0]; + vs_interstageDrawingCoord0[0] = dc.modelCoord; + vs_interstageDrawingCoord0[1] = dc.constantCoord; + vs_interstageDrawingCoord0[2] = dc.elementCoord; + vs_interstageDrawingCoord0[3] = dc.primitiveCoord; + vs_interstageDrawingCoord1[0] = dc.fvarCoord; + vs_interstageDrawingCoord1[1] = dc.shaderCoord; + vs_interstageDrawingCoord1[2] = dc.vertexCoord; + vs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + vs_interstageDrawingCoord2[0] = dc.varyingCoord; + vs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; + vs_interstageDrawingCoord2[2] = dc.instanceIndex[1]; + vs_interstageDrawingCoord2[3] = dc.instanceCoords[0]; outPrimvars.points = points; outPrimvars.normals = normals; } @@ -907,6 +898,14 @@ out VertexData { } outData; out vec4 gsPatchCoord; out noperspective vec3 hd_barycentricCoord; +in flat ivec4 vs_interstageDrawingCoord0[HD_NUM_PRIMITIVE_VERTS]; +out flat ivec4 gs_interstageDrawingCoord0; +in flat ivec4 vs_interstageDrawingCoord1[HD_NUM_PRIMITIVE_VERTS]; +out flat ivec4 gs_interstageDrawingCoord1; +in flat ivec4 vs_interstageDrawingCoord2[HD_NUM_PRIMITIVE_VERTS]; +out flat ivec4 gs_interstageDrawingCoord2; +in flat ivec4 vs_interstageDrawingCoord3[HD_NUM_PRIMITIVE_VERTS]; +out flat ivec4 gs_interstageDrawingCoord3; in PrimvarData { vec3 points; vec3 normals; @@ -916,32 +915,6 @@ out PrimvarData { vec3 normals; vec2 dispTextureCoord; } outPrimvars; -in flat int vs_dc_modelCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_modelCoord; -in flat int vs_dc_constantCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_constantCoord; -in flat int vs_dc_elementCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_elementCoord; -in flat int vs_dc_primitiveCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_primitiveCoord; -in flat int vs_dc_fvarCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_fvarCoord; -in flat int vs_dc_shaderCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_shaderCoord; -in flat int vs_dc_vertexCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_vertexCoord; -in flat int vs_dc_topologyVisibilityCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_topologyVisibilityCoord; -in flat int vs_dc_varyingCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_varyingCoord; -in flat int vs_dc_instanceIndexI0[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_instanceIndexI0; -in flat int vs_dc_instanceIndexI1[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_instanceIndexI1; -in flat int vs_dc_instanceCoordsI0[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_instanceCoordsI0; -in flat int vs_dc_instanceCoordsI1[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_instanceCoordsI1; layout(location = 5) uniform vec2 *dispTextureCoord; // //////// Codegen Accessors //////// @@ -1004,18 +977,18 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = vs_dc_modelCoord[0]; - dc.constantCoord = vs_dc_constantCoord[0]; - dc.elementCoord = vs_dc_elementCoord[0]; - dc.primitiveCoord = vs_dc_primitiveCoord[0]; - dc.fvarCoord = vs_dc_fvarCoord[0]; - dc.shaderCoord = vs_dc_shaderCoord[0]; - dc.vertexCoord = vs_dc_vertexCoord[0]; - dc.topologyVisibilityCoord = vs_dc_topologyVisibilityCoord[0]; - dc.varyingCoord = vs_dc_varyingCoord[0]; - dc.instanceIndex[0] = vs_dc_instanceIndexI0[0]; - dc.instanceIndex[1] = vs_dc_instanceIndexI1[0]; - dc.instanceCoords[0] = vs_dc_instanceCoordsI0[0]; + dc.modelCoord = vs_interstageDrawingCoord0[0][0]; + dc.constantCoord = vs_interstageDrawingCoord0[0][1]; + dc.elementCoord = vs_interstageDrawingCoord0[0][2]; + dc.primitiveCoord = vs_interstageDrawingCoord0[0][3]; + dc.fvarCoord = vs_interstageDrawingCoord1[0][0]; + dc.shaderCoord = vs_interstageDrawingCoord1[0][1]; + dc.vertexCoord = vs_interstageDrawingCoord1[0][2]; + dc.topologyVisibilityCoord = vs_interstageDrawingCoord1[0][3]; + dc.varyingCoord = vs_interstageDrawingCoord2[0][0]; + dc.instanceIndex[0] = vs_interstageDrawingCoord2[0][1]; + dc.instanceIndex[1] = vs_interstageDrawingCoord2[0][2]; + dc.instanceCoords[0] = vs_interstageDrawingCoord2[0][3]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -1108,18 +1081,18 @@ void ProcessPrimvarsOut(int index) { ); hd_barycentricCoord = coords[index]; hd_drawingCoord dc = GetDrawingCoord(); - gs_dc_modelCoord = dc.modelCoord; - gs_dc_constantCoord = dc.constantCoord; - gs_dc_elementCoord = dc.elementCoord; - gs_dc_primitiveCoord = dc.primitiveCoord; - gs_dc_fvarCoord = dc.fvarCoord; - gs_dc_shaderCoord = dc.shaderCoord; - gs_dc_vertexCoord = dc.vertexCoord; - gs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - gs_dc_varyingCoord = dc.varyingCoord; - gs_dc_instanceIndexI0 = dc.instanceIndex[0]; - gs_dc_instanceIndexI1 = dc.instanceIndex[1]; - gs_dc_instanceCoordsI0 = dc.instanceCoords[0]; + gs_interstageDrawingCoord0[0] = dc.modelCoord; + gs_interstageDrawingCoord0[1] = dc.constantCoord; + gs_interstageDrawingCoord0[2] = dc.elementCoord; + gs_interstageDrawingCoord0[3] = dc.primitiveCoord; + gs_interstageDrawingCoord1[0] = dc.fvarCoord; + gs_interstageDrawingCoord1[1] = dc.shaderCoord; + gs_interstageDrawingCoord1[2] = dc.vertexCoord; + gs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + gs_interstageDrawingCoord2[0] = dc.varyingCoord; + gs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; + gs_interstageDrawingCoord2[2] = dc.instanceIndex[1]; + gs_interstageDrawingCoord2[3] = dc.instanceCoords[0]; outPrimvars.points = inPrimvars[index].points; outPrimvars.normals = inPrimvars[index].normals; outPrimvars.dispTextureCoord = HdGet_dispTextureCoord(index); @@ -1749,24 +1722,15 @@ in VertexData { } inData; layout (location = 0) out vec4 colorOut; in noperspective vec3 hd_barycentricCoord; +in flat ivec4 gs_interstageDrawingCoord0; +in flat ivec4 gs_interstageDrawingCoord1; +in flat ivec4 gs_interstageDrawingCoord2; +in flat ivec4 gs_interstageDrawingCoord3; in PrimvarData { vec3 points; vec3 normals; vec2 dispTextureCoord; } inPrimvars; -in flat int gs_dc_modelCoord; -in flat int gs_dc_constantCoord; -in flat int gs_dc_elementCoord; -in flat int gs_dc_primitiveCoord; -in flat int gs_dc_fvarCoord; -in flat int gs_dc_shaderCoord; -in flat int gs_dc_vertexCoord; -in flat int gs_dc_topologyVisibilityCoord; -in flat int gs_dc_varyingCoord; -in flat int gs_dc_instanceIndexI0; -in flat int gs_dc_instanceIndexI1; -in flat int gs_dc_instanceCoordsI0; -in flat int gs_dc_instanceCoordsI1; layout(location = 5) uniform vec2 *dispTextureCoord; vec4 InterpolatePatchCoord(vec2 uv, ivec3 patchParam) { @@ -1843,18 +1807,18 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = gs_dc_modelCoord; - dc.constantCoord = gs_dc_constantCoord; - dc.elementCoord = gs_dc_elementCoord; - dc.primitiveCoord = gs_dc_primitiveCoord; - dc.fvarCoord = gs_dc_fvarCoord; - dc.shaderCoord = gs_dc_shaderCoord; - dc.vertexCoord = gs_dc_vertexCoord; - dc.topologyVisibilityCoord = gs_dc_topologyVisibilityCoord; - dc.varyingCoord = gs_dc_varyingCoord; - dc.instanceIndex[0] = gs_dc_instanceIndexI0; - dc.instanceIndex[1] = gs_dc_instanceIndexI1; - dc.instanceCoords[0] = gs_dc_instanceCoordsI0; + dc.modelCoord = gs_interstageDrawingCoord0[0]; + dc.constantCoord = gs_interstageDrawingCoord0[1]; + dc.elementCoord = gs_interstageDrawingCoord0[2]; + dc.primitiveCoord = gs_interstageDrawingCoord0[3]; + dc.fvarCoord = gs_interstageDrawingCoord1[0]; + dc.shaderCoord = gs_interstageDrawingCoord1[1]; + dc.vertexCoord = gs_interstageDrawingCoord1[2]; + dc.topologyVisibilityCoord = gs_interstageDrawingCoord1[3]; + dc.varyingCoord = gs_interstageDrawingCoord2[0]; + dc.instanceIndex[0] = gs_interstageDrawingCoord2[1]; + dc.instanceIndex[1] = gs_interstageDrawingCoord2[2]; + dc.instanceCoords[0] = gs_interstageDrawingCoord2[3]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -2108,12 +2072,37 @@ vec4 ApplyColorOverridesPostLighting(vec4 color) -void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +void RenderColor(vec4 color) { colorOut = color; } + +void RenderId() +{ + // do nothing +} + + + +void RenderNeye(vec3 Neye) +{ + // do nothing +} + + + +void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +{ + // Write to any desired AOVs here. The render pass shader configuation + // decides if any of these are no-ops. + RenderColor(color); + RenderId(); + RenderNeye(Neye); +} + + #ifndef HD_HAS_integrateLights #define HD_HAS_integrateLights #endif @@ -2949,25 +2938,16 @@ FORWARD_DECL(int GetElementID()); FORWARD_DECL(int GetAggregatedElementID()); FORWARD_DECL(int GetPrimitiveEdgeId()); FORWARD_DECL(float GetSelectedEdgeOpacity()); +out flat ivec4 vs_interstageDrawingCoord0; +out flat ivec4 vs_interstageDrawingCoord1; +out flat ivec4 vs_interstageDrawingCoord2; +out flat ivec4 vs_interstageDrawingCoord3; layout (location = 2) in ivec4 drawingCoord0; layout (location = 3) in ivec4 drawingCoord1; layout (location = 4) in ivec2 drawingCoord2; layout (location = 5) in int drawingCoordI0; layout (location = 0) in vec3 points; layout (location = 1) in vec3 normals; -out flat int vs_dc_modelCoord; -out flat int vs_dc_constantCoord; -out flat int vs_dc_elementCoord; -out flat int vs_dc_primitiveCoord; -out flat int vs_dc_fvarCoord; -out flat int vs_dc_shaderCoord; -out flat int vs_dc_vertexCoord; -out flat int vs_dc_topologyVisibilityCoord; -out flat int vs_dc_varyingCoord; -out flat int vs_dc_instanceIndexI0; -out flat int vs_dc_instanceIndexI1; -out flat int vs_dc_instanceCoordsI0; -out flat int vs_dc_instanceCoordsI1; layout(location = 6) uniform int *instanceIndices; layout(location = 7) uniform int *culledInstanceIndices; layout(location = 0) uniform ConstantData10 *constantPrimvars; @@ -3090,18 +3070,18 @@ float HdGetScalar_normals() { return HdGet_normals(0).x; } // //////// Codegen Proc VS //////// void ProcessPrimvarsIn() { hd_drawingCoord dc = GetDrawingCoord(); - vs_dc_modelCoord = dc.modelCoord; - vs_dc_constantCoord = dc.constantCoord; - vs_dc_elementCoord = dc.elementCoord; - vs_dc_primitiveCoord = dc.primitiveCoord; - vs_dc_fvarCoord = dc.fvarCoord; - vs_dc_shaderCoord = dc.shaderCoord; - vs_dc_vertexCoord = dc.vertexCoord; - vs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - vs_dc_varyingCoord = dc.varyingCoord; - vs_dc_instanceIndexI0 = dc.instanceIndex[0]; - vs_dc_instanceIndexI1 = dc.instanceIndex[1]; - vs_dc_instanceCoordsI0 = dc.instanceCoords[0]; + vs_interstageDrawingCoord0[0] = dc.modelCoord; + vs_interstageDrawingCoord0[1] = dc.constantCoord; + vs_interstageDrawingCoord0[2] = dc.elementCoord; + vs_interstageDrawingCoord0[3] = dc.primitiveCoord; + vs_interstageDrawingCoord1[0] = dc.fvarCoord; + vs_interstageDrawingCoord1[1] = dc.shaderCoord; + vs_interstageDrawingCoord1[2] = dc.vertexCoord; + vs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + vs_interstageDrawingCoord2[0] = dc.varyingCoord; + vs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; + vs_interstageDrawingCoord2[2] = dc.instanceIndex[1]; + vs_interstageDrawingCoord2[3] = dc.instanceCoords[0]; outPrimvars.points = points; outPrimvars.normals = normals; } @@ -3692,6 +3672,14 @@ out VertexData { } outData; out vec4 gsPatchCoord; out noperspective vec3 hd_barycentricCoord; +in flat ivec4 vs_interstageDrawingCoord0[HD_NUM_PRIMITIVE_VERTS]; +out flat ivec4 gs_interstageDrawingCoord0; +in flat ivec4 vs_interstageDrawingCoord1[HD_NUM_PRIMITIVE_VERTS]; +out flat ivec4 gs_interstageDrawingCoord1; +in flat ivec4 vs_interstageDrawingCoord2[HD_NUM_PRIMITIVE_VERTS]; +out flat ivec4 gs_interstageDrawingCoord2; +in flat ivec4 vs_interstageDrawingCoord3[HD_NUM_PRIMITIVE_VERTS]; +out flat ivec4 gs_interstageDrawingCoord3; in PrimvarData { vec3 points; vec3 normals; @@ -3701,32 +3689,6 @@ out PrimvarData { vec3 normals; vec2 dispTextureCoord; } outPrimvars; -in flat int vs_dc_modelCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_modelCoord; -in flat int vs_dc_constantCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_constantCoord; -in flat int vs_dc_elementCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_elementCoord; -in flat int vs_dc_primitiveCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_primitiveCoord; -in flat int vs_dc_fvarCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_fvarCoord; -in flat int vs_dc_shaderCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_shaderCoord; -in flat int vs_dc_vertexCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_vertexCoord; -in flat int vs_dc_topologyVisibilityCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_topologyVisibilityCoord; -in flat int vs_dc_varyingCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_varyingCoord; -in flat int vs_dc_instanceIndexI0[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_instanceIndexI0; -in flat int vs_dc_instanceIndexI1[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_instanceIndexI1; -in flat int vs_dc_instanceCoordsI0[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_instanceCoordsI0; -in flat int vs_dc_instanceCoordsI1[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_instanceCoordsI1; layout(location = 5) uniform vec2 *dispTextureCoord; // //////// Codegen Accessors //////// @@ -3789,18 +3751,18 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = vs_dc_modelCoord[0]; - dc.constantCoord = vs_dc_constantCoord[0]; - dc.elementCoord = vs_dc_elementCoord[0]; - dc.primitiveCoord = vs_dc_primitiveCoord[0]; - dc.fvarCoord = vs_dc_fvarCoord[0]; - dc.shaderCoord = vs_dc_shaderCoord[0]; - dc.vertexCoord = vs_dc_vertexCoord[0]; - dc.topologyVisibilityCoord = vs_dc_topologyVisibilityCoord[0]; - dc.varyingCoord = vs_dc_varyingCoord[0]; - dc.instanceIndex[0] = vs_dc_instanceIndexI0[0]; - dc.instanceIndex[1] = vs_dc_instanceIndexI1[0]; - dc.instanceCoords[0] = vs_dc_instanceCoordsI0[0]; + dc.modelCoord = vs_interstageDrawingCoord0[0][0]; + dc.constantCoord = vs_interstageDrawingCoord0[0][1]; + dc.elementCoord = vs_interstageDrawingCoord0[0][2]; + dc.primitiveCoord = vs_interstageDrawingCoord0[0][3]; + dc.fvarCoord = vs_interstageDrawingCoord1[0][0]; + dc.shaderCoord = vs_interstageDrawingCoord1[0][1]; + dc.vertexCoord = vs_interstageDrawingCoord1[0][2]; + dc.topologyVisibilityCoord = vs_interstageDrawingCoord1[0][3]; + dc.varyingCoord = vs_interstageDrawingCoord2[0][0]; + dc.instanceIndex[0] = vs_interstageDrawingCoord2[0][1]; + dc.instanceIndex[1] = vs_interstageDrawingCoord2[0][2]; + dc.instanceCoords[0] = vs_interstageDrawingCoord2[0][3]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -3893,18 +3855,18 @@ void ProcessPrimvarsOut(int index) { ); hd_barycentricCoord = coords[index]; hd_drawingCoord dc = GetDrawingCoord(); - gs_dc_modelCoord = dc.modelCoord; - gs_dc_constantCoord = dc.constantCoord; - gs_dc_elementCoord = dc.elementCoord; - gs_dc_primitiveCoord = dc.primitiveCoord; - gs_dc_fvarCoord = dc.fvarCoord; - gs_dc_shaderCoord = dc.shaderCoord; - gs_dc_vertexCoord = dc.vertexCoord; - gs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - gs_dc_varyingCoord = dc.varyingCoord; - gs_dc_instanceIndexI0 = dc.instanceIndex[0]; - gs_dc_instanceIndexI1 = dc.instanceIndex[1]; - gs_dc_instanceCoordsI0 = dc.instanceCoords[0]; + gs_interstageDrawingCoord0[0] = dc.modelCoord; + gs_interstageDrawingCoord0[1] = dc.constantCoord; + gs_interstageDrawingCoord0[2] = dc.elementCoord; + gs_interstageDrawingCoord0[3] = dc.primitiveCoord; + gs_interstageDrawingCoord1[0] = dc.fvarCoord; + gs_interstageDrawingCoord1[1] = dc.shaderCoord; + gs_interstageDrawingCoord1[2] = dc.vertexCoord; + gs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + gs_interstageDrawingCoord2[0] = dc.varyingCoord; + gs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; + gs_interstageDrawingCoord2[2] = dc.instanceIndex[1]; + gs_interstageDrawingCoord2[3] = dc.instanceCoords[0]; outPrimvars.points = inPrimvars[index].points; outPrimvars.normals = inPrimvars[index].normals; outPrimvars.dispTextureCoord = HdGet_dispTextureCoord(index); @@ -4563,24 +4525,15 @@ in VertexData { } inData; layout (location = 0) out vec4 colorOut; in noperspective vec3 hd_barycentricCoord; +in flat ivec4 gs_interstageDrawingCoord0; +in flat ivec4 gs_interstageDrawingCoord1; +in flat ivec4 gs_interstageDrawingCoord2; +in flat ivec4 gs_interstageDrawingCoord3; in PrimvarData { vec3 points; vec3 normals; vec2 dispTextureCoord; } inPrimvars; -in flat int gs_dc_modelCoord; -in flat int gs_dc_constantCoord; -in flat int gs_dc_elementCoord; -in flat int gs_dc_primitiveCoord; -in flat int gs_dc_fvarCoord; -in flat int gs_dc_shaderCoord; -in flat int gs_dc_vertexCoord; -in flat int gs_dc_topologyVisibilityCoord; -in flat int gs_dc_varyingCoord; -in flat int gs_dc_instanceIndexI0; -in flat int gs_dc_instanceIndexI1; -in flat int gs_dc_instanceCoordsI0; -in flat int gs_dc_instanceCoordsI1; layout(location = 5) uniform vec2 *dispTextureCoord; vec4 InterpolatePatchCoord(vec2 uv, ivec3 patchParam) { @@ -4657,18 +4610,18 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = gs_dc_modelCoord; - dc.constantCoord = gs_dc_constantCoord; - dc.elementCoord = gs_dc_elementCoord; - dc.primitiveCoord = gs_dc_primitiveCoord; - dc.fvarCoord = gs_dc_fvarCoord; - dc.shaderCoord = gs_dc_shaderCoord; - dc.vertexCoord = gs_dc_vertexCoord; - dc.topologyVisibilityCoord = gs_dc_topologyVisibilityCoord; - dc.varyingCoord = gs_dc_varyingCoord; - dc.instanceIndex[0] = gs_dc_instanceIndexI0; - dc.instanceIndex[1] = gs_dc_instanceIndexI1; - dc.instanceCoords[0] = gs_dc_instanceCoordsI0; + dc.modelCoord = gs_interstageDrawingCoord0[0]; + dc.constantCoord = gs_interstageDrawingCoord0[1]; + dc.elementCoord = gs_interstageDrawingCoord0[2]; + dc.primitiveCoord = gs_interstageDrawingCoord0[3]; + dc.fvarCoord = gs_interstageDrawingCoord1[0]; + dc.shaderCoord = gs_interstageDrawingCoord1[1]; + dc.vertexCoord = gs_interstageDrawingCoord1[2]; + dc.topologyVisibilityCoord = gs_interstageDrawingCoord1[3]; + dc.varyingCoord = gs_interstageDrawingCoord2[0]; + dc.instanceIndex[0] = gs_interstageDrawingCoord2[1]; + dc.instanceIndex[1] = gs_interstageDrawingCoord2[2]; + dc.instanceCoords[0] = gs_interstageDrawingCoord2[3]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -4922,12 +4875,37 @@ vec4 ApplyColorOverridesPostLighting(vec4 color) -void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +void RenderColor(vec4 color) { colorOut = color; } + +void RenderId() +{ + // do nothing +} + + + +void RenderNeye(vec3 Neye) +{ + // do nothing +} + + + +void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +{ + // Write to any desired AOVs here. The render pass shader configuation + // decides if any of these are no-ops. + RenderColor(color); + RenderId(); + RenderNeye(Neye); +} + + #ifndef HD_HAS_integrateLights #define HD_HAS_integrateLights #endif diff --git a/pxr/imaging/hdSt/testenv/testHdStCodeGen_GL/baseline/codegen_mesh_bindless_indirect_smoothNormals.out b/pxr/imaging/hdSt/testenv/testHdStCodeGen_GL/baseline/codegen_mesh_indirect_smoothNormals.out similarity index 95% rename from pxr/imaging/hdSt/testenv/testHdStCodeGen_GL/baseline/codegen_mesh_bindless_indirect_smoothNormals.out rename to pxr/imaging/hdSt/testenv/testHdStCodeGen_GL/baseline/codegen_mesh_indirect_smoothNormals.out index d546ea62b4e..abaa7580fd5 100644 --- a/pxr/imaging/hdSt/testenv/testHdStCodeGen_GL/baseline/codegen_mesh_bindless_indirect_smoothNormals.out +++ b/pxr/imaging/hdSt/testenv/testHdStCodeGen_GL/baseline/codegen_mesh_indirect_smoothNormals.out @@ -162,22 +162,14 @@ FORWARD_DECL(int GetElementID()); FORWARD_DECL(int GetAggregatedElementID()); FORWARD_DECL(int GetPrimitiveEdgeId()); FORWARD_DECL(float GetSelectedEdgeOpacity()); +out flat ivec4 vs_interstageDrawingCoord0; +out flat ivec4 vs_interstageDrawingCoord1; +out flat ivec4 vs_interstageDrawingCoord2; layout (location = 2) in ivec4 drawingCoord0; layout (location = 3) in ivec4 drawingCoord1; layout (location = 4) in ivec2 drawingCoord2; layout (location = 0) in vec3 points; layout (location = 1) in vec3 smoothNormals; -out flat int vs_dc_modelCoord; -out flat int vs_dc_constantCoord; -out flat int vs_dc_elementCoord; -out flat int vs_dc_primitiveCoord; -out flat int vs_dc_fvarCoord; -out flat int vs_dc_shaderCoord; -out flat int vs_dc_vertexCoord; -out flat int vs_dc_topologyVisibilityCoord; -out flat int vs_dc_varyingCoord; -out flat int vs_dc_instanceIndexI0; -out flat int vs_dc_instanceCoordsI0; layout(location = 0) uniform ConstantData10 *constantPrimvars; layout(location = 1) uniform int *primitiveParam; layout(location = 2) uniform int *edgeIndices; @@ -256,16 +248,16 @@ float HdGetScalar_smoothNormals() { return HdGet_smoothNormals(0).x; } // //////// Codegen Proc VS //////// void ProcessPrimvarsIn() { hd_drawingCoord dc = GetDrawingCoord(); - vs_dc_modelCoord = dc.modelCoord; - vs_dc_constantCoord = dc.constantCoord; - vs_dc_elementCoord = dc.elementCoord; - vs_dc_primitiveCoord = dc.primitiveCoord; - vs_dc_fvarCoord = dc.fvarCoord; - vs_dc_shaderCoord = dc.shaderCoord; - vs_dc_vertexCoord = dc.vertexCoord; - vs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - vs_dc_varyingCoord = dc.varyingCoord; - vs_dc_instanceIndexI0 = dc.instanceIndex[0]; + vs_interstageDrawingCoord0[0] = dc.modelCoord; + vs_interstageDrawingCoord0[1] = dc.constantCoord; + vs_interstageDrawingCoord0[2] = dc.elementCoord; + vs_interstageDrawingCoord0[3] = dc.primitiveCoord; + vs_interstageDrawingCoord1[0] = dc.fvarCoord; + vs_interstageDrawingCoord1[1] = dc.shaderCoord; + vs_interstageDrawingCoord1[2] = dc.vertexCoord; + vs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + vs_interstageDrawingCoord2[0] = dc.varyingCoord; + vs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = points; outPrimvars.smoothNormals = smoothNormals; } @@ -864,6 +856,12 @@ out VertexData { } outData; out vec4 gsPatchCoord; out noperspective vec3 hd_barycentricCoord; +in flat ivec4 vs_interstageDrawingCoord0[HD_NUM_PRIMITIVE_VERTS]; +out flat ivec4 gs_interstageDrawingCoord0; +in flat ivec4 vs_interstageDrawingCoord1[HD_NUM_PRIMITIVE_VERTS]; +out flat ivec4 gs_interstageDrawingCoord1; +in flat ivec4 vs_interstageDrawingCoord2[HD_NUM_PRIMITIVE_VERTS]; +out flat ivec4 gs_interstageDrawingCoord2; in PrimvarData { vec3 points; vec3 smoothNormals; @@ -873,28 +871,6 @@ out PrimvarData { vec3 smoothNormals; vec2 dispTextureCoord; } outPrimvars; -in flat int vs_dc_modelCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_modelCoord; -in flat int vs_dc_constantCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_constantCoord; -in flat int vs_dc_elementCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_elementCoord; -in flat int vs_dc_primitiveCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_primitiveCoord; -in flat int vs_dc_fvarCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_fvarCoord; -in flat int vs_dc_shaderCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_shaderCoord; -in flat int vs_dc_vertexCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_vertexCoord; -in flat int vs_dc_topologyVisibilityCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_topologyVisibilityCoord; -in flat int vs_dc_varyingCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_varyingCoord; -in flat int vs_dc_instanceIndexI0[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_instanceIndexI0; -in flat int vs_dc_instanceCoordsI0[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_instanceCoordsI0; layout(location = 4) uniform vec2 *dispTextureCoord; // //////// Codegen Accessors //////// @@ -939,16 +915,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = vs_dc_modelCoord[0]; - dc.constantCoord = vs_dc_constantCoord[0]; - dc.elementCoord = vs_dc_elementCoord[0]; - dc.primitiveCoord = vs_dc_primitiveCoord[0]; - dc.fvarCoord = vs_dc_fvarCoord[0]; - dc.shaderCoord = vs_dc_shaderCoord[0]; - dc.vertexCoord = vs_dc_vertexCoord[0]; - dc.topologyVisibilityCoord = vs_dc_topologyVisibilityCoord[0]; - dc.varyingCoord = vs_dc_varyingCoord[0]; - dc.instanceIndex[0] = vs_dc_instanceIndexI0[0]; + dc.modelCoord = vs_interstageDrawingCoord0[0][0]; + dc.constantCoord = vs_interstageDrawingCoord0[0][1]; + dc.elementCoord = vs_interstageDrawingCoord0[0][2]; + dc.primitiveCoord = vs_interstageDrawingCoord0[0][3]; + dc.fvarCoord = vs_interstageDrawingCoord1[0][0]; + dc.shaderCoord = vs_interstageDrawingCoord1[0][1]; + dc.vertexCoord = vs_interstageDrawingCoord1[0][2]; + dc.topologyVisibilityCoord = vs_interstageDrawingCoord1[0][3]; + dc.varyingCoord = vs_interstageDrawingCoord2[0][0]; + dc.instanceIndex[0] = vs_interstageDrawingCoord2[0][1]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -1041,16 +1017,16 @@ void ProcessPrimvarsOut(int index) { ); hd_barycentricCoord = coords[index]; hd_drawingCoord dc = GetDrawingCoord(); - gs_dc_modelCoord = dc.modelCoord; - gs_dc_constantCoord = dc.constantCoord; - gs_dc_elementCoord = dc.elementCoord; - gs_dc_primitiveCoord = dc.primitiveCoord; - gs_dc_fvarCoord = dc.fvarCoord; - gs_dc_shaderCoord = dc.shaderCoord; - gs_dc_vertexCoord = dc.vertexCoord; - gs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - gs_dc_varyingCoord = dc.varyingCoord; - gs_dc_instanceIndexI0 = dc.instanceIndex[0]; + gs_interstageDrawingCoord0[0] = dc.modelCoord; + gs_interstageDrawingCoord0[1] = dc.constantCoord; + gs_interstageDrawingCoord0[2] = dc.elementCoord; + gs_interstageDrawingCoord0[3] = dc.primitiveCoord; + gs_interstageDrawingCoord1[0] = dc.fvarCoord; + gs_interstageDrawingCoord1[1] = dc.shaderCoord; + gs_interstageDrawingCoord1[2] = dc.vertexCoord; + gs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + gs_interstageDrawingCoord2[0] = dc.varyingCoord; + gs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = inPrimvars[index].points; outPrimvars.smoothNormals = inPrimvars[index].smoothNormals; outPrimvars.dispTextureCoord = HdGet_dispTextureCoord(index); @@ -1662,22 +1638,14 @@ in VertexData { } inData; layout (location = 0) out vec4 colorOut; in noperspective vec3 hd_barycentricCoord; +in flat ivec4 gs_interstageDrawingCoord0; +in flat ivec4 gs_interstageDrawingCoord1; +in flat ivec4 gs_interstageDrawingCoord2; in PrimvarData { vec3 points; vec3 smoothNormals; vec2 dispTextureCoord; } inPrimvars; -in flat int gs_dc_modelCoord; -in flat int gs_dc_constantCoord; -in flat int gs_dc_elementCoord; -in flat int gs_dc_primitiveCoord; -in flat int gs_dc_fvarCoord; -in flat int gs_dc_shaderCoord; -in flat int gs_dc_vertexCoord; -in flat int gs_dc_topologyVisibilityCoord; -in flat int gs_dc_varyingCoord; -in flat int gs_dc_instanceIndexI0; -in flat int gs_dc_instanceCoordsI0; layout(location = 4) uniform vec2 *dispTextureCoord; vec4 InterpolatePatchCoord(vec2 uv, ivec3 patchParam) { @@ -1736,16 +1704,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = gs_dc_modelCoord; - dc.constantCoord = gs_dc_constantCoord; - dc.elementCoord = gs_dc_elementCoord; - dc.primitiveCoord = gs_dc_primitiveCoord; - dc.fvarCoord = gs_dc_fvarCoord; - dc.shaderCoord = gs_dc_shaderCoord; - dc.vertexCoord = gs_dc_vertexCoord; - dc.topologyVisibilityCoord = gs_dc_topologyVisibilityCoord; - dc.varyingCoord = gs_dc_varyingCoord; - dc.instanceIndex[0] = gs_dc_instanceIndexI0; + dc.modelCoord = gs_interstageDrawingCoord0[0]; + dc.constantCoord = gs_interstageDrawingCoord0[1]; + dc.elementCoord = gs_interstageDrawingCoord0[2]; + dc.primitiveCoord = gs_interstageDrawingCoord0[3]; + dc.fvarCoord = gs_interstageDrawingCoord1[0]; + dc.shaderCoord = gs_interstageDrawingCoord1[1]; + dc.vertexCoord = gs_interstageDrawingCoord1[2]; + dc.topologyVisibilityCoord = gs_interstageDrawingCoord1[3]; + dc.varyingCoord = gs_interstageDrawingCoord2[0]; + dc.instanceIndex[0] = gs_interstageDrawingCoord2[1]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -1999,12 +1967,37 @@ vec4 ApplyColorOverridesPostLighting(vec4 color) -void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +void RenderColor(vec4 color) { colorOut = color; } + +void RenderId() +{ + // do nothing +} + + + +void RenderNeye(vec3 Neye) +{ + // do nothing +} + + + +void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +{ + // Write to any desired AOVs here. The render pass shader configuation + // decides if any of these are no-ops. + RenderColor(color); + RenderId(); + RenderNeye(Neye); +} + + #ifndef HD_HAS_integrateLights #define HD_HAS_integrateLights #endif @@ -2838,22 +2831,14 @@ FORWARD_DECL(int GetElementID()); FORWARD_DECL(int GetAggregatedElementID()); FORWARD_DECL(int GetPrimitiveEdgeId()); FORWARD_DECL(float GetSelectedEdgeOpacity()); +out flat ivec4 vs_interstageDrawingCoord0; +out flat ivec4 vs_interstageDrawingCoord1; +out flat ivec4 vs_interstageDrawingCoord2; layout (location = 2) in ivec4 drawingCoord0; layout (location = 3) in ivec4 drawingCoord1; layout (location = 4) in ivec2 drawingCoord2; layout (location = 0) in vec3 points; layout (location = 1) in vec3 smoothNormals; -out flat int vs_dc_modelCoord; -out flat int vs_dc_constantCoord; -out flat int vs_dc_elementCoord; -out flat int vs_dc_primitiveCoord; -out flat int vs_dc_fvarCoord; -out flat int vs_dc_shaderCoord; -out flat int vs_dc_vertexCoord; -out flat int vs_dc_topologyVisibilityCoord; -out flat int vs_dc_varyingCoord; -out flat int vs_dc_instanceIndexI0; -out flat int vs_dc_instanceCoordsI0; layout(location = 0) uniform ConstantData10 *constantPrimvars; layout(location = 1) uniform int *primitiveParam; layout(location = 2) uniform ivec2 *edgeIndices; @@ -2932,16 +2917,16 @@ float HdGetScalar_smoothNormals() { return HdGet_smoothNormals(0).x; } // //////// Codegen Proc VS //////// void ProcessPrimvarsIn() { hd_drawingCoord dc = GetDrawingCoord(); - vs_dc_modelCoord = dc.modelCoord; - vs_dc_constantCoord = dc.constantCoord; - vs_dc_elementCoord = dc.elementCoord; - vs_dc_primitiveCoord = dc.primitiveCoord; - vs_dc_fvarCoord = dc.fvarCoord; - vs_dc_shaderCoord = dc.shaderCoord; - vs_dc_vertexCoord = dc.vertexCoord; - vs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - vs_dc_varyingCoord = dc.varyingCoord; - vs_dc_instanceIndexI0 = dc.instanceIndex[0]; + vs_interstageDrawingCoord0[0] = dc.modelCoord; + vs_interstageDrawingCoord0[1] = dc.constantCoord; + vs_interstageDrawingCoord0[2] = dc.elementCoord; + vs_interstageDrawingCoord0[3] = dc.primitiveCoord; + vs_interstageDrawingCoord1[0] = dc.fvarCoord; + vs_interstageDrawingCoord1[1] = dc.shaderCoord; + vs_interstageDrawingCoord1[2] = dc.vertexCoord; + vs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + vs_interstageDrawingCoord2[0] = dc.varyingCoord; + vs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = points; outPrimvars.smoothNormals = smoothNormals; } @@ -3540,6 +3525,12 @@ out VertexData { } outData; out vec4 gsPatchCoord; out noperspective vec3 hd_barycentricCoord; +in flat ivec4 vs_interstageDrawingCoord0[HD_NUM_PRIMITIVE_VERTS]; +out flat ivec4 gs_interstageDrawingCoord0; +in flat ivec4 vs_interstageDrawingCoord1[HD_NUM_PRIMITIVE_VERTS]; +out flat ivec4 gs_interstageDrawingCoord1; +in flat ivec4 vs_interstageDrawingCoord2[HD_NUM_PRIMITIVE_VERTS]; +out flat ivec4 gs_interstageDrawingCoord2; in PrimvarData { vec3 points; vec3 smoothNormals; @@ -3549,28 +3540,6 @@ out PrimvarData { vec3 smoothNormals; vec2 dispTextureCoord; } outPrimvars; -in flat int vs_dc_modelCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_modelCoord; -in flat int vs_dc_constantCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_constantCoord; -in flat int vs_dc_elementCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_elementCoord; -in flat int vs_dc_primitiveCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_primitiveCoord; -in flat int vs_dc_fvarCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_fvarCoord; -in flat int vs_dc_shaderCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_shaderCoord; -in flat int vs_dc_vertexCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_vertexCoord; -in flat int vs_dc_topologyVisibilityCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_topologyVisibilityCoord; -in flat int vs_dc_varyingCoord[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_varyingCoord; -in flat int vs_dc_instanceIndexI0[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_instanceIndexI0; -in flat int vs_dc_instanceCoordsI0[HD_NUM_PRIMITIVE_VERTS]; -out flat int gs_dc_instanceCoordsI0; layout(location = 4) uniform vec2 *dispTextureCoord; // //////// Codegen Accessors //////// @@ -3615,16 +3584,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = vs_dc_modelCoord[0]; - dc.constantCoord = vs_dc_constantCoord[0]; - dc.elementCoord = vs_dc_elementCoord[0]; - dc.primitiveCoord = vs_dc_primitiveCoord[0]; - dc.fvarCoord = vs_dc_fvarCoord[0]; - dc.shaderCoord = vs_dc_shaderCoord[0]; - dc.vertexCoord = vs_dc_vertexCoord[0]; - dc.topologyVisibilityCoord = vs_dc_topologyVisibilityCoord[0]; - dc.varyingCoord = vs_dc_varyingCoord[0]; - dc.instanceIndex[0] = vs_dc_instanceIndexI0[0]; + dc.modelCoord = vs_interstageDrawingCoord0[0][0]; + dc.constantCoord = vs_interstageDrawingCoord0[0][1]; + dc.elementCoord = vs_interstageDrawingCoord0[0][2]; + dc.primitiveCoord = vs_interstageDrawingCoord0[0][3]; + dc.fvarCoord = vs_interstageDrawingCoord1[0][0]; + dc.shaderCoord = vs_interstageDrawingCoord1[0][1]; + dc.vertexCoord = vs_interstageDrawingCoord1[0][2]; + dc.topologyVisibilityCoord = vs_interstageDrawingCoord1[0][3]; + dc.varyingCoord = vs_interstageDrawingCoord2[0][0]; + dc.instanceIndex[0] = vs_interstageDrawingCoord2[0][1]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -3717,16 +3686,16 @@ void ProcessPrimvarsOut(int index) { ); hd_barycentricCoord = coords[index]; hd_drawingCoord dc = GetDrawingCoord(); - gs_dc_modelCoord = dc.modelCoord; - gs_dc_constantCoord = dc.constantCoord; - gs_dc_elementCoord = dc.elementCoord; - gs_dc_primitiveCoord = dc.primitiveCoord; - gs_dc_fvarCoord = dc.fvarCoord; - gs_dc_shaderCoord = dc.shaderCoord; - gs_dc_vertexCoord = dc.vertexCoord; - gs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - gs_dc_varyingCoord = dc.varyingCoord; - gs_dc_instanceIndexI0 = dc.instanceIndex[0]; + gs_interstageDrawingCoord0[0] = dc.modelCoord; + gs_interstageDrawingCoord0[1] = dc.constantCoord; + gs_interstageDrawingCoord0[2] = dc.elementCoord; + gs_interstageDrawingCoord0[3] = dc.primitiveCoord; + gs_interstageDrawingCoord1[0] = dc.fvarCoord; + gs_interstageDrawingCoord1[1] = dc.shaderCoord; + gs_interstageDrawingCoord1[2] = dc.vertexCoord; + gs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + gs_interstageDrawingCoord2[0] = dc.varyingCoord; + gs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = inPrimvars[index].points; outPrimvars.smoothNormals = inPrimvars[index].smoothNormals; outPrimvars.dispTextureCoord = HdGet_dispTextureCoord(index); @@ -4367,22 +4336,14 @@ in VertexData { } inData; layout (location = 0) out vec4 colorOut; in noperspective vec3 hd_barycentricCoord; +in flat ivec4 gs_interstageDrawingCoord0; +in flat ivec4 gs_interstageDrawingCoord1; +in flat ivec4 gs_interstageDrawingCoord2; in PrimvarData { vec3 points; vec3 smoothNormals; vec2 dispTextureCoord; } inPrimvars; -in flat int gs_dc_modelCoord; -in flat int gs_dc_constantCoord; -in flat int gs_dc_elementCoord; -in flat int gs_dc_primitiveCoord; -in flat int gs_dc_fvarCoord; -in flat int gs_dc_shaderCoord; -in flat int gs_dc_vertexCoord; -in flat int gs_dc_topologyVisibilityCoord; -in flat int gs_dc_varyingCoord; -in flat int gs_dc_instanceIndexI0; -in flat int gs_dc_instanceCoordsI0; layout(location = 4) uniform vec2 *dispTextureCoord; vec4 InterpolatePatchCoord(vec2 uv, ivec3 patchParam) { @@ -4441,16 +4402,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = gs_dc_modelCoord; - dc.constantCoord = gs_dc_constantCoord; - dc.elementCoord = gs_dc_elementCoord; - dc.primitiveCoord = gs_dc_primitiveCoord; - dc.fvarCoord = gs_dc_fvarCoord; - dc.shaderCoord = gs_dc_shaderCoord; - dc.vertexCoord = gs_dc_vertexCoord; - dc.topologyVisibilityCoord = gs_dc_topologyVisibilityCoord; - dc.varyingCoord = gs_dc_varyingCoord; - dc.instanceIndex[0] = gs_dc_instanceIndexI0; + dc.modelCoord = gs_interstageDrawingCoord0[0]; + dc.constantCoord = gs_interstageDrawingCoord0[1]; + dc.elementCoord = gs_interstageDrawingCoord0[2]; + dc.primitiveCoord = gs_interstageDrawingCoord0[3]; + dc.fvarCoord = gs_interstageDrawingCoord1[0]; + dc.shaderCoord = gs_interstageDrawingCoord1[1]; + dc.vertexCoord = gs_interstageDrawingCoord1[2]; + dc.topologyVisibilityCoord = gs_interstageDrawingCoord1[3]; + dc.varyingCoord = gs_interstageDrawingCoord2[0]; + dc.instanceIndex[0] = gs_interstageDrawingCoord2[1]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -4704,12 +4665,37 @@ vec4 ApplyColorOverridesPostLighting(vec4 color) -void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +void RenderColor(vec4 color) { colorOut = color; } + +void RenderId() +{ + // do nothing +} + + + +void RenderNeye(vec3 Neye) +{ + // do nothing +} + + + +void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +{ + // Write to any desired AOVs here. The render pass shader configuation + // decides if any of these are no-ops. + RenderColor(color); + RenderId(); + RenderNeye(Neye); +} + + #ifndef HD_HAS_integrateLights #define HD_HAS_integrateLights #endif diff --git a/pxr/imaging/hdSt/testenv/testHdStCodeGen_GL/baseline/codegen_points_bindless.out b/pxr/imaging/hdSt/testenv/testHdStCodeGen_GL/baseline/codegen_points_bindless.out deleted file mode 100644 index fe4aba326cf..00000000000 --- a/pxr/imaging/hdSt/testenv/testHdStCodeGen_GL/baseline/codegen_points_bindless.out +++ /dev/null @@ -1,1776 +0,0 @@ -------------------------------------------------------- --- glslfx version 0.1 -#import $TOOLS/hdSt/shaders/points.glslfx --- configuration -{"techniques": {"default": { -"vertexShader" : { "source" : ["Instancing.Transform", "Point.Vertex", "PointId.Vertex.PointParam", "Selection.DecodeUtils", "Selection.Vertex.PointSel"] } -, "fragmentShader" : { "source" : ["Fragment.CommonTerminals", "Fragment.Surface", "Fragment.NoScalarOverride", "Point.Fragment", "PointId.Fragment.PointParam"] } -}}} -------------------------------------------------------- -======================================================= - VERTEX SHADER -======================================================= -#version 450 -#extension GL_NV_shader_buffer_load : require -#extension GL_NV_gpu_shader5 : require -#extension GL_ARB_bindless_texture : require -#extension GL_ARB_shader_draw_parameters : require -int HgiGetBaseVertex() { - return gl_BaseVertexARB; -} -#define REF(space,type) inout type -#define FORWARD_DECL(func_decl) func_decl; -#define ATOMIC_LOAD(a) (a) -#define ATOMIC_STORE(a, v) (a) = (v) -#define ATOMIC_ADD(a, v) atomicAdd(a, v) -#define ATOMIC_EXCHANGE(a, v) atomicExchange(a, v) -#define ATOMIC_COMP_SWAP(a, expected, desired) atomicCompSwap(a, expected, desired) -#define atomic_int int -#define atomic_uint uint - -#define HGI_HAS_DOUBLE_TYPE 1 - - -struct hgi_ivec3 { int x, y, z; }; -struct hgi_vec3 { float x, y, z; }; -struct hgi_dvec3 { double x, y, z; }; -struct hgi_mat3 { float m00, m01, m02, - m10, m11, m12, - m20, m21, m22; }; -struct hgi_dmat3 { double m00, m01, m02, - m10, m11, m12, - m20, m21, m22; }; - - -// //////// Codegen Defines //////// -#define HD_SHADER_API 2 -#define MAT4 mat4 -// Alias hgi vec and matrix types to hd. -#define hd_ivec3 hgi_ivec3 -#define hd_vec3 hgi_vec3 -#define hd_dvec3 hgi_dvec3 -#define hd_mat3 hgi_mat3 -#define hd_dmat3 hgi_dmat3 - -ivec3 hd_ivec3_get(hd_ivec3 v) { return ivec3(v.x, v.y, v.z); } -ivec3 hd_ivec3_get(ivec3 v) { return v; } -vec3 hd_vec3_get(hd_vec3 v) { return vec3(v.x, v.y, v.z); } -vec3 hd_vec3_get(vec3 v) { return v; } -dvec3 hd_dvec3_get(hd_dvec3 v) { return dvec3(v.x, v.y, v.z); } -dvec3 hd_dvec3_get(dvec3 v) { return v; } -mat3 hd_mat3_get(hd_mat3 v) { return mat3(v.m00, v.m01, v.m02, - v.m10, v.m11, v.m12, - v.m20, v.m21, v.m22); } -mat3 hd_mat3_get(mat3 v) { return v; } -dmat3 hd_dmat3_get(hd_dmat3 v) { return dmat3(v.m00, v.m01, v.m02, - v.m10, v.m11, v.m12, - v.m20, v.m21, v.m22); } -dmat3 hd_dmat3_get(dmat3 v) { return v; } -hd_ivec3 hd_ivec3_set(hd_ivec3 v) { return v; } -hd_ivec3 hd_ivec3_set(ivec3 v) { return hd_ivec3(v.x, v.y, v.z); } -hd_vec3 hd_vec3_set(hd_vec3 v) { return v; } -hd_vec3 hd_vec3_set(vec3 v) { return hd_vec3(v.x, v.y, v.z); } -hd_dvec3 hd_dvec3_set(hd_dvec3 v) { return v; } -hd_dvec3 hd_dvec3_set(dvec3 v) { return hd_dvec3(v.x, v.y, v.z); } -hd_mat3 hd_mat3_set(hd_mat3 v) { return v; } -hd_mat3 hd_mat3_set(mat3 v) { return hd_mat3(v[0][0], v[0][1], v[0][2], - v[1][0], v[1][1], v[1][2], - v[2][0], v[2][1], v[2][2]); } -hd_dmat3 hd_dmat3_set(hd_dmat3 v) { return v; } -hd_dmat3 hd_dmat3_set(dmat3 v) { return hd_dmat3(v[0][0], v[0][1], v[0][2], - v[1][0], v[1][1], v[1][2], - v[2][0], v[2][1], v[2][2]); } -int hd_int_get(int v) { return v; } -int hd_int_get(ivec2 v) { return v.x; } -int hd_int_get(ivec3 v) { return v.x; } -int hd_int_get(ivec4 v) { return v.x; } -vec3 hd_sample_udim(vec2 v) { -vec2 vf = floor(v); -return vec3(v.x - vf.x, v.y - vf.y, clamp(vf.x, 0.0, 10.0) + 10.0 * vf.y); -} -vec4 hd_vec4_2_10_10_10_get(int v) { - ivec4 unpacked = ivec4((v & 0x3ff) << 22, (v & 0xffc00) << 12, - (v & 0x3ff00000) << 2, (v & 0xc0000000)); - return vec4(unpacked) / 2147483647.0; } -int hd_vec4_2_10_10_10_set(vec4 v) { - return ( (int(v.x * 511.0) & 0x3ff) | - ((int(v.y * 511.0) & 0x3ff) << 10) | - ((int(v.z * 511.0) & 0x3ff) << 20) | - ((int(v.w) & 0x1) << 30)); } -vec2 hd_half2_get(uint v) { - return unpackHalf2x16(v); } -uint hd_half2_set(vec2 v) { - return packHalf2x16(v); } -vec4 hd_half4_get(uvec2 v) { - return vec4(unpackHalf2x16(v.x), unpackHalf2x16(v.y)); } -uvec2 hd_half4_set(vec4 v) { - return uvec2(packHalf2x16(v.xy), packHalf2x16(v.zw)); } -#define HD_NUM_PRIMITIVE_VERTS 1 -#define HD_HAS_transform 1 -#define HD_HAS_transformInverse 1 -#define HD_HAS_color 1 -#define HD_HAS_primID 1 -#define HD_HAS_widths 1 -#define HD_INSTANCER_NUM_LEVELS 0 -#define HD_INSTANCE_INDEX_WIDTH 1 -#define HD_HAS_points 1 -#define HD_HAS_normals 1 - - -// //////// Global Includes //////// - -// //////// Global Macros //////// - -// //////// Global Structs //////// - -// //////// Global Member Declarations //////// -uint hd_VertexID = gl_VertexID; -uint hd_InstanceID = gl_InstanceID; -uint hd_BaseInstance = 0; - -// //////// Global Function Definitions //////// - - -// //////// Codegen Decl //////// -struct hd_drawingCoord { - int modelCoord; - int constantCoord; - int elementCoord; - int primitiveCoord; - int fvarCoord; - int shaderCoord; - int vertexCoord; - int topologyVisibilityCoord; - int varyingCoord; - int instanceIndex[HD_INSTANCE_INDEX_WIDTH]; - int instanceCoords[HD_INSTANCE_INDEX_WIDTH]; -}; -FORWARD_DECL(hd_drawingCoord GetDrawingCoord()); -FORWARD_DECL(int HgiGetBaseVertex()); -struct hd_instanceIndex { int indices[HD_INSTANCE_INDEX_WIDTH]; }; -struct ConstantData10 { - mat4 transform; - mat4 transformInverse; - vec4 color; - vec4 primID; - float widths; -}; -FORWARD_DECL(int GetElementID()); -FORWARD_DECL(int GetAggregatedElementID()); -FORWARD_DECL(int GetPrimitiveEdgeId()); -FORWARD_DECL(float GetSelectedEdgeOpacity()); -layout (location = 2) in ivec4 drawingCoord0; -layout (location = 3) in ivec4 drawingCoord1; -layout (location = 4) in ivec2 drawingCoord2; -layout (location = 0) in vec3 points; -layout (location = 1) in vec3 normals; -out flat int vs_dc_modelCoord; -out flat int vs_dc_constantCoord; -out flat int vs_dc_elementCoord; -out flat int vs_dc_primitiveCoord; -out flat int vs_dc_fvarCoord; -out flat int vs_dc_shaderCoord; -out flat int vs_dc_vertexCoord; -out flat int vs_dc_topologyVisibilityCoord; -out flat int vs_dc_varyingCoord; -out flat int vs_dc_instanceIndexI0; -out flat int vs_dc_instanceCoordsI0; -layout(location = 0) uniform ConstantData10 *constantPrimvars; -out VertexData { - vec4 Peye; -} outData; -out flat int vsPointId; -out PrimvarData { - vec3 points; - vec3 normals; -} outPrimvars; - -// //////// Codegen Accessors //////// -mat4 HdGet_transform(int localIndex) { - int index = GetDrawingCoord().constantCoord; - return mat4(constantPrimvars[index].transform); -} -mat4 HdGet_transform() { return HdGet_transform(0); } -mat4 HdGet_transformInverse(int localIndex) { - int index = GetDrawingCoord().constantCoord; - return mat4(constantPrimvars[index].transformInverse); -} -mat4 HdGet_transformInverse() { return HdGet_transformInverse(0); } -vec4 HdGet_color(int localIndex) { - int index = GetDrawingCoord().constantCoord; - return vec4(constantPrimvars[index].color); -} -vec4 HdGet_color() { return HdGet_color(0); } -float HdGetScalar_color(int localIndex) { return HdGet_color(localIndex).x; } -float HdGetScalar_color() { return HdGet_color(0).x; } -vec4 HdGet_primID(int localIndex) { - int index = GetDrawingCoord().constantCoord; - return vec4(constantPrimvars[index].primID); -} -vec4 HdGet_primID() { return HdGet_primID(0); } -float HdGetScalar_primID(int localIndex) { return HdGet_primID(localIndex).x; } -float HdGetScalar_primID() { return HdGet_primID(0).x; } -float HdGet_widths(int localIndex) { - int index = GetDrawingCoord().constantCoord; - return float(constantPrimvars[index].widths); -} -float HdGet_widths() { return HdGet_widths(0); } -float HdGetScalar_widths(int localIndex) { return HdGet_widths(localIndex); } -float HdGetScalar_widths() { return HdGet_widths(0); } - -// //////// Codegen VS Source //////// -#define HD_BINDLESS_BUFFERS_ENABLED -int GetBaseVertexOffset() { - return HgiGetBaseVertex(); -} -hd_instanceIndex GetInstanceIndex() { hd_instanceIndex r; r.indices[0] = 0; return r; } -hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = drawingCoord0.x; - dc.constantCoord = drawingCoord0.y; - dc.elementCoord = drawingCoord0.z; - dc.primitiveCoord = drawingCoord0.w; - dc.fvarCoord = drawingCoord1.x; - dc.shaderCoord = drawingCoord1.z; - dc.vertexCoord = drawingCoord1.w; - dc.topologyVisibilityCoord = drawingCoord2.x; - dc.varyingCoord = drawingCoord2.y; - hd_instanceIndex r = GetInstanceIndex(); - dc.instanceIndex[0] = r.indices[0]; - return dc; -} -vec3 HdGet_points(int localIndex) { return hd_vec3_get(points);} -vec3 HdGet_points() { return HdGet_points(0); } -float HdGetScalar_points(int localIndex) { return HdGet_points(localIndex).x; } -float HdGetScalar_points() { return HdGet_points(0).x; } -vec3 HdGet_normals(int localIndex) { return hd_vec3_get(normals);} -vec3 HdGet_normals() { return HdGet_normals(0); } -float HdGetScalar_normals(int localIndex) { return HdGet_normals(localIndex).x; } -float HdGetScalar_normals() { return HdGet_normals(0).x; } - -// //////// Codegen Proc VS //////// -void ProcessPrimvarsIn() { - hd_drawingCoord dc = GetDrawingCoord(); - vs_dc_modelCoord = dc.modelCoord; - vs_dc_constantCoord = dc.constantCoord; - vs_dc_elementCoord = dc.elementCoord; - vs_dc_primitiveCoord = dc.primitiveCoord; - vs_dc_fvarCoord = dc.fvarCoord; - vs_dc_shaderCoord = dc.shaderCoord; - vs_dc_vertexCoord = dc.vertexCoord; - vs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - vs_dc_varyingCoord = dc.varyingCoord; - vs_dc_instanceIndexI0 = dc.instanceIndex[0]; - outPrimvars.points = points; - outPrimvars.normals = normals; -} - -// --------------------------------------------------------------------------- -// global defines -// --------------------------------------------------------------------------- -// codeGen can override this range (currently not). -// quadro 4000's max is 189. -#ifndef HD_GL_POINT_SIZE_MAX -#define HD_GL_POINT_SIZE_MAX 100.0 -#endif -#ifndef HD_GL_POINT_SIZE_MIN -#define HD_GL_POINT_SIZE_MIN .45 -#endif - -// --------------------------------------------------------------------------- -// render pass states -// --------------------------------------------------------------------------- - -MAT4 GetWorldToViewMatrix() { -#if defined(HD_HAS_worldToViewMatrix) - return MAT4(HdGet_worldToViewMatrix()); -#else - return MAT4(1); -#endif -} -MAT4 GetWorldToViewInverseMatrix() { -#if defined(HD_HAS_worldToViewInverseMatrix) - return MAT4(HdGet_worldToViewInverseMatrix()); -#else - return MAT4(1); -#endif -} -MAT4 GetProjectionMatrix() { -#if defined(HD_HAS_projectionMatrix) - return MAT4(HdGet_projectionMatrix()); -#else - return MAT4(1); -#endif -} -vec3 GetPositionInWorldSpace(vec3 windowRelativeCoord) -{ -#if defined(HD_HAS_imageToWorldMatrix) - vec4 pImage = vec4(windowRelativeCoord, 1.0); - vec4 pWorld = vec4(HdGet_imageToWorldMatrix() * pImage); - return (pWorld / pWorld.w).xyz; -#else - return windowRelativeCoord; -#endif -} -float GetLightingBlendAmount() { -#if defined(HD_HAS_lightingBlendAmount) - return HdGet_lightingBlendAmount(); -#else - return 1; -#endif -} -vec4 GetViewport() { -#if defined(HD_HAS_viewport) - return HdGet_viewport(); -#else - return vec4(0,0,1,1); -#endif -} -float GetTessLevel() { -#if defined(HD_HAS_tessLevel) - return HdGet_tessLevel(); -#else - return 1; -#endif -} -float GetPointSize() { -#if defined(HD_HAS_pointSize) - return HdGet_pointSize(); -#else - return 3.0; -#endif -} -float GetPointSelectedSize() { -#if defined(HD_HAS_pointSelectedSize) - return HdGet_pointSelectedSize(); -#else - return 5.0; -#endif -} -vec4 GetWireframeColor() { -// Individual prims can specify an alternative wireframe color -// to one specified in the render pass. This is used in cases were -// there is not enough contrast with the normal one. -#if defined(HD_HAS_overrideWireframeColor) - return HdGet_overrideWireframeColor(); -#elif defined(HD_HAS_wireframeColor) - return HdGet_wireframeColor(); -#else - return vec4(0,0,0,0); -#endif -} -vec4 GetMaskColor() { -#if defined(HD_HAS_maskColor) - return HdGet_maskColor(); -#else - return vec4(0.5,0,0,1); -#endif -} -vec4 GetIndicatorColor() { -#if defined(HD_HAS_indicatorColor) - return HdGet_indicatorColor(); -#else - return vec4(0,0.5,0,1); -#endif -} - -bool ShouldDiscardByAlpha(vec4 color) -{ -#if defined(HD_HAS_alphaThreshold) - float alphaThreshold = HdGet_alphaThreshold(); -#else - float alphaThreshold = 0; -#endif - return (color.a < alphaThreshold); -} - -vec2 ApplyAxisAlignedAffineTransform(vec4 t, vec2 pt) -{ - return t.xy * pt + t.zw; -} - - - -void ApplyClipPlanes(vec4 Peye) -{ -#if defined(HD_HAS_numClipPlanes) -#if defined(HD_HAS_clipPlanes) - for (int i=0; i> 1; // bits 31:1 -} - -// --------- subprim decoding ---------- -// Each subprims offsets' buffer encoding is: -// [subprim-type][min][max][ selOffsets ] -// <----------3 ----------><--- max - min + 1 --> -struct SubprimHeader { - int type; - int min; - int max; -}; -SubprimHeader DecodeSubprimHeader(int offset) -{ - SubprimHeader header; - header.type = HdGet_hdxSelectionBuffer(offset ); - header.min = HdGet_hdxSelectionBuffer(offset + 1); - header.max = HdGet_hdxSelectionBuffer(offset + 2); - return header; -} - -bool IsSubprimSelected(int id, int min, int max, int headerStart, - REF(thread, int) nextSubprimOffset) -{ - const int SUBPRIM_SELOFFSETS_HEADER_SIZE = 3; - - nextSubprimOffset = 0; // initialize - bool isSelected = false; - - if (id >= min && id < max) { - int netSubprimIndex = - headerStart + SUBPRIM_SELOFFSETS_HEADER_SIZE + id - min; - int selOffset = HdGet_hdxSelectionBuffer(netSubprimIndex); - - DecodeSelOffset(selOffset, /*out*/isSelected, /*out*/nextSubprimOffset); - } else { - // The subprim id does not fall in the selected id range, so the subprim - // in question isn't selected. However, we can still have other - // subprim(s) selected. To get the offset to jump to, we mimic decoding - // the "min" subprim id. - int minSubprimIndex = headerStart + SUBPRIM_SELOFFSETS_HEADER_SIZE; - DecodeSelOffset(HdGet_hdxSelectionBuffer(minSubprimIndex), - /*out*/isSelected, /*out*/nextSubprimOffset); - isSelected = false; - } - - return isSelected; -} -#endif // HD_HAS_hdxSelectionBuffer - -// Keep the result struct definition outside guards. -struct SubprimSelectionResult { - bool elementSelected; - bool elementEdgeSelected; - bool edgeSelected; - bool pointSelected; - int pointColorId; -}; - -SubprimSelectionResult InitSubprimSelectionResult( - bool elementSelected, - bool elementEdgeSelected, - bool edgeSelected, - bool pointSelected, - int pointColorId) -{ - SubprimSelectionResult res; - - res.elementSelected = elementSelected; - res.elementEdgeSelected = elementEdgeSelected; - res.edgeSelected = edgeSelected; - res.pointSelected = pointSelected; - res.pointColorId = pointColorId; - - return res; -} - -bool IsAnySubprimSelected(SubprimSelectionResult s) -{ - return (s.elementSelected || - s.elementEdgeSelected || - s.edgeSelected || - s.pointSelected); -} - -bool HasCustomizedPointColor(SubprimSelectionResult s) -{ - // Use -1 to encode selected points that don't have a custom point color. - return (s.pointColorId != -1); -} - -#if defined(HD_HAS_hdxSelectionBuffer) -// Note: These should match the SubprimType enum in hdx/SelectionTracker.cpp -#define SUBPRIM_TYPE_ELEMENT 0 -#define SUBPRIM_TYPE_ELEMENT_EDGE 1 -#define SUBPRIM_TYPE_EDGE 2 -#define SUBPRIM_TYPE_POINT 3 -#define SUBPRIM_TYPE_INSTANCE 4 - -SubprimSelectionResult GetSubprimSel(int offset, - int elementId, int edgeId, int pointId) -{ - SubprimSelectionResult s = - InitSubprimSelectionResult(false, false, false, false, 0); - - int nextSubprimOffset = 0; - SubprimHeader header = DecodeSubprimHeader(offset); - - if (header.type == SUBPRIM_TYPE_ELEMENT) { - s.elementSelected = - IsSubprimSelected(elementId, header.min, header.max, - offset, /*out*/nextSubprimOffset); - - if (nextSubprimOffset != 0) { - // fragment has additional subprim(s) selected. update header. - header = DecodeSubprimHeader(nextSubprimOffset); - offset = nextSubprimOffset; - } - } - - if (header.type == SUBPRIM_TYPE_ELEMENT_EDGE) { - s.elementEdgeSelected = - IsSubprimSelected(edgeId, header.min, header.max, - offset, /*out*/nextSubprimOffset); - - if (nextSubprimOffset != 0) { - // fragment has additional subprim(s) selected. update header. - header = DecodeSubprimHeader(nextSubprimOffset); - offset = nextSubprimOffset; - } - } - if (header.type == SUBPRIM_TYPE_EDGE) { - s.edgeSelected = - IsSubprimSelected(edgeId, header.min, header.max, - offset, /*out*/nextSubprimOffset); - - if (nextSubprimOffset != 0) { - // fragment has points selected. update header. - header = DecodeSubprimHeader(nextSubprimOffset); - offset = nextSubprimOffset; - } - } - - if (header.type == SUBPRIM_TYPE_POINT) { - s.pointSelected = - IsSubprimSelected(pointId, header.min, header.max, - offset, /*unused*/nextSubprimOffset); - // For points alone, since there isn't any subprim to follow it, the - // offset field is overriden to represent the index into the - // selectedPointColors buffer to support customized coloring of a set of - // selected points. - s.pointColorId = nextSubprimOffset; - } - - return s; -} - -// --------- instance decoding ---------- -bool IsInstanceSelected(int offset, REF(thread, int) nextOffset) -{ - // If we don't find an instance subprim block, pass the same offset to - // GetSubprimSel. - nextOffset = offset; - bool sel = false; - - int instanceId = GetDrawingCoord().instanceIndex[0]; - - SubprimHeader header = DecodeSubprimHeader(offset); - if (header.type == SUBPRIM_TYPE_INSTANCE) { - sel = - IsSubprimSelected(instanceId, header.min, header.max, - offset, /*out*/nextOffset); - } - - return sel; -} -#endif // HD_HAS_hdxSelectionBuffer - -// --------- selection buffer decoding entry point ---------- -struct SelectionResult { - bool primOrInstanceSel; - SubprimSelectionResult subprimSel; -}; - -SelectionResult InitSelectionResult( - bool primOrInstanceSel, - bool elementSelected, - bool elementEdgeSelected, - bool edgeSelected, - bool pointSelected, - int pointColorId) -{ - SelectionResult res; - - res.primOrInstanceSel = primOrInstanceSel; - res.subprimSel = InitSubprimSelectionResult( - elementSelected, - elementEdgeSelected, - edgeSelected, - pointSelected, - pointColorId); - - return res; -} - - -// Decodes the selection buffer encoding scheme for a given mode, and returns -// the selection result. -SelectionResult GetSelectionResult(int mode, - int elementId, int edgeId, int pointId) -{ - SelectionResult res = - InitSelectionResult(false, false, false, false, false, 0); - -#if defined(HD_HAS_hdxSelectionBuffer) - // The hdxSelectionBuffer layout is: - // [#modes] [per-mode offset] [data mode0] ... [data modeM] - // [---------header---------] - // Each mode's data is laid out as: - // [ prims | points | edges | elementEdges | elements | instances ] - // <----------- subprims -------------------> - // <------------------ per prim ------------------------> - // See hdx/SelectionTracker.cpp for details on the encoding scheme. - int modeOffset = GetIndexOffsetForHighlightMode(mode); - if (!HighlightModeHasSelection(modeOffset)) { - // highlight mode has no selected objects (prims/instances/elements) - return res; - } - - const int PRIM_SELOFFSETS_HEADER_SIZE = 2; - const int primId = HdGet_primID(); - int smin = HdGet_hdxSelectionBuffer(modeOffset); - int smax = HdGet_hdxSelectionBuffer(modeOffset + 1); - - if (primId >= smin && primId < smax) { - int offset = modeOffset + PRIM_SELOFFSETS_HEADER_SIZE + primId - smin; - int nextOffset = 0; - bool sel = false; - DecodeSelOffset(HdGet_hdxSelectionBuffer(offset), - /*out*/sel, /*out*/nextOffset); - - // At this point, sel indicates whether the fragment corresponds to - // a prim that needs to be fully highlighted, while a non-zero - // nextOffset indicates whether additional decoding may be done. - - // We don't currently differentiate between prim, instance and - // subprim selection highlighting (i.e., visually, they look the - // same), and thus can skip additional decoding if sel is true. - // We choose not to, for ease of future customization. - if (nextOffset != 0) { - // check if instance (or) subprim(s) are selected - offset = nextOffset; - sel = sel || IsInstanceSelected(offset, /*out*/nextOffset); - - if (nextOffset != 0) { - res.subprimSel = - GetSubprimSel(nextOffset, elementId, edgeId, pointId); - } - } - res.primOrInstanceSel = sel; - } -#endif // HD_HAS_hdxSelectionBuffer - - return res; -} - -// Returns the logical OR of the inputs -SelectionResult -_CombineWithOr(SelectionResult a, SelectionResult b) -{ - SelectionResult res = - InitSelectionResult(false, false, false, false, false, 0); - - res.primOrInstanceSel = a.primOrInstanceSel || b.primOrInstanceSel; - res.subprimSel.elementSelected = a.subprimSel.elementSelected || - b.subprimSel.elementSelected; - res.subprimSel.elementEdgeSelected = a.subprimSel.elementEdgeSelected || - b.subprimSel.elementEdgeSelected; - res.subprimSel.edgeSelected = a.subprimSel.edgeSelected || - b.subprimSel.edgeSelected; - res.subprimSel.pointSelected = a.subprimSel.pointSelected || - b.subprimSel.pointSelected; - // pointColorIndex is ignored. - return res; -} - -// Returns the net selection result aggregating the result of each selection -// mode. -SelectionResult GetNetSelectionResult(int elementId, int edgeId, int pointId) -{ - SelectionResult netResult = - InitSelectionResult(false, false, false, false, false, 0); - -#if defined(HD_HAS_hdxSelectionBuffer) - const int numSelectionModes = GetNumSelectionHighlightModes(); - for (int mode = 0; mode < numSelectionModes; mode++) { - SelectionResult modeResult = - GetSelectionResult(mode, elementId, edgeId, pointId); - netResult = _CombineWithOr(modeResult, netResult); - } -#endif - return netResult; -} - - -// Mixin for use in the vertex shader stage. -// Decodes the selection buffer to find out if the current vertex (point) is -// selected. This is called from hdSt/shaders/pointId.glslfx -bool IsPointSelected(int pointId) -{ - bool sel = false; - #if defined(HD_HAS_hdxSelectionBuffer) - const int numSelectionModes = GetNumSelectionHighlightModes(); - for (int mode = 0; mode < numSelectionModes; mode++) { - // At the VS stage, we don't carry enough state to determine the - // elementId and edgeId. So, use fallback values instead. - SelectionResult res = - GetSelectionResult(mode, /*elementId*/-1, /*edgeId*/-1, pointId); - if (res.subprimSel.pointSelected && - !HasCustomizedPointColor(res.subprimSel)) { - sel = true; - break; - } - } // for each highlight mode - #endif - return sel; -} - - -======================================================= - TESS CONTROL SHADER -======================================================= -======================================================= - TESS EVAL SHADER -======================================================= -======================================================= - GEOMETRY SHADER -======================================================= -======================================================= - FRAGMENT SHADER -======================================================= -#version 450 -#extension GL_NV_shader_buffer_load : require -#extension GL_NV_gpu_shader5 : require -#extension GL_ARB_bindless_texture : require -#define REF(space,type) inout type -#define FORWARD_DECL(func_decl) func_decl; -#define ATOMIC_LOAD(a) (a) -#define ATOMIC_STORE(a, v) (a) = (v) -#define ATOMIC_ADD(a, v) atomicAdd(a, v) -#define ATOMIC_EXCHANGE(a, v) atomicExchange(a, v) -#define ATOMIC_COMP_SWAP(a, expected, desired) atomicCompSwap(a, expected, desired) -#define atomic_int int -#define atomic_uint uint - -#define HGI_HAS_DOUBLE_TYPE 1 - - -struct hgi_ivec3 { int x, y, z; }; -struct hgi_vec3 { float x, y, z; }; -struct hgi_dvec3 { double x, y, z; }; -struct hgi_mat3 { float m00, m01, m02, - m10, m11, m12, - m20, m21, m22; }; -struct hgi_dmat3 { double m00, m01, m02, - m10, m11, m12, - m20, m21, m22; }; - - - -// //////// Global Includes //////// - -// //////// Global Macros //////// - -// //////// Global Structs //////// - -// //////// Global Member Declarations //////// - -// //////// Global Function Definitions //////// - - -// //////// Codegen Defines //////// -#define HD_SHADER_API 2 -#define MAT4 mat4 -// Alias hgi vec and matrix types to hd. -#define hd_ivec3 hgi_ivec3 -#define hd_vec3 hgi_vec3 -#define hd_dvec3 hgi_dvec3 -#define hd_mat3 hgi_mat3 -#define hd_dmat3 hgi_dmat3 - -ivec3 hd_ivec3_get(hd_ivec3 v) { return ivec3(v.x, v.y, v.z); } -ivec3 hd_ivec3_get(ivec3 v) { return v; } -vec3 hd_vec3_get(hd_vec3 v) { return vec3(v.x, v.y, v.z); } -vec3 hd_vec3_get(vec3 v) { return v; } -dvec3 hd_dvec3_get(hd_dvec3 v) { return dvec3(v.x, v.y, v.z); } -dvec3 hd_dvec3_get(dvec3 v) { return v; } -mat3 hd_mat3_get(hd_mat3 v) { return mat3(v.m00, v.m01, v.m02, - v.m10, v.m11, v.m12, - v.m20, v.m21, v.m22); } -mat3 hd_mat3_get(mat3 v) { return v; } -dmat3 hd_dmat3_get(hd_dmat3 v) { return dmat3(v.m00, v.m01, v.m02, - v.m10, v.m11, v.m12, - v.m20, v.m21, v.m22); } -dmat3 hd_dmat3_get(dmat3 v) { return v; } -hd_ivec3 hd_ivec3_set(hd_ivec3 v) { return v; } -hd_ivec3 hd_ivec3_set(ivec3 v) { return hd_ivec3(v.x, v.y, v.z); } -hd_vec3 hd_vec3_set(hd_vec3 v) { return v; } -hd_vec3 hd_vec3_set(vec3 v) { return hd_vec3(v.x, v.y, v.z); } -hd_dvec3 hd_dvec3_set(hd_dvec3 v) { return v; } -hd_dvec3 hd_dvec3_set(dvec3 v) { return hd_dvec3(v.x, v.y, v.z); } -hd_mat3 hd_mat3_set(hd_mat3 v) { return v; } -hd_mat3 hd_mat3_set(mat3 v) { return hd_mat3(v[0][0], v[0][1], v[0][2], - v[1][0], v[1][1], v[1][2], - v[2][0], v[2][1], v[2][2]); } -hd_dmat3 hd_dmat3_set(hd_dmat3 v) { return v; } -hd_dmat3 hd_dmat3_set(dmat3 v) { return hd_dmat3(v[0][0], v[0][1], v[0][2], - v[1][0], v[1][1], v[1][2], - v[2][0], v[2][1], v[2][2]); } -int hd_int_get(int v) { return v; } -int hd_int_get(ivec2 v) { return v.x; } -int hd_int_get(ivec3 v) { return v.x; } -int hd_int_get(ivec4 v) { return v.x; } -vec3 hd_sample_udim(vec2 v) { -vec2 vf = floor(v); -return vec3(v.x - vf.x, v.y - vf.y, clamp(vf.x, 0.0, 10.0) + 10.0 * vf.y); -} -vec4 hd_vec4_2_10_10_10_get(int v) { - ivec4 unpacked = ivec4((v & 0x3ff) << 22, (v & 0xffc00) << 12, - (v & 0x3ff00000) << 2, (v & 0xc0000000)); - return vec4(unpacked) / 2147483647.0; } -int hd_vec4_2_10_10_10_set(vec4 v) { - return ( (int(v.x * 511.0) & 0x3ff) | - ((int(v.y * 511.0) & 0x3ff) << 10) | - ((int(v.z * 511.0) & 0x3ff) << 20) | - ((int(v.w) & 0x1) << 30)); } -vec2 hd_half2_get(uint v) { - return unpackHalf2x16(v); } -uint hd_half2_set(vec2 v) { - return packHalf2x16(v); } -vec4 hd_half4_get(uvec2 v) { - return vec4(unpackHalf2x16(v.x), unpackHalf2x16(v.y)); } -uvec2 hd_half4_set(vec4 v) { - return uvec2(packHalf2x16(v.xy), packHalf2x16(v.zw)); } -#define HD_NUM_PRIMITIVE_VERTS 1 -#define HD_HAS_transform 1 -#define HD_HAS_transformInverse 1 -#define HD_HAS_color 1 -#define HD_HAS_primID 1 -#define HD_HAS_widths 1 -#define HD_INSTANCER_NUM_LEVELS 0 -#define HD_INSTANCE_INDEX_WIDTH 1 -#define HD_HAS_points 1 -#define HD_HAS_normals 1 - -// //////// Codegen Decl //////// -struct hd_drawingCoord { - int modelCoord; - int constantCoord; - int elementCoord; - int primitiveCoord; - int fvarCoord; - int shaderCoord; - int vertexCoord; - int topologyVisibilityCoord; - int varyingCoord; - int instanceIndex[HD_INSTANCE_INDEX_WIDTH]; - int instanceCoords[HD_INSTANCE_INDEX_WIDTH]; -}; -FORWARD_DECL(hd_drawingCoord GetDrawingCoord()); -FORWARD_DECL(int HgiGetBaseVertex()); -struct hd_instanceIndex { int indices[HD_INSTANCE_INDEX_WIDTH]; }; -struct ConstantData10 { - mat4 transform; - mat4 transformInverse; - vec4 color; - vec4 primID; - float widths; -}; -FORWARD_DECL(int GetElementID()); -FORWARD_DECL(int GetAggregatedElementID()); -FORWARD_DECL(int GetPrimitiveEdgeId()); -FORWARD_DECL(float GetSelectedEdgeOpacity()); -layout(location = 0) uniform ConstantData10 *constantPrimvars; -in VertexData { - vec4 Peye; -} inData; -in flat int vsPointId; -layout (location = 0) out vec4 colorOut; -in PrimvarData { - vec3 points; - vec3 normals; -} inPrimvars; -in flat int vs_dc_modelCoord; -in flat int vs_dc_constantCoord; -in flat int vs_dc_elementCoord; -in flat int vs_dc_primitiveCoord; -in flat int vs_dc_fvarCoord; -in flat int vs_dc_shaderCoord; -in flat int vs_dc_vertexCoord; -in flat int vs_dc_topologyVisibilityCoord; -in flat int vs_dc_varyingCoord; -in flat int vs_dc_instanceIndexI0; -in flat int vs_dc_instanceCoordsI0; - -// //////// Codegen Accessors //////// -mat4 HdGet_transform(int localIndex) { - int index = GetDrawingCoord().constantCoord; - return mat4(constantPrimvars[index].transform); -} -mat4 HdGet_transform() { return HdGet_transform(0); } -mat4 HdGet_transformInverse(int localIndex) { - int index = GetDrawingCoord().constantCoord; - return mat4(constantPrimvars[index].transformInverse); -} -mat4 HdGet_transformInverse() { return HdGet_transformInverse(0); } -vec4 HdGet_color(int localIndex) { - int index = GetDrawingCoord().constantCoord; - return vec4(constantPrimvars[index].color); -} -vec4 HdGet_color() { return HdGet_color(0); } -float HdGetScalar_color(int localIndex) { return HdGet_color(localIndex).x; } -float HdGetScalar_color() { return HdGet_color(0).x; } -vec4 HdGet_primID(int localIndex) { - int index = GetDrawingCoord().constantCoord; - return vec4(constantPrimvars[index].primID); -} -vec4 HdGet_primID() { return HdGet_primID(0); } -float HdGetScalar_primID(int localIndex) { return HdGet_primID(localIndex).x; } -float HdGetScalar_primID() { return HdGet_primID(0).x; } -float HdGet_widths(int localIndex) { - int index = GetDrawingCoord().constantCoord; - return float(constantPrimvars[index].widths); -} -float HdGet_widths() { return HdGet_widths(0); } -float HdGetScalar_widths(int localIndex) { return HdGet_widths(localIndex); } -float HdGetScalar_widths() { return HdGet_widths(0); } - -// //////// Codegen FS Source //////// -#define HD_SHADER_SUPPORTS_DOUBLE_PRECISION -#define HD_MINUS_ONE_TO_ONE_DEPTH_RANGE -vec3 GetBarycentricCoord() { - return vec3(0); -} -int GetPrimitiveID() { - return gl_PrimitiveID; -} -int GetPrimitiveIndex() { - return GetDrawingCoord().primitiveCoord + GetPrimitiveID(); -} -hd_drawingCoord GetDrawingCoord() { - hd_drawingCoord dc; - dc.modelCoord = vs_dc_modelCoord; - dc.constantCoord = vs_dc_constantCoord; - dc.elementCoord = vs_dc_elementCoord; - dc.primitiveCoord = vs_dc_primitiveCoord; - dc.fvarCoord = vs_dc_fvarCoord; - dc.shaderCoord = vs_dc_shaderCoord; - dc.vertexCoord = vs_dc_vertexCoord; - dc.topologyVisibilityCoord = vs_dc_topologyVisibilityCoord; - dc.varyingCoord = vs_dc_varyingCoord; - dc.instanceIndex[0] = vs_dc_instanceIndexI0; - return dc; -} -int GetElementID() { - return -1; -} -int GetAggregatedElementID() { - return GetElementID(); -} -int GetEdgeFlag() { - return 0; -} -ivec3 GetPatchParam() { - return ivec3(0, 0, 0); -} -int GetFVarIndex(int localIndex) { - return 0; -} -int GetAuthoredEdgeId(int primitiveEdgeId) { - return -1; -} -int GetPrimitiveEdgeId() { - return -1; -} -float GetSelectedEdgeOpacity() { - return 0.0; -} -bool SelectWireframeFaceEdges() { - return false; -} -vec3 HdGet_points(int localIndex) { return vec3(inPrimvars.points);} -vec3 HdGet_points() { return HdGet_points(0); } -float HdGetScalar_points(int localIndex) { return HdGet_points(localIndex).x; } -float HdGetScalar_points() { return HdGet_points(0).x; } -vec3 HdGet_normals(int localIndex) { return vec3(inPrimvars.normals);} -vec3 HdGet_normals() { return HdGet_normals(0); } -float HdGetScalar_normals(int localIndex) { return HdGet_normals(localIndex).x; } -float HdGetScalar_normals() { return HdGet_normals(0).x; } -FORWARD_DECL(vec4 GetPatchCoord(int index)); -void ProcessSamplingTransforms(MAT4 instanceModelViewInverse) { -} - -// --------------------------------------------------------------------------- -// global defines -// --------------------------------------------------------------------------- -// codeGen can override this range (currently not). -// quadro 4000's max is 189. -#ifndef HD_GL_POINT_SIZE_MAX -#define HD_GL_POINT_SIZE_MAX 100.0 -#endif -#ifndef HD_GL_POINT_SIZE_MIN -#define HD_GL_POINT_SIZE_MIN .45 -#endif - -// --------------------------------------------------------------------------- -// render pass states -// --------------------------------------------------------------------------- - -MAT4 GetWorldToViewMatrix() { -#if defined(HD_HAS_worldToViewMatrix) - return MAT4(HdGet_worldToViewMatrix()); -#else - return MAT4(1); -#endif -} -MAT4 GetWorldToViewInverseMatrix() { -#if defined(HD_HAS_worldToViewInverseMatrix) - return MAT4(HdGet_worldToViewInverseMatrix()); -#else - return MAT4(1); -#endif -} -MAT4 GetProjectionMatrix() { -#if defined(HD_HAS_projectionMatrix) - return MAT4(HdGet_projectionMatrix()); -#else - return MAT4(1); -#endif -} -vec3 GetPositionInWorldSpace(vec3 windowRelativeCoord) -{ -#if defined(HD_HAS_imageToWorldMatrix) - vec4 pImage = vec4(windowRelativeCoord, 1.0); - vec4 pWorld = vec4(HdGet_imageToWorldMatrix() * pImage); - return (pWorld / pWorld.w).xyz; -#else - return windowRelativeCoord; -#endif -} -float GetLightingBlendAmount() { -#if defined(HD_HAS_lightingBlendAmount) - return HdGet_lightingBlendAmount(); -#else - return 1; -#endif -} -vec4 GetViewport() { -#if defined(HD_HAS_viewport) - return HdGet_viewport(); -#else - return vec4(0,0,1,1); -#endif -} -float GetTessLevel() { -#if defined(HD_HAS_tessLevel) - return HdGet_tessLevel(); -#else - return 1; -#endif -} -float GetPointSize() { -#if defined(HD_HAS_pointSize) - return HdGet_pointSize(); -#else - return 3.0; -#endif -} -float GetPointSelectedSize() { -#if defined(HD_HAS_pointSelectedSize) - return HdGet_pointSelectedSize(); -#else - return 5.0; -#endif -} -vec4 GetWireframeColor() { -// Individual prims can specify an alternative wireframe color -// to one specified in the render pass. This is used in cases were -// there is not enough contrast with the normal one. -#if defined(HD_HAS_overrideWireframeColor) - return HdGet_overrideWireframeColor(); -#elif defined(HD_HAS_wireframeColor) - return HdGet_wireframeColor(); -#else - return vec4(0,0,0,0); -#endif -} -vec4 GetMaskColor() { -#if defined(HD_HAS_maskColor) - return HdGet_maskColor(); -#else - return vec4(0.5,0,0,1); -#endif -} -vec4 GetIndicatorColor() { -#if defined(HD_HAS_indicatorColor) - return HdGet_indicatorColor(); -#else - return vec4(0,0.5,0,1); -#endif -} - -bool ShouldDiscardByAlpha(vec4 color) -{ -#if defined(HD_HAS_alphaThreshold) - float alphaThreshold = HdGet_alphaThreshold(); -#else - float alphaThreshold = 0; -#endif - return (color.a < alphaThreshold); -} - -vec2 ApplyAxisAlignedAffineTransform(vec4 t, vec2 pt) -{ - return t.xy * pt + t.zw; -} - - - -vec2 HorizontallyNormalizedFilmbackCoordinates() -{ - const vec4 transform = -#ifdef HD_HAS_imageToHorizontallyNormalizedFilmback - HdGet_imageToHorizontallyNormalizedFilmback(); -#else - vec4(vec2(1.0), vec2(0.0)); -#endif - return ApplyAxisAlignedAffineTransform(transform, gl_FragCoord.xy); -} - - - -vec4 ApplySelectionColor(vec4 color) -{ - return color; -} - - - -// Forward declare selection functionality. -// XXX: Currently, the non-empty implementation of this is in hdx. -FORWARD_DECL(vec4 ApplySelectionColor(vec4 color)); - -// XXX: Make sure to update hdx/shaders/renderPass.glslfx when editing these -// color override methods, since they're currently duplicated. This is because -// we don't have a mixin token for color overrides in a render pass yet. -vec4 ApplyColorOverrides(vec4 color) -{ -#if defined(HD_HAS_overrideColor) - // Mix in override color - vec4 overrideColor = HdGet_overrideColor(); - color.rgb = mix(color.rgb, overrideColor.rgb, overrideColor.a); -#endif - return ApplySelectionColor(color); -} - -vec3 ApplyMaskColor(vec3 color, float weight, vec4 maskColor) -{ - float strength = maskColor.a * clamp(weight, 0.0, 1.0); - return mix(color, maskColor.rgb, strength); -} - -vec4 ApplyColorOverridesPostLighting(vec4 color) -{ - #if defined(HD_HAS_maskWeight) - float maskWeight = HdGet_maskWeight(); - vec4 maskColor = GetMaskColor(); - color.rgb = ApplyMaskColor(color.rgb, maskWeight, maskColor); - #endif - #if defined(HD_HAS_indicatorWeight) - float indicatorWeight = HdGet_indicatorWeight(); - vec4 indicatorColor = GetIndicatorColor(); - color.rgb = ApplyMaskColor(color.rgb, indicatorWeight, indicatorColor); - #endif - return color; -} - - - -void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) -{ - colorOut = color; -} - - -#ifndef HD_HAS_integrateLights -#define HD_HAS_integrateLights -#endif - -struct LightingContribution { - vec3 diffuse; -}; - -struct LightingInterfaceProperties { - float unused; -}; - -LightingContribution -integrateLightsDefault(vec4 Peye, vec3 Neye, LightingInterfaceProperties props) -{ - vec3 n = normalize(Neye); - - LightingContribution result; - result.diffuse = vec3(dot(n, vec3(0,0,1))); - - return result; -} - -LightingContribution -integrateLightsConstant(vec4 Peye, vec3 Neye, LightingInterfaceProperties props) -{ - LightingContribution result; - //pefectly diffuse white hemisphere contribution - result.diffuse = vec3(1); - - return result; -} - - - -FORWARD_DECL( - LightingContribution integrateLights(vec4 Peye, vec3 Neye, - LightingInterfaceProperties props)); - -vec3 FallbackLighting(in vec3 Peye, in vec3 Neye, in vec3 color) -{ - LightingInterfaceProperties props; - LightingContribution light = integrateLights(vec4(Peye, 1), Neye, props); - return color * light.diffuse; -} - - -vec4 surfaceShader(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) -{ - // lighting - color.rgb = FallbackLighting(Peye.xyz, Neye, color.rgb); - return color; -} - - -struct ReprStyle -{ - vec4 color; - bool usePrimvarColor; - bool usePrimvarAlpha; - bool applyColorOverride; - bool useSurfaceShaderColor; - bool useSurfaceShaderAlpha; -}; - -struct ScalarOverride -{ - bool enabled; - vec3 color; -}; - -FORWARD_DECL(ReprStyle GetReprStyle()); -FORWARD_DECL(ScalarOverride GetScalarOverride()); -FORWARD_DECL( - vec4 surfaceShader(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord)); -FORWARD_DECL(vec4 postSurfaceShader(vec4 Peye, vec3 Neye, vec4 color)); - -vec4 ShadingTerminal(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) -{ - ReprStyle reprStyle = GetReprStyle(); - - // Apply scalar override. - ScalarOverride scalarOverride = GetScalarOverride(); - if (scalarOverride.enabled) { - vec4 result; - - result.rgb = scalarOverride.color; - result.a = reprStyle.usePrimvarAlpha ? color.a: reprStyle.color.a; - - vec4 colorOverride = ApplyColorOverrides(result); - result = reprStyle.applyColorOverride ? colorOverride : result; - - return result; - } - - // Draw mode can override face color - vec4 reprColor; - - reprColor.rgb = reprStyle.usePrimvarColor ? color.rgb : reprStyle.color.rgb; - reprColor.a = reprStyle.usePrimvarAlpha ? color.a : reprStyle.color.a; - - // Compute color overrides - vec4 colorOverride = ApplyColorOverrides(reprColor); - reprColor = reprStyle.applyColorOverride ? colorOverride : reprColor; - - - // Surface shading can be expensive and also can contain undesirable - // side effects (like discards). So only run it for reprs that require it. - - if (reprStyle.useSurfaceShaderColor || - reprStyle.useSurfaceShaderAlpha) { - vec4 shadingColor; - - shadingColor = surfaceShader(Peye, - Neye, - reprColor, - patchCoord); - -#ifdef HD_HAS_postSurfaceShader - shadingColor = postSurfaceShader(Peye, - Neye, - shadingColor); -#endif - - reprColor.rgb = reprStyle.useSurfaceShaderColor ? - shadingColor.rgb : - reprColor.rgb; - - reprColor.a = reprStyle.useSurfaceShaderAlpha ? - shadingColor.a : - reprColor.a; - } - - vec4 baseColor = color; - baseColor = ApplyColorOverrides(baseColor); - - vec4 litColor = mix(baseColor, - reprColor, - GetLightingBlendAmount()); - - // Final overrides. - - return ApplyColorOverridesPostLighting(litColor); -} - - - -#ifdef HD_HAS_integrateLights -#ifndef HD_HAS_definedIntegrateLights -#define HD_HAS_definedIntegrateLights - -LightingContribution -integrateLights(vec4 Peye, vec3 Neye, LightingInterfaceProperties props) -{ - return integrateLightsDefault(Peye, Neye, props); -} - -#endif // HD_HAS_definedIntegrateLights -#endif - -ReprStyle GetReprStyle() -{ - ReprStyle reprStyle; - - reprStyle.color = vec4(0.0, 0.0, 0.0, 1.0); - reprStyle.usePrimvarColor = true; - reprStyle.usePrimvarAlpha = true; - reprStyle.applyColorOverride = true; - reprStyle.useSurfaceShaderColor = true; - reprStyle.useSurfaceShaderAlpha = true; - - return reprStyle; -} - - - -ScalarOverride GetScalarOverride() -{ - ScalarOverride result; - - result.enabled = false; - result.color = vec3(0.0, 0.0, 0.0); - - return result; -} - - -void main(void) -{ - vec3 Peye = inData.Peye.xyz / inData.Peye.w; - // camera facing. - vec3 Neye = vec3(0, 0, 1); - - vec4 color = vec4(0.5, 0.5, 0.5, 1); -#ifdef HD_HAS_displayColor - color.rgb = HdGet_displayColor().rgb; -#endif -#ifdef HD_HAS_displayOpacity - color.a = HdGet_displayOpacity(); -#endif - - vec4 patchCoord = vec4(0); - color = ShadingTerminal(vec4(Peye, 1), Neye, color, patchCoord); - -#ifdef HD_MATERIAL_TAG_MASKED - if (ShouldDiscardByAlpha(color)) { - discard; - } -#endif - - RenderOutput(vec4(Peye, 1), Neye, color, patchCoord); -} - - -int GetPointId() -{ - return vsPointId; -} - -OK diff --git a/pxr/imaging/hdSt/testenv/testHdStCodeGen_GL/baseline/codegen_points_indirect.out b/pxr/imaging/hdSt/testenv/testHdStCodeGen_GL/baseline/codegen_points_indirect.out index fe4aba326cf..074b6896878 100644 --- a/pxr/imaging/hdSt/testenv/testHdStCodeGen_GL/baseline/codegen_points_indirect.out +++ b/pxr/imaging/hdSt/testenv/testHdStCodeGen_GL/baseline/codegen_points_indirect.out @@ -159,22 +159,14 @@ FORWARD_DECL(int GetElementID()); FORWARD_DECL(int GetAggregatedElementID()); FORWARD_DECL(int GetPrimitiveEdgeId()); FORWARD_DECL(float GetSelectedEdgeOpacity()); +out flat ivec4 vs_interstageDrawingCoord0; +out flat ivec4 vs_interstageDrawingCoord1; +out flat ivec4 vs_interstageDrawingCoord2; layout (location = 2) in ivec4 drawingCoord0; layout (location = 3) in ivec4 drawingCoord1; layout (location = 4) in ivec2 drawingCoord2; layout (location = 0) in vec3 points; layout (location = 1) in vec3 normals; -out flat int vs_dc_modelCoord; -out flat int vs_dc_constantCoord; -out flat int vs_dc_elementCoord; -out flat int vs_dc_primitiveCoord; -out flat int vs_dc_fvarCoord; -out flat int vs_dc_shaderCoord; -out flat int vs_dc_vertexCoord; -out flat int vs_dc_topologyVisibilityCoord; -out flat int vs_dc_varyingCoord; -out flat int vs_dc_instanceIndexI0; -out flat int vs_dc_instanceCoordsI0; layout(location = 0) uniform ConstantData10 *constantPrimvars; out VertexData { vec4 Peye; @@ -250,16 +242,16 @@ float HdGetScalar_normals() { return HdGet_normals(0).x; } // //////// Codegen Proc VS //////// void ProcessPrimvarsIn() { hd_drawingCoord dc = GetDrawingCoord(); - vs_dc_modelCoord = dc.modelCoord; - vs_dc_constantCoord = dc.constantCoord; - vs_dc_elementCoord = dc.elementCoord; - vs_dc_primitiveCoord = dc.primitiveCoord; - vs_dc_fvarCoord = dc.fvarCoord; - vs_dc_shaderCoord = dc.shaderCoord; - vs_dc_vertexCoord = dc.vertexCoord; - vs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - vs_dc_varyingCoord = dc.varyingCoord; - vs_dc_instanceIndexI0 = dc.instanceIndex[0]; + vs_interstageDrawingCoord0[0] = dc.modelCoord; + vs_interstageDrawingCoord0[1] = dc.constantCoord; + vs_interstageDrawingCoord0[2] = dc.elementCoord; + vs_interstageDrawingCoord0[3] = dc.primitiveCoord; + vs_interstageDrawingCoord1[0] = dc.fvarCoord; + vs_interstageDrawingCoord1[1] = dc.shaderCoord; + vs_interstageDrawingCoord1[2] = dc.vertexCoord; + vs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + vs_interstageDrawingCoord2[0] = dc.varyingCoord; + vs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = points; outPrimvars.normals = normals; } @@ -1248,21 +1240,13 @@ in VertexData { } inData; in flat int vsPointId; layout (location = 0) out vec4 colorOut; +in flat ivec4 vs_interstageDrawingCoord0; +in flat ivec4 vs_interstageDrawingCoord1; +in flat ivec4 vs_interstageDrawingCoord2; in PrimvarData { vec3 points; vec3 normals; } inPrimvars; -in flat int vs_dc_modelCoord; -in flat int vs_dc_constantCoord; -in flat int vs_dc_elementCoord; -in flat int vs_dc_primitiveCoord; -in flat int vs_dc_fvarCoord; -in flat int vs_dc_shaderCoord; -in flat int vs_dc_vertexCoord; -in flat int vs_dc_topologyVisibilityCoord; -in flat int vs_dc_varyingCoord; -in flat int vs_dc_instanceIndexI0; -in flat int vs_dc_instanceCoordsI0; // //////// Codegen Accessors //////// mat4 HdGet_transform(int localIndex) { @@ -1311,16 +1295,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = vs_dc_modelCoord; - dc.constantCoord = vs_dc_constantCoord; - dc.elementCoord = vs_dc_elementCoord; - dc.primitiveCoord = vs_dc_primitiveCoord; - dc.fvarCoord = vs_dc_fvarCoord; - dc.shaderCoord = vs_dc_shaderCoord; - dc.vertexCoord = vs_dc_vertexCoord; - dc.topologyVisibilityCoord = vs_dc_topologyVisibilityCoord; - dc.varyingCoord = vs_dc_varyingCoord; - dc.instanceIndex[0] = vs_dc_instanceIndexI0; + dc.modelCoord = vs_interstageDrawingCoord0[0]; + dc.constantCoord = vs_interstageDrawingCoord0[1]; + dc.elementCoord = vs_interstageDrawingCoord0[2]; + dc.primitiveCoord = vs_interstageDrawingCoord0[3]; + dc.fvarCoord = vs_interstageDrawingCoord1[0]; + dc.shaderCoord = vs_interstageDrawingCoord1[1]; + dc.vertexCoord = vs_interstageDrawingCoord1[2]; + dc.topologyVisibilityCoord = vs_interstageDrawingCoord1[3]; + dc.varyingCoord = vs_interstageDrawingCoord2[0]; + dc.instanceIndex[0] = vs_interstageDrawingCoord2[1]; return dc; } int GetElementID() { @@ -1548,12 +1532,37 @@ vec4 ApplyColorOverridesPostLighting(vec4 color) -void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +void RenderColor(vec4 color) { colorOut = color; } + +void RenderId() +{ + // do nothing +} + + + +void RenderNeye(vec3 Neye) +{ + // do nothing +} + + + +void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +{ + // Write to any desired AOVs here. The render pass shader configuation + // decides if any of these are no-ops. + RenderColor(color); + RenderId(); + RenderNeye(Neye); +} + + #ifndef HD_HAS_integrateLights #define HD_HAS_integrateLights #endif diff --git a/pxr/imaging/hdSt/testenv/testHdStCodeGen_Vulkan/baseline/codegen_curves_indirect.out b/pxr/imaging/hdSt/testenv/testHdStCodeGen_Vulkan/baseline/codegen_curves_indirect.out index 071379f20f6..5b7c6b3359a 100644 --- a/pxr/imaging/hdSt/testenv/testHdStCodeGen_Vulkan/baseline/codegen_curves_indirect.out +++ b/pxr/imaging/hdSt/testenv/testHdStCodeGen_Vulkan/baseline/codegen_curves_indirect.out @@ -166,21 +166,13 @@ layout(location = 1) in vec3 normals; uint hd_VertexID = gl_VertexIndex; uint hd_InstanceID = gl_InstanceIndex; uint hd_BaseInstance = HgiGetBaseInstance(); -flat layout(location = 0) out int vs_dc_modelCoord; -flat layout(location = 1) out int vs_dc_constantCoord; -flat layout(location = 2) out int vs_dc_elementCoord; -flat layout(location = 3) out int vs_dc_primitiveCoord; -flat layout(location = 4) out int vs_dc_fvarCoord; -flat layout(location = 5) out int vs_dc_shaderCoord; -flat layout(location = 6) out int vs_dc_vertexCoord; -flat layout(location = 7) out int vs_dc_topologyVisibilityCoord; -flat layout(location = 8) out int vs_dc_varyingCoord; -flat layout(location = 9) out int vs_dc_instanceIndexI0; -flat layout(location = 10) out int vs_dc_instanceCoordsI0; -layout(location = 11) out CurveVertexData { +flat layout(location = 0) out ivec4 vs_interstageDrawingCoord0; +flat layout(location = 1) out ivec4 vs_interstageDrawingCoord1; +flat layout(location = 2) out ivec4 vs_interstageDrawingCoord2; +layout(location = 3) out CurveVertexData { vec4 Peye; } outData; -layout(location = 12) out PrimvarData { +layout(location = 4) out PrimvarData { vec3 points; vec3 normals; } outPrimvars; @@ -252,16 +244,16 @@ float HdGetScalar_normals() { return HdGet_normals(0).x; } // //////// Codegen Proc VS //////// void ProcessPrimvarsIn() { hd_drawingCoord dc = GetDrawingCoord(); - vs_dc_modelCoord = dc.modelCoord; - vs_dc_constantCoord = dc.constantCoord; - vs_dc_elementCoord = dc.elementCoord; - vs_dc_primitiveCoord = dc.primitiveCoord; - vs_dc_fvarCoord = dc.fvarCoord; - vs_dc_shaderCoord = dc.shaderCoord; - vs_dc_vertexCoord = dc.vertexCoord; - vs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - vs_dc_varyingCoord = dc.varyingCoord; - vs_dc_instanceIndexI0 = dc.instanceIndex[0]; + vs_interstageDrawingCoord0[0] = dc.modelCoord; + vs_interstageDrawingCoord0[1] = dc.constantCoord; + vs_interstageDrawingCoord0[2] = dc.elementCoord; + vs_interstageDrawingCoord0[3] = dc.primitiveCoord; + vs_interstageDrawingCoord1[0] = dc.fvarCoord; + vs_interstageDrawingCoord1[1] = dc.shaderCoord; + vs_interstageDrawingCoord1[2] = dc.vertexCoord; + vs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + vs_interstageDrawingCoord2[0] = dc.varyingCoord; + vs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = points; outPrimvars.normals = normals; } @@ -812,39 +804,23 @@ layout (vertices = HD_NUM_PATCH_EVAL_VERTS) out; // //////// Global Member Declarations //////// layout(std430, binding = 0) readonly buffer ssbo_constantPrimvars { ConstantData7 constantPrimvars[]; }; layout(std430, binding = 1) readonly buffer ssbo_faceVisibility { float faceVisibility[]; }; -flat layout(location = 0) in int vs_dc_modelCoord[gl_MaxPatchVertices]; -flat layout(location = 1) in int vs_dc_constantCoord[gl_MaxPatchVertices]; -flat layout(location = 2) in int vs_dc_elementCoord[gl_MaxPatchVertices]; -flat layout(location = 3) in int vs_dc_primitiveCoord[gl_MaxPatchVertices]; -flat layout(location = 4) in int vs_dc_fvarCoord[gl_MaxPatchVertices]; -flat layout(location = 5) in int vs_dc_shaderCoord[gl_MaxPatchVertices]; -flat layout(location = 6) in int vs_dc_vertexCoord[gl_MaxPatchVertices]; -flat layout(location = 7) in int vs_dc_topologyVisibilityCoord[gl_MaxPatchVertices]; -flat layout(location = 8) in int vs_dc_varyingCoord[gl_MaxPatchVertices]; -flat layout(location = 9) in int vs_dc_instanceIndexI0[gl_MaxPatchVertices]; -flat layout(location = 10) in int vs_dc_instanceCoordsI0[gl_MaxPatchVertices]; -layout(location = 11) in CurveVertexData { +flat layout(location = 0) in ivec4 vs_interstageDrawingCoord0[gl_MaxPatchVertices]; +flat layout(location = 1) in ivec4 vs_interstageDrawingCoord1[gl_MaxPatchVertices]; +flat layout(location = 2) in ivec4 vs_interstageDrawingCoord2[gl_MaxPatchVertices]; +layout(location = 3) in CurveVertexData { vec4 Peye; } inData[gl_MaxPatchVertices]; -layout(location = 12) in PrimvarData { +layout(location = 4) in PrimvarData { vec3 points; vec3 normals; } inPrimvars[gl_MaxPatchVertices]; -flat layout(location = 3) out int tcs_dc_modelCoord[HD_NUM_PATCH_EVAL_VERTS]; -flat layout(location = 4) out int tcs_dc_constantCoord[HD_NUM_PATCH_EVAL_VERTS]; -flat layout(location = 5) out int tcs_dc_elementCoord[HD_NUM_PATCH_EVAL_VERTS]; -flat layout(location = 6) out int tcs_dc_primitiveCoord[HD_NUM_PATCH_EVAL_VERTS]; -flat layout(location = 7) out int tcs_dc_fvarCoord[HD_NUM_PATCH_EVAL_VERTS]; -flat layout(location = 8) out int tcs_dc_shaderCoord[HD_NUM_PATCH_EVAL_VERTS]; -flat layout(location = 9) out int tcs_dc_vertexCoord[HD_NUM_PATCH_EVAL_VERTS]; -flat layout(location = 10) out int tcs_dc_topologyVisibilityCoord[HD_NUM_PATCH_EVAL_VERTS]; -flat layout(location = 11) out int tcs_dc_varyingCoord[HD_NUM_PATCH_EVAL_VERTS]; -flat layout(location = 12) out int tcs_dc_instanceIndexI0[HD_NUM_PATCH_EVAL_VERTS]; -flat layout(location = 13) out int tcs_dc_instanceCoordsI0[HD_NUM_PATCH_EVAL_VERTS]; +flat layout(location = 1) out ivec4 tcs_interstageDrawingCoord0[HD_NUM_PATCH_EVAL_VERTS]; +flat layout(location = 2) out ivec4 tcs_interstageDrawingCoord1[HD_NUM_PATCH_EVAL_VERTS]; +flat layout(location = 3) out ivec4 tcs_interstageDrawingCoord2[HD_NUM_PATCH_EVAL_VERTS]; layout(location = 0) out CurveVertexData { vec4 Peye; } outData[HD_NUM_PATCH_EVAL_VERTS]; -layout(location = 1) out PrimvarData { +layout(location = 4) out PrimvarData { vec3 points; vec3 normals; } outPrimvars[HD_NUM_PATCH_EVAL_VERTS]; @@ -894,16 +870,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = vs_dc_modelCoord[0]; - dc.constantCoord = vs_dc_constantCoord[0]; - dc.elementCoord = vs_dc_elementCoord[0]; - dc.primitiveCoord = vs_dc_primitiveCoord[0]; - dc.fvarCoord = vs_dc_fvarCoord[0]; - dc.shaderCoord = vs_dc_shaderCoord[0]; - dc.vertexCoord = vs_dc_vertexCoord[0]; - dc.topologyVisibilityCoord = vs_dc_topologyVisibilityCoord[0]; - dc.varyingCoord = vs_dc_varyingCoord[0]; - dc.instanceIndex[0] = vs_dc_instanceIndexI0[0]; + dc.modelCoord = vs_interstageDrawingCoord0[0][0]; + dc.constantCoord = vs_interstageDrawingCoord0[0][1]; + dc.elementCoord = vs_interstageDrawingCoord0[0][2]; + dc.primitiveCoord = vs_interstageDrawingCoord0[0][3]; + dc.fvarCoord = vs_interstageDrawingCoord1[0][0]; + dc.shaderCoord = vs_interstageDrawingCoord1[0][1]; + dc.vertexCoord = vs_interstageDrawingCoord1[0][2]; + dc.topologyVisibilityCoord = vs_interstageDrawingCoord1[0][3]; + dc.varyingCoord = vs_interstageDrawingCoord2[0][0]; + dc.instanceIndex[0] = vs_interstageDrawingCoord2[0][1]; return dc; } int GetElementID() { @@ -958,16 +934,16 @@ float HdGetScalar_normals() { return HdGet_normals(0).x; } // //////// Codegen Proc TCS //////// void ProcessPrimvarsOut() { hd_drawingCoord dc = GetDrawingCoord(); - tcs_dc_modelCoord[gl_InvocationID] = dc.modelCoord; - tcs_dc_constantCoord[gl_InvocationID] = dc.constantCoord; - tcs_dc_elementCoord[gl_InvocationID] = dc.elementCoord; - tcs_dc_primitiveCoord[gl_InvocationID] = dc.primitiveCoord; - tcs_dc_fvarCoord[gl_InvocationID] = dc.fvarCoord; - tcs_dc_shaderCoord[gl_InvocationID] = dc.shaderCoord; - tcs_dc_vertexCoord[gl_InvocationID] = dc.vertexCoord; - tcs_dc_topologyVisibilityCoord[gl_InvocationID] = dc.topologyVisibilityCoord; - tcs_dc_varyingCoord[gl_InvocationID] = dc.varyingCoord; - tcs_dc_instanceIndexI0[gl_InvocationID] = dc.instanceIndex[0]; + tcs_interstageDrawingCoord0[gl_InvocationID][0] = dc.modelCoord; + tcs_interstageDrawingCoord0[gl_InvocationID][1] = dc.constantCoord; + tcs_interstageDrawingCoord0[gl_InvocationID][2] = dc.elementCoord; + tcs_interstageDrawingCoord0[gl_InvocationID][3] = dc.primitiveCoord; + tcs_interstageDrawingCoord1[gl_InvocationID][0] = dc.fvarCoord; + tcs_interstageDrawingCoord1[gl_InvocationID][1] = dc.shaderCoord; + tcs_interstageDrawingCoord1[gl_InvocationID][2] = dc.vertexCoord; + tcs_interstageDrawingCoord1[gl_InvocationID][3] = dc.topologyVisibilityCoord; + tcs_interstageDrawingCoord2[gl_InvocationID][0] = dc.varyingCoord; + tcs_interstageDrawingCoord2[gl_InvocationID][1] = dc.instanceIndex[0]; outPrimvars[gl_InvocationID].points = inPrimvars[gl_InvocationID].points; outPrimvars[gl_InvocationID].normals = inPrimvars[gl_InvocationID].normals; } @@ -1338,39 +1314,23 @@ layout (cw) in; // //////// Global Member Declarations //////// layout(std430, binding = 0) readonly buffer ssbo_constantPrimvars { ConstantData7 constantPrimvars[]; }; layout(std430, binding = 1) readonly buffer ssbo_faceVisibility { float faceVisibility[]; }; -flat layout(location = 3) in int tcs_dc_modelCoord[gl_MaxPatchVertices]; -flat layout(location = 4) in int tcs_dc_constantCoord[gl_MaxPatchVertices]; -flat layout(location = 5) in int tcs_dc_elementCoord[gl_MaxPatchVertices]; -flat layout(location = 6) in int tcs_dc_primitiveCoord[gl_MaxPatchVertices]; -flat layout(location = 7) in int tcs_dc_fvarCoord[gl_MaxPatchVertices]; -flat layout(location = 8) in int tcs_dc_shaderCoord[gl_MaxPatchVertices]; -flat layout(location = 9) in int tcs_dc_vertexCoord[gl_MaxPatchVertices]; -flat layout(location = 10) in int tcs_dc_topologyVisibilityCoord[gl_MaxPatchVertices]; -flat layout(location = 11) in int tcs_dc_varyingCoord[gl_MaxPatchVertices]; -flat layout(location = 12) in int tcs_dc_instanceIndexI0[gl_MaxPatchVertices]; -flat layout(location = 13) in int tcs_dc_instanceCoordsI0[gl_MaxPatchVertices]; +flat layout(location = 1) in ivec4 tcs_interstageDrawingCoord0[gl_MaxPatchVertices]; +flat layout(location = 2) in ivec4 tcs_interstageDrawingCoord1[gl_MaxPatchVertices]; +flat layout(location = 3) in ivec4 tcs_interstageDrawingCoord2[gl_MaxPatchVertices]; layout(location = 0) in CurveVertexData { vec4 Peye; } inData[gl_MaxPatchVertices]; -layout(location = 1) in PrimvarData { +layout(location = 4) in PrimvarData { vec3 points; vec3 normals; } inPrimvars[gl_MaxPatchVertices]; -flat layout(location = 3) out int tes_dc_modelCoord; -flat layout(location = 4) out int tes_dc_constantCoord; -flat layout(location = 5) out int tes_dc_elementCoord; -flat layout(location = 6) out int tes_dc_primitiveCoord; -flat layout(location = 7) out int tes_dc_fvarCoord; -flat layout(location = 8) out int tes_dc_shaderCoord; -flat layout(location = 9) out int tes_dc_vertexCoord; -flat layout(location = 10) out int tes_dc_topologyVisibilityCoord; -flat layout(location = 11) out int tes_dc_varyingCoord; -flat layout(location = 12) out int tes_dc_instanceIndexI0; -flat layout(location = 13) out int tes_dc_instanceCoordsI0; +flat layout(location = 1) out ivec4 tes_interstageDrawingCoord0; +flat layout(location = 2) out ivec4 tes_interstageDrawingCoord1; +flat layout(location = 3) out ivec4 tes_interstageDrawingCoord2; layout(location = 0) out CurveVertexData { vec4 Peye; } outData; -layout(location = 1) out PrimvarData { +layout(location = 4) out PrimvarData { vec3 points; vec3 normals; } outPrimvars; @@ -1420,16 +1380,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = tcs_dc_modelCoord[0]; - dc.constantCoord = tcs_dc_constantCoord[0]; - dc.elementCoord = tcs_dc_elementCoord[0]; - dc.primitiveCoord = tcs_dc_primitiveCoord[0]; - dc.fvarCoord = tcs_dc_fvarCoord[0]; - dc.shaderCoord = tcs_dc_shaderCoord[0]; - dc.vertexCoord = tcs_dc_vertexCoord[0]; - dc.topologyVisibilityCoord = tcs_dc_topologyVisibilityCoord[0]; - dc.varyingCoord = tcs_dc_varyingCoord[0]; - dc.instanceIndex[0] = tcs_dc_instanceIndexI0[0]; + dc.modelCoord = tcs_interstageDrawingCoord0[0][0]; + dc.constantCoord = tcs_interstageDrawingCoord0[0][1]; + dc.elementCoord = tcs_interstageDrawingCoord0[0][2]; + dc.primitiveCoord = tcs_interstageDrawingCoord0[0][3]; + dc.fvarCoord = tcs_interstageDrawingCoord1[0][0]; + dc.shaderCoord = tcs_interstageDrawingCoord1[0][1]; + dc.vertexCoord = tcs_interstageDrawingCoord1[0][2]; + dc.topologyVisibilityCoord = tcs_interstageDrawingCoord1[0][3]; + dc.varyingCoord = tcs_interstageDrawingCoord2[0][0]; + dc.instanceIndex[0] = tcs_interstageDrawingCoord2[0][1]; return dc; } int GetElementID() { @@ -1488,16 +1448,16 @@ vec3 InterpolatePrimvar(vec3 inPv0, vec3 inPv1, vec3 inPv2, vec3 inPv3, vec4 bas vec4 InterpolatePrimvar(vec4 inPv0, vec4 inPv1, vec4 inPv3, vec4 inPv3, vec4 basis, vec2 uv); void ProcessPrimvarsOut(vec4 basis, int i0, int i1, int i2, int i3, vec2 uv) { hd_drawingCoord dc = GetDrawingCoord(); - tes_dc_modelCoord = dc.modelCoord; - tes_dc_constantCoord = dc.constantCoord; - tes_dc_elementCoord = dc.elementCoord; - tes_dc_primitiveCoord = dc.primitiveCoord; - tes_dc_fvarCoord = dc.fvarCoord; - tes_dc_shaderCoord = dc.shaderCoord; - tes_dc_vertexCoord = dc.vertexCoord; - tes_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - tes_dc_varyingCoord = dc.varyingCoord; - tes_dc_instanceIndexI0 = dc.instanceIndex[0]; + tes_interstageDrawingCoord0[0] = dc.modelCoord; + tes_interstageDrawingCoord0[1] = dc.constantCoord; + tes_interstageDrawingCoord0[2] = dc.elementCoord; + tes_interstageDrawingCoord0[3] = dc.primitiveCoord; + tes_interstageDrawingCoord1[0] = dc.fvarCoord; + tes_interstageDrawingCoord1[1] = dc.shaderCoord; + tes_interstageDrawingCoord1[2] = dc.vertexCoord; + tes_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + tes_interstageDrawingCoord2[0] = dc.varyingCoord; + tes_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = basis[0] * inPrimvars[i0].points + basis[1] * inPrimvars[i1].points + basis[2] * inPrimvars[i2].points + basis[3] * inPrimvars[i3].points; outPrimvars.normals = basis[0] * inPrimvars[i0].normals + basis[1] * inPrimvars[i1].normals + basis[2] * inPrimvars[i2].normals + basis[3] * inPrimvars[i3].normals; } @@ -2101,21 +2061,13 @@ FORWARD_DECL(float GetSelectedEdgeOpacity()); // //////// Global Member Declarations //////// layout(std430, binding = 0) readonly buffer ssbo_constantPrimvars { ConstantData7 constantPrimvars[]; }; layout(std430, binding = 1) readonly buffer ssbo_faceVisibility { float faceVisibility[]; }; -flat layout(location = 3) in int tes_dc_modelCoord; -flat layout(location = 4) in int tes_dc_constantCoord; -flat layout(location = 5) in int tes_dc_elementCoord; -flat layout(location = 6) in int tes_dc_primitiveCoord; -flat layout(location = 7) in int tes_dc_fvarCoord; -flat layout(location = 8) in int tes_dc_shaderCoord; -flat layout(location = 9) in int tes_dc_vertexCoord; -flat layout(location = 10) in int tes_dc_topologyVisibilityCoord; -flat layout(location = 11) in int tes_dc_varyingCoord; -flat layout(location = 12) in int tes_dc_instanceIndexI0; -flat layout(location = 13) in int tes_dc_instanceCoordsI0; +flat layout(location = 1) in ivec4 tes_interstageDrawingCoord0; +flat layout(location = 2) in ivec4 tes_interstageDrawingCoord1; +flat layout(location = 3) in ivec4 tes_interstageDrawingCoord2; layout(location = 0) in CurveVertexData { vec4 Peye; } inData; -layout(location = 1) in PrimvarData { +layout(location = 4) in PrimvarData { vec3 points; vec3 normals; } inPrimvars; @@ -2170,16 +2122,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = tes_dc_modelCoord; - dc.constantCoord = tes_dc_constantCoord; - dc.elementCoord = tes_dc_elementCoord; - dc.primitiveCoord = tes_dc_primitiveCoord; - dc.fvarCoord = tes_dc_fvarCoord; - dc.shaderCoord = tes_dc_shaderCoord; - dc.vertexCoord = tes_dc_vertexCoord; - dc.topologyVisibilityCoord = tes_dc_topologyVisibilityCoord; - dc.varyingCoord = tes_dc_varyingCoord; - dc.instanceIndex[0] = tes_dc_instanceIndexI0; + dc.modelCoord = tes_interstageDrawingCoord0[0]; + dc.constantCoord = tes_interstageDrawingCoord0[1]; + dc.elementCoord = tes_interstageDrawingCoord0[2]; + dc.primitiveCoord = tes_interstageDrawingCoord0[3]; + dc.fvarCoord = tes_interstageDrawingCoord1[0]; + dc.shaderCoord = tes_interstageDrawingCoord1[1]; + dc.vertexCoord = tes_interstageDrawingCoord1[2]; + dc.topologyVisibilityCoord = tes_interstageDrawingCoord1[3]; + dc.varyingCoord = tes_interstageDrawingCoord2[0]; + dc.instanceIndex[0] = tes_interstageDrawingCoord2[1]; return dc; } int GetElementID() { @@ -2414,12 +2366,37 @@ vec4 ApplyColorOverridesPostLighting(vec4 color) -void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +void RenderColor(vec4 color) { colorOut = color; } + +void RenderId() +{ + // do nothing +} + + + +void RenderNeye(vec3 Neye) +{ + // do nothing +} + + + +void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +{ + // Write to any desired AOVs here. The render pass shader configuation + // decides if any of these are no-ops. + RenderColor(color); + RenderId(); + RenderNeye(Neye); +} + + #ifndef HD_HAS_integrateLights #define HD_HAS_integrateLights #endif diff --git a/pxr/imaging/hdSt/testenv/testHdStCodeGen_Vulkan/baseline/codegen_mesh_edgeonly.out b/pxr/imaging/hdSt/testenv/testHdStCodeGen_Vulkan/baseline/codegen_mesh_edgeonly.out index d2f21a241aa..2a3b4cf9c2f 100644 --- a/pxr/imaging/hdSt/testenv/testHdStCodeGen_Vulkan/baseline/codegen_mesh_edgeonly.out +++ b/pxr/imaging/hdSt/testenv/testHdStCodeGen_Vulkan/baseline/codegen_mesh_edgeonly.out @@ -166,22 +166,14 @@ layout(location = 1) in vec3 normals; uint hd_VertexID = gl_VertexIndex; uint hd_InstanceID = gl_InstanceIndex; uint hd_BaseInstance = HgiGetBaseInstance(); -flat layout(location = 0) out int vs_dc_modelCoord; -flat layout(location = 1) out int vs_dc_constantCoord; -flat layout(location = 2) out int vs_dc_elementCoord; -flat layout(location = 3) out int vs_dc_primitiveCoord; -flat layout(location = 4) out int vs_dc_fvarCoord; -flat layout(location = 5) out int vs_dc_shaderCoord; -flat layout(location = 6) out int vs_dc_vertexCoord; -flat layout(location = 7) out int vs_dc_topologyVisibilityCoord; -flat layout(location = 8) out int vs_dc_varyingCoord; -flat layout(location = 9) out int vs_dc_instanceIndexI0; -flat layout(location = 10) out int vs_dc_instanceCoordsI0; -layout(location = 11) out VertexData { +flat layout(location = 0) out ivec4 vs_interstageDrawingCoord0; +flat layout(location = 1) out ivec4 vs_interstageDrawingCoord1; +flat layout(location = 2) out ivec4 vs_interstageDrawingCoord2; +layout(location = 3) out VertexData { vec4 Peye; vec3 Neye; } outData; -layout(location = 13) out PrimvarData { +layout(location = 5) out PrimvarData { vec3 points; vec3 normals; } outPrimvars; @@ -253,16 +245,16 @@ float HdGetScalar_normals() { return HdGet_normals(0).x; } // //////// Codegen Proc VS //////// void ProcessPrimvarsIn() { hd_drawingCoord dc = GetDrawingCoord(); - vs_dc_modelCoord = dc.modelCoord; - vs_dc_constantCoord = dc.constantCoord; - vs_dc_elementCoord = dc.elementCoord; - vs_dc_primitiveCoord = dc.primitiveCoord; - vs_dc_fvarCoord = dc.fvarCoord; - vs_dc_shaderCoord = dc.shaderCoord; - vs_dc_vertexCoord = dc.vertexCoord; - vs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - vs_dc_varyingCoord = dc.varyingCoord; - vs_dc_instanceIndexI0 = dc.instanceIndex[0]; + vs_interstageDrawingCoord0[0] = dc.modelCoord; + vs_interstageDrawingCoord0[1] = dc.constantCoord; + vs_interstageDrawingCoord0[2] = dc.elementCoord; + vs_interstageDrawingCoord0[3] = dc.primitiveCoord; + vs_interstageDrawingCoord1[0] = dc.fvarCoord; + vs_interstageDrawingCoord1[1] = dc.shaderCoord; + vs_interstageDrawingCoord1[2] = dc.vertexCoord; + vs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + vs_interstageDrawingCoord2[0] = dc.varyingCoord; + vs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = points; outPrimvars.normals = normals; } @@ -831,43 +823,27 @@ layout(std430, binding = 1) readonly buffer ssbo_primitiveParam { int primitiveP layout(std430, binding = 2) readonly buffer ssbo_edgeIndices { int edgeIndices[]; }; layout(std430, binding = 3) readonly buffer ssbo_faceVisibility { float faceVisibility[]; }; layout(std430, binding = 4) readonly buffer ssbo_dispTextureCoord { vec2 dispTextureCoord[]; }; -flat layout(location = 0) in int vs_dc_modelCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 1) in int vs_dc_constantCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 2) in int vs_dc_elementCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 3) in int vs_dc_primitiveCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 4) in int vs_dc_fvarCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 5) in int vs_dc_shaderCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 6) in int vs_dc_vertexCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 7) in int vs_dc_topologyVisibilityCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 8) in int vs_dc_varyingCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 9) in int vs_dc_instanceIndexI0[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 10) in int vs_dc_instanceCoordsI0[HD_NUM_PRIMITIVE_VERTS]; -layout(location = 11) in VertexData { +flat layout(location = 0) in ivec4 vs_interstageDrawingCoord0[HD_NUM_PRIMITIVE_VERTS]; +flat layout(location = 1) in ivec4 vs_interstageDrawingCoord1[HD_NUM_PRIMITIVE_VERTS]; +flat layout(location = 2) in ivec4 vs_interstageDrawingCoord2[HD_NUM_PRIMITIVE_VERTS]; +layout(location = 3) in VertexData { vec4 Peye; vec3 Neye; } inData[3]; -layout(location = 13) in PrimvarData { +layout(location = 5) in PrimvarData { vec3 points; vec3 normals; } inPrimvars[HD_NUM_PRIMITIVE_VERTS]; layout(location = 2) out vec4 gsPatchCoord; noperspective layout(location = 3) out vec3 hd_barycentricCoord; -flat layout(location = 7) out int gs_dc_modelCoord; -flat layout(location = 8) out int gs_dc_constantCoord; -flat layout(location = 9) out int gs_dc_elementCoord; -flat layout(location = 10) out int gs_dc_primitiveCoord; -flat layout(location = 11) out int gs_dc_fvarCoord; -flat layout(location = 12) out int gs_dc_shaderCoord; -flat layout(location = 13) out int gs_dc_vertexCoord; -flat layout(location = 14) out int gs_dc_topologyVisibilityCoord; -flat layout(location = 15) out int gs_dc_varyingCoord; -flat layout(location = 16) out int gs_dc_instanceIndexI0; -flat layout(location = 17) out int gs_dc_instanceCoordsI0; +flat layout(location = 4) out ivec4 gs_interstageDrawingCoord0; +flat layout(location = 5) out ivec4 gs_interstageDrawingCoord1; +flat layout(location = 6) out ivec4 gs_interstageDrawingCoord2; layout(location = 0) out VertexData { vec4 Peye; vec3 Neye; } outData; -layout(location = 4) out PrimvarData { +layout(location = 7) out PrimvarData { vec3 points; vec3 normals; vec2 dispTextureCoord; @@ -918,16 +894,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = vs_dc_modelCoord[0]; - dc.constantCoord = vs_dc_constantCoord[0]; - dc.elementCoord = vs_dc_elementCoord[0]; - dc.primitiveCoord = vs_dc_primitiveCoord[0]; - dc.fvarCoord = vs_dc_fvarCoord[0]; - dc.shaderCoord = vs_dc_shaderCoord[0]; - dc.vertexCoord = vs_dc_vertexCoord[0]; - dc.topologyVisibilityCoord = vs_dc_topologyVisibilityCoord[0]; - dc.varyingCoord = vs_dc_varyingCoord[0]; - dc.instanceIndex[0] = vs_dc_instanceIndexI0[0]; + dc.modelCoord = vs_interstageDrawingCoord0[0][0]; + dc.constantCoord = vs_interstageDrawingCoord0[0][1]; + dc.elementCoord = vs_interstageDrawingCoord0[0][2]; + dc.primitiveCoord = vs_interstageDrawingCoord0[0][3]; + dc.fvarCoord = vs_interstageDrawingCoord1[0][0]; + dc.shaderCoord = vs_interstageDrawingCoord1[0][1]; + dc.vertexCoord = vs_interstageDrawingCoord1[0][2]; + dc.topologyVisibilityCoord = vs_interstageDrawingCoord1[0][3]; + dc.varyingCoord = vs_interstageDrawingCoord2[0][0]; + dc.instanceIndex[0] = vs_interstageDrawingCoord2[0][1]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -1020,16 +996,16 @@ void ProcessPrimvarsOut(int index) { ); hd_barycentricCoord = coords[index]; hd_drawingCoord dc = GetDrawingCoord(); - gs_dc_modelCoord = dc.modelCoord; - gs_dc_constantCoord = dc.constantCoord; - gs_dc_elementCoord = dc.elementCoord; - gs_dc_primitiveCoord = dc.primitiveCoord; - gs_dc_fvarCoord = dc.fvarCoord; - gs_dc_shaderCoord = dc.shaderCoord; - gs_dc_vertexCoord = dc.vertexCoord; - gs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - gs_dc_varyingCoord = dc.varyingCoord; - gs_dc_instanceIndexI0 = dc.instanceIndex[0]; + gs_interstageDrawingCoord0[0] = dc.modelCoord; + gs_interstageDrawingCoord0[1] = dc.constantCoord; + gs_interstageDrawingCoord0[2] = dc.elementCoord; + gs_interstageDrawingCoord0[3] = dc.primitiveCoord; + gs_interstageDrawingCoord1[0] = dc.fvarCoord; + gs_interstageDrawingCoord1[1] = dc.shaderCoord; + gs_interstageDrawingCoord1[2] = dc.vertexCoord; + gs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + gs_interstageDrawingCoord2[0] = dc.varyingCoord; + gs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = inPrimvars[index].points; outPrimvars.normals = inPrimvars[index].normals; outPrimvars.dispTextureCoord = HdGet_dispTextureCoord(index); @@ -1651,22 +1627,14 @@ layout(std430, binding = 3) readonly buffer ssbo_faceVisibility { float faceVisi layout(std430, binding = 4) readonly buffer ssbo_dispTextureCoord { vec2 dispTextureCoord[]; }; layout(location = 2) in vec4 gsPatchCoord; noperspective layout(location = 3) in vec3 hd_barycentricCoord; -flat layout(location = 7) in int gs_dc_modelCoord; -flat layout(location = 8) in int gs_dc_constantCoord; -flat layout(location = 9) in int gs_dc_elementCoord; -flat layout(location = 10) in int gs_dc_primitiveCoord; -flat layout(location = 11) in int gs_dc_fvarCoord; -flat layout(location = 12) in int gs_dc_shaderCoord; -flat layout(location = 13) in int gs_dc_vertexCoord; -flat layout(location = 14) in int gs_dc_topologyVisibilityCoord; -flat layout(location = 15) in int gs_dc_varyingCoord; -flat layout(location = 16) in int gs_dc_instanceIndexI0; -flat layout(location = 17) in int gs_dc_instanceCoordsI0; +flat layout(location = 4) in ivec4 gs_interstageDrawingCoord0; +flat layout(location = 5) in ivec4 gs_interstageDrawingCoord1; +flat layout(location = 6) in ivec4 gs_interstageDrawingCoord2; layout(location = 0) in VertexData { vec4 Peye; vec3 Neye; } inData; -layout(location = 4) in PrimvarData { +layout(location = 7) in PrimvarData { vec3 points; vec3 normals; vec2 dispTextureCoord; @@ -1722,16 +1690,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = gs_dc_modelCoord; - dc.constantCoord = gs_dc_constantCoord; - dc.elementCoord = gs_dc_elementCoord; - dc.primitiveCoord = gs_dc_primitiveCoord; - dc.fvarCoord = gs_dc_fvarCoord; - dc.shaderCoord = gs_dc_shaderCoord; - dc.vertexCoord = gs_dc_vertexCoord; - dc.topologyVisibilityCoord = gs_dc_topologyVisibilityCoord; - dc.varyingCoord = gs_dc_varyingCoord; - dc.instanceIndex[0] = gs_dc_instanceIndexI0; + dc.modelCoord = gs_interstageDrawingCoord0[0]; + dc.constantCoord = gs_interstageDrawingCoord0[1]; + dc.elementCoord = gs_interstageDrawingCoord0[2]; + dc.primitiveCoord = gs_interstageDrawingCoord0[3]; + dc.fvarCoord = gs_interstageDrawingCoord1[0]; + dc.shaderCoord = gs_interstageDrawingCoord1[1]; + dc.vertexCoord = gs_interstageDrawingCoord1[2]; + dc.topologyVisibilityCoord = gs_interstageDrawingCoord1[3]; + dc.varyingCoord = gs_interstageDrawingCoord2[0]; + dc.instanceIndex[0] = gs_interstageDrawingCoord2[1]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -1985,12 +1953,37 @@ vec4 ApplyColorOverridesPostLighting(vec4 color) -void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +void RenderColor(vec4 color) { colorOut = color; } + +void RenderId() +{ + // do nothing +} + + + +void RenderNeye(vec3 Neye) +{ + // do nothing +} + + + +void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +{ + // Write to any desired AOVs here. The render pass shader configuation + // decides if any of these are no-ops. + RenderColor(color); + RenderId(); + RenderNeye(Neye); +} + + #ifndef HD_HAS_integrateLights #define HD_HAS_integrateLights #endif @@ -2877,22 +2870,14 @@ layout(location = 1) in vec3 normals; uint hd_VertexID = gl_VertexIndex; uint hd_InstanceID = gl_InstanceIndex; uint hd_BaseInstance = HgiGetBaseInstance(); -flat layout(location = 0) out int vs_dc_modelCoord; -flat layout(location = 1) out int vs_dc_constantCoord; -flat layout(location = 2) out int vs_dc_elementCoord; -flat layout(location = 3) out int vs_dc_primitiveCoord; -flat layout(location = 4) out int vs_dc_fvarCoord; -flat layout(location = 5) out int vs_dc_shaderCoord; -flat layout(location = 6) out int vs_dc_vertexCoord; -flat layout(location = 7) out int vs_dc_topologyVisibilityCoord; -flat layout(location = 8) out int vs_dc_varyingCoord; -flat layout(location = 9) out int vs_dc_instanceIndexI0; -flat layout(location = 10) out int vs_dc_instanceCoordsI0; -layout(location = 11) out VertexData { +flat layout(location = 0) out ivec4 vs_interstageDrawingCoord0; +flat layout(location = 1) out ivec4 vs_interstageDrawingCoord1; +flat layout(location = 2) out ivec4 vs_interstageDrawingCoord2; +layout(location = 3) out VertexData { vec4 Peye; vec3 Neye; } outData; -layout(location = 13) out PrimvarData { +layout(location = 5) out PrimvarData { vec3 points; vec3 normals; } outPrimvars; @@ -2964,16 +2949,16 @@ float HdGetScalar_normals() { return HdGet_normals(0).x; } // //////// Codegen Proc VS //////// void ProcessPrimvarsIn() { hd_drawingCoord dc = GetDrawingCoord(); - vs_dc_modelCoord = dc.modelCoord; - vs_dc_constantCoord = dc.constantCoord; - vs_dc_elementCoord = dc.elementCoord; - vs_dc_primitiveCoord = dc.primitiveCoord; - vs_dc_fvarCoord = dc.fvarCoord; - vs_dc_shaderCoord = dc.shaderCoord; - vs_dc_vertexCoord = dc.vertexCoord; - vs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - vs_dc_varyingCoord = dc.varyingCoord; - vs_dc_instanceIndexI0 = dc.instanceIndex[0]; + vs_interstageDrawingCoord0[0] = dc.modelCoord; + vs_interstageDrawingCoord0[1] = dc.constantCoord; + vs_interstageDrawingCoord0[2] = dc.elementCoord; + vs_interstageDrawingCoord0[3] = dc.primitiveCoord; + vs_interstageDrawingCoord1[0] = dc.fvarCoord; + vs_interstageDrawingCoord1[1] = dc.shaderCoord; + vs_interstageDrawingCoord1[2] = dc.vertexCoord; + vs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + vs_interstageDrawingCoord2[0] = dc.varyingCoord; + vs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = points; outPrimvars.normals = normals; } @@ -3542,43 +3527,27 @@ layout(std430, binding = 1) readonly buffer ssbo_primitiveParam { int primitiveP layout(std430, binding = 2) readonly buffer ssbo_edgeIndices { ivec2 edgeIndices[]; }; layout(std430, binding = 3) readonly buffer ssbo_faceVisibility { float faceVisibility[]; }; layout(std430, binding = 4) readonly buffer ssbo_dispTextureCoord { vec2 dispTextureCoord[]; }; -flat layout(location = 0) in int vs_dc_modelCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 1) in int vs_dc_constantCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 2) in int vs_dc_elementCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 3) in int vs_dc_primitiveCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 4) in int vs_dc_fvarCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 5) in int vs_dc_shaderCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 6) in int vs_dc_vertexCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 7) in int vs_dc_topologyVisibilityCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 8) in int vs_dc_varyingCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 9) in int vs_dc_instanceIndexI0[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 10) in int vs_dc_instanceCoordsI0[HD_NUM_PRIMITIVE_VERTS]; -layout(location = 11) in VertexData { +flat layout(location = 0) in ivec4 vs_interstageDrawingCoord0[HD_NUM_PRIMITIVE_VERTS]; +flat layout(location = 1) in ivec4 vs_interstageDrawingCoord1[HD_NUM_PRIMITIVE_VERTS]; +flat layout(location = 2) in ivec4 vs_interstageDrawingCoord2[HD_NUM_PRIMITIVE_VERTS]; +layout(location = 3) in VertexData { vec4 Peye; vec3 Neye; } inData[4]; -layout(location = 13) in PrimvarData { +layout(location = 5) in PrimvarData { vec3 points; vec3 normals; } inPrimvars[HD_NUM_PRIMITIVE_VERTS]; layout(location = 2) out vec4 gsPatchCoord; noperspective layout(location = 3) out vec3 hd_barycentricCoord; -flat layout(location = 7) out int gs_dc_modelCoord; -flat layout(location = 8) out int gs_dc_constantCoord; -flat layout(location = 9) out int gs_dc_elementCoord; -flat layout(location = 10) out int gs_dc_primitiveCoord; -flat layout(location = 11) out int gs_dc_fvarCoord; -flat layout(location = 12) out int gs_dc_shaderCoord; -flat layout(location = 13) out int gs_dc_vertexCoord; -flat layout(location = 14) out int gs_dc_topologyVisibilityCoord; -flat layout(location = 15) out int gs_dc_varyingCoord; -flat layout(location = 16) out int gs_dc_instanceIndexI0; -flat layout(location = 17) out int gs_dc_instanceCoordsI0; +flat layout(location = 4) out ivec4 gs_interstageDrawingCoord0; +flat layout(location = 5) out ivec4 gs_interstageDrawingCoord1; +flat layout(location = 6) out ivec4 gs_interstageDrawingCoord2; layout(location = 0) out VertexData { vec4 Peye; vec3 Neye; } outData; -layout(location = 4) out PrimvarData { +layout(location = 7) out PrimvarData { vec3 points; vec3 normals; vec2 dispTextureCoord; @@ -3629,16 +3598,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = vs_dc_modelCoord[0]; - dc.constantCoord = vs_dc_constantCoord[0]; - dc.elementCoord = vs_dc_elementCoord[0]; - dc.primitiveCoord = vs_dc_primitiveCoord[0]; - dc.fvarCoord = vs_dc_fvarCoord[0]; - dc.shaderCoord = vs_dc_shaderCoord[0]; - dc.vertexCoord = vs_dc_vertexCoord[0]; - dc.topologyVisibilityCoord = vs_dc_topologyVisibilityCoord[0]; - dc.varyingCoord = vs_dc_varyingCoord[0]; - dc.instanceIndex[0] = vs_dc_instanceIndexI0[0]; + dc.modelCoord = vs_interstageDrawingCoord0[0][0]; + dc.constantCoord = vs_interstageDrawingCoord0[0][1]; + dc.elementCoord = vs_interstageDrawingCoord0[0][2]; + dc.primitiveCoord = vs_interstageDrawingCoord0[0][3]; + dc.fvarCoord = vs_interstageDrawingCoord1[0][0]; + dc.shaderCoord = vs_interstageDrawingCoord1[0][1]; + dc.vertexCoord = vs_interstageDrawingCoord1[0][2]; + dc.topologyVisibilityCoord = vs_interstageDrawingCoord1[0][3]; + dc.varyingCoord = vs_interstageDrawingCoord2[0][0]; + dc.instanceIndex[0] = vs_interstageDrawingCoord2[0][1]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -3731,16 +3700,16 @@ void ProcessPrimvarsOut(int index) { ); hd_barycentricCoord = coords[index]; hd_drawingCoord dc = GetDrawingCoord(); - gs_dc_modelCoord = dc.modelCoord; - gs_dc_constantCoord = dc.constantCoord; - gs_dc_elementCoord = dc.elementCoord; - gs_dc_primitiveCoord = dc.primitiveCoord; - gs_dc_fvarCoord = dc.fvarCoord; - gs_dc_shaderCoord = dc.shaderCoord; - gs_dc_vertexCoord = dc.vertexCoord; - gs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - gs_dc_varyingCoord = dc.varyingCoord; - gs_dc_instanceIndexI0 = dc.instanceIndex[0]; + gs_interstageDrawingCoord0[0] = dc.modelCoord; + gs_interstageDrawingCoord0[1] = dc.constantCoord; + gs_interstageDrawingCoord0[2] = dc.elementCoord; + gs_interstageDrawingCoord0[3] = dc.primitiveCoord; + gs_interstageDrawingCoord1[0] = dc.fvarCoord; + gs_interstageDrawingCoord1[1] = dc.shaderCoord; + gs_interstageDrawingCoord1[2] = dc.vertexCoord; + gs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + gs_interstageDrawingCoord2[0] = dc.varyingCoord; + gs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = inPrimvars[index].points; outPrimvars.normals = inPrimvars[index].normals; outPrimvars.dispTextureCoord = HdGet_dispTextureCoord(index); @@ -4391,22 +4360,14 @@ layout(std430, binding = 3) readonly buffer ssbo_faceVisibility { float faceVisi layout(std430, binding = 4) readonly buffer ssbo_dispTextureCoord { vec2 dispTextureCoord[]; }; layout(location = 2) in vec4 gsPatchCoord; noperspective layout(location = 3) in vec3 hd_barycentricCoord; -flat layout(location = 7) in int gs_dc_modelCoord; -flat layout(location = 8) in int gs_dc_constantCoord; -flat layout(location = 9) in int gs_dc_elementCoord; -flat layout(location = 10) in int gs_dc_primitiveCoord; -flat layout(location = 11) in int gs_dc_fvarCoord; -flat layout(location = 12) in int gs_dc_shaderCoord; -flat layout(location = 13) in int gs_dc_vertexCoord; -flat layout(location = 14) in int gs_dc_topologyVisibilityCoord; -flat layout(location = 15) in int gs_dc_varyingCoord; -flat layout(location = 16) in int gs_dc_instanceIndexI0; -flat layout(location = 17) in int gs_dc_instanceCoordsI0; +flat layout(location = 4) in ivec4 gs_interstageDrawingCoord0; +flat layout(location = 5) in ivec4 gs_interstageDrawingCoord1; +flat layout(location = 6) in ivec4 gs_interstageDrawingCoord2; layout(location = 0) in VertexData { vec4 Peye; vec3 Neye; } inData; -layout(location = 4) in PrimvarData { +layout(location = 7) in PrimvarData { vec3 points; vec3 normals; vec2 dispTextureCoord; @@ -4462,16 +4423,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = gs_dc_modelCoord; - dc.constantCoord = gs_dc_constantCoord; - dc.elementCoord = gs_dc_elementCoord; - dc.primitiveCoord = gs_dc_primitiveCoord; - dc.fvarCoord = gs_dc_fvarCoord; - dc.shaderCoord = gs_dc_shaderCoord; - dc.vertexCoord = gs_dc_vertexCoord; - dc.topologyVisibilityCoord = gs_dc_topologyVisibilityCoord; - dc.varyingCoord = gs_dc_varyingCoord; - dc.instanceIndex[0] = gs_dc_instanceIndexI0; + dc.modelCoord = gs_interstageDrawingCoord0[0]; + dc.constantCoord = gs_interstageDrawingCoord0[1]; + dc.elementCoord = gs_interstageDrawingCoord0[2]; + dc.primitiveCoord = gs_interstageDrawingCoord0[3]; + dc.fvarCoord = gs_interstageDrawingCoord1[0]; + dc.shaderCoord = gs_interstageDrawingCoord1[1]; + dc.vertexCoord = gs_interstageDrawingCoord1[2]; + dc.topologyVisibilityCoord = gs_interstageDrawingCoord1[3]; + dc.varyingCoord = gs_interstageDrawingCoord2[0]; + dc.instanceIndex[0] = gs_interstageDrawingCoord2[1]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -4725,12 +4686,37 @@ vec4 ApplyColorOverridesPostLighting(vec4 color) -void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +void RenderColor(vec4 color) { colorOut = color; } + +void RenderId() +{ + // do nothing +} + + + +void RenderNeye(vec3 Neye) +{ + // do nothing +} + + + +void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +{ + // Write to any desired AOVs here. The render pass shader configuation + // decides if any of these are no-ops. + RenderColor(color); + RenderId(); + RenderNeye(Neye); +} + + #ifndef HD_HAS_integrateLights #define HD_HAS_integrateLights #endif diff --git a/pxr/imaging/hdSt/testenv/testHdStCodeGen_Vulkan/baseline/codegen_mesh_edgeonly_blendwireframe.out b/pxr/imaging/hdSt/testenv/testHdStCodeGen_Vulkan/baseline/codegen_mesh_edgeonly_blendwireframe.out index 97c1426762c..ac333842a21 100644 --- a/pxr/imaging/hdSt/testenv/testHdStCodeGen_Vulkan/baseline/codegen_mesh_edgeonly_blendwireframe.out +++ b/pxr/imaging/hdSt/testenv/testHdStCodeGen_Vulkan/baseline/codegen_mesh_edgeonly_blendwireframe.out @@ -166,22 +166,14 @@ layout(location = 1) in vec3 normals; uint hd_VertexID = gl_VertexIndex; uint hd_InstanceID = gl_InstanceIndex; uint hd_BaseInstance = HgiGetBaseInstance(); -flat layout(location = 0) out int vs_dc_modelCoord; -flat layout(location = 1) out int vs_dc_constantCoord; -flat layout(location = 2) out int vs_dc_elementCoord; -flat layout(location = 3) out int vs_dc_primitiveCoord; -flat layout(location = 4) out int vs_dc_fvarCoord; -flat layout(location = 5) out int vs_dc_shaderCoord; -flat layout(location = 6) out int vs_dc_vertexCoord; -flat layout(location = 7) out int vs_dc_topologyVisibilityCoord; -flat layout(location = 8) out int vs_dc_varyingCoord; -flat layout(location = 9) out int vs_dc_instanceIndexI0; -flat layout(location = 10) out int vs_dc_instanceCoordsI0; -layout(location = 11) out VertexData { +flat layout(location = 0) out ivec4 vs_interstageDrawingCoord0; +flat layout(location = 1) out ivec4 vs_interstageDrawingCoord1; +flat layout(location = 2) out ivec4 vs_interstageDrawingCoord2; +layout(location = 3) out VertexData { vec4 Peye; vec3 Neye; } outData; -layout(location = 13) out PrimvarData { +layout(location = 5) out PrimvarData { vec3 points; vec3 normals; } outPrimvars; @@ -253,16 +245,16 @@ float HdGetScalar_normals() { return HdGet_normals(0).x; } // //////// Codegen Proc VS //////// void ProcessPrimvarsIn() { hd_drawingCoord dc = GetDrawingCoord(); - vs_dc_modelCoord = dc.modelCoord; - vs_dc_constantCoord = dc.constantCoord; - vs_dc_elementCoord = dc.elementCoord; - vs_dc_primitiveCoord = dc.primitiveCoord; - vs_dc_fvarCoord = dc.fvarCoord; - vs_dc_shaderCoord = dc.shaderCoord; - vs_dc_vertexCoord = dc.vertexCoord; - vs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - vs_dc_varyingCoord = dc.varyingCoord; - vs_dc_instanceIndexI0 = dc.instanceIndex[0]; + vs_interstageDrawingCoord0[0] = dc.modelCoord; + vs_interstageDrawingCoord0[1] = dc.constantCoord; + vs_interstageDrawingCoord0[2] = dc.elementCoord; + vs_interstageDrawingCoord0[3] = dc.primitiveCoord; + vs_interstageDrawingCoord1[0] = dc.fvarCoord; + vs_interstageDrawingCoord1[1] = dc.shaderCoord; + vs_interstageDrawingCoord1[2] = dc.vertexCoord; + vs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + vs_interstageDrawingCoord2[0] = dc.varyingCoord; + vs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = points; outPrimvars.normals = normals; } @@ -831,43 +823,27 @@ layout(std430, binding = 1) readonly buffer ssbo_primitiveParam { int primitiveP layout(std430, binding = 2) readonly buffer ssbo_edgeIndices { int edgeIndices[]; }; layout(std430, binding = 3) readonly buffer ssbo_faceVisibility { float faceVisibility[]; }; layout(std430, binding = 4) readonly buffer ssbo_dispTextureCoord { vec2 dispTextureCoord[]; }; -flat layout(location = 0) in int vs_dc_modelCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 1) in int vs_dc_constantCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 2) in int vs_dc_elementCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 3) in int vs_dc_primitiveCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 4) in int vs_dc_fvarCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 5) in int vs_dc_shaderCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 6) in int vs_dc_vertexCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 7) in int vs_dc_topologyVisibilityCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 8) in int vs_dc_varyingCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 9) in int vs_dc_instanceIndexI0[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 10) in int vs_dc_instanceCoordsI0[HD_NUM_PRIMITIVE_VERTS]; -layout(location = 11) in VertexData { +flat layout(location = 0) in ivec4 vs_interstageDrawingCoord0[HD_NUM_PRIMITIVE_VERTS]; +flat layout(location = 1) in ivec4 vs_interstageDrawingCoord1[HD_NUM_PRIMITIVE_VERTS]; +flat layout(location = 2) in ivec4 vs_interstageDrawingCoord2[HD_NUM_PRIMITIVE_VERTS]; +layout(location = 3) in VertexData { vec4 Peye; vec3 Neye; } inData[3]; -layout(location = 13) in PrimvarData { +layout(location = 5) in PrimvarData { vec3 points; vec3 normals; } inPrimvars[HD_NUM_PRIMITIVE_VERTS]; layout(location = 2) out vec4 gsPatchCoord; noperspective layout(location = 3) out vec3 hd_barycentricCoord; -flat layout(location = 7) out int gs_dc_modelCoord; -flat layout(location = 8) out int gs_dc_constantCoord; -flat layout(location = 9) out int gs_dc_elementCoord; -flat layout(location = 10) out int gs_dc_primitiveCoord; -flat layout(location = 11) out int gs_dc_fvarCoord; -flat layout(location = 12) out int gs_dc_shaderCoord; -flat layout(location = 13) out int gs_dc_vertexCoord; -flat layout(location = 14) out int gs_dc_topologyVisibilityCoord; -flat layout(location = 15) out int gs_dc_varyingCoord; -flat layout(location = 16) out int gs_dc_instanceIndexI0; -flat layout(location = 17) out int gs_dc_instanceCoordsI0; +flat layout(location = 4) out ivec4 gs_interstageDrawingCoord0; +flat layout(location = 5) out ivec4 gs_interstageDrawingCoord1; +flat layout(location = 6) out ivec4 gs_interstageDrawingCoord2; layout(location = 0) out VertexData { vec4 Peye; vec3 Neye; } outData; -layout(location = 4) out PrimvarData { +layout(location = 7) out PrimvarData { vec3 points; vec3 normals; vec2 dispTextureCoord; @@ -918,16 +894,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = vs_dc_modelCoord[0]; - dc.constantCoord = vs_dc_constantCoord[0]; - dc.elementCoord = vs_dc_elementCoord[0]; - dc.primitiveCoord = vs_dc_primitiveCoord[0]; - dc.fvarCoord = vs_dc_fvarCoord[0]; - dc.shaderCoord = vs_dc_shaderCoord[0]; - dc.vertexCoord = vs_dc_vertexCoord[0]; - dc.topologyVisibilityCoord = vs_dc_topologyVisibilityCoord[0]; - dc.varyingCoord = vs_dc_varyingCoord[0]; - dc.instanceIndex[0] = vs_dc_instanceIndexI0[0]; + dc.modelCoord = vs_interstageDrawingCoord0[0][0]; + dc.constantCoord = vs_interstageDrawingCoord0[0][1]; + dc.elementCoord = vs_interstageDrawingCoord0[0][2]; + dc.primitiveCoord = vs_interstageDrawingCoord0[0][3]; + dc.fvarCoord = vs_interstageDrawingCoord1[0][0]; + dc.shaderCoord = vs_interstageDrawingCoord1[0][1]; + dc.vertexCoord = vs_interstageDrawingCoord1[0][2]; + dc.topologyVisibilityCoord = vs_interstageDrawingCoord1[0][3]; + dc.varyingCoord = vs_interstageDrawingCoord2[0][0]; + dc.instanceIndex[0] = vs_interstageDrawingCoord2[0][1]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -1020,16 +996,16 @@ void ProcessPrimvarsOut(int index) { ); hd_barycentricCoord = coords[index]; hd_drawingCoord dc = GetDrawingCoord(); - gs_dc_modelCoord = dc.modelCoord; - gs_dc_constantCoord = dc.constantCoord; - gs_dc_elementCoord = dc.elementCoord; - gs_dc_primitiveCoord = dc.primitiveCoord; - gs_dc_fvarCoord = dc.fvarCoord; - gs_dc_shaderCoord = dc.shaderCoord; - gs_dc_vertexCoord = dc.vertexCoord; - gs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - gs_dc_varyingCoord = dc.varyingCoord; - gs_dc_instanceIndexI0 = dc.instanceIndex[0]; + gs_interstageDrawingCoord0[0] = dc.modelCoord; + gs_interstageDrawingCoord0[1] = dc.constantCoord; + gs_interstageDrawingCoord0[2] = dc.elementCoord; + gs_interstageDrawingCoord0[3] = dc.primitiveCoord; + gs_interstageDrawingCoord1[0] = dc.fvarCoord; + gs_interstageDrawingCoord1[1] = dc.shaderCoord; + gs_interstageDrawingCoord1[2] = dc.vertexCoord; + gs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + gs_interstageDrawingCoord2[0] = dc.varyingCoord; + gs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = inPrimvars[index].points; outPrimvars.normals = inPrimvars[index].normals; outPrimvars.dispTextureCoord = HdGet_dispTextureCoord(index); @@ -1651,22 +1627,14 @@ layout(std430, binding = 3) readonly buffer ssbo_faceVisibility { float faceVisi layout(std430, binding = 4) readonly buffer ssbo_dispTextureCoord { vec2 dispTextureCoord[]; }; layout(location = 2) in vec4 gsPatchCoord; noperspective layout(location = 3) in vec3 hd_barycentricCoord; -flat layout(location = 7) in int gs_dc_modelCoord; -flat layout(location = 8) in int gs_dc_constantCoord; -flat layout(location = 9) in int gs_dc_elementCoord; -flat layout(location = 10) in int gs_dc_primitiveCoord; -flat layout(location = 11) in int gs_dc_fvarCoord; -flat layout(location = 12) in int gs_dc_shaderCoord; -flat layout(location = 13) in int gs_dc_vertexCoord; -flat layout(location = 14) in int gs_dc_topologyVisibilityCoord; -flat layout(location = 15) in int gs_dc_varyingCoord; -flat layout(location = 16) in int gs_dc_instanceIndexI0; -flat layout(location = 17) in int gs_dc_instanceCoordsI0; +flat layout(location = 4) in ivec4 gs_interstageDrawingCoord0; +flat layout(location = 5) in ivec4 gs_interstageDrawingCoord1; +flat layout(location = 6) in ivec4 gs_interstageDrawingCoord2; layout(location = 0) in VertexData { vec4 Peye; vec3 Neye; } inData; -layout(location = 4) in PrimvarData { +layout(location = 7) in PrimvarData { vec3 points; vec3 normals; vec2 dispTextureCoord; @@ -1722,16 +1690,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = gs_dc_modelCoord; - dc.constantCoord = gs_dc_constantCoord; - dc.elementCoord = gs_dc_elementCoord; - dc.primitiveCoord = gs_dc_primitiveCoord; - dc.fvarCoord = gs_dc_fvarCoord; - dc.shaderCoord = gs_dc_shaderCoord; - dc.vertexCoord = gs_dc_vertexCoord; - dc.topologyVisibilityCoord = gs_dc_topologyVisibilityCoord; - dc.varyingCoord = gs_dc_varyingCoord; - dc.instanceIndex[0] = gs_dc_instanceIndexI0; + dc.modelCoord = gs_interstageDrawingCoord0[0]; + dc.constantCoord = gs_interstageDrawingCoord0[1]; + dc.elementCoord = gs_interstageDrawingCoord0[2]; + dc.primitiveCoord = gs_interstageDrawingCoord0[3]; + dc.fvarCoord = gs_interstageDrawingCoord1[0]; + dc.shaderCoord = gs_interstageDrawingCoord1[1]; + dc.vertexCoord = gs_interstageDrawingCoord1[2]; + dc.topologyVisibilityCoord = gs_interstageDrawingCoord1[3]; + dc.varyingCoord = gs_interstageDrawingCoord2[0]; + dc.instanceIndex[0] = gs_interstageDrawingCoord2[1]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -1985,12 +1953,37 @@ vec4 ApplyColorOverridesPostLighting(vec4 color) -void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +void RenderColor(vec4 color) { colorOut = color; } + +void RenderId() +{ + // do nothing +} + + + +void RenderNeye(vec3 Neye) +{ + // do nothing +} + + + +void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +{ + // Write to any desired AOVs here. The render pass shader configuation + // decides if any of these are no-ops. + RenderColor(color); + RenderId(); + RenderNeye(Neye); +} + + #ifndef HD_HAS_integrateLights #define HD_HAS_integrateLights #endif @@ -2883,22 +2876,14 @@ layout(location = 1) in vec3 normals; uint hd_VertexID = gl_VertexIndex; uint hd_InstanceID = gl_InstanceIndex; uint hd_BaseInstance = HgiGetBaseInstance(); -flat layout(location = 0) out int vs_dc_modelCoord; -flat layout(location = 1) out int vs_dc_constantCoord; -flat layout(location = 2) out int vs_dc_elementCoord; -flat layout(location = 3) out int vs_dc_primitiveCoord; -flat layout(location = 4) out int vs_dc_fvarCoord; -flat layout(location = 5) out int vs_dc_shaderCoord; -flat layout(location = 6) out int vs_dc_vertexCoord; -flat layout(location = 7) out int vs_dc_topologyVisibilityCoord; -flat layout(location = 8) out int vs_dc_varyingCoord; -flat layout(location = 9) out int vs_dc_instanceIndexI0; -flat layout(location = 10) out int vs_dc_instanceCoordsI0; -layout(location = 11) out VertexData { +flat layout(location = 0) out ivec4 vs_interstageDrawingCoord0; +flat layout(location = 1) out ivec4 vs_interstageDrawingCoord1; +flat layout(location = 2) out ivec4 vs_interstageDrawingCoord2; +layout(location = 3) out VertexData { vec4 Peye; vec3 Neye; } outData; -layout(location = 13) out PrimvarData { +layout(location = 5) out PrimvarData { vec3 points; vec3 normals; } outPrimvars; @@ -2970,16 +2955,16 @@ float HdGetScalar_normals() { return HdGet_normals(0).x; } // //////// Codegen Proc VS //////// void ProcessPrimvarsIn() { hd_drawingCoord dc = GetDrawingCoord(); - vs_dc_modelCoord = dc.modelCoord; - vs_dc_constantCoord = dc.constantCoord; - vs_dc_elementCoord = dc.elementCoord; - vs_dc_primitiveCoord = dc.primitiveCoord; - vs_dc_fvarCoord = dc.fvarCoord; - vs_dc_shaderCoord = dc.shaderCoord; - vs_dc_vertexCoord = dc.vertexCoord; - vs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - vs_dc_varyingCoord = dc.varyingCoord; - vs_dc_instanceIndexI0 = dc.instanceIndex[0]; + vs_interstageDrawingCoord0[0] = dc.modelCoord; + vs_interstageDrawingCoord0[1] = dc.constantCoord; + vs_interstageDrawingCoord0[2] = dc.elementCoord; + vs_interstageDrawingCoord0[3] = dc.primitiveCoord; + vs_interstageDrawingCoord1[0] = dc.fvarCoord; + vs_interstageDrawingCoord1[1] = dc.shaderCoord; + vs_interstageDrawingCoord1[2] = dc.vertexCoord; + vs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + vs_interstageDrawingCoord2[0] = dc.varyingCoord; + vs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = points; outPrimvars.normals = normals; } @@ -3548,43 +3533,27 @@ layout(std430, binding = 1) readonly buffer ssbo_primitiveParam { int primitiveP layout(std430, binding = 2) readonly buffer ssbo_edgeIndices { ivec2 edgeIndices[]; }; layout(std430, binding = 3) readonly buffer ssbo_faceVisibility { float faceVisibility[]; }; layout(std430, binding = 4) readonly buffer ssbo_dispTextureCoord { vec2 dispTextureCoord[]; }; -flat layout(location = 0) in int vs_dc_modelCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 1) in int vs_dc_constantCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 2) in int vs_dc_elementCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 3) in int vs_dc_primitiveCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 4) in int vs_dc_fvarCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 5) in int vs_dc_shaderCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 6) in int vs_dc_vertexCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 7) in int vs_dc_topologyVisibilityCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 8) in int vs_dc_varyingCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 9) in int vs_dc_instanceIndexI0[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 10) in int vs_dc_instanceCoordsI0[HD_NUM_PRIMITIVE_VERTS]; -layout(location = 11) in VertexData { +flat layout(location = 0) in ivec4 vs_interstageDrawingCoord0[HD_NUM_PRIMITIVE_VERTS]; +flat layout(location = 1) in ivec4 vs_interstageDrawingCoord1[HD_NUM_PRIMITIVE_VERTS]; +flat layout(location = 2) in ivec4 vs_interstageDrawingCoord2[HD_NUM_PRIMITIVE_VERTS]; +layout(location = 3) in VertexData { vec4 Peye; vec3 Neye; } inData[4]; -layout(location = 13) in PrimvarData { +layout(location = 5) in PrimvarData { vec3 points; vec3 normals; } inPrimvars[HD_NUM_PRIMITIVE_VERTS]; layout(location = 2) out vec4 gsPatchCoord; noperspective layout(location = 3) out vec3 hd_barycentricCoord; -flat layout(location = 7) out int gs_dc_modelCoord; -flat layout(location = 8) out int gs_dc_constantCoord; -flat layout(location = 9) out int gs_dc_elementCoord; -flat layout(location = 10) out int gs_dc_primitiveCoord; -flat layout(location = 11) out int gs_dc_fvarCoord; -flat layout(location = 12) out int gs_dc_shaderCoord; -flat layout(location = 13) out int gs_dc_vertexCoord; -flat layout(location = 14) out int gs_dc_topologyVisibilityCoord; -flat layout(location = 15) out int gs_dc_varyingCoord; -flat layout(location = 16) out int gs_dc_instanceIndexI0; -flat layout(location = 17) out int gs_dc_instanceCoordsI0; +flat layout(location = 4) out ivec4 gs_interstageDrawingCoord0; +flat layout(location = 5) out ivec4 gs_interstageDrawingCoord1; +flat layout(location = 6) out ivec4 gs_interstageDrawingCoord2; layout(location = 0) out VertexData { vec4 Peye; vec3 Neye; } outData; -layout(location = 4) out PrimvarData { +layout(location = 7) out PrimvarData { vec3 points; vec3 normals; vec2 dispTextureCoord; @@ -3635,16 +3604,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = vs_dc_modelCoord[0]; - dc.constantCoord = vs_dc_constantCoord[0]; - dc.elementCoord = vs_dc_elementCoord[0]; - dc.primitiveCoord = vs_dc_primitiveCoord[0]; - dc.fvarCoord = vs_dc_fvarCoord[0]; - dc.shaderCoord = vs_dc_shaderCoord[0]; - dc.vertexCoord = vs_dc_vertexCoord[0]; - dc.topologyVisibilityCoord = vs_dc_topologyVisibilityCoord[0]; - dc.varyingCoord = vs_dc_varyingCoord[0]; - dc.instanceIndex[0] = vs_dc_instanceIndexI0[0]; + dc.modelCoord = vs_interstageDrawingCoord0[0][0]; + dc.constantCoord = vs_interstageDrawingCoord0[0][1]; + dc.elementCoord = vs_interstageDrawingCoord0[0][2]; + dc.primitiveCoord = vs_interstageDrawingCoord0[0][3]; + dc.fvarCoord = vs_interstageDrawingCoord1[0][0]; + dc.shaderCoord = vs_interstageDrawingCoord1[0][1]; + dc.vertexCoord = vs_interstageDrawingCoord1[0][2]; + dc.topologyVisibilityCoord = vs_interstageDrawingCoord1[0][3]; + dc.varyingCoord = vs_interstageDrawingCoord2[0][0]; + dc.instanceIndex[0] = vs_interstageDrawingCoord2[0][1]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -3737,16 +3706,16 @@ void ProcessPrimvarsOut(int index) { ); hd_barycentricCoord = coords[index]; hd_drawingCoord dc = GetDrawingCoord(); - gs_dc_modelCoord = dc.modelCoord; - gs_dc_constantCoord = dc.constantCoord; - gs_dc_elementCoord = dc.elementCoord; - gs_dc_primitiveCoord = dc.primitiveCoord; - gs_dc_fvarCoord = dc.fvarCoord; - gs_dc_shaderCoord = dc.shaderCoord; - gs_dc_vertexCoord = dc.vertexCoord; - gs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - gs_dc_varyingCoord = dc.varyingCoord; - gs_dc_instanceIndexI0 = dc.instanceIndex[0]; + gs_interstageDrawingCoord0[0] = dc.modelCoord; + gs_interstageDrawingCoord0[1] = dc.constantCoord; + gs_interstageDrawingCoord0[2] = dc.elementCoord; + gs_interstageDrawingCoord0[3] = dc.primitiveCoord; + gs_interstageDrawingCoord1[0] = dc.fvarCoord; + gs_interstageDrawingCoord1[1] = dc.shaderCoord; + gs_interstageDrawingCoord1[2] = dc.vertexCoord; + gs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + gs_interstageDrawingCoord2[0] = dc.varyingCoord; + gs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = inPrimvars[index].points; outPrimvars.normals = inPrimvars[index].normals; outPrimvars.dispTextureCoord = HdGet_dispTextureCoord(index); @@ -4397,22 +4366,14 @@ layout(std430, binding = 3) readonly buffer ssbo_faceVisibility { float faceVisi layout(std430, binding = 4) readonly buffer ssbo_dispTextureCoord { vec2 dispTextureCoord[]; }; layout(location = 2) in vec4 gsPatchCoord; noperspective layout(location = 3) in vec3 hd_barycentricCoord; -flat layout(location = 7) in int gs_dc_modelCoord; -flat layout(location = 8) in int gs_dc_constantCoord; -flat layout(location = 9) in int gs_dc_elementCoord; -flat layout(location = 10) in int gs_dc_primitiveCoord; -flat layout(location = 11) in int gs_dc_fvarCoord; -flat layout(location = 12) in int gs_dc_shaderCoord; -flat layout(location = 13) in int gs_dc_vertexCoord; -flat layout(location = 14) in int gs_dc_topologyVisibilityCoord; -flat layout(location = 15) in int gs_dc_varyingCoord; -flat layout(location = 16) in int gs_dc_instanceIndexI0; -flat layout(location = 17) in int gs_dc_instanceCoordsI0; +flat layout(location = 4) in ivec4 gs_interstageDrawingCoord0; +flat layout(location = 5) in ivec4 gs_interstageDrawingCoord1; +flat layout(location = 6) in ivec4 gs_interstageDrawingCoord2; layout(location = 0) in VertexData { vec4 Peye; vec3 Neye; } inData; -layout(location = 4) in PrimvarData { +layout(location = 7) in PrimvarData { vec3 points; vec3 normals; vec2 dispTextureCoord; @@ -4468,16 +4429,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = gs_dc_modelCoord; - dc.constantCoord = gs_dc_constantCoord; - dc.elementCoord = gs_dc_elementCoord; - dc.primitiveCoord = gs_dc_primitiveCoord; - dc.fvarCoord = gs_dc_fvarCoord; - dc.shaderCoord = gs_dc_shaderCoord; - dc.vertexCoord = gs_dc_vertexCoord; - dc.topologyVisibilityCoord = gs_dc_topologyVisibilityCoord; - dc.varyingCoord = gs_dc_varyingCoord; - dc.instanceIndex[0] = gs_dc_instanceIndexI0; + dc.modelCoord = gs_interstageDrawingCoord0[0]; + dc.constantCoord = gs_interstageDrawingCoord0[1]; + dc.elementCoord = gs_interstageDrawingCoord0[2]; + dc.primitiveCoord = gs_interstageDrawingCoord0[3]; + dc.fvarCoord = gs_interstageDrawingCoord1[0]; + dc.shaderCoord = gs_interstageDrawingCoord1[1]; + dc.vertexCoord = gs_interstageDrawingCoord1[2]; + dc.topologyVisibilityCoord = gs_interstageDrawingCoord1[3]; + dc.varyingCoord = gs_interstageDrawingCoord2[0]; + dc.instanceIndex[0] = gs_interstageDrawingCoord2[1]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -4731,12 +4692,37 @@ vec4 ApplyColorOverridesPostLighting(vec4 color) -void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +void RenderColor(vec4 color) { colorOut = color; } + +void RenderId() +{ + // do nothing +} + + + +void RenderNeye(vec3 Neye) +{ + // do nothing +} + + + +void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +{ + // Write to any desired AOVs here. The render pass shader configuation + // decides if any of these are no-ops. + RenderColor(color); + RenderId(); + RenderNeye(Neye); +} + + #ifndef HD_HAS_integrateLights #define HD_HAS_integrateLights #endif diff --git a/pxr/imaging/hdSt/testenv/testHdStCodeGen_Vulkan/baseline/codegen_mesh_indirect.out b/pxr/imaging/hdSt/testenv/testHdStCodeGen_Vulkan/baseline/codegen_mesh_indirect.out index ccc3bbfadc3..27706fa6cd0 100644 --- a/pxr/imaging/hdSt/testenv/testHdStCodeGen_Vulkan/baseline/codegen_mesh_indirect.out +++ b/pxr/imaging/hdSt/testenv/testHdStCodeGen_Vulkan/baseline/codegen_mesh_indirect.out @@ -166,22 +166,14 @@ layout(location = 1) in vec3 normals; uint hd_VertexID = gl_VertexIndex; uint hd_InstanceID = gl_InstanceIndex; uint hd_BaseInstance = HgiGetBaseInstance(); -flat layout(location = 0) out int vs_dc_modelCoord; -flat layout(location = 1) out int vs_dc_constantCoord; -flat layout(location = 2) out int vs_dc_elementCoord; -flat layout(location = 3) out int vs_dc_primitiveCoord; -flat layout(location = 4) out int vs_dc_fvarCoord; -flat layout(location = 5) out int vs_dc_shaderCoord; -flat layout(location = 6) out int vs_dc_vertexCoord; -flat layout(location = 7) out int vs_dc_topologyVisibilityCoord; -flat layout(location = 8) out int vs_dc_varyingCoord; -flat layout(location = 9) out int vs_dc_instanceIndexI0; -flat layout(location = 10) out int vs_dc_instanceCoordsI0; -layout(location = 11) out VertexData { +flat layout(location = 0) out ivec4 vs_interstageDrawingCoord0; +flat layout(location = 1) out ivec4 vs_interstageDrawingCoord1; +flat layout(location = 2) out ivec4 vs_interstageDrawingCoord2; +layout(location = 3) out VertexData { vec4 Peye; vec3 Neye; } outData; -layout(location = 13) out PrimvarData { +layout(location = 5) out PrimvarData { vec3 points; vec3 normals; } outPrimvars; @@ -253,16 +245,16 @@ float HdGetScalar_normals() { return HdGet_normals(0).x; } // //////// Codegen Proc VS //////// void ProcessPrimvarsIn() { hd_drawingCoord dc = GetDrawingCoord(); - vs_dc_modelCoord = dc.modelCoord; - vs_dc_constantCoord = dc.constantCoord; - vs_dc_elementCoord = dc.elementCoord; - vs_dc_primitiveCoord = dc.primitiveCoord; - vs_dc_fvarCoord = dc.fvarCoord; - vs_dc_shaderCoord = dc.shaderCoord; - vs_dc_vertexCoord = dc.vertexCoord; - vs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - vs_dc_varyingCoord = dc.varyingCoord; - vs_dc_instanceIndexI0 = dc.instanceIndex[0]; + vs_interstageDrawingCoord0[0] = dc.modelCoord; + vs_interstageDrawingCoord0[1] = dc.constantCoord; + vs_interstageDrawingCoord0[2] = dc.elementCoord; + vs_interstageDrawingCoord0[3] = dc.primitiveCoord; + vs_interstageDrawingCoord1[0] = dc.fvarCoord; + vs_interstageDrawingCoord1[1] = dc.shaderCoord; + vs_interstageDrawingCoord1[2] = dc.vertexCoord; + vs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + vs_interstageDrawingCoord2[0] = dc.varyingCoord; + vs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = points; outPrimvars.normals = normals; } @@ -831,43 +823,27 @@ layout(std430, binding = 1) readonly buffer ssbo_primitiveParam { int primitiveP layout(std430, binding = 2) readonly buffer ssbo_edgeIndices { int edgeIndices[]; }; layout(std430, binding = 3) readonly buffer ssbo_faceVisibility { float faceVisibility[]; }; layout(std430, binding = 4) readonly buffer ssbo_dispTextureCoord { vec2 dispTextureCoord[]; }; -flat layout(location = 0) in int vs_dc_modelCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 1) in int vs_dc_constantCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 2) in int vs_dc_elementCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 3) in int vs_dc_primitiveCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 4) in int vs_dc_fvarCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 5) in int vs_dc_shaderCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 6) in int vs_dc_vertexCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 7) in int vs_dc_topologyVisibilityCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 8) in int vs_dc_varyingCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 9) in int vs_dc_instanceIndexI0[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 10) in int vs_dc_instanceCoordsI0[HD_NUM_PRIMITIVE_VERTS]; -layout(location = 11) in VertexData { +flat layout(location = 0) in ivec4 vs_interstageDrawingCoord0[HD_NUM_PRIMITIVE_VERTS]; +flat layout(location = 1) in ivec4 vs_interstageDrawingCoord1[HD_NUM_PRIMITIVE_VERTS]; +flat layout(location = 2) in ivec4 vs_interstageDrawingCoord2[HD_NUM_PRIMITIVE_VERTS]; +layout(location = 3) in VertexData { vec4 Peye; vec3 Neye; } inData[3]; -layout(location = 13) in PrimvarData { +layout(location = 5) in PrimvarData { vec3 points; vec3 normals; } inPrimvars[HD_NUM_PRIMITIVE_VERTS]; layout(location = 2) out vec4 gsPatchCoord; noperspective layout(location = 3) out vec3 hd_barycentricCoord; -flat layout(location = 7) out int gs_dc_modelCoord; -flat layout(location = 8) out int gs_dc_constantCoord; -flat layout(location = 9) out int gs_dc_elementCoord; -flat layout(location = 10) out int gs_dc_primitiveCoord; -flat layout(location = 11) out int gs_dc_fvarCoord; -flat layout(location = 12) out int gs_dc_shaderCoord; -flat layout(location = 13) out int gs_dc_vertexCoord; -flat layout(location = 14) out int gs_dc_topologyVisibilityCoord; -flat layout(location = 15) out int gs_dc_varyingCoord; -flat layout(location = 16) out int gs_dc_instanceIndexI0; -flat layout(location = 17) out int gs_dc_instanceCoordsI0; +flat layout(location = 4) out ivec4 gs_interstageDrawingCoord0; +flat layout(location = 5) out ivec4 gs_interstageDrawingCoord1; +flat layout(location = 6) out ivec4 gs_interstageDrawingCoord2; layout(location = 0) out VertexData { vec4 Peye; vec3 Neye; } outData; -layout(location = 4) out PrimvarData { +layout(location = 7) out PrimvarData { vec3 points; vec3 normals; vec2 dispTextureCoord; @@ -918,16 +894,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = vs_dc_modelCoord[0]; - dc.constantCoord = vs_dc_constantCoord[0]; - dc.elementCoord = vs_dc_elementCoord[0]; - dc.primitiveCoord = vs_dc_primitiveCoord[0]; - dc.fvarCoord = vs_dc_fvarCoord[0]; - dc.shaderCoord = vs_dc_shaderCoord[0]; - dc.vertexCoord = vs_dc_vertexCoord[0]; - dc.topologyVisibilityCoord = vs_dc_topologyVisibilityCoord[0]; - dc.varyingCoord = vs_dc_varyingCoord[0]; - dc.instanceIndex[0] = vs_dc_instanceIndexI0[0]; + dc.modelCoord = vs_interstageDrawingCoord0[0][0]; + dc.constantCoord = vs_interstageDrawingCoord0[0][1]; + dc.elementCoord = vs_interstageDrawingCoord0[0][2]; + dc.primitiveCoord = vs_interstageDrawingCoord0[0][3]; + dc.fvarCoord = vs_interstageDrawingCoord1[0][0]; + dc.shaderCoord = vs_interstageDrawingCoord1[0][1]; + dc.vertexCoord = vs_interstageDrawingCoord1[0][2]; + dc.topologyVisibilityCoord = vs_interstageDrawingCoord1[0][3]; + dc.varyingCoord = vs_interstageDrawingCoord2[0][0]; + dc.instanceIndex[0] = vs_interstageDrawingCoord2[0][1]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -1020,16 +996,16 @@ void ProcessPrimvarsOut(int index) { ); hd_barycentricCoord = coords[index]; hd_drawingCoord dc = GetDrawingCoord(); - gs_dc_modelCoord = dc.modelCoord; - gs_dc_constantCoord = dc.constantCoord; - gs_dc_elementCoord = dc.elementCoord; - gs_dc_primitiveCoord = dc.primitiveCoord; - gs_dc_fvarCoord = dc.fvarCoord; - gs_dc_shaderCoord = dc.shaderCoord; - gs_dc_vertexCoord = dc.vertexCoord; - gs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - gs_dc_varyingCoord = dc.varyingCoord; - gs_dc_instanceIndexI0 = dc.instanceIndex[0]; + gs_interstageDrawingCoord0[0] = dc.modelCoord; + gs_interstageDrawingCoord0[1] = dc.constantCoord; + gs_interstageDrawingCoord0[2] = dc.elementCoord; + gs_interstageDrawingCoord0[3] = dc.primitiveCoord; + gs_interstageDrawingCoord1[0] = dc.fvarCoord; + gs_interstageDrawingCoord1[1] = dc.shaderCoord; + gs_interstageDrawingCoord1[2] = dc.vertexCoord; + gs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + gs_interstageDrawingCoord2[0] = dc.varyingCoord; + gs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = inPrimvars[index].points; outPrimvars.normals = inPrimvars[index].normals; outPrimvars.dispTextureCoord = HdGet_dispTextureCoord(index); @@ -1651,22 +1627,14 @@ layout(std430, binding = 3) readonly buffer ssbo_faceVisibility { float faceVisi layout(std430, binding = 4) readonly buffer ssbo_dispTextureCoord { vec2 dispTextureCoord[]; }; layout(location = 2) in vec4 gsPatchCoord; noperspective layout(location = 3) in vec3 hd_barycentricCoord; -flat layout(location = 7) in int gs_dc_modelCoord; -flat layout(location = 8) in int gs_dc_constantCoord; -flat layout(location = 9) in int gs_dc_elementCoord; -flat layout(location = 10) in int gs_dc_primitiveCoord; -flat layout(location = 11) in int gs_dc_fvarCoord; -flat layout(location = 12) in int gs_dc_shaderCoord; -flat layout(location = 13) in int gs_dc_vertexCoord; -flat layout(location = 14) in int gs_dc_topologyVisibilityCoord; -flat layout(location = 15) in int gs_dc_varyingCoord; -flat layout(location = 16) in int gs_dc_instanceIndexI0; -flat layout(location = 17) in int gs_dc_instanceCoordsI0; +flat layout(location = 4) in ivec4 gs_interstageDrawingCoord0; +flat layout(location = 5) in ivec4 gs_interstageDrawingCoord1; +flat layout(location = 6) in ivec4 gs_interstageDrawingCoord2; layout(location = 0) in VertexData { vec4 Peye; vec3 Neye; } inData; -layout(location = 4) in PrimvarData { +layout(location = 7) in PrimvarData { vec3 points; vec3 normals; vec2 dispTextureCoord; @@ -1722,16 +1690,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = gs_dc_modelCoord; - dc.constantCoord = gs_dc_constantCoord; - dc.elementCoord = gs_dc_elementCoord; - dc.primitiveCoord = gs_dc_primitiveCoord; - dc.fvarCoord = gs_dc_fvarCoord; - dc.shaderCoord = gs_dc_shaderCoord; - dc.vertexCoord = gs_dc_vertexCoord; - dc.topologyVisibilityCoord = gs_dc_topologyVisibilityCoord; - dc.varyingCoord = gs_dc_varyingCoord; - dc.instanceIndex[0] = gs_dc_instanceIndexI0; + dc.modelCoord = gs_interstageDrawingCoord0[0]; + dc.constantCoord = gs_interstageDrawingCoord0[1]; + dc.elementCoord = gs_interstageDrawingCoord0[2]; + dc.primitiveCoord = gs_interstageDrawingCoord0[3]; + dc.fvarCoord = gs_interstageDrawingCoord1[0]; + dc.shaderCoord = gs_interstageDrawingCoord1[1]; + dc.vertexCoord = gs_interstageDrawingCoord1[2]; + dc.topologyVisibilityCoord = gs_interstageDrawingCoord1[3]; + dc.varyingCoord = gs_interstageDrawingCoord2[0]; + dc.instanceIndex[0] = gs_interstageDrawingCoord2[1]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -1985,12 +1953,37 @@ vec4 ApplyColorOverridesPostLighting(vec4 color) -void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +void RenderColor(vec4 color) { colorOut = color; } + +void RenderId() +{ + // do nothing +} + + + +void RenderNeye(vec3 Neye) +{ + // do nothing +} + + + +void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +{ + // Write to any desired AOVs here. The render pass shader configuation + // decides if any of these are no-ops. + RenderColor(color); + RenderId(); + RenderNeye(Neye); +} + + #ifndef HD_HAS_integrateLights #define HD_HAS_integrateLights #endif @@ -2828,22 +2821,14 @@ layout(location = 1) in vec3 normals; uint hd_VertexID = gl_VertexIndex; uint hd_InstanceID = gl_InstanceIndex; uint hd_BaseInstance = HgiGetBaseInstance(); -flat layout(location = 0) out int vs_dc_modelCoord; -flat layout(location = 1) out int vs_dc_constantCoord; -flat layout(location = 2) out int vs_dc_elementCoord; -flat layout(location = 3) out int vs_dc_primitiveCoord; -flat layout(location = 4) out int vs_dc_fvarCoord; -flat layout(location = 5) out int vs_dc_shaderCoord; -flat layout(location = 6) out int vs_dc_vertexCoord; -flat layout(location = 7) out int vs_dc_topologyVisibilityCoord; -flat layout(location = 8) out int vs_dc_varyingCoord; -flat layout(location = 9) out int vs_dc_instanceIndexI0; -flat layout(location = 10) out int vs_dc_instanceCoordsI0; -layout(location = 11) out VertexData { +flat layout(location = 0) out ivec4 vs_interstageDrawingCoord0; +flat layout(location = 1) out ivec4 vs_interstageDrawingCoord1; +flat layout(location = 2) out ivec4 vs_interstageDrawingCoord2; +layout(location = 3) out VertexData { vec4 Peye; vec3 Neye; } outData; -layout(location = 13) out PrimvarData { +layout(location = 5) out PrimvarData { vec3 points; vec3 normals; } outPrimvars; @@ -2915,16 +2900,16 @@ float HdGetScalar_normals() { return HdGet_normals(0).x; } // //////// Codegen Proc VS //////// void ProcessPrimvarsIn() { hd_drawingCoord dc = GetDrawingCoord(); - vs_dc_modelCoord = dc.modelCoord; - vs_dc_constantCoord = dc.constantCoord; - vs_dc_elementCoord = dc.elementCoord; - vs_dc_primitiveCoord = dc.primitiveCoord; - vs_dc_fvarCoord = dc.fvarCoord; - vs_dc_shaderCoord = dc.shaderCoord; - vs_dc_vertexCoord = dc.vertexCoord; - vs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - vs_dc_varyingCoord = dc.varyingCoord; - vs_dc_instanceIndexI0 = dc.instanceIndex[0]; + vs_interstageDrawingCoord0[0] = dc.modelCoord; + vs_interstageDrawingCoord0[1] = dc.constantCoord; + vs_interstageDrawingCoord0[2] = dc.elementCoord; + vs_interstageDrawingCoord0[3] = dc.primitiveCoord; + vs_interstageDrawingCoord1[0] = dc.fvarCoord; + vs_interstageDrawingCoord1[1] = dc.shaderCoord; + vs_interstageDrawingCoord1[2] = dc.vertexCoord; + vs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + vs_interstageDrawingCoord2[0] = dc.varyingCoord; + vs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = points; outPrimvars.normals = normals; } @@ -3493,43 +3478,27 @@ layout(std430, binding = 1) readonly buffer ssbo_primitiveParam { int primitiveP layout(std430, binding = 2) readonly buffer ssbo_edgeIndices { ivec2 edgeIndices[]; }; layout(std430, binding = 3) readonly buffer ssbo_faceVisibility { float faceVisibility[]; }; layout(std430, binding = 4) readonly buffer ssbo_dispTextureCoord { vec2 dispTextureCoord[]; }; -flat layout(location = 0) in int vs_dc_modelCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 1) in int vs_dc_constantCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 2) in int vs_dc_elementCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 3) in int vs_dc_primitiveCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 4) in int vs_dc_fvarCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 5) in int vs_dc_shaderCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 6) in int vs_dc_vertexCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 7) in int vs_dc_topologyVisibilityCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 8) in int vs_dc_varyingCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 9) in int vs_dc_instanceIndexI0[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 10) in int vs_dc_instanceCoordsI0[HD_NUM_PRIMITIVE_VERTS]; -layout(location = 11) in VertexData { +flat layout(location = 0) in ivec4 vs_interstageDrawingCoord0[HD_NUM_PRIMITIVE_VERTS]; +flat layout(location = 1) in ivec4 vs_interstageDrawingCoord1[HD_NUM_PRIMITIVE_VERTS]; +flat layout(location = 2) in ivec4 vs_interstageDrawingCoord2[HD_NUM_PRIMITIVE_VERTS]; +layout(location = 3) in VertexData { vec4 Peye; vec3 Neye; } inData[4]; -layout(location = 13) in PrimvarData { +layout(location = 5) in PrimvarData { vec3 points; vec3 normals; } inPrimvars[HD_NUM_PRIMITIVE_VERTS]; layout(location = 2) out vec4 gsPatchCoord; noperspective layout(location = 3) out vec3 hd_barycentricCoord; -flat layout(location = 7) out int gs_dc_modelCoord; -flat layout(location = 8) out int gs_dc_constantCoord; -flat layout(location = 9) out int gs_dc_elementCoord; -flat layout(location = 10) out int gs_dc_primitiveCoord; -flat layout(location = 11) out int gs_dc_fvarCoord; -flat layout(location = 12) out int gs_dc_shaderCoord; -flat layout(location = 13) out int gs_dc_vertexCoord; -flat layout(location = 14) out int gs_dc_topologyVisibilityCoord; -flat layout(location = 15) out int gs_dc_varyingCoord; -flat layout(location = 16) out int gs_dc_instanceIndexI0; -flat layout(location = 17) out int gs_dc_instanceCoordsI0; +flat layout(location = 4) out ivec4 gs_interstageDrawingCoord0; +flat layout(location = 5) out ivec4 gs_interstageDrawingCoord1; +flat layout(location = 6) out ivec4 gs_interstageDrawingCoord2; layout(location = 0) out VertexData { vec4 Peye; vec3 Neye; } outData; -layout(location = 4) out PrimvarData { +layout(location = 7) out PrimvarData { vec3 points; vec3 normals; vec2 dispTextureCoord; @@ -3580,16 +3549,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = vs_dc_modelCoord[0]; - dc.constantCoord = vs_dc_constantCoord[0]; - dc.elementCoord = vs_dc_elementCoord[0]; - dc.primitiveCoord = vs_dc_primitiveCoord[0]; - dc.fvarCoord = vs_dc_fvarCoord[0]; - dc.shaderCoord = vs_dc_shaderCoord[0]; - dc.vertexCoord = vs_dc_vertexCoord[0]; - dc.topologyVisibilityCoord = vs_dc_topologyVisibilityCoord[0]; - dc.varyingCoord = vs_dc_varyingCoord[0]; - dc.instanceIndex[0] = vs_dc_instanceIndexI0[0]; + dc.modelCoord = vs_interstageDrawingCoord0[0][0]; + dc.constantCoord = vs_interstageDrawingCoord0[0][1]; + dc.elementCoord = vs_interstageDrawingCoord0[0][2]; + dc.primitiveCoord = vs_interstageDrawingCoord0[0][3]; + dc.fvarCoord = vs_interstageDrawingCoord1[0][0]; + dc.shaderCoord = vs_interstageDrawingCoord1[0][1]; + dc.vertexCoord = vs_interstageDrawingCoord1[0][2]; + dc.topologyVisibilityCoord = vs_interstageDrawingCoord1[0][3]; + dc.varyingCoord = vs_interstageDrawingCoord2[0][0]; + dc.instanceIndex[0] = vs_interstageDrawingCoord2[0][1]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -3682,16 +3651,16 @@ void ProcessPrimvarsOut(int index) { ); hd_barycentricCoord = coords[index]; hd_drawingCoord dc = GetDrawingCoord(); - gs_dc_modelCoord = dc.modelCoord; - gs_dc_constantCoord = dc.constantCoord; - gs_dc_elementCoord = dc.elementCoord; - gs_dc_primitiveCoord = dc.primitiveCoord; - gs_dc_fvarCoord = dc.fvarCoord; - gs_dc_shaderCoord = dc.shaderCoord; - gs_dc_vertexCoord = dc.vertexCoord; - gs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - gs_dc_varyingCoord = dc.varyingCoord; - gs_dc_instanceIndexI0 = dc.instanceIndex[0]; + gs_interstageDrawingCoord0[0] = dc.modelCoord; + gs_interstageDrawingCoord0[1] = dc.constantCoord; + gs_interstageDrawingCoord0[2] = dc.elementCoord; + gs_interstageDrawingCoord0[3] = dc.primitiveCoord; + gs_interstageDrawingCoord1[0] = dc.fvarCoord; + gs_interstageDrawingCoord1[1] = dc.shaderCoord; + gs_interstageDrawingCoord1[2] = dc.vertexCoord; + gs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + gs_interstageDrawingCoord2[0] = dc.varyingCoord; + gs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = inPrimvars[index].points; outPrimvars.normals = inPrimvars[index].normals; outPrimvars.dispTextureCoord = HdGet_dispTextureCoord(index); @@ -4342,22 +4311,14 @@ layout(std430, binding = 3) readonly buffer ssbo_faceVisibility { float faceVisi layout(std430, binding = 4) readonly buffer ssbo_dispTextureCoord { vec2 dispTextureCoord[]; }; layout(location = 2) in vec4 gsPatchCoord; noperspective layout(location = 3) in vec3 hd_barycentricCoord; -flat layout(location = 7) in int gs_dc_modelCoord; -flat layout(location = 8) in int gs_dc_constantCoord; -flat layout(location = 9) in int gs_dc_elementCoord; -flat layout(location = 10) in int gs_dc_primitiveCoord; -flat layout(location = 11) in int gs_dc_fvarCoord; -flat layout(location = 12) in int gs_dc_shaderCoord; -flat layout(location = 13) in int gs_dc_vertexCoord; -flat layout(location = 14) in int gs_dc_topologyVisibilityCoord; -flat layout(location = 15) in int gs_dc_varyingCoord; -flat layout(location = 16) in int gs_dc_instanceIndexI0; -flat layout(location = 17) in int gs_dc_instanceCoordsI0; +flat layout(location = 4) in ivec4 gs_interstageDrawingCoord0; +flat layout(location = 5) in ivec4 gs_interstageDrawingCoord1; +flat layout(location = 6) in ivec4 gs_interstageDrawingCoord2; layout(location = 0) in VertexData { vec4 Peye; vec3 Neye; } inData; -layout(location = 4) in PrimvarData { +layout(location = 7) in PrimvarData { vec3 points; vec3 normals; vec2 dispTextureCoord; @@ -4413,16 +4374,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = gs_dc_modelCoord; - dc.constantCoord = gs_dc_constantCoord; - dc.elementCoord = gs_dc_elementCoord; - dc.primitiveCoord = gs_dc_primitiveCoord; - dc.fvarCoord = gs_dc_fvarCoord; - dc.shaderCoord = gs_dc_shaderCoord; - dc.vertexCoord = gs_dc_vertexCoord; - dc.topologyVisibilityCoord = gs_dc_topologyVisibilityCoord; - dc.varyingCoord = gs_dc_varyingCoord; - dc.instanceIndex[0] = gs_dc_instanceIndexI0; + dc.modelCoord = gs_interstageDrawingCoord0[0]; + dc.constantCoord = gs_interstageDrawingCoord0[1]; + dc.elementCoord = gs_interstageDrawingCoord0[2]; + dc.primitiveCoord = gs_interstageDrawingCoord0[3]; + dc.fvarCoord = gs_interstageDrawingCoord1[0]; + dc.shaderCoord = gs_interstageDrawingCoord1[1]; + dc.vertexCoord = gs_interstageDrawingCoord1[2]; + dc.topologyVisibilityCoord = gs_interstageDrawingCoord1[3]; + dc.varyingCoord = gs_interstageDrawingCoord2[0]; + dc.instanceIndex[0] = gs_interstageDrawingCoord2[1]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -4676,12 +4637,37 @@ vec4 ApplyColorOverridesPostLighting(vec4 color) -void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +void RenderColor(vec4 color) { colorOut = color; } + +void RenderId() +{ + // do nothing +} + + + +void RenderNeye(vec3 Neye) +{ + // do nothing +} + + + +void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +{ + // Write to any desired AOVs here. The render pass shader configuation + // decides if any of these are no-ops. + RenderColor(color); + RenderId(); + RenderNeye(Neye); +} + + #ifndef HD_HAS_integrateLights #define HD_HAS_integrateLights #endif diff --git a/pxr/imaging/hdSt/testenv/testHdStCodeGen_Vulkan/baseline/codegen_mesh_indirect_doubleSided.out b/pxr/imaging/hdSt/testenv/testHdStCodeGen_Vulkan/baseline/codegen_mesh_indirect_doubleSided.out index d5bfce162ed..fbb7744dced 100644 --- a/pxr/imaging/hdSt/testenv/testHdStCodeGen_Vulkan/baseline/codegen_mesh_indirect_doubleSided.out +++ b/pxr/imaging/hdSt/testenv/testHdStCodeGen_Vulkan/baseline/codegen_mesh_indirect_doubleSided.out @@ -166,22 +166,14 @@ layout(location = 1) in vec3 normals; uint hd_VertexID = gl_VertexIndex; uint hd_InstanceID = gl_InstanceIndex; uint hd_BaseInstance = HgiGetBaseInstance(); -flat layout(location = 0) out int vs_dc_modelCoord; -flat layout(location = 1) out int vs_dc_constantCoord; -flat layout(location = 2) out int vs_dc_elementCoord; -flat layout(location = 3) out int vs_dc_primitiveCoord; -flat layout(location = 4) out int vs_dc_fvarCoord; -flat layout(location = 5) out int vs_dc_shaderCoord; -flat layout(location = 6) out int vs_dc_vertexCoord; -flat layout(location = 7) out int vs_dc_topologyVisibilityCoord; -flat layout(location = 8) out int vs_dc_varyingCoord; -flat layout(location = 9) out int vs_dc_instanceIndexI0; -flat layout(location = 10) out int vs_dc_instanceCoordsI0; -layout(location = 11) out VertexData { +flat layout(location = 0) out ivec4 vs_interstageDrawingCoord0; +flat layout(location = 1) out ivec4 vs_interstageDrawingCoord1; +flat layout(location = 2) out ivec4 vs_interstageDrawingCoord2; +layout(location = 3) out VertexData { vec4 Peye; vec3 Neye; } outData; -layout(location = 13) out PrimvarData { +layout(location = 5) out PrimvarData { vec3 points; vec3 normals; } outPrimvars; @@ -253,16 +245,16 @@ float HdGetScalar_normals() { return HdGet_normals(0).x; } // //////// Codegen Proc VS //////// void ProcessPrimvarsIn() { hd_drawingCoord dc = GetDrawingCoord(); - vs_dc_modelCoord = dc.modelCoord; - vs_dc_constantCoord = dc.constantCoord; - vs_dc_elementCoord = dc.elementCoord; - vs_dc_primitiveCoord = dc.primitiveCoord; - vs_dc_fvarCoord = dc.fvarCoord; - vs_dc_shaderCoord = dc.shaderCoord; - vs_dc_vertexCoord = dc.vertexCoord; - vs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - vs_dc_varyingCoord = dc.varyingCoord; - vs_dc_instanceIndexI0 = dc.instanceIndex[0]; + vs_interstageDrawingCoord0[0] = dc.modelCoord; + vs_interstageDrawingCoord0[1] = dc.constantCoord; + vs_interstageDrawingCoord0[2] = dc.elementCoord; + vs_interstageDrawingCoord0[3] = dc.primitiveCoord; + vs_interstageDrawingCoord1[0] = dc.fvarCoord; + vs_interstageDrawingCoord1[1] = dc.shaderCoord; + vs_interstageDrawingCoord1[2] = dc.vertexCoord; + vs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + vs_interstageDrawingCoord2[0] = dc.varyingCoord; + vs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = points; outPrimvars.normals = normals; } @@ -831,43 +823,27 @@ layout(std430, binding = 1) readonly buffer ssbo_primitiveParam { int primitiveP layout(std430, binding = 2) readonly buffer ssbo_edgeIndices { int edgeIndices[]; }; layout(std430, binding = 3) readonly buffer ssbo_faceVisibility { float faceVisibility[]; }; layout(std430, binding = 4) readonly buffer ssbo_dispTextureCoord { vec2 dispTextureCoord[]; }; -flat layout(location = 0) in int vs_dc_modelCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 1) in int vs_dc_constantCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 2) in int vs_dc_elementCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 3) in int vs_dc_primitiveCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 4) in int vs_dc_fvarCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 5) in int vs_dc_shaderCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 6) in int vs_dc_vertexCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 7) in int vs_dc_topologyVisibilityCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 8) in int vs_dc_varyingCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 9) in int vs_dc_instanceIndexI0[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 10) in int vs_dc_instanceCoordsI0[HD_NUM_PRIMITIVE_VERTS]; -layout(location = 11) in VertexData { +flat layout(location = 0) in ivec4 vs_interstageDrawingCoord0[HD_NUM_PRIMITIVE_VERTS]; +flat layout(location = 1) in ivec4 vs_interstageDrawingCoord1[HD_NUM_PRIMITIVE_VERTS]; +flat layout(location = 2) in ivec4 vs_interstageDrawingCoord2[HD_NUM_PRIMITIVE_VERTS]; +layout(location = 3) in VertexData { vec4 Peye; vec3 Neye; } inData[3]; -layout(location = 13) in PrimvarData { +layout(location = 5) in PrimvarData { vec3 points; vec3 normals; } inPrimvars[HD_NUM_PRIMITIVE_VERTS]; layout(location = 2) out vec4 gsPatchCoord; noperspective layout(location = 3) out vec3 hd_barycentricCoord; -flat layout(location = 7) out int gs_dc_modelCoord; -flat layout(location = 8) out int gs_dc_constantCoord; -flat layout(location = 9) out int gs_dc_elementCoord; -flat layout(location = 10) out int gs_dc_primitiveCoord; -flat layout(location = 11) out int gs_dc_fvarCoord; -flat layout(location = 12) out int gs_dc_shaderCoord; -flat layout(location = 13) out int gs_dc_vertexCoord; -flat layout(location = 14) out int gs_dc_topologyVisibilityCoord; -flat layout(location = 15) out int gs_dc_varyingCoord; -flat layout(location = 16) out int gs_dc_instanceIndexI0; -flat layout(location = 17) out int gs_dc_instanceCoordsI0; +flat layout(location = 4) out ivec4 gs_interstageDrawingCoord0; +flat layout(location = 5) out ivec4 gs_interstageDrawingCoord1; +flat layout(location = 6) out ivec4 gs_interstageDrawingCoord2; layout(location = 0) out VertexData { vec4 Peye; vec3 Neye; } outData; -layout(location = 4) out PrimvarData { +layout(location = 7) out PrimvarData { vec3 points; vec3 normals; vec2 dispTextureCoord; @@ -918,16 +894,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = vs_dc_modelCoord[0]; - dc.constantCoord = vs_dc_constantCoord[0]; - dc.elementCoord = vs_dc_elementCoord[0]; - dc.primitiveCoord = vs_dc_primitiveCoord[0]; - dc.fvarCoord = vs_dc_fvarCoord[0]; - dc.shaderCoord = vs_dc_shaderCoord[0]; - dc.vertexCoord = vs_dc_vertexCoord[0]; - dc.topologyVisibilityCoord = vs_dc_topologyVisibilityCoord[0]; - dc.varyingCoord = vs_dc_varyingCoord[0]; - dc.instanceIndex[0] = vs_dc_instanceIndexI0[0]; + dc.modelCoord = vs_interstageDrawingCoord0[0][0]; + dc.constantCoord = vs_interstageDrawingCoord0[0][1]; + dc.elementCoord = vs_interstageDrawingCoord0[0][2]; + dc.primitiveCoord = vs_interstageDrawingCoord0[0][3]; + dc.fvarCoord = vs_interstageDrawingCoord1[0][0]; + dc.shaderCoord = vs_interstageDrawingCoord1[0][1]; + dc.vertexCoord = vs_interstageDrawingCoord1[0][2]; + dc.topologyVisibilityCoord = vs_interstageDrawingCoord1[0][3]; + dc.varyingCoord = vs_interstageDrawingCoord2[0][0]; + dc.instanceIndex[0] = vs_interstageDrawingCoord2[0][1]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -1020,16 +996,16 @@ void ProcessPrimvarsOut(int index) { ); hd_barycentricCoord = coords[index]; hd_drawingCoord dc = GetDrawingCoord(); - gs_dc_modelCoord = dc.modelCoord; - gs_dc_constantCoord = dc.constantCoord; - gs_dc_elementCoord = dc.elementCoord; - gs_dc_primitiveCoord = dc.primitiveCoord; - gs_dc_fvarCoord = dc.fvarCoord; - gs_dc_shaderCoord = dc.shaderCoord; - gs_dc_vertexCoord = dc.vertexCoord; - gs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - gs_dc_varyingCoord = dc.varyingCoord; - gs_dc_instanceIndexI0 = dc.instanceIndex[0]; + gs_interstageDrawingCoord0[0] = dc.modelCoord; + gs_interstageDrawingCoord0[1] = dc.constantCoord; + gs_interstageDrawingCoord0[2] = dc.elementCoord; + gs_interstageDrawingCoord0[3] = dc.primitiveCoord; + gs_interstageDrawingCoord1[0] = dc.fvarCoord; + gs_interstageDrawingCoord1[1] = dc.shaderCoord; + gs_interstageDrawingCoord1[2] = dc.vertexCoord; + gs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + gs_interstageDrawingCoord2[0] = dc.varyingCoord; + gs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = inPrimvars[index].points; outPrimvars.normals = inPrimvars[index].normals; outPrimvars.dispTextureCoord = HdGet_dispTextureCoord(index); @@ -1651,22 +1627,14 @@ layout(std430, binding = 3) readonly buffer ssbo_faceVisibility { float faceVisi layout(std430, binding = 4) readonly buffer ssbo_dispTextureCoord { vec2 dispTextureCoord[]; }; layout(location = 2) in vec4 gsPatchCoord; noperspective layout(location = 3) in vec3 hd_barycentricCoord; -flat layout(location = 7) in int gs_dc_modelCoord; -flat layout(location = 8) in int gs_dc_constantCoord; -flat layout(location = 9) in int gs_dc_elementCoord; -flat layout(location = 10) in int gs_dc_primitiveCoord; -flat layout(location = 11) in int gs_dc_fvarCoord; -flat layout(location = 12) in int gs_dc_shaderCoord; -flat layout(location = 13) in int gs_dc_vertexCoord; -flat layout(location = 14) in int gs_dc_topologyVisibilityCoord; -flat layout(location = 15) in int gs_dc_varyingCoord; -flat layout(location = 16) in int gs_dc_instanceIndexI0; -flat layout(location = 17) in int gs_dc_instanceCoordsI0; +flat layout(location = 4) in ivec4 gs_interstageDrawingCoord0; +flat layout(location = 5) in ivec4 gs_interstageDrawingCoord1; +flat layout(location = 6) in ivec4 gs_interstageDrawingCoord2; layout(location = 0) in VertexData { vec4 Peye; vec3 Neye; } inData; -layout(location = 4) in PrimvarData { +layout(location = 7) in PrimvarData { vec3 points; vec3 normals; vec2 dispTextureCoord; @@ -1722,16 +1690,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = gs_dc_modelCoord; - dc.constantCoord = gs_dc_constantCoord; - dc.elementCoord = gs_dc_elementCoord; - dc.primitiveCoord = gs_dc_primitiveCoord; - dc.fvarCoord = gs_dc_fvarCoord; - dc.shaderCoord = gs_dc_shaderCoord; - dc.vertexCoord = gs_dc_vertexCoord; - dc.topologyVisibilityCoord = gs_dc_topologyVisibilityCoord; - dc.varyingCoord = gs_dc_varyingCoord; - dc.instanceIndex[0] = gs_dc_instanceIndexI0; + dc.modelCoord = gs_interstageDrawingCoord0[0]; + dc.constantCoord = gs_interstageDrawingCoord0[1]; + dc.elementCoord = gs_interstageDrawingCoord0[2]; + dc.primitiveCoord = gs_interstageDrawingCoord0[3]; + dc.fvarCoord = gs_interstageDrawingCoord1[0]; + dc.shaderCoord = gs_interstageDrawingCoord1[1]; + dc.vertexCoord = gs_interstageDrawingCoord1[2]; + dc.topologyVisibilityCoord = gs_interstageDrawingCoord1[3]; + dc.varyingCoord = gs_interstageDrawingCoord2[0]; + dc.instanceIndex[0] = gs_interstageDrawingCoord2[1]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -1985,12 +1953,37 @@ vec4 ApplyColorOverridesPostLighting(vec4 color) -void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +void RenderColor(vec4 color) { colorOut = color; } + +void RenderId() +{ + // do nothing +} + + + +void RenderNeye(vec3 Neye) +{ + // do nothing +} + + + +void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +{ + // Write to any desired AOVs here. The render pass shader configuation + // decides if any of these are no-ops. + RenderColor(color); + RenderId(); + RenderNeye(Neye); +} + + #ifndef HD_HAS_integrateLights #define HD_HAS_integrateLights #endif @@ -2827,22 +2820,14 @@ layout(location = 1) in vec3 normals; uint hd_VertexID = gl_VertexIndex; uint hd_InstanceID = gl_InstanceIndex; uint hd_BaseInstance = HgiGetBaseInstance(); -flat layout(location = 0) out int vs_dc_modelCoord; -flat layout(location = 1) out int vs_dc_constantCoord; -flat layout(location = 2) out int vs_dc_elementCoord; -flat layout(location = 3) out int vs_dc_primitiveCoord; -flat layout(location = 4) out int vs_dc_fvarCoord; -flat layout(location = 5) out int vs_dc_shaderCoord; -flat layout(location = 6) out int vs_dc_vertexCoord; -flat layout(location = 7) out int vs_dc_topologyVisibilityCoord; -flat layout(location = 8) out int vs_dc_varyingCoord; -flat layout(location = 9) out int vs_dc_instanceIndexI0; -flat layout(location = 10) out int vs_dc_instanceCoordsI0; -layout(location = 11) out VertexData { +flat layout(location = 0) out ivec4 vs_interstageDrawingCoord0; +flat layout(location = 1) out ivec4 vs_interstageDrawingCoord1; +flat layout(location = 2) out ivec4 vs_interstageDrawingCoord2; +layout(location = 3) out VertexData { vec4 Peye; vec3 Neye; } outData; -layout(location = 13) out PrimvarData { +layout(location = 5) out PrimvarData { vec3 points; vec3 normals; } outPrimvars; @@ -2914,16 +2899,16 @@ float HdGetScalar_normals() { return HdGet_normals(0).x; } // //////// Codegen Proc VS //////// void ProcessPrimvarsIn() { hd_drawingCoord dc = GetDrawingCoord(); - vs_dc_modelCoord = dc.modelCoord; - vs_dc_constantCoord = dc.constantCoord; - vs_dc_elementCoord = dc.elementCoord; - vs_dc_primitiveCoord = dc.primitiveCoord; - vs_dc_fvarCoord = dc.fvarCoord; - vs_dc_shaderCoord = dc.shaderCoord; - vs_dc_vertexCoord = dc.vertexCoord; - vs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - vs_dc_varyingCoord = dc.varyingCoord; - vs_dc_instanceIndexI0 = dc.instanceIndex[0]; + vs_interstageDrawingCoord0[0] = dc.modelCoord; + vs_interstageDrawingCoord0[1] = dc.constantCoord; + vs_interstageDrawingCoord0[2] = dc.elementCoord; + vs_interstageDrawingCoord0[3] = dc.primitiveCoord; + vs_interstageDrawingCoord1[0] = dc.fvarCoord; + vs_interstageDrawingCoord1[1] = dc.shaderCoord; + vs_interstageDrawingCoord1[2] = dc.vertexCoord; + vs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + vs_interstageDrawingCoord2[0] = dc.varyingCoord; + vs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = points; outPrimvars.normals = normals; } @@ -3492,43 +3477,27 @@ layout(std430, binding = 1) readonly buffer ssbo_primitiveParam { int primitiveP layout(std430, binding = 2) readonly buffer ssbo_edgeIndices { ivec2 edgeIndices[]; }; layout(std430, binding = 3) readonly buffer ssbo_faceVisibility { float faceVisibility[]; }; layout(std430, binding = 4) readonly buffer ssbo_dispTextureCoord { vec2 dispTextureCoord[]; }; -flat layout(location = 0) in int vs_dc_modelCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 1) in int vs_dc_constantCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 2) in int vs_dc_elementCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 3) in int vs_dc_primitiveCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 4) in int vs_dc_fvarCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 5) in int vs_dc_shaderCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 6) in int vs_dc_vertexCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 7) in int vs_dc_topologyVisibilityCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 8) in int vs_dc_varyingCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 9) in int vs_dc_instanceIndexI0[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 10) in int vs_dc_instanceCoordsI0[HD_NUM_PRIMITIVE_VERTS]; -layout(location = 11) in VertexData { +flat layout(location = 0) in ivec4 vs_interstageDrawingCoord0[HD_NUM_PRIMITIVE_VERTS]; +flat layout(location = 1) in ivec4 vs_interstageDrawingCoord1[HD_NUM_PRIMITIVE_VERTS]; +flat layout(location = 2) in ivec4 vs_interstageDrawingCoord2[HD_NUM_PRIMITIVE_VERTS]; +layout(location = 3) in VertexData { vec4 Peye; vec3 Neye; } inData[4]; -layout(location = 13) in PrimvarData { +layout(location = 5) in PrimvarData { vec3 points; vec3 normals; } inPrimvars[HD_NUM_PRIMITIVE_VERTS]; layout(location = 2) out vec4 gsPatchCoord; noperspective layout(location = 3) out vec3 hd_barycentricCoord; -flat layout(location = 7) out int gs_dc_modelCoord; -flat layout(location = 8) out int gs_dc_constantCoord; -flat layout(location = 9) out int gs_dc_elementCoord; -flat layout(location = 10) out int gs_dc_primitiveCoord; -flat layout(location = 11) out int gs_dc_fvarCoord; -flat layout(location = 12) out int gs_dc_shaderCoord; -flat layout(location = 13) out int gs_dc_vertexCoord; -flat layout(location = 14) out int gs_dc_topologyVisibilityCoord; -flat layout(location = 15) out int gs_dc_varyingCoord; -flat layout(location = 16) out int gs_dc_instanceIndexI0; -flat layout(location = 17) out int gs_dc_instanceCoordsI0; +flat layout(location = 4) out ivec4 gs_interstageDrawingCoord0; +flat layout(location = 5) out ivec4 gs_interstageDrawingCoord1; +flat layout(location = 6) out ivec4 gs_interstageDrawingCoord2; layout(location = 0) out VertexData { vec4 Peye; vec3 Neye; } outData; -layout(location = 4) out PrimvarData { +layout(location = 7) out PrimvarData { vec3 points; vec3 normals; vec2 dispTextureCoord; @@ -3579,16 +3548,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = vs_dc_modelCoord[0]; - dc.constantCoord = vs_dc_constantCoord[0]; - dc.elementCoord = vs_dc_elementCoord[0]; - dc.primitiveCoord = vs_dc_primitiveCoord[0]; - dc.fvarCoord = vs_dc_fvarCoord[0]; - dc.shaderCoord = vs_dc_shaderCoord[0]; - dc.vertexCoord = vs_dc_vertexCoord[0]; - dc.topologyVisibilityCoord = vs_dc_topologyVisibilityCoord[0]; - dc.varyingCoord = vs_dc_varyingCoord[0]; - dc.instanceIndex[0] = vs_dc_instanceIndexI0[0]; + dc.modelCoord = vs_interstageDrawingCoord0[0][0]; + dc.constantCoord = vs_interstageDrawingCoord0[0][1]; + dc.elementCoord = vs_interstageDrawingCoord0[0][2]; + dc.primitiveCoord = vs_interstageDrawingCoord0[0][3]; + dc.fvarCoord = vs_interstageDrawingCoord1[0][0]; + dc.shaderCoord = vs_interstageDrawingCoord1[0][1]; + dc.vertexCoord = vs_interstageDrawingCoord1[0][2]; + dc.topologyVisibilityCoord = vs_interstageDrawingCoord1[0][3]; + dc.varyingCoord = vs_interstageDrawingCoord2[0][0]; + dc.instanceIndex[0] = vs_interstageDrawingCoord2[0][1]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -3681,16 +3650,16 @@ void ProcessPrimvarsOut(int index) { ); hd_barycentricCoord = coords[index]; hd_drawingCoord dc = GetDrawingCoord(); - gs_dc_modelCoord = dc.modelCoord; - gs_dc_constantCoord = dc.constantCoord; - gs_dc_elementCoord = dc.elementCoord; - gs_dc_primitiveCoord = dc.primitiveCoord; - gs_dc_fvarCoord = dc.fvarCoord; - gs_dc_shaderCoord = dc.shaderCoord; - gs_dc_vertexCoord = dc.vertexCoord; - gs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - gs_dc_varyingCoord = dc.varyingCoord; - gs_dc_instanceIndexI0 = dc.instanceIndex[0]; + gs_interstageDrawingCoord0[0] = dc.modelCoord; + gs_interstageDrawingCoord0[1] = dc.constantCoord; + gs_interstageDrawingCoord0[2] = dc.elementCoord; + gs_interstageDrawingCoord0[3] = dc.primitiveCoord; + gs_interstageDrawingCoord1[0] = dc.fvarCoord; + gs_interstageDrawingCoord1[1] = dc.shaderCoord; + gs_interstageDrawingCoord1[2] = dc.vertexCoord; + gs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + gs_interstageDrawingCoord2[0] = dc.varyingCoord; + gs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = inPrimvars[index].points; outPrimvars.normals = inPrimvars[index].normals; outPrimvars.dispTextureCoord = HdGet_dispTextureCoord(index); @@ -4341,22 +4310,14 @@ layout(std430, binding = 3) readonly buffer ssbo_faceVisibility { float faceVisi layout(std430, binding = 4) readonly buffer ssbo_dispTextureCoord { vec2 dispTextureCoord[]; }; layout(location = 2) in vec4 gsPatchCoord; noperspective layout(location = 3) in vec3 hd_barycentricCoord; -flat layout(location = 7) in int gs_dc_modelCoord; -flat layout(location = 8) in int gs_dc_constantCoord; -flat layout(location = 9) in int gs_dc_elementCoord; -flat layout(location = 10) in int gs_dc_primitiveCoord; -flat layout(location = 11) in int gs_dc_fvarCoord; -flat layout(location = 12) in int gs_dc_shaderCoord; -flat layout(location = 13) in int gs_dc_vertexCoord; -flat layout(location = 14) in int gs_dc_topologyVisibilityCoord; -flat layout(location = 15) in int gs_dc_varyingCoord; -flat layout(location = 16) in int gs_dc_instanceIndexI0; -flat layout(location = 17) in int gs_dc_instanceCoordsI0; +flat layout(location = 4) in ivec4 gs_interstageDrawingCoord0; +flat layout(location = 5) in ivec4 gs_interstageDrawingCoord1; +flat layout(location = 6) in ivec4 gs_interstageDrawingCoord2; layout(location = 0) in VertexData { vec4 Peye; vec3 Neye; } inData; -layout(location = 4) in PrimvarData { +layout(location = 7) in PrimvarData { vec3 points; vec3 normals; vec2 dispTextureCoord; @@ -4412,16 +4373,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = gs_dc_modelCoord; - dc.constantCoord = gs_dc_constantCoord; - dc.elementCoord = gs_dc_elementCoord; - dc.primitiveCoord = gs_dc_primitiveCoord; - dc.fvarCoord = gs_dc_fvarCoord; - dc.shaderCoord = gs_dc_shaderCoord; - dc.vertexCoord = gs_dc_vertexCoord; - dc.topologyVisibilityCoord = gs_dc_topologyVisibilityCoord; - dc.varyingCoord = gs_dc_varyingCoord; - dc.instanceIndex[0] = gs_dc_instanceIndexI0; + dc.modelCoord = gs_interstageDrawingCoord0[0]; + dc.constantCoord = gs_interstageDrawingCoord0[1]; + dc.elementCoord = gs_interstageDrawingCoord0[2]; + dc.primitiveCoord = gs_interstageDrawingCoord0[3]; + dc.fvarCoord = gs_interstageDrawingCoord1[0]; + dc.shaderCoord = gs_interstageDrawingCoord1[1]; + dc.vertexCoord = gs_interstageDrawingCoord1[2]; + dc.topologyVisibilityCoord = gs_interstageDrawingCoord1[3]; + dc.varyingCoord = gs_interstageDrawingCoord2[0]; + dc.instanceIndex[0] = gs_interstageDrawingCoord2[1]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -4675,12 +4636,37 @@ vec4 ApplyColorOverridesPostLighting(vec4 color) -void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +void RenderColor(vec4 color) { colorOut = color; } + +void RenderId() +{ + // do nothing +} + + + +void RenderNeye(vec3 Neye) +{ + // do nothing +} + + + +void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +{ + // Write to any desired AOVs here. The render pass shader configuation + // decides if any of these are no-ops. + RenderColor(color); + RenderId(); + RenderNeye(Neye); +} + + #ifndef HD_HAS_integrateLights #define HD_HAS_integrateLights #endif diff --git a/pxr/imaging/hdSt/testenv/testHdStCodeGen_Vulkan/baseline/codegen_mesh_indirect_faceVarying.out b/pxr/imaging/hdSt/testenv/testHdStCodeGen_Vulkan/baseline/codegen_mesh_indirect_faceVarying.out index ccc3bbfadc3..27706fa6cd0 100644 --- a/pxr/imaging/hdSt/testenv/testHdStCodeGen_Vulkan/baseline/codegen_mesh_indirect_faceVarying.out +++ b/pxr/imaging/hdSt/testenv/testHdStCodeGen_Vulkan/baseline/codegen_mesh_indirect_faceVarying.out @@ -166,22 +166,14 @@ layout(location = 1) in vec3 normals; uint hd_VertexID = gl_VertexIndex; uint hd_InstanceID = gl_InstanceIndex; uint hd_BaseInstance = HgiGetBaseInstance(); -flat layout(location = 0) out int vs_dc_modelCoord; -flat layout(location = 1) out int vs_dc_constantCoord; -flat layout(location = 2) out int vs_dc_elementCoord; -flat layout(location = 3) out int vs_dc_primitiveCoord; -flat layout(location = 4) out int vs_dc_fvarCoord; -flat layout(location = 5) out int vs_dc_shaderCoord; -flat layout(location = 6) out int vs_dc_vertexCoord; -flat layout(location = 7) out int vs_dc_topologyVisibilityCoord; -flat layout(location = 8) out int vs_dc_varyingCoord; -flat layout(location = 9) out int vs_dc_instanceIndexI0; -flat layout(location = 10) out int vs_dc_instanceCoordsI0; -layout(location = 11) out VertexData { +flat layout(location = 0) out ivec4 vs_interstageDrawingCoord0; +flat layout(location = 1) out ivec4 vs_interstageDrawingCoord1; +flat layout(location = 2) out ivec4 vs_interstageDrawingCoord2; +layout(location = 3) out VertexData { vec4 Peye; vec3 Neye; } outData; -layout(location = 13) out PrimvarData { +layout(location = 5) out PrimvarData { vec3 points; vec3 normals; } outPrimvars; @@ -253,16 +245,16 @@ float HdGetScalar_normals() { return HdGet_normals(0).x; } // //////// Codegen Proc VS //////// void ProcessPrimvarsIn() { hd_drawingCoord dc = GetDrawingCoord(); - vs_dc_modelCoord = dc.modelCoord; - vs_dc_constantCoord = dc.constantCoord; - vs_dc_elementCoord = dc.elementCoord; - vs_dc_primitiveCoord = dc.primitiveCoord; - vs_dc_fvarCoord = dc.fvarCoord; - vs_dc_shaderCoord = dc.shaderCoord; - vs_dc_vertexCoord = dc.vertexCoord; - vs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - vs_dc_varyingCoord = dc.varyingCoord; - vs_dc_instanceIndexI0 = dc.instanceIndex[0]; + vs_interstageDrawingCoord0[0] = dc.modelCoord; + vs_interstageDrawingCoord0[1] = dc.constantCoord; + vs_interstageDrawingCoord0[2] = dc.elementCoord; + vs_interstageDrawingCoord0[3] = dc.primitiveCoord; + vs_interstageDrawingCoord1[0] = dc.fvarCoord; + vs_interstageDrawingCoord1[1] = dc.shaderCoord; + vs_interstageDrawingCoord1[2] = dc.vertexCoord; + vs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + vs_interstageDrawingCoord2[0] = dc.varyingCoord; + vs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = points; outPrimvars.normals = normals; } @@ -831,43 +823,27 @@ layout(std430, binding = 1) readonly buffer ssbo_primitiveParam { int primitiveP layout(std430, binding = 2) readonly buffer ssbo_edgeIndices { int edgeIndices[]; }; layout(std430, binding = 3) readonly buffer ssbo_faceVisibility { float faceVisibility[]; }; layout(std430, binding = 4) readonly buffer ssbo_dispTextureCoord { vec2 dispTextureCoord[]; }; -flat layout(location = 0) in int vs_dc_modelCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 1) in int vs_dc_constantCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 2) in int vs_dc_elementCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 3) in int vs_dc_primitiveCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 4) in int vs_dc_fvarCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 5) in int vs_dc_shaderCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 6) in int vs_dc_vertexCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 7) in int vs_dc_topologyVisibilityCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 8) in int vs_dc_varyingCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 9) in int vs_dc_instanceIndexI0[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 10) in int vs_dc_instanceCoordsI0[HD_NUM_PRIMITIVE_VERTS]; -layout(location = 11) in VertexData { +flat layout(location = 0) in ivec4 vs_interstageDrawingCoord0[HD_NUM_PRIMITIVE_VERTS]; +flat layout(location = 1) in ivec4 vs_interstageDrawingCoord1[HD_NUM_PRIMITIVE_VERTS]; +flat layout(location = 2) in ivec4 vs_interstageDrawingCoord2[HD_NUM_PRIMITIVE_VERTS]; +layout(location = 3) in VertexData { vec4 Peye; vec3 Neye; } inData[3]; -layout(location = 13) in PrimvarData { +layout(location = 5) in PrimvarData { vec3 points; vec3 normals; } inPrimvars[HD_NUM_PRIMITIVE_VERTS]; layout(location = 2) out vec4 gsPatchCoord; noperspective layout(location = 3) out vec3 hd_barycentricCoord; -flat layout(location = 7) out int gs_dc_modelCoord; -flat layout(location = 8) out int gs_dc_constantCoord; -flat layout(location = 9) out int gs_dc_elementCoord; -flat layout(location = 10) out int gs_dc_primitiveCoord; -flat layout(location = 11) out int gs_dc_fvarCoord; -flat layout(location = 12) out int gs_dc_shaderCoord; -flat layout(location = 13) out int gs_dc_vertexCoord; -flat layout(location = 14) out int gs_dc_topologyVisibilityCoord; -flat layout(location = 15) out int gs_dc_varyingCoord; -flat layout(location = 16) out int gs_dc_instanceIndexI0; -flat layout(location = 17) out int gs_dc_instanceCoordsI0; +flat layout(location = 4) out ivec4 gs_interstageDrawingCoord0; +flat layout(location = 5) out ivec4 gs_interstageDrawingCoord1; +flat layout(location = 6) out ivec4 gs_interstageDrawingCoord2; layout(location = 0) out VertexData { vec4 Peye; vec3 Neye; } outData; -layout(location = 4) out PrimvarData { +layout(location = 7) out PrimvarData { vec3 points; vec3 normals; vec2 dispTextureCoord; @@ -918,16 +894,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = vs_dc_modelCoord[0]; - dc.constantCoord = vs_dc_constantCoord[0]; - dc.elementCoord = vs_dc_elementCoord[0]; - dc.primitiveCoord = vs_dc_primitiveCoord[0]; - dc.fvarCoord = vs_dc_fvarCoord[0]; - dc.shaderCoord = vs_dc_shaderCoord[0]; - dc.vertexCoord = vs_dc_vertexCoord[0]; - dc.topologyVisibilityCoord = vs_dc_topologyVisibilityCoord[0]; - dc.varyingCoord = vs_dc_varyingCoord[0]; - dc.instanceIndex[0] = vs_dc_instanceIndexI0[0]; + dc.modelCoord = vs_interstageDrawingCoord0[0][0]; + dc.constantCoord = vs_interstageDrawingCoord0[0][1]; + dc.elementCoord = vs_interstageDrawingCoord0[0][2]; + dc.primitiveCoord = vs_interstageDrawingCoord0[0][3]; + dc.fvarCoord = vs_interstageDrawingCoord1[0][0]; + dc.shaderCoord = vs_interstageDrawingCoord1[0][1]; + dc.vertexCoord = vs_interstageDrawingCoord1[0][2]; + dc.topologyVisibilityCoord = vs_interstageDrawingCoord1[0][3]; + dc.varyingCoord = vs_interstageDrawingCoord2[0][0]; + dc.instanceIndex[0] = vs_interstageDrawingCoord2[0][1]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -1020,16 +996,16 @@ void ProcessPrimvarsOut(int index) { ); hd_barycentricCoord = coords[index]; hd_drawingCoord dc = GetDrawingCoord(); - gs_dc_modelCoord = dc.modelCoord; - gs_dc_constantCoord = dc.constantCoord; - gs_dc_elementCoord = dc.elementCoord; - gs_dc_primitiveCoord = dc.primitiveCoord; - gs_dc_fvarCoord = dc.fvarCoord; - gs_dc_shaderCoord = dc.shaderCoord; - gs_dc_vertexCoord = dc.vertexCoord; - gs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - gs_dc_varyingCoord = dc.varyingCoord; - gs_dc_instanceIndexI0 = dc.instanceIndex[0]; + gs_interstageDrawingCoord0[0] = dc.modelCoord; + gs_interstageDrawingCoord0[1] = dc.constantCoord; + gs_interstageDrawingCoord0[2] = dc.elementCoord; + gs_interstageDrawingCoord0[3] = dc.primitiveCoord; + gs_interstageDrawingCoord1[0] = dc.fvarCoord; + gs_interstageDrawingCoord1[1] = dc.shaderCoord; + gs_interstageDrawingCoord1[2] = dc.vertexCoord; + gs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + gs_interstageDrawingCoord2[0] = dc.varyingCoord; + gs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = inPrimvars[index].points; outPrimvars.normals = inPrimvars[index].normals; outPrimvars.dispTextureCoord = HdGet_dispTextureCoord(index); @@ -1651,22 +1627,14 @@ layout(std430, binding = 3) readonly buffer ssbo_faceVisibility { float faceVisi layout(std430, binding = 4) readonly buffer ssbo_dispTextureCoord { vec2 dispTextureCoord[]; }; layout(location = 2) in vec4 gsPatchCoord; noperspective layout(location = 3) in vec3 hd_barycentricCoord; -flat layout(location = 7) in int gs_dc_modelCoord; -flat layout(location = 8) in int gs_dc_constantCoord; -flat layout(location = 9) in int gs_dc_elementCoord; -flat layout(location = 10) in int gs_dc_primitiveCoord; -flat layout(location = 11) in int gs_dc_fvarCoord; -flat layout(location = 12) in int gs_dc_shaderCoord; -flat layout(location = 13) in int gs_dc_vertexCoord; -flat layout(location = 14) in int gs_dc_topologyVisibilityCoord; -flat layout(location = 15) in int gs_dc_varyingCoord; -flat layout(location = 16) in int gs_dc_instanceIndexI0; -flat layout(location = 17) in int gs_dc_instanceCoordsI0; +flat layout(location = 4) in ivec4 gs_interstageDrawingCoord0; +flat layout(location = 5) in ivec4 gs_interstageDrawingCoord1; +flat layout(location = 6) in ivec4 gs_interstageDrawingCoord2; layout(location = 0) in VertexData { vec4 Peye; vec3 Neye; } inData; -layout(location = 4) in PrimvarData { +layout(location = 7) in PrimvarData { vec3 points; vec3 normals; vec2 dispTextureCoord; @@ -1722,16 +1690,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = gs_dc_modelCoord; - dc.constantCoord = gs_dc_constantCoord; - dc.elementCoord = gs_dc_elementCoord; - dc.primitiveCoord = gs_dc_primitiveCoord; - dc.fvarCoord = gs_dc_fvarCoord; - dc.shaderCoord = gs_dc_shaderCoord; - dc.vertexCoord = gs_dc_vertexCoord; - dc.topologyVisibilityCoord = gs_dc_topologyVisibilityCoord; - dc.varyingCoord = gs_dc_varyingCoord; - dc.instanceIndex[0] = gs_dc_instanceIndexI0; + dc.modelCoord = gs_interstageDrawingCoord0[0]; + dc.constantCoord = gs_interstageDrawingCoord0[1]; + dc.elementCoord = gs_interstageDrawingCoord0[2]; + dc.primitiveCoord = gs_interstageDrawingCoord0[3]; + dc.fvarCoord = gs_interstageDrawingCoord1[0]; + dc.shaderCoord = gs_interstageDrawingCoord1[1]; + dc.vertexCoord = gs_interstageDrawingCoord1[2]; + dc.topologyVisibilityCoord = gs_interstageDrawingCoord1[3]; + dc.varyingCoord = gs_interstageDrawingCoord2[0]; + dc.instanceIndex[0] = gs_interstageDrawingCoord2[1]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -1985,12 +1953,37 @@ vec4 ApplyColorOverridesPostLighting(vec4 color) -void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +void RenderColor(vec4 color) { colorOut = color; } + +void RenderId() +{ + // do nothing +} + + + +void RenderNeye(vec3 Neye) +{ + // do nothing +} + + + +void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +{ + // Write to any desired AOVs here. The render pass shader configuation + // decides if any of these are no-ops. + RenderColor(color); + RenderId(); + RenderNeye(Neye); +} + + #ifndef HD_HAS_integrateLights #define HD_HAS_integrateLights #endif @@ -2828,22 +2821,14 @@ layout(location = 1) in vec3 normals; uint hd_VertexID = gl_VertexIndex; uint hd_InstanceID = gl_InstanceIndex; uint hd_BaseInstance = HgiGetBaseInstance(); -flat layout(location = 0) out int vs_dc_modelCoord; -flat layout(location = 1) out int vs_dc_constantCoord; -flat layout(location = 2) out int vs_dc_elementCoord; -flat layout(location = 3) out int vs_dc_primitiveCoord; -flat layout(location = 4) out int vs_dc_fvarCoord; -flat layout(location = 5) out int vs_dc_shaderCoord; -flat layout(location = 6) out int vs_dc_vertexCoord; -flat layout(location = 7) out int vs_dc_topologyVisibilityCoord; -flat layout(location = 8) out int vs_dc_varyingCoord; -flat layout(location = 9) out int vs_dc_instanceIndexI0; -flat layout(location = 10) out int vs_dc_instanceCoordsI0; -layout(location = 11) out VertexData { +flat layout(location = 0) out ivec4 vs_interstageDrawingCoord0; +flat layout(location = 1) out ivec4 vs_interstageDrawingCoord1; +flat layout(location = 2) out ivec4 vs_interstageDrawingCoord2; +layout(location = 3) out VertexData { vec4 Peye; vec3 Neye; } outData; -layout(location = 13) out PrimvarData { +layout(location = 5) out PrimvarData { vec3 points; vec3 normals; } outPrimvars; @@ -2915,16 +2900,16 @@ float HdGetScalar_normals() { return HdGet_normals(0).x; } // //////// Codegen Proc VS //////// void ProcessPrimvarsIn() { hd_drawingCoord dc = GetDrawingCoord(); - vs_dc_modelCoord = dc.modelCoord; - vs_dc_constantCoord = dc.constantCoord; - vs_dc_elementCoord = dc.elementCoord; - vs_dc_primitiveCoord = dc.primitiveCoord; - vs_dc_fvarCoord = dc.fvarCoord; - vs_dc_shaderCoord = dc.shaderCoord; - vs_dc_vertexCoord = dc.vertexCoord; - vs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - vs_dc_varyingCoord = dc.varyingCoord; - vs_dc_instanceIndexI0 = dc.instanceIndex[0]; + vs_interstageDrawingCoord0[0] = dc.modelCoord; + vs_interstageDrawingCoord0[1] = dc.constantCoord; + vs_interstageDrawingCoord0[2] = dc.elementCoord; + vs_interstageDrawingCoord0[3] = dc.primitiveCoord; + vs_interstageDrawingCoord1[0] = dc.fvarCoord; + vs_interstageDrawingCoord1[1] = dc.shaderCoord; + vs_interstageDrawingCoord1[2] = dc.vertexCoord; + vs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + vs_interstageDrawingCoord2[0] = dc.varyingCoord; + vs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = points; outPrimvars.normals = normals; } @@ -3493,43 +3478,27 @@ layout(std430, binding = 1) readonly buffer ssbo_primitiveParam { int primitiveP layout(std430, binding = 2) readonly buffer ssbo_edgeIndices { ivec2 edgeIndices[]; }; layout(std430, binding = 3) readonly buffer ssbo_faceVisibility { float faceVisibility[]; }; layout(std430, binding = 4) readonly buffer ssbo_dispTextureCoord { vec2 dispTextureCoord[]; }; -flat layout(location = 0) in int vs_dc_modelCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 1) in int vs_dc_constantCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 2) in int vs_dc_elementCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 3) in int vs_dc_primitiveCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 4) in int vs_dc_fvarCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 5) in int vs_dc_shaderCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 6) in int vs_dc_vertexCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 7) in int vs_dc_topologyVisibilityCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 8) in int vs_dc_varyingCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 9) in int vs_dc_instanceIndexI0[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 10) in int vs_dc_instanceCoordsI0[HD_NUM_PRIMITIVE_VERTS]; -layout(location = 11) in VertexData { +flat layout(location = 0) in ivec4 vs_interstageDrawingCoord0[HD_NUM_PRIMITIVE_VERTS]; +flat layout(location = 1) in ivec4 vs_interstageDrawingCoord1[HD_NUM_PRIMITIVE_VERTS]; +flat layout(location = 2) in ivec4 vs_interstageDrawingCoord2[HD_NUM_PRIMITIVE_VERTS]; +layout(location = 3) in VertexData { vec4 Peye; vec3 Neye; } inData[4]; -layout(location = 13) in PrimvarData { +layout(location = 5) in PrimvarData { vec3 points; vec3 normals; } inPrimvars[HD_NUM_PRIMITIVE_VERTS]; layout(location = 2) out vec4 gsPatchCoord; noperspective layout(location = 3) out vec3 hd_barycentricCoord; -flat layout(location = 7) out int gs_dc_modelCoord; -flat layout(location = 8) out int gs_dc_constantCoord; -flat layout(location = 9) out int gs_dc_elementCoord; -flat layout(location = 10) out int gs_dc_primitiveCoord; -flat layout(location = 11) out int gs_dc_fvarCoord; -flat layout(location = 12) out int gs_dc_shaderCoord; -flat layout(location = 13) out int gs_dc_vertexCoord; -flat layout(location = 14) out int gs_dc_topologyVisibilityCoord; -flat layout(location = 15) out int gs_dc_varyingCoord; -flat layout(location = 16) out int gs_dc_instanceIndexI0; -flat layout(location = 17) out int gs_dc_instanceCoordsI0; +flat layout(location = 4) out ivec4 gs_interstageDrawingCoord0; +flat layout(location = 5) out ivec4 gs_interstageDrawingCoord1; +flat layout(location = 6) out ivec4 gs_interstageDrawingCoord2; layout(location = 0) out VertexData { vec4 Peye; vec3 Neye; } outData; -layout(location = 4) out PrimvarData { +layout(location = 7) out PrimvarData { vec3 points; vec3 normals; vec2 dispTextureCoord; @@ -3580,16 +3549,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = vs_dc_modelCoord[0]; - dc.constantCoord = vs_dc_constantCoord[0]; - dc.elementCoord = vs_dc_elementCoord[0]; - dc.primitiveCoord = vs_dc_primitiveCoord[0]; - dc.fvarCoord = vs_dc_fvarCoord[0]; - dc.shaderCoord = vs_dc_shaderCoord[0]; - dc.vertexCoord = vs_dc_vertexCoord[0]; - dc.topologyVisibilityCoord = vs_dc_topologyVisibilityCoord[0]; - dc.varyingCoord = vs_dc_varyingCoord[0]; - dc.instanceIndex[0] = vs_dc_instanceIndexI0[0]; + dc.modelCoord = vs_interstageDrawingCoord0[0][0]; + dc.constantCoord = vs_interstageDrawingCoord0[0][1]; + dc.elementCoord = vs_interstageDrawingCoord0[0][2]; + dc.primitiveCoord = vs_interstageDrawingCoord0[0][3]; + dc.fvarCoord = vs_interstageDrawingCoord1[0][0]; + dc.shaderCoord = vs_interstageDrawingCoord1[0][1]; + dc.vertexCoord = vs_interstageDrawingCoord1[0][2]; + dc.topologyVisibilityCoord = vs_interstageDrawingCoord1[0][3]; + dc.varyingCoord = vs_interstageDrawingCoord2[0][0]; + dc.instanceIndex[0] = vs_interstageDrawingCoord2[0][1]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -3682,16 +3651,16 @@ void ProcessPrimvarsOut(int index) { ); hd_barycentricCoord = coords[index]; hd_drawingCoord dc = GetDrawingCoord(); - gs_dc_modelCoord = dc.modelCoord; - gs_dc_constantCoord = dc.constantCoord; - gs_dc_elementCoord = dc.elementCoord; - gs_dc_primitiveCoord = dc.primitiveCoord; - gs_dc_fvarCoord = dc.fvarCoord; - gs_dc_shaderCoord = dc.shaderCoord; - gs_dc_vertexCoord = dc.vertexCoord; - gs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - gs_dc_varyingCoord = dc.varyingCoord; - gs_dc_instanceIndexI0 = dc.instanceIndex[0]; + gs_interstageDrawingCoord0[0] = dc.modelCoord; + gs_interstageDrawingCoord0[1] = dc.constantCoord; + gs_interstageDrawingCoord0[2] = dc.elementCoord; + gs_interstageDrawingCoord0[3] = dc.primitiveCoord; + gs_interstageDrawingCoord1[0] = dc.fvarCoord; + gs_interstageDrawingCoord1[1] = dc.shaderCoord; + gs_interstageDrawingCoord1[2] = dc.vertexCoord; + gs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + gs_interstageDrawingCoord2[0] = dc.varyingCoord; + gs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = inPrimvars[index].points; outPrimvars.normals = inPrimvars[index].normals; outPrimvars.dispTextureCoord = HdGet_dispTextureCoord(index); @@ -4342,22 +4311,14 @@ layout(std430, binding = 3) readonly buffer ssbo_faceVisibility { float faceVisi layout(std430, binding = 4) readonly buffer ssbo_dispTextureCoord { vec2 dispTextureCoord[]; }; layout(location = 2) in vec4 gsPatchCoord; noperspective layout(location = 3) in vec3 hd_barycentricCoord; -flat layout(location = 7) in int gs_dc_modelCoord; -flat layout(location = 8) in int gs_dc_constantCoord; -flat layout(location = 9) in int gs_dc_elementCoord; -flat layout(location = 10) in int gs_dc_primitiveCoord; -flat layout(location = 11) in int gs_dc_fvarCoord; -flat layout(location = 12) in int gs_dc_shaderCoord; -flat layout(location = 13) in int gs_dc_vertexCoord; -flat layout(location = 14) in int gs_dc_topologyVisibilityCoord; -flat layout(location = 15) in int gs_dc_varyingCoord; -flat layout(location = 16) in int gs_dc_instanceIndexI0; -flat layout(location = 17) in int gs_dc_instanceCoordsI0; +flat layout(location = 4) in ivec4 gs_interstageDrawingCoord0; +flat layout(location = 5) in ivec4 gs_interstageDrawingCoord1; +flat layout(location = 6) in ivec4 gs_interstageDrawingCoord2; layout(location = 0) in VertexData { vec4 Peye; vec3 Neye; } inData; -layout(location = 4) in PrimvarData { +layout(location = 7) in PrimvarData { vec3 points; vec3 normals; vec2 dispTextureCoord; @@ -4413,16 +4374,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = gs_dc_modelCoord; - dc.constantCoord = gs_dc_constantCoord; - dc.elementCoord = gs_dc_elementCoord; - dc.primitiveCoord = gs_dc_primitiveCoord; - dc.fvarCoord = gs_dc_fvarCoord; - dc.shaderCoord = gs_dc_shaderCoord; - dc.vertexCoord = gs_dc_vertexCoord; - dc.topologyVisibilityCoord = gs_dc_topologyVisibilityCoord; - dc.varyingCoord = gs_dc_varyingCoord; - dc.instanceIndex[0] = gs_dc_instanceIndexI0; + dc.modelCoord = gs_interstageDrawingCoord0[0]; + dc.constantCoord = gs_interstageDrawingCoord0[1]; + dc.elementCoord = gs_interstageDrawingCoord0[2]; + dc.primitiveCoord = gs_interstageDrawingCoord0[3]; + dc.fvarCoord = gs_interstageDrawingCoord1[0]; + dc.shaderCoord = gs_interstageDrawingCoord1[1]; + dc.vertexCoord = gs_interstageDrawingCoord1[2]; + dc.topologyVisibilityCoord = gs_interstageDrawingCoord1[3]; + dc.varyingCoord = gs_interstageDrawingCoord2[0]; + dc.instanceIndex[0] = gs_interstageDrawingCoord2[1]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -4676,12 +4637,37 @@ vec4 ApplyColorOverridesPostLighting(vec4 color) -void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +void RenderColor(vec4 color) { colorOut = color; } + +void RenderId() +{ + // do nothing +} + + + +void RenderNeye(vec3 Neye) +{ + // do nothing +} + + + +void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +{ + // Write to any desired AOVs here. The render pass shader configuation + // decides if any of these are no-ops. + RenderColor(color); + RenderId(); + RenderNeye(Neye); +} + + #ifndef HD_HAS_integrateLights #define HD_HAS_integrateLights #endif diff --git a/pxr/imaging/hdSt/testenv/testHdStCodeGen_Vulkan/baseline/codegen_mesh_indirect_instance.out b/pxr/imaging/hdSt/testenv/testHdStCodeGen_Vulkan/baseline/codegen_mesh_indirect_instance.out index 067d4f433a7..ae48e42cba9 100644 --- a/pxr/imaging/hdSt/testenv/testHdStCodeGen_Vulkan/baseline/codegen_mesh_indirect_instance.out +++ b/pxr/imaging/hdSt/testenv/testHdStCodeGen_Vulkan/baseline/codegen_mesh_indirect_instance.out @@ -172,24 +172,15 @@ layout(location = 1) in vec3 normals; uint hd_VertexID = gl_VertexIndex; uint hd_InstanceID = gl_InstanceIndex; uint hd_BaseInstance = HgiGetBaseInstance(); -flat layout(location = 0) out int vs_dc_modelCoord; -flat layout(location = 1) out int vs_dc_constantCoord; -flat layout(location = 2) out int vs_dc_elementCoord; -flat layout(location = 3) out int vs_dc_primitiveCoord; -flat layout(location = 4) out int vs_dc_fvarCoord; -flat layout(location = 5) out int vs_dc_shaderCoord; -flat layout(location = 6) out int vs_dc_vertexCoord; -flat layout(location = 7) out int vs_dc_topologyVisibilityCoord; -flat layout(location = 8) out int vs_dc_varyingCoord; -flat layout(location = 9) out int vs_dc_instanceIndexI0; -flat layout(location = 10) out int vs_dc_instanceIndexI1; -flat layout(location = 11) out int vs_dc_instanceCoordsI0; -flat layout(location = 12) out int vs_dc_instanceCoordsI1; -layout(location = 13) out VertexData { +flat layout(location = 0) out ivec4 vs_interstageDrawingCoord0; +flat layout(location = 1) out ivec4 vs_interstageDrawingCoord1; +flat layout(location = 2) out ivec4 vs_interstageDrawingCoord2; +flat layout(location = 3) out ivec4 vs_interstageDrawingCoord3; +layout(location = 4) out VertexData { vec4 Peye; vec3 Neye; } outData; -layout(location = 15) out PrimvarData { +layout(location = 6) out PrimvarData { vec3 points; vec3 normals; } outPrimvars; @@ -302,18 +293,18 @@ float HdGetScalar_normals() { return HdGet_normals(0).x; } // //////// Codegen Proc VS //////// void ProcessPrimvarsIn() { hd_drawingCoord dc = GetDrawingCoord(); - vs_dc_modelCoord = dc.modelCoord; - vs_dc_constantCoord = dc.constantCoord; - vs_dc_elementCoord = dc.elementCoord; - vs_dc_primitiveCoord = dc.primitiveCoord; - vs_dc_fvarCoord = dc.fvarCoord; - vs_dc_shaderCoord = dc.shaderCoord; - vs_dc_vertexCoord = dc.vertexCoord; - vs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - vs_dc_varyingCoord = dc.varyingCoord; - vs_dc_instanceIndexI0 = dc.instanceIndex[0]; - vs_dc_instanceIndexI1 = dc.instanceIndex[1]; - vs_dc_instanceCoordsI0 = dc.instanceCoords[0]; + vs_interstageDrawingCoord0[0] = dc.modelCoord; + vs_interstageDrawingCoord0[1] = dc.constantCoord; + vs_interstageDrawingCoord0[2] = dc.elementCoord; + vs_interstageDrawingCoord0[3] = dc.primitiveCoord; + vs_interstageDrawingCoord1[0] = dc.fvarCoord; + vs_interstageDrawingCoord1[1] = dc.shaderCoord; + vs_interstageDrawingCoord1[2] = dc.vertexCoord; + vs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + vs_interstageDrawingCoord2[0] = dc.varyingCoord; + vs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; + vs_interstageDrawingCoord2[2] = dc.instanceIndex[1]; + vs_interstageDrawingCoord2[3] = dc.instanceCoords[0]; outPrimvars.points = points; outPrimvars.normals = normals; } @@ -887,47 +878,29 @@ layout(std430, binding = 2) readonly buffer ssbo_primitiveParam { int primitiveP layout(std430, binding = 3) readonly buffer ssbo_edgeIndices { int edgeIndices[]; }; layout(std430, binding = 4) readonly buffer ssbo_faceVisibility { float faceVisibility[]; }; layout(std430, binding = 5) readonly buffer ssbo_dispTextureCoord { vec2 dispTextureCoord[]; }; -flat layout(location = 0) in int vs_dc_modelCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 1) in int vs_dc_constantCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 2) in int vs_dc_elementCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 3) in int vs_dc_primitiveCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 4) in int vs_dc_fvarCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 5) in int vs_dc_shaderCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 6) in int vs_dc_vertexCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 7) in int vs_dc_topologyVisibilityCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 8) in int vs_dc_varyingCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 9) in int vs_dc_instanceIndexI0[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 10) in int vs_dc_instanceIndexI1[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 11) in int vs_dc_instanceCoordsI0[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 12) in int vs_dc_instanceCoordsI1[HD_NUM_PRIMITIVE_VERTS]; -layout(location = 13) in VertexData { +flat layout(location = 0) in ivec4 vs_interstageDrawingCoord0[HD_NUM_PRIMITIVE_VERTS]; +flat layout(location = 1) in ivec4 vs_interstageDrawingCoord1[HD_NUM_PRIMITIVE_VERTS]; +flat layout(location = 2) in ivec4 vs_interstageDrawingCoord2[HD_NUM_PRIMITIVE_VERTS]; +flat layout(location = 3) in ivec4 vs_interstageDrawingCoord3[HD_NUM_PRIMITIVE_VERTS]; +layout(location = 4) in VertexData { vec4 Peye; vec3 Neye; } inData[3]; -layout(location = 15) in PrimvarData { +layout(location = 6) in PrimvarData { vec3 points; vec3 normals; } inPrimvars[HD_NUM_PRIMITIVE_VERTS]; layout(location = 2) out vec4 gsPatchCoord; noperspective layout(location = 3) out vec3 hd_barycentricCoord; -flat layout(location = 7) out int gs_dc_modelCoord; -flat layout(location = 8) out int gs_dc_constantCoord; -flat layout(location = 9) out int gs_dc_elementCoord; -flat layout(location = 10) out int gs_dc_primitiveCoord; -flat layout(location = 11) out int gs_dc_fvarCoord; -flat layout(location = 12) out int gs_dc_shaderCoord; -flat layout(location = 13) out int gs_dc_vertexCoord; -flat layout(location = 14) out int gs_dc_topologyVisibilityCoord; -flat layout(location = 15) out int gs_dc_varyingCoord; -flat layout(location = 16) out int gs_dc_instanceIndexI0; -flat layout(location = 17) out int gs_dc_instanceIndexI1; -flat layout(location = 18) out int gs_dc_instanceCoordsI0; -flat layout(location = 19) out int gs_dc_instanceCoordsI1; +flat layout(location = 4) out ivec4 gs_interstageDrawingCoord0; +flat layout(location = 5) out ivec4 gs_interstageDrawingCoord1; +flat layout(location = 6) out ivec4 gs_interstageDrawingCoord2; +flat layout(location = 7) out ivec4 gs_interstageDrawingCoord3; layout(location = 0) out VertexData { vec4 Peye; vec3 Neye; } outData; -layout(location = 4) out PrimvarData { +layout(location = 8) out PrimvarData { vec3 points; vec3 normals; vec2 dispTextureCoord; @@ -996,18 +969,18 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = vs_dc_modelCoord[0]; - dc.constantCoord = vs_dc_constantCoord[0]; - dc.elementCoord = vs_dc_elementCoord[0]; - dc.primitiveCoord = vs_dc_primitiveCoord[0]; - dc.fvarCoord = vs_dc_fvarCoord[0]; - dc.shaderCoord = vs_dc_shaderCoord[0]; - dc.vertexCoord = vs_dc_vertexCoord[0]; - dc.topologyVisibilityCoord = vs_dc_topologyVisibilityCoord[0]; - dc.varyingCoord = vs_dc_varyingCoord[0]; - dc.instanceIndex[0] = vs_dc_instanceIndexI0[0]; - dc.instanceIndex[1] = vs_dc_instanceIndexI1[0]; - dc.instanceCoords[0] = vs_dc_instanceCoordsI0[0]; + dc.modelCoord = vs_interstageDrawingCoord0[0][0]; + dc.constantCoord = vs_interstageDrawingCoord0[0][1]; + dc.elementCoord = vs_interstageDrawingCoord0[0][2]; + dc.primitiveCoord = vs_interstageDrawingCoord0[0][3]; + dc.fvarCoord = vs_interstageDrawingCoord1[0][0]; + dc.shaderCoord = vs_interstageDrawingCoord1[0][1]; + dc.vertexCoord = vs_interstageDrawingCoord1[0][2]; + dc.topologyVisibilityCoord = vs_interstageDrawingCoord1[0][3]; + dc.varyingCoord = vs_interstageDrawingCoord2[0][0]; + dc.instanceIndex[0] = vs_interstageDrawingCoord2[0][1]; + dc.instanceIndex[1] = vs_interstageDrawingCoord2[0][2]; + dc.instanceCoords[0] = vs_interstageDrawingCoord2[0][3]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -1100,18 +1073,18 @@ void ProcessPrimvarsOut(int index) { ); hd_barycentricCoord = coords[index]; hd_drawingCoord dc = GetDrawingCoord(); - gs_dc_modelCoord = dc.modelCoord; - gs_dc_constantCoord = dc.constantCoord; - gs_dc_elementCoord = dc.elementCoord; - gs_dc_primitiveCoord = dc.primitiveCoord; - gs_dc_fvarCoord = dc.fvarCoord; - gs_dc_shaderCoord = dc.shaderCoord; - gs_dc_vertexCoord = dc.vertexCoord; - gs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - gs_dc_varyingCoord = dc.varyingCoord; - gs_dc_instanceIndexI0 = dc.instanceIndex[0]; - gs_dc_instanceIndexI1 = dc.instanceIndex[1]; - gs_dc_instanceCoordsI0 = dc.instanceCoords[0]; + gs_interstageDrawingCoord0[0] = dc.modelCoord; + gs_interstageDrawingCoord0[1] = dc.constantCoord; + gs_interstageDrawingCoord0[2] = dc.elementCoord; + gs_interstageDrawingCoord0[3] = dc.primitiveCoord; + gs_interstageDrawingCoord1[0] = dc.fvarCoord; + gs_interstageDrawingCoord1[1] = dc.shaderCoord; + gs_interstageDrawingCoord1[2] = dc.vertexCoord; + gs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + gs_interstageDrawingCoord2[0] = dc.varyingCoord; + gs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; + gs_interstageDrawingCoord2[2] = dc.instanceIndex[1]; + gs_interstageDrawingCoord2[3] = dc.instanceCoords[0]; outPrimvars.points = inPrimvars[index].points; outPrimvars.normals = inPrimvars[index].normals; outPrimvars.dispTextureCoord = HdGet_dispTextureCoord(index); @@ -1738,24 +1711,15 @@ layout(std430, binding = 4) readonly buffer ssbo_faceVisibility { float faceVisi layout(std430, binding = 5) readonly buffer ssbo_dispTextureCoord { vec2 dispTextureCoord[]; }; layout(location = 2) in vec4 gsPatchCoord; noperspective layout(location = 3) in vec3 hd_barycentricCoord; -flat layout(location = 7) in int gs_dc_modelCoord; -flat layout(location = 8) in int gs_dc_constantCoord; -flat layout(location = 9) in int gs_dc_elementCoord; -flat layout(location = 10) in int gs_dc_primitiveCoord; -flat layout(location = 11) in int gs_dc_fvarCoord; -flat layout(location = 12) in int gs_dc_shaderCoord; -flat layout(location = 13) in int gs_dc_vertexCoord; -flat layout(location = 14) in int gs_dc_topologyVisibilityCoord; -flat layout(location = 15) in int gs_dc_varyingCoord; -flat layout(location = 16) in int gs_dc_instanceIndexI0; -flat layout(location = 17) in int gs_dc_instanceIndexI1; -flat layout(location = 18) in int gs_dc_instanceCoordsI0; -flat layout(location = 19) in int gs_dc_instanceCoordsI1; +flat layout(location = 4) in ivec4 gs_interstageDrawingCoord0; +flat layout(location = 5) in ivec4 gs_interstageDrawingCoord1; +flat layout(location = 6) in ivec4 gs_interstageDrawingCoord2; +flat layout(location = 7) in ivec4 gs_interstageDrawingCoord3; layout(location = 0) in VertexData { vec4 Peye; vec3 Neye; } inData; -layout(location = 4) in PrimvarData { +layout(location = 8) in PrimvarData { vec3 points; vec3 normals; vec2 dispTextureCoord; @@ -1829,18 +1793,18 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = gs_dc_modelCoord; - dc.constantCoord = gs_dc_constantCoord; - dc.elementCoord = gs_dc_elementCoord; - dc.primitiveCoord = gs_dc_primitiveCoord; - dc.fvarCoord = gs_dc_fvarCoord; - dc.shaderCoord = gs_dc_shaderCoord; - dc.vertexCoord = gs_dc_vertexCoord; - dc.topologyVisibilityCoord = gs_dc_topologyVisibilityCoord; - dc.varyingCoord = gs_dc_varyingCoord; - dc.instanceIndex[0] = gs_dc_instanceIndexI0; - dc.instanceIndex[1] = gs_dc_instanceIndexI1; - dc.instanceCoords[0] = gs_dc_instanceCoordsI0; + dc.modelCoord = gs_interstageDrawingCoord0[0]; + dc.constantCoord = gs_interstageDrawingCoord0[1]; + dc.elementCoord = gs_interstageDrawingCoord0[2]; + dc.primitiveCoord = gs_interstageDrawingCoord0[3]; + dc.fvarCoord = gs_interstageDrawingCoord1[0]; + dc.shaderCoord = gs_interstageDrawingCoord1[1]; + dc.vertexCoord = gs_interstageDrawingCoord1[2]; + dc.topologyVisibilityCoord = gs_interstageDrawingCoord1[3]; + dc.varyingCoord = gs_interstageDrawingCoord2[0]; + dc.instanceIndex[0] = gs_interstageDrawingCoord2[1]; + dc.instanceIndex[1] = gs_interstageDrawingCoord2[2]; + dc.instanceCoords[0] = gs_interstageDrawingCoord2[3]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -2094,12 +2058,37 @@ vec4 ApplyColorOverridesPostLighting(vec4 color) -void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +void RenderColor(vec4 color) { colorOut = color; } + +void RenderId() +{ + // do nothing +} + + + +void RenderNeye(vec3 Neye) +{ + // do nothing +} + + + +void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +{ + // Write to any desired AOVs here. The render pass shader configuation + // decides if any of these are no-ops. + RenderColor(color); + RenderId(); + RenderNeye(Neye); +} + + #ifndef HD_HAS_integrateLights #define HD_HAS_integrateLights #endif @@ -2943,24 +2932,15 @@ layout(location = 1) in vec3 normals; uint hd_VertexID = gl_VertexIndex; uint hd_InstanceID = gl_InstanceIndex; uint hd_BaseInstance = HgiGetBaseInstance(); -flat layout(location = 0) out int vs_dc_modelCoord; -flat layout(location = 1) out int vs_dc_constantCoord; -flat layout(location = 2) out int vs_dc_elementCoord; -flat layout(location = 3) out int vs_dc_primitiveCoord; -flat layout(location = 4) out int vs_dc_fvarCoord; -flat layout(location = 5) out int vs_dc_shaderCoord; -flat layout(location = 6) out int vs_dc_vertexCoord; -flat layout(location = 7) out int vs_dc_topologyVisibilityCoord; -flat layout(location = 8) out int vs_dc_varyingCoord; -flat layout(location = 9) out int vs_dc_instanceIndexI0; -flat layout(location = 10) out int vs_dc_instanceIndexI1; -flat layout(location = 11) out int vs_dc_instanceCoordsI0; -flat layout(location = 12) out int vs_dc_instanceCoordsI1; -layout(location = 13) out VertexData { +flat layout(location = 0) out ivec4 vs_interstageDrawingCoord0; +flat layout(location = 1) out ivec4 vs_interstageDrawingCoord1; +flat layout(location = 2) out ivec4 vs_interstageDrawingCoord2; +flat layout(location = 3) out ivec4 vs_interstageDrawingCoord3; +layout(location = 4) out VertexData { vec4 Peye; vec3 Neye; } outData; -layout(location = 15) out PrimvarData { +layout(location = 6) out PrimvarData { vec3 points; vec3 normals; } outPrimvars; @@ -3073,18 +3053,18 @@ float HdGetScalar_normals() { return HdGet_normals(0).x; } // //////// Codegen Proc VS //////// void ProcessPrimvarsIn() { hd_drawingCoord dc = GetDrawingCoord(); - vs_dc_modelCoord = dc.modelCoord; - vs_dc_constantCoord = dc.constantCoord; - vs_dc_elementCoord = dc.elementCoord; - vs_dc_primitiveCoord = dc.primitiveCoord; - vs_dc_fvarCoord = dc.fvarCoord; - vs_dc_shaderCoord = dc.shaderCoord; - vs_dc_vertexCoord = dc.vertexCoord; - vs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - vs_dc_varyingCoord = dc.varyingCoord; - vs_dc_instanceIndexI0 = dc.instanceIndex[0]; - vs_dc_instanceIndexI1 = dc.instanceIndex[1]; - vs_dc_instanceCoordsI0 = dc.instanceCoords[0]; + vs_interstageDrawingCoord0[0] = dc.modelCoord; + vs_interstageDrawingCoord0[1] = dc.constantCoord; + vs_interstageDrawingCoord0[2] = dc.elementCoord; + vs_interstageDrawingCoord0[3] = dc.primitiveCoord; + vs_interstageDrawingCoord1[0] = dc.fvarCoord; + vs_interstageDrawingCoord1[1] = dc.shaderCoord; + vs_interstageDrawingCoord1[2] = dc.vertexCoord; + vs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + vs_interstageDrawingCoord2[0] = dc.varyingCoord; + vs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; + vs_interstageDrawingCoord2[2] = dc.instanceIndex[1]; + vs_interstageDrawingCoord2[3] = dc.instanceCoords[0]; outPrimvars.points = points; outPrimvars.normals = normals; } @@ -3658,47 +3638,29 @@ layout(std430, binding = 2) readonly buffer ssbo_primitiveParam { int primitiveP layout(std430, binding = 3) readonly buffer ssbo_edgeIndices { ivec2 edgeIndices[]; }; layout(std430, binding = 4) readonly buffer ssbo_faceVisibility { float faceVisibility[]; }; layout(std430, binding = 5) readonly buffer ssbo_dispTextureCoord { vec2 dispTextureCoord[]; }; -flat layout(location = 0) in int vs_dc_modelCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 1) in int vs_dc_constantCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 2) in int vs_dc_elementCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 3) in int vs_dc_primitiveCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 4) in int vs_dc_fvarCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 5) in int vs_dc_shaderCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 6) in int vs_dc_vertexCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 7) in int vs_dc_topologyVisibilityCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 8) in int vs_dc_varyingCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 9) in int vs_dc_instanceIndexI0[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 10) in int vs_dc_instanceIndexI1[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 11) in int vs_dc_instanceCoordsI0[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 12) in int vs_dc_instanceCoordsI1[HD_NUM_PRIMITIVE_VERTS]; -layout(location = 13) in VertexData { +flat layout(location = 0) in ivec4 vs_interstageDrawingCoord0[HD_NUM_PRIMITIVE_VERTS]; +flat layout(location = 1) in ivec4 vs_interstageDrawingCoord1[HD_NUM_PRIMITIVE_VERTS]; +flat layout(location = 2) in ivec4 vs_interstageDrawingCoord2[HD_NUM_PRIMITIVE_VERTS]; +flat layout(location = 3) in ivec4 vs_interstageDrawingCoord3[HD_NUM_PRIMITIVE_VERTS]; +layout(location = 4) in VertexData { vec4 Peye; vec3 Neye; } inData[4]; -layout(location = 15) in PrimvarData { +layout(location = 6) in PrimvarData { vec3 points; vec3 normals; } inPrimvars[HD_NUM_PRIMITIVE_VERTS]; layout(location = 2) out vec4 gsPatchCoord; noperspective layout(location = 3) out vec3 hd_barycentricCoord; -flat layout(location = 7) out int gs_dc_modelCoord; -flat layout(location = 8) out int gs_dc_constantCoord; -flat layout(location = 9) out int gs_dc_elementCoord; -flat layout(location = 10) out int gs_dc_primitiveCoord; -flat layout(location = 11) out int gs_dc_fvarCoord; -flat layout(location = 12) out int gs_dc_shaderCoord; -flat layout(location = 13) out int gs_dc_vertexCoord; -flat layout(location = 14) out int gs_dc_topologyVisibilityCoord; -flat layout(location = 15) out int gs_dc_varyingCoord; -flat layout(location = 16) out int gs_dc_instanceIndexI0; -flat layout(location = 17) out int gs_dc_instanceIndexI1; -flat layout(location = 18) out int gs_dc_instanceCoordsI0; -flat layout(location = 19) out int gs_dc_instanceCoordsI1; +flat layout(location = 4) out ivec4 gs_interstageDrawingCoord0; +flat layout(location = 5) out ivec4 gs_interstageDrawingCoord1; +flat layout(location = 6) out ivec4 gs_interstageDrawingCoord2; +flat layout(location = 7) out ivec4 gs_interstageDrawingCoord3; layout(location = 0) out VertexData { vec4 Peye; vec3 Neye; } outData; -layout(location = 4) out PrimvarData { +layout(location = 8) out PrimvarData { vec3 points; vec3 normals; vec2 dispTextureCoord; @@ -3767,18 +3729,18 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = vs_dc_modelCoord[0]; - dc.constantCoord = vs_dc_constantCoord[0]; - dc.elementCoord = vs_dc_elementCoord[0]; - dc.primitiveCoord = vs_dc_primitiveCoord[0]; - dc.fvarCoord = vs_dc_fvarCoord[0]; - dc.shaderCoord = vs_dc_shaderCoord[0]; - dc.vertexCoord = vs_dc_vertexCoord[0]; - dc.topologyVisibilityCoord = vs_dc_topologyVisibilityCoord[0]; - dc.varyingCoord = vs_dc_varyingCoord[0]; - dc.instanceIndex[0] = vs_dc_instanceIndexI0[0]; - dc.instanceIndex[1] = vs_dc_instanceIndexI1[0]; - dc.instanceCoords[0] = vs_dc_instanceCoordsI0[0]; + dc.modelCoord = vs_interstageDrawingCoord0[0][0]; + dc.constantCoord = vs_interstageDrawingCoord0[0][1]; + dc.elementCoord = vs_interstageDrawingCoord0[0][2]; + dc.primitiveCoord = vs_interstageDrawingCoord0[0][3]; + dc.fvarCoord = vs_interstageDrawingCoord1[0][0]; + dc.shaderCoord = vs_interstageDrawingCoord1[0][1]; + dc.vertexCoord = vs_interstageDrawingCoord1[0][2]; + dc.topologyVisibilityCoord = vs_interstageDrawingCoord1[0][3]; + dc.varyingCoord = vs_interstageDrawingCoord2[0][0]; + dc.instanceIndex[0] = vs_interstageDrawingCoord2[0][1]; + dc.instanceIndex[1] = vs_interstageDrawingCoord2[0][2]; + dc.instanceCoords[0] = vs_interstageDrawingCoord2[0][3]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -3871,18 +3833,18 @@ void ProcessPrimvarsOut(int index) { ); hd_barycentricCoord = coords[index]; hd_drawingCoord dc = GetDrawingCoord(); - gs_dc_modelCoord = dc.modelCoord; - gs_dc_constantCoord = dc.constantCoord; - gs_dc_elementCoord = dc.elementCoord; - gs_dc_primitiveCoord = dc.primitiveCoord; - gs_dc_fvarCoord = dc.fvarCoord; - gs_dc_shaderCoord = dc.shaderCoord; - gs_dc_vertexCoord = dc.vertexCoord; - gs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - gs_dc_varyingCoord = dc.varyingCoord; - gs_dc_instanceIndexI0 = dc.instanceIndex[0]; - gs_dc_instanceIndexI1 = dc.instanceIndex[1]; - gs_dc_instanceCoordsI0 = dc.instanceCoords[0]; + gs_interstageDrawingCoord0[0] = dc.modelCoord; + gs_interstageDrawingCoord0[1] = dc.constantCoord; + gs_interstageDrawingCoord0[2] = dc.elementCoord; + gs_interstageDrawingCoord0[3] = dc.primitiveCoord; + gs_interstageDrawingCoord1[0] = dc.fvarCoord; + gs_interstageDrawingCoord1[1] = dc.shaderCoord; + gs_interstageDrawingCoord1[2] = dc.vertexCoord; + gs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + gs_interstageDrawingCoord2[0] = dc.varyingCoord; + gs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; + gs_interstageDrawingCoord2[2] = dc.instanceIndex[1]; + gs_interstageDrawingCoord2[3] = dc.instanceCoords[0]; outPrimvars.points = inPrimvars[index].points; outPrimvars.normals = inPrimvars[index].normals; outPrimvars.dispTextureCoord = HdGet_dispTextureCoord(index); @@ -4538,24 +4500,15 @@ layout(std430, binding = 4) readonly buffer ssbo_faceVisibility { float faceVisi layout(std430, binding = 5) readonly buffer ssbo_dispTextureCoord { vec2 dispTextureCoord[]; }; layout(location = 2) in vec4 gsPatchCoord; noperspective layout(location = 3) in vec3 hd_barycentricCoord; -flat layout(location = 7) in int gs_dc_modelCoord; -flat layout(location = 8) in int gs_dc_constantCoord; -flat layout(location = 9) in int gs_dc_elementCoord; -flat layout(location = 10) in int gs_dc_primitiveCoord; -flat layout(location = 11) in int gs_dc_fvarCoord; -flat layout(location = 12) in int gs_dc_shaderCoord; -flat layout(location = 13) in int gs_dc_vertexCoord; -flat layout(location = 14) in int gs_dc_topologyVisibilityCoord; -flat layout(location = 15) in int gs_dc_varyingCoord; -flat layout(location = 16) in int gs_dc_instanceIndexI0; -flat layout(location = 17) in int gs_dc_instanceIndexI1; -flat layout(location = 18) in int gs_dc_instanceCoordsI0; -flat layout(location = 19) in int gs_dc_instanceCoordsI1; +flat layout(location = 4) in ivec4 gs_interstageDrawingCoord0; +flat layout(location = 5) in ivec4 gs_interstageDrawingCoord1; +flat layout(location = 6) in ivec4 gs_interstageDrawingCoord2; +flat layout(location = 7) in ivec4 gs_interstageDrawingCoord3; layout(location = 0) in VertexData { vec4 Peye; vec3 Neye; } inData; -layout(location = 4) in PrimvarData { +layout(location = 8) in PrimvarData { vec3 points; vec3 normals; vec2 dispTextureCoord; @@ -4629,18 +4582,18 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = gs_dc_modelCoord; - dc.constantCoord = gs_dc_constantCoord; - dc.elementCoord = gs_dc_elementCoord; - dc.primitiveCoord = gs_dc_primitiveCoord; - dc.fvarCoord = gs_dc_fvarCoord; - dc.shaderCoord = gs_dc_shaderCoord; - dc.vertexCoord = gs_dc_vertexCoord; - dc.topologyVisibilityCoord = gs_dc_topologyVisibilityCoord; - dc.varyingCoord = gs_dc_varyingCoord; - dc.instanceIndex[0] = gs_dc_instanceIndexI0; - dc.instanceIndex[1] = gs_dc_instanceIndexI1; - dc.instanceCoords[0] = gs_dc_instanceCoordsI0; + dc.modelCoord = gs_interstageDrawingCoord0[0]; + dc.constantCoord = gs_interstageDrawingCoord0[1]; + dc.elementCoord = gs_interstageDrawingCoord0[2]; + dc.primitiveCoord = gs_interstageDrawingCoord0[3]; + dc.fvarCoord = gs_interstageDrawingCoord1[0]; + dc.shaderCoord = gs_interstageDrawingCoord1[1]; + dc.vertexCoord = gs_interstageDrawingCoord1[2]; + dc.topologyVisibilityCoord = gs_interstageDrawingCoord1[3]; + dc.varyingCoord = gs_interstageDrawingCoord2[0]; + dc.instanceIndex[0] = gs_interstageDrawingCoord2[1]; + dc.instanceIndex[1] = gs_interstageDrawingCoord2[2]; + dc.instanceCoords[0] = gs_interstageDrawingCoord2[3]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -4894,12 +4847,37 @@ vec4 ApplyColorOverridesPostLighting(vec4 color) -void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +void RenderColor(vec4 color) { colorOut = color; } + +void RenderId() +{ + // do nothing +} + + + +void RenderNeye(vec3 Neye) +{ + // do nothing +} + + + +void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +{ + // Write to any desired AOVs here. The render pass shader configuation + // decides if any of these are no-ops. + RenderColor(color); + RenderId(); + RenderNeye(Neye); +} + + #ifndef HD_HAS_integrateLights #define HD_HAS_integrateLights #endif diff --git a/pxr/imaging/hdSt/testenv/testHdStCodeGen_Vulkan/baseline/codegen_mesh_indirect_smoothNormals.out b/pxr/imaging/hdSt/testenv/testHdStCodeGen_Vulkan/baseline/codegen_mesh_indirect_smoothNormals.out index 5fc79148e06..e544b38e41e 100644 --- a/pxr/imaging/hdSt/testenv/testHdStCodeGen_Vulkan/baseline/codegen_mesh_indirect_smoothNormals.out +++ b/pxr/imaging/hdSt/testenv/testHdStCodeGen_Vulkan/baseline/codegen_mesh_indirect_smoothNormals.out @@ -166,22 +166,14 @@ layout(location = 1) in vec3 smoothNormals; uint hd_VertexID = gl_VertexIndex; uint hd_InstanceID = gl_InstanceIndex; uint hd_BaseInstance = HgiGetBaseInstance(); -flat layout(location = 0) out int vs_dc_modelCoord; -flat layout(location = 1) out int vs_dc_constantCoord; -flat layout(location = 2) out int vs_dc_elementCoord; -flat layout(location = 3) out int vs_dc_primitiveCoord; -flat layout(location = 4) out int vs_dc_fvarCoord; -flat layout(location = 5) out int vs_dc_shaderCoord; -flat layout(location = 6) out int vs_dc_vertexCoord; -flat layout(location = 7) out int vs_dc_topologyVisibilityCoord; -flat layout(location = 8) out int vs_dc_varyingCoord; -flat layout(location = 9) out int vs_dc_instanceIndexI0; -flat layout(location = 10) out int vs_dc_instanceCoordsI0; -layout(location = 11) out VertexData { +flat layout(location = 0) out ivec4 vs_interstageDrawingCoord0; +flat layout(location = 1) out ivec4 vs_interstageDrawingCoord1; +flat layout(location = 2) out ivec4 vs_interstageDrawingCoord2; +layout(location = 3) out VertexData { vec4 Peye; vec3 Neye; } outData; -layout(location = 13) out PrimvarData { +layout(location = 5) out PrimvarData { vec3 points; vec3 smoothNormals; } outPrimvars; @@ -253,16 +245,16 @@ float HdGetScalar_smoothNormals() { return HdGet_smoothNormals(0).x; } // //////// Codegen Proc VS //////// void ProcessPrimvarsIn() { hd_drawingCoord dc = GetDrawingCoord(); - vs_dc_modelCoord = dc.modelCoord; - vs_dc_constantCoord = dc.constantCoord; - vs_dc_elementCoord = dc.elementCoord; - vs_dc_primitiveCoord = dc.primitiveCoord; - vs_dc_fvarCoord = dc.fvarCoord; - vs_dc_shaderCoord = dc.shaderCoord; - vs_dc_vertexCoord = dc.vertexCoord; - vs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - vs_dc_varyingCoord = dc.varyingCoord; - vs_dc_instanceIndexI0 = dc.instanceIndex[0]; + vs_interstageDrawingCoord0[0] = dc.modelCoord; + vs_interstageDrawingCoord0[1] = dc.constantCoord; + vs_interstageDrawingCoord0[2] = dc.elementCoord; + vs_interstageDrawingCoord0[3] = dc.primitiveCoord; + vs_interstageDrawingCoord1[0] = dc.fvarCoord; + vs_interstageDrawingCoord1[1] = dc.shaderCoord; + vs_interstageDrawingCoord1[2] = dc.vertexCoord; + vs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + vs_interstageDrawingCoord2[0] = dc.varyingCoord; + vs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = points; outPrimvars.smoothNormals = smoothNormals; } @@ -844,43 +836,27 @@ layout(std430, binding = 1) readonly buffer ssbo_primitiveParam { int primitiveP layout(std430, binding = 2) readonly buffer ssbo_edgeIndices { int edgeIndices[]; }; layout(std430, binding = 3) readonly buffer ssbo_faceVisibility { float faceVisibility[]; }; layout(std430, binding = 4) readonly buffer ssbo_dispTextureCoord { vec2 dispTextureCoord[]; }; -flat layout(location = 0) in int vs_dc_modelCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 1) in int vs_dc_constantCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 2) in int vs_dc_elementCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 3) in int vs_dc_primitiveCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 4) in int vs_dc_fvarCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 5) in int vs_dc_shaderCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 6) in int vs_dc_vertexCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 7) in int vs_dc_topologyVisibilityCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 8) in int vs_dc_varyingCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 9) in int vs_dc_instanceIndexI0[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 10) in int vs_dc_instanceCoordsI0[HD_NUM_PRIMITIVE_VERTS]; -layout(location = 11) in VertexData { +flat layout(location = 0) in ivec4 vs_interstageDrawingCoord0[HD_NUM_PRIMITIVE_VERTS]; +flat layout(location = 1) in ivec4 vs_interstageDrawingCoord1[HD_NUM_PRIMITIVE_VERTS]; +flat layout(location = 2) in ivec4 vs_interstageDrawingCoord2[HD_NUM_PRIMITIVE_VERTS]; +layout(location = 3) in VertexData { vec4 Peye; vec3 Neye; } inData[3]; -layout(location = 13) in PrimvarData { +layout(location = 5) in PrimvarData { vec3 points; vec3 smoothNormals; } inPrimvars[HD_NUM_PRIMITIVE_VERTS]; layout(location = 2) out vec4 gsPatchCoord; noperspective layout(location = 3) out vec3 hd_barycentricCoord; -flat layout(location = 7) out int gs_dc_modelCoord; -flat layout(location = 8) out int gs_dc_constantCoord; -flat layout(location = 9) out int gs_dc_elementCoord; -flat layout(location = 10) out int gs_dc_primitiveCoord; -flat layout(location = 11) out int gs_dc_fvarCoord; -flat layout(location = 12) out int gs_dc_shaderCoord; -flat layout(location = 13) out int gs_dc_vertexCoord; -flat layout(location = 14) out int gs_dc_topologyVisibilityCoord; -flat layout(location = 15) out int gs_dc_varyingCoord; -flat layout(location = 16) out int gs_dc_instanceIndexI0; -flat layout(location = 17) out int gs_dc_instanceCoordsI0; +flat layout(location = 4) out ivec4 gs_interstageDrawingCoord0; +flat layout(location = 5) out ivec4 gs_interstageDrawingCoord1; +flat layout(location = 6) out ivec4 gs_interstageDrawingCoord2; layout(location = 0) out VertexData { vec4 Peye; vec3 Neye; } outData; -layout(location = 4) out PrimvarData { +layout(location = 7) out PrimvarData { vec3 points; vec3 smoothNormals; vec2 dispTextureCoord; @@ -931,16 +907,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = vs_dc_modelCoord[0]; - dc.constantCoord = vs_dc_constantCoord[0]; - dc.elementCoord = vs_dc_elementCoord[0]; - dc.primitiveCoord = vs_dc_primitiveCoord[0]; - dc.fvarCoord = vs_dc_fvarCoord[0]; - dc.shaderCoord = vs_dc_shaderCoord[0]; - dc.vertexCoord = vs_dc_vertexCoord[0]; - dc.topologyVisibilityCoord = vs_dc_topologyVisibilityCoord[0]; - dc.varyingCoord = vs_dc_varyingCoord[0]; - dc.instanceIndex[0] = vs_dc_instanceIndexI0[0]; + dc.modelCoord = vs_interstageDrawingCoord0[0][0]; + dc.constantCoord = vs_interstageDrawingCoord0[0][1]; + dc.elementCoord = vs_interstageDrawingCoord0[0][2]; + dc.primitiveCoord = vs_interstageDrawingCoord0[0][3]; + dc.fvarCoord = vs_interstageDrawingCoord1[0][0]; + dc.shaderCoord = vs_interstageDrawingCoord1[0][1]; + dc.vertexCoord = vs_interstageDrawingCoord1[0][2]; + dc.topologyVisibilityCoord = vs_interstageDrawingCoord1[0][3]; + dc.varyingCoord = vs_interstageDrawingCoord2[0][0]; + dc.instanceIndex[0] = vs_interstageDrawingCoord2[0][1]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -1033,16 +1009,16 @@ void ProcessPrimvarsOut(int index) { ); hd_barycentricCoord = coords[index]; hd_drawingCoord dc = GetDrawingCoord(); - gs_dc_modelCoord = dc.modelCoord; - gs_dc_constantCoord = dc.constantCoord; - gs_dc_elementCoord = dc.elementCoord; - gs_dc_primitiveCoord = dc.primitiveCoord; - gs_dc_fvarCoord = dc.fvarCoord; - gs_dc_shaderCoord = dc.shaderCoord; - gs_dc_vertexCoord = dc.vertexCoord; - gs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - gs_dc_varyingCoord = dc.varyingCoord; - gs_dc_instanceIndexI0 = dc.instanceIndex[0]; + gs_interstageDrawingCoord0[0] = dc.modelCoord; + gs_interstageDrawingCoord0[1] = dc.constantCoord; + gs_interstageDrawingCoord0[2] = dc.elementCoord; + gs_interstageDrawingCoord0[3] = dc.primitiveCoord; + gs_interstageDrawingCoord1[0] = dc.fvarCoord; + gs_interstageDrawingCoord1[1] = dc.shaderCoord; + gs_interstageDrawingCoord1[2] = dc.vertexCoord; + gs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + gs_interstageDrawingCoord2[0] = dc.varyingCoord; + gs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = inPrimvars[index].points; outPrimvars.smoothNormals = inPrimvars[index].smoothNormals; outPrimvars.dispTextureCoord = HdGet_dispTextureCoord(index); @@ -1651,22 +1627,14 @@ layout(std430, binding = 3) readonly buffer ssbo_faceVisibility { float faceVisi layout(std430, binding = 4) readonly buffer ssbo_dispTextureCoord { vec2 dispTextureCoord[]; }; layout(location = 2) in vec4 gsPatchCoord; noperspective layout(location = 3) in vec3 hd_barycentricCoord; -flat layout(location = 7) in int gs_dc_modelCoord; -flat layout(location = 8) in int gs_dc_constantCoord; -flat layout(location = 9) in int gs_dc_elementCoord; -flat layout(location = 10) in int gs_dc_primitiveCoord; -flat layout(location = 11) in int gs_dc_fvarCoord; -flat layout(location = 12) in int gs_dc_shaderCoord; -flat layout(location = 13) in int gs_dc_vertexCoord; -flat layout(location = 14) in int gs_dc_topologyVisibilityCoord; -flat layout(location = 15) in int gs_dc_varyingCoord; -flat layout(location = 16) in int gs_dc_instanceIndexI0; -flat layout(location = 17) in int gs_dc_instanceCoordsI0; +flat layout(location = 4) in ivec4 gs_interstageDrawingCoord0; +flat layout(location = 5) in ivec4 gs_interstageDrawingCoord1; +flat layout(location = 6) in ivec4 gs_interstageDrawingCoord2; layout(location = 0) in VertexData { vec4 Peye; vec3 Neye; } inData; -layout(location = 4) in PrimvarData { +layout(location = 7) in PrimvarData { vec3 points; vec3 smoothNormals; vec2 dispTextureCoord; @@ -1722,16 +1690,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = gs_dc_modelCoord; - dc.constantCoord = gs_dc_constantCoord; - dc.elementCoord = gs_dc_elementCoord; - dc.primitiveCoord = gs_dc_primitiveCoord; - dc.fvarCoord = gs_dc_fvarCoord; - dc.shaderCoord = gs_dc_shaderCoord; - dc.vertexCoord = gs_dc_vertexCoord; - dc.topologyVisibilityCoord = gs_dc_topologyVisibilityCoord; - dc.varyingCoord = gs_dc_varyingCoord; - dc.instanceIndex[0] = gs_dc_instanceIndexI0; + dc.modelCoord = gs_interstageDrawingCoord0[0]; + dc.constantCoord = gs_interstageDrawingCoord0[1]; + dc.elementCoord = gs_interstageDrawingCoord0[2]; + dc.primitiveCoord = gs_interstageDrawingCoord0[3]; + dc.fvarCoord = gs_interstageDrawingCoord1[0]; + dc.shaderCoord = gs_interstageDrawingCoord1[1]; + dc.vertexCoord = gs_interstageDrawingCoord1[2]; + dc.topologyVisibilityCoord = gs_interstageDrawingCoord1[3]; + dc.varyingCoord = gs_interstageDrawingCoord2[0]; + dc.instanceIndex[0] = gs_interstageDrawingCoord2[1]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -1985,12 +1953,37 @@ vec4 ApplyColorOverridesPostLighting(vec4 color) -void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +void RenderColor(vec4 color) { colorOut = color; } + +void RenderId() +{ + // do nothing +} + + + +void RenderNeye(vec3 Neye) +{ + // do nothing +} + + + +void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +{ + // Write to any desired AOVs here. The render pass shader configuation + // decides if any of these are no-ops. + RenderColor(color); + RenderId(); + RenderNeye(Neye); +} + + #ifndef HD_HAS_integrateLights #define HD_HAS_integrateLights #endif @@ -2828,22 +2821,14 @@ layout(location = 1) in vec3 smoothNormals; uint hd_VertexID = gl_VertexIndex; uint hd_InstanceID = gl_InstanceIndex; uint hd_BaseInstance = HgiGetBaseInstance(); -flat layout(location = 0) out int vs_dc_modelCoord; -flat layout(location = 1) out int vs_dc_constantCoord; -flat layout(location = 2) out int vs_dc_elementCoord; -flat layout(location = 3) out int vs_dc_primitiveCoord; -flat layout(location = 4) out int vs_dc_fvarCoord; -flat layout(location = 5) out int vs_dc_shaderCoord; -flat layout(location = 6) out int vs_dc_vertexCoord; -flat layout(location = 7) out int vs_dc_topologyVisibilityCoord; -flat layout(location = 8) out int vs_dc_varyingCoord; -flat layout(location = 9) out int vs_dc_instanceIndexI0; -flat layout(location = 10) out int vs_dc_instanceCoordsI0; -layout(location = 11) out VertexData { +flat layout(location = 0) out ivec4 vs_interstageDrawingCoord0; +flat layout(location = 1) out ivec4 vs_interstageDrawingCoord1; +flat layout(location = 2) out ivec4 vs_interstageDrawingCoord2; +layout(location = 3) out VertexData { vec4 Peye; vec3 Neye; } outData; -layout(location = 13) out PrimvarData { +layout(location = 5) out PrimvarData { vec3 points; vec3 smoothNormals; } outPrimvars; @@ -2915,16 +2900,16 @@ float HdGetScalar_smoothNormals() { return HdGet_smoothNormals(0).x; } // //////// Codegen Proc VS //////// void ProcessPrimvarsIn() { hd_drawingCoord dc = GetDrawingCoord(); - vs_dc_modelCoord = dc.modelCoord; - vs_dc_constantCoord = dc.constantCoord; - vs_dc_elementCoord = dc.elementCoord; - vs_dc_primitiveCoord = dc.primitiveCoord; - vs_dc_fvarCoord = dc.fvarCoord; - vs_dc_shaderCoord = dc.shaderCoord; - vs_dc_vertexCoord = dc.vertexCoord; - vs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - vs_dc_varyingCoord = dc.varyingCoord; - vs_dc_instanceIndexI0 = dc.instanceIndex[0]; + vs_interstageDrawingCoord0[0] = dc.modelCoord; + vs_interstageDrawingCoord0[1] = dc.constantCoord; + vs_interstageDrawingCoord0[2] = dc.elementCoord; + vs_interstageDrawingCoord0[3] = dc.primitiveCoord; + vs_interstageDrawingCoord1[0] = dc.fvarCoord; + vs_interstageDrawingCoord1[1] = dc.shaderCoord; + vs_interstageDrawingCoord1[2] = dc.vertexCoord; + vs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + vs_interstageDrawingCoord2[0] = dc.varyingCoord; + vs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = points; outPrimvars.smoothNormals = smoothNormals; } @@ -3506,43 +3491,27 @@ layout(std430, binding = 1) readonly buffer ssbo_primitiveParam { int primitiveP layout(std430, binding = 2) readonly buffer ssbo_edgeIndices { ivec2 edgeIndices[]; }; layout(std430, binding = 3) readonly buffer ssbo_faceVisibility { float faceVisibility[]; }; layout(std430, binding = 4) readonly buffer ssbo_dispTextureCoord { vec2 dispTextureCoord[]; }; -flat layout(location = 0) in int vs_dc_modelCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 1) in int vs_dc_constantCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 2) in int vs_dc_elementCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 3) in int vs_dc_primitiveCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 4) in int vs_dc_fvarCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 5) in int vs_dc_shaderCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 6) in int vs_dc_vertexCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 7) in int vs_dc_topologyVisibilityCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 8) in int vs_dc_varyingCoord[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 9) in int vs_dc_instanceIndexI0[HD_NUM_PRIMITIVE_VERTS]; -flat layout(location = 10) in int vs_dc_instanceCoordsI0[HD_NUM_PRIMITIVE_VERTS]; -layout(location = 11) in VertexData { +flat layout(location = 0) in ivec4 vs_interstageDrawingCoord0[HD_NUM_PRIMITIVE_VERTS]; +flat layout(location = 1) in ivec4 vs_interstageDrawingCoord1[HD_NUM_PRIMITIVE_VERTS]; +flat layout(location = 2) in ivec4 vs_interstageDrawingCoord2[HD_NUM_PRIMITIVE_VERTS]; +layout(location = 3) in VertexData { vec4 Peye; vec3 Neye; } inData[4]; -layout(location = 13) in PrimvarData { +layout(location = 5) in PrimvarData { vec3 points; vec3 smoothNormals; } inPrimvars[HD_NUM_PRIMITIVE_VERTS]; layout(location = 2) out vec4 gsPatchCoord; noperspective layout(location = 3) out vec3 hd_barycentricCoord; -flat layout(location = 7) out int gs_dc_modelCoord; -flat layout(location = 8) out int gs_dc_constantCoord; -flat layout(location = 9) out int gs_dc_elementCoord; -flat layout(location = 10) out int gs_dc_primitiveCoord; -flat layout(location = 11) out int gs_dc_fvarCoord; -flat layout(location = 12) out int gs_dc_shaderCoord; -flat layout(location = 13) out int gs_dc_vertexCoord; -flat layout(location = 14) out int gs_dc_topologyVisibilityCoord; -flat layout(location = 15) out int gs_dc_varyingCoord; -flat layout(location = 16) out int gs_dc_instanceIndexI0; -flat layout(location = 17) out int gs_dc_instanceCoordsI0; +flat layout(location = 4) out ivec4 gs_interstageDrawingCoord0; +flat layout(location = 5) out ivec4 gs_interstageDrawingCoord1; +flat layout(location = 6) out ivec4 gs_interstageDrawingCoord2; layout(location = 0) out VertexData { vec4 Peye; vec3 Neye; } outData; -layout(location = 4) out PrimvarData { +layout(location = 7) out PrimvarData { vec3 points; vec3 smoothNormals; vec2 dispTextureCoord; @@ -3593,16 +3562,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = vs_dc_modelCoord[0]; - dc.constantCoord = vs_dc_constantCoord[0]; - dc.elementCoord = vs_dc_elementCoord[0]; - dc.primitiveCoord = vs_dc_primitiveCoord[0]; - dc.fvarCoord = vs_dc_fvarCoord[0]; - dc.shaderCoord = vs_dc_shaderCoord[0]; - dc.vertexCoord = vs_dc_vertexCoord[0]; - dc.topologyVisibilityCoord = vs_dc_topologyVisibilityCoord[0]; - dc.varyingCoord = vs_dc_varyingCoord[0]; - dc.instanceIndex[0] = vs_dc_instanceIndexI0[0]; + dc.modelCoord = vs_interstageDrawingCoord0[0][0]; + dc.constantCoord = vs_interstageDrawingCoord0[0][1]; + dc.elementCoord = vs_interstageDrawingCoord0[0][2]; + dc.primitiveCoord = vs_interstageDrawingCoord0[0][3]; + dc.fvarCoord = vs_interstageDrawingCoord1[0][0]; + dc.shaderCoord = vs_interstageDrawingCoord1[0][1]; + dc.vertexCoord = vs_interstageDrawingCoord1[0][2]; + dc.topologyVisibilityCoord = vs_interstageDrawingCoord1[0][3]; + dc.varyingCoord = vs_interstageDrawingCoord2[0][0]; + dc.instanceIndex[0] = vs_interstageDrawingCoord2[0][1]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -3695,16 +3664,16 @@ void ProcessPrimvarsOut(int index) { ); hd_barycentricCoord = coords[index]; hd_drawingCoord dc = GetDrawingCoord(); - gs_dc_modelCoord = dc.modelCoord; - gs_dc_constantCoord = dc.constantCoord; - gs_dc_elementCoord = dc.elementCoord; - gs_dc_primitiveCoord = dc.primitiveCoord; - gs_dc_fvarCoord = dc.fvarCoord; - gs_dc_shaderCoord = dc.shaderCoord; - gs_dc_vertexCoord = dc.vertexCoord; - gs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - gs_dc_varyingCoord = dc.varyingCoord; - gs_dc_instanceIndexI0 = dc.instanceIndex[0]; + gs_interstageDrawingCoord0[0] = dc.modelCoord; + gs_interstageDrawingCoord0[1] = dc.constantCoord; + gs_interstageDrawingCoord0[2] = dc.elementCoord; + gs_interstageDrawingCoord0[3] = dc.primitiveCoord; + gs_interstageDrawingCoord1[0] = dc.fvarCoord; + gs_interstageDrawingCoord1[1] = dc.shaderCoord; + gs_interstageDrawingCoord1[2] = dc.vertexCoord; + gs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + gs_interstageDrawingCoord2[0] = dc.varyingCoord; + gs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = inPrimvars[index].points; outPrimvars.smoothNormals = inPrimvars[index].smoothNormals; outPrimvars.dispTextureCoord = HdGet_dispTextureCoord(index); @@ -4342,22 +4311,14 @@ layout(std430, binding = 3) readonly buffer ssbo_faceVisibility { float faceVisi layout(std430, binding = 4) readonly buffer ssbo_dispTextureCoord { vec2 dispTextureCoord[]; }; layout(location = 2) in vec4 gsPatchCoord; noperspective layout(location = 3) in vec3 hd_barycentricCoord; -flat layout(location = 7) in int gs_dc_modelCoord; -flat layout(location = 8) in int gs_dc_constantCoord; -flat layout(location = 9) in int gs_dc_elementCoord; -flat layout(location = 10) in int gs_dc_primitiveCoord; -flat layout(location = 11) in int gs_dc_fvarCoord; -flat layout(location = 12) in int gs_dc_shaderCoord; -flat layout(location = 13) in int gs_dc_vertexCoord; -flat layout(location = 14) in int gs_dc_topologyVisibilityCoord; -flat layout(location = 15) in int gs_dc_varyingCoord; -flat layout(location = 16) in int gs_dc_instanceIndexI0; -flat layout(location = 17) in int gs_dc_instanceCoordsI0; +flat layout(location = 4) in ivec4 gs_interstageDrawingCoord0; +flat layout(location = 5) in ivec4 gs_interstageDrawingCoord1; +flat layout(location = 6) in ivec4 gs_interstageDrawingCoord2; layout(location = 0) in VertexData { vec4 Peye; vec3 Neye; } inData; -layout(location = 4) in PrimvarData { +layout(location = 7) in PrimvarData { vec3 points; vec3 smoothNormals; vec2 dispTextureCoord; @@ -4413,16 +4374,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = gs_dc_modelCoord; - dc.constantCoord = gs_dc_constantCoord; - dc.elementCoord = gs_dc_elementCoord; - dc.primitiveCoord = gs_dc_primitiveCoord; - dc.fvarCoord = gs_dc_fvarCoord; - dc.shaderCoord = gs_dc_shaderCoord; - dc.vertexCoord = gs_dc_vertexCoord; - dc.topologyVisibilityCoord = gs_dc_topologyVisibilityCoord; - dc.varyingCoord = gs_dc_varyingCoord; - dc.instanceIndex[0] = gs_dc_instanceIndexI0; + dc.modelCoord = gs_interstageDrawingCoord0[0]; + dc.constantCoord = gs_interstageDrawingCoord0[1]; + dc.elementCoord = gs_interstageDrawingCoord0[2]; + dc.primitiveCoord = gs_interstageDrawingCoord0[3]; + dc.fvarCoord = gs_interstageDrawingCoord1[0]; + dc.shaderCoord = gs_interstageDrawingCoord1[1]; + dc.vertexCoord = gs_interstageDrawingCoord1[2]; + dc.topologyVisibilityCoord = gs_interstageDrawingCoord1[3]; + dc.varyingCoord = gs_interstageDrawingCoord2[0]; + dc.instanceIndex[0] = gs_interstageDrawingCoord2[1]; return dc; } int HdGet_primitiveParam(int localIndex) { @@ -4676,12 +4637,37 @@ vec4 ApplyColorOverridesPostLighting(vec4 color) -void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +void RenderColor(vec4 color) { colorOut = color; } + +void RenderId() +{ + // do nothing +} + + + +void RenderNeye(vec3 Neye) +{ + // do nothing +} + + + +void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +{ + // Write to any desired AOVs here. The render pass shader configuation + // decides if any of these are no-ops. + RenderColor(color); + RenderId(); + RenderNeye(Neye); +} + + #ifndef HD_HAS_integrateLights #define HD_HAS_integrateLights #endif diff --git a/pxr/imaging/hdSt/testenv/testHdStCodeGen_Vulkan/baseline/codegen_points_indirect.out b/pxr/imaging/hdSt/testenv/testHdStCodeGen_Vulkan/baseline/codegen_points_indirect.out index 73823268af9..3dae5bf8e6c 100644 --- a/pxr/imaging/hdSt/testenv/testHdStCodeGen_Vulkan/baseline/codegen_points_indirect.out +++ b/pxr/imaging/hdSt/testenv/testHdStCodeGen_Vulkan/baseline/codegen_points_indirect.out @@ -160,22 +160,14 @@ layout(location = 1) in vec3 normals; uint hd_VertexID = gl_VertexIndex; uint hd_InstanceID = gl_InstanceIndex; uint hd_BaseInstance = HgiGetBaseInstance(); -flat layout(location = 0) out int vs_dc_modelCoord; -flat layout(location = 1) out int vs_dc_constantCoord; -flat layout(location = 2) out int vs_dc_elementCoord; -flat layout(location = 3) out int vs_dc_primitiveCoord; -flat layout(location = 4) out int vs_dc_fvarCoord; -flat layout(location = 5) out int vs_dc_shaderCoord; -flat layout(location = 6) out int vs_dc_vertexCoord; -flat layout(location = 7) out int vs_dc_topologyVisibilityCoord; -flat layout(location = 8) out int vs_dc_varyingCoord; -flat layout(location = 9) out int vs_dc_instanceIndexI0; -flat layout(location = 10) out int vs_dc_instanceCoordsI0; -flat layout(location = 12) out int vsPointId; -layout(location = 11) out VertexData { +flat layout(location = 0) out ivec4 vs_interstageDrawingCoord0; +flat layout(location = 1) out ivec4 vs_interstageDrawingCoord1; +flat layout(location = 2) out ivec4 vs_interstageDrawingCoord2; +flat layout(location = 4) out int vsPointId; +layout(location = 3) out VertexData { vec4 Peye; } outData; -layout(location = 13) out PrimvarData { +layout(location = 5) out PrimvarData { vec3 points; vec3 normals; } outPrimvars; @@ -247,16 +239,16 @@ float HdGetScalar_normals() { return HdGet_normals(0).x; } // //////// Codegen Proc VS //////// void ProcessPrimvarsIn() { hd_drawingCoord dc = GetDrawingCoord(); - vs_dc_modelCoord = dc.modelCoord; - vs_dc_constantCoord = dc.constantCoord; - vs_dc_elementCoord = dc.elementCoord; - vs_dc_primitiveCoord = dc.primitiveCoord; - vs_dc_fvarCoord = dc.fvarCoord; - vs_dc_shaderCoord = dc.shaderCoord; - vs_dc_vertexCoord = dc.vertexCoord; - vs_dc_topologyVisibilityCoord = dc.topologyVisibilityCoord; - vs_dc_varyingCoord = dc.varyingCoord; - vs_dc_instanceIndexI0 = dc.instanceIndex[0]; + vs_interstageDrawingCoord0[0] = dc.modelCoord; + vs_interstageDrawingCoord0[1] = dc.constantCoord; + vs_interstageDrawingCoord0[2] = dc.elementCoord; + vs_interstageDrawingCoord0[3] = dc.primitiveCoord; + vs_interstageDrawingCoord1[0] = dc.fvarCoord; + vs_interstageDrawingCoord1[1] = dc.shaderCoord; + vs_interstageDrawingCoord1[2] = dc.vertexCoord; + vs_interstageDrawingCoord1[3] = dc.topologyVisibilityCoord; + vs_interstageDrawingCoord2[0] = dc.varyingCoord; + vs_interstageDrawingCoord2[1] = dc.instanceIndex[0]; outPrimvars.points = points; outPrimvars.normals = normals; } @@ -1232,22 +1224,14 @@ FORWARD_DECL(float GetSelectedEdgeOpacity()); // //////// Global Member Declarations //////// layout(std430, binding = 0) readonly buffer ssbo_constantPrimvars { ConstantData7 constantPrimvars[]; }; -flat layout(location = 12) in int vsPointId; -flat layout(location = 0) in int vs_dc_modelCoord; -flat layout(location = 1) in int vs_dc_constantCoord; -flat layout(location = 2) in int vs_dc_elementCoord; -flat layout(location = 3) in int vs_dc_primitiveCoord; -flat layout(location = 4) in int vs_dc_fvarCoord; -flat layout(location = 5) in int vs_dc_shaderCoord; -flat layout(location = 6) in int vs_dc_vertexCoord; -flat layout(location = 7) in int vs_dc_topologyVisibilityCoord; -flat layout(location = 8) in int vs_dc_varyingCoord; -flat layout(location = 9) in int vs_dc_instanceIndexI0; -flat layout(location = 10) in int vs_dc_instanceCoordsI0; -layout(location = 11) in VertexData { +flat layout(location = 4) in int vsPointId; +flat layout(location = 0) in ivec4 vs_interstageDrawingCoord0; +flat layout(location = 1) in ivec4 vs_interstageDrawingCoord1; +flat layout(location = 2) in ivec4 vs_interstageDrawingCoord2; +layout(location = 3) in VertexData { vec4 Peye; } inData; -layout(location = 13) in PrimvarData { +layout(location = 5) in PrimvarData { vec3 points; vec3 normals; } inPrimvars; @@ -1302,16 +1286,16 @@ int GetPrimitiveIndex() { } hd_drawingCoord GetDrawingCoord() { hd_drawingCoord dc; - dc.modelCoord = vs_dc_modelCoord; - dc.constantCoord = vs_dc_constantCoord; - dc.elementCoord = vs_dc_elementCoord; - dc.primitiveCoord = vs_dc_primitiveCoord; - dc.fvarCoord = vs_dc_fvarCoord; - dc.shaderCoord = vs_dc_shaderCoord; - dc.vertexCoord = vs_dc_vertexCoord; - dc.topologyVisibilityCoord = vs_dc_topologyVisibilityCoord; - dc.varyingCoord = vs_dc_varyingCoord; - dc.instanceIndex[0] = vs_dc_instanceIndexI0; + dc.modelCoord = vs_interstageDrawingCoord0[0]; + dc.constantCoord = vs_interstageDrawingCoord0[1]; + dc.elementCoord = vs_interstageDrawingCoord0[2]; + dc.primitiveCoord = vs_interstageDrawingCoord0[3]; + dc.fvarCoord = vs_interstageDrawingCoord1[0]; + dc.shaderCoord = vs_interstageDrawingCoord1[1]; + dc.vertexCoord = vs_interstageDrawingCoord1[2]; + dc.topologyVisibilityCoord = vs_interstageDrawingCoord1[3]; + dc.varyingCoord = vs_interstageDrawingCoord2[0]; + dc.instanceIndex[0] = vs_interstageDrawingCoord2[1]; return dc; } int GetElementID() { @@ -1539,12 +1523,37 @@ vec4 ApplyColorOverridesPostLighting(vec4 color) -void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +void RenderColor(vec4 color) { colorOut = color; } + +void RenderId() +{ + // do nothing +} + + + +void RenderNeye(vec3 Neye) +{ + // do nothing +} + + + +void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) +{ + // Write to any desired AOVs here. The render pass shader configuation + // decides if any of these are no-ops. + RenderColor(color); + RenderId(); + RenderNeye(Neye); +} + + #ifndef HD_HAS_integrateLights #define HD_HAS_integrateLights #endif diff --git a/pxr/imaging/hdSt/testenv/testHdStCurvesPrimvars.cpp b/pxr/imaging/hdSt/testenv/testHdStCurvesPrimvars.cpp index 04c9bd3c6be..dd9c9fd0bb6 100644 --- a/pxr/imaging/hdSt/testenv/testHdStCurvesPrimvars.cpp +++ b/pxr/imaging/hdSt/testenv/testHdStCurvesPrimvars.cpp @@ -27,8 +27,6 @@ PXR_NAMESPACE_USING_DIRECTIVE -HdStResourceRegistrySharedPtr registry; - template static VtArray _BuildArray(T values[], int numValues) @@ -58,6 +56,7 @@ _CompareArrays(VtArray const & result, static bool _ComparePoints(std::string const & name, + HdStResourceRegistrySharedPtr const & registry, VtIntArray numVerts, VtIntArray indices, VtVec3fArray points, VtVec3fArray expected) { @@ -100,6 +99,7 @@ _ComparePoints(std::string const & name, static bool _CompareVertexPrimvar(std::string const & name, + HdStResourceRegistrySharedPtr const & registry, VtIntArray numVerts, VtIntArray indices, VtFloatArray primvar, VtFloatArray expected) { @@ -140,7 +140,7 @@ _CompareVertexPrimvar(std::string const & name, } bool -TopologyWithIndicesTest() +TopologyWithIndicesTest(HdStResourceRegistrySharedPtr const & registry) { { int numVerts[] = { 11 }; @@ -163,6 +163,7 @@ TopologyWithIndicesTest() GfVec3f(0, 0, 6) }; if (!_ComparePoints("topology_w_indices_points_small", + registry, _BuildArray(numVerts, sizeof(numVerts)/sizeof(int)), _BuildArray(indices, sizeof(indices)/sizeof(int)), _BuildArray(points, sizeof(points)/sizeof(GfVec3f)), @@ -187,6 +188,7 @@ TopologyWithIndicesTest() GfVec3f(0, 0, 10) }; if (!_ComparePoints("topology_w_indices_points_equal", + registry, _BuildArray(numVerts, sizeof(numVerts)/sizeof(int)), _BuildArray(indices, sizeof(indices)/sizeof(int)), _BuildArray(points, sizeof(points)/sizeof(GfVec3f)), @@ -224,6 +226,7 @@ TopologyWithIndicesTest() GfVec3f(0, 0, 9) }; if (!_ComparePoints("topology_w_indices_points_big", + registry, _BuildArray(numVerts, sizeof(numVerts)/sizeof(int)), _BuildArray(indices, sizeof(indices)/sizeof(int)), _BuildArray(points, sizeof(points)/sizeof(GfVec3f)), @@ -248,6 +251,7 @@ TopologyWithIndicesTest() std::fill_n(expected, 10, GfVec3f(1, 0, 0)); if (!_ComparePoints("topology_w_indices_points_insufficient", + registry, _BuildArray(numVerts, sizeof(numVerts)/sizeof(int)), _BuildArray(indices, sizeof(indices)/sizeof(int)), _BuildArray(points, sizeof(points)/sizeof(GfVec3f)), @@ -262,6 +266,7 @@ TopologyWithIndicesTest() float primvar[] = { 0, 1, 2, 3, 4, 5, 6}; float expected[] = { 0, 1, 2, 3, 4, 5, 6}; if (!_CompareVertexPrimvar("topology_w_indices_primvar_small", + registry, _BuildArray(numVerts, sizeof(numVerts)/sizeof(int)), _BuildArray(indices, sizeof(indices)/sizeof(int)), _BuildArray(primvar, sizeof(primvar)/sizeof(float)), @@ -275,6 +280,7 @@ TopologyWithIndicesTest() int indices[] = { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 }; float primvar[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; if (!_CompareVertexPrimvar("topology_w_indices_primvar_equal", + registry, _BuildArray(numVerts, sizeof(numVerts)/sizeof(int)), _BuildArray(indices, sizeof(indices)/sizeof(int)), _BuildArray(primvar, sizeof(primvar)/sizeof(float)), @@ -289,6 +295,7 @@ TopologyWithIndicesTest() float primvar[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; float expected[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; if (!_CompareVertexPrimvar("topology_w_indices_primvar_big", + registry, _BuildArray(numVerts, sizeof(numVerts)/sizeof(int)), _BuildArray(indices, sizeof(indices)/sizeof(int)), _BuildArray(primvar, sizeof(primvar)/sizeof(float)), @@ -307,6 +314,7 @@ TopologyWithIndicesTest() float expected[9]; std::fill_n(expected, 9, 0); if (!_CompareVertexPrimvar("topology_w_indices_primvar_insufficient", + registry, _BuildArray(numVerts, sizeof(numVerts)/sizeof(int)), _BuildArray(indices, sizeof(indices)/sizeof(int)), _BuildArray(primvar, sizeof(primvar)/sizeof(float)), @@ -326,10 +334,11 @@ int main() TfErrorMark mark; static HgiUniquePtr _hgi = Hgi::CreatePlatformDefaultHgi(); - registry = std::make_shared(_hgi.get()); + HdStResourceRegistrySharedPtr registry = + std::make_shared(_hgi.get()); bool success = true; - success &= TopologyWithIndicesTest(); + success &= TopologyWithIndicesTest(registry); registry->GarbageCollect(); registry.reset(); diff --git a/pxr/imaging/hdSt/testenv/testHdStDrawBatching.cpp b/pxr/imaging/hdSt/testenv/testHdStDrawBatching.cpp index 75bfc5c78e4..3c86714807e 100644 --- a/pxr/imaging/hdSt/testenv/testHdStDrawBatching.cpp +++ b/pxr/imaging/hdSt/testenv/testHdStDrawBatching.cpp @@ -15,17 +15,22 @@ #include "pxr/imaging/hdSt/renderPass.h" #include "pxr/imaging/hdSt/renderPassShader.h" #include "pxr/imaging/hdSt/resourceRegistry.h" +#include "pxr/imaging/hdSt/renderDelegate.h" #include "pxr/imaging/hdSt/tokens.h" #include "pxr/imaging/hdSt/unitTestHelper.h" #include "pxr/imaging/hdSt/geometricShader.h" +#include "pxr/imaging/hd/driver.h" #include "pxr/imaging/hd/mesh.h" #include "pxr/imaging/hd/perfLog.h" +#include "pxr/imaging/hd/renderIndex.h" #include "pxr/imaging/hd/renderPassState.h" #include "pxr/imaging/hd/rprimSharedData.h" #include "pxr/imaging/hd/tokens.h" #include "pxr/imaging/hd/vtBufferSource.h" +#include "pxr/imaging/hgi/tokens.h" + #include "pxr/imaging/hio/glslfx.h" #include "pxr/imaging/glf/testGLContext.h" @@ -55,10 +60,13 @@ static HdSt_MaterialNetworkShaderSharedPtr _GetFallbackShader() static HdStResourceRegistrySharedPtr _GetResourceRegistry() { static HgiUniquePtr _hgi = Hgi::CreatePlatformDefaultHgi(); - static HdStResourceRegistrySharedPtr _resourceRegistry = - std::make_shared(_hgi.get()); + static HdDriver _driver{HgiTokens->renderDriver, VtValue(_hgi.get())}; + static HdStRenderDelegate _renderDelegate; + static std::unique_ptr _index( + HdRenderIndex::New(&_renderDelegate, {&_driver})); - return _resourceRegistry; + return std::static_pointer_cast( + _index->GetResourceRegistry()); } template diff --git a/pxr/imaging/hdSt/testenv/testHdStDrawItemsCache.cpp b/pxr/imaging/hdSt/testenv/testHdStDrawItemsCache.cpp index ac647f271f2..add2da504df 100644 --- a/pxr/imaging/hdSt/testenv/testHdStDrawItemsCache.cpp +++ b/pxr/imaging/hdSt/testenv/testHdStDrawItemsCache.cpp @@ -136,7 +136,7 @@ class HdSt_MyTestDriver : public HdSt_TestDriverBase public: HdSt_MyTestDriver(); - void Draw(std::vector viewerIds); + void Draw(const std::vector &viewerIds); const HdStRenderPassStateSharedPtr &GetRenderPassState() const { return _renderPassStates[0]; @@ -211,7 +211,7 @@ HdSt_MyTestDriver::HdSt_MyTestDriver() } void -HdSt_MyTestDriver::Draw(std::vector viewerIds) +HdSt_MyTestDriver::Draw(const std::vector &viewerIds) { for (size_t const &vidx : viewerIds) { if (vidx < _viewers.size()) { diff --git a/pxr/imaging/hdSt/testenv/testHdStDynamicUvTexture.cpp b/pxr/imaging/hdSt/testenv/testHdStDynamicUvTexture.cpp index a899def8944..59b135617b2 100644 --- a/pxr/imaging/hdSt/testenv/testHdStDynamicUvTexture.cpp +++ b/pxr/imaging/hdSt/testenv/testHdStDynamicUvTexture.cpp @@ -40,8 +40,6 @@ class My_TestGLDrawing : public HdSt_UnitTestGLDrawing private: std::unique_ptr _driver; - - std::unique_ptr _hdStRegistry; std::unique_ptr _textureHandleRegistry; }; @@ -49,9 +47,9 @@ void My_TestGLDrawing::InitTest() { _driver = std::make_unique(); - _hdStRegistry = std::make_unique(_driver->GetHgi()); _textureHandleRegistry = - std::make_unique(_hdStRegistry.get()); + std::make_unique( + _driver->GetResourceRegistry().get()); } template diff --git a/pxr/imaging/hdSt/testenv/testHdStMeshTopology.cpp b/pxr/imaging/hdSt/testenv/testHdStMeshTopology.cpp index 145488da61e..a24387c41f6 100644 --- a/pxr/imaging/hdSt/testenv/testHdStMeshTopology.cpp +++ b/pxr/imaging/hdSt/testenv/testHdStMeshTopology.cpp @@ -8,19 +8,24 @@ #include "pxr/imaging/hdSt/flatNormals.h" #include "pxr/imaging/hdSt/meshTopology.h" #include "pxr/imaging/hdSt/quadrangulate.h" +#include "pxr/imaging/hdSt/renderDelegate.h" +#include "pxr/imaging/hdSt/resourceRegistry.h" #include "pxr/imaging/hdSt/smoothNormals.h" #include "pxr/imaging/hdSt/triangulate.h" #include "pxr/imaging/hdSt/vertexAdjacency.h" #include "pxr/imaging/hd/bufferSource.h" +#include "pxr/imaging/hd/driver.h" #include "pxr/imaging/hd/smoothNormals.h" #include "pxr/imaging/hd/flatNormals.h" +#include "pxr/imaging/hd/renderIndex.h" #include "pxr/imaging/hd/tokens.h" #include "pxr/imaging/hd/vertexAdjacency.h" #include "pxr/imaging/hd/vtBufferSource.h" -#include "pxr/imaging/hdSt/resourceRegistry.h" #include "pxr/imaging/glf/testGLContext.h" +#include "pxr/imaging/hgi/tokens.h" + #include "pxr/usd/sdf/path.h" #include "pxr/base/gf/math.h" @@ -977,7 +982,12 @@ int main() TfErrorMark mark; static HgiUniquePtr _hgi = Hgi::CreatePlatformDefaultHgi(); - registry = std::make_shared(_hgi.get()); + HdDriver driver{HgiTokens->renderDriver, VtValue(_hgi.get())}; + HdStRenderDelegate renderDelegate; + std::unique_ptr index( + HdRenderIndex::New(&renderDelegate, {&driver})); + registry = std::static_pointer_cast( + index->GetResourceRegistry()); bool success = true; success &= BasicTest(); diff --git a/pxr/imaging/hdSt/testenv/testHdStPrimitiveParam.cpp b/pxr/imaging/hdSt/testenv/testHdStPrimitiveParam.cpp index 85341419117..a12555a4efd 100644 --- a/pxr/imaging/hdSt/testenv/testHdStPrimitiveParam.cpp +++ b/pxr/imaging/hdSt/testenv/testHdStPrimitiveParam.cpp @@ -7,15 +7,19 @@ #include "pxr/imaging/hdSt/meshTopology.h" #include "pxr/imaging/hdSt/quadrangulate.h" +#include "pxr/imaging/hdSt/renderDelegate.h" +#include "pxr/imaging/hdSt/resourceRegistry.h" #include "pxr/imaging/hd/bufferSource.h" +#include "pxr/imaging/hd/driver.h" #include "pxr/imaging/hd/meshUtil.h" #include "pxr/imaging/hd/perfLog.h" +#include "pxr/imaging/hd/renderIndex.h" #include "pxr/imaging/hd/tokens.h" #include "pxr/imaging/hd/vtBufferSource.h" -#include "pxr/imaging/hdSt/resourceRegistry.h" #include "pxr/imaging/glf/testGLContext.h" #include "pxr/imaging/hgi/hgi.h" +#include "pxr/imaging/hgi/tokens.h" #include "pxr/base/gf/math.h" #include "pxr/base/gf/vec2i.h" @@ -349,8 +353,13 @@ int main() TfErrorMark mark; - std::unique_ptr hgi = Hgi::CreatePlatformDefaultHgi(); - registry = std::make_shared(hgi.get()); + HgiUniquePtr hgi = Hgi::CreatePlatformDefaultHgi(); + HdDriver driver{HgiTokens->renderDriver, VtValue(hgi.get())}; + HdStRenderDelegate renderDelegate; + std::unique_ptr index( + HdRenderIndex::New(&renderDelegate, {&driver})); + registry = std::static_pointer_cast( + index->GetResourceRegistry()); bool success = true; success &= PrimitiveIDMapTest(); diff --git a/pxr/imaging/hdSt/testenv/testHdStQuadrangulation.cpp b/pxr/imaging/hdSt/testenv/testHdStQuadrangulation.cpp index 569d7ad69c9..9fc247972ee 100644 --- a/pxr/imaging/hdSt/testenv/testHdStQuadrangulation.cpp +++ b/pxr/imaging/hdSt/testenv/testHdStQuadrangulation.cpp @@ -9,12 +9,16 @@ #include "pxr/imaging/hdSt/meshTopology.h" #include "pxr/imaging/hd/bufferSource.h" +#include "pxr/imaging/hd/driver.h" #include "pxr/imaging/hd/perfLog.h" #include "pxr/imaging/hd/tokens.h" #include "pxr/imaging/hd/types.h" +#include "pxr/imaging/hd/renderIndex.h" #include "pxr/imaging/hd/vtBufferSource.h" #include "pxr/imaging/hdSt/resourceRegistry.h" +#include "pxr/imaging/hdSt/renderDelegate.h" #include "pxr/imaging/glf/testGLContext.h" +#include "pxr/imaging/hgi/tokens.h" #include "pxr/base/gf/math.h" #include "pxr/base/gf/vec3d.h" @@ -75,8 +79,13 @@ _CompareQuadPoints(std::string const & name, std::cout << "GPU quadrangulate = " << gpu << "\n"; static HgiUniquePtr _hgi = Hgi::CreatePlatformDefaultHgi(); - static HdStResourceRegistrySharedPtr registry( - new HdStResourceRegistry(_hgi.get())); + static HdDriver driver{HgiTokens->renderDriver, VtValue(_hgi.get())}; + static HdStRenderDelegate renderDelegate; + static std::unique_ptr index( + HdRenderIndex::New(&renderDelegate, {&driver})); + HdStResourceRegistrySharedPtr const& registry = + std::static_pointer_cast( + index->GetResourceRegistry()); HdMeshTopology m(_tokens->bilinear, TfToken(orientation), numVerts, verts); diff --git a/pxr/imaging/hdSt/testenv/testHdStSamplerObjectRegistry.cpp b/pxr/imaging/hdSt/testenv/testHdStSamplerObjectRegistry.cpp index 4386fe78d57..6c3e0c34fe3 100644 --- a/pxr/imaging/hdSt/testenv/testHdStSamplerObjectRegistry.cpp +++ b/pxr/imaging/hdSt/testenv/testHdStSamplerObjectRegistry.cpp @@ -45,11 +45,12 @@ void My_TestGLDrawing::InitTest() { _driver = std::make_unique(); - _hdStRegistry = std::make_unique(_driver->GetHgi()); _textureRegistry = - std::make_unique(_hdStRegistry.get()); + std::make_unique( + _driver->GetResourceRegistry().get()); _samplerRegistry = - std::make_unique(_hdStRegistry.get()); + std::make_unique( + _driver->GetResourceRegistry().get()); } template diff --git a/pxr/imaging/hdSt/testenv/testHdStSubdivision.cpp b/pxr/imaging/hdSt/testenv/testHdStSubdivision.cpp index 52c3b2c0e3e..7662359005c 100644 --- a/pxr/imaging/hdSt/testenv/testHdStSubdivision.cpp +++ b/pxr/imaging/hdSt/testenv/testHdStSubdivision.cpp @@ -7,10 +7,13 @@ #include "pxr/imaging/hdSt/subdivision.h" #include "pxr/imaging/hdSt/meshTopology.h" +#include "pxr/imaging/hdSt/renderDelegate.h" #include "pxr/imaging/hd/bufferSource.h" +#include "pxr/imaging/hd/driver.h" #include "pxr/imaging/hd/meshUtil.h" #include "pxr/imaging/hd/perfLog.h" +#include "pxr/imaging/hd/renderIndex.h" #include "pxr/imaging/hd/tokens.h" #include "pxr/imaging/hd/vtBufferSource.h" #include "pxr/imaging/hdSt/resourceRegistry.h" @@ -18,6 +21,7 @@ #include "pxr/imaging/pxOsd/tokens.h" #include "pxr/imaging/glf/testGLContext.h" #include "pxr/imaging/hgi/hgi.h" +#include "pxr/imaging/hgi/tokens.h" #include "pxr/base/gf/math.h" #include "pxr/base/gf/vec3d.h" @@ -840,8 +844,13 @@ int main() TfErrorMark mark; - std::unique_ptr hgi = Hgi::CreatePlatformDefaultHgi(); - registry = std::make_shared(hgi.get()); + HgiUniquePtr hgi = Hgi::CreatePlatformDefaultHgi(); + HdDriver driver{HgiTokens->renderDriver, VtValue(hgi.get())}; + HdStRenderDelegate renderDelegate; + std::unique_ptr index( + HdRenderIndex::New(&renderDelegate, {&driver})); + registry = std::static_pointer_cast( + index->GetResourceRegistry()); bool success = true; success &= SubdivisionTest(PxOsdOpenSubdivTokens->catmullClark); diff --git a/pxr/imaging/hdSt/testenv/testHdStTextureHandleRegistry.cpp b/pxr/imaging/hdSt/testenv/testHdStTextureHandleRegistry.cpp index 1cf09a6c4ee..7587051a974 100644 --- a/pxr/imaging/hdSt/testenv/testHdStTextureHandleRegistry.cpp +++ b/pxr/imaging/hdSt/testenv/testHdStTextureHandleRegistry.cpp @@ -39,8 +39,6 @@ class My_TestGLDrawing : public HdSt_UnitTestGLDrawing { private: std::unique_ptr _driver; - - std::unique_ptr _hdStRegistry; std::unique_ptr _textureHandleRegistry; }; @@ -48,10 +46,9 @@ void My_TestGLDrawing::InitTest() { _driver = std::make_unique(); - _hdStRegistry = std::make_unique(_driver->GetHgi()); _textureHandleRegistry = - std::make_unique(_hdStRegistry.get()); - + std::make_unique( + _driver->GetResourceRegistry().get()); } template diff --git a/pxr/imaging/hdSt/testenv/testHdStTextureObjectRegistry.cpp b/pxr/imaging/hdSt/testenv/testHdStTextureObjectRegistry.cpp index 0913ebe9925..21f48790b6c 100644 --- a/pxr/imaging/hdSt/testenv/testHdStTextureObjectRegistry.cpp +++ b/pxr/imaging/hdSt/testenv/testHdStTextureObjectRegistry.cpp @@ -33,8 +33,6 @@ class My_TestGLDrawing : public HdSt_UnitTestGLDrawing { private: std::unique_ptr _driver; - - std::unique_ptr _hdStRegistry; std::unique_ptr _registry; }; @@ -42,9 +40,9 @@ void My_TestGLDrawing::InitTest() { _driver = std::make_unique(); - _hdStRegistry = std::make_unique(_driver->GetHgi()); _registry = - std::make_unique(_hdStRegistry.get()); + std::make_unique( + _driver->GetResourceRegistry().get()); } void diff --git a/pxr/imaging/hdSt/unitTestHelper.cpp b/pxr/imaging/hdSt/unitTestHelper.cpp index 584e3ab940b..31f1328ee82 100644 --- a/pxr/imaging/hdSt/unitTestHelper.cpp +++ b/pxr/imaging/hdSt/unitTestHelper.cpp @@ -325,6 +325,11 @@ HdSt_TestLightingShader::SetLight(int light, HdSt_TextureTestDriver::HdSt_TextureTestDriver() : _hgi(Hgi::CreatePlatformDefaultHgi()) + , _hgiDriver{HgiTokens->renderDriver, VtValue(_hgi.get())} + , _renderDelegate() + , _renderIndex(HdRenderIndex::New(&_renderDelegate, {&_hgiDriver})) + , _resourceRegistry(std::static_pointer_cast( + _renderIndex->GetResourceRegistry())) , _indexBuffer() , _vertexBuffer() , _shaderProgram() @@ -353,6 +358,12 @@ HdSt_TextureTestDriver::~HdSt_TextureTestDriver() } } +HdStResourceRegistrySharedPtr const & +HdSt_TextureTestDriver::GetResourceRegistry() +{ + return _resourceRegistry; +} + void HdSt_TextureTestDriver::Draw(HgiTextureHandle const &colorDst, HgiTextureHandle const &inputTexture, diff --git a/pxr/imaging/hdSt/unitTestHelper.h b/pxr/imaging/hdSt/unitTestHelper.h index 1ce34050176..61fdc6de450 100644 --- a/pxr/imaging/hdSt/unitTestHelper.h +++ b/pxr/imaging/hdSt/unitTestHelper.h @@ -550,6 +550,11 @@ class HdSt_TestDriver final : public HdSt_TestDriverBase HDST_API const HdRenderPassSharedPtr &GetRenderPass(); + + HDST_API + Hgi* GetHgi() { + return _GetHgi(); + } private: void _CreateRenderPassState(); @@ -631,6 +636,9 @@ class HdSt_TextureTestDriver HDST_API Hgi * GetHgi() { return _hgi.get(); } + + HDST_API + HdStResourceRegistrySharedPtr const & GetResourceRegistry(); private: void _CreateShaderProgram(); @@ -643,6 +651,11 @@ class HdSt_TextureTestDriver void _PrintCompileErrors(); HgiUniquePtr _hgi; + HdDriver _hgiDriver; + HdStRenderDelegate _renderDelegate; + std::unique_ptr _renderIndex; + HdStResourceRegistrySharedPtr _resourceRegistry; + HgiBufferHandle _indexBuffer; HgiBufferHandle _vertexBuffer; HgiShaderProgramHandle _shaderProgram; diff --git a/pxr/imaging/hdSt/vboMemoryManager.cpp b/pxr/imaging/hdSt/vboMemoryManager.cpp index 41a2f0fa62d..145bedaf946 100644 --- a/pxr/imaging/hdSt/vboMemoryManager.cpp +++ b/pxr/imaging/hdSt/vboMemoryManager.cpp @@ -20,6 +20,7 @@ #include "pxr/imaging/hgi/blitCmds.h" #include "pxr/imaging/hgi/blitCmdsOps.h" #include "pxr/imaging/hgi/buffer.h" +#include "pxr/imaging/hgi/capabilities.h" #include "pxr/base/arch/hash.h" #include "pxr/base/tf/diagnostic.h" @@ -440,7 +441,10 @@ size_t HdStVBOMemoryManager::_StripedBufferArray::GetMaxNumElements() const { static size_t vboMaxSize = TfGetEnvSetting(HD_MAX_VBO_SIZE); - return vboMaxSize / _maxBytesPerElement; + Hgi* hgi = _resourceRegistry->GetHgi(); + const size_t storageMaxSize = hgi->GetCapabilities()-> + GetMaxShaderStorageBlockSize(); + return std::min(storageMaxSize, vboMaxSize) / _maxBytesPerElement; } void diff --git a/pxr/imaging/hdSt/vboSimpleMemoryManager.cpp b/pxr/imaging/hdSt/vboSimpleMemoryManager.cpp index 40a2f1fe8a8..678ae12b0e9 100644 --- a/pxr/imaging/hdSt/vboSimpleMemoryManager.cpp +++ b/pxr/imaging/hdSt/vboSimpleMemoryManager.cpp @@ -22,6 +22,7 @@ #include "pxr/imaging/hgi/blitCmds.h" #include "pxr/imaging/hgi/blitCmdsOps.h" #include "pxr/imaging/hgi/buffer.h" +#include "pxr/imaging/hgi/capabilities.h" #include "pxr/imaging/hf/perfLog.h" @@ -342,7 +343,10 @@ size_t HdStVBOSimpleMemoryManager::_SimpleBufferArray::GetMaxNumElements() const { static size_t vboMaxSize = TfGetEnvSetting(HD_MAX_VBO_SIZE); - return vboMaxSize / _maxBytesPerElement; + Hgi* hgi = _resourceRegistry->GetHgi(); + const size_t storageMaxSize = hgi->GetCapabilities()-> + GetMaxShaderStorageBlockSize(); + return std::min(storageMaxSize, vboMaxSize) / _maxBytesPerElement; } void diff --git a/pxr/imaging/hdar/pch.h b/pxr/imaging/hdar/pch.h index 85c01c4d1fe..ef878583946 100644 --- a/pxr/imaging/hdar/pch.h +++ b/pxr/imaging/hdar/pch.h @@ -64,6 +64,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #if defined(__APPLE__) // Fix breakage caused by Python's pyport.h. diff --git a/pxr/imaging/hdsi/lightLinkingSceneIndex.cpp b/pxr/imaging/hdsi/lightLinkingSceneIndex.cpp index 1853733c202..d28daf8005f 100644 --- a/pxr/imaging/hdsi/lightLinkingSceneIndex.cpp +++ b/pxr/imaging/hdsi/lightLinkingSceneIndex.cpp @@ -755,10 +755,11 @@ _BuildDependenciesDataSource( const HdPathArrayDataSourceHandle instancePathsDs = topologySchema.GetInstanceLocations(); - if (!instancePathsDs) { - // XXX Point instancer. Per-instance categories does not make sense for - // point instancers. Should we use categories to reflect that they - // apply to all instances (of all prototypes)? + const bool isPointInstancer = + !instancePathsDs || instancePathsDs->GetTypedValue(0.0).empty(); + + if (isPointInstancer) { + // instanceCategories is not relevant to point instancers. return nullptr; } @@ -781,7 +782,9 @@ _BuildDependenciesDataSource( // on all prims targeted by the collection, including instance prims. // // We publish categories only for geometry prims and not instance - // prims. See HdsiLightLinkingSceneIndex::GetPrim. + // prims. See HdsiLightLinkingSceneIndex::GetPrim. + // Note: categories is relevant for instancer prims corresponding + // to point instancers. // size_t idx = 0; for (const SdfPath &instancePath : instancePaths) { @@ -964,7 +967,7 @@ class _LightDataSource : public HdContainerDataSource : name; // Note: Since this scene index relies on linking collections to - // be transported, use an overlay only when we have a + // be transported, provide an override only when we have a // collections data source on the prim to provide the category // ID for the collections, including an empty token for the // trivial case. @@ -1025,7 +1028,10 @@ class _LightPrimDataSource : public HdContainerDataSource TfTokenVector GetNames() override { - return _inputPrimDs->GetNames(); + // 'light' may be absent. + TfTokenVector names = _inputPrimDs->GetNames(); + _AddIfAbsent(HdLightSchemaTokens->light, &names); + return names; } HdDataSourceBaseHandle Get(const TfToken &name) override diff --git a/pxr/imaging/hdsi/pch.h b/pxr/imaging/hdsi/pch.h index 75c86405bf2..dab0bbd08b7 100644 --- a/pxr/imaging/hdsi/pch.h +++ b/pxr/imaging/hdsi/pch.h @@ -69,6 +69,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #if defined(__APPLE__) // Fix breakage caused by Python's pyport.h. diff --git a/pxr/imaging/hdx/pch.h b/pxr/imaging/hdx/pch.h index 20bc190c30d..ddaab1a0a9e 100644 --- a/pxr/imaging/hdx/pch.h +++ b/pxr/imaging/hdx/pch.h @@ -96,6 +96,7 @@ #include #endif // PXR_OCIO_PLUGIN_ENABLED #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #if defined(__APPLE__) // Fix breakage caused by Python's pyport.h. diff --git a/pxr/imaging/hdx/pickTask.cpp b/pxr/imaging/hdx/pickTask.cpp index 55d2e917da5..ffa03df24ea 100644 --- a/pxr/imaging/hdx/pickTask.cpp +++ b/pxr/imaging/hdx/pickTask.cpp @@ -217,9 +217,7 @@ HdxPickTask::_CreateAovBindings() binding.renderBufferId = aovId; binding.aovSettings = aovDesc.aovSettings; binding.renderBuffer = _pickableAovBuffers.back().get(); - // Clear all color channels to 1, so when cast as int, an unwritten - // pixel is encoded as -1. - binding.clearValue = VtValue(GfVec4f(1)); + binding.clearValue = aovDesc.clearValue; _pickableAovBindings.push_back(binding); diff --git a/pxr/imaging/hdx/renderSetupTask.cpp b/pxr/imaging/hdx/renderSetupTask.cpp index 83c3f679e29..9baea7e93a1 100644 --- a/pxr/imaging/hdx/renderSetupTask.cpp +++ b/pxr/imaging/hdx/renderSetupTask.cpp @@ -18,13 +18,12 @@ #include "pxr/imaging/hd/camera.h" #include "pxr/imaging/hdSt/renderPassShader.h" #include "pxr/imaging/hdSt/renderPassState.h" +#include "pxr/imaging/hdSt/resourceRegistry.h" #include "pxr/imaging/hdSt/tokens.h" #include "pxr/imaging/hdSt/volume.h" #include "pxr/imaging/cameraUtil/conformWindow.h" -#include - PXR_NAMESPACE_OPEN_SCOPE static const HioGlslfxSharedPtr & @@ -43,13 +42,15 @@ _GetRenderPassIdGlslfx() return glslfx; } -HdxRenderSetupTask::HdxRenderSetupTask(HdSceneDelegate* delegate, SdfPath const& id) +HdxRenderSetupTask::HdxRenderSetupTask( + HdSceneDelegate* delegate, SdfPath const& id) : HdTask(id) , _colorRenderPassShader( std::make_shared(_GetRenderPassColorGlslfx())) , _idRenderPassShader( std::make_shared(_GetRenderPassIdGlslfx())) , _viewport(0) + , _enableIdRenderFromParams(false) { } @@ -96,6 +97,12 @@ HdxRenderSetupTask::Prepare(HdTaskContext* ctx, HdStVolume::defaultStepSizeLighting); renderPassState->SetVolumeRenderingConstants(stepSize, stepSizeLighting); + if (HdStRenderPassState * const hdStRenderPassState = + dynamic_cast(renderPassState.get())) { + _SetRenderpassShadersForStorm(hdStRenderPassState, + renderIndex->GetResourceRegistry()); + } + renderPassState->Prepare(renderIndex->GetResourceRegistry()); (*ctx)[HdxTokens->renderPassState] = VtValue(_renderPassState); } @@ -110,23 +117,67 @@ HdxRenderSetupTask::Execute(HdTaskContext* ctx) (*ctx)[HdxTokens->renderPassState] = VtValue(_renderPassState); } +static +bool +_AovHasIdSemantic(TfToken const &name) +{ + // For now id render only means primId or instanceId. + return name == HdAovTokens->primId || + name == HdAovTokens->instanceId; +} + void HdxRenderSetupTask::_SetRenderpassShadersForStorm( - HdxRenderTaskParams const ¶ms, - HdStRenderPassState *renderPassState) + HdStRenderPassState *renderPassState, + HdResourceRegistrySharedPtr const &resourceRegistry) { - renderPassState->SetUseSceneMaterials(params.enableSceneMaterials); - if (params.enableIdRender) { + // XXX: This id render codepath will be deprecated soon. + if (_enableIdRenderFromParams) { renderPassState->SetRenderPassShader(_idRenderPassShader); - } else { + return; + // If no aovs are bound, use pre-assembled color render pass shader. + } else if (_aovBindings.empty()) { renderPassState->SetRenderPassShader(_colorRenderPassShader); + return; } + + HdStResourceRegistrySharedPtr const& hdStResourceRegistry = + std::static_pointer_cast(resourceRegistry); + + renderPassState->SetRenderPassShader( + HdStRenderPassShader::CreateRenderPassShaderFromAovs( + renderPassState, + hdStResourceRegistry, + _aovBindings)); } void HdxRenderSetupTask::SyncParams(HdSceneDelegate* delegate, HdxRenderTaskParams const ¶ms) { + _viewport = params.viewport; + _framing = params.framing; + _overrideWindowPolicy = params.overrideWindowPolicy; + _cameraId = params.camera; + _aovBindings = params.aovBindings; + _aovInputBindings = params.aovInputBindings; + + // Inspect aovs to see if we're doing an id render. + bool usingIdAov = false; + for (size_t i = 0; i < _aovBindings.size(); ++i) { + if (_AovHasIdSemantic(_aovBindings[i].aovName)) { + usingIdAov = true; + break; + } + } + + // XXX: For now, we track enabling an id render via params vs. AOV bindings + // as two slightly different states regarding MSAA. We will soon deprecate + // "enableIdRender" as an option, though. + _enableIdRenderFromParams = params.enableIdRender; + const bool enableIdRender = params.enableIdRender || usingIdAov; + const bool enableIdRenderNoIdAov = params.enableIdRender && !usingIdAov; + HdRenderIndex &renderIndex = delegate->GetRenderIndex(); HdRenderPassStateSharedPtr &renderPassState = _GetRenderPassState(&renderIndex); @@ -167,34 +218,34 @@ HdxRenderSetupTask::SyncParams(HdSceneDelegate* delegate, renderPassState->SetBlendConstantColor(params.blendConstantColor); // Don't enable alpha to coverage for id renders. + // XXX: If the list of aovs includes both color and an id aov (such as + // primdId), we still disable alpha to coverage for the render pass, + // which may result in different behavior for the color output compared + // to if the user didn't request an id aov at the same time. + // If this becomes an issue, we'll need to reconsider this approach. renderPassState->SetAlphaToCoverageEnabled( params.enableAlphaToCoverage && - !params.enableIdRender && + !enableIdRender && !TfDebug::IsEnabled(HDX_DISABLE_ALPHA_TO_COVERAGE)); + // For id renders that use an id aov (which use an int format), it's ok + // to have multi-sampling enabled. During the MSAA resolve for integer + // types, a single sample will be selected. renderPassState->SetMultiSampleEnabled( - params.useAovMultiSample && !params.enableIdRender); + params.useAovMultiSample && !enableIdRenderNoIdAov); if (HdStRenderPassState * const hdStRenderPassState = dynamic_cast(renderPassState.get())) { - + hdStRenderPassState->SetUseSceneMaterials( + params.enableSceneMaterials); + // Don't enable multisample for id renders. hdStRenderPassState->SetUseAovMultiSample( - params.useAovMultiSample && !params.enableIdRender); + params.useAovMultiSample && !enableIdRenderNoIdAov); hdStRenderPassState->SetResolveAovMultiSample( params.resolveAovMultiSample); - - _SetRenderpassShadersForStorm( - params, hdStRenderPassState); } } - - _viewport = params.viewport; - _framing = params.framing; - _overrideWindowPolicy = params.overrideWindowPolicy; - _cameraId = params.camera; - _aovBindings = params.aovBindings; - _aovInputBindings = params.aovInputBindings; } void diff --git a/pxr/imaging/hdx/renderSetupTask.h b/pxr/imaging/hdx/renderSetupTask.h index 396b57bfb1f..6268917da2e 100644 --- a/pxr/imaging/hdx/renderSetupTask.h +++ b/pxr/imaging/hdx/renderSetupTask.h @@ -97,10 +97,11 @@ class HdxRenderSetupTask : public HdTask GfVec4d _viewport; HdRenderPassAovBindingVector _aovBindings; HdRenderPassAovBindingVector _aovInputBindings; + bool _enableIdRenderFromParams; void _SetRenderpassShadersForStorm( - HdxRenderTaskParams const& params, - HdStRenderPassState *renderPassState); + HdStRenderPassState *renderPassState, + HdResourceRegistrySharedPtr const &resourceRegistry); HdRenderPassStateSharedPtr &_GetRenderPassState(HdRenderIndex* renderIndex); diff --git a/pxr/imaging/hdx/selectionTracker.h b/pxr/imaging/hdx/selectionTracker.h index c8fcb865b3f..7233dfd0461 100644 --- a/pxr/imaging/hdx/selectionTracker.h +++ b/pxr/imaging/hdx/selectionTracker.h @@ -94,6 +94,8 @@ class HdxSelectionTracker public: HDX_API HdxSelectionTracker(); + + HDX_API virtual ~HdxSelectionTracker(); /// Optional override to update the selection (either compute HdSelection and diff --git a/pxr/imaging/hdx/shaders/renderPass.glslfx b/pxr/imaging/hdx/shaders/renderPass.glslfx index 9b9e515f798..be46118ac93 100644 --- a/pxr/imaging/hdx/shaders/renderPass.glslfx +++ b/pxr/imaging/hdx/shaders/renderPass.glslfx @@ -125,11 +125,11 @@ void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) -- layout HdxRenderPass.RenderPick [ - ["out", "vec4", "primIdOut"], - ["out", "vec4", "instanceIdOut"], - ["out", "vec4", "elementIdOut"], - ["out", "vec4", "edgeIdOut"], - ["out", "vec4", "pointIdOut"], + ["out", "int", "primIdOut"], + ["out", "int", "instanceIdOut"], + ["out", "int", "elementIdOut"], + ["out", "int", "edgeIdOut"], + ["out", "int", "pointIdOut"], ["out", "vec4", "neyeOut"], ["buffer readWrite", "CounterBuffer", "PickBuffer", ["atomic_int", "PickBuffer"]] ] @@ -156,27 +156,21 @@ FORWARD_DECL(void RenderDeepPicks(int primId, int instanceId, int elementId, int void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord) { - int primId = HdGet_primID(); - primIdOut = IntToVec4(primId); + primIdOut = HdGet_primID(); // instanceIndex is a tuple of integers (num nested levels). // for picking, we store global instanceId (instanceIndex[0]) in the // selection framebuffer and then reconstruct the tuple in postprocess. - int instanceId = GetDrawingCoord().instanceIndex[0]; - instanceIdOut = IntToVec4(instanceId); + instanceIdOut = GetDrawingCoord().instanceIndex[0]; - int elementId = GetElementID(); - int edgeId = GetPrimitiveEdgeId(); - int pointId = GetPointId(); - - elementIdOut = IntToVec4(elementId); - edgeIdOut = IntToVec4(edgeId); - pointIdOut = IntToVec4(pointId); + elementIdOut = GetElementID(); + edgeIdOut = GetPrimitiveEdgeId(); + pointIdOut = GetPointId(); neyeOut = IntToVec4(hd_vec4_2_10_10_10_set(vec4(Neye,0))); #if defined(HD_HAS_PickBuffer) - RenderDeepPicks(primId, instanceId, elementId, edgeId, pointId); + RenderDeepPicks(primIdOut, instanceIdOut, elementIdOut, edgeIdOut, pointIdOut); #endif } diff --git a/pxr/imaging/hdx/shaders/renderPassColorShader.glslfx b/pxr/imaging/hdx/shaders/renderPassColorShader.glslfx index bb05ce38ffe..d4b60759374 100644 --- a/pxr/imaging/hdx/shaders/renderPassColorShader.glslfx +++ b/pxr/imaging/hdx/shaders/renderPassColorShader.glslfx @@ -11,7 +11,6 @@ --- #import $TOOLS/hdx/shaders/renderPassColorShader.glslfx #import $TOOLS/hdSt/shaders/renderPass.glslfx -#import $TOOLS/hdx/shaders/renderPass.glslfx #import $TOOLS/hdx/shaders/selection.glslfx -- configuration @@ -46,7 +45,10 @@ "Selection.DecodeUtils", "Selection.ComputeColor", "RenderPass.ApplyColorOverrides", - "RenderPass.RenderColor" ] + "RenderPass.RenderColor", + "RenderPass.RenderIdNoOp", + "RenderPass.RenderNeyeNoOp", + "RenderPass.RenderOutput" ] } } } diff --git a/pxr/imaging/hdx/shaders/renderPassIdShader.glslfx b/pxr/imaging/hdx/shaders/renderPassIdShader.glslfx index 67495226eaa..ea45bd8498b 100644 --- a/pxr/imaging/hdx/shaders/renderPassIdShader.glslfx +++ b/pxr/imaging/hdx/shaders/renderPassIdShader.glslfx @@ -11,7 +11,6 @@ --- #import $TOOLS/hdx/shaders/renderPassIdShader.glslfx #import $TOOLS/hdSt/shaders/renderPass.glslfx -#import $TOOLS/hdx/shaders/renderPass.glslfx -- configuration { @@ -44,7 +43,7 @@ "RenderPass.CameraFS", "RenderPass.NoSelection", "RenderPass.NoColorOverrides", - "RenderPass.RenderId" ] + "RenderPass.RenderIdNoIdAov"] } } } diff --git a/pxr/imaging/hdx/shaders/renderPassShadowShader.glslfx b/pxr/imaging/hdx/shaders/renderPassShadowShader.glslfx index 967a419f3ea..67219ef8dfb 100644 --- a/pxr/imaging/hdx/shaders/renderPassShadowShader.glslfx +++ b/pxr/imaging/hdx/shaders/renderPassShadowShader.glslfx @@ -11,7 +11,6 @@ --- #import $TOOLS/hdx/shaders/renderPassShadowShader.glslfx #import $TOOLS/hdSt/shaders/renderPass.glslfx -#import $TOOLS/hdx/shaders/renderPass.glslfx -- configuration { @@ -44,7 +43,10 @@ "RenderPass.CameraFS", "RenderPass.NoSelection", "RenderPass.NoColorOverrides", - "RenderPass.RenderColor" ] + "RenderPass.RenderColor", + "RenderPass.RenderIdNoOp", + "RenderPass.RenderNeyeNoOp", + "RenderPass.RenderOutput" ] } } } diff --git a/pxr/imaging/hdx/testenv/testHdxIdRender.cpp b/pxr/imaging/hdx/testenv/testHdxIdRender.cpp index f92b86e503c..2678526d235 100644 --- a/pxr/imaging/hdx/testenv/testHdxIdRender.cpp +++ b/pxr/imaging/hdx/testenv/testHdxIdRender.cpp @@ -90,7 +90,6 @@ Hdx_TestDriver::Draw(GfVec4d const &viewport, PickParam const * pickParam) HdxRenderTaskParams param = delegate.GetTaskParam( renderSetupTask, HdTokens->params).Get(); - param.enableIdRender = (pickParam != nullptr); param.viewport = viewport; param.aovBindings = pickParam ? _pickableAovBindings : _aovBindings; delegate.SetTaskParam(renderSetupTask, HdTokens->params, VtValue(param)); diff --git a/pxr/imaging/hgi/pch.h b/pxr/imaging/hgi/pch.h index 75803135c69..f61e1899f3d 100644 --- a/pxr/imaging/hgi/pch.h +++ b/pxr/imaging/hgi/pch.h @@ -69,6 +69,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #if defined(__APPLE__) // Fix breakage caused by Python's pyport.h. diff --git a/pxr/imaging/hgiGL/ops.cpp b/pxr/imaging/hgiGL/ops.cpp index a0473c4797d..1f69ecd8b5c 100644 --- a/pxr/imaging/hgiGL/ops.cpp +++ b/pxr/imaging/hgiGL/ops.cpp @@ -740,6 +740,16 @@ HgiGLOps::Dispatch(int dimX, int dimY) }; } +static +bool +_IsInt32Format(HgiFormat format) +{ + return (format == HgiFormatInt32) || + (format == HgiFormatInt32Vec2) || + (format == HgiFormatInt32Vec3) || + (format == HgiFormatInt32Vec4); +} + HgiGLOpsFn HgiGLOps::BindFramebufferOp( HgiGLDevice* device, @@ -769,7 +779,19 @@ HgiGLOps::BindFramebufferOp( } if (colorAttachment.loadOp == HgiAttachmentLoadOpClear) { - glClearBufferfv(GL_COLOR, i, colorAttachment.clearValue.data()); + // Special handling for int format used by id renders. + if (_IsInt32Format(colorAttachment.format)) { + GLint clearValue[4] = { + static_cast(colorAttachment.clearValue[0]), + static_cast(colorAttachment.clearValue[1]), + static_cast(colorAttachment.clearValue[2]), + static_cast(colorAttachment.clearValue[3]) + }; + glClearBufferiv(GL_COLOR, i, clearValue); + } else { + glClearBufferfv( + GL_COLOR, i, colorAttachment.clearValue.data()); + } } blendEnabled |= colorAttachment.blendEnabled; diff --git a/pxr/imaging/hgiInterop/pch.h b/pxr/imaging/hgiInterop/pch.h index f6e968984dd..ce02a5f4eb1 100644 --- a/pxr/imaging/hgiInterop/pch.h +++ b/pxr/imaging/hgiInterop/pch.h @@ -49,6 +49,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #if defined(__APPLE__) // Fix breakage caused by Python's pyport.h. diff --git a/pxr/imaging/hgiVulkan/CMakeLists.txt b/pxr/imaging/hgiVulkan/CMakeLists.txt index 61ea8bd71fd..48953c03da2 100644 --- a/pxr/imaging/hgiVulkan/CMakeLists.txt +++ b/pxr/imaging/hgiVulkan/CMakeLists.txt @@ -93,6 +93,9 @@ pxr_register_test(testHgiVulkan FAIL_PERCENT 0.001 PERCEPTUAL EXPECTED_RETURN_CODE 0 + ENV + HGI_ENABLE_VULKAN=1 + HGIVULKAN_DEBUG=1 ) # This test is not currently supported on static builds as it relies on diff --git a/pxr/imaging/hgiVulkan/buffer.cpp b/pxr/imaging/hgiVulkan/buffer.cpp index eaa653a2b9c..7484e71e122 100644 --- a/pxr/imaging/hgiVulkan/buffer.cpp +++ b/pxr/imaging/hgiVulkan/buffer.cpp @@ -40,7 +40,7 @@ HgiVulkanBuffer::HgiVulkanBuffer( VkBufferCreateInfo bi = {VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO}; bi.size = _descriptor.byteSize; bi.usage = HgiVulkanConversions::GetBufferUsage(_descriptor.usage); - bi.usage |= VK_BUFFER_USAGE_TRANSFER_SRC_BIT | + bi.usage |= VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT; bi.sharingMode = VK_SHARING_MODE_EXCLUSIVE; // gfx queue only @@ -52,8 +52,8 @@ HgiVulkanBuffer::HgiVulkanBuffer( VmaAllocationCreateInfo ai = {}; ai.preferredFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; // GPU efficient - TF_VERIFY( - vmaCreateBuffer(vma,&bi,&ai,&_vkBuffer,&_vmaAllocation,0) == VK_SUCCESS + HGIVULKAN_VERIFY_VK_RESULT( + vmaCreateBuffer(vma,&bi,&ai,&_vkBuffer,&_vmaAllocation,0) ); // Debug label @@ -71,10 +71,12 @@ HgiVulkanBuffer::HgiVulkanBuffer( // the device-local GPU buffer. HgiBufferDesc stagingDesc = _descriptor; if (!stagingDesc.debugName.empty()) { - stagingDesc.debugName = "Staging Buffer for " + stagingDesc.debugName; + stagingDesc.debugName = + "Staging Buffer for " + stagingDesc.debugName; } - HgiVulkanBuffer* stagingBuffer = CreateStagingBuffer(_device, stagingDesc); + HgiVulkanBuffer* stagingBuffer = CreateStagingBuffer( + _device, stagingDesc); VkBuffer vkStagingBuf = stagingBuffer->GetVulkanBuffer(); HgiVulkanCommandQueue* queue = device->GetCommandQueue(); @@ -152,18 +154,19 @@ HgiVulkanBuffer::GetCPUStagingAddress() HgiBufferDesc stagingDesc = _descriptor; stagingDesc.initialData = nullptr; if (!stagingDesc.debugName.empty()) { - stagingDesc.debugName = "Staging Buffer for " + stagingDesc.debugName; + stagingDesc.debugName = + "Staging Buffer for " + stagingDesc.debugName; } _stagingBuffer = CreateStagingBuffer(_device, stagingDesc); } if (!_cpuStagingAddress) { - TF_VERIFY( + HGIVULKAN_VERIFY_VK_RESULT( vmaMapMemory( - _device->GetVulkanMemoryAllocator(), - _stagingBuffer->GetVulkanMemoryAllocation(), - &_cpuStagingAddress) == VK_SUCCESS + _device->GetVulkanMemoryAllocator(), + _stagingBuffer->GetVulkanMemoryAllocation(), + &_cpuStagingAddress) ); } @@ -219,7 +222,7 @@ HgiVulkanBuffer::CreateStagingBuffer( VkBufferCreateInfo bi = {VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO}; bi.size = desc.byteSize; bi.usage = HgiVulkanConversions::GetBufferUsage(desc.usage); - bi.usage |= VK_BUFFER_USAGE_TRANSFER_SRC_BIT | + bi.usage |= VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT; bi.sharingMode = VK_SHARING_MODE_EXCLUSIVE; // gfx queue only @@ -230,14 +233,16 @@ HgiVulkanBuffer::CreateStagingBuffer( VkBuffer buffer = 0; VmaAllocation alloc = 0; - TF_VERIFY( - vmaCreateBuffer(vma, &bi, &ai, &buffer, &alloc, 0) == VK_SUCCESS + HGIVULKAN_VERIFY_VK_RESULT( + vmaCreateBuffer(vma, &bi, &ai, &buffer, &alloc, 0) ); // Map the (HOST_VISIBLE) buffer and upload data if (desc.initialData) { void* map; - TF_VERIFY(vmaMapMemory(vma, alloc, &map) == VK_SUCCESS); + HGIVULKAN_VERIFY_VK_RESULT( + vmaMapMemory(vma, alloc, &map) + ); memcpy(map, desc.initialData, desc.byteSize); vmaUnmapMemory(vma, alloc); } @@ -246,4 +251,4 @@ HgiVulkanBuffer::CreateStagingBuffer( return new HgiVulkanBuffer(device, buffer, alloc, desc); } -PXR_NAMESPACE_CLOSE_SCOPE +PXR_NAMESPACE_CLOSE_SCOPE \ No newline at end of file diff --git a/pxr/imaging/hgiVulkan/commandBuffer.cpp b/pxr/imaging/hgiVulkan/commandBuffer.cpp index 3662257b9e0..77e8106466b 100644 --- a/pxr/imaging/hgiVulkan/commandBuffer.cpp +++ b/pxr/imaging/hgiVulkan/commandBuffer.cpp @@ -36,11 +36,11 @@ HgiVulkanCommandBuffer::HgiVulkanCommandBuffer( allocInfo.commandPool = pool; allocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; - TF_VERIFY( + HGIVULKAN_VERIFY_VK_RESULT( vkAllocateCommandBuffers( vkDevice, &allocInfo, - &_vkCommandBuffer) == VK_SUCCESS + &_vkCommandBuffer) ); // Assign a debug label to command buffer @@ -58,23 +58,23 @@ HgiVulkanCommandBuffer::HgiVulkanCommandBuffer( VkFenceCreateInfo fenceInfo = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO}; fenceInfo.flags = 0; // Unsignaled starting state - TF_VERIFY( + HGIVULKAN_VERIFY_VK_RESULT( vkCreateFence( vkDevice, &fenceInfo, HgiVulkanAllocator(), - &_vkFence) == VK_SUCCESS + &_vkFence) ); // Create semaphore for GPU-GPU synchronization VkSemaphoreCreateInfo semaCreateInfo = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO}; - TF_VERIFY( + HGIVULKAN_VERIFY_VK_RESULT( vkCreateSemaphore( vkDevice, &semaCreateInfo, HgiVulkanAllocator(), - &_vkSemaphore) == VK_SUCCESS + &_vkSemaphore) ); // Assign a debug label to fence. @@ -105,8 +105,8 @@ HgiVulkanCommandBuffer::BeginCommandBuffer(uint8_t inflightId) {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO}; beginInfo.flags |= VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; - TF_VERIFY( - vkBeginCommandBuffer(_vkCommandBuffer, &beginInfo) == VK_SUCCESS + HGIVULKAN_VERIFY_VK_RESULT( + vkBeginCommandBuffer(_vkCommandBuffer, &beginInfo) ); _inflightId = inflightId; @@ -133,8 +133,8 @@ HgiVulkanCommandBuffer::EndCommandBuffer() TF_VERIFY(_isInFlight); TF_VERIFY(!_isSubmitted); - TF_VERIFY( - vkEndCommandBuffer(_vkCommandBuffer) == VK_SUCCESS + HGIVULKAN_VERIFY_VK_RESULT( + vkEndCommandBuffer(_vkCommandBuffer) ); _isSubmitted = true; @@ -163,8 +163,9 @@ HgiVulkanCommandBuffer::UpdateInFlightStatus(HgiSubmitWaitType wait) } static const uint64_t timeOut = 100000000000; - TF_VERIFY(vkWaitForFences( - vkDevice, 1, &_vkFence, VK_TRUE, timeOut) == VK_SUCCESS); + HGIVULKAN_VERIFY_VK_RESULT( + vkWaitForFences(vkDevice, 1, &_vkFence, VK_TRUE, timeOut) + ); } _isInFlight = false; @@ -191,8 +192,8 @@ HgiVulkanCommandBuffer::ResetIfConsumedByGPU(HgiSubmitWaitType wait) VkDevice vkDevice = _device->GetVulkanDevice(); // GPU is done with command buffer, reset fence and command buffer. - TF_VERIFY( - vkResetFences(vkDevice, 1, &_vkFence) == VK_SUCCESS + HGIVULKAN_VERIFY_VK_RESULT( + vkResetFences(vkDevice, 1, &_vkFence) ); // It might be more efficient to reset the cmd pool instead of individual @@ -202,8 +203,8 @@ HgiVulkanCommandBuffer::ResetIfConsumedByGPU(HgiSubmitWaitType wait) // been consumed by the GPU. VkCommandBufferResetFlags flags = _GetCommandBufferResetFlags(); - TF_VERIFY( - vkResetCommandBuffer(_vkCommandBuffer, flags) == VK_SUCCESS + HGIVULKAN_VERIFY_VK_RESULT( + vkResetCommandBuffer(_vkCommandBuffer, flags) ); // Command buffer may now be reused for new recordings / resource creation. diff --git a/pxr/imaging/hgiVulkan/commandQueue.cpp b/pxr/imaging/hgiVulkan/commandQueue.cpp index c70f479e8a7..7ad54a43125 100644 --- a/pxr/imaging/hgiVulkan/commandQueue.cpp +++ b/pxr/imaging/hgiVulkan/commandQueue.cpp @@ -9,6 +9,7 @@ #include "pxr/imaging/hgiVulkan/device.h" #include "pxr/base/tf/diagnostic.h" +#include "pxr/imaging/hgiVulkan/diagnostic.h" PXR_NAMESPACE_OPEN_SCOPE @@ -27,12 +28,12 @@ _CreateCommandPool(HgiVulkanDevice* device) VkCommandPool pool = nullptr; - TF_VERIFY( + HGIVULKAN_VERIFY_VK_RESULT( vkCreateCommandPool( device->GetVulkanDevice(), &poolCreateInfo, HgiVulkanAllocator(), - &pool) == VK_SUCCESS + &pool) ); HgiVulkanCommandQueue::HgiVulkan_CommandPool* newPool = @@ -110,8 +111,8 @@ HgiVulkanCommandQueue::SubmitToQueue( resourceInfo.signalSemaphoreCount = 1; resourceInfo.pSignalSemaphores = &semaphore; - TF_VERIFY( - vkQueueSubmit(_vkGfxQueue, 1, &resourceInfo, rFence) == VK_SUCCESS + HGIVULKAN_VERIFY_VK_RESULT( + vkQueueSubmit(_vkGfxQueue, 1, &resourceInfo, rFence) ); _resourceCommandBuffer = nullptr; @@ -139,16 +140,16 @@ HgiVulkanCommandQueue::SubmitToQueue( // Record and submission order does not guarantee execution order. // VK docs: "Execution Model" & "Implicit Synchronization Guarantees". // The vulkan queue must be externally synchronized. - TF_VERIFY( - vkQueueSubmit(_vkGfxQueue, 1, &workInfo, wFence) == VK_SUCCESS + HGIVULKAN_VERIFY_VK_RESULT( + vkQueueSubmit(_vkGfxQueue, 1, &workInfo, wFence) ); // Optional blocking wait if (wait == HgiSubmitWaitTypeWaitUntilCompleted) { static const uint64_t timeOut = 100000000000; VkDevice vkDevice = _device->GetVulkanDevice(); - TF_VERIFY( - vkWaitForFences(vkDevice, 1, &wFence, VK_TRUE, timeOut)==VK_SUCCESS + HGIVULKAN_VERIFY_VK_RESULT( + vkWaitForFences(vkDevice, 1, &wFence, VK_TRUE, timeOut) ); // When the client waits for the cmd buf to finish on GPU they will // expect to have the CompletedHandlers run. For example when the diff --git a/pxr/imaging/hgiVulkan/computePipeline.cpp b/pxr/imaging/hgiVulkan/computePipeline.cpp index 20129e0966b..1b8bb3f3fbd 100644 --- a/pxr/imaging/hgiVulkan/computePipeline.cpp +++ b/pxr/imaging/hgiVulkan/computePipeline.cpp @@ -72,12 +72,12 @@ HgiVulkanComputePipeline::HgiVulkanComputePipeline( pipeLayCreateInfo.setLayoutCount = (uint32_t)_vkDescriptorSetLayouts.size(); pipeLayCreateInfo.pSetLayouts = _vkDescriptorSetLayouts.data(); - TF_VERIFY( + HGIVULKAN_VERIFY_VK_RESULT( vkCreatePipelineLayout( _device->GetVulkanDevice(), &pipeLayCreateInfo, HgiVulkanAllocator(), - &_vkPipelineLayout) == VK_SUCCESS + &_vkPipelineLayout) ); // Debug label @@ -97,14 +97,14 @@ HgiVulkanComputePipeline::HgiVulkanComputePipeline( // HgiVulkanPipelineCache* pCache = device->GetPipelineCache(); - TF_VERIFY( + HGIVULKAN_VERIFY_VK_RESULT( vkCreateComputePipelines( _device->GetVulkanDevice(), pCache->GetVulkanPipelineCache(), 1, &pipeCreateInfo, HgiVulkanAllocator(), - &_vkPipeline) == VK_SUCCESS + &_vkPipeline) ); // Debug label @@ -162,4 +162,4 @@ HgiVulkanComputePipeline::GetInflightBits() return _inflightBits; } -PXR_NAMESPACE_CLOSE_SCOPE +PXR_NAMESPACE_CLOSE_SCOPE \ No newline at end of file diff --git a/pxr/imaging/hgiVulkan/device.cpp b/pxr/imaging/hgiVulkan/device.cpp index 19d7eb103f9..15b0bef1c83 100644 --- a/pxr/imaging/hgiVulkan/device.cpp +++ b/pxr/imaging/hgiVulkan/device.cpp @@ -95,11 +95,11 @@ HgiVulkanDevice::HgiVulkanDevice(HgiVulkanInstance* instance) const uint32_t maxDevices = 64; VkPhysicalDevice physicalDevices[maxDevices]; uint32_t physicalDeviceCount = maxDevices; - TF_VERIFY( + HGIVULKAN_VERIFY_VK_RESULT( vkEnumeratePhysicalDevices( instance->GetVulkanInstance(), &physicalDeviceCount, - physicalDevices) == VK_SUCCESS + physicalDevices) ); for (uint32_t i = 0; i < physicalDeviceCount; i++) { @@ -141,22 +141,22 @@ HgiVulkanDevice::HgiVulkanDevice(HgiVulkanInstance* instance) // uint32_t extensionCount = 0; - TF_VERIFY( + HGIVULKAN_VERIFY_VK_RESULT( vkEnumerateDeviceExtensionProperties( _vkPhysicalDevice, nullptr, &extensionCount, - nullptr) == VK_SUCCESS + nullptr) ); _vkExtensions.resize(extensionCount); - TF_VERIFY( + HGIVULKAN_VERIFY_VK_RESULT( vkEnumerateDeviceExtensionProperties( _vkPhysicalDevice, nullptr, &extensionCount, - _vkExtensions.data()) == VK_SUCCESS + _vkExtensions.data()) ); // @@ -300,12 +300,12 @@ HgiVulkanDevice::HgiVulkanDevice(HgiVulkanInstance* instance) createInfo.enabledExtensionCount = (uint32_t) extensions.size(); createInfo.pNext = &features; - TF_VERIFY( + HGIVULKAN_VERIFY_VK_RESULT( vkCreateDevice( _vkPhysicalDevice, &createInfo, HgiVulkanAllocator(), - &_vkDevice) == VK_SUCCESS + &_vkDevice) ); volkLoadDevice(_vkDevice); @@ -364,8 +364,8 @@ HgiVulkanDevice::HgiVulkanDevice(HgiVulkanInstance* instance) vmaVulkanFunctions.vkCmdCopyBuffer = vkCmdCopyBuffer; allocatorInfo.pVulkanFunctions = &vmaVulkanFunctions; - TF_VERIFY( - vmaCreateAllocator(&allocatorInfo, &_vmaAllocator) == VK_SUCCESS + HGIVULKAN_VERIFY_VK_RESULT( + vmaCreateAllocator(&allocatorInfo, &_vmaAllocator) ); // @@ -384,7 +384,9 @@ HgiVulkanDevice::HgiVulkanDevice(HgiVulkanInstance* instance) HgiVulkanDevice::~HgiVulkanDevice() { // Make sure device is idle before destroying objects. - TF_VERIFY(vkDeviceWaitIdle(_vkDevice) == VK_SUCCESS); + HGIVULKAN_VERIFY_VK_RESULT( + vkDeviceWaitIdle(_vkDevice) + ); delete _pipelineCache; delete _commandQueue; @@ -438,8 +440,8 @@ HgiVulkanDevice::GetPipelineCache() const void HgiVulkanDevice::WaitForIdle() { - TF_VERIFY( - vkDeviceWaitIdle(_vkDevice) == VK_SUCCESS + HGIVULKAN_VERIFY_VK_RESULT( + vkDeviceWaitIdle(_vkDevice) ); } diff --git a/pxr/imaging/hgiVulkan/diagnostic.cpp b/pxr/imaging/hgiVulkan/diagnostic.cpp index 64ba4853807..c48af5f41c7 100644 --- a/pxr/imaging/hgiVulkan/diagnostic.cpp +++ b/pxr/imaging/hgiVulkan/diagnostic.cpp @@ -14,6 +14,8 @@ #include "pxr/base/tf/diagnostic.h" #include "pxr/base/tf/envSetting.h" +#include + #include @@ -21,7 +23,7 @@ PXR_NAMESPACE_OPEN_SCOPE TF_DEFINE_ENV_SETTING(HGIVULKAN_DEBUG, 0, "Enable debugging for HgiVulkan"); -TF_DEFINE_ENV_SETTING(HGIVULKAN_DEBUG_VERBOSE, 0, +TF_DEFINE_ENV_SETTING(HGIVULKAN_DEBUG_VERBOSE, 0, "Enable verbose debugging for HgiVulkan"); bool @@ -108,12 +110,12 @@ HgiVulkanCreateDebug(HgiVulkanInstance* instance) dbgMsgCreateInfo.pfnUserCallback = _VulkanDebugCallback; dbgMsgCreateInfo.pUserData = nullptr; - TF_VERIFY( + HGIVULKAN_VERIFY_VK_RESULT( instance->vkCreateDebugUtilsMessengerEXT( vkInstance, &dbgMsgCreateInfo, HgiVulkanAllocator(), - &instance->vkDebugMessenger) == VK_SUCCESS + &instance->vkDebugMessenger) ); } @@ -250,4 +252,10 @@ HgiVulkanEndQueueLabel(HgiVulkanDevice* device) device->vkQueueEndDebugUtilsLabelEXT(gfxQueue); } -PXR_NAMESPACE_CLOSE_SCOPE +const char* +HgiVulkanResultString(VkResult result) +{ + return string_VkResult(result); +} + +PXR_NAMESPACE_CLOSE_SCOPE \ No newline at end of file diff --git a/pxr/imaging/hgiVulkan/diagnostic.h b/pxr/imaging/hgiVulkan/diagnostic.h index 84adc09cf75..f4f4beadc6f 100644 --- a/pxr/imaging/hgiVulkan/diagnostic.h +++ b/pxr/imaging/hgiVulkan/diagnostic.h @@ -66,6 +66,20 @@ void HgiVulkanBeginQueueLabel( HGIVULKAN_API void HgiVulkanEndQueueLabel(HgiVulkanDevice* device); +/// Returns a string representation of VkResult +HGIVULKAN_API +const char* HgiVulkanResultString(VkResult result); + +#define HGIVULKAN_VERIFY_VK_RESULT(cmd) \ + { \ + const VkResult result = cmd; \ + TF_VERIFY( \ + result == VK_SUCCESS, \ + "%s: %s", \ + #cmd, \ + HgiVulkanResultString(result)); \ + } while(0) + PXR_NAMESPACE_CLOSE_SCOPE -#endif +#endif \ No newline at end of file diff --git a/pxr/imaging/hgiVulkan/graphicsCmds.cpp b/pxr/imaging/hgiVulkan/graphicsCmds.cpp index 6e76681e5e8..d6669206d1f 100644 --- a/pxr/imaging/hgiVulkan/graphicsCmds.cpp +++ b/pxr/imaging/hgiVulkan/graphicsCmds.cpp @@ -19,6 +19,16 @@ PXR_NAMESPACE_OPEN_SCOPE +static +bool +_IsInt32Format(HgiFormat format) +{ + return (format == HgiFormatInt32) || + (format == HgiFormatInt32Vec2) || + (format == HgiFormatInt32Vec3) || + (format == HgiFormatInt32Vec4); +} + HgiVulkanGraphicsCmds::HgiVulkanGraphicsCmds( HgiVulkan* hgi, HgiGraphicsCmdsDesc const& desc) @@ -38,10 +48,19 @@ HgiVulkanGraphicsCmds::HgiVulkanGraphicsCmds( for (HgiAttachmentDesc const& attachmentDesc : _descriptor.colorAttachmentDescs) { VkClearValue vkClearValue; - vkClearValue.color.float32[0] = attachmentDesc.clearValue[0]; - vkClearValue.color.float32[1] = attachmentDesc.clearValue[1]; - vkClearValue.color.float32[2] = attachmentDesc.clearValue[2]; - vkClearValue.color.float32[3] = attachmentDesc.clearValue[3]; + + // Special handling for int format used by id renders. + if (_IsInt32Format(attachmentDesc.format)) { + vkClearValue.color.int32[0] = attachmentDesc.clearValue[0]; + vkClearValue.color.int32[1] = attachmentDesc.clearValue[1]; + vkClearValue.color.int32[2] = attachmentDesc.clearValue[2]; + vkClearValue.color.int32[3] = attachmentDesc.clearValue[3]; + } else { + vkClearValue.color.float32[0] = attachmentDesc.clearValue[0]; + vkClearValue.color.float32[1] = attachmentDesc.clearValue[1]; + vkClearValue.color.float32[2] = attachmentDesc.clearValue[2]; + vkClearValue.color.float32[3] = attachmentDesc.clearValue[3]; + } _vkClearValues.push_back(vkClearValue); } diff --git a/pxr/imaging/hgiVulkan/graphicsPipeline.cpp b/pxr/imaging/hgiVulkan/graphicsPipeline.cpp index 053d8d4e7d6..0b65a3fd2f7 100755 --- a/pxr/imaging/hgiVulkan/graphicsPipeline.cpp +++ b/pxr/imaging/hgiVulkan/graphicsPipeline.cpp @@ -330,12 +330,12 @@ HgiVulkanGraphicsPipeline::HgiVulkanGraphicsPipeline( pipeLayCreateInfo.setLayoutCount= (uint32_t) _vkDescriptorSetLayouts.size(); pipeLayCreateInfo.pSetLayouts = _vkDescriptorSetLayouts.data(); - TF_VERIFY( + HGIVULKAN_VERIFY_VK_RESULT( vkCreatePipelineLayout( _device->GetVulkanDevice(), &pipeLayCreateInfo, HgiVulkanAllocator(), - &_vkPipelineLayout) == VK_SUCCESS + &_vkPipelineLayout) ); // Debug label @@ -362,14 +362,14 @@ HgiVulkanGraphicsPipeline::HgiVulkanGraphicsPipeline( // HgiVulkanPipelineCache* pCache = device->GetPipelineCache(); - TF_VERIFY( + HGIVULKAN_VERIFY_VK_RESULT( vkCreateGraphicsPipelines( _device->GetVulkanDevice(), pCache->GetVulkanPipelineCache(), 1, &pipeCreateInfo, HgiVulkanAllocator(), - &_vkPipeline) == VK_SUCCESS + &_vkPipeline) ); // Debug label @@ -503,12 +503,12 @@ HgiVulkanGraphicsPipeline::AcquireVulkanFramebuffer( fbCreateInfo.height = framebuffer.dimensions[1]; fbCreateInfo.layers = 1; - TF_VERIFY( + HGIVULKAN_VERIFY_VK_RESULT( vkCreateFramebuffer( _device->GetVulkanDevice(), &fbCreateInfo, HgiVulkanAllocator(), - &framebuffer.vkFramebuffer) == VK_SUCCESS + &framebuffer.vkFramebuffer) ); // Debug label @@ -702,7 +702,7 @@ HgiVulkanGraphicsPipeline::_CreateRenderPass() if (hasDepth && _descriptor.resolveAttachments) { depthResolve.pDepthStencilResolveAttachment = &vkDepthResolveReference; depthResolve.depthResolveMode = VK_RESOLVE_MODE_SAMPLE_ZERO_BIT; - depthResolve.stencilResolveMode = VK_RESOLVE_MODE_NONE; + depthResolve.stencilResolveMode = VK_RESOLVE_MODE_SAMPLE_ZERO_BIT; subpassDesc.pNext = &depthResolve; } @@ -766,12 +766,12 @@ HgiVulkanGraphicsPipeline::_CreateRenderPass() vkCreateRenderPass2KHR = (PFN_vkCreateRenderPass2KHR) vkGetDeviceProcAddr( _device->GetVulkanDevice(), "vkCreateRenderPass2KHR"); - TF_VERIFY( + HGIVULKAN_VERIFY_VK_RESULT( vkCreateRenderPass2KHR( _device->GetVulkanDevice(), &renderPassInfo, HgiVulkanAllocator(), - &_vkRenderPass) == VK_SUCCESS + &_vkRenderPass) ); // Debug label @@ -785,4 +785,4 @@ HgiVulkanGraphicsPipeline::_CreateRenderPass() } } -PXR_NAMESPACE_CLOSE_SCOPE +PXR_NAMESPACE_CLOSE_SCOPE \ No newline at end of file diff --git a/pxr/imaging/hgiVulkan/instance.cpp b/pxr/imaging/hgiVulkan/instance.cpp index e48b78609df..e50f00b616d 100755 --- a/pxr/imaging/hgiVulkan/instance.cpp +++ b/pxr/imaging/hgiVulkan/instance.cpp @@ -19,20 +19,20 @@ PXR_NAMESPACE_OPEN_SCOPE static bool _CheckInstanceValidationLayerSupport(const char * layerName) -{ - uint32_t layerCount; - vkEnumerateInstanceLayerProperties(&layerCount, nullptr); +{ + uint32_t layerCount; + vkEnumerateInstanceLayerProperties(&layerCount, nullptr); std::vector availableLayers(layerCount); - + vkEnumerateInstanceLayerProperties(&layerCount, availableLayers.data()); - for (const auto& layerProperties : availableLayers) { - if (strcmp(layerName, layerProperties.layerName) == 0) { + for (const auto& layerProperties : availableLayers) { + if (strcmp(layerName, layerProperties.layerName) == 0) { return true; - } - } + } + } - return false; + return false; } static @@ -137,11 +137,11 @@ HgiVulkanInstance::HgiVulkanInstance() } #endif - TF_VERIFY( + HGIVULKAN_VERIFY_VK_RESULT( vkCreateInstance( &createInfo, HgiVulkanAllocator(), - &_vkInstance) == VK_SUCCESS + &_vkInstance) ); volkLoadInstance(_vkInstance); diff --git a/pxr/imaging/hgiVulkan/resourceBindings.cpp b/pxr/imaging/hgiVulkan/resourceBindings.cpp index 24e1cdd194d..812da43265b 100644 --- a/pxr/imaging/hgiVulkan/resourceBindings.cpp +++ b/pxr/imaging/hgiVulkan/resourceBindings.cpp @@ -35,12 +35,12 @@ _CreateDescriptorSetLayout( setCreateInfo.pNext = nullptr; VkDescriptorSetLayout layout = nullptr; - TF_VERIFY( + HGIVULKAN_VERIFY_VK_RESULT( vkCreateDescriptorSetLayout( device->GetVulkanDevice(), &setCreateInfo, HgiVulkanAllocator(), - &layout) == VK_SUCCESS + &layout) ); // Debug label @@ -170,12 +170,12 @@ HgiVulkanResourceBindings::HgiVulkanResourceBindings( pool_info.poolSizeCount = (uint32_t) poolSizes.size(); pool_info.pPoolSizes = poolSizes.data(); - TF_VERIFY( + HGIVULKAN_VERIFY_VK_RESULT( vkCreateDescriptorPool( _device->GetVulkanDevice(), &pool_info, HgiVulkanAllocator(), - &_vkDescriptorPool) == VK_SUCCESS + &_vkDescriptorPool) ); // Debug label @@ -198,11 +198,11 @@ HgiVulkanResourceBindings::HgiVulkanResourceBindings( allocateInfo.descriptorSetCount = _descriptorSetCnt; allocateInfo.pSetLayouts = &_vkDescriptorSetLayout; - TF_VERIFY( + HGIVULKAN_VERIFY_VK_RESULT( vkAllocateDescriptorSets( _device->GetVulkanDevice(), &allocateInfo, - &_vkDescriptorSet) == VK_SUCCESS + &_vkDescriptorSet) ); // Debug label @@ -406,4 +406,4 @@ HgiVulkanResourceBindings::GetInflightBits() return _inflightBits; } -PXR_NAMESPACE_CLOSE_SCOPE +PXR_NAMESPACE_CLOSE_SCOPE \ No newline at end of file diff --git a/pxr/imaging/hgiVulkan/sampler.cpp b/pxr/imaging/hgiVulkan/sampler.cpp index 3f99b1f0e4a..a5d1117e914 100644 --- a/pxr/imaging/hgiVulkan/sampler.cpp +++ b/pxr/imaging/hgiVulkan/sampler.cpp @@ -10,6 +10,7 @@ #include "pxr/imaging/hgiVulkan/conversions.h" #include "pxr/imaging/hgiVulkan/device.h" #include "pxr/imaging/hgiVulkan/sampler.h" +#include "pxr/imaging/hgiVulkan/diagnostic.h" #include @@ -58,12 +59,12 @@ HgiVulkanSampler::HgiVulkanSampler( static_cast(TfGetEnvSetting(HGI_MAX_ANISOTROPY))}) : 1.0f; } - TF_VERIFY( + HGIVULKAN_VERIFY_VK_RESULT( vkCreateSampler( device->GetVulkanDevice(), &sampler, HgiVulkanAllocator(), - &_vkSampler) == VK_SUCCESS + &_vkSampler) ); } @@ -99,4 +100,4 @@ HgiVulkanSampler::GetInflightBits() return _inflightBits; } -PXR_NAMESPACE_CLOSE_SCOPE +PXR_NAMESPACE_CLOSE_SCOPE \ No newline at end of file diff --git a/pxr/imaging/hgiVulkan/shaderCompiler.cpp b/pxr/imaging/hgiVulkan/shaderCompiler.cpp index 7f285e7a6ce..333c2bf1258 100644 --- a/pxr/imaging/hgiVulkan/shaderCompiler.cpp +++ b/pxr/imaging/hgiVulkan/shaderCompiler.cpp @@ -102,12 +102,12 @@ _CreateDescriptorSetLayout( std::string const& debugName) { VkDescriptorSetLayout layout = nullptr; - TF_VERIFY( + HGIVULKAN_VERIFY_VK_RESULT( vkCreateDescriptorSetLayout( device->GetVulkanDevice(), &createInfo, HgiVulkanAllocator(), - &layout) == VK_SUCCESS + &layout) ); // Debug label @@ -278,4 +278,4 @@ HgiVulkanMakeDescriptorSetLayouts( return layouts; } -PXR_NAMESPACE_CLOSE_SCOPE +PXR_NAMESPACE_CLOSE_SCOPE \ No newline at end of file diff --git a/pxr/imaging/hgiVulkan/shaderFunction.cpp b/pxr/imaging/hgiVulkan/shaderFunction.cpp index 9c2bffd8c7c..ec7eb7af93e 100644 --- a/pxr/imaging/hgiVulkan/shaderFunction.cpp +++ b/pxr/imaging/hgiVulkan/shaderFunction.cpp @@ -57,12 +57,12 @@ HgiVulkanShaderFunction::HgiVulkanShaderFunction( shaderCreateInfo.codeSize = _spirvByteSize; shaderCreateInfo.pCode = (uint32_t*) spirv.data(); - TF_VERIFY( + HGIVULKAN_VERIFY_VK_RESULT( vkCreateShaderModule( device->GetVulkanDevice(), &shaderCreateInfo, HgiVulkanAllocator(), - &_vkShaderModule) == VK_SUCCESS + &_vkShaderModule) ); // Debug label @@ -164,4 +164,4 @@ HgiVulkanShaderFunction::GetInflightBits() return _inflightBits; } -PXR_NAMESPACE_CLOSE_SCOPE +PXR_NAMESPACE_CLOSE_SCOPE \ No newline at end of file diff --git a/pxr/imaging/hgiVulkan/texture.cpp b/pxr/imaging/hgiVulkan/texture.cpp index 6a9cff01860..0b25e6618ff 100644 --- a/pxr/imaging/hgiVulkan/texture.cpp +++ b/pxr/imaging/hgiVulkan/texture.cpp @@ -107,14 +107,14 @@ HgiVulkanTexture::HgiVulkanTexture( // Equivalent to: vkCreateImage, vkAllocateMemory, vkBindImageMemory VmaAllocationCreateInfo allocInfo = {}; allocInfo.usage = VMA_MEMORY_USAGE_GPU_ONLY; - TF_VERIFY( + HGIVULKAN_VERIFY_VK_RESULT( vmaCreateImage( device->GetVulkanMemoryAllocator(), &imageCreateInfo, &allocInfo, &_vkImage, &_vmaImageAllocation, - nullptr) == VK_SUCCESS + nullptr) ); TF_VERIFY(_vkImage, "Failed to create image"); @@ -164,12 +164,12 @@ HgiVulkanTexture::HgiVulkanTexture( view.subresourceRange.levelCount = desc.mipLevels; view.image = _vkImage; - TF_VERIFY( + HGIVULKAN_VERIFY_VK_RESULT( vkCreateImageView( device->GetVulkanDevice(), &view, HgiVulkanAllocator(), - &_vkImageView) == VK_SUCCESS + &_vkImageView) ); // Debug label @@ -286,12 +286,12 @@ HgiVulkanTexture::HgiVulkanTexture( view.subresourceRange.levelCount = desc.mipLevels; view.image = srcTexture->GetImage(); - TF_VERIFY( + HGIVULKAN_VERIFY_VK_RESULT( vkCreateImageView( device->GetVulkanDevice(), &view, HgiVulkanAllocator(), - &_vkImageView) == VK_SUCCESS + &_vkImageView) ); // Debug label @@ -358,11 +358,11 @@ HgiVulkanTexture::GetCPUStagingAddress() } if (!_cpuStagingAddress) { - TF_VERIFY( + HGIVULKAN_VERIFY_VK_RESULT( vmaMapMemory( _device->GetVulkanMemoryAllocator(), _stagingBuffer->GetVulkanMemoryAllocation(), - &_cpuStagingAddress) == VK_SUCCESS + &_cpuStagingAddress) ); } @@ -651,4 +651,4 @@ HgiVulkanTexture::GetDefaultAccessFlags(HgiTextureUsage usage) return VK_ACCESS_SHADER_READ_BIT; } -PXR_NAMESPACE_CLOSE_SCOPE +PXR_NAMESPACE_CLOSE_SCOPE \ No newline at end of file diff --git a/pxr/imaging/hio/OpenEXR/openexr-c.c b/pxr/imaging/hio/OpenEXR/openexr-c.c index 5c39b5adb40..6cc2b79610d 100644 --- a/pxr/imaging/hio/OpenEXR/openexr-c.c +++ b/pxr/imaging/hio/OpenEXR/openexr-c.c @@ -657,7 +657,8 @@ static exr_result_t _nanoexr_rgba_decoding_initialize( for (int c = 0; c < decoder->channel_count; ++c) { int channelIndex = -1; decoder->channels[c].decode_to_ptr = NULL; - if (strIsComponent(layerName, decoder->channels[c].channel_name, "red")) { + if (strIsComponent(layerName, decoder->channels[c].channel_name, "red") + || (rgba[0] == -1 && strIsComponent(layerName, decoder->channels[c].channel_name, "y"))) { rgba[0] = c; channelIndex = 0; } diff --git a/pxr/imaging/hio/pch.h b/pxr/imaging/hio/pch.h index 14c08f5b552..da47e2a1538 100644 --- a/pxr/imaging/hio/pch.h +++ b/pxr/imaging/hio/pch.h @@ -84,6 +84,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #if defined(__APPLE__) // Fix breakage caused by Python's pyport.h. diff --git a/pxr/imaging/hioOpenVDB/pch.h b/pxr/imaging/hioOpenVDB/pch.h index 8dd40265066..b4fcc8e16a4 100644 --- a/pxr/imaging/hioOpenVDB/pch.h +++ b/pxr/imaging/hioOpenVDB/pch.h @@ -68,6 +68,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #if defined(__APPLE__) // Fix breakage caused by Python's pyport.h. diff --git a/pxr/imaging/plugin/hdEmbree/pch.h b/pxr/imaging/plugin/hdEmbree/pch.h index c64644c5454..0369fea3a14 100644 --- a/pxr/imaging/plugin/hdEmbree/pch.h +++ b/pxr/imaging/plugin/hdEmbree/pch.h @@ -76,6 +76,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #if defined(__APPLE__) // Fix breakage caused by Python's pyport.h. diff --git a/pxr/imaging/plugin/hdStorm/pch.h b/pxr/imaging/plugin/hdStorm/pch.h index ecb4ddd72ee..fe3470d7dc1 100644 --- a/pxr/imaging/plugin/hdStorm/pch.h +++ b/pxr/imaging/plugin/hdStorm/pch.h @@ -68,6 +68,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #if defined(__APPLE__) // Fix breakage caused by Python's pyport.h. diff --git a/pxr/imaging/plugin/hioAvif/pch.h b/pxr/imaging/plugin/hioAvif/pch.h index e58f2fab516..d0f85b38ebb 100644 --- a/pxr/imaging/plugin/hioAvif/pch.h +++ b/pxr/imaging/plugin/hioAvif/pch.h @@ -49,6 +49,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/pxr/imaging/plugin/hioOiio/pch.h b/pxr/imaging/plugin/hioOiio/pch.h index df1a527a704..22a057d7e7c 100644 --- a/pxr/imaging/plugin/hioOiio/pch.h +++ b/pxr/imaging/plugin/hioOiio/pch.h @@ -54,6 +54,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #if defined(__APPLE__) // Fix breakage caused by Python's pyport.h. diff --git a/pxr/imaging/pxOsd/pch.h b/pxr/imaging/pxOsd/pch.h index 2a2dc83f663..de88f453d5e 100644 --- a/pxr/imaging/pxOsd/pch.h +++ b/pxr/imaging/pxOsd/pch.h @@ -65,6 +65,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/pxr/usd/ar/CMakeLists.txt b/pxr/usd/ar/CMakeLists.txt index fb3a49f6652..cac51d94f67 100644 --- a/pxr/usd/ar/CMakeLists.txt +++ b/pxr/usd/ar/CMakeLists.txt @@ -55,6 +55,7 @@ pxr_library(ar PYMODULE_CPPFILES module.cpp + wrapAsset.cpp wrapAssetInfo.cpp wrapDefaultResolverContext.cpp wrapDefaultResolver.cpp @@ -81,6 +82,7 @@ pxr_test_scripts( testenv/testArAssetInfo.py testenv/testArAdvancedAPI.py testenv/testArDefaultResolver.py + testenv/testArOpenAsset.py testenv/testArPackageUtils.py testenv/testArResolvedPath.py testenv/testArResolverContext.py @@ -273,6 +275,11 @@ pxr_register_test(testArDefaultResolver_CPP COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testArDefaultResolver_CPP" ) +pxr_register_test(testArOpenAsset + PYTHON + COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testArOpenAsset" +) + pxr_register_test(testArPackageUtils PYTHON COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testArPackageUtils" diff --git a/pxr/usd/ar/module.cpp b/pxr/usd/ar/module.cpp index 86ba4c27a77..e1e4216e845 100644 --- a/pxr/usd/ar/module.cpp +++ b/pxr/usd/ar/module.cpp @@ -12,6 +12,7 @@ PXR_NAMESPACE_USING_DIRECTIVE TF_WRAP_MODULE { + TF_WRAP(Asset); TF_WRAP(AssetInfo); TF_WRAP(ResolvedPath); TF_WRAP(Timestamp); diff --git a/pxr/usd/ar/pch.h b/pxr/usd/ar/pch.h index 8e41c1fc786..0e35cab3bea 100644 --- a/pxr/usd/ar/pch.h +++ b/pxr/usd/ar/pch.h @@ -81,6 +81,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/pxr/usd/ar/testenv/testArOpenAsset.py b/pxr/usd/ar/testenv/testArOpenAsset.py new file mode 100644 index 00000000000..9c6ddf8ea04 --- /dev/null +++ b/pxr/usd/ar/testenv/testArOpenAsset.py @@ -0,0 +1,245 @@ +#!/pxrpythonsubst +# +# Copyright 2024 Pixar +# +# Licensed under the terms set forth in the LICENSE.txt file available at +# https://openusd.org/license. +# +import json +import os +import tempfile +import unittest + +from pxr import Ar + +class TestArOpenAsset(unittest.TestCase): + + def setUp(self): + # Create a temporary directory containing a JSON test file, along with + # a binary file: + self._tempDir = tempfile.TemporaryDirectory() + self._jsonFilePath = os.path.join(self._tempDir.name, 'text.json') + self._binaryFilePath = os.path.join(self._tempDir.name, 'binary.bin') + self._emptyFilePath = os.path.join(self._tempDir.name, 'empty.txt') + + # Write some sample JSON data to the test file. + # + # NOTE: The included UTF-8 string is represented by the following byte + # sequence: + # * 'H', 'e', 'l', 'l', 'o', ',', and '!' are all 1-byte characters + # (ASCII). + # * '世' and '界' are 3-byte characters (East Asian characters). + # * '🌍' is a 4-byte character (emoji representing "Earth Globe + # Europe-Africa"). + # + # The overall byte sequence for this UTF-8 string is: + # * "Hello, \\u4e16\\u754c! \\ud83c\\udf0d" + self._jsonData = { + 'name': 'example', + 'value': 1234, + 'utf-8': 'Hello, 世界! 🌍', + 'child-object': { + 'key': 'value', + }, + } + with open(self._jsonFilePath, 'w') as jsonFile: + json.dump(self._jsonData, jsonFile) + + # Write a file with no content: + open(self._emptyFilePath, 'w').close() + + # Write some sample binary data to the test file, including characters + # that would result in UTF-8 decoding errors such as: + # > UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc3 in + # > position 0: invalid continuation byte + # + # Equivalent string of the following byte representation: 'ÃÇéあ', + # where: + # * 'Ã' represents an 'A' with tilde in UTF-8, but can represent a + # different character in Latin-1. + # * 'Ç' represents a 'C' with cedilla in Latin-1, although would be + # different in UTF-8. + # * 'é' represents the byte 0xE9 in ISO-8859-1 (Latin-1), although + # in UTF-8, 0xE9 is not a valid single byte but part of a + # multi-byte sequence. + # * 'あ' is represented by the byte 0x82A0 in Shift JIS. + self._binaryData = b'\xc3\xc7\xe9\x82A0' + with open(self._binaryFilePath, 'wb') as binaryFile: + binaryFile.write(self._binaryData) + + def tearDown(self): + # Cleanup the temporary directory: + self._tempDir.cleanup() + + def _getResolvedTextFilepath(self): + """ + Return the resolved path of the Attribute referencing the JSON file, + located in the in-memory test Stage. + """ + return Ar.ResolvedPath(self._jsonFilePath) + + def _getResolvedEmptyFilepath(self): + """ + Return the resolved path of the Attribute referencing an empty file. + """ + return Ar.ResolvedPath(self._emptyFilePath) + + def _getNonExistingTextFilepath(self): + """Return the resolved path of an non-existing asset.""" + non_existing_json_file = os.path.join(self._tempDir.name, + 'non-existing-asset.json') + return Ar.ResolvedPath(non_existing_json_file) + + def _getResolvedBinaryFilepath(self): + """ + Return the resolved path of the Attribute referencing the JSON file, + located in the in-memory test Stage. + """ + return Ar.ResolvedPath(self._binaryFilePath) + + def test_readingNonExistingAssetResultsInInvalidAsset(self): + """ + Validate that attempting to read a non-existing asset returns None + """ + print("test_readingNonExistingAssetResultsInInvalidAsset") + nonExistingJsonFile = self._getNonExistingTextFilepath() + self.assertIsNone( + Ar.GetResolver().OpenAsset(resolvedPath=nonExistingJsonFile)) + + def test_arAssetHasExpectedContentSize(self): + """ + Validate that the referenced `pxr.Ar.Asset` has a size comparable + with the the content of the sample JSON data serialized to the + temporary directory. + """ + jsonFile = self._getResolvedTextFilepath() + expectedJsonContentSize = os.path.getsize(str(jsonFile)) + with Ar.GetResolver().OpenAsset(resolvedPath=jsonFile) as jsonAsset: + self.assertEqual(jsonAsset.GetSize(), expectedJsonContentSize) + + def test_arAssetBufferRead(self): + """ + Validate that the referenced `pxr.Ar.Asset` content matches the + actual JSON file in the temporary test directory, by reading it into a + valid buffer. + """ + jsonFile = self._getResolvedTextFilepath() + with Ar.GetResolver().OpenAsset(resolvedPath=jsonFile) as jsonAsset: + assetSize = jsonAsset.GetSize() + + buffer = jsonAsset.Read(assetSize, 0) + + self.assertEqual(buffer.decode(), json.dumps(self._jsonData)) + self.assertEqual(len(buffer), assetSize) + + def test_ArAssetPreventReadingBeyondSourceAsset(self): + """ + Validate that if a large amount of data is requested, the resulting + buffer will only return the amount of data actually available in the + asset. + """ + + jsonFile = self._getResolvedTextFilepath() + jsonContentSize = os.path.getsize(str(jsonFile)) + offset = 10 + + with Ar.GetResolver().OpenAsset(resolvedPath=jsonFile) as jsonAsset: + buffer = jsonAsset.Read(999999, offset) + self.assertEqual(len(buffer), jsonContentSize - offset) + + def test_ArAssetInvalidReadOffsetThrowsError(self): + """ + Validate that reading with an invalid offset will throw an error. + """ + + jsonFile = self._getResolvedTextFilepath() + with Ar.GetResolver().OpenAsset(resolvedPath=jsonFile) as jsonAsset: + with self.assertRaisesRegex(ValueError, 'Invalid read offset'): + jsonAsset.Read(10, 100000) + + + def test_arAssetReadWithSpecifiedLength(self): + """ + Validate that the referenced `pxr.Ar.Asset` content matches the + actual JSON file in the temporary test directory, by reading it into a + valid buffer and reading it up to a given length. + """ + jsonFile = self._getResolvedTextFilepath() + with Ar.GetResolver().OpenAsset(resolvedPath=jsonFile) as jsonAsset: + assetSize = jsonAsset.GetSize() + + # Read the first half of the file content: + bufferSize = assetSize // 2 + buffer = jsonAsset.Read(bufferSize, 0) + + self.assertEqual(buffer.decode(), + json.dumps(self._jsonData)[:bufferSize]) + self.assertEqual(len(buffer), bufferSize) + + # Read the second half of the file content: + bufferSize = assetSize - bufferSize + buffer = jsonAsset.Read(bufferSize, assetSize // 2) + + self.assertEqual(buffer.decode(), + json.dumps(self._jsonData)[bufferSize:]) + self.assertEqual(len(buffer), bufferSize) + + def test_readingAssetWithNoContentReturnsValidContext(self): + """ + Validate that attempting to read a file with no content returns a valid + operation. + """ + emptyFile = self._getResolvedEmptyFilepath() + with Ar.GetResolver().OpenAsset(resolvedPath=emptyFile) as emptyAsset: + self.assertTrue(emptyAsset, 'Expected asset to be valid') + + def test_arAssetBufferCanBeAccessedForTextContent(self): + """ + Validate that the referenced asset content matches the actual JSON + file in the temporary test directory. + """ + jsonFile = self._getResolvedTextFilepath() + with Ar.GetResolver().OpenAsset(resolvedPath=jsonFile) as jsonAsset: + self.assertTrue(jsonAsset, 'Expected asset to be valid') + jsonContent = jsonAsset.GetBuffer() + + self.assertEqual(jsonContent.decode(), json.dumps(self._jsonData)) + self.assertIn(b'Hello, \\u4e16\\u754c! \\ud83c\\udf0d', jsonContent) + + def test_arAssetBufferCanBeAccessedForBinaryContent(self): + """ + Validate that the referenced asset content matches the actual binary + file in the temporary test directory. + """ + binaryFile = self._getResolvedBinaryFilepath() + with Ar.GetResolver().OpenAsset(resolvedPath=binaryFile) as binaryAsset: + self.assertTrue(binaryAsset, 'Expected asset to be valid') + binaryContent = binaryAsset.GetBuffer() + + self.assertEqual(binaryContent, self._binaryData) + + def test_arAssetContextManagerReleasesResourceUponExiting(self): + """ + Validate that asset resources are freed upon exiting their initial + context manager scope. + """ + jsonFile = self._getResolvedTextFilepath() + asset = Ar.GetResolver().OpenAsset(resolvedPath=jsonFile) + + # Ensure the asset is deemed valid when consuming its resources within + # an initial scoped context: + with asset: + self.assertTrue( + asset, + 'Expected asset to be valid before release of context manager') + + # Ensure the asset is deemed invalid after exiting its initial scoped + # context: + with self.assertRaisesRegex(RuntimeError, + 'Unable to access invalid asset'): + with asset: + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/pxr/usd/ar/wrapAsset.cpp b/pxr/usd/ar/wrapAsset.cpp new file mode 100644 index 00000000000..f5df8c1e516 --- /dev/null +++ b/pxr/usd/ar/wrapAsset.cpp @@ -0,0 +1,171 @@ +// +// Copyright 2024 Pixar +// +// Licensed under the terms set forth in the LICENSE.txt file available at +// https://openusd.org/license. +// + +#include "pxr/pxr.h" +#include "pxr/base/tf/pyUtils.h" +#include "pxr/usd/ar/asset.h" + +#include "pxr/external/boost/python/class.hpp" +#include "pxr/external/boost/python/def.hpp" +#include "pxr/external/boost/python/object.hpp" +#include "pxr/external/boost/python/operators.hpp" +#include "pxr/external/boost/python/return_arg.hpp" +#include "pxr/external/boost/python/to_python_converter.hpp" +#include "pxr/external/boost/python/converter/from_python.hpp" + +PXR_NAMESPACE_USING_DIRECTIVE + +using namespace pxr_boost::python; + +// Data structure for exposing ArAsset objects exposed via ArResolver APIs to +// Python. +class Ar_PyAsset +{ +public: + // Create a Python representation of the given \c ArAsset resource. + // \param asset \c ArAsset for which to create a Python representation. + Ar_PyAsset(std::shared_ptr asset) + : _asset(asset) + {} + + // Return a buffer with the contents of the asset, or None if the data could + // not be read. + object GetBuffer() const + { + if (!_asset) { + TfPyThrowRuntimeError("Unable to access invalid asset"); + } + + std::shared_ptr buffer; + size_t bufferSize = 0; + { + TF_PY_ALLOW_THREADS_IN_SCOPE(); + buffer = _asset->GetBuffer(); + bufferSize = _asset->GetSize(); + } + + if (!buffer) { + return {}; + } + + // Create a Python bytes object from the buffer: + return object(handle<>( + PyBytes_FromStringAndSize(buffer.get(), bufferSize))); + } + + // Reads the specifed amount of data from the underlying ArAsset at the + // given offset + object Read(size_t count, size_t offset) + { + size_t assetSize = GetSize(); + if (offset >= assetSize) { + TfPyThrowValueError("Invalid read offset"); + } + + // Prevent allocating a buffer larger than the amount of data that + // we can read from the asset + count = std::min(count, assetSize - offset); + + PyObject *pyBytes = PyBytes_FromStringAndSize(NULL, count); + char *buffer = PyBytes_AsString(pyBytes); + size_t bytesRead = 0; + + { + TF_PY_ALLOW_THREADS_IN_SCOPE(); + bytesRead = _asset->Read(buffer, count, offset); + } + + if (bytesRead != count) { + // If we did not read all the bytes we are after, truncate the allocated + // buffer to avoid returning extra data. + if (_PyBytes_Resize(&pyBytes, bytesRead) == -1) { + TfPyThrowRuntimeError("Failed to read Asset data"); + } + } + + return object(handle<>(pyBytes)); + } + + // Returns the size of the underlying ArAsset + size_t GetSize() const { + if (!_asset) { + TfPyThrowRuntimeError("Unable to access invalid asset"); + } + + TF_PY_ALLOW_THREADS_IN_SCOPE(); + return _asset->GetSize(); + } + + // Checks validity of this object. + bool __bool__() const + { + return _asset != nullptr; + } + + // Enter the Python Context Manager for the representation of the ArAsset. + void __enter__() const + { + if (!_asset) { + TfPyThrowRuntimeError("Unable to access invalid asset"); + } + } + + // Exit the Python Context Manager for the representation of the ArAsset. + void __exit__(const object&, const object&, const object&) + { + _asset.reset(); + } + + static void RegisterConversions() { + // to-python + to_python_converter, Ar_PyAsset>(); + //from-python + converter::registry::push_back(&_convertible, &_construct, + pxr_boost::python::type_id>()); + } + + // to-python conversion of std::shared_ptr. + static PyObject *convert(const std::shared_ptr &asset) { + return incref(object(Ar_PyAsset{asset}).ptr()); + } + +private: + static void* _convertible(PyObject *obj_ptr) { + extract extractor(obj_ptr); + return extractor.check() ? obj_ptr : nullptr; + } + + static void _construct(PyObject *obj_ptr, + converter::rvalue_from_python_stage1_data *data) + { + void *storage = ((converter::rvalue_from_python_storage< + std::shared_ptr>*)data)->storage.bytes; + Ar_PyAsset pyAsset = extract(obj_ptr); + new (storage) std::shared_ptr(std::move(pyAsset._asset)); + data->convertible = storage; + } + + std::shared_ptr _asset; +}; + +void wrapAsset() +{ + typedef Ar_PyAsset This; + + class_ + ("Ar_PyAsset", no_init) + .def("GetBuffer", &This::GetBuffer) + .def("GetSize", &This::GetSize) + .def("Read", &This::Read, (arg("count"), arg("offset"))) + + .def("__bool__", &This::__bool__) + .def("__enter__", &This::__enter__, return_self<>()) + .def("__exit__", &This::__exit__) + ; + + Ar_PyAsset::RegisterConversions(); +} \ No newline at end of file diff --git a/pxr/usd/ar/wrapResolver.cpp b/pxr/usd/ar/wrapResolver.cpp index 0b5d4a742ae..d8aa1487a10 100644 --- a/pxr/usd/ar/wrapResolver.cpp +++ b/pxr/usd/ar/wrapResolver.cpp @@ -94,6 +94,8 @@ wrapResolver() (args("assetPath"), args("resolvedPath"))) .def("GetModificationTimestamp", &This::GetModificationTimestamp, (args("assetPath"), args("resolvedPath"))) + .def("OpenAsset", &This::OpenAsset, + (args("resolvedPath"))) .def("GetExtension", &This::GetExtension, args("assetPath")) diff --git a/pxr/usd/kind/pch.h b/pxr/usd/kind/pch.h index c50e72fb3a4..38b7a8ff721 100644 --- a/pxr/usd/kind/pch.h +++ b/pxr/usd/kind/pch.h @@ -48,6 +48,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/pxr/usd/ndr/pch.h b/pxr/usd/ndr/pch.h index f536d7f398c..a20e8053ddb 100644 --- a/pxr/usd/ndr/pch.h +++ b/pxr/usd/ndr/pch.h @@ -83,6 +83,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/pxr/usd/pcp/CMakeLists.txt b/pxr/usd/pcp/CMakeLists.txt index 0fa527db037..5232becd8e5 100644 --- a/pxr/usd/pcp/CMakeLists.txt +++ b/pxr/usd/pcp/CMakeLists.txt @@ -1399,8 +1399,6 @@ pxr_register_test(testPcpMuseum_TimeCodesPerSecond1 COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testPcpCompositionResults --usd TimeCodesPerSecond/root.sdf" STDOUT_REDIRECT compositionResults_TimeCodesPerSecond1.txt DIFF_COMPARE compositionResults_TimeCodesPerSecond1.txt - ENV - PCP_DISABLE_TIME_SCALING_BY_LAYER_TCPS=0 ) pxr_register_test(testPcpMuseum_TimeCodesPerSecond2 @@ -1408,8 +1406,6 @@ pxr_register_test(testPcpMuseum_TimeCodesPerSecond2 COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testPcpCompositionResults --usd TimeCodesPerSecond/root_48tcps.sdf" STDOUT_REDIRECT compositionResults_TimeCodesPerSecond2.txt DIFF_COMPARE compositionResults_TimeCodesPerSecond2.txt - ENV - PCP_DISABLE_TIME_SCALING_BY_LAYER_TCPS=0 ) pxr_register_test(testPcpMuseum_TimeCodesPerSecond3 @@ -1417,8 +1413,6 @@ pxr_register_test(testPcpMuseum_TimeCodesPerSecond3 COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testPcpCompositionResults --usd TimeCodesPerSecond/root_24tcps_12fps.sdf" STDOUT_REDIRECT compositionResults_TimeCodesPerSecond3.txt DIFF_COMPARE compositionResults_TimeCodesPerSecond3.txt - ENV - PCP_DISABLE_TIME_SCALING_BY_LAYER_TCPS=0 ) pxr_register_test(testPcpMuseum_TimeCodesPerSecond4 @@ -1426,44 +1420,6 @@ pxr_register_test(testPcpMuseum_TimeCodesPerSecond4 COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testPcpCompositionResults --usd TimeCodesPerSecond/root_12fps.sdf" STDOUT_REDIRECT compositionResults_TimeCodesPerSecond4.txt DIFF_COMPARE compositionResults_TimeCodesPerSecond4.txt - ENV - PCP_DISABLE_TIME_SCALING_BY_LAYER_TCPS=0 -) - -pxr_register_test(testPcpMuseum_TimeCodesPerSecond_Legacy1 - PYTHON - COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testPcpCompositionResults --usd TimeCodesPerSecond/root.sdf" - STDOUT_REDIRECT compositionResults_TimeCodesPerSecond1_Legacy.txt - DIFF_COMPARE compositionResults_TimeCodesPerSecond1_Legacy.txt - ENV - PCP_DISABLE_TIME_SCALING_BY_LAYER_TCPS=1 -) - -pxr_register_test(testPcpMuseum_TimeCodesPerSecond_Legacy2 - PYTHON - COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testPcpCompositionResults --usd TimeCodesPerSecond/root_48tcps.sdf" - STDOUT_REDIRECT compositionResults_TimeCodesPerSecond2_Legacy.txt - DIFF_COMPARE compositionResults_TimeCodesPerSecond2_Legacy.txt - ENV - PCP_DISABLE_TIME_SCALING_BY_LAYER_TCPS=1 -) - -pxr_register_test(testPcpMuseum_TimeCodesPerSecond_Legacy3 - PYTHON - COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testPcpCompositionResults --usd TimeCodesPerSecond/root_24tcps_12fps.sdf" - STDOUT_REDIRECT compositionResults_TimeCodesPerSecond3_Legacy.txt - DIFF_COMPARE compositionResults_TimeCodesPerSecond3_Legacy.txt - ENV - PCP_DISABLE_TIME_SCALING_BY_LAYER_TCPS=1 -) - -pxr_register_test(testPcpMuseum_TimeCodesPerSecond_Legacy4 - PYTHON - COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testPcpCompositionResults --usd TimeCodesPerSecond/root_12fps.sdf" - STDOUT_REDIRECT compositionResults_TimeCodesPerSecond4_Legacy.txt - DIFF_COMPARE compositionResults_TimeCodesPerSecond4_Legacy.txt - ENV - PCP_DISABLE_TIME_SCALING_BY_LAYER_TCPS=1 ) pxr_register_test(testPcpMuseum_TimeCodesPerSecondWithSessionLayer1 @@ -1471,8 +1427,6 @@ pxr_register_test(testPcpMuseum_TimeCodesPerSecondWithSessionLayer1 COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testPcpCompositionResults --usd TimeCodesPerSecond/root_24tcps_12fps.sdf --session TimeCodesPerSecond/session_48tcps.sdf" STDOUT_REDIRECT compositionResults_TimeCodesPerSecondWithSessionLayer1.txt DIFF_COMPARE compositionResults_TimeCodesPerSecondWithSessionLayer1.txt - ENV - PCP_DISABLE_TIME_SCALING_BY_LAYER_TCPS=0 ) pxr_register_test(testPcpMuseum_TimeCodesPerSecondWithSessionLayer2 @@ -1480,8 +1434,6 @@ pxr_register_test(testPcpMuseum_TimeCodesPerSecondWithSessionLayer2 COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testPcpCompositionResults --usd TimeCodesPerSecond/root_48tcps.sdf --session TimeCodesPerSecond/session_24fps.sdf" STDOUT_REDIRECT compositionResults_TimeCodesPerSecondWithSessionLayer2.txt DIFF_COMPARE compositionResults_TimeCodesPerSecondWithSessionLayer2.txt - ENV - PCP_DISABLE_TIME_SCALING_BY_LAYER_TCPS=0 ) pxr_register_test(testPcpMuseum_TimeCodesPerSecondWithSessionLayer3 @@ -1489,8 +1441,6 @@ pxr_register_test(testPcpMuseum_TimeCodesPerSecondWithSessionLayer3 COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testPcpCompositionResults --usd TimeCodesPerSecond/root_12fps.sdf --session TimeCodesPerSecond/session_24fps.sdf" STDOUT_REDIRECT compositionResults_TimeCodesPerSecondWithSessionLayer3.txt DIFF_COMPARE compositionResults_TimeCodesPerSecondWithSessionLayer3.txt - ENV - PCP_DISABLE_TIME_SCALING_BY_LAYER_TCPS=0 ) pxr_register_test(testPcpMuseum_TimeCodesPerSecondWithSessionLayer4 @@ -1498,8 +1448,6 @@ pxr_register_test(testPcpMuseum_TimeCodesPerSecondWithSessionLayer4 COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testPcpCompositionResults --usd TimeCodesPerSecond/root_12fps.sdf --session TimeCodesPerSecond/session.sdf" STDOUT_REDIRECT compositionResults_TimeCodesPerSecondWithSessionLayer4.txt DIFF_COMPARE compositionResults_TimeCodesPerSecondWithSessionLayer4.txt - ENV - PCP_DISABLE_TIME_SCALING_BY_LAYER_TCPS=0 ) pxr_register_test(testPcpMuseum_TypicalReferenceToRiggedModel @@ -2041,8 +1989,6 @@ pxr_register_test(testPcpChanges PYTHON COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testPcpChanges" EXPECTED_RETURN_CODE 0 - ENV - PCP_DISABLE_TIME_SCALING_BY_LAYER_TCPS=0 ) pxr_register_test(testPcpDependencies diff --git a/pxr/usd/pcp/cache.cpp b/pxr/usd/pcp/cache.cpp index 00b771227b8..e07a52fdcb6 100644 --- a/pxr/usd/pcp/cache.cpp +++ b/pxr/usd/pcp/cache.cpp @@ -1037,8 +1037,8 @@ PcpCache::Apply(const PcpCacheChanges& changes, PcpLifeboat* lifeboat) // we may have blown the prim index so check that it exists. if (PcpPrimIndex* primIndex = _GetPrimIndex(path)) { Pcp_RescanForSpecs(primIndex, IsUsd(), - /* updateHasSpecs */ true, - changes.layersToMute); + /* updateHasSpecs */ true, + &changes); // If there are no specs left then we can discard the // prim index. @@ -1073,6 +1073,13 @@ PcpCache::Apply(const PcpCacheChanges& changes, PcpLifeboat* lifeboat) updateSpecStacks(*i); } + TF_FOR_ALL(i, changes._didChangeSpecsAndChildrenInternal) { + auto range = _primIndexCache.FindSubtreeRange(*i); + for (auto i = range.first; i != range.second; ++i) { + updateSpecStacks(i->first); + } + } + // Fix the keys for any prim or property under any of the renamed // paths. // XXX: It'd be nice if this was a usd by just adjusting diff --git a/pxr/usd/pcp/changes.cpp b/pxr/usd/pcp/changes.cpp index face9b44bcd..99528bc1b50 100644 --- a/pxr/usd/pcp/changes.cpp +++ b/pxr/usd/pcp/changes.cpp @@ -1411,30 +1411,6 @@ void PcpChanges::DidMuteAndUnmuteLayers( const std::vector& layersToMute, const std::vector& layersToUnmute) { - PcpCacheChanges& changes = _GetCacheChanges(cache); - - // We first want to grab all layers that will be muted and unmuted and - // store them off. We may need to refer to these vectors when processing - // changes to account for a layer's future state once these changes have - // been applied - for (const auto& layerId : layersToMute) { - SdfLayerRefPtr layerToMute = - _LoadSublayerForChange(cache, layerId, _SublayerRemoved); - if (layerToMute) { - _lifeboat.Retain(layerToMute); - changes.layersToMute.emplace_back(layerToMute); - } - } - - for (const auto& layerId : layersToUnmute) { - SdfLayerRefPtr layerToUnmute = - _LoadSublayerForChange(cache, layerId, _SublayerAdded); - if (layerToUnmute) { - _lifeboat.Retain(layerToUnmute); - changes.layersToUnmute.emplace_back(layerToUnmute); - } - } - // Register changes for all computed layer stacks that are // affected by the newly muted/unmuted layers. for (const auto& layerToMute : layersToMute) { @@ -1446,25 +1422,64 @@ void PcpChanges::DidMuteAndUnmuteLayers( } } -void PcpChanges::_ProcessLayerStackAndDependencyChanges( +void +PcpChanges::_MarkReferencingSitesAsSignificantlyChanged( const PcpCache* cache, - const PcpLayerStackPtrVector& layerStacks, - bool markRefsOrPayloadSitesAsChanged) + const PcpLayerStackPtrVector& layerStacks) { TRACE_FUNCTION(); - const auto refOrPayloadChangeFunc = - [this, cache](const SdfPath &depIndexPath, - const PcpNodeRef &node) + const PcpCacheChanges& cacheChanges = _GetCacheChanges(cache); + + const auto refOrPayloadChangeFunc = + [this, cache](const SdfPath& depIndexPath, PcpArcType arcType) { - PcpArcType arcType = node.GetArcType(); - if (arcType == PcpArcTypeReference || - arcType == PcpArcTypePayload) - { + if (arcType == PcpArcTypeReference || + arcType == PcpArcTypePayload) { DidChangeSignificantly(cache, depIndexPath); } }; + for (const PcpLayerStackPtr& layerStack : layerStacks) { + PcpDependencyVector deps = cache->FindSiteDependencies( + layerStack, + SdfPath::AbsoluteRootPath(), + PcpDependencyTypeAnyIncludingVirtual, + /* recurseOnSite */ true, + /* recurseOnIndex */ false, + /* filter */ true); + + for(const PcpDependency &dep: deps) { + // If this layer stack no longer has any opinions at dep.sitePath, + // composed prims that reference this site must be recomputed to + // detect the broken reference. + if (PcpComposeSiteHasPrimSpecs( + layerStack, dep.sitePath, + cacheChanges.layersAffectedByMutingOrRemoval)) { + continue; + } + + Pcp_ForEachDependentNode( + dep.sitePath, layerStack, dep.indexPath, *cache, + [&](const SdfPath &depIndexPath, const PcpNodeRef &node) + { + refOrPayloadChangeFunc(depIndexPath, node.GetArcType()); + }, + [&](const SdfPath& depIndexPath, const PcpCulledDependency& dep) + { + refOrPayloadChangeFunc(depIndexPath, dep.arcType); + } + ); + } + } +} + +void +PcpChanges::_ProcessLayerStackAndDependencyChanges( + const PcpCache* cache, + const PcpLayerStackPtrVector& layerStacks) +{ + TRACE_FUNCTION(); for (const PcpLayerStackPtr& layerStack : layerStacks) { _DidChangeLayerStack(cache, @@ -1477,28 +1492,18 @@ void PcpChanges::_ProcessLayerStackAndDependencyChanges( layerStack, SdfPath::AbsoluteRootPath(), PcpDependencyTypeAnyIncludingVirtual, - /* recurseOnSite */ true, - /* recurseOnIndex */ true, + /* recurseOnSite */ false, + /* recurseOnIndex */ false, /* filter */ true); for(const PcpDependency &dep: deps) { - // This ensures that all sites which reference this layer are - // also marked as having changed significantly. - if (markRefsOrPayloadSitesAsChanged && - PcpComposeSiteHasPrimSpecs(layerStack, dep.sitePath)) - { - Pcp_ForEachDependentNode(dep.sitePath, layerStack, - dep.indexPath, - *cache, refOrPayloadChangeFunc); - } - // We also need to mark dependencies spec stacks as changed due to // the fact that the addition or removal of layers will result in // the need of prim stack indicies to be updated. // Note that property indexes don't have to be updated because they // hold on to spec objects directly instead of being index-based. if (dep.indexPath.IsAbsoluteRootOrPrimPath()) { - _DidChangeSpecStackInternal(cache, dep.indexPath); + _DidChangeSpecStackAndChildrenInternal(cache, dep.indexPath); } } } @@ -1513,13 +1518,25 @@ PcpChanges::_DidMuteLayer( std::string summary; std::string* debugSummary = TfDebug::IsEnabled(PCP_CHANGES) ? &summary : 0; - PcpCacheChanges& cacheChanges = _GetCacheChanges(cache); - const SdfLayerRefPtr mutedLayer = _LoadSublayerForChange(cache, layerId, _SublayerRemoved); const PcpLayerStackPtrVector& layerStacks = cache->FindAllLayerStacksUsingLayer(mutedLayer); + PcpCacheChanges& cacheChanges = _GetCacheChanges(cache); + if (mutedLayer) { + _lifeboat.Retain(mutedLayer); + cacheChanges.didMuteOrUnmuteNonEmptyLayer |= !mutedLayer->IsEmpty(); + + // Track sublayers that have been muted separately. These + // layers should no longer contribute opinions to the composed + // scene; during change processing, clients that need to + // recompute state (e.g. prim stacks) must explicitly ignore + // these layers. This is because these layers won't be removed + // from layer stacks until change processing is complete. + cacheChanges.layersAffectedByMutingOrRemoval.insert(mutedLayer); + } + PCP_APPEND_DEBUG(" Did mute layer @%s@\n", layerId.c_str()); // XXX: Computing proper changes for layers containing relocates at this @@ -1547,15 +1564,11 @@ PcpChanges::_DidMuteLayer( DidChange(cache, changes); cacheChanges.layerChangeListVec.emplace_back( std::move(changes.front())); - _lifeboat.Retain(mutedLayer); - _ProcessLayerStackAndDependencyChanges(cache, layerStacks, - /*markRefsOrPayloadSitesAsChanged*/ true); + _ProcessLayerStackAndDependencyChanges(cache, layerStacks); + _MarkReferencingSitesAsSignificantlyChanged(cache, layerStacks); } - cacheChanges.didMuteOrUnmuteNonEmptyLayer |= - mutedLayer ? !mutedLayer->IsEmpty() : false; - if (debugSummary && !debugSummary->empty()) { TfDebug::Helper().Msg("PcpChanges::_DidMuteLayer\n%s", debugSummary->c_str()); @@ -1571,13 +1584,17 @@ PcpChanges::_DidUnmuteLayer( std::string summary; std::string* debugSummary = TfDebug::IsEnabled(PCP_CHANGES) ? &summary : 0; - PcpCacheChanges& cacheChanges = _GetCacheChanges(cache); - const SdfLayerRefPtr unmutedLayer = _LoadSublayerForChange(cache, layerId, _SublayerAdded); const PcpLayerStackPtrVector& layerStacks = cache->_layerStackCache->FindAllUsingMutedLayer(layerId); + PcpCacheChanges& cacheChanges = _GetCacheChanges(cache); + if (unmutedLayer) { + _lifeboat.Retain(unmutedLayer); + cacheChanges.didMuteOrUnmuteNonEmptyLayer |= !unmutedLayer->IsEmpty(); + } + PCP_APPEND_DEBUG(" Did unmute layer @%s@\n", layerId.c_str()); // XXX: Computing proper changes for layers containing relocates at this @@ -1610,15 +1627,11 @@ PcpChanges::_DidUnmuteLayer( DidChange(cache, changes); cacheChanges.layerChangeListVec.emplace_back( std::move(changes.front())); - _lifeboat.Retain(unmutedLayer); - _ProcessLayerStackAndDependencyChanges(cache, layerStacks, - /*markRefsOrPayloadSitesAsChanged*/ true); + _ProcessLayerStackAndDependencyChanges(cache, layerStacks); + _MarkReferencingSitesAsSignificantlyChanged(cache, layerStacks); } - cacheChanges.didMuteOrUnmuteNonEmptyLayer |= - unmutedLayer ? !unmutedLayer->IsEmpty() : false; - if (debugSummary && !debugSummary->empty()) { TfDebug::Helper().Msg("PcpChanges::_DidUnmuteLayer\n%s", debugSummary->c_str()); @@ -1762,7 +1775,9 @@ static bool _NoLongerHasAnySpecs(const PcpCacheChanges& changes, const PcpPrimIndex& primIndex) { for (const PcpNodeRef &node: primIndex.GetNodeRange()) { - if (PcpComposeSiteHasPrimSpecs(node.GetLayerStack(), node.GetPath(), changes.layersToMute)) { + if (PcpComposeSiteHasPrimSpecs( + node.GetLayerStack(), node.GetPath(), + changes.layersAffectedByMutingOrRemoval)) { return false; } } @@ -2182,8 +2197,21 @@ PcpChanges::_DidAddOrRemoveSublayer( _SublayerChangeType sublayerChange) { PcpCacheChanges& cacheChanges = _GetCacheChanges(cache); - cacheChanges.didAddOrRemoveNonEmptySublayer |= - sublayer && !sublayer->IsEmpty(); + if (sublayer) { + _lifeboat.Retain(sublayer); + cacheChanges.didAddOrRemoveNonEmptySublayer |= !sublayer->IsEmpty(); + + // Track sublayers that have been removed separately. These + // layers should no longer contribute opinions to the composed + // scene; during change processing, clients that need to + // recompute state (e.g. prim stacks) must explicitly ignore + // these layers. This is because these layers won't be removed + // from layer stacks until change processing is complete. + if (sublayerChange == _SublayerRemoved) { + cacheChanges.layersAffectedByMutingOrRemoval + .insert(sublayer); + } + } if (!TfGetEnvSetting( PCP_ENABLE_MINIMAL_CHANGES_FOR_LAYER_OPERATIONS) || @@ -2218,14 +2246,12 @@ PcpChanges::_DidAddOrRemoveSublayer( empty, /*compareFieldValues*/ false))); } - _ProcessLayerStackAndDependencyChanges(cache, layerStacks, - /*markRefsOrPayloadSitesAsChanged*/ false); + _ProcessLayerStackAndDependencyChanges(cache, layerStacks); DidChange(cache, changes); cacheChanges.layerChangeListVec.emplace_back( std::move(changes.front())); - _lifeboat.Retain(sublayer); return true; }; @@ -2835,4 +2861,11 @@ PcpChanges::_DidChangeSpecStackInternal( _GetCacheChanges(cache)._didChangeSpecsInternal.insert(path); } +void +PcpChanges::_DidChangeSpecStackAndChildrenInternal( + const PcpCache* cache, const SdfPath& path) +{ + _GetCacheChanges(cache)._didChangeSpecsAndChildrenInternal.insert(path); +} + PXR_NAMESPACE_CLOSE_SCOPE diff --git a/pxr/usd/pcp/changes.h b/pxr/usd/pcp/changes.h index 777ac5b437a..ad7b5cc9f64 100644 --- a/pxr/usd/pcp/changes.h +++ b/pxr/usd/pcp/changes.h @@ -21,6 +21,7 @@ #include #include +#include PXR_NAMESPACE_OPEN_SCOPE @@ -134,8 +135,9 @@ class PcpCacheChanges { /// Will be true if a non empty sublayer was added or removed. bool didAddOrRemoveNonEmptySublayer = false; - /// Lists of layers that will be muted or unmuted during change processing. - std::vector layersToMute, layersToUnmute; + /// Set of layers that were explicitly muted or removed from a sublayer + /// list and all sublayers of those layers, recursively. + std::unordered_set layersAffectedByMutingOrRemoval; // Holds all the diff changelists that were computed when adding/removing // sublayers or muting/unmuting layers. @@ -150,6 +152,13 @@ class PcpCacheChanges { // not its contents. Because this causes no externally-observable // changes in state, clients do not need to be aware of these changes. SdfPathSet _didChangeSpecsInternal; + + // This set serves a similar purpose to _didChangeSpecsInternal above, + // however, during processing descendants of the specs in this set will also + // be marked as changed. A performance gain is accomplished by placing the + // ancestor specs in this set and marking children iteratively when applying + // changes to the cache. + SdfPathSet _didChangeSpecsAndChildrenInternal; }; /// Structure used to temporarily retain layers and layerStacks within @@ -436,17 +445,24 @@ class PcpChanges { void _DidChangeSpecStackInternal( const PcpCache* cache, const SdfPath& path); - // During change processing for added/removed or muted/unmuted layers, - // layer stacks and dependant paths need to be marked as having changed - // so that relevant data can be recalculated when the cache is applied. - // The \p markRefsOrPayloadSitesAsChanged parameter controls if, when - // traversing dependencies, if one is introduced via a reference or - // payload then that site will be marked as having changed significantly. - // This is set when processing changes for muted and unmuted layers. + void _DidChangeSpecStackAndChildrenInternal( + const PcpCache* cache, const SdfPath& path); + + // This method is used when processing layer operations. It ensures that + // affected layer stacks and their dependent spec stacks are marked as + // changed. void _ProcessLayerStackAndDependencyChanges( const PcpCache* cache, - const PcpLayerStackPtrVector& layerStacks, - bool markRefsOrPayloadSitesAsChanged); + const PcpLayerStackPtrVector& layerStacks); + + // When muting or unmuting a layer that is being referenced or payloaded, + // we need to ensure that all the relevant sites are recomposed. This + // function searches site dependencies of the provided layer stacks and + // marks those that are introduced via reference or payload arcs as + // significantly changed. + void _MarkReferencingSitesAsSignificantlyChanged( + const PcpCache* cache, + const PcpLayerStackPtrVector& layerStacks); private: LayerStackChanges _layerStackChanges; diff --git a/pxr/usd/pcp/composeSite.cpp b/pxr/usd/pcp/composeSite.cpp index 7fb57f42c25..c487e8dadb2 100644 --- a/pxr/usd/pcp/composeSite.cpp +++ b/pxr/usd/pcp/composeSite.cpp @@ -187,16 +187,14 @@ PcpComposeSitePermission(PcpLayerStackRefPtr const &layerStack, bool PcpComposeSiteHasPrimSpecs(PcpLayerStackRefPtr const &layerStack, SdfPath const &path, - const std::vector& layersToIgnore) + const std::unordered_set& + layersToIgnore) { for (auto const &layer: layerStack->GetLayers()) { // if a spec was found in this layer, ensure that it is currently not // being ignored. - if (layer->HasSpec(path)) { - if (std::find( layersToIgnore.begin(), layersToIgnore.end(), layer) - == layersToIgnore.end()) { - return true; - } + if (layer->HasSpec(path) && layersToIgnore.count(layer) == 0) { + return true; } } return false; diff --git a/pxr/usd/pcp/composeSite.h b/pxr/usd/pcp/composeSite.h index 2459d13ebec..02ccd95e30a 100644 --- a/pxr/usd/pcp/composeSite.h +++ b/pxr/usd/pcp/composeSite.h @@ -206,8 +206,10 @@ PCP_API bool PcpComposeSiteHasPrimSpecs(PcpLayerStackRefPtr const &layerStack, SdfPath const &path, - const std::vector& layersToIgnore); + const std::unordered_set& + layersToIgnore); +PCP_API bool PcpComposeSiteHasPrimSpecs(PcpLayerStackRefPtr const &layerStack, SdfPath const &path); diff --git a/pxr/usd/pcp/dependencies.cpp b/pxr/usd/pcp/dependencies.cpp index 8edf6e21da4..1fe32fb73f6 100644 --- a/pxr/usd/pcp/dependencies.cpp +++ b/pxr/usd/pcp/dependencies.cpp @@ -537,9 +537,10 @@ Pcp_AddCulledDependency( PcpCulledDependency dep; dep.flags = depFlags; + dep.arcType = node.GetArcType(); dep.layerStack = node.GetLayerStack(); dep.sitePath = node.GetPath(); - if (node.GetArcType() == PcpArcTypeRelocate) { + if (dep.arcType == PcpArcTypeRelocate) { // See _ProcessDependentNode in pcp/cache.cpp for the similar code // we use to handle non-culled dependency // diff --git a/pxr/usd/pcp/dependency.h b/pxr/usd/pcp/dependency.h index 72c9f87b668..c50cd9e8ee8 100644 --- a/pxr/usd/pcp/dependency.h +++ b/pxr/usd/pcp/dependency.h @@ -10,6 +10,7 @@ #include "pxr/pxr.h" #include "pxr/usd/pcp/api.h" #include "pxr/usd/pcp/mapFunction.h" +#include "pxr/usd/pcp/types.h" #include "pxr/usd/sdf/path.h" #include "pxr/base/tf/declarePtrs.h" @@ -121,6 +122,8 @@ struct PcpCulledDependency { /// Flag representing the type of dependency. PcpDependencyFlags flags = PcpDependencyTypeNone; + /// Arc type for this dependency. + PcpArcType arcType = PcpArcTypeRoot; /// Layer stack containing the specs the prim index depends on. PcpLayerStackRefPtr layerStack; /// Path of the dependency specs in the layer stack. diff --git a/pxr/usd/pcp/dependentNamespaceEditUtils.cpp b/pxr/usd/pcp/dependentNamespaceEditUtils.cpp index 107e0dc8726..d389531d057 100644 --- a/pxr/usd/pcp/dependentNamespaceEditUtils.cpp +++ b/pxr/usd/pcp/dependentNamespaceEditUtils.cpp @@ -235,8 +235,10 @@ class _PrimIndexDependentNodeEditProcessor void AddProcessEditsAtNodeTask( const PcpNodeRef &node, const SdfPath &oldPath, - const SdfPath &newPath) { - _InsertNodeTask({node, oldPath, newPath}); + const SdfPath &newPath, + bool willBeRelocated) { + _InsertNodeTask({node, oldPath, newPath, + /* isImpliedClassTask = */ false, willBeRelocated}); } // Processes all tasks producing all dependent edits for the prim index @@ -252,6 +254,7 @@ class _PrimIndexDependentNodeEditProcessor SdfPath oldPath; SdfPath newPath; bool isImpliedClassTask = false; + bool willBeRelocated = false; }; friend std::ostream & @@ -262,6 +265,9 @@ class _PrimIndexDependentNodeEditProcessor if (nodeTask.isImpliedClassTask) { out << " (isImpliedClassTask)"; } + if (nodeTask.willBeRelocated) { + out << " (willBeRelocated)"; + } return out; } @@ -658,7 +664,14 @@ _PrimIndexDependentNodeEditProcessor::_AddSpecMoveEdits( // move the specs at this node and log a warning as we only want to move // these specs if it constitutes moving the entire composed prim stack at // this node. - if (_HasUneditedUpstreamSpecConflicts(node, oldSpecPath)) { + // + // We ignore this check if the node has new relocates that will be applied + // to it by the initial edit. Relocates are used specifically for "moving" + // specs from weaker nodes without editing their specs so we actually expect + // unedited spec conflicts in this case and have used relocates to handle + // them. + if (!nodeTask.willBeRelocated && + _HasUneditedUpstreamSpecConflicts(node, oldSpecPath)) { return; } @@ -1552,6 +1565,8 @@ PcpGatherDependentNamespaceEdits( const SdfPath &oldPrimPath, const SdfPath &newPrimPath, const SdfLayerHandleVector &affectedLayers, + const PcpLayerStackRefPtr &affectedRelocatesLayerStack, + const SdfLayerHandle &addRelocatesToLayerStackEditLayer, const std::vector &dependentCaches) { TRACE_FUNCTION(); @@ -1562,6 +1577,75 @@ PcpGatherDependentNamespaceEdits( // Scratch space for spec move edits. _LayerSpecMovesScratch layerSpecMovesScratch; + // We don't author new relocates for the dependent prim indexes outside of + // the explicit new relocates that we will determine for the + // affectedRelocatesLayerStack if it is provided. Because of this, at each + // dependent node we look for conflicting specs in its subtree that will not + // be edited (and otherwise would require something like relocates) in order + // to log a warning that the composed prim stack won't be fully maintained + // by the edit. However, we won't have conflicting specs in nodes that are + // affected by the relocates edits above even if its subtree has unedited + // conflicting specs as the new relocates will effectively move those specs + // for us. All of this is to say that we need to pass the fact that the + // layer will have a relocates edit to the layer's dependent nodes so that + // they know to skip the conflicting subtree specs check. + // + // XXX: Note that this is actually a little simplified as what we really + // need to know at each node is whether its layer stack's compose relocates + // will, after the above relocates are applied, effectively relocate the + // subtree specs that would've otherwise had to be moved. But that is much + // more complex and this simpler method gets the job done for the vast + // majority of cases. + // + // Create a new list of each of the input affected layers paired with + // whether it has a relocates edit (which we initialize to false for all to + // start.) + std::vector> + affectedLayersAndHasRelocatesEdits; + affectedLayersAndHasRelocatesEdits.reserve(affectedLayers.size()); + for (const auto &layer : affectedLayers) { + affectedLayersAndHasRelocatesEdits.push_back({layer, false}); + } + + // If we were passed a layer stack to add relocates to, we'll use the + // relocates edit builder to process those now. + if (affectedRelocatesLayerStack) { + PcpLayerRelocatesEditBuilder builder( + affectedRelocatesLayerStack, addRelocatesToLayerStackEditLayer); + std::string error; + if (!builder.Relocate(oldPrimPath, newPrimPath, &error)) { + TF_CODING_ERROR("Cannot get relocates edits because: %s", + error.c_str()); + } + // For each initial relocates edit, we do three things: + // 1. Make sure the layer is put in the list of affected layers if it + // isn't already. Adding a relocate is the same as moving a spec as + // far as needing to update dependent prim indexes is concerned. + // 2. Marking the affected layer as having a relocates edit for when we + // add the initial dependent node tasks. + // 3. Move the edit into relocates edit results that is returned at the + // end. + for (auto &relocatesEdit : builder.GetEdits()) { + // Scoping for safety/clarity as the const reference of layer to + // relocatesEdit.first would become invalid after the relocatesEdit + // is inserted by rvalue reference. + { + const SdfLayerHandle &layer = relocatesEdit.first; + auto foundIt = std::find_if( + affectedLayersAndHasRelocatesEdits.begin(), + affectedLayersAndHasRelocatesEdits.end(), + [&](const auto &entry) { + return layer == entry.first;}); + if (foundIt == affectedLayersAndHasRelocatesEdits.end()) { + affectedLayersAndHasRelocatesEdits.push_back({layer, true}); + } else { + foundIt->second = true; + } + } + edits.dependentRelocatesEdits.insert(std::move(relocatesEdit)); + } + } + for (const PcpCache *cache : dependentCaches) { _PRINT_DEBUG_SCOPE( "Computing dependent namespace edits for PcpCache %s", @@ -1571,7 +1655,10 @@ PcpGatherDependentNamespaceEdits( // that depend on the old prim site in this layer and determine what // additional edits are necesssary to propagate edits to composition // dependencies as best as possible. - for (const auto &layer : affectedLayers) { + for (const auto &entry : affectedLayersAndHasRelocatesEdits) { + + const SdfLayerHandle &layer = entry.first; + const bool hasRelocatesEdits = entry.second; // Find all prim indexes which depend on the old prim path in this // layer. We recurse on site because moving or deleting a prim spec @@ -1637,8 +1724,14 @@ PcpGatherDependentNamespaceEdits( Pcp_ForEachDependentNode( dep.sitePath, layer, dep.indexPath, *cache, [&](const SdfPath &depIndexPath, const PcpNodeRef &node) { + // If the dependent layer is was affected by the + // initial relocates edit, indicate in the node task + // that the node task has a relocates edit. + // XXX: This is the part that is a little oversimplified + // as was mentioned earlier in this function. dependentNodeProcessor.AddProcessEditsAtNodeTask( - node, oldPrimPath, newPrimPath); + node, oldPrimPath, newPrimPath, + /*willBeRelocated = */ hasRelocatesEdits); }); dependentNodeProcessor.ProcessTasks(); } diff --git a/pxr/usd/pcp/dependentNamespaceEditUtils.h b/pxr/usd/pcp/dependentNamespaceEditUtils.h index 7d01aba8773..92d492fb57f 100644 --- a/pxr/usd/pcp/dependentNamespaceEditUtils.h +++ b/pxr/usd/pcp/dependentNamespaceEditUtils.h @@ -83,12 +83,20 @@ class PcpDependentNamespaceEdits { /// that would be affected by these edits and computes a full set of edits that /// would be required to maintain these dependent prim indexes' composed prim /// stacks, possibly moving the prim index to a new prim path if necessary. +/// If \p addRelocatesToLayerStack is provided, this will also add a new +/// relocates edit to the necessary layers in the layer stack that moves +/// oldPrimPath to newPrimPath. The layer \p addRelocatesToLayerStackEditLayer +/// provided is only relevant when the relocates layer stack is also provided as +/// it determines which specific layer in the layer stack will have a new +/// relocates entry added to it (see PcpLayerRelocatesEditBuilder). PCP_API PcpDependentNamespaceEdits PcpGatherDependentNamespaceEdits( const SdfPath &oldPrimPath, const SdfPath &newPrimPath, const SdfLayerHandleVector &affectedLayers, + const PcpLayerStackRefPtr &addRelocatesToLayerStack, + const SdfLayerHandle &addRelocatesToLayerStackEditLayer, const std::vector &dependentCaches); /// Gathers the list of layers that need to be edited to perform the spec move diff --git a/pxr/usd/pcp/layerStack.cpp b/pxr/usd/pcp/layerStack.cpp index fc16312f7ba..53a346c9064 100644 --- a/pxr/usd/pcp/layerStack.cpp +++ b/pxr/usd/pcp/layerStack.cpp @@ -44,11 +44,6 @@ TF_DEFINE_ENV_SETTING( PCP_ENABLE_PARALLEL_LAYER_PREFETCH, true, "Enables parallel, threaded pre-fetch of sublayers."); -TF_DEFINE_ENV_SETTING( - PCP_DISABLE_TIME_SCALING_BY_LAYER_TCPS, false, - "Disables automatic layer offset scaling from time codes per second " - "metadata in layers."); - TF_DEFINE_ENV_SETTING( PCP_ENABLE_LEGACY_RELOCATES_BEHAVIOR, true, "Enables the legacy behavior of ignoring composition errors that would " @@ -57,12 +52,6 @@ TF_DEFINE_ENV_SETTING( "non-USD caches/layer stacks; the legacy behavior cannot be enabled in USD " "mode"); -bool -PcpIsTimeScalingForLayerTimeCodesPerSecondDisabled() -{ - return TfGetEnvSetting(PCP_DISABLE_TIME_SCALING_BY_LAYER_TCPS); -} - struct Pcp_SublayerInfo { Pcp_SublayerInfo() = default; Pcp_SublayerInfo(const SdfLayerRefPtr& layer_, const SdfLayerOffset& offset_, @@ -1557,10 +1546,6 @@ PcpLayerStack::_Compute(const std::string &fileFormatTarget, // Build the layer stack. std::set seenLayers; - // Env setting for disabling TCPS scaling. - const bool scaleLayerOffsetByTcps = - !PcpIsTimeScalingForLayerTimeCodesPerSecondDisabled(); - const double rootTcps = _identifier.rootLayer->GetTimeCodesPerSecond(); SdfLayerOffset rootLayerOffset; @@ -1599,13 +1584,9 @@ PcpLayerStack::_Compute(const std::string &fileFormatTarget, if (_ShouldUseSessionTcps(_identifier.sessionLayer, _identifier.rootLayer)) { _timeCodesPerSecond = sessionTcps; - if (scaleLayerOffsetByTcps) { - rootLayerOffset.SetScale(_timeCodesPerSecond / rootTcps); - } + rootLayerOffset.SetScale(_timeCodesPerSecond / rootTcps); } else { - if (scaleLayerOffsetByTcps) { - sessionLayerOffset.SetScale(_timeCodesPerSecond / sessionTcps); - } + sessionLayerOffset.SetScale(_timeCodesPerSecond / sessionTcps); } _sessionLayerTree = @@ -1821,8 +1802,7 @@ PcpLayerStack::_BuildLayerStack( // Apply the scale from computed layer TCPS to sublayer TCPS to sublayer // layer offset. const double sublayerTcps = sublayerRefPtrs[i]->GetTimeCodesPerSecond(); - if (!PcpIsTimeScalingForLayerTimeCodesPerSecondDisabled() && - layerTcps != sublayerTcps) { + if (layerTcps != sublayerTcps) { sublayerOffset.SetScale(sublayerOffset.GetScale() * layerTcps / sublayerTcps); } diff --git a/pxr/usd/pcp/layerStack.h b/pxr/usd/pcp/layerStack.h index 8ae318b2ba6..35b0014d0b2 100644 --- a/pxr/usd/pcp/layerStack.h +++ b/pxr/usd/pcp/layerStack.h @@ -381,14 +381,6 @@ bool Pcp_NeedToRecomputeLayerStackTimeCodesPerSecond( const PcpLayerStackPtr& layerStack, const SdfLayerHandle &changedLayer); -/// Returns true when the environment variable has been set to disable the -/// behavior where differing time codes per second metadata in layers sublayered -/// or referenced by another layer are used to apply a layer offset scale to the -/// map function. -PCP_API -bool -PcpIsTimeScalingForLayerTimeCodesPerSecondDisabled(); - PXR_NAMESPACE_CLOSE_SCOPE #endif // PXR_USD_PCP_LAYER_STACK_H diff --git a/pxr/usd/pcp/pch.h b/pxr/usd/pcp/pch.h index b222a3116d6..326f2183f0f 100644 --- a/pxr/usd/pcp/pch.h +++ b/pxr/usd/pcp/pch.h @@ -72,6 +72,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/pxr/usd/pcp/primIndex.cpp b/pxr/usd/pcp/primIndex.cpp index 353aa664b23..44c3aee332f 100644 --- a/pxr/usd/pcp/primIndex.cpp +++ b/pxr/usd/pcp/primIndex.cpp @@ -9,6 +9,7 @@ #include "pxr/usd/pcp/primIndex.h" #include "pxr/usd/pcp/arc.h" #include "pxr/usd/pcp/cache.h" +#include "pxr/usd/pcp/changes.h" #include "pxr/usd/pcp/dynamicFileFormatContext.h" #include "pxr/usd/pcp/composeSite.h" #include "pxr/usd/pcp/debugCodes.h" @@ -2276,21 +2277,19 @@ _EvalRefOrPayloadArcs(PcpNodeRef node, layerStack = indexer->inputs.cache->ComputeLayerStack( layerStackIdentifier, &indexer->outputs->allErrors); - if (!PcpIsTimeScalingForLayerTimeCodesPerSecondDisabled()) { - // If the referenced or payloaded layer has a different TCPS - // than the source layer that introduces it, we apply the time - // scale between these TCPS values to the layer offset. - // Note that if the introducing layer is a layer stack sublayer, - // any TCPS scaling from the layer stack will already have been - // applied to the layer offset for the reference/payload. - const double srcTimeCodesPerSecond = - srcLayer->GetTimeCodesPerSecond(); - const double destTimeCodesPerSecond = - layerStack->GetTimeCodesPerSecond(); - if (srcTimeCodesPerSecond != destTimeCodesPerSecond) { - layerOffset.SetScale(layerOffset.GetScale() * - srcTimeCodesPerSecond / destTimeCodesPerSecond); - } + // If the referenced or payloaded layer has a different TCPS + // than the source layer that introduces it, we apply the time + // scale between these TCPS values to the layer offset. + // Note that if the introducing layer is a layer stack sublayer, + // any TCPS scaling from the layer stack will already have been + // applied to the layer offset for the reference/payload. + const double srcTimeCodesPerSecond = + srcLayer->GetTimeCodesPerSecond(); + const double destTimeCodesPerSecond = + layerStack->GetTimeCodesPerSecond(); + if (srcTimeCodesPerSecond != destTimeCodesPerSecond) { + layerOffset.SetScale(layerOffset.GetScale() * + srcTimeCodesPerSecond / destTimeCodesPerSecond); } } @@ -4718,19 +4717,12 @@ _EnforcePermissions( } } -void -Pcp_RescanForSpecs(PcpPrimIndex *index, bool usd, bool updateHasSpecs) -{ - const std::vector layersToIgnore; - Pcp_RescanForSpecs(index, usd, updateHasSpecs, layersToIgnore); -} - void Pcp_RescanForSpecs( PcpPrimIndex *index, bool usd, bool updateHasSpecs, - const std::vector& layersToIgnore) + const PcpCacheChanges *cacheChanges = nullptr) { TfAutoMallocTag2 tag("Pcp", "Pcp_RescanForSpecs"); @@ -4741,7 +4733,8 @@ Pcp_RescanForSpecs( TF_FOR_ALL(nodeIt, index->GetNodeRange()) { auto node = *nodeIt; nodeIt->SetHasSpecs(PcpComposeSiteHasPrimSpecs( - node.GetLayerStack(), node.GetPath(), layersToIgnore)); + node.GetLayerStack(), node.GetPath(), + cacheChanges->layersAffectedByMutingOrRemoval)); } } } else { @@ -4755,7 +4748,10 @@ Pcp_RescanForSpecs( node.GetLayerStack()->GetLayers(); const SdfPath& path = node.GetPath(); for (size_t i = 0, n = layers.size(); i != n; ++i) { - if (layers[i]->HasSpec(path)) { + if (layers[i]->HasSpec(path) && + (!cacheChanges || + cacheChanges->layersAffectedByMutingOrRemoval + .count(layers[i]) == 0)) { nodeHasSpecs = true; primSites.push_back(node.GetCompressedSdSite(i)); } diff --git a/pxr/usd/pcp/primIndex.h b/pxr/usd/pcp/primIndex.h index 00cb9730d9b..4d7c259817c 100644 --- a/pxr/usd/pcp/primIndex.h +++ b/pxr/usd/pcp/primIndex.h @@ -40,6 +40,7 @@ TF_DECLARE_WEAK_AND_REF_PTRS(PcpPrimIndex_Graph); class ArResolver; class PcpCache; +class PcpCacheChanges; class PcpPrimIndex; class PcpPrimIndexInputs; class PcpPrimIndexOutputs; @@ -281,7 +282,7 @@ class PcpPrimIndex friend void Pcp_RescanForSpecs( PcpPrimIndex*, bool usd, bool updateHasSpecs, - const std::vector& layersToIgnore); + const PcpCacheChanges *cacheChanges); // The node graph representing the compositional structure of this prim. PcpPrimIndex_GraphRefPtr _graph; diff --git a/pxr/usd/pcp/testenv/testPcpChanges.py b/pxr/usd/pcp/testenv/testPcpChanges.py index a003950b40c..e2094b1ac4a 100644 --- a/pxr/usd/pcp/testenv/testPcpChanges.py +++ b/pxr/usd/pcp/testenv/testPcpChanges.py @@ -6,9 +6,12 @@ # https://openusd.org/license. from pxr import Sdf, Pcp, Tf -import unittest +import os, unittest from contextlib import contextmanager +INCREMENTAL_CHANGES = Tf.GetEnvSetting( + 'PCP_ENABLE_MINIMAL_CHANGES_FOR_LAYER_OPERATIONS') + class TestPcpChanges(unittest.TestCase): def test_EmptySublayerChanges(self): subLayer1 = Sdf.Layer.CreateAnonymous() @@ -153,8 +156,13 @@ def "B" # With incremental changes these changes should only cause a resync # of /A and /B. - self.assertEqual(cp.GetSignificantChanges(), - [Sdf.Path('/A'), Sdf.Path('/B')]) + if INCREMENTAL_CHANGES: + self.assertEqual(cp.GetSignificantChanges(), + [Sdf.Path('/A'), Sdf.Path('/B')]) + else: + self.assertEqual(cp.GetSignificantChanges(), + [Sdf.Path('/')]) + self.assertEqual(cp.GetSpecChanges(), []) self.assertEqual(cp.GetPrimChanges(), []) @@ -370,9 +378,6 @@ def _ChangeAndVerify(newValDict, expectSignificantChange, expectedTcps): _ChangeAndVerify({'tcps' : 24.0, 'fps' : 24.0}, True, 24.0) _ChangeAndVerify({'tcps' : None, 'fps' : None}, False, 24.0) - @unittest.skipIf( - Tf.GetEnvSetting('PCP_DISABLE_TIME_SCALING_BY_LAYER_TCPS'), - "Test requires layer TCPS time scaling enabled") def test_TcpsChanges(self): """ Tests change processing for changes that affect the time codes per @@ -1027,6 +1032,109 @@ def test_ChangesToCulledAncestralNodes(self): self.assertEqual(cp.GetPrimChanges(), ['/FSToyCarA/Looks/PaintedWood_PaintedYellow']) + def test_MuteCulledAncestralReferences(self): + """Tests that muting an ancestrally-referenced layer and invalidates + affected prim indexes when the corresponding node is culled.""" + + rootLayer = Sdf.Layer.FindOrOpen( + 'TestMuteCulledAncestralReference/root.sdf') + refLayer = Sdf.Layer.FindOrOpenRelativeToLayer(rootLayer, 'ref.sdf') + pcp = Pcp.Cache(Pcp.LayerStackIdentifier(rootLayer)) + + # Compute the initial prim index and verify that all reference + # nodes pointing to ref.sdf have been culled from the graph. + # All nodes should be in the root layer stack. + pi, err = pcp.ComputePrimIndex( + '/FSToyCarA/Looks/PaintedWood_PaintedYellow') + + nodes = [pi.rootNode] + while nodes: + node = nodes[0] + nodes = nodes[1:] + node.children + self.assertEqual(node.layerStack.layers[0], rootLayer) + + # However, we should have a dependency registered on ref.sdf. + refLayerStack = pcp.FindAllLayerStacksUsingLayer(refLayer)[0] + self.assertEqual( + [dep.indexPath for dep in pcp.FindSiteDependencies( + refLayerStack, '/FSToyCarA_defaultShadingVariant')], + ['/FSToyCarA']) + + # Mute ref.sdf and verify that the prim index is invalidated + # and that recomputing the prim index results in a composition + # error due to the muted reference layer. + pcp.RequestLayerMuting([refLayer.identifier], []) + self.assertTrue(pcp.IsLayerMuted(refLayer.identifier)) + + self.assertFalse(pcp.FindPrimIndex( + '/FSToyCarA/Looks/PaintedWood_PaintedYellow')) + pi, err = pcp.ComputePrimIndex( + '/FSToyCarA/Looks/PaintedWood_PaintedYellow') + + self.assertTrue(err) + + def test_MuteRemoveSublayerWithSublayers(self): + """Tests that muting/removing sublayers that also have sublayers + invalidate affected cache prim indexes.""" + + def _Test(rootLayerId, layerOperationFn): + rootLayer = Sdf.Layer.FindOrOpen(rootLayerId) + pcp = Pcp.Cache(Pcp.LayerStackIdentifier(rootLayer)) + + def _ComputePrimIndex(path): + pi, err = pcp.ComputePrimIndex(path) + self.assertFalse(err, f"Unexpected errors for {path}: {err}") + return (pi, path) + + def _FindPrimIndex(indexAndPath): + return True if pcp.FindPrimIndex(indexAndPath[1]) else False + + # These prim indexes either have all of their opinions or a def + # in the sublayers that will be removed from composition. + overInSublayers = _ComputePrimIndex('/Parent/OverInSublayers') + overAndDefInSublayers = _ComputePrimIndex('/Parent/OverAndDefInSublayers') + overInRootDefInSublayer = _ComputePrimIndex('/Parent/OverInRootDefInSublayer') + + # This prim index has an over in the root layer and another over in + # a sublayer that will be removed from composition. + overInSublayerAndRoot = _ComputePrimIndex('/Parent/OverInSublayerAndRoot') + + layerOperationFn(pcp) + + # After the layer operation, all of these prim indexes should be + # resync'd. + self.assertFalse(_FindPrimIndex(overInSublayers)) + self.assertFalse(_FindPrimIndex(overAndDefInSublayers)) + self.assertFalse(_FindPrimIndex(overInRootDefInSublayer)) + + if INCREMENTAL_CHANGES: + # This prim index does not need to be recomputed, it just has an + # updated prim stack. + self.assertTrue(_FindPrimIndex(overInSublayerAndRoot)) + self.assertEqual( + overInSublayerAndRoot[0].primStack, + [rootLayer.GetPrimAtPath('/Parent/OverInSublayerAndRoot')]) + else: + self.assertFalse(_FindPrimIndex(overInSublayerAndRoot)) + + # Test cases for muting a sublayer that itself has sublayers. + def _MuteSublayer(pcp): + subLayer = pcp.layerStack.layers[1] + self.assertEqual(os.path.basename(subLayer.identifier), 'sub.sdf') + pcp.RequestLayerMuting([subLayer.identifier], []) + + _Test('TestMuteRemoveWithNestedSublayers/root.sdf', _MuteSublayer) + _Test('TestMuteRemoveWithSiblingSublayers/root.sdf', _MuteSublayer) + + # Test cases for removing a sublayer that itself has sublayers. + def _RemoveSublayer(pcp): + with Pcp._TestChangeProcessor(pcp): + rootLayer = pcp.GetLayerStackIdentifier().rootLayer + rootLayer.subLayerPaths.clear() + + _Test('TestMuteRemoveWithNestedSublayers/root.sdf', _RemoveSublayer) + _Test('TestMuteRemoveWithSiblingSublayers/root.sdf', _RemoveSublayer) + def test_AddMuteRemoveSublayerWithRelocates(self): """Tests that adding/muting/removing sublayers that only define layer relocates will invalidate affected cached prim indexes.""" diff --git a/pxr/usd/pcp/testenv/testPcpChanges.testenv/TestMuteCulledAncestralReference/ref.sdf b/pxr/usd/pcp/testenv/testPcpChanges.testenv/TestMuteCulledAncestralReference/ref.sdf new file mode 100644 index 00000000000..0951e460b00 --- /dev/null +++ b/pxr/usd/pcp/testenv/testPcpChanges.testenv/TestMuteCulledAncestralReference/ref.sdf @@ -0,0 +1,8 @@ +#sdf 1.4.32 + +def "FSToyCarA_defaultShadingVariant" +{ + def "Looks" + { + } +} diff --git a/pxr/usd/pcp/testenv/testPcpChanges.testenv/TestMuteCulledAncestralReference/root.sdf b/pxr/usd/pcp/testenv/testPcpChanges.testenv/TestMuteCulledAncestralReference/root.sdf new file mode 100644 index 00000000000..d9994d51e90 --- /dev/null +++ b/pxr/usd/pcp/testenv/testPcpChanges.testenv/TestMuteCulledAncestralReference/root.sdf @@ -0,0 +1,37 @@ +#sdf 1.4.32 + +def "FSToyCarA_geom" +{ + def "Looks" + { + def "PaintedWood" + { + custom float inputs:wood_diffuseK + } + + def "PaintedWood_PaintedYellow" ( + inherits = + ) + { + } + } +} + +over "FSToyCarA" ( + references = [ + @./ref.sdf@, + + ] +) +{ + over "Looks" + { + over "PaintedWood" + { + } + + over "PaintedWood_PaintedYellow" + { + } + } +} diff --git a/pxr/usd/pcp/testenv/testPcpChanges.testenv/TestMuteRemoveWithNestedSublayers/root.sdf b/pxr/usd/pcp/testenv/testPcpChanges.testenv/TestMuteRemoveWithNestedSublayers/root.sdf new file mode 100644 index 00000000000..f63cd99ff62 --- /dev/null +++ b/pxr/usd/pcp/testenv/testPcpChanges.testenv/TestMuteRemoveWithNestedSublayers/root.sdf @@ -0,0 +1,17 @@ +#sdf 1.4.32 +( + subLayers = [ + @./sub.sdf@ + ] +) + +def "Parent" +{ + over "OverInSublayerAndRoot" + { + } + + over "OverInRootDefInSublayer" + { + } +} diff --git a/pxr/usd/pcp/testenv/testPcpChanges.testenv/TestMuteRemoveWithNestedSublayers/sub.sdf b/pxr/usd/pcp/testenv/testPcpChanges.testenv/TestMuteRemoveWithNestedSublayers/sub.sdf new file mode 100644 index 00000000000..a9bf1f6aff8 --- /dev/null +++ b/pxr/usd/pcp/testenv/testPcpChanges.testenv/TestMuteRemoveWithNestedSublayers/sub.sdf @@ -0,0 +1,6 @@ +#sdf 1.4.32 +( + subLayers = [ + @./sub2.sdf@ + ] +) diff --git a/pxr/usd/pcp/testenv/testPcpChanges.testenv/TestMuteRemoveWithNestedSublayers/sub2.sdf b/pxr/usd/pcp/testenv/testPcpChanges.testenv/TestMuteRemoveWithNestedSublayers/sub2.sdf new file mode 100644 index 00000000000..56dea6230cf --- /dev/null +++ b/pxr/usd/pcp/testenv/testPcpChanges.testenv/TestMuteRemoveWithNestedSublayers/sub2.sdf @@ -0,0 +1,25 @@ +#sdf 1.4.32 +( + subLayers = [ + @./sub3.sdf@ + ] +) + +over "Parent" +{ + over "OverInSublayerAndRoot" + { + } + + def "OverInRootDefInSublayer" + { + } + + over "OverInSublayers" + { + } + + over "OverAndDefInSublayers" + { + } +} diff --git a/pxr/usd/pcp/testenv/testPcpChanges.testenv/TestMuteRemoveWithNestedSublayers/sub3.sdf b/pxr/usd/pcp/testenv/testPcpChanges.testenv/TestMuteRemoveWithNestedSublayers/sub3.sdf new file mode 100644 index 00000000000..2178853dc2e --- /dev/null +++ b/pxr/usd/pcp/testenv/testPcpChanges.testenv/TestMuteRemoveWithNestedSublayers/sub3.sdf @@ -0,0 +1,12 @@ +#sdf 1.4.32 + +over "Parent" +{ + over "OverInSublayers" + { + } + + def "OverAndDefInSublayers" + { + } +} diff --git a/pxr/usd/pcp/testenv/testPcpChanges.testenv/TestMuteRemoveWithSiblingSublayers/root.sdf b/pxr/usd/pcp/testenv/testPcpChanges.testenv/TestMuteRemoveWithSiblingSublayers/root.sdf new file mode 100644 index 00000000000..f63cd99ff62 --- /dev/null +++ b/pxr/usd/pcp/testenv/testPcpChanges.testenv/TestMuteRemoveWithSiblingSublayers/root.sdf @@ -0,0 +1,17 @@ +#sdf 1.4.32 +( + subLayers = [ + @./sub.sdf@ + ] +) + +def "Parent" +{ + over "OverInSublayerAndRoot" + { + } + + over "OverInRootDefInSublayer" + { + } +} diff --git a/pxr/usd/pcp/testenv/testPcpChanges.testenv/TestMuteRemoveWithSiblingSublayers/sub.sdf b/pxr/usd/pcp/testenv/testPcpChanges.testenv/TestMuteRemoveWithSiblingSublayers/sub.sdf new file mode 100644 index 00000000000..998848ae34d --- /dev/null +++ b/pxr/usd/pcp/testenv/testPcpChanges.testenv/TestMuteRemoveWithSiblingSublayers/sub.sdf @@ -0,0 +1,7 @@ +#sdf 1.4.32 +( + subLayers = [ + @./sub2.sdf@, + @./sub3.sdf@ + ] +) diff --git a/pxr/usd/pcp/testenv/testPcpChanges.testenv/TestMuteRemoveWithSiblingSublayers/sub2.sdf b/pxr/usd/pcp/testenv/testPcpChanges.testenv/TestMuteRemoveWithSiblingSublayers/sub2.sdf new file mode 100644 index 00000000000..7449c7c97ec --- /dev/null +++ b/pxr/usd/pcp/testenv/testPcpChanges.testenv/TestMuteRemoveWithSiblingSublayers/sub2.sdf @@ -0,0 +1,20 @@ +#sdf 1.4.32 + +over "Parent" +{ + over "OverInSublayerAndRoot" + { + } + + def "OverInRootDefInSublayer" + { + } + + over "OverInSublayers" + { + } + + over "OverAndDefInSublayers" + { + } +} diff --git a/pxr/usd/pcp/testenv/testPcpChanges.testenv/TestMuteRemoveWithSiblingSublayers/sub3.sdf b/pxr/usd/pcp/testenv/testPcpChanges.testenv/TestMuteRemoveWithSiblingSublayers/sub3.sdf new file mode 100644 index 00000000000..2178853dc2e --- /dev/null +++ b/pxr/usd/pcp/testenv/testPcpChanges.testenv/TestMuteRemoveWithSiblingSublayers/sub3.sdf @@ -0,0 +1,12 @@ +#sdf 1.4.32 + +over "Parent" +{ + over "OverInSublayers" + { + } + + def "OverAndDefInSublayers" + { + } +} diff --git a/pxr/usd/pcp/testenv/testPcpExpressionComposition.py b/pxr/usd/pcp/testenv/testPcpExpressionComposition.py index 93d724928d8..4810511eff9 100644 --- a/pxr/usd/pcp/testenv/testPcpExpressionComposition.py +++ b/pxr/usd/pcp/testenv/testPcpExpressionComposition.py @@ -7,7 +7,10 @@ import unittest -from pxr import Pcp, Sdf +from pxr import Pcp, Sdf, Tf + +INCREMENTAL_CHANGES = Tf.GetEnvSetting( + 'PCP_ENABLE_MINIMAL_CHANGES_FOR_LAYER_OPERATIONS') def LoadPcpCache(rootLayer, sessionLayer = None): l = Sdf.Layer.FindOrOpen(rootLayer) @@ -208,7 +211,12 @@ def test_SublayerAuthoring(self): # Since B.sdf is not empty, this should incur a significant resync. with Pcp._TestChangeProcessor(pcpCache) as changes: rootLayer.subLayerPaths.append('`"./B.sdf"`') - self.assertEqual(changes.GetSignificantChanges(), ['/Test']) + + if INCREMENTAL_CHANGES: + self.assertEqual(changes.GetSignificantChanges(), ['/Test']) + else: + self.assertEqual(changes.GetSignificantChanges(), ['/']) + self.assertEqual(changes.GetSpecChanges(), []) pi, err = pcpCache.ComputePrimIndex('/Test') @@ -232,7 +240,12 @@ def test_SublayerAuthoring(self): # Remove the sublayer we just added to reverse the changes. with Pcp._TestChangeProcessor(pcpCache) as changes: del rootLayer.subLayerPaths[-1] - self.assertEqual(changes.GetSignificantChanges(), ['/Test']) + + if INCREMENTAL_CHANGES: + self.assertEqual(changes.GetSignificantChanges(), ['/Test']) + else: + self.assertEqual(changes.GetSignificantChanges(), ['/']) + self.assertEqual(changes.GetSpecChanges(), []) pi, err = pcpCache.ComputePrimIndex('/Test') @@ -319,7 +332,11 @@ def test_SublayerAuthoringAndVariableChange(self): rootLayer.expressionVariables = {'X':'B'} rootLayer.subLayerPaths.append('`"./${X}.sdf"`') - self.assertEqual(changes.GetSignificantChanges(), ['/BaseRef']) + if INCREMENTAL_CHANGES: + self.assertEqual(changes.GetSignificantChanges(), ['/BaseRef']) + else: + self.assertEqual(changes.GetSignificantChanges(), ['/']) + self.assertEqual(changes.GetSpecChanges(), []) pi, err = pcpCache.ComputePrimIndex('/BaseRef') @@ -1017,7 +1034,10 @@ def test_ExpressionVarChanges_SignificantLayerStackChanges(self): rootLayer.expressionVariables = {'A':'C'} rootLayer.subLayerPaths.append('sig_changes/sub.sdf') - self.assertEqual(changes.GetSignificantChanges(), ['/Dummy']) + if INCREMENTAL_CHANGES: + self.assertEqual(changes.GetSignificantChanges(), ['/Dummy']) + else: + self.assertEqual(changes.GetSignificantChanges(), ['/']) self.AssertVariables( pcpCache, '/Root1', diff --git a/pxr/usd/pcp/testenv/testPcpLayerMuting.py b/pxr/usd/pcp/testenv/testPcpLayerMuting.py index 76f50eee5e1..c86bbaa9c90 100644 --- a/pxr/usd/pcp/testenv/testPcpLayerMuting.py +++ b/pxr/usd/pcp/testenv/testPcpLayerMuting.py @@ -185,48 +185,52 @@ def test_MutingReferencedLayers(self): rootLayer = self._LoadLayer(os.path.join(os.getcwd(), 'refs/root.sdf')) refLayer = self._LoadLayer(os.path.join(os.getcwd(), 'refs/ref.sdf')) - pcp = self._LoadPcpCache(rootLayer.identifier) - pcp2 = self._LoadPcpCache(rootLayer.identifier) - - (pi, err) = pcp.ComputePrimIndex('/Root') - self.assertTrue(not err) - self.assertEqual(pi.rootNode.children[0].arcType, Pcp.ArcTypeReference) - self.assertEqual(pi.rootNode.children[0].layerStack.layers[0], refLayer) - - (pi2, err2) = pcp2.ComputePrimIndex('/Root') - self.assertTrue(not err2) - self.assertEqual(pi2.rootNode.children[0].arcType, Pcp.ArcTypeReference) - self.assertEqual(pi2.rootNode.children[0].layerStack.layers[0], refLayer) - - # Mute the root layer of the referenced layer stack. This should - # result in change processing, a composition error when recomposing - # /Root, and no reference node on the prim index. - pcp.RequestLayerMuting([refLayer.identifier], []) - self.assertEqual(pcp.GetMutedLayers(), [refLayer.identifier]) - - (pi, err) = pcp.ComputePrimIndex('/Root') - self.assertTrue(err) - self.assertEqual(len(pi.rootNode.children), 0) - - (pi2, err2) = pcp2.ComputePrimIndex('/Root') - self.assertTrue(not err2) - self.assertEqual(pi2.rootNode.children[0].arcType, Pcp.ArcTypeReference) - self.assertEqual(pi2.rootNode.children[0].layerStack.layers[0], refLayer) - - # Unmute the layer and verify that the composition error is resolved - # and the reference is restored to the prim index. - pcp.RequestLayerMuting([], [refLayer.identifier]) - self.assertEqual(pcp.GetMutedLayers(), []) - - (pi, err) = pcp.ComputePrimIndex('/Root') - self.assertTrue(not err) - self.assertEqual(pi.rootNode.children[0].arcType, Pcp.ArcTypeReference) - self.assertEqual(pi.rootNode.children[0].layerStack.layers[0], refLayer) - - (pi2, err2) = pcp2.ComputePrimIndex('/Root') - self.assertTrue(not err2) - self.assertEqual(pi2.rootNode.children[0].arcType, Pcp.ArcTypeReference) - self.assertEqual(pi2.rootNode.children[0].layerStack.layers[0], refLayer) + def _Test(path): + pcp = self._LoadPcpCache(rootLayer.identifier) + pcp2 = self._LoadPcpCache(rootLayer.identifier) + + (pi, err) = pcp.ComputePrimIndex(path) + self.assertTrue(not err) + self.assertEqual(pi.rootNode.children[0].arcType, Pcp.ArcTypeReference) + self.assertEqual(pi.rootNode.children[0].layerStack.layers[0], refLayer) + + (pi2, err2) = pcp2.ComputePrimIndex(path) + self.assertTrue(not err2) + self.assertEqual(pi2.rootNode.children[0].arcType, Pcp.ArcTypeReference) + self.assertEqual(pi2.rootNode.children[0].layerStack.layers[0], refLayer) + + # Mute the root layer of the referenced layer stack. This should + # result in change processing, a composition error when recomposing + # /Root, and no reference node on the prim index. + pcp.RequestLayerMuting([refLayer.identifier], []) + self.assertEqual(pcp.GetMutedLayers(), [refLayer.identifier]) + + (pi, err) = pcp.ComputePrimIndex(path) + self.assertTrue(err) + self.assertEqual(len(pi.rootNode.children), 0) + + (pi2, err2) = pcp2.ComputePrimIndex(path) + self.assertTrue(not err2) + self.assertEqual(pi2.rootNode.children[0].arcType, Pcp.ArcTypeReference) + self.assertEqual(pi2.rootNode.children[0].layerStack.layers[0], refLayer) + + # Unmute the layer and verify that the composition error is resolved + # and the reference is restored to the prim index. + pcp.RequestLayerMuting([], [refLayer.identifier]) + self.assertEqual(pcp.GetMutedLayers(), []) + + (pi, err) = pcp.ComputePrimIndex(path) + self.assertTrue(not err) + self.assertEqual(pi.rootNode.children[0].arcType, Pcp.ArcTypeReference) + self.assertEqual(pi.rootNode.children[0].layerStack.layers[0], refLayer) + + (pi2, err2) = pcp2.ComputePrimIndex(path) + self.assertTrue(not err2) + self.assertEqual(pi2.rootNode.children[0].arcType, Pcp.ArcTypeReference) + self.assertEqual(pi2.rootNode.children[0].layerStack.layers[0], refLayer) + + _Test('/ReferenceToDef') + _Test('/ReferenceToOver') def test_MutingWithFileFormatTarget(self): """Tests layer muting for a Pcp.Cache with a file format target.""" diff --git a/pxr/usd/pcp/testenv/testPcpLayerMuting.testenv/refs/ref.sdf b/pxr/usd/pcp/testenv/testPcpLayerMuting.testenv/refs/ref.sdf index 8d259c99e06..fc07ac41023 100644 --- a/pxr/usd/pcp/testenv/testPcpLayerMuting.testenv/refs/ref.sdf +++ b/pxr/usd/pcp/testenv/testPcpLayerMuting.testenv/refs/ref.sdf @@ -1,5 +1,9 @@ #sdf 1.4.32 -def "Ref" +def "Def" +{ +} + +over "Over" { } diff --git a/pxr/usd/pcp/testenv/testPcpLayerMuting.testenv/refs/root.sdf b/pxr/usd/pcp/testenv/testPcpLayerMuting.testenv/refs/root.sdf index 58ee5066f6f..c01ee828d75 100644 --- a/pxr/usd/pcp/testenv/testPcpLayerMuting.testenv/refs/root.sdf +++ b/pxr/usd/pcp/testenv/testPcpLayerMuting.testenv/refs/root.sdf @@ -1,7 +1,13 @@ #sdf 1.4.32 -def "Root" ( - references = @./ref.sdf@ +def "ReferenceToDef" ( + references = @./ref.sdf@ +) +{ +} + +def "ReferenceToOver" ( + references = @./ref.sdf@ ) { } diff --git a/pxr/usd/pcp/testenv/testPcpMuseum_TimeCodesPerSecond.testenv/baseline/compositionResults_TimeCodesPerSecond1_Legacy.txt b/pxr/usd/pcp/testenv/testPcpMuseum_TimeCodesPerSecond.testenv/baseline/compositionResults_TimeCodesPerSecond1_Legacy.txt deleted file mode 100644 index 2c29b447197..00000000000 --- a/pxr/usd/pcp/testenv/testPcpMuseum_TimeCodesPerSecond.testenv/baseline/compositionResults_TimeCodesPerSecond1_Legacy.txt +++ /dev/null @@ -1,395 +0,0 @@ -Loading @TimeCodesPerSecond/root.sdf@ - ------------------------------------------------------------------------- -Layer Stack: - root.sdf - s.sdf - ss.sdf - ss_48tcps.sdf - ss_24tcps_12fps.sdf - ss_12fps.sdf - s_48tcps.sdf - ss.sdf - ss_48tcps.sdf - ss_24tcps_12fps.sdf - ss_12fps.sdf - s_24tcps_12fps.sdf - ss.sdf - ss_48tcps.sdf - ss_24tcps_12fps.sdf - ss_12fps.sdf - s_12fps.sdf - ss.sdf - ss_48tcps.sdf - ss_24tcps_12fps.sdf - ss_12fps.sdf - ------------------------------------------------------------------------- -Results for composing - -Prim Stack: - ss_12fps.sdf /SS4 - ss_12fps.sdf /SS4 - ss_12fps.sdf /SS4 - ss_12fps.sdf /SS4 - ref.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - ref_48tcps.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - ref_24tcps_12fps.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - ref_12fps.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - -Time Offsets: - root.sdf /SS4 root (offset=0.00, scale=1.00) - s.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_48tcps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_24tcps_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - ref.sdf /Ref reference (offset=70.00, scale=8.00) - ref_48tcps.sdf /Ref reference (offset=70.00, scale=8.00) - ref_24tcps_12fps.sdf /Ref reference (offset=70.00, scale=8.00) - ref_12fps.sdf /Ref reference (offset=70.00, scale=8.00) - ------------------------------------------------------------------------- -Results for composing - -Prim Stack: - ss_24tcps_12fps.sdf /SS3 - ss_24tcps_12fps.sdf /SS3 - ss_24tcps_12fps.sdf /SS3 - ss_24tcps_12fps.sdf /SS3 - ref.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - ref_48tcps.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - ref_24tcps_12fps.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - ref_12fps.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - -Time Offsets: - root.sdf /SS3 root (offset=0.00, scale=1.00) - s.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_48tcps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_24tcps_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - ref.sdf /Ref reference (offset=70.00, scale=8.00) - ref_48tcps.sdf /Ref reference (offset=70.00, scale=8.00) - ref_24tcps_12fps.sdf /Ref reference (offset=70.00, scale=8.00) - ref_12fps.sdf /Ref reference (offset=70.00, scale=8.00) - ------------------------------------------------------------------------- -Results for composing - -Prim Stack: - ss_48tcps.sdf /SS2 - ss_48tcps.sdf /SS2 - ss_48tcps.sdf /SS2 - ss_48tcps.sdf /SS2 - ref.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - ref_48tcps.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - ref_24tcps_12fps.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - ref_12fps.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - -Time Offsets: - root.sdf /SS2 root (offset=0.00, scale=1.00) - s.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_48tcps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_24tcps_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - ref.sdf /Ref reference (offset=70.00, scale=8.00) - ref_48tcps.sdf /Ref reference (offset=70.00, scale=8.00) - ref_24tcps_12fps.sdf /Ref reference (offset=70.00, scale=8.00) - ref_12fps.sdf /Ref reference (offset=70.00, scale=8.00) - ------------------------------------------------------------------------- -Results for composing - -Prim Stack: - ss.sdf /SS1 - ss.sdf /SS1 - ss.sdf /SS1 - ss.sdf /SS1 - ref.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - ref_48tcps.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - ref_24tcps_12fps.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - ref_12fps.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - -Time Offsets: - root.sdf /SS1 root (offset=0.00, scale=1.00) - s.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_48tcps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_24tcps_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - ref.sdf /Ref reference (offset=70.00, scale=8.00) - ref_48tcps.sdf /Ref reference (offset=70.00, scale=8.00) - ref_24tcps_12fps.sdf /Ref reference (offset=70.00, scale=8.00) - ref_12fps.sdf /Ref reference (offset=70.00, scale=8.00) - ------------------------------------------------------------------------- -Results for composing - -Prim Stack: - s_12fps.sdf /S4 - -Time Offsets: - root.sdf /S4 root (offset=0.00, scale=1.00) - s.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_48tcps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_24tcps_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - ------------------------------------------------------------------------- -Results for composing - -Prim Stack: - s_24tcps_12fps.sdf /S3 - -Time Offsets: - root.sdf /S3 root (offset=0.00, scale=1.00) - s.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_48tcps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_24tcps_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - ------------------------------------------------------------------------- -Results for composing - -Prim Stack: - s_48tcps.sdf /S2 - -Time Offsets: - root.sdf /S2 root (offset=0.00, scale=1.00) - s.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_48tcps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_24tcps_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - ------------------------------------------------------------------------- -Results for composing - -Prim Stack: - s.sdf /S1 - -Time Offsets: - root.sdf /S1 root (offset=0.00, scale=1.00) - s.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_48tcps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_24tcps_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - ------------------------------------------------------------------------- -Results for composing - -Prim Stack: - root.sdf /Root - -Time Offsets: - root.sdf /Root root (offset=0.00, scale=1.00) - s.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_48tcps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_24tcps_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - diff --git a/pxr/usd/pcp/testenv/testPcpMuseum_TimeCodesPerSecond.testenv/baseline/compositionResults_TimeCodesPerSecond2_Legacy.txt b/pxr/usd/pcp/testenv/testPcpMuseum_TimeCodesPerSecond.testenv/baseline/compositionResults_TimeCodesPerSecond2_Legacy.txt deleted file mode 100644 index a926dac4c7c..00000000000 --- a/pxr/usd/pcp/testenv/testPcpMuseum_TimeCodesPerSecond.testenv/baseline/compositionResults_TimeCodesPerSecond2_Legacy.txt +++ /dev/null @@ -1,395 +0,0 @@ -Loading @TimeCodesPerSecond/root_48tcps.sdf@ - ------------------------------------------------------------------------- -Layer Stack: - root_48tcps.sdf - s.sdf - ss.sdf - ss_48tcps.sdf - ss_24tcps_12fps.sdf - ss_12fps.sdf - s_48tcps.sdf - ss.sdf - ss_48tcps.sdf - ss_24tcps_12fps.sdf - ss_12fps.sdf - s_24tcps_12fps.sdf - ss.sdf - ss_48tcps.sdf - ss_24tcps_12fps.sdf - ss_12fps.sdf - s_12fps.sdf - ss.sdf - ss_48tcps.sdf - ss_24tcps_12fps.sdf - ss_12fps.sdf - ------------------------------------------------------------------------- -Results for composing - -Prim Stack: - ss_12fps.sdf /SS4 - ss_12fps.sdf /SS4 - ss_12fps.sdf /SS4 - ss_12fps.sdf /SS4 - ref.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - ref_48tcps.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - ref_24tcps_12fps.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - ref_12fps.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - -Time Offsets: - root_48tcps.sdf /SS4 root (offset=0.00, scale=1.00) - s.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_48tcps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_24tcps_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - ref.sdf /Ref reference (offset=70.00, scale=8.00) - ref_48tcps.sdf /Ref reference (offset=70.00, scale=8.00) - ref_24tcps_12fps.sdf /Ref reference (offset=70.00, scale=8.00) - ref_12fps.sdf /Ref reference (offset=70.00, scale=8.00) - ------------------------------------------------------------------------- -Results for composing - -Prim Stack: - ss_24tcps_12fps.sdf /SS3 - ss_24tcps_12fps.sdf /SS3 - ss_24tcps_12fps.sdf /SS3 - ss_24tcps_12fps.sdf /SS3 - ref.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - ref_48tcps.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - ref_24tcps_12fps.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - ref_12fps.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - -Time Offsets: - root_48tcps.sdf /SS3 root (offset=0.00, scale=1.00) - s.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_48tcps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_24tcps_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - ref.sdf /Ref reference (offset=70.00, scale=8.00) - ref_48tcps.sdf /Ref reference (offset=70.00, scale=8.00) - ref_24tcps_12fps.sdf /Ref reference (offset=70.00, scale=8.00) - ref_12fps.sdf /Ref reference (offset=70.00, scale=8.00) - ------------------------------------------------------------------------- -Results for composing - -Prim Stack: - ss_48tcps.sdf /SS2 - ss_48tcps.sdf /SS2 - ss_48tcps.sdf /SS2 - ss_48tcps.sdf /SS2 - ref.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - ref_48tcps.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - ref_24tcps_12fps.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - ref_12fps.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - -Time Offsets: - root_48tcps.sdf /SS2 root (offset=0.00, scale=1.00) - s.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_48tcps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_24tcps_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - ref.sdf /Ref reference (offset=70.00, scale=8.00) - ref_48tcps.sdf /Ref reference (offset=70.00, scale=8.00) - ref_24tcps_12fps.sdf /Ref reference (offset=70.00, scale=8.00) - ref_12fps.sdf /Ref reference (offset=70.00, scale=8.00) - ------------------------------------------------------------------------- -Results for composing - -Prim Stack: - ss.sdf /SS1 - ss.sdf /SS1 - ss.sdf /SS1 - ss.sdf /SS1 - ref.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - ref_48tcps.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - ref_24tcps_12fps.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - ref_12fps.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - -Time Offsets: - root_48tcps.sdf /SS1 root (offset=0.00, scale=1.00) - s.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_48tcps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_24tcps_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - ref.sdf /Ref reference (offset=70.00, scale=8.00) - ref_48tcps.sdf /Ref reference (offset=70.00, scale=8.00) - ref_24tcps_12fps.sdf /Ref reference (offset=70.00, scale=8.00) - ref_12fps.sdf /Ref reference (offset=70.00, scale=8.00) - ------------------------------------------------------------------------- -Results for composing - -Prim Stack: - s_12fps.sdf /S4 - -Time Offsets: - root_48tcps.sdf /S4 root (offset=0.00, scale=1.00) - s.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_48tcps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_24tcps_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - ------------------------------------------------------------------------- -Results for composing - -Prim Stack: - s_24tcps_12fps.sdf /S3 - -Time Offsets: - root_48tcps.sdf /S3 root (offset=0.00, scale=1.00) - s.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_48tcps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_24tcps_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - ------------------------------------------------------------------------- -Results for composing - -Prim Stack: - s_48tcps.sdf /S2 - -Time Offsets: - root_48tcps.sdf /S2 root (offset=0.00, scale=1.00) - s.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_48tcps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_24tcps_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - ------------------------------------------------------------------------- -Results for composing - -Prim Stack: - s.sdf /S1 - -Time Offsets: - root_48tcps.sdf /S1 root (offset=0.00, scale=1.00) - s.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_48tcps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_24tcps_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - ------------------------------------------------------------------------- -Results for composing - -Prim Stack: - root_48tcps.sdf /Root - -Time Offsets: - root_48tcps.sdf /Root root (offset=0.00, scale=1.00) - s.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_48tcps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_24tcps_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - diff --git a/pxr/usd/pcp/testenv/testPcpMuseum_TimeCodesPerSecond.testenv/baseline/compositionResults_TimeCodesPerSecond3_Legacy.txt b/pxr/usd/pcp/testenv/testPcpMuseum_TimeCodesPerSecond.testenv/baseline/compositionResults_TimeCodesPerSecond3_Legacy.txt deleted file mode 100644 index ae2edf1fd37..00000000000 --- a/pxr/usd/pcp/testenv/testPcpMuseum_TimeCodesPerSecond.testenv/baseline/compositionResults_TimeCodesPerSecond3_Legacy.txt +++ /dev/null @@ -1,395 +0,0 @@ -Loading @TimeCodesPerSecond/root_24tcps_12fps.sdf@ - ------------------------------------------------------------------------- -Layer Stack: - root_24tcps_12fps.sdf - s.sdf - ss.sdf - ss_48tcps.sdf - ss_24tcps_12fps.sdf - ss_12fps.sdf - s_48tcps.sdf - ss.sdf - ss_48tcps.sdf - ss_24tcps_12fps.sdf - ss_12fps.sdf - s_24tcps_12fps.sdf - ss.sdf - ss_48tcps.sdf - ss_24tcps_12fps.sdf - ss_12fps.sdf - s_12fps.sdf - ss.sdf - ss_48tcps.sdf - ss_24tcps_12fps.sdf - ss_12fps.sdf - ------------------------------------------------------------------------- -Results for composing - -Prim Stack: - ss_12fps.sdf /SS4 - ss_12fps.sdf /SS4 - ss_12fps.sdf /SS4 - ss_12fps.sdf /SS4 - ref.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - ref_48tcps.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - ref_24tcps_12fps.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - ref_12fps.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - -Time Offsets: - root_24tcps_12fps.sdf /SS4 root (offset=0.00, scale=1.00) - s.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_48tcps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_24tcps_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - ref.sdf /Ref reference (offset=70.00, scale=8.00) - ref_48tcps.sdf /Ref reference (offset=70.00, scale=8.00) - ref_24tcps_12fps.sdf /Ref reference (offset=70.00, scale=8.00) - ref_12fps.sdf /Ref reference (offset=70.00, scale=8.00) - ------------------------------------------------------------------------- -Results for composing - -Prim Stack: - ss_24tcps_12fps.sdf /SS3 - ss_24tcps_12fps.sdf /SS3 - ss_24tcps_12fps.sdf /SS3 - ss_24tcps_12fps.sdf /SS3 - ref.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - ref_48tcps.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - ref_24tcps_12fps.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - ref_12fps.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - -Time Offsets: - root_24tcps_12fps.sdf /SS3 root (offset=0.00, scale=1.00) - s.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_48tcps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_24tcps_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - ref.sdf /Ref reference (offset=70.00, scale=8.00) - ref_48tcps.sdf /Ref reference (offset=70.00, scale=8.00) - ref_24tcps_12fps.sdf /Ref reference (offset=70.00, scale=8.00) - ref_12fps.sdf /Ref reference (offset=70.00, scale=8.00) - ------------------------------------------------------------------------- -Results for composing - -Prim Stack: - ss_48tcps.sdf /SS2 - ss_48tcps.sdf /SS2 - ss_48tcps.sdf /SS2 - ss_48tcps.sdf /SS2 - ref.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - ref_48tcps.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - ref_24tcps_12fps.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - ref_12fps.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - -Time Offsets: - root_24tcps_12fps.sdf /SS2 root (offset=0.00, scale=1.00) - s.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_48tcps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_24tcps_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - ref.sdf /Ref reference (offset=70.00, scale=8.00) - ref_48tcps.sdf /Ref reference (offset=70.00, scale=8.00) - ref_24tcps_12fps.sdf /Ref reference (offset=70.00, scale=8.00) - ref_12fps.sdf /Ref reference (offset=70.00, scale=8.00) - ------------------------------------------------------------------------- -Results for composing - -Prim Stack: - ss.sdf /SS1 - ss.sdf /SS1 - ss.sdf /SS1 - ss.sdf /SS1 - ref.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - ref_48tcps.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - ref_24tcps_12fps.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - ref_12fps.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - -Time Offsets: - root_24tcps_12fps.sdf /SS1 root (offset=0.00, scale=1.00) - s.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_48tcps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_24tcps_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - ref.sdf /Ref reference (offset=70.00, scale=8.00) - ref_48tcps.sdf /Ref reference (offset=70.00, scale=8.00) - ref_24tcps_12fps.sdf /Ref reference (offset=70.00, scale=8.00) - ref_12fps.sdf /Ref reference (offset=70.00, scale=8.00) - ------------------------------------------------------------------------- -Results for composing - -Prim Stack: - s_12fps.sdf /S4 - -Time Offsets: - root_24tcps_12fps.sdf /S4 root (offset=0.00, scale=1.00) - s.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_48tcps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_24tcps_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - ------------------------------------------------------------------------- -Results for composing - -Prim Stack: - s_24tcps_12fps.sdf /S3 - -Time Offsets: - root_24tcps_12fps.sdf /S3 root (offset=0.00, scale=1.00) - s.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_48tcps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_24tcps_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - ------------------------------------------------------------------------- -Results for composing - -Prim Stack: - s_48tcps.sdf /S2 - -Time Offsets: - root_24tcps_12fps.sdf /S2 root (offset=0.00, scale=1.00) - s.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_48tcps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_24tcps_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - ------------------------------------------------------------------------- -Results for composing - -Prim Stack: - s.sdf /S1 - -Time Offsets: - root_24tcps_12fps.sdf /S1 root (offset=0.00, scale=1.00) - s.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_48tcps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_24tcps_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - ------------------------------------------------------------------------- -Results for composing - -Prim Stack: - root_24tcps_12fps.sdf /Root - -Time Offsets: - root_24tcps_12fps.sdf /Root root (offset=0.00, scale=1.00) - s.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_48tcps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_24tcps_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - diff --git a/pxr/usd/pcp/testenv/testPcpMuseum_TimeCodesPerSecond.testenv/baseline/compositionResults_TimeCodesPerSecond4_Legacy.txt b/pxr/usd/pcp/testenv/testPcpMuseum_TimeCodesPerSecond.testenv/baseline/compositionResults_TimeCodesPerSecond4_Legacy.txt deleted file mode 100644 index 755e328558e..00000000000 --- a/pxr/usd/pcp/testenv/testPcpMuseum_TimeCodesPerSecond.testenv/baseline/compositionResults_TimeCodesPerSecond4_Legacy.txt +++ /dev/null @@ -1,395 +0,0 @@ -Loading @TimeCodesPerSecond/root_12fps.sdf@ - ------------------------------------------------------------------------- -Layer Stack: - root_12fps.sdf - s.sdf - ss.sdf - ss_48tcps.sdf - ss_24tcps_12fps.sdf - ss_12fps.sdf - s_48tcps.sdf - ss.sdf - ss_48tcps.sdf - ss_24tcps_12fps.sdf - ss_12fps.sdf - s_24tcps_12fps.sdf - ss.sdf - ss_48tcps.sdf - ss_24tcps_12fps.sdf - ss_12fps.sdf - s_12fps.sdf - ss.sdf - ss_48tcps.sdf - ss_24tcps_12fps.sdf - ss_12fps.sdf - ------------------------------------------------------------------------- -Results for composing - -Prim Stack: - ss_12fps.sdf /SS4 - ss_12fps.sdf /SS4 - ss_12fps.sdf /SS4 - ss_12fps.sdf /SS4 - ref.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - ref_48tcps.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - ref_24tcps_12fps.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - ref_12fps.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - -Time Offsets: - root_12fps.sdf /SS4 root (offset=0.00, scale=1.00) - s.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_48tcps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_24tcps_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - ref.sdf /Ref reference (offset=70.00, scale=8.00) - ref_48tcps.sdf /Ref reference (offset=70.00, scale=8.00) - ref_24tcps_12fps.sdf /Ref reference (offset=70.00, scale=8.00) - ref_12fps.sdf /Ref reference (offset=70.00, scale=8.00) - ------------------------------------------------------------------------- -Results for composing - -Prim Stack: - ss_24tcps_12fps.sdf /SS3 - ss_24tcps_12fps.sdf /SS3 - ss_24tcps_12fps.sdf /SS3 - ss_24tcps_12fps.sdf /SS3 - ref.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - ref_48tcps.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - ref_24tcps_12fps.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - ref_12fps.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - -Time Offsets: - root_12fps.sdf /SS3 root (offset=0.00, scale=1.00) - s.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_48tcps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_24tcps_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - ref.sdf /Ref reference (offset=70.00, scale=8.00) - ref_48tcps.sdf /Ref reference (offset=70.00, scale=8.00) - ref_24tcps_12fps.sdf /Ref reference (offset=70.00, scale=8.00) - ref_12fps.sdf /Ref reference (offset=70.00, scale=8.00) - ------------------------------------------------------------------------- -Results for composing - -Prim Stack: - ss_48tcps.sdf /SS2 - ss_48tcps.sdf /SS2 - ss_48tcps.sdf /SS2 - ss_48tcps.sdf /SS2 - ref.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - ref_48tcps.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - ref_24tcps_12fps.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - ref_12fps.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - -Time Offsets: - root_12fps.sdf /SS2 root (offset=0.00, scale=1.00) - s.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_48tcps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_24tcps_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - ref.sdf /Ref reference (offset=70.00, scale=8.00) - ref_48tcps.sdf /Ref reference (offset=70.00, scale=8.00) - ref_24tcps_12fps.sdf /Ref reference (offset=70.00, scale=8.00) - ref_12fps.sdf /Ref reference (offset=70.00, scale=8.00) - ------------------------------------------------------------------------- -Results for composing - -Prim Stack: - ss.sdf /SS1 - ss.sdf /SS1 - ss.sdf /SS1 - ss.sdf /SS1 - ref.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - ref_48tcps.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - ref_24tcps_12fps.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - ref_12fps.sdf /Ref - ref_s.sdf /Ref - ref_s_48tcps.sdf /Ref - ref_s_24tcps_12fps.sdf /Ref - ref_s_12fps.sdf /Ref - -Time Offsets: - root_12fps.sdf /SS1 root (offset=0.00, scale=1.00) - s.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_48tcps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_24tcps_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - ref.sdf /Ref reference (offset=70.00, scale=8.00) - ref_48tcps.sdf /Ref reference (offset=70.00, scale=8.00) - ref_24tcps_12fps.sdf /Ref reference (offset=70.00, scale=8.00) - ref_12fps.sdf /Ref reference (offset=70.00, scale=8.00) - ------------------------------------------------------------------------- -Results for composing - -Prim Stack: - s_12fps.sdf /S4 - -Time Offsets: - root_12fps.sdf /S4 root (offset=0.00, scale=1.00) - s.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_48tcps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_24tcps_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - ------------------------------------------------------------------------- -Results for composing - -Prim Stack: - s_24tcps_12fps.sdf /S3 - -Time Offsets: - root_12fps.sdf /S3 root (offset=0.00, scale=1.00) - s.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_48tcps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_24tcps_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - ------------------------------------------------------------------------- -Results for composing - -Prim Stack: - s_48tcps.sdf /S2 - -Time Offsets: - root_12fps.sdf /S2 root (offset=0.00, scale=1.00) - s.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_48tcps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_24tcps_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - ------------------------------------------------------------------------- -Results for composing - -Prim Stack: - s.sdf /S1 - -Time Offsets: - root_12fps.sdf /S1 root (offset=0.00, scale=1.00) - s.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_48tcps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_24tcps_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - ------------------------------------------------------------------------- -Results for composing - -Prim Stack: - root_12fps.sdf /Root - -Time Offsets: - root_12fps.sdf /Root root (offset=0.00, scale=1.00) - s.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_48tcps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_24tcps_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - s_12fps.sdf sublayer (offset=10.00, scale=2.00) - ss.sdf sublayer (offset=30.00, scale=4.00) - ss_48tcps.sdf sublayer (offset=30.00, scale=4.00) - ss_24tcps_12fps.sdf sublayer (offset=30.00, scale=4.00) - ss_12fps.sdf sublayer (offset=30.00, scale=4.00) - diff --git a/pxr/usd/plugin/sdrOsl/pch.h b/pxr/usd/plugin/sdrOsl/pch.h index d13d8567098..3de99114642 100644 --- a/pxr/usd/plugin/sdrOsl/pch.h +++ b/pxr/usd/plugin/sdrOsl/pch.h @@ -64,6 +64,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/pxr/usd/plugin/usdAbc/pch.h b/pxr/usd/plugin/usdAbc/pch.h index 96df9137973..8611200586e 100644 --- a/pxr/usd/plugin/usdAbc/pch.h +++ b/pxr/usd/plugin/usdAbc/pch.h @@ -113,6 +113,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/pxr/usd/plugin/usdDraco/pch.h b/pxr/usd/plugin/usdDraco/pch.h index 38717936785..096c66376a6 100644 --- a/pxr/usd/plugin/usdDraco/pch.h +++ b/pxr/usd/plugin/usdDraco/pch.h @@ -72,6 +72,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/pxr/usd/sdf/listOp.cpp b/pxr/usd/sdf/listOp.cpp index 8a31c5adb46..1bb19a08386 100644 --- a/pxr/usd/sdf/listOp.cpp +++ b/pxr/usd/sdf/listOp.cpp @@ -160,12 +160,35 @@ SdfListOp::GetAppliedItems() const return result; } +template +std::vector _MakeUnique(const std::vector items, bool reverse=false) +{ + TfDenseHashSet existingSet; + std::vector uniqueItems; + + if (reverse) { + for (auto it = items.rbegin(); it != items.rend(); it++) { + if (existingSet.insert(*it).second) { + uniqueItems.push_back(*it); + } + } + std::reverse(uniqueItems.begin(), uniqueItems.end()); + } else { + for (auto it = items.cbegin(); it != items.cend(); it++) { + if (existingSet.insert(*it).second) { + uniqueItems.push_back(*it); + } + } + } + return uniqueItems; +} + template void SdfListOp::SetExplicitItems(const ItemVector &items) { _SetExplicit(true); - _explicitItems = items; + _explicitItems = _MakeUnique(items); } template @@ -181,7 +204,7 @@ void SdfListOp::SetPrependedItems(const ItemVector &items) { _SetExplicit(false); - _prependedItems = items; + _prependedItems = _MakeUnique(items); } template @@ -189,7 +212,7 @@ void SdfListOp::SetAppendedItems(const ItemVector &items) { _SetExplicit(false); - _appendedItems = items; + _appendedItems = _MakeUnique(items, true); } template @@ -197,7 +220,7 @@ void SdfListOp::SetDeletedItems(const ItemVector &items) { _SetExplicit(false); - _deletedItems = items; + _deletedItems = _MakeUnique(items); } template @@ -312,11 +335,11 @@ SdfListOp::ApplyOperations(ItemVector* vec, const ApplyCallback& cb) const search[*i] = i; } - _DeleteKeys (SdfListOpTypeDeleted, cb, &result, &search); + _DeleteKeys (cb, &result, &search); _AddKeys(SdfListOpTypeAdded, cb, &result, &search); - _PrependKeys(SdfListOpTypePrepended, cb, &result, &search); - _AppendKeys(SdfListOpTypeAppended, cb, &result, &search); - _ReorderKeys(SdfListOpTypeOrdered, cb, &result, &search); + _PrependKeys(cb, &result, &search); + _AppendKeys(cb, &result, &search); + _ReorderKeys(cb, &result, &search); } // Copy the result back to vec. @@ -463,15 +486,14 @@ SdfListOp::_AddKeys( template void SdfListOp::_PrependKeys( - SdfListOpType op, const ApplyCallback& callback, _ApplyList* result, _ApplyMap* search) const { - const ItemVector& items = GetItems(op); + const ItemVector& items = GetItems(SdfListOpTypePrepended); if (callback) { for (auto i = items.rbegin(), iEnd = items.rend(); i != iEnd; ++i) { - if (std::optional mappedItem = callback(op, *i)) { + if (std::optional mappedItem = callback(SdfListOpTypePrepended, *i)) { _InsertOrMove(*mappedItem, result->begin(), result, search); } } @@ -485,15 +507,14 @@ SdfListOp::_PrependKeys( template void SdfListOp::_AppendKeys( - SdfListOpType op, const ApplyCallback& callback, _ApplyList* result, _ApplyMap* search) const { - const ItemVector& items = GetItems(op); + const ItemVector& items = GetItems(SdfListOpTypeAppended); if (callback) { for (const T& item: items) { - if (std::optional mappedItem = callback(op, item)) { + if (std::optional mappedItem = callback(SdfListOpTypeAppended, item)) { _InsertOrMove(*mappedItem, result->end(), result, search); } } @@ -507,14 +528,13 @@ SdfListOp::_AppendKeys( template void SdfListOp::_DeleteKeys( - SdfListOpType op, const ApplyCallback& callback, _ApplyList* result, _ApplyMap* search) const { - TF_FOR_ALL(i, GetItems(op)) { + TF_FOR_ALL(i, GetItems(SdfListOpTypeDeleted)) { if (callback) { - if (std::optional item = callback(op, *i)) { + if (std::optional item = callback(SdfListOpTypeDeleted, *i)) { _RemoveIfPresent(*item, result, search); } } @@ -527,29 +547,36 @@ SdfListOp::_DeleteKeys( template void SdfListOp::_ReorderKeys( - SdfListOpType op, const ApplyCallback& callback, _ApplyList* result, _ApplyMap* search) const { + _ReorderKeysHelper(GetItems(SdfListOpTypeOrdered), callback, result, search); +} + +template +void +SdfListOp::_ReorderKeysHelper(ItemVector order, const ApplyCallback& callback, + _ApplyList* result, _ApplyMap* search) { + // Make a vector and set of the source items. - ItemVector order; + ItemVector uniqueOrder; std::set orderSet; - TF_FOR_ALL(i, GetItems(op)) { + TF_FOR_ALL(i, order) { if (callback) { - if (std::optional item = callback(op, *i)) { + if (std::optional item = callback(SdfListOpTypeOrdered, *i)) { if (orderSet.insert(*item).second) { - order.push_back(*item); + uniqueOrder.push_back(*item); } } } else { if (orderSet.insert(*i).second) { - order.push_back(*i); + uniqueOrder.push_back(*i); } } } - if (order.empty()) { + if (uniqueOrder.empty()) { return; } @@ -559,9 +586,9 @@ SdfListOp::_ReorderKeys( // Find each item from the order vector in the scratch list. // Then find the next item in the scratch list that's also in - // in the order vector. All of these items except the last + // in the uniqueOrder vector. All of these items except the last // form the next continuous sequence in the result. - TF_FOR_ALL(i, order) { + TF_FOR_ALL(i, uniqueOrder) { typename _ApplyMap::const_iterator j = search->find(*i); if (j != search->end()) { // Find the next item in both scratch and order. @@ -585,16 +612,17 @@ template static inline bool _ModifyCallbackHelper(const typename SdfListOp::ModifyCallback& cb, - std::vector* itemVector, bool removeDuplicates) + std::vector* itemVector) { bool didModify = false; std::vector modifiedVector; + modifiedVector.reserve(itemVector->size()); TfDenseHashSet existingSet; for (const T& item : *itemVector) { std::optional modifiedItem = cb(item); - if (removeDuplicates && modifiedItem) { + if (modifiedItem) { if (!existingSet.insert(*modifiedItem).second) { modifiedItem = std::nullopt; } @@ -620,29 +648,36 @@ _ModifyCallbackHelper(const typename SdfListOp::ModifyCallback& cb, template bool -SdfListOp::ModifyOperations(const ModifyCallback& callback, - bool removeDuplicates) +SdfListOp::ModifyOperations(const ModifyCallback& callback) { bool didModify = false; if (callback) { didModify |= _ModifyCallbackHelper( - callback, &_explicitItems, removeDuplicates); + callback, &_explicitItems); didModify |= _ModifyCallbackHelper( - callback, &_addedItems, removeDuplicates); + callback, &_addedItems); didModify |= _ModifyCallbackHelper( - callback, &_prependedItems, removeDuplicates); + callback, &_prependedItems); didModify |= _ModifyCallbackHelper( - callback, &_appendedItems, removeDuplicates); + callback, &_appendedItems); didModify |= _ModifyCallbackHelper( - callback, &_deletedItems, removeDuplicates); + callback, &_deletedItems); didModify |= _ModifyCallbackHelper( - callback, &_orderedItems, removeDuplicates); + callback, &_orderedItems); } return didModify; } +template +bool +SdfListOp::ModifyOperations(const ModifyCallback& callback, + bool unusedRemoveDuplicates) +{ + return ModifyOperations(callback); +} + template bool SdfListOp::ReplaceOperations(const SdfListOpType op, size_t index, size_t n, @@ -713,7 +748,7 @@ SdfListOp::ComposeOperations(const SdfListOp& stronger, SdfListOpType op) if (op == SdfListOpTypeOrdered) { stronger._AddKeys(op, ApplyCallback(), &weakerList, &weakerSearch); - stronger._ReorderKeys(op, ApplyCallback(), + stronger._ReorderKeys(ApplyCallback(), &weakerList, &weakerSearch); } else if (op == SdfListOpTypeAdded) { stronger._AddKeys(op, @@ -726,13 +761,11 @@ SdfListOp::ComposeOperations(const SdfListOp& stronger, SdfListOpType op) &weakerList, &weakerSearch); } else if (op == SdfListOpTypePrepended) { - stronger._PrependKeys(op, - ApplyCallback(), + stronger._PrependKeys(ApplyCallback(), &weakerList, &weakerSearch); } else if (op == SdfListOpTypeAppended) { - stronger._AppendKeys(op, - ApplyCallback(), + stronger._AppendKeys(ApplyCallback(), &weakerList, &weakerSearch); } @@ -749,10 +782,24 @@ void SdfApplyListOrdering(std::vector* v, const std::vector& order) { if (!order.empty() && !v->empty()) { - // XXX: This is lame, but just for now... - SdfListOp tmp; - tmp.SetOrderedItems(order); - tmp.ApplyOperations(v); + // Make a list of the inputs. We can efficiently (O(1)) splice + // these elements later. + typename SdfListOp::_ApplyList result; + result.insert(result.end(), v->begin(), v->end()); + + // Make a map of keys to list iterators. This avoids O(n) + // searches within O(n) loops below. + typename SdfListOp::_ApplyMap search; + typename SdfListOp::_ApplyList::iterator i = result.begin(); + for (; + i != result.end(); ++i) { + search[*i] = i; + } + SdfListOp::_ReorderKeysHelper(order, nullptr, &result, &search); + + // Copy the result back to vec. + v->clear(); + v->insert(v->end(), result.begin(), result.end()); } } diff --git a/pxr/usd/sdf/listOp.h b/pxr/usd/sdf/listOp.h index 19b24e087c5..e930674a780 100644 --- a/pxr/usd/sdf/listOp.h +++ b/pxr/usd/sdf/listOp.h @@ -48,11 +48,23 @@ struct Sdf_ListOpTraits /// \class SdfListOp /// -/// Value type representing a list-edit operation. -/// /// SdfListOp is a value type representing an operation that edits a list. -/// It may add or remove items, reorder them, or replace the list entirely. +/// It may append or prepend items, delete them, or replace the list entirely. +/// +/// SdfListOp maintains lists of items to be prepended, appended, deleted, or +/// used explicitly. If used in explicit mode, the ApplyOperations method replaces the given list +/// with the set explicit items. Otherwise, the ApplyOperations +/// method is used to apply the list-editing options in the input list in the +/// following order: +/// - Delete +/// - Prepend +/// - Append /// +/// Lists are meant to contain unique values, and all list operations +/// will remove duplicates if encountered. Prepending items and using +/// explicit mode will preserve the position of the first of the duplicates +/// to be encountered, while appending items will preserve the last. + template class SdfListOp { public: @@ -111,12 +123,6 @@ class SdfListOp { return _explicitItems; } - /// Returns the explicit items. - const ItemVector& GetAddedItems() const - { - return _addedItems; - } - /// Returns the explicit items. const ItemVector& GetPrependedItems() const { @@ -135,12 +141,6 @@ class SdfListOp { return _deletedItems; } - /// Returns the ordered items. - const ItemVector& GetOrderedItems() const - { - return _orderedItems; - } - /// Return the item vector identified by \p type. SDF_API const ItemVector& GetItems(SdfListOpType type) const; @@ -152,14 +152,24 @@ class SdfListOp { /// This is equivalent to calling ApplyOperations on an empty item vector. SDF_API ItemVector GetAppliedItems() const; + /// Sets the explicit items. If duplicates are present in \p items, + /// preserves the first occurence. SDF_API void SetExplicitItems(const ItemVector &items); - SDF_API void SetAddedItems(const ItemVector &items); + + /// Sets the prepended items. If duplicates are present in \p items, + /// preserves the first occurence. SDF_API void SetPrependedItems(const ItemVector &items); + + /// Sets the appended items. If duplicates are present in \p items, + /// preserves the last occurence. SDF_API void SetAppendedItems(const ItemVector &items); + + /// Sets the deleted items. If duplicates are present in \p items, + /// preserves the first occurence. SDF_API void SetDeletedItems(const ItemVector &items); - SDF_API void SetOrderedItems(const ItemVector &items); /// Sets the item vector for the given operation \p type. + /// Removes duplicates in \p items if present. SDF_API void SetItems(const ItemVector &items, SdfListOpType type); /// Removes all items and changes the list to be non-explicit. @@ -206,14 +216,19 @@ class SdfListOp { /// returned key is empty then the key is removed, otherwise it's replaced /// with the returned key. /// - /// If \p removeDuplicates is \c true and \p callback returns a key that was - /// previously returned for the current operation vector being processed, - /// the returned key will be removed. + /// If \p callback returns a key that was previously returned for the + /// current operation vector being processed, the returned key will be + /// removed. /// /// Returns true if a change was made, false otherwise. SDF_API + bool ModifyOperations(const ModifyCallback& callback); + + /// \deprecated Please use ModifyOperations(const ModifyCallback& callback) + /// instead. + SDF_API bool ModifyOperations(const ModifyCallback& callback, - bool removeDuplicates = false); + bool unusedRemoveDuplicates); /// Replaces the items in the specified operation vector in the range /// (index, index + n] with the given \p newItems. If \p newItems is empty @@ -227,6 +242,27 @@ class SdfListOp { SDF_API void ComposeOperations(const SdfListOp& stronger, SdfListOpType op); + /// \deprecated The add and reorder operations have been deprecated in favor + /// of the append and prepend operations. + const ItemVector& GetAddedItems() const + { + return _addedItems; + } + + /// \deprecated The add and reorder operations have been deprecated in favor + /// of the append and prepend operations. + const ItemVector& GetOrderedItems() const + { + return _orderedItems; + } + /// \deprecated The add and reorder operations have been deprecated in favor + /// of the append and prepend operations. + SDF_API void SetAddedItems(const ItemVector &items); + + /// \deprecated The add and reorder operations have been deprecated in favor + /// of the append and prepend operations. + SDF_API void SetOrderedItems(const ItemVector &items); + friend inline size_t hash_value(const SdfListOp &op) { return TfHash::Combine( op._isExplicit, @@ -261,16 +297,27 @@ class SdfListOp { typedef std::map _ApplyMap; - void _AddKeys(SdfListOpType, const ApplyCallback& cb, - _ApplyList* result, _ApplyMap* search) const; - void _PrependKeys(SdfListOpType, const ApplyCallback& cb, + void _PrependKeys(const ApplyCallback& cb, _ApplyList* result, _ApplyMap* search) const; - void _AppendKeys(SdfListOpType, const ApplyCallback& cb, + void _AppendKeys(const ApplyCallback& cb, _ApplyList* result, _ApplyMap* search) const; - void _DeleteKeys(SdfListOpType, const ApplyCallback& cb, + void _DeleteKeys(const ApplyCallback& cb, _ApplyList* result, _ApplyMap* search) const; - void _ReorderKeys(SdfListOpType, const ApplyCallback& cb, + + /// \deprecated + /// Use _PrependKeys or _AppendKeys instead. + void _AddKeys(SdfListOpType, const ApplyCallback& cb, + _ApplyList* result, _ApplyMap* search) const; + + /// \deprecated + /// Use _PrependKeys or _AppendKeys instead. + void _ReorderKeys(const ApplyCallback& cb, _ApplyList* result, _ApplyMap* search) const; + static void _ReorderKeysHelper(ItemVector order, const ApplyCallback& cb, + _ApplyList *result, _ApplyMap *search); + template + friend void SdfApplyListOrdering(std::vector *v, + const std::vector &order); private: bool _isExplicit; diff --git a/pxr/usd/sdf/listOpListEditor.h b/pxr/usd/sdf/listOpListEditor.h index 3e1a3740b61..8856daf18bc 100644 --- a/pxr/usd/sdf/listOpListEditor.h +++ b/pxr/usd/sdf/listOpListEditor.h @@ -238,7 +238,7 @@ Sdf_ListOpListEditor::ModifyItemEdits(const ModifyCallback& cb) modifiedListOp.ModifyOperations( [this, &cb](const value_type &t) { return _ModifyCallbackHelper(cb, _GetTypePolicy(), t); - }, /* removeDuplicates = */ true); + }); _UpdateListOp(modifiedListOp); } diff --git a/pxr/usd/sdf/pch.h b/pxr/usd/sdf/pch.h index 22d1798dde0..fbbb06112a0 100644 --- a/pxr/usd/sdf/pch.h +++ b/pxr/usd/sdf/pch.h @@ -94,6 +94,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/pxr/usd/sdf/testenv/testSdfAttribute.py b/pxr/usd/sdf/testenv/testSdfAttribute.py index d6cee7e166f..c4cf5888d60 100644 --- a/pxr/usd/sdf/testenv/testSdfAttribute.py +++ b/pxr/usd/sdf/testenv/testSdfAttribute.py @@ -315,12 +315,11 @@ def test_Connections(self): self.assertTrue( testPath_dead not in attr.connectionPathList.explicitItems) - # adding duplicate connection path: error expected + # adding duplicate connection path testPath = attr.connectionPathList.explicitItems[0] self.assertEqual( attr.connectionPathList.explicitItems.count(testPath), 1) - with self.assertRaises(Tf.ErrorException): - attr.connectionPathList.explicitItems.append(testPath) + attr.connectionPathList.explicitItems.append(testPath) self.assertEqual( attr.connectionPathList.explicitItems.count(testPath), 1) diff --git a/pxr/usd/sdf/testenv/testSdfListOp.py b/pxr/usd/sdf/testenv/testSdfListOp.py index 9cec8858ff5..5a9a2674fd6 100644 --- a/pxr/usd/sdf/testenv/testSdfListOp.py +++ b/pxr/usd/sdf/testenv/testSdfListOp.py @@ -59,8 +59,30 @@ def test_BasicSemantics(self): _ExplicitItems([1,2,3]) .ApplyOperations([0,3]), [1,2,3]) + self.assertEqual( + _ExplicitItems([1,2,1,3]) + .ApplyOperations([]), + [1,2,3]) - # "Add" leaves existing values in place and appends any new values. + # Ensure duplicates are removed when using setter methods. + self.assertEqual( + _ExplicitItems([1,2,1,3]) + .explicitItems, + [1,2,3]) + self.assertEqual( + _DeletedItems([1,2,1,3]) + .deletedItems, + [1,2,3]) + self.assertEqual( + _AppendedItems([1,2,1,3]) + .appendedItems, + [2,1,3]) + self.assertEqual( + _PrependedItems([1,2,1,3]) + .prependedItems, + [1,2,3]) + + # (deprecated)"Add" leaves existing values in place and appends any new values. self.assertEqual( _AddedItems([1,2,3]) .ApplyOperations([]), @@ -102,6 +124,10 @@ def test_BasicSemantics(self): _AppendedItems([1,2,3]) .ApplyOperations([3,4]), [4,1,2,3]) + self.assertEqual( + _AppendedItems([1,2,1,3]) + .ApplyOperations([]), + [2,1,3]) # "Prepend" is similar, but for the front of the list. self.assertEqual( @@ -116,8 +142,12 @@ def test_BasicSemantics(self): _PrependedItems([1,2,3]) .ApplyOperations([0,1]), [1,2,3,0]) + self.assertEqual( + _PrependedItems([1,2,1,3]) + .ApplyOperations([]), + [1,2,3]) - # "Order" is the most subtle. + # (deprecated) "Order" is the most subtle. self.assertEqual( _OrderedItems([1,2,3]) .ApplyOperations([]), diff --git a/pxr/usd/sdf/vectorListEditor.h b/pxr/usd/sdf/vectorListEditor.h index 2403175b004..ee45d63785f 100644 --- a/pxr/usd/sdf/vectorListEditor.h +++ b/pxr/usd/sdf/vectorListEditor.h @@ -256,7 +256,7 @@ Sdf_VectorListEditor::ModifyItemEdits(const ModifyCallback& cb) valueListOp.ModifyOperations( [this, &cb](const value_type &t) { return _ModifyCallbackHelper(cb, _GetTypePolicy(), t); - }, /* removeDuplicates = */ true); + }); _UpdateFieldData(valueListOp.GetItems(_op)); } diff --git a/pxr/usd/sdr/pch.h b/pxr/usd/sdr/pch.h index a2df6b79504..37c417c9d1e 100644 --- a/pxr/usd/sdr/pch.h +++ b/pxr/usd/sdr/pch.h @@ -69,6 +69,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/pxr/usd/usd/CMakeLists.txt b/pxr/usd/usd/CMakeLists.txt index 2915831ddc3..02793db9408 100644 --- a/pxr/usd/usd/CMakeLists.txt +++ b/pxr/usd/usd/CMakeLists.txt @@ -146,6 +146,7 @@ pxr_library(usd wrapTimeCode.cpp wrapUsdFileFormat.cpp wrapUtils.cpp + wrapValidationContext.cpp wrapValidationError.cpp wrapValidationRegistry.cpp wrapValidator.cpp @@ -234,8 +235,13 @@ pxr_test_scripts( testenv/testUsdMetadata.py testenv/testUsdModel.py testenv/testUsdNamespaceEditor.py + testenv/testUsdNamespaceEditorDependentEditsBase.py:testUsdNamespaceEditorDependentEditsBase.py + testenv/testUsdNamespaceEditorDependentEditsBasicReferencesAndPayloads.py + testenv/testUsdNamespaceEditorDependentEditsBasicSublayers.py testenv/testUsdNamespaceEditorProperties.py + testenv/testUsdNamespaceEditorTargetPathFixup.py testenv/testUsdNotices.py + testenv/testUsdObjectsChangedNotices.py testenv/testUsdOpaqueAttributes.py testenv/testUsdPathExpressionAttrs.py testenv/testUsdPayloads.py @@ -263,6 +269,7 @@ pxr_test_scripts( testenv/testUsdTimeSamples.py testenv/testUsdTimeValueAuthoring.py testenv/testUsdUsdzFileFormat.py + testenv/testUsdValidationContextPy.py testenv/testUsdValidationError.py testenv/testUsdValidationRegistryPy.py testenv/testUsdValidatorMetadata.py @@ -295,6 +302,16 @@ pxr_build_test_shared_lib(TestUsdResolverChangedResolver testenv/TestUsdResolverChangedResolver.cpp ) +pxr_build_test_shared_lib(TestUsdValidationContextValidators + INSTALL_PREFIX UsdPlugins + LIBRARIES + tf + usd + + CPPFILES + testenv/testUsdValidationContextValidators.cpp +) + pxr_build_test_shared_lib(TestUsdValidationRegistryPy INSTALL_PREFIX UsdPlugins LIBRARIES @@ -661,6 +678,11 @@ pxr_install_test_dir( DEST testUsdNamespaceEditorProperties ) +pxr_install_test_dir( + SRC testenv/testUsdNamespaceEditorTargetPathFixup + DEST testUsdNamespaceEditorTargetPathFixup +) + pxr_install_test_dir( SRC testenv/testUsdPrims.testenv DEST testUsdPrims @@ -786,6 +808,11 @@ pxr_install_test_dir( DEST testUsdValidationContext ) +pxr_install_test_dir( + SRC testenv/testUsdValidationContext + DEST testUsdValidationContextPy +) + pxr_install_test_dir( SRC testenv/testUsdValidationRegistry DEST testUsdValidationRegistry @@ -1051,24 +1078,24 @@ pxr_register_test(testUsdValidator EXPECTED_RETURN_CODE 0 ) -pxr_register_test(testUsdValidationContext - COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testUsdValidationContext" - EXPECTED_RETURN_CODE 0 -) - pxr_register_test(testUsdValidationRegistry COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testUsdValidationRegistry" EXPECTED_RETURN_CODE 0 ) -# This test relies on a plugin built specifically for this test. -# The build system currently doesn't support this for static library -# builds, so we only enable this test on shared library builds. +#The following tests rely on plugins built specifically for them. +#The build system currently doesn't support test-specific plugins +#for static library builds, so we only enable these tests for +#shared library builds. if (BUILD_SHARED_LIBS) pxr_register_test(testUsdResolverChanged COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testUsdResolverChanged" EXPECTED_RETURN_CODE 0 ) + pxr_register_test(testUsdValidationContext + COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testUsdValidationContext" + EXPECTED_RETURN_CODE 0 + ) endif() pxr_register_test(testUsdStageNoPython @@ -1120,8 +1147,6 @@ pxr_register_test(testUsdTimeOffsets PYTHON COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testUsdTimeOffsets" EXPECTED_RETURN_CODE 0 - ENV - PCP_DISABLE_TIME_SCALING_BY_LAYER_TCPS=0 ) pxr_register_test(testUsdPrimRange @@ -1261,18 +1286,42 @@ pxr_register_test(testUsdNotices EXPECTED_RETURN_CODE 0 ) +pxr_register_test(testUsdObjectsChangedNotices + PYTHON + COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testUsdObjectsChangedNotices" + EXPECTED_RETURN_CODE 0 +) + pxr_register_test(testUsdNamespaceEditor PYTHON COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testUsdNamespaceEditor" EXPECTED_RETURN_CODE 0 ) +pxr_register_test(testUsdNamespaceEditorDependentEditsBasicReferencesAndPayloads + PYTHON + COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testUsdNamespaceEditorDependentEditsBasicReferencesAndPayloads" + EXPECTED_RETURN_CODE 0 +) + +pxr_register_test(testUsdNamespaceEditorDependentEditsBasicSublayers + PYTHON + COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testUsdNamespaceEditorDependentEditsBasicSublayers" + EXPECTED_RETURN_CODE 0 +) + pxr_register_test(testUsdNamespaceEditorProperties PYTHON COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testUsdNamespaceEditorProperties" EXPECTED_RETURN_CODE 0 ) +pxr_register_test(testUsdNamespaceEditorTargetPathFixup + PYTHON + COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testUsdNamespaceEditorTargetPathFixup" + EXPECTED_RETURN_CODE 0 +) + pxr_register_test(testUsdReadOutOfBounds PYTHON COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testUsdReadOutOfBounds" @@ -1323,15 +1372,11 @@ pxr_register_test(testUsdTimeValueAuthoring PYTHON COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testUsdTimeValueAuthoring" EXPECTED_RETURN_CODE 0 - ENV - PCP_DISABLE_TIME_SCALING_BY_LAYER_TCPS=0 ) pxr_register_test(testUsdTimeValueAuthoringCpp COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testUsdTimeValueAuthoringCpp" EXPECTED_RETURN_CODE 0 - ENV - PCP_DISABLE_TIME_SCALING_BY_LAYER_TCPS=0 ) pxr_register_test(testUsdUsdzFileFormat @@ -1390,11 +1435,18 @@ pxr_register_test(testUsdValidationError EXPECTED_RETURN_CODE 0 ) +pxr_register_test(testUsdValidationContextPy + PYTHON + COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testUsdValidationContextPy" + EXPECTED_RETURN_CODE 0 +) + pxr_register_test(testUsdValidationRegistryPy PYTHON COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testUsdValidationRegistryPy" EXPECTED_RETURN_CODE 0 ) + pxr_register_test(testUsdUsdzBugGHSA01 COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testUsdUsdzBugGHSA01" EXPECTED_RETURN_CODE 0 diff --git a/pxr/usd/usd/codegenTemplates/schemaClass.cpp b/pxr/usd/usd/codegenTemplates/schemaClass.cpp index 885c8a05ece..19b072ec39f 100644 --- a/pxr/usd/usd/codegenTemplates/schemaClass.cpp +++ b/pxr/usd/usd/codegenTemplates/schemaClass.cpp @@ -22,12 +22,16 @@ TF_REGISTRY_FUNCTION(TfType) TfType::Bases< {{ cls.parentCppClassName }} > >(); {% if cls.isConcrete %} +{% if cls.cppClassName != cls.usdPrimTypeName %} // Register the usd prim typename as an alias under UsdSchemaBase. This // enables one to call // TfType::Find().FindDerivedByName("{{ cls.usdPrimTypeName }}") // to find TfType<{{ cls.cppClassName }}>, which is how IsA queries are // answered. TfType::AddAlias("{{ cls.usdPrimTypeName }}"); +{% else %} + // Skip registering an alias as it would be the same as the class name. +{% endif %} {% endif %} } diff --git a/pxr/usd/usd/module.cpp b/pxr/usd/usd/module.cpp index 544ffacfcfc..c68763c61b6 100644 --- a/pxr/usd/usd/module.cpp +++ b/pxr/usd/usd/module.cpp @@ -37,6 +37,7 @@ TF_WRAP_MODULE TF_WRAP(UsdSpecializes); TF_WRAP(UsdPrimRange); TF_WRAP(UsdVariantSets); + TF_WRAP(UsdValidationContext); TF_WRAP(UsdValidationError); TF_WRAP(UsdValidationRegistry); TF_WRAP(UsdValidator); diff --git a/pxr/usd/usd/namespaceEditor.cpp b/pxr/usd/usd/namespaceEditor.cpp index ff2187a4dfd..922df3f5a43 100644 --- a/pxr/usd/usd/namespaceEditor.cpp +++ b/pxr/usd/usd/namespaceEditor.cpp @@ -294,6 +294,31 @@ UsdNamespaceEditor::UsdNamespaceEditor( { } +void +UsdNamespaceEditor::AddDependentStage(const UsdStageRefPtr &stage) +{ + if (!stage || stage == _stage) { + return; + } + _ClearProcessedEdits(); + _dependentStages.insert(stage); +} + +void +UsdNamespaceEditor::RemoveDependentStage(const UsdStageRefPtr &stage) +{ + _ClearProcessedEdits(); + _dependentStages.erase(stage); +} + +void +UsdNamespaceEditor::SetDependentStages(const UsdStageRefPtrVector &stages) +{ + for (const auto &stage : stages) { + AddDependentStage(stage); + } +} + bool UsdNamespaceEditor::DeletePrimAtPath( const SdfPath &path) @@ -560,12 +585,14 @@ class UsdNamespaceEditor::_EditProcessor { // Creates a processed edit from an edit description. static UsdNamespaceEditor::_ProcessedEdit ProcessEdit( const UsdStageRefPtr &stage, + const _StageSet &dependentStages, const UsdNamespaceEditor::_EditDescription &editDesc, const UsdNamespaceEditor::EditOptions &editOptions); private: _EditProcessor( const UsdStageRefPtr &stage, + const _StageSet &_dependentStages, const UsdNamespaceEditor::_EditDescription &editDesc, const UsdNamespaceEditor::EditOptions &editOptions, _ProcessedEdit *processedEdit); @@ -581,8 +608,11 @@ class UsdNamespaceEditor::_EditProcessor { void _GatherLayersToEdit(); void _GatherTargetListOpEdits(); - + + void _GatherDependentStageEdits(); + const UsdStageRefPtr & _stage; + const _StageSet &_dependentStages; const UsdNamespaceEditor::_EditDescription & _editDesc; const UsdEditTarget &_editTarget; const UsdNamespaceEditor::EditOptions & _editOptions; @@ -601,7 +631,7 @@ UsdNamespaceEditor::_ProcessEditsIfNeeded() const return; } _processedEdit = UsdNamespaceEditor::_EditProcessor::ProcessEdit( - _stage, _editDescription, _editOptions); + _stage, _dependentStages, _editDescription, _editOptions); } static @@ -747,20 +777,23 @@ _IsValidNewParentPath( UsdNamespaceEditor::_ProcessedEdit UsdNamespaceEditor::_EditProcessor::ProcessEdit( const UsdStageRefPtr &stage, + const _StageSet &dependentStages, const _EditDescription &editDesc, const EditOptions &editOptions) { _ProcessedEdit processedEdit; - _EditProcessor(stage, editDesc, editOptions, &processedEdit); + _EditProcessor(stage, dependentStages, editDesc, editOptions, &processedEdit); return processedEdit; } UsdNamespaceEditor::_EditProcessor::_EditProcessor( const UsdStageRefPtr &stage, + const _StageSet &dependentStages, const UsdNamespaceEditor::_EditDescription &editDesc, const UsdNamespaceEditor::EditOptions &editOptions, _ProcessedEdit *processedEdit) : _stage(stage) + , _dependentStages(dependentStages) , _editDesc(editDesc) , _editTarget(stage->GetEditTarget()) , _editOptions(editOptions) @@ -771,11 +804,8 @@ UsdNamespaceEditor::_EditProcessor::_EditProcessor( return; } - // Add the edit to the processed SdfBatchNamespaceEdit. We use the index of - // "Same" specifically so renames don't move the object (it has no effect - // for any edits other than rename) - _processedEdit->edits.Add( - editDesc.oldPath, editDesc.newPath, SdfNamespaceEdit::Same); + // Copy the edit description. + _processedEdit->editDescription = _editDesc; // Validate whether the stage has the prim or property at the original path // that can be namespace edited. @@ -813,6 +843,10 @@ UsdNamespaceEditor::_EditProcessor::_EditProcessor( // to be edited when the edits are applied. _GatherLayersToEdit(); + // Gather all edits that need to be performed on dependent stages for prim + // indexes that would be affected by the initial layer edits. + _GatherDependentStageEdits(); + // Gather all the edits that need to be made to target path listOps in // property specs in order to "fix up" properties that have connections or // relationship targets targeting the namespace edited object. @@ -837,19 +871,12 @@ UsdNamespaceEditor::_EditProcessor::_ProcessNewPath() // For reparenting we have additional behaviors and validation to perform. if (_editDesc.editType == _EditType::Reparent) { - // For each layer we edit, we may need to create new overs for the new - // parent path and delete inert ancestor overs after moving a prim or - // property from its original parent, so add this info to the processed - // edit. - _processedEdit->createParentSpecIfNeededPath = - _editDesc.newPath.GetParentPath(); - _processedEdit->removeInertAncestorOvers = true; // Validate that the stage does have a prim at the new parent path to // reparent to. std::string whyNot; if (!_IsValidNewParentPath(_stage, _editDesc.oldPath, - _processedEdit->createParentSpecIfNeededPath, &whyNot)) { + _editDesc.newPath.GetParentPath(), &whyNot)) { _processedEdit->errors.push_back(std::move(whyNot)); return false; } @@ -966,16 +993,9 @@ UsdNamespaceEditor::_EditProcessor::_ProcessPrimEditRequiresRelocates( return; } - // Otherwise, use the relocates builder to get all the relocates metadata - // that needs to be authored in each layer to move old path to new path. - PcpLayerRelocatesEditBuilder builder( - _nodeForEditTarget.GetLayerStack(), _editTarget.GetLayer()); - std::string error; - if (!builder.Relocate(_editDesc.oldPath, _editDesc.newPath, &error)) { - TF_CODING_ERROR("Cannot get relocates edits because: %s", - error.c_str()); - } - _processedEdit->relocatesEdits = builder.GetEdits(); + // Otherwise, log that we will author relocates so that this will be + // accounted for when we compute the dependent stage namespace edits. + _processedEdit->willAuthorRelocates = true; } void @@ -1063,35 +1083,9 @@ UsdNamespaceEditor::_EditProcessor::_GatherLayersToEdit() return; } - // Collect every prim spec that exists for this prim path in the layer - // stack's layers. - for (const SdfLayerRefPtr &layer : layers) { - if (layer->HasSpec(_editDesc.oldPath)) { - _processedEdit->layersToEdit.push_back(layer); - } - } - - // Validate whether the necessary spec edits can actually be performed on - // each layer that needs to be edited. - for (const auto &layer : _processedEdit->layersToEdit) { - // The layer itself needs to be editable - if (!layer->PermissionToEdit()) { - _processedEdit->errors.push_back(TfStringPrintf("The spec @%s@<%s> " - "cannot be edited because the layer is not editable", - layer->GetIdentifier().c_str(), - _editDesc.oldPath.GetText())); - } - // If we're moving an object to a new path, the layer cannot have a - // spec already at the new path. - if (!_editDesc.newPath.IsEmpty() && layer->HasSpec(_editDesc.newPath)) { - _processedEdit->errors.push_back(TfStringPrintf("The spec @%s@<%s> " - "cannot be moved to <%s> because a spec already exists at " - "the new path", - layer->GetIdentifier().c_str(), - _editDesc.oldPath.GetText(), - _editDesc.newPath.GetText())); - } - } + _processedEdit->layersToEdit = PcpGatherLayersToEditForSpecMove( + _nodeForEditTarget.GetLayerStack(), + _editDesc.oldPath, _editDesc.newPath, &_processedEdit->errors); } void @@ -1178,10 +1172,10 @@ UsdNamespaceEditor::_EditProcessor::_GatherTargetListOpEdits() } } - // If we added relocates for this edit already, then the target paths - // authored across composition arcs will also be mapped by the + // If the edit will author relocates for the primary edit, then the target + // paths authored across composition arcs will also be mapped by the // relocation. - if (!_processedEdit->relocatesEdits.empty()) { + if (_processedEdit->willAuthorRelocates) { continue; } @@ -1259,52 +1253,51 @@ UsdNamespaceEditor::_ProcessedEdit::CanApply(std::string *whyNot) const return true; } -bool -UsdNamespaceEditor::_ProcessedEdit::Apply() +static bool +_ApplyLayerSpecMove( + const SdfLayerHandle &layer, const SdfPath &oldPath, const SdfPath &newPath) { - // This is to try to preemptively prevent partial edits when if any of the - // necessary specs can't be renamed. - if (std::string errorMsg; !CanApply(&errorMsg)) { - TF_CODING_ERROR(TfStringPrintf("Failed to apply edits to the stage " - "because of the following errors: %s", errorMsg.c_str())); - return false; - } + // Create an SdfBatchNamespaceEdit for the path move. We use the index of + // "Same" specifically so renames don't move the object out of its original + // order (it has no effect for any edits other than rename) + SdfBatchNamespaceEdit batchEdit; + batchEdit.Add(oldPath, newPath, SdfNamespaceEdit::Same); // Implementation function as this is optionally called with a cleanup // enabler depending on the edit type. - auto applyEditsToLayersFn = [&]() { - for (const auto &layer : layersToEdit) { - // While we do require that the new parent exists on the composed - // stage when doing a reparent operation, that doesn't guarantee - // that parent spec exists on every layer in which we have to move - // the source spec. Thus we need to ensure the parent spec of the - // new location exists by adding required overs if necessary. - if (!createParentSpecIfNeededPath.IsEmpty() && - !SdfJustCreatePrimInLayer( - layer, createParentSpecIfNeededPath)) { - TF_CODING_ERROR("Failed to find or create new parent spec " - "at path '%s' on layer '%s' which is necessary to " - "apply edits. The edit will be incomplete.", - createParentSpecIfNeededPath.GetText(), - layer->GetIdentifier().c_str()); - return false; - } + auto applyEditsToLayersFn = [&](const SdfPath &createParentSpecIfNeededPath) { + // While we do require that the new parent exists on the composed + // stage when doing a reparent operation, that doesn't guarantee + // that parent spec exists on every layer in which we have to move + // the source spec. Thus we need to ensure the parent spec of the + // new location exists by adding required overs if necessary. + if (!createParentSpecIfNeededPath.IsEmpty() && + !SdfJustCreatePrimInLayer( + layer, createParentSpecIfNeededPath)) { + TF_CODING_ERROR("Failed to find or create new parent spec " + "at path '%s' on layer '%s' which is necessary to " + "apply edits. The edit will be incomplete.", + createParentSpecIfNeededPath.GetText(), + layer->GetIdentifier().c_str()); + return false; + } - // Apply the namespace edits to the layer. - if (!layer->Apply(edits)) { - TF_CODING_ERROR("Failed to apply batch edit '%s' on layer '%s' " - "which is necessary to apply edits. The edit will be " - "incomplete.", - TfStringify(edits.GetEdits()).c_str(), - layer->GetIdentifier().c_str()); - return false; - } + // Apply the namespace edits to the layer. + if (!layer->Apply(batchEdit)) { + TF_CODING_ERROR("Failed to apply batch edit '%s' on layer '%s' " + "which is necessary to apply edits. The edit will be " + "incomplete.", + TfStringify(batchEdit.GetEdits()).c_str(), + layer->GetIdentifier().c_str()); + return false; } + return true; }; - SdfChangeBlock changeBlock; - if (removeInertAncestorOvers) { + const bool isReparent = !newPath.IsEmpty() && + newPath.GetParentPath() != oldPath.GetParentPath(); + if (isReparent) { // Moving a spec may leave the ancnestor specs as an inert overs. This // could easily be caused by reparenting a prim back to its original // parent (essentially an "undo") after a reparent that needed to create @@ -1313,18 +1306,58 @@ UsdNamespaceEditor::_ProcessedEdit::Apply() // moved path so that a reparent plus an "undo" can effectively leave // layers in their original state. SdfCleanupEnabler cleanupEnabler; - if (!applyEditsToLayersFn()) { + if (!applyEditsToLayersFn(newPath.GetParentPath())) { return false; } } else { - if (!applyEditsToLayersFn()) { + if (!applyEditsToLayersFn(SdfPath::EmptyPath())) { return false; } } - // Set any necessary relocates. - for (const auto &[layer, relocatesValue] : relocatesEdits) { - layer->SetRelocates(relocatesValue); + return true; +} + +bool +UsdNamespaceEditor::_ProcessedEdit::Apply() +{ + // This is to try to preemptively prevent partial edits when if any of the + // necessary specs can't be renamed. + if (std::string errorMsg; !CanApply(&errorMsg)) { + TF_CODING_ERROR(TfStringPrintf("Failed to apply edits to the stage " + "because of the following errors: %s", errorMsg.c_str())); + return false; + } + + SdfChangeBlock changeBlock; + + if (editDescription.IsPropertyEdit()) { + // For a property edit, we just have to move the specs in the layers to + // edit. + for (const auto &layer : layersToEdit) { + _ApplyLayerSpecMove(layer, + editDescription.oldPath, editDescription.newPath); + } + } else { + // For prim edits, the dependent stage edits are always computed for + // at least the primary stage so all necessary edits will be contained + // in those computed edits. + for (const auto &[layer, editVec] : + dependentStageNamespaceEdits.layerSpecMoves) { + for (const auto &edit : editVec) { + _ApplyLayerSpecMove(layer, edit.oldPath, edit.newPath); + } + } + + for (const auto &edit : + dependentStageNamespaceEdits.compositionFieldEdits) { + edit.layer->SetField(edit.path, edit.fieldName, edit.newFieldValue); + } + + for (const auto &[layer, relocates] : + dependentStageNamespaceEdits.dependentRelocatesEdits) { + layer->SetRelocates(relocates); + } } // Perform any target path listOp fixups necessary now that the namespace @@ -1349,5 +1382,47 @@ UsdNamespaceEditor::_ProcessedEdit::Apply() return true; } +void +UsdNamespaceEditor::_EditProcessor::_GatherDependentStageEdits() +{ + // Composition dependencies are only relevant for prim namespace edits. + if (_editDesc.IsPropertyEdit()) { + return; + } + + // Get the PcpCaches for each dependent stage. The primary stage is always + // a dependent so put its cache at the front. Note that _dependentStages + // are a uniqued set and should never contain the primary stage. + std::vector dependentCaches; + dependentCaches.reserve(_dependentStages.size() + 1); + dependentCaches.push_back(_stage->_GetPcpCache()); + for (const auto &stage : _dependentStages) { + dependentCaches.push_back(stage->_GetPcpCache()); + } + + // If we need and allow relocates for the primary edit, then we pass the + // layer stack where we'll author them to the dependent edits function + // which will compute the layer stack's relocates edits for us. + const PcpLayerStackRefPtr &addRelocatesToLayerStack = + _processedEdit->willAuthorRelocates ? + _nodeForEditTarget.GetLayerStack() : PcpLayerStackRefPtr(); + + // Gather all the dependent edits for all stage PcpCaches. + _processedEdit->dependentStageNamespaceEdits = + PcpGatherDependentNamespaceEdits( + _editDesc.oldPath, _editDesc.newPath, _processedEdit->layersToEdit, + addRelocatesToLayerStack, _editTarget.GetLayer(), + dependentCaches); + + // XXX: We may want an option to allow users to treat warnings as errors or + // to return warning as part of calling CanApplyEdits. But for now we just + // emit the warnings. + if (!_processedEdit->dependentStageNamespaceEdits.warnings.empty()) { + TF_WARN("Encountered warnings processing dependent namespace edits: %s", + TfStringJoin(_processedEdit->dependentStageNamespaceEdits.warnings, + "\n ").c_str()); + } +} + PXR_NAMESPACE_CLOSE_SCOPE diff --git a/pxr/usd/usd/namespaceEditor.h b/pxr/usd/usd/namespaceEditor.h index 25a7e56beb9..aebb2115a96 100644 --- a/pxr/usd/usd/namespaceEditor.h +++ b/pxr/usd/usd/namespaceEditor.h @@ -13,10 +13,9 @@ #include "pxr/usd/usd/api.h" #include "pxr/usd/usd/common.h" #include "pxr/usd/usd/stage.h" -#include "pxr/usd/pcp/layerRelocatesEditBuilder.h" +#include "pxr/usd/pcp/dependentNamespaceEditUtils.h" #include "pxr/usd/sdf/namespaceEdit.h" - PXR_NAMESPACE_OPEN_SCOPE /// @warning @@ -52,6 +51,41 @@ class UsdNamespaceEditor const UsdStageRefPtr &stage, const EditOptions &editOptions); + /// \name Dependent Stages + /// + /// Dependent stages are additional stages that may have composition + /// dependencies on the layer edits made for the editor's primary stage. + /// By adding dependent stages, the editor can make additional edits so that + /// affected composition arcs and specs that depend on affected composition + /// in composed prims on these stages are updated to compose with the moved + /// prim specs or, in the case of deletions, removed when the specs they + /// depend on are removed. + /// + /// Dependencies in the dependent stages are based only what is currently + /// loaded for those stages. In other words, the editor cannot find and + /// edit dependencies from unloaded payloads, inactive prim children, + /// prims that are load mask filtered, unselected variants, etc. The primary + /// stage of this editor is always a dependent stage, meaning that edits + /// will always be made to maintain affected composition dependencies in the + /// primary stage. + /// + /// @{ + + /// Adds the given \p stage as a dependent stage of this namespace editor. + USD_API + void AddDependentStage(const UsdStageRefPtr &stage); + + /// Removes the given \p stage as a dependent stage of this namespace editor. + USD_API + void RemoveDependentStage(const UsdStageRefPtr &stage); + + /// Sets the list of dependent stages for this namespace editor to + /// \p stages. + USD_API + void SetDependentStages(const UsdStageRefPtrVector &stages); + + /// @} + /// Adds an edit operation to delete the composed prim at the given \p path /// from this namespace editor's stage. /// @@ -243,17 +277,15 @@ class UsdNamespaceEditor // edit of the composed stage object from being completed successfully. std::vector errors; - // The Sdf batch namespace edit that needs to be applied to each layer - // with specs. - SdfBatchNamespaceEdit edits; - + // The edit description of the primary edit. + _EditDescription editDescription; + // The list of layers that have specs that need to have the Sdf // namespace edit applied. SdfLayerHandleVector layersToEdit; - // The list of relocates edits that need to be made to layers in order - // to relocate a prim. - PcpLayerRelocatesEditBuilder::LayerRelocatesEdits relocatesEdits; + // Whether performing the edit will author new relocates. + bool willAuthorRelocates = false; // Layer edits that need to be performed to update connection and // relationship targets of other properties in order to keep them @@ -274,20 +306,16 @@ class UsdNamespaceEditor }; std::vector targetPathListOpEdits; + // Full set of namespace edits that need to be performed for all the + // dependent stages of this editor as a result of dependencies on the + // initial spec move edits. + PcpDependentNamespaceEdits dependentStageNamespaceEdits; + // List of errors encountered that would prevent connection and // relationship target edits from being performed in response to the // namespace edits. std::vector targetPathListOpErrors; - // Reparent edits may require overs to be created for the new parent if - // a layer doesn't have any specs for the parent yet. This specifies the - // path of the parent specs to create if need. - SdfPath createParentSpecIfNeededPath; - - // Some edits want to remove inert ancestor overs after a prim is - // removed from its parent spec in a layer. - bool removeInertAncestorOvers = false; - // Applies this processed edit, performing the individual edits // necessary to each layer that needs to be updated. bool Apply(); @@ -321,6 +349,10 @@ class UsdNamespaceEditor class _EditProcessor; UsdStageRefPtr _stage; + // Dependent stage order should be arbitrary but we want don't want + // duplicates which can cause unnecessary work. + using _StageSet = std::unordered_set; + _StageSet _dependentStages; EditOptions _editOptions; _EditDescription _editDescription; mutable std::optional<_ProcessedEdit> _processedEdit; diff --git a/pxr/usd/usd/pch.h b/pxr/usd/usd/pch.h index 8aed2f8be8f..e3bad40a529 100644 --- a/pxr/usd/usd/pch.h +++ b/pxr/usd/usd/pch.h @@ -91,6 +91,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/pxr/usd/usd/schemaRegistry.cpp b/pxr/usd/usd/schemaRegistry.cpp index cf88e580c9b..d3238e94471 100644 --- a/pxr/usd/usd/schemaRegistry.cpp +++ b/pxr/usd/usd/schemaRegistry.cpp @@ -163,14 +163,22 @@ struct _TypeMapCache { } // The schema's identifier is the "schemaIdentifier" field. - // If not present, we use the type's alias under UsdSchemaBase. + // If not present, we use the type's alias under UsdSchemaBase + // to maintain backwards compatibility. string identifier = _GetSchemaIdentifierFromMetadata(metadata); if(identifier.empty()) { const vector aliases = schemaBaseType.GetAliases(type); - if (aliases.size() != 1) { - continue; + if (aliases.size() == 1) { + identifier = aliases.front(); } - identifier = aliases.front(); + } + + // Check if a valid identifier was found + if (identifier.empty()) { + TF_CODING_ERROR("Registration failed for schema type %s. " + "Schema types must have a single valid identifier.", + type.GetTypeName().c_str()); + continue; } // Generate all the components of the schema info. diff --git a/pxr/usd/usd/stage.h b/pxr/usd/usd/stage.h index d087278058b..4aff7169185 100644 --- a/pxr/usd/usd/stage.h +++ b/pxr/usd/usd/stage.h @@ -2362,6 +2362,7 @@ class UsdStage : public TfRefBase, public TfWeakBase { friend class UsdAttributeQuery; friend class UsdEditTarget; friend class UsdInherits; + friend class UsdNamespaceEditor; friend class UsdObject; friend class UsdPrim; friend class UsdProperty; diff --git a/pxr/usd/usd/testenv/TestUsdValidationContextValidators_plugInfo.json b/pxr/usd/usd/testenv/TestUsdValidationContextValidators_plugInfo.json new file mode 100644 index 00000000000..a43029c8c20 --- /dev/null +++ b/pxr/usd/usd/testenv/TestUsdValidationContextValidators_plugInfo.json @@ -0,0 +1,52 @@ +{ + "Plugins": [ + { + "Type": "library", + "Name": "testUsdValidationContextValidatorsPlugin", + "Root": "@TEST_PLUG_INFO_ROOT@", + "ResourcePath": "@TEST_PLUG_INFO_RESOURCE_PATH@", + "LibraryPath": "@TEST_PLUG_INFO_LIBRARY_PATH@", + "Info": { + "Validators": { + "Test1": { + "doc": "Stage Validator", + "keywords": ["Keyword1"] + }, + "Test2": { + "doc": "Layer Validator", + "keywords": ["Keyword2"] + }, + "Test3": { + "doc": "A generic prim validator", + "keywords": ["Keyword1"] + }, + "Test4": { + "doc": "validator for testBaseType", + "keywords": ["Keyword2"], + "schemaTypes": ["testBaseType"] + }, + "Test5": { + "doc": "validator for testDerivedType", + "keywords": ["Keyword1"], + "schemaTypes": ["testDerivedType"] + }, + "Test6": { + "doc": "validator for testNestedDerivedType", + "keywords": ["Keyword2"], + "schemaTypes": ["testNestedDerivedType"] + }, + "Test7": { + "doc": "validator for testAPISchema", + "keywords": ["Keyword1"], + "schemaTypes": ["testAPISchemaAPI"] + }, + "TestSuite": { + "doc": "A suite of validators for Test1, Test2 and Test3", + "isSuite": true, + "keywords": ["Keyword2"] + } + } + } + } + ] +} diff --git a/pxr/usd/usd/testenv/testUsdGenSchema/baseline/basic/generatedSchema.classes.txt b/pxr/usd/usd/testenv/testUsdGenSchema/baseline/basic/generatedSchema.classes.txt index b83a90a9d56..de709a2b70c 100644 --- a/pxr/usd/usd/testenv/testUsdGenSchema/baseline/basic/generatedSchema.classes.txt +++ b/pxr/usd/usd/testenv/testUsdGenSchema/baseline/basic/generatedSchema.classes.txt @@ -7,6 +7,7 @@ derivedNonAppliedAPI emptyMultipleApplyAPI multipleApplyAPI multipleApplyAPI_1 +noAlias nonAppliedAPI publicMultipleApplyAPI singleApplyAPI @@ -24,6 +25,7 @@ wrapDerivedNonAppliedAPI.cpp wrapEmptyMultipleApplyAPI.cpp wrapMultipleApplyAPI.cpp wrapMultipleApplyAPI_1.cpp +wrapNoAlias.cpp wrapNonAppliedAPI.cpp wrapPublicMultipleApplyAPI.cpp wrapSingleApplyAPI.cpp diff --git a/pxr/usd/usd/testenv/testUsdGenSchema/baseline/basic/generatedSchema.module.h b/pxr/usd/usd/testenv/testUsdGenSchema/baseline/basic/generatedSchema.module.h index 0a7079f9479..585f6647d73 100644 --- a/pxr/usd/usd/testenv/testUsdGenSchema/baseline/basic/generatedSchema.module.h +++ b/pxr/usd/usd/testenv/testUsdGenSchema/baseline/basic/generatedSchema.module.h @@ -19,4 +19,5 @@ TF_WRAP(UsdContrivedTestHairman_1); TF_WRAP(UsdContrivedTestNoVersion0_2); TF_WRAP(UsdContrivedSingleApplyAPI_1); TF_WRAP(UsdContrivedMultipleApplyAPI_1); +TF_WRAP(UsdContrivedNoAlias); TF_WRAP(UsdContrivedTokens); diff --git a/pxr/usd/usd/testenv/testUsdGenSchema/baseline/basic/generatedSchema.usda b/pxr/usd/usd/testenv/testUsdGenSchema/baseline/basic/generatedSchema.usda index 6e34a74280d..dd9c0ee1aaa 100644 --- a/pxr/usd/usd/testenv/testUsdGenSchema/baseline/basic/generatedSchema.usda +++ b/pxr/usd/usd/testenv/testUsdGenSchema/baseline/basic/generatedSchema.usda @@ -415,3 +415,7 @@ class "MultipleApplyAPI_1" double testNewVersion:__INSTANCE_NAME__:testAttrTwo } +class UsdContrivedNoAlias "UsdContrivedNoAlias" +{ +} + diff --git a/pxr/usd/usd/testenv/testUsdGenSchema/baseline/basic/noAlias.cpp b/pxr/usd/usd/testenv/testUsdGenSchema/baseline/basic/noAlias.cpp new file mode 100644 index 00000000000..fad4ee74662 --- /dev/null +++ b/pxr/usd/usd/testenv/testUsdGenSchema/baseline/basic/noAlias.cpp @@ -0,0 +1,107 @@ +// +// Copyright 2016 Pixar +// +// Licensed under the terms set forth in the LICENSE.txt file available at +// https://openusd.org/license. +// +#include "pxr/usd/usdContrived/noAlias.h" +#include "pxr/usd/usd/schemaRegistry.h" +#include "pxr/usd/usd/typed.h" + +#include "pxr/usd/sdf/types.h" +#include "pxr/usd/sdf/assetPath.h" + +PXR_NAMESPACE_OPEN_SCOPE + +// Register the schema with the TfType system. +TF_REGISTRY_FUNCTION(TfType) +{ + TfType::Define >(); + + // Skip registering an alias as it would be the same as the class name. +} + +/* virtual */ +UsdContrivedNoAlias::~UsdContrivedNoAlias() +{ +} + +/* static */ +UsdContrivedNoAlias +UsdContrivedNoAlias::Get(const UsdStagePtr &stage, const SdfPath &path) +{ + if (!stage) { + TF_CODING_ERROR("Invalid stage"); + return UsdContrivedNoAlias(); + } + return UsdContrivedNoAlias(stage->GetPrimAtPath(path)); +} + +/* static */ +UsdContrivedNoAlias +UsdContrivedNoAlias::Define( + const UsdStagePtr &stage, const SdfPath &path) +{ + static TfToken usdPrimTypeName("UsdContrivedNoAlias"); + if (!stage) { + TF_CODING_ERROR("Invalid stage"); + return UsdContrivedNoAlias(); + } + return UsdContrivedNoAlias( + stage->DefinePrim(path, usdPrimTypeName)); +} + +/* virtual */ +UsdSchemaKind UsdContrivedNoAlias::_GetSchemaKind() const +{ + return UsdContrivedNoAlias::schemaKind; +} + +/* static */ +const TfType & +UsdContrivedNoAlias::_GetStaticTfType() +{ + static TfType tfType = TfType::Find(); + return tfType; +} + +/* static */ +bool +UsdContrivedNoAlias::_IsTypedSchema() +{ + static bool isTyped = _GetStaticTfType().IsA(); + return isTyped; +} + +/* virtual */ +const TfType & +UsdContrivedNoAlias::_GetTfType() const +{ + return _GetStaticTfType(); +} + +/*static*/ +const TfTokenVector& +UsdContrivedNoAlias::GetSchemaAttributeNames(bool includeInherited) +{ + static TfTokenVector localNames; + static TfTokenVector allNames = + UsdTyped::GetSchemaAttributeNames(true); + + if (includeInherited) + return allNames; + else + return localNames; +} + +PXR_NAMESPACE_CLOSE_SCOPE + +// ===================================================================== // +// Feel free to add custom code below this line. It will be preserved by +// the code generator. +// +// Just remember to wrap code in the appropriate delimiters: +// 'PXR_NAMESPACE_OPEN_SCOPE', 'PXR_NAMESPACE_CLOSE_SCOPE'. +// ===================================================================== // +// --(BEGIN CUSTOM CODE)-- diff --git a/pxr/usd/usd/testenv/testUsdGenSchema/baseline/basic/noAlias.h b/pxr/usd/usd/testenv/testUsdGenSchema/baseline/basic/noAlias.h new file mode 100644 index 00000000000..102c1722f62 --- /dev/null +++ b/pxr/usd/usd/testenv/testUsdGenSchema/baseline/basic/noAlias.h @@ -0,0 +1,147 @@ +// +// Copyright 2016 Pixar +// +// Licensed under the terms set forth in the LICENSE.txt file available at +// https://openusd.org/license. +// +#ifndef USDCONTRIVED_GENERATED_NOALIAS_H +#define USDCONTRIVED_GENERATED_NOALIAS_H + +/// \file usdContrived/noAlias.h + +#include "pxr/pxr.h" +#include "pxr/usd/usdContrived/api.h" +#include "pxr/usd/usd/typed.h" +#include "pxr/usd/usd/prim.h" +#include "pxr/usd/usd/stage.h" + +#include "pxr/base/vt/value.h" + +#include "pxr/base/gf/vec3d.h" +#include "pxr/base/gf/vec3f.h" +#include "pxr/base/gf/matrix4d.h" + +#include "pxr/base/tf/token.h" +#include "pxr/base/tf/type.h" + +PXR_NAMESPACE_OPEN_SCOPE + +class SdfAssetPath; + +// -------------------------------------------------------------------------- // +// USDCONTRIVEDNOALIAS // +// -------------------------------------------------------------------------- // + +/// \class UsdContrivedNoAlias +/// +/// +class UsdContrivedNoAlias : public UsdTyped +{ +public: + /// Compile time constant representing what kind of schema this class is. + /// + /// \sa UsdSchemaKind + static const UsdSchemaKind schemaKind = UsdSchemaKind::ConcreteTyped; + + /// Construct a UsdContrivedNoAlias on UsdPrim \p prim . + /// Equivalent to UsdContrivedNoAlias::Get(prim.GetStage(), prim.GetPath()) + /// for a \em valid \p prim, but will not immediately throw an error for + /// an invalid \p prim + explicit UsdContrivedNoAlias(const UsdPrim& prim=UsdPrim()) + : UsdTyped(prim) + { + } + + /// Construct a UsdContrivedNoAlias on the prim held by \p schemaObj . + /// Should be preferred over UsdContrivedNoAlias(schemaObj.GetPrim()), + /// as it preserves SchemaBase state. + explicit UsdContrivedNoAlias(const UsdSchemaBase& schemaObj) + : UsdTyped(schemaObj) + { + } + + /// Destructor. + USDCONTRIVED_API + virtual ~UsdContrivedNoAlias(); + + /// Return a vector of names of all pre-declared attributes for this schema + /// class and all its ancestor classes. Does not include attributes that + /// may be authored by custom/extended methods of the schemas involved. + USDCONTRIVED_API + static const TfTokenVector & + GetSchemaAttributeNames(bool includeInherited=true); + + /// Return a UsdContrivedNoAlias holding the prim adhering to this + /// schema at \p path on \p stage. If no prim exists at \p path on + /// \p stage, or if the prim at that path does not adhere to this schema, + /// return an invalid schema object. This is shorthand for the following: + /// + /// \code + /// UsdContrivedNoAlias(stage->GetPrimAtPath(path)); + /// \endcode + /// + USDCONTRIVED_API + static UsdContrivedNoAlias + Get(const UsdStagePtr &stage, const SdfPath &path); + + /// Attempt to ensure a \a UsdPrim adhering to this schema at \p path + /// is defined (according to UsdPrim::IsDefined()) on this stage. + /// + /// If a prim adhering to this schema at \p path is already defined on this + /// stage, return that prim. Otherwise author an \a SdfPrimSpec with + /// \a specifier == \a SdfSpecifierDef and this schema's prim type name for + /// the prim at \p path at the current EditTarget. Author \a SdfPrimSpec s + /// with \p specifier == \a SdfSpecifierDef and empty typeName at the + /// current EditTarget for any nonexistent, or existing but not \a Defined + /// ancestors. + /// + /// The given \a path must be an absolute prim path that does not contain + /// any variant selections. + /// + /// If it is impossible to author any of the necessary PrimSpecs, (for + /// example, in case \a path cannot map to the current UsdEditTarget's + /// namespace) issue an error and return an invalid \a UsdPrim. + /// + /// Note that this method may return a defined prim whose typeName does not + /// specify this schema class, in case a stronger typeName opinion overrides + /// the opinion at the current EditTarget. + /// + USDCONTRIVED_API + static UsdContrivedNoAlias + Define(const UsdStagePtr &stage, const SdfPath &path); + +protected: + /// Returns the kind of schema this class belongs to. + /// + /// \sa UsdSchemaKind + USDCONTRIVED_API + UsdSchemaKind _GetSchemaKind() const override; + +private: + // needs to invoke _GetStaticTfType. + friend class UsdSchemaRegistry; + USDCONTRIVED_API + static const TfType &_GetStaticTfType(); + + static bool _IsTypedSchema(); + + // override SchemaBase virtuals. + USDCONTRIVED_API + const TfType &_GetTfType() const override; + +public: + // ===================================================================== // + // Feel free to add custom code below this line, it will be preserved by + // the code generator. + // + // Just remember to: + // - Close the class declaration with }; + // - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE + // - Close the include guard with #endif + // ===================================================================== // + // --(BEGIN CUSTOM CODE)-- +}; + +PXR_NAMESPACE_CLOSE_SCOPE + +#endif diff --git a/pxr/usd/usd/testenv/testUsdGenSchema/baseline/basic/plugInfo.json b/pxr/usd/usd/testenv/testUsdGenSchema/baseline/basic/plugInfo.json index 8529488299f..95df9a061d2 100644 --- a/pxr/usd/usd/testenv/testUsdGenSchema/baseline/basic/plugInfo.json +++ b/pxr/usd/usd/testenv/testUsdGenSchema/baseline/basic/plugInfo.json @@ -116,6 +116,14 @@ "schemaIdentifier": "MultipleApplyAPI_1", "schemaKind": "multipleApplyAPI" }, + "UsdContrivedNoAlias": { + "autoGenerated": true, + "bases": [ + "UsdTyped" + ], + "schemaIdentifier": "UsdContrivedNoAlias", + "schemaKind": "concreteTyped" + }, "UsdContrivedNonAppliedAPI": { "alias": { "UsdSchemaBase": "NonAppliedAPI" diff --git a/pxr/usd/usd/testenv/testUsdGenSchema/baseline/basic/tokens.cpp b/pxr/usd/usd/testenv/testUsdGenSchema/baseline/basic/tokens.cpp index 15c2541c235..e6567983a77 100644 --- a/pxr/usd/usd/testenv/testUsdGenSchema/baseline/basic/tokens.cpp +++ b/pxr/usd/usd/testenv/testUsdGenSchema/baseline/basic/tokens.cpp @@ -163,6 +163,7 @@ UsdContrivedTokensType::UsdContrivedTokensType() : TestNoVersion0_2("TestNoVersion0_2", TfToken::Immortal), TestPxHairman("TestPxHairman", TfToken::Immortal), TestPxHairman_1("TestPxHairman_1", TfToken::Immortal), + UsdContrivedNoAlias("UsdContrivedNoAlias", TfToken::Immortal), allTokens({ asset, assetArray, @@ -317,7 +318,8 @@ UsdContrivedTokensType::UsdContrivedTokensType() : TestNoVersion0, TestNoVersion0_2, TestPxHairman, - TestPxHairman_1 + TestPxHairman_1, + UsdContrivedNoAlias }) { } diff --git a/pxr/usd/usd/testenv/testUsdGenSchema/baseline/basic/tokens.h b/pxr/usd/usd/testenv/testUsdGenSchema/baseline/basic/tokens.h index be293e03781..f2b56cd2dfe 100644 --- a/pxr/usd/usd/testenv/testUsdGenSchema/baseline/basic/tokens.h +++ b/pxr/usd/usd/testenv/testUsdGenSchema/baseline/basic/tokens.h @@ -661,6 +661,10 @@ struct UsdContrivedTokensType { /// /// Schema identifer for UsdContrivedTestHairman_1 const TfToken TestPxHairman_1; + /// \brief "UsdContrivedNoAlias" + /// + /// Schema identifer and family for UsdContrivedNoAlias + const TfToken UsdContrivedNoAlias; /// A vector of all of the tokens listed above. const std::vector allTokens; }; diff --git a/pxr/usd/usd/testenv/testUsdGenSchema/baseline/basic/wrapNoAlias.cpp b/pxr/usd/usd/testenv/testUsdGenSchema/baseline/basic/wrapNoAlias.cpp new file mode 100644 index 00000000000..964f685f99b --- /dev/null +++ b/pxr/usd/usd/testenv/testUsdGenSchema/baseline/basic/wrapNoAlias.cpp @@ -0,0 +1,107 @@ +// +// Copyright 2016 Pixar +// +// Licensed under the terms set forth in the LICENSE.txt file available at +// https://openusd.org/license. +// +#include "pxr/usd/usdContrived/noAlias.h" +#include "pxr/usd/usd/schemaBase.h" + +#include "pxr/usd/sdf/primSpec.h" + +#include "pxr/usd/usd/pyConversions.h" +#include "pxr/base/tf/pyContainerConversions.h" +#include "pxr/base/tf/pyResultConversions.h" +#include "pxr/base/tf/pyUtils.h" +#include "pxr/base/tf/wrapTypeHelpers.h" + +#include "pxr/external/boost/python.hpp" + +#include + +PXR_NAMESPACE_USING_DIRECTIVE + +using namespace pxr_boost::python; + +namespace { + +#define WRAP_CUSTOM \ + template static void _CustomWrapCode(Cls &_class) + +// fwd decl. +WRAP_CUSTOM; + + +static std::string +_Repr(const UsdContrivedNoAlias &self) +{ + std::string primRepr = TfPyRepr(self.GetPrim()); + return TfStringPrintf( + "UsdContrived.NoAlias(%s)", + primRepr.c_str()); +} + +} // anonymous namespace + +void wrapUsdContrivedNoAlias() +{ + typedef UsdContrivedNoAlias This; + + class_ > + cls("NoAlias"); + + cls + .def(init(arg("prim"))) + .def(init(arg("schemaObj"))) + .def(TfTypePythonClass()) + + .def("Get", &This::Get, (arg("stage"), arg("path"))) + .staticmethod("Get") + + .def("Define", &This::Define, (arg("stage"), arg("path"))) + .staticmethod("Define") + + .def("GetSchemaAttributeNames", + &This::GetSchemaAttributeNames, + arg("includeInherited")=true, + return_value_policy()) + .staticmethod("GetSchemaAttributeNames") + + .def("_GetStaticTfType", (TfType const &(*)()) TfType::Find, + return_value_policy()) + .staticmethod("_GetStaticTfType") + + .def(!self) + + + .def("__repr__", ::_Repr) + ; + + _CustomWrapCode(cls); +} + +// ===================================================================== // +// Feel free to add custom code below this line, it will be preserved by +// the code generator. The entry point for your custom code should look +// minimally like the following: +// +// WRAP_CUSTOM { +// _class +// .def("MyCustomMethod", ...) +// ; +// } +// +// Of course any other ancillary or support code may be provided. +// +// Just remember to wrap code in the appropriate delimiters: +// 'namespace {', '}'. +// +// ===================================================================== // +// --(BEGIN CUSTOM CODE)-- + +namespace { + +WRAP_CUSTOM { +} + +} diff --git a/pxr/usd/usd/testenv/testUsdGenSchema/baseline/basic/wrapTokens.cpp b/pxr/usd/usd/testenv/testUsdGenSchema/baseline/basic/wrapTokens.cpp index 16639710666..793acd567b3 100644 --- a/pxr/usd/usd/testenv/testUsdGenSchema/baseline/basic/wrapTokens.cpp +++ b/pxr/usd/usd/testenv/testUsdGenSchema/baseline/basic/wrapTokens.cpp @@ -171,4 +171,5 @@ void wrapUsdContrivedTokens() _ADD_TOKEN(cls, TestNoVersion0_2); _ADD_TOKEN(cls, TestPxHairman); _ADD_TOKEN(cls, TestPxHairman_1); + _ADD_TOKEN(cls, UsdContrivedNoAlias); } diff --git a/pxr/usd/usd/testenv/testUsdGenSchema/baseline/codeless/plugInfo.json b/pxr/usd/usd/testenv/testUsdGenSchema/baseline/codeless/plugInfo.json index a397c7765b5..7e479255081 100644 --- a/pxr/usd/usd/testenv/testUsdGenSchema/baseline/codeless/plugInfo.json +++ b/pxr/usd/usd/testenv/testUsdGenSchema/baseline/codeless/plugInfo.json @@ -116,6 +116,14 @@ "schemaIdentifier": "MultipleApplyAPI_1", "schemaKind": "multipleApplyAPI" }, + "UsdContrivedNoAlias": { + "autoGenerated": true, + "bases": [ + "UsdTyped" + ], + "schemaIdentifier": "UsdContrivedNoAlias", + "schemaKind": "concreteTyped" + }, "UsdContrivedNonAppliedAPI": { "alias": { "UsdSchemaBase": "NonAppliedAPI" diff --git a/pxr/usd/usd/testenv/testUsdGenSchema/codeless_schema.usda b/pxr/usd/usd/testenv/testUsdGenSchema/codeless_schema.usda index 9270bf6bbf4..857c4df614e 100644 --- a/pxr/usd/usd/testenv/testUsdGenSchema/codeless_schema.usda +++ b/pxr/usd/usd/testenv/testUsdGenSchema/codeless_schema.usda @@ -553,3 +553,12 @@ class "MultipleApplyAPI_1" ( int testAttrOne double testAttrTwo } + +class UsdContrivedNoAlias "UsdContrivedNoAlias" ( + inherits = + customData = { + string className = "NoAlias" + } +) +{ +} \ No newline at end of file diff --git a/pxr/usd/usd/testenv/testUsdGenSchema/schema.usda b/pxr/usd/usd/testenv/testUsdGenSchema/schema.usda index 48ba508962e..bd1a040dc8d 100644 --- a/pxr/usd/usd/testenv/testUsdGenSchema/schema.usda +++ b/pxr/usd/usd/testenv/testUsdGenSchema/schema.usda @@ -552,3 +552,12 @@ class "MultipleApplyAPI_1" ( int testAttrOne double testAttrTwo } + +class UsdContrivedNoAlias "UsdContrivedNoAlias" ( + inherits = + customData = { + string className = "NoAlias" + } +) +{ +} \ No newline at end of file diff --git a/pxr/usd/usd/testenv/testUsdNamespaceEditorDependentEditsBase.py b/pxr/usd/usd/testenv/testUsdNamespaceEditorDependentEditsBase.py new file mode 100644 index 00000000000..7d86d3d73d7 --- /dev/null +++ b/pxr/usd/usd/testenv/testUsdNamespaceEditorDependentEditsBase.py @@ -0,0 +1,155 @@ +#!/pxrpythonsubst +# +# Copyright 2024 Pixar +# +# Licensed under the terms set forth in the LICENSE.txt file available at +# https://openusd.org/license. + +import contextlib, inspect, sys, unittest +from pxr import Sdf, Usd + +class TestUsdNamespaceEditorDependentEditsBase(unittest.TestCase): + '''Base class for testUsdNamespaceEditDependentEditsXXX tests which + provides share utilities for verifying outcomes of edits. + ''' + + @contextlib.contextmanager + def ApplyEdits(self, editor, label, expectWarnings = False): + '''Context manager for adding a namespace edit on a Usd.NameespaceEditor + that will automatically verify that it can be applied and will apply it + verifying a successful apply. It also prints out useful information to + help keep test output organized. + + Example Usage: + editor = Usd.NamespaceEditor(stage) + with self.ApplyEdits(editor, "Move /Foo to /Bar"): + self.assertTrue(editor.MovePrimAtPath('/Foo', '/Bar')) + ''' + + # The enclosing test case function name to output with the begin and + # end messages. + testFunctionName = next((x.function for x in inspect.stack() + if x.function.startswith("test_")), "") + msg = testFunctionName + " : " + label + print("\n==== Begin ApplyEdits : {} ====".format(msg)) + print("\n==== Begin ApplyEdits : {} ====".format(msg), file=sys.stderr) + + yield + + if expectWarnings: + print("\n=== EXPECT WARNINGS ===", file=sys.stderr) + self.assertTrue(editor.CanApplyEdits()) + self.assertTrue(editor.ApplyEdits()) + if expectWarnings: + print("\n=== END EXPECTED WARNINGS ===", file=sys.stderr) + + print("==== End ApplyEdits : {} ====".format(msg)) + print("==== End ApplyEdits : {} ====".format(msg), file=sys.stderr) + + def _VerifyPrimContents(self, prim, expectedContentsDict): + '''Helper that verifies the contents of a USD prim, specifically its + child prims and properties, match the given expected contents. + + A prims expected contents are expressed as a dictionary of the form + + { + '.' : ['propName1', 'propName2'], + 'Child1' : {...child prim expected contents...}, + 'Child2' : {...child prim expected contents...} + } + ''' + + # '.' is used to key the list of expected property names for the prim + expectedPropertyNameSet = set(expectedContentsDict.get('.', [])) + + # Get the actual property names and compare against the expected set. + propertyNameSet = set(prim.GetPropertyNames()) + self.assertEqual(propertyNameSet, expectedPropertyNameSet, + "The actual property set {} does not match the expected property " + "set {} for the prim at path {}".format( + list(propertyNameSet), + list(expectedPropertyNameSet), + prim.GetPath())) + + # Expected children names are all the expected contents keys except '.' + expectedChildNameSet = set( + [k for k in expectedContentsDict.keys() if k != '.']) + + # Get the actual child prim names and compare against the expected set. + # We specifically want all children so we get unloaded prims and prims + # that aren't defined (they are just overs) + childrenNameSet = set(prim.GetAllChildrenNames()) + self.assertEqual(childrenNameSet, expectedChildNameSet, + "The actual child prim set {} does not match the expected children " + "set {} for the prim at path {}".format( + list(childrenNameSet), + list(expectedChildNameSet), + prim.GetPath())) + + # Verify the expected contents of each expected child prim. + for childName in expectedChildNameSet: + childPath = prim.GetPath().AppendChild(childName) + primChild = prim.GetPrimAtPath(childPath) + self._VerifyPrimContents(primChild, expectedContentsDict[childName]) + + def _VerifyStageContents(self, stage, expectedContentsDict): + '''Helper that verifies the contents of every USD prim on the given + stage, specifically each's child prims and properties, match the given + expected contents dictionary.''' + + self._VerifyPrimContents(stage.GetPseudoRoot(), expectedContentsDict) + + def _GetCompositionFieldsInLayer(self, layer): + '''Helper that finds all prims specs with composition fields set in the + given layer and returns a dictionary of prim paths to the fields and + their values. + + Example output: + + { + '/' : { + relocates : (('/Prim/Foo', '/Prim/Bar), ) + }, + '/Prim' : { + references : [Sdf.Refence(layer, '/RefPath')], + payload : [Sdf.Payload(layer, '/PayloadPath)] + }, + '/PrimA/ChildA' : { + inherits : ['/GlobalClass', '/PrimA/LocalClass'] + } + } + ''' + + compositionFields = {} + + # Relocates are only in layer metadata so add them as belonging to the + # pseudoroot if there are any. + if layer.HasRelocates(): + compositionFields ['/'] = {'relocates' : layer.relocates} + + def _GetCompositonFieldsForPrimAtPath(path) : + if not path.IsPrimPath() and not path.IsPrimVariantSelectionPath(): + return + + def _AddListOpValueForField(fieldName, listOp): + if not path in compositionFields: + compositionFields[str(path)] = {} + compositionFields[str(path)][fieldName] = listOp.GetAppliedItems() + + prim = layer.GetPrimAtPath(path) + if prim is None: + return + if prim.hasReferences: + _AddListOpValueForField('references', prim.referenceList) + if prim.hasPayloads: + _AddListOpValueForField('payload', prim.payloadList) + if prim.hasInheritPaths: + _AddListOpValueForField('inherits', prim.inheritPathList) + if prim.hasSpecializes: + _AddListOpValueForField('specializes', prim.specializesList) + + layer.Traverse("/", _GetCompositonFieldsForPrimAtPath) + return compositionFields + +if __name__ == '__main__': + unittest.main() diff --git a/pxr/usd/usd/testenv/testUsdNamespaceEditorDependentEditsBasicReferencesAndPayloads.py b/pxr/usd/usd/testenv/testUsdNamespaceEditorDependentEditsBasicReferencesAndPayloads.py new file mode 100644 index 00000000000..59372709ec6 --- /dev/null +++ b/pxr/usd/usd/testenv/testUsdNamespaceEditorDependentEditsBasicReferencesAndPayloads.py @@ -0,0 +1,1611 @@ +#!/pxrpythonsubst +# +# Copyright 2024 Pixar +# +# Licensed under the terms set forth in the LICENSE.txt file available at +# https://openusd.org/license. + +import sys, unittest +from pxr import Sdf, Usd +from testUsdNamespaceEditorDependentEditsBase \ + import TestUsdNamespaceEditorDependentEditsBase + +class TestUsdNamespaceEditorDependentEditsBasicReferencesAndPayloads( + TestUsdNamespaceEditorDependentEditsBase): + '''Tests downstream dependency namespace edits across references and + payloads.''' + + def test_BasicDependentReferences(self): + """Test downstream dependency namespace edits across basic single + references, both internal and in separate layers """ + + # Setup: + # Layer 1 has simple hierarchy of /Ref, Child, and GrandChild that is + # referenced and will be namespace edited. It also has three prims + # that internally reference /Ref, /Ref/Child, and /Ref/Child/GrandChild + # respectively. These internally referencing prims will be affected by + # downstream dependency edits. + layer1 = Sdf.Layer.CreateAnonymous("layer1.usda") + layer1ImportString = '''#usda 1.0 + def "Ref" { + int refAttr + + def "Child" { + int childAttr + + def "GrandChild" { + int grandChildAttr + } + } + } + + def "InternalRef1" ( + references = + ) { + over "Child" { + int overChildAttr + over "GrandChild" { + int overGrandChildAttr + } + } + def "LocalChild" {} + int localAttr + } + + def "InternalRef2" ( + references = + ) { + over "GrandChild" { + int overGrandChildAttr + } + def "LocalChild" {} + int localAttr + } + + def "InternalRef3" ( + references = + ) { + def "LocalChild" {} + int localAttr + } + ''' + layer1.ImportFromString(layer1ImportString) + + # Layer 2 has three prims that reference /Ref, /Ref/Child, and + # /Ref/Child/GrandChild from layer 1 respectively. These prims will be + # affected by downstream dependency edits. + layer2 = Sdf.Layer.CreateAnonymous("layer2.usda") + layer2ImportString = '''#usda 1.0 + def "Prim1" ( + references = @''' + layer1.identifier + '''@ + ) { + over "Child" { + int overChildAttr + over "GrandChild" { + int overGrandChildAttr + } + } + def "LocalChild" {} + int localAttr + } + + def "Prim2" ( + references = @''' + layer1.identifier + '''@ + ) { + over "GrandChild" { + int overGrandChildAttr + } + def "LocalChild" {} + int localAttr + } + + def "Prim3" ( + references = @''' + layer1.identifier + '''@ + ) { + def "LocalChild" {} + int localAttr + } + ''' + layer2.ImportFromString(layer2ImportString) + + # Open both layers as stages. + stage1 = Usd.Stage.Open(layer1, Usd.Stage.LoadAll) + stage2 = Usd.Stage.Open(layer2, Usd.Stage.LoadAll) + + # Create an editor for stage 1 with stage 2 as an addtional dependent + # stage. + editor = Usd.NamespaceEditor(stage1) + editor.AddDependentStage(stage2) + + # Verify the initial composition fields for both layers. + self.assertEqual(self._GetCompositionFieldsInLayer(layer1), { + '/InternalRef1' : { + 'references' : (Sdf.Reference(primPath='/Ref'),) + }, + '/InternalRef2' : { + 'references' : (Sdf.Reference(primPath='/Ref/Child'),) + }, + '/InternalRef3' : { + 'references' : (Sdf.Reference(primPath='/Ref/Child/GrandChild'),) + }, + }) + + self.assertEqual(self._GetCompositionFieldsInLayer(layer2), { + '/Prim1' : { + 'references' : (Sdf.Reference(layer1.identifier, '/Ref'),) + }, + '/Prim2' : { + 'references' : (Sdf.Reference(layer1.identifier, '/Ref/Child'),) + }, + '/Prim3' : { + 'references' : (Sdf.Reference(layer1.identifier, + '/Ref/Child/GrandChild'),) + }, + }) + + # Both the internal reference prims in stage 1 and the "regular" + # reference prims in stage 2 will have same contents since they + # reference the same prims and define identical local specs. So, + # we create expected contents dictionaries that we can share for + # verification. + refToRefContents = { + '.' : ['refAttr', 'localAttr'], + 'Child' : { + '.' : ['childAttr', 'overChildAttr'], + 'GrandChild' : { + '.' : ['grandChildAttr', 'overGrandChildAttr'], + }, + }, + 'LocalChild' : {} + } + + refToChildContents = { + '.' : ['childAttr', 'localAttr'], + 'GrandChild' : { + '.' : ['grandChildAttr', 'overGrandChildAttr'], + }, + 'LocalChild' : {}, + } + + refToGrandChildContents = { + '.' : ['grandChildAttr', 'localAttr'], + 'LocalChild' : {}, + } + + # Verify the expected contents of stage 1 + self._VerifyStageContents(stage1, { + 'Ref': { + '.' : ['refAttr'], + 'Child' : { + '.' : ['childAttr'], + 'GrandChild' : { + '.' : ['grandChildAttr'], + } + } + }, + 'InternalRef1' : refToRefContents, + 'InternalRef2' : refToChildContents, + 'InternalRef3' : refToGrandChildContents + }) + + # Verify the expected contents of stage 2. + self._VerifyStageContents(stage2, { + 'Prim1' : refToRefContents, + 'Prim2' : refToChildContents, + 'Prim3' : refToGrandChildContents + }) + + # Edit: Rename /Ref/Child to /Ref/RenamedChild + with self.ApplyEdits(editor, "Move /Ref/Child -> /Ref/RenamedChild"): + self.assertTrue(editor.MovePrimAtPath( + '/Ref/Child', '/Ref/RenamedChild')) + + # Verify the updated composition fields in layer1. The internal + # reference fields to /Ref/Child and its descendant + # /Ref/Child/GrandChild have been updated to use the renamed paths. + self.assertEqual(self._GetCompositionFieldsInLayer(layer1), { + '/InternalRef1' : { + 'references' : (Sdf.Reference(primPath='/Ref'),) + }, + '/InternalRef2' : { + 'references' : (Sdf.Reference(primPath='/Ref/RenamedChild'),) + }, + '/InternalRef3' : { + 'references' : (Sdf.Reference( + primPath='/Ref/RenamedChild/GrandChild'),) + }, + }) + + # Verify the udpated composition fields in layer2. The reference fields + # to /Ref/Child and its descendant /Ref/Child/GrandChild have been + # similarly updated to use the renamed paths. + self.assertEqual(self._GetCompositionFieldsInLayer(layer2), { + '/Prim1' : { + 'references' : (Sdf.Reference(layer1.identifier, '/Ref'),) + }, + '/Prim2' : { + 'references' : (Sdf.Reference(layer1.identifier, + '/Ref/RenamedChild'),) + }, + '/Prim3' : { + 'references' : (Sdf.Reference(layer1.identifier, + '/Ref/RenamedChild/GrandChild'),) + }, + }) + + # Verify the updated stage contents for both stages. + # + # For the both prims that directly reference /Ref, the child prim is + # renamed to RenamedChild. Note that this means the local override specs + # for the referencing prims have been renamed to RenamedChild too which + # is why the composed RenamedChild prim still has both childAttr and + # overChildAttr and the composed GrandChild remains unchanged + # + # The contents of the other two prims in each stage remain unchanged + # as the update to the reference fields allow those prims to remain the + # same. + refToRefContents = { + '.' : ['refAttr', 'localAttr'], + 'RenamedChild' : { + '.' : ['childAttr', 'overChildAttr'], + 'GrandChild' : { + '.' : ['grandChildAttr', 'overGrandChildAttr'], + }, + }, + 'LocalChild' : {}, + } + + self._VerifyStageContents(stage1, { + 'Ref': { + '.' : ['refAttr'], + 'RenamedChild' : { + '.' : ['childAttr'], + 'GrandChild' : { + '.' : ['grandChildAttr'], + } + } + }, + 'InternalRef1' : refToRefContents, + 'InternalRef2' : refToChildContents, + 'InternalRef3' : refToGrandChildContents + }) + + self._VerifyStageContents(stage2, { + 'Prim1' : refToRefContents, + 'Prim2' : refToChildContents, + 'Prim3' : refToGrandChildContents + }) + + # Edit: Reparent and rename /Ref/RenamedChild to /MovedChild + with self.ApplyEdits(editor, "Move /Ref/RenamedChild -> /MovedChild"): + self.assertTrue(editor.MovePrimAtPath( + '/Ref/RenamedChild', '/MovedChild')) + + # Verify the udpated composition fields in layer1. The internal + # reference fields to /Ref/RenamedChild and its descendant + # /Ref/RenamedChild/GrandChild have been updated to use the moved paths. + self.assertEqual(self._GetCompositionFieldsInLayer(layer1), { + '/InternalRef1' : { + 'references' : (Sdf.Reference(primPath='/Ref'),) + }, + '/InternalRef2' : { + 'references' : (Sdf.Reference(primPath='/MovedChild'),) + }, + '/InternalRef3' : { + 'references' : (Sdf.Reference(primPath='/MovedChild/GrandChild'),) + }, + }) + + # Verify the udpated composition fields in layer2. The reference fields + # to /Ref/RenamedChild and its descendant /Ref/RenamedChild/GrandChild + # have been similarly updated to use the moved paths. + self.assertEqual(self._GetCompositionFieldsInLayer(layer2), { + '/Prim1' : { + 'references' : (Sdf.Reference(layer1.identifier, '/Ref'),) + }, + '/Prim2' : { + 'references' : (Sdf.Reference(layer1.identifier, '/MovedChild'),) + }, + '/Prim3' : { + 'references' : (Sdf.Reference(layer1.identifier, + '/MovedChild/GrandChild'),) + }, + }) + + # Verify the updated stage contents for both stages. + # + # For both prims that directly reference /Ref, since RenamedChild has + # been moved out of /Ref, it is no longer a composed child of the + # referencing prims. Note that the over to RenamedChild (which brought + # in the attributes overChildAttr and GrandChild.overChildAttr) has been + # deleted to prevent the reintroduction of a partially specced + # RenamedChild. + # + # The contents of the other two prims in each stage remain unchanged + # as the update to the reference fields allow those prims to remain the + # same. + refToRefContents = { + '.' : ['refAttr', 'localAttr'], + 'LocalChild' : {}, + } + + self._VerifyStageContents(stage1, { + 'Ref': { + '.' : ['refAttr'], + }, + 'MovedChild' : { + '.' : ['childAttr'], + 'GrandChild' : { + '.' : ['grandChildAttr'], + } + }, + 'InternalRef1' : refToRefContents, + 'InternalRef2' : refToChildContents, + 'InternalRef3' : refToGrandChildContents + }) + + self._VerifyStageContents(stage2, { + 'Prim1' : refToRefContents, + 'Prim2' : refToChildContents, + 'Prim3' : refToGrandChildContents + }) + + # Edit: Reparent and rename /MovedChild back to its original path + # /Ref/Child + with self.ApplyEdits(editor, "Move /MovedChild -> /Ref/Child"): + self.assertTrue(editor.MovePrimAtPath('/MovedChild', '/Ref/Child')) + + # Verify the udpated composition fields in layer1 and layer2. All the + # reference fields have been updated to their original paths. + self.assertEqual(self._GetCompositionFieldsInLayer(layer1), { + '/InternalRef1' : { + 'references' : (Sdf.Reference(primPath='/Ref'),) + }, + '/InternalRef2' : { + 'references' : (Sdf.Reference(primPath='/Ref/Child'),) + }, + '/InternalRef3' : { + 'references' : (Sdf.Reference(primPath='/Ref/Child/GrandChild'),) + }, + }) + + self.assertEqual(self._GetCompositionFieldsInLayer(layer2), { + '/Prim1' : { + 'references' : (Sdf.Reference(layer1.identifier, '/Ref'),) + }, + '/Prim2' : { + 'references' : (Sdf.Reference(layer1.identifier, '/Ref/Child'),) + }, + '/Prim3' : { + 'references' : (Sdf.Reference(layer1.identifier, + '/Ref/Child/GrandChild'),) + }, + }) + + # Verify the updated stage contents for both stages. + # + # For both prims that directly reference /Ref, they are returned to + # their original contents with one notable exception: the overs on + # Child that introduced overChildAttr and GrandChild.overGrandChildAttr + # are NOT restored from being deleted so these attributes are not + # present like they were in the initial state of the stages. + # + # The contents of the other two prims in each stage remain unchanged + # (which matches their initial state) as the update to the reference + # fields allow those prims to remain the same. + refToRefContents = { + '.' : ['refAttr', 'localAttr'], + 'Child' : { + '.' : ['childAttr'], + 'GrandChild' : { + '.' : ['grandChildAttr'] + } + }, + 'LocalChild' : {}, + } + + self._VerifyStageContents(stage1, { + 'Ref': { + '.' : ['refAttr'], + 'Child' : { + '.' : ['childAttr'], + 'GrandChild' : { + '.' : ['grandChildAttr'], + } + } + }, + 'InternalRef1' : refToRefContents, + 'InternalRef2' : refToChildContents, + 'InternalRef3' : refToGrandChildContents + }) + + self._VerifyStageContents(stage2, { + 'Prim1' : refToRefContents, + 'Prim2' : refToChildContents, + 'Prim3' : refToGrandChildContents + }) + + # Reset both layers before the next operation to return the overs on the + # prims that reference /Ref + layer1.ImportFromString(layer1ImportString) + layer2.ImportFromString(layer2ImportString) + + # Verify the stage contents which again have the initial overs. + refToRefContents = { + '.' : ['refAttr', 'localAttr'], + 'Child' : { + '.' : ['childAttr', 'overChildAttr'], + 'GrandChild' : { + '.' : ['grandChildAttr', 'overGrandChildAttr'] + } + }, + 'LocalChild' : {}, + } + + self._VerifyStageContents(stage1, { + 'Ref': { + '.' : ['refAttr'], + 'Child' : { + '.' : ['childAttr'], + 'GrandChild' : { + '.' : ['grandChildAttr'], + } + } + }, + 'InternalRef1' : refToRefContents, + 'InternalRef2' : refToChildContents, + 'InternalRef3' : refToGrandChildContents + }) + + self._VerifyStageContents(stage2, { + 'Prim1' : refToRefContents, + 'Prim2' : refToChildContents, + 'Prim3' : refToGrandChildContents + }) + + # Edit: Delete the prim at /Ref/Child + with self.ApplyEdits(editor, "Delete /Ref/Child"): + self.assertTrue(editor.DeletePrimAtPath('/Ref/Child')) + + # Verify the udpated composition fields in layer1 and layer2. All the + # reference fields that reference /Ref/Child or its descendants have + # had those references removed. Note the reference fields remain but the + # values are empty. + self.assertEqual(self._GetCompositionFieldsInLayer(layer1), { + '/InternalRef1' : { + 'references' : (Sdf.Reference(primPath='/Ref'),) + }, + '/InternalRef2' : { + 'references' : () + }, + '/InternalRef3' : { + 'references' : () + }, + }) + + self.assertEqual(self._GetCompositionFieldsInLayer(layer2), { + '/Prim1' : { + 'references' : (Sdf.Reference(layer1.identifier, '/Ref'),) + }, + '/Prim2' : { + 'references' : () + }, + '/Prim3' : { + 'references' : () + }, + }) + + # Verify the updated stage contents for both stages. + # + # For both prims that directly reference /Ref, since Child has been + # deleted as a child of from /Ref, it is no longer a composed child of + # these referencing prims. Note that the overs to Child (which brought + # in the attributes overChildAttr and GrandChild.overChildAttr) have + # been deleted to prevent the reintroduction of a partially specced + # Child. + # + # Unlike all the prior edits in this test case, the contents of the + # other two prims in each stage DO change because the references have + # been deleted and can no longer compose contents from across them. + # Addtionally any child specs in the referencing prims that would've + # comosed over the now deleted referenced prim's children are also + # deleted to "truly delete" all composed prims from the deleted + # reference. + # + # XXX: There is an open question as to whether this is the correct + # behavior or if we should go a step further and delete the specs that + # introduced the now deleted reference prims (instead of just removing + # the reference but not the referencing prim itself like we do now). + # This expanded approach would result in the InternalRef2, InternalRef3, + # Prim2, and Prim3 prims being completely deleted from their stages. + refToRefContents = { + '.' : ['refAttr', 'localAttr'], + 'LocalChild' : {}, + } + + refToChildContents = { + '.' : ['localAttr'], + 'LocalChild' : {}, + } + + refToGrandChildContents = { + '.' : ['localAttr'], + 'LocalChild' : {}, + } + + self._VerifyStageContents(stage1, { + 'Ref': { + '.' : ['refAttr'], + }, + 'InternalRef1' : refToRefContents, + 'InternalRef2' : refToChildContents, + 'InternalRef3' : refToGrandChildContents + }) + + self._VerifyStageContents(stage2, { + 'Prim1' : refToRefContents, + 'Prim2' : refToChildContents, + 'Prim3' : refToGrandChildContents + }) + + def test_BasicDependentPayloads(self): + """Test downstream dependency namespace edits across basic single + payloads.""" + + # Setup: + # Layer 1 has simple hierarchy of /Ref, Child, GrandChild that is + # referenced and will be namespace edited. + layer1 = Sdf.Layer.CreateAnonymous("layer1.usda") + layer1.ImportFromString('''#usda 1.0 + def "Ref" { + int refAttr + + def "Child" { + int childAttr + + def "GrandChild" { + int grandChildAttr + } + } + } + ''') + + # Layer 2 has three prims that payload /Ref, /Ref/Child, and + # /Ref/Child/GrandChild from layer 1 respectively. These will be + # affected by downstream dependency edits. + layer2 = Sdf.Layer.CreateAnonymous("layer2.usda") + layer2.ImportFromString('''#usda 1.0 + def "Prim1" ( + payload = @''' + layer1.identifier + '''@ + ) { + over "Child" { + int overChildAttr + over "GrandChild" { + int overGrandChildAttr + } + } + def "LocalChild" {} + int localAttr + } + + def "Prim2" ( + payload = @''' + layer1.identifier + '''@ + ) { + int overChildAttr + over "GrandChild" { + int overGrandChildAttr + } + def "LocalChild" {} + int localAttr + } + + def "Prim3" ( + payload = @''' + layer1.identifier + '''@ + ) { + def "LocalChild" {} + int localAttr + } + ''') + + # Open both layers as stages. + stage1 = Usd.Stage.Open(layer1, Usd.Stage.LoadAll) + stage2 = Usd.Stage.Open(layer2, Usd.Stage.LoadAll) + + # Create an editor for stage 1 with stage 2 as an addtional dependent + # stage. + editor = Usd.NamespaceEditor(stage1) + editor.AddDependentStage(stage2) + + # Verify the initial composition fields for both layer 2 (layer 1 has + # no composition fields). + self.assertEqual(self._GetCompositionFieldsInLayer(layer1), {}) + self.assertEqual(self._GetCompositionFieldsInLayer(layer2), { + '/Prim1' : { + 'payload' : (Sdf.Payload(layer1.identifier, '/Ref'),) + }, + '/Prim2' : { + 'payload' : (Sdf.Payload(layer1.identifier, '/Ref/Child'),) + }, + '/Prim3' : { + 'payload' : (Sdf.Payload(layer1.identifier, + '/Ref/Child/GrandChild'),) + }, + }) + + # Verify the initial simple hierarchy in stage 1. + self._VerifyStageContents(stage1, { + 'Ref': { + '.' : ['refAttr'], + 'Child' : { + '.' : ['childAttr'], + 'GrandChild' : { + '.' : ['grandChildAttr'] + } + } + } + }) + + # Verify the initial composed prim contents for each prim in stage 2. + # Note that all prims are loaded at the start so all payload contents + # are composed with local prim specs. + prim1Contents = { + '.' : ['refAttr', 'localAttr'], + 'Child' : { + '.' : ['childAttr', 'overChildAttr'], + 'GrandChild' : { + '.' : ['grandChildAttr', 'overGrandChildAttr'] + }, + }, + 'LocalChild' : {}, + } + + prim2Contents = { + '.' : ['childAttr', 'overChildAttr', 'localAttr'], + 'GrandChild' : { + '.' : ['grandChildAttr', 'overGrandChildAttr'] + }, + 'LocalChild' : {}, + } + + prim3Contents = { + '.' : ['grandChildAttr', 'localAttr'], + 'LocalChild' : {}, + } + + self._VerifyStageContents(stage2, { + 'Prim1' : prim1Contents, + 'Prim2' : prim2Contents, + 'Prim3' : prim3Contents + }) + + # Edit: Rename /Ref/Child to /Ref/RenamedChild + with self.ApplyEdits(editor, "Move /Ref/Child -> /Ref/RenamedChild"): + self.assertTrue(editor.MovePrimAtPath( + '/Ref/Child', '/Ref/RenamedChild')) + + # Verify the udpated composition fields in layer2. The payload fields to + # /Ref/Child and its descendant /Ref/Child/GrandChild have been updated + # to use the renamed paths because all prims are currently loaded. + self.assertEqual(self._GetCompositionFieldsInLayer(layer2), { + '/Prim1' : { + 'payload' : (Sdf.Payload(layer1.identifier, '/Ref'),) + }, + '/Prim2' : { + 'payload' : (Sdf.Payload(layer1.identifier, '/Ref/RenamedChild'),) + }, + '/Prim3' : { + 'payload' : (Sdf.Payload(layer1.identifier, + '/Ref/RenamedChild/GrandChild'),) + }, + }) + + # Verify the expected simple rename in stage 1. + self._VerifyStageContents(stage1, { + 'Ref': { + '.' : ['refAttr'], + 'RenamedChild' : { + '.' : ['childAttr'], + 'GrandChild' : { + '.' : ['grandChildAttr'] + } + } + }, + }) + + # Verify the updated contents for stage 2. + # + # For /Prim1 which directly references /Ref, the child prim is renamed + # to RenamedChild. And just like with references, this means the local + # override specs for the prims introducing the payloads have been + # renamed to RenamedChild. + # + # The contents of the other two prims in each stage remain unchanged + # as the update to the payload fields allow those prims to remain the + # same. + prim1Contents = { + '.' : ['refAttr', 'localAttr'], + 'RenamedChild' : { + '.' : ['childAttr', 'overChildAttr'], + 'GrandChild' : { + '.' : ['grandChildAttr', 'overGrandChildAttr'] + }, + }, + 'LocalChild' : {}, + } + + self._VerifyStageContents(stage2, { + 'Prim1' : prim1Contents, + 'Prim2' : prim2Contents, + 'Prim3' : prim3Contents + }) + + # Now unload /Prim1 and /Prim3 so that we can demonstrate the one way + # that payload dependencies deviate from references. + stage2.Unload('/Prim1') + stage2.Unload('/Prim3') + + # Verify the contents of stage 2 with the prims unloaded. + # + # /Prim1 and /Prim3 are only composed from the their local opinions + # without the opinions from their payloads in layer 1 + prim1Contents = { + '.' : ['localAttr'], + 'RenamedChild' : { + '.' : ['overChildAttr'], + 'GrandChild' : { + '.' : ['overGrandChildAttr'], + }, + }, + 'LocalChild' : {}, + } + + prim3Contents = { + '.' : ['localAttr'], + 'LocalChild' : {}, + } + + self._VerifyStageContents(stage2, { + 'Prim1' : prim1Contents, + 'Prim2' : prim2Contents, + 'Prim3' : prim3Contents + }) + + # Edit: Rename /Ref/RenamedChild back to /Ref/Child + with self.ApplyEdits(editor, "Move /Ref/RenamedChild -> /Ref/Child"): + self.assertTrue(editor.MovePrimAtPath( + '/Ref/RenamedChild', '/Ref/Child')) + + # Verify the udpated composition fields in layer2. ONLY the payload for + # the still loaded /Prim2 is updated. The payload for /Prim1 would've + # been unaffected regardless of the load state, but /Prim3's payload + # can't be updated solely because it is unloaded. + self.assertEqual(self._GetCompositionFieldsInLayer(layer2), { + '/Prim1' : { + 'payload' : (Sdf.Payload(layer1.identifier, '/Ref'),) + }, + '/Prim2' : { + 'payload' : (Sdf.Payload(layer1.identifier, '/Ref/Child'),) + }, + '/Prim3' : { + 'payload' : (Sdf.Payload(layer1.identifier, + '/Ref/RenamedChild/GrandChild'),) + }, + }) + + # Verify the contents for stage 2 + # + # NONE of the prim contents have changed but for a different reasons. + # /Prim1 and /Prim3 have not changed because the payloads are unloaded + # and there is no dependency on the payload path for which to propagate + # dependent edits. + # /Prim2 is unchanged because the loaded payload's path has been updated + # to the new path. + self._VerifyStageContents(stage2, { + 'Prim1' : prim1Contents, + 'Prim2' : prim2Contents, + 'Prim3' : prim3Contents + }) + + # Now load /Prim1 and /Prim3 again. Loading /Prim3 will emit warnings + # because of the payload points to path that no longer exists in layer1. + stage2.Load('/Prim1') + print("\n=== EXPECT WARNINGS ===", file=sys.stderr) + stage2.Load('/Prim3') + print("\n=== END EXPECTED WARNINGS ===", file=sys.stderr) + + # Verify the post-edit contents for stage 2 now with all prims loaded. + # + # The contents of /Prim1 and /Prim3 with payloads loaded show how we + # couldn't correctly update the dependent paths for the unloaded + # payloads when doing the prior rename back. + # + # The now loaded /Prim1 is in a partially edited state as we weren't + # able to move the the local RenamedChild specs back to Child while the + # prim was unloaded. + # + # The now loaded /Prim3 is unchanged from its unloaded state as the + # payload path still points to /Ref/RenamedChild/GrandChild which no + # longer exists at that path (and we have an unresolved payload + # composition error on this prim now). + prim1Contents = { + '.' : ['refAttr', 'localAttr'], + 'Child' : { + '.' : ['childAttr'], + 'GrandChild' : { + '.' : ['grandChildAttr'] + }, + }, + 'RenamedChild' : { + '.' : ['overChildAttr'], + 'GrandChild' : { + '.' : ['overGrandChildAttr'], + }, + }, + 'LocalChild' : {}, + } + + self._VerifyStageContents(stage2, { + 'Prim1' : prim1Contents, + 'Prim2' : prim2Contents, + 'Prim3' : prim3Contents + }) + + def test_BasicNestedReferences(self): + """Test downstream dependency name space edits across chains of + references.""" + + # Setup: + # Layer 1 has simple hierarchy of /Ref, Child, GrandChild that is + # referenced and will be namespace edited. + layer1 = Sdf.Layer.CreateAnonymous("layer1.usda") + layer1.ImportFromString('''#usda 1.0 + def "Ref" { + int refAttr + + def "Child" { + int childAttr + + def "GrandChild" { + int grandChildAttr + } + } + } + ''') + + # Layer 2 has three prims that reference /Ref, /Ref/Child, and + # /Ref/Child/GrandChild from layer 1 respectively. These will be + # affected by downstream dependency edits. + layer2 = Sdf.Layer.CreateAnonymous("layer2.usda") + layer2.ImportFromString('''#usda 1.0 + def "Prim1" ( + references = @''' + layer1.identifier + '''@ + ) { + over "Child" { + int over1ChildAttr + over "GrandChild" { + int over1GrandChildAttr + } + } + def "Prim1_LocalChild" {} + int prim1_localAttr + } + + def "Prim2" ( + references = @''' + layer1.identifier + '''@ + ) { + over "GrandChild" { + int over2GrandChildAttr + } + def "Prim2_LocalChild" {} + int prim2_localAttr + } + + def "Prim3" ( + references = @''' + layer1.identifier + '''@ + ) { + def "Prim3_LocalChild" {} + int prim3_LocalAttr + } + ''') + + # Layer3 has multiple prims that each reference the possible + # prims in layer2 in order to test the various permutations of direct + # and ancestral reference chains. + # /Prim4 : References /Prim1 which directly references /Ref + # /Prim4_A : References /Prim1/Child which ancestrally references + # /Ref/Child + # /Prim4_B : References /Prim1/Child/GrandChild which ancestrally + # references /Ref/Child/GrandChild + # /Prim5 : References /Prim2 which directly references /Ref/Child + # /Prim5_A : References /Prim2/GrandChild which ancestrally references + # /Ref/Child/GrandChild + # /Prim6 : References /Prim3 which directly references + # /Ref/Child/GrandChild + layer3 = Sdf.Layer.CreateAnonymous("layer3.usda") + layer3.ImportFromString('''#usda 1.0 + def "Prim4" ( + references = @''' + layer2.identifier + '''@ + ) { + over "Child" { + int over4ChildAttr + over "GrandChild" { + int over4GrandChildAttr + } + } + def "LocalChild" {} + int localAttr + } + + def "Prim4_A" ( + references = @''' + layer2.identifier + '''@ + ) { + over "GrandChild" { + int over4_AGrandChildAttr + } + def "LocalChild" {} + int localAttr + } + + def "Prim4_B" ( + references = @''' + layer2.identifier + '''@ + ) { + def "LocalChild" {} + int localAttr + } + + def "Prim5" ( + references = @''' + layer2.identifier + '''@ + ) { + over "GrandChild" { + int over5GrandChildAttr + } + def "LocalChild" {} + int localAttr + } + + def "Prim5_A" ( + references = @''' + layer2.identifier + '''@ + ) { + def "LocalChild" {} + int localAttr + } + + def "Prim6" ( + references = @''' + layer2.identifier + '''@ + ) { + def "LocalChild" {} + int localAttr + } + ''') + + # Open all three layers as stages. + stage1 = Usd.Stage.Open(layer1, Usd.Stage.LoadAll) + stage2 = Usd.Stage.Open(layer2, Usd.Stage.LoadAll) + stage3 = Usd.Stage.Open(layer3, Usd.Stage.LoadAll) + + # Create an editor for stage1 with ONLY stage 3 as a dependent stage + # (i.e. excluding stage 2). This will still cause edits to layer2 when + # layer1 is edited as stage3 has dependencies on layer 2 and thus, these + # changes will be reflected in stage 2. + editor = Usd.NamespaceEditor(stage1) + editor.AddDependentStage(stage3) + + # Verify the initial composition fields for each layer. + self.assertEqual(self._GetCompositionFieldsInLayer(layer1), {}) + + self.assertEqual(self._GetCompositionFieldsInLayer(layer2), { + '/Prim1' : { + 'references' : (Sdf.Reference(layer1.identifier, '/Ref'),) + }, + '/Prim2' : { + 'references' : (Sdf.Reference(layer1.identifier, '/Ref/Child'),) + }, + '/Prim3' : { + 'references' : (Sdf.Reference(layer1.identifier, + '/Ref/Child/GrandChild'),) + }, + }) + + self.assertEqual(self._GetCompositionFieldsInLayer(layer3), { + '/Prim4' : { + 'references' : (Sdf.Reference(layer2.identifier, '/Prim1'),) + }, + '/Prim4_A' : { + 'references' : (Sdf.Reference(layer2.identifier, '/Prim1/Child'),) + }, + '/Prim4_B' : { + 'references' : (Sdf.Reference(layer2.identifier, + '/Prim1/Child/GrandChild'),) + }, + '/Prim5' : { + 'references' : (Sdf.Reference(layer2.identifier, '/Prim2'),) + }, + '/Prim5_A' : { + 'references' : (Sdf.Reference(layer2.identifier, + '/Prim2/GrandChild'),) + }, + '/Prim6' : { + 'references' : (Sdf.Reference(layer2.identifier, '/Prim3'),) + }, + }) + + # Verify the initial contents of stage 1. + self._VerifyStageContents(stage1, { + 'Ref': { + '.' : ['refAttr'], + 'Child' : { + '.' : ['childAttr'], + 'GrandChild' : { + '.' : ['grandChildAttr'] + } + } + }, + }) + + # Verify the initial contents of stage 2 with its three single + # reference composed prims + prim1Contents = { + '.' : ['refAttr', 'prim1_localAttr'], + 'Child' : { + '.' : ['childAttr', 'over1ChildAttr'], + 'GrandChild' : { + '.' : ['grandChildAttr', 'over1GrandChildAttr'] + }, + }, + 'Prim1_LocalChild' : {}, + } + + prim2Contents = { + '.' : ['childAttr', 'prim2_localAttr'], + 'GrandChild' : { + '.' : ['grandChildAttr', 'over2GrandChildAttr'] + }, + 'Prim2_LocalChild' : {}, + } + + prim3Contents = { + '.' : ['grandChildAttr', 'prim3_LocalAttr'], + 'Prim3_LocalChild' : {}, + } + + self._VerifyStageContents(stage2, { + 'Prim1' : prim1Contents, + 'Prim2' : prim2Contents, + 'Prim3' : prim3Contents + }) + + # Verify the initial contents of stage 3 with its all its prims composed + # from 2-chain references + prim4Contents = { + '.' : ['refAttr', 'prim1_localAttr', 'localAttr'], + 'Child' : { + '.' : ['childAttr', 'over1ChildAttr', 'over4ChildAttr'], + 'GrandChild' : { + '.' : ['grandChildAttr', 'over1GrandChildAttr', + 'over4GrandChildAttr'] + }, + }, + 'Prim1_LocalChild' : {}, + 'LocalChild' : {}, + } + + prim4_AContents = { + '.' : ['childAttr', 'over1ChildAttr', 'localAttr'], + 'GrandChild' : { + '.' : ['grandChildAttr', 'over1GrandChildAttr', + 'over4_AGrandChildAttr'] + }, + 'LocalChild' : {}, + } + + prim4_BContents = { + '.' : ['grandChildAttr', 'over1GrandChildAttr', 'localAttr'], + 'LocalChild' : {}, + } + + prim5Contents = { + '.' : ['childAttr', 'prim2_localAttr', 'localAttr'], + 'GrandChild' : { + '.' : ['grandChildAttr', 'over2GrandChildAttr', + 'over5GrandChildAttr'] + }, + 'Prim2_LocalChild' : {}, + 'LocalChild' : {}, + } + + prim5_AContents = { + '.' : ['grandChildAttr', 'over2GrandChildAttr', 'localAttr'], + 'LocalChild' : {}, + } + + prim6Contents = { + '.' : ['grandChildAttr', 'prim3_LocalAttr', 'localAttr'], + 'Prim3_LocalChild' : {}, + 'LocalChild' : {}, + } + + self._VerifyStageContents(stage3, { + 'Prim4' : prim4Contents, + 'Prim4_A' : prim4_AContents, + 'Prim4_B' : prim4_BContents, + 'Prim5' : prim5Contents, + 'Prim5_A' : prim5_AContents, + 'Prim6' : prim6Contents + }) + + # Edit: Rename /Ref/Child to /Ref/RenamedChild on stage 1. + with self.ApplyEdits(editor, "Move /Ref/Child -> /Ref/RenamedChild"): + self.assertTrue(editor.MovePrimAtPath( + '/Ref/Child', '/Ref/RenamedChild')) + + # Verify the udpated composition fields in layer2. The reference fields + # to /Ref/Child and its descendant /Ref/Child/GrandChild have been + # updated to use the renamed paths. + self.assertEqual(self._GetCompositionFieldsInLayer(layer2), { + '/Prim1' : { + 'references' : (Sdf.Reference(layer1.identifier, '/Ref'),) + }, + '/Prim2' : { + 'references' : (Sdf.Reference(layer1.identifier, + '/Ref/RenamedChild'),) + }, + '/Prim3' : { + 'references' : (Sdf.Reference(layer1.identifier, + '/Ref/RenamedChild/GrandChild'),) + }, + }) + + # Verify the udpated composition fields in layer3. The reference + # fields to /Prim1/Child and its descendant /Prim1/Child/GrandChild have + # to be updated as all the specs composing /Prim1/Child are renamed to + # RenamedChild by the dependent edits. + self.assertEqual(self._GetCompositionFieldsInLayer(layer3), { + '/Prim4' : { + 'references' : (Sdf.Reference(layer2.identifier, '/Prim1'),) + }, + '/Prim4_A' : { + 'references' : (Sdf.Reference(layer2.identifier, + '/Prim1/RenamedChild'),) + }, + '/Prim4_B' : { + 'references' : (Sdf.Reference(layer2.identifier, + '/Prim1/RenamedChild/GrandChild'),) + }, + '/Prim5' : { + 'references' : (Sdf.Reference(layer2.identifier, '/Prim2'),) + }, + '/Prim5_A' : { + 'references' : (Sdf.Reference(layer2.identifier, + '/Prim2/GrandChild'),) + }, + '/Prim6' : { + 'references' : (Sdf.Reference(layer2.identifier, '/Prim3'),) + }, + }) + + # Verify the simple prim rename is reflected in contents of stage 1. + self._VerifyStageContents(stage1, { + 'Ref': { + '.' : ['refAttr'], + 'RenamedChild' : { + '.' : ['childAttr'], + 'GrandChild' : { + '.' : ['grandChildAttr'] + } + } + }, + }) + + # Verify the udpated contents of stage 2. + # + # There are prims in stage 3 that reference /Prim1/Child on layer2 so + # which ancestrally references /Ref/Child. So the specs for /Prim1/Child + # on layer 2 are renamed to RenamedChild for this dependency. This + # change is reflected in the contents of stage 2. + # + # Stage 3 also has prims with dependencies on /Prim2 and /Prim3, but + # the contents of those two prims remain the same as the reference paths + # are just updated to /Ref/RenamedChild and /Ref/RenamedChild/GrandChild. + prim1Contents = { + '.' : ['refAttr', 'prim1_localAttr'], + 'RenamedChild' : { + '.' : ['childAttr', 'over1ChildAttr'], + 'GrandChild' : { + '.' : ['grandChildAttr', 'over1GrandChildAttr'] + }, + }, + 'Prim1_LocalChild' : {}, + } + + self._VerifyStageContents(stage2, { + 'Prim1' : prim1Contents, + 'Prim2' : prim2Contents, + 'Prim3' : prim3Contents + }) + + # Verify the updated contents of stage 3. + # + # /Prim4 references /Prim1 which references /Ref so /Prim4/Child is also + # renamed to /Prim4/RenamedChild. + # No other prims' contents change as they each had one of their nested + # references arcs updated to the new path. + prim4Contents = { + '.' : ['refAttr', 'prim1_localAttr', 'localAttr'], + 'RenamedChild' : { + '.' : ['childAttr', 'over1ChildAttr', 'over4ChildAttr'], + 'GrandChild' : { + '.' : ['grandChildAttr', 'over1GrandChildAttr', + 'over4GrandChildAttr'] + }, + }, + 'Prim1_LocalChild' : {}, + 'LocalChild' : {}, + } + + self._VerifyStageContents(stage3, { + 'Prim4' : prim4Contents, + 'Prim4_A' : prim4_AContents, + 'Prim4_B' : prim4_BContents, + 'Prim5' : prim5Contents, + 'Prim5_A' : prim5_AContents, + 'Prim6' : prim6Contents + }) + + # Edit: Reparent and rename /Ref/RenamedChild to /MovedChild + with self.ApplyEdits(editor, "Move /Ref/RenamedChild -> /MovedChild"): + self.assertTrue(editor.MovePrimAtPath( + '/Ref/RenamedChild', '/MovedChild')) + + # Verify the udpated composition fields in layer2. The reference fields + # to /Ref/RenamedChild and its descendant /Ref/RenamedChild/GrandChild + # have been updated to use the moved paths. + self.assertEqual(self._GetCompositionFieldsInLayer(layer2), { + '/Prim1' : { + 'references' : (Sdf.Reference(layer1.identifier, '/Ref'),) + }, + '/Prim2' : { + 'references' : (Sdf.Reference(layer1.identifier, '/MovedChild'),) + }, + '/Prim3' : { + 'references' : (Sdf.Reference(layer1.identifier, + '/MovedChild/GrandChild'),) + }, + }) + + # Verify the udpated composition fields in layer3. Like with the + # previous edit, the reference fields to /Prim1/RenamedChild and + # its descendant /Prim1/RenamedChild/GrandChild have to be updated as + # all the specs composing /Prim1/RenameChild have been moved by the + # dependent edits. However, since RenamedChild was moved out /Ref, it no + # longer maps across the reference to /Prim1 which results in the + # deletion of the composed /Prim1/RenamedChild. So the reference fields + # for /Prim4_A and /Prim4_B are updated to delete these references to + # prims that no longer exist in layer2. + self.assertEqual(self._GetCompositionFieldsInLayer(layer3), { + '/Prim4' : { + 'references' : (Sdf.Reference(layer2.identifier, '/Prim1'),) + }, + '/Prim4_A' : { + 'references' : () + }, + '/Prim4_B' : { + 'references' : () + }, + '/Prim5' : { + 'references' : (Sdf.Reference(layer2.identifier, '/Prim2'),) + }, + '/Prim5_A' : { + 'references' : (Sdf.Reference(layer2.identifier, + '/Prim2/GrandChild'),) + }, + '/Prim6' : { + 'references' : (Sdf.Reference(layer2.identifier, '/Prim3'),) + }, + }) + + # Verify the simple reparent and rename is reflected in contents of + # stage 1. + self._VerifyStageContents(stage1, { + 'Ref': { + '.' : ['refAttr'], + }, + 'MovedChild' : { + '.' : ['childAttr'], + 'GrandChild' : { + '.' : ['grandChildAttr'] + } + } + }) + + # Verify the udpated contents of stage 2. + # + # There are prims in stage 3 that reference /Prim1/RenamedChild on + # layer2 which ancestrally references /Ref/RenamedChild. So the specs + # for /Prim1/RenamedChild on layer 2 are deleted for this dependency + # (since the RenamedChild was moved out of the reference). This change + # is reflected in the contents of stage 2. + # + # Stage 3 also has prims with dependencies on /Prim2 and /Prim3, but + # these contents remain the same as the reference paths are + # just updated to /MovedChild and /MovedChild/GrandChild. + prim1Contents = { + '.' : ['refAttr', 'prim1_localAttr'], + 'Prim1_LocalChild' : {}, + } + + self._VerifyStageContents(stage2, { + 'Prim1' : prim1Contents, + 'Prim2' : prim2Contents, + 'Prim3' : prim3Contents + }) + + # Verify the updated contents of stage 3. + # + # /Prim4 references /Prim1 which references /Ref so /Prim4/RenamedChild + # is also deleted. /Prim4_A and /Prim4_B have lost their references so + # these also only have the contents of their local specs. + # + # The rest of the prims have no contents change as they each had one of + # their nested references arcs updated to the new path. + prim4Contents = { + '.' : ['refAttr', 'prim1_localAttr', 'localAttr'], + 'Prim1_LocalChild' : {}, + 'LocalChild' : {}, + } + + prim4_AContents = { + '.' : ['localAttr'], + 'LocalChild' : {}, + } + + prim4_BContents = { + '.' : ['localAttr'], + 'LocalChild' : {}, + } + + self._VerifyStageContents(stage3, { + 'Prim4' : prim4Contents, + 'Prim4_A' : prim4_AContents, + 'Prim4_B' : prim4_BContents, + 'Prim5' : prim5Contents, + 'Prim5_A' : prim5_AContents, + 'Prim6' : prim6Contents + }) + + # Edit: Reparent and rename /MovedChild back to its original path + # /Ref/Child + with self.ApplyEdits(editor, "Move /MovedChild -> /Ref/Child"): + self.assertTrue(editor.MovePrimAtPath('/MovedChild', '/Ref/Child')) + + # Verify the udpated composition fields in layer2. The reference fields + # have all been updated to their original paths. + self.assertEqual(self._GetCompositionFieldsInLayer(layer2), { + '/Prim1' : { + 'references' : (Sdf.Reference(layer1.identifier, '/Ref'),) + }, + '/Prim2' : { + 'references' : (Sdf.Reference(layer1.identifier, '/Ref/Child'),) + }, + '/Prim3' : { + 'references' : (Sdf.Reference(layer1.identifier, + '/Ref/Child/GrandChild'),) + }, + }) + + # Verify the udpated composition fields in layer3 which have NOT changed + # because the prior edit deleted both references that initially + # referred to /Prim1/Child. + self.assertEqual(self._GetCompositionFieldsInLayer(layer3), { + '/Prim4' : { + 'references' : (Sdf.Reference(layer2.identifier, '/Prim1'),) + }, + '/Prim4_A' : { + 'references' : () + }, + '/Prim4_B' : { + 'references' : () + }, + '/Prim5' : { + 'references' : (Sdf.Reference(layer2.identifier, '/Prim2'),) + }, + '/Prim5_A' : { + 'references' : (Sdf.Reference(layer2.identifier, '/Prim2/GrandChild'),) + }, + '/Prim6' : { + 'references' : (Sdf.Reference(layer2.identifier, '/Prim3'),) + }, + }) + + # Verify the return to the the original contents in stage 1. + self._VerifyStageContents(stage1, { + 'Ref': { + '.' : ['refAttr'], + 'Child' : { + '.' : ['childAttr'], + 'GrandChild' : { + '.' : ['grandChildAttr'] + } + } + }, + }) + + # Verify the udpated contents of stage 2. + # + # The contents of /Prim1 have returned to the original contents with + # the exception that the local opinions for Child and GrandChild in + # layer2 were deleted in the prior edit and cannot be restored. + # + # /Prim2 and /Prim3 remain unchanged. + prim1Contents = { + '.' : ['refAttr', 'prim1_localAttr'], + 'Child' : { + '.' : ['childAttr'], + 'GrandChild' : { + '.' : ['grandChildAttr'] + }, + }, + 'Prim1_LocalChild' : {}, + } + + self._VerifyStageContents(stage2, { + 'Prim1' : prim1Contents, + 'Prim2' : prim2Contents, + 'Prim3' : prim3Contents + }) + + # Verify the updated contents of stage 3. + # + # /Prim4 returns to its original contents with the exception that + # deleted local opinions on layer3 for Child and the deleted opinions + # from /Prim1/Child on layer2 cannot be restored. + # + # /Prim4_A and /Prim4_B remain unchanged (and therefore unrestored) + # because their references were deleted by the previous edit. + # + # The rest of the prims continue to have no contents change as they each + # had one of their nested references arcs updated to the original path. + prim4Contents = { + '.' : ['refAttr', 'prim1_localAttr', 'localAttr'], + 'Child' : { + '.' : ['childAttr'], + 'GrandChild' : { + '.' : ['grandChildAttr'] + }, + }, + 'Prim1_LocalChild' : {}, + 'LocalChild' : {}, + } + + self._VerifyStageContents(stage3, { + 'Prim4' : prim4Contents, + 'Prim4_A' : prim4_AContents, + 'Prim4_B' : prim4_BContents, + 'Prim5' : prim5Contents, + 'Prim5_A' : prim5_AContents, + 'Prim6' : prim6Contents + }) + + # Edit: Delete /Ref/Child + with self.ApplyEdits(editor, "Delete /Ref/Child"): + self.assertTrue(editor.DeletePrimAtPath('/Ref/Child')) + + # Verify the udpated composition fields in layer2. The reference fields + # to /Ref/Child and its descendant /Ref/Child/GrandChild have been + # set to empty now that those prims don't exist on layer1 + self.assertEqual(self._GetCompositionFieldsInLayer(layer2), { + '/Prim1' : { + 'references' : (Sdf.Reference(layer1.identifier, '/Ref'),) + }, + '/Prim2' : { + 'references' : () + }, + '/Prim3' : { + 'references' : () + }, + }) + + # Verify the udpated composition fields in layer3. The only change now + # is that /Prim5_A's reference to /Prim2/GrandChild has been deleted as + # /Prim2/GrandChild is no a valid composed prim of layer2. + self.assertEqual(self._GetCompositionFieldsInLayer(layer3), { + '/Prim4' : { + 'references' : (Sdf.Reference(layer2.identifier, '/Prim1'),) + }, + '/Prim4_A' : { + 'references' : () + }, + '/Prim4_B' : { + 'references' : () + }, + '/Prim5' : { + 'references' : (Sdf.Reference(layer2.identifier, '/Prim2'),) + }, + '/Prim5_A' : { + 'references' : () + }, + '/Prim6' : { + 'references' : (Sdf.Reference(layer2.identifier, '/Prim3'),) + }, + }) + + # Verify the deletion of Child on stage 1. + self._VerifyStageContents(stage1, { + 'Ref': { + '.' : ['refAttr'], + }, + }) + + # Verify the udpated contents of stage 2. + # + # The contents of /Prim1 no longer have the child Child. + # + # /Prim2 and /Prim3 have lost their references so only have local + # opinions from layer2. + prim1Contents = { + '.' : ['refAttr', 'prim1_localAttr'], + 'Prim1_LocalChild' : {}, + } + + prim2Contents = { + '.' : ['prim2_localAttr'], + 'Prim2_LocalChild' : {}, + } + + prim3Contents = { + '.' : ['prim3_LocalAttr'], + 'Prim3_LocalChild' : {}, + } + + self._VerifyStageContents(stage2, { + 'Prim1' : prim1Contents, + 'Prim2' : prim2Contents, + 'Prim3' : prim3Contents + }) + + # Verify the updated contents of stage 3. + # + # /Prim4 loses all opinions about Child. + # + # /Prim4_A and /Prim4_B remain unchanged still because of the prior + # deleted references. + # + # /Prim5 and /Prim6 are affected by the deletion of the references on + # /Prim2 and /Prim3 respectively, but they still composed the layer2 + # local opinions from /Prim2 and /Prim3 + # + # /Prim5_A only has its own local opinions because its own reference + # has also been deleted. + prim4Contents = { + '.' : ['refAttr', 'prim1_localAttr', 'localAttr'], + 'Prim1_LocalChild' : {}, + 'LocalChild' : {}, + } + + prim5Contents = { + '.' : ['prim2_localAttr', 'localAttr'], + 'Prim2_LocalChild' : {}, + 'LocalChild' : {}, + } + + prim5_AContents = { + '.' : ['localAttr'], + 'LocalChild' : {}, + } + + prim6Contents = { + '.' : ['prim3_LocalAttr', 'localAttr'], + 'Prim3_LocalChild' : {}, + 'LocalChild' : {}, + } + + self._VerifyStageContents(stage3, { + 'Prim4' : prim4Contents, + 'Prim4_A' : prim4_AContents, + 'Prim4_B' : prim4_BContents, + 'Prim5' : prim5Contents, + 'Prim5_A' : prim5_AContents, + 'Prim6' : prim6Contents + }) + +if __name__ == '__main__': + unittest.main() diff --git a/pxr/usd/usd/testenv/testUsdNamespaceEditorDependentEditsBasicSublayers.py b/pxr/usd/usd/testenv/testUsdNamespaceEditorDependentEditsBasicSublayers.py new file mode 100644 index 00000000000..7de3777c2a2 --- /dev/null +++ b/pxr/usd/usd/testenv/testUsdNamespaceEditorDependentEditsBasicSublayers.py @@ -0,0 +1,894 @@ +#!/pxrpythonsubst +# +# Copyright 2024 Pixar +# +# Licensed under the terms set forth in the LICENSE.txt file available at +# https://openusd.org/license. + +import unittest +from pxr import Sdf, Usd +from testUsdNamespaceEditorDependentEditsBase \ + import TestUsdNamespaceEditorDependentEditsBase + +class TestUsdNamespaceEditorDependentEditsBasicRelocates( + TestUsdNamespaceEditorDependentEditsBase): + '''Tests downstream dependency namespace edits across sublayers. + ''' + + def test_BasicDependentSublayers(self): + """Tests downstream dependency namespace edits across sublayers from + other dependent stages.""" + + # Setup: + # Layer1 is a simple base layer with a prim hierarchy of /Ref, + # Child, and GrandChild. This layer will be opened as the base stage + # that direct namespace edits will be performed on. + layer1 = Sdf.Layer.CreateAnonymous("layer1.usda") + layer1.ImportFromString('''#usda 1.0 + def "Ref" ( + ) { + int refAttr + + def "Child" { + int childAttr + + def "GrandChild" { + int grandChildAttr + } + } + } + ''') + + # Layer2 includes layer1 as a sublayer and provides opinions for Ref + # Child and GrandChild. + layer2 = Sdf.Layer.CreateAnonymous("layer2.usda") + layer2.ImportFromString('''#usda 1.0 + ( + subLayers = [@''' + layer1.identifier + '''@] + ) + + over "Ref" ( + ) { + int over2RefAttr + + over "Child" { + int over2ChildAttr + + over "GrandChild" { + int over2GrandChildAttr + } + } + } + ''') + + # Layer3Sub will be a sublayer of the next layer, layer3 and provides + # opinions for Ref Child and GrandChild. + layer3Sub = Sdf.Layer.CreateAnonymous("layer3-sub.usda") + layer3Sub.ImportFromString('''#usda 1.0 + over "Ref" ( + ) { + int overSub3RefAttr + + over "Child" { + int overSub3ChildAttr + + over "GrandChild" { + int overSub3GrandChildAttr + } + } + } + ''') + + # Layer3 includes layer2 (which includes layer1) and layer3Sub as + # sublayer and also includes local opionion for the prims. + layer3 = Sdf.Layer.CreateAnonymous("layer3.usda") + layer3.ImportFromString('''#usda 1.0 + ( + subLayers = [ + @''' + layer2.identifier + '''@, + @''' + layer3Sub.identifier + '''@ + ] + ) + + over "Ref" ( + ) { + int over3RefAttr + + over "Child" { + int over3ChildAttr + + over "GrandChild" { + int over3GrandChildAttr + } + } + } + ''') + + # Layer4 includes layer3 as a sublayer as well as its own local + # opinions for the same prims. + layer4 = Sdf.Layer.CreateAnonymous("layer4.usda") + layer4.ImportFromString('''#usda 1.0 + ( + subLayers = [@''' + layer3.identifier + '''@] + ) + + over "Ref" ( + ) { + int over4RefAttr + + over "Child" { + int over4ChildAttr + + over "GrandChild" { + int over4GrandChildAttr + } + } + } + ''') + + # Open stages for the 4 main layers (excludes layer3Sub) + stage1 = Usd.Stage.Open(layer1) + stage2 = Usd.Stage.Open(layer2) + stage3 = Usd.Stage.Open(layer3) + stage4 = Usd.Stage.Open(layer4) + + # Create a namespace editor for stage1 which only includes layer1. + editor = Usd.NamespaceEditor(stage1) + + # Add ONLY stage3 as a dependent stage. This is to specifically show + # how layer2 will be affected by edits because stage3 depends on it + # but layer4 will not be affected as stage4 would've needed to be added + # to introduce any dependencies on layer4. + editor.AddDependentStage(stage3) + + # Verify initial contents of each stage. + + # Stage1 only includes opinions from layer1 + stage1ChildContents = { + '.' : ['childAttr'], + 'GrandChild' : { + '.' : ['grandChildAttr'], + } + } + + self._VerifyStageContents(stage1, { + 'Ref': { + '.' : ['refAttr'], + 'Child' : stage1ChildContents + }, + }) + + # Stage2's contents come from layer1 and layer2. + stage2ChildContents = { + '.' : ['childAttr', 'over2ChildAttr'], + 'GrandChild' : { + '.' : ['grandChildAttr', 'over2GrandChildAttr'], + } + } + + self._VerifyStageContents(stage2, { + 'Ref': { + '.' : ['refAttr', 'over2RefAttr'], + 'Child' : stage2ChildContents + }, + }) + + # Stage3's contents come from layers 1, 2, 3, and 3Sub. + stage3ChildContents = { + '.' : ['childAttr', 'over2ChildAttr', 'over3ChildAttr', + 'overSub3ChildAttr'], + 'GrandChild' : { + '.' : ['grandChildAttr', 'over2GrandChildAttr', + 'over3GrandChildAttr', 'overSub3GrandChildAttr'], + } + } + + self._VerifyStageContents(stage3, { + 'Ref': { + '.' : ['refAttr', 'over2RefAttr', 'over3RefAttr', + 'overSub3RefAttr'], + 'Child' : stage3ChildContents + }, + }) + + # Stage4's contents come from all layers: 1, 2 3, 3Sub, and 4 + stage4CombinedChildContents = { + '.' : ['childAttr', 'over2ChildAttr', 'over3ChildAttr', + 'overSub3ChildAttr', 'over4ChildAttr'], + 'GrandChild' : { + '.' : ['grandChildAttr', 'over2GrandChildAttr', + 'over3GrandChildAttr', 'overSub3GrandChildAttr', + 'over4GrandChildAttr'], + } + } + + self._VerifyStageContents(stage4, { + 'Ref': { + '.' : ['refAttr', 'over2RefAttr', 'over3RefAttr', + 'overSub3RefAttr', 'over4RefAttr'], + 'Child' : stage4CombinedChildContents + }, + }) + + # Edit: Rename /Ref/Child to /Ref/RenamedChild + with self.ApplyEdits(editor, "Move /Ref/Child -> /Ref/RenamedChild"): + self.assertTrue(editor.MovePrimAtPath( + '/Ref/Child', '/Ref/RenamedChild')) + + # Verify the direct rename on stage1 + self._VerifyStageContents(stage1, { + 'Ref': { + '.' : ['refAttr'], + 'RenamedChild' : stage1ChildContents + }, + }) + + # Stage2 was not added as a dependent stage, but layer2 is dependent on + # layer1 edits via stage3 so stage2 reflects the rename in layer1 and + # layer2. + self._VerifyStageContents(stage2, { + 'Ref': { + '.' : ['refAttr', 'over2RefAttr'], + 'RenamedChild' : stage2ChildContents + }, + }) + + # Stage3 is a dependent stage of the editor and depends on layer1 edits + # through sublayers, so all sublayers in the dependent layer stack of + # layer3 (this includes layer3Sub) are affected by the rename and Child + # is fully renamed in stage3. + self._VerifyStageContents(stage3, { + 'Ref': { + '.' : ['refAttr', 'over2RefAttr', 'over3RefAttr', + 'overSub3RefAttr'], + 'RenamedChild' : stage3ChildContents + }, + }) + + # Stage4 is not a dependent stage so layer4 is not updated even though + # all its other sublayers have been edited. Thus stage4 has both Child + # and RenamedChild where Child has only opinions from layer4 while + # RenamedChild has the opinions from all other layers. + layer4OnlyChildContents = { + '.' : ['over4ChildAttr'], + 'GrandChild' : { + '.' : ['over4GrandChildAttr'], + } + } + + self._VerifyStageContents(stage4, { + 'Ref': { + '.' : ['refAttr', 'over2RefAttr', 'over3RefAttr', + 'overSub3RefAttr', 'over4RefAttr'], + 'Child' : layer4OnlyChildContents, + 'RenamedChild' : stage3ChildContents + }, + }) + + # Edit: Reparent and rename /Ref/RenamedChild to /MovedChild + with self.ApplyEdits(editor, "Move /Ref/RenamedChild -> /MovedChild"): + self.assertTrue(editor.MovePrimAtPath( + '/Ref/RenamedChild', '/MovedChild')) + + # Verify the direct reparent and rename on stage1 + self._VerifyStageContents(stage1, { + 'Ref': { + '.' : ['refAttr'], + }, + 'MovedChild' : stage1ChildContents + }) + + # Like with the rename edit previously, RenamedChild is moved to + # /MovedChild in all layers and is reflected as a move in both stage2 + # and stage3. + self._VerifyStageContents(stage2, { + 'Ref': { + '.' : ['refAttr', 'over2RefAttr'], + }, + 'MovedChild' : stage2ChildContents + }) + + self._VerifyStageContents(stage3, { + 'Ref': { + '.' : ['refAttr', 'over2RefAttr', 'over3RefAttr', 'overSub3RefAttr'], + }, + 'MovedChild' : stage3ChildContents + }) + + # And RenamedChild is also fully moved to /MovedChild in stage4. But + # note that the specs for Child in layer4 were not renamed in the first + # edit so Child still exists with the same "layer4 only" contents as + # before. + self._VerifyStageContents(stage4, { + 'Ref': { + '.' : ['refAttr', 'over2RefAttr', 'over3RefAttr', + 'overSub3RefAttr', 'over4RefAttr'], + 'Child' : layer4OnlyChildContents, + }, + 'MovedChild' : stage3ChildContents + }) + + # Edit: Reparent and rename /MovedChild back to its original path + # /Ref/Child + with self.ApplyEdits(editor, "Move /MovedChild -> /Ref/Child"): + self.assertTrue(editor.MovePrimAtPath('/MovedChild', '/Ref/Child')) + + # All stages return to their exact original contents. + self._VerifyStageContents(stage1, { + 'Ref': { + '.' : ['refAttr'], + 'Child' : stage1ChildContents + }, + }) + + self._VerifyStageContents(stage2, { + 'Ref': { + '.' : ['refAttr', 'over2RefAttr'], + 'Child' : stage2ChildContents + }, + }) + + self._VerifyStageContents(stage3, { + 'Ref': { + '.' : ['refAttr', 'over2RefAttr', 'over3RefAttr', + 'overSub3RefAttr'], + 'Child' : stage3ChildContents + }, + }) + + # This includes stage4 where layer4's Child opinions are once again + # composed with the Child opinions from the other sublayers. + self._VerifyStageContents(stage4, { + 'Ref': { + '.' : ['refAttr', 'over2RefAttr', 'over3RefAttr', + 'overSub3RefAttr', 'over4RefAttr'], + 'Child' : stage4CombinedChildContents + }, + }) + + # Edit: Delete the prim at /Ref/Child + with self.ApplyEdits(editor, "Delete /Ref/Child"): + self.assertTrue(editor.DeletePrimAtPath('/Ref/Child')) + + # Verify the direct delete on stage1 + self._VerifyStageContents(stage1, { + 'Ref': { + '.' : ['refAttr'], + }, + }) + + # Stage2 was not added as a dependent stage, but layer2 is dependent on + # layer1 edits via stage3 so stage2 reflects the delete of Child in + # layer1 and layer2. + self._VerifyStageContents(stage2, { + 'Ref': { + '.' : ['refAttr', 'over2RefAttr'], + }, + }) + + # Stage3 is a dependent stage of the editor and depends on layer1 edits + # through sublayers, so all sublayers in the dependent layer stack of + # layer3 are affected by the deletion and Child is fully deleted in + # stage3. + self._VerifyStageContents(stage3, { + 'Ref': { + '.' : ['refAttr', 'over2RefAttr', 'over3RefAttr', + 'overSub3RefAttr'], + }, + }) + + # Stage4 is not a dependent stage so layer4 is not updated even though + # all its other sublayers have been edited. Thus stage4 still has Child + # which now only has opinions from layer4 as the Child opinions from all + # other sublayers have been deleted. + self._VerifyStageContents(stage4, { + 'Ref': { + '.' : ['refAttr', 'over2RefAttr', 'over3RefAttr', + 'overSub3RefAttr', 'over4RefAttr'], + 'Child' : layer4OnlyChildContents + }, + }) + + def test_DependentSublayersAcrossArcs(self): + """Tests downstream dependency namespace edits across sublayers from + within composition arcs.""" + + # Setup: + # Layer1 is a simple base layer with a prim hierarchy of /Ref, + # Child, and GrandChild. This layer will be opened as the base stage + # that direct namespace edits will be performed on. + layer1 = Sdf.Layer.CreateAnonymous("layer1.usda") + layer1.ImportFromString('''#usda 1.0 + def "Ref" ( + ) { + int refAttr + + def "Child" { + int childAttr + + def "GrandChild" { + int grandChildAttr + } + } + } + ''') + + # Layer2 includes layer1 as a sublayer and provides opinions for Ref + # Child and GrandChild. + layer2 = Sdf.Layer.CreateAnonymous("layer2.usda") + layer2.ImportFromString('''#usda 1.0 + ( + subLayers = [@''' + layer1.identifier + '''@] + ) + + over "Ref" ( + ) { + int over2RefAttr + + over "Child" { + int over2ChildAttr + + over "GrandChild" { + int over2GrandChildAttr + } + } + } + ''') + + # Layer3 has three prims that reference /Ref, /Ref/Child, and + # /Ref/Child/GrandChild from layer2 respectively. These will be + # affected by downstream dependency edits. + layer3 = Sdf.Layer.CreateAnonymous("layer3.usda") + layer3.ImportFromString('''#usda 1.0 + def "Prim1" ( + references = @''' + layer2.identifier + '''@ + ) { + int over3RefAttr + over "Child" { + int over3ChildAttr + over "GrandChild" { + int over3GrandChildAttr + } + } + } + + def "Prim2" ( + references = @''' + layer2.identifier + '''@ + ) { + int over3ChildAttr + over "GrandChild" { + int over3GrandChildAttr + } + } + + def "Prim3" ( + references = @''' + layer2.identifier + '''@ + ) { + int over3GrandChildAttr + } + ''') + + # Layer4Sub will be a sublayer of the next layer, layer4, which holds + # overs for all the prims that are defined in layer3. + layer4Sub = Sdf.Layer.CreateAnonymous("layer4-sub.usda") + layer4Sub.ImportFromString('''#usda 1.0 + over "Prim1" { + int over4RefAttr + over "Child" { + int over4ChildAttr + over "GrandChild" { + int over4GrandChildAttr + } + } + } + + over "Prim2" { + int over4ChildAttr + over "GrandChild" { + int over4GrandChildAttr + } + } + + over "Prim3" { + int over4GrandChildAttr + } + ''') + + # Layer4 just has two sublayers, layer3 which defines prims with + # references and layer4Sub which provides local opinions for those + # prims. This layer has no specs of its own. + layer4 = Sdf.Layer.CreateAnonymous("layer4.usda") + layer4.ImportFromString('''#usda 1.0 + ( + subLayers = [ + @''' + layer3.identifier + '''@, + @''' + layer4Sub.identifier + '''@ + ] + ) + ''') + + # Open stages for the 4 main layers (excludes layer4Sub) + stage1 = Usd.Stage.Open(layer1) + stage2 = Usd.Stage.Open(layer2) + stage3 = Usd.Stage.Open(layer3) + stage4 = Usd.Stage.Open(layer4) + + # Create a namespace editor for stage1 which only includes layer1. + editor = Usd.NamespaceEditor(stage1) + + # Add ONLY stage4 as a dependent stage. This is to specifically show + # how all layers will be affected by edits because stage4 introduces + # dependencies on all layers through a combination of sublayers and + # references. + editor.AddDependentStage(stage4) + + # Verify the initial composition fields for layer3 which is the only + # layer with non-sublayer composition fields. + self.assertEqual(self._GetCompositionFieldsInLayer(layer3), { + '/Prim1' : { + 'references' : (Sdf.Reference(layer2.identifier, '/Ref'),) + }, + '/Prim2' : { + 'references' : (Sdf.Reference(layer2.identifier, '/Ref/Child'),) + }, + '/Prim3' : { + 'references' : (Sdf.Reference(layer2.identifier, + '/Ref/Child/GrandChild'),) + }, + }) + + # Verify initial contents of each stage. + + # Stage1 has just the contents of layer1 + stage1ChildContents = { + '.' : ['childAttr'], + 'GrandChild' : { + '.' : ['grandChildAttr'], + } + } + self._VerifyStageContents(stage1, { + 'Ref': { + '.' : ['refAttr'], + 'Child' : stage1ChildContents + }, + }) + + # Stage2 composes layer2 with its only sublayer, layer1. + stage2ChildContents = { + '.' : ['childAttr', 'over2ChildAttr'], + 'GrandChild' : { + '.' : ['grandChildAttr', 'over2GrandChildAttr'], + } + } + self._VerifyStageContents(stage2, { + 'Ref': { + '.' : ['refAttr', 'over2RefAttr'], + 'Child' : stage2ChildContents + }, + }) + + # Stage3 has each prim composed with the referenced opinions from layer2 + # (which includes sublayer layer1) and the local opinions in layer3. + stage3Prim1ChildContents = { + '.' : ['childAttr', 'over2ChildAttr', 'over3ChildAttr'], + 'GrandChild' : { + '.' : ['grandChildAttr', 'over2GrandChildAttr', + 'over3GrandChildAttr'], + } + } + stage3Prim2Contents = { + '.' : ['childAttr', 'over2ChildAttr', 'over3ChildAttr'], + 'GrandChild' : { + '.' : ['grandChildAttr', 'over2GrandChildAttr', + 'over3GrandChildAttr'], + } + } + stage3Prim3Contents = { + '.' : ['grandChildAttr', 'over2GrandChildAttr', + 'over3GrandChildAttr'], + } + + self._VerifyStageContents(stage3, { + 'Prim1': { + '.' : ['refAttr', 'over2RefAttr', 'over3RefAttr'], + 'Child' : stage3Prim1ChildContents + }, + 'Prim2' : stage3Prim2Contents, + 'Prim3' : stage3Prim3Contents + }) + + # Stage4 has the same prims from stage3 composed with local opinions + # from sublayer layer4Sub + stage4Prim1ChildContents = { + '.' : ['childAttr', 'over2ChildAttr', 'over3ChildAttr', + 'over4ChildAttr'], + 'GrandChild' : { + '.' : ['grandChildAttr', 'over2GrandChildAttr', + 'over3GrandChildAttr', 'over4GrandChildAttr'], + } + } + stage4Prim2Contents = { + '.' : ['childAttr', 'over2ChildAttr', 'over3ChildAttr', + 'over4ChildAttr'], + 'GrandChild' : { + '.' : ['grandChildAttr', 'over2GrandChildAttr', + 'over3GrandChildAttr', 'over4GrandChildAttr'], + } + } + stage4Prim3Contents = { + '.' : ['grandChildAttr', 'over2GrandChildAttr', + 'over3GrandChildAttr', 'over4GrandChildAttr'], + } + + self._VerifyStageContents(stage4, { + 'Prim1': { + '.' : ['refAttr', 'over2RefAttr', 'over3RefAttr', + 'over4RefAttr'], + 'Child' : stage4Prim1ChildContents + }, + 'Prim2' : stage4Prim2Contents, + 'Prim3' : stage4Prim3Contents + }) + + # Edit: Rename /Ref/Child to /Ref/RenamedChild + with self.ApplyEdits(editor, "Move /Ref/Child -> /Ref/RenamedChild"): + self.assertTrue(editor.MovePrimAtPath( + '/Ref/Child', '/Ref/RenamedChild')) + + # Verify the updated composition fields for layer3 where Prim2 and Prim3 + # reference paths are updated to the renamed path. + self.assertEqual(self._GetCompositionFieldsInLayer(layer3), { + '/Prim1' : { + 'references' : (Sdf.Reference(layer2.identifier, '/Ref'),) + }, + '/Prim2' : { + 'references' : (Sdf.Reference(layer2.identifier, + '/Ref/RenamedChild'),) + }, + '/Prim3' : { + 'references' : (Sdf.Reference(layer2.identifier, + '/Ref/RenamedChild/GrandChild'),) + }, + }) + + # Verify the direct rename of Child on stage1. + self._VerifyStageContents(stage1, { + 'Ref': { + '.' : ['refAttr'], + 'RenamedChild' : stage1ChildContents + }, + }) + + # On stage2, Child is also fully renamed because layer2's specs were + # updated for the sublayer dependency on layer1. Note that stage4 is the + # only dependent stage added to the namespace editor so this update + # only occurs because stage4 has dependencies on these layer2 specs. + self._VerifyStageContents(stage2, { + 'Ref': { + '.' : ['refAttr', 'over2RefAttr'], + 'RenamedChild' : stage2ChildContents + }, + }) + + # On stage3, the rename of Child is propagated across the reference for + # Prim1 where the specs from layer3 are also renamed resulting in a full + # rename of /Prim1/Child. Prim2 and Prim3's composed contents are + # unchanged as their reference fields were updated to the new paths. + # Note that, like with stage2, these updates only occur because stage4 + # has dependencies on layer3 specs. + self._VerifyStageContents(stage3, { + 'Prim1': { + '.' : ['refAttr', 'over2RefAttr', 'over3RefAttr'], + 'RenamedChild' : stage3Prim1ChildContents + }, + 'Prim2' : stage3Prim2Contents, + 'Prim3' : stage3Prim3Contents + }) + + # On stage4, the rename of Child is propagated across the reference for + # Prim1 as in stage3. The sublayer layer4Sub has its specs updated for + # the rename resulting in /Prim1/RenamedChild having all the same + # opinions as /Prim1/Child did prior. + # + # Prim2 and Prim3's composed contents are unchanged as their reference + # fields were updated to the new paths (no changes are necessary to the + # overs in sublayer layer4Sub). + self._VerifyStageContents(stage4, { + 'Prim1': { + '.' : ['refAttr', 'over2RefAttr', 'over3RefAttr', 'over4RefAttr'], + 'RenamedChild' : stage4Prim1ChildContents + }, + 'Prim2' : stage4Prim2Contents, + 'Prim3' : stage4Prim3Contents + }) + + # Edit: Reparent and rename /Ref/RenamedChild to /MovedChild + with self.ApplyEdits(editor, "Move /Ref/RenamedChild -> /MovedChild"): + self.assertTrue(editor.MovePrimAtPath( + '/Ref/RenamedChild', '/MovedChild')) + + # Verify the updated composition fields for layer3 where Prim2 and Prim3 + # reference paths are updated to the moved path. + self.assertEqual(self._GetCompositionFieldsInLayer(layer3), { + '/Prim1' : { + 'references' : (Sdf.Reference(layer2.identifier, '/Ref'),) + }, + '/Prim2' : { + 'references' : (Sdf.Reference(layer2.identifier, + '/MovedChild'),) + }, + '/Prim3' : { + 'references' : (Sdf.Reference(layer2.identifier, + '/MovedChild/GrandChild'),) + }, + }) + + # Verify updated contents of stage1 and stage2. /Ref/RenamedChild is + # fully moved to /MovedChild on both stages. + self._VerifyStageContents(stage1, { + 'Ref': { + '.' : ['refAttr'], + }, + 'MovedChild' : stage1ChildContents + }) + + self._VerifyStageContents(stage2, { + 'Ref': { + '.' : ['refAttr', 'over2RefAttr'], + }, + 'MovedChild' : stage2ChildContents + }) + + # On stage3 and stage4, RenamedChild has been moved out from under the + # referenced prim for Prim1 resulting in an effective deletion of + # RenamedChild. All specs in layer3 and layer4Sub referring to + # /Prim1/RenamedChild are deleted too resulting in a full deletion of + # this prim on these stages. + # + # Prim2 and Prim3's composed contents are unchanged as their reference + # fields were updated to the new paths and no changes are necessary to + # the local specs in layer3 and layer4Sub). + self._VerifyStageContents(stage3, { + 'Prim1': { + '.' : ['refAttr', 'over2RefAttr', 'over3RefAttr'], + }, + 'Prim2' : stage3Prim2Contents, + 'Prim3' : stage3Prim3Contents + }) + + self._VerifyStageContents(stage4, { + 'Prim1': { + '.' : ['refAttr', 'over2RefAttr', 'over3RefAttr', 'over4RefAttr'], + }, + 'Prim2' : stage4Prim2Contents, + 'Prim3' : stage4Prim3Contents + }) + + # Edit: Reparent and rename /MovedChild back to its original path + # /Ref/Child + with self.ApplyEdits(editor, "Move /MovedChild -> /Ref/Child"): + self.assertTrue(editor.MovePrimAtPath('/MovedChild', '/Ref/Child')) + + # Verify the updated composition fields for layer3 where Prim2 and Prim3 + # reference paths are updated to the original paths. + self.assertEqual(self._GetCompositionFieldsInLayer(layer3), { + '/Prim1' : { + 'references' : (Sdf.Reference(layer2.identifier, '/Ref'),) + }, + '/Prim2' : { + 'references' : (Sdf.Reference(layer2.identifier, + '/Ref/Child'),) + }, + '/Prim3' : { + 'references' : (Sdf.Reference(layer2.identifier, + '/Ref/Child/GrandChild'),) + }, + }) + + # Verify updated contents of stage1 and stage2 where /Ref/Child has + # been returned to its original contents. + self._VerifyStageContents(stage1, { + 'Ref': { + '.' : ['refAttr'], + 'Child' : stage1ChildContents + }, + }) + + self._VerifyStageContents(stage2, { + 'Ref': { + '.' : ['refAttr', 'over2RefAttr'], + 'Child' : stage2ChildContents + }, + }) + + # On stage3 and stage4, Child has returned under Prim1 but now only + # matches the contents of /Ref/Child as seen on stage2. This is because + # the local specs on layer3 and layer4Sub for this prim were deleted + # by the prior edit and are not able to restored via this namespace + # edit. Thus /Prim1/Child only consists of specs from layer1 and layer2. + # + # Prim2 and Prim3's composed contents remain unchanged as their + # reference fields were updated to the original paths. + self._VerifyStageContents(stage3, { + 'Prim1': { + '.' : ['refAttr', 'over2RefAttr', 'over3RefAttr'], + 'Child' : stage2ChildContents + }, + 'Prim2' : stage3Prim2Contents, + 'Prim3' : stage3Prim3Contents + }) + + self._VerifyStageContents(stage4, { + 'Prim1': { + '.' : ['refAttr', 'over2RefAttr', 'over3RefAttr', 'over4RefAttr'], + 'Child' : stage2ChildContents + }, + 'Prim2' : stage4Prim2Contents, + 'Prim3' : stage4Prim3Contents + }) + + # Edit: Delete the prim at /Ref/Child + with self.ApplyEdits(editor, "Delete /Ref/Child"): + self.assertTrue(editor.DeletePrimAtPath('/Ref/Child')) + + # Verify the updated composition fields for layer3 where Prim2 and Prim3 + # references are deleted because prims at those paths have been deleted. + self.assertEqual(self._GetCompositionFieldsInLayer(layer3), { + '/Prim1' : { + 'references' : (Sdf.Reference(layer2.identifier, '/Ref'),) + }, + '/Prim2' : { + 'references' : () + }, + '/Prim3' : { + 'references' : () + }, + }) + + # Verify updated contents of stage1 and stage2. /Ref/Child is fully + # deleted on both stages. + self._VerifyStageContents(stage1, { + 'Ref': { + '.' : ['refAttr'], + }, + }) + + self._VerifyStageContents(stage2, { + 'Ref': { + '.' : ['refAttr', 'over2RefAttr'], + }, + }) + + # On stage3 and stage4, Child is fully deleted from under Prim1 again. + # + # This time Prim2 and Prim3's composed contents have changed as they + # no longer have references to layer2. Local opinions for /Prim2 and + # /Prim3 in layer3 and layer4Sub remain but opinions for + # /Prim2/GrandChild (which is considered an over for the deleted + # ancestral reference to /Ref/Child/GrandChild) are deleted. + self._VerifyStageContents(stage3, { + 'Prim1': { + '.' : ['refAttr', 'over2RefAttr', 'over3RefAttr'], + }, + 'Prim2' : { + '.' : ['over3ChildAttr'], + }, + 'Prim3' : { + '.' : ['over3GrandChildAttr'], + } + }) + + self._VerifyStageContents(stage4, { + 'Prim1': { + '.' : ['refAttr', 'over2RefAttr', 'over3RefAttr', 'over4RefAttr'], + }, + 'Prim2' : { + '.' : ['over3ChildAttr', 'over4ChildAttr'], + }, + 'Prim3' : { + '.' : ['over3GrandChildAttr', 'over4GrandChildAttr'], + } + }) + +if __name__ == '__main__': + unittest.main() diff --git a/pxr/usd/usd/testenv/testUsdObjectsChangedNotices.py b/pxr/usd/usd/testenv/testUsdObjectsChangedNotices.py new file mode 100644 index 00000000000..7a91d65bc5a --- /dev/null +++ b/pxr/usd/usd/testenv/testUsdObjectsChangedNotices.py @@ -0,0 +1,496 @@ +#!/pxrpythonsubst +# +# Copyright 2024 Pixar +# +# Licensed under the terms set forth in the LICENSE.txt file available at +# https://openusd.org/license. + +import unittest +from pxr import Kind, Sdf, Tf, Usd + +_LAYER_CONTENTS = '''#usda 1.0 +def Sphere "Ref1" ( + prepend apiSchemas = ["CollectionAPI:Ref1Collection"] +){ + def Scope "Ref1Child" { + } +} + +def Scope "Ref2" { +} + +def Scope "Parent1" { + + int attr1 = 1 + int attr2 = 2 + int attr2.connect = + int attr3 = 3 + + rel rel1 = + + def Sphere "Child1" { + } + + def Sphere "Child2" { + } +} +def "Parent2" ( + references = +){ +} +''' + +class TestUsdObjectsChangedNotices(unittest.TestCase): + def setUp(self): + self._layer = Sdf.Layer.CreateAnonymous('layer.usda') + self._layer.ImportFromString(_LAYER_CONTENTS) + self._stage = Usd.Stage.Open(self._layer) + self.assertTrue(self._stage) + self._editor = Usd.NamespaceEditor(self._stage) + + self._parent1 = self._stage.GetPrimAtPath('/Parent1') + self._parent2 = self._stage.GetPrimAtPath('/Parent2') + self._child1 = self._stage.GetPrimAtPath('/Parent1/Child1') + self._child2 = self._stage.GetPrimAtPath('/Parent1/Child2') + self._attr1 = self._parent1.GetAttribute('attr1') + self._attr2 = self._parent1.GetAttribute('attr2') + self._attr3 = self._parent1.GetAttribute('attr3') + self._rel1 = self._parent1.GetRelationship('rel1') + + self.assertTrue(self._parent1) + self.assertTrue(self._parent2) + self.assertTrue(self._child1) + self.assertTrue(self._child2) + self.assertTrue(self._attr1) + self.assertTrue(self._attr2) + self.assertTrue(self._attr3) + self.assertTrue(self._rel1) + + # Each ObjectsChanged notice is converted to a dictionary and appended + # to self._notices. The list of notices is reset before each test. + self._notices = [] + self._noticeKey = Tf.Notice.Register( + Usd.Notice.ObjectsChanged, + self._onObjectsChanged, + self._stage) + + def _onObjectsChanged(self, notice, sender): + asDict = {} + resynced = notice.GetResyncedPaths() + changedInfoOnly = notice.GetChangedInfoOnlyPaths() + resolvedAssetPathsResynced = notice.GetResolvedAssetPathsResyncedPaths() + if resynced: + asDict['Resynced'] = { + str(path): notice.GetChangedFields(path) + for path in resynced + } + if changedInfoOnly: + asDict['ChangedInfoOnly'] = { + str(path): notice.GetChangedFields(path) + for path in changedInfoOnly + } + if resolvedAssetPathsResynced: + asDict['ResolvedAssetPathsResynced'] = { + str(path): notice.GetChangedFields(path) + for path in resolvedAssetPathsResynced + } + self._notices.append(asDict) + + def test_ObjectSetMetadata(self): + self._parent1.SetMetadata('comment', 'test') + self.assertEqual(len(self._notices), 1) + self.assertDictEqual(self._notices[0], { + 'ChangedInfoOnly': { + '/Parent1': ['comment'] + } + }) + + def test_ObjectSetMetadataByDictKey(self): + self._parent1.SetMetadataByDictKey('customData', 'a:b', 42) + self.assertEqual(len(self._notices), 1) + self.assertDictEqual(self._notices[0], { + 'ChangedInfoOnly': { + '/Parent1': ['customData'] + } + }) + + def test_StageDefinePrim(self): + self._stage.DefinePrim('/Parent3', 'Sphere') + self.assertEqual(len(self._notices), 1) + self.assertDictEqual(self._notices[0], { + 'Resynced': { + '/Parent3': [ + 'specifier', + 'typeName', + ] + } + }) + + def test_PrimSetSpecifier(self): + self._parent1.SetSpecifier(Sdf.SpecifierClass) + self.assertEqual(len(self._notices), 1) + self.assertDictEqual(self._notices[0], { + 'Resynced': { + '/Parent1': ['specifier'] + } + }) + + def test_PrimSetTypeName(self): + self._parent1.SetTypeName('Cylinder') + self.assertEqual(len(self._notices), 1) + self.assertDictEqual(self._notices[0], { + 'Resynced': { + '/Parent1': ['typeName'] + } + }) + + def test_PrimClearTypeName(self): + self._parent1.ClearTypeName() + self.assertEqual(len(self._notices), 1) + self.assertDictEqual(self._notices[0], { + 'Resynced': { + '/Parent1': ['typeName'] + } + }) + + def test_PrimSetActive(self): + self._parent1.SetActive(False) + self.assertEqual(len(self._notices), 1) + self.assertDictEqual(self._notices[0], { + 'Resynced': { + '/Parent1': ['active'] + } + }) + + def test_PrimSetPropertyOrder(self): + self._parent1.SetPropertyOrder(['attr2', 'attr1', 'attr3']) + self.assertEqual(len(self._notices), 1) + self.assertDictEqual(self._notices[0], { + 'ChangedInfoOnly': { + # XXX:USD-10220: Shouldn't this be ['propertyOrder']? + '/Parent1': [] + } + }) + + def test_PrimRemoveProperty(self): + self._parent1.RemoveProperty('attr2') + self.assertEqual(len(self._notices), 1) + self.assertDictEqual(self._notices[0], { + 'Resynced': { + # Note: attr2 had connections, but the connectionPaths field + # is omitted. + '/Parent1.attr2': [] + } + }) + + def test_PrimSetKind(self): + self._parent1.SetKind(Kind.Tokens.model) + self.assertEqual(len(self._notices), 1) + self.assertDictEqual(self._notices[0], { + 'Resynced': { + '/Parent1': ['kind'] + } + }) + + def test_PrimAddAppliedSchema(self): + self._parent1.AddAppliedSchema('CollectionAPI:myCollection') + self.assertEqual(len(self._notices), 1) + self.assertDictEqual(self._notices[0], { + 'Resynced': { + '/Parent1': ['apiSchemas'] + } + }) + + def test_PrimSetChildrenReorder(self): + self._parent1.SetChildrenReorder(['Child2', 'Child1']) + self.assertEqual(len(self._notices), 1) + self.assertDictEqual(self._notices[0], { + 'Resynced': { + '/Parent1': ['primOrder'] + } + }) + + def test_PrimChangeReferences(self): + # In this case, the referenced prim has apiSchemas that are added to + # the referencing prim. Even though the 'apiSchemas' field will change, + # only the 'references' field is reported to have changed. + self._parent1.GetReferences().AddReference( + self._layer.identifier, '/Ref1') + self.assertEqual(len(self._notices), 1) + self.assertDictEqual(self._notices[0], { + 'Resynced': { + '/Parent1': ['references'] + } + }) + self.assertTrue(self._stage.GetPrimAtPath('/Parent1/Ref1Child')) + self.assertTrue(self._stage.GetRelationshipAtPath( + '/Parent1.collection:Ref1Collection:includes')) + + def test_PrimChangeReferencesChangesTypeName(self): + self.assertEqual(self._parent2.GetTypeName(), 'Scope') + self._parent2.GetReferences().SetReferences([ + Sdf.Reference(self._layer.identifier, '/Ref1') + ]) + self.assertEqual(len(self._notices), 1) + self.assertDictEqual(self._notices[0], { + 'Resynced': { + '/Parent2': ['references'] + } + }) + self.assertEqual(self._parent2.GetTypeName(), 'Sphere') + + def test_PropertySetDisplayGroup(self): + self._attr1.SetDisplayGroup('test') + self.assertEqual(len(self._notices), 1) + self.assertDictEqual(self._notices[0], { + 'ChangedInfoOnly': { + '/Parent1.attr1': ['displayGroup'] + } + }) + + def test_PropertySetNestedDisplayGroups(self): + self._attr1.SetNestedDisplayGroups(['test', 'test2']) + self.assertEqual(len(self._notices), 1) + self.assertDictEqual(self._notices[0], { + 'ChangedInfoOnly': { + '/Parent1.attr1': ['displayGroup'] + } + }) + + def test_PropertySetCustom(self): + self._attr1.SetCustom(True) + self.assertEqual(len(self._notices), 1) + self.assertDictEqual(self._notices[0], { + 'ChangedInfoOnly': { + '/Parent1.attr1': ['custom'] + } + }) + + def test_AttributeSetVariability(self): + self._attr1.SetVariability(Sdf.VariabilityUniform) + self.assertEqual(len(self._notices), 1) + self.assertDictEqual(self._notices[0], { + 'ChangedInfoOnly': { + '/Parent1.attr1': ['variability'] + } + }) + + def test_AttributeSetTypename(self): + self._attr1.SetTypeName(Sdf.ValueTypeNames.Double) + self.assertEqual(len(self._notices), 1) + self.assertDictEqual(self._notices[0], { + 'ChangedInfoOnly': { + '/Parent1.attr1': ['typeName'] + } + }) + + def test_AttributeSet(self): + self._attr1.Set(42) + self.assertEqual(len(self._notices), 1) + self.assertDictEqual(self._notices[0], { + 'ChangedInfoOnly': { + '/Parent1.attr1': ['default'] + } + }) + + def test_AttributeAddConnection(self): + self._attr1.AddConnection(self._attr2.GetPath()) + self.assertEqual(len(self._notices), 1) + self.assertDictEqual(self._notices[0], { + 'ChangedInfoOnly': { + '/Parent1.attr1': ['connectionPaths'] + } + }) + + def test_AttributeClearConnections(self): + self._attr2.ClearConnections() + self.assertEqual(len(self._notices), 1) + self.assertDictEqual(self._notices[0], { + 'ChangedInfoOnly': { + '/Parent1.attr2': ['connectionPaths'] + } + }) + + def test_RelationshipAddTarget(self): + self._rel1.AddTarget(self._parent2.GetPath()) + self.assertEqual(len(self._notices), 1) + self.assertDictEqual(self._notices[0], { + 'ChangedInfoOnly': { + '/Parent1.rel1': ['targetPaths'] + } + }) + + def test_RelationshipRemoveTarget(self): + self._rel1.RemoveTarget(self._child1.GetPath()) + self.assertEqual(len(self._notices), 1) + self.assertDictEqual(self._notices[0], { + 'ChangedInfoOnly': { + '/Parent1.rel1': ['targetPaths'] + } + }) + + # Removing target that does not exist should not trigger a notice. + self._rel1.RemoveTarget(self._child1.GetPath()) + self.assertEqual(len(self._notices), 1) + + def test_RelationshipSetTargets(self): + self._rel1.SetTargets([self._child1.GetPath(), self._child2.GetPath()]) + self.assertEqual(len(self._notices), 1) + self.assertDictEqual(self._notices[0], { + 'ChangedInfoOnly': { + '/Parent1.rel1': ['targetPaths'] + } + }) + + def test_RelationshipClearTargets(self): + self._rel1.ClearTargets(removeSpec = False) + self.assertEqual(len(self._notices), 1) + self.assertDictEqual(self._notices[0], { + 'ChangedInfoOnly': { + '/Parent1.rel1': ['targetPaths'] + } + }) + + self._rel1.ClearTargets(removeSpec = True) + self.assertEqual(len(self._notices), 2) + self.assertDictEqual(self._notices[1], { + 'Resynced': { + '/Parent1.rel1': [] + } + }) + + def test_NamespaceEditorDeletePrimAtPath(self): + self._editor.DeletePrimAtPath('/Parent1') + self._editor.ApplyEdits() + self.assertEqual(len(self._notices), 1) + self.assertDictEqual(self._notices[0], { + 'Resynced': { + '/Parent1': [] + } + }) + + def test_NamespaceEditorMovePrimAtPath(self): + self._editor.MovePrimAtPath('/Parent2', '/Parent1/Parent3') + self._editor.ApplyEdits() + self.assertEqual(len(self._notices), 1) + self.assertDictEqual(self._notices[0], { + 'Resynced': { + '/Parent2': [], + '/Parent1/Parent3': [] + } + }) + + def test_NamespaceEditorRenamePrim(self): + self._editor.RenamePrim(self._child1, 'Child3') + self._editor.ApplyEdits() + self.assertEqual(len(self._notices), 1) + self.assertDictEqual(self._notices[0], { + 'Resynced': { + '/Parent1/Child1': [], + '/Parent1/Child3': [] + }, + 'ChangedInfoOnly': { + '/Parent1.rel1': ['targetPaths'] + } + }) + + def test_NamespaceEditorReparentPrim(self): + self._editor.ReparentPrim(self._child1, self._parent2) + self._editor.ApplyEdits() + self.assertEqual(len(self._notices), 1) + self.assertDictEqual(self._notices[0], { + 'Resynced': { + '/Parent1/Child1': [], + '/Parent2/Child1': [] + }, + 'ChangedInfoOnly': { + '/Parent1.rel1': ['targetPaths'] + } + }) + + def test_NamespaceEditorDeleteProperty(self): + self._editor.DeleteProperty(self._attr3) + self._editor.ApplyEdits() + self.assertEqual(len(self._notices), 1) + self.assertDictEqual(self._notices[0], { + 'Resynced': { + '/Parent1.attr3': [] + }, + 'ChangedInfoOnly': { + '/Parent1.attr2': ['connectionPaths'] + } + }) + + def test_NamespaceEditorMovePropertyAtPath(self): + self._editor.MovePropertyAtPath( + self._attr3.GetPath(), + '/Parent2.newName') + self._editor.ApplyEdits() + self.assertEqual(len(self._notices), 1) + self.assertDictEqual(self._notices[0], { + 'Resynced': { + '/Parent1.attr3': [], + '/Parent2.newName': [] + }, + 'ChangedInfoOnly': { + '/Parent1.attr2': ['connectionPaths'] + } + }) + + def test_NamespaceEditorReparentProperty(self): + self._editor.ReparentProperty(self._attr3, self._parent2) + self._editor.ApplyEdits() + self.assertEqual(len(self._notices), 1) + self.assertDictEqual(self._notices[0], { + 'Resynced': { + '/Parent1.attr3': [], + '/Parent2.attr3': [] + }, + 'ChangedInfoOnly': { + '/Parent1.attr2': ['connectionPaths'] + } + }) + + def test_SdfChangeBlockChangeTypeThenDelete(self): + with Sdf.ChangeBlock(): + parentSpec = self._layer.GetPrimAtPath('/Parent1') + parentSpec.typeName = 'Cylinder' + del(self._layer.rootPrims['Parent1']) + self.assertEqual(len(self._notices), 1) + self.assertDictEqual(self._notices[0], { + 'Resynced': { + '/Parent1': ['typeName'] + } + }) + self.assertFalse(self._stage.GetPrimAtPath('/Parent1')) + + def test_SdfChangeBlockAppendAPISchemaThenDelete(self): + with Sdf.ChangeBlock(): + parentSpec = self._layer.GetPrimAtPath('/Parent1') + schemas = Sdf.TokenListOp.Create(['CollectionAPI:myCollection']) + parentSpec.SetInfo('apiSchemas', schemas) + del(self._layer.rootPrims['Parent1']) + self.assertEqual(len(self._notices), 1) + self.assertDictEqual(self._notices[0], { + 'Resynced': { + '/Parent1': ['apiSchemas'] + } + }) + self.assertFalse(self._stage.GetPrimAtPath('/Parent1')) + + def test_SdfChangeBlockReorderChildrenThenDelete(self): + with Sdf.ChangeBlock(): + parentSpec = self._layer.GetPrimAtPath('/Parent1') + parentSpec.nameChildrenOrder = ['Child2', 'Child1'] + del(self._layer.rootPrims['Parent1']) + self.assertEqual(len(self._notices), 1) + self.assertDictEqual(self._notices[0], { + 'Resynced': { + '/Parent1': ['primOrder'] + } + }) + self.assertFalse(self._stage.GetPrimAtPath('/Parent1')) + + +if __name__ == "__main__": + unittest.main() \ No newline at end of file diff --git a/pxr/usd/usd/testenv/testUsdSchemaRegistry.py b/pxr/usd/usd/testenv/testUsdSchemaRegistry.py index fb67de2f561..8ae941e633f 100644 --- a/pxr/usd/usd/testenv/testUsdSchemaRegistry.py +++ b/pxr/usd/usd/testenv/testUsdSchemaRegistry.py @@ -18,6 +18,16 @@ def setUpClass(cls): assert testPlugins[0].name == "testUsdSchemaRegistry", \ "Failed to load expected test plugin" + # This checks an invalid case for test_SchemaIdentifier that throws a + # coding error on schema registry construction + try: + Usd.SchemaRegistry() + assert False, "Coding error expected on schema registry initialization." + except Tf.ErrorException as e: + assert 'Registration failed for schema type ' \ + 'TestUsdSchemaRegistryNoIdentifierAndNoAlias.' in str(e) + assert len(str(e).strip().split('\n')) == 1 + def test_PrimMetadata(self): primDef = Usd.SchemaRegistry().FindConcretePrimDefinition( "MetadataTest") diff --git a/pxr/usd/usd/testenv/testUsdValidationContext.cpp b/pxr/usd/usd/testenv/testUsdValidationContext.cpp index c7e66b76a5e..db83eacbef0 100644 --- a/pxr/usd/usd/testenv/testUsdValidationContext.cpp +++ b/pxr/usd/usd/testenv/testUsdValidationContext.cpp @@ -15,154 +15,6 @@ PXR_NAMESPACE_USING_DIRECTIVE -TF_REGISTRY_FUNCTION(UsdValidationRegistry) -{ - UsdValidationRegistry& registry = UsdValidationRegistry::GetInstance(); - - // Register test plugin validators here - // Test validators simply just return errors, we need to make sure various - // UsdValidationContext APIs work and get the expected errors back, when - // Validate is called in various scenarios on a validation context instance. - { - const TfToken validatorName("testUsdValidationContext:Test1"); - const UsdValidateStageTaskFn stageTaskFn = []( - const UsdStagePtr & usdStage) - { - const TfToken validationErrorId("Test1Error"); - return UsdValidationErrorVector{ - UsdValidationError( - validationErrorId, UsdValidationErrorType::Error, - {UsdValidationErrorSite(usdStage, - SdfPath::AbsoluteRootPath())}, - "A stage validator error")}; - }; - - TfErrorMark m; - registry.RegisterPluginValidator(validatorName, stageTaskFn); - TF_AXIOM(m.IsClean()); - } - { - const TfToken validatorName("testUsdValidationContext:Test2"); - const UsdValidateLayerTaskFn layerTaskFn = []( - const SdfLayerHandle & layer) - { - const TfToken validationErrorId("Test2Error"); - return UsdValidationErrorVector{ - UsdValidationError( - validationErrorId, UsdValidationErrorType::Error, - {UsdValidationErrorSite(layer, - SdfPath::AbsoluteRootPath())}, - "A layer validator error")}; - }; - - TfErrorMark m; - registry.RegisterPluginValidator(validatorName, layerTaskFn); - TF_AXIOM(m.IsClean()); - } - { - const TfToken validatorName("testUsdValidationContext:Test3"); - const UsdValidatePrimTaskFn primTaskFn = []( - const UsdPrim & prim) - { - const TfToken validationErrorId("Test3Error"); - return UsdValidationErrorVector{ - UsdValidationError( - validationErrorId, UsdValidationErrorType::Error, - {UsdValidationErrorSite(prim.GetStage(), - prim.GetPath())}, - "A generic prim validator error")}; - }; - - TfErrorMark m; - registry.RegisterPluginValidator(validatorName, primTaskFn); - TF_AXIOM(m.IsClean()); - } - { - const TfToken validatorName("testUsdValidationContext:Test4"); - const UsdValidatePrimTaskFn primTaskFn = []( - const UsdPrim & prim) - { - const TfToken validationErrorId("Test4Error"); - return UsdValidationErrorVector{ - UsdValidationError( - validationErrorId, UsdValidationErrorType::Error, - {UsdValidationErrorSite(prim.GetStage(), - prim.GetPath())}, - "A testBaseType prim type validator error")}; - }; - - TfErrorMark m; - registry.RegisterPluginValidator(validatorName, primTaskFn); - TF_AXIOM(m.IsClean()); - } - { - const TfToken validatorName("testUsdValidationContext:Test5"); - const UsdValidatePrimTaskFn primTaskFn = []( - const UsdPrim & prim) - { - const TfToken validationErrorId("Test5Error"); - return UsdValidationErrorVector{ - UsdValidationError( - validationErrorId, UsdValidationErrorType::Error, - {UsdValidationErrorSite(prim.GetStage(), - prim.GetPath())}, - "A testDerivedType prim type validator error")}; - }; - - TfErrorMark m; - registry.RegisterPluginValidator(validatorName, primTaskFn); - TF_AXIOM(m.IsClean()); - } - { - const TfToken validatorName("testUsdValidationContext:Test6"); - const UsdValidatePrimTaskFn primTaskFn = []( - const UsdPrim & prim) - { - const TfToken validationErrorId("Test6Error"); - return UsdValidationErrorVector{ - UsdValidationError( - validationErrorId, UsdValidationErrorType::Error, - {UsdValidationErrorSite(prim.GetStage(), - prim.GetPath())}, - "A testNestedDerivedType prim type validator error")}; - }; - - TfErrorMark m; - registry.RegisterPluginValidator(validatorName, primTaskFn); - TF_AXIOM(m.IsClean()); - } - { - const TfToken validatorName("testUsdValidationContext:Test7"); - const UsdValidatePrimTaskFn primTaskFn = []( - const UsdPrim & prim) - { - const TfToken validationErrorId("Test7Error"); - return UsdValidationErrorVector{ - UsdValidationError( - validationErrorId, UsdValidationErrorType::Error, - {UsdValidationErrorSite(prim.GetStage(), - prim.GetPath())}, - "A testAPISchema prim type validator error")}; - }; - - TfErrorMark m; - registry.RegisterPluginValidator(validatorName, primTaskFn); - TF_AXIOM(m.IsClean()); - } - { - const TfToken suiteName("testUsdValidationContext:TestSuite"); - const std::vector containedValidators = - registry.GetOrLoadValidatorsByName( - {TfToken("testUsdValidationContext:Test1"), - TfToken("testUsdValidationContext:Test2"), - TfToken("testUsdValidationContext:Test3")}); - - TfErrorMark m; - registry.RegisterPluginValidatorSuite(suiteName, containedValidators); - TF_AXIOM(m.IsClean()); - } -} - static std::string _LayerContents() { @@ -202,7 +54,7 @@ void _TestError1(const UsdValidationError &error) { TF_AXIOM( error.GetValidator()->GetMetadata().name == - TfToken("testUsdValidationContext:Test1")); + TfToken("testUsdValidationContextValidatorsPlugin:Test1")); TF_AXIOM(error.GetSites().size() == 1); TF_AXIOM(error.GetSites()[0].IsPrim()); TF_AXIOM(error.GetSites()[0].GetPrim().GetPath() == @@ -214,7 +66,7 @@ void _TestError2(const UsdValidationError &error) { TF_AXIOM( error.GetValidator()->GetMetadata().name == - TfToken("testUsdValidationContext:Test2")); + TfToken("testUsdValidationContextValidatorsPlugin:Test2")); TF_AXIOM(error.GetSites().size() == 1); TF_AXIOM(error.GetSites()[0].IsValidSpecInLayer()); } @@ -224,7 +76,7 @@ void _TestError3(const UsdValidationError &error) { TF_AXIOM( error.GetValidator()->GetMetadata().name == - TfToken("testUsdValidationContext:Test3")); + TfToken("testUsdValidationContextValidatorsPlugin:Test3")); const std::set expectedPrimPaths = { SdfPath("/World"), SdfPath("/World/baseType"), @@ -241,7 +93,7 @@ void _TestError4(const UsdValidationError &error) { TF_AXIOM( error.GetValidator()->GetMetadata().name == - TfToken("testUsdValidationContext:Test4")); + TfToken("testUsdValidationContextValidatorsPlugin:Test4")); const std::set expectedPrimPaths = { SdfPath("/World/baseType"), SdfPath("/World/derivedType"), @@ -256,7 +108,7 @@ void _TestError5(const UsdValidationError &error) { TF_AXIOM( error.GetValidator()->GetMetadata().name == - TfToken("testUsdValidationContext:Test5")); + TfToken("testUsdValidationContextValidatorsPlugin:Test5")); const std::set expectedPrimPaths = { SdfPath("/World/derivedType"), SdfPath("/World/nestedDerivedType")}; @@ -270,7 +122,7 @@ void _TestError6(const UsdValidationError &error) { TF_AXIOM( error.GetValidator()->GetMetadata().name == - TfToken("testUsdValidationContext:Test6")); + TfToken("testUsdValidationContextValidatorsPlugin:Test6")); TF_AXIOM(error.GetSites().size() == 1); TF_AXIOM(error.GetSites()[0].IsPrim()); TF_AXIOM(error.GetSites()[0].GetPrim().GetName() == @@ -283,7 +135,7 @@ _TestError7(const UsdValidationError &error) { TF_AXIOM(error.GetName() == TfToken("Test7Error")); TF_AXIOM( error.GetValidator()->GetMetadata().name == - TfToken("testUsdValidationContext:Test7")); + TfToken("testUsdValidationContextValidatorsPlugin:Test7")); TF_AXIOM(error.GetSites().size() == 1); TF_AXIOM(error.GetSites()[0].IsPrim()); TF_AXIOM(error.GetSites()[0].GetPrim().GetName() == @@ -309,7 +161,7 @@ _TestUsdValidationContext() // Create a ValidationContext with a suite const UsdValidatorSuite* suite = UsdValidationRegistry::GetInstance().GetOrLoadValidatorSuiteByName( - TfToken("testUsdValidationContext:TestSuite")); + TfToken("testUsdValidationContextValidatorsPlugin:TestSuite")); UsdValidationContext context({suite}); SdfLayerRefPtr testLayer = _CreateTestLayer(); // Run Validate(layer) @@ -494,7 +346,7 @@ _TestUsdValidationContext() // Create a ValidationContext with plugins UsdValidationContext context({ PlugRegistry::GetInstance().GetPluginWithName( - "testUsdValidationContext")}); + "testUsdValidationContextValidatorsPlugin")}); SdfLayerRefPtr testLayer = _CreateTestLayer(); UsdStageRefPtr stage = UsdStage::Open(testLayer); UsdValidationErrorVector errors = context.Validate(stage); @@ -536,9 +388,19 @@ _TestUsdValidationContext() int main() { - // Register the test plugin - const std::string pluginPath = ArchGetCwd() + "/resources"; - TF_AXIOM(!PlugRegistry::GetInstance().RegisterPlugins(pluginPath).empty()); + // Register the test plugins + // Plugin which provides test usd schema types + const std::string testTypePluginPath = ArchGetCwd() + "/resources"; + TF_AXIOM(!PlugRegistry::GetInstance().RegisterPlugins( + testTypePluginPath).empty()); + // Plugin which provides test validators + const std::string testValidatorPluginPath = + TfStringCatPaths( + TfGetPathName(ArchGetExecutablePath()), + "UsdPlugins/lib/TestUsdValidationContextValidators*/Resources/") + + "/"; + TF_AXIOM(!PlugRegistry::GetInstance().RegisterPlugins( + testValidatorPluginPath).empty()); // Add a non-plugin based validator here. { diff --git a/pxr/usd/usd/testenv/testUsdValidationContext/resources/plugInfo.json b/pxr/usd/usd/testenv/testUsdValidationContext/resources/plugInfo.json index 1ed9b05b621..2b64e63ab92 100644 --- a/pxr/usd/usd/testenv/testUsdValidationContext/resources/plugInfo.json +++ b/pxr/usd/usd/testenv/testUsdValidationContext/resources/plugInfo.json @@ -34,45 +34,6 @@ }, "bases": ["UsdAPISchemaBase"] } - }, - "Validators": { - "Test1": { - "doc": "Stage Validator", - "keywords": ["Keyword1"] - }, - "Test2": { - "doc": "Layer Validator", - "keywords": ["Keyword2"] - }, - "Test3": { - "doc": "A generic prim validator", - "keywords": ["Keyword1"] - }, - "Test4": { - "doc": "validator for testBaseType", - "keywords": ["Keyword2"], - "schemaTypes": ["testBaseType"] - }, - "Test5": { - "doc": "validator for testDerivedType", - "keywords": ["Keyword1"], - "schemaTypes": ["testDerivedType"] - }, - "Test6": { - "doc": "validator for testNestedDerivedType", - "keywords": ["Keyword2"], - "schemaTypes": ["testNestedDerivedType"] - }, - "Test7": { - "doc": "validator for testAPISchema", - "keywords": ["Keyword1"], - "schemaTypes": ["testAPISchemaAPI"] - }, - "TestSuite": { - "doc": "A suite of validators for Test1, Test2 and Test3", - "isSuite": true, - "keywords": ["Keyword2"] - } } } } diff --git a/pxr/usd/usd/testenv/testUsdValidationContextPy.py b/pxr/usd/usd/testenv/testUsdValidationContextPy.py new file mode 100644 index 00000000000..4d04077d9bf --- /dev/null +++ b/pxr/usd/usd/testenv/testUsdValidationContextPy.py @@ -0,0 +1,327 @@ +#!/pxrpythonsubst +# +# Copyright 2024 Pixar +# +# Licensed under the terms set forth in the LICENSE.txt file available at +# https://openusd.org/license. + +import os, unittest + +from pxr import Plug, Sdf, Tf, Usd + +class TestUsdValidationContextPy(unittest.TestCase): + + @classmethod + def setUpClass(cls) -> None: + testTypePluginPath = os.path.abspath( + os.path.join(os.path.curdir, "resources")) + assert os.path.exists(testTypePluginPath) + testValidatorPluginPath = os.path.join( + os.path.dirname(__file__), + "UsdPlugins/lib/TestUsdValidationContextValidators*/Resources/") + try: + typePlugins = Plug.Registry().RegisterPlugins(testTypePluginPath) + assert typePlugins + assert len(typePlugins) == 1 + assert typePlugins[0].name == "testUsdValidationContext" + validatorPlugins = Plug.Registry().RegisterPlugins( + testValidatorPluginPath) + assert validatorPlugins + assert len(validatorPlugins) == 1 + assert validatorPlugins[0].name == \ + "testUsdValidationContextValidatorsPlugin" + except RuntimeError: + pass + + def _LayerContents(self): + layerContents = """#usda 1.0 + def "World" + { + def BaseTypeTest "baseType" + { + } + def DerivedTypeTest "derivedType" + { + } + def NestedDerivedTypeTest "nestedDerivedType" + { + } + def "somePrim" ( + prepend apiSchemas = ["APISchemaTestAPI"] + ) + { + } + } + """ + return layerContents + + def _CreateTestLayer(self): + layer = Sdf.Layer.CreateAnonymous(".usda") + layer.ImportFromString(self._LayerContents()) + return layer + + def _TestError1(self, error): + self.assertEqual( + error.GetValidator().GetMetadata().name, + "testUsdValidationContextValidatorsPlugin:Test1") + self.assertEqual(len(error.GetSites()), 1) + self.assertTrue(error.GetSites()[0].IsPrim()) + self.assertEqual( + error.GetSites()[0].GetPrim().GetPath(), + Sdf.Path.absoluteRootPath) + + def _TestError2(self, error): + self.assertEqual( + error.GetValidator().GetMetadata().name, + "testUsdValidationContextValidatorsPlugin:Test2") + self.assertEqual(len(error.GetSites()), 1) + self.assertTrue(error.GetSites()[0].IsValidSpecInLayer()) + + def _TestError3(self, error): + self.assertEqual( + error.GetValidator().GetMetadata().name, + "testUsdValidationContextValidatorsPlugin:Test3") + expectedPrimPaths = { + Sdf.Path("/World"), + Sdf.Path("/World/baseType"), + Sdf.Path("/World/derivedType"), + Sdf.Path("/World/nestedDerivedType"), + Sdf.Path("/World/somePrim")} + self.assertTrue( + error.GetSites()[0].GetPrim().GetPath() in expectedPrimPaths) + + def _TestError4(self, error): + self.assertEqual( + error.GetValidator().GetMetadata().name, + "testUsdValidationContextValidatorsPlugin:Test4") + expectedPrimPaths = { + Sdf.Path("/World/baseType"), + Sdf.Path("/World/derivedType"), + Sdf.Path("/World/nestedDerivedType")} + self.assertTrue( + error.GetSites()[0].GetPrim().GetPath() in expectedPrimPaths) + + def _TestError5(self, error): + self.assertEqual( + error.GetValidator().GetMetadata().name, + "testUsdValidationContextValidatorsPlugin:Test5") + expectedPrimPaths = { + Sdf.Path("/World/derivedType"), + Sdf.Path("/World/nestedDerivedType")} + self.assertTrue( + error.GetSites()[0].GetPrim().GetPath() in expectedPrimPaths) + + def _TestError6(self, error): + self.assertEqual( + error.GetValidator().GetMetadata().name, + "testUsdValidationContextValidatorsPlugin:Test6") + self.assertEqual(len(error.GetSites()), 1) + self.assertTrue(error.GetSites()[0].IsPrim()) + self.assertEqual( + error.GetSites()[0].GetPrim().GetName(), + "nestedDerivedType") + + def _TestError7(self, error): + self.assertEqual(error.GetName(), "Test7Error") + self.assertEqual( + error.GetValidator().GetMetadata().name, + "testUsdValidationContextValidatorsPlugin:Test7") + self.assertEqual(len(error.GetSites()), 1) + self.assertTrue(error.GetSites()[0].IsPrim()) + self.assertEqual( + error.GetSites()[0].GetPrim().GetName(), + "somePrim") + + + def test_UsdValidationContext(self): + # Create a ValidationContext with a suite + suite = Usd.ValidationRegistry().GetOrLoadValidatorSuiteByName( + "testUsdValidationContextValidatorsPlugin:TestSuite") + context = Usd.ValidationContext([suite]) + testLayer = self._CreateTestLayer() + # Run Validate(layer) + errors = context.Validate(testLayer) + # 1 error for Test2 validator - root layer of the stage + self.assertEqual(len(errors), 1) + self._TestError2(errors[0]) + # Run Validate(stage) + stage = Usd.Stage.Open(testLayer) + errors = context.Validate(stage) + # 1 error for Test1 validator (stage) + # 2 error for Test2 validator - root layer and session layer + # 5 errors for Test3 generic prim validator which runs on all 5 prims + self.assertEqual(len(errors), 8) + for error in errors: + if error.GetName() == "Test1Error": + self._TestError1(error) + elif error.GetName() == "Test2Error": + self._TestError2(error) + elif error.GetName() == "Test3Error": + self._TestError3(error) + else: + self.assertFalse(True) + + # Create a ValidationContext with explicit schemaTypes + context = Usd.ValidationContext( + [Tf.Type.FindByName("testBaseType")]) + testLayer = self._CreateTestLayer() + # Run Validate(layer) + errors = context.Validate(testLayer) + # 0 errors as we do not have any layer validators selected in this + # context. + self.assertTrue(not errors) + # Run Validate(stage) + stage = Usd.Stage.Open(testLayer) + errors = context.Validate(stage) + # 3 errors for Test4 testBaseType prim type validator which runs on + # the baseType, derivedType and nestedDerivedType prims + self.assertEqual(len(errors), 3) + for error in errors: + self._TestError4(error) + + # Create a ValidationContext with explicit schemaType - apiSchema + context = Usd.ValidationContext( + [Tf.Type.FindByName("testAPISchemaAPI")]) + testLayer = self._CreateTestLayer() + # Run Validate(layer) + errors = context.Validate(testLayer) + # 0 errors as we do not have any layer validators selected in this + # context. + self.assertTrue(not errors) + # Run Validate(stage) + stage = Usd.Stage.Open(testLayer) + errors = context.Validate(stage) + # 1 error for Test7 testAPISchema prim type validator which runs on + # the somePrim prim + self.assertEqual(len(errors), 1) + self._TestError7(errors[0]) + + # Create a ValidationContext with keywords API and have + # includeAllAncestors set to true + context = Usd.ValidationContext(["Keyword1"], True) + testLayer = self._CreateTestLayer() + # Run Validate(layer) + errors = context.Validate(testLayer) + # 0 errors as we do not have any layer validators selected in this + # context. + self.assertTrue(not errors) + # Run Validate(stage) + stage = Usd.Stage.Open(testLayer) + errors = context.Validate(stage) + # 1 error for Test1 validator + # 5 errors for Test3 generic prim validator which runs on all 5 prims + # 2 errors for Test5 testDerivedType prim type validator which runs on + # the derivedType and nestedDerivedType prims + # 3 errors for Test4 testBaseType prim type validator which runs on + # the baseType, derivedType and nestedDerivedType prims (This gets + # includes as an ancestor type of derivedType) + # 1 error for Test7 testAPISchema prim type validator which runs on + # the somePrim prim + self.assertEqual(len(errors), 12) + for error in errors: + if error.GetName() == "Test1Error": + self._TestError1(error) + elif error.GetName() == "Test3Error": + self._TestError3(error) + elif error.GetName() == "Test4Error": + self._TestError4(error) + elif error.GetName() == "Test5Error": + self._TestError5(error) + elif error.GetName() == "Test7Error": + self._TestError7(error) + else: + self.assertFalse(True) + + # Create a ValidationContext with keywords API and have + # includeAllAncestors set to false + context = Usd.ValidationContext(["Keyword2"], False) + testLayer = self._CreateTestLayer() + # Run Validate(layer) + errors = context.Validate(testLayer) + # 1 error for Test2 validator - root layer of the stage + self.assertEqual(len(errors), 1) + self._TestError2(errors[0]) + # Run Validate(prims) + stage = Usd.Stage.Open(testLayer) + errors = context.Validate(stage.Traverse()) + # 3 errors for Test4 testBaseType prim type validator which runs on + # the baseType, derivedType and nestedDerivedType prims + # 1 error for Test6 testNestedDerivedType prim type validator which + # runs on the nestedDerivedType prim + # 5 errors for Test3 generic prim validator which runs on all 5 prims + self.assertEqual(len(errors), 9) + for error in errors: + if error.GetName() == "Test3Error": + self._TestError3(error) + elif error.GetName() == "Test4Error": + self._TestError4(error) + elif error.GetName() == "Test6Error": + self._TestError6(error) + else: + self.assertFalse(True) + + # Run Validate(stage) + errors = context.Validate(stage) + # 2 error for Test2 validator - root layer and session layer + # 3 errors for Test4 testBaseType prim type validator which runs on + # the baseType, derivedType and nestedDerivedType prims + # 1 error for Test6 testNestedDerivedType prim type validator which + # runs on the nestedDerivedType prim + # Because of TestSuite: + # 1 error for Test1 validator + # 5 errors for Test3 generic prim validator which runs on all 5 prims + self.assertEqual(len(errors), 12) + for error in errors: + if error.GetName() == "Test1Error": + self._TestError1(error) + elif error.GetName() == "Test2Error": + self._TestError2(error) + elif error.GetName() == "Test3Error": + self._TestError3(error) + elif error.GetName() == "Test4Error": + self._TestError4(error) + elif error.GetName() == "Test6Error": + self._TestError6(error) + else: + self.assertFalse(True) + + # Create a ValidationContext with plugins + context = Usd.ValidationContext( + [Plug.Registry().GetPluginWithName( + "testUsdValidationContextValidatorsPlugin")], True) + testLayer = self._CreateTestLayer() + stage = Usd.Stage.Open(testLayer) + errors = context.Validate(stage) + # 1 error for Test1 validator + # 2 error for Test2 validator - root layer and session layer + # 5 errors for Test3 generic prim validator which runs on all 5 prims + # 3 errors for Test4 testBaseType prim type validator which runs on + # the baseType, derivedType and nestedDerivedType prims + # 2 error for Test5 testDerivedType prim type validator which runs on + # the derivedType and nestedDerivedType prims + # 1 error for Test6 testNestedDerivedType prim type validator which + # runs on the nestedDerivedType prim + # 1 error for Test7 testAPISchema prim type validator which runs on + # the somePrim prim + self.assertEqual(len(errors), 15) + for error in errors: + if error.GetName() == "Test1Error": + self._TestError1(error) + elif error.GetName() == "Test2Error": + self._TestError2(error) + elif error.GetName() == "Test3Error": + self._TestError3(error) + elif error.GetName() == "Test4Error": + self._TestError4(error) + elif error.GetName() == "Test5Error": + self._TestError5(error) + elif error.GetName() == "Test6Error": + self._TestError6(error) + elif error.GetName() == "Test7Error": + self._TestError7(error) + else: + self.assertFalse(True) + +if __name__ == "__main__": + unittest.main() + diff --git a/pxr/usd/usd/testenv/testUsdValidationContextValidators.cpp b/pxr/usd/usd/testenv/testUsdValidationContextValidators.cpp new file mode 100644 index 00000000000..66615018d21 --- /dev/null +++ b/pxr/usd/usd/testenv/testUsdValidationContextValidators.cpp @@ -0,0 +1,169 @@ +// +// Copyright 2024 Pixar +// +// Licensed under the terms set forth in the LICENSE.txt file available at +// https://openusd.org/license. +// + +#include "pxr/pxr.h" +#include "pxr/usd/usd/validationError.h" +#include "pxr/usd/usd/validationRegistry.h" +#include "pxr/usd/usd/validator.h" + +PXR_NAMESPACE_USING_DIRECTIVE + +TF_REGISTRY_FUNCTION(UsdValidationRegistry) +{ + UsdValidationRegistry& registry = UsdValidationRegistry::GetInstance(); + + // Register test plugin validators here + // Test validators simply just return errors, we need to make sure various + // UsdValidationContext APIs work and get the expected errors back, when + // Validate is called in various scenarios on a validation context instance. + { + const TfToken validatorName( + "testUsdValidationContextValidatorsPlugin:Test1"); + const UsdValidateStageTaskFn stageTaskFn = []( + const UsdStagePtr & usdStage) + { + const TfToken validationErrorId("Test1Error"); + return UsdValidationErrorVector{ + UsdValidationError( + validationErrorId, UsdValidationErrorType::Error, + {UsdValidationErrorSite(usdStage, + SdfPath::AbsoluteRootPath())}, + "A stage validator error")}; + }; + + TfErrorMark m; + registry.RegisterPluginValidator(validatorName, stageTaskFn); + TF_AXIOM(m.IsClean()); + } + { + const TfToken validatorName( + "testUsdValidationContextValidatorsPlugin:Test2"); + const UsdValidateLayerTaskFn layerTaskFn = []( + const SdfLayerHandle & layer) + { + const TfToken validationErrorId("Test2Error"); + return UsdValidationErrorVector{ + UsdValidationError( + validationErrorId, UsdValidationErrorType::Error, + {UsdValidationErrorSite(layer, + SdfPath::AbsoluteRootPath())}, + "A layer validator error")}; + }; + + TfErrorMark m; + registry.RegisterPluginValidator(validatorName, layerTaskFn); + TF_AXIOM(m.IsClean()); + } + { + const TfToken validatorName( + "testUsdValidationContextValidatorsPlugin:Test3"); + const UsdValidatePrimTaskFn primTaskFn = []( + const UsdPrim & prim) + { + const TfToken validationErrorId("Test3Error"); + return UsdValidationErrorVector{ + UsdValidationError( + validationErrorId, UsdValidationErrorType::Error, + {UsdValidationErrorSite(prim.GetStage(), + prim.GetPath())}, + "A generic prim validator error")}; + }; + + TfErrorMark m; + registry.RegisterPluginValidator(validatorName, primTaskFn); + TF_AXIOM(m.IsClean()); + } + { + const TfToken validatorName( + "testUsdValidationContextValidatorsPlugin:Test4"); + const UsdValidatePrimTaskFn primTaskFn = []( + const UsdPrim & prim) + { + const TfToken validationErrorId("Test4Error"); + return UsdValidationErrorVector{ + UsdValidationError( + validationErrorId, UsdValidationErrorType::Error, + {UsdValidationErrorSite(prim.GetStage(), + prim.GetPath())}, + "A testBaseType prim type validator error")}; + }; + + TfErrorMark m; + registry.RegisterPluginValidator(validatorName, primTaskFn); + TF_AXIOM(m.IsClean()); + } + { + const TfToken validatorName( + "testUsdValidationContextValidatorsPlugin:Test5"); + const UsdValidatePrimTaskFn primTaskFn = []( + const UsdPrim & prim) + { + const TfToken validationErrorId("Test5Error"); + return UsdValidationErrorVector{ + UsdValidationError( + validationErrorId, UsdValidationErrorType::Error, + {UsdValidationErrorSite(prim.GetStage(), + prim.GetPath())}, + "A testDerivedType prim type validator error")}; + }; + + TfErrorMark m; + registry.RegisterPluginValidator(validatorName, primTaskFn); + TF_AXIOM(m.IsClean()); + } + { + const TfToken validatorName( + "testUsdValidationContextValidatorsPlugin:Test6"); + const UsdValidatePrimTaskFn primTaskFn = []( + const UsdPrim & prim) + { + const TfToken validationErrorId("Test6Error"); + return UsdValidationErrorVector{ + UsdValidationError( + validationErrorId, UsdValidationErrorType::Error, + {UsdValidationErrorSite(prim.GetStage(), + prim.GetPath())}, + "A testNestedDerivedType prim type validator error")}; + }; + + TfErrorMark m; + registry.RegisterPluginValidator(validatorName, primTaskFn); + TF_AXIOM(m.IsClean()); + } + { + const TfToken validatorName( + "testUsdValidationContextValidatorsPlugin:Test7"); + const UsdValidatePrimTaskFn primTaskFn = []( + const UsdPrim & prim) + { + const TfToken validationErrorId("Test7Error"); + return UsdValidationErrorVector{ + UsdValidationError( + validationErrorId, UsdValidationErrorType::Error, + {UsdValidationErrorSite(prim.GetStage(), + prim.GetPath())}, + "A testAPISchema prim type validator error")}; + }; + + TfErrorMark m; + registry.RegisterPluginValidator(validatorName, primTaskFn); + TF_AXIOM(m.IsClean()); + } + { + const TfToken suiteName( + "testUsdValidationContextValidatorsPlugin:TestSuite"); + const std::vector containedValidators = + registry.GetOrLoadValidatorsByName( + {TfToken("testUsdValidationContextValidatorsPlugin:Test1"), + TfToken("testUsdValidationContextValidatorsPlugin:Test2"), + TfToken("testUsdValidationContextValidatorsPlugin:Test3")}); + + TfErrorMark m; + registry.RegisterPluginValidatorSuite(suiteName, containedValidators); + TF_AXIOM(m.IsClean()); + } +} diff --git a/pxr/usd/usd/usdGenSchema.py b/pxr/usd/usd/usdGenSchema.py index b89ada0d55e..aa456ab75bb 100644 --- a/pxr/usd/usd/usdGenSchema.py +++ b/pxr/usd/usd/usdGenSchema.py @@ -1508,8 +1508,10 @@ def GeneratePlugInfo(templatePath, codeGenPath, classes, validate, env, # for multiple apply schemas. _UpdatePlugInfoWithAPISchemaApplyInfo(clsDict, cls) - # Write out alias/primdefs for all schemas - clsDict['alias'] = {'UsdSchemaBase': cls.usdPrimTypeName} + # Write out aliases for schemas where the cpp class name and + # prim type name do not match. + if cls.usdPrimTypeName != cls.cppClassName: + clsDict['alias'] = {'UsdSchemaBase': cls.usdPrimTypeName} # Write out schema identifier clsDict['schemaIdentifier'] = cls.usdPrimTypeName diff --git a/pxr/usd/usd/validationContext.cpp b/pxr/usd/usd/validationContext.cpp index f93da721a81..0f7aba863af 100644 --- a/pxr/usd/usd/validationContext.cpp +++ b/pxr/usd/usd/validationContext.cpp @@ -8,9 +8,10 @@ #include "pxr/base/tf/type.h" #include "pxr/base/work/dispatcher.h" #include "pxr/base/work/withScopedParallelism.h" -#include "pxr/usd/usd/validationContext.h" +#include "pxr/usd/usd/primFlags.h" #include "pxr/usd/usd/schemaRegistry.h" #include "pxr/usd/usd/stage.h" +#include "pxr/usd/usd/validationContext.h" #include "pxr/usd/usd/validator.h" #include "pxr/usd/usd/validationRegistry.h" @@ -66,7 +67,7 @@ _CollectAncestorTypeValidators( // This is done before filtering the validators by schema types, so that // validators for all ancestor types are collected. for (const TfToken &schemaType : schemaTypeNames) { - const TfType type = TfType::FindByName(schemaType.GetString()); + const TfType type = UsdSchemaRegistry::GetTypeFromName(schemaType); std::vector ancestorTypes; type.GetAllAncestorTypes(&ancestorTypes); for (const TfType &ancestorType : ancestorTypes) { @@ -298,7 +299,8 @@ UsdValidationContext::Validate(const SdfLayerHandle &layer) const } UsdValidationErrorVector -UsdValidationContext::Validate(const UsdStagePtr &stage) const +UsdValidationContext::Validate(const UsdStagePtr &stage, + const Usd_PrimFlagsPredicate &predicate) const { if (!stage) { TF_CODING_ERROR("Invalid stage provided to validate."); @@ -308,12 +310,20 @@ UsdValidationContext::Validate(const UsdStagePtr &stage) const UsdValidationErrorVector errors; std::mutex errorsMutex; WorkWithScopedDispatcher( - [this, &stage, &errors, &errorsMutex](WorkDispatcher &dispatcher) { - _ValidateStage(dispatcher, stage, &errors, &errorsMutex); - }); + [this, &stage, &errors, &errorsMutex, &predicate]( + WorkDispatcher &dispatcher) { + _ValidateStage(dispatcher, stage, &errors, &errorsMutex, + predicate); + }); return errors; } +UsdValidationErrorVector +UsdValidationContext::Validate(const UsdStagePtr &stage) const +{ + return Validate(stage, UsdTraverseInstanceProxies(UsdPrimDefaultPredicate)); +} + UsdValidationErrorVector UsdValidationContext::Validate(const std::vector &prims) const { @@ -373,10 +383,10 @@ UsdValidationContext::_ValidateLayer(WorkDispatcher &dispatcher, } void -UsdValidationContext::_ValidateStage(WorkDispatcher &dispatcher, - const UsdStagePtr &stage, - UsdValidationErrorVector *errors, - std::mutex *errorsMutex) const +UsdValidationContext::_ValidateStage( + WorkDispatcher &dispatcher, const UsdStagePtr &stage, + UsdValidationErrorVector *errors, std::mutex *errorsMutex, + const Usd_PrimFlagsPredicate &predicate) const { // If we reached here via Validate(const UsdStagePtr&), then the stage // must be valid. @@ -393,7 +403,7 @@ UsdValidationContext::_ValidateStage(WorkDispatcher &dispatcher, _AddErrors(validator->Validate(stage), errors, errorsMutex); }); } - _ValidatePrims(dispatcher, stage->Traverse(), errors, errorsMutex); + _ValidatePrims(dispatcher, stage->Traverse(predicate), errors, errorsMutex); } template diff --git a/pxr/usd/usd/validationContext.h b/pxr/usd/usd/validationContext.h index 47157b097f2..46ca8bce068 100644 --- a/pxr/usd/usd/validationContext.h +++ b/pxr/usd/usd/validationContext.h @@ -25,6 +25,7 @@ PXR_NAMESPACE_OPEN_SCOPE class TfType; class WorkDispatcher; +class Usd_PrimFlagsPredicate; /// \class UsdValidationContext /// @@ -181,7 +182,7 @@ class UsdValidationContext /// the layers reachable from the stage. In addition to that any Stage /// validators will also be run on the given stage. The stage will also be /// traversed to run prim and schema type validators on all the prims in the - /// stage. + /// stage. \p predicate will be used to traverse the prims to be validated. /// /// All the validators run in parallel. Any resulting errors are collected /// in the returned vector. @@ -193,6 +194,19 @@ class UsdValidationContext /// /// A coding error is issued if the stage being validated is not valid. USD_API + UsdValidationErrorVector Validate( + const UsdStageWeakPtr &stage, + const Usd_PrimFlagsPredicate &predicate) const; + + /// Run validation on the given valid \p stage by executing the selected + /// validators for this UsdValidationContext; Returns a vector of errors + /// + /// \ref UsdTraverseInstanceProxies "Instance Proxy predicate" is used to + /// traverse the prims to be validated in this overload. + /// + /// \sa UsdValidationContext::Validate(const UsdStageWeakPtr &stage, + /// const Usd_PrimFlagsPredicate &predicate) const + USD_API UsdValidationErrorVector Validate(const UsdStagePtr &stage) const; /// Run validation on the given valid \p prims by executing the selected @@ -253,7 +267,8 @@ class UsdValidationContext void _ValidateStage(WorkDispatcher &dispatcher, const UsdStagePtr &stage, UsdValidationErrorVector *errors, - std::mutex *errorsMutex) const; + std::mutex *errorsMutex, + const Usd_PrimFlagsPredicate &predicate) const; // Helper function to validate prims. Generalized for UsdPrimRange and // vector of UsdPrims. diff --git a/pxr/usd/usd/validationError.cpp b/pxr/usd/usd/validationError.cpp index 4471f5a3045..a448004fc41 100644 --- a/pxr/usd/usd/validationError.cpp +++ b/pxr/usd/usd/validationError.cpp @@ -77,8 +77,17 @@ UsdValidationError::GetIdentifier() const std::string UsdValidationError::GetErrorAsString() const { - return _errorType == UsdValidationErrorType::None ? _errorMsg : TfStringPrintf( - "%s: %s", TfEnum::GetDisplayName(_errorType).c_str(), _errorMsg.c_str()); + if (_validator) { + return _errorType == UsdValidationErrorType::None ? _errorMsg : + TfStringPrintf( + "%s: (%s) %s", TfEnum::GetDisplayName(_errorType).c_str(), + GetIdentifier().GetString().c_str(), _errorMsg.c_str()); + } else { + return _errorType == UsdValidationErrorType::None ? _errorMsg : + TfStringPrintf( + "%s: %s", TfEnum::GetDisplayName(_errorType).c_str(), + _errorMsg.c_str()); + } } void diff --git a/pxr/usd/usd/wrapNamespaceEditor.cpp b/pxr/usd/usd/wrapNamespaceEditor.cpp index b02a0b04fab..5a03c4f2eb0 100644 --- a/pxr/usd/usd/wrapNamespaceEditor.cpp +++ b/pxr/usd/usd/wrapNamespaceEditor.cpp @@ -57,6 +57,10 @@ void wrapUsdNamespaceEditor() .def(init()) .def(init()) + .def("AddDependentStage", &This::AddDependentStage) + .def("RemoveDependentStage", &This::RemoveDependentStage) + .def("SetDependentStages", &This::SetDependentStages) + .def("DeletePrimAtPath", &This::DeletePrimAtPath) .def("MovePrimAtPath", &This::MovePrimAtPath) diff --git a/pxr/usd/usd/wrapValidationContext.cpp b/pxr/usd/usd/wrapValidationContext.cpp new file mode 100644 index 00000000000..d6f63d38839 --- /dev/null +++ b/pxr/usd/usd/wrapValidationContext.cpp @@ -0,0 +1,81 @@ +// +// Copyright 2024 Pixar +// +// Licensed under the terms set forth in the LICENSE.txt file available at +// https:/(); + class_("ValidationContext", no_init) + .def(init( + (arg("keywords"), arg("includeAllAncestors") = true))) + .def(init( + (arg("plugins"), arg("includeAllAncestors") = true))) + .def(init( + (arg("metadata"), arg("includeAllAncestors") = true))) + .def(init &>(arg("schemaTypes"))) + .def(init &>(arg("validators"))) + .def(init &>(arg("suites"))) + .def("Validate", + +[](const UsdValidationContext &ctx, const SdfLayerHandle &layer) + -> UsdValidationErrorVector { + return ctx.Validate(layer); + }, + return_value_policy(), + (arg("layer"))) + .def("Validate", + +[](const UsdValidationContext &ctx, const UsdStagePtr &stage) + -> UsdValidationErrorVector { + return ctx.Validate(stage); + }, + return_value_policy(), + (arg("stage"))) + .def("Validate", + +[](const UsdValidationContext &ctx, const UsdStagePtr &stage, + const Usd_PrimFlagsPredicate &predicate) + -> UsdValidationErrorVector { + return ctx.Validate(stage, predicate); + }, + return_value_policy(), + (arg("stage"), arg("predicate"))) + .def("Validate", + +[](const UsdValidationContext &ctx, + const std::vector &prims) + -> UsdValidationErrorVector { + return ctx.Validate(prims); + }, + return_value_policy(), + (arg("prims"))) + .def("Validate", + +[](const UsdValidationContext &ctx, const UsdPrimRange &prims) + -> UsdValidationErrorVector { + return ctx.Validate(prims); + }, + return_value_policy(), + (arg("prims"))); +} diff --git a/pxr/usd/usd/wrapValidator.cpp b/pxr/usd/usd/wrapValidator.cpp index 16541159187..19aa0f6e35b 100644 --- a/pxr/usd/usd/wrapValidator.cpp +++ b/pxr/usd/usd/wrapValidator.cpp @@ -84,6 +84,7 @@ void wrapUsdValidator() +[](const UsdValidatorMetadata &self) { return self.schemaTypes; }); + TfPyRegisterStlSequencesFromPython(); TfPyRegisterStlSequencesFromPython(); class_("Validator", no_init) @@ -118,6 +119,7 @@ void wrapUsdValidator() return left == right; }) .def("__repr__", &_Repr); + TfPyRegisterStlSequencesFromPython(); class_("ValidatorSuite", no_init) .def("GetMetadata", @@ -130,4 +132,5 @@ void wrapUsdValidator() +[](const UsdValidatorSuite *left, const UsdValidatorSuite *right) { return left == right; }); + TfPyRegisterStlSequencesFromPython(); } diff --git a/pxr/usd/usdGeom/pch.h b/pxr/usd/usdGeom/pch.h index 8771c52e41b..8fd0de332c7 100644 --- a/pxr/usd/usdGeom/pch.h +++ b/pxr/usd/usdGeom/pch.h @@ -72,6 +72,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/pxr/usd/usdHydra/pch.h b/pxr/usd/usdHydra/pch.h index bc6c47f91be..fdb618c79cd 100644 --- a/pxr/usd/usdHydra/pch.h +++ b/pxr/usd/usdHydra/pch.h @@ -70,6 +70,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/pxr/usd/usdLux/pch.h b/pxr/usd/usdLux/pch.h index c03cc805441..b240b8f188f 100644 --- a/pxr/usd/usdLux/pch.h +++ b/pxr/usd/usdLux/pch.h @@ -72,6 +72,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/pxr/usd/usdMedia/pch.h b/pxr/usd/usdMedia/pch.h index 95efd0e603e..cd456ff1527 100644 --- a/pxr/usd/usdMedia/pch.h +++ b/pxr/usd/usdMedia/pch.h @@ -71,6 +71,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/pxr/usd/usdMtlx/pch.h b/pxr/usd/usdMtlx/pch.h index 4856d3e163e..80c90a4b847 100644 --- a/pxr/usd/usdMtlx/pch.h +++ b/pxr/usd/usdMtlx/pch.h @@ -92,6 +92,7 @@ #include #endif // PXR_MATERIALX_SUPPORT_ENABLED #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/pxr/usd/usdMtlx/reader.cpp b/pxr/usd/usdMtlx/reader.cpp index f04ab07ac1a..6a3a91b12f6 100644 --- a/pxr/usd/usdMtlx/reader.cpp +++ b/pxr/usd/usdMtlx/reader.cpp @@ -433,9 +433,15 @@ _TypeSupportsColorSpace(const mx::ConstValueElementPtr& mxElem) bool colorImageNode = false; if (type == "filename") { - // verify the output is color3 or color4 - mx::ConstNodeDefPtr parentNodeDef = - _GetNodeDef(mxElem->getParent()->asA()); + mx::ConstNodeDefPtr parentNodeDef; + if (mxElem->getParent()->isA()) { + parentNodeDef = _GetNodeDef(mxElem->getParent()->asA()); + } + else if (mxElem->getParent()->isA()) { + parentNodeDef = mxElem->getParent()->asA(); + } + + // Verify the output is color3 or color4 if (parentNodeDef) { for (const mx::OutputPtr& output : parentNodeDef->getOutputs()) { const std::string &type = output->getType(); diff --git a/pxr/usd/usdPhysics/pch.h b/pxr/usd/usdPhysics/pch.h index 0a1efa7d7ed..86afdf3d243 100644 --- a/pxr/usd/usdPhysics/pch.h +++ b/pxr/usd/usdPhysics/pch.h @@ -71,6 +71,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/pxr/usd/usdProc/pch.h b/pxr/usd/usdProc/pch.h index 217de22bb65..394c8a5b413 100644 --- a/pxr/usd/usdProc/pch.h +++ b/pxr/usd/usdProc/pch.h @@ -71,6 +71,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/pxr/usd/usdRender/pch.h b/pxr/usd/usdRender/pch.h index 563904359ba..ef74172525b 100644 --- a/pxr/usd/usdRender/pch.h +++ b/pxr/usd/usdRender/pch.h @@ -72,6 +72,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/pxr/usd/usdRi/pch.h b/pxr/usd/usdRi/pch.h index e231b17831a..c1bc921d0d1 100644 --- a/pxr/usd/usdRi/pch.h +++ b/pxr/usd/usdRi/pch.h @@ -71,6 +71,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/pxr/usd/usdSemantics/overview.md b/pxr/usd/usdSemantics/overview.md index ecefaffbeed..1eb804b00d2 100644 --- a/pxr/usd/usdSemantics/overview.md +++ b/pxr/usd/usdSemantics/overview.md @@ -1,3 +1,4 @@ +# UsdSemantics : Semantic Labeling for Model Hierarchy {#usd_semantics_overview} \if ( PIXAR_MFB_BUILD ) \mainpage UsdSemantics : Semantic Labeling for Model Hierarchy \endif @@ -110,7 +111,7 @@ of a car prim" could be modeled by filtering the scene graph by prims with direct label `wheel` and whose parent has an inherited label `car`. ## Relationship to Other Domains -### `UsdGeom` +### UsdGeom The most common application of semantic labels will be to `Gprim`s and their ancestral `Scope`s and `Xform`s. @@ -120,7 +121,7 @@ labels as well. For example `/Human/Face` `Mesh` prim may have a `/Human/Face/LeftEar` and `/Human/Face/RightEar` `GeomSubset`s with `["ear"]` labels applied. -### `UsdShade` +### UsdShade `Material`s may be semantically labeled as well. For example, a `RustyMetal` Material could be semantically labeled with both `metal` and `corroded` labels. As `usdSemantics` is a domain separate from `UsdGeom` and `UsdShade`, there are @@ -167,7 +168,7 @@ purposes, there's no specification for if or how labels should feed into render products, as shader nodes and node graphs (unlike `UsdGeomSubset`) generally don't yield discrete segmentations. -### `UsdRender` (To be proposed and implemented) +### UsdRender (To be proposed and implemented) A common application of semantics is for downstream labeling and segmentation of renderer output. Semantics may make their way into outputs as either additional metadata or as matte channels. \ No newline at end of file diff --git a/pxr/usd/usdSemantics/pch.h b/pxr/usd/usdSemantics/pch.h index 7bb0332472a..dac396816ef 100644 --- a/pxr/usd/usdSemantics/pch.h +++ b/pxr/usd/usdSemantics/pch.h @@ -88,6 +88,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/pxr/usd/usdShade/pch.h b/pxr/usd/usdShade/pch.h index 3dcf3fcf01d..9ef32c84e00 100644 --- a/pxr/usd/usdShade/pch.h +++ b/pxr/usd/usdShade/pch.h @@ -87,6 +87,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/pxr/usd/usdSkel/pch.h b/pxr/usd/usdSkel/pch.h index 3e5bf6fd804..ba7cba856fe 100644 --- a/pxr/usd/usdSkel/pch.h +++ b/pxr/usd/usdSkel/pch.h @@ -71,6 +71,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/pxr/usd/usdUI/pch.h b/pxr/usd/usdUI/pch.h index 6d53e8bfe4f..4852335387d 100644 --- a/pxr/usd/usdUI/pch.h +++ b/pxr/usd/usdUI/pch.h @@ -69,6 +69,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/pxr/usd/usdUI/schema.usda b/pxr/usd/usdUI/schema.usda index 88d022c67f3..c8b95718837 100644 --- a/pxr/usd/usdUI/schema.usda +++ b/pxr/usd/usdUI/schema.usda @@ -1,6 +1,6 @@ #usda 1.0 ( - "This file describes the USD Shader schemata for code generation." + "This file describes the USD User Interface schemata for code generation." subLayers = [ @usd/schema.usda@ ] diff --git a/pxr/usd/usdUtils/CMakeLists.txt b/pxr/usd/usdUtils/CMakeLists.txt index dd0605106fa..5e27b27b4cd 100644 --- a/pxr/usd/usdUtils/CMakeLists.txt +++ b/pxr/usd/usdUtils/CMakeLists.txt @@ -246,6 +246,16 @@ pxr_install_test_dir( DEST testUsdUtilsDependencyExtractor5 ) +pxr_install_test_dir( + SRC testenv/testUsdUtilsDependencyExtractor + DEST testUsdUtilsDependencyExtractor6 +) + +pxr_install_test_dir( + SRC testenv/testUsdUtilsDependencyExtractor + DEST testUsdUtilsDependencyExtractor7 +) + pxr_install_test_dir( SRC testenv/testUsdUtilsFlattenLayerStack DEST testUsdUtilsFlattenLayerStack @@ -590,6 +600,20 @@ pxr_register_test(testUsdUtilsDependencyExtractor5 EXPECTED_RETURN_CODE 0 ) +pxr_register_test(testUsdUtilsDependencyExtractor6 + PYTHON + COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testUsdUtilsDependencyExtractor udims/root.usda udims.txt" + DIFF_COMPARE udims.txt + EXPECTED_RETURN_CODE 0 +) + +pxr_register_test(testUsdUtilsDependencyExtractor7 + PYTHON + COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testUsdUtilsDependencyExtractor --resolve-udim-paths udims/root.usda udims-resolved.txt" + DIFF_COMPARE udims-resolved.txt + EXPECTED_RETURN_CODE 0 +) + pxr_register_test(testUsdUtilsFlattenLayerStack PYTHON COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testUsdUtilsFlattenLayerStack" @@ -619,7 +643,9 @@ pxr_register_test(testUsdUtilsLocalizeAssetUdims pxr_register_test(testUsdUtilsModifyAssetPaths PYTHON COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testUsdUtilsModifyAssetPaths layer.usda modified.usda" - DIFF_COMPARE modified.usda duplicates.usda removal.usda removal_preserve_length.usda ref_layer_mod.usda ref_unmodified.usda + DIFF_COMPARE + modified.usda duplicates.usda removal.usda removal_preserve_length.usda + ref_layer_mod.usda ref_unmodified.usda preserve_metadata.usda EXPECTED_RETURN_CODE 0 ) diff --git a/pxr/usd/usdUtils/assetLocalization.cpp b/pxr/usd/usdUtils/assetLocalization.cpp index 1df66c4fdb9..3ae5e2f092f 100644 --- a/pxr/usd/usdUtils/assetLocalization.cpp +++ b/pxr/usd/usdUtils/assetLocalization.cpp @@ -229,7 +229,8 @@ UsdUtils_LocalizationContext::_ProcessMetadata( _delegate->BeginProcessValue(layer, value); _ProcessAssetValue(layer, infoKey, value, - /*processingMetadata*/ true); + /*processingMetadata*/ true, + /*processingDictionary*/ false); _delegate->EndProcessValue( layer, primSpec->GetPath(), infoKey, value); } @@ -440,9 +441,10 @@ void UsdUtils_LocalizationContext::_ProcessAssetValue( const SdfLayerRefPtr& layer, const VtValue &val, - bool processingMetadata) + bool processingMetadata, + bool processingDictionary) { - _ProcessAssetValue(layer, std::string(), val, processingMetadata); + _ProcessAssetValue(layer, std::string(), val, processingMetadata, processingDictionary); } void @@ -450,7 +452,8 @@ UsdUtils_LocalizationContext::_ProcessAssetValue( const SdfLayerRefPtr& layer, const std::string &keyPath, const VtValue &val, - bool processingMetadata) + bool processingMetadata, + bool processingDictionary) { if (_ShouldFilterAssetPath(keyPath, processingMetadata)) { return; @@ -465,7 +468,8 @@ UsdUtils_LocalizationContext::_ProcessAssetValue( const std::vector processedDeps = _delegate->ProcessValuePath( - layer, keyPath, rawAssetPath, dependencies); + layer, keyPath, rawAssetPath, dependencies, + processingMetadata, processingDictionary); _EnqueueDependency(layer, rawAssetPath); _EnqueueDependencies(layer, processedDeps); @@ -504,7 +508,9 @@ UsdUtils_LocalizationContext::_ProcessAssetValue( for (const auto& p : originalDict) { const std::string dictKey = keyPath.empty() ? p.first : keyPath + ':' + p.first; - _ProcessAssetValue(layer, dictKey, p.second, processingMetadata); + _ProcessAssetValue( + layer, dictKey, p.second, + processingMetadata, /*processingDictionary*/true); } } @@ -527,7 +533,7 @@ UsdUtils_LocalizationContext::_GetUdimTiles( { std::vector additionalPaths; - if (!UsdShadeUdimUtils::IsUdimIdentifier(assetPath)) { + if (!_resolveUdimPaths || !UsdShadeUdimUtils::IsUdimIdentifier(assetPath)) { return additionalPaths; } @@ -631,7 +637,8 @@ void UsdUtils_ExtractExternalReferences( const UsdUtils_LocalizationContext::ReferenceType refTypesToInclude, std::vector* outSublayers, std::vector* outReferences, - std::vector* outPayloads) + std::vector* outPayloads, + const UsdUtilsExtractExternalReferencesParams& params) { TRACE_FUNCTION(); @@ -643,6 +650,7 @@ void UsdUtils_ExtractExternalReferences( UsdUtils_LocalizationContext context(&delegate); context.SetRefTypesToInclude(refTypesToInclude); context.SetRecurseLayerDependencies(false); + context.SetResolveUdimPaths(params.GetResolveUdimPaths()); context.Process(SdfLayer::FindOrOpen(filePath)); client.SortAndRemoveDuplicates(); diff --git a/pxr/usd/usdUtils/assetLocalization.h b/pxr/usd/usdUtils/assetLocalization.h index 4150879698b..87c8c541734 100644 --- a/pxr/usd/usdUtils/assetLocalization.h +++ b/pxr/usd/usdUtils/assetLocalization.h @@ -88,6 +88,13 @@ class UsdUtils_LocalizationContext { dependenciesToSkip.end()); } + // Controls udim path resolution. + // If this value is set to false, asset paths containing udim patterns + // be re returned untouched. + inline void SetResolveUdimPaths(bool resolveUdimPaths) { + _resolveUdimPaths = resolveUdimPaths; + } + private: void _ProcessLayer(const SdfLayerRefPtr& layer); void _ProcessSublayers(const SdfLayerRefPtr& layer); @@ -105,17 +112,19 @@ class UsdUtils_LocalizationContext { void _ProcessAssetValue(const SdfLayerRefPtr& layer, const std::string &key, const VtValue &val, - bool processingMetadata = false); + bool processingMetadata = false, + bool processingDictionary = false); void _ProcessAssetValue(const SdfLayerRefPtr& layer, const VtValue &val, - bool processingMetadata = false); + bool processingMetadata = false, + bool processingDictionary = false); // Searches for udim tiles associated with the given asset path. - static std::vector _GetUdimTiles(const SdfLayerRefPtr& layer, + std::vector _GetUdimTiles(const SdfLayerRefPtr& layer, const std::string &assetPath); // Discovers all dependencies for the supplied asset path - static std::vector _GetDependencies(const SdfLayerRefPtr& layer, + std::vector _GetDependencies(const SdfLayerRefPtr& layer, const std::string &assetPath); // Searches for the clips of a given templated string @@ -158,6 +167,9 @@ class UsdUtils_LocalizationContext { // Specifies if metadata filtering should be enabled bool _metadataFilteringEnabled = false; + // Specifies if udim paths should be resolved during processing. + bool _resolveUdimPaths = true; + // user supplied list of dependencies that will be skipped when // processing the asset std::unordered_set _dependenciesToSkip; @@ -168,7 +180,8 @@ void UsdUtils_ExtractExternalReferences( const UsdUtils_LocalizationContext::ReferenceType refTypesToInclude, std::vector* subLayers, std::vector* references, - std::vector* payloads); + std::vector* payloads, + const UsdUtilsExtractExternalReferencesParams& params = {}); PXR_NAMESPACE_CLOSE_SCOPE diff --git a/pxr/usd/usdUtils/assetLocalizationDelegate.cpp b/pxr/usd/usdUtils/assetLocalizationDelegate.cpp index 8495271b370..d9931000650 100644 --- a/pxr/usd/usdUtils/assetLocalizationDelegate.cpp +++ b/pxr/usd/usdUtils/assetLocalizationDelegate.cpp @@ -137,9 +137,7 @@ UsdUtils_WritableLocalizationDelegate::_ProcessReferencesOrPayloads( return _ProcessRefOrPayload ( layer, item, &dependencies); - }, - /*removeDuplicates*/ true - ); + }); if (!modified) { return dependencies; @@ -216,7 +214,9 @@ UsdUtils_WritableLocalizationDelegate::ProcessValuePath( const SdfLayerRefPtr &layer, const std::string &keyPath, const std::string &authoredPath, - const std::vector &dependencies) + const std::vector &dependencies, + const bool processingMetadata, + const bool processingDictionary) { if (authoredPath.empty()) { return {}; @@ -228,7 +228,10 @@ UsdUtils_WritableLocalizationDelegate::ProcessValuePath( const std::string relativeKeyPath = _GetRelativeKeyPath(keyPath); - if (relativeKeyPath.empty()) { + if (relativeKeyPath.empty() || ( + processingMetadata && + !processingDictionary && + !info.GetAssetPath().empty())) { _currentValuePath = SdfAssetPath(info.GetAssetPath()); } else if (info.GetAssetPath().empty()){ @@ -567,7 +570,9 @@ UsdUtils_ReadOnlyLocalizationDelegate::ProcessValuePath( const SdfLayerRefPtr &layer, const std::string &keyPath, const std::string &authoredPath, - const std::vector &dependencies) + const std::vector &dependencies, + const bool processingMetadata, + const bool processingDictionary) { if (authoredPath.empty()) { return {}; diff --git a/pxr/usd/usdUtils/assetLocalizationDelegate.h b/pxr/usd/usdUtils/assetLocalizationDelegate.h index 4a36dcb48ed..afe0cde0f14 100644 --- a/pxr/usd/usdUtils/assetLocalizationDelegate.h +++ b/pxr/usd/usdUtils/assetLocalizationDelegate.h @@ -66,7 +66,9 @@ struct UsdUtils_LocalizationDelegate const SdfLayerRefPtr &layer, const std::string &keyPath, const std::string &authoredPath, - const std::vector &dependencies) { return {}; } + const std::vector &dependencies, + const bool processingMetadata = false, + const bool processingDictionary = false) { return {}; } virtual std::vector ProcessValuePathArrayElement( const SdfLayerRefPtr &layer, @@ -157,7 +159,9 @@ class UsdUtils_WritableLocalizationDelegate const SdfLayerRefPtr &layer, const std::string &keyPath, const std::string &authoredPath, - const std::vector &dependencies) override; + const std::vector &dependencies, + const bool processingMetadata = false, + const bool processingDictionary = false) override; virtual std::vector ProcessValuePathArrayElement( const SdfLayerRefPtr &layer, @@ -283,7 +287,9 @@ class UsdUtils_ReadOnlyLocalizationDelegate const SdfLayerRefPtr &layer, const std::string &keyPath, const std::string &authoredPath, - const std::vector &dependencies) override; + const std::vector &dependencies, + const bool processingMetadata = false, + const bool processingDictionary = false) override; virtual std::vector ProcessValuePathArrayElement( const SdfLayerRefPtr &layer, diff --git a/pxr/usd/usdUtils/complianceChecker.py b/pxr/usd/usdUtils/complianceChecker.py index fec233e58cd..1ad43063a70 100644 --- a/pxr/usd/usdUtils/complianceChecker.py +++ b/pxr/usd/usdUtils/complianceChecker.py @@ -1073,7 +1073,16 @@ def CheckCompliance(self, inputFile): # Collect all warnings using a diagnostic delegate. delegate = UsdUtils.CoalescingDiagnosticDelegate() - usdStage = Usd.Stage.Open(inputFile) + from pxr import Tf + try: + # It is possible Usd.Stage.Open will raise a TF_RUNTIME_ERROR + # (example via usdAbc plugin) which should be appropriately handled. + usdStage = Usd.Stage.Open(inputFile) + except Tf.ErrorException as e: + self._AddError("Failed to open USD stage from file '%s': %s" % + (inputFile, str(e))) + return + stageOpenDiagnostics = delegate.TakeUncoalescedDiagnostics() for rule in self._rules: @@ -1083,8 +1092,15 @@ def CheckCompliance(self, inputFile): with Ar.ResolverContextBinder(usdStage.GetPathResolverContext()): # This recursively computes all of inputFiles's external # dependencies. - (allLayers, allAssets, unresolvedPaths) = \ + from pxr import Tf + try: + (allLayers, allAssets, unresolvedPaths) = \ UsdUtils.ComputeAllDependencies(Sdf.AssetPath(inputFile)) + except Tf.ErrorException as e: + self._AddError( + "Failed to compute dependencies for file '%s': %s" % + (inputFile, str(e))) + return for rule in self._rules: rule.CheckUnresolvedPaths(unresolvedPaths) rule.CheckDependencies(usdStage, allLayers, allAssets) diff --git a/pxr/usd/usdUtils/dependencies.cpp b/pxr/usd/usdUtils/dependencies.cpp index 56c92f8e607..0eec2a94a55 100644 --- a/pxr/usd/usdUtils/dependencies.cpp +++ b/pxr/usd/usdUtils/dependencies.cpp @@ -34,11 +34,12 @@ UsdUtilsExtractExternalReferences( const std::string& filePath, std::vector* subLayers, std::vector* references, - std::vector* payloads) + std::vector* payloads, + const UsdUtilsExtractExternalReferencesParams& params) { UsdUtils_ExtractExternalReferences(filePath, UsdUtils_LocalizationContext::ReferenceType::All, - subLayers, references, payloads); + subLayers, references, payloads, params); } struct UsdUtils_ComputeAllDependenciesClient diff --git a/pxr/usd/usdUtils/dependencies.h b/pxr/usd/usdUtils/dependencies.h index 648dbffed42..3ddf40ca37c 100644 --- a/pxr/usd/usdUtils/dependencies.h +++ b/pxr/usd/usdUtils/dependencies.h @@ -28,11 +28,34 @@ PXR_NAMESPACE_OPEN_SCOPE +/// Structure which controls aspects of the +/// \ref UsdUtilsExtractExternalReferences function. +class UsdUtilsExtractExternalReferencesParams { +public: + /// Specifies whether UDIM template paths should be resolved when extracting + /// references. If true, the resolved paths for all discovered UDIM tiles + /// will be included in the references bucket and the template path will be + /// discarded. If false, no resolution will take place and the template path + /// will appear in the references bucket. + inline void SetResolveUdimPaths(bool resolveUdimPaths) { + _resolveUdimPaths = resolveUdimPaths; + } + + + inline bool GetResolveUdimPaths() const { return _resolveUdimPaths; } + +private: + bool _resolveUdimPaths = false; +}; + /// Parses the file at \p filePath, identifying external references, and /// sorting them into separate type-based buckets. Sublayers are returned in /// the \p sublayers vector, references, whether prim references, value clip /// references or values from asset path attributes, are returned in the /// \p references vector. Payload paths are returned in \p payloads. +/// The \p params parameter controls various settings that affect the +/// extraction process. See \ref UsdUtilsExtractExternalReferencesParams for +/// additional details. /// /// \note No recursive chasing of dependencies is performed; that is the /// client's responsibility, if desired. @@ -45,7 +68,8 @@ void UsdUtilsExtractExternalReferences( const std::string& filePath, std::vector* subLayers, std::vector* references, - std::vector* payloads); + std::vector* payloads, + const UsdUtilsExtractExternalReferencesParams& params = {}); /// Recursively computes all the dependencies of the given asset and populates /// \p layers with all the dependencies that can be opened as an SdfLayer. diff --git a/pxr/usd/usdUtils/pch.h b/pxr/usd/usdUtils/pch.h index 7bb0332472a..dac396816ef 100644 --- a/pxr/usd/usdUtils/pch.h +++ b/pxr/usd/usdUtils/pch.h @@ -88,6 +88,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/pxr/usd/usdUtils/plugInfo.json b/pxr/usd/usdUtils/plugInfo.json index 4d429b639a6..1962a094a63 100644 --- a/pxr/usd/usdUtils/plugInfo.json +++ b/pxr/usd/usdUtils/plugInfo.json @@ -4,7 +4,10 @@ "Info": { "Validators": { "PackageEncapsulationValidator": { - "doc": "If the root layer is a package, then its recommended for the composed stage to not contain references to files outside the package. The package should be self-contained, warn if not." + "doc": "If the root layer is a package, then its recommended for the composed stage to not contain references to files outside the package. The package should be self-contained, warn if not.", + "keywords": [ + "UsdzValidators" + ] }, "keywords": [ "UsdUtilsValidators" diff --git a/pxr/usd/usdUtils/testenv/testUsdUtilsDependencyExtractor.py b/pxr/usd/usdUtils/testenv/testUsdUtilsDependencyExtractor.py index 95a9e27320a..f421accfb43 100644 --- a/pxr/usd/usdUtils/testenv/testUsdUtilsDependencyExtractor.py +++ b/pxr/usd/usdUtils/testenv/testUsdUtilsDependencyExtractor.py @@ -28,6 +28,7 @@ def presult(ostr, fileName, refType, refs): parser.add_argument('infile') parser.add_argument('outfile', default='-') parser.add_argument('--open-as-anon', dest='openAsAnon', action='store_true') + parser.add_argument('--resolve-udim-paths', dest="resolveUdimPaths", action='store_true') args = parser.parse_args() if not os.path.exists(args.infile): @@ -46,8 +47,12 @@ def presult(ostr, fileName, refType, refs): layer.SetPermissionToEdit(False) identifier = args.infile + extractionParams = UsdUtils.ExtractExternalReferencesParams() + if (args.resolveUdimPaths): + extractionParams.SetResolveUdimPaths(True) + sublayers, references, payloads = \ - UsdUtils.ExtractExternalReferences(identifier) + UsdUtils.ExtractExternalReferences(identifier, extractionParams) with stream(args.outfile, 'w') as ofp: presult(ofp, args.infile, 'sublayers', sublayers) diff --git a/pxr/usd/usdUtils/testenv/testUsdUtilsDependencyExtractor/baseline/udims-resolved.txt b/pxr/usd/usdUtils/testenv/testUsdUtilsDependencyExtractor/baseline/udims-resolved.txt new file mode 100644 index 00000000000..2606fd2a8f1 --- /dev/null +++ b/pxr/usd/usdUtils/testenv/testUsdUtilsDependencyExtractor/baseline/udims-resolved.txt @@ -0,0 +1,4 @@ +udims/root.usda no sublayers +udims/root.usda references[001]: ./test.1001.txt +udims/root.usda references[002]: ./test.1002.txt +udims/root.usda no payloads diff --git a/pxr/usd/usdUtils/testenv/testUsdUtilsDependencyExtractor/baseline/udims.txt b/pxr/usd/usdUtils/testenv/testUsdUtilsDependencyExtractor/baseline/udims.txt new file mode 100644 index 00000000000..d5a5bec0e2b --- /dev/null +++ b/pxr/usd/usdUtils/testenv/testUsdUtilsDependencyExtractor/baseline/udims.txt @@ -0,0 +1,3 @@ +udims/root.usda no sublayers +udims/root.usda references[001]: ./test..txt +udims/root.usda no payloads diff --git a/pxr/usd/usdUtils/testenv/testUsdUtilsDependencyExtractor/udims/root.usda b/pxr/usd/usdUtils/testenv/testUsdUtilsDependencyExtractor/udims/root.usda new file mode 100644 index 00000000000..181d94d03ff --- /dev/null +++ b/pxr/usd/usdUtils/testenv/testUsdUtilsDependencyExtractor/udims/root.usda @@ -0,0 +1,5 @@ +#usda 1.0 + +def "Test" { + asset udims = @./test..txt@ +} \ No newline at end of file diff --git a/pxr/usd/usdUtils/testenv/testUsdUtilsDependencyExtractor/udims/test.1001.txt b/pxr/usd/usdUtils/testenv/testUsdUtilsDependencyExtractor/udims/test.1001.txt new file mode 100644 index 00000000000..7cebf7db5f2 --- /dev/null +++ b/pxr/usd/usdUtils/testenv/testUsdUtilsDependencyExtractor/udims/test.1001.txt @@ -0,0 +1 @@ +1001 \ No newline at end of file diff --git a/pxr/usd/usdUtils/testenv/testUsdUtilsDependencyExtractor/udims/test.1002.txt b/pxr/usd/usdUtils/testenv/testUsdUtilsDependencyExtractor/udims/test.1002.txt new file mode 100644 index 00000000000..5ed13cbaef2 --- /dev/null +++ b/pxr/usd/usdUtils/testenv/testUsdUtilsDependencyExtractor/udims/test.1002.txt @@ -0,0 +1 @@ +1002 \ No newline at end of file diff --git a/pxr/usd/usdUtils/testenv/testUsdUtilsModifyAssetPaths.py b/pxr/usd/usdUtils/testenv/testUsdUtilsModifyAssetPaths.py index e1e06b26218..fe6853a6718 100644 --- a/pxr/usd/usdUtils/testenv/testUsdUtilsModifyAssetPaths.py +++ b/pxr/usd/usdUtils/testenv/testUsdUtilsModifyAssetPaths.py @@ -62,3 +62,12 @@ def fn(s): refLayer.Export("ref_unmodified.usda") TestDoesNotRecurseDeps() + +def TestDoesNotStripMetadata(): + # Ensure that metadata is retained. + def fn(s): + return s + + Test('metadata.usda', 'preserve_metadata.usda', fn) + +TestDoesNotStripMetadata() diff --git a/pxr/usd/usdUtils/testenv/testUsdUtilsModifyAssetPaths/baseline/preserve_metadata.usda b/pxr/usd/usdUtils/testenv/testUsdUtilsModifyAssetPaths/baseline/preserve_metadata.usda new file mode 100644 index 00000000000..fd8c13b9af4 --- /dev/null +++ b/pxr/usd/usdUtils/testenv/testUsdUtilsModifyAssetPaths/baseline/preserve_metadata.usda @@ -0,0 +1,11 @@ +#usda 1.0 + +def "Model" ( + high = @example:geo/high.usd@ + lod = "low" + low = @example:geo/low.usd@ + payload = @example:geo/payload.usdc@ +) +{ +} + diff --git a/pxr/usd/usdUtils/testenv/testUsdUtilsModifyAssetPaths/metadata.usda b/pxr/usd/usdUtils/testenv/testUsdUtilsModifyAssetPaths/metadata.usda new file mode 100644 index 00000000000..fd8c13b9af4 --- /dev/null +++ b/pxr/usd/usdUtils/testenv/testUsdUtilsModifyAssetPaths/metadata.usda @@ -0,0 +1,11 @@ +#usda 1.0 + +def "Model" ( + high = @example:geo/high.usd@ + lod = "low" + low = @example:geo/low.usd@ + payload = @example:geo/payload.usdc@ +) +{ +} + diff --git a/pxr/usd/usdUtils/testenv/testUsdUtilsUpdateSchemaWithSdrNode/baseline/schemaConcrete.usda b/pxr/usd/usdUtils/testenv/testUsdUtilsUpdateSchemaWithSdrNode/baseline/schemaConcrete.usda index 5b22e6c0a46..800b1734ea1 100644 --- a/pxr/usd/usdUtils/testenv/testUsdUtilsUpdateSchemaWithSdrNode/baseline/schemaConcrete.usda +++ b/pxr/usd/usdUtils/testenv/testUsdUtilsUpdateSchemaWithSdrNode/baseline/schemaConcrete.usda @@ -20,7 +20,14 @@ class TestSchemaConcrete "TestSchemaConcrete" ( photographic measurements. """ string userDocBrief = """ - exposure: Specify the intensity of the light source as a power of 2 (in stops).""" + exposure: Specify the intensity of the light source as a power of 2 (in stops). + Increasing the exposure by 1 will double the energy emitted by the light source. + A value of 0 produces an intensity of 1, -1 produces .5. You may wonder why you + might use Exposure, and the answer is that real world lighting has high energies + and typical exposures are low values while you may have to type a really large + number for equivalent Intensity. This is also comfortable to artists familiar with + photographic measurements. + """ } displayGroup = "Basic" displayName = "Exposure" diff --git a/pxr/usd/usdUtils/updateSchemaWithSdrNode.py b/pxr/usd/usdUtils/updateSchemaWithSdrNode.py index 2ed04141fb7..9e998c865d8 100644 --- a/pxr/usd/usdUtils/updateSchemaWithSdrNode.py +++ b/pxr/usd/usdUtils/updateSchemaWithSdrNode.py @@ -46,7 +46,6 @@ class PropertyDefiningKeys(ConstantsGroup): class UserDocConstants(ConstantsGroup): USERDOC_FULL = "userDoc" USERDOC_BRIEF = "userDocBrief" - MAX_LENGTH_FOR_BRIEF = 500 def _IsNSPrefixConnectableAPICompliant(nsPrefix): return (nsPrefix == UsdShade.Tokens.inputs[:1] or \ @@ -177,17 +176,8 @@ def _SetSchemaUserDocFields(spec, doc): and attribute specs. """ # Set the "brief" user doc, used for in-context help, e.g. in DCC tools. - # If the doc string exceeds a certain length, just use the first sentence. - workDoc = "" - if len(doc) > UserDocConstants.MAX_LENGTH_FOR_BRIEF: - workDoc = doc.partition('.')[0] + '.' - # If '.' wasn't found, workDoc will be the entire doc string, so - # instead use the first MAX_LENGTH_FOR_BRIEF chars and append '...' - if len(workDoc) > UserDocConstants.MAX_LENGTH_FOR_BRIEF: - workDoc = workDoc[:UserDocConstants.MAX_LENGTH_FOR_BRIEF] + "..." - else: - workDoc = doc - spec.customData[UserDocConstants.USERDOC_BRIEF] = workDoc + # We currently want the full content, so we don't shorten userDocBrief. + spec.customData[UserDocConstants.USERDOC_BRIEF] = doc # Set the "long-form" user doc, used when generating HTML schema docs # (example: https://openusd.org/release/user_guides/schemas/index.html) spec.customData[UserDocConstants.USERDOC_FULL] = doc diff --git a/pxr/usd/usdUtils/usdzPackage.cpp b/pxr/usd/usdUtils/usdzPackage.cpp index f53cb451534..a3c70311471 100644 --- a/pxr/usd/usdUtils/usdzPackage.cpp +++ b/pxr/usd/usdUtils/usdzPackage.cpp @@ -117,9 +117,17 @@ UsdUtilsCreateNewARKitUsdzPackage( // the composition of the stage. std::vector sublayers, references, payloads; + // We are explicitly setting the UDIM path resolution option to false + // here because the following logic only cares if the root layer contains + // any external references and does reason about the contents of the + // results. UDIM path resolution has the potential to be expensive, for + // example in the case of network filesystem paths. + UsdUtilsExtractExternalReferencesParams params; + params.SetResolveUdimPaths(false); + UsdUtils_ExtractExternalReferences(resolvedPath, UsdUtils_LocalizationContext::ReferenceType::CompositionOnly, - &sublayers, &references, &payloads); + &sublayers, &references, &payloads, params); // Ensure that the root layer has the ".usdc" extension. std::string targetBaseName = firstLayerName.empty() ? diff --git a/pxr/usd/usdUtils/validatorTokens.h b/pxr/usd/usdUtils/validatorTokens.h index ac5424e131c..cc0b7ac1df9 100644 --- a/pxr/usd/usdUtils/validatorTokens.h +++ b/pxr/usd/usdUtils/validatorTokens.h @@ -25,7 +25,8 @@ PXR_NAMESPACE_OPEN_SCOPE #define USD_UTILS_VALIDATION_ERROR_NAME_TOKENS \ ((layerNotInPackage, "LayerNotInPackage")) \ - ((assetNotInPackage, "AssetNotInPackage")) + ((assetNotInPackage, "AssetNotInPackage")) \ + ((invalidLayerInPackage, "InvalidLayerInPackage")) ///\def /// Tokens representing validator names. Note that for plugin provided diff --git a/pxr/usd/usdUtils/validators.cpp b/pxr/usd/usdUtils/validators.cpp index 513f2aa5fc4..64e4cd33c38 100644 --- a/pxr/usd/usdUtils/validators.cpp +++ b/pxr/usd/usdUtils/validators.cpp @@ -45,6 +45,19 @@ _PackageEncapsulationValidator(const UsdStagePtr& usdStage) { if (!packagePath.empty()) { for (const SdfLayerRefPtr& referencedLayer : layers) { + if (!referencedLayer) { + errors.emplace_back( + UsdUtilsValidationErrorNameTokens->invalidLayerInPackage, + UsdValidationErrorType::Error, + UsdValidationErrorSites { + UsdValidationErrorSite( + rootLayer, SdfPath()) + }, + "Found invalid layer reference in package. This could be " + "due to a layer that failed to load or a layer that is not " + "a valid layer to be bundled in a package."); + continue; + } const std::string& realPath = referencedLayer->GetRealPath(); // We don't want to validate in-memory or session layers diff --git a/pxr/usd/usdUtils/wrapDependencies.cpp b/pxr/usd/usdUtils/wrapDependencies.cpp index 4fc906f26a0..fefed2c59f9 100644 --- a/pxr/usd/usdUtils/wrapDependencies.cpp +++ b/pxr/usd/usdUtils/wrapDependencies.cpp @@ -27,11 +27,12 @@ namespace { static bp::tuple _ExtractExternalReferences( - const std::string& filePath) + const std::string& filePath, + const UsdUtilsExtractExternalReferencesParams& params = {}) { std::vector subLayers, references, payloads; UsdUtilsExtractExternalReferences(filePath, - &subLayers, &references, &payloads); + &subLayers, &references, &payloads, params); return bp::make_tuple(subLayers, references, payloads); } @@ -65,8 +66,15 @@ _ComputeAllDependencies( void wrapDependencies() { + typedef UsdUtilsExtractExternalReferencesParams ExtractRefParams; + bp::class_("ExtractExternalReferencesParams") + .def("SetResolveUdimPaths", &ExtractRefParams::SetResolveUdimPaths) + .def("GetResolveUdimPaths", &ExtractRefParams::GetResolveUdimPaths) + ; + bp::def("ExtractExternalReferences", _ExtractExternalReferences, - bp::arg("filePath")); + (bp::arg("filePath"), + bp::arg("parameters") = ExtractRefParams())); bp::def("CreateNewUsdzPackage", UsdUtilsCreateNewUsdzPackage, (bp::arg("assetPath"), diff --git a/pxr/usd/usdVol/pch.h b/pxr/usd/usdVol/pch.h index 217de22bb65..394c8a5b413 100644 --- a/pxr/usd/usdVol/pch.h +++ b/pxr/usd/usdVol/pch.h @@ -71,6 +71,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/pxr/usdImaging/bin/testusdview/testenv/testUsdviewMetadatatabSelect/test.usda b/pxr/usdImaging/bin/testusdview/testenv/testUsdviewMetadatatabSelect/test.usda index 1bfacda5700..f5579cc4cf5 100644 --- a/pxr/usdImaging/bin/testusdview/testenv/testUsdviewMetadatatabSelect/test.usda +++ b/pxr/usdImaging/bin/testusdview/testenv/testUsdviewMetadatatabSelect/test.usda @@ -1,4 +1,7 @@ #usda 1.0 +( + upAxis = 'Z' +) def Xform "Implicits" ( add variantSets = "shapeVariant" diff --git a/pxr/usdImaging/bin/testusdview/testenv/testUsdviewMetadatatabSelect/testUsdviewMetadatatabSelect.py b/pxr/usdImaging/bin/testusdview/testenv/testUsdviewMetadatatabSelect/testUsdviewMetadatatabSelect.py index 0ec88809cc9..0d457324916 100644 --- a/pxr/usdImaging/bin/testusdview/testenv/testUsdviewMetadatatabSelect/testUsdviewMetadatatabSelect.py +++ b/pxr/usdImaging/bin/testusdview/testenv/testUsdviewMetadatatabSelect/testUsdviewMetadatatabSelect.py @@ -10,6 +10,7 @@ from pxr.Usdviewq.qt import QtWidgets class MetadataKeys(ConstantsGroup): + ROOT_METADATA_KEY = "upAxis" APPLIED_API_SCHEMAS_FIELD = "[applied API schemas]" AUTHORED_API_SCHEMAS_FIELD = 'apiSchemas' @@ -62,12 +63,31 @@ def _testBasic(appController): assert inspectorView.tabText(inspectorView.currentIndex()) == 'Composition' def _testAPISchemaMetadata(appController): + # Check root metadata is visible inspectorView = appController._ui.propertyInspector + appController.selectPseudoroot() inspectorView.setCurrentIndex(1) - appController._ui.primViewLineEdit.setText('RectLight') - appController._primViewFindNext() - appController._mainWindow.repaint() assert inspectorView.tabText(inspectorView.currentIndex()) == 'Meta Data' + appController._mainWindow.repaint() + metadataTable = inspectorView.currentWidget().findChildren( + QtWidgets.QTableWidget)[0] + + foundRootMetadata = False + for i in range(metadataTable.rowCount()): + fieldName = str(metadataTable.item(i, 0).text()) + value = str(metadataTable.item(i, 1).text()) + if fieldName == MetadataKeys.ROOT_METADATA_KEY: + foundRootMetadata = True + break + + assert foundRootMetadata + + # Check Applied API schemas are set and correct + inspectorView = appController._ui.propertyInspector + inspectorView.setCurrentIndex(1) + appController._ui.primViewLineEdit.setText('Light') + appController._primViewFindNext() + appController._updateMetadataView() metadataTable = inspectorView.currentWidget().findChildren( QtWidgets.QTableWidget)[0] @@ -84,7 +104,7 @@ def _testAPISchemaMetadata(appController): prim = appController._dataModel.selection.getFocusPrim() UsdLux.MeshLightAPI.Apply(prim) - appController._mainWindow.repaint() + appController._updateMetadataView() apiDef = reg.FindAppliedAPIPrimDefinition("MeshLightAPI") additionalAppliedSchemas = primDef.GetAppliedAPISchemas() diff --git a/pxr/usdImaging/plugin/sdrGlslfx/pch.h b/pxr/usdImaging/plugin/sdrGlslfx/pch.h index a53809377e2..be073fae4b7 100644 --- a/pxr/usdImaging/plugin/sdrGlslfx/pch.h +++ b/pxr/usdImaging/plugin/sdrGlslfx/pch.h @@ -50,6 +50,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/pxr/usdImaging/plugin/usdShaders/pch.h b/pxr/usdImaging/plugin/usdShaders/pch.h index 3b0ab0f0de5..7b302515a73 100644 --- a/pxr/usdImaging/plugin/usdShaders/pch.h +++ b/pxr/usdImaging/plugin/usdShaders/pch.h @@ -70,6 +70,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/pxr/usdImaging/usdAppUtils/pch.h b/pxr/usdImaging/usdAppUtils/pch.h index 7fab44a81d8..71dc34e16c1 100644 --- a/pxr/usdImaging/usdAppUtils/pch.h +++ b/pxr/usdImaging/usdAppUtils/pch.h @@ -88,6 +88,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/pxr/usdImaging/usdImaging/dataSourceUsdPrimInfo.cpp b/pxr/usdImaging/usdImaging/dataSourceUsdPrimInfo.cpp index f74b2186e1d..63e2351de8f 100644 --- a/pxr/usdImaging/usdImaging/dataSourceUsdPrimInfo.cpp +++ b/pxr/usdImaging/usdImaging/dataSourceUsdPrimInfo.cpp @@ -59,8 +59,11 @@ TfTokenVector UsdImagingDataSourceUsdPrimInfo::GetNames() { TfTokenVector result = { + UsdImagingUsdPrimInfoSchemaTokens->specifier, + UsdImagingUsdPrimInfoSchemaTokens->typeName, UsdImagingUsdPrimInfoSchemaTokens->isLoaded, - UsdImagingUsdPrimInfoSchemaTokens->specifier + UsdImagingUsdPrimInfoSchemaTokens->apiSchemas, + UsdImagingUsdPrimInfoSchemaTokens->kind, }; if (_usdPrim.IsInstance()) { @@ -77,13 +80,35 @@ UsdImagingDataSourceUsdPrimInfo::GetNames() HdDataSourceBaseHandle UsdImagingDataSourceUsdPrimInfo::Get(const TfToken &name) { - if (name == UsdImagingUsdPrimInfoSchemaTokens->isLoaded) { - return HdRetainedTypedSampledDataSource::New( - _usdPrim.IsLoaded()); - } + using BoolDataSource = HdRetainedTypedSampledDataSource; + using TokenDataSource = HdRetainedTypedSampledDataSource; + using TokenArrayDataSource = + HdRetainedTypedSampledDataSource>; + if (name == UsdImagingUsdPrimInfoSchemaTokens->specifier) { return _SpecifierToDataSource(_usdPrim.GetSpecifier()); } + if (name == UsdImagingUsdPrimInfoSchemaTokens->typeName) { + return TokenDataSource::New(_usdPrim.GetTypeName()); + } + if (name == UsdImagingUsdPrimInfoSchemaTokens->isLoaded) { + return BoolDataSource::New(_usdPrim.IsLoaded()); + } + if (name == UsdImagingUsdPrimInfoSchemaTokens->apiSchemas) { + const TfTokenVector appliedSchemas = _usdPrim.GetAppliedSchemas(); + if (!appliedSchemas.empty()) { + return TokenArrayDataSource::New( + VtArray(appliedSchemas.begin(), appliedSchemas.end())); + } + return nullptr; + } + if (name == UsdImagingUsdPrimInfoSchemaTokens->kind) { + TfToken kind; + if (_usdPrim.GetKind(&kind)) { + return TokenDataSource::New(kind); + } + return nullptr; + } if (name == UsdImagingUsdPrimInfoSchemaTokens->niPrototypePath) { if (!_usdPrim.IsInstance()) { return nullptr; @@ -99,7 +124,7 @@ UsdImagingDataSourceUsdPrimInfo::Get(const TfToken &name) if (!_usdPrim.IsPrototype()) { return nullptr; } - return HdRetainedTypedSampledDataSource::New(true); + return BoolDataSource::New(true); } return nullptr; } diff --git a/pxr/usdImaging/usdImaging/hdSchemaDefs.py b/pxr/usdImaging/usdImaging/hdSchemaDefs.py index df0160f3d13..c7e5417a8ac 100644 --- a/pxr/usdImaging/usdImaging/hdSchemaDefs.py +++ b/pxr/usdImaging/usdImaging/hdSchemaDefs.py @@ -17,11 +17,18 @@ SCHEMA_TOKEN = '__usdPrimInfo', ADD_DEFAULT_LOCATOR = True, MEMBERS = [ + ('specifier', T_TOKEN, {}), + ('typeName', T_TOKEN, {}), + ('isLoaded', T_BOOL, {}), + # Skipping isModel and isGroup, which can be inferred from 'kind'. + ('apiSchemas', T_TOKENARRAY, {}), + ('kind', T_TOKEN, {}), + # XXX Add variantSets. Is it a token array, or a container of token + # to token array? ('niPrototypePath', T_PATH, dict(ADD_LOCATOR=True)), ('isNiPrototype', T_BOOL, {}), - ('specifier', T_TOKEN, {}), ('piPropagatedPrototypes', T_CONTAINER, {}), - ('isLoaded', T_BOOL, {}), + ], STATIC_TOKEN_DATASOURCE_BUILDERS = [ ('specifier', ['def', 'over', '(class_, "class")']), @@ -196,4 +203,4 @@ ('namespacedSettings', T_CONTAINER, dict(ADD_LOCATOR=True)), ], ), -] +] diff --git a/pxr/usdImaging/usdImaging/pch.h b/pxr/usdImaging/usdImaging/pch.h index 51930588b87..cd106809e25 100644 --- a/pxr/usdImaging/usdImaging/pch.h +++ b/pxr/usdImaging/usdImaging/pch.h @@ -91,6 +91,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/pxr/usdImaging/usdImaging/testenv/testUsdImagingStageSceneIndexContents/baseline/basic.txt b/pxr/usdImaging/usdImaging/testenv/testUsdImagingStageSceneIndexContents/baseline/basic.txt index febc141946b..3240de58f78 100644 --- a/pxr/usdImaging/usdImaging/testenv/testUsdImagingStageSceneIndexContents/baseline/basic.txt +++ b/pxr/usdImaging/usdImaging/testenv/testUsdImagingStageSceneIndexContents/baseline/basic.txt @@ -14,6 +14,8 @@ 1 [specifier] def + [typeName] + Xform [primOrigin] [scenePath] HdPrimOriginSchema::OriginPath(/CoordSys) @@ -24,6 +26,8 @@ 1 [specifier] def + [typeName] + Xform [primOrigin] [scenePath] HdPrimOriginSchema::OriginPath(/CoordSys/modelSpace) @@ -34,6 +38,8 @@ 1 [specifier] def + [typeName] + Xform [primOrigin] [scenePath] HdPrimOriginSchema::OriginPath(/CoordSys/worldSpace) @@ -49,16 +55,22 @@ 1 [specifier] def + [typeName] + Xform [primOrigin] [scenePath] HdPrimOriginSchema::OriginPath(/Geom) [primvars] type = mesh [__usdPrimInfo] + [apiSchemas] + [MaterialBindingAPI, CoordSysAPI:worldSpace, CoordSysAPI:modelSpace] [isLoaded] 1 [specifier] def + [typeName] + Mesh [coordSysBinding] [modelSpace] /CoordSys/modelSpace @@ -137,6 +149,8 @@ 1 [specifier] def + [typeName] + Scope [primOrigin] [scenePath] HdPrimOriginSchema::OriginPath(/Materials) @@ -147,6 +161,8 @@ 1 [specifier] def + [typeName] + Material [material] [] [interfaceMappings] diff --git a/pxr/usdImaging/usdImaging/usdPrimInfoSchema.cpp b/pxr/usdImaging/usdImaging/usdPrimInfoSchema.cpp index aa75095fdc8..a575d84452d 100644 --- a/pxr/usdImaging/usdImaging/usdPrimInfoSchema.cpp +++ b/pxr/usdImaging/usdImaging/usdPrimInfoSchema.cpp @@ -32,56 +32,105 @@ TF_DEFINE_PUBLIC_TOKENS(UsdImagingUsdPrimInfoSchemaTokens, // --(BEGIN CUSTOM CODE: Schema Methods)-- // --(END CUSTOM CODE: Schema Methods)-- -HdPathDataSourceHandle -UsdImagingUsdPrimInfoSchema::GetNiPrototypePath() const +HdTokenDataSourceHandle +UsdImagingUsdPrimInfoSchema::GetSpecifier() const { - return _GetTypedDataSource( - UsdImagingUsdPrimInfoSchemaTokens->niPrototypePath); + return _GetTypedDataSource( + UsdImagingUsdPrimInfoSchemaTokens->specifier); +} + +HdTokenDataSourceHandle +UsdImagingUsdPrimInfoSchema::GetTypeName() const +{ + return _GetTypedDataSource( + UsdImagingUsdPrimInfoSchemaTokens->typeName); } HdBoolDataSourceHandle -UsdImagingUsdPrimInfoSchema::GetIsNiPrototype() const +UsdImagingUsdPrimInfoSchema::GetIsLoaded() const { return _GetTypedDataSource( - UsdImagingUsdPrimInfoSchemaTokens->isNiPrototype); + UsdImagingUsdPrimInfoSchemaTokens->isLoaded); +} + +HdTokenArrayDataSourceHandle +UsdImagingUsdPrimInfoSchema::GetApiSchemas() const +{ + return _GetTypedDataSource( + UsdImagingUsdPrimInfoSchemaTokens->apiSchemas); } HdTokenDataSourceHandle -UsdImagingUsdPrimInfoSchema::GetSpecifier() const +UsdImagingUsdPrimInfoSchema::GetKind() const { return _GetTypedDataSource( - UsdImagingUsdPrimInfoSchemaTokens->specifier); + UsdImagingUsdPrimInfoSchemaTokens->kind); } -HdContainerDataSourceHandle -UsdImagingUsdPrimInfoSchema::GetPiPropagatedPrototypes() const +HdPathDataSourceHandle +UsdImagingUsdPrimInfoSchema::GetNiPrototypePath() const { - return _GetTypedDataSource( - UsdImagingUsdPrimInfoSchemaTokens->piPropagatedPrototypes); + return _GetTypedDataSource( + UsdImagingUsdPrimInfoSchemaTokens->niPrototypePath); } HdBoolDataSourceHandle -UsdImagingUsdPrimInfoSchema::GetIsLoaded() const +UsdImagingUsdPrimInfoSchema::GetIsNiPrototype() const { return _GetTypedDataSource( - UsdImagingUsdPrimInfoSchemaTokens->isLoaded); + UsdImagingUsdPrimInfoSchemaTokens->isNiPrototype); +} + +HdContainerDataSourceHandle +UsdImagingUsdPrimInfoSchema::GetPiPropagatedPrototypes() const +{ + return _GetTypedDataSource( + UsdImagingUsdPrimInfoSchemaTokens->piPropagatedPrototypes); } /*static*/ HdContainerDataSourceHandle UsdImagingUsdPrimInfoSchema::BuildRetained( + const HdTokenDataSourceHandle &specifier, + const HdTokenDataSourceHandle &typeName, + const HdBoolDataSourceHandle &isLoaded, + const HdTokenArrayDataSourceHandle &apiSchemas, + const HdTokenDataSourceHandle &kind, const HdPathDataSourceHandle &niPrototypePath, const HdBoolDataSourceHandle &isNiPrototype, - const HdTokenDataSourceHandle &specifier, - const HdContainerDataSourceHandle &piPropagatedPrototypes, - const HdBoolDataSourceHandle &isLoaded + const HdContainerDataSourceHandle &piPropagatedPrototypes ) { - TfToken _names[5]; - HdDataSourceBaseHandle _values[5]; + TfToken _names[8]; + HdDataSourceBaseHandle _values[8]; size_t _count = 0; + if (specifier) { + _names[_count] = UsdImagingUsdPrimInfoSchemaTokens->specifier; + _values[_count++] = specifier; + } + + if (typeName) { + _names[_count] = UsdImagingUsdPrimInfoSchemaTokens->typeName; + _values[_count++] = typeName; + } + + if (isLoaded) { + _names[_count] = UsdImagingUsdPrimInfoSchemaTokens->isLoaded; + _values[_count++] = isLoaded; + } + + if (apiSchemas) { + _names[_count] = UsdImagingUsdPrimInfoSchemaTokens->apiSchemas; + _values[_count++] = apiSchemas; + } + + if (kind) { + _names[_count] = UsdImagingUsdPrimInfoSchemaTokens->kind; + _values[_count++] = kind; + } + if (niPrototypePath) { _names[_count] = UsdImagingUsdPrimInfoSchemaTokens->niPrototypePath; _values[_count++] = niPrototypePath; @@ -92,60 +141,74 @@ UsdImagingUsdPrimInfoSchema::BuildRetained( _values[_count++] = isNiPrototype; } - if (specifier) { - _names[_count] = UsdImagingUsdPrimInfoSchemaTokens->specifier; - _values[_count++] = specifier; - } - if (piPropagatedPrototypes) { _names[_count] = UsdImagingUsdPrimInfoSchemaTokens->piPropagatedPrototypes; _values[_count++] = piPropagatedPrototypes; } - - if (isLoaded) { - _names[_count] = UsdImagingUsdPrimInfoSchemaTokens->isLoaded; - _values[_count++] = isLoaded; - } return HdRetainedContainerDataSource::New(_count, _names, _values); } UsdImagingUsdPrimInfoSchema::Builder & -UsdImagingUsdPrimInfoSchema::Builder::SetNiPrototypePath( - const HdPathDataSourceHandle &niPrototypePath) +UsdImagingUsdPrimInfoSchema::Builder::SetSpecifier( + const HdTokenDataSourceHandle &specifier) { - _niPrototypePath = niPrototypePath; + _specifier = specifier; return *this; } UsdImagingUsdPrimInfoSchema::Builder & -UsdImagingUsdPrimInfoSchema::Builder::SetIsNiPrototype( - const HdBoolDataSourceHandle &isNiPrototype) +UsdImagingUsdPrimInfoSchema::Builder::SetTypeName( + const HdTokenDataSourceHandle &typeName) { - _isNiPrototype = isNiPrototype; + _typeName = typeName; return *this; } UsdImagingUsdPrimInfoSchema::Builder & -UsdImagingUsdPrimInfoSchema::Builder::SetSpecifier( - const HdTokenDataSourceHandle &specifier) +UsdImagingUsdPrimInfoSchema::Builder::SetIsLoaded( + const HdBoolDataSourceHandle &isLoaded) { - _specifier = specifier; + _isLoaded = isLoaded; return *this; } UsdImagingUsdPrimInfoSchema::Builder & -UsdImagingUsdPrimInfoSchema::Builder::SetPiPropagatedPrototypes( - const HdContainerDataSourceHandle &piPropagatedPrototypes) +UsdImagingUsdPrimInfoSchema::Builder::SetApiSchemas( + const HdTokenArrayDataSourceHandle &apiSchemas) { - _piPropagatedPrototypes = piPropagatedPrototypes; + _apiSchemas = apiSchemas; return *this; } UsdImagingUsdPrimInfoSchema::Builder & -UsdImagingUsdPrimInfoSchema::Builder::SetIsLoaded( - const HdBoolDataSourceHandle &isLoaded) +UsdImagingUsdPrimInfoSchema::Builder::SetKind( + const HdTokenDataSourceHandle &kind) { - _isLoaded = isLoaded; + _kind = kind; + return *this; +} + +UsdImagingUsdPrimInfoSchema::Builder & +UsdImagingUsdPrimInfoSchema::Builder::SetNiPrototypePath( + const HdPathDataSourceHandle &niPrototypePath) +{ + _niPrototypePath = niPrototypePath; + return *this; +} + +UsdImagingUsdPrimInfoSchema::Builder & +UsdImagingUsdPrimInfoSchema::Builder::SetIsNiPrototype( + const HdBoolDataSourceHandle &isNiPrototype) +{ + _isNiPrototype = isNiPrototype; + return *this; +} + +UsdImagingUsdPrimInfoSchema::Builder & +UsdImagingUsdPrimInfoSchema::Builder::SetPiPropagatedPrototypes( + const HdContainerDataSourceHandle &piPropagatedPrototypes) +{ + _piPropagatedPrototypes = piPropagatedPrototypes; return *this; } @@ -153,11 +216,14 @@ HdContainerDataSourceHandle UsdImagingUsdPrimInfoSchema::Builder::Build() { return UsdImagingUsdPrimInfoSchema::BuildRetained( + _specifier, + _typeName, + _isLoaded, + _apiSchemas, + _kind, _niPrototypePath, _isNiPrototype, - _specifier, - _piPropagatedPrototypes, - _isLoaded + _piPropagatedPrototypes ); } diff --git a/pxr/usdImaging/usdImaging/usdPrimInfoSchema.h b/pxr/usdImaging/usdImaging/usdPrimInfoSchema.h index 4b98f599bbb..e9afbb476b4 100644 --- a/pxr/usdImaging/usdImaging/usdPrimInfoSchema.h +++ b/pxr/usdImaging/usdImaging/usdPrimInfoSchema.h @@ -34,11 +34,14 @@ PXR_NAMESPACE_OPEN_SCOPE #define USD_IMAGING_USD_PRIM_INFO_SCHEMA_TOKENS \ (__usdPrimInfo) \ + (specifier) \ + (typeName) \ + (isLoaded) \ + (apiSchemas) \ + (kind) \ (niPrototypePath) \ (isNiPrototype) \ - (specifier) \ (piPropagatedPrototypes) \ - (isLoaded) \ (def) \ (over) \ ((class_, "class")) \ @@ -76,19 +79,28 @@ class UsdImagingUsdPrimInfoSchema : public HdSchema /// @{ USDIMAGING_API - HdPathDataSourceHandle GetNiPrototypePath() const; + HdTokenDataSourceHandle GetSpecifier() const; USDIMAGING_API - HdBoolDataSourceHandle GetIsNiPrototype() const; + HdTokenDataSourceHandle GetTypeName() const; USDIMAGING_API - HdTokenDataSourceHandle GetSpecifier() const; + HdBoolDataSourceHandle GetIsLoaded() const; USDIMAGING_API - HdContainerDataSourceHandle GetPiPropagatedPrototypes() const; + HdTokenArrayDataSourceHandle GetApiSchemas() const; USDIMAGING_API - HdBoolDataSourceHandle GetIsLoaded() const; + HdTokenDataSourceHandle GetKind() const; + + USDIMAGING_API + HdPathDataSourceHandle GetNiPrototypePath() const; + + USDIMAGING_API + HdBoolDataSourceHandle GetIsNiPrototype() const; + + USDIMAGING_API + HdContainerDataSourceHandle GetPiPropagatedPrototypes() const; /// @} @@ -134,11 +146,14 @@ class UsdImagingUsdPrimInfoSchema : public HdSchema USDIMAGING_API static HdContainerDataSourceHandle BuildRetained( + const HdTokenDataSourceHandle &specifier, + const HdTokenDataSourceHandle &typeName, + const HdBoolDataSourceHandle &isLoaded, + const HdTokenArrayDataSourceHandle &apiSchemas, + const HdTokenDataSourceHandle &kind, const HdPathDataSourceHandle &niPrototypePath, const HdBoolDataSourceHandle &isNiPrototype, - const HdTokenDataSourceHandle &specifier, - const HdContainerDataSourceHandle &piPropagatedPrototypes, - const HdBoolDataSourceHandle &isLoaded + const HdContainerDataSourceHandle &piPropagatedPrototypes ); /// \class UsdImagingUsdPrimInfoSchema::Builder @@ -151,31 +166,43 @@ class UsdImagingUsdPrimInfoSchema : public HdSchema { public: USDIMAGING_API + Builder &SetSpecifier( + const HdTokenDataSourceHandle &specifier); + USDIMAGING_API + Builder &SetTypeName( + const HdTokenDataSourceHandle &typeName); + USDIMAGING_API + Builder &SetIsLoaded( + const HdBoolDataSourceHandle &isLoaded); + USDIMAGING_API + Builder &SetApiSchemas( + const HdTokenArrayDataSourceHandle &apiSchemas); + USDIMAGING_API + Builder &SetKind( + const HdTokenDataSourceHandle &kind); + USDIMAGING_API Builder &SetNiPrototypePath( const HdPathDataSourceHandle &niPrototypePath); USDIMAGING_API Builder &SetIsNiPrototype( const HdBoolDataSourceHandle &isNiPrototype); USDIMAGING_API - Builder &SetSpecifier( - const HdTokenDataSourceHandle &specifier); - USDIMAGING_API Builder &SetPiPropagatedPrototypes( const HdContainerDataSourceHandle &piPropagatedPrototypes); - USDIMAGING_API - Builder &SetIsLoaded( - const HdBoolDataSourceHandle &isLoaded); /// Returns a container data source containing the members set thus far. USDIMAGING_API HdContainerDataSourceHandle Build(); private: + HdTokenDataSourceHandle _specifier; + HdTokenDataSourceHandle _typeName; + HdBoolDataSourceHandle _isLoaded; + HdTokenArrayDataSourceHandle _apiSchemas; + HdTokenDataSourceHandle _kind; HdPathDataSourceHandle _niPrototypePath; HdBoolDataSourceHandle _isNiPrototype; - HdTokenDataSourceHandle _specifier; HdContainerDataSourceHandle _piPropagatedPrototypes; - HdBoolDataSourceHandle _isLoaded; }; diff --git a/pxr/usdImaging/usdImagingGL/engine.cpp b/pxr/usdImaging/usdImagingGL/engine.cpp index 12b4bc66108..bc822e8d1be 100644 --- a/pxr/usdImaging/usdImagingGL/engine.cpp +++ b/pxr/usdImaging/usdImagingGL/engine.cpp @@ -867,15 +867,28 @@ UsdImagingGLEngine::DecodeIntersection( SdfPath *outHitInstancerPath, int *outHitInstanceIndex, HdInstancerContext *outInstancerContext) +{ + const int primIdx = HdxPickTask::DecodeIDRenderColor(primIdColor); + const int instanceIdx = HdxPickTask::DecodeIDRenderColor(instanceIdColor); + + return DecodeIntersection(primIdx, instanceIdx, outHitPrimPath, + outHitInstancerPath, outHitInstanceIndex, outInstancerContext); +} + +bool +UsdImagingGLEngine::DecodeIntersection( + int primIdx, + int instanceIdx, + SdfPath *outHitPrimPath, + SdfPath *outHitInstancerPath, + int *outHitInstanceIndex, + HdInstancerContext *outInstancerContext) { if (ARCH_UNLIKELY(!_renderDelegate)) { return false; } - const int primId = HdxPickTask::DecodeIDRenderColor(primIdColor); - const int instanceIdx = HdxPickTask::DecodeIDRenderColor(instanceIdColor); - - SdfPath primPath = _renderIndex->GetRprimPathFromPrimId(primId); + SdfPath primPath = _renderIndex->GetRprimPathFromPrimId(primIdx); if (primPath.IsEmpty()) { return false; } @@ -1267,6 +1280,7 @@ UsdImagingGLEngine::GetRendererAovs() const { HdAovTokens->primId, HdAovTokens->depth, HdAovTokens->normal, + HdAovTokens->Neye, HdAovTokensMakePrimvar(TfToken("st")) }; TfTokenVector aovs = { HdAovTokens->color }; @@ -1295,6 +1309,20 @@ UsdImagingGLEngine::SetRendererAov(TfToken const &id) return false; } +bool +UsdImagingGLEngine::SetRendererAovs(TfTokenVector const &ids) +{ + if (ARCH_UNLIKELY(!_renderDelegate)) { + return false; + } + + if (_renderIndex->IsBprimTypeSupported(HdPrimTypeTokens->renderBuffer)) { + _taskController->SetRenderOutputs(ids); + return true; + } + return false; +} + HgiTextureHandle UsdImagingGLEngine::GetAovTexture( TfToken const& name) const diff --git a/pxr/usdImaging/usdImagingGL/engine.h b/pxr/usdImaging/usdImagingGL/engine.h index e90410f3cd8..1a7ff92e3dc 100644 --- a/pxr/usdImaging/usdImagingGL/engine.h +++ b/pxr/usdImaging/usdImagingGL/engine.h @@ -379,7 +379,7 @@ class UsdImagingGLEngine IntersectionResultVector* outResults); /// Decodes a pick result given hydra prim ID/instance ID (like you'd get - /// from an ID render). + /// from an ID render), where ID is represented as a vec4 color. USDIMAGINGGL_API bool DecodeIntersection( unsigned char const primIdColor[4], @@ -389,6 +389,17 @@ class UsdImagingGLEngine int *outHitInstanceIndex = NULL, HdInstancerContext *outInstancerContext = NULL); + /// Decodes a pick result given hydra prim ID/instance ID (like you'd get + /// from an ID render), where ID is represented as a int. + USDIMAGINGGL_API + bool DecodeIntersection( + int primIdx, + int instanceIdx, + SdfPath *outHitPrimPath = NULL, + SdfPath *outHitInstancerPath = NULL, + int *outHitInstanceIndex = NULL, + HdInstancerContext *outInstancerContext = NULL); + /// @} // --------------------------------------------------------------------- @@ -432,6 +443,10 @@ class UsdImagingGLEngine USDIMAGINGGL_API bool SetRendererAov(TfToken const& id); + /// Set the current renderer AOVs to a list of \p ids. + USDIMAGINGGL_API + bool SetRendererAovs(TfTokenVector const &ids); + /// Returns an AOV texture handle for the given token. USDIMAGINGGL_API HgiTextureHandle GetAovTexture(TfToken const& name) const; diff --git a/pxr/usdImaging/usdImagingGL/pch.h b/pxr/usdImaging/usdImagingGL/pch.h index 91cbdfc51ae..8a04b4f3603 100644 --- a/pxr/usdImaging/usdImagingGL/pch.h +++ b/pxr/usdImaging/usdImagingGL/pch.h @@ -78,6 +78,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/pxr/usdImaging/usdImagingGL/testenv/testUsdImagingGLAovVisualization/baseline/testUsdImagingGLAovVisualization_Storm_Neye.png b/pxr/usdImaging/usdImagingGL/testenv/testUsdImagingGLAovVisualization/baseline/testUsdImagingGLAovVisualization_Storm_Neye.png new file mode 100644 index 00000000000..9ce3d5b9872 Binary files /dev/null and b/pxr/usdImaging/usdImagingGL/testenv/testUsdImagingGLAovVisualization/baseline/testUsdImagingGLAovVisualization_Storm_Neye.png differ diff --git a/pxr/usdImaging/usdImagingGL/testenv/testUsdImagingGLAovVisualization/baseline/testUsdImagingGLAovVisualization_Storm_primId.png b/pxr/usdImaging/usdImagingGL/testenv/testUsdImagingGLAovVisualization/baseline/testUsdImagingGLAovVisualization_Storm_primId.png new file mode 100644 index 00000000000..67140e74503 Binary files /dev/null and b/pxr/usdImaging/usdImagingGL/testenv/testUsdImagingGLAovVisualization/baseline/testUsdImagingGLAovVisualization_Storm_primId.png differ diff --git a/pxr/usdImaging/usdImagingGL/testenv/testUsdImagingGLBasicDrawing.cpp b/pxr/usdImaging/usdImagingGL/testenv/testUsdImagingGLBasicDrawing.cpp index 8fb7b634fa2..753fbf33df7 100644 --- a/pxr/usdImaging/usdImagingGL/testenv/testUsdImagingGLBasicDrawing.cpp +++ b/pxr/usdImaging/usdImagingGL/testenv/testUsdImagingGLBasicDrawing.cpp @@ -239,7 +239,6 @@ My_TestGLDrawing::DrawTest(bool offscreen) UsdImagingGLRenderParams params; params.drawMode = GetDrawMode(); params.enableLighting = IsEnabledTestLighting(); - params.enableIdRender = IsEnabledIdRender(); params.enableSceneMaterials = IsEnabledSceneMaterials(); params.complexity = _GetComplexity(); params.cullStyle = GetCullStyle(); @@ -293,7 +292,9 @@ My_TestGLDrawing::DrawTest(bool offscreen) renderTime.Stop(); } - TF_VERIFY(mark.IsClean(), "Errors occurred while rendering!"); + // Note that we do not confirm that mark.IsClear() here, since + // in some tests we do expect to encounter broken materials + // that will fail to compile, ex: testUsdImagingGLInvalidMaterial std::cout << "Iterations to convergence: " << convergenceIterations << std::endl; std::cout << "itemsDrawn " << perfLog.GetCounter(HdTokens->itemsDrawn) << std::endl; diff --git a/pxr/usdImaging/usdImagingGL/testenv/testUsdImagingGLBasicDrawing/baseline/testUsdImagingGLBasicDrawing_id.png b/pxr/usdImaging/usdImagingGL/testenv/testUsdImagingGLBasicDrawing/baseline/testUsdImagingGLBasicDrawing_id.png index 8f97c69eadb..7d76a330e26 100644 Binary files a/pxr/usdImaging/usdImagingGL/testenv/testUsdImagingGLBasicDrawing/baseline/testUsdImagingGLBasicDrawing_id.png and b/pxr/usdImaging/usdImagingGL/testenv/testUsdImagingGLBasicDrawing/baseline/testUsdImagingGLBasicDrawing_id.png differ diff --git a/pxr/usdImaging/usdImagingGL/testenv/testUsdImagingGLHighlight.cpp b/pxr/usdImaging/usdImagingGL/testenv/testUsdImagingGLHighlight.cpp index 3b642b3766c..8e1d1fe0bb4 100644 --- a/pxr/usdImaging/usdImagingGL/testenv/testUsdImagingGLHighlight.cpp +++ b/pxr/usdImaging/usdImagingGL/testenv/testUsdImagingGLHighlight.cpp @@ -338,7 +338,6 @@ My_TestGLDrawing::Pick(GfVec2i const &startPos, GfVec2i const &endPos) frustum.SetWindow(GfRange2d(min, max)); UsdImagingGLRenderParams params; - params.enableIdRender = true; GfVec3d outHitPoint; GfVec3d outHitNormal; diff --git a/pxr/usdImaging/usdImagingGL/testenv/testUsdImagingGLPickAndHighlight.cpp b/pxr/usdImaging/usdImagingGL/testenv/testUsdImagingGLPickAndHighlight.cpp index 46f86a494a8..19b1138cd24 100644 --- a/pxr/usdImaging/usdImagingGL/testenv/testUsdImagingGLPickAndHighlight.cpp +++ b/pxr/usdImaging/usdImagingGL/testenv/testUsdImagingGLPickAndHighlight.cpp @@ -454,7 +454,6 @@ My_TestGLDrawing::DeepSelect(GfVec2i const& startPos, GfVec2i const& endPos, // XXX: For a timevarying test need to set timecode for frame param UsdImagingGLRenderParams params; - params.enableIdRender = true; SdfPathVector selection; @@ -505,7 +504,6 @@ My_TestGLDrawing::Pick(GfVec2i const &startPos, GfVec2i const &endPos, // XXX: For a timevarying test need to set timecode for frame param UsdImagingGLRenderParams params; - params.enableIdRender = true; UsdImagingGLEngine::IntersectionResultVector outResults; diff --git a/pxr/usdImaging/usdProcImaging/pch.h b/pxr/usdImaging/usdProcImaging/pch.h index 879863bf3cd..fb9999de96f 100644 --- a/pxr/usdImaging/usdProcImaging/pch.h +++ b/pxr/usdImaging/usdProcImaging/pch.h @@ -74,6 +74,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/pxr/usdImaging/usdRiPxrImaging/pch.h b/pxr/usdImaging/usdRiPxrImaging/pch.h index 879863bf3cd..fb9999de96f 100644 --- a/pxr/usdImaging/usdRiPxrImaging/pch.h +++ b/pxr/usdImaging/usdRiPxrImaging/pch.h @@ -74,6 +74,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/pxr/usdImaging/usdSkelImaging/pch.h b/pxr/usdImaging/usdSkelImaging/pch.h index ec4b6c11315..9cfed39912e 100644 --- a/pxr/usdImaging/usdSkelImaging/pch.h +++ b/pxr/usdImaging/usdSkelImaging/pch.h @@ -74,6 +74,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/pxr/usdImaging/usdVolImaging/pch.h b/pxr/usdImaging/usdVolImaging/pch.h index 879863bf3cd..fb9999de96f 100644 --- a/pxr/usdImaging/usdVolImaging/pch.h +++ b/pxr/usdImaging/usdVolImaging/pch.h @@ -74,6 +74,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/pxr/usdImaging/usdviewq/appController.py b/pxr/usdImaging/usdviewq/appController.py index 30b9d8658f0..e09297b8c7f 100644 --- a/pxr/usdImaging/usdviewq/appController.py +++ b/pxr/usdImaging/usdviewq/appController.py @@ -897,9 +897,6 @@ def __init__(self, parserData, resolverContextFn): self._ui.actionDisplay_Camera_Oracles.triggered.connect( self._toggleDisplayCameraOracles) - self._ui.actionDisplay_PrimId.triggered.connect( - self._toggleDisplayPrimId) - self._ui.actionEnable_Scene_Materials.triggered.connect( self._toggleEnableSceneMaterials) @@ -2648,10 +2645,6 @@ def _toggleDisplayCameraOracles(self): self._dataModel.viewSettings.displayCameraOracles = ( self._ui.actionDisplay_Camera_Oracles.isChecked()) - def _toggleDisplayPrimId(self): - self._dataModel.viewSettings.displayPrimId = ( - self._ui.actionDisplay_PrimId.isChecked()) - def _toggleEnableSceneMaterials(self): self._dataModel.viewSettings.enableSceneMaterials = ( self._ui.actionEnable_Scene_Materials.isChecked()) @@ -4236,21 +4229,12 @@ def _updateMetadataView(self, obj=None): "references", "specializes", "payload", "subLayers"] - for k in compKeys: v = obj.GetMetadata(k) if not v is None: m[k] = v - clipMetadata = obj.GetMetadata("clips") - if clipMetadata is None: - clipMetadata = {} - numClipRows = 0 - for (clip, data) in clipMetadata.items(): - numClipRows += len(data) - m["clips"] = clipMetadata - - numMetadataRows = (len(m) - 1) + numClipRows + m["clips"] = obj.GetMetadata("clips") or {} # Variant selections that don't have a defined variant set will be # displayed as well to aid debugging. Collect them separately from @@ -4285,9 +4269,6 @@ def _updateMetadataView(self, obj=None): # Remove found variant set from setless. setlessVariantSelections.pop(variantSetName, None) - tableWidget.setRowCount(numMetadataRows + len(variantSets) + - len(setlessVariantSelections) + 2) - rowIndex = 0 # Although most metadata should be presented alphabetically,the most @@ -4295,6 +4276,7 @@ def _updateMetadataView(self, obj=None): # list, these consist of [object type], [path], variant sets, active, # assetInfo, and kind. def populateMetadataTable(key, val, rowIndex): + tableWidget.insertRow(rowIndex) attrName = QtWidgets.QTableWidgetItem(str(key)) tableWidget.setItem(rowIndex, 0, attrName) @@ -4304,6 +4286,12 @@ def populateMetadataTable(key, val, rowIndex): tableWidget.setItem(rowIndex, 1, attrVal) + def populateMetadataTableVariant(key, val, rowIndex): + tableWidget.insertRow(rowIndex) + attrName = QtWidgets.QTableWidgetItem(str(key + ' variant')) + tableWidget.setItem(rowIndex, 0, attrName) + tableWidget.setCellWidget(rowIndex, 1, val) + sortedKeys = sorted(m.keys()) reorderedKeys = ["kind", "assetInfo", "active"] @@ -4330,9 +4318,7 @@ def populateMetadataTable(key, val, rowIndex): rowIndex += 1 for variantSetName, combo in variantSets.items(): - attrName = QtWidgets.QTableWidgetItem(str(variantSetName+ ' variant')) - tableWidget.setItem(rowIndex, 0, attrName) - tableWidget.setCellWidget(rowIndex, 1, combo) + populateMetadataTableVariant(variantSetName, combo, rowIndex) combo.currentIndexChanged.connect( lambda i, combo=combo: combo.updateVariantSelection(i, self._makeTimer)) @@ -4341,15 +4327,12 @@ def populateMetadataTable(key, val, rowIndex): # Add all the setless variant selections directly after the variant # combo boxes for variantSetName, variantSelection in setlessVariantSelections.items(): - attrName = QtWidgets.QTableWidgetItem(str(variantSetName+ ' variant')) - tableWidget.setItem(rowIndex, 0, attrName) - valStr, ttStr = self._formatMetadataValueView(variantSelection) # Italicized label to stand out when debugging a scene. label = QtWidgets.QLabel('' + valStr + '') label.setIndent(3) label.setToolTip(ttStr) - tableWidget.setCellWidget(rowIndex, 1, label) + populateMetadataTableVariant(variantSetName, label, rowIndex) rowIndex += 1 @@ -4357,8 +4340,11 @@ def populateMetadataTable(key, val, rowIndex): if key == "clips": for (clip, metadataGroup) in m[key].items(): attrName = QtWidgets.QTableWidgetItem(str('clips:' + clip)) - tableWidget.setItem(rowIndex, 0, attrName) - for metadata in metadataGroup.keys(): + for i, metadata in enumerate(metadataGroup.keys()): + tableWidget.insertRow(rowIndex) + if i == 0: + tableWidget.setItem(rowIndex, 0, attrName) + dataPair = (metadata, metadataGroup[metadata]) valStr, ttStr = self._formatMetadataValueView(dataPair) attrVal = QtWidgets.QTableWidgetItem(valStr) @@ -5377,8 +5363,6 @@ def _refreshViewMenu(self): self._dataModel.viewSettings.enableSceneMaterials) self._ui.actionEnable_Scene_Lights.setChecked( self._dataModel.viewSettings.enableSceneLights) - self._ui.actionDisplay_PrimId.setChecked( - self._dataModel.viewSettings.displayPrimId) self._ui.actionCull_Backfaces.setChecked( self._dataModel.viewSettings.cullBackfaces) self._ui.actionDomeLightTexturesVisible.setChecked( diff --git a/pxr/usdImaging/usdviewq/mainWindowUI.ui b/pxr/usdImaging/usdviewq/mainWindowUI.ui index 94c7a01586d..69de7637cfb 100644 --- a/pxr/usdImaging/usdviewq/mainWindowUI.ui +++ b/pxr/usdImaging/usdviewq/mainWindowUI.ui @@ -2414,14 +2414,6 @@ Render - - - true - - - Display Prim Id - - true diff --git a/pxr/usdImaging/usdviewq/pch.h b/pxr/usdImaging/usdviewq/pch.h index 4aceb8b756c..c71797a837f 100644 --- a/pxr/usdImaging/usdviewq/pch.h +++ b/pxr/usdImaging/usdviewq/pch.h @@ -72,6 +72,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/pxr/usdImaging/usdviewq/stageView.py b/pxr/usdImaging/usdviewq/stageView.py index 782760b15ea..dc620a08804 100644 --- a/pxr/usdImaging/usdviewq/stageView.py +++ b/pxr/usdImaging/usdviewq/stageView.py @@ -1452,8 +1452,8 @@ def renderSinglePass(self, renderMode, renderSelHighlights): if self._dataModel.viewSettings.cullBackfaces else UsdImagingGL.CullStyle.CULL_STYLE_NOTHING) self._renderParams.gammaCorrectColors = False - self._renderParams.enableIdRender = self._dataModel.viewSettings.displayPrimId - self._renderParams.enableSampleAlphaToCoverage = not self._dataModel.viewSettings.displayPrimId + self._renderParams.enableIdRender = False + self._renderParams.enableSamlpeAlphaToCoverage = True self._renderParams.highlight = renderSelHighlights self._renderParams.enableSceneMaterials = self._dataModel.viewSettings.enableSceneMaterials self._renderParams.domeLightCameraVisibility = self._dataModel.viewSettings.domeLightTexturesVisible diff --git a/pxr/usdImaging/usdviewq/viewSettingsDataModel.py b/pxr/usdImaging/usdviewq/viewSettingsDataModel.py index f0493e4e8a0..319dd33c2c8 100644 --- a/pxr/usdImaging/usdviewq/viewSettingsDataModel.py +++ b/pxr/usdImaging/usdviewq/viewSettingsDataModel.py @@ -165,7 +165,6 @@ def __init__(self, rootDataModel, parent): self._displayGuide = self.stateProperty("displayGuide", default=False) self._displayProxy = self.stateProperty("displayProxy", default=True) self._displayRender = self.stateProperty("displayRender", default=False) - self._displayPrimId = self.stateProperty("displayPrimId", default=False) self._enableSceneMaterials = self.stateProperty("enableSceneMaterials", default=True) self._enableSceneLights = self.stateProperty("enableSceneLights", default=True) self._cullBackfaces = self.stateProperty("cullBackfaces", default=False) @@ -238,7 +237,6 @@ def onSaveState(self, state): state["displayGuide"] = self._displayGuide state["displayProxy"] = self._displayProxy state["displayRender"] = self._displayRender - state["displayPrimId"] = self._displayPrimId state["enableSceneMaterials"] = self._enableSceneMaterials state["enableSceneLights"] = self._enableSceneLights state["cullBackfaces"] = self._cullBackfaces @@ -552,15 +550,6 @@ def displayCameraOracles(self): def displayCameraOracles(self, value): self._displayCameraOracles = value - @property - def displayPrimId(self): - return self._displayPrimId - - @displayPrimId.setter - @visibleViewSetting - def displayPrimId(self, value): - self._displayPrimId = value - @property def enableSceneMaterials(self): return self._enableSceneMaterials diff --git a/third_party/renderman-26/plugin/hdPrman/CMakeLists.txt b/third_party/renderman-26/plugin/hdPrman/CMakeLists.txt index bb041899192..9bb2dc8c9d1 100644 --- a/third_party/renderman-26/plugin/hdPrman/CMakeLists.txt +++ b/third_party/renderman-26/plugin/hdPrman/CMakeLists.txt @@ -1,4 +1,4 @@ -# To be sure our VtVisitValue polyfill works correctly, the preprocessor must +# To be sure our VtVisitValue polyfill works correctly, the preprocessor must # resolve the #include in our identically-named # polyfill to the real one in libpxr. But CMAKE_INCLUDE_CURRENT_DIR injects the # cpp source directory as the first include search path. The preprocessor @@ -155,7 +155,6 @@ pxr_plugin(${PXR_PACKAGE} matfiltSceneIndexPlugins motionBlurSceneIndexPlugin pinnedCurveExpandingSceneIndexPlugin - projectionParams renderBuffer renderParam renderPass diff --git a/third_party/renderman-26/plugin/hdPrman/gprim.h b/third_party/renderman-26/plugin/hdPrman/gprim.h index aa74251f844..3dc0c4e436f 100644 --- a/third_party/renderman-26/plugin/hdPrman/gprim.h +++ b/third_party/renderman-26/plugin/hdPrman/gprim.h @@ -473,19 +473,34 @@ HdPrman_Gprim::Sync(HdSceneDelegate* sceneDelegate, "size mismatch (%lu, %lu, %lu)\n", _prototypeIds.size(), subsetMaterialIds.size(), subsetPaths.size()); - // next, tell the hdprman instancer to sync the riley instances - HdPrmanInstancer *instancer = static_cast( - renderIndex.GetInstancer(instancerId)); - if (instancer) { - instancer->Populate( - renderParam, - dirtyBits, - id, - _prototypeIds, - coordSysList, - attrs, xf, - subsetMaterialIds, - subsetPaths); + // XXX: To avoid a failed verify inside Populate(), we will check the + // prototype ids for validity here. We don't usually do this, relying on + // Riley to report invalid prototype ids on instance creation. But + // Populate() allows and expects an invalid prototype id when instancing + // lights, so doing this check here lets us make a more informative + // warning. HYD-3206 + if (std::any_of(_prototypeIds.begin(), _prototypeIds.end(), + [](const auto& id){ + return id == riley::GeometryPrototypeId::InvalidId(); + })) { + TF_WARN("Riley geometry prototype creation failed for " + "instanced gprim <%s>; the prim will not be instanced.", + id.GetText()); + } else { + // next, tell the hdprman instancer to sync the riley instances + HdPrmanInstancer *instancer = static_cast( + renderIndex.GetInstancer(instancerId)); + if (instancer) { + instancer->Populate( + renderParam, + dirtyBits, + id, + _prototypeIds, + coordSysList, + attrs, xf, + subsetMaterialIds, + subsetPaths); + } } } *dirtyBits &= ~HdChangeTracker::AllSceneDirtyBits; diff --git a/third_party/renderman-26/plugin/hdPrman/matfiltConvertPreviewMaterial.cpp b/third_party/renderman-26/plugin/hdPrman/matfiltConvertPreviewMaterial.cpp index 9e1e1dcc412..8bc55e74d4b 100644 --- a/third_party/renderman-26/plugin/hdPrman/matfiltConvertPreviewMaterial.cpp +++ b/third_party/renderman-26/plugin/hdPrman/matfiltConvertPreviewMaterial.cpp @@ -66,13 +66,13 @@ TF_DEFINE_PRIVATE_TOKENS( (dispScalarOut) (glassIor) (glassIorOut) + (glassRoughness) + (glassRoughnessOut) (glowGain) (glowGainOut) (glowColor) (glowColorOut) (normalIn) - (refractionGain) - (refractionGainOut) (specularEdgeColor) (specularEdgeColorOut) (specularFaceColor) @@ -225,6 +225,7 @@ _ProcessPreviewSurfaceNode( {_tokens->diffuseColor, _tokens->diffuseColorOut}, {_tokens->diffuseGain, _tokens->diffuseGainOut}, {_tokens->glassIor, _tokens->glassIorOut}, + {_tokens->glassRoughness, _tokens->glassRoughnessOut}, {_tokens->glowColor, _tokens->glowColorOut}, {_tokens->glowGain, _tokens->glowGainOut}, {_tokens->specularFaceColor, _tokens->specularFaceColorOut}, @@ -242,19 +243,6 @@ _ProcessPreviewSurfaceNode( pxrSurfaceNodeName, inOutPair.first, {{nodeName, inOutPair.second}}); } - - // If opacityThreshold is > 0, do *not* use refraction. - VtValue vtOpThres; - if (_GetParameter( - netInterface, nodeName, _tokens->opacityThreshold, - &vtOpThres)) { - - if (vtOpThres.Get() <= 0.0f) { - netInterface->SetNodeInputConnection( - pxrSurfaceNodeName, _tokens->refractionGain, - {{nodeName, _tokens->refractionGainOut}}); - } - } } // Check for non-zero displacement param or connection diff --git a/third_party/renderman-26/plugin/hdPrman/portalLightResolvingSceneIndexPlugin.cpp b/third_party/renderman-26/plugin/hdPrman/portalLightResolvingSceneIndexPlugin.cpp index 74c13dfdb09..609348cad7e 100644 --- a/third_party/renderman-26/plugin/hdPrman/portalLightResolvingSceneIndexPlugin.cpp +++ b/third_party/renderman-26/plugin/hdPrman/portalLightResolvingSceneIndexPlugin.cpp @@ -52,6 +52,7 @@ TF_DEFINE_PRIVATE_TOKENS( (exposure) (intensity) ((intensityMult, "ri:light:intensityMult")) + ((exposureAdjust, "ri:light:exposureAdjust")) ((portalName, "ri:light:portalName")) ((portalToDome, "ri:light:portalToDome")) ((tint, "ri:light:tint")) @@ -313,9 +314,11 @@ _BuildPortalLightDataSource( const VtValue portalTintVal = getPortalMatVal(_tokens->tint); const VtValue portalIntMultVal = getPortalMatVal(_tokens->intensityMult); + const VtValue portalExpAdjtVal = getPortalMatVal(_tokens->exposureAdjust); const auto portalTint = portalTintVal.GetWithDefault(GfVec3f(1.0f)); const auto portalIntMult = portalIntMultVal.GetWithDefault(1.0f); + const auto portalExpAdj = portalExpAdjtVal.GetWithDefault(0.0f); GfMatrix4d portalXform; if (const auto origPortalXform = portalXformSchema.GetMatrix()) { @@ -346,7 +349,7 @@ _BuildPortalLightDataSource( const auto computedPortalColor = GfCompMult(portalTint, domeColor); const auto computedPortalIntensity = portalIntMult * domeIntensity * - powf(2.0f, domeExposure); + powf(2.0f, domeExposure+portalExpAdj); const auto computedPortalToDome = portalXform * domeXform.GetInverse(); const auto computedPortalName = _GetPortalName(domeColorMap, domeXform, portalXform); diff --git a/third_party/renderman-26/plugin/hdPrman/projectionParams.cpp b/third_party/renderman-26/plugin/hdPrman/projectionParams.cpp deleted file mode 100644 index 96c8e2940cf..00000000000 --- a/third_party/renderman-26/plugin/hdPrman/projectionParams.cpp +++ /dev/null @@ -1,128 +0,0 @@ -// -// Copyright 2019 Pixar -// -// Licensed under the terms set forth in the LICENSE.txt file available at -// https://openusd.org/license. -// -#include "hdPrman/projectionParams.h" -#include - -PXR_NAMESPACE_OPEN_SCOPE - -namespace HdPrman_ProjectionParams { - - void GetIntegratorParamRole(const TfToken& paramName, TfToken& role) -{ - static std::map _integratorParamMap = { - {TfToken("ri:integrator:PxrUnified:photonVisibilityRodMin"), TfToken("point")}, - {TfToken("ri:integrator:PxrUnified:photonVisibilityRodMax"), TfToken("point")}, - - {TfToken("ri:integrator:PxrVCM:photonGuidingBBoxMin"), TfToken("point")}, - {TfToken("ri:integrator:PxrVCM:photonGuidingBBoxMax"), TfToken("point")}, - - {TfToken("ri:integrator:PxrVisualizer:wireframeColor"), TfToken("color")} - }; - - const auto it = _integratorParamMap.find(paramName); - if (it != _integratorParamMap.end()) - { - role = it->second; - } -} - -void GetProjectionParamRole(TfToken& paramName, TfToken& role) -{ - static std::map _ProjectionParamMap = { - //// PxrPerspective - {TfToken("ri:projection:PxrPerspective:fovEnd"), TfToken("float")}, - - //// PxrCamera - {TfToken("ri:projection:PxrCamera:fovEnd"), TfToken("float")}, - // Tilt shift - {TfToken("ri:projection:PxrCamera:tilt"), TfToken("float")}, - {TfToken("ri:projection:PxrCamera:roll"), TfToken("float")}, - {TfToken("ri:projection:PxrCamera:focus1"), TfToken("point")}, - {TfToken("ri:projection:PxrCamera:focus2"), TfToken("point")}, - {TfToken("ri:projection:PxrCamera:focus3"), TfToken("point")}, - {TfToken("ri:projection:PxrCamera:shiftX"), TfToken("float")}, - {TfToken("ri:projection:PxrCamera:shiftY"), TfToken("float")}, - // Lens Distortion - {TfToken("ri:projection:PxrCamera:radial1"), TfToken("float")}, - {TfToken("ri:projection:PxrCamera:radial2"), TfToken("float")}, - {TfToken("ri:projection:PxrCamera:assymX"), TfToken("float")}, - {TfToken("ri:projection:PxrCamera:assymY"), TfToken("float")}, - {TfToken("ri:projection:PxrCamera:squeeze"), TfToken("float")}, - // Chromatic Aberration - {TfToken("ri:projection:PxrCamera:axial"), TfToken("color")}, - {TfToken("ri:projection:PxrCamera:transverse"), TfToken("color")}, - // Vignetting - {TfToken("ri:projection:PxrCamera:natural"), TfToken("float")}, - {TfToken("ri:projection:PxrCamera:optical"), TfToken("float")}, - // Shutter - {TfToken("ri:projection:PxrCamera:sweep"), TfToken("string")}, - {TfToken("ri:projection:PxrCamera:duration"), TfToken("float")}, - // Advanced - {TfToken("ri:projection:PxrCamera:detail"), TfToken("float")}, - {TfToken("ri:projection:PxrCamera:enhance"), TfToken("vector")}, - {TfToken("ri:projection:PxrCamera:matte"), TfToken("string")}, - - //// PxrCylinderCamera - {TfToken("ri:projection:PxrCylinderCamera:hsweep"), TfToken("float")}, - {TfToken("ri:projection:PxrCylinderCamera:vsweep"), TfToken("float")}, - - //// PxrSphereCamera - {TfToken("ri:projection:PxrSphereCamera:hsweep"), TfToken("float")}, - {TfToken("ri:projection:PxrSphereCamera:vsweep"), TfToken("float")}, - - //// OmnidirectionalStereo - {TfToken("ri:projection:OmnidirectionalStereo:interpupilaryDistance"), TfToken("float")} - }; - - const auto it = _ProjectionParamMap.find(paramName); - if (it != _ProjectionParamMap.end()) - { - role = it->second; - } -} - -void GetFilterParamRole(TfToken& paramName, TfToken& role) -{ - // color params won't work unless set in the param list as color - // rather than float3 - static const std::map _filterParamMap = { - {TfToken("PxrBackgroundSampleFilter:backgroundColor"), TfToken("color")}, - {TfToken("PxrGradeSampleFilter:blackPoint"), TfToken("color")}, - {TfToken("PxrGradeSampleFilter:whitePoint"), TfToken("color")}, - {TfToken("PxrGradeSampleFilter:lift"), TfToken("color")}, - {TfToken("PxrGradeSampleFilter:gain"), TfToken("color")}, - {TfToken("PxrGradeSampleFilter:multiply"), TfToken("color")}, - {TfToken("PxrGradeSampleFilter:gamma"), TfToken("color")}, - {TfToken("PxrGradeSampleFilter:offset"), TfToken("color")}, - {TfToken("PxrGradeSampleFilter:mask"), TfToken("color")}, - {TfToken("PxrBackgroundDisplayFilter:backgroundColor"), TfToken("color")}, - {TfToken("PxrImagePlaneFilter:colorGain"), TfToken("color")}, - {TfToken("PxrImagePlaneFilter:colorOffset"), TfToken("color")}, - {TfToken("PxrWhitePointSampleFilter:manualWhitePoint"), TfToken("color")}, - {TfToken("PxrGradeDisplayFilter:blackPoint"), TfToken("color")}, - {TfToken("PxrGradeDisplayFilter:whitePoint"), TfToken("color")}, - {TfToken("PxrGradeDisplayFilter:lift"), TfToken("color")}, - {TfToken("PxrGradeDisplayFilter:gain"), TfToken("color")}, - {TfToken("PxrGradeDisplayFilter:multiply"), TfToken("color")}, - {TfToken("PxrGradeDisplayFilter:gamma"), TfToken("color")}, - {TfToken("PxrGradeDisplayFilter:offset"), TfToken("color")}, - {TfToken("PxrGradeDisplayFilter:mask"), TfToken("color")}, - {TfToken("PxrImageDisplayFilter:colorGain"), TfToken("color")}, - {TfToken("PxrImageDisplayFilter:colorOffset"), TfToken("color")}, - {TfToken("PxrWhitePointDisplayFilter:manualWhitePoint"), TfToken("color")} - }; - - const auto it = _filterParamMap.find(paramName); - if (it != _filterParamMap.end()) - { - role = it->second; - } -} - -} // namespace HdPrman_ProjectionParams - -PXR_NAMESPACE_CLOSE_SCOPE diff --git a/third_party/renderman-26/plugin/hdPrman/projectionParams.h b/third_party/renderman-26/plugin/hdPrman/projectionParams.h deleted file mode 100644 index b253816d8a6..00000000000 --- a/third_party/renderman-26/plugin/hdPrman/projectionParams.h +++ /dev/null @@ -1,32 +0,0 @@ -// -// Copyright 2019 Pixar -// -// Licensed under the terms set forth in the LICENSE.txt file available at -// https://openusd.org/license. -// -#ifndef EXT_RMANPKG_25_0_PLUGIN_RENDERMAN_PLUGIN_HD_PRMAN_PROJECTION_PARAMS_H -#define EXT_RMANPKG_25_0_PLUGIN_RENDERMAN_PLUGIN_HD_PRMAN_PROJECTION_PARAMS_H - -#include "pxr/base/tf/token.h" - -PXR_NAMESPACE_OPEN_SCOPE - -// This file should be considered temporary and only exists -// because we currently are unable to ascertain parameter value -// roles from an HdRenderSettingsMap -// -// TODO: Stop setting these on RenderSettings prim. They should be set on -// the integrator/camera/filter prims to which they apply. If they are not -// in usdRiPxr schema, they should be added there. - -namespace HdPrman_ProjectionParams { - - void GetIntegratorParamRole(const TfToken& paramName, TfToken& role); - void GetProjectionParamRole(TfToken& paramName, TfToken& role); - void GetFilterParamRole(TfToken& paramName, TfToken& role); - -} // namespace HdPrman_ProjectionParams - -PXR_NAMESPACE_CLOSE_SCOPE - -#endif // EXT_RMANPKG_25_0_PLUGIN_RENDERMAN_PLUGIN_HD_PRMAN_PROJECTION_PARAMS_H diff --git a/third_party/renderman-26/plugin/hdPrman/renderParam.cpp b/third_party/renderman-26/plugin/hdPrman/renderParam.cpp index 31fd4977aa6..dcd43c12067 100644 --- a/third_party/renderman-26/plugin/hdPrman/renderParam.cpp +++ b/third_party/renderman-26/plugin/hdPrman/renderParam.cpp @@ -16,48 +16,103 @@ #include "hdPrman/material.h" #include "hdPrman/motionBlurSceneIndexPlugin.h" #include "hdPrman/prmanArchDefs.h" // required for stats/Session.h -#include "hdPrman/projectionParams.h" #include "hdPrman/renderDelegate.h" -#if PXR_VERSION >= 2308 -#include "hdPrman/renderSettings.h" -#endif +#include "hdPrman/renderViewContext.h" #include "hdPrman/rixStrings.h" -#include "hdPrman/tokens.h" #include "hdPrman/utils.h" +#include "pxr/imaging/hd/aov.h" +#include "pxr/imaging/hd/enums.h" #include "pxr/imaging/hd/extComputationUtils.h" +#include "pxr/imaging/hd/material.h" #include "pxr/imaging/hd/renderBuffer.h" +#include "pxr/imaging/hd/renderDelegate.h" #include "pxr/imaging/hd/renderThread.h" #include "pxr/imaging/hd/rprim.h" #include "pxr/imaging/hd/sceneDelegate.h" -#include "pxr/imaging/hd/sceneIndexPluginRegistry.h" +#include "pxr/imaging/hd/sprim.h" +#include "pxr/imaging/hd/timeSampleArray.h" +#include "pxr/imaging/hd/tokens.h" +#include "pxr/imaging/hd/types.h" #include "pxr/imaging/hd/version.h" #include "pxr/usd/sdf/path.h" +#include "pxr/usd/sdr/declare.h" +#include "pxr/usd/sdr/registry.h" +#include "pxr/usd/sdr/shaderNode.h" +#include "pxr/usd/sdr/shaderProperty.h" #include "pxr/base/arch/library.h" +#include "pxr/base/gf/vec2d.h" +#include "pxr/base/gf/vec2f.h" +#include "pxr/base/gf/vec2i.h" #include "pxr/base/plug/plugin.h" #include "pxr/base/plug/registry.h" #include "pxr/base/tf/debug.h" +#include "pxr/base/tf/diagnostic.h" +#include "pxr/base/tf/enum.h" #include "pxr/base/tf/envSetting.h" #include "pxr/base/tf/getenv.h" +#include "pxr/base/tf/iterator.h" #include "pxr/base/tf/pathUtils.h" // Extract extension from tf token +#include "pxr/base/tf/registryManager.h" #include "pxr/base/tf/scopeDescription.h" +#include "pxr/base/tf/staticData.h" +#include "pxr/base/tf/staticTokens.h" #include "pxr/base/tf/stringUtils.h" - -#if PXR_VERSION >= 2302 -#include "pxr/imaging/hd/retainedDataSource.h" -#include "pxr/imaging/hd/containerDataSourceEditor.h" -#endif - +#include "pxr/base/tf/token.h" +#include "pxr/base/trace/trace.h" +#include "pxr/base/vt/array.h" +#include "pxr/base/vt/dictionary.h" +#include "pxr/base/vt/types.h" +#include "pxr/pxr.h" + +#include +#include +#include #include #include +#include +#include +#include #include #include +#include +#include #include - +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include +#include +#include +#include +#include +#include + +#if PXR_VERSION >= 2302 +#include "pxr/imaging/hd/retainedDataSource.h" +#include "pxr/imaging/hd/containerDataSourceEditor.h" +#endif + +#if PXR_VERSION >= 2308 +#include "hdPrman/renderSettings.h" +#include "pxr/imaging/hd/renderSettings.h" +#endif PXR_NAMESPACE_OPEN_SCOPE @@ -80,11 +135,13 @@ TF_DEFINE_PRIVATE_TOKENS( ((riDisplayChannelNamespace, "ri:displayChannel:")) // See PxrDisplayDriverAPI ((riDisplayDriverNamespace, "ri:displayDriver:")) - + ((renderTagPrefix, "rendertag_")) (renderCameraPath) ((displayfilterPrefix, "ri:displayfilter")) ((samplefilterPrefix, "ri:samplefilter")) + + (PxrCryptomatte) ); TF_DEFINE_PRIVATE_TOKENS( @@ -182,7 +239,7 @@ HdPrman_RenderParam::HdPrman_RenderParam( TfRegistryManager::GetInstance().SubscribeTo(); _CreateRiley(rileyVariant, xpuCpuConfig, xpuGpuConfig, extraArgs); - + // Register RenderMan display driver HdPrmanFramebuffer::Register(_rix); @@ -211,7 +268,7 @@ HdPrman_RenderParam::IncrementLightLinkCount(TfToken const& name) ++_lightLinkRefs[name]; } -void +void HdPrman_RenderParam::DecrementLightLinkCount(TfToken const& name) { std::lock_guard lock(_lightLinkMutex); @@ -220,7 +277,7 @@ HdPrman_RenderParam::DecrementLightLinkCount(TfToken const& name) } } -bool +bool HdPrman_RenderParam::IsLightLinkUsed(TfToken const& name) { std::lock_guard lock(_lightLinkMutex); @@ -234,7 +291,7 @@ HdPrman_RenderParam::IncrementLightFilterCount(TfToken const& name) ++_lightFilterRefs[name]; } -void +void HdPrman_RenderParam::DecrementLightFilterCount(TfToken const& name) { std::lock_guard lock(_lightFilterMutex); @@ -243,7 +300,7 @@ HdPrman_RenderParam::DecrementLightFilterCount(TfToken const& name) } } -bool +bool HdPrman_RenderParam::IsLightFilterUsed(TfToken const& name) { std::lock_guard lock(_lightFilterMutex); @@ -277,7 +334,7 @@ _ConvertPointsPrimvar( #if HD_API_VERSION >= 68 shutterInterval[0], shutterInterval[1], -#endif +#endif &boxedPoints); } else { HdExtComputationUtils::SampledValueStore @@ -516,11 +573,11 @@ _Convert(HdSceneDelegate *sceneDelegate, SdfPath const& id, std::is_same, std::is_same>::value, "params must be RtParamList or RtPrimVarList"); - + // XXX:TODO: To support array-valued types, we need more // shaping information. Currently we assume arrays are // simply N scalar values, according to the detail. - + std::string label; if constexpr (std::is_same()) { label = "primvar"; @@ -541,14 +598,14 @@ _Convert(HdSceneDelegate *sceneDelegate, SdfPath const& id, // XXX: Prman doesn't seem to check dirtyness before pulling a value. // Passing AllDirty until we plumb/respect change tracking. HdExtComputationPrimvarDescriptorVector computedPrimvars = - _GetComputedPrimvars(sceneDelegate, id, hdInterp, + _GetComputedPrimvars(sceneDelegate, id, hdInterp, HdChangeTracker::AllDirty); if (!computedPrimvars.empty()) { // Execute the computations HdExtComputationUtils::ValueStore valueStore = HdExtComputationUtils::GetComputedPrimvarValues( computedPrimvars, sceneDelegate); - + for (auto const& compPrimvar : computedPrimvars) { auto const it = valueStore.find(compPrimvar.name); if (!TF_VERIFY(it != valueStore.end())) { @@ -571,7 +628,7 @@ _Convert(HdSceneDelegate *sceneDelegate, SdfPath const& id, name.CStr(), TfStringify(val).c_str()); - if (val.IsArrayValued() && + if (val.IsArrayValued() && val.GetArraySize() != static_cast(expectedSize)) { TF_WARN("<%s> primvar '%s' size (%zu) did not match " "expected (%d)", id.GetText(), @@ -703,7 +760,7 @@ _Convert(HdSceneDelegate *sceneDelegate, SdfPath const& id, TF_WARN("<%s> provided multiple representations of the primvar " "'%s'", id.GetText(), name.CStr()); } - // When both ri:attributes and primvar:ri:attributes versions of + // When both ri:attributes and primvar:ri:attributes versions of // the same primvars exist, the primvar:ri:attributes version should // win out. if (hasRiAttributesPrefix && !hasPrimvarsPrefix && @@ -749,7 +806,7 @@ _Convert(HdSceneDelegate *sceneDelegate, SdfPath const& id, // For non-constant primvars, check array size to make sure it // matches the expected topology size. if (hdInterp != HdInterpolationConstant && - val.IsArrayValued() && + val.IsArrayValued() && val.GetArraySize() != static_cast(expectedSize)) { TF_WARN("<%s> %s '%s' size (%zu) did not match " "expected (%d)", id.GetText(), label.c_str(), @@ -817,14 +874,14 @@ HdPrman_TransferMaterialPrimvarOpinions(HdSceneDelegate *sceneDelegate, const HdPrmanMaterial *material = dynamic_cast(sprim); if (material && material->IsValid()) { - const HdMaterialNetwork2 & matNetwork = + const HdMaterialNetwork2 & matNetwork = material->GetMaterialNetwork(); for (const auto & nodeIt : matNetwork.nodes) { const HdMaterialNode2 & node = nodeIt.second; if (node.nodeTypeId == _tokens->PrimvarPass) { for (const auto ¶m : node.parameters) { uint32_t paramId; - RtUString paramName = + RtUString paramName = RtUString(param.first.GetText()); if (!primvars.GetParamId(paramName, paramId)) { HdPrman_Utils::SetPrimVarFromVtValue(paramName, @@ -892,7 +949,7 @@ HdPrman_RenderParam::ConvertAttributes(HdSceneDelegate *sceneDelegate, // e.g., the cards drawmode adapter. // TODO: (tgvarik) Check how Ri:ReverseOrientation interacts with - // displacement. What is intended when front-face culling is applied + // displacement. What is intended when front-face culling is applied // to a surface with displacement? Should be vanishingly rare. const HdCullStyle cullStyle = sceneDelegate->GetCullStyle(id); @@ -907,11 +964,11 @@ HdPrman_RenderParam::ConvertAttributes(HdSceneDelegate *sceneDelegate, attrs.SetInteger(RixStr.k_Ri_Sides, 1); break; case HdCullStyleFrontUnlessDoubleSided: - attrs.SetInteger(RixStr.k_Ri_ReverseOrientation, + attrs.SetInteger(RixStr.k_Ri_ReverseOrientation, sceneDelegate->GetDoubleSided(id) ? 0 : 1); // fallthrough case HdCullStyleBackUnlessDoubleSided: - attrs.SetInteger(RixStr.k_Ri_Sides, + attrs.SetInteger(RixStr.k_Ri_Sides, sceneDelegate->GetDoubleSided(id) ? 2 : 1); break; case HdCullStyleDontCare: @@ -919,7 +976,7 @@ HdPrman_RenderParam::ConvertAttributes(HdSceneDelegate *sceneDelegate, // defer to Prman default by not setting Ri:Sides. break; } - + // Double-sidedness in usd is a property of the gprim for legacy reasons. // Double-sidedness in prman is a property of the material. To achieve @@ -935,7 +992,7 @@ HdPrman_RenderParam::ConvertAttributes(HdSceneDelegate *sceneDelegate, sceneDelegate->GetDoubleSided(id) ? 1 : 0 ); } - + return attrs; } @@ -1153,12 +1210,12 @@ HdPrman_RenderParam::UpdateLegacyOptions() RtUString riName; riName = RtUString(token.GetText()+3); - // XXX there is currently no way to distinguish the type of a + // XXX there is currently no way to distinguish the type of a // float3 setting (color, point, vector). All float3 settings are - // treated as float[3] until we have a way to determine the type. + // treated as float[3] until we have a way to determine the type. HdPrman_Utils::SetParamFromVtValue(riName, val, TfToken(), &options); } else { - + // ri: namespaced settings win over custom settings tokens when // present. if (token == HdRenderSettingsTokens->convergedSamplesPerPixel) { @@ -1183,7 +1240,7 @@ HdPrman_RenderParam::UpdateLegacyOptions() } else if (token == HdPrmanRenderSettingsTokens->pixelAspectRatio) { if (!_Contains(renderSettingsMap, _riOptionsTokens->riRiFormatPixelAspectRatio)) { - options.SetFloat(RixStr.k_Ri_FormatPixelAspectRatio, + options.SetFloat(RixStr.k_Ri_FormatPixelAspectRatio, val.UncheckedGet()); } @@ -1191,7 +1248,7 @@ HdPrman_RenderParam::UpdateLegacyOptions() if (!_Contains(renderSettingsMap, _riOptionsTokens->riRiFormatResolution)) { const GfVec2i& res = val.UncheckedGet(); - options.SetIntegerArray(RixStr.k_Ri_FormatResolution, + options.SetIntegerArray(RixStr.k_Ri_FormatResolution, res.data(), 2); } } else if (token == HdRenderSettingsTokens->threadLimit) { @@ -1208,9 +1265,15 @@ HdPrman_RenderParam::UpdateLegacyOptions() batchCommandLine = val; } // Note: HdPrmanRenderSettingsTokens->disableMotionBlur is handled in - // SetRileyShutterIntervalFromCameraContextCameraPath. + // SetRileyShutterIntervalFromCameraContextCameraPath. } } + + // Force incremental to be enabled for interacive renders + if (_renderDelegate->IsInteractive() && !_usingHusk) { + options.SetInteger(RixStr.k_hider_incremental, 1); + } + // Apply the batch command line settings last, so that they can // either intentionally override render settings, or sometimes be skipped // if the equivalent render setting exists, like for checkpointinterval. @@ -1219,23 +1282,49 @@ HdPrman_RenderParam::UpdateLegacyOptions() SetBatchCommandLineArgs(batchCommandLine, &options); } +static TfToken _GetShaderInputParamRole( + const TfToken& shader, + const TfToken& param) +{ + SdrRegistry& registry = SdrRegistry::GetInstance(); + const SdrShaderNode* entry = registry.GetShaderNodeByIdentifier(shader); + if (!entry) { + return TfToken(); + } + const SdrShaderProperty* input = entry->GetShaderInput(param); + if (!input) { + return TfToken(); + } + return input->GetType(); +} + void HdPrman_RenderParam::SetIntegratorParamsFromRenderSettingsMap( HdPrmanRenderDelegate *renderDelegate, const std::string& integratorName, RtParamList& params) { + // An integrator param in the render settings map looks like this: + // ri:integrator:: + // When asking Sdr for the param, the param name will look like this: + // ri: + // Finally, RenderMan expects to get the param name like this: + // + HdRenderSettingsMap renderSettings = renderDelegate->GetRenderSettingsMap(); - TfToken prefix(std::string("ri:integrator:") + integratorName + ":"); - for (auto const& entry : renderSettings) { + const TfToken prefix(std::string("ri:integrator:") + integratorName + ":"); + for (const auto& entry : renderSettings) { if (TfStringStartsWith(entry.first.GetText(), prefix.GetText())) { - // Strip namespace prefix from USD. - RtUString riName(entry.first.GetText() + prefix.size()); - TfToken role; - HdPrman_ProjectionParams::GetIntegratorParamRole(entry.first, role); - HdPrman_Utils::SetParamFromVtValue(riName, entry.second, - role, ¶ms); + // For RenderMan, strip the whole prefix + const RtUString riName(entry.first.GetText() + prefix.size()); + // for SdrRegistry, strip the prefix but re-prepend 'ri:' + const TfToken inputName( + "ri:" + entry.first.GetString().substr(prefix.size())); + const TfToken role = _GetShaderInputParamRole( + TfToken(integratorName), inputName); + HdPrman_Utils::SetParamFromVtValue( + riName, entry.second, role, ¶ms); } } } @@ -1246,22 +1335,27 @@ HdPrman_RenderParam::SetProjectionParamsFromRenderSettings( std::string& projectionName, RtParamList& params) { - HdRenderSettingsMap renderSettings = renderDelegate->GetRenderSettingsMap(); + // A projection param in the render settings map looks like this: + // ri:projection:: + // When asking Sdr for the param, the param name will look like this: + // ri: + // Finally, RenderMan expects to get the param name like this: + // - TfToken preFix(std::string("ri:projection:") + projectionName); - for (auto const& entry : renderSettings) { - TfToken token = entry.first; - VtValue val = entry.second; + HdRenderSettingsMap renderSettings = renderDelegate->GetRenderSettingsMap(); - bool hasRiPrefix = TfStringStartsWith(token.GetText(), - preFix.GetText()); - if (hasRiPrefix) { - // Strip namespace from USD. - RtUString riName; - riName = RtUString(token.GetText()+preFix.size()+1); - TfToken role; - HdPrman_ProjectionParams::GetProjectionParamRole(token, role); - HdPrman_Utils::SetParamFromVtValue(riName, val, role, ¶ms); + const TfToken prefix(std::string("ri:projection:") + projectionName + ":"); + for (const auto& entry : renderSettings) { + if (TfStringStartsWith(entry.first.GetText(), prefix.GetText())) { + // For RenderMan, strip the whole prefix + const RtUString riName(entry.first.GetText() + prefix.size()); + // for SdrRegistry, strip the prefix but re-prepend 'ri:' + const TfToken inputName( + "ri:" + entry.first.GetString().substr(prefix.size())); + const TfToken role = _GetShaderInputParamRole( + TfToken(projectionName), inputName); + HdPrman_Utils::SetParamFromVtValue( + riName, entry.second, role, ¶ms); } } } @@ -1640,26 +1734,21 @@ HdPrman_RenderParam::SetFiltersFromRenderSettings( return; } - for(auto const& prefix : prefixes) - { - - // Create shading nodes for each sample filter + for (auto const& prefix : prefixes) { + // Create shading nodes for each sample/display filter // They're numbered starting with 1 std::vector nodes; int nodeIdx = 0; bool isSample = (prefix == _tokens->samplefilterPrefix); - while(true) - { - std::string defaultFilterName("None"); + while (true) { + const std::string defaultFilterName("None"); std::string nmStr = prefix.GetText(); nmStr += std::to_string(nodeIdx); nmStr += ":name"; - std::string filterName = - renderDelegate->GetRenderSetting( - TfToken(nmStr.c_str()), - defaultFilterName); - if(!filterName.empty() && filterName != "None") - { + auto filterName = + renderDelegate->GetRenderSetting( + TfToken(nmStr.c_str()), defaultFilterName); + if (!filterName.empty() && filterName != "None") { riley::ShadingNode sn; sn.name = RtUString(filterName.c_str()); std::string handle = filterName += std::to_string(nodeIdx); @@ -1668,9 +1757,7 @@ HdPrman_RenderParam::SetFiltersFromRenderSettings( riley::ShadingNode::Type::k_SampleFilter : riley::ShadingNode::Type::k_DisplayFilter; nodes.push_back(sn); - } - else - { + } else { break; } nodeIdx++; @@ -1679,65 +1766,66 @@ HdPrman_RenderParam::SetFiltersFromRenderSettings( // Append filters collected from shading nodes, // which is not currently the primary workflow, // but they may be present - if(isSample) - { - for(auto it = _sampleFilters.begin(); - it != _sampleFilters.end(); ++it) - { - nodes.push_back(it->second); + if (isSample) { + for (const auto& sampleFilter : _sampleFilters) { + nodes.push_back(sampleFilter.second); } - } - else - { - for(auto it = _displayFilters.begin(); - it != _displayFilters.end(); ++it) - { - nodes.push_back(it->second); + } else { + for (const auto& displayFilter : _displayFilters) { + nodes.push_back(displayFilter.second); } } _sampleFiltersDirty = false; _displayFiltersDirty = false; - if(!nodes.empty()) - { + if (!nodes.empty()) { for (auto const& entry : renderSettings) { - TfToken token = entry.first; - VtValue val = entry.second; - bool hasRiPrefix = TfStringStartsWith(token.GetText(), - prefix.GetText()); - if (hasRiPrefix) { - std::vector toks = TfStringSplit(token, ":"); + // Filter params in render settings map look like this: + // ri::: + // Note that 'prefix' (set above for outer loop) will be: + // ri: + // So we can extract the index, filter name, and param name + // by first stripping the prefix, then splitting on ':' + + if (TfStringStartsWith( + entry.first.GetString(), prefix.GetText())) { + const std::vector toks = TfStringSplit( + entry.first.GetString().substr(prefix.size()), ":"); + // toks[0] : index + // toks[1] : filter name + // toks[2] : param name unsigned long idx = 0; - // strip off the index - // eg. ri:samplefilter0:PxrBackgroundSampleFilter:name - // eg. ri:displayfilter0:PxrBackgroundSampleFilter:name - RtUString riName;; - if(toks.size() == 4) - { - int offset = isSample ? 12 : 13; - std::string idxStr(toks[1].begin()+offset, toks[1].end()); - if(!idxStr.empty()) - idx = std::stoi(idxStr); + RtUString riName; + if (toks.size() == 3 && !toks[0].empty()) { + try { + idx = std::stoi(toks[0]); + } catch (const std::logic_error& e) { + TF_WARN("Malformed sample/display filter param " + "name in render settings: '%s'", + entry.first.GetText()); + continue; + } } - if(toks.size() != 4 || - idx >= nodes.size()) + if (toks.size() != 3 || idx >= nodes.size()) { continue; - std::vector toks2; - toks2.push_back(toks[2]); - toks2.push_back(toks[3]); - riName = RtUString(toks2[1].c_str()); - token = TfToken(TfStringJoin(toks2, ":")); + } + riName = RtUString(toks[2].c_str()); + const TfToken inputName("ri:" + toks[2]); + const TfToken shaderName(toks[1]); + + // copy the value + VtValue value = entry.second; // Some specific fixes for cryptomatte sample filter - if (isSample && toks[2] == "PxrCryptomatte") { - _AddCryptomatteFixes(riName, val); + if (isSample && shaderName == _tokens->PxrCryptomatte) { + _AddCryptomatteFixes(riName, value); } - TfToken role; - HdPrman_ProjectionParams::GetFilterParamRole(token, role); + const TfToken role = _GetShaderInputParamRole( + shaderName, inputName); - HdPrman_Utils::SetParamFromVtValue(riName, val, - role, &nodes[idx].params); + HdPrman_Utils::SetParamFromVtValue( + riName, value, role, &nodes[idx].params); } } @@ -1785,7 +1873,7 @@ HdPrman_RenderParam::SetIntegratorParamsFromCamera( } } -void +void HdPrman_RenderParam::RegisterIntegratorCallbackForCamera( IntegratorCameraCallback const& callback) { @@ -1876,7 +1964,7 @@ HdPrman_RenderParam::_CreateStatsSession(void) HdRetainedTypedSampledDataSource::New(serverId)); // Finalize addition of scene index information - _statsSceneIndex->AddPrims({{SdfPath("/globals"), TfToken("globals"), + _statsSceneIndex->AddPrims({{SdfPath("/globals"), TfToken("globals"), editor.Finish()}}); #endif #endif @@ -2052,7 +2140,7 @@ HdPrman_RenderParam::_CreateRiley(const std::string &rileyVariant, } } -struct RenderOutputDataTypeDesc +struct RenderOutputDataTypeDesc { riley::RenderOutputType rileyType; RtUString fileDataType; @@ -2199,7 +2287,7 @@ _GetOutputDisplayDriverType(const std::string &extension) { std::string("tiff"), TfToken("tiff") }, { std::string("png"), TfToken("png") } }; - + const auto it = extToDisplayDriver.find(extension); if (it != extToDisplayDriver.end()) { return RtUString(it->second.GetText()); @@ -2299,7 +2387,7 @@ _ComputeRenderViewDesc( VtDictionaryGet>( renderSpec, HdPrmanExperimentalRenderSpecTokens->renderVars); - + for (const VtValue &renderVarVal : renderVars) { const VtDictionary renderVar = renderVarVal.Get(); @@ -2345,7 +2433,7 @@ _ComputeRenderViewDesc( _tokens->riDisplayChannelNamespace); renderViewDesc.renderOutputDescs.push_back(renderOutputDesc); } - + const std::vector & renderProducts = VtDictionaryGet>( renderSpec, @@ -2389,8 +2477,8 @@ _ComputeRenderViewDesc( // Forward declaration of helper to create Render Output in the RenderViewDesc static RtUString -_AddRenderOutput(RtUString aovName, - const TfToken &dataType, HdFormat aovFormat, +_AddRenderOutput(RtUString aovName, + const TfToken &dataType, HdFormat aovFormat, RtUString sourceName, const RtParamList ¶ms, const RtUString& filter, const GfVec2f& filterWidth, std::vector *renderOutputDescs, @@ -2448,7 +2536,7 @@ _ComputeRenderViewDesc( if (renderVarIt != seenRenderVars.end()) { displayDesc.renderOutputIndices.push_back(renderVarIt->second); continue; - } + } seenRenderVars.insert( std::pair(renderVar.varPath, renderVarIndex)); displayDesc.renderOutputIndices.push_back(renderVarIndex); @@ -2460,21 +2548,21 @@ _ComputeRenderViewDesc( std::string aovNameStr = (renderVar.sourceType == _tokens->lpe) ? renderVar.varPath.GetName() : renderVar.sourceName; - std::string sourceNameStr = (renderVar.sourceType == _tokens->lpe) + std::string sourceNameStr = (renderVar.sourceType == _tokens->lpe) ? "lpe:" + renderVar.sourceName : renderVar.sourceName; const RtUString aovName(aovNameStr.c_str()); const RtUString sourceName(sourceNameStr.c_str()); - // Create a RenderOutputDesc for this RenderVar and add it to the + // Create a RenderOutputDesc for this RenderVar and add it to the // renderViewDesc. - // Note that we are not using the renderOutputIndices passed into + // Note that we are not using the renderOutputIndices passed into // this function, we are instead relying on the indices stored above std::vector renderOutputIndices; - _AddRenderOutput(aovName, - renderVar.dataType, + _AddRenderOutput(aovName, + renderVar.dataType, HdFormatInvalid, // using renderVar.dataType - sourceName, + sourceName, _ToRtParamList(renderVar.namespacedSettings, _tokens->riDisplayChannelNamespace), defaultPixelFilter, defaultPixelFilterWidth, @@ -2502,13 +2590,13 @@ HdPrman_RenderParam::CreateRenderViewFromRenderSpec( TF_DEBUG(HDPRMAN_RENDER_PASS) .Msg("Create Riley RenderView from the RenderSpec.\n"); - + GetRenderViewContext().CreateRenderView(renderViewDesc, AcquireRiley()); } #if PXR_VERSION >= 2308 /// XXX This should eventually replace the above use of the RenderSpec -void +void HdPrman_RenderParam::CreateRenderViewFromRenderSettingsProducts( HdRenderSettings::RenderProducts const &products, HdPrman_RenderViewContext *renderViewContext) @@ -2518,8 +2606,8 @@ HdPrman_RenderParam::CreateRenderViewFromRenderSettingsProducts( const HdPrman_RenderViewDesc renderViewDesc = _ComputeRenderViewDesc( products, - GetCameraContext().GetCameraId(), - GetActiveIntegratorId(), + GetCameraContext().GetCameraId(), + GetActiveIntegratorId(), GetSampleFilterList(), GetDisplayFilterList()); @@ -2711,7 +2799,7 @@ HdPrman_RenderParam::_ComputeIntegratorNode( const HdPrmanCamera * const cam) { #if PXR_VERSION >= 2308 - // Use the integrator node from a terminal connection on the + // Use the integrator node from a terminal connection on the // renderSettingsPrim if we can if (!GetRenderSettingsIntegratorPath().IsEmpty()) { @@ -2723,14 +2811,16 @@ HdPrman_RenderParam::_ComputeIntegratorNode( rileyIntegratorNode.name = RtUString(integratorNodeType.GetText()); rileyIntegratorNode.handle = RtUString(integratorNodeType.GetText()); - // Initialize the Integrator parameters + // Initialize the Integrator parameters const TfToken prefix("ri:"); for (const auto ¶m : GetRenderSettingsIntegratorNode().parameters) { // Strip the 'ri' namespace before setting the param if (TfStringStartsWith(param.first.GetText(), prefix.GetText())) { - RtUString riName(param.first.GetText() + prefix.size()); - HdPrman_Utils::SetParamFromVtValue(riName, param.second, - TfToken(), &rileyIntegratorNode.params); + const RtUString riName(param.first.GetText() + prefix.size()); + const TfToken role = _GetShaderInputParamRole( + integratorNodeType, param.first); + HdPrman_Utils::SetParamFromVtValue( + riName, param.second, role, &rileyIntegratorNode.params); } } @@ -2741,7 +2831,7 @@ HdPrman_RenderParam::_ComputeIntegratorNode( integratorNodeType.GetString(), rileyIntegratorNode.params); } - + // TODO: Adjust when PxrPathTracer adds support for excludeSubset if (integratorNodeType == HdPrmanIntegratorTokens->PbsPathTracer || integratorNodeType == HdPrmanIntegratorTokens->PxrUnified) { @@ -2777,7 +2867,7 @@ HdPrman_RenderParam::_ComputeIntegratorNode( integratorName, _integratorParams); } - + // TODO: Adjust when PxrPathTracer adds support for excludeSubset if (integratorName == HdPrmanIntegratorTokens->PbsPathTracer.GetString() || integratorName == HdPrmanIntegratorTokens->PxrUnified.GetString()) { @@ -2806,7 +2896,7 @@ HdPrman_RenderParam::_CreateIntegrator(HdRenderDelegate * const renderDelegate) riley::UserId( stats::AddDataLocation(integratorNode.name.CStr()).GetValue()), integratorNode); - + TF_VERIFY(_integratorId != riley::IntegratorId::InvalidId()); _activeIntegratorId = _integratorId; @@ -2820,17 +2910,17 @@ HdPrman_RenderParam::SetActiveRenderTags( // sort the active tags for set_difference TfTokenVector sortedTags(activeRenderTags); std::sort(sortedTags.begin(), sortedTags.end()); - + // set for uniqueness, ordered for set_difference - std::set rprimTags; + std::set rprimTags; for (const SdfPath& id : renderIndex->GetRprimIds()) { const HdRprim* rprim = renderIndex->GetRprim(id); rprimTags.insert(rprim->GetRenderTag()); } - + // fast set for comparison with cached TfToken::Set excludedTags; - + // All rprim tags not in activeTags should be excluded (rprim - active) std::set_difference( rprimTags.begin(), rprimTags.end(), @@ -2853,10 +2943,10 @@ HdPrman_RenderParam::AddRenderTagToGroupingMembership( if (!renderTag.IsEmpty()) { const std::string renderTagString = TfStringPrintf("%s%s", _tokens->renderTagPrefix.GetText(), renderTag.GetText()); - + RtUString membership; params.GetString(RixStr.k_grouping_membership, membership); - + if (membership.Empty()) { membership = RtUString(renderTagString.c_str()); } else { @@ -2904,16 +2994,16 @@ HdPrman_RenderParam::UpdateIntegrator(const HdRenderIndex * const renderIndex) AcquireRiley()->ModifyIntegrator(_integratorId, &node); } -void +void HdPrman_RenderParam::_RenderThreadCallback() { static RtUString const US_RENDERMODE = RtUString("renderMode"); static RtUString const US_INTERACTIVE = RtUString("interactive"); static RtUString const US_PROGRESSMODE = RtUString("progressMode"); - // Note: this is currently hard-coded because hdprman currently + // Note: this is currently hard-coded because hdprman currently // creates only one single camera (via the camera context). - // When this changes, we will need to make sure + // When this changes, we will need to make sure // the correct name is used here. RtUString const &defaultReferenceCamera = GetCameraContext().GetCameraName(); @@ -2921,7 +3011,7 @@ HdPrman_RenderParam::_RenderThreadCallback() RtParamList renderOptions; renderOptions.SetString(US_RENDERMODE, US_INTERACTIVE); renderOptions.SetString( - RixStr.k_dice_referencecamera, + RixStr.k_dice_referencecamera, defaultReferenceCamera); renderOptions.SetInteger(US_PROGRESSMODE, _progressMode); @@ -2934,7 +3024,7 @@ HdPrman_RenderParam::_RenderThreadCallback() renderOptions); } -void +void HdPrman_RenderParam::_ProgressCallback(RixEventCallbacks::Event, RtConstPointer data, RtPointer clientData) { @@ -2950,18 +3040,18 @@ HdPrman_RenderParam::_ProgressCallback(RixEventCallbacks::Event, } } -bool +bool HdPrman_RenderParam::IsValid() const { return _riley; } -void +void HdPrman_RenderParam::Begin(HdPrmanRenderDelegate *renderDelegate) { // Initialize legacy options from the render settings map. UpdateLegacyOptions(); - + // Force initialization of Riley scene options. // (see related comments in SetRileyOptions) #if PXR_VERSION >= 2311 // avoid deferring for now because can cause crash @@ -2971,7 +3061,7 @@ HdPrman_RenderParam::Begin(HdPrmanRenderDelegate *renderDelegate) { SetRileyOptions(); } - + // Set the camera path before the first sync so that // HdPrmanCamera::Sync can detect whether it is syncing the // current camera and needs to set the riley shutter interval @@ -3164,7 +3254,7 @@ HdPrman_RenderParam::SetRileyOptions() _envOptions, _rileySceneIndexObserverOptions, #if PXR_VERSION >= 2311 // causes issues for houdini 20, eg. bad shutter interval - _renderSettingsPrimOptions, + _renderSettingsPrimOptions, #endif GetLegacyOptions(), _fallbackOptions); @@ -3198,7 +3288,7 @@ HdPrman_RenderParam::SetRileyOptions() } } -void +void HdPrman_RenderParam::SetActiveIntegratorId(const riley::IntegratorId id) { _activeIntegratorId = id; @@ -3208,7 +3298,7 @@ HdPrman_RenderParam::SetActiveIntegratorId(const riley::IntegratorId id) GetRenderViewContext().SetIntegratorId(id, riley); } -void +void HdPrman_RenderParam::StartRender() { // Last chance to set Ri options before starting riley! @@ -3236,7 +3326,7 @@ HdPrman_RenderParam::StartRender() _renderThread->StartRender(); } -void +void HdPrman_RenderParam::End() { DeleteRenderThread(); @@ -3318,7 +3408,7 @@ HdPrman_RenderParam::_UpdatePixelFilter() // Riley API is modified to set filter and filter width as an option, we // need to get the render setting ourselves and set it for each AOV. - // WARNING: Defaults are hardcoded. + // WARNING: Defaults are hardcoded. // Make sure they match the values in PRManOptions.args. #if _PRMANAPI_VERSION_MAJOR_ >= 26 static const std::string defaultPixelFilter("gaussian"); @@ -3347,14 +3437,14 @@ HdPrman_RenderParam::_UpdatePixelFilter() bool HdPrman_RenderParam::_UpdateQNSettings() -{ +{ // look for QN settings const HdRenderSettingsMap renderSettingsMap = _renderDelegate->GetRenderSettingsMap(); - const bool useQN = _renderDelegate->GetRenderSetting(TfToken("rmanEnableQNDenoise"), false); - const bool qnCheapPass = _renderDelegate->GetRenderSetting(TfToken("rmanQNCheapPass"), false); - const int qnMinSamples = _renderDelegate->GetRenderSetting(TfToken("rmanQNMinSamples"), 2); - const int qnInterval = _renderDelegate->GetRenderSetting(TfToken("rmanQNInterval"), 4); + const bool useQN = _renderDelegate->GetRenderSetting(TfToken("rmanEnableQNDenoise"), false); + const bool qnCheapPass = _renderDelegate->GetRenderSetting(TfToken("rmanQNCheapPass"), false); + const int qnMinSamples = _renderDelegate->GetRenderSetting(TfToken("rmanQNMinSamples"), 2); + const int qnInterval = _renderDelegate->GetRenderSetting(TfToken("rmanQNInterval"), 4); if (useQN != _useQN || qnCheapPass != _qnCheapPass || qnMinSamples != _qnMinSamples || qnInterval != _qnInterval) { @@ -3368,7 +3458,7 @@ HdPrman_RenderParam::_UpdateQNSettings() } static riley::RenderOutputType -_ToRenderOutputTypeFromHdFormat(const HdFormat aovFormat) +_ToRenderOutputTypeFromHdFormat(const HdFormat aovFormat) { // Prman only supports float, color, and integer if(aovFormat == HdFormatFloat32) { @@ -3385,7 +3475,7 @@ _ToRenderOutputTypeFromHdFormat(const HdFormat aovFormat) // If the aovFormat has 3 or 4 channels, make format Float32 static void -_AdjustColorFormat(HdFormat* aovFormat) +_AdjustColorFormat(HdFormat* aovFormat) { // Prman always renders colors as float, so for types with 3 or 4 // components, always set the format in our framebuffer to float. @@ -3400,9 +3490,9 @@ _AdjustColorFormat(HdFormat* aovFormat) } } -// Update the given Rman AOV and Source names +// Update the given Rman AOV and Source names // - aovName: Map the given hdAovName to the Prman equivalent -// - SourceName: Add 'lpe:' prefix as needed +// - SourceName: Add 'lpe:' prefix as needed static void _UpdateRmanAovAndSourceName( const TfToken &hdAovName, @@ -3420,46 +3510,43 @@ _UpdateRmanAovAndSourceName( // If the sourceType hints that the source is an lpe or primvar, make sure // it starts with "lpe:" or "primvars:" as required by prman. - if(sourceType == "lpe") - { + if(sourceType == "lpe") { std::string sn = rmanSourceName->CStr(); if(sn.rfind("lpe:", 0) == std::string::npos) sn = "lpe:" + sn; *rmanSourceName = RtUString(sn.c_str()); - } - else if(sourceType == "primvar") - { + } else if(sourceType == "primvar") { std::string sn = rmanSourceName->CStr(); if(sn.rfind("primvars:", 0) == std::string::npos) sn = "primvars:" + sn; *rmanSourceName = RtUString(sn.c_str()); } - // Update the Aov and Source names by mapping the HdAovName to an - // equivalent Prman name - if (hdAovName == HdAovTokens->color || hdAovName.GetString() == "ci") { - *rmanAovName = RixStr.k_Ci; - *rmanSourceName = RixStr.k_Ci; - } else if (hdAovName == HdAovTokens->depth) { - *rmanSourceName = RixStr.k_z; - } else if (hdAovName == HdAovTokens->normal) { - *rmanSourceName= RixStr.k_Nn; - } else if (hdAovName == HdAovTokens->primId) { - *rmanAovName = RixStr.k_id; - *rmanSourceName = RixStr.k_id; - } else if (hdAovName == HdAovTokens->instanceId) { - *rmanAovName = RixStr.k_id2; - *rmanSourceName = RixStr.k_id2; - } else if (hdAovName == HdAovTokens->elementId) { - *rmanAovName = RixStr.k_faceindex; - *rmanSourceName = RixStr.k_faceindex; - } else if (*rmanAovName == us_primvars_st) { - *rmanSourceName = us_st; - } - - // If no sourceName is specified, assume name is a standard prman aov - if (rmanSourceName->Empty()) { - *rmanSourceName = *rmanAovName; + if(rmanSourceName->Empty()) { + // Update the Aov and Source names by mapping the HdAovName to an + // equivalent Prman name + if (hdAovName == HdAovTokens->color || hdAovName.GetString() == "ci") { + *rmanAovName = RixStr.k_Ci; + *rmanSourceName = RixStr.k_Ci; + } else if (hdAovName == HdAovTokens->depth) { + *rmanSourceName = RixStr.k_z; + } else if (hdAovName == HdAovTokens->normal) { + *rmanSourceName= RixStr.k_Nn; + } else if (hdAovName == HdAovTokens->primId) { + *rmanAovName = RixStr.k_id; + *rmanSourceName = RixStr.k_id; + } else if (hdAovName == HdAovTokens->instanceId) { + *rmanAovName = RixStr.k_id2; + *rmanSourceName = RixStr.k_id2; + } else if (hdAovName == HdAovTokens->elementId) { + *rmanAovName = RixStr.k_faceindex; + *rmanSourceName = RixStr.k_faceindex; + } else if (*rmanAovName == us_primvars_st) { + *rmanSourceName = us_st; + } else { + // If no sourceName is specified, assume name is a standard prman aov + *rmanSourceName = *rmanAovName; + } } } @@ -3493,8 +3580,8 @@ _GetOutputParamsAndUpdateRmanNames( settingVal.GetWithDefault().GetString(); } - // Gather all properties with the 'driver:parameters:aov' prefix - // into the RtParamList, updating the hdAovName if needed. + // Gather all properties with the 'driver:parameters:aov' prefix + // into the RtParamList, updating the hdAovName if needed. else if (TfStringStartsWith( settingName.GetText(), "driver:parameters:aov:") || TfStringStartsWith( @@ -3561,12 +3648,12 @@ HdPrman_RenderParam::_CreateRileyDisplay( PlugRegistry::GetInstance().GetPluginWithName("hdPrman")) { const std::string path = TfGetPathName(plugin->GetPath()); if (!path.empty()) { - hdPrmanPath = + hdPrmanPath = TfStringCatPaths(path, "hdPrman" ARCH_LIBRARY_SUFFIX); } driver = RtUString("quicklyNoiseless"); displayParams.SetString(RtUString("dspyDSOPath"), RtUString(hdPrmanPath.c_str())); - displayParams.SetInteger(RtUString("cheaPass"), (int) _qnCheapPass); + displayParams.SetInteger(RtUString("cheaPass"), (int) _qnCheapPass); displayParams.SetInteger(RtUString("minSamples"), _qnMinSamples); displayParams.SetInteger(RtUString("interval"), _qnInterval); displayParams.SetInteger(RtUString("normalAsColor"), 1); @@ -3639,7 +3726,11 @@ _AddRenderOutput( } // Get the relativePixelVariance and remap from the given RtParamList +#if _PRMANAPI_VERSION_MAJOR_ >= 26 + float relativePixelVariance = 0.0f; +#else float relativePixelVariance = 1.0f; +#endif params.GetFloat(RixStr.k_relativepixelvariance, relativePixelVariance); RtParamList extraParams; @@ -3678,7 +3769,7 @@ _AddRenderOutput( TF_DEBUG(HDPRMAN_RENDER_PASS) .Msg("Add RenderOutputDesc: \n - name: '%s'\n - type: '%d'\n" " - sourceName: '%s'\n - rule: '%s'\n - filter: '%s'\n\n", - aovName.CStr(), int(rType), sourceName.CStr(), + aovName.CStr(), int(rType), sourceName.CStr(), rule.CStr(), filter.CStr()); renderOutputDescs->push_back(std::move(renderOutputDesc)); @@ -3852,8 +3943,8 @@ HdPrman_RenderParam::CreateFramebufferAndRenderViewFromAovs( // isn't the intent in case it becomes a problem. auto rsrvd = _ComputeRenderViewDesc(renderSettings->GetRenderProducts(), - renderViewDesc.cameraId, - renderViewDesc.integratorId, + renderViewDesc.cameraId, + renderViewDesc.integratorId, renderViewDesc.sampleFilterList, renderViewDesc.displayFilterList); @@ -3894,7 +3985,7 @@ HdPrman_RenderParam::CreateRenderViewFromLegacyProducts( const VtArray& renderProducts, int frame) { // Display edits are not currently supported in HdPrman - // RenderMan Display drivers are inteded for use in batch rendering, + // RenderMan Display drivers are inteded for use in batch rendering, // so bail here if Riley has already been started, since this means that // the Displays already exist. if (renderProducts.empty() || @@ -3910,12 +4001,12 @@ HdPrman_RenderParam::CreateRenderViewFromLegacyProducts( // Here we loop over the Render Products (a USD concept which corresponds // to a Riley Display), make a list of Riley Displays, and collect a list // of all the outputs (AOVs) used by the Displays. - // One Target will be used for all Displays, it needs to be created + // One Target will be used for all Displays, it needs to be created // before the Displays, and takes a list of all possible outputs (AOVs). - // + // // The View and Displays are created, each referencing the Target's id. - // - // XXX In the future, when xpu supports it, we may want to change this to + // + // XXX In the future, when xpu supports it, we may want to change this to // allow for a different Target/View for each Display. HdPrman_RenderViewDesc renderViewDesc; @@ -3942,7 +4033,7 @@ HdPrman_RenderParam::CreateRenderViewFromLegacyProducts( } else if (settingName == HdPrmanRenderProductTokens->orderedVars) { VtArray orderedVars = settingVal.UncheckedGet>(); - + // Find Ci and a Outputs in the RenderVar list int Ci_idx = -1; int a_idx = -1; @@ -3968,7 +4059,7 @@ HdPrman_RenderParam::CreateRenderViewFromLegacyProducts( } // Populate the AOVs Array from the RenderVar list making sure - // that the Ci and a RenderVars are first. + // that the Ci and a RenderVars are first. aovs.reserve(orderedVars.size()); if (Ci_idx >= 0 && Ci_idx < static_cast(orderedVars.size())) { aovs.push_back(orderedVars[Ci_idx]); @@ -3995,8 +4086,8 @@ HdPrman_RenderParam::CreateRenderViewFromLegacyProducts( // If an --output or -o has been specified on command line, override the // product's name and expand variables: - // : source prim (render product node name) - // , , , , , : frame number with padding + // : source prim (render product node name) + // , , , , , : frame number with padding // : the ordinial frame number // Vars can also use dollar style (braces optional) eg. $F4 // ${F4} $OS or printf style formatting: %04d @@ -4025,7 +4116,7 @@ HdPrman_RenderParam::CreateRenderViewFromLegacyProducts( productName = TfToken(outputName); } - // Build Display Settings ParamList using the driverParameters gathered + // Build Display Settings ParamList using the driverParameters gathered // above from the Render Product Settings RtParamList displayParams; for (const TfToken& paramName : driverParameters) { @@ -4054,7 +4145,7 @@ HdPrman_RenderParam::CreateRenderViewFromLegacyProducts( } } - // Keep a list of the indices for the Render Outputs (AOVs/RenderVars) + // Keep a list of the indices for the Render Outputs (AOVs/RenderVars) // of this Display (RenderProduct) // renderViewDesc.renderOutputDescs is a list of all Render Outputs // across all Displays, these renderOutputIndices index into that list. @@ -4072,7 +4163,7 @@ HdPrman_RenderParam::CreateRenderViewFromLegacyProducts( HdFormatFloat32); _AdjustColorFormat(&aovFormat); - // RmanSourceName + // RmanSourceName RtUString rmanSourceName = _GetAsRtUString(aov, HdPrmanAovSettingsTokens->sourceName); @@ -4188,7 +4279,7 @@ HdPrman_RenderParam::_ComputeQuickIntegratorNode( static const RtUString numBxdfSamples("numBxdfSamples"); _quickIntegratorParams.SetInteger(numLightSamples, 1); - _quickIntegratorParams.SetInteger(numBxdfSamples, 1); + _quickIntegratorParams.SetInteger(numBxdfSamples, 1); return riley::ShadingNode{ riley::ShadingNode::Type::k_Integrator, @@ -4230,7 +4321,7 @@ HdPrman_RenderParam::UpdateQuickIntegrator( _ComputeQuickIntegratorNode( renderIndex->GetRenderDelegate(), _cameraContext.GetCamera(renderIndex)); - + AcquireRiley()->ModifyIntegrator( _quickIntegratorId, &node); @@ -4334,7 +4425,7 @@ HdPrman_RenderParam::SetRenderSettingsIntegratorPath( if (! HdRenderIndex::IsSceneIndexEmulationEnabled()) { // Mark the Integrator Prim Dirty sceneDelegate->GetRenderIndex().GetChangeTracker() - .MarkSprimDirty(renderSettingsIntegratorPath, + .MarkSprimDirty(renderSettingsIntegratorPath, HdChangeTracker::DirtyParams); } _renderSettingsIntegratorPath = renderSettingsIntegratorPath; @@ -4346,7 +4437,7 @@ HdPrman_RenderParam::SetRenderSettingsIntegratorPath( } } -void +void HdPrman_RenderParam::SetRenderSettingsIntegratorNode( HdRenderIndex *renderIndex, HdMaterialNode2 const &integratorNode) { @@ -4450,16 +4541,16 @@ HdPrman_RenderParam::CreateSampleFilterNetwork(HdSceneDelegate *sceneDelegate) filterArrayName, filterRefs.data(), filterRefs.size()); shadingNodes.push_back(combinerNode); } - + // Create or update the Riley SampleFilters riley::ShadingNetwork const sampleFilterNetwork = { static_cast(shadingNodes.size()), &shadingNodes[0] }; - + if (_sampleFiltersId == riley::SampleFilterId::InvalidId()) { _sampleFiltersId = AcquireRiley()->CreateSampleFilter( riley::UserId(stats::AddDataLocation("/sampleFilters"). GetValue()), - sampleFilterNetwork, + sampleFilterNetwork, RtParamList()); } else { @@ -4507,16 +4598,16 @@ HdPrman_RenderParam::CreateDisplayFilterNetwork(HdSceneDelegate *sceneDelegate) filterArrayName, filterRefs.data(), filterRefs.size()); shadingNodes.push_back(combinerNode); } - + // Create or update the Riley DisplayFilters riley::ShadingNetwork const displayFilterNetwork = { static_cast(shadingNodes.size()), &shadingNodes[0] }; - + if (_displayFiltersId == riley::DisplayFilterId::InvalidId()) { _displayFiltersId = AcquireRiley()->CreateDisplayFilter( riley::UserId(stats::AddDataLocation("/displayFilters"). GetValue()), - displayFilterNetwork, + displayFilterNetwork, RtParamList()); } else { @@ -4559,7 +4650,7 @@ HdPrman_RenderParam::AddDisplayFilter( filterIt.first->second = node; } - // If we have all the Shading Nodes, creat the DisplayFilters in Riley + // If we have all the Shading Nodes, creat the DisplayFilters in Riley if (_displayFilterNodes.size() == _connectedDisplayFilterPaths.size()) { CreateDisplayFilterNetwork(sceneDelegate); } @@ -4568,7 +4659,7 @@ HdPrman_RenderParam::AddDisplayFilter( riley::SampleFilterList HdPrman_RenderParam::GetSampleFilterList() { - return (_sampleFiltersId == riley::SampleFilterId::InvalidId()) + return (_sampleFiltersId == riley::SampleFilterId::InvalidId()) ? riley::SampleFilterList({ 0, nullptr }) : riley::SampleFilterList({ 1, &_sampleFiltersId }); } @@ -4585,7 +4676,7 @@ void HdPrman_RenderParam::_CreateFallbackLight() { static const RtUString us_PxrDomeLight("PxrDomeLight"); - static const RtUString us_lightA("lightA"); + static const RtUString us_lightA("lightA"); static const RtUString us_traceLightPaths("traceLightPaths"); static const RtUString us_lightGroup("lightGroup"); static const RtUString us_A("A"); @@ -4604,9 +4695,9 @@ HdPrman_RenderParam::_CreateFallbackLight() }; _fallbackLightShader = _riley->CreateLightShader( riley::UserId::DefaultId(), {1, &lightNode}, {0, nullptr}); - + riley::CoordinateSystemList const k_NoCoordsys = { 0, nullptr }; - + // Constant identity transform const float zerotime[1] = { 0.0f }; const RtMatrix4x4 matrix[1] = { RixConstants::k_IdentityMatrix }; diff --git a/third_party/renderman-26/plugin/hdPrman/renderPassSceneIndex.cpp b/third_party/renderman-26/plugin/hdPrman/renderPassSceneIndex.cpp index 0e736e301d9..7fdaeac1838 100644 --- a/third_party/renderman-26/plugin/hdPrman/renderPassSceneIndex.cpp +++ b/third_party/renderman-26/plugin/hdPrman/renderPassSceneIndex.cpp @@ -4,7 +4,7 @@ // https://openusd.org/license. #include "hdPrman/renderPassSceneIndex.h" -#if PXR_VERSION >= 2405 +#if PXR_VERSION >= 2408 #include "hdPrman/tokens.h" #include "pxr/imaging/hd/version.h" @@ -547,4 +547,4 @@ HdPrman_RenderPassSceneIndex::_UpdateActiveRenderPassState( } PXR_NAMESPACE_CLOSE_SCOPE -#endif //PXR_VERSION >= 2405 +#endif //PXR_VERSION >= 2408 diff --git a/third_party/renderman-26/plugin/hdPrman/renderPassSceneIndex.h b/third_party/renderman-26/plugin/hdPrman/renderPassSceneIndex.h index 776a0b6e718..eca7d9342ee 100644 --- a/third_party/renderman-26/plugin/hdPrman/renderPassSceneIndex.h +++ b/third_party/renderman-26/plugin/hdPrman/renderPassSceneIndex.h @@ -7,7 +7,7 @@ #define EXT_RMANPKG_25_0_PLUGIN_RENDERMAN_PLUGIN_HD_PRMAN_RENDER_PASS_SCENE_INDEX_H #include "pxr/pxr.h" -#if PXR_VERSION >= 2405 +#if PXR_VERSION >= 2408 #include "pxr/imaging/hd/collectionExpressionEvaluator.h" #include "pxr/imaging/hd/filteringSceneIndex.h" #include @@ -92,4 +92,4 @@ class HdPrman_RenderPassSceneIndex : PXR_NAMESPACE_CLOSE_SCOPE #endif -#endif // PXR_VERSION >= 2405 +#endif // PXR_VERSION >= 2408 diff --git a/third_party/renderman-26/plugin/hdPrman/renderPassSceneIndexPlugin.cpp b/third_party/renderman-26/plugin/hdPrman/renderPassSceneIndexPlugin.cpp index e25c1ce62bf..18a0cb2a057 100644 --- a/third_party/renderman-26/plugin/hdPrman/renderPassSceneIndexPlugin.cpp +++ b/third_party/renderman-26/plugin/hdPrman/renderPassSceneIndexPlugin.cpp @@ -6,7 +6,7 @@ #include "hdPrman/renderPassSceneIndexPlugin.h" -#if PXR_VERSION >= 2405 +#if PXR_VERSION >= 2408 #include "hdPrman/tokens.h" @@ -56,4 +56,4 @@ HdPrman_RenderPassSceneIndexPlugin::_AppendSceneIndex( PXR_NAMESPACE_CLOSE_SCOPE -#endif // PXR_VERSION >= 2405 +#endif // PXR_VERSION >= 2408 diff --git a/third_party/renderman-26/plugin/hdPrman/renderPassSceneIndexPlugin.h b/third_party/renderman-26/plugin/hdPrman/renderPassSceneIndexPlugin.h index 0297ab05ef6..d9a5190493d 100644 --- a/third_party/renderman-26/plugin/hdPrman/renderPassSceneIndexPlugin.h +++ b/third_party/renderman-26/plugin/hdPrman/renderPassSceneIndexPlugin.h @@ -8,7 +8,7 @@ #define EXT_RMANPKG_25_0_PLUGIN_RENDERMAN_PLUGIN_HD_PRMAN_RENDER_PASS_SCENE_INDEX_PLUGIN_H #include "pxr/pxr.h" -#if PXR_VERSION >= 2405 +#if PXR_VERSION >= 2408 #include "pxr/imaging/hd/sceneIndexPlugin.h" #include "hdPrman/api.h" @@ -33,4 +33,4 @@ class HdPrman_RenderPassSceneIndexPlugin : public HdSceneIndexPlugin PXR_NAMESPACE_CLOSE_SCOPE #endif -#endif //PXR_VERSION >= 2405 +#endif //PXR_VERSION >= 2408 diff --git a/third_party/renderman-26/plugin/hdPrman/renderSettings.cpp b/third_party/renderman-26/plugin/hdPrman/renderSettings.cpp index 69fe636b5e8..bd3e8c51830 100644 --- a/third_party/renderman-26/plugin/hdPrman/renderSettings.cpp +++ b/third_party/renderman-26/plugin/hdPrman/renderSettings.cpp @@ -231,7 +231,7 @@ _UpdateRileyCamera( } } -#if PXR_VERSION >= 2405 +#if PXR_VERSION >= 2407 // Update the Frame number from the Stage Global Scene Index void _UpdateFrame( @@ -563,7 +563,7 @@ void HdPrman_RenderSettings::_Sync( } #endif -#if PXR_VERSION >= 2405 +#if PXR_VERSION >= 2407 if (*dirtyBits & HdRenderSettings::DirtyFrameNumber || *dirtyBits & HdRenderSettings::DirtyNamespacedSettings) { _UpdateFrame(terminalSi, &_settingsOptions); @@ -587,7 +587,7 @@ void HdPrman_RenderSettings::_Sync( param->SetDrivingRenderSettingsPrimPath(GetId()); -#if PXR_VERSION >= 2405 +#if PXR_VERSION >= 2407 if (*dirtyBits & HdRenderSettings::DirtyNamespacedSettings || *dirtyBits & HdRenderSettings::DirtyActive || *dirtyBits & HdRenderSettings::DirtyShutterInterval || diff --git a/third_party/renderman-26/plugin/rmanArgsParser/pch.h b/third_party/renderman-26/plugin/rmanArgsParser/pch.h index 0c374855dea..8b77628f495 100644 --- a/third_party/renderman-26/plugin/rmanArgsParser/pch.h +++ b/third_party/renderman-26/plugin/rmanArgsParser/pch.h @@ -59,6 +59,7 @@ #include #include #if defined(PXR_PYTHON_SUPPORT_ENABLED) && !defined(PXR_USE_INTERNAL_BOOST_PYTHON) +#include "pxr/external/boost/python/common.hpp" #include #include #include diff --git a/third_party/renderman-26/shaders/UsdPreviewSurfaceParameters.osl b/third_party/renderman-26/shaders/UsdPreviewSurfaceParameters.osl index a7e6b9ba306..11b3e8d9212 100644 --- a/third_party/renderman-26/shaders/UsdPreviewSurfaceParameters.osl +++ b/third_party/renderman-26/shaders/UsdPreviewSurfaceParameters.osl @@ -56,17 +56,15 @@ shader UsdPreviewSurfaceParameters output normal bumpNormalOut = normal(0.0,0.0,0.0) [[ string widget = "null" ]], - // Opacity - output float refractionGainOut = 0.0 - [[ string widget = "null" ]], + // Opacity & Presence outputs output float glassIorOut= 0.0 [[ string widget = "null" ]], - - // Presence output + output float glassRoughnessOut = 0.0 + [[ string widget = "null" ]], output float presenceOut = 1.0 [[ string widget = "null" ]], - // Displacement output + // Displacement outputs output float dispAmountOut = 0.0 [[ string widget = "null" ]], output float dispScalarOut = 0.0 @@ -145,7 +143,7 @@ shader UsdPreviewSurfaceParameters // Opacity if (opacityAdjusted < 1.0) { glassIorOut = ior; - refractionGainOut = 1.0 - opacityAdjusted; + glassRoughnessOut = 0.0; diffuseGainOut *= opacityAdjusted; presenceOut = opacityAdjusted; }