gallivm: Translate all util_cpu_caps bits to LLVM attributes.
[mesa.git] / src / gallium / auxiliary / util / u_blitter.h
index b96e68e9310616dc1729b81279a5b643b8ff3292..eab48c5f00dd39cb92608d4206b59df5d73290b5 100644 (file)
@@ -17,7 +17,7 @@
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 #include "util/u_framebuffer.h"
 #include "util/u_inlines.h"
-#include "util/u_memory.h"
 
 #include "pipe/p_state.h"
 
+/* u_memory.h conflicts with st/mesa */
+#ifndef Elements
+#define Elements(x) (sizeof(x)/sizeof((x)[0]))
+#endif
+
 
 #ifdef __cplusplus
 extern "C" {
@@ -79,6 +83,15 @@ struct blitter_context
                           enum blitter_attrib_type type,
                           const union pipe_color_union *color);
 
+   /**
+    * Get the next surface layer for the pipe surface, i.e. make a copy
+    * of the surface and increment the first and last layer by 1.
+    *
+    * This callback is exposed, so that drivers can override it if needed.
+    */
+   struct pipe_surface *(*get_next_surface_layer)(struct pipe_context *pipe,
+                                                  struct pipe_surface *surf);
+
    /* Whether the blitter is running. */
    boolean running;
 
@@ -89,7 +102,7 @@ struct blitter_context
    void *saved_dsa_state;     /**< depth stencil alpha state */
    void *saved_velem_state;   /**< vertex elements state */
    void *saved_rs_state;      /**< rasterizer state */
-   void *saved_fs, *saved_vs, *saved_gs; /**< shaders */
+   void *saved_fs, *saved_vs, *saved_gs, *saved_tcs, *saved_tes; /**< shaders */
 
    struct pipe_framebuffer_state saved_fb_state;  /**< framebuffer state */
    struct pipe_stencil_ref saved_stencil_ref;     /**< stencil ref */
@@ -112,6 +125,7 @@ struct blitter_context
 
    struct pipe_query *saved_render_cond_query;
    uint saved_render_cond_mode;
+   boolean saved_render_cond_cond;
 };
 
 /**
@@ -129,7 +143,7 @@ void util_blitter_cache_all_shaders(struct blitter_context *blitter);
 /**
  * Return the pipe context associated with a blitter context.
  */
-static INLINE
+static inline
 struct pipe_context *util_blitter_get_pipe(struct blitter_context *blitter)
 {
    return blitter->pipe;
@@ -148,17 +162,6 @@ void util_blitter_draw_rectangle(struct blitter_context *blitter,
                                  enum blitter_attrib_type type,
                                  const union pipe_color_union *attrib);
 
-/**
- * Try to do a blit using resource_copy_region. The function calls
- * resource_copy_region if the blit description is compatible with it.
- *
- * It returns TRUE if the blit was done using resource_copy_region.
- *
- * It returns FALSE otherwise and the caller must fall back to a more generic
- * codepath for the blit operation. (e.g. by using u_blitter)
- */
-boolean util_try_blit_via_copy_region(struct pipe_context *ctx,
-                                      const struct pipe_blit_info *blit);
 
 /*
  * These states must be saved before any of the following functions are called:
@@ -180,23 +183,18 @@ boolean util_try_blit_via_copy_region(struct pipe_context *ctx,
  * - blend state
  */
 void util_blitter_clear(struct blitter_context *blitter,
-                        unsigned width, unsigned height,
-                        unsigned num_cbufs,
+                        unsigned width, unsigned height, unsigned num_layers,
                         unsigned clear_buffers,
-                        enum pipe_format cbuf_format,
                         const union pipe_color_union *color,
                         double depth, unsigned stencil);
 
 /**
  * Check if the blitter (with the help of the driver) can blit between
  * the two resources.
- * The mask is a combination of the PIPE_MASK_* flags.
- * Set to PIPE_MASK_RGBAZS if unsure.
  */
 boolean util_blitter_is_copy_supported(struct blitter_context *blitter,
                                        const struct pipe_resource *dst,
-                                       const struct pipe_resource *src,
-                                       unsigned mask);
+                                       const struct pipe_resource *src);
 
 boolean util_blitter_is_blit_supported(struct blitter_context *blitter,
                                       const struct pipe_blit_info *info);
