[1/4] i965: Move some genX infrastructure to genX_boilerplate.h.

Submitted by Kenneth Graunke on Nov. 2, 2018, 3:04 a.m.

Details

Message ID 20181102030421.13894-1-kenneth@whitecape.org
State New
Headers show
Series "Series without cover letter" ( rev: 1 ) in Mesa

Not browsing as part of any series.

Commit Message

Kenneth Graunke Nov. 2, 2018, 3:04 a.m.
This will let us make multiple genX_*.c files, without copy and pasting
all this boilerplate.
---
 src/mesa/drivers/dri/i965/Makefile.sources    |  10 ++
 src/mesa/drivers/dri/i965/genX_boilerplate.h  | 160 ++++++++++++++++++
 src/mesa/drivers/dri/i965/genX_state_upload.c | 129 +-------------
 src/mesa/drivers/dri/i965/meson.build         |   3 +-
 4 files changed, 174 insertions(+), 128 deletions(-)
 create mode 100644 src/mesa/drivers/dri/i965/genX_boilerplate.h

Patch hide | download patch | download mbox

diff --git a/src/mesa/drivers/dri/i965/Makefile.sources b/src/mesa/drivers/dri/i965/Makefile.sources
index 043a70029f2..63fa7b886f2 100644
--- a/src/mesa/drivers/dri/i965/Makefile.sources
+++ b/src/mesa/drivers/dri/i965/Makefile.sources
@@ -126,42 +126,52 @@  intel_tiled_memcpy_dep_FILES = \
 
 i965_gen4_FILES = \
 	genX_blorp_exec.c \
+	genX_boilerplate.h \
 	genX_state_upload.c
 
 i965_gen45_FILES = \
 	genX_blorp_exec.c \
+	genX_boilerplate.h \
 	genX_state_upload.c
 
 i965_gen5_FILES = \
 	genX_blorp_exec.c \
+	genX_boilerplate.h \
 	genX_state_upload.c
 
 i965_gen6_FILES = \
 	genX_blorp_exec.c \
+	genX_boilerplate.h \
 	genX_state_upload.c
 
 i965_gen7_FILES = \
 	genX_blorp_exec.c \
+	genX_boilerplate.h \
 	genX_state_upload.c
 
 i965_gen75_FILES = \
 	genX_blorp_exec.c \
+	genX_boilerplate.h \
 	genX_state_upload.c
 
 i965_gen8_FILES = \
 	genX_blorp_exec.c \
+	genX_boilerplate.h \
 	genX_state_upload.c
 
 i965_gen9_FILES = \
 	genX_blorp_exec.c \
+	genX_boilerplate.h \
 	genX_state_upload.c
 
 i965_gen10_FILES = \
 	genX_blorp_exec.c \
+	genX_boilerplate.h \
 	genX_state_upload.c
 
 i965_gen11_FILES = \
 	genX_blorp_exec.c \
+	genX_boilerplate.h \
 	genX_state_upload.c
 
 i965_oa_GENERATED_FILES = \
