X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fmain%2Fformats.c;h=cd9eb81852fbae6526e6cf7cf115dd5357c8e75f;hb=772b25e1f366edc857e77b8c1ccdc5297d82cc41;hp=329b795074570f4a5060ba69b1528d3e38c815aa;hpb=2d0c2952566810ef1b277b49b064f4874a973112;p=mesa.git diff --git a/src/mesa/main/formats.c b/src/mesa/main/formats.c index 329b7950745..cd9eb81852f 100644 --- a/src/mesa/main/formats.c +++ b/src/mesa/main/formats.c @@ -26,8 +26,7 @@ #include "imports.h" #include "formats.h" -#include "config.h" -#include "texstore.h" +#include "mfeatures.h" /** @@ -49,7 +48,7 @@ struct gl_format_info /** * Logical data type: one of GL_UNSIGNED_NORMALIZED, GL_SIGNED_NORMALED, - * GL_UNSIGNED_INT, GL_SIGNED_INT, GL_FLOAT. + * GL_UNSIGNED_INT, GL_INT, GL_FLOAT. */ GLenum DataType; @@ -321,6 +320,60 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ 1, 1, 2 /* BlockWidth/Height,Bytes */ }, + { + MESA_FORMAT_R8, + "MESA_FORMAT_R8", + GL_RED, + GL_UNSIGNED_NORMALIZED, + 8, 0, 0, 0, + 0, 0, 0, 0, 0, + 1, 1, 1 + }, + { + MESA_FORMAT_RG88, + "MESA_FORMAT_RG88", + GL_RG, + GL_UNSIGNED_NORMALIZED, + 8, 8, 0, 0, + 0, 0, 0, 0, 0, + 1, 1, 2 + }, + { + MESA_FORMAT_RG88_REV, + "MESA_FORMAT_RG88_REV", + GL_RG, + GL_UNSIGNED_NORMALIZED, + 8, 8, 0, 0, + 0, 0, 0, 0, 0, + 1, 1, 2 + }, + { + MESA_FORMAT_R16, + "MESA_FORMAT_R16", + GL_RED, + GL_UNSIGNED_NORMALIZED, + 16, 0, 0, 0, + 0, 0, 0, 0, 0, + 1, 1, 2 + }, + { + MESA_FORMAT_RG1616, + "MESA_FORMAT_RG1616", + GL_RG, + GL_UNSIGNED_NORMALIZED, + 16, 16, 0, 0, + 0, 0, 0, 0, 0, + 1, 1, 4 + }, + { + MESA_FORMAT_RG1616_REV, + "MESA_FORMAT_RG1616_REV", + GL_RG, + GL_UNSIGNED_NORMALIZED, + 16, 16, 0, 0, + 0, 0, 0, 0, 0, + 1, 1, 4 + }, { MESA_FORMAT_Z24_S8, /* Name */ "MESA_FORMAT_Z24_S8", /* StrName */ @@ -629,6 +682,66 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = 0, 16, 0, 0, 0, 1, 1, 2 }, + + /* unnormalized signed int formats */ + { + MESA_FORMAT_RGBA_INT8, + "MESA_FORMAT_RGBA_INT8", + GL_RGBA, + GL_INT, + 8, 8, 8, 8, + 0, 0, 0, 0, 0, + 1, 1, 4 + }, + { + MESA_FORMAT_RGBA_INT16, + "MESA_FORMAT_RGBA_INT16", + GL_RGBA, + GL_INT, + 16, 16, 16, 16, + 0, 0, 0, 0, 0, + 1, 1, 8 + }, + { + MESA_FORMAT_RGBA_INT32, + "MESA_FORMAT_RGBA_INT32", + GL_RGBA, + GL_INT, + 32, 32, 32, 32, + 0, 0, 0, 0, 0, + 1, 1, 16 + }, + + /* unnormalized unsigned int formats */ + { + MESA_FORMAT_RGBA_UINT8, + "MESA_FORMAT_RGBA_UINT8", + GL_RGBA, + GL_UNSIGNED_INT, + 8, 8, 8, 8, + 0, 0, 0, 0, 0, + 1, 1, 4 + }, + { + MESA_FORMAT_RGBA_UINT16, + "MESA_FORMAT_RGBA_UINT16", + GL_RGBA, + GL_UNSIGNED_INT, + 16, 16, 16, 16, + 0, 0, 0, 0, 0, + 1, 1, 8 + }, + { + MESA_FORMAT_RGBA_UINT32, + "MESA_FORMAT_RGBA_UINT32", + GL_RGBA, + GL_UNSIGNED_INT, + 32, 32, 32, 32, + 0, 0, 0, 0, 0, + 1, 1, 16 + }, + + { MESA_FORMAT_DUDV8, "MESA_FORMAT_DUDV8", @@ -638,6 +751,35 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = 0, 0, 0, 0, 0, 1, 1, 2 }, + + /* Signed 8 bits / channel */ + { + MESA_FORMAT_SIGNED_R8, /* Name */ + "MESA_FORMAT_SIGNED_R8", /* StrName */ + GL_RGBA, /* BaseFormat */ + GL_SIGNED_NORMALIZED, /* DataType */ + 8, 0, 0, 0, /* Red/Green/Blue/AlphaBits */ + 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ + 1, 1, 1 /* BlockWidth/Height,Bytes */ + }, + { + MESA_FORMAT_SIGNED_RG88, + "MESA_FORMAT_SIGNED_RG88", + GL_RGBA, + GL_SIGNED_NORMALIZED, + 8, 8, 0, 0, + 0, 0, 0, 0, 0, + 1, 1, 2 + }, + { + MESA_FORMAT_SIGNED_RGBX8888, + "MESA_FORMAT_SIGNED_RGBX8888", + GL_RGBA, + GL_SIGNED_NORMALIZED, + 8, 8, 8, 0, + 0, 0, 0, 0, 0, + 1, 1, 4 /* 4 bpp, but no alpha */ + }, { MESA_FORMAT_SIGNED_RGBA8888, "MESA_FORMAT_SIGNED_RGBA8888", @@ -656,6 +798,35 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = 0, 0, 0, 0, 0, 1, 1, 4 }, + + /* Signed 16 bits / channel */ + { + MESA_FORMAT_SIGNED_R_16, + "MESA_FORMAT_SIGNED_R_16", + GL_RGBA, + GL_SIGNED_NORMALIZED, + 16, 0, 0, 0, + 0, 0, 0, 0, 0, + 1, 1, 2 + }, + { + MESA_FORMAT_SIGNED_RG_16, + "MESA_FORMAT_SIGNED_RG_16", + GL_RGBA, + GL_SIGNED_NORMALIZED, + 16, 16, 0, 0, + 0, 0, 0, 0, 0, + 1, 1, 4 + }, + { + MESA_FORMAT_SIGNED_RGB_16, + "MESA_FORMAT_SIGNED_RGB_16", + GL_RGBA, + GL_SIGNED_NORMALIZED, + 16, 16, 16, 0, + 0, 0, 0, 0, 0, + 1, 1, 6 + }, { MESA_FORMAT_SIGNED_RGBA_16, "MESA_FORMAT_SIGNED_RGBA_16", @@ -664,6 +835,15 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = 16, 16, 16, 16, 0, 0, 0, 0, 0, 1, 1, 8 + }, + { + MESA_FORMAT_RGBA_16, + "MESA_FORMAT_RGBA_16", + GL_RGBA, + GL_UNSIGNED_NORMALIZED, + 16, 16, 16, 16, + 0, 0, 0, 0, 0, + 1, 1, 8 } }; @@ -765,6 +945,7 @@ _mesa_get_format_bits(gl_format format, GLenum pname) * GL_UNSIGNED_NORMALIZED = unsigned int representing [0,1] * GL_SIGNED_NORMALIZED = signed int representing [-1, 1] * GL_UNSIGNED_INT = an ordinary unsigned integer + * GL_INT = an ordinary signed integer * GL_FLOAT = an ordinary float */ GLenum @@ -814,6 +995,32 @@ _mesa_is_format_compressed(gl_format format) } +/** + * Determine if the given format represents a packed depth/stencil buffer. + */ +GLboolean +_mesa_is_format_packed_depth_stencil(gl_format format) +{ + const struct gl_format_info *info = _mesa_get_format_info(format); + + return info->BaseFormat == GL_DEPTH_STENCIL; +} + + +/** + * Is the given format a signed/unsigned integer color format? + */ +GLboolean +_mesa_is_format_integer_color(gl_format format) +{ + const struct gl_format_info *info = _mesa_get_format_info(format); + return (info->DataType == GL_INT || info->DataType == GL_UNSIGNED_INT) && + info->BaseFormat != GL_DEPTH_COMPONENT && + info->BaseFormat != GL_DEPTH_STENCIL && + info->BaseFormat != GL_STENCIL_INDEX; +} + + /** * Return color encoding for given format. * \return GL_LINEAR or GL_SRGB @@ -850,11 +1057,12 @@ _mesa_format_image_size(gl_format format, GLsizei width, const struct gl_format_info *info = _mesa_get_format_info(format); /* Strictly speaking, a conditional isn't needed here */ if (info->BlockWidth > 1 || info->BlockHeight > 1) { - /* compressed format */ + /* compressed format (2D only for now) */ const GLuint bw = info->BlockWidth, bh = info->BlockHeight; const GLuint wblocks = (width + bw - 1) / bw; const GLuint hblocks = (height + bh - 1) / bh; const GLuint sz = wblocks * hblocks * info->BytesPerBlock; + assert(depth == 1); return sz; } else { @@ -865,6 +1073,36 @@ _mesa_format_image_size(gl_format format, GLsizei width, } +/** + * Same as _mesa_format_image_size() but returns a 64-bit value to + * accomodate very large textures. + */ +uint64_t +_mesa_format_image_size64(gl_format format, GLsizei width, + GLsizei height, GLsizei depth) +{ + const struct gl_format_info *info = _mesa_get_format_info(format); + /* Strictly speaking, a conditional isn't needed here */ + if (info->BlockWidth > 1 || info->BlockHeight > 1) { + /* compressed format (2D only for now) */ + const uint64_t bw = info->BlockWidth, bh = info->BlockHeight; + const uint64_t wblocks = (width + bw - 1) / bw; + const uint64_t hblocks = (height + bh - 1) / bh; + const uint64_t sz = wblocks * hblocks * info->BytesPerBlock; + assert(depth == 1); + return sz; + } + else { + /* non-compressed */ + const uint64_t sz = ((uint64_t) width * + (uint64_t) height * + (uint64_t) depth * + info->BytesPerBlock); + return sz; + } +} + + GLint _mesa_format_row_stride(gl_format format, GLsizei width) @@ -910,6 +1148,7 @@ _mesa_test_formats(void) GLuint t = info->RedBits + info->GreenBits + info->BlueBits + info->AlphaBits; assert(t / 8 == info->BytesPerBlock); + (void) t; } } @@ -934,6 +1173,22 @@ _mesa_test_formats(void) assert(info->LuminanceBits == 0); assert(info->IntensityBits == 0); } + else if (info->BaseFormat == GL_RG) { + assert(info->RedBits > 0); + assert(info->GreenBits > 0); + assert(info->BlueBits == 0); + assert(info->AlphaBits == 0); + assert(info->LuminanceBits == 0); + assert(info->IntensityBits == 0); + } + else if (info->BaseFormat == GL_RED) { + assert(info->RedBits > 0); + assert(info->GreenBits == 0); + assert(info->BlueBits == 0); + assert(info->AlphaBits == 0); + assert(info->LuminanceBits == 0); + assert(info->IntensityBits == 0); + } else if (info->BaseFormat == GL_LUMINANCE) { assert(info->RedBits == 0); assert(info->GreenBits == 0); @@ -970,6 +1225,7 @@ _mesa_format_to_type_and_comps(gl_format format, case MESA_FORMAT_ARGB8888: case MESA_FORMAT_ARGB8888_REV: case MESA_FORMAT_XRGB8888: + case MESA_FORMAT_XRGB8888_REV: *datatype = GL_UNSIGNED_BYTE; *comps = 4; return; @@ -996,18 +1252,32 @@ _mesa_format_to_type_and_comps(gl_format format, *comps = 4; return; + case MESA_FORMAT_RGBA5551: + *datatype = GL_UNSIGNED_SHORT_5_5_5_1; + *comps = 4; + return; + case MESA_FORMAT_AL88: case MESA_FORMAT_AL88_REV: + case MESA_FORMAT_RG88: + case MESA_FORMAT_RG88_REV: *datatype = GL_UNSIGNED_BYTE; *comps = 2; return; case MESA_FORMAT_AL1616: case MESA_FORMAT_AL1616_REV: + case MESA_FORMAT_RG1616: + case MESA_FORMAT_RG1616_REV: *datatype = GL_UNSIGNED_SHORT; *comps = 2; return; + case MESA_FORMAT_R16: + *datatype = GL_UNSIGNED_SHORT; + *comps = 1; + return; + case MESA_FORMAT_RGB332: *datatype = GL_UNSIGNED_BYTE_3_3_2; *comps = 3; @@ -1017,6 +1287,8 @@ _mesa_format_to_type_and_comps(gl_format format, case MESA_FORMAT_L8: case MESA_FORMAT_I8: case MESA_FORMAT_CI8: + case MESA_FORMAT_R8: + case MESA_FORMAT_S8: *datatype = GL_UNSIGNED_BYTE; *comps = 1; return; @@ -1062,11 +1334,38 @@ _mesa_format_to_type_and_comps(gl_format format, *comps = 2; return; + case MESA_FORMAT_SIGNED_R8: + *datatype = GL_BYTE; + *comps = 1; + return; + case MESA_FORMAT_SIGNED_RG88: + *datatype = GL_BYTE; + *comps = 2; + return; case MESA_FORMAT_SIGNED_RGBA8888: case MESA_FORMAT_SIGNED_RGBA8888_REV: + case MESA_FORMAT_SIGNED_RGBX8888: *datatype = GL_BYTE; *comps = 4; return; + + case MESA_FORMAT_RGBA_16: + *datatype = GL_UNSIGNED_SHORT; + *comps = 4; + return; + + case MESA_FORMAT_SIGNED_R_16: + *datatype = GL_SHORT; + *comps = 1; + return; + case MESA_FORMAT_SIGNED_RG_16: + *datatype = GL_SHORT; + *comps = 2; + return; + case MESA_FORMAT_SIGNED_RGB_16: + *datatype = GL_SHORT; + *comps = 3; + return; case MESA_FORMAT_SIGNED_RGBA_16: *datatype = GL_SHORT; *comps = 4; @@ -1106,12 +1405,12 @@ _mesa_format_to_type_and_comps(gl_format format, case MESA_FORMAT_SRGBA_DXT1: case MESA_FORMAT_SRGBA_DXT3: case MESA_FORMAT_SRGBA_DXT5: +#endif #endif /* XXX generate error instead? */ *datatype = GL_UNSIGNED_BYTE; *comps = 0; return; -#endif case MESA_FORMAT_RGBA_FLOAT32: *datatype = GL_FLOAT; @@ -1150,8 +1449,43 @@ _mesa_format_to_type_and_comps(gl_format format, *comps = 1; return; + case MESA_FORMAT_RGBA_INT8: + *datatype = GL_BYTE; + *comps = 4; + return; + case MESA_FORMAT_RGBA_INT16: + *datatype = GL_SHORT; + *comps = 4; + return; + case MESA_FORMAT_RGBA_INT32: + *datatype = GL_INT; + *comps = 4; + return; + + /** + * \name Non-normalized unsigned integer formats. + */ + case MESA_FORMAT_RGBA_UINT8: + *datatype = GL_UNSIGNED_BYTE; + *comps = 4; + return; + case MESA_FORMAT_RGBA_UINT16: + *datatype = GL_UNSIGNED_SHORT; + *comps = 4; + return; + case MESA_FORMAT_RGBA_UINT32: + *datatype = GL_UNSIGNED_INT; + *comps = 4; + return; + + case MESA_FORMAT_NONE: + case MESA_FORMAT_COUNT: + /* For debug builds, warn if any formats are not handled */ +#ifndef DEBUG default: - _mesa_problem(NULL, "bad format in _mesa_format_to_type_and_comps"); +#endif + _mesa_problem(NULL, "bad format %s in _mesa_format_to_type_and_comps", + _mesa_get_format_name(format)); *datatype = 0; *comps = 1; }