configure.ac: Use AX_GCC_BUILTIN to check availability of __builtin_bswap32 v2
[mesa.git] / src / gallium / auxiliary / util / u_inlines.h
index ba745ebb5fb6ca370119824954149a425ceee071..e9526159ae33ea6c43823e5f9c1ae3bd973a7909 100644 (file)
@@ -1,6 +1,6 @@
 /**************************************************************************
  * 
- * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * Copyright 2007 VMware, Inc.
  * All Rights Reserved.
  * 
  * Permission is hereby granted, free of charge, to any person obtaining a
@@ -18,7 +18,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.
@@ -227,6 +227,12 @@ pipe_surface_equal(struct pipe_surface *s1, struct pipe_surface *s2)
  * Convenience wrappers for screen buffer functions.
  */
 
+
+/**
+ * Create a new resource.
+ * \param bind  bitmask of PIPE_BIND_x flags
+ * \param usage  bitmask of PIPE_USAGE_x flags
+ */
 static INLINE struct pipe_resource *
 pipe_buffer_create( struct pipe_screen *screen,
                    unsigned bind,
@@ -247,12 +253,20 @@ pipe_buffer_create( struct pipe_screen *screen,
    return screen->resource_create(screen, &buffer);
 }
 
+
+/**
+ * Map a range of a resource.
+ * \param offset  start of region, in bytes 
+ * \param length  size of region, in bytes 
+ * \param access  bitmask of PIPE_TRANSFER_x flags
+ * \param transfer  returns a transfer object
+ */
 static INLINE void *
 pipe_buffer_map_range(struct pipe_context *pipe,
                      struct pipe_resource *buffer,
                      unsigned offset,
                      unsigned length,
-                     unsigned usage,
+                     unsigned access,
                      struct pipe_transfer **transfer)
 {
    struct pipe_box box;
@@ -264,7 +278,7 @@ pipe_buffer_map_range(struct pipe_context *pipe,
 
    u_box_1d(offset, length, &box);
 
-   map = pipe->transfer_map(pipe, buffer, 0, usage, &box, transfer);
+   map = pipe->transfer_map(pipe, buffer, 0, access, &box, transfer);
    if (map == NULL) {
       return NULL;
    }
@@ -273,13 +287,18 @@ pipe_buffer_map_range(struct pipe_context *pipe,
 }
 
 
+/**
+ * Map whole resource.
+ * \param access  bitmask of PIPE_TRANSFER_x flags
+ * \param transfer  returns a transfer object
+ */
 static INLINE void *
 pipe_buffer_map(struct pipe_context *pipe,
                 struct pipe_resource *buffer,
-                unsigned usage,
+                unsigned access,
                 struct pipe_transfer **transfer)
 {
-   return pipe_buffer_map_range(pipe, buffer, 0, buffer->width0, usage, transfer);
+   return pipe_buffer_map_range(pipe, buffer, 0, buffer->width0, access, transfer);
 }
 
 
@@ -322,12 +341,12 @@ pipe_buffer_write(struct pipe_context *pipe,
                   const void *data)
 {
    struct pipe_box box;
-   unsigned usage = PIPE_TRANSFER_WRITE;
+   unsigned access = PIPE_TRANSFER_WRITE;
 
    if (offset == 0 && size == buf->width0) {
-      usage |= PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE;
+      access |= PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE;
    } else {
-      usage |= PIPE_TRANSFER_DISCARD_RANGE;
+      access |= PIPE_TRANSFER_DISCARD_RANGE;
    }
 
    u_box_1d(offset, size, &box);
@@ -335,7 +354,7 @@ pipe_buffer_write(struct pipe_context *pipe,
    pipe->transfer_inline_write( pipe,
                                 buf,
                                 0,
-                                usage,
+                                access,
                                 &box,
                                 data,
                                 size,
@@ -368,12 +387,18 @@ pipe_buffer_write_nooverlap(struct pipe_context *pipe,
                                0, 0);
 }
 
+
+/**
+ * Create a new resource and immediately put data into it
+ * \param bind  bitmask of PIPE_BIND_x flags
+ * \param usage  bitmask of PIPE_USAGE_x flags
+ */
 static INLINE struct pipe_resource *
 pipe_buffer_create_with_data(struct pipe_context *pipe,
                              unsigned bind,
                              unsigned usage,
                              unsigned size,
-                             void *ptr)
+                             const void *ptr)
 {
    struct pipe_resource *res = pipe_buffer_create(pipe->screen,
                                                   bind, usage, size);
@@ -403,11 +428,16 @@ pipe_buffer_read(struct pipe_context *pipe,
    pipe_buffer_unmap(pipe, src_transfer);
 }
 
+
+/**
+ * Map a resource for reading/writing.
+ * \param access  bitmask of PIPE_TRANSFER_x flags
+ */
 static INLINE void *
 pipe_transfer_map(struct pipe_context *context,
                   struct pipe_resource *resource,
                   unsigned level, unsigned layer,
-                  enum pipe_transfer_usage usage,
+                  unsigned access,
                   unsigned x, unsigned y,
                   unsigned w, unsigned h,
                   struct pipe_transfer **transfer)
@@ -417,15 +447,20 @@ pipe_transfer_map(struct pipe_context *context,
    return context->transfer_map(context,
                                 resource,
                                 level,
-                                usage,
+                                access,
                                 &box, transfer);
 }
 
+
+/**
+ * Map a 3D (texture) resource for reading/writing.
+ * \param access  bitmask of PIPE_TRANSFER_x flags
+ */
 static INLINE void *
 pipe_transfer_map_3d(struct pipe_context *context,
                      struct pipe_resource *resource,
                      unsigned level,
-                     enum pipe_transfer_usage usage,
+                     unsigned access,
                      unsigned x, unsigned y, unsigned z,
                      unsigned w, unsigned h, unsigned d,
                      struct pipe_transfer **transfer)
@@ -435,7 +470,7 @@ pipe_transfer_map_3d(struct pipe_context *context,
    return context->transfer_map(context,
                                 resource,
                                 level,
-                                usage,
+                                access,
                                 &box, transfer);
 }
 
@@ -463,9 +498,13 @@ pipe_set_constant_buffer(struct pipe_context *pipe, uint shader, uint index,
 }
 
 
-static INLINE boolean util_get_offset( 
-   const struct pipe_rasterizer_state *templ,
-   unsigned fill_mode)
+/**
+ * Get the polygon offset enable/disable flag for the given polygon fill mode.
+ * \param fill_mode  one of PIPE_POLYGON_MODE_POINT/LINE/FILL
+ */
+static INLINE boolean
+util_get_offset(const struct pipe_rasterizer_state *templ,
+                unsigned fill_mode)
 {
    switch(fill_mode) {
    case PIPE_POLYGON_MODE_POINT:
@@ -485,8 +524,7 @@ util_get_min_point_size(const struct pipe_rasterizer_state *state)
 {
    /* The point size should be clamped to this value at the rasterizer stage.
     */
-   return state->gl_rasterization_rules &&
-          !state->point_quad_rasterization &&
+   return !state->point_quad_rasterization &&
           !state->point_smooth &&
           !state->multisample ? 1.0f : 0.0f;
 }
@@ -517,7 +555,7 @@ util_query_clear_result(union pipe_query_result *result, unsigned type)
       memset(&result->pipeline_statistics, 0, sizeof(result->pipeline_statistics));
       break;
    default:
-      assert(0);
+      memset(result, 0, sizeof(*result));
    }
 }
 
@@ -583,7 +621,7 @@ util_copy_constant_buffer(struct pipe_constant_buffer *dst,
 }
 
 static INLINE unsigned
-util_max_layer(struct pipe_resource *r, unsigned level)
+util_max_layer(const struct pipe_resource *r, unsigned level)
 {
    switch (r->target) {
    case PIPE_TEXTURE_CUBE: