[Mesa-dev] [PATCH 3/5] st/mesa: consolidate view format setup code
Brian Paul
brianp at vmware.com
Fri Sep 30 22:53:10 UTC 2016
Before, we had code to compute the sampler view's format spread across two
different functions: in update_single_texture() and
st_get_texture_sampler_view_from_stobj(). Now it's all in one new function.
Also, use _mesa_texture_base_format() to simplify the code.
---
src/mesa/state_tracker/st_atom_texture.c | 88 ++++++++++++++++++++------------
1 file changed, 54 insertions(+), 34 deletions(-)
diff --git a/src/mesa/state_tracker/st_atom_texture.c b/src/mesa/state_tracker/st_atom_texture.c
index 86f1c62..bfa16dc 100644
--- a/src/mesa/state_tracker/st_atom_texture.c
+++ b/src/mesa/state_tracker/st_atom_texture.c
@@ -271,6 +271,58 @@ last_layer(const struct st_texture_object *stObj)
return stObj->pt->array_size - 1;
}
+
+/**
+ * Determine the format for the texture sampler view.
+ */
+static enum pipe_format
+get_sampler_view_format(struct st_context *st,
+ const struct st_texture_object *stObj,
+ const struct gl_sampler_object *samp)
+{
+ enum pipe_format format;
+
+ if (stObj->base.Target == GL_TEXTURE_BUFFER) {
+ format =
+ st_mesa_format_to_pipe_format(st, stObj->base._BufferObjectFormat);
+ }
+ else {
+ format =
+ stObj->surface_based ? stObj->surface_format : stObj->pt->format;
+
+ if (util_format_is_depth_and_stencil(format)) {
+ if (stObj->base.StencilSampling) {
+ format = util_format_stencil_only(format);
+ }
+ else {
+ GLenum baseFormat = _mesa_texture_base_format(&stObj->base);
+ if (baseFormat == GL_STENCIL_INDEX) {
+ format = util_format_stencil_only(format);
+ }
+ }
+ }
+ else {
+ /* If sRGB decoding is off, use the linear format */
+ if (samp->sRGBDecode == GL_SKIP_DECODE_EXT) {
+ format = util_format_linear(format);
+ }
+
+ /* Use R8_UNORM for video formats */
+ switch (format) {
+ case PIPE_FORMAT_NV12:
+ case PIPE_FORMAT_IYUV:
+ format = PIPE_FORMAT_R8_UNORM;
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
+ return format;
+}
+
+
static struct pipe_sampler_view *
st_create_texture_sampler_view_from_stobj(struct st_context *st,
struct st_texture_object *stObj,
@@ -322,23 +374,13 @@ st_get_texture_sampler_view_from_stobj(struct st_context *st,
unsigned glsl_version)
{
struct pipe_sampler_view **sv;
- const struct st_texture_image *firstImage;
+
if (!stObj || !stObj->pt) {
return NULL;
}
sv = st_texture_get_sampler_view(st, stObj);
- if (util_format_is_depth_and_stencil(format)) {
- if (stObj->base.StencilSampling)
- format = util_format_stencil_only(format);
- else {
- firstImage = st_texture_image_const(_mesa_base_tex_image(&stObj->base));
- if (firstImage->base._BaseFormat == GL_STENCIL_INDEX)
- format = util_format_stencil_only(format);
- }
- }
-
/* if sampler view has changed dereference it */
if (*sv) {
if (check_sampler_swizzle(st, stObj, *sv, glsl_version) ||
@@ -395,29 +437,7 @@ update_single_texture(struct st_context *st,
return GL_FALSE;
}
- /* Determine the format of the texture sampler view */
- if (texObj->Target == GL_TEXTURE_BUFFER) {
- view_format =
- st_mesa_format_to_pipe_format(st, stObj->base._BufferObjectFormat);
- }
- else {
- view_format =
- stObj->surface_based ? stObj->surface_format : stObj->pt->format;
-
- /* If sRGB decoding is off, use the linear format */
- if (samp->sRGBDecode == GL_SKIP_DECODE_EXT) {
- view_format = util_format_linear(view_format);
- }
- }
-
- switch (view_format) {
- case PIPE_FORMAT_NV12:
- case PIPE_FORMAT_IYUV:
- view_format = PIPE_FORMAT_R8_UNORM;
- break;
- default:
- break;
- }
+ view_format = get_sampler_view_format(st, stObj, samp);
*sampler_view =
st_get_texture_sampler_view_from_stobj(st, stObj, view_format,
--
1.9.1
More information about the mesa-dev
mailing list