From: Tim Rowley Date: Mon, 31 Oct 2016 00:27:07 +0000 (-0500) Subject: swr: [rasterizer archrast] don't generate empty files X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=584b65ad442f8219c0216961641d4b9f4a1671da;p=mesa.git swr: [rasterizer archrast] don't generate empty files Don't generate files when no events have been generated outside the header events. Reviewed-by: Bruce Cherniak --- diff --git a/src/gallium/drivers/swr/rasterizer/archrast/archrast.cpp b/src/gallium/drivers/swr/rasterizer/archrast/archrast.cpp index 574098d80a8..16b6d3347ac 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 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 e6376f208fe..4783144fcb5 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 542eccda95e..bf7a9f606f5 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 97eca59f564..ada134d01c3 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}; }; }