summaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/swr/rasterizer
diff options
context:
space:
mode:
authorTim Rowley <[email protected]>2016-10-05 13:45:12 -0500
committerTim Rowley <[email protected]>2016-10-11 11:22:04 -0500
commit07326d4006245be761469a58e4dd41ef378f6c25 (patch)
tree184d6fa82cf3bcb1f7f3894b1b5dbed511d40326 /src/gallium/drivers/swr/rasterizer
parente845eeb0be89e3dcc62ae43a03f71336c26c40ed (diff)
swr: [rasterizer archrast] add mako template
Add template for generating code to save events to a file. Signed-off-by: Tim Rowley <[email protected]>
Diffstat (limited to 'src/gallium/drivers/swr/rasterizer')
-rw-r--r--src/gallium/drivers/swr/rasterizer/archrast/archrast.cpp9
-rw-r--r--src/gallium/drivers/swr/rasterizer/scripts/gen_archrast.py15
-rw-r--r--src/gallium/drivers/swr/rasterizer/scripts/templates/ar_eventhandlerfile_h.template84
3 files changed, 107 insertions, 1 deletions
diff --git a/src/gallium/drivers/swr/rasterizer/archrast/archrast.cpp b/src/gallium/drivers/swr/rasterizer/archrast/archrast.cpp
index 48dec28a105..b1c5134caf1 100644
--- a/src/gallium/drivers/swr/rasterizer/archrast/archrast.cpp
+++ b/src/gallium/drivers/swr/rasterizer/archrast/archrast.cpp
@@ -25,9 +25,12 @@
* @brief Definitions for archrast.
*
******************************************************************************/
+#include <atomic>
+
#include "common/os.h"
#include "archrast/archrast.h"
#include "archrast/eventmanager.h"
+#include "gen_ar_eventhandlerfile.h"
namespace ArchRast
{
@@ -39,8 +42,12 @@ namespace ArchRast
// Construct an event manager and associate a handler with it.
HANDLE CreateThreadContext()
{
+ // 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 EventHandler();
+ EventHandler* pHandler = new EventHandlerFile(id);
if (pManager && pHandler)
{
diff --git a/src/gallium/drivers/swr/rasterizer/scripts/gen_archrast.py b/src/gallium/drivers/swr/rasterizer/scripts/gen_archrast.py
index deb16bed8cd..1b89a91b8fd 100644
--- a/src/gallium/drivers/swr/rasterizer/scripts/gen_archrast.py
+++ b/src/gallium/drivers/swr/rasterizer/scripts/gen_archrast.py
@@ -103,6 +103,7 @@ def parse_protos(filename):
protos['enums'] = {}
protos['enum_names'] = []
+ eventId = 0
raw_text = []
while idx < len(lines):
line = lines[idx].rstrip()
@@ -112,10 +113,12 @@ def parse_protos(filename):
match = re.match(r"(\s*)event(\s*)(\w+)", line)
if match:
+ eventId += 1
event_name = match.group(3)
protos['event_names'].append(event_name)
protos['events'][event_name] = {}
+ protos['events'][event_name]['event_id'] = eventId
idx = parse_event_fields(lines, idx, protos['events'][event_name])
# search for enums.
@@ -139,6 +142,7 @@ def main():
parser.add_argument("--gen_event_h", "-geh", help="Generate event header", action="store_true", default=False)
parser.add_argument("--gen_event_cpp", "-gec", help="Generate event cpp", action="store_true", default=False)
parser.add_argument("--gen_eventhandler_h", "-gehh", help="Generate eventhandler header", action="store_true", default=False)
+ parser.add_argument("--gen_eventhandlerfile_h", "-gehf", help="Generate eventhandler header for writing to files", action="store_true", default=False)
args = parser.parse_args()
proto_filename = args.proto
@@ -188,6 +192,17 @@ def main():
event_header="gen_ar_event.h", # todo: fix this!
protos=protos)
+ # Generate event handler header
+ if args.gen_eventhandlerfile_h:
+ curdir = os.path.dirname(os.path.abspath(__file__))
+ template_file = os.sep.join([curdir, 'templates', 'ar_eventhandlerfile_h.template'])
+ output_fullpath = os.sep.join([output_dir, output_filename])
+
+ write_template_to_file(template_file, output_fullpath,
+ filename=output_filename,
+ event_header="gen_ar_eventhandler.h", # todo: fix this!
+ protos=protos)
+
return 0
if __name__ == '__main__':
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
new file mode 100644
index 00000000000..6264442b089
--- /dev/null
+++ b/src/gallium/drivers/swr/rasterizer/scripts/templates/ar_eventhandlerfile_h.template
@@ -0,0 +1,84 @@
+/****************************************************************************
+* Copyright (C) 2016 Intel Corporation. All Rights Reserved.
+*
+* Permission is hereby granted, free of charge, to any person obtaining a
+* copy of this software and associated documentation files (the "Software"),
+* to deal in the Software without restriction, including without limitation
+* the rights to use, copy, modify, merge, publish, distribute, sublicense,
+* and/or sell copies of the Software, and to permit persons to whom the
+* Software is furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice (including the next
+* paragraph) shall be included in all copies or substantial portions of the
+* Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+* IN THE SOFTWARE.
+*
+* @file ${filename}
+*
+* @brief Event handler interface. auto-generated file
+*
+* DO NOT EDIT
+*
+******************************************************************************/
+#pragma once
+
+#include "common/os.h"
+#include "${event_header}"
+#include <fstream>
+
+namespace ArchRast
+{
+ //////////////////////////////////////////////////////////////////////////
+ /// EventHandlerFile - interface for handling events.
+ //////////////////////////////////////////////////////////////////////////
+ class EventHandlerFile : public EventHandler
+ {
+ public:
+ EventHandlerFile(uint32_t id)
+ {
+#if defined(_WIN32)
+ char buf[255];
+ // There could be multiple threads creating thread pools. We
+ // want to make sure they are uniquly identified by adding in
+ // the creator's thread id into the filename.
+ sprintf(buf, "\\ar_event%d_%d.bin", GetCurrentThreadId(), id);
+ mFilename = std::string(buf);
+#else
+ SWR_ASSERT(0);
+#endif
+ }
+
+ ~EventHandlerFile()
+ {
+ if (mFile.is_open()) mFile.close();
+ }
+
+ void write(uint32_t eventId, const char* pBlock, uint32_t size)
+ {
+ if (!mFile.is_open())
+ {
+ mFile.open(mFilename, std::ios::out | std::ios::app | std::ios::binary);
+ }
+
+ mFile.write((char*)&eventId, sizeof(eventId));
+ mFile.write(pBlock, size);
+ }
+
+% for name in protos['event_names']:
+ virtual void handle(${name}& event)
+ {
+ write(${protos['events'][name]['event_id']}, (char*)&event, sizeof(event));
+ }
+% endfor
+
+ std::ofstream mFile;
+ std::string mFilename;
+ };
+}