From 0420b2be89a4023eb6c1b45740d98184bb77e7cd Mon Sep 17 00:00:00 2001
From: George Kyriazis <george.kyriazis@intel.com>
Date: Wed, 31 Jan 2018 01:09:53 -0600
Subject: swr/rast: Separate event types to public and private

Split into two proto files and modify appropriate build rules for
configure / scons / meson builds.

There are private internal events (proxy) that communicate information
from rasterizer to ArchRast. ArchRast can use these events to calculate
a final answer and then emit other public events which will be saved to
file. Users will use the public proto file and not the private one.

Reviewed-by: Bruce Cherniak <bruce.cherniak@intel.com>
---
 src/gallium/drivers/swr/Makefile.am                |  18 ++--
 src/gallium/drivers/swr/SConscript                 |  17 +++-
 src/gallium/drivers/swr/meson.build                |   1 +
 .../drivers/swr/rasterizer/archrast/events.proto   |  96 ------------------
 .../swr/rasterizer/archrast/events_private.proto   | 109 +++++++++++++++++++++
 .../drivers/swr/rasterizer/codegen/gen_archrast.py |  25 +++--
 .../drivers/swr/rasterizer/codegen/meson.build     |   8 +-
 7 files changed, 155 insertions(+), 119 deletions(-)
 create mode 100644 src/gallium/drivers/swr/rasterizer/archrast/events_private.proto

(limited to 'src/gallium/drivers/swr')

diff --git a/src/gallium/drivers/swr/Makefile.am b/src/gallium/drivers/swr/Makefile.am
index 2bc129429c6..869eec16d82 100644
--- a/src/gallium/drivers/swr/Makefile.am
+++ b/src/gallium/drivers/swr/Makefile.am
@@ -140,37 +140,41 @@ rasterizer/jitter/gen_builder_x86.hpp: rasterizer/codegen/gen_llvm_ir_macros.py
 		--output rasterizer/jitter \
 		--gen_x86_h
 
-rasterizer/archrast/gen_ar_event.hpp: rasterizer/codegen/gen_archrast.py rasterizer/codegen/templates/gen_ar_event.hpp rasterizer/archrast/events.proto rasterizer/codegen/gen_common.py
+rasterizer/archrast/gen_ar_event.hpp: rasterizer/codegen/gen_archrast.py rasterizer/codegen/templates/gen_ar_event.hpp rasterizer/archrast/events.proto rasterizer/archrast/events_private.proto rasterizer/codegen/gen_common.py
 	$(MKDIR_GEN)
 	$(PYTHON_GEN) \
 		$(srcdir)/rasterizer/codegen/gen_archrast.py \
 		--proto $(srcdir)/rasterizer/archrast/events.proto \
+		--proto_private $(srcdir)/rasterizer/archrast/events_private.proto \
 		--output rasterizer/archrast/gen_ar_event.hpp \
-		--gen_event_h
+		--gen_event_hpp
 
-rasterizer/archrast/gen_ar_event.cpp: rasterizer/codegen/gen_archrast.py rasterizer/codegen/templates/gen_ar_event.cpp rasterizer/archrast/events.proto rasterizer/codegen/gen_common.py
+rasterizer/archrast/gen_ar_event.cpp: rasterizer/codegen/gen_archrast.py rasterizer/codegen/templates/gen_ar_event.cpp rasterizer/archrast/events.proto rasterizer/archrast/events_private.proto rasterizer/codegen/gen_common.py
 	$(MKDIR_GEN)
 	$(PYTHON_GEN) \
 		$(srcdir)/rasterizer/codegen/gen_archrast.py \
 		--proto $(srcdir)/rasterizer/archrast/events.proto \
+		--proto_private $(srcdir)/rasterizer/archrast/events_private.proto \
 		--output rasterizer/archrast/gen_ar_event.cpp \
 		--gen_event_cpp
 
