diff options
Diffstat (limited to 'src/gallium/auxiliary')
-rw-r--r-- | src/gallium/auxiliary/Makefile | 8 | ||||
-rw-r--r-- | src/gallium/auxiliary/SConscript | 9 | ||||
-rw-r--r-- | src/gallium/auxiliary/gallivm/lp_bld_format_aos.c | 383 | ||||
-rw-r--r-- | src/gallium/auxiliary/gallivm/lp_bld_format_query.c | 72 | ||||
-rw-r--r-- | src/gallium/auxiliary/gallivm/lp_bld_format_soa.c | 6 | ||||
-rw-r--r-- | src/gallium/auxiliary/gallivm/lp_bld_printf.c | 6 | ||||
-rw-r--r-- | src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c | 2 | ||||
-rw-r--r-- | src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c | 12 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/.gitignore | 1 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_format.h | 45 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_format_access.py | 6 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_format_pack.py | 401 | ||||
-rwxr-xr-x | src/gallium/auxiliary/util/u_format_table.py | 36 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_format_tests.c | 11 |
14 files changed, 275 insertions, 723 deletions
diff --git a/src/gallium/auxiliary/Makefile b/src/gallium/auxiliary/Makefile index 452eceb7f4f..903c5a331ce 100644 --- a/src/gallium/auxiliary/Makefile +++ b/src/gallium/auxiliary/Makefile @@ -148,8 +148,6 @@ GALLIVM_SOURCES = \ gallivm/lp_bld_debug.c \ gallivm/lp_bld_depth.c \ gallivm/lp_bld_flow.c \ - gallivm/lp_bld_format_aos.c \ - gallivm/lp_bld_format_query.c \ gallivm/lp_bld_format_soa.c \ gallivm/lp_bld_interp.c \ gallivm/lp_bld_intr.c \ @@ -170,7 +168,6 @@ GENERATED_SOURCES = \ indices/u_indices_gen.c \ indices/u_unfilled_gen.c \ util/u_format_access.c \ - util/u_format_pack.h \ util/u_format_table.c @@ -194,12 +191,9 @@ indices/u_indices_gen.c: indices/u_indices_gen.py indices/u_unfilled_gen.c: indices/u_unfilled_gen.py python $< > $@ -util/u_format_table.c: util/u_format_table.py util/u_format_parse.py util/u_format.csv +util/u_format_table.c: util/u_format_table.py util/u_format_pack.py util/u_format_parse.py util/u_format.csv python util/u_format_table.py util/u_format.csv > $@ -util/u_format_pack.h: util/u_format_pack.py util/u_format_parse.py util/u_format.csv - python util/u_format_pack.py util/u_format.csv > $@ - util/u_format_access.c: util/u_format_access.py util/u_format_parse.py util/u_format.csv python util/u_format_access.py util/u_format.csv > $@ diff --git a/src/gallium/auxiliary/SConscript b/src/gallium/auxiliary/SConscript index 0a23da47b2a..772ab415235 100644 --- a/src/gallium/auxiliary/SConscript +++ b/src/gallium/auxiliary/SConscript @@ -31,13 +31,6 @@ env.CodeGenerate( ) env.CodeGenerate( - target = File('util/u_format_pack.h').srcnode(), - script = 'util/u_format_pack.py', - source = ['util/u_format.csv'], - command = 'python $SCRIPT $SOURCE > $TARGET' -) - -env.CodeGenerate( target = 'util/u_format_access.c', script = 'util/u_format_access.py', source = ['util/u_format.csv'], @@ -192,8 +185,6 @@ if drawllvm: 'gallivm/lp_bld_debug.c', 'gallivm/lp_bld_depth.c', 'gallivm/lp_bld_flow.c', - 'gallivm/lp_bld_format_aos.c', - 'gallivm/lp_bld_format_query.c', 'gallivm/lp_bld_format_soa.c', 'gallivm/lp_bld_interp.c', 'gallivm/lp_bld_intr.c', diff --git a/src/gallium/auxiliary/gallivm/lp_bld_format_aos.c b/src/gallium/auxiliary/gallivm/lp_bld_format_aos.c deleted file mode 100644 index a07f7418f2c..00000000000 --- a/src/gallium/auxiliary/gallivm/lp_bld_format_aos.c +++ /dev/null @@ -1,383 +0,0 @@ -/************************************************************************** - * - * Copyright 2009 VMware, 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 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 NON-INFRINGEMENT. - * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -/** - * @file - * AoS pixel format manipulation. - * - * @author Jose Fonseca <[email protected]> - */ - - -#include "util/u_cpu_detect.h" -#include "util/u_format.h" - -#include "lp_bld_type.h" -#include "lp_bld_const.h" -#include "lp_bld_swizzle.h" -#include "lp_bld_format.h" - - -/** - * Unpack a single pixel into its RGBA components. - * - * @param packed integer. - * - * @return RGBA in a 4 floats vector. - * - * XXX: This is mostly for reference and testing -- operating a single pixel at - * a time is rarely if ever needed. - */ -LLVMValueRef -lp_build_unpack_rgba_aos(LLVMBuilderRef builder, - const struct util_format_description *desc, - LLVMValueRef packed) -{ - LLVMTypeRef type; - LLVMValueRef shifted, casted, scaled, masked; - LLVMValueRef shifts[4]; - LLVMValueRef masks[4]; - LLVMValueRef scales[4]; - LLVMValueRef swizzles[4]; - LLVMValueRef aux[4]; - bool normalized; - int empty_channel; - unsigned shift; - unsigned i; - - /* FIXME: Support more formats */ - assert(desc->layout == UTIL_FORMAT_LAYOUT_PLAIN); - assert(desc->block.width == 1); - assert(desc->block.height == 1); - assert(desc->block.bits <= 32); - - type = LLVMIntType(desc->block.bits); - - /* Do the intermediate integer computations with 32bit integers since it - * matches floating point size */ - if (desc->block.bits < 32) - packed = LLVMBuildZExt(builder, packed, LLVMInt32Type(), ""); - - /* Broadcast the packed value to all four channels */ - packed = LLVMBuildInsertElement(builder, - LLVMGetUndef(LLVMVectorType(LLVMInt32Type(), 4)), - packed, - LLVMConstNull(LLVMInt32Type()), - ""); - packed = LLVMBuildShuffleVector(builder, - packed, - LLVMGetUndef(LLVMVectorType(LLVMInt32Type(), 4)), - LLVMConstNull(LLVMVectorType(LLVMInt32Type(), 4)), - ""); - - /* Initialize vector constants */ - normalized = FALSE; - empty_channel = -1; - shift = 0; - for (i = 0; i < 4; ++i) { - unsigned bits = desc->channel[i].size; - - if (desc->channel[i].type == UTIL_FORMAT_TYPE_VOID) { - shifts[i] = LLVMGetUndef(LLVMInt32Type()); - masks[i] = LLVMConstNull(LLVMInt32Type()); - scales[i] = LLVMConstNull(LLVMFloatType()); - empty_channel = i; - } - else { - unsigned mask = (1 << bits) - 1; - - assert(desc->channel[i].type == UTIL_FORMAT_TYPE_UNSIGNED); - assert(bits < 32); - - shifts[i] = LLVMConstInt(LLVMInt32Type(), shift, 0); - masks[i] = LLVMConstInt(LLVMInt32Type(), mask, 0); - - if (desc->channel[i].normalized) { - scales[i] = LLVMConstReal(LLVMFloatType(), 1.0/mask); - normalized = TRUE; - } - else - scales[i] = LLVMConstReal(LLVMFloatType(), 1.0); - } - - shift += bits; - } - - shifted = LLVMBuildLShr(builder, packed, LLVMConstVector(shifts, 4), ""); - masked = LLVMBuildAnd(builder, shifted, LLVMConstVector(masks, 4), ""); - /* UIToFP can't be expressed in SSE2 */ - casted = LLVMBuildSIToFP(builder, masked, LLVMVectorType(LLVMFloatType(), 4), ""); - - if (normalized) - scaled = LLVMBuildMul(builder, casted, LLVMConstVector(scales, 4), ""); - else - scaled = casted; - - for (i = 0; i < 4; ++i) - aux[i] = LLVMGetUndef(LLVMFloatType()); - - for (i = 0; i < 4; ++i) { - enum util_format_swizzle swizzle = desc->swizzle[i]; - - switch (swizzle) { - case UTIL_FORMAT_SWIZZLE_X: - case UTIL_FORMAT_SWIZZLE_Y: - case UTIL_FORMAT_SWIZZLE_Z: - case UTIL_FORMAT_SWIZZLE_W: - swizzles[i] = LLVMConstInt(LLVMInt32Type(), swizzle, 0); - break; - case UTIL_FORMAT_SWIZZLE_0: - assert(empty_channel >= 0); - swizzles[i] = LLVMConstInt(LLVMInt32Type(), empty_channel, 0); - break; - case UTIL_FORMAT_SWIZZLE_1: - swizzles[i] = LLVMConstInt(LLVMInt32Type(), 4, 0); - aux[0] = LLVMConstReal(LLVMFloatType(), 1.0); - break; - case UTIL_FORMAT_SWIZZLE_NONE: - swizzles[i] = LLVMGetUndef(LLVMFloatType()); - assert(0); - break; - } - } - - return LLVMBuildShuffleVector(builder, scaled, LLVMConstVector(aux, 4), LLVMConstVector(swizzles, 4), ""); -} - - -/** - * Take a vector with packed pixels and unpack into a rgba8 vector. - * - * Formats with bit depth smaller than 32bits are accepted, but they must be - * padded to 32bits. - */ -LLVMValueRef -lp_build_unpack_rgba8_aos(LLVMBuilderRef builder, - const struct util_format_description *desc, - struct lp_type type, - LLVMValueRef packed) -{ - struct lp_build_context bld; - bool rgba8; - LLVMValueRef res; - unsigned i; - - lp_build_context_init(&bld, builder, type); - - /* FIXME: Support more formats */ - assert(desc->layout == UTIL_FORMAT_LAYOUT_PLAIN); - assert(desc->block.width == 1); - assert(desc->block.height == 1); - assert(desc->block.bits <= 32); - - assert(!type.floating); - assert(!type.fixed); - assert(type.norm); - assert(type.width == 8); - assert(type.length % 4 == 0); - - rgba8 = TRUE; - for(i = 0; i < 4; ++i) { - assert(desc->channel[i].type == UTIL_FORMAT_TYPE_UNSIGNED || - desc->channel[i].type == UTIL_FORMAT_TYPE_VOID); - if(desc->channel[0].size != 8) - rgba8 = FALSE; - } - - if(rgba8) { - /* - * The pixel is already in a rgba8 format variant. All it is necessary - * is to swizzle the channels. - */ - - unsigned char swizzles[4]; - boolean zeros[4]; /* bitwise AND mask */ - boolean ones[4]; /* bitwise OR mask */ - boolean swizzles_needed = FALSE; - boolean zeros_needed = FALSE; - boolean ones_needed = FALSE; - - for(i = 0; i < 4; ++i) { - enum util_format_swizzle swizzle = desc->swizzle[i]; - - /* Initialize with the no-op case */ - swizzles[i] = util_cpu_caps.little_endian ? 3 - i : i; - zeros[i] = TRUE; - ones[i] = FALSE; - - switch (swizzle) { - case UTIL_FORMAT_SWIZZLE_X: - case UTIL_FORMAT_SWIZZLE_Y: - case UTIL_FORMAT_SWIZZLE_Z: - case UTIL_FORMAT_SWIZZLE_W: - if(swizzle != swizzles[i]) { - swizzles[i] = swizzle; - swizzles_needed = TRUE; - } - break; - case UTIL_FORMAT_SWIZZLE_0: - zeros[i] = FALSE; - zeros_needed = TRUE; - break; - case UTIL_FORMAT_SWIZZLE_1: - ones[i] = TRUE; - ones_needed = TRUE; - break; - case UTIL_FORMAT_SWIZZLE_NONE: - assert(0); - break; - } - } - - res = packed; - - if(swizzles_needed) - res = lp_build_swizzle1_aos(&bld, res, swizzles); - - if(zeros_needed) { - /* Mask out zero channels */ - LLVMValueRef mask = lp_build_const_mask_aos(type, zeros); - res = LLVMBuildAnd(builder, res, mask, ""); - } - - if(ones_needed) { - /* Or one channels */ - LLVMValueRef mask = lp_build_const_mask_aos(type, ones); - res = LLVMBuildOr(builder, res, mask, ""); - } - } - else { - /* FIXME */ - assert(0); - res = lp_build_undef(type); - } - - return res; -} - - -/** - * Pack a single pixel. - * - * @param rgba 4 float vector with the unpacked components. - * - * XXX: This is mostly for reference and testing -- operating a single pixel at - * a time is rarely if ever needed. - */ -LLVMValueRef -lp_build_pack_rgba_aos(LLVMBuilderRef builder, - const struct util_format_description *desc, - LLVMValueRef rgba) -{ - LLVMTypeRef type; - LLVMValueRef packed = NULL; - LLVMValueRef swizzles[4]; - LLVMValueRef shifted, casted, scaled, unswizzled; - LLVMValueRef shifts[4]; - LLVMValueRef scales[4]; - bool normalized; - unsigned shift; - unsigned i, j; - - assert(desc->layout == UTIL_FORMAT_LAYOUT_PLAIN); - assert(desc->block.width == 1); - assert(desc->block.height == 1); - - type = LLVMIntType(desc->block.bits); - - /* Unswizzle the color components into the source vector. */ - for (i = 0; i < 4; ++i) { - for (j = 0; j < 4; ++j) { - if (desc->swizzle[j] == i) - break; - } - if (j < 4) - swizzles[i] = LLVMConstInt(LLVMInt32Type(), j, 0); - else - swizzles[i] = LLVMGetUndef(LLVMInt32Type()); - } - - unswizzled = LLVMBuildShuffleVector(builder, rgba, - LLVMGetUndef(LLVMVectorType(LLVMFloatType(), 4)), - LLVMConstVector(swizzles, 4), ""); - - normalized = FALSE; - shift = 0; - for (i = 0; i < 4; ++i) { - unsigned bits = desc->channel[i].size; - - if (desc->channel[i].type == UTIL_FORMAT_TYPE_VOID) { - shifts[i] = LLVMGetUndef(LLVMInt32Type()); - scales[i] = LLVMGetUndef(LLVMFloatType()); - } - else { - unsigned mask = (1 << bits) - 1; - - assert(desc->channel[i].type == UTIL_FORMAT_TYPE_UNSIGNED); - assert(bits < 32); - - shifts[i] = LLVMConstInt(LLVMInt32Type(), shift, 0); - - if (desc->channel[i].normalized) { - scales[i] = LLVMConstReal(LLVMFloatType(), mask); - normalized = TRUE; - } - else - scales[i] = LLVMConstReal(LLVMFloatType(), 1.0); - } - - shift += bits; - } - - if (normalized) - scaled = LLVMBuildMul(builder, unswizzled, LLVMConstVector(scales, 4), ""); - else - scaled = unswizzled; - - casted = LLVMBuildFPToSI(builder, scaled, LLVMVectorType(LLVMInt32Type(), 4), ""); - - shifted = LLVMBuildShl(builder, casted, LLVMConstVector(shifts, 4), ""); - - /* Bitwise or all components */ - for (i = 0; i < 4; ++i) { - if (desc->channel[i].type == UTIL_FORMAT_TYPE_UNSIGNED) { - LLVMValueRef component = LLVMBuildExtractElement(builder, shifted, LLVMConstInt(LLVMInt32Type(), i, 0), ""); - if (packed) - packed = LLVMBuildOr(builder, packed, component, ""); - else - packed = component; - } - } - - if (!packed) - packed = LLVMGetUndef(LLVMInt32Type()); - - if (desc->block.bits < 32) - packed = LLVMBuildTrunc(builder, packed, type, ""); - - return packed; -} diff --git a/src/gallium/auxiliary/gallivm/lp_bld_format_query.c b/src/gallium/auxiliary/gallivm/lp_bld_format_query.c deleted file mode 100644 index f3832d07ff9..00000000000 --- a/src/gallium/auxiliary/gallivm/lp_bld_format_query.c +++ /dev/null @@ -1,72 +0,0 @@ -/************************************************************************** - * - * Copyright 2009 VMware, 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 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 NON-INFRINGEMENT. - * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -/** - * @file - * Utility functions to make assertions about formats. - * - * This module centralizes most of logic used when determining what algorithm - * is most suitable (i.e., most efficient yet correct) for a given format. - * - * It might be possible to move some of these functions to u_format module, - * but since tiny differences in the format my render it more/less - * appropriate to a given algorithm it is impossible to make any long term - * guarantee about the semantics of these functions. - * - * @author Jose Fonseca <[email protected]> - */ - - -#include "util/u_format.h" - -#include "lp_bld_format.h" - - -/** - * Whether this format is a 4 rgba8 variant - */ -boolean -lp_format_is_rgba8(const struct util_format_description *desc) -{ - unsigned chan; - - if(desc->block.width != 1 || - desc->block.height != 1 || - desc->block.bits != 32) - return FALSE; - - for(chan = 0; chan < 4; ++chan) { - if(desc->channel[chan].type != UTIL_FORMAT_TYPE_UNSIGNED && - desc->channel[chan].type != UTIL_FORMAT_TYPE_SIGNED && - desc->channel[chan].type != UTIL_FORMAT_TYPE_VOID) - return FALSE; - if(desc->channel[chan].size != 8) - return FALSE; - } - - return TRUE; -} diff --git a/src/gallium/auxiliary/gallivm/lp_bld_format_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_format_soa.c index 45ee4b12ced..c9fbe0ad10c 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_format_soa.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_format_soa.c @@ -92,14 +92,14 @@ lp_build_unpack_rgba_soa(LLVMBuilderRef builder, unsigned chan; /* FIXME: Support more formats */ - assert(format_desc->layout == UTIL_FORMAT_LAYOUT_PLAIN); + assert(format_desc->is_bitmask); assert(format_desc->block.width == 1); assert(format_desc->block.height == 1); assert(format_desc->block.bits <= 32); /* Decode the input vector components */ start = 0; - for (chan = 0; chan < 4; ++chan) { + for (chan = 0; chan < format_desc->nr_channels; ++chan) { unsigned width = format_desc->channel[chan].size; unsigned stop = start + width; LLVMValueRef input; @@ -123,7 +123,7 @@ lp_build_unpack_rgba_soa(LLVMBuilderRef builder, if(format_desc->channel[chan].normalized) input = lp_build_unsigned_norm_to_float(builder, width, type, input); else - input = LLVMBuildFPToSI(builder, input, lp_build_vec_type(type), ""); + input = LLVMBuildSIToFP(builder, input, lp_build_vec_type(type), ""); } else { /* FIXME */ diff --git a/src/gallium/auxiliary/gallivm/lp_bld_printf.c b/src/gallium/auxiliary/gallivm/lp_bld_printf.c index ae4d400af39..78c9ec778b6 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_printf.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_printf.c @@ -27,6 +27,8 @@ #include <stdio.h> +#include "util/u_debug.h" +#include "util/u_memory.h" #include "lp_bld_printf.h" @@ -84,12 +86,14 @@ lp_build_printf(LLVMBuilderRef builder, const char *fmt, ...) int i = 0; int argcount = lp_get_printf_arg_count(fmt); LLVMModuleRef module = LLVMGetGlobalParent(LLVMGetBasicBlockParent(LLVMGetInsertBlock(builder))); - LLVMValueRef params[argcount + 1]; + LLVMValueRef params[50]; LLVMValueRef fmtarg = lp_build_const_string_variable(module, fmt, strlen(fmt) + 1); LLVMValueRef int0 = LLVMConstInt(LLVMInt32Type(), 0, 0); LLVMValueRef index[2]; LLVMValueRef func_printf = LLVMGetNamedFunction(module, "printf"); + assert(Elements(params) >= argcount + 1); + index[0] = index[1] = int0; if (!func_printf) { diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c index 995c016b9dd..5b56f2cf3b7 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c @@ -2037,7 +2037,7 @@ lp_build_sample_soa(LLVMBuilderRef builder, height_vec = lp_build_broadcast_scalar(&bld.uint_coord_bld, height); depth_vec = lp_build_broadcast_scalar(&bld.uint_coord_bld, depth); - if (lp_format_is_rgba8(bld.format_desc) && + if (util_format_is_rgba8_variant(bld.format_desc) && static_state->target == PIPE_TEXTURE_2D && static_state->min_img_filter == PIPE_TEX_FILTER_LINEAR && static_state->mag_img_filter == PIPE_TEX_FILTER_LINEAR && diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c index 95cd6a0ecf3..8901e656aed 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c @@ -666,30 +666,20 @@ emit_declaration( first_inst); for (idx = first; idx <= last; ++idx) { - boolean ok; - switch (decl->Declaration.File) { case TGSI_FILE_TEMPORARY: for (i = 0; i < NUM_CHANNELS; i++) bld->temps[idx][i] = lp_build_alloca(&bld->base); - ok = TRUE; break; case TGSI_FILE_OUTPUT: for (i = 0; i < NUM_CHANNELS; i++) bld->outputs[idx][i] = lp_build_alloca(&bld->base); - ok = TRUE; break; default: /* don't need to declare other vars */ - ok = TRUE; - } - - if (!ok) { - LLVMPositionBuilderAtEnd(bld->base.builder, - current_block); - return FALSE; + break; } } diff --git a/src/gallium/auxiliary/util/.gitignore b/src/gallium/auxiliary/util/.gitignore index 448d2f304fb..29c586c9b51 100644 --- a/src/gallium/auxiliary/util/.gitignore +++ b/src/gallium/auxiliary/util/.gitignore @@ -1,3 +1,2 @@ u_format_access.c u_format_table.c -u_format_pack.h diff --git a/src/gallium/auxiliary/util/u_format.h b/src/gallium/auxiliary/util/u_format.h index 98d4b98ebb5..609d398ebfc 100644 --- a/src/gallium/auxiliary/util/u_format.h +++ b/src/gallium/auxiliary/util/u_format.h @@ -189,6 +189,23 @@ struct util_format_description * Colorspace transformation. */ enum util_format_colorspace colorspace; + + /** + * Accessor functions. + */ + + void + (*unpack_8unorm)(uint8_t *dst, const uint8_t *src, unsigned nr_blocks); + + void + (*pack_8unorm)(uint8_t *dst, const uint8_t *src, unsigned nr_blocks); + + void + (*unpack_float)(float *dst, const uint8_t *src, unsigned nr_blocks); + + void + (*pack_float)(uint8_t *dst, const float *src, unsigned nr_blocks); + }; @@ -261,6 +278,34 @@ util_format_is_depth_and_stencil(enum pipe_format format) desc->swizzle[1] != UTIL_FORMAT_SWIZZLE_NONE) ? TRUE : FALSE; } +/** + * Whether this format is a rgab8 variant. + * + * That is, any format that matches the + * + * PIPE_FORMAT_?8?8?8?8_UNORM + */ +static INLINE boolean +util_format_is_rgba8_variant(const struct util_format_description *desc) +{ + unsigned chan; + + if(desc->block.width != 1 || + desc->block.height != 1 || + desc->block.bits != 32) + return FALSE; + + for(chan = 0; chan < 4; ++chan) { + if(desc->channel[chan].type != UTIL_FORMAT_TYPE_UNSIGNED && + desc->channel[chan].type != UTIL_FORMAT_TYPE_VOID) + return FALSE; + if(desc->channel[chan].size != 8) + return FALSE; + } + + return TRUE; +} + /** * Return total bits needed for the pixel format per block. diff --git a/src/gallium/auxiliary/util/u_format_access.py b/src/gallium/auxiliary/util/u_format_access.py index 42a37badca7..1c76d9a79da 100644 --- a/src/gallium/auxiliary/util/u_format_access.py +++ b/src/gallium/auxiliary/util/u_format_access.py @@ -81,9 +81,7 @@ def native_type(format): else: # For array pixel formats return the integer type that matches the color channel channel = format.channels[0] - if channel.type == VOID: - channel = format.channels[1] - if channel.type == UNSIGNED: + if channel.type in (UNSIGNED, VOID): return 'uint%u_t' % channel.size elif channel.type == SIGNED: return 'int%u_t' % channel.size @@ -322,7 +320,7 @@ def main(): print print '#include "pipe/p_compiler.h"' print '#include "u_math.h"' - print '#include "u_format_pack.h"' + print '#include "u_format.h"' print generate_srgb_tables() diff --git a/src/gallium/auxiliary/util/u_format_pack.py b/src/gallium/auxiliary/util/u_format_pack.py index 47def90317e..f40b3bdf2ec 100644 --- a/src/gallium/auxiliary/util/u_format_pack.py +++ b/src/gallium/auxiliary/util/u_format_pack.py @@ -132,17 +132,15 @@ def native_type(format): return 'uint%u_t' % format.block_size() else: # For array pixel formats return the integer type that matches the color channel - type = format.channels[0] - if type.type == VOID: - type = format.channels[1] - if type.type == UNSIGNED: - return 'uint%u_t' % type.size - elif type.type == SIGNED: - return 'int%u_t' % type.size - elif type.type == FLOAT: - if type.size == 32: + channel = format.channels[0] + if channel.type in (UNSIGNED, VOID): + return 'uint%u_t' % channel.size + elif channel.type == SIGNED: + return 'int%u_t' % channel.size + elif channel.type == FLOAT: + if channel.size == 32: return 'float' - elif type.size == 64: + elif channel.size == 64: return 'double' else: assert False @@ -314,108 +312,116 @@ def conversion_expr(src_channel, dst_channel, dst_native_type, value, clamp=True def generate_format_unpack(format, dst_channel, dst_native_type, dst_suffix): '''Generate the function to unpack pixels from a particular format''' - assert format.layout == PLAIN - name = format.short_name() - src_native_type = native_type(format) - print 'static INLINE void' - print 'util_format_%s_unpack_%s(%s *dst, const void *src)' % (name, dst_suffix, dst_native_type) + print 'util_format_%s_unpack_%s(%s *dst, const uint8_t *src, unsigned length)' % (name, dst_suffix, dst_native_type) print '{' - - if format.is_bitmask(): - depth = format.block_size() - print ' uint%u_t value = *(uint%u_t *)src;' % (depth, depth) - - # Declare the intermediate variables - for i in range(format.nr_channels()): - src_channel = format.channels[i] - if src_channel.type == UNSIGNED: - print ' uint%u_t %s;' % (depth, src_channel.name) - elif src_channel.type == SIGNED: - print ' int%u_t %s;' % (depth, src_channel.name) - print '#ifdef PIPE_ARCH_BIG_ENDIAN' - print ' value = util_bswap%u(value);' % depth - print '#endif' + if is_format_supported(format): + + assert format.layout == PLAIN + + src_native_type = native_type(format) - # Compute the intermediate unshifted values - shift = 0 - for i in range(format.nr_channels()): - src_channel = format.channels[i] - value = 'value' - if src_channel.type == UNSIGNED: - if shift: - value = '%s >> %u' % (value, shift) - if shift + src_channel.size < depth: - value = '(%s) & 0x%x' % (value, (1 << src_channel.size) - 1) - elif src_channel.type == SIGNED: - if shift + src_channel.size < depth: - # Align the sign bit - lshift = depth - (shift + src_channel.size) - value = '%s << %u' % (value, lshift) - # Cast to signed - value = '(int%u_t)(%s) ' % (depth, value) - if src_channel.size < depth: - # Align the LSB bit - rshift = depth - src_channel.size - value = '(%s) >> %u' % (value, rshift) - else: - value = None - - 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] - if swizzle < 4: - src_channel = format.channels[swizzle] - value = src_channel.name - value = conversion_expr(src_channel, dst_channel, dst_native_type, value) - elif swizzle == SWIZZLE_0: - value = '0' - elif swizzle == SWIZZLE_1: - value = get_one(dst_channel) - elif swizzle == SWIZZLE_NONE: - value = '0' - else: - assert False - if format.colorspace == ZS: - if i == 3: + print ' while(length--) {' + + if format.is_bitmask(): + depth = format.block_size() + print ' uint%u_t value = *(uint%u_t *)src;' % (depth, depth) + + # Declare the intermediate variables + for i in range(format.nr_channels()): + src_channel = format.channels[i] + if src_channel.type == UNSIGNED: + print ' uint%u_t %s;' % (depth, src_channel.name) + elif src_channel.type == SIGNED: + print ' int%u_t %s;' % (depth, src_channel.name) + + 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' + if src_channel.type == UNSIGNED: + if shift: + value = '%s >> %u' % (value, shift) + if shift + src_channel.size < depth: + value = '(%s) & 0x%x' % (value, (1 << src_channel.size) - 1) + elif src_channel.type == SIGNED: + if shift + src_channel.size < depth: + # Align the sign bit + lshift = depth - (shift + src_channel.size) + value = '%s << %u' % (value, lshift) + # Cast to signed + value = '(int%u_t)(%s) ' % (depth, value) + if src_channel.size < depth: + # Align the LSB bit + rshift = depth - src_channel.size + value = '(%s) >> %u' % (value, rshift) + else: + value = None + + 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] + if swizzle < 4: + src_channel = format.channels[swizzle] + value = src_channel.name + value = conversion_expr(src_channel, dst_channel, dst_native_type, value) + elif swizzle == SWIZZLE_0: + value = '0' + elif swizzle == SWIZZLE_1: value = get_one(dst_channel) - elif i >= 1: - value = 'dst[0]' - print ' dst[%u] = %s; /* %s */' % (i, value, 'rgba'[i]) + elif swizzle == SWIZZLE_NONE: + value = '0' + else: + assert False + if format.colorspace == ZS: + if i == 3: + value = get_one(dst_channel) + elif i >= 1: + value = 'dst[0]' + print ' dst[%u] = %s; /* %s */' % (i, value, 'rgba'[i]) + + else: + print ' union util_format_%s pixel;' % format.short_name() + print ' memcpy(&pixel, src, sizeof pixel);' + bswap_format(format) - 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] - if swizzle < 4: - src_channel = format.channels[swizzle] - value = 'pixel.chan.%s' % src_channel.name - value = conversion_expr(src_channel, dst_channel, dst_native_type, value) - elif swizzle == SWIZZLE_0: - value = '0' - elif swizzle == SWIZZLE_1: - value = get_one(dst_channel) - elif swizzle == SWIZZLE_NONE: - value = '0' - else: - assert False - if format.colorspace == ZS: - if i == 3: + for i in range(4): + swizzle = format.swizzles[i] + if swizzle < 4: + src_channel = format.channels[swizzle] + value = 'pixel.chan.%s' % src_channel.name + value = conversion_expr(src_channel, dst_channel, dst_native_type, value) + elif swizzle == SWIZZLE_0: + value = '0' + elif swizzle == SWIZZLE_1: value = get_one(dst_channel) - elif i >= 1: - value = 'dst[0]' - print ' dst[%u] = %s; /* %s */' % (i, value, 'rgba'[i]) + elif swizzle == SWIZZLE_NONE: + value = '0' + else: + assert False + if format.colorspace == ZS: + if i == 3: + value = get_one(dst_channel) + elif i >= 1: + value = 'dst[0]' + print ' dst[%u] = %s; /* %s */' % (i, value, 'rgba'[i]) + + print ' src += %u;' % (format.block_size() / 8,) + print ' dst += 4;' + print ' }' print '}' print @@ -426,72 +432,79 @@ def generate_format_pack(format, src_channel, src_native_type, src_suffix): name = format.short_name() - dst_native_type = native_type(format) - - assert format.layout == PLAIN - - inv_swizzle = format.inv_swizzles() - print 'static INLINE void' - print 'util_format_%s_pack_%s(void *dst, %s r, %s g, %s b, %s a)' % (name, src_suffix, src_native_type, src_native_type, src_native_type, src_native_type) + print 'util_format_%s_pack_%s(uint8_t *dst, const %s *src, unsigned length)' % (name, src_suffix, src_native_type) print '{' - if format.is_bitmask(): - depth = format.block_size() - print ' uint%u_t value = 0;' % depth - - shift = 0 - for i in range(4): - dst_channel = format.channels[i] - if inv_swizzle[i] is not None: - value = 'rgba'[inv_swizzle[i]] + if is_format_supported(format): + dst_native_type = native_type(format) + + assert format.layout == PLAIN + + inv_swizzle = format.inv_swizzles() + + print ' while(length--) {' + + if format.is_bitmask(): + depth = format.block_size() + print ' uint%u_t value = 0;' % depth + + shift = 0 + for i in range(4): + dst_channel = format.channels[i] + if inv_swizzle[i] is not None: + value ='src[%u]' % inv_swizzle[i] + value = conversion_expr(src_channel, dst_channel, dst_native_type, value) + if format.colorspace == ZS: + if i == 3: + value = get_one(dst_channel) + elif i >= 1: + value = '0' + if dst_channel.type in (UNSIGNED, SIGNED): + if shift + dst_channel.size < depth: + value = '(%s) & 0x%x' % (value, (1 << dst_channel.size) - 1) + if shift: + value = '(%s) << %u' % (value, shift) + if dst_channel.type == SIGNED: + # Cast to unsigned + value = '(uint%u_t)(%s) ' % (depth, value) + else: + value = None + if value is not None: + print ' value |= %s;' % (value) + + shift += dst_channel.size + + print '#ifdef PIPE_ARCH_BIG_ENDIAN' + print ' value = util_bswap%u(value);' % depth + print '#endif' + + print ' *(uint%u_t *)dst = value;' % depth + + else: + print ' union util_format_%s pixel;' % format.short_name() + + for i in range(4): + dst_channel = format.channels[i] + width = dst_channel.size + if inv_swizzle[i] is None: + continue + value ='src[%u]' % inv_swizzle[i] value = conversion_expr(src_channel, dst_channel, dst_native_type, value) if format.colorspace == ZS: if i == 3: value = get_one(dst_channel) elif i >= 1: value = '0' - if dst_channel.type in (UNSIGNED, SIGNED): - if shift + dst_channel.size < depth: - value = '(%s) & 0x%x' % (value, (1 << dst_channel.size) - 1) - if shift: - value = '(%s) << %u' % (value, shift) - if dst_channel.type == SIGNED: - # Cast to unsigned - value = '(uint%u_t)(%s) ' % (depth, value) - else: - value = None - if value is not None: - print ' value |= %s;' % (value) - - shift += dst_channel.size - - print '#ifdef PIPE_ARCH_BIG_ENDIAN' - print ' value = util_bswap%u(value);' % depth - print '#endif' + print ' pixel.chan.%s = %s;' % (dst_channel.name, value) - print ' *(uint%u_t *)dst = value;' % depth + bswap_format(format) + print ' memcpy(dst, &pixel, sizeof pixel);' + + print ' src += 4;' + print ' dst += %u;' % (format.block_size() / 8,) + print ' }' - else: - print ' union util_format_%s pixel;' % format.short_name() - - for i in range(4): - dst_channel = format.channels[i] - width = dst_channel.size - if inv_swizzle[i] is None: - continue - value = 'rgba'[inv_swizzle[i]] - value = conversion_expr(src_channel, dst_channel, dst_native_type, value) - if format.colorspace == ZS: - if i == 3: - value = get_one(dst_channel) - elif i >= 1: - value = '0' - print ' pixel.chan.%s = %s;' % (dst_channel.name, value) - - bswap_format(format) - print ' memcpy(dst, &pixel, sizeof pixel);' - print '}' print @@ -500,67 +513,17 @@ def generate_unpack(formats, dst_channel, dst_native_type, dst_suffix): '''Generate the dispatch function to unpack pixels from any format''' for format in formats: - if is_format_supported(format): - generate_format_unpack(format, dst_channel, dst_native_type, dst_suffix) - - print 'static INLINE void' - print 'util_format_unpack_%s(enum pipe_format format, %s *dst, const void *src)' % (dst_suffix, dst_native_type) - print '{' - print ' void (*func)(%s *dst, const void *src);' % dst_native_type - print ' switch(format) {' - for format in formats: - if is_format_supported(format): - print ' case %s:' % format.name - print ' func = &util_format_%s_unpack_%s;' % (format.short_name(), dst_suffix) - print ' break;' - print ' default:' - print ' debug_printf("unsupported format\\n");' - print ' return;' - print ' }' - print ' func(dst, src);' - print '}' - print + generate_format_unpack(format, dst_channel, dst_native_type, dst_suffix) def generate_pack(formats, src_channel, src_native_type, src_suffix): '''Generate the dispatch function to pack pixels to any format''' for format in formats: - if is_format_supported(format): - generate_format_pack(format, src_channel, src_native_type, src_suffix) - - print 'static INLINE void' - print 'util_format_pack_%s(enum pipe_format format, void *dst, %s r, %s g, %s b, %s a)' % (src_suffix, src_native_type, src_native_type, src_native_type, src_native_type) - print '{' - print ' void (*func)(void *dst, %s r, %s g, %s b, %s a);' % (src_native_type, src_native_type, src_native_type, src_native_type) - print ' switch(format) {' - for format in formats: - if is_format_supported(format): - print ' case %s:' % format.name - print ' func = &util_format_%s_pack_%s;' % (format.short_name(), src_suffix) - print ' break;' - print ' default:' - print ' debug_printf("%s: unsupported format\\n", __FUNCTION__);' - print ' return;' - print ' }' - print ' func(dst, r, g, b, a);' - print '}' - print - + generate_format_pack(format, src_channel, src_native_type, src_suffix) -def main(): - formats = [] - for arg in sys.argv[1:]: - formats.extend(parse(arg)) - print '/* This file is autogenerated by u_format_pack.py from u_format.csv. Do not edit directly. */' - print - # This will print the copyright message on the top of this file - print __doc__.strip() - - print - print '#ifndef U_FORMAT_PACK_H' - print '#define U_FORMAT_PACK_H' +def generate(formats): print print '#include "pipe/p_compiler.h"' print '#include "u_math.h"' @@ -570,30 +533,20 @@ def main(): generate_clamp() for format in formats: - if format.layout == PLAIN: + if is_format_supported(format): generate_format_type(format) channel = Channel(FLOAT, False, 32) native_type = 'float' - suffix = '4f' + suffix = 'float' generate_unpack(formats, channel, native_type, suffix) generate_pack(formats, channel, native_type, suffix) channel = Channel(UNSIGNED, True, 8) native_type = 'uint8_t' - suffix = '4ub' + suffix = '8unorm' generate_unpack(formats, channel, native_type, suffix) generate_pack(formats, channel, native_type, suffix) - print - print '#ifdef __cplusplus' - print '}' - print '#endif' - print - print '#endif /* ! U_FORMAT_PACK_H */' - - -if __name__ == '__main__': - main() diff --git a/src/gallium/auxiliary/util/u_format_table.py b/src/gallium/auxiliary/util/u_format_table.py index fb68852a530..fe910d9a772 100755 --- a/src/gallium/auxiliary/util/u_format_table.py +++ b/src/gallium/auxiliary/util/u_format_table.py @@ -33,6 +33,7 @@ import sys from u_format_parse import * +import u_format_pack def layout_map(layout): @@ -86,6 +87,27 @@ def write_format_table(formats): print print '#include "u_format.h"' print + print ''' +static void +util_format_none_unpack_8unorm(uint8_t *dst, const uint8_t *src, unsigned length) +{ +} + +static void +util_format_none_pack_8unorm(uint8_t *dst, const uint8_t *src, unsigned length) +{ +} + +static void +util_format_none_unpack_float(float *dst, const uint8_t *src, unsigned length) +{ +} + +static void +util_format_none_pack_float(uint8_t *dst, const float *src, unsigned length) +{ +} + ''' print 'const struct util_format_description' print 'util_format_none_description = {' print " PIPE_FORMAT_NONE," @@ -99,9 +121,16 @@ def write_format_table(formats): print " 0," print " {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}," print " {0, 0, 0, 0}," - print " 0" + print " 0," + print " &util_format_none_unpack_8unorm," + print " &util_format_none_pack_8unorm," + print " &util_format_none_unpack_float," + print " &util_format_none_pack_float" print "};" print + + u_format_pack.generate(formats) + for format in formats: print 'const struct util_format_description' print 'util_format_%s_description = {' % (format.short_name(),) @@ -140,8 +169,13 @@ def write_format_table(formats): print " %s%s\t/* %s */" % (swizzle_map[swizzle], sep, comment) print " }," print " %s," % (colorspace_map(format.colorspace),) + print " &util_format_%s_unpack_8unorm," % format.short_name() + print " &util_format_%s_pack_8unorm," % format.short_name() + print " &util_format_%s_unpack_float," % format.short_name() + print " &util_format_%s_pack_float" % format.short_name() print "};" print + print "const struct util_format_description *" print "util_format_description(enum pipe_format format)" print "{" diff --git a/src/gallium/auxiliary/util/u_format_tests.c b/src/gallium/auxiliary/util/u_format_tests.c index 9d6debcd8c7..4c4cc067a56 100644 --- a/src/gallium/auxiliary/util/u_format_tests.c +++ b/src/gallium/auxiliary/util/u_format_tests.c @@ -120,12 +120,11 @@ util_format_test_cases[] = * 16-bit rendertarget formats */ - {PIPE_FORMAT_B5G5R5X1_UNORM, PACKED_1x16(0x7fff), PACKED_1x16(0x0000), {0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_B5G5R5X1_UNORM, PACKED_1x16(0x7fff), PACKED_1x16(0x001f), {0.0, 0.0, 1.0, 0.0}}, - {PIPE_FORMAT_B5G5R5X1_UNORM, PACKED_1x16(0x7fff), PACKED_1x16(0x03e0), {0.0, 1.0, 0.0, 0.0}}, - {PIPE_FORMAT_B5G5R5X1_UNORM, PACKED_1x16(0x7fff), PACKED_1x16(0x7c00), {1.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_B5G5R5X1_UNORM, PACKED_1x16(0x7fff), PACKED_1x16(0x8000), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_B5G5R5X1_UNORM, PACKED_1x16(0x7fff), PACKED_1x16(0xffff), {1.0, 1.0, 1.0, 1.0}}, + {PIPE_FORMAT_B5G5R5X1_UNORM, PACKED_1x16(0x7fff), PACKED_1x16(0x0000), {0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_B5G5R5X1_UNORM, PACKED_1x16(0x7fff), PACKED_1x16(0x001f), {0.0, 0.0, 1.0, 1.0}}, + {PIPE_FORMAT_B5G5R5X1_UNORM, PACKED_1x16(0x7fff), PACKED_1x16(0x03e0), {0.0, 1.0, 0.0, 1.0}}, + {PIPE_FORMAT_B5G5R5X1_UNORM, PACKED_1x16(0x7fff), PACKED_1x16(0x7c00), {1.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_B5G5R5X1_UNORM, PACKED_1x16(0x7fff), PACKED_1x16(0x7fff), {1.0, 1.0, 1.0, 1.0}}, {PIPE_FORMAT_B5G5R5A1_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), {0.0, 0.0, 0.0, 0.0}}, {PIPE_FORMAT_B5G5R5A1_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x001f), {0.0, 0.0, 1.0, 0.0}}, |