Title: [248194] trunk/Source/WebCore
Revision
248194
Author
[email protected]
Date
2019-08-02 18:10:43 -0700 (Fri, 02 Aug 2019)

Log Message

[WHLSL] Avoid visiting the full AST in computeDimensions
https://bugs.webkit.org/show_bug.cgi?id=200410

Reviewed by Myles C. Maxfield.

Avoid visiting the full AST in computeDimensions
This cuts the time spent in computeDimensions on compute_boids.html from about 2ms to about 0.002ms.

No new tests as there is no functional change intended.

* Modules/webgpu/WHLSL/WHLSLComputeDimensions.cpp:
(WebCore::WHLSL::computeDimensions):
* Modules/webgpu/WHLSL/WHLSLPrepare.cpp:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (248193 => 248194)


--- trunk/Source/WebCore/ChangeLog	2019-08-03 00:49:41 UTC (rev 248193)
+++ trunk/Source/WebCore/ChangeLog	2019-08-03 01:10:43 UTC (rev 248194)
@@ -1,3 +1,19 @@
+2019-08-02  Robin Morisset  <[email protected]>
+
+        [WHLSL] Avoid visiting the full AST in computeDimensions
+        https://bugs.webkit.org/show_bug.cgi?id=200410
+
+        Reviewed by Myles C. Maxfield.
+
+        Avoid visiting the full AST in computeDimensions
+        This cuts the time spent in computeDimensions on compute_boids.html from about 2ms to about 0.002ms.
+
+        No new tests as there is no functional change intended.
+
+        * Modules/webgpu/WHLSL/WHLSLComputeDimensions.cpp:
+        (WebCore::WHLSL::computeDimensions):
+        * Modules/webgpu/WHLSL/WHLSLPrepare.cpp:
+
 2019-08-02  Ryosuke Niwa  <[email protected]>
 
         Ref Frame in DOMWindow::screen* functions

Modified: trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLComputeDimensions.cpp (248193 => 248194)


--- trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLComputeDimensions.cpp	2019-08-03 00:49:41 UTC (rev 248193)
+++ trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLComputeDimensions.cpp	2019-08-03 01:10:43 UTC (rev 248194)
@@ -38,50 +38,31 @@
 
 namespace WHLSL {
 
-class ComputeDimensionsVisitor : public Visitor {
-public:
-    ComputeDimensionsVisitor(AST::FunctionDefinition& entryPoint)
-        : m_entryPoint(entryPoint)
-    {
-    }
+Optional<ComputeDimensions> computeDimensions(Program& program, AST::FunctionDefinition& entryPoint)
+{
+    Optional<ComputeDimensions> computeDimensions;
 
-    virtual ~ComputeDimensionsVisitor() = default;
-
-    Optional<ComputeDimensions> computeDimensions() const { return m_computeDimensions; }
-
-private:
-    void visit(AST::FunctionDeclaration& functionDeclaration) override
-    {
+    for (auto& functionDefinition : program.functionDefinitions()) {
         bool foundNumThreadsFunctionAttribute = false;
-        for (auto& functionAttribute : functionDeclaration.attributeBlock()) {
+        for (auto& functionAttribute : functionDefinition->attributeBlock()) {
             auto success = WTF::visit(WTF::makeVisitor([&](AST::NumThreadsFunctionAttribute& numThreadsFunctionAttribute) {
                 if (foundNumThreadsFunctionAttribute)
                     return false;
                 foundNumThreadsFunctionAttribute = true;
-                if (&functionDeclaration == &m_entryPoint) {
-                    ASSERT(!m_computeDimensions);
-                    m_computeDimensions = {{ numThreadsFunctionAttribute.width(), numThreadsFunctionAttribute.height(), numThreadsFunctionAttribute.depth() }};
+                if (&functionDefinition == &entryPoint) {
+                    ASSERT(!computeDimensions);
+                    computeDimensions = {{ numThreadsFunctionAttribute.width(), numThreadsFunctionAttribute.height(), numThreadsFunctionAttribute.depth() }};
                 }
                 return true;
             }), functionAttribute);
             if (!success) {
-                setError(Error("Cannot declare multiple numthread attributes.", functionDeclaration.codeLocation()));
-                return;
+                // Cannot declare multiple numthread attributes on a single function.
+                return WTF::nullopt;
             }
         }
     }
 
-    AST::FunctionDefinition& m_entryPoint;
-    Optional<ComputeDimensions> m_computeDimensions;
-};
-
-Optional<ComputeDimensions> computeDimensions(Program& program, AST::FunctionDefinition& entryPoint)
-{
-    ComputeDimensionsVisitor computeDimensions(entryPoint);
-    computeDimensions.Visitor::visit(program);
-    if (computeDimensions.hasError())
-        return WTF::nullopt;
-    return computeDimensions.computeDimensions();
+    return computeDimensions;
 }
 
 } // namespace WHLSL
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to