[Mesa-dev] [PATCH 06/14] swr: [rasterizer archrast] don't generate empty files

Tim Rowley timothy.o.rowley at intel.com
Thu Nov 10 03:18:40 UTC 2016


Don't generate files when no events have been generated outside
the header events.
---
 .../drivers/swr/rasterizer/archrast/archrast.cpp        | 16 ++++++++++++++--
 src/gallium/drivers/swr/rasterizer/archrast/archrast.h  |  8 +++++++-
 src/gallium/drivers/swr/rasterizer/core/api.cpp         |  6 ++----
 .../scripts/templates/ar_eventhandlerfile_h.template    | 17 ++++++++++++++++-
 4 files changed, 39 insertions(+), 8 deletions(-)

diff --git a/src/gallium/drivers/swr/rasterizer/archrast/archrast.cpp b/src/gallium/drivers/swr/rasterizer/archrast/archrast.cpp
index 574098d..16b6d33 100644
--- a/src/gallium/drivers/swr/rasterizer/archrast/archrast.cpp
+++ b/src/gallium/drivers/swr/rasterizer/archrast/archrast.cpp
@@ -53,19 +53,31 @@ namespace ArchRast
     }
 
     // Construct an event manager and associate a handler with it.
-    HANDLE CreateThreadContext()
+    HANDLE CreateThreadContext(AR_THREAD type)
     {
         // Can we assume single threaded here?
         static std::atomic<uint32_t> counter(0);
         uint32_t id = counter.fetch_add(1);
 
         EventManager* pManager = new EventManager();
-        EventHandler* pHandler = new EventHandlerStatsFile(id);
+        EventHandlerFile* pHandler = new EventHandlerStatsFile(id);
 
         if (pManager && pHandler)
         {
             pManager->Attach(pHandler);
 
+            if (type == AR_THREAD::API)
+            {
+                ThreadStartApiEvent e;
+                pManager->Dispatch(e);
+            }
+            else
+            {
+                ThreadStartWorkerEvent e;
+                pManager->Dispatch(e);
+            }
+            pHandler->MarkHeader();
+
             return pManager;
         }
 
diff --git a/src/gallium/drivers/swr/rasterizer/archrast/archrast.h b/src/gallium/drivers/swr/rasterizer/archrast/archrast.h
index e6376f2..4783144 100644
--- a/src/gallium/drivers/swr/rasterizer/archrast/archrast.h
+++ b/src/gallium/drivers/swr/rasterizer/archrast/archrast.h
@@ -32,7 +32,13 @@
 
 namespace ArchRast
 {
-    HANDLE CreateThreadContext();
+    enum class AR_THREAD
+    {
+        API = 0,
+        WORKER = 1
+    };
+
+    HANDLE CreateThreadContext(AR_THREAD type);
     void DestroyThreadContext(HANDLE hThreadContext);
 
     // Dispatch event for this thread.
diff --git a/src/gallium/drivers/swr/rasterizer/core/api.cpp b/src/gallium/drivers/swr/rasterizer/core/api.cpp
index 542eccd..bf7a9f6 100644
--- a/src/gallium/drivers/swr/rasterizer/core/api.cpp
+++ b/src/gallium/drivers/swr/rasterizer/core/api.cpp
@@ -115,8 +115,7 @@ HANDLE SwrCreateContext(
 #if defined(KNOB_ENABLE_AR)
     // Setup ArchRast thread contexts which includes +1 for API thread.
     pContext->pArContext = new HANDLE[pContext->NumWorkerThreads+1];
-    pContext->pArContext[pContext->NumWorkerThreads] = ArchRast::CreateThreadContext();
-    _AR_EVENT(pContext->pArContext[pContext->NumWorkerThreads], ThreadStartApiEvent());
+    pContext->pArContext[pContext->NumWorkerThreads] = ArchRast::CreateThreadContext(ArchRast::AR_THREAD::API);
 #endif
 
     // Allocate scratch space for workers.
@@ -136,8 +135,7 @@ HANDLE SwrCreateContext(
 
 #if defined(KNOB_ENABLE_AR)
         // Initialize worker thread context for ArchRast.
-        pContext->pArContext[i] = ArchRast::CreateThreadContext();
-        _AR_EVENT(pContext->pArContext[i], ThreadStartWorkerEvent());
+        pContext->pArContext[i] = ArchRast::CreateThreadContext(ArchRast::AR_THREAD::WORKER);
 #endif
     }
 
diff --git a/src/gallium/drivers/swr/rasterizer/scripts/templates/ar_eventhandlerfile_h.template b/src/gallium/drivers/swr/rasterizer/scripts/templates/ar_eventhandlerfile_h.template
index 97eca59..ada134d 100644
--- a/src/gallium/drivers/swr/rasterizer/scripts/templates/ar_eventhandlerfile_h.template
+++ b/src/gallium/drivers/swr/rasterizer/scripts/templates/ar_eventhandlerfile_h.template
@@ -81,6 +81,12 @@ namespace ArchRast
         {
             if (mBufOffset > 0)
             {
+                if (mBufOffset == mHeaderBufOffset)
+                {
+                    // Nothing to flush. Only header has been generated.
+                    return false;
+                }
+
                 std::ofstream file;
                 file.open(mFilename, std::ios::out | std::ios::app | std::ios::binary);
 
@@ -94,6 +100,7 @@ namespace ArchRast
                 file.close();
 
                 mBufOffset = 0;
+                mHeaderBufOffset = 0; // Reset header offset so its no longer considered.
             }
             return true;
         }
@@ -121,7 +128,7 @@ namespace ArchRast
 % for name in protos['event_names']:
         //////////////////////////////////////////////////////////////////////////
         /// @brief Handle ${name} event
-        virtual void Handle(${name}& event)
+        virtual void Handle(${name}&& event)
         {
 % if protos['events'][name]['num_fields'] == 0:
             Write(${protos['events'][name]['event_id']}, (char*)&event.data, 0);
@@ -131,10 +138,18 @@ namespace ArchRast
         }
 % endfor
 
+        //////////////////////////////////////////////////////////////////////////
+        /// @brief Everything written to buffer this point is the header.
+        virtual void MarkHeader()
+        {
+            mHeaderBufOffset = mBufOffset;
+        }
+
         std::string mFilename;
 
         static const uint32_t mBufferSize = 1024;
         uint8_t mBuffer[mBufferSize];
         uint32_t mBufOffset{0};
+        uint32_t mHeaderBufOffset{0};
     };
 }
-- 
2.7.4



More information about the mesa-dev mailing list