radeonsi: add a debug flag for unsafe math LLVM optimizations
[mesa.git] / src / gallium / drivers / radeon / r600_pipe_common.h
index c300c0b3332da721b311ca3b043cabe988139016..c0e4282c23f899b7776aca2681f6c8f644a5597f 100644 (file)
 #include "util/u_suballoc.h"
 #include "util/u_transfer.h"
 
+#define ATI_VENDOR_ID 0x1002
+
 #define R600_RESOURCE_FLAG_TRANSFER            (PIPE_RESOURCE_FLAG_DRV_PRIV << 0)
 #define R600_RESOURCE_FLAG_FLUSHED_DEPTH       (PIPE_RESOURCE_FLAG_DRV_PRIV << 1)
 #define R600_RESOURCE_FLAG_FORCE_TILING                (PIPE_RESOURCE_FLAG_DRV_PRIV << 2)
-
-#define R600_QUERY_DRAW_CALLS          (PIPE_QUERY_DRIVER_SPECIFIC + 0)
-#define R600_QUERY_REQUESTED_VRAM      (PIPE_QUERY_DRIVER_SPECIFIC + 1)
-#define R600_QUERY_REQUESTED_GTT       (PIPE_QUERY_DRIVER_SPECIFIC + 2)
-#define R600_QUERY_BUFFER_WAIT_TIME    (PIPE_QUERY_DRIVER_SPECIFIC + 3)
-#define R600_QUERY_NUM_CS_FLUSHES      (PIPE_QUERY_DRIVER_SPECIFIC + 4)
-#define R600_QUERY_NUM_BYTES_MOVED     (PIPE_QUERY_DRIVER_SPECIFIC + 5)
-#define R600_QUERY_VRAM_USAGE          (PIPE_QUERY_DRIVER_SPECIFIC + 6)
-#define R600_QUERY_GTT_USAGE           (PIPE_QUERY_DRIVER_SPECIFIC + 7)
-#define R600_QUERY_GPU_TEMPERATURE     (PIPE_QUERY_DRIVER_SPECIFIC + 8)
-#define R600_QUERY_CURRENT_GPU_SCLK    (PIPE_QUERY_DRIVER_SPECIFIC + 9)
-#define R600_QUERY_CURRENT_GPU_MCLK    (PIPE_QUERY_DRIVER_SPECIFIC + 10)
-#define R600_QUERY_GPU_LOAD            (PIPE_QUERY_DRIVER_SPECIFIC + 11)
-#define R600_QUERY_NUM_COMPILATIONS    (PIPE_QUERY_DRIVER_SPECIFIC + 12)
-#define R600_QUERY_NUM_SHADERS_CREATED (PIPE_QUERY_DRIVER_SPECIFIC + 13)
+#define R600_RESOURCE_FLAG_DISABLE_DCC         (PIPE_RESOURCE_FLAG_DRV_PRIV << 3)
 
 #define R600_CONTEXT_STREAMOUT_FLUSH           (1u << 0)
-#define R600_CONTEXT_PRIVATE_FLAG              (1u << 1)
+/* Pipeline & streamout query controls. */
+#define R600_CONTEXT_START_PIPELINE_STATS      (1u << 1)
+#define R600_CONTEXT_STOP_PIPELINE_STATS       (1u << 2)
+#define R600_CONTEXT_PRIVATE_FLAG              (1u << 3)
 
 /* special primitive types */
 #define R600_PRIM_RECTANGLE_LIST       PIPE_PRIM_MAX
 /* Debug flags. */
 /* logging */
 #define DBG_TEX                        (1 << 0)
-#define DBG_TEXMIP             (1 << 1)
+/* gap - reuse */
 #define DBG_COMPUTE            (1 << 2)
 #define DBG_VM                 (1 << 3)
-#define DBG_TRACE_CS           (1 << 4)
+/* gap - reuse */
 /* shader logging */
 #define DBG_FS                 (1 << 5)
 #define DBG_VS                 (1 << 6)
@@ -86,6 +77,9 @@
 #define DBG_NO_IR              (1 << 12)
 #define DBG_NO_TGSI            (1 << 13)
 #define DBG_NO_ASM             (1 << 14)
