aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/gallium
diff options
context:
space:
mode:
Diffstat (limited to 'mesalib/src/gallium')
-rw-r--r--mesalib/src/gallium/auxiliary/hud/hud_cpu.c12
-rw-r--r--mesalib/src/gallium/auxiliary/hud/hud_fps.c12
-rw-r--r--mesalib/src/gallium/auxiliary/hud/hud_private.h2
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_debug_stack.c56
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_debug_stack.h7
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_debug_symbol.c239
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_format.h25
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_format_pack.py29
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_format_parse.py10
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_format_table.py4
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_pack_color.h36
11 files changed, 301 insertions, 131 deletions
diff --git a/mesalib/src/gallium/auxiliary/hud/hud_cpu.c b/mesalib/src/gallium/auxiliary/hud/hud_cpu.c
index ce98115d5..cd20deec9 100644
--- a/mesalib/src/gallium/auxiliary/hud/hud_cpu.c
+++ b/mesalib/src/gallium/auxiliary/hud/hud_cpu.c
@@ -116,6 +116,12 @@ query_cpu_load(struct hud_graph *gr)
}
}
+static void
+free_query_data(void *p)
+{
+ FREE(p);
+}
+
void
hud_cpu_graph_install(struct hud_pane *pane, unsigned cpu_index)
{
@@ -144,7 +150,11 @@ hud_cpu_graph_install(struct hud_pane *pane, unsigned cpu_index)
}
gr->query_new_value = query_cpu_load;
- gr->free_query_data = free;
+
+ /* Don't use free() as our callback as that messes up Gallium's
+ * memory debugger. Use simple free_query_data() wrapper.
+ */
+ gr->free_query_data = free_query_data;
info = gr->query_data;
info->cpu_index = cpu_index;
diff --git a/mesalib/src/gallium/auxiliary/hud/hud_fps.c b/mesalib/src/gallium/auxiliary/hud/hud_fps.c
index 80381f547..6e9be712b 100644
--- a/mesalib/src/gallium/auxiliary/hud/hud_fps.c
+++ b/mesalib/src/gallium/auxiliary/hud/hud_fps.c
@@ -60,6 +60,12 @@ query_fps(struct hud_graph *gr)
}
}
+static void
+free_query_data(void *p)
+{
+ FREE(p);
+}
+
void
hud_fps_graph_install(struct hud_pane *pane)
{
@@ -76,7 +82,11 @@ hud_fps_graph_install(struct hud_pane *pane)
}
gr->query_new_value = query_fps;
- gr->free_query_data = free;
+
+ /* Don't use free() as our callback as that messes up Gallium's
+ * memory debugger. Use simple free_query_data() wrapper.
+ */
+ gr->free_query_data = free_query_data;
hud_pane_add_graph(pane, gr);
}
diff --git a/mesalib/src/gallium/auxiliary/hud/hud_private.h b/mesalib/src/gallium/auxiliary/hud/hud_private.h
index 2b7d56bb1..1606ada4a 100644
--- a/mesalib/src/gallium/auxiliary/hud/hud_private.h
+++ b/mesalib/src/gallium/auxiliary/hud/hud_private.h
@@ -42,7 +42,7 @@ struct hud_graph {
char name[128];
void *query_data;
void (*query_new_value)(struct hud_graph *gr);
- void (*free_query_data)(void *ptr);
+ void (*free_query_data)(void *ptr); /**< do not use ordinary free() */
/* mutable variables */
unsigned num_vertices;
diff --git a/mesalib/src/gallium/auxiliary/util/u_debug_stack.c b/mesalib/src/gallium/auxiliary/util/u_debug_stack.c
index 50a248a97..68961d351 100644
--- a/mesalib/src/gallium/auxiliary/util/u_debug_stack.c
+++ b/mesalib/src/gallium/auxiliary/util/u_debug_stack.c
@@ -36,7 +36,17 @@
#include "u_debug_symbol.h"
#include "u_debug_stack.h"
+#if defined(PIPE_OS_WINDOWS)
+#include <windows.h>
+#endif
+
+/**
+ * Capture stack backtrace.
+ *
+ * NOTE: The implementation of this function is quite big, but it is important not to
+ * break it down in smaller functions to avoid adding new frames to the calling stack.
+ */
void
debug_backtrace_capture(struct debug_stack_frame *backtrace,
unsigned start_frame,
@@ -45,8 +55,50 @@ debug_backtrace_capture(struct debug_stack_frame *backtrace,
const void **frame_pointer = NULL;
unsigned i = 0;
- if(!nr_frames)
+ if (!nr_frames) {
return;
+ }
+
+ /*
+ * On Windows try obtaining the stack backtrace via CaptureStackBackTrace.
+ *
+ * It works reliably both for x86 for x86_64.
+ */
+#if defined(PIPE_OS_WINDOWS)
+ {
+ typedef USHORT (WINAPI *PFNCAPTURESTACKBACKTRACE)(ULONG, ULONG, PVOID *, PULONG);
+ static PFNCAPTURESTACKBACKTRACE pfnCaptureStackBackTrace = NULL;
+
+ if (!pfnCaptureStackBackTrace) {
+ static HMODULE hModule = NULL;
+ if (!hModule) {
+ hModule = LoadLibraryA("kernel32");
+ assert(hModule);
+ }
+ if (hModule) {
+ pfnCaptureStackBackTrace = (PFNCAPTURESTACKBACKTRACE)GetProcAddress(hModule,
+ "RtlCaptureStackBackTrace");
+ }
+ }
+ if (pfnCaptureStackBackTrace) {
+ /*
+ * Skip this (debug_backtrace_capture) function's frame.
+ */
+
+ start_frame += 1;
+
+ assert(start_frame + nr_frames < 63);
+ i = pfnCaptureStackBackTrace(start_frame, nr_frames, (PVOID *) &backtrace->function, NULL);
+
+ /* Pad remaing requested frames with NULL */
+ while (i < nr_frames) {
+ backtrace[i++].function = NULL;
+ }
+
+ return;
+ }
+ }
+#endif
#if defined(PIPE_CC_GCC)
frame_pointer = ((const void **)__builtin_frame_address(1));
@@ -86,7 +138,7 @@ debug_backtrace_capture(struct debug_stack_frame *backtrace,
#else
(void) frame_pointer;
#endif
-
+
while(nr_frames) {
backtrace[i++].function = NULL;
--nr_frames;
diff --git a/mesalib/src/gallium/auxiliary/util/u_debug_stack.h b/mesalib/src/gallium/auxiliary/util/u_debug_stack.h
index f50f04e0f..b1848ddef 100644
--- a/mesalib/src/gallium/auxiliary/util/u_debug_stack.h
+++ b/mesalib/src/gallium/auxiliary/util/u_debug_stack.h
@@ -42,6 +42,13 @@ extern "C" {
#endif
+/**
+ * Represent a frame from a stack backtrace.
+ *
+ * XXX: Do not change this.
+ *
+ * TODO: This should be refactored as a void * typedef.
+ */
struct debug_stack_frame
{
const void *function;
diff --git a/mesalib/src/gallium/auxiliary/util/u_debug_symbol.c b/mesalib/src/gallium/auxiliary/util/u_debug_symbol.c
index 0ef111c3b..bba9122e7 100644
--- a/mesalib/src/gallium/auxiliary/util/u_debug_symbol.c
+++ b/mesalib/src/gallium/auxiliary/util/u_debug_symbol.c
@@ -40,7 +40,8 @@
#include "u_debug_symbol.h"
#include "u_hash_table.h"
-#if defined(PIPE_OS_WINDOWS) && defined(PIPE_ARCH_X86)
+
+#if defined(PIPE_OS_WINDOWS)
#include <windows.h>
#include <stddef.h>
@@ -48,139 +49,221 @@
#include "dbghelp.h"
-static BOOL bSymInitialized = FALSE;
-
-static HMODULE hModule_Dbghelp = NULL;
+/**
+ * SymInitialize() must be called once for each process (in this case, the
+ * current process), before any of the other functions can be called.
+ */
+static BOOL g_bSymInitialized = FALSE;
-static
-FARPROC WINAPI __GetProcAddress(LPCSTR lpProcName)
+/**
+ * Lookup the address of a DbgHelp function.
+ */
+static FARPROC WINAPI
+getDbgHelpProcAddress(LPCSTR lpProcName)
{
+ static HMODULE hModule = NULL;
+
+ if (!hModule) {
+ static boolean bail = FALSE;
+
+ if (bail) {
+ return NULL;
+ }
+
#ifdef PIPE_CC_GCC
- if (!hModule_Dbghelp) {
/*
- * bfdhelp.dll is a dbghelp.dll look-alike replacement, which is able to
- * understand MinGW symbols using BFD library. It is available from
+ * DbgHelp does not understand the debug information generated by MinGW toolchain.
+ *
+ * mgwhelp.dll is a dbghelp.dll look-alike replacement, which is able to
+ * understand MinGW symbols, including on 64-bit builds.
+ */
+ if (!hModule) {
+ hModule = LoadLibraryA("mgwhelp.dll");
+ if (!hModule) {
+ _debug_printf("warning: mgwhelp.dll not found: symbol names will not be resolved\n"
+ "warning: download it from http://code.google.com/p/jrfonseca/wiki/DrMingw#MgwHelp\n");
+ }
+ }
+
+ /*
+ * bfdhelp.dll was the predecessor of mgwhelp.dll. It is available from
* http://people.freedesktop.org/~jrfonseca/bfdhelp/ for now.
*/
- hModule_Dbghelp = LoadLibraryA("bfdhelp.dll");
- }
-#endif
+ if (!hModule) {
+ hModule = LoadLibraryA("bfdhelp.dll");
+ }
+ #endif
- if (!hModule_Dbghelp) {
- hModule_Dbghelp = LoadLibraryA("dbghelp.dll");
- if (!hModule_Dbghelp) {
+ /*
+ * Fallback to the real DbgHelp.
+ */
+ if (!hModule) {
+ hModule = LoadLibraryA("dbghelp.dll");
+ }
+
+ if (!hModule) {
+ bail = TRUE;
return NULL;
}
}
- return GetProcAddress(hModule_Dbghelp, lpProcName);
+ return GetProcAddress(hModule, lpProcName);
}
-typedef BOOL (WINAPI *PFNSYMINITIALIZE)(HANDLE, LPSTR, BOOL);
-static PFNSYMINITIALIZE pfnSymInitialize = NULL;
+/**
+ * Generic macro to dispatch a DbgHelp functions.
+ */
+#define DBGHELP_DISPATCH(_name, _ret_type, _ret_default, _arg_types, _arg_names) \
+ static _ret_type WINAPI \
+ j_##_name _arg_types \
+ { \
+ typedef BOOL (WINAPI *PFN) _arg_types; \
+ static PFN pfn = NULL; \
+ if (!pfn) { \
+ pfn = (PFN) getDbgHelpProcAddress(#_name); \
+ if (!pfn) { \
+ return _ret_default; \
+ } \
+ } \
+ return pfn _arg_names; \
+ }
-static
-BOOL WINAPI j_SymInitialize(HANDLE hProcess, PSTR UserSearchPath, BOOL fInvadeProcess)
-{
- if(
- (pfnSymInitialize || (pfnSymInitialize = (PFNSYMINITIALIZE) __GetProcAddress("SymInitialize")))
- )
- return pfnSymInitialize(hProcess, UserSearchPath, fInvadeProcess);
- else
- return FALSE;
-}
+DBGHELP_DISPATCH(SymInitialize,
+ BOOL, 0,
+ (HANDLE hProcess, PSTR UserSearchPath, BOOL fInvadeProcess),
+ (hProcess, UserSearchPath, fInvadeProcess))
-typedef DWORD (WINAPI *PFNSYMSETOPTIONS)(DWORD);
-static PFNSYMSETOPTIONS pfnSymSetOptions = NULL;
+DBGHELP_DISPATCH(SymSetOptions,
+ DWORD, FALSE,
+ (DWORD SymOptions),
+ (SymOptions))
-static
-DWORD WINAPI j_SymSetOptions(DWORD SymOptions)
-{
- if(
- (pfnSymSetOptions || (pfnSymSetOptions = (PFNSYMSETOPTIONS) __GetProcAddress("SymSetOptions")))
- )
- return pfnSymSetOptions(SymOptions);
- else
- return FALSE;
-}
+DBGHELP_DISPATCH(SymFromAddr,
+ BOOL, FALSE,
+ (HANDLE hProcess, DWORD64 Address, PDWORD64 Displacement, PSYMBOL_INFO Symbol),
+ (hProcess, Address, Displacement, Symbol))
-typedef BOOL (WINAPI *PFNSYMGETSYMFROMADDR)(HANDLE, DWORD64, PDWORD64, PSYMBOL_INFO);
-static PFNSYMGETSYMFROMADDR pfnSymFromAddr = NULL;
+DBGHELP_DISPATCH(SymGetLineFromAddr64,
+ BOOL, FALSE,
+ (HANDLE hProcess, DWORD64 dwAddr, PDWORD pdwDisplacement, PIMAGEHLP_LINE64 Line),
+ (hProcess, dwAddr, pdwDisplacement, Line))
-static
-BOOL WINAPI j_SymFromAddr(HANDLE hProcess, DWORD64 Address, PDWORD64 Displacement, PSYMBOL_INFO Symbol)
-{
- if(
- (pfnSymFromAddr || (pfnSymFromAddr = (PFNSYMGETSYMFROMADDR) __GetProcAddress("SymFromAddr")))
- )
- return pfnSymFromAddr(hProcess, Address, Displacement, Symbol);
- else
- return FALSE;
-}
+
+#undef DBGHELP_DISPATCH
-static INLINE void
+static INLINE boolean
debug_symbol_name_dbghelp(const void *addr, char* buf, unsigned size)
{
- HANDLE hProcess;
- BYTE symbolBuffer[1024];
- PSYMBOL_INFO pSymbol = (PSYMBOL_INFO) symbolBuffer;
- DWORD64 dwDisplacement = 0; /* Displacement of the input address, relative to the start of the symbol */
+ DWORD64 dwAddr = (DWORD64)(uintptr_t)addr;
+ HANDLE hProcess = GetCurrentProcess();
- hProcess = GetCurrentProcess();
+ /* General purpose buffer, to back pSymbol and other temporary stuff.
+ * Must not be too memory hungry here to avoid stack overflows.
+ */
+ CHAR buffer[512];
+
+ PSYMBOL_INFO pSymbol = (PSYMBOL_INFO) buffer;
+ DWORD64 dwDisplacement = 0; /* Displacement of the input address, relative to the start of the symbol */
+ DWORD dwLineDisplacement = 0;
+ IMAGEHLP_LINE64 Line;
memset(pSymbol, 0, sizeof *pSymbol);
- pSymbol->SizeOfStruct = sizeof(symbolBuffer);
- pSymbol->MaxNameLen = sizeof(symbolBuffer) - offsetof(SYMBOL_INFO, Name);
+ pSymbol->SizeOfStruct = sizeof buffer;
+ pSymbol->MaxNameLen = sizeof buffer - offsetof(SYMBOL_INFO, Name);
- if(!bSymInitialized) {
+ if (!g_bSymInitialized) {
j_SymSetOptions(/* SYMOPT_UNDNAME | */ SYMOPT_LOAD_LINES);
- if(j_SymInitialize(hProcess, NULL, TRUE))
- bSymInitialized = TRUE;
+ if (j_SymInitialize(hProcess, NULL, TRUE)) {
+ g_bSymInitialized = TRUE;
+ }
}
- if(!j_SymFromAddr(hProcess, (DWORD64)(uintptr_t)addr, &dwDisplacement, pSymbol))
- buf[0] = 0;
- else
- {
- strncpy(buf, pSymbol->Name, size);
- buf[size - 1] = 0;
+ /* Lookup symbol name */
+ if (!g_bSymInitialized ||
+ !j_SymFromAddr(hProcess, dwAddr, &dwDisplacement, pSymbol)) {
+ /*
+ * We couldn't obtain symbol information. At least tell which module the address belongs.
+ */
+
+ HMODULE hModule = NULL;
+
+ if (!GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
+ (LPCTSTR)addr,
+ &hModule)) {
+ return FALSE;
+ }
+
+ if (GetModuleFileNameA(hModule, buffer, sizeof buffer) == sizeof buffer) {
+ return FALSE;
+ }
+ util_snprintf(buf, size, "%p at %s+0x%lx",
+ addr, buffer,
+ (unsigned long)((uintptr_t)addr - (uintptr_t)hModule));
+
+ return TRUE;
}
+
+ /*
+ * Try to get filename and line number.
+ */
+ memset(&Line, 0, sizeof Line);
+ Line.SizeOfStruct = sizeof Line;
+ if (!j_SymGetLineFromAddr64(hProcess, dwAddr, &dwLineDisplacement, &Line)) {
+ Line.FileName = NULL;
+ }
+
+ if (Line.FileName) {
+ util_snprintf(buf, size, "%s at %s:%lu", pSymbol->Name, Line.FileName, Line.LineNumber);
+ } else {
+ util_snprintf(buf, size, "%s", pSymbol->Name);
+ }
+
+ return TRUE;
}
-#endif
+
+#endif /* PIPE_OS_WINDOWS */
+
#if defined(__GLIBC__) && !defined(__UCLIBC__)
+
#include <execinfo.h>
/* This can only provide dynamic symbols, or binary offsets into a file.
*
* To fix this, post-process the output with tools/addr2line.sh
*/
-static INLINE void
+static INLINE boolean
debug_symbol_name_glibc(const void *addr, char* buf, unsigned size)
{
char** syms = backtrace_symbols((void**)&addr, 1);
+ if (!syms) {
+ return FALSE;
+ }
strncpy(buf, syms[0], size);
buf[size - 1] = 0;
free(syms);
+ return TRUE;
}
-#endif
+
+#endif /* defined(__GLIBC__) && !defined(__UCLIBC__) */
+
void
debug_symbol_name(const void *addr, char* buf, unsigned size)
{
-#if defined(PIPE_OS_WINDOWS) && defined(PIPE_ARCH_X86)
- debug_symbol_name_dbghelp(addr, buf, size);
- if(buf[0])
+#if defined(PIPE_OS_WINDOWS)
+ if (debug_symbol_name_dbghelp(addr, buf, size)) {
return;
+ }
#endif
#if defined(__GLIBC__) && !defined(__UCLIBC__)
- debug_symbol_name_glibc(addr, buf, size);
- if(buf[0])
- return;
+ if (debug_symbol_name_glibc(addr, buf, size)) {
+ return;
+ }
#endif
util_snprintf(buf, size, "%p", addr);
diff --git a/mesalib/src/gallium/auxiliary/util/u_format.h b/mesalib/src/gallium/auxiliary/util/u_format.h
index 4cace6ad1..9774a2b4c 100644
--- a/mesalib/src/gallium/auxiliary/util/u_format.h
+++ b/mesalib/src/gallium/auxiliary/util/u_format.h
@@ -133,6 +133,7 @@ struct util_format_channel_description
unsigned normalized:1;
unsigned pure_integer:1;
unsigned size:9; /**< bits per channel */
+ unsigned shift:16; /** number of bits from lsb */
};
@@ -179,9 +180,31 @@ struct util_format_description
unsigned is_mixed:1;
/**
- * Input channel description.
+ * Input channel description, in the order XYZW.
*
* Only valid for UTIL_FORMAT_LAYOUT_PLAIN formats.
+ *
+ * If each channel is accessed as an individual N-byte value, X is always
+ * at the lowest address in memory, Y is always next, and so on. For all
+ * currently-defined formats, the N-byte value has native endianness.
+ *
+ * If instead a group of channels is accessed as a single N-byte value,
+ * the order of the channels within that value depends on endianness.
+ * For big-endian targets, X is the most significant subvalue,
+ * otherwise it is the least significant one.
+ *
+ * For example, if X is 8 bits and Y is 24 bits, the memory order is:
+ *
+ * 0 1 2 3
+ * little-endian: X Yl Ym Yu (l = lower, m = middle, u = upper)
+ * big-endian: X Yu Ym Yl
+ *
+ * If X is 5 bits, Y is 5 bits, Z is 5 bits and W is 1 bit, the layout is:
+ *
+ * 0 1
+ * msb lsb msb lsb
+ * little-endian: YYYXXXXX WZZZZZYY
+ * big-endian: XXXXXYYY YYZZZZZW
*/
struct util_format_channel_description channel[4];
diff --git a/mesalib/src/gallium/auxiliary/util/u_format_pack.py b/mesalib/src/gallium/auxiliary/util/u_format_pack.py
index 565d059c3..d1f68c804 100644
--- a/mesalib/src/gallium/auxiliary/util/u_format_pack.py
+++ b/mesalib/src/gallium/auxiliary/util/u_format_pack.py
@@ -99,15 +99,6 @@ def generate_format_type(format):
print
-def bswap_format(format):
- '''Generate a structure that describes the format.'''
-
- if format.is_bitmask() and not format.is_array() and format.block_size() > 8:
- print '#ifdef PIPE_ARCH_BIG_ENDIAN'
- print ' pixel.value = util_bswap%u(pixel.value);' % format.block_size()
- print '#endif'
-
-
def is_format_supported(format):
'''Determines whether we actually have the plumbing necessary to generate the
to read/write to/from this format.'''
@@ -423,16 +414,11 @@ def generate_unpack_kernel(format, dst_channel, dst_native_type):
elif src_channel.type == SIGNED:
print ' int%u_t %s;' % (depth, src_channel.name)
- if depth > 8:
- print '#ifdef PIPE_ARCH_BIG_ENDIAN'
- print ' value = util_bswap%u(value);' % depth
- print '#endif'
-
# Compute the intermediate unshifted values
- shift = 0
for i in range(format.nr_channels()):
src_channel = format.channels[i]
value = 'value'
+ shift = src_channel.shift
if src_channel.type == UNSIGNED:
if shift:
value = '%s >> %u' % (value, shift)
@@ -455,8 +441,6 @@ def generate_unpack_kernel(format, dst_channel, dst_native_type):
if value is not None:
print ' %s = %s;' % (src_channel.name, value)
- shift += src_channel.size
-
# Convert, swizzle, and store final values
for i in range(4):
swizzle = format.swizzles[i]
@@ -484,7 +468,6 @@ def generate_unpack_kernel(format, dst_channel, dst_native_type):
else:
print ' union util_format_%s pixel;' % format.short_name()
print ' memcpy(&pixel, src, sizeof pixel);'
- bswap_format(format)
for i in range(4):
swizzle = format.swizzles[i]
@@ -525,9 +508,9 @@ def generate_pack_kernel(format, src_channel, src_native_type):
depth = format.block_size()
print ' uint%u_t value = 0;' % depth
- shift = 0
for i in range(4):
dst_channel = format.channels[i]
+ shift = dst_channel.shift
if inv_swizzle[i] is not None:
value ='src[%u]' % inv_swizzle[i]
dst_colorspace = format.colorspace
@@ -551,13 +534,6 @@ def generate_pack_kernel(format, src_channel, src_native_type):
if value is not None:
print ' value |= %s;' % (value)
- shift += dst_channel.size
-
- if depth > 8:
- print '#ifdef PIPE_ARCH_BIG_ENDIAN'
- print ' value = util_bswap%u(value);' % depth
- print '#endif'
-
print ' *(uint%u_t *)dst = value;' % depth
else:
@@ -579,7 +555,6 @@ def generate_pack_kernel(format, src_channel, src_native_type):
dst_colorspace = dst_colorspace)
print ' pixel.chan.%s = %s;' % (dst_channel.name, value)
- bswap_format(format)
print ' memcpy(dst, &pixel, sizeof pixel);'
diff --git a/mesalib/src/gallium/auxiliary/util/u_format_parse.py b/mesalib/src/gallium/auxiliary/util/u_format_parse.py
index 07052b996..e202099b9 100644
--- a/mesalib/src/gallium/auxiliary/util/u_format_parse.py
+++ b/mesalib/src/gallium/auxiliary/util/u_format_parse.py
@@ -30,6 +30,8 @@
'''
+import sys
+
VOID, UNSIGNED, SIGNED, FIXED, FLOAT = range(5)
SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_W, SWIZZLE_0, SWIZZLE_1, SWIZZLE_NONE, = range(7)
@@ -42,6 +44,9 @@ YUV = 'yuv'
ZS = 'zs'
+# Not cross-compiler friendly
+is_big_endian = sys.byteorder == 'big'
+
def is_pot(x):
return (x & (x - 1)) == 0
@@ -307,6 +312,11 @@ def parse(filename):
channel = Channel(type, norm, pure, size, names[i])
channels.append(channel)
+ shift = 0
+ for channel in channels[3::-1] if is_big_endian else channels:
+ channel.shift = shift
+ shift += channel.size
+
format = Format(name, layout, block_width, block_height, channels, swizzles, colorspace)
formats.append(format)
return formats
diff --git a/mesalib/src/gallium/auxiliary/util/u_format_table.py b/mesalib/src/gallium/auxiliary/util/u_format_table.py
index 8edb50523..9d44cf391 100644
--- a/mesalib/src/gallium/auxiliary/util/u_format_table.py
+++ b/mesalib/src/gallium/auxiliary/util/u_format_table.py
@@ -114,9 +114,9 @@ def write_format_table(formats):
else:
sep = ""
if channel.size:
- print " {%s, %s, %s, %u}%s\t/* %s = %s */" % (type_map[channel.type], bool_map(channel.norm), bool_map(channel.pure), channel.size, sep, "xyzw"[i], channel.name)
+ print " {%s, %s, %s, %u, %u}%s\t/* %s = %s */" % (type_map[channel.type], bool_map(channel.norm), bool_map(channel.pure), channel.size, channel.shift, sep, "xyzw"[i], channel.name)
else:
- print " {0, 0, 0, 0}%s" % (sep,)
+ print " {0, 0, 0, 0, 0}%s" % (sep,)
print " },"
print " {"
for i in range(4):
diff --git a/mesalib/src/gallium/auxiliary/util/u_pack_color.h b/mesalib/src/gallium/auxiliary/util/u_pack_color.h
index 1f6a56a33..102ad6051 100644
--- a/mesalib/src/gallium/auxiliary/util/u_pack_color.h
+++ b/mesalib/src/gallium/auxiliary/util/u_pack_color.h
@@ -65,32 +65,32 @@ util_pack_color_ub(ubyte r, ubyte g, ubyte b, ubyte a,
enum pipe_format format, union util_color *uc)
{
switch (format) {
- case PIPE_FORMAT_A8B8G8R8_UNORM:
+ case PIPE_FORMAT_ABGR8888_UNORM:
{
uc->ui = (r << 24) | (g << 16) | (b << 8) | a;
}
return;
- case PIPE_FORMAT_X8B8G8R8_UNORM:
+ case PIPE_FORMAT_XBGR8888_UNORM:
{
uc->ui = (r << 24) | (g << 16) | (b << 8) | 0xff;
}
return;
- case PIPE_FORMAT_B8G8R8A8_UNORM:
+ case PIPE_FORMAT_BGRA8888_UNORM:
{
uc->ui = (a << 24) | (r << 16) | (g << 8) | b;
}
return;
- case PIPE_FORMAT_B8G8R8X8_UNORM:
+ case PIPE_FORMAT_BGRX8888_UNORM:
{
uc->ui = (0xff << 24) | (r << 16) | (g << 8) | b;
}
return;
- case PIPE_FORMAT_A8R8G8B8_UNORM:
+ case PIPE_FORMAT_ARGB8888_UNORM:
{
uc->ui = (b << 24) | (g << 16) | (r << 8) | a;
}
return;
- case PIPE_FORMAT_X8R8G8B8_UNORM:
+ case PIPE_FORMAT_XRGB8888_UNORM:
{
uc->ui = (b << 24) | (g << 16) | (r << 8) | 0xff;
}
@@ -166,7 +166,7 @@ util_unpack_color_ub(enum pipe_format format, union util_color *uc,
ubyte *r, ubyte *g, ubyte *b, ubyte *a)
{
switch (format) {
- case PIPE_FORMAT_A8B8G8R8_UNORM:
+ case PIPE_FORMAT_ABGR8888_UNORM:
{
uint p = uc->ui;
*r = (ubyte) ((p >> 24) & 0xff);
@@ -175,7 +175,7 @@ util_unpack_color_ub(enum pipe_format format, union util_color *uc,
*a = (ubyte) ((p >> 0) & 0xff);
}
return;
- case PIPE_FORMAT_X8B8G8R8_UNORM:
+ case PIPE_FORMAT_XBGR8888_UNORM:
{
uint p = uc->ui;
*r = (ubyte) ((p >> 24) & 0xff);
@@ -184,7 +184,7 @@ util_unpack_color_ub(enum pipe_format format, union util_color *uc,
*a = (ubyte) 0xff;
}
return;
- case PIPE_FORMAT_B8G8R8A8_UNORM:
+ case PIPE_FORMAT_BGRA8888_UNORM:
{
uint p = uc->ui;
*r = (ubyte) ((p >> 16) & 0xff);
@@ -193,7 +193,7 @@ util_unpack_color_ub(enum pipe_format format, union util_color *uc,
*a = (ubyte) ((p >> 24) & 0xff);
}
return;
- case PIPE_FORMAT_B8G8R8X8_UNORM:
+ case PIPE_FORMAT_BGRX8888_UNORM:
{
uint p = uc->ui;
*r = (ubyte) ((p >> 16) & 0xff);
@@ -202,7 +202,7 @@ util_unpack_color_ub(enum pipe_format format, union util_color *uc,
*a = (ubyte) 0xff;
}
return;
- case PIPE_FORMAT_A8R8G8B8_UNORM:
+ case PIPE_FORMAT_ARGB8888_UNORM:
{
uint p = uc->ui;
*r = (ubyte) ((p >> 8) & 0xff);
@@ -211,7 +211,7 @@ util_unpack_color_ub(enum pipe_format format, union util_color *uc,
*a = (ubyte) ((p >> 0) & 0xff);
}
return;
- case PIPE_FORMAT_X8R8G8B8_UNORM:
+ case PIPE_FORMAT_XRGB8888_UNORM:
{
uint p = uc->ui;
*r = (ubyte) ((p >> 8) & 0xff);
@@ -350,32 +350,32 @@ util_pack_color(const float rgba[4], enum pipe_format format, union util_color *
}
switch (format) {
- case PIPE_FORMAT_A8B8G8R8_UNORM:
+ case PIPE_FORMAT_ABGR8888_UNORM:
{
uc->ui = (r << 24) | (g << 16) | (b << 8) | a;
}
return;
- case PIPE_FORMAT_X8B8G8R8_UNORM:
+ case PIPE_FORMAT_XBGR8888_UNORM:
{
uc->ui = (r << 24) | (g << 16) | (b << 8) | 0xff;
}
return;
- case PIPE_FORMAT_B8G8R8A8_UNORM:
+ case PIPE_FORMAT_BGRA8888_UNORM:
{
uc->ui = (a << 24) | (r << 16) | (g << 8) | b;
}
return;
- case PIPE_FORMAT_B8G8R8X8_UNORM:
+ case PIPE_FORMAT_BGRX8888_UNORM:
{
uc->ui = (0xff << 24) | (r << 16) | (g << 8) | b;
}
return;
- case PIPE_FORMAT_A8R8G8B8_UNORM:
+ case PIPE_FORMAT_ARGB8888_UNORM:
{
uc->ui = (b << 24) | (g << 16) | (r << 8) | a;
}
return;
- case PIPE_FORMAT_X8R8G8B8_UNORM:
+ case PIPE_FORMAT_XRGB8888_UNORM:
{
uc->ui = (b << 24) | (g << 16) | (r << 8) | 0xff;
}