[Mesa-dev] [RFC 62/63] i965/formatquery: Add support for INTERNALFORMAT_PREFERRED query
Eduardo Lima Mitev
elima at igalia.com
Tue Jan 19 08:42:42 PST 2016
This pname is tricky. The spec states that an internal format should be
returned, that is compatible with the passed internal format, and has
at least the same precision. There is no clear API to resolve this.
The closest we have (and what other drivers (i.e, NVidia proprietary) do,
is to return the same internal format given as parameter. By now, this
patch will do the same, but will check first that the passed internal
format is supported by i965.
To check for support, we have 'brw_format_for_mesa_format'. But this
method expects a 'mesa_format', which takes a format type into
consideration. So, we must first come up with a generic type that is
suited for this internal format, then get a mesa_format and do the
validation.
The cleanest solution here is to add a method that does exactly what
the spec wants: a driver's preferred internal format from a given
internal format. But at this point we lack a clear view of what
defines this preference.
---
src/mesa/drivers/dri/i965/brw_formatquery.c | 35 +++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/src/mesa/drivers/dri/i965/brw_formatquery.c b/src/mesa/drivers/dri/i965/brw_formatquery.c
index 1bd212c..253e0f2 100644
--- a/src/mesa/drivers/dri/i965/brw_formatquery.c
+++ b/src/mesa/drivers/dri/i965/brw_formatquery.c
@@ -22,7 +22,9 @@
*/
#include "brw_context.h"
+#include "brw_state.h"
#include "main/formatquery.h"
+#include "main/glformats.h"
static size_t
brw_query_samples_for_format(struct gl_context *ctx, GLenum target,
@@ -85,6 +87,39 @@ brw_query_internal_format(struct gl_context *ctx, GLenum target,
break;
}
+ case GL_INTERNALFORMAT_PREFERRED: {
+ params[0] = GL_NONE;
+
+ /* We need to resolve an internal format that is compatible with
+ * the passed internal format, and is "optimal" to the driver. This is
+ * still poorly defined to us, so right now we just validate that the
+ * passed internal format is supported. If so, we return the same
+ * internal format, otherwise GL_NONE.
+ */
+
+ /* We need to "come up" with a type, to obtain a mesa_format out of
+ * the passed internal format. Here, we get one from the internal
+ * format itself, that is generic enough.
+ */
+ GLenum type;
+ if (_mesa_is_enum_format_unsigned_int(internalFormat))
+ type = GL_UNSIGNED_BYTE;
+ else if (_mesa_is_enum_format_signed_int(internalFormat))
+ type = GL_BYTE;
+ else
+ type = GL_FLOAT;
+
+ /* Get a mesa_format from the internal format. */
+ mesa_format mesa_format =
+ _mesa_format_from_format_and_type(internalFormat, type);
+ if (mesa_format < MESA_FORMAT_COUNT) {
+ uint32_t brw_format = brw_format_for_mesa_format(mesa_format);
+ if (brw_format != 0)
+ params[0] = internalFormat;
+ }
+ break;
+ }
+
default:
/* By default, we call the driver hook's fallback function from the frontend,
* which has generic implementation for all pnames.
--
2.5.3
More information about the mesa-dev
mailing list