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,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_ST_API_H
|
||||
#define PXR_IMAGING_HD_ST_API_H
|
||||
|
||||
#include "pxr/base/arch/export.h"
|
||||
|
||||
#if defined(PXR_STATIC)
|
||||
# define HDST_API
|
||||
# define HDST_API_TEMPLATE_CLASS(...)
|
||||
# define HDST_API_TEMPLATE_STRUCT(...)
|
||||
# define HDST_LOCAL
|
||||
#else
|
||||
# if defined(HDST_EXPORTS)
|
||||
# define HDST_API ARCH_EXPORT
|
||||
# define HDST_API_TEMPLATE_CLASS(...) ARCH_EXPORT_TEMPLATE(class, __VA_ARGS__)
|
||||
# define HDST_API_TEMPLATE_STRUCT(...) ARCH_EXPORT_TEMPLATE(struct, __VA_ARGS__)
|
||||
# else
|
||||
# define HDST_API ARCH_IMPORT
|
||||
# define HDST_API_TEMPLATE_CLASS(...) ARCH_IMPORT_TEMPLATE(class, __VA_ARGS__)
|
||||
# define HDST_API_TEMPLATE_STRUCT(...) ARCH_IMPORT_TEMPLATE(struct, __VA_ARGS__)
|
||||
# endif
|
||||
# define HDST_LOCAL ARCH_HIDDEN
|
||||
#endif
|
||||
|
||||
#endif // PXR_IMAGING_HD_ST_API_H
|
||||
@@ -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_ST_BASIS_CURVES_H
|
||||
#define PXR_IMAGING_HD_ST_BASIS_CURVES_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/basisCurves.h"
|
||||
#include "pxr/imaging/hd/drawingCoord.h"
|
||||
#include "pxr/imaging/hd/enums.h"
|
||||
#include "pxr/imaging/hd/perfLog.h"
|
||||
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
#include "pxr/base/vt/array.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdStDrawItem;
|
||||
using HdSt_BasisCurvesTopologySharedPtr =
|
||||
std::shared_ptr<class HdSt_BasisCurvesTopology>;
|
||||
|
||||
/// \class HdStBasisCurves
|
||||
///
|
||||
/// A collection of curves using a particular basis.
|
||||
///
|
||||
/// Render mode is dependent on both the HdBasisCurvesGeomStyle, refinement
|
||||
/// level, and the authored primvars.
|
||||
///
|
||||
/// If style is set to HdBasisCurvesGeomStyleWire, the curves will always draw
|
||||
/// as infinitely thin wires. Cubic curves will be refined if complexity is
|
||||
/// above 0, otherwise they draw the unrefined control points. (This may
|
||||
/// provide a misleading representation for Catmull-Rom and Bspline curves.)
|
||||
///
|
||||
/// If style is set to HdBasisCurvesGeomStylePatch, the curves will draw as
|
||||
/// patches ONLY if refinement level is above 0. Otherwise, they draw
|
||||
/// as the unrefined control points (see notes on HdBasisCurvesGeomStyleWire).
|
||||
///
|
||||
/// Curves rendered as patches may be rendered as ribbons or halftubes.
|
||||
/// Curves with primvar authored normals will always render as ribbons.
|
||||
/// Curves without primvar authored normals are assumed to be round and may be
|
||||
/// rendered in one of three styles:
|
||||
/// * if complexity is 1, a camera facing normal is used
|
||||
/// * if complexity is 2, a fake "bumped" round normal is used
|
||||
/// * if complexity is 3 or above, the patch is displaced into a half tube
|
||||
/// We plan for future checkins will remove the need for the camera facing normal
|
||||
/// mode, using the fake "bumped" round normal instead.
|
||||
class HdStBasisCurves final: public HdBasisCurves
|
||||
{
|
||||
public:
|
||||
HF_MALLOC_TAG_NEW("new HdStBasisCurves");
|
||||
|
||||
HDST_API
|
||||
HdStBasisCurves(SdfPath const& id);
|
||||
|
||||
HDST_API
|
||||
~HdStBasisCurves() override;
|
||||
|
||||
HDST_API
|
||||
void Sync(HdSceneDelegate *delegate,
|
||||
HdRenderParam *renderParam,
|
||||
HdDirtyBits *dirtyBits,
|
||||
TfToken const &reprToken) override;
|
||||
|
||||
HDST_API
|
||||
void Finalize(HdRenderParam *renderParam) override;
|
||||
|
||||
HDST_API
|
||||
HdDirtyBits GetInitialDirtyBitsMask() const override;
|
||||
|
||||
protected:
|
||||
HDST_API
|
||||
void _InitRepr(TfToken const &reprToken, HdDirtyBits *dirtyBits) override;
|
||||
|
||||
HDST_API
|
||||
HdDirtyBits _PropagateDirtyBits(HdDirtyBits bits) const override;
|
||||
|
||||
void _UpdateRepr(HdSceneDelegate *sceneDelegate,
|
||||
HdRenderParam *renderParam,
|
||||
TfToken const &reprToken,
|
||||
HdDirtyBits *dirtyBitsState);
|
||||
|
||||
void _PopulateTopology(HdSceneDelegate *sceneDelegate,
|
||||
HdRenderParam *renderParam,
|
||||
HdStDrawItem *drawItem,
|
||||
HdDirtyBits *dirtyBits,
|
||||
const HdBasisCurvesReprDesc &desc);
|
||||
|
||||
void _PopulateVertexPrimvars(HdSceneDelegate *sceneDelegate,
|
||||
HdRenderParam *renderParam,
|
||||
HdStDrawItem *drawItem,
|
||||
HdDirtyBits *dirtyBits);
|
||||
|
||||
void _PopulateVaryingPrimvars(HdSceneDelegate *sceneDelegate,
|
||||
HdRenderParam *renderParam,
|
||||
HdStDrawItem *drawItem,
|
||||
HdDirtyBits *dirtyBits);
|
||||
|
||||
void _PopulateElementPrimvars(HdSceneDelegate *sceneDelegate,
|
||||
HdRenderParam *renderParam,
|
||||
HdStDrawItem *drawItem,
|
||||
HdDirtyBits *dirtyBits);
|
||||
|
||||
private:
|
||||
enum DrawingCoord {
|
||||
HullTopology = HdDrawingCoord::CustomSlotsBegin,
|
||||
PointsTopology,
|
||||
InstancePrimvar // has to be at the very end
|
||||
};
|
||||
|
||||
enum DirtyBits : HdDirtyBits {
|
||||
DirtyIndices = HdChangeTracker::CustomBitsBegin,
|
||||
DirtyHullIndices = (DirtyIndices << 1),
|
||||
DirtyPointsIndices = (DirtyHullIndices << 1)
|
||||
};
|
||||
|
||||
// When processing primvars, these will get set to if we determine that
|
||||
// we should do cubic basis interpolation on the normals and widths.
|
||||
// NOTE: I worry that it may be possible for these to get out of sync.
|
||||
// The right long term fix is likely to maintain proper separation between
|
||||
// varying and vertex primvars throughout the HdSt rendering pipeline.
|
||||
bool _basisWidthInterpolation = false;
|
||||
bool _basisNormalInterpolation = false;
|
||||
|
||||
bool _SupportsRefinement(int refineLevel);
|
||||
bool _SupportsUserWidths(HdStDrawItem* drawItem);
|
||||
bool _SupportsUserNormals(HdStDrawItem* drawItem);
|
||||
|
||||
void _UpdateDrawItem(HdSceneDelegate *sceneDelegate,
|
||||
HdRenderParam *renderParam,
|
||||
HdStDrawItem *drawItem,
|
||||
HdDirtyBits *dirtyBits,
|
||||
const HdBasisCurvesReprDesc &desc);
|
||||
|
||||
void _UpdateDrawItemGeometricShader(HdSceneDelegate *sceneDelegate,
|
||||
HdRenderParam *renderParam,
|
||||
HdStDrawItem *drawItem,
|
||||
const HdBasisCurvesReprDesc &desc);
|
||||
|
||||
void _UpdateShadersForAllReprs(HdSceneDelegate *sceneDelegate,
|
||||
HdRenderParam *renderParam,
|
||||
bool updateMaterialNetworkShader,
|
||||
bool updateGeometricShader);
|
||||
|
||||
void _UpdateMaterialTagsForAllReprs(HdSceneDelegate *sceneDelegate,
|
||||
HdRenderParam *renderParam);
|
||||
|
||||
HdSt_BasisCurvesTopologySharedPtr _topology;
|
||||
HdTopology::ID _topologyId;
|
||||
HdDirtyBits _customDirtyBitsInUse;
|
||||
int _refineLevel; // XXX: could be moved into HdBasisCurveTopology.
|
||||
bool _displayOpacity : 1;
|
||||
bool _occludedSelectionShowsThrough : 1;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_ST_BASIS_CURVES_H
|
||||
@@ -0,0 +1,124 @@
|
||||
//
|
||||
// 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_ST_BUFFER_ARRAY_RANGE_H
|
||||
#define PXR_IMAGING_HD_ST_BUFFER_ARRAY_RANGE_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
#include "pxr/imaging/hd/bufferArrayRange.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
class HdBufferArrayGL;
|
||||
class HdStResourceRegistry;
|
||||
|
||||
using HdStBufferArrayRangeSharedPtr =
|
||||
std::shared_ptr<class HdStBufferArrayRange>;
|
||||
|
||||
class HdStBufferResource;
|
||||
|
||||
using HdStBufferResourceSharedPtr =
|
||||
std::shared_ptr<class HdStBufferResource>;
|
||||
using HdStBufferResourceNamedList =
|
||||
std::vector< std::pair<TfToken, HdStBufferResourceSharedPtr> >;
|
||||
|
||||
/// \class HdStBufferArrayRange
|
||||
///
|
||||
/// 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 HdStBufferArrayRange : public HdBufferArrayRange
|
||||
{
|
||||
public:
|
||||
HdStBufferArrayRange(HdStResourceRegistry* resourceRegistry);
|
||||
|
||||
/// 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.
|
||||
HDST_API
|
||||
virtual ~HdStBufferArrayRange();
|
||||
|
||||
/// Returns the GPU resource. If the buffer array contains more than one
|
||||
/// resource, this method raises a coding error.
|
||||
virtual HdStBufferResourceSharedPtr GetResource() const = 0;
|
||||
|
||||
/// Returns the named GPU resource.
|
||||
virtual HdStBufferResourceSharedPtr GetResource(TfToken const& name) = 0;
|
||||
|
||||
/// Returns the list of all named GPU resources for this bufferArrayRange.
|
||||
virtual HdStBufferResourceNamedList const& GetResources() const = 0;
|
||||
|
||||
/// Sets the bufferSpecs for all resources.
|
||||
HDST_API
|
||||
virtual void GetBufferSpecs(HdBufferSpecVector *bufferSpecs) const override;
|
||||
|
||||
protected:
|
||||
HdStResourceRegistry* GetResourceRegistry();
|
||||
|
||||
private:
|
||||
HdStResourceRegistry* _resourceRegistry;
|
||||
};
|
||||
|
||||
HDST_API
|
||||
std::ostream &operator <<(std::ostream &out,
|
||||
const HdStBufferArrayRange &self);
|
||||
|
||||
/// \class HdStBufferArrayRangeContainer
|
||||
///
|
||||
/// A resizable container of HdBufferArrayRanges.
|
||||
///
|
||||
class HdStBufferArrayRangeContainer
|
||||
{
|
||||
public:
|
||||
/// Constructor
|
||||
HdStBufferArrayRangeContainer(int size) : _ranges(size) { }
|
||||
|
||||
/// Set \p range into the container at \p index.
|
||||
/// If the size of container is smaller than index, resize it.
|
||||
HDST_API
|
||||
void Set(int index, HdStBufferArrayRangeSharedPtr const &range);
|
||||
|
||||
/// Returns the bar at \p index. returns null if either the index
|
||||
// is out of range or not yet set.
|
||||
HDST_API
|
||||
HdStBufferArrayRangeSharedPtr const &Get(int index) const;
|
||||
|
||||
private:
|
||||
std::vector<HdStBufferArrayRangeSharedPtr> _ranges;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // HD_BUFFER_ARRAY_RANGE_GL_H
|
||||
@@ -0,0 +1,80 @@
|
||||
//
|
||||
// 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_ST_BUFFER_RESOURCE_H
|
||||
#define PXR_IMAGING_HD_ST_BUFFER_RESOURCE_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/imaging/hd/bufferResource.h"
|
||||
|
||||
#include "pxr/imaging/hgi/buffer.h"
|
||||
|
||||
#include "pxr/base/tf/token.h"
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
using HdStBufferResourceSharedPtr =
|
||||
std::shared_ptr<class HdStBufferResource>;
|
||||
|
||||
using HdStBufferResourceNamedPair =
|
||||
std::pair<TfToken, HdStBufferResourceSharedPtr>;
|
||||
using HdStBufferResourceNamedList =
|
||||
std::vector<HdStBufferResourceNamedPair>;
|
||||
|
||||
/// \class HdStBufferResource
|
||||
///
|
||||
/// A specific type of HdBufferResource (GPU resource) representing
|
||||
/// an HgiBufferHandle.
|
||||
///
|
||||
class HdStBufferResource final : public HdBufferResource
|
||||
{
|
||||
public:
|
||||
HDST_API
|
||||
HdStBufferResource(TfToken const &role,
|
||||
HdTupleType tupleType,
|
||||
int offset,
|
||||
int stride);
|
||||
HDST_API
|
||||
~HdStBufferResource();
|
||||
|
||||
/// Sets the HgiBufferHandle for this resource and its size.
|
||||
/// also caches the gpu address of the buffer.
|
||||
HDST_API
|
||||
void SetAllocation(HgiBufferHandle const& handle, size_t size);
|
||||
|
||||
/// Returns the HgiBufferHandle for this GPU resource
|
||||
HgiBufferHandle& GetHandle() { return _handle; }
|
||||
|
||||
private:
|
||||
HgiBufferHandle _handle;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_ST_BUFFER_RESOURCE_H
|
||||
@@ -0,0 +1,134 @@
|
||||
//
|
||||
// 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_ST_COMMAND_BUFFER_H
|
||||
#define PXR_IMAGING_HD_ST_COMMAND_BUFFER_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hdSt/drawItemInstance.h"
|
||||
|
||||
#include "pxr/base/gf/vec2f.h"
|
||||
#include "pxr/base/gf/matrix4f.h"
|
||||
#include "pxr/base/gf/matrix4d.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
class HdStDrawItem;
|
||||
class HdStDrawItemInstance;
|
||||
|
||||
using HdStRenderPassStateSharedPtr = std::shared_ptr<class HdStRenderPassState>;
|
||||
using HdStResourceRegistrySharedPtr =
|
||||
std::shared_ptr<class HdStResourceRegistry>;
|
||||
|
||||
using HdDrawItemConstPtrVector = std::vector<class HdDrawItem const*>;
|
||||
using HdDrawItemConstPtrVectorSharedPtr
|
||||
= std::shared_ptr<HdDrawItemConstPtrVector>;
|
||||
|
||||
using HdSt_DrawBatchSharedPtr = std::shared_ptr<class HdSt_DrawBatch>;
|
||||
using HdSt_DrawBatchSharedPtrVector = std::vector<HdSt_DrawBatchSharedPtr>;
|
||||
|
||||
/// \class HdStCommandBuffer
|
||||
///
|
||||
/// A buffer of commands (HdStDrawItem or HdComputeItem objects) to be executed.
|
||||
///
|
||||
/// The HdStCommandBuffer is responsible for accumulating draw items and sorting
|
||||
/// them for correctness (e.g. alpha transparency) and efficiency (e.g. the
|
||||
/// fewest number of GPU state changes).
|
||||
///
|
||||
class HdStCommandBuffer {
|
||||
public:
|
||||
HDST_API
|
||||
HdStCommandBuffer();
|
||||
HDST_API
|
||||
~HdStCommandBuffer();
|
||||
|
||||
/// Prepare the command buffer for draw
|
||||
HDST_API
|
||||
void PrepareDraw(HdStRenderPassStateSharedPtr const &renderPassState,
|
||||
HdStResourceRegistrySharedPtr const &resourceRegistry);
|
||||
|
||||
/// Execute the command buffer
|
||||
HDST_API
|
||||
void ExecuteDraw(HdStRenderPassStateSharedPtr const &renderPassState,
|
||||
HdStResourceRegistrySharedPtr const &resourceRegistry);
|
||||
|
||||
/// Cull drawItemInstances based on passed in combined view and projection matrix
|
||||
HDST_API
|
||||
void FrustumCull(GfMatrix4d const &cullMatrix);
|
||||
|
||||
/// Sync visibility state from RprimSharedState to DrawItemInstances.
|
||||
HDST_API
|
||||
void SyncDrawItemVisibility(unsigned visChangeCount);
|
||||
|
||||
/// Sets the draw items to use for batching.
|
||||
/// If the shared pointer or version is different, batches are rebuilt and
|
||||
/// the batch version is updated.
|
||||
HDST_API
|
||||
void SetDrawItems(HdDrawItemConstPtrVectorSharedPtr const &drawItems,
|
||||
unsigned currentBatchVersion);
|
||||
|
||||
/// Rebuild all draw batches if any underlying buffer array is invalidated.
|
||||
HDST_API
|
||||
void RebuildDrawBatchesIfNeeded(unsigned currentBatchVersion);
|
||||
|
||||
/// Returns the total number of draw items, including culled items.
|
||||
size_t GetTotalSize() const {
|
||||
if (_drawItems) return _drawItems->size();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// Returns the number of draw items, excluding culled items.
|
||||
size_t GetVisibleSize() const { return _visibleSize; }
|
||||
|
||||
/// Returns the number of culled draw items.
|
||||
size_t GetCulledSize() const {
|
||||
if (_drawItems) {
|
||||
return _drawItems->size() - _visibleSize;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
HDST_API
|
||||
void SetEnableTinyPrimCulling(bool tinyPrimCulling);
|
||||
|
||||
private:
|
||||
void _RebuildDrawBatches();
|
||||
|
||||
HdDrawItemConstPtrVectorSharedPtr _drawItems;
|
||||
std::vector<HdStDrawItemInstance> _drawItemInstances;
|
||||
HdSt_DrawBatchSharedPtrVector _drawBatches;
|
||||
size_t _visibleSize;
|
||||
unsigned int _visChangeCount;
|
||||
unsigned int _drawBatchesVersion;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif //PXR_IMAGING_HD_ST_COMMAND_BUFFER_H
|
||||
@@ -0,0 +1,63 @@
|
||||
//
|
||||
// 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_ST_COPY_COMPUTATION_H
|
||||
#define PXR_IMAGING_HD_ST_COPY_COMPUTATION_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/imaging/hd/computation.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
/// \class HdStCopyComputationGPU
|
||||
///
|
||||
/// A GPU computation which transfers a vbo range specified by src and name to
|
||||
/// the given range.
|
||||
///
|
||||
class HdStCopyComputationGPU : public HdComputation {
|
||||
public:
|
||||
HDST_API
|
||||
HdStCopyComputationGPU(HdBufferArrayRangeSharedPtr const &src,
|
||||
TfToken const &name);
|
||||
|
||||
HDST_API
|
||||
virtual void Execute(HdBufferArrayRangeSharedPtr const &range,
|
||||
HdResourceRegistry *resourceRegistry) override;
|
||||
|
||||
HDST_API
|
||||
virtual int GetNumOutputElements() const override;
|
||||
|
||||
HDST_API
|
||||
virtual void GetBufferSpecs(HdBufferSpecVector *specs) const override;
|
||||
|
||||
private:
|
||||
HdBufferArrayRangeSharedPtr _src;
|
||||
TfToken _name;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // HDST_COMPUTATION_H
|
||||
@@ -0,0 +1,53 @@
|
||||
|
||||
// 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_ST_DEBUG_CODES_H
|
||||
#define PXR_IMAGING_HD_ST_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(
|
||||
HDST_DRAW_BATCH,
|
||||
HDST_FORCE_DRAW_BATCH_REBUILD,
|
||||
HDST_DRAW_ITEM_GATHER,
|
||||
HDST_DRAWITEMS_CACHE,
|
||||
HDST_DISABLE_FRUSTUM_CULLING,
|
||||
HDST_DISABLE_MULTITHREADED_CULLING,
|
||||
HDST_DUMP_GLSLFX_CONFIG,
|
||||
HDST_DUMP_FAILING_SHADER_SOURCE,
|
||||
HDST_DUMP_FAILING_SHADER_SOURCEFILE,
|
||||
HDST_DUMP_SHADER_SOURCE,
|
||||
HDST_DUMP_SHADER_SOURCEFILE,
|
||||
HDST_MATERIAL_ADDED,
|
||||
HDST_MATERIAL_REMOVED
|
||||
);
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_ST_DEBUG_CODES_H
|
||||
@@ -0,0 +1,177 @@
|
||||
//
|
||||
// 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_ST_DISPATCH_BUFFER_H
|
||||
#define PXR_IMAGING_HD_ST_DISPATCH_BUFFER_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/bufferArray.h"
|
||||
#include "pxr/imaging/hd/bufferSpec.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/imaging/hdSt/bufferArrayRange.h"
|
||||
#include "pxr/imaging/hdSt/bufferResource.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdStResourceRegistry;
|
||||
|
||||
using HdStDispatchBufferSharedPtr = std::shared_ptr<class HdStDispatchBuffer>;
|
||||
|
||||
/// \class HdStDispatchBuffer
|
||||
///
|
||||
/// A VBO of a simple array of unsigned integers.
|
||||
///
|
||||
/// This buffer is used to prepare data on the GPU for indirect dispatch i.e.
|
||||
/// to be consumed by MultiDrawIndirect or DispatchComputeIndirect. At the
|
||||
/// same time, interleaved subsets of the array are bound in several different
|
||||
/// ways to provide additional data interface to shaders.
|
||||
///
|
||||
/// For each binding, we define 'BufferResourceView' on top of the uint array.
|
||||
/// HdBufferArray aggregates those views and HdResourceBinder binds them
|
||||
/// with specified binding method and interleaved offset.
|
||||
///
|
||||
/// Example:
|
||||
/// DrawElements + Instance culling : 14 integers for each drawitem
|
||||
///
|
||||
/// BufferResourceViews BufferResourceViews
|
||||
/// for draw for cull
|
||||
///
|
||||
/// +----draw item 0----+----------------------------> destination buffer
|
||||
/// | count | --+
|
||||
/// | instanceCount | |
|
||||
/// | first | |----> MDI dispatch
|
||||
/// | baseVertex | |
|
||||
/// | baseInstance | --+-------------------------> drawitem index
|
||||
/// | cullCount | ----+
|
||||
/// | cullInstanceCount | |------------------------> MDI dispatch
|
||||
/// | cullFirstVertex | |
|
||||
/// | cullBaseInstance | ----+
|
||||
/// | modelDC | --+
|
||||
/// | constantDC | |----> DrawingCoord0 -------> DrawingCoord0
|
||||
/// | elementDC | |
|
||||
/// | primitiveDC | --+
|
||||
/// | fvarDC | --+
|
||||
/// | instanceIndexDC | |----> DrawingCoord1 -------> DrawingCoord1
|
||||
/// | shaderDC | --+
|
||||
/// | (instanceDC[0]) | --+
|
||||
/// | (instanceDC[1]) | |----> DrawingCoordI -------> DrawingCoordI
|
||||
/// | (instanceDC[2]) | |
|
||||
/// | ... | --+
|
||||
/// +----draw item 1----+
|
||||
/// | count |
|
||||
/// | instanceCount |
|
||||
/// | ... |
|
||||
///
|
||||
/// XXX: it would be better to generalize this class not only for dispatch
|
||||
/// buffer, if we see other similar use-cases.
|
||||
///
|
||||
class HdStDispatchBuffer : public HdBufferArray
|
||||
{
|
||||
public:
|
||||
/// Constructor. commandNumUints is given in how many integers.
|
||||
HDST_API
|
||||
HdStDispatchBuffer(HdStResourceRegistry* resourceRegistry,
|
||||
TfToken const &role,
|
||||
int count,
|
||||
unsigned int commandNumUints);
|
||||
|
||||
/// Destructor.
|
||||
HDST_API
|
||||
~HdStDispatchBuffer() override;
|
||||
|
||||
/// Update entire buffer data
|
||||
HDST_API
|
||||
void CopyData(std::vector<uint32_t> const &data);
|
||||
|
||||
/// Add an interleaved view to this buffer.
|
||||
HDST_API
|
||||
void AddBufferResourceView(TfToken const &name,
|
||||
HdTupleType tupleType, int offset);
|
||||
|
||||
/// Returns the dispatch count
|
||||
int GetCount() const { return _count; }
|
||||
|
||||
/// Returns the number of uints in a single draw command.
|
||||
unsigned int GetCommandNumUints() const { return _commandNumUints; }
|
||||
|
||||
/// Returns a bar which locates all interleaved resources of the entire
|
||||
/// buffer.
|
||||
HdStBufferArrayRangeSharedPtr GetBufferArrayRange() const {
|
||||
return _bar;
|
||||
}
|
||||
|
||||
/// Returns entire buffer as a single HdBufferResource.
|
||||
HdStBufferResourceSharedPtr GetEntireResource() const {
|
||||
return _entireResource;
|
||||
}
|
||||
|
||||
// HdBufferArray overrides. they are not supported in this class.
|
||||
HDST_API
|
||||
bool GarbageCollect() override;
|
||||
HDST_API
|
||||
void Reallocate(
|
||||
std::vector<HdBufferArrayRangeSharedPtr> const &,
|
||||
HdBufferArraySharedPtr const &) override;
|
||||
|
||||
HDST_API
|
||||
void DebugDump(std::ostream &out) const override;
|
||||
|
||||
/// Returns the GPU resource. If the buffer array contains more than one
|
||||
/// resource, this method raises a coding error.
|
||||
HDST_API
|
||||
HdStBufferResourceSharedPtr GetResource() const;
|
||||
|
||||
/// Returns the named GPU resource. This method returns the first found
|
||||
/// resource. In HDST_SAFE_MODE it checks all underlying GPU buffers
|
||||
/// in _resourceMap and raises a coding error if there are more than
|
||||
/// one GPU buffers exist.
|
||||
HDST_API
|
||||
HdStBufferResourceSharedPtr GetResource(TfToken const& name);
|
||||
|
||||
/// Returns the list of all named GPU resources for this bufferArray.
|
||||
HdStBufferResourceNamedList const& GetResources() const {return _resourceList;}
|
||||
|
||||
protected:
|
||||
/// Adds a new, named GPU resource and returns it.
|
||||
HDST_API
|
||||
HdStBufferResourceSharedPtr _AddResource(TfToken const& name,
|
||||
HdTupleType tupleType,
|
||||
int offset,
|
||||
int stride);
|
||||
|
||||
private:
|
||||
HdStResourceRegistry *_resourceRegistry;
|
||||
int _count;
|
||||
unsigned int _commandNumUints;
|
||||
HdStBufferResourceNamedList _resourceList;
|
||||
HdStBufferResourceSharedPtr _entireResource;
|
||||
HdStBufferArrayRangeSharedPtr _bar; // Alternative to range list in base class
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_ST_DISPATCH_BUFFER_H
|
||||
@@ -0,0 +1,92 @@
|
||||
//
|
||||
// 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_ST_DOME_LIGHT_COMPUTATIONS_H
|
||||
#define PXR_IMAGING_HD_ST_DOME_LIGHT_COMPUTATIONS_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/imaging/hd/computation.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// Dome Light texture computations GPU
|
||||
///
|
||||
///
|
||||
using HdSt_DomeLightComputationGPUSharedPtr =
|
||||
std::shared_ptr<class HdSt_DomeLightComputationGPU>;
|
||||
using HdStSimpleLightingShaderPtr =
|
||||
std::weak_ptr<class HdStSimpleLightingShader>;
|
||||
|
||||
////
|
||||
//// \class HdSt_DomeLightComputationGPU
|
||||
///
|
||||
/// Given an OpenGL texture at construction time, create a new OpenGL
|
||||
/// texture (computed from the contents of the given texture) and sets
|
||||
/// the GL name on the given lighting shader during Execute (also
|
||||
/// freeing previous texture).
|
||||
///
|
||||
/// If the texture to be created has several mip levels, the texture
|
||||
/// will only be created by the computation with level = 0 and the
|
||||
/// computations with level > 0 will use the same texture.
|
||||
///
|
||||
class HdSt_DomeLightComputationGPU : public HdComputation {
|
||||
public:
|
||||
/// Constructor
|
||||
HDST_API
|
||||
HdSt_DomeLightComputationGPU(
|
||||
// Name of computation shader to use, also used as
|
||||
// key when setting the GL name on the lighting shader
|
||||
const TfToken & shaderToken,
|
||||
// Lighting shader that remembers the GL texture names
|
||||
HdStSimpleLightingShaderPtr const &lightingShader,
|
||||
// Number of mip levels.
|
||||
unsigned int numLevels = 1,
|
||||
// Level to be filled (0 means also to allocate texture)
|
||||
unsigned int level = 0,
|
||||
float roughness = -1.0);
|
||||
|
||||
HDST_API
|
||||
void GetBufferSpecs(HdBufferSpecVector *specs) const override {}
|
||||
|
||||
HDST_API
|
||||
void Execute(HdBufferArrayRangeSharedPtr const &range,
|
||||
HdResourceRegistry *resourceRegistry) override;
|
||||
|
||||
/// This computation doesn't generate buffer source (i.e. 2nd phase)
|
||||
/// This is a gpu computation, but no need to resize the destination
|
||||
/// since it belongs the same range as src buffer.
|
||||
int GetNumOutputElements() const override { return 0; }
|
||||
|
||||
private:
|
||||
const TfToken _shaderToken;
|
||||
HdStSimpleLightingShaderPtr const _lightingShader;
|
||||
const unsigned int _numLevels;
|
||||
const unsigned int _level;
|
||||
const float _roughness;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_ST_DOME_LIGHT_COMPUTATIONS_H
|
||||
@@ -0,0 +1,79 @@
|
||||
//
|
||||
// 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_ST_DRAW_ITEM_H
|
||||
#define PXR_IMAGING_HD_ST_DRAW_ITEM_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/imaging/hd/drawItem.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
using HdSt_GeometricShaderSharedPtr =
|
||||
std::shared_ptr<class HdSt_GeometricShader>;
|
||||
using HdSt_MaterialNetworkShaderSharedPtr =
|
||||
std::shared_ptr<class HdSt_MaterialNetworkShader>;
|
||||
|
||||
class HdStDrawItem : public HdDrawItem
|
||||
{
|
||||
public:
|
||||
HF_MALLOC_TAG_NEW("new HdStDrawItem");
|
||||
|
||||
HDST_API
|
||||
HdStDrawItem(HdRprimSharedData const *sharedData);
|
||||
|
||||
HDST_API
|
||||
~HdStDrawItem() override;
|
||||
|
||||
void SetGeometricShader(HdSt_GeometricShaderSharedPtr const &shader) {
|
||||
_geometricShader = shader;
|
||||
}
|
||||
|
||||
HdSt_GeometricShaderSharedPtr const &GetGeometricShader() const {
|
||||
return _geometricShader;
|
||||
}
|
||||
|
||||
HdSt_MaterialNetworkShaderSharedPtr const &
|
||||
GetMaterialNetworkShader() const {
|
||||
return _materialNetworkShader;
|
||||
}
|
||||
|
||||
void SetMaterialNetworkShader(
|
||||
HdSt_MaterialNetworkShaderSharedPtr const &shader) {
|
||||
_materialNetworkShader = shader;
|
||||
}
|
||||
|
||||
protected:
|
||||
size_t _GetBufferArraysHash() const override;
|
||||
size_t _GetElementOffsetsHash() const override;
|
||||
|
||||
private:
|
||||
HdSt_GeometricShaderSharedPtr _geometricShader;
|
||||
HdSt_MaterialNetworkShaderSharedPtr _materialNetworkShader;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif //PXR_IMAGING_HD_ST_DRAW_ITEM_H
|
||||
@@ -0,0 +1,92 @@
|
||||
//
|
||||
// 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_ST_DRAW_ITEM_INSTANCE_H
|
||||
#define PXR_IMAGING_HD_ST_DRAW_ITEM_INSTANCE_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/imaging/hdSt/drawItem.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
using HdSt_DrawBatchSharedPtr = std::shared_ptr<class HdSt_DrawBatch>;
|
||||
|
||||
/// \class HdStDrawItemInstance
|
||||
///
|
||||
/// A container to store instance state for a drawitem.
|
||||
///
|
||||
/// During culling, the visibility state will be set. If the instance
|
||||
/// has a batch, the batch will get a DrawItemInstanceChanged
|
||||
/// callback.
|
||||
///
|
||||
/// The Batch is responsible for calling SetBatch and SetBatchIndex
|
||||
/// when adding / appending the instance. If the batch does not require
|
||||
/// the DrawItemInstanceChanged callback, then this step can be skipped
|
||||
///
|
||||
class HdStDrawItemInstance
|
||||
{
|
||||
public:
|
||||
HDST_API
|
||||
HdStDrawItemInstance(HdStDrawItem const *drawItem);
|
||||
HDST_API
|
||||
~HdStDrawItemInstance();
|
||||
|
||||
/// Set visibility state
|
||||
HDST_API
|
||||
void SetVisible(bool visible);
|
||||
|
||||
/// Query visibility state
|
||||
bool IsVisible() const { return _visible; }
|
||||
|
||||
/// Set index into batch list. Can be used by
|
||||
/// batch during DrawItemInstanceChanged callback
|
||||
HDST_API
|
||||
void SetBatchIndex(size_t batchIndex);
|
||||
|
||||
/// Query batch index
|
||||
size_t GetBatchIndex() const { return _batchIndex; }
|
||||
|
||||
/// Set the batch that will receive the DrawItemInstanceChanged
|
||||
/// callback when visibility is updated. Setting batch to NULL
|
||||
/// will disable this callback.
|
||||
// HDST_API
|
||||
void SetBatch(HdSt_DrawBatch *batch);
|
||||
|
||||
/// Return a const pointer to draw item
|
||||
HdStDrawItem const *GetDrawItem() const { return _drawItem; }
|
||||
|
||||
private:
|
||||
HdStDrawItemInstance();
|
||||
|
||||
HdSt_DrawBatch * _batch;
|
||||
HdStDrawItem const * _drawItem;
|
||||
size_t _batchIndex;
|
||||
bool _visible;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_ST_DRAW_ITEM_INSTANCE_H
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
//
|
||||
// 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_ST_DRAW_TARGET_H
|
||||
#define PXR_IMAGING_HD_ST_DRAW_TARGET_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/imaging/hdSt/drawTargetRenderPassState.h"
|
||||
#include "pxr/imaging/hd/rprimCollection.h"
|
||||
#include "pxr/imaging/hd/sprim.h"
|
||||
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
#include "pxr/base/tf/staticTokens.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
#define HDST_DRAW_TARGET_TOKENS \
|
||||
(camera) \
|
||||
(collection) \
|
||||
(drawTargetSet) \
|
||||
(enable) \
|
||||
(resolution) \
|
||||
(aovBindings) \
|
||||
(depthPriority)
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdStDrawTargetTokens, HDST_API, HDST_DRAW_TARGET_TOKENS);
|
||||
|
||||
class HdCamera;
|
||||
class HdRenderIndex;
|
||||
using HdStDrawTargetPtrVector = std::vector<class HdStDrawTarget *>;
|
||||
|
||||
/// \class HdStDrawTarget
|
||||
///
|
||||
/// Represents an render to texture render pass.
|
||||
///
|
||||
/// \note This is a temporary API to aid transition to Storm, and is subject
|
||||
/// to major changes.
|
||||
///
|
||||
class HdStDrawTarget : public HdSprim
|
||||
{
|
||||
public:
|
||||
HDST_API
|
||||
HdStDrawTarget(SdfPath const & id);
|
||||
HDST_API
|
||||
~HdStDrawTarget() override;
|
||||
|
||||
/// Dirty bits for the HdStDrawTarget object
|
||||
///
|
||||
/// When GetUseStormTextureSystem() is true, "Legacy" dirty
|
||||
/// bits are ignored.
|
||||
///
|
||||
enum DirtyBits : HdDirtyBits {
|
||||
Clean = 0,
|
||||
DirtyDTEnable = 1 << 0,
|
||||
DirtyDTCamera = 1 << 1,
|
||||
DirtyDTResolution = 1 << 2,
|
||||
DirtyDTAovBindings = 1 << 4,
|
||||
DirtyDTDepthPriority = 1 << 6,
|
||||
DirtyDTCollection = 1 << 7,
|
||||
AllDirty = (DirtyDTEnable
|
||||
|DirtyDTCamera
|
||||
|DirtyDTResolution
|
||||
|DirtyDTAovBindings
|
||||
|DirtyDTDepthPriority
|
||||
|DirtyDTCollection)
|
||||
};
|
||||
|
||||
/// Synchronizes state from the delegate to this object.
|
||||
HDST_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.
|
||||
HDST_API
|
||||
HdDirtyBits GetInitialDirtyBitsMask() const override;
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Draw Target API
|
||||
// ---------------------------------------------------------------------- //
|
||||
bool IsEnabled() const { return _enabled; }
|
||||
const HdStDrawTargetRenderPassState *GetDrawTargetRenderPassState() const
|
||||
{
|
||||
return &_drawTargetRenderPassState;
|
||||
}
|
||||
|
||||
/// Returns collection of rprims the draw target draws.
|
||||
HDST_API
|
||||
HdRprimCollection const &GetCollection() const { return _collection; }
|
||||
|
||||
/// returns all HdStDrawTargets in the render index
|
||||
HDST_API
|
||||
static void GetDrawTargets(HdRenderIndex* renderIndex,
|
||||
HdStDrawTargetPtrVector *drawTargets);
|
||||
|
||||
/// Resolution.
|
||||
///
|
||||
/// Set during sync.
|
||||
///
|
||||
const GfVec2i &GetResolution() const {
|
||||
return _resolution;
|
||||
}
|
||||
|
||||
private:
|
||||
bool _enabled;
|
||||
GfVec2i _resolution;
|
||||
HdRprimCollection _collection;
|
||||
|
||||
HdStDrawTargetRenderPassState _drawTargetRenderPassState;
|
||||
|
||||
// No copy
|
||||
HdStDrawTarget() = delete;
|
||||
HdStDrawTarget(const HdStDrawTarget &) = delete;
|
||||
HdStDrawTarget &operator =(const HdStDrawTarget &) = delete;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_ST_DRAW_TARGET_H
|
||||
@@ -0,0 +1,113 @@
|
||||
//
|
||||
// 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_ST_DRAW_TARGET_RENDER_PASS_STATE_H
|
||||
#define PXR_IMAGING_HD_ST_DRAW_TARGET_RENDER_PASS_STATE_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/imaging/hd/enums.h"
|
||||
#include "pxr/imaging/hd/rprimCollection.h"
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
class VtValue;
|
||||
using HdRenderPassAovBindingVector =
|
||||
std::vector<struct HdRenderPassAovBinding>;
|
||||
|
||||
/// \class HdStDrawTargetRenderPassState
|
||||
///
|
||||
/// Represents common non-gl context specific render pass state for a draw
|
||||
/// target.
|
||||
///
|
||||
/// \note This is a temporary API to aid transition to Storm, and is subject
|
||||
/// to major changes. It is likely this functionality will be absorbed into
|
||||
/// the base class.
|
||||
///
|
||||
class HdStDrawTargetRenderPassState final
|
||||
{
|
||||
public:
|
||||
HDST_API
|
||||
HdStDrawTargetRenderPassState();
|
||||
HDST_API
|
||||
~HdStDrawTargetRenderPassState(); // final no need to be virtual
|
||||
|
||||
const HdRenderPassAovBindingVector &GetAovBindings() const {
|
||||
return _aovBindings;
|
||||
}
|
||||
|
||||
HDST_API
|
||||
void SetAovBindings(const HdRenderPassAovBindingVector &aovBindings);
|
||||
|
||||
/// Sets the priority of values in the depth buffer.
|
||||
/// i.e. should pixels closer or further from the camera win.
|
||||
HDST_API
|
||||
void SetDepthPriority(HdDepthPriority priority);
|
||||
|
||||
/// Set the path to the camera to use to draw this render path from.
|
||||
HDST_API
|
||||
void SetCamera(const SdfPath &cameraId);
|
||||
|
||||
HDST_API
|
||||
void SetRprimCollection(HdRprimCollection const& col);
|
||||
|
||||
HdDepthPriority GetDepthPriority() const { return _depthPriority; }
|
||||
|
||||
|
||||
/// Returns the path to the camera to render from.
|
||||
const SdfPath &GetCamera() const { return _cameraId; }
|
||||
|
||||
/// Returns an increasing version number for when the collection object
|
||||
/// is changed.
|
||||
/// Note: This tracks the actual object and not the contents of the
|
||||
/// collection.
|
||||
unsigned int GetRprimCollectionVersion() const
|
||||
{
|
||||
return _rprimCollectionVersion;
|
||||
}
|
||||
|
||||
/// Returns the collection associated with this draw target.
|
||||
const HdRprimCollection &GetRprimCollection() const
|
||||
{
|
||||
return _rprimCollection;
|
||||
}
|
||||
|
||||
private:
|
||||
HdRenderPassAovBindingVector _aovBindings;
|
||||
HdDepthPriority _depthPriority;
|
||||
|
||||
SdfPath _cameraId;
|
||||
|
||||
HdRprimCollection _rprimCollection;
|
||||
unsigned int _rprimCollectionVersion;
|
||||
|
||||
HdStDrawTargetRenderPassState(const HdStDrawTargetRenderPassState &) = delete;
|
||||
HdStDrawTargetRenderPassState &operator =(const HdStDrawTargetRenderPassState &) = delete;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_ST_DRAW_TARGET_RENDER_PASS_STATE_H
|
||||
@@ -0,0 +1,59 @@
|
||||
//
|
||||
// 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_ST_DYNAMIC_UV_TEXTURE_IMPLEMENTATION_H
|
||||
#define PXR_IMAGING_HD_ST_DYNAMIC_UV_TEXTURE_IMPLEMENTATION_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdStDynamicUvTextureObject;
|
||||
|
||||
/// \class HdStDynamicUvTextureImplementation
|
||||
///
|
||||
/// Allows external clients to specify how a UV texture is loaded from, e.g.,
|
||||
/// a file and how it is committed to the GPU.
|
||||
///
|
||||
class HdStDynamicUvTextureImplementation
|
||||
{
|
||||
public:
|
||||
/// Called during the load phase of the Storm texture system
|
||||
/// when a texture file is supposed to be loaded to the CPU.
|
||||
///
|
||||
/// This method has to be thread-safe.
|
||||
///
|
||||
virtual void Load(HdStDynamicUvTextureObject *textureObject) = 0;
|
||||
|
||||
/// Called during the commit phase of the Storm texture system
|
||||
/// when the CPU texture is committed to the GPU.
|
||||
virtual void Commit(HdStDynamicUvTextureObject *textureObject) = 0;
|
||||
|
||||
/// Queried by, e.g., the material system to determine whether
|
||||
/// to use, e.g., the fallback value of a texture node.
|
||||
virtual bool IsValid(const HdStDynamicUvTextureObject *textureObject) = 0;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,130 @@
|
||||
//
|
||||
// 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_ST_DYNAMIC_UV_TEXTURE_OBJECT_H
|
||||
#define PXR_IMAGING_HD_ST_DYNAMIC_UV_TEXTURE_OBJECT_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
|
||||
#include "pxr/imaging/hdSt/textureObject.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdStDynamicUvTextureImplementation;
|
||||
|
||||
/// \class HdStDynamicUvTextureObject
|
||||
///
|
||||
/// A uv texture that is managed but not populated by the Storm texture system.
|
||||
///
|
||||
/// Clients can allocate an instance of this class through
|
||||
/// HdStResourceRegistry::AllocateTextureHandle or AllocateTextureObject
|
||||
/// by passing an HdStTextureIdentifier with a
|
||||
/// HdStDynamicUvSubtextureIdentifier.
|
||||
///
|
||||
/// The client can allocate the GPU resource with CreateTexture and populate it
|
||||
/// by either giving data in the HgiTextureDesc or binding the texture as target
|
||||
/// for a computation or render.
|
||||
///
|
||||
/// Bindless texture sampler handles can only be created correctly if
|
||||
/// a client has created the texture before the texture commit phase
|
||||
/// is finished.
|
||||
///
|
||||
class HdStDynamicUvTextureObject final : public HdStUvTextureObject
|
||||
{
|
||||
public:
|
||||
HDST_API
|
||||
HdStDynamicUvTextureObject(
|
||||
const HdStTextureIdentifier &textureId,
|
||||
HdSt_TextureObjectRegistry *textureObjectRegistry);
|
||||
|
||||
HDST_API
|
||||
~HdStDynamicUvTextureObject() override;
|
||||
|
||||
/// Allocate GPU resource using the texture descriptor. Populate
|
||||
/// if data are given in the descriptor.
|
||||
///
|
||||
void CreateTexture(const HgiTextureDesc &desc) {
|
||||
_CreateTexture(desc);
|
||||
}
|
||||
|
||||
/// Make GPU generate mipmaps.
|
||||
///
|
||||
void GenerateMipmaps()
|
||||
{
|
||||
_GenerateMipmaps();
|
||||
}
|
||||
|
||||
/// Release GPU resource.
|
||||
void DestroyTexture() {
|
||||
_DestroyTexture();
|
||||
}
|
||||
|
||||
/// Set wrap mode hints used when a texture node's wrap mode
|
||||
/// is use metadata.
|
||||
///
|
||||
/// This is typically called from HdStDynamicUvTextureImplementation::Load
|
||||
/// when the texture file has wrap mode hints.
|
||||
void SetWrapParameters(const std::pair<HdWrap, HdWrap> &wrapParameters) {
|
||||
_SetWrapParameters(wrapParameters);
|
||||
}
|
||||
|
||||
/// Save CPU data for this texture (transfering ownership).
|
||||
///
|
||||
/// This is typically called from HdStDynamicUvTextureImplementation::Load
|
||||
/// so that the CPU data can be uploaded during commit.
|
||||
///
|
||||
/// To free the CPU data, call with nullptr.
|
||||
///
|
||||
void SetCpuData(std::unique_ptr<HdStTextureCpuData> &&cpuData) {
|
||||
_SetCpuData(std::move(cpuData));
|
||||
}
|
||||
|
||||
/// Get the CPU data stored for this texture.
|
||||
///
|
||||
/// Typically used in HdStDynamicUvTextureImplementation::Commit to
|
||||
/// commit CPU data to GPU.
|
||||
HdStTextureCpuData * GetCpuData() const {
|
||||
return _GetCpuData();
|
||||
}
|
||||
|
||||
/// Always returns true - so that samplers for this texture are
|
||||
/// created.
|
||||
///
|
||||
HDST_API
|
||||
bool IsValid() const override;
|
||||
|
||||
protected:
|
||||
HDST_API
|
||||
void _Load() override;
|
||||
|
||||
HDST_API
|
||||
void _Commit() override;
|
||||
|
||||
private:
|
||||
HdStDynamicUvTextureImplementation * _GetImpl() const;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,214 @@
|
||||
//
|
||||
// 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_ST_EXT_COMP_GPU_COMPUTATION_H
|
||||
#define PXR_IMAGING_HD_ST_EXT_COMP_GPU_COMPUTATION_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/imaging/hdSt/extCompGpuComputationResource.h"
|
||||
#include "pxr/imaging/hdSt/resourceBinder.h"
|
||||
#include "pxr/imaging/hd/binding.h"
|
||||
#include "pxr/imaging/hd/bufferSource.h"
|
||||
#include "pxr/imaging/hd/computation.h"
|
||||
#include "pxr/imaging/hd/types.h"
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
#include "pxr/base/vt/value.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdSceneDelegate;
|
||||
class HdExtComputation;
|
||||
using HdStGLSLProgramSharedPtr= std::shared_ptr<class HdStGLSLProgram>;
|
||||
using HdExtComputationPrimvarDescriptorVector =
|
||||
std::vector<struct HdExtComputationPrimvarDescriptor>;
|
||||
|
||||
using HdStExtCompGpuComputationSharedPtr =
|
||||
std::shared_ptr<class HdStExtCompGpuComputation>;
|
||||
|
||||
|
||||
/// \class HdStExtCompGpuComputation
|
||||
/// A Computation that represents a GPU implementation of a ExtComputation.
|
||||
///
|
||||
/// The computation implements the basic:
|
||||
/// input HdBufferArrayRange -> processing -> output HdBufferArrayRange
|
||||
/// model of HdComputations where processing happens in Execute during the
|
||||
/// Execute phase of HdResourceRegistry::Commit.
|
||||
///
|
||||
/// The computation is performed in three stages by three companion classes:
|
||||
///
|
||||
/// 1. Input HdBuffersources are committed into the input HdBufferArrayRange
|
||||
/// during the Resolve phase of the HdResourceRegistry::Commit processing.
|
||||
///
|
||||
/// 2. HdStExtCompGpuComputationResource holds the committed GPU resident
|
||||
/// resources along with the compiled compute shading kernel to execute.
|
||||
/// The values of the HdBufferArrayRanges for the inputs are stored in this
|
||||
/// object. The resource can store heterogenous sources with differing number
|
||||
/// of elements as may be required by computations.
|
||||
///
|
||||
/// 3. HdStExtCompGpuComputation executes the kernel using the committed GPU
|
||||
/// resident resources and stores the results to the destination
|
||||
/// HdBufferArrayRange given in Execute. The destination HdBufferArrayRange is
|
||||
/// allocated by the owning HdRprim that registers the computation with the
|
||||
/// HdResourceRegistry by calling HdResourceRegistry::AddComputation.
|
||||
///
|
||||
/// \see HdStExtCompGpuComputationResource
|
||||
/// \see HdRprim
|
||||
/// \see HdComputation
|
||||
/// \see HdResourceRegistry
|
||||
/// \see HdExtComputation
|
||||
/// \see HdBufferArrayRange
|
||||
class HdStExtCompGpuComputation final : public HdComputation {
|
||||
public:
|
||||
/// Constructs a new GPU ExtComputation computation.
|
||||
/// resource provides the set of input data and kernel to execute this
|
||||
/// computation.
|
||||
/// compPrimvars identifies the primvar data being computed
|
||||
///
|
||||
/// dispatchCount specifies the number of kernel invocations to execute.
|
||||
/// elementCount specifies the number of elements to allocate for output.
|
||||
HdStExtCompGpuComputation(
|
||||
SdfPath const &id,
|
||||
HdStExtCompGpuComputationResourceSharedPtr const &resource,
|
||||
HdExtComputationPrimvarDescriptorVector const &compPrimvars,
|
||||
int dispatchCount,
|
||||
int elementCount);
|
||||
|
||||
/// Creates a GPU computation implementing the given abstract computation.
|
||||
/// When created this allocates HdStExtCompGpuComputationResource.
|
||||
/// Nothing is assigned GPU resources unless the source is subsequently
|
||||
/// added to the hdResourceRegistry and the registry is committed.
|
||||
///
|
||||
/// This delayed allocation allow Rprims to share computed primvar data and
|
||||
/// avoid duplicate allocations GPU resources for computation inputs and
|
||||
/// outputs.
|
||||
///
|
||||
/// \param[in] sceneDelegate the delegate to pull scene inputs from.
|
||||
/// \param[in] sourceComp the abstract computation in the HdRenderIndex
|
||||
/// this instance actually implements.
|
||||
/// \param[in] compPrimvars identifies the primvar data being computed.
|
||||
/// \see HdExtComputation
|
||||
HDST_API
|
||||
static HdStExtCompGpuComputationSharedPtr
|
||||
CreateGpuComputation(
|
||||
HdSceneDelegate *sceneDelegate,
|
||||
HdExtComputation const *sourceComp,
|
||||
HdExtComputationPrimvarDescriptorVector const &compPrimvars);
|
||||
|
||||
HDST_API
|
||||
virtual ~HdStExtCompGpuComputation() = default;
|
||||
|
||||
/// Adds the output buffer specs generated by this computation to the
|
||||
/// passed in vector of buffer specs.
|
||||
/// \param[out] specs the vector of HdBufferSpec to add this computation
|
||||
/// output buffer layout requirements to.
|
||||
HDST_API
|
||||
virtual void GetBufferSpecs(HdBufferSpecVector *specs) const override;
|
||||
|
||||
/// Executes the computation on the GPU.
|
||||
/// Called by HdResourceRegistry::Commit with the HdBufferArrayRange given
|
||||
/// to the HdResourceRegistry when the computation was added to the
|
||||
/// registry.
|
||||
/// \param[inout] range the buffer array range to save the computation
|
||||
/// result to.
|
||||
/// \param[in] resourceRegistry the registry that is current committing
|
||||
/// resources to the GPU.
|
||||
HDST_API
|
||||
virtual void Execute(HdBufferArrayRangeSharedPtr const &range,
|
||||
HdResourceRegistry *resourceRegistry) override;
|
||||
|
||||
/// Gets the number of GPU kernel invocations to execute.
|
||||
/// It can be useful for this to be different than the number of output
|
||||
/// elements, e.g. to run a per-curve kernel computing multiple points
|
||||
/// per-curve.
|
||||
HDST_API
|
||||
int GetDispatchCount() const;
|
||||
|
||||
/// Gets the number of elements in the output primvar.
|
||||
/// The number of elements produced by the computation must be known before
|
||||
/// doing the computation. The allocation of GPU resources needs to know
|
||||
/// the size to allocate before the kernel can run.
|
||||
HDST_API
|
||||
virtual int GetNumOutputElements() const override;
|
||||
|
||||
/// Gets the shared GPU resource holder for the computation.
|
||||
HDST_API
|
||||
virtual HdStExtCompGpuComputationResourceSharedPtr const &
|
||||
GetResource() const;
|
||||
|
||||
private:
|
||||
SdfPath _id;
|
||||
HdStExtCompGpuComputationResourceSharedPtr _resource;
|
||||
HdExtComputationPrimvarDescriptorVector _compPrimvars;
|
||||
int _dispatchCount;
|
||||
int _elementCount;
|
||||
|
||||
HdStExtCompGpuComputation() = delete;
|
||||
HdStExtCompGpuComputation(const HdStExtCompGpuComputation &) = delete;
|
||||
HdStExtCompGpuComputation &operator = (const HdStExtCompGpuComputation &)
|
||||
= delete;
|
||||
};
|
||||
|
||||
|
||||
/// Obtains a set of ExtComputation primvar source computations needed for this
|
||||
/// Rprim.
|
||||
///
|
||||
/// The list of computed primvar descriptors for an interpolation mode
|
||||
/// is passed in.
|
||||
///
|
||||
/// The scene delegate also provides information about which output on
|
||||
/// which computation is providing the source of the primvar.
|
||||
///
|
||||
/// Based on the information, the function creates the necessary
|
||||
/// computations and appends them on to the sources list (the sources vector
|
||||
/// need not be empty).
|
||||
///
|
||||
/// The caller is expected to pass these computation on these computations
|
||||
/// onto the resource registry (associating them with BARs if it is
|
||||
/// expected the primvar will be downloaded) Additional sources that
|
||||
/// should be associated with BARs but do not otherwise need to be scheduled
|
||||
/// for commit will be returned in reserveOnlySources.
|
||||
///
|
||||
/// The computation may also need to add sources that are resolved against
|
||||
/// internal BARs that are not to be associated with the primvar BAR. Those
|
||||
/// are returned in the separateComputationSources vector.
|
||||
/// The caller is expected to add them to the resource registry if the
|
||||
/// computation is needed.
|
||||
HDST_API
|
||||
void HdSt_GetExtComputationPrimvarsComputations(
|
||||
const SdfPath &id,
|
||||
HdSceneDelegate *sceneDelegate,
|
||||
HdExtComputationPrimvarDescriptorVector const& allCompPrimvars,
|
||||
HdDirtyBits dirtyBits,
|
||||
HdBufferSourceSharedPtrVector *sources,
|
||||
HdBufferSourceSharedPtrVector *reserveOnlySources,
|
||||
HdBufferSourceSharedPtrVector *separateComputationSources,
|
||||
HdStComputationSharedPtrVector *computations);
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_ST_EXT_COMP_GPU_COMPUTATION_H
|
||||
@@ -0,0 +1,134 @@
|
||||
//
|
||||
// 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_ST_EXT_COMP_GPU_COMPUTATION_RESOURCE_H
|
||||
#define PXR_IMAGING_HD_ST_EXT_COMP_GPU_COMPUTATION_RESOURCE_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/imaging/hd/bufferSource.h"
|
||||
#include "pxr/imaging/hdSt/resourceBinder.h"
|
||||
#include "pxr/imaging/hdSt/extCompComputeShader.h"
|
||||
#include "pxr/imaging/hdSt/resourceRegistry.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
using HdStExtCompGpuComputationResourceSharedPtr =
|
||||
std::shared_ptr<class HdStExtCompGpuComputationResource>;
|
||||
using HdStGLSLProgramSharedPtr= std::shared_ptr<class HdStGLSLProgram>;
|
||||
using HdBufferArrayRangeSharedPtrVector =
|
||||
std::vector<HdBufferArrayRangeSharedPtr>;
|
||||
|
||||
/// \class HdStExtCompGpuComputationResource
|
||||
///
|
||||
/// A resource that represents the persistent GPU resources of an ExtComputation.
|
||||
///
|
||||
/// All program and binding data required for compiling and loading HdRprim and
|
||||
/// internal primvar data is held by this object. The companion source and
|
||||
/// computation appeal to this object to access the GPU resources.
|
||||
///
|
||||
/// \see HdStExtCompGpuComputation
|
||||
class HdStExtCompGpuComputationResource final {
|
||||
public:
|
||||
/// Creates a GPU computation resource that can bind resources matching
|
||||
/// the layout of the compute kernel.
|
||||
/// The registry passed is the registry that the kernel program will
|
||||
/// be shared amongst. De-duplication of the compiled and linked program
|
||||
/// for runtime execution happens on a per-registry basis.
|
||||
///
|
||||
/// Memory for the input computation buffers must be provided
|
||||
/// This must be done prior to a HdResourceRegistry::Commit in
|
||||
/// which the computation has been added.
|
||||
/// Note that the Resource allocates no memory on its own and can be
|
||||
/// speculatively created and later de-duplicated, or discarded,
|
||||
/// without wasting resources.
|
||||
///
|
||||
/// \param[in] outputBufferSpecs the buffer specs that the computation is
|
||||
/// expecting to output.
|
||||
/// \param[in] kernel the compute kernel source to run as the computation.
|
||||
/// \param[in] registry the registry that the internal computation
|
||||
/// will cache and de-duplicate its compute shader instance with.
|
||||
HdStExtCompGpuComputationResource(
|
||||
HdBufferSpecVector const &outputBufferSpecs,
|
||||
HdSt_ExtCompComputeShaderSharedPtr const &kernel,
|
||||
HdBufferArrayRangeSharedPtrVector const &inputs,
|
||||
HdStResourceRegistrySharedPtr const ®istry
|
||||
);
|
||||
|
||||
virtual ~HdStExtCompGpuComputationResource() = default;
|
||||
|
||||
/// Gets the HdBufferArrayRange that inputs should be loaded into using the
|
||||
/// resource binder.
|
||||
HdBufferArrayRangeSharedPtrVector const &GetInputs() const {
|
||||
return _inputs;
|
||||
}
|
||||
|
||||
/// Gets the GPU HdStGLSLProgram to run to execute the computation.
|
||||
/// This may have been shared with many other instances in the same
|
||||
/// registry.
|
||||
/// The program is only valid for execution after Resolve has been called.
|
||||
HdStGLSLProgramSharedPtr const &GetProgram() {
|
||||
if (!_computeProgram) {
|
||||
_Resolve();
|
||||
}
|
||||
return _computeProgram;
|
||||
}
|
||||
|
||||
/// Gets the resource binder that matches the layout of the compute program.
|
||||
/// The binder is only valid for resolving layouts after Resolve has been
|
||||
/// called.
|
||||
HdSt_ResourceBinder const &GetResourceBinder() {
|
||||
if (!_computeProgram) {
|
||||
_Resolve();
|
||||
}
|
||||
return _resourceBinder;
|
||||
}
|
||||
|
||||
private:
|
||||
/// Resolve the resource bindings and program for use by a computation.
|
||||
/// The compute program is resolved and linked against the input and output
|
||||
/// resource bindings and the kernel source in this step.
|
||||
bool _Resolve();
|
||||
|
||||
HdBufferSpecVector _outputBufferSpecs;
|
||||
HdSt_ExtCompComputeShaderSharedPtr _kernel;
|
||||
HdStResourceRegistrySharedPtr _registry;
|
||||
|
||||
size_t _shaderSourceHash;
|
||||
HdBufferArrayRangeSharedPtrVector _inputs;
|
||||
HdStGLSLProgramSharedPtr _computeProgram;
|
||||
HdSt_ResourceBinder _resourceBinder;
|
||||
|
||||
HdStExtCompGpuComputationResource() = delete;
|
||||
HdStExtCompGpuComputationResource(
|
||||
const HdStExtCompGpuComputationResource &) = delete;
|
||||
HdStExtCompGpuComputationResource &operator = (
|
||||
const HdStExtCompGpuComputationResource &) = delete;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_ST_EXT_COMP_GPU_COMPUTATION_RESOURCE_H
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
//
|
||||
// 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_ST_EXT_COMP_GPU_PRIMVAR_BUFFER_SOURCE_H
|
||||
#define PXR_IMAGING_HD_ST_EXT_COMP_GPU_PRIMVAR_BUFFER_SOURCE_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/imaging/hd/bufferSource.h"
|
||||
#include "pxr/imaging/hd/types.h"
|
||||
|
||||
#include "pxr/base/tf/token.h"
|
||||
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// \class HdStExtCompGpuPrimvarBufferSource
|
||||
/// A buffer source mapped to an output of an ExtComp CPU computation.
|
||||
///
|
||||
class HdStExtCompGpuPrimvarBufferSource final : public HdNullBufferSource {
|
||||
public:
|
||||
HdStExtCompGpuPrimvarBufferSource(TfToken const & name,
|
||||
HdTupleType const & valueType,
|
||||
int numElements,
|
||||
SdfPath const& compId);
|
||||
|
||||
HDST_API
|
||||
virtual ~HdStExtCompGpuPrimvarBufferSource() = default;
|
||||
|
||||
HDST_API
|
||||
virtual size_t ComputeHash() const override;
|
||||
|
||||
HDST_API
|
||||
virtual bool Resolve() override;
|
||||
|
||||
HD_API
|
||||
virtual TfToken const &GetName() const override;
|
||||
|
||||
HDST_API
|
||||
virtual size_t GetNumElements() const override;
|
||||
|
||||
HD_API
|
||||
virtual HdTupleType GetTupleType() const override;
|
||||
|
||||
HDST_API
|
||||
virtual void GetBufferSpecs(HdBufferSpecVector *specs) const override;
|
||||
|
||||
protected:
|
||||
virtual bool _CheckValid() const override;
|
||||
|
||||
private:
|
||||
TfToken _name;
|
||||
HdTupleType _tupleType;
|
||||
size_t _numElements;
|
||||
SdfPath _compId;
|
||||
|
||||
HdStExtCompGpuPrimvarBufferSource() = delete;
|
||||
HdStExtCompGpuPrimvarBufferSource(
|
||||
const HdStExtCompGpuPrimvarBufferSource &) = delete;
|
||||
HdStExtCompGpuPrimvarBufferSource &operator = (
|
||||
const HdStExtCompGpuPrimvarBufferSource &) = delete;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_ST_EXT_COMP_GPU_PRIMVAR_BUFFER_SOURCE_H
|
||||
@@ -0,0 +1,78 @@
|
||||
//
|
||||
// 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_ST_EXT_COMPUTATION_H
|
||||
#define PXR_IMAGING_HD_ST_EXT_COMPUTATION_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/imaging/hd/extComputation.h"
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
#include "pxr/base/vt/value.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdSceneDelegate;
|
||||
using HdBufferArrayRangeSharedPtr = std::shared_ptr<class HdBufferArrayRange>;
|
||||
|
||||
/// \class HdStExtComputation
|
||||
///
|
||||
/// Specialization of HdExtComputation which manages inputs as GPU resources.
|
||||
///
|
||||
class HdStExtComputation : public HdExtComputation
|
||||
{
|
||||
public:
|
||||
/// Construct a new ExtComputation identified by id.
|
||||
HDST_API
|
||||
HdStExtComputation(SdfPath const &id);
|
||||
|
||||
HDST_API
|
||||
~HdStExtComputation() override;
|
||||
|
||||
HDST_API
|
||||
void Sync(HdSceneDelegate *sceneDelegate,
|
||||
HdRenderParam *renderParam,
|
||||
HdDirtyBits *dirtyBits) override;
|
||||
|
||||
HDST_API
|
||||
void Finalize(HdRenderParam *renderParam) override;
|
||||
|
||||
HDST_API
|
||||
HdBufferArrayRangeSharedPtr const & GetInputRange() const {
|
||||
return _inputRange;
|
||||
}
|
||||
|
||||
private:
|
||||
// No default construction or copying
|
||||
HdStExtComputation() = delete;
|
||||
HdStExtComputation(const HdStExtComputation &) = delete;
|
||||
HdStExtComputation &operator =(const HdStExtComputation &) = delete;
|
||||
|
||||
HdBufferArrayRangeSharedPtr _inputRange;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_ST_EXT_COMPUTATION_H
|
||||
@@ -0,0 +1,79 @@
|
||||
//
|
||||
// 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_ST_FALLBACK_LIGHTING_SHADER_H
|
||||
#define PXR_IMAGING_HD_ST_FALLBACK_LIGHTING_SHADER_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/imaging/hdSt/lightingShader.h"
|
||||
|
||||
#include "pxr/base/gf/vec4d.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HioGlslfx;
|
||||
|
||||
/// \class HdSt_FallbackLightingShader
|
||||
///
|
||||
/// A shader that provides fallback lighting behavior.
|
||||
///
|
||||
class HdSt_FallbackLightingShader : public HdStLightingShader
|
||||
{
|
||||
public:
|
||||
HDST_API
|
||||
HdSt_FallbackLightingShader();
|
||||
HDST_API
|
||||
~HdSt_FallbackLightingShader() override;
|
||||
|
||||
// HdStShaderCode overrides
|
||||
HDST_API
|
||||
ID ComputeHash() const override;
|
||||
HDST_API
|
||||
std::string GetSource(TfToken const &shaderStageKey) const override;
|
||||
HDST_API
|
||||
void BindResources(int program,
|
||||
HdSt_ResourceBinder const &binder,
|
||||
HdRenderPassState const &state) override;
|
||||
HDST_API
|
||||
void UnbindResources(int program,
|
||||
HdSt_ResourceBinder const &binder,
|
||||
HdRenderPassState const &state) override;
|
||||
HDST_API
|
||||
void AddBindings(HdBindingRequestVector *customBindings) override;
|
||||
|
||||
// HdStLightingShader overrides
|
||||
HDST_API
|
||||
void SetCamera(GfMatrix4d const &worldToViewMatrix,
|
||||
GfMatrix4d const &projectionMatrix) override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<HioGlslfx> _glslfx;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_ST_FALLBACK_LIGHTING_SHADER_H
|
||||
@@ -0,0 +1,84 @@
|
||||
//
|
||||
// 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_ST_FIELD_H
|
||||
#define PXR_IMAGING_HD_ST_FIELD_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/field.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
|
||||
#include "pxr/imaging/hdSt/textureIdentifier.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
///
|
||||
/// Represents a Field Buffer Prim.
|
||||
///
|
||||
class HdStField : public HdField {
|
||||
public:
|
||||
/// For now, only fieldType HdStTokens->openvdbAsset is supported.
|
||||
HDST_API
|
||||
HdStField(SdfPath const & id, TfToken const & fieldType);
|
||||
HDST_API
|
||||
~HdStField() override;
|
||||
|
||||
/// Loads field as 3d texture to generate GetFieldResource.
|
||||
HDST_API
|
||||
void Sync(HdSceneDelegate *sceneDelegate,
|
||||
HdRenderParam *renderParam,
|
||||
HdDirtyBits *dirtyBits) override;
|
||||
|
||||
HDST_API
|
||||
HdDirtyBits GetInitialDirtyBitsMask() const override;
|
||||
|
||||
/// Initialized by Sync.
|
||||
HDST_API
|
||||
HdStTextureIdentifier const &GetTextureIdentifier() const {
|
||||
return _textureId;
|
||||
}
|
||||
|
||||
/// Get memory request for this field
|
||||
size_t GetTextureMemory() const { return _textureMemory; }
|
||||
|
||||
/// Bprim types handled by this class
|
||||
HDST_API
|
||||
static const TfTokenVector &GetSupportedBprimTypes();
|
||||
|
||||
/// Can bprim type be handled by this class
|
||||
HDST_API
|
||||
static bool IsSupportedBprimType(const TfToken &bprimType);
|
||||
|
||||
private:
|
||||
const TfToken _fieldType;
|
||||
|
||||
HdStTextureIdentifier _textureId;
|
||||
size_t _textureMemory;
|
||||
|
||||
bool _isInitialized : 1;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif //PXR_IMAGING_HD_ST_FIELD_H
|
||||
@@ -0,0 +1,105 @@
|
||||
//
|
||||
// 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_ST_FIELD_SUBTEXTURE_IDENTIFIER_H
|
||||
#define PXR_IMAGING_HD_ST_FIELD_SUBTEXTURE_IDENTIFIER_H
|
||||
|
||||
#include "pxr/imaging/hdSt/subtextureIdentifier.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
///
|
||||
/// \class HdStOpenVDBAssetSubtextureIdentifier
|
||||
///
|
||||
/// Identifies a grid in an OpenVDB file. Parallels OpenVDBAsset in usdVol.
|
||||
///
|
||||
class HdStOpenVDBAssetSubtextureIdentifier final
|
||||
: public HdStFieldBaseSubtextureIdentifier
|
||||
{
|
||||
public:
|
||||
/// C'tor
|
||||
///
|
||||
/// fieldName corresponds to the gridName in the OpenVDB file.
|
||||
///
|
||||
HDST_API
|
||||
explicit HdStOpenVDBAssetSubtextureIdentifier(
|
||||
TfToken const &fieldName,
|
||||
int fieldIndex);
|
||||
|
||||
HDST_API
|
||||
std::unique_ptr<HdStSubtextureIdentifier> Clone() const override;
|
||||
|
||||
HDST_API
|
||||
~HdStOpenVDBAssetSubtextureIdentifier() override;
|
||||
|
||||
protected:
|
||||
HDST_API
|
||||
ID _Hash() const override;
|
||||
};
|
||||
|
||||
///
|
||||
/// \class HdStField3DAssetSubtextureIdentifier
|
||||
///
|
||||
/// Identifies the grid in a Field3DAsset file.
|
||||
/// Parallels Field3DAsset in usdVol.
|
||||
///
|
||||
class HdStField3DAssetSubtextureIdentifier final
|
||||
: public HdStFieldBaseSubtextureIdentifier
|
||||
{
|
||||
public:
|
||||
/// C'tor
|
||||
///
|
||||
/// fieldName corresponds (e.g., density) to the
|
||||
/// layer/attribute name in the Field3D file
|
||||
/// fieldIndex corresponds to the
|
||||
/// partition index
|
||||
/// fieldPurpose (e.g., BigCloud) corresponds to the
|
||||
/// partition name/grouping
|
||||
///
|
||||
HDST_API
|
||||
explicit HdStField3DAssetSubtextureIdentifier(
|
||||
TfToken const &fieldName,
|
||||
int fieldIndex,
|
||||
TfToken const &fieldPurpose);
|
||||
|
||||
HDST_API
|
||||
std::unique_ptr<HdStSubtextureIdentifier> Clone() const override;
|
||||
|
||||
HDST_API
|
||||
TfToken const &GetFieldPurpose() const { return _fieldPurpose; }
|
||||
|
||||
HDST_API
|
||||
~HdStField3DAssetSubtextureIdentifier() override;
|
||||
|
||||
protected:
|
||||
HDST_API
|
||||
ID _Hash() const override;
|
||||
|
||||
private:
|
||||
TfToken _fieldPurpose;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,78 @@
|
||||
//
|
||||
// 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_ST_FLAT_NORMALS_H
|
||||
#define PXR_IMAGING_HD_ST_FLAT_NORMALS_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/imaging/hd/bufferSource.h"
|
||||
#include "pxr/imaging/hd/computation.h"
|
||||
|
||||
#include "pxr/base/tf/token.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
class Hd_FaceCoords;
|
||||
|
||||
/// flat normal computation GPU
|
||||
///
|
||||
///
|
||||
class HdSt_FlatNormalsComputationGPU : public HdComputation {
|
||||
public:
|
||||
|
||||
/// Constructor
|
||||
HDST_API
|
||||
HdSt_FlatNormalsComputationGPU(HdBufferArrayRangeSharedPtr const
|
||||
&topologyRange,
|
||||
HdBufferArrayRangeSharedPtr const
|
||||
&vertexRange,
|
||||
int numFaces,
|
||||
TfToken const &srcName,
|
||||
TfToken const &dstName,
|
||||
HdType srcDataType,
|
||||
bool packed);
|
||||
|
||||
HDST_API
|
||||
virtual void GetBufferSpecs(HdBufferSpecVector *specs) const override;
|
||||
HDST_API
|
||||
virtual void Execute(HdBufferArrayRangeSharedPtr const &range,
|
||||
HdResourceRegistry *resourceRegistry) override;
|
||||
|
||||
virtual int GetNumOutputElements() const override;
|
||||
|
||||
private:
|
||||
HdBufferArrayRangeSharedPtr const _topologyRange;
|
||||
HdBufferArrayRangeSharedPtr const _vertexRange;
|
||||
int _numFaces;
|
||||
TfToken _srcName;
|
||||
TfToken _dstName;
|
||||
HdType _srcDataType;
|
||||
HdType _dstDataType;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_ST_FLAT_NORMALS_H
|
||||
@@ -0,0 +1,250 @@
|
||||
//
|
||||
// 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_ST_GEOMETRIC_SHADER_H
|
||||
#define PXR_IMAGING_HD_ST_GEOMETRIC_SHADER_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/enums.h"
|
||||
#include "pxr/imaging/hdSt/shaderCode.h"
|
||||
#include "pxr/imaging/hdSt/resourceRegistry.h"
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
#include "pxr/imaging/garch/glApi.h"
|
||||
#include "pxr/imaging/hio/glslfx.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
using HdSt_GeometricShaderSharedPtr =
|
||||
std::shared_ptr<class HdSt_GeometricShader>;
|
||||
struct HdSt_ShaderKey;
|
||||
|
||||
/// \class HdSt_GeometricShader
|
||||
///
|
||||
/// Storm breaks down the concept of a shader program into distinct
|
||||
/// conceptual pieces that are then stitched together during code generation.
|
||||
/// The pieces are:
|
||||
/// (i) geometric shader
|
||||
/// (ii) material shader
|
||||
/// (iii) lighting shader
|
||||
/// (iv) render pass shader
|
||||
///
|
||||
/// The geometric shader contains the entry points for the relevant shader
|
||||
/// stages and uses geometry opinions (such as cullstyle, double sided, etc)
|
||||
/// to generate shader code variants via mixins.
|
||||
///
|
||||
class HdSt_GeometricShader : public HdStShaderCode {
|
||||
public:
|
||||
/// Used in HdSt_CodeGen to generate the appropriate shader source
|
||||
enum class PrimitiveType {
|
||||
PRIM_POINTS,
|
||||
PRIM_BASIS_CURVES_LINES, // when linear (or) non-refined cubic
|
||||
PRIM_BASIS_CURVES_LINEAR_PATCHES, // refined linear curves
|
||||
PRIM_BASIS_CURVES_CUBIC_PATCHES, // refined cubic curves
|
||||
PRIM_MESH_COARSE_TRIANGLES,
|
||||
PRIM_MESH_REFINED_TRIANGLES, // e.g: loop subdiv
|
||||
PRIM_MESH_COARSE_QUADS, // e.g: quadrangulation for ptex
|
||||
PRIM_MESH_REFINED_QUADS, // e.g: catmark/bilinear subdiv
|
||||
PRIM_MESH_BSPLINE, // e.g. catmark limit surface patches
|
||||
PRIM_MESH_BOXSPLINETRIANGLE, // e.g. loop limit surface patches
|
||||
PRIM_VOLUME // Simply draws triangles of bounding
|
||||
// box of a volume.
|
||||
};
|
||||
|
||||
/// static query functions for PrimitiveType
|
||||
static inline bool IsPrimTypePoints (PrimitiveType primType) {
|
||||
return primType == PrimitiveType::PRIM_POINTS;
|
||||
}
|
||||
|
||||
static inline bool IsPrimTypeBasisCurves(PrimitiveType primType) {
|
||||
return (primType == PrimitiveType::PRIM_BASIS_CURVES_LINES ||
|
||||
primType == PrimitiveType::PRIM_BASIS_CURVES_CUBIC_PATCHES ||
|
||||
primType == PrimitiveType::PRIM_BASIS_CURVES_LINEAR_PATCHES);
|
||||
}
|
||||
|
||||
static inline bool IsPrimTypeMesh(PrimitiveType primType) {
|
||||
return (primType == PrimitiveType::PRIM_MESH_COARSE_TRIANGLES ||
|
||||
primType == PrimitiveType::PRIM_MESH_REFINED_TRIANGLES ||
|
||||
primType == PrimitiveType::PRIM_MESH_COARSE_QUADS ||
|
||||
primType == PrimitiveType::PRIM_MESH_REFINED_QUADS ||
|
||||
primType == PrimitiveType::PRIM_MESH_BSPLINE ||
|
||||
primType == PrimitiveType::PRIM_MESH_BOXSPLINETRIANGLE);
|
||||
}
|
||||
|
||||
static inline bool IsPrimTypeTriangles(PrimitiveType primType) {
|
||||
return (primType == PrimitiveType::PRIM_MESH_COARSE_TRIANGLES ||
|
||||
primType == PrimitiveType::PRIM_MESH_REFINED_TRIANGLES ||
|
||||
primType == PrimitiveType::PRIM_VOLUME);
|
||||
}
|
||||
|
||||
static inline bool IsPrimTypeQuads(PrimitiveType primType) {
|
||||
return (primType == PrimitiveType::PRIM_MESH_COARSE_QUADS ||
|
||||
primType == PrimitiveType::PRIM_MESH_REFINED_QUADS);
|
||||
}
|
||||
|
||||
static inline bool IsPrimTypeRefinedMesh(PrimitiveType primType) {
|
||||
return (primType == PrimitiveType::PRIM_MESH_REFINED_TRIANGLES ||
|
||||
primType == PrimitiveType::PRIM_MESH_REFINED_QUADS ||
|
||||
primType == PrimitiveType::PRIM_MESH_BSPLINE ||
|
||||
primType == PrimitiveType::PRIM_MESH_BOXSPLINETRIANGLE);
|
||||
}
|
||||
|
||||
static inline bool IsPrimTypePatches(PrimitiveType primType) {
|
||||
return primType == PrimitiveType::PRIM_MESH_BSPLINE ||
|
||||
primType == PrimitiveType::PRIM_MESH_BOXSPLINETRIANGLE ||
|
||||
primType == PrimitiveType::PRIM_BASIS_CURVES_CUBIC_PATCHES ||
|
||||
primType == PrimitiveType::PRIM_BASIS_CURVES_LINEAR_PATCHES;
|
||||
}
|
||||
|
||||
// Face-varying patch type
|
||||
enum class FvarPatchType {
|
||||
PATCH_COARSE_TRIANGLES,
|
||||
PATCH_REFINED_TRIANGLES,
|
||||
PATCH_COARSE_QUADS,
|
||||
PATCH_REFINED_QUADS,
|
||||
PATCH_BSPLINE,
|
||||
PATCH_BOXSPLINETRIANGLE,
|
||||
PATCH_NONE
|
||||
};
|
||||
|
||||
HDST_API
|
||||
HdSt_GeometricShader(std::string const &glslfxString,
|
||||
PrimitiveType primType,
|
||||
HdCullStyle cullStyle,
|
||||
bool useHardwareFaceCulling,
|
||||
bool hasMirroredTransform,
|
||||
bool doubleSided,
|
||||
HdPolygonMode polygonMode,
|
||||
bool cullingPass,
|
||||
FvarPatchType fvarPatchType,
|
||||
SdfPath const &debugId = SdfPath(),
|
||||
float lineWidth = 0);
|
||||
|
||||
HDST_API
|
||||
~HdSt_GeometricShader() override;
|
||||
|
||||
// HdShader overrides
|
||||
HDST_API
|
||||
ID ComputeHash() const override;
|
||||
HDST_API
|
||||
std::string GetSource(TfToken const &shaderStageKey) const override;
|
||||
HDST_API
|
||||
void BindResources(int program,
|
||||
HdSt_ResourceBinder const &binder,
|
||||
HdRenderPassState const &state) override;
|
||||
|
||||
HDST_API
|
||||
void UnbindResources(int program,
|
||||
HdSt_ResourceBinder const &binder,
|
||||
HdRenderPassState const &state) override;
|
||||
HDST_API
|
||||
void AddBindings(HdBindingRequestVector *customBindings) override;
|
||||
|
||||
/// Returns true if this geometric shader is used for GPU frustum culling.
|
||||
bool IsFrustumCullingPass() const {
|
||||
return _frustumCullingPass;
|
||||
}
|
||||
|
||||
PrimitiveType GetPrimitiveType() const {
|
||||
return _primType;
|
||||
}
|
||||
|
||||
/// member query functions for PrimitiveType
|
||||
inline bool IsPrimTypePoints() const {
|
||||
return IsPrimTypePoints(_primType);
|
||||
}
|
||||
|
||||
inline bool IsPrimTypeBasisCurves() const {
|
||||
return IsPrimTypeBasisCurves(_primType);
|
||||
}
|
||||
|
||||
inline bool IsPrimTypeMesh() const {
|
||||
return IsPrimTypeMesh(_primType);
|
||||
}
|
||||
|
||||
inline bool IsPrimTypeTriangles() const {
|
||||
return IsPrimTypeTriangles(_primType);
|
||||
}
|
||||
|
||||
inline bool IsPrimTypeQuads() const {
|
||||
return IsPrimTypeQuads(_primType);
|
||||
}
|
||||
|
||||
inline bool IsPrimTypePatches() const {
|
||||
return IsPrimTypePatches(_primType);
|
||||
}
|
||||
|
||||
FvarPatchType GetFvarPatchType() const {
|
||||
return _fvarPatchType;
|
||||
}
|
||||
|
||||
/// Return the GL primitive type of the draw item based on _primType
|
||||
HDST_API
|
||||
GLenum GetPrimitiveMode() const;
|
||||
|
||||
// Returns the primitive index size based on the primitive mode
|
||||
// 3 for triangles, 4 for quads, 16 for regular b-spline patches etc.
|
||||
HDST_API
|
||||
int GetPrimitiveIndexSize() const;
|
||||
|
||||
// Returns the number of vertices output for patch evaluation,
|
||||
// i.e. the number of tessellation control shader invocations.
|
||||
HDST_API
|
||||
int GetNumPatchEvalVerts() const;
|
||||
|
||||
// Returns the primitive index size for the geometry shader shade
|
||||
// 1 for points, 2 for lines, 3 for triangles, 4 for lines_adjacency
|
||||
HDST_API
|
||||
int GetNumPrimitiveVertsForGeometryShader() const;
|
||||
|
||||
// Factory for convenience.
|
||||
static HdSt_GeometricShaderSharedPtr Create(
|
||||
HdSt_ShaderKey const &shaderKey,
|
||||
HdStResourceRegistrySharedPtr const &resourceRegistry);
|
||||
|
||||
private:
|
||||
PrimitiveType _primType;
|
||||
HdCullStyle _cullStyle;
|
||||
bool _useHardwareFaceCulling;
|
||||
bool _hasMirroredTransform;
|
||||
bool _doubleSided;
|
||||
HdPolygonMode _polygonMode;
|
||||
float _lineWidth;
|
||||
|
||||
std::unique_ptr<HioGlslfx> _glslfx;
|
||||
bool _frustumCullingPass;
|
||||
FvarPatchType _fvarPatchType;
|
||||
ID _hash;
|
||||
|
||||
// No copying
|
||||
HdSt_GeometricShader(const HdSt_GeometricShader &) = delete;
|
||||
HdSt_GeometricShader &operator =(const HdSt_GeometricShader &) = delete;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_ST_GEOMETRIC_SHADER_H
|
||||
@@ -0,0 +1,69 @@
|
||||
//
|
||||
// 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_ST_GL_CONVERSIONS_H
|
||||
#define PXR_IMAGING_HD_ST_GL_CONVERSIONS_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/imaging/hd/enums.h"
|
||||
#include "pxr/imaging/hd/types.h"
|
||||
#include "pxr/imaging/hio/types.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
class HdStGLConversions {
|
||||
public:
|
||||
HDST_API
|
||||
static GLenum GetGlDepthFunc(HdCompareFunction func);
|
||||
|
||||
HDST_API
|
||||
static GLenum GetGlStencilFunc(HdCompareFunction func);
|
||||
|
||||
HDST_API
|
||||
static GLenum GetGlStencilOp(HdStencilOp op);
|
||||
|
||||
HDST_API
|
||||
static GLenum GetGlBlendOp(HdBlendOp op);
|
||||
|
||||
HDST_API
|
||||
static GLenum GetGlBlendFactor(HdBlendFactor factor);
|
||||
|
||||
HDST_API
|
||||
static int GetGLAttribType(HdType type);
|
||||
|
||||
/// Return the name of the given type as represented in GLSL.
|
||||
HDST_API
|
||||
static TfToken GetGLSLTypename(HdType type);
|
||||
|
||||
/// Return a GLSL-safe, mangled name identifier.
|
||||
HDST_API
|
||||
static TfToken GetGLSLIdentifier(TfToken const& identifier);
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_ST_GL_CONVERSIONS_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_ST_GL_UTILS_H
|
||||
#define PXR_IMAGING_HD_ST_GL_UTILS_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/imaging/hd/types.h"
|
||||
#include "pxr/imaging/hgi/buffer.h"
|
||||
|
||||
#include "pxr/base/vt/value.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdStGLUtils {
|
||||
public:
|
||||
|
||||
/// Reads the content of VBO back to VtArray.
|
||||
/// The \p vboOffset is expressed in bytes.
|
||||
HDST_API
|
||||
static VtValue ReadBuffer(uint64_t vbo,
|
||||
HdTupleType tupleType,
|
||||
int vboOffset,
|
||||
int stride,
|
||||
int numElements);
|
||||
};
|
||||
|
||||
/// \class HdStBufferRelocator
|
||||
///
|
||||
/// A utility class to perform batched buffer copy.
|
||||
///
|
||||
class HdStBufferRelocator {
|
||||
public:
|
||||
HdStBufferRelocator(
|
||||
HgiBufferHandle const& srcBuffer, HgiBufferHandle const& dstBuffer) :
|
||||
_srcBuffer(srcBuffer), _dstBuffer(dstBuffer) {}
|
||||
|
||||
/// Schedule the range to be copied. The consecutive ranges could be
|
||||
/// aggregated into a single copy where possible.
|
||||
HDST_API
|
||||
void AddRange(ptrdiff_t readOffset,
|
||||
ptrdiff_t writeOffset,
|
||||
ptrdiff_t copySize);
|
||||
|
||||
/// Execute Hgi buffer copy command to flush all scheduled range copies.
|
||||
HDST_API
|
||||
void Commit(class HgiBlitCmds* blitCmds);
|
||||
|
||||
private:
|
||||
struct _CopyUnit {
|
||||
_CopyUnit(ptrdiff_t read, ptrdiff_t write, ptrdiff_t size)
|
||||
: readOffset(read), writeOffset(write), copySize(size) {}
|
||||
|
||||
bool Concat(_CopyUnit const &next) {
|
||||
if (readOffset + copySize == next.readOffset &&
|
||||
writeOffset + copySize == next.writeOffset) {
|
||||
copySize += next.copySize;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
ptrdiff_t readOffset;
|
||||
ptrdiff_t writeOffset;
|
||||
ptrdiff_t copySize;
|
||||
};
|
||||
|
||||
std::vector<_CopyUnit> _queue;
|
||||
HgiBufferHandle _srcBuffer;
|
||||
HgiBufferHandle _dstBuffer;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_ST_GL_UTILS_H
|
||||
@@ -0,0 +1,118 @@
|
||||
//
|
||||
// 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_ST_GLSL_PROGRAM_H
|
||||
#define PXR_IMAGING_HD_ST_GLSL_PROGRAM_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/imaging/hgi/buffer.h"
|
||||
#include "pxr/imaging/hgi/shaderProgram.h"
|
||||
#include "pxr/imaging/hgi/enums.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdStResourceRegistry;
|
||||
using HdStGLSLProgramSharedPtr = std::shared_ptr<class HdStGLSLProgram>;
|
||||
|
||||
using HgiShaderProgramHandle = HgiHandle<class HgiShaderProgram>;
|
||||
|
||||
/// \class HdStGLSLProgram
|
||||
///
|
||||
/// An instance of a glsl program.
|
||||
///
|
||||
class HdStGLSLProgram final
|
||||
{
|
||||
public:
|
||||
typedef size_t ID;
|
||||
|
||||
HDST_API
|
||||
HdStGLSLProgram(TfToken const &role, HdStResourceRegistry*const registry);
|
||||
HDST_API
|
||||
~HdStGLSLProgram();
|
||||
|
||||
/// Compile shader source for a shader stage.
|
||||
HDST_API
|
||||
bool CompileShader(HgiShaderStage stage, std::string const & source);
|
||||
|
||||
/// Link the compiled shaders together.
|
||||
HDST_API
|
||||
bool Link();
|
||||
|
||||
/// Validate if this program is a valid progam in the current context.
|
||||
HDST_API
|
||||
bool Validate() const;
|
||||
|
||||
/// Returns HdResource of the program object.
|
||||
HgiShaderProgramHandle const &GetProgram() const { return _program; }
|
||||
|
||||
/// Convenience method to get a shared compute shader program
|
||||
HDST_API
|
||||
static HdStGLSLProgramSharedPtr GetComputeProgram(
|
||||
TfToken const &shaderToken,
|
||||
HdStResourceRegistry *resourceRegistry);
|
||||
|
||||
HDST_API
|
||||
static HdStGLSLProgramSharedPtr GetComputeProgram(
|
||||
TfToken const &shaderFileName,
|
||||
TfToken const &shaderToken,
|
||||
HdStResourceRegistry *resourceRegistry);
|
||||
|
||||
using PopulateDescriptorCallback =
|
||||
std::function<void(HgiShaderFunctionDesc &computeDesc)>;
|
||||
|
||||
HDST_API
|
||||
static HdStGLSLProgramSharedPtr GetComputeProgram(
|
||||
TfToken const &shaderToken,
|
||||
HdStResourceRegistry *resourceRegistry,
|
||||
PopulateDescriptorCallback populateDescriptor);
|
||||
|
||||
HDST_API
|
||||
static HdStGLSLProgramSharedPtr GetComputeProgram(
|
||||
TfToken const &shaderToken,
|
||||
std::string const &defines,
|
||||
HdStResourceRegistry *resourceRegistry,
|
||||
PopulateDescriptorCallback populateDescriptor);
|
||||
|
||||
/// Returns the role of the GPU data in this resource.
|
||||
TfToken const & GetRole() const {return _role;}
|
||||
|
||||
private:
|
||||
HdStResourceRegistry *const _registry;
|
||||
TfToken _role;
|
||||
|
||||
HgiShaderProgramDesc _programDesc;
|
||||
HgiShaderProgramHandle _program;
|
||||
|
||||
// An identifier for uniquely identifying the program, for debugging
|
||||
// purposes - programs that fail to compile for one reason or another
|
||||
// will get deleted, and their GL program IDs reused, so we can't use
|
||||
// that to identify it uniquely
|
||||
size_t _debugID;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_ST_GLSL_PROGRAM_H
|
||||
@@ -0,0 +1,60 @@
|
||||
//
|
||||
// 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_ST_GLSLFX_SHADER_H
|
||||
#define PXR_IMAGING_HD_ST_GLSLFX_SHADER_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hdSt/materialNetworkShader.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
using HioGlslfxSharedPtr = std::shared_ptr<class HioGlslfx>;
|
||||
|
||||
/// \class HdStGLSLFXShader
|
||||
///
|
||||
/// A simple specialization of HdSt_MaterialNetworkShader used to
|
||||
/// load the built-in fallback material network.
|
||||
///
|
||||
class HdStGLSLFXShader final : public HdSt_MaterialNetworkShader
|
||||
{
|
||||
public:
|
||||
HDST_API
|
||||
HdStGLSLFXShader(HioGlslfxSharedPtr const& glslfx);
|
||||
HDST_API
|
||||
~HdStGLSLFXShader() override;
|
||||
|
||||
/// If the prim is based on asset, reload that asset.
|
||||
HDST_API
|
||||
void Reload() override;
|
||||
|
||||
private:
|
||||
HioGlslfxSharedPtr _glslfx;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif //PXR_IMAGING_HD_ST_GLSLFX_SHADER_H
|
||||
@@ -0,0 +1,64 @@
|
||||
//
|
||||
// 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_ST_HGI_CONVERSIONS_H
|
||||
#define PXR_IMAGING_HD_ST_HGI_CONVERSIONS_H
|
||||
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/imaging/hd/types.h"
|
||||
#include "pxr/imaging/hgi/types.h"
|
||||
#include "pxr/imaging/hgi/enums.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
///
|
||||
/// \class HdStHgiConversions
|
||||
///
|
||||
/// Converts from Hd types to Hgi types
|
||||
///
|
||||
class HdStHgiConversions
|
||||
{
|
||||
public:
|
||||
|
||||
HDST_API
|
||||
static HgiFormat GetHgiFormat(HdFormat hdFormat);
|
||||
|
||||
HDST_API
|
||||
static HgiSamplerAddressMode GetHgiSamplerAddressMode(HdWrap hdWrap);
|
||||
|
||||
HDST_API
|
||||
static HgiSamplerFilter GetHgiMagFilter(HdMagFilter hdMagFilter);
|
||||
|
||||
/// The HdMinFilter translates into two Hgi enums for
|
||||
/// HgiSamplerDesc::minFilter and HgiSamplerDesc::mipFilter.
|
||||
///
|
||||
HDST_API
|
||||
static void GetHgiMinAndMipFilter(
|
||||
HdMinFilter hdMinFilter,
|
||||
HgiSamplerFilter *hgiSamplerFilter, HgiMipFilter *hgiMipFilter);
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,45 @@
|
||||
//
|
||||
// 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_ST_HIO_CONVERSIONS_H
|
||||
#define PXR_IMAGING_HD_ST_HIO_CONVERSIONS_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/imaging/hd/types.h"
|
||||
#include "pxr/imaging/hio/types.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
class HdStHioConversions
|
||||
{
|
||||
public:
|
||||
HDST_API
|
||||
static HioFormat GetHioFormat(HdFormat inFormat);
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_ST_HIO_CONVERSIONS_H
|
||||
@@ -0,0 +1,86 @@
|
||||
//
|
||||
// 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_ST_IMAGE_SHADER_RENDER_PASS_H
|
||||
#define PXR_IMAGING_HD_ST_IMAGE_SHADER_RENDER_PASS_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/imaging/hdSt/drawItemInstance.h"
|
||||
#include "pxr/imaging/hd/renderPass.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
using HdStResourceRegistrySharedPtr =
|
||||
std::shared_ptr<class HdStResourceRegistry>;
|
||||
|
||||
using HdSt_ImageShaderRenderPassSharedPtr =
|
||||
std::shared_ptr<class HdSt_ImageShaderRenderPass>;
|
||||
using HdStResourceRegistrySharedPtr =
|
||||
std::shared_ptr<class HdStResourceRegistry>;
|
||||
|
||||
class Hgi;
|
||||
|
||||
/// \class HdSt_ImageShaderRenderPass
|
||||
///
|
||||
/// A single, full-screen triangle render pass.
|
||||
/// The task that creates this RenderPass should set a RenderPassShader on the
|
||||
/// RenderPassState. The RenderPassShader is your full-screen post-effect.
|
||||
/// The benefit of using RenderPassShader is that it participates in codegen.
|
||||
/// This means your full-screen shader can use buffers created by other tasks.
|
||||
///
|
||||
class HdSt_ImageShaderRenderPass final : public HdRenderPass {
|
||||
public:
|
||||
HDST_API
|
||||
HdSt_ImageShaderRenderPass(HdRenderIndex *index,
|
||||
HdRprimCollection const &collection);
|
||||
|
||||
HDST_API
|
||||
virtual ~HdSt_ImageShaderRenderPass();
|
||||
|
||||
// Set the vertex BAR and geometric shader for the triangle.
|
||||
// This function should be called before the Execute task phase.
|
||||
HDST_API
|
||||
void SetupFullscreenTriangleDrawItem();
|
||||
protected:
|
||||
|
||||
void _Execute(HdRenderPassStateSharedPtr const &renderPassState,
|
||||
TfTokenVector const &renderTags) override;
|
||||
|
||||
private:
|
||||
// Setup a BAR for a single triangle
|
||||
void _SetupVertexPrimvarBAR(HdStResourceRegistrySharedPtr const&);
|
||||
|
||||
// We re-use the immediateBatch to draw the full-screen triangle.
|
||||
HdRprimSharedData _sharedData;
|
||||
HdStDrawItem _drawItem;
|
||||
HdStDrawItemInstance _drawItemInstance;
|
||||
HdSt_DrawBatchSharedPtr _immediateBatch;
|
||||
Hgi* _hgi;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,115 @@
|
||||
//
|
||||
// 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_ST_INSTANCER_H
|
||||
#define PXR_IMAGING_HD_ST_INSTANCER_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/imaging/hd/changeTracker.h"
|
||||
#include "pxr/imaging/hd/instancer.h"
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
#include "pxr/base/vt/array.h"
|
||||
#include "pxr/base/tf/hashmap.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdRprim;
|
||||
class HdStDrawItem;
|
||||
struct HdRprimSharedData;
|
||||
|
||||
using HdBufferArrayRangeSharedPtr = std::shared_ptr<class HdBufferArrayRange>;
|
||||
|
||||
/// \class HdStInstancer
|
||||
///
|
||||
/// HdSt implements instancing by drawing each proto multiple times with
|
||||
/// a single draw call. Application of instance primvars (like transforms)
|
||||
/// is done in shaders. Instance transforms in particular are computed in
|
||||
/// ApplyInstanceTransform in instancing.glslfx.
|
||||
///
|
||||
/// If this instancer is nested, instance indices will be computed
|
||||
/// recursively by ascending the hierarchy. HdStInstancer computes a flattened
|
||||
/// index structure for each prototype by taking the cartesian product of the
|
||||
/// instance indices at each level.
|
||||
///
|
||||
/// For example:
|
||||
/// - InstancerA draws instances [ProtoX, InstancerB, ProtoX, InstancerB]
|
||||
/// - InstancerB draws instances [ProtoY, ProtoZ, ProtoY]
|
||||
/// The flattened index for Proto Y is:
|
||||
/// [0, 0, 1]; [1, 0, 3]; [2, 2, 1]; [3, 2, 3];
|
||||
/// where the first tuple element is the position in the flattened index;
|
||||
/// the second tuple element is the position in Instancer B;
|
||||
/// and the last tuple element is the position in Instancer A.
|
||||
///
|
||||
/// The flattened index gives the number of times the proto is drawn, and the
|
||||
/// index tuple can be passed to the shader so that each instance can look up
|
||||
/// its instance primvars in the bound primvar arrays.
|
||||
|
||||
class HdStInstancer : public HdInstancer {
|
||||
public:
|
||||
/// Constructor.
|
||||
HDST_API
|
||||
HdStInstancer(HdSceneDelegate* delegate, SdfPath const &id);
|
||||
|
||||
// Updates the instance primvar buffers.
|
||||
// XXX: Note, this is currently called from rprimUtils instead of the
|
||||
// render index sync phase, so it needs to take a mutex.
|
||||
HDST_API
|
||||
void Sync(HdSceneDelegate *sceneDelegate,
|
||||
HdRenderParam *renderParam,
|
||||
HdDirtyBits *dirtyBits) override;
|
||||
|
||||
HdBufferArrayRangeSharedPtr GetInstancePrimvarRange() const {
|
||||
return _instancePrimvarRange;
|
||||
}
|
||||
|
||||
/// Populates the instance index indirection buffer for \p prototypeId and
|
||||
/// returns a flat array of instance index tuples.
|
||||
HDST_API
|
||||
VtIntArray GetInstanceIndices(SdfPath const &prototypeId);
|
||||
|
||||
protected:
|
||||
HDST_API
|
||||
void _GetInstanceIndices(SdfPath const &prototypeId,
|
||||
std::vector<VtIntArray> *instanceIndicesArray);
|
||||
|
||||
HDST_API
|
||||
void _SyncPrimvars(HdSceneDelegate *sceneDelegate,
|
||||
HdDirtyBits *dirtyBits);
|
||||
|
||||
private:
|
||||
// # of entries in an instance primvar. This should be consistent between
|
||||
// all primvars, and also consistent with the instance indices (meaning
|
||||
// no instance index is out-of-range).
|
||||
size_t _instancePrimvarNumElements;
|
||||
|
||||
// The BAR of the instance primvars for this instancer.
|
||||
// (Note: instance indices are computed per prototype and the rprim owns
|
||||
// the bar).
|
||||
HdBufferArrayRangeSharedPtr _instancePrimvarRange;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_ST_INSTANCER_H
|
||||
@@ -0,0 +1,355 @@
|
||||
//
|
||||
// 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_ST_INTERLEAVED_MEMORY_MANAGER_H
|
||||
#define PXR_IMAGING_HD_ST_INTERLEAVED_MEMORY_MANAGER_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/imaging/hdSt/bufferArrayRange.h"
|
||||
#include "pxr/imaging/hd/bufferArray.h"
|
||||
#include "pxr/imaging/hd/bufferSpec.h"
|
||||
#include "pxr/imaging/hd/bufferSource.h"
|
||||
#include "pxr/imaging/hd/resource.h"
|
||||
#include "pxr/imaging/hd/strategyBase.h"
|
||||
#include "pxr/imaging/hd/tokens.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hgi/buffer.h"
|
||||
#include "pxr/base/tf/mallocTag.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
|
||||
#include <memory>
|
||||
#include <list>
|
||||
#include <unordered_map>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdStResourceRegistry;
|
||||
struct HgiBufferCpuToGpuOp;
|
||||
|
||||
/// \class HdStInterleavedMemoryManager
|
||||
///
|
||||
/// Interleaved memory manager (base class).
|
||||
///
|
||||
class HdStInterleavedMemoryManager : public HdAggregationStrategy {
|
||||
protected:
|
||||
class _StripedInterleavedBuffer;
|
||||
|
||||
/// specialized buffer array range
|
||||
class _StripedInterleavedBufferRange : public HdStBufferArrayRange
|
||||
{
|
||||
public:
|
||||
/// Constructor.
|
||||
_StripedInterleavedBufferRange(HdStResourceRegistry* resourceRegistry)
|
||||
: HdStBufferArrayRange(resourceRegistry)
|
||||
, _stripedBuffer(nullptr)
|
||||
, _index(NOT_ALLOCATED)
|
||||
, _numElements(1) {}
|
||||
|
||||
/// Destructor.
|
||||
HDST_API
|
||||
~_StripedInterleavedBufferRange() override;
|
||||
|
||||
/// Returns true if this range is valid
|
||||
bool IsValid() const override {
|
||||
// note: a range is valid even its index is NOT_ALLOCATED.
|
||||
return (bool)_stripedBuffer;
|
||||
}
|
||||
|
||||
/// Returns true is the range has been assigned to a buffer
|
||||
HDST_API
|
||||
bool IsAssigned() const override;
|
||||
|
||||
/// Returns true if this range is marked as immutable.
|
||||
bool IsImmutable() const override;
|
||||
|
||||
/// Returns true if this needs a staging buffer for CPU to GPU copies.
|
||||
bool RequiresStaging() const override;
|
||||
|
||||
/// Resize memory area for this range. Returns true if it causes container
|
||||
/// buffer reallocation.
|
||||
HDST_API
|
||||
bool Resize(int numElements) override;
|
||||
|
||||
/// Copy source data into buffer
|
||||
HDST_API
|
||||
void CopyData(HdBufferSourceSharedPtr const &bufferSource) override;
|
||||
|
||||
/// Read back the buffer content
|
||||
HDST_API
|
||||
VtValue ReadData(TfToken const &name) const override;
|
||||
|
||||
/// Returns the offset at which this range begins in the underlying
|
||||
/// buffer array in terms of elements.
|
||||
int GetElementOffset() const override {
|
||||
return _index;
|
||||
}
|
||||
|
||||
/// Returns the byte offset at which this range begins in the underlying
|
||||
/// buffer array for the given resource.
|
||||
int GetByteOffset(TfToken const& resourceName) const override {
|
||||
TF_UNUSED(resourceName);
|
||||
if (!TF_VERIFY(_stripedBuffer) ||
|
||||
!TF_VERIFY(_index != NOT_ALLOCATED)) return 0;
|
||||
return _stripedBuffer->GetStride() * _index;
|
||||
}
|
||||
|
||||
/// Returns the number of elements
|
||||
size_t GetNumElements() const override {
|
||||
return _numElements;
|
||||
}
|
||||
|
||||
/// Returns the version of the buffer array.
|
||||
size_t GetVersion() const override {
|
||||
return _stripedBuffer->GetVersion();
|
||||
}
|
||||
|
||||
/// Increment the version of the buffer array.
|
||||
void IncrementVersion() override {
|
||||
_stripedBuffer->IncrementVersion();
|
||||
}
|
||||
|
||||
/// Returns the max number of elements
|
||||
HDST_API
|
||||
size_t GetMaxNumElements() const override;
|
||||
|
||||
/// Returns the usage hint from the underlying buffer array
|
||||
HDST_API
|
||||
HdBufferArrayUsageHint GetUsageHint() const override;
|
||||
|
||||
/// Returns the GPU resource. If the buffer array contains more than one
|
||||
/// resource, this method raises a coding error.
|
||||
HDST_API
|
||||
HdStBufferResourceSharedPtr GetResource() const override;
|
||||
|
||||
/// Returns the named GPU resource.
|
||||
HDST_API
|
||||
HdStBufferResourceSharedPtr GetResource(TfToken const& name) override;
|
||||
|
||||
/// Returns the list of all named GPU resources for this bufferArrayRange.
|
||||
HDST_API
|
||||
HdStBufferResourceNamedList const& GetResources() const override;
|
||||
|
||||
/// Sets the buffer array associated with this buffer;
|
||||
HDST_API
|
||||
void SetBufferArray(HdBufferArray *bufferArray) override;
|
||||
|
||||
/// Debug dump
|
||||
HDST_API
|
||||
void DebugDump(std::ostream &out) const override;
|
||||
|
||||
/// Set the relative offset for this range.
|
||||
void SetIndex(int index) {
|
||||
_index = index;
|
||||
}
|
||||
|
||||
/// Make this range invalid
|
||||
void Invalidate() {
|
||||
_stripedBuffer = nullptr;
|
||||
}
|
||||
|
||||
protected:
|
||||
/// Returns the aggregation container
|
||||
HDST_API
|
||||
const void *_GetAggregation() const override;
|
||||
|
||||
private:
|
||||
enum { NOT_ALLOCATED = -1 };
|
||||
_StripedInterleavedBuffer *_stripedBuffer;
|
||||
int _index;
|
||||
size_t _numElements;
|
||||
};
|
||||
|
||||
using _StripedInterleavedBufferSharedPtr =
|
||||
std::shared_ptr<_StripedInterleavedBuffer>;
|
||||
using _StripedInterleavedBufferRangeSharedPtr =
|
||||
std::shared_ptr<_StripedInterleavedBufferRange>;
|
||||
using _StripedInterleavedBufferRangePtr =
|
||||
std::weak_ptr<_StripedInterleavedBufferRange>;
|
||||
|
||||
/// striped buffer
|
||||
class _StripedInterleavedBuffer : public HdBufferArray {
|
||||
public:
|
||||
/// Constructor.
|
||||
HDST_API
|
||||
_StripedInterleavedBuffer(HdStInterleavedMemoryManager* mgr,
|
||||
HdStResourceRegistry* resourceRegistry,
|
||||
TfToken const &role,
|
||||
HdBufferSpecVector const &bufferSpecs,
|
||||
HdBufferArrayUsageHint usageHint,
|
||||
int bufferOffsetAlignment,
|
||||
int structAlignment,
|
||||
size_t maxSize,
|
||||
TfToken const &garbageCollectionPerfToken);
|
||||
|
||||
/// Destructor. It invalidates _rangeList
|
||||
HDST_API
|
||||
virtual ~_StripedInterleavedBuffer();
|
||||
|
||||
/// perform compaction if necessary, returns true if it becomes empty.
|
||||
HDST_API
|
||||
virtual bool GarbageCollect();
|
||||
|
||||
/// Debug output
|
||||
HDST_API
|
||||
virtual void DebugDump(std::ostream &out) const;
|
||||
|
||||
/// Performs reallocation.
|
||||
/// GLX context has to be set when calling this function.
|
||||
HDST_API
|
||||
virtual void Reallocate(
|
||||
std::vector<HdBufferArrayRangeSharedPtr> const &ranges,
|
||||
HdBufferArraySharedPtr const &curRangeOwner);
|
||||
|
||||
/// Mark to perform reallocation on Reallocate()
|
||||
void SetNeedsReallocation() {
|
||||
_needsReallocation = true;
|
||||
}
|
||||
|
||||
/// Mark to perform compaction on GarbageCollect()
|
||||
void SetNeedsCompaction() {
|
||||
_needsCompaction = true;
|
||||
}
|
||||
|
||||
/// Returns the stride.
|
||||
int GetStride() const {
|
||||
return _stride;
|
||||
}
|
||||
|
||||
/// TODO: We need to distinguish between the primvar types here, we should
|
||||
/// tag each HdBufferSource and HdBufferResource with Constant, Uniform,
|
||||
/// Varying, Vertex, or FaceVarying and provide accessors for the specific
|
||||
/// buffer types.
|
||||
|
||||
/// Returns the GPU resource. If the buffer array contains more than one
|
||||
/// resource, this method raises a coding error.
|
||||
HDST_API
|
||||
HdStBufferResourceSharedPtr GetResource() const;
|
||||
|
||||
/// Returns the named GPU resource. This method returns the first found
|
||||
/// resource. In HD_SAFE_MODE it checks all underlying GL buffers
|
||||
/// in _resourceMap and raises a coding error if there are more than
|
||||
/// one GL buffers exist.
|
||||
HDST_API
|
||||
HdStBufferResourceSharedPtr GetResource(TfToken const& name);
|
||||
|
||||
/// Returns the list of all named GPU resources for this bufferArray.
|
||||
HdStBufferResourceNamedList const& GetResources() const {return _resourceList;}
|
||||
|
||||
/// Reconstructs the bufferspecs and returns it (for buffer splitting)
|
||||
HDST_API
|
||||
HdBufferSpecVector GetBufferSpecs() const;
|
||||
|
||||
HdStInterleavedMemoryManager*
|
||||
GetManager() const {
|
||||
return _manager;
|
||||
}
|
||||
|
||||
protected:
|
||||
HDST_API
|
||||
void _DeallocateResources();
|
||||
|
||||
/// Adds a new, named GPU resource and returns it.
|
||||
HDST_API
|
||||
HdStBufferResourceSharedPtr _AddResource(TfToken const& name,
|
||||
HdTupleType tupleType,
|
||||
int offset,
|
||||
int stride);
|
||||
|
||||
private:
|
||||
HdStInterleavedMemoryManager* _manager;
|
||||
HdStResourceRegistry* const _resourceRegistry;
|
||||
bool _needsCompaction;
|
||||
int _stride;
|
||||
int _bufferOffsetAlignment; // ranged binding offset alignment
|
||||
size_t _maxSize; // maximum size of single buffer
|
||||
|
||||
HdStBufferResourceNamedList _resourceList;
|
||||
|
||||
_StripedInterleavedBufferRangeSharedPtr _GetRangeSharedPtr(size_t idx) const {
|
||||
return std::static_pointer_cast<_StripedInterleavedBufferRange>(GetRange(idx).lock());
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
HdStInterleavedMemoryManager(HdStResourceRegistry* resourceRegistry)
|
||||
: _resourceRegistry(resourceRegistry) {}
|
||||
|
||||
/// Factory for creating HdBufferArrayRange
|
||||
HdBufferArrayRangeSharedPtr CreateBufferArrayRange() override;
|
||||
|
||||
/// Returns the buffer specs from a given buffer array
|
||||
HdBufferSpecVector GetBufferSpecs(
|
||||
HdBufferArraySharedPtr const &bufferArray) const override;
|
||||
|
||||
/// Returns the size of the GPU memory used by the passed buffer array
|
||||
size_t GetResourceAllocation(
|
||||
HdBufferArraySharedPtr const &bufferArray,
|
||||
VtDictionary &result) const override;
|
||||
|
||||
HdStResourceRegistry* const _resourceRegistry;
|
||||
};
|
||||
|
||||
class HdStInterleavedUBOMemoryManager : public HdStInterleavedMemoryManager {
|
||||
public:
|
||||
HdStInterleavedUBOMemoryManager(HdStResourceRegistry* resourceRegistry)
|
||||
: HdStInterleavedMemoryManager(resourceRegistry) {}
|
||||
|
||||
/// Factory for creating HdBufferArray managed by
|
||||
/// HdStVBOMemoryManager aggregation.
|
||||
HDST_API
|
||||
virtual HdBufferArraySharedPtr CreateBufferArray(
|
||||
TfToken const &role,
|
||||
HdBufferSpecVector const &bufferSpecs,
|
||||
HdBufferArrayUsageHint usageHint);
|
||||
|
||||
/// Returns id for given bufferSpecs to be used for aggregation
|
||||
HDST_API
|
||||
virtual AggregationId ComputeAggregationId(
|
||||
HdBufferSpecVector const &bufferSpecs,
|
||||
HdBufferArrayUsageHint usageHint) const;
|
||||
};
|
||||
|
||||
class HdStInterleavedSSBOMemoryManager : public HdStInterleavedMemoryManager {
|
||||
public:
|
||||
HdStInterleavedSSBOMemoryManager(HdStResourceRegistry* resourceRegistry)
|
||||
: HdStInterleavedMemoryManager(resourceRegistry) {}
|
||||
|
||||
/// Factory for creating HdBufferArray managed by
|
||||
/// HdStVBOMemoryManager aggregation.
|
||||
HDST_API
|
||||
virtual HdBufferArraySharedPtr CreateBufferArray(
|
||||
TfToken const &role,
|
||||
HdBufferSpecVector const &bufferSpecs,
|
||||
HdBufferArrayUsageHint usageHint);
|
||||
|
||||
/// Returns id for given bufferSpecs to be used for aggregation
|
||||
HDST_API
|
||||
virtual AggregationId ComputeAggregationId(
|
||||
HdBufferSpecVector const &bufferSpecs,
|
||||
HdBufferArrayUsageHint usageHint) const;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_ST_INTERLEAVED_MEMORY_MANAGER_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_ST_LIGHT_H
|
||||
#define PXR_IMAGING_HD_ST_LIGHT_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/light.h"
|
||||
|
||||
#include "pxr/imaging/glf/simpleLight.h"
|
||||
|
||||
#include "pxr/base/vt/value.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// \class HdStLight
|
||||
///
|
||||
/// A light model for use in Storm.
|
||||
/// Note: This class simply stores the light parameters and relies on an
|
||||
/// external task (HdxSimpleLightTask) to upload them to the GPU.
|
||||
///
|
||||
class HdStLight final : public HdLight {
|
||||
public:
|
||||
HDST_API
|
||||
HdStLight(SdfPath const & id, TfToken const &lightType);
|
||||
HDST_API
|
||||
~HdStLight() override;
|
||||
|
||||
/// Synchronizes state from the delegate to this object.
|
||||
HDST_API
|
||||
void Sync(HdSceneDelegate *sceneDelegate,
|
||||
HdRenderParam *renderParam,
|
||||
HdDirtyBits *dirtyBits) override;
|
||||
|
||||
/// Finalizes object resources. This function might not delete resources,
|
||||
/// but it should deal with resource ownership so that the sprim is
|
||||
/// deletable.
|
||||
HDST_API
|
||||
void Finalize(HdRenderParam *renderParam) override;
|
||||
|
||||
/// Accessor for tasks to get the parameters cached in this object.
|
||||
HDST_API
|
||||
VtValue Get(TfToken const &token) const;
|
||||
|
||||
/// 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.
|
||||
HDST_API
|
||||
HdDirtyBits GetInitialDirtyBitsMask() const override;
|
||||
|
||||
private:
|
||||
// Converts area lights (sphere lights and distant lights) into
|
||||
// glfSimpleLights and inserts them in the dictionary so
|
||||
// SimpleLightTask can use them later on as if they were regular lights.
|
||||
GlfSimpleLight _ApproximateAreaLight(SdfPath const &id,
|
||||
HdSceneDelegate *sceneDelegate);
|
||||
|
||||
// Collects data such as the environment map texture path for a
|
||||
// dome light. The lighting shader is responsible for pre-calculating
|
||||
// the different textures needed for IBL.
|
||||
GlfSimpleLight _PrepareDomeLight(SdfPath const &id,
|
||||
HdSceneDelegate *sceneDelegate);
|
||||
|
||||
private:
|
||||
// Stores the internal light type of this light.
|
||||
TfToken _lightType;
|
||||
|
||||
// Cached states.
|
||||
TfHashMap<TfToken, VtValue, TfToken::HashFunctor> _params;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_ST_LIGHT_H
|
||||
@@ -0,0 +1,61 @@
|
||||
//
|
||||
// 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_ST_LIGHTING_SHADER_H
|
||||
#define PXR_IMAGING_HD_ST_LIGHTING_SHADER_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/imaging/hdSt/shaderCode.h"
|
||||
#include "pxr/base/gf/matrix4d.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
using HdStLightingShaderSharedPtr = std::shared_ptr<class HdStLightingShader>;
|
||||
|
||||
/// \class HdStLightingShader
|
||||
///
|
||||
/// A lighting shader base class.
|
||||
///
|
||||
class HdStLightingShader : public HdStShaderCode {
|
||||
public:
|
||||
HDST_API
|
||||
HdStLightingShader();
|
||||
HDST_API
|
||||
virtual ~HdStLightingShader();
|
||||
|
||||
/// Sets camera state.
|
||||
virtual void SetCamera(GfMatrix4d const &worldToViewMatrix,
|
||||
GfMatrix4d const &projectionMatrix) = 0;
|
||||
|
||||
private:
|
||||
|
||||
// No copying
|
||||
HdStLightingShader(const HdStLightingShader &) = delete;
|
||||
HdStLightingShader &operator =(const HdStLightingShader &) = delete;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_ST_LIGHTING_SHADER_H
|
||||
@@ -0,0 +1,174 @@
|
||||
//
|
||||
// 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_ST_MATERIAL_H
|
||||
#define PXR_IMAGING_HD_ST_MATERIAL_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/imaging/hdSt/materialNetwork.h"
|
||||
#include "pxr/imaging/hdSt/shaderCode.h"
|
||||
#include "pxr/imaging/hd/material.h"
|
||||
#include "pxr/imaging/hf/perfLog.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
using HdSt_MaterialNetworkShaderSharedPtr =
|
||||
std::shared_ptr<class HdSt_MaterialNetworkShader>;
|
||||
|
||||
class HioGlslfx;
|
||||
|
||||
class HdStMaterial final: public HdMaterial
|
||||
{
|
||||
public:
|
||||
HF_MALLOC_TAG_NEW("new HdStMaterial");
|
||||
|
||||
/// For volumes, the corresponding draw items do not use the
|
||||
/// HdStShaderCode produced by HdStMaterial. Instead HdStVolume is
|
||||
/// using some data from the material to produce its own HdStShaderCode
|
||||
/// based on the volume field bindings.
|
||||
struct VolumeMaterialData final
|
||||
{
|
||||
/// glslfx source code for volume
|
||||
std::string source;
|
||||
HdSt_MaterialParamVector params;
|
||||
};
|
||||
|
||||
HDST_API
|
||||
HdStMaterial(SdfPath const& id);
|
||||
HDST_API
|
||||
~HdStMaterial() override;
|
||||
|
||||
/// Synchronizes state from the delegate to this object.
|
||||
HDST_API
|
||||
void Sync(HdSceneDelegate *sceneDelegate,
|
||||
HdRenderParam *renderParam,
|
||||
HdDirtyBits *dirtyBits) override;
|
||||
|
||||
HDST_API
|
||||
void Finalize(HdRenderParam *renderParam) 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.
|
||||
HDST_API
|
||||
HdDirtyBits GetInitialDirtyBitsMask() const override;
|
||||
|
||||
/// Obtains the GLSLFX code together with supporting information
|
||||
/// such as material params and textures to render surfaces.
|
||||
HDST_API
|
||||
HdSt_MaterialNetworkShaderSharedPtr GetMaterialNetworkShader() const;
|
||||
|
||||
/// Obtains the GLSLFLX code together with material params to
|
||||
/// render volumes.
|
||||
inline const VolumeMaterialData &GetVolumeMaterialData() const;
|
||||
|
||||
/// Summary flag. Returns true if the material is bound to one or more
|
||||
/// textures and any of those textures is a ptex texture.
|
||||
/// If no textures are bound or all textures are uv textures, then
|
||||
/// the method returns false.
|
||||
inline bool HasPtex() const;
|
||||
|
||||
/// Returns true if the material specifies limit surface evaluation.
|
||||
inline bool HasLimitSurfaceEvaluation() const;
|
||||
|
||||
// Returns true if the material has a displacement terminal.
|
||||
inline bool HasDisplacement() const;
|
||||
|
||||
// Returns the material's render pass tag.
|
||||
inline const TfToken& GetMaterialTag() const;
|
||||
|
||||
/// Replaces the shader code object with an externally created one
|
||||
/// Used to set the fallback shader for prim.
|
||||
/// This class takes ownership of the passed in object.
|
||||
HDST_API
|
||||
void SetMaterialNetworkShader(
|
||||
HdSt_MaterialNetworkShaderSharedPtr &shaderCode);
|
||||
|
||||
private:
|
||||
// Processes the texture descriptors from a material network to
|
||||
// create textures using the Storm texture system.
|
||||
//
|
||||
// Adds buffer specs/sources necessary for textures, e.g., bindless
|
||||
// handles or sampling transform for field textures.
|
||||
void _ProcessTextureDescriptors(
|
||||
HdSceneDelegate * sceneDelegate,
|
||||
HdStResourceRegistrySharedPtr const& resourceRegistry,
|
||||
std::weak_ptr<HdStShaderCode> const &shaderCode,
|
||||
HdStMaterialNetwork::TextureDescriptorVector const &descs,
|
||||
HdStShaderCode::NamedTextureHandleVector * texturesFromStorm,
|
||||
HdBufferSpecVector * specs,
|
||||
HdBufferSourceSharedPtrVector * sources);
|
||||
|
||||
bool
|
||||
_GetHasLimitSurfaceEvaluation(VtDictionary const & metadata) const;
|
||||
|
||||
void _InitFallbackShader();
|
||||
|
||||
static HioGlslfx *_fallbackGlslfx;
|
||||
|
||||
HdSt_MaterialNetworkShaderSharedPtr _materialNetworkShader;
|
||||
VolumeMaterialData _volumeMaterialData;
|
||||
|
||||
bool _isInitialized : 1;
|
||||
bool _hasPtex : 1;
|
||||
bool _hasLimitSurfaceEvaluation : 1;
|
||||
bool _hasDisplacement : 1;
|
||||
|
||||
TfToken _materialTag;
|
||||
size_t _textureHash;
|
||||
|
||||
HdStMaterialNetwork _networkProcessor;
|
||||
};
|
||||
|
||||
inline bool HdStMaterial::HasPtex() const
|
||||
{
|
||||
return _hasPtex;
|
||||
}
|
||||
|
||||
inline bool HdStMaterial::HasLimitSurfaceEvaluation() const
|
||||
{
|
||||
return _hasLimitSurfaceEvaluation;
|
||||
}
|
||||
|
||||
inline bool HdStMaterial::HasDisplacement() const
|
||||
{
|
||||
return _hasDisplacement;
|
||||
}
|
||||
|
||||
inline const TfToken& HdStMaterial::GetMaterialTag() const
|
||||
{
|
||||
return _materialTag;
|
||||
}
|
||||
|
||||
inline const HdStMaterial::VolumeMaterialData &
|
||||
HdStMaterial::GetVolumeMaterialData() const {
|
||||
return _volumeMaterialData;
|
||||
}
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_ST_MATERIAL_H
|
||||
@@ -0,0 +1,122 @@
|
||||
//
|
||||
// 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_ST_MATERIAL_NETWORK_H
|
||||
#define PXR_IMAGING_HD_ST_MATERIAL_NETWORK_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/imaging/hd/material.h"
|
||||
#include "pxr/imaging/hdSt/textureIdentifier.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdStResourceRegistry;
|
||||
using HioGlslfxSharedPtr = std::shared_ptr<class HioGlslfx>;
|
||||
using HdSt_MaterialParamVector = std::vector<class HdSt_MaterialParam>;
|
||||
|
||||
/// \class HdStMaterialNetwork
|
||||
///
|
||||
/// Helps HdStMaterial process a Hydra material network into shader source code
|
||||
/// and parameters values.
|
||||
class HdStMaterialNetwork final
|
||||
{
|
||||
public:
|
||||
HDST_API
|
||||
HdStMaterialNetwork();
|
||||
|
||||
HDST_API
|
||||
~HdStMaterialNetwork();
|
||||
|
||||
/// Process a material network topology and extract all the information we
|
||||
/// need from it.
|
||||
HDST_API
|
||||
void ProcessMaterialNetwork(
|
||||
SdfPath const& materialId,
|
||||
HdMaterialNetworkMap const& hdNetworkMap,
|
||||
HdStResourceRegistry *resourceRegistry);
|
||||
|
||||
HDST_API
|
||||
TfToken const& GetMaterialTag() const;
|
||||
|
||||
HDST_API
|
||||
std::string const& GetFragmentCode() const;
|
||||
|
||||
HDST_API
|
||||
std::string const& GetVolumeCode() const;
|
||||
|
||||
HDST_API
|
||||
std::string const& GetGeometryCode() const;
|
||||
|
||||
HDST_API
|
||||
VtDictionary const& GetMetadata() const;
|
||||
|
||||
HDST_API
|
||||
HdSt_MaterialParamVector const& GetMaterialParams() const;
|
||||
|
||||
// Information necessary to allocate a texture.
|
||||
struct TextureDescriptor
|
||||
{
|
||||
// Name by which the texture will be accessed, i.e., the name
|
||||
// of the accesor for thexture will be HdGet_name(...).
|
||||
// It is generated from the input name the corresponding texture
|
||||
// node is connected to.
|
||||
TfToken name;
|
||||
HdStTextureIdentifier textureId;
|
||||
HdTextureType type;
|
||||
HdSamplerParameters samplerParameters;
|
||||
// Memory request in bytes.
|
||||
size_t memoryRequest;
|
||||
|
||||
// The texture is not just identified by a file path attribute
|
||||
// on the texture prim but there is special API to texture prim
|
||||
// to obtain the texture.
|
||||
//
|
||||
// This is used for draw targets.
|
||||
bool useTexturePrimToFindTexture;
|
||||
// This is used for draw targets and hashing.
|
||||
SdfPath texturePrim;
|
||||
};
|
||||
|
||||
using TextureDescriptorVector = std::vector<TextureDescriptor>;
|
||||
|
||||
HDST_API
|
||||
TextureDescriptorVector const& GetTextureDescriptors() const;
|
||||
|
||||
private:
|
||||
TfToken _materialTag;
|
||||
std::string _fragmentSource;
|
||||
std::string _volumeSource;
|
||||
std::string _geometrySource;
|
||||
VtDictionary _materialMetadata;
|
||||
HdSt_MaterialParamVector _materialParams;
|
||||
TextureDescriptorVector _textureDescriptors;
|
||||
HioGlslfxSharedPtr _surfaceGfx;
|
||||
size_t _surfaceGfxHash;
|
||||
};
|
||||
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,355 @@
|
||||
//
|
||||
// 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_ST_MESH_H
|
||||
#define PXR_IMAGING_HD_ST_MESH_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/changeTracker.h"
|
||||
#include "pxr/imaging/hd/drawingCoord.h"
|
||||
#include "pxr/imaging/hd/mesh.h"
|
||||
#include "pxr/imaging/hd/perfLog.h"
|
||||
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
#include "pxr/base/vt/array.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
class HdStDrawItem;
|
||||
class HdSceneDelegate;
|
||||
|
||||
using Hd_VertexAdjacencySharedPtr = std::shared_ptr<class Hd_VertexAdjacency>;
|
||||
using HdBufferSourceSharedPtr = std::shared_ptr<class HdBufferSource>;
|
||||
using HdSt_MeshTopologySharedPtr = std::shared_ptr<class HdSt_MeshTopology>;
|
||||
|
||||
using HdStResourceRegistrySharedPtr =
|
||||
std::shared_ptr<class HdStResourceRegistry>;
|
||||
|
||||
/// A subdivision surface or poly-mesh object.
|
||||
///
|
||||
class HdStMesh final : public HdMesh
|
||||
{
|
||||
public:
|
||||
HF_MALLOC_TAG_NEW("new HdStMesh");
|
||||
|
||||
HDST_API
|
||||
HdStMesh(SdfPath const& id);
|
||||
|
||||
HDST_API
|
||||
~HdStMesh() override;
|
||||
|
||||
HDST_API
|
||||
void Sync(HdSceneDelegate *delegate,
|
||||
HdRenderParam *renderParam,
|
||||
HdDirtyBits *dirtyBits,
|
||||
TfToken const &reprToken) override;
|
||||
|
||||
HDST_API
|
||||
void Finalize(HdRenderParam *renderParam) override;
|
||||
|
||||
HDST_API
|
||||
HdDirtyBits GetInitialDirtyBitsMask() const override;
|
||||
|
||||
/// Topology (member) getter
|
||||
HDST_API
|
||||
HdMeshTopologySharedPtr GetTopology() const override;
|
||||
|
||||
/// Returns whether packed (10_10_10 bits) normals to be used
|
||||
HDST_API
|
||||
static bool IsEnabledPackedNormals();
|
||||
|
||||
protected:
|
||||
HDST_API
|
||||
void _InitRepr(TfToken const &reprToken, HdDirtyBits *dirtyBits) override;
|
||||
|
||||
HDST_API
|
||||
HdDirtyBits _PropagateDirtyBits(HdDirtyBits bits) const override;
|
||||
|
||||
void _UpdateRepr(HdSceneDelegate *sceneDelegate,
|
||||
HdRenderParam *renderParam,
|
||||
TfToken const &reprToken,
|
||||
HdDirtyBits *dirtyBitsState);
|
||||
|
||||
HdBufferArrayRangeSharedPtr
|
||||
_GetSharedPrimvarRange(uint64_t primvarId,
|
||||
HdBufferSpecVector const &updatedOrAddedSpecs,
|
||||
HdBufferSpecVector const &removedSpecs,
|
||||
HdBufferArrayRangeSharedPtr const &curRange,
|
||||
bool * isFirstInstance,
|
||||
HdStResourceRegistrySharedPtr const &resourceRegistry) const;
|
||||
|
||||
bool _MaterialHasPtex(const HdRenderIndex &renderIndex,
|
||||
const SdfPath &materialId) const;
|
||||
|
||||
bool _UseQuadIndices(const HdRenderIndex &renderIndex,
|
||||
const HdSt_MeshTopologySharedPtr &topology) const;
|
||||
|
||||
bool _MaterialHasLimitSurface(const HdRenderIndex &renderIndex,
|
||||
const SdfPath &materialId) const;
|
||||
|
||||
bool _UseLimitRefinement(const HdRenderIndex &renderIndex,
|
||||
const HdMeshTopology &topology) const;
|
||||
|
||||
bool _UseSmoothNormals(HdSt_MeshTopologySharedPtr const& topology) const;
|
||||
|
||||
bool _UseFlatNormals(const HdMeshReprDesc &desc) const;
|
||||
|
||||
void _UpdateDrawItem(HdSceneDelegate *sceneDelegate,
|
||||
HdRenderParam *renderParam,
|
||||
HdStDrawItem *drawItem,
|
||||
HdDirtyBits *dirtyBits,
|
||||
const TfToken &reprToken,
|
||||
const HdReprSharedPtr &repr,
|
||||
const HdMeshReprDesc &desc,
|
||||
bool requireSmoothNormals,
|
||||
bool requireFlatNormals,
|
||||
int geomSubsetDescIndex);
|
||||
|
||||
void _UpdateDrawItemGeometricShader(HdSceneDelegate *sceneDelegate,
|
||||
HdRenderParam *renderParam,
|
||||
HdStDrawItem *drawItem,
|
||||
const HdMeshReprDesc &desc,
|
||||
const SdfPath &materialId);
|
||||
|
||||
void _UpdateShadersForAllReprs(HdSceneDelegate *sceneDelegate,
|
||||
HdRenderParam *renderParam,
|
||||
bool updateMaterialNetworkShader,
|
||||
bool updateGeometricShader);
|
||||
|
||||
void _UpdateMaterialTagsForAllReprs(HdSceneDelegate *sceneDelegate,
|
||||
HdRenderParam *renderParam);
|
||||
|
||||
void _PopulateTopology(HdSceneDelegate *sceneDelegate,
|
||||
HdRenderParam *renderParam,
|
||||
HdStDrawItem *drawItem,
|
||||
HdDirtyBits *dirtyBits,
|
||||
const TfToken &reprToken,
|
||||
const HdReprSharedPtr &repr,
|
||||
const HdMeshReprDesc &desc,
|
||||
int geomSubsetDescIndex);
|
||||
|
||||
void _UpdateDrawItemsForGeomSubsets(HdSceneDelegate *sceneDelegate,
|
||||
HdRenderParam *renderParam,
|
||||
HdStDrawItem *drawItem,
|
||||
const TfToken &reprToken,
|
||||
const HdReprSharedPtr &repr,
|
||||
const HdGeomSubsets &geomSubsets,
|
||||
size_t oldNumGeomSubsets);
|
||||
|
||||
void _CreateTopologyRangeForGeomSubset(
|
||||
HdStResourceRegistrySharedPtr resourceRegistry,
|
||||
HdChangeTracker &changeTracker,
|
||||
HdRenderParam *renderParam,
|
||||
HdDrawItem *drawItem,
|
||||
const TfToken &indexToken,
|
||||
HdBufferSourceSharedPtr indicesSource,
|
||||
HdBufferSourceSharedPtr fvarIndicesSource,
|
||||
HdBufferSourceSharedPtr geomSubsetFaceIndicesHelperSource,
|
||||
const VtIntArray &faceIndices,
|
||||
bool refined);
|
||||
|
||||
void _GatherFaceVaryingTopologies(HdSceneDelegate *sceneDelegate,
|
||||
const HdReprSharedPtr &repr,
|
||||
const HdMeshReprDesc &desc,
|
||||
HdStDrawItem *drawItem,
|
||||
int geomSubsetDescIndex,
|
||||
HdDirtyBits *dirtyBits,
|
||||
const SdfPath &id,
|
||||
HdSt_MeshTopologySharedPtr topology);
|
||||
|
||||
void _PopulateAdjacency(
|
||||
HdStResourceRegistrySharedPtr const &resourceRegistry);
|
||||
|
||||
void _PopulateVertexPrimvars(HdSceneDelegate *sceneDelegate,
|
||||
HdRenderParam *renderParam,
|
||||
const HdReprSharedPtr &repr,
|
||||
const HdMeshReprDesc &desc,
|
||||
HdStDrawItem *drawItem,
|
||||
int geomSubsetDescIndex,
|
||||
HdDirtyBits *dirtyBits,
|
||||
bool requireSmoothNormals);
|
||||
|
||||
void _PopulateFaceVaryingPrimvars(HdSceneDelegate *sceneDelegate,
|
||||
HdRenderParam *renderParam,
|
||||
const HdReprSharedPtr &repr,
|
||||
const HdMeshReprDesc &desc,
|
||||
HdStDrawItem *drawItem,
|
||||
int geomSubsetDescIndex,
|
||||
HdDirtyBits *dirtyBits);
|
||||
|
||||
void _PopulateElementPrimvars(HdSceneDelegate *sceneDelegate,
|
||||
HdRenderParam *renderParam,
|
||||
const HdReprSharedPtr &repr,
|
||||
const HdMeshReprDesc &desc,
|
||||
HdStDrawItem *drawItem,
|
||||
int geomSubsetDescIndex,
|
||||
HdDirtyBits *dirtyBits,
|
||||
bool requireFlatNormals);
|
||||
|
||||
int _GetRefineLevelForDesc(const HdMeshReprDesc &desc) const;
|
||||
|
||||
// Helper class for meshes to keep track of the topologies of their
|
||||
// face-varying primvars. The face-varying topologies are later passed to
|
||||
// the OSD refiner in an order that will correspond to their face-varying
|
||||
// channel number. We keep a vector of only the topologies in use, paired
|
||||
// with their associated primvar names.
|
||||
class _FvarTopologyTracker
|
||||
{
|
||||
public:
|
||||
const TopologyToPrimvarVector & GetTopologyToPrimvarVector() const {
|
||||
return _topologies;
|
||||
}
|
||||
|
||||
// Add a primvar and its corresponding toplogy to the tracker
|
||||
void AddOrUpdateTopology(const TfToken &primvar,
|
||||
const VtIntArray &topology) {
|
||||
for (size_t i = 0; i < _topologies.size(); ++i) {
|
||||
// Found existing topology
|
||||
if (_topologies[i].first == topology) {
|
||||
|
||||
if (std::find(_topologies[i].second.begin(),
|
||||
_topologies[i].second.end(),
|
||||
primvar) == _topologies[i].second.end()) {
|
||||
// Topology does not have that primvar assigned
|
||||
RemovePrimvar(primvar);
|
||||
_topologies[i].second.push_back(primvar);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Found new topology
|
||||
RemovePrimvar(primvar);
|
||||
_topologies.push_back(
|
||||
std::pair<VtIntArray, std::vector<TfToken>>(
|
||||
topology, {primvar}));
|
||||
}
|
||||
|
||||
// Remove a primvar from the tracker.
|
||||
void RemovePrimvar(const TfToken &primvar) {
|
||||
for (size_t i = 0; i < _topologies.size(); ++i) {
|
||||
_topologies[i].second.erase(std::find(
|
||||
_topologies[i].second.begin(),
|
||||
_topologies[i].second.end(),
|
||||
primvar), _topologies[i].second.end());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Remove unused topologies (topologies with no associated primvars), as
|
||||
// we do not want to build stencil tables for them.
|
||||
void RemoveUnusedTopologies() {
|
||||
_topologies.erase(std::remove_if(
|
||||
_topologies.begin(), _topologies.end(), NoPrimvars),
|
||||
_topologies.end());
|
||||
}
|
||||
|
||||
// Get the face-varying channel given a primvar name. If the primvar is
|
||||
// not in the tracker, returns -1.
|
||||
int GetChannelFromPrimvar(const TfToken &primvar) const {
|
||||
for (size_t i = 0; i < _topologies.size(); ++i) {
|
||||
if (std::find(_topologies[i].second.begin(),
|
||||
_topologies[i].second.end(),
|
||||
primvar) !=
|
||||
_topologies[i].second.end()) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Return a vector of all the face-varying topologies.
|
||||
std::vector<VtIntArray> GetFvarTopologies() const {
|
||||
std::vector<VtIntArray> fvarTopologies;
|
||||
for (const auto& it : _topologies) {
|
||||
fvarTopologies.push_back(it.first);
|
||||
}
|
||||
return fvarTopologies;
|
||||
}
|
||||
|
||||
size_t GetNumTopologies() const {
|
||||
return _topologies.size();
|
||||
}
|
||||
|
||||
private:
|
||||
// Helper function that returns true if a <topology, primvar vector> has
|
||||
// no primvars.
|
||||
static bool NoPrimvars(const std::pair<VtIntArray, std::vector<TfToken>>
|
||||
&topology) {
|
||||
return topology.second.empty();
|
||||
}
|
||||
|
||||
TopologyToPrimvarVector _topologies;
|
||||
};
|
||||
|
||||
private:
|
||||
enum DrawingCoord {
|
||||
HullTopology = HdDrawingCoord::CustomSlotsBegin,
|
||||
PointsTopology,
|
||||
FreeSlot // If the mesh topology has geom subsets, we might place
|
||||
// them here as geom subsets are processed before instance
|
||||
// primvars. The instance primvars will follow after. If there
|
||||
// are no geom subsets, instance primvars start here.
|
||||
};
|
||||
|
||||
enum DirtyBits : HdDirtyBits {
|
||||
DirtySmoothNormals = HdChangeTracker::CustomBitsBegin,
|
||||
DirtyFlatNormals = (DirtySmoothNormals << 1),
|
||||
DirtyIndices = (DirtyFlatNormals << 1),
|
||||
DirtyHullIndices = (DirtyIndices << 1),
|
||||
DirtyPointsIndices = (DirtyHullIndices << 1)
|
||||
};
|
||||
|
||||
HdSt_MeshTopologySharedPtr _topology;
|
||||
Hd_VertexAdjacencySharedPtr _vertexAdjacency;
|
||||
|
||||
HdTopology::ID _topologyId;
|
||||
HdTopology::ID _vertexPrimvarId;
|
||||
HdDirtyBits _customDirtyBitsInUse;
|
||||
|
||||
HdType _pointsDataType;
|
||||
HdInterpolation _sceneNormalsInterpolation;
|
||||
HdCullStyle _cullStyle;
|
||||
bool _hasMirroredTransform : 1;
|
||||
bool _doubleSided : 1;
|
||||
bool _flatShadingEnabled : 1;
|
||||
bool _displacementEnabled : 1;
|
||||
bool _limitNormals : 1;
|
||||
bool _sceneNormals : 1;
|
||||
bool _hasVaryingTopology : 1; // The prim's topology has changed since
|
||||
// the prim was created
|
||||
bool _displayOpacity : 1;
|
||||
bool _occludedSelectionShowsThrough : 1;
|
||||
|
||||
std::unique_ptr<_FvarTopologyTracker> _fvarTopologyTracker;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_ST_MESH_H
|
||||
@@ -0,0 +1,63 @@
|
||||
//
|
||||
// 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_ST_PACKAGE_H
|
||||
#define PXR_IMAGING_HD_ST_PACKAGE_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
HDST_API
|
||||
TfToken HdStPackageComputeShader();
|
||||
|
||||
HDST_API
|
||||
TfToken HdStPackageDomeLightShader();
|
||||
|
||||
HDST_API
|
||||
TfToken HdStPackagePtexTextureShader();
|
||||
|
||||
HDST_API
|
||||
TfToken HdStPackageRenderPassShader();
|
||||
|
||||
HDST_API
|
||||
TfToken HdStPackageFallbackLightingShader();
|
||||
|
||||
HDST_API
|
||||
TfToken HdStPackageFallbackMaterialNetworkShader();
|
||||
|
||||
HDST_API
|
||||
TfToken HdStPackageFallbackVolumeShader();
|
||||
|
||||
HDST_API
|
||||
TfToken HdStPackageImageShader();
|
||||
|
||||
HDST_API
|
||||
TfToken HdStPackageSimpleLightingShader();
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,105 @@
|
||||
//
|
||||
// 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_ST_POINTS_H
|
||||
#define PXR_IMAGING_HD_ST_POINTS_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/drawingCoord.h"
|
||||
#include "pxr/imaging/hd/enums.h"
|
||||
#include "pxr/imaging/hd/perfLog.h"
|
||||
#include "pxr/imaging/hd/points.h"
|
||||
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
#include "pxr/base/vt/array.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// \class HdStPoints
|
||||
///
|
||||
/// Points.
|
||||
///
|
||||
class HdStPoints final : public HdPoints
|
||||
{
|
||||
public:
|
||||
HF_MALLOC_TAG_NEW("new HdStPoints");
|
||||
|
||||
HDST_API
|
||||
HdStPoints(SdfPath const& id);
|
||||
|
||||
HDST_API
|
||||
~HdStPoints() override;
|
||||
|
||||
HDST_API
|
||||
void Sync(HdSceneDelegate *delegate,
|
||||
HdRenderParam *renderParam,
|
||||
HdDirtyBits *dirtyBits,
|
||||
TfToken const &reprToken) override;
|
||||
|
||||
HDST_API
|
||||
void Finalize(HdRenderParam *renderParam) override;
|
||||
|
||||
HDST_API
|
||||
HdDirtyBits GetInitialDirtyBitsMask() const override;
|
||||
|
||||
protected:
|
||||
HDST_API
|
||||
void _InitRepr(TfToken const &reprToken, HdDirtyBits *dirtyBits) override;
|
||||
|
||||
HDST_API
|
||||
HdDirtyBits _PropagateDirtyBits(HdDirtyBits bits) const override;
|
||||
|
||||
void _UpdateRepr(HdSceneDelegate *sceneDelegate,
|
||||
HdRenderParam *renderParam,
|
||||
TfToken const &reprToken,
|
||||
HdDirtyBits *dirtyBitsState);
|
||||
|
||||
void _PopulateVertexPrimvars(HdSceneDelegate *sceneDelegate,
|
||||
HdRenderParam *renderParam,
|
||||
HdStDrawItem *drawItem,
|
||||
HdDirtyBits *dirtyBitsState);
|
||||
|
||||
private:
|
||||
HdReprSharedPtr _smoothHullRepr;
|
||||
|
||||
bool _displayOpacity;
|
||||
|
||||
enum DrawingCoord {
|
||||
InstancePrimvar = HdDrawingCoord::CustomSlotsBegin
|
||||
};
|
||||
|
||||
void _UpdateDrawItem(HdSceneDelegate *sceneDelegate,
|
||||
HdRenderParam *renderParam,
|
||||
HdStDrawItem *drawItem,
|
||||
HdDirtyBits *dirtyBits);
|
||||
|
||||
void _UpdateMaterialTagsForAllReprs(HdSceneDelegate *sceneDelegate,
|
||||
HdRenderParam *renderParam);
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_ST_POINTS_H
|
||||
@@ -0,0 +1,313 @@
|
||||
//
|
||||
// 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_ST_PRIM_UTILS_H
|
||||
#define PXR_IMAGING_HD_ST_PRIM_UTILS_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/imaging/hdSt/resourceRegistry.h"
|
||||
#include "pxr/imaging/hd/sceneDelegate.h"
|
||||
#include "pxr/imaging/hd/rprim.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdChangeTracker;
|
||||
class HdDrawItem;
|
||||
class HdRenderIndex;
|
||||
class HdRenderParam;
|
||||
class HdRprim;
|
||||
struct HdRprimSharedData;
|
||||
class HdStDrawItem;
|
||||
class HdStInstancer;
|
||||
|
||||
using HdBufferArrayRangeSharedPtr = std::shared_ptr<class HdBufferArrayRange>;
|
||||
|
||||
using HdBufferSourceSharedPtrVector = std::vector<HdBufferSourceSharedPtr>;
|
||||
using HdBufferSpecVector = std::vector<struct HdBufferSpec>;
|
||||
using HdSt_MaterialNetworkShaderSharedPtr =
|
||||
std::shared_ptr<class HdSt_MaterialNetworkShader>;
|
||||
|
||||
using HdComputationSharedPtr = std::shared_ptr<class HdComputation>;
|
||||
|
||||
using HdStResourceRegistrySharedPtr =
|
||||
std::shared_ptr<HdStResourceRegistry>;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Draw invalidation and garbage collection utilities
|
||||
// -----------------------------------------------------------------------------
|
||||
HDST_API
|
||||
void HdStMarkDrawBatchesDirty(HdRenderParam *renderParam);
|
||||
|
||||
HDST_API
|
||||
void HdStMarkMaterialTagsDirty(HdRenderParam *renderParam);
|
||||
|
||||
HDST_API
|
||||
void HdStMarkGeomSubsetDrawItemsDirty(HdRenderParam *renderParam);
|
||||
|
||||
HDST_API
|
||||
void HdStMarkGarbageCollectionNeeded(HdRenderParam *renderParam);
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Primvar descriptor filtering utilities
|
||||
// -----------------------------------------------------------------------------
|
||||
// Get filtered primvar descriptors for drawItem
|
||||
HDST_API
|
||||
HdPrimvarDescriptorVector
|
||||
HdStGetPrimvarDescriptors(
|
||||
HdRprim const * prim,
|
||||
HdStDrawItem const * drawItem,
|
||||
HdSceneDelegate * delegate,
|
||||
HdInterpolation interpolation,
|
||||
const HdReprSharedPtr &repr = nullptr,
|
||||
HdMeshGeomStyle descGeomStyle = HdMeshGeomStyleInvalid,
|
||||
int geomSubsetDescIndex = 0,
|
||||
size_t numGeomSubsets = 0);
|
||||
|
||||
// Get filtered instancer primvar descriptors for drawItem
|
||||
HDST_API
|
||||
HdPrimvarDescriptorVector
|
||||
HdStGetInstancerPrimvarDescriptors(
|
||||
HdStInstancer const * instancer,
|
||||
HdSceneDelegate * delegate);
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Material processing utilities
|
||||
// -----------------------------------------------------------------------------
|
||||
HDST_API
|
||||
void HdStSetMaterialId(HdSceneDelegate *delegate,
|
||||
HdRenderParam *renderParam,
|
||||
HdRprim *rprim);
|
||||
|
||||
HDST_API
|
||||
void HdStSetMaterialTag(HdRenderParam *renderParam,
|
||||
HdDrawItem *drawItem,
|
||||
const TfToken &materialTag);
|
||||
|
||||
HDST_API
|
||||
void HdStSetMaterialTag(HdSceneDelegate *delegate,
|
||||
HdRenderParam *renderParam,
|
||||
HdDrawItem *drawItem,
|
||||
SdfPath const & materialId,
|
||||
bool hasDisplayOpacityPrimvar,
|
||||
bool occludedSelectionShowsThrough);
|
||||
// Resolves the material network shader for the given prim (using a fallback
|
||||
// material as necessary).
|
||||
HDST_API
|
||||
HdSt_MaterialNetworkShaderSharedPtr
|
||||
HdStGetMaterialNetworkShader(
|
||||
HdRprim const * prim,
|
||||
HdSceneDelegate * delegate);
|
||||
|
||||
HDST_API
|
||||
HdSt_MaterialNetworkShaderSharedPtr
|
||||
HdStGetMaterialNetworkShader(
|
||||
HdRprim const * prim,
|
||||
HdSceneDelegate * delegate,
|
||||
SdfPath const & materialId);
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Primvar processing and BAR allocation utilities
|
||||
// -----------------------------------------------------------------------------
|
||||
// Returns true if range is non-empty and valid.
|
||||
HDST_API
|
||||
bool HdStIsValidBAR(HdBufferArrayRangeSharedPtr const& range);
|
||||
|
||||
// Returns true if curRange can be used as-is (even if it's empty) during
|
||||
// primvar processing.
|
||||
HDST_API
|
||||
bool HdStCanSkipBARAllocationOrUpdate(
|
||||
HdBufferSourceSharedPtrVector const& sources,
|
||||
HdStComputationSharedPtrVector const& computations,
|
||||
HdBufferArrayRangeSharedPtr const& curRange,
|
||||
HdDirtyBits dirtyBits);
|
||||
|
||||
HDST_API
|
||||
bool HdStCanSkipBARAllocationOrUpdate(
|
||||
HdBufferSourceSharedPtrVector const& sources,
|
||||
HdBufferArrayRangeSharedPtr const& curRange,
|
||||
HdDirtyBits dirtyBits);
|
||||
|
||||
// Returns the buffer specs that have been removed from curRange based on the
|
||||
// new primvar descriptors and internally generated primvar names.
|
||||
//
|
||||
// Internally generated primvar names will never be among the specs returned,
|
||||
HDST_API
|
||||
HdBufferSpecVector
|
||||
HdStGetRemovedPrimvarBufferSpecs(
|
||||
HdBufferArrayRangeSharedPtr const& curRange,
|
||||
HdPrimvarDescriptorVector const& newPrimvarDescs,
|
||||
HdExtComputationPrimvarDescriptorVector const& newCompPrimvarDescs,
|
||||
TfTokenVector const& internallyGeneratedPrimvarNames,
|
||||
SdfPath const& rprimId);
|
||||
|
||||
HDST_API
|
||||
HdBufferSpecVector
|
||||
HdStGetRemovedPrimvarBufferSpecs(
|
||||
HdBufferArrayRangeSharedPtr const& curRange,
|
||||
HdPrimvarDescriptorVector const& newPrimvarDescs,
|
||||
TfTokenVector const& internallyGeneratedPrimvarNames,
|
||||
SdfPath const& rprimId);
|
||||
|
||||
// Updates the existing range at drawCoordIndex with newRange and flags garbage
|
||||
// collection (for the existing range) and rebuild of all draw batches when
|
||||
// necessary.
|
||||
HDST_API
|
||||
void HdStUpdateDrawItemBAR(
|
||||
HdBufferArrayRangeSharedPtr const& newRange,
|
||||
int drawCoordIndex,
|
||||
HdRprimSharedData *sharedData,
|
||||
HdRenderParam *renderParam,
|
||||
HdChangeTracker *changeTracker);
|
||||
|
||||
// Returns true if primvar with primvarName exists within primvar descriptor
|
||||
// vector primvars and primvar has a valid value
|
||||
HDST_API
|
||||
bool HdStIsPrimvarExistentAndValid(
|
||||
HdRprim *prim,
|
||||
HdSceneDelegate *delegate,
|
||||
HdPrimvarDescriptorVector const& primvars,
|
||||
TfToken const& primvarName);
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Constant primvar processing utilities
|
||||
// -----------------------------------------------------------------------------
|
||||
// Returns whether constant primvars need to be populated/updated based on the
|
||||
// dirty bits for a given rprim.
|
||||
HDST_API
|
||||
bool HdStShouldPopulateConstantPrimvars(
|
||||
HdDirtyBits const *dirtyBits,
|
||||
SdfPath const& id);
|
||||
|
||||
// Given prim information it will create sources representing
|
||||
// constant primvars and hand it to the resource registry.
|
||||
// If transforms are dirty, updates the optional bool.
|
||||
HDST_API
|
||||
void HdStPopulateConstantPrimvars(
|
||||
HdRprim *prim,
|
||||
HdRprimSharedData *sharedData,
|
||||
HdSceneDelegate *delegate,
|
||||
HdRenderParam *renderParam,
|
||||
HdDrawItem *drawItem,
|
||||
HdDirtyBits *dirtyBits,
|
||||
HdPrimvarDescriptorVector const& constantPrimvars,
|
||||
bool *hasMirroredTransform = nullptr);
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Instancer processing utilities
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// Updates drawItem bindings for changes to instance topology/primvars.
|
||||
HDST_API
|
||||
void HdStUpdateInstancerData(
|
||||
HdRenderIndex &renderIndex,
|
||||
HdRenderParam *renderParam,
|
||||
HdRprim *prim,
|
||||
HdStDrawItem *drawItem,
|
||||
HdRprimSharedData *sharedData,
|
||||
HdDirtyBits rprimDirtyBits);
|
||||
|
||||
// Returns true if primvar with primvarName exists among instance primvar
|
||||
// descriptors.
|
||||
HDST_API
|
||||
bool HdStIsInstancePrimvarExistentAndValid(
|
||||
HdRenderIndex &renderIndex,
|
||||
HdRprim *prim,
|
||||
TfToken const& primvarName);
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Topological visibility processing utility
|
||||
// -----------------------------------------------------------------------------
|
||||
// Creates/Updates/Migrates the topology visiblity BAR with element and point
|
||||
// visibility encoded using one bit per element/point of the topology.
|
||||
HDST_API
|
||||
void HdStProcessTopologyVisibility(
|
||||
VtIntArray invisibleElements,
|
||||
int numTotalElements,
|
||||
VtIntArray invisiblePoints,
|
||||
int numTotalPoints,
|
||||
HdRprimSharedData *sharedData,
|
||||
HdStDrawItem *drawItem,
|
||||
HdRenderParam *renderParam,
|
||||
HdChangeTracker *changeTracker,
|
||||
HdStResourceRegistrySharedPtr const &resourceRegistry,
|
||||
SdfPath const& rprimId);
|
||||
|
||||
//
|
||||
// De-duplicating and sharing immutable primvar data.
|
||||
//
|
||||
// Primvar data is identified using a hash computed from the
|
||||
// sources of the primvar data, of which there are generally
|
||||
// two kinds:
|
||||
// - data provided by the scene delegate
|
||||
// - data produced by computations
|
||||
//
|
||||
// Immutable and mutable buffer data is managed using distinct
|
||||
// heaps in the resource registry. Aggregation of buffer array
|
||||
// ranges within each heap is managed separately.
|
||||
//
|
||||
// We attempt to balance the benefits of sharing vs efficient
|
||||
// varying update using the following simple strategy:
|
||||
//
|
||||
// - When populating the first repr for an rprim, allocate
|
||||
// the primvar range from the immutable heap and attempt
|
||||
// to deduplicate the data by looking up the primvarId
|
||||
// in the primvar instance registry.
|
||||
//
|
||||
// - When populating an additional repr for an rprim using
|
||||
// an existing immutable primvar range, compute an updated
|
||||
// primvarId and allocate from the immutable heap, again
|
||||
// attempting to deduplicate.
|
||||
//
|
||||
// - Otherwise, migrate the primvar data to the mutable heap
|
||||
// and abandon further attempts to deduplicate.
|
||||
//
|
||||
// - The computation of the primvarId for an rprim is cumulative
|
||||
// and includes the new sources of data being committed
|
||||
// during each successive update.
|
||||
//
|
||||
// - Once we have migrated a primvar allocation to the mutable
|
||||
// heap we will no longer spend time computing a primvarId.
|
||||
//
|
||||
|
||||
HDST_API
|
||||
bool HdStIsEnabledSharedVertexPrimvar();
|
||||
|
||||
HDST_API
|
||||
uint64_t HdStComputeSharedPrimvarId(
|
||||
uint64_t baseId,
|
||||
HdBufferSourceSharedPtrVector const &sources,
|
||||
HdStComputationSharedPtrVector const &computations);
|
||||
|
||||
HDST_API
|
||||
void HdStGetBufferSpecsFromCompuations(
|
||||
HdStComputationSharedPtrVector const& computations,
|
||||
HdBufferSpecVector *bufferSpecs);
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_ST_PRIM_UTILS_H
|
||||
@@ -0,0 +1,119 @@
|
||||
//
|
||||
// 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_ST_PTEX_TEXTURE_OBJECT_H
|
||||
#define PXR_IMAGING_HD_ST_PTEX_TEXTURE_OBJECT_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/imaging/hdSt/textureObject.h"
|
||||
|
||||
#include "pxr/imaging/hgi/handle.h"
|
||||
|
||||
#include "pxr/base/gf/vec2i.h"
|
||||
#include "pxr/base/gf/vec3i.h"
|
||||
|
||||
#ifdef PXR_PTEX_SUPPORT_ENABLED
|
||||
#include "pxr/imaging/hdSt/ptexMipmapTextureLoader.h"
|
||||
#endif
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// Returns true if the file given by \p imageFilePath represents a ptex file,
|
||||
/// and false otherwise.
|
||||
///
|
||||
/// This function simply checks the extension of the file name and does not
|
||||
/// otherwise guarantee that the file is in any way valid for reading.
|
||||
///
|
||||
/// If ptex support is disabled, this function will always return false.
|
||||
///
|
||||
HDST_API bool HdStIsSupportedPtexTexture(std::string const & imageFilePath);
|
||||
|
||||
enum HgiFormat : int;
|
||||
using HgiTextureHandle = HgiHandle<class HgiTexture>;
|
||||
|
||||
/// \class HdStPtexTextureObject
|
||||
///
|
||||
/// A Ptex texture.
|
||||
///
|
||||
class HdStPtexTextureObject final : public HdStTextureObject
|
||||
{
|
||||
public:
|
||||
HDST_API
|
||||
HdStPtexTextureObject(
|
||||
const HdStTextureIdentifier &textureId,
|
||||
HdSt_TextureObjectRegistry *textureObjectRegistry);
|
||||
|
||||
HDST_API
|
||||
~HdStPtexTextureObject() override;
|
||||
|
||||
/// Get the GPU texture handle for the texels
|
||||
///
|
||||
/// Only valid after commit phase.
|
||||
///
|
||||
HgiTextureHandle GetTexelTexture() const { return _texelTexture; }
|
||||
|
||||
/// Get the GPU texture handle for the layout
|
||||
///
|
||||
/// Only valid after commit phase.
|
||||
///
|
||||
HgiTextureHandle GetLayoutTexture() const { return _layoutTexture; }
|
||||
|
||||
HDST_API
|
||||
bool IsValid() const override;
|
||||
|
||||
HDST_API
|
||||
HdTextureType GetTextureType() const override;
|
||||
|
||||
protected:
|
||||
HDST_API
|
||||
void _Load() override;
|
||||
|
||||
HDST_API
|
||||
void _Commit() override;
|
||||
|
||||
private:
|
||||
HgiFormat _format;
|
||||
GfVec3i _texelDimensions;
|
||||
int _texelLayers;
|
||||
size_t _texelDataSize;
|
||||
GfVec2i _layoutDimensions;
|
||||
size_t _layoutDataSize;
|
||||
|
||||
std::unique_ptr<uint8_t[]> _texelData;
|
||||
std::unique_ptr<uint8_t[]> _layoutData;
|
||||
|
||||
HgiTextureHandle _texelTexture;
|
||||
HgiTextureHandle _layoutTexture;
|
||||
|
||||
void _DestroyTextures();
|
||||
};
|
||||
|
||||
template<>
|
||||
struct HdSt_TypedTextureObjectHelper<HdTextureType::Ptex> {
|
||||
using type = HdStPtexTextureObject;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,145 @@
|
||||
//
|
||||
// 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_ST_RENDER_BUFFER_H
|
||||
#define PXR_IMAGING_HD_ST_RENDER_BUFFER_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/base/gf/vec3i.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/imaging/hd/renderBuffer.h"
|
||||
#include "pxr/imaging/hgi/hgi.h"
|
||||
#include "pxr/imaging/hgi/enums.h"
|
||||
#include "pxr/imaging/hgi/texture.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdStResourceRegistry;
|
||||
class HdStTextureIdentifier;
|
||||
using HdStDynamicUvTextureObjectSharedPtr =
|
||||
std::shared_ptr<class HdStDynamicUvTextureObject>;
|
||||
|
||||
class HdStRenderBuffer : public HdRenderBuffer
|
||||
{
|
||||
public:
|
||||
HDST_API
|
||||
HdStRenderBuffer(HdStResourceRegistry *resourceRegistry, SdfPath const& id);
|
||||
|
||||
HDST_API
|
||||
~HdStRenderBuffer() override;
|
||||
|
||||
HDST_API
|
||||
void Sync(HdSceneDelegate *sceneDelegate,
|
||||
HdRenderParam *renderParam,
|
||||
HdDirtyBits *dirtyBits) override;
|
||||
|
||||
HDST_API
|
||||
bool Allocate(GfVec3i const& dimensions,
|
||||
HdFormat format,
|
||||
bool multiSampled) override;
|
||||
|
||||
HDST_API
|
||||
unsigned int GetWidth() const override;
|
||||
|
||||
HDST_API
|
||||
unsigned int GetHeight() const override;
|
||||
|
||||
HDST_API
|
||||
unsigned int GetDepth() const override;
|
||||
|
||||
HDST_API
|
||||
HdFormat GetFormat() const override {return _format;}
|
||||
|
||||
HDST_API
|
||||
bool IsMultiSampled() const override;
|
||||
|
||||
/// Map the buffer for reading. The control flow should be Map(),
|
||||
/// before any I/O, followed by memory access, followed by Unmap() when
|
||||
/// done.
|
||||
/// \return The address of the buffer.
|
||||
HDST_API
|
||||
void* Map() override;
|
||||
|
||||
/// Unmap the buffer.
|
||||
HDST_API
|
||||
void Unmap() override;
|
||||
|
||||
/// Return whether any clients have this buffer mapped currently.
|
||||
/// \return True if the buffer is currently mapped by someone.
|
||||
HDST_API
|
||||
bool IsMapped() const override {
|
||||
return _mappers.load() != 0;
|
||||
}
|
||||
|
||||
/// Is the buffer converged?
|
||||
/// \return True if the buffer is converged (not currently being
|
||||
/// rendered to).
|
||||
HDST_API
|
||||
bool IsConverged() const override {
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Resolve the sample buffer into final values.
|
||||
HDST_API
|
||||
void Resolve() override;
|
||||
|
||||
/// Returns the texture handle.
|
||||
HDST_API
|
||||
VtValue GetResource(bool multiSampled) const override;
|
||||
|
||||
/// The identifier that can be passed to, e.g.,
|
||||
/// HdStResourceRegistry::AllocateTextureHandle so that a
|
||||
/// shader can bind this buffer as texture.
|
||||
HDST_API
|
||||
HdStTextureIdentifier GetTextureIdentifier(
|
||||
bool multiSampled);
|
||||
|
||||
protected:
|
||||
void _Deallocate() override;
|
||||
|
||||
private:
|
||||
// HdRenderBuffer::Allocate should take a scene delegate or
|
||||
// resource registry so that we do not need to save it here.
|
||||
HdStResourceRegistry * _resourceRegistry;
|
||||
|
||||
// Format saved here (somewhat redundantely) since the
|
||||
// Hgi texture descriptor holds an HgiFormat instead of HdFormat.
|
||||
HdFormat _format;
|
||||
|
||||
uint32_t _msaaSampleCount;
|
||||
|
||||
// The GPU texture resource
|
||||
HdStDynamicUvTextureObjectSharedPtr _textureObject;
|
||||
|
||||
// The GPU multi-sample texture resource (optional)
|
||||
HdStDynamicUvTextureObjectSharedPtr _textureMSAAObject;
|
||||
|
||||
// The number of callers mapping this buffer.
|
||||
std::atomic<int> _mappers;
|
||||
// Texels are temp captured into this buffer between map and unmap.
|
||||
std::vector<uint8_t> _mappedBuffer;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,181 @@
|
||||
//
|
||||
// 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_ST_RENDER_DELEGATE_H
|
||||
#define PXR_IMAGING_HD_ST_RENDER_DELEGATE_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/imaging/hd/renderDelegate.h"
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class Hgi;
|
||||
class HdStRenderParam;
|
||||
using HdStDrawItemsCacheUniquePtr =
|
||||
std::unique_ptr<class HdSt_DrawItemsCache>;
|
||||
using HdStDrawItemsCachePtr = HdSt_DrawItemsCache *;
|
||||
|
||||
using HdStResourceRegistrySharedPtr =
|
||||
std::shared_ptr<class HdStResourceRegistry>;
|
||||
|
||||
///
|
||||
/// HdStRenderDelegate
|
||||
///
|
||||
/// The Storm Render Delegate provides a rasterizer renderer to draw the scene.
|
||||
/// While it currently has some ties to GL, the goal is to use Hgi to allow
|
||||
/// it to be graphics API agnostic.
|
||||
///
|
||||
class HdStRenderDelegate final : public HdRenderDelegate {
|
||||
public:
|
||||
HDST_API
|
||||
HdStRenderDelegate();
|
||||
HDST_API
|
||||
HdStRenderDelegate(HdRenderSettingsMap const& settingsMap);
|
||||
|
||||
HDST_API
|
||||
virtual ~HdStRenderDelegate();
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name HdRenderDelegate virtual API
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
HDST_API
|
||||
virtual void SetDrivers(HdDriverVector const& drivers) override;
|
||||
|
||||
HDST_API
|
||||
virtual HdRenderParam *GetRenderParam() const override;
|
||||
|
||||
HDST_API
|
||||
virtual const TfTokenVector &GetSupportedRprimTypes() const override;
|
||||
HDST_API
|
||||
virtual const TfTokenVector &GetSupportedSprimTypes() const override;
|
||||
HDST_API
|
||||
virtual const TfTokenVector &GetSupportedBprimTypes() const override;
|
||||
HDST_API
|
||||
virtual HdResourceRegistrySharedPtr GetResourceRegistry() const override;
|
||||
|
||||
HDST_API
|
||||
virtual HdRenderPassSharedPtr CreateRenderPass(HdRenderIndex *index,
|
||||
HdRprimCollection const& collection) override;
|
||||
HDST_API
|
||||
virtual HdRenderPassStateSharedPtr CreateRenderPassState() const override;
|
||||
|
||||
HDST_API
|
||||
virtual HdInstancer *CreateInstancer(HdSceneDelegate *delegate,
|
||||
SdfPath const& id) override;
|
||||
|
||||
HDST_API
|
||||
virtual void DestroyInstancer(HdInstancer *instancer) override;
|
||||
|
||||
HDST_API
|
||||
virtual HdRprim *CreateRprim(TfToken const& typeId,
|
||||
SdfPath const& rprimId) override;
|
||||
HDST_API
|
||||
virtual void DestroyRprim(HdRprim *rPrim) override;
|
||||
|
||||
HDST_API
|
||||
virtual HdSprim *CreateSprim(TfToken const& typeId,
|
||||
SdfPath const& sprimId) override;
|
||||
HDST_API
|
||||
virtual HdSprim *CreateFallbackSprim(TfToken const& typeId) override;
|
||||
HDST_API
|
||||
virtual void DestroySprim(HdSprim *sPrim) override;
|
||||
|
||||
HDST_API
|
||||
virtual HdBprim *CreateBprim(TfToken const& typeId,
|
||||
SdfPath const& bprimId) override;
|
||||
HDST_API
|
||||
virtual HdBprim *CreateFallbackBprim(TfToken const& typeId) override;
|
||||
HDST_API
|
||||
virtual void DestroyBprim(HdBprim *bPrim) override;
|
||||
|
||||
HDST_API
|
||||
virtual void CommitResources(HdChangeTracker *tracker) override;
|
||||
|
||||
HDST_API
|
||||
virtual TfTokenVector GetMaterialRenderContexts() const override;
|
||||
|
||||
HDST_API
|
||||
virtual TfTokenVector GetShaderSourceTypes() const override;
|
||||
|
||||
HDST_API
|
||||
virtual bool IsPrimvarFilteringNeeded() const override;
|
||||
|
||||
HDST_API
|
||||
virtual HdRenderSettingDescriptorList
|
||||
GetRenderSettingDescriptors() const override;
|
||||
|
||||
HDST_API
|
||||
virtual VtDictionary GetRenderStats() const override;
|
||||
|
||||
HDST_API
|
||||
virtual HdAovDescriptor
|
||||
GetDefaultAovDescriptor(TfToken const& name) const override;
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// \name Misc public API
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
// Returns whether or not HdStRenderDelegate can run on the current
|
||||
// hardware.
|
||||
HDST_API
|
||||
static bool IsSupported();
|
||||
|
||||
// Returns a raw pointer to the draw items cache owned (solely) by the
|
||||
// render delegate.
|
||||
HDST_API
|
||||
HdStDrawItemsCachePtr GetDrawItemsCache() const;
|
||||
|
||||
// Returns Hydra graphics interface
|
||||
HDST_API
|
||||
Hgi* GetHgi();
|
||||
|
||||
private:
|
||||
void _ApplyTextureSettings();
|
||||
HdSprim *_CreateFallbackMaterialPrim();
|
||||
|
||||
HdStRenderDelegate(const HdStRenderDelegate &) = delete;
|
||||
HdStRenderDelegate &operator =(const HdStRenderDelegate &) = delete;
|
||||
|
||||
static const TfTokenVector SUPPORTED_RPRIM_TYPES;
|
||||
static const TfTokenVector SUPPORTED_SPRIM_TYPES;
|
||||
|
||||
// Resource registry used in this render delegate
|
||||
HdStResourceRegistrySharedPtr _resourceRegistry;
|
||||
|
||||
HdRenderSettingDescriptorList _settingDescriptors;
|
||||
|
||||
Hgi* _hgi;
|
||||
|
||||
std::unique_ptr<HdStRenderParam> _renderParam;
|
||||
|
||||
HdStDrawItemsCacheUniquePtr _drawItemsCache;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_ST_RENDER_DELEGATE_H
|
||||
@@ -0,0 +1,126 @@
|
||||
//
|
||||
// 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_PLUGIN_HD_ST_RENDER_PARAM_H
|
||||
#define PXR_IMAGING_PLUGIN_HD_ST_RENDER_PARAM_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hd/renderDelegate.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <shared_mutex>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
///
|
||||
/// \class HdStRenderParam
|
||||
///
|
||||
/// The render delegate can create an object of type HdRenderParam, to pass
|
||||
/// to each prim during Sync(). Storm uses this class to house global
|
||||
/// counters amd flags that assist invalidation of draw batch caches.
|
||||
///
|
||||
class HdStRenderParam final : public HdRenderParam
|
||||
{
|
||||
public:
|
||||
HdStRenderParam();
|
||||
~HdStRenderParam() override;
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// Draw items cache and batch invalidation
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// Marks all batches dirty, meaning they need to be validated and
|
||||
/// potentially rebuilt.
|
||||
HDST_API
|
||||
void MarkDrawBatchesDirty();
|
||||
|
||||
HDST_API
|
||||
unsigned int GetDrawBatchesVersion() const;
|
||||
|
||||
/// Marks material tags dirty, meaning that the draw items associated with
|
||||
/// the collection of a render pass need to be re-gathered.
|
||||
HDST_API
|
||||
void MarkMaterialTagsDirty();
|
||||
|
||||
HDST_API
|
||||
unsigned int GetMaterialTagsVersion() const;
|
||||
|
||||
/// Marks geom subsets draw items dirty, meaning that the draw items
|
||||
/// associated with the collection of a render pass need to be re-gathered.
|
||||
HDST_API
|
||||
void MarkGeomSubsetDrawItemsDirty();
|
||||
|
||||
HDST_API
|
||||
unsigned int GetGeomSubsetDrawItemsVersion() const;
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// Material tag tracking
|
||||
// ---------------------------------------------------------------------- /
|
||||
|
||||
/// Does render index have rprims with given materialTag? Note
|
||||
/// that for performance reasons and ease of implementation
|
||||
/// (HdRprimSharedData::materialTag initializes to the default
|
||||
/// material tag), this always returns true for the default (and
|
||||
/// empty) material tag.
|
||||
HDST_API
|
||||
bool HasMaterialTag(const TfToken &materialTag) const;
|
||||
|
||||
/// Register that there is an rprim with given materialTag.
|
||||
HDST_API
|
||||
void IncreaseMaterialTagCount(const TfToken &materialTag);
|
||||
|
||||
/// Unregister that there is an rprim with given materialTag.
|
||||
HDST_API
|
||||
void DecreaseMaterialTagCount(const TfToken &materialTag);
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
/// Garbage collection tracking
|
||||
// ---------------------------------------------------------------------- //
|
||||
void SetGarbageCollectionNeeded() {
|
||||
_needsGarbageCollection = true;
|
||||
}
|
||||
|
||||
void ClearGarbageCollectionNeeded() {
|
||||
_needsGarbageCollection = false;
|
||||
}
|
||||
|
||||
bool IsGarbageCollectionNeeded() const {
|
||||
return _needsGarbageCollection;
|
||||
}
|
||||
|
||||
private:
|
||||
void _AdjustMaterialTagCount(const TfToken &materialTag, int i);
|
||||
|
||||
std::atomic_uint _drawBatchesVersion;
|
||||
std::atomic_uint _materialTagsVersion;
|
||||
std::atomic_uint _geomSubsetDrawItemsVersion;
|
||||
bool _needsGarbageCollection; // Doesn't need to be atomic since parallel
|
||||
// sync might only set it (and not clear).
|
||||
|
||||
mutable std::shared_timed_mutex _materialTagToCountMutex;
|
||||
std::unordered_map<TfToken, std::atomic_int, TfHash> _materialTagToCount;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_PLUGIN_HD_ST_RENDER_PARAM_H
|
||||
@@ -0,0 +1,118 @@
|
||||
//
|
||||
// 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_ST_RENDER_PASS_H
|
||||
#define PXR_IMAGING_HD_ST_RENDER_PASS_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/imaging/hdSt/commandBuffer.h"
|
||||
#include "pxr/imaging/hd/renderPass.h"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class Hgi;
|
||||
|
||||
/// \class HdSt_RenderPass
|
||||
///
|
||||
/// A single draw pass to a render target/buffer. Stream implementation.
|
||||
///
|
||||
class HdSt_RenderPass : public HdRenderPass {
|
||||
public:
|
||||
HDST_API
|
||||
HdSt_RenderPass(HdRenderIndex *index, HdRprimCollection const &collection);
|
||||
HDST_API
|
||||
virtual ~HdSt_RenderPass();
|
||||
|
||||
/// Returns whether the render pass has draw items to be submitted
|
||||
/// during _Execute. This may be queried during the Prepare and Execute
|
||||
/// phases of the task owning the render pass.
|
||||
/// This information is useful to prevent unnecessary resource allocation
|
||||
/// and pipeline state changes.
|
||||
HDST_API
|
||||
bool HasDrawItems() const;
|
||||
|
||||
protected:
|
||||
virtual void _Execute(HdRenderPassStateSharedPtr const &renderPassState,
|
||||
TfTokenVector const &renderTags) override;
|
||||
|
||||
virtual void _MarkCollectionDirty() override;
|
||||
|
||||
private:
|
||||
void _UpdateDrawItems(TfTokenVector const& renderTags);
|
||||
void _UpdateCommandBuffer(TfTokenVector const& renderTags);
|
||||
|
||||
// XXX: This should really be in HdSt_DrawBatch::PrepareDraw.
|
||||
void _FrustumCullCPU(HdStRenderPassStateSharedPtr const &renderPassState);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Drawing state
|
||||
HdStCommandBuffer _cmdBuffer;
|
||||
|
||||
int _lastSettingsVersion;
|
||||
bool _useTinyPrimCulling;
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Change tracking state.
|
||||
// XXX: This is necessary only when not using the draw items cache.
|
||||
|
||||
// The version number of the currently held collection.
|
||||
int _collectionVersion;
|
||||
|
||||
// The version number of the render tag opinion of rprims
|
||||
int _rprimRenderTagVersion;
|
||||
|
||||
// The version number of the render tags opinion of tasks.
|
||||
int _taskRenderTagsVersion;
|
||||
|
||||
// Cache the render tags parameter passed to _Execute().
|
||||
TfTokenVector _renderTags;
|
||||
|
||||
// The version number of the material tags (of the rprims).
|
||||
unsigned int _materialTagsVersion;
|
||||
|
||||
// The version number of the geom subset draw items.
|
||||
unsigned int _geomSubsetDrawItemsVersion;
|
||||
|
||||
// A flag indicating that the held collection changed since this renderPass
|
||||
// was last drawn.
|
||||
//
|
||||
// When _collectionChanged is true, it indicates that _collectionVersion is
|
||||
// no longer accurate, because _collectionVersion was stored for the
|
||||
// previously held collection.
|
||||
bool _collectionChanged;
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// DrawItems that are used to build the draw batches.
|
||||
HdDrawItemConstPtrVectorSharedPtr _drawItems;
|
||||
size_t _drawItemCount;
|
||||
bool _drawItemsChanged;
|
||||
|
||||
Hgi* _hgi;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_ST_RENDER_PASS_H
|
||||
@@ -0,0 +1,133 @@
|
||||
//
|
||||
// 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_ST_RENDER_PASS_SHADER_H
|
||||
#define PXR_IMAGING_HD_ST_RENDER_PASS_SHADER_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/imaging/hd/enums.h"
|
||||
#include "pxr/imaging/hd/binding.h"
|
||||
#include "pxr/imaging/hdSt/shaderCode.h"
|
||||
#include "pxr/imaging/hio/glslfx.h"
|
||||
|
||||
#include "pxr/base/tf/declarePtrs.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
using HdStRenderPassShaderSharedPtr =
|
||||
std::shared_ptr<class HdStRenderPassShader>;
|
||||
class HdRenderIndex;
|
||||
using HdRenderPassAovBindingVector =
|
||||
std::vector<struct HdRenderPassAovBinding>;
|
||||
|
||||
/// \class HdStRenderPassShader
|
||||
///
|
||||
/// A shader that supports common renderPass functionality.
|
||||
///
|
||||
class HdStRenderPassShader : public HdStShaderCode {
|
||||
public:
|
||||
HDST_API
|
||||
HdStRenderPassShader();
|
||||
HDST_API
|
||||
HdStRenderPassShader(TfToken const &glslfxFile);
|
||||
HDST_API
|
||||
~HdStRenderPassShader() override;
|
||||
|
||||
/// HdShader overrides
|
||||
HDST_API
|
||||
ID ComputeHash() const override;
|
||||
HDST_API
|
||||
std::string GetSource(TfToken const &shaderStageKey) const override;
|
||||
HDST_API
|
||||
void BindResources(int program,
|
||||
HdSt_ResourceBinder const &binder,
|
||||
HdRenderPassState const &state) override;
|
||||
HDST_API
|
||||
void UnbindResources(int program,
|
||||
HdSt_ResourceBinder const &binder,
|
||||
HdRenderPassState const &state) override;
|
||||
HDST_API
|
||||
void AddBindings(HdBindingRequestVector *customBindings) override;
|
||||
HDST_API
|
||||
HdSt_MaterialParamVector const& GetParams() const override;
|
||||
|
||||
HDST_API
|
||||
NamedTextureHandleVector const & GetNamedTextureHandles() const override;
|
||||
|
||||
/// Add a custom binding request for use when this shader executes.
|
||||
HDST_API
|
||||
void AddBufferBinding(HdBindingRequest const& req);
|
||||
|
||||
/// Remove \p name from custom binding.
|
||||
HDST_API
|
||||
void RemoveBufferBinding(TfToken const &name);
|
||||
|
||||
/// Clear all custom bindings associated with this shader.
|
||||
HDST_API
|
||||
void ClearBufferBindings();
|
||||
|
||||
HdCullStyle GetCullStyle() const {
|
||||
return _cullStyle;
|
||||
}
|
||||
|
||||
void SetCullStyle(HdCullStyle cullStyle) {
|
||||
_cullStyle = cullStyle;
|
||||
}
|
||||
|
||||
// Sets the textures and params such that the shader can access
|
||||
// the requested aovs with HdGet_AOVNAMEReadback().
|
||||
//
|
||||
// Needs to be called in task prepare or sync since it is
|
||||
// allocating texture handles.
|
||||
//
|
||||
HDST_API
|
||||
void UpdateAovInputTextures(
|
||||
HdRenderPassAovBindingVector const &aovInputBindings,
|
||||
HdRenderIndex * const renderIndex);
|
||||
|
||||
private:
|
||||
TfToken _glslfxFile;
|
||||
std::unique_ptr<HioGlslfx> _glslfx;
|
||||
mutable size_t _hash;
|
||||
mutable bool _hashValid;
|
||||
|
||||
TfHashMap<TfToken, HdBindingRequest, TfToken::HashFunctor> _customBuffers;
|
||||
HdCullStyle _cullStyle;
|
||||
|
||||
NamedTextureHandleVector _namedTextureHandles;
|
||||
|
||||
HdSt_MaterialParamVector _params;
|
||||
|
||||
// No copying
|
||||
HdStRenderPassShader(const HdStRenderPassShader &) = delete;
|
||||
HdStRenderPassShader &operator =(const HdStRenderPassShader &) = delete;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_ST_RENDER_PASS_SHADER_H
|
||||
@@ -0,0 +1,167 @@
|
||||
//
|
||||
// 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_ST_RENDER_PASS_STATE_H
|
||||
#define PXR_IMAGING_HD_ST_RENDER_PASS_STATE_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/imaging/hd/renderPassState.h"
|
||||
#include "pxr/imaging/hgi/graphicsCmdsDesc.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
using HdResourceRegistrySharedPtr = std::shared_ptr<class HdResourceRegistry>;
|
||||
using HdStRenderPassStateSharedPtr = std::shared_ptr<class HdStRenderPassState>;
|
||||
|
||||
using HdBufferArrayRangeSharedPtr = std::shared_ptr<class HdBufferArrayRange>;
|
||||
|
||||
using HdStShaderCodeSharedPtr = std::shared_ptr<class HdStShaderCode>;
|
||||
using HdStLightingShaderSharedPtr = std::shared_ptr<class HdStLightingShader>;
|
||||
using HdStRenderPassShaderSharedPtr =
|
||||
std::shared_ptr<class HdStRenderPassShader>;
|
||||
using HdSt_FallbackLightingShaderSharedPtr =
|
||||
std::shared_ptr<class HdSt_FallbackLightingShader>;
|
||||
using HdStShaderCodeSharedPtrVector = std::vector<HdStShaderCodeSharedPtr>;
|
||||
class HdRenderIndex;
|
||||
|
||||
/// \class HdStRenderPassState
|
||||
///
|
||||
/// A set of rendering parameters used among render passes.
|
||||
///
|
||||
/// Parameters are expressed as GL states, uniforms or shaders.
|
||||
///
|
||||
class HdStRenderPassState : public HdRenderPassState
|
||||
{
|
||||
public:
|
||||
HDST_API
|
||||
HdStRenderPassState();
|
||||
HDST_API
|
||||
HdStRenderPassState(HdStRenderPassShaderSharedPtr const &shader);
|
||||
HDST_API
|
||||
~HdStRenderPassState() override;
|
||||
|
||||
HDST_API
|
||||
void
|
||||
Prepare(HdResourceRegistrySharedPtr const &resourceRegistry) override;
|
||||
|
||||
/// XXX: Bind and Unbind set./restore the following GL state.
|
||||
/// This will be reworked to use Hgi in the near future.
|
||||
/// Following states may be changed and restored to
|
||||
/// the GL default at Unbind().
|
||||
/// glEnable(GL_BLEND);
|
||||
/// glEnable(GL_CULL_FACE);
|
||||
/// glEnable(GL_POLYGON_OFFSET_FILL)
|
||||
/// glEnable(GL_PROGRAM_POINT_SIZE);
|
||||
/// glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE)
|
||||
/// glEnable(GL_DEPTH_TEST);
|
||||
/// glEnable(GL_STENCIL_TEST);
|
||||
/// glPolygonOffset()
|
||||
/// glBlend*()
|
||||
/// glColorMask()
|
||||
/// glCullFace()
|
||||
/// glDepthFunc()
|
||||
/// glDepthMask()
|
||||
/// glLineWidth()
|
||||
/// glStencilFunc()
|
||||
/// glStencilOp()
|
||||
HDST_API
|
||||
void Bind();
|
||||
HDST_API
|
||||
void Unbind();
|
||||
|
||||
/// If set to true (default) and the render pass is rendering into a
|
||||
/// multi-sampled aovs, the aovs will be resolved at the end of the render
|
||||
/// pass. If false or the aov is not multi-sampled or the render pass is not
|
||||
/// rendering into the multi-sampled aov, no resolution takes place.
|
||||
HD_API
|
||||
void SetResolveAovMultiSample(bool state);
|
||||
HD_API
|
||||
bool GetResolveAovMultiSample() const;
|
||||
|
||||
/// Set lighting shader
|
||||
HDST_API
|
||||
void SetLightingShader(HdStLightingShaderSharedPtr const &lightingShader);
|
||||
HdStLightingShaderSharedPtr const & GetLightingShader() const {
|
||||
return _lightingShader;
|
||||
}
|
||||
|
||||
/// renderpass shader
|
||||
HDST_API
|
||||
void SetRenderPassShader(HdStRenderPassShaderSharedPtr const &renderPassShader);
|
||||
HdStRenderPassShaderSharedPtr const &GetRenderPassShader() const {
|
||||
return _renderPassShader;
|
||||
}
|
||||
|
||||
/// scene materials
|
||||
HDST_API
|
||||
void SetUseSceneMaterials(bool state);
|
||||
bool GetUseSceneMaterials() const {
|
||||
return _useSceneMaterials;
|
||||
}
|
||||
|
||||
/// returns shaders (lighting/renderpass)
|
||||
HDST_API
|
||||
HdStShaderCodeSharedPtrVector GetShaders() const;
|
||||
|
||||
HDST_API
|
||||
size_t GetShaderHash() const;
|
||||
|
||||
/// Camera setter API
|
||||
/// Option 1: Specify matrices, viewport and clipping planes (defined in
|
||||
/// camera space) directly.
|
||||
HD_API
|
||||
void SetCameraFramingState(GfMatrix4d const &worldToViewMatrix,
|
||||
GfMatrix4d const &projectionMatrix,
|
||||
GfVec4d const &viewport,
|
||||
ClipPlanesVector const & clipPlanes);
|
||||
|
||||
// Helper to get graphics cmds descriptor describing textures
|
||||
// we render into and the blend state, constructed from
|
||||
// AOV bindings.
|
||||
//
|
||||
HDST_API
|
||||
HgiGraphicsCmdsDesc MakeGraphicsCmdsDesc(const HdRenderIndex *) const;
|
||||
|
||||
private:
|
||||
bool _UseAlphaMask() const;
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
// Shader Objects
|
||||
// ---------------------------------------------------------------------- //
|
||||
HdStRenderPassShaderSharedPtr _renderPassShader;
|
||||
HdSt_FallbackLightingShaderSharedPtr _fallbackLightingShader;
|
||||
HdStLightingShaderSharedPtr _lightingShader;
|
||||
|
||||
HdBufferArrayRangeSharedPtr _renderPassStateBar;
|
||||
size_t _clipPlanesBufferSize;
|
||||
float _alphaThresholdCurrent;
|
||||
bool _resolveMultiSampleAov;
|
||||
bool _useSceneMaterials;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_ST_RENDER_PASS_STATE_H
|
||||
@@ -0,0 +1,680 @@
|
||||
//
|
||||
// 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_ST_RESOURCE_REGISTRY_H
|
||||
#define PXR_IMAGING_HD_ST_RESOURCE_REGISTRY_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/base/vt/dictionary.h"
|
||||
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
|
||||
#include "pxr/imaging/hgi/hgi.h"
|
||||
|
||||
#include "pxr/imaging/hd/bufferArrayRange.h"
|
||||
#include "pxr/imaging/hd/bufferArrayRegistry.h"
|
||||
#include "pxr/imaging/hd/bufferSource.h"
|
||||
#include "pxr/imaging/hd/bufferSpec.h"
|
||||
#include "pxr/imaging/hd/enums.h"
|
||||
#include "pxr/imaging/hd/instanceRegistry.h"
|
||||
#include "pxr/imaging/hd/resourceRegistry.h"
|
||||
|
||||
#include <tbb/concurrent_vector.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
using HdComputationSharedPtr = std::shared_ptr<class HdComputation>;
|
||||
using HdStDispatchBufferSharedPtr = std::shared_ptr<class HdStDispatchBuffer>;
|
||||
using HdStGLSLProgramSharedPtr = std::shared_ptr<class HdStGLSLProgram>;
|
||||
using HioGlslfxSharedPtr = std::shared_ptr<class HioGlslfx>;
|
||||
|
||||
using HdSt_BasisCurvesTopologySharedPtr =
|
||||
std::shared_ptr<class HdSt_BasisCurvesTopology>;
|
||||
|
||||
using HdStShaderCodePtr =
|
||||
std::weak_ptr<class HdStShaderCode>;
|
||||
using HdSt_GeometricShaderSharedPtr =
|
||||
std::shared_ptr<class HdSt_GeometricShader>;
|
||||
|
||||
using HdStTextureHandleSharedPtr =
|
||||
std::shared_ptr<class HdStTextureHandle>;
|
||||
using HdStTextureObjectSharedPtr =
|
||||
std::shared_ptr<class HdStTextureObject>;
|
||||
using HdStBufferResourceSharedPtr =
|
||||
std::shared_ptr<class HdStBufferResource>;
|
||||
using HdStResourceRegistrySharedPtr =
|
||||
std::shared_ptr<class HdStResourceRegistry>;
|
||||
using Hd_VertexAdjacencySharedPtr =
|
||||
std::shared_ptr<class Hd_VertexAdjacency>;
|
||||
using HdSt_MeshTopologySharedPtr =
|
||||
std::shared_ptr<class HdSt_MeshTopology>;
|
||||
using HgiResourceBindingsSharedPtr =
|
||||
std::shared_ptr<HgiResourceBindingsHandle>;
|
||||
using HgiGraphicsPipelineSharedPtr =
|
||||
std::shared_ptr<HgiGraphicsPipelineHandle>;
|
||||
using HgiComputePipelineSharedPtr =
|
||||
std::shared_ptr<HgiComputePipelineHandle>;
|
||||
|
||||
class HdStTextureIdentifier;
|
||||
class HdSamplerParameters;
|
||||
class HdStStagingBuffer;
|
||||
|
||||
/// \enum HdStComputeQueue
|
||||
///
|
||||
/// Determines the 'compute queue' a computation should be added into.
|
||||
///
|
||||
/// We only perform synchronization between queues, not within one queue.
|
||||
/// In OpenGL terms that means we insert memory barriers between computations
|
||||
/// of two queues, but not between two computations in the same queue.
|
||||
///
|
||||
/// A prim determines the role for each queue based on its local knowledge of
|
||||
/// compute dependencies. Eg. HdStMesh knows computing normals should wait
|
||||
/// until the primvar refinement computation has fnished. It can assign one
|
||||
/// queue to primvar refinement and a following queue for normal computations.
|
||||
///
|
||||
enum HdStComputeQueue {
|
||||
HdStComputeQueueZero=0,
|
||||
HdStComputeQueueOne,
|
||||
HdStComputeQueueTwo,
|
||||
HdStComputeQueueThree,
|
||||
HdStComputeQueueCount};
|
||||
|
||||
using HdStComputationSharedPtrVector =
|
||||
std::vector<std::pair<HdComputationSharedPtr, HdStComputeQueue>>;
|
||||
|
||||
|
||||
/// \class HdStResourceRegistry
|
||||
///
|
||||
/// A central registry of all GPU resources.
|
||||
///
|
||||
class HdStResourceRegistry final : public HdResourceRegistry
|
||||
{
|
||||
public:
|
||||
HF_MALLOC_TAG_NEW("new HdStResourceRegistry");
|
||||
|
||||
HDST_API
|
||||
explicit HdStResourceRegistry(Hgi* hgi);
|
||||
|
||||
HDST_API
|
||||
~HdStResourceRegistry() override;
|
||||
|
||||
HDST_API
|
||||
void InvalidateShaderRegistry() override;
|
||||
|
||||
HDST_API
|
||||
void ReloadResource(TfToken const& resourceType,
|
||||
std::string const& path) override;
|
||||
|
||||
HDST_API
|
||||
VtDictionary GetResourceAllocation() const override;
|
||||
|
||||
/// Returns Hgi used to create/destroy GPU resources.
|
||||
HDST_API
|
||||
Hgi* GetHgi();
|
||||
|
||||
/// ------------------------------------------------------------------------
|
||||
/// Texture allocation API
|
||||
/// ------------------------------------------------------------------------
|
||||
///
|
||||
|
||||
/// Allocate texture handle (encapsulates texture and sampler
|
||||
/// object, memory request and callback to shader).
|
||||
///
|
||||
/// The actual allocation of the associated GPU texture and
|
||||
/// sampler resources and loading of the texture file is delayed
|
||||
/// until the commit phase.
|
||||
HDST_API
|
||||
HdStTextureHandleSharedPtr AllocateTextureHandle(
|
||||
/// Path to file and information to identify a texture if the
|
||||
/// file is a container for several textures (e.g., OpenVDB
|
||||
/// file containing several grids, movie file containing frames).
|
||||
const HdStTextureIdentifier &textureId,
|
||||
/// Texture type, e.g., uv, ptex, ...
|
||||
HdTextureType textureType,
|
||||
/// Sampling parameters such as wrapS, ...
|
||||
/// wrapS, wrapT, wrapR mode, min filer, mag filter
|
||||
const HdSamplerParameters &samplerParams,
|
||||
/// Memory request. The texture is down-sampled to meet the
|
||||
/// target memory which is the maximum of all memory requests
|
||||
/// associated to the texture.
|
||||
/// If all memory requests are 0, no down-sampling will happen.
|
||||
size_t memoryRequest,
|
||||
/// After the texture is committed (or after it has been
|
||||
/// changed) the given shader code can add additional buffer
|
||||
/// sources and computations using the texture metadata with
|
||||
/// AddResourcesFromTextures.
|
||||
HdStShaderCodePtr const &shaderCode);
|
||||
|
||||
/// Allocate texture object.
|
||||
///
|
||||
/// The actual allocation of the associated GPU texture and
|
||||
/// sampler resources and loading of the texture file is delayed
|
||||
/// until the commit phase.
|
||||
HDST_API
|
||||
HdStTextureObjectSharedPtr AllocateTextureObject(
|
||||
/// Path to file and information to identify a texture if the
|
||||
/// file is a container for several textures (e.g., OpenVDB
|
||||
/// file containing several grids, movie file containing frames).
|
||||
const HdStTextureIdentifier &textureId,
|
||||
/// Texture type, e.g., uv, ptex, ...
|
||||
HdTextureType textureType);
|
||||
|
||||
/// Sets how much memory a single texture can consume in bytes by
|
||||
/// texture type.
|
||||
///
|
||||
/// Only has an effect if non-zero and only applies to textures if
|
||||
/// no texture handle referencing the texture has a memory
|
||||
/// request.
|
||||
///
|
||||
HDST_API
|
||||
void SetMemoryRequestForTextureType(
|
||||
HdTextureType textureType,
|
||||
size_t memoryRequest);
|
||||
|
||||
/// ------------------------------------------------------------------------
|
||||
/// BAR allocation API
|
||||
/// ------------------------------------------------------------------------
|
||||
///
|
||||
/// The Allocate* flavor of methods allocate a new BAR for the given buffer
|
||||
/// specs using the chosen aggregation strategy.
|
||||
|
||||
HDST_API
|
||||
HdBufferArrayRangeSharedPtr AllocateNonUniformBufferArrayRange(
|
||||
TfToken const &role,
|
||||
HdBufferSpecVector const &bufferSpecs,
|
||||
HdBufferArrayUsageHint usageHint);
|
||||
|
||||
HDST_API
|
||||
HdBufferArrayRangeSharedPtr AllocateNonUniformImmutableBufferArrayRange(
|
||||
TfToken const &role,
|
||||
HdBufferSpecVector const &bufferSpecs,
|
||||
HdBufferArrayUsageHint usageHint);
|
||||
|
||||
HDST_API
|
||||
HdBufferArrayRangeSharedPtr AllocateUniformBufferArrayRange(
|
||||
TfToken const &role,
|
||||
HdBufferSpecVector const &bufferSpecs,
|
||||
HdBufferArrayUsageHint usageHint);
|
||||
|
||||
HDST_API
|
||||
HdBufferArrayRangeSharedPtr AllocateShaderStorageBufferArrayRange(
|
||||
TfToken const &role,
|
||||
HdBufferSpecVector const &bufferSpecs,
|
||||
HdBufferArrayUsageHint usageHint);
|
||||
|
||||
HDST_API
|
||||
HdBufferArrayRangeSharedPtr AllocateSingleBufferArrayRange(
|
||||
TfToken const &role,
|
||||
HdBufferSpecVector const &bufferSpecs,
|
||||
HdBufferArrayUsageHint usageHint);
|
||||
|
||||
/// ------------------------------------------------------------------------
|
||||
/// BAR allocation/migration/update API
|
||||
/// ------------------------------------------------------------------------
|
||||
///
|
||||
/// The Update* flavor of methods handle both allocation of a new BAR and
|
||||
/// reallocation-migration based on the existing range, updated/added specs,
|
||||
/// removed specs and usage hint. This allows client code to be less verbose
|
||||
/// when a range's signature (specs) can change.
|
||||
///
|
||||
/// If \p curRange is invalid, this is equivalent to calling Allocate*.
|
||||
/// Otherwise, checks if \p curRange needs to be migrated to a new range
|
||||
/// (based on \p updatedOrAddedSpecs and \p removedSpecs and \p usageHint).
|
||||
/// If migration is necessary, allocate a new range and register necessary
|
||||
/// migration computations and return the new range.
|
||||
/// Otherwise, just return the same range.
|
||||
|
||||
HDST_API
|
||||
HdBufferArrayRangeSharedPtr UpdateNonUniformBufferArrayRange(
|
||||
TfToken const &role,
|
||||
HdBufferArrayRangeSharedPtr const& curRange,
|
||||
HdBufferSpecVector const &updatedOrAddedSpecs,
|
||||
HdBufferSpecVector const& removedSpecs,
|
||||
HdBufferArrayUsageHint usageHint);
|
||||
|
||||
HDST_API
|
||||
HdBufferArrayRangeSharedPtr UpdateNonUniformImmutableBufferArrayRange(
|
||||
TfToken const &role,
|
||||
HdBufferArrayRangeSharedPtr const& curRange,
|
||||
HdBufferSpecVector const &updatedOrAddedSpecs,
|
||||
HdBufferSpecVector const& removedSpecs,
|
||||
HdBufferArrayUsageHint usageHint);
|
||||
|
||||
HDST_API
|
||||
HdBufferArrayRangeSharedPtr UpdateUniformBufferArrayRange(
|
||||
TfToken const &role,
|
||||
HdBufferArrayRangeSharedPtr const& curRange,
|
||||
HdBufferSpecVector const &updatedOrAddedSpecs,
|
||||
HdBufferSpecVector const& removedSpecs,
|
||||
HdBufferArrayUsageHint usageHint);
|
||||
|
||||
HDST_API
|
||||
HdBufferArrayRangeSharedPtr UpdateShaderStorageBufferArrayRange(
|
||||
TfToken const &role,
|
||||
HdBufferArrayRangeSharedPtr const& curRange,
|
||||
HdBufferSpecVector const &updatedOrAddedSpecs,
|
||||
HdBufferSpecVector const& removedSpecs,
|
||||
HdBufferArrayUsageHint usageHint);
|
||||
|
||||
/// ------------------------------------------------------------------------
|
||||
/// Resource update & computation queuing API
|
||||
/// ------------------------------------------------------------------------
|
||||
|
||||
/// Append source data for given range to be committed later.
|
||||
HDST_API
|
||||
void AddSources(HdBufferArrayRangeSharedPtr const &range,
|
||||
HdBufferSourceSharedPtrVector &&sources);
|
||||
|
||||
/// Append a source data for given range to be committed later.
|
||||
HDST_API
|
||||
void AddSource(HdBufferArrayRangeSharedPtr const &range,
|
||||
HdBufferSourceSharedPtr const &source);
|
||||
|
||||
/// Append a source data just to be resolved (used for cpu computations).
|
||||
HDST_API
|
||||
void AddSource(HdBufferSourceSharedPtr const &source);
|
||||
|
||||
/// Append a gpu computation into queue.
|
||||
/// The parameter 'range' specifies the destination buffer range,
|
||||
/// which has to be allocated by caller of this function.
|
||||
///
|
||||
/// note: GPU computations will be executed in the order that
|
||||
/// they are registered.
|
||||
HDST_API
|
||||
void AddComputation(HdBufferArrayRangeSharedPtr const &range,
|
||||
HdComputationSharedPtr const &computation,
|
||||
HdStComputeQueue const queue);
|
||||
|
||||
/// ------------------------------------------------------------------------
|
||||
/// Dispatch & buffer API
|
||||
/// ------------------------------------------------------------------------
|
||||
|
||||
/// Register a buffer allocated with \a count * \a commandNumUints *
|
||||
/// sizeof(uint32_t) to be used as an indirect dispatch buffer.
|
||||
HDST_API
|
||||
HdStDispatchBufferSharedPtr RegisterDispatchBuffer(
|
||||
TfToken const &role, int count, int commandNumUints);
|
||||
|
||||
/// Register a misc buffer resource.
|
||||
/// Usually buffers are part of a buffer array (buffer aggregation) and are
|
||||
/// managed via buffer array APIs.
|
||||
/// RegisterBufferResource lets you create a standalone buffer that can
|
||||
/// be used for misc purposes (Eg. GPU frustum cull prim count read back).
|
||||
HDST_API
|
||||
HdStBufferResourceSharedPtr RegisterBufferResource(
|
||||
TfToken const &role,
|
||||
HdTupleType tupleType);
|
||||
|
||||
/// Remove any entries associated with expired dispatch buffers.
|
||||
HDST_API
|
||||
void GarbageCollectDispatchBuffers();
|
||||
|
||||
/// Remove any entries associated with expired misc buffers.
|
||||
HDST_API
|
||||
void GarbageCollectBufferResources();
|
||||
|
||||
/// ------------------------------------------------------------------------
|
||||
/// Instance Registries
|
||||
/// ------------------------------------------------------------------------
|
||||
|
||||
/// These registries implement sharing and deduplication of data based
|
||||
/// on computed hash identifiers. Each returned HdInstance object retains
|
||||
/// a shared pointer to a data instance. When an HdInstance is registered
|
||||
/// for a previously unused ID, the data pointer will be null and it is
|
||||
/// the caller's responsibility to set its value. The instance registries
|
||||
/// are cleaned of unreferenced entries during garbage collection.
|
||||
///
|
||||
/// Note: As entries can be registered from multiple threads, the returned
|
||||
/// object holds a lock on the instance registry. This lock is held
|
||||
/// until the returned HdInstance object is destroyed.
|
||||
|
||||
/// Topology instancing
|
||||
HDST_API
|
||||
HdInstance<HdSt_MeshTopologySharedPtr>
|
||||
RegisterMeshTopology(HdInstance<HdSt_MeshTopologySharedPtr>::ID id);
|
||||
|
||||
HDST_API
|
||||
HdInstance<HdSt_BasisCurvesTopologySharedPtr>
|
||||
RegisterBasisCurvesTopology(
|
||||
HdInstance<HdSt_BasisCurvesTopologySharedPtr>::ID id);
|
||||
|
||||
HDST_API
|
||||
HdInstance<Hd_VertexAdjacencySharedPtr>
|
||||
RegisterVertexAdjacency(HdInstance<Hd_VertexAdjacencySharedPtr>::ID id);
|
||||
|
||||
/// Topology Index buffer array range instancing
|
||||
/// Returns the HdInstance points to shared HdBufferArrayRange,
|
||||
/// distinguished by given ID.
|
||||
/// *Refer the comment on RegisterTopology for the same consideration.
|
||||
HDST_API
|
||||
HdInstance<HdBufferArrayRangeSharedPtr>
|
||||
RegisterMeshIndexRange(
|
||||
HdInstance<HdBufferArrayRangeSharedPtr>::ID id, TfToken const &name);
|
||||
|
||||
HDST_API
|
||||
HdInstance<HdBufferArrayRangeSharedPtr>
|
||||
RegisterBasisCurvesIndexRange(
|
||||
HdInstance<HdBufferArrayRangeSharedPtr>::ID id, TfToken const &name);
|
||||
|
||||
/// Primvar array range instancing
|
||||
/// Returns the HdInstance pointing to shared HdBufferArrayRange,
|
||||
/// distinguished by given ID.
|
||||
/// *Refer the comment on RegisterTopology for the same consideration.
|
||||
HDST_API
|
||||
HdInstance<HdBufferArrayRangeSharedPtr>
|
||||
RegisterPrimvarRange(
|
||||
HdInstance<HdBufferArrayRangeSharedPtr>::ID id);
|
||||
|
||||
/// ExtComputation data array range instancing
|
||||
/// Returns the HdInstance pointing to shared HdBufferArrayRange,
|
||||
/// distinguished by given ID.
|
||||
/// *Refer the comment on RegisterTopology for the same consideration.
|
||||
HDST_API
|
||||
HdInstance<HdBufferArrayRangeSharedPtr>
|
||||
RegisterExtComputationDataRange(
|
||||
HdInstance<HdBufferArrayRangeSharedPtr>::ID id);
|
||||
|
||||
/// Register a geometric shader.
|
||||
HDST_API
|
||||
HdInstance<HdSt_GeometricShaderSharedPtr>
|
||||
RegisterGeometricShader(HdInstance<HdSt_GeometricShaderSharedPtr>::ID id);
|
||||
|
||||
/// Register a GLSL program into the program registry.
|
||||
HDST_API
|
||||
HdInstance<HdStGLSLProgramSharedPtr>
|
||||
RegisterGLSLProgram(HdInstance<HdStGLSLProgramSharedPtr>::ID id);
|
||||
|
||||
/// Register a GLSLFX file.
|
||||
HDST_API
|
||||
HdInstance<HioGlslfxSharedPtr>
|
||||
RegisterGLSLFXFile(HdInstance<HioGlslfxSharedPtr>::ID id);
|
||||
|
||||
/// Register a Hgi resource bindings into the registry.
|
||||
HDST_API
|
||||
HdInstance<HgiResourceBindingsSharedPtr>
|
||||
RegisterResourceBindings(HdInstance<HgiResourceBindingsSharedPtr>::ID id);
|
||||
|
||||
/// Register a Hgi graphics pipeline into the registry.
|
||||
HDST_API
|
||||
HdInstance<HgiGraphicsPipelineSharedPtr>
|
||||
RegisterGraphicsPipeline(HdInstance<HgiGraphicsPipelineSharedPtr>::ID id);
|
||||
|
||||
/// Register a Hgi compute pipeline into the registry.
|
||||
HDST_API
|
||||
HdInstance<HgiComputePipelineSharedPtr>
|
||||
RegisterComputePipeline(HdInstance<HgiComputePipelineSharedPtr>::ID id);
|
||||
|
||||
/// Returns the global hgi blit command queue for recording blitting work.
|
||||
/// When using this global cmd instead of creating a new HgiBlitCmds we
|
||||
/// reduce the number of command buffers being created.
|
||||
/// The returned pointer should not be held onto by the client as it is
|
||||
/// only valid until the HgiBlitCmds has been submitted.
|
||||
HDST_API
|
||||
HgiBlitCmds* GetGlobalBlitCmds();
|
||||
|
||||
/// Returns the global hgi compute cmd queue for recording compute work.
|
||||
/// When using this global cmd instead of creating a new HgiComputeCmds we
|
||||
/// reduce the number of command buffers being created.
|
||||
/// The returned pointer should not be held onto by the client as it is
|
||||
/// only valid until the HgiComputeCmds has been submitted.
|
||||
HDST_API
|
||||
HgiComputeCmds* GetGlobalComputeCmds();
|
||||
|
||||
/// Submits blit work queued in global blit cmds for GPU execution.
|
||||
/// We can call this when we want to submit some work to the GPU.
|
||||
/// To stall the CPU and wait for the GPU to finish, 'wait' can be provided.
|
||||
/// To insert a barrier to ensure memory writes are visible after the
|
||||
/// barrier a HgiMemoryBarrier can be provided.
|
||||
HDST_API
|
||||
void SubmitBlitWork(HgiSubmitWaitType wait = HgiSubmitWaitTypeNoWait);
|
||||
|
||||
/// Submits compute work queued in global compute cmds for GPU execution.
|
||||
/// We can call this when we want to submit some work to the GPU.
|
||||
/// To stall the CPU and wait for the GPU to finish, 'wait' can be provided.
|
||||
/// To insert a barrier to ensure memory writes are visible after the
|
||||
/// barrier a HgiMemoryBarrier can be provided.
|
||||
HDST_API
|
||||
void SubmitComputeWork(HgiSubmitWaitType wait = HgiSubmitWaitTypeNoWait);
|
||||
|
||||
/// Returns the staging buffer used when committing data to the GPU.
|
||||
HDST_API
|
||||
HdStStagingBuffer* GetStagingBuffer();
|
||||
|
||||
public:
|
||||
//
|
||||
// Unit test API
|
||||
//
|
||||
|
||||
/// Set the aggregation strategy for non uniform parameters
|
||||
/// (vertex, varying, facevarying)
|
||||
/// Takes ownership of the passed in strategy object.
|
||||
void SetNonUniformAggregationStrategy(
|
||||
std::unique_ptr<HdAggregationStrategy> &&strategy) {
|
||||
_nonUniformAggregationStrategy = std::move(strategy);
|
||||
}
|
||||
|
||||
/// Set the aggregation strategy for non uniform immutable parameters
|
||||
/// (vertex, varying, facevarying)
|
||||
/// Takes ownership of the passed in strategy object.
|
||||
void SetNonUniformImmutableAggregationStrategy(
|
||||
std::unique_ptr<HdAggregationStrategy> &&strategy) {
|
||||
_nonUniformImmutableAggregationStrategy = std::move(strategy);
|
||||
}
|
||||
|
||||
/// Set the aggregation strategy for uniform (shader globals)
|
||||
/// Takes ownership of the passed in strategy object.
|
||||
void SetUniformAggregationStrategy(
|
||||
std::unique_ptr<HdAggregationStrategy> &&strategy) {
|
||||
_uniformUboAggregationStrategy = std::move(strategy);
|
||||
}
|
||||
|
||||
/// Set the aggregation strategy for SSBO (uniform primvars)
|
||||
/// Takes ownership of the passed in strategy object.
|
||||
void SetShaderStorageAggregationStrategy(
|
||||
std::unique_ptr<HdAggregationStrategy> &&strategy) {
|
||||
_uniformSsboAggregationStrategy = std::move(strategy);
|
||||
}
|
||||
|
||||
/// Set the aggregation strategy for single buffers (for nested instancer).
|
||||
/// Takes ownership of the passed in strategy object.
|
||||
void SetSingleStorageAggregationStrategy(
|
||||
std::unique_ptr<HdAggregationStrategy> &&strategy) {
|
||||
_singleAggregationStrategy = std::move(strategy);
|
||||
}
|
||||
|
||||
/// Debug dump
|
||||
HDST_API
|
||||
friend std::ostream &operator <<(
|
||||
std::ostream &out,
|
||||
const HdStResourceRegistry& self);
|
||||
|
||||
protected:
|
||||
void _Commit() override;
|
||||
void _GarbageCollect() override;
|
||||
|
||||
private:
|
||||
void _CommitTextures();
|
||||
// Wrapper function for BAR allocation
|
||||
HdBufferArrayRangeSharedPtr _AllocateBufferArrayRange(
|
||||
HdAggregationStrategy *strategy,
|
||||
HdBufferArrayRegistry &bufferArrayRegistry,
|
||||
TfToken const &role,
|
||||
HdBufferSpecVector const &bufferSpecs,
|
||||
HdBufferArrayUsageHint usageHint);
|
||||
|
||||
/// Wrapper function for BAR allocation/reallocation-migration.
|
||||
HdBufferArrayRangeSharedPtr _UpdateBufferArrayRange(
|
||||
HdAggregationStrategy *strategy,
|
||||
HdBufferArrayRegistry &bufferArrayRegistry,
|
||||
TfToken const &role,
|
||||
HdBufferArrayRangeSharedPtr const& curRange,
|
||||
HdBufferSpecVector const &updatedOrAddedSpecs,
|
||||
HdBufferSpecVector const& removedSpecs,
|
||||
HdBufferArrayUsageHint usageHint);
|
||||
|
||||
// Tally resources by key into the given dictionary. Any additions should
|
||||
// be cumulative with the existing key values.
|
||||
void _TallyResourceAllocation(VtDictionary *result) const;
|
||||
|
||||
// TODO: this is a transient structure. we'll revisit the BufferSource
|
||||
// interface later.
|
||||
struct _PendingSource {
|
||||
_PendingSource(HdBufferArrayRangeSharedPtr const &range)
|
||||
: range(range)
|
||||
, sources()
|
||||
{
|
||||
}
|
||||
|
||||
_PendingSource(HdBufferArrayRangeSharedPtr const &range,
|
||||
HdBufferSourceSharedPtr const &source)
|
||||
: range(range)
|
||||
, sources(1, source)
|
||||
{
|
||||
}
|
||||
|
||||
_PendingSource(HdBufferArrayRangeSharedPtr const &range,
|
||||
HdBufferSourceSharedPtrVector && sources)
|
||||
: range(range)
|
||||
, sources(std::move(sources))
|
||||
{
|
||||
}
|
||||
|
||||
HdBufferArrayRangeSharedPtr range;
|
||||
HdBufferSourceSharedPtrVector sources;
|
||||
};
|
||||
|
||||
Hgi* _hgi;
|
||||
|
||||
typedef tbb::concurrent_vector<_PendingSource> _PendingSourceList;
|
||||
_PendingSourceList _pendingSources;
|
||||
std::atomic_size_t _numBufferSourcesToResolve;
|
||||
|
||||
struct _PendingComputation{
|
||||
_PendingComputation(HdBufferArrayRangeSharedPtr const &range,
|
||||
HdComputationSharedPtr const &computation)
|
||||
: range(range), computation(computation) { }
|
||||
HdBufferArrayRangeSharedPtr range;
|
||||
HdComputationSharedPtr computation;
|
||||
};
|
||||
|
||||
// If we need more 'compute queues' we can increase HdStComputeQueueCount.
|
||||
// We could also consider tbb::concurrent_priority_queue if we want this
|
||||
// to be dynamically scalable.
|
||||
typedef tbb::concurrent_vector<_PendingComputation> _PendingComputationList;
|
||||
_PendingComputationList _pendingComputations[HdStComputeQueueCount];
|
||||
|
||||
// aggregated buffer array
|
||||
HdBufferArrayRegistry _nonUniformBufferArrayRegistry;
|
||||
HdBufferArrayRegistry _nonUniformImmutableBufferArrayRegistry;
|
||||
HdBufferArrayRegistry _uniformUboBufferArrayRegistry;
|
||||
HdBufferArrayRegistry _uniformSsboBufferArrayRegistry;
|
||||
HdBufferArrayRegistry _singleBufferArrayRegistry;
|
||||
|
||||
// current aggregation strategies
|
||||
std::unique_ptr<HdAggregationStrategy> _nonUniformAggregationStrategy;
|
||||
std::unique_ptr<HdAggregationStrategy>
|
||||
_nonUniformImmutableAggregationStrategy;
|
||||
std::unique_ptr<HdAggregationStrategy> _uniformUboAggregationStrategy;
|
||||
std::unique_ptr<HdAggregationStrategy> _uniformSsboAggregationStrategy;
|
||||
std::unique_ptr<HdAggregationStrategy> _singleAggregationStrategy;
|
||||
|
||||
typedef std::vector<HdStDispatchBufferSharedPtr>
|
||||
_DispatchBufferRegistry;
|
||||
_DispatchBufferRegistry _dispatchBufferRegistry;
|
||||
|
||||
typedef std::vector<HdStBufferResourceSharedPtr>
|
||||
_BufferResourceRegistry;
|
||||
_BufferResourceRegistry _bufferResourceRegistry;
|
||||
|
||||
// Register mesh topology.
|
||||
HdInstanceRegistry<HdSt_MeshTopologySharedPtr>
|
||||
_meshTopologyRegistry;
|
||||
|
||||
// Register basisCurves topology.
|
||||
HdInstanceRegistry<HdSt_BasisCurvesTopologySharedPtr>
|
||||
_basisCurvesTopologyRegistry;
|
||||
|
||||
// Register vertex adjacency.
|
||||
HdInstanceRegistry<Hd_VertexAdjacencySharedPtr>
|
||||
_vertexAdjacencyRegistry;
|
||||
|
||||
// Register topology index buffers.
|
||||
typedef HdInstanceRegistry<HdBufferArrayRangeSharedPtr>
|
||||
_TopologyIndexRangeInstanceRegistry;
|
||||
typedef tbb::concurrent_unordered_map< TfToken,
|
||||
_TopologyIndexRangeInstanceRegistry,
|
||||
TfToken::HashFunctor >
|
||||
_TopologyIndexRangeInstanceRegMap;
|
||||
|
||||
_TopologyIndexRangeInstanceRegMap _meshTopologyIndexRangeRegistry;
|
||||
_TopologyIndexRangeInstanceRegMap _basisCurvesTopologyIndexRangeRegistry;
|
||||
|
||||
// Register shared primvar buffers.
|
||||
HdInstanceRegistry<HdBufferArrayRangeSharedPtr>
|
||||
_primvarRangeRegistry;
|
||||
|
||||
// Register ext computation resource.
|
||||
HdInstanceRegistry<HdBufferArrayRangeSharedPtr>
|
||||
_extComputationDataRangeRegistry;
|
||||
|
||||
// geometric shader registry
|
||||
HdInstanceRegistry<HdSt_GeometricShaderSharedPtr>
|
||||
_geometricShaderRegistry;
|
||||
|
||||
// glsl shader program registry
|
||||
HdInstanceRegistry<HdStGLSLProgramSharedPtr>
|
||||
_glslProgramRegistry;
|
||||
|
||||
// glslfx file registry
|
||||
HdInstanceRegistry<HioGlslfxSharedPtr>
|
||||
_glslfxFileRegistry;
|
||||
|
||||
// texture handle registry
|
||||
std::unique_ptr<class HdSt_TextureHandleRegistry> _textureHandleRegistry;
|
||||
|
||||
// Hgi resource bindings registry
|
||||
HdInstanceRegistry<HgiResourceBindingsSharedPtr>
|
||||
_resourceBindingsRegistry;
|
||||
|
||||
// Hgi graphics pipeline registry
|
||||
HdInstanceRegistry<HgiGraphicsPipelineSharedPtr>
|
||||
_graphicsPipelineRegistry;
|
||||
|
||||
// Hgi compute pipeline registry
|
||||
HdInstanceRegistry<HgiComputePipelineSharedPtr>
|
||||
_computePipelineRegistry;
|
||||
|
||||
HgiBlitCmdsUniquePtr _blitCmds;
|
||||
HgiComputeCmdsUniquePtr _computeCmds;
|
||||
|
||||
std::unique_ptr<HdStStagingBuffer> _stagingBuffer;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif //PXR_IMAGING_HD_ST_RESOURCE_REGISTRY_H
|
||||
@@ -0,0 +1,210 @@
|
||||
//
|
||||
// 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_ST_SAMPLER_OBJECT_H
|
||||
#define PXR_IMAGING_HD_ST_SAMPLER_OBJECT_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
|
||||
#include "pxr/imaging/hgi/handle.h"
|
||||
#include "pxr/imaging/hd/enums.h"
|
||||
#include "pxr/imaging/hd/types.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class Hgi;
|
||||
class HdStUvTextureObject;
|
||||
class HdStFieldTextureObject;
|
||||
class HdStPtexTextureObject;
|
||||
class HdStUdimTextureObject;
|
||||
class HdSt_SamplerObjectRegistry;
|
||||
using HgiSamplerHandle = HgiHandle<class HgiSampler>;
|
||||
|
||||
using HdStSamplerObjectSharedPtr =
|
||||
std::shared_ptr<class HdStSamplerObject>;
|
||||
|
||||
/// \class HdStSamplerObject
|
||||
///
|
||||
/// A base class encapsulating a GPU sampler object.
|
||||
///
|
||||
/// The subclasses of HdStSamplerObject mirror the subclasses of
|
||||
/// HdStTextureObject with the intention that they will be used in
|
||||
/// conjunction (e.g., the not yet existing HdStPtexSamplerObject will
|
||||
/// have two samplers and texture sampler handles for the texels and
|
||||
/// layout texture in a HdStPtexTextureObject).
|
||||
///
|
||||
/// The GPU resources is con-/destructed immediately in the
|
||||
/// c'tor/d'tor. By going through the HdSt_SamplerObjectRegistry, we
|
||||
/// can obtain a shared pointer that can safely be dropped in a
|
||||
/// different thread. The HdSt_SamplerObjectRegistry is also dispatching
|
||||
/// by texture type to construct the corresponding sampler type.
|
||||
///
|
||||
class HdStSamplerObject
|
||||
{
|
||||
public:
|
||||
virtual ~HdStSamplerObject() = 0;
|
||||
|
||||
protected:
|
||||
explicit HdStSamplerObject(
|
||||
HdSt_SamplerObjectRegistry * samplerObjectRegistry);
|
||||
|
||||
Hgi* _GetHgi() const;
|
||||
HdSt_SamplerObjectRegistry * const _samplerObjectRegistry;
|
||||
};
|
||||
|
||||
/// \class HdStUvSamplerObject
|
||||
///
|
||||
/// A sampler suitable for HdStUvTextureObject.
|
||||
///
|
||||
class HdStUvSamplerObject final : public HdStSamplerObject {
|
||||
public:
|
||||
HDST_API
|
||||
HdStUvSamplerObject(
|
||||
HdStUvTextureObject const &uvTexture,
|
||||
HdSamplerParameters const &samplerParameters,
|
||||
HdSt_SamplerObjectRegistry * samplerObjectRegistry);
|
||||
|
||||
HDST_API
|
||||
~HdStUvSamplerObject() override;
|
||||
|
||||
/// The sampler.
|
||||
///
|
||||
const HgiSamplerHandle &GetSampler() const {
|
||||
return _sampler;
|
||||
}
|
||||
|
||||
private:
|
||||
HgiSamplerHandle _sampler;
|
||||
};
|
||||
|
||||
/// \class HdStFieldSamplerObject
|
||||
///
|
||||
/// A sampler suitable for HdStFieldTextureObject.
|
||||
///
|
||||
class HdStFieldSamplerObject final : public HdStSamplerObject {
|
||||
public:
|
||||
HdStFieldSamplerObject(
|
||||
HdStFieldTextureObject const &uvTexture,
|
||||
HdSamplerParameters const &samplerParameters,
|
||||
HdSt_SamplerObjectRegistry * samplerObjectRegistry);
|
||||
|
||||
~HdStFieldSamplerObject() override;
|
||||
|
||||
/// The sampler.
|
||||
///
|
||||
const HgiSamplerHandle &GetSampler() const {
|
||||
return _sampler;
|
||||
}
|
||||
|
||||
private:
|
||||
HgiSamplerHandle _sampler;
|
||||
};
|
||||
|
||||
/// \class HdStPtexSamplerObject
|
||||
///
|
||||
/// Ptex doesn't bind samplers, so this class is just holding a
|
||||
/// sampler to resolve handles for bindless textures.
|
||||
///
|
||||
class HdStPtexSamplerObject final : public HdStSamplerObject {
|
||||
public:
|
||||
HdStPtexSamplerObject(
|
||||
HdStPtexTextureObject const &ptexTexture,
|
||||
// samplerParameters are ignored by ptex
|
||||
HdSamplerParameters const &samplerParameters,
|
||||
HdSt_SamplerObjectRegistry * samplerObjectRegistry);
|
||||
|
||||
~HdStPtexSamplerObject() override;
|
||||
|
||||
/// The GPU sampler object for the texels texture.
|
||||
///
|
||||
const HgiSamplerHandle &GetTexelsSampler() const {
|
||||
return _texelsSampler;
|
||||
}
|
||||
|
||||
private:
|
||||
HgiSamplerHandle _texelsSampler;
|
||||
};
|
||||
|
||||
/// \class HdStUdimSamplerObject
|
||||
///
|
||||
/// A sampler suitable for Udim textures (wraps one GPU sampler
|
||||
/// for the texels texture).
|
||||
///
|
||||
class HdStUdimSamplerObject final : public HdStSamplerObject {
|
||||
public:
|
||||
HdStUdimSamplerObject(
|
||||
HdStUdimTextureObject const &ptexTexture,
|
||||
// samplerParameters are ignored by udim (at least for now)
|
||||
HdSamplerParameters const &samplerParameters,
|
||||
HdSt_SamplerObjectRegistry * samplerObjectRegistry);
|
||||
|
||||
~HdStUdimSamplerObject() override;
|
||||
|
||||
/// The GPU sampler object for the texels texture.
|
||||
///
|
||||
const HgiSamplerHandle &GetTexelsSampler() const {
|
||||
return _texelsSampler;
|
||||
}
|
||||
|
||||
private:
|
||||
HgiSamplerHandle _texelsSampler;
|
||||
};
|
||||
|
||||
template<HdTextureType textureType>
|
||||
struct HdSt_TypedSamplerObjectHelper;
|
||||
|
||||
/// \class HdStTypedSamplerObject
|
||||
///
|
||||
/// A template alias such that, e.g., HdStUvSamplerObject can be
|
||||
/// accessed as HdStTypedSamplerObject<HdTextureType::Uv>.
|
||||
///
|
||||
template<HdTextureType textureType>
|
||||
using HdStTypedSamplerObject =
|
||||
typename HdSt_TypedSamplerObjectHelper<textureType>::type;
|
||||
|
||||
template<>
|
||||
struct HdSt_TypedSamplerObjectHelper<HdTextureType::Uv> {
|
||||
using type = HdStUvSamplerObject;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct HdSt_TypedSamplerObjectHelper<HdTextureType::Field> {
|
||||
using type = HdStFieldSamplerObject;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct HdSt_TypedSamplerObjectHelper<HdTextureType::Ptex> {
|
||||
using type = HdStPtexSamplerObject;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct HdSt_TypedSamplerObjectHelper<HdTextureType::Udim> {
|
||||
using type = HdStUdimSamplerObject;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,93 @@
|
||||
//
|
||||
// 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_ST_SAMPLER_OBJECT_REGISTRY_H
|
||||
#define PXR_IMAGING_HD_ST_SAMPLER_OBJECT_REGISTRY_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdSamplerParameters;
|
||||
using HdStTextureObjectSharedPtr =
|
||||
std::shared_ptr<class HdStTextureObject>;
|
||||
using HdStSamplerObjectSharedPtr =
|
||||
std::shared_ptr<class HdStSamplerObject>;
|
||||
class HdStResourceRegistry;
|
||||
|
||||
/// \class HdSt_SamplerObjectRegistry
|
||||
///
|
||||
/// A simple registry for GPU samplers.
|
||||
///
|
||||
/// The registry makes no attempt at de-duplication. But construction
|
||||
/// is dispatched by texture type returing a matching sampler (e.g.,
|
||||
/// HdStFieldSamplerObject for a HdStFieldTextureObject or
|
||||
/// HdStPtexSamplerObject for the (not yet existing)
|
||||
/// HdStPtexTextureObject). Also, it keeps a shared pointer to a sampler
|
||||
/// around until garbage collection so that clients can safely drop their
|
||||
/// shared pointers from different threads.
|
||||
///
|
||||
class HdSt_SamplerObjectRegistry final
|
||||
{
|
||||
public:
|
||||
HDST_API
|
||||
explicit HdSt_SamplerObjectRegistry(HdStResourceRegistry * registry);
|
||||
|
||||
HDST_API
|
||||
~HdSt_SamplerObjectRegistry();
|
||||
|
||||
/// Create new sampler object matching the given texture object.
|
||||
///
|
||||
/// The associated GPU resource is created immediately and
|
||||
/// the call is not thread-safe.
|
||||
HDST_API
|
||||
HdStSamplerObjectSharedPtr AllocateSampler(
|
||||
HdStTextureObjectSharedPtr const &texture,
|
||||
HdSamplerParameters const &samplerParameters);
|
||||
|
||||
/// Delete samplers no longer used by a client.
|
||||
HDST_API
|
||||
void GarbageCollect();
|
||||
|
||||
HDST_API
|
||||
void MarkGarbageCollectionNeeded();
|
||||
|
||||
/// Get resource registry
|
||||
///
|
||||
HDST_API
|
||||
HdStResourceRegistry * GetResourceRegistry() const;
|
||||
|
||||
private:
|
||||
std::vector<HdStSamplerObjectSharedPtr> _samplerObjects;
|
||||
|
||||
bool _garbageCollectionNeeded;
|
||||
HdStResourceRegistry *_resourceRegistry;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,237 @@
|
||||
//
|
||||
// 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_ST_SHADER_CODE_H
|
||||
#define PXR_IMAGING_HD_ST_SHADER_CODE_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/imaging/hdSt/resourceRegistry.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/enums.h"
|
||||
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
|
||||
#include "pxr/base/tf/token.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
using HdBindingRequestVector = std::vector<class HdBindingRequest>;
|
||||
|
||||
using HdStShaderCodeSharedPtr =
|
||||
std::shared_ptr<class HdStShaderCode>;
|
||||
using HdStShaderCodeSharedPtrVector =
|
||||
std::vector<HdStShaderCodeSharedPtr>;
|
||||
|
||||
using HdSt_MaterialParamVector =
|
||||
std::vector<class HdSt_MaterialParam>;
|
||||
using HdBufferSourceSharedPtr =
|
||||
std::shared_ptr<class HdBufferSource>;
|
||||
using HdBufferSourceSharedPtrVector =
|
||||
std::vector<HdBufferSourceSharedPtr>;
|
||||
using HdBufferArrayRangeSharedPtr =
|
||||
std::shared_ptr<class HdBufferArrayRange>;
|
||||
using HdStTextureHandleSharedPtr =
|
||||
std::shared_ptr<class HdStTextureHandle>;
|
||||
using HdComputationSharedPtr =
|
||||
std::shared_ptr<class HdComputation>;
|
||||
|
||||
class HdRenderPassState;
|
||||
class HdSt_ResourceBinder;
|
||||
class HdStResourceRegistry;
|
||||
|
||||
/// \class HdStShaderCode
|
||||
///
|
||||
/// A base class representing the implementation (code) of a shader,
|
||||
/// used in conjunction with HdRenderPass.
|
||||
///
|
||||
/// This interface provides a simple way for clients to affect the
|
||||
/// composition of shading programs used for a render pass.
|
||||
class HdStShaderCode : public std::enable_shared_from_this<HdStShaderCode>
|
||||
{
|
||||
public:
|
||||
typedef size_t ID;
|
||||
|
||||
HDST_API
|
||||
HdStShaderCode();
|
||||
HDST_API
|
||||
virtual ~HdStShaderCode();
|
||||
|
||||
/// Returns the hash value of the shader code and configuration.
|
||||
///
|
||||
/// It is computed from the the GLSL code as well as the resource
|
||||
/// signature of the shader (as determined from its parameters).
|
||||
/// If two shaders have the same hash, the GLSL code as expanded
|
||||
/// by codegen should also be the same.
|
||||
///
|
||||
virtual ID ComputeHash() const = 0;
|
||||
|
||||
/// Returns the combined hash values of multiple shaders.
|
||||
HDST_API
|
||||
static ID ComputeHash(HdStShaderCodeSharedPtrVector const &shaders);
|
||||
|
||||
/// Returns the hash value of the paths of the texture prims
|
||||
/// consumed by this shader.
|
||||
///
|
||||
/// Unless textures are bindless, shaders using different textures
|
||||
/// cannot be used in the same draw batch. Since textures can be
|
||||
/// animated, it can happen that two texture prims use the same
|
||||
/// texture at some time but different textures at other times. To
|
||||
/// avoid re-computing the draw batches over time, we use the this
|
||||
/// hash when grouping the draw batches.
|
||||
///
|
||||
virtual ID ComputeTextureSourceHash() const;
|
||||
|
||||
/// Returns the shader source provided by this shader
|
||||
/// for \a shaderStageKey
|
||||
virtual std::string GetSource(TfToken const &shaderStageKey) const = 0;
|
||||
|
||||
// XXX: Should be pure-virtual
|
||||
/// Returns the shader parameters for this shader.
|
||||
HDST_API
|
||||
virtual HdSt_MaterialParamVector const& GetParams() const;
|
||||
|
||||
/// Returns whether primvar filtering is enabled for this shader.
|
||||
HDST_API
|
||||
virtual bool IsEnabledPrimvarFiltering() const;
|
||||
|
||||
/// Returns the names of primvar that are used by this shader.
|
||||
HDST_API
|
||||
virtual TfTokenVector const& GetPrimvarNames() const;
|
||||
|
||||
/// @}
|
||||
|
||||
///
|
||||
/// \name Texture system
|
||||
/// @{
|
||||
|
||||
/// Information necessary to bind textures and create accessor
|
||||
/// for the texture.
|
||||
///
|
||||
struct NamedTextureHandle {
|
||||
/// Name by which the texture will be accessed, i.e., the name
|
||||
/// of the accesor for thexture will be HdGet_name(...).
|
||||
///
|
||||
TfToken name;
|
||||
/// Equal to handle->GetTextureObject()->GetTextureType().
|
||||
/// Saved here for convenience (note that name and type
|
||||
/// completely determine the creation of the texture accesor
|
||||
/// HdGet_name(...)).
|
||||
///
|
||||
HdTextureType type;
|
||||
/// The texture.
|
||||
HdStTextureHandleSharedPtr handle;
|
||||
|
||||
/// A hash unique to the corresponding asset; used to
|
||||
/// split draw batches when not using bindless textures.
|
||||
size_t hash;
|
||||
};
|
||||
using NamedTextureHandleVector = std::vector<NamedTextureHandle>;
|
||||
|
||||
/// Textures that need to be bound for this shader.
|
||||
///
|
||||
HDST_API
|
||||
virtual NamedTextureHandleVector const & GetNamedTextureHandles() const;
|
||||
|
||||
/// @}
|
||||
|
||||
// XXX: Should be pure-virtual
|
||||
/// Returns a buffer which stores parameter fallback values and texture
|
||||
/// handles.
|
||||
HDST_API
|
||||
virtual HdBufferArrayRangeSharedPtr const& GetShaderData() const;
|
||||
|
||||
/// Binds shader-specific resources to \a program
|
||||
/// XXX: this interface is meant to be used for bridging
|
||||
/// the GlfSimpleLightingContext mechanism, and not for generic use-cases.
|
||||
virtual void BindResources(int program,
|
||||
HdSt_ResourceBinder const &binder,
|
||||
HdRenderPassState const &state) = 0;
|
||||
|
||||
/// Unbinds shader-specific resources.
|
||||
virtual void UnbindResources(int program,
|
||||
HdSt_ResourceBinder const &binder,
|
||||
HdRenderPassState const &state) = 0;
|
||||
|
||||
/// Add custom bindings (used by codegen)
|
||||
virtual void AddBindings(HdBindingRequestVector* customBindings) = 0;
|
||||
|
||||
/// Material tags can be set in the meta-data of a glslfx file to control
|
||||
/// what rprim collection that prims using this shader should go into.
|
||||
/// E.g. We can use it to split opaque and translucent prims into different
|
||||
/// collections. When no material tags are specified in the shader, a empty
|
||||
/// token is returned.
|
||||
HDST_API
|
||||
virtual TfToken GetMaterialTag() const;
|
||||
|
||||
/// \class ResourceContext
|
||||
///
|
||||
/// The context available in implementations of
|
||||
/// AddResourcesFromTextures.
|
||||
class ResourceContext {
|
||||
public:
|
||||
HDST_API
|
||||
void AddSource(HdBufferArrayRangeSharedPtr const &range,
|
||||
HdBufferSourceSharedPtr const &source);
|
||||
|
||||
HDST_API
|
||||
void AddSources(HdBufferArrayRangeSharedPtr const &range,
|
||||
HdBufferSourceSharedPtrVector &&sources);
|
||||
|
||||
HDST_API
|
||||
void AddComputation(HdBufferArrayRangeSharedPtr const &range,
|
||||
HdComputationSharedPtr const &computation,
|
||||
HdStComputeQueue const queue);
|
||||
|
||||
private:
|
||||
friend class HdStResourceRegistry;
|
||||
ResourceContext(HdStResourceRegistry *);
|
||||
HdStResourceRegistry *_registry;
|
||||
};
|
||||
|
||||
/// This function is called after textures have been allocated and
|
||||
/// loaded to add buffer sources and computations to the resource
|
||||
/// registry that require texture meta data not available until
|
||||
/// the texture is allocated or loaded. For example, the OpenGl
|
||||
/// texture sampler handle (in the bindless case) is not available
|
||||
/// until after the texture commit phase.
|
||||
///
|
||||
HDST_API
|
||||
virtual void AddResourcesFromTextures(ResourceContext &ctx) const;
|
||||
|
||||
private:
|
||||
|
||||
// No copying
|
||||
HdStShaderCode(const HdStShaderCode &) = delete;
|
||||
HdStShaderCode &operator =(const HdStShaderCode &) = delete;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif //HDST_SHADER_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_HDST_SIMPLE_LIGHTING_SHADER_H
|
||||
#define PXR_IMAGING_HDST_SIMPLE_LIGHTING_SHADER_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/imaging/hdSt/lightingShader.h"
|
||||
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
|
||||
#include "pxr/imaging/glf/simpleLightingContext.h"
|
||||
#include "pxr/base/tf/declarePtrs.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdSceneDelegate;
|
||||
using HdStSimpleLightingShaderSharedPtr =
|
||||
std::shared_ptr<class HdStSimpleLightingShader>;
|
||||
TF_DECLARE_REF_PTRS(GlfBindingMap);
|
||||
|
||||
/// \class HdStSimpleLightingShader
|
||||
///
|
||||
/// A shader that supports simple lighting functionality.
|
||||
///
|
||||
class HdStSimpleLightingShader : public HdStLightingShader
|
||||
{
|
||||
public:
|
||||
HDST_API
|
||||
HdStSimpleLightingShader();
|
||||
HDST_API
|
||||
~HdStSimpleLightingShader() override;
|
||||
|
||||
/// HdShader overrides
|
||||
HDST_API
|
||||
ID ComputeHash() const override;
|
||||
HDST_API
|
||||
std::string GetSource(TfToken const &shaderStageKey) const override;
|
||||
HDST_API
|
||||
void BindResources(int program,
|
||||
HdSt_ResourceBinder const &binder,
|
||||
HdRenderPassState const &state) override;
|
||||
HDST_API
|
||||
void UnbindResources(int program,
|
||||
HdSt_ResourceBinder const &binder,
|
||||
HdRenderPassState const &state) override;
|
||||
HDST_API
|
||||
void AddBindings(HdBindingRequestVector *customBindings) override;
|
||||
|
||||
/// Adds computations to create the dome light textures that
|
||||
/// are pre-calculated from the environment map texture.
|
||||
HDST_API
|
||||
void AddResourcesFromTextures(ResourceContext &ctx) const override;
|
||||
|
||||
/// HdStShaderCode overrides
|
||||
HDST_API
|
||||
HdSt_MaterialParamVector const& GetParams() const override;
|
||||
|
||||
/// HdStLightingShader overrides
|
||||
HDST_API
|
||||
void SetCamera(
|
||||
GfMatrix4d const &worldToViewMatrix,
|
||||
GfMatrix4d const &projectionMatrix) override;
|
||||
HDST_API
|
||||
void SetLightingStateFromOpenGL();
|
||||
HDST_API
|
||||
void SetLightingState(GlfSimpleLightingContextPtr const &lightingContext);
|
||||
|
||||
GlfSimpleLightingContextRefPtr GetLightingContext() const {
|
||||
return _lightingContext;
|
||||
};
|
||||
|
||||
/// Allocates texture handles (texture loading happens later during commit)
|
||||
/// needed for lights.
|
||||
///
|
||||
/// Call after lighting context has been set or updated in Sync-phase.
|
||||
///
|
||||
HDST_API
|
||||
void AllocateTextureHandles(HdSceneDelegate *delegate);
|
||||
|
||||
/// The dome light environment map used as source for the other
|
||||
/// dome light textures.
|
||||
const HdStTextureHandleSharedPtr &
|
||||
GetDomeLightEnvironmentTextureHandle() const {
|
||||
return _domeLightEnvironmentTextureHandle;
|
||||
}
|
||||
|
||||
/// The textures computed from the dome light environment map that
|
||||
/// the shader needs to bind for the dome light shading.
|
||||
HDST_API
|
||||
NamedTextureHandleVector const &GetNamedTextureHandles() const override;
|
||||
|
||||
/// Get one of the textures that need to be computed from the dome
|
||||
/// light environment map.
|
||||
HDST_API
|
||||
const HdStTextureHandleSharedPtr &GetTextureHandle(
|
||||
const TfToken &name) const;
|
||||
|
||||
private:
|
||||
GlfSimpleLightingContextRefPtr _lightingContext;
|
||||
GlfBindingMapRefPtr _bindingMap;
|
||||
bool _useLighting;
|
||||
std::unique_ptr<class HioGlslfx> _glslfx;
|
||||
|
||||
// The environment map used as source for the dome light textures.
|
||||
//
|
||||
// Handle is allocated in AllocateTextureHandles. Actual loading
|
||||
// happens during commit.
|
||||
HdStTextureHandleSharedPtr _domeLightEnvironmentTextureHandle;
|
||||
|
||||
// Other dome light textures.
|
||||
NamedTextureHandleVector _namedTextureHandles;
|
||||
|
||||
HdSt_MaterialParamVector _lightTextureParams;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HDST_SIMPLE_LIGHTING_SHADER_H
|
||||
@@ -0,0 +1,74 @@
|
||||
//
|
||||
// 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_ST_SMOOTH_NORMALS_H
|
||||
#define PXR_IMAGING_HD_ST_SMOOTH_NORMALS_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/imaging/hd/bufferSource.h"
|
||||
#include "pxr/imaging/hd/computation.h"
|
||||
|
||||
#include "pxr/base/tf/token.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
class Hd_VertexAdjacency;
|
||||
|
||||
/// smooth normal computation GPU
|
||||
///
|
||||
///
|
||||
class HdSt_SmoothNormalsComputationGPU : public HdComputation {
|
||||
public:
|
||||
/// Constructor
|
||||
HDST_API
|
||||
HdSt_SmoothNormalsComputationGPU(Hd_VertexAdjacency const *adjacency,
|
||||
TfToken const &srcName,
|
||||
TfToken const &dstName,
|
||||
HdType srcDataType,
|
||||
bool packed);
|
||||
|
||||
HDST_API
|
||||
virtual void GetBufferSpecs(HdBufferSpecVector *specs) const override;
|
||||
HDST_API
|
||||
virtual void Execute(HdBufferArrayRangeSharedPtr const &range,
|
||||
HdResourceRegistry *resourceRegistry) override;
|
||||
|
||||
/// This computation doesn't generate buffer source (i.e. 2nd phase)
|
||||
/// This is a gpu computation, but no need to resize the destination
|
||||
/// since it belongs the same range as src buffer.
|
||||
virtual int GetNumOutputElements() const override { return 0; }
|
||||
|
||||
private:
|
||||
Hd_VertexAdjacency const *_adjacency;
|
||||
TfToken _srcName;
|
||||
TfToken _dstName;
|
||||
HdType _srcDataType;
|
||||
HdType _dstDataType;
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_ST_SMOOTH_NORMALS_H
|
||||
@@ -0,0 +1,94 @@
|
||||
//
|
||||
// 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_ST_STAGING_BUFFER_H
|
||||
#define PXR_IMAGING_HD_ST_STAGING_BUFFER_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
|
||||
#include "pxr/imaging/hgi/blitCmdsOps.h"
|
||||
#include "pxr/imaging/hgi/buffer.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdStResourceRegistry;
|
||||
|
||||
using HdStStagingBufferSharedPtr =
|
||||
std::shared_ptr<class HdStStagingBuffer>;
|
||||
|
||||
/// \class HdStStagingBuffer
|
||||
///
|
||||
/// Provides a staging buffer for CPU writes of triple-buffered resources.
|
||||
/// None of the function calls are thread safe, they should be only accessed
|
||||
/// from the commit call to ResourceRegistry.
|
||||
///
|
||||
class HdStStagingBuffer
|
||||
{
|
||||
public:
|
||||
HDST_API
|
||||
HdStStagingBuffer(HdStResourceRegistry *resourceRegistry);
|
||||
|
||||
HDST_API
|
||||
~HdStStagingBuffer();
|
||||
|
||||
/// Destroys contained HgiBuffers and resets state to empty.
|
||||
HDST_API
|
||||
void Deallocate();
|
||||
|
||||
/// Set the capacity for the staging buffer. Only applied once first call
|
||||
/// to StageCopy is called.
|
||||
/// Cannot be called if there have already been calls to StageCopy for this
|
||||
/// commit.
|
||||
HDST_API
|
||||
void Resize(size_t totalSize);
|
||||
|
||||
/// Submit a CPU to GPU copy operation to be added to the staging buffer.
|
||||
/// The contents are memcpy'd over into the staging buffer during this call
|
||||
/// and a GPU to GPU blit is queued up to do the final copy to destination.
|
||||
HDST_API
|
||||
void StageCopy(HgiBufferCpuToGpuOp const ©Op);
|
||||
|
||||
/// Flush the queued GPU to GPU blits from the calls to StageCopy. Resets
|
||||
/// the state for the next ResoureRegistry commit.
|
||||
HDST_API
|
||||
void Flush();
|
||||
|
||||
private:
|
||||
static constexpr int32_t MULTIBUFFERING = 3;
|
||||
|
||||
HdStResourceRegistry *_resourceRegistry;
|
||||
HgiBufferHandle _handles[MULTIBUFFERING];
|
||||
size_t _head;
|
||||
size_t _capacity;
|
||||
size_t _activeSlot;
|
||||
bool _tripleBuffered;
|
||||
std::vector<HgiBufferGpuToGpuOp> _gpuCopyOps;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_ST_STAGING_BUFFER_H
|
||||
@@ -0,0 +1,263 @@
|
||||
//
|
||||
// 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_ST_SUBTEXTURE_IDENTIFIER_H
|
||||
#define PXR_IMAGING_HD_ST_SUBTEXTURE_IDENTIFIER_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
|
||||
#include "pxr/base/tf/token.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdStDynamicUvTextureImplementation;
|
||||
|
||||
///
|
||||
/// \class HdStSubtextureIdentifier
|
||||
///
|
||||
/// Base class for additional information to identify a texture in a
|
||||
/// file that can contain several textures (e.g., frames in a movie or
|
||||
/// grids in an OpenVDB file).
|
||||
///
|
||||
class HdStSubtextureIdentifier
|
||||
{
|
||||
public:
|
||||
using ID = size_t;
|
||||
|
||||
HDST_API
|
||||
virtual std::unique_ptr<HdStSubtextureIdentifier> Clone() const = 0;
|
||||
|
||||
HDST_API
|
||||
virtual ~HdStSubtextureIdentifier();
|
||||
|
||||
protected:
|
||||
HDST_API
|
||||
friend size_t hash_value(const HdStSubtextureIdentifier &subId);
|
||||
|
||||
virtual ID _Hash() const = 0;
|
||||
};
|
||||
|
||||
HDST_API
|
||||
size_t hash_value(const HdStSubtextureIdentifier &subId);
|
||||
|
||||
///
|
||||
/// \class HdStFieldBaseSubtextureIdentifier
|
||||
///
|
||||
/// Base class for information identifying a grid in a volume field
|
||||
/// file. Parallels FieldBase in usdVol.
|
||||
///
|
||||
class HdStFieldBaseSubtextureIdentifier : public HdStSubtextureIdentifier
|
||||
{
|
||||
public:
|
||||
/// Get field name.
|
||||
///
|
||||
HDST_API
|
||||
TfToken const &GetFieldName() const { return _fieldName; }
|
||||
|
||||
/// Get field index.
|
||||
///
|
||||
HDST_API
|
||||
int GetFieldIndex() const { return _fieldIndex; }
|
||||
|
||||
HDST_API
|
||||
~HdStFieldBaseSubtextureIdentifier() override = 0;
|
||||
|
||||
protected:
|
||||
HDST_API
|
||||
HdStFieldBaseSubtextureIdentifier(TfToken const &fieldName, int fieldIndex);
|
||||
|
||||
HDST_API
|
||||
ID _Hash() const override;
|
||||
|
||||
private:
|
||||
TfToken _fieldName;
|
||||
int _fieldIndex;
|
||||
};
|
||||
|
||||
///
|
||||
/// \class HdStAssetUvSubtextureIdentifier
|
||||
///
|
||||
/// Specifies whether a UV texture should be loaded flipped vertically, whether
|
||||
/// it should be loaded with pre-multiplied alpha values, and the color space
|
||||
/// in which the texture is encoded.
|
||||
///
|
||||
/// The former functionality allows the texture system to support both the
|
||||
/// legacy HwUvTexture_1 (flipVertically = true) and UsdUvTexture
|
||||
/// (flipVertically = false) which have opposite conventions for the
|
||||
/// vertical orientation.
|
||||
///
|
||||
class HdStAssetUvSubtextureIdentifier final
|
||||
: public HdStSubtextureIdentifier
|
||||
{
|
||||
public:
|
||||
/// C'tor takes bool whether flipping vertically, whether to pre-multiply
|
||||
/// by alpha, and the texture's source color space
|
||||
HDST_API
|
||||
explicit HdStAssetUvSubtextureIdentifier(bool flipVertically,
|
||||
bool premultiplyAlpha,
|
||||
const TfToken& sourceColorSpace);
|
||||
|
||||
HDST_API
|
||||
std::unique_ptr<HdStSubtextureIdentifier> Clone() const override;
|
||||
|
||||
HDST_API
|
||||
bool GetFlipVertically() const { return _flipVertically; }
|
||||
|
||||
HDST_API
|
||||
bool GetPremultiplyAlpha() const { return _premultiplyAlpha; }
|
||||
|
||||
HDST_API
|
||||
TfToken GetSourceColorSpace() const { return _sourceColorSpace; }
|
||||
|
||||
HDST_API
|
||||
~HdStAssetUvSubtextureIdentifier() override;
|
||||
|
||||
protected:
|
||||
HDST_API
|
||||
ID _Hash() const override;
|
||||
|
||||
private:
|
||||
bool _flipVertically;
|
||||
bool _premultiplyAlpha;
|
||||
TfToken _sourceColorSpace;
|
||||
};
|
||||
|
||||
///
|
||||
/// \class HdStDynamicUvSubtextureIdentifier
|
||||
///
|
||||
/// Used as a tag that the Storm texture system returns a
|
||||
/// HdStDynamicUvTextureObject that is populated by a client rather
|
||||
/// than by the Storm texture system.
|
||||
///
|
||||
/// Clients can subclass this class and provide their own
|
||||
/// HdStDynamicUvTextureImplementation to create UV texture with custom
|
||||
/// load and commit behavior.
|
||||
///
|
||||
/// testHdStDynamicUvTexture.cpp is an example of how custom load and
|
||||
/// commit behavior can be implemented.
|
||||
///
|
||||
/// AOV's are another example. In presto, these are baked by
|
||||
/// HdStDynamicUvTextureObject's. In this case, the
|
||||
/// HdStDynamicUvTextureObject's do not provide custom load or commit
|
||||
/// behavior (null-ptr returned by GetTextureImplementation). Instead,
|
||||
/// GPU memory is allocated by explicitly calling
|
||||
/// HdStDynamicUvTextureObject::CreateTexture in
|
||||
/// HdStRenderBuffer::Sync/Allocate and the texture is filled by using
|
||||
/// it as render target in various render passes.
|
||||
///
|
||||
class HdStDynamicUvSubtextureIdentifier : public HdStSubtextureIdentifier
|
||||
{
|
||||
public:
|
||||
HDST_API
|
||||
HdStDynamicUvSubtextureIdentifier();
|
||||
|
||||
HDST_API
|
||||
~HdStDynamicUvSubtextureIdentifier() override;
|
||||
|
||||
HDST_API
|
||||
std::unique_ptr<HdStSubtextureIdentifier> Clone() const override;
|
||||
|
||||
/// Textures can return their own HdStDynamicUvTextureImplementation
|
||||
/// to customize the load and commit behavior.
|
||||
HDST_API
|
||||
virtual HdStDynamicUvTextureImplementation *GetTextureImplementation() const;
|
||||
|
||||
protected:
|
||||
HDST_API
|
||||
ID _Hash() const override;
|
||||
};
|
||||
|
||||
///
|
||||
/// \class HdStPtexSubtextureIdentifier
|
||||
///
|
||||
/// Specifies whether a Ptex texture should be loaded with pre-multiplied alpha
|
||||
/// values.
|
||||
///
|
||||
class HdStPtexSubtextureIdentifier final
|
||||
: public HdStSubtextureIdentifier
|
||||
{
|
||||
public:
|
||||
/// C'tor takes bool whether to pre-multiply by alpha
|
||||
HDST_API
|
||||
explicit HdStPtexSubtextureIdentifier(bool premultiplyAlpha);
|
||||
|
||||
HDST_API
|
||||
std::unique_ptr<HdStSubtextureIdentifier> Clone() const override;
|
||||
|
||||
HDST_API
|
||||
bool GetPremultiplyAlpha() const { return _premultiplyAlpha; }
|
||||
|
||||
HDST_API
|
||||
~HdStPtexSubtextureIdentifier() override;
|
||||
|
||||
protected:
|
||||
HDST_API
|
||||
ID _Hash() const override;
|
||||
|
||||
private:
|
||||
bool _premultiplyAlpha;
|
||||
};
|
||||
|
||||
///
|
||||
/// \class HdStUdimSubtextureIdentifier
|
||||
///
|
||||
/// Specifies whether a Udim texture should be loaded with pre-multiplied alpha
|
||||
/// values and the color space in which the texture is encoded.
|
||||
///
|
||||
class HdStUdimSubtextureIdentifier final
|
||||
: public HdStSubtextureIdentifier
|
||||
{
|
||||
public:
|
||||
/// C'tor takes bool whether to pre-multiply by alpha and the texture's
|
||||
/// source color space
|
||||
HDST_API
|
||||
explicit HdStUdimSubtextureIdentifier(bool premultiplyAlpha,
|
||||
const TfToken& sourceColorSpace);
|
||||
|
||||
HDST_API
|
||||
std::unique_ptr<HdStSubtextureIdentifier> Clone() const override;
|
||||
|
||||
HDST_API
|
||||
bool GetPremultiplyAlpha() const { return _premultiplyAlpha; }
|
||||
|
||||
HDST_API
|
||||
TfToken GetSourceColorSpace() const { return _sourceColorSpace; }
|
||||
|
||||
HDST_API
|
||||
~HdStUdimSubtextureIdentifier() override;
|
||||
|
||||
protected:
|
||||
HDST_API
|
||||
ID _Hash() const override;
|
||||
|
||||
private:
|
||||
bool _premultiplyAlpha;
|
||||
TfToken _sourceColorSpace;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,89 @@
|
||||
//
|
||||
// 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_ST_TEXTURE_BINDER_H
|
||||
#define PXR_IMAGING_HD_ST_TEXTURE_BINDER_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/imaging/hdSt/shaderCode.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
using HdBufferSpecVector = std::vector<struct HdBufferSpec>;
|
||||
|
||||
/// \class HdSt_TextureBinder
|
||||
///
|
||||
/// A class helping HdStShaderCode with binding textures.
|
||||
///
|
||||
/// This class helps binding textures or populating the shader
|
||||
/// bar with texture sampler handles if bindless textures are used. It
|
||||
/// also includes writing texture metadata such as the sampling
|
||||
/// transform to the shader bar.
|
||||
///
|
||||
class HdSt_TextureBinder {
|
||||
public:
|
||||
using NamedTextureHandle =
|
||||
HdStShaderCode::NamedTextureHandle;
|
||||
using NamedTextureHandleVector =
|
||||
HdStShaderCode::NamedTextureHandleVector;
|
||||
|
||||
/// Add buffer specs necessary for the textures (e.g., for
|
||||
/// bindless texture sampler handles or sampling transform).
|
||||
///
|
||||
static void
|
||||
GetBufferSpecs(
|
||||
const NamedTextureHandleVector &textures,
|
||||
HdBufferSpecVector * specs);
|
||||
|
||||
/// Compute buffer sources for shader bar.
|
||||
///
|
||||
/// This works in conjunction with GetBufferSpecs, but unlike
|
||||
/// GetBufferSpecs is extracting information from the texture
|
||||
/// handles and thus can only be called after the textures have
|
||||
/// been committed in
|
||||
/// HdStShaderCode::AddResourcesFromTextures().
|
||||
///
|
||||
static void
|
||||
ComputeBufferSources(
|
||||
const NamedTextureHandleVector &textures,
|
||||
HdBufferSourceSharedPtrVector * sources);
|
||||
|
||||
/// Bind textures.
|
||||
///
|
||||
static void
|
||||
BindResources(
|
||||
HdSt_ResourceBinder const &binder,
|
||||
const NamedTextureHandleVector &textures);
|
||||
|
||||
/// Unbind textures.
|
||||
///
|
||||
static void
|
||||
UnbindResources(
|
||||
HdSt_ResourceBinder const &binder,
|
||||
const NamedTextureHandleVector &textures);
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_ST_TEXTURE_BINDER_H
|
||||
@@ -0,0 +1,59 @@
|
||||
//
|
||||
// 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_ST_TEXTURE_CPU_DATA_H
|
||||
#define PXR_IMAGING_HD_ST_TEXTURE_CPU_DATA_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
struct HgiTextureDesc;
|
||||
|
||||
/// \class HdStTextureCpuData
|
||||
///
|
||||
/// Represents CPU data that can be stored in a HdStUvTextureObject, mostly,
|
||||
/// likely during the load phase to be committed to the GPU.
|
||||
///
|
||||
class HdStTextureCpuData {
|
||||
public:
|
||||
HDST_API
|
||||
virtual ~HdStTextureCpuData();
|
||||
|
||||
/// The metadata of the texture (width, height, ...) including a
|
||||
/// pointer to the CPU data (as initialData).
|
||||
virtual const HgiTextureDesc &GetTextureDesc() const = 0;
|
||||
|
||||
/// Make GPU generate mipmaps. The number of mipmaps is specified
|
||||
/// in the texture descriptor and the mipmaps are generate from
|
||||
/// the mip level 0 data.
|
||||
virtual bool GetGenerateMipmaps() const = 0;
|
||||
|
||||
/// Are the data valid (e.g., false if file could not be found).
|
||||
virtual bool IsValid() const = 0;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,123 @@
|
||||
//
|
||||
// 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 HD_ST_TEXTURE_HANDLE_H
|
||||
#define HD_ST_TEXTURE_HANDLE_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
|
||||
#include "pxr/imaging/hd/enums.h"
|
||||
#include "pxr/imaging/hd/types.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
using HdStShaderCodePtr =
|
||||
std::weak_ptr<class HdStShaderCode>;
|
||||
using HdStTextureObjectSharedPtr =
|
||||
std::shared_ptr<class HdStTextureObject>;
|
||||
using HdStSamplerObjectSharedPtr =
|
||||
std::shared_ptr<class HdStSamplerObject>;
|
||||
|
||||
using HdStTextureHandleSharedPtr =
|
||||
std::shared_ptr<class HdStTextureHandle>;
|
||||
|
||||
class HdSt_TextureHandleRegistry;
|
||||
|
||||
/// \class HdStTextureHandle
|
||||
///
|
||||
/// Represents a texture and sampler that will be allocated and loaded
|
||||
/// from a texture file during commit, possibly a texture sampler
|
||||
/// handle and a memory request. It is intended for HdStShaderCode and
|
||||
/// HdStShaderCode::AddResourcesFromTextures() is called whenever
|
||||
/// the underlying texture and sampler gets allocated and (re-)loaded
|
||||
/// so that the shader code can react to, e.g., changing texture
|
||||
/// sampler handle for bindless or changing texture metadata such as a
|
||||
/// field bounding box for volumes.
|
||||
///
|
||||
class HdStTextureHandle
|
||||
{
|
||||
public:
|
||||
/// See HdStResourceRegistry::AllocateTextureHandle for details.
|
||||
HDST_API
|
||||
HdStTextureHandle(
|
||||
HdStTextureObjectSharedPtr const &textureObject,
|
||||
const HdSamplerParameters &samplerParams,
|
||||
size_t memoryRequest,
|
||||
HdStShaderCodePtr const & shaderCode,
|
||||
HdSt_TextureHandleRegistry *textureHandleRegistry);
|
||||
|
||||
HDST_API
|
||||
~HdStTextureHandle();
|
||||
|
||||
/// Get texture object.
|
||||
///
|
||||
/// Can be accessed after commit.
|
||||
HdStTextureObjectSharedPtr const &GetTextureObject() const {
|
||||
return _textureObject;
|
||||
}
|
||||
|
||||
/// Get sampler object.
|
||||
///
|
||||
/// Can be accessed after commit.
|
||||
HdStSamplerObjectSharedPtr const &GetSamplerObject() const {
|
||||
return _samplerObject;
|
||||
}
|
||||
|
||||
/// Get sampler parameters.
|
||||
///
|
||||
HdSamplerParameters const &GetSamplerParameters() const {
|
||||
return _samplerParams;
|
||||
}
|
||||
|
||||
/// Get how much memory this handle requested for the texture.
|
||||
///
|
||||
size_t GetMemoryRequest() const {
|
||||
return _memoryRequest;
|
||||
}
|
||||
|
||||
/// Get the shader code associated with this handle.
|
||||
///
|
||||
HdStShaderCodePtr const &GetShaderCode() const {
|
||||
return _shaderCode;
|
||||
}
|
||||
|
||||
/// Allocate sampler for this handle (not thread-safe).
|
||||
///
|
||||
HDST_API
|
||||
void ReallocateSamplerIfNecessary();
|
||||
|
||||
private:
|
||||
HdStTextureObjectSharedPtr _textureObject;
|
||||
HdStSamplerObjectSharedPtr _samplerObject;
|
||||
HdSamplerParameters _samplerParams;
|
||||
size_t _memoryRequest;
|
||||
HdStShaderCodePtr _shaderCode;
|
||||
HdSt_TextureHandleRegistry *_textureHandleRegistry;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,193 @@
|
||||
//
|
||||
// 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_ST_TEXTURE_HANDLE_REGISTRY_H
|
||||
#define PXR_IMAGING_HD_ST_TEXTURE_HANDLE_REGISTRY_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
|
||||
#include "pxr/imaging/hdSt/textureObject.h"
|
||||
|
||||
#include "pxr/imaging/hd/enums.h"
|
||||
|
||||
#include <tbb/concurrent_vector.h>
|
||||
|
||||
#include <set>
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdStResourceRegistry;
|
||||
class HdStTextureIdentifier;
|
||||
class HdSamplerParameters;
|
||||
class HdSt_SamplerObjectRegistry;
|
||||
|
||||
using HdStTextureHandlePtr =
|
||||
std::weak_ptr<class HdStTextureHandle>;
|
||||
using HdStTextureHandleSharedPtr =
|
||||
std::shared_ptr<class HdStTextureHandle>;
|
||||
using HdStTextureObjectPtr =
|
||||
std::weak_ptr<class HdStTextureObject>;
|
||||
using HdStTextureObjectSharedPtr =
|
||||
std::shared_ptr<class HdStTextureObject>;
|
||||
using HdStSamplerObjectSharedPtr =
|
||||
std::shared_ptr<class HdStSamplerObject>;
|
||||
using HdStShaderCodePtr =
|
||||
std::weak_ptr<class HdStShaderCode>;
|
||||
using HdStShaderCodeSharedPtr =
|
||||
std::shared_ptr<class HdStShaderCode>;
|
||||
|
||||
/// \class HdSt_TextureHandleRegistry
|
||||
///
|
||||
/// Keeps track of texture handles and allocates the textures and
|
||||
/// samplers using the HdSt_TextureObjectRegistry, respectively,
|
||||
/// HdSt_SamplerObjectRegistry. Its responsibilities including
|
||||
/// tracking what texture handles are associated to a texture,
|
||||
/// computing the target memory of a texture from the memory requests
|
||||
/// in the texture handles, triggering sampler and texture garbage
|
||||
/// collection, and determining what HdStShaderCode instances are
|
||||
/// affecting by (re-)committing a texture.
|
||||
///
|
||||
class HdSt_TextureHandleRegistry final
|
||||
{
|
||||
public:
|
||||
HDST_API
|
||||
explicit HdSt_TextureHandleRegistry(HdStResourceRegistry * registry);
|
||||
|
||||
HDST_API
|
||||
~HdSt_TextureHandleRegistry();
|
||||
|
||||
/// Allocate texture handle (thread-safe).
|
||||
///
|
||||
/// See HdStResourceRegistry::AllocateTextureHandle for details.
|
||||
///
|
||||
HDST_API
|
||||
HdStTextureHandleSharedPtr AllocateTextureHandle(
|
||||
const HdStTextureIdentifier &textureId,
|
||||
HdTextureType textureType,
|
||||
const HdSamplerParameters &samplerParams,
|
||||
/// memoryRequest in bytes.
|
||||
size_t memoryRequest,
|
||||
HdStShaderCodePtr const &shaderCode);
|
||||
|
||||
/// Mark texture dirty (thread-safe).
|
||||
///
|
||||
/// If set, the target memory of the texture will be recomputed
|
||||
/// during commit and the data structure tracking the associated
|
||||
/// handles will be updated potentially triggering texture garbage
|
||||
/// collection.
|
||||
///
|
||||
HDST_API
|
||||
void MarkDirty(HdStTextureObjectPtr const &texture);
|
||||
|
||||
/// Mark shader dirty (thread-safe).
|
||||
///
|
||||
/// If set, the shader is scheduled to be updated (i.e., have its
|
||||
/// AddResourcesFromTextures called) on the next commit.
|
||||
///
|
||||
HDST_API
|
||||
void MarkDirty(HdStShaderCodePtr const &shader);
|
||||
|
||||
/// Mark that sampler garbage collection needs to happen during
|
||||
/// next commit (thead-safe).
|
||||
///
|
||||
HDST_API
|
||||
void MarkSamplerGarbageCollectionNeeded();
|
||||
|
||||
/// Get texture object registry.
|
||||
///
|
||||
HdSt_TextureObjectRegistry * GetTextureObjectRegistry() const {
|
||||
return _textureObjectRegistry.get();
|
||||
}
|
||||
|
||||
/// Get sampler object registry.
|
||||
///
|
||||
HdSt_SamplerObjectRegistry * GetSamplerObjectRegistry() const {
|
||||
return _samplerObjectRegistry.get();
|
||||
}
|
||||
|
||||
/// Commit textures. Return shader code instances that
|
||||
/// depend on the (re-)loaded textures so that they can add
|
||||
/// buffer sources based on the texture meta-data.
|
||||
///
|
||||
/// Also garbage collect textures and samplers if necessary.
|
||||
///
|
||||
HDST_API
|
||||
std::set<HdStShaderCodeSharedPtr> Commit();
|
||||
|
||||
/// Sets how much memory a single texture can consume in bytes by
|
||||
/// texture type.
|
||||
///
|
||||
/// Only has an effect if non-zero and only applies to textures if
|
||||
/// no texture handle referencing the texture has a memory
|
||||
/// request.
|
||||
///
|
||||
HDST_API
|
||||
void SetMemoryRequestForTextureType(HdTextureType textureType, size_t memoryRequest);
|
||||
|
||||
HDST_API
|
||||
size_t GetNumberOfTextureHandles() const;
|
||||
|
||||
private:
|
||||
void _ComputeMemoryRequest(HdStTextureObjectSharedPtr const &);
|
||||
void _ComputeMemoryRequests(const std::set<HdStTextureObjectSharedPtr> &);
|
||||
void _ComputeAllMemoryRequests();
|
||||
|
||||
bool _GarbageCollectHandlesAndComputeTargetMemory();
|
||||
void _GarbageCollectAndComputeTargetMemory();
|
||||
std::set<HdStShaderCodeSharedPtr> _Commit();
|
||||
|
||||
class _TextureToHandlesMap;
|
||||
|
||||
// Maps texture type to memory a single texture of that type can consume
|
||||
// (in bytes).
|
||||
// Will be taken into account when computing the maximum of all the
|
||||
// memory requests of the texture handles.
|
||||
std::map<HdTextureType, size_t> _textureTypeToMemoryRequest;
|
||||
// Has _textureTypeToMemoryRequest changed since the last commit.
|
||||
bool _textureTypeToMemoryRequestChanged;
|
||||
|
||||
// Handles that are new or for which the underlying texture has
|
||||
// changed: samplers might need to be (re-)allocated and the
|
||||
// corresponding shader code might need to update the shader bar.
|
||||
tbb::concurrent_vector<HdStTextureHandlePtr> _dirtyHandles;
|
||||
|
||||
// Textures whose set of associated handles and target memory
|
||||
// might have changed.
|
||||
tbb::concurrent_vector<HdStTextureObjectPtr> _dirtyTextures;
|
||||
|
||||
// Shaders that dropped a texture handle also need to be notified
|
||||
// (for example because they re-allocated the shader bar after dropping
|
||||
// the texture).
|
||||
tbb::concurrent_vector<HdStShaderCodePtr> _dirtyShaders;
|
||||
|
||||
std::unique_ptr<class HdSt_SamplerObjectRegistry> _samplerObjectRegistry;
|
||||
std::unique_ptr<class HdSt_TextureObjectRegistry> _textureObjectRegistry;
|
||||
std::unique_ptr<_TextureToHandlesMap> _textureToHandlesMap;
|
||||
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,101 @@
|
||||
//
|
||||
// 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_ST_TEXTURE_IDENTIFIER_H
|
||||
#define PXR_IMAGING_HD_ST_TEXTURE_IDENTIFIER_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
|
||||
#include "pxr/base/tf/token.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdStSubtextureIdentifier;
|
||||
|
||||
///
|
||||
/// \class HdStTextureIdentifier
|
||||
///
|
||||
/// Class to identify a texture file or a texture within the texture file
|
||||
/// (e.g., a frame in a movie).
|
||||
///
|
||||
/// The class has value semantics and uses HdStSubtextureIdentifier in a
|
||||
/// polymorphic way.
|
||||
///
|
||||
class HdStTextureIdentifier final
|
||||
{
|
||||
public:
|
||||
using ID = size_t;
|
||||
|
||||
HdStTextureIdentifier();
|
||||
|
||||
/// C'tor for files that can contain only one texture.
|
||||
///
|
||||
explicit HdStTextureIdentifier(const TfToken &filePath);
|
||||
|
||||
/// C'tor for files that can contain more than one texture (e.g.,
|
||||
/// frames in a movie, grids in a VDB file).
|
||||
///
|
||||
HdStTextureIdentifier(
|
||||
const TfToken &filePath,
|
||||
std::unique_ptr<const HdStSubtextureIdentifier> &&subtextureId);
|
||||
|
||||
HdStTextureIdentifier(const HdStTextureIdentifier &textureId);
|
||||
|
||||
HdStTextureIdentifier &operator=(HdStTextureIdentifier &&textureId);
|
||||
|
||||
HdStTextureIdentifier &operator=(const HdStTextureIdentifier &textureId);
|
||||
|
||||
~HdStTextureIdentifier();
|
||||
|
||||
/// Get file path of texture file.
|
||||
///
|
||||
const TfToken &GetFilePath() const {
|
||||
return _filePath;
|
||||
}
|
||||
|
||||
/// Get additional information identifying a texture in a file that
|
||||
/// can contain more than one texture (e.g., a frame in a movie or
|
||||
/// a grid in a VDB file).
|
||||
///
|
||||
/// nullptr for files (e.g., png) that can contain only one texture.
|
||||
///
|
||||
const HdStSubtextureIdentifier * GetSubtextureIdentifier() const {
|
||||
return _subtextureId.get();
|
||||
}
|
||||
|
||||
bool operator==(const HdStTextureIdentifier &other) const;
|
||||
bool operator!=(const HdStTextureIdentifier &other) const;
|
||||
|
||||
private:
|
||||
TfToken _filePath;
|
||||
std::unique_ptr<const HdStSubtextureIdentifier> _subtextureId;
|
||||
};
|
||||
|
||||
size_t hash_value(const HdStTextureIdentifier &);
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,306 @@
|
||||
//
|
||||
// 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_ST_TEXTURE_OBJECT_H
|
||||
#define PXR_IMAGING_HD_ST_TEXTURE_OBJECT_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
|
||||
#include "pxr/imaging/hdSt/textureIdentifier.h"
|
||||
#include "pxr/imaging/hd/enums.h"
|
||||
#include "pxr/imaging/hd/types.h"
|
||||
|
||||
#include "pxr/imaging/hgi/handle.h"
|
||||
#include "pxr/imaging/hio/image.h"
|
||||
|
||||
#include "pxr/base/gf/bbox3d.h"
|
||||
#include "pxr/base/tf/declarePtrs.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class Hgi;
|
||||
using HgiTextureHandle = HgiHandle<class HgiTexture>;
|
||||
class HdSt_TextureObjectRegistry;
|
||||
struct HgiTextureDesc;
|
||||
class HdStTextureCpuData;
|
||||
class HdStResourceRegistry;
|
||||
|
||||
using HdStTextureObjectSharedPtr = std::shared_ptr<class HdStTextureObject>;
|
||||
|
||||
/// \class HdStTextureObject
|
||||
///
|
||||
/// Base class for a texture object. The actual GPU resources will be
|
||||
/// allocated during the commit phase.
|
||||
///
|
||||
class HdStTextureObject :
|
||||
public std::enable_shared_from_this<HdStTextureObject>
|
||||
{
|
||||
public:
|
||||
/// Get texture identifier
|
||||
///
|
||||
const HdStTextureIdentifier &
|
||||
GetTextureIdentifier() const { return _textureId; }
|
||||
|
||||
/// Get the target memory for the texture.
|
||||
///
|
||||
size_t GetTargetMemory() const { return _targetMemory; }
|
||||
|
||||
/// Set the target memory (in bytes).
|
||||
///
|
||||
/// When uploading the texture to the GPU, it will be downsampled
|
||||
/// to meet this target memory.
|
||||
///
|
||||
HDST_API
|
||||
void SetTargetMemory(size_t);
|
||||
|
||||
/// Is texture valid? Only correct after commit phase.
|
||||
///
|
||||
/// E.g., no file at given file path. Consulted by clients to
|
||||
/// determine whether to use the fallback value.
|
||||
///
|
||||
HDST_API
|
||||
virtual bool IsValid() const = 0;
|
||||
|
||||
/// Get texture type
|
||||
///
|
||||
HDST_API
|
||||
virtual HdTextureType GetTextureType() const = 0;
|
||||
|
||||
HDST_API
|
||||
virtual ~HdStTextureObject();
|
||||
|
||||
protected:
|
||||
HdStTextureObject(
|
||||
const HdStTextureIdentifier &textureId,
|
||||
HdSt_TextureObjectRegistry * textureObjectRegistry);
|
||||
|
||||
HDST_API
|
||||
HdStResourceRegistry* _GetResourceRegistry() const;
|
||||
|
||||
HDST_API
|
||||
Hgi* _GetHgi() const;
|
||||
|
||||
HDST_API
|
||||
std::string _GetDebugName(const HdStTextureIdentifier &textureId) const;
|
||||
|
||||
HDST_API
|
||||
bool
|
||||
_GetPremultiplyAlpha(const HdStSubtextureIdentifier * const subId) const;
|
||||
|
||||
HDST_API
|
||||
HioImage::SourceColorSpace
|
||||
_GetSourceColorSpace(const HdStSubtextureIdentifier * const subId) const;
|
||||
|
||||
/// Load texture to CPU (thread-safe)
|
||||
///
|
||||
HDST_API
|
||||
virtual void _Load() = 0;
|
||||
|
||||
/// Commit texture to GPU (not thread-safe)
|
||||
///
|
||||
HDST_API
|
||||
virtual void _Commit() = 0;
|
||||
|
||||
/// Add signed number to total texture memory amount maintained by
|
||||
/// registry.
|
||||
///
|
||||
HDST_API
|
||||
void _AdjustTotalTextureMemory(int64_t memDiff);
|
||||
|
||||
/// Compute memory of texture and add to total texture memory
|
||||
/// amount maintained by registry.
|
||||
HDST_API
|
||||
void _AddToTotalTextureMemory(const HgiTextureHandle &texture);
|
||||
|
||||
/// Compute memory of texture and subtract to total texture memory
|
||||
/// amount maintained by registry.
|
||||
HDST_API
|
||||
void _SubtractFromTotalTextureMemory(const HgiTextureHandle &texture);
|
||||
|
||||
private:
|
||||
friend class HdSt_TextureObjectRegistry;
|
||||
|
||||
HdSt_TextureObjectRegistry * const _textureObjectRegistry;
|
||||
const HdStTextureIdentifier _textureId;
|
||||
size_t _targetMemory;
|
||||
};
|
||||
|
||||
/// \class HdStUvTextureObject
|
||||
///
|
||||
/// A base class for uv textures.
|
||||
///
|
||||
class HdStUvTextureObject : public HdStTextureObject
|
||||
{
|
||||
public:
|
||||
~HdStUvTextureObject() override;
|
||||
|
||||
/// Get the handle to the actual GPU resource.
|
||||
///
|
||||
/// Only valid after commit phase.
|
||||
///
|
||||
HgiTextureHandle const &GetTexture() const {
|
||||
return _gpuTexture;
|
||||
}
|
||||
|
||||
/// Opinion about wrapS and wrapT parameters from the texture file.
|
||||
///
|
||||
/// Only valid after commit phase. Can be HdWrapNoOpinion.
|
||||
const std::pair<HdWrap, HdWrap> &GetWrapParameters() const {
|
||||
return _wrapParameters;
|
||||
}
|
||||
|
||||
HDST_API
|
||||
HdTextureType GetTextureType() const override final;
|
||||
|
||||
protected:
|
||||
HdStUvTextureObject(
|
||||
const HdStTextureIdentifier &textureId,
|
||||
HdSt_TextureObjectRegistry * textureObjectRegistry);
|
||||
|
||||
void _SetWrapParameters(
|
||||
const std::pair<HdWrap, HdWrap> &wrapParameters);
|
||||
|
||||
void _SetCpuData(std::unique_ptr<HdStTextureCpuData> &&);
|
||||
HdStTextureCpuData * _GetCpuData() const;
|
||||
|
||||
void _CreateTexture(const HgiTextureDesc &desc);
|
||||
void _GenerateMipmaps();
|
||||
void _DestroyTexture();
|
||||
|
||||
private:
|
||||
std::pair<HdWrap, HdWrap> _wrapParameters;
|
||||
std::unique_ptr<HdStTextureCpuData> _cpuData;
|
||||
HgiTextureHandle _gpuTexture;
|
||||
};
|
||||
|
||||
/// \class HdAssetStUvTextureObject
|
||||
///
|
||||
/// A uv texture loading the asset identified by the texture identifier.
|
||||
///
|
||||
class HdStAssetUvTextureObject final : public HdStUvTextureObject
|
||||
{
|
||||
public:
|
||||
HDST_API
|
||||
HdStAssetUvTextureObject(
|
||||
const HdStTextureIdentifier &textureId,
|
||||
HdSt_TextureObjectRegistry *textureObjectRegistry);
|
||||
|
||||
HDST_API
|
||||
~HdStAssetUvTextureObject() override;
|
||||
|
||||
HDST_API
|
||||
bool IsValid() const override;
|
||||
|
||||
protected:
|
||||
HDST_API
|
||||
void _Load() override;
|
||||
|
||||
HDST_API
|
||||
void _Commit() override;
|
||||
};
|
||||
|
||||
/// \class HdStFieldTextureObject
|
||||
///
|
||||
/// A uvw texture with a bounding box describing how to transform it.
|
||||
///
|
||||
class HdStFieldTextureObject final : public HdStTextureObject
|
||||
{
|
||||
public:
|
||||
HDST_API
|
||||
HdStFieldTextureObject(
|
||||
const HdStTextureIdentifier &textureId,
|
||||
HdSt_TextureObjectRegistry *textureObjectRegistry);
|
||||
|
||||
HDST_API
|
||||
~HdStFieldTextureObject() override;
|
||||
|
||||
/// Get the handle to the actual GPU resource.
|
||||
///
|
||||
/// Only valid after commit phase.
|
||||
///
|
||||
HgiTextureHandle const &GetTexture() const {
|
||||
return _gpuTexture;
|
||||
}
|
||||
|
||||
/// The box the texture fills out.
|
||||
///
|
||||
/// Only valid after the commit phase.
|
||||
///
|
||||
const GfBBox3d &GetBoundingBox() const { return _bbox; }
|
||||
|
||||
/// The sampling transform.
|
||||
///
|
||||
/// Only valid after the commit phase.
|
||||
///
|
||||
const GfMatrix4d &GetSamplingTransform() const {
|
||||
return _samplingTransform;
|
||||
}
|
||||
|
||||
HDST_API
|
||||
bool IsValid() const override;
|
||||
|
||||
HDST_API
|
||||
HdTextureType GetTextureType() const override;
|
||||
|
||||
protected:
|
||||
HDST_API
|
||||
void _Load() override;
|
||||
|
||||
HDST_API
|
||||
void _Commit() override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<HdStTextureCpuData> _cpuData;
|
||||
GfBBox3d _bbox;
|
||||
GfMatrix4d _samplingTransform;
|
||||
HgiTextureHandle _gpuTexture;
|
||||
};
|
||||
|
||||
template<HdTextureType textureType>
|
||||
struct HdSt_TypedTextureObjectHelper;
|
||||
|
||||
/// \class HdStTypedTextureObject
|
||||
///
|
||||
/// A template alias such that, e.g., HdStUvTextureObject can be
|
||||
/// accessed as HdStTypedTextureObject<HdTextureType::Uv>.
|
||||
///
|
||||
template<HdTextureType textureType>
|
||||
using HdStTypedTextureObject =
|
||||
typename HdSt_TypedTextureObjectHelper<textureType>::type;
|
||||
|
||||
template<>
|
||||
struct HdSt_TypedTextureObjectHelper<HdTextureType::Uv> {
|
||||
using type = HdStUvTextureObject;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct HdSt_TypedTextureObjectHelper<HdTextureType::Field> {
|
||||
using type = HdStFieldTextureObject;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,144 @@
|
||||
//
|
||||
// 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_ST_TEXTURE_OBJECT_REGISTRY_H
|
||||
#define PXR_IMAGING_HD_ST_TEXTURE_OBJECT_REGISTRY_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/imaging/hd/enums.h"
|
||||
#include "pxr/imaging/hd/instanceRegistry.h"
|
||||
|
||||
#include <tbb/concurrent_vector.h>
|
||||
#include <vector>
|
||||
#include <atomic>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
using HdStTextureObjectSharedPtr =
|
||||
std::shared_ptr<class HdStTextureObject>;
|
||||
using HdStTextureObjectPtr =
|
||||
std::weak_ptr<class HdStTextureObject>;
|
||||
using HdStTextureObjectPtrVector =
|
||||
std::vector<HdStTextureObjectPtr>;
|
||||
class HdStResourceRegistry;
|
||||
class HdStTextureIdentifier;
|
||||
|
||||
|
||||
/// \class HdSt_TextureObjectRegistry
|
||||
///
|
||||
/// A central registry for texture GPU resources.
|
||||
///
|
||||
class HdSt_TextureObjectRegistry final
|
||||
{
|
||||
public:
|
||||
explicit HdSt_TextureObjectRegistry(HdStResourceRegistry * registry);
|
||||
~HdSt_TextureObjectRegistry();
|
||||
|
||||
/// Allocate texture.
|
||||
///
|
||||
/// This just creates the HdStTextureObject, the actual GPU
|
||||
/// resources won't be allocated until the Commit phase.
|
||||
///
|
||||
HDST_API
|
||||
HdStTextureObjectSharedPtr AllocateTextureObject(
|
||||
const HdStTextureIdentifier &textureId,
|
||||
HdTextureType textureType);
|
||||
|
||||
/// Create GPU texture objects, load textures from files and
|
||||
/// upload to GPU.
|
||||
///
|
||||
HDST_API
|
||||
std::set<HdStTextureObjectSharedPtr> Commit();
|
||||
|
||||
/// Free GPU resources of textures not used by any client.
|
||||
///
|
||||
HDST_API
|
||||
void GarbageCollect();
|
||||
|
||||
/// Mark texture file path as dirty. All textures whose identifier
|
||||
/// contains the file path will be reloaded during the next Commit.
|
||||
///
|
||||
HDST_API
|
||||
void MarkTextureFilePathDirty(const TfToken &filePath);
|
||||
|
||||
/// Mark that the GPU resource for a texture needs to be
|
||||
/// (re-)loaded, e.g., because the memory request changed.
|
||||
///
|
||||
HDST_API
|
||||
void MarkTextureObjectDirty(
|
||||
HdStTextureObjectPtr const &textureObject);
|
||||
|
||||
/// Get resource registry
|
||||
///
|
||||
HDST_API
|
||||
HdStResourceRegistry * GetResourceRegistry() const {
|
||||
return _resourceRegistry;
|
||||
}
|
||||
|
||||
/// The total GPU memory consumed by all textures managed by this registry.
|
||||
///
|
||||
int64_t GetTotalTextureMemory() const {
|
||||
return _totalTextureMemory;
|
||||
}
|
||||
|
||||
/// Add signed number to total texture memory amount. Called from
|
||||
/// texture objects when (de-)allocated GPU resources.
|
||||
///
|
||||
HDST_API
|
||||
void AdjustTotalTextureMemory(int64_t memDiff);
|
||||
|
||||
/// The number of texture objects.
|
||||
size_t GetNumberOfTextureObjects() const {
|
||||
return _textureObjectRegistry.size();
|
||||
}
|
||||
|
||||
private:
|
||||
HdStTextureObjectSharedPtr _MakeTextureObject(
|
||||
const HdStTextureIdentifier &textureId,
|
||||
HdTextureType textureType);
|
||||
|
||||
std::atomic<int64_t> _totalTextureMemory;
|
||||
|
||||
// Registry for texture and sampler objects.
|
||||
HdInstanceRegistry<HdStTextureObjectSharedPtr>
|
||||
_textureObjectRegistry;
|
||||
|
||||
// Map file paths to texture objects for quick invalidation
|
||||
// by file path.
|
||||
std::unordered_map<TfToken, HdStTextureObjectPtrVector,
|
||||
TfToken::HashFunctor>
|
||||
_filePathToTextureObjects;
|
||||
|
||||
// File paths for which GPU resources need to be (re-)loaded
|
||||
tbb::concurrent_vector<TfToken> _dirtyFilePaths;
|
||||
|
||||
// Texture for which GPU resources need to be (re-)loaded
|
||||
tbb::concurrent_vector<HdStTextureObjectPtr> _dirtyTextures;
|
||||
|
||||
HdStResourceRegistry *_resourceRegistry;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,117 @@
|
||||
//
|
||||
// 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_ST_TEXTURE_UTILS_H
|
||||
#define PXR_IMAGING_HD_ST_TEXTURE_UTILS_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
|
||||
#include "pxr/imaging/hio/types.h"
|
||||
#include "pxr/imaging/hio/image.h"
|
||||
#include "pxr/imaging/hgi/types.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// \class HdStTextureUtils
|
||||
///
|
||||
/// Helpers for loading textures.
|
||||
///
|
||||
class HdStTextureUtils
|
||||
{
|
||||
public:
|
||||
/// Converts given number of texels.
|
||||
///
|
||||
/// Conversion can be in-place if the ends of the source and destination
|
||||
/// buffers align.
|
||||
using ConversionFunction =
|
||||
void(*)(const void * src,
|
||||
size_t numTexels,
|
||||
void * dst);
|
||||
|
||||
/// Get the Hgi format suitable for a given Hio format.
|
||||
///
|
||||
/// Premultiply alpha indicates whether a conversion function
|
||||
/// multiplying RGB with alpha should be created.
|
||||
HDST_API
|
||||
static
|
||||
HgiFormat GetHgiFormat(
|
||||
HioFormat hioFormat,
|
||||
bool premultiplyAlpha);
|
||||
|
||||
/// Returns the conversion function to return a HioFormat
|
||||
/// to the corresponding HgiFormat given by GetHgiFormat.
|
||||
///
|
||||
/// Returns nullptr if no conversion necessary.
|
||||
HDST_API
|
||||
static
|
||||
ConversionFunction GetHioToHgiConversion(
|
||||
HioFormat hioFormat,
|
||||
bool premultiplyAlpha);
|
||||
|
||||
/// Get all mip levels from a file.
|
||||
HDST_API
|
||||
static
|
||||
std::vector<HioImageSharedPtr> GetAllMipImages(
|
||||
const std::string &filePath,
|
||||
HioImage::SourceColorSpace sourceColorSpace);
|
||||
|
||||
// Compute dimensions so that all tiles fit into the given target memory.
|
||||
// First by traversing the given images and then by computing a mip chain
|
||||
// starting with the lowest resolution image.
|
||||
// Optionally, can also give the index of the image in mips that was used
|
||||
// to compute the dimensions.
|
||||
HDST_API
|
||||
static
|
||||
GfVec3i
|
||||
ComputeDimensionsFromTargetMemory(
|
||||
const std::vector<HioImageSharedPtr> &mips,
|
||||
HgiFormat targetFormat,
|
||||
size_t tileCount,
|
||||
size_t targetMemory,
|
||||
size_t * mipIndex = nullptr);
|
||||
|
||||
// Read given HioImage and convert it to corresponding Hgi format.
|
||||
// Returns false if reading the HioImage failed.
|
||||
//
|
||||
// bufferStart is assumed to point at the beginning of a mip chain
|
||||
// with mipInfo describing what mip level of the mip chain to be
|
||||
// filled. layer gives the layer number if the mip chain is for an
|
||||
// array texture.
|
||||
HDST_API
|
||||
static
|
||||
bool
|
||||
ReadAndConvertImage(
|
||||
HioImageSharedPtr const &image,
|
||||
bool flipped,
|
||||
bool premultiplyAlpha,
|
||||
const HgiMipInfo &mipInfo,
|
||||
size_t layer,
|
||||
void * bufferStart);
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,150 @@
|
||||
//
|
||||
// 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_ST_TOKENS_H
|
||||
#define PXR_IMAGING_HD_ST_TOKENS_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/base/tf/staticTokens.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
#define HDST_GLSL_PROGRAM_TOKENS \
|
||||
(smoothNormalsFloatToFloat) \
|
||||
(smoothNormalsFloatToPacked) \
|
||||
(smoothNormalsDoubleToDouble) \
|
||||
(smoothNormalsDoubleToPacked) \
|
||||
(flatNormalsTriFloatToFloat) \
|
||||
(flatNormalsTriFloatToPacked) \
|
||||
(flatNormalsTriDoubleToDouble) \
|
||||
(flatNormalsTriDoubleToPacked) \
|
||||
(flatNormalsQuadFloatToFloat) \
|
||||
(flatNormalsQuadFloatToPacked) \
|
||||
(flatNormalsQuadDoubleToDouble) \
|
||||
(flatNormalsQuadDoubleToPacked) \
|
||||
(quadrangulateFloat) \
|
||||
(quadrangulateDouble)
|
||||
|
||||
#define HDST_TOKENS \
|
||||
(constantLighting) \
|
||||
(packedSmoothNormals) \
|
||||
(smoothNormals) \
|
||||
(packedFlatNormals) \
|
||||
(flatNormals) \
|
||||
(scale) \
|
||||
(bias) \
|
||||
(rotation) \
|
||||
(translation) \
|
||||
(sRGB) \
|
||||
(raw) \
|
||||
((_double, "double")) \
|
||||
((_float, "float")) \
|
||||
((_int, "int")) \
|
||||
((colorSpaceAuto, "auto")) \
|
||||
(fvarIndices) \
|
||||
(fvarPatchParam) \
|
||||
(coarseFaceIndex) \
|
||||
(processedFaceCounts) \
|
||||
(processedFaceIndices) \
|
||||
(geomSubsetFaceIndices)
|
||||
|
||||
#define HDST_TEXTURE_TOKENS \
|
||||
(wrapS) \
|
||||
(wrapT) \
|
||||
(wrapR) \
|
||||
(black) \
|
||||
(clamp) \
|
||||
(mirror) \
|
||||
(repeat) \
|
||||
(useMetadata) \
|
||||
(minFilter) \
|
||||
(magFilter) \
|
||||
(linear) \
|
||||
(nearest) \
|
||||
(linearMipmapLinear) \
|
||||
(linearMipmapNearest) \
|
||||
(nearestMipmapLinear) \
|
||||
(nearestMipmapNearest)
|
||||
|
||||
#define HDST_RENDER_BUFFER_TOKENS \
|
||||
((stormMsaaSampleCount, "storm:msaaSampleCount"))
|
||||
|
||||
#define HDST_RENDER_SETTINGS_TOKENS \
|
||||
(enableTinyPrimCulling) \
|
||||
(volumeRaymarchingStepSize) \
|
||||
(volumeRaymarchingStepSizeLighting) \
|
||||
(volumeMaxTextureMemoryPerField)
|
||||
|
||||
// Material tags help bucket prims into different queues for draw submission.
|
||||
// The tags supported by Storm are:
|
||||
// defaultMaterialTag : opaque geometry
|
||||
// masked : opaque geometry that uses cutout masks (e.g., foliage)
|
||||
// translucentToSelection: opaque geometry that allows occluded selection
|
||||
// to show through
|
||||
// additive : transparent geometry (cheap OIT solution w/o sorting)
|
||||
// translucent: transparent geometry (OIT solution w/ sorted fragment lists)
|
||||
// volume : transparent geoometry (raymarched)
|
||||
#define HDST_MATERIAL_TAG_TOKENS \
|
||||
(defaultMaterialTag) \
|
||||
(masked) \
|
||||
(translucentToSelection) \
|
||||
(additive) \
|
||||
(translucent) \
|
||||
(volume)
|
||||
|
||||
#define HDST_SDR_METADATA_TOKENS \
|
||||
(swizzle)
|
||||
|
||||
#define HDST_PERF_TOKENS \
|
||||
(copyBufferGpuToGpu) \
|
||||
(copyBufferCpuToGpu) \
|
||||
(drawItemsCacheHit) \
|
||||
(drawItemsCacheMiss) \
|
||||
(drawItemsCacheStale) \
|
||||
(drawItemsFetched)
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdStGLSLProgramTokens, HDST_API,
|
||||
HDST_GLSL_PROGRAM_TOKENS);
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdStTokens, HDST_API, HDST_TOKENS);
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdStTextureTokens, HDST_API, HDST_TEXTURE_TOKENS);
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdStRenderBufferTokens, HDST_API,
|
||||
HDST_RENDER_BUFFER_TOKENS);
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdStRenderSettingsTokens, HDST_API,
|
||||
HDST_RENDER_SETTINGS_TOKENS);
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdStMaterialTagTokens, HDST_API,
|
||||
HDST_MATERIAL_TAG_TOKENS);
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdStSdrMetadataTokens, HDST_API,
|
||||
HDST_SDR_METADATA_TOKENS);
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(HdStPerfTokens, HDST_API, HDST_PERF_TOKENS);
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif //PXR_IMAGING_HD_ST_TOKENS_H
|
||||
@@ -0,0 +1,112 @@
|
||||
//
|
||||
// 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_ST_UDIM_TEXTURE_OBJECT_H
|
||||
#define PXR_IMAGING_HD_ST_UDIM_TEXTURE_OBJECT_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
|
||||
#include "pxr/imaging/hdSt/textureObject.h"
|
||||
|
||||
#include "pxr/imaging/hgi/handle.h"
|
||||
|
||||
#include "pxr/base/gf/vec3i.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
enum HgiFormat : int;
|
||||
using HgiTextureHandle = HgiHandle<class HgiTexture>;
|
||||
|
||||
/// Returns true if the file given by \p imageFilePath represents a udim file,
|
||||
/// and false otherwise.
|
||||
///
|
||||
/// This function simply checks the existence of the <udim> tag in the
|
||||
/// file name and does not otherwise guarantee that
|
||||
/// the file is in any way valid for reading.
|
||||
///
|
||||
HDST_API bool HdStIsSupportedUdimTexture(std::string const& imageFilePath);
|
||||
|
||||
/// \class HdStUdimTextureObject
|
||||
///
|
||||
/// A UDIM texture.
|
||||
///
|
||||
class HdStUdimTextureObject final : public HdStTextureObject
|
||||
{
|
||||
public:
|
||||
HDST_API
|
||||
HdStUdimTextureObject(
|
||||
const HdStTextureIdentifier &textureId,
|
||||
HdSt_TextureObjectRegistry *textureObjectRegistry);
|
||||
|
||||
HDST_API
|
||||
~HdStUdimTextureObject() override;
|
||||
|
||||
/// Get the gpu texture name for the texels
|
||||
///
|
||||
/// Only valid after commit phase.
|
||||
///
|
||||
HgiTextureHandle const& GetTexelTexture() const { return _texelTexture; }
|
||||
|
||||
/// Get the gpu texture name for the layout
|
||||
///
|
||||
/// Only valid after commit phase.
|
||||
///
|
||||
HgiTextureHandle const& GetLayoutTexture() const { return _layoutTexture; }
|
||||
|
||||
HDST_API
|
||||
bool IsValid() const override;
|
||||
|
||||
HDST_API
|
||||
HdTextureType GetTextureType() const override;
|
||||
|
||||
protected:
|
||||
HDST_API
|
||||
void _Load() override;
|
||||
|
||||
HDST_API
|
||||
void _Commit() override;
|
||||
|
||||
private:
|
||||
std::vector<uint8_t> _textureData;
|
||||
std::vector<float> _layoutData;
|
||||
|
||||
GfVec3i _dimensions;
|
||||
size_t _tileCount;
|
||||
size_t _mipCount;
|
||||
HgiFormat _hgiFormat;
|
||||
|
||||
HgiTextureHandle _texelTexture;
|
||||
HgiTextureHandle _layoutTexture;
|
||||
|
||||
void _DestroyTextures();
|
||||
};
|
||||
|
||||
template<>
|
||||
struct HdSt_TypedTextureObjectHelper<HdTextureType::Udim> {
|
||||
using type = HdStUdimTextureObject;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,115 @@
|
||||
//
|
||||
// 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_ST_UNIT_TEST_GLDRAWING_H
|
||||
#define PXR_IMAGING_HD_ST_UNIT_TEST_GLDRAWING_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/base/gf/frustum.h"
|
||||
#include "pxr/base/gf/matrix4d.h"
|
||||
#include "pxr/base/gf/vec3f.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
class HdSt_UnitTestWindow;
|
||||
|
||||
/// \class HdSt_UnitTestGLDrawing
|
||||
///
|
||||
/// A helper class for unit tests which need to perform GL drawing.
|
||||
///
|
||||
class HdSt_UnitTestGLDrawing {
|
||||
public:
|
||||
HDST_API
|
||||
HdSt_UnitTestGLDrawing();
|
||||
HDST_API
|
||||
virtual ~HdSt_UnitTestGLDrawing();
|
||||
|
||||
HDST_API
|
||||
int GetWidth() const;
|
||||
HDST_API
|
||||
int GetHeight() const;
|
||||
HDST_API
|
||||
void RunTest(int argc, char *argv[]);
|
||||
HDST_API
|
||||
void RunOffscreenTest();
|
||||
|
||||
virtual void InitTest() = 0;
|
||||
HDST_API virtual void UninitTest();
|
||||
virtual void DrawTest() = 0; // interactive mode
|
||||
virtual void OffscreenTest() = 0; // offscreen mode (automated test)
|
||||
|
||||
HDST_API
|
||||
virtual void MousePress(int button, int x, int y, int modKeys);
|
||||
HDST_API
|
||||
virtual void MouseRelease(int button, int x, int y, int modKeys);
|
||||
HDST_API
|
||||
virtual void MouseMove(int x, int y, int modKeys);
|
||||
HDST_API
|
||||
virtual void KeyRelease(int key);
|
||||
|
||||
HDST_API
|
||||
virtual void Idle();
|
||||
|
||||
HDST_API
|
||||
bool WriteToFile(std::string const & attachment,
|
||||
std::string const & filename) const;
|
||||
|
||||
protected:
|
||||
HDST_API
|
||||
virtual void ParseArgs(int argc, char *argv[]);
|
||||
|
||||
void SetCameraRotate(float rx, float ry) {
|
||||
_rotate[0] = rx; _rotate[1] = ry;
|
||||
}
|
||||
void SetCameraTranslate(GfVec3f t) {
|
||||
_translate = t;
|
||||
}
|
||||
GfVec3f GetCameraTranslate() const {
|
||||
return _translate;
|
||||
}
|
||||
HDST_API
|
||||
GfMatrix4d GetViewMatrix() const;
|
||||
HDST_API
|
||||
GfMatrix4d GetProjectionMatrix() const;
|
||||
HDST_API
|
||||
GfFrustum GetFrustum() const;
|
||||
|
||||
GfVec2i GetMousePos() const { return GfVec2i(_mousePos[0], _mousePos[1]); }
|
||||
|
||||
private:
|
||||
HdSt_UnitTestWindow *_widget;
|
||||
float _rotate[2];
|
||||
GfVec3f _translate;
|
||||
|
||||
int _mousePos[2];
|
||||
bool _mouseButton[3];
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_ST_UNIT_TEST_GLDRAWING_H
|
||||
@@ -0,0 +1,339 @@
|
||||
//
|
||||
// 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_ST_VBO_MEMORY_MANAGER_H
|
||||
#define PXR_IMAGING_HD_ST_VBO_MEMORY_MANAGER_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/bufferArray.h"
|
||||
#include "pxr/imaging/hdSt/bufferArrayRange.h"
|
||||
#include "pxr/imaging/hd/bufferSpec.h"
|
||||
#include "pxr/imaging/hd/bufferSource.h"
|
||||
#include "pxr/imaging/hd/strategyBase.h"
|
||||
|
||||
#include "pxr/base/tf/mallocTag.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
|
||||
#include <list>
|
||||
#include <memory>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdStResourceRegistry;
|
||||
|
||||
/// \class HdStVBOMemoryManager
|
||||
///
|
||||
/// VBO memory manager.
|
||||
///
|
||||
class HdStVBOMemoryManager : public HdAggregationStrategy
|
||||
{
|
||||
public:
|
||||
HdStVBOMemoryManager(HdStResourceRegistry *resourceRegistry)
|
||||
: HdAggregationStrategy()
|
||||
, _resourceRegistry(resourceRegistry) {}
|
||||
|
||||
/// Factory for creating HdBufferArray managed by
|
||||
/// HdStVBOMemoryManager aggregation.
|
||||
HDST_API
|
||||
virtual HdBufferArraySharedPtr CreateBufferArray(
|
||||
TfToken const &role,
|
||||
HdBufferSpecVector const &bufferSpecs,
|
||||
HdBufferArrayUsageHint usageHint);
|
||||
|
||||
/// Factory for creating HdBufferArrayRange managed by
|
||||
/// HdStVBOMemoryManager aggregation.
|
||||
HDST_API
|
||||
virtual HdBufferArrayRangeSharedPtr CreateBufferArrayRange();
|
||||
|
||||
/// Returns id for given bufferSpecs to be used for aggregation
|
||||
HDST_API
|
||||
virtual AggregationId ComputeAggregationId(
|
||||
HdBufferSpecVector const &bufferSpecs,
|
||||
HdBufferArrayUsageHint usageHint) const;
|
||||
|
||||
/// Returns the buffer specs from a given buffer array
|
||||
virtual HdBufferSpecVector GetBufferSpecs(
|
||||
HdBufferArraySharedPtr const &bufferArray) const;
|
||||
|
||||
/// Returns the size of the GPU memory used by the passed buffer array
|
||||
virtual size_t GetResourceAllocation(
|
||||
HdBufferArraySharedPtr const &bufferArray,
|
||||
VtDictionary &result) const;
|
||||
|
||||
protected:
|
||||
class _StripedBufferArray;
|
||||
|
||||
/// specialized buffer array range
|
||||
class _StripedBufferArrayRange : public HdStBufferArrayRange
|
||||
{
|
||||
public:
|
||||
/// Constructor.
|
||||
_StripedBufferArrayRange(HdStResourceRegistry* resourceRegistry)
|
||||
: HdStBufferArrayRange(resourceRegistry),
|
||||
_stripedBufferArray(nullptr),
|
||||
_elementOffset(0),
|
||||
_numElements(0),
|
||||
_capacity(0)
|
||||
{
|
||||
}
|
||||
|
||||
/// Destructor.
|
||||
HDST_API
|
||||
~_StripedBufferArrayRange() override;
|
||||
|
||||
/// Returns true if this range is valid
|
||||
bool IsValid() const override {
|
||||
return (bool)_stripedBufferArray;
|
||||
}
|
||||
|
||||
/// Returns true is the range has been assigned to a buffer
|
||||
HDST_API
|
||||
bool IsAssigned() const override;
|
||||
|
||||
/// Returns true if this bar is marked as immutable.
|
||||
bool IsImmutable() const override;
|
||||
|
||||
/// Returns true if this needs a staging buffer for CPU to GPU copies.
|
||||
bool RequiresStaging() const override;
|
||||
|
||||
/// Resize memory area for this range. Returns true if it causes container
|
||||
/// buffer reallocation.
|
||||
HDST_API
|
||||
bool Resize(int numElements) override;
|
||||
|
||||
/// Copy source data into buffer
|
||||
HDST_API
|
||||
void CopyData(HdBufferSourceSharedPtr const &bufferSource) override;
|
||||
|
||||
/// Read back the buffer content
|
||||
HDST_API
|
||||
VtValue ReadData(TfToken const &name) const override;
|
||||
|
||||
/// Returns the relative element offset in aggregated buffer
|
||||
int GetElementOffset() const override {
|
||||
return _elementOffset;
|
||||
}
|
||||
|
||||
/// Returns the byte offset at which this range begins in the underlying
|
||||
/// buffer array for the given resource.
|
||||
int GetByteOffset(TfToken const& resourceName) const override;
|
||||
|
||||
/// Returns the number of elements
|
||||
size_t GetNumElements() const override {
|
||||
return _numElements;
|
||||
}
|
||||
|
||||
/// Returns the version of the buffer array.
|
||||
size_t GetVersion() const override {
|
||||
return _stripedBufferArray->GetVersion();
|
||||
}
|
||||
|
||||
/// Increment the version of the buffer array.
|
||||
void IncrementVersion() override {
|
||||
_stripedBufferArray->IncrementVersion();
|
||||
}
|
||||
|
||||
/// Returns the max number of elements
|
||||
HDST_API
|
||||
size_t GetMaxNumElements() const override;
|
||||
|
||||
/// Returns the usage hint from the underlying buffer array
|
||||
HDST_API
|
||||
HdBufferArrayUsageHint GetUsageHint() const override;
|
||||
|
||||
/// Returns the GPU resource. If the buffer array contains more than one
|
||||
/// resource, this method raises a coding error.
|
||||
HDST_API
|
||||
HdStBufferResourceSharedPtr GetResource() const override;
|
||||
|
||||
/// Returns the named GPU resource.
|
||||
HDST_API
|
||||
HdStBufferResourceSharedPtr GetResource(TfToken const& name) override;
|
||||
|
||||
/// Returns the list of all named GPU resources for this bufferArrayRange.
|
||||
HDST_API
|
||||
HdStBufferResourceNamedList const& GetResources() const override;
|
||||
|
||||
/// Sets the buffer array associated with this buffer;
|
||||
HDST_API
|
||||
void SetBufferArray(HdBufferArray *bufferArray) override;
|
||||
|
||||
/// Debug dump
|
||||
HDST_API
|
||||
void DebugDump(std::ostream &out) const override;
|
||||
|
||||
/// Set the relative offset for this range.
|
||||
void SetElementOffset(int offset) {
|
||||
_elementOffset = offset;
|
||||
}
|
||||
|
||||
/// Set the number of elements for this range.
|
||||
void SetNumElements(int numElements) {
|
||||
_numElements = numElements;
|
||||
}
|
||||
|
||||
/// Returns the capacity of allocated area
|
||||
int GetCapacity() const {
|
||||
return _capacity;
|
||||
}
|
||||
|
||||
/// Set the capacity of allocated area for this range.
|
||||
void SetCapacity(int capacity) {
|
||||
_capacity = capacity;
|
||||
}
|
||||
|
||||
/// Make this range invalid
|
||||
void Invalidate() {
|
||||
_stripedBufferArray = NULL;
|
||||
}
|
||||
|
||||
protected:
|
||||
/// Returns the aggregation container
|
||||
HDST_API
|
||||
const void *_GetAggregation() const override;
|
||||
|
||||
private:
|
||||
// Returns the byte offset at which the BAR begins for the resource.
|
||||
size_t _GetByteOffset(HdStBufferResourceSharedPtr const& resource)
|
||||
const;
|
||||
|
||||
// holding a weak reference to container.
|
||||
// this pointer becomes null when the StripedBufferArray gets destructed,
|
||||
// in case if any drawItem still holds this bufferRange.
|
||||
_StripedBufferArray *_stripedBufferArray;
|
||||
int _elementOffset;
|
||||
size_t _numElements;
|
||||
int _capacity;
|
||||
};
|
||||
|
||||
using _StripedBufferArraySharedPtr =
|
||||
std::shared_ptr<_StripedBufferArray>;
|
||||
using _StripedBufferArrayRangeSharedPtr =
|
||||
std::shared_ptr<_StripedBufferArrayRange>;
|
||||
using _StripedBufferArrayRangePtr =
|
||||
std::weak_ptr<_StripedBufferArrayRange>;
|
||||
|
||||
/// striped buffer array
|
||||
class _StripedBufferArray : public HdBufferArray
|
||||
{
|
||||
public:
|
||||
/// Constructor.
|
||||
HDST_API
|
||||
_StripedBufferArray(HdStResourceRegistry* resourceRegistry,
|
||||
TfToken const &role,
|
||||
HdBufferSpecVector const &bufferSpecs,
|
||||
HdBufferArrayUsageHint usageHint);
|
||||
|
||||
/// Destructor. It invalidates _rangeList
|
||||
HDST_API
|
||||
~_StripedBufferArray() override;
|
||||
|
||||
/// perform compaction if necessary. If it becomes empty, release all
|
||||
/// resources and returns true
|
||||
HDST_API
|
||||
bool GarbageCollect() override;
|
||||
|
||||
/// Debug output
|
||||
HDST_API
|
||||
void DebugDump(std::ostream &out) const override;
|
||||
|
||||
/// Performs reallocation.
|
||||
/// GLX context has to be set when calling this function.
|
||||
HDST_API
|
||||
void Reallocate(
|
||||
std::vector<HdBufferArrayRangeSharedPtr> const &ranges,
|
||||
HdBufferArraySharedPtr const &curRangeOwner) override;
|
||||
|
||||
/// Returns the maximum number of elements capacity.
|
||||
HDST_API
|
||||
size_t GetMaxNumElements() const override;
|
||||
|
||||
/// Mark to perform reallocation on Reallocate()
|
||||
void SetNeedsReallocation() {
|
||||
_needsReallocation = true;
|
||||
}
|
||||
|
||||
/// Mark to perform compaction on GarbageCollect()
|
||||
void SetNeedsCompaction() {
|
||||
_needsCompaction = true;
|
||||
}
|
||||
|
||||
/// TODO: We need to distinguish between the primvar types here, we should
|
||||
/// tag each HdBufferSource and HdBufferResource with Constant, Uniform,
|
||||
/// Varying, Vertex, or FaceVarying and provide accessors for the specific
|
||||
/// buffer types.
|
||||
|
||||
/// Returns the GPU resource. If the buffer array contains more than one
|
||||
/// resource, this method raises a coding error.
|
||||
HDST_API
|
||||
HdStBufferResourceSharedPtr GetResource() const;
|
||||
|
||||
/// Returns the named GPU resource. This method returns the first found
|
||||
/// resource. In HD_SAFE_MODE it checks all underlying GL buffers
|
||||
/// in _resourceMap and raises a coding error if there are more than
|
||||
/// one GL buffers exist.
|
||||
HDST_API
|
||||
HdStBufferResourceSharedPtr GetResource(TfToken const& name);
|
||||
|
||||
/// Returns the list of all named GPU resources for this bufferArray.
|
||||
HdStBufferResourceNamedList const& GetResources() const
|
||||
{return _resourceList;}
|
||||
|
||||
/// Reconstructs the bufferspecs and returns it (for buffer splitting)
|
||||
HDST_API
|
||||
HdBufferSpecVector GetBufferSpecs() const;
|
||||
|
||||
protected:
|
||||
HDST_API
|
||||
void _DeallocateResources();
|
||||
|
||||
/// Adds a new, named GPU resource and returns it.
|
||||
HDST_API
|
||||
HdStBufferResourceSharedPtr _AddResource(TfToken const& name,
|
||||
HdTupleType tupleType,
|
||||
int offset,
|
||||
int stride);
|
||||
|
||||
private:
|
||||
|
||||
HdStResourceRegistry* _resourceRegistry;
|
||||
bool _needsCompaction;
|
||||
int _totalCapacity;
|
||||
size_t _maxBytesPerElement;
|
||||
|
||||
HdStBufferResourceNamedList _resourceList;
|
||||
|
||||
// Helper routine to cast the range shared pointer.
|
||||
_StripedBufferArrayRangeSharedPtr _GetRangeSharedPtr(size_t idx) const {
|
||||
return std::static_pointer_cast<_StripedBufferArrayRange>(GetRange(idx).lock());
|
||||
}
|
||||
};
|
||||
|
||||
HdStResourceRegistry* _resourceRegistry;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_ST_VBO_MEMORY_MANAGER_H
|
||||
@@ -0,0 +1,317 @@
|
||||
//
|
||||
// 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_ST_VBO_SIMPLE_MEMORY_MANAGER_H
|
||||
#define PXR_IMAGING_HD_ST_VBO_SIMPLE_MEMORY_MANAGER_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/imaging/hdSt/bufferArrayRange.h"
|
||||
#include "pxr/imaging/hdSt/resourceRegistry.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/strategyBase.h"
|
||||
#include "pxr/imaging/hd/bufferArray.h"
|
||||
#include "pxr/imaging/hd/bufferSpec.h"
|
||||
#include "pxr/imaging/hd/bufferSource.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdStResourceRegistry;
|
||||
|
||||
/// \class HdStVBOSimpleMemoryManager
|
||||
///
|
||||
/// VBO simple memory manager.
|
||||
///
|
||||
/// This class doesn't perform any aggregation.
|
||||
///
|
||||
class HdStVBOSimpleMemoryManager : public HdAggregationStrategy
|
||||
{
|
||||
public:
|
||||
HdStVBOSimpleMemoryManager(HdStResourceRegistry* resourceRegistry)
|
||||
: _resourceRegistry(resourceRegistry) {}
|
||||
|
||||
/// Factory for creating HdBufferArray managed by
|
||||
/// HdStVBOSimpleMemoryManager.
|
||||
HDST_API
|
||||
virtual HdBufferArraySharedPtr CreateBufferArray(
|
||||
TfToken const &role,
|
||||
HdBufferSpecVector const &bufferSpecs,
|
||||
HdBufferArrayUsageHint usageHint);
|
||||
|
||||
/// Factory for creating HdBufferArrayRange
|
||||
HDST_API
|
||||
virtual HdBufferArrayRangeSharedPtr CreateBufferArrayRange();
|
||||
|
||||
/// Returns id for given bufferSpecs to be used for aggregation
|
||||
HDST_API
|
||||
virtual HdAggregationStrategy::AggregationId ComputeAggregationId(
|
||||
HdBufferSpecVector const &bufferSpecs,
|
||||
HdBufferArrayUsageHint usageHint) const;
|
||||
|
||||
/// Returns the buffer specs from a given buffer array
|
||||
virtual HdBufferSpecVector GetBufferSpecs(
|
||||
HdBufferArraySharedPtr const &bufferArray) const;
|
||||
|
||||
/// Returns the size of the GPU memory used by the passed buffer array
|
||||
virtual size_t GetResourceAllocation(
|
||||
HdBufferArraySharedPtr const &bufferArray,
|
||||
VtDictionary &result) const;
|
||||
|
||||
protected:
|
||||
class _SimpleBufferArray;
|
||||
|
||||
/// \class _SimpleBufferArrayRange
|
||||
///
|
||||
/// Specialized buffer array range for SimpleBufferArray.
|
||||
///
|
||||
class _SimpleBufferArrayRange final : public HdStBufferArrayRange
|
||||
{
|
||||
public:
|
||||
/// Constructor.
|
||||
_SimpleBufferArrayRange(HdStResourceRegistry* resourceRegistry)
|
||||
: HdStBufferArrayRange(resourceRegistry)
|
||||
, _bufferArray(nullptr)
|
||||
, _numElements(0) {
|
||||
}
|
||||
|
||||
/// Returns true if this range is valid
|
||||
bool IsValid() const override {
|
||||
return (bool)_bufferArray;
|
||||
}
|
||||
|
||||
/// Returns true is the range has been assigned to a buffer
|
||||
HDST_API
|
||||
bool IsAssigned() const override;
|
||||
|
||||
/// Returns true if this range is marked as immutable.
|
||||
bool IsImmutable() const override;
|
||||
|
||||
/// Returns true if this needs a staging buffer for CPU to GPU copies.
|
||||
bool RequiresStaging() const override;
|
||||
|
||||
/// Resize memory area for this range. Returns true if it causes container
|
||||
/// buffer reallocation.
|
||||
bool Resize(int numElements) override {
|
||||
_numElements = numElements;
|
||||
return _bufferArray->Resize(numElements);
|
||||
}
|
||||
|
||||
/// Copy source data into buffer
|
||||
HDST_API
|
||||
void CopyData(HdBufferSourceSharedPtr const &bufferSource) override;
|
||||
|
||||
/// Read back the buffer content
|
||||
HDST_API
|
||||
VtValue ReadData(TfToken const &name) const override;
|
||||
|
||||
/// Returns the offset at which this range begins in the underlying
|
||||
/// buffer array in terms of elements.
|
||||
int GetElementOffset() const override {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// Returns the byte offset at which this range begins in the underlying
|
||||
/// buffer array for the given resource.
|
||||
int GetByteOffset(TfToken const& resourceName) const override {
|
||||
TF_UNUSED(resourceName);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// Returns the number of elements allocated
|
||||
size_t GetNumElements() const override {
|
||||
return _numElements;
|
||||
}
|
||||
|
||||
/// Returns the capacity of allocated area for this range
|
||||
int GetCapacity() const {
|
||||
return _bufferArray->GetCapacity();
|
||||
}
|
||||
|
||||
/// Returns the version of the buffer array.
|
||||
size_t GetVersion() const override {
|
||||
return _bufferArray->GetVersion();
|
||||
}
|
||||
|
||||
/// Increment the version of the buffer array.
|
||||
void IncrementVersion() override {
|
||||
_bufferArray->IncrementVersion();
|
||||
}
|
||||
|
||||
/// Returns the max number of elements
|
||||
HDST_API
|
||||
size_t GetMaxNumElements() const override;
|
||||
|
||||
/// Returns the usage hint from the underlying buffer array
|
||||
HDST_API
|
||||
HdBufferArrayUsageHint GetUsageHint() const override;
|
||||
|
||||
/// Returns the GPU resource. If the buffer array contains more than one
|
||||
/// resource, this method raises a coding error.
|
||||
HDST_API
|
||||
HdStBufferResourceSharedPtr GetResource() const override;
|
||||
|
||||
/// Returns the named GPU resource.
|
||||
HDST_API
|
||||
HdStBufferResourceSharedPtr GetResource(TfToken const& name) override;
|
||||
|
||||
/// Returns the list of all named GPU resources for this bufferArrayRange.
|
||||
HDST_API
|
||||
HdStBufferResourceNamedList const& GetResources() const override;
|
||||
|
||||
/// Sets the buffer array associated with this buffer;
|
||||
HDST_API
|
||||
void SetBufferArray(HdBufferArray *bufferArray) override;
|
||||
|
||||
/// Debug dump
|
||||
HDST_API
|
||||
void DebugDump(std::ostream &out) const override;
|
||||
|
||||
/// Make this range invalid
|
||||
void Invalidate() {
|
||||
_bufferArray = NULL;
|
||||
}
|
||||
|
||||
protected:
|
||||
/// Returns the aggregation container
|
||||
HDST_API
|
||||
const void *_GetAggregation() const override;
|
||||
|
||||
/// Adds a new, named GPU resource and returns it.
|
||||
HDST_API
|
||||
HdStBufferResourceSharedPtr _AddResource(TfToken const& name,
|
||||
HdTupleType tupleType,
|
||||
int offset,
|
||||
int stride);
|
||||
|
||||
private:
|
||||
_SimpleBufferArray * _bufferArray;
|
||||
size_t _numElements;
|
||||
};
|
||||
|
||||
using _SimpleBufferArraySharedPtr =
|
||||
std::shared_ptr<_SimpleBufferArray>;
|
||||
using _SimpleBufferArrayRangeSharedPtr =
|
||||
std::shared_ptr<_SimpleBufferArrayRange>;
|
||||
using _SimpleBufferArrayRangePtr =
|
||||
std::weak_ptr<_SimpleBufferArrayRange>;
|
||||
|
||||
/// \class _SimpleBufferArray
|
||||
///
|
||||
/// Simple buffer array (non-aggregated).
|
||||
///
|
||||
class _SimpleBufferArray final : public HdBufferArray
|
||||
{
|
||||
public:
|
||||
/// Constructor.
|
||||
HDST_API
|
||||
_SimpleBufferArray(HdStResourceRegistry* resourceRegistry,
|
||||
TfToken const &role,
|
||||
HdBufferSpecVector const &bufferSpecs,
|
||||
HdBufferArrayUsageHint usageHint);
|
||||
|
||||
/// Destructor. It invalidates _range
|
||||
HDST_API
|
||||
~_SimpleBufferArray() override;
|
||||
|
||||
/// perform compaction if necessary, returns true if it becomes empty.
|
||||
HDST_API
|
||||
bool GarbageCollect() override;
|
||||
|
||||
/// Debug output
|
||||
HDST_API
|
||||
void DebugDump(std::ostream &out) const override;
|
||||
|
||||
/// Set to resize buffers. Actual reallocation happens on Reallocate()
|
||||
HDST_API
|
||||
bool Resize(int numElements);
|
||||
|
||||
/// Performs reallocation.
|
||||
/// GLX context has to be set when calling this function.
|
||||
HDST_API
|
||||
void Reallocate(
|
||||
std::vector<HdBufferArrayRangeSharedPtr> const &ranges,
|
||||
HdBufferArraySharedPtr const &curRangeOwner) override;
|
||||
|
||||
/// Returns the maximum number of elements capacity.
|
||||
HDST_API
|
||||
size_t GetMaxNumElements() const override;
|
||||
|
||||
/// Returns current capacity. It could be different from numElements.
|
||||
int GetCapacity() const {
|
||||
return _capacity;
|
||||
}
|
||||
|
||||
/// TODO: We need to distinguish between the primvar types here, we should
|
||||
/// tag each HdBufferSource and HdBufferResource with Constant, Uniform,
|
||||
/// Varying, Vertex, or FaceVarying and provide accessors for the specific
|
||||
/// buffer types.
|
||||
|
||||
/// Returns the GPU resource. If the buffer array contains more than one
|
||||
/// resource, this method raises a coding error.
|
||||
HDST_API
|
||||
HdStBufferResourceSharedPtr GetResource() const;
|
||||
|
||||
/// Returns the named GPU resource. This method returns the first found
|
||||
/// resource. In HD_SAFE_MODE it checks all underlying GL buffers
|
||||
/// in _resourceMap and raises a coding error if there are more than
|
||||
/// one GL buffers exist.
|
||||
HDST_API
|
||||
HdStBufferResourceSharedPtr GetResource(TfToken const& name);
|
||||
|
||||
/// Returns the list of all named GPU resources for this bufferArray.
|
||||
HdStBufferResourceNamedList const& GetResources() const {return _resourceList;}
|
||||
|
||||
/// Reconstructs the bufferspecs and returns it (for buffer splitting)
|
||||
HDST_API
|
||||
HdBufferSpecVector GetBufferSpecs() const;
|
||||
|
||||
protected:
|
||||
HDST_API
|
||||
void _DeallocateResources();
|
||||
|
||||
/// Adds a new, named GPU resource and returns it.
|
||||
HDST_API
|
||||
HdStBufferResourceSharedPtr _AddResource(TfToken const& name,
|
||||
HdTupleType tupleType,
|
||||
int offset,
|
||||
int stride);
|
||||
private:
|
||||
HdStResourceRegistry* const _resourceRegistry;
|
||||
int _capacity;
|
||||
size_t _maxBytesPerElement;
|
||||
|
||||
HdStBufferResourceNamedList _resourceList;
|
||||
|
||||
_SimpleBufferArrayRangeSharedPtr _GetRangeSharedPtr() const {
|
||||
return GetRangeCount() > 0
|
||||
? std::static_pointer_cast<_SimpleBufferArrayRange>(GetRange(0).lock())
|
||||
: _SimpleBufferArrayRangeSharedPtr();
|
||||
}
|
||||
};
|
||||
|
||||
HdStResourceRegistry* const _resourceRegistry;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_IMAGING_HD_ST_VBO_SIMPLE_MEMORY_MANAGER_H
|
||||
@@ -0,0 +1,89 @@
|
||||
//
|
||||
// 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_ST_VOLUME_H
|
||||
#define PXR_IMAGING_HD_ST_VOLUME_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/imaging/hdSt/api.h"
|
||||
#include "pxr/imaging/hd/version.h"
|
||||
#include "pxr/imaging/hd/volume.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class HdStDrawItem;
|
||||
|
||||
/// Represents a Volume Prim.
|
||||
///
|
||||
class HdStVolume final : public HdVolume {
|
||||
public:
|
||||
HDST_API
|
||||
HdStVolume(SdfPath const& id);
|
||||
HDST_API
|
||||
~HdStVolume() override;
|
||||
|
||||
HDST_API
|
||||
HdDirtyBits GetInitialDirtyBitsMask() const override;
|
||||
|
||||
HDST_API
|
||||
void Sync(HdSceneDelegate* delegate,
|
||||
HdRenderParam* renderParam,
|
||||
HdDirtyBits* dirtyBits,
|
||||
TfToken const &reprToken) override;
|
||||
|
||||
HDST_API
|
||||
void Finalize(HdRenderParam *renderParam) override;
|
||||
|
||||
/// Default step size used for raymarching
|
||||
static const float defaultStepSize;
|
||||
|
||||
/// Default step size used for raymarching for lighting computation
|
||||
static const float defaultStepSizeLighting;
|
||||
|
||||
/// Default memory limit for a field texture (in Mb) if not
|
||||
/// overridden by field prim with textureMemory.
|
||||
static const float defaultMaxTextureMemoryPerField;
|
||||
|
||||
protected:
|
||||
void _InitRepr(TfToken const &reprToken,
|
||||
HdDirtyBits* dirtyBits) override;
|
||||
|
||||
HdDirtyBits _PropagateDirtyBits(HdDirtyBits bits) const override;
|
||||
|
||||
void _UpdateRepr(HdSceneDelegate *sceneDelegate,
|
||||
HdRenderParam *renderParam,
|
||||
TfToken const &reprToken,
|
||||
HdDirtyBits *dirtyBitsState);
|
||||
|
||||
private:
|
||||
void _UpdateDrawItem(HdSceneDelegate *sceneDelegate,
|
||||
HdRenderParam *renderParam,
|
||||
HdStDrawItem *drawItem,
|
||||
HdDirtyBits *dirtyBits);
|
||||
|
||||
HdReprSharedPtr _volumeRepr;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif //PXR_IMAGING_HD_ST_VOLUME_H
|
||||
Reference in new issue
Block a user