@@ -220,18 +218,18 @@ void util_blitter_copy_texture(struct blitter_context *blitter,
                                unsigned dstx, unsigned dsty, unsigned dstz,
                                struct pipe_resource *src,
                                unsigned src_level,
-                               const struct pipe_box *srcbox, unsigned mask,
-                               boolean copy_all_samples);
+                               const struct pipe_box *srcbox);
 
 /**
- * Same as util_blitter_copy_texture with the capabilities of util_blitter_blit,
- * but dst and src are pipe_surface and pipe_sampler_view, respectively.
- * The mipmap level and dstz are part of the views.
+ * This is a generic implementation of pipe->blit, which accepts
+ * sampler/surface views instead of resources.
+ *
+ * The layer and mipmap level are specified by the views.
  *
  * Drivers can use this to change resource properties (like format, width,
  * height) by changing how the views interpret them, instead of changing
- * pipe_resource directly. This is usually needed to accelerate copying of
- * compressed formats.
+ * pipe_resource directly. This is used to blit resources of formats which
+ * are not renderable.
  *
  * src_width0 and src_height0 are sampler_view-private properties that
  * override pipe_resource. The blitter uses them for computation of texture
@@ -243,14 +241,13 @@ void util_blitter_copy_texture(struct blitter_context *blitter,
  */
 void util_blitter_blit_generic(struct blitter_context *blitter,
                                struct pipe_surface *dst,
-                               int dstx, int dsty,
-                               unsigned dst_width, unsigned dst_height,
+                               const struct pipe_box *dstbox,
                                struct pipe_sampler_view *src,
                                const struct pipe_box *srcbox,
                                unsigned src_width0, unsigned src_height0,
                                unsigned mask, unsigned filter,
                                const struct pipe_scissor_state *scissor,
-                               boolean copy_all_samples);
+                               boolean alpha_blend);
 
 void util_blitter_blit(struct blitter_context *blitter,
                       const struct pipe_blit_info *info);