+#define DBG_PREOPT_IR          (1 << 15)
+/* gaps */
+#define DBG_TEST_DMA           (1 << 20)
 /* Bits 21-31 are reserved for the r600g driver. */
 /* features */
 #define DBG_NO_ASYNC_DMA       (1llu << 32)
 #define DBG_CHECK_VM           (1llu << 42)
 #define DBG_NO_DCC             (1llu << 43)
 #define DBG_NO_DCC_CLEAR       (1llu << 44)
+#define DBG_NO_RB_PLUS         (1llu << 45)
+#define DBG_SI_SCHED           (1llu << 46)
+#define DBG_MONOLITHIC_SHADERS (1llu << 47)
+#define DBG_NO_CE              (1llu << 48)
+#define DBG_UNSAFE_MATH                (1llu << 49)
 
 #define R600_MAP_BUFFER_ALIGNMENT 64
+#define R600_MAX_VIEWPORTS        16
+
+enum r600_coherency {
+       R600_COHERENCY_NONE, /* no cache flushes needed */
+       R600_COHERENCY_SHADER,
+       R600_COHERENCY_CB_META,
+};
+
+#ifdef PIPE_ARCH_BIG_ENDIAN
+#define R600_BIG_ENDIAN 1
+#else
+#define R600_BIG_ENDIAN 0
+#endif
 
 struct r600_common_context;
+struct r600_perfcounters;
+struct tgsi_shader_info;
 
 struct radeon_shader_reloc {
-       char *name;
+       char name[32];
        uint64_t offset;
 };
 
@@ -142,12 +156,17 @@ struct radeon_shader_binary {
        char *disasm_string;
 };
 
