<?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>219204</bug_id>
          
          <creation_ts>2020-11-20 07:29:48 -0800</creation_ts>
          <short_desc>Incorrect values of disabled (const) attribute when drawing with drawArraysInstanced / drawArrays</short_desc>
          <delta_ts>2022-03-14 03:58:38 -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 14</version>
          <rep_platform>iPhone / iPad</rep_platform>
          <op_sys>iOS 13</op_sys>
          <bug_status>ASSIGNED</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Major</bug_severity>
          <target_milestone>---</target_milestone>
          
          <blocked>126404</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Marcin">msokalski</reporter>
          <assigned_to name="Kimmo Kinnunen">kkinnunen</assigned_to>
          <cc>ap</cc>
    
    <cc>dino</cc>
    
    <cc>jdarpinian</cc>
    
    <cc>kbr</cc>
    
    <cc>kkinnunen</cc>
    
    <cc>kpiddington</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1709472</commentid>
    <comment_count>0</comment_count>
    <who name="Marcin">msokalski</who>
    <bug_when>2020-11-20 07:29:48 -0800</bug_when>
    <thetext>Problem occurs on iOS 14.2, Safari 14, iPhone SE (2017)
It works perfectly on iMac(27&quot; late 2013) Catalina 10.15.7, Safari 14.0

Using WebGL2 context, I have 3 attributes, 
2 are enabled and 1 is disabled in VAO.

#0 enabled  divisor = 1
#1 disabled divisor = 0
#2 enabled  divisor = 1

all other attributes are disabled and not used in shader program.


When drawing with drawArraysInstanced attribute #1 values, accessed in vertex shader, are invalid and vary. 
It should have a CONSTANT value set by ie: call to vertexAttrib4f().

Values of other two attributes (#0 and #2) are ok.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1709478</commentid>
    <comment_count>1</comment_count>
    <who name="Marcin">msokalski</who>
    <bug_when>2020-11-20 07:43:11 -0800</bug_when>
    <thetext>More complete attributes description:

#0 size = 4, type UBYTE, stride = 6, offset = 0 (contains x1,y1,x2,y2 coordinates of rectangle)
#2 size = 2, type UBYTE, strand = 6, offset = 4 (contains texture coordinates of lower-left corner)

shader reconstructs vertex coordinates by testing gl_VertexID

actual draw call:

gl.drawArraysInstanced(gl.TRIANGLE_STRIP, 0, 4, number_of_rectangles_in_vbo);</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1709514</commentid>
    <comment_count>2</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2020-11-20 09:37:11 -0800</bug_when>
    <thetext>Thank you for the report! Could you please attach a complete test case that demonstrates the problem?

Just to clarify, are you enabling WebGL 2.0 experimental feature in Safari for this work?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1709521</commentid>
    <comment_count>3</comment_count>
    <who name="Marcin">msokalski</who>
    <bug_when>2020-11-20 09:53:07 -0800</bug_when>
    <thetext>It would be hard to prepare isolated reproducer for you from my current code, you know, engine, wasm, assets etc...

But if I find some spare time on weekend I&apos;ll try to code something in pure JS for you.

Yes, of course, in order to use WebGL2 I enabled it in experimental features.
And I&apos;m patiently waiting for release with enabled WebGL2 by default. :)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1709686</commentid>
    <comment_count>4</comment_count>
    <who name="Kenneth Russell">kbr</who>
    <bug_when>2020-11-20 15:49:50 -0800</bug_when>
    <thetext>Several bugs have been fixed between the version of Safari you&apos;re testing and top-of-tree WebKit which probably affect these API calls. Please test on macOS with Safari Technology Preview 116, just released, which contains these bug fixes.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1709687</commentid>
    <comment_count>5</comment_count>
    <who name="Kenneth Russell">kbr</who>
    <bug_when>2020-11-20 15:54:08 -0800</bug_when>
    <thetext>Also, if you can provide any test case, perhaps dino or kkinnunen can confirm that it&apos;s working on top-of-tree on iOS.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1709867</commentid>
    <comment_count>6</comment_count>
    <who name="Marcin">msokalski</who>
    <bug_when>2020-11-23 00:56:49 -0800</bug_when>
    <thetext>OK, looks like I have something.

https://asciicker.com/tests/test2.html

It should render color cycling squares.
On my iPhone all are simply white.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1709872</commentid>
    <comment_count>7</comment_count>
    <who name="Marcin">msokalski</who>
    <bug_when>2020-11-23 02:05:15 -0800</bug_when>
    <thetext>Also, now I&apos;m wondering what could cause such problem,
actual hardware, driver, ANGLE (I don&apos;t know if you use it) or the browser?

Are you aware of any method helping me to figure it out?

Thanks, 
Marcin.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1709911</commentid>
    <comment_count>8</comment_count>
    <who name="James Darpinian">jdarpinian</who>
    <bug_when>2020-11-23 09:54:00 -0800</bug_when>
    <thetext>It works for me on the iOS simulator with WebKit built from source at HEAD. I don&apos;t have a way to test on real hardware, but I think it is likely to be something we already fixed since the Safari 14 branch.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1709914</commentid>
    <comment_count>9</comment_count>
    <who name="Marcin">msokalski</who>
    <bug_when>2020-11-23 10:04:26 -0800</bug_when>
    <thetext>Yes, hopefully.
So if the test made in simulator using older branch is failing, that would confirm it is indeed solved, right?

