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
|
|
|
/**
|
2014-03-25 11:04:40 -06:00
|
|
|
* Given a user-specified texture base format, the actual gallium texture
|
|
|
|
* format and the current GL_DEPTH_MODE, return a texture swizzle.
|
2010-07-19 20:46:15 +02:00
|
|
|
*
|
2014-03-25 11:04:40 -06:00
|
|
|
* Consider the case where the user requests a GL_RGB internal texture
|
|
|
|
* format the driver actually uses an RGBA format. The A component should
|
|
|
|
* be ignored and sampling from the texture should always return (r,g,b,1).
|
|
|
|
* But if we rendered to the texture we might have written A values != 1.
|
|
|
|
* By sampling the texture with a ".xyz1" swizzle we'll get the expected A=1.
|
|
|
|
* This function computes the texture swizzle needed to get the expected
|
|
|
|
* values.
|
|
|
|
*
|
|
|
|
* In the case of depth textures, the GL_DEPTH_MODE state determines the
|
|
|
|
* texture swizzle.
|
|
|
|
*
|
|
|
|
* This result must be composed with the user-specified swizzle to get
|
|
|
|
* the final swizzle.
|
2010-07-19 20:46:15 +02:00
|
|
|
*/
|
2014-03-25 11:04:40 -06:00
|
|
|
static unsigned
|
|
|
|
compute_texture_format_swizzle(GLenum baseFormat, GLenum depthMode,
|
|
|
|
enum pipe_format actualFormat)
|
2010-07-19 20:46:15 +02:00
|
|
|
{
|
2014-03-25 11:04:40 -06:00
|
|
|
switch (baseFormat) {
|
|
|
|
case GL_RGBA:
|
|
|
|
return SWIZZLE_XYZW;
|
|
|
|
case GL_RGB:
|
|
|
|
if (util_format_has_alpha(actualFormat))
|
|
|
|
return MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_ONE);
|
|
|
|
else
|
|
|
|
return SWIZZLE_XYZW;
|
|
|
|
case GL_RG:
|
|
|
|
if (util_format_get_nr_components(actualFormat) > 2)
|
|
|
|
return MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_ZERO, SWIZZLE_ONE);
|
|
|
|
else
|
|
|
|
return SWIZZLE_XYZW;
|
|
|
|
case GL_RED:
|
|
|
|
if (util_format_get_nr_components(actualFormat) > 1)
|
|
|
|
return MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_ZERO,
|
|
|
|
SWIZZLE_ZERO, SWIZZLE_ONE);
|
|
|
|
else
|
|
|
|
return SWIZZLE_XYZW;
|
|
|
|
case GL_ALPHA:
|
|
|
|
if (util_format_get_nr_components(actualFormat) > 1)
|
|
|
|
return MAKE_SWIZZLE4(SWIZZLE_ZERO, SWIZZLE_ZERO,
|
|
|
|
SWIZZLE_ZERO, SWIZZLE_W);
|
|
|
|
else
|
|
|
|
return SWIZZLE_XYZW;
|
2014-03-25 09:36:29 -06:00
|
|
|
case GL_LUMINANCE:
|
2014-03-25 11:04:40 -06:00
|
|
|
if (util_format_get_nr_components(actualFormat) > 1)
|
|
|
|
return MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_X, SWIZZLE_X, SWIZZLE_ONE);
|
|
|
|
else
|
|
|
|
return SWIZZLE_XYZW;
|
|
|
|
case GL_LUMINANCE_ALPHA:
|
|
|
|
if (util_format_get_nr_components(actualFormat) > 2)
|
|
|
|
return MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_X, SWIZZLE_X, SWIZZLE_W);
|
|
|
|
else
|
|
|
|
return SWIZZLE_XYZW;
|
2014-03-25 09:36:29 -06:00
|
|
|
case GL_INTENSITY:
|
2014-03-25 11:04:40 -06:00
|
|
|
if (util_format_get_nr_components(actualFormat) > 1)
|
|
|
|
return SWIZZLE_XXXX;
|
|
|
|
else
|
|
|
|
return SWIZZLE_XYZW;
|
|
|
|
case GL_STENCIL_INDEX:
|
|
|
|
return SWIZZLE_XYZW;
|
|
|
|
case GL_DEPTH_STENCIL:
|
|
|
|
/* fall-through */
|
|
|
|
case GL_DEPTH_COMPONENT:
|
|
|
|
/* Now examine the depth mode */
|
|
|
|
switch (depthMode) {
|
|
|
|
case GL_LUMINANCE:
|
|
|
|
return MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_X, SWIZZLE_X, SWIZZLE_ONE);
|
|
|
|
case GL_INTENSITY:
|
|
|
|
return MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_X, SWIZZLE_X, SWIZZLE_X);
|
|
|
|
case GL_ALPHA:
|
|
|
|
return MAKE_SWIZZLE4(SWIZZLE_ZERO, SWIZZLE_ZERO,
|
|
|
|
SWIZZLE_ZERO, SWIZZLE_X);
|
|
|
|
case GL_RED:
|
|
|
|
return MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_ZERO,
|
|
|
|
SWIZZLE_ZERO, SWIZZLE_ONE);
|
|
|
|
default:
|
|
|
|
assert(!"Unexpected depthMode");
|
|
|
|
return SWIZZLE_XYZW;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
assert(!"Unexpected baseFormat");
|
|
|
|
return SWIZZLE_XYZW;
|
2010-07-19 20:46:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-20 08:38:19 -07:00
|
|
|
|
2014-03-25 11:04:40 -06:00
|
|
|
static unsigned
|
|
|
|
get_texture_format_swizzle(const struct st_texture_object *stObj)
|
|
|
|
{
|
|
|
|
const struct gl_texture_image *texImage =
|
|
|
|
stObj->base.Image[0][stObj->base.BaseLevel];
|
|
|
|
unsigned tex_swizzle;
|
|
|
|
|
|
|
|
if (texImage) {
|
|
|
|
tex_swizzle = compute_texture_format_swizzle(texImage->_BaseFormat,
|
|
|
|
stObj->base.DepthMode,
|
|
|
|
stObj->pt->format);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tex_swizzle = SWIZZLE_XYZW;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Combine the texture format swizzle with user's swizzle */
|
|
|
|
return swizzle_swizzle(stObj->base._Swizzle, tex_swizzle);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-19 20:46:15 +02:00
|
|
|
/**
|
2014-03-25 11:04:40 -06:00
|
|
|
* Return TRUE if the texture's sampler view swizzle is equal to
|
|
|
|
* the texture's swizzle.
|
2010-07-19 20:46:15 +02:00
|
|
|
*
|
2014-03-25 11:04:40 -06:00
|
|
|
* \param stObj the st texture object,
|
2010-07-19 20:46:15 +02:00
|
|
|
*/
|
2011-01-20 08:38:19 -07:00
|
|
|
static boolean
|
2014-03-25 17:31:49 +01:00
|
|
|
check_sampler_swizzle(const struct st_texture_object *stObj,
|
|
|
|
struct pipe_sampler_view *sv)
|
2010-04-27 21:06:44 +10:00
|
|
|
{
|
2014-03-25 11:04:40 -06:00
|
|
|
unsigned swizzle = get_texture_format_swizzle(stObj);
|
|
|
|
|
|
|
|
return ((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)));
|
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;
|
2014-03-25 11:04:40 -06:00
|
|
|
unsigned swizzle = get_texture_format_swizzle(stObj);
|
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 *
|
2014-03-25 17:31:49 +01:00
|
|
|
st_get_texture_sampler_view_from_stobj(struct st_context *st,
|
|
|
|
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
|
|
|
{
|
2014-03-25 17:31:49 +01:00
|
|
|
struct pipe_sampler_view **sv;
|
|
|
|
|
2010-04-27 21:06:44 +10:00
|
|
|
if (!stObj || !stObj->pt) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-03-25 17:31:49 +01:00
|
|
|
sv = st_texture_get_sampler_view(st, stObj);
|
|
|
|
|
2014-05-03 05:08:53 -04:00
|
|
|
if (stObj->base.StencilSampling &&
|
|
|
|
util_format_is_depth_and_stencil(format))
|
|
|
|
format = util_format_stencil_only(format);
|
|
|
|
|
2014-03-25 17:31:49 +01:00
|
|
|
/* if sampler view has changed dereference it */
|
|
|
|
if (*sv) {
|
|
|
|
if (check_sampler_swizzle(stObj, *sv) ||
|
|
|
|
(format != (*sv)->format) ||
|
|
|
|
stObj->base.BaseLevel != (*sv)->u.tex.first_level) {
|
|
|
|
pipe_sampler_view_reference(sv, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!*sv) {
|
|
|
|
*sv = st_create_texture_sampler_view_from_stobj(st->pipe, stObj, samp, format);
|
2014-03-22 21:30:07 +01:00
|
|
|
|
2014-03-25 17:31:49 +01:00
|
|
|
} else if ((*sv)->context != st->pipe) {
|
2014-03-22 21:30:07 +01:00
|
|
|
/* Recreate view in correct context, use existing view as template */
|
2014-03-25 17:31:49 +01:00
|
|
|
struct pipe_sampler_view *new_sv =
|
|
|
|
st->pipe->create_sampler_view(st->pipe, stObj->pt, *sv);
|
|
|
|
pipe_sampler_view_reference(sv, NULL);
|
|
|
|
*sv = new_sv;
|
2010-04-27 21:06:44 +10:00
|
|
|
}
|
|
|
|
|
2014-03-25 17:31:49 +01:00
|
|
|
return *sv;
|
2010-04-27 21:06:44 +10:00
|
|
|
}
|
2008-04-25 15:23:21 -06: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)
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2014-03-25 17:31:49 +01:00
|
|
|
*sampler_view = st_get_texture_sampler_view_from_stobj(st, stObj, 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;
|
2014-06-07 12:02:56 +10:00
|
|
|
GLuint unit;
|
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-06 08:35:20 -06:00
|
|
|
cso_set_sampler_views(st->cso_context,
|
|
|
|
shader_stage,
|
2014-06-07 12:02:56 +10:00
|
|
|
*num_textures,
|
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 */
|
|
|
|
};
|