<?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>278452</bug_id>
          
          <creation_ts>2024-08-21 00:35:46 -0700</creation_ts>
          <short_desc>REGRESSION(282012@main): [GTK][WPE][Skia] Crash using threaded rendering</short_desc>
          <delta_ts>2024-08-30 00:12:10 -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>WebKitGTK</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Miguel Gomez">magomez</reporter>
          <assigned_to name="Nikolas Zimmermann">zimmermann</assigned_to>
          <cc>akeerthi</cc>
    
    <cc>bugs-noreply</cc>
    
    <cc>cgarcia</cc>
    
    <cc>fujii</cc>
    
    <cc>mcatanzaro</cc>
    
    <cc>sabouhallawa</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2054364</commentid>
    <comment_count>0</comment_count>
    <who name="Miguel Gomez">magomez</who>
    <bug_when>2024-08-21 00:35:46 -0700</bug_when>
    <thetext>The threaded rendering option is used by both GTK and WPE when using the skia cpu backend. This option uses DisplayLists to record the commands required to render each of the GraphicsLayer tiles, and then uses some rendering threads to replay those commands. Since 282012@main, we&apos;re getting a random crash during the replay stage of the rendering.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2054375</commentid>
    <comment_count>1</comment_count>
    <who name="Miguel Gomez">magomez</who>
    <bug_when>2024-08-21 02:16:30 -0700</bug_when>
    <thetext>What we&apos;re doing in both GTK and WPE is recording the commands needed to render the GraphicsLayer contents on the main thread, and then replaying them in some secondary renderer threads.

The code that does this is CoordinatedGraphicsLayer::paintTile() in CoordinatedGraphicsLayerSkia.cpp. We&apos;re creating the recording context with

auto recordingContext = makeUnique&lt;DisplayList::DrawingContext&gt;(tileRect.size());

And then moving that recordingContext to the renderer thread and replaying it with

recordingContext-&gt;replayDisplayList(context);


I think the problem is that non Apple platforms were always receiving nullptr when trying to get a ControlFactory, but they are now receiving the new EmptyControlFactory. But EmptyControlFactory is not a thread safe object and it&apos;s intended to be used on the main thread only, and I&apos;m seeing calls to ControlFactory::shared() that are happening inside the rendering threads (in the Replayer constructor).

Probably just forcing GTK and WPE to return nullptr when trying to get ControlFactory would fix our problem, but I&apos;d like to try to understand how is the feature intended to work before doing any change.

So I&apos;m not sure what&apos;s exactly the problem here:
- Isn&apos;t DisplayList replay in threads not supported? The current implementation with the new EmptyControlFactory seems to suggest so.
- Maybe in order to replay in threads we need to use a RemoteDisplayListRecorder, which don&apos;t use the shared ControlFactory, but a new one?
- Is replaying in threads supported but this is a bug in how ControlFactory is handled? Can&apos;t ControlFactory be made thread safe? Is there any platform limitation for this?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2054418</commentid>
    <comment_count>2</comment_count>
    <who name="Aditya Keerthi">akeerthi</who>
    <bug_when>2024-08-21 09:01:45 -0700</bug_when>
    <thetext>Correct, `ControlFactory` is not thread-safe due to platform limitations. The members that a control factory holds are platform objects which themselves are not thread-safe.

Also correct that we create a `ControlFactory` per `RemoteDisplayListRecorder`, which is tied a given `RemoteRenderingBackend` thread.

You may also be able to get away with using `std::call_once` when creating the factory, as `EmptyControlFactory` doesn&apos;t actually contain any logic? However, it would be ideal to create a unique factory per thread, as intended.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2054420</commentid>
    <comment_count>3</comment_count>
    <who name="Aditya Keerthi">akeerthi</who>
    <bug_when>2024-08-21 09:03:41 -0700</bug_when>
    <thetext>282012@main itself fixed a thread safety issue where the shared factory was being used on multiple threads.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2054550</commentid>
    <comment_count>4</comment_count>
    <who name="Fujii Hironori">fujii</who>
    <bug_when>2024-08-21 15:49:30 -0700</bug_when>
    <thetext>282487@main introduced ControlFactoryAdwaita. GTK and WPE no longer creates EmptyControlFactory.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2056403</commentid>
    <comment_count>5</comment_count>
    <who name="Nikolas Zimmermann">zimmermann</who>
    <bug_when>2024-08-29 15:23:29 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/32911</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2056483</commentid>
    <comment_count>6</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2024-08-30 00:12:06 -0700</bug_when>
    <thetext>Committed 282951@main (e46ab4de36b4): &lt;https://commits.webkit.org/282951@main&gt;

Reviewed commits have been landed. Closing PR #32911 and removing active labels.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>