diff --git a/src/mesa/drivers/dri/i965/genX_boilerplate.h b/src/mesa/drivers/dri/i965/genX_boilerplate.h
new file mode 100644
index 00000000000..546dd1e23bc
--- /dev/null
+++ b/src/mesa/drivers/dri/i965/genX_boilerplate.h
@@ -0,0 +1,160 @@ 
+/*
+ * Copyright © 2018 Intel Corporation
+ *
+ * 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 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.
+ */
+
+#ifndef GENX_BOILERPLATE_H
+#define GENX_BOILERPLATE_H
+
+#include <assert.h>
+
+#include "genxml/gen_macros.h"
+
+#include "brw_context.h"
+#include "intel_batchbuffer.h"
+
+UNUSED static void *
+emit_dwords(struct brw_context *brw, unsigned n)
+{
+   intel_batchbuffer_begin(brw, n);
+   uint32_t *map = brw->batch.map_next;
+   brw->batch.map_next += n;
+   intel_batchbuffer_advance(brw);
+   return map;
+}
+
+struct brw_address {
+   struct brw_bo *bo;
+   unsigned reloc_flags;
+   uint32_t offset;
+};
+
+#define __gen_address_type struct brw_address
+#define __gen_user_data struct brw_context
+
+static uint64_t
+__gen_combine_address(struct brw_context *brw, void *location,
+                      struct brw_address address, uint32_t delta)
+{
+   struct intel_batchbuffer *batch = &brw->batch;
+   uint32_t offset;
+
+   if (address.bo == NULL) {
+      return address.offset + delta;
+   } else {
+      if (GEN_GEN < 6 && brw_ptr_in_state_buffer(batch, location)) {
+         offset = (char *) location - (char *) brw->batch.state.map;
+         return brw_state_reloc(batch, offset, address.bo,
+                                address.offset + delta,
+                                address.reloc_flags);
+      }
+
+      assert(!brw_ptr_in_state_buffer(batch, location));
+
+      offset = (char *) location - (char *) brw->batch.batch.map;
+      return brw_batch_reloc(batch, offset, address.bo,
+                             address.offset + delta,
+                             address.reloc_flags);
+   }
+}
+
+UNUSED static struct brw_address
+rw_bo(struct brw_bo *bo, uint32_t offset)
+{
+   return (struct brw_address) {
+            .bo = bo,
+            .offset = offset,
+            .reloc_flags = RELOC_WRITE,
+   };
+}
+
+UNUSED static struct brw_address
+ro_bo(struct brw_bo *bo, uint32_t offset)
+{
+   return (struct brw_address) {
+            .bo = bo,
+            .offset = offset,
+   };
+}
+
+UNUSED static struct brw_address
+rw_32_bo(struct brw_bo *bo, uint32_t offset)
+{
+   return (struct brw_address) {
+            .bo = bo,
+            .offset = offset,
+            .reloc_flags = RELOC_WRITE | RELOC_32BIT,
+   };
+}
+
+UNUSED static struct brw_address
+ro_32_bo(struct brw_bo *bo, uint32_t offset)
+{
+   return (struct brw_address) {
+            .bo = bo,
+            .offset = offset,
+            .reloc_flags = RELOC_32BIT,
+   };
+}
+
+UNUSED static struct brw_address
+ggtt_bo(struct brw_bo *bo, uint32_t offset)
+{
+   return (struct brw_address) {
+            .bo = bo,
+            .offset = offset,
+            .reloc_flags = RELOC_WRITE | RELOC_NEEDS_GGTT,
+   };
+}
+
+#include "genxml/genX_pack.h"
+
+#define _brw_cmd_length(cmd) cmd ## _length
+#define _brw_cmd_length_bias(cmd) cmd ## _length_bias
+#define _brw_cmd_header(cmd) cmd ## _header
+#define _brw_cmd_pack(cmd) cmd ## _pack
+
+#define brw_batch_emit(brw, cmd, name)                  \
+   for (struct cmd name = { _brw_cmd_header(cmd) },     \
+        *_dst = emit_dwords(brw, _brw_cmd_length(cmd)); \
+        __builtin_expect(_dst != NULL, 1);              \
+        _brw_cmd_pack(cmd)(brw, (void *)_dst, &name),   \
+        _dst = NULL)
+
+#define brw_batch_emitn(brw, cmd, n, ...) ({           \
+      uint32_t *_dw = emit_dwords(brw, n);             \
+      struct cmd template = {                          \
+         _brw_cmd_header(cmd),                         \
+         .DWordLength = n - _brw_cmd_length_bias(cmd), \
+         __VA_ARGS__                                   \
+      };                                               \
+      _brw_cmd_pack(cmd)(brw, _dw, &template);         \
+      _dw + 1; /* Array starts at dw[1] */             \
+   })
+
+#define brw_state_emit(brw, cmd, align, offset, name)              \
+   for (struct cmd name = {},                                      \
+        *_dst = brw_state_batch(brw, _brw_cmd_length(cmd) * 4,     \
+                                align, offset);                    \
+        __builtin_expect(_dst != NULL, 1);                         \
+        _brw_cmd_pack(cmd)(brw, (void *)_dst, &name),              \
+        _dst = NULL)
+
+#endif
diff --git a/src/mesa/drivers/dri/i965/genX_state_upload.c b/src/mesa/drivers/dri/i965/genX_state_upload.c
index 9cd017a5cff..a7b458a2ada 100644
--- a/src/mesa/drivers/dri/i965/genX_state_upload.c
+++ b/src/mesa/drivers/dri/i965/genX_state_upload.c
@@ -33,6 +33,8 @@ 
 #include "main/macros.h"
 #include "main/state.h"
 
