diff options
Diffstat (limited to 'mesalib')
-rw-r--r-- | mesalib/src/gallium/auxiliary/util/u_format.c | 834 | ||||
-rw-r--r-- | mesalib/src/gallium/auxiliary/util/u_format.h | 1663 | ||||
-rw-r--r-- | mesalib/src/glsl/ir_function.cpp | 8 | ||||
-rw-r--r-- | mesalib/src/glsl/ir_function_detect_recursion.cpp | 5 | ||||
-rw-r--r-- | mesalib/src/glsl/link_functions.cpp | 4 | ||||
-rw-r--r-- | mesalib/src/glsl/linker.cpp | 193 | ||||
-rw-r--r-- | mesalib/src/glsl/linker.h | 3 | ||||
-rw-r--r-- | mesalib/src/glsl/main.cpp | 1 | ||||
-rw-r--r-- | mesalib/src/glsl/program.h | 62 | ||||
-rw-r--r-- | mesalib/src/mesa/main/shaderobj.c | 829 | ||||
-rw-r--r-- | mesalib/src/mesa/program/ir_to_mesa.cpp | 79 |
11 files changed, 1882 insertions, 1799 deletions
diff --git a/mesalib/src/gallium/auxiliary/util/u_format.c b/mesalib/src/gallium/auxiliary/util/u_format.c index 91485b05c..34922ab18 100644 --- a/mesalib/src/gallium/auxiliary/util/u_format.c +++ b/mesalib/src/gallium/auxiliary/util/u_format.c @@ -1,392 +1,442 @@ -/**************************************************************************
- *
- * Copyright 2010 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
- * Pixel format accessor functions.
- *
- * @author Jose Fonseca <jfonseca@vmware.com>
- */
-
-#include "u_math.h"
-#include "u_memory.h"
-#include "u_rect.h"
-#include "u_format.h"
-#include "u_format_s3tc.h"
-
-#include "pipe/p_defines.h"
-
-
-boolean
-util_format_is_float(enum pipe_format format)
-{
- const struct util_format_description *desc = util_format_description(format);
- unsigned i;
-
- assert(desc);
- if (!desc) {
- return FALSE;
- }
-
- /* Find the first non-void channel. */
- for (i = 0; i < 4; i++) {
- if (desc->channel[i].type != UTIL_FORMAT_TYPE_VOID) {
- break;
- }
- }
-
- if (i == 4) {
- return FALSE;
- }
-
- return desc->channel[i].type == UTIL_FORMAT_TYPE_FLOAT ? TRUE : FALSE;
-}
-
-
-boolean
-util_format_is_supported(enum pipe_format format, unsigned bind)
-{
- if (util_format_is_s3tc(format) && !util_format_s3tc_enabled) {
- return FALSE;
- }
-
-#ifndef TEXTURE_FLOAT_ENABLED
- if ((bind & PIPE_BIND_RENDER_TARGET) &&
- format != PIPE_FORMAT_R9G9B9E5_FLOAT &&
- format != PIPE_FORMAT_R11G11B10_FLOAT &&
- util_format_is_float(format)) {
- return FALSE;
- }
-#endif
-
- return TRUE;
-}
-
-
-void
-util_format_read_4f(enum pipe_format format,
- float *dst, unsigned dst_stride,
- const void *src, unsigned src_stride,
- unsigned x, unsigned y, unsigned w, unsigned h)
-{
- const struct util_format_description *format_desc;
- const uint8_t *src_row;
- float *dst_row;
-
- format_desc = util_format_description(format);
-
- assert(x % format_desc->block.width == 0);
- assert(y % format_desc->block.height == 0);
-
- src_row = (const uint8_t *)src + y*src_stride + x*(format_desc->block.bits/8);
- dst_row = dst;
-
- format_desc->unpack_rgba_float(dst_row, dst_stride, src_row, src_stride, w, h);
-}
-
-
-void
-util_format_write_4f(enum pipe_format format,
- const float *src, unsigned src_stride,
- void *dst, unsigned dst_stride,
- unsigned x, unsigned y, unsigned w, unsigned h)
-{
- const struct util_format_description *format_desc;
- uint8_t *dst_row;
- const float *src_row;
-
- format_desc = util_format_description(format);
-
- assert(x % format_desc->block.width == 0);
- assert(y % format_desc->block.height == 0);
-
- dst_row = (uint8_t *)dst + y*dst_stride + x*(format_desc->block.bits/8);
- src_row = src;
-
- format_desc->pack_rgba_float(dst_row, dst_stride, src_row, src_stride, w, h);
-}
-
-
-void
-util_format_read_4ub(enum pipe_format format, uint8_t *dst, unsigned dst_stride, const void *src, unsigned src_stride, unsigned x, unsigned y, unsigned w, unsigned h)
-{
- const struct util_format_description *format_desc;
- const uint8_t *src_row;
- uint8_t *dst_row;
-
- format_desc = util_format_description(format);
-
- assert(x % format_desc->block.width == 0);
- assert(y % format_desc->block.height == 0);
-
- src_row = (const uint8_t *)src + y*src_stride + x*(format_desc->block.bits/8);
- dst_row = dst;
-
- format_desc->unpack_rgba_8unorm(dst_row, dst_stride, src_row, src_stride, w, h);
-}
-
-
-void
-util_format_write_4ub(enum pipe_format format, const uint8_t *src, unsigned src_stride, void *dst, unsigned dst_stride, unsigned x, unsigned y, unsigned w, unsigned h)
-{
- const struct util_format_description *format_desc;
- uint8_t *dst_row;
- const uint8_t *src_row;
-
- format_desc = util_format_description(format);
-
- assert(x % format_desc->block.width == 0);
- assert(y % format_desc->block.height == 0);
-
- dst_row = (uint8_t *)dst + y*dst_stride + x*(format_desc->block.bits/8);
- src_row = src;
-
- format_desc->pack_rgba_8unorm(dst_row, dst_stride, src_row, src_stride, w, h);
-}
-
-
-boolean
-util_is_format_compatible(const struct util_format_description *src_desc,
- const struct util_format_description *dst_desc)
-{
- unsigned chan;
-
- if (src_desc->format == dst_desc->format) {
- return TRUE;
- }
-
- if (src_desc->layout != UTIL_FORMAT_LAYOUT_PLAIN ||
- dst_desc->layout != UTIL_FORMAT_LAYOUT_PLAIN) {
- return FALSE;
- }
-
- if (src_desc->block.bits != dst_desc->block.bits ||
- src_desc->nr_channels != dst_desc->nr_channels ||
- src_desc->colorspace != dst_desc->colorspace) {
- return FALSE;
- }
-
- for (chan = 0; chan < 4; ++chan) {
- if (src_desc->channel[chan].size !=
- dst_desc->channel[chan].size) {
- return FALSE;
- }
- }
-
- for (chan = 0; chan < 4; ++chan) {
- enum util_format_swizzle swizzle = dst_desc->swizzle[chan];
-
- if (swizzle < 4) {
- if (src_desc->swizzle[chan] != swizzle) {
- return FALSE;
- }
- if ((src_desc->channel[swizzle].type !=
- dst_desc->channel[swizzle].type) ||
- (src_desc->channel[swizzle].normalized !=
- dst_desc->channel[swizzle].normalized)) {
- return FALSE;
- }
- }
- }
-
- return TRUE;
-}
-
-
-boolean
-util_format_fits_8unorm(const struct util_format_description *format_desc)
-{
- unsigned chan;
-
- /*
- * After linearized sRGB values require more than 8bits.
- */
-
- if (format_desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB) {
- return FALSE;
- }
-
- switch (format_desc->layout) {
-
- case UTIL_FORMAT_LAYOUT_S3TC:
- case UTIL_FORMAT_LAYOUT_RGTC:
- /*
- * These are straight forward.
- */
-
- return TRUE;
-
- case UTIL_FORMAT_LAYOUT_PLAIN:
- /*
- * For these we can find a generic rule.
- */
-
- for (chan = 0; chan < format_desc->nr_channels; ++chan) {
- switch (format_desc->channel[chan].type) {
- case UTIL_FORMAT_TYPE_VOID:
- break;
- case UTIL_FORMAT_TYPE_UNSIGNED:
- if (!format_desc->channel[chan].normalized ||
- format_desc->channel[chan].size > 8) {
- return FALSE;
- }
- break;
- default:
- return FALSE;
- }
- }
- return TRUE;
-
- default:
- /*
- * Handle all others on a case by case basis.
- */
-
- switch (format_desc->format) {
- case PIPE_FORMAT_R1_UNORM:
- case PIPE_FORMAT_UYVY:
- case PIPE_FORMAT_YUYV:
- case PIPE_FORMAT_R8G8_B8G8_UNORM:
- case PIPE_FORMAT_G8R8_G8B8_UNORM:
- return TRUE;
-
- default:
- return FALSE;
- }
- }
-}
-
-
-void
-util_format_translate(enum pipe_format dst_format,
- void *dst, unsigned dst_stride,
- unsigned dst_x, unsigned dst_y,
- enum pipe_format src_format,
- const void *src, unsigned src_stride,
- unsigned src_x, unsigned src_y,
- unsigned width, unsigned height)
-{
- const struct util_format_description *dst_format_desc;
- const struct util_format_description *src_format_desc;
- uint8_t *dst_row;
- const uint8_t *src_row;
- unsigned x_step, y_step;
- unsigned dst_step;
- unsigned src_step;
-
- dst_format_desc = util_format_description(dst_format);
- src_format_desc = util_format_description(src_format);
-
- if (util_is_format_compatible(src_format_desc, dst_format_desc)) {
- /*
- * Trivial case.
- */
-
- util_copy_rect(dst, dst_format, dst_stride, dst_x, dst_y,
- width, height, src, (int)src_stride,
- src_x, src_y);
- return;
- }
-
- assert(dst_x % dst_format_desc->block.width == 0);
- assert(dst_y % dst_format_desc->block.height == 0);
- assert(src_x % src_format_desc->block.width == 0);
- assert(src_y % src_format_desc->block.height == 0);
-
- dst_row = (uint8_t *)dst + dst_y*dst_stride + dst_x*(dst_format_desc->block.bits/8);
- src_row = (const uint8_t *)src + src_y*src_stride + src_x*(src_format_desc->block.bits/8);
-
- /*
- * This works because all pixel formats have pixel blocks with power of two
- * sizes.
- */
-
- y_step = MAX2(dst_format_desc->block.height, src_format_desc->block.height);
- x_step = MAX2(dst_format_desc->block.width, src_format_desc->block.width);
- assert(y_step % dst_format_desc->block.height == 0);
- assert(y_step % src_format_desc->block.height == 0);
-
- dst_step = y_step / dst_format_desc->block.height * dst_stride;
- src_step = y_step / src_format_desc->block.height * src_stride;
-
- /*
- * TODO: double formats will loose precision
- * TODO: Add a special case for formats that are mere swizzles of each other
- */
-
- if (util_format_fits_8unorm(src_format_desc) ||
- util_format_fits_8unorm(dst_format_desc)) {
- unsigned tmp_stride;
- uint8_t *tmp_row;
-
- tmp_stride = MAX2(width, x_step) * 4 * sizeof *tmp_row;
- tmp_row = MALLOC(y_step * tmp_stride);
- if (!tmp_row)
- return;
-
- while (height >= y_step) {
- src_format_desc->unpack_rgba_8unorm(tmp_row, tmp_stride, src_row, src_stride, width, y_step);
- dst_format_desc->pack_rgba_8unorm(dst_row, dst_stride, tmp_row, tmp_stride, width, y_step);
-
- dst_row += dst_step;
- src_row += src_step;
- height -= y_step;
- }
-
- if (height) {
- src_format_desc->unpack_rgba_8unorm(tmp_row, tmp_stride, src_row, src_stride, width, height);
- dst_format_desc->pack_rgba_8unorm(dst_row, dst_stride, tmp_row, tmp_stride, width, height);
- }
-
- FREE(tmp_row);
- }
- else {
- unsigned tmp_stride;
- float *tmp_row;
-
- tmp_stride = MAX2(width, x_step) * 4 * sizeof *tmp_row;
- tmp_row = MALLOC(y_step * tmp_stride);
- if (!tmp_row)
- return;
-
- while (height >= y_step) {
- src_format_desc->unpack_rgba_float(tmp_row, tmp_stride, src_row, src_stride, width, y_step);
- dst_format_desc->pack_rgba_float(dst_row, dst_stride, tmp_row, tmp_stride, width, y_step);
-
- dst_row += dst_step;
- src_row += src_step;
- height -= y_step;
- }
-
- if (height) {
- src_format_desc->unpack_rgba_float(tmp_row, tmp_stride, src_row, src_stride, width, height);
- dst_format_desc->pack_rgba_float(dst_row, dst_stride, tmp_row, tmp_stride, width, height);
- }
-
- FREE(tmp_row);
- }
-}
+/************************************************************************** + * + * Copyright 2010 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 + * Pixel format accessor functions. + * + * @author Jose Fonseca <jfonseca@vmware.com> + */ + +#include "u_math.h" +#include "u_memory.h" +#include "u_rect.h" +#include "u_format.h" +#include "u_format_s3tc.h" + +#include "pipe/p_defines.h" + + +boolean +util_format_is_float(enum pipe_format format) +{ + const struct util_format_description *desc = util_format_description(format); + unsigned i; + + assert(desc); + if (!desc) { + return FALSE; + } + + /* Find the first non-void channel. */ + for (i = 0; i < 4; i++) { + if (desc->channel[i].type != UTIL_FORMAT_TYPE_VOID) { + break; + } + } + + if (i == 4) { + return FALSE; + } + + return desc->channel[i].type == UTIL_FORMAT_TYPE_FLOAT ? TRUE : FALSE; +} + + +boolean +util_format_is_supported(enum pipe_format format, unsigned bind) +{ + if (util_format_is_s3tc(format) && !util_format_s3tc_enabled) { + return FALSE; + } + +#ifndef TEXTURE_FLOAT_ENABLED + if ((bind & PIPE_BIND_RENDER_TARGET) && + format != PIPE_FORMAT_R9G9B9E5_FLOAT && + format != PIPE_FORMAT_R11G11B10_FLOAT && + util_format_is_float(format)) { + return FALSE; + } +#endif + + return TRUE; +} + + +void +util_format_read_4f(enum pipe_format format, + float *dst, unsigned dst_stride, + const void *src, unsigned src_stride, + unsigned x, unsigned y, unsigned w, unsigned h) +{ + const struct util_format_description *format_desc; + const uint8_t *src_row; + float *dst_row; + + format_desc = util_format_description(format); + + assert(x % format_desc->block.width == 0); + assert(y % format_desc->block.height == 0); + + src_row = (const uint8_t *)src + y*src_stride + x*(format_desc->block.bits/8); + dst_row = dst; + + format_desc->unpack_rgba_float(dst_row, dst_stride, src_row, src_stride, w, h); +} + + +void +util_format_write_4f(enum pipe_format format, + const float *src, unsigned src_stride, + void *dst, unsigned dst_stride, + unsigned x, unsigned y, unsigned w, unsigned h) +{ + const struct util_format_description *format_desc; + uint8_t *dst_row; + const float *src_row; + + format_desc = util_format_description(format); + + assert(x % format_desc->block.width == 0); + assert(y % format_desc->block.height == 0); + + dst_row = (uint8_t *)dst + y*dst_stride + x*(format_desc->block.bits/8); + src_row = src; + + format_desc->pack_rgba_float(dst_row, dst_stride, src_row, src_stride, w, h); +} + + +void +util_format_read_4ub(enum pipe_format format, uint8_t *dst, unsigned dst_stride, const void *src, unsigned src_stride, unsigned x, unsigned y, unsigned w, unsigned h) +{ + const struct util_format_description *format_desc; + const uint8_t *src_row; + uint8_t *dst_row; + + format_desc = util_format_description(format); + + assert(x % format_desc->block.width == 0); + assert(y % format_desc->block.height == 0); + + src_row = (const uint8_t *)src + y*src_stride + x*(format_desc->block.bits/8); + dst_row = dst; + + format_desc->unpack_rgba_8unorm(dst_row, dst_stride, src_row, src_stride, w, h); +} + + +void +util_format_write_4ub(enum pipe_format format, const uint8_t *src, unsigned src_stride, void *dst, unsigned dst_stride, unsigned x, unsigned y, unsigned w, unsigned h) +{ + const struct util_format_description *format_desc; + uint8_t *dst_row; + const uint8_t *src_row; + + format_desc = util_format_description(format); + + assert(x % format_desc->block.width == 0); + assert(y % format_desc->block.height == 0); + + dst_row = (uint8_t *)dst + y*dst_stride + x*(format_desc->block.bits/8); + src_row = src; + + format_desc->pack_rgba_8unorm(dst_row, dst_stride, src_row, src_stride, w, h); +} + + +boolean +util_is_format_compatible(const struct util_format_description *src_desc, + const struct util_format_description *dst_desc) +{ + unsigned chan; + + if (src_desc->format == dst_desc->format) { + return TRUE; + } + + if (src_desc->layout != UTIL_FORMAT_LAYOUT_PLAIN || + dst_desc->layout != UTIL_FORMAT_LAYOUT_PLAIN) { + return FALSE; + } + + if (src_desc->block.bits != dst_desc->block.bits || + src_desc->nr_channels != dst_desc->nr_channels || + src_desc->colorspace != dst_desc->colorspace) { + return FALSE; + } + + for (chan = 0; chan < 4; ++chan) { + if (src_desc->channel[chan].size != + dst_desc->channel[chan].size) { + return FALSE; + } + } + + for (chan = 0; chan < 4; ++chan) { + enum util_format_swizzle swizzle = dst_desc->swizzle[chan]; + + if (swizzle < 4) { + if (src_desc->swizzle[chan] != swizzle) { + return FALSE; + } + if ((src_desc->channel[swizzle].type != + dst_desc->channel[swizzle].type) || + (src_desc->channel[swizzle].normalized != + dst_desc->channel[swizzle].normalized)) { + return FALSE; + } + } + } + + return TRUE; +} + + +boolean +util_format_fits_8unorm(const struct util_format_description *format_desc) +{ + unsigned chan; + + /* + * After linearized sRGB values require more than 8bits. + */ + + if (format_desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB) { + return FALSE; + } + + switch (format_desc->layout) { + + case UTIL_FORMAT_LAYOUT_S3TC: + case UTIL_FORMAT_LAYOUT_RGTC: + /* + * These are straight forward. + */ + + return TRUE; + + case UTIL_FORMAT_LAYOUT_PLAIN: + /* + * For these we can find a generic rule. + */ + + for (chan = 0; chan < format_desc->nr_channels; ++chan) { + switch (format_desc->channel[chan].type) { + case UTIL_FORMAT_TYPE_VOID: + break; + case UTIL_FORMAT_TYPE_UNSIGNED: + if (!format_desc->channel[chan].normalized || + format_desc->channel[chan].size > 8) { + return FALSE; + } + break; + default: + return FALSE; + } + } + return TRUE; + + default: + /* + * Handle all others on a case by case basis. + */ + + switch (format_desc->format) { + case PIPE_FORMAT_R1_UNORM: + case PIPE_FORMAT_UYVY: + case PIPE_FORMAT_YUYV: + case PIPE_FORMAT_R8G8_B8G8_UNORM: + case PIPE_FORMAT_G8R8_G8B8_UNORM: + return TRUE; + + default: + return FALSE; + } + } +} + + +void +util_format_translate(enum pipe_format dst_format, + void *dst, unsigned dst_stride, + unsigned dst_x, unsigned dst_y, + enum pipe_format src_format, + const void *src, unsigned src_stride, + unsigned src_x, unsigned src_y, + unsigned width, unsigned height) +{ + const struct util_format_description *dst_format_desc; + const struct util_format_description *src_format_desc; + uint8_t *dst_row; + const uint8_t *src_row; + unsigned x_step, y_step; + unsigned dst_step; + unsigned src_step; + + dst_format_desc = util_format_description(dst_format); + src_format_desc = util_format_description(src_format); + + if (util_is_format_compatible(src_format_desc, dst_format_desc)) { + /* + * Trivial case. + */ + + util_copy_rect(dst, dst_format, dst_stride, dst_x, dst_y, + width, height, src, (int)src_stride, + src_x, src_y); + return; + } + + assert(dst_x % dst_format_desc->block.width == 0); + assert(dst_y % dst_format_desc->block.height == 0); + assert(src_x % src_format_desc->block.width == 0); + assert(src_y % src_format_desc->block.height == 0); + + dst_row = (uint8_t *)dst + dst_y*dst_stride + dst_x*(dst_format_desc->block.bits/8); + src_row = (const uint8_t *)src + src_y*src_stride + src_x*(src_format_desc->block.bits/8); + + /* + * This works because all pixel formats have pixel blocks with power of two + * sizes. + */ + + y_step = MAX2(dst_format_desc->block.height, src_format_desc->block.height); + x_step = MAX2(dst_format_desc->block.width, src_format_desc->block.width); + assert(y_step % dst_format_desc->block.height == 0); + assert(y_step % src_format_desc->block.height == 0); + + dst_step = y_step / dst_format_desc->block.height * dst_stride; + src_step = y_step / src_format_desc->block.height * src_stride; + + /* + * TODO: double formats will loose precision + * TODO: Add a special case for formats that are mere swizzles of each other + */ + + if (util_format_fits_8unorm(src_format_desc) || + util_format_fits_8unorm(dst_format_desc)) { + unsigned tmp_stride; + uint8_t *tmp_row; + + tmp_stride = MAX2(width, x_step) * 4 * sizeof *tmp_row; + tmp_row = MALLOC(y_step * tmp_stride); + if (!tmp_row) + return; + + while (height >= y_step) { + src_format_desc->unpack_rgba_8unorm(tmp_row, tmp_stride, src_row, src_stride, width, y_step); + dst_format_desc->pack_rgba_8unorm(dst_row, dst_stride, tmp_row, tmp_stride, width, y_step); + + dst_row += dst_step; + src_row += src_step; + height -= y_step; + } + + if (height) { + src_format_desc->unpack_rgba_8unorm(tmp_row, tmp_stride, src_row, src_stride, width, height); + dst_format_desc->pack_rgba_8unorm(dst_row, dst_stride, tmp_row, tmp_stride, width, height); + } + + FREE(tmp_row); + } + else { + unsigned tmp_stride; + float *tmp_row; + + tmp_stride = MAX2(width, x_step) * 4 * sizeof *tmp_row; + tmp_row = MALLOC(y_step * tmp_stride); + if (!tmp_row) + return; + + while (height >= y_step) { + src_format_desc->unpack_rgba_float(tmp_row, tmp_stride, src_row, src_stride, width, y_step); + dst_format_desc->pack_rgba_float(dst_row, dst_stride, tmp_row, tmp_stride, width, y_step); + + dst_row += dst_step; + src_row += src_step; + height -= y_step; + } + + if (height) { + src_format_desc->unpack_rgba_float(tmp_row, tmp_stride, src_row, src_stride, width, height); + dst_format_desc->pack_rgba_float(dst_row, dst_stride, tmp_row, tmp_stride, width, height); + } + + FREE(tmp_row); + } +} + +void util_format_compose_swizzles(const unsigned char swz1[4], + const unsigned char swz2[4], + unsigned char dst[4]) +{ + unsigned i; + + for (i = 0; i < 4; i++) { + dst[i] = swz2[i] <= UTIL_FORMAT_SWIZZLE_W ? + swz1[swz2[i]] : swz2[i]; + } +} + +void util_format_swizzle_4f(float *dst, const float *src, + const unsigned char swz[4]) +{ + unsigned i; + + for (i = 0; i < 4; i++) { + if (swz[i] <= UTIL_FORMAT_SWIZZLE_W) + dst[i] = src[swz[i]]; + else if (swz[i] == UTIL_FORMAT_SWIZZLE_0) + dst[i] = 0; + else if (swz[i] == UTIL_FORMAT_SWIZZLE_1) + dst[i] = 1; + } +} + +void util_format_unswizzle_4f(float *dst, const float *src, + const unsigned char swz[4]) +{ + unsigned i; + + for (i = 0; i < 4; i++) { + switch (swz[i]) { + case UTIL_FORMAT_SWIZZLE_X: + dst[0] = src[i]; + break; + case UTIL_FORMAT_SWIZZLE_Y: + dst[1] = src[i]; + break; + case UTIL_FORMAT_SWIZZLE_Z: + dst[2] = src[i]; + break; + case UTIL_FORMAT_SWIZZLE_W: + dst[3] = src[i]; + break; + } + } +} diff --git a/mesalib/src/gallium/auxiliary/util/u_format.h b/mesalib/src/gallium/auxiliary/util/u_format.h index 6e9b6902e..566fa79e7 100644 --- a/mesalib/src/gallium/auxiliary/util/u_format.h +++ b/mesalib/src/gallium/auxiliary/util/u_format.h @@ -1,822 +1,841 @@ -/**************************************************************************
- *
- * Copyright 2009-2010 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.
- *
- **************************************************************************/
-
-
-#ifndef U_FORMAT_H
-#define U_FORMAT_H
-
-
-#include "pipe/p_format.h"
-#include "util/u_debug.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/**
- * Describe how to pack/unpack pixels into/from the prescribed format.
- *
- * XXX: This could be renamed to something like util_format_pack, or broke down
- * in flags inside util_format_block that said exactly what we want.
- */
-enum util_format_layout {
- /**
- * Formats with util_format_block::width == util_format_block::height == 1
- * that can be described as an ordinary data structure.
- */
- UTIL_FORMAT_LAYOUT_PLAIN = 0,
-
- /**
- * Formats with sub-sampled channels.
- *
- * This is for formats like YV12 where there is less than one sample per
- * pixel.
- */
- UTIL_FORMAT_LAYOUT_SUBSAMPLED = 3,
-
- /**
- * S3 Texture Compression formats.
- */
- UTIL_FORMAT_LAYOUT_S3TC = 4,
-
- /**
- * Red-Green Texture Compression formats.
- */
- UTIL_FORMAT_LAYOUT_RGTC = 5,
-
- /**
- * Everything else that doesn't fit in any of the above layouts.
- */
- UTIL_FORMAT_LAYOUT_OTHER = 6
-};
-
-
-struct util_format_block
-{
- /** Block width in pixels */
- unsigned width;
-
- /** Block height in pixels */
- unsigned height;
-
- /** Block size in bits */
- unsigned bits;
-};
-
-
-enum util_format_type {
- UTIL_FORMAT_TYPE_VOID = 0,
- UTIL_FORMAT_TYPE_UNSIGNED = 1,
- UTIL_FORMAT_TYPE_SIGNED = 2,
- UTIL_FORMAT_TYPE_FIXED = 3,
- UTIL_FORMAT_TYPE_FLOAT = 4
-};
-
-
-enum util_format_swizzle {
- UTIL_FORMAT_SWIZZLE_X = 0,
- UTIL_FORMAT_SWIZZLE_Y = 1,
- UTIL_FORMAT_SWIZZLE_Z = 2,
- UTIL_FORMAT_SWIZZLE_W = 3,
- UTIL_FORMAT_SWIZZLE_0 = 4,
- UTIL_FORMAT_SWIZZLE_1 = 5,
- UTIL_FORMAT_SWIZZLE_NONE = 6
-};
-
-
-enum util_format_colorspace {
- UTIL_FORMAT_COLORSPACE_RGB = 0,
- UTIL_FORMAT_COLORSPACE_SRGB = 1,
- UTIL_FORMAT_COLORSPACE_YUV = 2,
- UTIL_FORMAT_COLORSPACE_ZS = 3
-};
-
-
-struct util_format_channel_description
-{
- unsigned type:6;
- unsigned normalized:1;
- unsigned size:9;
-};
-
-
-struct util_format_description
-{
- enum pipe_format format;
-
- const char *name;
-
- /**
- * Short name, striped of the prefix, lower case.
- */
- const char *short_name;
-
- /**
- * Pixel block dimensions.
- */
- struct util_format_block block;
-
- enum util_format_layout layout;
-
- /**
- * The number of channels.
- */
- unsigned nr_channels:3;
-
- /**
- * Whether all channels have the same number of (whole) bytes.
- */
- unsigned is_array:1;
-
- /**
- * Whether the pixel format can be described as a bitfield structure.
- *
- * In particular:
- * - pixel depth must be 8, 16, or 32 bits;
- * - all channels must be unsigned, signed, or void
- */
- unsigned is_bitmask:1;
-
- /**
- * Whether channels have mixed types (ignoring UTIL_FORMAT_TYPE_VOID).
- */
- unsigned is_mixed:1;
-
- /**
- * Input channel description.
- *
- * Only valid for UTIL_FORMAT_LAYOUT_PLAIN formats.
- */
- struct util_format_channel_description channel[4];
-
- /**
- * Output channel swizzle.
- *
- * The order is either:
- * - RGBA
- * - YUV(A)
- * - ZS
- * depending on the colorspace.
- */
- unsigned char swizzle[4];
-
- /**
- * Colorspace transformation.
- */
- enum util_format_colorspace colorspace;
-
- /**
- * Unpack pixel blocks to R8G8B8A8_UNORM.
- * Note: strides are in bytes.
- *
- * Only defined for non-depth-stencil formats.
- */
- void
- (*unpack_rgba_8unorm)(uint8_t *dst, unsigned dst_stride,
- const uint8_t *src, unsigned src_stride,
- unsigned width, unsigned height);
-
- /**
- * Pack pixel blocks from R8G8B8A8_UNORM.
- * Note: strides are in bytes.
- *
- * Only defined for non-depth-stencil formats.
- */
- void
- (*pack_rgba_8unorm)(uint8_t *dst, unsigned dst_stride,
- const uint8_t *src, unsigned src_stride,
- unsigned width, unsigned height);
-
- /**
- * Fetch a single pixel (i, j) from a block.
- *
- * XXX: Only defined for a very few select formats.
- */
- void
- (*fetch_rgba_8unorm)(uint8_t *dst,
- const uint8_t *src,
- unsigned i, unsigned j);
-
- /**
- * Unpack pixel blocks to R32G32B32A32_FLOAT.
- * Note: strides are in bytes.
- *
- * Only defined for non-depth-stencil formats.
- */
- void
- (*unpack_rgba_float)(float *dst, unsigned dst_stride,
- const uint8_t *src, unsigned src_stride,
- unsigned width, unsigned height);
-
- /**
- * Pack pixel blocks from R32G32B32A32_FLOAT.
- * Note: strides are in bytes.
- *
- * Only defined for non-depth-stencil formats.
- */
- void
- (*pack_rgba_float)(uint8_t *dst, unsigned dst_stride,
- const float *src, unsigned src_stride,
- unsigned width, unsigned height);
-
- /**
- * Fetch a single pixel (i, j) from a block.
- *
- * Only defined for non-depth-stencil formats.
- */
- void
- (*fetch_rgba_float)(float *dst,
- const uint8_t *src,
- unsigned i, unsigned j);
-
- /**
- * Unpack pixels to Z32_UNORM.
- * Note: strides are in bytes.
- *
- * Only defined for depth formats.
- */
- void
- (*unpack_z_32unorm)(uint32_t *dst, unsigned dst_stride,
- const uint8_t *src, unsigned src_stride,
- unsigned width, unsigned height);
-
- /**
- * Pack pixels from Z32_FLOAT.
- * Note: strides are in bytes.
- *
- * Only defined for depth formats.
- */
- void
- (*pack_z_32unorm)(uint8_t *dst, unsigned dst_stride,
- const uint32_t *src, unsigned src_stride,
- unsigned width, unsigned height);
-
- /**
- * Unpack pixels to Z32_FLOAT.
- * Note: strides are in bytes.
- *
- * Only defined for depth formats.
- */
- void
- (*unpack_z_float)(float *dst, unsigned dst_stride,
- const uint8_t *src, unsigned src_stride,
- unsigned width, unsigned height);
-
- /**
- * Pack pixels from Z32_FLOAT.
- * Note: strides are in bytes.
- *
- * Only defined for depth formats.
- */
- void
- (*pack_z_float)(uint8_t *dst, unsigned dst_stride,
- const float *src, unsigned src_stride,
- unsigned width, unsigned height);
-
- /**
- * Unpack pixels to S8_USCALED.
- * Note: strides are in bytes.
- *
- * Only defined for stencil formats.
- */
- void
- (*unpack_s_8uscaled)(uint8_t *dst, unsigned dst_stride,
- const uint8_t *src, unsigned src_stride,
- unsigned width, unsigned height);
-
- /**
- * Pack pixels from S8_USCALED.
- * Note: strides are in bytes.
- *
- * Only defined for stencil formats.
- */
- void
- (*pack_s_8uscaled)(uint8_t *dst, unsigned dst_stride,
- const uint8_t *src, unsigned src_stride,
- unsigned width, unsigned height);
-
-};
-
-
-extern const struct util_format_description
-util_format_description_table[];
-
-
-const struct util_format_description *
-util_format_description(enum pipe_format format);
-
-
-/*
- * Format query functions.
- */
-
-static INLINE const char *
-util_format_name(enum pipe_format format)
-{
- const struct util_format_description *desc = util_format_description(format);
-
- assert(desc);
- if (!desc) {
- return "PIPE_FORMAT_???";
- }
-
- return desc->name;
-}
-
-static INLINE const char *
-util_format_short_name(enum pipe_format format)
-{
- const struct util_format_description *desc = util_format_description(format);
-
- assert(desc);
- if (!desc) {
- return "???";
- }
-
- return desc->short_name;
-}
-
-/**
- * Whether this format is plain, see UTIL_FORMAT_LAYOUT_PLAIN for more info.
- */
-static INLINE boolean
-util_format_is_plain(enum pipe_format format)
-{
- const struct util_format_description *desc = util_format_description(format);
-
- if (!format) {
- return FALSE;
- }
-
- return desc->layout == UTIL_FORMAT_LAYOUT_PLAIN ? TRUE : FALSE;
-}
-
-static INLINE boolean
-util_format_is_compressed(enum pipe_format format)
-{
- const struct util_format_description *desc = util_format_description(format);
-
- assert(desc);
- if (!desc) {
- return FALSE;
- }
-
- switch (desc->layout) {
- case UTIL_FORMAT_LAYOUT_S3TC:
- case UTIL_FORMAT_LAYOUT_RGTC:
- /* XXX add other formats in the future */
- return TRUE;
- default:
- return FALSE;
- }
-}
-
-static INLINE boolean
-util_format_is_s3tc(enum pipe_format format)
-{
- const struct util_format_description *desc = util_format_description(format);
-
- assert(desc);
- if (!desc) {
- return FALSE;
- }
-
- return desc->layout == UTIL_FORMAT_LAYOUT_S3TC ? TRUE : FALSE;
-}
-
-static INLINE boolean
-util_format_is_depth_or_stencil(enum pipe_format format)
-{
- const struct util_format_description *desc = util_format_description(format);
-
- assert(desc);
- if (!desc) {
- return FALSE;
- }
-
- return desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS ? TRUE : FALSE;
-}
-
-static INLINE boolean
-util_format_is_depth_and_stencil(enum pipe_format format)
-{
- const struct util_format_description *desc = util_format_description(format);
-
- assert(desc);
- if (!desc) {
- return FALSE;
- }
-
- if (desc->colorspace != UTIL_FORMAT_COLORSPACE_ZS) {
- return FALSE;
- }
-
- return (desc->swizzle[0] != UTIL_FORMAT_SWIZZLE_NONE &&
- desc->swizzle[1] != UTIL_FORMAT_SWIZZLE_NONE) ? TRUE : FALSE;
-}
-
-
-/**
- * Give the RGBA colormask of the channels that can be represented in this
- * format.
- *
- * That is, the channels whose values are preserved.
- */
-static INLINE unsigned
-util_format_colormask(const struct util_format_description *desc)
-{
- unsigned colormask;
- unsigned chan;
-
- switch (desc->colorspace) {
- case UTIL_FORMAT_COLORSPACE_RGB:
- case UTIL_FORMAT_COLORSPACE_SRGB:
- case UTIL_FORMAT_COLORSPACE_YUV:
- colormask = 0;
- for (chan = 0; chan < 4; ++chan) {
- if (desc->swizzle[chan] < 4) {
- colormask |= (1 << chan);
- }
- }
- return colormask;
- case UTIL_FORMAT_COLORSPACE_ZS:
- return 0;
- default:
- assert(0);
- return 0;
- }
-}
-
-
-boolean
-util_format_is_float(enum pipe_format format);
-
-
-/**
- * Whether the src format can be blitted to destation format with a simple
- * memcpy.
- */
-boolean
-util_is_format_compatible(const struct util_format_description *src_desc,
- const struct util_format_description *dst_desc);
-
-/**
- * Whether the format is supported by Gallium for the given bindings.
- * This covers S3TC textures and floating-point render targets.
- */
-boolean
-util_format_is_supported(enum pipe_format format, unsigned bind);
-
-/**
- * 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.
- */
-static INLINE uint
-util_format_get_blocksizebits(enum pipe_format format)
-{
- const struct util_format_description *desc = util_format_description(format);
-
- assert(desc);
- if (!desc) {
- return 0;
- }
-
- return desc->block.bits;
-}
-
-/**
- * Return bytes per block (not pixel) for the given format.
- */
-static INLINE uint
-util_format_get_blocksize(enum pipe_format format)
-{
- uint bits = util_format_get_blocksizebits(format);
-
- assert(bits % 8 == 0);
-
- return bits / 8;
-}
-
-static INLINE uint
-util_format_get_blockwidth(enum pipe_format format)
-{
- const struct util_format_description *desc = util_format_description(format);
-
- assert(desc);
- if (!desc) {
- return 1;
- }
-
- return desc->block.width;
-}
-
-static INLINE uint
-util_format_get_blockheight(enum pipe_format format)
-{
- const struct util_format_description *desc = util_format_description(format);
-
- assert(desc);
- if (!desc) {
- return 1;
- }
-
- return desc->block.height;
-}
-
-static INLINE unsigned
-util_format_get_nblocksx(enum pipe_format format,
- unsigned x)
-{
- unsigned blockwidth = util_format_get_blockwidth(format);
- return (x + blockwidth - 1) / blockwidth;
-}
-
-static INLINE unsigned
-util_format_get_nblocksy(enum pipe_format format,
- unsigned y)
-{
- unsigned blockheight = util_format_get_blockheight(format);
- return (y + blockheight - 1) / blockheight;
-}
-
-static INLINE unsigned
-util_format_get_nblocks(enum pipe_format format,
- unsigned width,
- unsigned height)
-{
- return util_format_get_nblocksx(format, width) * util_format_get_nblocksy(format, height);
-}
-
-static INLINE size_t
-util_format_get_stride(enum pipe_format format,
- unsigned width)
-{
- return util_format_get_nblocksx(format, width) * util_format_get_blocksize(format);
-}
-
-static INLINE size_t
-util_format_get_2d_size(enum pipe_format format,
- size_t stride,
- unsigned height)
-{
- return util_format_get_nblocksy(format, height) * stride;
-}
-
-static INLINE uint
-util_format_get_component_bits(enum pipe_format format,
- enum util_format_colorspace colorspace,
- uint component)
-{
- const struct util_format_description *desc = util_format_description(format);
- enum util_format_colorspace desc_colorspace;
-
- assert(format);
- if (!format) {
- return 0;
- }
-
- assert(component < 4);
-
- /* Treat RGB and SRGB as equivalent. */
- if (colorspace == UTIL_FORMAT_COLORSPACE_SRGB) {
- colorspace = UTIL_FORMAT_COLORSPACE_RGB;
- }
- if (desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB) {
- desc_colorspace = UTIL_FORMAT_COLORSPACE_RGB;
- } else {
- desc_colorspace = desc->colorspace;
- }
-
- if (desc_colorspace != colorspace) {
- return 0;
- }
-
- switch (desc->swizzle[component]) {
- case UTIL_FORMAT_SWIZZLE_X:
- return desc->channel[0].size;
- case UTIL_FORMAT_SWIZZLE_Y:
- return desc->channel[1].size;
- case UTIL_FORMAT_SWIZZLE_Z:
- return desc->channel[2].size;
- case UTIL_FORMAT_SWIZZLE_W:
- return desc->channel[3].size;
- default:
- return 0;
- }
-}
-
-static INLINE boolean
-util_format_has_alpha(enum pipe_format format)
-{
- const struct util_format_description *desc = util_format_description(format);
-
- assert(format);
- if (!format) {
- return FALSE;
- }
-
- switch (desc->colorspace) {
- case UTIL_FORMAT_COLORSPACE_RGB:
- case UTIL_FORMAT_COLORSPACE_SRGB:
- return desc->swizzle[3] != UTIL_FORMAT_SWIZZLE_1;
- case UTIL_FORMAT_COLORSPACE_YUV:
- return FALSE;
- case UTIL_FORMAT_COLORSPACE_ZS:
- return FALSE;
- default:
- assert(0);
- return FALSE;
- }
-}
-
-/**
- * Given a linear RGB colorspace format, return the corresponding SRGB
- * format, or PIPE_FORMAT_NONE if none.
- */
-static INLINE enum pipe_format
-util_format_srgb(enum pipe_format format)
-{
- switch (format) {
- case PIPE_FORMAT_L8_UNORM:
- return PIPE_FORMAT_L8_SRGB;
- case PIPE_FORMAT_L8A8_UNORM:
- return PIPE_FORMAT_L8A8_SRGB;
- case PIPE_FORMAT_R8G8B8_UNORM:
- return PIPE_FORMAT_R8G8B8_SRGB;
- case PIPE_FORMAT_A8B8G8R8_UNORM:
- return PIPE_FORMAT_A8B8G8R8_SRGB;
- case PIPE_FORMAT_X8B8G8R8_UNORM:
- return PIPE_FORMAT_X8B8G8R8_SRGB;
- case PIPE_FORMAT_B8G8R8A8_UNORM:
- return PIPE_FORMAT_B8G8R8A8_SRGB;
- case PIPE_FORMAT_B8G8R8X8_UNORM:
- return PIPE_FORMAT_B8G8R8X8_SRGB;
- case PIPE_FORMAT_A8R8G8B8_UNORM:
- return PIPE_FORMAT_A8R8G8B8_SRGB;
- case PIPE_FORMAT_X8R8G8B8_UNORM:
- return PIPE_FORMAT_X8R8G8B8_SRGB;
- case PIPE_FORMAT_DXT1_RGB:
- return PIPE_FORMAT_DXT1_SRGB;
- case PIPE_FORMAT_DXT1_RGBA:
- return PIPE_FORMAT_DXT1_SRGBA;
- case PIPE_FORMAT_DXT3_RGBA:
- return PIPE_FORMAT_DXT3_SRGBA;
- case PIPE_FORMAT_DXT5_RGBA:
- return PIPE_FORMAT_DXT5_SRGBA;
- default:
- return PIPE_FORMAT_NONE;
- }
-}
-
-/**
- * Given an sRGB format, return the corresponding linear colorspace format.
- * For non sRGB formats, return the format unchanged.
- */
-static INLINE enum pipe_format
-util_format_linear(enum pipe_format format)
-{
- switch (format) {
- case PIPE_FORMAT_L8_SRGB:
- return PIPE_FORMAT_L8_UNORM;
- case PIPE_FORMAT_L8A8_SRGB:
- return PIPE_FORMAT_L8A8_UNORM;
- case PIPE_FORMAT_R8G8B8_SRGB:
- return PIPE_FORMAT_R8G8B8_UNORM;
- case PIPE_FORMAT_A8B8G8R8_SRGB:
- return PIPE_FORMAT_A8B8G8R8_UNORM;
- case PIPE_FORMAT_X8B8G8R8_SRGB:
- return PIPE_FORMAT_X8B8G8R8_UNORM;
- case PIPE_FORMAT_B8G8R8A8_SRGB:
- return PIPE_FORMAT_B8G8R8A8_UNORM;
- case PIPE_FORMAT_B8G8R8X8_SRGB:
- return PIPE_FORMAT_B8G8R8X8_UNORM;
- case PIPE_FORMAT_A8R8G8B8_SRGB:
- return PIPE_FORMAT_A8R8G8B8_UNORM;
- case PIPE_FORMAT_X8R8G8B8_SRGB:
- return PIPE_FORMAT_X8R8G8B8_UNORM;
- case PIPE_FORMAT_DXT1_SRGB:
- return PIPE_FORMAT_DXT1_RGB;
- case PIPE_FORMAT_DXT1_SRGBA:
- return PIPE_FORMAT_DXT1_RGBA;
- case PIPE_FORMAT_DXT3_SRGBA:
- return PIPE_FORMAT_DXT3_RGBA;
- case PIPE_FORMAT_DXT5_SRGBA:
- return PIPE_FORMAT_DXT5_RGBA;
- default:
- return format;
- }
-}
-
-/**
- * Return the number of components stored.
- * Formats with block size != 1x1 will always have 1 component (the block).
- */
-static INLINE unsigned
-util_format_get_nr_components(enum pipe_format format)
-{
- const struct util_format_description *desc = util_format_description(format);
- return desc->nr_channels;
-}
-
-/*
- * Format access functions.
- */
-
-void
-util_format_read_4f(enum pipe_format format,
- float *dst, unsigned dst_stride,
- const void *src, unsigned src_stride,
- unsigned x, unsigned y, unsigned w, unsigned h);
-
-void
-util_format_write_4f(enum pipe_format format,
- const float *src, unsigned src_stride,
- void *dst, unsigned dst_stride,
- unsigned x, unsigned y, unsigned w, unsigned h);
-
-void
-util_format_read_4ub(enum pipe_format format,
- uint8_t *dst, unsigned dst_stride,
- const void *src, unsigned src_stride,
- unsigned x, unsigned y, unsigned w, unsigned h);
-
-void
-util_format_write_4ub(enum pipe_format format,
- const uint8_t *src, unsigned src_stride,
- void *dst, unsigned dst_stride,
- unsigned x, unsigned y, unsigned w, unsigned h);
-
-/*
- * Generic format conversion;
- */
-
-boolean
-util_format_fits_8unorm(const struct util_format_description *format_desc);
-
-void
-util_format_translate(enum pipe_format dst_format,
- void *dst, unsigned dst_stride,
- unsigned dst_x, unsigned dst_y,
- enum pipe_format src_format,
- const void *src, unsigned src_stride,
- unsigned src_x, unsigned src_y,
- unsigned width, unsigned height);
-
-#ifdef __cplusplus
-} // extern "C" {
-#endif
-
-#endif /* ! U_FORMAT_H */
+/************************************************************************** + * + * Copyright 2009-2010 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. + * + **************************************************************************/ + + +#ifndef U_FORMAT_H +#define U_FORMAT_H + + +#include "pipe/p_format.h" +#include "util/u_debug.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * Describe how to pack/unpack pixels into/from the prescribed format. + * + * XXX: This could be renamed to something like util_format_pack, or broke down + * in flags inside util_format_block that said exactly what we want. + */ +enum util_format_layout { + /** + * Formats with util_format_block::width == util_format_block::height == 1 + * that can be described as an ordinary data structure. + */ + UTIL_FORMAT_LAYOUT_PLAIN = 0, + + /** + * Formats with sub-sampled channels. + * + * This is for formats like YV12 where there is less than one sample per + * pixel. + */ + UTIL_FORMAT_LAYOUT_SUBSAMPLED = 3, + + /** + * S3 Texture Compression formats. + */ + UTIL_FORMAT_LAYOUT_S3TC = 4, + + /** + * Red-Green Texture Compression formats. + */ + UTIL_FORMAT_LAYOUT_RGTC = 5, + + /** + * Everything else that doesn't fit in any of the above layouts. + */ + UTIL_FORMAT_LAYOUT_OTHER = 6 +}; + + +struct util_format_block +{ + /** Block width in pixels */ + unsigned width; + + /** Block height in pixels */ + unsigned height; + + /** Block size in bits */ + unsigned bits; +}; + + +enum util_format_type { + UTIL_FORMAT_TYPE_VOID = 0, + UTIL_FORMAT_TYPE_UNSIGNED = 1, + UTIL_FORMAT_TYPE_SIGNED = 2, + UTIL_FORMAT_TYPE_FIXED = 3, + UTIL_FORMAT_TYPE_FLOAT = 4 +}; + + +enum util_format_swizzle { + UTIL_FORMAT_SWIZZLE_X = 0, + UTIL_FORMAT_SWIZZLE_Y = 1, + UTIL_FORMAT_SWIZZLE_Z = 2, + UTIL_FORMAT_SWIZZLE_W = 3, + UTIL_FORMAT_SWIZZLE_0 = 4, + UTIL_FORMAT_SWIZZLE_1 = 5, + UTIL_FORMAT_SWIZZLE_NONE = 6 +}; + + +enum util_format_colorspace { + UTIL_FORMAT_COLORSPACE_RGB = 0, + UTIL_FORMAT_COLORSPACE_SRGB = 1, + UTIL_FORMAT_COLORSPACE_YUV = 2, + UTIL_FORMAT_COLORSPACE_ZS = 3 +}; + + +struct util_format_channel_description +{ + unsigned type:6; + unsigned normalized:1; + unsigned size:9; +}; + + +struct util_format_description +{ + enum pipe_format format; + + const char *name; + + /** + * Short name, striped of the prefix, lower case. + */ + const char *short_name; + + /** + * Pixel block dimensions. + */ + struct util_format_block block; + + enum util_format_layout layout; + + /** + * The number of channels. + */ + unsigned nr_channels:3; + + /** + * Whether all channels have the same number of (whole) bytes. + */ + unsigned is_array:1; + + /** + * Whether the pixel format can be described as a bitfield structure. + * + * In particular: + * - pixel depth must be 8, 16, or 32 bits; + * - all channels must be unsigned, signed, or void + */ + unsigned is_bitmask:1; + + /** + * Whether channels have mixed types (ignoring UTIL_FORMAT_TYPE_VOID). + */ + unsigned is_mixed:1; + + /** + * Input channel description. + * + * Only valid for UTIL_FORMAT_LAYOUT_PLAIN formats. + */ + struct util_format_channel_description channel[4]; + + /** + * Output channel swizzle. + * + * The order is either: + * - RGBA + * - YUV(A) + * - ZS + * depending on the colorspace. + */ + unsigned char swizzle[4]; + + /** + * Colorspace transformation. + */ + enum util_format_colorspace colorspace; + + /** + * Unpack pixel blocks to R8G8B8A8_UNORM. + * Note: strides are in bytes. + * + * Only defined for non-depth-stencil formats. + */ + void + (*unpack_rgba_8unorm)(uint8_t *dst, unsigned dst_stride, + const uint8_t *src, unsigned src_stride, + unsigned width, unsigned height); + + /** + * Pack pixel blocks from R8G8B8A8_UNORM. + * Note: strides are in bytes. + * + * Only defined for non-depth-stencil formats. + */ + void + (*pack_rgba_8unorm)(uint8_t *dst, unsigned dst_stride, + const uint8_t *src, unsigned src_stride, + unsigned width, unsigned height); + + /** + * Fetch a single pixel (i, j) from a block. + * + * XXX: Only defined for a very few select formats. + */ + void + (*fetch_rgba_8unorm)(uint8_t *dst, + const uint8_t *src, + unsigned i, unsigned j); + + /** + * Unpack pixel blocks to R32G32B32A32_FLOAT. + * Note: strides are in bytes. + * + * Only defined for non-depth-stencil formats. + */ + void + (*unpack_rgba_float)(float *dst, unsigned dst_stride, + const uint8_t *src, unsigned src_stride, + unsigned width, unsigned height); + + /** + * Pack pixel blocks from R32G32B32A32_FLOAT. + * Note: strides are in bytes. + * + * Only defined for non-depth-stencil formats. + */ + void + (*pack_rgba_float)(uint8_t *dst, unsigned dst_stride, + const float *src, unsigned src_stride, + unsigned width, unsigned height); + + /** + * Fetch a single pixel (i, j) from a block. + * + * Only defined for non-depth-stencil formats. + */ + void + (*fetch_rgba_float)(float *dst, + const uint8_t *src, + unsigned i, unsigned j); + + /** + * Unpack pixels to Z32_UNORM. + * Note: strides are in bytes. + * + * Only defined for depth formats. + */ + void + (*unpack_z_32unorm)(uint32_t *dst, unsigned dst_stride, + const uint8_t *src, unsigned src_stride, + unsigned width, unsigned height); + + /** + * Pack pixels from Z32_FLOAT. + * Note: strides are in bytes. + * + * Only defined for depth formats. + */ + void + (*pack_z_32unorm)(uint8_t *dst, unsigned dst_stride, + const uint32_t *src, unsigned src_stride, + unsigned width, unsigned height); + + /** + * Unpack pixels to Z32_FLOAT. + * Note: strides are in bytes. + * + * Only defined for depth formats. + */ + void + (*unpack_z_float)(float *dst, unsigned dst_stride, + const uint8_t *src, unsigned src_stride, + unsigned width, unsigned height); + + /** + * Pack pixels from Z32_FLOAT. + * Note: strides are in bytes. + * + * Only defined for depth formats. + */ + void + (*pack_z_float)(uint8_t *dst, unsigned dst_stride, + const float *src, unsigned src_stride, + unsigned width, unsigned height); + + /** + * Unpack pixels to S8_USCALED. + * Note: strides are in bytes. + * + * Only defined for stencil formats. + */ + void + (*unpack_s_8uscaled)(uint8_t *dst, unsigned dst_stride, + const uint8_t *src, unsigned src_stride, + unsigned width, unsigned height); + + /** + * Pack pixels from S8_USCALED. + * Note: strides are in bytes. + * + * Only defined for stencil formats. + */ + void + (*pack_s_8uscaled)(uint8_t *dst, unsigned dst_stride, + const uint8_t *src, unsigned src_stride, + unsigned width, unsigned height); + +}; + + +extern const struct util_format_description +util_format_description_table[]; + + +const struct util_format_description * +util_format_description(enum pipe_format format); + + +/* + * Format query functions. + */ + +static INLINE const char * +util_format_name(enum pipe_format format) +{ + const struct util_format_description *desc = util_format_description(format); + + assert(desc); + if (!desc) { + return "PIPE_FORMAT_???"; + } + + return desc->name; +} + +static INLINE const char * +util_format_short_name(enum pipe_format format) +{ + const struct util_format_description *desc = util_format_description(format); + + assert(desc); + if (!desc) { + return "???"; + } + + return desc->short_name; +} + +/** + * Whether this format is plain, see UTIL_FORMAT_LAYOUT_PLAIN for more info. + */ +static INLINE boolean +util_format_is_plain(enum pipe_format format) +{ + const struct util_format_description *desc = util_format_description(format); + + if (!format) { + return FALSE; + } + + return desc->layout == UTIL_FORMAT_LAYOUT_PLAIN ? TRUE : FALSE; +} + +static INLINE boolean +util_format_is_compressed(enum pipe_format format) +{ + const struct util_format_description *desc = util_format_description(format); + + assert(desc); + if (!desc) { + return FALSE; + } + + switch (desc->layout) { + case UTIL_FORMAT_LAYOUT_S3TC: + case UTIL_FORMAT_LAYOUT_RGTC: + /* XXX add other formats in the future */ + return TRUE; + default: + return FALSE; + } +} + +static INLINE boolean +util_format_is_s3tc(enum pipe_format format) +{ + const struct util_format_description *desc = util_format_description(format); + + assert(desc); + if (!desc) { + return FALSE; + } + + return desc->layout == UTIL_FORMAT_LAYOUT_S3TC ? TRUE : FALSE; +} + +static INLINE boolean +util_format_is_depth_or_stencil(enum pipe_format format) +{ + const struct util_format_description *desc = util_format_description(format); + + assert(desc); + if (!desc) { + return FALSE; + } + + return desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS ? TRUE : FALSE; +} + +static INLINE boolean +util_format_is_depth_and_stencil(enum pipe_format format) +{ + const struct util_format_description *desc = util_format_description(format); + + assert(desc); + if (!desc) { + return FALSE; + } + + if (desc->colorspace != UTIL_FORMAT_COLORSPACE_ZS) { + return FALSE; + } + + return (desc->swizzle[0] != UTIL_FORMAT_SWIZZLE_NONE && + desc->swizzle[1] != UTIL_FORMAT_SWIZZLE_NONE) ? TRUE : FALSE; +} + + +/** + * Give the RGBA colormask of the channels that can be represented in this + * format. + * + * That is, the channels whose values are preserved. + */ +static INLINE unsigned +util_format_colormask(const struct util_format_description *desc) +{ + unsigned colormask; + unsigned chan; + + switch (desc->colorspace) { + case UTIL_FORMAT_COLORSPACE_RGB: + case UTIL_FORMAT_COLORSPACE_SRGB: + case UTIL_FORMAT_COLORSPACE_YUV: + colormask = 0; + for (chan = 0; chan < 4; ++chan) { + if (desc->swizzle[chan] < 4) { + colormask |= (1 << chan); + } + } + return colormask; + case UTIL_FORMAT_COLORSPACE_ZS: + return 0; + default: + assert(0); + return 0; + } +} + + +boolean +util_format_is_float(enum pipe_format format); + + +/** + * Whether the src format can be blitted to destation format with a simple + * memcpy. + */ +boolean +util_is_format_compatible(const struct util_format_description *src_desc, + const struct util_format_description *dst_desc); + +/** + * Whether the format is supported by Gallium for the given bindings. + * This covers S3TC textures and floating-point render targets. + */ +boolean +util_format_is_supported(enum pipe_format format, unsigned bind); + +/** + * 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. + */ +static INLINE uint +util_format_get_blocksizebits(enum pipe_format format) +{ + const struct util_format_description *desc = util_format_description(format); + + assert(desc); + if (!desc) { + return 0; + } + + return desc->block.bits; +} + +/** + * Return bytes per block (not pixel) for the given format. + */ +static INLINE uint +util_format_get_blocksize(enum pipe_format format) +{ + uint bits = util_format_get_blocksizebits(format); + + assert(bits % 8 == 0); + + return bits / 8; +} + +static INLINE uint +util_format_get_blockwidth(enum pipe_format format) +{ + const struct util_format_description *desc = util_format_description(format); + + assert(desc); + if (!desc) { + return 1; + } + + return desc->block.width; +} + +static INLINE uint +util_format_get_blockheight(enum pipe_format format) +{ + const struct util_format_description *desc = util_format_description(format); + + assert(desc); + if (!desc) { + return 1; + } + + return desc->block.height; +} + +static INLINE unsigned +util_format_get_nblocksx(enum pipe_format format, + unsigned x) +{ + unsigned blockwidth = util_format_get_blockwidth(format); + return (x + blockwidth - 1) / blockwidth; +} + +static INLINE unsigned +util_format_get_nblocksy(enum pipe_format format, + unsigned y) +{ + unsigned blockheight = util_format_get_blockheight(format); + return (y + blockheight - 1) / blockheight; +} + +static INLINE unsigned +util_format_get_nblocks(enum pipe_format format, + unsigned width, + unsigned height) +{ + return util_format_get_nblocksx(format, width) * util_format_get_nblocksy(format, height); +} + +static INLINE size_t +util_format_get_stride(enum pipe_format format, + unsigned width) +{ + return util_format_get_nblocksx(format, width) * util_format_get_blocksize(format); +} + +static INLINE size_t +util_format_get_2d_size(enum pipe_format format, + size_t stride, + unsigned height) +{ + return util_format_get_nblocksy(format, height) * stride; +} + +static INLINE uint +util_format_get_component_bits(enum pipe_format format, + enum util_format_colorspace colorspace, + uint component) +{ + const struct util_format_description *desc = util_format_description(format); + enum util_format_colorspace desc_colorspace; + + assert(format); + if (!format) { + return 0; + } + + assert(component < 4); + + /* Treat RGB and SRGB as equivalent. */ + if (colorspace == UTIL_FORMAT_COLORSPACE_SRGB) { + colorspace = UTIL_FORMAT_COLORSPACE_RGB; + } + if (desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB) { + desc_colorspace = UTIL_FORMAT_COLORSPACE_RGB; + } else { + desc_colorspace = desc->colorspace; + } + + if (desc_colorspace != colorspace) { + return 0; + } + + switch (desc->swizzle[component]) { + case UTIL_FORMAT_SWIZZLE_X: + return desc->channel[0].size; + case UTIL_FORMAT_SWIZZLE_Y: + return desc->channel[1].size; + case UTIL_FORMAT_SWIZZLE_Z: + return desc->channel[2].size; + case UTIL_FORMAT_SWIZZLE_W: + return desc->channel[3].size; + default: + return 0; + } +} + +static INLINE boolean +util_format_has_alpha(enum pipe_format format) +{ + const struct util_format_description *desc = util_format_description(format); + + assert(format); + if (!format) { + return FALSE; + } + + switch (desc->colorspace) { + case UTIL_FORMAT_COLORSPACE_RGB: + case UTIL_FORMAT_COLORSPACE_SRGB: + return desc->swizzle[3] != UTIL_FORMAT_SWIZZLE_1; + case UTIL_FORMAT_COLORSPACE_YUV: + return FALSE; + case UTIL_FORMAT_COLORSPACE_ZS: + return FALSE; + default: + assert(0); + return FALSE; + } +} + +/** + * Given a linear RGB colorspace format, return the corresponding SRGB + * format, or PIPE_FORMAT_NONE if none. + */ +static INLINE enum pipe_format +util_format_srgb(enum pipe_format format) +{ + switch (format) { + case PIPE_FORMAT_L8_UNORM: + return PIPE_FORMAT_L8_SRGB; + case PIPE_FORMAT_L8A8_UNORM: + return PIPE_FORMAT_L8A8_SRGB; + case PIPE_FORMAT_R8G8B8_UNORM: + return PIPE_FORMAT_R8G8B8_SRGB; + case PIPE_FORMAT_A8B8G8R8_UNORM: + return PIPE_FORMAT_A8B8G8R8_SRGB; + case PIPE_FORMAT_X8B8G8R8_UNORM: + return PIPE_FORMAT_X8B8G8R8_SRGB; + case PIPE_FORMAT_B8G8R8A8_UNORM: + return PIPE_FORMAT_B8G8R8A8_SRGB; + case PIPE_FORMAT_B8G8R8X8_UNORM: + return PIPE_FORMAT_B8G8R8X8_SRGB; + case PIPE_FORMAT_A8R8G8B8_UNORM: + return PIPE_FORMAT_A8R8G8B8_SRGB; + case PIPE_FORMAT_X8R8G8B8_UNORM: + return PIPE_FORMAT_X8R8G8B8_SRGB; + case PIPE_FORMAT_DXT1_RGB: + return PIPE_FORMAT_DXT1_SRGB; + case PIPE_FORMAT_DXT1_RGBA: + return PIPE_FORMAT_DXT1_SRGBA; + case PIPE_FORMAT_DXT3_RGBA: + return PIPE_FORMAT_DXT3_SRGBA; + case PIPE_FORMAT_DXT5_RGBA: + return PIPE_FORMAT_DXT5_SRGBA; + default: + return PIPE_FORMAT_NONE; + } +} + +/** + * Given an sRGB format, return the corresponding linear colorspace format. + * For non sRGB formats, return the format unchanged. + */ +static INLINE enum pipe_format +util_format_linear(enum pipe_format format) +{ + switch (format) { + case PIPE_FORMAT_L8_SRGB: + return PIPE_FORMAT_L8_UNORM; + case PIPE_FORMAT_L8A8_SRGB: + return PIPE_FORMAT_L8A8_UNORM; + case PIPE_FORMAT_R8G8B8_SRGB: + return PIPE_FORMAT_R8G8B8_UNORM; + case PIPE_FORMAT_A8B8G8R8_SRGB: + return PIPE_FORMAT_A8B8G8R8_UNORM; + case PIPE_FORMAT_X8B8G8R8_SRGB: + return PIPE_FORMAT_X8B8G8R8_UNORM; + case PIPE_FORMAT_B8G8R8A8_SRGB: + return PIPE_FORMAT_B8G8R8A8_UNORM; + case PIPE_FORMAT_B8G8R8X8_SRGB: + return PIPE_FORMAT_B8G8R8X8_UNORM; + case PIPE_FORMAT_A8R8G8B8_SRGB: + return PIPE_FORMAT_A8R8G8B8_UNORM; + case PIPE_FORMAT_X8R8G8B8_SRGB: + return PIPE_FORMAT_X8R8G8B8_UNORM; + case PIPE_FORMAT_DXT1_SRGB: + return PIPE_FORMAT_DXT1_RGB; + case PIPE_FORMAT_DXT1_SRGBA: + return PIPE_FORMAT_DXT1_RGBA; + case PIPE_FORMAT_DXT3_SRGBA: + return PIPE_FORMAT_DXT3_RGBA; + case PIPE_FORMAT_DXT5_SRGBA: + return PIPE_FORMAT_DXT5_RGBA; + default: + return format; + } +} + +/** + * Return the number of components stored. + * Formats with block size != 1x1 will always have 1 component (the block). + */ +static INLINE unsigned +util_format_get_nr_components(enum pipe_format format) +{ + const struct util_format_description *desc = util_format_description(format); + return desc->nr_channels; +} + +/* + * Format access functions. + */ + +void +util_format_read_4f(enum pipe_format format, + float *dst, unsigned dst_stride, + const void *src, unsigned src_stride, + unsigned x, unsigned y, unsigned w, unsigned h); + +void +util_format_write_4f(enum pipe_format format, + const float *src, unsigned src_stride, + void *dst, unsigned dst_stride, + unsigned x, unsigned y, unsigned w, unsigned h); + +void +util_format_read_4ub(enum pipe_format format, + uint8_t *dst, unsigned dst_stride, + const void *src, unsigned src_stride, + unsigned x, unsigned y, unsigned w, unsigned h); + +void +util_format_write_4ub(enum pipe_format format, + const uint8_t *src, unsigned src_stride, + void *dst, unsigned dst_stride, + unsigned x, unsigned y, unsigned w, unsigned h); + +/* + * Generic format conversion; + */ + +boolean +util_format_fits_8unorm(const struct util_format_description *format_desc); + +void +util_format_translate(enum pipe_format dst_format, + void *dst, unsigned dst_stride, + unsigned dst_x, unsigned dst_y, + enum pipe_format src_format, + const void *src, unsigned src_stride, + unsigned src_x, unsigned src_y, + unsigned width, unsigned height); + +/* + * Swizzle operations. + */ + +/* Compose two sets of swizzles. + * If V is a 4D vector and the function parameters represent functions that + * swizzle vector components, this holds: + * swz2(swz1(V)) = dst(V) + */ +void util_format_compose_swizzles(const unsigned char swz1[4], + const unsigned char swz2[4], + unsigned char dst[4]); + +void util_format_swizzle_4f(float *dst, const float *src, + const unsigned char swz[4]); + +void util_format_unswizzle_4f(float *dst, const float *src, + const unsigned char swz[4]); + +#ifdef __cplusplus +} // extern "C" { +#endif + +#endif /* ! U_FORMAT_H */ diff --git a/mesalib/src/glsl/ir_function.cpp b/mesalib/src/glsl/ir_function.cpp index 6cfc32cc2..2a4de5b0d 100644 --- a/mesalib/src/glsl/ir_function.cpp +++ b/mesalib/src/glsl/ir_function.cpp @@ -37,14 +37,6 @@ typedef enum { * \param list_b Actual parameters passed to the function. * \see matching_signature() */ - -/** - * \brief Check if two parameter lists match. - * - * \param list_a Parameters of the function definition. - * \param list_b Actual parameters passed to the function. - * \see matching_signature() - */ static parameter_list_match_t parameter_lists_match(const exec_list *list_a, const exec_list *list_b) { diff --git a/mesalib/src/glsl/ir_function_detect_recursion.cpp b/mesalib/src/glsl/ir_function_detect_recursion.cpp index 44a1cd0b9..8f805bf1b 100644 --- a/mesalib/src/glsl/ir_function_detect_recursion.cpp +++ b/mesalib/src/glsl/ir_function_detect_recursion.cpp @@ -125,6 +125,7 @@ #include "glsl_parser_extras.h" #include "linker.h" #include "program/hash_table.h" +#include "program.h" struct call_node : public exec_node { class function *func; @@ -311,9 +312,7 @@ emit_errors_linked(const void *key, void *data, void *closure) f->sig->function_name(), &f->sig->parameters); - linker_error_printf(prog, - "function `%s' has static recursion.\n", - proto); + linker_error(prog, "function `%s' has static recursion.\n", proto); ralloc_free(proto); prog->LinkStatus = false; } diff --git a/mesalib/src/glsl/link_functions.cpp b/mesalib/src/glsl/link_functions.cpp index e7713b4bc..b3a701858 100644 --- a/mesalib/src/glsl/link_functions.cpp +++ b/mesalib/src/glsl/link_functions.cpp @@ -91,8 +91,8 @@ public: if (sig == NULL) {
/* FINISHME: Log the full signature of unresolved function.
*/
- linker_error_printf(this->prog, "unresolved reference to function "
- "`%s'\n", name);
+ linker_error(this->prog, "unresolved reference to function `%s'\n",
+ name);
this->success = false;
return visit_stop;
}
diff --git a/mesalib/src/glsl/linker.cpp b/mesalib/src/glsl/linker.cpp index cfadfd5e3..cb4083b29 100644 --- a/mesalib/src/glsl/linker.cpp +++ b/mesalib/src/glsl/linker.cpp @@ -164,7 +164,7 @@ private: void
-linker_error_printf(gl_shader_program *prog, const char *fmt, ...)
+linker_error(gl_shader_program *prog, const char *fmt, ...)
{
va_list ap;
@@ -172,6 +172,21 @@ linker_error_printf(gl_shader_program *prog, const char *fmt, ...) va_start(ap, fmt);
ralloc_vasprintf_append(&prog->InfoLog, fmt, ap);
va_end(ap);
+
+ prog->LinkStatus = false;
+}
+
+
+void
+linker_warning(gl_shader_program *prog, const char *fmt, ...)
+{
+ va_list ap;
+
+ ralloc_strcat(&prog->InfoLog, "error: ");
+ va_start(ap, fmt);
+ ralloc_vasprintf_append(&prog->InfoLog, fmt, ap);
+ va_end(ap);
+
}
@@ -243,8 +258,7 @@ validate_vertex_shader_executable(struct gl_shader_program *prog, find_assignment_visitor find("gl_Position");
find.run(shader->ir);
if (!find.variable_found()) {
- linker_error_printf(prog,
- "vertex shader does not write to `gl_Position'\n");
+ linker_error(prog, "vertex shader does not write to `gl_Position'\n");
return false;
}
@@ -271,8 +285,8 @@ validate_fragment_shader_executable(struct gl_shader_program *prog, frag_data.run(shader->ir);
if (frag_color.variable_found() && frag_data.variable_found()) {
- linker_error_printf(prog, "fragment shader writes to both "
- "`gl_FragColor' and `gl_FragData'\n");
+ linker_error(prog, "fragment shader writes to both "
+ "`gl_FragColor' and `gl_FragData'\n");
return false;
}
@@ -357,11 +371,11 @@ cross_validate_globals(struct gl_shader_program *prog, existing->type = var->type;
}
} else {
- linker_error_printf(prog, "%s `%s' declared as type "
- "`%s' and type `%s'\n",
- mode_string(var),
- var->name, var->type->name,
- existing->type->name);
+ linker_error(prog, "%s `%s' declared as type "
+ "`%s' and type `%s'\n",
+ mode_string(var),
+ var->name, var->type->name,
+ existing->type->name);
return false;
}
}
@@ -369,9 +383,9 @@ cross_validate_globals(struct gl_shader_program *prog, if (var->explicit_location) {
if (existing->explicit_location
&& (var->location != existing->location)) {
- linker_error_printf(prog, "explicit locations for %s "
- "`%s' have differing values\n",
- mode_string(var), var->name);
+ linker_error(prog, "explicit locations for %s "
+ "`%s' have differing values\n",
+ mode_string(var), var->name);
return false;
}
@@ -392,12 +406,12 @@ cross_validate_globals(struct gl_shader_program *prog, bool layout_declared = var->depth_layout != ir_depth_layout_none;
bool layout_differs = var->depth_layout != existing->depth_layout;
if (layout_declared && layout_differs) {
- linker_error_printf(prog,
+ linker_error(prog,
"All redeclarations of gl_FragDepth in all fragment shaders "
"in a single program must have the same set of qualifiers.");
}
if (var->used && layout_differs) {
- linker_error_printf(prog,
+ linker_error(prog,
"If gl_FragDepth is redeclared with a layout qualifier in"
"any fragment shader, it must be redeclared with the same"
"layout qualifier in all fragment shaders that have"
@@ -410,9 +424,9 @@ cross_validate_globals(struct gl_shader_program *prog, if (var->constant_value != NULL) {
if (existing->constant_value != NULL) {
if (!var->constant_value->has_value(existing->constant_value)) {
- linker_error_printf(prog, "initializers for %s "
- "`%s' have differing values\n",
- mode_string(var), var->name);
+ linker_error(prog, "initializers for %s "
+ "`%s' have differing values\n",
+ mode_string(var), var->name);
return false;
}
} else
@@ -433,15 +447,15 @@ cross_validate_globals(struct gl_shader_program *prog, }
if (existing->invariant != var->invariant) {
- linker_error_printf(prog, "declarations for %s `%s' have "
- "mismatching invariant qualifiers\n",
- mode_string(var), var->name);
+ linker_error(prog, "declarations for %s `%s' have "
+ "mismatching invariant qualifiers\n",
+ mode_string(var), var->name);
return false;
}
if (existing->centroid != var->centroid) {
- linker_error_printf(prog, "declarations for %s `%s' have "
- "mismatching centroid qualifiers\n",
- mode_string(var), var->name);
+ linker_error(prog, "declarations for %s `%s' have "
+ "mismatching centroid qualifiers\n",
+ mode_string(var), var->name);
return false;
}
} else
@@ -529,13 +543,12 @@ cross_validate_outputs_to_inputs(struct gl_shader_program *prog, */
if (!output->type->is_array()
|| (strncmp("gl_", output->name, 3) != 0)) {
- linker_error_printf(prog,
- "%s shader output `%s' declared as "
- "type `%s', but %s shader input declared "
- "as type `%s'\n",
- producer_stage, output->name,
- output->type->name,
- consumer_stage, input->type->name);
+ linker_error(prog,
+ "%s shader output `%s' declared as type `%s', "
+ "but %s shader input declared as type `%s'\n",
+ producer_stage, output->name,
+ output->type->name,
+ consumer_stage, input->type->name);
return false;
}
}
@@ -543,40 +556,40 @@ cross_validate_outputs_to_inputs(struct gl_shader_program *prog, /* Check that all of the qualifiers match between stages.
*/
if (input->centroid != output->centroid) {
- linker_error_printf(prog,
- "%s shader output `%s' %s centroid qualifier, "
- "but %s shader input %s centroid qualifier\n",
- producer_stage,
- output->name,
- (output->centroid) ? "has" : "lacks",
- consumer_stage,
- (input->centroid) ? "has" : "lacks");
+ linker_error(prog,
+ "%s shader output `%s' %s centroid qualifier, "
+ "but %s shader input %s centroid qualifier\n",
+ producer_stage,
+ output->name,
+ (output->centroid) ? "has" : "lacks",
+ consumer_stage,
+ (input->centroid) ? "has" : "lacks");
return false;
}
if (input->invariant != output->invariant) {
- linker_error_printf(prog,
- "%s shader output `%s' %s invariant qualifier, "
- "but %s shader input %s invariant qualifier\n",
- producer_stage,
- output->name,
- (output->invariant) ? "has" : "lacks",
- consumer_stage,
- (input->invariant) ? "has" : "lacks");
+ linker_error(prog,
+ "%s shader output `%s' %s invariant qualifier, "
+ "but %s shader input %s invariant qualifier\n",
+ producer_stage,
+ output->name,
+ (output->invariant) ? "has" : "lacks",
+ consumer_stage,
+ (input->invariant) ? "has" : "lacks");
return false;
}
if (input->interpolation != output->interpolation) {
- linker_error_printf(prog,
- "%s shader output `%s' specifies %s "
- "interpolation qualifier, "
- "but %s shader input specifies %s "
- "interpolation qualifier\n",
- producer_stage,
- output->name,
- output->interpolation_string(),
- consumer_stage,
- input->interpolation_string());
+ linker_error(prog,
+ "%s shader output `%s' specifies %s "
+ "interpolation qualifier, "
+ "but %s shader input specifies %s "
+ "interpolation qualifier\n",
+ producer_stage,
+ output->name,
+ output->interpolation_string(),
+ consumer_stage,
+ input->interpolation_string());
return false;
}
}
@@ -823,9 +836,8 @@ link_intrastage_shaders(void *mem_ctx, if ((other_sig != NULL) && other_sig->is_defined
&& !other_sig->is_builtin) {
- linker_error_printf(prog,
- "function `%s' is multiply defined",
- f->name);
+ linker_error(prog, "function `%s' is multiply defined",
+ f->name);
return NULL;
}
}
@@ -849,9 +861,9 @@ link_intrastage_shaders(void *mem_ctx, }
if (main == NULL) {
- linker_error_printf(prog, "%s shader lacks `main'\n",
- (shader_list[0]->Type == GL_VERTEX_SHADER)
- ? "vertex" : "fragment");
+ linker_error(prog, "%s shader lacks `main'\n",
+ (shader_list[0]->Type == GL_VERTEX_SHADER)
+ ? "vertex" : "fragment");
return NULL;
}
@@ -1309,10 +1321,10 @@ assign_attribute_or_color_locations(gl_shader_program *prog, * attribute overlaps any previously allocated bits.
*/
if ((~(use_mask << attr) & used_locations) != used_locations) {
- linker_error_printf(prog,
- "insufficient contiguous attribute locations "
- "available for vertex shader input `%s'",
- var->name);
+ linker_error(prog,
+ "insufficient contiguous attribute locations "
+ "available for vertex shader input `%s'",
+ var->name);
return false;
}
@@ -1353,11 +1365,10 @@ assign_attribute_or_color_locations(gl_shader_program *prog, if ((var->location >= (int)(max_index + generic_base))
|| (var->location < 0)) {
- linker_error_printf(prog,
- "invalid explicit location %d specified for "
- "`%s'\n",
- (var->location < 0) ? var->location : attr,
- var->name);
+ linker_error(prog,
+ "invalid explicit location %d specified for `%s'\n",
+ (var->location < 0) ? var->location : attr,
+ var->name);
return false;
} else if (var->location >= generic_base) {
used_locations |= (use_mask << attr);
@@ -1406,10 +1417,10 @@ assign_attribute_or_color_locations(gl_shader_program *prog, const char *const string = (target_index == MESA_SHADER_VERTEX)
? "vertex shader input" : "fragment shader output";
- linker_error_printf(prog,
- "insufficient contiguous attribute locations "
- "available for %s `%s'",
- string, to_assign[i].var->name);
+ linker_error(prog,
+ "insufficient contiguous attribute locations "
+ "available for %s `%s'",
+ string, to_assign[i].var->name);
return false;
}
@@ -1525,9 +1536,8 @@ assign_varying_locations(struct gl_context *ctx, * "glsl1-varying read but not written" in piglit.
*/
- linker_error_printf(prog, "fragment shader varying %s not written "
- "by vertex shader\n.", var->name);
- prog->LinkStatus = false;
+ linker_error(prog, "fragment shader varying %s not written "
+ "by vertex shader\n.", var->name);
}
/* An 'in' variable is only really a shader input if its
@@ -1544,17 +1554,17 @@ assign_varying_locations(struct gl_context *ctx, if (ctx->API == API_OPENGLES2 || prog->Version == 100) {
if (varying_vectors > ctx->Const.MaxVarying) {
- linker_error_printf(prog, "shader uses too many varying vectors "
- "(%u > %u)\n",
- varying_vectors, ctx->Const.MaxVarying);
+ linker_error(prog, "shader uses too many varying vectors "
+ "(%u > %u)\n",
+ varying_vectors, ctx->Const.MaxVarying);
return false;
}
} else {
const unsigned float_components = varying_vectors * 4;
if (float_components > ctx->Const.MaxVarying * 4) {
- linker_error_printf(prog, "shader uses too many varying components "
- "(%u > %u)\n",
- float_components, ctx->Const.MaxVarying * 4);
+ linker_error(prog, "shader uses too many varying components "
+ "(%u > %u)\n",
+ float_components, ctx->Const.MaxVarying * 4);
return false;
}
}
@@ -1618,8 +1628,8 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog) assert(max_version <= 130);
if ((max_version >= 130 || min_version == 100)
&& min_version != max_version) {
- linker_error_printf(prog, "all shaders must use same shading "
- "language version\n");
+ linker_error(prog, "all shaders must use same shading "
+ "language version\n");
goto done;
}
@@ -1720,12 +1730,10 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog) * FINISHME: at least 16, so hardcode 16 for now.
*/
if (!assign_attribute_or_color_locations(prog, MESA_SHADER_VERTEX, 16)) {
- prog->LinkStatus = false;
goto done;
}
if (!assign_attribute_or_color_locations(prog, MESA_SHADER_FRAGMENT, ctx->Const.MaxDrawBuffers)) {
- prog->LinkStatus = false;
goto done;
}
@@ -1742,7 +1750,6 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog) if (!assign_varying_locations(ctx, prog,
prog->_LinkedShaders[prev],
prog->_LinkedShaders[i])) {
- prog->LinkStatus = false;
goto done;
}
@@ -1774,11 +1781,9 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog) */
if (ctx->API == API_OPENGLES2 || prog->Version == 100) {
if (prog->_LinkedShaders[MESA_SHADER_VERTEX] == NULL) {
- linker_error_printf(prog, "program lacks a vertex shader\n");
- prog->LinkStatus = false;
+ linker_error(prog, "program lacks a vertex shader\n");
} else if (prog->_LinkedShaders[MESA_SHADER_FRAGMENT] == NULL) {
- linker_error_printf(prog, "program lacks a fragment shader\n");
- prog->LinkStatus = false;
+ linker_error(prog, "program lacks a fragment shader\n");
}
}
diff --git a/mesalib/src/glsl/linker.h b/mesalib/src/glsl/linker.h index a8ce16a7e..769cf68b6 100644 --- a/mesalib/src/glsl/linker.h +++ b/mesalib/src/glsl/linker.h @@ -25,9 +25,6 @@ #ifndef GLSL_LINKER_H #define GLSL_LINKER_H -extern void -linker_error_printf(gl_shader_program *prog, const char *fmt, ...); - extern bool link_function_calls(gl_shader_program *prog, gl_shader *main, gl_shader **shader_list, unsigned num_shaders); diff --git a/mesalib/src/glsl/main.cpp b/mesalib/src/glsl/main.cpp index 900879638..b368b3dbc 100644 --- a/mesalib/src/glsl/main.cpp +++ b/mesalib/src/glsl/main.cpp @@ -232,6 +232,7 @@ main(int argc, char **argv) whole_program = rzalloc (NULL, struct gl_shader_program);
assert(whole_program != NULL);
+ whole_program->InfoLog = ralloc_strdup(whole_program, "");
for (/* empty */; argc > optind; optind++) {
whole_program->Shaders =
diff --git a/mesalib/src/glsl/program.h b/mesalib/src/glsl/program.h index 6834b42f4..437ca1462 100644 --- a/mesalib/src/glsl/program.h +++ b/mesalib/src/glsl/program.h @@ -1,27 +1,35 @@ -/*
- * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
- * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
- * Copyright © 2010 Intel Corporation
- *
- * 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
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#include "main/core.h"
-
-extern void
-link_shaders(struct gl_context *ctx, struct gl_shader_program *prog);
+/* + * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. + * Copyright (C) 2009 VMware, Inc. All Rights Reserved. + * Copyright © 2010 Intel Corporation + * + * 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 + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "main/core.h" + +extern void +link_shaders(struct gl_context *ctx, struct gl_shader_program *prog); + +extern void +linker_error(gl_shader_program *prog, const char *fmt, ...) + PRINTFLIKE(2, 3); + +extern void +linker_warning(gl_shader_program *prog, const char *fmt, ...) + PRINTFLIKE(2, 3); diff --git a/mesalib/src/mesa/main/shaderobj.c b/mesalib/src/mesa/main/shaderobj.c index 67dd5c9aa..f128648f4 100644 --- a/mesalib/src/mesa/main/shaderobj.c +++ b/mesalib/src/mesa/main/shaderobj.c @@ -1,414 +1,415 @@ -/*
- * Mesa 3-D graphics library
- *
- * Copyright (C) 2004-2008 Brian Paul All Rights Reserved.
- * Copyright (C) 2009-2010 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, 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
- * BRIAN PAUL 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 shaderobj.c
- * \author Brian Paul
- *
- */
-
-
-#include "main/glheader.h"
-#include "main/context.h"
-#include "main/hash.h"
-#include "main/mfeatures.h"
-#include "main/mtypes.h"
-#include "main/shaderobj.h"
-#include "program/program.h"
-#include "program/prog_parameter.h"
-#include "program/prog_uniform.h"
-#include "ralloc.h"
-
-/**********************************************************************/
-/*** Shader object functions ***/
-/**********************************************************************/
-
-
-/**
- * Set ptr to point to sh.
- * If ptr is pointing to another shader, decrement its refcount (and delete
- * if refcount hits zero).
- * Then set ptr to point to sh, incrementing its refcount.
- */
-void
-_mesa_reference_shader(struct gl_context *ctx, struct gl_shader **ptr,
- struct gl_shader *sh)
-{
- assert(ptr);
- if (*ptr == sh) {
- /* no-op */
- return;
- }
- if (*ptr) {
- /* Unreference the old shader */
- GLboolean deleteFlag = GL_FALSE;
- struct gl_shader *old = *ptr;
-
- ASSERT(old->RefCount > 0);
- old->RefCount--;
- /*printf("SHADER DECR %p (%d) to %d\n",
- (void*) old, old->Name, old->RefCount);*/
- deleteFlag = (old->RefCount == 0);
-
- if (deleteFlag) {
- if (old->Name != 0)
- _mesa_HashRemove(ctx->Shared->ShaderObjects, old->Name);
- ctx->Driver.DeleteShader(ctx, old);
- }
-
- *ptr = NULL;
- }
- assert(!*ptr);
-
- if (sh) {
- /* reference new */
- sh->RefCount++;
- /*printf("SHADER INCR %p (%d) to %d\n",
- (void*) sh, sh->Name, sh->RefCount);*/
- *ptr = sh;
- }
-}
-
-void
-_mesa_init_shader(struct gl_context *ctx, struct gl_shader *shader)
-{
- shader->RefCount = 1;
-}
-
-/**
- * Allocate a new gl_shader object, initialize it.
- * Called via ctx->Driver.NewShader()
- */
-struct gl_shader *
-_mesa_new_shader(struct gl_context *ctx, GLuint name, GLenum type)
-{
- struct gl_shader *shader;
- assert(type == GL_FRAGMENT_SHADER || type == GL_VERTEX_SHADER ||
- type == GL_GEOMETRY_SHADER_ARB);
- shader = rzalloc(NULL, struct gl_shader);
- if (shader) {
- shader->Type = type;
- shader->Name = name;
- _mesa_init_shader(ctx, shader);
- }
- return shader;
-}
-
-
-/**
- * Delete a shader object.
- * Called via ctx->Driver.DeleteShader().
- */
-static void
-_mesa_delete_shader(struct gl_context *ctx, struct gl_shader *sh)
-{
- if (sh->Source)
- free((void *) sh->Source);
- _mesa_reference_program(ctx, &sh->Program, NULL);
- ralloc_free(sh);
-}
-
-
-/**
- * Lookup a GLSL shader object.
- */
-struct gl_shader *
-_mesa_lookup_shader(struct gl_context *ctx, GLuint name)
-{
- if (name) {
- struct gl_shader *sh = (struct gl_shader *)
- _mesa_HashLookup(ctx->Shared->ShaderObjects, name);
- /* Note that both gl_shader and gl_shader_program objects are kept
- * in the same hash table. Check the object's type to be sure it's
- * what we're expecting.
- */
- if (sh && sh->Type == GL_SHADER_PROGRAM_MESA) {
- return NULL;
- }
- return sh;
- }
- return NULL;
-}
-
-
-/**
- * As above, but record an error if shader is not found.
- */
-struct gl_shader *
-_mesa_lookup_shader_err(struct gl_context *ctx, GLuint name, const char *caller)
-{
- if (!name) {
- _mesa_error(ctx, GL_INVALID_VALUE, "%s", caller);
- return NULL;
- }
- else {
- struct gl_shader *sh = (struct gl_shader *)
- _mesa_HashLookup(ctx->Shared->ShaderObjects, name);
- if (!sh) {
- _mesa_error(ctx, GL_INVALID_VALUE, "%s", caller);
- return NULL;
- }
- if (sh->Type == GL_SHADER_PROGRAM_MESA) {
- _mesa_error(ctx, GL_INVALID_OPERATION, "%s", caller);
- return NULL;
- }
- return sh;
- }
-}
-
-
-
-/**********************************************************************/
-/*** Shader Program object functions ***/
-/**********************************************************************/
-
-
-/**
- * Set ptr to point to shProg.
- * If ptr is pointing to another object, decrement its refcount (and delete
- * if refcount hits zero).
- * Then set ptr to point to shProg, incrementing its refcount.
- */
-void
-_mesa_reference_shader_program(struct gl_context *ctx,
- struct gl_shader_program **ptr,
- struct gl_shader_program *shProg)
-{
- assert(ptr);
- if (*ptr == shProg) {
- /* no-op */
- return;
- }
- if (*ptr) {
- /* Unreference the old shader program */
- GLboolean deleteFlag = GL_FALSE;
- struct gl_shader_program *old = *ptr;
-
- ASSERT(old->RefCount > 0);
- old->RefCount--;
-#if 0
- printf("ShaderProgram %p ID=%u RefCount-- to %d\n",
- (void *) old, old->Name, old->RefCount);
-#endif
- deleteFlag = (old->RefCount == 0);
-
- if (deleteFlag) {
- if (old->Name != 0)
- _mesa_HashRemove(ctx->Shared->ShaderObjects, old->Name);
- ctx->Driver.DeleteShaderProgram(ctx, old);
- }
-
- *ptr = NULL;
- }
- assert(!*ptr);
-
- if (shProg) {
- shProg->RefCount++;
-#if 0
- printf("ShaderProgram %p ID=%u RefCount++ to %d\n",
- (void *) shProg, shProg->Name, shProg->RefCount);
-#endif
- *ptr = shProg;
- }
-}
-
-void
-_mesa_init_shader_program(struct gl_context *ctx, struct gl_shader_program *prog)
-{
- prog->Type = GL_SHADER_PROGRAM_MESA;
- prog->RefCount = 1;
- prog->Attributes = _mesa_new_parameter_list();
-#if FEATURE_ARB_geometry_shader4
- prog->Geom.VerticesOut = 0;
- prog->Geom.InputType = GL_TRIANGLES;
- prog->Geom.OutputType = GL_TRIANGLE_STRIP;
-#endif
-}
-
-/**
- * Allocate a new gl_shader_program object, initialize it.
- * Called via ctx->Driver.NewShaderProgram()
- */
-static struct gl_shader_program *
-_mesa_new_shader_program(struct gl_context *ctx, GLuint name)
-{
- struct gl_shader_program *shProg;
- shProg = rzalloc(NULL, struct gl_shader_program);
- if (shProg) {
- shProg->Name = name;
- _mesa_init_shader_program(ctx, shProg);
- }
- return shProg;
-}
-
-
-/**
- * Clear (free) the shader program state that gets produced by linking.
- */
-void
-_mesa_clear_shader_program_data(struct gl_context *ctx,
- struct gl_shader_program *shProg)
-{
- _mesa_reference_vertprog(ctx, &shProg->VertexProgram, NULL);
- _mesa_reference_fragprog(ctx, &shProg->FragmentProgram, NULL);
- _mesa_reference_geomprog(ctx, &shProg->GeometryProgram, NULL);
-
- if (shProg->Uniforms) {
- _mesa_free_uniform_list(shProg->Uniforms);
- shProg->Uniforms = NULL;
- }
-
- if (shProg->Varying) {
- _mesa_free_parameter_list(shProg->Varying);
- shProg->Varying = NULL;
- }
-}
-
-
-/**
- * Free all the data that hangs off a shader program object, but not the
- * object itself.
- */
-void
-_mesa_free_shader_program_data(struct gl_context *ctx,
- struct gl_shader_program *shProg)
-{
- GLuint i;
- gl_shader_type sh;
-
- assert(shProg->Type == GL_SHADER_PROGRAM_MESA);
-
- _mesa_clear_shader_program_data(ctx, shProg);
-
- if (shProg->Attributes) {
- _mesa_free_parameter_list(shProg->Attributes);
- shProg->Attributes = NULL;
- }
-
- /* detach shaders */
- for (i = 0; i < shProg->NumShaders; i++) {
- _mesa_reference_shader(ctx, &shProg->Shaders[i], NULL);
- }
- shProg->NumShaders = 0;
-
- if (shProg->Shaders) {
- free(shProg->Shaders);
- shProg->Shaders = NULL;
- }
-
- if (shProg->InfoLog) {
- ralloc_free(shProg->InfoLog);
- shProg->InfoLog = NULL;
- }
-
- /* Transform feedback varying vars */
- for (i = 0; i < shProg->TransformFeedback.NumVarying; i++) {
- free(shProg->TransformFeedback.VaryingNames[i]);
- }
- free(shProg->TransformFeedback.VaryingNames);
- shProg->TransformFeedback.VaryingNames = NULL;
- shProg->TransformFeedback.NumVarying = 0;
-
-
- for (sh = 0; sh < MESA_SHADER_TYPES; sh++) {
- if (shProg->_LinkedShaders[sh] != NULL) {
- ctx->Driver.DeleteShader(ctx, shProg->_LinkedShaders[sh]);
- shProg->_LinkedShaders[sh] = NULL;
- }
- }
-}
-
-
-/**
- * Free/delete a shader program object.
- * Called via ctx->Driver.DeleteShaderProgram().
- */
-static void
-_mesa_delete_shader_program(struct gl_context *ctx, struct gl_shader_program *shProg)
-{
- _mesa_free_shader_program_data(ctx, shProg);
-
- ralloc_free(shProg);
-}
-
-
-/**
- * Lookup a GLSL program object.
- */
-struct gl_shader_program *
-_mesa_lookup_shader_program(struct gl_context *ctx, GLuint name)
-{
- struct gl_shader_program *shProg;
- if (name) {
- shProg = (struct gl_shader_program *)
- _mesa_HashLookup(ctx->Shared->ShaderObjects, name);
- /* Note that both gl_shader and gl_shader_program objects are kept
- * in the same hash table. Check the object's type to be sure it's
- * what we're expecting.
- */
- if (shProg && shProg->Type != GL_SHADER_PROGRAM_MESA) {
- return NULL;
- }
- return shProg;
- }
- return NULL;
-}
-
-
-/**
- * As above, but record an error if program is not found.
- */
-struct gl_shader_program *
-_mesa_lookup_shader_program_err(struct gl_context *ctx, GLuint name,
- const char *caller)
-{
- if (!name) {
- _mesa_error(ctx, GL_INVALID_VALUE, "%s", caller);
- return NULL;
- }
- else {
- struct gl_shader_program *shProg = (struct gl_shader_program *)
- _mesa_HashLookup(ctx->Shared->ShaderObjects, name);
- if (!shProg) {
- _mesa_error(ctx, GL_INVALID_VALUE, "%s", caller);
- return NULL;
- }
- if (shProg->Type != GL_SHADER_PROGRAM_MESA) {
- _mesa_error(ctx, GL_INVALID_OPERATION, "%s", caller);
- return NULL;
- }
- return shProg;
- }
-}
-
-
-void
-_mesa_init_shader_object_functions(struct dd_function_table *driver)
-{
- driver->NewShader = _mesa_new_shader;
- driver->DeleteShader = _mesa_delete_shader;
- driver->NewShaderProgram = _mesa_new_shader_program;
- driver->DeleteShaderProgram = _mesa_delete_shader_program;
- driver->LinkShader = _mesa_ir_link_shader;
-}
+/* + * Mesa 3-D graphics library + * + * Copyright (C) 2004-2008 Brian Paul All Rights Reserved. + * Copyright (C) 2009-2010 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, 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 + * BRIAN PAUL 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 shaderobj.c + * \author Brian Paul + * + */ + + +#include "main/glheader.h" +#include "main/context.h" +#include "main/hash.h" +#include "main/mfeatures.h" +#include "main/mtypes.h" +#include "main/shaderobj.h" +#include "program/program.h" +#include "program/prog_parameter.h" +#include "program/prog_uniform.h" +#include "ralloc.h" + +/**********************************************************************/ +/*** Shader object functions ***/ +/**********************************************************************/ + + +/** + * Set ptr to point to sh. + * If ptr is pointing to another shader, decrement its refcount (and delete + * if refcount hits zero). + * Then set ptr to point to sh, incrementing its refcount. + */ +void +_mesa_reference_shader(struct gl_context *ctx, struct gl_shader **ptr, + struct gl_shader *sh) +{ + assert(ptr); + if (*ptr == sh) { + /* no-op */ + return; + } + if (*ptr) { + /* Unreference the old shader */ + GLboolean deleteFlag = GL_FALSE; + struct gl_shader *old = *ptr; + + ASSERT(old->RefCount > 0); + old->RefCount--; + /*printf("SHADER DECR %p (%d) to %d\n", + (void*) old, old->Name, old->RefCount);*/ + deleteFlag = (old->RefCount == 0); + + if (deleteFlag) { + if (old->Name != 0) + _mesa_HashRemove(ctx->Shared->ShaderObjects, old->Name); + ctx->Driver.DeleteShader(ctx, old); + } + + *ptr = NULL; + } + assert(!*ptr); + + if (sh) { + /* reference new */ + sh->RefCount++; + /*printf("SHADER INCR %p (%d) to %d\n", + (void*) sh, sh->Name, sh->RefCount);*/ + *ptr = sh; + } +} + +void +_mesa_init_shader(struct gl_context *ctx, struct gl_shader *shader) +{ + shader->RefCount = 1; +} + +/** + * Allocate a new gl_shader object, initialize it. + * Called via ctx->Driver.NewShader() + */ +struct gl_shader * +_mesa_new_shader(struct gl_context *ctx, GLuint name, GLenum type) +{ + struct gl_shader *shader; + assert(type == GL_FRAGMENT_SHADER || type == GL_VERTEX_SHADER || + type == GL_GEOMETRY_SHADER_ARB); + shader = rzalloc(NULL, struct gl_shader); + if (shader) { + shader->Type = type; + shader->Name = name; + _mesa_init_shader(ctx, shader); + } + return shader; +} + + +/** + * Delete a shader object. + * Called via ctx->Driver.DeleteShader(). + */ +static void +_mesa_delete_shader(struct gl_context *ctx, struct gl_shader *sh) +{ + if (sh->Source) + free((void *) sh->Source); + _mesa_reference_program(ctx, &sh->Program, NULL); + ralloc_free(sh); +} + + +/** + * Lookup a GLSL shader object. + */ +struct gl_shader * +_mesa_lookup_shader(struct gl_context *ctx, GLuint name) +{ + if (name) { + struct gl_shader *sh = (struct gl_shader *) + _mesa_HashLookup(ctx->Shared->ShaderObjects, name); + /* Note that both gl_shader and gl_shader_program objects are kept + * in the same hash table. Check the object's type to be sure it's + * what we're expecting. + */ + if (sh && sh->Type == GL_SHADER_PROGRAM_MESA) { + return NULL; + } + return sh; + } + return NULL; +} + + +/** + * As above, but record an error if shader is not found. + */ +struct gl_shader * +_mesa_lookup_shader_err(struct gl_context *ctx, GLuint name, const char *caller) +{ + if (!name) { + _mesa_error(ctx, GL_INVALID_VALUE, "%s", caller); + return NULL; + } + else { + struct gl_shader *sh = (struct gl_shader *) + _mesa_HashLookup(ctx->Shared->ShaderObjects, name); + if (!sh) { + _mesa_error(ctx, GL_INVALID_VALUE, "%s", caller); + return NULL; + } + if (sh->Type == GL_SHADER_PROGRAM_MESA) { + _mesa_error(ctx, GL_INVALID_OPERATION, "%s", caller); + return NULL; + } + return sh; + } +} + + + +/**********************************************************************/ +/*** Shader Program object functions ***/ +/**********************************************************************/ + + +/** + * Set ptr to point to shProg. + * If ptr is pointing to another object, decrement its refcount (and delete + * if refcount hits zero). + * Then set ptr to point to shProg, incrementing its refcount. + */ +void +_mesa_reference_shader_program(struct gl_context *ctx, + struct gl_shader_program **ptr, + struct gl_shader_program *shProg) +{ + assert(ptr); + if (*ptr == shProg) { + /* no-op */ + return; + } + if (*ptr) { + /* Unreference the old shader program */ + GLboolean deleteFlag = GL_FALSE; + struct gl_shader_program *old = *ptr; + + ASSERT(old->RefCount > 0); + old->RefCount--; +#if 0 + printf("ShaderProgram %p ID=%u RefCount-- to %d\n", + (void *) old, old->Name, old->RefCount); +#endif + deleteFlag = (old->RefCount == 0); + + if (deleteFlag) { + if (old->Name != 0) + _mesa_HashRemove(ctx->Shared->ShaderObjects, old->Name); + ctx->Driver.DeleteShaderProgram(ctx, old); + } + + *ptr = NULL; + } + assert(!*ptr); + + if (shProg) { + shProg->RefCount++; +#if 0 + printf("ShaderProgram %p ID=%u RefCount++ to %d\n", + (void *) shProg, shProg->Name, shProg->RefCount); +#endif + *ptr = shProg; + } +} + +void +_mesa_init_shader_program(struct gl_context *ctx, struct gl_shader_program *prog) +{ + prog->Type = GL_SHADER_PROGRAM_MESA; + prog->RefCount = 1; + prog->Attributes = _mesa_new_parameter_list(); +#if FEATURE_ARB_geometry_shader4 + prog->Geom.VerticesOut = 0; + prog->Geom.InputType = GL_TRIANGLES; + prog->Geom.OutputType = GL_TRIANGLE_STRIP; +#endif + + prog->InfoLog = ralloc_strdup(prog, ""); +} + +/** + * Allocate a new gl_shader_program object, initialize it. + * Called via ctx->Driver.NewShaderProgram() + */ +static struct gl_shader_program * +_mesa_new_shader_program(struct gl_context *ctx, GLuint name) +{ + struct gl_shader_program *shProg; + shProg = rzalloc(NULL, struct gl_shader_program); + if (shProg) { + shProg->Name = name; + _mesa_init_shader_program(ctx, shProg); + } + return shProg; +} + + +/** + * Clear (free) the shader program state that gets produced by linking. + */ +void +_mesa_clear_shader_program_data(struct gl_context *ctx, + struct gl_shader_program *shProg) +{ + _mesa_reference_vertprog(ctx, &shProg->VertexProgram, NULL); + _mesa_reference_fragprog(ctx, &shProg->FragmentProgram, NULL); + _mesa_reference_geomprog(ctx, &shProg->GeometryProgram, NULL); + + if (shProg->Uniforms) { + _mesa_free_uniform_list(shProg->Uniforms); + shProg->Uniforms = NULL; + } + + if (shProg->Varying) { + _mesa_free_parameter_list(shProg->Varying); + shProg->Varying = NULL; + } + + assert(shProg->InfoLog != NULL); + ralloc_free(shProg->InfoLog); + shProg->InfoLog = ralloc_strdup(shProg, ""); +} + + +/** + * Free all the data that hangs off a shader program object, but not the + * object itself. + */ +void +_mesa_free_shader_program_data(struct gl_context *ctx, + struct gl_shader_program *shProg) +{ + GLuint i; + gl_shader_type sh; + + assert(shProg->Type == GL_SHADER_PROGRAM_MESA); + + _mesa_clear_shader_program_data(ctx, shProg); + + if (shProg->Attributes) { + _mesa_free_parameter_list(shProg->Attributes); + shProg->Attributes = NULL; + } + + /* detach shaders */ + for (i = 0; i < shProg->NumShaders; i++) { + _mesa_reference_shader(ctx, &shProg->Shaders[i], NULL); + } + shProg->NumShaders = 0; + + if (shProg->Shaders) { + free(shProg->Shaders); + shProg->Shaders = NULL; + } + + /* Transform feedback varying vars */ + for (i = 0; i < shProg->TransformFeedback.NumVarying; i++) { + free(shProg->TransformFeedback.VaryingNames[i]); + } + free(shProg->TransformFeedback.VaryingNames); + shProg->TransformFeedback.VaryingNames = NULL; + shProg->TransformFeedback.NumVarying = 0; + + + for (sh = 0; sh < MESA_SHADER_TYPES; sh++) { + if (shProg->_LinkedShaders[sh] != NULL) { + ctx->Driver.DeleteShader(ctx, shProg->_LinkedShaders[sh]); + shProg->_LinkedShaders[sh] = NULL; + } + } +} + + +/** + * Free/delete a shader program object. + * Called via ctx->Driver.DeleteShaderProgram(). + */ +static void +_mesa_delete_shader_program(struct gl_context *ctx, struct gl_shader_program *shProg) +{ + _mesa_free_shader_program_data(ctx, shProg); + + ralloc_free(shProg); +} + + +/** + * Lookup a GLSL program object. + */ +struct gl_shader_program * +_mesa_lookup_shader_program(struct gl_context *ctx, GLuint name) +{ + struct gl_shader_program *shProg; + if (name) { + shProg = (struct gl_shader_program *) + _mesa_HashLookup(ctx->Shared->ShaderObjects, name); + /* Note that both gl_shader and gl_shader_program objects are kept + * in the same hash table. Check the object's type to be sure it's + * what we're expecting. + */ + if (shProg && shProg->Type != GL_SHADER_PROGRAM_MESA) { + return NULL; + } + return shProg; + } + return NULL; +} + + +/** + * As above, but record an error if program is not found. + */ +struct gl_shader_program * +_mesa_lookup_shader_program_err(struct gl_context *ctx, GLuint name, + const char *caller) +{ + if (!name) { + _mesa_error(ctx, GL_INVALID_VALUE, "%s", caller); + return NULL; + } + else { + struct gl_shader_program *shProg = (struct gl_shader_program *) + _mesa_HashLookup(ctx->Shared->ShaderObjects, name); + if (!shProg) { + _mesa_error(ctx, GL_INVALID_VALUE, "%s", caller); + return NULL; + } + if (shProg->Type != GL_SHADER_PROGRAM_MESA) { + _mesa_error(ctx, GL_INVALID_OPERATION, "%s", caller); + return NULL; + } + return shProg; + } +} + + +void +_mesa_init_shader_object_functions(struct dd_function_table *driver) +{ + driver->NewShader = _mesa_new_shader; + driver->DeleteShader = _mesa_delete_shader; + driver->NewShaderProgram = _mesa_new_shader_program; + driver->DeleteShaderProgram = _mesa_delete_shader_program; + driver->LinkShader = _mesa_ir_link_shader; +} diff --git a/mesalib/src/mesa/program/ir_to_mesa.cpp b/mesalib/src/mesa/program/ir_to_mesa.cpp index f39fa37d5..a08aa0af8 100644 --- a/mesalib/src/mesa/program/ir_to_mesa.cpp +++ b/mesalib/src/mesa/program/ir_to_mesa.cpp @@ -331,20 +331,6 @@ dst_reg undef_dst = dst_reg(PROGRAM_UNDEFINED, SWIZZLE_NOOP); dst_reg address_reg = dst_reg(PROGRAM_ADDRESS, WRITEMASK_X);
-static void
-fail_link(struct gl_shader_program *prog, const char *fmt, ...) PRINTFLIKE(2, 3);
-
-static void
-fail_link(struct gl_shader_program *prog, const char *fmt, ...)
-{
- va_list args;
- va_start(args, fmt);
- ralloc_vasprintf_append(&prog->InfoLog, fmt, args);
- va_end(args);
-
- prog->LinkStatus = GL_FALSE;
-}
-
static int
swizzle_for_size(int size)
{
@@ -789,10 +775,11 @@ ir_to_mesa_visitor::visit(ir_variable *ir) if (storage->file == PROGRAM_TEMPORARY &&
dst.index != storage->index + (int) ir->num_state_slots) {
- fail_link(this->shader_program,
- "failed to load builtin uniform `%s' (%d/%d regs loaded)\n",
- ir->name, dst.index - storage->index,
- type_size(ir->type));
+ linker_error(this->shader_program,
+ "failed to load builtin uniform `%s' "
+ "(%d/%d regs loaded)\n",
+ ir->name, dst.index - storage->index,
+ type_size(ir->type));
}
}
}
@@ -2413,29 +2400,32 @@ check_resources(const struct gl_context *ctx, case GL_VERTEX_PROGRAM_ARB:
if (_mesa_bitcount(prog->SamplersUsed) >
ctx->Const.MaxVertexTextureImageUnits) {
- fail_link(shader_program, "Too many vertex shader texture samplers");
+ linker_error(shader_program,
+ "Too many vertex shader texture samplers");
}
if (prog->Parameters->NumParameters > MAX_UNIFORMS) {
- fail_link(shader_program, "Too many vertex shader constants");
+ linker_error(shader_program, "Too many vertex shader constants");
}
break;
case MESA_GEOMETRY_PROGRAM:
if (_mesa_bitcount(prog->SamplersUsed) >
ctx->Const.MaxGeometryTextureImageUnits) {
- fail_link(shader_program, "Too many geometry shader texture samplers");
+ linker_error(shader_program,
+ "Too many geometry shader texture samplers");
}
if (prog->Parameters->NumParameters >
MAX_GEOMETRY_UNIFORM_COMPONENTS / 4) {
- fail_link(shader_program, "Too many geometry shader constants");
+ linker_error(shader_program, "Too many geometry shader constants");
}
break;
case GL_FRAGMENT_PROGRAM_ARB:
if (_mesa_bitcount(prog->SamplersUsed) >
ctx->Const.MaxTextureImageUnits) {
- fail_link(shader_program, "Too many fragment shader texture samplers");
+ linker_error(shader_program,
+ "Too many fragment shader texture samplers");
}
if (prog->Parameters->NumParameters > MAX_UNIFORMS) {
- fail_link(shader_program, "Too many fragment shader constants");
+ linker_error(shader_program, "Too many fragment shader constants");
}
break;
default:
@@ -2550,9 +2540,10 @@ add_uniforms_to_parameters_list(struct gl_shader_program *shader_program, * from _mesa_add_uniform) has to match what the linker chose.
*/
if (index != parameter_index) {
- fail_link(shader_program, "Allocation of uniform `%s' to target "
- "failed (%d vs %d)\n",
- uniform->Name, index, parameter_index);
+ linker_error(shader_program,
+ "Allocation of uniform `%s' to target failed "
+ "(%d vs %d)\n",
+ uniform->Name, index, parameter_index);
}
}
}
@@ -2585,8 +2576,8 @@ set_uniform_initializer(struct gl_context *ctx, void *mem_ctx, int loc = _mesa_get_uniform_location(ctx, shader_program, name);
if (loc == -1) {
- fail_link(shader_program,
- "Couldn't find uniform for initializer %s\n", name);
+ linker_error(shader_program,
+ "Couldn't find uniform for initializer %s\n", name);
return;
}
@@ -2986,11 +2977,31 @@ get_mesa_program(struct gl_context *ctx, if (mesa_inst->SrcReg[src].RelAddr)
prog->IndirectRegisterFiles |= 1 << mesa_inst->SrcReg[src].File;
- if (options->EmitNoIfs && mesa_inst->Opcode == OPCODE_IF) {
- fail_link(shader_program, "Couldn't flatten if statement\n");
- }
-
switch (mesa_inst->Opcode) {
+ case OPCODE_IF:
+ if (options->EmitNoIfs) {
+ linker_warning(shader_program,
+ "Couldn't flatten if-statement. "
+ "This will likely result in software "
+ "rasterization.\n");
+ }
+ break;
+ case OPCODE_BGNLOOP:
+ if (options->EmitNoLoops) {
+ linker_warning(shader_program,
+ "Couldn't unroll loop. "
+ "This will likely result in software "
+ "rasterization.\n");
+ }
+ break;
+ case OPCODE_CONT:
+ if (options->EmitNoCont) {
+ linker_warning(shader_program,
+ "Couldn't lower continue-statement. "
+ "This will likely result in software "
+ "rasterization.\n");
+ }
+ break;
case OPCODE_BGNSUB:
inst->function->inst = i;
mesa_inst->Comment = strdup(inst->function->sig->function_name());
@@ -3258,7 +3269,7 @@ _mesa_glsl_link_shader(struct gl_context *ctx, struct gl_shader_program *prog) for (i = 0; i < prog->NumShaders; i++) {
if (!prog->Shaders[i]->CompileStatus) {
- fail_link(prog, "linking with uncompiled shader");
+ linker_error(prog, "linking with uncompiled shader");
prog->LinkStatus = GL_FALSE;
}
}
|