[Mesa-dev] [PATCH 20/51] i965: Add dword aliases to bitfield structs

Chris Wilson chris at chris-wilson.co.uk
Tue Jan 10 21:23:43 UTC 2017


When processing the packed fields, it is often much easier to pass around
the dword value (as would be seen by hardware) than it is manipulating
the bitfield. By aliasing the bitfield with a uint32_t member, we can
treat the value as either a collection of bits or a single value
depending upon the situation.

Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
---
 src/mesa/drivers/dri/i965/brw_structs.h | 137 +++++++++++++++++++++-----------
 1 file changed, 89 insertions(+), 48 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_structs.h b/src/mesa/drivers/dri/i965/brw_structs.h
index 55338c0e24..e08280301e 100644
--- a/src/mesa/drivers/dri/i965/brw_structs.h
+++ b/src/mesa/drivers/dri/i965/brw_structs.h
@@ -119,7 +119,10 @@ struct thread3
 
 struct brw_clip_unit_state
 {
-   struct thread0 thread0;
+   union {
+      struct thread0 thread0;
+      uint32_t dw0;
+   };
    struct
    {
       unsigned pad0:7;
@@ -136,7 +139,10 @@ struct brw_clip_unit_state
       unsigned single_program_flow:1;
    } thread1;
 
-   struct thread2 thread2;
+   union {
+      struct thread2 thread2;
+      uint32_t dw2;
+   };
    struct thread3 thread3;
 
    struct
@@ -167,12 +173,13 @@ struct brw_clip_unit_state
       unsigned pad2:1;
    } clip5;
 
-   struct
-   {
-      unsigned pad0:5;
-      unsigned clipper_viewport_state_ptr:27;
-   } clip6;
-
+   union {
+      struct {
+         unsigned pad0:5;
+         unsigned clipper_viewport_state_ptr:27;
+      } clip6;
+      uint32_t dw6;
+   };
 
    float viewport_xmin;
    float viewport_xmax;
@@ -333,11 +340,13 @@ struct brw_cc_unit_state
       unsigned pad2:16;
    } cc3;
 
-   struct
-   {
-      unsigned pad0:5;
-      unsigned cc_viewport_state_offset:27; /* Offset from GENERAL_STATE_BASE */
-   } cc4;
+   union {
+      struct {
+         unsigned pad0:5;
+         unsigned cc_viewport_state_offset:27; /* Offset from GENERAL_STATE_BASE */
+      } cc4;
+      uint32_t dw4;
+   };
 
    struct
    {
@@ -374,9 +383,15 @@ struct brw_cc_unit_state
 
 struct brw_sf_unit_state
 {
-   struct thread0 thread0;
+   union {
+      struct thread0 thread0;
+      uint32_t dw0;
+   };
    struct thread1 thread1;
-   struct thread2 thread2;
+   union {
+      struct thread2 thread2;
+      uint32_t dw2;
+   };
    struct thread3 thread3;
 
    struct
@@ -391,13 +406,16 @@ struct brw_sf_unit_state
       unsigned pad3:1;
    } thread4;
 
-   struct
+   union
    {
-      unsigned front_winding:1;
-      unsigned viewport_transform:1;
-      unsigned pad0:3;
-      unsigned sf_viewport_state_offset:27; /* Offset from GENERAL_STATE_BASE */
-   } sf5;
+      struct {
+         unsigned front_winding:1;
+         unsigned viewport_transform:1;
+         unsigned pad0:3;
+         unsigned sf_viewport_state_offset:27; /* Offset from GENERAL_STATE_BASE */
+      } sf5;
+      uint32_t dw5;
+   };
 
    struct
    {
@@ -441,9 +459,15 @@ struct gen6_scissor_rect
 
 struct brw_gs_unit_state
 {
-   struct thread0 thread0;
+   union {
+      struct thread0 thread0;
+      uint32_t dw0;
+   };
    struct thread1 thread1;
-   struct thread2 thread2;
+   union {
+      struct thread2 thread2;
+      uint32_t dw2;
+   };
    struct thread3 thread3;
 
    struct
@@ -460,13 +484,14 @@ struct brw_gs_unit_state
       unsigned pad3:2;
    } thread4;
 
-   struct
-   {
-      unsigned sampler_count:3;
-      unsigned pad0:2;
-      unsigned sampler_state_pointer:27;
-   } gs5;
-
+   union {
+      struct {
+         unsigned sampler_count:3;
+         unsigned pad0:2;
+         unsigned sampler_state_pointer:27;
+      } gs5;
+      uint32_t dw5;
+   };
 
    struct
    {
@@ -485,9 +510,15 @@ struct brw_gs_unit_state
 
 struct brw_vs_unit_state
 {
-   struct thread0 thread0;
+   union {
+      struct thread0 thread0;
+      uint32_t dw0;
+   };
    struct thread1 thread1;
-   struct thread2 thread2;
+   union {
+      struct thread2 thread2;
+      uint32_t dw2;
+   };
    struct thread3 thread3;
 
    struct
@@ -502,12 +533,14 @@ struct brw_vs_unit_state
       unsigned pad3:1;
    } thread4;
 
-   struct
-   {
-      unsigned sampler_count:3;
-      unsigned pad0:2;
-      unsigned sampler_state_pointer:27;
-   } vs5;
+   union {
+      struct {
+         unsigned sampler_count:3;
+         unsigned pad0:2;
+         unsigned sampler_state_pointer:27;
+      } vs5;
+      uint32_t dw5;
+   };
 
    struct
    {
@@ -520,20 +553,28 @@ struct brw_vs_unit_state
 
 struct brw_wm_unit_state
 {
-   struct thread0 thread0;
+   union {
+      struct thread0 thread0;
+      uint32_t dw0;
+   };
    struct thread1 thread1;
-   struct thread2 thread2;
+   union {
+      struct thread2 thread2;
+      uint32_t dw2;
+   };
    struct thread3 thread3;
 
-   struct {
-      unsigned stats_enable:1;
-      unsigned depth_buffer_clear:1;
-      unsigned sampler_count:3;
-      unsigned sampler_state_pointer:27;
-   } wm4;
+   union {
+      struct {
+         unsigned stats_enable:1;
+         unsigned depth_buffer_clear:1;
+         unsigned sampler_count:3;
+         unsigned sampler_state_pointer:27;
+      } wm4;
+      uint32_t dw4;
+   };
 
-   struct
-   {
+   struct {
       unsigned enable_8_pix:1;
       unsigned enable_16_pix:1;
       unsigned enable_32_pix:1;
-- 
2.11.0



More information about the mesa-dev mailing list