add usd-21-11-win64_py39
This commit is contained in:
1 parent
41d23e71ba
commit
ba5e1f7e67
15684 files changed
+3069957
No files matched your search
@@ -0,0 +1,186 @@
|
||||
//
|
||||
// Copyright 2018 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_AOV_H
|
||||
#define PXR_IMAGING_HD_AOV_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/types.h"
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
#include "pxr/base/gf/vec3i.h"
|
||||
#include "pxr/base/tf/hashmap.h"
|
||||
#include "pxr/base/vt/value.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
typedef TfHashMap<TfToken, VtValue, TfToken::HashFunctor> HdAovSettingsMap;
|
||||
|
||||
/// \class HdAovDescriptor
|
||||
///
|
||||
/// A bundle of state describing an AOV ("Arbitrary Output Variable") display
|
||||
/// channel. Note that in hydra API, this data is split between
|
||||
/// HdRenderPassAovBinding and HdRenderBufferDescriptor. This class is
|
||||
/// provided for use in higher level application-facing API.
|
||||
struct HdAovDescriptor
|
||||
{
|
||||
HdAovDescriptor()
|
||||
: format(HdFormatInvalid), multiSampled(false)
|
||||
, clearValue(), aovSettings() {}
|
||||
HdAovDescriptor(HdFormat f, bool ms, VtValue const& c)
|
||||
: format(f), multiSampled(ms), clearValue(c), aovSettings() {}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// Render buffer parameters
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
/// The AOV output format. See also HdRenderBufferDescriptor#format.
|
||||
HdFormat format;
|
||||
|
||||
/// Whether the render buffer should be multisampled.
|
||||
/// See also HdRenderBufferDescriptor#multiSampled.
|
||||
bool multiSampled;
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// Renderpass binding parameters.
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
/// The clear value to apply to the render buffer before rendering.
|
||||
/// The type of "clearValue" should match the provided format.
|
||||
/// If clearValue is empty, no clear will be performed.
|
||||
/// See also HdRenderPassAovBinding#clearValue.
|
||||
VtValue clearValue;
|
||||
|
||||
/// Extra settings for AOV rendering, such as pixel filtering options.
|
||||
/// See also HdRenderPassAovBinding#aovSettings.
|
||||
HdAovSettingsMap aovSettings;
|
||||
};
|
||||
typedef std::vector<HdAovDescriptor> HdAovDescriptorList;
|
||||
|
||||
/// \struct HdRenderBufferDescriptor
|
||||
///
|
||||
/// Describes the allocation structure of a render buffer bprim.
|
||||
struct HdRenderBufferDescriptor {
|
||||
/// The width, height, and depth of the allocated render buffer.
|
||||
GfVec3i dimensions;
|
||||
|
||||
/// The data format of the render buffer. See also HdAovDescriptor#format.
|
||||
HdFormat format;
|
||||
|
||||
/// Whether the render buffer should be multisampled. See also
|
||||
/// HdAovDescriptor#multiSampled.
|
||||
bool multiSampled;
|
||||
|
||||
bool operator==(HdRenderBufferDescriptor const& rhs) const {
|
||||
return dimensions == rhs.dimensions &&
|
||||
format == rhs.format && multiSampled == rhs.multiSampled;
|
||||
}
|
||||
bool operator!=(HdRenderBufferDescriptor const& rhs) const {
|
||||
return !(*this == rhs);
|
||||
}
|
||||
};
|
||||
|
||||
/// \class HdRenderPassAovBinding
|
||||
///
|
||||
/// A renderpass AOV represents a binding of some output of the
|
||||
/// rendering process to an output buffer.
|
||||
|
||||
class HdRenderBuffer;
|
||||
|
||||
struct HdRenderPassAovBinding {
|
||||
|
||||
HdRenderPassAovBinding()
|
||||
: renderBuffer(nullptr) {}
|
||||
|
||||
/// The identifier of the renderer output to be consumed. This should take
|
||||
/// a value from HdAovTokens.
|
||||
/// XXX: Depth aov bindings are identified by the "depth" suffix.
|
||||
/// See HdAovHasDepthSemantic().
|
||||
TfToken aovName;
|
||||
|
||||
/// The render buffer to be bound to the above terminal output.
|
||||
///
|
||||
/// From the app or scene, this can be specified as either a pointer or
|
||||
/// a path to a renderbuffer in the render index. If both are specified,
|
||||
/// the pointer is used preferentially.
|
||||
///
|
||||
/// Note: hydra never takes ownership of the renderBuffer, but assumes it
|
||||
/// will be alive until the end of the renderpass, or whenever the buffer
|
||||
/// is marked converged, whichever is later.
|
||||
HdRenderBuffer* renderBuffer;
|
||||
|
||||
/// The render buffer to be bound to the above terminal output.
|
||||
SdfPath renderBufferId;
|
||||
|
||||
/// The clear value to apply to the bound render buffer, before rendering.
|
||||
/// The type of "clearValue" should match the type of the bound buffer.
|
||||
/// If clearValue is empty, it indicates no clear should be performed.
|
||||
/// See also HdAovDescriptor#clearValue.
|
||||
VtValue clearValue;
|
||||
|
||||
/// Extra settings for AOV rendering, such as pixel filtering options.
|
||||
/// See also HdAovDescriptor#aovSettings.
|
||||
HdAovSettingsMap aovSettings;
|
||||
};
|
||||
|
||||
typedef std::vector<HdRenderPassAovBinding> HdRenderPassAovBindingVector;
|
||||
|
||||
// VtValue requirements for HdRenderPassAovBinding
|
||||
HD_API
|
||||
std::ostream& operator<<(std::ostream& out,
|
||||
const HdRenderPassAovBinding& desc);
|
||||
HD_API
|
||||
bool operator==(const HdRenderPassAovBinding& lhs,
|
||||
const HdRenderPassAovBinding& rhs);
|
||||
HD_API
|
||||
bool operator!=(const HdRenderPassAovBinding& lhs,
|
||||
const HdRenderPassAovBinding& rhs);
|
||||
|
||||
HD_API
|
||||
size_t hash_value(const HdRenderPassAovBinding &b);
|
||||
|
||||
/// Returns true if the aov is used as a depth binding based on its name.
|
||||
HD_API
|
||||
bool HdAovHasDepthSemantic(TfToken const& aovName);
|
||||
|
||||
/// \class HdParsedAovToken
|
||||
///
|
||||
/// Represents an AOV token which has been parsed to extract the prefix
|
||||
/// (in the case of "primvars:"/"lpe:"/etc.).
|
||||
struct HdParsedAovToken {
|
||||
HD_API
|
||||
HdParsedAovToken();
|
||||
HD_API
|
||||
HdParsedAovToken(TfToken const& aovName);
|
||||
|
||||
TfToken name;
|
||||
bool isPrimvar : 1;
|
||||
bool isLpe : 1;
|
||||
bool isShader : 1;
|
||||
};
|
||||
typedef std::vector<HdParsedAovToken> HdParsedAovTokenVector;
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_AOV_H
|
||||
@@ -0,0 +1,47 @@
|
||||
//
|
||||
// Copyright 2017 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_API_H
|
||||
#define PXR_IMAGING_HD_API_H
|
||||
|
||||
#include "pxr/base/arch/export.h"
|
||||
|
||||
#if defined(PXR_STATIC)
|
||||
# define HD_API
|
||||
# define HD_API_TEMPLATE_CLASS(...)
|
||||
# define HD_API_TEMPLATE_STRUCT(...)
|
||||
# define HD_LOCAL
|
||||
#else
|
||||
# if defined(HD_EXPORTS)
|
||||
# define HD_API ARCH_EXPORT
|
||||
# define HD_API_TEMPLATE_CLASS(...) ARCH_EXPORT_TEMPLATE(class, __VA_ARGS__)
|
||||
# define HD_API_TEMPLATE_STRUCT(...) ARCH_EXPORT_TEMPLATE(struct, __VA_ARGS__)
|
||||
# else
|
||||
# define HD_API ARCH_IMPORT
|
||||
# define HD_API_TEMPLATE_CLASS(...) ARCH_IMPORT_TEMPLATE(class, __VA_ARGS__)
|
||||
# define HD_API_TEMPLATE_STRUCT(...) ARCH_IMPORT_TEMPLATE(struct, __VA_ARGS__)
|
||||
# endif
|
||||
# define HD_LOCAL ARCH_HIDDEN
|
||||
#endif
|
||||
|
||||
#endif // PXR_IMAGING_HD_API_H
|
||||
@@ -0,0 +1,124 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_BASIS_CURVES_H
|
||||
#define PXR_IMAGING_HD_BASIS_CURVES_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/rprim.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
#define HD_BASISCURVES_REPR_DESC_TOKENS \
|
||||
(surfaceShader) \
|
||||
(surfaceShaderUnlit) \
|
||||
(hullColor) \
|
||||
(pointColor)
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdBasisCurvesReprDescTokens, HD_API,
|
||||
HD_BASISCURVES_REPR_DESC_TOKENS);
|
||||
|
||||
/// \class HdBasisCurvesReprDesc
|
||||
///
|
||||
/// Descriptor to configure a drawItem for a repr.
|
||||
///
|
||||
struct HdBasisCurvesReprDesc {
|
||||
HdBasisCurvesReprDesc(
|
||||
HdBasisCurvesGeomStyle geomStyle = HdBasisCurvesGeomStyleInvalid,
|
||||
TfToken shadingTerminal = HdBasisCurvesReprDescTokens->surfaceShader)
|
||||
: geomStyle(geomStyle),
|
||||
shadingTerminal(shadingTerminal)
|
||||
{}
|
||||
|
||||
bool IsEmpty() const {
|
||||
return geomStyle == HdBasisCurvesGeomStyleInvalid;
|
||||
}
|
||||
|
||||
HdBasisCurvesGeomStyle geomStyle;
|
||||
/// Specifies how the fragment color should be computed from primvar;
|
||||
/// this can be used to render heatmap highlighting etc.
|
||||
TfToken shadingTerminal;
|
||||
};
|
||||
|
||||
/// Hydra Schema for a collection of curves using a particular basis.
|
||||
///
|
||||
class HdBasisCurves : public HdRprim {
|
||||
public:
|
||||
HD_API
|
||||
virtual ~HdBasisCurves();
|
||||
|
||||
///
|
||||
/// Topology
|
||||
///
|
||||
inline HdBasisCurvesTopology GetBasisCurvesTopology(HdSceneDelegate* delegate) const;
|
||||
inline HdDisplayStyle GetDisplayStyle(HdSceneDelegate* delegate) const;
|
||||
|
||||
HD_API
|
||||
TfTokenVector const & GetBuiltinPrimvarNames() const override;
|
||||
|
||||
/// Configure geometric style of drawItems for \p reprName
|
||||
HD_API
|
||||
static void ConfigureRepr(TfToken const &reprName,
|
||||
HdBasisCurvesReprDesc desc);
|
||||
|
||||
/// Returns whether refinement is always on or not.
|
||||
HD_API
|
||||
static bool IsEnabledForceRefinedCurves();
|
||||
|
||||
protected:
|
||||
HD_API
|
||||
HdBasisCurves(SdfPath const& id);
|
||||
|
||||
typedef _ReprDescConfigs<HdBasisCurvesReprDesc> _BasisCurvesReprConfig;
|
||||
|
||||
HD_API
|
||||
static _BasisCurvesReprConfig::DescArray
|
||||
_GetReprDesc(TfToken const &reprName);
|
||||
|
||||
private:
|
||||
// Class can not be default constructed or copied.
|
||||
HdBasisCurves() = delete;
|
||||
HdBasisCurves(const HdBasisCurves &) = delete;
|
||||
HdBasisCurves &operator =(const HdBasisCurves &) = delete;
|
||||
|
||||
static _BasisCurvesReprConfig _reprDescConfig;
|
||||
};
|
||||
|
||||
inline HdBasisCurvesTopology
|
||||
HdBasisCurves::GetBasisCurvesTopology(HdSceneDelegate* delegate) const
|
||||
{
|
||||
return delegate->GetBasisCurvesTopology(GetId());
|
||||
}
|
||||
|
||||
inline HdDisplayStyle
|
||||
HdBasisCurves::GetDisplayStyle(HdSceneDelegate* delegate) const
|
||||
{
|
||||
return delegate->GetDisplayStyle(GetId());
|
||||
}
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_BASIS_CURVES_H
|
||||
@@ -0,0 +1,136 @@
|
||||
//
|
||||
// Copyright 2021 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// This file is generated by a script. Do not edit directly. Edit the
|
||||
// schema.template.h file to make changes.
|
||||
|
||||
#ifndef PXR_IMAGING_HD_BASIS_CURVES_SCHEMA_H
|
||||
#define PXR_IMAGING_HD_BASIS_CURVES_SCHEMA_H
|
||||
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
|
||||
#include "pxr/imaging/hd/basisCurvesTopologySchema.h"
|
||||
#include "pxr/imaging/hd/geomSubsetsSchema.h"
|
||||
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define HDBASISCURVES_SCHEMA_TOKENS \
|
||||
(basisCurves) \
|
||||
(topology) \
|
||||
(geomSubsets) \
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdBasisCurvesSchemaTokens, HD_API,
|
||||
HDBASISCURVES_SCHEMA_TOKENS);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class HdBasisCurvesSchema : public HdSchema
|
||||
{
|
||||
public:
|
||||
HdBasisCurvesSchema(HdContainerDataSourceHandle container)
|
||||
: HdSchema(container) {}
|
||||
|
||||
//ACCESSORS
|
||||
|
||||
HD_API
|
||||
HdBasisCurvesTopologySchema GetTopology();
|
||||
HD_API
|
||||
HdGeomSubsetsSchema GetGeomSubsets();
|
||||
|
||||
// RETRIEVING AND CONSTRUCTING
|
||||
|
||||
/// 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 HdContainerDataSourceHandle &topology,
|
||||
const HdContainerDataSourceHandle &geomSubsets
|
||||
);
|
||||
|
||||
/// \class HdBasisCurvesSchema::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 &SetTopology(
|
||||
const HdContainerDataSourceHandle &topology);
|
||||
HD_API
|
||||
Builder &SetGeomSubsets(
|
||||
const HdContainerDataSourceHandle &geomSubsets);
|
||||
|
||||
/// Returns a container data source containing the members set thus far.
|
||||
HD_API
|
||||
HdContainerDataSourceHandle Build();
|
||||
|
||||
private:
|
||||
HdContainerDataSourceHandle _topology;
|
||||
HdContainerDataSourceHandle _geomSubsets;
|
||||
};
|
||||
|
||||
/// Retrieves a container data source with the schema's default name token
|
||||
/// "basisCurves" from the parent container and constructs a
|
||||
/// HdBasisCurvesSchema 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 HdBasisCurvesSchema GetFromParent(
|
||||
const HdContainerDataSourceHandle &fromParentContainer);
|
||||
|
||||
/// 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();
|
||||
|
||||
|
||||
/// Returns an HdDataSourceLocator (relative to the prim-level data source)
|
||||
/// where the topology data source can be found.
|
||||
/// This is often useful for checking intersection against the
|
||||
/// HdDataSourceLocatorSet sent with HdDataSourceObserver::PrimsDirtied.
|
||||
HD_API
|
||||
static const HdDataSourceLocator &GetTopologyLocator();
|
||||
|
||||
/// Returns an HdDataSourceLocator (relative to the prim-level data source)
|
||||
/// where the geomsubsets data source can be found.
|
||||
/// This is often useful for checking intersection against the
|
||||
/// HdDataSourceLocatorSet sent with HdDataSourceObserver::PrimsDirtied.
|
||||
HD_API
|
||||
static const HdDataSourceLocator &GetGeomSubsetsLocator();
|
||||
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,182 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_BASIS_CURVES_TOPOLOGY_H
|
||||
#define PXR_IMAGING_HD_BASIS_CURVES_TOPOLOGY_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/topology.h"
|
||||
#include "pxr/imaging/hd/tokens.h"
|
||||
|
||||
#include "pxr/base/vt/array.h"
|
||||
#include "pxr/base/vt/value.h"
|
||||
|
||||
#include "pxr/base/tf/token.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// \class HdBasisCurvesTopology
|
||||
///
|
||||
/// Topology data for basisCurves.
|
||||
///
|
||||
/// HdBasisCurvesTopology holds the raw input topology data for basisCurves
|
||||
///
|
||||
/// The Type, Basis and Wrap mode combined describe the curve and it's
|
||||
/// segments.
|
||||
///
|
||||
/// If Type == linear, the curve is a bunch of line segments and basis is
|
||||
/// ignored.
|
||||
///
|
||||
/// The wrap mode defines how the curve segments are specified:
|
||||
///
|
||||
/// If Wrap == segmented, this is equivalent to GL_LINES and curve vertex
|
||||
/// counts is 2 * number of segments (multiple entries in curve vertex
|
||||
/// array is optional).
|
||||
///
|
||||
/// If Wrap == nonperiodic, this is equivalent to GL_LINE_STRIP and curve
|
||||
/// counts is an array where each entry is the number of vertices in that
|
||||
/// line segment. The first and last vertex in the segment are not joined.
|
||||
///
|
||||
/// If Wrap == periodic, this is equivalent to GL_LINE_LOOP and curve counts
|
||||
/// is an array where each entry is the number of vertices in that line
|
||||
/// segment. An additional line is place between the first and last vertex
|
||||
/// in each segment.
|
||||
///
|
||||
/// If Type == cubic, the type of curve is specified by basis:
|
||||
/// The Basis can be bezier, bspline or catmullRom.
|
||||
///
|
||||
/// Wrap can be either periodic or nonperiodic (segmented is unsupported).
|
||||
///
|
||||
/// For each type of line, the generated vertex indices can pass through an
|
||||
/// optional index buffer to map the generated indices to actual indices in
|
||||
/// the vertex buffer.
|
||||
///
|
||||
class HdBasisCurvesTopology : public HdTopology {
|
||||
public:
|
||||
|
||||
HD_API
|
||||
HdBasisCurvesTopology();
|
||||
HD_API
|
||||
HdBasisCurvesTopology(const HdBasisCurvesTopology &src);
|
||||
|
||||
HD_API
|
||||
HdBasisCurvesTopology(const TfToken &curveType,
|
||||
const TfToken &curveBasis,
|
||||
const TfToken &curveWrap,
|
||||
const VtIntArray &curveVertexCounts,
|
||||
const VtIntArray &curveIndices);
|
||||
HD_API
|
||||
virtual ~HdBasisCurvesTopology();
|
||||
|
||||
///
|
||||
/// \name Topological invisibility
|
||||
/// @{
|
||||
///
|
||||
HD_API
|
||||
void SetInvisiblePoints(VtIntArray const &invisiblePoints) {
|
||||
_invisiblePoints = invisiblePoints;
|
||||
}
|
||||
|
||||
HD_API
|
||||
VtIntArray const & GetInvisiblePoints() const {
|
||||
return _invisiblePoints;
|
||||
}
|
||||
|
||||
HD_API
|
||||
void SetInvisibleCurves(VtIntArray const &invisibleCurves) {
|
||||
_invisibleCurves = invisibleCurves;
|
||||
}
|
||||
|
||||
HD_API
|
||||
VtIntArray const & GetInvisibleCurves() const {
|
||||
return _invisibleCurves;
|
||||
}
|
||||
/// @}
|
||||
|
||||
/// Returns segment vertex counts.
|
||||
VtIntArray const &GetCurveVertexCounts() const {
|
||||
return _curveVertexCounts;
|
||||
}
|
||||
|
||||
/// Returns indices.
|
||||
VtIntArray const &GetCurveIndices() const {
|
||||
return _curveIndices;
|
||||
}
|
||||
|
||||
/// Returns the number of curves
|
||||
size_t GetNumCurves() const {
|
||||
return _curveVertexCounts.size();
|
||||
}
|
||||
|
||||
/// Returns the number of points implied by vertex counts and indices
|
||||
HD_API
|
||||
size_t GetNumPoints() const {
|
||||
return _numPoints;
|
||||
}
|
||||
|
||||
/// See class documentation for valid combination of values
|
||||
TfToken GetCurveType() const { return _curveType; }
|
||||
TfToken GetCurveBasis() const { return _curveBasis; }
|
||||
TfToken GetCurveWrap() const { return _curveWrap; }
|
||||
|
||||
/// Does the topology use an index buffer
|
||||
bool HasIndices() const { return !_curveIndices.empty(); }
|
||||
|
||||
/// Returns the hash value of this topology to be used for instancing.
|
||||
HD_API
|
||||
virtual ID ComputeHash() const;
|
||||
|
||||
/// Equality check between two basisCurves topologies.
|
||||
HD_API
|
||||
bool operator==(HdBasisCurvesTopology const &other) const;
|
||||
HD_API
|
||||
bool operator!=(HdBasisCurvesTopology const &other) const;
|
||||
|
||||
/// Figure out how many vertices / control points this topology references
|
||||
HD_API
|
||||
size_t CalculateNeededNumberOfControlPoints() const;
|
||||
|
||||
/// Figure out how many control points with varying data this topology needs
|
||||
HD_API
|
||||
size_t CalculateNeededNumberOfVaryingControlPoints() const;
|
||||
|
||||
private:
|
||||
TfToken _curveType;
|
||||
TfToken _curveBasis;
|
||||
TfToken _curveWrap;
|
||||
VtIntArray _curveVertexCounts;
|
||||
VtIntArray _curveIndices;
|
||||
VtIntArray _invisiblePoints;
|
||||
VtIntArray _invisibleCurves;
|
||||
size_t _numPoints;
|
||||
};
|
||||
|
||||
HD_API
|
||||
std::ostream& operator << (std::ostream &out, HdBasisCurvesTopology const &topo);
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_BASIS_CURVES_TOPOLOGY_H
|
||||
@@ -0,0 +1,143 @@
|
||||
//
|
||||
// Copyright 2021 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// This file is generated by a script. Do not edit directly. Edit the
|
||||
// schema.template.h file to make changes.
|
||||
|
||||
#ifndef PXR_IMAGING_HD_BASIS_CURVES_TOPOLOGY_SCHEMA_H
|
||||
#define PXR_IMAGING_HD_BASIS_CURVES_TOPOLOGY_SCHEMA_H
|
||||
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
|
||||
#include "pxr/imaging/hd/schema.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define HDBASISCURVESTOPOLOGY_SCHEMA_TOKENS \
|
||||
(topology) \
|
||||
(curveVertexCounts) \
|
||||
(curveIndices) \
|
||||
(basis) \
|
||||
(type) \
|
||||
(wrap) \
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdBasisCurvesTopologySchemaTokens, HD_API,
|
||||
HDBASISCURVESTOPOLOGY_SCHEMA_TOKENS);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class HdBasisCurvesTopologySchema : public HdSchema
|
||||
{
|
||||
public:
|
||||
HdBasisCurvesTopologySchema(HdContainerDataSourceHandle container)
|
||||
: HdSchema(container) {}
|
||||
|
||||
//ACCESSORS
|
||||
|
||||
HD_API
|
||||
HdIntArrayDataSourceHandle GetCurveVertexCounts();
|
||||
HD_API
|
||||
HdIntArrayDataSourceHandle GetCurveIndices();
|
||||
HD_API
|
||||
HdTokenDataSourceHandle GetBasis();
|
||||
HD_API
|
||||
HdTokenDataSourceHandle GetType();
|
||||
HD_API
|
||||
HdTokenDataSourceHandle GetWrap();
|
||||
|
||||
// RETRIEVING AND CONSTRUCTING
|
||||
|
||||
/// 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 HdIntArrayDataSourceHandle &curveVertexCounts,
|
||||
const HdIntArrayDataSourceHandle &curveIndices,
|
||||
const HdTokenDataSourceHandle &basis,
|
||||
const HdTokenDataSourceHandle &type,
|
||||
const HdTokenDataSourceHandle &wrap
|
||||
);
|
||||
|
||||
/// \class HdBasisCurvesTopologySchema::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 &SetCurveVertexCounts(
|
||||
const HdIntArrayDataSourceHandle &curveVertexCounts);
|
||||
HD_API
|
||||
Builder &SetCurveIndices(
|
||||
const HdIntArrayDataSourceHandle &curveIndices);
|
||||
HD_API
|
||||
Builder &SetBasis(
|
||||
const HdTokenDataSourceHandle &basis);
|
||||
HD_API
|
||||
Builder &SetType(
|
||||
const HdTokenDataSourceHandle &type);
|
||||
HD_API
|
||||
Builder &SetWrap(
|
||||
const HdTokenDataSourceHandle &wrap);
|
||||
|
||||
/// Returns a container data source containing the members set thus far.
|
||||
HD_API
|
||||
HdContainerDataSourceHandle Build();
|
||||
|
||||
private:
|
||||
HdIntArrayDataSourceHandle _curveVertexCounts;
|
||||
HdIntArrayDataSourceHandle _curveIndices;
|
||||
HdTokenDataSourceHandle _basis;
|
||||
HdTokenDataSourceHandle _type;
|
||||
HdTokenDataSourceHandle _wrap;
|
||||
};
|
||||
|
||||
/// Retrieves a container data source with the schema's default name token
|
||||
/// "topology" from the parent container and constructs a
|
||||
/// HdBasisCurvesTopologySchema 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 HdBasisCurvesTopologySchema GetFromParent(
|
||||
const HdContainerDataSourceHandle &fromParentContainer);
|
||||
|
||||
/// 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();
|
||||
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,303 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_BINDING_H
|
||||
#define PXR_IMAGING_HD_BINDING_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/types.h"
|
||||
|
||||
#include "pxr/imaging/hd/bufferResource.h"
|
||||
#include "pxr/imaging/hd/bufferArrayRange.h"
|
||||
|
||||
#include "pxr/base/tf/hash.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
typedef std::vector<class HdBinding> HdBindingVector;
|
||||
typedef std::vector<class HdBindingRequest> HdBindingRequestVector;
|
||||
|
||||
/// \class HdBinding
|
||||
///
|
||||
/// Bindings are used for buffers or textures, it simple associates a binding
|
||||
/// type with a binding location.
|
||||
///
|
||||
class HdBinding {
|
||||
public:
|
||||
enum Type { // primvar, drawing coordinate and dispatch buffer bindings
|
||||
// also shader fallback values
|
||||
UNKNOWN,
|
||||
DISPATCH, // GL_DRAW_INDIRECT_BUFFER
|
||||
DRAW_INDEX, // per-drawcall. not instanced
|
||||
DRAW_INDEX_INSTANCE, // per-drawcall. attribdivisor=on
|
||||
DRAW_INDEX_INSTANCE_ARRAY, // per-drawcall. attribdivisor=on, array
|
||||
VERTEX_ATTR, // vertex-attribute
|
||||
INDEX_ATTR, // GL_ELEMENT_ARRAY_BUFFER
|
||||
SSBO, //
|
||||
BINDLESS_SSBO_RANGE, //
|
||||
UBO, //
|
||||
BINDLESS_UNIFORM, //
|
||||
UNIFORM, //
|
||||
UNIFORM_ARRAY, //
|
||||
|
||||
// shader parameter bindings
|
||||
FALLBACK, // fallback value
|
||||
TEXTURE_2D, // non-bindless uv texture
|
||||
TEXTURE_FIELD, // non-bindless field texture
|
||||
// creates accessor that samples uvw
|
||||
// texture after transforming coordinates
|
||||
// by a sampling transform
|
||||
TEXTURE_UDIM_ARRAY, // non-bindless udim texture array
|
||||
TEXTURE_UDIM_LAYOUT, // non-bindless udim layout
|
||||
TEXTURE_PTEX_TEXEL, // non-bindless ptex texels
|
||||
TEXTURE_PTEX_LAYOUT, // non-bindless ptex layout
|
||||
BINDLESS_TEXTURE_2D, // bindless uv texture
|
||||
BINDLESS_TEXTURE_FIELD, // bindless field texture
|
||||
// (see above)
|
||||
BINDLESS_TEXTURE_UDIM_ARRAY, // bindless uv texture array
|
||||
BINDLESS_TEXTURE_UDIM_LAYOUT, // bindless udim layout
|
||||
BINDLESS_TEXTURE_PTEX_TEXEL, // bindless ptex texels
|
||||
BINDLESS_TEXTURE_PTEX_LAYOUT, // bindless ptex layout
|
||||
PRIMVAR_REDIRECT, // primvar redirection
|
||||
FIELD_REDIRECT, // accesses a field texture by name and
|
||||
// uses fallbackValue if no accessor for
|
||||
// the texture exists.
|
||||
TRANSFORM_2D // transform2d
|
||||
};
|
||||
enum Location {
|
||||
// NOT_EXIST is a special value of location for a uniform
|
||||
// which is assigned but optimized out after linking program.
|
||||
NOT_EXIST = 0xffff
|
||||
};
|
||||
HdBinding() : _typeAndLocation(-1) { }
|
||||
HdBinding(Type type, int location, int textureUnit=0) {
|
||||
Set(type, location, textureUnit);
|
||||
}
|
||||
void Set(Type type, int location, int textureUnit) {
|
||||
_typeAndLocation = (textureUnit << 24)|(location << 8)|(int)(type);
|
||||
}
|
||||
bool IsValid() const { return _typeAndLocation >= 0; }
|
||||
Type GetType() const { return (Type)(_typeAndLocation & 0xff); }
|
||||
int GetLocation() const { return (_typeAndLocation >> 8) & 0xffff; }
|
||||
int GetTextureUnit() const { return (_typeAndLocation >> 24) & 0xff; }
|
||||
int GetValue() const { return _typeAndLocation; }
|
||||
bool operator < (HdBinding const &b) const {
|
||||
return (_typeAndLocation < b._typeAndLocation);
|
||||
}
|
||||
private:
|
||||
int _typeAndLocation;
|
||||
};
|
||||
|
||||
/// BindingRequest allows externally allocated buffers to be bound at render
|
||||
/// time. The different modes of binding discussed below allow the caller a
|
||||
/// range of opt-in binding behaviors, from simply reserving a binding location
|
||||
/// so it can be managed from client code, to fully generating buffer accessor
|
||||
/// code at compile time (i.e. when using a BufferArrayRange or BufferResource).
|
||||
///
|
||||
/// This is a "request" because the caller makes a request before bindings are
|
||||
/// resolved. All requests are consulted and fulfilled during binding
|
||||
/// resolution.
|
||||
class HdBindingRequest {
|
||||
public:
|
||||
|
||||
HdBindingRequest() = default;
|
||||
|
||||
/// A data binding, not backed by neither BufferArrayRange nor
|
||||
/// BufferResource. This binding request simply
|
||||
/// generates named metadata (#define HD_HAS_foo 1, #define HD_foo_Binding)
|
||||
HdBindingRequest(HdBinding::Type bindingType, TfToken const& name)
|
||||
: _bindingType(bindingType)
|
||||
, _dataType(HdTypeInvalid)
|
||||
, _name(name)
|
||||
, _resource(nullptr)
|
||||
, _bar(nullptr)
|
||||
, _isInterleaved(false)
|
||||
{}
|
||||
|
||||
/// A data binding, not backed by neither BufferArrayRange nor
|
||||
/// BufferResource.
|
||||
HdBindingRequest(HdBinding::Type bindingType, TfToken const& name,
|
||||
HdType dataType)
|
||||
: _bindingType(bindingType)
|
||||
, _dataType(dataType)
|
||||
, _name(name)
|
||||
, _resource(nullptr)
|
||||
, _bar(nullptr)
|
||||
, _isInterleaved(false)
|
||||
{}
|
||||
|
||||
/// A buffer resource binding. Binds a given buffer resource to a specified
|
||||
/// name. The data type is set from the resource.
|
||||
HdBindingRequest(HdBinding::Type bindingType, TfToken const& name,
|
||||
HdBufferResourceSharedPtr const& resource)
|
||||
: _bindingType(bindingType)
|
||||
, _dataType(resource->GetTupleType().type)
|
||||
, _name(name)
|
||||
, _resource(resource)
|
||||
, _bar(nullptr)
|
||||
, _isInterleaved(false)
|
||||
{}
|
||||
|
||||
/// A named struct binding. From an interleaved BufferArray, an array of
|
||||
/// structs will be generated, consuming a single binding point. Note that
|
||||
/// all resources in the buffer array must have the same underlying
|
||||
/// identifier, hence must be interleaved and bindable as a single resource.
|
||||
/// Data types can be derived from each HdBufferResource of bar.
|
||||
HdBindingRequest(HdBinding::Type type, TfToken const& name,
|
||||
HdBufferArrayRangeSharedPtr bar,
|
||||
bool interleave)
|
||||
: _bindingType(type)
|
||||
, _dataType(HdTypeInvalid)
|
||||
, _name(name)
|
||||
, _resource(nullptr)
|
||||
, _bar(bar)
|
||||
, _isInterleaved(interleave)
|
||||
{}
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Discriminators
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Resource bingings have a single associated Hydra resource, but no buffer
|
||||
/// array.
|
||||
bool IsResource() const {
|
||||
return bool(_resource);
|
||||
}
|
||||
|
||||
/// A buffer array binding has several buffers bundled together and each
|
||||
/// buffer will be bound individually and exposed as independent arrays in
|
||||
/// the shader.
|
||||
bool IsBufferArray() const {
|
||||
return _bar && !_isInterleaved;
|
||||
}
|
||||
|
||||
/// Like BufferArray binding requests, struct bindings have several buffers,
|
||||
/// however they must be allocated into a single resource and interleaved.
|
||||
/// This type of binding request is exposed in the shader an array of
|
||||
/// structs.
|
||||
bool IsInterleavedBufferArray() const {
|
||||
return _bar && _isInterleaved;
|
||||
}
|
||||
|
||||
/// This binding is typelss. CodeGen only allocate location and
|
||||
/// skip emitting declarations and accessors.
|
||||
bool IsTypeless() const {
|
||||
return (!_bar) && (!_resource) && (_dataType == HdTypeInvalid);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Accessors
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Returns the name of the binding point, if any; buffer arrays and structs
|
||||
/// need not be named.
|
||||
TfToken const& GetName() const {
|
||||
return _name;
|
||||
}
|
||||
/// Returns the HdBinding type of this request.
|
||||
HdBinding::Type GetBindingType() const {
|
||||
return _bindingType;
|
||||
}
|
||||
/// Returns the single resource associated with this binding request or
|
||||
/// null when IsResource() returns false.
|
||||
HdBufferResourceSharedPtr const& GetResource() const {
|
||||
return _resource;
|
||||
}
|
||||
/// Returns the resource or buffer array range offset, defaults to zero.
|
||||
int GetByteOffset() const {
|
||||
// buffer resource binding
|
||||
if (_resource) return _resource->GetOffset();
|
||||
|
||||
// named struct binding (interleaved) - the resource name doesn't matter
|
||||
// since a single binding point is used.
|
||||
if (_bar) return _bar->GetByteOffset(TfToken());
|
||||
return 0;
|
||||
}
|
||||
/// Returns the buffer array range associated with this binding request or
|
||||
/// null when IsBufferArrqay() returns false.
|
||||
HdBufferArrayRangeSharedPtr const& GetBar() const {
|
||||
return _bar;
|
||||
}
|
||||
|
||||
/// Return the data type of this request
|
||||
HdType GetDataType() const {
|
||||
return _dataType;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Comparison
|
||||
// ---------------------------------------------------------------------- //
|
||||
HD_API
|
||||
bool operator==(HdBindingRequest const &other) const;
|
||||
|
||||
HD_API
|
||||
bool operator!=(HdBindingRequest const &other) const;
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Hash
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Returns the hash corresponding to this buffer request.
|
||||
///
|
||||
/// Note that this hash captures the structural state of the request, not
|
||||
/// the contents. For example, buffer array versions/reallocations will not
|
||||
/// affect hash, but changing the BAR pointer will.
|
||||
HD_API
|
||||
size_t ComputeHash() const;
|
||||
|
||||
// TfHash support.
|
||||
template <class HashState>
|
||||
friend void TfHashAppend(HashState &h, HdBindingRequest const &br) {
|
||||
h.Append(br._name,
|
||||
br._bindingType,
|
||||
br._dataType,
|
||||
br._isInterleaved);
|
||||
}
|
||||
|
||||
private:
|
||||
// This class unfortunately represents several concepts packed into a single
|
||||
// class. Ideally, we would break this out as one class per concept,
|
||||
// however that would also require virtual dispatch, which is overkill for
|
||||
// the current use cases.
|
||||
|
||||
// Named binding request
|
||||
HdBinding::Type _bindingType;
|
||||
HdType _dataType;
|
||||
TfToken _name;
|
||||
|
||||
// Resource binding request
|
||||
HdBufferResourceSharedPtr _resource;
|
||||
|
||||
// Struct binding request
|
||||
HdBufferArrayRangeSharedPtr _bar;
|
||||
bool _isInterleaved;
|
||||
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_BINDING_H
|
||||
@@ -0,0 +1,97 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_BPRIM_H
|
||||
#define PXR_IMAGING_HD_BPRIM_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/types.h"
|
||||
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdSceneDelegate;
|
||||
class HdRenderParam;
|
||||
|
||||
/// \class HdBprim
|
||||
///
|
||||
/// Bprim (buffer prim) is a base class of managing a blob of data that is
|
||||
/// used to communicate between the scene delegate and render.
|
||||
///
|
||||
/// Like other prim types (Rprim and Sprim), the Bprim communicates with the
|
||||
/// scene delegate got get buffer properties (e.g. the size of the buffer) as
|
||||
/// well as the contents of the buffer.
|
||||
///
|
||||
/// Changes to the properties and contents are change tracked and updates
|
||||
/// are cached in the renderer. The Render Delegate may choose to transform
|
||||
/// the data into a renderer specific form on download.
|
||||
///
|
||||
/// BPrims are sync'ed first and thus, Bprims should not be
|
||||
/// Dependent on the state of any other prim.
|
||||
///
|
||||
/// The most typical use of a Bprim would be a Texture.
|
||||
class HdBprim {
|
||||
public:
|
||||
HD_API
|
||||
HdBprim(SdfPath const & id);
|
||||
HD_API
|
||||
virtual ~HdBprim();
|
||||
|
||||
/// Returns the identifier by which this buffer is known. This
|
||||
/// identifier is a common associative key used by the SceneDelegate,
|
||||
/// RenderIndex, and for binding to the buffer
|
||||
SdfPath const& GetId() const { return _id; }
|
||||
|
||||
/// Synchronizes state from the delegate to this object.
|
||||
/// @param[in, out] dirtyBits: On input specifies which state is
|
||||
/// is dirty and can be pulled from the scene
|
||||
/// delegate.
|
||||
/// On output specifies which bits are still
|
||||
/// dirty and were not cleaned by the sync.
|
||||
///
|
||||
virtual void Sync(HdSceneDelegate *sceneDelegate,
|
||||
HdRenderParam *renderParam,
|
||||
HdDirtyBits *dirtyBits) = 0;
|
||||
|
||||
/// Finalizes object resources. This function might not delete resources,
|
||||
/// but it should deal with resource ownership so that the sprim is
|
||||
/// deletable.
|
||||
HD_API
|
||||
virtual void Finalize(HdRenderParam *renderParam);
|
||||
|
||||
/// Returns the minimal set of dirty bits to place in the
|
||||
/// change tracker for use in the first sync of this prim.
|
||||
/// Typically this would be all dirty bits.
|
||||
virtual HdDirtyBits GetInitialDirtyBitsMask() const = 0;
|
||||
|
||||
private:
|
||||
SdfPath _id;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_BPRIM_H
|
||||
@@ -0,0 +1,207 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_BUFFER_ARRAY_H
|
||||
#define PXR_IMAGING_HD_BUFFER_ARRAY_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/bufferSpec.h"
|
||||
#include "pxr/imaging/hd/bufferResource.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
#include "pxr/base/vt/value.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
class HdBufferArrayRange;
|
||||
|
||||
using HdBufferArraySharedPtr = std::shared_ptr<class HdBufferArray>;
|
||||
using HdBufferArrayRangeSharedPtr = std::shared_ptr<HdBufferArrayRange>;
|
||||
using HdBufferArrayRangePtr = std::weak_ptr<HdBufferArrayRange>;
|
||||
|
||||
/// \union HdBufferArrayUsageHint
|
||||
///
|
||||
/// The union provides a set of flags that provide hints to the memory
|
||||
/// management system about the properties of a Buffer Array Range (BAR),
|
||||
/// so it can efficiently organize that memory. For example,
|
||||
/// the memory manager should probably not aggregate BARs with different
|
||||
/// usage hints.
|
||||
///
|
||||
/// The union provides two members:
|
||||
/// - value: The combined set of flags
|
||||
/// - bits: Access to individual flag bits
|
||||
///
|
||||
/// The flag bits are:
|
||||
/// - immutable: The BAR will not be modified once created and populated.
|
||||
/// - sizeVarying: The number of elements in the BAR changes with time.
|
||||
///
|
||||
/// Some flag bits may not make sense in combination
|
||||
/// (i.e. mutually exclusive to each other). For example, it is logically
|
||||
/// impossible to be both immutable (i.e. not changing) and sizeVarying
|
||||
/// (changing). However, these logically impossible combinations are
|
||||
/// not enforced and remain valid potential values.
|
||||
///
|
||||
union HdBufferArrayUsageHint {
|
||||
struct _Bits {
|
||||
uint32_t immutable : 1;
|
||||
uint32_t sizeVarying : 1;
|
||||
uint32_t pad : 30;
|
||||
} bits;
|
||||
uint32_t value;
|
||||
|
||||
HdBufferArrayUsageHint() : value(0) {}
|
||||
};
|
||||
|
||||
|
||||
/// \class HdBufferArray
|
||||
///
|
||||
/// Similar to a VAO, this object is a bundle of coherent buffers. This object
|
||||
/// can be shared across multiple HdRprims, in the context of buffer
|
||||
/// aggregation.
|
||||
///
|
||||
class HdBufferArray : public std::enable_shared_from_this<HdBufferArray>
|
||||
{
|
||||
public:
|
||||
HD_API
|
||||
HdBufferArray(TfToken const &role,
|
||||
TfToken const garbageCollectionPerfToken,
|
||||
HdBufferArrayUsageHint usageHint);
|
||||
|
||||
HD_API
|
||||
virtual ~HdBufferArray();
|
||||
|
||||
/// Returns the role of the GPU data in this bufferArray.
|
||||
TfToken const& GetRole() const {return _role;}
|
||||
|
||||
/// Returns the version of this buffer array.
|
||||
/// Used to determine when to rebuild outdated indirect dispatch buffers
|
||||
size_t GetVersion() const {
|
||||
return _version;
|
||||
}
|
||||
|
||||
/// Increments the version of this buffer array.
|
||||
HD_API
|
||||
void IncrementVersion();
|
||||
|
||||
/// Attempts to assign a range to this buffer array.
|
||||
/// Multiple threads could be trying to assign to this buffer at the same time.
|
||||
/// Returns true is the range is assigned to this buffer otherwise
|
||||
/// returns false if the buffer doesn't have space to assign the range.
|
||||
HD_API
|
||||
bool TryAssignRange(HdBufferArrayRangeSharedPtr &range);
|
||||
|
||||
/// Performs compaction if necessary and returns true if it becomes empty.
|
||||
virtual bool GarbageCollect() = 0;
|
||||
|
||||
/// Performs reallocation. After reallocation, the buffer will contain
|
||||
/// the specified \a ranges. If these ranges are currently held by a
|
||||
/// different buffer array instance, then their data will be copied
|
||||
/// from the specified \a curRangeOwner.
|
||||
virtual void Reallocate(
|
||||
std::vector<HdBufferArrayRangeSharedPtr> const &ranges,
|
||||
HdBufferArraySharedPtr const &curRangeOwner) = 0;
|
||||
|
||||
/// Returns the maximum number of elements capacity.
|
||||
HD_API
|
||||
virtual size_t GetMaxNumElements() const;
|
||||
|
||||
/// Debug output
|
||||
virtual void DebugDump(std::ostream &out) const = 0;
|
||||
|
||||
/// How many ranges are attached to the buffer array.
|
||||
size_t GetRangeCount() const { return _rangeCount; }
|
||||
|
||||
/// Get the attached range at the specified index.
|
||||
HD_API
|
||||
HdBufferArrayRangePtr GetRange(size_t idx) const;
|
||||
|
||||
/// Remove any ranges from the range list that have been deallocated
|
||||
/// Returns number of ranges after clean-up
|
||||
HD_API
|
||||
void RemoveUnusedRanges();
|
||||
|
||||
/// Returns true if Reallocate() needs to be called on this buffer array.
|
||||
bool NeedsReallocation() const {
|
||||
return _needsReallocation;
|
||||
}
|
||||
|
||||
/// Returns true if this buffer array is marked as immutable.
|
||||
bool IsImmutable() const {
|
||||
return _usageHint.bits.immutable;
|
||||
}
|
||||
|
||||
/// Returns the usage hints for this buffer array.
|
||||
HdBufferArrayUsageHint GetUsageHint() const {
|
||||
return _usageHint;
|
||||
}
|
||||
|
||||
protected:
|
||||
/// Dirty bit to set when the ranges attached to the buffer
|
||||
/// changes. If set Reallocate() should be called to clean it.
|
||||
bool _needsReallocation;
|
||||
|
||||
/// Limits the number of ranges that can be
|
||||
/// allocated to this buffer to max.
|
||||
void _SetMaxNumRanges(size_t max) { _maxNumRanges = max; }
|
||||
|
||||
/// Swap the rangelist with \p ranges
|
||||
HD_API
|
||||
void _SetRangeList(std::vector<HdBufferArrayRangeSharedPtr> const &ranges);
|
||||
|
||||
private:
|
||||
|
||||
// Do not allow copies.
|
||||
HdBufferArray(const HdBufferArray &) = delete;
|
||||
HdBufferArray &operator=(const HdBufferArray &) = delete;
|
||||
|
||||
|
||||
typedef std::vector<HdBufferArrayRangePtr> _RangeList;
|
||||
|
||||
// Vector of ranges associated with this buffer
|
||||
// We add values to the list in a multi-threaded fashion
|
||||
// but can later remove them in _RemoveUnusedRanges
|
||||
// than add more.
|
||||
//
|
||||
_RangeList _rangeList;
|
||||
std::atomic_size_t _rangeCount; // how many ranges are valid in list
|
||||
std::mutex _rangeListLock;
|
||||
|
||||
const TfToken _role;
|
||||
const TfToken _garbageCollectionPerfToken;
|
||||
|
||||
size_t _version;
|
||||
|
||||
size_t _maxNumRanges;
|
||||
HdBufferArrayUsageHint _usageHint;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif //PXR_IMAGING_HD_BUFFER_ARRAY_H
|
||||
@@ -0,0 +1,172 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_BUFFER_ARRAY_RANGE_H
|
||||
#define PXR_IMAGING_HD_BUFFER_ARRAY_RANGE_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
#include "pxr/base/vt/value.h"
|
||||
#include "pxr/imaging/hd/bufferArray.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
using HdBufferSpecVector = std::vector<struct HdBufferSpec>;
|
||||
using HdBufferArrayRangeSharedPtr = std::shared_ptr<class HdBufferArrayRange>;
|
||||
using HdBufferSourceSharedPtr = std::shared_ptr<class HdBufferSource>;
|
||||
|
||||
/// \class HdBufferArrayRange
|
||||
///
|
||||
/// Interface class for representing range (subset) locator of HdBufferArray.
|
||||
///
|
||||
/// Each memory management strategy defines a specialized range class which is
|
||||
/// inherited of this interface so that client (drawItem) can be agnostic about
|
||||
/// the implementation detail of aggregation.
|
||||
///
|
||||
class HdBufferArrayRange
|
||||
{
|
||||
public:
|
||||
|
||||
HD_API
|
||||
HdBufferArrayRange();
|
||||
|
||||
/// Destructor (do nothing).
|
||||
/// The specialized range class may want to do something for garbage
|
||||
/// collection in its destructor. However, be careful not do any
|
||||
/// substantial work here (obviously including any kind of GL calls),
|
||||
/// since the destructor gets called frequently on various contexts.
|
||||
HD_API
|
||||
virtual ~HdBufferArrayRange();
|
||||
|
||||
/// Returns true if this range is valid
|
||||
virtual bool IsValid() const = 0;
|
||||
|
||||
/// Returns true is the range has been assigned to a buffer
|
||||
virtual bool IsAssigned() const = 0;
|
||||
|
||||
/// Returns true if this range is marked as immutable.
|
||||
virtual bool IsImmutable() const = 0;
|
||||
|
||||
/// Returns true if this needs a staging buffer for CPU to GPU copies.
|
||||
virtual bool RequiresStaging() const = 0;
|
||||
|
||||
/// Resize memory area for this range. Returns true if it causes container
|
||||
/// buffer reallocation.
|
||||
virtual bool Resize(int numElements) = 0;
|
||||
|
||||
/// Copy source data into buffer
|
||||
virtual void CopyData(HdBufferSourceSharedPtr const &bufferSource) = 0;
|
||||
|
||||
/// Read back the buffer content
|
||||
virtual VtValue ReadData(TfToken const &name) const = 0;
|
||||
|
||||
/// Returns the offset at which this range begins in the underlying buffer
|
||||
/// array in terms of elements.
|
||||
virtual int GetElementOffset() const = 0;
|
||||
|
||||
/// Returns the byte offset at which this range begins in the underlying
|
||||
/// buffer array for the given resource.
|
||||
virtual int GetByteOffset(TfToken const& resourceName) const = 0;
|
||||
|
||||
/// Returns the number of elements
|
||||
virtual size_t GetNumElements() const = 0;
|
||||
|
||||
/// Returns the version of the buffer array.
|
||||
virtual size_t GetVersion() const = 0;
|
||||
|
||||
/// Increment the version of the buffer array. mostly used for notifying
|
||||
/// drawbatches to be rebuilt to remove expired BufferArrayRange.
|
||||
virtual void IncrementVersion() = 0;
|
||||
|
||||
/// Returns the max number of elements
|
||||
virtual size_t GetMaxNumElements() const = 0;
|
||||
|
||||
/// Gets the usage hint on the underlying buffer array
|
||||
virtual HdBufferArrayUsageHint GetUsageHint() const = 0;
|
||||
|
||||
/// Sets the buffer array associated with this buffer;
|
||||
virtual void SetBufferArray(HdBufferArray *bufferArray) = 0;
|
||||
|
||||
/// Debug output
|
||||
virtual void DebugDump(std::ostream &out) const = 0;
|
||||
|
||||
/// Returns true if the underlying buffer array is aggregated to other's
|
||||
bool IsAggregatedWith(HdBufferArrayRangeSharedPtr const &other) const {
|
||||
return (other && (_GetAggregation() == other->_GetAggregation()));
|
||||
}
|
||||
|
||||
/// Gets the bufferSpecs for all resources.
|
||||
virtual void GetBufferSpecs(HdBufferSpecVector *bufferSpecs) const = 0;
|
||||
|
||||
protected:
|
||||
/// Returns the aggregation container to be used in IsAggregatedWith()
|
||||
virtual const void *_GetAggregation() const = 0;
|
||||
|
||||
// Don't allow copies
|
||||
HdBufferArrayRange(const HdBufferArrayRange &) = delete;
|
||||
HdBufferArrayRange &operator=(const HdBufferArrayRange &) = delete;
|
||||
|
||||
};
|
||||
|
||||
HD_API
|
||||
std::ostream &operator <<(std::ostream &out,
|
||||
const HdBufferArrayRange &self);
|
||||
|
||||
/// \class HdBufferArrayRangeContainer
|
||||
///
|
||||
/// A resizable container of HdBufferArrayRanges.
|
||||
///
|
||||
class HdBufferArrayRangeContainer
|
||||
{
|
||||
public:
|
||||
/// Constructor
|
||||
HdBufferArrayRangeContainer(int size) : _ranges(size) { }
|
||||
|
||||
/// Set \p range into the container at \p index.
|
||||
/// If the size of container is smaller than index, resize it.
|
||||
HD_API
|
||||
void Set(int index, HdBufferArrayRangeSharedPtr const &range);
|
||||
|
||||
/// Returns the bar at \p index. returns null if either the index
|
||||
/// is out of range or not yet set.
|
||||
HD_API
|
||||
HdBufferArrayRangeSharedPtr const &Get(int index) const;
|
||||
|
||||
/// Resize the buffer array range container to size \p size.
|
||||
/// Used to explicitly resize or shrink the container.
|
||||
HD_API
|
||||
void Resize(int size);
|
||||
|
||||
private:
|
||||
std::vector<HdBufferArrayRangeSharedPtr> _ranges;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_BUFFER_ARRAY_RANGE_H
|
||||
@@ -0,0 +1,161 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_BUFFER_ARRAY_REGISTRY_H
|
||||
#define PXR_IMAGING_HD_BUFFER_ARRAY_REGISTRY_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
|
||||
#include "pxr/imaging/hd/bufferArrayRange.h"
|
||||
#include "pxr/imaging/hd/bufferSpec.h"
|
||||
#include "pxr/imaging/hd/perfLog.h"
|
||||
#include "pxr/imaging/hd/strategyBase.h"
|
||||
|
||||
#include "pxr/imaging/hf/perfLog.h"
|
||||
|
||||
#include "pxr/base/vt/dictionary.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
|
||||
#include <tbb/concurrent_unordered_map.h>
|
||||
|
||||
#include <condition_variable>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
using HdBufferArraySharedPtr = std::shared_ptr<class HdBufferArray>;
|
||||
|
||||
/// \class HdBufferArrayRegistry
|
||||
///
|
||||
/// Manages the pool of buffer arrays.
|
||||
///
|
||||
class HdBufferArrayRegistry
|
||||
{
|
||||
public:
|
||||
HF_MALLOC_TAG_NEW("new HdBufferArrayRegistry");
|
||||
|
||||
HD_API
|
||||
HdBufferArrayRegistry();
|
||||
~HdBufferArrayRegistry() = default;
|
||||
|
||||
/// Allocate new buffer array range using strategy
|
||||
/// Thread-Safe
|
||||
HD_API
|
||||
HdBufferArrayRangeSharedPtr AllocateRange(
|
||||
HdAggregationStrategy *strategy,
|
||||
TfToken const &role,
|
||||
HdBufferSpecVector const &bufferSpecs,
|
||||
HdBufferArrayUsageHint usageHint);
|
||||
|
||||
/// Triggers reallocation on all buffers managed by the registry.
|
||||
HD_API
|
||||
void ReallocateAll(HdAggregationStrategy *strategy);
|
||||
|
||||
/// Frees up buffers that no longer contain any allocated ranges.
|
||||
HD_API
|
||||
void GarbageCollect();
|
||||
|
||||
/// Generate a report on resources consumed by the managed
|
||||
/// buffer array. The returned size is an esitmate of the
|
||||
/// gpu memory consumed by the buffers
|
||||
HD_API
|
||||
size_t GetResourceAllocation(HdAggregationStrategy *strategy,
|
||||
VtDictionary &result) const;
|
||||
|
||||
/// Debug dump
|
||||
HD_API
|
||||
friend std::ostream &operator <<(std::ostream &out,
|
||||
const HdBufferArrayRegistry& self);
|
||||
|
||||
private:
|
||||
|
||||
HdBufferArrayRegistry(const HdBufferArrayRegistry &) = delete;
|
||||
HdBufferArrayRegistry &operator=(const HdBufferArrayRegistry &) = delete;
|
||||
|
||||
typedef std::list<HdBufferArraySharedPtr> _HdBufferArraySharedPtrList;
|
||||
|
||||
/// \struct _Entry
|
||||
///
|
||||
/// Entry in the buffer array cache. The list is the buffer arrays which
|
||||
/// all have the same format. There is as a lock for modifications to the
|
||||
/// entry and a condition used to determine if the entry has been
|
||||
/// construction.
|
||||
///
|
||||
/// A constructed entry always has at least 1 buffer array in its list.
|
||||
///
|
||||
struct _Entry
|
||||
{
|
||||
_HdBufferArraySharedPtrList bufferArrays;
|
||||
std::mutex lock;
|
||||
std::condition_variable emptyCondition;
|
||||
|
||||
// Default / Copy constructors needed for std::make_pair.
|
||||
// as the version of TBB doesn't have emplace() yet.
|
||||
_Entry() {}
|
||||
_Entry(const _Entry &other) { TF_VERIFY(bufferArrays.empty()); }
|
||||
};
|
||||
|
||||
|
||||
/// Predicate class for determine if an entry
|
||||
/// has been consturcted (determined by there
|
||||
/// being at least 1 entry in the buffer array list.
|
||||
class _EntryIsNotEmpty
|
||||
{
|
||||
public:
|
||||
_EntryIsNotEmpty(const _Entry &entry) : _entry(entry) {}
|
||||
|
||||
bool operator()() {
|
||||
return (!(_entry.bufferArrays.empty()));
|
||||
}
|
||||
|
||||
private:
|
||||
const _Entry &_entry;
|
||||
};
|
||||
|
||||
typedef tbb::concurrent_unordered_map< HdAggregationStrategy::AggregationId, _Entry> _BufferArrayIndex;
|
||||
|
||||
_BufferArrayIndex _entries;
|
||||
|
||||
/// Concurrently adds a new buffer to an entry in the cache.
|
||||
/// If expectedTail differs from the buffer at the end of the
|
||||
/// entries list after locking, then this function fails and
|
||||
/// does not add a new buffer (because another thread beat it
|
||||
/// to it).
|
||||
/// strategy is the factory class used to create the BufferArray.
|
||||
/// role and bufferSpecs are parameters to the BufferArray creation.
|
||||
void _InsertNewBufferArray(_Entry &entry,
|
||||
const HdBufferArraySharedPtr &expectedTail,
|
||||
HdAggregationStrategy *strategy,
|
||||
TfToken const &role,
|
||||
HdBufferSpecVector const &bufferSpecs,
|
||||
HdBufferArrayUsageHint usageHint);
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_BUFFER_ARRAY_REGISTRY_H
|
||||
@@ -0,0 +1,81 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_BUFFER_RESOURCE_H
|
||||
#define PXR_IMAGING_HD_BUFFER_RESOURCE_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/resource.h"
|
||||
#include "pxr/imaging/hd/types.h"
|
||||
|
||||
#include "pxr/base/tf/token.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
class HdBufferResource;
|
||||
|
||||
using HdBufferResourceSharedPtr = std::shared_ptr<HdBufferResource>;
|
||||
using HdBufferResourceNamedList = std::vector<
|
||||
std::pair<TfToken, HdBufferResourceSharedPtr> >;
|
||||
|
||||
/// \class HdBufferResource
|
||||
///
|
||||
/// A specific type of HdResource (GPU resource) representing a buffer object.
|
||||
///
|
||||
class HdBufferResource : public HdResource {
|
||||
public:
|
||||
HD_API
|
||||
HdBufferResource(TfToken const &role,
|
||||
HdTupleType tupleType,
|
||||
int offset,
|
||||
int stride);
|
||||
HD_API
|
||||
~HdBufferResource();
|
||||
|
||||
/// Data type and count
|
||||
HdTupleType GetTupleType() const { return _tupleType; }
|
||||
|
||||
/// Returns the interleaved offset (in bytes) of this data.
|
||||
int GetOffset() const {return _offset;}
|
||||
|
||||
/// Returns the stride (in bytes) of underlying buffer.
|
||||
int GetStride() const {return _stride;}
|
||||
|
||||
protected:
|
||||
HdTupleType _tupleType;
|
||||
int _offset;
|
||||
int _stride;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif //PXR_IMAGING_HD_BUFFER_RESOURCE_H
|
||||
@@ -0,0 +1,257 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_BUFFER_SOURCE_H
|
||||
#define PXR_IMAGING_HD_BUFFER_SOURCE_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/bufferSpec.h"
|
||||
#include "pxr/base/tf/diagnostic.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdBufferSource;
|
||||
using HdBufferSourceSharedPtr = std::shared_ptr<HdBufferSource>;
|
||||
using HdBufferSourceConstSharedPtr = std::shared_ptr<HdBufferSource const>;
|
||||
using HdBufferSourceSharedPtrVector = std::vector<HdBufferSourceSharedPtr>;
|
||||
using HdBufferSourceWeakPtr = std::weak_ptr<HdBufferSource>;
|
||||
|
||||
/// \class HdBufferSource
|
||||
///
|
||||
/// A transient buffer of data that has not yet been committed.
|
||||
///
|
||||
/// HdBufferSource is an abstract interface class, to be registered to the
|
||||
/// resource registry with the buffer array range that specifies the
|
||||
/// destination resource.
|
||||
///
|
||||
class HdBufferSource
|
||||
{
|
||||
public:
|
||||
HdBufferSource() : _state(UNRESOLVED) { }
|
||||
|
||||
HD_API
|
||||
virtual ~HdBufferSource();
|
||||
|
||||
/// Return the name of this buffer source.
|
||||
virtual TfToken const &GetName() const = 0;
|
||||
|
||||
/// Add the buffer spec for this buffer source into given bufferspec vector.
|
||||
/// note: buffer specs has to be determined before the source resolution.
|
||||
virtual void GetBufferSpecs(HdBufferSpecVector *specs) const = 0;
|
||||
|
||||
/// Computes and returns a hash value for the underlying data.
|
||||
HD_API
|
||||
virtual size_t ComputeHash() const;
|
||||
|
||||
/// Prepare the access of GetData(). This process may include some
|
||||
/// computations (e.g. cpu smooth normals).
|
||||
/// Note: Resolve may be called in parallel from multiple threads
|
||||
/// across buffer sources, so be careful if it uses static/shared
|
||||
/// states among objects.
|
||||
/// Returns true if it resolved. If the buffer source has to wait
|
||||
/// some results of other buffer sources, or the buffer source is
|
||||
/// being resolved by other threads, it returns false.
|
||||
virtual bool Resolve() = 0;
|
||||
|
||||
/// Following interfaces will be called after Resolve.
|
||||
|
||||
/// Returns the raw pointer to the underlying data.
|
||||
virtual void const* GetData() const = 0;
|
||||
|
||||
/// Returns the data type and count (array size) for this buffer source.
|
||||
virtual HdTupleType GetTupleType() const = 0;
|
||||
|
||||
/// Returns the number of elements (e.g. VtVec3dArray().GetLength()) from
|
||||
/// the source array.
|
||||
virtual size_t GetNumElements() const = 0;
|
||||
|
||||
/// Returns true it this computation has already been resolved.
|
||||
bool IsResolved() const {
|
||||
return _state >= RESOLVED;
|
||||
}
|
||||
|
||||
/// Returns true if an error occurred during resolve.
|
||||
bool HasResolveError() const {
|
||||
return _state == RESOLVE_ERROR;
|
||||
}
|
||||
|
||||
/// \name Chained Buffers
|
||||
/// Buffer sources may be daisy-chained together.
|
||||
///
|
||||
/// Pre-chained buffer sources typically represent sources that
|
||||
/// are inputs to computed buffer sources (e.g. coarse vertex
|
||||
/// privmar data needing to be quadrangulated or refined) and
|
||||
/// will be scheduled to be resolved along with their owning
|
||||
/// buffer sources.
|
||||
///
|
||||
/// Post-chained buffer sources typically represent additional
|
||||
/// results produced by a computation (e.g. primitive param data
|
||||
/// computed along with index buffer data) and will be scheduled
|
||||
/// to be committed along with their owning buffer sources.
|
||||
/// @{
|
||||
|
||||
/// Returns true if this buffer has a pre-chained buffer.
|
||||
HD_API
|
||||
virtual bool HasPreChainedBuffer() const;
|
||||
|
||||
/// Returns the pre-chained buffer.
|
||||
HD_API
|
||||
virtual HdBufferSourceSharedPtr GetPreChainedBuffer() const;
|
||||
|
||||
/// Returns true if this buffer has any chained buffer(s)
|
||||
HD_API
|
||||
virtual bool HasChainedBuffer() const;
|
||||
|
||||
/// Returns the vector of chained buffers.
|
||||
HD_API
|
||||
virtual HdBufferSourceSharedPtrVector GetChainedBuffers() const;
|
||||
|
||||
/// @}
|
||||
|
||||
/// Checks the validity of the source buffer.
|
||||
/// The function should be called to determine if
|
||||
/// AddBufferSpec() and Resolve() would return valid
|
||||
/// results.
|
||||
HD_API
|
||||
bool IsValid() const;
|
||||
|
||||
protected:
|
||||
/// Marks this buffer source as resolved. It has to be called
|
||||
/// at the end of Resolve on concrete implementations.
|
||||
void _SetResolved() {
|
||||
TF_VERIFY(_state == BEING_RESOLVED);
|
||||
_state = RESOLVED;
|
||||
}
|
||||
|
||||
/// Called during Resolve() to indicate an unrecoverable failure occurred
|
||||
/// and the results of the computation can not be used.
|
||||
/// Further calls to Resolve() will not lead to success.
|
||||
///
|
||||
/// This is different from Resolve() returning false, which indicates
|
||||
/// that additional calls to Resolve() will eventually lead to success.
|
||||
///
|
||||
/// This is also later in the pipeline than IsValid, which checks
|
||||
/// that the buffer is setup such that Resolve() can be successful.
|
||||
void _SetResolveError() {
|
||||
TF_VERIFY(_state == BEING_RESOLVED);
|
||||
_state = RESOLVE_ERROR;
|
||||
}
|
||||
|
||||
/// Non-blocking lock acquisition.
|
||||
/// If no one else is resolving this buffer source, returns true.
|
||||
/// In that case the caller needs to call _SetResolved at the end
|
||||
/// of computation.
|
||||
/// It returns false if anyone else has already acquired lock.
|
||||
bool _TryLock() {
|
||||
State oldState = UNRESOLVED;
|
||||
return _state.compare_exchange_strong(oldState, BEING_RESOLVED);
|
||||
}
|
||||
|
||||
/// Checks the validity of the source buffer.
|
||||
/// This function is called by IsValid() to do the real checking.
|
||||
///
|
||||
/// Should only be implemented in classes at leafs of the class hierarchy
|
||||
/// (Please place common validation code in a new non-virtual method)
|
||||
///
|
||||
/// This code should return false:
|
||||
/// - If the buffer would produce an invalid BufferSpec
|
||||
/// - If a required dependent buffer is invalid
|
||||
/// For example, return false when:
|
||||
/// The data type is invalid, causing an invalid BufferSpec.
|
||||
///
|
||||
/// The resolve step requires a 'source' buffer and that buffer is invalid.
|
||||
///
|
||||
/// If returning false, the buffer will not be registered with the resource
|
||||
/// registry. AddBufferSpec and Resolve will not be called
|
||||
virtual bool _CheckValid() const = 0;
|
||||
|
||||
private:
|
||||
// Don't allow copies
|
||||
HdBufferSource(const HdBufferSource &) = delete;
|
||||
HdBufferSource &operator=(const HdBufferSource &) = delete;
|
||||
|
||||
enum State { UNRESOLVED=0, BEING_RESOLVED, RESOLVED, RESOLVE_ERROR};
|
||||
std::atomic<State> _state;
|
||||
};
|
||||
|
||||
/// A abstract base class for cpu computation followed by buffer
|
||||
/// transfer to the GPU.
|
||||
///
|
||||
/// concrete class needs to implement
|
||||
/// virtual void GetBufferSpecs(HdBufferSpecVector *specs) const;
|
||||
/// virtual void Resolve();
|
||||
/// and set the result via _SetResult().
|
||||
///
|
||||
class HdComputedBufferSource : public HdBufferSource {
|
||||
public:
|
||||
HD_API
|
||||
virtual TfToken const &GetName() const override;
|
||||
HD_API
|
||||
virtual size_t ComputeHash() const override;
|
||||
HD_API
|
||||
virtual void const* GetData() const override;
|
||||
HD_API
|
||||
virtual HdTupleType GetTupleType() const override;
|
||||
HD_API
|
||||
virtual size_t GetNumElements() const override;
|
||||
|
||||
protected:
|
||||
void _SetResult(HdBufferSourceSharedPtr const &result) {
|
||||
_result = result;
|
||||
}
|
||||
|
||||
private:
|
||||
HdBufferSourceSharedPtr _result;
|
||||
};
|
||||
|
||||
/// A abstract base class for pure cpu computation.
|
||||
/// the result won't be scheduled for GPU transfer.
|
||||
///
|
||||
class HdNullBufferSource : public HdBufferSource {
|
||||
public:
|
||||
HD_API
|
||||
virtual TfToken const &GetName() const override;
|
||||
HD_API
|
||||
virtual void const* GetData() const override;
|
||||
HD_API
|
||||
virtual size_t ComputeHash() const override;
|
||||
HD_API
|
||||
virtual size_t GetNumElements() const override;
|
||||
HD_API
|
||||
virtual HdTupleType GetTupleType() const override;
|
||||
HD_API
|
||||
virtual void GetBufferSpecs(HdBufferSpecVector *specs) const override;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif //PXR_IMAGING_HD_BUFFER_SOURCE_H
|
||||
@@ -0,0 +1,130 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_BUFFER_SPEC_H
|
||||
#define PXR_IMAGING_HD_BUFFER_SPEC_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/types.h"
|
||||
#include "pxr/base/tf/stl.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
typedef std::vector<struct HdBufferSpec> HdBufferSpecVector;
|
||||
|
||||
/// \class HdBufferSpec
|
||||
///
|
||||
/// Describes each named resource of buffer array.
|
||||
/// This specifies the buffer's value type as HdTupleType,
|
||||
/// which specifies the value type, number of components, and
|
||||
/// number of array entries (which may be 1).
|
||||
///
|
||||
/// for example:
|
||||
/// HdBufferSpecVector
|
||||
/// 0: name = points, tupleType = {HdTypeFloatVec3, 1}
|
||||
/// 1: name = normals, tupleType = {HdTypeFloatVec3, 1}
|
||||
/// 2: name = colors, tupleType = {HdTypeFloatVec3, 1}
|
||||
///
|
||||
struct HdBufferSpec final {
|
||||
/// Constructor.
|
||||
HdBufferSpec(TfToken const &name, HdTupleType tupleType) :
|
||||
name(name), tupleType(tupleType) {}
|
||||
|
||||
/// Util function for adding buffer specs of sources into bufferspecs.
|
||||
template<typename T>
|
||||
static void GetBufferSpecs(T const &sources,
|
||||
HdBufferSpecVector *bufferSpecs) {
|
||||
for (auto const &src : sources) {
|
||||
if (src->IsValid()) {
|
||||
src->GetBufferSpecs(bufferSpecs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns true if \p subset is a subset of \p superset.
|
||||
/// An empty set is considered a valid subset of the superset.
|
||||
HD_API
|
||||
static bool IsSubset(HdBufferSpecVector const &subset,
|
||||
HdBufferSpecVector const &superset);
|
||||
|
||||
/// Returns union set of \p spec1 and \p spec2.
|
||||
/// Duplicated entries are uniquified.
|
||||
HD_API
|
||||
static HdBufferSpecVector ComputeUnion(HdBufferSpecVector const &spec1,
|
||||
HdBufferSpecVector const &spec2);
|
||||
|
||||
/// Returns difference set of \p spec1 and \p spec2, i.e., entries in spec1
|
||||
/// that are not in spec2.
|
||||
HD_API
|
||||
static HdBufferSpecVector ComputeDifference(HdBufferSpecVector const &spec1,
|
||||
HdBufferSpecVector const &spec2);
|
||||
|
||||
/// Debug output.
|
||||
HD_API
|
||||
static void Dump(HdBufferSpecVector const &specs);
|
||||
|
||||
/// Return a size_t hash for this spec.
|
||||
HD_API
|
||||
size_t Hash() const;
|
||||
|
||||
/// Functor to use for unorderd sets, maps.
|
||||
struct HashFunctor {
|
||||
size_t operator()(HdBufferSpec const& spec) const {
|
||||
return spec.Hash();
|
||||
}
|
||||
};
|
||||
|
||||
/// Equality checks.
|
||||
bool operator == (HdBufferSpec const &other) const {
|
||||
return name == other.name && tupleType == other.tupleType;
|
||||
}
|
||||
bool operator != (HdBufferSpec const &other) const {
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
/// Ordering.
|
||||
bool operator < (HdBufferSpec const &other) const {
|
||||
return name < other.name || (name == other.name &&
|
||||
tupleType < other.tupleType);
|
||||
}
|
||||
|
||||
TfToken name;
|
||||
HdTupleType tupleType;
|
||||
};
|
||||
|
||||
// Support TfHash.
|
||||
template <class HashState>
|
||||
void
|
||||
TfHashAppend(HashState &h, HdBufferSpec const &bs)
|
||||
{
|
||||
h.Append(bs.name, bs.tupleType);
|
||||
}
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_BUFFER_SPEC_H
|
||||
@@ -0,0 +1,263 @@
|
||||
//
|
||||
// Copyright 2017 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_CAMERA_H
|
||||
#define PXR_IMAGING_HD_CAMERA_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/sprim.h"
|
||||
|
||||
#include "pxr/imaging/cameraUtil/conformWindow.h"
|
||||
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
#include "pxr/base/tf/staticTokens.h"
|
||||
#include "pxr/base/gf/matrix4d.h"
|
||||
#include "pxr/base/gf/range1f.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// Camera state that can be requested from the scene delegate via
|
||||
/// GetCameraParamValue(id, token). The parameters below mimic the
|
||||
/// USD camera schema and GfCamera (with the exception of window
|
||||
/// policy). All spatial units are in world units though and
|
||||
/// projection is HdCamera::Projection rather than a token.
|
||||
#define HD_CAMERA_TOKENS \
|
||||
/* frustum */ \
|
||||
(projection) \
|
||||
(horizontalAperture) \
|
||||
(verticalAperture) \
|
||||
(horizontalApertureOffset) \
|
||||
(verticalApertureOffset) \
|
||||
(focalLength) \
|
||||
(clippingRange) \
|
||||
(clipPlanes) \
|
||||
\
|
||||
/* depth of field */ \
|
||||
(fStop) \
|
||||
(focusDistance) \
|
||||
\
|
||||
/* shutter/lighting */ \
|
||||
(shutterOpen) \
|
||||
(shutterClose) \
|
||||
(exposure) \
|
||||
\
|
||||
/* how to match window with different aspect */ \
|
||||
(windowPolicy) \
|
||||
\
|
||||
/* OpenGL-style matrices, deprecated */ \
|
||||
(worldToViewMatrix) \
|
||||
(projectionMatrix)
|
||||
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdCameraTokens, HD_API, HD_CAMERA_TOKENS);
|
||||
|
||||
/// \class HdCamera
|
||||
///
|
||||
/// Hydra schema for a camera that pulls the params (see above) during
|
||||
/// Sync.
|
||||
/// Backends that use additional camera parameters can inherit from HdCamera and
|
||||
/// pull on them.
|
||||
///
|
||||
class HdCamera : public HdSprim
|
||||
{
|
||||
public:
|
||||
using ClipPlanesVector = std::vector<GfVec4d>;
|
||||
|
||||
HD_API
|
||||
HdCamera(SdfPath const & id);
|
||||
HD_API
|
||||
~HdCamera() override;
|
||||
|
||||
// change tracking for HdCamera
|
||||
enum DirtyBits : HdDirtyBits
|
||||
{
|
||||
Clean = 0,
|
||||
DirtyTransform = 1 << 0,
|
||||
DirtyViewMatrix = DirtyTransform, // deprecated
|
||||
DirtyProjMatrix = 1 << 1, // deprecated
|
||||
DirtyWindowPolicy = 1 << 2,
|
||||
DirtyClipPlanes = 1 << 3,
|
||||
DirtyParams = 1 << 4,
|
||||
AllDirty = (DirtyTransform
|
||||
|DirtyProjMatrix
|
||||
|DirtyWindowPolicy
|
||||
|DirtyClipPlanes
|
||||
|DirtyParams)
|
||||
};
|
||||
|
||||
enum Projection {
|
||||
Perspective = 0,
|
||||
Orthographic
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// Sprim API
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Synchronizes state from the delegate to this object.
|
||||
HD_API
|
||||
void Sync(HdSceneDelegate *sceneDelegate,
|
||||
HdRenderParam *renderParam,
|
||||
HdDirtyBits *dirtyBits) override;
|
||||
|
||||
|
||||
/// Returns the minimal set of dirty bits to place in the
|
||||
/// change tracker for use in the first sync of this prim.
|
||||
/// Typically this would be all dirty bits.
|
||||
HD_API
|
||||
HdDirtyBits GetInitialDirtyBitsMask() const override;
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// Camera parameters accessor API
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Returns camera transform
|
||||
GfMatrix4d const& GetTransform() const {
|
||||
return _transform;
|
||||
}
|
||||
|
||||
/// Returns whether camera is orthographic and perspective
|
||||
Projection GetProjection() const {
|
||||
return _projection;
|
||||
}
|
||||
|
||||
/// Returns horizontal aperture in world units.
|
||||
float GetHorizontalAperture() const {
|
||||
return _horizontalAperture;
|
||||
}
|
||||
|
||||
/// Returns vertical aperture in world units.
|
||||
float GetVerticalAperture() const {
|
||||
return _verticalAperture;
|
||||
}
|
||||
|
||||
/// Returns horizontal aperture offset in world units.
|
||||
float GetHorizontalApertureOffset() const {
|
||||
return _horizontalApertureOffset;
|
||||
}
|
||||
|
||||
/// Returns vertical aperture offset in world units.
|
||||
float GetVerticalApertureOffset() const {
|
||||
return _verticalApertureOffset;
|
||||
}
|
||||
|
||||
/// Returns focal length in world units.
|
||||
float GetFocalLength() const {
|
||||
return _focalLength;
|
||||
}
|
||||
|
||||
/// Returns near and far plane in world units
|
||||
GfRange1f const &GetClippingRange() const {
|
||||
return _clippingRange;
|
||||
}
|
||||
|
||||
/// Returns any additional clipping planes defined in camera space.
|
||||
std::vector<GfVec4d> const& GetClipPlanes() const {
|
||||
return _clipPlanes;
|
||||
}
|
||||
|
||||
/// Returns fstop of camera
|
||||
float GetFStop() const {
|
||||
return _fStop;
|
||||
}
|
||||
|
||||
/// Returns focus distance in world units.
|
||||
float GetFocusDistance() const {
|
||||
return _focusDistance;
|
||||
}
|
||||
|
||||
double GetShutterOpen() const {
|
||||
return _shutterOpen;
|
||||
}
|
||||
|
||||
double GetShutterClose() const {
|
||||
return _shutterClose;
|
||||
}
|
||||
|
||||
float GetExposure() const {
|
||||
return _exposure;
|
||||
}
|
||||
|
||||
/// Returns the window policy of the camera. If no opinion is authored, we
|
||||
/// default to "CameraUtilFit"
|
||||
CameraUtilConformWindowPolicy const& GetWindowPolicy() const {
|
||||
return _windowPolicy;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// Legacy camera parameters accessor API
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Returns the matrix transformation from world to camera space.
|
||||
/// \deprecated Use GetTransform instead
|
||||
HD_API
|
||||
GfMatrix4d GetViewMatrix() const;
|
||||
|
||||
/// Returns the matrix transformation from camera to world space.
|
||||
/// \deprecated Use GetTransform and invert instead
|
||||
HD_API
|
||||
GfMatrix4d GetViewInverseMatrix() const;
|
||||
|
||||
/// Returns the projection matrix for the camera.
|
||||
/// \deprecated Compute from above physically based attributes
|
||||
HD_API
|
||||
GfMatrix4d GetProjectionMatrix() const;
|
||||
|
||||
protected:
|
||||
// frustum
|
||||
GfMatrix4d _transform;
|
||||
Projection _projection;
|
||||
float _horizontalAperture;
|
||||
float _verticalAperture;
|
||||
float _horizontalApertureOffset;
|
||||
float _verticalApertureOffset;
|
||||
float _focalLength;
|
||||
GfRange1f _clippingRange;
|
||||
std::vector<GfVec4d> _clipPlanes;
|
||||
|
||||
// focus
|
||||
float _fStop;
|
||||
float _focusDistance;
|
||||
|
||||
// shutter/lighting
|
||||
double _shutterOpen;
|
||||
double _shutterClose;
|
||||
float _exposure;
|
||||
|
||||
// Camera's opinion how it display in a window with
|
||||
// a different aspect ratio
|
||||
CameraUtilConformWindowPolicy _windowPolicy;
|
||||
|
||||
// OpenGL-style matrices
|
||||
GfMatrix4d _worldToViewMatrix;
|
||||
GfMatrix4d _worldToViewInverseMatrix;
|
||||
GfMatrix4d _projectionMatrix;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_CAMERA_H
|
||||
@@ -0,0 +1,170 @@
|
||||
//
|
||||
// Copyright 2021 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// This file is generated by a script. Do not edit directly. Edit the
|
||||
// schema.template.h file to make changes.
|
||||
|
||||
#ifndef PXR_IMAGING_HD_CAMERA_SCHEMA_H
|
||||
#define PXR_IMAGING_HD_CAMERA_SCHEMA_H
|
||||
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
|
||||
#include "pxr/imaging/hd/schema.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define HDCAMERA_SCHEMA_TOKENS \
|
||||
(camera) \
|
||||
(projection) \
|
||||
(horizontalAperture) \
|
||||
(verticalAperture) \
|
||||
(horizontalApertureOffset) \
|
||||
(verticalApertureOffset) \
|
||||
(focalLength) \
|
||||
(clippingRange) \
|
||||
(perspective) \
|
||||
(orthographic) \
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdCameraSchemaTokens, HD_API,
|
||||
HDCAMERA_SCHEMA_TOKENS);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class HdCameraSchema : public HdSchema
|
||||
{
|
||||
public:
|
||||
HdCameraSchema(HdContainerDataSourceHandle container)
|
||||
: HdSchema(container) {}
|
||||
|
||||
//ACCESSORS
|
||||
|
||||
HD_API
|
||||
HdTokenDataSourceHandle GetProjection();
|
||||
HD_API
|
||||
HdFloatDataSourceHandle GetHorizontalAperture();
|
||||
HD_API
|
||||
HdFloatDataSourceHandle GetVerticalAperture();
|
||||
HD_API
|
||||
HdFloatDataSourceHandle GetHorizontalApertureOffset();
|
||||
HD_API
|
||||
HdFloatDataSourceHandle GetVerticalApertureOffset();
|
||||
HD_API
|
||||
HdFloatDataSourceHandle GetFocalLength();
|
||||
HD_API
|
||||
HdVec2fDataSourceHandle GetClippingRange();
|
||||
|
||||
// RETRIEVING AND CONSTRUCTING
|
||||
|
||||
/// 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 HdTokenDataSourceHandle &projection,
|
||||
const HdFloatDataSourceHandle &horizontalAperture,
|
||||
const HdFloatDataSourceHandle &verticalAperture,
|
||||
const HdFloatDataSourceHandle &horizontalApertureOffset,
|
||||
const HdFloatDataSourceHandle &verticalApertureOffset,
|
||||
const HdFloatDataSourceHandle &focalLength,
|
||||
const HdVec2fDataSourceHandle &clippingRange
|
||||
);
|
||||
|
||||
/// \class HdCameraSchema::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 &SetProjection(
|
||||
const HdTokenDataSourceHandle &projection);
|
||||
HD_API
|
||||
Builder &SetHorizontalAperture(
|
||||
const HdFloatDataSourceHandle &horizontalAperture);
|
||||
HD_API
|
||||
Builder &SetVerticalAperture(
|
||||
const HdFloatDataSourceHandle &verticalAperture);
|
||||
HD_API
|
||||
Builder &SetHorizontalApertureOffset(
|
||||
const HdFloatDataSourceHandle &horizontalApertureOffset);
|
||||
HD_API
|
||||
Builder &SetVerticalApertureOffset(
|
||||
const HdFloatDataSourceHandle &verticalApertureOffset);
|
||||
HD_API
|
||||
Builder &SetFocalLength(
|
||||
const HdFloatDataSourceHandle &focalLength);
|
||||
HD_API
|
||||
Builder &SetClippingRange(
|
||||
const HdVec2fDataSourceHandle &clippingRange);
|
||||
|
||||
/// Returns a container data source containing the members set thus far.
|
||||
HD_API
|
||||
HdContainerDataSourceHandle Build();
|
||||
|
||||
private:
|
||||
HdTokenDataSourceHandle _projection;
|
||||
HdFloatDataSourceHandle _horizontalAperture;
|
||||
HdFloatDataSourceHandle _verticalAperture;
|
||||
HdFloatDataSourceHandle _horizontalApertureOffset;
|
||||
HdFloatDataSourceHandle _verticalApertureOffset;
|
||||
HdFloatDataSourceHandle _focalLength;
|
||||
HdVec2fDataSourceHandle _clippingRange;
|
||||
};
|
||||
|
||||
/// Retrieves a container data source with the schema's default name token
|
||||
/// "camera" from the parent container and constructs a
|
||||
/// HdCameraSchema 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 HdCameraSchema GetFromParent(
|
||||
const HdContainerDataSourceHandle &fromParentContainer);
|
||||
|
||||
/// 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();
|
||||
|
||||
/// Returns token data source for use as projection value.
|
||||
/// Values of...
|
||||
/// - HdCameraSchemaTokens->perspective
|
||||
/// - HdCameraSchemaTokens->orthographic
|
||||
/// ...will be stored statically and reused for future calls.
|
||||
HD_API
|
||||
static HdTokenDataSourceHandle BuildProjectionDataSource(
|
||||
const TfToken &projection);
|
||||
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,81 @@
|
||||
//
|
||||
// Copyright 2021 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// This file is generated by a script. Do not edit directly. Edit the
|
||||
// schema.template.h file to make changes.
|
||||
|
||||
#ifndef PXR_IMAGING_HD_CATEGORIES_SCHEMA_H
|
||||
#define PXR_IMAGING_HD_CATEGORIES_SCHEMA_H
|
||||
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
|
||||
#include "pxr/imaging/hd/schema.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define HDCATEGORIES_SCHEMA_TOKENS \
|
||||
(categories) \
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdCategoriesSchemaTokens, HD_API,
|
||||
HDCATEGORIES_SCHEMA_TOKENS);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class HdCategoriesSchema : public HdSchema
|
||||
{
|
||||
public:
|
||||
HdCategoriesSchema(HdContainerDataSourceHandle container)
|
||||
: HdSchema(container) {}
|
||||
|
||||
VtArray<TfToken> GetIncludedCategoryNames();
|
||||
bool IsIncludedInCategory(const TfToken &categoryName);
|
||||
|
||||
static HdContainerDataSourceHandle BuildRetained(
|
||||
size_t includedNameCount,
|
||||
TfToken *includedNames,
|
||||
size_t excludedNameCount,
|
||||
TfToken *excludedNames);
|
||||
|
||||
|
||||
/// Retrieves a container data source with the schema's default name token
|
||||
/// "categories" from the parent container and constructs a
|
||||
/// HdCategoriesSchema 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 HdCategoriesSchema GetFromParent(
|
||||
const HdContainerDataSourceHandle &fromParentContainer);
|
||||
|
||||
/// 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();
|
||||
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,674 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_CHANGE_TRACKER_H
|
||||
#define PXR_IMAGING_HD_CHANGE_TRACKER_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/rprimCollection.h"
|
||||
#include "pxr/imaging/hd/types.h"
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
#include "pxr/base/tf/hashmap.h"
|
||||
|
||||
#include <tbb/concurrent_hash_map.h>
|
||||
#include <atomic>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdRetainedSceneIndex;
|
||||
|
||||
/// \class HdChangeTracker
|
||||
///
|
||||
/// Tracks changes from the HdSceneDelegate, providing invalidation cues to the
|
||||
/// render engine.
|
||||
///
|
||||
/// Changes flagged here are accumulated until the next time resource associated
|
||||
/// with the change is required, at which point the resource is updated and the
|
||||
/// flag is cleared.
|
||||
///
|
||||
class HdChangeTracker
|
||||
{
|
||||
public:
|
||||
|
||||
// Common dirty bits for Rprims
|
||||
// XXX: Move this to HdRprim
|
||||
enum RprimDirtyBits : HdDirtyBits {
|
||||
Clean = 0,
|
||||
InitRepr = 1 << 0,
|
||||
Varying = 1 << 1,
|
||||
AllDirty = ~Varying,
|
||||
DirtyPrimID = 1 << 2,
|
||||
DirtyExtent = 1 << 3,
|
||||
DirtyDisplayStyle = 1 << 4,
|
||||
DirtyPoints = 1 << 5,
|
||||
DirtyPrimvar = 1 << 6,
|
||||
DirtyMaterialId = 1 << 7,
|
||||
DirtyTopology = 1 << 8,
|
||||
DirtyTransform = 1 << 9,
|
||||
DirtyVisibility = 1 << 10,
|
||||
DirtyNormals = 1 << 11,
|
||||
DirtyDoubleSided = 1 << 12,
|
||||
DirtyCullStyle = 1 << 13,
|
||||
DirtySubdivTags = 1 << 14,
|
||||
DirtyWidths = 1 << 15,
|
||||
DirtyInstancer = 1 << 16,
|
||||
DirtyInstanceIndex = 1 << 17,
|
||||
DirtyRepr = 1 << 18,
|
||||
DirtyRenderTag = 1 << 19,
|
||||
DirtyComputationPrimvarDesc = 1 << 20,
|
||||
DirtyCategories = 1 << 21,
|
||||
DirtyVolumeField = 1 << 22,
|
||||
AllSceneDirtyBits = ((1<<23) - 1),
|
||||
|
||||
NewRepr = 1 << 23,
|
||||
|
||||
CustomBitsBegin = 1 << 24,
|
||||
CustomBitsEnd = 1 << 30,
|
||||
CustomBitsMask = 0x7f << 24,
|
||||
};
|
||||
|
||||
// InstancerDirtybits are a subset of rprim dirty bits right now:
|
||||
// DirtyPrimvar, DirtyTransform, DirtyInstanceIndex, DirtyInstancer.
|
||||
|
||||
// Dirty bits for Tasks
|
||||
// XXX: Move this to HdTask
|
||||
enum TaskDirtyBits : HdDirtyBits {
|
||||
//Varying = 1 << 0,
|
||||
DirtyType = 1 << 1,
|
||||
DirtyParams = 1 << 2,
|
||||
DirtyCollection = 1 << 3,
|
||||
DirtyRenderTags = 1 << 4,
|
||||
};
|
||||
|
||||
HD_API
|
||||
HdChangeTracker();
|
||||
HD_API
|
||||
virtual ~HdChangeTracker();
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Rprim Object Tracking
|
||||
/// @{
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Start tracking Rprim with the given \p id.
|
||||
HD_API
|
||||
void RprimInserted(SdfPath const& id, HdDirtyBits initialDirtyState);
|
||||
|
||||
/// Stop tracking Rprim with the given \p id.
|
||||
HD_API
|
||||
void RprimRemoved(SdfPath const& id);
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// @}
|
||||
/// \name Rprim State Tracking
|
||||
/// @{
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Returns the dirty bits for the rprim with \p id.
|
||||
HD_API
|
||||
HdDirtyBits GetRprimDirtyBits(SdfPath const& id) const;
|
||||
|
||||
/// Flag the Rprim with the given \p id as being dirty. Multiple calls with
|
||||
/// different dirty bits accumulate.
|
||||
HD_API
|
||||
void MarkRprimDirty(SdfPath const& id, HdDirtyBits bits=AllDirty);
|
||||
|
||||
/// Clear the dirty flags for an HdRprim. if inSync is true, set OutOfSync
|
||||
/// flag to notify dirtyList will discover the prim to sync the residual
|
||||
/// data for new repr.
|
||||
HD_API
|
||||
void MarkRprimClean(SdfPath const& id, HdDirtyBits newBits=Clean);
|
||||
|
||||
/// Mark the primvar for the rprim with \p id as being dirty.
|
||||
HD_API
|
||||
void MarkPrimvarDirty(SdfPath const& id, TfToken const& name);
|
||||
|
||||
/// Flag all the Rprim with the given \p id as being dirty. Multiple calls
|
||||
/// with different dirty bits accumulate.
|
||||
/// Doesn't touch varying state.
|
||||
HD_API
|
||||
void MarkAllRprimsDirty(HdDirtyBits bits);
|
||||
|
||||
/// Clear Varying bit of all prims.
|
||||
///
|
||||
/// The idea is that from frame to frame (update iteration), the set of
|
||||
/// dirty rprims and their dirty bits do not change; that is, the same
|
||||
/// rprims get dirtied with the same dirty bits.. The change tracker can
|
||||
/// leverage this help build a stable dirty list and reduce the
|
||||
/// overall cost of an update iteration.
|
||||
HD_API
|
||||
void ResetVaryingState();
|
||||
|
||||
/// Reset the varying state on one Rprim
|
||||
/// This is done for Rprims, where we choose not to clean them
|
||||
/// (due to state like invisibility).
|
||||
HD_API
|
||||
void ResetRprimVaryingState(SdfPath const& id);
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Returns true if the rprim identified by \p id has any dirty flags set.
|
||||
HD_API
|
||||
bool IsRprimDirty(SdfPath const& id);
|
||||
|
||||
/// Returns true if the rprim identified by \p id has a dirty extent.
|
||||
HD_API
|
||||
bool IsExtentDirty(SdfPath const& id);
|
||||
|
||||
/// Returns true if the rprim identified by \p id has a dirty display style.
|
||||
HD_API
|
||||
bool IsDisplayStyleDirty(SdfPath const& id);
|
||||
|
||||
/// Returns true if the rprim identified by \p id with primvar \p name is
|
||||
/// dirty.
|
||||
HD_API
|
||||
bool IsPrimvarDirty(SdfPath const& id, TfToken const& name);
|
||||
|
||||
/// Returns true if the rprim identified by \p id has any dirty primvars.
|
||||
HD_API
|
||||
bool IsAnyPrimvarDirty(SdfPath const& id);
|
||||
|
||||
/// Returns true if the rprim identified by \p id has a dirty topology.
|
||||
HD_API
|
||||
bool IsTopologyDirty(SdfPath const& id);
|
||||
|
||||
/// Returns true if the rprim identified by \p id has dirty doubleSided state.
|
||||
HD_API
|
||||
bool IsDoubleSidedDirty(SdfPath const& id);
|
||||
|
||||
/// Returns true if the rprim identified by \p id has dirty cullstyle.
|
||||
HD_API
|
||||
bool IsCullStyleDirty(SdfPath const& id);
|
||||
|
||||
/// Returns true if the rprim identified by \p id has a dirty subdiv tags.
|
||||
HD_API
|
||||
bool IsSubdivTagsDirty(SdfPath const& id);
|
||||
|
||||
/// Returns true if the rprim identified by \p id has a dirty transform.
|
||||
HD_API
|
||||
bool IsTransformDirty(SdfPath const& id);
|
||||
|
||||
/// Returns true if the rprim identified by \p id has dirty visibility.
|
||||
HD_API
|
||||
bool IsVisibilityDirty(SdfPath const& id);
|
||||
|
||||
/// Returns true if the rprim identified by \p id has a dirty primID.
|
||||
HD_API
|
||||
bool IsPrimIdDirty(SdfPath const& id);
|
||||
|
||||
/// Returns true if the dirtyBits has any flags set other than the varying
|
||||
/// flag.
|
||||
static bool IsDirty(HdDirtyBits dirtyBits) {
|
||||
return (dirtyBits & AllDirty) != 0;
|
||||
}
|
||||
|
||||
/// Returns true if the dirtyBits has no flags set except the varying flag.
|
||||
static bool IsClean(HdDirtyBits dirtyBits) {
|
||||
return (dirtyBits & AllDirty) == 0;
|
||||
}
|
||||
|
||||
/// Returns true if the varying flag is set.
|
||||
static bool IsVarying(HdDirtyBits dirtyBits) {
|
||||
return (dirtyBits & Varying) != 0;
|
||||
}
|
||||
|
||||
/// Returns true if the dirtyBits has a dirty extent. id is for perflog.
|
||||
HD_API
|
||||
static bool IsExtentDirty(HdDirtyBits dirtyBits, SdfPath const& id);
|
||||
|
||||
/// Returns true if the dirtyBits has a dirty display style. id is for perflog.
|
||||
HD_API
|
||||
static bool IsDisplayStyleDirty(HdDirtyBits dirtyBits, SdfPath const& id);
|
||||
|
||||
/// Returns true if the dirtyBits has a dirty subdiv tags. id is for perflog.
|
||||
HD_API
|
||||
static bool IsSubdivTagsDirty(HdDirtyBits dirtyBits, SdfPath const& id);
|
||||
|
||||
/// Returns true if the dirtyBits has a dirty primvar \p name.
|
||||
/// id is for perflog.
|
||||
HD_API
|
||||
static bool IsPrimvarDirty(HdDirtyBits dirtyBits, SdfPath const& id,
|
||||
TfToken const& name);
|
||||
|
||||
/// Returns true if the dirtyBits has any dirty primvars.
|
||||
/// id is for perflog.
|
||||
HD_API
|
||||
static bool IsAnyPrimvarDirty(HdDirtyBits dirtyBits, SdfPath const& id);
|
||||
|
||||
/// Returns true if the dirtyBits has a dirty topology. id is for perflog.
|
||||
HD_API
|
||||
static bool IsTopologyDirty(HdDirtyBits dirtyBits, SdfPath const& id);
|
||||
|
||||
/// Returns true if the dirtyBits has dirty doubleSided state. id is for perflog.
|
||||
HD_API
|
||||
static bool IsDoubleSidedDirty(HdDirtyBits dirtyBits, SdfPath const& id);
|
||||
|
||||
/// Returns true if the dirtyBits has dirty cullstyle. id is for perflog.
|
||||
HD_API
|
||||
static bool IsCullStyleDirty(HdDirtyBits dirtyBits, SdfPath const& id);
|
||||
|
||||
/// Returns true if the dirtyBits has a dirty transform. id is for perflog.
|
||||
HD_API
|
||||
static bool IsTransformDirty(HdDirtyBits dirtyBits, SdfPath const& id);
|
||||
|
||||
/// Returns true if the dirtyBits has dirty visibility. id is for perflog.
|
||||
HD_API
|
||||
static bool IsVisibilityDirty(HdDirtyBits dirtyBits, SdfPath const& id);
|
||||
|
||||
/// Returns true if the dirtyBits has a dirty primID. id is for perflog.
|
||||
HD_API
|
||||
static bool IsPrimIdDirty(HdDirtyBits dirtyBits, SdfPath const& id);
|
||||
|
||||
/// Returns true if the dirtyBits has a dirty instancer. id is for perflog.
|
||||
HD_API
|
||||
static bool IsInstancerDirty(HdDirtyBits dirtyBits, SdfPath const& id);
|
||||
|
||||
/// Returns true if the dirtyBits has a dirty instance index. id is for perflog.
|
||||
HD_API
|
||||
static bool IsInstanceIndexDirty(HdDirtyBits dirtyBits, SdfPath const& id);
|
||||
|
||||
HD_API
|
||||
static bool IsReprDirty(HdDirtyBits dirtyBits, SdfPath const &id);
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Set the primvar dirty flag to \p dirtyBits.
|
||||
HD_API
|
||||
static void MarkPrimvarDirty(HdDirtyBits *dirtyBits, TfToken const &name);
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// @}
|
||||
/// \name Task Object Tracking
|
||||
/// @{
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Start tracking Task with the given \p id.
|
||||
HD_API
|
||||
void TaskInserted(SdfPath const& id, HdDirtyBits initialDirtyState);
|
||||
|
||||
/// Stop tracking Task with the given \p id.
|
||||
HD_API
|
||||
void TaskRemoved(SdfPath const& id);
|
||||
|
||||
/// Set the dirty flags to \p bits.
|
||||
HD_API
|
||||
void MarkTaskDirty(SdfPath const& id, HdDirtyBits bits=AllDirty);
|
||||
|
||||
/// Get the dirty bits for Task with the given \p id.
|
||||
HD_API
|
||||
HdDirtyBits GetTaskDirtyBits(SdfPath const& id);
|
||||
|
||||
/// Set the dirty flags to \p newBits.
|
||||
HD_API
|
||||
void MarkTaskClean(SdfPath const& id, HdDirtyBits newBits=Clean);
|
||||
|
||||
/// Retrieve the current version number of the rprim render tag set
|
||||
/// XXX Rename to GetRprimRenderTagVersion
|
||||
HD_API
|
||||
unsigned GetRenderTagVersion() const;
|
||||
|
||||
/// Retrieve the current version number of the task's render tags opinion.
|
||||
HD_API
|
||||
unsigned GetTaskRenderTagsVersion() const;
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// @}
|
||||
/// \name Instancer State Tracking
|
||||
/// @{
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Start tracking Instancer with the given \p id.
|
||||
HD_API
|
||||
void InstancerInserted(SdfPath const& id, HdDirtyBits initialDirtyState);
|
||||
|
||||
/// Stop tracking Instancer with the given \p id.
|
||||
HD_API
|
||||
void InstancerRemoved(SdfPath const& id);
|
||||
|
||||
/// Returns the dirty bits for the instancer with \p id.
|
||||
HD_API
|
||||
HdDirtyBits GetInstancerDirtyBits(SdfPath const& id);
|
||||
|
||||
/// Flag the Instancer with the given \p id as being dirty. Multiple calls
|
||||
/// with different dirty bits accumulate.
|
||||
HD_API
|
||||
void MarkInstancerDirty(SdfPath const& id, HdDirtyBits bits=AllDirty);
|
||||
|
||||
/// Clean the specified dirty bits for the instancer with \p id.
|
||||
HD_API
|
||||
void MarkInstancerClean(SdfPath const& id, HdDirtyBits newBits=Clean);
|
||||
|
||||
/// Insert a dependency between \p rprimId and parent instancer
|
||||
/// \p instancerId. Changes to the latter mark the former with
|
||||
/// DirtyInstancer.
|
||||
HD_API
|
||||
void AddInstancerRprimDependency(SdfPath const& instancerId,
|
||||
SdfPath const& rprimId);
|
||||
|
||||
/// Remove a dependency between \p rprimId and parent instancer
|
||||
/// \p instancerId.
|
||||
HD_API
|
||||
void RemoveInstancerRprimDependency(SdfPath const& instancerId,
|
||||
SdfPath const& rprimId);
|
||||
|
||||
/// Insert a dependency between \p instancerId and parent instancer
|
||||
/// \p parentInstancerId. Changes to the latter mark the former with
|
||||
/// DirtyInstancer.
|
||||
HD_API
|
||||
void AddInstancerInstancerDependency(SdfPath const& parentInstancerId,
|
||||
SdfPath const& instancerId);
|
||||
|
||||
/// Remove a dependency between \p instancerId and parent instancer
|
||||
/// \p parentInstancerId.
|
||||
HD_API
|
||||
void RemoveInstancerInstancerDependency(SdfPath const& parentInstancerId,
|
||||
SdfPath const& instancerId);
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// @}
|
||||
/// \name Sprim (scene state prim: camera, light, ...) state Tracking
|
||||
/// @{
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Start tracking sprim with the given \p id.
|
||||
HD_API
|
||||
void SprimInserted(SdfPath const& id, HdDirtyBits initialDirtyState);
|
||||
|
||||
/// Stop tracking sprim with the given \p id.
|
||||
HD_API
|
||||
void SprimRemoved(SdfPath const& id);
|
||||
|
||||
/// Get the dirty bits for sprim with the given \p id.
|
||||
HD_API
|
||||
HdDirtyBits GetSprimDirtyBits(SdfPath const& id);
|
||||
|
||||
/// Set the dirty flags to \p bits.
|
||||
HD_API
|
||||
void MarkSprimDirty(SdfPath const& id, HdDirtyBits bits);
|
||||
|
||||
/// Set the dirty flags to \p newBits.
|
||||
HD_API
|
||||
void MarkSprimClean(SdfPath const& id, HdDirtyBits newBits=Clean);
|
||||
|
||||
/// Insert a dependency between \p sprimId and parent sprim
|
||||
/// \p parentSprimId.
|
||||
HD_API
|
||||
void AddSprimSprimDependency(SdfPath const& parentSprimId,
|
||||
SdfPath const& sprimId);
|
||||
|
||||
/// Remove a dependency between \p sprimId and parent sprim
|
||||
/// \p parentSprimId.
|
||||
HD_API
|
||||
void RemoveSprimSprimDependency(SdfPath const& parentSprimId,
|
||||
SdfPath const& sprimId);
|
||||
|
||||
/// Remove all dependencies involving \p sprimId as a parent or child.
|
||||
HD_API
|
||||
void RemoveSprimFromSprimSprimDependencies(SdfPath const& sprimId);
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// @}
|
||||
/// \name Bprim (buffer prim: texture, buffer, ...) state Tracking
|
||||
/// @{
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Start tracking bprim with the given \p id.
|
||||
HD_API
|
||||
void BprimInserted(SdfPath const& id, HdDirtyBits initialDirtyState);
|
||||
|
||||
/// Stop tracking bprim with the given \p id.
|
||||
HD_API
|
||||
void BprimRemoved(SdfPath const& id);
|
||||
|
||||
/// Get the dirty bits for bprim with the given \p id.
|
||||
HD_API
|
||||
HdDirtyBits GetBprimDirtyBits(SdfPath const& id);
|
||||
|
||||
/// Set the dirty flags to \p bits.
|
||||
HD_API
|
||||
void MarkBprimDirty(SdfPath const& id, HdDirtyBits bits);
|
||||
|
||||
/// Set the dirty flags to \p newBits.
|
||||
HD_API
|
||||
void MarkBprimClean(SdfPath const& id, HdDirtyBits newBits=Clean);
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// @}
|
||||
/// \name RprimCollection Tracking
|
||||
/// @{
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Adds a named collection for tracking.
|
||||
HD_API
|
||||
void AddCollection(TfToken const& collectionName);
|
||||
|
||||
/// Marks a named collection as being dirty, this bumps the version of the
|
||||
/// collection.
|
||||
HD_API
|
||||
void MarkCollectionDirty(TfToken const& collectionName);
|
||||
|
||||
/// Returns the current version of the named collection.
|
||||
HD_API
|
||||
unsigned GetCollectionVersion(TfToken const& collectionName) const;
|
||||
|
||||
/// Returns the number of changes to visibility. This is intended to be used
|
||||
/// to detect when visibility has changed for *any* Rprim.
|
||||
HD_API
|
||||
unsigned GetVisibilityChangeCount() const;
|
||||
|
||||
/// Returns the current version of varying state. This is used to refresh
|
||||
/// cached DirtyLists
|
||||
unsigned GetVaryingStateVersion() const {
|
||||
return _varyingStateVersion;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// @}
|
||||
/// \name Render Index Versioning
|
||||
/// @{
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Returns the current version of the Render Index's RPrim set.
|
||||
/// This version number changes when Rprims are inserted or removed
|
||||
/// from the render index. Invalidating any cached gather operations.
|
||||
unsigned GetRprimIndexVersion() const {
|
||||
return _rprimIndexVersion;
|
||||
}
|
||||
|
||||
/// Returns the current version of the Render Index's SPrim set.
|
||||
/// This version number changes when Sprims are inserted or removed
|
||||
/// from the render index. Invalidating any cached gather operations.
|
||||
unsigned GetSprimIndexVersion() const {
|
||||
return _sprimIndexVersion;
|
||||
}
|
||||
|
||||
/// Returns the current version of the Render Index's BPrim set.
|
||||
/// This version number changes when Bprims are inserted or removed
|
||||
/// from the render index. Invalidating any cached gather operations.
|
||||
unsigned GetBprimIndexVersion() const {
|
||||
return _bprimIndexVersion;
|
||||
}
|
||||
|
||||
/// Returns the current version of the Render Index's Instancer set.
|
||||
/// This version number changes when Instancers are inserted or removed
|
||||
/// from the render index. Invalidating any cached gather operations.
|
||||
unsigned GetInstancerIndexVersion() const {
|
||||
return _instancerIndexVersion;
|
||||
}
|
||||
|
||||
|
||||
/// Returns the current version of the scene state.
|
||||
/// This version number changes whenever any prims are inserted, removed
|
||||
/// or marked dirty.
|
||||
/// The use case is to detect that nothing has changed, so the Sync
|
||||
/// phase can be avoided.
|
||||
unsigned GetSceneStateVersion() const {
|
||||
return _sceneStateVersion;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// @}
|
||||
/// \name General state tracking
|
||||
/// @{
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Adds a named state for tracking.
|
||||
HD_API
|
||||
void AddState(TfToken const& name);
|
||||
|
||||
/// Marks a named state as being dirty., this bumps the version of the
|
||||
/// state.
|
||||
HD_API
|
||||
void MarkStateDirty(TfToken const& name);
|
||||
|
||||
/// Returns the current version of the named state.
|
||||
HD_API
|
||||
unsigned GetStateVersion(TfToken const &name) const;
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// @}
|
||||
/// \name Debug
|
||||
/// @{
|
||||
// ---------------------------------------------------------------------- //
|
||||
HD_API
|
||||
static std::string StringifyDirtyBits(HdDirtyBits dirtyBits);
|
||||
|
||||
HD_API
|
||||
static void DumpDirtyBits(HdDirtyBits dirtyBits);
|
||||
|
||||
/// @}
|
||||
|
||||
private:
|
||||
|
||||
// Don't allow copies
|
||||
HdChangeTracker(const HdChangeTracker &) = delete;
|
||||
HdChangeTracker &operator=(const HdChangeTracker &) = delete;
|
||||
|
||||
|
||||
static void _LogCacheAccess(TfToken const& cacheName,
|
||||
SdfPath const& id, bool hit);
|
||||
|
||||
typedef TfHashMap<SdfPath, HdDirtyBits, SdfPath::Hash> _IDStateMap;
|
||||
typedef TfHashMap<TfToken, int, TfToken::HashFunctor> _CollectionStateMap;
|
||||
typedef TfHashMap<TfToken, unsigned, TfToken::HashFunctor> _GeneralStateMap;
|
||||
|
||||
struct _PathHashCompare {
|
||||
static bool equal(const SdfPath& a, const SdfPath& b)
|
||||
{ return a == b; }
|
||||
|
||||
static size_t hash(const SdfPath& path)
|
||||
{ return hash_value(path); }
|
||||
};
|
||||
typedef tbb::concurrent_hash_map<SdfPath, SdfPathSet, _PathHashCompare>
|
||||
_DependencyMap;
|
||||
|
||||
// Core dirty state.
|
||||
_IDStateMap _rprimState;
|
||||
_IDStateMap _instancerState;
|
||||
_IDStateMap _taskState;
|
||||
_IDStateMap _sprimState;
|
||||
_IDStateMap _bprimState;
|
||||
_GeneralStateMap _generalState;
|
||||
|
||||
// Collection versions / state.
|
||||
_CollectionStateMap _collectionState;
|
||||
|
||||
// Provides reverse-association between instancers and the child
|
||||
// instancers/rprims that use them.
|
||||
_DependencyMap _instancerRprimDependencies;
|
||||
_DependencyMap _instancerInstancerDependencies;
|
||||
|
||||
// Provides forward and reverse-association between sprims and the child
|
||||
// sprims that reference them. For example, a light prim (child) who needs
|
||||
// to know when its light filter (parent) is modified.
|
||||
// Maps parent sprim to child sprim.
|
||||
_DependencyMap _sprimSprimTargetDependencies;
|
||||
// Maps child sprim to parent sprim.
|
||||
_DependencyMap _sprimSprimSourceDependencies;
|
||||
|
||||
// Dependency map helpers
|
||||
void _AddDependency(_DependencyMap &depMap,
|
||||
SdfPath const& parent, SdfPath const& child);
|
||||
void _RemoveDependency(_DependencyMap &depMap,
|
||||
SdfPath const& parent, SdfPath const& child);
|
||||
|
||||
// Typically the Rprims that get marked dirty per update iteration end up
|
||||
// being a stable set of objects; to leverage this fact, we require the
|
||||
// delegate notify the change tracker when that state changes, which bumps
|
||||
// the varyingStateVersion, which triggers downstream invalidation.
|
||||
unsigned _varyingStateVersion;
|
||||
|
||||
// Tracks changes (insertions/removals) of prims in the render index.
|
||||
// This is used to indicating that cached gather operations need to be
|
||||
// re-evaluated, such as dirty lists or batch building.
|
||||
unsigned _rprimIndexVersion;
|
||||
unsigned _sprimIndexVersion;
|
||||
unsigned _bprimIndexVersion;
|
||||
unsigned _instancerIndexVersion;
|
||||
|
||||
// The following tracks any changes of state. As a result it is very broad.
|
||||
// The use case to detect, when no changes have been made, as to
|
||||
// avoid the need to sync or reset progressive renderers.
|
||||
unsigned _sceneStateVersion;
|
||||
|
||||
// Used to detect that visibility changed somewhere in the render index.
|
||||
unsigned _visChangeCount;
|
||||
|
||||
// Used to detect changes to the render tag opinion of rprims.
|
||||
unsigned _rprimRenderTagVersion;
|
||||
|
||||
// Used to detect changes to the render tags opinion of tasks.
|
||||
unsigned _taskRenderTagsVersion;
|
||||
|
||||
// Allow HdRenderIndex to provide a scene index to forward dirty
|
||||
// information. This is necessary to accommodate legacy HdSceneDelegate
|
||||
// based applications that rely on the HdChangeTracker for invalidating
|
||||
// state on Hydra prims.
|
||||
friend class HdRenderIndex;
|
||||
// Does not take ownership. The HdRenderIndex manages the lifetime of this
|
||||
// scene index.
|
||||
HdRetainedSceneIndex * _emulationSceneIndex;
|
||||
void _SetTargetSceneIndex(HdRetainedSceneIndex *emulationSceneIndex);
|
||||
|
||||
// Private methods which implement the behaviors of their public
|
||||
// equivalents. The public versions check to see if legacy emulation is
|
||||
// active. If so, they dirty the HdRetainedSceneIndex member instead
|
||||
// of directly acting. If legacy render delegate emulation is active, these
|
||||
// will eventually make their way back to the private methods via
|
||||
// HdSceneIndexAdapterSceneDelegate. This prevents dirtying cycles while
|
||||
// allowing single HdRenderIndex/HdChangeTracker instances to be used for
|
||||
// both ends of emulation.
|
||||
friend class HdSceneIndexAdapterSceneDelegate;
|
||||
void _MarkRprimDirty(SdfPath const& id, HdDirtyBits bits=AllDirty);
|
||||
void _MarkSprimDirty(SdfPath const& id, HdDirtyBits bits=AllDirty);
|
||||
void _MarkBprimDirty(SdfPath const& id, HdDirtyBits bits=AllDirty);
|
||||
void _MarkInstancerDirty(SdfPath const& id, HdDirtyBits bits=AllDirty);
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif //PXR_IMAGING_HD_CHANGE_TRACKER_H
|
||||
@@ -0,0 +1,113 @@
|
||||
//
|
||||
// Copyright 2021 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_COMMAND_H
|
||||
#define PXR_IMAGING_HD_COMMAND_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
|
||||
#include "pxr/base/vt/dictionary.h"
|
||||
#include "pxr/base/vt/value.h"
|
||||
|
||||
#include "pxr/base/tf/token.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// \class HdCommandArgDescriptor
|
||||
///
|
||||
/// A bundle of state describing an argument to a command. See \c
|
||||
/// HdCommandDescriptor for more information about commands.
|
||||
///
|
||||
struct HdCommandArgDescriptor
|
||||
{
|
||||
HdCommandArgDescriptor();
|
||||
|
||||
HdCommandArgDescriptor(const TfToken &argName,
|
||||
const VtValue &defaultValue_)
|
||||
: argName(argName)
|
||||
, defaultValue(defaultValue_)
|
||||
{}
|
||||
|
||||
///
|
||||
/// The name of the argument
|
||||
///
|
||||
const TfToken argName;
|
||||
|
||||
///
|
||||
/// Default value for this argument
|
||||
///
|
||||
const VtValue defaultValue;
|
||||
};
|
||||
|
||||
using HdCommandArgDescriptors = std::vector<HdCommandArgDescriptor>;
|
||||
|
||||
///
|
||||
/// Command arguments are a map of tokens to values
|
||||
///
|
||||
using HdCommandArgs = VtDictionary;
|
||||
|
||||
/// \class HdCommandDescriptor
|
||||
///
|
||||
/// A bundle of state describing a "command". A command is simply a token
|
||||
/// that can be invoked and delivered to the render delegate.
|
||||
///
|
||||
struct HdCommandDescriptor
|
||||
{
|
||||
HdCommandDescriptor();
|
||||
|
||||
explicit HdCommandDescriptor(
|
||||
const TfToken &name_,
|
||||
const std::string &description_="",
|
||||
const HdCommandArgDescriptors &args_=HdCommandArgDescriptors())
|
||||
: commandName(name_)
|
||||
, commandDescription(description_)
|
||||
, commandArgs(args_)
|
||||
{}
|
||||
|
||||
///
|
||||
/// A token representing a command that can be invoked.
|
||||
///
|
||||
const TfToken commandName;
|
||||
|
||||
///
|
||||
/// A description of the command suitable for display in a UI for example.
|
||||
///
|
||||
const std::string commandDescription;
|
||||
|
||||
///
|
||||
/// List of arguments this command supports, may be empty.
|
||||
///
|
||||
const HdCommandArgDescriptors commandArgs;
|
||||
|
||||
};
|
||||
|
||||
using HdCommandDescriptors = std::vector<HdCommandDescriptor>;
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_COMMAND_H
|
||||
@@ -0,0 +1,82 @@
|
||||
//
|
||||
// Copyright 2017 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
|
||||
#ifndef PXR_IMAGING_HD_COMP_EXT_COMP_INPUT_SOURCE_H
|
||||
#define PXR_IMAGING_HD_COMP_EXT_COMP_INPUT_SOURCE_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/extCompInputSource.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdExtCompCpuComputation;
|
||||
|
||||
using HdExtCompCpuComputationSharedPtr =
|
||||
std::shared_ptr<HdExtCompCpuComputation>;
|
||||
|
||||
///
|
||||
/// An Hd Buffer Source Computation that is used to bind an ExtComputation input
|
||||
/// to a specific output of another ExtComputation.
|
||||
///
|
||||
class Hd_CompExtCompInputSource final : public Hd_ExtCompInputSource {
|
||||
public:
|
||||
/// Constructs the computation, binding inputName to sourceOutputName
|
||||
/// on buffer source representation of the source computation.
|
||||
HD_API
|
||||
Hd_CompExtCompInputSource(const TfToken &inputName,
|
||||
const HdExtCompCpuComputationSharedPtr &source,
|
||||
const TfToken &sourceOutputName);
|
||||
|
||||
HD_API
|
||||
virtual ~Hd_CompExtCompInputSource() = default;
|
||||
|
||||
/// Returns true once the source computation has been resolved.
|
||||
HD_API
|
||||
virtual bool Resolve() override;
|
||||
|
||||
/// Obtains the value of the output from the source computation.
|
||||
HD_API
|
||||
virtual const VtValue &GetValue() const override;
|
||||
|
||||
protected:
|
||||
/// Returns true if the binding is successful.
|
||||
virtual bool _CheckValid() const override;
|
||||
|
||||
private:
|
||||
HdExtCompCpuComputationSharedPtr _source;
|
||||
size_t _sourceOutputIdx;
|
||||
|
||||
Hd_CompExtCompInputSource() = delete;
|
||||
Hd_CompExtCompInputSource(const Hd_CompExtCompInputSource &) = delete;
|
||||
Hd_CompExtCompInputSource &operator = (const Hd_CompExtCompInputSource &)
|
||||
= delete;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_COMP_EXT_COMP_INPUT_SOURCE_H
|
||||
@@ -0,0 +1,85 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_COMPUTATION_H
|
||||
#define PXR_IMAGING_HD_COMPUTATION_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/bufferSpec.h"
|
||||
#include "pxr/imaging/hd/perfLog.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
using HdBufferArrayRangeSharedPtr = std::shared_ptr<class HdBufferArrayRange>;
|
||||
|
||||
using HdComputationSharedPtr = std::shared_ptr<class HdComputation>;
|
||||
using HdComputationSharedPtrVector = std::vector<HdComputationSharedPtr>;
|
||||
|
||||
/// \class HdComputation
|
||||
///
|
||||
/// An interface class for GPU computation.
|
||||
///
|
||||
/// GPU computation fills the result into range, which has to be allocated
|
||||
/// using buffer specs determined by GetBufferSpecs, and registered as a pair
|
||||
/// of computation and range.
|
||||
///
|
||||
class HdComputation
|
||||
{
|
||||
public:
|
||||
HD_API
|
||||
virtual ~HdComputation();
|
||||
|
||||
/// Execute computation.
|
||||
virtual void Execute(
|
||||
HdBufferArrayRangeSharedPtr const &range,
|
||||
HdResourceRegistry *resourceRegistry) = 0;
|
||||
|
||||
/// Returns the size of its destination buffer (located by range argument
|
||||
/// of Execute()). This function will be called after all HdBufferSources
|
||||
/// have been resolved and commited, so it can use the result of those
|
||||
/// buffer source results.
|
||||
/// Returning 0 means it doesn't need to resize.
|
||||
virtual int GetNumOutputElements() const = 0;
|
||||
|
||||
/// Add the buffer spec for this computation into given bufferspec vector.
|
||||
/// Caller has to allocate the destination buffer with respect to the
|
||||
/// BufferSpecs, and passes the range when registering the computation.
|
||||
virtual void GetBufferSpecs(HdBufferSpecVector *specs) const = 0;
|
||||
|
||||
/// This function is needed as HdComputation shares a templatized interface
|
||||
/// with HdBufferSource.
|
||||
///
|
||||
/// It is a check to see if the GetBufferSpecs would produce a valid result.
|
||||
bool IsValid() { return true; }
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_COMPUTATION_H
|
||||
@@ -0,0 +1,90 @@
|
||||
//
|
||||
// Copyright 2019 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_COORD_SYS_H
|
||||
#define PXR_IMAGING_HD_COORD_SYS_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/sprim.h"
|
||||
|
||||
#include "pxr/base/vt/dictionary.h"
|
||||
#include "pxr/base/vt/value.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdSceneDelegate;
|
||||
|
||||
/// \class HdCoordSys
|
||||
///
|
||||
/// HdCoordSys representes a coordinate system as a Hydra state prim.
|
||||
///
|
||||
/// Coordinate systems may be referred to by name from a shader network.
|
||||
/// Following the convention in UsdShadeCoordSysAPI, we use the Hydra
|
||||
/// id to establish the name, where the id is a namespaced property
|
||||
/// path of the form <tt><.../prim.coordSys:NAME></tt>. GetName()
|
||||
/// will retrieve the name.
|
||||
///
|
||||
/// Each rprim may have a set of bound coordinate systems, which
|
||||
/// may be retrieved via the <tt>HdTokens->coordSysBindings</tt> key.
|
||||
/// The returned value is of type HdIdVectorSharedPtr, a reference-
|
||||
/// counted pointer to a vector of ids of coordinate systems.
|
||||
/// The intention of this design is to make it efficient for scene
|
||||
/// delegates to communicate to renderer delegates the common
|
||||
/// mappings of bound coordinate systems across groups of rprims.
|
||||
///
|
||||
/// The transform value of an HdCoordSys is the matrix representation
|
||||
/// of the transform from its local space to world space. In other
|
||||
/// words, it has the same interpretation as the transform for rprims.
|
||||
///
|
||||
class HdCoordSys : public HdSprim {
|
||||
public:
|
||||
HD_API
|
||||
HdCoordSys(SdfPath const & id);
|
||||
HD_API
|
||||
virtual ~HdCoordSys();
|
||||
|
||||
// Change tracking for HdCoordSys
|
||||
enum DirtyBits : HdDirtyBits {
|
||||
Clean = 0,
|
||||
DirtyTransform = 1 << 0,
|
||||
AllDirty = DirtyTransform
|
||||
};
|
||||
|
||||
/// Returns the name bound to this coordinate system.
|
||||
///
|
||||
/// There may be multiple coordinate systems with the same
|
||||
/// name, but they must associate with disjoint sets of rprims.
|
||||
TfToken GetName() const { return _name; }
|
||||
|
||||
private:
|
||||
TfToken _name;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_COORD_SYS_H
|
||||
@@ -0,0 +1,81 @@
|
||||
//
|
||||
// Copyright 2021 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// This file is generated by a script. Do not edit directly. Edit the
|
||||
// schema.template.h file to make changes.
|
||||
|
||||
#ifndef PXR_IMAGING_HD_COORD_SYS_BINDING_SCHEMA_H
|
||||
#define PXR_IMAGING_HD_COORD_SYS_BINDING_SCHEMA_H
|
||||
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
|
||||
#include "pxr/imaging/hd/schema.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define HDCOORDSYSBINDING_SCHEMA_TOKENS \
|
||||
(coordSysBinding) \
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdCoordSysBindingSchemaTokens, HD_API,
|
||||
HDCOORDSYSBINDING_SCHEMA_TOKENS);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class HdCoordSysBindingSchema : public HdSchema
|
||||
{
|
||||
public:
|
||||
HdCoordSysBindingSchema(HdContainerDataSourceHandle container)
|
||||
: HdSchema(container) {}
|
||||
|
||||
HD_API
|
||||
static HdContainerDataSourceHandle
|
||||
BuildRetained(
|
||||
size_t count,
|
||||
TfToken *names,
|
||||
HdDataSourceBaseHandle *values);
|
||||
|
||||
HdPathDataSourceHandle GetCoordSysBinding(TfToken const &name);
|
||||
|
||||
|
||||
/// Retrieves a container data source with the schema's default name token
|
||||
/// "coordSysBinding" from the parent container and constructs a
|
||||
/// HdCoordSysBindingSchema 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 HdCoordSysBindingSchema GetFromParent(
|
||||
const HdContainerDataSourceHandle &fromParentContainer);
|
||||
|
||||
/// 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();
|
||||
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,243 @@
|
||||
//
|
||||
// Copyright 2021 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_DATASOURCE_H
|
||||
#define PXR_IMAGING_HD_DATASOURCE_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/dataSourceLocator.h"
|
||||
|
||||
#include "pxr/base/tf/token.h"
|
||||
#include "pxr/base/vt/value.h"
|
||||
|
||||
#include <iosfwd>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <atomic>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// HD_DECLARE_DATASOURCE_ABSTRACT
|
||||
/// Used for non-instantiable classes, this defines a set of functions
|
||||
/// for manipulating handles to this type of datasource.
|
||||
#define HD_DECLARE_DATASOURCE_ABSTRACT(type) \
|
||||
using Handle = std::shared_ptr<type>; \
|
||||
using AtomicHandle = Handle; \
|
||||
static Handle AtomicLoad(AtomicHandle &ptr) { \
|
||||
return std::atomic_load(&ptr); \
|
||||
} \
|
||||
static void AtomicStore(AtomicHandle &ptr, Handle &v) { \
|
||||
std::atomic_store(&ptr, v); \
|
||||
} \
|
||||
static Handle Cast(const HdDataSourceBase::Handle &v) { \
|
||||
return std::dynamic_pointer_cast<type>(v); \
|
||||
}
|
||||
|
||||
/// HD_DECLARE_DATASOURCE
|
||||
/// Used for instantiable classes, this defines functions for manipulating
|
||||
/// and allocating handles to this type of datasource.
|
||||
///
|
||||
/// Use of this macro in derived classes is important to make sure that
|
||||
/// core and client code share the same handle type and allocator.
|
||||
#define HD_DECLARE_DATASOURCE(type) \
|
||||
HD_DECLARE_DATASOURCE_ABSTRACT(type) \
|
||||
template <typename ... Args> \
|
||||
static Handle New(Args&& ... args) { \
|
||||
return Handle(new type(std::forward<Args>(args) ... )); \
|
||||
}
|
||||
|
||||
#define HD_DECLARE_DATASOURCE_HANDLES(type) \
|
||||
using type##Handle = type::Handle; \
|
||||
using type##AtomicHandle = type::AtomicHandle;
|
||||
|
||||
/// \class HdDataSourceBase
|
||||
///
|
||||
/// Represents an object which can produce scene data.
|
||||
/// \sa HdContainerDataSource HdVectorDataSource HdSampledDataSource
|
||||
/// Note that most derived classes will have standard API for allocation
|
||||
/// and handle manipulation. Derived classes that don't support instantiation
|
||||
/// should use HD_DECLARE_DATASOURCE_ABSTRACT, which omits the
|
||||
/// definition of ::New().
|
||||
///
|
||||
class HdDataSourceBase
|
||||
{
|
||||
public:
|
||||
HD_DECLARE_DATASOURCE_ABSTRACT(HdDataSourceBase)
|
||||
|
||||
HD_API
|
||||
virtual ~HdDataSourceBase() = 0;
|
||||
};
|
||||
|
||||
HD_DECLARE_DATASOURCE_HANDLES(HdDataSourceBase);
|
||||
|
||||
/// \class HdContainerDataSource
|
||||
///
|
||||
/// A datasource representing structured (named, hierarchical) data, for
|
||||
/// example a geometric primitive or a sub-object like a material definition.
|
||||
/// Note that implementations are responsible for providing cache invalidation,
|
||||
/// if necessary.
|
||||
///
|
||||
class HdContainerDataSource : public HdDataSourceBase
|
||||
{
|
||||
public:
|
||||
HD_DECLARE_DATASOURCE_ABSTRACT(HdContainerDataSource);
|
||||
|
||||
/// Returns \c true if the container has a child datasource of the given
|
||||
/// name, in which case \p Get(name) is expected to be non-null. This call
|
||||
/// is expected to be threadsafe.
|
||||
virtual bool Has(const TfToken &name) = 0;
|
||||
|
||||
/// Returns the list of names for which \p Get(...) is expected to return
|
||||
/// a non-null value. This call is expected to be threadsafe.
|
||||
virtual TfTokenVector GetNames() = 0;
|
||||
|
||||
/// Returns the child datasource of the given name. This call is expected
|
||||
/// to be threadsafe.
|
||||
virtual HdDataSourceBaseHandle Get(const TfToken &name) = 0;
|
||||
|
||||
/// A convenience function: given \p container, return the descendant
|
||||
/// identified by \p locator, which may be at any depth. Returns
|
||||
/// \p container itself on an empty locator, or null if \p locator doesn't
|
||||
/// identify a valid descendant.
|
||||
HD_API
|
||||
static HdDataSourceBaseHandle Get(
|
||||
const Handle &container,
|
||||
const HdDataSourceLocator &locator);
|
||||
};
|
||||
|
||||
HD_DECLARE_DATASOURCE_HANDLES(HdContainerDataSource);
|
||||
|
||||
/// \class HdVectorDataSource
|
||||
///
|
||||
/// A datasource representing indexed data. This should be used when a scene
|
||||
/// index is expected to manipulate the indexing; for array-valued data, a
|
||||
/// \p HdSampledDataSource can be used instead. Note that implementations are
|
||||
/// responsible for providing cache invalidation, if necessary.
|
||||
///
|
||||
class HdVectorDataSource : public HdDataSourceBase
|
||||
{
|
||||
public:
|
||||
HD_DECLARE_DATASOURCE_ABSTRACT(HdVectorDataSource);
|
||||
|
||||
/// Return the number of elements in this datasource. This call is
|
||||
/// expected to be threadsafe.
|
||||
virtual size_t GetNumElements() = 0;
|
||||
|
||||
/// Return the element at position \p element in this datasource. This
|
||||
/// is expected to return non-null for the range [0, \p numElements).
|
||||
/// This call is expected to be threadsafe.
|
||||
virtual HdDataSourceBaseHandle GetElement(size_t element) = 0;
|
||||
};
|
||||
|
||||
HD_DECLARE_DATASOURCE_HANDLES(HdVectorDataSource);
|
||||
|
||||
/// \class HdSampledDataSource
|
||||
///
|
||||
/// A datasource representing time-sampled values. Note that implementations
|
||||
/// are responsible for providing cache invalidation, if necessary.
|
||||
///
|
||||
class HdSampledDataSource : public HdDataSourceBase
|
||||
{
|
||||
public:
|
||||
HD_DECLARE_DATASOURCE_ABSTRACT(HdSampledDataSource);
|
||||
using Time = float;
|
||||
|
||||
/// Returns the value of this data source at frame-relative time
|
||||
/// \p shutterOffset. The caller does not track the frame; the scene
|
||||
/// index producing this datasource is responsible for that, if applicable.
|
||||
/// Note that, although this call returns a VtValue for each shutter
|
||||
/// offset, the type of the held value is expected to be the same across
|
||||
/// all shutter offsets. This call is expected to be threadsafe.
|
||||
virtual VtValue GetValue(Time shutterOffset) = 0;
|
||||
|
||||
/// Given a shutter window of interest (\p startTime and \p endTime
|
||||
/// relative to the current frame), return a list of sample times for the
|
||||
/// caller to query with GetValue such that the caller can reconstruct the
|
||||
/// signal over the shutter window. For a sample-based attribute, this
|
||||
/// might be a list of times when samples are defined. For a procedural
|
||||
/// scene, this might be a generated distribution. Note that the returned
|
||||
/// samples don't need to be within \p startTime and \p endTime; if
|
||||
/// a boundary sample is outside of the window, implementers can return it,
|
||||
/// and callers should expect it and interpolate to \p startTime or
|
||||
/// \p endTime accordingly. If this call returns \p true, the caller is
|
||||
/// expected to pass the list of \p outSampleTimes to \p GetValue. If this
|
||||
/// call returns \p false, this value is uniform across the shutter window
|
||||
/// and the caller should call \p GetValue(0) to get that uniform value.
|
||||
virtual bool GetContributingSampleTimesForInterval(
|
||||
Time startTime,
|
||||
Time endTime,
|
||||
std::vector<Time> * outSampleTimes) = 0;
|
||||
};
|
||||
|
||||
HD_DECLARE_DATASOURCE_HANDLES(HdSampledDataSource);
|
||||
|
||||
/// \class HdTypedSampledDataSource
|
||||
///
|
||||
/// A datasource representing a concretely-typed sampled value.
|
||||
///
|
||||
template <typename T>
|
||||
class HdTypedSampledDataSource : public HdSampledDataSource
|
||||
{
|
||||
public:
|
||||
HD_DECLARE_DATASOURCE_ABSTRACT(HdTypedSampledDataSource<T>);
|
||||
using Type = T;
|
||||
|
||||
/// Returns the value of this data source at frame-relative time
|
||||
/// \p shutterOffset, as type \p T.
|
||||
virtual T GetTypedValue(Time shutterOffset) = 0;
|
||||
};
|
||||
|
||||
|
||||
/// \class HdBlockDataSource
|
||||
///
|
||||
/// A datasource representing the absence of a datasource. If a container has
|
||||
/// a child datasource which is a block datasource, that's equivalent to that
|
||||
/// child being null. This type is useful when composing containers, where a
|
||||
/// block might shadow sampled data, and sampled data might shadow nullptr.
|
||||
///
|
||||
class HdBlockDataSource : public HdDataSourceBase
|
||||
{
|
||||
public:
|
||||
HD_DECLARE_DATASOURCE(HdBlockDataSource);
|
||||
|
||||
HdBlockDataSource(){}
|
||||
};
|
||||
|
||||
HD_DECLARE_DATASOURCE_HANDLES(HdBlockDataSource);
|
||||
|
||||
// Utilities //////////////////////////////////////////////////////////////////
|
||||
|
||||
/// Print a datasource to a stream, for debugging/testing.
|
||||
void HdDebugPrintDataSource(
|
||||
std::ostream &,
|
||||
HdDataSourceBaseHandle,
|
||||
int indentLevel = 0);
|
||||
|
||||
/// Print a datasource to stdout, for debugging/testing
|
||||
void HdDebugPrintDataSource(HdDataSourceBaseHandle, int indentLevel = 0);
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_DATASOURCE_H
|
||||
@@ -0,0 +1,136 @@
|
||||
//
|
||||
// Copyright 2021 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_DATA_SOURCE_LEGACY_PRIM_H
|
||||
#define PXR_IMAGING_HD_DATA_SOURCE_LEGACY_PRIM_H
|
||||
|
||||
#include "pxr/imaging/hd/sceneIndex.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/base/tf/staticTokens.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdSceneDelegate;
|
||||
class HdExtComputationContext;
|
||||
|
||||
#define HD_LEGACY_PRIMTYPE_TOKENS \
|
||||
/* Bprims */ \
|
||||
(openvdbAsset) \
|
||||
(field3dAsset)
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdLegacyPrimTypeTokens, HD_API,
|
||||
HD_LEGACY_PRIMTYPE_TOKENS);
|
||||
|
||||
/// \class HdExtComputationCallbackDataSource
|
||||
///
|
||||
/// This is a data source which holds a legacy ext computation. It is used
|
||||
/// only during emulation of legacy scene delegates but is exposed here as it
|
||||
/// is used by HdSceneIndexAdapterSceneDelegate for emulation of legacy
|
||||
/// render delegates.
|
||||
///
|
||||
class HdExtComputationCallbackDataSource : public HdDataSourceBase
|
||||
{
|
||||
public:
|
||||
HD_DECLARE_DATASOURCE(HdExtComputationCallbackDataSource);
|
||||
|
||||
HdExtComputationCallbackDataSource(
|
||||
const SdfPath &id, HdSceneDelegate *sceneDelegate)
|
||||
: _id(id), _sceneDelegate(sceneDelegate) {}
|
||||
|
||||
void Invoke(HdExtComputationContext *context);
|
||||
|
||||
private:
|
||||
SdfPath _id;
|
||||
HdSceneDelegate *_sceneDelegate;
|
||||
};
|
||||
|
||||
HD_DECLARE_DATASOURCE_HANDLES(HdExtComputationCallbackDataSource);
|
||||
|
||||
/// \class HdDataSourceLegacyPrim
|
||||
///
|
||||
/// This is an HdContainerDataSource which represents a prim-level data source
|
||||
/// for adapting HdSceneDelegate calls into the forms defined by HdSchemas
|
||||
/// during emulation of legacy scene delegates.
|
||||
///
|
||||
class HdDataSourceLegacyPrim : public HdContainerDataSource
|
||||
{
|
||||
public:
|
||||
HD_DECLARE_DATASOURCE(HdDataSourceLegacyPrim);
|
||||
|
||||
bool Has(const TfToken &name) override;
|
||||
TfTokenVector GetNames() override;
|
||||
HdDataSourceBaseHandle Get(const TfToken &name) override;
|
||||
|
||||
/// This clears internal cached values and is currently called only by
|
||||
/// HdLegacyPrimSceneIndex in response to its own DirtyPrims method
|
||||
void PrimDirtied(const HdDataSourceLocatorSet &locators);
|
||||
|
||||
/// Return which locators PrimDirtied will respond to...
|
||||
static const HdDataSourceLocatorSet &GetCachedLocators();
|
||||
|
||||
private:
|
||||
HdDataSourceLegacyPrim(
|
||||
SdfPath id,
|
||||
TfToken type,
|
||||
HdSceneDelegate *sceneDelegate);
|
||||
|
||||
HdDataSourceBaseHandle _GetPrimvarsDataSource();
|
||||
HdDataSourceBaseHandle _GetExtComputationPrimvarsDataSource();
|
||||
HdDataSourceBaseHandle _GetMaterialBindingDataSource();
|
||||
HdDataSourceBaseHandle _GetXformDataSource();
|
||||
HdDataSourceBaseHandle _GetMaterialDataSource();
|
||||
HdDataSourceBaseHandle _GetDisplayStyleDataSource();
|
||||
HdDataSourceBaseHandle _GetInstancedByDataSource();
|
||||
HdDataSourceBaseHandle _GetInstancerTopologyDataSource();
|
||||
HdDataSourceBaseHandle _GetVolumeFieldBindingDataSource();
|
||||
HdDataSourceBaseHandle _GetCoordSysBindingDataSource();
|
||||
HdDataSourceBaseHandle _GetVisibilityDataSource();
|
||||
HdDataSourceBaseHandle _GetPurposeDataSource();
|
||||
HdDataSourceBaseHandle _GetExtentDataSource();
|
||||
HdDataSourceBaseHandle _GetCategoriesDataSource();
|
||||
HdDataSourceBaseHandle _GetInstanceCategoriesDataSource();
|
||||
|
||||
private:
|
||||
SdfPath _id;
|
||||
TfToken _type;
|
||||
HdSceneDelegate *_sceneDelegate;
|
||||
|
||||
std::atomic_bool _primvarsBuilt;
|
||||
bool _extComputationPrimvarsBuilt : 1;
|
||||
|
||||
HdContainerDataSourceAtomicHandle _primvars;
|
||||
HdContainerDataSourceHandle _extComputationPrimvars;
|
||||
|
||||
// Note: _instancerTopology needs to be an atomic handle, since
|
||||
// some downstream customers of it (render index sync, hdSt instancer sync)
|
||||
// are not threadsafe.
|
||||
HdContainerDataSourceAtomicHandle _instancerTopology;
|
||||
};
|
||||
|
||||
HD_DECLARE_DATASOURCE_HANDLES(HdDataSourceLegacyPrim);
|
||||
|
||||
bool HdLegacyPrimTypeIsVolumeField(TfToken const &primType);
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,285 @@
|
||||
//
|
||||
// Copyright 2021 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_DATASOURCELOCATOR_H
|
||||
#define PXR_IMAGING_HD_DATASOURCELOCATOR_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
#include "pxr/base/tf/smallVector.h"
|
||||
#include "pxr/base/tf/hash.h"
|
||||
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// \class HdDataSourceLocator
|
||||
///
|
||||
/// Represents an object that can identify the location of a data source.
|
||||
/// Data Source Locators are meant to be short lists of tokens that, taken
|
||||
/// together, can represent the location of a given data source.
|
||||
///
|
||||
class HdDataSourceLocator
|
||||
{
|
||||
public:
|
||||
|
||||
/// Returns a common empty locator.
|
||||
///
|
||||
/// This is an often needed locator and is quicker to get this way rather
|
||||
/// than creating your own empty one.
|
||||
HD_API
|
||||
static const HdDataSourceLocator &EmptyLocator();
|
||||
|
||||
/// Creates an empty locator.
|
||||
///
|
||||
/// If all you need is an empty locator, see EmptyLocator().
|
||||
///
|
||||
HD_API
|
||||
HdDataSourceLocator();
|
||||
|
||||
/// The following constructors take a number of tokens and build a locator
|
||||
/// with the apporpriate number of tokens in the given order.
|
||||
///
|
||||
/// These are convenience constructors for commonly used patterns. Note
|
||||
/// that we generally expect a very small number of entities in a locator,
|
||||
/// which is why we haven't gone with a more general N-way solution.
|
||||
///
|
||||
HD_API
|
||||
explicit HdDataSourceLocator(const TfToken &t1);
|
||||
HD_API
|
||||
HdDataSourceLocator(const TfToken &t1, const TfToken &t2);
|
||||
HD_API
|
||||
HdDataSourceLocator(const TfToken &t1, const TfToken &t2,
|
||||
const TfToken &t3);
|
||||
HD_API
|
||||
HdDataSourceLocator(const TfToken &t1, const TfToken &t2, const TfToken &t3,
|
||||
const TfToken &t4);
|
||||
HD_API
|
||||
HdDataSourceLocator(const TfToken &t1, const TfToken &t2, const TfToken &t3,
|
||||
const TfToken &t4, const TfToken &t5);
|
||||
HD_API
|
||||
HdDataSourceLocator(const TfToken &t1, const TfToken &t2, const TfToken &t3,
|
||||
const TfToken &t4, const TfToken &t5,
|
||||
const TfToken &t6);
|
||||
|
||||
/// Builds a data source locator from the \p tokens array of the given
|
||||
/// \p count.
|
||||
///
|
||||
HD_API
|
||||
HdDataSourceLocator(size_t count, const TfToken *tokens);
|
||||
|
||||
/// Copy constructor
|
||||
HdDataSourceLocator(const HdDataSourceLocator &rhs) = default;
|
||||
|
||||
/// Returns the number of elements (tokens) in this data source.
|
||||
HD_API
|
||||
size_t GetElementCount() const;
|
||||
|
||||
/// Returns the element (token) at index \p i.
|
||||
///
|
||||
/// If \p i is out of bounds, the behavior is undefined.
|
||||
///
|
||||
HD_API
|
||||
const TfToken &GetElement(size_t i) const;
|
||||
|
||||
/// Returns the first element, or empty token if none.
|
||||
HD_API
|
||||
const TfToken &GetFirstElement() const;
|
||||
|
||||
/// Returns the last element, or empty token if none.
|
||||
HD_API
|
||||
const TfToken &GetLastElement() const;
|
||||
|
||||
/// Returns a copy of this data source locator with the last element
|
||||
/// replaced by the one given by \p name. If this data source locator is
|
||||
/// empty an identical copy is returned.
|
||||
///
|
||||
HD_API
|
||||
HdDataSourceLocator ReplaceLastElement(const TfToken &name) const;
|
||||
|
||||
/// Returns a copy of this data source locator with the last element
|
||||
/// removed.
|
||||
///
|
||||
HD_API
|
||||
HdDataSourceLocator RemoveLastElement() const;
|
||||
|
||||
/// Returns a copy of this data source locator with the first element
|
||||
/// removed.
|
||||
///
|
||||
HD_API
|
||||
HdDataSourceLocator RemoveFirstElement() const;
|
||||
|
||||
/// Appends \p name to this data source locator.
|
||||
HD_API
|
||||
HdDataSourceLocator Append(const TfToken &name) const;
|
||||
|
||||
/// Appends all of the elements in \p locator to this data source locator.
|
||||
HD_API
|
||||
HdDataSourceLocator Append(const HdDataSourceLocator &locator) const;
|
||||
|
||||
/// Prepends \p name to this data source locator.
|
||||
HD_API
|
||||
HdDataSourceLocator Prepend(const TfToken &name) const;
|
||||
|
||||
/// Prepends all of the elements in \p locator to this data source locator.
|
||||
HD_API
|
||||
HdDataSourceLocator Prepend(const HdDataSourceLocator &locator) const;
|
||||
|
||||
/// Returns \c true if this data source locator has \p prefix as a prefix.
|
||||
HD_API
|
||||
bool HasPrefix(const HdDataSourceLocator &prefix) const;
|
||||
|
||||
/// Returns a data source locator that represents the common prefix
|
||||
/// between this data source and \p other.
|
||||
///
|
||||
HD_API
|
||||
HdDataSourceLocator GetCommonPrefix(const HdDataSourceLocator &other) const;
|
||||
|
||||
/// Returns a copy of this data source locator with \p oldPrefix replaced
|
||||
/// by \p newPrefix.
|
||||
///
|
||||
HD_API
|
||||
HdDataSourceLocator ReplacePrefix(
|
||||
const HdDataSourceLocator &oldPrefix,
|
||||
const HdDataSourceLocator &newPrefix) const;
|
||||
|
||||
/// Returns \c true if either this or other are equal to or contain one
|
||||
/// another
|
||||
///
|
||||
HD_API
|
||||
bool Intersects(const HdDataSourceLocator &other) const;
|
||||
|
||||
inline bool operator==(const HdDataSourceLocator &rhs) const {
|
||||
return _tokens == rhs._tokens;
|
||||
}
|
||||
|
||||
inline bool operator!=(const HdDataSourceLocator &rhs) const {
|
||||
return _tokens != rhs._tokens;
|
||||
}
|
||||
|
||||
HD_API
|
||||
bool operator<(const HdDataSourceLocator &rhs) const;
|
||||
|
||||
inline bool IsEmpty() const {
|
||||
return _tokens.empty();
|
||||
}
|
||||
|
||||
/// Returns a string representation of this data source locator with the
|
||||
/// given \p delimiter inserted between each element.
|
||||
///
|
||||
HD_API
|
||||
std::string GetString(const char *delimiter = "/") const;
|
||||
|
||||
template <class HashState>
|
||||
friend void TfHashAppend(HashState &h, HdDataSourceLocator const &myObj) {
|
||||
h.AppendContiguous(myObj._tokens.data(), myObj._tokens.size());
|
||||
}
|
||||
|
||||
inline size_t Hash() const;
|
||||
|
||||
private:
|
||||
using _TokenVector = TfSmallVector<TfToken, 6>;
|
||||
_TokenVector _tokens;
|
||||
};
|
||||
|
||||
inline size_t
|
||||
HdDataSourceLocator::Hash() const
|
||||
{
|
||||
return TfHash()(*this);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
///
|
||||
/// \class HdDataSourceLocatorSet
|
||||
///
|
||||
/// Represents a set of data source locators.
|
||||
///
|
||||
class HdDataSourceLocatorSet
|
||||
{
|
||||
private:
|
||||
using _Locators = TfSmallVector<HdDataSourceLocator, 8>;
|
||||
public:
|
||||
using const_iterator = typename _Locators::const_iterator;
|
||||
|
||||
explicit HdDataSourceLocatorSet() {}
|
||||
|
||||
HdDataSourceLocatorSet(const HdDataSourceLocator &locator);
|
||||
|
||||
// Initializer list constructor.
|
||||
HdDataSourceLocatorSet(
|
||||
const std::initializer_list<const HdDataSourceLocator> &l);
|
||||
|
||||
/// Copy Ctor
|
||||
HdDataSourceLocatorSet(const HdDataSourceLocatorSet &rhs) = default;
|
||||
|
||||
/// Move Ctor.
|
||||
HdDataSourceLocatorSet(HdDataSourceLocatorSet &&rhs) = default;
|
||||
|
||||
/// Move assignment operator.
|
||||
HdDataSourceLocatorSet &operator=(HdDataSourceLocatorSet &&rhs) = default;
|
||||
|
||||
/// Copy assignment operator.
|
||||
HdDataSourceLocatorSet &operator=(const HdDataSourceLocatorSet &rhs)
|
||||
= default;
|
||||
|
||||
HD_API
|
||||
void insert(const HdDataSourceLocator &locator);
|
||||
HD_API
|
||||
void insert(const HdDataSourceLocatorSet &locatorSet);
|
||||
|
||||
/// append() is semantically equivalent to insert(), but works much faster
|
||||
/// if \p locator would be added to the end of the set, lexicographically.
|
||||
HD_API
|
||||
void append(const HdDataSourceLocator &locator);
|
||||
|
||||
bool operator==(const HdDataSourceLocatorSet &rhs) const {
|
||||
return _locators == rhs._locators;
|
||||
}
|
||||
|
||||
bool operator!=(const HdDataSourceLocatorSet &rhs) const {
|
||||
return !(*this == rhs);
|
||||
}
|
||||
|
||||
HD_API
|
||||
const_iterator begin() const;
|
||||
HD_API
|
||||
const_iterator end() const;
|
||||
|
||||
HD_API
|
||||
bool Intersects(const HdDataSourceLocator &locator) const;
|
||||
HD_API
|
||||
bool Intersects(const HdDataSourceLocatorSet &locatorSet) const;
|
||||
HD_API
|
||||
bool IsEmpty() const;
|
||||
|
||||
private:
|
||||
void _InsertAndDeleteSuffixes(_Locators::iterator *position,
|
||||
const HdDataSourceLocator &locator);
|
||||
|
||||
_Locators _locators;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_DATASOURCELOCATOR_H
|
||||
@@ -0,0 +1,120 @@
|
||||
//
|
||||
// Copyright 2021 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_DATASOURCETYPEDEFS_H
|
||||
#define PXR_IMAGING_HD_DATASOURCETYPEDEFS_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
|
||||
#include "pxr/imaging/hd/dataSource.h"
|
||||
#include "pxr/imaging/hd/dataSourceLocator.h"
|
||||
#include "pxr/imaging/hd/types.h"
|
||||
|
||||
#include "pxr/base/gf/matrix4d.h"
|
||||
#include "pxr/base/gf/vec2f.h"
|
||||
#include "pxr/base/tf/staticTokens.h"
|
||||
#include "pxr/base/vt/array.h"
|
||||
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
#include "pxr/usd/sdf/assetPath.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
// Numeric
|
||||
using HdIntDataSource = HdTypedSampledDataSource<int>;
|
||||
using HdIntDataSourceHandle = HdIntDataSource::Handle;
|
||||
using HdIntArrayDataSource = HdTypedSampledDataSource<VtArray<int>>;
|
||||
using HdIntArrayDataSourceHandle = HdIntArrayDataSource::Handle;
|
||||
|
||||
using HdSizetDataSource = HdTypedSampledDataSource<size_t>;
|
||||
using HdSizetDataSourceHandle = HdSizetDataSource::Handle;
|
||||
|
||||
using HdFloatDataSource = HdTypedSampledDataSource<float>;
|
||||
using HdFloatDataSourceHandle = HdFloatDataSource::Handle;
|
||||
using HdFloatArrayDataSource = HdTypedSampledDataSource<VtArray<float>>;
|
||||
using HdFloatArrayDataSourceHandle = HdFloatArrayDataSource::Handle;
|
||||
|
||||
// Bool
|
||||
using HdBoolDataSource = HdTypedSampledDataSource<bool>;
|
||||
using HdBoolDataSourceHandle = HdBoolDataSource::Handle;
|
||||
using HdBoolArrayDataSource = HdTypedSampledDataSource<VtArray<bool>>;
|
||||
using HdBoolArrayDataSourceHandle = HdBoolArrayDataSource::Handle;
|
||||
|
||||
// String
|
||||
using HdTokenDataSource = HdTypedSampledDataSource<TfToken>;
|
||||
using HdTokenDataSourceHandle = HdTokenDataSource::Handle;
|
||||
using HdTokenArrayDataSource = HdTypedSampledDataSource<VtArray<TfToken>>;
|
||||
using HdTokenArrayDataSourceHandle = HdTokenArrayDataSource::Handle;
|
||||
|
||||
using HdPathDataSource = HdTypedSampledDataSource<SdfPath>;
|
||||
using HdPathDataSourceHandle = HdPathDataSource::Handle;
|
||||
using HdPathArrayDataSource = HdTypedSampledDataSource<VtArray<SdfPath>>;
|
||||
using HdPathArrayDataSourceHandle = HdPathArrayDataSource::Handle;
|
||||
|
||||
using HdStringDataSource = HdTypedSampledDataSource<std::string>;
|
||||
using HdStringDataSourceHandle = HdStringDataSource::Handle;
|
||||
|
||||
using HdAssetPathDataSource = HdTypedSampledDataSource<SdfAssetPath>;
|
||||
using HdAssetPathDataSourceHandle = HdAssetPathDataSource::Handle;
|
||||
|
||||
// Linear algebra
|
||||
using HdVec2iDataSource = HdTypedSampledDataSource<GfVec2i>;
|
||||
using HdVec2iDataSourceHandle = HdVec2iDataSource::Handle;
|
||||
using HdVec2fDataSource = HdTypedSampledDataSource<GfVec2f>;
|
||||
using HdVec2fDataSourceHandle = HdVec2fDataSource::Handle;
|
||||
using HdVec2fArrayDataSource = HdTypedSampledDataSource<VtArray<GfVec2f>>;
|
||||
using HdVec2fArrayDataSourceHandle = HdVec2fArrayDataSource::Handle;
|
||||
|
||||
using HdVec3iDataSource = HdTypedSampledDataSource<GfVec3i>;
|
||||
using HdVec3iDataSourceHandle = HdVec3iDataSource::Handle;
|
||||
using HdVec3fDataSource = HdTypedSampledDataSource<GfVec3f>;
|
||||
using HdVec3fDataSourceHandle = HdVec3fDataSource::Handle;
|
||||
using HdVec3fArrayDataSource = HdTypedSampledDataSource<VtArray<GfVec3f>>;
|
||||
using HdVec3fArrayDataSourceHandle = HdVec3fArrayDataSource::Handle;
|
||||
|
||||
using HdVec4iDataSource = HdTypedSampledDataSource<GfVec4i>;
|
||||
using HdVec4iDataSourceHandle = HdVec4iDataSource::Handle;
|
||||
using HdVec3dDataSource = HdTypedSampledDataSource<GfVec3d>;
|
||||
using HdVec3dDataSourceHandle = HdVec3dDataSource::Handle;
|
||||
using HdVec3dArrayDataSource = HdTypedSampledDataSource<VtArray<GfVec3d>>;
|
||||
using HdVec3dArrayDataSourceHandle = HdVec3dArrayDataSource::Handle;
|
||||
|
||||
using HdMatrixDataSource = HdTypedSampledDataSource<GfMatrix4d>;
|
||||
using HdMatrixDataSourceHandle = HdMatrixDataSource::Handle;
|
||||
using HdMatrixArrayDataSource = HdTypedSampledDataSource<VtArray<GfMatrix4d>>;
|
||||
using HdMatrixArrayDataSourceHandle = HdMatrixArrayDataSource::Handle;
|
||||
|
||||
// Locator
|
||||
using HdLocatorDataSource = HdTypedSampledDataSource<HdDataSourceLocator>;
|
||||
using HdLocatorDataSourceHandle = HdLocatorDataSource::Handle;
|
||||
|
||||
// Enum
|
||||
using HdFormatDataSource = HdTypedSampledDataSource<HdFormat>;
|
||||
using HdFormatDataSourceHandle = HdFormatDataSource::Handle;
|
||||
|
||||
using HdTupleTypeDataSource = HdTypedSampledDataSource<HdTupleType>;
|
||||
using HdTupleTypeDataSourceHandle = HdTupleTypeDataSource::Handle;
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_DATASOURCETYPEDEFS_H
|
||||
@@ -0,0 +1,76 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_DEBUG_CODES_H
|
||||
#define PXR_IMAGING_HD_DEBUG_CODES_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/base/tf/debug.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
TF_DEBUG_CODES(
|
||||
HD_BPRIM_ADDED,
|
||||
HD_BPRIM_REMOVED,
|
||||
HD_BUFFER_ARRAY_INFO,
|
||||
HD_BUFFER_ARRAY_RANGE_CLEANED,
|
||||
HD_CACHE_HITS,
|
||||
HD_CACHE_MISSES,
|
||||
HD_COUNTER_CHANGED,
|
||||
HD_DIRTY_ALL_COLLECTIONS,
|
||||
HD_DIRTY_LIST,
|
||||
HD_DISABLE_MULTITHREADED_RPRIM_SYNC,
|
||||
HD_DRAWITEMS_CULLED,
|
||||
HD_ENGINE_PHASE_INFO,
|
||||
HD_EXT_COMPUTATION_ADDED,
|
||||
HD_EXT_COMPUTATION_REMOVED,
|
||||
HD_EXT_COMPUTATION_UPDATED,
|
||||
HD_EXT_COMPUTATION_EXECUTION,
|
||||
HD_FREEZE_CULL_FRUSTUM,
|
||||
HD_INSTANCER_ADDED,
|
||||
HD_INSTANCER_CLEANED,
|
||||
HD_INSTANCER_REMOVED,
|
||||
HD_INSTANCER_UPDATED,
|
||||
HD_MDI,
|
||||
HD_RENDER_SETTINGS,
|
||||
HD_RPRIM_ADDED,
|
||||
HD_RPRIM_CLEANED,
|
||||
HD_RPRIM_REMOVED,
|
||||
HD_RPRIM_UPDATED,
|
||||
HD_SAFE_MODE,
|
||||
HD_SELECTION_UPDATE,
|
||||
HD_SHARED_EXT_COMPUTATION_DATA,
|
||||
HD_SPRIM_ADDED,
|
||||
HD_SPRIM_REMOVED,
|
||||
HD_SYNC_ALL,
|
||||
HD_TASK_ADDED,
|
||||
HD_TASK_REMOVED,
|
||||
HD_VARYING_STATE
|
||||
);
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_DEBUG_CODES_H
|
||||
@@ -0,0 +1,78 @@
|
||||
//
|
||||
// Copyright 2021 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// This file is generated by a script. Do not edit directly. Edit the
|
||||
// schema.template.h file to make changes.
|
||||
|
||||
#ifndef PXR_IMAGING_HD_DEPENDENCIES_SCHEMA_H
|
||||
#define PXR_IMAGING_HD_DEPENDENCIES_SCHEMA_H
|
||||
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
|
||||
#include "pxr/imaging/hd/dependencySchema.h"
|
||||
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define HDDEPENDENCIES_SCHEMA_TOKENS \
|
||||
(__dependencies) \
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdDependenciesSchemaTokens, HD_API,
|
||||
HDDEPENDENCIES_SCHEMA_TOKENS);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class HdDependenciesSchema : public HdSchema
|
||||
{
|
||||
public:
|
||||
HdDependenciesSchema(HdContainerDataSourceHandle container)
|
||||
: HdSchema(container) {}
|
||||
|
||||
using EntryPair = std::pair<TfToken, HdDependencySchema>;
|
||||
using EntryVector = TfSmallVector<EntryPair, 8>;
|
||||
|
||||
EntryVector GetEntries();
|
||||
|
||||
|
||||
/// Retrieves a container data source with the schema's default name token
|
||||
/// "__dependencies" from the parent container and constructs a
|
||||
/// HdDependenciesSchema 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 HdDependenciesSchema GetFromParent(
|
||||
const HdContainerDataSourceHandle &fromParentContainer);
|
||||
|
||||
/// 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();
|
||||
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,112 @@
|
||||
//
|
||||
// Copyright 2021 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// This file is generated by a script. Do not edit directly. Edit the
|
||||
// schema.template.h file to make changes.
|
||||
|
||||
#ifndef PXR_IMAGING_HD_DEPENDENCY_SCHEMA_H
|
||||
#define PXR_IMAGING_HD_DEPENDENCY_SCHEMA_H
|
||||
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
|
||||
#include "pxr/imaging/hd/schema.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define HDDEPENDENCY_SCHEMA_TOKENS \
|
||||
(dependedOnPrimPath) \
|
||||
(dependedOnDataSourceLocator) \
|
||||
(affectedDataSourceLocator) \
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdDependencySchemaTokens, HD_API,
|
||||
HDDEPENDENCY_SCHEMA_TOKENS);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class HdDependencySchema : public HdSchema
|
||||
{
|
||||
public:
|
||||
HdDependencySchema(HdContainerDataSourceHandle container)
|
||||
: HdSchema(container) {}
|
||||
|
||||
//ACCESSORS
|
||||
|
||||
HD_API
|
||||
HdPathDataSourceHandle GetDependedOnPrimPath();
|
||||
HD_API
|
||||
HdLocatorDataSourceHandle GetDependedOnDataSourceLocator();
|
||||
HD_API
|
||||
HdLocatorDataSourceHandle GetAffectedDataSourceLocator();
|
||||
|
||||
// RETRIEVING AND CONSTRUCTING
|
||||
|
||||
/// 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 HdPathDataSourceHandle &dependedOnPrimPath,
|
||||
const HdLocatorDataSourceHandle &dependedOnDataSourceLocator,
|
||||
const HdLocatorDataSourceHandle &affectedDataSourceLocator
|
||||
);
|
||||
|
||||
/// \class HdDependencySchema::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 &SetDependedOnPrimPath(
|
||||
const HdPathDataSourceHandle &dependedOnPrimPath);
|
||||
HD_API
|
||||
Builder &SetDependedOnDataSourceLocator(
|
||||
const HdLocatorDataSourceHandle &dependedOnDataSourceLocator);
|
||||
HD_API
|
||||
Builder &SetAffectedDataSourceLocator(
|
||||
const HdLocatorDataSourceHandle &affectedDataSourceLocator);
|
||||
|
||||
/// Returns a container data source containing the members set thus far.
|
||||
HD_API
|
||||
HdContainerDataSourceHandle Build();
|
||||
|
||||
private:
|
||||
HdPathDataSourceHandle _dependedOnPrimPath;
|
||||
HdLocatorDataSourceHandle _dependedOnDataSourceLocator;
|
||||
HdLocatorDataSourceHandle _affectedDataSourceLocator;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,64 @@
|
||||
//
|
||||
// Copyright 2021 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_DIRTY_BITS_TRANSLATOR_H
|
||||
#define PXR_IMAGING_HD_DIRTY_BITS_TRANSLATOR_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
#include "pxr/imaging/hd/dataSourceLocator.h"
|
||||
#include "pxr/imaging/hd/types.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// \class HdDirtyBitsTranslator
|
||||
///
|
||||
/// A set of optimized functions for translating between dirty bits and
|
||||
/// datasource locators for different prim types.
|
||||
class HdDirtyBitsTranslator
|
||||
{
|
||||
public:
|
||||
// Dirty bits to locators.
|
||||
static void RprimDirtyBitsToLocatorSet(TfToken const& primType,
|
||||
const HdDirtyBits bits, HdDataSourceLocatorSet *set);
|
||||
static void SprimDirtyBitsToLocatorSet(TfToken const& primType,
|
||||
const HdDirtyBits bits, HdDataSourceLocatorSet *set);
|
||||
static void BprimDirtyBitsToLocatorSet(TfToken const& primType,
|
||||
const HdDirtyBits bits, HdDataSourceLocatorSet *set);
|
||||
static void InstancerDirtyBitsToLocatorSet(TfToken const& primType,
|
||||
const HdDirtyBits bits, HdDataSourceLocatorSet *set);
|
||||
|
||||
// Locators to dirty bits.
|
||||
static HdDirtyBits RprimLocatorSetToDirtyBits(TfToken const& primType,
|
||||
HdDataSourceLocatorSet const& set);
|
||||
static HdDirtyBits SprimLocatorSetToDirtyBits(TfToken const& primType,
|
||||
HdDataSourceLocatorSet const& set);
|
||||
static HdDirtyBits BprimLocatorSetToDirtyBits(TfToken const& primType,
|
||||
HdDataSourceLocatorSet const& set);
|
||||
static HdDirtyBits InstancerLocatorSetToDirtyBits(TfToken const& primType,
|
||||
HdDataSourceLocatorSet const& set);
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_DIRTY_BITS_TRANSLATOR_H
|
||||
@@ -0,0 +1,154 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_DIRTY_LIST_H
|
||||
#define PXR_IMAGING_HD_DIRTY_LIST_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/repr.h"
|
||||
#include "pxr/imaging/hd/rprimCollection.h"
|
||||
#include "pxr/imaging/hd/types.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdRenderIndex;
|
||||
class HdChangeTracker;
|
||||
using HdReprSelectorVector = std::vector<HdReprSelector>;
|
||||
|
||||
/// \class HdDirtyList
|
||||
///
|
||||
/// Used for faster iteration of dirty Rprims by the render index.
|
||||
///
|
||||
/// GetDirtyRprims() implicitly refreshes and caches the list if needed.
|
||||
/// The returning prims list will be used for sync.
|
||||
///
|
||||
/// DirtyList construction can expensive. We have 3 layer
|
||||
/// versioning to make it efficient.
|
||||
///
|
||||
/// 1. Nothing changed since last time (super fast),
|
||||
/// no prims need to be synced.
|
||||
/// DirtyList returns empty vector GetDirtyRprims.
|
||||
/// This can be detected by HdChangeTracker::GetSceneStateVersion.
|
||||
/// It's incremented when any change made on any prim.
|
||||
///
|
||||
/// 2. Constantly updating Prims in a stable set (fast)
|
||||
/// when munging or playing back, the same set of prims are being updated,
|
||||
/// while the remaining prims (could be huge -- for example a large set)
|
||||
/// are static.
|
||||
/// Those animating prims can be distinguished by the Varying bit. The Varying
|
||||
/// bit is set on a prim when any dirty bit is set, and stays even after
|
||||
/// cleaning the scene dirty bits, until HdChangeTracker::ResetVaryingState
|
||||
/// clears it out.
|
||||
///
|
||||
/// DirtyList caches those prims in a list at the first time (described in 3),
|
||||
/// and returns the list for the subsequent queries. Since that list is
|
||||
/// conservatively picked by the Varying bit instead of the actual DirtyBits
|
||||
/// needed for various reprs, consumer of DirtyList needs to check the
|
||||
/// dirtybits again (this is a common pattern in HdRprim, HdMesh and other).
|
||||
///
|
||||
/// 3. Varying state changed (medium cost)
|
||||
/// when a exisitng prim newly starts updating (start munging), or when
|
||||
/// a majority of the dirtylist stop updating, we need to reconstruct
|
||||
/// the dirtylist. HdChangeTracker::GetVaryingStateVersion() tells the
|
||||
/// right timing to refresh, by comparing the cached version number in
|
||||
/// the dirtylist.
|
||||
///
|
||||
/// To construct a dirtylist, the Varying bit is checked instead of other
|
||||
/// dirtybits, since effective dirtybits may differ over prims, by prim
|
||||
/// type (mesh vs curve) or by per-prim repr style (flat vs smooth)
|
||||
///
|
||||
/// example: [x]=Varying [x*]=Dirty,Varying
|
||||
///
|
||||
/// say in change tracker:
|
||||
/// A B C D E [F*] [G] [H*] [I*] [J] [K] L M N ...
|
||||
/// then the dirtylist will be:
|
||||
/// F*, G, H*, I*, J, K
|
||||
///
|
||||
/// Note that G, J and K are not dirty, but it exists in the dirtylist.
|
||||
/// This optimization gives the maximum efficiency when all of Varying
|
||||
/// prims are being updated.
|
||||
///
|
||||
/// 4. Initial creation, filter changes (most expensive)
|
||||
/// If we fail to early out all the above condition, such as when we add
|
||||
/// new prims or switch the render tag set, all prims should be
|
||||
/// passed down to HdRenderIndex::Sync, except ones we know that are
|
||||
/// completely clean. Although it requires to sweep all prims in the
|
||||
/// render index, this traversal has already been optimized
|
||||
/// using the Gather utility.
|
||||
///
|
||||
class HdDirtyList {
|
||||
public:
|
||||
HD_API
|
||||
explicit HdDirtyList(HdRenderIndex &index);
|
||||
|
||||
/// Returns a reference of dirty rprim ids.
|
||||
/// If the change tracker hasn't changed any state since the last time
|
||||
/// GetDirtyRprims gets called, and if the tracked filtering parameters
|
||||
/// (set via UpdateRenderTagsAndReprSelectors) are the same, it simply
|
||||
/// returns an empty list.
|
||||
/// Otherwise depending on what changed, it will return a list of
|
||||
/// Rprim ids to be synced.
|
||||
/// Therefore, it is expected that GetDirtyRprims is called _only once_
|
||||
/// per render index sync.
|
||||
HD_API
|
||||
SdfPathVector const& GetDirtyRprims();
|
||||
|
||||
/// Updates the tracked filtering parameters.
|
||||
/// This typically comes from the tasks submitted to HdEngine::Execute.
|
||||
HD_API
|
||||
void UpdateRenderTagsAndReprSelectors(
|
||||
TfTokenVector const &tags, HdReprSelectorVector const &reprs);
|
||||
|
||||
/// Sets the flag to prune to dirty list to just the varying Rprims on
|
||||
/// the next call to GetDirtyRprims.
|
||||
void PruneToVaryingRprims() {
|
||||
_pruneDirtyList = true;
|
||||
}
|
||||
|
||||
private:
|
||||
HdChangeTracker & _GetChangeTracker() const;
|
||||
void _UpdateDirtyIdsIfNeeded();
|
||||
|
||||
// Note: Can't use a const ref to the renderIndex because
|
||||
// HdRenderIndex::GetRprimIds() isn't a const member fn.
|
||||
HdRenderIndex &_renderIndex;
|
||||
TfTokenVector _trackedRenderTags;
|
||||
HdReprSelectorVector _trackedReprs;
|
||||
SdfPathVector _dirtyIds;
|
||||
|
||||
unsigned int _sceneStateVersion;
|
||||
unsigned int _rprimIndexVersion;
|
||||
unsigned int _rprimRenderTagVersion;
|
||||
unsigned int _varyingStateVersion;
|
||||
|
||||
bool _rebuildDirtyList;
|
||||
bool _pruneDirtyList;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_DIRTY_LIST_H
|
||||
@@ -0,0 +1,269 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_DRAW_ITEM_H
|
||||
#define PXR_IMAGING_HD_DRAW_ITEM_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/perfLog.h"
|
||||
#include "pxr/imaging/hd/drawingCoord.h"
|
||||
#include "pxr/imaging/hd/rprimSharedData.h"
|
||||
|
||||
#include "pxr/imaging/hf/perfLog.h"
|
||||
|
||||
#include "pxr/base/gf/matrix4d.h"
|
||||
#include "pxr/base/gf/bbox3d.h"
|
||||
#include "pxr/base/gf/vec2i.h"
|
||||
#include "pxr/base/gf/vec4f.h"
|
||||
|
||||
#include <iosfwd>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// \class HdDrawItem
|
||||
///
|
||||
/// A draw item is a light-weight representation of an HdRprim's resources and
|
||||
/// material to be used for rendering. The visual representation (HdRepr) of an
|
||||
/// HdRprim might require multiple draw items.
|
||||
///
|
||||
/// HdDrawItem(s) are created by the HdRprim (HdMesh, HdBasisCurve, ..) for each
|
||||
/// HdRepr. The relevant compositional hierarchy is:
|
||||
///
|
||||
/// HdRprim
|
||||
/// |
|
||||
/// +--HdRepr(s)
|
||||
/// |
|
||||
/// +--HdDrawItem(s)
|
||||
///
|
||||
/// HdDrawItem(s) are consumed by HdRenderPass for its HdRprimCollection via
|
||||
/// HdRenderIndex::GetDrawItems.
|
||||
///
|
||||
/// \note
|
||||
/// Rendering backends may choose to specialize this class.
|
||||
///
|
||||
class HdDrawItem {
|
||||
public:
|
||||
HF_MALLOC_TAG_NEW("new HdDrawItem");
|
||||
|
||||
HD_API
|
||||
HdDrawItem(HdRprimSharedData const *sharedData);
|
||||
HD_API
|
||||
virtual ~HdDrawItem();
|
||||
|
||||
HD_API
|
||||
SdfPath const &GetRprimID() const { return _sharedData->rprimID; }
|
||||
|
||||
HD_API
|
||||
GfBBox3d const & GetBounds() const { return _sharedData->bounds; }
|
||||
|
||||
HD_API
|
||||
GfRange3d const& GetExtent() const {
|
||||
return _sharedData->bounds.GetRange();
|
||||
}
|
||||
|
||||
HD_API
|
||||
GfMatrix4d const& GetMatrix() const {
|
||||
return _sharedData->bounds.GetMatrix();
|
||||
}
|
||||
|
||||
/// Returns a BufferRange of constant-Primvar.
|
||||
HD_API
|
||||
HdBufferArrayRangeSharedPtr const &GetConstantPrimvarRange() const {
|
||||
return _sharedData->barContainer.Get(
|
||||
_drawingCoord.GetConstantPrimvarIndex());
|
||||
}
|
||||
|
||||
/// Returns the number of nested levels of instance primvars.
|
||||
HD_API
|
||||
int GetInstancePrimvarNumLevels() const {
|
||||
TF_VERIFY(_sharedData->instancerLevels != -1);
|
||||
return _sharedData->instancerLevels;
|
||||
}
|
||||
|
||||
/// Returns a BufferRange of instance-Primvars at \p level
|
||||
/// the level is assigned to nested instancers in a bottom-up manner.
|
||||
///
|
||||
/// example: (numLevels = 2)
|
||||
///
|
||||
/// instancerA (level = 1)
|
||||
/// |
|
||||
/// +-- instancerB (level = 0)
|
||||
/// |
|
||||
/// +-- mesh_prototype
|
||||
///
|
||||
HD_API
|
||||
HdBufferArrayRangeSharedPtr const &GetInstancePrimvarRange(int level) const {
|
||||
return _sharedData->barContainer.Get(
|
||||
_drawingCoord.GetInstancePrimvarIndex(level));
|
||||
}
|
||||
|
||||
/// Returns a BufferRange of instance-index indirection.
|
||||
HD_API
|
||||
HdBufferArrayRangeSharedPtr const &GetInstanceIndexRange() const {
|
||||
return _sharedData->barContainer.Get(
|
||||
_drawingCoord.GetInstanceIndexIndex());
|
||||
}
|
||||
|
||||
/// Returns a BufferRange of element-Primvars.
|
||||
HD_API
|
||||
HdBufferArrayRangeSharedPtr const &GetElementPrimvarRange() const {
|
||||
return _sharedData->barContainer.Get(
|
||||
_drawingCoord.GetElementPrimvarIndex());
|
||||
}
|
||||
|
||||
/// Returns a BufferArrayRange of topology.
|
||||
HD_API
|
||||
HdBufferArrayRangeSharedPtr const &GetTopologyRange() const {
|
||||
return _sharedData->barContainer.Get(
|
||||
_drawingCoord.GetTopologyIndex());
|
||||
}
|
||||
|
||||
HD_API
|
||||
HdBufferArrayRangeSharedPtr const &GetTopologyVisibilityRange() const {
|
||||
return _sharedData->barContainer.Get(
|
||||
_drawingCoord.GetTopologyVisibilityIndex());
|
||||
}
|
||||
|
||||
/// Returns a BufferArrayRange of vertex-primvars.
|
||||
HD_API
|
||||
HdBufferArrayRangeSharedPtr const &GetVertexPrimvarRange() const {
|
||||
return _sharedData->barContainer.Get(
|
||||
_drawingCoord.GetVertexPrimvarIndex());
|
||||
}
|
||||
|
||||
/// Returns a BufferArrayRange of varying primvars.
|
||||
HD_API
|
||||
HdBufferArrayRangeSharedPtr const &GetVaryingPrimvarRange() const {
|
||||
return _sharedData->barContainer.Get(
|
||||
_drawingCoord.GetVaryingPrimvarIndex());
|
||||
}
|
||||
|
||||
|
||||
/// Returns a BufferArrayRange of face-varying primvars.
|
||||
HD_API
|
||||
HdBufferArrayRangeSharedPtr const &GetFaceVaryingPrimvarRange() const {
|
||||
return _sharedData->barContainer.Get(
|
||||
_drawingCoord.GetFaceVaryingPrimvarIndex());
|
||||
}
|
||||
|
||||
HD_API
|
||||
HdDrawingCoord *GetDrawingCoord() {
|
||||
return &_drawingCoord;
|
||||
}
|
||||
|
||||
/// Returns the authored visibility, expressed by the delegate.
|
||||
HD_API
|
||||
bool GetVisible() const { return _sharedData->visible; }
|
||||
|
||||
HD_API
|
||||
TfToken const& GetMaterialTag() const {
|
||||
return _materialTag;
|
||||
}
|
||||
|
||||
HD_API
|
||||
void SetMaterialTag(TfToken const &materialTag) {
|
||||
_materialTag = materialTag;
|
||||
}
|
||||
|
||||
TopologyToPrimvarVector const &GetFvarTopologyToPrimvarVector() const {
|
||||
return _sharedData->fvarTopologyToPrimvarVector;
|
||||
}
|
||||
|
||||
/// Returns true if the drawItem has instancer.
|
||||
HD_API
|
||||
bool HasInstancer() const {
|
||||
TF_VERIFY(_sharedData->instancerLevels != -1);
|
||||
return (_sharedData->instancerLevels > 0);
|
||||
}
|
||||
|
||||
/// Returns the hash of the versions of underlying buffers. When the
|
||||
/// hash changes, it means the drawing coord might have been reassigned,
|
||||
/// so any drawing coord caching buffer (e.g. indirect dispatch buffer)
|
||||
/// has to be rebuilt at the moment.
|
||||
/// Note that this value is a hash, not sequential.
|
||||
HD_API
|
||||
size_t GetBufferArraysHash() const;
|
||||
|
||||
/// Returns the hash of the element offsets of the underlying BARs.
|
||||
/// When the hash changes, it means that any drawing coord caching
|
||||
/// buffer (e.g. the indirect dispatch buffer) has to be rebuilt.
|
||||
/// Note that this value is a hash, not sequential.
|
||||
HD_API
|
||||
size_t GetElementOffsetsHash() const;
|
||||
|
||||
/// Tests the intersection with the view projection matrix.
|
||||
/// Returns true if this drawItem is in the frustum.
|
||||
///
|
||||
/// XXX: Currently if this drawitem uses HW instancing, always returns true.
|
||||
HD_API
|
||||
bool IntersectsViewVolume(GfMatrix4d const &viewProjMatrix) const;
|
||||
|
||||
HD_API
|
||||
friend std::ostream &operator <<(std::ostream &out,
|
||||
const HdDrawItem& self);
|
||||
|
||||
protected:
|
||||
// TfHash support.
|
||||
template <class HashState>
|
||||
friend void TfHashAppend(HashState &h, HdDrawItem const &di);
|
||||
|
||||
/// Returns the shared data
|
||||
HD_API
|
||||
HdRprimSharedData const *_GetSharedData() const {
|
||||
return _sharedData;
|
||||
}
|
||||
|
||||
/// Allows derived classes to return a hash of the versions of buffers
|
||||
/// they manage.
|
||||
/// Called by GetBufferArraysHash.
|
||||
HD_API
|
||||
virtual size_t _GetBufferArraysHash() const;
|
||||
|
||||
/// Allows derived classes to return a hash of the element offsets of
|
||||
/// the underlying BARs they manage.
|
||||
/// Called by GetBufferArraysHash.
|
||||
HD_API
|
||||
virtual size_t _GetElementOffsetsHash() const;
|
||||
|
||||
private:
|
||||
// configuration of how to bundle the drawing coordinate for this draw item
|
||||
// out of BARs in sharedData
|
||||
HdDrawingCoord _drawingCoord;
|
||||
|
||||
// pointer to shared data across reprs, owned by rprim:
|
||||
// bufferArrayRanges, bounds, visibility
|
||||
HdRprimSharedData const *_sharedData;
|
||||
|
||||
/// The materialTag allows the draw items of rprims to be organized into
|
||||
/// different collections based on properties of the prim's material.
|
||||
/// E.g. A renderer may wish to organize opaque and translucent prims
|
||||
/// into different collections so they can be rendered seperately.
|
||||
TfToken _materialTag;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif //PXR_IMAGING_HD_DRAW_ITEM_H
|
||||
@@ -0,0 +1,141 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_DRAWING_COORD_H
|
||||
#define PXR_IMAGING_HD_DRAWING_COORD_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/base/tf/diagnostic.h"
|
||||
#include <stdint.h>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// \class HdDrawingCoord
|
||||
///
|
||||
/// A tiny set of integers, which provides an indirection mapping from the
|
||||
/// conceptual space of an HdRprim's resources (topological, primvar &
|
||||
/// instancing) to the index within HdBufferArrayRangeContainer, where the
|
||||
/// resource is stored.
|
||||
///
|
||||
/// Each HdDrawItem contains a HdDrawingCoord, with the relevant compositional
|
||||
/// hierarchy being:
|
||||
///
|
||||
/// HdRprim
|
||||
/// |
|
||||
/// +--HdRepr(s)
|
||||
/// | |
|
||||
/// | +--HdDrawItem(s)----------.
|
||||
/// | | |
|
||||
/// | +--HdDrawingCoord |
|
||||
/// | | (mapping provided by HdDrawingCoord)
|
||||
/// +--HdRprimSharedData |
|
||||
/// | |
|
||||
/// +--HdBARContainer <--------+
|
||||
///
|
||||
///
|
||||
/// Having this indirection provides a recipe for how to configure
|
||||
/// a drawing coordinate, which is a bundle of HdBufferArrayRanges, while
|
||||
/// they are shared or not shared across different representations
|
||||
/// constructed on the same prim.
|
||||
///
|
||||
/// HullRepr --------- Rprim --------- RefinedRepr
|
||||
/// | | |
|
||||
/// DrawItem | DrawItem
|
||||
/// | | |
|
||||
/// DrawingCoord Container DrawingCoord
|
||||
/// constant -------> [ 0 ] <------ constant
|
||||
/// vertex -------> [ 1 ]
|
||||
/// topology -------> [ 2 ]
|
||||
/// [ 3 ]
|
||||
/// [ 4 ]
|
||||
/// [ 5 ]
|
||||
/// [ 6 ]
|
||||
/// [ 7 ]
|
||||
/// [ 8 ] <------ vertex (refined)
|
||||
/// [ 9 ] <------ topology (refined)
|
||||
/// ...
|
||||
/// instance level=0 ---> [ k ]
|
||||
/// instance level=1 ---> [k+1]
|
||||
/// instance level=2 ---> [k+2]
|
||||
///
|
||||
class HdDrawingCoord {
|
||||
public:
|
||||
static const int CustomSlotsBegin = 8;
|
||||
static const int DefaultNumSlots = 3; /* Constant, Vertex, Topology */
|
||||
static const int Unassigned = -1;
|
||||
|
||||
HdDrawingCoord() :
|
||||
// default slots:
|
||||
_constantPrimvar(0),
|
||||
_vertexPrimvar(1),
|
||||
_topology(2),
|
||||
_elementPrimvar(3),
|
||||
_instanceIndex(4),
|
||||
_faceVaryingPrimvar(5),
|
||||
_topologyVisibility(6),
|
||||
_varyingPrimvar(7),
|
||||
_instancePrimvar(Unassigned) {
|
||||
}
|
||||
|
||||
int GetConstantPrimvarIndex() const { return _constantPrimvar; }
|
||||
void SetConstantPrimvarIndex(int slot) { _constantPrimvar = slot; }
|
||||
int GetVertexPrimvarIndex() const { return _vertexPrimvar; }
|
||||
void SetVertexPrimvarIndex(int slot) { _vertexPrimvar = slot; }
|
||||
int GetTopologyIndex() const { return _topology; }
|
||||
void SetTopologyIndex(int slot) { _topology = slot; }
|
||||
int GetElementPrimvarIndex() const { return _elementPrimvar; }
|
||||
void SetElementPrimvarIndex(int slot) { _elementPrimvar = slot; }
|
||||
int GetInstanceIndexIndex() const { return _instanceIndex; }
|
||||
void SetInstanceIndexIndex(int slot) { _instanceIndex = slot; }
|
||||
int GetFaceVaryingPrimvarIndex() const { return _faceVaryingPrimvar; }
|
||||
void SetFaceVaryingPrimvarIndex(int slot) { _faceVaryingPrimvar = slot; }
|
||||
int GetTopologyVisibilityIndex() const { return _topologyVisibility; }
|
||||
void SetTopologyVisibilityIndex(int slot) { _topologyVisibility = slot; }
|
||||
int GetVaryingPrimvarIndex() const { return _varyingPrimvar; }
|
||||
void SetVaryingPrimvarIndex(int slot) { _varyingPrimvar = slot; }
|
||||
|
||||
// instance primvars take up a range of slots.
|
||||
void SetInstancePrimvarBaseIndex(int slot) { _instancePrimvar = slot; }
|
||||
int GetInstancePrimvarIndex(int level) const {
|
||||
TF_VERIFY(_instancePrimvar != Unassigned);
|
||||
return _instancePrimvar + level;
|
||||
}
|
||||
|
||||
private:
|
||||
int8_t _constantPrimvar;
|
||||
int8_t _vertexPrimvar;
|
||||
int8_t _topology;
|
||||
int8_t _elementPrimvar;
|
||||
int8_t _instanceIndex;
|
||||
int8_t _faceVaryingPrimvar;
|
||||
int8_t _topologyVisibility;
|
||||
int8_t _varyingPrimvar;
|
||||
int8_t _instancePrimvar;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_DRAWING_COORD_H
|
||||
@@ -0,0 +1,48 @@
|
||||
//
|
||||
// Copyright 2020 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_DRIVER_H
|
||||
#define PXR_IMAGING_HD_DRIVER_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
|
||||
#include "pxr/base/tf/token.h"
|
||||
#include "pxr/base/vt/value.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// HdDriver represents a device object, commonly a render device, that is owned
|
||||
/// by the application and passed to HdRenderIndex. The RenderIndex passes it to
|
||||
/// the render delegate and rendering tasks.
|
||||
/// The application manages the lifetime (destruction) of HdDriver and must
|
||||
/// ensure it remains valid while Hydra is running.
|
||||
class HdDriver {
|
||||
public:
|
||||
TfToken name;
|
||||
VtValue driver;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,99 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_ENGINE_H
|
||||
#define PXR_IMAGING_HD_ENGINE_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
|
||||
#include "pxr/imaging/hd/task.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdRenderIndex;
|
||||
class HdRenderDelegate;
|
||||
class HdResourceRegistry;
|
||||
|
||||
using HdRenderPassSharedPtr = std::shared_ptr<class HdRenderPass>;
|
||||
using HdRenderPassStateSharedPtr = std::shared_ptr<class HdRenderPassState>;
|
||||
|
||||
/// \class HdEngine
|
||||
///
|
||||
/// The application-facing entry point top-level entry point for accessing Hydra.
|
||||
/// Typically the application would only create one of these.
|
||||
class HdEngine {
|
||||
public:
|
||||
HD_API
|
||||
HdEngine();
|
||||
HD_API
|
||||
virtual ~HdEngine();
|
||||
|
||||
/// \name Task Context
|
||||
///
|
||||
/// External interface to set data/state in the task context passed to
|
||||
/// each task in the render graph
|
||||
///
|
||||
/// @{
|
||||
|
||||
/// Adds or updates the value associated with the token.
|
||||
/// Only one is supported for each token.
|
||||
HD_API
|
||||
void SetTaskContextData(const TfToken &id, const VtValue &data);
|
||||
|
||||
/// If found, will return the value from the task context data associated
|
||||
/// with the token. Returns false if the data could not be found.
|
||||
HD_API
|
||||
bool GetTaskContextData(const TfToken &id, VtValue *data) const;
|
||||
|
||||
/// Removes the specified token.
|
||||
HD_API
|
||||
void RemoveTaskContextData(const TfToken &id);
|
||||
|
||||
/// Removes all keys.
|
||||
HD_API
|
||||
void ClearTaskContextData();
|
||||
|
||||
/// @}
|
||||
|
||||
/// Execute tasks.
|
||||
HD_API
|
||||
void Execute(HdRenderIndex *index,
|
||||
HdTaskSharedPtrVector *tasks);
|
||||
|
||||
|
||||
private:
|
||||
/// Context containing token-value pairs, that is passed to each
|
||||
/// task in the render graph. The task-context can be pre-populated
|
||||
/// and managed externally, so the state is persistent between runs of the
|
||||
/// render graph.
|
||||
HdTaskContext _taskContext;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif //PXR_IMAGING_HD_ENGINE_H
|
||||
@@ -0,0 +1,247 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_ENUMS_H
|
||||
#define PXR_IMAGING_HD_ENUMS_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// \enum HdCompareFunction
|
||||
///
|
||||
/// Abstraction of the Graphics compare functions.
|
||||
///
|
||||
enum HdCompareFunction
|
||||
{
|
||||
HdCmpFuncNever,
|
||||
HdCmpFuncLess,
|
||||
HdCmpFuncEqual,
|
||||
HdCmpFuncLEqual,
|
||||
HdCmpFuncGreater,
|
||||
HdCmpFuncNotEqual,
|
||||
HdCmpFuncGEqual,
|
||||
HdCmpFuncAlways,
|
||||
|
||||
HdCmpFuncLast
|
||||
};
|
||||
|
||||
/// \enum HdStencilOp
|
||||
///
|
||||
/// Abstraction of the Graphics stencil test operations.
|
||||
///
|
||||
enum HdStencilOp
|
||||
{
|
||||
HdStencilOpKeep,
|
||||
HdStencilOpZero,
|
||||
HdStencilOpReplace,
|
||||
HdStencilOpIncrement,
|
||||
HdStencilOpIncrementWrap,
|
||||
HdStencilOpDecrement,
|
||||
HdStencilOpDecrementWrap,
|
||||
HdStencilOpInvert,
|
||||
|
||||
HdStencilOpLast
|
||||
};
|
||||
|
||||
/// \enum HdBlendOp
|
||||
///
|
||||
/// Abstraction of the Graphics blend operations.
|
||||
///
|
||||
enum HdBlendOp
|
||||
{
|
||||
HdBlendOpAdd,
|
||||
HdBlendOpSubtract,
|
||||
HdBlendOpReverseSubtract,
|
||||
HdBlendOpMin,
|
||||
HdBlendOpMax,
|
||||
|
||||
HdBlendOpLast
|
||||
};
|
||||
|
||||
/// \enum HdBlendFactor
|
||||
///
|
||||
/// Abstraction of the Graphics blend factors.
|
||||
///
|
||||
enum HdBlendFactor
|
||||
{
|
||||
HdBlendFactorZero,
|
||||
HdBlendFactorOne,
|
||||
HdBlendFactorSrcColor,
|
||||
HdBlendFactorOneMinusSrcColor,
|
||||
HdBlendFactorDstColor,
|
||||
HdBlendFactorOneMinusDstColor,
|
||||
HdBlendFactorSrcAlpha,
|
||||
HdBlendFactorOneMinusSrcAlpha,
|
||||
HdBlendFactorDstAlpha,
|
||||
HdBlendFactorOneMinusDstAlpha,
|
||||
HdBlendFactorConstantColor,
|
||||
HdBlendFactorOneMinusConstantColor,
|
||||
HdBlendFactorConstantAlpha,
|
||||
HdBlendFactorOneMinusConstantAlpha,
|
||||
HdBlendFactorSrcAlphaSaturate,
|
||||
HdBlendFactorSrc1Color,
|
||||
HdBlendFactorOneMinusSrc1Color,
|
||||
HdBlendFactorSrc1Alpha,
|
||||
HdBlendFactorOneMinusSrc1Alpha,
|
||||
|
||||
HdBlendFactorLast
|
||||
};
|
||||
|
||||
/// \enum HdCullStyle
|
||||
///
|
||||
/// Face culling options.
|
||||
///
|
||||
/// DontCare indicates this prim doesn't determine what should be culled.
|
||||
/// Any other CullStyle opinion will override this (such as from the viewer).
|
||||
///
|
||||
/// BackUnlessDoubleSided and FrontUnlessDoubleSided will only cull back or
|
||||
/// front faces if prim isn't marked as doubleSided.
|
||||
///
|
||||
enum HdCullStyle
|
||||
{
|
||||
HdCullStyleDontCare,
|
||||
HdCullStyleNothing,
|
||||
HdCullStyleBack,
|
||||
HdCullStyleFront,
|
||||
HdCullStyleBackUnlessDoubleSided,
|
||||
HdCullStyleFrontUnlessDoubleSided
|
||||
};
|
||||
|
||||
/// Returns the opposite of the given cullstyle; backface culling becomes
|
||||
/// frontface and vice versa.
|
||||
HD_API
|
||||
HdCullStyle HdInvertCullStyle(HdCullStyle cs);
|
||||
|
||||
enum HdPolygonMode
|
||||
{
|
||||
HdPolygonModeFill,
|
||||
HdPolygonModeLine
|
||||
};
|
||||
|
||||
/// \enum HdMeshGeomStyle
|
||||
///
|
||||
/// Hydra native geom styles.
|
||||
///
|
||||
enum HdMeshGeomStyle {
|
||||
HdMeshGeomStyleInvalid,
|
||||
HdMeshGeomStyleSurf,
|
||||
HdMeshGeomStyleEdgeOnly,
|
||||
HdMeshGeomStyleEdgeOnSurf,
|
||||
HdMeshGeomStyleHull,
|
||||
HdMeshGeomStyleHullEdgeOnly,
|
||||
HdMeshGeomStyleHullEdgeOnSurf,
|
||||
HdMeshGeomStylePoints
|
||||
};
|
||||
|
||||
enum HdBasisCurvesGeomStyle {
|
||||
HdBasisCurvesGeomStyleInvalid,
|
||||
HdBasisCurvesGeomStyleWire,
|
||||
HdBasisCurvesGeomStylePatch,
|
||||
HdBasisCurvesGeomStylePoints
|
||||
};
|
||||
|
||||
enum HdPointsGeomStyle {
|
||||
HdPointsGeomStyleInvalid,
|
||||
HdPointsGeomStylePoints
|
||||
};
|
||||
|
||||
///
|
||||
/// \enum HdInterpolation
|
||||
///
|
||||
/// Enumerates Hydra's primvar interpolation modes.
|
||||
///
|
||||
/// Constant: One value remains constant over the entire surface primitive.
|
||||
///
|
||||
/// Uniform: One value remains constant for each uv patch segment of the
|
||||
/// surface primitive.
|
||||
///
|
||||
/// Varying: Four values are interpolated over each uv patch segment of
|
||||
/// the surface. Bilinear interpolation is used for interpolation
|
||||
/// between the four values.
|
||||
///
|
||||
/// Vertex: Values are interpolated between each vertex in the surface
|
||||
/// primitive. The basis function of the surface is used for
|
||||
/// interpolation between vertices.
|
||||
///
|
||||
/// Facevarying: For polygons and subdivision surfaces, four values are
|
||||
/// interpolated over each face of the mesh. Bilinear interpolation
|
||||
/// is used for interpolation between the four values.
|
||||
///
|
||||
/// Instance: One value remains constant across each instance.
|
||||
///
|
||||
enum HdInterpolation
|
||||
{
|
||||
HdInterpolationConstant = 0,
|
||||
HdInterpolationUniform,
|
||||
HdInterpolationVarying,
|
||||
HdInterpolationVertex,
|
||||
HdInterpolationFaceVarying,
|
||||
HdInterpolationInstance,
|
||||
|
||||
HdInterpolationCount
|
||||
};
|
||||
|
||||
///
|
||||
/// \enum HdTextureType
|
||||
/// Enumerates Hydra's supported texture types.
|
||||
///
|
||||
/// Uv: Sample the uv coordinates and accesses a single 2d texture.
|
||||
///
|
||||
/// Field: Transform coordinates by matrix before accessing a single 3d
|
||||
/// texture.
|
||||
///
|
||||
/// Ptex: Use the ptex connectivity information to sample a ptex texture.
|
||||
///
|
||||
/// Udim: Remap the uv coordinates into udim coordinates using a maximum
|
||||
/// tile width of 10 and sample all the udim tiles found in the
|
||||
/// file system.
|
||||
///
|
||||
enum class HdTextureType
|
||||
{
|
||||
Uv,
|
||||
Field,
|
||||
Ptex,
|
||||
Udim
|
||||
};
|
||||
|
||||
/// \enum HdDepthPriority
|
||||
/// Sets the priorities for a depth based operation
|
||||
///
|
||||
/// <ul>
|
||||
/// <li>HdDepthPriorityNearest Prioritize objects nearest to the camera</li>
|
||||
/// <li>HdDepthPriorityFarthest Prioritize objects farthest from the camera</li>
|
||||
/// </ul>
|
||||
///
|
||||
enum HdDepthPriority
|
||||
{
|
||||
HdDepthPriorityNearest = 0,
|
||||
HdDepthPriorityFarthest,
|
||||
|
||||
HdDepthPriorityCount
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_ENUMS_H
|
||||
@@ -0,0 +1,135 @@
|
||||
//
|
||||
// Copyright 2017 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_EXT_COMP_CPU_COMPUTATION_H
|
||||
#define PXR_IMAGING_HD_EXT_COMP_CPU_COMPUTATION_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/extCompInputSource.h"
|
||||
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
|
||||
#include "pxr/base/tf/token.h"
|
||||
#include "pxr/base/vt/value.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdSceneDelegate;
|
||||
class HdExtComputation;
|
||||
class HdExtCompCpuComputation;
|
||||
|
||||
using HdExtCompCpuComputationSharedPtr =
|
||||
std::shared_ptr<HdExtCompCpuComputation>;
|
||||
|
||||
///
|
||||
/// A Buffer Source that represents a CPU implementation of a ExtComputation.
|
||||
///
|
||||
/// The computation implements the basic: input->processing->output model
|
||||
/// where the inputs are other buffer sources and processing happens during
|
||||
/// resolve.
|
||||
///
|
||||
/// As a computation may have many outputs, the outputs from the CPU
|
||||
/// Computation can not be directly associated with a BAR. Instead
|
||||
/// other buffer source computation bind the output to sources that can
|
||||
/// be used in a BAR.
|
||||
///
|
||||
/// Outputs to a computation are in SOA form, so a computation may have
|
||||
/// many outputs, but each output has the same number of elements in it.
|
||||
class HdExtCompCpuComputation final : public HdNullBufferSource {
|
||||
public:
|
||||
static const size_t INVALID_OUTPUT_INDEX;
|
||||
|
||||
/// Constructs a new Cpu ExtComputation source.
|
||||
/// inputs provides a list of buffer sources that this computation
|
||||
/// requires.
|
||||
/// outputs is a list of outputs by names that the computation produces.
|
||||
///
|
||||
/// Num elements specifies the number of elements in the output.
|
||||
///
|
||||
/// sceneDelegate and id are used to callback to the scene delegate
|
||||
/// in order to invoke computation processing.
|
||||
HdExtCompCpuComputation(const SdfPath &id,
|
||||
const Hd_ExtCompInputSourceSharedPtrVector &inputs,
|
||||
const TfTokenVector &outputs,
|
||||
int numElements,
|
||||
HdSceneDelegate *sceneDelegate);
|
||||
|
||||
/// Create a CPU computation implementing the given abstract computation.
|
||||
/// The scene delegate identifies which delegate to pull scene inputs from.
|
||||
HD_API
|
||||
static HdExtCompCpuComputationSharedPtr
|
||||
CreateComputation(HdSceneDelegate *sceneDelegate,
|
||||
const HdExtComputation &computation,
|
||||
HdBufferSourceSharedPtrVector *computationSources);
|
||||
|
||||
HD_API
|
||||
virtual ~HdExtCompCpuComputation() = default;
|
||||
|
||||
/// Returns the id for this computation as a token.
|
||||
HD_API
|
||||
virtual TfToken const &GetName() const override;
|
||||
|
||||
/// Ask the scene delegate to run the computation and captures the output
|
||||
/// signals.
|
||||
HD_API
|
||||
virtual bool Resolve() override;
|
||||
|
||||
HD_API
|
||||
virtual size_t GetNumElements() const override;
|
||||
|
||||
|
||||
/// Converts a output name token into an index.
|
||||
HD_API
|
||||
size_t GetOutputIndex(const TfToken &outputName) const;
|
||||
|
||||
/// Returns the value of the specified output
|
||||
/// (after the computations been Resolved).
|
||||
HD_API
|
||||
const VtValue &GetOutputByIndex(size_t index) const;
|
||||
|
||||
protected:
|
||||
/// Returns if the computation is specified correctly.
|
||||
HD_API
|
||||
virtual bool _CheckValid() const override;
|
||||
|
||||
private:
|
||||
SdfPath _id;
|
||||
Hd_ExtCompInputSourceSharedPtrVector _inputs;
|
||||
TfTokenVector _outputs;
|
||||
size_t _numElements;
|
||||
HdSceneDelegate *_sceneDelegate;
|
||||
|
||||
std::vector<VtValue> _outputValues;
|
||||
|
||||
HdExtCompCpuComputation() = delete;
|
||||
HdExtCompCpuComputation(const HdExtCompCpuComputation &) = delete;
|
||||
HdExtCompCpuComputation &operator = (const HdExtCompCpuComputation &)
|
||||
= delete;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_EXT_COMP_CPU_COMPUTATION_H
|
||||
@@ -0,0 +1,77 @@
|
||||
//
|
||||
// Copyright 2017 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
|
||||
#ifndef PXR_IMAGING_HD_EXT_COMP_INPUT_SOURCE_H
|
||||
#define PXR_IMAGING_HD_EXT_COMP_INPUT_SOURCE_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/bufferSource.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class VtValue;
|
||||
|
||||
///
|
||||
/// Abstract base class for a Buffer Source that represents a binding to an
|
||||
/// input to an ExtComputation.
|
||||
///
|
||||
///
|
||||
class Hd_ExtCompInputSource : public HdNullBufferSource {
|
||||
public:
|
||||
/// Constructs the input binding with the name inputName
|
||||
HD_API
|
||||
Hd_ExtCompInputSource(const TfToken &inputName);
|
||||
|
||||
HD_API
|
||||
virtual ~Hd_ExtCompInputSource() = default;
|
||||
|
||||
/// Returns the name of the input.
|
||||
HD_API
|
||||
virtual TfToken const &GetName() const final;
|
||||
|
||||
/// Returns the value associated with the input.
|
||||
HD_API
|
||||
virtual const VtValue &GetValue() const = 0;
|
||||
|
||||
private:
|
||||
TfToken _inputName;
|
||||
|
||||
Hd_ExtCompInputSource() = delete;
|
||||
Hd_ExtCompInputSource(const Hd_ExtCompInputSource &) = delete;
|
||||
Hd_ExtCompInputSource &operator = (const Hd_ExtCompInputSource &) = delete;
|
||||
};
|
||||
|
||||
using Hd_ExtCompInputSourceSharedPtr =
|
||||
std::shared_ptr<Hd_ExtCompInputSource>;
|
||||
using Hd_ExtCompInputSourceSharedPtrVector =
|
||||
std::vector<Hd_ExtCompInputSourceSharedPtr>;
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_EXT_COMP_INPUT_SOURCE_H
|
||||
@@ -0,0 +1,117 @@
|
||||
//
|
||||
// Copyright 2017 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_EXT_COMP_PRIMVAR_BUFFER_SOURCE_H
|
||||
#define PXR_IMAGING_HD_EXT_COMP_PRIMVAR_BUFFER_SOURCE_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/bufferSource.h"
|
||||
#include "pxr/imaging/hd/types.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdExtCompCpuComputation;
|
||||
|
||||
using HdExtCompCpuComputationSharedPtr =
|
||||
std::shared_ptr<HdExtCompCpuComputation>;
|
||||
|
||||
/// Hd Buffer Source that binds a primvar to a Ext Computation output.
|
||||
/// This buffer source is compatible with being bound to a Bar.
|
||||
class HdExtCompPrimvarBufferSource final : public HdBufferSource {
|
||||
public:
|
||||
|
||||
/// Constructs a new primvar buffer source called primvarName and
|
||||
/// binds it to the output called sourceOutputName from the
|
||||
/// computation identified by source.
|
||||
///
|
||||
/// Default value provides type information for the primvar and may
|
||||
/// be used in the event of an error.
|
||||
HD_API
|
||||
HdExtCompPrimvarBufferSource(const TfToken &primvarName,
|
||||
const HdExtCompCpuComputationSharedPtr &source,
|
||||
const TfToken &sourceOutputName,
|
||||
const HdTupleType &valueType);
|
||||
|
||||
HD_API
|
||||
virtual ~HdExtCompPrimvarBufferSource() = default;
|
||||
|
||||
/// Returns the name of the primvar.
|
||||
HD_API
|
||||
virtual TfToken const &GetName() const override;
|
||||
|
||||
/// Adds this Primvar's buffer description to the buffer spec vector.
|
||||
HD_API
|
||||
virtual void GetBufferSpecs(HdBufferSpecVector *specs) const override;
|
||||
|
||||
/// Computes and returns a hash value for the underlying data.
|
||||
HD_API
|
||||
virtual size_t ComputeHash() const override;
|
||||
|
||||
/// Extracts the primvar from the source computation.
|
||||
HD_API
|
||||
virtual bool Resolve() override;
|
||||
|
||||
/// Returns a raw pointer to the primvar data.
|
||||
HD_API
|
||||
virtual void const *GetData() const override;
|
||||
|
||||
/// Returns the tuple data format of the primvar data.
|
||||
HD_API
|
||||
virtual HdTupleType GetTupleType() const override;
|
||||
|
||||
/// Returns a count of the number of elements.
|
||||
HD_API
|
||||
virtual size_t GetNumElements() const override;
|
||||
|
||||
protected:
|
||||
/// Returns true if the binding to the source computation was successful.
|
||||
HD_API
|
||||
virtual bool _CheckValid() const override;
|
||||
|
||||
private:
|
||||
// TfHash support.
|
||||
template <class HashState>
|
||||
friend void TfHashAppend(HashState &h,
|
||||
HdExtCompPrimvarBufferSource const &);
|
||||
|
||||
TfToken _primvarName;
|
||||
HdExtCompCpuComputationSharedPtr _source;
|
||||
size_t _sourceOutputIdx;
|
||||
HdTupleType _tupleType;
|
||||
void const *_rawDataPtr;
|
||||
|
||||
HdExtCompPrimvarBufferSource() = delete;
|
||||
HdExtCompPrimvarBufferSource(const HdExtCompPrimvarBufferSource &)
|
||||
= delete;
|
||||
HdExtCompPrimvarBufferSource &operator = (
|
||||
const HdExtCompPrimvarBufferSource &)
|
||||
= delete;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_EXT_COMP_PRIMVAR_BUFFER_SOURCE_H
|
||||
@@ -0,0 +1,162 @@
|
||||
//
|
||||
// Copyright 2017 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_EXT_COMPUTATION_H
|
||||
#define PXR_IMAGING_HD_EXT_COMPUTATION_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/sceneDelegate.h"
|
||||
#include "pxr/imaging/hd/sprim.h"
|
||||
#include "pxr/imaging/hd/types.h"
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
#include "pxr/base/vt/value.h"
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
///
|
||||
/// Hydra Representation of a Client defined computation.
|
||||
///
|
||||
/// A computation provides a way to procedurally generate a primvar.
|
||||
///
|
||||
/// It represents a basic Input -> Processing -> Output model.
|
||||
///
|
||||
/// Primarily inputs are provided by the scene delegate via the Get()
|
||||
/// mechanism.
|
||||
///
|
||||
/// Computations can also be chained together, such that the output from
|
||||
/// one computation can be an input to another.
|
||||
///
|
||||
/// The results of a computation is designed to be in SOA form (structure or
|
||||
/// array), where each output is a member of the "structure" producing several
|
||||
/// parallel arrays. While the type of the elements of the array is defined
|
||||
/// by the output member, the number of elements in each array is the same
|
||||
/// across all outputs.
|
||||
///
|
||||
/// ExtComputations use a pull model, so processing is only triggered if
|
||||
/// a downstream computation or prim pulls on one the computations outputs.
|
||||
///
|
||||
class HdExtComputation : public HdSprim {
|
||||
public:
|
||||
/// Construct a new ExtComputation identified by id.
|
||||
HD_API
|
||||
HdExtComputation(SdfPath const &id);
|
||||
|
||||
HD_API
|
||||
virtual ~HdExtComputation() = default;
|
||||
|
||||
///
|
||||
/// Change tracking
|
||||
///
|
||||
enum DirtyBits : HdDirtyBits {
|
||||
Clean = 0,
|
||||
DirtyInputDesc = 1 << 0, ///< The list of inputs or input
|
||||
/// bindings changed
|
||||
DirtyOutputDesc = 1 << 1, ///< The list of outputs changed
|
||||
DirtyElementCount = 1 << 2, ///< The number of elements in the
|
||||
/// output arrays changed
|
||||
DirtySceneInput = 1 << 3, ///< A scene input changed value
|
||||
DirtyCompInput = 1 << 4, ///< A computation input changed value
|
||||
DirtyKernel = 1 << 5, ///< The compute kernel binding changed
|
||||
|
||||
DirtyDispatchCount = 1 << 6, ///< The number of kernel
|
||||
/// invocations to execute changed
|
||||
|
||||
AllDirty = (DirtyInputDesc
|
||||
|DirtyOutputDesc
|
||||
|DirtyElementCount
|
||||
|DirtySceneInput
|
||||
|DirtyCompInput
|
||||
|DirtyKernel
|
||||
|DirtyDispatchCount)
|
||||
};
|
||||
|
||||
HD_API
|
||||
virtual void Sync(HdSceneDelegate *sceneDelegate,
|
||||
HdRenderParam *renderParam,
|
||||
HdDirtyBits *dirtyBits) override;
|
||||
|
||||
HD_API
|
||||
virtual HdDirtyBits GetInitialDirtyBitsMask() const override;
|
||||
|
||||
HD_API
|
||||
size_t GetDispatchCount() const;
|
||||
|
||||
HD_API
|
||||
size_t GetElementCount() const { return _elementCount; }
|
||||
|
||||
HD_API
|
||||
TfTokenVector const & GetSceneInputNames() const {
|
||||
return _sceneInputNames;
|
||||
}
|
||||
|
||||
HD_API
|
||||
TfTokenVector GetOutputNames() const;
|
||||
|
||||
HD_API
|
||||
HdExtComputationInputDescriptorVector const &
|
||||
GetComputationInputs() const {
|
||||
return _computationInputs;
|
||||
}
|
||||
|
||||
HD_API
|
||||
HdExtComputationOutputDescriptorVector const &
|
||||
GetComputationOutputs() const {
|
||||
return _computationOutputs;
|
||||
}
|
||||
|
||||
HD_API
|
||||
const std::string& GetGpuKernelSource() const { return _gpuKernelSource; }
|
||||
|
||||
HD_API
|
||||
bool IsInputAggregation() const;
|
||||
|
||||
protected:
|
||||
HD_API
|
||||
void
|
||||
_Sync(HdSceneDelegate *sceneDelegate,
|
||||
HdRenderParam *renderParam,
|
||||
HdDirtyBits *dirtyBits);
|
||||
|
||||
HD_API
|
||||
static bool _IsEnabledSharedExtComputationData();
|
||||
|
||||
private:
|
||||
size_t _dispatchCount;
|
||||
size_t _elementCount;
|
||||
TfTokenVector _sceneInputNames;
|
||||
HdExtComputationInputDescriptorVector _computationInputs;
|
||||
HdExtComputationOutputDescriptorVector _computationOutputs;
|
||||
std::string _gpuKernelSource;
|
||||
|
||||
// No default construction or copying
|
||||
HdExtComputation() = delete;
|
||||
HdExtComputation(const HdExtComputation &) = delete;
|
||||
HdExtComputation &operator =(const HdExtComputation &) = delete;
|
||||
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_EXT_COMPUTATION_H
|
||||
@@ -0,0 +1,78 @@
|
||||
//
|
||||
// Copyright 2017 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_EXT_COMPUTATION_CONTEXT_H
|
||||
#define PXR_IMAGING_HD_EXT_COMPUTATION_CONTEXT_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/base/vt/value.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
///
|
||||
/// Interface class that defines the execution environment for the client
|
||||
/// to run a computation.
|
||||
///
|
||||
class HdExtComputationContext {
|
||||
public:
|
||||
HdExtComputationContext() = default;
|
||||
virtual ~HdExtComputationContext();
|
||||
|
||||
///
|
||||
/// Obtains the value of an named input to the computation.
|
||||
///
|
||||
/// The code will issue a coding error and return a empty array
|
||||
/// if the input is missing or of a different type.
|
||||
///
|
||||
virtual const VtValue &GetInputValue(const TfToken &name) const = 0;
|
||||
|
||||
///
|
||||
/// Obtains the value of an named input to the computation.
|
||||
///
|
||||
/// If the input isn't present or of a different type
|
||||
/// nullptr will be returned.
|
||||
///
|
||||
virtual const VtValue *GetOptionalInputValuePtr(
|
||||
const TfToken &name) const = 0;
|
||||
|
||||
///
|
||||
/// Set the value of the specified output.
|
||||
///
|
||||
virtual void SetOutputValue(const TfToken &name, const VtValue &output) = 0;
|
||||
|
||||
///
|
||||
/// Called to indicate an error occurred while executing a computation
|
||||
/// so that its output are invalid.
|
||||
///
|
||||
virtual void RaiseComputationError() = 0;
|
||||
|
||||
private:
|
||||
HdExtComputationContext(const HdExtComputationContext &) = delete;
|
||||
HdExtComputationContext &operator = (const HdExtComputationContext &)
|
||||
= delete;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_EXT_COMPUTATION_CONTEXT_H
|
||||
@@ -0,0 +1,112 @@
|
||||
//
|
||||
// Copyright 2021 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// This file is generated by a script. Do not edit directly. Edit the
|
||||
// schema.template.h file to make changes.
|
||||
|
||||
#ifndef PXR_IMAGING_HD_EXT_COMPUTATION_INPUT_COMPUTATION_SCHEMA_H
|
||||
#define PXR_IMAGING_HD_EXT_COMPUTATION_INPUT_COMPUTATION_SCHEMA_H
|
||||
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
|
||||
#include "pxr/imaging/hd/schema.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define HDEXTCOMPUTATIONINPUTCOMPUTATION_SCHEMA_TOKENS \
|
||||
(name) \
|
||||
(sourceComputation) \
|
||||
(sourceComputationOutputName) \
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdExtComputationInputComputationSchemaTokens, HD_API,
|
||||
HDEXTCOMPUTATIONINPUTCOMPUTATION_SCHEMA_TOKENS);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class HdExtComputationInputComputationSchema : public HdSchema
|
||||
{
|
||||
public:
|
||||
HdExtComputationInputComputationSchema(HdContainerDataSourceHandle container)
|
||||
: HdSchema(container) {}
|
||||
|
||||
//ACCESSORS
|
||||
|
||||
HD_API
|
||||
HdTokenDataSourceHandle GetName();
|
||||
HD_API
|
||||
HdPathDataSourceHandle GetSourceComputation();
|
||||
HD_API
|
||||
HdTokenDataSourceHandle GetSourceComputationOutputName();
|
||||
|
||||
// RETRIEVING AND CONSTRUCTING
|
||||
|
||||
/// 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 HdTokenDataSourceHandle &name,
|
||||
const HdPathDataSourceHandle &sourceComputation,
|
||||
const HdTokenDataSourceHandle &sourceComputationOutputName
|
||||
);
|
||||
|
||||
/// \class HdExtComputationInputComputationSchema::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 &SetName(
|
||||
const HdTokenDataSourceHandle &name);
|
||||
HD_API
|
||||
Builder &SetSourceComputation(
|
||||
const HdPathDataSourceHandle &sourceComputation);
|
||||
HD_API
|
||||
Builder &SetSourceComputationOutputName(
|
||||
const HdTokenDataSourceHandle &sourceComputationOutputName);
|
||||
|
||||
/// Returns a container data source containing the members set thus far.
|
||||
HD_API
|
||||
HdContainerDataSourceHandle Build();
|
||||
|
||||
private:
|
||||
HdTokenDataSourceHandle _name;
|
||||
HdPathDataSourceHandle _sourceComputation;
|
||||
HdTokenDataSourceHandle _sourceComputationOutputName;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,104 @@
|
||||
//
|
||||
// Copyright 2021 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// This file is generated by a script. Do not edit directly. Edit the
|
||||
// schema.template.h file to make changes.
|
||||
|
||||
#ifndef PXR_IMAGING_HD_EXT_COMPUTATION_OUTPUT_SCHEMA_H
|
||||
#define PXR_IMAGING_HD_EXT_COMPUTATION_OUTPUT_SCHEMA_H
|
||||
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
|
||||
#include "pxr/imaging/hd/schema.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define HDEXTCOMPUTATIONOUTPUT_SCHEMA_TOKENS \
|
||||
(name) \
|
||||
(valueType) \
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdExtComputationOutputSchemaTokens, HD_API,
|
||||
HDEXTCOMPUTATIONOUTPUT_SCHEMA_TOKENS);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class HdExtComputationOutputSchema : public HdSchema
|
||||
{
|
||||
public:
|
||||
HdExtComputationOutputSchema(HdContainerDataSourceHandle container)
|
||||
: HdSchema(container) {}
|
||||
|
||||
//ACCESSORS
|
||||
|
||||
HD_API
|
||||
HdTokenDataSourceHandle GetName();
|
||||
HD_API
|
||||
HdTupleTypeDataSourceHandle GetValueType();
|
||||
|
||||
// RETRIEVING AND CONSTRUCTING
|
||||
|
||||
/// 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 HdTokenDataSourceHandle &name,
|
||||
const HdTupleTypeDataSourceHandle &valueType
|
||||
);
|
||||
|
||||
/// \class HdExtComputationOutputSchema::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 &SetName(
|
||||
const HdTokenDataSourceHandle &name);
|
||||
HD_API
|
||||
Builder &SetValueType(
|
||||
const HdTupleTypeDataSourceHandle &valueType);
|
||||
|
||||
/// Returns a container data source containing the members set thus far.
|
||||
HD_API
|
||||
HdContainerDataSourceHandle Build();
|
||||
|
||||
private:
|
||||
HdTokenDataSourceHandle _name;
|
||||
HdTupleTypeDataSourceHandle _valueType;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,140 @@
|
||||
//
|
||||
// Copyright 2021 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// This file is generated by a script. Do not edit directly. Edit the
|
||||
// schema.template.h file to make changes.
|
||||
|
||||
#ifndef PXR_IMAGING_HD_EXT_COMPUTATION_PRIMVAR_SCHEMA_H
|
||||
#define PXR_IMAGING_HD_EXT_COMPUTATION_PRIMVAR_SCHEMA_H
|
||||
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
|
||||
#include "pxr/imaging/hd/primvarSchema.h"
|
||||
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define HDEXTCOMPUTATIONPRIMVAR_SCHEMA_TOKENS \
|
||||
(interpolation) \
|
||||
(role) \
|
||||
(sourceComputation) \
|
||||
(sourceComputationOutputName) \
|
||||
(valueType) \
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdExtComputationPrimvarSchemaTokens, HD_API,
|
||||
HDEXTCOMPUTATIONPRIMVAR_SCHEMA_TOKENS);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class HdExtComputationPrimvarSchema : public HdSchema
|
||||
{
|
||||
public:
|
||||
HdExtComputationPrimvarSchema(HdContainerDataSourceHandle container)
|
||||
: HdSchema(container) {}
|
||||
|
||||
//ACCESSORS
|
||||
|
||||
HD_API
|
||||
HdTokenDataSourceHandle GetInterpolation();
|
||||
HD_API
|
||||
HdTokenDataSourceHandle GetRole();
|
||||
HD_API
|
||||
HdPathDataSourceHandle GetSourceComputation();
|
||||
HD_API
|
||||
HdTokenDataSourceHandle GetSourceComputationOutputName();
|
||||
HD_API
|
||||
HdTupleTypeDataSourceHandle GetValueType();
|
||||
|
||||
// RETRIEVING AND CONSTRUCTING
|
||||
|
||||
/// 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 HdTokenDataSourceHandle &interpolation,
|
||||
const HdTokenDataSourceHandle &role,
|
||||
const HdPathDataSourceHandle &sourceComputation,
|
||||
const HdTokenDataSourceHandle &sourceComputationOutputName,
|
||||
const HdTupleTypeDataSourceHandle &valueType
|
||||
);
|
||||
|
||||
/// \class HdExtComputationPrimvarSchema::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 &SetInterpolation(
|
||||
const HdTokenDataSourceHandle &interpolation);
|
||||
HD_API
|
||||
Builder &SetRole(
|
||||
const HdTokenDataSourceHandle &role);
|
||||
HD_API
|
||||
Builder &SetSourceComputation(
|
||||
const HdPathDataSourceHandle &sourceComputation);
|
||||
HD_API
|
||||
Builder &SetSourceComputationOutputName(
|
||||
const HdTokenDataSourceHandle &sourceComputationOutputName);
|
||||
HD_API
|
||||
Builder &SetValueType(
|
||||
const HdTupleTypeDataSourceHandle &valueType);
|
||||
|
||||
/// Returns a container data source containing the members set thus far.
|
||||
HD_API
|
||||
HdContainerDataSourceHandle Build();
|
||||
|
||||
private:
|
||||
HdTokenDataSourceHandle _interpolation;
|
||||
HdTokenDataSourceHandle _role;
|
||||
HdPathDataSourceHandle _sourceComputation;
|
||||
HdTokenDataSourceHandle _sourceComputationOutputName;
|
||||
HdTupleTypeDataSourceHandle _valueType;
|
||||
};
|
||||
|
||||
// these return statically allocated instances for the common cases.
|
||||
static HdTokenDataSourceHandle BuildInterpolationDataSource(
|
||||
TfToken interpolation) {
|
||||
return HdPrimvarSchema::BuildInterpolationDataSource(interpolation);
|
||||
}
|
||||
|
||||
static HdTokenDataSourceHandle BuildRoleDataSource(TfToken role) {
|
||||
return HdPrimvarSchema::BuildRoleDataSource(role);
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,76 @@
|
||||
//
|
||||
// Copyright 2021 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// This file is generated by a script. Do not edit directly. Edit the
|
||||
// schema.template.h file to make changes.
|
||||
|
||||
#ifndef PXR_IMAGING_HD_EXT_COMPUTATION_PRIMVARS_SCHEMA_H
|
||||
#define PXR_IMAGING_HD_EXT_COMPUTATION_PRIMVARS_SCHEMA_H
|
||||
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
|
||||
#include "pxr/imaging/hd/extComputationPrimvarSchema.h"
|
||||
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define HDEXTCOMPUTATIONPRIMVARS_SCHEMA_TOKENS \
|
||||
(extComputationPrimvars) \
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdExtComputationPrimvarsSchemaTokens, HD_API,
|
||||
HDEXTCOMPUTATIONPRIMVARS_SCHEMA_TOKENS);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class HdExtComputationPrimvarsSchema : public HdSchema
|
||||
{
|
||||
public:
|
||||
HdExtComputationPrimvarsSchema(HdContainerDataSourceHandle container)
|
||||
: HdSchema(container) {}
|
||||
|
||||
TfTokenVector GetExtComputationPrimvarNames();
|
||||
HdExtComputationPrimvarSchema GetPrimvar(const TfToken &name);
|
||||
|
||||
|
||||
/// Retrieves a container data source with the schema's default name token
|
||||
/// "extComputationPrimvars" from the parent container and constructs a
|
||||
/// HdExtComputationPrimvarsSchema 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 HdExtComputationPrimvarsSchema GetFromParent(
|
||||
const HdContainerDataSourceHandle &fromParentContainer);
|
||||
|
||||
/// 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();
|
||||
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,202 @@
|
||||
//
|
||||
// Copyright 2021 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// This file is generated by a script. Do not edit directly. Edit the
|
||||
// schema.template.h file to make changes.
|
||||
|
||||
#ifndef PXR_IMAGING_HD_EXT_COMPUTATION_SCHEMA_H
|
||||
#define PXR_IMAGING_HD_EXT_COMPUTATION_SCHEMA_H
|
||||
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
|
||||
#include "pxr/imaging/hd/schema.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define HDEXTCOMPUTATION_SCHEMA_TOKENS \
|
||||
(extComputation) \
|
||||
(inputValues) \
|
||||
(inputComputations) \
|
||||
(outputs) \
|
||||
(glslKernel) \
|
||||
(cpuCallback) \
|
||||
(dispatchCount) \
|
||||
(elementCount) \
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdExtComputationSchemaTokens, HD_API,
|
||||
HDEXTCOMPUTATION_SCHEMA_TOKENS);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class HdExtComputationSchema : public HdSchema
|
||||
{
|
||||
public:
|
||||
HdExtComputationSchema(HdContainerDataSourceHandle container)
|
||||
: HdSchema(container) {}
|
||||
|
||||
//ACCESSORS
|
||||
|
||||
HD_API
|
||||
HdContainerDataSourceHandle GetInputValues();
|
||||
HD_API
|
||||
HdVectorDataSourceHandle GetInputComputations();
|
||||
HD_API
|
||||
HdVectorDataSourceHandle GetOutputs();
|
||||
HD_API
|
||||
HdStringDataSourceHandle GetGlslKernel();
|
||||
HD_API
|
||||
HdDataSourceBaseHandle GetCpuCallback();
|
||||
HD_API
|
||||
HdSizetDataSourceHandle GetDispatchCount();
|
||||
HD_API
|
||||
HdSizetDataSourceHandle GetElementCount();
|
||||
|
||||
// RETRIEVING AND CONSTRUCTING
|
||||
|
||||
/// 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 HdContainerDataSourceHandle &inputValues,
|
||||
const HdVectorDataSourceHandle &inputComputations,
|
||||
const HdVectorDataSourceHandle &outputs,
|
||||
const HdStringDataSourceHandle &glslKernel,
|
||||
const HdDataSourceBaseHandle &cpuCallback,
|
||||
const HdSizetDataSourceHandle &dispatchCount,
|
||||
const HdSizetDataSourceHandle &elementCount
|
||||
);
|
||||
|
||||
/// \class HdExtComputationSchema::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 &SetInputValues(
|
||||
const HdContainerDataSourceHandle &inputValues);
|
||||
HD_API
|
||||
Builder &SetInputComputations(
|
||||
const HdVectorDataSourceHandle &inputComputations);
|
||||
HD_API
|
||||
Builder &SetOutputs(
|
||||
const HdVectorDataSourceHandle &outputs);
|
||||
HD_API
|
||||
Builder &SetGlslKernel(
|
||||
const HdStringDataSourceHandle &glslKernel);
|
||||
HD_API
|
||||
Builder &SetCpuCallback(
|
||||
const HdDataSourceBaseHandle &cpuCallback);
|
||||
HD_API
|
||||
Builder &SetDispatchCount(
|
||||
const HdSizetDataSourceHandle &dispatchCount);
|
||||
HD_API
|
||||
Builder &SetElementCount(
|
||||
const HdSizetDataSourceHandle &elementCount);
|
||||
|
||||
/// Returns a container data source containing the members set thus far.
|
||||
HD_API
|
||||
HdContainerDataSourceHandle Build();
|
||||
|
||||
private:
|
||||
HdContainerDataSourceHandle _inputValues;
|
||||
HdVectorDataSourceHandle _inputComputations;
|
||||
HdVectorDataSourceHandle _outputs;
|
||||
HdStringDataSourceHandle _glslKernel;
|
||||
HdDataSourceBaseHandle _cpuCallback;
|
||||
HdSizetDataSourceHandle _dispatchCount;
|
||||
HdSizetDataSourceHandle _elementCount;
|
||||
};
|
||||
|
||||
/// Retrieves a container data source with the schema's default name token
|
||||
/// "extComputation" from the parent container and constructs a
|
||||
/// HdExtComputationSchema 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 HdExtComputationSchema GetFromParent(
|
||||
const HdContainerDataSourceHandle &fromParentContainer);
|
||||
|
||||
/// 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();
|
||||
|
||||
|
||||
/// Returns an HdDataSourceLocator (relative to the prim-level data source)
|
||||
/// where the inputvalues data source can be found.
|
||||
/// This is often useful for checking intersection against the
|
||||
/// HdDataSourceLocatorSet sent with HdDataSourceObserver::PrimsDirtied.
|
||||
HD_API
|
||||
static const HdDataSourceLocator &GetInputValuesLocator();
|
||||
|
||||
/// Returns an HdDataSourceLocator (relative to the prim-level data source)
|
||||
/// where the inputcomputations data source can be found.
|
||||
/// This is often useful for checking intersection against the
|
||||
/// HdDataSourceLocatorSet sent with HdDataSourceObserver::PrimsDirtied.
|
||||
HD_API
|
||||
static const HdDataSourceLocator &GetInputComputationsLocator();
|
||||
|
||||
/// Returns an HdDataSourceLocator (relative to the prim-level data source)
|
||||
/// where the outputs data source can be found.
|
||||
/// This is often useful for checking intersection against the
|
||||
/// HdDataSourceLocatorSet sent with HdDataSourceObserver::PrimsDirtied.
|
||||
HD_API
|
||||
static const HdDataSourceLocator &GetOutputsLocator();
|
||||
|
||||
/// Returns an HdDataSourceLocator (relative to the prim-level data source)
|
||||
/// where the dispatchcount data source can be found.
|
||||
/// This is often useful for checking intersection against the
|
||||
/// HdDataSourceLocatorSet sent with HdDataSourceObserver::PrimsDirtied.
|
||||
HD_API
|
||||
static const HdDataSourceLocator &GetDispatchCountLocator();
|
||||
|
||||
/// Returns an HdDataSourceLocator (relative to the prim-level data source)
|
||||
/// where the elementcount data source can be found.
|
||||
/// This is often useful for checking intersection against the
|
||||
/// HdDataSourceLocatorSet sent with HdDataSourceObserver::PrimsDirtied.
|
||||
HD_API
|
||||
static const HdDataSourceLocator &GetElementCountLocator();
|
||||
|
||||
/// Returns an HdDataSourceLocator (relative to the prim-level data source)
|
||||
/// where the glslkernel data source can be found.
|
||||
/// This is often useful for checking intersection against the
|
||||
/// HdDataSourceLocatorSet sent with HdDataSourceObserver::PrimsDirtied.
|
||||
HD_API
|
||||
static const HdDataSourceLocator &GetGlslKernelLocator();
|
||||
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,280 @@
|
||||
//
|
||||
// Copyright 2019 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_EXT_COMPUTATION_UTILS_H
|
||||
#define PXR_IMAGING_HD_EXT_COMPUTATION_UTILS_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/extComputation.h"
|
||||
#include "pxr/imaging/hd/sceneDelegate.h"
|
||||
|
||||
#include "pxr/base/tf/span.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
#include "pxr/base/vt/value.h"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
using HdExtComputationConstPtr = HdExtComputation const *;
|
||||
using HdExtComputationConstPtrVector = std::vector<HdExtComputationConstPtr>;
|
||||
|
||||
// This class contains utility methods to allow any Hydra backend to execute
|
||||
// CPU computations via the Hydra ExtComputation framework.
|
||||
//
|
||||
// Note:
|
||||
// The computation execution happens during Rprim sync. This precludes the
|
||||
// use of computations shared by multiple Rprims, since the chain of
|
||||
// computations for a computation primvar is executed for each Rprim.
|
||||
class HdExtComputationUtils {
|
||||
public:
|
||||
using ValueStore =
|
||||
std::unordered_map<TfToken, VtValue, TfToken::HashFunctor>;
|
||||
|
||||
// Returns a map containing the (token, value) pairs for each "computation
|
||||
// primvar".
|
||||
// The participating computations are ordered based on their dependency
|
||||
// and then, the CPU kernel is executed for each computation.
|
||||
HD_API
|
||||
static ValueStore
|
||||
GetComputedPrimvarValues(
|
||||
HdExtComputationPrimvarDescriptorVector const& compPrimvars,
|
||||
HdSceneDelegate* sceneDelegate);
|
||||
|
||||
template <unsigned int CAPACITY>
|
||||
using SampledValueStore =
|
||||
std::unordered_map<TfToken, HdTimeSampleArray<VtValue, CAPACITY>,
|
||||
TfToken::HashFunctor>;
|
||||
|
||||
/// Returns a map containing the (token, samples) pairs for each
|
||||
/// computation primvar, with up to \a maxSampleCount samples.
|
||||
/// The participating computations are ordered based on their dependency
|
||||
/// and then, the CPU kernel is executed for each computation.
|
||||
template <unsigned int CAPACITY>
|
||||
static void
|
||||
SampleComputedPrimvarValues(
|
||||
HdExtComputationPrimvarDescriptorVector const& compPrimvars,
|
||||
HdSceneDelegate* sceneDelegate,
|
||||
size_t maxSampleCount,
|
||||
SampledValueStore<CAPACITY> *computedPrimvarValueStore);
|
||||
|
||||
// Helper methods (these are public for testing purposes)
|
||||
using ComputationDependencyMap =
|
||||
std::unordered_map<HdExtComputation const *,
|
||||
HdExtComputationConstPtrVector>;
|
||||
// Returns true if an ordering of the computations wherein any dependencies
|
||||
// of a given computation come before it is possible, and fills
|
||||
// sortedComps with the ordering.
|
||||
// Returns false otherwise.
|
||||
// The directed graph of a computation (vertex) and its dependencies (edges)
|
||||
// is represented via the ComputationDependencyMap.
|
||||
HD_API
|
||||
static bool
|
||||
DependencySort(ComputationDependencyMap cdm,
|
||||
HdExtComputationConstPtrVector* sortedComps);
|
||||
|
||||
HD_API
|
||||
static void
|
||||
PrintDependencyMap(ComputationDependencyMap const& cdm);
|
||||
|
||||
private:
|
||||
HD_API
|
||||
static ComputationDependencyMap
|
||||
_GenerateDependencyMap(
|
||||
HdExtComputationPrimvarDescriptorVector const& compPrimvars,
|
||||
HdSceneDelegate* sceneDelegate);
|
||||
|
||||
template <unsigned int CAPACITY>
|
||||
static void
|
||||
_ExecuteSampledComputations(
|
||||
HdExtComputationConstPtrVector computations,
|
||||
HdSceneDelegate* sceneDelegate,
|
||||
size_t maxSampleCount,
|
||||
SampledValueStore<CAPACITY>* valueStore);
|
||||
|
||||
// Limits the list of the computation input time samples to the specified
|
||||
// maximum number of (unique) samples.
|
||||
HD_API
|
||||
static void
|
||||
_LimitTimeSamples(size_t maxSampleCount, std::vector<double>* times);
|
||||
|
||||
// Internal method to invoke the computation with the specified input
|
||||
// values, storing the output values in the provided buffer. The value
|
||||
// arrays correspond to GetSceneInputNames(), GetComputationInputs(), and
|
||||
// GetComputationOutputs() from the HdExtComputation, respectively, and are
|
||||
// required to have the same lengths.
|
||||
HD_API
|
||||
static bool
|
||||
_InvokeComputation(
|
||||
HdSceneDelegate& sceneDelegate,
|
||||
HdExtComputation const& computation,
|
||||
TfSpan<const VtValue> sceneInputValues,
|
||||
TfSpan<const VtValue> compInputValues,
|
||||
TfSpan<VtValue> compOutputValues);
|
||||
};
|
||||
|
||||
template <unsigned int CAPACITY>
|
||||
/*static*/ void
|
||||
HdExtComputationUtils::SampleComputedPrimvarValues(
|
||||
HdExtComputationPrimvarDescriptorVector const& compPrimvars,
|
||||
HdSceneDelegate* sceneDelegate,
|
||||
size_t maxSampleCount,
|
||||
SampledValueStore<CAPACITY> *computedPrimvarValueStore
|
||||
)
|
||||
{
|
||||
HD_TRACE_FUNCTION();
|
||||
|
||||
// Directed graph representation of the participating computations
|
||||
ComputationDependencyMap cdm =
|
||||
_GenerateDependencyMap(compPrimvars, sceneDelegate);
|
||||
|
||||
// Topological ordering of the computations
|
||||
HdExtComputationConstPtrVector sortedComputations;
|
||||
bool success = DependencySort(cdm, &sortedComputations);
|
||||
if (!success) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Execution
|
||||
SampledValueStore<CAPACITY> valueStore;
|
||||
_ExecuteSampledComputations<CAPACITY>(sortedComputations, sceneDelegate,
|
||||
maxSampleCount, &valueStore);
|
||||
|
||||
// Output extraction
|
||||
for (auto const& pv : compPrimvars) {
|
||||
TfToken const& compOutputName = pv.sourceComputationOutputName;
|
||||
(*computedPrimvarValueStore)[pv.name] = valueStore[compOutputName];
|
||||
}
|
||||
}
|
||||
|
||||
template <unsigned int CAPACITY>
|
||||
/*static*/ void
|
||||
HdExtComputationUtils::_ExecuteSampledComputations(
|
||||
HdExtComputationConstPtrVector computations,
|
||||
HdSceneDelegate* sceneDelegate,
|
||||
size_t maxSampleCount,
|
||||
SampledValueStore<CAPACITY> *valueStore
|
||||
)
|
||||
{
|
||||
HD_TRACE_FUNCTION();
|
||||
|
||||
for (auto const& comp : computations) {
|
||||
SdfPath const& compId = comp->GetId();
|
||||
|
||||
TfTokenVector const& sceneInputNames = comp->GetSceneInputNames();
|
||||
HdExtComputationInputDescriptorVector const& compInputs =
|
||||
comp->GetComputationInputs();
|
||||
HdExtComputationOutputDescriptorVector const& compOutputs =
|
||||
comp->GetComputationOutputs();
|
||||
|
||||
// Add all the scene inputs to the value store
|
||||
std::vector<double> times;
|
||||
for (TfToken const& input : sceneInputNames) {
|
||||
auto &samples = (*valueStore)[input];
|
||||
sceneDelegate->SampleExtComputationInput(compId, input, &samples);
|
||||
|
||||
for (size_t i = 0; i < samples.count; ++i)
|
||||
times.push_back(samples.times[i]);
|
||||
}
|
||||
|
||||
if (comp->IsInputAggregation()) {
|
||||
// An aggregator computation produces no output, and thus
|
||||
// doesn't need to be executed.
|
||||
continue;
|
||||
}
|
||||
|
||||
// Also find all the time samples from the computed inputs.
|
||||
for (auto const& computedInput : compInputs) {
|
||||
auto const& samples =
|
||||
valueStore->at(computedInput.sourceComputationOutputName);
|
||||
for (size_t i = 0; i < samples.count; ++i) {
|
||||
times.push_back(samples.times[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// Determine the time samples to evaluate the computation at.
|
||||
_LimitTimeSamples(maxSampleCount, ×);
|
||||
|
||||
// Allocate enough space for the evaluated outputs.
|
||||
for (const TfToken &name : comp->GetOutputNames())
|
||||
{
|
||||
auto &output_samples = (*valueStore)[name];
|
||||
output_samples.Resize(times.size());
|
||||
output_samples.count = 0;
|
||||
}
|
||||
|
||||
TfSmallVector<VtValue, CAPACITY> sceneInputValues;
|
||||
sceneInputValues.reserve(sceneInputNames.size());
|
||||
|
||||
TfSmallVector<VtValue, CAPACITY> compInputValues;
|
||||
compInputValues.reserve(compInputs.size());
|
||||
|
||||
TfSmallVector<VtValue, CAPACITY> compOutputValues;
|
||||
|
||||
// Evaluate the computation for each time sample.
|
||||
for (double t : times) {
|
||||
|
||||
// Retrieve all the inputs (scene, computed) from the value store,
|
||||
// resampled to the required time.
|
||||
sceneInputValues.clear();
|
||||
for (auto const& sceneInput : comp->GetSceneInputNames()) {
|
||||
auto const& samples = valueStore->at(sceneInput);
|
||||
sceneInputValues.push_back(samples.Resample(t));
|
||||
}
|
||||
|
||||
compInputValues.clear();
|
||||
for (auto const& computedInput : compInputs) {
|
||||
auto const& samples =
|
||||
valueStore->at(computedInput.sourceComputationOutputName);
|
||||
compInputValues.push_back(samples.Resample(t));
|
||||
}
|
||||
|
||||
compOutputValues.resize(compOutputs.size());
|
||||
if (!_InvokeComputation(*sceneDelegate, *comp,
|
||||
TfMakeSpan(sceneInputValues),
|
||||
TfMakeSpan(compInputValues),
|
||||
TfMakeSpan(compOutputValues))) {
|
||||
// We could bail here, or choose to execute other computations.
|
||||
// Choose the latter.
|
||||
continue;
|
||||
}
|
||||
|
||||
// Add outputs to the value store (subsequent computations may need
|
||||
// them as computation inputs)
|
||||
for (size_t i = 0; i < compOutputValues.size(); ++i) {
|
||||
auto &output_samples = (*valueStore)[compOutputs[i].name];
|
||||
|
||||
output_samples.times[output_samples.count] = t;
|
||||
output_samples.values[output_samples.count] =
|
||||
std::move(compOutputValues[i]);
|
||||
++output_samples.count;
|
||||
}
|
||||
}
|
||||
|
||||
} // for each computation
|
||||
}
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_EXT_COMPUTATION_UTILS_H
|
||||
@@ -0,0 +1,119 @@
|
||||
//
|
||||
// Copyright 2021 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// This file is generated by a script. Do not edit directly. Edit the
|
||||
// schema.template.h file to make changes.
|
||||
|
||||
#ifndef PXR_IMAGING_HD_EXTENT_SCHEMA_H
|
||||
#define PXR_IMAGING_HD_EXTENT_SCHEMA_H
|
||||
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
|
||||
#include "pxr/imaging/hd/schema.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define HDEXTENT_SCHEMA_TOKENS \
|
||||
(extent) \
|
||||
(min) \
|
||||
(max) \
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdExtentSchemaTokens, HD_API,
|
||||
HDEXTENT_SCHEMA_TOKENS);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class HdExtentSchema : public HdSchema
|
||||
{
|
||||
public:
|
||||
HdExtentSchema(HdContainerDataSourceHandle container)
|
||||
: HdSchema(container) {}
|
||||
|
||||
//ACCESSORS
|
||||
|
||||
HD_API
|
||||
HdVec3dDataSourceHandle GetMin();
|
||||
HD_API
|
||||
HdVec3dDataSourceHandle GetMax();
|
||||
|
||||
// RETRIEVING AND CONSTRUCTING
|
||||
|
||||
/// 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 HdVec3dDataSourceHandle &min,
|
||||
const HdVec3dDataSourceHandle &max
|
||||
);
|
||||
|
||||
/// \class HdExtentSchema::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 &SetMin(
|
||||
const HdVec3dDataSourceHandle &min);
|
||||
HD_API
|
||||
Builder &SetMax(
|
||||
const HdVec3dDataSourceHandle &max);
|
||||
|
||||
/// Returns a container data source containing the members set thus far.
|
||||
HD_API
|
||||
HdContainerDataSourceHandle Build();
|
||||
|
||||
private:
|
||||
HdVec3dDataSourceHandle _min;
|
||||
HdVec3dDataSourceHandle _max;
|
||||
};
|
||||
|
||||
/// Retrieves a container data source with the schema's default name token
|
||||
/// "extent" from the parent container and constructs a
|
||||
/// HdExtentSchema 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 HdExtentSchema GetFromParent(
|
||||
const HdContainerDataSourceHandle &fromParentContainer);
|
||||
|
||||
/// 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();
|
||||
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,69 @@
|
||||
//
|
||||
// Copyright 2018 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_FIELD_H
|
||||
#define PXR_IMAGING_HD_FIELD_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/bprim.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
#define HD_FIELD_TOKENS \
|
||||
(filePath) \
|
||||
(fieldName)
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdFieldTokens, HD_API, HD_FIELD_TOKENS);
|
||||
|
||||
class HdSceneDelegate;
|
||||
typedef std::vector<class HdField const *> HdFieldPtrConstVector;
|
||||
|
||||
/// \class HdField
|
||||
///
|
||||
/// Hydra schema for a USD field primitive. Acts like a texture, combined
|
||||
/// with other fields to make up a renderable volume.
|
||||
///
|
||||
class HdField : public HdBprim {
|
||||
public:
|
||||
HD_API
|
||||
HdField(SdfPath const & id);
|
||||
HD_API
|
||||
virtual ~HdField();
|
||||
|
||||
// Change tracking for HdField
|
||||
enum DirtyBits : HdDirtyBits {
|
||||
Clean = 0,
|
||||
DirtyTransform = 1 << 0,
|
||||
DirtyParams = 1 << 1,
|
||||
AllDirty = (DirtyTransform
|
||||
|DirtyParams)
|
||||
};
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_FIELD_H
|
||||
@@ -0,0 +1,127 @@
|
||||
//
|
||||
// Copyright 2021 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_FILTERING_SCENE_INDEX_H
|
||||
#define PXR_IMAGING_HD_FILTERING_SCENE_INDEX_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
|
||||
#include <set>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "pxr/base/tf/declarePtrs.h"
|
||||
#include "pxr/base/tf/singleton.h"
|
||||
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
|
||||
#include "pxr/imaging/hd/dataSource.h"
|
||||
#include "pxr/imaging/hd/dataSourceLocator.h"
|
||||
#include "pxr/imaging/hd/sceneIndex.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
TF_DECLARE_WEAK_AND_REF_PTRS(HdFilteringSceneIndexBase);
|
||||
|
||||
///
|
||||
/// \class HdFilteringSceneIndexBase
|
||||
///
|
||||
/// An abstract base class for scene indexes that have one or more input scene
|
||||
/// indexes which serve as a basis for their own scene.
|
||||
///
|
||||
class HdFilteringSceneIndexBase : public HdSceneIndexBase
|
||||
{
|
||||
public:
|
||||
virtual std::vector<HdSceneIndexBaseRefPtr> GetInputScenes() const = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
TF_DECLARE_WEAK_AND_REF_PTRS(HdSingleInputFilteringSceneIndexBase);
|
||||
|
||||
///
|
||||
/// \class HdSingleInputFilteringSceneIndexBase
|
||||
///
|
||||
/// An abstract base class for a filtering scene index that observes a single
|
||||
/// input scene index.
|
||||
///
|
||||
class HdSingleInputFilteringSceneIndexBase : public HdFilteringSceneIndexBase
|
||||
{
|
||||
public:
|
||||
|
||||
std::vector<HdSceneIndexBaseRefPtr> GetInputScenes() const final;
|
||||
|
||||
protected:
|
||||
|
||||
HdSingleInputFilteringSceneIndexBase(
|
||||
const HdSceneIndexBaseRefPtr &inputSceneIndex);
|
||||
|
||||
virtual void _PrimsAdded(
|
||||
const HdSceneIndexBase &sender,
|
||||
const HdSceneIndexObserver::AddedPrimEntries &entries) = 0;
|
||||
|
||||
virtual void _PrimsRemoved(
|
||||
const HdSceneIndexBase &sender,
|
||||
const HdSceneIndexObserver::RemovedPrimEntries &entries) = 0;
|
||||
|
||||
virtual void _PrimsDirtied(
|
||||
const HdSceneIndexBase &sender,
|
||||
const HdSceneIndexObserver::DirtiedPrimEntries &entries) = 0;
|
||||
|
||||
const HdSceneIndexBaseRefPtr &_GetInputSceneIndex() const {
|
||||
return _inputSceneIndex;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
HdSceneIndexBaseRefPtr _inputSceneIndex;
|
||||
|
||||
friend class _Observer;
|
||||
|
||||
class _Observer : public HdSceneIndexObserver
|
||||
{
|
||||
public:
|
||||
_Observer(HdSingleInputFilteringSceneIndexBase *owner)
|
||||
: _owner(owner) {}
|
||||
|
||||
void PrimsAdded(
|
||||
const HdSceneIndexBase &sender,
|
||||
const AddedPrimEntries &entries) override;
|
||||
|
||||
void PrimsRemoved(
|
||||
const HdSceneIndexBase &sender,
|
||||
const RemovedPrimEntries &entries) override;
|
||||
|
||||
void PrimsDirtied(
|
||||
const HdSceneIndexBase &sender,
|
||||
const DirtiedPrimEntries &entries) override;
|
||||
private:
|
||||
HdSingleInputFilteringSceneIndexBase *_owner;
|
||||
};
|
||||
|
||||
_Observer _observer;
|
||||
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_FILTERING_SCENE_INDEX_H
|
||||
@@ -0,0 +1,109 @@
|
||||
//
|
||||
// Copyright 2018 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_FLAT_NORMALS_H
|
||||
#define PXR_IMAGING_HD_FLAT_NORMALS_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/bufferSource.h"
|
||||
#include "pxr/imaging/hd/computation.h"
|
||||
#include "pxr/imaging/hd/types.h"
|
||||
|
||||
#include "pxr/base/gf/vec3d.h"
|
||||
#include "pxr/base/gf/vec3f.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdMeshTopology;
|
||||
|
||||
/// \class Hd_FlatNormals
|
||||
///
|
||||
/// Hd_FlatNormals encapsulates mesh flat normals information.
|
||||
/// It uses passed-in face index data and points data to compute
|
||||
/// flat per-face normals. It does this by breaking each face into
|
||||
/// a triangle fan centered at vertex 0, and averaging triangle normals.
|
||||
///
|
||||
class Hd_FlatNormals final {
|
||||
public:
|
||||
/// Computes the flat normals result using the supplied face coord
|
||||
/// information and points data. Returns an array of the same size and
|
||||
/// type as the source points, with optional packing.
|
||||
HD_API
|
||||
static VtArray<GfVec3f> ComputeFlatNormals(
|
||||
HdMeshTopology const * topology,
|
||||
GfVec3f const * pointsPtr);
|
||||
HD_API
|
||||
static VtArray<GfVec3d> ComputeFlatNormals(
|
||||
HdMeshTopology const * topology,
|
||||
GfVec3d const * pointsPtr);
|
||||
HD_API
|
||||
static VtArray<HdVec4f_2_10_10_10_REV> ComputeFlatNormalsPacked(
|
||||
HdMeshTopology const * topology,
|
||||
GfVec3f const * pointsPtr);
|
||||
HD_API
|
||||
static VtArray<HdVec4f_2_10_10_10_REV> ComputeFlatNormalsPacked(
|
||||
HdMeshTopology const * topology,
|
||||
GfVec3d const * pointsPtr);
|
||||
|
||||
private:
|
||||
Hd_FlatNormals() = delete;
|
||||
~Hd_FlatNormals() = delete;
|
||||
};
|
||||
|
||||
/// \class Hd_FlatNormalsComputation
|
||||
///
|
||||
/// Flat normal computation CPU.
|
||||
///
|
||||
class Hd_FlatNormalsComputation : public HdComputedBufferSource {
|
||||
public:
|
||||
HD_API
|
||||
Hd_FlatNormalsComputation(HdMeshTopology const *topology,
|
||||
HdBufferSourceSharedPtr const &points,
|
||||
TfToken const &dstName,
|
||||
bool packed);
|
||||
|
||||
/// overrides
|
||||
HD_API
|
||||
virtual void GetBufferSpecs(HdBufferSpecVector *specs) const override;
|
||||
HD_API
|
||||
virtual bool Resolve() override;
|
||||
HD_API
|
||||
virtual TfToken const &GetName() const override;
|
||||
|
||||
protected:
|
||||
HD_API
|
||||
virtual bool _CheckValid() const override;
|
||||
|
||||
private:
|
||||
HdMeshTopology const *_topology;
|
||||
HdBufferSourceSharedPtr const _points;
|
||||
TfToken _dstName;
|
||||
bool _packed;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_FLAT_NORMALS_H
|
||||
@@ -0,0 +1,150 @@
|
||||
//
|
||||
// Copyright 2021 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_FLATTENING_SCENE_H
|
||||
#define PXR_IMAGING_HD_FLATTENING_SCENE_H
|
||||
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
|
||||
#include "pxr/imaging/hd/filteringSceneIndex.h"
|
||||
|
||||
#include "pxr/usd/sdf/pathTable.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdFlatteningSceneIndex;
|
||||
TF_DECLARE_REF_PTRS(HdFlatteningSceneIndex);
|
||||
|
||||
///
|
||||
/// \class HdFlatteningSceneIndex
|
||||
///
|
||||
/// A scene index that observes an input scene index and produces a comparable
|
||||
/// scene in which inherited state is represented at leaf prims.
|
||||
///
|
||||
/// This kind of representation is typically required for legacy-style
|
||||
/// render delegates that require all the information to be available at the
|
||||
/// leaf prims.
|
||||
///
|
||||
class HdFlatteningSceneIndex : public HdSingleInputFilteringSceneIndexBase
|
||||
{
|
||||
public:
|
||||
|
||||
/// Creates a new flattening scene index.
|
||||
///
|
||||
static HdFlatteningSceneIndexRefPtr New(
|
||||
const HdSceneIndexBaseRefPtr &inputScene) {
|
||||
return TfCreateRefPtr(new HdFlatteningSceneIndex(inputScene));
|
||||
}
|
||||
|
||||
HD_API
|
||||
~HdFlatteningSceneIndex() override;
|
||||
|
||||
// satisfying HdSceneIndexBase
|
||||
HD_API
|
||||
HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override;
|
||||
|
||||
HD_API
|
||||
SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override;
|
||||
|
||||
protected:
|
||||
|
||||
HD_API
|
||||
HdFlatteningSceneIndex(const HdSceneIndexBaseRefPtr &inputScene);
|
||||
|
||||
// satisfying HdSingleInputFilteringSceneIndexBase
|
||||
void _PrimsAdded(
|
||||
const HdSceneIndexBase &sender,
|
||||
const HdSceneIndexObserver::AddedPrimEntries &entries) override;
|
||||
|
||||
void _PrimsRemoved(
|
||||
const HdSceneIndexBase &sender,
|
||||
const HdSceneIndexObserver::RemovedPrimEntries &entries) override;
|
||||
|
||||
void _PrimsDirtied(
|
||||
const HdSceneIndexBase &sender,
|
||||
const HdSceneIndexObserver::DirtiedPrimEntries &entries) override;
|
||||
private:
|
||||
|
||||
// members
|
||||
struct _PrimEntry
|
||||
{
|
||||
HdSceneIndexPrim prim;
|
||||
};
|
||||
|
||||
using _PrimEntryTable = SdfPathTable<_PrimEntry>;
|
||||
_PrimEntryTable _prims;
|
||||
|
||||
HdContainerDataSourceHandle _identityXform;
|
||||
HdContainerDataSourceHandle _identityVis;
|
||||
HdContainerDataSourceHandle _identityPurpose;
|
||||
|
||||
// methods
|
||||
void _DirtyHierarchy(
|
||||
const SdfPath &primPath,
|
||||
const HdDataSourceLocatorSet &dirtyLocators,
|
||||
HdSceneIndexObserver::DirtiedPrimEntries *dirtyEntries);
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
friend class _PrimLevelWrappingDataSource;
|
||||
|
||||
/// wraps the input scene's prim-level data sources in order to deliver
|
||||
/// overriden value
|
||||
class _PrimLevelWrappingDataSource : public HdContainerDataSource
|
||||
{
|
||||
public:
|
||||
HD_DECLARE_DATASOURCE(_PrimLevelWrappingDataSource);
|
||||
|
||||
_PrimLevelWrappingDataSource(
|
||||
const HdFlatteningSceneIndex &scene,
|
||||
const SdfPath &primPath,
|
||||
HdContainerDataSourceHandle inputDataSource);
|
||||
|
||||
void UpdateInputDataSource(HdContainerDataSourceHandle inputDataSource);
|
||||
|
||||
bool PrimDirtied(const HdDataSourceLocatorSet &locators);
|
||||
|
||||
bool Has(const TfToken &name) override;
|
||||
TfTokenVector GetNames() override;
|
||||
HdDataSourceBaseHandle Get(const TfToken &name) override;
|
||||
|
||||
private:
|
||||
HdDataSourceBaseHandle _GetXform();
|
||||
HdDataSourceBaseHandle _GetVis();
|
||||
HdDataSourceBaseHandle _GetPurpose();
|
||||
|
||||
const HdFlatteningSceneIndex &_sceneIndex;
|
||||
SdfPath _primPath;
|
||||
HdContainerDataSourceHandle _inputDataSource;
|
||||
HdContainerDataSourceAtomicHandle _computedXformDataSource;
|
||||
HdContainerDataSourceAtomicHandle _computedVisDataSource;
|
||||
HdContainerDataSourceAtomicHandle _computedPurposeDataSource;
|
||||
};
|
||||
|
||||
HD_DECLARE_DATASOURCE_HANDLES(_PrimLevelWrappingDataSource);
|
||||
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,67 @@
|
||||
//
|
||||
// Copyright 2018 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_GEOM_SUBSET_H
|
||||
#define PXR_IMAGING_HD_GEOM_SUBSET_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
#include "pxr/base/vt/array.h"
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// \class HdGeomSubset
|
||||
///
|
||||
/// Describes a subset of a piece of geometry as a set of indices.
|
||||
///
|
||||
struct HdGeomSubset {
|
||||
enum Type {
|
||||
/// A subset of faces
|
||||
TypeFaceSet,
|
||||
|
||||
// For now, there is only one type, but this may grow in the future
|
||||
// to accomodate edges, points, etc.
|
||||
};
|
||||
|
||||
/// The type of elements this geometry subset includes.
|
||||
Type type;
|
||||
/// The path used to identify this subset in the scene.
|
||||
SdfPath id;
|
||||
/// The path used to identify this material bound to the subset.
|
||||
SdfPath materialId;
|
||||
/// The list of element indices contained in the subset.
|
||||
VtIntArray indices;
|
||||
};
|
||||
|
||||
/// A group of geometry subsets.
|
||||
typedef std::vector<HdGeomSubset> HdGeomSubsets;
|
||||
|
||||
HD_API
|
||||
bool operator==(const HdGeomSubset& lhs, const HdGeomSubset& rhs);
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_GEOM_SUBSET_H
|
||||
@@ -0,0 +1,117 @@
|
||||
//
|
||||
// Copyright 2021 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// This file is generated by a script. Do not edit directly. Edit the
|
||||
// schema.template.h file to make changes.
|
||||
|
||||
#ifndef PXR_IMAGING_HD_GEOM_SUBSET_SCHEMA_H
|
||||
#define PXR_IMAGING_HD_GEOM_SUBSET_SCHEMA_H
|
||||
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
|
||||
#include "pxr/imaging/hd/schema.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define HDGEOMSUBSET_SCHEMA_TOKENS \
|
||||
(type) \
|
||||
(indices) \
|
||||
(typeFaceSet) \
|
||||
(typePointSet) \
|
||||
(typeCurveSet) \
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdGeomSubsetSchemaTokens, HD_API,
|
||||
HDGEOMSUBSET_SCHEMA_TOKENS);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class HdGeomSubsetSchema : public HdSchema
|
||||
{
|
||||
public:
|
||||
HdGeomSubsetSchema(HdContainerDataSourceHandle container)
|
||||
: HdSchema(container) {}
|
||||
|
||||
//ACCESSORS
|
||||
|
||||
HD_API
|
||||
HdTokenDataSourceHandle GetType();
|
||||
HD_API
|
||||
HdIntArrayDataSourceHandle GetIndices();
|
||||
|
||||
// RETRIEVING AND CONSTRUCTING
|
||||
|
||||
/// 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 HdTokenDataSourceHandle &type,
|
||||
const HdIntArrayDataSourceHandle &indices
|
||||
);
|
||||
|
||||
/// \class HdGeomSubsetSchema::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 &SetType(
|
||||
const HdTokenDataSourceHandle &type);
|
||||
HD_API
|
||||
Builder &SetIndices(
|
||||
const HdIntArrayDataSourceHandle &indices);
|
||||
|
||||
/// Returns a container data source containing the members set thus far.
|
||||
HD_API
|
||||
HdContainerDataSourceHandle Build();
|
||||
|
||||
private:
|
||||
HdTokenDataSourceHandle _type;
|
||||
HdIntArrayDataSourceHandle _indices;
|
||||
};
|
||||
|
||||
/// Returns token data source for use as type value.
|
||||
/// Values of...
|
||||
/// - HdGeomSubsetSchemaTokens->typeFaceSet
|
||||
/// - HdGeomSubsetSchemaTokens->typePointSet
|
||||
/// - HdGeomSubsetSchemaTokens->typeCurveSet
|
||||
/// ...will be stored statically and reused for future calls.
|
||||
HD_API
|
||||
static HdTokenDataSourceHandle BuildTypeDataSource(
|
||||
const TfToken &type);
|
||||
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,72 @@
|
||||
//
|
||||
// Copyright 2021 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// This file is generated by a script. Do not edit directly. Edit the
|
||||
// schema.template.h file to make changes.
|
||||
|
||||
#ifndef PXR_IMAGING_HD_GEOM_SUBSETS_SCHEMA_H
|
||||
#define PXR_IMAGING_HD_GEOM_SUBSETS_SCHEMA_H
|
||||
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
|
||||
#include "pxr/imaging/hd/geomSubsetSchema.h"
|
||||
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define HDGEOMSUBSETS_SCHEMA_TOKENS \
|
||||
(geomSubsets) \
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdGeomSubsetsSchemaTokens, HD_API,
|
||||
HDGEOMSUBSETS_SCHEMA_TOKENS);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class HdGeomSubsetsSchema : public HdSchema
|
||||
{
|
||||
public:
|
||||
HdGeomSubsetsSchema(HdContainerDataSourceHandle container)
|
||||
: HdSchema(container) {}
|
||||
|
||||
TfTokenVector GetIds();
|
||||
HdGeomSubsetSchema GetGeomSubset(const TfToken & id);
|
||||
|
||||
|
||||
/// Retrieves a container data source with the schema's default name token
|
||||
/// "geomSubsets" from the parent container and constructs a
|
||||
/// HdGeomSubsetsSchema 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 HdGeomSubsetsSchema GetFromParent(
|
||||
const HdContainerDataSourceHandle &fromParentContainer);
|
||||
|
||||
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,111 @@
|
||||
//
|
||||
// Copyright 2021 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// This file is generated by a script. Do not edit directly. Edit the
|
||||
// schema.template.h file to make changes.
|
||||
|
||||
#ifndef PXR_IMAGING_HD_INSTANCE_CATEGORIES_SCHEMA_H
|
||||
#define PXR_IMAGING_HD_INSTANCE_CATEGORIES_SCHEMA_H
|
||||
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
|
||||
#include "pxr/imaging/hd/schema.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define HDINSTANCECATEGORIES_SCHEMA_TOKENS \
|
||||
(instanceCategories) \
|
||||
(categoriesValues) \
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdInstanceCategoriesSchemaTokens, HD_API,
|
||||
HDINSTANCECATEGORIES_SCHEMA_TOKENS);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class HdInstanceCategoriesSchema : public HdSchema
|
||||
{
|
||||
public:
|
||||
HdInstanceCategoriesSchema(HdContainerDataSourceHandle container)
|
||||
: HdSchema(container) {}
|
||||
|
||||
//ACCESSORS
|
||||
|
||||
HD_API
|
||||
HdVectorDataSourceHandle GetCategoriesValues();
|
||||
|
||||
// RETRIEVING AND CONSTRUCTING
|
||||
|
||||
/// 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 HdVectorDataSourceHandle &categoriesValues
|
||||
);
|
||||
|
||||
/// \class HdInstanceCategoriesSchema::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 &SetCategoriesValues(
|
||||
const HdVectorDataSourceHandle &categoriesValues);
|
||||
|
||||
/// Returns a container data source containing the members set thus far.
|
||||
HD_API
|
||||
HdContainerDataSourceHandle Build();
|
||||
|
||||
private:
|
||||
HdVectorDataSourceHandle _categoriesValues;
|
||||
};
|
||||
|
||||
/// Retrieves a container data source with the schema's default name token
|
||||
/// "instanceCategories" from the parent container and constructs a
|
||||
/// HdInstanceCategoriesSchema 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 HdInstanceCategoriesSchema GetFromParent(
|
||||
const HdContainerDataSourceHandle &fromParentContainer);
|
||||
|
||||
/// 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();
|
||||
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,287 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_INSTANCE_REGISTRY_H
|
||||
#define PXR_IMAGING_HD_INSTANCE_REGISTRY_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/perfLog.h"
|
||||
#include "pxr/imaging/hf/perfLog.h"
|
||||
|
||||
#include <tbb/concurrent_unordered_map.h>
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
/// \class HdInstance
|
||||
///
|
||||
/// This class is used as an interface to a shared instance in
|
||||
/// HdInstanceRegistry.
|
||||
///
|
||||
/// KeyType is a hashable index type and VALUE is shared_ptr. In most use
|
||||
/// cases, the client computes a hash key which represents large bulky data
|
||||
/// (like topology, primvars) and registers it into HdInstanceRegistry. If the
|
||||
/// key has already been registered, the registry returns HdInstance and the
|
||||
/// client can use GetValue() without setting/computing actual bulky data. If
|
||||
/// it doesn't exist, IsFirstInstance() returns true for the first instance
|
||||
/// and the client needs to populate an appropriate data VALUE into the
|
||||
/// instance by SetValue().
|
||||
///
|
||||
/// In order to support concurrent access to HdInstanceRegistry, this
|
||||
/// class holds a lock to a mutex in HdInstanceRegistry. This lock will
|
||||
/// be held until the instance of this interface class is destroyed.
|
||||
///
|
||||
template <typename VALUE>
|
||||
class HdInstance {
|
||||
public:
|
||||
typedef uint64_t KeyType;
|
||||
typedef VALUE ValueType;
|
||||
|
||||
typedef KeyType ID;
|
||||
|
||||
struct ValueHolder {
|
||||
ValueHolder(ValueType const & value = ValueType())
|
||||
: value(value)
|
||||
, recycleCounter(0)
|
||||
{ }
|
||||
void ResetRecycleCounter() {
|
||||
recycleCounter = 0;
|
||||
}
|
||||
|
||||
ValueType value;
|
||||
int recycleCounter;
|
||||
};
|
||||
typedef tbb::concurrent_unordered_map<KeyType, ValueHolder> Dictionary;
|
||||
|
||||
typedef std::mutex RegistryMutex;
|
||||
typedef std::unique_lock<RegistryMutex> RegistryLock;
|
||||
|
||||
HdInstance() = delete;
|
||||
|
||||
/// Construct an instance holding a registry lock, representing a value
|
||||
/// held in a registry container.
|
||||
explicit HdInstance(KeyType const &key,
|
||||
ValueType const &value,
|
||||
RegistryLock &®istryLock,
|
||||
Dictionary *container)
|
||||
: _key(key)
|
||||
, _value(value)
|
||||
, _registryLock(std::move(registryLock))
|
||||
, _container(container)
|
||||
, _isFirstInstance(!bool(_value))
|
||||
{ }
|
||||
|
||||
/// Construct an instance with no lock or registry container. This
|
||||
/// is used to present a consistent interface to clients in cases
|
||||
/// where shared resource registration is disabled.
|
||||
explicit HdInstance(KeyType const &key)
|
||||
: _key(key)
|
||||
, _value(ValueType())
|
||||
, _registryLock()
|
||||
, _container(nullptr)
|
||||
, _isFirstInstance(!bool(_value))
|
||||
{ }
|
||||
|
||||
/// Returns the key
|
||||
KeyType const &GetKey() const { return _key; }
|
||||
|
||||
/// Returns the value
|
||||
ValueType const &GetValue() const { return _value; }
|
||||
|
||||
/// Update the value in dictionary indexed by the key.
|
||||
void SetValue(ValueType const &value) {
|
||||
if (_container) (*_container)[_key] = ValueHolder(value);
|
||||
_value = value;
|
||||
}
|
||||
|
||||
/// Returns true if the value has not been initialized.
|
||||
bool IsFirstInstance() const {
|
||||
return _isFirstInstance;
|
||||
}
|
||||
|
||||
private:
|
||||
KeyType _key;
|
||||
ValueType _value;
|
||||
RegistryLock _registryLock;
|
||||
Dictionary *_container;
|
||||
bool _isFirstInstance;
|
||||
};
|
||||
|
||||
/// \class HdInstanceRegistry
|
||||
///
|
||||
/// HdInstanceRegistry is a dictionary container of HdInstance.
|
||||
/// This class is almost just a dictionary from key to value.
|
||||
/// For cleaning unused entries, it provides GarbageCollect() API.
|
||||
/// It sweeps all entries in the dictionary and erase unreferenced entries.
|
||||
/// When HdInstance::ValueType is shared_ptr, it is regarded as unreferenced
|
||||
/// if the shared_ptr is unique (use_count==1). Note that Key is not
|
||||
/// involved to determine the lifetime of entries.
|
||||
///
|
||||
template <typename VALUE>
|
||||
class HdInstanceRegistry {
|
||||
public:
|
||||
typedef HdInstance<VALUE> InstanceType;
|
||||
|
||||
HdInstanceRegistry() = default;
|
||||
|
||||
/// Copy constructor. Need as HdInstanceRegistry is placed in a map
|
||||
/// and mutex is not copy constructable, so can't use default
|
||||
HdInstanceRegistry(const HdInstanceRegistry &other)
|
||||
: _dictionary(other._dictionary)
|
||||
, _registryMutex() // mutex is not copied
|
||||
{ }
|
||||
|
||||
/// Returns a shared instance for given key.
|
||||
InstanceType GetInstance(
|
||||
typename InstanceType::KeyType const &key);
|
||||
|
||||
/// Returns a shared instance for a given key
|
||||
/// only if the key exists in the dictionary.
|
||||
InstanceType FindInstance(
|
||||
typename InstanceType::KeyType const &key, bool *found);
|
||||
|
||||
/// Removes unreferenced entries and returns the count
|
||||
/// of remaining entries. When recycleCount is greater than zero,
|
||||
/// unreferenced entries will not be removed until GarbageCollect() is
|
||||
/// called that many more times, i.e. allowing unreferenced entries to
|
||||
/// be recycled if they are needed again.
|
||||
size_t GarbageCollect(int recycleCount = 0);
|
||||
|
||||
/// Returns a const iterator being/end of dictionary. Mainly used for
|
||||
/// resource auditing.
|
||||
typedef typename InstanceType::Dictionary::const_iterator const_iterator;
|
||||
const_iterator begin() const { return _dictionary.begin(); }
|
||||
const_iterator end() const { return _dictionary.end(); }
|
||||
|
||||
size_t size() const { return _dictionary.size(); }
|
||||
|
||||
void Invalidate();
|
||||
|
||||
private:
|
||||
template <typename T>
|
||||
static bool _IsUnique(std::shared_ptr<T> const &value) {
|
||||
return value.unique();
|
||||
}
|
||||
|
||||
typename InstanceType::Dictionary _dictionary;
|
||||
typename InstanceType::RegistryMutex _registryMutex;
|
||||
|
||||
HdInstanceRegistry &operator =(HdInstanceRegistry &) = delete;
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// instance registry impl
|
||||
|
||||
template <typename VALUE>
|
||||
HdInstance<VALUE>
|
||||
HdInstanceRegistry<VALUE>::GetInstance(
|
||||
typename HdInstance<VALUE>::KeyType const &key)
|
||||
{
|
||||
HD_TRACE_FUNCTION();
|
||||
HF_MALLOC_TAG_FUNCTION();
|
||||
|
||||
// Grab Registry lock
|
||||
// (and don't release it in this function, return it instead)
|
||||
typename InstanceType::RegistryLock lock(_registryMutex);
|
||||
|
||||
typename InstanceType::Dictionary::iterator it = _dictionary.find(key);
|
||||
if (it == _dictionary.end()) {
|
||||
// not found. create new one
|
||||
it = _dictionary.insert(
|
||||
std::make_pair(key, typename InstanceType::ValueHolder())).first;
|
||||
}
|
||||
|
||||
it->second.ResetRecycleCounter();
|
||||
return InstanceType(key, it->second.value, std::move(lock), &_dictionary);
|
||||
}
|
||||
|
||||
template <typename VALUE>
|
||||
HdInstance<VALUE>
|
||||
HdInstanceRegistry<VALUE>::FindInstance(
|
||||
typename HdInstance<VALUE>::KeyType const &key, bool *found)
|
||||
{
|
||||
HD_TRACE_FUNCTION();
|
||||
HF_MALLOC_TAG_FUNCTION();
|
||||
|
||||
// Grab Registry lock
|
||||
// (and don't release it in this function, return it instead)
|
||||
typename InstanceType::RegistryLock lock(_registryMutex);
|
||||
|
||||
typename InstanceType::Dictionary::iterator it = _dictionary.find(key);
|
||||
if (it == _dictionary.end()) {
|
||||
*found = false;
|
||||
return InstanceType(key, VALUE(), std::move(lock), nullptr);
|
||||
} else {
|
||||
*found = true;
|
||||
it->second.ResetRecycleCounter();
|
||||
return InstanceType(key, it->second.value,std::move(lock),&_dictionary);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename VALUE>
|
||||
size_t
|
||||
HdInstanceRegistry<VALUE>::GarbageCollect(int recycleCount)
|
||||
{
|
||||
HD_TRACE_FUNCTION();
|
||||
HF_MALLOC_TAG_FUNCTION();
|
||||
|
||||
// Skip garbage collection entirely when then the recycleCount is < 0
|
||||
if (recycleCount < 0) {
|
||||
return _dictionary.size();
|
||||
}
|
||||
|
||||
size_t inUseCount = 0;
|
||||
for (typename InstanceType::Dictionary::iterator it = _dictionary.begin();
|
||||
it != _dictionary.end();) {
|
||||
|
||||
// erase instance which isn't referred from anyone
|
||||
bool isUnique = _IsUnique(it->second.value);
|
||||
if (isUnique && (++it->second.recycleCounter > recycleCount)) {
|
||||
it = _dictionary.unsafe_erase(it);
|
||||
} else {
|
||||
++it;
|
||||
++inUseCount;
|
||||
}
|
||||
}
|
||||
return inUseCount;
|
||||
}
|
||||
|
||||
template <typename VALUE>
|
||||
void
|
||||
HdInstanceRegistry<VALUE>::Invalidate()
|
||||
{
|
||||
HD_TRACE_FUNCTION();
|
||||
HF_MALLOC_TAG_FUNCTION();
|
||||
|
||||
_dictionary.clear();
|
||||
}
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_INSTANCE_REGISTRY_H
|
||||
@@ -0,0 +1,121 @@
|
||||
//
|
||||
// Copyright 2021 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// This file is generated by a script. Do not edit directly. Edit the
|
||||
// schema.template.h file to make changes.
|
||||
|
||||
#ifndef PXR_IMAGING_HD_INSTANCE_SCHEMA_H
|
||||
#define PXR_IMAGING_HD_INSTANCE_SCHEMA_H
|
||||
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
|
||||
#include "pxr/imaging/hd/schema.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define HDINSTANCE_SCHEMA_TOKENS \
|
||||
(instancer) \
|
||||
(path) \
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdInstanceSchemaTokens, HD_API,
|
||||
HDINSTANCE_SCHEMA_TOKENS);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// This schema can be considered the opposite of instancerTopology's
|
||||
// "instanceLocations". When the scene coalesces scene prims into multiple
|
||||
// instances of a single prototype, it inserts "instance" prims at the site
|
||||
// of de-duplication. The instancer prim added to manage the prototype
|
||||
// uses "instanceLocations" to point back to all of these instance prims.
|
||||
//
|
||||
// The instance prims aren't directly useful for rendering but can be useful
|
||||
// for scene processing and data aggregation.
|
||||
|
||||
|
||||
class HdInstanceSchema : public HdSchema
|
||||
{
|
||||
public:
|
||||
HdInstanceSchema(HdContainerDataSourceHandle container)
|
||||
: HdSchema(container) {}
|
||||
|
||||
//ACCESSORS
|
||||
|
||||
HD_API
|
||||
HdPathArrayDataSourceHandle GetPath();
|
||||
|
||||
// RETRIEVING AND CONSTRUCTING
|
||||
|
||||
/// 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 HdPathArrayDataSourceHandle &path
|
||||
);
|
||||
|
||||
/// \class HdInstanceSchema::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 &SetPath(
|
||||
const HdPathArrayDataSourceHandle &path);
|
||||
|
||||
/// Returns a container data source containing the members set thus far.
|
||||
HD_API
|
||||
HdContainerDataSourceHandle Build();
|
||||
|
||||
private:
|
||||
HdPathArrayDataSourceHandle _path;
|
||||
};
|
||||
|
||||
/// Retrieves a container data source with the schema's default name token
|
||||
/// "instancer" from the parent container and constructs a
|
||||
/// HdInstanceSchema 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 HdInstanceSchema GetFromParent(
|
||||
const HdContainerDataSourceHandle &fromParentContainer);
|
||||
|
||||
/// 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();
|
||||
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,131 @@
|
||||
//
|
||||
// Copyright 2021 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// This file is generated by a script. Do not edit directly. Edit the
|
||||
// schema.template.h file to make changes.
|
||||
|
||||
#ifndef PXR_IMAGING_HD_INSTANCED_BY_SCHEMA_H
|
||||
#define PXR_IMAGING_HD_INSTANCED_BY_SCHEMA_H
|
||||
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
|
||||
#include "pxr/imaging/hd/schema.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define HDINSTANCEDBY_SCHEMA_TOKENS \
|
||||
(instancedBy) \
|
||||
(paths) \
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdInstancedBySchemaTokens, HD_API,
|
||||
HDINSTANCEDBY_SCHEMA_TOKENS);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// A schema marking a prim as instanced by another prim.
|
||||
//
|
||||
// Many renderers need to know not what prototypes an instancer has, but
|
||||
// rather what instancers a prototype has; this is encoded in
|
||||
// "instancedBy". A prim is "instancedBy" /Instancer if /Instancer has
|
||||
// a prototype path that's a parent of the prim. A complicating exception is
|
||||
// if /A instances /A/B, which instances /A/B/C, we don't consider /A to be
|
||||
// instancing /A/B/C directly; this is to support nested explicit instancing
|
||||
// of things like leaves/trees/forests.
|
||||
//
|
||||
// This value is computed based on the instancer topology of instancer prims in
|
||||
// the scene.
|
||||
//
|
||||
// Note: if multiple instancers reference a prototype, it's possible for
|
||||
// instancedBy to contain multiple entries. Some renderers may be able to
|
||||
// read this directly, but some may need to duplicate prims with an op so that
|
||||
// each prim has a single instancer, depending on how the renderer exposes
|
||||
// instancing.
|
||||
|
||||
|
||||
class HdInstancedBySchema : public HdSchema
|
||||
{
|
||||
public:
|
||||
HdInstancedBySchema(HdContainerDataSourceHandle container)
|
||||
: HdSchema(container) {}
|
||||
|
||||
//ACCESSORS
|
||||
|
||||
HD_API
|
||||
HdPathArrayDataSourceHandle GetPaths();
|
||||
|
||||
// RETRIEVING AND CONSTRUCTING
|
||||
|
||||
/// 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 HdPathArrayDataSourceHandle &paths
|
||||
);
|
||||
|
||||
/// \class HdInstancedBySchema::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 &SetPaths(
|
||||
const HdPathArrayDataSourceHandle &paths);
|
||||
|
||||
/// Returns a container data source containing the members set thus far.
|
||||
HD_API
|
||||
HdContainerDataSourceHandle Build();
|
||||
|
||||
private:
|
||||
HdPathArrayDataSourceHandle _paths;
|
||||
};
|
||||
|
||||
/// Retrieves a container data source with the schema's default name token
|
||||
/// "instancedBy" from the parent container and constructs a
|
||||
/// HdInstancedBySchema 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 HdInstancedBySchema GetFromParent(
|
||||
const HdContainerDataSourceHandle &fromParentContainer);
|
||||
|
||||
/// 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();
|
||||
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,182 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_INSTANCER_H
|
||||
#define PXR_IMAGING_HD_INSTANCER_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/types.h"
|
||||
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
|
||||
#include <mutex>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdSceneDelegate;
|
||||
class HdRenderIndex;
|
||||
class HdRprim;
|
||||
class HdRenderParam;
|
||||
|
||||
/// \class HdInstancer
|
||||
///
|
||||
/// This class exists to facilitate point cloud style instancing. Instancers,
|
||||
/// conceptually, are instructions to draw N objects; for each object, store
|
||||
/// which Rprim you're drawing and what instance-specific primvars you're
|
||||
/// binding.
|
||||
///
|
||||
/// "/InstancerA": prototypes = ["/sphere", "/cube", "/sphere"];
|
||||
/// translate = [ <0,0,0>, <1,0,0>, <0,1,0>]
|
||||
///
|
||||
/// Hydra stores this in reverse: Rprims store which instancer is drawing them,
|
||||
/// and the instancer stores which indices in that array of N objects are the
|
||||
/// given Rprim.
|
||||
///
|
||||
/// "/sphere": instancerId = "/InstancerA"
|
||||
/// "/cube": instancerId = "/InstancerA"
|
||||
/// Instancer A: indices("/sphere") = [0, 2]
|
||||
/// indices("/cube") = [1]
|
||||
/// translate = [<0,0,0>, <1,0,0>, <0,1,0>]
|
||||
///
|
||||
/// Instancing is implemented by the prototype drawing itself multiple times,
|
||||
/// and looking up per-instance data each time based on "indices": so
|
||||
/// "/sphere" would draw itself once with translate=<0,0,0> and once with
|
||||
/// translate=<0,1,0>.
|
||||
///
|
||||
/// To make things more exciting, instancers can be nested.
|
||||
///
|
||||
/// "/cube": instancerId = "/InstancerA"
|
||||
/// "/InstancerA": instancerId = "/InstancerB"
|
||||
/// indices("/cube") = [0, 1]
|
||||
/// translate = [<0,0,0>, <1,0,0>]
|
||||
/// "/InstancerB": indices("/InstancerA") = [0, 1]
|
||||
/// translate = [<0,0,0>, <0,1,0>]
|
||||
///
|
||||
/// In this case, "/cube" draws itself four times, for each of the
|
||||
/// index tuples <0,0>, <0,1>, <1,0>, <1,1> where the first index is
|
||||
/// the index in instancerA, and the second index is in instancerB.
|
||||
///
|
||||
/// If the same primvar (e.g. "translate") shows up at multiple levels of
|
||||
/// nesting, it's resolved as follows:
|
||||
///
|
||||
/// Transforms
|
||||
/// ----------
|
||||
///
|
||||
/// Instance primvars "translate", "rotate", "scale", and "instanceTransform"
|
||||
/// are used to compute the final transform of an instance. "translate"
|
||||
/// and "scale" are interpreted as vec3: position, and axis-aligned scale
|
||||
/// respectively. "rotate" is interpreted as a vec4 quaternion, and
|
||||
/// "instanceTransform" is a 4x4 matrix. In the transform computation,
|
||||
/// everything is converted to a 4x4 matrix.
|
||||
///
|
||||
/// There are additional transforms: "instancerTransform" comes from
|
||||
/// HdSceneDelegate::GetInstancerTransform(instancer, proto), and represents
|
||||
/// the constant transform between the instancer and the prototype. It
|
||||
/// varies with each level of nesting, but not across instances.
|
||||
///
|
||||
/// "transform" is the proto Rprim's local transform.
|
||||
///
|
||||
/// The final instance transform for instance "index" is computed as:
|
||||
///
|
||||
/// nested_transform(level) = instancerTransform(level) *
|
||||
/// translate(level, index) *
|
||||
/// rotate(level, index) *
|
||||
/// scale(level, index) *
|
||||
/// instanceTransform(level, index);
|
||||
/// output_transform = product(i : nested-levels - 1 -> 0) {
|
||||
/// nested_transform(i)
|
||||
/// } * transform;
|
||||
///
|
||||
/// Any transforms not provided by the scene delegate are set to identity.
|
||||
///
|
||||
/// Class responsibilities
|
||||
/// ======================
|
||||
///
|
||||
/// HdInstancer's primary role is to track the "indices" arrays for each
|
||||
/// proto used by an instancer, and any provided primvar arrays. The
|
||||
/// implementation is in the renderer-specific instancers, like HdStInstancer.
|
||||
///
|
||||
/// All data access (aside from local caches) is routed to the HdSceneDelegate.
|
||||
///
|
||||
|
||||
class HdInstancer {
|
||||
public:
|
||||
/// Constructor.
|
||||
HD_API
|
||||
HdInstancer(HdSceneDelegate* delegate, SdfPath const& id);
|
||||
|
||||
HD_API
|
||||
virtual ~HdInstancer();
|
||||
|
||||
/// Returns the identifier.
|
||||
SdfPath const& GetId() const { return _id; }
|
||||
|
||||
/// Returns the parent instancer identifier.
|
||||
SdfPath const& GetParentId() const { return _parentId; }
|
||||
|
||||
HdSceneDelegate* GetDelegate() const { return _delegate; }
|
||||
|
||||
HD_API
|
||||
static int GetInstancerNumLevels(HdRenderIndex& index,
|
||||
HdRprim const& rprim);
|
||||
|
||||
HD_API
|
||||
static TfTokenVector const & GetBuiltinPrimvarNames();
|
||||
|
||||
HD_API
|
||||
virtual void Sync(HdSceneDelegate *sceneDelegate,
|
||||
HdRenderParam *renderParam,
|
||||
HdDirtyBits *dirtyBits);
|
||||
|
||||
HD_API
|
||||
virtual void Finalize(HdRenderParam *renderParam);
|
||||
|
||||
HD_API
|
||||
virtual HdDirtyBits GetInitialDirtyBitsMask() const;
|
||||
|
||||
HD_API
|
||||
static void _SyncInstancerAndParents(
|
||||
HdRenderIndex &renderIndex,
|
||||
SdfPath const& instancerId);
|
||||
|
||||
protected:
|
||||
HD_API
|
||||
void _UpdateInstancer(HdSceneDelegate *delegate,
|
||||
HdDirtyBits *dirtyBits);
|
||||
|
||||
private:
|
||||
HdSceneDelegate* _delegate;
|
||||
SdfPath _id;
|
||||
SdfPath _parentId;
|
||||
|
||||
// XXX: This mutex exists for _SyncInstancerAndParents, which will go
|
||||
// away when the render index calls sync on instancers.
|
||||
std::mutex _instanceLock;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_INSTANCER_H
|
||||
@@ -0,0 +1,177 @@
|
||||
//
|
||||
// Copyright 2021 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// This file is generated by a script. Do not edit directly. Edit the
|
||||
// schema.template.h file to make changes.
|
||||
|
||||
#ifndef PXR_IMAGING_HD_INSTANCER_TOPOLOGY_SCHEMA_H
|
||||
#define PXR_IMAGING_HD_INSTANCER_TOPOLOGY_SCHEMA_H
|
||||
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
|
||||
#include "pxr/imaging/hd/schema.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define HDINSTANCERTOPOLOGY_SCHEMA_TOKENS \
|
||||
(instancerTopology) \
|
||||
(prototypes) \
|
||||
(instanceIndices) \
|
||||
(mask) \
|
||||
(instanceLocations) \
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdInstancerTopologySchemaTokens, HD_API,
|
||||
HDINSTANCERTOPOLOGY_SCHEMA_TOKENS);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// Since the instancing schema is complicated:
|
||||
//
|
||||
// An instancer is a prim at a certain scenegraph location that causes other
|
||||
// prims to be duplicated. The instancer can also hold instance-varying data
|
||||
// like constant primvars or material relationships.
|
||||
//
|
||||
// The important things an instancer has is:
|
||||
// 1.) Instancer topology, describing how exactly the prims are duplicated;
|
||||
// 2.) Instance-rate data, meaning data that varies per instance, such as
|
||||
// primvars or material bindings.
|
||||
//
|
||||
// If an instancer causes prims "/A" and "/B" to be duplicated, we encode that
|
||||
// by setting prototypes = ["/A", "/B"]. Note that "/A" and "/B" can be
|
||||
// subtrees, not direct gprims. instanceIndices encodes both multiplicity
|
||||
// and position in arrays of instance-rate data, per prototype path; if
|
||||
// instanceIndices = { [0,2], [1] }, then we draw /A twice (with instance
|
||||
// primvar indices 0 and 2); and /B once (with instance primvar index 1).
|
||||
// Mask is an auxiliary parameter that can be used to deactivate certain
|
||||
// instances; mask = [true, true, false] would disable the
|
||||
// second copy of "/A". An empty mask array is the same as all-true.
|
||||
//
|
||||
// Scenes generally specify instancing in one of two ways:
|
||||
// 1.) Explicit instancing: prim /Instancer wants to draw its subtree at
|
||||
// an array of locations. This is a data expansion form.
|
||||
// 2.) Implicit instancing: prims /X and /Y are marked as being identical,
|
||||
// and scene load replaces them with a single prim and an instancer.
|
||||
// This is a data coalescing form.
|
||||
//
|
||||
// For implicit instancing, we want to know the original paths of /X and /Y,
|
||||
// for doing things like resolving inheritance. This is encoded in the
|
||||
// "instanceLocations" path, while the prototype prims (e.g. /_Prototype/Cube,
|
||||
// the deduplicated version of /X/Cube and /Y/Cube) is encoded in the
|
||||
// "prototypes" path.
|
||||
//
|
||||
// For explicit instancing, the "instanceLocations" attribute is meaningless
|
||||
// and should be left null.
|
||||
|
||||
class HdInstancerTopologySchema : public HdSchema
|
||||
{
|
||||
public:
|
||||
HdInstancerTopologySchema(HdContainerDataSourceHandle container)
|
||||
: HdSchema(container) {}
|
||||
|
||||
//ACCESSORS
|
||||
|
||||
HD_API
|
||||
HdPathArrayDataSourceHandle GetPrototypes();
|
||||
|
||||
// Note: expected to be a vector of HdIntArrayDataSource.
|
||||
HD_API
|
||||
HdVectorDataSourceHandle GetInstanceIndices();
|
||||
HD_API
|
||||
HdBoolArrayDataSourceHandle GetMask();
|
||||
HD_API
|
||||
HdPathArrayDataSourceHandle GetInstanceLocations();
|
||||
|
||||
// RETRIEVING AND CONSTRUCTING
|
||||
|
||||
/// 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 HdPathArrayDataSourceHandle &prototypes,
|
||||
const HdVectorDataSourceHandle &instanceIndices,
|
||||
const HdBoolArrayDataSourceHandle &mask,
|
||||
const HdPathArrayDataSourceHandle &instanceLocations
|
||||
);
|
||||
|
||||
/// \class HdInstancerTopologySchema::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 &SetPrototypes(
|
||||
const HdPathArrayDataSourceHandle &prototypes);
|
||||
HD_API
|
||||
Builder &SetInstanceIndices(
|
||||
const HdVectorDataSourceHandle &instanceIndices);
|
||||
HD_API
|
||||
Builder &SetMask(
|
||||
const HdBoolArrayDataSourceHandle &mask);
|
||||
HD_API
|
||||
Builder &SetInstanceLocations(
|
||||
const HdPathArrayDataSourceHandle &instanceLocations);
|
||||
|
||||
/// Returns a container data source containing the members set thus far.
|
||||
HD_API
|
||||
HdContainerDataSourceHandle Build();
|
||||
|
||||
private:
|
||||
HdPathArrayDataSourceHandle _prototypes;
|
||||
HdVectorDataSourceHandle _instanceIndices;
|
||||
HdBoolArrayDataSourceHandle _mask;
|
||||
HdPathArrayDataSourceHandle _instanceLocations;
|
||||
};
|
||||
// HELPERS
|
||||
VtArray<int> ComputeInstanceIndicesForProto(SdfPath const &path);
|
||||
|
||||
|
||||
/// Retrieves a container data source with the schema's default name token
|
||||
/// "instancerTopology" from the parent container and constructs a
|
||||
/// HdInstancerTopologySchema 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 HdInstancerTopologySchema GetFromParent(
|
||||
const HdContainerDataSourceHandle &fromParentContainer);
|
||||
|
||||
/// 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();
|
||||
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,174 @@
|
||||
//
|
||||
// Copyright 2021 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// This file is generated by a script. Do not edit directly. Edit the
|
||||
// schema.template.h file to make changes.
|
||||
|
||||
#ifndef PXR_IMAGING_HD_LEGACY_DISPLAY_STYLE_SCHEMA_H
|
||||
#define PXR_IMAGING_HD_LEGACY_DISPLAY_STYLE_SCHEMA_H
|
||||
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
|
||||
#include "pxr/imaging/hd/schema.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define HDLEGACYDISPLAYSTYLE_SCHEMA_TOKENS \
|
||||
(displayStyle) \
|
||||
(refineLevel) \
|
||||
(flatShadingEnabled) \
|
||||
(displacementEnabled) \
|
||||
(occludedSelectionShowsThrough) \
|
||||
(shadingStyle) \
|
||||
(reprSelector) \
|
||||
(cullStyle) \
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdLegacyDisplayStyleSchemaTokens, HD_API,
|
||||
HDLEGACYDISPLAYSTYLE_SCHEMA_TOKENS);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class HdLegacyDisplayStyleSchema : public HdSchema
|
||||
{
|
||||
public:
|
||||
HdLegacyDisplayStyleSchema(HdContainerDataSourceHandle container)
|
||||
: HdSchema(container) {}
|
||||
|
||||
//ACCESSORS
|
||||
|
||||
HD_API
|
||||
HdIntDataSourceHandle GetRefineLevel();
|
||||
HD_API
|
||||
HdBoolDataSourceHandle GetFlatShadingEnabled();
|
||||
HD_API
|
||||
HdBoolDataSourceHandle GetDisplacementEnabled();
|
||||
HD_API
|
||||
HdBoolDataSourceHandle GetOccludedSelectionShowsThrough();
|
||||
HD_API
|
||||
HdTokenDataSourceHandle GetShadingStyle();
|
||||
HD_API
|
||||
HdTokenArrayDataSourceHandle GetReprSelector();
|
||||
HD_API
|
||||
HdTokenDataSourceHandle GetCullStyle();
|
||||
|
||||
// RETRIEVING AND CONSTRUCTING
|
||||
|
||||
/// 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 HdIntDataSourceHandle &refineLevel,
|
||||
const HdBoolDataSourceHandle &flatShadingEnabled,
|
||||
const HdBoolDataSourceHandle &displacementEnabled,
|
||||
const HdBoolDataSourceHandle &occludedSelectionShowsThrough,
|
||||
const HdTokenDataSourceHandle &shadingStyle,
|
||||
const HdTokenArrayDataSourceHandle &reprSelector,
|
||||
const HdTokenDataSourceHandle &cullStyle
|
||||
);
|
||||
|
||||
/// \class HdLegacyDisplayStyleSchema::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 &SetRefineLevel(
|
||||
const HdIntDataSourceHandle &refineLevel);
|
||||
HD_API
|
||||
Builder &SetFlatShadingEnabled(
|
||||
const HdBoolDataSourceHandle &flatShadingEnabled);
|
||||
HD_API
|
||||
Builder &SetDisplacementEnabled(
|
||||
const HdBoolDataSourceHandle &displacementEnabled);
|
||||
HD_API
|
||||
Builder &SetOccludedSelectionShowsThrough(
|
||||
const HdBoolDataSourceHandle &occludedSelectionShowsThrough);
|
||||
HD_API
|
||||
Builder &SetShadingStyle(
|
||||
const HdTokenDataSourceHandle &shadingStyle);
|
||||
HD_API
|
||||
Builder &SetReprSelector(
|
||||
const HdTokenArrayDataSourceHandle &reprSelector);
|
||||
HD_API
|
||||
Builder &SetCullStyle(
|
||||
const HdTokenDataSourceHandle &cullStyle);
|
||||
|
||||
/// Returns a container data source containing the members set thus far.
|
||||
HD_API
|
||||
HdContainerDataSourceHandle Build();
|
||||
|
||||
private:
|
||||
HdIntDataSourceHandle _refineLevel;
|
||||
HdBoolDataSourceHandle _flatShadingEnabled;
|
||||
HdBoolDataSourceHandle _displacementEnabled;
|
||||
HdBoolDataSourceHandle _occludedSelectionShowsThrough;
|
||||
HdTokenDataSourceHandle _shadingStyle;
|
||||
HdTokenArrayDataSourceHandle _reprSelector;
|
||||
HdTokenDataSourceHandle _cullStyle;
|
||||
};
|
||||
|
||||
/// Retrieves a container data source with the schema's default name token
|
||||
/// "displayStyle" from the parent container and constructs a
|
||||
/// HdLegacyDisplayStyleSchema 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 HdLegacyDisplayStyleSchema GetFromParent(
|
||||
const HdContainerDataSourceHandle &fromParentContainer);
|
||||
|
||||
/// 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();
|
||||
|
||||
|
||||
/// Returns an HdDataSourceLocator (relative to the prim-level data source)
|
||||
/// where the reprselector data source can be found.
|
||||
/// This is often useful for checking intersection against the
|
||||
/// HdDataSourceLocatorSet sent with HdDataSourceObserver::PrimsDirtied.
|
||||
HD_API
|
||||
static const HdDataSourceLocator &GetReprSelectorLocator();
|
||||
|
||||
/// Returns an HdDataSourceLocator (relative to the prim-level data source)
|
||||
/// where the cullstyle data source can be found.
|
||||
/// This is often useful for checking intersection against the
|
||||
/// HdDataSourceLocatorSet sent with HdDataSourceObserver::PrimsDirtied.
|
||||
HD_API
|
||||
static const HdDataSourceLocator &GetCullStyleLocator();
|
||||
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,63 @@
|
||||
//
|
||||
// Copyright 2021 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_LEGACY_PRIM_SCENE_INDEX_H
|
||||
#define PXR_IMAGING_HD_LEGACY_PRIM_SCENE_INDEX_H
|
||||
|
||||
#include "pxr/imaging/hd/retainedSceneIndex.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdSceneDelegate;
|
||||
|
||||
TF_DECLARE_REF_PTRS(HdLegacyPrimSceneIndex);
|
||||
|
||||
/// \class HdLegacyPrimSceneIndex
|
||||
///
|
||||
/// Extends HdRetainedSceneIndex to instantiate and dirty HdDataSourceLegacyPrim
|
||||
/// data sources.
|
||||
///
|
||||
/// During emulation of legacy HdSceneDelegates, HdRenderIndex forwards
|
||||
/// prim insertion calls here to produce a comparable HdSceneIndex
|
||||
/// representation
|
||||
class HdLegacyPrimSceneIndex : public HdRetainedSceneIndex
|
||||
{
|
||||
public:
|
||||
|
||||
static HdLegacyPrimSceneIndexRefPtr New() {
|
||||
return TfCreateRefPtr(new HdLegacyPrimSceneIndex);
|
||||
}
|
||||
|
||||
/// custom insertion wrapper called by HdRenderIndex during population
|
||||
/// of legacy HdSceneDelegates
|
||||
void AddLegacyPrim(SdfPath const &id, TfToken const &type,
|
||||
HdSceneDelegate *sceneDelegate);
|
||||
|
||||
/// extends to also call DirtyPrim on HdDataSourceLegacyPrim
|
||||
void DirtyPrims(
|
||||
const HdSceneIndexObserver::DirtiedPrimEntries &entries) override;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,107 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_LIGHT_H
|
||||
#define PXR_IMAGING_HD_LIGHT_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/sprim.h"
|
||||
|
||||
#include "pxr/base/tf/staticTokens.h"
|
||||
#include "pxr/base/vt/dictionary.h"
|
||||
#include "pxr/base/vt/value.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
#define HD_LIGHT_TOKENS \
|
||||
(angle) \
|
||||
(color) \
|
||||
(colorTemperature) \
|
||||
(enableColorTemperature) \
|
||||
(exposure) \
|
||||
(height) \
|
||||
(intensity) \
|
||||
(radius) \
|
||||
(length) \
|
||||
((textureFile, "texture:file")) \
|
||||
((textureFormat, "texture:format")) \
|
||||
(width) \
|
||||
(diffuse) \
|
||||
(specular) \
|
||||
(normalize) \
|
||||
((shapingFocus, "shaping:focus")) \
|
||||
((shapingFocusTint, "shaping:focusTint")) \
|
||||
((shapingConeAngle, "shaping:cone:angle")) \
|
||||
((shapingConeSoftness, "shaping:cone:softness")) \
|
||||
((shapingIesFile, "shaping:ies:file")) \
|
||||
((shapingIesAngleScale, "shaping:ies:angleScale")) \
|
||||
((shapingIesNormalize, "shaping:ies:normalize")) \
|
||||
((shadowEnable, "shadow:enable")) \
|
||||
((shadowColor, "shadow:color")) \
|
||||
((shadowDistance, "shadow:distance")) \
|
||||
((shadowFalloff, "shadow:falloff")) \
|
||||
((shadowFalloffGamma, "shadow:falloffGamma")) \
|
||||
\
|
||||
(params) \
|
||||
(shadowCollection) \
|
||||
(shadowParams)
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdLightTokens, HD_API, HD_LIGHT_TOKENS);
|
||||
|
||||
class HdSceneDelegate;
|
||||
typedef std::vector<class HdLight const *> HdLightPtrConstVector;
|
||||
|
||||
/// \class HdLight
|
||||
///
|
||||
/// A light model, used in conjunction with HdRenderPass.
|
||||
///
|
||||
class HdLight : public HdSprim {
|
||||
public:
|
||||
HD_API
|
||||
HdLight(SdfPath const & id);
|
||||
HD_API
|
||||
virtual ~HdLight();
|
||||
|
||||
// Change tracking for HdLight
|
||||
enum DirtyBits : HdDirtyBits {
|
||||
Clean = 0,
|
||||
DirtyTransform = 1 << 0,
|
||||
DirtyParams = 1 << 1,
|
||||
DirtyShadowParams = 1 << 2,
|
||||
DirtyCollection = 1 << 3,
|
||||
DirtyResource = 1 << 4,
|
||||
AllDirty = (DirtyTransform
|
||||
|DirtyParams
|
||||
|DirtyShadowParams
|
||||
|DirtyCollection
|
||||
|DirtyResource)
|
||||
};
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_LIGHT_H
|
||||
@@ -0,0 +1,72 @@
|
||||
//
|
||||
// Copyright 2021 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// This file is generated by a script. Do not edit directly. Edit the
|
||||
// schema.template.h file to make changes.
|
||||
|
||||
#ifndef PXR_IMAGING_HD_LIGHT_SCHEMA_H
|
||||
#define PXR_IMAGING_HD_LIGHT_SCHEMA_H
|
||||
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
|
||||
#include "pxr/imaging/hd/schema.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define HDLIGHT_SCHEMA_TOKENS \
|
||||
(light) \
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdLightSchemaTokens, HD_API,
|
||||
HDLIGHT_SCHEMA_TOKENS);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class HdLightSchema : public HdSchema
|
||||
{
|
||||
public:
|
||||
HdLightSchema(HdContainerDataSourceHandle container)
|
||||
: HdSchema(container) {}
|
||||
|
||||
|
||||
/// Retrieves a container data source with the schema's default name token
|
||||
/// "light" from the parent container and constructs a
|
||||
/// HdLightSchema 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 HdLightSchema GetFromParent(
|
||||
const HdContainerDataSourceHandle &fromParentContainer);
|
||||
|
||||
/// 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();
|
||||
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,216 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_MATERIAL_H
|
||||
#define PXR_IMAGING_HD_MATERIAL_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/sprim.h"
|
||||
#include "pxr/imaging/hd/sceneDelegate.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
///
|
||||
/// Hydra Schema for a material object.
|
||||
///
|
||||
class HdMaterial : public HdSprim {
|
||||
public:
|
||||
// change tracking for HdMaterial prim
|
||||
enum DirtyBits : HdDirtyBits {
|
||||
Clean = 0,
|
||||
// XXX: Got to skip varying and force sync bits for now
|
||||
DirtyParams = 1 << 2,
|
||||
DirtyResource = 1 << 3,
|
||||
AllDirty = (DirtyParams | DirtyResource)
|
||||
};
|
||||
|
||||
HD_API
|
||||
virtual ~HdMaterial();
|
||||
|
||||
protected:
|
||||
HD_API
|
||||
HdMaterial(SdfPath const& id);
|
||||
|
||||
private:
|
||||
// Class can not be default constructed or copied.
|
||||
HdMaterial() = delete;
|
||||
HdMaterial(const HdMaterial &) = delete;
|
||||
HdMaterial &operator =(const HdMaterial &) = delete;
|
||||
};
|
||||
|
||||
|
||||
/// \struct HdMaterialRelationship
|
||||
///
|
||||
/// Describes a connection between two nodes in a material.
|
||||
///
|
||||
/// A brief discussion of terminology follows:
|
||||
///
|
||||
/// * Shading nodes have inputs and outputs.
|
||||
/// * Shading nodes consume input values and produce output values.
|
||||
/// * Connections also have inputs and outputs.
|
||||
/// * Connections consume a value from the (\em inputId, \em inputName)
|
||||
/// and pass that value to the (\em outputId, \em outputName).
|
||||
///
|
||||
/// Note that a connection's input is considered an output on the
|
||||
/// upstream shading node, and the connection's output is an input
|
||||
/// on the downstream shading node.
|
||||
///
|
||||
/// A guideline to remember this terminology is that inputs
|
||||
/// are always upstream of outputs in the dataflow.
|
||||
///
|
||||
struct HdMaterialRelationship {
|
||||
SdfPath inputId;
|
||||
TfToken inputName;
|
||||
SdfPath outputId;
|
||||
TfToken outputName;
|
||||
};
|
||||
|
||||
// VtValue requirements
|
||||
HD_API
|
||||
bool operator==(const HdMaterialRelationship& lhs,
|
||||
const HdMaterialRelationship& rhs);
|
||||
|
||||
|
||||
/// \struct HdMaterialNode
|
||||
///
|
||||
/// Describes a material node which is made of a path, an identifier and
|
||||
/// a list of parameters.
|
||||
struct HdMaterialNode {
|
||||
SdfPath path;
|
||||
TfToken identifier;
|
||||
std::map<TfToken, VtValue> parameters;
|
||||
};
|
||||
|
||||
// VtValue requirements
|
||||
HD_API
|
||||
bool operator==(const HdMaterialNode& lhs, const HdMaterialNode& rhs);
|
||||
|
||||
|
||||
/// \struct HdMaterialNetwork
|
||||
///
|
||||
/// Describes a material network composed of nodes, primvars, and relationships
|
||||
/// between the nodes and terminals of those nodes.
|
||||
struct HdMaterialNetwork {
|
||||
std::vector<HdMaterialRelationship> relationships;
|
||||
std::vector<HdMaterialNode> nodes;
|
||||
TfTokenVector primvars;
|
||||
};
|
||||
|
||||
/// \struct HdMaterialNetworkMap
|
||||
///
|
||||
/// Describes a map from network type to network.
|
||||
struct HdMaterialNetworkMap {
|
||||
std::map<TfToken, HdMaterialNetwork> map;
|
||||
std::vector<SdfPath> terminals;
|
||||
};
|
||||
|
||||
|
||||
///
|
||||
/// HdMaterialNetwork2
|
||||
///
|
||||
/// This struct replaces the previously used MatfiltNetwork and
|
||||
/// HdSt_MaterialNetwork.
|
||||
/// In the furuture this HdMaterialNetwork2 will replace the current
|
||||
/// HdMaterialNetwork defined above.
|
||||
///
|
||||
|
||||
/// \struct HdMaterialConnection2
|
||||
///
|
||||
/// Describes a single connection to an upsream node and output port
|
||||
/// Replacement for HdRelationship.
|
||||
struct HdMaterialConnection2 {
|
||||
SdfPath upstreamNode;
|
||||
TfToken upstreamOutputName;
|
||||
|
||||
bool operator==(const HdMaterialConnection2 & rhs) const {
|
||||
return upstreamNode == rhs.upstreamNode
|
||||
&& upstreamOutputName == rhs.upstreamOutputName;
|
||||
}
|
||||
};
|
||||
|
||||
/// \struct HdMaterialNode2
|
||||
///
|
||||
/// Describes an instance of a node within a network
|
||||
/// A node contains a (shader) type identifier, parameter values, and
|
||||
/// connections to upstream nodes. A single input (mapped by TfToken) may have
|
||||
/// multiple upstream connections to describe connected array elements.
|
||||
struct HdMaterialNode2 {
|
||||
TfToken nodeTypeId;
|
||||
std::map<TfToken, VtValue> parameters;
|
||||
std::map<TfToken, std::vector<HdMaterialConnection2>> inputConnections;
|
||||
|
||||
bool operator==(const HdMaterialNode2 & rhs) const {
|
||||
return nodeTypeId == rhs.nodeTypeId
|
||||
&& parameters == rhs.parameters
|
||||
&& inputConnections == rhs.inputConnections;
|
||||
}
|
||||
};
|
||||
|
||||
/// \struct HdMaterialNetwork2
|
||||
///
|
||||
/// Container of nodes and top-level terminal connections. This is the mutable
|
||||
/// representation of a shading network sent to filtering functions by a
|
||||
/// MatfiltFilterChain.
|
||||
struct HdMaterialNetwork2 {
|
||||
std::map<SdfPath, HdMaterialNode2> nodes;
|
||||
std::map<TfToken, HdMaterialConnection2> terminals;
|
||||
TfTokenVector primvars;
|
||||
|
||||
bool operator==(const HdMaterialNetwork2 & rhs) const {
|
||||
return nodes == rhs.nodes
|
||||
&& terminals == rhs.terminals
|
||||
&& primvars == rhs.primvars;
|
||||
}
|
||||
};
|
||||
|
||||
/// Converts a HdMaterialNetworkMap to a HdMaterialNetwork2
|
||||
HD_API
|
||||
void HdMaterialNetwork2ConvertFromHdMaterialNetworkMap(
|
||||
const HdMaterialNetworkMap & hdNetworkMap,
|
||||
HdMaterialNetwork2 *result,
|
||||
bool *isVolume = nullptr);
|
||||
|
||||
|
||||
// VtValue requirements
|
||||
HD_API
|
||||
std::ostream& operator<<(std::ostream& out, const HdMaterialNetwork& pv);
|
||||
HD_API
|
||||
bool operator==(const HdMaterialNetwork& lhs, const HdMaterialNetwork& rhs);
|
||||
HD_API
|
||||
bool operator!=(const HdMaterialNetwork& lhs, const HdMaterialNetwork& rhs);
|
||||
|
||||
HD_API
|
||||
std::ostream& operator<<(std::ostream& out,
|
||||
const HdMaterialNetworkMap& pv);
|
||||
HD_API
|
||||
bool operator==(const HdMaterialNetworkMap& lhs,
|
||||
const HdMaterialNetworkMap& rhs);
|
||||
HD_API
|
||||
bool operator!=(const HdMaterialNetworkMap& lhs,
|
||||
const HdMaterialNetworkMap& rhs);
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_MATERIAL_H
|
||||
@@ -0,0 +1,83 @@
|
||||
//
|
||||
// Copyright 2021 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// This file is generated by a script. Do not edit directly. Edit the
|
||||
// schema.template.h file to make changes.
|
||||
|
||||
#ifndef PXR_IMAGING_HD_MATERIAL_BINDING_SCHEMA_H
|
||||
#define PXR_IMAGING_HD_MATERIAL_BINDING_SCHEMA_H
|
||||
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
|
||||
#include "pxr/imaging/hd/schema.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define HDMATERIALBINDING_SCHEMA_TOKENS \
|
||||
(materialBinding) \
|
||||
((allPurpose, "")) \
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdMaterialBindingSchemaTokens, HD_API,
|
||||
HDMATERIALBINDING_SCHEMA_TOKENS);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class HdMaterialBindingSchema : public HdSchema
|
||||
{
|
||||
public:
|
||||
HdMaterialBindingSchema(HdContainerDataSourceHandle container)
|
||||
: HdSchema(container) {}
|
||||
|
||||
HD_API
|
||||
static HdContainerDataSourceHandle
|
||||
BuildRetained(
|
||||
size_t count,
|
||||
TfToken *names,
|
||||
HdDataSourceBaseHandle *values);
|
||||
|
||||
HdPathDataSourceHandle GetMaterialBinding();
|
||||
HdPathDataSourceHandle GetMaterialBinding(TfToken const &purpose);
|
||||
|
||||
|
||||
/// Retrieves a container data source with the schema's default name token
|
||||
/// "materialBinding" from the parent container and constructs a
|
||||
/// HdMaterialBindingSchema 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 HdMaterialBindingSchema GetFromParent(
|
||||
const HdContainerDataSourceHandle &fromParentContainer);
|
||||
|
||||
/// 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();
|
||||
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,104 @@
|
||||
//
|
||||
// Copyright 2021 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// This file is generated by a script. Do not edit directly. Edit the
|
||||
// schema.template.h file to make changes.
|
||||
|
||||
#ifndef PXR_IMAGING_HD_MATERIAL_CONNECTION_SCHEMA_H
|
||||
#define PXR_IMAGING_HD_MATERIAL_CONNECTION_SCHEMA_H
|
||||
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
|
||||
#include "pxr/imaging/hd/schema.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define HDMATERIALCONNECTION_SCHEMA_TOKENS \
|
||||
(upstreamNodePath) \
|
||||
(upstreamNodeOutputName) \
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdMaterialConnectionSchemaTokens, HD_API,
|
||||
HDMATERIALCONNECTION_SCHEMA_TOKENS);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class HdMaterialConnectionSchema : public HdSchema
|
||||
{
|
||||
public:
|
||||
HdMaterialConnectionSchema(HdContainerDataSourceHandle container)
|
||||
: HdSchema(container) {}
|
||||
|
||||
//ACCESSORS
|
||||
|
||||
HD_API
|
||||
HdTokenDataSourceHandle GetUpstreamNodePath();
|
||||
HD_API
|
||||
HdTokenDataSourceHandle GetUpstreamNodeOutputName();
|
||||
|
||||
// RETRIEVING AND CONSTRUCTING
|
||||
|
||||
/// 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 HdTokenDataSourceHandle &upstreamNodePath,
|
||||
const HdTokenDataSourceHandle &upstreamNodeOutputName
|
||||
);
|
||||
|
||||
/// \class HdMaterialConnectionSchema::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 &SetUpstreamNodePath(
|
||||
const HdTokenDataSourceHandle &upstreamNodePath);
|
||||
HD_API
|
||||
Builder &SetUpstreamNodeOutputName(
|
||||
const HdTokenDataSourceHandle &upstreamNodeOutputName);
|
||||
|
||||
/// Returns a container data source containing the members set thus far.
|
||||
HD_API
|
||||
HdContainerDataSourceHandle Build();
|
||||
|
||||
private:
|
||||
HdTokenDataSourceHandle _upstreamNodePath;
|
||||
HdTokenDataSourceHandle _upstreamNodeOutputName;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,104 @@
|
||||
//
|
||||
// Copyright 2021 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// This file is generated by a script. Do not edit directly. Edit the
|
||||
// schema.template.h file to make changes.
|
||||
|
||||
#ifndef PXR_IMAGING_HD_MATERIAL_NETWORK_SCHEMA_H
|
||||
#define PXR_IMAGING_HD_MATERIAL_NETWORK_SCHEMA_H
|
||||
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
|
||||
#include "pxr/imaging/hd/schema.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define HDMATERIALNETWORK_SCHEMA_TOKENS \
|
||||
(nodes) \
|
||||
(terminals) \
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdMaterialNetworkSchemaTokens, HD_API,
|
||||
HDMATERIALNETWORK_SCHEMA_TOKENS);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class HdMaterialNetworkSchema : public HdSchema
|
||||
{
|
||||
public:
|
||||
HdMaterialNetworkSchema(HdContainerDataSourceHandle container)
|
||||
: HdSchema(container) {}
|
||||
|
||||
//ACCESSORS
|
||||
|
||||
HD_API
|
||||
HdContainerDataSourceHandle GetNodes();
|
||||
HD_API
|
||||
HdContainerDataSourceHandle GetTerminals();
|
||||
|
||||
// RETRIEVING AND CONSTRUCTING
|
||||
|
||||
/// 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 HdContainerDataSourceHandle &nodes,
|
||||
const HdContainerDataSourceHandle &terminals
|
||||
);
|
||||
|
||||
/// \class HdMaterialNetworkSchema::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 &SetNodes(
|
||||
const HdContainerDataSourceHandle &nodes);
|
||||
HD_API
|
||||
Builder &SetTerminals(
|
||||
const HdContainerDataSourceHandle &terminals);
|
||||
|
||||
/// Returns a container data source containing the members set thus far.
|
||||
HD_API
|
||||
HdContainerDataSourceHandle Build();
|
||||
|
||||
private:
|
||||
HdContainerDataSourceHandle _nodes;
|
||||
HdContainerDataSourceHandle _terminals;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,112 @@
|
||||
//
|
||||
// Copyright 2021 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// This file is generated by a script. Do not edit directly. Edit the
|
||||
// schema.template.h file to make changes.
|
||||
|
||||
#ifndef PXR_IMAGING_HD_MATERIAL_NODE_SCHEMA_H
|
||||
#define PXR_IMAGING_HD_MATERIAL_NODE_SCHEMA_H
|
||||
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
|
||||
#include "pxr/imaging/hd/schema.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define HDMATERIALNODE_SCHEMA_TOKENS \
|
||||
(parameters) \
|
||||
(inputConnections) \
|
||||
(nodeIdentifier) \
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdMaterialNodeSchemaTokens, HD_API,
|
||||
HDMATERIALNODE_SCHEMA_TOKENS);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class HdMaterialNodeSchema : public HdSchema
|
||||
{
|
||||
public:
|
||||
HdMaterialNodeSchema(HdContainerDataSourceHandle container)
|
||||
: HdSchema(container) {}
|
||||
|
||||
//ACCESSORS
|
||||
|
||||
HD_API
|
||||
HdContainerDataSourceHandle GetParameters();
|
||||
HD_API
|
||||
HdContainerDataSourceHandle GetInputConnections();
|
||||
HD_API
|
||||
HdTokenDataSourceHandle GetNodeIdentifier();
|
||||
|
||||
// RETRIEVING AND CONSTRUCTING
|
||||
|
||||
/// 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 HdContainerDataSourceHandle ¶meters,
|
||||
const HdContainerDataSourceHandle &inputConnections,
|
||||
const HdTokenDataSourceHandle &nodeIdentifier
|
||||
);
|
||||
|
||||
/// \class HdMaterialNodeSchema::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 &SetParameters(
|
||||
const HdContainerDataSourceHandle ¶meters);
|
||||
HD_API
|
||||
Builder &SetInputConnections(
|
||||
const HdContainerDataSourceHandle &inputConnections);
|
||||
HD_API
|
||||
Builder &SetNodeIdentifier(
|
||||
const HdTokenDataSourceHandle &nodeIdentifier);
|
||||
|
||||
/// Returns a container data source containing the members set thus far.
|
||||
HD_API
|
||||
HdContainerDataSourceHandle Build();
|
||||
|
||||
private:
|
||||
HdContainerDataSourceHandle _parameters;
|
||||
HdContainerDataSourceHandle _inputConnections;
|
||||
HdTokenDataSourceHandle _nodeIdentifier;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,83 @@
|
||||
//
|
||||
// Copyright 2021 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// This file is generated by a script. Do not edit directly. Edit the
|
||||
// schema.template.h file to make changes.
|
||||
|
||||
#ifndef PXR_IMAGING_HD_MATERIAL_SCHEMA_H
|
||||
#define PXR_IMAGING_HD_MATERIAL_SCHEMA_H
|
||||
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
|
||||
#include "pxr/imaging/hd/schema.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define HDMATERIAL_SCHEMA_TOKENS \
|
||||
(material) \
|
||||
((universalRenderContext, "")) \
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdMaterialSchemaTokens, HD_API,
|
||||
HDMATERIAL_SCHEMA_TOKENS);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class HdMaterialSchema : public HdSchema
|
||||
{
|
||||
public:
|
||||
HdMaterialSchema(HdContainerDataSourceHandle container)
|
||||
: HdSchema(container) {}
|
||||
|
||||
HD_API
|
||||
static HdContainerDataSourceHandle
|
||||
BuildRetained(
|
||||
size_t count,
|
||||
TfToken *names,
|
||||
HdDataSourceBaseHandle *values);
|
||||
|
||||
HdContainerDataSourceHandle GetMaterialNetwork();
|
||||
HdContainerDataSourceHandle GetMaterialNetwork(TfToken const &context);
|
||||
|
||||
|
||||
/// Retrieves a container data source with the schema's default name token
|
||||
/// "material" from the parent container and constructs a
|
||||
/// HdMaterialSchema 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 HdMaterialSchema GetFromParent(
|
||||
const HdContainerDataSourceHandle &fromParentContainer);
|
||||
|
||||
/// 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();
|
||||
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,224 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_MESH_H
|
||||
#define PXR_IMAGING_HD_MESH_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/enums.h"
|
||||
#include "pxr/imaging/hd/meshTopology.h"
|
||||
#include "pxr/imaging/hd/rprim.h"
|
||||
#include "pxr/imaging/hd/tokens.h"
|
||||
#include "pxr/imaging/pxOsd/subdivTags.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
#define HD_MESH_REPR_DESC_TOKENS \
|
||||
(surfaceShader) \
|
||||
(surfaceShaderUnlit) \
|
||||
(surfaceShaderSheer) \
|
||||
(surfaceShaderOutline) \
|
||||
(constantColor) \
|
||||
(hullColor) \
|
||||
(pointColor)
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdMeshReprDescTokens, HD_API,
|
||||
HD_MESH_REPR_DESC_TOKENS);
|
||||
|
||||
/// \class HdMeshReprDesc
|
||||
///
|
||||
/// Descriptor to configure the drawItem(s) for a repr
|
||||
///
|
||||
struct HdMeshReprDesc {
|
||||
HdMeshReprDesc(HdMeshGeomStyle geomStyle = HdMeshGeomStyleInvalid,
|
||||
HdCullStyle cullStyle = HdCullStyleDontCare,
|
||||
TfToken shadingTerminal = HdMeshReprDescTokens->surfaceShader,
|
||||
bool flatShadingEnabled = true,
|
||||
bool blendWireframeColor = true,
|
||||
bool doubleSided = false,
|
||||
float lineWidth = 0,
|
||||
bool useCustomDisplacement = true,
|
||||
bool enableScalarOverride = true)
|
||||
: geomStyle(geomStyle)
|
||||
, cullStyle(cullStyle)
|
||||
, shadingTerminal(shadingTerminal)
|
||||
, flatShadingEnabled(flatShadingEnabled)
|
||||
, blendWireframeColor(blendWireframeColor)
|
||||
, doubleSided(doubleSided)
|
||||
, lineWidth(lineWidth)
|
||||
, useCustomDisplacement(useCustomDisplacement)
|
||||
, enableScalarOverride(enableScalarOverride)
|
||||
{}
|
||||
|
||||
bool IsEmpty() const {
|
||||
return geomStyle == HdMeshGeomStyleInvalid;
|
||||
}
|
||||
|
||||
/// The rendering style: draw refined/unrefined, edge, points, etc.
|
||||
HdMeshGeomStyle geomStyle;
|
||||
/// The culling style: draw front faces, back faces, etc.
|
||||
HdCullStyle cullStyle;
|
||||
/// Specifies how the fragment color should be computed from surfaceShader;
|
||||
/// this can be used to render a mesh lit, unlit, unshaded, etc.
|
||||
TfToken shadingTerminal;
|
||||
/// Does this mesh want flat shading?
|
||||
bool flatShadingEnabled;
|
||||
/// Should the wireframe color be blended into the color primvar?
|
||||
bool blendWireframeColor;
|
||||
/// Should this mesh be treated as double-sided? The resolved value is
|
||||
/// (prim.doubleSided || repr.doubleSided).
|
||||
bool doubleSided;
|
||||
/// How big (in pixels) should line drawing be?
|
||||
float lineWidth;
|
||||
/// Should this mesh use displacementShader() to displace points?
|
||||
bool useCustomDisplacement;
|
||||
/// Should scalar override be allowed on this drawItem.
|
||||
/// scalar override allows for visualization of a single float value
|
||||
/// across a prim.
|
||||
bool enableScalarOverride;
|
||||
};
|
||||
|
||||
/// Hydra Schema for a subdivision surface or poly-mesh object.
|
||||
///
|
||||
class HdMesh : public HdRprim {
|
||||
public:
|
||||
HD_API
|
||||
virtual ~HdMesh();
|
||||
|
||||
///
|
||||
/// Render State
|
||||
///
|
||||
inline bool IsDoubleSided(HdSceneDelegate* delegate) const;
|
||||
inline HdCullStyle GetCullStyle(HdSceneDelegate* delegate) const;
|
||||
inline VtValue GetShadingStyle(HdSceneDelegate* delegate) const;
|
||||
|
||||
///
|
||||
/// Topological accessors via the scene delegate
|
||||
///
|
||||
inline HdMeshTopology GetMeshTopology(HdSceneDelegate* delegate) const;
|
||||
inline HdDisplayStyle GetDisplayStyle(HdSceneDelegate* delegate) const;
|
||||
inline PxOsdSubdivTags GetSubdivTags(HdSceneDelegate* delegate) const;
|
||||
|
||||
/// Topology getter
|
||||
virtual HdMeshTopologySharedPtr GetTopology() const;
|
||||
|
||||
///
|
||||
/// Primvars Accessors
|
||||
///
|
||||
inline VtValue GetPoints(HdSceneDelegate* delegate) const;
|
||||
inline VtValue GetNormals(HdSceneDelegate* delegate) const;
|
||||
|
||||
HD_API
|
||||
TfTokenVector const & GetBuiltinPrimvarNames() const override;
|
||||
|
||||
/// Configure the geometric style of the mesh for a given representation.
|
||||
/// We currently allow up to 2 descriptors for a representation.
|
||||
/// Example of when this may be useful:
|
||||
/// Drawing the outline in addition to the surface for a mesh.
|
||||
HD_API
|
||||
static void ConfigureRepr(TfToken const &reprName,
|
||||
HdMeshReprDesc desc1,
|
||||
HdMeshReprDesc desc2=HdMeshReprDesc());
|
||||
|
||||
protected:
|
||||
/// Constructor. instancerId, if specified, is the instancer which uses
|
||||
/// this mesh as a prototype.
|
||||
HD_API
|
||||
HdMesh(SdfPath const& id);
|
||||
|
||||
// We allow up to 2 repr descs per repr for meshes (see ConfigureRepr above)
|
||||
typedef _ReprDescConfigs<HdMeshReprDesc, 2> _MeshReprConfig;
|
||||
|
||||
HD_API
|
||||
static _MeshReprConfig::DescArray _GetReprDesc(TfToken const &reprName);
|
||||
|
||||
private:
|
||||
|
||||
// Class can not be default constructed or copied.
|
||||
HdMesh() = delete;
|
||||
HdMesh(const HdMesh &) = delete;
|
||||
HdMesh &operator =(const HdMesh &) = delete;
|
||||
|
||||
static _MeshReprConfig _reprDescConfig;
|
||||
};
|
||||
|
||||
inline bool
|
||||
HdMesh::IsDoubleSided(HdSceneDelegate* delegate) const
|
||||
{
|
||||
return delegate->GetDoubleSided(GetId());
|
||||
}
|
||||
|
||||
inline HdCullStyle
|
||||
HdMesh::GetCullStyle(HdSceneDelegate* delegate) const
|
||||
{
|
||||
return delegate->GetCullStyle(GetId());
|
||||
}
|
||||
|
||||
inline VtValue
|
||||
HdMesh::GetShadingStyle(HdSceneDelegate* delegate) const
|
||||
{
|
||||
return delegate->GetShadingStyle(GetId());
|
||||
}
|
||||
|
||||
inline HdMeshTopology
|
||||
HdMesh::GetMeshTopology(HdSceneDelegate* delegate) const
|
||||
{
|
||||
return delegate->GetMeshTopology(GetId());
|
||||
}
|
||||
|
||||
inline HdDisplayStyle
|
||||
HdMesh::GetDisplayStyle(HdSceneDelegate* delegate) const
|
||||
{
|
||||
return delegate->GetDisplayStyle(GetId());
|
||||
}
|
||||
|
||||
inline PxOsdSubdivTags
|
||||
HdMesh::GetSubdivTags(HdSceneDelegate* delegate) const
|
||||
{
|
||||
return delegate->GetSubdivTags(GetId());
|
||||
}
|
||||
|
||||
inline HdMeshTopologySharedPtr
|
||||
HdMesh::GetTopology() const
|
||||
{
|
||||
return HdMeshTopologySharedPtr();
|
||||
}
|
||||
|
||||
inline VtValue
|
||||
HdMesh::GetPoints(HdSceneDelegate* delegate) const
|
||||
{
|
||||
return GetPrimvar(delegate, HdTokens->points);
|
||||
}
|
||||
|
||||
inline VtValue
|
||||
HdMesh::GetNormals(HdSceneDelegate* delegate) const
|
||||
{
|
||||
return GetPrimvar(delegate, HdTokens->normals);
|
||||
}
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif //PXR_IMAGING_HD_MESH_H
|
||||
@@ -0,0 +1,182 @@
|
||||
//
|
||||
// Copyright 2021 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// This file is generated by a script. Do not edit directly. Edit the
|
||||
// schema.template.h file to make changes.
|
||||
|
||||
#ifndef PXR_IMAGING_HD_MESH_SCHEMA_H
|
||||
#define PXR_IMAGING_HD_MESH_SCHEMA_H
|
||||
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
|
||||
#include "pxr/imaging/hd/meshTopologySchema.h"
|
||||
#include "pxr/imaging/hd/subdivisionTagsSchema.h"
|
||||
#include "pxr/imaging/hd/geomSubsetsSchema.h"
|
||||
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define HDMESH_SCHEMA_TOKENS \
|
||||
(mesh) \
|
||||
(topology) \
|
||||
(subdivisionScheme) \
|
||||
(subdivisionTags) \
|
||||
(geomSubsets) \
|
||||
(doubleSided) \
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdMeshSchemaTokens, HD_API,
|
||||
HDMESH_SCHEMA_TOKENS);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class HdMeshSchema : public HdSchema
|
||||
{
|
||||
public:
|
||||
HdMeshSchema(HdContainerDataSourceHandle container)
|
||||
: HdSchema(container) {}
|
||||
|
||||
//ACCESSORS
|
||||
|
||||
HD_API
|
||||
HdMeshTopologySchema GetTopology();
|
||||
HD_API
|
||||
HdTokenDataSourceHandle GetSubdivisionScheme();
|
||||
HD_API
|
||||
HdSubdivisionTagsSchema GetSubdivisionTags();
|
||||
HD_API
|
||||
HdGeomSubsetsSchema GetGeomSubsets();
|
||||
HD_API
|
||||
HdBoolDataSourceHandle GetDoubleSided();
|
||||
|
||||
// RETRIEVING AND CONSTRUCTING
|
||||
|
||||
/// 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 HdContainerDataSourceHandle &topology,
|
||||
const HdTokenDataSourceHandle &subdivisionScheme,
|
||||
const HdContainerDataSourceHandle &subdivisionTags,
|
||||
const HdContainerDataSourceHandle &geomSubsets,
|
||||
const HdBoolDataSourceHandle &doubleSided
|
||||
);
|
||||
|
||||
/// \class HdMeshSchema::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 &SetTopology(
|
||||
const HdContainerDataSourceHandle &topology);
|
||||
HD_API
|
||||
Builder &SetSubdivisionScheme(
|
||||
const HdTokenDataSourceHandle &subdivisionScheme);
|
||||
HD_API
|
||||
Builder &SetSubdivisionTags(
|
||||
const HdContainerDataSourceHandle &subdivisionTags);
|
||||
HD_API
|
||||
Builder &SetGeomSubsets(
|
||||
const HdContainerDataSourceHandle &geomSubsets);
|
||||
HD_API
|
||||
Builder &SetDoubleSided(
|
||||
const HdBoolDataSourceHandle &doubleSided);
|
||||
|
||||
/// Returns a container data source containing the members set thus far.
|
||||
HD_API
|
||||
HdContainerDataSourceHandle Build();
|
||||
|
||||
private:
|
||||
HdContainerDataSourceHandle _topology;
|
||||
HdTokenDataSourceHandle _subdivisionScheme;
|
||||
HdContainerDataSourceHandle _subdivisionTags;
|
||||
HdContainerDataSourceHandle _geomSubsets;
|
||||
HdBoolDataSourceHandle _doubleSided;
|
||||
};
|
||||
|
||||
/// Retrieves a container data source with the schema's default name token
|
||||
/// "mesh" from the parent container and constructs a
|
||||
/// HdMeshSchema 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 HdMeshSchema GetFromParent(
|
||||
const HdContainerDataSourceHandle &fromParentContainer);
|
||||
|
||||
/// 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();
|
||||
|
||||
|
||||
/// Returns an HdDataSourceLocator (relative to the prim-level data source)
|
||||
/// where the topology data source can be found.
|
||||
/// This is often useful for checking intersection against the
|
||||
/// HdDataSourceLocatorSet sent with HdDataSourceObserver::PrimsDirtied.
|
||||
HD_API
|
||||
static const HdDataSourceLocator &GetTopologyLocator();
|
||||
|
||||
/// Returns an HdDataSourceLocator (relative to the prim-level data source)
|
||||
/// where the geomsubsets data source can be found.
|
||||
/// This is often useful for checking intersection against the
|
||||
/// HdDataSourceLocatorSet sent with HdDataSourceObserver::PrimsDirtied.
|
||||
HD_API
|
||||
static const HdDataSourceLocator &GetGeomSubsetsLocator();
|
||||
|
||||
/// Returns an HdDataSourceLocator (relative to the prim-level data source)
|
||||
/// where the doublesided data source can be found.
|
||||
/// This is often useful for checking intersection against the
|
||||
/// HdDataSourceLocatorSet sent with HdDataSourceObserver::PrimsDirtied.
|
||||
HD_API
|
||||
static const HdDataSourceLocator &GetDoubleSidedLocator();
|
||||
|
||||
/// Returns an HdDataSourceLocator (relative to the prim-level data source)
|
||||
/// where the subdivisiontags data source can be found.
|
||||
/// This is often useful for checking intersection against the
|
||||
/// HdDataSourceLocatorSet sent with HdDataSourceObserver::PrimsDirtied.
|
||||
HD_API
|
||||
static const HdDataSourceLocator &GetSubdivisionTagsLocator();
|
||||
|
||||
/// Returns an HdDataSourceLocator (relative to the prim-level data source)
|
||||
/// where the subdivisionscheme data source can be found.
|
||||
/// This is often useful for checking intersection against the
|
||||
/// HdDataSourceLocatorSet sent with HdDataSourceObserver::PrimsDirtied.
|
||||
HD_API
|
||||
static const HdDataSourceLocator &GetSubdivisionSchemeLocator();
|
||||
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,227 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_MESH_TOPOLOGY_H
|
||||
#define PXR_IMAGING_HD_MESH_TOPOLOGY_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/geomSubset.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/topology.h"
|
||||
|
||||
#include "pxr/imaging/pxOsd/meshTopology.h"
|
||||
|
||||
#include "pxr/base/vt/array.h"
|
||||
#include "pxr/base/vt/value.h"
|
||||
|
||||
#include "pxr/base/tf/token.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
using HdMeshTopologySharedPtr = std::shared_ptr<class HdMeshTopology>;
|
||||
|
||||
/// \class HdMeshTopology
|
||||
///
|
||||
/// Topology data for meshes.
|
||||
///
|
||||
/// HdMeshTopology holds the raw input topology data for a mesh and is capable
|
||||
/// of computing derivative topological data (such as indices or subdivision
|
||||
/// stencil tables and patch tables).
|
||||
///
|
||||
class HdMeshTopology : public HdTopology {
|
||||
public:
|
||||
HD_API
|
||||
HdMeshTopology();
|
||||
HD_API
|
||||
HdMeshTopology(const HdMeshTopology &, int refineLevel=0);
|
||||
HD_API
|
||||
HdMeshTopology(const PxOsdMeshTopology &, int refineLevel=0);
|
||||
HD_API
|
||||
HdMeshTopology(const TfToken &scheme,
|
||||
const TfToken &orientation,
|
||||
const VtIntArray &faceVertexCounts,
|
||||
const VtIntArray &faceVertexIndices,
|
||||
int refineLevel = 0);
|
||||
HD_API
|
||||
HdMeshTopology(const TfToken &scheme,
|
||||
const TfToken &orientation,
|
||||
const VtIntArray &faceVertexCounts,
|
||||
const VtIntArray &faceVertexIndices,
|
||||
const VtIntArray &holeIndices,
|
||||
int refineLevel = 0);
|
||||
HD_API
|
||||
virtual ~HdMeshTopology();
|
||||
|
||||
HD_API
|
||||
HdMeshTopology &operator =(const HdMeshTopology ©);
|
||||
|
||||
/// Returns whether adaptive subdivision is enabled or not.
|
||||
HD_API
|
||||
static bool IsEnabledAdaptive();
|
||||
|
||||
PxOsdMeshTopology const & GetPxOsdMeshTopology() const {
|
||||
return _topology;
|
||||
}
|
||||
|
||||
/// Returns the num faces
|
||||
HD_API
|
||||
int GetNumFaces() const;
|
||||
|
||||
/// Returns the num facevarying primvars
|
||||
HD_API
|
||||
int GetNumFaceVaryings() const;
|
||||
|
||||
/// Returns the num points of the topology vert indices array
|
||||
HD_API
|
||||
int GetNumPoints() const;
|
||||
|
||||
/// Returns the num points by looking vert indices array
|
||||
HD_API
|
||||
static int ComputeNumPoints(VtIntArray const &verts);
|
||||
|
||||
/// Returns the subdivision scheme
|
||||
TfToken const GetScheme() const {
|
||||
return _topology.GetScheme();
|
||||
}
|
||||
|
||||
/// Returns the refinement level
|
||||
int GetRefineLevel() const {
|
||||
return _refineLevel;
|
||||
}
|
||||
|
||||
/// Returns face vertex counts.
|
||||
VtIntArray const &GetFaceVertexCounts() const {
|
||||
return _topology.GetFaceVertexCounts();
|
||||
}
|
||||
|
||||
/// Returns face vertex indics.
|
||||
VtIntArray const &GetFaceVertexIndices() const {
|
||||
return _topology.GetFaceVertexIndices();
|
||||
}
|
||||
|
||||
/// Returns orientation.
|
||||
TfToken const &GetOrientation() const {
|
||||
return _topology.GetOrientation();
|
||||
}
|
||||
|
||||
/// Returns the hash value of this topology to be used for instancing.
|
||||
HD_API
|
||||
virtual ID ComputeHash() const;
|
||||
|
||||
/// Equality check between two mesh topologies.
|
||||
HD_API
|
||||
bool operator==(HdMeshTopology const &other) const;
|
||||
|
||||
///
|
||||
/// \name Hole
|
||||
/// @{
|
||||
|
||||
/// Sets hole face indices. faceIndices needs to be sorted in
|
||||
/// ascending order.
|
||||
void SetHoleIndices(VtIntArray const &holeIndices) {
|
||||
_topology = _topology.WithHoleIndices(holeIndices);
|
||||
}
|
||||
|
||||
/// Returns the hole face indices.
|
||||
VtIntArray const &GetHoleIndices() const {
|
||||
return _topology.GetHoleIndices();
|
||||
}
|
||||
|
||||
/// @}
|
||||
|
||||
///
|
||||
/// \name Subdivision
|
||||
/// @{
|
||||
|
||||
/// Sets subdivision tags.
|
||||
void SetSubdivTags(PxOsdSubdivTags const &subdivTags) {
|
||||
_topology = _topology.WithSubdivTags(subdivTags);
|
||||
}
|
||||
|
||||
/// Returns subdivision tags
|
||||
PxOsdSubdivTags const&GetSubdivTags() const {
|
||||
return _topology.GetSubdivTags();
|
||||
}
|
||||
|
||||
/// @}
|
||||
|
||||
///
|
||||
/// \name Geometry subsets
|
||||
/// @{
|
||||
|
||||
/// Sets geometry subsets
|
||||
HD_API
|
||||
void SetGeomSubsets(HdGeomSubsets const &geomSubsets) {
|
||||
_geomSubsets = geomSubsets;
|
||||
}
|
||||
|
||||
/// Returns geometry subsets
|
||||
HD_API
|
||||
HdGeomSubsets const &GetGeomSubsets() const {
|
||||
return _geomSubsets;
|
||||
}
|
||||
|
||||
/// @}
|
||||
|
||||
///
|
||||
/// \name Topological invisibility
|
||||
/// @{
|
||||
///
|
||||
HD_API
|
||||
void SetInvisiblePoints(VtIntArray const &invisiblePoints) {
|
||||
_invisiblePoints = invisiblePoints;
|
||||
}
|
||||
|
||||
HD_API
|
||||
VtIntArray const & GetInvisiblePoints() const {
|
||||
return _invisiblePoints;
|
||||
}
|
||||
|
||||
HD_API
|
||||
void SetInvisibleFaces(VtIntArray const &invisibleFaces) {
|
||||
_invisibleFaces = invisibleFaces;
|
||||
}
|
||||
|
||||
HD_API
|
||||
VtIntArray const & GetInvisibleFaces() const {
|
||||
return _invisibleFaces;
|
||||
}
|
||||
/// @}
|
||||
|
||||
protected:
|
||||
PxOsdMeshTopology _topology;
|
||||
HdGeomSubsets _geomSubsets;
|
||||
VtIntArray _invisiblePoints;
|
||||
VtIntArray _invisibleFaces;
|
||||
int _refineLevel;
|
||||
int _numPoints;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_MESH_TOPOLOGY_H
|
||||
@@ -0,0 +1,147 @@
|
||||
//
|
||||
// Copyright 2021 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// This file is generated by a script. Do not edit directly. Edit the
|
||||
// schema.template.h file to make changes.
|
||||
|
||||
#ifndef PXR_IMAGING_HD_MESH_TOPOLOGY_SCHEMA_H
|
||||
#define PXR_IMAGING_HD_MESH_TOPOLOGY_SCHEMA_H
|
||||
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
|
||||
#include "pxr/imaging/hd/subdivisionTagsSchema.h"
|
||||
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define HDMESHTOPOLOGY_SCHEMA_TOKENS \
|
||||
(topology) \
|
||||
(faceVertexCounts) \
|
||||
(faceVertexIndices) \
|
||||
(holeIndices) \
|
||||
(orientation) \
|
||||
(leftHanded) \
|
||||
(rightHanded) \
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdMeshTopologySchemaTokens, HD_API,
|
||||
HDMESHTOPOLOGY_SCHEMA_TOKENS);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class HdMeshTopologySchema : public HdSchema
|
||||
{
|
||||
public:
|
||||
HdMeshTopologySchema(HdContainerDataSourceHandle container)
|
||||
: HdSchema(container) {}
|
||||
|
||||
//ACCESSORS
|
||||
|
||||
HD_API
|
||||
HdIntArrayDataSourceHandle GetFaceVertexCounts();
|
||||
HD_API
|
||||
HdIntArrayDataSourceHandle GetFaceVertexIndices();
|
||||
HD_API
|
||||
HdIntArrayDataSourceHandle GetHoleIndices();
|
||||
HD_API
|
||||
HdTokenDataSourceHandle GetOrientation();
|
||||
|
||||
// RETRIEVING AND CONSTRUCTING
|
||||
|
||||
/// 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 HdIntArrayDataSourceHandle &faceVertexCounts,
|
||||
const HdIntArrayDataSourceHandle &faceVertexIndices,
|
||||
const HdIntArrayDataSourceHandle &holeIndices,
|
||||
const HdTokenDataSourceHandle &orientation
|
||||
);
|
||||
|
||||
/// \class HdMeshTopologySchema::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 &SetFaceVertexCounts(
|
||||
const HdIntArrayDataSourceHandle &faceVertexCounts);
|
||||
HD_API
|
||||
Builder &SetFaceVertexIndices(
|
||||
const HdIntArrayDataSourceHandle &faceVertexIndices);
|
||||
HD_API
|
||||
Builder &SetHoleIndices(
|
||||
const HdIntArrayDataSourceHandle &holeIndices);
|
||||
HD_API
|
||||
Builder &SetOrientation(
|
||||
const HdTokenDataSourceHandle &orientation);
|
||||
|
||||
/// Returns a container data source containing the members set thus far.
|
||||
HD_API
|
||||
HdContainerDataSourceHandle Build();
|
||||
|
||||
private:
|
||||
HdIntArrayDataSourceHandle _faceVertexCounts;
|
||||
HdIntArrayDataSourceHandle _faceVertexIndices;
|
||||
HdIntArrayDataSourceHandle _holeIndices;
|
||||
HdTokenDataSourceHandle _orientation;
|
||||
};
|
||||
|
||||
/// Retrieves a container data source with the schema's default name token
|
||||
/// "topology" from the parent container and constructs a
|
||||
/// HdMeshTopologySchema 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 HdMeshTopologySchema GetFromParent(
|
||||
const HdContainerDataSourceHandle &fromParentContainer);
|
||||
|
||||
/// 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();
|
||||
|
||||
/// Returns token data source for use as orientation value.
|
||||
/// Values of...
|
||||
/// - HdMeshTopologySchemaTokens->leftHanded
|
||||
/// - HdMeshTopologySchemaTokens->rightHanded
|
||||
/// ...will be stored statically and reused for future calls.
|
||||
HD_API
|
||||
static HdTokenDataSourceHandle BuildOrientationDataSource(
|
||||
const TfToken &orientation);
|
||||
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,318 @@
|
||||
//
|
||||
// Copyright 2017 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_MESH_UTIL_H
|
||||
#define PXR_IMAGING_HD_MESH_UTIL_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/types.h"
|
||||
#include "pxr/imaging/hd/meshTopology.h"
|
||||
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
|
||||
#include "pxr/base/gf/vec2i.h"
|
||||
#include "pxr/base/gf/vec3i.h"
|
||||
#include "pxr/base/gf/vec4i.h"
|
||||
|
||||
#include "pxr/base/vt/array.h"
|
||||
#include "pxr/base/vt/value.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// \class HdQuadInfo
|
||||
/// A helper class for quadrangulation computation.
|
||||
|
||||
// v0 v2
|
||||
// +-----e2----+
|
||||
// \ | /
|
||||
// \ __c__ /
|
||||
// e0 e1
|
||||
// \ /
|
||||
// \ /
|
||||
// + v1
|
||||
//
|
||||
//
|
||||
// original points additional center and edge points
|
||||
// +------------ ... ----+--------------------------------+
|
||||
// | v0 v1 v2 vn | e0 e1 e2 c0, e3 e4 e5 c1 ... |
|
||||
// +------------ ... ----+--------------------------------+
|
||||
// ^
|
||||
// pointsOffset
|
||||
// <----- numAdditionalPoints ---->
|
||||
|
||||
struct HdQuadInfo {
|
||||
HdQuadInfo() : pointsOffset(0), numAdditionalPoints(0), maxNumVert(0) { }
|
||||
|
||||
/// Returns true if the mesh is all-quads.
|
||||
bool IsAllQuads() const { return numAdditionalPoints == 0; }
|
||||
|
||||
int pointsOffset;
|
||||
int numAdditionalPoints;
|
||||
int maxNumVert;
|
||||
std::vector<int> numVerts; // num vertices of non-quads
|
||||
std::vector<int> verts; // vertex indices of non-quads
|
||||
};
|
||||
|
||||
/// \class HdMeshUtil
|
||||
/// A collection of utility algorithms for generating triangulation
|
||||
/// and quadrangulation of an input topology.
|
||||
|
||||
class HdMeshUtil
|
||||
{
|
||||
public:
|
||||
HdMeshUtil(HdMeshTopology const* topology, SdfPath const& id)
|
||||
: _topology(topology), _id(id) {}
|
||||
virtual ~HdMeshUtil() {}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// Triangulation
|
||||
|
||||
// In order to access per-face signals (face color, face selection etc)
|
||||
// we need a mapping from primitiveID to authored face index domain.
|
||||
// This is stored in primitiveParams, and computed along with indices.
|
||||
/*
|
||||
+--------+-------+
|
||||
/| \ |\ |\
|
||||
/ | \ 1 | \ 2 | \
|
||||
/ | \ | \ | \
|
||||
/ | \ | \ | 2 +
|
||||
/ 0 | 1 \ | 2 \ | /
|
||||
/ | \ | \ | /
|
||||
/ | \| \|/
|
||||
+-------+--------+-------+
|
||||
*/
|
||||
|
||||
/// Return a triangulation of the input topology. indices and
|
||||
/// primitiveParams are output parameters.
|
||||
HD_API
|
||||
void ComputeTriangleIndices(VtVec3iArray *indices,
|
||||
VtIntArray *primitiveParams,
|
||||
VtIntArray *edgeIndices = nullptr) const;
|
||||
|
||||
/// Return a triangulation of a face-varying primvar. source is
|
||||
/// a buffer of size numElements and type corresponding to dataType
|
||||
/// (e.g. HdTypeFloatVec3); the result is a VtArray<T> of the
|
||||
/// correct type written to the variable "triangulated".
|
||||
/// This function returns false if it can't resolve dataType.
|
||||
HD_API
|
||||
bool ComputeTriangulatedFaceVaryingPrimvar(void const* source,
|
||||
int numElements,
|
||||
HdType dataType,
|
||||
VtValue *triangulated) const;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// Quadrangulation
|
||||
|
||||
// In order to access per-face signals (face color, face selection etc)
|
||||
// we need a mapping from primitiveID to authored face index domain.
|
||||
// This is stored in primitiveParams, and computed along with indices.
|
||||
/*
|
||||
+--------+-------+
|
||||
/| | | \
|
||||
/ | | 2 | 2 /\
|
||||
/ | | \ / \
|
||||
/ 0 | 1 |------+ 2 +
|
||||
/\ /| | / \ /
|
||||
/ \/ | | 2 | 2 \/
|
||||
/ 0 | 0| | | /
|
||||
+-------+--------+-------+
|
||||
*/
|
||||
|
||||
/// Generate a quadInfo struct for the input topology.
|
||||
HD_API
|
||||
void ComputeQuadInfo(HdQuadInfo* quadInfo) const;
|
||||
|
||||
/// Return quadrangulated indices of the input topology. indices and
|
||||
/// primitiveParams are output parameters.
|
||||
HD_API
|
||||
void ComputeQuadIndices(VtVec4iArray *indices,
|
||||
VtIntArray *primitiveParams,
|
||||
VtVec2iArray *edgeIndices = nullptr) const;
|
||||
|
||||
/// Return a quadrangulation of a per-vertex primvar. source is
|
||||
/// a buffer of size numElements and type corresponding to dataType
|
||||
/// (e.g. HdTypeFloatVec3); the result is a VtArray<T> of the
|
||||
/// correct type written to the variable "quadrangulated".
|
||||
/// This function returns false if it can't resolve dataType.
|
||||
HD_API
|
||||
bool ComputeQuadrangulatedPrimvar(HdQuadInfo const* qi,
|
||||
void const* source,
|
||||
int numElements,
|
||||
HdType dataType,
|
||||
VtValue *quadrangulated) const;
|
||||
|
||||
/// Return a quadrangulation of a face-varying primvar.
|
||||
/// source is a buffer of size numElements and type corresponding
|
||||
/// to dataType (e.g. HdTypeFloatVec3); the result is a VtArray<T> of the
|
||||
/// correct type written to the variable "quadrangulated".
|
||||
/// This function returns false if it can't resolve dataType.
|
||||
HD_API
|
||||
bool ComputeQuadrangulatedFaceVaryingPrimvar(void const* source,
|
||||
int numElements,
|
||||
HdType dataType,
|
||||
VtValue *quadrangulated) const;
|
||||
|
||||
/// Return a buffer filled with face vertex index pairs corresponding
|
||||
/// to the sequence in which edges are visited when iterating through
|
||||
/// the mesh topology. The edges of degenerate and hole faces are
|
||||
/// included so that this sequence will correspond with either base
|
||||
/// face triangulation or quadrangulation (which typically skips
|
||||
/// over hole faces) as well as for refined surfaces which take into
|
||||
/// account faces tagged as holes as well as other non-manifold faces.
|
||||
HD_API
|
||||
void EnumerateEdges(std::vector<GfVec2i> * edgeVerticesOut) const;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// Primitive param bit encoding
|
||||
|
||||
// Per-primitive coarse-face-param encoding/decoding functions
|
||||
static int EncodeCoarseFaceParam(int faceIndex, int edgeFlag) {
|
||||
return ((faceIndex << 2) | (edgeFlag & 3));
|
||||
}
|
||||
static int DecodeFaceIndexFromCoarseFaceParam(int coarseFaceParam) {
|
||||
return (coarseFaceParam >> 2);
|
||||
}
|
||||
static int DecodeEdgeFlagFromCoarseFaceParam(int coarseFaceParam) {
|
||||
return (coarseFaceParam & 3);
|
||||
}
|
||||
|
||||
private:
|
||||
/// Return the number of quadrangulated quads.
|
||||
/// If degenerate face is found, sets invalidFaceFound as true.
|
||||
int _ComputeNumQuads(VtIntArray const &numVerts,
|
||||
VtIntArray const &holeIndices,
|
||||
bool *invalidFaceFound = nullptr) const;
|
||||
|
||||
HdMeshTopology const* _topology;
|
||||
SdfPath const _id;
|
||||
};
|
||||
|
||||
/// \class Edge Indices
|
||||
///
|
||||
/// Mesh edges are described as a pair of adjacent vertices encoded
|
||||
/// as GfVec2i.
|
||||
///
|
||||
/// The encoding of mesh edge indices is derived from the enumeration
|
||||
/// of face vertex index pairs provided by HdMeshUtil::EnumerateEdges().
|
||||
///
|
||||
/// This encoding is consistent across triangulation or quadrangulation
|
||||
/// of the base mesh faces as well as for non-manifold faces on refined
|
||||
/// subdivision surface meshes.
|
||||
///
|
||||
/// There can be multiple edge indices associated with each pair of
|
||||
/// topological vertices in the mesh, e.g. one for each face incident
|
||||
/// on the edge.
|
||||
///
|
||||
/// For example, here is a typical edge index assignment for a mesh
|
||||
/// with 2 quad faces and 6 vertices:
|
||||
///
|
||||
/// faceVertexCounts: [4, 4]
|
||||
/// faceVertexIndices: [0, 1, 4, 3, 1, 2, 5, 4]
|
||||
///
|
||||
/// edgeId:(edgeVertex[0], edgeVertex[1])
|
||||
///
|
||||
/// 2:(3,4) 6:(4,5)
|
||||
/// 3----------------4----------------5
|
||||
/// | | |
|
||||
/// | Face 0 | Face 1 |
|
||||
/// | | |
|
||||
/// |3:(0,3) 1:(1,4)|7:(1,4) 5:(2,5)|
|
||||
/// | | |
|
||||
/// | | |
|
||||
/// | | |
|
||||
/// 0----------------1----------------2
|
||||
/// 0:(0,1) 4:(1,2)
|
||||
///
|
||||
/// Notice that with this assignment, there are eight edge indices even
|
||||
/// though the mesh has seven topological edges. The mesh edge between
|
||||
/// vertex 1 and vertex 4 is associated with two edgeIds (1 and 7),
|
||||
/// one for each incident face.
|
||||
///
|
||||
/// This kind of edge index assignment can be implemented efficiently
|
||||
/// on the GPU since it falls out automatically from the primitive
|
||||
/// drawing order and requires minimal additional GPU data.
|
||||
///
|
||||
///
|
||||
class HdMeshEdgeIndexTable
|
||||
{
|
||||
public:
|
||||
explicit HdMeshEdgeIndexTable(HdMeshTopology const * topology);
|
||||
~HdMeshEdgeIndexTable();
|
||||
|
||||
bool GetVerticesForEdgeIndex(int edgeId, GfVec2i * edgeVerticesOut) const;
|
||||
|
||||
bool GetVerticesForEdgeIndices(
|
||||
std::vector<int> const & edgeIndices,
|
||||
std::vector<GfVec2i> * edgeVerticesOut) const;
|
||||
|
||||
bool GetEdgeIndices(GfVec2i const & edgeVertices,
|
||||
std::vector<int> * edgeIndicesOut) const;
|
||||
|
||||
private:
|
||||
struct _Edge{
|
||||
_Edge(GfVec2i const & verts_ = GfVec2i(-1), int index_ = -1)
|
||||
: verts(verts_)
|
||||
, index(index_)
|
||||
{
|
||||
// Simplify sorting and searching by keeping the vertices ordered.
|
||||
if (verts[0] > verts[1]) {
|
||||
std::swap(verts[0], verts[1]);
|
||||
}
|
||||
}
|
||||
GfVec2i verts;
|
||||
int index;
|
||||
|
||||
};
|
||||
|
||||
struct _CompareEdgeVertices {
|
||||
bool operator() (_Edge const &lhs, _Edge const & rhs) const {
|
||||
return (lhs.verts[0] < rhs.verts[0] ||
|
||||
(lhs.verts[0] == rhs.verts[0] &&
|
||||
lhs.verts[1] < rhs.verts[1]));
|
||||
}
|
||||
};
|
||||
|
||||
struct _EdgeVerticesHash {
|
||||
// Use a custom hash so that edges (a,b) and (b,a) are equivalent
|
||||
inline size_t operator()(GfVec2i const& v) const {
|
||||
// Triangular numbers for 2-d hash.
|
||||
int theMin = v[0], theMax = v[1];
|
||||
if (theMin > theMax) {
|
||||
std::swap(theMin, theMax);
|
||||
}
|
||||
size_t x = theMin;
|
||||
size_t y = x + theMax;
|
||||
return x + (y * (y + 1)) / 2;
|
||||
}
|
||||
};
|
||||
|
||||
std::vector<GfVec2i> _edgeVertices;
|
||||
std::vector<_Edge> _edgesByIndex;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_MESH_UTIL_H
|
||||
@@ -0,0 +1,59 @@
|
||||
//
|
||||
// Copyright 2021 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_OVERLAY_CONTAINER_DATA_SOURCE_H
|
||||
#define PXR_IMAGING_HD_OVERLAY_CONTAINER_DATA_SOURCE_H
|
||||
|
||||
#include "pxr/imaging/hd/dataSource.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// \class HdOverlayContainerDataSource
|
||||
///
|
||||
/// Lazily composes two or more container source hierarchies
|
||||
/// Earlier entries on the containers array have stronger opinion strength
|
||||
/// for overlapping child names. Overlapping children which are all containers
|
||||
/// themselves are returned as another instance of this class
|
||||
class HdOverlayContainerDataSource : public HdContainerDataSource
|
||||
{
|
||||
public:
|
||||
HD_DECLARE_DATASOURCE(HdOverlayContainerDataSource);
|
||||
|
||||
HdOverlayContainerDataSource(
|
||||
size_t count,
|
||||
HdContainerDataSourceHandle *containers);
|
||||
|
||||
bool Has(const TfToken &name) override;
|
||||
TfTokenVector GetNames() override;
|
||||
HdDataSourceBaseHandle Get(const TfToken &name) override;
|
||||
|
||||
private:
|
||||
using _ContainerVector = TfSmallVector<HdContainerDataSourceHandle, 8>;
|
||||
_ContainerVector _containers;
|
||||
};
|
||||
|
||||
HD_DECLARE_DATASOURCE_HANDLES(HdOverlayContainerDataSource);
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,240 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_PERF_LOG_H
|
||||
#define PXR_IMAGING_HD_PERF_LOG_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/debugCodes.h"
|
||||
|
||||
#include "pxr/base/trace/trace.h"
|
||||
|
||||
#include "pxr/base/tf/mallocTag.h"
|
||||
#include "pxr/base/tf/singleton.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
|
||||
#include "pxr/base/tf/hashmap.h"
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
class SdfPath;
|
||||
class HdResourceRegistry;
|
||||
|
||||
// XXX: it would be nice to move this into Trace or use the existing Trace
|
||||
// counter mechanism, however we are restricted to TraceLite in the rocks.
|
||||
|
||||
//----------------------------------------------------------------------------//
|
||||
// PERFORMANCE INSTURMENTATION MACROS //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
// Emits a trace scope tagged for the function.
|
||||
#define HD_TRACE_FUNCTION() TRACE_FUNCTION()
|
||||
// Emits a trace scope with the specified tag.
|
||||
#define HD_TRACE_SCOPE(tag) TRACE_SCOPE(tag)
|
||||
|
||||
// Adds a cache hit for the given cache name, the id is provided for debugging,
|
||||
// see HdPerfLog for details.
|
||||
#define HD_PERF_CACHE_HIT(name, id) \
|
||||
HdPerfLog::GetInstance().AddCacheHit(name, id);
|
||||
#define HD_PERF_CACHE_HIT_TAG(name, id, tag) \
|
||||
HdPerfLog::GetInstance().AddCacheHit(name, id, tag);
|
||||
|
||||
// Adds a cache miss for the given cache name, the id is provided for debugging,
|
||||
// see HdPerfLog for details.
|
||||
#define HD_PERF_CACHE_MISS(name, id) \
|
||||
HdPerfLog::GetInstance().AddCacheMiss(name, id);
|
||||
#define HD_PERF_CACHE_MISS_TAG(name, id, tag) \
|
||||
HdPerfLog::GetInstance().AddCacheMiss(name, id, tag);
|
||||
|
||||
// Increments/Decrements/Sets/Adds/Subtracts a named performance counter
|
||||
// see HdPerfLog for details.
|
||||
#define HD_PERF_COUNTER_INCR(name) \
|
||||
HdPerfLog::GetInstance().IncrementCounter(name);
|
||||
#define HD_PERF_COUNTER_DECR(name) \
|
||||
HdPerfLog::GetInstance().DecrementCounter(name);
|
||||
#define HD_PERF_COUNTER_SET(name, value) \
|
||||
HdPerfLog::GetInstance().SetCounter(name, value);
|
||||
#define HD_PERF_COUNTER_ADD(name, value) \
|
||||
HdPerfLog::GetInstance().AddCounter(name, value);
|
||||
#define HD_PERF_COUNTER_SUBTRACT(name, value) \
|
||||
HdPerfLog::GetInstance().SubtractCounter(name, value);
|
||||
|
||||
//----------------------------------------------------------------------------//
|
||||
// PERFORMANCE LOG //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
/// \class HdPerfLog
|
||||
///
|
||||
/// Performance counter monitoring.
|
||||
///
|
||||
class HdPerfLog
|
||||
{
|
||||
public:
|
||||
HD_API
|
||||
static HdPerfLog& GetInstance() {
|
||||
return TfSingleton<HdPerfLog>::GetInstance();
|
||||
}
|
||||
|
||||
/// Tracks a cache hit for the named cache, the id and tag are reported
|
||||
/// when debug logging is enabled.
|
||||
HD_API
|
||||
void AddCacheHit(TfToken const& name,
|
||||
SdfPath const& id,
|
||||
TfToken const& tag=TfToken());
|
||||
|
||||
/// Tracks a cache miss for the named cache, the id and tag are reported
|
||||
/// when debug logging is enabled.
|
||||
HD_API
|
||||
void AddCacheMiss(TfToken const& name,
|
||||
SdfPath const& id,
|
||||
TfToken const& tag=TfToken());
|
||||
|
||||
HD_API
|
||||
void ResetCache(TfToken const& name);
|
||||
|
||||
/// Gets the hit ratio (numHits / totalRequests) of a cache performance
|
||||
/// counter.
|
||||
HD_API
|
||||
double GetCacheHitRatio(TfToken const& name);
|
||||
|
||||
/// Gets the number of hit hits for a cache performance counter.
|
||||
HD_API
|
||||
size_t GetCacheHits(TfToken const& name);
|
||||
|
||||
/// Gets the number of hit misses for a cache performance counter.
|
||||
HD_API
|
||||
size_t GetCacheMisses(TfToken const& name);
|
||||
|
||||
/// Returns the names of all cache performance counters.
|
||||
HD_API
|
||||
TfTokenVector GetCacheNames();
|
||||
|
||||
/// Returns a vector of all performance counter names.
|
||||
HD_API
|
||||
TfTokenVector GetCounterNames();
|
||||
|
||||
/// Increments a named counter by 1.0.
|
||||
HD_API
|
||||
void IncrementCounter(TfToken const& name);
|
||||
|
||||
/// Decrements a named counter by 1.0.
|
||||
HD_API
|
||||
void DecrementCounter(TfToken const& name);
|
||||
|
||||
/// Sets the value of a named counter.
|
||||
HD_API
|
||||
void SetCounter(TfToken const& name, double value);
|
||||
|
||||
/// Adds value to a named counter.
|
||||
HD_API
|
||||
void AddCounter(TfToken const& name, double value);
|
||||
|
||||
/// Subtracts value to a named counter.
|
||||
HD_API
|
||||
void SubtractCounter(TfToken const& name, double value);
|
||||
|
||||
/// Returns the current value of a named counter.
|
||||
HD_API
|
||||
double GetCounter(TfToken const& name);
|
||||
|
||||
/// Reset all conter values to 0.0.
|
||||
/// Note that this doesn't reset cache counters.
|
||||
HD_API
|
||||
void ResetCounters();
|
||||
|
||||
/// Enable performance logging.
|
||||
void Enable() { _enabled = true; }
|
||||
|
||||
/// Disable performance logging.
|
||||
void Disable() { _enabled = false; }
|
||||
|
||||
/// Add a resource registry to the tracking.
|
||||
HD_API
|
||||
void AddResourceRegistry(HdResourceRegistry * resourceRegistry);
|
||||
|
||||
/// Remove Resource Registry from the tracking.
|
||||
HD_API
|
||||
void RemoveResourceRegistry(HdResourceRegistry * resourceRegistry);
|
||||
|
||||
/// Returns a vector of resource registry.
|
||||
HD_API
|
||||
std::vector<HdResourceRegistry*> const& GetResourceRegistryVector();
|
||||
|
||||
private:
|
||||
|
||||
// Don't allow copies
|
||||
HdPerfLog(const HdPerfLog &) = delete;
|
||||
HdPerfLog &operator=(const HdPerfLog &) = delete;
|
||||
|
||||
friend class TfSingleton<HdPerfLog>;
|
||||
HD_API HdPerfLog();
|
||||
HD_API ~HdPerfLog();
|
||||
|
||||
// Tracks number of hits and misses and provides some convenience API.
|
||||
class _CacheEntry {
|
||||
public:
|
||||
_CacheEntry() : _hits(0), _misses(0) { }
|
||||
|
||||
void AddHit() {++_hits;}
|
||||
size_t GetHits() {return _hits;}
|
||||
|
||||
void AddMiss() {++_misses;}
|
||||
size_t GetMisses() {return _misses;}
|
||||
|
||||
size_t GetTotal() {return _hits+_misses;}
|
||||
double GetHitRatio() {return (double)_hits / GetTotal();}
|
||||
|
||||
void Reset() { _hits = 0; _misses = 0; }
|
||||
private:
|
||||
size_t _hits;
|
||||
size_t _misses;
|
||||
};
|
||||
|
||||
// Cache performance counters.
|
||||
typedef TfHashMap<TfToken, _CacheEntry, TfToken::HashFunctor> _CacheMap;
|
||||
_CacheMap _cacheMap;
|
||||
|
||||
// Named value counters.
|
||||
typedef TfHashMap<TfToken, double, TfToken::HashFunctor> _CounterMap;
|
||||
_CounterMap _counterMap;
|
||||
|
||||
// Resource registry vector.
|
||||
std::vector<HdResourceRegistry *> _resourceRegistryVector;
|
||||
|
||||
// Enable / disable performance tracking.
|
||||
bool _enabled;
|
||||
std::mutex _mutex;
|
||||
typedef std::lock_guard<std::mutex> _Lock;
|
||||
};
|
||||
|
||||
HD_API_TEMPLATE_CLASS(TfSingleton<HdPerfLog>);
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_PERF_LOG_H
|
||||
@@ -0,0 +1,96 @@
|
||||
//
|
||||
// Copyright 2020 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_PLUGIN_RENDER_DELEGATE_UNIQUE_HANDLE_H
|
||||
#define PXR_IMAGING_HD_PLUGIN_RENDER_DELEGATE_UNIQUE_HANDLE_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/rendererPluginHandle.h"
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdRenderDelegate;
|
||||
|
||||
///
|
||||
/// A (movable) handle for a render delegate that was created using a
|
||||
/// a plugin.
|
||||
///
|
||||
/// The handle owns the render delegate (render delegate is destroyed
|
||||
/// when handle is dropped). The handle also can be queried what
|
||||
/// plugin was used to create the render delegate and ensures the
|
||||
/// plugin is kept alive until the render delegate is destroyed.
|
||||
/// In other words, the handle can be used just like a std::unique_ptr.
|
||||
///
|
||||
class HdPluginRenderDelegateUniqueHandle final
|
||||
{
|
||||
public:
|
||||
HdPluginRenderDelegateUniqueHandle() : _delegate(nullptr) { }
|
||||
HdPluginRenderDelegateUniqueHandle(const std::nullptr_t &)
|
||||
: _delegate(nullptr) { }
|
||||
|
||||
/// Transfer ownership
|
||||
HD_API
|
||||
HdPluginRenderDelegateUniqueHandle(HdPluginRenderDelegateUniqueHandle &&);
|
||||
|
||||
HD_API
|
||||
~HdPluginRenderDelegateUniqueHandle();
|
||||
|
||||
/// Transfer ownership
|
||||
HD_API
|
||||
HdPluginRenderDelegateUniqueHandle &operator=(
|
||||
HdPluginRenderDelegateUniqueHandle &&);
|
||||
|
||||
HD_API
|
||||
HdPluginRenderDelegateUniqueHandle &operator=(
|
||||
const std::nullptr_t &);
|
||||
|
||||
/// Get render delegate
|
||||
HdRenderDelegate *Get() const { return _delegate; }
|
||||
|
||||
HdRenderDelegate *operator->() const { return _delegate; }
|
||||
HdRenderDelegate &operator*() const { return *_delegate; }
|
||||
|
||||
/// Is the wrapped HdRenderDelegate valid?
|
||||
explicit operator bool() const { return _delegate; }
|
||||
|
||||
/// Get the id of the plugin used to create render delegate
|
||||
HD_API
|
||||
TfToken GetPluginId() const;
|
||||
|
||||
private:
|
||||
friend class HdRendererPlugin;
|
||||
|
||||
HdPluginRenderDelegateUniqueHandle(
|
||||
const HdRendererPluginHandle &plugin, HdRenderDelegate * delegate)
|
||||
: _plugin(plugin), _delegate(delegate) { }
|
||||
|
||||
HdRendererPluginHandle _plugin;
|
||||
HdRenderDelegate *_delegate;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,90 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_POINTS_H
|
||||
#define PXR_IMAGING_HD_POINTS_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/rprim.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// \class HdPointsReprDesc
|
||||
///
|
||||
/// Descriptor to configure a drawItem for a repr.
|
||||
///
|
||||
struct HdPointsReprDesc {
|
||||
HdPointsReprDesc(
|
||||
HdPointsGeomStyle geomStyle = HdPointsGeomStyleInvalid)
|
||||
: geomStyle(geomStyle)
|
||||
{}
|
||||
|
||||
bool IsEmpty() const {
|
||||
return geomStyle == HdPointsGeomStyleInvalid;
|
||||
}
|
||||
|
||||
HdPointsGeomStyle geomStyle;
|
||||
};
|
||||
|
||||
/// Hydra Schema for a point cloud.
|
||||
///
|
||||
class HdPoints: public HdRprim {
|
||||
public:
|
||||
HD_API
|
||||
virtual ~HdPoints();
|
||||
|
||||
HD_API
|
||||
TfTokenVector const & GetBuiltinPrimvarNames() const override;
|
||||
|
||||
/// Configure geometric style of drawItems for \p reprName
|
||||
HD_API
|
||||
static void ConfigureRepr(TfToken const &reprName,
|
||||
const HdPointsReprDesc &desc);
|
||||
|
||||
protected:
|
||||
/// Constructor. instancerId, if specified, is the instancer which uses
|
||||
/// this point cloud as a prototype.
|
||||
HD_API
|
||||
HdPoints(SdfPath const& id);
|
||||
|
||||
typedef _ReprDescConfigs<HdPointsReprDesc> _PointsReprConfig;
|
||||
|
||||
HD_API
|
||||
static _PointsReprConfig::DescArray _GetReprDesc(TfToken const &reprName);
|
||||
|
||||
private:
|
||||
|
||||
// Class can not be default constructed or copied.
|
||||
HdPoints() = delete;
|
||||
HdPoints(const HdPoints &) = delete;
|
||||
HdPoints &operator =(const HdPoints &) = delete;
|
||||
|
||||
static _PointsReprConfig _reprDescConfig;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_POINTS_H
|
||||
@@ -0,0 +1,91 @@
|
||||
//
|
||||
// Copyright 2021 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_PREFIXING_SCENE_INDEX_H
|
||||
#define PXR_IMAGING_HD_PREFIXING_SCENE_INDEX_H
|
||||
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/filteringSceneIndex.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdPrefixingSceneIndex;
|
||||
TF_DECLARE_REF_PTRS(HdPrefixingSceneIndex);
|
||||
|
||||
///
|
||||
/// \class HdPrefixingSceneIndex
|
||||
///
|
||||
/// A prefixing scene index is one in which the input scene contains data
|
||||
/// data sources whose paths are all prefixed with a given prefix.
|
||||
///
|
||||
class HdPrefixingSceneIndex : public HdSingleInputFilteringSceneIndexBase
|
||||
{
|
||||
public:
|
||||
|
||||
/// Creates a new prefixing scene index.
|
||||
///
|
||||
static HdPrefixingSceneIndexRefPtr New(
|
||||
const HdSceneIndexBaseRefPtr &inputScene, const SdfPath &prefix)
|
||||
{
|
||||
return TfCreateRefPtr(new HdPrefixingSceneIndex(inputScene, prefix));
|
||||
}
|
||||
|
||||
// satisfying HdSceneIndexBase
|
||||
HD_API
|
||||
HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override;
|
||||
|
||||
HD_API
|
||||
SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override;
|
||||
|
||||
protected:
|
||||
|
||||
HD_API
|
||||
HdPrefixingSceneIndex(const HdSceneIndexBaseRefPtr &inputScene,
|
||||
const SdfPath &prefix);
|
||||
|
||||
// satisfying HdSingleInputFilteringSceneIndexBase
|
||||
void _PrimsAdded(
|
||||
const HdSceneIndexBase &sender,
|
||||
const HdSceneIndexObserver::AddedPrimEntries &entries) override;
|
||||
|
||||
void _PrimsRemoved(
|
||||
const HdSceneIndexBase &sender,
|
||||
const HdSceneIndexObserver::RemovedPrimEntries &entries) override;
|
||||
|
||||
void _PrimsDirtied(
|
||||
const HdSceneIndexBase &sender,
|
||||
const HdSceneIndexObserver::DirtiedPrimEntries &entries) override;
|
||||
|
||||
private:
|
||||
|
||||
SdfPath _AddPathPrefix(const SdfPath &primPath) const;
|
||||
|
||||
SdfPath _RemovePathPrefix(const SdfPath &primPath) const;
|
||||
|
||||
const SdfPath _prefix;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
//
|
||||
// Copyright 2021 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_PRIM_DATA_SOURCE_OVERLAY_CACHE_H
|
||||
#define PXR_IMAGING_HD_PRIM_DATA_SOURCE_OVERLAY_CACHE_H
|
||||
|
||||
#include "pxr/imaging/hd/sceneIndex.h"
|
||||
#include "pxr/imaging/hd/dataSource.h"
|
||||
|
||||
#include "pxr/usd/sdf/pathTable.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// A utility class to handle caching of datasource overlays, along with
|
||||
// invalidation functions to clear the cache.
|
||||
|
||||
class HdPrimDataSourceOverlayCache :
|
||||
public std::enable_shared_from_this<HdPrimDataSourceOverlayCache>
|
||||
{
|
||||
public:
|
||||
virtual ~HdPrimDataSourceOverlayCache();
|
||||
|
||||
HdSceneIndexPrim GetPrim(const SdfPath &primPath) const;
|
||||
|
||||
void HandlePrimsAdded(
|
||||
const HdSceneIndexObserver::AddedPrimEntries &entries,
|
||||
const HdSceneIndexBaseRefPtr &source);
|
||||
void HandlePrimsRemoved(
|
||||
const HdSceneIndexObserver::RemovedPrimEntries &entries);
|
||||
void HandlePrimsDirtied(
|
||||
const HdSceneIndexObserver::DirtiedPrimEntries &entries,
|
||||
HdSceneIndexObserver::DirtiedPrimEntries *additionalDirtied);
|
||||
|
||||
protected:
|
||||
HdPrimDataSourceOverlayCache() = default;
|
||||
|
||||
// This struct provides a way for users of the cache to describe the
|
||||
// structure of synthetic attributes. For example, if you compute
|
||||
// "xformInverse" from "xform", the topology would look like:
|
||||
// OverlayTopology topo = { "xformInverse" ->
|
||||
// { .onPrim = { "xform" }, .onParent = { }, false }
|
||||
// }
|
||||
// ... notably, this tells us what attributes we're adding (xformInverse,
|
||||
// but only when xform is present); and also to dirty xformInverse when
|
||||
// xform is dirty.
|
||||
//
|
||||
// For attributes we always want to add (even if their dependents are not
|
||||
// present), dependenciesOptional lets us say as much.
|
||||
//
|
||||
// Note: _ComputeOverlayDataSource should respect this topology, or behavior
|
||||
// is undefined...
|
||||
//
|
||||
// XXX: the "onParent" dependencies here are to support eventual inherited
|
||||
// attribute caching, but this feature hasn't been implemented yet.
|
||||
struct _OverlayDependencies
|
||||
{
|
||||
_OverlayDependencies()
|
||||
: onPrim(), onParent(), dependenciesOptional(false) {}
|
||||
|
||||
HdDataSourceLocatorSet onPrim;
|
||||
HdDataSourceLocatorSet onParent;
|
||||
bool dependenciesOptional;
|
||||
};
|
||||
using _OverlayTopology = std::map<TfToken, _OverlayDependencies>;
|
||||
|
||||
|
||||
// Topology should be set once, from the derived class constructor.
|
||||
void _SetOverlayTopology(const _OverlayTopology &topology) {
|
||||
_overlayTopology = topology;
|
||||
}
|
||||
|
||||
// Compute the named datasource. Note that inputDataSource comes from the
|
||||
// source scene index, while parentOverlayDataSource comes from the cache
|
||||
// and is consequently recursively composed.
|
||||
//
|
||||
// XXX: the "parentOverlayDataSource" is here to support eventual inherited
|
||||
// attribute caching, but this feature hasn't been implemented yet. For now,
|
||||
// it will always be null.
|
||||
virtual HdDataSourceBaseHandle _ComputeOverlayDataSource(
|
||||
const TfToken &name,
|
||||
HdContainerDataSourceHandle inputDataSource,
|
||||
HdContainerDataSourceHandle parentOverlayDataSource) const = 0;
|
||||
|
||||
private:
|
||||
class _HdPrimDataSourceOverlay : public HdContainerDataSource
|
||||
{
|
||||
public:
|
||||
HD_DECLARE_DATASOURCE(_HdPrimDataSourceOverlay);
|
||||
|
||||
_HdPrimDataSourceOverlay(
|
||||
HdContainerDataSourceHandle inputDataSource,
|
||||
HdContainerDataSourceHandle parentOverlayDataSource,
|
||||
const std::weak_ptr<const HdPrimDataSourceOverlayCache> cache);
|
||||
|
||||
void UpdateInputDataSource(HdContainerDataSourceHandle inputDataSource);
|
||||
|
||||
void PrimDirtied(const HdDataSourceLocatorSet &dirtyAttributes);
|
||||
|
||||
bool Has(const TfToken &name) override;
|
||||
TfTokenVector GetNames() override;
|
||||
HdDataSourceBaseHandle Get(const TfToken &name) override;
|
||||
|
||||
private:
|
||||
HdContainerDataSourceHandle _inputDataSource;
|
||||
HdContainerDataSourceHandle _parentOverlayDataSource;
|
||||
const std::weak_ptr<const HdPrimDataSourceOverlayCache> _cache;
|
||||
|
||||
using _OverlayMap = std::map<TfToken, HdDataSourceBaseHandle>;
|
||||
|
||||
_OverlayMap _overlayMap;
|
||||
};
|
||||
|
||||
SdfPathTable<HdSceneIndexPrim> _cache;
|
||||
_OverlayTopology _overlayTopology;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,235 @@
|
||||
//
|
||||
// Copyright 2017 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_PRIM_GATHER_H
|
||||
#define PXR_IMAGING_HD_PRIM_GATHER_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
|
||||
#include <vector>
|
||||
#include <tbb/enumerable_thread_specific.h>
|
||||
#include <tbb/blocked_range.h>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdPrimGather final {
|
||||
public:
|
||||
typedef bool (*FilterPredicateFn)(const SdfPath &path, const void *param);
|
||||
|
||||
HdPrimGather() = default;
|
||||
~HdPrimGather() = default;
|
||||
|
||||
///
|
||||
/// Filter takes a list of paths and returns a list of paths that
|
||||
/// match the following criteria:
|
||||
///
|
||||
/// - A path is prefixed by at least one include path
|
||||
/// - A path is not prefixed by an exclude path that has more elements
|
||||
/// than the include path with the most element that is a prefix
|
||||
/// of the path.
|
||||
///
|
||||
/// The list of paths to filter must be pre-sorted with
|
||||
/// ordering defined by std::less<SdfPath &>.
|
||||
///
|
||||
/// The list of include and exclude paths do not need to be pre-sorted.
|
||||
///
|
||||
/// If the same path appears in the list of include and exclude paths
|
||||
/// results are undefined.
|
||||
///
|
||||
/// The resulting set of paths are stored in results arg, the results
|
||||
/// might not be in sorted order.
|
||||
///
|
||||
HD_API
|
||||
void Filter(const SdfPathVector &paths,
|
||||
const SdfPathVector &includePaths,
|
||||
const SdfPathVector &excludePaths,
|
||||
SdfPathVector *results);
|
||||
|
||||
///
|
||||
/// PredicatedFilter takes a list of paths and returns a list of paths that
|
||||
/// match the following criteria:
|
||||
///
|
||||
/// - A path is prefixed by at least one include path
|
||||
/// - A path is not prefixed by an exclude path that has more elements
|
||||
/// than the include path with the most element that is a prefix
|
||||
/// of the path.
|
||||
/// - The predicate function for the path returns true.
|
||||
///
|
||||
/// The list of paths to filter must be pre-sorted with
|
||||
/// ordering defined by std::less<SdfPath &>.
|
||||
///
|
||||
/// The list of include and exclude paths do not need to be pre-sorted.
|
||||
///
|
||||
/// If the same path appears in the list of include and exclude paths
|
||||
/// results are undefined.
|
||||
///
|
||||
/// The predicate function has the prototype:
|
||||
/// bool Predicate(const SdfPath &path, void *param);
|
||||
///
|
||||
/// The function should return true if the path should appear in the results
|
||||
/// and false if not. The Predicate function may be called on worker
|
||||
/// threads and as such must be thread-safe.
|
||||
///
|
||||
/// The resulting set of paths are stored in results arg, the results
|
||||
/// might not be in sorted order.
|
||||
///
|
||||
HD_API
|
||||
void PredicatedFilter(const SdfPathVector &paths,
|
||||
const SdfPathVector &includePaths,
|
||||
const SdfPathVector &excludePaths,
|
||||
FilterPredicateFn predicateFn,
|
||||
void *predicateParam,
|
||||
SdfPathVector *results);
|
||||
|
||||
///
|
||||
/// Subtree is a simplified form of filter, that gathers
|
||||
/// all prims that meet the single rootPath prefix condition.
|
||||
///
|
||||
/// The list of paths to filter must be pre-sorted with
|
||||
/// ordering defined by std::less<SdfPath &>.
|
||||
///
|
||||
/// The returned result maintain the sorted order.
|
||||
///
|
||||
HD_API
|
||||
void Subtree(const SdfPathVector &paths,
|
||||
const SdfPath &rootPath,
|
||||
SdfPathVector *results);
|
||||
|
||||
///
|
||||
/// Subtree is a simplified form of filter, that gathers
|
||||
/// all prims that meet the single rootPath prefix condition.
|
||||
///
|
||||
/// The list of paths to filter must be pre-sorted with
|
||||
/// ordering defined by std::less<SdfPath &>.
|
||||
///
|
||||
/// Rather than returning a list the paths, it instead returns
|
||||
/// the start and end (inclusive) indexes into the paths
|
||||
/// vector of that subtree range.
|
||||
///
|
||||
/// If the rootPath wasn't found or an error occurred, that
|
||||
/// otherwise produces an invalid range. The method returns false.
|
||||
HD_API
|
||||
bool SubtreeAsRange(const SdfPathVector &paths,
|
||||
const SdfPath &rootPath,
|
||||
size_t *start,
|
||||
size_t *end);
|
||||
|
||||
private:
|
||||
struct _PathFilter {
|
||||
SdfPath _path;
|
||||
bool _includePath; // false = exclude path
|
||||
|
||||
_PathFilter(const SdfPath &path, bool includePath)
|
||||
: _path(path)
|
||||
, _includePath(includePath)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool operator >(const _PathFilter &other) const {
|
||||
return other._path < _path;
|
||||
}
|
||||
};
|
||||
typedef std::vector<_PathFilter> _PathFilterArray;
|
||||
|
||||
// While processing, the algorithm stores results as a set of ranges
|
||||
// rather than copying all the paths.
|
||||
// This to avoid copying the larger set of paths at intermediate
|
||||
// processing steps.
|
||||
struct _Range {
|
||||
size_t _start;
|
||||
size_t _end; // Inclusive
|
||||
|
||||
_Range(size_t start, size_t end)
|
||||
: _start(start)
|
||||
, _end(end)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
typedef std::vector<_Range> _RangeArray;
|
||||
typedef tbb::enumerable_thread_specific<_RangeArray> _ConcurrentRangeArray;
|
||||
typedef tbb::blocked_range<size_t> _ConcurrentRange;
|
||||
|
||||
|
||||
|
||||
_PathFilterArray _filterList;
|
||||
_RangeArray _gatheredRanges;
|
||||
_ConcurrentRangeArray _resultRanges;
|
||||
|
||||
|
||||
|
||||
size_t _FindLowerBound(const SdfPathVector &paths,
|
||||
size_t start,
|
||||
size_t end,
|
||||
const SdfPath &path) const;
|
||||
size_t _FindUpperBound(const SdfPathVector &paths,
|
||||
size_t start,
|
||||
size_t end,
|
||||
const SdfPath &path) const;
|
||||
|
||||
void _FilterRange(const SdfPathVector &paths,
|
||||
size_t start,
|
||||
size_t end,
|
||||
bool include);
|
||||
|
||||
void _SetupFilter(const SdfPathVector &includePaths,
|
||||
const SdfPathVector &excludePaths);
|
||||
|
||||
void _GatherPaths(const SdfPathVector &paths);
|
||||
|
||||
// Outer Loop called for each range in vector
|
||||
void _DoPredicateTestOnRange(const SdfPathVector &paths,
|
||||
const _Range &range,
|
||||
FilterPredicateFn predicateFn,
|
||||
void *predicateParam);
|
||||
|
||||
// Inner Loop over each prim in a sub range of _Range.
|
||||
void _DoPredicateTestOnPrims(const SdfPathVector &paths,
|
||||
_ConcurrentRange &range,
|
||||
FilterPredicateFn predicateFn,
|
||||
void *predicateParam);
|
||||
|
||||
template <class Iterator>
|
||||
static void _WriteResults(const SdfPathVector &paths,
|
||||
const Iterator &rangesBegin,
|
||||
const Iterator &rangesEnd,
|
||||
SdfPathVector *results);
|
||||
|
||||
void _FilterSubTree(const SdfPathVector &paths,
|
||||
const SdfPath &rootPath);
|
||||
|
||||
// No default copying or assignment
|
||||
HdPrimGather(const HdPrimGather &) = delete;
|
||||
HdPrimGather &operator =(const HdPrimGather &) = delete;
|
||||
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_PRIM_GATHER_H
|
||||
@@ -0,0 +1,228 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_PRIM_TYPE_INDEX_H
|
||||
#define PXR_IMAGING_HD_PRIM_TYPE_INDEX_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/types.h"
|
||||
#include "pxr/imaging/hd/sortedIds.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
|
||||
#include <set>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdChangeTracker;
|
||||
class HdRenderDelegate;
|
||||
class HdRenderParam;
|
||||
class HdSceneDelegate;
|
||||
class SdfPath;
|
||||
using HdSceneDelegatePtrVector = std::vector<HdSceneDelegate*>;
|
||||
|
||||
/// This class is only used by the render index.
|
||||
/// It provides functionality to manage and store one class of prim
|
||||
/// such as a Sprim or Bprim.
|
||||
template <class PrimType>
|
||||
class Hd_PrimTypeIndex {
|
||||
public:
|
||||
Hd_PrimTypeIndex();
|
||||
~Hd_PrimTypeIndex();
|
||||
|
||||
///
|
||||
/// Initialize this prim index, specifying the typeId tokens
|
||||
/// that should be supported by this index.
|
||||
///
|
||||
void InitPrimTypes(const TfTokenVector &primTypes);
|
||||
|
||||
///
|
||||
/// Removes and frees all prims in this index.
|
||||
/// The render delegate is responsible for freeing the actual memory
|
||||
/// allocated to the prim.
|
||||
/// The prim is also removed from the change tracker.
|
||||
///
|
||||
void Clear(HdChangeTracker &tracker, HdRenderDelegate *renderDelegate);
|
||||
|
||||
///
|
||||
/// Add a new a prim to the render index identified by the globally unique
|
||||
/// identifier, primId.
|
||||
/// typeId is the type of the prim to create, which is allocated using
|
||||
/// the provided render delegate. The Scene delegate provided is
|
||||
/// associated with the prim and is the one used to pull the data for the
|
||||
/// prim during sync processing.
|
||||
/// As well as being inserted into this index, the prim is added to the
|
||||
/// change tracker, with the initial dirty state provided by the prim itself.
|
||||
///
|
||||
void InsertPrim(const TfToken &typeId,
|
||||
HdSceneDelegate *sceneDelegate,
|
||||
const SdfPath &primId,
|
||||
HdChangeTracker &tracker,
|
||||
HdRenderDelegate *renderDelegate);
|
||||
|
||||
///
|
||||
/// Removes the prim identifier by primId. TypeId is the type of that
|
||||
/// prim. Memory for the prim is deallocated using the render delegate.
|
||||
/// The prim is also removed from the change tracker.
|
||||
///
|
||||
void RemovePrim(const TfToken &typeId,
|
||||
const SdfPath &primId,
|
||||
HdChangeTracker &tracker,
|
||||
HdRenderDelegate *renderDelegate);
|
||||
|
||||
///
|
||||
/// Removes the subtree of prims identifier by root that are owned
|
||||
/// by the given scene delegate.
|
||||
/// This function affects all prim types.
|
||||
/// Memory for the prim is deallocated using the render delegate.
|
||||
/// The prim is also removed from the change tracker.
|
||||
///
|
||||
void RemoveSubtree(const SdfPath &root,
|
||||
HdSceneDelegate* sceneDelegate,
|
||||
HdChangeTracker &tracker,
|
||||
HdRenderDelegate *renderDelegate);
|
||||
|
||||
/// Obtains a modifiable pointer the prim with the given type and id.
|
||||
/// If no prim with the given id is in the index or the type id is
|
||||
/// incorrect, then nullptr is returned.
|
||||
PrimType *GetPrim(const TfToken &typeId,
|
||||
const SdfPath &primId) const;
|
||||
|
||||
///
|
||||
/// Obtain a prim, that implements the schema given by type id, that
|
||||
/// can be used as a substitute for any prim of that type in the event of
|
||||
/// an error.
|
||||
///
|
||||
/// Hydra guarantees that the prim is not null for any type that
|
||||
/// is supported by the back-end.
|
||||
///
|
||||
PrimType *GetFallbackPrim(TfToken const &typeId) const;
|
||||
|
||||
///
|
||||
/// Returns a list of Prim Ids in outPaths of prims that type match
|
||||
/// typeId who are namespace children of rootPath.
|
||||
/// rootPath does not need to match any prim in the index or
|
||||
/// it may point to a prim of a different type.
|
||||
///
|
||||
void GetPrimSubtree(const TfToken &typeId,
|
||||
const SdfPath &rootPath,
|
||||
SdfPathVector *outPaths);
|
||||
|
||||
///
|
||||
/// Uses the provided render delegate to create the fallback prims
|
||||
/// for use by the index. The prim types created are based on those
|
||||
/// specified by InitPrimTypes.
|
||||
///
|
||||
/// If the render delegate fails to create a prim, this function returns
|
||||
/// false and the index is remain uninitialized and shouldn't be used.
|
||||
///
|
||||
bool CreateFallbackPrims(HdRenderDelegate *renderDelegate);
|
||||
|
||||
///
|
||||
/// Clean-up function for the index. Uses the delegate to deallocate
|
||||
/// the memory used by the fallback prims. The index is returned to
|
||||
/// an uninitialized state and shouldn't be used, unless reinitialized.
|
||||
///
|
||||
void DestroyFallbackPrims(HdRenderDelegate *renderDelegate);
|
||||
|
||||
///
|
||||
/// Main Sync Processing function.
|
||||
///
|
||||
/// Will call the Sync function on all prims in the index that
|
||||
/// are marked dirty in the specified change tracker.
|
||||
/// Also updates an internal list of scene delegates for the dirty prims.
|
||||
///
|
||||
void SyncPrims(HdChangeTracker &tracker,
|
||||
HdRenderParam *renderParam);
|
||||
|
||||
/// Returns a vector of unique scene delegates corresponding to the dirty
|
||||
/// prims that were sync'd in SyncPrims.
|
||||
const HdSceneDelegatePtrVector& GetSceneDelegatesForDirtyPrims();
|
||||
|
||||
private:
|
||||
struct _PrimInfo {
|
||||
HdSceneDelegate *sceneDelegate;
|
||||
PrimType *prim;
|
||||
};
|
||||
|
||||
typedef std::unordered_map<SdfPath, _PrimInfo, SdfPath::Hash> _PrimMap;
|
||||
|
||||
struct _PrimTypeEntry
|
||||
{
|
||||
_PrimMap primMap;
|
||||
Hd_SortedIds primIds; // Primarily for sub-tree searching
|
||||
PrimType *fallbackPrim;
|
||||
|
||||
_PrimTypeEntry()
|
||||
: primMap()
|
||||
, primIds()
|
||||
, fallbackPrim(nullptr)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::unordered_map<TfToken, size_t, TfToken::HashFunctor> _TypeIndex;
|
||||
|
||||
typedef std::vector<_PrimTypeEntry> _PrimTypeList;
|
||||
|
||||
_PrimTypeList _entries;
|
||||
_TypeIndex _index;
|
||||
HdSceneDelegatePtrVector _dirtyPrimDelegates;
|
||||
|
||||
|
||||
// Template methods that are expected to be specialized on PrimType.
|
||||
// These are to handle prim type specific function names on called objects.
|
||||
static void _TrackerInsertPrim(HdChangeTracker &tracker,
|
||||
const SdfPath &path,
|
||||
HdDirtyBits initialDirtyState);
|
||||
|
||||
static void _TrackerRemovePrim(HdChangeTracker &tracker,
|
||||
const SdfPath &path);
|
||||
|
||||
static HdDirtyBits _TrackerGetPrimDirtyBits(HdChangeTracker &tracker,
|
||||
const SdfPath &path);
|
||||
|
||||
static void _TrackerMarkPrimClean(HdChangeTracker &tracker,
|
||||
const SdfPath &path,
|
||||
HdDirtyBits dirtyBits);
|
||||
|
||||
static PrimType *_RenderDelegateCreatePrim(HdRenderDelegate *renderDelegate,
|
||||
const TfToken &typeId,
|
||||
const SdfPath &primId);
|
||||
static PrimType *_RenderDelegateCreateFallbackPrim(
|
||||
HdRenderDelegate *renderDelegate,
|
||||
const TfToken &typeId);
|
||||
|
||||
static void _RenderDelegateDestroyPrim(HdRenderDelegate *renderDelegate,
|
||||
PrimType *prim);
|
||||
|
||||
// No copying
|
||||
Hd_PrimTypeIndex(const Hd_PrimTypeIndex &) = delete;
|
||||
Hd_PrimTypeIndex &operator =(const Hd_PrimTypeIndex &) = delete;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_PRIM_TYPE_INDEX_H
|
||||
@@ -0,0 +1,179 @@
|
||||
//
|
||||
// Copyright 2021 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// This file is generated by a script. Do not edit directly. Edit the
|
||||
// schema.template.h file to make changes.
|
||||
|
||||
#ifndef PXR_IMAGING_HD_PRIMVAR_SCHEMA_H
|
||||
#define PXR_IMAGING_HD_PRIMVAR_SCHEMA_H
|
||||
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
|
||||
#include "pxr/imaging/hd/schema.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define HDPRIMVAR_SCHEMA_TOKENS \
|
||||
(primvarValue) \
|
||||
(indexedPrimvarValue) \
|
||||
(indices) \
|
||||
(interpolation) \
|
||||
(role) \
|
||||
(constant) \
|
||||
(uniform) \
|
||||
(varying) \
|
||||
(vertex) \
|
||||
(faceVarying) \
|
||||
(instance) \
|
||||
(Point) \
|
||||
(Normal) \
|
||||
(Vector) \
|
||||
(Color) \
|
||||
(PointIndex) \
|
||||
(EdgeIndex) \
|
||||
(FaceIndex) \
|
||||
(TextureCoordinate) \
|
||||
(Transform) \
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdPrimvarSchemaTokens, HD_API,
|
||||
HDPRIMVAR_SCHEMA_TOKENS);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class HdPrimvarSchema : public HdSchema
|
||||
{
|
||||
public:
|
||||
HdPrimvarSchema(HdContainerDataSourceHandle container)
|
||||
: HdSchema(container) {}
|
||||
|
||||
//ACCESSORS
|
||||
|
||||
|
||||
// If the primvar does not have indices, GetPrimvarValue() and
|
||||
// GetIndexedPrimvarValue() will return the same thing. If the primvar
|
||||
// does has indices, GetPrimvarValue() will return the flattened value,
|
||||
// while GetIndexedPrimvarValue() will return the unflattened value.
|
||||
HD_API
|
||||
HdSampledDataSourceHandle GetPrimvarValue();
|
||||
HD_API
|
||||
HdSampledDataSourceHandle GetIndexedPrimvarValue();
|
||||
HD_API
|
||||
HdIntArrayDataSourceHandle GetIndices();
|
||||
HD_API
|
||||
HdTokenDataSourceHandle GetInterpolation();
|
||||
HD_API
|
||||
HdTokenDataSourceHandle GetRole();
|
||||
|
||||
// RETRIEVING AND CONSTRUCTING
|
||||
|
||||
/// 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 HdSampledDataSourceHandle &primvarValue,
|
||||
const HdSampledDataSourceHandle &indexedPrimvarValue,
|
||||
const HdIntArrayDataSourceHandle &indices,
|
||||
const HdTokenDataSourceHandle &interpolation,
|
||||
const HdTokenDataSourceHandle &role
|
||||
);
|
||||
|
||||
/// \class HdPrimvarSchema::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 &SetPrimvarValue(
|
||||
const HdSampledDataSourceHandle &primvarValue);
|
||||
HD_API
|
||||
Builder &SetIndexedPrimvarValue(
|
||||
const HdSampledDataSourceHandle &indexedPrimvarValue);
|
||||
HD_API
|
||||
Builder &SetIndices(
|
||||
const HdIntArrayDataSourceHandle &indices);
|
||||
HD_API
|
||||
Builder &SetInterpolation(
|
||||
const HdTokenDataSourceHandle &interpolation);
|
||||
HD_API
|
||||
Builder &SetRole(
|
||||
const HdTokenDataSourceHandle &role);
|
||||
|
||||
/// Returns a container data source containing the members set thus far.
|
||||
HD_API
|
||||
HdContainerDataSourceHandle Build();
|
||||
|
||||
private:
|
||||
HdSampledDataSourceHandle _primvarValue;
|
||||
HdSampledDataSourceHandle _indexedPrimvarValue;
|
||||
HdIntArrayDataSourceHandle _indices;
|
||||
HdTokenDataSourceHandle _interpolation;
|
||||
HdTokenDataSourceHandle _role;
|
||||
};
|
||||
// Returns true if it contains data sources for an indexed primvar value
|
||||
// and for indices.
|
||||
bool IsIndexed();
|
||||
|
||||
|
||||
/// Returns token data source for use as interpolation value.
|
||||
/// Values of...
|
||||
/// - HdPrimvarSchemaTokens->constant
|
||||
/// - HdPrimvarSchemaTokens->uniform
|
||||
/// - HdPrimvarSchemaTokens->varying
|
||||
/// - HdPrimvarSchemaTokens->vertex
|
||||
/// - HdPrimvarSchemaTokens->faceVarying
|
||||
/// - HdPrimvarSchemaTokens->instance
|
||||
/// ...will be stored statically and reused for future calls.
|
||||
HD_API
|
||||
static HdTokenDataSourceHandle BuildInterpolationDataSource(
|
||||
const TfToken &interpolation);
|
||||
/// Returns token data source for use as role value.
|
||||
/// Values of...
|
||||
/// - HdPrimvarSchemaTokens->Point
|
||||
/// - HdPrimvarSchemaTokens->Normal
|
||||
/// - HdPrimvarSchemaTokens->Vector
|
||||
/// - HdPrimvarSchemaTokens->Color
|
||||
/// - HdPrimvarSchemaTokens->PointIndex
|
||||
/// - HdPrimvarSchemaTokens->EdgeIndex
|
||||
/// - HdPrimvarSchemaTokens->FaceIndex
|
||||
/// - HdPrimvarSchemaTokens->TextureCoordinate
|
||||
/// ...will be stored statically and reused for future calls.
|
||||
HD_API
|
||||
static HdTokenDataSourceHandle BuildRoleDataSource(
|
||||
const TfToken &role);
|
||||
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,101 @@
|
||||
//
|
||||
// Copyright 2021 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// This file is generated by a script. Do not edit directly. Edit the
|
||||
// schema.template.h file to make changes.
|
||||
|
||||
#ifndef PXR_IMAGING_HD_PRIMVARS_SCHEMA_H
|
||||
#define PXR_IMAGING_HD_PRIMVARS_SCHEMA_H
|
||||
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
|
||||
#include "pxr/imaging/hd/primvarSchema.h"
|
||||
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define HDPRIMVARS_SCHEMA_TOKENS \
|
||||
(primvars) \
|
||||
(points) \
|
||||
(normals) \
|
||||
(widths) \
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdPrimvarsSchemaTokens, HD_API,
|
||||
HDPRIMVARS_SCHEMA_TOKENS);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class HdPrimvarsSchema : public HdSchema
|
||||
{
|
||||
public:
|
||||
HdPrimvarsSchema(HdContainerDataSourceHandle container)
|
||||
: HdSchema(container) {}
|
||||
|
||||
TfTokenVector GetPrimvarNames();
|
||||
HdPrimvarSchema GetPrimvar(TfToken name);
|
||||
|
||||
|
||||
/// Retrieves a container data source with the schema's default name token
|
||||
/// "primvars" from the parent container and constructs a
|
||||
/// HdPrimvarsSchema 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 HdPrimvarsSchema GetFromParent(
|
||||
const HdContainerDataSourceHandle &fromParentContainer);
|
||||
|
||||
/// 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();
|
||||
|
||||
|
||||
/// Returns an HdDataSourceLocator (relative to the prim-level data source)
|
||||
/// where the points data source can be found.
|
||||
/// This is often useful for checking intersection against the
|
||||
/// HdDataSourceLocatorSet sent with HdDataSourceObserver::PrimsDirtied.
|
||||
HD_API
|
||||
static const HdDataSourceLocator &GetPointsLocator();
|
||||
|
||||
/// Returns an HdDataSourceLocator (relative to the prim-level data source)
|
||||
/// where the normals data source can be found.
|
||||
/// This is often useful for checking intersection against the
|
||||
/// HdDataSourceLocatorSet sent with HdDataSourceObserver::PrimsDirtied.
|
||||
HD_API
|
||||
static const HdDataSourceLocator &GetNormalsLocator();
|
||||
|
||||
/// Returns an HdDataSourceLocator (relative to the prim-level data source)
|
||||
/// where the widths data source can be found.
|
||||
/// This is often useful for checking intersection against the
|
||||
/// HdDataSourceLocatorSet sent with HdDataSourceObserver::PrimsDirtied.
|
||||
HD_API
|
||||
static const HdDataSourceLocator &GetWidthsLocator();
|
||||
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,111 @@
|
||||
//
|
||||
// Copyright 2021 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// This file is generated by a script. Do not edit directly. Edit the
|
||||
// schema.template.h file to make changes.
|
||||
|
||||
#ifndef PXR_IMAGING_HD_PURPOSE_SCHEMA_H
|
||||
#define PXR_IMAGING_HD_PURPOSE_SCHEMA_H
|
||||
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
|
||||
#include "pxr/imaging/hd/schema.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define HDPURPOSE_SCHEMA_TOKENS \
|
||||
(purpose) \
|
||||
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdPurposeSchemaTokens, HD_API,
|
||||
HDPURPOSE_SCHEMA_TOKENS);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class HdPurposeSchema : public HdSchema
|
||||
{
|
||||
public:
|
||||
HdPurposeSchema(HdContainerDataSourceHandle container)
|
||||
: HdSchema(container) {}
|
||||
|
||||
//ACCESSORS
|
||||
|
||||
HD_API
|
||||
HdTokenDataSourceHandle GetPurpose();
|
||||
|
||||
// RETRIEVING AND CONSTRUCTING
|
||||
|
||||
/// 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 HdTokenDataSourceHandle &purpose
|
||||
);
|
||||
|
||||
/// \class HdPurposeSchema::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 &SetPurpose(
|
||||
const HdTokenDataSourceHandle &purpose);
|
||||
|
||||
/// Returns a container data source containing the members set thus far.
|
||||
HD_API
|
||||
HdContainerDataSourceHandle Build();
|
||||
|
||||
private:
|
||||
HdTokenDataSourceHandle _purpose;
|
||||
};
|
||||
|
||||
/// Retrieves a container data source with the schema's default name token
|
||||
/// "purpose" from the parent container and constructs a
|
||||
/// HdPurposeSchema 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 HdPurposeSchema GetFromParent(
|
||||
const HdContainerDataSourceHandle &fromParentContainer);
|
||||
|
||||
/// 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();
|
||||
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,140 @@
|
||||
//
|
||||
// Copyright 2018 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_RENDER_BUFFER_H
|
||||
#define PXR_IMAGING_HD_RENDER_BUFFER_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/bprim.h"
|
||||
#include "pxr/imaging/hd/types.h"
|
||||
#include "pxr/imaging/hd/enums.h"
|
||||
|
||||
#include "pxr/base/gf/vec2i.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
|
||||
|
||||
/// \class HdRenderBuffer
|
||||
///
|
||||
/// A render buffer is a handle to a data resource that can be rendered into,
|
||||
/// such as a 2d image for a draw target or auxiliary rendering output.
|
||||
///
|
||||
/// The render buffer can be used as an indexed prim, in which case it
|
||||
/// communicates with the scene delegate to get buffer properties, or it can
|
||||
/// be created out of band and supplied directly with allocation parameters.
|
||||
///
|
||||
/// Render buffers can be targeted by render passes. They also contain
|
||||
/// mapping functionality for reading and writing buffer data.
|
||||
class HdRenderBuffer : public HdBprim {
|
||||
public:
|
||||
// change tracking for HdRenderBuffer
|
||||
enum DirtyBits : HdDirtyBits {
|
||||
Clean = 0,
|
||||
DirtyDescription = 1 << 0,
|
||||
AllDirty = (DirtyDescription)
|
||||
};
|
||||
|
||||
HD_API
|
||||
HdRenderBuffer(SdfPath const& id);
|
||||
HD_API
|
||||
virtual ~HdRenderBuffer();
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Prim API
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Get initial invalidation state.
|
||||
HD_API
|
||||
virtual HdDirtyBits GetInitialDirtyBitsMask() const override;
|
||||
|
||||
/// Get allocation information from the scene delegate.
|
||||
HD_API
|
||||
virtual void Sync(HdSceneDelegate *sceneDelegate,
|
||||
HdRenderParam *renderParam,
|
||||
HdDirtyBits *dirtyBits) override;
|
||||
|
||||
/// Deallocate before deletion.
|
||||
HD_API
|
||||
virtual void Finalize(HdRenderParam *renderParam) override;
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Renderbuffer API
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Allocate a buffer. Can be called from Sync(), or directly.
|
||||
/// If the buffer has already been allocated, calling Allocate() again
|
||||
/// will destroy the old buffer and allocate a new one.
|
||||
///
|
||||
/// A negative dimension or invalid format will cause an allocation error.
|
||||
/// If the requested buffer can't be allocated, the function will return
|
||||
/// false.
|
||||
virtual bool Allocate(GfVec3i const& dimensions,
|
||||
HdFormat format,
|
||||
bool multiSampled) = 0;
|
||||
|
||||
/// Get the buffer's width.
|
||||
virtual unsigned int GetWidth() const = 0;
|
||||
/// Get the buffer's height.
|
||||
virtual unsigned int GetHeight() const = 0;
|
||||
/// Get the buffer's depth.
|
||||
virtual unsigned int GetDepth() const = 0;
|
||||
/// Get the buffer's per-pixel format.
|
||||
virtual HdFormat GetFormat() const = 0;
|
||||
/// Get whether the buffer is multisampled.
|
||||
virtual bool IsMultiSampled() const = 0;
|
||||
|
||||
/// Map the buffer for reading.
|
||||
virtual void* Map() = 0;
|
||||
/// Unmap the buffer. It is no longer safe to read from the buffer.
|
||||
virtual void Unmap() = 0;
|
||||
/// Return whether the buffer is currently mapped by anybody.
|
||||
virtual bool IsMapped() const = 0;
|
||||
|
||||
/// Resolve the buffer so that reads reflect the latest writes.
|
||||
///
|
||||
/// Some buffer implementations may defer final processing of writes until
|
||||
/// a buffer is read, for efficiency; examples include OpenGL MSAA or
|
||||
/// multi-sampled raytraced buffers.
|
||||
virtual void Resolve() = 0;
|
||||
|
||||
/// Return whether the buffer is converged (whether the renderer is
|
||||
/// still adding samples or not).
|
||||
virtual bool IsConverged() const = 0;
|
||||
|
||||
/// This optional API returns a (type-erased) resource that backs this
|
||||
/// render buffer. For example, a render buffer implementation may allocate
|
||||
/// a gpu texture that holds the data of the buffer. This function allows
|
||||
/// other parts of Hydra, such as a HdTask to get access to this resource.
|
||||
virtual VtValue GetResource(bool multiSampled) const {return VtValue();}
|
||||
|
||||
protected:
|
||||
/// Deallocate the buffer, freeing any owned resources.
|
||||
virtual void _Deallocate() = 0;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_RENDER_BUFFER_H
|
||||
@@ -0,0 +1,127 @@
|
||||
//
|
||||
// Copyright 2021 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// This file is generated by a script. Do not edit directly. Edit the
|
||||
// schema.template.h file to make changes.
|
||||
|
||||
#ifndef PXR_IMAGING_HD_RENDER_BUFFER_SCHEMA_H
|
||||
#define PXR_IMAGING_HD_RENDER_BUFFER_SCHEMA_H
|
||||
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
|
||||
#include "pxr/imaging/hd/schema.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define HDRENDERBUFFER_SCHEMA_TOKENS \
|
||||
(renderBuffer) \
|
||||
(dimensions) \
|
||||
(format) \
|
||||
(multiSampled) \
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdRenderBufferSchemaTokens, HD_API,
|
||||
HDRENDERBUFFER_SCHEMA_TOKENS);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class HdRenderBufferSchema : public HdSchema
|
||||
{
|
||||
public:
|
||||
HdRenderBufferSchema(HdContainerDataSourceHandle container)
|
||||
: HdSchema(container) {}
|
||||
|
||||
//ACCESSORS
|
||||
|
||||
HD_API
|
||||
HdVec3iDataSourceHandle GetDimensions();
|
||||
HD_API
|
||||
HdFormatDataSourceHandle GetFormat();
|
||||
HD_API
|
||||
HdBoolDataSourceHandle GetMultiSampled();
|
||||
|
||||
// RETRIEVING AND CONSTRUCTING
|
||||
|
||||
/// 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 HdVec3iDataSourceHandle &dimensions,
|
||||
const HdFormatDataSourceHandle &format,
|
||||
const HdBoolDataSourceHandle &multiSampled
|
||||
);
|
||||
|
||||
/// \class HdRenderBufferSchema::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 &SetDimensions(
|
||||
const HdVec3iDataSourceHandle &dimensions);
|
||||
HD_API
|
||||
Builder &SetFormat(
|
||||
const HdFormatDataSourceHandle &format);
|
||||
HD_API
|
||||
Builder &SetMultiSampled(
|
||||
const HdBoolDataSourceHandle &multiSampled);
|
||||
|
||||
/// Returns a container data source containing the members set thus far.
|
||||
HD_API
|
||||
HdContainerDataSourceHandle Build();
|
||||
|
||||
private:
|
||||
HdVec3iDataSourceHandle _dimensions;
|
||||
HdFormatDataSourceHandle _format;
|
||||
HdBoolDataSourceHandle _multiSampled;
|
||||
};
|
||||
|
||||
/// Retrieves a container data source with the schema's default name token
|
||||
/// "renderBuffer" from the parent container and constructs a
|
||||
/// HdRenderBufferSchema 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 HdRenderBufferSchema GetFromParent(
|
||||
const HdContainerDataSourceHandle &fromParentContainer);
|
||||
|
||||
/// 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();
|
||||
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,483 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_RENDER_DELEGATE_H
|
||||
#define PXR_IMAGING_HD_RENDER_DELEGATE_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/aov.h"
|
||||
#include "pxr/imaging/hd/changeTracker.h"
|
||||
#include "pxr/imaging/hd/command.h"
|
||||
#include "pxr/base/vt/dictionary.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class SdfPath;
|
||||
class HdRprim;
|
||||
class HdSprim;
|
||||
class HdBprim;
|
||||
class HdSceneDelegate;
|
||||
class HdRenderIndex;
|
||||
class HdRenderPass;
|
||||
class HdInstancer;
|
||||
class HdDriver;
|
||||
|
||||
using HdRenderPassSharedPtr = std::shared_ptr<class HdRenderPass>;
|
||||
using HdRenderPassStateSharedPtr = std::shared_ptr<class HdRenderPassState>;
|
||||
using HdResourceRegistrySharedPtr = std::shared_ptr<class HdResourceRegistry>;
|
||||
using HdDriverVector = std::vector<HdDriver*>;
|
||||
|
||||
///
|
||||
/// The HdRenderParam is an opaque (to core Hydra) handle, to an object
|
||||
/// that is obtained from the render delegate and passed to each prim
|
||||
/// during Sync processing.
|
||||
///
|
||||
class HdRenderParam
|
||||
{
|
||||
public:
|
||||
HdRenderParam() {}
|
||||
HD_API
|
||||
virtual ~HdRenderParam();
|
||||
|
||||
private:
|
||||
// Hydra will not attempt to copy the class.
|
||||
HdRenderParam(const HdRenderParam &) = delete;
|
||||
HdRenderParam &operator =(const HdRenderParam &) = delete;
|
||||
};
|
||||
|
||||
typedef TfHashMap<TfToken, VtValue, TfToken::HashFunctor> HdRenderSettingsMap;
|
||||
|
||||
///
|
||||
/// HdRenderSettingDescriptor represents a render setting that a render delegate
|
||||
/// wants to export (e.g. to UI).
|
||||
///
|
||||
struct HdRenderSettingDescriptor
|
||||
{
|
||||
// A human readable name.
|
||||
std::string name;
|
||||
// The key for HdRenderDelegate::SetRenderSetting/GetRenderSetting.
|
||||
TfToken key;
|
||||
// The default value.
|
||||
VtValue defaultValue;
|
||||
};
|
||||
|
||||
typedef std::vector<HdRenderSettingDescriptor> HdRenderSettingDescriptorList;
|
||||
|
||||
/// \class HdRenderDelegate
|
||||
///
|
||||
class HdRenderDelegate
|
||||
{
|
||||
public:
|
||||
HD_API
|
||||
virtual ~HdRenderDelegate();
|
||||
|
||||
///
|
||||
/// Set list of driver objects, such as a rendering context / devices.
|
||||
/// This is automatically called from HdRenderIndex when a HdDriver is
|
||||
/// provided during its construction. Default implementation does nothing.
|
||||
///
|
||||
HD_API
|
||||
virtual void SetDrivers(HdDriverVector const& drivers);
|
||||
|
||||
///
|
||||
/// Returns a list of typeId's of all supported Rprims by this render
|
||||
/// delegate.
|
||||
///
|
||||
virtual const TfTokenVector &GetSupportedRprimTypes() const = 0;
|
||||
|
||||
///
|
||||
/// Returns a list of typeId's of all supported Sprims by this render
|
||||
/// delegate.
|
||||
///
|
||||
virtual const TfTokenVector &GetSupportedSprimTypes() const = 0;
|
||||
|
||||
|
||||
///
|
||||
/// Returns a list of typeId's of all supported Bprims by this render
|
||||
/// delegate.
|
||||
///
|
||||
virtual const TfTokenVector &GetSupportedBprimTypes() const = 0;
|
||||
|
||||
///
|
||||
/// Returns an opaque handle to a render param, that in turn is
|
||||
/// passed to each prim created by the render delegate during sync
|
||||
/// processing. This avoids the need to store a global state pointer
|
||||
/// in each prim.
|
||||
///
|
||||
/// The typical lifetime of the renderParam would match that of the
|
||||
/// RenderDelegate, however the minimal lifetime is that of the Sync
|
||||
/// processing. The param maybe queried multiple times during sync.
|
||||
///
|
||||
/// A render delegate may return null for the param.
|
||||
///
|
||||
HD_API
|
||||
virtual HdRenderParam *GetRenderParam() const;
|
||||
|
||||
///
|
||||
/// Returns a shared ptr to the resource registry of the current render
|
||||
/// delegate.
|
||||
///
|
||||
virtual HdResourceRegistrySharedPtr GetResourceRegistry() const = 0;
|
||||
|
||||
///
|
||||
/// Set a custom render setting on this render delegate.
|
||||
///
|
||||
HD_API
|
||||
virtual void SetRenderSetting(TfToken const& key, VtValue const& value);
|
||||
|
||||
///
|
||||
/// Get the current value for a render setting.
|
||||
///
|
||||
HD_API
|
||||
virtual VtValue GetRenderSetting(TfToken const& key) const;
|
||||
|
||||
///
|
||||
/// Get the current value for a render setting, taking a desired type
|
||||
/// and a fallback value in case of type mismatch.
|
||||
///
|
||||
template<typename T>
|
||||
T GetRenderSetting(TfToken const& key, T const& defValue) const {
|
||||
return GetRenderSetting(key).Cast<T>().GetWithDefault(defValue);
|
||||
}
|
||||
|
||||
///
|
||||
/// Get the backend-exported render setting descriptors.
|
||||
///
|
||||
HD_API
|
||||
virtual HdRenderSettingDescriptorList GetRenderSettingDescriptors() const;
|
||||
|
||||
///
|
||||
/// Get the current version of the render settings dictionary.
|
||||
///
|
||||
HD_API
|
||||
virtual unsigned int GetRenderSettingsVersion() const;
|
||||
|
||||
///
|
||||
/// Returns an open-format dictionary of render statistics
|
||||
///
|
||||
HD_API
|
||||
virtual VtDictionary GetRenderStats() const;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
///
|
||||
/// Control of background rendering threads.
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
///
|
||||
/// Advertise whether this delegate supports pausing and resuming of
|
||||
/// background render threads. Default implementation returns false.
|
||||
///
|
||||
HD_API
|
||||
virtual bool IsPauseSupported() const;
|
||||
|
||||
///
|
||||
/// Pause all of this delegate's background rendering threads. Default
|
||||
/// implementation does nothing.
|
||||
///
|
||||
/// Returns \c true if successful.
|
||||
///
|
||||
HD_API
|
||||
virtual bool Pause();
|
||||
|
||||
///
|
||||
/// Resume all of this delegate's background rendering threads previously
|
||||
/// paused by a call to Pause. Default implementation does nothing.
|
||||
///
|
||||
/// Returns \c true if successful.
|
||||
///
|
||||
HD_API
|
||||
virtual bool Resume();
|
||||
|
||||
///
|
||||
/// Advertise whether this delegate supports stopping and restarting of
|
||||
/// background render threads. Default implementation returns false.
|
||||
///
|
||||
HD_API
|
||||
virtual bool IsStopSupported() const;
|
||||
|
||||
///
|
||||
/// Stop all of this delegate's background rendering threads. Default
|
||||
/// implementation does nothing.
|
||||
///
|
||||
/// Returns \c true if successful.
|
||||
///
|
||||
HD_API
|
||||
virtual bool Stop();
|
||||
|
||||
///
|
||||
/// Restart all of this delegate's background rendering threads previously
|
||||
/// stopped by a call to Stop. Default implementation does nothing.
|
||||
///
|
||||
/// Returns \c true if successful.
|
||||
///
|
||||
HD_API
|
||||
virtual bool Restart();
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
///
|
||||
/// Renderpass Factory
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
///
|
||||
/// Request to create a new renderpass.
|
||||
/// \param index the render index to bind to the new renderpass.
|
||||
/// \param collection the rprim collection to bind to the new renderpass.
|
||||
/// \return A shared pointer to the new renderpass or empty on error.
|
||||
///
|
||||
virtual HdRenderPassSharedPtr CreateRenderPass(HdRenderIndex *index,
|
||||
HdRprimCollection const& collection) = 0;
|
||||
|
||||
///
|
||||
/// Request to create a new renderpass state.
|
||||
/// The default implementation creates an HdRenderPassState instance,
|
||||
/// but derived render delegates may instantiate their own state type.
|
||||
/// \param shader The render pass shader to use. If null, a new
|
||||
/// HdRenderPassShared will be created.
|
||||
/// \return A shared pointer to the new renderpass state.
|
||||
///
|
||||
HD_API
|
||||
virtual HdRenderPassStateSharedPtr CreateRenderPassState() const;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
///
|
||||
/// Instancer Factory
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
///
|
||||
/// Request to create a new instancer.
|
||||
/// \param id The unique identifier of this instancer.
|
||||
/// \return A pointer to the new instancer or nullptr on error.
|
||||
///
|
||||
virtual HdInstancer *CreateInstancer(HdSceneDelegate *delegate,
|
||||
SdfPath const& id) = 0;
|
||||
|
||||
virtual void DestroyInstancer(HdInstancer *instancer) = 0;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
///
|
||||
/// Prim Factories
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
///
|
||||
/// Request to Allocate and Construct a new Rprim.
|
||||
/// \param typeId the type identifier of the prim to allocate
|
||||
/// \param rprimId a unique identifier for the prim
|
||||
/// \return A pointer to the new prim or nullptr on error.
|
||||
///
|
||||
virtual HdRprim *CreateRprim(TfToken const& typeId,
|
||||
SdfPath const& rprimId) = 0;
|
||||
|
||||
///
|
||||
/// Request to Destruct and deallocate the prim.
|
||||
///
|
||||
virtual void DestroyRprim(HdRprim *rPrim) = 0;
|
||||
|
||||
///
|
||||
/// Request to Allocate and Construct a new Sprim.
|
||||
/// \param typeId the type identifier of the prim to allocate
|
||||
/// \param sprimId a unique identifier for the prim
|
||||
/// \return A pointer to the new prim or nullptr on error.
|
||||
///
|
||||
virtual HdSprim *CreateSprim(TfToken const& typeId,
|
||||
SdfPath const& sprimId) = 0;
|
||||
|
||||
///
|
||||
/// Request to Allocate and Construct an Sprim to use as a standin, if there
|
||||
/// if an error with another another Sprim of the same type. For example,
|
||||
/// if another prim references a non-exisiting Sprim, the fallback could
|
||||
/// be used.
|
||||
///
|
||||
/// \param typeId the type identifier of the prim to allocate
|
||||
/// \return A pointer to the new prim or nullptr on error.
|
||||
///
|
||||
virtual HdSprim *CreateFallbackSprim(TfToken const& typeId) = 0;
|
||||
|
||||
///
|
||||
/// Request to Destruct and deallocate the prim.
|
||||
///
|
||||
virtual void DestroySprim(HdSprim *sprim) = 0;
|
||||
|
||||
///
|
||||
/// Request to Allocate and Construct a new Bprim.
|
||||
/// \param typeId the type identifier of the prim to allocate
|
||||
/// \param sprimId a unique identifier for the prim
|
||||
/// \return A pointer to the new prim or nullptr on error.
|
||||
///
|
||||
virtual HdBprim *CreateBprim(TfToken const& typeId,
|
||||
SdfPath const& bprimId) = 0;
|
||||
|
||||
|
||||
///
|
||||
/// Request to Allocate and Construct a Bprim to use as a standin, if there
|
||||
/// if an error with another another Bprim of the same type. For example,
|
||||
/// if another prim references a non-exisiting Bprim, the fallback could
|
||||
/// be used.
|
||||
///
|
||||
/// \param typeId the type identifier of the prim to allocate
|
||||
/// \return A pointer to the new prim or nullptr on error.
|
||||
///
|
||||
virtual HdBprim *CreateFallbackBprim(TfToken const& typeId) = 0;
|
||||
|
||||
///
|
||||
/// Request to Destruct and deallocate the prim.
|
||||
///
|
||||
virtual void DestroyBprim(HdBprim *bprim) = 0;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
///
|
||||
/// Sync, Execute & Dispatch Hooks
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
///
|
||||
/// Notification point from the Engine to the delegate.
|
||||
/// This notification occurs after all Sync's have completed and
|
||||
/// before task execution.
|
||||
///
|
||||
/// This notification gives the Render Delegate a chance to
|
||||
/// update and move memory that the render may need.
|
||||
///
|
||||
/// For example, the render delegate might fill primvar buffers or texture
|
||||
/// memory.
|
||||
///
|
||||
virtual void CommitResources(HdChangeTracker *tracker) = 0;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
///
|
||||
/// Materials
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
///
|
||||
/// Returns a token that indicates material bindings should be used,
|
||||
/// based on the indicated purpose. The default purpose is
|
||||
/// HdTokens->preview.
|
||||
///
|
||||
HD_API
|
||||
virtual TfToken GetMaterialBindingPurpose() const;
|
||||
|
||||
|
||||
/// \deprecated use GetMaterialRenderContexts()
|
||||
HD_API
|
||||
virtual TfToken GetMaterialNetworkSelector() const;
|
||||
|
||||
///
|
||||
/// Returns a list, in descending order of preference, that can be used to
|
||||
/// select among multiple material network implementations. The default
|
||||
/// list contains an empty token.
|
||||
///
|
||||
HD_API
|
||||
virtual TfTokenVector GetMaterialRenderContexts() const;
|
||||
|
||||
///
|
||||
/// Return true to indicate that the render delegate wants rprim primvars
|
||||
/// to be filtered by the scene delegate to reduce the amount of primvars
|
||||
/// that are send to the render delegate. For example the scene delegate
|
||||
/// may check the bound material primvar requirements and send only those
|
||||
/// to the render delegate. Return false to not apply primvar filtering in
|
||||
/// the scene delegate. Defaults to false.
|
||||
///
|
||||
HD_API
|
||||
virtual bool IsPrimvarFilteringNeeded() const;
|
||||
|
||||
///
|
||||
/// Returns the ordered list of shader source types that the render delegate
|
||||
/// supports.
|
||||
///
|
||||
HD_API
|
||||
virtual TfTokenVector GetShaderSourceTypes() const;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
///
|
||||
/// AOVs
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
///
|
||||
/// Returns a default AOV descriptor for the given named AOV, specifying
|
||||
/// things like preferred format.
|
||||
///
|
||||
HD_API
|
||||
virtual HdAovDescriptor GetDefaultAovDescriptor(TfToken const& name) const;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
///
|
||||
/// Commands API
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
///
|
||||
/// Get the descriptors for the commands supported by this render delegate.
|
||||
///
|
||||
HD_API
|
||||
virtual HdCommandDescriptors GetCommandDescriptors() const;
|
||||
|
||||
///
|
||||
/// Invokes the command described by the token \p command with optional
|
||||
/// \p args.
|
||||
///
|
||||
/// If the command succeeds, returns \c true, otherwise returns \c false.
|
||||
/// A command will generally fail if it is not among those returned by
|
||||
/// GetCommandDescriptors().
|
||||
///
|
||||
HD_API
|
||||
virtual bool InvokeCommand(
|
||||
const TfToken &command,
|
||||
const HdCommandArgs &args = HdCommandArgs());
|
||||
|
||||
|
||||
protected:
|
||||
/// This class must be derived from.
|
||||
HD_API
|
||||
HdRenderDelegate();
|
||||
/// Allow derived classes to pass construction-time render settings.
|
||||
HD_API
|
||||
HdRenderDelegate(HdRenderSettingsMap const& settingsMap);
|
||||
|
||||
///
|
||||
/// This class is not intended to be copied.
|
||||
///
|
||||
HdRenderDelegate(const HdRenderDelegate &) = delete;
|
||||
HdRenderDelegate &operator=(const HdRenderDelegate &) = delete;
|
||||
|
||||
HD_API
|
||||
void _PopulateDefaultSettings(
|
||||
HdRenderSettingDescriptorList const& defaultSettings);
|
||||
|
||||
/// Render settings state.
|
||||
HdRenderSettingsMap _settingsMap;
|
||||
unsigned int _settingsVersion;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif //PXR_IMAGING_HD_RENDER_DELEGATE_H
|
||||
@@ -0,0 +1,539 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_RENDER_INDEX_H
|
||||
#define PXR_IMAGING_HD_RENDER_INDEX_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/changeTracker.h"
|
||||
#include "pxr/imaging/hd/dirtyList.h"
|
||||
#include "pxr/imaging/hd/perfLog.h"
|
||||
#include "pxr/imaging/hd/primTypeIndex.h"
|
||||
#include "pxr/imaging/hd/resourceRegistry.h"
|
||||
#include "pxr/imaging/hd/sortedIds.h"
|
||||
#include "pxr/imaging/hd/tokens.h"
|
||||
|
||||
#include "pxr/imaging/hd/sceneIndex.h"
|
||||
#include "pxr/imaging/hd/legacyPrimSceneIndex.h"
|
||||
|
||||
#include "pxr/imaging/hf/perfLog.h"
|
||||
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
|
||||
#include "pxr/base/gf/vec4i.h"
|
||||
#include "pxr/base/tf/hashmap.h"
|
||||
|
||||
#include <tbb/enumerable_thread_specific.h>
|
||||
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdRprim;
|
||||
class HdSprim;
|
||||
class HdBprim;
|
||||
class HdDrawItem;
|
||||
class HdRprimCollection;
|
||||
class HdSceneDelegate;
|
||||
class HdRenderDelegate;
|
||||
class HdExtComputation;
|
||||
class VtValue;
|
||||
class HdInstancer;
|
||||
class HdDriver;
|
||||
|
||||
using HdDriverVector = std::vector<HdDriver*>;
|
||||
using HdRprimCollectionVector = std::vector<HdRprimCollection>;
|
||||
using HdTaskSharedPtr = std::shared_ptr<class HdTask>;
|
||||
using HdResourceRegistrySharedPtr = std::shared_ptr<class HdResourceRegistry>;
|
||||
using HdTaskSharedPtrVector = std::vector<HdTaskSharedPtr>;
|
||||
using HdTaskContext = std::unordered_map<TfToken,
|
||||
VtValue,
|
||||
TfToken::HashFunctor>;
|
||||
|
||||
/// \class HdRenderIndex
|
||||
///
|
||||
/// The Hydra render index is a flattened representation of the client scene
|
||||
/// graph, which may be composed of several self-contained scene graphs, each of
|
||||
/// which provides a HdSceneDelegate adapter for data access.
|
||||
///
|
||||
/// Thus, multiple HdSceneDelegate's may be tied to the same HdRenderIndex.
|
||||
///
|
||||
/// The render index, however, is tied to a single HdRenderDelegate, which
|
||||
/// handles the actual creation and deletion of Hydra scene primitives. These
|
||||
/// include geometry and non-drawable objects (such as the camera and texture
|
||||
/// buffers). The render index simply holds a handle to these primitives, and
|
||||
/// tracks any changes to them via the HdChangeTracker.
|
||||
/// It also tracks computations and tasks that may update resources and render a
|
||||
/// subset of the renderable primitives.
|
||||
///
|
||||
/// The render index orchestrates the "syncing" of scene primitives, by
|
||||
/// providing the relevant scene delegate for data access, and leaves resource
|
||||
/// management to the rendering backend (via HdResourceRegistry).
|
||||
///
|
||||
/// It also provides "execution" functionality for application facing Hydra
|
||||
/// concepts (such as HdTask/HdRenderPass) in computing the set of HdDrawItems
|
||||
/// for a given HdRprimCollection, for rendering.
|
||||
///
|
||||
/// \sa
|
||||
/// HdChangeTracker
|
||||
/// HdDrawItem
|
||||
/// HdRenderDelegate
|
||||
/// HdRprimCollection
|
||||
/// HdSceneDelegate
|
||||
///
|
||||
/// \note
|
||||
/// The current design ties a HdRenderIndex to a HdRenderDelegate.
|
||||
/// However, the HdRenderIndex isn't tied to a viewer (viewport).
|
||||
/// It is common to have multiple viewers image the composed scene (for example,
|
||||
/// with different cameras), in which case the HdRenderIndex and
|
||||
/// HdRenderDelegate are shared by the viewers.
|
||||
///
|
||||
/// If two viewers use different HdRenderDelegate's, then it may unfortunately
|
||||
/// require populating two HdRenderIndex's.
|
||||
///
|
||||
class HdRenderIndex final
|
||||
{
|
||||
public:
|
||||
typedef std::vector<HdDrawItem const*> HdDrawItemPtrVector;
|
||||
|
||||
/// Create a render index with the given render delegate.
|
||||
/// Returns null if renderDelegate is null.
|
||||
/// The render delegate and render tasks may require access to a renderer's
|
||||
/// device provided by the application. The objects can be
|
||||
/// passed in as 'drivers'. Hgi is an example of a HdDriver.
|
||||
// hgi = Hgi::CreatePlatformDefaultHgi()
|
||||
// hgiDriver = new HdDriver<Hgi*>(HgiTokens→renderDriver, hgi)
|
||||
// HdRenderIndex::New(_renderDelegate, {_hgiDriver})
|
||||
HD_API
|
||||
static HdRenderIndex* New(
|
||||
HdRenderDelegate *renderDelegate,
|
||||
HdDriverVector const& drivers);
|
||||
|
||||
HD_API
|
||||
~HdRenderIndex();
|
||||
|
||||
/// Clear all r (render), s (state) and b (buffer) prims.
|
||||
HD_API
|
||||
void Clear();
|
||||
|
||||
/// Clear all entries in the render index under
|
||||
/// the given root and belong to a specified delegate.
|
||||
///
|
||||
/// Used for example to unload a delegate.
|
||||
HD_API
|
||||
void RemoveSubtree(const SdfPath &root, HdSceneDelegate* sceneDelegate);
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// Given a prim id, returns the path of the corresponding rprim
|
||||
/// or an empty path if none is found.
|
||||
HD_API
|
||||
SdfPath GetRprimPathFromPrimId(int primId) const;
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Synchronization
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Hydra's core currently needs to know the collections used by tasks
|
||||
/// to aggregate the reprs that need to be synced for the dirty Rprims.
|
||||
///
|
||||
HD_API
|
||||
void EnqueueCollectionToSync(HdRprimCollection const &collection);
|
||||
|
||||
/// Syncs input tasks, B & S prims, (external) computations and updates the
|
||||
/// Rprim dirty list to then sync the Rprims.
|
||||
/// At the end of this step, all the resources that need to be updated have
|
||||
/// handles to their data sources.
|
||||
/// This is the first phase in Hydra's execution. See HdEngine::Execute
|
||||
HD_API
|
||||
void SyncAll(HdTaskSharedPtrVector *tasks, HdTaskContext *taskContext);
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Execution
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Returns a list of relevant draw items that match the criteria specified
|
||||
// by renderTags and collection.
|
||||
/// The is typically called during render pass execution, which is the
|
||||
/// final phase in the Hydra's execution. See HdRenderPass::Execute
|
||||
HD_API
|
||||
HdDrawItemPtrVector GetDrawItems(HdRprimCollection const& collection,
|
||||
TfTokenVector const& renderTags);
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Change Tracker
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
HdChangeTracker& GetChangeTracker() { return _tracker; }
|
||||
HdChangeTracker const& GetChangeTracker() const { return _tracker; }
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Renderable prims (e.g. meshes, basis curves)
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Returns whether the rprim type is supported by this render index.
|
||||
HD_API
|
||||
bool IsRprimTypeSupported(TfToken const& typeId) const;
|
||||
|
||||
/// Insert a rprim into index
|
||||
HD_API
|
||||
void InsertRprim(TfToken const& typeId,
|
||||
HdSceneDelegate* sceneDelegate,
|
||||
SdfPath const& rprimId);
|
||||
|
||||
/// Remove a rprim from index
|
||||
HD_API
|
||||
void RemoveRprim(SdfPath const& id);
|
||||
|
||||
/// Returns true if rprim \p id exists in index.
|
||||
bool HasRprim(SdfPath const& id) {
|
||||
return _rprimMap.find(id) != _rprimMap.end();
|
||||
}
|
||||
|
||||
/// Returns the rprim of id
|
||||
HD_API
|
||||
HdRprim const *GetRprim(SdfPath const &id) const;
|
||||
|
||||
/// Returns the scene delegate for the given rprim
|
||||
HD_API
|
||||
HdSceneDelegate *GetSceneDelegateForRprim(SdfPath const &id) const;
|
||||
|
||||
/// Query function to return the id's of the scene delegate and instancer
|
||||
/// associated with the Rprim at the given path.
|
||||
HD_API
|
||||
bool GetSceneDelegateAndInstancerIds(SdfPath const &id,
|
||||
SdfPath* sceneDelegateId,
|
||||
SdfPath* instancerId) const;
|
||||
|
||||
/// Returns the render tag for the given rprim
|
||||
HD_API
|
||||
TfToken GetRenderTag(SdfPath const& id) const;
|
||||
|
||||
/// Returns a sorted list of all Rprims in the render index.
|
||||
/// The list is sorted by std::less<SdfPath>
|
||||
HD_API
|
||||
const SdfPathVector &GetRprimIds() { return _rprimIds.GetIds(); }
|
||||
|
||||
|
||||
/// Returns the subtree rooted under the given path.
|
||||
HD_API
|
||||
SdfPathVector GetRprimSubtree(SdfPath const& root);
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Instancer Support
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Insert an instancer into index
|
||||
HD_API
|
||||
void InsertInstancer(HdSceneDelegate* delegate,
|
||||
SdfPath const &id);
|
||||
|
||||
/// Remove an instancer from index
|
||||
HD_API
|
||||
void RemoveInstancer(SdfPath const& id);
|
||||
|
||||
/// Returns true if instancer \p id exists in index.
|
||||
bool HasInstancer(SdfPath const& id) {
|
||||
return _instancerMap.find(id) != _instancerMap.end();
|
||||
}
|
||||
|
||||
/// Returns the instancer of id
|
||||
HD_API
|
||||
HdInstancer *GetInstancer(SdfPath const &id) const;
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Task Support
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Inserts a new task into the render index with an identifier of \p id.
|
||||
template <typename T>
|
||||
void InsertTask(HdSceneDelegate* delegate, SdfPath const& id);
|
||||
|
||||
/// Removes the given task from the RenderIndex.
|
||||
HD_API
|
||||
void RemoveTask(SdfPath const& id);
|
||||
|
||||
/// Returns true if a task exists in the index with the given \p id.
|
||||
bool HasTask(SdfPath const& id) {
|
||||
return _taskMap.find(id) != _taskMap.end();
|
||||
}
|
||||
|
||||
/// Returns the task for the given \p id.
|
||||
HD_API
|
||||
HdTaskSharedPtr const& GetTask(SdfPath const& id) const;
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Scene state prims (e.g. camera, light)
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Returns whether the sprim type is supported by this render index.
|
||||
HD_API
|
||||
bool IsSprimTypeSupported(TfToken const& typeId) const;
|
||||
|
||||
/// Insert a sprim into index
|
||||
HD_API
|
||||
void InsertSprim(TfToken const& typeId,
|
||||
HdSceneDelegate* delegate,
|
||||
SdfPath const& sprimId);
|
||||
|
||||
HD_API
|
||||
void RemoveSprim(TfToken const& typeId, SdfPath const &id);
|
||||
|
||||
HD_API
|
||||
HdSprim *GetSprim(TfToken const& typeId, SdfPath const &id) const;
|
||||
|
||||
/// Returns the subtree rooted under the given path for the given sprim
|
||||
/// type.
|
||||
HD_API
|
||||
SdfPathVector GetSprimSubtree(TfToken const& typeId,
|
||||
SdfPath const& root);
|
||||
|
||||
/// Returns the fullback prim for the Sprim of the given type.
|
||||
HD_API
|
||||
HdSprim *GetFallbackSprim(TfToken const& typeId) const;
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Buffer prims (e.g. textures, buffers)
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Returns whether the bprim type is supported by this render index.
|
||||
HD_API
|
||||
bool IsBprimTypeSupported(TfToken const& typeId) const;
|
||||
|
||||
/// Insert a bprim into index
|
||||
HD_API
|
||||
void InsertBprim(TfToken const& typeId,
|
||||
HdSceneDelegate* delegate,
|
||||
SdfPath const& bprimId);
|
||||
|
||||
HD_API
|
||||
void RemoveBprim(TfToken const& typeId, SdfPath const &id);
|
||||
|
||||
HD_API
|
||||
HdBprim *GetBprim(TfToken const& typeId, SdfPath const &id) const;
|
||||
|
||||
/// Returns the subtree rooted under the given path for the given bprim
|
||||
/// type.
|
||||
HD_API
|
||||
SdfPathVector GetBprimSubtree(TfToken const& typeId,
|
||||
SdfPath const& root);
|
||||
|
||||
/// Returns the fallback prim for the Bprim of the given type.
|
||||
HD_API
|
||||
HdBprim *GetFallbackBprim(TfToken const& typeId) const;
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Render Delegate
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// Currently, a render index only supports connection to one type of
|
||||
/// render delegate, due to the inserted information and change tracking
|
||||
/// being specific to that delegate type.
|
||||
HD_API
|
||||
HdRenderDelegate *GetRenderDelegate() const;
|
||||
|
||||
// The render delegate may require access to a render context / device
|
||||
// that is provided by the application.
|
||||
HD_API
|
||||
HdDriverVector const& GetDrivers() const;
|
||||
|
||||
/// Returns a shared ptr to the resource registry of the current render
|
||||
/// delegate.
|
||||
HD_API
|
||||
HdResourceRegistrySharedPtr GetResourceRegistry() const;
|
||||
|
||||
private:
|
||||
// The render index constructor is private so we can check
|
||||
// renderDelegate before construction: see HdRenderIndex::New(...).
|
||||
HdRenderIndex(
|
||||
HdRenderDelegate *renderDelegate,
|
||||
HdDriverVector const& drivers);
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
// Private Helper methods
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
// Go through all RPrims and reallocate their instance ids
|
||||
// This is called once we have exhausted all all 24bit instance ids.
|
||||
void _CompactPrimIds();
|
||||
|
||||
// Allocate the next available instance id to the prim
|
||||
void _AllocatePrimId(HdRprim* prim);
|
||||
|
||||
// Inserts the task into the index and updates tracking state.
|
||||
// _TrackDelegateTask is called by the inlined InsertTask<T>, so it needs
|
||||
// to be marked HD_API.
|
||||
HD_API
|
||||
void _TrackDelegateTask(HdSceneDelegate* delegate,
|
||||
SdfPath const& taskId,
|
||||
HdTaskSharedPtr const& task);
|
||||
|
||||
template <typename T>
|
||||
static inline const TfToken & _GetTypeId();
|
||||
|
||||
|
||||
// Private versions of equivalent public methods which insert and remove
|
||||
// from this render index.
|
||||
//
|
||||
// The public versions check to see if scene delegate emulation is active.
|
||||
// If not, they call through to these. Otherwise, they forward to the
|
||||
// the HdLegacyPrimSceneIndex member. If a legacy render delegate is also
|
||||
// in use, the scene index chain will terminate with a
|
||||
// HdSceneIndexAdapterSceneDelegate. That will call the private versions
|
||||
// directly so that the internal render index tables are updated.
|
||||
//
|
||||
// This prevents cyclic insertion/removals while allowing a single
|
||||
// HdRenderIndex to be used for both front and back-end emulation.
|
||||
//
|
||||
// Note: all render index users should call the public APIs; only
|
||||
// sceneIndexAdapterSceneDelegate.cpp should call these versions, to keep
|
||||
// state synchronized. Note, for example, that _RemoveSubtree and _Clear
|
||||
// don't affect the task map, since tasks aren't part of emulation, whereas
|
||||
// RemoveSubtree and Clear do affect the task map...
|
||||
friend class HdSceneIndexAdapterSceneDelegate;
|
||||
void _InsertRprim(TfToken const& typeId,
|
||||
HdSceneDelegate* sceneDelegate,
|
||||
SdfPath const& rprimId);
|
||||
void _InsertSprim(TfToken const& typeId,
|
||||
HdSceneDelegate* delegate,
|
||||
SdfPath const& sprimId);
|
||||
void _InsertBprim(TfToken const& typeId,
|
||||
HdSceneDelegate* delegate,
|
||||
SdfPath const& bprimId);
|
||||
void _InsertInstancer(HdSceneDelegate* delegate,
|
||||
SdfPath const &id);
|
||||
|
||||
void _RemoveRprim(SdfPath const& id);
|
||||
void _RemoveSprim(TfToken const& typeId, SdfPath const& id);
|
||||
void _RemoveBprim(TfToken const& typeId, SdfPath const& id);
|
||||
void _RemoveInstancer(SdfPath const& id);
|
||||
void _RemoveSubtree(SdfPath const& id, HdSceneDelegate* sceneDelegate);
|
||||
void _RemoveRprimSubtree(const SdfPath &root,
|
||||
HdSceneDelegate* sceneDelegate);
|
||||
void _RemoveInstancerSubtree(const SdfPath &root,
|
||||
HdSceneDelegate* sceneDelegate);
|
||||
void _RemoveExtComputationSubtree(const SdfPath &root,
|
||||
HdSceneDelegate* sceneDelegate);
|
||||
void _RemoveTaskSubtree(const SdfPath &root,
|
||||
HdSceneDelegate* sceneDelegate);
|
||||
void _Clear();
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
// Index State
|
||||
// ---------------------------------------------------------------------- //
|
||||
struct _RprimInfo {
|
||||
HdSceneDelegate *sceneDelegate;
|
||||
HdRprim *rprim;
|
||||
};
|
||||
|
||||
HdLegacyPrimSceneIndexRefPtr _emulationSceneIndex;
|
||||
std::unique_ptr<class HdSceneIndexAdapterSceneDelegate> _siSd;
|
||||
|
||||
struct _TaskInfo {
|
||||
HdSceneDelegate *sceneDelegate;
|
||||
HdTaskSharedPtr task;
|
||||
};
|
||||
|
||||
typedef std::unordered_map<SdfPath, _TaskInfo, SdfPath::Hash> _TaskMap;
|
||||
typedef TfHashMap<SdfPath, _RprimInfo, SdfPath::Hash> _RprimMap;
|
||||
typedef std::vector<SdfPath> _RprimPrimIDVector;
|
||||
|
||||
typedef Hd_PrimTypeIndex<HdSprim> _SprimIndex;
|
||||
typedef Hd_PrimTypeIndex<HdBprim> _BprimIndex;
|
||||
|
||||
_RprimMap _rprimMap;
|
||||
Hd_SortedIds _rprimIds;
|
||||
|
||||
_RprimPrimIDVector _rprimPrimIdMap;
|
||||
|
||||
_TaskMap _taskMap;
|
||||
|
||||
_SprimIndex _sprimIndex;
|
||||
_BprimIndex _bprimIndex;
|
||||
|
||||
HdChangeTracker _tracker;
|
||||
|
||||
typedef TfHashMap<SdfPath, HdInstancer*, SdfPath::Hash> _InstancerMap;
|
||||
_InstancerMap _instancerMap;
|
||||
|
||||
HdRenderDelegate *_renderDelegate;
|
||||
HdDriverVector _drivers;
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
// Sync State
|
||||
// ---------------------------------------------------------------------- //
|
||||
HdRprimCollectionVector _collectionsToSync;
|
||||
HdDirtyList _rprimDirtyList;
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Register the render delegate's list of supported prim types.
|
||||
void _InitPrimTypes();
|
||||
|
||||
/// Creates fallback prims for each supported prim type.
|
||||
bool _CreateFallbackPrims();
|
||||
|
||||
/// Release the fallback prims.
|
||||
void _DestroyFallbackPrims();
|
||||
|
||||
typedef tbb::enumerable_thread_specific<HdDrawItemPtrVector>
|
||||
_ConcurrentDrawItems;
|
||||
|
||||
void _AppendDrawItems(const SdfPathVector &rprimIds,
|
||||
size_t begin,
|
||||
size_t end,
|
||||
HdRprimCollection const& collection,
|
||||
_ConcurrentDrawItems* result);
|
||||
|
||||
/// Register core hydra reprs. Only ever called once, the first time
|
||||
/// a render index is created.
|
||||
/// XXX: This code should move to the application layer.
|
||||
static void _ConfigureReprs();
|
||||
|
||||
// Remove default constructor
|
||||
HdRenderIndex() = delete;
|
||||
|
||||
// Don't allow copies
|
||||
HdRenderIndex(const HdRenderIndex &) = delete;
|
||||
HdRenderIndex &operator=(const HdRenderIndex &) = delete;
|
||||
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
void
|
||||
HdRenderIndex::InsertTask(HdSceneDelegate* delegate, SdfPath const& id)
|
||||
{
|
||||
HD_TRACE_FUNCTION();
|
||||
HF_MALLOC_TAG_FUNCTION();
|
||||
|
||||
HdTaskSharedPtr task = std::make_shared<T>(delegate, id);
|
||||
_TrackDelegateTask(delegate, id, task);
|
||||
}
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif //PXR_IMAGING_HD_RENDER_INDEX_H
|
||||
@@ -0,0 +1,144 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_RENDER_PASS_H
|
||||
#define PXR_IMAGING_HD_RENDER_PASS_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/rprimCollection.h"
|
||||
#include "pxr/imaging/hd/task.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdRenderIndex;
|
||||
class HdSceneDelegate;
|
||||
|
||||
using HdRenderPassSharedPtr = std::shared_ptr<class HdRenderPass>;
|
||||
using HdRenderPassStateSharedPtr = std::shared_ptr<class HdRenderPassState>;
|
||||
|
||||
/// \class HdRenderPass
|
||||
///
|
||||
/// An abstract class representing a single render iteration over a set of prims
|
||||
/// (the HdRprimCollection), for the camera/viewport parameters in
|
||||
/// HdRenderPassState.
|
||||
///
|
||||
/// Conceptually, a rendering task may be broken down into one or more
|
||||
/// HdRenderPass(es).
|
||||
///
|
||||
/// An HdRenderPass has two phases, Sync() and Execute(), in line with Hydra's
|
||||
/// execution phases (See HdEngine::Execute)
|
||||
///
|
||||
/// The base class implementation of Sync() takes care of syncing collection
|
||||
/// changes with the HdRenderIndex via HdDirtyList, and allows derived classes
|
||||
/// to track collection changes (via _MarkCollectionDirty) and sync additional
|
||||
/// resources (via _Sync)
|
||||
///
|
||||
/// Renderer backends implement _Execute, wherein the HdDrawItem(s) for the
|
||||
/// collection may be consumed via HdRenderIndex::GetDrawItems.
|
||||
/// Typically, the HdRenderPassState argument of _Execute is made available via
|
||||
/// the HdTaskContext.
|
||||
///
|
||||
/// \note
|
||||
/// Rendering backends are expected to specialize this abstract class, and
|
||||
/// return the specialized object via HdRenderDelegate::CreateRenderPass
|
||||
///
|
||||
class HdRenderPass
|
||||
{
|
||||
public:
|
||||
HD_API
|
||||
HdRenderPass(HdRenderIndex *index, HdRprimCollection const& collection);
|
||||
HD_API
|
||||
virtual ~HdRenderPass();
|
||||
|
||||
/// Returns the HdRprimCollection to be drawn by this RenderPass.
|
||||
HdRprimCollection const& GetRprimCollection() const { return _collection; }
|
||||
|
||||
/// Sets the HdRprimCollection, note that this may invalidate internal
|
||||
/// caches used to accelerate drawing.
|
||||
HD_API
|
||||
void SetRprimCollection(HdRprimCollection const& col);
|
||||
|
||||
/// Return the render index
|
||||
HdRenderIndex* GetRenderIndex() const { return _renderIndex; }
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Synchronization
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Sync the render pass resources
|
||||
HD_API
|
||||
void Sync();
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Execution
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Execute a subset of buckets of this renderpass.
|
||||
HD_API
|
||||
void Execute(HdRenderPassStateSharedPtr const &renderPassState,
|
||||
TfTokenVector const &renderTags);
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Optional API hooks for progressive rendering
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
virtual bool IsConverged() const { return true; }
|
||||
|
||||
protected:
|
||||
/// Virtual API: Execute the buckets corresponding to renderTags;
|
||||
/// renderTags.empty() implies execute everything.
|
||||
virtual void _Execute(HdRenderPassStateSharedPtr const &renderPassState,
|
||||
TfTokenVector const &renderTags) = 0;
|
||||
|
||||
/// Optional API: let derived classes mark their collection tracking as dirty.
|
||||
virtual void _MarkCollectionDirty() {}
|
||||
|
||||
/// Optional API: let derived classes sync data.
|
||||
virtual void _Sync() {}
|
||||
|
||||
private:
|
||||
|
||||
// Don't allow copies
|
||||
HdRenderPass(const HdRenderPass &) = delete;
|
||||
HdRenderPass &operator=(const HdRenderPass &) = delete;
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
// \name Change Tracking State
|
||||
// ---------------------------------------------------------------------- //
|
||||
// The renderIndex to which this renderPass belongs
|
||||
// (can't change after construction)
|
||||
HdRenderIndex * const _renderIndex;
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
// \name Core RenderPass State
|
||||
// ---------------------------------------------------------------------- //
|
||||
HdRprimCollection _collection;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif //PXR_IMAGING_HD_RENDER_PASS_H
|
||||
@@ -0,0 +1,421 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_RENDER_PASS_STATE_H
|
||||
#define PXR_IMAGING_HD_RENDER_PASS_STATE_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/aov.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/enums.h"
|
||||
|
||||
#include "pxr/imaging/cameraUtil/framing.h"
|
||||
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
|
||||
#include "pxr/base/tf/token.h"
|
||||
#include "pxr/base/vt/value.h"
|
||||
#include "pxr/base/gf/matrix4d.h"
|
||||
#include "pxr/base/gf/vec2f.h"
|
||||
#include "pxr/base/gf/vec4d.h"
|
||||
#include "pxr/base/gf/vec4f.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
using HdRenderPassStateSharedPtr = std::shared_ptr<class HdRenderPassState>;
|
||||
using HdResourceRegistrySharedPtr = std::shared_ptr<class HdResourceRegistry>;
|
||||
|
||||
class HdCamera;
|
||||
|
||||
/// \class HdRenderPassState
|
||||
///
|
||||
/// A set of rendering parameters used among render passes.
|
||||
///
|
||||
/// Parameters are expressed as GL states, uniforms or shaders.
|
||||
///
|
||||
class HdRenderPassState
|
||||
{
|
||||
public:
|
||||
HD_API
|
||||
HdRenderPassState();
|
||||
HD_API
|
||||
virtual ~HdRenderPassState();
|
||||
|
||||
/// Schedule to update renderPassState parameters.
|
||||
/// e.g. camera matrix, override color, id blend factor.
|
||||
/// Prepare, called once per frame after the sync phase, but prior to
|
||||
/// the commit phase.
|
||||
HD_API
|
||||
virtual void Prepare(HdResourceRegistrySharedPtr const &resourceRegistry);
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Camera and framing state
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
using ClipPlanesVector = std::vector<GfVec4d>;
|
||||
|
||||
/// Camera setter API
|
||||
///
|
||||
/// Sets the camera transform (aka view inverse matrix) and physical
|
||||
/// parameters, the framing information and a possible overide value
|
||||
/// for the window policy used to conform the camera frustum if its
|
||||
/// aspect ratio is not matching the display window.
|
||||
///
|
||||
/// Note: using std::pair<bool, ...> here instead of std::optional<...>
|
||||
/// since the latter is only available in C++17 or later.
|
||||
HD_API
|
||||
void SetCameraAndFraming(
|
||||
HdCamera const *camera,
|
||||
CameraUtilFraming const &framing,
|
||||
const std::pair<bool, CameraUtilConformWindowPolicy> &
|
||||
overrideWindowPolicy);
|
||||
|
||||
/// Get camera
|
||||
HdCamera const *
|
||||
GetCamera() const { return _camera; }
|
||||
|
||||
/// Get framing information determining how the filmback plane maps
|
||||
/// to pixels.
|
||||
const CameraUtilFraming &
|
||||
GetFraming() const { return _framing; }
|
||||
|
||||
/// The override value for the window policy to conform the camera
|
||||
/// frustum that can be specified by the application.
|
||||
const std::pair<bool, CameraUtilConformWindowPolicy> &
|
||||
GetOverrideWindowPolicy() const { return _overrideWindowPolicy; }
|
||||
|
||||
/// The resolved window policy to conform the camera frustum.
|
||||
/// This is either the override value specified by the application or
|
||||
/// the value from the scene delegate's camera.
|
||||
HD_API
|
||||
CameraUtilConformWindowPolicy
|
||||
GetWindowPolicy() const;
|
||||
|
||||
/// Camera setter API
|
||||
/// The view, projection and clipping plane info of the camera will be used.
|
||||
///
|
||||
/// \deprecated Use the more expressive SetCameraAndFraming instead.
|
||||
HD_API
|
||||
void SetCameraAndViewport(HdCamera const *camera,
|
||||
GfVec4d const& viewport);
|
||||
/// Camera getter API
|
||||
///
|
||||
/// For backwards compatibility, use the worldToView matrix of the HdCamera
|
||||
/// if given. Otherwise, use the HdCamera's transform.
|
||||
///
|
||||
/// The HdRenderPassState also has a fallback value for the view
|
||||
/// matrix that is used if no HdCamera was specified, that can be set with,
|
||||
/// e.g.g, HdStRenderPassState::SetCameraFramingState.
|
||||
///
|
||||
HD_API
|
||||
GfMatrix4d GetWorldToViewMatrix() const;
|
||||
|
||||
/// It is expected that an HdCamera was specified that has physically based
|
||||
/// attributes. The projection matrix is computed from those attributes and
|
||||
/// the conform window policy is applied.
|
||||
///
|
||||
/// For backwards compatibility with scene and render delegates:
|
||||
/// if the HdCamera has no physically based attributes (more precisely,
|
||||
/// the scene delegate provided a VtValue for focalLength that is either
|
||||
/// empty or 1.0f), the HdCamera's projection matrix is used.
|
||||
/// The HdRenderPassState also has a fallback value for the projection
|
||||
/// matrix that is used if no HdCamera was specified, that can be set with,
|
||||
/// e.g.g, HdStRenderPassState::SetCameraFramingState.
|
||||
///
|
||||
HD_API
|
||||
GfMatrix4d GetProjectionMatrix() const;
|
||||
|
||||
/// Only use when clients did not specify a camera framing.
|
||||
///
|
||||
/// \deprecated
|
||||
GfVec4f const & GetViewport() const { return _viewport; }
|
||||
|
||||
HD_API
|
||||
ClipPlanesVector const & GetClipPlanes() const;
|
||||
|
||||
GfMatrix4d GetCullMatrix() const { return _cullMatrix; }
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Application rendering state
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Set an override color for rendering where the R, G and B components
|
||||
/// are the color and the alpha component is the blend value
|
||||
HD_API
|
||||
void SetOverrideColor(GfVec4f const &color);
|
||||
const GfVec4f& GetOverrideColor() const { return _overrideColor; }
|
||||
|
||||
/// Set a wireframe color for rendering where the R, G and B components
|
||||
/// are the color and the alpha component is the blend value
|
||||
HD_API
|
||||
void SetWireframeColor(GfVec4f const &color);
|
||||
const GfVec4f& GetWireframeColor() const { return _wireframeColor; }
|
||||
|
||||
HD_API
|
||||
void SetMaskColor(GfVec4f const &color);
|
||||
const GfVec4f& GetMaskColor() const { return _maskColor; }
|
||||
|
||||
HD_API
|
||||
void SetIndicatorColor(GfVec4f const &color);
|
||||
const GfVec4f& GetIndicatorColor() const { return _indicatorColor; }
|
||||
|
||||
/// Set a point color for rendering where the R, G and B components
|
||||
/// are the color and the alpha component is the blend value
|
||||
HD_API
|
||||
void SetPointColor(GfVec4f const &color);
|
||||
const GfVec4f& GetPointColor() const { return _pointColor; }
|
||||
|
||||
/// Set the point size for unselected points.
|
||||
HD_API
|
||||
void SetPointSize(float size);
|
||||
float GetPointSize() const { return _pointSize; }
|
||||
|
||||
/// Set the point size for selected points.
|
||||
HD_API
|
||||
void SetPointSelectedSize(float size);
|
||||
float GetPointSelectedSize() const { return _pointSelectedSize; }
|
||||
|
||||
/// XXX: Hacky way of disabling lighting
|
||||
HD_API
|
||||
void SetLightingEnabled(bool enabled);
|
||||
bool GetLightingEnabled() const { return _lightingEnabled; }
|
||||
|
||||
HD_API
|
||||
void SetClippingEnabled(bool enabled);
|
||||
bool GetClippingEnabled() const { return _clippingEnabled; }
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Render pipeline state
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
/// Set the attachments for this renderpass to render into.
|
||||
HD_API
|
||||
void SetAovBindings(HdRenderPassAovBindingVector const &aovBindings);
|
||||
HD_API
|
||||
HdRenderPassAovBindingVector const& GetAovBindings() const;
|
||||
|
||||
/// Set the AOVs that this renderpass needs to read from.
|
||||
HD_API
|
||||
void SetAovInputBindings(HdRenderPassAovBindingVector const &aovBindings);
|
||||
HD_API
|
||||
HdRenderPassAovBindingVector const& GetAovInputBindings() const;
|
||||
|
||||
/// Returns true if the render pass wants to render into the multi-sample
|
||||
/// aovs. Returns false if the render wants to render into the resolve aovs.
|
||||
HD_API
|
||||
void SetUseAovMultiSample(bool state);
|
||||
HD_API
|
||||
bool GetUseAovMultiSample() const;
|
||||
|
||||
HD_API
|
||||
void SetCullStyle(HdCullStyle cullStyle);
|
||||
HD_API
|
||||
HdCullStyle GetCullStyle() const { return _cullStyle; }
|
||||
|
||||
HD_API
|
||||
void SetAlphaThreshold(float alphaThreshold);
|
||||
float GetAlphaThreshold() const { return _alphaThreshold; }
|
||||
|
||||
HD_API
|
||||
void SetTessLevel(float level);
|
||||
float GetTessLevel() const { return _tessLevel; }
|
||||
|
||||
HD_API
|
||||
void SetDrawingRange(GfVec2f const &drawRange);
|
||||
GfVec2f GetDrawingRange() const { return _drawRange; } // in pixel
|
||||
GfVec2f GetDrawingRangeNDC() const { // in ndc
|
||||
return GfVec2f(2*_drawRange[0]/_viewport[2],
|
||||
2*_drawRange[1]/_viewport[3]);
|
||||
}
|
||||
|
||||
HD_API
|
||||
void SetDepthBiasUseDefault(bool useDefault);
|
||||
bool GetDepthBiasUseDefault() const { return _depthBiasUseDefault; }
|
||||
|
||||
HD_API
|
||||
void SetDepthBiasEnabled(bool enabled);
|
||||
bool GetDepthBiasEnabled() const { return _depthBiasEnabled; }
|
||||
|
||||
HD_API
|
||||
void SetDepthBias(float constantFactor, float slopeFactor);
|
||||
|
||||
HD_API
|
||||
void SetDepthFunc(HdCompareFunction depthFunc);
|
||||
HdCompareFunction GetDepthFunc() const { return _depthFunc; }
|
||||
|
||||
HD_API
|
||||
void SetEnableDepthMask(bool state);
|
||||
HD_API
|
||||
bool GetEnableDepthMask();
|
||||
|
||||
HD_API
|
||||
void SetEnableDepthTest(bool enabled);
|
||||
HD_API
|
||||
bool GetEnableDepthTest() const;
|
||||
|
||||
HD_API
|
||||
void SetStencil(HdCompareFunction func, int ref, int mask,
|
||||
HdStencilOp fail, HdStencilOp zfail, HdStencilOp zpass);
|
||||
HdCompareFunction GetStencilFunc() const { return _stencilFunc; }
|
||||
int GetStencilRef() const { return _stencilRef; }
|
||||
int GetStencilMask() const { return _stencilMask; }
|
||||
HdStencilOp GetStencilFailOp() const { return _stencilFailOp; }
|
||||
HdStencilOp GetStencilDepthFailOp() const { return _stencilZFailOp; }
|
||||
HdStencilOp GetStencilDepthPassOp() const { return _stencilZPassOp; }
|
||||
HD_API
|
||||
void SetStencilEnabled(bool enabled);
|
||||
HD_API
|
||||
bool GetStencilEnabled() const;
|
||||
|
||||
HD_API
|
||||
void SetLineWidth(float width);
|
||||
float GetLineWidth() const { return _lineWidth; }
|
||||
|
||||
HD_API
|
||||
void SetBlend(HdBlendOp colorOp,
|
||||
HdBlendFactor colorSrcFactor,
|
||||
HdBlendFactor colorDstFactor,
|
||||
HdBlendOp alphaOp,
|
||||
HdBlendFactor alphaSrcFactor,
|
||||
HdBlendFactor alphaDstFactor);
|
||||
HdBlendOp GetBlendColorOp() { return _blendColorOp; }
|
||||
HdBlendFactor GetBlendColorSrcFactor() { return _blendColorSrcFactor; }
|
||||
HdBlendFactor GetBlendColorDstFactor() { return _blendColorDstFactor; }
|
||||
HdBlendOp GetBlendAlphaOp() { return _blendAlphaOp; }
|
||||
HdBlendFactor GetBlendAlphaSrcFactor() { return _blendAlphaSrcFactor; }
|
||||
HdBlendFactor GetBlendAlphaDstFactor() { return _blendAlphaDstFactor; }
|
||||
HD_API
|
||||
void SetBlendConstantColor(GfVec4f const & color);
|
||||
const GfVec4f& GetBlendConstantColor() const { return _blendConstantColor; }
|
||||
HD_API
|
||||
void SetBlendEnabled(bool enabled);
|
||||
|
||||
HD_API
|
||||
void SetAlphaToCoverageEnabled(bool enabled);
|
||||
bool GetAlphaToCoverageEnabled() const { return _alphaToCoverageEnabled; }
|
||||
|
||||
HD_API
|
||||
void SetColorMaskUseDefault(bool useDefault);
|
||||
bool GetColorMaskUseDefault() const { return _colorMaskUseDefault;}
|
||||
|
||||
enum ColorMask {
|
||||
ColorMaskNone,
|
||||
ColorMaskRGB,
|
||||
ColorMaskRGBA
|
||||
};
|
||||
|
||||
HD_API
|
||||
void SetColorMasks(std::vector<ColorMask> const& masks);
|
||||
std::vector<ColorMask> const& GetColorMasks() const { return _colorMasks; }
|
||||
|
||||
protected:
|
||||
// ---------------------------------------------------------------------- //
|
||||
// Camera and framing state
|
||||
// ---------------------------------------------------------------------- //
|
||||
HdCamera const *_camera;
|
||||
GfVec4f _viewport;
|
||||
CameraUtilFraming _framing;
|
||||
std::pair<bool, CameraUtilConformWindowPolicy> _overrideWindowPolicy;
|
||||
GfMatrix4d _cullMatrix; // updated during Prepare(..)
|
||||
|
||||
// Used by applications setting the view matrix directly instead of
|
||||
// using an HdCamera. Will be removed eventually.
|
||||
GfMatrix4d _worldToViewMatrix;
|
||||
// Used by applications setting the projection matrix directly instead
|
||||
// of using an HdCamera. Will be removed eventually.
|
||||
GfMatrix4d _projectionMatrix;
|
||||
// Used by applications setting the clip planes directly instead
|
||||
// of using an HdCamera. Will be removed eventually.
|
||||
ClipPlanesVector _clipPlanes;
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
// Application rendering state
|
||||
// ---------------------------------------------------------------------- //
|
||||
GfVec4f _overrideColor;
|
||||
GfVec4f _wireframeColor;
|
||||
GfVec4f _pointColor;
|
||||
float _pointSize;
|
||||
bool _lightingEnabled;
|
||||
bool _clippingEnabled;
|
||||
|
||||
GfVec4f _maskColor;
|
||||
GfVec4f _indicatorColor;
|
||||
float _pointSelectedSize;
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
// Render pipeline state
|
||||
// ---------------------------------------------------------------------- //
|
||||
float _alphaThreshold;
|
||||
float _tessLevel;
|
||||
GfVec2f _drawRange;
|
||||
|
||||
bool _depthBiasUseDefault; // inherit existing state, ignore values below.
|
||||
bool _depthBiasEnabled;
|
||||
float _depthBiasConstantFactor;
|
||||
float _depthBiasSlopeFactor;
|
||||
HdCompareFunction _depthFunc;
|
||||
bool _depthMaskEnabled;
|
||||
bool _depthTestEnabled;
|
||||
|
||||
HdCullStyle _cullStyle;
|
||||
|
||||
// Stencil RenderPassState
|
||||
HdCompareFunction _stencilFunc;
|
||||
int _stencilRef;
|
||||
int _stencilMask;
|
||||
HdStencilOp _stencilFailOp;
|
||||
HdStencilOp _stencilZFailOp;
|
||||
HdStencilOp _stencilZPassOp;
|
||||
bool _stencilEnabled;
|
||||
|
||||
// Line width
|
||||
float _lineWidth;
|
||||
|
||||
// Blending
|
||||
HdBlendOp _blendColorOp;
|
||||
HdBlendFactor _blendColorSrcFactor;
|
||||
HdBlendFactor _blendColorDstFactor;
|
||||
HdBlendOp _blendAlphaOp;
|
||||
HdBlendFactor _blendAlphaSrcFactor;
|
||||
HdBlendFactor _blendAlphaDstFactor;
|
||||
GfVec4f _blendConstantColor;
|
||||
bool _blendEnabled;
|
||||
|
||||
// alpha to coverage
|
||||
bool _alphaToCoverageEnabled;
|
||||
|
||||
bool _colorMaskUseDefault;
|
||||
std::vector<ColorMask> _colorMasks;
|
||||
|
||||
HdRenderPassAovBindingVector _aovBindings;
|
||||
HdRenderPassAovBindingVector _aovInputBindings;
|
||||
bool _useMultiSampleAov;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_RENDER_PASS_STATE_H
|
||||
@@ -0,0 +1,368 @@
|
||||
//
|
||||
// Copyright 2018 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_RENDER_THREAD_H
|
||||
#define PXR_IMAGING_HD_RENDER_THREAD_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <condition_variable>
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
/// \class HdRenderThread
|
||||
///
|
||||
/// HdRenderThread is a utility that specific render delegates can choose to
|
||||
/// use depending on their needs. It provides a system for rendering in a
|
||||
/// background thread, and synchronizing between hydra (either in the main
|
||||
/// thread, or the sync threadpool) and the rendering thread.
|
||||
///
|
||||
/// \section HdRenderThread_StateMachine State Machine
|
||||
///
|
||||
/// The render thread is implemented in terms of a state machine, and hydra
|
||||
/// requests to the render thread are implemented in terms of transitions on
|
||||
/// that state machine.
|
||||
///
|
||||
/// States:
|
||||
/// - \em StateInitial - indicates the render thread hasn't been started.
|
||||
/// - \em StateIdle - indicates the render thread is running, but not rendering.
|
||||
/// - \em StateRendering - indicates the render thread is rendering.
|
||||
/// - \em StateTerminated - indicates the render thread is shutting down.
|
||||
///
|
||||
/// Transitions:
|
||||
/// - StartThread(): StateInitial => StateIdle
|
||||
/// - StartRender(): StateIdle, StateRendering => StateRendering
|
||||
/// - StopRender(): StateIdle, StateRendering => StateIdle
|
||||
/// - StopThread(): StateIdle, StateRendering => StateTerminated
|
||||
/// - StopThread(): StateTerminated => StateInitial
|
||||
///
|
||||
/// \section HdRenderThread_Usage Example Usage
|
||||
///
|
||||
/// \code{.cpp}
|
||||
/// class ExampleRenderDelegate : HdRenderDelegate {
|
||||
/// public:
|
||||
/// ExampleRenderDelegate() {
|
||||
/// _renderThread.SetRenderCallback(
|
||||
/// std::bind(&ExampleRenderDelegate::_RenderCallback, this));
|
||||
/// _renderThread.StartThread();
|
||||
/// }
|
||||
/// ~ExampleRenderDelegate() {
|
||||
/// _renderThread.StopThread();
|
||||
/// }
|
||||
/// private:
|
||||
/// void _RenderCallback() {
|
||||
/// bool renderComplete = false;
|
||||
/// while(!renderComplete) {
|
||||
/// // Check if we have been asked to pause.
|
||||
/// while(_renderThread.IsPauseRequested()) {
|
||||
/// if(_renderThread.IsStopRequested()) {
|
||||
/// break;
|
||||
/// }
|
||||
/// std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
/// }
|
||||
/// if(_renderThread.IsStopRequested()) {
|
||||
/// break;
|
||||
/// }
|
||||
/// // generate N pixels.
|
||||
/// auto lock = _renderThread.LockFramebuffer();
|
||||
/// // resolve pixels to shared buffer.
|
||||
/// // Set renderComplete = true when finished rendering.
|
||||
/// }
|
||||
/// }
|
||||
/// HdRenderThread _renderThread;
|
||||
/// };
|
||||
///
|
||||
/// class ExampleRenderParam : HdRenderParam {
|
||||
/// public:
|
||||
/// ExampleRenderParam(HdRenderThread* renderThread, SceneData *scene);
|
||||
/// SceneData* AcquireSceneForEdit() {
|
||||
/// _renderThread->StopRender();
|
||||
/// return _scene;
|
||||
/// }
|
||||
/// };
|
||||
///
|
||||
/// class ExamplePrim : HdMesh {
|
||||
/// public:
|
||||
/// void Sync(...) {
|
||||
/// SceneData *scene = renderParam->AcquireSceneForEdit();
|
||||
/// ...
|
||||
/// }
|
||||
/// };
|
||||
///
|
||||
/// class ExampleRenderPass : HdRenderPass {
|
||||
/// public:
|
||||
/// ExampleRenderPass(HdRenderThread *renderThread);
|
||||
/// protected:
|
||||
/// void _Execute(...) {
|
||||
/// _renderThread->StartRendering();
|
||||
/// auto lock = _renderThread->LockFramebuffer();
|
||||
/// // blit pixels from shared to application buffer.
|
||||
/// }
|
||||
/// };
|
||||
/// \endcode
|
||||
///
|
||||
/// Having a locked and shared framebuffer is important if you want to avoid
|
||||
/// tearing, or if the rendering API disallows multithreaded access to buffers
|
||||
/// (for example, if your framebuffers are on a GPU). It might be unnecessary
|
||||
/// for some renderers.
|
||||
///
|
||||
/// Stopping the render only when you're about to make a scene edit means that
|
||||
/// long-running renders aren't interrupted if the scene is static. Hiding the
|
||||
/// renderer's scene data handle behind AcquireSceneForEdit helps callers
|
||||
/// use the synchronization mechanisms correctly.
|
||||
///
|
||||
/// The render is restarted at the last possible second, in the render pass,
|
||||
/// after we know scene edits are done.
|
||||
///
|
||||
/// The render callback should use IsStopRequested() as a cancellation
|
||||
/// mechanism.
|
||||
///
|
||||
class HdRenderThread {
|
||||
public:
|
||||
|
||||
HD_API
|
||||
HdRenderThread();
|
||||
|
||||
HD_API
|
||||
~HdRenderThread();
|
||||
|
||||
/// \anchor Management
|
||||
/// \name API for thread management
|
||||
///
|
||||
/// Methods to configure, start, and stop the render thread. These functions
|
||||
/// are not threadsafe.
|
||||
///
|
||||
/// @{
|
||||
|
||||
/// Set the rendering callback for the render thread to use.
|
||||
HD_API
|
||||
void SetRenderCallback(std::function<void()> renderCallback);
|
||||
|
||||
/// Set the shutdown callback for the render thread to use. This will be
|
||||
/// called once, right before the render thread exits, regardless of whether
|
||||
/// the render callback has been called. This can be used to clean up
|
||||
/// thread-specific rendering resources.
|
||||
HD_API
|
||||
void SetShutdownCallback(std::function<void()> shutdownCallback);
|
||||
|
||||
/// Start the rendering background thread.
|
||||
/// Note: it's an error to call this function when the render thread is
|
||||
/// already running, but it's acceptable to stop the render thread and then
|
||||
/// start it again.
|
||||
HD_API
|
||||
void StartThread();
|
||||
|
||||
/// Stop the rendering background thread. This function will ask the render
|
||||
/// thread to transition to StateTerminated, and then join on the thread,
|
||||
/// so it will block. After this function returns, the rendering state
|
||||
/// machine will be back in its initial state, and the render thread can be
|
||||
/// started again.
|
||||
HD_API
|
||||
void StopThread();
|
||||
|
||||
/// Check whether the background thread is running (i.e. StartThread was
|
||||
/// called successfully, but StopThread has not been).
|
||||
HD_API
|
||||
bool IsThreadRunning();
|
||||
|
||||
/// @}
|
||||
|
||||
/// \anchor HydraAPI
|
||||
/// \name API for hydra threads
|
||||
///
|
||||
/// Methods for hydra to communicate with the render thread. These methods
|
||||
/// can be called from the application thread or hydra threadpool threads.
|
||||
///
|
||||
/// @{
|
||||
|
||||
/// Ask the render thread to start rendering. This call is a no-op if the
|
||||
/// render thread is already rendering. Otherwise, it may block briefly.
|
||||
/// This is threadsafe against the render thread, but it shouldn't be
|
||||
/// called at the same time as StopRender(), and it shouldn't be called
|
||||
/// from multiple hydra threads at once.
|
||||
HD_API
|
||||
void StartRender();
|
||||
|
||||
/// Ask the render thread to stop rendering, and block until the render
|
||||
/// thread is idle. This is fully threadsafe, and can be called from
|
||||
/// multiple hydra threads at once.
|
||||
HD_API
|
||||
void StopRender();
|
||||
|
||||
/// Query whether the render thread is currently rendering. This is set by
|
||||
/// StartRender() and reset after the render callback exits, or reset by
|
||||
/// StopRender() if the render callback never runs. This does not
|
||||
/// block, and is fully threadsafe.
|
||||
HD_API
|
||||
bool IsRendering();
|
||||
|
||||
/// Ask the render thread to pause rendering. The speed at which the
|
||||
/// renderer actually enters the pause state depends on the delegate.
|
||||
HD_API
|
||||
void PauseRender();
|
||||
|
||||
/// Ask the render thread to resume rendering. Pause and Resume calls do
|
||||
/// not need to be paired. The last call (to Pause or Resume) decides the
|
||||
/// current state.
|
||||
HD_API
|
||||
void ResumeRender();
|
||||
|
||||
/// @}
|
||||
|
||||
/// \anchor RenderThreadAPI
|
||||
/// \name API for hydra threads
|
||||
///
|
||||
/// Methods for the render thread to communicate with hydra. These should
|
||||
/// only be called from the render thread, from inside the render callback.
|
||||
///
|
||||
/// @{
|
||||
|
||||
/// Query whether hydra has asked to interrupt the current frame since
|
||||
/// the last time StartRender() was called. The render callback can check
|
||||
/// this to determine whether to cancel rendering.
|
||||
HD_API
|
||||
bool IsStopRequested();
|
||||
|
||||
/// Query whether hydra has asked to pause rendering. This will continue
|
||||
/// to return true until a request has been made for rendering to resume.
|
||||
/// Remember to check for a stop request while paused.
|
||||
HD_API
|
||||
bool IsPauseRequested();
|
||||
|
||||
/// Query whether the pause/resume state has changed since the last time
|
||||
/// we called IsPauseDirty.
|
||||
HD_API
|
||||
bool IsPauseDirty();
|
||||
|
||||
/// @}
|
||||
|
||||
/// \anchor CommonAPI
|
||||
/// \name API for both hydra and render threads
|
||||
///
|
||||
/// Methods for both hydra and the render threads to synchronize access to
|
||||
/// other data.
|
||||
///
|
||||
/// @{
|
||||
|
||||
/// Return a scoped lock on the render delegate's framebuffer. Hydra and the
|
||||
/// render thread can use this to synchronize blits between render-thread
|
||||
/// owned resources, and application-owned resources.
|
||||
HD_API
|
||||
std::unique_lock<std::mutex> LockFramebuffer();
|
||||
|
||||
/// @}
|
||||
|
||||
private:
|
||||
// _RenderLoop implements the render thread's state machine; see
|
||||
// \ref HdRenderThread_StateMachine for details. It runs in a background
|
||||
// thread and manages synchronization with hydra. To implement rendering,
|
||||
// it calls out to the render callback provided via SetRenderCallback.
|
||||
void _RenderLoop();
|
||||
|
||||
// _renderCallback is the render-delegate-provided function responsible for
|
||||
// actually rendering. It's called from _RenderLoop.
|
||||
std::function<void()> _renderCallback;
|
||||
|
||||
// _shutdownCallback is the render-delegate-provided function responsible
|
||||
// for cleaning up thread-specific resources. It's called once, right
|
||||
// before _RenderLoop exits.
|
||||
std::function<void()> _shutdownCallback;
|
||||
|
||||
// A placeholder initial value for _renderCallback.
|
||||
static void _DefaultRenderCallback();
|
||||
|
||||
// A placeholder initial value for _shutdownCallback.
|
||||
static void _DefaultShutdownCallback();
|
||||
|
||||
// The state enumeration of the render thread state machine; see
|
||||
// \ref HdRenderThread_StateMachine for details.
|
||||
enum State {
|
||||
// Initial constructed state. Render thread is not running.
|
||||
StateInitial,
|
||||
// Render thread is running and ready for scene edits. No rendering
|
||||
// is taking place.
|
||||
StateIdle,
|
||||
// Render thread is running and rendering; no scene edits are allowed.
|
||||
StateRendering,
|
||||
// Render thread is shutting down.
|
||||
StateTerminated,
|
||||
};
|
||||
|
||||
// _requestedState is set by hydra to direct the render thread's state
|
||||
// machine; see \ref HdRenderThread_StateMachine for details.
|
||||
// _requestedState is protected by a mutex/condition variable combination.
|
||||
// The render thread holds _requestedStateMutex while rendering; the
|
||||
// frequency with which it can give it up is the interruption frequency.
|
||||
//
|
||||
// StartRender() and StopRender() lock and write to _requestedState.
|
||||
// _RenderLoop() locks and reads _requestedState.
|
||||
State _requestedState;
|
||||
std::mutex _requestedStateMutex;
|
||||
std::condition_variable _requestedStateCV;
|
||||
|
||||
// _enableRender provides an out-of-band way for hydra to cancel a
|
||||
// render while the render thread is still holding _requestedStateMutex.
|
||||
//
|
||||
// StartRender() and StopRender() will write true/false to _enableRender.
|
||||
// IsStopRequested() will read from _enableRender.
|
||||
std::atomic_flag _enableRender;
|
||||
// _stopRequested keeps track of whether _enableRender has gone low since
|
||||
// the last time the render callback was called (since _enableRender is
|
||||
// reset on read).
|
||||
bool _stopRequested;
|
||||
|
||||
// _pauseRender provides a properly locked boolean flag that holds the
|
||||
// current pause state of the thread. Toggled by calling PauseRender and
|
||||
// ResumeRender, tested by IsPauseRequested.
|
||||
std::atomic<bool> _pauseRender;
|
||||
|
||||
// _pauseDirty provides a properly locked boolean flag that holds the
|
||||
// current dirtyness of the pause state of the thread. Toggled by
|
||||
// calling PauseRender and ResumeRender, tested by IsPauseDirty.
|
||||
std::atomic<bool> _pauseDirty;
|
||||
|
||||
// _rendering records whether the render thread is currently inside the
|
||||
// render callback, or planning to be inside the render callback.
|
||||
// It is managed by StartRender(), StopRender(), and _RenderLoop().
|
||||
// IsRendering() will read from _rendering.
|
||||
std::atomic<bool> _rendering;
|
||||
|
||||
// _renderThread is the background render thread; it runs _RenderLoop().
|
||||
std::thread _renderThread;
|
||||
|
||||
// _frameBufferMutex protects access to the render delegate's framebuffer,
|
||||
// and provides an optional synchronization point for blits between the
|
||||
// render thread's resources and the application's resources.
|
||||
std::mutex _frameBufferMutex;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_RENDER_THREAD_H
|
||||
@@ -0,0 +1,121 @@
|
||||
//
|
||||
// Copyright 2017 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_RENDERER_PLUGIN_H
|
||||
#define PXR_IMAGING_HD_RENDERER_PLUGIN_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hf/pluginBase.h"
|
||||
#include "pxr/imaging/hd/renderDelegate.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class SdfPath;
|
||||
class HdRenderIndex;
|
||||
class HdPluginRenderDelegateUniqueHandle;
|
||||
|
||||
///
|
||||
/// This class defines a renderer plugin interface for Hydra.
|
||||
/// A renderer plugin is a dynamically discovered and loaded at run-time using
|
||||
/// the Plug system.
|
||||
///
|
||||
/// This object has singleton behavior, in that is instantiated once per
|
||||
/// library (managed by the plugin registry).
|
||||
///
|
||||
/// The class is used to factory objects that provide delegate support
|
||||
/// to other parts of the Hydra Ecosystem.
|
||||
///
|
||||
class HdRendererPlugin : public HfPluginBase {
|
||||
public:
|
||||
|
||||
///
|
||||
/// Create a render delegate through the plugin and wrap it in a
|
||||
/// handle that keeps this plugin alive until render delegate is
|
||||
/// destroyed. Initial settings can be passed in.
|
||||
///
|
||||
HD_API
|
||||
HdPluginRenderDelegateUniqueHandle CreateDelegate(
|
||||
HdRenderSettingsMap const &settingsMap = {});
|
||||
|
||||
///
|
||||
/// Look-up plugin id in plugin registry.
|
||||
///
|
||||
HD_API
|
||||
TfToken GetPluginId() const;
|
||||
|
||||
///
|
||||
/// Clients should use CreateDelegate since this method
|
||||
/// will eventually become protected, use CreateRenderDelegateHandle
|
||||
/// instead.
|
||||
///
|
||||
/// Factory a Render Delegate object, that Hydra can use to
|
||||
/// factory prims and communicate with a renderer.
|
||||
///
|
||||
virtual HdRenderDelegate *CreateRenderDelegate() = 0;
|
||||
|
||||
///
|
||||
/// Clients should use CreateDelegate since this method
|
||||
/// will eventually become protected.
|
||||
///
|
||||
/// Factory a Render Delegate object, that Hydra can use to
|
||||
/// factory prims and communicate with a renderer. Pass in initial
|
||||
/// settings...
|
||||
///
|
||||
HD_API
|
||||
virtual HdRenderDelegate *CreateRenderDelegate(
|
||||
HdRenderSettingsMap const& settingsMap);
|
||||
|
||||
///
|
||||
/// Clients should use CreateDelegate since this method
|
||||
/// will eventually become protected.
|
||||
///
|
||||
/// Release the object factoried by CreateRenderDelegate().
|
||||
///
|
||||
virtual void DeleteRenderDelegate(HdRenderDelegate *renderDelegate) = 0;
|
||||
|
||||
///
|
||||
/// Returns \c true if this renderer plugin is supported in the running
|
||||
/// process and \c false if not.
|
||||
///
|
||||
/// This gives the plugin a chance to perform some runtime checks to make
|
||||
/// sure that the system meets minimum requirements.
|
||||
///
|
||||
virtual bool IsSupported() const = 0;
|
||||
|
||||
protected:
|
||||
HdRendererPlugin() = default;
|
||||
HD_API
|
||||
~HdRendererPlugin() override;
|
||||
|
||||
private:
|
||||
// This class doesn't require copy support.
|
||||
HdRendererPlugin(const HdRendererPlugin &) = delete;
|
||||
HdRendererPlugin &operator =(const HdRendererPlugin &) = delete;
|
||||
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_RENDERER_PLUGIN_H
|
||||
@@ -0,0 +1,86 @@
|
||||
//
|
||||
// Copyright 2020 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_RENDERER_PLUGIN_HANDLE_H
|
||||
#define PXR_IMAGING_HD_RENDERER_PLUGIN_HANDLE_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/renderDelegate.h"
|
||||
|
||||
#include "pxr/base/tf/token.h"
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdRendererPlugin;
|
||||
class HdPluginRenderDelegateUniqueHandle;
|
||||
|
||||
///
|
||||
/// A handle for HdRendererPlugin also storing the plugin id.
|
||||
///
|
||||
/// Alleviates the need to ever call, e.g., ReleasePlugin since it
|
||||
/// automatically decreases and increases the plugin's reference
|
||||
/// counts with the plugin registry.
|
||||
///
|
||||
class HdRendererPluginHandle final
|
||||
{
|
||||
public:
|
||||
HdRendererPluginHandle() : _plugin(nullptr) { }
|
||||
HdRendererPluginHandle(const std::nullptr_t &) : _plugin(nullptr) { }
|
||||
|
||||
HD_API
|
||||
HdRendererPluginHandle(const HdRendererPluginHandle &);
|
||||
|
||||
HD_API
|
||||
~HdRendererPluginHandle();
|
||||
|
||||
HD_API
|
||||
HdRendererPluginHandle &operator=(const HdRendererPluginHandle &);
|
||||
|
||||
HD_API
|
||||
HdRendererPluginHandle &operator=(const std::nullptr_t &);
|
||||
|
||||
/// Get the wrapped HdRendererPlugin
|
||||
HdRendererPlugin *Get() const { return _plugin; }
|
||||
|
||||
HdRendererPlugin *operator->() const { return _plugin; }
|
||||
HdRendererPlugin &operator*() const { return *_plugin; }
|
||||
|
||||
/// Is the wrapped HdRendererPlugin valid?
|
||||
explicit operator bool() const { return _plugin; }
|
||||
|
||||
private:
|
||||
friend class HdRendererPluginRegistry;
|
||||
friend class HdRendererPlugin;
|
||||
|
||||
HdRendererPluginHandle(HdRendererPlugin * const plugin)
|
||||
: _plugin(plugin) { }
|
||||
|
||||
HdRendererPlugin *_plugin;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,117 @@
|
||||
//
|
||||
// Copyright 2017 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_RENDERER_PLUGIN_REGISTRY_H
|
||||
#define PXR_IMAGING_HD_RENDERER_PLUGIN_REGISTRY_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/renderDelegate.h"
|
||||
#include "pxr/base/tf/singleton.h"
|
||||
#include "pxr/imaging/hf/pluginRegistry.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
class HdRendererPlugin;
|
||||
class HdRendererPluginHandle;
|
||||
class HdPluginRenderDelegateUniqueHandle;
|
||||
|
||||
class HdRendererPluginRegistry final : public HfPluginRegistry
|
||||
{
|
||||
public:
|
||||
///
|
||||
/// Returns the singleton registry for \c HdRendererPlugin
|
||||
///
|
||||
HD_API
|
||||
static HdRendererPluginRegistry &GetInstance();
|
||||
|
||||
///
|
||||
/// Entry point for defining an HdRendererPlugin plugin.
|
||||
///
|
||||
template<typename T, typename... Bases>
|
||||
static void Define();
|
||||
|
||||
///
|
||||
/// Returns the id of plugin to use as the default
|
||||
///
|
||||
HD_API
|
||||
TfToken GetDefaultPluginId();
|
||||
|
||||
///
|
||||
/// \deprecated Use GetOrCreateRendererPlugin instead.
|
||||
///
|
||||
/// Returns the renderer plugin for the given id or null
|
||||
/// if not found. The reference count on the returned
|
||||
/// delegate is incremented.
|
||||
///
|
||||
HD_API
|
||||
HdRendererPlugin *GetRendererPlugin(const TfToken &pluginId);
|
||||
|
||||
///
|
||||
/// Returns the renderer plugin for the given id or a null handle
|
||||
/// if not found. The plugin is wrapped in a handle that automatically
|
||||
/// increments and decrements the reference count and also stores the
|
||||
/// plugin id.
|
||||
///
|
||||
HD_API
|
||||
HdRendererPluginHandle GetOrCreateRendererPlugin(const TfToken &pluginId);
|
||||
|
||||
///
|
||||
/// Returns a render delegate created by the plugin with the given name
|
||||
/// if the plugin is supported using given initial settings.
|
||||
/// The render delegate is wrapped in a movable handle that
|
||||
/// keeps the plugin alive until the render delegate is destroyed by
|
||||
/// dropping the handle.
|
||||
///
|
||||
HD_API
|
||||
HdPluginRenderDelegateUniqueHandle CreateRenderDelegate(
|
||||
const TfToken &pluginId,
|
||||
const HdRenderSettingsMap &settingsMap = {});
|
||||
|
||||
private:
|
||||
// Friend required by TfSingleton to access constructor (as it is private).
|
||||
friend class TfSingleton<HdRendererPluginRegistry>;
|
||||
|
||||
// Singleton gets private constructed
|
||||
HdRendererPluginRegistry();
|
||||
~HdRendererPluginRegistry() override;
|
||||
|
||||
//
|
||||
/// This class is not intended to be copied.
|
||||
///
|
||||
HdRendererPluginRegistry(const HdRendererPluginRegistry &) = delete;
|
||||
HdRendererPluginRegistry &operator=(const HdRendererPluginRegistry &) = delete;
|
||||
};
|
||||
|
||||
|
||||
template<typename T, typename... Bases>
|
||||
void HdRendererPluginRegistry::Define()
|
||||
{
|
||||
HfPluginRegistry::Define<T, HdRendererPlugin, Bases...>();
|
||||
}
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_RENDERER_PLUGIN_REGISTRY_H
|
||||
@@ -0,0 +1,242 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_REPR_H
|
||||
#define PXR_IMAGING_HD_REPR_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/drawItem.h"
|
||||
#include "pxr/imaging/hd/tokens.h"
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
/// \class HdReprSelector
|
||||
///
|
||||
/// Describes one or more authored display representations for an rprim.
|
||||
/// Display opinions are separated by the topology index they represent.
|
||||
/// This allows the application to specify one or more topological
|
||||
/// representations for a given HdRprim.
|
||||
/// For some visualizations, an application may choose to provide an opinion for
|
||||
/// the display of the refined surface, the unrefined hull and the points
|
||||
/// separately from the rprim's authored opinions.
|
||||
/// HdReprSelector allows these opinions to compose/merge into a final composite
|
||||
/// representation to be used for rendering.
|
||||
///
|
||||
class HdReprSelector
|
||||
{
|
||||
public:
|
||||
explicit HdReprSelector()
|
||||
: refinedToken()
|
||||
, unrefinedToken()
|
||||
, pointsToken() { }
|
||||
|
||||
explicit HdReprSelector(TfToken const &token)
|
||||
: refinedToken(token)
|
||||
, unrefinedToken()
|
||||
, pointsToken() { }
|
||||
|
||||
explicit HdReprSelector(
|
||||
TfToken const &refined,
|
||||
TfToken const &unrefined)
|
||||
: refinedToken(refined)
|
||||
, unrefinedToken(unrefined)
|
||||
, pointsToken() { }
|
||||
|
||||
explicit HdReprSelector(
|
||||
TfToken const &refined,
|
||||
TfToken const &unrefined,
|
||||
TfToken const &points)
|
||||
: refinedToken(refined)
|
||||
, unrefinedToken(unrefined)
|
||||
, pointsToken(points) { }
|
||||
|
||||
/// Currenly support upto 3 topology tokens.
|
||||
static const size_t MAX_TOPOLOGY_REPRS = 3;
|
||||
|
||||
/// Returns true if the passed in reprToken is in the set of tokens
|
||||
/// for any topology index.
|
||||
HD_API
|
||||
bool Contains(const TfToken &reprToken) const;
|
||||
|
||||
/// Returns true if the topology token at an index is active, i.e., neither
|
||||
/// empty nor disabled.
|
||||
HD_API
|
||||
bool IsActiveRepr(size_t topologyIndex) const;
|
||||
|
||||
/// Returns true if any of the topology tokens is valid, i.e., neither
|
||||
/// empty nor disabled.
|
||||
HD_API
|
||||
bool AnyActiveRepr() const;
|
||||
|
||||
/// Returns a selector that is the composite of this selector 'over'
|
||||
/// the passed in selector.
|
||||
/// For each token that IsEmpty in this selector return the corresponding
|
||||
/// token in the passed in selector.
|
||||
/// Effectively this performs a merge operation where this selector wins
|
||||
/// for each topological index it has an opinion on.
|
||||
HD_API
|
||||
HdReprSelector CompositeOver(const HdReprSelector &under) const;
|
||||
|
||||
HD_API
|
||||
bool operator==(const HdReprSelector &rhs) const;
|
||||
|
||||
HD_API
|
||||
bool operator!=(const HdReprSelector &rhs) const;
|
||||
|
||||
HD_API
|
||||
bool operator<(const HdReprSelector &rhs) const;
|
||||
|
||||
HD_API
|
||||
size_t Hash() const;
|
||||
|
||||
HD_API
|
||||
char const* GetText() const;
|
||||
|
||||
HD_API
|
||||
friend std::ostream &operator <<(std::ostream &stream,
|
||||
HdReprSelector const& t);
|
||||
|
||||
|
||||
HD_API
|
||||
TfToken const &operator[](size_t topologyIndex) const;
|
||||
|
||||
private:
|
||||
// TfHash support.
|
||||
template <class HashState>
|
||||
friend void
|
||||
TfHashAppend(HashState &h, HdReprSelector const &rs) {
|
||||
h.Append(rs.refinedToken, rs.unrefinedToken, rs.pointsToken);
|
||||
}
|
||||
|
||||
TfToken refinedToken;
|
||||
TfToken unrefinedToken;
|
||||
TfToken pointsToken;
|
||||
};
|
||||
|
||||
|
||||
/// \class HdRepr
|
||||
///
|
||||
/// An HdRepr refers to a (single) topological representation of an rprim, and
|
||||
/// owns the draw item(s) that visually represent it. The draw items are
|
||||
/// populated by the rprim.
|
||||
/// The relevant compositional hierarchy is:
|
||||
///
|
||||
/// HdRprim
|
||||
/// |
|
||||
/// +--HdRepr(s)
|
||||
/// |
|
||||
/// +--HdDrawItem(s)
|
||||
///
|
||||
/// When multiple topological representations are required for an rprim, we use
|
||||
/// HdReprSelector to compose the individual representations.
|
||||
///
|
||||
class HdRepr final
|
||||
{
|
||||
public:
|
||||
using DrawItemUniquePtr = std::unique_ptr<HdDrawItem>;
|
||||
using DrawItemUniquePtrVector = std::vector<DrawItemUniquePtr>;
|
||||
|
||||
HD_API
|
||||
HdRepr();
|
||||
HD_API
|
||||
~HdRepr();
|
||||
|
||||
/// Returns the draw items for this representation.
|
||||
const DrawItemUniquePtrVector& GetDrawItems() const {
|
||||
return _drawItems;
|
||||
}
|
||||
|
||||
/// Transfers ownership of a draw item to this repr.
|
||||
/// Do not use for adding geom subset draw items.
|
||||
void AddDrawItem(std::unique_ptr<HdDrawItem> &&item) {
|
||||
_drawItems.insert(_drawItems.begin() + _geomSubsetsStart,
|
||||
std::move(item));
|
||||
_geomSubsetsStart++;
|
||||
}
|
||||
|
||||
/// Returns the draw item at the requested index.
|
||||
///
|
||||
/// Note that the pointer returned is owned by this object and must not be
|
||||
/// deleted.
|
||||
HdDrawItem* GetDrawItem(size_t index) const {
|
||||
return _drawItems[index].get();
|
||||
}
|
||||
|
||||
/// HdRepr can hold geom subset draw items, which are unique in that they
|
||||
/// not created at the time the repr is created, but instead when populating
|
||||
/// the mesh topology of a mesh rprim. The number of geom subset draw items
|
||||
/// in a repr can change over time.
|
||||
/// We make some assumptions when using these geom subset related functions.
|
||||
/// We assume the geom subset draw items will only be added (or cleared)
|
||||
/// after all of the main draw items for a repr have been added.
|
||||
/// We also assume that the geom subset draw items for a repr desc are all
|
||||
/// added one after the other before moving onto the next repr desc.
|
||||
/// Thus the order of draw items in the _drawItems member might go something
|
||||
/// like (assuming two repr descs and three geom subsets in this example):
|
||||
/// [ main DI for desc 1, main DI for desc 2, GS1 DI for desc 1,
|
||||
/// GS2 DI for desc 1, GS3 DI for desc 1, GS1 DI for desc 2,
|
||||
/// GS2 DI for desc 2, GS3 DI for desc 2 ]
|
||||
/// It is also possible for there to exist a main draw item for a particular
|
||||
/// repr desc but no geom subsets for that repr desc, while having geom
|
||||
/// subsets exist for a different repr desc.
|
||||
|
||||
/// Transfers ownership of a draw item to this repr.
|
||||
/// To be used only for geom subset draw items.
|
||||
void AddGeomSubsetDrawItem(std::unique_ptr<HdDrawItem> &&item) {
|
||||
_drawItems.push_back(std::move(item));
|
||||
}
|
||||
|
||||
/// Utility similar to GetDrawItem for getting geom subset draw items.
|
||||
HdDrawItem* GetDrawItemForGeomSubset(size_t reprDescIndex,
|
||||
size_t numGeomSubsets, size_t geomSubsetIndex) const {
|
||||
return _drawItems[_geomSubsetsStart + reprDescIndex * numGeomSubsets +
|
||||
geomSubsetIndex].get();
|
||||
}
|
||||
|
||||
/// Removes all of the geom subset draw items from the repr.
|
||||
void ClearGeomSubsetDrawItems() {
|
||||
_drawItems.erase(
|
||||
_drawItems.begin() + _geomSubsetsStart, _drawItems.end());
|
||||
}
|
||||
|
||||
private:
|
||||
// Noncopyable
|
||||
HdRepr(const HdRepr&) = delete;
|
||||
HdRepr& operator=(const HdRepr&) = delete;
|
||||
|
||||
private:
|
||||
// Contains normal draw items first, potentially followed by geom subset
|
||||
// draw items
|
||||
DrawItemUniquePtrVector _drawItems;
|
||||
|
||||
// Index into _drawItems indicating where the geom subset draw items begin.
|
||||
size_t _geomSubsetsStart;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif //PXR_IMAGING_HD_REPR_H
|
||||
@@ -0,0 +1,78 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_IMAGING_HD_RESOURCE_H
|
||||
#define PXR_IMAGING_HD_RESOURCE_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
using HdResourceSharedPtr = std::shared_ptr<class HdResource>;
|
||||
|
||||
/// \class HdResource
|
||||
///
|
||||
/// Base class for all GPU resource objects.
|
||||
///
|
||||
class HdResource
|
||||
{
|
||||
public:
|
||||
HD_API
|
||||
HdResource(TfToken const & role);
|
||||
HD_API
|
||||
virtual ~HdResource();
|
||||
|
||||
/// Returns the role of the GPU data in this resource.
|
||||
TfToken const & GetRole() const {return _role;}
|
||||
|
||||
/// Returns the size of the resource allocated in the GPU
|
||||
HD_API
|
||||
size_t GetSize() const {return _size;}
|
||||
|
||||
protected:
|
||||
/// Stores the size of the resource allocated in the GPU
|
||||
HD_API
|
||||
void SetSize(size_t size);
|
||||
|
||||
private:
|
||||
|
||||
// Don't allow copies.
|
||||
HdResource(const HdResource &) = delete;
|
||||
HdResource &operator=(const HdResource &) = delete;
|
||||
|
||||
|
||||
const TfToken _role;
|
||||
size_t _size;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif //PXR_IMAGING_HD_RESOURCE_H
|
||||
Loaded 100 of 15684 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user