pipeFormat = st_choose_format(st, intFormat, format, type,
st->internal_target, 0, 0,
- PIPE_BIND_SAMPLER_VIEW, FALSE);
+ PIPE_BIND_SAMPLER_VIEW,
+ false, false);
assert(pipeFormat != PIPE_FORMAT_NONE);
}
if (type == GL_DEPTH) {
srcFormat = st_choose_format(st, GL_DEPTH_COMPONENT, GL_NONE,
GL_NONE, st->internal_target, 0, 0,
- srcBind, FALSE);
+ srcBind, false, false);
}
else {
assert(type == GL_COLOR);
if (util_format_is_float(srcFormat)) {
srcFormat = st_choose_format(st, GL_RGBA32F, GL_NONE,
GL_NONE, st->internal_target, 0, 0,
- srcBind, FALSE);
+ srcBind, false, false);
}
else if (util_format_is_pure_sint(srcFormat)) {
srcFormat = st_choose_format(st, GL_RGBA32I, GL_NONE,
GL_NONE, st->internal_target, 0, 0,
- srcBind, FALSE);
+ srcBind, false, false);
}
else if (util_format_is_pure_uint(srcFormat)) {
srcFormat = st_choose_format(st, GL_RGBA32UI, GL_NONE,
GL_NONE, st->internal_target, 0, 0,
- srcBind, FALSE);
+ srcBind, false, false);
}
else if (util_format_is_snorm(srcFormat)) {
srcFormat = st_choose_format(st, GL_RGBA16_SNORM, GL_NONE,
GL_NONE, st->internal_target, 0, 0,
- srcBind, FALSE);
+ srcBind, false, false);
}
else {
srcFormat = st_choose_format(st, GL_RGBA, GL_NONE,
GL_NONE, st->internal_target, 0, 0,
- srcBind, FALSE);
+ srcBind, false, false);
}
}
return PIPE_FORMAT_NONE;
}
-
-struct exact_format_mapping
-{
- GLenum format;
- GLenum type;
- enum pipe_format pformat;
-};
-
-static const struct exact_format_mapping rgba8888_tbl[] =
-{
- { GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, PIPE_FORMAT_ABGR8888_UNORM },
- { GL_ABGR_EXT, GL_UNSIGNED_INT_8_8_8_8_REV, PIPE_FORMAT_ABGR8888_UNORM },
- { GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, PIPE_FORMAT_RGBA8888_UNORM },
- { GL_ABGR_EXT, GL_UNSIGNED_INT_8_8_8_8, PIPE_FORMAT_RGBA8888_UNORM },
- { GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, PIPE_FORMAT_ARGB8888_UNORM },
- { GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, PIPE_FORMAT_BGRA8888_UNORM },
- { GL_RGBA, GL_UNSIGNED_BYTE, PIPE_FORMAT_R8G8B8A8_UNORM },
- { GL_ABGR_EXT, GL_UNSIGNED_BYTE, PIPE_FORMAT_A8B8G8R8_UNORM },
- { GL_BGRA, GL_UNSIGNED_BYTE, PIPE_FORMAT_B8G8R8A8_UNORM },
- { 0, 0, 0 }
-};
-
-static const struct exact_format_mapping rgbx8888_tbl[] =
-{
- { GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, PIPE_FORMAT_XBGR8888_UNORM },
- { GL_ABGR_EXT, GL_UNSIGNED_INT_8_8_8_8_REV, PIPE_FORMAT_XBGR8888_UNORM },
- { GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, PIPE_FORMAT_RGBX8888_UNORM },
- { GL_ABGR_EXT, GL_UNSIGNED_INT_8_8_8_8, PIPE_FORMAT_RGBX8888_UNORM },
- { GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, PIPE_FORMAT_XRGB8888_UNORM },
- { GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, PIPE_FORMAT_BGRX8888_UNORM },
- { GL_RGBA, GL_UNSIGNED_BYTE, PIPE_FORMAT_R8G8B8X8_UNORM },
- { GL_ABGR_EXT, GL_UNSIGNED_BYTE, PIPE_FORMAT_X8B8G8R8_UNORM },
- { GL_BGRA, GL_UNSIGNED_BYTE, PIPE_FORMAT_B8G8R8X8_UNORM },
- { 0, 0, 0 }
-};
-
-
-/**
- * For unsized/base internal formats, we may choose a convenient effective
- * internal format for {format, type}. If one exists, return that, otherwise
- * return PIPE_FORMAT_NONE.
- */
-static enum pipe_format
-find_exact_format(GLint internalFormat, GLenum format, GLenum type)
-{
- uint i;
- const struct exact_format_mapping* tbl;
-
- if (format == GL_NONE || type == GL_NONE)
- return PIPE_FORMAT_NONE;
-
- switch (internalFormat) {
- case 4:
- case GL_RGBA:
- tbl = rgba8888_tbl;
- break;
- case 3:
- case GL_RGB:
- tbl = rgbx8888_tbl;
- break;
- default:
- return PIPE_FORMAT_NONE;
- }
-
- for (i = 0; tbl[i].format; i++)
- if (tbl[i].format == format && tbl[i].type == type)
- return tbl[i].pformat;
-
- return PIPE_FORMAT_NONE;
-}
-
-
/**
* Given an OpenGL internalFormat value for a texture or surface, return
* the best matching PIPE_FORMAT_x, or PIPE_FORMAT_NONE if there's no match.
GLenum format, GLenum type,
enum pipe_texture_target target, unsigned sample_count,
unsigned storage_sample_count,
- unsigned bindings, boolean allow_dxt)
+ unsigned bindings, bool swap_bytes, bool allow_dxt)
{
struct pipe_screen *screen = st->pipe->screen;
unsigned i;
return PIPE_FORMAT_NONE;
}
- /* search for exact matches */
- pf = find_exact_format(internalFormat, format, type);
- if (pf != PIPE_FORMAT_NONE &&
- screen->is_format_supported(screen, pf, target, sample_count,
- storage_sample_count, bindings)) {
- goto success;
+ /* If we have an unsized internalFormat, and the driver supports a format
+ * that exactly matches format/type such that we can just memcpy, pick that
+ * (unless the format wouldn't still be unorm, which is the expectation for
+ * unsized formats).
+ */
+ if (_mesa_is_enum_format_unsized(internalFormat) && format != 0 &&
+ _mesa_is_type_unsigned(type)) {
+ pf = st_choose_matching_format(st, bindings, format, type,
+ swap_bytes);
+
+ if (pf != PIPE_FORMAT_NONE &&
+ screen->is_format_supported(screen, pf, target, sample_count,
+ storage_sample_count, bindings) &&
+ _mesa_get_format_base_format(st_pipe_format_to_mesa_format(pf)) ==
+ internalFormat) {
+ goto success;
+ }
}
/* For an unsized GL_RGB but a 2_10_10_10 type, try to pick one of the
bindings = PIPE_BIND_RENDER_TARGET;
return st_choose_format(st, internalFormat, GL_NONE, GL_NONE,
PIPE_TEXTURE_2D, sample_count,
- storage_sample_count, bindings, FALSE);
+ storage_sample_count, bindings,
+ false, false);
}
}
pFormat = st_choose_format(st, internalFormat, format, type,
- pTarget, 0, 0, bindings, GL_TRUE);
+ pTarget, 0, 0, bindings,
+ ctx->Unpack.SwapBytes, true);
if (pFormat == PIPE_FORMAT_NONE && !is_renderbuffer) {
/* try choosing format again, this time without render target bindings */
pFormat = st_choose_format(st, internalFormat, format, type,
pTarget, 0, 0, PIPE_BIND_SAMPLER_VIEW,
- GL_TRUE);
+ ctx->Unpack.SwapBytes, true);
}
if (pFormat == PIPE_FORMAT_NONE) {
/* Set sample counts in descending order. */
for (i = 16; i > 1; i--) {
format = st_choose_format(st, internalFormat, GL_NONE, GL_NONE,
- PIPE_TEXTURE_2D, i, i, bind, FALSE);
+ PIPE_TEXTURE_2D, i, i, bind,
+ false, false);
if (format != PIPE_FORMAT_NONE) {
samples[num_sample_counts++] = i;
GL_NONE,
GL_NONE,
PIPE_TEXTURE_2D, 0, 0,
- bindings, FALSE);
+ bindings,
+ false, false);
if (pformat)
params[0] = internalFormat;
break;