+void radeon_shader_binary_init(struct radeon_shader_binary *b);
+void radeon_shader_binary_clean(struct radeon_shader_binary *b);
+
+/* Only 32-bit buffer allocations are supported, gallium doesn't support more
+ * at the moment.
+ */
 struct r600_resource {
        struct u_resource               b;
 
        /* Winsys objects. */
        struct pb_buffer                *buf;
-       struct radeon_winsys_cs_handle  *cs_buf;
        uint64_t                        gpu_address;
 
        /* Resource state. */
@@ -174,6 +193,10 @@ struct r600_resource {
         * use TC L2.
         */
        bool                            TC_L2_dirty;
+
+       /* Whether the resource has been exported via resource_get_handle. */
+       bool                            is_shared;
+       unsigned                        external_usage; /* PIPE_HANDLE_USAGE_* */
 };
 
 struct r600_transfer {
@@ -183,28 +206,39 @@ struct r600_transfer {
 };
 
 struct r600_fmask_info {
-       unsigned offset;
-       unsigned size;
+       uint64_t offset;
+       uint64_t size;
        unsigned alignment;
-       unsigned pitch;
+       unsigned pitch_in_pixels;
        unsigned bank_height;
        unsigned slice_tile_max;
        unsigned tile_mode_index;
 };
 
 struct r600_cmask_info {
-       unsigned offset;
-       unsigned size;
+       uint64_t offset;
+       uint64_t size;
        unsigned alignment;
+       unsigned pitch;
+       unsigned height;
+       unsigned xalign;
+       unsigned yalign;
        unsigned slice_tile_max;
        unsigned base_address_reg;
 };
 
+struct r600_htile_info {
+       unsigned pitch;
+       unsigned height;
+       unsigned xalign;
+       unsigned yalign;
+};
+
 struct r600_texture {
        struct r600_resource            resource;
 
-       unsigned                        size;
-       unsigned                        pitch_override;
+       uint64_t                        size;
+       unsigned                        num_level0_transfers;
        bool                            is_depth;
        unsigned                        dirty_level_mask; /* each bit says if that mipmap is compressed */
        unsigned                        stencil_dirty_level_mask; /* each bit says if that mipmap is compressed */
@@ -216,20 +250,30 @@ struct r600_texture {
        struct r600_fmask_info          fmask;
        struct r600_cmask_info          cmask;
        struct r600_resource            *cmask_buffer;
-       struct r600_resource            *dcc_buffer;
+       uint64_t                        dcc_offset; /* 0 = disabled */
        unsigned                        cb_color_info; /* fast clear enable bit */
        unsigned                        color_clear_value[2];
+       unsigned                        last_msaa_resolve_target_micro_mode;
 
        /* Depth buffer compression and fast clear. */
+       struct r600_htile_info          htile;
        struct r600_resource            *htile_buffer;
        bool                            depth_cleared; /* if it was cleared at least once */
        float                           depth_clear_value;
+       bool                            stencil_cleared; /* if it was cleared at least once */
+       uint8_t                         stencil_clear_value;
 
        bool                            non_disp_tiling; /* R600-Cayman only */
+
+       /* Counter that should be non-zero if the texture is bound to a
+        * framebuffer. Implemented in radeonsi only.
+        */
+       uint32_t                        framebuffers_bound;
 };
 
 struct r600_surface {
        struct pipe_surface             base;
+       const struct radeon_surf_level  *level_info;
 
        bool color_initialized;
        bool depth_initialized;
@@ -237,6 +281,7 @@ struct r600_surface {
        /* Misc. color flags. */
        bool alphatest_bypass;
        bool export_16bpc;
+       bool color_is_int8;
 
        /* Color registers. */
        unsigned cb_color_info;
@@ -246,13 +291,16 @@ struct r600_surface {
        unsigned cb_color_dim;          /* EG only */
        unsigned cb_color_pitch;        /* EG and later */
        unsigned cb_color_slice;        /* EG and later */
-       unsigned cb_dcc_base;           /* VI and later */
        unsigned cb_color_attrib;       /* EG and later */
        unsigned cb_dcc_control;        /* VI and later */
        unsigned cb_color_fmask;        /* CB_COLORn_FMASK (EG and later) or CB_COLORn_FRAG (r600) */
        unsigned cb_color_fmask_slice;  /* EG and later */
        unsigned cb_color_cmask;        /* CB_COLORn_TILE (r600 only) */
        unsigned cb_color_mask;         /* R600 only */
+       unsigned spi_shader_col_format;         /* SI+, no blending, no alpha-to-coverage. */
+       unsigned spi_shader_col_format_alpha;   /* SI+, alpha-to-coverage */
+       unsigned spi_shader_col_format_blend;   /* SI+, blending without alpha. */
+       unsigned spi_shader_col_format_blend_alpha; /* SI+, blending with alpha. */
        struct r600_resource *cb_buffer_fmask; /* Used for FMASK relocations. R600 only */
        struct r600_resource *cb_buffer_cmask; /* Used for CMASK relocations. R600 only */
 
@@ -272,32 +320,24 @@ struct r600_surface {
        unsigned pa_su_poly_offset_db_fmt_cntl;
 };
 
-struct r600_tiling_info {
-       unsigned num_channels;
-       unsigned num_banks;
-       unsigned group_bytes;
-};
-
 struct r600_common_screen {
        struct pipe_screen              b;
        struct radeon_winsys            *ws;
        enum radeon_family              family;
        enum chip_class                 chip_class;
        struct radeon_info              info;
-       struct r600_tiling_info         tiling_info;
        uint64_t                        debug_flags;
        bool                            has_cp_dma;
        bool                            has_streamout;
 
+       /* Texture filter settings. */
+       int                             force_aniso; /* -1 = disabled */
+
        /* Auxiliary context. Mainly used to initialize resources.
         * It must be locked prior to using and flushed before unlocking. */
        struct pipe_context             *aux_context;
        pipe_mutex                      aux_context_lock;
 
-       struct r600_resource            *trace_bo;
-       uint32_t                        *trace_ptr;
-       unsigned                        cs_count;
-
        /* This must be in the screen, because UE4 uses one context for
         * compilation and another one for rendering.
         */
@@ -315,6 +355,36 @@ struct r600_common_screen {
        volatile unsigned               gpu_load_stop_thread; /* bool */
 
        char                            renderer_string[64];
+
+       /* Performance counters. */
+       struct r600_perfcounters        *perfcounters;
+
+       /* If pipe_screen wants to re-emit the framebuffer state of all
+        * contexts, it should atomically increment this. Each context will
+        * compare this with its own last known value of the counter before
+        * drawing and re-emit the framebuffer state accordingly.
+        */
+       unsigned                        dirty_fb_counter;
+
+       /* Atomically increment this counter when an existing texture's
+        * metadata is enabled or disabled in a way that requires changing
+        * contexts' compressed texture binding masks.
+        */
+       unsigned                        compressed_colortex_counter;
+
+       /* Atomically increment this counter when an existing texture's
+        * backing buffer or tile mode parameters have changed that requires
+        * recomputation of shader descriptors.
+        */
+       unsigned                        dirty_tex_descriptor_counter;
+
+       void (*query_opaque_metadata)(struct r600_common_screen *rscreen,
+                                     struct r600_texture *rtex,
+                                     struct radeon_bo_metadata *md);
+
+       void (*apply_opaque_metadata)(struct r600_common_screen *rscreen,
+                                   struct r600_texture *rtex,
+                                   struct radeon_bo_metadata *md);
 };
 
 /* This encapsulates a state or an operation which can emitted into the GPU
@@ -363,18 +433,32 @@ struct r600_streamout {
        int                             num_prims_gen_queries;
 };
 
+struct r600_signed_scissor {
+       int minx;
+       int miny;
+       int maxx;
+       int maxy;
+};
+
+struct r600_scissors {
+       struct r600_atom                atom;
+       unsigned                        dirty_mask;
+       struct pipe_scissor_state       states[R600_MAX_VIEWPORTS];
+};
+
+struct r600_viewports {
+       struct r600_atom                atom;
+       unsigned                        dirty_mask;
+       struct pipe_viewport_state      states[R600_MAX_VIEWPORTS];
+       struct r600_signed_scissor      as_scissor[R600_MAX_VIEWPORTS];
+};
+
 struct r600_ring {
        struct radeon_winsys_cs         *cs;
-       bool                            flushing;
        void (*flush)(void *ctx, unsigned flags,
                      struct pipe_fence_handle **fence);
 };
 
-struct r600_rings {
-       struct r600_ring                gfx;
-       struct r600_ring                dma;
-};
-
 struct r600_common_context {
        struct pipe_context b; /* base class */
 
@@ -383,12 +467,17 @@ struct r600_common_context {
        struct radeon_winsys_ctx        *ctx;
        enum radeon_family              family;
        enum chip_class                 chip_class;
-       struct r600_rings               rings;
+       struct r600_ring                gfx;
+       struct r600_ring                dma;
+       struct pipe_fence_handle        *last_sdma_fence;
        unsigned                        initial_gfx_cs_size;
        unsigned                        gpu_reset_counter;
+       unsigned                        last_dirty_fb_counter;
+       unsigned                        last_compressed_colortex_counter;
+       unsigned                        last_dirty_tex_descriptor_counter;
 
        struct u_upload_mgr             *uploader;
-       struct u_suballocator           *allocator_so_filled_size;
+       struct u_suballocator           *allocator_zeroed_memory;
        struct util_slab_mempool        pool_transfers;
 
        /* Current unaccounted memory usage. */
@@ -397,38 +486,38 @@ struct r600_common_context {
 
        /* States. */
        struct r600_streamout           streamout;
+       struct r600_scissors            scissors;
+       struct r600_viewports           viewports;
+       bool                            scissor_enabled;
+       bool                            vs_writes_viewport_index;
+       bool                            vs_disables_clipping_viewport;
 
        /* Additional context states. */
        unsigned flags; /* flush flags */
 
        /* Queries. */
-       /* The list of active queries. Only one query of each type can be active. */
+       /* Maintain the list of active queries for pausing between IBs. */
        int                             num_occlusion_queries;
-       /* Keep track of non-timer queries, because they should be suspended
-        * during context flushing.
-        * The timer queries (TIME_ELAPSED) shouldn't be suspended for blits,
-        * but they should be suspended between IBs. */
-       struct list_head                active_nontimer_queries;
-       struct list_head                active_timer_queries;
-       unsigned                        num_cs_dw_nontimer_queries_suspend;
-       unsigned                        num_cs_dw_timer_queries_suspend;
-       /* If queries have been suspended. */
-       bool                            queries_suspended_for_flush;
+       int                             num_perfect_occlusion_queries;
+       struct list_head                active_queries;
+       unsigned                        num_cs_dw_queries_suspend;
        /* Additional hardware info. */
        unsigned                        backend_mask;
        unsigned                        max_db; /* for OQ */
        /* Misc stats. */
        unsigned                        num_draw_calls;
+       unsigned                        num_spill_draw_calls;
+       unsigned                        num_compute_calls;
+       unsigned                        num_spill_compute_calls;
+       unsigned                        num_dma_calls;
+       uint64_t                        num_alloc_tex_transfer_bytes;
 
        /* Render condition. */
-       struct pipe_query               *current_render_cond;
-       unsigned                        current_render_cond_mode;
-       boolean                         current_render_cond_cond;
-       boolean                         predicate_drawing;
-       /* For context flushing. */
-       struct pipe_query               *saved_render_cond;
-       boolean                         saved_render_cond_cond;
-       unsigned                        saved_render_cond_mode;
+       struct r600_atom                render_cond_atom;
+       struct pipe_query               *render_cond;
+       unsigned                        render_cond_mode;
+       boolean                         render_cond_invert;
+       bool                            render_cond_force_off; /* for u_blitter */
 
        /* MSAA sample locations.
         * The first index is the sample index.
@@ -444,6 +533,8 @@ struct r600_common_context {
         * the GPU addresses are updated. */
        struct list_head                texture_buffers;
 
+       struct pipe_debug_callback      debug;
+
        /* Copy one resource to another using async DMA. */
        void (*dma_copy)(struct pipe_context *ctx,
                         struct pipe_resource *dst,
@@ -454,8 +545,8 @@ struct r600_common_context {
                         const struct pipe_box *src_box);
 
        void (*clear_buffer)(struct pipe_context *ctx, struct pipe_resource *dst,
-                            unsigned offset, unsigned size, unsigned value,
-                            bool is_framebuffer);
+                            uint64_t offset, uint64_t size, unsigned value,
+                            enum r600_coherency coher);
 
        void (*blit_decompress_depth)(struct pipe_context *ctx,
                                      struct r600_texture *texture,
@@ -464,6 +555,9 @@ struct r600_common_context {
                                      unsigned first_layer, unsigned last_layer,
                                      unsigned first_sample, unsigned last_sample);
 
+       void (*decompress_dcc)(struct pipe_context *ctx,
+                              struct r600_texture *rtex);
+
        /* Reallocate the buffer and update all resource bindings where
         * the buffer is bound, including all resource descriptors. */
        void (*invalidate_buffer)(struct pipe_context *ctx, struct pipe_resource *buf);
@@ -481,15 +575,14 @@ struct r600_common_context {
 
 /* r600_buffer.c */
 boolean r600_rings_is_buffer_referenced(struct r600_common_context *ctx,
-                                       struct radeon_winsys_cs_handle *buf,
+                                       struct pb_buffer *buf,
                                        enum radeon_bo_usage usage);
 void *r600_buffer_map_sync_with_rings(struct r600_common_context *ctx,
                                       struct r600_resource *resource,
                                       unsigned usage);
 bool r600_init_resource(struct r600_common_screen *rscreen,
                        struct r600_resource *res,
-                       unsigned size, unsigned alignment,
-                       bool use_reusable_pool);
+                       uint64_t size, unsigned alignment);
 struct pipe_resource *r600_buffer_create(struct pipe_screen *screen,
                                         const struct pipe_resource *templ,
                                         unsigned alignment);
@@ -502,6 +595,9 @@ struct pipe_resource *
 r600_buffer_from_user_memory(struct pipe_screen *screen,
                             const struct pipe_resource *templ,
                             void *user_memory);
+void
+r600_invalidate_resource(struct pipe_context *ctx,
+                        struct pipe_resource *resource);
 
 /* r600_common_pipe.c */
 void r600_draw_rectangle(struct blitter_context *blitter,
@@ -518,26 +614,30 @@ bool r600_common_context_init(struct r600_common_context *rctx,
 void r600_common_context_cleanup(struct r600_common_context *rctx);
 void r600_context_add_resource_size(struct pipe_context *ctx, struct pipe_resource *r);
 bool r600_can_dump_shader(struct r600_common_screen *rscreen,
-                         const struct tgsi_token *tokens);
+                         unsigned processor);
 void r600_screen_clear_buffer(struct r600_common_screen *rscreen, struct pipe_resource *dst,
-                             unsigned offset, unsigned size, unsigned value,
-                             bool is_framebuffer);
+                             uint64_t offset, uint64_t size, unsigned value,
+                             enum r600_coherency coher);
 struct pipe_resource *r600_resource_create_common(struct pipe_screen *screen,
                                                  const struct pipe_resource *templ);
 const char *r600_get_llvm_processor_name(enum radeon_family family);
-void r600_need_dma_space(struct r600_common_context *ctx, unsigned num_dw);
+void r600_need_dma_space(struct r600_common_context *ctx, unsigned num_dw,
+                        struct r600_resource *dst, struct r600_resource *src);
+void r600_dma_emit_wait_idle(struct r600_common_context *rctx);
 
 /* r600_gpu_load.c */
 void r600_gpu_load_kill_thread(struct r600_common_screen *rscreen);
 uint64_t r600_gpu_load_begin(struct r600_common_screen *rscreen);
 unsigned r600_gpu_load_end(struct r600_common_screen *rscreen, uint64_t begin);
 
+/* r600_perfcounters.c */
+void r600_perfcounters_destroy(struct r600_common_screen *rscreen);
+
 /* r600_query.c */
+void r600_init_screen_query_functions(struct r600_common_screen *rscreen);
 void r600_query_init(struct r600_common_context *rctx);
-void r600_suspend_nontimer_queries(struct r600_common_context *ctx);
-void r600_resume_nontimer_queries(struct r600_common_context *ctx);
-void r600_suspend_timer_queries(struct r600_common_context *ctx);
-void r600_resume_timer_queries(struct r600_common_context *ctx);
+void r600_suspend_queries(struct r600_common_context *ctx);
+void r600_resume_queries(struct r600_common_context *ctx);
 void r600_query_init_backend_mask(struct r600_common_context *ctx);
 
 /* r600_streamout.c */
@@ -551,7 +651,17 @@ void r600_update_prims_generated_query_state(struct r600_common_context *rctx,
                                             unsigned type, int diff);
 void r600_streamout_init(struct r600_common_context *rctx);
 
+/* r600_test_dma.c */
+void r600_test_dma(struct r600_common_screen *rscreen);
+
 /* r600_texture.c */
+bool r600_prepare_for_dma_blit(struct r600_common_context *rctx,
+                               struct r600_texture *rdst,
+                               unsigned dst_level, unsigned dstx,
+                               unsigned dsty, unsigned dstz,
+                               struct r600_texture *rsrc,
+                               unsigned src_level,
+                               const struct pipe_box *src_box);
 void r600_texture_get_fmask_info(struct r600_common_screen *rscreen,
                                 struct r600_texture *rtex,
                                 unsigned nr_samples,
@@ -562,21 +672,35 @@ void r600_texture_get_cmask_info(struct r600_common_screen *rscreen,
 bool r600_init_flushed_depth_texture(struct pipe_context *ctx,
                                     struct pipe_resource *texture,
                                     struct r600_texture **staging);
+void r600_print_texture_info(struct r600_texture *rtex, FILE *f);
 struct pipe_resource *r600_texture_create(struct pipe_screen *screen,
                                        const struct pipe_resource *templ);
 struct pipe_surface *r600_create_surface_custom(struct pipe_context *pipe,
                                                struct pipe_resource *texture,
                                                const struct pipe_surface *templ,
                                                unsigned width, unsigned height);
-unsigned r600_translate_colorswap(enum pipe_format format);
+unsigned r600_translate_colorswap(enum pipe_format format, bool do_endian_swap);
+void vi_dcc_clear_level(struct r600_common_context *rctx,
+                       struct r600_texture *rtex,
+                       unsigned level, unsigned clear_value);
 void evergreen_do_fast_color_clear(struct r600_common_context *rctx,
                                   struct pipe_framebuffer_state *fb,
                                   struct r600_atom *fb_state,
                                   unsigned *buffers, unsigned *dirty_cbufs,
                                   const union pipe_color_union *color);
+bool r600_texture_disable_dcc(struct r600_common_screen *rscreen,
+                             struct r600_texture *rtex);
 void r600_init_screen_texture_functions(struct r600_common_screen *rscreen);
 void r600_init_context_texture_functions(struct r600_common_context *rctx);
 
+/* r600_viewport.c */
+void evergreen_apply_scissor_bug_workaround(struct r600_common_context *rctx,
+                                           struct pipe_scissor_state *scissor);
+void r600_set_scissor_enable(struct r600_common_context *rctx, bool enable);
+void r600_update_vs_writes_viewport_index(struct r600_common_context *rctx,
+                                         struct tgsi_shader_info *info);
+void r600_init_viewport_functions(struct r600_common_context *rctx);
+
 /* cayman_msaa.c */
 extern const uint32_t eg_sample_locs_2x[4];
 extern const unsigned eg_max_dist_2x;
@@ -604,13 +728,38 @@ r600_resource_reference(struct r600_resource **ptr, struct r600_resource *res)
                                (struct pipe_resource *)res);
 }
 
+static inline bool r600_get_strmout_en(struct r600_common_context *rctx)
+{
+       return rctx->streamout.streamout_enabled ||
+              rctx->streamout.prims_gen_query_enabled;
+}
+
+#define     SQ_TEX_XY_FILTER_POINT                         0x00
+#define     SQ_TEX_XY_FILTER_BILINEAR                      0x01
+#define     SQ_TEX_XY_FILTER_ANISO_POINT                   0x02
+#define     SQ_TEX_XY_FILTER_ANISO_BILINEAR                0x03
+
+static inline unsigned eg_tex_filter(unsigned filter, unsigned max_aniso)
+{
+       if (filter == PIPE_TEX_FILTER_LINEAR)
+               return max_aniso > 1 ? SQ_TEX_XY_FILTER_ANISO_BILINEAR
+                                    : SQ_TEX_XY_FILTER_BILINEAR;
+       else
+               return max_aniso > 1 ? SQ_TEX_XY_FILTER_ANISO_POINT
+                                    : SQ_TEX_XY_FILTER_POINT;
+}
+
 static inline unsigned r600_tex_aniso_filter(unsigned filter)
 {
-       if (filter <= 1)   return 0;
-       if (filter <= 2)   return 1;
-       if (filter <= 4)   return 2;
-       if (filter <= 8)   return 3;
-        /* else */        return 4;
+       if (filter < 2)
+               return 0;
+       if (filter < 4)
+               return 1;
+       if (filter < 8)
+               return 2;
+       if (filter < 16)
+               return 3;
+       return 4;
 }
 
 static inline unsigned r600_wavefront_size(enum radeon_family family)
@@ -651,13 +800,13 @@ r600_get_sampler_view_priority(struct r600_resource *res)
        } while (0);
 
 #define R600_ERR(fmt, args...) \
-       fprintf(stderr, "EE %s:%d %s - "fmt, __FILE__, __LINE__, __func__, ##args)
+       fprintf(stderr, "EE %s:%d %s - " fmt, __FILE__, __LINE__, __func__, ##args)
 
 /* For MSAA sample positions. */
 #define FILL_SREG(s0x, s0y, s1x, s1y, s2x, s2y, s3x, s3y)  \
-       (((s0x) & 0xf) | (((s0y) & 0xf) << 4) |            \
-       (((s1x) & 0xf) << 8) | (((s1y) & 0xf) << 12) |     \
-       (((s2x) & 0xf) << 16) | (((s2y) & 0xf) << 20) |    \
-        (((s3x) & 0xf) << 24) | (((s3y) & 0xf) << 28))
+       (((s0x) & 0xf) | (((unsigned)(s0y) & 0xf) << 4) |                  \
+       (((unsigned)(s1x) & 0xf) << 8) | (((unsigned)(s1y) & 0xf) << 12) |         \
+       (((unsigned)(s2x) & 0xf) << 16) | (((unsigned)(s2y) & 0xf) << 20) |        \
+        (((unsigned)(s3x) & 0xf) << 24) | (((unsigned)(s3y) & 0xf) << 28))
 
 #endif