summaryrefslogtreecommitdiff
path: root/src/mesa/state_tracker
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa/state_tracker')
-rw-r--r--src/mesa/state_tracker/st_atom_constbuf.c3
-rw-r--r--src/mesa/state_tracker/st_atom_depth.c4
-rw-r--r--src/mesa/state_tracker/st_atom_framebuffer.c16
-rw-r--r--src/mesa/state_tracker/st_atom_pixeltransfer.c3
-rw-r--r--src/mesa/state_tracker/st_cb_accum.c13
-rw-r--r--src/mesa/state_tracker/st_cb_bitmap.c13
-rw-r--r--src/mesa/state_tracker/st_cb_clear.c13
-rw-r--r--src/mesa/state_tracker/st_cb_drawpixels.c40
-rw-r--r--src/mesa/state_tracker/st_cb_fbo.c32
-rw-r--r--src/mesa/state_tracker/st_cb_readpixels.c4
-rw-r--r--src/mesa/state_tracker/st_cb_texture.c85
-rw-r--r--src/mesa/state_tracker/st_context.c6
-rw-r--r--src/mesa/state_tracker/st_debug.c28
-rw-r--r--src/mesa/state_tracker/st_debug.h36
-rw-r--r--src/mesa/state_tracker/st_format.c12
-rw-r--r--src/mesa/state_tracker/st_format.h5
-rw-r--r--src/mesa/state_tracker/st_framebuffer.c7
-rw-r--r--src/mesa/state_tracker/st_gen_mipmap.c86
-rw-r--r--src/mesa/state_tracker/st_mesa_to_tgsi.c46
-rw-r--r--src/mesa/state_tracker/st_program.c20
-rw-r--r--src/mesa/state_tracker/st_texture.c24
21 files changed, 359 insertions, 137 deletions
diff --git a/src/mesa/state_tracker/st_atom_constbuf.c b/src/mesa/state_tracker/st_atom_constbuf.c
index 5d4d8eee02..77153889b6 100644
--- a/src/mesa/state_tracker/st_atom_constbuf.c
+++ b/src/mesa/state_tracker/st_atom_constbuf.c
@@ -39,6 +39,7 @@
#include "pipe/p_defines.h"
#include "pipe/p_inlines.h"
+#include "st_debug.h"
#include "st_context.h"
#include "st_atom.h"
#include "st_atom_constbuf.h"
@@ -75,7 +76,7 @@ void st_upload_constants( struct st_context *st,
PIPE_BUFFER_USAGE_CONSTANT,
paramBytes );
- if (0) {
+ if (ST_DEBUG & DEBUG_CONSTANTS) {
debug_printf("%s(shader=%d, numParams=%d, stateFlags=0x%x)\n",
__FUNCTION__, shader_type, params->NumParameters,
params->StateFlags);
diff --git a/src/mesa/state_tracker/st_atom_depth.c b/src/mesa/state_tracker/st_atom_depth.c
index 0aa128f947..88b80a07fc 100644
--- a/src/mesa/state_tracker/st_atom_depth.c
+++ b/src/mesa/state_tracker/st_atom_depth.c
@@ -104,10 +104,6 @@ update_depth_stencil_alpha(struct st_context *st)
dsa->depth.func = st_compare_func_to_pipe(ctx->Depth.Func);
}
- if (ctx->Query.CurrentOcclusionObject &&
- ctx->Query.CurrentOcclusionObject->Active)
- dsa->depth.occlusion_count = 1;
-
if (ctx->Stencil.Enabled && ctx->DrawBuffer->Visual.stencilBits > 0) {
dsa->stencil[0].enabled = 1;
dsa->stencil[0].func = st_compare_func_to_pipe(ctx->Stencil.Function[0]);
diff --git a/src/mesa/state_tracker/st_atom_framebuffer.c b/src/mesa/state_tracker/st_atom_framebuffer.c
index 5209a6a0c9..e18c0f6e0a 100644
--- a/src/mesa/state_tracker/st_atom_framebuffer.c
+++ b/src/mesa/state_tracker/st_atom_framebuffer.c
@@ -39,6 +39,7 @@
#include "pipe/p_context.h"
#include "pipe/p_inlines.h"
#include "cso_cache/cso_context.h"
+#include "util/u_rect.h"
@@ -162,10 +163,17 @@ update_framebuffer_state( struct st_context *st )
(void) st_get_framebuffer_surface(stfb, ST_SURFACE_FRONT_LEFT, &surf_front);
(void) st_get_framebuffer_surface(stfb, ST_SURFACE_BACK_LEFT, &surf_back);
- st->pipe->surface_copy(st->pipe,
- surf_front, 0, 0, /* dest */
- surf_back, 0, 0, /* src */
- fb->Width, fb->Height);
+ if (st->pipe->surface_copy) {
+ st->pipe->surface_copy(st->pipe,
+ surf_front, 0, 0, /* dest */
+ surf_back, 0, 0, /* src */
+ fb->Width, fb->Height);
+ } else {
+ util_surface_copy(st->pipe, FALSE,
+ surf_front, 0, 0,
+ surf_back, 0, 0,
+ fb->Width, fb->Height);
+ }
}
/* we're assuming we'll really draw to the front buffer */
st->frontbuffer_status = FRONT_STATUS_DIRTY;
diff --git a/src/mesa/state_tracker/st_atom_pixeltransfer.c b/src/mesa/state_tracker/st_atom_pixeltransfer.c
index eff3666ca8..babfcc87b4 100644
--- a/src/mesa/state_tracker/st_atom_pixeltransfer.c
+++ b/src/mesa/state_tracker/st_atom_pixeltransfer.c
@@ -122,7 +122,8 @@ create_color_map_texture(GLcontext *ctx)
const uint texSize = 256; /* simple, and usually perfect */
/* find an RGBA texture format */
- format = st_choose_format(pipe, GL_RGBA, PIPE_TEXTURE_2D, PIPE_TEXTURE_USAGE_SAMPLER);
+ format = st_choose_format(pipe->screen, GL_RGBA,
+ PIPE_TEXTURE_2D, PIPE_TEXTURE_USAGE_SAMPLER);
/* create texture for color map/table */
pt = st_texture_create(ctx->st, PIPE_TEXTURE_2D, format, 0,
diff --git a/src/mesa/state_tracker/st_cb_accum.c b/src/mesa/state_tracker/st_cb_accum.c
index 95181578f6..a6b9765452 100644
--- a/src/mesa/state_tracker/st_cb_accum.c
+++ b/src/mesa/state_tracker/st_cb_accum.c
@@ -34,6 +34,7 @@
#include "main/image.h"
#include "main/macros.h"
+#include "st_debug.h"
#include "st_context.h"
#include "st_cb_accum.h"
#include "st_cb_fbo.h"
@@ -136,6 +137,9 @@ accum_accum(struct st_context *st, GLfloat value,
GLubyte *data = acc_strb->data;
GLfloat *buf;
+ if (ST_DEBUG & DEBUG_FALLBACK)
+ debug_printf("%s: fallback processing\n", __FUNCTION__);
+
color_trans = st_cond_flush_get_tex_transfer(st, color_strb->texture,
0, 0, 0,
PIPE_TRANSFER_READ, xpos, ypos,
@@ -181,6 +185,10 @@ accum_load(struct st_context *st, GLfloat value,
GLubyte *data = acc_strb->data;
GLfloat *buf;
+
+ if (ST_DEBUG & DEBUG_FALLBACK)
+ debug_printf("%s: fallback processing\n", __FUNCTION__);
+
color_trans = st_cond_flush_get_tex_transfer(st, color_strb->texture,
0, 0, 0,
PIPE_TRANSFER_READ, xpos, ypos,
@@ -228,6 +236,9 @@ accum_return(GLcontext *ctx, GLfloat value,
const GLubyte *data = acc_strb->data;
GLfloat *buf;
+ if (ST_DEBUG & DEBUG_FALLBACK)
+ debug_printf("%s: fallback processing\n", __FUNCTION__);
+
buf = (GLfloat *) _mesa_malloc(width * height * 4 * sizeof(GLfloat));
if (!colormask[0] || !colormask[1] || !colormask[2] || !colormask[3])
@@ -241,7 +252,7 @@ accum_return(GLcontext *ctx, GLfloat value,
xpos, ypos,
width, height);
- if (usage != PIPE_TRANSFER_WRITE)
+ if (usage & PIPE_TRANSFER_READ)
pipe_get_tile_rgba(color_trans, 0, 0, width, height, buf);
switch (acc_strb->format) {
diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c
index 902fb38d1a..a22fa68299 100644
--- a/src/mesa/state_tracker/st_cb_bitmap.c
+++ b/src/mesa/state_tracker/st_cb_bitmap.c
@@ -330,7 +330,18 @@ setup_bitmap_vertex_data(struct st_context *st,
const GLfloat clip_y0 = (GLfloat)(y0 / fb_height * 2.0 - 1.0);
const GLfloat clip_x1 = (GLfloat)(x1 / fb_width * 2.0 - 1.0);
const GLfloat clip_y1 = (GLfloat)(y1 / fb_height * 2.0 - 1.0);
- const GLuint max_slots = 4096 / sizeof(st->bitmap.vertices);
+
+ /* XXX: Need to improve buffer_write to allow NO_WAIT (as well as
+ * no_flush) updates to buffers where we know there is no conflict
+ * with previous data. Currently using max_slots > 1 will cause
+ * synchronous rendering if the driver flushes its command buffers
+ * between one bitmap and the next. Our flush hook below isn't
+ * sufficient to catch this as the driver doesn't tell us when it
+ * flushes its own command buffers. Until this gets fixed, pay the
+ * price of allocating a new buffer for each bitmap cache-flush to
+ * avoid synchronous rendering.
+ */
+ const GLuint max_slots = 1; /* 4096 / sizeof(st->bitmap.vertices); */
GLuint i;
if (st->bitmap.vbuf_slot >= max_slots) {
diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c
index f015b12368..e83b6c92ef 100644
--- a/src/mesa/state_tracker/st_cb_clear.c
+++ b/src/mesa/state_tracker/st_cb_clear.c
@@ -117,7 +117,18 @@ draw_quad(GLcontext *ctx,
{
struct st_context *st = ctx->st;
struct pipe_context *pipe = st->pipe;
- const GLuint max_slots = 1024 / sizeof(st->clear.vertices);
+
+ /* XXX: Need to improve buffer_write to allow NO_WAIT (as well as
+ * no_flush) updates to buffers where we know there is no conflict
+ * with previous data. Currently using max_slots > 1 will cause
+ * synchronous rendering if the driver flushes its command buffers
+ * between one bitmap and the next. Our flush hook below isn't
+ * sufficient to catch this as the driver doesn't tell us when it
+ * flushes its own command buffers. Until this gets fixed, pay the
+ * price of allocating a new buffer for each bitmap cache-flush to
+ * avoid synchronous rendering.
+ */
+ const GLuint max_slots = 1; /* 1024 / sizeof(st->clear.vertices); */
GLuint i;
if (st->clear.vbuf_slot >= max_slots) {
diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c
index 3751c8717f..0a6bfcd3d1 100644
--- a/src/mesa/state_tracker/st_cb_drawpixels.c
+++ b/src/mesa/state_tracker/st_cb_drawpixels.c
@@ -41,6 +41,7 @@
#include "shader/prog_parameter.h"
#include "shader/prog_print.h"
+#include "st_debug.h"
#include "st_context.h"
#include "st_atom.h"
#include "st_atom_constbuf.h"
@@ -62,6 +63,7 @@
#include "util/u_tile.h"
#include "util/u_draw_quad.h"
#include "util/u_math.h"
+#include "util/u_rect.h"
#include "shader/prog_instruction.h"
#include "cso_cache/cso_context.h"
@@ -600,15 +602,15 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z,
/* viewport state: viewport matching window dims */
{
- const float width = (float) ctx->DrawBuffer->Width;
- const float height = (float) ctx->DrawBuffer->Height;
+ const float w = (float) ctx->DrawBuffer->Width;
+ const float h = (float) ctx->DrawBuffer->Height;
struct pipe_viewport_state vp;
- vp.scale[0] = 0.5f * width;
- vp.scale[1] = -0.5f * height;
+ vp.scale[0] = 0.5f * w;
+ vp.scale[1] = -0.5f * h;
vp.scale[2] = 1.0f;
vp.scale[3] = 1.0f;
- vp.translate[0] = 0.5f * width;
- vp.translate[1] = 0.5f * height;
+ vp.translate[0] = 0.5f * w;
+ vp.translate[1] = 0.5f * h;
vp.translate[2] = 0.0f;
vp.translate[3] = 0.0f;
cso_set_viewport(cso, &vp);
@@ -1016,13 +1018,14 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy,
else {
/* srcFormat can't be used as a texture format */
if (type == GL_DEPTH) {
- texFormat = st_choose_format(pipe, GL_DEPTH_COMPONENT, PIPE_TEXTURE_2D,
+ texFormat = st_choose_format(screen, GL_DEPTH_COMPONENT,
+ PIPE_TEXTURE_2D,
PIPE_TEXTURE_USAGE_DEPTH_STENCIL);
assert(texFormat != PIPE_FORMAT_NONE); /* XXX no depth texture formats??? */
}
else {
/* default color format */
- texFormat = st_choose_format(pipe, GL_RGBA, PIPE_TEXTURE_2D,
+ texFormat = st_choose_format(screen, GL_RGBA, PIPE_TEXTURE_2D,
PIPE_TEXTURE_USAGE_SAMPLER);
assert(texFormat != PIPE_FORMAT_NONE);
}
@@ -1075,11 +1078,19 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy,
PIPE_BUFFER_USAGE_GPU_READ);
struct pipe_surface *psTex = screen->get_tex_surface(screen, pt, 0, 0, 0,
PIPE_BUFFER_USAGE_GPU_WRITE );
- pipe->surface_copy(pipe,
- psTex, /* dest */
- 0, 0, /* destx/y */
- psRead,
- srcx, srcy, width, height);
+ if (pipe->surface_copy) {
+ pipe->surface_copy(pipe,
+ psTex, /* dest */
+ 0, 0, /* destx/y */
+ psRead,
+ srcx, srcy, width, height);
+ } else {
+ util_surface_copy(pipe, FALSE,
+ psTex,
+ 0, 0,
+ psRead,
+ srcx, srcy, width, height);
+ }
pipe_surface_reference(&psRead, NULL);
pipe_surface_reference(&psTex, NULL);
}
@@ -1092,6 +1103,9 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy,
struct pipe_transfer *ptTex;
enum pipe_transfer_usage transfer_usage;
+ if (ST_DEBUG & DEBUG_FALLBACK)
+ debug_printf("%s: fallback processing\n", __FUNCTION__);
+
if (type == GL_DEPTH && pf_is_depth_and_stencil(pt->format))
transfer_usage = PIPE_TRANSFER_READ_WRITE;
else
diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c
index 7899d745aa..65ce12ccd4 100644
--- a/src/mesa/state_tracker/st_cb_fbo.c
+++ b/src/mesa/state_tracker/st_cb_fbo.c
@@ -49,6 +49,7 @@
#include "st_public.h"
#include "st_texture.h"
+#include "util/u_rect.h"
/**
@@ -87,7 +88,7 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb,
if (strb->format != PIPE_FORMAT_NONE)
format = strb->format;
else
- format = st_choose_renderbuffer_format(pipe, internalFormat);
+ format = st_choose_renderbuffer_format(pipe->screen, internalFormat);
/* init renderbuffer fields */
strb->Base.Width = width;
@@ -159,12 +160,12 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb,
strb->texture,
0, 0, 0,
surface_usage );
-
- assert(strb->surface->texture);
- assert(strb->surface->format);
- assert(strb->surface->width == width);
- assert(strb->surface->height == height);
-
+ if (strb->surface) {
+ assert(strb->surface->texture);
+ assert(strb->surface->format);
+ assert(strb->surface->width == width);
+ assert(strb->surface->height == height);
+ }
return strb->surface != NULL;
}
@@ -286,6 +287,7 @@ st_new_renderbuffer_fb(enum pipe_format format, int samples, boolean sw)
default:
_mesa_problem(NULL,
"Unexpected format in st_new_renderbuffer_fb");
+ _mesa_free(strb);
return NULL;
}
@@ -371,6 +373,7 @@ st_render_texture(GLcontext *ctx,
rb->Width = texImage->Width2;
rb->Height = texImage->Height2;
+ rb->_BaseFormat = texImage->_BaseFormat;
/*printf("***** render to texture level %d: %d x %d\n", att->TextureLevel, rb->Width, rb->Height);*/
/*printf("***** pipe texture %d x %d\n", pt->width[0], pt->height[0]);*/
@@ -524,10 +527,17 @@ copy_back_to_front(struct st_context *st,
(void) st_get_framebuffer_surface(stfb, backIndex, &surf_back);
if (surf_front && surf_back) {
- st->pipe->surface_copy(st->pipe,
- surf_front, 0, 0, /* dest */
- surf_back, 0, 0, /* src */
- fb->Width, fb->Height);
+ if (st->pipe->surface_copy) {
+ st->pipe->surface_copy(st->pipe,
+ surf_front, 0, 0, /* dest */
+ surf_back, 0, 0, /* src */
+ fb->Width, fb->Height);
+ } else {
+ util_surface_copy(st->pipe, FALSE,
+ surf_front, 0, 0,
+ surf_back, 0, 0,
+ fb->Width, fb->Height);
+ }
}
}
diff --git a/src/mesa/state_tracker/st_cb_readpixels.c b/src/mesa/state_tracker/st_cb_readpixels.c
index 75424aa2e7..772bb3bb69 100644
--- a/src/mesa/state_tracker/st_cb_readpixels.c
+++ b/src/mesa/state_tracker/st_cb_readpixels.c
@@ -43,6 +43,7 @@
#include "pipe/p_inlines.h"
#include "util/u_tile.h"
+#include "st_debug.h"
#include "st_context.h"
#include "st_cb_bitmap.h"
#include "st_cb_readpixels.h"
@@ -416,6 +417,9 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height,
yStep = 1;
}
+ if (ST_DEBUG & DEBUG_FALLBACK)
+ debug_printf("%s: fallback processing\n", __FUNCTION__);
+
/*
* Copy pixels from pipe_transfer to user memory
*/
diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c
index e8bb720acc..878a40fae9 100644
--- a/src/mesa/state_tracker/st_cb_texture.c
+++ b/src/mesa/state_tracker/st_cb_texture.c
@@ -45,6 +45,7 @@
#include "main/texobj.h"
#include "main/texstore.h"
+#include "state_tracker/st_debug.h"
#include "state_tracker/st_context.h"
#include "state_tracker/st_cb_fbo.h"
#include "state_tracker/st_cb_texture.h"
@@ -330,10 +331,13 @@ guess_and_alloc_texture(struct st_context *st,
stObj->base.MinFilter == GL_LINEAR ||
stImage->base._BaseFormat == GL_DEPTH_COMPONENT ||
stImage->base._BaseFormat == GL_DEPTH_STENCIL_EXT) &&
+ !stObj->base.GenerateMipmap &&
stImage->level == firstLevel) {
+ /* only alloc space for a single mipmap level */
lastLevel = firstLevel;
}
else {
+ /* alloc space for a full mipmap */
GLuint l2width = util_logbase2(width);
GLuint l2height = util_logbase2(height);
GLuint l2depth = util_logbase2(depth);
@@ -894,6 +898,9 @@ decompress_with_blit(GLcontext * ctx, GLenum target, GLint level,
GLvoid *dest = _mesa_image_address2d(&ctx->Pack, pixels, width,
height, format, type, row, 0);
+ if (ST_DEBUG & DEBUG_FALLBACK)
+ debug_printf("%s: fallback format translation\n", __FUNCTION__);
+
/* get float[4] rgba row from surface */
pipe_get_tile_rgba(tex_xfer, 0, row, width, 1, rgba);
@@ -1285,6 +1292,9 @@ fallback_copy_texsubimage(GLcontext *ctx, GLenum target, GLint level,
struct pipe_transfer *src_trans;
GLvoid *texDest;
enum pipe_transfer_usage transfer_usage;
+
+ if (ST_DEBUG & DEBUG_FALLBACK)
+ debug_printf("%s: fallback processing\n", __FUNCTION__);
assert(width <= MAX_WIDTH);
@@ -1410,6 +1420,12 @@ compatible_src_dst_formats(const struct gl_renderbuffer *src,
return TGSI_WRITEMASK_XYZ; /* A ==> 1.0 */
}
else {
+ if (ST_DEBUG & DEBUG_FALLBACK)
+ debug_printf("%s failed for src %s, dst %s\n",
+ __FUNCTION__,
+ _mesa_lookup_enum_by_nr(srcFormat),
+ _mesa_lookup_enum_by_nr(dstLogicalFormat));
+
/* Otherwise fail.
*/
return 0;
@@ -1526,7 +1542,8 @@ st_copy_texsubimage(GLcontext *ctx,
if (ctx->_ImageTransferState == 0x0) {
- if (matching_base_formats &&
+ if (pipe->surface_copy &&
+ matching_base_formats &&
src_format == dest_format &&
!do_flip)
{
@@ -1689,53 +1706,6 @@ st_CopyTexSubImage3D(GLcontext * ctx, GLenum target, GLint level,
}
-/**
- * Compute which mipmap levels that really need to be sent to the hardware.
- * This depends on the base image size, GL_TEXTURE_MIN_LOD,
- * GL_TEXTURE_MAX_LOD, GL_TEXTURE_BASE_LEVEL, and GL_TEXTURE_MAX_LEVEL.
- */
-static void
-calculate_first_last_level(struct st_texture_object *stObj)
-{
- struct gl_texture_object *tObj = &stObj->base;
-
- /* These must be signed values. MinLod and MaxLod can be negative numbers,
- * and having firstLevel and lastLevel as signed prevents the need for
- * extra sign checks.
- */
- GLint firstLevel;
- GLint lastLevel;
-
- /* Yes, this looks overly complicated, but it's all needed.
- */
- switch (tObj->Target) {
- case GL_TEXTURE_1D:
- case GL_TEXTURE_2D:
- case GL_TEXTURE_3D:
- case GL_TEXTURE_CUBE_MAP:
- if (tObj->MinFilter == GL_NEAREST || tObj->MinFilter == GL_LINEAR) {
- /* GL_NEAREST and GL_LINEAR only care about GL_TEXTURE_BASE_LEVEL.
- */
- firstLevel = lastLevel = tObj->BaseLevel;
- }
- else {
- firstLevel = 0;
- lastLevel = MIN2(tObj->MaxLevel,
- (int) tObj->Image[0][tObj->BaseLevel]->WidthLog2);
- }
- break;
- case GL_TEXTURE_RECTANGLE_NV:
- case GL_TEXTURE_4D_SGIS:
- firstLevel = lastLevel = 0;
- break;
- default:
- return;
- }
-
- stObj->lastLevel = lastLevel;
-}
-
-
static void
copy_image_data_to_texture(struct st_context *st,
struct st_texture_object *stObj,
@@ -1799,13 +1769,20 @@ st_finalize_texture(GLcontext *ctx,
*needFlush = GL_FALSE;
- /* We know/require this is true by now:
- */
- assert(stObj->base._Complete);
+ if (stObj->base._Complete) {
+ /* The texture is complete and we know exactly how many mipmap levels
+ * are present/needed. This is conditional because we may be called
+ * from the st_generate_mipmap() function when the texture object is
+ * incomplete. In that case, we'll have set stObj->lastLevel before
+ * we get here.
+ */
+ if (stObj->base.MinFilter == GL_LINEAR ||
+ stObj->base.MinFilter == GL_NEAREST)
+ stObj->lastLevel = stObj->base.BaseLevel;
+ else
+ stObj->lastLevel = stObj->base._MaxLevel - stObj->base.BaseLevel;
+ }
- /* What levels must the texture include at a minimum?
- */
- calculate_first_last_level(stObj);
firstImage = st_texture_image(stObj->base.Image[0][stObj->base.BaseLevel]);
/* If both firstImage and stObj point to a texture which can contain
diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c
index 8514b6b375..f0eddafd33 100644
--- a/src/mesa/state_tracker/st_context.c
+++ b/src/mesa/state_tracker/st_context.c
@@ -36,6 +36,7 @@
#include "shader/shader_api.h"
#include "glapi/glapi.h"
#include "st_public.h"
+#include "st_debug.h"
#include "st_context.h"
#include "st_cb_accum.h"
#include "st_cb_bitmap.h"
@@ -113,6 +114,9 @@ st_create_context_priv( GLcontext *ctx, struct pipe_context *pipe )
st->ctx = ctx;
st->pipe = pipe;
+ /* XXX: this is one-off, per-screen init: */
+ st_debug_init();
+
/* state tracker needs the VBO module */
_vbo_CreateContext(ctx);
@@ -332,7 +336,7 @@ void st_init_driver_functions(struct dd_function_table *functions)
st_init_feedback_functions(functions);
#endif
st_init_program_functions(functions);
-#if FEATURE_ARB_occlusion_query
+#if FEATURE_queryobj
st_init_query_functions(functions);
#endif
st_init_readpixels_functions(functions);
diff --git a/src/mesa/state_tracker/st_debug.c b/src/mesa/state_tracker/st_debug.c
index c7d26ce33c..3009cde9d5 100644
--- a/src/mesa/state_tracker/st_debug.c
+++ b/src/mesa/state_tracker/st_debug.c
@@ -41,6 +41,32 @@
+#ifdef DEBUG
+int ST_DEBUG = 0;
+
+static const struct debug_named_value st_debug_flags[] = {
+ { "mesa", DEBUG_MESA },
+ { "tgsi", DEBUG_TGSI },
+ { "pipe", DEBUG_PIPE },
+ { "tex", DEBUG_TEX },
+ { "fallback", DEBUG_FALLBACK },
+ { "screen", DEBUG_SCREEN },
+ { "query", DEBUG_QUERY },
+ {NULL, 0}
+};
+#endif
+
+
+void
+st_debug_init(void)
+{
+#ifdef DEBUG
+ ST_DEBUG = debug_get_flags_option("ST_DEBUG", st_debug_flags, 0 );
+#endif
+}
+
+
+
/**
* Print current state. May be called from inside gdb to see currently
* bound vertex/fragment shaders and associated constants.
@@ -68,3 +94,5 @@ st_print_current(void)
if (st->fp->Base.Base.Parameters)
_mesa_print_parameter_list(st->fp->Base.Base.Parameters);
}
+
+
diff --git a/src/mesa/state_tracker/st_debug.h b/src/mesa/state_tracker/st_debug.h
index 49d752e1b2..4a060d7759 100644
--- a/src/mesa/state_tracker/st_debug.h
+++ b/src/mesa/state_tracker/st_debug.h
@@ -29,8 +29,44 @@
#ifndef ST_DEBUG_H
#define ST_DEBUG_H
+#include "pipe/p_compiler.h"
+#include "util/u_debug.h"
+
extern void
st_print_current(void);
+#define DEBUG_MESA 0x1
+#define DEBUG_TGSI 0x2
+#define DEBUG_CONSTANTS 0x4
+#define DEBUG_PIPE 0x8
+#define DEBUG_TEX 0x10
+#define DEBUG_FALLBACK 0x20
+#define DEBUG_QUERY 0x40
+#define DEBUG_SCREEN 0x80
+
+#ifdef DEBUG
+extern int ST_DEBUG;
+#define DBSTR(x) x
+#else
+#define ST_DEBUG 0
+#define DBSTR(x) ""
+#endif
+
+void st_debug_init( void );
+
+static INLINE void
+ST_DBG( unsigned flag, const char *fmt, ... )
+{
+ if (ST_DEBUG & flag)
+ {
+ va_list args;
+
+ va_start( args, fmt );
+ debug_vprintf( fmt, args );
+ va_end( args );
+ }
+}
+
+
#endif /* ST_DEBUG_H */
diff --git a/src/mesa/state_tracker/st_format.c b/src/mesa/state_tracker/st_format.c
index aa71b91ec8..0be2737272 100644
--- a/src/mesa/state_tracker/st_format.c
+++ b/src/mesa/state_tracker/st_format.c
@@ -455,10 +455,9 @@ default_depth_format(struct pipe_screen *screen,
* or PIPE_TEXTURE_USAGE_SAMPLER
*/
enum pipe_format
-st_choose_format(struct pipe_context *pipe, GLenum internalFormat,
+st_choose_format(struct pipe_screen *screen, GLenum internalFormat,
enum pipe_texture_target target, unsigned tex_usage)
{
- struct pipe_screen *screen = pipe->screen;
unsigned geom_flags = 0;
switch (internalFormat) {
@@ -681,14 +680,15 @@ is_depth_or_stencil_format(GLenum internalFormat)
* Called by FBO code to choose a PIPE_FORMAT_ for drawing surfaces.
*/
enum pipe_format
-st_choose_renderbuffer_format(struct pipe_context *pipe, GLenum internalFormat)
+st_choose_renderbuffer_format(struct pipe_screen *screen,
+ GLenum internalFormat)
{
uint usage;
if (is_depth_or_stencil_format(internalFormat))
usage = PIPE_TEXTURE_USAGE_DEPTH_STENCIL;
else
usage = PIPE_TEXTURE_USAGE_RENDER_TARGET;
- return st_choose_format(pipe, internalFormat, PIPE_TEXTURE_2D, usage);
+ return st_choose_format(screen, internalFormat, PIPE_TEXTURE_2D, usage);
}
@@ -776,8 +776,8 @@ st_ChooseTextureFormat(GLcontext *ctx, GLint internalFormat,
(void) format;
(void) type;
- pFormat = st_choose_format(ctx->st->pipe, internalFormat, PIPE_TEXTURE_2D,
- PIPE_TEXTURE_USAGE_SAMPLER);
+ pFormat = st_choose_format(ctx->st->pipe->screen, internalFormat,
+ PIPE_TEXTURE_2D, PIPE_TEXTURE_USAGE_SAMPLER);
if (pFormat == PIPE_FORMAT_NONE)
return MESA_FORMAT_NONE;
diff --git a/src/mesa/state_tracker/st_format.h b/src/mesa/state_tracker/st_format.h
index 97422bb199..7cddf5aa66 100644
--- a/src/mesa/state_tracker/st_format.h
+++ b/src/mesa/state_tracker/st_format.h
@@ -68,11 +68,12 @@ st_pipe_format_to_mesa_format(enum pipe_format pipeFormat);
extern enum pipe_format
-st_choose_format(struct pipe_context *pipe, GLenum internalFormat,
+st_choose_format(struct pipe_screen *screen, GLenum internalFormat,
enum pipe_texture_target target, unsigned tex_usage);
extern enum pipe_format
-st_choose_renderbuffer_format(struct pipe_context *pipe, GLenum internalFormat);
+st_choose_renderbuffer_format(struct pipe_screen *screen,
+ GLenum internalFormat);
extern gl_format
diff --git a/src/mesa/state_tracker/st_framebuffer.c b/src/mesa/state_tracker/st_framebuffer.c
index 5c0d335d62..a5d1ae3b03 100644
--- a/src/mesa/state_tracker/st_framebuffer.c
+++ b/src/mesa/state_tracker/st_framebuffer.c
@@ -52,6 +52,7 @@ st_create_framebuffer( const __GLcontextModes *visual,
struct st_framebuffer *stfb = ST_CALLOC_STRUCT(st_framebuffer);
if (stfb) {
int samples = st_get_msaa();
+ int i;
if (visual->sampleBuffers)
samples = visual->samples;
@@ -119,6 +120,12 @@ st_create_framebuffer( const __GLcontextModes *visual,
_mesa_add_renderbuffer(&stfb->Base, BUFFER_ACCUM, accumRb);
}
+ for (i = 0; i < visual->numAuxBuffers; i++) {
+ struct gl_renderbuffer *aux
+ = st_new_renderbuffer_fb(colorFormat, 0, FALSE);
+ _mesa_add_renderbuffer(&stfb->Base, BUFFER_AUX0 + i, aux);
+ }
+
stfb->Base.Initialized = GL_TRUE;
stfb->InitWidth = width;
stfb->InitHeight = height;
diff --git a/src/mesa/state_tracker/st_gen_mipmap.c b/src/mesa/state_tracker/st_gen_mipmap.c
index 58f6933652..16ca2771b0 100644
--- a/src/mesa/state_tracker/st_gen_mipmap.c
+++ b/src/mesa/state_tracker/st_gen_mipmap.c
@@ -27,6 +27,7 @@
#include "main/imports.h"
+#include "main/macros.h"
#include "main/mipmap.h"
#include "main/teximage.h"
#include "main/texformat.h"
@@ -41,6 +42,7 @@
#include "cso_cache/cso_cache.h"
#include "cso_cache/cso_context.h"
+#include "st_debug.h"
#include "st_context.h"
#include "st_draw.h"
#include "st_gen_mipmap.h"
@@ -112,6 +114,9 @@ fallback_generate_mipmap(GLcontext *ctx, GLenum target,
uint dstLevel;
GLenum datatype;
GLuint comps;
+
+ if (ST_DEBUG & DEBUG_FALLBACK)
+ debug_printf("%s: fallback processing\n", __FUNCTION__);
assert(target != GL_TEXTURE_3D); /* not done yet */
@@ -161,6 +166,43 @@ fallback_generate_mipmap(GLcontext *ctx, GLenum target,
}
+/**
+ * Compute the expected number of mipmap levels in the texture given
+ * the width/height/depth of the base image and the GL_TEXTURE_BASE_LEVEL/
+ * GL_TEXTURE_MAX_LEVEL settings. This will tell us how many mipmap
+ * level should be generated.
+ */
+static GLuint
+compute_num_levels(GLcontext *ctx,
+ struct gl_texture_object *texObj,
+ GLenum target)
+{
+ if (target == GL_TEXTURE_RECTANGLE_ARB) {
+ return 1;
+ }
+ else {
+ const GLuint maxLevels = texObj->MaxLevel - texObj->BaseLevel + 1;
+ const struct gl_texture_image *baseImage =
+ _mesa_get_tex_image(ctx, texObj, target, texObj->BaseLevel);
+ GLuint size, numLevels;
+
+ size = MAX2(baseImage->Width2, baseImage->Height2);
+ size = MAX2(size, baseImage->Depth2);
+
+ numLevels = 0;
+
+ while (size > 0) {
+ numLevels++;
+ size >>= 1;
+ }
+
+ numLevels = MIN2(numLevels, maxLevels);
+
+ return numLevels;
+ }
+}
+
+
void
st_generate_mipmap(GLcontext *ctx, GLenum target,
struct gl_texture_object *texObj)
@@ -174,9 +216,49 @@ st_generate_mipmap(GLcontext *ctx, GLenum target,
if (!pt)
return;
- lastLevel = pt->last_level;
+ /* find expected last mipmap level */
+ lastLevel = compute_num_levels(ctx, texObj, target) - 1;
+
+ if (pt->last_level < lastLevel) {
+ /* The current gallium texture doesn't have space for all the
+ * mipmap levels we need to generate. So allocate a new texture.
+ */
+ struct st_texture_object *stObj = st_texture_object(texObj);
+ struct pipe_texture *oldTex = stObj->pt;
+ GLboolean needFlush;
+
+ /* create new texture with space for more levels */
+ stObj->pt = st_texture_create(st,
+ oldTex->target,
+ oldTex->format,
+ lastLevel,
+ oldTex->width[0],
+ oldTex->height[0],
+ oldTex->depth[0],
+ oldTex->tex_usage);
+
+ /* The texture isn't in a "complete" state yet so set the expected
+ * lastLevel here, since it won't get done in st_finalize_texture().
+ */
+ stObj->lastLevel = lastLevel;
+
+ /* This will copy the old texture's base image into the new texture
+ * which we just allocated.
+ */
+ st_finalize_texture(ctx, st->pipe, texObj, &needFlush);
+
+ /* release the old tex (will likely be freed too) */
+ pipe_texture_reference(&oldTex, NULL);
+
+ pt = stObj->pt;
+ }
+
+ assert(lastLevel <= pt->last_level);
- if (!st_render_mipmap(st, target, pt, baseLevel, lastLevel)) {
+ /* Recall that the Mesa BaseLevel image is stored in the gallium
+ * texture's level[0] position. So pass baseLevel=0 here.
+ */
+ if (!st_render_mipmap(st, target, pt, 0, lastLevel)) {
fallback_generate_mipmap(ctx, target, texObj);
}
diff --git a/src/mesa/state_tracker/st_mesa_to_tgsi.c b/src/mesa/state_tracker/st_mesa_to_tgsi.c
index b0a1b529f1..3d6c215819 100644
--- a/src/mesa/state_tracker/st_mesa_to_tgsi.c
+++ b/src/mesa/state_tracker/st_mesa_to_tgsi.c
@@ -151,7 +151,7 @@ dst_register( struct st_translate *t,
return t->address[index];
default:
- assert( 0 );
+ debug_assert( 0 );
return ureg_dst_undef();
}
}
@@ -173,8 +173,9 @@ src_register( struct st_translate *t,
case PROGRAM_STATE_VAR:
case PROGRAM_NAMED_PARAM:
+ case PROGRAM_ENV_PARAM:
case PROGRAM_UNIFORM:
- case PROGRAM_CONSTANT:
+ case PROGRAM_CONSTANT: /* ie, immediate */
return t->constants[index];
case PROGRAM_INPUT:
@@ -187,7 +188,7 @@ src_register( struct st_translate *t,
return ureg_src(t->address[index]);
default:
- assert( 0 );
+ debug_assert( 0 );
return ureg_src_undef();
}
}
@@ -216,7 +217,7 @@ translate_texture_target( GLuint textarget,
case TEXTURE_CUBE_INDEX: return TGSI_TEXTURE_CUBE;
case TEXTURE_RECT_INDEX: return TGSI_TEXTURE_RECT;
default:
- assert( 0 );
+ debug_assert( 0 );
return TGSI_TEXTURE_1D;
}
}
@@ -386,7 +387,7 @@ static void emit_swz( struct st_translate *t,
swizzle_4v( imm, add_swizzle ) );
}
else {
- assert(0);
+ debug_assert(0);
}
#undef IMM_ZERO
@@ -480,14 +481,6 @@ translate_opcode( unsigned op )
return TGSI_OPCODE_MOV;
case OPCODE_MUL:
return TGSI_OPCODE_MUL;
- case OPCODE_NOISE1:
- return TGSI_OPCODE_NOISE1;
- case OPCODE_NOISE2:
- return TGSI_OPCODE_NOISE2;
- case OPCODE_NOISE3:
- return TGSI_OPCODE_NOISE3;
- case OPCODE_NOISE4:
- return TGSI_OPCODE_NOISE4;
case OPCODE_NOP:
return TGSI_OPCODE_NOP;
case OPCODE_NRM3:
@@ -522,8 +515,6 @@ translate_opcode( unsigned op )
return TGSI_OPCODE_SSG;
case OPCODE_SUB:
return TGSI_OPCODE_SUB;
- case OPCODE_SWZ:
- return TGSI_OPCODE_SWZ;
case OPCODE_TEX:
return TGSI_OPCODE_TEX;
case OPCODE_TXB:
@@ -539,7 +530,7 @@ translate_opcode( unsigned op )
case OPCODE_END:
return TGSI_OPCODE_END;
default:
- assert( 0 );
+ debug_assert( 0 );
return TGSI_OPCODE_NOP;
}
}
@@ -578,7 +569,7 @@ compile_instruction(
case OPCODE_ELSE:
case OPCODE_ENDLOOP:
case OPCODE_IF:
- assert(num_dst == 0);
+ debug_assert(num_dst == 0);
ureg_label_insn( ureg,
translate_opcode( inst->Opcode ),
src, num_src,
@@ -615,6 +606,21 @@ compile_instruction(
src, num_src );
break;
+ case OPCODE_NOISE1:
+ case OPCODE_NOISE2:
+ case OPCODE_NOISE3:
+ case OPCODE_NOISE4:
+ /* At some point, a motivated person could add a better
+ * implementation of noise. Currently not even the nvidia
+ * binary drivers do anything more than this. In any case, the
+ * place to do this is in the GL state tracker, not the poor
+ * driver.
+ */
+ ureg_MOV( ureg, dst[0], ureg_imm1f(ureg, 0.5) );
+ break;
+
+
+
default:
ureg_insn( ureg,
translate_opcode( inst->Opcode ),
@@ -761,7 +767,7 @@ st_translate_mesa_program(
outputSemanticIndex[i] );
break;
default:
- assert(0);
+ debug_assert(0);
return 0;
}
}
@@ -781,7 +787,7 @@ st_translate_mesa_program(
/* Declare address register.
*/
if (program->NumAddressRegs > 0) {
- assert( program->NumAddressRegs == 1 );
+ debug_assert( program->NumAddressRegs == 1 );
t->address[0] = ureg_DECL_address( ureg );
}
@@ -864,7 +870,7 @@ out:
if (!tokens) {
debug_printf("%s: failed to translate Mesa program:\n", __FUNCTION__);
_mesa_print_program(program);
- assert(0);
+ debug_assert(0);
}
return tokens;
diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c
index 927f60cc7e..a9be80ce8f 100644
--- a/src/mesa/state_tracker/st_program.c
+++ b/src/mesa/state_tracker/st_program.c
@@ -42,6 +42,7 @@
#include "draw/draw_context.h"
#include "tgsi/tgsi_dump.h"
+#include "st_debug.h"
#include "st_context.h"
#include "st_atom.h"
#include "st_program.h"
@@ -49,9 +50,6 @@
#include "cso_cache/cso_context.h"
-#define TGSI_DEBUG 0
-
-
/**
* Translate a Mesa vertex shader into a TGSI shader.
* \param outputMapping to map vertex program output registers (VERT_RESULT_x)
@@ -346,11 +344,15 @@ st_translate_vertex_program(struct st_context *st,
stvp->num_inputs = vs_num_inputs;
stvp->driver_shader = pipe->create_vs_state(pipe, &stvp->state);
- if (0)
+ if ((ST_DEBUG & DEBUG_TGSI) && (ST_DEBUG & DEBUG_MESA)) {
_mesa_print_program(&stvp->Base.Base);
+ debug_printf("\n");
+ }
- if (TGSI_DEBUG)
+ if (ST_DEBUG & DEBUG_TGSI) {
tgsi_dump( stvp->state.tokens, 0 );
+ debug_printf("\n");
+ }
}
@@ -526,11 +528,15 @@ st_translate_fragment_program(struct st_context *st,
stfp->driver_shader = pipe->create_fs_state(pipe, &stfp->state);
- if (0)
+ if ((ST_DEBUG & DEBUG_TGSI) && (ST_DEBUG & DEBUG_MESA)) {
_mesa_print_program(&stfp->Base.Base);
+ debug_printf("\n");
+ }
- if (TGSI_DEBUG)
+ if (ST_DEBUG & DEBUG_TGSI) {
tgsi_dump( stfp->state.tokens, 0/*TGSI_DUMP_VERBOSE*/ );
+ debug_printf("\n");
+ }
}
diff --git a/src/mesa/state_tracker/st_texture.c b/src/mesa/state_tracker/st_texture.c
index 4a883f9f0a..3945822f66 100644
--- a/src/mesa/state_tracker/st_texture.c
+++ b/src/mesa/state_tracker/st_texture.c
@@ -343,12 +343,21 @@ st_texture_image_copy(struct pipe_context *pipe,
src_surface = screen->get_tex_surface(screen, src, face, srcLevel, i,
PIPE_BUFFER_USAGE_GPU_READ);
- pipe->surface_copy(pipe,
- dst_surface,
- 0, 0, /* destX, Y */
- src_surface,
- 0, 0, /* srcX, Y */
- width, height);
+ if (pipe->surface_copy) {
+ pipe->surface_copy(pipe,
+ dst_surface,
+ 0, 0, /* destX, Y */
+ src_surface,
+ 0, 0, /* srcX, Y */
+ width, height);
+ } else {
+ util_surface_copy(pipe, FALSE,
+ dst_surface,
+ 0, 0, /* destX, Y */
+ src_surface,
+ 0, 0, /* srcX, Y */
+ width, height);
+ }
pipe_surface_reference(&src_surface, NULL);
pipe_surface_reference(&dst_surface, NULL);
@@ -578,7 +587,6 @@ st_teximage_flush_before_map(struct st_context *st,
pipe->is_texture_referenced(pipe, pt, face, level);
if (referenced && ((referenced & PIPE_REFERENCED_FOR_WRITE) ||
- usage == PIPE_TRANSFER_WRITE ||
- usage == PIPE_TRANSFER_READ_WRITE))
+ (usage & PIPE_TRANSFER_WRITE)))
st_flush(st, PIPE_FLUSH_RENDER_CACHE, NULL);
}