@@ -262,8 +259,7 @@ void util_blitter_blit(struct blitter_context *blitter,
 void util_blitter_default_dst_texture(struct pipe_surface *dst_templ,
                                       struct pipe_resource *dst,
                                       unsigned dstlevel,
-                                      unsigned dstz,
-                                      const struct pipe_box *srcbox);
+                                      unsigned dstz);
 
 /**
  * Helper function to initialize a view for copy_texture_view.
@@ -275,7 +271,7 @@ void util_blitter_default_src_texture(struct pipe_sampler_view *src_templ,
 
 /**
  * Copy data from one buffer to another using the Stream Output functionality.
- * Some alignment is required, otherwise software fallback is used.
+ * 4-byte alignment is required, otherwise software fallback is used.
  */
 void util_blitter_copy_buffer(struct blitter_context *blitter,
                               struct pipe_resource *dst,
@@ -284,6 +280,22 @@ void util_blitter_copy_buffer(struct blitter_context *blitter,
                               unsigned srcx,
                               unsigned size);
 
+/**
+ * Clear the contents of a buffer using the Stream Output functionality.
+ * 4-byte alignment is required.
+ *
+ * "num_channels" can be 1, 2, 3, or 4, and specifies if the clear value is
+ * R, RG, RGB, or RGBA.
+ *
+ * For each element, only "num_channels" components of "clear_value" are
+ * copied to the buffer, then the offset is incremented by num_channels*4.
+ */
+void util_blitter_clear_buffer(struct blitter_context *blitter,
+                               struct pipe_resource *dst,
+                               unsigned offset, unsigned size,
+                               unsigned num_channels,
+                               const union pipe_color_union *clear_value);
+
 /**
  * Clear a region of a (color) surface to a constant value.
  *
@@ -360,85 +372,94 @@ void util_blitter_custom_resolve_color(struct blitter_context *blitter,
  *
  * States not listed here are not affected by util_blitter. */
 
-static INLINE
-void util_blitter_save_blend(struct blitter_context *blitter,
-                             void *state)
+static inline void
+util_blitter_save_blend(struct blitter_context *blitter, void *state)
 {
    blitter->saved_blend_state = state;
 }
 
-static INLINE
-void util_blitter_save_depth_stencil_alpha(struct blitter_context *blitter,
-                                           void *state)
+static inline void
+util_blitter_save_depth_stencil_alpha(struct blitter_context *blitter,
+                                      void *state)
 {
    blitter->saved_dsa_state = state;
 }
 
-static INLINE
-void util_blitter_save_vertex_elements(struct blitter_context *blitter,
-                                       void *state)
+static inline void
+util_blitter_save_vertex_elements(struct blitter_context *blitter, void *state)
 {
    blitter->saved_velem_state = state;
 }
 
-static INLINE
-void util_blitter_save_stencil_ref(struct blitter_context *blitter,
-                                   const struct pipe_stencil_ref *state)
+static inline void
+util_blitter_save_stencil_ref(struct blitter_context *blitter,
+                              const struct pipe_stencil_ref *state)
 {
    blitter->saved_stencil_ref = *state;
 }
 
-static INLINE
+static inline
 void util_blitter_save_rasterizer(struct blitter_context *blitter,
                                   void *state)
 {
    blitter->saved_rs_state = state;
 }
 
-static INLINE
-void util_blitter_save_fragment_shader(struct blitter_context *blitter,
-                                       void *fs)
+static inline void
+util_blitter_save_fragment_shader(struct blitter_context *blitter, void *fs)
 {
    blitter->saved_fs = fs;
 }
 
-static INLINE
-void util_blitter_save_vertex_shader(struct blitter_context *blitter,
-                                     void *vs)
+static inline void
+util_blitter_save_vertex_shader(struct blitter_context *blitter, void *vs)
 {
    blitter->saved_vs = vs;
 }
 
-static INLINE
-void util_blitter_save_geometry_shader(struct blitter_context *blitter,
-                                       void *gs)
+static inline void
+util_blitter_save_geometry_shader(struct blitter_context *blitter, void *gs)
 {
    blitter->saved_gs = gs;
 }
 
-static INLINE
-void util_blitter_save_framebuffer(struct blitter_context *blitter,
-                                   const struct pipe_framebuffer_state *state)
+static inline void
+util_blitter_save_tessctrl_shader(struct blitter_context *blitter,
+                                  void *sh)
+{
+   blitter->saved_tcs = sh;
+}
+
+static inline void
+util_blitter_save_tesseval_shader(struct blitter_context *blitter,
+                                  void *sh)
+{
+   blitter->saved_tes = sh;
+}
+
+static inline void
+util_blitter_save_framebuffer(struct blitter_context *blitter,
+                              const struct pipe_framebuffer_state *state)
 {
    blitter->saved_fb_state.nr_cbufs = 0; /* It's ~0 now, meaning it's unsaved. */
    util_copy_framebuffer_state(&blitter->saved_fb_state, state);
 }
 
-static INLINE
-void util_blitter_save_viewport(struct blitter_context *blitter,
-                                struct pipe_viewport_state *state)
+static inline void
+util_blitter_save_viewport(struct blitter_context *blitter,
+                           struct pipe_viewport_state *state)
 {
    blitter->saved_viewport = *state;
 }
 
-static INLINE
-void util_blitter_save_scissor(struct blitter_context *blitter,
-                               struct pipe_scissor_state *state)
+static inline void
+util_blitter_save_scissor(struct blitter_context *blitter,
+                          struct pipe_scissor_state *state)
 {
    blitter->saved_scissor = *state;
 }
 
-static INLINE
+static inline
 void util_blitter_save_fragment_sampler_states(
                   struct blitter_context *blitter,
                   unsigned num_sampler_states,
@@ -451,7 +472,7 @@ void util_blitter_save_fragment_sampler_states(
           num_sampler_states * sizeof(void *));
 }
 
-static INLINE void
+static inline void
 util_blitter_save_fragment_sampler_views(struct blitter_context *blitter,
                                          unsigned num_views,
                                          struct pipe_sampler_view **views)
@@ -465,7 +486,7 @@ util_blitter_save_fragment_sampler_views(struct blitter_context *blitter,
                                   views[i]);
 }
 
-static INLINE void
+static inline void
 util_blitter_save_vertex_buffer_slot(struct blitter_context *blitter,
                                      struct pipe_vertex_buffer *vertex_buffers)
 {
@@ -475,7 +496,7 @@ util_blitter_save_vertex_buffer_slot(struct blitter_context *blitter,
           sizeof(struct pipe_vertex_buffer));
 }
 
-static INLINE void
+static inline void
 util_blitter_save_so_targets(struct blitter_context *blitter,
                              unsigned num_targets,
                              struct pipe_stream_output_target **targets)
@@ -489,7 +510,7 @@ util_blitter_save_so_targets(struct blitter_context *blitter,
                                targets[i]);
 }
 
-static INLINE void
+static inline void
 util_blitter_save_sample_mask(struct blitter_context *blitter,
                               unsigned sample_mask)
 {
@@ -497,13 +518,15 @@ util_blitter_save_sample_mask(struct blitter_context *blitter,
    blitter->saved_sample_mask = sample_mask;
 }
 
-static INLINE void
+static inline void
 util_blitter_save_render_condition(struct blitter_context *blitter,
                                    struct pipe_query *query,
+                                   boolean condition,
                                    uint mode)
 {
    blitter->saved_render_cond_query = query;
    blitter->saved_render_cond_mode = mode;
+   blitter->saved_render_cond_cond = condition;
 }
 
 #ifdef __cplusplus