-rasterizer/archrast/gen_ar_eventhandler.hpp: rasterizer/codegen/gen_archrast.py rasterizer/codegen/templates/gen_ar_eventhandler.hpp rasterizer/archrast/events.proto rasterizer/codegen/gen_common.py
+rasterizer/archrast/gen_ar_eventhandler.hpp: rasterizer/codegen/gen_archrast.py rasterizer/codegen/templates/gen_ar_eventhandler.hpp rasterizer/archrast/events.proto rasterizer/archrast/events_private.proto rasterizer/codegen/gen_common.py
 	$(MKDIR_GEN)
 	$(PYTHON_GEN) \
 		$(srcdir)/rasterizer/codegen/gen_archrast.py \
 		--proto $(srcdir)/rasterizer/archrast/events.proto \
+		--proto_private $(srcdir)/rasterizer/archrast/events_private.proto \
 		--output rasterizer/archrast/gen_ar_eventhandler.hpp \
-		--gen_eventhandler_h
+		--gen_eventhandler_hpp
 
-rasterizer/archrast/gen_ar_eventhandlerfile.hpp: rasterizer/codegen/gen_archrast.py rasterizer/codegen/templates/gen_ar_eventhandlerfile.hpp rasterizer/archrast/events.proto rasterizer/codegen/gen_common.py
+rasterizer/archrast/gen_ar_eventhandlerfile.hpp: rasterizer/codegen/gen_archrast.py rasterizer/codegen/templates/gen_ar_eventhandlerfile.hpp rasterizer/archrast/events.proto rasterizer/archrast/events_private.proto rasterizer/codegen/gen_common.py
 	$(MKDIR_GEN)
 	$(PYTHON_GEN) \
 		$(srcdir)/rasterizer/codegen/gen_archrast.py \
 		--proto $(srcdir)/rasterizer/archrast/events.proto \
+		--proto_private $(srcdir)/rasterizer/archrast/events_private.proto \
 		--output rasterizer/archrast/gen_ar_eventhandlerfile.hpp \
-		--gen_eventhandlerfile_h
+		--gen_eventhandlerfile_hpp
 
 rasterizer/core/backends/gen_BackendPixelRate0.cpp \
 rasterizer/core/backends/gen_BackendPixelRate1.cpp \
diff --git a/src/gallium/drivers/swr/SConscript b/src/gallium/drivers/swr/SConscript
index eca4830c249..cc9c9e9a024 100644
--- a/src/gallium/drivers/swr/SConscript
+++ b/src/gallium/drivers/swr/SConscript
@@ -36,6 +36,7 @@ if not env['msvc'] :
     ])
 
 swrroot = '#src/gallium/drivers/swr/'