+#include "genX_boilerplate.h"
+
 #include "brw_context.h"
 #include "brw_draw.h"
 #include "brw_multisample_state.h"
@@ -56,100 +58,6 @@ 
 #include "main/viewport.h"
 #include "util/half_float.h"
 
-UNUSED static void *
-emit_dwords(struct brw_context *brw, unsigned n)
-{
-   intel_batchbuffer_begin(brw, n);
-   uint32_t *map = brw->batch.map_next;
-   brw->batch.map_next += n;
-   intel_batchbuffer_advance(brw);
-   return map;
-}
-
-struct brw_address {
-   struct brw_bo *bo;
-   unsigned reloc_flags;
-   uint32_t offset;
-};
-
-#define __gen_address_type struct brw_address
-#define __gen_user_data struct brw_context
-
-static uint64_t
-__gen_combine_address(struct brw_context *brw, void *location,
-                      struct brw_address address, uint32_t delta)
-{
-   struct intel_batchbuffer *batch = &brw->batch;
-   uint32_t offset;
-
-   if (address.bo == NULL) {
-      return address.offset + delta;
-   } else {
-      if (GEN_GEN < 6 && brw_ptr_in_state_buffer(batch, location)) {
-         offset = (char *) location - (char *) brw->batch.state.map;
-         return brw_state_reloc(batch, offset, address.bo,
-                                address.offset + delta,
-                                address.reloc_flags);
-      }
-
-      assert(!brw_ptr_in_state_buffer(batch, location));
-
-      offset = (char *) location - (char *) brw->batch.batch.map;
-      return brw_batch_reloc(batch, offset, address.bo,
-                             address.offset + delta,
-                             address.reloc_flags);
-   }
-}
-
-UNUSED static struct brw_address
-rw_bo(struct brw_bo *bo, uint32_t offset)
-{
-   return (struct brw_address) {
-            .bo = bo,
-            .offset = offset,
-            .reloc_flags = RELOC_WRITE,
-   };
-}
-
-static struct brw_address
-ro_bo(struct brw_bo *bo, uint32_t offset)
-{
-   return (struct brw_address) {
-            .bo = bo,
-            .offset = offset,
-   };
-}
-
-static struct brw_address
-rw_32_bo(struct brw_bo *bo, uint32_t offset)
-{
-   return (struct brw_address) {
-            .bo = bo,
-            .offset = offset,
-            .reloc_flags = RELOC_WRITE | RELOC_32BIT,
-   };
-}
-
-static struct brw_address
-ro_32_bo(struct brw_bo *bo, uint32_t offset)
-{
-   return (struct brw_address) {
-            .bo = bo,
-            .offset = offset,
-            .reloc_flags = RELOC_32BIT,
-   };
-}
-
-UNUSED static struct brw_address
-ggtt_bo(struct brw_bo *bo, uint32_t offset)
-{
-   return (struct brw_address) {
-            .bo = bo,
-            .offset = offset,
-            .reloc_flags = RELOC_WRITE | RELOC_NEEDS_GGTT,
-   };
-}
-
 #if GEN_GEN == 4
 static struct brw_address
 KSP(struct brw_context *brw, uint32_t offset)
@@ -164,39 +72,6 @@  KSP(UNUSED struct brw_context *brw, uint32_t offset)
 }
 #endif
 
