diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2019-10-16 15:17:12 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2019-10-30 17:15:55 +0300 |
commit | ca3a96c24365991ed46b5e0109a29a0293a44aaf (patch) | |
tree | 148a40e9bb678d15be4a9c984c3f503ca297902e /intern/opensubdiv/internal/opensubdiv_evaluator_internal.cc | |
parent | d3c87876c9bcfc6d41af196331824f4760bae361 (diff) |
OpenSubdiv: Use more generic access to patch coordinates
Saves another unnecessary temporary data copy during evaluation.
Diffstat (limited to 'intern/opensubdiv/internal/opensubdiv_evaluator_internal.cc')
-rw-r--r-- | intern/opensubdiv/internal/opensubdiv_evaluator_internal.cc | 57 |
1 files changed, 25 insertions, 32 deletions
diff --git a/intern/opensubdiv/internal/opensubdiv_evaluator_internal.cc b/intern/opensubdiv/internal/opensubdiv_evaluator_internal.cc index 0777dab24e6..a88193c30cc 100644 --- a/intern/opensubdiv/internal/opensubdiv_evaluator_internal.cc +++ b/intern/opensubdiv/internal/opensubdiv_evaluator_internal.cc @@ -58,54 +58,47 @@ namespace opensubdiv_capi { namespace { -// Helper class to wrap single of patch coord into a buffer. Used to pass -// coordinates to the CPU evaluator. Other evaluators are not supported. -class SinglePatchCoordBuffer { +// Buffer which implements API required by OpenSubdiv and uses an existing memory as an underlying +// storage. +template<typename T> class RawDataWrapperBuffer { public: - SinglePatchCoordBuffer() + RawDataWrapperBuffer(T *data) : data_(data) { } - explicit SinglePatchCoordBuffer(const PatchCoord &patch_coord) : patch_coord_(patch_coord) + T *BindCpuBuffer() { + return data_; } - PatchCoord *BindCpuBuffer() - { - return &patch_coord_; - } + // TODO(sergey): Support UpdateData(). - int GetNumVertices() + protected: + T *data_; +}; + +template<typename T> class RawDataWrapperVertexBuffer : public RawDataWrapperBuffer<T> { + public: + RawDataWrapperVertexBuffer(T *data, int num_vertices) + : RawDataWrapperBuffer<T>(data), num_vertices_(num_vertices) { - return 1; } - void UpdateData(const PatchCoord &patch_coord) + int GetNumVertices() { - patch_coord_ = patch_coord; + return num_vertices_; } protected: - PatchCoord patch_coord_; + int num_vertices_; }; -// Buffer which implements API required by OpenSubdiv and uses an existing memory as an underlying -// storage. -template<typename T> class RawDataWrapperBuffer { +class ConstPatchCoordWrapperBuffer : public RawDataWrapperVertexBuffer<const PatchCoord> { public: - RawDataWrapperBuffer(T *data) : data_(data) + ConstPatchCoordWrapperBuffer(const PatchCoord *data, int num_vertices) + : RawDataWrapperVertexBuffer(data, num_vertices) { } - - T *BindCpuBuffer() - { - return data_; - } - - // TODO(sergey): Support UpdateData(). - - protected: - T *data_; }; template<typename EVAL_VERTEX_BUFFER, @@ -170,7 +163,7 @@ class FaceVaryingVolatileEval { { RawDataWrapperBuffer<float> face_varying_data(face_varying); BufferDescriptor face_varying_desc(0, 2, 2); - SinglePatchCoordBuffer patch_coord_buffer(patch_coord); + ConstPatchCoordWrapperBuffer patch_coord_buffer(&patch_coord, 1); const EVALUATOR *eval_instance = OpenSubdiv::Osd::GetEvaluator<EVALUATOR>( evaluator_cache_, src_face_varying_desc_, face_varying_desc, device_context_); EVALUATOR::EvalPatchesFaceVarying(src_face_varying_data_, @@ -349,7 +342,7 @@ class VolatileEvalOutput { RawDataWrapperBuffer<float> P_data(P); // TODO(sergey): Support interleaved vertex-varying data. BufferDescriptor P_desc(0, 3, 3); - SinglePatchCoordBuffer patch_coord_buffer(patch_coord); + ConstPatchCoordWrapperBuffer patch_coord_buffer(&patch_coord, 1); const EVALUATOR *eval_instance = OpenSubdiv::Osd::GetEvaluator<EVALUATOR>( evaluator_cache_, src_desc_, P_desc, device_context_); EVALUATOR::EvalPatches(src_data_, @@ -375,7 +368,7 @@ class VolatileEvalOutput { // TODO(sergey): Support interleaved vertex-varying data. BufferDescriptor P_desc(0, 3, 3); BufferDescriptor dpDu_desc(0, 3, 3), pPdv_desc(0, 3, 3); - SinglePatchCoordBuffer patch_coord_buffer(patch_coord); + ConstPatchCoordWrapperBuffer patch_coord_buffer(&patch_coord, 1); const EVALUATOR *eval_instance = OpenSubdiv::Osd::GetEvaluator<EVALUATOR>( evaluator_cache_, src_desc_, P_desc, dpDu_desc, pPdv_desc, device_context_); EVALUATOR::EvalPatches(src_data_, @@ -397,7 +390,7 @@ class VolatileEvalOutput { { RawDataWrapperBuffer<float> varying_data(varying); BufferDescriptor varying_desc(3, 3, 6); - SinglePatchCoordBuffer patch_coord_buffer(patch_coord); + ConstPatchCoordWrapperBuffer patch_coord_buffer(&patch_coord, 1); const EVALUATOR *eval_instance = OpenSubdiv::Osd::GetEvaluator<EVALUATOR>( evaluator_cache_, src_varying_desc_, varying_desc, device_context_); EVALUATOR::EvalPatchesVarying(src_varying_data_, |