gv100/ir: fix coherent and volatile memory access
[mesa.git] / src / gallium / drivers / llvmpipe / lp_scene.h
index cc19def3b111605b8898c2c8fe759e1e6be6feed..679e2c07b28c1c0382c7c524a94c79a2720cac23 100644 (file)
 #define LP_SCENE_H
 
 #include "os/os_thread.h"
-#include "lp_tile_soa.h"
 #include "lp_rast.h"
+#include "lp_debug.h"
 
 struct lp_scene_queue;
+struct lp_rast_state;
 
 /* We're limited to 2K by 2K for 32bit fixed point rasterization.
  * Will need a 64-bit version for larger framebuffers.
@@ -48,15 +49,21 @@ struct lp_scene_queue;
 #define TILES_Y (LP_MAX_HEIGHT / TILE_SIZE)
 
 
-#define CMD_BLOCK_MAX 16
-#define DATA_BLOCK_SIZE (64 * 1024 - 2 * sizeof(void *))
+/* Commands per command block (ideally so sizeof(cmd_block) is a power of
+ * two in size.)
+ */
+#define CMD_BLOCK_MAX 29
+
+/* Bytes per data block.
+ */
+#define DATA_BLOCK_SIZE (64 * 1024)
 
 /* Scene temporary storage is clamped to this size:
  */
-#define LP_SCENE_MAX_SIZE (1024*1024)
+#define LP_SCENE_MAX_SIZE (36*1024*1024)
 
 /* The maximum amount of texture storage referenced by a scene is
- * clamped ot this size:
+ * clamped to this size:
  */
 #define LP_SCENE_MAX_RESOURCE_SIZE (64*1024*1024)
 
@@ -74,10 +81,6 @@ struct cmd_block {
    struct cmd_block *next;
 };
 