-#include "genxml/genX_pack.h"
-
-#define _brw_cmd_length(cmd) cmd ## _length
-#define _brw_cmd_length_bias(cmd) cmd ## _length_bias
-#define _brw_cmd_header(cmd) cmd ## _header
-#define _brw_cmd_pack(cmd) cmd ## _pack
-
-#define brw_batch_emit(brw, cmd, name)                  \
-   for (struct cmd name = { _brw_cmd_header(cmd) },     \
-        *_dst = emit_dwords(brw, _brw_cmd_length(cmd)); \
-        __builtin_expect(_dst != NULL, 1);              \
-        _brw_cmd_pack(cmd)(brw, (void *)_dst, &name),   \
-        _dst = NULL)
-
-#define brw_batch_emitn(brw, cmd, n, ...) ({           \
-      uint32_t *_dw = emit_dwords(brw, n);             \
-      struct cmd template = {                          \
-         _brw_cmd_header(cmd),                         \
-         .DWordLength = n - _brw_cmd_length_bias(cmd), \
-         __VA_ARGS__                                   \
-      };                                               \
-      _brw_cmd_pack(cmd)(brw, _dw, &template);         \
-      _dw + 1; /* Array starts at dw[1] */             \
-   })
-
-#define brw_state_emit(brw, cmd, align, offset, name)              \
-   for (struct cmd name = {},                                      \
-        *_dst = brw_state_batch(brw, _brw_cmd_length(cmd) * 4,     \
-                                align, offset);                    \
-        __builtin_expect(_dst != NULL, 1);                         \
-        _brw_cmd_pack(cmd)(brw, (void *)_dst, &name),              \
-        _dst = NULL)
-
 /**
  * Polygon stipple packet
  */
diff --git a/src/mesa/drivers/dri/i965/meson.build b/src/mesa/drivers/dri/i965/meson.build
index 24172955e9b..02f5f3073f7 100644
--- a/src/mesa/drivers/dri/i965/meson.build
+++ b/src/mesa/drivers/dri/i965/meson.build
@@ -147,7 +147,8 @@  i965_gen_libs = []
 foreach v : ['40', '45', '50', '60', '70', '75', '80', '90', '100', '110']
   i965_gen_libs += static_library(
     'i965_gen@0@'.format(v),
-    ['genX_blorp_exec.c', 'genX_state_upload.c', gen_xml_pack],
+    ['genX_blorp_exec.c', 'genX_boilerplate.h', 'genX_state_upload.c',
+     gen_xml_pack],
     include_directories : [inc_common, inc_intel, inc_dri_common],
     c_args : [
       c_vis_args, no_override_init_args, c_sse2_args,

Comments

On 2018-11-01 20:04:18, Kenneth Graunke wrote:
> This will let us make multiple genX_*.c files, without copy and pasting
> all this boilerplate.
> ---
>  src/mesa/drivers/dri/i965/Makefile.sources    |  10 ++
>  src/mesa/drivers/dri/i965/genX_boilerplate.h  | 160 ++++++++++++++++++
>  src/mesa/drivers/dri/i965/genX_state_upload.c | 129 +-------------
>  src/mesa/drivers/dri/i965/meson.build         |   3 +-
>  4 files changed, 174 insertions(+), 128 deletions(-)
>  create mode 100644 src/mesa/drivers/dri/i965/genX_boilerplate.h
> 
> diff --git a/src/mesa/drivers/dri/i965/Makefile.sources b/src/mesa/drivers/dri/i965/Makefile.sources
> index 043a70029f2..63fa7b886f2 100644
> --- a/src/mesa/drivers/dri/i965/Makefile.sources
> +++ b/src/mesa/drivers/dri/i965/Makefile.sources
> @@ -126,42 +126,52 @@ intel_tiled_memcpy_dep_FILES = \
>  
>  i965_gen4_FILES = \
>         genX_blorp_exec.c \
> +       genX_boilerplate.h \

brw_genX.h? genX_common.h? genX.h?