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.c5
-rw-r--r--src/mesa/state_tracker/st_atom_framebuffer.c16
-rw-r--r--src/mesa/state_tracker/st_atom_pixeltransfer.c9
-rw-r--r--src/mesa/state_tracker/st_atom_texture.c20
-rw-r--r--src/mesa/state_tracker/st_cb_accum.c17
-rw-r--r--src/mesa/state_tracker/st_cb_bitmap.c75
-rw-r--r--src/mesa/state_tracker/st_cb_blit.c15
-rw-r--r--src/mesa/state_tracker/st_cb_clear.c5
-rw-r--r--src/mesa/state_tracker/st_cb_drawpixels.c209
-rw-r--r--src/mesa/state_tracker/st_cb_fbo.c51
-rw-r--r--src/mesa/state_tracker/st_cb_fbo.h6
-rw-r--r--src/mesa/state_tracker/st_cb_flush.c6
-rw-r--r--src/mesa/state_tracker/st_cb_readpixels.c44
-rw-r--r--src/mesa/state_tracker/st_cb_texture.c57
-rw-r--r--src/mesa/state_tracker/st_context.c40
-rw-r--r--src/mesa/state_tracker/st_context.h15
-rw-r--r--src/mesa/state_tracker/st_draw.c20
-rw-r--r--src/mesa/state_tracker/st_draw_feedback.c1
-rw-r--r--src/mesa/state_tracker/st_extensions.c13
-rw-r--r--src/mesa/state_tracker/st_framebuffer.c1
-rw-r--r--src/mesa/state_tracker/st_gen_mipmap.c25
-rw-r--r--src/mesa/state_tracker/st_inlines.h10
-rw-r--r--src/mesa/state_tracker/st_manager.c800
-rw-r--r--src/mesa/state_tracker/st_manager.h47
-rw-r--r--src/mesa/state_tracker/st_public.h3
-rw-r--r--src/mesa/state_tracker/st_texture.c47
-rw-r--r--src/mesa/state_tracker/st_texture.h39
27 files changed, 1309 insertions, 287 deletions
diff --git a/src/mesa/state_tracker/st_atom.c b/src/mesa/state_tracker/st_atom.c
index 7806df4a53..9fa4dae5ca 100644
--- a/src/mesa/state_tracker/st_atom.c
+++ b/src/mesa/state_tracker/st_atom.c
@@ -34,6 +34,7 @@
#include "st_atom.h"
#include "st_cb_bitmap.h"
#include "st_program.h"
+#include "st_manager.h"
#include "pipe/p_context.h"
@@ -136,9 +137,7 @@ void st_validate_state( struct st_context *st )
check_program_state( st );
- if (st->pipe->screen->update_buffer)
- st->pipe->screen->update_buffer(st->pipe->screen,
- st->pipe->priv);
+ st_manager_validate_framebuffers(st);
if (state->st == 0)
return;
diff --git a/src/mesa/state_tracker/st_atom_framebuffer.c b/src/mesa/state_tracker/st_atom_framebuffer.c
index fba7bfe2ce..79ad70909a 100644
--- a/src/mesa/state_tracker/st_atom_framebuffer.c
+++ b/src/mesa/state_tracker/st_atom_framebuffer.c
@@ -38,7 +38,6 @@
#include "st_texture.h"
#include "pipe/p_context.h"
#include "cso_cache/cso_context.h"
-#include "util/u_rect.h"
#include "util/u_math.h"
#include "util/u_inlines.h"
@@ -164,17 +163,10 @@ 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);
- 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);
- }
+ st->pipe->surface_copy(st->pipe,
+ surf_front, 0, 0, /* dest */
+ surf_back, 0, 0, /* src */
+ 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 0b2e3f5381..03e3336144 100644
--- a/src/mesa/state_tracker/st_atom_pixeltransfer.c
+++ b/src/mesa/state_tracker/st_atom_pixeltransfer.c
@@ -138,7 +138,6 @@ static void
load_color_map_texture(GLcontext *ctx, struct pipe_texture *pt)
{
struct pipe_context *pipe = ctx->st->pipe;
- struct pipe_screen *screen = pipe->screen;
struct pipe_transfer *transfer;
const GLuint rSize = ctx->PixelMaps.RtoR.Size;
const GLuint gSize = ctx->PixelMaps.GtoG.Size;
@@ -151,7 +150,7 @@ load_color_map_texture(GLcontext *ctx, struct pipe_texture *pt)
transfer = st_cond_flush_get_tex_transfer(st_context(ctx),
pt, 0, 0, 0, PIPE_TRANSFER_WRITE,
0, 0, texSize, texSize);
- dest = (uint *) screen->transfer_map(screen, transfer);
+ dest = (uint *) pipe->transfer_map(pipe, transfer);
/* Pack four 1D maps into a 2D texture:
* R map is placed horizontally, indexed by S, in channel 0
@@ -172,8 +171,8 @@ load_color_map_texture(GLcontext *ctx, struct pipe_texture *pt)
}
}
- screen->transfer_unmap(screen, transfer);
- screen->tex_transfer_destroy(transfer);
+ pipe->transfer_unmap(pipe, transfer);
+ pipe->tex_transfer_destroy(pipe, transfer);
}
@@ -257,6 +256,8 @@ get_pixel_transfer_program(GLcontext *ctx, const struct state_key *key)
/* create the colormap/texture now if not already done */
if (!st->pixel_xfer.pixelmap_texture) {
st->pixel_xfer.pixelmap_texture = create_color_map_texture(ctx);
+ st->pixel_xfer.pixelmap_sampler_view = st_sampler_view_from_texture(ctx->st->pipe,
+ st->pixel_xfer.pixelmap_texture);
}
/* with a little effort, we can do four pixel map look-ups with
diff --git a/src/mesa/state_tracker/st_atom_texture.c b/src/mesa/state_tracker/st_atom_texture.c
index 57b71c1e7b..241c001f94 100644
--- a/src/mesa/state_tracker/st_atom_texture.c
+++ b/src/mesa/state_tracker/st_atom_texture.c
@@ -56,7 +56,7 @@ update_textures(struct st_context *st)
/* loop over sampler units (aka tex image units) */
for (su = 0; su < st->ctx->Const.MaxTextureImageUnits; su++) {
- struct pipe_texture *pt = NULL;
+ struct pipe_sampler_view *sampler_view = NULL;
if (samplersUsed & (1 << su)) {
struct gl_texture_object *texObj;
@@ -84,7 +84,7 @@ update_textures(struct st_context *st)
st->state.num_textures = su + 1;
- pt = st_get_stobj_texture(stObj);
+ sampler_view = st_get_stobj_sampler_view(stObj);
}
/*
@@ -96,17 +96,17 @@ update_textures(struct st_context *st)
}
*/
- pipe_texture_reference(&st->state.sampler_texture[su], pt);
+ pipe_sampler_view_reference(&st->state.sampler_views[su], sampler_view);
}
- cso_set_sampler_textures(st->cso_context,
- st->state.num_textures,
- st->state.sampler_texture);
+ cso_set_fragment_sampler_views(st->cso_context,
+ st->state.num_textures,
+ st->state.sampler_views);
if (st->ctx->Const.MaxVertexTextureImageUnits > 0) {
- cso_set_vertex_sampler_textures(st->cso_context,
- MIN2(st->state.num_textures,
- st->ctx->Const.MaxVertexTextureImageUnits),
- st->state.sampler_texture);
+ cso_set_vertex_sampler_views(st->cso_context,
+ MIN2(st->state.num_textures,
+ st->ctx->Const.MaxVertexTextureImageUnits),
+ st->state.sampler_views);
}
}
diff --git a/src/mesa/state_tracker/st_cb_accum.c b/src/mesa/state_tracker/st_cb_accum.c
index 33e43ddcc4..01aba3e3dd 100644
--- a/src/mesa/state_tracker/st_cb_accum.c
+++ b/src/mesa/state_tracker/st_cb_accum.c
@@ -129,7 +129,6 @@ accum_accum(struct st_context *st, GLfloat value,
struct st_renderbuffer *color_strb)
{
struct pipe_context *pipe = st->pipe;
- struct pipe_screen *screen = pipe->screen;
struct pipe_transfer *color_trans;
size_t stride = acc_strb->stride;
GLubyte *data = acc_strb->data;
@@ -145,7 +144,7 @@ accum_accum(struct st_context *st, GLfloat value,
buf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat));
- pipe_get_tile_rgba(color_trans, 0, 0, width, height, buf);
+ pipe_get_tile_rgba(pipe, color_trans, 0, 0, width, height, buf);
switch (acc_strb->format) {
case PIPE_FORMAT_R16G16B16A16_SNORM:
@@ -166,7 +165,7 @@ accum_accum(struct st_context *st, GLfloat value,
}
free(buf);
- screen->tex_transfer_destroy(color_trans);
+ pipe->tex_transfer_destroy(pipe, color_trans);
}
@@ -177,7 +176,6 @@ accum_load(struct st_context *st, GLfloat value,
struct st_renderbuffer *color_strb)
{
struct pipe_context *pipe = st->pipe;
- struct pipe_screen *screen = pipe->screen;
struct pipe_transfer *color_trans;
size_t stride = acc_strb->stride;
GLubyte *data = acc_strb->data;
@@ -194,7 +192,7 @@ accum_load(struct st_context *st, GLfloat value,
buf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat));
- pipe_get_tile_rgba(color_trans, 0, 0, width, height, buf);
+ pipe_get_tile_rgba(pipe, color_trans, 0, 0, width, height, buf);
switch (acc_strb->format) {
case PIPE_FORMAT_R16G16B16A16_SNORM:
@@ -215,7 +213,7 @@ accum_load(struct st_context *st, GLfloat value,
}
free(buf);
- screen->tex_transfer_destroy(color_trans);
+ pipe->tex_transfer_destroy(pipe, color_trans);
}
@@ -226,7 +224,6 @@ accum_return(GLcontext *ctx, GLfloat value,
struct st_renderbuffer *color_strb)
{
struct pipe_context *pipe = ctx->st->pipe;
- struct pipe_screen *screen = pipe->screen;
const GLubyte *colormask = ctx->Color.ColorMask[0];
enum pipe_transfer_usage usage;
struct pipe_transfer *color_trans;
@@ -251,7 +248,7 @@ accum_return(GLcontext *ctx, GLfloat value,
width, height);
if (usage & PIPE_TRANSFER_READ)
- pipe_get_tile_rgba(color_trans, 0, 0, width, height, buf);
+ pipe_get_tile_rgba(pipe, color_trans, 0, 0, width, height, buf);
switch (acc_strb->format) {
case PIPE_FORMAT_R16G16B16A16_SNORM:
@@ -280,10 +277,10 @@ accum_return(GLcontext *ctx, GLfloat value,
_mesa_problem(NULL, "unexpected format in st_clear_accum_buffer()");
}
- pipe_put_tile_rgba(color_trans, 0, 0, width, height, buf);
+ pipe_put_tile_rgba(pipe, color_trans, 0, 0, width, height, buf);
free(buf);
- screen->tex_transfer_destroy(color_trans);
+ pipe->tex_transfer_destroy(pipe, color_trans);
}
diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c
index 0332d4dbdf..9a0446bb71 100644
--- a/src/mesa/state_tracker/st_cb_bitmap.c
+++ b/src/mesa/state_tracker/st_cb_bitmap.c
@@ -259,7 +259,6 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height,
const GLubyte *bitmap)
{
struct pipe_context *pipe = ctx->st->pipe;
- struct pipe_screen *screen = pipe->screen;
struct pipe_transfer *transfer;
ubyte *dest;
struct pipe_texture *pt;
@@ -285,7 +284,7 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height,
PIPE_TRANSFER_WRITE,
0, 0, width, height);
- dest = screen->transfer_map(screen, transfer);
+ dest = pipe->transfer_map(pipe, transfer);
/* Put image into texture transfer */
memset(dest, 0xff, height * transfer->stride);
@@ -295,8 +294,8 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height,
_mesa_unmap_pbo_source(ctx, unpack);
/* Release transfer */
- screen->transfer_unmap(screen, transfer);
- screen->tex_transfer_destroy(transfer);
+ pipe->transfer_unmap(pipe, transfer);
+ pipe->tex_transfer_destroy(pipe, transfer);
return pt;
}
@@ -398,7 +397,7 @@ setup_bitmap_vertex_data(struct st_context *st,
static void
draw_bitmap_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z,
GLsizei width, GLsizei height,
- struct pipe_texture *pt,
+ struct pipe_sampler_view *sv,
const GLfloat *color)
{
struct st_context *st = ctx->st;
@@ -436,10 +435,11 @@ draw_bitmap_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z,
cso_save_rasterizer(cso);
cso_save_samplers(cso);
- cso_save_sampler_textures(cso);
+ cso_save_fragment_sampler_views(cso);
cso_save_viewport(cso);
cso_save_fragment_shader(cso);
cso_save_vertex_shader(cso);
+ cso_save_vertex_elements(cso);
/* rasterizer state: just scissor */
st->bitmap.rasterizer.scissor = ctx->Scissor.Enabled;
@@ -465,11 +465,11 @@ draw_bitmap_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z,
/* user textures, plus the bitmap texture */
{
- struct pipe_texture *textures[PIPE_MAX_SAMPLERS];
+ struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS];
uint num = MAX2(stfp->bitmap_sampler + 1, st->state.num_textures);
- memcpy(textures, st->state.sampler_texture, sizeof(textures));
- textures[stfp->bitmap_sampler] = pt;
- cso_set_sampler_textures(cso, num, textures);
+ memcpy(sampler_views, st->state.sampler_views, sizeof(sampler_views));
+ sampler_views[stfp->bitmap_sampler] = sv;
+ cso_set_fragment_sampler_views(cso, num, sampler_views);
}
/* viewport state: viewport matching window dims */
@@ -490,6 +490,8 @@ draw_bitmap_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z,
cso_set_viewport(cso, &vp);
}
+ cso_set_vertex_elements(cso, 3, st->velems_util_draw);
+
/* convert Z from [0,1] to [-1,-1] to match viewport Z scale/bias */
z = z * 2.0 - 1.0;
@@ -505,10 +507,11 @@ draw_bitmap_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z,
/* restore state */
cso_restore_rasterizer(cso);
cso_restore_samplers(cso);
- cso_restore_sampler_textures(cso);
+ cso_restore_fragment_sampler_views(cso);
cso_restore_viewport(cso);
cso_restore_fragment_shader(cso);
cso_restore_vertex_shader(cso);
+ cso_restore_vertex_elements(cso);
}
@@ -516,7 +519,6 @@ static void
reset_cache(struct st_context *st)
{
struct pipe_context *pipe = st->pipe;
- struct pipe_screen *screen = pipe->screen;
struct bitmap_cache *cache = st->bitmap.cache;
/*memset(cache->buffer, 0xff, sizeof(cache->buffer));*/
@@ -528,7 +530,7 @@ reset_cache(struct st_context *st)
cache->ymax = -1000000;
if (cache->trans) {
- screen->tex_transfer_destroy(cache->trans);
+ pipe->tex_transfer_destroy(pipe, cache->trans);
cache->trans = NULL;
}
@@ -566,7 +568,6 @@ static void
create_cache_trans(struct st_context *st)
{
struct pipe_context *pipe = st->pipe;
- struct pipe_screen *screen = pipe->screen;
struct bitmap_cache *cache = st->bitmap.cache;
if (cache->trans)
@@ -579,7 +580,7 @@ create_cache_trans(struct st_context *st)
PIPE_TRANSFER_WRITE, 0, 0,
BITMAP_CACHE_WIDTH,
BITMAP_CACHE_HEIGHT);
- cache->buffer = screen->transfer_map(screen, cache->trans);
+ cache->buffer = pipe->transfer_map(pipe, cache->trans);
/* init image to all 0xff */
memset(cache->buffer, 0xff, cache->trans->stride * BITMAP_CACHE_HEIGHT);
@@ -597,7 +598,7 @@ st_flush_bitmap_cache(struct st_context *st)
if (st->ctx->DrawBuffer) {
struct pipe_context *pipe = st->pipe;
- struct pipe_screen *screen = pipe->screen;
+ struct pipe_sampler_view *sv;
assert(cache->xmin <= cache->xmax);
@@ -613,20 +614,25 @@ st_flush_bitmap_cache(struct st_context *st)
if (cache->trans) {
if (0)
print_cache(cache);
- screen->transfer_unmap(screen, cache->trans);
+ pipe->transfer_unmap(pipe, cache->trans);
cache->buffer = NULL;
- screen->tex_transfer_destroy(cache->trans);
+ pipe->tex_transfer_destroy(pipe, cache->trans);
cache->trans = NULL;
}
- draw_bitmap_quad(st->ctx,
- cache->xpos,
- cache->ypos,
- cache->zpos,
- BITMAP_CACHE_WIDTH, BITMAP_CACHE_HEIGHT,
- cache->texture,
- cache->color);
+ sv = st_sampler_view_from_texture(st->pipe, cache->texture);
+ if (sv) {
+ draw_bitmap_quad(st->ctx,
+ cache->xpos,
+ cache->ypos,
+ cache->zpos,
+ BITMAP_CACHE_WIDTH, BITMAP_CACHE_HEIGHT,
+ sv,
+ cache->color);
+
+ pipe_sampler_view_reference(&sv, NULL);
+ }
}
/* release/free the texture */
@@ -749,10 +755,18 @@ st_Bitmap(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height,
pt = make_bitmap_texture(ctx, width, height, unpack, bitmap);
if (pt) {
+ struct pipe_sampler_view *sv = st_sampler_view_from_texture(st->pipe, pt);
+
assert(pt->target == PIPE_TEXTURE_2D);
- draw_bitmap_quad(ctx, x, y, ctx->Current.RasterPos[2],
- width, height, pt,
- st->ctx->Current.RasterColor);
+
+ if (sv) {
+ draw_bitmap_quad(ctx, x, y, ctx->Current.RasterPos[2],
+ width, height, sv,
+ st->ctx->Current.RasterColor);
+
+ pipe_sampler_view_reference(&sv, NULL);
+ }
+
/* release/free the texture */
pipe_texture_reference(&pt, NULL);
}
@@ -819,7 +833,6 @@ void
st_destroy_bitmap(struct st_context *st)
{
struct pipe_context *pipe = st->pipe;
- struct pipe_screen *screen = pipe->screen;
struct bitmap_cache *cache = st->bitmap.cache;
@@ -836,8 +849,8 @@ st_destroy_bitmap(struct st_context *st)
if (cache) {
if (cache->trans) {
- screen->transfer_unmap(screen, cache->trans);
- screen->tex_transfer_destroy(cache->trans);
+ pipe->transfer_unmap(pipe, cache->trans);
+ pipe->tex_transfer_destroy(pipe, cache->trans);
}
pipe_texture_reference(&st->bitmap.cache->texture, NULL);
free(st->bitmap.cache);
diff --git a/src/mesa/state_tracker/st_cb_blit.c b/src/mesa/state_tracker/st_cb_blit.c
index 36e03018d9..06b0a18fd2 100644
--- a/src/mesa/state_tracker/st_cb_blit.c
+++ b/src/mesa/state_tracker/st_cb_blit.c
@@ -69,6 +69,7 @@ st_BlitFramebuffer(GLcontext *ctx,
const GLbitfield depthStencil = (GL_DEPTH_BUFFER_BIT |
GL_STENCIL_BUFFER_BIT);
struct st_context *st = ctx->st;
+ struct pipe_context *pipe = st->pipe;
const uint pFilter = ((filter == GL_NEAREST)
? PIPE_TEX_MIPFILTER_NEAREST
: PIPE_TEX_MIPFILTER_LINEAR);
@@ -111,8 +112,8 @@ st_BlitFramebuffer(GLcontext *ctx,
&readFB->Attachment[readFB->_ColorReadBufferIndex];
if(srcAtt->Type == GL_TEXTURE) {
- struct pipe_screen *screen = ctx->st->pipe->screen;
- const struct st_texture_object *srcObj =
+ struct pipe_screen *screen = pipe->screen;
+ struct st_texture_object *srcObj =
st_texture_object(srcAtt->Texture);
struct st_renderbuffer *dstRb =
st_renderbuffer(drawFB->_ColorDrawBuffers[0]);
@@ -132,7 +133,8 @@ st_BlitFramebuffer(GLcontext *ctx,
return;
util_blit_pixels(st->blit,
- srcSurf, srcX0, srcY0, srcX1, srcY1,
+ srcSurf, st_get_stobj_sampler_view(srcObj),
+ srcX0, srcY0, srcX1, srcY1,
dstSurf, dstX0, dstY0, dstX1, dstY1,
0.0, pFilter);
@@ -144,10 +146,11 @@ st_BlitFramebuffer(GLcontext *ctx,
struct st_renderbuffer *dstRb =
st_renderbuffer(drawFB->_ColorDrawBuffers[0]);
struct pipe_surface *srcSurf = srcRb->surface;
+ struct pipe_sampler_view *srcView = st_renderbuffer_get_sampler_view(srcRb, pipe);
struct pipe_surface *dstSurf = dstRb->surface;
util_blit_pixels(st->blit,
- srcSurf, srcX0, srcY0, srcX1, srcY1,
+ srcSurf, srcView, srcX0, srcY0, srcX1, srcY1,
dstSurf, dstX0, dstY0, dstX1, dstY1,
0.0, pFilter);
}
@@ -179,11 +182,13 @@ st_BlitFramebuffer(GLcontext *ctx,
if ((mask & depthStencil) == depthStencil &&
srcDepthSurf == srcStencilSurf &&
dstDepthSurf == dstStencilSurf) {
+ struct pipe_sampler_view *srcView = st_renderbuffer_get_sampler_view(srcDepthRb, pipe);
+
/* Blitting depth and stencil values between combined
* depth/stencil buffers. This is the ideal case for such buffers.
*/
util_blit_pixels(st->blit,
- srcDepthSurf, srcX0, srcY0, srcX1, srcY1,
+ srcDepthSurf, srcView, srcX0, srcY0, srcX1, srcY1,
dstDepthSurf, dstX0, dstY0, dstX1, dstY1,
0.0, pFilter);
}
diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c
index 9e66eed363..de86062fc4 100644
--- a/src/mesa/state_tracker/st_cb_clear.c
+++ b/src/mesa/state_tracker/st_cb_clear.c
@@ -213,6 +213,7 @@ clear_with_quad(GLcontext *ctx,
cso_save_clip(st->cso_context);
cso_save_fragment_shader(st->cso_context);
cso_save_vertex_shader(st->cso_context);
+ cso_save_vertex_elements(st->cso_context);
/* blend state: RGBA masking */
{
@@ -264,6 +265,8 @@ clear_with_quad(GLcontext *ctx,
cso_set_depth_stencil_alpha(st->cso_context, &depth_stencil);
}
+ cso_set_vertex_elements(st->cso_context, 2, st->velems_util_draw);
+
cso_set_rasterizer(st->cso_context, &st->clear.raster);
/* viewport state: viewport matching window dims */
@@ -297,6 +300,8 @@ clear_with_quad(GLcontext *ctx,
cso_restore_clip(st->cso_context);
cso_restore_fragment_shader(st->cso_context);
cso_restore_vertex_shader(st->cso_context);
+ cso_restore_vertex_elements(st->cso_context);
+
}
diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c
index b937288f8c..c9d1e9c6c4 100644
--- a/src/mesa/state_tracker/st_cb_drawpixels.c
+++ b/src/mesa/state_tracker/st_cb_drawpixels.c
@@ -59,7 +59,6 @@
#include "util/u_draw_quad.h"
#include "util/u_format.h"
#include "util/u_math.h"
-#include "util/u_rect.h"
#include "shader/prog_instruction.h"
#include "cso_cache/cso_context.h"
@@ -293,6 +292,51 @@ base_format(GLenum format)
/**
+ * Create a temporary texture to hold an image of the given size.
+ * If width, height are not POT and the driver only handles POT textures,
+ * allocate the next larger size of texture that is POT.
+ */
+static struct pipe_texture *
+alloc_texture(struct st_context *st, GLsizei width, GLsizei height,
+ enum pipe_format texFormat)
+{
+ struct pipe_context *pipe = st->pipe;
+ struct pipe_screen *screen = pipe->screen;
+ struct pipe_texture *pt;
+ int ptw, pth;
+
+ ptw = width;
+ pth = height;
+
+ /* Need to use POT texture? */
+ if (!screen->get_param(screen, PIPE_CAP_NPOT_TEXTURES)) {
+ int l2pt, maxSize;
+
+ l2pt = util_logbase2(width);
+ if (1 << l2pt != width) {
+ ptw = 1 << (l2pt + 1);
+ }
+
+ l2pt = util_logbase2(height);
+ if (1 << l2pt != height) {
+ pth = 1 << (l2pt + 1);
+ }
+
+ /* Check against maximum texture size */
+ maxSize = 1 << (pipe->screen->get_param(pipe->screen,
+ PIPE_CAP_MAX_TEXTURE_2D_LEVELS) - 1);
+ assert(ptw <= maxSize);
+ assert(pth <= maxSize);
+ }
+
+ pt = st_texture_create(st, PIPE_TEXTURE_2D, texFormat, 0,
+ ptw, pth, 1, PIPE_TEXTURE_USAGE_SAMPLER);
+
+ return pt;
+}
+
+
+/**
* Make texture containing an image for glDrawPixels image.
* If 'pixels' is NULL, leave the texture image data undefined.
*/
@@ -304,13 +348,11 @@ make_texture(struct st_context *st,
{
GLcontext *ctx = st->ctx;
struct pipe_context *pipe = st->pipe;
- struct pipe_screen *screen = pipe->screen;
gl_format mformat;
struct pipe_texture *pt;
enum pipe_format pipeFormat;
GLuint cpp;
GLenum baseFormat;
- int ptw, pth;
baseFormat = base_format(format);
@@ -325,29 +367,8 @@ make_texture(struct st_context *st,
if (!pixels)
return NULL;
- /* Need to use POT texture? */
- ptw = width;
- pth = height;
- if (!screen->get_param(screen, PIPE_CAP_NPOT_TEXTURES)) {
- int l2pt, maxSize;
-
- l2pt = util_logbase2(width);
- if (1<<l2pt != width) {
- ptw = 1<<(l2pt+1);
- }
- l2pt = util_logbase2(height);
- if (1<<l2pt != height) {
- pth = 1<<(l2pt+1);
- }
-
- /* Check against maximum texture size */
- maxSize = 1 << (pipe->screen->get_param(pipe->screen, PIPE_CAP_MAX_TEXTURE_2D_LEVELS) - 1);
- assert(ptw <= maxSize);
- assert(pth <= maxSize);
- }
-
- pt = st_texture_create(st, PIPE_TEXTURE_2D, pipeFormat, 0, ptw, pth, 1,
- PIPE_TEXTURE_USAGE_SAMPLER);
+ /* alloc temporary texture */
+ pt = alloc_texture(st, width, height, pipeFormat);
if (!pt) {
_mesa_unmap_pbo_source(ctx, unpack);
return NULL;
@@ -368,7 +389,7 @@ make_texture(struct st_context *st,
width, height);
/* map texture transfer */
- dest = screen->transfer_map(screen, transfer);
+ dest = pipe->transfer_map(pipe, transfer);
/* Put image into texture transfer.
@@ -388,8 +409,8 @@ make_texture(struct st_context *st,
unpack);
/* unmap */
- screen->transfer_unmap(screen, transfer);
- screen->tex_transfer_destroy(transfer);
+ pipe->transfer_unmap(pipe, transfer);
+ pipe->tex_transfer_destroy(pipe, transfer);
assert(success);
@@ -503,7 +524,7 @@ static void
draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z,
GLsizei width, GLsizei height,
GLfloat zoomX, GLfloat zoomY,
- struct pipe_texture *pt,
+ struct pipe_sampler_view *sv,
void *driver_vp,
void *driver_fp,
const GLfloat *color,
@@ -526,9 +547,10 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z,
cso_save_rasterizer(cso);
cso_save_viewport(cso);
cso_save_samplers(cso);
- cso_save_sampler_textures(cso);
+ cso_save_fragment_sampler_views(cso);
cso_save_fragment_shader(cso);
cso_save_vertex_shader(cso);
+ cso_save_vertex_elements(cso);
/* rasterizer state: just scissor */
{
@@ -581,15 +603,17 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z,
cso_set_viewport(cso, &vp);
}
+ cso_set_vertex_elements(cso, 3, st->velems_util_draw);
+
/* texture state: */
if (st->pixel_xfer.pixelmap_enabled) {
- struct pipe_texture *textures[2];
- textures[0] = pt;
- textures[1] = st->pixel_xfer.pixelmap_texture;
- pipe->set_fragment_sampler_textures(pipe, 2, textures);
+ struct pipe_sampler_view *sampler_views[2];
+ sampler_views[0] = sv;
+ sampler_views[1] = st->pixel_xfer.pixelmap_sampler_view;
+ cso_set_fragment_sampler_views(cso, 2, sampler_views);
}
else {
- pipe->set_fragment_sampler_textures(pipe, 1, &pt);
+ cso_set_fragment_sampler_views(cso, 1, &sv);
}
/* Compute Gallium window coords (y=0=top) with pixel zoom.
@@ -610,16 +634,17 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z,
z = z * 2.0 - 1.0;
draw_quad(ctx, x0, y0, z, x1, y1, color, invertTex,
- (GLfloat) width / pt->width0,
- (GLfloat) height / pt->height0);
+ (GLfloat) width / sv->texture->width0,
+ (GLfloat) height / sv->texture->height0);
/* restore state */
cso_restore_rasterizer(cso);
cso_restore_viewport(cso);
cso_restore_samplers(cso);
- cso_restore_sampler_textures(cso);
+ cso_restore_fragment_sampler_views(cso);
cso_restore_fragment_shader(cso);
cso_restore_vertex_shader(cso);
+ cso_restore_vertex_elements(cso);
}
@@ -631,7 +656,6 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y,
{
struct st_context *st = st_context(ctx);
struct pipe_context *pipe = st->pipe;
- struct pipe_screen *screen = pipe->screen;
struct st_renderbuffer *strb;
enum pipe_transfer_usage usage;
struct pipe_transfer *pt;
@@ -665,7 +689,7 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y,
usage, x, y,
width, height);
- stmap = screen->transfer_map(screen, pt);
+ stmap = pipe->transfer_map(pipe, pt);
pixels = _mesa_map_pbo_source(ctx, &clippedUnpack, pixels);
assert(pixels);
@@ -765,8 +789,8 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y,
_mesa_unmap_pbo_source(ctx, &clippedUnpack);
/* unmap the stencil buffer */
- screen->transfer_unmap(screen, pt);
- screen->tex_transfer_destroy(pt);
+ pipe->transfer_unmap(pipe, pt);
+ pipe->tex_transfer_destroy(pipe, pt);
}
@@ -810,12 +834,17 @@ st_DrawPixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height,
struct pipe_texture *pt
= make_texture(st, width, height, format, type, unpack, pixels);
if (pt) {
- draw_textured_quad(ctx, x, y, ctx->Current.RasterPos[2],
- width, height, ctx->Pixel.ZoomX, ctx->Pixel.ZoomY,
- pt,
- driver_vp,
- driver_fp,
- color, GL_FALSE);
+ struct pipe_sampler_view *sv = st_sampler_view_from_texture(st->pipe, pt);
+
+ if (sv) {
+ draw_textured_quad(ctx, x, y, ctx->Current.RasterPos[2],
+ width, height, ctx->Pixel.ZoomX, ctx->Pixel.ZoomY,
+ sv,
+ driver_vp,
+ driver_fp,
+ color, GL_FALSE);
+ pipe_sampler_view_reference(&sv, NULL);
+ }
pipe_texture_reference(&pt, NULL);
}
}
@@ -829,7 +858,7 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
GLint dstx, GLint dsty)
{
struct st_renderbuffer *rbDraw = st_renderbuffer(ctx->DrawBuffer->_StencilBuffer);
- struct pipe_screen *screen = ctx->st->pipe->screen;
+ struct pipe_context *pipe = ctx->st->pipe;
enum pipe_transfer_usage usage;
struct pipe_transfer *ptDraw;
ubyte *drawMap;
@@ -865,7 +894,7 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
assert(util_format_get_blockheight(ptDraw->texture->format) == 1);
/* map the stencil buffer */
- drawMap = screen->transfer_map(screen, ptDraw);
+ drawMap = pipe->transfer_map(pipe, ptDraw);
/* draw */
/* XXX PixelZoom not handled yet */
@@ -918,8 +947,8 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
free(buffer);
/* unmap the stencil buffer */
- screen->transfer_unmap(screen, ptDraw);
- screen->tex_transfer_destroy(ptDraw);
+ pipe->transfer_unmap(pipe, ptDraw);
+ pipe->tex_transfer_destroy(pipe, ptDraw);
}
@@ -934,9 +963,9 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy,
struct st_renderbuffer *rbRead;
void *driver_vp, *driver_fp;
struct pipe_texture *pt;
+ struct pipe_sampler_view *sv;
GLfloat *color;
enum pipe_format srcFormat, texFormat;
- int ptw, pth;
GLboolean invertTex = GL_FALSE;
GLint readX, readY, readW, readH;
struct gl_pixelstore_attrib pack = ctx->DefaultPacking;
@@ -1007,33 +1036,17 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy,
readW = MAX2(0, readW);
readH = MAX2(0, readH);
- /* Need to use POT texture? */
- ptw = width;
- pth = height;
- if (!screen->get_param(screen, PIPE_CAP_NPOT_TEXTURES)) {
- int l2pt, maxSize;
-
- l2pt = util_logbase2(width);
- if (1<<l2pt != width) {
- ptw = 1<<(l2pt+1);
- }
- l2pt = util_logbase2(height);
- if (1<<l2pt != height) {
- pth = 1<<(l2pt+1);
- }
-
- /* Check against maximum texture size */
- maxSize = 1 << (pipe->screen->get_param(pipe->screen, PIPE_CAP_MAX_TEXTURE_2D_LEVELS) - 1);
- assert(ptw <= maxSize);
- assert(pth <= maxSize);
- }
-
- pt = st_texture_create(st, PIPE_TEXTURE_2D, texFormat, 0,
- ptw, pth, 1,
- PIPE_TEXTURE_USAGE_SAMPLER);
+ /* alloc temporary texture */
+ pt = alloc_texture(st, width, height, texFormat);
if (!pt)
return;
+ sv = st_sampler_view_from_texture(st->pipe, pt);
+ if (!sv) {
+ pipe_texture_reference(&pt, NULL);
+ return;
+ }
+
/* Make temporary texture which is a copy of the src region.
*/
if (srcFormat == texFormat) {
@@ -1043,24 +1056,17 @@ 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 );
- if (pipe->surface_copy) {
- pipe->surface_copy(pipe,
- psTex, /* dest surf */
- pack.SkipPixels, pack.SkipRows, /* dest pos */
- psRead, /* src surf */
- readX, readY, readW, readH); /* src region */
- } else {
- util_surface_copy(pipe, FALSE,
- psTex,
- pack.SkipPixels, pack.SkipRows,
- psRead,
- readX, readY, readW, readH);
- }
+
+ pipe->surface_copy(pipe,
+ psTex, /* dest surf */
+ pack.SkipPixels, pack.SkipRows, /* dest pos */
+ psRead, /* src surf */
+ readX, readY, readW, readH); /* src region */
if (0) {
/* debug */
- debug_dump_surface("copypixsrcsurf", psRead);
- debug_dump_surface("copypixtemptex", psTex);
+ debug_dump_surface(pipe, "copypixsrcsurf", psRead);
+ debug_dump_surface(pipe, "copypixtemptex", psTex);
}
pipe_surface_reference(&psRead, NULL);
@@ -1090,22 +1096,22 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy,
if (type == GL_COLOR) {
/* alternate path using get/put_tile() */
GLfloat *buf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat));
- pipe_get_tile_rgba(ptRead, readX, readY, readW, readH, buf);
- pipe_put_tile_rgba(ptTex, pack.SkipPixels, pack.SkipRows,
+ pipe_get_tile_rgba(pipe, ptRead, readX, readY, readW, readH, buf);
+ pipe_put_tile_rgba(pipe, ptTex, pack.SkipPixels, pack.SkipRows,
readW, readH, buf);
free(buf);
}
else {
/* GL_DEPTH */
GLuint *buf = (GLuint *) malloc(width * height * sizeof(GLuint));
- pipe_get_tile_z(ptRead, readX, readY, readW, readH, buf);
- pipe_put_tile_z(ptTex, pack.SkipPixels, pack.SkipRows,
- readW, readH, buf);
+ pipe_get_tile_z(pipe, ptRead, readX, readY, readW, readH, buf);
+ pipe_put_tile_z(pipe, ptTex, pack.SkipPixels, pack.SkipRows,
+ readW, readH, buf);
free(buf);
}
- screen->tex_transfer_destroy(ptRead);
- screen->tex_transfer_destroy(ptTex);
+ pipe->tex_transfer_destroy(pipe, ptRead);
+ pipe->tex_transfer_destroy(pipe, ptTex);
}
/* OK, the texture 'pt' contains the src image/pixels. Now draw a
@@ -1113,12 +1119,13 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy,
*/
draw_textured_quad(ctx, dstx, dsty, ctx->Current.RasterPos[2],
width, height, ctx->Pixel.ZoomX, ctx->Pixel.ZoomY,
- pt,
+ sv,
driver_vp,
driver_fp,
color, invertTex);
pipe_texture_reference(&pt, NULL);
+ pipe_sampler_view_reference(&sv, NULL);
}
diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c
index 00e9d1dccb..84c2474038 100644
--- a/src/mesa/state_tracker/st_cb_fbo.c
+++ b/src/mesa/state_tracker/st_cb_fbo.c
@@ -48,9 +48,9 @@
#include "st_format.h"
#include "st_public.h"
#include "st_texture.h"
+#include "st_manager.h"
#include "util/u_format.h"
-#include "util/u_rect.h"
#include "util/u_inlines.h"
@@ -103,6 +103,7 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb,
*/
pipe_surface_reference( &strb->surface, NULL );
pipe_texture_reference( &strb->texture, NULL );
+ pipe_sampler_view_reference(&strb->sampler_view, NULL);
/* Setup new texture template.
*/
@@ -162,6 +163,7 @@ st_renderbuffer_delete(struct gl_renderbuffer *rb)
ASSERT(strb);
pipe_surface_reference(&strb->surface, NULL);
pipe_texture_reference(&strb->texture, NULL);
+ pipe_sampler_view_reference(&strb->sampler_view, NULL);
free(strb->data);
free(strb);
}
@@ -368,6 +370,8 @@ st_render_texture(GLcontext *ctx,
pipe_surface_reference(&strb->surface, NULL);
+ pipe_sampler_view_reference(&strb->sampler_view, st_get_stobj_sampler_view(stObj));
+
assert(strb->rtt_level <= strb->texture->last_level);
/* new surface for rendering into the texture */
@@ -379,6 +383,8 @@ st_render_texture(GLcontext *ctx,
PIPE_BUFFER_USAGE_GPU_READ |
PIPE_BUFFER_USAGE_GPU_WRITE);
+ strb->format = pt->format;
+
strb->Base.Format = st_pipe_format_to_mesa_format(pt->format);
strb->Base.DataType = st_format_datatype(pt->format);
@@ -511,17 +517,10 @@ copy_back_to_front(struct st_context *st,
(void) st_get_framebuffer_surface(stfb, backIndex, &surf_back);
if (surf_front && surf_back) {
- 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);
- }
+ st->pipe->surface_copy(st->pipe,
+ surf_front, 0, 0, /* dest */
+ surf_back, 0, 0, /* src */
+ fb->Width, fb->Height);
}
}
@@ -612,8 +611,18 @@ check_create_front_buffers(GLcontext *ctx, struct gl_framebuffer *fb)
static void
st_DrawBuffers(GLcontext *ctx, GLsizei count, const GLenum *buffers)
{
+ GLframebuffer *fb = ctx->DrawBuffer;
+ GLuint i;
+
(void) count;
(void) buffers;
+
+ /* add the renderbuffers on demand */
+ for (i = 0; i < fb->_NumColorDrawBuffers; i++) {
+ gl_buffer_index idx = fb->_ColorDrawBufferIndexes[i];
+ st_manager_add_color_renderbuffer(ctx->st, fb, idx);
+ }
+
check_create_front_buffers(ctx, ctx->DrawBuffer);
}
@@ -624,8 +633,13 @@ st_DrawBuffers(GLcontext *ctx, GLsizei count, const GLenum *buffers)
static void
st_ReadBuffer(GLcontext *ctx, GLenum buffer)
{
+ GLframebuffer *fb = ctx->ReadBuffer;
+
(void) buffer;
- check_create_front_buffers(ctx, ctx->ReadBuffer);
+
+ /* add the renderbuffer on demand */
+ st_manager_add_color_renderbuffer(ctx->st, fb, fb->_ColorReadBufferIndex);
+ check_create_front_buffers(ctx, fb);
}
@@ -645,3 +659,14 @@ void st_init_fbo_functions(struct dd_function_table *functions)
functions->DrawBuffers = st_DrawBuffers;
functions->ReadBuffer = st_ReadBuffer;
}
+
+struct pipe_sampler_view *
+st_renderbuffer_get_sampler_view(struct st_renderbuffer *rb,
+ struct pipe_context *pipe)
+{
+ if (!rb->sampler_view) {
+ rb->sampler_view = st_sampler_view_from_texture(pipe, rb->texture);
+ }
+
+ return rb->sampler_view;
+}
diff --git a/src/mesa/state_tracker/st_cb_fbo.h b/src/mesa/state_tracker/st_cb_fbo.h
index bea6eb89c3..7a45a608fe 100644
--- a/src/mesa/state_tracker/st_cb_fbo.h
+++ b/src/mesa/state_tracker/st_cb_fbo.h
@@ -39,6 +39,7 @@ struct st_renderbuffer
struct gl_renderbuffer Base;
struct pipe_texture *texture;
struct pipe_surface *surface; /* temporary view into texture */
+ struct pipe_sampler_view *sampler_view;
enum pipe_format format; /** preferred format, or PIPE_FORMAT_NONE */
GLboolean defined; /**< defined contents? */
@@ -55,6 +56,7 @@ struct st_renderbuffer
/** Render to texture state */
struct pipe_texture *texture_save;
struct pipe_surface *surface_save;
+ struct pipe_sampler_view *sampler_view_save;
};
@@ -71,5 +73,9 @@ st_new_renderbuffer_fb(enum pipe_format format, int samples, boolean sw);
extern void
st_init_fbo_functions(struct dd_function_table *functions);
+extern struct pipe_sampler_view *
+st_renderbuffer_get_sampler_view(struct st_renderbuffer *rb,
+ struct pipe_context *pipe);
+
#endif /* ST_CB_FBO_H */
diff --git a/src/mesa/state_tracker/st_cb_flush.c b/src/mesa/state_tracker/st_cb_flush.c
index 1329f807bc..30e7afcf2a 100644
--- a/src/mesa/state_tracker/st_cb_flush.c
+++ b/src/mesa/state_tracker/st_cb_flush.c
@@ -40,6 +40,7 @@
#include "st_cb_clear.h"
#include "st_cb_fbo.h"
#include "st_public.h"
+#include "st_manager.h"
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
#include "pipe/p_screen.h"
@@ -74,12 +75,9 @@ display_front_buffer(struct st_context *st)
= st_renderbuffer(fb->Attachment[BUFFER_FRONT_LEFT].Renderbuffer);
if (strb) {
- struct pipe_surface *front_surf = strb->surface;
-
/* Hook for copying "fake" frontbuffer if necessary:
*/
- st->pipe->screen->flush_frontbuffer( st->pipe->screen, front_surf,
- st->pipe->priv );
+ st_manager_flush_frontbuffer(st);
/*
st->frontbuffer_status = FRONT_STATUS_UNDEFINED;
diff --git a/src/mesa/state_tracker/st_cb_readpixels.c b/src/mesa/state_tracker/st_cb_readpixels.c
index 952d9ce915..7afb275fe2 100644
--- a/src/mesa/state_tracker/st_cb_readpixels.c
+++ b/src/mesa/state_tracker/st_cb_readpixels.c
@@ -45,6 +45,7 @@
#include "st_debug.h"
#include "st_context.h"
+#include "st_atom.h"
#include "st_cb_readpixels.h"
#include "st_cb_fbo.h"
#include "st_public.h"
@@ -63,7 +64,7 @@ st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y,
GLvoid *pixels)
{
struct gl_framebuffer *fb = ctx->ReadBuffer;
- struct pipe_screen *screen = ctx->st->pipe->screen;
+ struct pipe_context *pipe = ctx->st->pipe;
struct st_renderbuffer *strb = st_renderbuffer(fb->_StencilBuffer);
struct pipe_transfer *pt;
ubyte *stmap;
@@ -81,7 +82,7 @@ st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y,
width, height);
/* map the stencil buffer */
- stmap = screen->transfer_map(screen, pt);
+ stmap = pipe->transfer_map(pipe, pt);
/* width should never be > MAX_WIDTH since we did clipping earlier */
ASSERT(width <= MAX_WIDTH);
@@ -161,8 +162,8 @@ st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y,
}
/* unmap the stencil buffer */
- screen->transfer_unmap(screen, pt);
- screen->tex_transfer_destroy(pt);
+ pipe->transfer_unmap(pipe, pt);
+ pipe->tex_transfer_destroy(pipe, pt);
}
@@ -234,13 +235,13 @@ st_fast_readpixels(GLcontext *ctx, struct st_renderbuffer *strb,
{
struct pipe_context *pipe = ctx->st->pipe;
- struct pipe_screen *screen = pipe->screen;
struct pipe_transfer *trans;
const GLubyte *map;
GLubyte *dst;
GLint row, col, dy, dstStride;
if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
+ /* convert GL Y to Gallium Y */
y = strb->texture->height0 - y - height;
}
@@ -252,17 +253,22 @@ st_fast_readpixels(GLcontext *ctx, struct st_renderbuffer *strb,
return GL_FALSE;
}
- map = screen->transfer_map(screen, trans);
+ map = pipe->transfer_map(pipe, trans);
if (!map) {
- screen->tex_transfer_destroy(trans);
+ pipe->tex_transfer_destroy(pipe, trans);
return GL_FALSE;
}
+ /* We always write to the user/dest buffer from low addr to high addr
+ * but the read order depends on renderbuffer orientation
+ */
if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
+ /* read source rows from bottom to top */
y = height - 1;
dy = -1;
}
else {
+ /* read source rows from top to bottom */
y = 0;
dy = 1;
}
@@ -311,8 +317,8 @@ st_fast_readpixels(GLcontext *ctx, struct st_renderbuffer *strb,
; /* nothing */
}
- screen->transfer_unmap(screen, trans);
- screen->tex_transfer_destroy(trans);
+ pipe->transfer_unmap(pipe, trans);
+ pipe->tex_transfer_destroy(pipe, trans);
}
return GL_TRUE;
@@ -331,7 +337,6 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height,
GLvoid *dest)
{
struct pipe_context *pipe = ctx->st->pipe;
- struct pipe_screen *screen = pipe->screen;
GLfloat temp[MAX_WIDTH][4];
const GLbitfield transferOps = ctx->_ImageTransferState;
GLsizei i, j;
@@ -346,6 +351,8 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height,
/* XXX convolution not done yet */
assert((transferOps & IMAGE_CONVOLUTION_BIT) == 0);
+ st_validate_state(ctx->st);
+
/* Do all needed clipping here, so that we can forget about it later */
if (!_mesa_clip_readpixels(ctx, &x, &y, &width, &height, &clippedPacking)) {
/* The ReadPixels transfer is totally outside the window bounds */
@@ -396,6 +403,7 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height,
}
if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
+ /* convert GL Y to Gallium Y */
y = strb->Base.Height - y - height;
}
@@ -436,7 +444,7 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height,
GLuint ztemp[MAX_WIDTH];
GLfloat zfloat[MAX_WIDTH];
const double scale = 1.0 / ((1 << 24) - 1);
- pipe_get_tile_raw(trans, 0, y, width, 1, ztemp, 0);
+ pipe_get_tile_raw(pipe, trans, 0, y, width, 1, ztemp, 0);
y += yStep;
for (j = 0; j < width; j++) {
zfloat[j] = (float) (scale * (ztemp[j] & 0xffffff));
@@ -451,7 +459,7 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height,
assert(format == GL_DEPTH_STENCIL_EXT);
for (i = 0; i < height; i++) {
GLuint *zshort = (GLuint *)dst;
- pipe_get_tile_raw(trans, 0, y, width, 1, dst, 0);
+ pipe_get_tile_raw(pipe, trans, 0, y, width, 1, dst, 0);
y += yStep;
/* Reverse into 24/8 */
for (j = 0; j < width; j++) {
@@ -468,7 +476,7 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height,
GLuint ztemp[MAX_WIDTH];
GLfloat zfloat[MAX_WIDTH];
const double scale = 1.0 / ((1 << 24) - 1);
- pipe_get_tile_raw(trans, 0, y, width, 1, ztemp, 0);
+ pipe_get_tile_raw(pipe, trans, 0, y, width, 1, ztemp, 0);
y += yStep;
for (j = 0; j < width; j++) {
zfloat[j] = (float) (scale * ((ztemp[j] >> 8) & 0xffffff));
@@ -482,7 +490,7 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height,
/* XXX: unreachable code -- should be before st_read_stencil_pixels */
assert(format == GL_DEPTH_STENCIL_EXT);
for (i = 0; i < height; i++) {
- pipe_get_tile_raw(trans, 0, y, width, 1, dst, 0);
+ pipe_get_tile_raw(pipe, trans, 0, y, width, 1, dst, 0);
y += yStep;
dst += dstStride;
}
@@ -493,7 +501,7 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height,
GLushort ztemp[MAX_WIDTH];
GLfloat zfloat[MAX_WIDTH];
const double scale = 1.0 / 0xffff;
- pipe_get_tile_raw(trans, 0, y, width, 1, ztemp, 0);
+ pipe_get_tile_raw(pipe, trans, 0, y, width, 1, ztemp, 0);
y += yStep;
for (j = 0; j < width; j++) {
zfloat[j] = (float) (scale * ztemp[j]);
@@ -508,7 +516,7 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height,
GLuint ztemp[MAX_WIDTH];
GLfloat zfloat[MAX_WIDTH];
const double scale = 1.0 / 0xffffffff;
- pipe_get_tile_raw(trans, 0, y, width, 1, ztemp, 0);
+ pipe_get_tile_raw(pipe, trans, 0, y, width, 1, ztemp, 0);
y += yStep;
for (j = 0; j < width; j++) {
zfloat[j] = (float) (scale * ztemp[j]);
@@ -522,7 +530,7 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height,
/* RGBA format */
/* Do a row at a time to flip image data vertically */
for (i = 0; i < height; i++) {
- pipe_get_tile_rgba(trans, 0, y, width, 1, df);
+ pipe_get_tile_rgba(pipe, trans, 0, y, width, 1, df);
y += yStep;
df += dfStride;
if (!dfStride) {
@@ -534,7 +542,7 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height,
}
}
- screen->tex_transfer_destroy(trans);
+ pipe->tex_transfer_destroy(pipe, trans);
_mesa_unmap_pbo_dest(ctx, &clippedPacking);
}
diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c
index 92eefca2e7..d7a774aa40 100644
--- a/src/mesa/state_tracker/st_cb_texture.c
+++ b/src/mesa/state_tracker/st_cb_texture.c
@@ -63,6 +63,7 @@
#include "util/u_blit.h"
#include "util/u_format.h"
#include "util/u_surface.h"
+#include "util/u_sampler.h"
#include "util/u_math.h"
@@ -123,6 +124,8 @@ st_DeleteTextureObject(GLcontext *ctx,
struct st_texture_object *stObj = st_texture_object(texObj);
if (stObj->pt)
pipe_texture_reference(&stObj->pt, NULL);
+ if (stObj->sampler_view)
+ pipe_sampler_view_reference(&stObj->sampler_view, NULL);
_mesa_delete_texture_object(ctx, texObj);
}
@@ -312,6 +315,8 @@ guess_and_alloc_texture(struct st_context *st,
depth,
usage);
+ stObj->pipe = st->pipe;
+
DBG("%s - success\n", __FUNCTION__);
}
@@ -371,10 +376,13 @@ compress_with_blit(GLcontext * ctx,
{
const GLuint dstImageOffsets[1] = {0};
struct st_texture_image *stImage = st_texture_image(texImage);
- struct pipe_screen *screen = ctx->st->pipe->screen;
+ struct pipe_context *pipe = ctx->st->pipe;
+ struct pipe_screen *screen = pipe->screen;
gl_format mesa_format;
struct pipe_texture templ;
struct pipe_texture *src_tex;
+ struct pipe_sampler_view view_templ;
+ struct pipe_sampler_view *src_view;
struct pipe_surface *dst_surface;
struct pipe_transfer *tex_xfer;
void *map;
@@ -421,7 +429,7 @@ compress_with_blit(GLcontext * ctx,
0, 0, 0, /* face, level are zero */
PIPE_TRANSFER_WRITE,
0, 0, width, height); /* x, y, w, h */
- map = screen->transfer_map(screen, tex_xfer);
+ map = pipe->transfer_map(pipe, tex_xfer);
_mesa_texstore(ctx, 2, GL_RGBA, mesa_format,
map, /* dest ptr */
@@ -433,12 +441,19 @@ compress_with_blit(GLcontext * ctx,
pixels, /* source data */
unpack); /* source data packing */
- screen->transfer_unmap(screen, tex_xfer);
- screen->tex_transfer_destroy(tex_xfer);
+ pipe->transfer_unmap(pipe, tex_xfer);
+ pipe->tex_transfer_destroy(pipe, tex_xfer);
+
+ /* Create temporary sampler view */
+ u_sampler_view_default_template(&view_templ,
+ src_tex,
+ src_tex->format);
+ src_view = pipe->create_sampler_view(pipe, src_tex, &view_templ);
+
/* copy / compress image */
util_blit_pixels_tex(ctx->st->blit,
- src_tex, /* pipe_texture (src) */
+ src_view, /* sampler view (src) */
0, 0, /* src x0, y0 */
width, height, /* src x1, y1 */
dst_surface, /* pipe_surface (dst) */
@@ -450,6 +465,7 @@ compress_with_blit(GLcontext * ctx,
pipe_surface_reference(&dst_surface, NULL);
pipe_texture_reference(&src_tex, NULL);
+ pipe_sampler_view_reference(&src_view, NULL);
return GL_TRUE;
}
@@ -555,6 +571,7 @@ st_TexImage(GLcontext * ctx,
DBG("release it\n");
pipe_texture_reference(&stObj->pt, NULL);
assert(!stObj->pt);
+ pipe_sampler_view_reference(&stObj->sampler_view, NULL);
stObj->teximage_realloc = FALSE;
}
}
@@ -809,8 +826,11 @@ decompress_with_blit(GLcontext * ctx, GLenum target, GLint level,
struct gl_texture_object *texObj,
struct gl_texture_image *texImage)
{
- struct pipe_screen *screen = ctx->st->pipe->screen;
+ struct pipe_context *pipe = ctx->st->pipe;
+ struct pipe_screen *screen = pipe->screen;
struct st_texture_image *stImage = st_texture_image(texImage);
+ struct st_texture_object *stObj = st_texture_object(texObj);
+ struct pipe_sampler_view *src_view = st_get_stobj_sampler_view(stObj);
const GLuint width = texImage->Width;
const GLuint height = texImage->Height;
struct pipe_surface *dst_surface;
@@ -827,7 +847,7 @@ decompress_with_blit(GLcontext * ctx, GLenum target, GLint level,
/* blit/render/decompress */
util_blit_pixels_tex(ctx->st->blit,
- stImage->pt, /* pipe_texture (src) */
+ src_view, /* pipe_texture (src) */
0, 0, /* src x0, y0 */
width, height, /* src x1, y1 */
dst_surface, /* pipe_surface (dst) */
@@ -848,7 +868,7 @@ decompress_with_blit(GLcontext * ctx, GLenum target, GLint level,
if (st_equal_formats(stImage->pt->format, format, type)) {
/* memcpy */
const uint bytesPerRow = width * util_format_get_blocksize(stImage->pt->format);
- ubyte *map = screen->transfer_map(screen, tex_xfer);
+ ubyte *map = pipe->transfer_map(pipe, tex_xfer);
GLuint row;
for (row = 0; row < height; row++) {
GLvoid *dest = _mesa_image_address2d(&ctx->Pack, pixels, width,
@@ -856,7 +876,7 @@ decompress_with_blit(GLcontext * ctx, GLenum target, GLint level,
memcpy(dest, map, bytesPerRow);
map += tex_xfer->stride;
}
- screen->transfer_unmap(screen, tex_xfer);
+ pipe->transfer_unmap(pipe, tex_xfer);
}
else {
/* format translation via floats */
@@ -871,7 +891,7 @@ decompress_with_blit(GLcontext * ctx, GLenum target, GLint level,
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);
+ pipe_get_tile_rgba(pipe, tex_xfer, 0, row, width, 1, rgba);
_mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) rgba, format,
type, dest, &ctx->Pack, transferOps);
@@ -880,7 +900,7 @@ decompress_with_blit(GLcontext * ctx, GLenum target, GLint level,
_mesa_unmap_pbo_dest(ctx, &ctx->Pack);
- screen->tex_transfer_destroy(tex_xfer);
+ pipe->tex_transfer_destroy(pipe, tex_xfer);
/* destroy the temp / dest surface */
util_destroy_rgba_surface(dst_texture, dst_surface);
@@ -1258,7 +1278,6 @@ fallback_copy_texsubimage(GLcontext *ctx, GLenum target, GLint level,
GLsizei width, GLsizei height)
{
struct pipe_context *pipe = ctx->st->pipe;
- struct pipe_screen *screen = pipe->screen;
struct pipe_transfer *src_trans;
GLvoid *texDest;
enum pipe_transfer_usage transfer_usage;
@@ -1311,11 +1330,11 @@ fallback_copy_texsubimage(GLcontext *ctx, GLenum target, GLint level,
/* To avoid a large temp memory allocation, do copy row by row */
for (row = 0; row < height; row++, srcY += yStep) {
uint data[MAX_WIDTH];
- pipe_get_tile_z(src_trans, 0, srcY, width, 1, data);
+ pipe_get_tile_z(pipe, src_trans, 0, srcY, width, 1, data);
if (scaleOrBias) {
_mesa_scale_and_bias_depth_uint(ctx, width, data);
}
- pipe_put_tile_z(stImage->transfer, 0, row, width, 1, data);
+ pipe_put_tile_z(pipe, stImage->transfer, 0, row, width, 1, data);
}
}
else {
@@ -1337,7 +1356,7 @@ fallback_copy_texsubimage(GLcontext *ctx, GLenum target, GLint level,
/* XXX this usually involves a lot of int/float conversion.
* try to avoid that someday.
*/
- pipe_get_tile_rgba(src_trans, 0, 0, width, height, tempSrc);
+ pipe_get_tile_rgba(pipe, src_trans, 0, 0, width, height, tempSrc);
/* Store into texture memory.
* Note that this does some special things such as pixel transfer
@@ -1365,7 +1384,7 @@ fallback_copy_texsubimage(GLcontext *ctx, GLenum target, GLint level,
}
st_texture_image_unmap(ctx->st, stImage);
- screen->tex_transfer_destroy(src_trans);
+ pipe->tex_transfer_destroy(pipe, src_trans);
}
@@ -1541,8 +1560,7 @@ st_copy_texsubimage(GLcontext *ctx,
if (ctx->_ImageTransferState == 0x0) {
- if (pipe->surface_copy &&
- matching_base_formats &&
+ if (matching_base_formats &&
src_format == dest_format &&
!do_flip)
{
@@ -1594,6 +1612,7 @@ st_copy_texsubimage(GLcontext *ctx,
}
util_blit_pixels_writemask(ctx->st->blit,
strb->surface,
+ st_renderbuffer_get_sampler_view(strb, pipe),
srcX, srcY0,
srcX + width, srcY1,
dest_surface,
@@ -1790,6 +1809,7 @@ st_finalize_texture(GLcontext *ctx,
firstImage->pt != stObj->pt &&
firstImage->pt->last_level >= stObj->lastLevel) {
pipe_texture_reference(&stObj->pt, firstImage->pt);
+ pipe_sampler_view_reference(&stObj->sampler_view, NULL);
}
/* bytes per pixel block (blocks are usually 1x1) */
@@ -1809,6 +1829,7 @@ st_finalize_texture(GLcontext *ctx,
stObj->pt->depth0 != firstImage->base.Depth2)
{
pipe_texture_reference(&stObj->pt, NULL);
+ pipe_sampler_view_reference(&stObj->sampler_view, NULL);
ctx->st->dirty.st |= ST_NEW_FRAMEBUFFER;
}
}
diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c
index de8beaf5e2..72f5a9c1e0 100644
--- a/src/mesa/state_tracker/st_context.c
+++ b/src/mesa/state_tracker/st_context.c
@@ -30,9 +30,9 @@
#include "vbo/vbo.h"
#include "shader/shader_api.h"
#include "glapi/glapi.h"
+#include "st_context.h"
#include "st_public.h"
#include "st_debug.h"
-#include "st_context.h"
#include "st_cb_accum.h"
#include "st_cb_bitmap.h"
#include "st_cb_blit.h"
@@ -63,6 +63,7 @@
#include "st_program.h"
#include "pipe/p_context.h"
#include "util/u_inlines.h"
+#include "util/u_rect.h"
#include "draw/draw_context.h"
#include "cso_cache/cso_context.h"
@@ -97,6 +98,19 @@ st_get_msaa(void)
}
+/** Default method for pipe_context::surface_copy() */
+static void
+st_surface_copy(struct pipe_context *pipe,
+ struct pipe_surface *dst,
+ unsigned dst_x, unsigned dst_y,
+ struct pipe_surface *src,
+ unsigned src_x, unsigned src_y,
+ unsigned w, unsigned h)
+{
+ util_surface_copy(pipe, FALSE, dst, dst_x, dst_y, src, src_x, src_y, w, h);
+}
+
+
static struct st_context *
st_create_context_priv( GLcontext *ctx, struct pipe_context *pipe )
{
@@ -141,6 +155,14 @@ st_create_context_priv( GLcontext *ctx, struct pipe_context *pipe )
for (i = 0; i < PIPE_MAX_SAMPLERS; i++)
st->state.sampler_list[i] = &st->state.samplers[i];
+ for (i = 0; i < 3; i++) {
+ memset(&st->velems_util_draw[i], 0, sizeof(struct pipe_vertex_element));
+ st->velems_util_draw[i].src_offset = i * 4 * sizeof(float);
+ st->velems_util_draw[i].instance_divisor = 0;
+ st->velems_util_draw[i].vertex_buffer_index = 0;
+ st->velems_util_draw[i].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
+ }
+
/* we want all vertex data to be placed in buffer objects */
vbo_use_buffer_objects(ctx);
@@ -158,6 +180,10 @@ st_create_context_priv( GLcontext *ctx, struct pipe_context *pipe )
st_init_limits(st);
st_init_extensions(st);
+ /* plug in helper driver functions if needed */
+ if (!pipe->surface_copy)
+ pipe->surface_copy = st_surface_copy;
+
return st;
}
@@ -207,8 +233,8 @@ static void st_destroy_context_priv( struct st_context *st )
st_destroy_drawtex(st);
#endif
- for (i = 0; i < Elements(st->state.sampler_texture); i++) {
- pipe_texture_reference(&st->state.sampler_texture[i], NULL);
+ for (i = 0; i < Elements(st->state.sampler_views); i++) {
+ pipe_sampler_view_reference(&st->state.sampler_views[i], NULL);
}
for (i = 0; i < Elements(st->state.constants); i++) {
@@ -264,7 +290,8 @@ void st_destroy_context( struct st_context *st )
GLboolean
st_make_current(struct st_context *st,
struct st_framebuffer *draw,
- struct st_framebuffer *read)
+ struct st_framebuffer *read,
+ void *winsys_drawable_handle )
{
/* Call this periodically to detect when the user has begun using
* GL rendering from multiple threads.
@@ -272,10 +299,13 @@ st_make_current(struct st_context *st,
_glapi_check_multithread();
if (st) {
- if (!_mesa_make_current(st->ctx, &draw->Base, &read->Base))
+ if (!_mesa_make_current(st->ctx, &draw->Base, &read->Base)) {
+ st->pipe->priv = NULL;
return GL_FALSE;
+ }
_mesa_check_init_viewport(st->ctx, draw->InitWidth, draw->InitHeight);
+ st->winsys_drawable_handle = winsys_drawable_handle;
return GL_TRUE;
}
diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h
index 045c029c30..786beaec08 100644
--- a/src/mesa/state_tracker/st_context.h
+++ b/src/mesa/state_tracker/st_context.h
@@ -31,6 +31,7 @@
#include "main/mtypes.h"
#include "shader/prog_cache.h"
#include "pipe/p_state.h"
+#include "state_tracker/st_api.h"
struct st_context;
@@ -73,6 +74,8 @@ struct st_tracked_state {
struct st_context
{
+ struct st_context_iface iface;
+
GLcontext *ctx;
struct pipe_context *pipe;
@@ -94,7 +97,7 @@ struct st_context
struct pipe_clip_state clip;
struct pipe_buffer *constants[2];
struct pipe_framebuffer_state framebuffer;
- struct pipe_texture *sampler_texture[PIPE_MAX_SAMPLERS];
+ struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS];
struct pipe_scissor_state scissor;
struct pipe_viewport_state viewport;
@@ -141,6 +144,7 @@ struct st_context
struct st_fragment_program *combined_prog;
GLuint combined_prog_sn;
struct pipe_texture *pixelmap_texture;
+ struct pipe_sampler_view *pixelmap_sampler_view;
boolean pixelmap_enabled; /**< use the pixelmap texture? */
} pixel_xfer;
@@ -174,6 +178,9 @@ struct st_context
unsigned vbuf_slot;
} clear;
+ /** used for anything using util_draw_vertex_buffer */
+ struct pipe_vertex_element velems_util_draw[3];
+
void *passthrough_fs; /**< simple pass-through frag shader */
struct gen_mipmap_state *gen_mipmap;
@@ -182,6 +189,7 @@ struct st_context
struct cso_context *cso_context;
int force_msaa;
+ void *winsys_drawable_handle;
};
@@ -202,6 +210,11 @@ struct st_framebuffer
GLframebuffer Base;
void *Private;
GLuint InitWidth, InitHeight;
+
+ struct st_framebuffer_iface *iface;
+ enum st_attachment_type statts[ST_ATTACHMENT_COUNT];
+ unsigned num_statts;
+ int32_t revalidate;
};
diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c
index 32b9a473cf..7f45e3f548 100644
--- a/src/mesa/state_tracker/st_draw.c
+++ b/src/mesa/state_tracker/st_draw.c
@@ -57,6 +57,7 @@
#include "pipe/p_defines.h"
#include "util/u_inlines.h"
#include "util/u_format.h"
+#include "cso_cache/cso_context.h"
static GLuint double_types[4] = {
@@ -183,7 +184,7 @@ st_pipe_vertex_format(GLenum type, GLuint size, GLenum format,
/* this is an odd-ball case */
assert(type == GL_UNSIGNED_BYTE);
assert(normalized);
- return PIPE_FORMAT_A8R8G8B8_UNORM;
+ return PIPE_FORMAT_B8G8R8A8_UNORM;
}
if (normalized) {
@@ -272,7 +273,8 @@ is_interleaved_arrays(const struct st_vertex_program *vp,
}
*userSpace = (num_client_arrays == vpv->num_inputs);
- /* printf("user space: %d (%d %d)\n", (int) *userSpace,num_client_arrays,vp->num_inputs); */
+ /* debug_printf("user space: %s (%d arrays, %d inputs)\n",
+ (int)*userSpace ? "Yes" : "No", num_client_arrays, vp->num_inputs); */
return GL_TRUE;
}
@@ -292,6 +294,8 @@ get_arrays_bounds(const struct st_vertex_program *vp,
const GLubyte *high_addr = NULL;
GLuint attr;
+ /* debug_printf("get_arrays_bounds: Handling %u attrs\n", vpv->num_inputs); */
+
for (attr = 0; attr < vpv->num_inputs; attr++) {
const GLuint mesaAttr = vp->index_to_input[attr];
const GLint stride = arrays[mesaAttr]->StrideB;
@@ -300,6 +304,9 @@ get_arrays_bounds(const struct st_vertex_program *vp,
_mesa_sizeof_type(arrays[mesaAttr]->Type));
const GLubyte *end = start + (max_index * stride) + sz;
+ /* debug_printf("attr %u: stride %d size %u start %p end %p\n",
+ attr, stride, sz, start, end); */
+
if (attr == 0) {
low_addr = start;
high_addr = end;
@@ -347,7 +354,8 @@ setup_interleaved_attribs(GLcontext *ctx,
const GLubyte *low, *high;
get_arrays_bounds(vp, vpv, arrays, max_index, &low, &high);
- /*printf("buffer range: %p %p %d\n", low, high, high-low);*/
+ /* debug_printf("buffer range: %p %p range %d max index %u\n",
+ low, high, high - low, max_index); */
offset0 = low;
if (userSpace) {
@@ -368,7 +376,6 @@ setup_interleaved_attribs(GLcontext *ctx,
(unsigned) (arrays[mesaAttr]->Ptr - offset0);
velements[attr].instance_divisor = 0;
velements[attr].vertex_buffer_index = 0;
- velements[attr].nr_components = arrays[mesaAttr]->Size;
velements[attr].src_format =
st_pipe_vertex_format(arrays[mesaAttr]->Type,
arrays[mesaAttr]->Size,
@@ -458,7 +465,6 @@ setup_non_interleaved_attribs(GLcontext *ctx,
vbuffer[attr].max_index = max_index;
velements[attr].instance_divisor = 0;
velements[attr].vertex_buffer_index = attr;
- velements[attr].nr_components = arrays[mesaAttr]->Size;
velements[attr].src_format
= st_pipe_vertex_format(arrays[mesaAttr]->Type,
arrays[mesaAttr]->Size,
@@ -564,6 +570,7 @@ st_draw_vbo(GLcontext *ctx,
(void) check_uniforms;
#endif
+ memset(velements, 0, sizeof(struct pipe_vertex_element) * vpv->num_inputs);
/*
* Setup the vbuffer[] and velements[] arrays.
*/
@@ -596,14 +603,13 @@ st_draw_vbo(GLcontext *ctx,
for (i = 0; i < num_velements; i++) {
printf("vlements[%d].vbuffer_index = %u\n", i, velements[i].vertex_buffer_index);
printf("vlements[%d].src_offset = %u\n", i, velements[i].src_offset);
- printf("vlements[%d].nr_comps = %u\n", i, velements[i].nr_components);
printf("vlements[%d].format = %s\n", i, util_format_name(velements[i].src_format));
}
}
#endif
pipe->set_vertex_buffers(pipe, num_vbuffers, vbuffer);
- pipe->set_vertex_elements(pipe, num_velements, velements);
+ cso_set_vertex_elements(ctx->st->cso_context, num_velements, velements);
if (num_vbuffers == 0 || num_velements == 0)
return;
diff --git a/src/mesa/state_tracker/st_draw_feedback.c b/src/mesa/state_tracker/st_draw_feedback.c
index 087f2f22bb..26a5b3fcd6 100644
--- a/src/mesa/state_tracker/st_draw_feedback.c
+++ b/src/mesa/state_tracker/st_draw_feedback.c
@@ -178,7 +178,6 @@ st_feedback_draw_vbo(GLcontext *ctx,
vbuffers[attr].max_index = max_index;
velements[attr].instance_divisor = 0;
velements[attr].vertex_buffer_index = attr;
- velements[attr].nr_components = arrays[mesaAttr]->Size;
velements[attr].src_format =
st_pipe_vertex_format(arrays[mesaAttr]->Type,
arrays[mesaAttr]->Size,
diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c
index 79be833768..290ee36b0f 100644
--- a/src/mesa/state_tracker/st_extensions.c
+++ b/src/mesa/state_tracker/st_extensions.c
@@ -137,6 +137,9 @@ void st_init_limits(struct st_context *st)
/* XXX separate query for early function return? */
st->ctx->Shader.EmitContReturn =
screen->get_param(screen, PIPE_CAP_TGSI_CONT_SUPPORTED);
+
+ /* Quads always follow GL provoking rules. */
+ c->QuadsFollowProvokingVertexConvention = GL_FALSE;
}
@@ -169,6 +172,7 @@ void st_init_extensions(struct st_context *st)
ctx->Extensions.ARB_vertex_array_object = GL_TRUE;
ctx->Extensions.ARB_vertex_buffer_object = GL_TRUE;
ctx->Extensions.ARB_vertex_program = GL_TRUE;
+ ctx->Extensions.ARB_window_pos = GL_TRUE;
ctx->Extensions.EXT_blend_color = GL_TRUE;
ctx->Extensions.EXT_blend_func_separate = GL_TRUE;
@@ -193,9 +197,17 @@ void st_init_extensions(struct st_context *st)
ctx->Extensions.APPLE_vertex_array_object = GL_TRUE;
+ ctx->Extensions.MESA_pack_invert = GL_TRUE;
+
ctx->Extensions.NV_blend_square = GL_TRUE;
ctx->Extensions.NV_texgen_reflection = GL_TRUE;
ctx->Extensions.NV_texture_env_combine4 = GL_TRUE;
+ ctx->Extensions.NV_texture_rectangle = GL_TRUE;
+#if 0
+ /* possibly could support the following two */
+ ctx->Extensions.NV_vertex_program = GL_TRUE;
+ ctx->Extensions.NV_vertex_program1_1 = GL_TRUE;
+#endif
#if FEATURE_OES_draw_texture
ctx->Extensions.OES_draw_texture = GL_TRUE;
@@ -233,7 +245,6 @@ void st_init_extensions(struct st_context *st)
if (screen->get_param(screen, PIPE_CAP_NPOT_TEXTURES)) {
ctx->Extensions.ARB_texture_non_power_of_two = GL_TRUE;
- ctx->Extensions.NV_texture_rectangle = GL_TRUE;
}
if (screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS) > 1) {
diff --git a/src/mesa/state_tracker/st_framebuffer.c b/src/mesa/state_tracker/st_framebuffer.c
index 0a91183f89..d3c43bbc68 100644
--- a/src/mesa/state_tracker/st_framebuffer.c
+++ b/src/mesa/state_tracker/st_framebuffer.c
@@ -197,6 +197,7 @@ st_set_framebuffer_surface(struct st_framebuffer *stfb,
/* replace the renderbuffer's surface/texture pointers */
pipe_surface_reference( &strb->surface, surf );
pipe_texture_reference( &strb->texture, surf->texture );
+ pipe_sampler_view_reference(&strb->sampler_view, NULL);
if (ctx) {
/* If ctx isn't set, we've likely not made current yet.
diff --git a/src/mesa/state_tracker/st_gen_mipmap.c b/src/mesa/state_tracker/st_gen_mipmap.c
index f67d7b4cb5..030b0a0f06 100644
--- a/src/mesa/state_tracker/st_gen_mipmap.c
+++ b/src/mesa/state_tracker/st_gen_mipmap.c
@@ -79,22 +79,23 @@ st_destroy_generate_mipmap(struct st_context *st)
static boolean
st_render_mipmap(struct st_context *st,
GLenum target,
- struct pipe_texture *pt,
+ struct st_texture_object *stObj,
uint baseLevel, uint lastLevel)
{
struct pipe_context *pipe = st->pipe;
struct pipe_screen *screen = pipe->screen;
+ struct pipe_sampler_view *psv = st_get_stobj_sampler_view(stObj);
const uint face = _mesa_tex_target_to_face(target);
assert(target != GL_TEXTURE_3D); /* not done yet */
/* check if we can render in the texture's format */
- if (!screen->is_format_supported(screen, pt->format, pt->target,
+ if (!screen->is_format_supported(screen, psv->format, psv->texture->target,
PIPE_TEXTURE_USAGE_RENDER_TARGET, 0)) {
return FALSE;
}
- util_gen_mipmap(st->gen_mipmap, pt, face, baseLevel, lastLevel,
+ util_gen_mipmap(st->gen_mipmap, psv, face, baseLevel, lastLevel,
PIPE_TEX_FILTER_LINEAR);
return TRUE;
@@ -106,7 +107,6 @@ fallback_generate_mipmap(GLcontext *ctx, GLenum target,
struct gl_texture_object *texObj)
{
struct pipe_context *pipe = ctx->st->pipe;
- struct pipe_screen *screen = pipe->screen;
struct pipe_texture *pt = st_get_texobj_texture(texObj);
const uint baseLevel = texObj->BaseLevel;
const uint lastLevel = pt->last_level;
@@ -142,8 +142,8 @@ fallback_generate_mipmap(GLcontext *ctx, GLenum target,
u_minify(pt->width0, dstLevel),
u_minify(pt->height0, dstLevel));
- srcData = (ubyte *) screen->transfer_map(screen, srcTrans);
- dstData = (ubyte *) screen->transfer_map(screen, dstTrans);
+ srcData = (ubyte *) pipe->transfer_map(pipe, srcTrans);
+ dstData = (ubyte *) pipe->transfer_map(pipe, dstTrans);
srcStride = srcTrans->stride / util_format_get_blocksize(srcTrans->texture->format);
dstStride = dstTrans->stride / util_format_get_blocksize(dstTrans->texture->format);
@@ -161,11 +161,11 @@ fallback_generate_mipmap(GLcontext *ctx, GLenum target,
dstData,
dstStride); /* stride in texels */
- screen->transfer_unmap(screen, srcTrans);
- screen->transfer_unmap(screen, dstTrans);
+ pipe->transfer_unmap(pipe, srcTrans);
+ pipe->transfer_unmap(pipe, dstTrans);
- screen->tex_transfer_destroy(srcTrans);
- screen->tex_transfer_destroy(dstTrans);
+ pipe->tex_transfer_destroy(pipe, srcTrans);
+ pipe->tex_transfer_destroy(pipe, dstTrans);
}
}
@@ -212,6 +212,7 @@ st_generate_mipmap(GLcontext *ctx, GLenum target,
struct gl_texture_object *texObj)
{
struct st_context *st = ctx->st;
+ struct st_texture_object *stObj = st_texture_object(texObj);
struct pipe_texture *pt = st_get_texobj_texture(texObj);
const uint baseLevel = texObj->BaseLevel;
uint lastLevel;
@@ -230,7 +231,6 @@ st_generate_mipmap(GLcontext *ctx, GLenum target,
/* 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;
@@ -256,6 +256,7 @@ st_generate_mipmap(GLcontext *ctx, GLenum target,
/* release the old tex (will likely be freed too) */
pipe_texture_reference(&oldTex, NULL);
+ pipe_sampler_view_reference(&stObj->sampler_view, NULL);
pt = stObj->pt;
}
@@ -265,7 +266,7 @@ st_generate_mipmap(GLcontext *ctx, GLenum target,
/* 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)) {
+ if (!st_render_mipmap(st, target, stObj, 0, lastLevel)) {
fallback_generate_mipmap(ctx, target, texObj);
}
diff --git a/src/mesa/state_tracker/st_inlines.h b/src/mesa/state_tracker/st_inlines.h
index e105870bc7..7fcde7b1a9 100644
--- a/src/mesa/state_tracker/st_inlines.h
+++ b/src/mesa/state_tracker/st_inlines.h
@@ -53,11 +53,11 @@ st_cond_flush_get_tex_transfer(struct st_context *st,
unsigned int x, unsigned int y,
unsigned int w, unsigned int h)
{
- struct pipe_screen *screen = st->pipe->screen;
+ struct pipe_context *context = st->pipe;
st_teximage_flush_before_map(st, pt, face, level, usage);
- return screen->get_tex_transfer(screen, pt, face, level, zslice, usage,
- x, y, w, h);
+ return context->get_tex_transfer(context, pt, face, level, zslice, usage,
+ x, y, w, h);
}
static INLINE struct pipe_transfer *
@@ -70,9 +70,9 @@ st_no_flush_get_tex_transfer(struct st_context *st,
unsigned int x, unsigned int y,
unsigned int w, unsigned int h)
{
- struct pipe_screen *screen = st->pipe->screen;
+ struct pipe_context *context = st->pipe;
- return screen->get_tex_transfer(screen, pt, face, level,
+ return context->get_tex_transfer(context, pt, face, level,
zslice, usage, x, y, w, h);
}
diff --git a/src/mesa/state_tracker/st_manager.c b/src/mesa/state_tracker/st_manager.c
new file mode 100644
index 0000000000..6ec4c8d792
--- /dev/null
+++ b/src/mesa/state_tracker/st_manager.c
@@ -0,0 +1,800 @@
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.9
+ *
+ * Copyright (C) 2010 LunarG Inc.
+ *
+ * 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, sublicense,
+ * 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:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * 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 NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR 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.
+ *
+ * Authors:
+ * Chia-I Wu <olv@lunarg.com>
+ */
+
+#include "state_tracker/st_api.h"
+
+#include "pipe/p_context.h"
+#include "pipe/p_screen.h"
+#include "util/u_format.h"
+#include "util/u_pointer.h"
+#include "util/u_inlines.h"
+#include "util/u_atomic.h"
+
+#include "main/mtypes.h"
+#include "main/context.h"
+#include "main/texobj.h"
+#include "main/teximage.h"
+#include "main/texstate.h"
+#include "main/texfetch.h"
+#include "main/fbobject.h"
+#include "main/framebuffer.h"
+#include "main/renderbuffer.h"
+#include "st_texture.h"
+
+#include "st_context.h"
+#include "st_format.h"
+#include "st_cb_fbo.h"
+#include "st_manager.h"
+
+/* these functions are defined in st_context.c */
+struct st_context *
+st_create_context(struct pipe_context *pipe,
+ const __GLcontextModes *visual,
+ struct st_context *share);
+void st_destroy_context(struct st_context *st);
+void st_flush(struct st_context *st, uint pipeFlushFlags,
+ struct pipe_fence_handle **fence);
+
+/**
+ * Note that this function may fail.
+ */
+static INLINE struct st_framebuffer *
+st_framebuffer(GLframebuffer *fb)
+{
+ /* FBO cannot be casted. See st_new_framebuffer */
+ return (struct st_framebuffer *) ((fb && !fb->Name) ? fb : NULL);
+}
+
+/**
+ * Map an attachment to a buffer index.
+ */
+static INLINE gl_buffer_index
+attachment_to_buffer_index(enum st_attachment_type statt)
+{
+ gl_buffer_index index;
+
+ switch (statt) {
+ case ST_ATTACHMENT_FRONT_LEFT:
+ index = BUFFER_FRONT_LEFT;
+ break;
+ case ST_ATTACHMENT_BACK_LEFT:
+ index = BUFFER_BACK_LEFT;
+ break;
+ case ST_ATTACHMENT_FRONT_RIGHT:
+ index = BUFFER_FRONT_RIGHT;
+ break;
+ case ST_ATTACHMENT_BACK_RIGHT:
+ index = BUFFER_BACK_RIGHT;
+ break;
+ case ST_ATTACHMENT_DEPTH_STENCIL:
+ index = BUFFER_DEPTH;
+ break;
+ case ST_ATTACHMENT_ACCUM:
+ index = BUFFER_ACCUM;
+ break;
+ case ST_ATTACHMENT_SAMPLE:
+ default:
+ index = BUFFER_COUNT;
+ break;
+ }
+
+ return index;
+}
+
+/**
+ * Map a buffer index to an attachment.
+ */
+static INLINE enum st_attachment_type
+buffer_index_to_attachment(gl_buffer_index index)
+{
+ enum st_attachment_type statt;
+
+ switch (index) {
+ case BUFFER_FRONT_LEFT:
+ statt = ST_ATTACHMENT_FRONT_LEFT;
+ break;
+ case BUFFER_BACK_LEFT:
+ statt = ST_ATTACHMENT_BACK_LEFT;
+ break;
+ case BUFFER_FRONT_RIGHT:
+ statt = ST_ATTACHMENT_FRONT_RIGHT;
+ break;
+ case BUFFER_BACK_RIGHT:
+ statt = ST_ATTACHMENT_BACK_RIGHT;
+ break;
+ case BUFFER_DEPTH:
+ statt = ST_ATTACHMENT_DEPTH_STENCIL;
+ break;
+ case BUFFER_ACCUM:
+ statt = ST_ATTACHMENT_ACCUM;
+ break;
+ default:
+ statt = ST_ATTACHMENT_INVALID;
+ break;
+ }
+
+ return statt;
+}
+
+/**
+ * Validate a framebuffer to make sure up-to-date pipe_textures are used.
+ */
+static void
+st_framebuffer_validate(struct st_framebuffer *stfb, struct st_context *st)
+{
+ struct pipe_screen *screen = st->pipe->screen;
+ struct pipe_texture *textures[ST_ATTACHMENT_COUNT];
+ uint width, height;
+ unsigned i;
+ boolean changed = FALSE;
+
+ if (!p_atomic_read(&stfb->revalidate))
+ return;
+
+ /* validate the fb */
+ if (!stfb->iface->validate(stfb->iface, stfb->statts, stfb->num_statts, textures))
+ return;
+
+ width = stfb->Base.Width;
+ height = stfb->Base.Height;
+
+ for (i = 0; i < stfb->num_statts; i++) {
+ struct st_renderbuffer *strb;
+ struct pipe_surface *ps;
+ gl_buffer_index idx;
+
+ if (!textures[i])
+ continue;
+
+ idx = attachment_to_buffer_index(stfb->statts[i]);
+ if (idx >= BUFFER_COUNT) {
+ pipe_texture_reference(&textures[i], NULL);
+ continue;
+ }
+
+ strb = st_renderbuffer(stfb->Base.Attachment[idx].Renderbuffer);
+ assert(strb);
+ if (strb->texture == textures[i]) {
+ pipe_texture_reference(&textures[i], NULL);
+ continue;
+ }
+
+ ps = screen->get_tex_surface(screen, textures[i], 0, 0, 0,
+ PIPE_BUFFER_USAGE_GPU_READ | PIPE_BUFFER_USAGE_GPU_WRITE);
+ if (ps) {
+ pipe_surface_reference(&strb->surface, ps);
+ pipe_texture_reference(&strb->texture, ps->texture);
+ /* ownership transfered */
+ pipe_surface_reference(&ps, NULL);
+
+ changed = TRUE;
+
+ strb->Base.Width = strb->surface->width;
+ strb->Base.Height = strb->surface->height;
+
+ width = strb->Base.Width;
+ height = strb->Base.Height;
+ }
+
+ pipe_texture_reference(&textures[i], NULL);
+ }
+
+ if (changed) {
+ st->dirty.st |= ST_NEW_FRAMEBUFFER;
+ _mesa_resize_framebuffer(st->ctx, &stfb->Base, width, height);
+
+ assert(stfb->Base.Width == width);
+ assert(stfb->Base.Height == height);
+ }
+
+ p_atomic_set(&stfb->revalidate, FALSE);
+}
+
+/**
+ * Update the attachments to validate by looping the existing renderbuffers.
+ */
+static void
+st_framebuffer_update_attachments(struct st_framebuffer *stfb)
+{
+ gl_buffer_index idx;
+
+ stfb->num_statts = 0;
+ for (idx = 0; idx < BUFFER_COUNT; idx++) {
+ struct st_renderbuffer *strb;
+ enum st_attachment_type statt;
+
+ strb = st_renderbuffer(stfb->Base.Attachment[idx].Renderbuffer);
+ if (!strb || strb->software)
+ continue;
+
+ statt = buffer_index_to_attachment(idx);
+ if (statt != ST_ATTACHMENT_INVALID &&
+ st_visual_have_buffers(stfb->iface->visual, 1 << statt))
+ stfb->statts[stfb->num_statts++] = statt;
+ }
+
+ p_atomic_set(&stfb->revalidate, TRUE);
+}
+
+/**
+ * Add a renderbuffer to the framebuffer.
+ */
+static boolean
+st_framebuffer_add_renderbuffer(struct st_framebuffer *stfb,
+ gl_buffer_index idx)
+{
+ struct gl_renderbuffer *rb;
+ enum pipe_format format;
+ int samples;
+ boolean sw;
+
+ /* do not distinguish depth/stencil buffers */
+ if (idx == BUFFER_STENCIL)
+ idx = BUFFER_DEPTH;
+
+ switch (idx) {
+ case BUFFER_DEPTH:
+ format = stfb->iface->visual->depth_stencil_format;
+ sw = FALSE;
+ break;
+ case BUFFER_ACCUM:
+ format = stfb->iface->visual->accum_format;
+ sw = TRUE;
+ break;
+ default:
+ format = stfb->iface->visual->color_format;
+ sw = FALSE;
+ break;
+ }
+
+ if (format == PIPE_FORMAT_NONE)
+ return FALSE;
+
+ samples = stfb->iface->visual->samples;
+ if (!samples)
+ samples = st_get_msaa();
+
+ rb = st_new_renderbuffer_fb(format, samples, sw);
+ if (!rb)
+ return FALSE;
+
+ if (idx != BUFFER_DEPTH) {
+ _mesa_add_renderbuffer(&stfb->Base, idx, rb);
+ }
+ else {
+ if (util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_ZS, 0))
+ _mesa_add_renderbuffer(&stfb->Base, BUFFER_DEPTH, rb);
+ if (util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_ZS, 1))
+ _mesa_add_renderbuffer(&stfb->Base, BUFFER_STENCIL, rb);
+ }
+
+ return TRUE;
+}
+
+/**
+ * Intialize a __GLcontextModes from a visual.
+ */
+static void
+st_visual_to_context_mode(const struct st_visual *visual,
+ __GLcontextModes *mode)
+{
+ memset(mode, 0, sizeof(*mode));
+
+ if (st_visual_have_buffers(visual, ST_ATTACHMENT_BACK_LEFT_MASK))
+ mode->doubleBufferMode = GL_TRUE;
+ if (st_visual_have_buffers(visual,
+ ST_ATTACHMENT_FRONT_RIGHT_MASK | ST_ATTACHMENT_BACK_RIGHT_MASK))
+ mode->stereoMode = GL_TRUE;
+
+ if (visual->color_format != PIPE_FORMAT_NONE) {
+ mode->rgbMode = GL_TRUE;
+
+ mode->redBits =
+ util_format_get_component_bits(visual->color_format,
+ UTIL_FORMAT_COLORSPACE_RGB, 0);
+ mode->greenBits =
+ util_format_get_component_bits(visual->color_format,
+ UTIL_FORMAT_COLORSPACE_RGB, 1);
+ mode->blueBits =
+ util_format_get_component_bits(visual->color_format,
+ UTIL_FORMAT_COLORSPACE_RGB, 2);
+ mode->alphaBits =
+ util_format_get_component_bits(visual->color_format,
+ UTIL_FORMAT_COLORSPACE_RGB, 3);
+
+ mode->rgbBits = mode->redBits +
+ mode->greenBits + mode->blueBits + mode->alphaBits;
+ }
+
+ if (visual->depth_stencil_format != PIPE_FORMAT_NONE) {
+ mode->haveDepthBuffer = GL_TRUE;
+ mode->haveStencilBuffer = GL_TRUE;
+
+ mode->depthBits =
+ util_format_get_component_bits(visual->depth_stencil_format,
+ UTIL_FORMAT_COLORSPACE_ZS, 0);
+ mode->stencilBits =
+ util_format_get_component_bits(visual->depth_stencil_format,
+ UTIL_FORMAT_COLORSPACE_ZS, 1);
+ }
+
+ if (visual->accum_format != PIPE_FORMAT_NONE) {
+ mode->haveAccumBuffer = GL_TRUE;
+
+ mode->accumRedBits =
+ util_format_get_component_bits(visual->accum_format,
+ UTIL_FORMAT_COLORSPACE_RGB, 0);
+ mode->accumGreenBits =
+ util_format_get_component_bits(visual->accum_format,
+ UTIL_FORMAT_COLORSPACE_RGB, 1);
+ mode->accumBlueBits =
+ util_format_get_component_bits(visual->accum_format,
+ UTIL_FORMAT_COLORSPACE_RGB, 2);
+ mode->accumAlphaBits =
+ util_format_get_component_bits(visual->accum_format,
+ UTIL_FORMAT_COLORSPACE_RGB, 3);
+ }
+
+ if (visual->samples) {
+ mode->sampleBuffers = 1;
+ mode->samples = visual->samples;
+ }
+}
+
+/**
+ * Determine the default draw or read buffer from a visual.
+ */
+static void
+st_visual_to_default_buffer(const struct st_visual *visual,
+ GLenum *buffer, GLint *index)
+{
+ enum st_attachment_type statt;
+ GLenum buf;
+ gl_buffer_index idx;
+
+ statt = visual->render_buffer;
+ /* do nothing if an invalid render buffer is specified */
+ if (statt == ST_ATTACHMENT_INVALID ||
+ !st_visual_have_buffers(visual, 1 << statt))
+ return;
+
+ switch (statt) {
+ case ST_ATTACHMENT_FRONT_LEFT:
+ buf = GL_FRONT_LEFT;
+ idx = BUFFER_FRONT_LEFT;
+ break;
+ case ST_ATTACHMENT_BACK_LEFT:
+ buf = GL_BACK_LEFT;
+ idx = BUFFER_BACK_LEFT;
+ break;
+ case ST_ATTACHMENT_FRONT_RIGHT:
+ buf = GL_FRONT_RIGHT;
+ idx = BUFFER_FRONT_RIGHT;
+ break;
+ case ST_ATTACHMENT_BACK_RIGHT:
+ buf = GL_BACK_RIGHT;
+ idx = BUFFER_BACK_RIGHT;
+ break;
+ default:
+ buf = GL_NONE;
+ idx = BUFFER_COUNT;
+ break;
+ }
+
+ if (buf != GL_NONE) {
+ if (buffer)
+ *buffer = buf;
+ if (index)
+ *index = idx;
+ }
+}
+
+/**
+ * Create a framebuffer from a manager interface.
+ */
+static struct st_framebuffer *
+st_framebuffer_create(struct st_framebuffer_iface *stfbi)
+{
+ struct st_framebuffer *stfb;
+ __GLcontextModes mode;
+ gl_buffer_index idx;
+
+ stfb = CALLOC_STRUCT(st_framebuffer);
+ if (!stfb)
+ return NULL;
+
+ st_visual_to_context_mode(stfbi->visual, &mode);
+ _mesa_initialize_window_framebuffer(&stfb->Base, &mode);
+
+ /* modify the draw/read buffers of the fb */
+ st_visual_to_default_buffer(stfbi->visual, &stfb->Base.ColorDrawBuffer[0],
+ &stfb->Base._ColorDrawBufferIndexes[0]);
+ st_visual_to_default_buffer(stfbi->visual, &stfb->Base.ColorReadBuffer,
+ &stfb->Base._ColorReadBufferIndex);
+
+ stfb->iface = stfbi;
+
+ /* add the color buffer */
+ idx = stfb->Base._ColorDrawBufferIndexes[0];
+ if (!st_framebuffer_add_renderbuffer(stfb, idx)) {
+ FREE(stfb);
+ return NULL;
+ }
+
+ st_framebuffer_add_renderbuffer(stfb, BUFFER_DEPTH);
+ st_framebuffer_add_renderbuffer(stfb, BUFFER_ACCUM);
+
+ st_framebuffer_update_attachments(stfb);
+
+ stfb->Base.Initialized = GL_TRUE;
+
+ return stfb;
+}
+
+/**
+ * Reference a framebuffer.
+ */
+static void
+st_framebuffer_reference(struct st_framebuffer **ptr,
+ struct st_framebuffer *stfb)
+{
+ GLframebuffer *fb = &stfb->Base;
+ _mesa_reference_framebuffer((GLframebuffer **) ptr, fb);
+}
+
+static void
+st_context_notify_invalid_framebuffer(struct st_context_iface *stctxi,
+ struct st_framebuffer_iface *stfbi)
+{
+ struct st_context *st = (struct st_context *) stctxi;
+ struct st_framebuffer *stfb;
+
+ /* either draw or read winsys fb */
+ stfb = st_framebuffer(st->ctx->WinSysDrawBuffer);
+ if (!stfb || stfb->iface != stfbi)
+ stfb = st_framebuffer(st->ctx->WinSysReadBuffer);
+ assert(stfb && stfb->iface == stfbi);
+
+ p_atomic_set(&stfb->revalidate, TRUE);
+}
+
+static void
+st_context_flush(struct st_context_iface *stctxi, unsigned flags,
+ struct pipe_fence_handle **fence)
+{
+ struct st_context *st = (struct st_context *) stctxi;
+ st_flush(st, flags, fence);
+ if (flags & PIPE_FLUSH_RENDER_CACHE)
+ st_manager_flush_frontbuffer(st);
+}
+
+static boolean
+st_context_teximage(struct st_context_iface *stctxi, enum st_texture_type target,
+ int level, enum pipe_format internal_format,
+ struct pipe_texture *tex, boolean mipmap)
+{
+ struct st_context *st = (struct st_context *) stctxi;
+ GLcontext *ctx = st->ctx;
+ struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx);
+ struct gl_texture_object *texObj;
+ struct gl_texture_image *texImage;
+ struct st_texture_object *stObj;
+ struct st_texture_image *stImage;
+ GLenum internalFormat;
+
+ switch (target) {
+ case ST_TEXTURE_1D:
+ target = GL_TEXTURE_1D;
+ break;
+ case ST_TEXTURE_2D:
+ target = GL_TEXTURE_2D;
+ break;
+ case ST_TEXTURE_3D:
+ target = GL_TEXTURE_3D;
+ break;
+ case ST_TEXTURE_RECT:
+ target = GL_TEXTURE_RECTANGLE_ARB;
+ break;
+ default:
+ return FALSE;
+ break;
+ }
+
+ if (util_format_get_component_bits(internal_format,
+ UTIL_FORMAT_COLORSPACE_RGB, 3) > 0)
+ internalFormat = GL_RGBA;
+ else
+ internalFormat = GL_RGB;
+
+ texObj = _mesa_select_tex_object(ctx, texUnit, target);
+ _mesa_lock_texture(ctx, texObj);
+
+ stObj = st_texture_object(texObj);
+ /* switch to surface based */
+ if (!stObj->surface_based) {
+ _mesa_clear_texture_object(ctx, texObj);
+ stObj->surface_based = GL_TRUE;
+ }
+
+ texImage = _mesa_get_tex_image(ctx, texObj, target, level);
+ stImage = st_texture_image(texImage);
+ if (tex) {
+ _mesa_init_teximage_fields(ctx, target, texImage,
+ tex->width0, tex->height0, 1, 0, internalFormat);
+ texImage->TexFormat = st_ChooseTextureFormat(ctx, internalFormat,
+ GL_RGBA, GL_UNSIGNED_BYTE);
+ _mesa_set_fetch_functions(texImage, 2);
+ }
+ else {
+ _mesa_clear_texture_image(ctx, texImage);
+ }
+
+ stObj->pipe = st->pipe;
+ pipe_texture_reference(&stImage->pt, tex);
+
+ _mesa_dirty_texobj(ctx, texObj, GL_TRUE);
+ _mesa_unlock_texture(ctx, texObj);
+
+ return TRUE;
+}
+
+static void
+st_context_destroy(struct st_context_iface *stctxi)
+{
+ struct st_context *st = (struct st_context *) stctxi;
+ st_destroy_context(st);
+}
+
+static struct st_context_iface *
+st_api_create_context(struct st_api *stapi, struct st_manager *smapi,
+ const struct st_visual *visual,
+ struct st_context_iface *shared_stctxi)
+{
+ struct st_context *shared_ctx = (struct st_context *) shared_stctxi;
+ struct st_context *st;
+ struct pipe_context *pipe;
+ __GLcontextModes mode;
+
+ pipe = smapi->screen->context_create(smapi->screen, NULL);
+ if (!pipe)
+ return NULL;
+
+ st_visual_to_context_mode(visual, &mode);
+ st = st_create_context(pipe, &mode, shared_ctx);
+ if (!st) {
+ pipe->destroy(pipe);
+ return NULL;
+ }
+
+ st->iface.destroy = st_context_destroy;
+
+ st->iface.notify_invalid_framebuffer =
+ st_context_notify_invalid_framebuffer;
+ st->iface.flush = st_context_flush;
+
+ st->iface.teximage = st_context_teximage;
+ st->iface.copy = NULL;
+
+ st->iface.st_context_private = (void *) smapi;
+
+ return &st->iface;
+}
+
+static boolean
+st_api_make_current(struct st_api *stapi, struct st_context_iface *stctxi,
+ struct st_framebuffer_iface *stdrawi,
+ struct st_framebuffer_iface *streadi)
+{
+ struct st_context *st = (struct st_context *) stctxi;
+ struct st_framebuffer *stdraw, *stread, *stfb;
+ boolean ret;
+
+ _glapi_check_multithread();
+
+ if (st) {
+ /* reuse/create the draw fb */
+ stfb = st_framebuffer(st->ctx->WinSysDrawBuffer);
+ if (stfb && stfb->iface == stdrawi) {
+ stdraw = NULL;
+ st_framebuffer_reference(&stdraw, stfb);
+ }
+ else {
+ stdraw = st_framebuffer_create(stdrawi);
+ }
+
+ /* reuse/create the read fb */
+ stfb = st_framebuffer(st->ctx->WinSysReadBuffer);
+ if (!stfb || stfb->iface != streadi)
+ stfb = stdraw;
+ if (stfb && stfb->iface == streadi) {
+ stread = NULL;
+ st_framebuffer_reference(&stread, stfb);
+ }
+ else {
+ stread = st_framebuffer_create(streadi);
+ }
+
+ if (stdraw && stread) {
+ st_framebuffer_validate(stdraw, st);
+ if (stread != stdraw)
+ st_framebuffer_validate(stread, st);
+
+ /* modify the draw/read buffers of the context */
+ st_visual_to_default_buffer(stdraw->iface->visual,
+ &st->ctx->Color.DrawBuffer[0], NULL);
+ st_visual_to_default_buffer(stread->iface->visual,
+ &st->ctx->Pixel.ReadBuffer, NULL);
+
+ ret = _mesa_make_current(st->ctx, &stdraw->Base, &stread->Base);
+ }
+ else {
+ ret = FALSE;
+ }
+
+ st_framebuffer_reference(&stdraw, NULL);
+ st_framebuffer_reference(&stread, NULL);
+ }
+ else {
+ ret = _mesa_make_current(NULL, NULL, NULL);
+ }
+
+ return ret;
+}
+
+static struct st_context_iface *
+st_api_get_current(struct st_api *stapi)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ struct st_context *st = (ctx) ? ctx->st : NULL;
+
+ return (st) ? &st->iface : NULL;
+}
+
+static boolean
+st_api_is_visual_supported(struct st_api *stapi,
+ const struct st_visual *visual)
+{
+ return TRUE;
+}
+
+static st_proc_t
+st_api_get_proc_address(struct st_api *stapi, const char *procname)
+{
+ return (st_proc_t) _glapi_get_proc_address(procname);
+}
+
+static void
+st_api_destroy(struct st_api *stapi)
+{
+ FREE(stapi);
+}
+
+/**
+ * Flush the front buffer if the current context renders to the front buffer.
+ */
+void
+st_manager_flush_frontbuffer(struct st_context *st)
+{
+ struct st_framebuffer *stfb = st_framebuffer(st->ctx->DrawBuffer);
+ struct st_renderbuffer *strb = NULL;
+
+ if (stfb)
+ strb = st_renderbuffer(stfb->Base.Attachment[BUFFER_FRONT_LEFT].Renderbuffer);
+ if (!strb)
+ return;
+
+ /* st_public.h */
+ if (!stfb->iface) {
+ struct pipe_surface *front_surf = strb->surface;
+ st->pipe->screen->flush_frontbuffer(st->pipe->screen,
+ front_surf, st->winsys_drawable_handle);
+ return;
+ }
+
+ stfb->iface->flush_front(stfb->iface, ST_ATTACHMENT_FRONT_LEFT);
+}
+
+/**
+ * Re-validate the framebuffers.
+ */
+void
+st_manager_validate_framebuffers(struct st_context *st)
+{
+ struct st_framebuffer *stdraw = st_framebuffer(st->ctx->DrawBuffer);
+ struct st_framebuffer *stread = st_framebuffer(st->ctx->ReadBuffer);
+
+ /* st_public.h */
+ if ((stdraw && !stdraw->iface) || (stread && !stread->iface)) {
+ struct pipe_screen *screen = st->pipe->screen;
+ if (screen->update_buffer)
+ screen->update_buffer(screen, st->pipe->priv);
+ return;
+ }
+
+ if (stdraw)
+ st_framebuffer_validate(stdraw, st);
+ if (stread && stread != stdraw)
+ st_framebuffer_validate(stread, st);
+}
+
+/**
+ * Add a color renderbuffer on demand.
+ */
+boolean
+st_manager_add_color_renderbuffer(struct st_context *st, GLframebuffer *fb,
+ gl_buffer_index idx)
+{
+ struct st_framebuffer *stfb = st_framebuffer(fb);
+
+ /* FBO or st_public.h */
+ if (!stfb || !stfb->iface)
+ return FALSE;
+
+ if (stfb->Base.Attachment[idx].Renderbuffer)
+ return TRUE;
+
+ switch (idx) {
+ case BUFFER_FRONT_LEFT:
+ case BUFFER_BACK_LEFT:
+ case BUFFER_FRONT_RIGHT:
+ case BUFFER_BACK_RIGHT:
+ break;
+ default:
+ return FALSE;
+ break;
+ }
+
+ if (!st_framebuffer_add_renderbuffer(stfb, idx))
+ return FALSE;
+
+ st_framebuffer_update_attachments(stfb);
+ st_invalidate_state(st->ctx, _NEW_BUFFERS);
+
+ return TRUE;
+}
+
+/**
+ * Create an st_api to manage the state tracker.
+ */
+struct st_api *
+st_manager_create_api(void)
+{
+ struct st_api *stapi;
+
+ stapi = CALLOC_STRUCT(st_api);
+ if (stapi) {
+ stapi->destroy = st_api_destroy;
+ stapi->get_proc_address = st_api_get_proc_address;
+ stapi->is_visual_supported = st_api_is_visual_supported;
+
+ stapi->create_context = st_api_create_context;
+ stapi->make_current = st_api_make_current;
+ stapi->get_current = st_api_get_current;
+ }
+
+ return stapi;
+}
diff --git a/src/mesa/state_tracker/st_manager.h b/src/mesa/state_tracker/st_manager.h
new file mode 100644
index 0000000000..a3f5199223
--- /dev/null
+++ b/src/mesa/state_tracker/st_manager.h
@@ -0,0 +1,47 @@
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.9
+ *
+ * Copyright (C) 2010 LunarG Inc.
+ *
+ * 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, sublicense,
+ * 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:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * 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 NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR 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.
+ *
+ * Authors:
+ * Chia-I Wu <olv@lunarg.com>
+ */
+
+#ifndef ST_MANAGER_H
+#define ST_MANAGER_H
+
+#include "state_tracker/st_api.h"
+#include "st_context.h"
+
+void
+st_manager_flush_frontbuffer(struct st_context *st);
+
+void
+st_manager_validate_framebuffers(struct st_context *st);
+
+boolean
+st_manager_add_color_renderbuffer(struct st_context *st, GLframebuffer *fb,
+ gl_buffer_index idx);
+
+struct st_api *
+st_manager_create_api(void);
+
+#endif /* ST_MANAGER_H */
diff --git a/src/mesa/state_tracker/st_public.h b/src/mesa/state_tracker/st_public.h
index 0824356cec..4b40d6d044 100644
--- a/src/mesa/state_tracker/st_public.h
+++ b/src/mesa/state_tracker/st_public.h
@@ -105,7 +105,8 @@ void st_unreference_framebuffer( struct st_framebuffer *stfb );
PUBLIC
GLboolean st_make_current(struct st_context *st,
struct st_framebuffer *draw,
- struct st_framebuffer *read);
+ struct st_framebuffer *read,
+ void *winsys_drawable_handle);
PUBLIC
struct st_context *st_get_current(void);
diff --git a/src/mesa/state_tracker/st_texture.c b/src/mesa/state_tracker/st_texture.c
index 5a45c4358a..5809927852 100644
--- a/src/mesa/state_tracker/st_texture.c
+++ b/src/mesa/state_tracker/st_texture.c
@@ -192,7 +192,6 @@ st_texture_image_map(struct st_context *st, struct st_texture_image *stImage,
GLuint x, GLuint y, GLuint w, GLuint h)
{
struct pipe_context *pipe = st->pipe;
- struct pipe_screen *screen = pipe->screen;
struct pipe_texture *pt = stImage->pt;
DBG("%s \n", __FUNCTION__);
@@ -202,7 +201,7 @@ st_texture_image_map(struct st_context *st, struct st_texture_image *stImage,
usage, x, y, w, h);
if (stImage->transfer)
- return screen->transfer_map(screen, stImage->transfer);
+ return pipe->transfer_map(pipe, stImage->transfer);
else
return NULL;
}
@@ -212,13 +211,13 @@ void
st_texture_image_unmap(struct st_context *st,
struct st_texture_image *stImage)
{
- struct pipe_screen *screen = st->pipe->screen;
+ struct pipe_context *pipe = st->pipe;
DBG("%s\n", __FUNCTION__);
- screen->transfer_unmap(screen, stImage->transfer);
+ pipe->transfer_unmap(pipe, stImage->transfer);
- screen->tex_transfer_destroy(stImage->transfer);
+ pipe->tex_transfer_destroy(pipe, stImage->transfer);
}
@@ -238,8 +237,7 @@ st_surface_data(struct pipe_context *pipe,
const void *src, unsigned src_stride,
unsigned srcx, unsigned srcy, unsigned width, unsigned height)
{
- struct pipe_screen *screen = pipe->screen;
- void *map = screen->transfer_map(screen, dst);
+ void *map = pipe->transfer_map(pipe, dst);
assert(dst->texture);
util_copy_rect(map,
@@ -250,7 +248,7 @@ st_surface_data(struct pipe_context *pipe,
src, src_stride,
srcx, srcy);
- screen->transfer_unmap(screen, dst);
+ pipe->transfer_unmap(pipe, dst);
}
@@ -265,7 +263,6 @@ st_texture_image_data(struct st_context *st,
GLuint src_row_stride, GLuint src_image_stride)
{
struct pipe_context *pipe = st->pipe;
- struct pipe_screen *screen = pipe->screen;
GLuint depth = u_minify(dst->depth0, level);
GLuint i;
const GLubyte *srcUB = src;
@@ -287,7 +284,7 @@ st_texture_image_data(struct st_context *st,
u_minify(dst->width0, level),
u_minify(dst->height0, level)); /* width, height */
- screen->tex_transfer_destroy(dst_transfer);
+ pipe->tex_transfer_destroy(pipe, dst_transfer);
srcUB += src_image_stride;
}
@@ -345,21 +342,12 @@ st_texture_image_copy(struct pipe_context *pipe,
src_surface = screen->get_tex_surface(screen, src, face, srcLevel, i,
PIPE_BUFFER_USAGE_GPU_READ);
- 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_copy(pipe,
+ 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);
@@ -531,14 +519,21 @@ st_bind_teximage(struct st_framebuffer *stfb, uint surfIndex,
/* save the renderbuffer's surface/texture info */
pipe_texture_reference(&strb->texture_save, strb->texture);
pipe_surface_reference(&strb->surface_save, strb->surface);
+ pipe_sampler_view_reference(&strb->sampler_view_save, strb->sampler_view);
/* plug in new surface/texture info */
pipe_texture_reference(&strb->texture, stImage->pt);
+
+ /* XXX: Shouldn't we release reference to old surface here?
+ */
+
strb->surface = screen->get_tex_surface(screen, strb->texture,
face, level, slice,
(PIPE_BUFFER_USAGE_GPU_READ |
PIPE_BUFFER_USAGE_GPU_WRITE));
+ pipe_sampler_view_reference(&strb->sampler_view, NULL);
+
st->dirty.st |= ST_NEW_FRAMEBUFFER;
return 1;
@@ -568,9 +563,11 @@ st_release_teximage(struct st_framebuffer *stfb, uint surfIndex,
/* free tex surface, restore original */
pipe_surface_reference(&strb->surface, strb->surface_save);
pipe_texture_reference(&strb->texture, strb->texture_save);
+ pipe_sampler_view_reference(&strb->sampler_view, strb->sampler_view_save);
pipe_surface_reference(&strb->surface_save, NULL);
pipe_texture_reference(&strb->texture_save, NULL);
+ pipe_sampler_view_reference(&strb->sampler_view, NULL);
st->dirty.st |= ST_NEW_FRAMEBUFFER;
diff --git a/src/mesa/state_tracker/st_texture.h b/src/mesa/state_tracker/st_texture.h
index 60868ce067..c62f7f2cc0 100644
--- a/src/mesa/state_tracker/st_texture.h
+++ b/src/mesa/state_tracker/st_texture.h
@@ -29,6 +29,9 @@
#define ST_TEXTURE_H
+#include "pipe/p_context.h"
+#include "util/u_sampler.h"
+
#include "main/mtypes.h"
struct pipe_context;
@@ -68,6 +71,13 @@ struct st_texture_object
*/
struct pipe_texture *pt;
+ /* Default sampler view attached to this texture object. Created lazily
+ * on first binding.
+ */
+ struct pipe_sampler_view *sampler_view;
+
+ struct pipe_context *pipe;
+
GLboolean teximage_realloc;
/* True if there is/was a surface bound to this texture object. It helps
@@ -105,6 +115,35 @@ st_get_stobj_texture(struct st_texture_object *stObj)
}
+static INLINE struct pipe_sampler_view *
+st_sampler_view_from_texture(struct pipe_context *pipe,
+ struct pipe_texture *texture)
+{
+ struct pipe_sampler_view templ;
+
+ u_sampler_view_default_template(&templ,
+ texture,
+ texture->format);
+
+ return pipe->create_sampler_view(pipe, texture, &templ);
+}
+
+
+static INLINE struct pipe_sampler_view *
+st_get_stobj_sampler_view(struct st_texture_object *stObj)
+{
+ if (!stObj || !stObj->pt) {
+ return NULL;
+ }
+
+ if (!stObj->sampler_view) {
+ stObj->sampler_view = st_sampler_view_from_texture(stObj->pipe, stObj->pt);
+ }
+
+ return stObj->sampler_view;
+}
+
+
extern struct pipe_texture *
st_texture_create(struct st_context *st,
enum pipe_texture_target target,