1bf215546Sopenharmony_ci/**************************************************************************
2bf215546Sopenharmony_ci *
3bf215546Sopenharmony_ci * Copyright 2009 VMware, Inc.
4bf215546Sopenharmony_ci * All Rights Reserved.
5bf215546Sopenharmony_ci *
6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the
8bf215546Sopenharmony_ci * "Software"), to deal in the Software without restriction, including
9bf215546Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish,
10bf215546Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to
11bf215546Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to
12bf215546Sopenharmony_ci * the following conditions:
13bf215546Sopenharmony_ci *
14bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the
15bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions
16bf215546Sopenharmony_ci * of the Software.
17bf215546Sopenharmony_ci *
18bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20bf215546Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21bf215546Sopenharmony_ci * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22bf215546Sopenharmony_ci * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23bf215546Sopenharmony_ci * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24bf215546Sopenharmony_ci * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25bf215546Sopenharmony_ci *
26bf215546Sopenharmony_ci **************************************************************************/
27bf215546Sopenharmony_ci
28bf215546Sopenharmony_ci
29bf215546Sopenharmony_ci/**
30bf215546Sopenharmony_ci * Binner data structures and bin-related functions.
31bf215546Sopenharmony_ci * Note: the "setup" code is concerned with building scenes while
32bf215546Sopenharmony_ci * The "rast" code is concerned with consuming/executing scenes.
33bf215546Sopenharmony_ci */
34bf215546Sopenharmony_ci
35bf215546Sopenharmony_ci#ifndef LP_SCENE_H
36bf215546Sopenharmony_ci#define LP_SCENE_H
37bf215546Sopenharmony_ci
38bf215546Sopenharmony_ci#include "os/os_thread.h"
39bf215546Sopenharmony_ci#include "lp_rast.h"
40bf215546Sopenharmony_ci#include "lp_debug.h"
41bf215546Sopenharmony_ci
42bf215546Sopenharmony_cistruct lp_scene_queue;
43bf215546Sopenharmony_cistruct lp_rast_state;
44bf215546Sopenharmony_ci
45bf215546Sopenharmony_ci/* We're limited to 2K by 2K for 32bit fixed point rasterization.
46bf215546Sopenharmony_ci * Will need a 64-bit version for larger framebuffers.
47bf215546Sopenharmony_ci */
48bf215546Sopenharmony_ci#define TILES_X (LP_MAX_WIDTH / TILE_SIZE)
49bf215546Sopenharmony_ci#define TILES_Y (LP_MAX_HEIGHT / TILE_SIZE)
50bf215546Sopenharmony_ci
51bf215546Sopenharmony_ci
52bf215546Sopenharmony_ci/* Commands per command block (ideally so sizeof(cmd_block) is a power of
53bf215546Sopenharmony_ci * two in size.)
54bf215546Sopenharmony_ci */
55bf215546Sopenharmony_ci#define CMD_BLOCK_MAX 29
56bf215546Sopenharmony_ci
57bf215546Sopenharmony_ci/* Bytes per data block.  This effectively limits the maximum constant buffer
58bf215546Sopenharmony_ci * size.
59bf215546Sopenharmony_ci */
60bf215546Sopenharmony_ci#define DATA_BLOCK_SIZE (64 * 1024)
61bf215546Sopenharmony_ci
62bf215546Sopenharmony_ci/* Scene temporary storage is clamped to this size:
63bf215546Sopenharmony_ci */
64bf215546Sopenharmony_ci#define LP_SCENE_MAX_SIZE (36*1024*1024)
65bf215546Sopenharmony_ci
66bf215546Sopenharmony_ci/* The maximum amount of texture storage referenced by a scene is
67bf215546Sopenharmony_ci * clamped to this size:
68bf215546Sopenharmony_ci */
69bf215546Sopenharmony_ci#define LP_SCENE_MAX_RESOURCE_SIZE (64*1024*1024)
70bf215546Sopenharmony_ci
71bf215546Sopenharmony_ci
72bf215546Sopenharmony_ci/* switch to a non-pointer value for this:
73bf215546Sopenharmony_ci */
74bf215546Sopenharmony_citypedef void (*lp_rast_cmd_func)(struct lp_rasterizer_task *,
75bf215546Sopenharmony_ci                                 const union lp_rast_cmd_arg);
76bf215546Sopenharmony_ci
77bf215546Sopenharmony_ci
78bf215546Sopenharmony_cistruct cmd_block {
79bf215546Sopenharmony_ci   uint8_t cmd[CMD_BLOCK_MAX];  // LP_RAST_OP_x
80bf215546Sopenharmony_ci   union lp_rast_cmd_arg arg[CMD_BLOCK_MAX];
81bf215546Sopenharmony_ci   unsigned count;
82bf215546Sopenharmony_ci   struct cmd_block *next;
83bf215546Sopenharmony_ci};
84bf215546Sopenharmony_ci
85bf215546Sopenharmony_ci
86bf215546Sopenharmony_cistruct data_block {
87bf215546Sopenharmony_ci   ubyte data[DATA_BLOCK_SIZE];
88bf215546Sopenharmony_ci   unsigned used;
89bf215546Sopenharmony_ci   struct data_block *next;
90bf215546Sopenharmony_ci};
91bf215546Sopenharmony_ci
92bf215546Sopenharmony_ci
93bf215546Sopenharmony_ci
94bf215546Sopenharmony_ci/**
95bf215546Sopenharmony_ci * For each screen tile we have one of these bins.
96bf215546Sopenharmony_ci */
97bf215546Sopenharmony_cistruct cmd_bin {
98bf215546Sopenharmony_ci   const struct lp_rast_state *last_state;  /* most recent state set in bin */
99bf215546Sopenharmony_ci   struct cmd_block *head;
100bf215546Sopenharmony_ci   struct cmd_block *tail;
101bf215546Sopenharmony_ci};
102bf215546Sopenharmony_ci
103bf215546Sopenharmony_ci
104bf215546Sopenharmony_ci/**
105bf215546Sopenharmony_ci * This stores bulk data which is used for all memory allocations
106bf215546Sopenharmony_ci * within a scene.
107bf215546Sopenharmony_ci *
108bf215546Sopenharmony_ci * Examples include triangle data and state data.  The commands in
109bf215546Sopenharmony_ci * the per-tile bins will point to chunks of data in this structure.
110bf215546Sopenharmony_ci *
111bf215546Sopenharmony_ci * Include the first block of data statically to ensure we can always
112bf215546Sopenharmony_ci * initiate a scene without relying on malloc succeeding.
113bf215546Sopenharmony_ci */
114bf215546Sopenharmony_cistruct data_block_list {
115bf215546Sopenharmony_ci   struct data_block first;
116bf215546Sopenharmony_ci   struct data_block *head;
117bf215546Sopenharmony_ci};
118bf215546Sopenharmony_ci
119bf215546Sopenharmony_cistruct resource_ref;
120bf215546Sopenharmony_ci
121bf215546Sopenharmony_cistruct shader_ref;
122bf215546Sopenharmony_ci
123bf215546Sopenharmony_cistruct lp_scene_surface {
124bf215546Sopenharmony_ci   uint8_t *map;
125bf215546Sopenharmony_ci   unsigned stride;
126bf215546Sopenharmony_ci   unsigned layer_stride;
127bf215546Sopenharmony_ci   unsigned format_bytes;
128bf215546Sopenharmony_ci   unsigned sample_stride;
129bf215546Sopenharmony_ci   unsigned nr_samples;
130bf215546Sopenharmony_ci};
131bf215546Sopenharmony_ci
132bf215546Sopenharmony_ci/**
133bf215546Sopenharmony_ci * All bins and bin data are contained here.
134bf215546Sopenharmony_ci * Per-bin data goes into the 'tile' bins.
135bf215546Sopenharmony_ci * Shared data goes into the 'data' buffer.
136bf215546Sopenharmony_ci *
137bf215546Sopenharmony_ci * When there are multiple threads, will want to double-buffer between
138bf215546Sopenharmony_ci * scenes:
139bf215546Sopenharmony_ci */
140bf215546Sopenharmony_cistruct lp_scene {
141bf215546Sopenharmony_ci   struct pipe_context *pipe;
142bf215546Sopenharmony_ci   struct lp_fence *fence;
143bf215546Sopenharmony_ci   struct lp_setup_context *setup;
144bf215546Sopenharmony_ci
145bf215546Sopenharmony_ci   /* The queries still active at end of scene */
146bf215546Sopenharmony_ci   struct llvmpipe_query *active_queries[LP_MAX_ACTIVE_BINNED_QUERIES];
147bf215546Sopenharmony_ci   unsigned num_active_queries;
148bf215546Sopenharmony_ci   /* If queries were either active or there were begin/end query commands */
149bf215546Sopenharmony_ci   boolean had_queries;
150bf215546Sopenharmony_ci
151bf215546Sopenharmony_ci   /* Framebuffer mappings - valid only between begin_rasterization()
152bf215546Sopenharmony_ci    * and end_rasterization().
153bf215546Sopenharmony_ci    */
154bf215546Sopenharmony_ci   struct lp_scene_surface zsbuf, cbufs[PIPE_MAX_COLOR_BUFS];
155bf215546Sopenharmony_ci
156bf215546Sopenharmony_ci   /* The amount of layers in the fb (minimum of all attachments) */
157bf215546Sopenharmony_ci   unsigned fb_max_layer;
158bf215546Sopenharmony_ci
159bf215546Sopenharmony_ci   /* fixed point sample positions. */
160bf215546Sopenharmony_ci   int32_t fixed_sample_pos[LP_MAX_SAMPLES][2];
161bf215546Sopenharmony_ci
162bf215546Sopenharmony_ci   /* max samples for bound framebuffer */
163bf215546Sopenharmony_ci   unsigned fb_max_samples;
164bf215546Sopenharmony_ci
165bf215546Sopenharmony_ci   /** the framebuffer to render the scene into */
166bf215546Sopenharmony_ci   struct pipe_framebuffer_state fb;
167bf215546Sopenharmony_ci
168bf215546Sopenharmony_ci   /** list of resources referenced by the scene commands */
169bf215546Sopenharmony_ci   struct resource_ref *resources;
170bf215546Sopenharmony_ci
171bf215546Sopenharmony_ci   /** list of writable resources referenced by the scene commands */
172bf215546Sopenharmony_ci   struct resource_ref *writeable_resources;
173bf215546Sopenharmony_ci
174bf215546Sopenharmony_ci   /** list of frag shaders referenced by the scene commands */
175bf215546Sopenharmony_ci   struct shader_ref *frag_shaders;
176bf215546Sopenharmony_ci
177bf215546Sopenharmony_ci   /** Total memory used by the scene (in bytes).  This sums all the
178bf215546Sopenharmony_ci    * data blocks and counts all bins, state, resource references and
179bf215546Sopenharmony_ci    * other random allocations within the scene.
180bf215546Sopenharmony_ci    */
181bf215546Sopenharmony_ci   unsigned scene_size;
182bf215546Sopenharmony_ci
183bf215546Sopenharmony_ci   /** Sum of sizes of all resources referenced by the scene.  Sums
184bf215546Sopenharmony_ci    * all the textures read by the scene:
185bf215546Sopenharmony_ci    */
186bf215546Sopenharmony_ci   unsigned resource_reference_size;
187bf215546Sopenharmony_ci
188bf215546Sopenharmony_ci   boolean alloc_failed;
189bf215546Sopenharmony_ci   boolean permit_linear_rasterizer;
190bf215546Sopenharmony_ci
191bf215546Sopenharmony_ci   /**
192bf215546Sopenharmony_ci    * Number of active tiles in each dimension.
193bf215546Sopenharmony_ci    * This basically the framebuffer size divided by tile size
194bf215546Sopenharmony_ci    */
195bf215546Sopenharmony_ci   unsigned tiles_x, tiles_y;
196bf215546Sopenharmony_ci
197bf215546Sopenharmony_ci   int curr_x, curr_y;  /**< for iterating over bins */
198bf215546Sopenharmony_ci   mtx_t mutex;
199bf215546Sopenharmony_ci
200bf215546Sopenharmony_ci   unsigned num_alloced_tiles;
201bf215546Sopenharmony_ci   struct cmd_bin *tiles;
202bf215546Sopenharmony_ci   struct data_block_list data;
203bf215546Sopenharmony_ci};
204bf215546Sopenharmony_ci
205bf215546Sopenharmony_ci
206bf215546Sopenharmony_ci
207bf215546Sopenharmony_cistruct lp_scene *lp_scene_create(struct lp_setup_context *setup);
208bf215546Sopenharmony_ci
209bf215546Sopenharmony_civoid lp_scene_destroy(struct lp_scene *scene);
210bf215546Sopenharmony_ci
211bf215546Sopenharmony_ciboolean lp_scene_is_empty(struct lp_scene *scene);
212bf215546Sopenharmony_ciboolean lp_scene_is_oom(struct lp_scene *scene);
213bf215546Sopenharmony_ci
214bf215546Sopenharmony_ci
215bf215546Sopenharmony_cistruct data_block *lp_scene_new_data_block(struct lp_scene *scene);
216bf215546Sopenharmony_ci
217bf215546Sopenharmony_cistruct cmd_block *lp_scene_new_cmd_block(struct lp_scene *scene,
218bf215546Sopenharmony_ci                                         struct cmd_bin *bin);
219bf215546Sopenharmony_ci
220bf215546Sopenharmony_ciboolean lp_scene_add_resource_reference(struct lp_scene *scene,
221bf215546Sopenharmony_ci                                        struct pipe_resource *resource,
222bf215546Sopenharmony_ci                                        boolean initializing_scene,
223bf215546Sopenharmony_ci                                        boolean writeable);
224bf215546Sopenharmony_ci
225bf215546Sopenharmony_ciunsigned lp_scene_is_resource_referenced(const struct lp_scene *scene,
226bf215546Sopenharmony_ci                                         const struct pipe_resource *resource);
227bf215546Sopenharmony_ci
228bf215546Sopenharmony_ciboolean lp_scene_add_frag_shader_reference(struct lp_scene *scene,
229bf215546Sopenharmony_ci                                           struct lp_fragment_shader_variant *variant);
230bf215546Sopenharmony_ci
231bf215546Sopenharmony_ci
232bf215546Sopenharmony_ci
233bf215546Sopenharmony_ci/**
234bf215546Sopenharmony_ci * Allocate space for a command/data in the bin's data buffer.
235bf215546Sopenharmony_ci * Grow the block list if needed.
236bf215546Sopenharmony_ci */
237bf215546Sopenharmony_cistatic inline void *
238bf215546Sopenharmony_cilp_scene_alloc(struct lp_scene *scene, unsigned size)
239bf215546Sopenharmony_ci{
240bf215546Sopenharmony_ci   struct data_block_list *list = &scene->data;
241bf215546Sopenharmony_ci   struct data_block *block = list->head;
242bf215546Sopenharmony_ci
243bf215546Sopenharmony_ci   assert(size <= DATA_BLOCK_SIZE);
244bf215546Sopenharmony_ci   assert(block != NULL);
245bf215546Sopenharmony_ci
246bf215546Sopenharmony_ci   if (LP_DEBUG & DEBUG_MEM)
247bf215546Sopenharmony_ci      debug_printf("alloc %u block %u/%u tot %u/%u\n",
248bf215546Sopenharmony_ci                   size, block->used, (unsigned)DATA_BLOCK_SIZE,
249bf215546Sopenharmony_ci                   scene->scene_size, LP_SCENE_MAX_SIZE);
250bf215546Sopenharmony_ci
251bf215546Sopenharmony_ci   if (block->used + size > DATA_BLOCK_SIZE) {
252bf215546Sopenharmony_ci      block = lp_scene_new_data_block(scene);
253bf215546Sopenharmony_ci      if (!block) {
254bf215546Sopenharmony_ci         /* out of memory */
255bf215546Sopenharmony_ci         return NULL;
256bf215546Sopenharmony_ci      }
257bf215546Sopenharmony_ci   }
258bf215546Sopenharmony_ci
259bf215546Sopenharmony_ci   {
260bf215546Sopenharmony_ci      ubyte *data = block->data + block->used;
261bf215546Sopenharmony_ci      block->used += size;
262bf215546Sopenharmony_ci      return data;
263bf215546Sopenharmony_ci   }
264bf215546Sopenharmony_ci}
265bf215546Sopenharmony_ci
266bf215546Sopenharmony_ci
267bf215546Sopenharmony_ci/**
268bf215546Sopenharmony_ci * As above, but with specific alignment.
269bf215546Sopenharmony_ci */
270bf215546Sopenharmony_cistatic inline void *
271bf215546Sopenharmony_cilp_scene_alloc_aligned(struct lp_scene *scene, unsigned size,
272bf215546Sopenharmony_ci                       unsigned alignment)
273bf215546Sopenharmony_ci{
274bf215546Sopenharmony_ci   struct data_block_list *list = &scene->data;
275bf215546Sopenharmony_ci   struct data_block *block = list->head;
276bf215546Sopenharmony_ci
277bf215546Sopenharmony_ci   assert(block != NULL);
278bf215546Sopenharmony_ci
279bf215546Sopenharmony_ci   if (LP_DEBUG & DEBUG_MEM)
280bf215546Sopenharmony_ci      debug_printf("alloc %u block %u/%u tot %u/%u\n",
281bf215546Sopenharmony_ci                   size + alignment - 1,
282bf215546Sopenharmony_ci                   block->used, (unsigned)DATA_BLOCK_SIZE,
283bf215546Sopenharmony_ci                   scene->scene_size, LP_SCENE_MAX_SIZE);
284bf215546Sopenharmony_ci
285bf215546Sopenharmony_ci   if (block->used + size + alignment - 1 > DATA_BLOCK_SIZE) {
286bf215546Sopenharmony_ci      block = lp_scene_new_data_block(scene);
287bf215546Sopenharmony_ci      if (!block)
288bf215546Sopenharmony_ci         return NULL;
289bf215546Sopenharmony_ci   }
290bf215546Sopenharmony_ci
291bf215546Sopenharmony_ci   {
292bf215546Sopenharmony_ci      ubyte *data = block->data + block->used;
293bf215546Sopenharmony_ci      unsigned offset = (((uintptr_t)data + alignment - 1) & ~(alignment - 1)) - (uintptr_t)data;
294bf215546Sopenharmony_ci      block->used += offset + size;
295bf215546Sopenharmony_ci      return data + offset;
296bf215546Sopenharmony_ci   }
297bf215546Sopenharmony_ci}
298bf215546Sopenharmony_ci
299bf215546Sopenharmony_ci
300bf215546Sopenharmony_ci/** Return pointer to a particular tile's bin. */
301bf215546Sopenharmony_cistatic inline struct cmd_bin *
302bf215546Sopenharmony_cilp_scene_get_bin(struct lp_scene *scene, unsigned x, unsigned y)
303bf215546Sopenharmony_ci{
304bf215546Sopenharmony_ci   unsigned idx = scene->tiles_x * y + x;
305bf215546Sopenharmony_ci   return &scene->tiles[idx];
306bf215546Sopenharmony_ci}
307bf215546Sopenharmony_ci
308bf215546Sopenharmony_ci
309bf215546Sopenharmony_ci/** Remove all commands from a bin */
310bf215546Sopenharmony_civoid
311bf215546Sopenharmony_cilp_scene_bin_reset(struct lp_scene *scene, unsigned x, unsigned y);
312bf215546Sopenharmony_ci
313bf215546Sopenharmony_ci
314bf215546Sopenharmony_ci/* Add a command to bin[x][y].
315bf215546Sopenharmony_ci */
316bf215546Sopenharmony_cistatic inline boolean
317bf215546Sopenharmony_cilp_scene_bin_command(struct lp_scene *scene,
318bf215546Sopenharmony_ci                     unsigned x, unsigned y,
319bf215546Sopenharmony_ci                     enum lp_rast_op cmd,
320bf215546Sopenharmony_ci                     union lp_rast_cmd_arg arg)
321bf215546Sopenharmony_ci{
322bf215546Sopenharmony_ci   struct cmd_bin *bin = lp_scene_get_bin(scene, x, y);
323bf215546Sopenharmony_ci   struct cmd_block *tail = bin->tail;
324bf215546Sopenharmony_ci
325bf215546Sopenharmony_ci   assert(x < scene->tiles_x);
326bf215546Sopenharmony_ci   assert(y < scene->tiles_y);
327bf215546Sopenharmony_ci   assert(cmd < LP_RAST_OP_MAX);
328bf215546Sopenharmony_ci
329bf215546Sopenharmony_ci   if (tail == NULL || tail->count == CMD_BLOCK_MAX) {
330bf215546Sopenharmony_ci      tail = lp_scene_new_cmd_block(scene, bin);
331bf215546Sopenharmony_ci      if (!tail) {
332bf215546Sopenharmony_ci         return FALSE;
333bf215546Sopenharmony_ci      }
334bf215546Sopenharmony_ci      assert(tail->count == 0);
335bf215546Sopenharmony_ci   }
336bf215546Sopenharmony_ci
337bf215546Sopenharmony_ci   {
338bf215546Sopenharmony_ci      unsigned i = tail->count;
339bf215546Sopenharmony_ci      tail->cmd[i] = cmd & LP_RAST_OP_MASK;
340bf215546Sopenharmony_ci      tail->arg[i] = arg;
341bf215546Sopenharmony_ci      tail->count++;
342bf215546Sopenharmony_ci   }
343bf215546Sopenharmony_ci
344bf215546Sopenharmony_ci   return TRUE;
345bf215546Sopenharmony_ci}
346bf215546Sopenharmony_ci
347bf215546Sopenharmony_ci
348bf215546Sopenharmony_cistatic inline boolean
349bf215546Sopenharmony_cilp_scene_bin_cmd_with_state(struct lp_scene *scene,
350bf215546Sopenharmony_ci                            unsigned x, unsigned y,
351bf215546Sopenharmony_ci                            const struct lp_rast_state *state,
352bf215546Sopenharmony_ci                            enum lp_rast_op cmd,
353bf215546Sopenharmony_ci                            union lp_rast_cmd_arg arg)
354bf215546Sopenharmony_ci{
355bf215546Sopenharmony_ci   struct cmd_bin *bin = lp_scene_get_bin(scene, x, y);
356bf215546Sopenharmony_ci
357bf215546Sopenharmony_ci   if (state != bin->last_state) {
358bf215546Sopenharmony_ci      bin->last_state = state;
359bf215546Sopenharmony_ci      if (!lp_scene_bin_command(scene, x, y,
360bf215546Sopenharmony_ci                                LP_RAST_OP_SET_STATE,
361bf215546Sopenharmony_ci                                lp_rast_arg_state(state)))
362bf215546Sopenharmony_ci         return FALSE;
363bf215546Sopenharmony_ci   }
364bf215546Sopenharmony_ci
365bf215546Sopenharmony_ci   if (!lp_scene_bin_command(scene, x, y, cmd, arg))
366bf215546Sopenharmony_ci      return FALSE;
367bf215546Sopenharmony_ci
368bf215546Sopenharmony_ci   return TRUE;
369bf215546Sopenharmony_ci}
370bf215546Sopenharmony_ci
371bf215546Sopenharmony_ci
372bf215546Sopenharmony_ci/* Add a command to all active bins.
373bf215546Sopenharmony_ci */
374bf215546Sopenharmony_cistatic inline boolean
375bf215546Sopenharmony_cilp_scene_bin_everywhere(struct lp_scene *scene,
376bf215546Sopenharmony_ci                        enum lp_rast_op cmd,
377bf215546Sopenharmony_ci                        const union lp_rast_cmd_arg arg)
378bf215546Sopenharmony_ci{
379bf215546Sopenharmony_ci   for (unsigned i = 0; i < scene->tiles_x; i++) {
380bf215546Sopenharmony_ci      for (unsigned j = 0; j < scene->tiles_y; j++) {
381bf215546Sopenharmony_ci         if (!lp_scene_bin_command(scene, i, j, cmd, arg))
382bf215546Sopenharmony_ci            return FALSE;
383bf215546Sopenharmony_ci      }
384bf215546Sopenharmony_ci   }
385bf215546Sopenharmony_ci
386bf215546Sopenharmony_ci   return TRUE;
387bf215546Sopenharmony_ci}
388bf215546Sopenharmony_ci
389bf215546Sopenharmony_ci
390bf215546Sopenharmony_cistatic inline unsigned
391bf215546Sopenharmony_cilp_scene_get_num_bins(const struct lp_scene *scene)
392bf215546Sopenharmony_ci{
393bf215546Sopenharmony_ci   return scene->tiles_x * scene->tiles_y;
394bf215546Sopenharmony_ci}
395bf215546Sopenharmony_ci
396bf215546Sopenharmony_ci
397bf215546Sopenharmony_civoid
398bf215546Sopenharmony_cilp_scene_bin_iter_begin(struct lp_scene *scene);
399bf215546Sopenharmony_ci
400bf215546Sopenharmony_cistruct cmd_bin *
401bf215546Sopenharmony_cilp_scene_bin_iter_next(struct lp_scene *scene, int *x, int *y);
402bf215546Sopenharmony_ci
403bf215546Sopenharmony_ci
404bf215546Sopenharmony_ci
405bf215546Sopenharmony_ci/* Begin/end binning of a scene
406bf215546Sopenharmony_ci */
407bf215546Sopenharmony_civoid
408bf215546Sopenharmony_cilp_scene_begin_binning(struct lp_scene *scene,
409bf215546Sopenharmony_ci                       struct pipe_framebuffer_state *fb);
410bf215546Sopenharmony_ci
411bf215546Sopenharmony_civoid
412bf215546Sopenharmony_cilp_scene_end_binning(struct lp_scene *scene);
413bf215546Sopenharmony_ci
414bf215546Sopenharmony_ci
415bf215546Sopenharmony_ci/* Begin/end rasterization of a scene
416bf215546Sopenharmony_ci */
417bf215546Sopenharmony_civoid
418bf215546Sopenharmony_cilp_scene_begin_rasterization(struct lp_scene *scene);
419bf215546Sopenharmony_ci
420bf215546Sopenharmony_civoid
421bf215546Sopenharmony_cilp_scene_end_rasterization(struct lp_scene *scene);
422bf215546Sopenharmony_ci
423bf215546Sopenharmony_ci
424bf215546Sopenharmony_ci#endif /* LP_BIN_H */
425