swr/rast: Refactor api and worker event handlers.
authorGeorge Kyriazis <george.kyriazis@intel.com>
Mon, 26 Feb 2018 21:19:08 +0000 (15:19 -0600)
committerGeorge Kyriazis <george.kyriazis@intel.com>
Fri, 9 Mar 2018 15:35:59 +0000 (09:35 -0600)
In the API event handler we want to share information between the core
layer and the API. Specifically, around associating various ids with
different kinds of events. For example, associate render pass id with
draw ids, or command buffer ids with draw ids.

Reviewed-by: Bruce Cherniak <bruce.cherniak@intel.com>
src/gallium/drivers/swr/rasterizer/archrast/archrast.cpp
src/gallium/drivers/swr/rasterizer/archrast/eventmanager.h

index 0728a85e020189d86d65417bc08c7104911b7c01..d5cffbb5cec1604f7745b7828cee13f0c19e51c3 100644 (file)
@@ -74,12 +74,52 @@ namespace ArchRast
     };
 
     //////////////////////////////////////////////////////////////////////////
-    /// @brief Event handler that saves stat events to event files. This
-    ///        handler filters out unwanted events.
-    class EventHandlerStatsFile : public EventHandlerFile
+    /// @brief Event handler that handles API thread events. This is shared
+    ///        between the API and its caller (e.g. driver shim) but typically
+    ///        there is only a single API thread per context. So you can save
+    ///        information in the class to be used for other events.
+    class EventHandlerApiStats : public EventHandlerFile
     {
     public:
-        EventHandlerStatsFile(uint32_t id) : EventHandlerFile(id), mNeedFlush(false) {}
+        EventHandlerApiStats(uint32_t id) : EventHandlerFile(id) {}
+
+        virtual void Handle(const DrawInstancedEvent& event)
+        {
+            DrawInfoEvent e(event.data.drawId, ArchRast::Instanced, event.data.topology, event.data.numVertices, 0, 0, event.data.startVertex, event.data.numInstances, event.data.startInstance);
+
+            EventHandlerFile::Handle(e);
+        }
+
+        virtual void Handle(const DrawIndexedInstancedEvent& event)
+        {
+            DrawInfoEvent e(event.data.drawId, ArchRast::IndexedInstanced, event.data.topology, 0, event.data.numIndices, event.data.indexOffset, event.data.baseVertex, event.data.numInstances, event.data.startInstance);
+
+            EventHandlerFile::Handle(e);
+        }
+
+        virtual void Handle(const DrawInstancedSplitEvent& event)
+        {
+            DrawInfoEvent e(event.data.drawId, ArchRast::InstancedSplit, 0, 0, 0, 0, 0, 0, 0);
+
+            EventHandlerFile::Handle(e);
+        }
+
+        virtual void Handle(const DrawIndexedInstancedSplitEvent& event)
+        {
+            DrawInfoEvent e(event.data.drawId, ArchRast::IndexedInstancedSplit, 0, 0, 0, 0, 0, 0, 0);
+
+            EventHandlerFile::Handle(e);
+        }
+    };
+
+    //////////////////////////////////////////////////////////////////////////
+    /// @brief Event handler that handles worker thread events. There is one
+    ///        event handler per thread. The python script will need to sum
+    ///        up counters across all of the threads.
+    class EventHandlerWorkerStats : public EventHandlerFile
+    {
+    public:
+        EventHandlerWorkerStats(uint32_t id) : EventHandlerFile(id), mNeedFlush(false) {}
 
         virtual void Handle(const EarlyDepthStencilInfoSingleSample& event)
         {
@@ -215,34 +255,6 @@ namespace ArchRast
             mClipper.trivialAcceptCount += _mm_popcnt_u32(event.data.validMask & ~event.data.clipMask);
         }
 
-        virtual void Handle(const DrawInstancedEvent& event)
-        {
-            DrawInfoEvent e(event.data.drawId, ArchRast::Instanced, event.data.topology, event.data.numVertices, 0, 0, event.data.startVertex, event.data.numInstances, event.data.startInstance);
-
-            EventHandlerFile::Handle(e);
-        }
-
-        virtual void Handle(const DrawIndexedInstancedEvent& event)
-        {
-            DrawInfoEvent e(event.data.drawId, ArchRast::IndexedInstanced, event.data.topology, 0, event.data.numIndices, event.data.indexOffset, event.data.baseVertex, event.data.numInstances, event.data.startInstance);
-
-            EventHandlerFile::Handle(e);
-        }
-
-        virtual void Handle(const DrawInstancedSplitEvent& event)
-        {
-            DrawInfoEvent e(event.data.drawId, ArchRast::InstancedSplit, 0, 0, 0, 0, 0, 0, 0);
-
-            EventHandlerFile::Handle(e);
-        }
-
-        virtual void Handle(const DrawIndexedInstancedSplitEvent& event)
-        {
-            DrawInfoEvent e(event.data.drawId, ArchRast::IndexedInstancedSplit, 0, 0, 0, 0, 0, 0, 0);
-
-            EventHandlerFile::Handle(e);
-        }
-
         // Flush cached events for this draw
         virtual void FlushDraw(uint32_t drawId)
         {
@@ -354,20 +366,24 @@ namespace ArchRast
         uint32_t id = counter.fetch_add(1);
 
         EventManager* pManager = new EventManager();
-        EventHandlerFile* pHandler = new EventHandlerStatsFile(id);
 
-        if (pManager && pHandler)
+        if (pManager)
         {
-            pManager->Attach(pHandler);
+            EventHandlerFile* pHandler = nullptr;
 
             if (type == AR_THREAD::API)
             {
+                pHandler = new EventHandlerApiStats(id);
+                pManager->Attach(pHandler);
                 pHandler->Handle(ThreadStartApiEvent());
             }
             else
             {
+                pHandler = new EventHandlerWorkerStats(id);
+                pManager->Attach(pHandler);
                 pHandler->Handle(ThreadStartWorkerEvent());
             }
+
             pHandler->MarkHeader();
 
             return pManager;
index c251daf036197eae29be250385aa9dfe07b5a110..10e0dce6ad9649b5a9b0fb8adb952ede24284605 100644 (file)
@@ -57,6 +57,7 @@ namespace ArchRast
 
         void Attach(EventHandler* pHandler)
         {
+            SWR_ASSERT(pHandler != nullptr);
             mHandlers.push_back(pHandler);
         }