|
|
|
@ -35,6 +35,7 @@ |
|
|
|
|
* @author Jose Fonseca <jfonseca@vmware.com> |
|
|
|
|
*/ |
|
|
|
|
''' |
|
|
|
|
from __future__ import print_function |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from u_format_parse import * |
|
|
|
@ -54,11 +55,11 @@ def print_channels(format, func): |
|
|
|
|
if format.nr_channels() <= 1: |
|
|
|
|
func(format.le_channels, format.le_swizzles) |
|
|
|
|
else: |
|
|
|
|
print '#ifdef PIPE_ARCH_BIG_ENDIAN' |
|
|
|
|
print('#ifdef PIPE_ARCH_BIG_ENDIAN') |
|
|
|
|
func(format.be_channels, format.be_swizzles) |
|
|
|
|
print '#else' |
|
|
|
|
print('#else') |
|
|
|
|
func(format.le_channels, format.le_swizzles) |
|
|
|
|
print '#endif' |
|
|
|
|
print('#endif') |
|
|
|
|
|
|
|
|
|
def generate_format_type(format): |
|
|
|
|
'''Generate a structure that describes the format.''' |
|
|
|
@ -69,18 +70,18 @@ def generate_format_type(format): |
|
|
|
|
for channel in channels: |
|
|
|
|
if channel.type == VOID: |
|
|
|
|
if channel.size: |
|
|
|
|
print ' unsigned %s:%u;' % (channel.name, channel.size) |
|
|
|
|
print(' unsigned %s:%u;' % (channel.name, channel.size)) |
|
|
|
|
elif channel.type == UNSIGNED: |
|
|
|
|
print ' unsigned %s:%u;' % (channel.name, channel.size) |
|
|
|
|
print(' unsigned %s:%u;' % (channel.name, channel.size)) |
|
|
|
|
elif channel.type in (SIGNED, FIXED): |
|
|
|
|
print ' int %s:%u;' % (channel.name, channel.size) |
|
|
|
|
print(' int %s:%u;' % (channel.name, channel.size)) |
|
|
|
|
elif channel.type == FLOAT: |
|
|
|
|
if channel.size == 64: |
|
|
|
|
print ' double %s;' % (channel.name) |
|
|
|
|
print(' double %s;' % (channel.name)) |
|
|
|
|
elif channel.size == 32: |
|
|
|
|
print ' float %s;' % (channel.name) |
|
|
|
|
print(' float %s;' % (channel.name)) |
|
|
|
|
else: |
|
|
|
|
print ' unsigned %s:%u;' % (channel.name, channel.size) |
|
|
|
|
print(' unsigned %s:%u;' % (channel.name, channel.size)) |
|
|
|
|
else: |
|
|
|
|
assert 0 |
|
|
|
|
|
|
|
|
@ -89,41 +90,41 @@ def generate_format_type(format): |
|
|
|
|
assert channel.size % 8 == 0 and is_pot(channel.size) |
|
|
|
|
if channel.type == VOID: |
|
|
|
|
if channel.size: |
|
|
|
|
print ' uint%u_t %s;' % (channel.size, channel.name) |
|
|
|
|
print(' uint%u_t %s;' % (channel.size, channel.name)) |
|
|
|
|
elif channel.type == UNSIGNED: |
|
|
|
|
print ' uint%u_t %s;' % (channel.size, channel.name) |
|
|
|
|
print(' uint%u_t %s;' % (channel.size, channel.name)) |
|
|
|
|
elif channel.type in (SIGNED, FIXED): |
|
|
|
|
print ' int%u_t %s;' % (channel.size, channel.name) |
|
|
|
|
print(' int%u_t %s;' % (channel.size, channel.name)) |
|
|
|
|
elif channel.type == FLOAT: |
|
|
|
|
if channel.size == 64: |
|
|
|
|
print ' double %s;' % (channel.name) |
|
|
|
|
print(' double %s;' % (channel.name)) |
|
|
|
|
elif channel.size == 32: |
|
|
|
|
print ' float %s;' % (channel.name) |
|
|
|
|
print(' float %s;' % (channel.name)) |
|
|
|
|
elif channel.size == 16: |
|
|
|
|
print ' uint16_t %s;' % (channel.name) |
|
|
|
|
print(' uint16_t %s;' % (channel.name)) |
|
|
|
|
else: |
|
|
|
|
assert 0 |
|
|
|
|
else: |
|
|
|
|
assert 0 |
|
|
|
|
|
|
|
|
|
print 'union util_format_%s {' % format.short_name() |
|
|
|
|
print('union util_format_%s {' % format.short_name()) |
|
|
|
|
|
|
|
|
|
if format.block_size() in (8, 16, 32, 64): |
|
|
|
|
print ' uint%u_t value;' % (format.block_size(),) |
|
|
|
|
print(' uint%u_t value;' % (format.block_size(),)) |
|
|
|
|
|
|
|
|
|
use_bitfields = False |
|
|
|
|
for channel in format.le_channels: |
|
|
|
|
if channel.size % 8 or not is_pot(channel.size): |
|
|
|
|
use_bitfields = True |
|
|
|
|
|
|
|
|
|
print ' struct {' |
|
|
|
|
print(' struct {') |
|
|
|
|
if use_bitfields: |
|
|
|
|
print_channels(format, generate_bitfields) |
|
|
|
|
else: |
|
|
|
|
print_channels(format, generate_full_fields) |
|
|
|
|
print ' } chan;' |
|
|
|
|
print '};' |
|
|
|
|
print |
|
|
|
|
print(' } chan;') |
|
|
|
|
print('};') |
|
|
|
|
print() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def is_format_supported(format): |
|
|
|
@ -445,15 +446,15 @@ def generate_unpack_kernel(format, dst_channel, dst_native_type): |
|
|
|
|
|
|
|
|
|
def unpack_from_bitmask(channels, swizzles): |
|
|
|
|
depth = format.block_size() |
|
|
|
|
print ' uint%u_t value = *(const uint%u_t *)src;' % (depth, depth) |
|
|
|
|
print(' uint%u_t value = *(const uint%u_t *)src;' % (depth, depth)) |
|
|
|
|
|
|
|
|
|
# Declare the intermediate variables |
|
|
|
|
for i in range(format.nr_channels()): |
|
|
|
|
src_channel = channels[i] |
|
|
|
|
if src_channel.type == UNSIGNED: |
|
|
|
|
print ' uint%u_t %s;' % (depth, src_channel.name) |
|
|
|
|
print(' uint%u_t %s;' % (depth, src_channel.name)) |
|
|
|
|
elif src_channel.type == SIGNED: |
|
|
|
|
print ' int%u_t %s;' % (depth, src_channel.name) |
|
|
|
|
print(' int%u_t %s;' % (depth, src_channel.name)) |
|
|
|
|
|
|
|
|
|
# Compute the intermediate unshifted values |
|
|
|
|
for i in range(format.nr_channels()): |
|
|
|
@ -480,7 +481,7 @@ def generate_unpack_kernel(format, dst_channel, dst_native_type): |
|
|
|
|
value = None |
|
|
|
|
|
|
|
|
|
if value is not None: |
|
|
|
|
print ' %s = %s;' % (src_channel.name, value) |
|
|
|
|
print(' %s = %s;' % (src_channel.name, value)) |
|
|
|
|
|
|
|
|
|
# Convert, swizzle, and store final values |
|
|
|
|
for i in range(4): |
|
|
|
@ -504,11 +505,11 @@ def generate_unpack_kernel(format, dst_channel, dst_native_type): |
|
|
|
|
value = '0' |
|
|
|
|
else: |
|
|
|
|
assert False |
|
|
|
|
print ' dst[%u] = %s; /* %s */' % (i, value, 'rgba'[i]) |
|
|
|
|
print(' dst[%u] = %s; /* %s */' % (i, value, 'rgba'[i])) |
|
|
|
|
|
|
|
|
|
def unpack_from_union(channels, swizzles): |
|
|
|
|
print ' union util_format_%s pixel;' % format.short_name() |
|
|
|
|
print ' memcpy(&pixel, src, sizeof pixel);' |
|
|
|
|
print(' union util_format_%s pixel;' % format.short_name()) |
|
|
|
|
print(' memcpy(&pixel, src, sizeof pixel);') |
|
|
|
|
|
|
|
|
|
for i in range(4): |
|
|
|
|
swizzle = swizzles[i] |
|
|
|
@ -531,7 +532,7 @@ def generate_unpack_kernel(format, dst_channel, dst_native_type): |
|
|
|
|
value = '0' |
|
|
|
|
else: |
|
|
|
|
assert False |
|
|
|
|
print ' dst[%u] = %s; /* %s */' % (i, value, 'rgba'[i]) |
|
|
|
|
print(' dst[%u] = %s; /* %s */' % (i, value, 'rgba'[i])) |
|
|
|
|
|
|
|
|
|
if format.is_bitmask(): |
|
|
|
|
print_channels(format, unpack_from_bitmask) |
|
|
|
@ -552,7 +553,7 @@ def generate_pack_kernel(format, src_channel, src_native_type): |
|
|
|
|
inv_swizzle = inv_swizzles(swizzles) |
|
|
|
|
|
|
|
|
|
depth = format.block_size() |
|
|
|
|
print ' uint%u_t value = 0;' % depth |
|
|
|
|
print(' uint%u_t value = 0;' % depth) |
|
|
|
|
|
|
|
|
|
for i in range(4): |
|
|
|
|
dst_channel = channels[i] |
|
|
|
@ -578,14 +579,14 @@ def generate_pack_kernel(format, src_channel, src_native_type): |
|
|
|
|
else: |
|
|
|
|
value = None |
|
|
|
|
if value is not None: |
|
|
|
|
print ' value |= %s;' % (value) |
|
|
|
|
print(' value |= %s;' % (value)) |
|
|
|
|
|
|
|
|
|
print ' *(uint%u_t *)dst = value;' % depth |
|
|
|
|
print(' *(uint%u_t *)dst = value;' % depth) |
|
|
|
|
|
|
|
|
|
def pack_into_union(channels, swizzles): |
|
|
|
|
inv_swizzle = inv_swizzles(swizzles) |
|
|
|
|
|
|
|
|
|
print ' union util_format_%s pixel;' % format.short_name() |
|
|
|
|
print(' union util_format_%s pixel;' % format.short_name()) |
|
|
|
|
|
|
|
|
|
for i in range(4): |
|
|
|
|
dst_channel = channels[i] |
|
|
|
@ -601,9 +602,9 @@ def generate_pack_kernel(format, src_channel, src_native_type): |
|
|
|
|
dst_channel, dst_native_type, |
|
|
|
|
value, |
|
|
|
|
dst_colorspace = dst_colorspace) |
|
|
|
|
print ' pixel.chan.%s = %s;' % (dst_channel.name, value) |
|
|
|
|
print(' pixel.chan.%s = %s;' % (dst_channel.name, value)) |
|
|
|
|
|
|
|
|
|
print ' memcpy(dst, &pixel, sizeof pixel);' |
|
|
|
|
print(' memcpy(dst, &pixel, sizeof pixel);') |
|
|
|
|
|
|
|
|
|
if format.is_bitmask(): |
|
|
|
|
print_channels(format, pack_into_bitmask) |
|
|
|
@ -616,28 +617,28 @@ def generate_format_unpack(format, dst_channel, dst_native_type, dst_suffix): |
|
|
|
|
|
|
|
|
|
name = format.short_name() |
|
|
|
|
|
|
|
|
|
print 'static inline void' |
|
|
|
|
print 'util_format_%s_unpack_%s(%s *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)' % (name, dst_suffix, dst_native_type) |
|
|
|
|
print '{' |
|
|
|
|
print('static inline void') |
|
|
|
|
print('util_format_%s_unpack_%s(%s *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)' % (name, dst_suffix, dst_native_type)) |
|
|
|
|
print('{') |
|
|
|
|
|
|
|
|
|
if is_format_supported(format): |
|
|
|
|
print ' unsigned x, y;' |
|
|
|
|
print ' for(y = 0; y < height; y += %u) {' % (format.block_height,) |
|
|
|
|
print ' %s *dst = dst_row;' % (dst_native_type) |
|
|
|
|
print ' const uint8_t *src = src_row;' |
|
|
|
|
print ' for(x = 0; x < width; x += %u) {' % (format.block_width,) |
|
|
|
|
print(' unsigned x, y;') |
|
|
|
|
print(' for(y = 0; y < height; y += %u) {' % (format.block_height,)) |
|
|
|
|
print(' %s *dst = dst_row;' % (dst_native_type)) |
|
|
|
|
print(' const uint8_t *src = src_row;') |
|
|
|
|
print(' for(x = 0; x < width; x += %u) {' % (format.block_width,)) |
|
|
|
|
|
|
|
|
|
generate_unpack_kernel(format, dst_channel, dst_native_type) |
|
|
|
|
|
|
|
|
|
print ' src += %u;' % (format.block_size() / 8,) |
|
|
|
|
print ' dst += 4;' |
|
|
|
|
print ' }' |
|
|
|
|
print ' src_row += src_stride;' |
|
|
|
|
print ' dst_row += dst_stride/sizeof(*dst_row);' |
|
|
|
|
print ' }' |
|
|
|
|
print(' src += %u;' % (format.block_size() / 8,)) |
|
|
|
|
print(' dst += 4;') |
|
|
|
|
print(' }') |
|
|
|
|
print(' src_row += src_stride;') |
|
|
|
|
print(' dst_row += dst_stride/sizeof(*dst_row);') |
|
|
|
|
print(' }') |
|
|
|
|
|
|
|
|
|
print '}' |
|
|
|
|
print |
|
|
|
|
print('}') |
|
|
|
|
print() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def generate_format_pack(format, src_channel, src_native_type, src_suffix): |
|
|
|
@ -645,28 +646,28 @@ def generate_format_pack(format, src_channel, src_native_type, src_suffix): |
|
|
|
|
|
|
|
|
|
name = format.short_name() |
|
|
|
|
|
|
|
|
|
print 'static inline void' |
|
|
|
|
print 'util_format_%s_pack_%s(uint8_t *dst_row, unsigned dst_stride, const %s *src_row, unsigned src_stride, unsigned width, unsigned height)' % (name, src_suffix, src_native_type) |
|
|
|
|
print '{' |
|
|
|
|
print('static inline void') |
|
|
|
|
print('util_format_%s_pack_%s(uint8_t *dst_row, unsigned dst_stride, const %s *src_row, unsigned src_stride, unsigned width, unsigned height)' % (name, src_suffix, src_native_type)) |
|
|
|
|
print('{') |
|
|
|
|
|
|
|
|
|
if is_format_supported(format): |
|
|
|
|
print ' unsigned x, y;' |
|
|
|
|
print ' for(y = 0; y < height; y += %u) {' % (format.block_height,) |
|
|
|
|
print ' const %s *src = src_row;' % (src_native_type) |
|
|
|
|
print ' uint8_t *dst = dst_row;' |
|
|
|
|
print ' for(x = 0; x < width; x += %u) {' % (format.block_width,) |
|
|
|
|
print(' unsigned x, y;') |
|
|
|
|
print(' for(y = 0; y < height; y += %u) {' % (format.block_height,)) |
|
|
|
|
print(' const %s *src = src_row;' % (src_native_type)) |
|
|
|
|
print(' uint8_t *dst = dst_row;') |
|
|
|
|
print(' for(x = 0; x < width; x += %u) {' % (format.block_width,)) |
|
|
|
|
|
|
|
|
|
generate_pack_kernel(format, src_channel, src_native_type) |
|
|
|
|
|
|
|
|
|
print ' src += 4;' |
|
|
|
|
print ' dst += %u;' % (format.block_size() / 8,) |
|
|
|
|
print ' }' |
|
|
|
|
print ' dst_row += dst_stride;' |
|
|
|
|
print ' src_row += src_stride/sizeof(*src_row);' |
|
|
|
|
print ' }' |
|
|
|
|
print(' src += 4;') |
|
|
|
|
print(' dst += %u;' % (format.block_size() / 8,)) |
|
|
|
|
print(' }') |
|
|
|
|
print(' dst_row += dst_stride;') |
|
|
|
|
print(' src_row += src_stride/sizeof(*src_row);') |
|
|
|
|
print(' }') |
|
|
|
|
|
|
|
|
|
print '}' |
|
|
|
|
print |
|
|
|
|
print('}') |
|
|
|
|
print() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def generate_format_fetch(format, dst_channel, dst_native_type, dst_suffix): |
|
|
|
@ -674,15 +675,15 @@ def generate_format_fetch(format, dst_channel, dst_native_type, dst_suffix): |
|
|
|
|
|
|
|
|
|
name = format.short_name() |
|
|
|
|
|
|
|
|
|
print 'static inline void' |
|
|
|
|
print 'util_format_%s_fetch_%s(%s *dst, const uint8_t *src, unsigned i, unsigned j)' % (name, dst_suffix, dst_native_type) |
|
|
|
|
print '{' |
|
|
|
|
print('static inline void') |
|
|
|
|
print('util_format_%s_fetch_%s(%s *dst, const uint8_t *src, unsigned i, unsigned j)' % (name, dst_suffix, dst_native_type)) |
|
|
|
|
print('{') |
|
|
|
|
|
|
|
|
|
if is_format_supported(format): |
|
|
|
|
generate_unpack_kernel(format, dst_channel, dst_native_type) |
|
|
|
|
|
|
|
|
|
print '}' |
|
|
|
|
print |
|
|
|
|
print('}') |
|
|
|
|
print() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def is_format_hand_written(format): |
|
|
|
@ -690,10 +691,10 @@ def is_format_hand_written(format): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def generate(formats): |
|
|
|
|
print |
|
|
|
|
print '#include "pipe/p_compiler.h"' |
|
|
|
|
print '#include "u_math.h"' |
|
|
|
|
print '#include "u_half.h"' |
|
|
|
|
print '#include "u_format.h"' |
|
|
|
|
print |
|
|
|
|
print() |
|
|
|
|
print('#include "pipe/p_compiler.h"') |
|
|
|
|
print('#include "u_math.h"') |
|
|
|
|
print('#include "u_half.h"') |
|
|
|
|
print('#include "u_format.h"') |
|
|
|
|
print() |
|
|
|
|
|
|
|
|
|