2007-08-07 15:11:20 -06:00
|
|
|
/**************************************************************************
|
2012-01-09 09:30:13 -07:00
|
|
|
*
|
s/Tungsten Graphics/VMware/
Tungsten Graphics Inc. was acquired by VMware Inc. in 2008. Leaving the
old copyright name is creating unnecessary confusion, hence this change.
This was the sed script I used:
$ cat tg2vmw.sed
# Run as:
#
# git reset --hard HEAD && find include scons src -type f -not -name 'sed*' -print0 | xargs -0 sed -i -f tg2vmw.sed
#
# Rename copyrights
s/Tungsten Gra\(ph\|hp\)ics,\? [iI]nc\.\?\(, Cedar Park\)\?\(, Austin\)\?\(, \(Texas\|TX\)\)\?\.\?/VMware, Inc./g
/Copyright/s/Tungsten Graphics\(,\? [iI]nc\.\)\?\(, Cedar Park\)\?\(, Austin\)\?\(, \(Texas\|TX\)\)\?\.\?/VMware, Inc./
s/TUNGSTEN GRAPHICS/VMWARE/g
# Rename emails
s/alanh@tungstengraphics.com/alanh@vmware.com/
s/jens@tungstengraphics.com/jowen@vmware.com/g
s/jrfonseca-at-tungstengraphics-dot-com/jfonseca-at-vmware-dot-com/
s/jrfonseca\?@tungstengraphics.com/jfonseca@vmware.com/g
s/keithw\?@tungstengraphics.com/keithw@vmware.com/g
s/michel@tungstengraphics.com/daenzer@vmware.com/g
s/thomas-at-tungstengraphics-dot-com/thellstom-at-vmware-dot-com/
s/zack@tungstengraphics.com/zackr@vmware.com/
# Remove dead links
s@Tungsten Graphics (http://www.tungstengraphics.com)@Tungsten Graphics@g
# C string src/gallium/state_trackers/vega/api_misc.c
s/"Tungsten Graphics, Inc"/"VMware, Inc"/
Reviewed-by: Brian Paul <brianp@vmware.com>
2014-01-17 16:27:50 +00:00
|
|
|
* Copyright 2007 VMware, Inc.
|
2007-08-07 15:11:20 -06:00
|
|
|
* All Rights Reserved.
|
2012-01-09 09:30:13 -07:00
|
|
|
*
|
2007-08-07 15:11:20 -06:00
|
|
|
* 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:
|
2012-01-09 09:30:13 -07:00
|
|
|
*
|
2007-08-07 15:11:20 -06:00
|
|
|
* The above copyright notice and this permission notice (including the
|
|
|
|
* next paragraph) shall be included in all copies or substantial portions
|
|
|
|
* of the Software.
|
2012-01-09 09:30:13 -07:00
|
|
|
*
|
2007-08-07 15:11:20 -06:00
|
|
|
* 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.
|
s/Tungsten Graphics/VMware/
Tungsten Graphics Inc. was acquired by VMware Inc. in 2008. Leaving the
old copyright name is creating unnecessary confusion, hence this change.
This was the sed script I used:
$ cat tg2vmw.sed
# Run as:
#
# git reset --hard HEAD && find include scons src -type f -not -name 'sed*' -print0 | xargs -0 sed -i -f tg2vmw.sed
#
# Rename copyrights
s/Tungsten Gra\(ph\|hp\)ics,\? [iI]nc\.\?\(, Cedar Park\)\?\(, Austin\)\?\(, \(Texas\|TX\)\)\?\.\?/VMware, Inc./g
/Copyright/s/Tungsten Graphics\(,\? [iI]nc\.\)\?\(, Cedar Park\)\?\(, Austin\)\?\(, \(Texas\|TX\)\)\?\.\?/VMware, Inc./
s/TUNGSTEN GRAPHICS/VMWARE/g
# Rename emails
s/alanh@tungstengraphics.com/alanh@vmware.com/
s/jens@tungstengraphics.com/jowen@vmware.com/g
s/jrfonseca-at-tungstengraphics-dot-com/jfonseca-at-vmware-dot-com/
s/jrfonseca\?@tungstengraphics.com/jfonseca@vmware.com/g
s/keithw\?@tungstengraphics.com/keithw@vmware.com/g
s/michel@tungstengraphics.com/daenzer@vmware.com/g
s/thomas-at-tungstengraphics-dot-com/thellstom-at-vmware-dot-com/
s/zack@tungstengraphics.com/zackr@vmware.com/
# Remove dead links
s@Tungsten Graphics (http://www.tungstengraphics.com)@Tungsten Graphics@g
# C string src/gallium/state_trackers/vega/api_misc.c
s/"Tungsten Graphics, Inc"/"VMware, Inc"/
Reviewed-by: Brian Paul <brianp@vmware.com>
2014-01-17 16:27:50 +00:00
|
|
|
* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
|
2007-08-07 15:11:20 -06:00
|
|
|
* 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.
|
2012-01-09 09:30:13 -07:00
|
|
|
*
|
2007-08-07 15:11:20 -06:00
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Authors:
|
s/Tungsten Graphics/VMware/
Tungsten Graphics Inc. was acquired by VMware Inc. in 2008. Leaving the
old copyright name is creating unnecessary confusion, hence this change.
This was the sed script I used:
$ cat tg2vmw.sed
# Run as:
#
# git reset --hard HEAD && find include scons src -type f -not -name 'sed*' -print0 | xargs -0 sed -i -f tg2vmw.sed
#
# Rename copyrights
s/Tungsten Gra\(ph\|hp\)ics,\? [iI]nc\.\?\(, Cedar Park\)\?\(, Austin\)\?\(, \(Texas\|TX\)\)\?\.\?/VMware, Inc./g
/Copyright/s/Tungsten Graphics\(,\? [iI]nc\.\)\?\(, Cedar Park\)\?\(, Austin\)\?\(, \(Texas\|TX\)\)\?\.\?/VMware, Inc./
s/TUNGSTEN GRAPHICS/VMWARE/g
# Rename emails
s/alanh@tungstengraphics.com/alanh@vmware.com/
s/jens@tungstengraphics.com/jowen@vmware.com/g
s/jrfonseca-at-tungstengraphics-dot-com/jfonseca-at-vmware-dot-com/
s/jrfonseca\?@tungstengraphics.com/jfonseca@vmware.com/g
s/keithw\?@tungstengraphics.com/keithw@vmware.com/g
s/michel@tungstengraphics.com/daenzer@vmware.com/g
s/thomas-at-tungstengraphics-dot-com/thellstom-at-vmware-dot-com/
s/zack@tungstengraphics.com/zackr@vmware.com/
# Remove dead links
s@Tungsten Graphics (http://www.tungstengraphics.com)@Tungsten Graphics@g
# C string src/gallium/state_trackers/vega/api_misc.c
s/"Tungsten Graphics, Inc"/"VMware, Inc"/
Reviewed-by: Brian Paul <brianp@vmware.com>
2014-01-17 16:27:50 +00:00
|
|
|
* Keith Whitwell <keithw@vmware.com>
|
2007-08-07 15:11:20 -06:00
|
|
|
* Brian Paul
|
|
|
|
*/
|
2012-01-09 09:30:13 -07:00
|
|
|
|
2007-08-07 15:11:20 -06:00
|
|
|
|
2009-12-01 11:19:33 +01:00
|
|
|
#include "main/macros.h"
|
2011-04-20 11:48:31 -07:00
|
|
|
#include "main/mtypes.h"
|
|
|
|
#include "main/samplerobj.h"
|
2012-02-12 16:30:28 -07:00
|
|
|
#include "main/texobj.h"
|
2010-06-10 23:02:41 -06:00
|
|
|
#include "program/prog_instruction.h"
|
2009-12-01 11:19:33 +01:00
|
|
|
|
2007-08-07 15:11:20 -06:00
|
|
|
#include "st_context.h"
|
|
|
|
#include "st_atom.h"
|
2008-02-20 11:20:25 -07:00
|
|
|
#include "st_texture.h"
|
2010-04-24 18:53:55 +10:00
|
|
|
#include "st_format.h"
|
2007-08-07 15:11:20 -06:00
|
|
|
#include "st_cb_texture.h"
|
|
|
|
#include "pipe/p_context.h"
|
2010-07-19 20:46:15 +02:00
|
|
|
#include "util/u_format.h"
|
2010-02-02 14:42:17 +00:00
|
|
|
#include "util/u_inlines.h"
|
2008-04-25 15:23:21 -06:00
|
|
|
#include "cso_cache/cso_context.h"
|
|
|
|
|
2011-01-20 08:38:19 -07:00
|
|
|
|
2014-03-25 09:36:29 -06:00
|
|
|
/**
|
|
|
|
* Return swizzle1(swizzle2)
|
|
|
|
*/
|
|
|
|
static unsigned
|
|
|
|
swizzle_swizzle(unsigned swizzle1, unsigned swizzle2)
|
|
|
|
{
|
|
|
|
unsigned i, swz[4];
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
unsigned s = GET_SWZ(swizzle1, i);
|
|
|
|
switch (s) {
|
|
|
|
case SWIZZLE_X:
|
|
|
|
case SWIZZLE_Y:
|
|
|
|
case SWIZZLE_Z:
|
|
|
|
case SWIZZLE_W:
|
|
|
|
swz[i] = GET_SWZ(swizzle2, s);
|
|
|
|
break;
|
|
|
|
case SWIZZLE_ZERO:
|
|
|
|
swz[i] = SWIZZLE_ZERO;
|
|
|
|
break;
|
|
|
|
case SWIZZLE_ONE:
|
|
|
|
swz[i] = SWIZZLE_ONE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(!"Bad swizzle term");
|
|
|
|
swz[i] = SWIZZLE_X;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return MAKE_SWIZZLE4(swz[0], swz[1], swz[2], swz[3]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-19 20:46:15 +02:00
|
|
|
/**
|
|
|
|
* Combine depth texture mode with "swizzle" so that depth mode swizzling
|
|
|
|
* takes place before texture swizzling, and return the resulting swizzle.
|
|
|
|
* If the format is not a depth format, return "swizzle" unchanged.
|
|
|
|
*
|
|
|
|
* \param format PIPE_FORMAT_*.
|
|
|
|
* \param swizzle Texture swizzle, a bitmask computed using MAKE_SWIZZLE4.
|
2010-08-11 19:04:05 +10:00
|
|
|
* \param depthmode One of GL_LUMINANCE, GL_INTENSITY, GL_ALPHA, GL_RED.
|
2010-07-19 20:46:15 +02:00
|
|
|
*/
|
2011-01-20 08:38:19 -07:00
|
|
|
static GLuint
|
|
|
|
apply_depthmode(enum pipe_format format, GLuint swizzle, GLenum depthmode)
|
2010-07-19 20:46:15 +02:00
|
|
|
{
|
|
|
|
const struct util_format_description *desc =
|
|
|
|
util_format_description(format);
|
2014-03-25 09:36:29 -06:00
|
|
|
unsigned swz;
|
2010-07-19 20:46:15 +02:00
|
|
|
|
|
|
|
if (desc->colorspace != UTIL_FORMAT_COLORSPACE_ZS ||
|
|
|
|
desc->swizzle[0] == UTIL_FORMAT_SWIZZLE_NONE) {
|
|
|
|
/* Not a depth format. */
|
|
|
|
return swizzle;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (depthmode) {
|
2014-03-25 09:36:29 -06:00
|
|
|
case GL_LUMINANCE:
|
|
|
|
swz = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_X, SWIZZLE_X, SWIZZLE_ONE);
|
|
|
|
break;
|
|
|
|
case GL_INTENSITY:
|
|
|
|
swz = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_X, SWIZZLE_X, SWIZZLE_X);
|
|
|
|
break;
|
|
|
|
case GL_ALPHA:
|
|
|
|
swz = MAKE_SWIZZLE4(SWIZZLE_ZERO, SWIZZLE_ZERO, SWIZZLE_ZERO, SWIZZLE_X);
|
|
|
|
break;
|
|
|
|
case GL_RED:
|
|
|
|
swz = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_ZERO, SWIZZLE_ZERO, SWIZZLE_ONE);
|
|
|
|
break;
|
2010-07-19 20:46:15 +02:00
|
|
|
}
|
|
|
|
|
2014-03-25 09:36:29 -06:00
|
|
|
return swizzle_swizzle(swizzle, swz);
|
2010-07-19 20:46:15 +02:00
|
|
|
}
|
|
|
|
|
2011-01-20 08:38:19 -07:00
|
|
|
|
2010-07-19 20:46:15 +02:00
|
|
|
/**
|
|
|
|
* Return TRUE if the swizzling described by "swizzle" and
|
|
|
|
* "depthmode" (for depth textures only) is different from the swizzling
|
|
|
|
* set in the given sampler view.
|
|
|
|
*
|
|
|
|
* \param sv A sampler view.
|
|
|
|
* \param swizzle Texture swizzle, a bitmask computed using MAKE_SWIZZLE4.
|
|
|
|
* \param depthmode One of GL_LUMINANCE, GL_INTENSITY, GL_ALPHA.
|
|
|
|
*/
|
2011-01-20 08:38:19 -07:00
|
|
|
static boolean
|
|
|
|
check_sampler_swizzle(struct pipe_sampler_view *sv,
|
|
|
|
GLuint swizzle, GLenum depthmode)
|
2010-04-27 21:06:44 +10:00
|
|
|
{
|
2010-07-19 20:46:15 +02:00
|
|
|
swizzle = apply_depthmode(sv->texture->format, swizzle, depthmode);
|
|
|
|
|
|
|
|
if ((sv->swizzle_r != GET_SWZ(swizzle, 0)) ||
|
|
|
|
(sv->swizzle_g != GET_SWZ(swizzle, 1)) ||
|
|
|
|
(sv->swizzle_b != GET_SWZ(swizzle, 2)) ||
|
|
|
|
(sv->swizzle_a != GET_SWZ(swizzle, 3)))
|
2011-01-20 08:38:19 -07:00
|
|
|
return TRUE;
|
|
|
|
return FALSE;
|
2010-04-27 21:06:44 +10:00
|
|
|
}
|
|
|
|
|
2011-01-20 08:38:19 -07:00
|
|
|
|
2012-02-13 15:41:57 -07:00
|
|
|
static struct pipe_sampler_view *
|
2010-04-27 21:06:44 +10:00
|
|
|
st_create_texture_sampler_view_from_stobj(struct pipe_context *pipe,
|
2010-04-24 18:53:55 +10:00
|
|
|
struct st_texture_object *stObj,
|
2011-04-10 12:44:46 -06:00
|
|
|
const struct gl_sampler_object *samp,
|
2010-04-24 18:53:55 +10:00
|
|
|
enum pipe_format format)
|
2010-04-27 21:06:44 +10:00
|
|
|
{
|
|
|
|
struct pipe_sampler_view templ;
|
2010-07-19 20:46:15 +02:00
|
|
|
GLuint swizzle = apply_depthmode(stObj->pt->format,
|
|
|
|
stObj->base._Swizzle,
|
mesa: Move DepthMode to texture object
GL_DEPTH_TEXTURE_MODE isn't meant to be part of sampler state based on
compatibility profile specifications.
OpenGL specification 4.1 compatibility 20100725 3.9.2:
"... The values accepted in the pname parameter
are TEXTURE_WRAP_S, TEXTURE_WRAP_T, TEXTURE_WRAP_R, TEXTURE_MIN_-
FILTER, TEXTURE_MAG_FILTER, TEXTURE_BORDER_COLOR, TEXTURE_MIN_-
LOD, TEXTURE_MAX_LOD, TEXTURE_LOD_BIAS, TEXTURE_COMPARE_MODE, and
TEXTURE_COMPARE_FUNC. Texture state listed in table 6.25 but not listed here and
in the sampler state in table 6.26 is not part of the sampler state, and remains in the
texture object."
The list of states is in Table 6.24 "Textures (state per texture
object)" instead of 6.25 mentioned in the specification text.
Same can be found from 3.3 compatibility specification.
Signed-off-by: Pauli Nieminen <pauli.nieminen@linux.intel.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
2012-06-12 21:38:46 +03:00
|
|
|
stObj->base.DepthMode);
|
2010-04-27 21:06:44 +10:00
|
|
|
|
|
|
|
u_sampler_view_default_template(&templ,
|
|
|
|
stObj->pt,
|
2010-04-24 18:53:55 +10:00
|
|
|
format);
|
2012-12-22 13:46:27 +01:00
|
|
|
|
|
|
|
if (stObj->pt->target == PIPE_BUFFER) {
|
|
|
|
unsigned base, size;
|
|
|
|
unsigned f, n;
|
|
|
|
const struct util_format_description *desc
|
|
|
|
= util_format_description(templ.format);
|
|
|
|
|
|
|
|
base = stObj->base.BufferOffset;
|
|
|
|
if (base >= stObj->pt->width0)
|
|
|
|
return NULL;
|
|
|
|
size = MIN2(stObj->pt->width0 - base, (unsigned)stObj->base.BufferSize);
|
|
|
|
|
|
|
|
f = ((base * 8) / desc->block.bits) * desc->block.width;
|
|
|
|
n = ((size * 8) / desc->block.bits) * desc->block.width;
|
|
|
|
if (!n)
|
|
|
|
return NULL;
|
|
|
|
templ.u.buf.first_element = f;
|
|
|
|
templ.u.buf.last_element = f + (n - 1);
|
|
|
|
} else {
|
|
|
|
templ.u.tex.first_level = stObj->base.BaseLevel;
|
|
|
|
}
|
2010-04-27 21:06:44 +10:00
|
|
|
|
2010-07-19 20:46:15 +02:00
|
|
|
if (swizzle != SWIZZLE_NOOP) {
|
|
|
|
templ.swizzle_r = GET_SWZ(swizzle, 0);
|
|
|
|
templ.swizzle_g = GET_SWZ(swizzle, 1);
|
|
|
|
templ.swizzle_b = GET_SWZ(swizzle, 2);
|
|
|
|
templ.swizzle_a = GET_SWZ(swizzle, 3);
|
2010-04-27 21:06:44 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
return pipe->create_sampler_view(pipe, stObj->pt, &templ);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-13 15:41:57 -07:00
|
|
|
static struct pipe_sampler_view *
|
2010-04-27 21:06:44 +10:00
|
|
|
st_get_texture_sampler_view_from_stobj(struct st_texture_object *stObj,
|
2010-04-24 18:53:55 +10:00
|
|
|
struct pipe_context *pipe,
|
2011-04-10 12:44:46 -06:00
|
|
|
const struct gl_sampler_object *samp,
|
2010-04-24 18:53:55 +10:00
|
|
|
enum pipe_format format)
|
2010-04-27 21:06:44 +10:00
|
|
|
{
|
|
|
|
if (!stObj || !stObj->pt) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!stObj->sampler_view) {
|
2011-01-20 08:38:19 -07:00
|
|
|
stObj->sampler_view =
|
2011-04-10 12:44:46 -06:00
|
|
|
st_create_texture_sampler_view_from_stobj(pipe, stObj, samp, format);
|
2014-03-22 21:30:07 +01:00
|
|
|
|
|
|
|
} else if (stObj->sampler_view->context != pipe) {
|
|
|
|
/* Recreate view in correct context, use existing view as template */
|
|
|
|
/* XXX: This isn't optimal, we should try to use more than one view.
|
|
|
|
Otherwise we create/destroy the view all the time
|
|
|
|
*/
|
|
|
|
struct pipe_sampler_view *sv =
|
|
|
|
pipe->create_sampler_view(pipe, stObj->pt, stObj->sampler_view);
|
|
|
|
pipe_sampler_view_reference(&stObj->sampler_view, NULL);
|
|
|
|
stObj->sampler_view = sv;
|
2010-04-27 21:06:44 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
return stObj->sampler_view;
|
|
|
|
}
|
2008-04-25 15:23:21 -06:00
|
|
|
|
2012-01-09 09:30:13 -07:00
|
|
|
|
2011-05-14 18:04:08 +10:00
|
|
|
static GLboolean
|
2012-01-09 09:30:13 -07:00
|
|
|
update_single_texture(struct st_context *st,
|
|
|
|
struct pipe_sampler_view **sampler_view,
|
2011-05-14 18:04:08 +10:00
|
|
|
GLuint texUnit)
|
|
|
|
{
|
|
|
|
struct pipe_context *pipe = st->pipe;
|
2011-06-14 09:15:36 -06:00
|
|
|
struct gl_context *ctx = st->ctx;
|
2011-05-14 18:04:08 +10:00
|
|
|
const struct gl_sampler_object *samp;
|
|
|
|
struct gl_texture_object *texObj;
|
|
|
|
struct st_texture_object *stObj;
|
2013-02-01 18:00:45 -07:00
|
|
|
enum pipe_format view_format;
|
2011-05-14 18:04:08 +10:00
|
|
|
GLboolean retval;
|
|
|
|
|
2011-06-14 09:15:36 -06:00
|
|
|
samp = _mesa_get_samplerobj(ctx, texUnit);
|
2011-05-14 18:04:08 +10:00
|
|
|
|
2011-06-14 09:15:36 -06:00
|
|
|
texObj = ctx->Texture.Unit[texUnit]._Current;
|
2011-05-14 18:04:08 +10:00
|
|
|
|
|
|
|
if (!texObj) {
|
2012-02-12 16:30:28 -07:00
|
|
|
texObj = _mesa_get_fallback_texture(ctx, TEXTURE_2D_INDEX);
|
2011-05-14 18:04:08 +10:00
|
|
|
samp = &texObj->Sampler;
|
|
|
|
}
|
|
|
|
stObj = st_texture_object(texObj);
|
|
|
|
|
2011-06-14 09:15:36 -06:00
|
|
|
retval = st_finalize_texture(ctx, st->pipe, texObj);
|
2011-05-14 18:04:08 +10:00
|
|
|
if (!retval) {
|
|
|
|
/* out of mem */
|
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Determine the format of the texture sampler view */
|
2013-02-12 21:00:43 +01:00
|
|
|
if (texObj->Target == GL_TEXTURE_BUFFER) {
|
|
|
|
view_format =
|
|
|
|
st_mesa_format_to_pipe_format(stObj->base._BufferObjectFormat);
|
|
|
|
}
|
|
|
|
else {
|
2013-05-10 02:03:15 +02:00
|
|
|
view_format =
|
|
|
|
stObj->surface_based ? stObj->surface_format : stObj->pt->format;
|
2011-05-14 18:04:08 +10:00
|
|
|
|
2013-02-12 21:00:43 +01:00
|
|
|
/* If sRGB decoding is off, use the linear format */
|
|
|
|
if (samp->sRGBDecode == GL_SKIP_DECODE_EXT) {
|
|
|
|
view_format = util_format_linear(view_format);
|
|
|
|
}
|
2011-05-14 18:04:08 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
/* if sampler view has changed dereference it */
|
|
|
|
if (stObj->sampler_view) {
|
|
|
|
if (check_sampler_swizzle(stObj->sampler_view,
|
|
|
|
stObj->base._Swizzle,
|
mesa: Move DepthMode to texture object
GL_DEPTH_TEXTURE_MODE isn't meant to be part of sampler state based on
compatibility profile specifications.
OpenGL specification 4.1 compatibility 20100725 3.9.2:
"... The values accepted in the pname parameter
are TEXTURE_WRAP_S, TEXTURE_WRAP_T, TEXTURE_WRAP_R, TEXTURE_MIN_-
FILTER, TEXTURE_MAG_FILTER, TEXTURE_BORDER_COLOR, TEXTURE_MIN_-
LOD, TEXTURE_MAX_LOD, TEXTURE_LOD_BIAS, TEXTURE_COMPARE_MODE, and
TEXTURE_COMPARE_FUNC. Texture state listed in table 6.25 but not listed here and
in the sampler state in table 6.26 is not part of the sampler state, and remains in the
texture object."
The list of states is in Table 6.24 "Textures (state per texture
object)" instead of 6.25 mentioned in the specification text.
Same can be found from 3.3 compatibility specification.
Signed-off-by: Pauli Nieminen <pauli.nieminen@linux.intel.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
2012-06-12 21:38:46 +03:00
|
|
|
stObj->base.DepthMode) ||
|
2013-02-01 18:00:45 -07:00
|
|
|
(view_format != stObj->sampler_view->format) ||
|
2011-05-14 18:04:08 +10:00
|
|
|
stObj->base.BaseLevel != stObj->sampler_view->u.tex.first_level) {
|
2013-12-14 07:15:00 -07:00
|
|
|
pipe_sampler_view_release(pipe, &stObj->sampler_view);
|
2011-05-14 18:04:08 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*sampler_view = st_get_texture_sampler_view_from_stobj(stObj, pipe,
|
|
|
|
samp,
|
2013-02-01 18:00:45 -07:00
|
|
|
view_format);
|
2011-05-14 18:04:08 +10:00
|
|
|
return GL_TRUE;
|
|
|
|
}
|
2011-01-20 08:38:19 -07:00
|
|
|
|
2012-01-09 09:30:13 -07:00
|
|
|
|
2012-08-06 08:35:20 -06:00
|
|
|
|
2012-01-09 09:30:13 -07:00
|
|
|
static void
|
2012-08-06 08:35:20 -06:00
|
|
|
update_textures(struct st_context *st,
|
|
|
|
unsigned shader_stage,
|
|
|
|
const struct gl_program *prog,
|
|
|
|
unsigned max_units,
|
|
|
|
struct pipe_sampler_view **sampler_views,
|
|
|
|
unsigned *num_textures)
|
2007-08-07 15:11:20 -06:00
|
|
|
{
|
2012-08-06 08:35:20 -06:00
|
|
|
const GLuint old_max = *num_textures;
|
|
|
|
GLbitfield samplers_used = prog->SamplersUsed;
|
2012-08-17 08:16:23 -06:00
|
|
|
GLuint unit, new_count;
|
2011-05-14 18:04:08 +10:00
|
|
|
|
2012-08-06 08:35:20 -06:00
|
|
|
if (samplers_used == 0x0 && old_max == 0)
|
2012-02-07 16:18:05 +00:00
|
|
|
return;
|
|
|
|
|
2012-08-06 08:35:20 -06:00
|
|
|
*num_textures = 0;
|
2011-05-14 18:04:08 +10:00
|
|
|
|
|
|
|
/* loop over sampler units (aka tex image units) */
|
2012-08-06 08:35:20 -06:00
|
|
|
for (unit = 0; unit < max_units; unit++, samplers_used >>= 1) {
|
2011-05-14 18:04:08 +10:00
|
|
|
struct pipe_sampler_view *sampler_view = NULL;
|
2012-08-06 08:35:20 -06:00
|
|
|
|
|
|
|
if (samplers_used & 1) {
|
2012-08-06 08:35:20 -06:00
|
|
|
const GLuint texUnit = prog->SamplerUnits[unit];
|
2011-05-14 18:04:08 +10:00
|
|
|
GLboolean retval;
|
|
|
|
|
2011-11-07 19:38:13 +01:00
|
|
|
retval = update_single_texture(st, &sampler_view, texUnit);
|
|
|
|
if (retval == GL_FALSE)
|
|
|
|
continue;
|
2011-05-14 18:04:08 +10:00
|
|
|
|
2012-08-06 08:35:20 -06:00
|
|
|
*num_textures = unit + 1;
|
|
|
|
}
|
|
|
|
else if (samplers_used == 0 && unit >= old_max) {
|
2012-08-06 08:35:20 -06:00
|
|
|
/* if we've reset all the old views and we have no more new ones */
|
|
|
|
break;
|
2011-05-14 18:04:08 +10:00
|
|
|
}
|
2012-08-06 08:35:20 -06:00
|
|
|
|
2012-08-06 08:35:20 -06:00
|
|
|
pipe_sampler_view_reference(&(sampler_views[unit]), sampler_view);
|
2011-05-14 18:04:08 +10:00
|
|
|
}
|
|
|
|
|
2012-08-17 08:16:23 -06:00
|
|
|
/* Ex: if old_max = 3 and *num_textures = 1, we need to pass an
|
|
|
|
* array of views={X, NULL, NULL} to unref the old texture views
|
|
|
|
* at positions [1] and [2].
|
|
|
|
*/
|
|
|
|
new_count = MAX2(*num_textures, old_max);
|
|
|
|
assert(new_count <= max_units);
|
|
|
|
|
2012-08-06 08:35:20 -06:00
|
|
|
cso_set_sampler_views(st->cso_context,
|
|
|
|
shader_stage,
|
2012-08-17 08:16:23 -06:00
|
|
|
new_count,
|
2012-08-06 08:35:20 -06:00
|
|
|
sampler_views);
|
2011-05-14 18:04:08 +10:00
|
|
|
}
|
|
|
|
|
2012-01-09 09:30:13 -07:00
|
|
|
|
2012-08-06 08:35:20 -06:00
|
|
|
|
2012-01-09 09:30:13 -07:00
|
|
|
static void
|
2012-08-06 08:35:20 -06:00
|
|
|
update_vertex_textures(struct st_context *st)
|
2011-05-14 18:04:08 +10:00
|
|
|
{
|
2011-06-14 09:15:36 -06:00
|
|
|
const struct gl_context *ctx = st->ctx;
|
2012-02-08 13:58:14 +00:00
|
|
|
|
2014-01-08 10:00:28 -08:00
|
|
|
if (ctx->Const.Program[MESA_SHADER_VERTEX].MaxTextureImageUnits > 0) {
|
2012-08-06 08:35:20 -06:00
|
|
|
update_textures(st,
|
|
|
|
PIPE_SHADER_VERTEX,
|
|
|
|
&ctx->VertexProgram._Current->Base,
|
2014-01-08 10:00:28 -08:00
|
|
|
ctx->Const.Program[MESA_SHADER_VERTEX].MaxTextureImageUnits,
|
2012-08-09 20:59:44 -06:00
|
|
|
st->state.sampler_views[PIPE_SHADER_VERTEX],
|
|
|
|
&st->state.num_sampler_views[PIPE_SHADER_VERTEX]);
|
2012-08-06 08:35:20 -06:00
|
|
|
}
|
|
|
|
}
|
2008-08-14 15:38:09 -06:00
|
|
|
|
2011-05-14 18:04:08 +10:00
|
|
|
|
2012-08-06 08:35:20 -06:00
|
|
|
static void
|
|
|
|
update_fragment_textures(struct st_context *st)
|
|
|
|
{
|
|
|
|
const struct gl_context *ctx = st->ctx;
|
2008-03-05 10:50:14 +01:00
|
|
|
|
2012-08-06 08:35:20 -06:00
|
|
|
update_textures(st,
|
|
|
|
PIPE_SHADER_FRAGMENT,
|
|
|
|
&ctx->FragmentProgram._Current->Base,
|
2014-01-08 10:00:28 -08:00
|
|
|
ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits,
|
2012-08-09 20:59:44 -06:00
|
|
|
st->state.sampler_views[PIPE_SHADER_FRAGMENT],
|
|
|
|
&st->state.num_sampler_views[PIPE_SHADER_FRAGMENT]);
|
2007-08-07 15:11:20 -06:00
|
|
|
}
|
|
|
|
|
2012-01-09 09:30:13 -07:00
|
|
|
|
2012-08-09 20:59:44 -06:00
|
|
|
static void
|
|
|
|
update_geometry_textures(struct st_context *st)
|
|
|
|
{
|
|
|
|
const struct gl_context *ctx = st->ctx;
|
|
|
|
|
|
|
|
if (ctx->GeometryProgram._Current) {
|
|
|
|
update_textures(st,
|
|
|
|
PIPE_SHADER_GEOMETRY,
|
|
|
|
&ctx->GeometryProgram._Current->Base,
|
2014-01-08 10:00:28 -08:00
|
|
|
ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits,
|
2012-08-09 20:59:44 -06:00
|
|
|
st->state.sampler_views[PIPE_SHADER_GEOMETRY],
|
|
|
|
&st->state.num_sampler_views[PIPE_SHADER_GEOMETRY]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const struct st_tracked_state st_update_fragment_texture = {
|
2008-05-02 10:08:03 +00:00
|
|
|
"st_update_texture", /* name */
|
|
|
|
{ /* dirty */
|
|
|
|
_NEW_TEXTURE, /* mesa */
|
|
|
|
ST_NEW_FRAGMENT_PROGRAM, /* st */
|
2007-08-07 15:11:20 -06:00
|
|
|
},
|
2011-05-18 17:27:39 +10:00
|
|
|
update_fragment_textures /* update */
|
|
|
|
};
|
|
|
|
|
2012-01-09 09:30:13 -07:00
|
|
|
|
2011-05-18 17:27:39 +10:00
|
|
|
const struct st_tracked_state st_update_vertex_texture = {
|
2012-01-09 09:30:13 -07:00
|
|
|
"st_update_vertex_texture", /* name */
|
2011-05-18 17:27:39 +10:00
|
|
|
{ /* dirty */
|
|
|
|
_NEW_TEXTURE, /* mesa */
|
|
|
|
ST_NEW_VERTEX_PROGRAM, /* st */
|
|
|
|
},
|
|
|
|
update_vertex_textures /* update */
|
2007-08-07 15:11:20 -06:00
|
|
|
};
|
2008-05-07 16:44:33 -06:00
|
|
|
|
2012-01-09 09:30:13 -07:00
|
|
|
|
2012-08-09 20:59:44 -06:00
|
|
|
const struct st_tracked_state st_update_geometry_texture = {
|
|
|
|
"st_update_geometry_texture", /* name */
|
|
|
|
{ /* dirty */
|
|
|
|
_NEW_TEXTURE, /* mesa */
|
|
|
|
ST_NEW_GEOMETRY_PROGRAM, /* st */
|
|
|
|
},
|
|
|
|
update_geometry_textures /* update */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-01-09 09:30:13 -07:00
|
|
|
|
|
|
|
static void
|
2008-05-07 16:44:33 -06:00
|
|
|
finalize_textures(struct st_context *st)
|
|
|
|
{
|
2011-06-14 09:15:36 -06:00
|
|
|
struct gl_context *ctx = st->ctx;
|
|
|
|
struct gl_fragment_program *fprog = ctx->FragmentProgram._Current;
|
2008-05-07 16:44:33 -06:00
|
|
|
const GLboolean prev_missing_textures = st->missing_textures;
|
|
|
|
GLuint su;
|
|
|
|
|
|
|
|
st->missing_textures = GL_FALSE;
|
|
|
|
|
2011-06-14 09:15:36 -06:00
|
|
|
for (su = 0; su < ctx->Const.MaxTextureCoordUnits; su++) {
|
2008-05-07 16:44:33 -06:00
|
|
|
if (fprog->Base.SamplersUsed & (1 << su)) {
|
|
|
|
const GLuint texUnit = fprog->Base.SamplerUnits[su];
|
|
|
|
struct gl_texture_object *texObj
|
2011-06-14 09:15:36 -06:00
|
|
|
= ctx->Texture.Unit[texUnit]._Current;
|
2008-05-07 16:44:33 -06:00
|
|
|
|
|
|
|
if (texObj) {
|
2010-05-03 16:13:20 -06:00
|
|
|
GLboolean retval;
|
2008-05-07 16:44:33 -06:00
|
|
|
|
2011-06-14 09:15:36 -06:00
|
|
|
retval = st_finalize_texture(ctx, st->pipe, texObj);
|
2008-05-07 16:44:33 -06:00
|
|
|
if (!retval) {
|
|
|
|
/* out of mem */
|
|
|
|
st->missing_textures = GL_TRUE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (prev_missing_textures != st->missing_textures)
|
|
|
|
st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const struct st_tracked_state st_finalize_textures = {
|
|
|
|
"st_finalize_textures", /* name */
|
|
|
|
{ /* dirty */
|
|
|
|
_NEW_TEXTURE, /* mesa */
|
|
|
|
0, /* st */
|
|
|
|
},
|
|
|
|
finalize_textures /* update */
|
|
|
|
};
|