aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/gallium/auxiliary/util
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2015-02-22 21:39:56 +0100
committermarha <marha@users.sourceforge.net>2015-02-22 21:39:56 +0100
commit462f18c7b25fe3e467f837647d07ab0a78aa8d2b (patch)
treefc8013c0a1bac05a1945846c1697e973f4c35013 /mesalib/src/gallium/auxiliary/util
parent36f711ee12b6dd5184198abed3aa551efb585587 (diff)
downloadvcxsrv-462f18c7b25fe3e467f837647d07ab0a78aa8d2b.tar.gz
vcxsrv-462f18c7b25fe3e467f837647d07ab0a78aa8d2b.tar.bz2
vcxsrv-462f18c7b25fe3e467f837647d07ab0a78aa8d2b.zip
Merged origin/release (checked in because wanted to merge new stuff)
Diffstat (limited to 'mesalib/src/gallium/auxiliary/util')
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_atomic.h401
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_blend.h25
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_cache.c2
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_cpu_detect.c8
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_debug.h2
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_debug_flush.c12
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_format.csv11
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_format_bptc.h109
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_format_fake.c (renamed from mesalib/src/gallium/auxiliary/util/u_format_bptc.c)13
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_format_fake.h66
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_format_table.py2
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_math.h29
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_prim.h6
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_pstipple.c25
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_pstipple.h3
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_simple_list.h199
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_simple_shaders.c12
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_slab.c2
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_tests.c302
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_tests.h4
20 files changed, 434 insertions, 799 deletions
diff --git a/mesalib/src/gallium/auxiliary/util/u_atomic.h b/mesalib/src/gallium/auxiliary/util/u_atomic.h
deleted file mode 100644
index 2500bc752..000000000
--- a/mesalib/src/gallium/auxiliary/util/u_atomic.h
+++ /dev/null
@@ -1,401 +0,0 @@
-/**
- * Many similar implementations exist. See for example libwsbm
- * or the linux kernel include/atomic.h
- *
- * No copyright claimed on this file.
- *
- */
-
-#ifndef U_ATOMIC_H
-#define U_ATOMIC_H
-
-#include "pipe/p_compiler.h"
-#include "pipe/p_defines.h"
-
-/* Favor OS-provided implementations.
- *
- * Where no OS-provided implementation is available, fall back to
- * locally coded assembly, compiler intrinsic or ultimately a
- * mutex-based implementation.
- */
-#if defined(PIPE_OS_SOLARIS)
-#define PIPE_ATOMIC_OS_SOLARIS
-#elif defined(PIPE_CC_MSVC)
-#define PIPE_ATOMIC_MSVC_INTRINSIC
-#elif (defined(PIPE_CC_MSVC) && defined(PIPE_ARCH_X86))
-#define PIPE_ATOMIC_ASM_MSVC_X86
-#elif defined(PIPE_CC_GCC) && (PIPE_CC_GCC_VERSION >= 401)
-#define PIPE_ATOMIC_GCC_INTRINSIC
-#elif (defined(PIPE_CC_GCC) && defined(PIPE_ARCH_X86))
-#define PIPE_ATOMIC_ASM_GCC_X86
-#elif (defined(PIPE_CC_GCC) && defined(PIPE_ARCH_X86_64))
-#define PIPE_ATOMIC_ASM_GCC_X86_64
-#else
-#error "Unsupported platform"
-#endif
-
-
-#if defined(PIPE_ATOMIC_ASM_GCC_X86_64)
-#define PIPE_ATOMIC "GCC x86_64 assembly"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define p_atomic_set(_v, _i) (*(_v) = (_i))
-#define p_atomic_read(_v) (*(_v))
-
-static INLINE boolean
-p_atomic_dec_zero(int32_t *v)
-{
- unsigned char c;
-
- __asm__ __volatile__("lock; decl %0; sete %1":"+m"(*v), "=qm"(c)
- ::"memory");
-
- return c != 0;
-}
-
-static INLINE void
-p_atomic_inc(int32_t *v)
-{
- __asm__ __volatile__("lock; incl %0":"+m"(*v));
-}
-
-static INLINE void
-p_atomic_dec(int32_t *v)
-{
- __asm__ __volatile__("lock; decl %0":"+m"(*v));
-}
-
-static INLINE int32_t
-p_atomic_inc_return(int32_t *v)
-{
- return __sync_add_and_fetch(v, 1);
-}
-
-static INLINE int32_t
-p_atomic_dec_return(int32_t *v)
-{
- return __sync_sub_and_fetch(v, 1);
-}
-
-static INLINE int32_t
-p_atomic_cmpxchg(int32_t *v, int32_t old, int32_t _new)
-{
- return __sync_val_compare_and_swap(v, old, _new);
-}
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* PIPE_ATOMIC_ASM_GCC_X86_64 */
-
-
-#if defined(PIPE_ATOMIC_ASM_GCC_X86)
-
-#define PIPE_ATOMIC "GCC x86 assembly"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define p_atomic_set(_v, _i) (*(_v) = (_i))
-#define p_atomic_read(_v) (*(_v))
-
-static INLINE boolean
-p_atomic_dec_zero(int32_t *v)
-{
- unsigned char c;
-
- __asm__ __volatile__("lock; decl %0; sete %1":"+m"(*v), "=qm"(c)
- ::"memory");
-
- return c != 0;
-}
-
-static INLINE void
-p_atomic_inc(int32_t *v)
-{
- __asm__ __volatile__("lock; incl %0":"+m"(*v));
-}
-
-static INLINE void
-p_atomic_dec(int32_t *v)
-{
- __asm__ __volatile__("lock; decl %0":"+m"(*v));
-}
-
-static INLINE int32_t
-p_atomic_inc_return(int32_t *v)
-{
- return __sync_add_and_fetch(v, 1);
-}
-
-static INLINE int32_t
-p_atomic_dec_return(int32_t *v)
-{
- return __sync_sub_and_fetch(v, 1);
-}
-
-static INLINE int32_t
-p_atomic_cmpxchg(int32_t *v, int32_t old, int32_t _new)
-{
- return __sync_val_compare_and_swap(v, old, _new);
-}
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-
-
-
-/* Implementation using GCC-provided synchronization intrinsics
- */
-#if defined(PIPE_ATOMIC_GCC_INTRINSIC)
-
-#define PIPE_ATOMIC "GCC Sync Intrinsics"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define p_atomic_set(_v, _i) (*(_v) = (_i))
-#define p_atomic_read(_v) (*(_v))
-
-static INLINE boolean
-p_atomic_dec_zero(int32_t *v)
-{
- return (__sync_sub_and_fetch(v, 1) == 0);
-}
-
-static INLINE void
-p_atomic_inc(int32_t *v)
-{
- (void) __sync_add_and_fetch(v, 1);
-}
-
-static INLINE void
-p_atomic_dec(int32_t *v)
-{
- (void) __sync_sub_and_fetch(v, 1);
-}
-
-static INLINE int32_t
-p_atomic_inc_return(int32_t *v)
-{
- return __sync_add_and_fetch(v, 1);
-}
-
-static INLINE int32_t
-p_atomic_dec_return(int32_t *v)
-{
- return __sync_sub_and_fetch(v, 1);
-}
-
-static INLINE int32_t
-p_atomic_cmpxchg(int32_t *v, int32_t old, int32_t _new)
-{
- return __sync_val_compare_and_swap(v, old, _new);
-}
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-
-
-
-/* Unlocked version for single threaded environments, such as some
- * windows kernel modules.
- */
-#if defined(PIPE_ATOMIC_OS_UNLOCKED)
-
-#define PIPE_ATOMIC "Unlocked"
-
-#define p_atomic_set(_v, _i) (*(_v) = (_i))
-#define p_atomic_read(_v) (*(_v))
-#define p_atomic_dec_zero(_v) ((boolean) --(*(_v)))
-#define p_atomic_inc(_v) ((void) (*(_v))++)
-#define p_atomic_dec(_v) ((void) (*(_v))--)
-#define p_atomic_inc_return(_v) ((*(_v))++)
-#define p_atomic_dec_return(_v) ((*(_v))--)
-#define p_atomic_cmpxchg(_v, old, _new) (*(_v) == old ? *(_v) = (_new) : *(_v))
-
-#endif
-
-
-/* Locally coded assembly for MSVC on x86:
- */
-#if defined(PIPE_ATOMIC_ASM_MSVC_X86)
-
-#define PIPE_ATOMIC "MSVC x86 assembly"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define p_atomic_set(_v, _i) (*(_v) = (_i))
-#define p_atomic_read(_v) (*(_v))
-
-static INLINE boolean
-p_atomic_dec_zero(int32_t *v)
-{
- unsigned char c;
-
- __asm {
- mov eax, [v]
- lock dec dword ptr [eax]
- sete byte ptr [c]
- }
-
- return c != 0;
-}
-
-static INLINE void
-p_atomic_inc(int32_t *v)
-{
- __asm {
- mov eax, [v]
- lock inc dword ptr [eax]
- }
-}
-
-static INLINE void
-p_atomic_dec(int32_t *v)
-{
- __asm {
- mov eax, [v]
- lock dec dword ptr [eax]
- }
-}
-
-static INLINE int32_t
-p_atomic_cmpxchg(int32_t *v, int32_t old, int32_t _new)
-{
- int32_t orig;
-
- __asm {
- mov ecx, [v]
- mov eax, [old]
- mov edx, [_new]
- lock cmpxchg [ecx], edx
- mov [orig], eax
- }
-
- return orig;
-}
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-
-
-#if defined(PIPE_ATOMIC_MSVC_INTRINSIC)
-
-#define PIPE_ATOMIC "MSVC Intrinsics"
-
-#include <intrin.h>
-
-#pragma intrinsic(_InterlockedIncrement)
-#pragma intrinsic(_InterlockedDecrement)
-#pragma intrinsic(_InterlockedCompareExchange)
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define p_atomic_set(_v, _i) (*(_v) = (_i))
-#define p_atomic_read(_v) (*(_v))
-
-static INLINE boolean
-p_atomic_dec_zero(int32_t *v)
-{
- return _InterlockedDecrement((long *)v) == 0;
-}
-
-static INLINE void
-p_atomic_inc(int32_t *v)
-{
- _InterlockedIncrement((long *)v);
-}
-
-static INLINE int32_t
-p_atomic_inc_return(int32_t *v)
-{
- return _InterlockedIncrement((long *)v);
-}
-
-static INLINE void
-p_atomic_dec(int32_t *v)
-{
- _InterlockedDecrement((long *)v);
-}
-
-static INLINE int32_t
-p_atomic_dec_return(int32_t *v)
-{
- return _InterlockedDecrement((long *)v);
-}
-
-static INLINE int32_t
-p_atomic_cmpxchg(int32_t *v, int32_t old, int32_t _new)
-{
- return _InterlockedCompareExchange((long *)v, _new, old);
-}
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-
-#if defined(PIPE_ATOMIC_OS_SOLARIS)
-
-#define PIPE_ATOMIC "Solaris OS atomic functions"
-
-#include <atomic.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define p_atomic_set(_v, _i) (*(_v) = (_i))
-#define p_atomic_read(_v) (*(_v))
-
-static INLINE boolean
-p_atomic_dec_zero(int32_t *v)
-{
- uint32_t n = atomic_dec_32_nv((uint32_t *) v);
-
- return n != 0;
-}
-
-#define p_atomic_inc(_v) atomic_inc_32((uint32_t *) _v)
-#define p_atomic_dec(_v) atomic_dec_32((uint32_t *) _v)
-#define p_atomic_inc_return(_v) atomic_inc_32_nv((uint32_t *) _v)
-#define p_atomic_dec_return(_v) atomic_dec_32_nv((uint32_t *) _v)
-
-#define p_atomic_cmpxchg(_v, _old, _new) \
- atomic_cas_32( (uint32_t *) _v, (uint32_t) _old, (uint32_t) _new)
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-
-
-#ifndef PIPE_ATOMIC
-#error "No pipe_atomic implementation selected"
-#endif
-
-
-
-#endif /* U_ATOMIC_H */
diff --git a/mesalib/src/gallium/auxiliary/util/u_blend.h b/mesalib/src/gallium/auxiliary/util/u_blend.h
new file mode 100644
index 000000000..2485c34d4
--- /dev/null
+++ b/mesalib/src/gallium/auxiliary/util/u_blend.h
@@ -0,0 +1,25 @@
+#ifndef U_BLEND_H
+#define U_BLEND_H
+
+#include "pipe/p_state.h"
+
+/**
+ * When faking RGBX render target formats with RGBA ones, the blender is still
+ * supposed to treat the destination's alpha channel as 1 instead of the
+ * garbage that's there. Return a blend factor that will take that into
+ * account.
+ */
+static INLINE int
+util_blend_dst_alpha_to_one(int factor)
+{
+ switch (factor) {
+ case PIPE_BLENDFACTOR_DST_ALPHA:
+ return PIPE_BLENDFACTOR_ONE;
+ case PIPE_BLENDFACTOR_INV_DST_ALPHA:
+ return PIPE_BLENDFACTOR_ZERO;
+ default:
+ return factor;
+ }
+}
+
+#endif /* U_BLEND_H */
diff --git a/mesalib/src/gallium/auxiliary/util/u_cache.c b/mesalib/src/gallium/auxiliary/util/u_cache.c
index 26aab2bf1..9395c66f2 100644
--- a/mesalib/src/gallium/auxiliary/util/u_cache.c
+++ b/mesalib/src/gallium/auxiliary/util/u_cache.c
@@ -42,7 +42,7 @@
#include "util/u_math.h"
#include "util/u_memory.h"
#include "util/u_cache.h"
-#include "util/u_simple_list.h"
+#include "util/simple_list.h"
struct util_cache_entry
diff --git a/mesalib/src/gallium/auxiliary/util/u_cpu_detect.c b/mesalib/src/gallium/auxiliary/util/u_cpu_detect.c
index 5d9db59d1..23ab46c54 100644
--- a/mesalib/src/gallium/auxiliary/util/u_cpu_detect.c
+++ b/mesalib/src/gallium/auxiliary/util/u_cpu_detect.c
@@ -272,7 +272,7 @@ static INLINE uint64_t xgetbv(void)
#if defined(PIPE_ARCH_X86)
-static INLINE boolean sse2_has_daz(void)
+PIPE_ALIGN_STACK static INLINE boolean sse2_has_daz(void)
{
struct {
uint32_t pad1[7];
@@ -409,8 +409,12 @@ util_cpu_detect(void)
}
if (regs[0] >= 0x80000006) {
+ /* should we really do this if the clflush size above worked? */
+ unsigned int cacheline;
cpuid(0x80000006, regs2);
- util_cpu_caps.cacheline = regs2[2] & 0xFF;
+ cacheline = regs2[2] & 0xFF;
+ if (cacheline > 0)
+ util_cpu_caps.cacheline = cacheline;
}
if (!util_cpu_caps.has_sse) {
diff --git a/mesalib/src/gallium/auxiliary/util/u_debug.h b/mesalib/src/gallium/auxiliary/util/u_debug.h
index badd5e296..4c22fdfb6 100644
--- a/mesalib/src/gallium/auxiliary/util/u_debug.h
+++ b/mesalib/src/gallium/auxiliary/util/u_debug.h
@@ -185,7 +185,7 @@ void _debug_assert_fail(const char *expr,
#ifdef DEBUG
#define debug_assert(expr) ((expr) ? (void)0 : _debug_assert_fail(#expr, __FILE__, __LINE__, __FUNCTION__))
#else
-#define debug_assert(expr) do { } while (0 && (expr))
+#define debug_assert(expr) (void)(0 && (expr))
#endif
diff --git a/mesalib/src/gallium/auxiliary/util/u_debug_flush.c b/mesalib/src/gallium/auxiliary/util/u_debug_flush.c
index fdb248c23..cdefca2fb 100644
--- a/mesalib/src/gallium/auxiliary/util/u_debug_flush.c
+++ b/mesalib/src/gallium/auxiliary/util/u_debug_flush.c
@@ -132,8 +132,7 @@ debug_flush_buf_reference(struct debug_flush_buf **dst,
struct debug_flush_buf *fbuf = *dst;
if (pipe_reference(&(*dst)->reference, &src->reference)) {
- if (fbuf->map_frame)
- FREE(fbuf->map_frame);
+ FREE(fbuf->map_frame);
FREE(fbuf);
}
@@ -146,8 +145,7 @@ debug_flush_item_destroy(struct debug_flush_item *item)
{
debug_flush_buf_reference(&item->fbuf, NULL);
- if (item->ref_frame)
- FREE(item->ref_frame);
+ FREE(item->ref_frame);
FREE(item);
}
@@ -263,10 +261,8 @@ debug_flush_unmap(struct debug_flush_buf *fbuf)
fbuf->mapped_sync = FALSE;
fbuf->mapped = FALSE;
- if (fbuf->map_frame) {
- FREE(fbuf->map_frame);
- fbuf->map_frame = NULL;
- }
+ FREE(fbuf->map_frame);
+ fbuf->map_frame = NULL;
pipe_mutex_unlock(fbuf->mutex);
}
diff --git a/mesalib/src/gallium/auxiliary/util/u_format.csv b/mesalib/src/gallium/auxiliary/util/u_format.csv
index a71aaf15d..d3b77e6b9 100644
--- a/mesalib/src/gallium/auxiliary/util/u_format.csv
+++ b/mesalib/src/gallium/auxiliary/util/u_format.csv
@@ -186,6 +186,17 @@ PIPE_FORMAT_LATC2_SNORM , rgtc, 4, 4, x128, , , , xxxy, rg
PIPE_FORMAT_ETC1_RGB8 , etc, 4, 4, x64, , , , xyz1, rgb
+PIPE_FORMAT_ETC2_RGB8 , etc, 4, 4, x64, , , , xyz1, rgb
+PIPE_FORMAT_ETC2_SRGB8 , etc, 4, 4, x64, , , , xyz1, srgb
+PIPE_FORMAT_ETC2_RGB8A1 , etc, 4, 4, x64, , , , xyzw, rgb
+PIPE_FORMAT_ETC2_SRGB8A1 , etc, 4, 4, x64, , , , xyzw, srgb
+PIPE_FORMAT_ETC2_RGBA8 , etc, 4, 4, x128, , , , xyzw, rgb
+PIPE_FORMAT_ETC2_SRGBA8 , etc, 4, 4, x128, , , , xyzw, srgb
+PIPE_FORMAT_ETC2_R11_UNORM , etc, 4, 4, x64, , , , x001, rgb
+PIPE_FORMAT_ETC2_R11_SNORM , etc, 4, 4, x64, , , , x001, rgb
+PIPE_FORMAT_ETC2_RG11_UNORM , etc, 4, 4, x128, , , , xy01, rgb
+PIPE_FORMAT_ETC2_RG11_SNORM , etc, 4, 4, x128, , , , xy01, rgb
+
PIPE_FORMAT_BPTC_RGBA_UNORM , bptc, 4, 4, x128, , , , xyzw, rgb
PIPE_FORMAT_BPTC_SRGBA , bptc, 4, 4, x128, , , , xyzw, srgb
PIPE_FORMAT_BPTC_RGB_FLOAT , bptc, 4, 4, x128, , , , xyz1, rgb
diff --git a/mesalib/src/gallium/auxiliary/util/u_format_bptc.h b/mesalib/src/gallium/auxiliary/util/u_format_bptc.h
deleted file mode 100644
index f67d071ee..000000000
--- a/mesalib/src/gallium/auxiliary/util/u_format_bptc.h
+++ /dev/null
@@ -1,109 +0,0 @@
-/**************************************************************************
- *
- * Copyright 2011 Red Hat Inc.
- * All Rights Reserved.
- *
- * 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, sub license, 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 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
- * THE COPYRIGHT HOLDERS, AUTHORS 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.
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- **************************************************************************/
-
-#ifndef U_FORMAT_BPTC_H_
-#define U_FORMAT_BPTC_H_
-
-void
-util_format_bptc_rgba_unorm_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j);
-
-void
-util_format_bptc_rgba_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_bptc_rgba_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_bptc_rgba_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_bptc_rgba_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_bptc_rgba_unorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j);
-
-
-
-void
-util_format_bptc_srgba_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j);
-
-void
-util_format_bptc_srgba_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_bptc_srgba_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_bptc_srgba_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_bptc_srgba_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_bptc_srgba_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j);
-
-
-
-void
-util_format_bptc_rgb_float_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j);
-
-void
-util_format_bptc_rgb_float_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_bptc_rgb_float_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_bptc_rgb_float_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_bptc_rgb_float_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_bptc_rgb_float_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j);
-
-
-void
-util_format_bptc_rgb_ufloat_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j);
-
-void
-util_format_bptc_rgb_ufloat_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_bptc_rgb_ufloat_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_bptc_rgb_ufloat_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_bptc_rgb_ufloat_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_bptc_rgb_ufloat_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j);
-
-
-#endif
diff --git a/mesalib/src/gallium/auxiliary/util/u_format_bptc.c b/mesalib/src/gallium/auxiliary/util/u_format_fake.c
index 196220ee0..77e896d27 100644
--- a/mesalib/src/gallium/auxiliary/util/u_format_bptc.c
+++ b/mesalib/src/gallium/auxiliary/util/u_format_fake.c
@@ -1,5 +1,5 @@
#include "u_format.h"
-#include "u_format_bptc.h"
+#include "u_format_fake.h"
#define fake(format) \
void \
@@ -24,3 +24,14 @@ fake(bptc_rgba_unorm)
fake(bptc_srgba)
fake(bptc_rgb_float)
fake(bptc_rgb_ufloat)
+
+fake(etc2_rgb8)
+fake(etc2_srgb8)
+fake(etc2_rgb8a1)
+fake(etc2_srgb8a1)
+fake(etc2_rgba8)
+fake(etc2_srgba8)
+fake(etc2_r11_unorm)
+fake(etc2_r11_snorm)
+fake(etc2_rg11_unorm)
+fake(etc2_rg11_snorm)
diff --git a/mesalib/src/gallium/auxiliary/util/u_format_fake.h b/mesalib/src/gallium/auxiliary/util/u_format_fake.h
new file mode 100644
index 000000000..e6bfd4e15
--- /dev/null
+++ b/mesalib/src/gallium/auxiliary/util/u_format_fake.h
@@ -0,0 +1,66 @@
+/**************************************************************************
+ *
+ * Copyright 2011 Red Hat Inc.
+ * All Rights Reserved.
+ *
+ * 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, sub license, 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 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
+ * THE COPYRIGHT HOLDERS, AUTHORS 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.
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ **************************************************************************/
+
+#ifndef U_FORMAT_FAKE_H_
+#define U_FORMAT_FAKE_H_
+
+#define __format_fake(format) \
+void \
+util_format_##format##_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j); \
+\
+void \
+util_format_##format##_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); \
+\
+void \
+util_format_##format##_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); \
+\
+void \
+util_format_##format##_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); \
+\
+void \
+util_format_##format##_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height); \
+\
+void \
+util_format_##format##_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j);
+
+__format_fake(bptc_rgba_unorm)
+__format_fake(bptc_srgba)
+__format_fake(bptc_rgb_float)
+__format_fake(bptc_rgb_ufloat)
+
+__format_fake(etc2_rgb8)
+__format_fake(etc2_srgb8)
+__format_fake(etc2_rgb8a1)
+__format_fake(etc2_srgb8a1)
+__format_fake(etc2_rgba8)
+__format_fake(etc2_srgba8)
+__format_fake(etc2_r11_unorm)
+__format_fake(etc2_r11_snorm)
+__format_fake(etc2_rg11_unorm)
+__format_fake(etc2_rg11_snorm)
+
+#endif
diff --git a/mesalib/src/gallium/auxiliary/util/u_format_table.py b/mesalib/src/gallium/auxiliary/util/u_format_table.py
index ad582e4f5..aceb0caf7 100644
--- a/mesalib/src/gallium/auxiliary/util/u_format_table.py
+++ b/mesalib/src/gallium/auxiliary/util/u_format_table.py
@@ -90,7 +90,7 @@ def write_format_table(formats):
print '#include "u_format_rgtc.h"'
print '#include "u_format_latc.h"'
print '#include "u_format_etc.h"'
- print '#include "u_format_bptc.h"'
+ print '#include "u_format_fake.h"'
print
u_format_pack.generate(formats)
diff --git a/mesalib/src/gallium/auxiliary/util/u_math.h b/mesalib/src/gallium/auxiliary/util/u_math.h
index 0113fb1a0..d6e83f962 100644
--- a/mesalib/src/gallium/auxiliary/util/u_math.h
+++ b/mesalib/src/gallium/auxiliary/util/u_math.h
@@ -40,7 +40,6 @@
#include "pipe/p_compiler.h"
-#include "util/u_debug.h"
#ifdef __cplusplus
@@ -530,6 +529,7 @@ unsigned ffs( unsigned u )
}
#elif defined(__MINGW32__) || defined(PIPE_OS_ANDROID)
#define ffs __builtin_ffs
+#define ffsll __builtin_ffsll
#endif
#endif /* FFS_DEFINED */
@@ -541,7 +541,7 @@ unsigned ffs( unsigned u )
static INLINE unsigned
util_last_bit(unsigned u)
{
-#if defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 304)
+#if defined(__GNUC__)
return u == 0 ? 0 : 32 - __builtin_clz(u);
#else
unsigned r = 0;
@@ -561,14 +561,10 @@ util_last_bit(unsigned u)
static INLINE unsigned
util_last_bit_signed(int i)
{
-#if defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 407) && !defined(__INTEL_COMPILER)
- return 31 - __builtin_clrsb(i);
-#else
if (i >= 0)
return util_last_bit(i);
else
return util_last_bit(~(unsigned)i);
-#endif
}
/* Destructively loop over all of the bits in a mask as in:
@@ -587,6 +583,15 @@ u_bit_scan(unsigned *mask)
return i;
}
+#ifndef _MSC_VER
+static INLINE int
+u_bit_scan64(uint64_t *mask)
+{
+ int i = ffsll(*mask) - 1;
+ *mask &= ~(1llu << i);
+ return i;
+}
+#endif
/**
* Return float bits.
@@ -602,9 +607,9 @@ fui( float f )
static INLINE float
uif(uint32_t ui)
{
- union fi fi;
- fi.ui = ui;
- return fi.f;
+ union fi fi;
+ fi.ui = ui;
+ return fi.f;
}
@@ -658,7 +663,7 @@ float_to_byte_tex(float f)
static INLINE unsigned
util_logbase2(unsigned n)
{
-#if defined(PIPE_CC_GCC) && (PIPE_CC_GCC_VERSION >= 304)
+#if defined(PIPE_CC_GCC)
return ((sizeof(unsigned) * 8 - 1) - __builtin_clz(n | 1));
#else
unsigned pos = 0;
@@ -678,7 +683,7 @@ util_logbase2(unsigned n)
static INLINE unsigned
util_next_power_of_two(unsigned x)
{
-#if defined(PIPE_CC_GCC) && (PIPE_CC_GCC_VERSION >= 304)
+#if defined(PIPE_CC_GCC)
if (x <= 1)
return 1;
@@ -710,7 +715,7 @@ util_next_power_of_two(unsigned x)
static INLINE unsigned
util_bitcount(unsigned n)
{
-#if defined(PIPE_CC_GCC) && (PIPE_CC_GCC_VERSION >= 304)
+#if defined(PIPE_CC_GCC)
return __builtin_popcount(n);
#else
/* K&R classic bitcount.
diff --git a/mesalib/src/gallium/auxiliary/util/u_prim.h b/mesalib/src/gallium/auxiliary/util/u_prim.h
index cf1a18f42..b2dd44df2 100644
--- a/mesalib/src/gallium/auxiliary/util/u_prim.h
+++ b/mesalib/src/gallium/auxiliary/util/u_prim.h
@@ -280,4 +280,10 @@ u_reduced_prims_for_vertices(int primitive, int vertices)
const char *u_prim_name( unsigned pipe_prim );
+
+#ifdef __cplusplus
+}
+#endif
+
+
#endif
diff --git a/mesalib/src/gallium/auxiliary/util/u_pstipple.c b/mesalib/src/gallium/auxiliary/util/u_pstipple.c
index 1e1ec4a98..0a20bdb47 100644
--- a/mesalib/src/gallium/auxiliary/util/u_pstipple.c
+++ b/mesalib/src/gallium/auxiliary/util/u_pstipple.c
@@ -182,6 +182,8 @@ struct pstip_transform_context {
int freeSampler; /** an available sampler for the pstipple */
int numImmed;
uint coordOrigin;
+ unsigned fixedUnit;
+ bool hasFixedUnit;
};
@@ -279,7 +281,8 @@ pstip_transform_prolog(struct tgsi_transform_context *ctx)
}
/* declare new sampler */
- tgsi_transform_sampler_decl(ctx, pctx->freeSampler);
+ tgsi_transform_sampler_decl(ctx,
+ pctx->hasFixedUnit ? pctx->fixedUnit : pctx->freeSampler);
/* Declare temp[0] reg if not already declared.
* We can always use temp[0] since this code is before
@@ -318,7 +321,8 @@ pstip_transform_prolog(struct tgsi_transform_context *ctx)
tgsi_transform_tex_2d_inst(ctx,
TGSI_FILE_TEMPORARY, texTemp,
TGSI_FILE_TEMPORARY, texTemp,
- pctx->freeSampler);
+ pctx->hasFixedUnit ? pctx->fixedUnit
+ : pctx->freeSampler);
/* KILL_IF -texTemp; # if -texTemp < 0, kill fragment */
tgsi_transform_kill_inst(ctx,
@@ -330,12 +334,16 @@ pstip_transform_prolog(struct tgsi_transform_context *ctx)
/**
* Given a fragment shader, return a new fragment shader which
* samples a stipple texture and executes KILL.
+ *
* \param samplerUnitOut returns the index of the sampler unit which
- * will be used to sample the stipple texture
+ * will be used to sample the stipple texture;
+ * if NULL, the fixed unit is used
+ * \param fixedUnit fixed texture unit used for the stipple texture
*/
struct tgsi_token *
util_pstipple_create_fragment_shader(const struct tgsi_token *tokens,
- unsigned *samplerUnitOut)
+ unsigned *samplerUnitOut,
+ unsigned fixedUnit)
{
struct pstip_transform_context transform;
const uint newLen = tgsi_num_tokens(tokens) + NUM_NEW_TOKENS;
@@ -352,6 +360,8 @@ util_pstipple_create_fragment_shader(const struct tgsi_token *tokens,
transform.wincoordInput = -1;
transform.maxInput = -1;
transform.coordOrigin = TGSI_FS_COORD_ORIGIN_UPPER_LEFT;
+ transform.hasFixedUnit = !samplerUnitOut;
+ transform.fixedUnit = fixedUnit;
transform.base.prolog = pstip_transform_prolog;
transform.base.transform_declaration = pstip_transform_decl;
transform.base.transform_immediate = pstip_transform_immed;
@@ -368,9 +378,10 @@ util_pstipple_create_fragment_shader(const struct tgsi_token *tokens,
tgsi_dump(new_fs->tokens, 0);
#endif
- assert(transform.freeSampler < PIPE_MAX_SAMPLERS);
- *samplerUnitOut = transform.freeSampler;
+ if (samplerUnitOut) {
+ assert(transform.freeSampler < PIPE_MAX_SAMPLERS);
+ *samplerUnitOut = transform.freeSampler;
+ }
return new_tokens;
}
-
diff --git a/mesalib/src/gallium/auxiliary/util/u_pstipple.h b/mesalib/src/gallium/auxiliary/util/u_pstipple.h
index 13155e7f5..249c58be9 100644
--- a/mesalib/src/gallium/auxiliary/util/u_pstipple.h
+++ b/mesalib/src/gallium/auxiliary/util/u_pstipple.h
@@ -49,7 +49,8 @@ util_pstipple_create_sampler(struct pipe_context *pipe);
struct tgsi_token *
util_pstipple_create_fragment_shader(const struct tgsi_token *tokens,
- unsigned *samplerUnitOut);
+ unsigned *samplerUnitOut,
+ unsigned fixed_unit);
#endif
diff --git a/mesalib/src/gallium/auxiliary/util/u_simple_list.h b/mesalib/src/gallium/auxiliary/util/u_simple_list.h
deleted file mode 100644
index 3f7def5fc..000000000
--- a/mesalib/src/gallium/auxiliary/util/u_simple_list.h
+++ /dev/null
@@ -1,199 +0,0 @@
-/**
- * \file simple_list.h
- * Simple macros for type-safe, intrusive lists.
- *
- * Intended to work with a list sentinal which is created as an empty
- * list. Insert & delete are O(1).
- *
- * \author
- * (C) 1997, Keith Whitwell
- */
-
-/*
- * Mesa 3-D graphics library
- *
- * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
- *
- * 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 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.
- */
-
-
-#ifndef _U_SIMPLE_LIST_H_
-#define _U_SIMPLE_LIST_H_
-
-/**
- * Remove an element from list.
- *
- * \param elem element to remove.
- */
-#define remove_from_list(elem) \
-do { \
- (elem)->next->prev = (elem)->prev; \
- (elem)->prev->next = (elem)->next; \
- (elem)->next = elem; \
- (elem)->prev = elem; \
-} while (0)
-
-/**
- * Insert an element to the list head.
- *
- * \param list list.
- * \param elem element to insert.
- */
-#define insert_at_head(list, elem) \
-do { \
- (elem)->prev = list; \
- (elem)->next = (list)->next; \
- (list)->next->prev = elem; \
- (list)->next = elem; \
-} while(0)
-
-/**
- * Insert an element to the list tail.
- *
- * \param list list.
- * \param elem element to insert.
- */
-#define insert_at_tail(list, elem) \
-do { \
- (elem)->next = list; \
- (elem)->prev = (list)->prev; \
- (list)->prev->next = elem; \
- (list)->prev = elem; \
-} while(0)
-
-/**
- * Move an element to the list head.
- *
- * \param list list.
- * \param elem element to move.
- */
-#define move_to_head(list, elem) \
-do { \
- remove_from_list(elem); \
- insert_at_head(list, elem); \
-} while (0)
-
-/**
- * Move an element to the list tail.
- *
- * \param list list.
- * \param elem element to move.
- */
-#define move_to_tail(list, elem) \
-do { \
- remove_from_list(elem); \
- insert_at_tail(list, elem); \
-} while (0)
-
-/**
- * Make a empty list empty.
- *
- * \param sentinal list (sentinal element).
- */
-#define make_empty_list(sentinal) \
-do { \
- (sentinal)->next = sentinal; \
- (sentinal)->prev = sentinal; \
-} while (0)
-
-/**
- * Get list first element.
- *
- * \param list list.
- *
- * \return pointer to first element.
- */
-#define first_elem(list) ((list)->next)
-
-/**
- * Get list last element.
- *
- * \param list list.
- *
- * \return pointer to last element.
- */
-#define last_elem(list) ((list)->prev)
-
-/**
- * Get next element.
- *
- * \param elem element.
- *
- * \return pointer to next element.
- */
-#define next_elem(elem) ((elem)->next)
-
-/**
- * Get previous element.
- *
- * \param elem element.
- *
- * \return pointer to previous element.
- */
-#define prev_elem(elem) ((elem)->prev)
-
-/**
- * Test whether element is at end of the list.
- *
- * \param list list.
- * \param elem element.
- *
- * \return non-zero if element is at end of list, or zero otherwise.
- */
-#define at_end(list, elem) ((elem) == (list))
-
-/**
- * Test if a list is empty.
- *
- * \param list list.
- *
- * \return non-zero if list empty, or zero otherwise.
- */
-#define is_empty_list(list) ((list)->next == (list))
-
-/**
- * Walk through the elements of a list.
- *
- * \param ptr pointer to the current element.
- * \param list list.
- *
- * \note It should be followed by a { } block or a single statement, as in a \c
- * for loop.
- */
-#define foreach(ptr, list) \
- for( ptr=(list)->next ; ptr!=list ; ptr=(ptr)->next )
-
-/**
- * Walk through the elements of a list.
- *
- * Same as #foreach but lets you unlink the current value during a list
- * traversal. Useful for freeing a list, element by element.
- *
- * \param ptr pointer to the current element.
- * \param t temporary pointer.
- * \param list list.
- *
- * \note It should be followed by a { } block or a single statement, as in a \c
- * for loop.
- */
-#define foreach_s(ptr, t, list) \
- for(ptr=(list)->next,t=(ptr)->next; list != ptr; ptr=t, t=(t)->next)
-
-#endif /* _U_SIMPLE_LIST_H_ */
diff --git a/mesalib/src/gallium/auxiliary/util/u_simple_shaders.c b/mesalib/src/gallium/auxiliary/util/u_simple_shaders.c
index edb30379b..c612b67e2 100644
--- a/mesalib/src/gallium/auxiliary/util/u_simple_shaders.c
+++ b/mesalib/src/gallium/auxiliary/util/u_simple_shaders.c
@@ -246,9 +246,15 @@ util_make_fragment_tex_shader_writemask(struct pipe_context *pipe,
ureg_MOV( ureg, out, imm );
}
- ureg_TEX( ureg,
- ureg_writemask(out, writemask),
- tex_target, tex, sampler );
+ if (tex_target == TGSI_TEXTURE_BUFFER)
+ ureg_TXF(ureg,
+ ureg_writemask(out, writemask),
+ tex_target, tex, sampler);
+ else
+ ureg_TEX(ureg,
+ ureg_writemask(out, writemask),
+ tex_target, tex, sampler);
+
ureg_END( ureg );
return ureg_create_shader_and_destroy( ureg, pipe );
diff --git a/mesalib/src/gallium/auxiliary/util/u_slab.c b/mesalib/src/gallium/auxiliary/util/u_slab.c
index dbdebc6c9..7e7d43bd8 100644
--- a/mesalib/src/gallium/auxiliary/util/u_slab.c
+++ b/mesalib/src/gallium/auxiliary/util/u_slab.c
@@ -24,7 +24,7 @@
#include "util/u_math.h"
#include "util/u_memory.h"
-#include "util/u_simple_list.h"
+#include "util/simple_list.h"
#include <stdio.h>
diff --git a/mesalib/src/gallium/auxiliary/util/u_tests.c b/mesalib/src/gallium/auxiliary/util/u_tests.c
index c0f6327b6..fe549723c 100644
--- a/mesalib/src/gallium/auxiliary/util/u_tests.c
+++ b/mesalib/src/gallium/auxiliary/util/u_tests.c
@@ -30,9 +30,13 @@
#include "util/u_draw_quad.h"
#include "util/u_format.h"
#include "util/u_inlines.h"
+#include "util/u_memory.h"
#include "util/u_simple_shaders.h"
#include "util/u_surface.h"
+#include "util/u_string.h"
#include "util/u_tile.h"
+#include "tgsi/tgsi_strings.h"
+#include "tgsi/tgsi_text.h"
#include "cso_cache/cso_context.h"
#include <stdio.h>
@@ -138,15 +142,70 @@ util_set_interleaved_vertex_elements(struct cso_context *cso,
free(velem);
}
+static void *
+util_set_passthrough_vertex_shader(struct cso_context *cso,
+ struct pipe_context *ctx,
+ bool window_space)
+{
+ static const uint vs_attribs[] = {
+ TGSI_SEMANTIC_POSITION,
+ TGSI_SEMANTIC_GENERIC
+ };
+ static const uint vs_indices[] = {0, 0};
+ void *vs;
+
+ vs = util_make_vertex_passthrough_shader(ctx, 2, vs_attribs, vs_indices,
+ window_space);
+ cso_set_vertex_shader_handle(cso, vs);
+ return vs;
+}
+
+static void
+util_set_common_states_and_clear(struct cso_context *cso, struct pipe_context *ctx,
+ struct pipe_resource *cb)
+{
+ static const float clear_color[] = {0.1, 0.1, 0.1, 0.1};
+
+ util_set_framebuffer_cb0(cso, ctx, cb);
+ util_set_blend_normal(cso);
+ util_set_dsa_disable(cso);
+ util_set_rasterizer_normal(cso);
+ util_set_max_viewport(cso, cb);
+
+ ctx->clear(ctx, PIPE_CLEAR_COLOR0, (void*)clear_color, 0, 0);
+}
+
+static void
+util_draw_fullscreen_quad(struct cso_context *cso)
+{
+ static float vertices[] = {
+ -1, -1, 0, 1, 0, 0, 0, 0,
+ -1, 1, 0, 1, 0, 1, 0, 0,
+ 1, 1, 0, 1, 1, 1, 0, 0,
+ 1, -1, 0, 1, 1, 0, 0, 0
+ };
+ util_set_interleaved_vertex_elements(cso, 2);
+ util_draw_user_vertex_buffer(cso, vertices, PIPE_PRIM_QUADS, 4, 2);
+}
+
+/**
+ * Probe and test if the rectangle contains the expected color.
+ *
+ * If "num_expected_colors" > 1, at least one expected color must match
+ * the probed color. "expected" should be an array of 4*num_expected_colors
+ * floats.
+ */
static bool
-util_probe_rect_rgba(struct pipe_context *ctx, struct pipe_resource *tex,
- unsigned offx, unsigned offy, unsigned w, unsigned h,
- const float *expected)
+util_probe_rect_rgba_multi(struct pipe_context *ctx, struct pipe_resource *tex,
+ unsigned offx, unsigned offy, unsigned w,
+ unsigned h,
+ const float *expected,
+ unsigned num_expected_colors)
{
struct pipe_transfer *transfer;
void *map;
float *pixels = malloc(w * h * 4 * sizeof(float));
- int x,y,c;
+ int x,y,e,c;
bool pass = true;
map = pipe_transfer_map(ctx, tex, 0, 0, PIPE_TRANSFER_READ,
@@ -154,21 +213,31 @@ util_probe_rect_rgba(struct pipe_context *ctx, struct pipe_resource *tex,
pipe_get_tile_rgba(transfer, map, 0, 0, w, h, pixels);
pipe_transfer_unmap(ctx, transfer);
- for (y = 0; y < h; y++) {
- for (x = 0; x < w; x++) {
- float *probe = &pixels[(y*w + x)*4];
-
- for (c = 0; c < 4; c++)
- if (fabs(probe[c] - expected[c]) >= TOLERANCE) {
- printf("Probe color at (%i,%i), ", offx+x, offy+y);
- printf("Expected: %.3f, %.3f, %.3f, %.3f, ",
- expected[0], expected[1], expected[2], expected[3]);
- printf("Got: %.3f, %.3f, %.3f, %.3f\n",
- probe[0], probe[1], probe[2], probe[2]);
- pass = false;
- goto done;
+ for (e = 0; e < num_expected_colors; e++) {
+ for (y = 0; y < h; y++) {
+ for (x = 0; x < w; x++) {
+ float *probe = &pixels[(y*w + x)*4];
+
+ for (c = 0; c < 4; c++) {
+ if (fabs(probe[c] - expected[e*4+c]) >= TOLERANCE) {
+ if (e < num_expected_colors-1)
+ goto next_color; /* test the next expected color */
+
+ printf("Probe color at (%i,%i), ", offx+x, offy+y);
+ printf("Expected: %.3f, %.3f, %.3f, %.3f, ",
+ expected[e*4], expected[e*4+1],
+ expected[e*4+2], expected[e*4+3]);
+ printf("Got: %.3f, %.3f, %.3f, %.3f\n",
+ probe[0], probe[1], probe[2], probe[2]);
+ pass = false;
+ goto done;
+ }
}
+ }
}
+ break; /* this color was successful */
+
+ next_color:;
}
done:
@@ -176,6 +245,37 @@ done:
return pass;
}
+static bool
+util_probe_rect_rgba(struct pipe_context *ctx, struct pipe_resource *tex,
+ unsigned offx, unsigned offy, unsigned w, unsigned h,
+ const float *expected)
+{
+ return util_probe_rect_rgba_multi(ctx, tex, offx, offy, w, h, expected, 1);
+}
+
+enum {
+ SKIP = -1,
+ FAIL = 0, /* also "false" */
+ PASS = 1 /* also "true" */
+};
+
+static void
+util_report_result_helper(int status, const char *name, ...)
+{
+ char buf[256];
+ va_list ap;
+
+ va_start(ap, name);
+ util_vsnprintf(buf, sizeof(buf), name, ap);
+ va_end(ap);
+
+ printf("Test(%s) = %s\n", buf,
+ status == SKIP ? "skip" :
+ status == PASS ? "pass" : "fail");
+}
+
+#define util_report_result(status) util_report_result_helper(status, __func__)
+
/**
* Test TGSI_PROPERTY_VS_WINDOW_SPACE_POSITION.
*
@@ -196,38 +296,18 @@ tgsi_vs_window_space_position(struct pipe_context *ctx)
struct pipe_resource *cb;
void *fs, *vs;
bool pass = true;
-
- static uint vs_attribs[] = {
- TGSI_SEMANTIC_POSITION,
- TGSI_SEMANTIC_GENERIC
- };
- static uint vs_indices[] = {0, 0};
- static float vertices[] = {
- 0, 0, 0, 0, 1, 0, 0, 1,
- 0, 256, 0, 0, 1, 0, 0, 1,
- 256, 256, 0, 0, 1, 0, 0, 1,
- 256, 0, 0, 0, 1, 0, 0, 1,
- };
- static float red[] = {1, 0, 0, 1};
- static float clear_color[] = {0.1, 0.1, 0.1, 0.1};
+ static const float red[] = {1, 0, 0, 1};
if (!ctx->screen->get_param(ctx->screen,
PIPE_CAP_TGSI_VS_WINDOW_SPACE_POSITION)) {
- printf("Test(%s) = skip\n", __func__);
+ util_report_result(SKIP);
return;
}
cso = cso_create_context(ctx);
cb = util_create_texture2d(ctx->screen, 256, 256,
PIPE_FORMAT_R8G8B8A8_UNORM);
-
- /* Set states. */
- util_set_framebuffer_cb0(cso, ctx, cb);
- util_set_blend_normal(cso);
- util_set_dsa_disable(cso);
- util_set_rasterizer_normal(cso);
- util_set_max_viewport(cso, cb);
- util_set_interleaved_vertex_elements(cso, 2);
+ util_set_common_states_and_clear(cso, ctx, cb);
/* Fragment shader. */
fs = util_make_fragment_passthrough_shader(ctx, TGSI_SEMANTIC_GENERIC,
@@ -235,26 +315,138 @@ tgsi_vs_window_space_position(struct pipe_context *ctx)
cso_set_fragment_shader_handle(cso, fs);
/* Vertex shader. */
- vs = util_make_vertex_passthrough_shader(ctx, 2, vs_attribs, vs_indices,
- TRUE);
- cso_set_vertex_shader_handle(cso, vs);
-
- /* Clear and draw. */
- ctx->clear(ctx, PIPE_CLEAR_COLOR0, (void*)clear_color, 0, 0);
- util_draw_user_vertex_buffer(cso, vertices, PIPE_PRIM_QUADS, 4, 2);
+ vs = util_set_passthrough_vertex_shader(cso, ctx, true);
+
+ /* Draw. */
+ {
+ static float vertices[] = {
+ 0, 0, 0, 0, 1, 0, 0, 1,
+ 0, 256, 0, 0, 1, 0, 0, 1,
+ 256, 256, 0, 0, 1, 0, 0, 1,
+ 256, 0, 0, 0, 1, 0, 0, 1,
+ };
+ util_set_interleaved_vertex_elements(cso, 2);
+ util_draw_user_vertex_buffer(cso, vertices, PIPE_PRIM_QUADS, 4, 2);
+ }
/* Probe pixels. */
pass = pass && util_probe_rect_rgba(ctx, cb, 0, 0,
cb->width0, cb->height0, red);
/* Cleanup. */
- cso_release_all(cso);
cso_destroy_context(cso);
ctx->delete_vs_state(ctx, vs);
ctx->delete_fs_state(ctx, fs);
pipe_resource_reference(&cb, NULL);
- printf("Test(%s) = %s\n", __func__, pass ? "pass" : "fail");
+ util_report_result(pass);
+}
+
+static void
+null_sampler_view(struct pipe_context *ctx, unsigned tgsi_tex_target)
+{
+ struct cso_context *cso;
+ struct pipe_resource *cb;
+ void *fs, *vs;
+ bool pass = true;
+ /* 2 expected colors: */
+ static const float expected_tex[] = {0, 0, 0, 1,
+ 0, 0, 0, 0};
+ static const float expected_buf[] = {0, 0, 0, 0};
+ const float *expected = tgsi_tex_target == TGSI_TEXTURE_BUFFER ?
+ expected_buf : expected_tex;
+ unsigned num_expected = tgsi_tex_target == TGSI_TEXTURE_BUFFER ? 1 : 2;
+
+ if (tgsi_tex_target == TGSI_TEXTURE_BUFFER &&
+ !ctx->screen->get_param(ctx->screen, PIPE_CAP_TEXTURE_BUFFER_OBJECTS)) {
+ util_report_result_helper(SKIP, "%s: %s", __func__,
+ tgsi_texture_names[tgsi_tex_target]);
+ return;
+ }
+
+ cso = cso_create_context(ctx);
+ cb = util_create_texture2d(ctx->screen, 256, 256,
+ PIPE_FORMAT_R8G8B8A8_UNORM);
+ util_set_common_states_and_clear(cso, ctx, cb);
+
+ ctx->set_sampler_views(ctx, PIPE_SHADER_FRAGMENT, 0, 1, NULL);
+
+ /* Fragment shader. */
+ fs = util_make_fragment_tex_shader(ctx, tgsi_tex_target,
+ TGSI_INTERPOLATE_LINEAR);
+ cso_set_fragment_shader_handle(cso, fs);
+
+ /* Vertex shader. */
+ vs = util_set_passthrough_vertex_shader(cso, ctx, false);
+ util_draw_fullscreen_quad(cso);
+
+ /* Probe pixels. */
+ pass = pass && util_probe_rect_rgba_multi(ctx, cb, 0, 0,
+ cb->width0, cb->height0, expected,
+ num_expected);
+
+ /* Cleanup. */
+ cso_destroy_context(cso);
+ ctx->delete_vs_state(ctx, vs);
+ ctx->delete_fs_state(ctx, fs);
+ pipe_resource_reference(&cb, NULL);
+
+ util_report_result_helper(pass, "%s: %s", __func__,
+ tgsi_texture_names[tgsi_tex_target]);
+}
+
+static void
+null_constant_buffer(struct pipe_context *ctx)
+{
+ struct cso_context *cso;
+ struct pipe_resource *cb;
+ void *fs, *vs;
+ bool pass = true;
+ static const float zero[] = {0, 0, 0, 0};
+
+ cso = cso_create_context(ctx);
+ cb = util_create_texture2d(ctx->screen, 256, 256,
+ PIPE_FORMAT_R8G8B8A8_UNORM);
+ util_set_common_states_and_clear(cso, ctx, cb);
+
+ ctx->set_constant_buffer(ctx, PIPE_SHADER_FRAGMENT, 0, NULL);
+
+ /* Fragment shader. */
+ {
+ static const char *text = /* I don't like ureg... */
+ "FRAG\n"
+ "DCL CONST[0]\n"
+ "DCL OUT[0], COLOR\n"
+
+ "MOV OUT[0], CONST[0]\n"
+ "END\n";
+ struct tgsi_token tokens[1000];
+ struct pipe_shader_state state = {tokens};
+
+ if (!tgsi_text_translate(text, tokens, Elements(tokens))) {
+ puts("Can't compile a fragment shader.");
+ util_report_result(FAIL);
+ return;
+ }
+ fs = ctx->create_fs_state(ctx, &state);
+ cso_set_fragment_shader_handle(cso, fs);
+ }
+
+ /* Vertex shader. */
+ vs = util_set_passthrough_vertex_shader(cso, ctx, false);
+ util_draw_fullscreen_quad(cso);
+
+ /* Probe pixels. */
+ pass = pass && util_probe_rect_rgba(ctx, cb, 0, 0, cb->width0,
+ cb->height0, zero);
+
+ /* Cleanup. */
+ cso_destroy_context(cso);
+ ctx->delete_vs_state(ctx, vs);
+ ctx->delete_fs_state(ctx, fs);
+ pipe_resource_reference(&cb, NULL);
+
+ util_report_result(pass);
}
/**
@@ -262,7 +454,17 @@ tgsi_vs_window_space_position(struct pipe_context *ctx)
* context_create.
*/
void
-util_run_tests(struct pipe_context *ctx)
+util_run_tests(struct pipe_screen *screen)
{
+ struct pipe_context *ctx = screen->context_create(screen, NULL);
+
tgsi_vs_window_space_position(ctx);
+ null_sampler_view(ctx, TGSI_TEXTURE_2D);
+ null_sampler_view(ctx, TGSI_TEXTURE_BUFFER);
+ null_constant_buffer(ctx);
+
+ ctx->destroy(ctx);
+
+ puts("Done. Exiting..");
+ exit(0);
}
diff --git a/mesalib/src/gallium/auxiliary/util/u_tests.h b/mesalib/src/gallium/auxiliary/util/u_tests.h
index a1439347d..49ae54f87 100644
--- a/mesalib/src/gallium/auxiliary/util/u_tests.h
+++ b/mesalib/src/gallium/auxiliary/util/u_tests.h
@@ -30,8 +30,8 @@
#include "pipe/p_compiler.h"
-struct pipe_context;
+struct pipe_screen;
-void util_run_tests(struct pipe_context *ctx);
+void util_run_tests(struct pipe_screen *screen);
#endif