Thanks</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1709915</commentid>
    <comment_count>10</comment_count>
    <who name="James Darpinian">jdarpinian</who>
    <bug_when>2020-11-23 10:05:37 -0800</bug_when>
    <thetext>Yes, I think that would confirm it. Thank you for testing early!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1709925</commentid>
    <comment_count>11</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2020-11-23 11:26:25 -0800</bug_when>
    <thetext>This still reproduces for me on device with a two week old WebKit (r269643). This could have been fixed since then, but probably worth another look.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1709934</commentid>
    <comment_count>12</comment_count>
    <who name="James Darpinian">jdarpinian</who>
    <bug_when>2020-11-23 12:31:19 -0800</bug_when>
    <thetext>Hmm, perhaps it is hardware specific then. I just tried to do a MacCatalyst and/or iOS simulator build of WebKit on Apple Silicon but couldn&apos;t get it to work, likely due to not having access to internal SDKs. I think only Apple can test this right now, until WebKit&apos;s Apple Silicon builds are fixed to work without internal SDKs.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1709950</commentid>
    <comment_count>13</comment_count>
    <who name="Kenneth Russell">kbr</who>
    <bug_when>2020-11-23 16:52:10 -0800</bug_when>
    <thetext>Kimmo, could you help reproduce this on ToT WebKit on hardware? If there&apos;s a bug in ANGLE we&apos;d love to resolve it as soon as possible. Thanks.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1709983</commentid>
    <comment_count>14</comment_count>
    <who name="Kimmo Kinnunen">kkinnunen</who>
    <bug_when>2020-11-24 05:02:59 -0800</bug_when>
    <thetext>Thanks for the report!

The test case works in
ToT WebKit Mac
The test cas fails in
ToT WebKit iPhone 12 14.2
ToT WebKit iPhone 11 14.2
ToT WebKit iPhone 10 14.2

It&apos;s unclear if it worked on iOS 14.0/14.1

I can further try to reduce the test case.

It appears that when the value set by the vertexAttrib4f() is accessed in the fragment shader, the whole expression becomes 1.0.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1709985</commentid>
    <comment_count>15</comment_count>
    <who name="Marcin">msokalski</who>
    <bug_when>2020-11-24 05:24:23 -0800</bug_when>
    <thetext>Thanks Kimmo!

I found some weird fix to the test case,
if you change attribute index (used by &apos;tex&apos; attribute) from 4 to 2, (making no gaps in active attributes) everything starts to work!

lines: 10, 144,145,146

Hope that helps to narrow the thing.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1709987</commentid>
    <comment_count>16</comment_count>
    <who name="Kimmo Kinnunen">kkinnunen</who>
    <bug_when>2020-11-24 05:37:21 -0800</bug_when>
    <thetext>&gt; if you change attribute index (used by &apos;tex&apos; attribute) from 4 to 2, (making no gaps in active attributes) everything starts to work!

Nice catch! This is especially surprising since 

Works:
        layout(location = 0) in vec4 rect;  // x1,y1,x2,y2
        layout(location = 1) in vec4 color; // r,g,b,a
        layout(location = 2) in vec4 tex;

Does not work:
        layout(location = 0) in vec4 rect;  // x1,y1,x2,y2
        layout(location = 2) in vec4 color; // r,g,b,a
        layout(location = 1) in vec4 tex;

E.g. no gaps, but if the constant attribute is the last one, it does not work.. or I made a typo</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1709990</commentid>
    <comment_count>17</comment_count>
    <who name="Marcin">msokalski</who>
    <bug_when>2020-11-24 05:47:46 -0800</bug_when>
    <thetext>Made same attrib index swizzling here (0,2,1), also fails! -- really strange.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1710016</commentid>
    <comment_count>18</comment_count>
    <who name="Kenneth Russell">kbr</who>
    <bug_when>2020-11-24 12:28:39 -0800</bug_when>
    <thetext>Great diagnosis Kimmo. Could you ask Apple&apos;s OpenGL ES on iOS team about this bug? It seems difficult or impossible to postulate a workaround in ANGLE for this driver bug. Reordering the declarations in the shader seems the only option, but it&apos;s unclear whether that would work, given the nature of this bug.

Raising to Major severity and blocking Bug 126404 on this one - an unknown number of WebGL 2.0 applications might be broken by this bug.

I wonder whether ANGLE&apos;s Metal backend already implicitly fixes this issue.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1710146</commentid>
    <comment_count>19</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2020-11-26 03:29:23 -0800</bug_when>
    <thetext>&lt;rdar://problem/71747873&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1736393</commentid>
    <comment_count>20</comment_count>
    <who name="Marcin">msokalski</who>
    <bug_when>2021-03-05 10:04:21 -0800</bug_when>
    <thetext>FYI, in effort to move away from instancedDraw calls (because of this issue and Issue 218949), I found out that same problem occurs with regular drawArrays as well. Changing attributes indexes (avoid gaps, keep last active attribute enabled) works around the problem so far, phew.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1736743</commentid>
    <comment_count>21</comment_count>
    <who name="Kenneth Russell">kbr</who>
    <bug_when>2021-03-05 20:56:42 -0800</bug_when>
    <thetext>Hopefully this will be automatically fixed with the new Metal backend for ANGLE - it should not be subject to this kind of OpenGL ES driver bug. Confirmation would be great, though.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1850824</commentid>
    <comment_count>22</comment_count>
    <who name="Marcin">msokalski</who>
    <bug_when>2022-03-14 03:58:38 -0700</bug_when>
    <thetext>Confirmed - bug is fixed on iOS 15.3.1</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>