aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/gallium
diff options
context:
space:
mode:
Diffstat (limited to 'mesalib/src/gallium')
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_format_r11g11b10f.h388
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_linkage.h132
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_math.h34
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_staging.c264
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_staging.h126
5 files changed, 484 insertions, 460 deletions
diff --git a/mesalib/src/gallium/auxiliary/util/u_format_r11g11b10f.h b/mesalib/src/gallium/auxiliary/util/u_format_r11g11b10f.h
index e079b90b1..8e0572aa7 100644
--- a/mesalib/src/gallium/auxiliary/util/u_format_r11g11b10f.h
+++ b/mesalib/src/gallium/auxiliary/util/u_format_r11g11b10f.h
@@ -1,190 +1,198 @@
-/*
- * Copyright (C) 2011 Marek Olšák <maraeo@gmail.com>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * 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 NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS 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.
- */
-
-/* Based on code from The OpenGL Programming Guide / 7th Edition, Appendix J.
- * Available here: http://www.opengl-redbook.com/appendices/
- * The algorithm in the book contains a bug though, which is fixed in the code
- * below.
- */
-
-#define UF11_EXPONENT_BIAS 15
-#define UF11_EXPONENT_BITS 0x1F
-#define UF11_EXPONENT_SHIFT 6
-#define UF11_MANTISSA_BITS 0x3F
-#define UF11_MANTISSA_SHIFT (23 - UF11_EXPONENT_SHIFT)
-#define UF11_MAX_EXPONENT (UF11_EXPONENT_BITS << UF11_EXPONENT_SHIFT)
-
-#define UF10_EXPONENT_BIAS 15
-#define UF10_EXPONENT_BITS 0x1F
-#define UF10_EXPONENT_SHIFT 5
-#define UF10_MANTISSA_BITS 0x3F
-#define UF10_MANTISSA_SHIFT (23 - UF10_EXPONENT_SHIFT)
-#define UF10_MAX_EXPONENT (UF10_EXPONENT_BITS << UF10_EXPONENT_SHIFT)
-
-#define F32_INFINITY 0x7f800000
-
-static INLINE unsigned f32_to_uf11(float val)
-{
- uint32_t f32 = (*(uint32_t *) &val);
- uint16_t uf11 = 0;
-
- /* Decode little-endian 32-bit floating-point value */
- int sign = (f32 >> 16) & 0x8000;
- /* Map exponent to the range [-127,128] */
- int exponent = ((f32 >> 23) & 0xff) - 127;
- int mantissa = f32 & 0x007fffff;
-
- if (sign) return 0;
-
- if (exponent == 128) { /* Infinity or NaN */
- uf11 = UF11_MAX_EXPONENT;
- if (mantissa) uf11 |= (mantissa & UF11_MANTISSA_BITS);
- }
- else if (exponent > 15) { /* Overflow - flush to Infinity */
- uf11 = UF11_MAX_EXPONENT;
- }
- else if (exponent > -15) { /* Representable value */
- exponent += UF11_EXPONENT_BIAS;
- mantissa >>= UF11_MANTISSA_SHIFT;
- uf11 = exponent << UF11_EXPONENT_SHIFT | mantissa;
- }
-
- return uf11;
-}
-
-static INLINE float uf11_to_f32(uint16_t val)
-{
- union {
- float f;
- uint32_t ui;
- } f32;
-
- int exponent = (val & 0x07c0) >> UF11_EXPONENT_SHIFT;
- int mantissa = (val & 0x003f);
-
- f32.f = 0.0;
-
- if (exponent == 0) {
- if (mantissa != 0) {
- const float scale = 1.0 / (1 << 20);
- f32.f = scale * mantissa;
- }
- }
- else if (exponent == 31) {
- f32.ui = F32_INFINITY | mantissa;
- }
- else {
- float scale, decimal;
- exponent -= 15;
- if (exponent < 0) {
- scale = 1.0 / (1 << -exponent);
- }
- else {
- scale = 1 << exponent;
- }
- decimal = 1.0 + (float) mantissa / 64;
- f32.f = scale * decimal;
- }
-
- return f32.f;
-}
-
-static INLINE unsigned f32_to_uf10(float val)
-{
- uint32_t f32 = (*(uint32_t *) &val);
- uint16_t uf10 = 0;
-
- /* Decode little-endian 32-bit floating-point value */
- int sign = (f32 >> 16) & 0x8000;
- /* Map exponent to the range [-127,128] */
- int exponent = ((f32 >> 23) & 0xff) - 127;
- int mantissa = f32 & 0x007fffff;
-
- if (sign) return 0;
-
- if (exponent == 128) { /* Infinity or NaN */
- uf10 = UF10_MAX_EXPONENT;
- if (mantissa) uf10 |= (mantissa & UF10_MANTISSA_BITS);
- }
- else if (exponent > 15) { /* Overflow - flush to Infinity */
- uf10 = UF10_MAX_EXPONENT;
- }
- else if (exponent > -15) { /* Representable value */
- exponent += UF10_EXPONENT_BIAS;
- mantissa >>= UF10_MANTISSA_SHIFT;
- uf10 = exponent << UF10_EXPONENT_SHIFT | mantissa;
- }
-
- return uf10;
-}
-
-static INLINE float uf10_to_f32(uint16_t val)
-{
- union {
- float f;
- uint32_t ui;
- } f32;
-
- int exponent = (val & 0x07c0) >> UF10_EXPONENT_SHIFT;
- int mantissa = (val & 0x003f);
-
- f32.f = 0.0;
-
- if (exponent == 0) {
- if (mantissa != 0) {
- const float scale = 1.0 / (1 << 20);
- f32.f = scale * mantissa;
- }
- }
- else if (exponent == 31) {
- f32.ui = F32_INFINITY | mantissa;
- }
- else {
- float scale, decimal;
- exponent -= 15;
- if (exponent < 0) {
- scale = 1.0 / (1 << -exponent);
- }
- else {
- scale = 1 << exponent;
- }
- decimal = 1.0 + (float) mantissa / 32;
- f32.f = scale * decimal;
- }
-
- return f32.f;
-}
-
-static INLINE unsigned float3_to_r11g11b10f(const float rgb[3])
-{
- return ( f32_to_uf11(rgb[0]) & 0x7ff) |
- ((f32_to_uf11(rgb[1]) & 0x7ff) << 11) |
- ((f32_to_uf10(rgb[2]) & 0x3ff) << 22);
-}
-
-static INLINE void r11g11b10f_to_float3(unsigned rgb, float retval[3])
-{
- retval[0] = uf11_to_f32( rgb & 0x7ff);
- retval[1] = uf11_to_f32((rgb >> 11) & 0x7ff);
- retval[2] = uf10_to_f32((rgb >> 22) & 0x3ff);
-}
+/*
+ * Copyright (C) 2011 Marek Olšák <maraeo@gmail.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * 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 NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/* Based on code from The OpenGL Programming Guide / 7th Edition, Appendix J.
+ * Available here: http://www.opengl-redbook.com/appendices/
+ * The algorithm in the book contains a bug though, which is fixed in the code
+ * below.
+ */
+
+#define UF11_EXPONENT_BIAS 15
+#define UF11_EXPONENT_BITS 0x1F
+#define UF11_EXPONENT_SHIFT 6
+#define UF11_MANTISSA_BITS 0x3F
+#define UF11_MANTISSA_SHIFT (23 - UF11_EXPONENT_SHIFT)
+#define UF11_MAX_EXPONENT (UF11_EXPONENT_BITS << UF11_EXPONENT_SHIFT)
+
+#define UF10_EXPONENT_BIAS 15
+#define UF10_EXPONENT_BITS 0x1F
+#define UF10_EXPONENT_SHIFT 5
+#define UF10_MANTISSA_BITS 0x3F
+#define UF10_MANTISSA_SHIFT (23 - UF10_EXPONENT_SHIFT)
+#define UF10_MAX_EXPONENT (UF10_EXPONENT_BITS << UF10_EXPONENT_SHIFT)
+
+#define F32_INFINITY 0x7f800000
+
+static INLINE unsigned f32_to_uf11(float val)
+{
+ union {
+ float f;
+ uint32_t ui;
+ } f32 = {val};
+
+ uint16_t uf11 = 0;
+
+ /* Decode little-endian 32-bit floating-point value */
+ int sign = (f32.ui >> 16) & 0x8000;
+ /* Map exponent to the range [-127,128] */
+ int exponent = ((f32.ui >> 23) & 0xff) - 127;
+ int mantissa = f32.ui & 0x007fffff;
+
+ if (sign) return 0;
+
+ if (exponent == 128) { /* Infinity or NaN */
+ uf11 = UF11_MAX_EXPONENT;
+ if (mantissa) uf11 |= (mantissa & UF11_MANTISSA_BITS);
+ }
+ else if (exponent > 15) { /* Overflow - flush to Infinity */
+ uf11 = UF11_MAX_EXPONENT;
+ }
+ else if (exponent > -15) { /* Representable value */
+ exponent += UF11_EXPONENT_BIAS;
+ mantissa >>= UF11_MANTISSA_SHIFT;
+ uf11 = exponent << UF11_EXPONENT_SHIFT | mantissa;
+ }
+
+ return uf11;
+}
+
+static INLINE float uf11_to_f32(uint16_t val)
+{
+ union {
+ float f;
+ uint32_t ui;
+ } f32;
+
+ int exponent = (val & 0x07c0) >> UF11_EXPONENT_SHIFT;
+ int mantissa = (val & 0x003f);
+
+ f32.f = 0.0;
+
+ if (exponent == 0) {
+ if (mantissa != 0) {
+ const float scale = 1.0 / (1 << 20);
+ f32.f = scale * mantissa;
+ }
+ }
+ else if (exponent == 31) {
+ f32.ui = F32_INFINITY | mantissa;
+ }
+ else {
+ float scale, decimal;
+ exponent -= 15;
+ if (exponent < 0) {
+ scale = 1.0 / (1 << -exponent);
+ }
+ else {
+ scale = 1 << exponent;
+ }
+ decimal = 1.0 + (float) mantissa / 64;
+ f32.f = scale * decimal;
+ }
+
+ return f32.f;
+}
+
+static INLINE unsigned f32_to_uf10(float val)
+{
+ union {
+ float f;
+ uint32_t ui;
+ } f32 = {val};
+
+ uint16_t uf10 = 0;
+
+ /* Decode little-endian 32-bit floating-point value */
+ int sign = (f32.ui >> 16) & 0x8000;
+ /* Map exponent to the range [-127,128] */
+ int exponent = ((f32.ui >> 23) & 0xff) - 127;
+ int mantissa = f32.ui & 0x007fffff;
+
+ if (sign) return 0;
+
+ if (exponent == 128) { /* Infinity or NaN */
+ uf10 = UF10_MAX_EXPONENT;
+ if (mantissa) uf10 |= (mantissa & UF10_MANTISSA_BITS);
+ }
+ else if (exponent > 15) { /* Overflow - flush to Infinity */
+ uf10 = UF10_MAX_EXPONENT;
+ }
+ else if (exponent > -15) { /* Representable value */
+ exponent += UF10_EXPONENT_BIAS;
+ mantissa >>= UF10_MANTISSA_SHIFT;
+ uf10 = exponent << UF10_EXPONENT_SHIFT | mantissa;
+ }
+
+ return uf10;
+}
+
+static INLINE float uf10_to_f32(uint16_t val)
+{
+ union {
+ float f;
+ uint32_t ui;
+ } f32;
+
+ int exponent = (val & 0x07c0) >> UF10_EXPONENT_SHIFT;
+ int mantissa = (val & 0x003f);
+
+ f32.f = 0.0;
+
+ if (exponent == 0) {
+ if (mantissa != 0) {
+ const float scale = 1.0 / (1 << 20);
+ f32.f = scale * mantissa;
+ }
+ }
+ else if (exponent == 31) {
+ f32.ui = F32_INFINITY | mantissa;
+ }
+ else {
+ float scale, decimal;
+ exponent -= 15;
+ if (exponent < 0) {
+ scale = 1.0 / (1 << -exponent);
+ }
+ else {
+ scale = 1 << exponent;
+ }
+ decimal = 1.0 + (float) mantissa / 32;
+ f32.f = scale * decimal;
+ }
+
+ return f32.f;
+}
+
+static INLINE unsigned float3_to_r11g11b10f(const float rgb[3])
+{
+ return ( f32_to_uf11(rgb[0]) & 0x7ff) |
+ ((f32_to_uf11(rgb[1]) & 0x7ff) << 11) |
+ ((f32_to_uf10(rgb[2]) & 0x3ff) << 22);
+}
+
+static INLINE void r11g11b10f_to_float3(unsigned rgb, float retval[3])
+{
+ retval[0] = uf11_to_f32( rgb & 0x7ff);
+ retval[1] = uf11_to_f32((rgb >> 11) & 0x7ff);
+ retval[2] = uf10_to_f32((rgb >> 22) & 0x3ff);
+}
diff --git a/mesalib/src/gallium/auxiliary/util/u_linkage.h b/mesalib/src/gallium/auxiliary/util/u_linkage.h
index bca4d3b4a..43ec917fc 100644
--- a/mesalib/src/gallium/auxiliary/util/u_linkage.h
+++ b/mesalib/src/gallium/auxiliary/util/u_linkage.h
@@ -1,66 +1,66 @@
-/**************************************************************************
- *
- * Copyright 2010 Luca Barbieri
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sublicense, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial
- * portions of the Software.
- *
- * 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 NONINFRINGEMENT.
- * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) 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.
- *
- **************************************************************************/
-
-#ifndef U_LINKAGE_H_
-#define U_LINKAGE_H_
-
-#include "pipe/p_compiler.h"
-#include "pipe/p_shader_tokens.h"
-
-struct util_semantic_set
-{
- unsigned long masks[256 / 8 / sizeof(unsigned long)];
-};
-
-static INLINE bool
-util_semantic_set_contains(struct util_semantic_set *set, unsigned char value)
-{
- return !!(set->masks[value / (sizeof(long) * 8)] & (1 << (value / (sizeof(long) * 8))));
-}
-
-unsigned util_semantic_set_from_program_file(struct util_semantic_set *set, const struct tgsi_token *tokens, enum tgsi_file_type file);
-
-/* efficient_slots is the number of slots such that hardware performance is
- * the same for using that amount, with holes, or less slots but with less
- * holes.
- *
- * num_slots is the size of the layout array and hardware limit instead.
- *
- * efficient_slots == 0 or efficient_solts == num_slots are typical settings.
- */
-void util_semantic_layout_from_set(unsigned char *layout, const struct util_semantic_set *set, unsigned efficient_slots, unsigned num_slots);
-
-static INLINE void
-util_semantic_table_from_layout(unsigned char *table, unsigned char *layout, unsigned char first_slot_value, unsigned char num_slots)
-{
- int i;
- memset(table, 0xff, sizeof(table));
-
- for(i = 0; i < num_slots; ++i)
- table[layout[i]] = first_slot_value + i;
-}
-
-#endif /* U_LINKAGE_H_ */
+/**************************************************************************
+ *
+ * Copyright 2010 Luca Barbieri
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) 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.
+ *
+ **************************************************************************/
+
+#ifndef U_LINKAGE_H_
+#define U_LINKAGE_H_
+
+#include "pipe/p_compiler.h"
+#include "pipe/p_shader_tokens.h"
+
+struct util_semantic_set
+{
+ unsigned long masks[256 / 8 / sizeof(unsigned long)];
+};
+
+static INLINE boolean
+util_semantic_set_contains(struct util_semantic_set *set, unsigned char value)
+{
+ return !!(set->masks[value / (sizeof(long) * 8)] & (1 << (value / (sizeof(long) * 8))));
+}
+
+unsigned util_semantic_set_from_program_file(struct util_semantic_set *set, const struct tgsi_token *tokens, enum tgsi_file_type file);
+
+/* efficient_slots is the number of slots such that hardware performance is
+ * the same for using that amount, with holes, or less slots but with less
+ * holes.
+ *
+ * num_slots is the size of the layout array and hardware limit instead.
+ *
+ * efficient_slots == 0 or efficient_solts == num_slots are typical settings.
+ */
+void util_semantic_layout_from_set(unsigned char *layout, const struct util_semantic_set *set, unsigned efficient_slots, unsigned num_slots);
+
+static INLINE void
+util_semantic_table_from_layout(unsigned char *table, unsigned char *layout, unsigned char first_slot_value, unsigned char num_slots)
+{
+ int i;
+ memset(table, 0xff, sizeof(table));
+
+ for(i = 0; i < num_slots; ++i)
+ table[layout[i]] = first_slot_value + i;
+}
+
+#endif /* U_LINKAGE_H_ */
diff --git a/mesalib/src/gallium/auxiliary/util/u_math.h b/mesalib/src/gallium/auxiliary/util/u_math.h
index b37d62175..9a061e8a9 100644
--- a/mesalib/src/gallium/auxiliary/util/u_math.h
+++ b/mesalib/src/gallium/auxiliary/util/u_math.h
@@ -477,6 +477,9 @@ float_to_byte_tex(float f)
static INLINE unsigned
util_logbase2(unsigned n)
{
+#if defined(PIPE_CC_GCC) && (PIPE_CC_GCC_VERSION >= 304)
+ return ((sizeof(unsigned) * 8 - 1) - __builtin_clz(n | 1));
+#else
unsigned pos = 0;
if (n >= 1<<16) { n >>= 16; pos += 16; }
if (n >= 1<< 8) { n >>= 8; pos += 8; }
@@ -484,6 +487,7 @@ util_logbase2(unsigned n)
if (n >= 1<< 2) { n >>= 2; pos += 2; }
if (n >= 1<< 1) { pos += 1; }
return pos;
+#endif
}
@@ -493,17 +497,29 @@ util_logbase2(unsigned n)
static INLINE unsigned
util_next_power_of_two(unsigned x)
{
- unsigned i;
-
- if (x == 0)
- return 1;
+#if defined(PIPE_CC_GCC) && (PIPE_CC_GCC_VERSION >= 304)
+ if (x <= 1)
+ return 1;
- --x;
+ return (1 << ((sizeof(unsigned) * 8) - __builtin_clz(x - 1)));
+#else
+ unsigned val = x;
- for (i = 1; i < sizeof(unsigned) * 8; i <<= 1)
- x |= x >> i;
+ if (x <= 1)
+ return 1;
- return x + 1;
+ if (util_is_power_of_two(x))
+ return x;
+
+ val--;
+ val = (val >> 1) | val;
+ val = (val >> 2) | val;
+ val = (val >> 4) | val;
+ val = (val >> 8) | val;
+ val = (val >> 16) | val;
+ val++;
+ return val;
+#endif
}
@@ -513,7 +529,7 @@ util_next_power_of_two(unsigned x)
static INLINE unsigned
util_bitcount(unsigned n)
{
-#if defined(PIPE_CC_GCC)
+#if defined(PIPE_CC_GCC) && (PIPE_CC_GCC_VERSION >= 304)
return __builtin_popcount(n);
#else
/* K&R classic bitcount.
diff --git a/mesalib/src/gallium/auxiliary/util/u_staging.c b/mesalib/src/gallium/auxiliary/util/u_staging.c
index 030ee4718..b5e37932e 100644
--- a/mesalib/src/gallium/auxiliary/util/u_staging.c
+++ b/mesalib/src/gallium/auxiliary/util/u_staging.c
@@ -1,132 +1,132 @@
-/**************************************************************************
- *
- * Copyright 2010 Luca Barbieri
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sublicense, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial
- * portions of the Software.
- *
- * 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 NONINFRINGEMENT.
- * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) 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_staging.h"
-#include "pipe/p_context.h"
-#include "util/u_memory.h"
-#include "util/u_inlines.h"
-
-static void
-util_staging_resource_template(struct pipe_resource *pt, unsigned width, unsigned height, unsigned depth, struct pipe_resource *template)
-{
- memset(template, 0, sizeof(struct pipe_resource));
- if(pt->target != PIPE_BUFFER && depth <= 1)
- template->target = PIPE_TEXTURE_RECT;
- else
- template->target = pt->target;
- template->format = pt->format;
- template->width0 = width;
- template->height0 = height;
- template->depth0 = depth;
- template->array_size = 1;
- template->last_level = 0;
- template->nr_samples = pt->nr_samples;
- template->bind = 0;
- template->usage = PIPE_USAGE_STAGING;
- template->flags = 0;
-}
-
-struct util_staging_transfer *
-util_staging_transfer_init(struct pipe_context *pipe,
- struct pipe_resource *pt,
- unsigned level,
- unsigned usage,
- const struct pipe_box *box,
- bool direct, struct util_staging_transfer *tx)
-{
- struct pipe_screen *pscreen = pipe->screen;
-
- struct pipe_resource staging_resource_template;
-
- pipe_resource_reference(&tx->base.resource, pt);
- tx->base.level = level;
- tx->base.usage = usage;
- tx->base.box = *box;
-
- if (direct)
- {
- tx->staging_resource = pt;
- return tx;
- }
-
- util_staging_resource_template(pt, box->width, box->height, box->depth, &staging_resource_template);
- tx->staging_resource = pscreen->resource_create(pscreen, &staging_resource_template);
- if (!tx->staging_resource)
- {
- pipe_resource_reference(&tx->base.resource, NULL);
- FREE(tx);
- return NULL;
- }
-
- if (usage & PIPE_TRANSFER_READ)
- {
- /* XXX this looks wrong dst is always the same but looping over src z? */
- unsigned zi;
- struct pipe_box sbox;
- sbox.x = box->x;
- sbox.y = box->y;
- sbox.z = box->z;
- sbox.width = box->width;
- sbox.height = box->height;
- sbox.depth = 1;
- for(zi = 0; zi < box->depth; ++zi) {
- sbox.z = sbox.z + zi;
- pipe->resource_copy_region(pipe, tx->staging_resource, 0, 0, 0, 0,
- tx->base.resource, level, &sbox);
- }
- }
-
- return tx;
-}
-
-void
-util_staging_transfer_destroy(struct pipe_context *pipe, struct pipe_transfer *ptx)
-{
- struct util_staging_transfer *tx = (struct util_staging_transfer *)ptx;
-
- if (tx->staging_resource != tx->base.resource)
- {
- if(tx->base.usage & PIPE_TRANSFER_WRITE) {
- /* XXX this looks wrong src is always the same but looping over dst z? */
- unsigned zi;
- struct pipe_box sbox;
- sbox.x = 0;
- sbox.y = 0;
- sbox.z = 0;
- sbox.width = tx->base.box.width;
- sbox.height = tx->base.box.height;
- sbox.depth = 1;
- for(zi = 0; zi < tx->base.box.depth; ++zi)
- pipe->resource_copy_region(pipe, tx->base.resource, tx->base.level, tx->base.box.x, tx->base.box.y, tx->base.box.z + zi,
- tx->staging_resource, 0, &sbox);
- }
-
- pipe_resource_reference(&tx->staging_resource, NULL);
- }
-
- pipe_resource_reference(&ptx->resource, NULL);
- FREE(ptx);
-}
+/**************************************************************************
+ *
+ * Copyright 2010 Luca Barbieri
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) 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_staging.h"
+#include "pipe/p_context.h"
+#include "util/u_memory.h"
+#include "util/u_inlines.h"
+
+static void
+util_staging_resource_template(struct pipe_resource *pt, unsigned width, unsigned height, unsigned depth, struct pipe_resource *template)
+{
+ memset(template, 0, sizeof(struct pipe_resource));
+ if(pt->target != PIPE_BUFFER && depth <= 1)
+ template->target = PIPE_TEXTURE_RECT;
+ else
+ template->target = pt->target;
+ template->format = pt->format;
+ template->width0 = width;
+ template->height0 = height;
+ template->depth0 = depth;
+ template->array_size = 1;
+ template->last_level = 0;
+ template->nr_samples = pt->nr_samples;
+ template->bind = 0;
+ template->usage = PIPE_USAGE_STAGING;
+ template->flags = 0;
+}
+
+struct util_staging_transfer *
+util_staging_transfer_init(struct pipe_context *pipe,
+ struct pipe_resource *pt,
+ unsigned level,
+ unsigned usage,
+ const struct pipe_box *box,
+ boolean direct, struct util_staging_transfer *tx)
+{
+ struct pipe_screen *pscreen = pipe->screen;
+
+ struct pipe_resource staging_resource_template;
+
+ pipe_resource_reference(&tx->base.resource, pt);
+ tx->base.level = level;
+ tx->base.usage = usage;
+ tx->base.box = *box;
+
+ if (direct)
+ {
+ tx->staging_resource = pt;
+ return tx;
+ }
+
+ util_staging_resource_template(pt, box->width, box->height, box->depth, &staging_resource_template);
+ tx->staging_resource = pscreen->resource_create(pscreen, &staging_resource_template);
+ if (!tx->staging_resource)
+ {
+ pipe_resource_reference(&tx->base.resource, NULL);
+ FREE(tx);
+ return NULL;
+ }
+
+ if (usage & PIPE_TRANSFER_READ)
+ {
+ /* XXX this looks wrong dst is always the same but looping over src z? */
+ unsigned zi;
+ struct pipe_box sbox;
+ sbox.x = box->x;
+ sbox.y = box->y;
+ sbox.z = box->z;
+ sbox.width = box->width;
+ sbox.height = box->height;
+ sbox.depth = 1;
+ for(zi = 0; zi < box->depth; ++zi) {
+ sbox.z = sbox.z + zi;
+ pipe->resource_copy_region(pipe, tx->staging_resource, 0, 0, 0, 0,
+ tx->base.resource, level, &sbox);
+ }
+ }
+
+ return tx;
+}
+
+void
+util_staging_transfer_destroy(struct pipe_context *pipe, struct pipe_transfer *ptx)
+{
+ struct util_staging_transfer *tx = (struct util_staging_transfer *)ptx;
+
+ if (tx->staging_resource != tx->base.resource)
+ {
+ if(tx->base.usage & PIPE_TRANSFER_WRITE) {
+ /* XXX this looks wrong src is always the same but looping over dst z? */
+ unsigned zi;
+ struct pipe_box sbox;
+ sbox.x = 0;
+ sbox.y = 0;
+ sbox.z = 0;
+ sbox.width = tx->base.box.width;
+ sbox.height = tx->base.box.height;
+ sbox.depth = 1;
+ for(zi = 0; zi < tx->base.box.depth; ++zi)
+ pipe->resource_copy_region(pipe, tx->base.resource, tx->base.level, tx->base.box.x, tx->base.box.y, tx->base.box.z + zi,
+ tx->staging_resource, 0, &sbox);
+ }
+
+ pipe_resource_reference(&tx->staging_resource, NULL);
+ }
+
+ pipe_resource_reference(&ptx->resource, NULL);
+ FREE(ptx);
+}
diff --git a/mesalib/src/gallium/auxiliary/util/u_staging.h b/mesalib/src/gallium/auxiliary/util/u_staging.h
index 87eb5a1da..ddbb33443 100644
--- a/mesalib/src/gallium/auxiliary/util/u_staging.h
+++ b/mesalib/src/gallium/auxiliary/util/u_staging.h
@@ -1,63 +1,63 @@
-/**************************************************************************
- *
- * Copyright 2010 Luca Barbieri
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sublicense, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial
- * portions of the Software.
- *
- * 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 NONINFRINGEMENT.
- * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) 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.
- *
- **************************************************************************/
-
-/* Direct3D 10/11 has no concept of transfers. Applications instead
- * create resources with a STAGING or DYNAMIC usage, copy between them
- * and the real resource and use Map to map the STAGING/DYNAMIC resource.
- *
- * This util module allows to implement Gallium drivers as a Direct3D
- * driver would be implemented: transfers allocate a resource with
- * PIPE_USAGE_STAGING, and copy the data between it and the real resource
- * with resource_copy_region.
- */
-
-#ifndef U_STAGING_H
-#define U_STAGING_H
-
-#include "pipe/p_state.h"
-
-struct util_staging_transfer {
- struct pipe_transfer base;
-
- /* if direct, same as base.resource, otherwise the temporary staging resource */
- struct pipe_resource *staging_resource;
-};
-
-/* user must be stride, slice_stride and offset */
-/* pt->usage == PIPE_USAGE_DYNAMIC || pt->usage == PIPE_USAGE_STAGING should be a good value to pass for direct */
-/* staging resource is currently created with PIPE_USAGE_STAGING */
-struct util_staging_transfer *
-util_staging_transfer_init(struct pipe_context *pipe,
- struct pipe_resource *pt,
- unsigned level,
- unsigned usage,
- const struct pipe_box *box,
- bool direct, struct util_staging_transfer *tx);
-
-void
-util_staging_transfer_destroy(struct pipe_context *pipe, struct pipe_transfer *ptx);
-
-#endif
+/**************************************************************************
+ *
+ * Copyright 2010 Luca Barbieri
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * 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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) 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.
+ *
+ **************************************************************************/
+
+/* Direct3D 10/11 has no concept of transfers. Applications instead
+ * create resources with a STAGING or DYNAMIC usage, copy between them
+ * and the real resource and use Map to map the STAGING/DYNAMIC resource.
+ *
+ * This util module allows to implement Gallium drivers as a Direct3D
+ * driver would be implemented: transfers allocate a resource with
+ * PIPE_USAGE_STAGING, and copy the data between it and the real resource
+ * with resource_copy_region.
+ */
+
+#ifndef U_STAGING_H
+#define U_STAGING_H
+
+#include "pipe/p_state.h"
+
+struct util_staging_transfer {
+ struct pipe_transfer base;
+
+ /* if direct, same as base.resource, otherwise the temporary staging resource */
+ struct pipe_resource *staging_resource;
+};
+
+/* user must be stride, slice_stride and offset */
+/* pt->usage == PIPE_USAGE_DYNAMIC || pt->usage == PIPE_USAGE_STAGING should be a good value to pass for direct */
+/* staging resource is currently created with PIPE_USAGE_STAGING */
+struct util_staging_transfer *
+util_staging_transfer_init(struct pipe_context *pipe,
+ struct pipe_resource *pt,
+ unsigned level,
+ unsigned usage,
+ const struct pipe_box *box,
+ boolean direct, struct util_staging_transfer *tx);
+
+void
+util_staging_transfer_destroy(struct pipe_context *pipe, struct pipe_transfer *ptx);
+
+#endif