-struct cmd_block_list {
-   struct cmd_block *head;
-   struct cmd_block *tail;
-};
 
 struct data_block {
    ubyte data[DATA_BLOCK_SIZE];
@@ -91,8 +94,7 @@ struct data_block {
  * For each screen tile we have one of these bins.
  */
 struct cmd_bin {
-   ushort x;
-   ushort y;
+   const struct lp_rast_state *last_state;       /* most recent state set in bin */
    struct cmd_block *head;
    struct cmd_block *tail;
 };
@@ -127,15 +129,33 @@ struct lp_scene {
    struct pipe_context *pipe;
    struct lp_fence *fence;
 
+   /* The queries still active at end of scene */
+   struct llvmpipe_query *active_queries[LP_MAX_ACTIVE_BINNED_QUERIES];
+   unsigned num_active_queries;
+   /* If queries were either active or there were begin/end query commands */
+   boolean had_queries;
+
    /* Framebuffer mappings - valid only between begin_rasterization()
     * and end_rasterization().
     */
    struct {
       uint8_t *map;
       unsigned stride;
-      unsigned blocksize;
+      unsigned layer_stride;
+      unsigned format_bytes;
+      unsigned sample_stride;
+      unsigned nr_samples;
    } zsbuf, cbufs[PIPE_MAX_COLOR_BUFS];
-   
+
+   /* The amount of layers in the fb (minimum of all attachments) */
+   unsigned fb_max_layer;
+
+   /* fixed point sample positions. */
+   int32_t fixed_sample_pos[LP_MAX_SAMPLES][2];
+
+   /* max samples for bound framebuffer */
+   unsigned fb_max_samples;
+
    /** the framebuffer to render the scene into */
    struct pipe_framebuffer_state fb;
 
@@ -154,8 +174,6 @@ struct lp_scene {
    unsigned resource_reference_size;
 
    boolean alloc_failed;
-   boolean has_depthstencil_clear;
-
    /**
     * Number of active tiles in each dimension.
     * This basically the framebuffer size divided by tile size
@@ -163,7 +181,7 @@ struct lp_scene {
    unsigned tiles_x, tiles_y;
 
    int curr_x, curr_y;  /**< for iterating over bins */
-   pipe_mutex mutex;
+   mtx_t mutex;
 
    struct cmd_bin tile[TILES_X][TILES_Y];
    struct data_block_list data;
@@ -196,7 +214,7 @@ boolean lp_scene_is_resource_referenced(const struct lp_scene *scene,
  * Allocate space for a command/data in the bin's data buffer.
  * Grow the block list if needed.
  */
-static INLINE void *
+static inline void *
 lp_scene_alloc( struct lp_scene *scene, unsigned size)
 {
    struct data_block_list *list = &scene->data;
@@ -205,6 +223,11 @@ lp_scene_alloc( struct lp_scene *scene, unsigned size)
    assert(size <= DATA_BLOCK_SIZE);
    assert(block != NULL);
 
+   if (LP_DEBUG & DEBUG_MEM)
+      debug_printf("alloc %u block %u/%u tot %u/%u\n",
+                  size, block->used, DATA_BLOCK_SIZE,
+                  scene->scene_size, LP_SCENE_MAX_SIZE);
+
    if (block->used + size > DATA_BLOCK_SIZE) {
       block = lp_scene_new_data_block( scene );
       if (!block) {
@@ -224,7 +247,7 @@ lp_scene_alloc( struct lp_scene *scene, unsigned size)
 /**
  * As above, but with specific alignment.
  */
-static INLINE void *
+static inline void *
 lp_scene_alloc_aligned( struct lp_scene *scene, unsigned size,
                        unsigned alignment )
 {
@@ -232,6 +255,12 @@ lp_scene_alloc_aligned( struct lp_scene *scene, unsigned size,
    struct data_block *block = list->head;
 
    assert(block != NULL);
+
+   if (LP_DEBUG & DEBUG_MEM)
+      debug_printf("alloc %u block %u/%u tot %u/%u\n",
+                  size + alignment - 1,
+                  block->used, DATA_BLOCK_SIZE,
+                  scene->scene_size, LP_SCENE_MAX_SIZE);
        
    if (block->used + size + alignment - 1 > DATA_BLOCK_SIZE) {
       block = lp_scene_new_data_block( scene );
@@ -250,7 +279,7 @@ lp_scene_alloc_aligned( struct lp_scene *scene, unsigned size,
 
 /* Put back data if we decide not to use it, eg. culled triangles.
  */
-static INLINE void
+static inline void
 lp_scene_putback_data( struct lp_scene *scene, unsigned size)
 {
    struct data_block_list *list = &scene->data;
@@ -260,7 +289,7 @@ lp_scene_putback_data( struct lp_scene *scene, unsigned size)
 
 
 /** Return pointer to a particular tile's bin. */
-static INLINE struct cmd_bin *
+static inline struct cmd_bin *
 lp_scene_get_bin(struct lp_scene *scene, unsigned x, unsigned y)
 {
    return &scene->tile[x][y];
@@ -274,7 +303,7 @@ lp_scene_bin_reset(struct lp_scene *scene, unsigned x, unsigned y);
 
 /* Add a command to bin[x][y].
  */
-static INLINE boolean
+static inline boolean
 lp_scene_bin_command( struct lp_scene *scene,
                       unsigned x, unsigned y,
                       unsigned cmd,
@@ -285,7 +314,7 @@ lp_scene_bin_command( struct lp_scene *scene,
 
    assert(x < scene->tiles_x);
    assert(y < scene->tiles_y);
-   assert(cmd <= LP_RAST_OP_END_QUERY);
+   assert(cmd < LP_RAST_OP_MAX);
 
    if (tail == NULL || tail->count == CMD_BLOCK_MAX) {
       tail = lp_scene_new_cmd_block( scene, bin );
@@ -306,9 +335,33 @@ lp_scene_bin_command( struct lp_scene *scene,
 }
 
 
+static inline boolean
+lp_scene_bin_cmd_with_state( struct lp_scene *scene,
+                             unsigned x, unsigned y,
+                             const struct lp_rast_state *state,
+                             unsigned cmd,
+                             union lp_rast_cmd_arg arg )
+{
+   struct cmd_bin *bin = lp_scene_get_bin(scene, x, y);
+
+   if (state != bin->last_state) {
+      bin->last_state = state;
+      if (!lp_scene_bin_command(scene, x, y,
+                                LP_RAST_OP_SET_STATE,
+                                lp_rast_arg_state(state)))
+         return FALSE;
+   }
+
+   if (!lp_scene_bin_command( scene, x, y, cmd, arg ))
+      return FALSE;
+
+   return TRUE;
+}
+
+
 /* Add a command to all active bins.
  */
-static INLINE boolean
+static inline boolean
 lp_scene_bin_everywhere( struct lp_scene *scene,
                         unsigned cmd,
                         const union lp_rast_cmd_arg arg )
@@ -325,7 +378,7 @@ lp_scene_bin_everywhere( struct lp_scene *scene,
 }
 
 
-static INLINE unsigned
+static inline unsigned
 lp_scene_get_num_bins( const struct lp_scene *scene )
 {
    return scene->tiles_x * scene->tiles_y;
@@ -336,18 +389,18 @@ void
 lp_scene_bin_iter_begin( struct lp_scene *scene );
 
 struct cmd_bin *
-lp_scene_bin_iter_next( struct lp_scene *scene );
+lp_scene_bin_iter_next( struct lp_scene *scene, int *x, int *y );
 
 
 
 /* Begin/end binning of a scene
  */
 void
-lp_scene_begin_binning( struct lp_scene *scene,
-                        struct pipe_framebuffer_state *fb );
+lp_scene_begin_binning(struct lp_scene *scene,
+                       struct pipe_framebuffer_state *fb);
 
 void
-lp_scene_end_binning( struct lp_scene *scene );
+lp_scene_end_binning(struct lp_scene *scene);
 
 
 /* Begin/end rasterization of a scene
@@ -356,7 +409,7 @@ void
 lp_scene_begin_rasterization(struct lp_scene *scene);
 
 void
-lp_scene_end_rasterization(struct lp_scene *scene );
+lp_scene_end_rasterization(struct lp_scene *scene);