aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/mesa/state_tracker
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2014-03-28 17:43:20 +0100
committermarha <marha@users.sourceforge.net>2014-03-28 17:43:20 +0100
commitf0f09f4aa3cdd0267f58b362a7c9fc5ae0921afd (patch)
treeafbeb028495328a2817aedbac7aae484a2c71a83 /mesalib/src/mesa/state_tracker
parentbf0cbcc1d00962ef2221cb4ceae87cc5ae737454 (diff)
parentcbfb19790917d271b8ca6156554b16acc802719f (diff)
downloadvcxsrv-f0f09f4aa3cdd0267f58b362a7c9fc5ae0921afd.tar.gz
vcxsrv-f0f09f4aa3cdd0267f58b362a7c9fc5ae0921afd.tar.bz2
vcxsrv-f0f09f4aa3cdd0267f58b362a7c9fc5ae0921afd.zip
Merge remote-tracking branch 'origin/released'
Conflicts: X11/xtrans/Xtrans.c
Diffstat (limited to 'mesalib/src/mesa/state_tracker')
-rw-r--r--mesalib/src/mesa/state_tracker/st_atom_clip.c2
-rw-r--r--mesalib/src/mesa/state_tracker/st_atom_constbuf.c6
-rw-r--r--mesalib/src/mesa/state_tracker/st_atom_texture.c216
-rw-r--r--mesalib/src/mesa/state_tracker/st_cb_drawpixels.c2
-rw-r--r--mesalib/src/mesa/state_tracker/st_cb_queryobj.c18
-rw-r--r--mesalib/src/mesa/state_tracker/st_context.c17
-rw-r--r--mesalib/src/mesa/state_tracker/st_draw.c2
-rw-r--r--mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp2
-rw-r--r--mesalib/src/mesa/state_tracker/st_program.c2
-rw-r--r--mesalib/src/mesa/state_tracker/st_texture.c7
-rw-r--r--mesalib/src/mesa/state_tracker/st_texture.h4
11 files changed, 195 insertions, 83 deletions
diff --git a/mesalib/src/mesa/state_tracker/st_atom_clip.c b/mesalib/src/mesa/state_tracker/st_atom_clip.c
index 274b36a62..f82c1332a 100644
--- a/mesalib/src/mesa/state_tracker/st_atom_clip.c
+++ b/mesalib/src/mesa/state_tracker/st_atom_clip.c
@@ -52,7 +52,7 @@ static void update_clip( struct st_context *st )
/* if we have a vertex shader that writes clip vertex we need to pass
the pre-projection transformed coordinates into the driver. */
if (st->vp) {
- if (ctx->Shader.CurrentProgram[MESA_SHADER_VERTEX])
+ if (ctx->_Shader->CurrentProgram[MESA_SHADER_VERTEX])
use_eye = TRUE;
}
diff --git a/mesalib/src/mesa/state_tracker/st_atom_constbuf.c b/mesalib/src/mesa/state_tracker/st_atom_constbuf.c
index a5013ed2c..7984bf742 100644
--- a/mesalib/src/mesa/state_tracker/st_atom_constbuf.c
+++ b/mesalib/src/mesa/state_tracker/st_atom_constbuf.c
@@ -219,7 +219,7 @@ static void st_bind_ubos(struct st_context *st,
static void bind_vs_ubos(struct st_context *st)
{
struct gl_shader_program *prog =
- st->ctx->Shader.CurrentProgram[MESA_SHADER_VERTEX];
+ st->ctx->_Shader->CurrentProgram[MESA_SHADER_VERTEX];
if (!prog)
return;
@@ -239,7 +239,7 @@ const struct st_tracked_state st_bind_vs_ubos = {
static void bind_fs_ubos(struct st_context *st)
{
struct gl_shader_program *prog =
- st->ctx->Shader.CurrentProgram[MESA_SHADER_FRAGMENT];
+ st->ctx->_Shader->CurrentProgram[MESA_SHADER_FRAGMENT];
if (!prog)
return;
@@ -259,7 +259,7 @@ const struct st_tracked_state st_bind_fs_ubos = {
static void bind_gs_ubos(struct st_context *st)
{
struct gl_shader_program *prog =
- st->ctx->Shader.CurrentProgram[MESA_SHADER_GEOMETRY];
+ st->ctx->_Shader->CurrentProgram[MESA_SHADER_GEOMETRY];
if (!prog)
return;
diff --git a/mesalib/src/mesa/state_tracker/st_atom_texture.c b/mesalib/src/mesa/state_tracker/st_atom_texture.c
index 75e6face4..c9bffce4f 100644
--- a/mesalib/src/mesa/state_tracker/st_atom_texture.c
+++ b/mesalib/src/mesa/state_tracker/st_atom_texture.c
@@ -50,91 +50,165 @@
/**
- * 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.
- * \param depthmode One of GL_LUMINANCE, GL_INTENSITY, GL_ALPHA, GL_RED.
+ * Return swizzle1(swizzle2)
*/
-static GLuint
-apply_depthmode(enum pipe_format format, GLuint swizzle, GLenum depthmode)
+static unsigned
+swizzle_swizzle(unsigned swizzle1, unsigned swizzle2)
{
- const struct util_format_description *desc =
- util_format_description(format);
- unsigned char swiz[4];
- unsigned i;
-
- if (desc->colorspace != UTIL_FORMAT_COLORSPACE_ZS ||
- desc->swizzle[0] == UTIL_FORMAT_SWIZZLE_NONE) {
- /* Not a depth format. */
- return swizzle;
+ 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;
+ }
}
- for (i = 0; i < 4; i++)
- swiz[i] = GET_SWZ(swizzle, i);
+ return MAKE_SWIZZLE4(swz[0], swz[1], swz[2], swz[3]);
+}
- switch (depthmode) {
- case GL_LUMINANCE:
- /* Rewrite reads from W to ONE, and reads from XYZ to XXX. */
- for (i = 0; i < 4; i++)
- if (swiz[i] == SWIZZLE_W)
- swiz[i] = SWIZZLE_ONE;
- else if (swiz[i] < SWIZZLE_W)
- swiz[i] = SWIZZLE_X;
- break;
+/**
+ * Given a user-specified texture base format, the actual gallium texture
+ * format and the current GL_DEPTH_MODE, return a texture swizzle.
+ *
+ * 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.
+ */
+static unsigned
+compute_texture_format_swizzle(GLenum baseFormat, GLenum depthMode,
+ enum pipe_format actualFormat)
+{
+ 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;
+ case GL_LUMINANCE:
+ 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;
+ case GL_INTENSITY:
+ 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:
- /* Rewrite reads from XYZW to XXXX. */
- for (i = 0; i < 4; i++)
- if (swiz[i] <= SWIZZLE_W)
- swiz[i] = SWIZZLE_X;
- break;
-
+ return MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_X, SWIZZLE_X, SWIZZLE_X);
case GL_ALPHA:
- /* Rewrite reads from W to X, and reads from XYZ to 000. */
- for (i = 0; i < 4; i++)
- if (swiz[i] == SWIZZLE_W)
- swiz[i] = SWIZZLE_X;
- else if (swiz[i] < SWIZZLE_W)
- swiz[i] = SWIZZLE_ZERO;
- break;
+ return MAKE_SWIZZLE4(SWIZZLE_ZERO, SWIZZLE_ZERO,
+ SWIZZLE_ZERO, SWIZZLE_X);
case GL_RED:
- /* Rewrite reads W to 1, XYZ to X00 */
- for (i = 0; i < 4; i++)
- if (swiz[i] == SWIZZLE_W)
- swiz[i] = SWIZZLE_ONE;
- else if (swiz[i] == SWIZZLE_Y || swiz[i] == SWIZZLE_Z)
- swiz[i] = SWIZZLE_ZERO;
- break;
+ 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;
}
-
- return MAKE_SWIZZLE4(swiz[0], swiz[1], swiz[2], swiz[3]);
}
+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);
+}
+
+
/**
- * 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.
+ * Return TRUE if the texture's sampler view swizzle is equal to
+ * the texture's swizzle.
*
- * \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.
+ * \param stObj the st texture object,
*/
static boolean
-check_sampler_swizzle(struct pipe_sampler_view *sv,
- GLuint swizzle, GLenum depthmode)
+check_sampler_swizzle(const struct st_texture_object *stObj)
{
- 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)))
- return TRUE;
- return FALSE;
+ const struct pipe_sampler_view *sv = stObj->sampler_view;
+ 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)));
}
@@ -145,9 +219,7 @@ st_create_texture_sampler_view_from_stobj(struct pipe_context *pipe,
enum pipe_format format)
{
struct pipe_sampler_view templ;
- GLuint swizzle = apply_depthmode(stObj->pt->format,
- stObj->base._Swizzle,
- stObj->base.DepthMode);
+ unsigned swizzle = get_texture_format_swizzle(stObj);
u_sampler_view_default_template(&templ,
stObj->pt,
@@ -260,9 +332,7 @@ update_single_texture(struct st_context *st,
/* if sampler view has changed dereference it */
if (stObj->sampler_view) {
- if (check_sampler_swizzle(stObj->sampler_view,
- stObj->base._Swizzle,
- stObj->base.DepthMode) ||
+ if (check_sampler_swizzle(stObj) ||
(view_format != stObj->sampler_view->format) ||
stObj->base.BaseLevel != stObj->sampler_view->u.tex.first_level) {
pipe_sampler_view_release(pipe, &stObj->sampler_view);
diff --git a/mesalib/src/mesa/state_tracker/st_cb_drawpixels.c b/mesalib/src/mesa/state_tracker/st_cb_drawpixels.c
index 2b3636151..6119cc275 100644
--- a/mesalib/src/mesa/state_tracker/st_cb_drawpixels.c
+++ b/mesalib/src/mesa/state_tracker/st_cb_drawpixels.c
@@ -1364,7 +1364,7 @@ blit_copy_pixels(struct gl_context *ctx, GLint srcx, GLint srcy,
!ctx->Stencil.Enabled &&
!ctx->FragmentProgram.Enabled &&
!ctx->VertexProgram.Enabled &&
- !ctx->Shader.CurrentProgram[MESA_SHADER_FRAGMENT] &&
+ !ctx->_Shader->CurrentProgram[MESA_SHADER_FRAGMENT] &&
ctx->DrawBuffer->_NumColorDrawBuffers == 1 &&
!ctx->Query.CondRenderQuery &&
!ctx->Query.CurrentOcclusionObject) {
diff --git a/mesalib/src/mesa/state_tracker/st_cb_queryobj.c b/mesalib/src/mesa/state_tracker/st_cb_queryobj.c
index 5186a5157..78a737094 100644
--- a/mesalib/src/mesa/state_tracker/st_cb_queryobj.c
+++ b/mesalib/src/mesa/state_tracker/st_cb_queryobj.c
@@ -141,7 +141,13 @@ st_BeginQuery(struct gl_context *ctx, struct gl_query_object *q)
stq->pq = pipe->create_query(pipe, type);
stq->type = type;
}
- pipe->begin_query(pipe, stq->pq);
+ if (stq->pq) {
+ pipe->begin_query(pipe, stq->pq);
+ }
+ else {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBeginQuery");
+ return;
+ }
}
assert(stq->type == type);
}
@@ -162,7 +168,8 @@ st_EndQuery(struct gl_context *ctx, struct gl_query_object *q)
stq->type = PIPE_QUERY_TIMESTAMP;
}
- pipe->end_query(pipe, stq->pq);
+ if (stq->pq)
+ pipe->end_query(pipe, stq->pq);
}
@@ -171,6 +178,13 @@ get_query_result(struct pipe_context *pipe,
struct st_query_object *stq,
boolean wait)
{
+ if (!stq->pq) {
+ /* Only needed in case we failed to allocate the gallium query earlier.
+ * Return TRUE so we don't spin on this forever.
+ */
+ return TRUE;
+ }
+
if (!pipe->get_query_result(pipe,
stq->pq,
wait,
diff --git a/mesalib/src/mesa/state_tracker/st_context.c b/mesalib/src/mesa/state_tracker/st_context.c
index 0ffc76263..807a86fdf 100644
--- a/mesalib/src/mesa/state_tracker/st_context.c
+++ b/mesalib/src/mesa/state_tracker/st_context.c
@@ -33,6 +33,7 @@
#include "main/shaderobj.h"
#include "main/version.h"
#include "main/vtxfmt.h"
+#include "main/hash.h"
#include "program/prog_cache.h"
#include "vbo/vbo.h"
#include "glapi/glapi.h"
@@ -66,6 +67,7 @@
#include "st_gen_mipmap.h"
#include "st_program.h"
#include "st_vdpau.h"
+#include "st_texture.h"
#include "pipe/p_context.h"
#include "util/u_inlines.h"
#include "util/u_upload_mgr.h"
@@ -280,6 +282,19 @@ static void st_destroy_context_priv( struct st_context *st )
free( st );
}
+
+/**
+ * Callback to release the sampler view attached to a texture object.
+ * Called by _mesa_HashWalk().
+ */
+static void
+destroy_tex_sampler_cb(GLuint id, void *data, void *userData)
+{
+ struct gl_texture_object *texObj = (struct gl_texture_object *) data;
+ struct st_context *st = (struct st_context *) userData;
+
+ st_texture_release_sampler_view(st, st_texture_object(texObj));
+}
void st_destroy_context( struct st_context *st )
{
@@ -288,6 +303,8 @@ void st_destroy_context( struct st_context *st )
struct gl_context *ctx = st->ctx;
GLuint i;
+ _mesa_HashWalk(ctx->Shared->TexObjects, destroy_tex_sampler_cb, st);
+
/* need to unbind and destroy CSO objects before anything else */
cso_release_all(st->cso_context);
diff --git a/mesalib/src/mesa/state_tracker/st_draw.c b/mesalib/src/mesa/state_tracker/st_draw.c
index dba5870a0..c8189faad 100644
--- a/mesalib/src/mesa/state_tracker/st_draw.c
+++ b/mesalib/src/mesa/state_tracker/st_draw.c
@@ -131,7 +131,7 @@ setup_index_buffer(struct st_context *st,
static void
check_uniforms(struct gl_context *ctx)
{
- struct gl_shader_program **shProg = ctx->Shader.CurrentProgram;
+ struct gl_shader_program **shProg = ctx->_Shader->CurrentProgram;
unsigned j;
for (j = 0; j < 3; j++) {
diff --git a/mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index a9e75d8a6..f019a55c2 100644
--- a/mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -5198,7 +5198,7 @@ get_mesa_program(struct gl_context *ctx,
/* Write the END instruction. */
v->emit(NULL, TGSI_OPCODE_END);
- if (ctx->Shader.Flags & GLSL_DUMP) {
+ if (ctx->_Shader->Flags & GLSL_DUMP) {
printf("\n");
printf("GLSL IR for linked %s program %d:\n",
_mesa_shader_stage_to_string(shader->Stage),
diff --git a/mesalib/src/mesa/state_tracker/st_program.c b/mesalib/src/mesa/state_tracker/st_program.c
index 692a57008..2f0ec32f5 100644
--- a/mesalib/src/mesa/state_tracker/st_program.c
+++ b/mesalib/src/mesa/state_tracker/st_program.c
@@ -1204,7 +1204,7 @@ st_get_gp_variant(struct st_context *st,
void
st_print_shaders(struct gl_context *ctx)
{
- struct gl_shader_program **shProg = ctx->Shader.CurrentProgram;
+ struct gl_shader_program **shProg = ctx->_Shader->CurrentProgram;
unsigned j;
for (j = 0; j < 3; j++) {
diff --git a/mesalib/src/mesa/state_tracker/st_texture.c b/mesalib/src/mesa/state_tracker/st_texture.c
index b5ccc76d4..a3b345356 100644
--- a/mesalib/src/mesa/state_tracker/st_texture.c
+++ b/mesalib/src/mesa/state_tracker/st_texture.c
@@ -412,3 +412,10 @@ st_create_color_map_texture(struct gl_context *ctx)
return pt;
}
+void
+st_texture_release_sampler_view(struct st_context *st,
+ struct st_texture_object *stObj)
+{
+ if (stObj->sampler_view && stObj->sampler_view->context == st->pipe)
+ pipe_sampler_view_reference(&stObj->sampler_view, NULL);
+}
diff --git a/mesalib/src/mesa/state_tracker/st_texture.h b/mesalib/src/mesa/state_tracker/st_texture.h
index bce2a0934..b4a27a00a 100644
--- a/mesalib/src/mesa/state_tracker/st_texture.h
+++ b/mesalib/src/mesa/state_tracker/st_texture.h
@@ -227,4 +227,8 @@ st_texture_image_copy(struct pipe_context *pipe,
extern struct pipe_resource *
st_create_color_map_texture(struct gl_context *ctx);
+extern void
+st_texture_release_sampler_view(struct st_context *st,
+ struct st_texture_object *stObj);
+
#endif