<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>244152</bug_id>
          
          <creation_ts>2022-08-19 23:37:15 -0700</creation_ts>
          <short_desc>use of gl_VertexId causes error compiling shader with Metal backend</short_desc>
          <delta_ts>2022-08-26 23:38:15 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebGL</component>
          <version>Safari Technology Preview</version>
          <rep_platform>Mac (Intel)</rep_platform>
          <op_sys>macOS 12</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>morem</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>dino</cc>
    
    <cc>geofflang</cc>
    
    <cc>gman</cc>
    
    <cc>jonahr</cc>
    
    <cc>kbr</cc>
    
    <cc>kkinnunen</cc>
    
    <cc>kpiddington</cc>
    
    <cc>morem</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1892607</commentid>
    <comment_count>0</comment_count>
    <who name="">morem</who>
    <bug_when>2022-08-19 23:37:15 -0700</bug_when>
    <thetext>Hi,

I get an error checking the link status of a WebGL2 shader program

&quot;Internal error compiling shader with Metal backend&quot;

Or if I call `gl.validateProgram` before checking the link status

&quot;Program has not been successfully linked.&quot;


I don&apos;t have a minimal reproduction but tracked it down to the use of `gl_VertexId` and found a workaround. If I use it as is I get the above error but if I do `int(gl_VertexId)` everything works fine. I don&apos;t see this issue with Firefox or Chrome on Mac or Win.

I see the issue in Safari 16.0, 15.6 and earlier.


You can trigger the error in Mol* here: https://molstar.org/viewer/?debug-mode=1&amp;emdb=EMD-14403


Best
Alexander</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1892734</commentid>
    <comment_count>1</comment_count>
    <who name="">morem</who>
    <bug_when>2022-08-20 16:56:30 -0700</bug_when>
    <thetext>New repro link: https://molstar.org/dev/safari-debug/viewer/?debug-mode=1&amp;disable-wboit=1&amp;emdb=EMD-14403</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1893059</commentid>
    <comment_count>2</comment_count>
    <who name="Kenneth Russell">kbr</who>
    <bug_when>2022-08-22 14:11:06 -0700</bug_when>
    <thetext>The new repro link fails in Chrome with ANGLE&apos;s Metal backend as well. These are the reported compilation errors:

---
[.WebGL-0x118015ca100] GL_INVALID_OPERATION: Error: 0x00000502, in ../../third_party/angle/src/libANGLE/renderer/metal/ProgramMtl.mm, createMslShaderLib:768. Internal error compiling shader with Metal backend.
program_source:409:28: error: call to &apos;_ureadFromTexture&apos; is ambiguous
  metal::float4 ANGLE_55 = _ureadFromTexture(ANGLE_textureEnvs._utGroup, ANGLE_invocationVertexGlobals.gl_VertexID, ANGLE_userUniforms._uuGeoTexDim);
                           ^~~~~~~~~~~~~~~~~
program_source:377:15: note: candidate function
metal::float4 _ureadFromTexture(ANGLE_TextureEnv&lt;metal::texture2d&lt;float&gt;&gt; _utex, float _ui, metal::float2 _udim)
              ^
program_source:389:15: note: candidate function
metal::float4 _ureadFromTexture(ANGLE_TextureEnv&lt;metal::texture2d&lt;float&gt;&gt; _utex, int _ui, metal::float2 _udim)
              ^
program_source:418:28: error: call to &apos;_ureadFromTexture&apos; is ambiguous
  metal::float4 ANGLE_63 = _ureadFromTexture(ANGLE_textureEnvs._utPosition, ANGLE_invocationVertexGlobals.gl_VertexID, ANGLE_userUniforms._uuGeoTexDim);
                           ^~~~~~~~~~~~~~~~~
program_source:377:15: note: candidate function
metal::float4 _ureadFromTexture(ANGLE_TextureEnv&lt;metal::texture2d&lt;float&gt;&gt; _utex, float _ui, metal::float2 _udim)
              ^
program_source:389:15: note: candidate function
metal::float4 _ureadFromTexture(ANGLE_TextureEnv&lt;metal::texture2d&lt;float&gt;&gt; _utex, int _ui, metal::float2 _udim)
              ^
program_source:426:28: error: call to &apos;_ureadFromTexture&apos; is ambiguous
  metal::float4 ANGLE_68 = _ureadFromTexture(ANGLE_textureEnvs._utNormal, ANGLE_invocationVertexGlobals.gl_VertexID, ANGLE_userUniforms._uuGeoTexDim);
                           ^~~~~~~~~~~~~~~~~
program_source:377:15: note: candidate function
metal::float4 _ureadFromTexture(ANGLE_TextureEnv&lt;metal::texture2d&lt;float&gt;&gt; _utex, float _ui, metal::float2 _udim)
              ^
program_source:389:15: note: candidate function
metal::float4 _ureadFromTexture(ANGLE_TextureEnv&lt;metal::texture2d&lt;float&gt;&gt; _utex, int _ui, metal::float2 _udim)
---

It makes sense that `int(gl_VertexId)` works around the bug because that disambiguates the internal function call.

Surprising this didn&apos;t show up in the conformance tests.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1894180</commentid>
    <comment_count>3</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2022-08-26 23:38:15 -0700</bug_when>
    <thetext>&lt;rdar://problem/99218768&gt;</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>