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
This commit is contained in:
Jason Fielder 2023-01-08 15:40:40 +01:00 committed by Clément Foucault
parent 710f8164b4
commit b1d2ea3e1b
Notes: blender-bot 2023-02-14 07:53:51 +01:00
Referenced by issue #96261, Metal Viewport
2 changed files with 13 additions and 0 deletions

View File

@ -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_;

View File

@ -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) {