Changeset View
Changeset View
Standalone View
Standalone View
intern/opensubdiv/internal/evaluator/eval_output.h
| Show All 40 Lines | ||||||||||
| class EvalOutputAPI::EvalOutput { | class EvalOutputAPI::EvalOutput { | |||||||||
| public: | public: | |||||||||
| virtual ~EvalOutput() = default; | virtual ~EvalOutput() = default; | |||||||||
| virtual void updateData(const float *src, int start_vertex, int num_vertices) = 0; | virtual void updateData(const float *src, int start_vertex, int num_vertices) = 0; | |||||||||
| virtual void updateVaryingData(const float *src, int start_vertex, int num_vertices) = 0; | virtual void updateVaryingData(const float *src, int start_vertex, int num_vertices) = 0; | |||||||||
| virtual void updateExtraVertexData(const float *src, int start_vertex, int num_vertices) = 0; | ||||||||||
| virtual void updateFaceVaryingData(const int face_varying_channel, | virtual void updateFaceVaryingData(const int face_varying_channel, | |||||||||
| const float *src, | const float *src, | |||||||||
| int start_vertex, | int start_vertex, | |||||||||
| int num_vertices) = 0; | int num_vertices) = 0; | |||||||||
| virtual void refine() = 0; | virtual void refine() = 0; | |||||||||
| // NOTE: P must point to a memory of at least float[3]*num_patch_coords. | // NOTE: P must point to a memory of at least float[3]*num_patch_coords. | |||||||||
| virtual void evalPatches(const PatchCoord *patch_coord, | virtual void evalPatches(const PatchCoord *patch_coord, | |||||||||
| const int num_patch_coords, | const int num_patch_coords, | |||||||||
| float *P) = 0; | float *P) = 0; | |||||||||
| // NOTE: P, dPdu, dPdv must point to a memory of at least float[3]*num_patch_coords. | // NOTE: P, dPdu, dPdv must point to a memory of at least float[3]*num_patch_coords. | |||||||||
| virtual void evalPatchesWithDerivatives(const PatchCoord *patch_coord, | virtual void evalPatchesWithDerivatives(const PatchCoord *patch_coord, | |||||||||
| const int num_patch_coords, | const int num_patch_coords, | |||||||||
| float *P, | float *P, | |||||||||
| float *dPdu, | float *dPdu, | |||||||||
| float *dPdv) = 0; | float *dPdv) = 0; | |||||||||
| // NOTE: varying must point to a memory of at least float[3]*num_patch_coords. | // NOTE: varying must point to a memory of at least float[3]*num_patch_coords. | |||||||||
| virtual void evalPatchesVarying(const PatchCoord *patch_coord, | virtual void evalPatchesVarying(const PatchCoord *patch_coord, | |||||||||
| const int num_patch_coords, | const int num_patch_coords, | |||||||||
| float *varying) = 0; | float *varying) = 0; | |||||||||
| // NOTE: vertex_data must point to a memory of at least float*num_extra_vertex_data. | ||||||||||
| virtual void evalPatchesExtraVertexData(const PatchCoord *patch_coord, | ||||||||||
| const int num_patch_coords, | ||||||||||
| float *vertex_data) = 0; | ||||||||||
| virtual void evalPatchesFaceVarying(const int face_varying_channel, | virtual void evalPatchesFaceVarying(const int face_varying_channel, | |||||||||
| const PatchCoord *patch_coord, | const PatchCoord *patch_coord, | |||||||||
| const int num_patch_coords, | const int num_patch_coords, | |||||||||
| float face_varying[2]) = 0; | float face_varying[2]) = 0; | |||||||||
| // The following interfaces are dependant on the actual evaluator type (CPU, OpenGL, etc.) which | // The following interfaces are dependant on the actual evaluator type (CPU, OpenGL, etc.) which | |||||||||
| // have slightly different APIs to access patch arrays, as well as different types for their | // have slightly different APIs to access patch arrays, as well as different types for their | |||||||||
| // data structure. They need to be overridden in the specific instances of the EvalOutput derived | // data structure. They need to be overridden in the specific instances of the EvalOutput derived | |||||||||
| ▲ Show 20 Lines • Show All 245 Lines • ▼ Show 20 Lines | typedef FaceVaryingVolatileEval<EVAL_VERTEX_BUFFER, | |||||||||
| EVALUATOR, | EVALUATOR, | |||||||||
| DEVICE_CONTEXT> | DEVICE_CONTEXT> | |||||||||
| FaceVaryingEval; | FaceVaryingEval; | |||||||||
| VolatileEvalOutput(const StencilTable *vertex_stencils, | VolatileEvalOutput(const StencilTable *vertex_stencils, | |||||||||
| const StencilTable *varying_stencils, | const StencilTable *varying_stencils, | |||||||||
| const vector<const StencilTable *> &all_face_varying_stencils, | const vector<const StencilTable *> &all_face_varying_stencils, | |||||||||
| const int face_varying_width, | const int face_varying_width, | |||||||||
| const int extra_vertex_data_width, | ||||||||||
| const PatchTable *patch_table, | const PatchTable *patch_table, | |||||||||
| EvaluatorCache *evaluator_cache = NULL, | EvaluatorCache *evaluator_cache = NULL, | |||||||||
| DEVICE_CONTEXT *device_context = NULL) | DEVICE_CONTEXT *device_context = NULL) | |||||||||
| : src_desc_(0, 3, 3), | : src_desc_(0, 3, 3), | |||||||||
| src_varying_desc_(0, 3, 3), | src_varying_desc_(0, 3, 3), | |||||||||
| src_extra_desc_(0, extra_vertex_data_width, extra_vertex_data_width), | ||||||||||
| face_varying_width_(face_varying_width), | face_varying_width_(face_varying_width), | |||||||||
| evaluator_cache_(evaluator_cache), | evaluator_cache_(evaluator_cache), | |||||||||
| device_context_(device_context) | device_context_(device_context) | |||||||||
| { | { | |||||||||
| // Total number of vertices = coarse points + refined points + local points. | // Total number of vertices = coarse points + refined points + local points. | |||||||||
| int num_total_vertices = vertex_stencils->GetNumControlVertices() + | int num_total_vertices = vertex_stencils->GetNumControlVertices() + | |||||||||
| vertex_stencils->GetNumStencils(); | vertex_stencils->GetNumStencils(); | |||||||||
| num_coarse_vertices_ = vertex_stencils->GetNumControlVertices(); | num_coarse_vertices_ = vertex_stencils->GetNumControlVertices(); | |||||||||
| using OpenSubdiv::Osd::convertToCompatibleStencilTable; | using OpenSubdiv::Osd::convertToCompatibleStencilTable; | |||||||||
| src_data_ = SRC_VERTEX_BUFFER::Create(3, num_total_vertices, device_context_); | src_data_ = SRC_VERTEX_BUFFER::Create(3, num_total_vertices, device_context_); | |||||||||
| src_varying_data_ = SRC_VERTEX_BUFFER::Create(3, num_total_vertices, device_context_); | src_varying_data_ = SRC_VERTEX_BUFFER::Create(3, num_total_vertices, device_context_); | |||||||||
| patch_table_ = PATCH_TABLE::Create(patch_table, device_context_); | patch_table_ = PATCH_TABLE::Create(patch_table, device_context_); | |||||||||
| vertex_stencils_ = convertToCompatibleStencilTable<STENCIL_TABLE>(vertex_stencils, | vertex_stencils_ = convertToCompatibleStencilTable<STENCIL_TABLE>(vertex_stencils, | |||||||||
| device_context_); | device_context_); | |||||||||
| varying_stencils_ = convertToCompatibleStencilTable<STENCIL_TABLE>(varying_stencils, | varying_stencils_ = convertToCompatibleStencilTable<STENCIL_TABLE>(varying_stencils, | |||||||||
| device_context_); | device_context_); | |||||||||
| // Optionally allocate additional data to be subdivided like vertex coordinates | ||||||||||
sergeyUnsubmitted Not Done Inline Actions
sergey: | ||||||||||
| if (extra_vertex_data_width > 0) { | ||||||||||
| src_extra_data_ = SRC_VERTEX_BUFFER::Create( | ||||||||||
| extra_vertex_data_width, num_total_vertices, device_context_); | ||||||||||
| } | ||||||||||
| else { | ||||||||||
| src_extra_data_ = NULL; | ||||||||||
| } | ||||||||||
| // Create evaluators for every face varying channel. | // Create evaluators for every face varying channel. | |||||||||
| face_varying_evaluators.reserve(all_face_varying_stencils.size()); | face_varying_evaluators.reserve(all_face_varying_stencils.size()); | |||||||||
| int face_varying_channel = 0; | int face_varying_channel = 0; | |||||||||
| for (const StencilTable *face_varying_stencils : all_face_varying_stencils) { | for (const StencilTable *face_varying_stencils : all_face_varying_stencils) { | |||||||||
| face_varying_evaluators.push_back(new FaceVaryingEval(face_varying_channel, | face_varying_evaluators.push_back(new FaceVaryingEval(face_varying_channel, | |||||||||
| face_varying_stencils, | face_varying_stencils, | |||||||||
| face_varying_width, | face_varying_width, | |||||||||
| patch_table_, | patch_table_, | |||||||||
| evaluator_cache_, | evaluator_cache_, | |||||||||
| device_context_)); | device_context_)); | |||||||||
| ++face_varying_channel; | ++face_varying_channel; | |||||||||
| } | } | |||||||||
| } | } | |||||||||
| ~VolatileEvalOutput() override | ~VolatileEvalOutput() override | |||||||||
| { | { | |||||||||
| delete src_data_; | delete src_data_; | |||||||||
| delete src_varying_data_; | delete src_varying_data_; | |||||||||
| delete src_extra_data_; | ||||||||||
| delete patch_table_; | delete patch_table_; | |||||||||
| delete vertex_stencils_; | delete vertex_stencils_; | |||||||||
| delete varying_stencils_; | delete varying_stencils_; | |||||||||
| for (FaceVaryingEval *face_varying_evaluator : face_varying_evaluators) { | for (FaceVaryingEval *face_varying_evaluator : face_varying_evaluators) { | |||||||||
| delete face_varying_evaluator; | delete face_varying_evaluator; | |||||||||
| } | } | |||||||||
| } | } | |||||||||
| // TODO(sergey): Implement binding API. | // TODO(sergey): Implement binding API. | |||||||||
| void updateData(const float *src, int start_vertex, int num_vertices) override | void updateData(const float *src, int start_vertex, int num_vertices) override | |||||||||
| { | { | |||||||||
| src_data_->UpdateData(src, start_vertex, num_vertices, device_context_); | src_data_->UpdateData(src, start_vertex, num_vertices, device_context_); | |||||||||
| } | } | |||||||||
| void updateVaryingData(const float *src, int start_vertex, int num_vertices) override | void updateVaryingData(const float *src, int start_vertex, int num_vertices) override | |||||||||
| { | { | |||||||||
| src_varying_data_->UpdateData(src, start_vertex, num_vertices, device_context_); | src_varying_data_->UpdateData(src, start_vertex, num_vertices, device_context_); | |||||||||
| } | } | |||||||||
| void updateExtraVertexData(const float *src, int start_vertex, int num_vertices) override | ||||||||||
| { | ||||||||||
| src_extra_data_->UpdateData(src, start_vertex, num_vertices, device_context_); | ||||||||||
| } | ||||||||||
| void updateFaceVaryingData(const int face_varying_channel, | void updateFaceVaryingData(const int face_varying_channel, | |||||||||
| const float *src, | const float *src, | |||||||||
| int start_vertex, | int start_vertex, | |||||||||
| int num_vertices) override | int num_vertices) override | |||||||||
| { | { | |||||||||
| assert(face_varying_channel >= 0); | assert(face_varying_channel >= 0); | |||||||||
| assert(face_varying_channel < face_varying_evaluators.size()); | assert(face_varying_channel < face_varying_evaluators.size()); | |||||||||
| face_varying_evaluators[face_varying_channel]->updateData(src, start_vertex, num_vertices); | face_varying_evaluators[face_varying_channel]->updateData(src, start_vertex, num_vertices); | |||||||||
| Show All 20 Lines | const EVALUATOR *eval_instance = OpenSubdiv::Osd::GetEvaluator<EVALUATOR>( | |||||||||
| evaluator_cache_, src_desc_, dst_desc, device_context_); | evaluator_cache_, src_desc_, dst_desc, device_context_); | |||||||||
| EVALUATOR::EvalStencils(src_data_, | EVALUATOR::EvalStencils(src_data_, | |||||||||
| src_desc_, | src_desc_, | |||||||||
| src_data_, | src_data_, | |||||||||
| dst_desc, | dst_desc, | |||||||||
| vertex_stencils_, | vertex_stencils_, | |||||||||
| eval_instance, | eval_instance, | |||||||||
| device_context_); | device_context_); | |||||||||
| // Evaluate extra vertex data. | ||||||||||
| if (src_extra_data_) { | ||||||||||
| BufferDescriptor dst_extra_desc = src_extra_desc_; | ||||||||||
| dst_extra_desc.offset += num_coarse_vertices_ * src_extra_desc_.stride; | ||||||||||
| const EVALUATOR *eval_instance = OpenSubdiv::Osd::GetEvaluator<EVALUATOR>( | ||||||||||
| evaluator_cache_, src_extra_desc_, dst_extra_desc, device_context_); | ||||||||||
| EVALUATOR::EvalStencils(src_extra_data_, | ||||||||||
| src_extra_desc_, | ||||||||||
| src_extra_data_, | ||||||||||
| dst_extra_desc, | ||||||||||
| vertex_stencils_, | ||||||||||
| eval_instance, | ||||||||||
| device_context_); | ||||||||||
| } | ||||||||||
| // Evaluate varying data. | // Evaluate varying data. | |||||||||
| if (hasVaryingData()) { | if (hasVaryingData()) { | |||||||||
| BufferDescriptor dst_varying_desc = src_varying_desc_; | BufferDescriptor dst_varying_desc = src_varying_desc_; | |||||||||
| dst_varying_desc.offset += num_coarse_vertices_ * src_varying_desc_.stride; | dst_varying_desc.offset += num_coarse_vertices_ * src_varying_desc_.stride; | |||||||||
| eval_instance = OpenSubdiv::Osd::GetEvaluator<EVALUATOR>( | eval_instance = OpenSubdiv::Osd::GetEvaluator<EVALUATOR>( | |||||||||
| evaluator_cache_, src_varying_desc_, dst_varying_desc, device_context_); | evaluator_cache_, src_varying_desc_, dst_varying_desc, device_context_); | |||||||||
| EVALUATOR::EvalStencils(src_varying_data_, | EVALUATOR::EvalStencils(src_varying_data_, | |||||||||
| src_varying_desc_, | src_varying_desc_, | |||||||||
| ▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | EVALUATOR::EvalPatchesVarying(src_varying_data_, | |||||||||
| varying_desc, | varying_desc, | |||||||||
| patch_coord_buffer.GetNumVertices(), | patch_coord_buffer.GetNumVertices(), | |||||||||
| &patch_coord_buffer, | &patch_coord_buffer, | |||||||||
| patch_table_, | patch_table_, | |||||||||
| eval_instance, | eval_instance, | |||||||||
| device_context_); | device_context_); | |||||||||
| } | } | |||||||||
| // NOTE: vertex_data must point to a memory of at least float*num_extra_vertex_data. | ||||||||||
| void evalPatchesExtraVertexData(const PatchCoord *patch_coord, | ||||||||||
| const int num_patch_coords, | ||||||||||
| float *extra_vertex_data) override | ||||||||||
| { | ||||||||||
| RawDataWrapperBuffer<float> vertex_data(extra_vertex_data); | ||||||||||
| BufferDescriptor vertex_desc(0, src_extra_desc_.length, src_extra_desc_.length); | ||||||||||
| ConstPatchCoordWrapperBuffer patch_coord_buffer(patch_coord, num_patch_coords); | ||||||||||
| const EVALUATOR *eval_instance = OpenSubdiv::Osd::GetEvaluator<EVALUATOR>( | ||||||||||
| evaluator_cache_, src_extra_desc_, vertex_desc, device_context_); | ||||||||||
| EVALUATOR::EvalPatches(src_extra_data_, | ||||||||||
| src_extra_desc_, | ||||||||||
| &vertex_data, | ||||||||||
| vertex_desc, | ||||||||||
| patch_coord_buffer.GetNumVertices(), | ||||||||||
| &patch_coord_buffer, | ||||||||||
| patch_table_, | ||||||||||
| eval_instance, | ||||||||||
| device_context_); | ||||||||||
| } | ||||||||||
| void evalPatchesFaceVarying(const int face_varying_channel, | void evalPatchesFaceVarying(const int face_varying_channel, | |||||||||
| const PatchCoord *patch_coord, | const PatchCoord *patch_coord, | |||||||||
| const int num_patch_coords, | const int num_patch_coords, | |||||||||
| float face_varying[2]) override | float face_varying[2]) override | |||||||||
| { | { | |||||||||
| assert(face_varying_channel >= 0); | assert(face_varying_channel >= 0); | |||||||||
| assert(face_varying_channel < face_varying_evaluators.size()); | assert(face_varying_channel < face_varying_evaluators.size()); | |||||||||
| face_varying_evaluators[face_varying_channel]->evalPatches( | face_varying_evaluators[face_varying_channel]->evalPatches( | |||||||||
| Show All 23 Lines | public: | |||||||||
| PATCH_TABLE *getFVarPatchTable(const int face_varying_channel) const | PATCH_TABLE *getFVarPatchTable(const int face_varying_channel) const | |||||||||
| { | { | |||||||||
| return face_varying_evaluators[face_varying_channel]->getPatchTable(); | return face_varying_evaluators[face_varying_channel]->getPatchTable(); | |||||||||
| } | } | |||||||||
| private: | private: | |||||||||
| SRC_VERTEX_BUFFER *src_data_; | SRC_VERTEX_BUFFER *src_data_; | |||||||||
| SRC_VERTEX_BUFFER *src_varying_data_; | SRC_VERTEX_BUFFER *src_varying_data_; | |||||||||
| SRC_VERTEX_BUFFER *src_extra_data_; | ||||||||||
| PATCH_TABLE *patch_table_; | PATCH_TABLE *patch_table_; | |||||||||
| BufferDescriptor src_desc_; | BufferDescriptor src_desc_; | |||||||||
| BufferDescriptor src_varying_desc_; | BufferDescriptor src_varying_desc_; | |||||||||
| BufferDescriptor src_extra_desc_; | ||||||||||
| int num_coarse_vertices_; | int num_coarse_vertices_; | |||||||||
| const STENCIL_TABLE *vertex_stencils_; | const STENCIL_TABLE *vertex_stencils_; | |||||||||
| const STENCIL_TABLE *varying_stencils_; | const STENCIL_TABLE *varying_stencils_; | |||||||||
| int face_varying_width_; | int face_varying_width_; | |||||||||
| vector<FaceVaryingEval *> face_varying_evaluators; | vector<FaceVaryingEval *> face_varying_evaluators; | |||||||||
| Show All 9 Lines | ||||||||||