lp_rast_priv.h revision 5fe2ce28b6e9fba181c13c6f49b57b3dd68fe88e
1/**************************************************************************
2 *
3 * Copyright 2009 VMware, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28#ifndef LP_RAST_PRIV_H
29#define LP_RAST_PRIV_H
30
31#include "os/os_thread.h"
32#include "util/u_format.h"
33#include "gallivm/lp_bld_debug.h"
34#include "lp_rast.h"
35#include "lp_tile_soa.h"
36
37
38#define MAX_THREADS 8  /* XXX probably temporary here */
39
40
41struct lp_rasterizer;
42
43
44/**
45 * A tile's color and depth memory.
46 * We can choose whatever layout for the internal tile storage we prefer.
47 */
48struct lp_rast_tile
49{
50   uint8_t *color[PIPE_MAX_COLOR_BUFS];
51};
52
53
54/**
55 * Per-thread rasterization state
56 */
57struct lp_rasterizer_task
58{
59   struct lp_rast_tile tile;   /** Tile color/z/stencil memory */
60
61   unsigned x, y;          /**< Pos of this tile in framebuffer, in pixels */
62
63   const struct lp_rast_state *current_state;
64
65   /** "back" pointer */
66   struct lp_rasterizer *rast;
67
68   /** "my" index */
69   unsigned thread_index;
70
71   pipe_semaphore work_ready;
72   pipe_semaphore work_done;
73};
74
75
76/**
77 * This is the state required while rasterizing tiles.
78 * Note that this contains per-thread information too.
79 * The tile size is TILE_SIZE x TILE_SIZE pixels.
80 */
81struct lp_rasterizer
82{
83   boolean exit_flag;
84
85   /* Framebuffer stuff
86    */
87   struct {
88      void *map;
89      unsigned stride;
90      unsigned width;
91      unsigned height;
92      enum pipe_format format;
93   } cbuf[PIPE_MAX_COLOR_BUFS];
94
95   struct {
96      uint8_t *map;
97      unsigned stride;
98      unsigned blocksize;
99   } zsbuf;
100
101   struct {
102      unsigned nr_cbufs;
103      boolean write_color;
104      boolean write_zstencil;
105      unsigned clear_color;
106      unsigned clear_depth;
107      char clear_stencil;
108   } state;
109
110   /** The incoming queue of scenes ready to rasterize */
111   struct lp_scene_queue *full_scenes;
112
113   /**
114    * The outgoing queue of processed scenes to return to setup module
115    *
116    * XXX: while scenes are per-context but the rasterizer is
117    * (potentially) shared, these empty scenes should be returned to
118    * the context which created them rather than retained here.
119    */
120   struct lp_scene_queue *empty_scenes;
121
122   /** The scene currently being rasterized by the threads */
123   struct lp_scene *curr_scene;
124
125   /** A task object for each rasterization thread */
126   struct lp_rasterizer_task tasks[MAX_THREADS];
127
128   unsigned num_threads;
129   pipe_thread threads[MAX_THREADS];
130
131   /** For synchronizing the rasterization threads */
132   pipe_barrier barrier;
133};
134
135
136void lp_rast_shade_quads( struct lp_rasterizer_task *task,
137                          const struct lp_rast_shader_inputs *inputs,
138                          unsigned x, unsigned y,
139                          int32_t c1, int32_t c2, int32_t c3);
140
141
142/**
143 * Get the pointer to the depth buffer for a block.
144 * \param x, y location of 4x4 block in window coords
145 */
146static INLINE void *
147lp_rast_depth_pointer( struct lp_rasterizer *rast,
148                       unsigned x, unsigned y )
149{
150   void * depth;
151
152   assert((x % TILE_VECTOR_WIDTH) == 0);
153   assert((y % TILE_VECTOR_HEIGHT) == 0);
154
155   if (!rast->zsbuf.map)
156      return NULL;
157
158   depth = (rast->zsbuf.map +
159            rast->zsbuf.stride * y +
160            rast->zsbuf.blocksize * x * TILE_VECTOR_HEIGHT);
161
162   assert(lp_check_alignment(depth, 16));
163   return depth;
164}
165
166
167
168/**
169 * Shade all pixels in a 4x4 block.  The fragment code omits the
170 * triangle in/out tests.
171 * \param x, y location of 4x4 block in window coords
172 */
173static INLINE void
174lp_rast_shade_quads_all( struct lp_rasterizer_task *task,
175                         const struct lp_rast_shader_inputs *inputs,
176                         unsigned x, unsigned y )
177{
178   struct lp_rasterizer *rast = task->rast;
179   const struct lp_rast_state *state = task->current_state;
180   struct lp_rast_tile *tile = &task->tile;
181   const unsigned ix = x % TILE_SIZE, iy = y % TILE_SIZE;
182   uint8_t *color[PIPE_MAX_COLOR_BUFS];
183   void *depth;
184   unsigned block_offset, i;
185
186   /* offset of the containing 16x16 pixel block within the tile */
187   block_offset = (iy / 4) * (16 * 16) + (ix / 4) * 16;
188
189   /* color buffer */
190   for (i = 0; i < rast->state.nr_cbufs; i++)
191      color[i] = tile->color[i] + 4 * block_offset;
192
193   depth = lp_rast_depth_pointer(rast, x, y);
194
195   /* run shader */
196   state->jit_function[0]( &state->jit_context,
197                           x, y,
198                           inputs->a0,
199                           inputs->dadx,
200                           inputs->dady,
201                           color,
202                           depth,
203                           INT_MIN, INT_MIN, INT_MIN,
204                           NULL, NULL, NULL );
205}
206
207
208#endif
209