diff --git a/intern/opensubdiv/internal/evaluator/evaluator_capi.cc b/intern/opensubdiv/internal/evaluator/evaluator_capi.cc index 96c72f960fc..0a0154c0d9b 100644 --- a/intern/opensubdiv/internal/evaluator/evaluator_capi.cc +++ b/intern/opensubdiv/internal/evaluator/evaluator_capi.cc @@ -6,7 +6,11 @@ #include "opensubdiv_evaluator_capi.hh" -#include +#ifdef __APPLE__ +# include +#else +# include +#endif #include "MEM_guardedalloc.h" @@ -34,7 +38,11 @@ const char *openSubdiv_getGLSLPatchBasisSource() /* Using a global string to avoid dealing with memory allocation/ownership. */ static std::string patch_basis_source; if (patch_basis_source.empty()) { +#ifdef __APPLE__ + patch_basis_source = OpenSubdiv::Osd::MTLPatchShaderSource::GetPatchBasisShaderSource(); +#else patch_basis_source = OpenSubdiv::Osd::GLSLPatchShaderSource::GetPatchBasisShaderSource(); +#endif } return patch_basis_source.c_str(); } diff --git a/intern/opensubdiv/internal/evaluator/gpu_compute_evaluator.cc b/intern/opensubdiv/internal/evaluator/gpu_compute_evaluator.cc index da48a91dadb..00e78e2580c 100644 --- a/intern/opensubdiv/internal/evaluator/gpu_compute_evaluator.cc +++ b/intern/opensubdiv/internal/evaluator/gpu_compute_evaluator.cc @@ -9,7 +9,6 @@ #include #include #include -#include #include #include @@ -336,8 +335,13 @@ static GPUShader *compile_eval_stencil_shader(BufferDescriptor const &srcDesc, using namespace blender::gpu::shader; ShaderCreateInfo info("opensubdiv_compute_eval"); info.local_group_size(workGroupSize, 1, 1); + + /* Ensure the basis code has access to proper backend specification define: it is not guaranteed + * that the code provided by OpenSubdiv specifies it. For example, it doesn't for GLSL but it + * does for Metal. Additionally, for Metal OpenSubdiv defines OSD_PATCH_BASIS_METAL as 1, so do + * the same here to avoid possible warning about value being re-defined. */ if (GPU_backend_get_type() == GPU_BACKEND_METAL) { - info.define("OSD_PATCH_BASIS_METAL"); + info.define("OSD_PATCH_BASIS_METAL", "1"); } else { info.define("OSD_PATCH_BASIS_GLSL"); @@ -438,8 +442,13 @@ static GPUShader *compile_eval_patches_shader(BufferDescriptor const &srcDesc, using namespace blender::gpu::shader; ShaderCreateInfo info("opensubdiv_compute_eval"); info.local_group_size(workGroupSize, 1, 1); + + /* Ensure the basis code has access to proper backend specification define: it is not guaranteed + * that the code provided by OpenSubdiv specifies it. For example, it doesn't for GLSL but it + * does for Metal. Additionally, for Metal OpenSubdiv defines OSD_PATCH_BASIS_METAL as 1, so do + * the same here to avoid possible warning about value being re-defined. */ if (GPU_backend_get_type() == GPU_BACKEND_METAL) { - info.define("OSD_PATCH_BASIS_METAL"); + info.define("OSD_PATCH_BASIS_METAL", "1"); } else { info.define("OSD_PATCH_BASIS_GLSL"); diff --git a/source/blender/draw/intern/shaders/subdiv_info.hh b/source/blender/draw/intern/shaders/subdiv_info.hh index 41c474b5867..aae06686111 100644 --- a/source/blender/draw/intern/shaders/subdiv_info.hh +++ b/source/blender/draw/intern/shaders/subdiv_info.hh @@ -30,7 +30,9 @@ GPU_SHADER_CREATE_END() * \{ */ #ifdef __APPLE__ -# define SUBDIV_PATCH_EVALUATION_BASIS_DEFINES() DEFINE("OSD_PATCH_BASIS_METAL") +/* Match definition from OPenSubdiv which defines OSD_PATCH_BASIS_METAL as 1. Matching it here + * avoids possible re-definition warning at runtime. */ +# define SUBDIV_PATCH_EVALUATION_BASIS_DEFINES() DEFINE_VALUE("OSD_PATCH_BASIS_METAL", "1") #else # define SUBDIV_PATCH_EVALUATION_BASIS_DEFINES() DEFINE("OSD_PATCH_BASIS_GLSL") #endif