void *fs;
struct pipe_buffer *vbuf; /**< quad vertices */
+ unsigned vbuf_slot;
+
float vertices[4][2][4]; /**< vertex/texcoords for quad */
};
/* fragment shader */
ctx->fs = util_make_fragment_tex_shader(pipe, &ctx->frag_shader);
-
- ctx->vbuf = pipe_buffer_create(pipe->screen,
- 32,
- PIPE_BUFFER_USAGE_VERTEX,
- sizeof(ctx->vertices));
- if (!ctx->vbuf) {
- FREE(ctx);
- ctx->pipe->delete_fs_state(ctx->pipe, ctx->fs);
- ctx->pipe->delete_vs_state(ctx->pipe, ctx->vs);
- return NULL;
- }
+ ctx->vbuf = NULL;
/* init vertex data that doesn't change */
for (i = 0; i < 4; i++) {
}
+static unsigned get_next_slot( struct blit_state *ctx )
+{
+ const unsigned max_slots = 4096 / sizeof ctx->vertices;
+
+ if (ctx->vbuf_slot >= max_slots)
+ util_blit_flush( ctx );
+
+ if (!ctx->vbuf) {
+ ctx->vbuf = pipe_buffer_create(ctx->pipe->screen,
+ 32,
+ PIPE_BUFFER_USAGE_VERTEX,
+ max_slots * sizeof ctx->vertices);
+ }
+
+ return ctx->vbuf_slot++ * sizeof ctx->vertices;
+}
+
+
+
/**
* Setup vertex data for the textured quad we'll draw.
* Note: y=0=top
*/
-static void
+static unsigned
setup_vertex_data(struct blit_state *ctx,
float x0, float y0, float x1, float y1, float z)
{
void *buf;
+ unsigned offset;
ctx->vertices[0][0][0] = x0;
ctx->vertices[0][0][1] = y0;
ctx->vertices[3][1][0] = 0.0f;
ctx->vertices[3][1][1] = 1.0f;
+ offset = get_next_slot( ctx );
+
buf = pipe_buffer_map(ctx->pipe->screen, ctx->vbuf,
PIPE_BUFFER_USAGE_CPU_WRITE);
- memcpy(buf, ctx->vertices, sizeof(ctx->vertices));
+ memcpy((char *)buf + offset, ctx->vertices, sizeof(ctx->vertices));
pipe_buffer_unmap(ctx->pipe->screen, ctx->vbuf);
+
+ return offset;
}
* Setup vertex data for the textured quad we'll draw.
* Note: y=0=top
*/
-static void
+static unsigned
setup_vertex_data_tex(struct blit_state *ctx,
float x0, float y0, float x1, float y1,
float s0, float t0, float s1, float t1,
float z)
{
void *buf;
+ unsigned offset;
ctx->vertices[0][0][0] = x0;
ctx->vertices[0][0][1] = y0;
ctx->vertices[3][1][0] = s0;
ctx->vertices[3][1][1] = t1;
+ offset = get_next_slot( ctx );
+
buf = pipe_buffer_map(ctx->pipe->screen, ctx->vbuf,
PIPE_BUFFER_USAGE_CPU_WRITE);
- memcpy(buf, ctx->vertices, sizeof(ctx->vertices));
+ memcpy((char *)buf + offset, ctx->vertices, sizeof(ctx->vertices));
pipe_buffer_unmap(ctx->pipe->screen, ctx->vbuf);
+
+ return offset;
}
/**
* Copy pixel block from src surface to dst surface.
const int srcH = abs(srcY1 - srcY0);
const int srcLeft = MIN2(srcX0, srcX1);
const int srcTop = MIN2(srcY0, srcY1);
+ unsigned offset;
assert(filter == PIPE_TEX_MIPFILTER_NEAREST ||
filter == PIPE_TEX_MIPFILTER_LINEAR);
cso_set_framebuffer(ctx->cso, &fb);
/* draw quad */
- setup_vertex_data(ctx,
- (float) dstX0, (float) dstY0,
- (float) dstX1, (float) dstY1, z);
+ offset = setup_vertex_data(ctx,
+ (float) dstX0, (float) dstY0,
+ (float) dstX1, (float) dstY1, z);
- util_draw_vertex_buffer(ctx->pipe, ctx->vbuf,
+ util_draw_vertex_buffer(ctx->pipe, ctx->vbuf, offset,
PIPE_PRIM_TRIANGLE_FAN,
4, /* verts */
2); /* attribs/vert */
screen->texture_release(screen, &tex);
}
+
+/* Release vertex buffer at end of frame to avoid synchronous
+ * rendering.
+ */
+void util_blit_flush( struct blit_state *ctx )
+{
+ pipe_buffer_reference(ctx->pipe->screen, &ctx->vbuf, NULL);
+ ctx->vbuf_slot = 0;
+}
+
+
+
/**
* Copy pixel block from src texture to dst surface.
* Overlapping regions are acceptable.
struct pipe_screen *screen = pipe->screen;
struct pipe_framebuffer_state fb;
float s0, t0, s1, t1;
+ unsigned offset;
assert(filter == PIPE_TEX_MIPFILTER_NEAREST ||
filter == PIPE_TEX_MIPFILTER_LINEAR);
cso_set_framebuffer(ctx->cso, &fb);
/* draw quad */
- setup_vertex_data_tex(ctx,
- (float) dstX0, (float) dstY0,
- (float) dstX1, (float) dstY1,
- s0, t0, s1, t1,
- z);
-
- util_draw_vertex_buffer(ctx->pipe, ctx->vbuf,
+ offset = setup_vertex_data_tex(ctx,
+ (float) dstX0, (float) dstY0,
+ (float) dstX1, (float) dstY1,
+ s0, t0, s1, t1,
+ z);
+
+ util_draw_vertex_buffer(ctx->pipe,
+ ctx->vbuf, offset,
PIPE_PRIM_TRIANGLE_FAN,
4, /* verts */
2); /* attribs/vert */
int dstX1, int dstY1,
float z, uint filter);
+/* Call at end of frame to avoid synchronous rendering.
+ */
+extern void
+util_blit_flush( struct blit_state *ctx );
#ifdef __cplusplus
}
void
util_draw_vertex_buffer(struct pipe_context *pipe,
struct pipe_buffer *vbuf,
+ uint offset,
uint prim_type,
uint num_verts,
uint num_attribs)
/* tell pipe about the vertex buffer */
vbuffer.buffer = vbuf;
vbuffer.pitch = num_attribs * 4 * sizeof(float); /* vertex size */
- vbuffer.buffer_offset = 0;
+ vbuffer.buffer_offset = offset;
pipe->set_vertex_buffers(pipe, 1, &vbuffer);
/* tell pipe about the vertex attributes */
v[29] = 1.0;
pipe_buffer_unmap(pipe->screen, vbuf);
- util_draw_vertex_buffer(pipe, vbuf, PIPE_PRIM_TRIANGLE_FAN, 4, 2);
+ util_draw_vertex_buffer(pipe, vbuf, 0, PIPE_PRIM_TRIANGLE_FAN, 4, 2);
}
pipe_buffer_reference(pipe->screen, &vbuf, NULL);
extern void
util_draw_vertex_buffer(struct pipe_context *pipe,
- struct pipe_buffer *vbuf,
+ struct pipe_buffer *vbuf, uint offset,
uint num_attribs, uint num_verts, uint prim_type);
void *fs;
struct pipe_buffer *vbuf; /**< quad vertices */
+ unsigned vbuf_slot;
+
float vertices[4][2][4]; /**< vertex/texcoords for quad */
};
}
-static void
+static unsigned get_next_slot( struct gen_mipmap_state *ctx )
+{
+ const unsigned max_slots = 4096 / sizeof ctx->vertices;
+
+ if (ctx->vbuf_slot >= max_slots)
+ util_gen_mipmap_flush( ctx );
+
+ if (!ctx->vbuf) {
+ ctx->vbuf = pipe_buffer_create(ctx->pipe->screen,
+ 32,
+ PIPE_BUFFER_USAGE_VERTEX,
+ max_slots * sizeof ctx->vertices);
+ }
+
+ return ctx->vbuf_slot++ * sizeof ctx->vertices;
+}
+
+static unsigned
set_vertex_data(struct gen_mipmap_state *ctx, float width, float height)
{
void *buf;
+ unsigned offset;
ctx->vertices[0][0][0] = 0.0f; /*x*/
ctx->vertices[0][0][1] = 0.0f; /*y*/
ctx->vertices[3][1][0] = 0.0f;
ctx->vertices[3][1][1] = 1.0f;
+ offset = get_next_slot( ctx );
+
buf = pipe_buffer_map(ctx->pipe->screen, ctx->vbuf,
PIPE_BUFFER_USAGE_CPU_WRITE);
- memcpy(buf, ctx->vertices, sizeof(ctx->vertices));
+ memcpy((char *)buf + offset, ctx->vertices, sizeof(ctx->vertices));
pipe_buffer_unmap(ctx->pipe->screen, ctx->vbuf);
+
+ return offset;
}
}
+
+/* Release vertex buffer at end of frame to avoid synchronous
+ * rendering.
+ */
+void util_gen_mipmap_flush( struct gen_mipmap_state *ctx )
+{
+ pipe_buffer_reference(ctx->pipe->screen, &ctx->vbuf, NULL);
+ ctx->vbuf_slot = 0;
+}
+
+
/**
* Generate mipmap images. It's assumed all needed texture memory is
* already allocated.
struct pipe_framebuffer_state fb;
uint dstLevel;
uint zslice = 0;
+ uint offset;
/* check if we can render in the texture's format */
if (!screen->is_format_supported(screen, pt->format, PIPE_TEXTURE_2D,
cso_set_sampler_textures(ctx->cso, 1, &pt);
/* quad coords in window coords (bypassing clipping, viewport mapping) */
- set_vertex_data(ctx,
- (float) pt->width[dstLevel],
- (float) pt->height[dstLevel]);
- util_draw_vertex_buffer(ctx->pipe, ctx->vbuf,
+ offset = set_vertex_data(ctx,
+ (float) pt->width[dstLevel],
+ (float) pt->height[dstLevel]);
+
+ util_draw_vertex_buffer(ctx->pipe,
+ ctx->vbuf,
+ offset,
PIPE_PRIM_TRIANGLE_FAN,
4, /* verts */
2); /* attribs/vert */
extern void
util_destroy_gen_mipmap(struct gen_mipmap_state *ctx);
+/* Release vertex buffer at end of frame to avoid synchronous
+ * rendering.
+ */
+extern void
+util_gen_mipmap_flush( struct gen_mipmap_state *ctx );
extern void
#include "st_cb_accum.h"
#include "st_cb_fbo.h"
#include "st_draw.h"
+#include "st_public.h"
#include "st_format.h"
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
const GLint height = ctx->DrawBuffer->_Ymax - ypos;
/* make sure color bufs aren't cached */
- pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL);
+ st_flush( st, PIPE_FLUSH_RENDER_CACHE, NULL );
switch (op) {
case GL_ADD:
return pt;
}
-
-static void
+static GLuint
setup_bitmap_vertex_data(struct st_context *st,
int x, int y, int width, int height,
float z, const float color[4])
const GLfloat clip_y0 = (GLfloat)(y0 / fb_height * 2.0 - 1.0);
const GLfloat clip_x1 = (GLfloat)(x1 / fb_width * 2.0 - 1.0);
const GLfloat clip_y1 = (GLfloat)(y1 / fb_height * 2.0 - 1.0);
+ const GLuint max_slots = 4096 / sizeof(st->bitmap.vertices);
GLuint i;
- void *buf;
+
+ if (st->bitmap.vbuf_slot >= max_slots) {
+ pipe_buffer_reference(pipe->screen, &st->bitmap.vbuf, NULL);
+ st->bitmap.vbuf_slot = 0;
+ }
if (!st->bitmap.vbuf) {
- st->bitmap.vbuf = pipe_buffer_create(pipe->screen, 32, PIPE_BUFFER_USAGE_VERTEX,
- sizeof(st->bitmap.vertices));
+ st->bitmap.vbuf = pipe_buffer_create(pipe->screen, 32,
+ PIPE_BUFFER_USAGE_VERTEX,
+ max_slots * sizeof(st->bitmap.vertices));
}
/* Positions are in clip coords since we need to do clipping in case
}
/* put vertex data into vbuf */
- buf = pipe_buffer_map(pipe->screen, st->bitmap.vbuf, PIPE_BUFFER_USAGE_CPU_WRITE);
- memcpy(buf, st->bitmap.vertices, sizeof(st->bitmap.vertices));
- pipe_buffer_unmap(pipe->screen, st->bitmap.vbuf);
+ {
+ char *buf = pipe_buffer_map(pipe->screen,
+ st->bitmap.vbuf,
+ PIPE_BUFFER_USAGE_CPU_WRITE);
+
+ memcpy(buf + st->bitmap.vbuf_slot * sizeof st->bitmap.vertices,
+ st->bitmap.vertices,
+ sizeof st->bitmap.vertices);
+
+ pipe_buffer_unmap(pipe->screen, st->bitmap.vbuf);
+ }
+
+ return st->bitmap.vbuf_slot++ * sizeof st->bitmap.vertices;
}
struct cso_context *cso = ctx->st->cso_context;
struct st_fragment_program *stfp;
GLuint maxSize;
+ GLuint offset;
stfp = combined_bitmap_fragment_program(ctx);
}
/* draw textured quad */
- setup_bitmap_vertex_data(st, x, y, width, height,
- ctx->Current.RasterPos[2],
- color);
+ offset = setup_bitmap_vertex_data(st, x, y, width, height,
+ ctx->Current.RasterPos[2],
+ color);
- util_draw_vertex_buffer(pipe, st->bitmap.vbuf,
+ util_draw_vertex_buffer(pipe, st->bitmap.vbuf, offset,
PIPE_PRIM_TRIANGLE_FAN,
4, /* verts */
3); /* attribs/vert */
struct pipe_screen *screen = pipe->screen;
assert(cache->xmin <= cache->xmax);
- /*
- printf("flush size %d x %d at %d, %d\n",
+
+/* printf("flush size %d x %d at %d, %d\n",
cache->xmax - cache->xmin,
cache->ymax - cache->ymin,
cache->xpos, cache->ypos);
- */
+*/
/* The texture surface has been mapped until now.
* So unmap and release the texture surface before drawing.
}
}
+/* Flush bitmap cache and release vertex buffer.
+ */
+void
+st_flush_bitmap( struct st_context *st )
+{
+ st_flush_bitmap_cache(st);
+
+ /* Release vertex buffer to avoid synchronous rendering if we were
+ * to map it in the next frame.
+ */
+ pipe_buffer_reference(st->pipe->screen, &st->bitmap.vbuf, NULL);
+ st->bitmap.vbuf_slot = 0;
+}
+
/**
* Try to accumulate this glBitmap call in the bitmap cache.
extern void
st_flush_bitmap_cache(struct st_context *st);
+/* Flush bitmap cache and release vertex buffer. Needed at end of
+ * frame to avoid synchronous rendering.
+ */
+extern void
+st_flush_bitmap(struct st_context *st);
+
#endif /* ST_CB_BITMAP_H */
{
struct st_context *st = ctx->st;
struct pipe_context *pipe = st->pipe;
+ const GLuint max_slots = 1024 / sizeof(st->clear.vertices);
GLuint i;
void *buf;
+ if (st->clear.vbuf_slot >= max_slots) {
+ pipe_buffer_reference(pipe->screen, &st->clear.vbuf, NULL);
+ st->clear.vbuf_slot = 0;
+ }
+
if (!st->clear.vbuf) {
st->clear.vbuf = pipe_buffer_create(pipe->screen, 32, PIPE_BUFFER_USAGE_VERTEX,
- sizeof(st->clear.vertices));
+ max_slots * sizeof(st->clear.vertices));
}
/* positions */
/* put vertex data into vbuf */
buf = pipe_buffer_map(pipe->screen, st->clear.vbuf, PIPE_BUFFER_USAGE_CPU_WRITE);
- memcpy(buf, st->clear.vertices, sizeof(st->clear.vertices));
+
+ memcpy((char *)buf + st->clear.vbuf_slot * sizeof(st->clear.vertices),
+ st->clear.vertices,
+ sizeof(st->clear.vertices));
+
pipe_buffer_unmap(pipe->screen, st->clear.vbuf);
/* draw */
- util_draw_vertex_buffer(pipe, st->clear.vbuf,
+ util_draw_vertex_buffer(pipe,
+ st->clear.vbuf,
+ st->clear.vbuf_slot * sizeof(st->clear.vertices),
PIPE_PRIM_TRIANGLE_FAN,
4, /* verts */
2); /* attribs/vert */
+
+ /* Increment slot */
+ st->clear.vbuf_slot++;
}
}
+void st_flush_clear( struct st_context *st )
+{
+ /* Release vertex buffer to avoid synchronous rendering if we were
+ * to map it in the next frame.
+ */
+ pipe_buffer_reference(st->pipe->screen, &st->clear.vbuf, NULL);
+ st->clear.vbuf_slot = 0;
+}
+
+
/**
* Called via ctx->Driver.Clear()
extern void
st_destroy_clear(struct st_context *st);
+extern void
+st_flush_clear(struct st_context *st);
+
extern void
st_init_clear_functions(struct dd_function_table *functions);
memcpy(map, verts, sizeof(verts));
pipe_buffer_unmap(pipe->screen, buf);
- util_draw_vertex_buffer(pipe, buf,
+ util_draw_vertex_buffer(pipe, buf, 0,
PIPE_PRIM_QUADS,
4, /* verts */
3); /* attribs/vert */
if (!strb)
return;
- ctx->st->pipe->flush(ctx->st->pipe, PIPE_FLUSH_RENDER_CACHE, NULL);
+ st_flush( ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL );
if (strb->surface)
screen->tex_surface_release( screen, &strb->surface );
#include "st_context.h"
#include "st_cb_bitmap.h"
#include "st_cb_flush.h"
+#include "st_cb_clear.h"
#include "st_cb_fbo.h"
#include "st_public.h"
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
#include "pipe/p_winsys.h"
+#include "util/u_gen_mipmap.h"
+#include "util/u_blit.h"
static INLINE GLboolean
{
FLUSH_VERTICES(st->ctx, 0);
- st_flush_bitmap_cache(st);
+ /* Release any vertex buffers that might potentially be accessed in
+ * successive frames:
+ */
+ st_flush_bitmap(st);
+ st_flush_clear(st);
+ util_blit_flush(st->blit);
+ util_gen_mipmap_flush(st->gen_mipmap);
st->pipe->flush( st->pipe, pipeFlushFlags, fence );
}
if (!dest)
return;
- st_flush_bitmap_cache(ctx->st);
-
/* make sure rendering has completed */
- pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL);
+ st_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL);
if (format == GL_STENCIL_INDEX) {
st_read_stencil_pixels(ctx, x, y, width, height, type, pack, dest);
void *vs;
float vertices[4][3][4]; /**< vertex pos + color + texcoord */
struct pipe_buffer *vbuf;
+ unsigned vbuf_slot; /* next free slot in vbuf */
struct bitmap_cache *cache;
} bitmap;
void *fs;
float vertices[4][2][4]; /**< vertex pos + color */
struct pipe_buffer *vbuf;
+ unsigned vbuf_slot;
} clear;
void *passthrough_fs; /**< simple pass-through frag shader */