+srcroot = Dir(swrroot).abspath
 bldroot = Dir('.').abspath
 
 env.CodeGenerate(
@@ -96,8 +97,10 @@ env.CodeGenerate(
     target = 'rasterizer/archrast/gen_ar_event.hpp',
     script = swrroot + 'rasterizer/codegen/gen_archrast.py',
     source = 'rasterizer/archrast/events.proto',
-    command = python_cmd + ' $SCRIPT --proto $SOURCE --output $TARGET --gen_event_h'
+    command = python_cmd + ' $SCRIPT --proto $SOURCE --proto_private ' + srcroot + '/rasterizer/archrast/events_private.proto --output $TARGET --gen_event_hpp'
 )
+Depends('rasterizer/archrast/gen_ar_event.hpp',
+        swrroot + 'rasterizer/archrast/events_private.proto')
 Depends('rasterizer/jitter/gen_state_llvm.h',
         swrroot + 'rasterizer/codegen/templates/gen_ar_event.hpp')
 
@@ -105,8 +108,10 @@ env.CodeGenerate(
     target = 'rasterizer/archrast/gen_ar_event.cpp',
     script = swrroot + 'rasterizer/codegen/gen_archrast.py',
     source = 'rasterizer/archrast/events.proto',
-    command = python_cmd + ' $SCRIPT --proto $SOURCE --output $TARGET --gen_event_cpp'
+    command = python_cmd + ' $SCRIPT --proto $SOURCE --proto_private ' + srcroot + '/rasterizer/archrast/events_private.proto --output $TARGET --gen_event_cpp'
 )
+Depends('rasterizer/archrast/gen_ar_event.cpp',
+        swrroot + 'rasterizer/archrast/events_private.proto')
 Depends('rasterizer/jitter/gen_state_llvm.h',
         swrroot + 'rasterizer/codegen/templates/gen_ar_event.cpp')
 
@@ -114,8 +119,10 @@ env.CodeGenerate(
     target = 'rasterizer/archrast/gen_ar_eventhandler.hpp',
     script = swrroot + 'rasterizer/codegen/gen_archrast.py',
     source = 'rasterizer/archrast/events.proto',
-    command = python_cmd + ' $SCRIPT --proto $SOURCE --output $TARGET --gen_eventhandler_h'
+    command = python_cmd + ' $SCRIPT --proto $SOURCE --proto_private ' + srcroot + '/rasterizer/archrast/events_private.proto --output $TARGET --gen_eventhandler_hpp'
 )
+Depends('rasterizer/archrast/gen_ar_eventhandler.hpp',
+        swrroot + 'rasterizer/archrast/events_private.proto')
 Depends('rasterizer/jitter/gen_state_llvm.h',
         swrroot + 'rasterizer/codegen/templates/gen_ar_eventhandler.hpp')
 
@@ -123,8 +130,10 @@ env.CodeGenerate(
     target = 'rasterizer/archrast/gen_ar_eventhandlerfile.hpp',
     script = swrroot + 'rasterizer/codegen/gen_archrast.py',
     source = 'rasterizer/archrast/events.proto',
-    command = python_cmd + ' $SCRIPT --proto $SOURCE --output $TARGET --gen_eventhandlerfile_h'
+    command = python_cmd + ' $SCRIPT --proto $SOURCE --proto_private ' + srcroot + '/rasterizer/archrast/events_private.proto --output $TARGET --gen_eventhandlerfile_hpp'
 )
+Depends('rasterizer/archrast/gen_ar_eventhandlerfile.hpp',
+        swrroot + 'rasterizer/archrast/events_private.proto')
 Depends('rasterizer/jitter/gen_state_llvm.h',
         swrroot + 'rasterizer/codegen/templates/gen_ar_eventhandlerfile.hpp')
 
diff --git a/src/gallium/drivers/swr/meson.build b/src/gallium/drivers/swr/meson.build
index a527d5ced19..4bcd4f4e388 100644
--- a/src/gallium/drivers/swr/meson.build
+++ b/src/gallium/drivers/swr/meson.build
@@ -151,6 +151,7 @@ files_swr_arch = files(
 swr_context_files = files('swr_context.h')
 swr_state_files = files('rasterizer/core/state.h')
 swr_event_proto_files = files('rasterizer/archrast/events.proto')
+swr_event_pproto_files = files('rasterizer/archrast/events_private.proto')
 swr_gen_backend_files = files('rasterizer/codegen/templates/gen_backend.cpp')
 swr_gen_rasterizer_files = files('rasterizer/codegen/templates/gen_rasterizer.cpp')
 swr_gen_header_init_files = files('rasterizer/codegen/templates/gen_header_init.hpp')
diff --git a/src/gallium/drivers/swr/rasterizer/archrast/events.proto b/src/gallium/drivers/swr/rasterizer/archrast/events.proto
index 68773270f30..f9be5844333 100644
--- a/src/gallium/drivers/swr/rasterizer/archrast/events.proto
+++ b/src/gallium/drivers/swr/rasterizer/archrast/events.proto
@@ -131,72 +131,6 @@ event BackendStatsEvent
 
 };
 
-event EarlyDepthStencilInfoSingleSample
-{
-    uint64_t depthPassMask;
-    uint64_t stencilPassMask;
-    uint64_t coverageMask;
-};
-
-event EarlyDepthStencilInfoSampleRate
-{
-    uint64_t depthPassMask;
-    uint64_t stencilPassMask;
-    uint64_t coverageMask;
-};
-
-event EarlyDepthStencilInfoNullPS
-{
-    uint64_t depthPassMask;
-    uint64_t stencilPassMask;
-    uint64_t coverageMask;
-};
-
-event LateDepthStencilInfoSingleSample
-{
-    uint64_t depthPassMask;
-    uint64_t stencilPassMask;
-    uint64_t coverageMask;
-};
-
-event LateDepthStencilInfoSampleRate
-{
-    uint64_t depthPassMask;
-    uint64_t stencilPassMask;
-    uint64_t coverageMask;
-};
-
-event LateDepthStencilInfoNullPS
-{
-    uint64_t depthPassMask;
-    uint64_t stencilPassMask;
-    uint64_t coverageMask;
-};
-
-event EarlyDepthInfoPixelRate
-{
-    uint64_t depthPassCount;
-    uint64_t activeLanes;
-};
-
-
-event LateDepthInfoPixelRate
-{
-    uint64_t depthPassCount;
-    uint64_t activeLanes;
-};
-
-
-event BackendDrawEndEvent
-{
-    uint32_t drawId;
-};
-
-event FrontendDrawEndEvent
-{
-    uint32_t drawId;
-};
-
 event EarlyZSingleSample
 {
     uint32_t drawId;
@@ -310,13 +244,6 @@ event LateOmStencil
     uint64_t failCount;
 };
 
-event GSPrimInfo
-{
-    uint64_t inputPrimCount;
-    uint64_t primGeneratedCount;
-    uint64_t vertsInput;
-};
-
 event GSInputPrims
 {
     uint32_t drawId;
@@ -335,35 +262,12 @@ event GSVertsInput
     uint64_t vertsInput;
 };
 
-event ClipVertexCount
-{
-    uint64_t vertsPerPrim;
-    uint64_t primMask;
-};
-
-//REMOVE AND REPLACE
-event FlushVertClip
-{
-    uint32_t drawId;
-};
-
 event VertsClipped
 {
     uint32_t drawId;
     uint64_t clipCount;
 };
 
-event TessPrimCount
-{
-    uint64_t primCount;
-};
-
-//REMOVE AND REPLACE
-event TessPrimFlush
-{
-    uint32_t drawId;
-};
-
 event TessPrims
 {
     uint32_t drawId;
diff --git a/src/gallium/drivers/swr/rasterizer/archrast/events_private.proto b/src/gallium/drivers/swr/rasterizer/archrast/events_private.proto
new file mode 100644
index 00000000000..e0fe9b93104
--- /dev/null
+++ b/src/gallium/drivers/swr/rasterizer/archrast/events_private.proto
@@ -0,0 +1,109 @@
+# Copyright (C) 2018 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.
+#
+# Provides definitions for private internal events that are only used internally
+# to rasty for communicating information between Rasty and Archrast. One goal for
+# ArchRast is to not pollute the Rasty code with lots of calculations, etc. that
+# are needed to compute per draw statistics, etc.
+
+event EarlyDepthStencilInfoSingleSample
+{
+    uint64_t depthPassMask;
+    uint64_t stencilPassMask;
+    uint64_t coverageMask;
+};
+
+event EarlyDepthStencilInfoSampleRate
+{
+    uint64_t depthPassMask;
+    uint64_t stencilPassMask;
+    uint64_t coverageMask;
+};
+
+event EarlyDepthStencilInfoNullPS
+{
+    uint64_t depthPassMask;
+    uint64_t stencilPassMask;
+    uint64_t coverageMask;
+};
+
+event LateDepthStencilInfoSingleSample
+{
+    uint64_t depthPassMask;
+    uint64_t stencilPassMask;
+    uint64_t coverageMask;
+};
+
+event LateDepthStencilInfoSampleRate
+{
+    uint64_t depthPassMask;
+    uint64_t stencilPassMask;
+    uint64_t coverageMask;
+};
+
+event LateDepthStencilInfoNullPS
+{
+    uint64_t depthPassMask;
+    uint64_t stencilPassMask;
+    uint64_t coverageMask;
+};
+
+event EarlyDepthInfoPixelRate
+{
+    uint64_t depthPassCount;
+    uint64_t activeLanes;
+};
+
+
+event LateDepthInfoPixelRate
+{
+    uint64_t depthPassCount;
+    uint64_t activeLanes;
+};
+
+
+event BackendDrawEndEvent
+{
+    uint32_t drawId;
+};
+
+event FrontendDrawEndEvent
+{
+    uint32_t drawId;
+};
+
+event ClipVertexCount
+{
+    uint64_t vertsPerPrim;
+    uint64_t primMask;
+};
+
+event TessPrimCount
+{
+    uint64_t primCount;
+};
+
+event GSPrimInfo
+{
+    uint64_t inputPrimCount;
+    uint64_t primGeneratedCount;
+    uint64_t vertsInput;
+};
diff --git a/src/gallium/drivers/swr/rasterizer/codegen/gen_archrast.py b/src/gallium/drivers/swr/rasterizer/codegen/gen_archrast.py
index 06a3dea4ad9..aa09f220c3f 100644
--- a/src/gallium/drivers/swr/rasterizer/codegen/gen_archrast.py
+++ b/src/gallium/drivers/swr/rasterizer/codegen/gen_archrast.py
@@ -77,19 +77,13 @@ def parse_enums(lines, idx, event_dict):
     event_dict['names'] = enum_names
     return idx
 
-def parse_protos(filename):
-    protos = {}
+def parse_protos(protos, filename):
 
     with open(filename, 'r') as f:
         lines=f.readlines()
 
         idx = 0
 
-        protos['events'] = {}       # event dictionary containing events with their fields
-        protos['event_names'] = []  # needed to keep events in order parsed. dict is not ordered.
-        protos['enums'] = {}
-        protos['enum_names'] = []
-
         eventId = 0
         raw_text = []
         while idx < len(lines):
@@ -118,13 +112,12 @@ def parse_protos(filename):
                 protos['enums'][enum_name] = {}
                 idx = parse_enums(lines, idx, protos['enums'][enum_name])
 
-    return protos
-
 def main():
 
     # Parse args...
     parser = ArgumentParser()
     parser.add_argument('--proto', '-p', help='Path to proto file', required=True)
+    parser.add_argument('--proto_private', '-pp', help='Path to private proto file', required=True)
     parser.add_argument('--output', '-o', help='Output filename (i.e. event.hpp)', required=True)
     parser.add_argument('--gen_event_hpp', help='Generate event header', action='store_true', default=False)
     parser.add_argument('--gen_event_cpp', help='Generate event cpp', action='store_true', default=False)
@@ -133,6 +126,7 @@ def main():
     args = parser.parse_args()
 
     proto_filename = args.proto
+    proto_private_filename = args.proto_private
 
     (output_dir, output_filename) = os.path.split(args.output)
 
@@ -146,7 +140,18 @@ def main():
         print('Error: Could not find proto file %s' % proto_filename, file=sys.stderr)
         return 1
 
-    protos = parse_protos(proto_filename)
+    if not os.path.exists(proto_private_filename):
+        print('Error: Could not find private proto file %s' % proto_private_filename, file=sys.stderr)
+        return 1
+
+    protos = {}
+    protos['events'] = {}       # event dictionary containing events with their fields
+    protos['event_names'] = []  # needed to keep events in order parsed. dict is not ordered.
+    protos['enums'] = {}
+    protos['enum_names'] = []
+
+    parse_protos(protos, proto_filename)
+    parse_protos(protos, proto_private_filename)
 
     # Generate event header
     if args.gen_event_hpp:
diff --git a/src/gallium/drivers/swr/rasterizer/codegen/meson.build b/src/gallium/drivers/swr/rasterizer/codegen/meson.build
index a6e127b8c5f..bbe6efff01a 100644
--- a/src/gallium/drivers/swr/rasterizer/codegen/meson.build
+++ b/src/gallium/drivers/swr/rasterizer/codegen/meson.build
@@ -67,10 +67,14 @@ foreach x : [['gen_ar_event.hpp', '--gen_event_hpp'],
              ['gen_ar_eventhandlerfile.hpp', '--gen_eventhandlerfile_h']]
   files_swr_common += custom_target(
     x[0],
-    input : ['gen_archrast.py', swr_event_proto_files],
+    input : ['gen_archrast.py', swr_event_proto_files, swr_event_pproto_files],
     output : x[0],
     command : [
-      prog_python2, '@INPUT0@', '--proto', '@INPUT1@', '--output', '@OUTPUT@',
+      prog_python2,
+      '@INPUT0@',
+      '--proto', '@INPUT1@',
+      '--proto_private', '@INPUT2@',
+      '--output', '@OUTPUT@',
       x[1],
     ],
     depend_files : files(
-- 
cgit v1.2.3