[Bf-blender-cvs] [b1d2ea3e1b1] master: Metal: Add gl_PrimitiveID support.

Jason Fielder noreply at git.blender.org
Sun Jan 8 15:43:41 CET 2023


Commit: b1d2ea3e1b1173122eebecda0c3bd7552f4ee9c1
Author: Jason Fielder
Date:   Sun Jan 8 15:40:40 2023 +0100
Branches: master
https://developer.blender.org/rBb1d2ea3e1b1173122eebecda0c3bd7552f4ee9c1

Metal: Add gl_PrimitiveID support.

Resolves failing Mesh Snap utilities line add-on.

Authored by Apple: Michael Parkin-White

Ref T96261

Reviewed By: fclem

Maniphest Tasks: T96261

Differential Revision: https://developer.blender.org/D16905

===================================================================

M	source/blender/gpu/metal/mtl_shader_generator.hh
M	source/blender/gpu/metal/mtl_shader_generator.mm

===================================================================

diff --git a/source/blender/gpu/metal/mtl_shader_generator.hh b/source/blender/gpu/metal/mtl_shader_generator.hh
index f4cf42deb68..90f9a86b064 100644
--- a/source/blender/gpu/metal/mtl_shader_generator.hh
+++ b/source/blender/gpu/metal/mtl_shader_generator.hh
@@ -391,6 +391,7 @@ class MSLGeneratorInterface {
   bool uses_gl_InstanceID;
   bool uses_gl_BaseInstanceARB;
   bool uses_gl_FrontFacing;
+  bool uses_gl_PrimitiveID;
   /* Sets the output render target array index when using multilayered rendering. */
   bool uses_gl_FragDepth;
   bool uses_mtl_array_index_;
diff --git a/source/blender/gpu/metal/mtl_shader_generator.mm b/source/blender/gpu/metal/mtl_shader_generator.mm
index 9ed1461f857..fc37263d239 100644
--- a/source/blender/gpu/metal/mtl_shader_generator.mm
+++ b/source/blender/gpu/metal/mtl_shader_generator.mm
@@ -670,6 +670,9 @@ bool MTLShader::generate_msl_from_glsl(const shader::ShaderCreateInfo *info)
     msl_iface.uses_gl_FrontFacing = bool(info->builtins_ & BuiltinBits::FRONT_FACING) ||
                                     shd_builder_->glsl_fragment_source_.find("gl_FrontFacing") !=
                                         std::string::npos;
+    msl_iface.uses_gl_PrimitiveID = bool(info->builtins_ & BuiltinBits::PRIMITIVE_ID) ||
+                                    shd_builder_->glsl_fragment_source_.find("gl_PrimitiveID") !=
+                                        std::string::npos;
 
     /* NOTE(Metal): If FragColor is not used, then we treat the first fragment output attachment
      * as the primary output. */
@@ -990,6 +993,9 @@ bool MTLShader::generate_msl_from_glsl(const shader::ShaderCreateInfo *info)
     if (msl_iface.uses_gl_FrontFacing) {
       ss_fragment << "MTLBOOL gl_FrontFacing;" << std::endl;
     }
+    if (msl_iface.uses_gl_PrimitiveID) {
+      ss_fragment << "uint gl_PrimitiveID;" << std::endl;
+    }
 
     /* Add Texture members. */
     for (const MSLTextureSampler &tex : msl_iface.texture_samplers) {
@@ -1515,6 +1521,9 @@ std::string MSLGeneratorInterface::generate_msl_fragment_entry_stub()
   if (this->uses_gl_FrontFacing) {
     out << "fragment_shader_instance.gl_FrontFacing = gl_FrontFacing;" << std::endl;
   }
+  if (this->uses_gl_PrimitiveID) {
+    out << "fragment_shader_instance.gl_PrimitiveID = gl_PrimitiveID;" << std::endl;
+  }
 
   /* Copy vertex attributes into local variable.s */
   out << this->generate_msl_fragment_input_population();
@@ -1690,6 +1699,9 @@ std::string MSLGeneratorInterface::generate_msl_fragment_inputs_string()
   if (this->uses_gl_FrontFacing) {
     out << ",\n\tconst MTLBOOL gl_FrontFacing [[front_facing]]";
   }
+  if (this->uses_gl_PrimitiveID) {
+    out << ",\n\tconst uint gl_PrimitiveID [[primitive_id]]";
+  }
 
   /* Barycentrics. */
   if (this->uses_barycentrics) {



More information about the Bf-blender-cvs mailing list