diff --git a/opensubdiv/osd/CMakeLists.txt b/opensubdiv/osd/CMakeLists.txt index 470b34699..654697a74 100755 --- a/opensubdiv/osd/CMakeLists.txt +++ b/opensubdiv/osd/CMakeLists.txt @@ -52,13 +52,18 @@ set(PUBLIC_HEADER_FILES types.h ) -list(APPEND KERNEL_FILES - patchBasisCommonTypes.h - patchBasisCommon.h - patchBasisCommonEval.h +set(DOXY_HEADER_FILES ${PUBLIC_HEADER_FILES}) + +# These are public but excluded from doxygen +list(APPEND PUBLIC_HEADER_FILES + patchBasisTypes.h + patchBasis.h ) -set(DOXY_HEADER_FILES ${PUBLIC_HEADER_FILES}) +list(APPEND KERNEL_FILES + patchBasisTypes.h + patchBasis.h +) #------------------------------------------------------------------------------- set(OPENMP_PUBLIC_HEADERS diff --git a/opensubdiv/osd/clEvaluator.cpp b/opensubdiv/osd/clEvaluator.cpp index c2f8d7109..77d076e8f 100644 --- a/opensubdiv/osd/clEvaluator.cpp +++ b/opensubdiv/osd/clEvaluator.cpp @@ -42,13 +42,10 @@ static const char *clSource = #include "clKernel.gen.h" ; static const char *patchBasisTypesSource = -#include "patchBasisCommonTypes.gen.h" +#include "patchBasisTypes.gen.h" ; static const char *patchBasisSource = -#include "patchBasisCommon.gen.h" -; -static const char *patchBasisEvalSource = -#include "patchBasisCommonEval.gen.h" +#include "patchBasis.gen.h" ; // ---------------------------------------------------------------------------- @@ -175,9 +172,8 @@ CLEvaluator::Compile(BufferDescriptor const &srcDesc, const char *sources[] = { defineStr.c_str(), patchBasisTypesSource, patchBasisSource, - patchBasisEvalSource, clSource }; - _program = clCreateProgramWithSource(_clContext, 5, sources, 0, &errNum); + _program = clCreateProgramWithSource(_clContext, 4, sources, 0, &errNum); if (errNum != CL_SUCCESS) { Far::Error(Far::FAR_RUNTIME_ERROR, "clCreateProgramWithSource (%d)", errNum); diff --git a/opensubdiv/osd/cpuEvaluator.cpp b/opensubdiv/osd/cpuEvaluator.cpp index a5ce6978a..473e37b97 100644 --- a/opensubdiv/osd/cpuEvaluator.cpp +++ b/opensubdiv/osd/cpuEvaluator.cpp @@ -24,9 +24,7 @@ #include "../osd/cpuEvaluator.h" #include "../osd/cpuKernel.h" -#include "../osd/patchBasisCommonTypes.h" -#include "../osd/patchBasisCommon.h" -#include "../osd/patchBasisCommonEval.h" +#include "../osd/patchBasis.h" #include diff --git a/opensubdiv/osd/cudaKernel.cu b/opensubdiv/osd/cudaKernel.cu index 910565539..45fa18f3d 100644 --- a/opensubdiv/osd/cudaKernel.cu +++ b/opensubdiv/osd/cudaKernel.cu @@ -24,9 +24,8 @@ #include #define OSD_PATCH_BASIS_CUDA -#include "../osd/patchBasisCommonTypes.h" -#include "../osd/patchBasisCommon.h" -#include "../osd/patchBasisCommonEval.h" +#include "../osd/patchBasisTypes.h" +#include "../osd/patchBasis.h" // ----------------------------------------------------------------------------- template struct DeviceVertex { diff --git a/opensubdiv/osd/glslPatchShaderSource.cpp b/opensubdiv/osd/glslPatchShaderSource.cpp index 81a78041f..d3576a778 100644 --- a/opensubdiv/osd/glslPatchShaderSource.cpp +++ b/opensubdiv/osd/glslPatchShaderSource.cpp @@ -41,13 +41,10 @@ static const char *patchLegacyShaderSource = #include "glslPatchLegacy.gen.h" ; static const char *patchBasisTypesShaderSource = -#include "patchBasisCommonTypes.gen.h" +#include "patchBasisTypes.gen.h" ; static const char *patchBasisShaderSource = -#include "patchBasisCommon.gen.h" -; -static const char *patchBasisEvalShaderSource = -#include "patchBasisCommonEval.gen.h" +#include "patchBasis.gen.h" ; static const char *boxSplineTriangleShaderSource = #include "glslPatchBoxSplineTriangle.gen.h" @@ -84,7 +81,6 @@ GLSLPatchShaderSource::GetPatchBasisShaderSource() { #endif ss << std::string(patchBasisTypesShaderSource); ss << std::string(patchBasisShaderSource); - ss << std::string(patchBasisEvalShaderSource); return ss.str(); } diff --git a/opensubdiv/osd/hlslPatchShaderSource.cpp b/opensubdiv/osd/hlslPatchShaderSource.cpp index 6a3bba496..172ea8068 100644 --- a/opensubdiv/osd/hlslPatchShaderSource.cpp +++ b/opensubdiv/osd/hlslPatchShaderSource.cpp @@ -43,13 +43,10 @@ static const char *patchLegacyShaderSource = #include "hlslPatchLegacy.gen.h" ; static const char *patchBasisTypesShaderSource = -#include "patchBasisCommonTypes.gen.h" +#include "patchBasisTypes.gen.h" ; static const char *patchBasisShaderSource = -#include "patchBasisCommon.gen.h" -; -static const char *patchBasisEvalShaderSource = -#include "patchBasisCommonEval.gen.h" +#include "patchBasis.gen.h" ; static const char *boxSplineTriangleShaderSource = #include "hlslPatchBoxSplineTriangle.gen.h" @@ -86,7 +83,6 @@ HLSLPatchShaderSource::GetPatchBasisShaderSource() { #endif ss << std::string(patchBasisTypesShaderSource); ss << std::string(patchBasisShaderSource); - ss << std::string(patchBasisEvalShaderSource); return ss.str(); } diff --git a/opensubdiv/osd/mtlPatchShaderSource.mm b/opensubdiv/osd/mtlPatchShaderSource.mm index 754909f01..6129d8b70 100644 --- a/opensubdiv/osd/mtlPatchShaderSource.mm +++ b/opensubdiv/osd/mtlPatchShaderSource.mm @@ -44,13 +44,10 @@ #include "mtlPatchLegacy.gen.h" ); static std::string patchBasisTypesShaderSource( -#include "patchBasisCommonTypes.gen.h" +#include "patchBasisTypes.gen.h" ); static std::string patchBasisShaderSource( -#include "patchBasisCommon.gen.h" -); -static std::string patchBasisEvalShaderSource( -#include "patchBasisCommonEval.gen.h" +#include "patchBasis.gen.h" ); static std::string bsplineShaderSource( #include "mtlPatchBSpline.gen.h" @@ -171,7 +168,6 @@ #endif ss << patchBasisTypesShaderSource; ss << patchBasisShaderSource; - ss << patchBasisEvalShaderSource; return ss.str(); } diff --git a/opensubdiv/osd/ompEvaluator.cpp b/opensubdiv/osd/ompEvaluator.cpp index 543824b5c..1352ff6ee 100644 --- a/opensubdiv/osd/ompEvaluator.cpp +++ b/opensubdiv/osd/ompEvaluator.cpp @@ -24,9 +24,7 @@ #include "../osd/ompEvaluator.h" #include "../osd/ompKernel.h" -#include "../osd/patchBasisCommonTypes.h" -#include "../osd/patchBasisCommon.h" -#include "../osd/patchBasisCommonEval.h" +#include "../osd/patchBasis.h" #include namespace OpenSubdiv { diff --git a/opensubdiv/osd/patchBasisCommon.h b/opensubdiv/osd/patchBasis.h similarity index 87% rename from opensubdiv/osd/patchBasisCommon.h rename to opensubdiv/osd/patchBasis.h index 13454fe01..13481a9df 100644 --- a/opensubdiv/osd/patchBasisCommon.h +++ b/opensubdiv/osd/patchBasis.h @@ -22,8 +22,33 @@ // language governing permissions and limitations under the Apache License. // -#ifndef OPENSUBDIV3_OSD_PATCH_BASIS_COMMON_H -#define OPENSUBDIV3_OSD_PATCH_BASIS_COMMON_H +#ifndef OPENSUBDIV3_OSD_PATCH_BASIS_H +#define OPENSUBDIV3_OSD_PATCH_BASIS_H + +/// This is an implementation of the functionality from far/patchBasis.h +/// which can be used from client shader and kernel code, i.e for +/// GLSL, HLSL, CUDA, OpenCL, Metal, and C++ shaders and kernels. +/// +/// This is defined within the OpenSubdiv::Osd namespace for C++, but +/// the methods and types also have an Osd prefix for consistency with +/// environments (e.g. GLSL, etc.) where C++ namespaces are not available. + +#if !defined(OSD_PATCH_BASIS_GLSL) && \ + !defined(OSD_PATCH_BASIS_HLSL) && \ + !defined(OSD_PATCH_BASIS_CUDA) && \ + !defined(OSD_PATCH_BASIS_OPENCL) && \ + !defined(OSD_PATCH_BASIS_METAL) + +#include "../version.h" + +#include "../osd/patchBasisTypes.h" + +namespace OpenSubdiv { +namespace OPENSUBDIV_VERSION { + +namespace Osd { + +#endif OSD_FUNCTION_STORAGE_CLASS // template @@ -45,7 +70,6 @@ Osd_EvalBasisLinear(OSD_REAL s, OSD_REAL t, wP[2] = s * t; wP[3] = sC * t; } - if (OSD_OPTIONAL(wDs && wDt)) { wDs[0] = -tC; wDs[1] = tC; @@ -58,7 +82,7 @@ Osd_EvalBasisLinear(OSD_REAL s, OSD_REAL t, wDt[3] = sC; if (OSD_OPTIONAL(wDss && wDst && wDtt)) { - for(int i=0;i<4;i++) { + for(int i = 0; i < 4; ++i) { wDss[i] = 0.0f; wDtt[i] = 0.0f; } @@ -199,7 +223,6 @@ Osd_EvalBasisBSpline(OSD_REAL s, OSD_REAL t, } } } - if (OSD_OPTIONAL(wDs && wDt)) { for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { @@ -285,7 +308,6 @@ Osd_EvalBasisBezier(OSD_REAL s, OSD_REAL t, } } } - if (OSD_OPTIONAL(wDs && wDt)) { for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { @@ -1415,4 +1437,191 @@ OsdGetGregoryPatchWeights( } } +// +// Higher level basis evaluation functions that deal with parameterization and +// boundary issues (reflected in PatchParam) for all patch types: +// +OSD_FUNCTION_STORAGE_CLASS +// template +int +OsdEvaluatePatchBasisNormalized( + int patchType, OsdPatchParam param, + OSD_REAL s, OSD_REAL t, + OSD_OUT_ARRAY(OSD_REAL, wP, 20), + OSD_OUT_ARRAY(OSD_REAL, wDs, 20), + OSD_OUT_ARRAY(OSD_REAL, wDt, 20), + OSD_OUT_ARRAY(OSD_REAL, wDss, 20), + OSD_OUT_ARRAY(OSD_REAL, wDst, 20), + OSD_OUT_ARRAY(OSD_REAL, wDtt, 20)) { + + int boundaryMask = OsdPatchParamGetBoundary(param); + + int nPoints = 0; + if (patchType == OSD_PATCH_DESCRIPTOR_REGULAR) { +#if OSD_ARRAY_ARG_BOUND_OPTIONAL + nPoints = Osd_EvalBasisBSpline(s, t, wP, wDs, wDt, wDss, wDst, wDtt); + if (boundaryMask != 0) { + Osd_boundBasisBSpline( + boundaryMask, wP, wDs, wDt, wDss, wDst, wDtt); + } +#else + OSD_REAL wP16[16], wDs16[16], wDt16[16], + wDss16[16], wDst16[16], wDtt16[16]; + nPoints = Osd_EvalBasisBSpline( + s, t, wP16, wDs16, wDt16, wDss16, wDst16, wDtt16); + if (boundaryMask != 0) { + Osd_boundBasisBSpline( + boundaryMask, wP16, wDs16, wDt16, wDss16, wDst16, wDtt16); + } + for (int i=0; i +int +OsdEvaluatePatchBasis( + int patchType, OsdPatchParam param, + OSD_REAL s, OSD_REAL t, + OSD_OUT_ARRAY(OSD_REAL, wP, 20), + OSD_OUT_ARRAY(OSD_REAL, wDs, 20), + OSD_OUT_ARRAY(OSD_REAL, wDt, 20), + OSD_OUT_ARRAY(OSD_REAL, wDss, 20), + OSD_OUT_ARRAY(OSD_REAL, wDst, 20), + OSD_OUT_ARRAY(OSD_REAL, wDtt, 20)) { + + OSD_REAL derivSign = 1.0f; + + if ((patchType == OSD_PATCH_DESCRIPTOR_LOOP) || + (patchType == OSD_PATCH_DESCRIPTOR_GREGORY_TRIANGLE) || + (patchType == OSD_PATCH_DESCRIPTOR_TRIANGLES)) { + OSD_REAL uv[2] = OSD_ARRAY_2(OSD_REAL, s, t); + OsdPatchParamNormalizeTriangle(param, uv); + s = uv[0]; + t = uv[1]; + if (OsdPatchParamIsTriangleRotated(param)) { + derivSign = -1.0f; + } + } else { + OSD_REAL uv[2] = OSD_ARRAY_2(OSD_REAL, s, t); + OsdPatchParamNormalize(param, uv); + s = uv[0]; + t = uv[1]; + } + + int nPoints = OsdEvaluatePatchBasisNormalized( + patchType, param, s, t, wP, wDs, wDt, wDss, wDst, wDtt); + + if (OSD_OPTIONAL(wDs && wDt)) { + OSD_REAL d1Scale = + derivSign * OSD_REAL_CAST(1 << OsdPatchParamGetDepth(param)); + + for (int i = 0; i < nPoints; ++i) { + wDs[i] *= d1Scale; + wDt[i] *= d1Scale; + } + + if (OSD_OPTIONAL(wDss && wDst && wDtt)) { + OSD_REAL d2Scale = derivSign * d1Scale * d1Scale; + + for (int i = 0; i < nPoints; ++i) { + wDss[i] *= d2Scale; + wDst[i] *= d2Scale; + wDtt[i] *= d2Scale; + } + } + } + return nPoints; +} + +#if !defined(OSD_PATCH_BASIS_GLSL) && \ + !defined(OSD_PATCH_BASIS_HLSL) && \ + !defined(OSD_PATCH_BASIS_CUDA) && \ + !defined(OSD_PATCH_BASIS_OPENCL) && \ + !defined(OSD_PATCH_BASIS_METAL) + +} // end namespace Osd + +} // end namespace OPENSUBDIV_VERSION +using namespace OPENSUBDIV_VERSION; + +} // end namespace OpenSubdiv + +#endif + #endif /* OPENSUBDIV3_OSD_PATCH_BASIS_H */ diff --git a/opensubdiv/osd/patchBasisCommonEval.h b/opensubdiv/osd/patchBasisCommonEval.h deleted file mode 100644 index 5af5953a1..000000000 --- a/opensubdiv/osd/patchBasisCommonEval.h +++ /dev/null @@ -1,196 +0,0 @@ -// -// 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 OPENSUBDIV3_OSD_PATCH_BASIS_COMMON_EVAL_H -#define OPENSUBDIV3_OSD_PATCH_BASIS_COMMON_EVAL_H - -OSD_FUNCTION_STORAGE_CLASS -// template -int -OsdEvaluatePatchBasisNormalized( - int patchType, OsdPatchParam param, - OSD_REAL s, OSD_REAL t, - OSD_OUT_ARRAY(OSD_REAL, wP, 20), - OSD_OUT_ARRAY(OSD_REAL, wDs, 20), - OSD_OUT_ARRAY(OSD_REAL, wDt, 20), - OSD_OUT_ARRAY(OSD_REAL, wDss, 20), - OSD_OUT_ARRAY(OSD_REAL, wDst, 20), - OSD_OUT_ARRAY(OSD_REAL, wDtt, 20)) { - - int boundaryMask = OsdPatchParamGetBoundary(param); - - int nPoints = 0; - if (patchType == OSD_PATCH_DESCRIPTOR_REGULAR) { -#if OSD_ARRAY_ARG_BOUND_OPTIONAL - nPoints = Osd_EvalBasisBSpline(s, t, wP, wDs, wDt, wDss, wDst, wDtt); - if (boundaryMask != 0) { - Osd_boundBasisBSpline( - boundaryMask, wP, wDs, wDt, wDss, wDst, wDtt); - } -#else - OSD_REAL wP16[16], wDs16[16], wDt16[16], - wDss16[16], wDst16[16], wDtt16[16]; - nPoints = Osd_EvalBasisBSpline( - s, t, wP16, wDs16, wDt16, wDss16, wDst16, wDtt16); - if (boundaryMask != 0) { - Osd_boundBasisBSpline( - boundaryMask, wP16, wDs16, wDt16, wDss16, wDst16, wDtt16); - } - for (int i=0; i -int -OsdEvaluatePatchBasis( - int patchType, OsdPatchParam param, - OSD_REAL s, OSD_REAL t, - OSD_OUT_ARRAY(OSD_REAL, wP, 20), - OSD_OUT_ARRAY(OSD_REAL, wDs, 20), - OSD_OUT_ARRAY(OSD_REAL, wDt, 20), - OSD_OUT_ARRAY(OSD_REAL, wDss, 20), - OSD_OUT_ARRAY(OSD_REAL, wDst, 20), - OSD_OUT_ARRAY(OSD_REAL, wDtt, 20)) { - - OSD_REAL derivSign = 1.0f; - - if ((patchType == OSD_PATCH_DESCRIPTOR_LOOP) || - (patchType == OSD_PATCH_DESCRIPTOR_GREGORY_TRIANGLE) || - (patchType == OSD_PATCH_DESCRIPTOR_TRIANGLES)) { - OSD_REAL uv[2] = OSD_ARRAY_2(OSD_REAL, s, t); - OsdPatchParamNormalizeTriangle(param, uv); - s = uv[0]; - t = uv[1]; - if (OsdPatchParamIsTriangleRotated(param)) { - derivSign = -1.0f; - } - } else { - OSD_REAL uv[2] = OSD_ARRAY_2(OSD_REAL, s, t); - OsdPatchParamNormalize(param, uv); - s = uv[0]; - t = uv[1]; - } - - int nPoints = OsdEvaluatePatchBasisNormalized( - patchType, param, s, t, wP, wDs, wDt, wDss, wDst, wDtt); - - if (OSD_OPTIONAL(wDs && wDt)) { - OSD_REAL d1Scale = - derivSign * OSD_REAL_CAST(1 << OsdPatchParamGetDepth(param)); - - for (int i = 0; i < nPoints; ++i) { - wDs[i] *= d1Scale; - wDt[i] *= d1Scale; - } - - if (OSD_OPTIONAL(wDss && wDst && wDtt)) { - OSD_REAL d2Scale = derivSign * d1Scale * d1Scale; - - for (int i = 0; i < nPoints; ++i) { - wDss[i] *= d2Scale; - wDst[i] *= d2Scale; - wDtt[i] *= d2Scale; - } - } - } - return nPoints; -} - -#endif /* OPENSUBDIV3_OSD_PATCH_BASIS_COMMON_EVAL_H */ diff --git a/opensubdiv/osd/patchBasisCommonTypes.h b/opensubdiv/osd/patchBasisTypes.h similarity index 92% rename from opensubdiv/osd/patchBasisCommonTypes.h rename to opensubdiv/osd/patchBasisTypes.h index 594e6b111..d3d98f324 100644 --- a/opensubdiv/osd/patchBasisCommonTypes.h +++ b/opensubdiv/osd/patchBasisTypes.h @@ -22,8 +22,31 @@ // language governing permissions and limitations under the Apache License. // -#ifndef OPENSUBDIV3_OSD_PATCH_BASIS_COMMON_TYPES_H -#define OPENSUBDIV3_OSD_PATCH_BASIS_COMMON_TYPES_H +#ifndef OPENSUBDIV3_OSD_PATCH_BASIS_TYPES_H +#define OPENSUBDIV3_OSD_PATCH_BASIS_TYPES_H + +/// This is an implementation of the functionality from osd/types.h +/// which can be used from client shader and kernel code, i.e for +/// GLSL, HLSL, CUDA, OpenCL, Metal, and C++ shaders and kernels. +/// +/// This is defined within the OpenSubdiv::Osd namespace for C++, but +/// the methods and types also have an Osd prefix for consistency with +/// environments (e.g. GLSL, etc.) where C++ namespaces are not available. + +#if !defined(OSD_PATCH_BASIS_GLSL) && \ + !defined(OSD_PATCH_BASIS_HLSL) && \ + !defined(OSD_PATCH_BASIS_CUDA) && \ + !defined(OSD_PATCH_BASIS_OPENCL) && \ + !defined(OSD_PATCH_BASIS_METAL) + +#include "../version.h" + +namespace OpenSubdiv { +namespace OPENSUBDIV_VERSION { + +namespace Osd { + +#endif #if defined(OSD_PATCH_BASIS_GLSL) @@ -419,4 +442,19 @@ OsdPatchParamUnnormalizeTriangle( } } -#endif /* OPENSUBDIV3_OSD_PATCH_BASIS_COMMON_TYPES_H */ +#if !defined(OSD_PATCH_BASIS_GLSL) && \ + !defined(OSD_PATCH_BASIS_HLSL) && \ + !defined(OSD_PATCH_BASIS_CUDA) && \ + !defined(OSD_PATCH_BASIS_OPENCL) && \ + !defined(OSD_PATCH_BASIS_METAL) + +} // end namespace Osd + +} // end namespace OPENSUBDIV_VERSION +using namespace OPENSUBDIV_VERSION; + +} // end namespace OpenSubdiv + +#endif + +#endif /* OPENSUBDIV3_OSD_PATCH_BASIS_TYPES_H */ diff --git a/opensubdiv/osd/tbbKernel.cpp b/opensubdiv/osd/tbbKernel.cpp index 968b94ffa..07cf8e14e 100644 --- a/opensubdiv/osd/tbbKernel.cpp +++ b/opensubdiv/osd/tbbKernel.cpp @@ -26,9 +26,7 @@ #include "../osd/tbbKernel.h" #include "../osd/types.h" #include "../osd/bufferDescriptor.h" -#include "../osd/patchBasisCommonTypes.h" -#include "../osd/patchBasisCommon.h" -#include "../osd/patchBasisCommonEval.h" +#include "../osd/patchBasis.h" #include #include